Use member variable instead of a global in the dialogs sample.

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
This commit is contained in:
Vadim Zeitlin
2009-10-05 22:53:32 +00:00
parent e9ee227022
commit 87a1867991
2 changed files with 21 additions and 18 deletions

View File

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

View File

@@ -422,15 +422,21 @@ private:
wxColourData m_clrData; wxColourData m_clrData;
// just a window which we use to show the effect of font/colours selection
wxWindow *m_canvas;
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
class MyCanvas: public wxScrolledWindow class MyCanvas: public wxScrolledWindow
{ {
public: public:
MyCanvas(wxWindow *parent) : MyCanvas(wxWindow *parent) : wxScrolledWindow(parent, wxID_ANY)
wxScrolledWindow(parent,wxID_ANY,wxDefaultPosition,wxDefaultSize,wxNO_FULL_REPAINT_ON_RESIZE) { } {
SetBackgroundColour(*wxWHITE);
}
private:
void OnPaint(wxPaintEvent& event); void OnPaint(wxPaintEvent& event);
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()