Page 1 of 1

ListIcon-remove column heading/scrollbars-api

Posted: Thu May 27, 2010 9:51 pm
by WilliamL
I came across this code, by Freak, at http://www.purebasic.fr/english/viewtop ... 13&t=42372 on the forum and I wanted the Mac community to see and be able to use it.

I am puzzled of where 'ImportC "" ' actually is and what other commands might be available at this location. Like would it be possible to remove the scroll bar at the bottom or the side?

Code: Select all

ImportC ""
  SetDataBrowserListViewHeaderBtnHeight(Control.i, Height.u)
  GetDataBrowserListViewHeaderBtnHeight(Control.i, *Height.UNICODE)
EndImport
#noErr = 0


If OpenWindow(0, 100, 100, 350, 100, "NoColumnHeader & AutoSize", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListIconGadget(0, 5, 5, 340, 90, "", 200, #PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
  AddGadgetColumn(0, 1, "", 200)
  For X.l = 1 To 5
    AddGadgetItem(0, -1, "Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay")
    AddGadgetItem(0, -1, "Ginger Brokeit"+Chr(10)+"130 PureBasic Road, BigTown, CodeCity") 
  Next
  
  If GetDataBrowserListViewHeaderBtnHeight(GadgetID(0), @oldheight.u) = #noErr
    ; If you want the header back, call this again with 'oldheight' as last parameter 
    ; (if you never want to get the header back, you don't need the GetDataBrowserListViewHeaderBtnHeight() call at all)
    SetDataBrowserListViewHeaderBtnHeight(GadgetID(0), 0)
  EndIf
  
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf

Re: ListIcon-remove column heading

Posted: Thu May 27, 2010 10:53 pm
by freak
WilliamL wrote:I am puzzled of where 'ImportC "" ' actually is and what other commands might be available at this location.
The required libraries for these commands are already linked to the executable because the Gadget commands themselves use them too, so you can just leave that part blank. This should work with most Carbon commands as long as you use some PB gui commands as well. My approach here is to just leave the string blank and only worry where things are if i get a linker error.

WilliamL wrote:Like would it be possible to remove the scroll bar at the bottom or the side?
Yes, there is the SetDataBrowserHasScrollBars() function:
http://developer.apple.com/mac/library/ ... ScrollBars

Just put it in such an ImportC and call it with GadgetID() as the first parameter like the others above. The ListIconGadget, ListViewGadget, TreeGadget, ExplorerListGadget and ExplorerTreeGadget all use the databrowser control with different settings, so the above reference can be useful for them.

In general, if you are looking for API commands to import, look in the Carbon and Core Foundation documentation. These are mostly used by PB commands internally (among some others). I usually use the XCode help as documentation. It makes searching simpler than using the web. For using PB objects with API commands, these are the most important object types returned from the [...]ID() functions:
  • WindowID() returns a WindowRef
  • GadgetID() returns a ControlRef
  • MenuID() returns a MenuRef
  • ImageID() returns a CGImageRef
  • StatusBarID() returns a ControlRef (its an ordinary userpane control)
  • ToolBarID() returns a HIToolbarRef
  • FontID() actually returns a PB internal pointer because a FontRef only specifies a name, not a size (so you have to load a font yourself if you need it for API stuff)
If you have more questions, feel free to ask.

Re: ListIcon-remove column heading

Posted: Fri May 28, 2010 3:44 am
by WilliamL
Yes, that worked! I was able to turn off the horizontal scrollbar. I never quite know what to do with defining the variable types. Below it is looking for a boolean and I used .b but I'm guessing .i would work just as well.
OSStatus SetDataBrowserHasScrollBars (
ControlRef browser,
Boolean horiz,
Boolean vert
);
In your example below I have no clue what 'UInt16 *height' means and how it relates to '@oldheight.u' that you put in, it would stop me from being able to use the api. I see what you put in but that answer is beyond me. Maybe I will ask you when I get stuck on my next api call. :|
OSStatus GetDataBrowserListViewHeaderBtnHeight (
ControlRef browser,
UInt16 *height
);

Code: Select all

ImportC ""
  SetDataBrowserListViewHeaderBtnHeight(Control.i, Height.u)
  GetDataBrowserListViewHeaderBtnHeight(Control.i, *Height.UNICODE)
  SetDataBrowserHasScrollBars(Control.i,horiz.b,vert.b) ; for scrollbars
EndImport

#noErr = 0

If OpenWindow(0, 100, 100, 350, 100, "NoColumnHeader & AutoSize", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListIconGadget(0, 5, 5, 340, 90, "", 200, #PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
  AddGadgetColumn(0, 1, "", 200)
  For X.l = 1 To 5
    AddGadgetItem(0, -1, "Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay")
    AddGadgetItem(0, -1, "Ginger Brokeit"+Chr(10)+"130 PureBasic Road, BigTown, CodeCity") 
  Next
  
  If GetDataBrowserListViewHeaderBtnHeight(GadgetID(0), @oldheight.u) = #noErr
    ; If you want the header back, call this again with 'oldheight' as last parameter 
    ; (if you never want to get the header back, you don't need the GetDataBrowserListViewHeaderBtnHeight() call at all)
    SetDataBrowserListViewHeaderBtnHeight(GadgetID(0), 0)
  EndIf
  SetDataBrowserHasScrollBars(GadgetID(0),#False,#True) ; no horizontal (bottom) scrollbar
  
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf

Re: ListIcon-remove column heading/scrollbars-api

Posted: Mon Jun 14, 2010 9:44 pm
by Shardik
WilliamL wrote:Below it is looking for a boolean and I used .b but I'm guessing .i would work just as well.
'.b' doesn't mean Boolean but Byte and it is no good idea to use it. Use '.i' instead
because the conversion from Byte to the native register size of your CPU (32 or
64 bits) could slow down your program (if used very often). As a boolean variable
can hold only two values (#True or #False) and only 1 bit would be required to
represent this value, 31 oder 63 bits are wasted. If you don't want to waste these
bits you could use bitwise operations to utilize each of those bits...
WilliamL wrote:In your example below I have no clue what 'UInt16 *height' means and how it relates to '@oldheight.u' that you put in, it would stop me from being able to use the api. I see what you put in but that answer is beyond me. Maybe I will ask you when I get stuck on my next api call. :|
If you take a look into the help (variables, types and operators) you will see that
'.u' declares a variable as type Unicode. 'UInt16' means Unsigned Integer with
16 Bits (2 bytes). PureBasic doesn't have "official" support for this variable type,
only '.w' which is a Signed Integer of 16 bits (2 bytes) ranging from -32768 to
32767.
So freak "misuses" the Unicode type which in reality is just what you need:
Unsigned integer of 16 bits (2 bytes) ranging from 0 to 65535 although the name
suggests that you can only use it with unicode characters which isn't true... :wink:

Re: ListIcon-remove column heading/scrollbars-api

Posted: Tue Jun 15, 2010 12:11 am
by WilliamL
HI, Shardik, nice hearing from you.

After looking through the Apple Developer documents, I think Freak just copied the code there that used the 'UInt16' variable and references in booleans. I think I read somewhere here on the forum that there wasn't a boolean type so we'll have to make do. I've been reading about unicode/unsigned variables, which is interesting, but I understand that .i will be the default for most efficient memory usage (speed).