Re: Set/change mouse cursor (multi-OS)
Posted: Fri Mar 25, 2016 9:59 pm
On MacOS X with the current Cocoa framework the busy or wait cursor is problematic: you won't find a busy cursor at all because a busy cursor is automatically displayed by MacOS:
So now you are able to display a wait cursor on MacOS X in 32 and 64 bit programs. But you should be warned that Apple won't like or approve this...
On Wikipedia the explanation for the missing wait cursor on MacOS X is even more detailed:Apple's [url=https://developer.apple.com/library/mac/documentation/UserExperience/Conceptual/OSXHIGuidelines/Pointers.html][color=#0040FF]OS X Human Interface Guidelines[/color][/url] wrote:The spinning wait cursor (shown below) is also standard, but it is displayed automatically by the window server when an app can't handle all of the events it receives. In general, if an app doesn't respond for a few moments, the spinning wait cursor appears. If the app continues to be unresponsive, users often react by force-quitting it.
Nevertheless I have tried to find a cross-platform solution which allows you to toggle between the normal arrow cursor and a busy cursor. I have simply loaded the PNG image of a classic Windows hourglass from Wikipedia and converted it to data in a DataSection. On MacOS now this image is read in with CatchImage() to display an hourglass as wait cursor while on Linux and Windows the default cursor images are used.Wikipedia for [url=https://en.wikipedia.org/wiki/Spinning_pinwheel][color=#0040FF]Spinning_pinwheel[/color][/url] wrote:The display of the wait cursor is controlled by the operating system, not by the application. This works as follows:
Each application has an event queue that receives events from the operating system (For example key presses and mouse button clicks). If an application takes longer than 2 seconds[7] to process the events in its event queue (regardless of the exact cause) the operating system displays the wait cursor whenever the cursor hovers over that application's windows.
This is meant to indicate that the application is temporarily unresponsive, a state from which the application may recover, however it may also indicate that the application has entered an unrecoverable state or an infinite loop.
This prevents the user from closing, resizing, or even minimizing the windows of that application, however moving the window is still possible in OS X and previously hidden parts of the window are usually redrawn even when the application is unresponsive.
Users can choose to terminate an unresponsive application, by using "Force Quit" under the Apple menu, the keystroke command-option-escape, or the Force Quit command found by control-clicking (or right-clicking) the icon of an unresponsive application in the Dock.
While one application is unresponsive, typically other applications are usable in the meantime.
So now you are able to display a wait cursor on MacOS X in 32 and 64 bit programs. But you should be warned that Apple won't like or approve this...


Code: Select all
EnableExplicit
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
#CURSOR_ARROW = #GDK_ARROW
#CURSOR_BUSY = #GDK_WATCH
ImportC ""
gtk_widget_get_window(*Widget.GtkWidget)
EndImport
CompilerCase #PB_OS_MacOS
UsePNGImageDecoder()
Define Hotspot.NSPoint
CatchImage(0, ?HourglassImagePNG)
CompilerCase #PB_OS_Windows
#CURSOR_ARROW = #IDC_ARROW
#CURSOR_BUSY = #IDC_WAIT
CompilerEndSelect
Define BusyCursorActive.I
Define NewCursor.I
OpenWindow(0, 270, 100, 200, 90, "Toggle busy cursor")
ButtonGadget(0, 20, 30, 160, 25, "Enable busy cursor")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
If EventGadget() = 0 And EventType() = #PB_EventType_LeftClick
BusyCursorActive ! 1
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux ; -----------------------------------------
If BusyCursorActive
NewCursor = gdk_cursor_new_(#CURSOR_BUSY)
Else
NewCursor = gdk_cursor_new_(#CURSOR_ARROW)
EndIf
If NewCursor
gdk_window_set_cursor_(gtk_widget_get_window(WindowID(0)), NewCursor)
EndIf
CompilerCase #PB_OS_MacOS ; -----------------------------------------
If BusyCursorActive
Hotspot\x = 0
Hotspot\y = 0
NewCursor = CocoaMessage(0, 0, "NSCursor alloc")
CocoaMessage(0, NewCursor, "initWithImage:", ImageID(0),
"hotSpot:@", @Hotspot)
Else
NewCursor = CocoaMessage(0, 0, "NSCursor arrowCursor")
EndIf
If NewCursor
CocoaMessage(0, NewCursor, "set")
EndIf
CompilerCase #PB_OS_Windows ; ---------------------------------------
If BusyCursorActive
NewCursor = LoadCursor_(0, #CURSOR_BUSY)
Else
NewCursor = LoadCursor_(0, #CURSOR_ARROW)
EndIf
If NewCursor
SetClassLongPtr_(WindowID(0), #GCL_HCURSOR, NewCursor)
EndIf
CompilerEndSelect ; ---------------------------------------------------
If BusyCursorActive
SetGadgetText(0, "Disable busy cursor")
Else
SetGadgetText(0, "Enable busy cursor")
EndIf
EndIf
EndSelect
ForEver
End
DataSection
HourglassImagePNG:
Data.Q $0A1A0A0D474E5089,$524448490D000000,$180000000F000000,$A705250000000608,$4343692404000069
Data.Q $6F72502043434950,$11380000656C6966,$3E1454DB6FDF5585,$58203F16A4526F89,$5B5355AFC58A8747
Data.Q $934906C6AD1A1BB9,$2AD8E9A5164AEDA5,$071BA989373AE424,$37817B4FAAB6E9DB,$480F03D94001FC06
Data.Q $F6D97B62060D213C,$49AA2A875349B4C0,$ED26210FC4E87B48,$53276276BBE15505,$39DF39CBFAF55CC4
Data.Q $5F3D44DB5EE73BE7,$AB968855199AB569,$16A7939524CF9DAE,$4BD4B3D28A4D9E94,$CB912D4EE9ABD403
Data.Q $EBCEF715C12E12CD,$EE91EDCB088A1DE1,$DC8B7ABF23F64EFE,$1D156EC04F2289D1,$6BD4CC510CF8197D
Data.Q $69F8FB07BF144BB6,$36D3F01CF3DC06B7,$129C7D9702AB0204,$3F214E3D27C7D178,$08AD15EB2AD08E09
Data.Q $B72F66D8BC3C06BC,$55E193C818035F61,$ADB3916622BA1B6E,$718F2FE1CF726192,$F4759B2E0FFF31B7
Data.Q $B9A59CFB58835DEC,$54F62BDE890FB863,$F01CF4B5D73F89BE,$7F6149B9AF5FB04B,$78027CD2FA8FF805
Data.Q $DE747D92A9F4511F,$06DE14AD5F5F47E7,$4D0BA770D17B05DE,$B1181C7B31756AFB,$3823C898EB25F5D1
Data.Q $8017A4B3126775D7,$91E863D8B4F856EF,$C1E061E06953C8A8,$56719A5F99AA7D4A,$CC995AB3CBDD84E6
Data.Q $E4CDA7BF648F2302,$A8BCADB43F800780,$16A233373AD2CD05,$41A9AE6E6B574BF2,$32FD0B51599AAEDA
Data.Q $BB6D29C88F5E3B99,$76BA0ECB1F94C295,$E9D1C64A16CB19A1,$DA11677A66AD7F26,$9F90DA179EBB05D8
Data.Q $D879180674ECD2DD,$DB1C06E62F3ABC3F,$47C0A3B66252D45D,$622D164E234444E8,$329E50A43B4AA9D5
Data.Q $32253C3646BDC494,$223161CBC38584C8,$8F3979DD6C12D24F,$2DBD17B28C84C7E3,$BF70AFC73BA551A2
Data.Q $FC01D9533F58B1C9,$13671B30ECB3621F,$4B08EC9BD837B0A4,$6D720A050EC13AC1,$F3F5287DD32A153A
Data.Q $504E3A1654754FBC,$CE5188287D40FCF2,$86FE8FCDFA1AEFD9,$D04F23F42B4BB09A,$13072013ED5B3431
Data.Q $6B6BA73ED2377568,$F8BB06CA3C0EEC3F,$71FC746B6BBEEDCE,$B036C76D8BDD8DF3,$B1AFD8F8C2B6C66E
Data.Q $7A603B02526DFC2D,$09C276F0CAA1968A,$25D3015C3D1D2378,$52DAD059E06FEB0D,$D081F9EAA5A3B1DA
Data.Q $D2CC3EC83FC12623,$A9FEA2FEAAD0E1B9,$3BDFD417A85FA86E,$2A7D24A63B19846A,$2F7D277D28FD2B7D
Data.Q $FD22BA59748A4CFD,$39052E91BE955D24,$AF7BD8259FBDEFBB,$D5685D8ADD13615F,$7BCA4E5327359F6B
Data.Q $B2FCBCFC94E517E4,$931E5FB914B01B3C,$CDF609ECF0BDE4A7,$B30A7418BD1DFD0C,$1804F12D7BB54D6A
Data.Q $C6D7069D06250F34,$DB591674AB84C554,$D8C6C83652A6939F,$96E59C5C76A723F4,$8948278A9E3A788A
Data.Q $0233E2C7C44F8BEF,$B026F85EF8BC9EB7,$3A301393FEF503A6,$33C8254C2C6DE03A,$0AF44556713A9DE2
Data.Q $DF067E5DCDD09B74,$CA36D676AB49A20E,$0929AFAAAFD95715,$8747D55D32B8CA7C,$3628E5CF1534CD15
Data.Q $BE24A38BC2BDB877,$BEFBDE41E88E2283,$445BEE6D0CDD7645,$5B6856EB3BC2FF87,$1ABFF510ED7D13A8
Data.Q $A233E67C4EF086DA,$A3E7E2BDBAF5078B,$DFB03A539106E448,$B774DDE24BE91DFB,$4427CF55F78078D1
Data.Q $1A37AEFF1A371F3B,$F365D116FF225F3B,$2B1B6C787100593F,$5948700900000013,$0B0000130B000073
Data.Q $0000189C9A000113,$113854414449D400,$040C30830ECB94AD,$4B85B9FFFFA4D569,$91F4A18DAD1354B5
Data.Q $D31231AF1DE24E03,$3E3DAD6D88BAC3F4,$3CD0E6FDCB2CB1AD,$1F71F7BDF72C7ECF,$5B6D66C1C50C4F60
Data.Q $B98B2D59D67EB579,$31CFDA612AEDF1EA,$8331E817DAB0949B,$F3D02A252718073A,$06AEF7C0E9818CD2
Data.Q $1024CE0FA4B0C807,$5D7E7056A05E48E6,$3383694190280EC5,$CF7BDEAE71B8D9F0,$A79201881067383D
Data.Q $148F0221024CE1B3,$205311067383FDE3,$B9C4A051488C03E7,$1B02A3C1D84A6B80,$586303AC0AF702B8
Data.Q $24FE1686BDBBD2DE,$3D80419F01552079,$2224027BBD7F8151,$0000253E8FBDD066,$42AE444E45490000
Data.Q $0000000000008260
EndDataSection