It is currently Wed Nov 13, 2019 1:17 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Extended StringGadget
PostPosted: Wed Dec 12, 2018 8:16 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Jun 23, 2014 1:18 pm
Posts: 124
Hey...

I have the problem to give a StringGadget a little more Functions. Like a Back-Text or a "Pressed-Return-Event". So I created a "bad" module to solve that problem.

Code:
DeclareModule StringGadget
   Prototype ReturnEvent()
   Declare RegisterStringGadget(gadget,text.s,ReturnEvent.ReturnEvent=0)
   Declare UnRegisterStringGadget(gadget)
EndDeclareModule

Module StringGadget
   EnableExplicit
   
   Structure strGad
      string.i
      short.i
      text.s
      event.ReturnEvent
      idx.i
   EndStructure
   
   Global NewMap gadgets.strGad()
   
   Global pidx=1000
   
   Procedure RC()
      Protected gadget=GetActiveGadget()
      Protected key.s=Str(gadget)
      Protected *gad.strGad=gadgets(key)
      If *gad\Event
         *gad\Event()
      EndIf
   EndProcedure
   
   
   Procedure LF()
      Protected gadget=EventGadget()
      Protected key.s=Str(gadget)
      Protected text.s=GetGadgetText(gadget)
      Protected *gad.strGad=gadgets(key)
      If text=""
         SetGadgetText(gadget,*gad\text)
         SetGadgetColor(gadget,#PB_Gadget_FrontColor,#Gray)
      EndIf
   EndProcedure
   
   Procedure GF()
      Protected gadget=EventGadget()
      Protected key.s=Str(gadget)
      Protected text.s=GetGadgetText(gadget)
      Protected *gad.strGad=gadgets(key)
      If text=*gad\text
         SetGadgetText(gadget,"")
      EndIf
      SetGadgetColor(gadget,#PB_Gadget_FrontColor,#Black)
   EndProcedure
   
   Procedure RegisterStringGadget(gadget,text.s,ret.ReturnEvent=0)
      Protected key.s=Str(gadget)
      Protected *gad.strGad=AddMapElement(gadgets(),key)
      With *gad
         \string=gadget
         \text=text
         \Event=ret
         \short=CreatePopupMenu(#PB_Any)
         \idx=pidx
      EndWith
      pidx+1
      If text<>""
         BindGadgetEvent(gadget,@LF(),#PB_EventType_LostFocus)
         BindGadgetEvent(gadget,@GF(),#PB_EventType_Focus)
         SetGadgetText(gadget,text)
         SetGadgetColor(gadget,#PB_Gadget_FrontColor,#Gray)
      EndIf
      If ret
         AddKeyboardShortcut(GetActiveWindow(),#PB_Shortcut_Return,*gad\idx)
         BindMenuEvent(*gad\short,*gad\idx,@RC())
      EndIf
   EndProcedure
   
   Procedure UnRegisterStringGadget(gadget)
      Protected key.s=Str(gadget)
      Protected *gad.strGad=FindMapElement(gadgets(),key)
      UnbindMenuEvent(*gad\short,*gad\idx,@RC())
      FreeMenu(*gad\short)
      DeleteMapElement(gadgets(),key)
      UnbindGadgetEvent(gadget,@LF(),#PB_EventType_LostFocus)
      UnbindGadgetEvent(gadget,@GF(),#PB_EventType_Focus)
      SetGadgetColor(gadget,#PB_Gadget_FrontColor,#Black)
      
   EndProcedure
   
EndModule

CompilerIf #PB_Compiler_IsMainFile
   Procedure pressedReturn()
      Debug GetGadgetText(0)
   EndProcedure
   OpenWindow(0,0,0,300,200,"StringGadget",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
   StringGadget(0,5,5,150,22,"")
   
   StringGadget::RegisterStringGadget(0,"Search...",@pressedReturn())
   Repeat
   Until WaitWindowEvent()=#PB_Event_CloseWindow
CompilerEndIf


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

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 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