]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/text/text.cpp
Documented tbar95.cpp backports
[wxWidgets.git] / samples / text / text.cpp
index 7ddeaa84238beff4c90d3302df51ae0b94df1c47..3f699879570429c9dfe41ba9f46f3f88353414ed 100644 (file)
@@ -8,10 +8,6 @@
 // Licence:     wxWindows license
 /////////////////////////////////////////////////////////////////////////////
 
-#ifdef __GNUG__
-    #pragma implementation "text.cpp"
-#endif
-
 // For compilers that support precompilation, includes "wx/wx.h".
 #include "wx/wxprec.h"
 
@@ -153,47 +149,47 @@ public:
 #endif // wxUSE_TOOLTIPS
 
 #if wxUSE_CLIPBOARD
-    void OnPasteFromClipboard( wxCommandEvent &event )
+    void OnPasteFromClipboard( wxCommandEvent& WXUNUSED(event) )
         { m_panel->DoPasteFromClipboard(); }
-    void OnCopyToClipboard( wxCommandEvent &event )
+    void OnCopyToClipboard( wxCommandEvent& WXUNUSED(event) )
         { m_panel->DoCopyToClipboard(); }
 #endif // wxUSE_CLIPBOARD
 
-    void OnAddTextFreeze( wxCommandEvent& event )
+    void OnAddTextFreeze( wxCommandEvent& WXUNUSED(event) )
         { DoAddText(true); }
-    void OnAddText( wxCommandEvent& event )
+    void OnAddText( wxCommandEvent& WXUNUSED(event) )
         { DoAddText(false); }
-    void OnRemoveText( wxCommandEvent& event )
+    void OnRemoveText( wxCommandEvent& WXUNUSED(event) )
         { m_panel->DoRemoveText(); }
-    void OnReplaceText( wxCommandEvent& event )
+    void OnReplaceText( wxCommandEvent& WXUNUSED(event) )
         { m_panel->DoReplaceText(); }
-    void OnSelectText( wxCommandEvent& event )
+    void OnSelectText( wxCommandEvent& WXUNUSED(event) )
         { m_panel->DoSelectText(); }
 
-    void OnMoveToEndOfText( wxCommandEvent &event )
+    void OnMoveToEndOfText( wxCommandEvent& WXUNUSED(event) )
         { m_panel->DoMoveToEndOfText(); }
-    void OnMoveToEndOfEntry( wxCommandEvent &event )
+    void OnMoveToEndOfEntry( wxCommandEvent& WXUNUSED(event) )
         { m_panel->DoMoveToEndOfEntry(); }
 
-    void OnScrollLineDown(wxCommandEvent& event)
+    void OnScrollLineDown(wxCommandEvent& WXUNUSED(event))
     {
         if ( !m_panel->m_textrich->LineDown() )
             wxLogMessage(_T("Already at the bottom"));
     }
 
-    void OnScrollLineUp(wxCommandEvent& event)
+    void OnScrollLineUp(wxCommandEvent& WXUNUSED(event))
     {
         if ( !m_panel->m_textrich->LineUp() )
             wxLogMessage(_T("Already at the top"));
     }
 
-    void OnScrollPageDown(wxCommandEvent& event)
+    void OnScrollPageDown(wxCommandEvent& WXUNUSED(event))
     {
         if ( !m_panel->m_textrich->PageDown() )
             wxLogMessage(_T("Already at the bottom"));
     }
 
-    void OnScrollPageUp(wxCommandEvent& event)
+    void OnScrollPageUp(wxCommandEvent& WXUNUSED(event))
     {
         if ( !m_panel->m_textrich->PageUp() )
             wxLogMessage(_T("Already at the top"));
@@ -232,7 +228,7 @@ public:
         MyTextCtrl::ms_logFocus = event.IsChecked();
     }
 
-    void OnSetText(wxCommandEvent& event)
+    void OnSetText(wxCommandEvent& WXUNUSED(event))
     {
         m_panel->m_text->SetValue(_T("Hello, world (what else did you expect)?"));
     }
@@ -276,6 +272,7 @@ public:
 // Event handlers
 
     void OnClose(wxCommandEvent& event);
+    void OnIdle(wxIdleEvent& event);
     void OnLeftAlign(wxCommandEvent& event);
     void OnRightAlign(wxCommandEvent& event);
     void OnJustify(wxCommandEvent& event);
