]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/widgets/hyperlnk.cpp
Support using GetTextExtent() with empty string to get descent in wxOSX.
[wxWidgets.git] / samples / widgets / hyperlnk.cpp
index f93cc97acd9393c076fcbc34634673f986b0a03f..437dc9d5c2c44a140e8f4c1a3214472fa4fed751 100644 (file)
@@ -6,7 +6,7 @@
 // Created:     27 Sep 2003
 // Id:          $Id$
 // Copyright:   (c) 2003 wxWindows team
 // Created:     27 Sep 2003
 // Id:          $Id$
 // Copyright:   (c) 2003 wxWindows team
-// License:     wxWindows license
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 // ============================================================================
 /////////////////////////////////////////////////////////////////////////////
 
 // ============================================================================
@@ -93,6 +93,7 @@ protected:
 
     void OnButtonReset(wxCommandEvent& event);
     void OnAlignment(wxCommandEvent& event);
 
     void OnButtonReset(wxCommandEvent& event);
     void OnAlignment(wxCommandEvent& event);
+    void OnGeneric(wxCommandEvent& event);
 
     // reset the control parameters
     void Reset();
 
     // reset the control parameters
     void Reset();
@@ -105,8 +106,8 @@ protected:
     // ------------
 
     // the checkbox itself and the sizer it is in
     // ------------
 
     // 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;
 
     wxTextCtrl *m_label;
     wxTextCtrl *m_url;
@@ -118,6 +119,7 @@ protected:
     wxTextCtrl *m_textLabel;
 
     wxRadioBox *m_radioAlignMode;
     wxTextCtrl *m_textLabel;
 
     wxRadioBox *m_radioAlignMode;
+    wxCheckBox *m_checkGeneric;
 
 private:
     DECLARE_EVENT_TABLE()
 
 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_BUTTON(HyperlinkPage_SetURL, HyperlinkWidgetsPage::OnButtonSetURL)
 
     EVT_RADIOBOX(wxID_ANY, HyperlinkWidgetsPage::OnAlignment)
+    EVT_CHECKBOX(wxID_ANY, HyperlinkWidgetsPage::OnGeneric)
 END_EVENT_TABLE()
 
 // ============================================================================
 END_EVENT_TABLE()
 
 // ============================================================================
@@ -167,21 +170,23 @@ void HyperlinkWidgetsPage::CreateContent()
 
     static const wxString alignments[] =
     {
 
     static const wxString alignments[] =
     {
-        _T("&left"),
-        _T("&centre"),
-        _T("&right")
+        wxT("&left"),
+        wxT("&centre"),
+        wxT("&right")
     };
     wxCOMPILE_TIME_ASSERT( WXSIZEOF(alignments) == Align_Max,
                            AlignMismatch );
 
     };
     wxCOMPILE_TIME_ASSERT( WXSIZEOF(alignments) == Align_Max,
                            AlignMismatch );
 
-    m_radioAlignMode = new wxRadioBox(this, wxID_ANY, _T("alignment"),
+    m_radioAlignMode = new wxRadioBox(this, wxID_ANY, wxT("alignment"),
                                       wxDefaultPosition, wxDefaultSize,
                                       WXSIZEOF(alignments), alignments);
     m_radioAlignMode->SetSelection(1);  // start with "centre" selected since
                                         // wxHL_DEFAULT_STYLE contains wxHL_ALIGN_CENTRE
     sizerLeft->Add(m_radioAlignMode, 0, wxALL|wxGROW, 5);
 
                                       wxDefaultPosition, wxDefaultSize,
                                       WXSIZEOF(alignments), alignments);
     m_radioAlignMode->SetSelection(1);  // start with "centre" selected since
                                         // 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);
 
     // right pane
     wxSizer *szHyperlinkLong = new wxBoxSizer(wxVERTICAL);
@@ -189,10 +194,20 @@ void HyperlinkWidgetsPage::CreateContent()
 
     m_visit = new wxStaticText(this, wxID_ANY, wxT("Visit "));
 
 
     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!"));
 
 
     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);
 
     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);
 
     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();
 
     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);
 
     // 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;
 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);
 
     // update sizer's child window
     GetSizer()->Replace(m_hyperlinkLong, hyp, true);
@@ -304,7 +355,7 @@ void HyperlinkWidgetsPage::OnAlignment(wxCommandEvent& WXUNUSED(event))
     {
         default:
         case Align_Max:
     {
         default:
         case Align_Max:
-            wxFAIL_MSG( _T("unknown alignment") );
+            wxFAIL_MSG( wxT("unknown alignment") );
             // fall through
 
         case Align_Left:
             // fall through
 
         case Align_Left:
@@ -323,4 +374,10 @@ void HyperlinkWidgetsPage::OnAlignment(wxCommandEvent& WXUNUSED(event))
     CreateHyperlinkLong(addstyle);
 }
 
     CreateHyperlinkLong(addstyle);
 }
 
+void HyperlinkWidgetsPage::OnGeneric(wxCommandEvent& event)
+{
+    CreateHyperlink();
+    OnAlignment(event);
+}
+
 #endif // wxUSE_HYPERLINKCTRL
 #endif // wxUSE_HYPERLINKCTRL