]>
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
6 // Copyright: (c) 2010 wxWidgets team
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
14 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
21 #if wxUSE_HYPERLINKCTRL && wxUSE_UNICODE
23 #include "wx/hyperlink.h"
27 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
28 #include "wx/msw/private.h"
29 #include "wx/msw/missing.h"
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 #ifndef LM_GETIDEALSIZE
37 #define LM_GETIDEALSIZE (WM_USER + 0x301)
41 #define LWS_RIGHT 0x0020
45 #define WC_LINK L"SysLink"
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
54 bool HasNativeHyperlinkCtrl()
56 // Notice that we really must test comctl32.dll version and not the OS
57 // version here as even under Vista/7 we could be not using the v6 e.g.
58 // if the program doesn't have the correct manifest for some reason.
59 return wxApp::GetComCtl32Version() >= 600;
62 wxString
GetLabelForSysLink(const wxString
& text
, const wxString
& url
)
64 // Any "&"s in the text should appear on the screen and not be (mis)
65 // interpreted as mnemonics.
66 return wxString::Format("<A HREF=\"%s\">%s</A>",
68 wxControl::EscapeMnemonics(text
));
72 // ----------------------------------------------------------------------------
74 // ----------------------------------------------------------------------------
76 bool wxHyperlinkCtrl::Create(wxWindow
*parent
,
78 const wxString
& label
, const wxString
& url
,
84 if ( !HasNativeHyperlinkCtrl() )
86 return wxGenericHyperlinkCtrl::Create( parent
, id
, label
, url
, pos
,
90 if ( !CreateControl(parent
, id
, pos
, size
, style
,
91 wxDefaultValidator
, name
) )
100 WXDWORD msStyle
= MSWGetStyle(style
, &exstyle
);
102 if ( !MSWCreateControl(WC_LINK
, msStyle
, pos
, size
,
103 GetLabelForSysLink( label
, url
), exstyle
) )
108 // Make sure both the label and URL are non-empty strings.
109 SetURL(url
.empty() ? label
: url
);
110 SetLabel(label
.empty() ? url
: label
);
112 ConnectMenuHandlers();
117 WXDWORD
wxHyperlinkCtrl::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
119 WXDWORD msStyle
= wxControl::MSWGetStyle( style
, exstyle
);
121 if ( style
& wxHL_ALIGN_RIGHT
)
122 msStyle
|= LWS_RIGHT
;
127 void wxHyperlinkCtrl::SetURL(const wxString
&url
)
129 if ( !HasNativeHyperlinkCtrl() )
131 wxGenericHyperlinkCtrl::SetURL( url
);
135 if ( GetURL() != url
)
137 wxGenericHyperlinkCtrl::SetURL( url
);
138 wxWindow::SetLabel( GetLabelForSysLink(m_labelOrig
, url
) );
141 void wxHyperlinkCtrl::SetLabel(const wxString
&label
)
143 if ( !HasNativeHyperlinkCtrl() )
145 wxGenericHyperlinkCtrl::SetLabel( label
);
150 wxWindow::SetLabel( GetLabelForSysLink(label
, GetURL()) );
151 InvalidateBestSize();
154 wxSize
wxHyperlinkCtrl::DoGetBestClientSize() const
156 // LM_GETIDEALSIZE only exists under Vista so use the generic version even
157 // when using the native control under XP
158 if ( !HasNativeHyperlinkCtrl() || (wxGetWinVersion() < wxWinVersion_6
) )
159 return wxGenericHyperlinkCtrl::DoGetBestClientSize();
162 ::SendMessage(m_hWnd
, LM_GETIDEALSIZE
, 0, (LPARAM
)&idealSize
);
164 return wxSize(idealSize
.cx
, idealSize
.cy
);
167 bool wxHyperlinkCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
169 if ( HasNativeHyperlinkCtrl() )
171 switch ( ((LPNMHDR
) lParam
)->code
)
181 return wxGenericHyperlinkCtrl::MSWOnNotify(idCtrl
, lParam
, result
);
184 #endif // wxUSE_HYPERLINKCTRL && wxUSE_UNICODE