@@ -288,6 +285,7 @@ public:
 
 private:
     wxTextCtrl *m_textCtrl;
+    long m_currentPosition;
 
     DECLARE_EVENT_TABLE()
 };
@@ -698,7 +696,7 @@ void MyTextCtrl::OnText(wxCommandEvent& event)
     }
 }
 
-void MyTextCtrl::OnTextMaxLen(wxCommandEvent& event)
+void MyTextCtrl::OnTextMaxLen(wxCommandEvent& WXUNUSED(event))
 {
     wxLogMessage(_T("You can't enter more characters into this control."));
 }
@@ -926,17 +924,13 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
       wxPoint(180,170), wxSize(240,70), wxTE_MULTILINE);
     m_enter->SetClientData((void *)_T("enter"));
 
-#if 0
     m_textrich = new MyTextCtrl(this, -1, _T("Allows more than 30Kb of text\n")
                                 _T("(even under broken Win9x)\n")
                                 _T("and a very very very very very ")
                                 _T("very very very long line to test ")
                                 _T("wxHSCROLL style"),
                                 wxPoint(450, 10), wxSize(230, 230),
-                                wxTE_RICH2 |
-                                wxTE_MULTILINE |
-                                // wxTE_AUTO_URL |
-                                wxHSCROLL);
+                                wxTE_RICH | wxTE_MULTILINE | wxHSCROLL);
     m_textrich->SetStyle(0, 10, *wxRED);
     m_textrich->SetStyle(10, 20, *wxBLUE);
     m_textrich->SetStyle(30, 40,
@@ -951,19 +945,13 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
     m_textrich->SetDefaultStyle(wxTextAttr(*wxBLUE, *wxWHITE));
     m_textrich->AppendText(_T("And this should be in blue and the text you ")
                            _T("type should be in blue as well"));
-#else
-    m_textrich = new MyTextCtrl(this, -1, _T(""),
-                                wxPoint(450, 10), wxSize(230, 230),
-                                wxTE_RICH2 |
-                                wxTE_MULTILINE |
-                                wxHSCROLL);
-#endif
 }
 
 void MyPanel::OnSize( wxSizeEvent &event )
 {
     wxSize client_area( GetClientSize() );
-    m_log->SetSize( 0, 260, client_area.x, client_area.y - 260 );
+    if (m_log)
+      m_log->SetSize( 0, 260, client_area.x, client_area.y - 260 );
     event.Skip();
 }
 
@@ -1172,7 +1160,8 @@ void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) )
 }
 
 #if wxUSE_TOOLTIPS
-void MyFrame::OnSetTooltipDelay(wxCommandEvent& event)
+
+void MyFrame::OnSetTooltipDelay(wxCommandEvent& WXUNUSED(event))
 {
     static long s_delay = 5000;
 
@@ -1193,7 +1182,7 @@ void MyFrame::OnSetTooltipDelay(wxCommandEvent& event)
     wxLogStatus(this, _T("Tooltip delay set to %ld milliseconds"), s_delay);
 }
 
-void MyFrame::OnToggleTooltips(wxCommandEvent& event)
+void MyFrame::OnToggleTooltips(wxCommandEvent& WXUNUSED(event))
 {
     static bool s_enabled = TRUE;
 
@@ -1234,7 +1223,7 @@ void MyFrame::OnSetEnabled(wxCommandEvent& WXUNUSED(event))
     m_panel->m_textrich->Enable(enabled);
 }
 
