]>
git.saurik.com Git - wxWidgets.git/blob - src/common/hyperlnkcmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/hyperlnkcmn.cpp
3 // Purpose: Hyperlink control
4 // Author: David Norris <danorris@gmail.com>, Otto Wyss
5 // Modified by: Ryan Norton, Francesco Montorsi
8 // Copyright: (c) 2005 David Norris
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 //---------------------------------------------------------------------------
17 // Pre-compiled header stuff
18 //---------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #if wxUSE_HYPERLINKCTRL
29 //---------------------------------------------------------------------------
31 //---------------------------------------------------------------------------
33 #include "wx/hyperlink.h"
38 #include "wx/dataobj.h"
41 // ============================================================================
43 // ============================================================================
45 wxDEFINE_FLAGS( wxHyperlinkStyle
)
46 wxBEGIN_FLAGS( wxHyperlinkStyle
)
47 // new style border flags, we put them first to
48 // use them for streaming out
49 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
50 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
51 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
52 wxFLAGS_MEMBER(wxBORDER_RAISED
)
53 wxFLAGS_MEMBER(wxBORDER_STATIC
)
54 wxFLAGS_MEMBER(wxBORDER_NONE
)
56 // old style border flags
57 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
58 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
59 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
60 wxFLAGS_MEMBER(wxRAISED_BORDER
)
61 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
62 wxFLAGS_MEMBER(wxBORDER
)
64 // standard window styles
65 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
66 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
67 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
68 wxFLAGS_MEMBER(wxWANTS_CHARS
)
69 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
70 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
71 wxFLAGS_MEMBER(wxVSCROLL
)
72 wxFLAGS_MEMBER(wxHSCROLL
)
74 wxFLAGS_MEMBER(wxHL_CONTEXTMENU
)
75 wxFLAGS_MEMBER(wxHL_ALIGN_LEFT
)
76 wxFLAGS_MEMBER(wxHL_ALIGN_RIGHT
)
77 wxFLAGS_MEMBER(wxHL_ALIGN_CENTRE
)
78 wxEND_FLAGS( wxHyperlinkStyle
)
80 wxIMPLEMENT_DYNAMIC_CLASS_XTI( wxHyperlinkCtrl
, wxControl
, "wx/hyperlink.h")
82 IMPLEMENT_DYNAMIC_CLASS(wxHyperlinkEvent
, wxCommandEvent
)
83 wxDEFINE_EVENT( wxEVT_HYPERLINK
, wxHyperlinkEvent
);
85 wxBEGIN_PROPERTIES_TABLE(wxHyperlinkCtrl
)
86 wxPROPERTY( Label
, wxString
, SetLabel
, GetLabel
, wxString(), \
87 0 /*flags*/, wxT("The link label"), wxT("group") )
89 wxPROPERTY( URL
, wxString
, SetURL
, GetURL
, wxString(), \
90 0 /*flags*/, wxT("The link URL"), wxT("group") )
91 wxPROPERTY_FLAGS( WindowStyle
, wxHyperlinkStyle
, long, SetWindowStyleFlag
, \
92 GetWindowStyleFlag
, wxEMPTY_PARAMETER_VALUE
, 0 /*flags*/, \
93 wxT("The link style"), wxT("group")) // style
94 wxEND_PROPERTIES_TABLE()
96 wxEMPTY_HANDLERS_TABLE(wxHyperlinkCtrl
)
98 wxCONSTRUCTOR_7( wxHyperlinkCtrl
, wxWindow
*, Parent
, wxWindowID
, Id
, wxString
, \
99 Label
, wxString
, URL
, wxPoint
, Position
, wxSize
, Size
, long, WindowStyle
)
102 const char wxHyperlinkCtrlNameStr
[] = "hyperlink";
104 // ----------------------------------------------------------------------------
105 // wxHyperlinkCtrlBase
106 // ----------------------------------------------------------------------------
109 wxHyperlinkCtrlBase::CheckParams(const wxString
& label
,
114 wxASSERT_MSG(!url
.empty() || !label
.empty(),
115 wxT("Both URL and label are empty ?"));
117 int alignment
= (int)((style
& wxHL_ALIGN_LEFT
) != 0) +
118 (int)((style
& wxHL_ALIGN_CENTRE
) != 0) +
119 (int)((style
& wxHL_ALIGN_RIGHT
) != 0);
120 wxASSERT_MSG(alignment
== 1,
121 wxT("Specify exactly one align flag!"));
122 #else // !wxDEBUG_LEVEL
126 #endif // wxDEBUG_LEVEL/!wxDEBUG_LEVEL
129 void wxHyperlinkCtrlBase::SendEvent()
131 wxString url
= GetURL();
132 wxHyperlinkEvent
linkEvent(this, GetId(), url
);
133 if (!GetEventHandler()->ProcessEvent(linkEvent
)) // was the event skipped ?
135 if (!wxLaunchDefaultBrowser(url
))
137 wxLogWarning(wxT("Could not launch the default browser with url '%s' !"), url
.c_str());
142 #endif // wxUSE_HYPERLINKCTRL