PureBasic Forum
https://www.purebasic.fr/english/

How to detect double click on TextGadget()?
https://www.purebasic.fr/english/viewtopic.php?f=19&t=73743
Page 1 of 2

Author:  Wolfram [ Sat Oct 05, 2019 1:35 pm ]
Post subject:  How to detect double click on TextGadget()?

I want to edit the text of a TextGadget().
To do that I need to detect a double click on it so I can swop the gadget with a string gadget.

Any ideas how to do that?

Author:  chi [ Sat Oct 05, 2019 2:42 pm ]
Post subject:  Re: How to detect double click on TextGadget()?

On Windows you can add #SS_NOTIFY to the TextGadget... Maybe there is something similar for OSX?!

Author:  mk-soft [ Sat Oct 05, 2019 6:40 pm ]
Post subject:  Re: How to detect double click on TextGadget()?

Got it running after a while.

Update v0.1
- Added free subclass
- Optimize first mouse click

Code:
;-TOP

;Define AppDelegate.I = CocoaMessage(0, CocoaMessage(0, 0, "NSApplication sharedApplication"), "delegate")

; ----

ImportC ""
  objc_disposeClassPair(*Class)
EndImport
 
Structure udtGadgetData
  ; Header
  Window.i
  Gadget.i
  *OldClass
  *NewClass
  ; Data
  last_time.i
EndStructure

Global NewMap ClassGadgetMap.udtGadgetData()

