]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/text/text.cpp
Create a wrapper file for X11/XKBlib.h header.
[wxWidgets.git] / samples / text / text.cpp
index 6cd3a13646e3e29852ed29b5793767431512eff3..12662153bd1e9cc1a8eb453b57e7668803dd1cff 100644 (file)
@@ -5,7 +5,7 @@
 // Modified by:
 // RCS-ID:      $Id$
 // Copyright:   (c) Robert Roebling, Julian Smart, Vadim Zeitlin
 // Modified by:
 // RCS-ID:      $Id$
 // Copyright:   (c) Robert Roebling, Julian Smart, Vadim Zeitlin
-// Licence:     wxWindows license
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 // For compilers that support precompilation, includes "wx/wx.h".
 /////////////////////////////////////////////////////////////////////////////
 
 // For compilers that support precompilation, includes "wx/wx.h".
@@ -45,7 +45,7 @@
 #include "wx/numdlg.h"
 #include "wx/tokenzr.h"
 
 #include "wx/numdlg.h"
 #include "wx/tokenzr.h"
 
-#ifndef __WXMSW__
+#ifndef wxHAS_IMAGES_IN_RESOURCES
     #include "../sample.xpm"
 #endif
 
     #include "../sample.xpm"
 #endif
 
@@ -128,6 +128,7 @@ public:
     void DoSelectText();
     void DoMoveToEndOfText();
     void DoMoveToEndOfEntry();
     void DoSelectText();
     void DoMoveToEndOfText();
     void DoMoveToEndOfEntry();
+    void DoGetWindowCoordinates();
 
     // return true if currently text control has any selection
     bool HasSelection() const
 
     // return true if currently text control has any selection
     bool HasSelection() const
@@ -217,6 +218,10 @@ public:
 
     void OnMoveToEndOfText( wxCommandEvent& WXUNUSED(event) )
         { m_panel->DoMoveToEndOfText(); }
 
     void OnMoveToEndOfText( wxCommandEvent& WXUNUSED(event) )
         { m_panel->DoMoveToEndOfText(); }
+
+    void OnGetWindowCoordinates( wxCommandEvent& WXUNUSED(event) )
+        { m_panel->DoGetWindowCoordinates(); }
+
     void OnMoveToEndOfEntry( wxCommandEvent& WXUNUSED(event) )
         { m_panel->DoMoveToEndOfEntry(); }
 
     void OnMoveToEndOfEntry( wxCommandEvent& WXUNUSED(event) )
         { m_panel->DoMoveToEndOfEntry(); }
 
@@ -415,6 +420,7 @@ enum
     TEXT_ADD_FREEZE,
     TEXT_ADD_LINE,
     TEXT_MOVE_ENDTEXT,
     TEXT_ADD_FREEZE,
     TEXT_ADD_LINE,
     TEXT_MOVE_ENDTEXT,
+    TEXT_GET_WINDOW_COORD,
     TEXT_MOVE_ENDENTRY,
     TEXT_SET_EDITABLE,
     TEXT_SET_ENABLED,
     TEXT_MOVE_ENDENTRY,
     TEXT_SET_EDITABLE,
     TEXT_SET_ENABLED,
@@ -513,6 +519,7 @@ bool MyApp::OnInit()
     menuText->Append(TEXT_LINE_UP, wxT("Scroll text one line up"));
     menuText->Append(TEXT_PAGE_DOWN, wxT("Scroll text one page down"));
     menuText->Append(TEXT_PAGE_UP, wxT("Scroll text one page up"));
     menuText->Append(TEXT_LINE_UP, wxT("Scroll text one line up"));
     menuText->Append(TEXT_PAGE_DOWN, wxT("Scroll text one page down"));
     menuText->Append(TEXT_PAGE_UP, wxT("Scroll text one page up"));
