NOCOLUMNHEADER & AUTOSIZE on Linux & Mac

Just starting out? Need help? Post your questions and find answers here.
sverson
Enthusiast
Enthusiast
Posts: 286
Joined: Sun Jul 04, 2004 12:15 pm
Location: Germany

NOCOLUMNHEADER & AUTOSIZE on Linux & Mac

Post by sverson »

How can I do this on Linux & Mac?

Code: Select all

If OpenWindow(0, 100, 100, 350, 100, "NoColumnHeader & AutoSize", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListIconGadget(0, 5, 5, 340, 90, "", 0, #PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection|#LVS_NOCOLUMNHEADER)
  AddGadgetColumn(0, 1, "", 0)
  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
  For X.l = 0 To 1
    SendMessage_(GadgetID(0),#LVM_SETCOLUMNWIDTH,X,#LVSCW_AUTOSIZE_USEHEADER) 
  Next
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: NOCOLUMNHEADER & AUTOSIZE on Linux & Mac

Post by Shardik »

I have modified your code to run in Windows and Linux. In Linux you don't need to adjust the
column size. It's the default setting. To disable the column headers you can use

Code: Select all

gtk_tree_view_set_headers_visible_(GadgetID(#ListIconGadget), #False)
In order to run in Linux and in Windows I had to define a column width greater than 0 because
Linux displays an error for a column size of 0. But that doesn't matter because afterwards the
column size will be adjusted... :wink:

Code: Select all

OpenWindow(0, 100, 100, 450, 100, "NoColumnHeader & AutoSize", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(0, 5, 5, 440, 90, "", 100, #PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(0, 1, "", 100)

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

CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Linux
    gtk_tree_view_set_headers_visible_(GadgetID(0), #False)
  CompilerCase #PB_OS_Windows
    SetWindowLong_(GadgetID(0), #GWL_STYLE, GetWindowLong_(GadgetID(0), #GWL_STYLE) | #LVS_NOCOLUMNHEADER)
    For X.l = 0 To 1
      SendMessage_(GadgetID(0),#LVM_SETCOLUMNWIDTH,X,#LVSCW_AUTOSIZE_USEHEADER)
    Next
CompilerEndSelect

Repeat
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
sverson
Enthusiast
Enthusiast
Posts: 286
Joined: Sun Jul 04, 2004 12:15 pm
Location: Germany

Re: NOCOLUMNHEADER & AUTOSIZE on Linux & Mac

Post by sverson »

Thanks Shardik.

This is exactly what I was looking for. :)
Now just the mac code is missing. :(
Shardik wrote:In order to run in Linux and in Windows I had to define a column width greater than 0 because Linux displays an error for a column size of 0.
Yes - sad thing in some cases - this is another one I need to solve. - Does anyone konw how to hide a column permamently on linux (& mac) :?:
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: NOCOLUMNHEADER & AUTOSIZE on Linux & Mac

Post by Shardik »

sverson wrote:Does anyone konw how to hide a column permamently on linux
That's very easy:

Code: Select all

OpenWindow(0, 100, 100, 410, 115, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(0, 5, 5, 400, 75, "Name", 100, #PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(0, 1, "Address", 250)
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")
ButtonGadget(1, 155, 85, 120, 25, "Hide Column 0")
*Column0.GtkTreeViewColumn = gtk_tree_view_get_column_(GadgetID(0), 0)

Repeat
  Event = WaitWindowEvent()

  If Event = #PB_Event_Gadget
    If EventGadget() = 1
      Column0State = gtk_tree_view_column_get_visible_(*Column0)
      gtk_tree_view_column_set_visible_(*Column0, Column0State ! 1)

      If Column0State
        SetGadgetText(1, "Display Column 0")
      Else
        SetGadgetText(1, "Hide Column 0")
      EndIf
    EndIf
  EndIf
Until Event = #PB_Event_CloseWindow
sverson
Enthusiast
Enthusiast
Posts: 286
Joined: Sun Jul 04, 2004 12:15 pm
Location: Germany

Re: NOCOLUMNHEADER & AUTOSIZE on Linux & Mac

Post by sverson »

Thanks again.
Works great!
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: NOCOLUMNHEADER & AUTOSIZE on Linux & Mac

Post by freak »

Hide the header on the mac:

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
There is no way to autosize the columns by content (only by some predefined min/max values). I suggest to choose a fixed column with which you think makes sense for your data and then apply the autosize only for the OS that support it.
quidquid Latine dictum sit altum videtur
sverson
Enthusiast
Enthusiast
Posts: 286
Joined: Sun Jul 04, 2004 12:15 pm
Location: Germany

Re: NOCOLUMNHEADER & AUTOSIZE on Linux & Mac

Post by sverson »

Thanks for your help, Freak.
Will test it asap.
Post Reply