]> git.saurik.com Git - wxWidgets.git/blobdiff - src/univ/notebook.cpp
fixed SetInsertionPoint() for the rich text controls (ugly hack)
[wxWidgets.git] / src / univ / notebook.cpp
index cb24dadee14aa425f848b8f278bf3e666f58d741..252723acd71358232492af6fbb8cace98710b220 100644 (file)
@@ -5,7 +5,7 @@
 // Modified by:
 // Created:     01.02.01
 // RCS-ID:      $Id$
 // Modified by:
 // Created:     01.02.01
 // RCS-ID:      $Id$
-// Copyright:   (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
+// Copyright:   (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
@@ -31,8 +31,8 @@
 
 #include "wx/imaglist.h"
 #include "wx/notebook.h"
 
 #include "wx/imaglist.h"
 #include "wx/notebook.h"
-
 #include "wx/spinbutt.h"
 #include "wx/spinbutt.h"
+#include "wx/dcmemory.h"
 
 #include "wx/univ/renderer.h"
 
 
 #include "wx/univ/renderer.h"
 
@@ -48,6 +48,9 @@
 
 static const size_t INVALID_PAGE = (size_t)-1;
 
 
 static const size_t INVALID_PAGE = (size_t)-1;
 
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED)
+DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING)
+
 // ----------------------------------------------------------------------------
 // private classes
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // private classes
 // ----------------------------------------------------------------------------
@@ -209,15 +212,21 @@ int wxNotebook::SetSelection(int nPage)
         return m_sel;
     }
 
         return m_sel;
     }
 
-    if ( m_sel != INVALID_PAGE )
+    // we need to change m_sel first, before calling RefreshTab() below as
+    // otherwise the previously selected tab wouldn't be redrawn properly under
+    // wxGTK which calls Refresh() immediately and not during the next event
+    // loop iteration as wxMSW does and as it should
+    size_t selOld = m_sel;
+
+    m_sel = nPage;
+
+    if ( selOld != INVALID_PAGE )
     {
     {
-        RefreshTab(m_sel);
+        RefreshTab(selOld, TRUE /* this tab was selected */);
 
 
-        m_pages[m_sel]->Hide();
+        m_pages[selOld]->Hide();
     }
 
     }
 
-    m_sel = nPage;
-
     if ( m_sel != INVALID_PAGE ) // this is impossible - but test nevertheless
     {
         if ( HasSpinBtn() )
     if ( m_sel != INVALID_PAGE ) // this is impossible - but test nevertheless
     {
         if ( HasSpinBtn() )
@@ -418,12 +427,12 @@ void wxNotebook::RefreshCurrent()
     }
 }
 
     }
 }
 
-void wxNotebook::RefreshTab(int page)
+void wxNotebook::RefreshTab(int page, bool forceSelected)
 {
     wxCHECK_RET( IS_VALID_PAGE(page), _T("invalid notebook page") );
 
     wxRect rect = GetTabRect(page);
 {
     wxCHECK_RET( IS_VALID_PAGE(page), _T("invalid notebook page") );
 
     wxRect rect = GetTabRect(page);
-    if ( (size_t)page == m_sel )
+    if ( forceSelected || ((size_t)page == m_sel) )
     {
         const wxSize indent = GetRenderer()->GetTabIndent();
         rect.Inflate(indent.x, indent.y);
     {
         const wxSize indent = GetRenderer()->GetTabIndent();
         rect.Inflate(indent.x, indent.y);
@@ -457,6 +466,7 @@ void wxNotebook::DoDrawTab(wxDC& dc, const wxRect& rect, size_t n)
         dc.SelectObject(bmp);
         dc.SetBackground(wxBrush(GetBackgroundColour(), wxSOLID));
         m_imageList->Draw(image, dc, 0, 0, wxIMAGELIST_DRAW_NORMAL, TRUE);
         dc.SelectObject(bmp);
         dc.SetBackground(wxBrush(GetBackgroundColour(), wxSOLID));
         m_imageList->Draw(image, dc, 0, 0, wxIMAGELIST_DRAW_NORMAL, TRUE);
+        dc.SelectObject(wxNullBitmap);
 #else
         bmp = *m_imageList->GetBitmap(image);
 #endif
 #else
         bmp = *m_imageList->GetBitmap(image);
 #endif
@@ -1278,14 +1288,14 @@ wxStdNotebookInputHandler::wxStdNotebookInputHandler(wxInputHandler *inphand)
 {
 }
 
 {
 }
 
-bool wxStdNotebookInputHandler::HandleKey(wxControl *control,
+bool wxStdNotebookInputHandler::HandleKey(wxInputConsumer *consumer,
                                           const wxKeyEvent& event,
                                           bool pressed)
 {
     // ignore the key releases
     if ( pressed )
     {
                                           const wxKeyEvent& event,
                                           bool pressed)
 {
     // ignore the key releases
     if ( pressed )
     {
-        wxNotebook *notebook = wxStaticCast(control, wxNotebook);
+        wxNotebook *notebook = wxStaticCast(consumer->GetInputWindow(), wxNotebook);
 
         int page = 0;
         wxControlAction action;
 
         int page = 0;
         wxControlAction action;
@@ -1324,57 +1334,57 @@ bool wxStdNotebookInputHandler::HandleKey(wxControl *control,
 
         if ( !!action )
         {
 
         if ( !!action )
         {
-            return control->PerformAction(action, page);
+            return consumer->PerformAction(action, page);
         }
     }
 
         }
     }
 
-    return wxStdInputHandler::HandleKey(control, event, pressed);
+    return wxStdInputHandler::HandleKey(consumer, event, pressed);
 }
 
 }
 
-bool wxStdNotebookInputHandler::HandleMouse(wxControl *control,
+bool wxStdNotebookInputHandler::HandleMouse(wxInputConsumer *consumer,
                                             const wxMouseEvent& event)
 {
     if ( event.ButtonDown(1) )
     {
                                             const wxMouseEvent& event)
 {
     if ( event.ButtonDown(1) )
     {
-        wxNotebook *notebook = wxStaticCast(control, wxNotebook);
+        wxNotebook *notebook = wxStaticCast(consumer->GetInputWindow(), wxNotebook);
         int page = notebook->HitTest(event.GetPosition());
         if ( page != -1 )
         {
         int page = notebook->HitTest(event.GetPosition());
         if ( page != -1 )
         {
-            control->PerformAction(wxACTION_NOTEBOOK_GOTO, page);
+            consumer->PerformAction(wxACTION_NOTEBOOK_GOTO, page);
 
             return FALSE;
         }
     }
 
 
             return FALSE;
         }
     }
 
-    return wxStdInputHandler::HandleMouse(control, event);
+    return wxStdInputHandler::HandleMouse(consumer, event);
 }
 
 }
 
-bool wxStdNotebookInputHandler::HandleMouseMove(wxControl *control,
+bool wxStdNotebookInputHandler::HandleMouseMove(wxInputConsumer *consumer,
                                                 const wxMouseEvent& event)
 {
                                                 const wxMouseEvent& event)
 {
-    return wxStdInputHandler::HandleMouseMove(control, event);
+    return wxStdInputHandler::HandleMouseMove(consumer, event);
 }
 
 }
 
-bool wxStdNotebookInputHandler::HandleFocus(wxControl *control,
+bool wxStdNotebookInputHandler::HandleFocus(wxInputConsumer *consumer,
                                             const wxFocusEvent& event)
 {
                                             const wxFocusEvent& event)
 {
-    HandleFocusChange(control);
+    HandleFocusChange(consumer);
 
     return FALSE;
 }
 
 
     return FALSE;
 }
 
-bool wxStdNotebookInputHandler::HandleActivation(wxControl *control,
+bool wxStdNotebookInputHandler::HandleActivation(wxInputConsumer *consumer,
                                                  bool WXUNUSED(activated))
 {
     // we react to the focus change in the same way as to the [de]activation
                                                  bool WXUNUSED(activated))
 {
     // we react to the focus change in the same way as to the [de]activation
-    HandleFocusChange(control);
+    HandleFocusChange(consumer);
 
     return FALSE;
 }
 
 
     return FALSE;
 }
 
-void wxStdNotebookInputHandler::HandleFocusChange(wxControl *control)
+void wxStdNotebookInputHandler::HandleFocusChange(wxInputConsumer *consumer)
 {
 {
-    wxNotebook *notebook = wxStaticCast(control, wxNotebook);
+    wxNotebook *notebook = wxStaticCast(consumer->GetInputWindow(), wxNotebook);
     notebook->RefreshCurrent();
 }
 
     notebook->RefreshCurrent();
 }