]>
git.saurik.com Git - wxWidgets.git/blob - samples/widgets/hyperlnk.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Program: wxWidgets Widgets Sample
4 // Purpose: Part of the widgets sample showing wxHyperlinkCtrl
5 // Author: Dimitri Schoolwerth, Vadim Zeitlin
6 // Created: 27 Sep 2003
8 // Copyright: (c) 2003 wxWindows team
9 // License: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // for compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
27 #if wxUSE_HYPERLINKCTRL
29 // for all others, include the necessary headers
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"
45 #include "wx/hyperlink.h"
49 #include "icons/hyperlnk.xpm"
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
58 HyperlinkPage_Reset
= wxID_HIGHEST
,
59 HyperlinkPage_SetLabel
,
64 // ----------------------------------------------------------------------------
65 // CheckBoxWidgetsPage
66 // ----------------------------------------------------------------------------
68 class HyperlinkWidgetsPage
: public WidgetsPage
71 HyperlinkWidgetsPage(WidgetsBookCtrl
*book
, wxImageList
*imaglist
);
72 virtual ~HyperlinkWidgetsPage() {}
74 virtual wxControl
*GetWidget() const { return m_hyperlink
; }
75 virtual void RecreateWidget() { CreateHyperlink(); }
77 // lazy creation of the content
78 virtual void CreateContent();
82 void OnButtonSetLabel(wxCommandEvent
& event
);
83 void OnButtonSetURL(wxCommandEvent
& event
);
85 void OnButtonReset(wxCommandEvent
& event
);
87 // reset the control parameters
90 // (re)create the hyperctrl
91 void CreateHyperlink();
96 // the checkbox itself and the sizer it is in
97 wxHyperlinkCtrl
*m_hyperlink
;
98 wxSizer
*m_sizerHyperlink
;
103 wxStaticText
*m_visit
;
106 // the text entries for command parameters
107 wxTextCtrl
*m_textLabel
;
110 DECLARE_EVENT_TABLE()
111 DECLARE_WIDGETS_PAGE(HyperlinkWidgetsPage
)
114 // ----------------------------------------------------------------------------
116 // ----------------------------------------------------------------------------
118 BEGIN_EVENT_TABLE(HyperlinkWidgetsPage
, WidgetsPage
)
119 EVT_BUTTON(HyperlinkPage_Reset
, HyperlinkWidgetsPage::OnButtonReset
)
120 EVT_BUTTON(HyperlinkPage_SetLabel
, HyperlinkWidgetsPage::OnButtonSetLabel
)
121 EVT_BUTTON(HyperlinkPage_SetURL
, HyperlinkWidgetsPage::OnButtonSetURL
)
124 // ============================================================================
126 // ============================================================================
128 IMPLEMENT_WIDGETS_PAGE(HyperlinkWidgetsPage
, wxT("Hyperlink"),
132 HyperlinkWidgetsPage::HyperlinkWidgetsPage(WidgetsBookCtrl
*book
,
133 wxImageList
*imaglist
)
134 :WidgetsPage(book
, imaglist
, hyperlnk_xpm
)
138 void HyperlinkWidgetsPage::CreateContent()
140 wxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
143 wxStaticBox
*box
= new wxStaticBox(this, wxID_ANY
, wxT("Hyperlink details"));
145 wxSizer
*sizerLeft
= new wxStaticBoxSizer(box
, wxVERTICAL
);
147 sizerLeft
->Add( CreateSizerWithTextAndButton( HyperlinkPage_SetLabel
, wxT("Set &Label"), wxID_ANY
, &m_label
),
148 0, wxALL
| wxALIGN_RIGHT
, 5 );
150 sizerLeft
->Add( CreateSizerWithTextAndButton( HyperlinkPage_SetURL
, wxT("Set &URL"), wxID_ANY
, &m_url
),
151 0, wxALL
| wxALIGN_RIGHT
, 5 );
154 wxSizer
*sizerRight
= new wxBoxSizer(wxHORIZONTAL
);
156 m_visit
= new wxStaticText(this, wxID_ANY
, wxT("Visit "));
158 m_hyperlink
= new wxHyperlinkCtrl(this,
160 wxT("wxWidgets website"),
161 wxT("www.wxwidgets.org"));
163 m_fun
= new wxStaticText(this, wxID_ANY
, wxT(" for fun!"));
165 sizerRight
->Add(0, 0, 1, wxCENTRE
);
166 sizerRight
->Add(m_visit
, 0, wxCENTRE
);
167 sizerRight
->Add(m_hyperlink
, 0, wxCENTRE
);
168 sizerRight
->Add(m_fun
, 0, wxCENTRE
);
169 sizerRight
->Add(0, 0, 1, wxCENTRE
);
170 sizerRight
->SetMinSize(150, 0);
171 m_sizerHyperlink
= sizerRight
; // save it to modify it later
173 // the 3 panes panes compose the window
174 sizerTop
->Add(sizerLeft
, 0, (wxALL
& ~wxLEFT
), 10);
175 sizerTop
->Add(sizerRight
, 1, wxGROW
| (wxALL
& ~wxRIGHT
), 10);
177 // final initializations
185 void HyperlinkWidgetsPage::Reset()
187 m_label
->SetValue(m_hyperlink
->GetLabel());
188 m_url
->SetValue(m_hyperlink
->GetURL());
191 void HyperlinkWidgetsPage::CreateHyperlink()
193 const wxString label
= m_hyperlink
->GetLabel();
194 const wxString url
= m_hyperlink
->GetURL();
196 size_t count
= m_sizerHyperlink
->GetChildren().GetCount();
197 for ( size_t n
= 0; n
< count
; n
++ )
199 m_sizerHyperlink
->Remove(0);
204 m_hyperlink
= new wxHyperlinkCtrl(this,
209 m_sizerHyperlink
->Add(0, 0, 1, wxCENTRE
);
210 m_sizerHyperlink
->Add(m_visit
, 0, wxCENTRE
);
211 m_sizerHyperlink
->Add(m_hyperlink
, 0, wxCENTRE
);
212 m_sizerHyperlink
->Add(m_fun
, 0, wxCENTRE
);
213 m_sizerHyperlink
->Add(0, 0, 1, wxCENTRE
);
214 m_sizerHyperlink
->Layout();
217 // ----------------------------------------------------------------------------
219 // ----------------------------------------------------------------------------
221 void HyperlinkWidgetsPage::OnButtonReset(wxCommandEvent
& WXUNUSED(event
))
228 void HyperlinkWidgetsPage::OnButtonSetLabel(wxCommandEvent
& WXUNUSED(event
))
230 m_hyperlink
->SetLabel(m_label
->GetValue());
234 void HyperlinkWidgetsPage::OnButtonSetURL(wxCommandEvent
& WXUNUSED(event
))
236 m_hyperlink
->SetURL(m_url
->GetValue());
240 #endif // wxUSE_HYPERLINKCTRL