]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/text/text.cpp
[ 1578466 ] Support for custom floating panes
[wxWidgets.git] / samples / text / text.cpp
index fe76bd993fcb8209d24be9a95ee721be5305e62f..8cadc01a1da86c181fe3a323ce5524bd42e7ce8f 100644 (file)
@@ -43,6 +43,7 @@
 #include "wx/colordlg.h"
 #include "wx/fontdlg.h"
 #include "wx/numdlg.h"
 #include "wx/colordlg.h"
 #include "wx/fontdlg.h"
 #include "wx/numdlg.h"
+#include "wx/tokenzr.h"
 
 //----------------------------------------------------------------------
 // class definitions
 
 //----------------------------------------------------------------------
 // class definitions
@@ -296,7 +297,12 @@ public:
 
     void OnSetText(wxCommandEvent& WXUNUSED(event))
     {
 
     void OnSetText(wxCommandEvent& WXUNUSED(event))
     {
-        m_panel->m_text->SetValue(_T("Hello, world (what else did you expect)?"));
+        m_panel->m_text->SetValue(_T("Hello, world! (what else did you expect?)"));
+    }
+
+    void OnChangeText(wxCommandEvent& WXUNUSED(event))
+    {
+        m_panel->m_text->ChangeValue(_T("Changed, not set: no event"));
     }
 
     void OnIdle( wxIdleEvent& event );
     }
 
     void OnIdle( wxIdleEvent& event );
@@ -348,6 +354,7 @@ public:
     void OnChangeBackgroundColour(wxCommandEvent& event);
     void OnLeftIndent(wxCommandEvent& event);
     void OnRightIndent(wxCommandEvent& event);
     void OnChangeBackgroundColour(wxCommandEvent& event);
     void OnLeftIndent(wxCommandEvent& event);
     void OnRightIndent(wxCommandEvent& event);
+    void OnTabStops(wxCommandEvent& event);
 
 private:
     wxTextCtrl *m_textCtrl;
 
 private:
     wxTextCtrl *m_textCtrl;
@@ -403,6 +410,7 @@ enum
     TEXT_REPLACE,
     TEXT_SELECT,
     TEXT_SET,
     TEXT_REPLACE,
     TEXT_SELECT,
     TEXT_SET,
+    TEXT_CHANGE,
 
     // log menu
     TEXT_LOG_KEY,
 
     // log menu
     TEXT_LOG_KEY,
@@ -468,6 +476,7 @@ bool MyApp::OnInit()
     menuText->Append(TEXT_REPLACE, _T("&Replace characters 4 to 8 with ABC\tCtrl-R"));
     menuText->Append(TEXT_SELECT, _T("&Select characters 4 to 8\tCtrl-I"));
     menuText->Append(TEXT_SET, _T("&Set the first text zone value\tCtrl-E"));
     menuText->Append(TEXT_REPLACE, _T("&Replace characters 4 to 8 with ABC\tCtrl-R"));
     menuText->Append(TEXT_SELECT, _T("&Select characters 4 to 8\tCtrl-I"));
     menuText->Append(TEXT_SET, _T("&Set the first text zone value\tCtrl-E"));
+    menuText->Append(TEXT_CHANGE, _T("&Change the first text zone value\tShift-Ctrl-E"));
     menuText->AppendSeparator();
     menuText->Append(TEXT_MOVE_ENDTEXT, _T("Move cursor to the end of &text"));
     menuText->Append(TEXT_MOVE_ENDENTRY, _T("Move cursor to the end of &entry"));
     menuText->AppendSeparator();
     menuText->Append(TEXT_MOVE_ENDTEXT, _T("Move cursor to the end of &text"));
     menuText->Append(TEXT_MOVE_ENDENTRY, _T("Move cursor to the end of &entry"));
@@ -782,15 +791,16 @@ void MyTextCtrl::OnText(wxCommandEvent& event)
         return;
 
     MyTextCtrl *win = (MyTextCtrl *)event.GetEventObject();
         return;
 
     MyTextCtrl *win = (MyTextCtrl *)event.GetEventObject();