-void MyFrame::OnFileSave(wxCommandEvent& event)
+void MyFrame::OnFileSave(wxCommandEvent& WXUNUSED(event))
 {
     if ( m_panel->m_textrich->SaveFile(_T("dummy.txt")) )
     {
@@ -1251,7 +1240,7 @@ void MyFrame::OnFileSave(wxCommandEvent& event)
         wxLogStatus(this, _T("Couldn't save the file"));
 }
 
-void MyFrame::OnFileLoad(wxCommandEvent& event)
+void MyFrame::OnFileLoad(wxCommandEvent& WXUNUSED(event))
 {
     if ( m_panel->m_textrich->LoadFile(_T("dummy.txt")) )
         wxLogStatus(this, _T("Successfully loaded file"));
@@ -1259,7 +1248,7 @@ void MyFrame::OnFileLoad(wxCommandEvent& event)
         wxLogStatus(this, _T("Couldn't load the file"));
 }
 
-void MyFrame::OnRichTextTest(wxCommandEvent& event)
+void MyFrame::OnRichTextTest(wxCommandEvent& WXUNUSED(event))
 {
     RichTextFrame* frame = new RichTextFrame(this, _T("Rich Text Editor"));
     frame->Show(TRUE);
@@ -1311,6 +1300,7 @@ enum
 };
 
 BEGIN_EVENT_TABLE(RichTextFrame, wxFrame)
+    EVT_IDLE(RichTextFrame::OnIdle)
     EVT_MENU(RICHTEXT_CLOSE, RichTextFrame::OnClose)
     EVT_MENU(RICHTEXT_LEFT_ALIGN, RichTextFrame::OnLeftAlign)
     EVT_MENU(RICHTEXT_RIGHT_ALIGN, RichTextFrame::OnRightAlign)
@@ -1326,6 +1316,7 @@ END_EVENT_TABLE()
 RichTextFrame::RichTextFrame(wxWindow* parent, const wxString& title):
     wxFrame(parent, -1, title, wxDefaultPosition, wxSize(300, 400))
 {
+    m_currentPosition = -1;
     m_textCtrl = new wxTextCtrl(this, -1, wxEmptyString, wxDefaultPosition,
             wxDefaultSize, wxTE_MULTILINE|wxTE_RICH2);
 
@@ -1362,16 +1353,17 @@ RichTextFrame::RichTextFrame(wxWindow* parent, const wxString& title):
     menuBar->Append(editMenu, _("Edit"));
 
     SetMenuBar(menuBar);
+    CreateStatusBar();
 }
 
 // Event handlers
 
-void RichTextFrame::OnClose(wxCommandEvent& event)
+void RichTextFrame::OnClose(wxCommandEvent& WXUNUSED(event))
 {
     Close(TRUE);
 }
 
-void RichTextFrame::OnLeftAlign(wxCommandEvent& event)
+void RichTextFrame::OnLeftAlign(wxCommandEvent& WXUNUSED(event))
 {
     wxTextAttr attr;
     attr.SetAlignment(wxTEXT_ALIGNMENT_LEFT);
@@ -1379,9 +1371,11 @@ void RichTextFrame::OnLeftAlign(wxCommandEvent& event)
     long start, end;
     m_textCtrl->GetSelection(& start, & end);
     m_textCtrl->SetStyle(start, end, attr);
+
+    m_currentPosition = -1;
 }
 
-void RichTextFrame::OnRightAlign(wxCommandEvent& event)
+void RichTextFrame::OnRightAlign(wxCommandEvent& WXUNUSED(event))
 {
     wxTextAttr attr;
     attr.SetAlignment(wxTEXT_ALIGNMENT_RIGHT);
@@ -1389,9 +1383,11 @@ void RichTextFrame::OnRightAlign(wxCommandEvent& event)
     long start, end;
     m_textCtrl->GetSelection(& start, & end);
     m_textCtrl->SetStyle(start, end, attr);
+
+    m_currentPosition = -1;
 }
 
-void RichTextFrame::OnJustify(wxCommandEvent& event)
+void RichTextFrame::OnJustify(wxCommandEvent& WXUNUSED(event))
 {
     wxTextAttr attr;
     attr.SetAlignment(wxTEXT_ALIGNMENT_JUSTIFIED);
@@ -1399,9 +1395,11 @@ void RichTextFrame::OnJustify(wxCommandEvent& event)
     long start, end;
     m_textCtrl->GetSelection(& start, & end);
     m_textCtrl->SetStyle(start, end, attr);
+
+    m_currentPosition = -1;
 }
 
-void RichTextFrame::OnCentre(wxCommandEvent& event)
+void RichTextFrame::OnCentre(wxCommandEvent& WXUNUSED(event))
 {
     wxTextAttr attr;
     attr.SetAlignment(wxTEXT_ALIGNMENT_CENTRE);
@@ -1409,9 +1407,11 @@ void RichTextFrame::OnCentre(wxCommandEvent& event)
     long start, end;
     m_textCtrl->GetSelection(& start, & end);
     m_textCtrl->SetStyle(start, end, attr);
+
+    m_currentPosition = -1;
 }
 
-void RichTextFrame::OnChangeFont(wxCommandEvent& event)
+void RichTextFrame::OnChangeFont(wxCommandEvent& WXUNUSED(event))
 {
     wxFontData data;
 
@@ -1428,10 +1428,12 @@ void RichTextFrame::OnChangeFont(wxCommandEvent& event)
         long start, end;
         m_textCtrl->GetSelection(& start, & end);
         m_textCtrl->SetStyle(start, end, attr);
+
+        m_currentPosition = -1;
     }
 }
 
