2006-05-30 07:55:24 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Program: wxWidgets Widgets Sample
|
|
|
|
// Name: hyperlnk.cpp
|
|
|
|
// Purpose: Part of the widgets sample showing wxHyperlinkCtrl
|
|
|
|
// Author: Dimitri Schoolwerth, Vadim Zeitlin
|
|
|
|
// Created: 27 Sep 2003
|
|
|
|
// Copyright: (c) 2003 wxWindows team
|
2010-07-13 09:29:13 -04:00
|
|
|
// Licence: wxWindows licence
|
2006-05-30 07:55:24 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// declarations
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// for compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if wxUSE_HYPERLINKCTRL
|
|
|
|
|
|
|
|
// for all others, include the necessary headers
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/app.h"
|
|
|
|
#include "wx/log.h"
|
|
|
|
|
|
|
|
#include "wx/bitmap.h"
|
|
|
|
#include "wx/button.h"
|
|
|
|
#include "wx/checkbox.h"
|
|
|
|
#include "wx/radiobox.h"
|
|
|
|
#include "wx/statbox.h"
|
|
|
|
#include "wx/stattext.h"
|
|
|
|
#include "wx/textctrl.h"
|
|
|
|
|
|
|
|
#include "wx/sizer.h"
|
|
|
|
#endif
|
|
|
|
|
2006-06-01 18:15:07 -04:00
|
|
|
#include "wx/hyperlink.h"
|
2006-05-30 07:55:24 -04:00
|
|
|
|
|
|
|
#include "widgets.h"
|
|
|
|
|
|
|
|
#include "icons/hyperlnk.xpm"
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// control ids
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
HyperlinkPage_Reset = wxID_HIGHEST,
|
|
|
|
HyperlinkPage_SetLabel,
|
|
|
|
HyperlinkPage_SetURL,
|
|
|
|
HyperlinkPage_Ctrl
|
|
|
|
};
|
|
|
|
|
2006-09-10 19:57:26 -04:00
|
|
|
// alignment radiobox indices
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
Align_Left,
|
|
|
|
Align_Centre,
|
|
|
|
Align_Right,
|
|
|
|
Align_Max
|
|
|
|
};
|
|
|
|
|
2006-05-30 07:55:24 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// CheckBoxWidgetsPage
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class HyperlinkWidgetsPage : public WidgetsPage
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
HyperlinkWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist);
|
2006-06-06 10:10:06 -04:00
|
|
|
virtual ~HyperlinkWidgetsPage() {}
|
2006-05-30 07:55:24 -04:00
|
|
|
|
|
|
|
virtual wxControl *GetWidget() const { return m_hyperlink; }
|
|
|
|
virtual void RecreateWidget() { CreateHyperlink(); }
|
|
|
|
|
2006-06-06 10:10:06 -04:00
|
|
|
// lazy creation of the content
|
|
|
|
virtual void CreateContent();
|
|
|
|
|
2006-05-30 07:55:24 -04:00
|
|
|
protected:
|
|
|
|
// event handlers
|
|
|
|
void OnButtonSetLabel(wxCommandEvent& event);
|
|
|
|
void OnButtonSetURL(wxCommandEvent& event);
|
|
|
|
|
|
|
|
void OnButtonReset(wxCommandEvent& event);
|
2006-09-10 19:57:26 -04:00
|
|
|
void OnAlignment(wxCommandEvent& event);
|
2011-06-15 17:56:23 -04:00
|
|
|
void OnGeneric(wxCommandEvent& event);
|
2006-05-30 07:55:24 -04:00
|
|
|
|
|
|
|
// reset the control parameters
|
|
|
|
void Reset();
|
|
|
|
|
|
|
|
// (re)create the hyperctrl
|
|
|
|
void CreateHyperlink();
|
2006-09-10 19:57:26 -04:00
|
|
|
void CreateHyperlinkLong(long);
|
2006-05-30 07:55:24 -04:00
|
|
|
|
|
|
|
// the controls
|
|
|
|
// ------------
|
|
|
|
|
|
|
|
// the checkbox itself and the sizer it is in
|
2011-06-15 17:56:23 -04:00
|
|
|
wxGenericHyperlinkCtrl *m_hyperlink;
|
|
|
|
wxGenericHyperlinkCtrl *m_hyperlinkLong;
|
2006-05-30 07:55:24 -04:00
|
|
|
|
|
|
|
wxTextCtrl *m_label;
|
|
|
|
wxTextCtrl *m_url;
|
|
|
|
|
|
|
|
wxStaticText *m_visit;
|
|
|
|
wxStaticText *m_fun;
|
|
|
|
|
|
|
|
// the text entries for command parameters
|
|
|
|
wxTextCtrl *m_textLabel;
|
|
|
|
|
2006-09-10 19:57:26 -04:00
|
|
|
wxRadioBox *m_radioAlignMode;
|
2011-06-15 17:56:23 -04:00
|
|
|
wxCheckBox *m_checkGeneric;
|
2006-09-10 19:57:26 -04:00
|
|
|
|
2006-05-30 07:55:24 -04:00
|
|
|
private:
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
DECLARE_WIDGETS_PAGE(HyperlinkWidgetsPage)
|
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// event tables
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(HyperlinkWidgetsPage, WidgetsPage)
|
|
|
|
EVT_BUTTON(HyperlinkPage_Reset, HyperlinkWidgetsPage::OnButtonReset)
|
|
|
|
EVT_BUTTON(HyperlinkPage_SetLabel, HyperlinkWidgetsPage::OnButtonSetLabel)
|
|
|
|
EVT_BUTTON(HyperlinkPage_SetURL, HyperlinkWidgetsPage::OnButtonSetURL)
|
2006-09-10 19:57:26 -04:00
|
|
|
|
|
|
|
EVT_RADIOBOX(wxID_ANY, HyperlinkWidgetsPage::OnAlignment)
|
2011-06-15 17:56:23 -04:00
|
|
|
EVT_CHECKBOX(wxID_ANY, HyperlinkWidgetsPage::OnGeneric)
|
2006-05-30 07:55:24 -04:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// implementation
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
IMPLEMENT_WIDGETS_PAGE(HyperlinkWidgetsPage, wxT("Hyperlink"),
|
|
|
|
GENERIC_CTRLS
|
|
|
|
);
|
|
|
|
|
|
|
|
HyperlinkWidgetsPage::HyperlinkWidgetsPage(WidgetsBookCtrl *book,
|
|
|
|
wxImageList *imaglist)
|
2006-06-06 10:10:06 -04:00
|
|
|
:WidgetsPage(book, imaglist, hyperlnk_xpm)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void HyperlinkWidgetsPage::CreateContent()
|
2006-05-30 07:55:24 -04:00
|
|
|
{
|
|
|
|
wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
|
|
|
|
// left pane
|
|
|
|
wxStaticBox *box = new wxStaticBox(this, wxID_ANY, wxT("Hyperlink details"));
|
|
|
|
|
|
|
|
wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
|
|
|
|
|
|
|
|
sizerLeft->Add( CreateSizerWithTextAndButton( HyperlinkPage_SetLabel , wxT("Set &Label"), wxID_ANY, &m_label ),
|
|
|
|
0, wxALL | wxALIGN_RIGHT , 5 );
|
|
|
|
|
|
|
|
sizerLeft->Add( CreateSizerWithTextAndButton( HyperlinkPage_SetURL , wxT("Set &URL"), wxID_ANY, &m_url ),
|
|
|
|
0, wxALL | wxALIGN_RIGHT , 5 );
|
|
|
|
|
2006-09-10 19:57:26 -04:00
|
|
|
static const wxString alignments[] =
|
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
wxT("&left"),
|
|
|
|
wxT("¢re"),
|
|
|
|
wxT("&right")
|
2006-09-10 19:57:26 -04:00
|
|
|
};
|
|
|
|
wxCOMPILE_TIME_ASSERT( WXSIZEOF(alignments) == Align_Max,
|
|
|
|
AlignMismatch );
|
|
|
|
|
2009-07-23 16:30:22 -04:00
|
|
|
m_radioAlignMode = new wxRadioBox(this, wxID_ANY, wxT("alignment"),
|
2006-09-10 19:57:26 -04:00
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
WXSIZEOF(alignments), alignments);
|
|
|
|
m_radioAlignMode->SetSelection(1); // start with "centre" selected since
|
|
|
|
// wxHL_DEFAULT_STYLE contains wxHL_ALIGN_CENTRE
|
|
|
|
sizerLeft->Add(m_radioAlignMode, 0, wxALL|wxGROW, 5);
|
|
|
|
|
2011-06-15 17:56:23 -04:00
|
|
|
m_checkGeneric = new wxCheckBox(this, wxID_ANY, wxT("Use generic version"),
|
|
|
|
wxDefaultPosition, wxDefaultSize);
|
|
|
|
sizerLeft->Add(m_checkGeneric, 0, wxALL|wxGROW, 5);
|
2006-09-10 19:57:26 -04:00
|
|
|
|
2006-05-30 07:55:24 -04:00
|
|
|
// right pane
|
2006-09-10 19:57:26 -04:00
|
|
|
wxSizer *szHyperlinkLong = new wxBoxSizer(wxVERTICAL);
|
|
|
|
wxSizer *szHyperlink = new wxBoxSizer(wxHORIZONTAL);
|
2006-05-30 07:55:24 -04:00
|
|
|
|
|
|
|
m_visit = new wxStaticText(this, wxID_ANY, wxT("Visit "));
|
|
|
|
|
2011-06-15 17:56:23 -04:00
|
|
|
if (m_checkGeneric->IsChecked())
|
|
|
|
{
|
|
|
|
m_hyperlink = new wxGenericHyperlinkCtrl(this,
|
|
|
|
HyperlinkPage_Ctrl,
|
|
|
|
wxT("wxWidgets website"),
|
|
|
|
wxT("www.wxwidgets.org"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_hyperlink = new wxHyperlinkCtrl(this,
|
|
|
|
HyperlinkPage_Ctrl,
|
|
|
|
wxT("wxWidgets website"),
|
|
|
|
wxT("www.wxwidgets.org"));
|
|
|
|
}
|
2006-05-30 07:55:24 -04:00
|
|
|
|
|
|
|
m_fun = new wxStaticText(this, wxID_ANY, wxT(" for fun!"));
|
|
|
|
|
2006-09-10 19:57:26 -04:00
|
|
|
szHyperlink->Add(0, 0, 1, wxCENTRE);
|
|
|
|
szHyperlink->Add(m_visit, 0, wxCENTRE);
|
|
|
|
szHyperlink->Add(m_hyperlink, 0, wxCENTRE);
|
|
|
|
szHyperlink->Add(m_fun, 0, wxCENTRE);
|
|
|
|
szHyperlink->Add(0, 0, 1, wxCENTRE);
|
|
|
|
szHyperlink->SetMinSize(150, 0);
|
|
|
|
|
2011-06-15 17:56:23 -04:00
|
|
|
if (m_checkGeneric->IsChecked())
|
|
|
|
{
|
|
|
|
m_hyperlinkLong = new wxGenericHyperlinkCtrl(this,
|
|
|
|
wxID_ANY,
|
|
|
|
wxT("This is a long hyperlink"),
|
|
|
|
wxT("www.wxwidgets.org"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_hyperlinkLong = new wxHyperlinkCtrl(this,
|
|
|
|
wxID_ANY,
|
|
|
|
wxT("This is a long hyperlink"),
|
|
|
|
wxT("www.wxwidgets.org"));
|
|
|
|
}
|
2006-09-10 19:57:26 -04:00
|
|
|
|
|
|
|
szHyperlinkLong->Add(0, 0, 1, wxCENTRE);
|
|
|
|
szHyperlinkLong->Add(szHyperlink, 0, wxCENTRE|wxGROW);
|
|
|
|
szHyperlinkLong->Add(0, 0, 1, wxCENTRE);
|
|
|
|
szHyperlinkLong->Add(m_hyperlinkLong, 0, wxGROW);
|
|
|
|
szHyperlinkLong->Add(0, 0, 1, wxCENTRE);
|
|
|
|
|
2006-05-30 07:55:24 -04:00
|
|
|
|
|
|
|
// the 3 panes panes compose the window
|
|
|
|
sizerTop->Add(sizerLeft, 0, (wxALL & ~wxLEFT), 10);
|
2006-09-10 19:57:26 -04:00
|
|
|
sizerTop->Add(szHyperlinkLong, 1, wxGROW | (wxALL & ~wxRIGHT), 10);
|
2006-05-30 07:55:24 -04:00
|
|
|
|
|
|
|
// final initializations
|
|
|
|
Reset();
|
|
|
|
|
|
|
|
SetSizer(sizerTop);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HyperlinkWidgetsPage::Reset()
|
|
|
|
{
|
|
|
|
m_label->SetValue(m_hyperlink->GetLabel());
|
|
|
|
m_url->SetValue(m_hyperlink->GetURL());
|
|
|
|
}
|
|
|
|
|
|
|
|
void HyperlinkWidgetsPage::CreateHyperlink()
|
|
|
|
{
|
|
|
|
const wxString label = m_hyperlink->GetLabel();
|
|
|
|
const wxString url = m_hyperlink->GetURL();
|
|
|
|
|
2011-06-15 17:56:23 -04:00
|
|
|
wxGenericHyperlinkCtrl *hyp;
|
|
|
|
if (m_checkGeneric->IsChecked())
|
|
|
|
{
|
|
|
|
hyp = new wxGenericHyperlinkCtrl(this,
|
|
|
|
HyperlinkPage_Ctrl,
|
|
|
|
label,
|
|
|
|
url);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hyp = new wxHyperlinkCtrl(this,
|
|
|
|
HyperlinkPage_Ctrl,
|
|
|
|
label,
|
|
|
|
url);
|
|
|
|
}
|
2006-05-30 07:55:24 -04:00
|
|
|
|
2006-09-10 19:57:26 -04:00
|
|
|
// update sizer's child window
|
|
|
|
GetSizer()->Replace(m_hyperlink, hyp, true);
|
|
|
|
|
|
|
|
// update our pointer
|
2006-05-30 07:55:24 -04:00
|
|
|
delete m_hyperlink;
|
2006-09-10 19:57:26 -04:00
|
|
|
m_hyperlink = hyp;
|
2006-05-30 07:55:24 -04:00
|
|
|
|
2006-09-10 19:57:26 -04:00
|
|
|
// relayout the sizer
|
|
|
|
GetSizer()->Layout();
|
|
|
|
}
|
|
|
|
|
|
|
|
void HyperlinkWidgetsPage::CreateHyperlinkLong(long style)
|
|
|
|
{
|
|
|
|
style = (wxHL_DEFAULT_STYLE & ~wxHL_ALIGN_CENTRE)|style;
|
2011-06-15 17:56:23 -04:00
|
|
|
|
|
|
|
wxGenericHyperlinkCtrl *hyp;
|
|
|
|
if (m_checkGeneric->IsChecked())
|
|
|
|
{
|
|
|
|
hyp = new wxGenericHyperlinkCtrl(this,
|
|
|
|
wxID_ANY,
|
|
|
|
wxT("This is a long hyperlink"),
|
|
|
|
wxT("www.wxwidgets.org"),
|
|
|
|
wxDefaultPosition,
|
|
|
|
wxDefaultSize,
|
|
|
|
style);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hyp = new wxHyperlinkCtrl(this,
|
|
|
|
wxID_ANY,
|
|
|
|
wxT("This is a long hyperlink"),
|
|
|
|
wxT("www.wxwidgets.org"),
|
|
|
|
wxDefaultPosition,
|
|
|
|
wxDefaultSize,
|
|
|
|
style);
|
|
|
|
}
|
2006-09-10 19:57:26 -04:00
|
|
|
|
|
|
|
// update sizer's child window
|
|
|
|
GetSizer()->Replace(m_hyperlinkLong, hyp, true);
|
|
|
|
|
|
|
|
// update our pointer
|
|
|
|
delete m_hyperlinkLong;
|
|
|
|
m_hyperlinkLong = hyp;
|
|
|
|
|
|
|
|
// relayout the sizer
|
|
|
|
GetSizer()->Layout();
|
2006-05-30 07:55:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// event handlers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void HyperlinkWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
|
|
|
|
CreateHyperlink();
|
|
|
|
}
|
|
|
|
|
|
|
|
void HyperlinkWidgetsPage::OnButtonSetLabel(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
m_hyperlink->SetLabel(m_label->GetValue());
|
|
|
|
CreateHyperlink();
|
|
|
|
}
|
|
|
|
|
|
|
|
void HyperlinkWidgetsPage::OnButtonSetURL(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
m_hyperlink->SetURL(m_url->GetValue());
|
|
|
|
CreateHyperlink();
|
|
|
|
}
|
|
|
|
|
2006-09-10 19:57:26 -04:00
|
|
|
void HyperlinkWidgetsPage::OnAlignment(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
long addstyle;
|
|
|
|
switch ( m_radioAlignMode->GetSelection() )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case Align_Max:
|
2009-07-23 16:30:22 -04:00
|
|
|
wxFAIL_MSG( wxT("unknown alignment") );
|
2006-09-10 19:57:26 -04:00
|
|
|
// fall through
|
|
|
|
|
|
|
|
case Align_Left:
|
|
|
|
addstyle = wxHL_ALIGN_LEFT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Align_Centre:
|
|
|
|
addstyle = wxHL_ALIGN_CENTRE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Align_Right:
|
|
|
|
addstyle = wxHL_ALIGN_RIGHT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
CreateHyperlinkLong(addstyle);
|
|
|
|
}
|
|
|
|
|
2011-06-15 17:56:23 -04:00
|
|
|
void HyperlinkWidgetsPage::OnGeneric(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
CreateHyperlink();
|
|
|
|
OnAlignment(event);
|
|
|
|
}
|
|
|
|
|
2006-05-30 07:55:24 -04:00
|
|
|
#endif // wxUSE_HYPERLINKCTRL
|