Why is my callback not working?

Mac OSX specific forum
Wolfram
Enthusiast
Enthusiast
Posts: 567
Joined: Thu May 30, 2013 4:39 pm

Why is my callback not working?

Post by Wolfram »

I use these code in another program and it works, but in my new program the knob of the scrollbar is not moving.
Does anyone has an idea???

Edit:
I found out if I place a overlapping gadget over the ListIconGadget() the callback works.
So maybe someone has an idea why.

Code: Select all

EnableExplicit

ImportC ""
  class_addMethod(Class.i, Selector.i, *Callback, Types.P-ASCII)
  objc_allocateClassPair(ModelClass.i, NewClassName.P-ASCII, ExtraBytes.i)
  objc_registerClassPair(NewClass.i)
  object_setClass(ObjectToModify.i, NewClass.i)
  sel_registerName(MethodName.P-ASCII)
EndImport


Global backGround =CreateImage(#PB_Any, 8, 8, 32, $C5C8C9)


ProcedureC DrawTrackCallback(Object.i, Selector.i, x.f, y.f, w.f, h.f, Highlight, d1.d,d2.d,d3.d,d4.d, x_.d, y_.d, w_.d, h_.d)
  Protected Delta.CGFloat = 1.0
  Protected Point.NSPoint
  Protected.NSRect src, dst
  
  Debug "scroll"
  
  Src\size\width = ImageWidth(backGround)
  Src\size\height = ImageHeight(backGround)
  
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
    Dst\origin\x = x_
    Dst\origin\y = y_
    Dst\size\width = w_
    Dst\size\height = h_
  CompilerElse
    Dst\origin\x = x
    Dst\origin\y = y
    Dst\size\width = w
    Dst\size\height = h  
  CompilerEndIf
  
  CocoaMessage(0, ImageID(backGround),
    "drawInRect:@", @Dst,
    "fromRect:@", @Src,
    "operation:", #NSCompositeSourceOver,
    "fraction:@", @Delta)
EndProcedure


OpenWindow(0, 450, 100, 440, 250, "New Window")


Global listGG =ListIconGadget(#PB_Any, 20, 30, 134, 154, "", 180) ;ListViewGadget(#PB_Any, 20, 30, 134, 154)
Define gadgetID = GadgetID(listGG)
CocoaMessage(0, gadgetID, "setHeaderView:", #NO)

Define scrollView = CocoaMessage(0, gadgetID,"enclosingScrollView")
Define NSScroller = CocoaMessage(0, scrollView, "verticalScroller")

Define CustomScrollBarClass = objc_allocateClassPair(CocoaMessage(0, NSScroller, "class"), "CustomScrollBar", 0)
objc_registerClassPair(CustomScrollBarClass)
object_setClass(NSScroller, CustomScrollBarClass)

class_addMethod(CustomScrollBarClass, sel_registerName("drawKnobSlotInRect:highlight:"),
                @DrawTrackCallback(), "v@:{CGRect={CGPoint=dd}{CGSize=dd}}c")

CocoaMessage(0, scrollView, "setHasHorizontalScroller:", #NO)

;-If I place another gadget, which overlaps with the ListIconGadget(), the callback works.
Define dummy =ButtonGadget(#PB_Any, 20, 150, 25, 25, "") 
HideGadget(dummy, #YES)


Define ii
Repeat
  AddGadgetItem(listGG, -1, Str(ii))
  ii +1
Until ii = 16


Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
macOS Catalina 10.15.7
Wolfram
Enthusiast
Enthusiast
Posts: 567
Joined: Thu May 30, 2013 4:39 pm

Re: Why is my callback not working?

Post by Wolfram »

I found out why it works in my old program, but Wilbert told me that my first post works on his Mac, on OSX 10.14, as well.
So maybe this code here is just a workaround.
I changed the "selectionHighlightStyle" of the ListGadget.

Code: Select all

EnableExplicit

;SelectionStyle
#NSTableViewSelectionHighlightStyleNone = -1
#NSTableViewSelectionHighlightStyleRegular =0
#NSTableViewSelectionHighlightStyleSourceList =1

Global backGround =CreateImage(#PB_Any, 8, 8, 32, $C5C8C9)


ProcedureC DrawTrackCallback(Object.i, Selector.i, x.f, y.f, w.f, h.f, Highlight, d1.d,d2.d,d3.d,d4.d, x_.d, y_.d, w_.d, h_.d)
  Protected Delta.CGFloat = 1.0
  Protected Point.NSPoint
  Protected.NSRect src, dst
  
  Debug "scroll"
  
  Src\size\width = ImageWidth(backGround)
  Src\size\height = ImageHeight(backGround)
  
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
    Dst\origin\x = x_
    Dst\origin\y = y_
    Dst\size\width = w_
    Dst\size\height = h_
  CompilerElse
    Dst\origin\x = x
    Dst\origin\y = y
    Dst\size\width = w
    Dst\size\height = h  
  CompilerEndIf
  
  CocoaMessage(0, ImageID(backGround),
    "drawInRect:@", @Dst,
    "fromRect:@", @Src,
    "operation:", #NSCompositeSourceOver,
    "fraction:@", @Delta)
EndProcedure


OpenWindow(0, 450, 100, 440, 250, "New Window")

Global listGG =ListIconGadget(#PB_Any, 20, 30, 134, 154, "", 180) ;ListViewGadget(#PB_Any, 20, 30, 134, 154)
Define gadgetID = GadgetID(listGG)


;//NEW
CocoaMessage(0, gadgetID, "setSelectionHighlightStyle:", #NSTableViewSelectionHighlightStyleSourceList)

;//If you want to change the color of the ListGadget you must do it after "setSelectionHighlightStyle:"
SetGadgetColor(listGG, #PB_Gadget_BackColor, $C5C8C9)



CocoaMessage(0, gadgetID, "setHeaderView:", #NO)

Define scrollView = CocoaMessage(0, gadgetID,"enclosingScrollView")
Define NSScroller = CocoaMessage(0, scrollView, "verticalScroller")

Define CustomScrollBarClass = objc_allocateClassPair_(CocoaMessage(0, NSScroller, "class"), "CustomScrollBar", 0)
objc_registerClassPair_(CustomScrollBarClass)
object_setClass_(NSScroller, CustomScrollBarClass)

class_addMethod_(CustomScrollBarClass, sel_registerName_("drawKnobSlotInRect:highlight:"),
                @DrawTrackCallback(), "v@:{CGRect={CGPoint=dd}{CGSize=dd}}c")

CocoaMessage(0, scrollView, "setHasHorizontalScroller:", #NO)


Define ii
Repeat
  AddGadgetItem(listGG, -1, Str(ii))
  ii +1
Until ii = 16


Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
macOS Catalina 10.15.7
Post Reply