Page 1 of 1

Posted: Tue Dec 12, 2006 2:29 pm
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 

Posted: Wed Dec 13, 2006 1:22 am
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.

Posted: Wed Dec 13, 2006 1:32 am
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.

Posted: Wed Dec 13, 2006 1:51 am
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 :)

Posted: Wed Dec 13, 2006 11:45 am
by utopiomania
I just rewrote and combined the two callbacks into one procedure, and everything works fine. Thanks for the help!

Posted: Wed Dec 13, 2006 11:49 am
by Derek
That looks just like my workstation at work. :D

Posted: Wed Dec 13, 2006 12:07 pm
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. :)

Posted: Wed Dec 13, 2006 1:48 pm
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

Posted: Wed Dec 13, 2006 3:04 pm
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. :)

Posted: Wed Dec 13, 2006 5:51 pm
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.

Posted: Thu Dec 14, 2006 12:21 am
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.