Change Gadget Flags
- electrochrisso
- Addict
- Posts: 989
- Joined: Mon May 14, 2007 2:13 am
- Location: Darling River
Change Gadget Flags
Is it possible to change gadget flags on the fly.
I want to be able to switch between having #PB_ListIcon_MultiSelect on or off between play and stop modes on the MP3 player app I am playing around with.
Currently I set up two ListIcon Gadgets and use a bit of extra code to keep the changes in sync with each other, which is a little noticeable when switching between the gadgets using show and hide.
I want to be able to switch between having #PB_ListIcon_MultiSelect on or off between play and stop modes on the MP3 player app I am playing around with.
Currently I set up two ListIcon Gadgets and use a bit of extra code to keep the changes in sync with each other, which is a little noticeable when switching between the gadgets using show and hide.
PureBasic! Purely the best 

Re: Change Gadget Flags
Hi
Code: Select all
OpenWindow(0, 0, 0, 640, 300, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(0, 10, 10, 620, 250, "Column 0", 100,#PB_ListIcon_FullRowSelect |#PB_ListIcon_GridLines)
For b = 1 To 5
AddGadgetColumn(a, b, "Column " + Str(b), 100)
Next
For b = 0 To 5
AddGadgetItem(a, b, "Item 1"+Chr(10)+"Item 1"+Chr(10)+"Item 2"+Chr(10)+"Item 3"+Chr(10)+"Item 4"+Chr(10)+"Item 5"+Chr(10)+"Item 6")
Next
ButtonGadget(1, 10,270,100,20,"TEST",#PB_Button_Toggle)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Q = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 1
Run = Run ! 1
If Run = 0
SetWindowLong_(GadgetID(0), #GWL_STYLE, GetWindowLong_(GadgetID(0), #GWL_STYLE)|#PB_ListIcon_MultiSelect)
Else
SetWindowLong_(GadgetID(0), #GWL_STYLE, GetWindowLong_(GadgetID(0), #GWL_STYLE)&~#PB_ListIcon_MultiSelect)
EndIf
EndSelect
EndSelect
Until Q = 1
Egypt my love
- electrochrisso
- Addict
- Posts: 989
- Joined: Mon May 14, 2007 2:13 am
- Location: Darling River
Re: Change Gadget Flags
Thanks for that RASHAD
I thinks you should be nominated the Master of API

I thinks you should be nominated the Master of API

PureBasic! Purely the best 

Re: Change Gadget Flags
Thank you RASHAD for your helpful example. And you can even shorten it by replacing this code blockby just one line
I have written a new example which also works in Linux (this evening I will try to find a solution for the Mac, so that this example will become truely cross-platform):
Code: Select all
Run = Run ! 1
If Run = 0
SetWindowLong_(GadgetID(0), #GWL_STYLE, GetWindowLong_(GadgetID(0), #GWL_STYLE)|#PB_ListIcon_MultiSelect)
Else
SetWindowLong_(GadgetID(0), #GWL_STYLE, GetWindowLong_(GadgetID(0), #GWL_STYLE)&~#PB_ListIcon_MultiSelect)
EndIf
Code: Select all
SetWindowLong_(GadgetID(0), #GWL_STYLE, GetWindowLong_(GadgetID(0), #GWL_STYLE) ! 4)
Code: Select all
OpenWindow(0, 200, 100, 420, 112, "Toggle MultiSelection", #PB_Window_SystemMenu)
ListIconGadget(0, 5, 5, 410, WindowHeight(0) - 40, "Name", 100, #PB_ListIcon_FullRowSelect)
AddGadgetColumn(0, 1, "Address", 250)
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_Windows
SetWindowLong_(GadgetID(0), #GWL_STYLE, GetWindowLong_(GadgetID(0), #GWL_STYLE) ! 4)
CompilerEndSelect
If MultiSelectEnabled
SetGadgetText(1, "Disable MultiSelection")
Else
SetGadgetText(1, "Enable MultiSelection")
EndIf
SetGadgetState(0, -1)
EndIf
EndIf
EndSelect
ForEver
Re: Change Gadget Flags
Thanks Shardik
You are the Three Phase Pro
My way to show electrochrisso the case how to enable or disable PB_ListIcon_MultiSelect
Maybe he will not use a toggle button
For anybody to be not confused
You are the Three Phase Pro
My way to show electrochrisso the case how to enable or disable PB_ListIcon_MultiSelect
Maybe he will not use a toggle button
For anybody to be not confused
Code: Select all
! 4 = ! #PB_ListIcon_MultiSelect
Egypt my love
Re: Change Gadget Flags
Thank you RASHAD for your remark. It's always a good practice to use the constantRASHAD wrote:For anybody to be not confused
Code: Select all
! 4 = ! #PB_ListIcon_MultiSelect
name and not the numeric value. Should there be a change in the API you don't have
to change all your codes if the PB devs have changed the definition of the constant...

- electrochrisso
- Addict
- Posts: 989
- Joined: Mon May 14, 2007 2:13 am
- Location: Darling River
Re: Change Gadget Flags
I have implemented using these two from RASHAD and working ok so far.
SetWindowLong_(GadgetID(0), #GWL_STYLE, GetWindowLong_(GadgetID(0), #GWL_STYLE)|#PB_ListIcon_MultiSelect)
SetWindowLong_(GadgetID(0), #GWL_STYLE, GetWindowLong_(GadgetID(0), #GWL_STYLE)&~#PB_ListIcon_MultiSelect)
All I am doing is to switch between MultiSelect mode and no MultiSelect mode in the ListIcon depending on Play and Stop modes for my MP3 player app.
Thank you too Shardik, I will play around with your input and see what I come up with.
SetWindowLong_(GadgetID(0), #GWL_STYLE, GetWindowLong_(GadgetID(0), #GWL_STYLE)|#PB_ListIcon_MultiSelect)
SetWindowLong_(GadgetID(0), #GWL_STYLE, GetWindowLong_(GadgetID(0), #GWL_STYLE)&~#PB_ListIcon_MultiSelect)
All I am doing is to switch between MultiSelect mode and no MultiSelect mode in the ListIcon depending on Play and Stop modes for my MP3 player app.
Thank you too Shardik, I will play around with your input and see what I come up with.
PureBasic! Purely the best 

Re: Change Gadget Flags
I have expanded my above cross-platform example to also work on the Mac.
And I have changed RASHAD's SetWindowLong() and GetWindowLong() against
SetWindowLongPtr() and GetWindowLongPtr() because Microsoft recommends:
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
- electrochrisso
- Addict
- Posts: 989
- Joined: Mon May 14, 2007 2:13 am
- Location: Darling River