It is currently Thu Jul 18, 2019 8:23 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Return in StringGadget stops EditorGadget newline
PostPosted: Tue Dec 11, 2018 1:06 pm 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 4462
Location: Not Sydney!!! (Bad water, no goats)
I have a strange situation that I didn't think through.

One a form, I have an editorgadget and a stringgadget. I have attached a Return key shortcut to the form (Wasn't thinking) which triggers a search of the editorgadget but of course then Return no longer goes to a new line in the editorgadget.

Has anyone had this problem before and thought of a better way to do this?

_________________
Amateur Radio, D-STAR/VK3HAF


Top
 Profile  
Reply with quote  
 Post subject: Re: Return in StringGadget stops EditorGadget newline
PostPosted: Tue Dec 11, 2018 1:22 pm 
Offline
Addict
Addict
User avatar

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 3559
Location: Utah, USA
Here's one way:
Code:
Global EventTyp.l, liveWin, lastLiveWin
#KB_Return = #PB_Shortcut_Return + 49152

Procedure KeyboardGyration()
  Select EventType()
    Case #PB_EventType_Focus
      Debug "focus on window " + Str(liveWin)
      AddKeyboardShortcut(liveWin, #PB_Shortcut_Return, #KB_Return)
      lastLiveWin = liveWin
    Case #PB_EventType_LostFocus
      Debug "lost focus on window " + Str(lastLiveWin)
      RemoveKeyboardShortcut(lastLiveWin, #PB_Shortcut_Return)
  EndSelect
EndProcedure

OpenWindow(0,0,0,640,480,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)

TextGadget(#PB_Any, 10,20,100,16,"Enter Something:")
StringGadget(0, 110,20,300,20,"")
EditorGadget(1,10,50,400,400)
SetActiveGadget(0)

OpenWindow(2,0,0,640,480,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
TextGadget(#PB_Any, 10,20,100,16,"Enter Something:")
StringGadget(2, 110,20,300,20,"")
EditorGadget(3,10,50,400,400)
SetActiveGadget(2)

Repeat
  EventID = WaitWindowEvent()
  liveWin = GetActiveWindow()
  Select EventID
    Case #PB_Event_Gadget ;only one gadget list for all windows
      EventTyp.l = EventType()
      Select EventGadget()
        Case 0, 2
          KeyboardGyration()
      EndSelect
    Case #PB_Event_Menu
      Select EventMenu()
        Case #KB_Return
          Select liveWin ;menu events can take place on different windows
            Case 0
              SetActiveGadget(1)
            Case 1
              SetActiveGadget(3)
          EndSelect
      EndSelect
  EndSelect
Until EventID = #PB_Event_CloseWindow

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Return in StringGadget stops EditorGadget newline
PostPosted: Tue Dec 11, 2018 1:37 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3351
Hi Fang
Simple as usual
Code:
If OpenWindow(0, 0, 0, 300, 200, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  StringGadget(0,10,10,280,24,"OK")
 
  EditorGadget(1, 10, 45, 280,130,#PB_Editor_WordWrap)
Repeat
  Select WaitWindowEvent(10)
        Case #PB_Event_CloseWindow
            Quit = 1
           
        Case #PB_Event_Menu
            Select EventMenu()
              Case 10
                If GetActiveGadget() = 0
                  SetActiveGadget(1)
                EndIf
            EndSelect
                 
        Case #PB_Event_Gadget
            Select EventGadget()
              Case 0
                AddKeyboardShortcut(0,#PB_Shortcut_Return,10)
              Case 1               
                RemoveKeyboardShortcut(0, #PB_Shortcut_Return)                 
            EndSelect
  EndSelect
Until Quit = 1
EndIf

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: Return in StringGadget stops EditorGadget newline
PostPosted: Tue Dec 11, 2018 2:27 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4255
Location: Germany
Only depending on the StringGadget itself:

Code:
If OpenWindow(0, 0, 0, 300, 200, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  StringGadget(0,10,10,280,24,"OK")
 
  EditorGadget(1, 10, 45, 280,130,#PB_Editor_WordWrap)
  Repeat
    Select WaitWindowEvent(10)
      Case #PB_Event_CloseWindow
        Quit = 1
       
      Case #PB_Event_Menu
        Select EventMenu()
          Case 10
            Debug "Shortcut from StringGadget"
           
        EndSelect
       
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 0
            Select EventType()
              Case #PB_EventType_Focus
                AddKeyboardShortcut(0,#PB_Shortcut_Return,10)
              Case #PB_EventType_LostFocus
                RemoveKeyboardShortcut(0, #PB_Shortcut_Return)                 
            EndSelect
        EndSelect
    EndSelect
  Until Quit = 1
EndIf


Top
 Profile  
Reply with quote  
 Post subject: Re: Return in StringGadget stops EditorGadget newline
PostPosted: Tue Dec 11, 2018 8:39 pm 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 4462
Location: Not Sydney!!! (Bad water, no goats)
I suspected that adding and removing the shortcut might work but at 11:30 at night, it was too late to try it.

Us old folks need our beauty sleep after all.

Thanks for the nice examples folks, I didn't think things through properly.

_________________
Amateur Radio, D-STAR/VK3HAF


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye