]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/caret/caret.cpp
not needed anywhere
[wxWidgets.git] / samples / caret / caret.cpp
index d62a84c1c95d61c405af65af36c7e6d4f6004c73..4a2b1bf40d2eb8d1c12d902f451ffa6909579c02 100644 (file)
@@ -10,7 +10,7 @@
 /////////////////////////////////////////////////////////////////////////////
 
 // For compilers that support precompilation, includes "wx/wx.h".
-#include <wx/wxprec.h>
+#include "wx/wxprec.h"
 
 #ifdef __BORLANDC__
     #pragma hdrstop
@@ -19,9 +19,9 @@
 // for all others, include the necessary headers (this file is usually all you
 // need because it includes almost all <standard< wxWindows headers
 #ifndef WX_PRECOMP
-    #include <wx/wx.h>
+    #include "wx/wx.h"
 
-    #include <wx/log.h>
+    #include "wx/log.h"
 #endif
 
 #include "wx/caret.h"
@@ -30,7 +30,7 @@
 // ressources
 // ----------------------------------------------------------------------------
 // the application icon
-#if defined(__WXGTK__) || defined(__WXMOTIF__)
+#if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__)
     #include "mondrian.xpm"
 #endif
 
@@ -176,7 +176,7 @@ IMPLEMENT_APP(MyApp)
 bool MyApp::OnInit()
 {
     // create and show the main application window
-    MyFrame *frame = new MyFrame("Caret wxWindows sample",
+    MyFrame *frame = new MyFrame(_T("Caret wxWindows sample"),
                                  wxPoint(50, 50), wxSize(450, 340));
 
     frame->Show(TRUE);
@@ -201,16 +201,16 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
     // create a menu bar
     wxMenu *menuFile = new wxMenu;
 
-    menuFile->Append(Caret_SetBlinkTime, "&Blink time...\tCtrl-B");
-    menuFile->Append(Caret_Move, "&Move caret\tCtrl-C");
+    menuFile->Append(Caret_SetBlinkTime, _T("&Blink time...\tCtrl-B"));
+    menuFile->Append(Caret_Move, _T("&Move caret\tCtrl-C"));
     menuFile->AppendSeparator();
-    menuFile->Append(Caret_About, "&About...\tCtrl-A", "Show about dialog");
+    menuFile->Append(Caret_About, _T("&About...\tCtrl-A"), _T("Show about dialog"));
     menuFile->AppendSeparator();
-    menuFile->Append(Caret_Quit, "E&xit\tAlt-X", "Quit this program");
+    menuFile->Append(Caret_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
 
     // now append the freshly created menu to the menu bar...
     wxMenuBar *menuBar = new wxMenuBar;
-    menuBar->Append(menuFile, "&File");
+    menuBar->Append(menuFile, _T("&File"));
 
     // ... and attach this menu bar to the frame
     SetMenuBar(menuBar);
@@ -219,7 +219,7 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
 
     // create a status bar just for fun (by default with 1 pane only)
     CreateStatusBar(2);
-    SetStatusText("Welcome to wxWindows!");
+    SetStatusText(_T("Welcome to wxWindows!"));
 }
 
 
@@ -358,6 +358,7 @@ void MyCanvas::OnSize( wxSizeEvent &event )
 //     would use GetUpdateRegion() and iterate over rectangles it contains
 void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
 {
+    wxCaretSuspend cs(this);
     wxPaintDC dc( this );
     PrepareDC( dc );
     dc.Clear();
@@ -382,9 +383,7 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
 
 void MyCanvas::OnChar( wxKeyEvent &event )
 {
-    bool refresh = FALSE;
-
-    switch ( event.KeyCode() )
+    switch ( event.GetKeyCode() )
     {
         case WXK_LEFT:
             PrevChar();
@@ -416,12 +415,19 @@ void MyCanvas::OnChar( wxKeyEvent &event )
             break;
 
         default:
-            if ( !event.AltDown() && wxIsprint(event.KeyCode()) )
+            if ( !event.AltDown() && wxIsprint(event.GetKeyCode()) )
             {
-                CharAt(m_xCaret, m_yCaret) = (wxChar)event.KeyCode();
-                NextChar();
+                wxChar ch = (wxChar)event.GetKeyCode();
+                CharAt(m_xCaret, m_yCaret) = ch;
+
+                wxCaretSuspend cs(this);
+                wxClientDC dc(this);
+                dc.SetFont(m_font);
+                dc.SetBackgroundMode(wxSOLID); // overwrite old value
+                dc.DrawText(ch, m_xMargin + m_xCaret * m_widthChar,
+                                m_yMargin + m_yCaret * m_heightChar );
 
-                refresh = TRUE;
+                NextChar();
             }
             else
             {
@@ -430,8 +436,5 @@ void MyCanvas::OnChar( wxKeyEvent &event )
     }
 
     DoMoveCaret();
-
-    if ( refresh )
-        Refresh();
 }