Author Topic: wxScintilla events  (Read 3067 times)

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5300
wxScintilla events
« on: August 26, 2006, 08:58:15 pm »
I have been looking at the wxScintilla reference, but I did not quit find what I was looking for.
I'd like to be notified (through wxScintillaEvent) every time a key is pressed. Event type wxEVT_SCI_KEY is no option, since that one is not sended on windows :-(

Another thing I could do is EVT_CHAR_HOOK, but how do I know then that the keypresses are coming from the active editor and not a key pressed in some other control or menu.

Next to this I need to know when the user left clicked somewhere in the editor.

Any ideas.

sethjackson

  • Guest
Re: wxScintilla events
« Reply #1 on: August 26, 2006, 10:56:14 pm »
EVT_KEY_DOWN doesn't work or maybe the wxScintilla control doesn't send this event???

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5300
Re: wxScintilla events
« Reply #2 on: August 26, 2006, 11:09:10 pm »
probably same problem : how do I know the EVT_KEY_DOWN comes from the editor and not from another control in CB (or menu) ?

Offline eranif

  • Regular
  • ***
  • Posts: 254
Re: wxScintilla events
« Reply #3 on: August 26, 2006, 11:09:52 pm »
Hi,

If scintilla does not fire the event, you can workaround it by providing your own event handler and process them before scintilla
do, you just derive a class from wxEvtHandler and add it to the window event handlers.

Here is a simple code that should do what you need (in the following example, I tried to intercept KEY_DOWN, CHAR, CHAR_HOOK, KEY_UP
events):

Code
class MyEvtHandler : public wxEvtHandler
{
public:
void SetWindow(wxWindow *win) { m_win = win; }
MyEvtHandler(wxESFlatMenu *menu, wxEvtHandler* oldHandler)
: m_oldHandler( oldHandler )
{ SetWindow(win); };

    virtual bool ProcessEvent(wxEvent& event)
    {
    if ( event.GetEventType() == wxEVT_KEY_DOWN || event.GetEventType() == wxEVT_KEY_UP ||
event.GetEventType() == wxEVT_CHAR || event.GetEventType() == wxEVT_CHAR_HOOK)
{
// Process the event here (assuming you derived class is called Editor)
Editor* editor = dynamic_cast<Editor*>(m_win);
            if( editor )
             {
        editor->ProcessKeyDown((wxKeyEvent &)event);
           }
   
           // And let scintilla keep processing the event
       return m_oldHandler->ProcessEvent(event);
             }

    }

private:
    wxWindow *m_win;
wxEvtHandler* m_oldHandler;
};

// in your code, replace the old handler with MyEvtHandler
// Somewhere in the construction of the control put this line:
PushEventHandler(new MyEvtHandler(this, GetEventHandler()) );


// And in the destructor of the control - or in its OnClose function or something similar, add:
PopEventHandler( true ); // Delete the new handler and use the previous one

Hope that helped,
Eran
« Last Edit: August 26, 2006, 11:11:48 pm by eranif »

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2318
Re: wxScintilla events
« Reply #4 on: August 26, 2006, 11:37:04 pm »
probably same problem : how do I know the EVT_KEY_DOWN comes from the editor and not from another control in CB (or menu) ?

You can also use connect/disconnect events.
Look at cbDragScroll. You might even be able to use/copy the code, but use a key event instead of a mouse event.