[futurebasic] Re: [FB] badged icon problem in carbon and carbon classic

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

From: Robert Purves <robert.purves@...>
Date: Thu, 12 Feb 2004 21:16:50 +1300
Edwards, Waverly wrote:

>> The red stop icon is obsolete in OS X...
>
> Either there is another interpretation of that guideline or they are in
> direct vialotion of the same.  If you use createstandardsheet it shows 
> a
> badged icon which is the toolbox I planned to emulate.

It seems we are not both playing from the same sheet :-)

Try the demo below, which is lightly edited from a posting in October 
2003.

In OS X 10.3.2, the Note and Stop alerts show the application's icon 
(as seen in, for instance, the Dock); the Caution alert has a yellow 
triangle badged with the app icon at lower right.

Robert P.


'-------------------------
'~'A
'                       Runtime : Rntm Appearance.Incl
'                           CPU : Carbon
'                    CALL Req'd : Off
'~'B
/*
Demo of sheet alerts in OS X
Robert P.    modified  12 February 2004
*/
include "Tlbx CarbonEvents.incl"

end globals

begin record AlertStdCFStringAlertParamRec
dim as UInt32          version
dim as Boolean         movable
dim as Boolean         helpButton
dim as CFStringRef     defaultText
dim as CFStringRef     cancelText
dim as CFStringRef     otherText
dim as SInt16          defaultButton
dim as SInt16          cancelButton
dim as UInt16          position
dim as OptionBits      flags
end record

#define AlertStdCFStringAlertParamPtr as Ptr
#define AlertType as SInt16
_kStdCFStringAlertVersionOne = 1


toolbox fn GetStandardAlertDefaultParams( AlertStdCFStringAlertParamPtr 
¬
   param, UInt32 version ) = OSStatus
toolbox fn CloseStandardSheet( DialogRef inSheet,UInt32 ¬
   inResultCommand ) = OSStatus
toolbox fn GetSheetWindowParent( WindowRef inSheet, ¬
   WindowRef *outParentWindow ) = OSStatus
toolbox fn GetControlCommandID( ControlRef inControl, ¬
   UInt32 * outCommandID )= OSStatus
toolbox fn GetDialogWindow( DialogRef) = WindowRef
toolbox CreateStandardSheet( AlertType alertType, CFStringRef error, ¬
   CFStringRef explanation,const AlertStdCFStringAlertParamRec *param,¬
   EventTargetRef notifyTarget, DialogRef * outSheet )


#if ( compilerVersion <= 0x07000000 )
// quick-and-dirty CFSTR; don't use in production code
local fn CFSTR( @s as ^Str255 )
end fn = fn CFStringCreateWithPascalString( 0, #s,¬
             _kCFStringEncodingMacRoman )
#endif



local fn InstallSheetDismissedHandler( wndNum as long )
'~'1
dim as EventTypeSpec   eventType
dim as WindowRef     @ w
begin globals
dim as proc   sDismissUPP // 'static' variable
end globals

long if ( sDismissUPP == 0 )
sDismissUPP = fn NewEventHandlerUPP¬
    ( [proc "SheetDismissed" + _FBprocToProcPtrOffset] )
end if
eventType.eventClass = _kEventClassCommand
eventType.eventKind  = _kEventProcessCommand
get window wndNum, w
end fn = fn InstallEventHandler( fn GetWindowEventTarget( w ), ¬
               sDismissUPP, 1, @eventType, #wndNum, #0 )


// a plain FB routine that gets called when a sheet is dismissed
local mode
local fn MySheetCloseAction( wndNum as long, commandID as UInt32 )
'~'1
select commandID
  case _kHICommandOK
   window output wndNum
   print "OK" //... perform action on window wndNum for OK at Sheet 
closure
  case _kHICommandCancel
   window output wndNum
   print "Cancel" //... don't perform action on window wndNum
  end select
end fn



long if 0
"SheetDismissed"
enterproc fn SheetDismissed( nextHandler as EventHandlerCallRef, ¬
    theEvent as EventRef, userData as Ptr ) = OSStatus
'~'1
dim as OSStatus           result, ignore
dim as HICommand          command
dim as long               wndNum

result = _eventNotHandledErr

long if ( fn GetEventKind( theEvent ) == _kEventCommandProcess )

long if ( _noErr == fn GetEventParameter( theEvent, 
_kEventParamDirectObject, ¬
    _typeHICommand, #0, sizeof( HICommand ), #0, @command ) )

long if ( command.commandID == _kHICommandOK )¬
    or (command.commandID == _kHICommandCancel )
wndNum = userData // FB wndNum
fn MySheetCloseAction( wndNum, command.commandID )
result = _noErr // we handled the event
end if

end if

end if
exitproc = result

end if


local mode
local fn DoSheetAlert( parent as WindowRef, messageText as Str255, ¬
   informativeText as Str255, alertType as SInt16 )
'~'1
dim as AlertStdCFStringAlertParamRec  paramRec
dim as OSStatus                       ignore
dim as DialogRef                    @ sheet
dim as Ptr                            paramRecPtr

ignore = fn GetStandardAlertDefaultParams( paramRec, ¬
    _kStdCFStringAlertVersionOne )

select alertType

case _kAlertCautionAlert, _kAlertStopAlert
// we'll make these have two buttons
paramRec.defaultText   = _kAlertDefaultOKText
paramRec.defaultButton = _kAlertStdAlertOKButton
paramRec.cancelText    = _kAlertDefaultCancelText
paramRec.cancelButton  = _kAlertStdAlertCancelButton
paramRecPtr = @paramRec

case else
paramRecPtr = _nil // we'll make these with default button only

end select

fn CreateStandardSheet( alertType, fn CFSTR( messageText ), ¬
   fn CFSTR( informativeText ), #paramRecPtr, ¬
   fn GetWindowEventTarget( parent ), @sheet )
ignore = fn ShowSheetWindow( fn GetDialogWindow( sheet ), parent )

end fn


local mode
local fn DoDialog
'~'1
select dialog(0)
case _btnClick
select dialog(_btnClick)
case 1
fn DoSheetAlert( window( _wndRef), "Plain Stuff", "Blah", 
_kAlertPlainAlert )
case 2
fn DoSheetAlert( window( _wndRef), "Note Stuff", "Blah", 
_kAlertNoteAlert )
case 3
fn DoSheetAlert( window( _wndRef), "Caution Stuff", "Blah", 
_kAlertCautionAlert )
case 4
fn DoSheetAlert( window( _wndRef), "Stop Stuff", "Blah", 
_kAlertStopAlert )
end select
case _wndClick
window dialog( _wndClick )
end select
end fn


local mode
local fn BuildWindow( wndNum as long )
'~'1
dim as Rect  r

window wndNum, str$( wndNum )
fn InstallSheetDismissedHandler( wndNum )
SetRect( r, 180, 100, 280, 120 )
button 1, _activeBtn, "Plain", @r
OffsetRect( r, 0, 30 )
button 2, _activeBtn, "Note", @r
OffsetRect( r, 0, 30 )
button 3, _activeBtn, "Caution", @r
OffsetRect( r, 0, 30 )
button 4, _activeBtn, "Stop", @r
end fn


// main program
on dialog fn DoDialog
fn BuildWindow( 1 )
fn BuildWindow( 777 )
do
HandleEvents
until 0
'-------------------------