]>
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"
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 return wxGetWinVersion() >= wxWinVersion_XP
;
60 wxString
GetLabelForSysLink(const wxString
& text
, const wxString
& url
)
62 return wxString("<A HREF=\"") + wxStaticText::RemoveMarkup(url
) + "\">"
63 + wxStaticText::RemoveMarkup(text
) + "</A>";
67 // ----------------------------------------------------------------------------
69 // ----------------------------------------------------------------------------
71 bool wxHyperlinkCtrl::Create(wxWindow
*parent
,
73 const wxString
& label
, const wxString
& url
,
79 if ( !HasNativeHyperlinkCtrl() )
81 return wxGenericHyperlinkCtrl::Create( parent
, id
, label
, url
, pos
,
85 if ( !CreateControl(parent
, id
, pos
, size
, style
,
86 wxDefaultValidator
, name
) )
95 WXDWORD msStyle
= MSWGetStyle(style
, &exstyle
);
97 if ( !MSWCreateControl(WC_LINK
, msStyle
, pos
, size
,
98 GetLabelForSysLink( label
, url
), exstyle
) )
103 // Make sure both the label and URL are non-empty strings.
104 SetURL(url
.empty() ? label
: url
);
105 SetLabel(label
.empty() ? url
: label
);
107 ConnectMenuHandlers();
112 WXDWORD
wxHyperlinkCtrl::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
114 WXDWORD msStyle
= wxControl::MSWGetStyle( style
, exstyle
);
116 if ( style
& wxHL_ALIGN_RIGHT
)
117 msStyle
|= LWS_RIGHT
;
122 void wxHyperlinkCtrl::SetURL(const wxString
&url
)
124 if ( !HasNativeHyperlinkCtrl() )
126 wxGenericHyperlinkCtrl::SetURL( url
);
130 if ( GetURL() != url
)
132 wxGenericHyperlinkCtrl::SetURL( url
);
133 wxWindow::SetLabel( GetLabelForSysLink(m_labelOrig
, url
) );
136 void wxHyperlinkCtrl::SetLabel(const wxString
&label
)
138 if ( !HasNativeHyperlinkCtrl() )
140 wxGenericHyperlinkCtrl::SetLabel( label
);
145 wxWindow::SetLabel( GetLabelForSysLink(label
, GetURL()) );
146 InvalidateBestSize();
149 wxSize
wxHyperlinkCtrl::DoGetBestClientSize() const
151 // LM_GETIDEALSIZE only exists under Vista so use the generic version even
152 // when using the native control under XP
153 if ( wxGetWinVersion() < wxWinVersion_6
)
154 return wxGenericHyperlinkCtrl::DoGetBestClientSize();
157 ::SendMessage(m_hWnd
, LM_GETIDEALSIZE
, 0, (LPARAM
)&idealSize
);
159 return wxSize(idealSize
.cx
, idealSize
.cy
);
162 bool wxHyperlinkCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
164 if ( HasNativeHyperlinkCtrl() )
166 switch ( ((LPNMHDR
) lParam
)->code
)
176 return wxGenericHyperlinkCtrl::MSWOnNotify(idCtrl
, lParam
, result
);
179 #endif // wxUSE_HYPERLINKCTRL && wxUSE_UNICODE