William,WilliamL wrote:I think I need it to stay changed until I change it back...
that's a very delicate topic which already resulted in numerous postings
and heated discussions in different Mac forums. Most Mac addicts don't
like the concept that the programmer changes the cursor shape to a wait
cursor. They argue that MacOS takes care of changing the cursor
automatically if your application is busy and that therefore it should be
forbidden to change its shape programmatically. As an example for that
concept try the following simple code example which switches the cursor
shape to a spinning wheel (I had to learn that this cursor is called "Spinning
pizza Of Death" or SPOD

process window events in this time span) and therefore keeps this cursor
active for 2000 ms and automatically switches back to the default cursor.
Most Mac addicts argue that you should never use the SPOD cursor because
the normal Mac user is thinking that the application hangs and he would have
to terminate your app or even has to reboot his Mac...:

Code: Select all
ImportC ""
QDDisplayWaitCursor(ForceWaitCursor.L)
EndImport
OpenWindow(0, 200, 100, 250, 130, "Display Wait cursor")
ButtonGadget(0, 10, 50, 230, 20, "Change cursor to spinning wheel")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
If EventGadget() = 0
QDDisplayWaitCursor(#True)
Delay(2000)
QDDisplayWaitCursor(#False)
EndIf
EndSelect
ForEver
But it's a lot of effort to realize it because you have to install an EventHandler
that intercepts mouse movements and restores the wait cursor on every mouse
movement. As an additional goodie I have implemented a WindowTimer, so that
animated wait cursors are possible. But don't reveal this example to the hardcore
Mac addicts because they would probably lynch me...

Code: Select all
EnableExplicit
ImportC ""
GetEventClass(Event)
RemoveEventHandler(EventHandlerRef.L)
SetAnimatedThemeCursor(CursorType.L, AnimationStep.L)
SetThemeCursor(CursorType.L)
EndImport
#kEventClassMouse = 'mous'
#kEventMouseMoved = 5
#kThemeArrowCursor = 0
#kThemeWatchCursor = 7
#kThemeSpinningCursor = 14
Structure EventTypeSpec
EventClass.L
EventKind.L
EndStructure
Define AnimationStep.L
Define CursorID.L
Define EventHandlerRef.L
Define EventHandlerUPP.L
Define NumAnimationSteps.L
Procedure EventHandler(*NextEventHandler, Event, UserData)
Shared AnimationStep.L
Shared CursorID.L
If GetEventClass(Event) = #kEventClassMouse
If GetEventKind_(Event) = #kEventMouseMoved
SetAnimatedThemeCursor(CursorID, AnimationStep)
EndIf
EndIf
EndProcedure
Dim EventTypes.EventTypeSpec(0)
OpenWindow(0, 200, 100, 250, 120, "Display animated wait cursor")
ButtonGadget(0, 10, 20, 230, 20, "Change cursor to spinning wheel")
ButtonGadget(1, 10, 50, 230, 20, "Change cursor to running watch")
ButtonGadget(2, 10, 80, 230, 20, "Restore default cursor")
EventHandlerUPP = NewEventHandlerUPP_(@EventHandler())
EventTypes(0)\EventClass = #kEventClassMouse
EventTypes(0)\EventKind = #kEventMouseMoved
CursorID = #kThemeSpinningCursor
NumAnimationSteps = 4
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
If EventHandlerRef
RemoveEventHandler(EventHandlerRef)
EndIf
Break
Case #PB_Event_Gadget
Select EventGadget()
Case 0
CursorID = #kThemeSpinningCursor
NumAnimationSteps = 4
InstallEventHandler_(GetWindowEventTarget_(WindowID(0)), EventHandlerUPP, 1, @EventTypes(), 0, @EventHandlerRef)
AddWindowTimer(0, 0, 150)
DisableGadget(0, #True)
DisableGadget(1, #True)
Case 1
CursorID = #kThemeWatchCursor
NumAnimationSteps = 8
InstallEventHandler_(GetWindowEventTarget_(WindowID(0)), EventHandlerUPP, 1, @EventTypes(), 0, @EventHandlerRef)
AddWindowTimer(0, 0, 150)
DisableGadget(0, #True)
DisableGadget(1, #True)
Case 2
RemoveEventHandler(EventHandlerRef)
EventHandlerRef = 0
RemoveWindowTimer(0, 0)
DisableGadget(0, #False)
DisableGadget(1, #False)
SetThemeCursor(#kThemeArrowCursor)
EndSelect
Case #PB_Event_Timer
If EventTimer() = 0
SetAnimatedThemeCursor(CursorID, AnimationStep)
AnimationStep = (AnimationStep + 1) % NumAnimationSteps
EndIf
EndSelect
ForEver