]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/hyperlink.cpp
ff2e8e9ccc7b1bea97943c9db1ed1408cf80a715
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/wrapcctl.h" // include <commctrl.h> "properly"
29 #include "wx/msw/private.h"
30 #include "wx/msw/missing.h"
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
37 #ifndef LM_GETIDEALSIZE
38 #define LM_GETIDEALSIZE (WM_USER + 0x301)
42 #define LWS_RIGHT 0x0020
46 #define WC_LINK L"SysLink"
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
55 bool HasNativeHyperlinkCtrl()
57 // Notice that we really must test comctl32.dll version and not the OS
58 // version here as even under Vista/7 we could be not using the v6 e.g.
59 // if the program doesn't have the correct manifest for some reason.
60 return wxApp::GetComCtl32Version() >= 600;
63 wxString
GetLabelForSysLink(const wxString
& text
, const wxString
& url
)
65 return wxString("<A HREF=\"") + wxStaticText::RemoveMarkup(url
) + "\">"
66 + wxStaticText::RemoveMarkup(text
) + "</A>";
70 // ----------------------------------------------------------------------------
72 // ----------------------------------------------------------------------------
74 bool wxHyperlinkCtrl::Create(wxWindow
*parent
,
76 const wxString
& label
, const wxString
& url
,
82 if ( !HasNativeHyperlinkCtrl() )
84 return wxGenericHyperlinkCtrl::Create( parent
, id
, label
, url
, pos
,
88 if ( !CreateControl(parent
, id
, pos
, size
, style
,
89 wxDefaultValidator
, name
) )
98 WXDWORD msStyle
= MSWGetStyle(style
, &exstyle
);
100 if ( !MSWCreateControl(WC_LINK
, msStyle
, pos
, size
,
101 GetLabelForSysLink( label
, url
), exstyle
) )
106 // Make sure both the label and URL are non-empty strings.
107 SetURL(url
.empty() ? label
: url
);
108 SetLabel(label
.empty() ? url
: label
);
110 ConnectMenuHandlers();
115 WXDWORD
wxHyperlinkCtrl::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
117 WXDWORD msStyle
= wxControl::MSWGetStyle( style
, exstyle
);
119 if ( style
& wxHL_ALIGN_RIGHT
)
120 msStyle
|= LWS_RIGHT
;
125 void wxHyperlinkCtrl::SetURL(const wxString
&url
)
127 if ( !HasNativeHyperlinkCtrl() )
129 wxGenericHyperlinkCtrl::SetURL( url
);
133 if ( GetURL() != url
)
135 wxGenericHyperlinkCtrl::SetURL( url
);
136 wxWindow::SetLabel( GetLabelForSysLink(m_labelOrig
, url
) );
139 void wxHyperlinkCtrl::SetLabel(const wxString
&label
)
141 if ( !HasNativeHyperlinkCtrl() )
143 wxGenericHyperlinkCtrl::SetLabel( label
);
148 wxWindow::SetLabel( GetLabelForSysLink(label
, GetURL()) );
149 InvalidateBestSize();
152 wxSize
wxHyperlinkCtrl::DoGetBestClientSize() const
154 // LM_GETIDEALSIZE only exists under Vista so use the generic version even
155 // when using the native control under XP
156 if ( !HasNativeHyperlinkCtrl() || (wxGetWinVersion() < wxWinVersion_6
) )
157 return wxGenericHyperlinkCtrl::DoGetBestClientSize();
160 ::SendMessage(m_hWnd
, LM_GETIDEALSIZE
, 0, (LPARAM
)&idealSize
);
162 return wxSize(idealSize
.cx
, idealSize
.cy
);
165 bool wxHyperlinkCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
167 if ( HasNativeHyperlinkCtrl() )
169 switch ( ((LPNMHDR
) lParam
)->code
)
179 return wxGenericHyperlinkCtrl::MSWOnNotify(idCtrl
, lParam
, result
);
182 #endif // wxUSE_HYPERLINKCTRL && wxUSE_UNICODE