TweetFollow Us on Twitter

MACINTOSH C
MACINTOSH C: A Hobbyist's Guide To Programming the Mac OS in C
Version 2.3

© 2000 K. J. Bricknell

Go to Contents

(Chapter 21)

FLOATING WINDOWS

A link to the associated demonstration program listing is at the bottom of this page



Floating Windows

Floating windows are windows which stay in front of all of an application's document windows. They are typically used to display tool, pattern, colour, and other choices to be made available to the user. Examples of floating windows are shown at Fig 1.

(Floating windows - examples)

System support for floating windows was introduced with Mac OS 8.5; however, there were bugs in the window activation area which prevented programmers from utilising this inbuilt support. The bugs were eliminated in Mac OS 8.6. Chapter 4B - More on Windows - Mac OS 8.5 Window Manager and the associated demonstration program Windows2 describe and demonstrate system-supported floating windows.

If your application requires floating windows, and is required to run under Mac OS 8.5 or earlier, the application itself will have to provide the necessary support. Application support for floating windows is addressed in this chapter.

Front-To-Back Ordering of On-Screen Objects

The fact that floating windows always remain in front of an application's document windows leads naturally to a consideration of the correct front-to-back ordering of on-screen interface objects. Within an application, this front-to-back ordering should be as follows:

  • Help balloons.

  • Menus.

  • System windows.

    System windows are windows which can appear in an application's window list but which are not directly created by the application. These windows appear in front of all windows created by the application. An example of a system window is a notification alert box.

  • Modal and movable modal dialog and alert boxes.

  • Floating windows.

  • Document windows and modeless dialog boxes.
Note that floating windows should remain behind modal and movable modal dialog and alert boxes, reflecting the fact that, whatever choices the user can make from a floating window, those choices relate only to operations within the application's document windows and not to operations within modal dialogs and alert boxes.

In terms of front-to-back ordering, floating windows, unlike document windows, are all basically equal. Unless they actually overlap each other, there is no visual cue of any front-to-back ordering as there is with normal windows. Because of this equality, floating windows should almost always appear in the active state. The exception is when a modal or movable modal dialog or alert box is presented to the user. When this occurs, the appearance of all floating windows should be changed to reflect the inactive state. As a further refinement, the content of the window should be dimmed to further suggest to the user that the floating windows are irrelevant to operations within the dialog box or alert box.

Implementing Floating Windows - Considerations

Activate Events

The most significant aspect of implementing floating windows has to do with activate events.

The Single Active Window Problem. The Window Manager was written on the assumption that there is only ever one active window. However, this will not be the case in an application which implements floating windows. (See Fig 1, in which two floating windows and one document window are active at the same time.) Accordingly, you will need to work around how the Window Manager generates activate events and how the Toolbox Event Manager reports them to an application.

The Single Deactivate Event Problem. Because the Window Manager works on the principle that only one window is ever active, only one deactivate event is generated for every activate event. This behaviour will not suffice for an application with floating windows when a modal or movable modal dialog receives the activate event. In that case, a deactivate event is required not only for the frontmost document window but for all of the visible floating windows as well.

These two problems mean that you must not use those Window Manager functions, such as SelectWindow, ShowWindow, and HideWindow, which implicitly generate activate and deactivate events. Instead, you must use lower-level functions like BringToFront, ShowHide, and HiliteWindow to simulate the higher-level calls.

Activate Events and Document Windows. Other cases that the Window Manager does not handle well occur when the frontmost document window is closed or when a new document window is created in front of other document windows. If floating windows are present, these document windows do not receive the needed activate and deactivate events, since the application is essentially removing or creating windows in the middle of the window list. Accordingly, your application must itself manage the activation and deactivation of the relevant windows.

Activate Events and Modal Windows. When a modal window is to appear, your application will need to deactivate all visible floating windows and the active document window. When the user dismisses the modal window, your application must re-activate each of those windows.

These considerations require that you subvert the system software's normal window activation/deactivation activities and divide the window list into two sections, specifically, the section occupied by the floating windows (which must always be at the beginning of the overall list) and the section occupied by the document windows.

Opening, Closing, Showing and Hiding

Floating windows should be opened at application launch and should remain open until the application is closed. Since Open... and Close items in the File menu should apply only to document windows, items in some other appropriate menu should be provided to allow the user to toggle each floating window between the hidden and showing state.

A floating window's close box should simply hide the window, not close it. For that reason, the close box in floating windows should be conceived of as a "hide" box rather than as a go-away box.

Application in the Background. Floating windows should be hidden by the owner application when that application receives a suspend event. This is to avoid user confusion arising from one application's floating windows being visible when another application is in the foreground. The floating windows should be shown again only when the application receives a subsequent resume event.

Implementing Floating Windows - Substitute and Supporting Functions

Implementing floating windows in an application basically involves providing a number of application-defined substitute and supporting functions, many of which perform the necessary subversion of the system software's normal window activation/deactivation activities and treat the window list as comprising separate document windows and floating windows sections.

The following reflects the implementation methodology used in the demonstration program associated with this chapter.

Main Substitute Functions

The substitute functions are those functions used in lieu of the Macintosh Toolbox functions that would ordinarily be used in a non-floating windows environment. The main substitute functions, the actions performed by those functions, and the Toolbox calls they replace, are as follows:

Substitute Replaces Actions Performed
FW_GetNewCWindow GetNewCWindow Create floating and document windows based on a resource template.

When a new floating window is opened, bring that window to the very front of any existing windows.

When a new document window is opened, move that window to immediately behind the last floating window, and in front of any document windows which may already be open.

FW_DisposeWindow DisposeWindow Dispose of document windows.

Activate the next document window in the window list, and call DisposeWindow to remove the specified document window from the screen and the window list and discard all it data storage.

FW_SelectWindow SelectWindow Bring the window (floating or document) in which the mouse-down occurred as far forward in the window list as it should come. If it is a floating window, makes it the absolute frontmost window. If it is a document window, make it the frontmost window behind the floating windows.
FW_HideWindow HideWindow Hide the specified window.

As with HideWindow, if the frontmost (floating or document) window is to be hidden, place it behind the window immediately behind it in its section of the window list so that, when it is shown again, it will no longer be frontmost window in its section.

FW_ShowWindow ShowWindow Show the specified window.

As with ShowWindow, show the window without changing its position in the window list. If the window being shown is the frontmost document window, deactivate the window behind it, and activate the window being shown.

If the specified window is a floating window, and if a modal or movable modal dialog box is present, show the window in the inactive state.

FW_DragWindow DragWindow Drag the specified window around, ensuring that, if it is a document window, it remains behind the floating windows.

As with DragWindow, do not bring the window forward if the Command key is held down during the drag.

The names of the replacement and supplementary functions shown are, of course, purely arbitrary. You may use whatever names you like. The names shown are those used in the demonstration program.

Additional Substitute Functions

The demonstration program associated with this chapter uses the refCon field of all document and floating window window structures to store a handle to a special structure containing information relevant to window management in the floating windows environment. This means that the use of the window structure's refCon field is denied to the application for other purposes (such as, for example, storing a handle to a document structure).

To compensate for this, a reference constant field is included in the special structure containing information relevant to window management. This field may be used to store the value that you would ordinarily assign to the window structure's refCon field. The following additional substitute functions pertain to assigning a value to, and retrieving that value from, this field:

Substitute Replaces Actions Performed
FW_SetWRefCon SetWRefCon Assign a value to the reference constant field of a structure whose handle is assigned to the refCon field of a window's window structure.
FW_GetWRefCon GetWRefCon Get the value in the reference constant field of a structure whose handle is assigned to the refCon field of a window's window structure.

Supporting Functions

The main supporting functions, and the actions performed by those functions, are as follows:

Function Actions Performed
FW_doSuspendEvent Hide any floating windows, and unhighlight and deactivate the frontmost document window.

(Call this function when the application receives a suspend event.)

FW_doResumeEvent Show all floating windows which were visible when the application was sent to the background, and highlight and activate the front document window.

(Call this function when the application receives a suspend event.)

FW_deactivateFloatsAndFirstDocWin Unhighlight and deactivate any visible floating windows and the frontmost document window.

(Call this function immediately before a modal or movable modal dialog or alert box is invoked.)

FW_activateFloatsAndFirstDocWin Highlight and activate those windows which were visible and activated before FW_deactivateFloatersAndFirstDocWin was called.

(Call this function immediately after an alert or modal dialog box is dismissed.)

FW_findFrontNonFloatWindow Find the first visible non-floating window in the window list.

(Call this function when you need the pointer to the frontmost document window or when you need to determine whether any document windows are currently open.)

FW_validateWindowList Ensure that all floating windows are in front of all document windows.

(Call this function, as a safety measure, immediately prior to opening and closing document windows.)

Floating Window Types

Figs 2 and 3 show the sixteen available window types for floating windows and the constants that represent those types.

(Window types for floating windows)

(Window types for floating windows (side title bar))

Window Definition IDs

The WDEF resource IDs for the floating window types are 66, and 67. The window definition IDs are as follows:

WDEF
Resource ID
Variation
Code
Window Definition ID (Value) Window Definition ID (Constant)
66 1 66 * 16 + 1 = 1057 kWindowFloatProc
66 3 66 * 16 + 3 = 1059 kWindowFloatGrowProc
66 5 66 * 16 + 5 = 1061 kWindowFloatVertZoomProc
66 7 66 * 16 + 7 = 1063 kWindowFloatVertZoomGrowProc
66 9 66 * 16 + 9 = 1065 kWindowFloatHorizZoomProc
66 11 66 * 16 + 11 = 1067 kWindowFloatHorizZoomGrowProc
66 13 66 * 16 + 13 = 1069 kWindowFloatFullZoomProc
66 15 66 * 16 + 15 = 1071 kWindowFloatFullZoomGrowProc
67 1 67 * 16 + 1 = 1073 kWindowFloatSideProc
67 3 67 * 16 + 3 = 1075 kWindowFloatSideGrowProc
67 5 67 * 16 + 5 = 1077 kWindowFloatSideVertZoomProc
67 7 67 * 16 + 7 = 1079 kWindowFloatSideVertZoomGrowProc
67 9 67 * 16 + 9 = 1081 kWindowFloatSideHorizZoomProc
67 11 67 * 16 + 11 = 1083 kWindowFloatSideHorizZoomGrowProc
67 13 67 * 16 + 13 = 1085 kWindowFloatSideFullZoomProc
67 15 67 * 16 + 15 = 1087 kWindowFloatSideFullZoomGrowProc



Floating Windows Library Functions

In the accompanying demonstration program files, the source code pertaining to implementing a floating windows environment has been compiled as a library. The following are the prototypes for those functions in the library that need to be called from an application.

Main Substitute Functions

OSErr  FW_GetNewCWindow(WindowPtr *windowPtr,SInt16 windResourceID,WindowPtr behind,
       ActivateHandlerUPP activateFunctionUPP,Boolean isFloater)
void   FW_DisposeWindow(WindowPtr windowPtr)
void   FW_SelectWindow(WindowPtr windowPtr)
void   FW_HideWindow(WindowPtr windowPtr)
void   FW_ShowWindow(WindowPtr windowPtr)
void   FW_DragWindow(WindowPtr windowPtr,Point startPoint,const Rect *draggingBounds)

Additional Substitute Functions

SInt32  FW_GetWRefCon(WindowPtr windowPtr)
void    FW_SetWRefCon(WindowPtr windowPtr,SInt32 refCon)

Supporting Functions

void       FW_doSuspendEvent(void)
void       FW_doResumeEvent(void)
void       FW_activateFloatsAndFirstDocWin(void)
void       FW_deactivateFloatsAndFirstDocWin(void)
WindowPtr  FW_findFrontNonFloatWindow(void)
void       FW_validateWindowList(void)

