Generic wxHyperlinkCtrl appearance and behaviour improvements.

Show focus rectangle around the control when it has focus. Also handle the
space key to trigger the link.

Also allow using either the native or generic version of the class in the
widgets sample.

Closes #11285.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67948 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2011-06-15 21:56:23 +00:00
parent da8eb5f5bb
commit bc927c9a8c
4 changed files with 116 additions and 22 deletions

View File

@@ -41,6 +41,7 @@
#endif
#include "wx/clipbrd.h"
#include "wx/renderer.h"
// ============================================================================
// implementation
@@ -89,6 +90,9 @@ bool wxGenericHyperlinkCtrl::Create(wxWindow *parent, wxWindowID id,
// with GTK+'s native handling):
Connect( wxEVT_PAINT, wxPaintEventHandler(wxGenericHyperlinkCtrl::OnPaint) );
Connect( wxEVT_SET_FOCUS, wxFocusEventHandler(wxGenericHyperlinkCtrl::OnFocus) );
Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler(wxGenericHyperlinkCtrl::OnFocus) );
Connect( wxEVT_CHAR, wxKeyEventHandler(wxGenericHyperlinkCtrl::OnChar) );
Connect( wxEVT_LEAVE_WINDOW, wxMouseEventHandler(wxGenericHyperlinkCtrl::OnLeaveWindow) );
Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler(wxGenericHyperlinkCtrl::OnLeftDown) );
@@ -187,6 +191,32 @@ void wxGenericHyperlinkCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
dc.SetTextBackground(GetBackgroundColour());
dc.DrawText(GetLabel(), GetLabelRect().GetTopLeft());
if (HasFocus())
{
wxRendererNative::Get().DrawFocusRect(this, dc, GetClientRect(), wxCONTROL_SELECTED);
}
}
void wxGenericHyperlinkCtrl::OnFocus(wxFocusEvent& event)
{
Refresh();
event.Skip();
}
void wxGenericHyperlinkCtrl::OnChar(wxKeyEvent& event)
{
switch (event.m_keyCode)
{
default:
event.Skip();
break;
case WXK_SPACE:
case WXK_NUMPAD_SPACE:
SetForegroundColour(m_visitedColour);
m_visited = true;
SendEvent();
break;
}
}
void wxGenericHyperlinkCtrl::OnLeftDown(wxMouseEvent& event)