Adobe AIR Programming Unleashed: Working with Windows [con't]
NativeWindowSystemChrome.NONE
This option specifies that the window should not display any system chrome whatsoever. Creating a NativeWindow
with no chrome generates a rectangle onscreen with no controls. This is the starting point for implementing custom chrome discussed later in this chapter. The following demonstrates how to specify no system chrome:
NativeWindowInitOptions.type
Each window offers unique traits suited for different roles in an application. There are three NativeWindowTypes to choose from:
NORMAL
UTILITY
LIGHTWEIGHT
NativeWindowType.NORMAL
This is the default window type. If nothing is specified for this parameter in your NativeWindowInitOptions
, Figure 5.2 shows what is displayed.
NORMAL
windows have typical controls such as minimize, maximize, and close. Their physical characteristics match that of any standard window on each respective operating system.
NativeWindowType.UTILITY
In Figure 5.3, you see the same system chrome but differences in both physical and behavioral aspects of NativeWindow
.
Often used as containers for supporting content or tool palettes, these windows do not serve as the primary focus of an application. Their content may change as events happen in the main application window, such as displaying properties of an object that has received focus.
NOTE
There are applications that utilize this window type as its primary user interface. These are typically smaller, more specialized applications such as instant messaging or media players. There isn't a need to crowd the user's Dock or taskbar with an application running in the background most of the time.
NativeWindowType.LIGHTWEIGHT LIGHTWEIGHT
NativeWindow
s have no chrome whatsoever. In fact, you'll get a runtime error unless you specifically set the systemChrome
property to NONE
. Creating a window in this fashion gives you a white box that can't be moved or even closed directly. Figure 5.4 demonstrates a native window with no chrome and uses a bitmap image as the window's background.
Uses for LIGHTWEIGHT
NativeWindow
s range from custom system chrome implementations to toast messages (dialogs that temporarily slide up onscreen like toast out of a toaster) to drawer dialogs common on Mac OS X.
NativeWindowInitOptions.transparent
This property refers to the transparency of the window background window. A transparent window has no default background. Any area not occupied by a display object is invisible; for example, whatever lies beneath your application window shows through.
You can also change the alpha property of your display objects to allow underlying desktop content to show through.
CAUTION
Display objects with an alpha setting of less than .06 (approximately) prevent the window from capturing mouse events in that area. It will appear as though you have clicked the object behind the window.
NOTE
You cannot create transparent windows in combination with any system chrome.
NativeWindowInitOptions.maximizable
When this property is set to false
, the window cannot be maximized. For a window with system chrome, this affects the appearance of the window Maximize button, such as making it appear disabled.
NOTE
On Mac OS X, you'll have to set both the maximizable and resizable options tofalse
to prevent the window from being zoomed or resized.
NativeWindowInitOptions.minimizable
When this property is set to false
, the window cannot be minimized. As with a window with system chrome, this affects the appearance of the window Minimize button.
NativeWindowInitOptions.resizable
When this property is set to false
, the window cannot be resized.
NOTE
As with the NativeWindowInitOptions.maximizable property, on Mac OS X, you'll have to set both the maximizable and resizable options tofalse
to prevent the window from being zoomed or resized.
Creating an Instance of the Window
Now we need to create a new NativeWindow
instance. Remember that the properties defined in NativeWindowInitOptions
cannot be changed after we instantiate the window. The default window size is determined by the operating system, but you can change it by setting the window bounds. (We'll look at this later in the chapter.)
The variable windowOptions
refers to the NativeWindowInitOptions
we constructed in the previous section.
Putting the Window
Onscreen
If we were to stop at the previous step, the user would not see anything appear onscreen. After instantiating our NativeWindow
, we need to specifically put it on the screen. There are two ways this can be accomplished:
or
NativeWindow.activate()
Invoking the activate() method on the NativeWindow
instance does the following:
- Makes the window visible
- Brings the window to the front
- Gives the window keyboard and mouse focus
The following snippet instantiates a new NativeWindow
, passing in window options, followed by the activate()
method.
Using NativeWindow.visible
This property specifies whether the window is visible on the desktop. It affects only visibility and does not give the window focus or bring it to the front.
For example, you might want to open a supporting UTILITY
type window for an application where focus must remain on the primary window. Rather than activating your window, simply set its visible property to true, and it appears onscreen without the primary window flashing in and out of focus.
By default, visible is set to false
. To make the window visible, do the following:
NOTE
An invisible window isn't displayed on the desktop, but all the properties and methods are still available.On Mac OS X, turning off visibility on a minimized window does not remove it from the Dock. The user is still able to click that Dock icon, which causes the window to be visible, restore, and have focus.