]>
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(); }
79 void OnButtonSetLabel(wxCommandEvent
& event
);
80 void OnButtonSetURL(wxCommandEvent
& event
);
82 void OnButtonReset(wxCommandEvent
& event
);
84 // reset the control parameters
87 // (re)create the hyperctrl
88 void CreateHyperlink();
93 // the checkbox itself and the sizer it is in
94 wxHyperlinkCtrl
*m_hyperlink
;
95 wxSizer
*m_sizerHyperlink
;
100 wxStaticText
*m_visit
;
103 // the text entries for command parameters
104 wxTextCtrl
*m_textLabel
;
107 DECLARE_EVENT_TABLE()
108 DECLARE_WIDGETS_PAGE(HyperlinkWidgetsPage
)
111 // ----------------------------------------------------------------------------
113 // ----------------------------------------------------------------------------
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
)
121 // ============================================================================
123 // ============================================================================
125 IMPLEMENT_WIDGETS_PAGE(HyperlinkWidgetsPage
, wxT("Hyperlink"),
129 HyperlinkWidgetsPage::HyperlinkWidgetsPage(WidgetsBookCtrl
*book
,
130 wxImageList
*imaglist
)
131 :WidgetsPage(book
, imaglist
, hyperlnk_xpm
)
133 wxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
136 wxStaticBox
*box
= new wxStaticBox(this, wxID_ANY
, wxT("Hyperlink details"));
138 wxSizer
*sizerLeft
= new wxStaticBoxSizer(box
, wxVERTICAL
);
140 sizerLeft
->Add( CreateSizerWithTextAndButton( HyperlinkPage_SetLabel
, wxT("Set &Label"), wxID_ANY
, &m_label
),
141 0, wxALL
| wxALIGN_RIGHT
, 5 );
143 sizerLeft
->Add( CreateSizerWithTextAndButton( HyperlinkPage_SetURL
, wxT("Set &URL"), wxID_ANY
, &m_url
),
144 0, wxALL
| wxALIGN_RIGHT
, 5 );
147 wxSizer
*sizerRight
= new wxBoxSizer(wxHORIZONTAL
);
149 m_visit
= new wxStaticText(this, wxID_ANY
, wxT("Visit "));
151 m_hyperlink
= new wxHyperlinkCtrl(this,
153 wxT("wxWidgets website"),
154 wxT("www.wxwidgets.org"));
156 m_fun
= new wxStaticText(this, wxID_ANY
, wxT(" for fun!"));
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
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);
170 // final initializations
178 void HyperlinkWidgetsPage::Reset()
180 m_label
->SetValue(m_hyperlink
->GetLabel());
181 m_url
->SetValue(m_hyperlink
->GetURL());
184 void HyperlinkWidgetsPage::CreateHyperlink()
186 const wxString label
= m_hyperlink
->GetLabel();
187 const wxString url
= m_hyperlink
->GetURL();
189 size_t count
= m_sizerHyperlink
->GetChildren().GetCount();
190 for ( size_t n
= 0; n
< count
; n
++ )
192 m_sizerHyperlink
->Remove(0);
197 m_hyperlink
= new wxHyperlinkCtrl(this,
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();
210 // ----------------------------------------------------------------------------
212 // ----------------------------------------------------------------------------
214 void HyperlinkWidgetsPage::OnButtonReset(wxCommandEvent
& WXUNUSED(event
))
221 void HyperlinkWidgetsPage::OnButtonSetLabel(wxCommandEvent
& WXUNUSED(event
))
223 m_hyperlink
->SetLabel(m_label
->GetValue());
227 void HyperlinkWidgetsPage::OnButtonSetURL(wxCommandEvent
& WXUNUSED(event
))
229 m_hyperlink
->SetURL(m_url
->GetValue());
233 #endif // wxUSE_HYPERLINKCTRL