]> git.saurik.com Git - wxWidgets.git/blobdiff - src/univ/notebook.cpp
Rework the wxCusor ctor taking wx stock number to provide as many cursors as
[wxWidgets.git] / src / univ / notebook.cpp
index 2b9e19f9ffc4e9bb1f903782ed41a8eeaf0c988d..392f13c4aa5a6c9c6684b0e4279f0762b7963a44 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
-// Name:        univ/notebook.cpp
+// Name:        src/univ/notebook.cpp
 // Purpose:     wxNotebook implementation
 // Author:      Vadim Zeitlin
 // Modified by:
 // Purpose:     wxNotebook implementation
 // Author:      Vadim Zeitlin
 // Modified by:
 // headers
 // ----------------------------------------------------------------------------
 
 // headers
 // ----------------------------------------------------------------------------
 
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
-    #pragma implementation "univnotebook.h"
-#endif
-
-#ifdef __VMS
-#pragma message disable unscomzer
-#endif
-
 #include "wx/wxprec.h"
 
 #ifdef __BORLANDC__
 #include "wx/wxprec.h"
 
 #ifdef __BORLANDC__
 
 #if wxUSE_NOTEBOOK
 
 
 #if wxUSE_NOTEBOOK
 
-#include "wx/imaglist.h"
 #include "wx/notebook.h"
 #include "wx/notebook.h"
+
+#ifndef WX_PRECOMP
+    #include "wx/dcmemory.h"
+#endif
+
+#include "wx/imaglist.h"
 #include "wx/spinbutt.h"
 #include "wx/spinbutt.h"
-#include "wx/dcmemory.h"
 
 #include "wx/univ/renderer.h"
 
 
 #include "wx/univ/renderer.h"
 
+// ----------------------------------------------------------------------------
+// wxStdNotebookInputHandler: translates SPACE and ENTER keys and the left mouse
+// click into button press/release actions
+// ----------------------------------------------------------------------------
+
+class WXDLLEXPORT wxStdNotebookInputHandler : public wxStdInputHandler
+{
+public:
+    wxStdNotebookInputHandler(wxInputHandler *inphand);
+
+    virtual bool HandleKey(wxInputConsumer *consumer,
+                           const wxKeyEvent& event,
+                           bool pressed);
+    virtual bool HandleMouse(wxInputConsumer *consumer,
+                             const wxMouseEvent& event);
+    virtual bool HandleMouseMove(wxInputConsumer *consumer, const wxMouseEvent& event);
+    virtual bool HandleFocus(wxInputConsumer *consumer, const wxFocusEvent& event);
+    virtual bool HandleActivation(wxInputConsumer *consumer, bool activated);
+
+protected:
+    void HandleFocusChange(wxInputConsumer *consumer);
+};
+
 // ----------------------------------------------------------------------------
 // macros
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // macros
 // ----------------------------------------------------------------------------
@@ -125,13 +144,16 @@ bool wxNotebook::Create(wxWindow *parent,
                         long style,
                         const wxString& name)
 {
                         long style,
                         const wxString& name)
 {
+    if ( (style & wxBK_ALIGN_MASK) == wxBK_DEFAULT )
+        style |= wxBK_TOP;
+
     if ( !wxControl::Create(parent, id, pos, size, style,
                             wxDefaultValidator, name) )
         return false;
 
     m_sizePad = GetRenderer()->GetTabPadding();
 
     if ( !wxControl::Create(parent, id, pos, size, style,
                             wxDefaultValidator, name) )
         return false;
 
     m_sizePad = GetRenderer()->GetTabPadding();
 
-    SetBestSize(size);
+    SetInitialSize(size);
 
     CreateInputHandler(wxINP_HANDLER_NOTEBOOK);
 
 
     CreateInputHandler(wxINP_HANDLER_NOTEBOOK);
 
@@ -174,7 +196,7 @@ bool wxNotebook::SetPageText(size_t nPage, const wxString& strText)
 
 int wxNotebook::GetPageImage(size_t nPage) const
 {
 
 int wxNotebook::GetPageImage(size_t nPage) const
 {
-    wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, _T("invalid notebook page") );
+    wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, _T("invalid notebook page") );
 
     return m_images[nPage];
 }
 
     return m_images[nPage];
 }
@@ -211,9 +233,9 @@ wxNotebook::~wxNotebook()
 // wxNotebook page switching
 // ----------------------------------------------------------------------------
 
 // wxNotebook page switching
 // ----------------------------------------------------------------------------
 
