X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/aa3310b88de52e7b7d6fe3432e42707ae92d4af8..e8769ed11cb9315fbf414d121490982df714b68a:/src/univ/notebook.cpp diff --git a/src/univ/notebook.cpp b/src/univ/notebook.cpp index 1d8c16355c..a1c7d867f2 100644 --- a/src/univ/notebook.cpp +++ b/src/univ/notebook.cpp @@ -25,13 +25,40 @@ #if wxUSE_NOTEBOOK -#include "wx/imaglist.h" #include "wx/notebook.h" + +#ifndef WX_PRECOMP + #include "wx/dcmemory.h" +#endif + +#include "wx/imaglist.h" #include "wx/spinbutt.h" -#include "wx/dcmemory.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 // ---------------------------------------------------------------------------- @@ -87,7 +114,7 @@ END_EVENT_TABLE() // implementation // ============================================================================ -IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl) +IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxBookCtrlBase) IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxCommandEvent) // ---------------------------------------------------------------------------- @@ -117,13 +144,16 @@ bool wxNotebook::Create(wxWindow *parent, 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(); - SetBestSize(size); + SetInitialSize(size); CreateInputHandler(wxINP_HANDLER_NOTEBOOK); @@ -203,7 +233,7 @@ wxNotebook::~wxNotebook() // wxNotebook page switching // ---------------------------------------------------------------------------- -int wxNotebook::SetSelection(size_t nPage) +int wxNotebook::DoSetSelection(size_t nPage, int flags) { wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, _T("invalid notebook page") ); @@ -213,15 +243,13 @@ int wxNotebook::SetSelection(size_t nPage) 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 @@ -267,9 +295,11 @@ int wxNotebook::SetSelection(size_t nPage) 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; } @@ -578,10 +608,10 @@ void wxNotebook::DoDraw(wxControlRenderer *renderer) 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 - if ( !GetClientRect().Inside(pt) ) + if ( !GetClientRect().Contains(pt) ) { return -1; } @@ -619,12 +649,12 @@ int wxNotebook::HitTest(const wxPoint& pt, long *flags) const { GetTabSize(n, &rectTabs.width, &rectTabs.height); - if ( rectTabs.Inside(pt) ) + if ( rectTabs.Contains(pt) ) { if ( flags ) { // TODO: be more precise - *flags = wxNB_HITTEST_ONITEM; + *flags = wxBK_HITTEST_ONITEM; } return n; @@ -1312,6 +1342,14 @@ bool wxNotebook::PerformAction(const wxControlAction& action, return true; } +/* static */ +wxInputHandler *wxNotebook::GetStdInputHandler(wxInputHandler *handlerDef) +{ + static wxStdNotebookInputHandler s_handler(handlerDef); + + return &s_handler; +} + // ---------------------------------------------------------------------------- // wxStdNotebookInputHandler // ----------------------------------------------------------------------------