]>
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/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 // Any "&"s in the text should appear on the screen and not be (mis)
66 // interpreted as mnemonics.
67 return wxString::Format("<A HREF=\"%s\">%s</A>",
69 wxControl::EscapeMnemonics(text
));
73 // ----------------------------------------------------------------------------
75 // ----------------------------------------------------------------------------
77 bool wxHyperlinkCtrl::Create(wxWindow
*parent
,
79 const wxString
& label
, const wxString
& url
,
85 if ( !HasNativeHyperlinkCtrl() )
87 return wxGenericHyperlinkCtrl::Create( parent
, id
, label
, url
, pos
,
91 if ( !CreateControl(parent
, id
, pos
, size
, style
,
92 wxDefaultValidator
, name
) )
101 WXDWORD msStyle
= MSWGetStyle(style
, &exstyle
);
103 if ( !MSWCreateControl(WC_LINK
, msStyle
, pos
, size
,
104 GetLabelForSysLink( label
, url
), exstyle
) )
109 // Make sure both the label and URL are non-empty strings.
110 SetURL(url
.empty() ? label
: url
);
111 SetLabel(label
.empty() ? url
: label
);
113 ConnectMenuHandlers();
118 WXDWORD
wxHyperlinkCtrl::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
120 WXDWORD msStyle
= wxControl::MSWGetStyle( style
, exstyle
);
122 if ( style
& wxHL_ALIGN_RIGHT
)
123 msStyle
|= LWS_RIGHT
;
128 void wxHyperlinkCtrl::SetURL(const wxString
&url
)
130 if ( !HasNativeHyperlinkCtrl() )
132 wxGenericHyperlinkCtrl::SetURL( url
);
136 if ( GetURL() != url
)
138 wxGenericHyperlinkCtrl::SetURL( url
);
139 wxWindow::SetLabel( GetLabelForSysLink(m_labelOrig
, url
) );
142 void wxHyperlinkCtrl::SetLabel(const wxString
&label
)
144 if ( !HasNativeHyperlinkCtrl() )
146 wxGenericHyperlinkCtrl::SetLabel( label
);
151 wxWindow::SetLabel( GetLabelForSysLink(label
, GetURL()) );
152 InvalidateBestSize();
155 wxSize
wxHyperlinkCtrl::DoGetBestClientSize() const
157 // LM_GETIDEALSIZE only exists under Vista so use the generic version even
158 // when using the native control under XP
159 if ( !HasNativeHyperlinkCtrl() || (wxGetWinVersion() < wxWinVersion_6
) )
160 return wxGenericHyperlinkCtrl::DoGetBestClientSize();
163 ::SendMessage(m_hWnd
, LM_GETIDEALSIZE
, 0, (LPARAM
)&idealSize
);
165 return wxSize(idealSize
.cx
, idealSize
.cy
);
168 bool wxHyperlinkCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
170 if ( HasNativeHyperlinkCtrl() )
172 switch ( ((LPNMHDR
) lParam
)->code
)
182 return wxGenericHyperlinkCtrl::MSWOnNotify(idCtrl
, lParam
, result
);
185 #endif // wxUSE_HYPERLINKCTRL && wxUSE_UNICODE