ProcedureC ClassGadgetCallback(Object.i, Selector.i, Event.i)
  Protected time, diff_time
  time = ElapsedMilliseconds()
  If FindMapElement(ClassGadgetMap(), Hex(Object))
    With ClassGadgetMap()
      diff_time = time - \last_time
      \last_time = time
      If diff_time < DoubleClickTime()
        PostEvent(#PB_Event_Gadget, \Window, \Gadget, #PB_EventType_LeftDoubleClick)
      Else
        PostEvent(#PB_Event_Gadget, \Window, \Gadget, #PB_EventType_LeftClick)
      EndIf
    EndWith
  EndIf
EndProcedure

Procedure SubclassGadget(Window.i, Gadget.i, NewClassName.s)
  Protected GadgetID = GadgetID(Gadget)
  Protected GadgetClass = CocoaMessage(0, GadgetID, "class")
  Protected NewGadgetClass
 
  If Not FindMapElement(ClassGadgetMap(), Hex(GadgetID))
    AddMapElement(ClassGadgetMap(), Hex(GadgetID))
    NewClassName + Str(Gadget)
   
    NewGadgetClass = objc_allocateClassPair_(GadgetClass, NewClassName, 0)
    objc_registerClassPair_(NewGadgetClass)
    object_setClass_(GadgetID, NewGadgetClass)
   
    ;class_addMethod_(NewGadgetClass, sel_registerName_("rightMouseDown:"), @ClassGadgetCallback(), "v@:@")
    class_addMethod_(NewGadgetClass, sel_registerName_("mouseDown:"), @ClassGadgetCallback(), "v@:@")
   
    With ClassGadgetMap()
      \Window = Window
      \Gadget = Gadget
      \OldClass = GadgetClass
      \NewClass = NewGadgetClass
      \last_time = ElapsedMilliseconds() - DoubleClickTime()
    EndWith
   
  EndIf
EndProcedure

Procedure FreeSubclassGadget(Gadget)
  Protected GadgetID = GadgetID(Gadget)
  If FindMapElement(ClassGadgetMap(), Hex(GadgetID))
    With ClassGadgetMap()
      object_setClass_(GadgetID, \OldClass)
      objc_disposeClassPair(\NewClass)
    EndWith
    DeleteMapElement(ClassGadgetMap())
  EndIf
EndProcedure

; ---.

If OpenWindow(0, 40, 40, 200, 120, "Test")
  TextGadget(0, 10, 10, 180, 30, "TextGadget 1")
  TextGadget(1, 10, 50, 180, 30, "TextGadget 2")
 
  SubclassGadget(0, 0, "SubclassedTextGadget")
  SubclassGadget(0, 1, "SubclassedTextGadget")
 
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Break
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 0
            Select EventType()
              Case #PB_EventType_LeftClick
                Debug "1. LeftClick"
              Case #PB_EventType_LeftDoubleClick
                Debug "1. LeftDoubleClick"
                ;FreeSubclassGadget(1)
            EndSelect
          Case 1
            Select EventType()
              Case #PB_EventType_LeftClick
                Debug "2. LeftClick"
              Case #PB_EventType_LeftDoubleClick
                Debug "2. LeftDoubleClick"
            EndSelect
           
        EndSelect
       
    EndSelect
   
  ForEver
 
EndIf

Author:  wilbert [ Sat Oct 05, 2019 7:45 pm ]
Post subject:  Re: How to detect double click on TextGadget()?

If you don't mind targeting MacOS 10.10+ you can use NSClickGestureRecognizer

Code:
; MacOS 10.10+

ProcedureC DoubleClickCallback(Obj, Sel, GestureRecognizer)
  Debug "DoubleClick at GadgetID: " + Str(CocoaMessage(0, GestureRecognizer, "view"))
EndProcedure

AppDelegate = CocoaMessage(0, CocoaMessage(0, 0, "NSApplication sharedApplication"), "delegate")
DelegateClass = CocoaMessage(0, AppDelegate, "class")
class_addMethod_(DelegateClass, sel_registerName_("doubleClick:"), @DoubleClickCallback(),"v@:@")

DoubleClick = CocoaMessage(0, 0, "NSClickGestureRecognizer alloc")
DoubleClick = CocoaMessage(0, DoubleClick, "initWithTarget:", AppDelegate, "action:", sel_registerName_("doubleClick:"))
CocoaMessage(0, DoubleClick, "setNumberOfClicksRequired:", 2)

OpenWindow(0, 0, 0, 322, 50, "TextGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
TextGadget(0, 8, 8, 306, 20, "DoubleClick me", #PB_Text_Border)
CocoaMessage(0, GadgetID(0), "addGestureRecognizer:", DoubleClick)

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow

Author:  Wolfram [ Sat Oct 05, 2019 7:51 pm ]
Post subject:  Re: How to detect double click on TextGadget()?

Wow! Thanks both

if someone has a more easy solution as my pleas let me know.

Code:
Global Window_0, textGadget, strGadget

ProcedureC DoubleClickCallback(Obj, Sel, GestureRecognizer)
  Debug "DoubleClick at GadgetID: " + Str(CocoaMessage(0, GestureRecognizer, "view"))
  HideGadget(textGadget, #True)
  HideGadget(strGadget, #False)
  SetActiveGadget(strGadget)
EndProcedure


Global AppDelegate = CocoaMessage(0, CocoaMessage(0, 0, "NSApplication sharedApplication"), "delegate")
DelegateClass = CocoaMessage(0, AppDelegate, "class")
class_addMethod_(DelegateClass, sel_registerName_("doubleClick:"), @DoubleClickCallback(),"v@:@")



Procedure OpenWindow_0(x = 0, y = 0, width = 450, height = 160)
  Window_0 = OpenWindow(#PB_Any, x, y, width, height, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
 
  textGadget = TextGadget(#PB_Any, 8, 8, 306, 20, "DoubleClick me", #PB_Text_Border)
  DoubleClick = CocoaMessage(0, 0, "NSClickGestureRecognizer alloc")
  DoubleClick = CocoaMessage(0, DoubleClick, "initWithTarget:", AppDelegate, "action:", sel_registerName_("doubleClick:"))
  CocoaMessage(0, DoubleClick, "setNumberOfClicksRequired:", 2)
  CocoaMessage(0, GadgetID(textGadget), "addGestureRecognizer:", DoubleClick)
 
 
  strGadget = StringGadget(#PB_Any, 8, 8, 306, 20,  "DoubleClick me")
  CocoaMessage(0, GadgetID(strGadget), "setDelegate:", AppDelegate)
  CocoaMessage(0, GadgetID(strGadget), "setAction:", sel_registerName_("performClick:") )
  CocoaMessage(0, GadgetID(strGadget), "setTarget:", GadgetID(textGadget))
  HideGadget(strGadget, #True)
 
EndProcedure


Procedure Window_0_Events(event)
  Select event
    Case #PB_Event_CloseWindow
      ProcedureReturn #False
     
    Case #PB_Event_Menu
      Select EventMenu()
        Case #PB_Menu_Quit
          ProcedureReturn #False
      EndSelect
     
    Case #PB_Event_Gadget
      Select EventGadget()
        Case Button_0
        Case textGadget
          If EventType() = 0
            HideGadget(textGadget, #False)
            SetGadgetText(textGadget, GetGadgetText(strGadget) )
            HideGadget(strGadget, #True)
          EndIf
         
      EndSelect
  EndSelect
  ProcedureReturn #True
EndProcedure

OpenWindow_0()

Repeat
  event = WaitWindowEvent()
Until Window_0_Events(event) = #False


Author:  wilbert [ Sun Oct 06, 2019 6:17 am ]
Post subject:  Re: How to detect double click on TextGadget()?

Wolfram wrote:
if someone has a more easy solution as my pleas let me know.

I don't know if it is easier but you could use only a StringGadget without a TextGadget and switch its state between editable or not.
Code:
Procedure ChangeState(StringGadget, Editable)
  Protected StringGadgetID = GadgetID(StringGadget)
  CocoaMessage(0, StringGadgetID, "setEditable:", Editable)
  CocoaMessage(0, StringGadgetID, "setBezeled:", Editable)
  CocoaMessage(0, StringGadgetID, "setDrawsBackground:", Editable)
EndProcedure

Author:  Wolfram [ Sun Oct 06, 2019 11:18 am ]
Post subject:  Re: How to detect double click on TextGadget()?

Yes, these looks more economic.
But I still need a second gadget to exit the edit mode by pressing ReturnKey.

Code:
  CocoaMessage(0, GadgetID(strGadget), "setAction:", sel_registerName_("performClick:") )
  CocoaMessage(0, GadgetID(strGadget), "setTarget:", GadgetID(textGadget))


Is there another way to call a procedure by pressing Return on the StringGadget()?

Author:  mk-soft [ Sun Oct 06, 2019 1:59 pm ]
Post subject:  Re: How to detect double click on TextGadget()?

Add method 'keyDown:' to gadget not work, but without CocoaMessages...
Code:
;-TOP
Enumeration CustomEventType #PB_EventType_FirstCustomValue
  #My_EventType_Return
EndEnumeration
 
Procedure EventReturnKey()
  PostEvent(#PB_Event_Gadget, GetActiveWindow(), GetActiveGadget(), #My_EventType_Return)
EndProcedure


If OpenWindow(0, 0, 0, 400, 300, "StringGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  StringGadget(0, 10, 10, 380, 30, "StringGadget...")
  EditorGadget(1, 10, 50, 380, 240)
 
  CreateMenu(0, WindowID(0))
  BindMenuEvent(0, 1000, @EventReturnKey())
 
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Break
       
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 0
            Select EventType()
              Case #PB_EventType_Focus
                AddKeyboardShortcut(0, #PB_Shortcut_Return, 1000)
              Case #PB_EventType_LostFocus
                RemoveKeyboardShortcut(0, #PB_Shortcut_Return)
              Case #My_EventType_Return
                Debug "Return"
                SetActiveGadget(1)
            EndSelect
               
        EndSelect
       
    EndSelect
  ForEver
 
EndIf

Author:  Wolfram [ Sun Oct 06, 2019 3:01 pm ]
Post subject:  Re: How to detect double click on TextGadget()?

So this look to me good.

Code:
Global Window_0, strGadget

Enumeration CustomEventType #PB_EventType_FirstCustomValue
  #My_EventType_Return
EndEnumeration


Procedure ChangeState(StringGadget, Editable)
  Protected StringGadgetID = GadgetID(StringGadget)
  CocoaMessage(0, StringGadgetID, "setEditable:", Editable)
  CocoaMessage(0, StringGadgetID, "setBezeled:", Editable)
  CocoaMessage(0, StringGadgetID, "setDrawsBackground:", Editable)
  SetActiveGadget(StringGadget)
EndProcedure


Procedure EventReturnKey()
  Debug "RetunKey"
  PostEvent(#PB_Event_Gadget, GetActiveWindow(), GetActiveGadget(), #My_EventType_Return)
EndProcedure


ProcedureC DoubleClickCallback(Obj, Sel, GestureRecognizer)
  Debug "DoubleClick at GadgetID: " + Str(CocoaMessage(0, GestureRecognizer, "view"))

  ChangeState(strGadget, #True)
 
  BindMenuEvent(0, 1000, @EventReturnKey())
  AddKeyboardShortcut(Window_0, #PB_Shortcut_Return, 1000)
 
EndProcedure


Global AppDelegate = CocoaMessage(0, CocoaMessage(0, 0, "NSApplication sharedApplication"), "delegate")
DelegateClass = CocoaMessage(0, AppDelegate, "class")
class_addMethod_(DelegateClass, sel_registerName_("doubleClick:"), @DoubleClickCallback(),"v@:@")



Procedure OpenWindow_0(x = 0, y = 0, width = 450, height = 160)
  Window_0 = OpenWindow(#PB_Any, x, y, width, height, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
 
  strGadget = StringGadget(#PB_Any, 8, 8, 306, 20,  "DoubleClick me")
  CocoaMessage(0, GadgetID(strGadget), "setDelegate:", AppDelegate)
 
  ChangeState(strGadget, #False)
 
  DoubleClick = CocoaMessage(0, 0, "NSClickGestureRecognizer alloc")
  DoubleClick = CocoaMessage(0, DoubleClick, "initWithTarget:", AppDelegate, "action:", sel_registerName_("doubleClick:"))
  CocoaMessage(0, DoubleClick, "setNumberOfClicksRequired:", 2)
  CocoaMessage(0, GadgetID(strGadget), "addGestureRecognizer:", DoubleClick)
 
  CreateMenu(0, WindowID(Window_0))
 
EndProcedure


Procedure Window_0_Events(event)
  Select event
    Case #PB_Event_CloseWindow
      ProcedureReturn #False
     
    Case #PB_Event_Menu
      Select EventMenu()
        Case #PB_Menu_Quit
          ProcedureReturn #False
      EndSelect
     
    Case #PB_Event_Gadget
      Select EventGadget()
        Case Button_0
        Case strGadget
          If EventType() = #My_EventType_Return
            UnbindMenuEvent(0, 1000, @EventReturnKey())
            RemoveKeyboardShortcut(Window_0, #PB_Shortcut_Return)
            ChangeState(strGadget, #False)     
          EndIf
         
      EndSelect
  EndSelect
  ProcedureReturn #True
EndProcedure

OpenWindow_0()

Repeat
  event = WaitWindowEvent()
Until Window_0_Events(event) = #False

Author:  Wolfram [ Mon Oct 07, 2019 2:29 pm ]
Post subject:  Re: How to detect double click on TextGadget()?

Which object is given on this callback?
How can I select between different gadgets?

Code:
ProcedureC DoubleClickCallback(Obj, Sel, GestureRecognizer)

  Select Obj
    Case GadgetID(strGadget)
      ChangeState(strGadget, #True)
     
    Case GadgetID(strGadget2)
      ChangeState(strGadget2, #True)
     
  EndSelect

  BindMenuEvent(0, 1000, @EventReturnKey())
  AddKeyboardShortcut(Window_0, #PB_Shortcut_Return, 1000)
 
EndProcedure

Author:  wilbert [ Mon Oct 07, 2019 5:13 pm ]
Post subject:  Re: How to detect double click on TextGadget()?

Wolfram wrote:
How can I select between different gadgets?

I just found out a gesture recognizer can only be added to one view.
That means you would have to create a new one for every gadget :(

So maybe replacing mouseDown: similar to what mk-soft did is a better option.
Code:
Prototype Proto_MouseDown(Object, Selector, Event)
DeclareC MouseDown(Object, Selector, Event)

Global MouseDown_.Proto_MouseDown = class_replaceMethod_(objc_getClass_("NSTextField"),
                                                         sel_registerName_("mouseDown:"),
                                                         @MouseDown(), "v@:@")

ProcedureC MouseDown(Object, Selector, Event)
  Protected Gadget, ClickCount = CocoaMessage(0, Event, "clickCount")
  If ClickCount = 2
    Gadget = CocoaMessage(0, Object, "tag")
    Debug "DoubleClick on gadget:" + Str(Gadget)
  EndIf
  If MouseDown_
    MouseDown_(Object, Selector, Event)
  EndIf
EndProcedure


OpenWindow(0, 270, 100, 200, 170, "DoubleClick", #PB_Window_MinimizeGadget)
TextGadget(1, 10, 10, 100, 20, "Gadget 1")
TextGadget(2, 10, 40, 100, 20, "Gadget 2")
StringGadget(3, 10, 70, 100, 20, "Gadget 3")

Repeat
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow

Author:  Wolfram [ Mon Oct 07, 2019 7:53 pm ]
Post subject:  Re: How to detect double click on TextGadget()?

Hi Wilbert,

what do you think about this solution?

Code:
Global Window_0, strGadget, strGadget2

Enumeration CustomEventType #PB_EventType_FirstCustomValue
  #My_EventType_Return
EndEnumeration


Procedure ChangeState(StringGadget, Editable)
  Protected StringGadgetID = GadgetID(StringGadget)
  CocoaMessage(0, StringGadgetID, "setEditable:", Editable)
  CocoaMessage(0, StringGadgetID, "setBezeled:", Editable)
  CocoaMessage(0, StringGadgetID, "setDrawsBackground:", Editable)
  SetActiveGadget(StringGadget)
EndProcedure


Procedure EventReturnKey()
  Debug "RetunKey"
  PostEvent(#PB_Event_Gadget, GetActiveWindow(), GetActiveGadget(), #My_EventType_Return)
EndProcedure


Procedure getGadget()
  windowID = WindowID(Window_0)
  NSPoint.NSPoint
 
  CocoaMessage(@NSPoint, windowID, "mouseLocationOutsideOfEventStream")
  object = CocoaMessage(0, CocoaMessage(0, windowID, "contentView"), "hitTest:@", @NSPoint)
 
  ProcedureReturn CocoaMessage(0, object, "tag")
EndProcedure


Procedure exitEdit(gadget)
  ChangeState(gadget, #False)
  UnbindMenuEvent(0, 1000, @EventReturnKey())
  RemoveKeyboardShortcut(Window_0, #PB_Shortcut_Return)
 
EndProcedure


ProcedureC DoubleClickCallback(Obj, Sel, GestureRecognizer)
  Static gadget = -1
 
  If gadget <> -1
    exitEdit(gadget)
  EndIf
 
  gadget = getGadget()
 
  If gadget <> -1
    SetActiveGadget(gadget)
    ChangeState(gadget, #True)
    BindMenuEvent(0, 1000, @EventReturnKey())
    AddKeyboardShortcut(Window_0, #PB_Shortcut_Return, 1000)
   
  EndIf

EndProcedure

Procedure initDoubleClickGesture()
  DoubleClick = CocoaMessage(0, 0, "NSClickGestureRecognizer alloc")
  DoubleClick = CocoaMessage(0, DoubleClick, "initWithTarget:", AppDelegate, "action:", sel_registerName_("doubleClick:"))
  CocoaMessage(0, DoubleClick, "setNumberOfClicksRequired:", 2)
  ProcedureReturn DoubleClick
EndProcedure


Global AppDelegate = CocoaMessage(0, CocoaMessage(0, 0, "NSApplication sharedApplication"), "delegate")
DelegateClass = CocoaMessage(0, AppDelegate, "class")
class_addMethod_(DelegateClass, sel_registerName_("doubleClick:"), @DoubleClickCallback(),"v@:@")



Procedure OpenWindow_0(x = 0, y = 0, width = 450, height = 160)
  Window_0 = OpenWindow(#PB_Any, x, y, width, height, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
 
  strGadget = StringGadget(#PB_Any, 8, 8, 306, 20,  "DoubleClick me")
  strGadget2 = StringGadget(#PB_Any, 8, 50, 306, 20,  "DoubleClick me2")
  CocoaMessage(0, GadgetID(strGadget), "setDelegate:", AppDelegate)
  CocoaMessage(0, GadgetID(strGadget2), "setDelegate:", AppDelegate)
 
  ChangeState(strGadget, #False)
  ChangeState(strGadget2, #False)
 

  CocoaMessage(0, GadgetID(strGadget), "addGestureRecognizer:", initDoubleClickGesture() )

  CocoaMessage(0, GadgetID(strGadget2), "addGestureRecognizer:", initDoubleClickGesture() )
 
  CreateMenu(0, WindowID(Window_0))
 
EndProcedure


Procedure Window_0_Events(event)
  Select event
    Case #PB_Event_CloseWindow
      ProcedureReturn #False
     
    Case #PB_Event_Menu
      Select EventMenu()
        Case #PB_Menu_Quit
          ProcedureReturn #False
      EndSelect
     
    Case #PB_Event_Gadget
      Select EventGadget()
         
        Case strGadget
          If EventType() = #My_EventType_Return
            exitEdit(strGadget)     
          EndIf
        Case strGadget2
          If EventType() = #My_EventType_Return
            exitEdit(strGadget2)   
          EndIf
         
      EndSelect
  EndSelect
  ProcedureReturn #True
EndProcedure

OpenWindow_0()

Repeat
  event = WaitWindowEvent()
Until Window_0_Events(event) = #False

Author:  mk-soft [ Mon Oct 07, 2019 8:22 pm ]
Post subject:  Re: How to detect double click on TextGadget()?

@wilbert
How do you know something like this that Purebasic added the method (or property) "tag" to get the gadget number :?: :?: :?:
Code:
Gadget = CocoaMessage(0, Object, "tag")

Author:  wilbert [ Mon Oct 07, 2019 8:27 pm ]
Post subject:  Re: How to detect double click on TextGadget()?

Wolfram wrote:
what do you think about this solution?

Inside the DoubleClickCallback procedure, it's easier to get the gadget like this
Code:
gadget = CocoaMessage(0, CocoaMessage(0, GestureRecognizer, "view"), "tag")
You don't need things like hitTest.


mk-soft wrote:
How do you know something like this that Purebasic added the method (or property) "tag" to get the gadget number

Inside the SDK, there's a file named Gadget.h which mentions this
Quote:
the NSView tag method is used to store our GadgetID

Author:  mk-soft [ Mon Oct 07, 2019 8:56 pm ]
Post subject:  Re: How to detect double click on TextGadget()?

Ok, Thanks wildert...

Now with your 'mouseDown' code

Bugfix - missing EnableExplicit
- Update: Move SetActiveGadget to enterEdit

Code:
;-TOP

EnableExplicit

; ***************************************
;- Wilberts mouseDown Method (and mk-soft)

Prototype Proto_MouseDown(Object, Selector, Event)
DeclareC MyMouseDown(Object, Selector, Event)

Global DefaultMouseDown.Proto_MouseDown = class_replaceMethod_(objc_getClass_("NSTextField"),
                                                         sel_registerName_("mouseDown:"),
                                                         @MyMouseDown(), "v@:@")

ProcedureC MyMouseDown(Object, Selector, Event)
  Protected Gadget = CocoaMessage(0, Object, "tag")
  Protected ClickCount = CocoaMessage(0, Event, "clickCount")
  If ClickCount = 1
    PostEvent(#PB_Event_Gadget, GetActiveWindow(), Gadget, #PB_EventType_LeftClick)
  ElseIf ClickCount = 2
    PostEvent(#PB_Event_Gadget, GetActiveWindow(), Gadget, #PB_EventType_LeftDoubleClick)
  EndIf
  If DefaultMouseDown
    DefaultMouseDown(Object, Selector, Event)
  EndIf
EndProcedure

; ***************************************


Global Window_0, strGadget, strGadget2, strGadget3

Enumeration CustomEventType #PB_EventType_FirstCustomValue
  #My_EventType_Return
EndEnumeration


Procedure ChangeState(StringGadget, Editable)
  Protected StringGadgetID = GadgetID(StringGadget)
  CocoaMessage(0, StringGadgetID, "setEditable:", Editable)
  CocoaMessage(0, StringGadgetID, "setBezeled:", Editable)
  CocoaMessage(0, StringGadgetID, "setDrawsBackground:", Editable)
EndProcedure


Procedure EventReturnKey()
  PostEvent(#PB_Event_Gadget, GetActiveWindow(), GetActiveGadget(), #My_EventType_Return)
EndProcedure


Procedure enterEdit(gadget)
  ChangeState(gadget, #True)
  AddKeyboardShortcut(Window_0, #PB_Shortcut_Return, 1000)
  SetActiveGadget(gadget)
EndProcedure

Procedure exitEdit(gadget)
  ChangeState(gadget, #False)
  RemoveKeyboardShortcut(Window_0, #PB_Shortcut_Return)
EndProcedure


Procedure OpenWindow_0(x = 0, y = 0, width = 450, height = 160)
  Window_0 = OpenWindow(#PB_Any, x, y, width, height, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
 
  strGadget = StringGadget(#PB_Any, 8, 8, 306, 20,  "DoubleClick me")
  strGadget2 = StringGadget(#PB_Any, 8, 50, 306, 20,  "DoubleClick me2")
  strGadget3 = EditorGadget(#PB_Any, 8, 92, 306, 60)
 
  ChangeState(strGadget, #False)
  ChangeState(strGadget2, #False)
 
  CreateMenu(0, WindowID(Window_0))
  BindMenuEvent(0, 1000, @EventReturnKey())
 
EndProcedure


Procedure Window_0_Events(event)
  Select event
    Case #PB_Event_CloseWindow
      ProcedureReturn #False
     
    Case #PB_Event_Menu
      Select EventMenu()
        Case #PB_Menu_Quit
          ProcedureReturn #False
      EndSelect
     
    Case #PB_Event_Gadget
      Select EventGadget()
         
        Case strGadget
          Select EventType()
            Case #PB_EventType_LeftDoubleClick
              enterEdit(strGadget)
             
            Case #My_EventType_Return, #PB_EventType_LostFocus
              exitEdit(strGadget)
             
          EndSelect
         
        Case strGadget2
          Select EventType()
            Case #PB_EventType_LeftDoubleClick
              enterEdit(strGadget2)
           
            Case #My_EventType_Return, #PB_EventType_LostFocus
              exitEdit(strGadget2)
             
          EndSelect
         
      EndSelect
  EndSelect
  ProcedureReturn #True
EndProcedure

OpenWindow_0()

Define event

Repeat
  event = WaitWindowEvent()
Until Window_0_Events(event) = #False

Page 1 of 2 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/