[futurebasic] Re: sheet alerts

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : September 2003 : Group Archive : Group : All Groups

From: Ken Shmidheiser <kshmidheiser@...>
Date: Wed, 24 Sep 2003 02:14:06 -0400
Waverly,

Apologies for not reading more carefully. You did 
not properly define fn GetDialogWindow. Also, be 
sure to release the CF strings.

Try this:

Ken


'~'A
'                       Runtime : Rntm Appearance.Incl
'                           CPU : Carbon
'                      Debugger : Off
'               DIM'd Vars Only : On
'              No Re-DIM'd Vars : On
'                    CALL Req'd : Off
'                 Register Vars : On
'                MacsBug Labels : On
'           Ary Bounds Checking : On
'                     QB Labels : Off
'                 Optimize STR# : On
'         Make Line Start Table : Off
'                 Show Warnings : On
'~'B

include "tlbx carbonevents.incl"

begin record AlertStdCFStringAlertParamRec
dim as UInt32          version /* kStdCFStringAlertVersionOne */
dim as Boolean         movable /* Make alert movable modal */
dim as Boolean         helpButton /* Is there a help button? */
dim as CFStringRef     defaultText /* Text for button in OK position */
dim as CFStringRef     cancelText /* Text for button in cancel position*/
dim as CFStringRef     otherText /* Text for button in left position */
dim as SInt16          defaultButton /* Which button behaves as the default */
dim as SInt16          cancelButton /* Which one 
behaves as cancel (can be 0) */
dim as UInt16          position /* Position 
(kWindowDefaultPosition in this case */
      /* equals kWindowAlertPositionParentWindowScreen) */
dim as OptionBits      flags /* Options for the 
behavior of the alert or sheet */

end record

_kStdCFStringAlertVersionOne = 1 /* current 
version of AlertStdCFStringAlertParamRec */

#define AlertStdCFStringAlertParamPtr as ^AlertStdCFStringAlertParamRec
#define AlertType as SInt16

toolbox fn GetStandardAlertDefaultParams( AlertStdCFStringAlertParamPtr param,¬
 
UInt32 version) = OSStatus
toolbox fn CreateStandardSheet( AlertType alertType, CFStringRef error,¬
                                                CFStringRef explanation,¬
                             const AlertStdCFStringAlertParamRec *param,¬
                       EventTargetRef 
notifyTarget,DialogRef * outSheet ) = OSStatus
toolbox fn GetDialogWindow ( DialogRef dialog ) = WindowRef

local fn DoSheetAlert( parent as WindowRef )
dim as AlertStdCFStringAlertParamRec  paramRec
dim as Str255                         messageText, informativeText
dim as CFStringRef                    messageTextCF, informativeTextCF
dim as OSStatus                       osError
dim as DialogRef                    @ dialogRef

osError = fn GetStandardAlertDefaultParams( 
paramRec, _kStdCFStringAlertVersionOne )
if osError then stop str$(osError) + " GetStandardAlertDefaultParams"

#if 0
//setup the default button
paramRec.defaultText   = fn CFSTR( "OK" )
paramRec.defaultButton = _kAlertStdAlertOKButton
//setup the cancel button
paramRec.cancelText    = fn CFSTR( "Cancel" )
paramRec.cancelButton  = _kAlertStdAlertCancelButton
#else

//setup the default button
paramRec.defaultText   = _kAlertDefaultOKText
paramRec.defaultButton = _kAlertStdAlertOKButton
//setup the cancel button
paramRec.cancelText    = _kAlertDefaultCancelText
paramRec.cancelButton  = _kAlertStdAlertCancelButton
#endif

messageText     = "This is an example of a Standard Sheet"
informativeText = "(extra text goes here)"

messageTextCF     = fn CFSTR(messageText)
informativeTextCF = fn CFSTR(informativeText)

// or _kAlertPlainAlert
osError = fn CreateStandardSheet( _kAlertCautionAlert,¬
                                         messageTextCF,¬
                                     informativeTextCF,¬
                                             @paramRec,¬
                       fn GetWindowEventTarget(parent),¬
                                            @dialogRef )

long if( osError == _noErr)
osError = fn ShowSheetWindow( fn GetDialogWindow( dialogRef ), parent )
CFRelease( messageTextCF )
CFRelease( informativeTextCF )
xelse
stop str$(osError) + " ShowSheetWindow"
end if

end fn = osError

dim as OSStatus   err
dim as WindowRef  parent

appearance window 1,,, _kDocumentWindowClass, ¬
_kWindowStandardDocumentAttributes¬
_kWindowStandardHandlerAttribute

parent = window(_wndRef)
err = fn DoSheetAlert( parent )

do
HandleEvents
until 0