]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/richtext/richtextbackgroundpage.cpp
Fixed layout and hit-testing problem particularly with centred lines
[wxWidgets.git] / src / richtext / richtextbackgroundpage.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/richtext/richtextbackgroundpage.cpp
3// Purpose:
4// Author: Julian Smart
5// Modified by:
6// Created: 13/11/2010 11:17:25
7// RCS-ID:
8// Copyright: (c) Julian Smart
9// Licence: wxWindows Licence
10/////////////////////////////////////////////////////////////////////////////
11
12#include "wx/richtext/richtextbackgroundpage.h"
13#include "wx/richtext/richtextformatdlg.h"
14
15////@begin XPM images
16////@end XPM images
17
18
19/*!
20 * wxRichTextBackgroundPage type definition
21 */
22
23IMPLEMENT_DYNAMIC_CLASS( wxRichTextBackgroundPage, wxRichTextDialogPage )
24
25
26/*!
27 * wxRichTextBackgroundPage event table definition
28 */
29
30BEGIN_EVENT_TABLE( wxRichTextBackgroundPage, wxRichTextDialogPage )
31EVT_BUTTON(ID_RICHTEXT_BACKGROUND_COLOUR_SWATCH, wxRichTextBackgroundPage::OnColourSwatch)
32
33////@begin wxRichTextBackgroundPage event table entries
34////@end wxRichTextBackgroundPage event table entries
35
36END_EVENT_TABLE()
37
38IMPLEMENT_HELP_PROVISION(wxRichTextBackgroundPage)
39
40/*!
41 * wxRichTextBackgroundPage constructors
42 */
43
44wxRichTextBackgroundPage::wxRichTextBackgroundPage()
45{
46 Init();
47}
48
49wxRichTextBackgroundPage::wxRichTextBackgroundPage( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
50{
51 Init();
52 Create(parent, id, pos, size, style);
53}
54
55
56/*!
57 * wxRichTextBackgroundPage creator
58 */
59
60bool wxRichTextBackgroundPage::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
61{
62////@begin wxRichTextBackgroundPage creation
63 SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY);
64 wxRichTextDialogPage::Create( parent, id, pos, size, style );
65
66 CreateControls();
67 if (GetSizer())
68 {
69 GetSizer()->SetSizeHints(this);
70 }
71 Centre();
72////@end wxRichTextBackgroundPage creation
73 return true;
74}
75
76
77/*!
78 * wxRichTextBackgroundPage destructor
79 */
80
81wxRichTextBackgroundPage::~wxRichTextBackgroundPage()
82{
83////@begin wxRichTextBackgroundPage destruction
84////@end wxRichTextBackgroundPage destruction
85}
86
87
88/*!
89 * Member initialisation
90 */
91
92void wxRichTextBackgroundPage::Init()
93{
94////@begin wxRichTextBackgroundPage member initialisation
95 m_backgroundColourCheckBox = NULL;
96 m_backgroundColourSwatch = NULL;
97////@end wxRichTextBackgroundPage member initialisation
98}
99
100
101/*!
102 * Control creation for wxRichTextBackgroundPage
103 */
104
105void wxRichTextBackgroundPage::CreateControls()
106{
107////@begin wxRichTextBackgroundPage content construction
108 wxRichTextBackgroundPage* itemRichTextDialogPage1 = this;
109
110 wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
111 itemRichTextDialogPage1->SetSizer(itemBoxSizer2);
112
113 wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxVERTICAL);
114 itemBoxSizer2->Add(itemBoxSizer3, 1, wxGROW, 5);
115
116 wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
117 itemBoxSizer3->Add(itemBoxSizer4, 0, wxGROW, 5);
118
119 wxStaticText* itemStaticText5 = new wxStaticText( itemRichTextDialogPage1, wxID_STATIC, _("Background"), wxDefaultPosition, wxDefaultSize, 0 );
120 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("")));
121 itemBoxSizer4->Add(itemStaticText5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
122
123 wxStaticLine* itemStaticLine6 = new wxStaticLine( itemRichTextDialogPage1, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
124 itemBoxSizer4->Add(itemStaticLine6, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
125
126 wxBoxSizer* itemBoxSizer7 = new wxBoxSizer(wxHORIZONTAL);
127 itemBoxSizer3->Add(itemBoxSizer7, 0, wxGROW, 5);
128
129 itemBoxSizer7->Add(5, 5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
130
131 m_backgroundColourCheckBox = new wxCheckBox( itemRichTextDialogPage1, ID_RICHTEXT_BACKGROUND_COLOUR_CHECKBOX, _("Background &colour:"), wxDefaultPosition, wxDefaultSize, 0 );
132 m_backgroundColourCheckBox->SetValue(false);
133 m_backgroundColourCheckBox->SetHelpText(_("Enables a background colour."));
134 if (wxRichTextBackgroundPage::ShowToolTips())
135 m_backgroundColourCheckBox->SetToolTip(_("Enables a background colour."));
136 itemBoxSizer7->Add(m_backgroundColourCheckBox, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
137
138 m_backgroundColourSwatch = new wxRichTextColourSwatchCtrl( itemRichTextDialogPage1, ID_RICHTEXT_BACKGROUND_COLOUR_SWATCH, wxDefaultPosition, wxSize(80, 20), wxBORDER_THEME );
139 m_backgroundColourSwatch->SetHelpText(_("The background colour."));
140 if (wxRichTextBackgroundPage::ShowToolTips())
141 m_backgroundColourSwatch->SetToolTip(_("The background colour."));
142 itemBoxSizer7->Add(m_backgroundColourSwatch, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
143
144////@end wxRichTextBackgroundPage content construction
145}
146
147
148/*!
149 * Should we show tooltips?
150 */
151
152wxRichTextAttr* wxRichTextBackgroundPage::GetAttributes()
153{
154 return wxRichTextFormattingDialog::GetDialogAttributes(this);
155}
156
157bool wxRichTextBackgroundPage::TransferDataToWindow()
158{
159 wxRichTextAttr* attr = GetAttributes();
160 if (!attr->HasBackgroundColour())
161 {
162 m_backgroundColourCheckBox->SetValue(false);
163 m_backgroundColourSwatch->SetColour(*wxWHITE);
164 }
165 else
166 {
167 m_backgroundColourCheckBox->SetValue(true);
168 m_backgroundColourSwatch->SetColour(attr->GetBackgroundColour());
169 }
170
171 return true;
172}
173
174bool wxRichTextBackgroundPage::TransferDataFromWindow()
175{
176 wxRichTextAttr* attr = GetAttributes();
177 if (m_backgroundColourCheckBox->GetValue())
178 {
179 attr->SetBackgroundColour(m_backgroundColourSwatch->GetColour());
180 }
181 else
182 {
183 attr->SetFlags(attr->GetFlags() & ~wxTEXT_ATTR_BACKGROUND_COLOUR);
184 }
185
186 return true;
187}
188
189// Respond to colour swatch click
190void wxRichTextBackgroundPage::OnColourSwatch(wxCommandEvent& event)
191{
192 m_backgroundColourCheckBox->SetValue(true);
193 event.Skip();
194}
195
196bool wxRichTextBackgroundPage::ShowToolTips()
197{
198 return true;
199}
200
201/*!
202 * Get bitmap resources
203 */
204
205wxBitmap wxRichTextBackgroundPage::GetBitmapResource( const wxString& name )
206{
207 // Bitmap retrieval
208////@begin wxRichTextBackgroundPage bitmap retrieval
209 wxUnusedVar(name);
210 return wxNullBitmap;
211////@end wxRichTextBackgroundPage bitmap retrieval
212}
213
214/*!
215 * Get icon resources
216 */
217
218wxIcon wxRichTextBackgroundPage::GetIconResource( const wxString& name )
219{
220 // Icon retrieval
221////@begin wxRichTextBackgroundPage icon retrieval
222 wxUnusedVar(name);
223 return wxNullIcon;
224////@end wxRichTextBackgroundPage icon retrieval
225}