]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/widgets/widgets.cpp
Correct example in wxStringBufferLength documentation.
[wxWidgets.git] / samples / widgets / widgets.cpp
index 19d86f02e3d752860886b995aeb3f85146404869..0551340bdd1055b188b71e2c641f1a8db1640390 100644 (file)
@@ -97,6 +97,8 @@ enum
     TextEntry_DisableAutoComplete = TextEntry_Begin,
     TextEntry_AutoCompleteFixed,
     TextEntry_AutoCompleteFilenames,
+
+    TextEntry_SetHint,
     TextEntry_End
 };
 
@@ -164,10 +166,13 @@ protected:
     void OnToggleGlobalBusyCursor(wxCommandEvent& event);
     void OnToggleBusyCursor(wxCommandEvent& event);
 
+    // wxTextEntry-specific tests
     void OnDisableAutoComplete(wxCommandEvent& event);
     void OnAutoCompleteFixed(wxCommandEvent& event);
     void OnAutoCompleteFilenames(wxCommandEvent& event);
 
+    void OnSetHint(wxCommandEvent& event);
+
     void OnUpdateTextUI(wxUpdateUIEvent& event)
     {
         event.Enable( CurrentPage()->GetTextEntry() != NULL );
@@ -225,29 +230,14 @@ public:
 
 private:
     // implement sink functions
-    virtual void DoLog(wxLogLevel level, const wxString& str, time_t t)
+    virtual void DoLogTextAtLevel(wxLogLevel level, const wxString& msg)
     {
-        // don't put trace messages into listbox or we can get into infinite
-        // recursion
         if ( level == wxLOG_Trace )
         {
             if ( m_logOld )
-            {
-                // cast is needed to call protected method
-                ((LboxLogger *)m_logOld)->DoLog(level, str, t);
-            }
-        }
-        else
-        {
-            wxLog::DoLog(level, str, t);
+                m_logOld->LogTextAtLevel(level, msg);
+            return;
         }
-    }
-
-    virtual void DoLogString(const wxString& str, time_t WXUNUSED(t))
-    {
-        wxString msg;
-        TimeStamp(&msg);
-        msg += str;
 
         #ifdef __WXUNIVERSAL__
             m_lbox->AppendAndEnsureVisible(msg);
@@ -308,6 +298,8 @@ BEGIN_EVENT_TABLE(WidgetsFrame, wxFrame)
     EVT_MENU(TextEntry_AutoCompleteFixed,     WidgetsFrame::OnAutoCompleteFixed)
     EVT_MENU(TextEntry_AutoCompleteFilenames, WidgetsFrame::OnAutoCompleteFilenames)
 
+    EVT_MENU(TextEntry_SetHint, WidgetsFrame::OnSetHint)
+
     EVT_UPDATE_UI_RANGE(TextEntry_Begin, TextEntry_End - 1,
                         WidgetsFrame::OnUpdateTextUI)
 
@@ -419,6 +411,8 @@ WidgetsFrame::WidgetsFrame(const wxString& title)
                                    _T("Fixed-&list auto-completion"));
     menuTextEntry->AppendRadioItem(TextEntry_AutoCompleteFilenames,
                                    _T("&Files names auto-completion"));
+    menuTextEntry->AppendSeparator();
+    menuTextEntry->Append(TextEntry_SetHint, "Set help &hint");
 
     mbar->Append(menuTextEntry, _T("&Text"));
 
@@ -910,9 +904,13 @@ void WidgetsFrame::OnDisableAutoComplete(wxCommandEvent& WXUNUSED(event))
     wxCHECK_RET( entry, "menu item should be disabled" );
 
     if ( entry->AutoComplete(wxArrayString()) )
+    {
         wxLogMessage("Disabled auto completion.");
+    }
     else
+    {
         wxLogMessage("AutoComplete() failed.");
+    }
 }
 
 void WidgetsFrame::OnAutoCompleteFixed(wxCommandEvent& WXUNUSED(event))
@@ -932,9 +930,13 @@ void WidgetsFrame::OnAutoCompleteFixed(wxCommandEvent& WXUNUSED(event))
     completion_choices.push_back("this string is for test");
 
     if ( entry->AutoComplete(completion_choices) )
+    {
         wxLogMessage("Enabled auto completion of a set of fixed strings.");
+    }
     else
+    {
         wxLogMessage("AutoComplete() failed.");
+    }
 }
 
 void WidgetsFrame::OnAutoCompleteFilenames(wxCommandEvent& WXUNUSED(event))
@@ -943,9 +945,36 @@ void WidgetsFrame::OnAutoCompleteFilenames(wxCommandEvent& WXUNUSED(event))
     wxCHECK_RET( entry, "menu item should be disabled" );
 
     if ( entry->AutoCompleteFileNames() )
+    {
         wxLogMessage("Enable auto completion of file names.");
+    }
     else
+    {
         wxLogMessage("AutoCompleteFileNames() failed.");
+    }
+}
+
+void WidgetsFrame::OnSetHint(wxCommandEvent& WXUNUSED(event))
+{
+    wxTextEntryBase *entry = CurrentPage()->GetTextEntry();
+    wxCHECK_RET( entry, "menu item should be disabled" );
+
+    static wxString s_hint("Type here");
+    wxString
+        hint = wxGetTextFromUser("Text hint:", "Widgets sample", s_hint, this);
+    if ( hint.empty() )
+        return;
+
+    s_hint = hint;
+
+    if ( entry->SetHint(hint) )
+    {
+        wxLogMessage("Set hint to \"%s\".", hint);
+    }
+    else
+    {
+        wxLogMessage("Text hints not supported.");
+    }
 }
 
 #endif // wxUSE_MENUS