]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/hyperlink.cpp
0e4f5009f5409d7d135a6777e62880d81b0cd2d1
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/hyperlink.cpp
3 // Purpose: Hyperlink control
4 // Author: Rickard Westerlund
7 // Copyright: (c) 2010 wxWidgets team
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ----------------------------------------------------------------------------
13 // ----------------------------------------------------------------------------
15 // For compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
22 #if wxUSE_HYPERLINKCTRL && wxUSE_UNICODE
24 #include "wx/hyperlink.h"
27 #include "wx/stattext.h"
30 // ----------------------------------------------------------------------------
32 // ----------------------------------------------------------------------------
34 #ifndef LM_GETIDEALSIZE
35 #define LM_GETIDEALSIZE (WM_USER + 0x301)
39 #define LWS_RIGHT 0x0020
43 #define WC_LINK L"SysLink"
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
52 bool HasNativeHyperlinkCtrl()
54 return wxGetWinVersion() >= wxWinVersion_XP
;
57 wxString
GetLabelForSysLink(const wxString
& text
, const wxString
& url
)
59 return wxString("<A HREF=\"") + wxStaticText::RemoveMarkup(url
) + "\">"
60 + wxStaticText::RemoveMarkup(text
) + "</A>";
64 // ----------------------------------------------------------------------------
66 // ----------------------------------------------------------------------------
68 bool wxHyperlinkCtrl::Create(wxWindow
*parent
,
70 const wxString
& label
, const wxString
& url
,
76 if ( !HasNativeHyperlinkCtrl() )
78 return wxGenericHyperlinkCtrl::Create( parent
, id
, label
, url
, pos
,
82 if ( !CreateControl(parent
, id
, pos
, size
, style
,
83 wxDefaultValidator
, name
) )
92 WXDWORD msStyle
= MSWGetStyle(style
, &exstyle
);
94 if ( !MSWCreateControl(WC_LINK
, msStyle
, pos
, size
,
95 GetLabelForSysLink( label
, url
), exstyle
) )
100 // Make sure both the label and URL are non-empty strings.
101 SetURL(url
.empty() ? label
: url
);
102 SetLabel(label
.empty() ? url
: label
);
104 ConnectMenuHandlers();
109 WXDWORD
wxHyperlinkCtrl::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
111 WXDWORD msStyle
= wxControl::MSWGetStyle( style
, exstyle
);
113 if ( style
& wxHL_ALIGN_RIGHT
)
114 msStyle
|= LWS_RIGHT
;
119 void wxHyperlinkCtrl::SetURL(const wxString
&url
)
121 if ( !HasNativeHyperlinkCtrl() )
123 wxGenericHyperlinkCtrl::SetURL( url
);
127 if ( GetURL() != url
)
129 wxGenericHyperlinkCtrl::SetURL( url
);
130 wxWindow::SetLabel( GetLabelForSysLink(m_labelOrig
, url
) );
133 void wxHyperlinkCtrl::SetLabel(const wxString
&label
)
135 if ( !HasNativeHyperlinkCtrl() )
137 wxGenericHyperlinkCtrl::SetLabel( label
);
142 wxWindow::SetLabel( GetLabelForSysLink(label
, GetURL()) );
143 InvalidateBestSize();
146 wxSize
wxHyperlinkCtrl::DoGetBestClientSize() const
148 // LM_GETIDEALSIZE only exists under Vista so use the generic version even
149 // when using the native control under XP
150 if ( wxGetWinVersion() < wxWinVersion_6
)
151 return wxGenericHyperlinkCtrl::DoGetBestClientSize();
154 ::SendMessage(m_hWnd
, LM_GETIDEALSIZE
, 0, (LPARAM
)&idealSize
);
156 return wxSize(idealSize
.cx
, idealSize
.cy
);
159 bool wxHyperlinkCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
161 if ( HasNativeHyperlinkCtrl() )
163 switch ( ((LPNMHDR
) lParam
)->code
)
173 return wxGenericHyperlinkCtrl::MSWOnNotify(idCtrl
, lParam
, result
);
176 #endif // wxUSE_HYPERLINKCTRL && wxUSE_UNICODE