]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/common/hyperlnkcmn.cpp
Add some version checks to help compiling on OSX.
[wxWidgets.git] / src / common / hyperlnkcmn.cpp
... / ...
CommitLineData
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
45wxDEFINE_FLAGS( wxHyperlinkStyle )
46wxBEGIN_FLAGS( wxHyperlinkStyle )
47// new style border flags, we put them first to
48// use them for streaming out
49wxFLAGS_MEMBER(wxBORDER_SIMPLE)
50wxFLAGS_MEMBER(wxBORDER_SUNKEN)
51wxFLAGS_MEMBER(wxBORDER_DOUBLE)
52wxFLAGS_MEMBER(wxBORDER_RAISED)
53wxFLAGS_MEMBER(wxBORDER_STATIC)
54wxFLAGS_MEMBER(wxBORDER_NONE)
55
56// old style border flags
57wxFLAGS_MEMBER(wxSIMPLE_BORDER)
58wxFLAGS_MEMBER(wxSUNKEN_BORDER)
59wxFLAGS_MEMBER(wxDOUBLE_BORDER)
60wxFLAGS_MEMBER(wxRAISED_BORDER)
61wxFLAGS_MEMBER(wxSTATIC_BORDER)
62wxFLAGS_MEMBER(wxBORDER)
63
64// standard window styles
65wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
66wxFLAGS_MEMBER(wxCLIP_CHILDREN)
67wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
68wxFLAGS_MEMBER(wxWANTS_CHARS)
69wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
70wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
71wxFLAGS_MEMBER(wxVSCROLL)
72wxFLAGS_MEMBER(wxHSCROLL)
73
74wxFLAGS_MEMBER(wxHL_CONTEXTMENU)
75wxFLAGS_MEMBER(wxHL_ALIGN_LEFT)
76wxFLAGS_MEMBER(wxHL_ALIGN_RIGHT)
77wxFLAGS_MEMBER(wxHL_ALIGN_CENTRE)
78wxEND_FLAGS( wxHyperlinkStyle )
79
80wxIMPLEMENT_DYNAMIC_CLASS_XTI( wxHyperlinkCtrl, wxControl, "wx/hyperlink.h")
81
82IMPLEMENT_DYNAMIC_CLASS(wxHyperlinkEvent, wxCommandEvent)
83wxDEFINE_EVENT( wxEVT_COMMAND_HYPERLINK, wxHyperlinkEvent );
84
85wxBEGIN_PROPERTIES_TABLE(wxHyperlinkCtrl)
86wxPROPERTY( Label, wxString, SetLabel, GetLabel, wxString(), \
87 0 /*flags*/, wxT("The link label"), wxT("group") )
88
89wxPROPERTY( URL, wxString, SetURL, GetURL, wxString(), \
90 0 /*flags*/, wxT("The link URL"), wxT("group") )
91wxPROPERTY_FLAGS( WindowStyle, wxHyperlinkStyle, long, SetWindowStyleFlag, \
92 GetWindowStyleFlag, wxEMPTY_PARAMETER_VALUE, 0 /*flags*/, \
93 wxT("The link style"), wxT("group")) // style
94wxEND_PROPERTIES_TABLE()
95
96wxEMPTY_HANDLERS_TABLE(wxHyperlinkCtrl)
97
98wxCONSTRUCTOR_7( wxHyperlinkCtrl, wxWindow*, Parent, wxWindowID, Id, wxString, \
99 Label, wxString, URL, wxPoint, Position, wxSize, Size, long, WindowStyle )
100
101
102const char wxHyperlinkCtrlNameStr[] = "hyperlink";
103
104// ----------------------------------------------------------------------------
105// wxHyperlinkCtrlBase
106// ----------------------------------------------------------------------------
107
108void
109wxHyperlinkCtrlBase::CheckParams(const wxString& label,
110 const wxString& url,
111 long style)
112{
113#if wxDEBUG_LEVEL
114 wxASSERT_MSG(!url.empty() || !label.empty(),
115 wxT("Both URL and label are empty ?"));
116
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
123 wxUnusedVar(label);
124 wxUnusedVar(url);
125 wxUnusedVar(style);
126#endif // wxDEBUG_LEVEL/!wxDEBUG_LEVEL
127}
128
129void wxHyperlinkCtrlBase::SendEvent()
130{
131 wxString url = GetURL();
132 wxHyperlinkEvent linkEvent(this, GetId(), url);
133 if (!GetEventHandler()->ProcessEvent(linkEvent)) // was the event skipped ?
134 {
135 if (!wxLaunchDefaultBrowser(url))
136 {
137 wxLogWarning(wxT("Could not launch the default browser with url '%s' !"), url.c_str());
138 }
139 }
140}
141
142#endif // wxUSE_HYPERLINKCTRL