Page 1 of 1

Indicate change in text

Posted: Fri Mar 02, 2012 3:37 pm
by BjornF
Dear All,

I have a programme that shows records in a couple of editor fields. The user can change the text in the fields.
What I would like to do is to signal to the user that he has changed the text by changing the background colour.

Just now I can think of two ways of doing it.
1. record content then use a timer that compares the recorded with the present content every 0.5s
2. record content then use EventGadget for the editorfields to indicate that something has happened, compare texts as above

However both seem to have their disadvantages:
1. seems like a waste of resources and will continue running even when the programme is in the background (this could be solved if there is a Window - lostfocus, but I can't find one)
2. this is evoked for any number of reasons, not all are related to changes in the text

Is there a smart(er) way of doing it?

all the best / Björn

Re: Indicate change in text

Posted: Fri Mar 02, 2012 3:57 pm
by juror
Windows only:
EM_GETMODIFY

Re: Indicate change in text

Posted: Fri Mar 02, 2012 4:01 pm
by BjornF
Nice, but do you know anything about the reliability? At least someone seems to have had problems with it...

http://msdn.microsoft.com/en-us/library ... s.85).aspx

Re: Indicate change in text

Posted: Fri Mar 02, 2012 4:48 pm
by Num3

Code: Select all

 Case #PB_Event_Gadget
      EventGadget = EventGadget()
      EventType = EventType()
      If EventGadget = #String_minutes
        If EventType = #PB_EventType_Change ; <---- DING DING
          Do extra check to see if it is equal to last value
          etc....
        EndIf
      EndIf

Re: Indicate change in text

Posted: Fri Mar 02, 2012 4:48 pm
by Little John
BjornF wrote:[EventGadget] is evoked for any number of reasons, not all are related to changes in the text

Is there a smart(er) way of doing it?
I use #PB_Event_Gadget together with #PB_EventType_Change:

Code: Select all

      event = WaitWindowEvent()

      If event = #PB_Event_Gadget
         Select EventGadget()
            Case #MyEditField
               Select EventType()
                  Case #PB_EventType_Change
                     ; do something
               EndSelect
            [...]
Works fine for me.

Regards, Little John

//edit: Num3 was some seconds faster. :-)

Re: Indicate change in text

Posted: Fri Mar 02, 2012 4:53 pm
by BjornF
Excellent ! :D

Thank you for the help, just the thing I was after. / Björn


edit: I just tried it, and couldn't get it to work :( :( :(
Did you try it? (Editorgadget isn't noted as one of the gadgets it can be used on)

Re: Indicate change in text

Posted: Fri Mar 02, 2012 5:17 pm
by Num3
BjornF wrote:Excellent ! :D

Thank you for the help, just the thing I was after. / Björn


edit: I just tried it, and couldn't get it to work :( :( :(
Did you try it? (Editorgadget isn't noted as one of the gadgets it can be used on)
Upsss you forgot to mention it was for an editor gadget!

I don't think it will work with that :(

Re: Indicate change in text

Posted: Fri Mar 02, 2012 5:55 pm
by Little John
Ooops ...

For an EditorGadget, use this code (slightly modified for recent PB versions after a code by srod):

Code: Select all

If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
   EditorGadget(0, 8, 8, 306, 133)
   ;Add the following line to enable the editor gadget to send #EN_CHANGE notifications.
   SendMessage_(GadgetID(0), #EM_SETEVENTMASK, 0, SendMessage_(GadgetID(0), #EM_GETEVENTMASK, 0,0)|#ENM_CHANGE)
   
   For a = 0 To 5
      AddGadgetItem(0, a, "Line " + Str(a))
   Next
   
   Repeat
      Event = WaitWindowEvent()
      Select EventType()
         Case #PB_EventType_Change
            Debug "changed"
      EndSelect
   Until Event = #PB_Event_CloseWindow
EndIf
Regards, Little John

Re: Indicate change in text

Posted: Fri Mar 02, 2012 6:02 pm
by BjornF
Thank you, I'll have a go with that one. / all the best, Björn