Page 1 of 1
Treegadget doubleclick - annoying expand/collapse
Posted: Thu Mar 08, 2012 5:46 pm
by auser
How can I be sure via PureBasic if a doubleclick on a treegadgetitem was done?
My (simple) plan is "If somebody doubleclick this GadgetItem in a TreeGadget then do something".
But here is my problem:
*)I don't know exactly which TreeItem was double-clicked. I just know that a double-click was done and I know the current selected element.
**) Workaround: Wait until double-click on TreeGadget was done and then check which item of the treegadget is currently selected.
***) Problem of workaround: If somebody does not double-click a real gadgetitem but just the expand-collapse-box instead then no select was done and I get a false-positive. For example: A user selected the 10th treeitem previously and later "double-clicks" on the expand-box [+] of the 3rd item (in fact he just fast expands and collapses and never selected it) then it seems for my program that element 10 was double-clicked (which is wrong) because I still only know that the treegadget was double-clicked and that (still) item 10 is selected.
So how can I get sure that only a real double-click on an item of the TreeGadget would be processed as such? It looks really buggy if somebody selects some item at bottom of the tree and then expands/collapses fast an item at the top of the treegadget that the program would start stuff that just should happen if the element at bottom would be double-clicked.
My theory was to use that gui for Windows and Linux.
Any ideas?
Greetings,
auser
Re: Treegadget doubleclick - annoying expand/collapse
Posted: Fri Mar 09, 2012 4:04 am
by citystate
use a callback and consume the doubleclick event?
Re: Treegadget doubleclick - annoying expand/collapse
Posted: Fri Mar 09, 2012 8:05 am
by auser
citystate wrote:use a callback and consume the doubleclick event?
Sounds like a workaround that would not work in linux. This is really frustrating (again). Isn't it a basic-requirement to know which item was double-clicked? What should I do with a gadget that I can't check afterwards (no I don't know what happend just something happened)? What should I do with a language that could compile something on different platforms (linux, windows) when it get stuck already at such basics? Sometimes I get the feeling almost nobody is using PB seriously. At least the current behaviour does not make sense at all. Nobody would know a double-click on an expand-collapse-box but there might be a chance that somebody would really use the TreeGadget.
Re: Treegadget doubleclick - annoying expand/collapse
Posted: Fri Mar 09, 2012 8:00 pm
by utopiomania
del
Re: Treegadget doubleclick - annoying expand/collapse
Posted: Mon Mar 12, 2012 8:28 am
by auser
utopiomania wrote:I'm not shure I understand the problem, is this a Linux issue?
Run the code below(read the app title) and tell me whats wrong with how
it behaves?
Even your example is working wrong. To reproduce:
Leftclick item 60 so it is selected. Then move mouse-cursor upwards and left-double-click the first expandbox (don't double-click the first item itself but just the expandbox [+] --> [-] --> [+] on the leftside). The result in the title-bar (since element 60 is still selected): "60 0 left double-click". And that's wrong. You did not double-click element 60 but you just expand->collapse->expanded the subtree below element 1. So in fact nothing should happen. But your program would think you have double-clicked item 60. Because all you know is: There was a double-click (in that case on an expandbox of 1 element) and and element is selected (in that case still item 60) which you get with "ndx = GetGadgetState(#TREE)". That's too less and even produces wrong results in your code.
You can workaround this stuff in windows with a callback, looking for #TVN_ITEMEXPANDED - (if left_doubleclick and something_expanded then continue) but for sure this would make it incompatible for Linux and that sucks - because a treegadget where you have to guesswork what happens inside afterwards is crap.
Re: Treegadget doubleclick - annoying expand/collapse
Posted: Mon Mar 12, 2012 3:26 pm
by Shardik
auser wrote:You can workaround this stuff in windows with a callback, looking for #TVN_ITEMEXPANDED - (if left_doubleclick and something_expanded then continue) but for sure this would make it incompatible for Linux and that sucks - because a treegadget where you have to guesswork what happens inside afterwards is crap.
What's so difficult in using API calls for Windows
and Linux?
Code: Select all
EnableExplicit
Define i.I
Define SubtreeExpandedOrCollapsed.I
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
ProcedureC ExpandAndCollapseCallback(*TreeView, *Iter, *Path, UserData.I)
Shared SubtreeExpandedOrCollapsed.I
SubtreeExpandedOrCollapsed = #True
EndProcedure
CompilerCase #PB_OS_Windows
Procedure WindowCallback(WindowHandle, Msg, WParam, LParam)
Shared SubtreeExpandedOrCollapsed.I
Protected *NMTV.NM_TREEVIEW
Protected TVHitTest.TV_HITTESTINFO
If Msg = #WM_NOTIFY
*NMTV = LParam
If *NMTV\hdr\code = #TVN_ITEMEXPANDED
TVHitTest\Pt\x = WindowMouseX(0) - GadgetX(0)
TVHitTest\Pt\y = WindowMouseY(0) - GadgetY(0)
If SendMessage_(GadgetID(0), #TVM_HITTEST, 0, @TVHitTest) <> 0
If TVHitTest\Flags = #TVHT_ONITEMBUTTON
SubtreeExpandedOrCollapsed = #True
EndIf
EndIf
EndIf
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
CompilerEndSelect
OpenWindow(0, 100, 100, 300, 200, "Waiting for double clicks...", #PB_Window_SystemMenu)
TreeGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20)
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
g_signal_connect_data_(GadgetID(0), "row-collapsed", @ExpandAndCollapseCallback(), 0, 0, 0)
g_signal_connect_data_(GadgetID(0), "row-expanded", @ExpandAndCollapseCallback(), 0, 0, 0)
CompilerCase #PB_OS_Windows
SetWindowCallback(@WindowCallback())
CompilerEndSelect
For i = 1 To 2
AddGadgetItem(0, -1, "Node " + Str(i), 0, 0)
AddGadgetItem(0, -1, "Subitem 1", 0, 1)
AddGadgetItem(0, -1, "Subitem 2", 0, 1)
AddGadgetItem(0, -1, "Subitem 3", 0, 1)
Next i
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
SetWindowCallback(0)
CompilerEndIf
Break
Case #PB_Event_Gadget
Select EventType()
Case #PB_EventType_LeftClick
SubtreeExpandedOrCollapsed = #False
Case #PB_EventType_LeftDoubleClick
If SubtreeExpandedOrCollapsed
SetWindowTitle(0, "Double click on expand box")
SubtreeExpandedOrCollapsed = #False
Else
SetWindowTitle(0, "Double click on " + GetGadgetText(0))
EndIf
EndSelect
EndSelect
ForEver
Re: Treegadget doubleclick - annoying expand/collapse
Posted: Mon Mar 12, 2012 5:47 pm
by RASHAD
Hi
The next code is for Windows only ,sorry
It is for how to identify which item was clicked
Maybe Shardik can adapt it for Linux & Mac
Code: Select all
If OpenWindow(0, 0, 0, 400, 600, "TreeGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
TreeGadget(0, 10, 10, 200, 580)
For a = 0 To 10
AddGadgetItem (0, -1, "Normal Item "+Str(a), 0, 0)
AddGadgetItem (0, -1, "Node "+Str(a), 0, 0)
AddGadgetItem(0, -1, "Sub-Item 1", 0, 1)
AddGadgetItem(0, -1, "Sub-Item 2", 0, 1)
AddGadgetItem(0, -1, "Sub-Item 3", 0, 1)
AddGadgetItem(0, -1, "Sub-Item 4", 0, 1)
AddGadgetItem (0, -1, "File "+Str(a), 0, 0)
Next
t.TV_HITTESTINFO
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 0
GetCursorPos_(@t\pt)
ScreenToClient_(GadgetID(0),@t\pt)
SendMessage_(GadgetID(0),#TVM_HITTEST,0,t)
SendMessage_(GadgetID(0),#TVM_SELECTITEM,#TVGN_CARET,t\hItem)
Result = GetGadgetState(0);
If GetGadgetItemState(0, Result) & #PB_Tree_Collapsed
MessageRequester("Info", "Item "+Str(Result)+" is : Collapsed")
ElseIf GetGadgetItemState(0, Result) & #PB_Tree_Expanded
MessageRequester("Info", "Item "+Str(Result)+" is : Expanded")
EndIf
EndSelect
EndSelect
Until Quit = 1
EndIf
Re: Treegadget doubleclick - annoying expand/collapse
Posted: Tue Mar 13, 2012 10:06 am
by auser
Shardik wrote:
What's so difficult in using API calls for Windows
and Linux?
You mean what is so difficult to implement 2 different kind of callbacks as a workaround for 2 OS just because you would really know which item was double-clicked in a treegadget (which is a very basic requirement)? Yes for sure... what's so diffecult to do so.
Code: Select all
EnableExplicit
Define i.I
Define SubtreeExpandedOrCollapsed.I
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
ProcedureC ExpandAndCollapseCallback(*TreeView, *Iter, *Path, UserData.I)
Shared SubtreeExpandedOrCollapsed.I
SubtreeExpandedOrCollapsed = #True
EndProcedure
CompilerCase #PB_OS_Windows
Procedure WindowCallback(WindowHandle, Msg, WParam, LParam)
Shared SubtreeExpandedOrCollapsed.I
Protected *NMTV.NM_TREEVIEW
Protected TVHitTest.TV_HITTESTINFO
If Msg = #WM_NOTIFY
*NMTV = LParam
If *NMTV\hdr\code = #TVN_ITEMEXPANDED
TVHitTest\Pt\x = WindowMouseX(0) - GadgetX(0)
TVHitTest\Pt\y = WindowMouseY(0) - GadgetY(0)
If SendMessage_(GadgetID(0), #TVM_HITTEST, 0, @TVHitTest) <> 0
If TVHitTest\Flags = #TVHT_ONITEMBUTTON
SubtreeExpandedOrCollapsed = #True
EndIf
EndIf
EndIf
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
CompilerEndSelect
OpenWindow(0, 100, 100, 300, 200, "Waiting for double clicks...", #PB_Window_SystemMenu)
TreeGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20)
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
g_signal_connect_data_(GadgetID(0), "row-collapsed", @ExpandAndCollapseCallback(), 0, 0, 0)
g_signal_connect_data_(GadgetID(0), "row-expanded", @ExpandAndCollapseCallback(), 0, 0, 0)
CompilerCase #PB_OS_Windows
SetWindowCallback(@WindowCallback())
CompilerEndSelect
For i = 1 To 2
AddGadgetItem(0, -1, "Node " + Str(i), 0, 0)
AddGadgetItem(0, -1, "Subitem 1", 0, 1)
AddGadgetItem(0, -1, "Subitem 2", 0, 1)
AddGadgetItem(0, -1, "Subitem 3", 0, 1)
Next i
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
SetWindowCallback(0)
CompilerEndIf
Break
Case #PB_Event_Gadget
Select EventType()
Case #PB_EventType_LeftClick
SubtreeExpandedOrCollapsed = #False
Case #PB_EventType_LeftDoubleClick
If SubtreeExpandedOrCollapsed
SetWindowTitle(0, "Double click on expand box")
SubtreeExpandedOrCollapsed = #False
Else
SetWindowTitle(0, "Double click on " + GetGadgetText(0))
EndIf
EndSelect
EndSelect
ForEver
Nice one. Thx for sharing. I had already code implemented for windows to workaround the lack of PB. Your code seems working on linux as well.
Greetings,
auser
Re: Treegadget doubleclick - annoying expand/collapse
Posted: Wed Mar 14, 2012 11:06 am
by utopiomania
60 0 left double-click". And that's wrong. You did not double-click element 60 but you just expand->collapse->expanded the subtree below element 1
The title doesn't say I doubleclicked element 60, just that a doubleclick event occurred, and that element 60 is still selected. Both are correct.