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:
@@ -271,9 +271,6 @@ bool MyApp::OnInit()
|
|||||||
wxInitAllImageHandlers();
|
wxInitAllImageHandlers();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_canvasTextColour = *wxBLACK;
|
|
||||||
m_canvasFont = *wxNORMAL_FONT;
|
|
||||||
|
|
||||||
// Create the main frame window
|
// Create the main frame window
|
||||||
MyFrame *frame = new MyFrame(wxT("wxWidgets dialogs example"));
|
MyFrame *frame = new MyFrame(wxT("wxWidgets dialogs example"));
|
||||||
|
|
||||||
@@ -544,12 +541,12 @@ void MyFrame::GetColour(wxCommandEvent& WXUNUSED(event))
|
|||||||
wxColour clr = wxGetColourFromUser
|
wxColour clr = wxGetColourFromUser
|
||||||
(
|
(
|
||||||
this,
|
this,
|
||||||
wxGetApp().m_canvasTextColour,
|
m_canvas->GetForegroundColour(),
|
||||||
"Please choose the foreground colour"
|
"Please choose the foreground colour"
|
||||||
);
|
);
|
||||||
if ( clr.IsOk() )
|
if ( clr.IsOk() )
|
||||||
{
|
{
|
||||||
wxGetApp().m_canvasTextColour = clr;
|
m_canvas->SetForegroundColour(clr);
|
||||||
m_canvas->Refresh();
|
m_canvas->Refresh();
|
||||||
}
|
}
|
||||||
//else: dialog cancelled by user
|
//else: dialog cancelled by user
|
||||||
@@ -592,8 +589,8 @@ void MyFrame::ChooseColourGeneric(wxCommandEvent& WXUNUSED(event))
|
|||||||
void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) )
|
void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) )
|
||||||
{
|
{
|
||||||
wxFontData data;
|
wxFontData data;
|
||||||
data.SetInitialFont(wxGetApp().m_canvasFont);
|
data.SetInitialFont(m_canvas->GetFont());
|
||||||
data.SetColour(wxGetApp().m_canvasTextColour);
|
data.SetColour(m_canvas->GetForegroundColour());
|
||||||
|
|
||||||
// you might also do this:
|
// you might also do this:
|
||||||
//
|
//
|
||||||
@@ -605,8 +602,8 @@ void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) )
|
|||||||
if (dialog.ShowModal() == wxID_OK)
|
if (dialog.ShowModal() == wxID_OK)
|
||||||
{
|
{
|
||||||
wxFontData retData = dialog.GetFontData();
|
wxFontData retData = dialog.GetFontData();
|
||||||
wxGetApp().m_canvasFont = retData.GetChosenFont();
|
m_canvas->SetFont(retData.GetChosenFont());
|
||||||
wxGetApp().m_canvasTextColour = retData.GetColour();
|
m_canvas->SetForegroundColour(retData.GetColour());
|
||||||
m_canvas->Refresh();
|
m_canvas->Refresh();
|
||||||
}
|
}
|
||||||
//else: cancelled by the user, don't change the font
|
//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) )
|
void MyFrame::ChooseFontGeneric(wxCommandEvent& WXUNUSED(event) )
|
||||||
{
|
{
|
||||||
wxFontData data;
|
wxFontData data;
|
||||||
data.SetInitialFont(wxGetApp().m_canvasFont);
|
data.SetInitialFont(m_canvas->GetFont());
|
||||||
data.SetColour(wxGetApp().m_canvasTextColour);
|
data.SetColour(m_canvas->GetForegroundColour());
|
||||||
|
|
||||||
wxGenericFontDialog *dialog = new wxGenericFontDialog(this, data);
|
wxGenericFontDialog *dialog = new wxGenericFontDialog(this, data);
|
||||||
if (dialog->ShowModal() == wxID_OK)
|
if (dialog->ShowModal() == wxID_OK)
|
||||||
{
|
{
|
||||||
wxFontData retData = dialog->GetFontData();
|
wxFontData retData = dialog->GetFontData();
|
||||||
wxGetApp().m_canvasFont = retData.GetChosenFont();
|
m_canvas->SetFont(retData.GetChosenFont());
|
||||||
wxGetApp().m_canvasTextColour = retData.GetColour();
|
m_canvas->SetForegroundColour(retData.GetColour());
|
||||||
m_canvas->Refresh();
|
m_canvas->Refresh();
|
||||||
}
|
}
|
||||||
dialog->Destroy();
|
dialog->Destroy();
|
||||||
@@ -1933,8 +1930,6 @@ void MyFrame::OnFindDialog(wxFindDialogEvent& event)
|
|||||||
void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) )
|
void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) )
|
||||||
{
|
{
|
||||||
wxPaintDC dc(this);
|
wxPaintDC dc(this);
|
||||||
dc.SetFont(wxGetApp().m_canvasFont);
|
|
||||||
dc.SetTextForeground(wxGetApp().m_canvasTextColour);
|
|
||||||
dc.SetBackgroundMode(wxTRANSPARENT);
|
dc.SetBackgroundMode(wxTRANSPARENT);
|
||||||
dc.DrawText(
|
dc.DrawText(
|
||||||
wxT("wxWidgets common dialogs")
|
wxT("wxWidgets common dialogs")
|
||||||
|
@@ -117,9 +117,6 @@ class MyApp: public wxApp
|
|||||||
public:
|
public:
|
||||||
virtual bool OnInit();
|
virtual bool OnInit();
|
||||||
|
|
||||||
wxFont m_canvasFont;
|
|
||||||
wxColour m_canvasTextColour;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
#if wxUSE_LOG
|
#if wxUSE_LOG
|
||||||
virtual wxAppTraits *CreateTraits() { return new MyAppTraits; }
|
virtual wxAppTraits *CreateTraits() { return new MyAppTraits; }
|
||||||
@@ -434,7 +431,9 @@ class MyCanvas: public wxScrolledWindow
|
|||||||
public:
|
public:
|
||||||
MyCanvas(wxWindow *parent) : wxScrolledWindow(parent, wxID_ANY)
|
MyCanvas(wxWindow *parent) : wxScrolledWindow(parent, wxID_ANY)
|
||||||
{
|
{
|
||||||
|
SetForegroundColour(*wxBLACK);
|
||||||
SetBackgroundColour(*wxWHITE);
|
SetBackgroundColour(*wxWHITE);
|
||||||
|
SetFont(*wxNORMAL_FONT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Reference in New Issue
Block a user