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

Summon your guild and prepare for war in...
Netmarble is making some pretty big moves with their latest update for Seven Knights Idle Adventure, with a bunch of interesting additions. Two new heroes enter the battle, there are events and bosses abound, and perhaps most interesting, a huge... | Read more »
Make the passage of time your plaything...
While some of us are still waiting for a chance to get our hands on Ash Prime - yes, don’t remind me I could currently buy him this month I’m barely hanging on - Digital Extremes has announced its next anticipated Prime Form for Warframe. Starting... | Read more »
If you can find it and fit through the d...
The holy trinity of amazing company names have come together, to release their equally amazing and adorable mobile game, Hamster Inn. Published by HyperBeard Games, and co-developed by Mum Not Proud and Little Sasquatch Studios, it's time to... | Read more »
Amikin Survival opens for pre-orders on...
Join me on the wonderful trip down the inspiration rabbit hole; much as Palworld seemingly “borrowed” many aspects from the hit Pokemon franchise, it is time for the heavily armed animal survival to also spawn some illegitimate children as Helio... | Read more »
PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »
Embark into the frozen tundra of certain...
Chucklefish, developers of hit action-adventure sandbox game Starbound and owner of one of the cutest logos in gaming, has released their roguelike deck-builder Wildfrost. Created alongside developers Gaziter and Deadpan Games, Wildfrost will... | Read more »
MoreFun Studios has announced Season 4,...
Tension has escalated in the ever-volatile world of Arena Breakout, as your old pal Randall Fisher and bosses Fred and Perrero continue to lob insults and explosives at each other, bringing us to a new phase of warfare. Season 4, Into The Fog of... | Read more »
Top 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 »
Marvel Future Fight celebrates nine year...
Announced alongside an advertising image I can only assume was aimed squarely at myself with the prominent Deadpool and Odin featured on it, Netmarble has revealed their celebrations for the 9th anniversary of Marvel Future Fight. The Countdown... | Read more »
HoYoFair 2024 prepares to showcase over...
To say Genshin Impact took the world by storm when it was released would be an understatement. However, I think the most surprising part of the launch was just how much further it went than gaming. There have been concerts, art shows, massive... | Read more »

Price Scanner via MacPrices.net

Apple Watch Ultra 2 now available at Apple fo...
Apple has, for the first time, begun offering Certified Refurbished Apple Watch Ultra 2 models in their online store for $679, or $120 off MSRP. Each Watch includes Apple’s standard one-year warranty... Read more
AT&T has the iPhone 14 on sale for only $...
AT&T has the 128GB Apple iPhone 14 available for only $5.99 per month for new and existing customers when you activate unlimited service and use AT&T’s 36 month installment plan. The fine... Read more
Amazon is offering a $100 discount on every M...
Amazon is offering a $100 instant discount on each configuration of Apple’s new 13″ M3 MacBook Air, in Midnight, this weekend. These are the lowest prices currently available for new 13″ M3 MacBook... Read more
You can save $300-$480 on a 14-inch M3 Pro/Ma...
Apple has 14″ M3 Pro and M3 Max MacBook Pros in stock today and available, Certified Refurbished, starting at $1699 and ranging up to $480 off MSRP. Each model features a new outer case, shipping is... Read more
24-inch M1 iMacs available at Apple starting...
Apple has clearance M1 iMacs available in their Certified Refurbished store starting at $1049 and ranging up to $300 off original MSRP. Each iMac is in like-new condition and comes with Apple’s... Read more
Walmart continues to offer $699 13-inch M1 Ma...
Walmart continues to offer new Apple 13″ M1 MacBook Airs (8GB RAM, 256GB SSD) online for $699, $300 off original MSRP, in Space Gray, Silver, and Gold colors. These are new MacBook for sale by... Read more
B&H has 13-inch M2 MacBook Airs with 16GB...
B&H Photo has 13″ MacBook Airs with M2 CPUs, 16GB of memory, and 256GB of storage in stock and on sale for $1099, $100 off Apple’s MSRP for this configuration. Free 1-2 day delivery is available... Read more
14-inch M3 MacBook Pro with 16GB of RAM avail...
Apple has the 14″ M3 MacBook Pro with 16GB of RAM and 1TB of storage, Certified Refurbished, available for $300 off MSRP. Each MacBook Pro features a new outer case, shipping is free, and an Apple 1-... Read more
Apple M2 Mac minis on sale for up to $150 off...
Amazon has Apple’s M2-powered Mac minis in stock and on sale for $100-$150 off MSRP, each including free delivery: – Mac mini M2/256GB SSD: $499, save $100 – Mac mini M2/512GB SSD: $699, save $100 –... Read more
Amazon is offering a $200 discount on 14-inch...
Amazon has 14-inch M3 MacBook Pros in stock and on sale for $200 off MSRP. Shipping is free. Note that Amazon’s stock tends to come and go: – 14″ M3 MacBook Pro (8GB RAM/512GB SSD): $1399.99, $200... Read more

Jobs Board

*Apple* Systems Administrator - JAMF - Syste...
Title: Apple Systems Administrator - JAMF ALTA is supporting a direct hire opportunity. This position is 100% Onsite for initial 3-6 months and then remote 1-2 Read more
Relationship Banker - *Apple* Valley Financ...
Relationship Banker - Apple Valley Financial Center APPLE VALLEY, Minnesota **Job Description:** At Bank of America, we are guided by a common purpose to help Read more
IN6728 Optometrist- *Apple* Valley, CA- Tar...
Date: Apr 9, 2024 Brand: Target Optical Location: Apple Valley, CA, US, 92308 **Requisition ID:** 824398 At Target Optical, we help people see and look great - and Read more
Medical Assistant - Orthopedics *Apple* Hil...
Medical Assistant - Orthopedics Apple Hill York Location: WellSpan Medical Group, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply Now Read more
*Apple* Systems Administrator - JAMF - Activ...
…**Public Trust/Other Required:** None **Job Family:** Systems Administration **Skills:** Apple Platforms,Computer Servers,Jamf Pro **Experience:** 3 + years of Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.