]> git.saurik.com Git - wxWidgets.git/commitdiff
Use member variable instead of a global in the dialogs sample.
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 5 Oct 2009 22:53:32 +0000 (22:53 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 5 Oct 2009 22:53:32 +0000 (22:53 +0000)
Made MyCanvas member of MyFrame instead of using a global variable which was
put inside the frame by wxApp.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62263 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/dialogs/dialogs.cpp
samples/dialogs/dialogs.h

index 7d554673aadda05ee38b339dd7822dee30e73935..8b59fce29db8a60a7745a0fc46b7a2e605e7c6ab 100644 (file)
@@ -260,8 +260,6 @@ BEGIN_EVENT_TABLE(StdButtonSizerDialog, wxDialog)
     EVT_RADIOBUTTON(wxID_ANY, StdButtonSizerDialog::OnEvent)
 END_EVENT_TABLE()
 
-MyCanvas *myCanvas = (MyCanvas *) NULL;
-
 // `Main program' equivalent, creating windows and returning main app frame
 bool MyApp::OnInit()
 {
@@ -475,9 +473,6 @@ bool MyApp::OnInit()
 
     frame->SetMenuBar(menubar);
 
-    myCanvas = new MyCanvas(frame);
-    myCanvas->SetBackgroundColour(*wxWHITE);
-
     frame->Centre(wxBOTH);
 
     // Show the frame
@@ -520,6 +515,8 @@ MyFrame::MyFrame(wxWindow *parent,
 #if wxUSE_STATUSBAR
     CreateStatusBar();
 #endif // wxUSE_STATUSBAR
+
+    m_canvas = new MyCanvas(this);
 }
 
 MyFrame::~MyFrame()
@@ -533,16 +530,16 @@ MyFrame::~MyFrame()
 
 void MyFrame::ChooseColour(wxCommandEvent& WXUNUSED(event))
 {
-    m_clrData.SetColour(myCanvas->GetBackgroundColour());
+    m_clrData.SetColour(m_canvas->GetBackgroundColour());
 
     wxColourDialog dialog(this, &m_clrData);
     dialog.SetTitle(_("Please choose the background colour"));
     if ( dialog.ShowModal() == wxID_OK )
     {
         m_clrData = dialog.GetColourData();
-        myCanvas->SetBackgroundColour(m_clrData.GetColour());
-        myCanvas->ClearBackground();
-        myCanvas->Refresh();
+        m_canvas->SetBackgroundColour(m_clrData.GetColour());
+        m_canvas->ClearBackground();
+        m_canvas->Refresh();
     }
 }
 
@@ -557,7 +554,7 @@ void MyFrame::GetColour(wxCommandEvent& WXUNUSED(event))
     if ( clr.IsOk() )
     {
         wxGetApp().m_canvasTextColour = clr;
-        myCanvas->Refresh();
+        m_canvas->Refresh();
     }
     //else: dialog cancelled by user
 }
@@ -568,7 +565,7 @@ void MyFrame::GetColour(wxCommandEvent& WXUNUSED(event))
 #if USE_COLOURDLG_GENERIC
 void MyFrame::ChooseColourGeneric(wxCommandEvent& WXUNUSED(event))
 {
-    m_clrData.SetColour(myCanvas->GetBackgroundColour());
+    m_clrData.SetColour(m_canvas->GetBackgroundColour());
 
     //FIXME:TODO:This has no effect...
     m_clrData.SetChooseFull(true);
@@ -587,9 +584,9 @@ void MyFrame::ChooseColourGeneric(wxCommandEvent& WXUNUSED(event))
     if (dialog->ShowModal() == wxID_OK)
     {
         m_clrData = dialog->GetColourData();
-        myCanvas->SetBackgroundColour(m_clrData.GetColour());
-        myCanvas->ClearBackground();
-        myCanvas->Refresh();
+        m_canvas->SetBackgroundColour(m_clrData.GetColour());
+        m_canvas->ClearBackground();
+        m_canvas->Refresh();
     }
     dialog->Destroy();
 }
@@ -614,7 +611,7 @@ void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) )
         wxFontData retData = dialog.GetFontData();
         wxGetApp().m_canvasFont = retData.GetChosenFont();
         wxGetApp().m_canvasTextColour = retData.GetColour();
-        myCanvas->Refresh();
+        m_canvas->Refresh();
     }
     //else: cancelled by the user, don't change the font
 }
@@ -633,7 +630,7 @@ void MyFrame::ChooseFontGeneric(wxCommandEvent& WXUNUSED(event) )
         wxFontData retData = dialog->GetFontData();
         wxGetApp().m_canvasFont = retData.GetChosenFont();
         wxGetApp().m_canvasTextColour = retData.GetColour();
-        myCanvas->Refresh();
+        m_canvas->Refresh();
     }
     dialog->Destroy();
 }
index 52630093d158d34deedb5f7ce93e842df4c96145..90b46574a28599492b70bc1602f326a25ab13bf7 100644 (file)
@@ -422,15 +422,21 @@ private:
 
     wxColourData m_clrData;
 
+    // just a window which we use to show the effect of font/colours selection
+    wxWindow *m_canvas;
+
     DECLARE_EVENT_TABLE()
 };
 
 class MyCanvas: public wxScrolledWindow
 {
 public:
-    MyCanvas(wxWindow *parent) :
-       wxScrolledWindow(parent,wxID_ANY,wxDefaultPosition,wxDefaultSize,wxNO_FULL_REPAINT_ON_RESIZE) { }
+    MyCanvas(wxWindow *parent) : wxScrolledWindow(parent, wxID_ANY)
+    {
+        SetBackgroundColour(*wxWHITE);
+    }
 
+private:
     void OnPaint(wxPaintEvent& event);
 
     DECLARE_EVENT_TABLE()