Get editorgadget LINE/COL when caret is moved?

Just starting out? Need help? Post your questions and find answers here.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Haven't tested the following very much and you might need to adjust which events are being trapped etc.

Your code for calculating the column wasn't quite right.

Code: Select all

Procedure Callback(hWnd, uMsg, wParam, lParam)
  Protected result, *msgf.MSGFILTER
  Result = #PB_ProcessPureBasicEvents
  Select uMsg
    Case #WM_NOTIFY 
      *msgf=lParam
      Select *msgf\NMHDR\code
        Case #EN_MSGFILTER   
          Select *msgf\msg
            Case #WM_LBUTTONUP, #WM_KEYUP
              GetCaretPos_(@pos.POINT) 
              char=SendMessage_(GadgetID(0), #EM_CHARFROMPOS, 0, @pos)
              lineindex=SendMessage_(GadgetID(0), #EM_LINEFROMCHAR, char, 0)
              colindex=SendMessage_(GadgetID(0), #EM_LINEINDEX, lineindex,0)
              col = char-colindex
              row = lineindex + 1 
              Debug "("+Str(col)+", "+Str(row)+")"
          EndSelect
      EndSelect
  EndSelect
  ProcedureReturn Result
EndProcedure


 If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0)) 
    EditorGadget(0, 8, 8, 306, 133) 
    For a = 0 To 5 
      AddGadgetItem(0, a, "Line "+Str(a)) 
    Next 
    evMask = SendMessage_(GadgetID(0), #EM_GETEVENTMASK, 0, 0) 
    SendMessage_(GadgetID(0), #EM_SETEVENTMASK, 0, evMask|#ENM_KEYEVENTS|#ENM_MOUSEEVENTS )
    SetWindowCallback(@Callback())
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow 
  EndIf 
I may look like a mule, but I'm not a complete ass.
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Post by utopiomania »

THANKS :) the code you posted worked out of the box, but to be able to make it work in my own app
I had to add the window id to the setWindowCallback() procedure:

Code: Select all

  ;callback to update editorgadget line number 
  ;setWindowCallback(@lineNumCallback(), #WIN1)
However, this callback broke another callback in my app (see below). I'm shure I miss something obvious here, but this API
stuff really makes my braincell hurt, so... :)

Code: Select all

  ;find/replace callback
  uFindReplaceMsg = registerWindowMessage_(#FINDMSGSTRING) 
  ;setWindowCallback(@findReplaceCallback(), #WIN1)
If I unrem both, the first stops working, and the second works. If I unrem one of them, the other one works.

The editorgadget is attached to a panel gadget BTW, but I don't know if that has anything to do with this.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

A window can only have one Window callback resulting from a SetWindowCallback(). If I read your post correctly then your second SetWindowCallback(..., #WIN1) command will cancel out the first one, effectively removing the callback.

What you'll have to do is either move the code from one callback into the other and create one big callback function, or nest them, i.e. get one callback to call the other as a normal procedure etc.


My suggestion is to place the contents of the #WM_NOTIFY command from the callback I posted into your existing callback (taking care not to destroy any existing #WM_NOTIFY handler) and then remove my SetWindowCallback() etc.
I may look like a mule, but I'm not a complete ass.
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Post by utopiomania »

Ok, Thanks for your help. I'll go back to my Workstation

http://www.planetvids.com/html/Touch-Sc ... rface.html

and see If I can fix this :)
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Post by utopiomania »

I just rewrote and combined the two callbacks into one procedure, and everything works fine. Thanks for the help!
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

That looks just like my workstation at work. :D
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

utopiomania wrote:I just rewrote and combined the two callbacks into one procedure, and everything works fine. Thanks for the help!
That's good. Glad it's worked out. :)
I may look like a mule, but I'm not a complete ass.
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Post by Shardik »

@utopiomania:
Did you try the forum search? netmaestro already posted a similar example at october 21st:
http://www.purebasic.fr/english/viewtop ... 50&start=3
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Shardik wrote:@utopiomania:
Did you try the forum search? netmaestro already posted a similar example at october 21st:
http://www.purebasic.fr/english/viewtop ... 50&start=3
Must admit I didn't see that one!

Anyhow, I used a callback in the above code so that I could have a little more control over which events were trapped. The regular PB event loop method is not quite as selective in this case. :)
I may look like a mule, but I'm not a complete ass.
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Post by utopiomania »

@Shardik, I searched the forums and found the post you link to, but couldn't get it to work properly
in my own program.

It seems to update the col/row position on all events that hit the messagehandler?

The statusbar flickered badly, repaint became slow etc, and I wasn't able to filter out the correct
message(s)to use, so I dropped it and tried srods solution instead, which work very well.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Yes there seems to be a change in editorgadget events since I wrote that. Now there's a #WM_PAINT message firing every loop for some reason. I updated the code to only change the status bar on a #WM_LBUTTONUP and it works like it used to again.
BERESHEIT
Post Reply