+    menuText->Append(TEXT_GET_WINDOW_COORD, wxT("Get window coordinates"));
     menuText->AppendSeparator();
     menuText->Append(TEXT_GET_LINE, wxT("Get the text of a line of the tabbed multiline"));
     menuText->Append(TEXT_GET_LINELENGTH, wxT("Get the length of a line of the tabbed multiline"));
     menuText->AppendSeparator();
     menuText->Append(TEXT_GET_LINE, wxT("Get the text of a line of the tabbed multiline"));
     menuText->Append(TEXT_GET_LINELENGTH, wxT("Get the length of a line of the tabbed multiline"));
@@ -545,8 +552,6 @@ bool MyApp::OnInit()
 
     frame->Show(true);
 
 
     frame->Show(true);
 
-    SetTopWindow(frame);
-
     // report success
     return true;
 }
     // report success
     return true;
 }
@@ -735,10 +740,27 @@ static wxString GetMouseEventDesc(const wxMouseEvent& ev)
         dbl = ev.RightDClick();
         up = ev.RightUp();
     }
         dbl = ev.RightDClick();
         up = ev.RightUp();
     }
+    else if ( ev.Aux1Down() || ev.Aux1Up() || ev.Aux1DClick() )
+    {
+        button = wxT("Aux1");
+        dbl = ev.Aux1DClick();
+        up = ev.Aux1Up();
+    }
+    else if ( ev.Aux2Down() || ev.Aux2Up() || ev.Aux2DClick() )
+    {
+        button = wxT("Aux2");
+        dbl = ev.Aux2DClick();
+        up = ev.Aux2Up();
+    }
+    else if ( ev.GetWheelRotation() )
+    {
+        return wxString::Format("Wheel rotation %+d", ev.GetWheelRotation());
+    }
     else
     {
         return wxT("Unknown mouse event");
     }
     else
     {
         return wxT("Unknown mouse event");
     }
+    wxASSERT(!(dbl && up));
 
     return wxString::Format(wxT("%s mouse button %s"),
                             button.c_str(),
 
     return wxString::Format(wxT("%s mouse button %s"),
                             button.c_str(),
@@ -782,6 +804,8 @@ void MyTextCtrl::OnMouseEvent(wxMouseEvent& ev)
             << GetChar( ev.LeftIsDown(), wxT('1') )
             << GetChar( ev.MiddleIsDown(), wxT('2') )
             << GetChar( ev.RightIsDown(), wxT('3') )
             << GetChar( ev.LeftIsDown(), wxT('1') )
             << GetChar( ev.MiddleIsDown(), wxT('2') )
             << GetChar( ev.RightIsDown(), wxT('3') )
+            << GetChar( ev.Aux1IsDown(), wxT('x') )
+            << GetChar( ev.Aux2IsDown(), wxT('X') )
             << GetChar( ev.ControlDown(), wxT('C') )
             << GetChar( ev.AltDown(), wxT('A') )
             << GetChar( ev.ShiftDown(), wxT('S') )
             << GetChar( ev.ControlDown(), wxT('C') )
             << GetChar( ev.AltDown(), wxT('A') )
             << GetChar( ev.ShiftDown(), wxT('S') )
@@ -1031,7 +1055,7 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
 #if wxUSE_LOG
     m_log = new wxTextCtrl( this, wxID_ANY, wxT("This is the log window.\n"),
                             wxPoint(5,260), wxSize(630,100),
 #if wxUSE_LOG
     m_log = new wxTextCtrl( this, wxID_ANY, wxT("This is the log window.\n"),
                             wxPoint(5,260), wxSize(630,100),
-                            wxTE_MULTILINE | wxTE_READONLY /* | wxTE_RICH */);
+                            wxTE_MULTILINE | wxTE_READONLY);
 
     m_logOld = wxLog::SetActiveTarget( new wxLogTextCtrl( m_log ) );
 #endif // wxUSE_LOG
 
     m_logOld = wxLog::SetActiveTarget( new wxLogTextCtrl( m_log ) );
 #endif // wxUSE_LOG
@@ -1301,6 +1325,18 @@ void MyPanel::DoMoveToEndOfText()
     m_multitext->SetFocus();
 }
 
     m_multitext->SetFocus();
 }
 
