Page 1 of 1

Focus/LostFocus solution for TreeGadget?

Posted: Thu Jan 03, 2013 3:44 am
by ozzie
I know there's been a Feature Request raised for Focus and LostFocus events to be raised for TreeGadgets, but since this isn't yet available in PB is there an alternative Windows solution for this?

In my program I want to allow the user to use Ctrl/C, Ctrl/V etc to copy and paste nodes in the TreeGadget. I can implement a KeyboardShortcut to handle this and check the active gadget for the TreeGadget, so that all works fine. But by doing this users then lose the ability to use normal copy and paste on text fields in the same window. So ideally I want to be able to add the keyboard shortcuts when the treegadget gains focus and remove the keyboard shortcuts when it loses focus.

Any ideas?

Re: Focus/LostFocus solution for TreeGadget?

Posted: Thu Jan 03, 2013 5:27 am
by RASHAD
- You can get the focused gadget using Tab or the Mouse
- You can use Ctrl+C & Ctrl+V with the Focused TreeGadget()
- And many more

Code: Select all

  If OpenWindow(0, 0, 0, 355, 300, "TreeGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    TreeGadget(0, 10, 10, 160, 160)                                         ; TreeGadget standard
    TreeGadget(1, 180, 10, 160, 160, #PB_Tree_CheckBoxes | #PB_Tree_NoLines)  ; TreeGadget with Checkboxes + NoLines
    For ID = 0 To 1
      For a = 0 To 10
        AddGadgetItem (ID, -1, "Normal Item "+Str(a), 0, 0) ; if you want to add an image, use
        AddGadgetItem (ID, -1, "Node "+Str(a), 0, 0)        ; ImageID(x) as 4th parameter
        AddGadgetItem(ID, -1, "Sub-Item 1", 0, 1)    ; These are on the 1st sublevel
        AddGadgetItem(ID, -1, "Sub-Item 2", 0, 1)
        AddGadgetItem(ID, -1, "Sub-Item 3", 0, 1)
        AddGadgetItem(ID, -1, "Sub-Item 4", 0, 1)
        AddGadgetItem (ID, -1, "File "+Str(a), 0, 0) ; sublevel 0 again
      Next
    Next
    ButtonGadget(2,10,270,60,20,"Test 2")
    ButtonGadget(3,80,270,60,20,"Test 3")
    tv.TV_HITTESTINFO
   
  Repeat
 
    Select WaitWindowEvent()

      Case #WM_LBUTTONDOWN
            Debug "Gadget : "+Str(GetProp_(GetFocus_(), "PB_ID")) + " Got The Focus"
           
      Case #WM_KEYUP
           If EventwParam() = 9
                Debug "Gadget : "+Str(GetProp_(GetFocus_(), "PB_ID")) + " Got The Focus"
            EndIf
           
      Case #WM_CHAR
            If GadgetType(GetActiveGadget()) = #PB_GadgetType_Tree           
                Focgad = GetActiveGadget()
                If EventwParam() = 3
                  Result$ = GetGadgetItemText(Focgad, GetGadgetState(Focgad))
                  Debug Result$
                EndIf               
                If EventwParam() = 22
                   SetGadgetItemText(Focgad, GetGadgetState(Focgad), Result$)
                EndIf
            EndIf
             
     
      Case #PB_Event_CloseWindow
            Quit = 1
       
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 0
              GetCursorPos_(@tv\pt)
              ScreenToClient_(GadgetID(0),@tv\pt)
              Debug "Item Handle : "+ Str(SendMessage_(GadgetID(0),#TVM_HITTEST,0,tv)) +" Got The Focus"
              Debug GetGadgetState(0)
             
         
            Case 1
              GetCursorPos_(@tv\pt)
              ScreenToClient_(GadgetID(0),@tv\pt)
              Debug "Item Handle : "+ Str(SendMessage_(GadgetID(1),#TVM_HITTEST,0,tv)) +" Got The Focus"
              Debug GetGadgetState(1)
             
        EndSelect
    EndSelect
  Until Quit = 1
  EndIf

Re: Focus/LostFocus solution for TreeGadget?

Posted: Thu Jan 03, 2013 12:04 pm
by ozzie
Many thanks, RASHAD. The #WM_CHAR event is all I need to use, so that's even better - I don't have to add and remove keyboard shortcuts, etc.

I'm just a bit puzzled by EventwParam(). It doesn't seem to be mentioned in the PB documentation apart from a reference in the 'History' section. Maybe I should raise this in the "Bugs - Documentation" forum.

Re: Focus/LostFocus solution for TreeGadget?

Posted: Thu Jan 03, 2013 1:57 pm
by Shardik
ozzie wrote:I'm just a bit puzzled by EventwParam(). It doesn't seem to be mentioned in the PB documentation apart from a reference in the 'History' section. Maybe I should raise this in the "Bugs - Documentation" forum.
Well, this is an old story. In many old postings it was mentioned not to use EventwParam() and EventlParam() because they are deprecated. But they are implemented in PB since version 2.4 and Andre has the inclusion of these commands in the help on his todo list since August 2009:
Andre wrote:- EventLParam() / EventWParam() : users are requesting manual descriptions for them, because they are included since PB 2.4 but still not officialy supported...
Fred posted:
Fred wrote:well, these two commands aren't 'officials' but it would probably hurt if we remove it as we can't replace it with something else. So it's still here..