Page 1 of 1

Editor Gadgets are EventGadget() Kings

Posted: Tue May 28, 2013 1:26 am
by IdeasVacuum
This is something I didn't know until now.

I have a Window with gadgets that mainly consist of StringGadgets and EditorGadgets. In the event loop, I want to detect which gadget the User has clicked on. However, until another gadget is clicked on, if an EditorGadget is there, it is the EventGadget() -even if, prior to starting the loop, another gadget is set as Active.

Code: Select all

Enumeration
#Win             ;0
#BtnExit         ;1
#Str01           ;2
#Str02           ;3
#Str03           ;4
#Editor01        ;5
EndEnumeration

Procedure Win()
;--------------
Protected iEvent.i, iGadget.i, iStop.i = #False

  If OpenWindow(#Win, 0, 0, 300, 240, "Editor Gadget Event", #PB_Window_TitleBar | #PB_Window_ScreenCentered)

             ButtonGadget(#BtnExit,  10, 200, 280, 30, "EXIT")
             StringGadget(#Str01,    10,  10, 280, 20, "#Str01")
             StringGadget(#Str02,    10,  40, 280, 20, "#Str02")
             StringGadget(#Str03,    10,  70, 280, 20, "#Str03")
             EditorGadget(#Editor01, 10, 100, 280, 90)
            SetGadgetText(#Editor01, "Editor01")
  EndIf

                SetActiveGadget(#BtnExit)

                Repeat
                             iEvent = WaitWindowEvent()
                      Select iEvent

                             Case #PB_Event_Gadget

                                           iGadget = EventGadget()
                                           Debug iGadget
                                        If(iGadget = #BtnExit)

                                                 iStop = #True
                                        Else
                                                 SetGadgetColor(iGadget,#PB_Gadget_BackColor,RGB(0,128,255))
                                        EndIf
                      EndSelect

                Until(iStop = #True)
EndProcedure

Win()

End
So, is there a way to prevent the Editor Gadget(s) being the EventGadget() until the User clicks on them - i.e. same behaviour as the string gadgets in the sample code?

Re: Editor Gadgets are EventGadget() Kings

Posted: Wed May 29, 2013 1:39 am
by IdeasVacuum
Well, here is my best solution so far: Make a hidden gadget active pre-loop and detect active gadgets (active when the are clicked) using GetActiveGadget().

Code: Select all

Enumeration
#Win             ;0
#BtnExit         ;1
#Str00           ;2
#Str01           ;3
#Str02           ;4
#Str03           ;5
#Editor01        ;6
EndEnumeration

Procedure Win()
;--------------
Protected iEvent.i, iGadget.i, iStop.i = #False

  If OpenWindow(#Win, 0, 0, 300, 240, "Editor Gadget Event", #PB_Window_TitleBar | #PB_Window_ScreenCentered)

             ButtonGadget(#BtnExit,  10, 200, 280, 30, "EXIT")
             StringGadget(#Str00,    10,  10, 280, 20, "#Str00")
               HideGadget(#Str00,#True)
             StringGadget(#Str01,    10,  10, 280, 20, "#Str01")
             StringGadget(#Str02,    10,  40, 280, 20, "#Str02")
             StringGadget(#Str03,    10,  70, 280, 20, "#Str03")
             EditorGadget(#Editor01, 10, 100, 280, 90)
            SetGadgetText(#Editor01, "Editor01")
  EndIf

                SetActiveGadget(#Str00)

                Repeat
                             iEvent = WaitWindowEvent()
                      Select iEvent

                             Case #PB_Event_Gadget

                                           iGadget = GetActiveGadget()
                                        If(iGadget = #BtnExit)

                                                 iStop = #True
                                        Else
                                                 SetGadgetColor(iGadget,#PB_Gadget_BackColor,RGB(0,128,255))
                                        EndIf
                      EndSelect

                Until(iStop = #True)
EndProcedure

Win()

End