Treegadget problem...

Just starting out? Need help? Post your questions and find answers here.
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

Hi guys! I appologise i wasn't more explicit about what i wanted... Sparkie, that's exactly what i had in mind... Thank you both for saving me again :).

Code: Select all

AddElement(Saved())
Saved()\Names = "Sparkie, Srod"
Saved()\Times + 1
:D
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Code: Select all

GetWrongEndOfStick$ = "srod"
For i = 1 to 10000
  PrintN(GetWrongEndOfStick$)
  KickSrodUpTheArse + 1
Next
:)
I may look like a mule, but I'm not a complete ass.
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

There is a problem... If you press space on a such modified item, a checkbox appears... :)
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

That confirms that Windows cycles around the stateicon images!

A quick fix simply discards key presses. Not very subtle and probably not very practical for many purposes which would require something more sophisticated.

Code: Select all

Global oldproc

Procedure RemoveTVIcheckbox(tvGadget, item) 
  tvi.TV_ITEM 
  tvi\mask = #TVIF_HANDLE | #TVIF_STATE 
  tvi\hItem = GadgetItemID(tvGadget, item) 
  tvi\state = 0 << 12 
  tvi\stateMask = #TVIS_STATEIMAGEMASK 
  SendMessage_(GadgetID(1), #TVM_SETITEM, 0, tvi) 
EndProcedure 

Procedure Callback(hWnd, uMsg, wParam, lParam)
  Protected result
  Select uMsg
    Case #WM_KEYDOWN
      result=0
    Case #WM_CHAR ;Stop the infernal beeping!
      result=0
    Default
      result=CallWindowProc_(oldproc, hWnd, uMsg, wParam, lParam)
  EndSelect
  ProcedureReturn Result
EndProcedure

If OpenWindow(0, 0, 0, 400, 380, "TreeGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0)) 
  TreeGadget(1, 180, 10, 160, 360, #PB_Tree_CheckBoxes) 
  For a = 0 To 4 
    AddGadgetItem (1, -1, "Normal Item "+Str(a), 0, 0) 
    AddGadgetItem (1, -1, "Node "+Str(a), 0, 0) 
    AddGadgetItem(1, -1, "Sub-Item 1", 0, 1) 
    AddGadgetItem(1, -1, "Sub-Item 2", 0, 1) 
    AddGadgetItem(1, -1, "Sub-Item 3", 0, 1) 
    AddGadgetItem(1, -1, "Sub-Item 4", 0, 1) 
    AddGadgetItem (1, -1, "File "+Str(a), 0, 0) 
  Next a 
  RemoveTVIcheckbox(1, 1) 
  RemoveTVIcheckbox(1, 6) 
  For i = 8 To 12 
    RemoveTVIcheckbox(1, i) 
  Next i 
  SetGadgetItemState(1, 8, #PB_Tree_Expanded) 
  oldproc=SetWindowLong_(GadgetID(1), #GWL_WNDPROC, @callback())

  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow 
EndIf 
I may look like a mule, but I'm not a complete ass.
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

U are a saint! (and you're added to the credits ;) )

10X!

P.S. Sparkie is added too :)
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Sparkie wrote::?:

Code: Select all

Procedure RemoveTVIcheckbox(tvGadget, item)
  tvi.TV_ITEM
  tvi\mask = #TVIF_HANDLE | #TVIF_STATE 
  tvi\hItem = GadgetItemID(tvGadget, item)
  tvi\state = 0 << 12
  tvi\stateMask = #TVIS_STATEIMAGEMASK 
  SendMessage_(GadgetID(1), #TVM_SETITEM, 0, tvi)
EndProcedure

If OpenWindow(0, 0, 0, 400, 380, "TreeGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
  TreeGadget(1, 180, 10, 160, 360, #PB_Tree_CheckBoxes)
  For a = 0 To 4
    AddGadgetItem (1, -1, "Normal Item "+Str(a), 0, 0)
    AddGadgetItem (1, -1, "Node "+Str(a), 0, 0)
    AddGadgetItem(1, -1, "Sub-Item 1", 0, 1)
    AddGadgetItem(1, -1, "Sub-Item 2", 0, 1)
    AddGadgetItem(1, -1, "Sub-Item 3", 0, 1)
    AddGadgetItem(1, -1, "Sub-Item 4", 0, 1)
    AddGadgetItem (1, -1, "File "+Str(a), 0, 0)
  Next a
  RemoveTVIcheckbox(1, 1)
  RemoveTVIcheckbox(1, 6)
  For i = 8 To 12
    RemoveTVIcheckbox(1, i)
  Next i
  SetGadgetItemState(1, 8, #PB_Tree_Expanded)
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Here is something wierd:
Item index 8 , named as 'Node 1' has the checkbox, but the code removes it. Commenting line

Code: Select all

SetGadgetItemState(1, 8, #PB_Tree_Expanded)
it works as expected.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

Happends here too, and i removed that line too. It seems that if it refreshes, the checkboxes reappear :? .
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Ah, a bug with Purebasic. Purebasic is resetting the stateicon index.

You can see it better with the following:

Code: Select all

If OpenWindow(0, 0, 0, 400, 380, "TreeGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0)) 
  TreeGadget(1, 180, 10, 160, 360, #PB_Tree_CheckBoxes) 
    AddGadgetItem (1, -1, "Normal Item "+Str(a), 0, 0) 
    AddGadgetItem(1, -1, "Sub-Item 1", 0, 1) 
    AddGadgetItem(1, -1, "Sub-Item 2", 0, 1) 
    AddGadgetItem(1, -1, "Sub-Item 3", 0, 1) 
    AddGadgetItem(1, -1, "Sub-Item 4", 0, 1) 
  SetGadgetItemState(1, 0, #PB_Tree_Checked)
  SetGadgetItemState(1, 0, #PB_Tree_Expanded) 
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow 
EndIf
The SetGadgetItemState(1, 0, #PB_Tree_Expanded) command is clearing the checkmark!

Best post this in the bug section.

@Info: if you don't need to use the SetGadgetItemState(1, 0, #PB_Tree_Expanded) command then you should be fine. I'd say it's most likely a PB issue rather than a Windows one.
Last edited by srod on Sat Dec 09, 2006 11:22 pm, edited 2 times in total.
I may look like a mule, but I'm not a complete ass.
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

Ok :).
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Yes I've run some identical code using pure api (i.e. removed the SetGadgetItemState(1, 0, #PB_Tree_Expanded) and replaced it with api) and it works fine.

Definitely a PB issue.
I may look like a mule, but I'm not a complete ass.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Hi, I've reported the bug about the Sparkie snippet
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Already reported and Freak has explained that it is not actually a bug, just a misuse of SetGadgetItemState() !

I should have realised. Reckon I should start going to bed earlier! :)
I may look like a mule, but I'm not a complete ass.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

srod wrote:Already reported and Freak has explained that it is not actually a bug, just a misuse of SetGadgetItemState() !

I should have realised. Reckon I should start going to bed earlier! :)
Sorry, what i report is not the same.

Inf0Byt3 report is about the check mark inside the checkbox appear or dissappear.

My report is about the checkbox itself appear or dissappear.

You see?
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

It actually amounts to the same thing, as Sparkie's code is a bit of a cheat to remove the checkmark box from a treeview which does have the #TVS_CHECKBOXES style after all - which is a slight abuse! :) So I think that Freak's response already explains this one as PB just resets the imagestate icon in response to SetGadgetItemState(....#PB_Tree_Expanded) etc. i.e. in the absence of #PB_Tree_Checked.
I may look like a mule, but I'm not a complete ass.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

srod wrote:It actually amounts to the same thing, as Sparkie's code is a bit of a cheat to remove the checkmark box from a treeview which does have the #TVS_CHECKBOXES style after all - which is a slight abuse! :) So I think that Freak's response already explains this one as PB just resets the imagestate icon in response to SetGadgetItemState(....#PB_Tree_Expanded) etc. i.e. in the absence of #PB_Tree_Checked.
may be ok, but sorry: that Freak answer is far to be valid for my report.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Post Reply