rndrei wrote:
How can I disable the cursor icon above editorgadget() and put my own icon?
The EditorGadget forces the cursor to always be displayed as an insertion cursor. In order to display a custom cursor, you have to subclass the EditorGadget (internally a NSTextView) and check in a callback for all mouse move events. In each mouse move event you have to set your custom cursor. I have tested the following example successfully on MacOS 15.7.1 'Seqouia' with PB 6.21 and PB 6.30 Beta 4:
Code: Select all
EnableExplicit
#NSMouseMoved = 5
UsePNGImageDecoder()
Define CustomCursor.I
Define Hotspot.NSPoint
Define SubclassedEditorGadget.I
Procedure SubclassGadget(GadgetID.I, NewClassName.S)
Protected GadgetClass.I = CocoaMessage(0, GadgetID(GadgetID), "class")
Protected NewGadgetClass.I
NewGadgetClass = objc_allocateClassPair_(GadgetClass, NewClassName, 0)
objc_registerClassPair_(NewGadgetClass)
object_setClass_(GadgetID(GadgetID), NewGadgetClass)
ProcedureReturn NewGadgetClass
EndProcedure
ProcedureC EditorEventCallback(Object.I, Selector.I, Event.I)
Shared CustomCursor.I
If CocoaMessage(0, Event, "type") = #NSMouseMoved
CocoaMessage(0, CustomCursor, "set")
EndIf
EndProcedure
OpenWindow(0, 200, 100, 320, 140, "Display custom cursor above editor")
EditorGadget(0, 90, 20, 140, 100)
; ----- Subclass EditorGadget and define callback for cursor moving
SubclassedEditorGadget = SubclassGadget(0, "SubclassedEditorGadget")
class_addMethod_(SubclassedEditorGadget, sel_registerName_("mouseMoved:"),
@EditorEventCallback(), "v@:@")
If LoadImage(0, #PB_Compiler_Home + "Examples/Sources/Data/World.png")
; ----- Create custom cursor
Hotspot\x = 4
Hotspot\y = 4
CustomCursor = CocoaMessage(0, 0, "NSCursor alloc")
CocoaMessage(0, CustomCursor,
"initWithImage:", ImageID(0),
"hotSpot:@", @Hotspot)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf