]>
Commit | Line | Data |
---|---|---|
c105dda0 VZ |
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 | |
6 | // Created: 04/02/2005 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 2005 David Norris | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | //--------------------------------------------------------------------------- | |
17 | // Pre-compiled header stuff | |
18 | //--------------------------------------------------------------------------- | |
19 | ||
20 | // For compilers that support precompilation, includes "wx.h". | |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
27 | #if wxUSE_HYPERLINKCTRL | |
28 | ||
29 | //--------------------------------------------------------------------------- | |
30 | // Includes | |
31 | //--------------------------------------------------------------------------- | |
32 | ||
33 | #include "wx/hyperlink.h" | |
34 | ||
35 | #ifndef WX_PRECOMP | |
36 | #include "wx/menu.h" | |
37 | #include "wx/log.h" | |
38 | #include "wx/dataobj.h" | |
39 | #endif | |
40 | ||
41 | // ============================================================================ | |
42 | // implementation | |
43 | // ============================================================================ | |
44 | ||
b815cf68 VZ |
45 | #if wxUSE_EXTENDED_RTTI |
46 | wxIMPLEMENT_DYNAMIC_CLASS_XTI( wxHyperlinkCtrl, wxControl, "wx/hyperlink.h") | |
47 | #else | |
48 | wxIMPLEMENT_DYNAMIC_CLASS( wxHyperlinkCtrl, wxControl ) | |
49 | #endif // wxUSE_EXTENDED_RTTI | |
50 | ||
c105dda0 | 51 | IMPLEMENT_DYNAMIC_CLASS(wxHyperlinkEvent, wxCommandEvent) |
9b11752c | 52 | wxDEFINE_EVENT( wxEVT_COMMAND_HYPERLINK, wxHyperlinkEvent ); |
c105dda0 | 53 | |
23318a53 | 54 | const char wxHyperlinkCtrlNameStr[] = "hyperlink"; |
c105dda0 VZ |
55 | |
56 | // ---------------------------------------------------------------------------- | |
57 | // wxHyperlinkCtrlBase | |
58 | // ---------------------------------------------------------------------------- | |
59 | ||
657a8a35 VZ |
60 | void |
61 | wxHyperlinkCtrlBase::CheckParams(const wxString& label, | |
62 | const wxString& url, | |
63 | long style) | |
c105dda0 | 64 | { |
657a8a35 | 65 | #if wxDEBUG_LEVEL |
c105dda0 VZ |
66 | wxASSERT_MSG(!url.empty() || !label.empty(), |
67 | wxT("Both URL and label are empty ?")); | |
68 | ||
69 | int alignment = (int)((style & wxHL_ALIGN_LEFT) != 0) + | |
70 | (int)((style & wxHL_ALIGN_CENTRE) != 0) + | |
71 | (int)((style & wxHL_ALIGN_RIGHT) != 0); | |
72 | wxASSERT_MSG(alignment == 1, | |
73 | wxT("Specify exactly one align flag!")); | |
657a8a35 VZ |
74 | #else // !wxDEBUG_LEVEL |
75 | wxUnusedVar(label); | |
76 | wxUnusedVar(url); | |
77 | wxUnusedVar(style); | |
78 | #endif // wxDEBUG_LEVEL/!wxDEBUG_LEVEL | |
c105dda0 | 79 | } |
c105dda0 VZ |
80 | |
81 | void wxHyperlinkCtrlBase::SendEvent() | |
82 | { | |
83 | wxString url = GetURL(); | |
84 | wxHyperlinkEvent linkEvent(this, GetId(), url); | |
85 | if (!GetEventHandler()->ProcessEvent(linkEvent)) // was the event skipped ? | |
af588446 | 86 | { |
c105dda0 | 87 | if (!wxLaunchDefaultBrowser(url)) |
af588446 | 88 | { |
c105dda0 | 89 | wxLogWarning(wxT("Could not launch the default browser with url '%s' !"), url.c_str()); |
af588446 VZ |
90 | } |
91 | } | |
c105dda0 VZ |
92 | } |
93 | ||
94 | #endif // wxUSE_HYPERLINKCTRL |