]> git.saurik.com Git - wxWidgets.git/commitdiff
Generic wxHyperlinkCtrl appearance and behaviour improvements.
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 15 Jun 2011 21:56:23 +0000 (21:56 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 15 Jun 2011 21:56:23 +0000 (21:56 +0000)
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

docs/changes.txt
include/wx/generic/hyperlink.h
samples/widgets/hyperlnk.cpp
src/generic/hyperlinkg.cpp

index 85f86d24c1f117f28279bc5b4d749120b400e4f6..a3fa1d5894d7a584ef7f67dd8a292ed2afe59a90 100644 (file)
@@ -508,6 +508,7 @@ All (GUI):
 - Allow customizing AUI tab colours in wxAuiTabArt (snowleopard).
 - Added wxAffineMatrix2D class (Catalin Raceanu).
 - Allow showing preview frame non modally (John Roberts).
+- Improve appearance of the generic wxHyperlinkCtrl (David Connet).
 
 GTK:
 
index 9146ba8ada126f20b044524fd51f5f48876b3fe4..c148dba91b096ff1616692f7a4ee3fc54844070d 100644 (file)
@@ -75,6 +75,12 @@ protected:
     // Renders the hyperlink.
     void OnPaint(wxPaintEvent& event);
 
+    // Handle set/kill focus events (invalidate for painting focus rect)
+    void OnFocus(wxFocusEvent& event);
+
+    // Fire a HyperlinkEvent on space
+    void OnChar(wxKeyEvent& event);
+
     // Returns the wxRect of the label of this hyperlink.
     // This is different from the clientsize's rectangle when
     // clientsize != bestsize and this rectangle is influenced
index 8c13a685755ed1baafe8f1decb5b1ce17917f297..437dc9d5c2c44a140e8f4c1a3214472fa4fed751 100644 (file)
@@ -93,6 +93,7 @@ protected:
 
     void OnButtonReset(wxCommandEvent& event);
     void OnAlignment(wxCommandEvent& event);
+    void OnGeneric(wxCommandEvent& event);
 
     // reset the control parameters
     void Reset();
@@ -105,8 +106,8 @@ protected:
     // ------------
 
     // the checkbox itself and the sizer it is in
-    wxHyperlinkCtrl *m_hyperlink;
-    wxHyperlinkCtrl *m_hyperlinkLong;
+    wxGenericHyperlinkCtrl *m_hyperlink;
+    wxGenericHyperlinkCtrl *m_hyperlinkLong;
 
     wxTextCtrl *m_label;
     wxTextCtrl *m_url;
@@ -118,6 +119,7 @@ protected:
     wxTextCtrl *m_textLabel;
 
     wxRadioBox *m_radioAlignMode;
+    wxCheckBox *m_checkGeneric;
 
 private:
     DECLARE_EVENT_TABLE()
@@ -134,6 +136,7 @@ BEGIN_EVENT_TABLE(HyperlinkWidgetsPage, WidgetsPage)
     EVT_BUTTON(HyperlinkPage_SetURL, HyperlinkWidgetsPage::OnButtonSetURL)
 
     EVT_RADIOBOX(wxID_ANY, HyperlinkWidgetsPage::OnAlignment)
+    EVT_CHECKBOX(wxID_ANY, HyperlinkWidgetsPage::OnGeneric)
 END_EVENT_TABLE()
 
 // ============================================================================
@@ -181,7 +184,9 @@ void HyperlinkWidgetsPage::CreateContent()
                                         // wxHL_DEFAULT_STYLE contains wxHL_ALIGN_CENTRE
     sizerLeft->Add(m_radioAlignMode, 0, wxALL|wxGROW, 5);
 
-
+    m_checkGeneric = new wxCheckBox(this, wxID_ANY, wxT("Use generic version"),
+                                    wxDefaultPosition, wxDefaultSize);
+    sizerLeft->Add(m_checkGeneric, 0, wxALL|wxGROW, 5);
 
     // right pane
     wxSizer *szHyperlinkLong = new wxBoxSizer(wxVERTICAL);
@@ -189,10 +194,20 @@ void HyperlinkWidgetsPage::CreateContent()
 
     m_visit = new wxStaticText(this, wxID_ANY, wxT("Visit "));
 
-    m_hyperlink = new wxHyperlinkCtrl(this,
-                                      HyperlinkPage_Ctrl,
-                                      wxT("wxWidgets website"),
-                                      wxT("www.wxwidgets.org"));
+    if (m_checkGeneric->IsChecked())
+    {
+        m_hyperlink = new wxGenericHyperlinkCtrl(this,
+                                          HyperlinkPage_Ctrl,
+                                          wxT("wxWidgets website"),
+                                          wxT("www.wxwidgets.org"));
+    }
+    else
+    {
+        m_hyperlink = new wxHyperlinkCtrl(this,
+                                          HyperlinkPage_Ctrl,
+                                          wxT("wxWidgets website"),
+                                          wxT("www.wxwidgets.org"));
+    }
 
     m_fun = new wxStaticText(this, wxID_ANY, wxT(" for fun!"));
 
@@ -203,10 +218,20 @@ void HyperlinkWidgetsPage::CreateContent()
     szHyperlink->Add(0, 0, 1, wxCENTRE);
     szHyperlink->SetMinSize(150, 0);
 
-    m_hyperlinkLong = new wxHyperlinkCtrl(this,
-                                          wxID_ANY,
-                                          wxT("This is a long hyperlink"),
-                                          wxT("www.wxwidgets.org"));
+    if (m_checkGeneric->IsChecked())
+    {
+        m_hyperlinkLong = new wxGenericHyperlinkCtrl(this,
+                                              wxID_ANY,
+                                              wxT("This is a long hyperlink"),
+                                              wxT("www.wxwidgets.org"));
+    }
+    else
+    {
+        m_hyperlinkLong = new wxHyperlinkCtrl(this,
+                                              wxID_ANY,
+                                              wxT("This is a long hyperlink"),
+                                              wxT("www.wxwidgets.org"));
+    }
 
     szHyperlinkLong->Add(0, 0, 1, wxCENTRE);
     szHyperlinkLong->Add(szHyperlink, 0, wxCENTRE|wxGROW);
@@ -236,10 +261,21 @@ void HyperlinkWidgetsPage::CreateHyperlink()
     const wxString label = m_hyperlink->GetLabel();
     const wxString url = m_hyperlink->GetURL();
 
-    wxHyperlinkCtrl *hyp = new wxHyperlinkCtrl(this,
-                                               HyperlinkPage_Ctrl,
-                                               label,
-                                               url);
+    wxGenericHyperlinkCtrl *hyp;
+    if (m_checkGeneric->IsChecked())
+    {
+        hyp = new wxGenericHyperlinkCtrl(this,
+                                  HyperlinkPage_Ctrl,
+                                  label,
+                                  url);
+    }
+    else
+    {
+        hyp = new wxHyperlinkCtrl(this,
+                                  HyperlinkPage_Ctrl,
+                                  label,
+                                  url);
+    }
 
     // update sizer's child window
     GetSizer()->Replace(m_hyperlink, hyp, true);
@@ -255,13 +291,28 @@ void HyperlinkWidgetsPage::CreateHyperlink()
 void HyperlinkWidgetsPage::CreateHyperlinkLong(long style)
 {
     style = (wxHL_DEFAULT_STYLE & ~wxHL_ALIGN_CENTRE)|style;
-    wxHyperlinkCtrl *hyp = new wxHyperlinkCtrl(this,
-                                               wxID_ANY,
-                                               wxT("This is a long hyperlink"),
-                                               wxT("www.wxwidgets.org"),
-                                               wxDefaultPosition,
-                                               wxDefaultSize,
-                                               style);
+
+    wxGenericHyperlinkCtrl *hyp;
+    if (m_checkGeneric->IsChecked())
+    {
+        hyp = new wxGenericHyperlinkCtrl(this,
+                                  wxID_ANY,
+                                  wxT("This is a long hyperlink"),
+                                  wxT("www.wxwidgets.org"),
+                                  wxDefaultPosition,
+                                  wxDefaultSize,
+                                  style);
+    }
+    else
+    {
+        hyp = new wxHyperlinkCtrl(this,
+                                  wxID_ANY,
+                                  wxT("This is a long hyperlink"),
+                                  wxT("www.wxwidgets.org"),
+                                  wxDefaultPosition,
+                                  wxDefaultSize,
+                                  style);
+    }
 
     // update sizer's child window
     GetSizer()->Replace(m_hyperlinkLong, hyp, true);
@@ -323,4 +374,10 @@ void HyperlinkWidgetsPage::OnAlignment(wxCommandEvent& WXUNUSED(event))
     CreateHyperlinkLong(addstyle);
 }
 
+void HyperlinkWidgetsPage::OnGeneric(wxCommandEvent& event)
+{
+    CreateHyperlink();
+    OnAlignment(event);
+}
+
 #endif // wxUSE_HYPERLINKCTRL
index fb8bc57ba1638395300d04d8ee076dea633c4832..257e6ef67fb51927241bd2b439105b910a4dffc6 100644 (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)