Mouse-events for further use

Help
Mr. W.
2009-06-15
2013-05-02
  • Mr. W.
    Mr. W.
    2009-06-15

    Hello!

    I would like to use further functionality in some event-functions used by wxMathplot.

    So I implemented an event-table in my own class:

    BEGIN_EVENT_TABLE(MyClass, wxFrame)
        EVT_MENU(ID_QUIT, MyClass::OnQuit)
        EVT_MENU(ID_PRINT_PREVIEW, MyClass::OnPrintPreview)
        EVT_MENU(ID_PRINT, MyClass::OnPrint)
        EVT_MOUSE_EVENTS(MyClass::OnMouseLeftDown)
    END_EVENT_TABLE()

    MyClass::MyClass() : wxFrame( (wxFrame *)NULL, -1, wxT("MyClass"), wxDefaultPosition, wxSize(500,500))
    {
    m_plot = new mpWindow(this, -1, wxPoint(0,0), wxSize(100,100), wxSUNKEN_BORDER);
    }

    But when I create a plot with wxMathplot and clicked the mousebutton, the event doesn't reach my event-function.

    I hope you can tell me, how I have to implement my event-table to use the events forwarted by mathplot with event.Skip().

    Greetings and thx for any help

     
    • Nigel Paton
      Nigel Paton
      2009-06-15

      Hi,

      Not sure why this wouldn't work but then I'm no expert on wx event handling.

      When adding some extras to the mathplot code I've sometimes created a new class with mpWindow as it's base class and then put the event table in the new class.

      class MyMpClass : public mpWindow
      {
      public:
          MyMpClass(wxWindow *parent, wxWindowID id,
                      const wxPoint &pos = wxDefaultPosition,
                      const wxSize &size = wxDefaultSize,
                      int flags = 0) : mpWindow(parent, id, pos, size, flags) {}

          void OnMouseLeftDown (wxMouseEvent     &event);

          DECLARE_EVENT_TABLE()
      }

      void MyMpClass::OnMouseLeftDown (wxMouseEvent     &event)
      {
          // Do stuff
          event.Skip();
      }

      BEGIN_EVENT_TABLE(MyMpClass, mpWindow)
      EVT_LEFT_DOWN(MyMpClass::OnMouseLeftDown)
      END_EVENT_TABLE()

      m_plot = new MyMpClass(this, -1, wxPoint(0,0), wxSize(100,100), wxSUNKEN_BORDER);

      Note I've also used EVT_LEFT_DOWN rather than the more general EVT_MOUSE_EVENTS.

      Cheers

       
      • Mr. W.
        Mr. W.
        2009-06-15

        Hi!

        I will remember your solution, but I'm loath to change or add something to the mathplot-library.

        Cheers

         
        • Nigel Paton
          Nigel Paton
          2009-06-16

          Hi,

          It's not changing the mathplot lib as this code would sit in your files. It's just allowing you to intercept the events and possibly modifying/blocking the handling.

          Cheers

           
    • cdron77
      cdron77
      2009-06-15

      Maybe you're not intercepting the right event. Try with EVT_LEFT_DOWN for mouse left button.

      Anyway, I'm not sure that all mouse events of wxMathPlot are skipped: mouse left down is, but I did not checked all.

      I hope this is helpful.

      CD-RON77

       
      • Mr. W.
        Mr. W.
        2009-06-15

        Hi!

        Thanks for the fast answer.

        I tried nearly all mouse-events, also EVT_LEFT_DOWN, EVT_LEFT_DCLICK and so on. But no event occurs on my event-function.
        Furthermore I tested an EVT_CHAR-event. This is not used by wxMathplot, but its the same.

        Greetings