+    const wxChar *changeVerb = win->IsModified() ? _T("changed")
+                                                 : _T("set by program");
     const wxChar *data = (const wxChar *)(win->GetClientData());
     if ( data )
     {
     const wxChar *data = (const wxChar *)(win->GetClientData());
     if ( data )
     {
-        wxLogMessage(_T("Text changed in control '%s'"), data);
+        wxLogMessage(_T("Text %s in control \"%s\""), changeVerb, data);
     }
     else
     {
     }
     else
     {
-        // wxLogMessage( event.GetString() );
-        wxLogMessage(_T("Text changed in some control"));
+        wxLogMessage(_T("Text %s in some control"), changeVerb);
     }
 }
 
     }
 }
 
@@ -944,7 +954,7 @@ void MyTextCtrl::OnKeyDown(wxKeyEvent& event)
         case WXK_F6:
             wxLogMessage(_T("IsModified() before SetValue(): %d"),
                          IsModified());
         case WXK_F6:
             wxLogMessage(_T("IsModified() before SetValue(): %d"),
                          IsModified());
-            SetValue(_T("SetValue() has been called"));
+            ChangeValue(_T("ChangeValue() has been called"));
             wxLogMessage(_T("IsModified() after SetValue(): %d"),
                          IsModified());
             break;
             wxLogMessage(_T("IsModified() after SetValue(): %d"),
                          IsModified());
             break;
@@ -966,6 +976,11 @@ void MyTextCtrl::OnKeyDown(wxKeyEvent& event)
         case WXK_F10:
             AppendText(_T("AppendText() has been called"));
             break;
         case WXK_F10:
             AppendText(_T("AppendText() has been called"));
             break;
+
+        case WXK_F11:
+            DiscardEdits();
+            wxLogMessage(_T("Control marked as non modified"));
+            break;
     }
 
     if ( ms_logKey )
     }
 
     if ( ms_logKey )
@@ -1325,10 +1340,11 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
     EVT_MENU(TEXT_PAGE_DOWN,          MyFrame::OnScrollPageDown)
     EVT_MENU(TEXT_PAGE_UP,            MyFrame::OnScrollPageUp)
 
     EVT_MENU(TEXT_PAGE_DOWN,          MyFrame::OnScrollPageDown)
     EVT_MENU(TEXT_PAGE_UP,            MyFrame::OnScrollPageUp)
 
-    EVT_MENU(TEXT_GET_LINE,            MyFrame::OnGetLine)
-    EVT_MENU(TEXT_GET_LINELENGTH,            MyFrame::OnGetLineLength)
+    EVT_MENU(TEXT_GET_LINE,           MyFrame::OnGetLine)
+    EVT_MENU(TEXT_GET_LINELENGTH,     MyFrame::OnGetLineLength)
 
     EVT_MENU(TEXT_SET,                MyFrame::OnSetText)
 
     EVT_MENU(TEXT_SET,                MyFrame::OnSetText)
+    EVT_MENU(TEXT_CHANGE,             MyFrame::OnChangeText)
 
     EVT_IDLE(MyFrame::OnIdle)
 END_EVENT_TABLE()
 
     EVT_IDLE(MyFrame::OnIdle)
 END_EVENT_TABLE()
@@ -1507,7 +1523,8 @@ enum
     RICHTEXT_CHANGE_TEXT_COLOUR,
     RICHTEXT_CHANGE_BACKGROUND_COLOUR,
     RICHTEXT_LEFT_INDENT,
     RICHTEXT_CHANGE_TEXT_COLOUR,
     RICHTEXT_CHANGE_BACKGROUND_COLOUR,
     RICHTEXT_LEFT_INDENT,
-    RICHTEXT_RIGHT_INDENT
+    RICHTEXT_RIGHT_INDENT,
+    RICHTEXT_TAB_STOPS
 };
 
 BEGIN_EVENT_TABLE(RichTextFrame, wxFrame)
 };
 
 BEGIN_EVENT_TABLE(RichTextFrame, wxFrame)