Go to Demo

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Six fantastic ways to spend National Vid...
As if anyone needed an excuse to play games today, I am about to give you one: it is National Video Games Day. A day for us to play games, like we no doubt do every day. Let’s not look a gift horse in the mouth. Instead, feast your eyes on this... | Read more »
Old School RuneScape players turn out in...
The sheer leap in technological advancements in our lifetime has been mind-blowing. We went from Commodore 64s to VR glasses in what feels like a heartbeat, but more importantly, the internet. It can be a dark mess, but it also brought hundreds of... | Read more »
Today's Best Mobile Game Discounts...
Every day, we pick out a curated list of the best mobile discounts on the App Store and post them here. This list won't be comprehensive, but it every game on it is recommended. Feel free to check out the coverage we did on them in the links below... | Read more »
Nintendo and The Pokémon Company's...
Unless you have been living under a rock, you know that Nintendo has been locked in an epic battle with Pocketpair, creator of the obvious PokĂ©mon rip-off Palworld. Nintendo often resorts to legal retaliation at the drop of a hat, but it seems this... | Read more »
Apple exclusive mobile games don’t make...
If you are a gamer on phones, no doubt you have been as distressed as I am on one huge sticking point: exclusivity. For years, Xbox and PlayStation have done battle, and before this was the Sega Genesis and the Nintendo NES. On console, it makes... | Read more »
Regionally exclusive events make no sens...
Last week, over on our sister site AppSpy, I babbled excitedly about the PokĂ©mon GO Safari Days event. You can get nine Eevees with an explorer hat per day. Or, can you? Specifically, you, reader. Do you have the time or funds to possibly fly for... | Read more »
As Jon Bellamy defends his choice to can...
Back in March, Jagex announced the appointment of a new CEO, Jon Bellamy. Mr Bellamy then decided to almost immediately paint a huge target on his back by cancelling the Runescapes Pride event. This led to widespread condemnation about his perceived... | Read more »
Marvel Contest of Champions adds two mor...
When I saw the latest two Marvel Contest of Champions characters, I scoffed. Mr Knight and Silver Samurai, thought I, they are running out of good choices. Then I realised no, I was being far too cynical. This is one of the things that games do best... | Read more »
Grass is green, and water is wet: Pokémo...
It must be a day that ends in Y, because PokĂ©mon Trading Card Game Pocket has kicked off its Zoroark Drop Event. Here you can get a promo version of another card, and look forward to the next Wonder Pick Event and the next Mass Outbreak that will be... | Read more »
Enter the Gungeon review
It took me a minute to get around to reviewing this game for a couple of very good reasons. The first is that Enter the Gungeon's style of roguelike bullet-hell action is teetering on the edge of being straight-up malicious, which made getting... | Read more »

Price Scanner via MacPrices.net

Take $150 off every Apple 11-inch M3 iPad Air
Amazon is offering a $150 discount on 11-inch M3 WiFi iPad Airs right now. Shipping is free: – 11″ 128GB M3 WiFi iPad Air: $449, $150 off – 11″ 256GB M3 WiFi iPad Air: $549, $150 off – 11″ 512GB M3... Read more
Apple iPad minis back on sale for $100 off MS...
Amazon is offering $100 discounts (up to 20% off) on Apple’s newest 2024 WiFi iPad minis, each with free shipping. These are the lowest prices available for new minis among the Apple retailers we... Read more
Apple’s 16-inch M4 Max MacBook Pros are on sa...
Amazon has 16-inch M4 Max MacBook Pros (Silver and Black colors) on sale for up to $410 off Apple’s MSRP right now. Shipping is free. Be sure to select Amazon as the seller, rather than a third-party... Read more
Red Pocket Mobile is offering a $150 rebate o...
Red Pocket Mobile has new Apple iPhone 17’s on sale for $150 off MSRP when you switch and open up a new line of service. Red Pocket Mobile is a nationwide MVNO using all the major wireless carrier... Read more
Switch to Verizon, and get any iPhone 16 for...
With yesterday’s introduction of the new iPhone 17 models, Verizon responded by running “on us” promos across much of the iPhone 16 lineup: iPhone 16 and 16 Plus show as $0/mo for 36 months with bill... Read more
Here is a summary of the new features in Appl...
Apple’s September 2025 event introduced major updates across its most popular product lines, focusing on health, performance, and design breakthroughs. The AirPods Pro 3 now feature best-in-class... Read more
Apple’s Smartphone Lineup Could Use A Touch o...
COMMENTARY – Whatever happened to the old adage, “less is more”? Apple’s smartphone lineup. — which is due for its annual refresh either this month or next (possibly at an Apple Event on September 9... Read more
Take $50 off every 11th-generation A16 WiFi i...
Amazon has Apple’s 11th-generation A16 WiFi iPads in stock on sale for $50 off MSRP right now. Shipping is free: – 11″ 11th-generation 128GB WiFi iPads: $299 $50 off MSRP – 11″ 11th-generation 256GB... Read more
Sunday Sale: 14-inch M4 MacBook Pros for up t...
Don’t pay full price! Amazon has Apple’s 14-inch M4 MacBook Pros (Silver and Black colors) on sale for up to $220 off MSRP right now. Shipping is free. Be sure to select Amazon as the seller, rather... Read more
Mac mini with M4 Pro CPU back on sale for $12...
B&H Photo has Apple’s Mac mini with the M4 Pro CPU back on sale for $1259, $140 off MSRP. B&H offers free 1-2 day shipping to most US addresses: – Mac mini M4 Pro CPU (24GB/512GB): $1259, $... Read more

Jobs Board

All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.