Store canvas attributes in the canvas itself in the dialogs sample.

Simplify the code by not transferring font and colours between canvas and
wxTheApp but use canvas font and colours directly instead.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62265 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2009-10-05 22:53:44 +00:00
parent 5b05ce47a4
commit 3406ebd4ea
2 changed files with 12 additions and 18 deletions

View File

@ -271,9 +271,6 @@ bool MyApp::OnInit()
wxInitAllImageHandlers();
#endif
m_canvasTextColour = *wxBLACK;
m_canvasFont = *wxNORMAL_FONT;
// Create the main frame window
MyFrame *frame = new MyFrame(wxT("wxWidgets dialogs example"));
@ -544,12 +541,12 @@ void MyFrame::GetColour(wxCommandEvent& WXUNUSED(event))
wxColour clr = wxGetColourFromUser
(
this,
wxGetApp().m_canvasTextColour,
m_canvas->GetForegroundColour(),
"Please choose the foreground colour"
);
if ( clr.IsOk() )
{
wxGetApp().m_canvasTextColour = clr;
m_canvas->SetForegroundColour(clr);
m_canvas->Refresh();
}
//else: dialog cancelled by user
@ -592,8 +589,8 @@ void MyFrame::ChooseColourGeneric(wxCommandEvent& WXUNUSED(event))
void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) )
{
wxFontData data;
data.SetInitialFont(wxGetApp().m_canvasFont);
data.SetColour(wxGetApp().m_canvasTextColour);
data.SetInitialFont(m_canvas->GetFont());
data.SetColour(m_canvas->GetForegroundColour());
// you might also do this:
//
@ -605,8 +602,8 @@ void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) )
if (dialog.ShowModal() == wxID_OK)
{
wxFontData retData = dialog.GetFontData();
wxGetApp().m_canvasFont = retData.GetChosenFont();
wxGetApp().m_canvasTextColour = retData.GetColour();
m_canvas->SetFont(retData.GetChosenFont());
m_canvas->SetForegroundColour(retData.GetColour());
m_canvas->Refresh();
}
//else: cancelled by the user, don't change the font
@ -617,15 +614,15 @@ void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) )
void MyFrame::ChooseFontGeneric(wxCommandEvent& WXUNUSED(event) )
{
wxFontData data;
data.SetInitialFont(wxGetApp().m_canvasFont);
data.SetColour(wxGetApp().m_canvasTextColour);
data.SetInitialFont(m_canvas->GetFont());
data.SetColour(m_canvas->GetForegroundColour());
wxGenericFontDialog *dialog = new wxGenericFontDialog(this, data);
if (dialog->ShowModal() == wxID_OK)
{
wxFontData retData = dialog->GetFontData();
wxGetApp().m_canvasFont = retData.GetChosenFont();
wxGetApp().m_canvasTextColour = retData.GetColour();
m_canvas->SetFont(retData.GetChosenFont());
m_canvas->SetForegroundColour(retData.GetColour());
m_canvas->Refresh();
}
dialog->Destroy();
@ -1933,8 +1930,6 @@ void MyFrame::OnFindDialog(wxFindDialogEvent& event)
void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) )
{
wxPaintDC dc(this);
dc.SetFont(wxGetApp().m_canvasFont);
dc.SetTextForeground(wxGetApp().m_canvasTextColour);
dc.SetBackgroundMode(wxTRANSPARENT);
dc.DrawText(
wxT("wxWidgets common dialogs")

View File

@ -117,9 +117,6 @@ class MyApp: public wxApp
public:
virtual bool OnInit();
wxFont m_canvasFont;
wxColour m_canvasTextColour;
protected:
#if wxUSE_LOG
virtual wxAppTraits *CreateTraits() { return new MyAppTraits; }
@ -434,7 +431,9 @@ class MyCanvas: public wxScrolledWindow
public:
MyCanvas(wxWindow *parent) : wxScrolledWindow(parent, wxID_ANY)
{
SetForegroundColour(*wxBLACK);
SetBackgroundColour(*wxWHITE);
SetFont(*wxNORMAL_FONT);
}
private: