Question about controls

Mac OSX specific forum
spacebuddy
Enthusiast
Enthusiast
Posts: 364
Joined: Thu Jul 02, 2009 5:42 am

Question about controls

Post by spacebuddy »

Are all the Gadgets in PB native controls for OS/X?

Someone told me on another forum that PB controls are not native so they are useless??? :(

Not sure what that means :D
User avatar
Shardik
Addict
Addict
Posts: 2076
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Question about controls

Post by Shardik »

spacebuddy wrote:Are all the Gadgets in PB native controls for OS/X?
Most of PB's gadgets are native controls. Some PB gadgets don't exist as a native cocoa control (for example the ExplorerTreeGadget is a custom gadget programmed by the PB devs using another native cocoa control to emulate more or less the functions working natively on other OS platforms). You can easily find out what native cocoa controls are hidden behind PB's gadgets. Wilbert has already demonstrated how to find out the underlying objects of a cocoa control (for the MacOS Carbon framework, for Windows and for Linux all underlying native controls are listed in this PB blog posting).

This code example lists the inherited objects of PB's ComboBox. As you will see, an editable ComboBox is a native NSComboBox from the cocoa framework. An uneditable ComboBox is a made from a native cocoa NSPopUpButton:

Code: Select all

Procedure.S GetInheritedObjects(Object)
  Protected Result.I
  Protected MutableArray.I = CocoaMessage(0, 0, "NSMutableArray arrayWithCapacity:", 10)
 
  Repeat
    CocoaMessage(0, MutableArray, "addObject:", CocoaMessage(0, Object, "className"))
    CocoaMessage(@Object, Object, "superclass")
  Until Object = 0
 
  CocoaMessage(@Result, MutableArray, "componentsJoinedByString:$", @"  -->  ")
  CocoaMessage(@Result, Result, "UTF8String")
 
  ProcedureReturn PeekS(Result, -1, #PB_UTF8)
 EndProcedure

OpenWindow(0, 270, 100, 390, 80, "ComboBoxGadget")
ComboBoxGadget(0, 10, 10, 180, 25, #PB_ComboBox_Editable)
ComboBoxGadget(1, 200, 10, 180, 25)

For i = 1 To 3
  AddGadgetItem(0, -1, "Item " + Str(i))
  AddGadgetItem(1, -1, "Item " + Str(i))
Next i

SetGadgetState(0, 0)
SetGadgetState(1, 0)

Debug "Editable ComboBox: " + GetInheritedObjects(GadgetID(0))
Debug "Uneditable ComboBox: " + GetInheritedObjects(GadgetID(1))

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
An ExplorerTreeGadget is a custom gadget made from a native cocoa NSOutlineView:

Code: Select all

Procedure.S GetInheritedObjects(Object)
  Protected Result.I
  Protected MutableArray.I = CocoaMessage(0, 0, "NSMutableArray arrayWithCapacity:", 10)
 
  Repeat
    CocoaMessage(0, MutableArray, "addObject:", CocoaMessage(0, Object, "className"))
    CocoaMessage(@Object, Object, "superclass")
  Until Object = 0
 
  CocoaMessage(@Result, MutableArray, "componentsJoinedByString:$", @"  -->  ")
  CocoaMessage(@Result, Result, "UTF8String")
 
  ProcedureReturn PeekS(Result, -1, #PB_UTF8)
 EndProcedure

OpenWindow(0, 270, 100, 400, 400, "Test")
ExplorerTreeGadget(0, 10, 10, 380, 380, "/Volumes/Daten/")
Debug "ExplorerTreeGadget: " + GetInheritedObjects(GadgetID(0))

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
spacebuddy
Enthusiast
Enthusiast
Posts: 364
Joined: Thu Jul 02, 2009 5:42 am

Re: Question about controls

Post by spacebuddy »

That is good news :D
Post Reply