]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/hyperlink.cpp
a2ba44a8eb2747b8de6ed4152b922ada84f608f7
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
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
48 bool HasNativeHyperlinkCtrl()
50 return wxGetWinVersion() >= wxWinVersion_XP
;
53 wxString
GetLabelForSysLink(const wxString
& text
, const wxString
& url
)
55 return wxString("<A HREF=\"") + wxStaticText::RemoveMarkup(url
) + "\">"
56 + wxStaticText::RemoveMarkup(text
) + "</A>";
60 // ----------------------------------------------------------------------------
62 // ----------------------------------------------------------------------------
64 bool wxHyperlinkCtrl::Create(wxWindow
*parent
,
66 const wxString
& label
, const wxString
& url
,
72 if ( !HasNativeHyperlinkCtrl() )
74 return wxGenericHyperlinkCtrl::Create( parent
, id
, label
, url
, pos
,
78 if ( !CreateControl(parent
, id
, pos
, size
, style
,
79 wxDefaultValidator
, name
) )
88 WXDWORD msStyle
= MSWGetStyle(style
, &exstyle
);
90 if ( !MSWCreateControl(WC_LINK
, msStyle
, pos
, size
,
91 GetLabelForSysLink( label
, url
), exstyle
) )
96 // Make sure both the label and URL are non-empty strings.
97 SetURL(url
.empty() ? label
: url
);
98 SetLabel(label
.empty() ? url
: label
);
100 ConnectMenuHandlers();
105 WXDWORD
wxHyperlinkCtrl::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
107 WXDWORD msStyle
= wxControl::MSWGetStyle( style
, exstyle
);
109 if ( style
& wxHL_ALIGN_RIGHT
)
110 msStyle
|= LWS_RIGHT
;
115 void wxHyperlinkCtrl::SetURL(const wxString
&url
)
117 if ( !HasNativeHyperlinkCtrl() )
119 wxGenericHyperlinkCtrl::SetURL( url
);
123 if ( GetURL() != url
)
125 wxGenericHyperlinkCtrl::SetURL( url
);
126 wxWindow::SetLabel( GetLabelForSysLink(m_labelOrig
, url
) );
129 void wxHyperlinkCtrl::SetLabel(const wxString
&label
)
131 if ( !HasNativeHyperlinkCtrl() )
133 wxGenericHyperlinkCtrl::SetLabel( label
);
138 wxWindow::SetLabel( GetLabelForSysLink(label
, GetURL()) );
139 InvalidateBestSize();
142 wxSize
wxHyperlinkCtrl::DoGetBestClientSize() const
144 // LM_GETIDEALSIZE only exists under Vista so use the generic version even
145 // when using the native control under XP
146 if ( wxGetWinVersion() < wxWinVersion_6
)
147 return wxGenericHyperlinkCtrl::DoGetBestClientSize();
150 ::SendMessage(m_hWnd
, LM_GETIDEALSIZE
, 0, (LPARAM
)&idealSize
);
152 return wxSize(idealSize
.cx
, idealSize
.cy
);
155 bool wxHyperlinkCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
157 if ( HasNativeHyperlinkCtrl() )
159 switch ( ((LPNMHDR
) lParam
)->code
)
169 return wxGenericHyperlinkCtrl::MSWOnNotify(idCtrl
, lParam
, result
);
172 #endif // wxUSE_HYPERLINKCTRL && wxUSE_UNICODE