[futurebasic] Re: [FB] Sheets - new subject

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : March 2004 : Group Archive : Group : All Groups

From: Robert Purves <robert.purves@...>
Date: Sat, 6 Mar 2004 20:58:06 +1300
Joe Lewis Wilkins wrote:

> As a general note of interest, according to Apple's HIG (I suppose), 
> when are we supposed to use "Sheets" rather than conventional Dialogs?

Apple says:
"A sheet is a modal dialog attached to a particular document or window, 
ensuring that the user never loses track of which window the dialog 
applies to. The ability to keep a dialog attached to its pertinent 
window helps users take full advantage of the Mac OS X window layering 
model (see "Window Layering"). Sheets also allow users to perform other 
tasks before dismissing the dialog, so there’s no longer the sense of 
the system being "hijacked" by the application...

When to Use Sheets
Use sheets for dialogs specific to a document when the user interacts 
with the dialog and dismisses it before proceeding with work. Some 
examples of when to use sheets:
• A modal dialog that is specific to a particular document, such as 
saving or printing.
• A modal dialog that is specific to a single-window application that 
does not create documents. A single-window utility program might use a 
sheet to request acceptance of a licensing agreement from the user, for 
example.
• Other window-specific dialogs typically dismissed by the user before 
proceeding. Use a sheet when a dialog benefits from being attached to 
the window as a modal dialog, even if you might otherwise design the 
dialog as a modeless dialog."


The simplest "OK" sheet alert is not especially difficult to program; 
see demo.

Robert P.

'-------------------------
'~'A
'                       Runtime : Rntm Appearance.Incl
'                           CPU : Carbon
'                    CALL Req'd : Off
'~'B

/*
Minimal demo of sheet alert in OS X.
Parameters 3, 4 and 5 of CreateStandardSheet are
given the value 0, for the simplest behaviour and coding.

Robert P.   6 March 2003
*/

include "Tlbx CarbonEvents.incl"
end globals

#define AlertType as SInt16
begin record AlertStdCFStringAlertParamRec
// contents not used in this demo
end record

toolbox CreateStandardSheet( AlertType alertType, CFStringRef error, ¬
   CFStringRef explanation, const AlertStdCFStringAlertParamRec *param,¬
   EventTargetRef notifyTarget, DialogRef *outSheet )
toolbox fn GetDialogWindow( DialogRef) = WindowRef


local mode
local fn DoSheetAlert( parentWndNum as long, errText as Str255 )
'~'1
dim as DialogRef    @ sheet
dim as WindowRef    @ parentWndRef
dim as CFStringRef    errCFStr

errCFStr = fn CFStringCreateWithPascalString( 0, errText,¬
             _kCFStringEncodingMacRoman )
CreateStandardSheet( _kAlertNoteAlert, errCFStr, ¬
     0, #0, 0, @sheet )
CFRelease( errCFStr )
get window parentWndNum, parentWndRef
end fn = fn ShowSheetWindow( fn GetDialogWindow( sheet ), parentWndRef )


local mode
local fn DoDialog
'~'1
select dialog( 0 )
case _btnClick
fn DoSheetAlert( window( _outputWnd ), "Oops, sorry" )
end select
end fn


// main
dim as Rect  r
on dialog fn DoDialog
window 1
SetRect( r, 200, 300, 340, 320 )
button 1, _activeBtn, "Do something", @r
do
HandleEvents
until 0
'-------------------------