1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/richtext/richtextstylepage.cpp
4 // Author: Julian Smart
6 // Created: 10/5/2006 11:34:55 AM
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
14 #include "wx/richtext/richtextstylepage.h"
17 * wxRichTextStylePage type definition
20 IMPLEMENT_DYNAMIC_CLASS( wxRichTextStylePage
, wxRichTextDialogPage
)
23 * wxRichTextStylePage event table definition
26 BEGIN_EVENT_TABLE( wxRichTextStylePage
, wxRichTextDialogPage
)
28 ////@begin wxRichTextStylePage event table entries
29 EVT_UPDATE_UI( ID_RICHTEXTSTYLEPAGE_NEXT_STYLE
, wxRichTextStylePage::OnNextStyleUpdate
)
31 ////@end wxRichTextStylePage event table entries
35 IMPLEMENT_HELP_PROVISION(wxRichTextStylePage
)
38 * wxRichTextStylePage constructors
41 wxRichTextStylePage::wxRichTextStylePage( )
46 wxRichTextStylePage::wxRichTextStylePage( wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
49 Create(parent
, id
, pos
, size
, style
);
56 void wxRichTextStylePage::Init()
58 ////@begin wxRichTextStylePage member initialisation
62 ////@end wxRichTextStylePage member initialisation
66 * wxRichTextStylePage creator
69 bool wxRichTextStylePage::Create( wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
)
71 ////@begin wxRichTextStylePage creation
72 wxRichTextDialogPage::Create( parent
, id
, pos
, size
, style
);
77 GetSizer()->SetSizeHints(this);
80 ////@end wxRichTextStylePage creation
85 * Control creation for wxRichTextStylePage
88 void wxRichTextStylePage::CreateControls()
90 ////@begin wxRichTextStylePage content construction
91 wxRichTextStylePage
* itemRichTextDialogPage1
= this;
93 wxBoxSizer
* itemBoxSizer2
= new wxBoxSizer(wxVERTICAL
);
94 itemRichTextDialogPage1
->SetSizer(itemBoxSizer2
);
96 wxBoxSizer
* itemBoxSizer3
= new wxBoxSizer(wxVERTICAL
);
97 itemBoxSizer2
->Add(itemBoxSizer3
, 1, wxGROW
|wxALL
, 5);
99 wxBoxSizer
* itemBoxSizer4
= new wxBoxSizer(wxHORIZONTAL
);
100 itemBoxSizer3
->Add(itemBoxSizer4
, 0, wxGROW
, 5);
102 wxBoxSizer
* itemBoxSizer5
= new wxBoxSizer(wxVERTICAL
);
103 itemBoxSizer4
->Add(itemBoxSizer5
, 1, wxGROW
, 5);
105 wxStaticText
* itemStaticText6
= new wxStaticText( itemRichTextDialogPage1
, wxID_STATIC
, _("&Style:"), wxDefaultPosition
, wxDefaultSize
, 0 );
106 itemBoxSizer5
->Add(itemStaticText6
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
108 m_styleName
= new wxTextCtrl( itemRichTextDialogPage1
, ID_RICHTEXTSTYLEPAGE_STYLE_NAME
, wxEmptyString
, wxDefaultPosition
, wxSize(300, -1), wxTE_READONLY
);
109 m_styleName
->SetHelpText(_("The style name."));
110 if (wxRichTextStylePage::ShowToolTips())
111 m_styleName
->SetToolTip(_("The style name."));
112 itemBoxSizer5
->Add(m_styleName
, 0, wxGROW
|wxALL
, 5);
114 wxStaticText
* itemStaticText8
= new wxStaticText( itemRichTextDialogPage1
, wxID_STATIC
, _("&Based on:"), wxDefaultPosition
, wxDefaultSize
, 0 );
115 itemBoxSizer5
->Add(itemStaticText8
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
117 wxArrayString m_basedOnStrings
;
118 m_basedOn
= new wxComboBox( itemRichTextDialogPage1
, ID_RICHTEXTSTYLEPAGE_BASED_ON
, wxEmptyString
, wxDefaultPosition
, wxSize(300, -1), m_basedOnStrings
, wxCB_DROPDOWN
);
119 m_basedOn
->SetHelpText(_("The style on which this style is based."));
120 if (wxRichTextStylePage::ShowToolTips())
121 m_basedOn
->SetToolTip(_("The style on which this style is based."));
122 itemBoxSizer5
->Add(m_basedOn
, 0, wxGROW
|wxALL
, 5);
124 wxStaticText
* itemStaticText10
= new wxStaticText( itemRichTextDialogPage1
, wxID_STATIC
, _("&Next style:"), wxDefaultPosition
, wxDefaultSize
, 0 );
125 itemBoxSizer5
->Add(itemStaticText10
, 0, wxALIGN_LEFT
|wxLEFT
|wxRIGHT
|wxTOP
, 5);
127 wxArrayString m_nextStyleStrings
;
128 m_nextStyle
= new wxComboBox( itemRichTextDialogPage1
, ID_RICHTEXTSTYLEPAGE_NEXT_STYLE
, wxEmptyString
, wxDefaultPosition
, wxSize(300, -1), m_nextStyleStrings
, wxCB_DROPDOWN
);
129 m_nextStyle
->SetHelpText(_("The default style for the next paragraph."));
130 if (wxRichTextStylePage::ShowToolTips())
131 m_nextStyle
->SetToolTip(_("The default style for the next paragraph."));
132 itemBoxSizer5
->Add(m_nextStyle
, 0, wxGROW
|wxALL
, 5);
134 itemBoxSizer3
->Add(5, 5, 1, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 5);
136 ////@end wxRichTextStylePage content construction
139 /// Transfer data from/to window
140 bool wxRichTextStylePage::TransferDataFromWindow()
142 wxPanel::TransferDataFromWindow();
144 wxRichTextStyleDefinition
* def
= wxRichTextFormattingDialog::GetDialogStyleDefinition(this);
147 wxRichTextParagraphStyleDefinition
* paraDef
= wxDynamicCast(def
, wxRichTextParagraphStyleDefinition
);
149 paraDef
->SetNextStyle(m_nextStyle
->GetValue());
151 def
->SetName(m_styleName
->GetValue());
152 def
->SetBaseStyle(m_basedOn
->GetValue());
158 bool wxRichTextStylePage::TransferDataToWindow()
160 wxPanel::TransferDataToWindow();
162 wxRichTextStyleDefinition
* def
= wxRichTextFormattingDialog::GetDialogStyleDefinition(this);
166 m_nextStyle
->Freeze();
168 wxRichTextParagraphStyleDefinition
* paraDef
= wxDynamicCast(def
, wxRichTextParagraphStyleDefinition
);
169 wxRichTextListStyleDefinition
* listDef
= wxDynamicCast(def
, wxRichTextListStyleDefinition
);
170 wxRichTextCharacterStyleDefinition
* charDef
= wxDynamicCast(def
, wxRichTextCharacterStyleDefinition
);
171 wxRichTextStyleSheet
* sheet
= wxRichTextFormattingDialog::GetDialog(this)->GetStyleSheet();
172 wxRichTextBoxStyleDefinition
* boxDef
= wxDynamicCast(def
, wxRichTextBoxStyleDefinition
);
174 m_styleName
->SetValue(def
->GetName());
178 if (m_nextStyle
->GetCount() == 0)
183 for (i
= 0; i
< sheet
->GetListStyleCount(); i
++)
185 wxRichTextListStyleDefinition
* p
= wxDynamicCast(sheet
->GetListStyle(i
), wxRichTextListStyleDefinition
);
187 m_nextStyle
->Append(p
->GetName());
191 m_nextStyle
->SetValue(listDef
->GetNextStyle());
195 if (m_nextStyle
->GetCount() == 0)
200 for (i
= 0; i
< sheet
->GetParagraphStyleCount(); i
++)
202 wxRichTextParagraphStyleDefinition
* p
= wxDynamicCast(sheet
->GetParagraphStyle(i
), wxRichTextParagraphStyleDefinition
);
204 m_nextStyle
->Append(p
->GetName());
208 m_nextStyle
->SetValue(paraDef
->GetNextStyle());
211 if (m_basedOn
->GetCount() == 0)
218 for (i
= 0; i
< sheet
->GetListStyleCount(); i
++)
220 wxRichTextListStyleDefinition
* p
= wxDynamicCast(sheet
->GetListStyle(i
), wxRichTextListStyleDefinition
);
222 m_basedOn
->Append(p
->GetName());
228 for (i
= 0; i
< sheet
->GetParagraphStyleCount(); i
++)
230 wxRichTextParagraphStyleDefinition
* p
= wxDynamicCast(sheet
->GetParagraphStyle(i
), wxRichTextParagraphStyleDefinition
);
232 m_basedOn
->Append(p
->GetName());
238 for (i
= 0; i
< sheet
->GetBoxStyleCount(); i
++)
240 wxRichTextBoxStyleDefinition
* p
= wxDynamicCast(sheet
->GetBoxStyle(i
), wxRichTextBoxStyleDefinition
);
242 m_basedOn
->Append(p
->GetName());
248 for (i
= 0; i
< sheet
->GetCharacterStyleCount(); i
++)
250 wxRichTextCharacterStyleDefinition
* p
= wxDynamicCast(sheet
->GetCharacterStyle(i
), wxRichTextCharacterStyleDefinition
);
252 m_basedOn
->Append(p
->GetName());
258 m_basedOn
->SetValue(def
->GetBaseStyle());
267 wxRichTextAttr
* wxRichTextStylePage::GetAttributes()
269 return wxRichTextFormattingDialog::GetDialogAttributes(this);
273 * Should we show tooltips?
276 bool wxRichTextStylePage::ShowToolTips()
278 return wxRichTextFormattingDialog::ShowToolTips();
282 * Get bitmap resources
285 wxBitmap
wxRichTextStylePage::GetBitmapResource( const wxString
& name
)
288 ////@begin wxRichTextStylePage bitmap retrieval
291 ////@end wxRichTextStylePage bitmap retrieval
298 wxIcon
wxRichTextStylePage::GetIconResource( const wxString
& name
)
301 ////@begin wxRichTextStylePage icon retrieval
304 ////@end wxRichTextStylePage icon retrieval
307 * wxEVT_UPDATE_UI event handler for ID_RICHTEXTSTYLEPAGE_NEXT_STYLE
310 void wxRichTextStylePage::OnNextStyleUpdate( wxUpdateUIEvent
& event
)
312 wxRichTextStyleDefinition
* def
= wxRichTextFormattingDialog::GetDialogStyleDefinition(this);
313 event
.Enable(wxDynamicCast(def
, wxRichTextParagraphStyleDefinition
) != NULL
);
316 #endif // wxUSE_RICHTEXT