]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/hyperlinkg.cpp
Fix horizontal mouse wheel scrolling in wxGTK.
[wxWidgets.git] / src / generic / hyperlinkg.cpp
index f368ee3b32231c62b7eded0cbe98c602a53a8e1d..eb8485955d1e5118de88d917d99a74abcbcdab68 100644 (file)
@@ -4,7 +4,6 @@
 // Author:      David Norris <danorris@gmail.com>, Otto Wyss
 // Modified by: Ryan Norton, Francesco Montorsi
 // Created:     04/02/2005
-// RCS-ID:      $Id$
 // Copyright:   (c) 2005 David Norris
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 #endif
 
 #include "wx/clipbrd.h"
+#include "wx/renderer.h"
 
 // ============================================================================
 // implementation
 // ============================================================================
 
-IMPLEMENT_DYNAMIC_CLASS(wxGenericHyperlinkCtrl, wxControl)
-
 // reserved for internal use only
 #define wxHYPERLINK_POPUP_COPY_ID           16384
 
@@ -72,13 +70,7 @@ bool wxGenericHyperlinkCtrl::Create(wxWindow *parent, wxWindowID id,
     SetURL(url.empty() ? label : url);
     SetLabel(label.empty() ? url : label);
 
-    m_rollover = false;
-    m_clicking = false;
-    m_visited = false;
-
-    // colours
-    m_normalColour = *wxBLUE;
-    m_hoverColour = *wxRED;
+    Init();
     SetForegroundColour(m_normalColour);
 
     // by default the font of an hyperlink control is underlined
@@ -97,30 +89,44 @@ 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) );
     Connect( wxEVT_LEFT_UP, wxMouseEventHandler(wxGenericHyperlinkCtrl::OnLeftUp) );
-    Connect( wxEVT_RIGHT_UP, wxMouseEventHandler(wxGenericHyperlinkCtrl::OnRightUp) );
     Connect( wxEVT_MOTION, wxMouseEventHandler(wxGenericHyperlinkCtrl::OnMotion) );
 
-    Connect( wxHYPERLINK_POPUP_COPY_ID, wxEVT_COMMAND_MENU_SELECTED,
-             wxCommandEventHandler(wxGenericHyperlinkCtrl::OnPopUpCopy) );
+    ConnectMenuHandlers();
 
     return true;
 }
 
-wxSize wxGenericHyperlinkCtrl::DoGetBestSize() const
+void wxGenericHyperlinkCtrl::Init()
 {
-    int w, h;
+    m_rollover = false;
+    m_clicking = false;
+    m_visited = false;
 
-    wxClientDC dc((wxWindow *)this);
-    dc.SetFont(GetFont());
-    dc.GetTextExtent(GetLabel(), &w, &h);
+    // colours
+    m_normalColour = *wxBLUE;
+    m_hoverColour = *wxRED;
+    m_visitedColour = wxColour("#551a8b");
+}
 
-    wxSize best(w, h);
-    CacheBestSize(best);
-    return best;
+void wxGenericHyperlinkCtrl::ConnectMenuHandlers()
+{
+    // Connect the event handlers for the context menu.
+    Connect( wxEVT_RIGHT_UP, wxMouseEventHandler(wxGenericHyperlinkCtrl::OnRightUp) );
+    Connect( wxHYPERLINK_POPUP_COPY_ID, wxEVT_MENU,
+             wxCommandEventHandler(wxGenericHyperlinkCtrl::OnPopUpCopy) );
+}
+
+wxSize wxGenericHyperlinkCtrl::DoGetBestClientSize() const
+{
+    wxClientDC dc((wxWindow *)this);
+    return dc.GetTextExtent(GetLabel());
 }
 
 
@@ -147,7 +153,7 @@ void wxGenericHyperlinkCtrl::SetVisitedColour(const wxColour &colour)
 void wxGenericHyperlinkCtrl::DoContextMenu(const wxPoint &pos)
 {
     wxMenu *menuPopUp = new wxMenu(wxEmptyString, wxMENU_TEAROFF);
-    menuPopUp->Append(wxHYPERLINK_POPUP_COPY_ID, wxT("Copy URL"));
+    menuPopUp->Append(wxHYPERLINK_POPUP_COPY_ID, _("&Copy URL"));
     PopupMenu( menuPopUp, pos );
     delete menuPopUp;
 }
@@ -184,6 +190,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)
@@ -195,7 +227,7 @@ void wxGenericHyperlinkCtrl::OnLeftDown(wxMouseEvent& event)
 void wxGenericHyperlinkCtrl::OnLeftUp(wxMouseEvent& event)
 {
     // the click must be started and ended in the hyperlink rect
-    if (!m_clicking || !GetLabelRect().Contains(event.GetPosition())) 
+    if (!m_clicking || !GetLabelRect().Contains(event.GetPosition()))
         return;
 
     SetForegroundColour(m_visitedColour);