-void RichTextFrame::OnChangeTextColour(wxCommandEvent& event)
+void RichTextFrame::OnChangeTextColour(wxCommandEvent& WXUNUSED(event))
 {
     wxColourData data;
     data.SetColour(* wxBLACK);
@@ -1455,10 +1457,12 @@ void RichTextFrame::OnChangeTextColour(wxCommandEvent& event)
         long start, end;
         m_textCtrl->GetSelection(& start, & end);
         m_textCtrl->SetStyle(start, end, attr);
+
+        m_currentPosition = -1;
     }
 }
 
-void RichTextFrame::OnChangeBackgroundColour(wxCommandEvent& event)
+void RichTextFrame::OnChangeBackgroundColour(wxCommandEvent& WXUNUSED(event))
 {
     wxColourData data;
     data.SetColour(* wxWHITE);
@@ -1482,13 +1486,18 @@ void RichTextFrame::OnChangeBackgroundColour(wxCommandEvent& event)
         long start, end;
         m_textCtrl->GetSelection(& start, & end);
         m_textCtrl->SetStyle(start, end, attr);
+
+        m_currentPosition = -1;
     }
 }
 
-void RichTextFrame::OnLeftIndent(wxCommandEvent& event)
+void RichTextFrame::OnLeftIndent(wxCommandEvent& WXUNUSED(event))
 {
-    wxString indentStr = wxGetTextFromUser(_("Please enter the left indent in tenths of a millimetre."),
-        _("Left Indent"));
+    wxString indentStr = wxGetTextFromUser
+                         (
+                            _("Please enter the left indent in tenths of a millimetre."),
+                            _("Left Indent")
+                         );
     if (!indentStr.IsEmpty())
     {
         int indent = wxAtoi(indentStr);
@@ -1499,13 +1508,18 @@ void RichTextFrame::OnLeftIndent(wxCommandEvent& event)
         long start, end;
         m_textCtrl->GetSelection(& start, & end);
         m_textCtrl->SetStyle(start, end, attr);
+
+        m_currentPosition = -1;
     }
 }
 
-void RichTextFrame::OnRightIndent(wxCommandEvent& event)
+void RichTextFrame::OnRightIndent(wxCommandEvent& WXUNUSED(event))
 {
-    wxString indentStr = wxGetTextFromUser(_("Please enter the right indent in tenths of a millimetre."),
-        _("Right Indent"));
+    wxString indentStr = wxGetTextFromUser
+                         (
+                            _("Please enter the right indent in tenths of a millimetre."),
+                            _("Right Indent")
+                         );
     if (!indentStr.IsEmpty())
     {
         int indent = wxAtoi(indentStr);
@@ -1516,5 +1530,40 @@ void RichTextFrame::OnRightIndent(wxCommandEvent& event)
         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();
+    if (insertionPoint != m_currentPosition)
+    {
+        wxTextAttr attr;
+        if (m_textCtrl->GetStyle(insertionPoint, attr))
+        {
+            wxString msg;
+            wxString facename(wxT("unknown"));
+            if (attr.GetFont().Ok())
+            {
+                facename = attr.GetFont().GetFaceName();
+            }
+            wxString alignment(wxT("unknown alignment"));
+            if (attr.GetAlignment() == wxTEXT_ALIGNMENT_CENTRE)
+                alignment = wxT("centred");
+            else if (attr.GetAlignment() == wxTEXT_ALIGNMENT_RIGHT)
+                alignment = wxT("right-aligned");
+            else if (attr.GetAlignment() == wxTEXT_ALIGNMENT_LEFT)
+                alignment = wxT("left-aligned");
+            else if (attr.GetAlignment() == wxTEXT_ALIGNMENT_JUSTIFIED)
+                alignment = wxT("justified");
+            msg.Printf(wxT("Facename: %s, wxColour(%d, %d, %d), %s"),
+                (const wxChar*) facename,
+                attr.GetTextColour().Red(), attr.GetTextColour().Green(), attr.GetTextColour().Blue(),
+                (const wxChar*) alignment);
+            SetStatusText(msg);
+        }
+        m_currentPosition = insertionPoint;
     }
 }