And I have changed RASHAD's SetWindowLong() and GetWindowLong() against
SetWindowLongPtr() and GetWindowLongPtr() because Microsoft recommends:
Furthermore I have changed the flag value 4 to the official Microsoft constant LVS_SINGLESEL.MSDN wrote:Note To write code that is compatible with both 32-bit and 64-bit versions of Windows, use SetWindowLongPtr. When compiling for 32-bit Windows, SetWindowLongPtr is defined as a call to the SetWindowLong function.
Code: Select all
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
ImportC ""
GetDataBrowserSelectionFlags(ControlRef.L, *SelectionFlags)
SetDataBrowserSelectionFlags(ControlRef.L, SelectionFlags.L)
EndImport
CompilerEndIf
OpenWindow(0, 200, 100, 425, 118, "Toggle MultiSelection", #PB_Window_SystemMenu)
ListIconGadget(0, 5, 5, 415, WindowHeight(0) - 40, "Name", 110, #PB_ListIcon_FullRowSelect)
AddGadgetColumn(0, 1, "Address", 280)
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) - 180)/ 2, WindowHeight(0) - 30, 180, 25, "Enable MultiSelection")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
If EventGadget() = 1
If EventType() = #PB_EventType_LeftClick
MultiSelectEnabled ! 1
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
gtk_tree_selection_set_mode_(gtk_tree_view_get_selection_(GadgetID(0)), (MultiSelectEnabled << 1) | 1)
CompilerCase #PB_OS_MacOS
GetDataBrowserSelectionFlags(GadgetID(0), @SelectionFlags)
SetDataBrowserSelectionFlags(GadgetID(0), SelectionFlags ! 2)
CompilerCase #PB_OS_Windows
SetWindowLongPtr_(GadgetID(0), #GWL_STYLE, GetWindowLongPtr_(GadgetID(0), #GWL_STYLE) ! #LVS_SINGLESEL)
CompilerEndSelect
If MultiSelectEnabled
SetGadgetText(1, "Disable MultiSelection")
Else
SetGadgetText(1, "Enable MultiSelection")
EndIf
SetGadgetState(0, -1)
EndIf
EndIf
EndSelect
ForEver