-int wxNotebook::SetSelection(size_t nPage)
+int wxNotebook::DoSetSelection(size_t nPage, int flags)
 {
 {
-    wxCHECK_MSG( IS_VALID_PAGE(nPage), -1, _T("invalid notebook page") );
+    wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, _T("invalid notebook page") );
 
     if ( (size_t)nPage == m_sel )
     {
 
     if ( (size_t)nPage == m_sel )
     {
@@ -221,15 +243,13 @@ int wxNotebook::SetSelection(size_t nPage)
         return m_sel;
     }
 
         return m_sel;
     }
 
-    // event handling
-    wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId);
-    event.SetSelection(nPage);
-    event.SetOldSelection(m_sel);
-    event.SetEventObject(this);
-    if ( GetEventHandler()->ProcessEvent(event) && !event.IsAllowed() )
+    if ( flags & SetSelection_SendEvent )
     {
     {
-        // program doesn't allow the page change
-        return m_sel;
+        if ( !SendPageChangingEvent(nPage) )
+        {
+            // program doesn't allow the page change
+            return m_sel;
+        }
     }
 
     // we need to change m_sel first, before calling RefreshTab() below as
     }
 
     // we need to change m_sel first, before calling RefreshTab() below as
@@ -275,9 +295,11 @@ int wxNotebook::SetSelection(size_t nPage)
         m_pages[m_sel]->Show();
     }
 
         m_pages[m_sel]->Show();
     }
 
-    // event handling
-    event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED);
-    GetEventHandler()->ProcessEvent(event);
+    if ( flags & SetSelection_SendEvent )
+    {
+        // event handling
+        SendPageChangedEvent(selOld);
+    }
 
     return selOld;
 }
 
     return selOld;
 }
@@ -473,7 +495,7 @@ void wxNotebook::DoDrawTab(wxDC& dc, const wxRect& rect, size_t n)
         m_imageList->Draw(image, dc, 0, 0, wxIMAGELIST_DRAW_NORMAL, true);
         dc.SelectObject(wxNullBitmap);
 #else
         m_imageList->Draw(image, dc, 0, 0, wxIMAGELIST_DRAW_NORMAL, true);
         dc.SelectObject(wxNullBitmap);
 #else
-        bmp = *m_imageList->GetBitmap(image);
+        bmp = m_imageList->GetBitmap(image);
 #endif
     }
 
 #endif
     }
 
@@ -586,10 +608,10 @@ void wxNotebook::DoDraw(wxControlRenderer *renderer)
 int wxNotebook::HitTest(const wxPoint& pt, long *flags) const
 {
     if ( flags )
 int wxNotebook::HitTest(const wxPoint& pt, long *flags) const
 {
     if ( flags )
-        *flags = wxNB_HITTEST_NOWHERE;
+        *flags = wxBK_HITTEST_NOWHERE;
 
     // first check that it is in this window at all
 
     // first check that it is in this window at all
-    if ( !GetClientRect().Inside(pt) )
+    if ( !GetClientRect().Contains(pt) )
     {
         return -1;
     }
     {
         return -1;
     }
@@ -627,12 +649,12 @@ int wxNotebook::HitTest(const wxPoint& pt, long *flags) const
     {
         GetTabSize(n, &rectTabs.width, &rectTabs.height);
 
     {
         GetTabSize(n, &rectTabs.width, &rectTabs.height);
 
-        if ( rectTabs.Inside(pt) )
+        if ( rectTabs.Contains(pt) )
         {
             if ( flags )
             {
                 // TODO: be more precise
         {
             if ( flags )
             {
                 // TODO: be more precise
-                *flags = wxNB_HITTEST_ONITEM;
+                *flags = wxBK_HITTEST_ONITEM;
             }
 
             return n;
             }
 
             return n;
@@ -658,14 +680,14 @@ bool wxNotebook::IsVertical() const
 wxDirection wxNotebook::GetTabOrientation() const
 {
     long style = GetWindowStyle();
 wxDirection wxNotebook::GetTabOrientation() const
 {
     long style = GetWindowStyle();
-    if ( style & wxNB_BOTTOM )
+    if ( style & wxBK_BOTTOM )
         return wxBOTTOM;
         return wxBOTTOM;
-    else if ( style & wxNB_RIGHT )
+    else if ( style & wxBK_RIGHT )
         return wxRIGHT;
         return wxRIGHT;
-    else if ( style & wxNB_LEFT )
+    else if ( style & wxBK_LEFT )
         return wxLEFT;
 
         return wxLEFT;
 
-    // wxNB_TOP == 0 so we don't have to test for it
+    // wxBK_TOP == 0 so we don't have to test for it
     return wxTOP;
 }
 
     return wxTOP;
 }
 
@@ -1320,6 +1342,14 @@ bool wxNotebook::PerformAction(const wxControlAction& action,
     return true;
 }
 
     return true;
 }
 
+/* static */
+wxInputHandler *wxNotebook::GetStdInputHandler(wxInputHandler *handlerDef)
+{
+    static wxStdNotebookInputHandler s_handler(handlerDef);
+
+    return &s_handler;
+}
+
 // ----------------------------------------------------------------------------
 // wxStdNotebookInputHandler
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // wxStdNotebookInputHandler
 // ----------------------------------------------------------------------------
@@ -1431,4 +1461,3 @@ void wxStdNotebookInputHandler::HandleFocusChange(wxInputConsumer *consumer)
 }
 
 #endif // wxUSE_NOTEBOOK
 }
 
 #endif // wxUSE_NOTEBOOK
-