+void MyPanel::DoGetWindowCoordinates()
+{
+    wxTextCtrl * const text = GetFocusedText();
+
+    const wxPoint pt0 = text->PositionToCoords(0);
+    const wxPoint ptCur = text->PositionToCoords(text->GetInsertionPoint());
+    *m_log << "Current position coordinates: "
+              "(" << ptCur.x << ", "  << ptCur.y << "), "
+              "first position coordinates: "
+              "(" << pt0.x << ", "  << pt0.y << ")\n";
+}
+
 void MyPanel::DoMoveToEndOfEntry()
 {
     m_text->SetInsertionPointEnd();
 void MyPanel::DoMoveToEndOfEntry()
 {
     m_text->SetInsertionPointEnd();
@@ -1363,6 +1399,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
     EVT_MENU(TEXT_ADD_FREEZE,         MyFrame::OnAddTextFreeze)
     EVT_MENU(TEXT_ADD_LINE,           MyFrame::OnAddTextLine)
     EVT_MENU(TEXT_MOVE_ENDTEXT,       MyFrame::OnMoveToEndOfText)
     EVT_MENU(TEXT_ADD_FREEZE,         MyFrame::OnAddTextFreeze)
     EVT_MENU(TEXT_ADD_LINE,           MyFrame::OnAddTextLine)
     EVT_MENU(TEXT_MOVE_ENDTEXT,       MyFrame::OnMoveToEndOfText)
+    EVT_MENU(TEXT_GET_WINDOW_COORD,   MyFrame::OnGetWindowCoordinates)
     EVT_MENU(TEXT_MOVE_ENDENTRY,      MyFrame::OnMoveToEndOfEntry)
 
     EVT_MENU(TEXT_SET_EDITABLE,       MyFrame::OnSetEditable)
     EVT_MENU(TEXT_MOVE_ENDENTRY,      MyFrame::OnMoveToEndOfEntry)
 
     EVT_MENU(TEXT_SET_EDITABLE,       MyFrame::OnSetEditable)
@@ -1850,7 +1887,7 @@ void RichTextFrame::OnIdle(wxIdleEvent& WXUNUSED(event))
         {
             wxString msg;
             wxString facename(wxT("unknown"));
         {
             wxString msg;
             wxString facename(wxT("unknown"));
-            if (attr.GetFont().Ok())
+            if (attr.GetFont().IsOk())
             {
                 facename = attr.GetFont().GetFaceName();
             }
             {
                 facename = attr.GetFont().GetFaceName();
             }
@@ -1863,9 +1900,20 @@ void RichTextFrame::OnIdle(wxIdleEvent& WXUNUSED(event))
                 alignment = wxT("left-aligned");
             else if (attr.GetAlignment() == wxTEXT_ALIGNMENT_JUSTIFIED)
                 alignment = wxT("justified");
                 alignment = wxT("left-aligned");
             else if (attr.GetAlignment() == wxTEXT_ALIGNMENT_JUSTIFIED)
                 alignment = wxT("justified");
-            msg.Printf( "Facename: %s, wxColour(%d, %d, %d), %s", facename,
-                attr.GetTextColour().Red(), attr.GetTextColour().Green(), attr.GetTextColour().Blue(),
-                alignment );
+
+            msg.Printf("Facename: %s", facename);
+
+            if (attr.HasTextColour())
+            {
+                msg += wxString::Format(", colour: %s",
+                                        attr.GetTextColour().GetAsString());
+            }
+            else
+            {
+                msg += ", no colour";
+            }
+
+            msg << ", " << alignment;
 
             if (attr.HasFont())
             {
 
             if (attr.HasFont())
             {