@@ -1522,6 +1539,7 @@ BEGIN_EVENT_TABLE(RichTextFrame, wxFrame)
     EVT_MENU(RICHTEXT_CHANGE_BACKGROUND_COLOUR, RichTextFrame::OnChangeBackgroundColour)
     EVT_MENU(RICHTEXT_LEFT_INDENT, RichTextFrame::OnLeftIndent)
     EVT_MENU(RICHTEXT_RIGHT_INDENT, RichTextFrame::OnRightIndent)
     EVT_MENU(RICHTEXT_CHANGE_BACKGROUND_COLOUR, RichTextFrame::OnChangeBackgroundColour)
     EVT_MENU(RICHTEXT_LEFT_INDENT, RichTextFrame::OnLeftIndent)
     EVT_MENU(RICHTEXT_RIGHT_INDENT, RichTextFrame::OnRightIndent)
+    EVT_MENU(RICHTEXT_TAB_STOPS, RichTextFrame::OnTabStops)
 END_EVENT_TABLE()
 
 RichTextFrame::RichTextFrame(wxWindow* parent, const wxString& title):
 END_EVENT_TABLE()
 
 RichTextFrame::RichTextFrame(wxWindow* parent, const wxString& title):
@@ -1560,7 +1578,8 @@ RichTextFrame::RichTextFrame(wxWindow* parent, const wxString& title):
     editMenu->Append(RICHTEXT_CHANGE_BACKGROUND_COLOUR, _("Change Background Colour"));
     editMenu->AppendSeparator();
     editMenu->Append(RICHTEXT_LEFT_INDENT, _("Left Indent"));
     editMenu->Append(RICHTEXT_CHANGE_BACKGROUND_COLOUR, _("Change Background Colour"));
     editMenu->AppendSeparator();
     editMenu->Append(RICHTEXT_LEFT_INDENT, _("Left Indent"));
-    editMenu->Append(RICHTEXT_RIGHT_INDENT, _("Right indent"));
+    editMenu->Append(RICHTEXT_RIGHT_INDENT, _("Right Indent"));
+    editMenu->Append(RICHTEXT_TAB_STOPS, _("Tab Stops"));
     menuBar->Append(editMenu, _("Edit"));
 
     SetMenuBar(menuBar);
     menuBar->Append(editMenu, _("Edit"));
 
     SetMenuBar(menuBar);
@@ -1752,6 +1771,35 @@ void RichTextFrame::OnRightIndent(wxCommandEvent& WXUNUSED(event))
     }
 }
 
     }
 }
 
+void RichTextFrame::OnTabStops(wxCommandEvent& WXUNUSED(event))
+{
+    wxString tabsStr = wxGetTextFromUser
+                         (
+                            _("Please enter the tab stop positions in tenths of a millimetre, separated by spaces.\nLeave empty to reset tab stops."),
+                            _("Tab Stops"),
+                            wxEmptyString,
+                            this
+                         );
+
+    wxArrayInt tabs;
+
+    wxStringTokenizer tokens(tabsStr, _T(" "));
+    while (tokens.HasMoreTokens())
+    {
+        wxString token = tokens.GetNextToken();
+        tabs.Add(wxAtoi(token));
+    }
+
+    wxTextAttr attr;
+    attr.SetTabs(tabs);
+
+    long start, end;
+    m_textCtrl->GetSelection(& start, & end);
+    m_textCtrl->SetStyle(start, end, attr);
+
+    m_currentPosition = -1;
+}
+
 void RichTextFrame::OnIdle(wxIdleEvent& WXUNUSED(event))
 {
     long insertionPoint = m_textCtrl->GetInsertionPoint();
 void RichTextFrame::OnIdle(wxIdleEvent& WXUNUSED(event))
 {
     long insertionPoint = m_textCtrl->GetInsertionPoint();