wxMac, PaintEvent
Stefan Csomor
csomor at advancedconcepts.ch
Sun Sep 24 22:08:56 PDT 2006
Hi Nusi
thank's very much for that detailed setup - ready to test for me :-)
stay tuned
Stefan
> -----Original Message-----
> From: Nusret Taşçı [mailto:nusi at sofha.de]
> Sent: Sonntag, 24. September 2006 19:45
> To: wx-users at lists.wxwidgets.org
> Subject: Re: wxMac, PaintEvent
>
> > wxPanels are windows, not just drawable areas, so yes, you
> will have
> > to connect the events in another way, or call back upon the parent
> > from the paint events of the chilrdren.
>
> I'm sorry that I answer so late, but I couldn't continue
> fixing the remaining problem until today.
>
> I've tracked down the issue to one specific point, let me
> give an example so that we both have something to argue about:
>
> #include "wx/wxprec.h"
> #ifndef WX_PRECOMP
> #include "wx/wx.h"
> #endif
> // Define a new application type, each program should derive
> a class from wxApp class MyApp : public wxApp {
> public:
> virtual bool OnInit();
> };
>
> // Define a new frame type: this is going to be our main
> frame class MyFrame : public wxFrame {
> public:
> MyFrame(const wxString& title);
> private:
> void ButtonClicked(wxCommandEvent &event);
> void UpperPaint(wxPaintEvent &event);
> void LowerPaint(wxPaintEvent &event);
>
> bool m_bDrawUpperRed;
> wxButton *pButton;
> wxPanel *pUpperPanel;
> wxPanel *pLowerPanel;
> DECLARE_EVENT_TABLE()
> };
>
> BEGIN_EVENT_TABLE(MyFrame, wxFrame)
> END_EVENT_TABLE()
>
> IMPLEMENT_APP(MyApp)
>
> bool MyApp::OnInit()
> {
> if ( !wxApp::OnInit() )
> return false;
> MyFrame *frame = new MyFrame(_T("Minimal wxWidgets App"));
> frame->Show(true);
> return true;
> }
>
> MyFrame::MyFrame(const wxString& title)
> : wxFrame(NULL, wxID_ANY, title) {
> m_bDrawUpperRed = false;
> pButton = new wxButton(this, wxID_ANY, wxT("Change Color"));
> pUpperPanel = new wxPanel(this, wxID_ANY, wxPoint(100,
> 0), wxSize(100, 100));
> pLowerPanel = new wxPanel(this, wxID_ANY, wxPoint(100,
> 100), wxSize(100, 100));
> pButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
> wxCommandEventHandler(MyFrame::ButtonClicked), NULL, this);
> // POI
> pUpperPanel->Connect(wxEVT_PAINT,
> wxPaintEventHandler(MyFrame::UpperPaint), NULL, this);
> pLowerPanel->Connect(wxEVT_PAINT,
> wxPaintEventHandler(MyFrame::LowerPaint), NULL, this); }
>
> void MyFrame::ButtonClicked(wxCommandEvent &) {
> m_bDrawUpperRed = !m_bDrawUpperRed; #if 1 // POINT OF INTEREST
> // case 1
> pUpperPanel->Refresh();
> pLowerPanel->Refresh();
> #else
> //case 2
> Refresh();
> #endif
> }
>
> void MyFrame::UpperPaint(wxPaintEvent &event) {
> wxPaintDC dc((wxWindow*)event.GetEventObject());
> if (m_bDrawUpperRed)
> dc.SetBackground(*wxRED);
> else
> dc.SetBackground(*wxGREEN);
> dc.Clear();
> }
>
> void MyFrame::LowerPaint(wxPaintEvent &event) {
> wxPaintDC dc((wxWindow*)event.GetEventObject());
> if (m_bDrawUpperRed)
> dc.SetBackground(*wxGREEN);
> else
> dc.SetBackground(*wxRED);
> dc.Clear();
> }
>
> This sample works.
> If you change the connects to somethink like following:
> // POI
> pUpperPanel->Connect(pUpperPanel->GetId(), wxEVT_PAINT,
> wxPaintEventHandler(MyFrame::UpperPaint), NULL, this);
> pLowerPanel->Connect(pLowerPanel->GetId(), wxEVT_PAINT,
> wxPaintEventHandler(MyFrame::LowerPaint), NULL, this);
>
> than it will not work anymore. The difference is "->GetId()".
> When connecting to a painthandler, this seems not to work for
> wxMac. However, Connecting with GetId() for other handlers
> seem to work, though I haven't tested all of them of course.
>
>
> Nusi
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wx-users-unsubscribe at lists.wxwidgets.org
> For additional commands, e-mail: wx-users-help at lists.wxwidgets.org
>
>
More information about the wx-users
mailing list