]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/hyperlink.cpp
1f432871297a354fcd5f56f884e2aebfff1d0bf0
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"
28 #include "wx/msw/private.h"
31 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
35 #ifndef LM_GETIDEALSIZE
36 #define LM_GETIDEALSIZE (WM_USER + 0x301)
40 #define LWS_RIGHT 0x0020
44 #define WC_LINK L"SysLink"
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
53 bool HasNativeHyperlinkCtrl()
55 return wxGetWinVersion() >= wxWinVersion_XP
;
58 wxString
GetLabelForSysLink(const wxString
& text
, const wxString
& url
)
60 return wxString("<A HREF=\"") + wxStaticText::RemoveMarkup(url
) + "\">"
61 + wxStaticText::RemoveMarkup(text
) + "</A>";
65 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
69 bool wxHyperlinkCtrl::Create(wxWindow
*parent
,
71 const wxString
& label
, const wxString
& url
,
77 if ( !HasNativeHyperlinkCtrl() )
79 return wxGenericHyperlinkCtrl::Create( parent
, id
, label
, url
, pos
,
83 if ( !CreateControl(parent
, id
, pos
, size
, style
,
84 wxDefaultValidator
, name
) )
93 WXDWORD msStyle
= MSWGetStyle(style
, &exstyle
);
95 if ( !MSWCreateControl(WC_LINK
, msStyle
, pos
, size
,
96 GetLabelForSysLink( label
, url
), exstyle
) )
101 // Make sure both the label and URL are non-empty strings.
102 SetURL(url
.empty() ? label
: url
);
103 SetLabel(label
.empty() ? url
: label
);
105 ConnectMenuHandlers();
110 WXDWORD
wxHyperlinkCtrl::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
112 WXDWORD msStyle
= wxControl::MSWGetStyle( style
, exstyle
);
114 if ( style
& wxHL_ALIGN_RIGHT
)
115 msStyle
|= LWS_RIGHT
;
120 void wxHyperlinkCtrl::SetURL(const wxString
&url
)
122 if ( !HasNativeHyperlinkCtrl() )
124 wxGenericHyperlinkCtrl::SetURL( url
);
128 if ( GetURL() != url
)
130 wxGenericHyperlinkCtrl::SetURL( url
);
131 wxWindow::SetLabel( GetLabelForSysLink(m_labelOrig
, url
) );
134 void wxHyperlinkCtrl::SetLabel(const wxString
&label
)
136 if ( !HasNativeHyperlinkCtrl() )
138 wxGenericHyperlinkCtrl::SetLabel( label
);
143 wxWindow::SetLabel( GetLabelForSysLink(label
, GetURL()) );
144 InvalidateBestSize();
147 wxSize
wxHyperlinkCtrl::DoGetBestClientSize() const
149 // LM_GETIDEALSIZE only exists under Vista so use the generic version even
150 // when using the native control under XP
151 if ( wxGetWinVersion() < wxWinVersion_6
)
152 return wxGenericHyperlinkCtrl::DoGetBestClientSize();
155 ::SendMessage(m_hWnd
, LM_GETIDEALSIZE
, 0, (LPARAM
)&idealSize
);
157 return wxSize(idealSize
.cx
, idealSize
.cy
);
160 bool wxHyperlinkCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
162 if ( HasNativeHyperlinkCtrl() )
164 switch ( ((LPNMHDR
) lParam
)->code
)
174 return wxGenericHyperlinkCtrl::MSWOnNotify(idCtrl
, lParam
, result
);
177 #endif // wxUSE_HYPERLINKCTRL && wxUSE_UNICODE