Try this procedure which works in Windows and Linux. If time allows I will try to supplement
the code for MacOS this evening.
@csk,
one small demand: please change the topic text from "Beginner's questions" to something
more informative, for example "Cross-platform justification of ListIconGadget columns". If
someone later tries to find a solution to this problem he probably won't look for a topic
"Beginner's questions"
Code: Select all
EnableExplicit
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
ImportC ""
g_object_set_double(*Object, Property.P-ASCII, Value.D, Null) As "g_object_set"
EndImport
CompilerEndIf
Enumeration
#PB_ListIcon_JustifyColumnLeft
#PB_ListIcon_JustifyColumnCenter
#PB_ListIcon_JustifyColumnRight
EndEnumeration
Procedure SetListIconColumnJustification(ListIconID, Column, Alignment)
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
Protected AlignmentFactor.D
Protected *CellRenderers
Protected *Column
Protected Count
Protected i
Select Alignment
Case #PB_ListIcon_JustifyColumnLeft
AlignmentFactor = 0.0
Case #PB_ListIcon_JustifyColumnCenter
AlignmentFactor = 0.5
Case #PB_ListIcon_JustifyColumnRight
AlignmentFactor = 1.0
EndSelect
*Column = gtk_tree_view_get_column_(GadgetID(ListIconID), Column)
If *Column
gtk_tree_view_column_set_alignment_(*Column, AlignmentFactor)
*CellRenderers = gtk_tree_view_column_get_cell_renderers_(*Column)
If *CellRenderers
Count = g_list_length_(*CellRenderers)
For i = 0 To Count - 1
g_object_set_double(g_list_nth_data_(*CellRenderers, i), "xalign", AlignmentFactor, #Null)
Next i
g_list_free_(*CellRenderers)
EndIf
EndIf
CompilerCase #PB_OS_Windows
Protected ListIconColumn.LV_COLUMN
ListIconColumn\mask = #LVCF_FMT
Select Alignment
Case #PB_ListIcon_JustifyColumnLeft
ListIconColumn\fmt = #LVCFMT_LEFT
Case #PB_ListIcon_JustifyColumnCenter
ListIconColumn\fmt = #LVCFMT_CENTER
Case #PB_ListIcon_JustifyColumnRight
ListIconColumn\fmt = #LVCFMT_RIGHT
EndSelect
SendMessage_(GadgetID(ListIconID), #LVM_SETCOLUMN, Column, @ListIconColumn)
CompilerEndSelect
EndProcedure
OpenWindow(0, 200, 100, 430, 85, "Change column justification")
ListIconGadget(0, 5, 5, 420, 75, "Name", 100)
AddGadgetColumn(0, 1, "Address", 310)
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")
SetListIconColumnJustification(0, 0, #PB_ListIcon_JustifyColumnRight)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Update 1: Sorry, I forgot to include an Import statement for the Linux version.
I have added that and for clarity I changed the constants from a simple #Right
etc. to #PB_ListIcon_JustifyColumnRight etc. and changed the procedure name
from SetColumnAlignment() to SetListIconColumnJustification(). Furthermore I
added a simple example so that this code is runnable at once without change...