]>
Commit | Line | Data |
---|---|---|
f9300d42 WS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Program: wxWidgets Widgets Sample | |
3 | // Name: hyperlnk.cpp | |
4 | // Purpose: Part of the widgets sample showing wxHyperlinkCtrl | |
5 | // Author: Dimitri Schoolwerth, Vadim Zeitlin | |
6 | // Created: 27 Sep 2003 | |
7 | // Id: $Id$ | |
8 | // Copyright: (c) 2003 wxWindows team | |
9 | // License: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | // for compilers that support precompilation, includes "wx/wx.h". | |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
27 | #if wxUSE_HYPERLINKCTRL | |
28 | ||
29 | // for all others, include the necessary headers | |
30 | #ifndef WX_PRECOMP | |
31 | #include "wx/app.h" | |
32 | #include "wx/log.h" | |
33 | ||
34 | #include "wx/bitmap.h" | |
35 | #include "wx/button.h" | |
36 | #include "wx/checkbox.h" | |
37 | #include "wx/radiobox.h" | |
38 | #include "wx/statbox.h" | |
39 | #include "wx/stattext.h" | |
40 | #include "wx/textctrl.h" | |
41 | ||
42 | #include "wx/sizer.h" | |
43 | #endif | |
44 | ||
38ffe8cd | 45 | #include "wx/hyperlink.h" |
f9300d42 WS |
46 | |
47 | #include "widgets.h" | |
48 | ||
49 | #include "icons/hyperlnk.xpm" | |
50 | ||
51 | // ---------------------------------------------------------------------------- | |
52 | // constants | |
53 | // ---------------------------------------------------------------------------- | |
54 | ||
55 | // control ids | |
56 | enum | |
57 | { | |
58 | HyperlinkPage_Reset = wxID_HIGHEST, | |
59 | HyperlinkPage_SetLabel, | |
60 | HyperlinkPage_SetURL, | |
61 | HyperlinkPage_Ctrl | |
62 | }; | |
63 | ||
64 | // ---------------------------------------------------------------------------- | |
65 | // CheckBoxWidgetsPage | |
66 | // ---------------------------------------------------------------------------- | |
67 | ||
68 | class HyperlinkWidgetsPage : public WidgetsPage | |
69 | { | |
70 | public: | |
71 | HyperlinkWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist); | |
72 | virtual ~HyperlinkWidgetsPage(){}; | |
73 | ||
74 | virtual wxControl *GetWidget() const { return m_hyperlink; } | |
75 | virtual void RecreateWidget() { CreateHyperlink(); } | |
76 | ||
77 | protected: | |
78 | // event handlers | |
79 | void OnButtonSetLabel(wxCommandEvent& event); | |
80 | void OnButtonSetURL(wxCommandEvent& event); | |
81 | ||
82 | void OnButtonReset(wxCommandEvent& event); | |
83 | ||
84 | // reset the control parameters | |
85 | void Reset(); | |
86 | ||
87 | // (re)create the hyperctrl | |
88 | void CreateHyperlink(); | |
89 | ||
90 | // the controls | |
91 | // ------------ | |
92 | ||
93 | // the checkbox itself and the sizer it is in | |
94 | wxHyperlinkCtrl *m_hyperlink; | |
95 | wxSizer *m_sizerHyperlink; | |
96 | ||
97 | wxTextCtrl *m_label; | |
98 | wxTextCtrl *m_url; | |
99 | ||
100 | wxStaticText *m_visit; | |
101 | wxStaticText *m_fun; | |
102 | ||
103 | // the text entries for command parameters | |
104 | wxTextCtrl *m_textLabel; | |
105 | ||
106 | private: | |
107 | DECLARE_EVENT_TABLE() | |
108 | DECLARE_WIDGETS_PAGE(HyperlinkWidgetsPage) | |
109 | }; | |
110 | ||
111 | // ---------------------------------------------------------------------------- | |
112 | // event tables | |
113 | // ---------------------------------------------------------------------------- | |
114 | ||
115 | BEGIN_EVENT_TABLE(HyperlinkWidgetsPage, WidgetsPage) | |
116 | EVT_BUTTON(HyperlinkPage_Reset, HyperlinkWidgetsPage::OnButtonReset) | |
117 | EVT_BUTTON(HyperlinkPage_SetLabel, HyperlinkWidgetsPage::OnButtonSetLabel) | |
118 | EVT_BUTTON(HyperlinkPage_SetURL, HyperlinkWidgetsPage::OnButtonSetURL) | |
119 | END_EVENT_TABLE() | |
120 | ||
121 | // ============================================================================ | |
122 | // implementation | |
123 | // ============================================================================ | |
124 | ||
125 | IMPLEMENT_WIDGETS_PAGE(HyperlinkWidgetsPage, wxT("Hyperlink"), | |
126 | GENERIC_CTRLS | |
127 | ); | |
128 | ||
129 | HyperlinkWidgetsPage::HyperlinkWidgetsPage(WidgetsBookCtrl *book, | |
130 | wxImageList *imaglist) | |
131 | :WidgetsPage(book, imaglist, hyperlnk_xpm) | |
132 | { | |
133 | wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); | |
134 | ||
135 | // left pane | |
136 | wxStaticBox *box = new wxStaticBox(this, wxID_ANY, wxT("Hyperlink details")); | |
137 | ||
138 | wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL); | |
139 | ||
140 | sizerLeft->Add( CreateSizerWithTextAndButton( HyperlinkPage_SetLabel , wxT("Set &Label"), wxID_ANY, &m_label ), | |
141 | 0, wxALL | wxALIGN_RIGHT , 5 ); | |
142 | ||
143 | sizerLeft->Add( CreateSizerWithTextAndButton( HyperlinkPage_SetURL , wxT("Set &URL"), wxID_ANY, &m_url ), | |
144 | 0, wxALL | wxALIGN_RIGHT , 5 ); | |
145 | ||
146 | // right pane | |
147 | wxSizer *sizerRight = new wxBoxSizer(wxHORIZONTAL); | |
148 | ||
149 | m_visit = new wxStaticText(this, wxID_ANY, wxT("Visit ")); | |
150 | ||
151 | m_hyperlink = new wxHyperlinkCtrl(this, | |
152 | HyperlinkPage_Ctrl, | |
153 | wxT("wxWidgets website"), | |
154 | wxT("www.wxwidgets.org")); | |
155 | ||
156 | m_fun = new wxStaticText(this, wxID_ANY, wxT(" for fun!")); | |
157 | ||
158 | sizerRight->Add(0, 0, 1, wxCENTRE); | |
159 | sizerRight->Add(m_visit, 0, wxCENTRE); | |
160 | sizerRight->Add(m_hyperlink, 0, wxCENTRE); | |
161 | sizerRight->Add(m_fun, 0, wxCENTRE); | |
162 | sizerRight->Add(0, 0, 1, wxCENTRE); | |
163 | sizerRight->SetMinSize(150, 0); | |
164 | m_sizerHyperlink = sizerRight; // save it to modify it later | |
165 | ||
166 | // the 3 panes panes compose the window | |
167 | sizerTop->Add(sizerLeft, 0, (wxALL & ~wxLEFT), 10); | |
168 | sizerTop->Add(sizerRight, 1, wxGROW | (wxALL & ~wxRIGHT), 10); | |
169 | ||
170 | // final initializations | |
171 | Reset(); | |
172 | ||
173 | SetSizer(sizerTop); | |
174 | ||
175 | sizerTop->Fit(this); | |
176 | } | |
177 | ||
178 | void HyperlinkWidgetsPage::Reset() | |
179 | { | |
180 | m_label->SetValue(m_hyperlink->GetLabel()); | |
181 | m_url->SetValue(m_hyperlink->GetURL()); | |
182 | } | |
183 | ||
184 | void HyperlinkWidgetsPage::CreateHyperlink() | |
185 | { | |
186 | const wxString label = m_hyperlink->GetLabel(); | |
187 | const wxString url = m_hyperlink->GetURL(); | |
188 | ||
189 | size_t count = m_sizerHyperlink->GetChildren().GetCount(); | |
190 | for ( size_t n = 0; n < count; n++ ) | |
191 | { | |
192 | m_sizerHyperlink->Remove(0); | |
193 | } | |
194 | ||
195 | delete m_hyperlink; | |
196 | ||
197 | m_hyperlink = new wxHyperlinkCtrl(this, | |
198 | HyperlinkPage_Ctrl, | |
199 | label, | |
200 | url); | |
201 | ||
202 | m_sizerHyperlink->Add(0, 0, 1, wxCENTRE); | |
203 | m_sizerHyperlink->Add(m_visit, 0, wxCENTRE); | |
204 | m_sizerHyperlink->Add(m_hyperlink, 0, wxCENTRE); | |
205 | m_sizerHyperlink->Add(m_fun, 0, wxCENTRE); | |
206 | m_sizerHyperlink->Add(0, 0, 1, wxCENTRE); | |
207 | m_sizerHyperlink->Layout(); | |
208 | } | |
209 | ||
210 | // ---------------------------------------------------------------------------- | |
211 | // event handlers | |
212 | // ---------------------------------------------------------------------------- | |
213 | ||
214 | void HyperlinkWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event)) | |
215 | { | |
216 | Reset(); | |
217 | ||
218 | CreateHyperlink(); | |
219 | } | |
220 | ||
221 | void HyperlinkWidgetsPage::OnButtonSetLabel(wxCommandEvent& WXUNUSED(event)) | |
222 | { | |
223 | m_hyperlink->SetLabel(m_label->GetValue()); | |
224 | CreateHyperlink(); | |
225 | } | |
226 | ||
227 | void HyperlinkWidgetsPage::OnButtonSetURL(wxCommandEvent& WXUNUSED(event)) | |
228 | { | |
229 | m_hyperlink->SetURL(m_url->GetValue()); | |
230 | CreateHyperlink(); | |
231 | } | |
232 | ||
233 | #endif // wxUSE_HYPERLINKCTRL |