]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/hyperlink.cpp
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"
28 #include "wx/stattext.h"
29 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
30 #include "wx/msw/private.h"
31 #include "wx/msw/missing.h"
34 // ----------------------------------------------------------------------------
36 // ----------------------------------------------------------------------------
38 #ifndef LM_GETIDEALSIZE
39 #define LM_GETIDEALSIZE (WM_USER + 0x301)
43 #define LWS_RIGHT 0x0020
47 #define WC_LINK L"SysLink"
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
56 bool HasNativeHyperlinkCtrl()
58 // Notice that we really must test comctl32.dll version and not the OS
59 // version here as even under Vista/7 we could be not using the v6 e.g.
60 // if the program doesn't have the correct manifest for some reason.
61 return wxApp::GetComCtl32Version() >= 600;
64 wxString
GetLabelForSysLink(const wxString
& text
, const wxString
& url
)
66 return wxString("<A HREF=\"") + wxStaticText::RemoveMarkup(url
) + "\">"
67 + wxStaticText::RemoveMarkup(text
) + "</A>";
71 // ----------------------------------------------------------------------------
73 // ----------------------------------------------------------------------------
75 bool wxHyperlinkCtrl::Create(wxWindow
*parent
,
77 const wxString
& label
, const wxString
& url
,
83 if ( !HasNativeHyperlinkCtrl() )
85 return wxGenericHyperlinkCtrl::Create( parent
, id
, label
, url
, pos
,
89 if ( !CreateControl(parent
, id
, pos
, size
, style
,
90 wxDefaultValidator
, name
) )
99 WXDWORD msStyle
= MSWGetStyle(style
, &exstyle
);
101 if ( !MSWCreateControl(WC_LINK
, msStyle
, pos
, size
,
102 GetLabelForSysLink( label
, url
), exstyle
) )
107 // Make sure both the label and URL are non-empty strings.
108 SetURL(url
.empty() ? label
: url
);
109 SetLabel(label
.empty() ? url
: label
);
111 ConnectMenuHandlers();
116 WXDWORD
wxHyperlinkCtrl::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
118 WXDWORD msStyle
= wxControl::MSWGetStyle( style
, exstyle
);
120 if ( style
& wxHL_ALIGN_RIGHT
)
121 msStyle
|= LWS_RIGHT
;
126 void wxHyperlinkCtrl::SetURL(const wxString
&url
)
128 if ( !HasNativeHyperlinkCtrl() )
130 wxGenericHyperlinkCtrl::SetURL( url
);
134 if ( GetURL() != url
)
136 wxGenericHyperlinkCtrl::SetURL( url
);
137 wxWindow::SetLabel( GetLabelForSysLink(m_labelOrig
, url
) );
140 void wxHyperlinkCtrl::SetLabel(const wxString
&label
)
142 if ( !HasNativeHyperlinkCtrl() )
144 wxGenericHyperlinkCtrl::SetLabel( label
);
149 wxWindow::SetLabel( GetLabelForSysLink(label
, GetURL()) );
150 InvalidateBestSize();
153 wxSize
wxHyperlinkCtrl::DoGetBestClientSize() const
155 // LM_GETIDEALSIZE only exists under Vista so use the generic version even
156 // when using the native control under XP
157 if ( !HasNativeHyperlinkCtrl() || (wxGetWinVersion() < wxWinVersion_6
) )
158 return wxGenericHyperlinkCtrl::DoGetBestClientSize();
161 ::SendMessage(m_hWnd
, LM_GETIDEALSIZE
, 0, (LPARAM
)&idealSize
);
163 return wxSize(idealSize
.cx
, idealSize
.cy
);
166 bool wxHyperlinkCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
168 if ( HasNativeHyperlinkCtrl() )
170 switch ( ((LPNMHDR
) lParam
)->code
)
180 return wxGenericHyperlinkCtrl::MSWOnNotify(idCtrl
, lParam
, result
);
183 #endif // wxUSE_HYPERLINKCTRL && wxUSE_UNICODE