Working with Windows

Scripts give you complete control over the database windows on the screen. You can create new windows, close existing windows, bring any window to the front, and move or resize any window. (Why would a script need to monkey with someone's onscreen windows? See the box on Section 14.6.3 for some ideas.)

14.6.1. Creating Windows

To make a new window on the screen, you use the New Window script step. With this step selected in your script, you see a Specify button in ScriptMaker's Script Step Options area. Clicking this button brings up the New Window Options dialog box, pictured in Figure 14-14.

The first boxWindow Namegives your script control over the name of the window. (Window name is something you can control only from a script. When you create the window from the Window menu, FileMaker assigns it a name for you.) You can also tell FileMaker how big the window should be (Height and Width), and where to put the window on the screen ("Distance from top" and "Distance from left").

Here are some tips on using the New Window Options dialog box:

Figure 14-14. The Window Options dialog box lets your script open and close windows and move them around the screen. You can use it to make family members think they have poltergeists in their PCs, or just make windows behave properly when your scripts run. See the box on Section 14.6.3 for advice.

 

14.6.2. Bringing a Window to the Front

In ScriptMaker parlance, you bring a window to the front by selecting it. As such, you use the Select Window script step. It has one option, which lets you specify a window by name, or select the current window, as shown in Figure 14-15. You also use the Select Window script step to show a hidden window and bring it to the front.

Figure 14-15. This is the window you see when you click the Specify button with a Select Window script step selected. From here, you can specify the Current Window, or choose Window Name and put the name of the window you want in the box. As usual, you can use a calculation to determine the window name as well.


Note: Usually, the current window is already in the front, and you don't have to worry about this step. But when you run scripts that involve more than one database, as you'll learn in Chapter 15, you may need this step to bring forward the current window from another file.


POWER USERS' CLINIC

Window Size and Position Calculations

The fact that you can set a new window's size and position using a calculation might seem a little strange. After all, do you really need a bigger window for someone named Bill? Do you want your windows in a different place on Thursdays?

In fact, though, you can do a lot of interesting things with window size and position calculations. FileMaker provides a handful of functions that let you find out about the size and position of the current window, and of the computer screen, and use that information in calculations:

  • The Get ( WindowHeight ) function, for instance, returns the height of the current window, in screen pixels (the little dots on your screen). Its brother, Get ( WindowContentHeight ) returns the height of just the content area of the window; that is, the area inside the title bar, scroll bars, and status area.) The Get ( WindowHeight ) and Get ( WindowContentHeight ) functions are similar.
  • Get ( WindowTop ) and Get ( WindowLeft ) functions tell you where the window is on the screen. The first returns the distance from the top of the window to the top of the screen. The second tells you the distance from the left edge of the window to the left side of the screen. Both distances are measured in pixels.
  • The Get ( WindowDesktopHeight ) and Get ( WindowDesktopWidth ) functions tell you how much desktop space you have. On Windows, it's the area of FileMaker's main application window. On Mac OS X, it's the size of the desktop.
  • Finally, Get ( ScreenHeight ) and Get ( ScreenWidth ) tell you how big the screen is. (If you have more than one screen, they tell you about the screen the current window is on.)

    Let ( [ Limit = Get ( WindowDesktopHeight ) Get ( WindowHeight ) ; Offset = Get ( WindowTop ) + 20 ; Best = Min ( Limit ; Offset ) ] ; Best )

By combining these functions in creative ways, you can make your scripts smart about how they size and position windows. For example, to make the new window appear slightly offset from the current window, use these settings:

Distance from top: Get ( WindowTop ) + 20

Distance from left: Get ( WindowLeft ) + 20

If you're paranoid, and you want to make sure the new window never hangs off the bottom of the screen, use this calculation for the "Distance from top" value:

Similarly, you can use the "Distance from left" value to make sure it doesn't hang off the screen's right edge. Just substitute WindowDesktopWidth, WindowWidth, and WindowLeft for WindowDesktopHeight, WindowHeight, and WindowTop.

 

14.6.3. Closing a Window

The Close Window script step has the same options as Select Window. You tell FileMaker which window to close: the current window, or one you specify by name.

14.6.4. Moving and Resizing Existing Windows

FileMaker has three ways to move and resize a window. You can opt for one of its canned window maneuvers or you can set the exact pixel size and location of the window just like you can with the New Window step. You can also hide the current window.

14.6.4.1. Adjust Window

The Adjust Window script step always operates on the current window, and it gives you just five simple choices:


Note: The Maximize options have slightly different behavior on Mac OS X and Windows. For example, when you maximize a window in Windows, and then select a different window, the second window also gets maximized. On Mac OS X, on the other hand, the second window keeps its original size. Also, a maximized window on Mac OS X fills as much of the screen as possible. On Windows, it fills FileMaker's outer application window, whatever size it may be, and there's no way to adjust the application window from a script.


14.6.4.2. Arrange All Windows

The Arrange All Windows script step is the equivalent of the four window arrangement options in the Window menu. You can choose to tile windows horizontally or vertically, or cascade them (see Section 1.7.2.1). On Mac OS X, you can also choose to bring all FileMaker windows to the front.

14.6.4.3. Move/Resize Window

For the ultimate in window control, call upon the Move/Resize Window script step. It can move and/or resize any window with pixel-perfect precision. Its Specify button shows the dialog box in Figure 14-16, where you can choose the window's size and position. As with New Window, you can leave any of the size or position values empty. When you do, FileMaker leaves that part of the window's size or position alone. For example, if you specify a new Width but leave Height blank, FileMaker makes the window wider or narrower, but its height doesn't change.

Figure 14-16. The Move/Resize Window settings look like a combination of the Select Window settings and the New Window settings. First, you pick which window you want to work on (Current Window, or a window selected by name). You then specify the new size and position for the window.


Note: Move/Resize Window also selects the window it acts on, which always brings the window to the front, and, if it's a hidden window, shows it.


14.6.5. Other Window-Related Script Steps

FileMaker has a handful of other window-related script steps, listed below. They come in handy if you need to exert more control over what your users see. (Not to imply that you're a control freak or anything.)

Категории