Set minimum and maximum column width of ListIconGadget
Posted: Thu Dec 08, 2011 7:43 pm
In MacOS it is possible to limit the column width of a ListIconGadget
to a specified minimum and maximum value using API functions. Try
to change the column width of the Address column in the following
example before and after clicking onto the button:
to a specified minimum and maximum value using API functions. Try
to change the column width of the Address column in the following
example before and after clicking onto the button:
Code: Select all
EnableExplicit
ImportC ""
CFRelease(CFTypeRef.L)
GetDataBrowserListViewHeaderDesc(DataBrowserRef.L, ColumnID.L, *HeaderDesc)
GetDataBrowserTableViewColumnProperty(DataBrowserRef.L, Column.L, *ColumnID)
SetDataBrowserListViewHeaderDesc(DataBrowserRef.L, ColumnID.L, *HeaderDesc)
EndImport
Structure RGBColor
Red.U
Green.U
Blue.U
EndStructure
Structure ControlFontStyleRec
Flags.W
Font.W
Size.W
Style.W
Mode.W
Just.W
ForeColor.RGBColor
BackColor.RGBColor
EndStructure
Structure DataBrowserListViewHeaderDesc
Version.L
MinimumColumnWidth.U
MaximumColumnWidth.U
TitleOffset.W
CFTitleString.L
InitialSortOrder.L
FontStyle.ControlFontStyleRec
IconInfo.L
EndStructure
Procedure LimitColumnWidth(ListIconID.L, Column.L, MinimumWidth.U, MaximumWidth.U)
Protected ColumnID.L
Protected HeaderDesc.DataBrowserListViewHeaderDesc
If GetDataBrowserTableViewColumnProperty(GadgetID(ListIconID), Column, @ColumnID) = 0
If GetDataBrowserListViewHeaderDesc(GadgetID(ListIconID), ColumnID, @HeaderDesc) = 0
Debug "Previous column width:"
Debug "Minimum = " + Str(HeaderDesc\MinimumColumnWidth) + ", Maximum = " + Str(HeaderDesc\MaximumColumnWidth)
HeaderDesc\MinimumColumnWidth = MinimumWidth
HeaderDesc\MaximumColumnWidth = MaximumWidth
SetDataBrowserListViewHeaderDesc(GadgetID(ListIconID), ColumnID, @HeaderDesc)
Debug "New column width:"
Debug "Minimum = " + Str(MinimumWidth) + ", maximum = " + Str(MaximumWidth)
CFRelease(HeaderDesc\CFTitleString)
EndIf
EndIf
EndProcedure
OpenWindow(0, 270, 100, 445, 120, "Limit minimum and maximum width of Address column")
ListIconGadget(0, 5, 5, 435, 80, "Name", 110)
AddGadgetColumn(0, 1, "Address", 304)
AddGadgetItem(0, -1, "Harry Rannit" + #LF$ + "12 Parliament Way, Battle Street, By the Bay")
AddGadgetItem(0, -1, "Ginger Brokeit" + #LF$ + "130 PureBasic Road, BigTown, CodeCity")
ButtonGadget(1, WindowWidth(0)/ 2 - 80, WindowHeight(0) - 30, 160, 20, "Limit column width")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
If EventGadget() = 1
If EventType() = #PB_EventType_LeftClick
LimitColumnWidth(0, 1, 100, 304)
DisableGadget(1, #True)
EndIf
EndIf
EndSelect
ForEver