]>
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
7 // Copyright: (c) 2005 David Norris
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 //---------------------------------------------------------------------------
16 // Pre-compiled header stuff
17 //---------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
26 #if wxUSE_HYPERLINKCTRL
28 //---------------------------------------------------------------------------
30 //---------------------------------------------------------------------------
32 #include "wx/hyperlink.h"
37 #include "wx/dataobj.h"
40 // ============================================================================
42 // ============================================================================
44 wxDEFINE_FLAGS( wxHyperlinkStyle
)
45 wxBEGIN_FLAGS( wxHyperlinkStyle
)
46 // new style border flags, we put them first to
47 // use them for streaming out
48 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
49 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
50 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
51 wxFLAGS_MEMBER(wxBORDER_RAISED
)
52 wxFLAGS_MEMBER(wxBORDER_STATIC
)
53 wxFLAGS_MEMBER(wxBORDER_NONE
)
55 // old style border flags
56 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
57 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
58 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
59 wxFLAGS_MEMBER(wxRAISED_BORDER
)
60 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
61 wxFLAGS_MEMBER(wxBORDER
)
63 // standard window styles
64 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
65 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
66 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
67 wxFLAGS_MEMBER(wxWANTS_CHARS
)
68 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
69 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
70 wxFLAGS_MEMBER(wxVSCROLL
)
71 wxFLAGS_MEMBER(wxHSCROLL
)
73 wxFLAGS_MEMBER(wxHL_CONTEXTMENU
)
74 wxFLAGS_MEMBER(wxHL_ALIGN_LEFT
)
75 wxFLAGS_MEMBER(wxHL_ALIGN_RIGHT
)
76 wxFLAGS_MEMBER(wxHL_ALIGN_CENTRE
)
77 wxEND_FLAGS( wxHyperlinkStyle
)
79 wxIMPLEMENT_DYNAMIC_CLASS_XTI( wxHyperlinkCtrl
, wxControl
, "wx/hyperlink.h")
81 IMPLEMENT_DYNAMIC_CLASS(wxHyperlinkEvent
, wxCommandEvent
)
82 wxDEFINE_EVENT( wxEVT_HYPERLINK
, wxHyperlinkEvent
);
84 wxBEGIN_PROPERTIES_TABLE(wxHyperlinkCtrl
)
85 wxPROPERTY( Label
, wxString
, SetLabel
, GetLabel
, wxString(), \
86 0 /*flags*/, wxT("The link label"), wxT("group") )
88 wxPROPERTY( URL
, wxString
, SetURL
, GetURL
, wxString(), \
89 0 /*flags*/, wxT("The link URL"), wxT("group") )
90 wxPROPERTY_FLAGS( WindowStyle
, wxHyperlinkStyle
, long, SetWindowStyleFlag
, \
91 GetWindowStyleFlag
, wxEMPTY_PARAMETER_VALUE
, 0 /*flags*/, \
92 wxT("The link style"), wxT("group")) // style
93 wxEND_PROPERTIES_TABLE()
95 wxEMPTY_HANDLERS_TABLE(wxHyperlinkCtrl
)
97 wxCONSTRUCTOR_7( wxHyperlinkCtrl
, wxWindow
*, Parent
, wxWindowID
, Id
, wxString
, \
98 Label
, wxString
, URL
, wxPoint
, Position
, wxSize
, Size
, long, WindowStyle
)
101 const char wxHyperlinkCtrlNameStr
[] = "hyperlink";
103 // ----------------------------------------------------------------------------
104 // wxHyperlinkCtrlBase
105 // ----------------------------------------------------------------------------
108 wxHyperlinkCtrlBase::CheckParams(const wxString
& label
,
113 wxASSERT_MSG(!url
.empty() || !label
.empty(),
114 wxT("Both URL and label are empty ?"));
116 int alignment
= (int)((style
& wxHL_ALIGN_LEFT
) != 0) +
117 (int)((style
& wxHL_ALIGN_CENTRE
) != 0) +
118 (int)((style
& wxHL_ALIGN_RIGHT
) != 0);
119 wxASSERT_MSG(alignment
== 1,
120 wxT("Specify exactly one align flag!"));
121 #else // !wxDEBUG_LEVEL
125 #endif // wxDEBUG_LEVEL/!wxDEBUG_LEVEL
128 void wxHyperlinkCtrlBase::SendEvent()
130 wxString url
= GetURL();
131 wxHyperlinkEvent
linkEvent(this, GetId(), url
);
132 if (!GetEventHandler()->ProcessEvent(linkEvent
)) // was the event skipped ?
134 if (!wxLaunchDefaultBrowser(url
))
136 wxLogWarning(wxT("Could not launch the default browser with url '%s' !"), url
.c_str());
141 #endif // wxUSE_HYPERLINKCTRL