1 /////////////////////////////////////////////////////////////////////////////
2 // Name: richtextbackgroundpage.cpp
4 // Author: Julian Smart
6 // Created: 13/11/2010 11:17:25
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows Licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
26 #include "wx/richtext/richtextbackgroundpage.h"
27 #include "wx/richtext/richtextformatdlg.h"
34 * wxRichTextBackgroundPage type definition
37 IMPLEMENT_DYNAMIC_CLASS( wxRichTextBackgroundPage
, wxRichTextDialogPage
)
41 * wxRichTextBackgroundPage event table definition
44 BEGIN_EVENT_TABLE( wxRichTextBackgroundPage
, wxRichTextDialogPage
)
45 EVT_BUTTON(ID_RICHTEXT_BACKGROUND_COLOUR_SWATCH
, wxRichTextBackgroundPage::OnColourSwatch
)
47 ////@begin wxRichTextBackgroundPage event table entries
48 ////@end wxRichTextBackgroundPage event table entries
52 IMPLEMENT_HELP_PROVISION(wxRichTextBackgroundPage
)
55 * wxRichTextBackgroundPage constructors
58 wxRichTextBackgroundPage::wxRichTextBackgroundPage()
63 wxRichTextBackgroundPage::wxRichTextBackgroundPage( wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
66 Create(parent
, id
, pos
, size
, style
);
71 * wxRichTextBackgroundPage creator
74 bool wxRichTextBackgroundPage::Create( wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
76 ////@begin wxRichTextBackgroundPage creation
77 SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY
);
78 wxRichTextDialogPage::Create( parent
, id
, pos
, size
, style
);
83 GetSizer()->SetSizeHints(this);
86 ////@end wxRichTextBackgroundPage creation
92 * wxRichTextBackgroundPage destructor
95 wxRichTextBackgroundPage::~wxRichTextBackgroundPage()
97 ////@begin wxRichTextBackgroundPage destruction
98 ////@end wxRichTextBackgroundPage destruction
103 * Member initialisation
106 void wxRichTextBackgroundPage::Init()
108 ////@begin wxRichTextBackgroundPage member initialisation
109 m_backgroundColourCheckBox
= NULL
;
110 m_backgroundColourSwatch
= NULL
;
111 ////@end wxRichTextBackgroundPage member initialisation
116 * Control creation for wxRichTextBackgroundPage
119 void wxRichTextBackgroundPage::CreateControls()
121 ////@begin wxRichTextBackgroundPage content construction
122 wxRichTextBackgroundPage
* itemRichTextDialogPage1
= this;
124 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
125 itemRichTextDialogPage1
->SetSizer(itemBoxSizer2
);
127 wxBoxSizer
* itemBoxSizer3
= new wxBoxSizer(wxVERTICAL
);
128 itemBoxSizer2
->Add(itemBoxSizer3
, 1, wxGROW
, 5);
130 wxBoxSizer
* itemBoxSizer4
= new wxBoxSizer(wxHORIZONTAL
);
131 itemBoxSizer3
->Add(itemBoxSizer4
, 0, wxGROW
, 5);
133 wxStaticText
* itemStaticText5
= new wxStaticText( itemRichTextDialogPage1
, wxID_STATIC
, _("Background"), wxDefaultPosition
, wxDefaultSize
, 0 );
134 itemStaticText5
->SetFont(wxFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
).GetPointSize(), wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
).GetFamily(), wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
).GetStyle(), wxBOLD
, false, wxT("")));
135 itemBoxSizer4
->Add(itemStaticText5
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
137 wxStaticLine
* itemStaticLine6
= new wxStaticLine( itemRichTextDialogPage1
, wxID_STATIC
, wxDefaultPosition
, wxDefaultSize
, wxLI_HORIZONTAL
);
138 itemBoxSizer4
->Add(itemStaticLine6
, 1, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
140 wxBoxSizer
* itemBoxSizer7
= new wxBoxSizer(wxHORIZONTAL
);
141 itemBoxSizer3
->Add(itemBoxSizer7
, 0, wxGROW
, 5);
143 itemBoxSizer7
->Add(5, 5, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
145 m_backgroundColourCheckBox
= new wxCheckBox( itemRichTextDialogPage1
, ID_RICHTEXT_BACKGROUND_COLOUR_CHECKBOX
, _("Background &colour:"), wxDefaultPosition
, wxDefaultSize
, 0 );
146 m_backgroundColourCheckBox
->SetValue(false);
147 m_backgroundColourCheckBox
->SetHelpText(_("Enables a background colour."));
148 if (wxRichTextBackgroundPage::ShowToolTips())
149 m_backgroundColourCheckBox
->SetToolTip(_("Enables a background colour."));
150 itemBoxSizer7
->Add(m_backgroundColourCheckBox
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
152 m_backgroundColourSwatch
= new wxRichTextColourSwatchCtrl( itemRichTextDialogPage1
, ID_RICHTEXT_BACKGROUND_COLOUR_SWATCH
, wxDefaultPosition
, wxSize(80, 20), wxBORDER_THEME
);
153 m_backgroundColourSwatch
->SetHelpText(_("The background colour."));
154 if (wxRichTextBackgroundPage::ShowToolTips())
155 m_backgroundColourSwatch
->SetToolTip(_("The background colour."));
156 itemBoxSizer7
->Add(m_backgroundColourSwatch
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
158 ////@end wxRichTextBackgroundPage content construction
163 * Should we show tooltips?
166 wxRichTextAttr
* wxRichTextBackgroundPage::GetAttributes()
168 return wxRichTextFormattingDialog::GetDialogAttributes(this);
171 bool wxRichTextBackgroundPage::TransferDataToWindow()
173 wxRichTextAttr
* attr
= GetAttributes();
174 if (!attr
->HasBackgroundColour())
176 m_backgroundColourCheckBox
->SetValue(false);
177 m_backgroundColourSwatch
->SetColour(*wxWHITE
);
181 m_backgroundColourCheckBox
->SetValue(true);
182 m_backgroundColourSwatch
->SetColour(attr
->GetBackgroundColour());
188 bool wxRichTextBackgroundPage::TransferDataFromWindow()
190 wxRichTextAttr
* attr
= GetAttributes();
191 if (m_backgroundColourCheckBox
->GetValue())
193 attr
->SetBackgroundColour(m_backgroundColourSwatch
->GetColour());
197 attr
->SetFlags(attr
->GetFlags() & ~wxTEXT_ATTR_BACKGROUND_COLOUR
);
203 // Respond to colour swatch click
204 void wxRichTextBackgroundPage::OnColourSwatch(wxCommandEvent
& event
)
206 m_backgroundColourCheckBox
->SetValue(true);
210 bool wxRichTextBackgroundPage::ShowToolTips()
216 * Get bitmap resources
219 wxBitmap
wxRichTextBackgroundPage::GetBitmapResource( const wxString
& name
)
222 ////@begin wxRichTextBackgroundPage bitmap retrieval
225 ////@end wxRichTextBackgroundPage bitmap retrieval
232 wxIcon
wxRichTextBackgroundPage::GetIconResource( const wxString
& name
)
235 ////@begin wxRichTextBackgroundPage icon retrieval
238 ////@end wxRichTextBackgroundPage icon retrieval