X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3a6bdcad42c1553ce3ad0e07e2cb9a88b2ef38e9..a6c129111b38341eb561b110fd1566b260740675:/contrib/src/gizmos/dynamicsash.cpp diff --git a/contrib/src/gizmos/dynamicsash.cpp b/contrib/src/gizmos/dynamicsash.cpp index f8d5980143..137d00cc4e 100644 --- a/contrib/src/gizmos/dynamicsash.cpp +++ b/contrib/src/gizmos/dynamicsash.cpp @@ -10,10 +10,6 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ - #pragma implementation "splittree.h" -#endif - // For compilers that support precompilation, includes "wx/wx.h". #include "wx/wxprec.h" @@ -192,10 +188,11 @@ public: bool Create(); void AddChild(wxWindow *window); DynamicSashRegion GetRegion(int x, int y); - void ResizeChild(wxSize size); + void ResizeChild(const wxSize& size); wxScrollBar *FindScrollBar(const wxWindow *child, int vert) const; void OnSize(wxSizeEvent &event); + void OnViewSize(wxSizeEvent &event); void OnPaint(wxPaintEvent &event); void OnScroll(wxScrollEvent &event); void OnFocus(wxFocusEvent &event); @@ -207,13 +204,15 @@ public: wxDynamicSashWindowImpl *m_impl; - wxScrollBar *m_vscroll, *m_hscroll; + wxScrollBar *m_vscroll, + *m_hscroll; /* m_child is the window provided to us by the application developer. m_viewport is a window we've created, and it is the immediately parent of m_child. We scroll m_child by moving it around within m_viewport. */ - wxWindow *m_viewport, *m_child; + wxWindow *m_viewport, + *m_child; }; @@ -999,7 +998,9 @@ wxDynamicSashWindowLeaf::wxDynamicSashWindowLeaf(wxDynamicSashWindowImpl *impl) { m_impl = impl; - m_hscroll = m_vscroll = NULL; + m_hscroll = + m_vscroll = NULL; + m_child = NULL; } @@ -1007,7 +1008,6 @@ wxDynamicSashWindowLeaf::~wxDynamicSashWindowLeaf() { m_hscroll->SetEventHandler(m_hscroll); m_vscroll->SetEventHandler(m_vscroll); - m_viewport->SetEventHandler(m_viewport); m_hscroll->Destroy(); m_vscroll->Destroy(); @@ -1016,24 +1016,25 @@ wxDynamicSashWindowLeaf::~wxDynamicSashWindowLeaf() bool wxDynamicSashWindowLeaf::Create() { - bool success; - m_hscroll = new wxScrollBar(); m_vscroll = new wxScrollBar(); m_viewport = new wxWindow(); - if (!m_hscroll || !m_vscroll || !m_viewport) - { - return false; - } - wxDynamicSashWindowImpl *add_child_target = m_impl->m_add_child_target; m_impl->m_add_child_target = NULL; - success = m_hscroll->Create(m_impl->m_container, wxID_ANY, wxDefaultPosition, wxDefaultSize, - wxSB_HORIZONTAL); - success = success && m_vscroll->Create(m_impl->m_container, wxID_ANY, wxDefaultPosition, wxDefaultSize, - wxSB_VERTICAL); - success = success && m_viewport->Create(m_impl->m_container, wxID_ANY); + + bool success = m_hscroll->Create(m_impl->m_container, wxID_ANY, + wxDefaultPosition, wxDefaultSize, + wxSB_HORIZONTAL); + if ( success ) + success = m_vscroll->Create(m_impl->m_container, wxID_ANY, + wxDefaultPosition, wxDefaultSize, + wxSB_VERTICAL); + if ( success ) + success = m_viewport->Create(m_impl->m_container, wxID_ANY); + if ( !success ) + return false; + m_impl->m_add_child_target = add_child_target; wxCursor cursor(wxCURSOR_ARROW); @@ -1041,50 +1042,46 @@ bool wxDynamicSashWindowLeaf::Create() m_vscroll->SetCursor(cursor); m_viewport->SetCursor(cursor); - m_viewport->SetEventHandler(this); - Connect(wxID_ANY, wxEVT_DYNAMIC_SASH_REPARENT, (wxObjectEventFunction)&wxDynamicSashWindowLeaf::OnReparent); + // the viewport must resize its child when it is itself resized, but it's + // more convenient to do it in our own method instead of deriving a new + // class just for this: this is why we pass this as last Connect() argument + m_viewport->Connect(wxEVT_SIZE, + wxSizeEventHandler(wxDynamicSashWindowLeaf::OnViewSize), + NULL, this); + + Connect(wxEVT_DYNAMIC_SASH_REPARENT, + wxEventHandler(wxDynamicSashWindowLeaf::OnReparent)); if (m_impl->m_window->GetWindowStyle() & wxDS_MANAGE_SCROLLBARS) { m_hscroll->SetEventHandler(this); m_vscroll->SetEventHandler(this); - Connect(wxID_ANY, wxEVT_SET_FOCUS, (wxObjectEventFunction) - (wxEventFunction) - (wxFocusEventFunction)&wxDynamicSashWindowLeaf::OnFocus); - Connect(wxID_ANY, wxEVT_SCROLL_TOP, (wxObjectEventFunction) - (wxEventFunction) - (wxScrollEventFunction)&wxDynamicSashWindowLeaf::OnScroll); - Connect(wxID_ANY, wxEVT_SCROLL_BOTTOM, (wxObjectEventFunction) - (wxEventFunction) - (wxScrollEventFunction)&wxDynamicSashWindowLeaf::OnScroll); - Connect(wxID_ANY, wxEVT_SCROLL_LINEUP, (wxObjectEventFunction) - (wxEventFunction) - (wxScrollEventFunction)&wxDynamicSashWindowLeaf::OnScroll); - Connect(wxID_ANY, wxEVT_SCROLL_LINEDOWN, (wxObjectEventFunction) - (wxEventFunction) - (wxScrollEventFunction)&wxDynamicSashWindowLeaf::OnScroll); - Connect(wxID_ANY, wxEVT_SCROLL_PAGEUP, (wxObjectEventFunction) - (wxEventFunction) - (wxScrollEventFunction)&wxDynamicSashWindowLeaf::OnScroll); - Connect(wxID_ANY, wxEVT_SCROLL_PAGEDOWN, (wxObjectEventFunction) - (wxEventFunction) - (wxScrollEventFunction)&wxDynamicSashWindowLeaf::OnScroll); - Connect(wxID_ANY, wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction) - (wxEventFunction) - (wxScrollEventFunction)&wxDynamicSashWindowLeaf::OnScroll); - Connect(wxID_ANY, wxEVT_SCROLL_THUMBRELEASE, (wxObjectEventFunction) - (wxEventFunction) - (wxScrollEventFunction)&wxDynamicSashWindowLeaf::OnScroll); + Connect(wxEVT_SET_FOCUS, + wxFocusEventHandler(wxDynamicSashWindowLeaf::OnFocus)); + Connect(wxEVT_SCROLL_TOP, + wxScrollEventHandler(wxDynamicSashWindowLeaf::OnScroll)); + Connect(wxEVT_SCROLL_BOTTOM, + wxScrollEventHandler(wxDynamicSashWindowLeaf::OnScroll)); + Connect(wxEVT_SCROLL_LINEUP, + wxScrollEventHandler(wxDynamicSashWindowLeaf::OnScroll)); + Connect(wxEVT_SCROLL_LINEDOWN, + wxScrollEventHandler(wxDynamicSashWindowLeaf::OnScroll)); + Connect(wxEVT_SCROLL_PAGEUP, + wxScrollEventHandler(wxDynamicSashWindowLeaf::OnScroll)); + Connect(wxEVT_SCROLL_PAGEDOWN, + wxScrollEventHandler(wxDynamicSashWindowLeaf::OnScroll)); + Connect(wxEVT_SCROLL_THUMBTRACK, + wxScrollEventHandler(wxDynamicSashWindowLeaf::OnScroll)); + Connect(wxEVT_SCROLL_THUMBRELEASE, + wxScrollEventHandler(wxDynamicSashWindowLeaf::OnScroll)); } wxLayoutConstraints *layout = new wxLayoutConstraints(); if (!layout) return false; + wxSize size = m_hscroll->GetBestSize(); -#ifdef __WXMSW__ - size = m_hscroll->GetSize(); -#endif layout->left.SameAs(m_impl->m_container, wxLeft, 10); layout->right.LeftOf(m_vscroll); @@ -1095,10 +1092,8 @@ bool wxDynamicSashWindowLeaf::Create() layout = new wxLayoutConstraints(); if (!layout) return false; - size = size = m_vscroll->GetBestSize(); -#ifdef __WXMSW__ - size = m_vscroll->GetSize(); -#endif + + size = m_vscroll->GetBestSize(); layout->top.SameAs(m_impl->m_container, wxTop, 10); layout->bottom.Above(m_hscroll); @@ -1117,7 +1112,7 @@ bool wxDynamicSashWindowLeaf::Create() m_impl->m_container->Layout(); - return success; + return true; } void wxDynamicSashWindowLeaf::AddChild(wxWindow *window) @@ -1159,22 +1154,17 @@ DynamicSashRegion wxDynamicSashWindowLeaf::GetRegion(int x, int y) return DSR_NONE; } -void wxDynamicSashWindowLeaf::ResizeChild(wxSize size) +void wxDynamicSashWindowLeaf::ResizeChild(const wxSize& size) { if (m_child) { - if (m_impl->m_window->GetWindowStyle() & wxDS_MANAGE_SCROLLBARS) + if (m_impl->m_window->HasFlag(wxDS_MANAGE_SCROLLBARS)) { - m_child->SetSize(size); wxSize best_size = m_child->GetBestSize(); if (best_size.GetWidth() < size.GetWidth()) - { best_size.SetWidth(size.GetWidth()); - } if (best_size.GetHeight() < size.GetHeight()) - { best_size.SetHeight(size.GetHeight()); - } m_child->SetSize(best_size); int hpos = m_hscroll->GetThumbPosition(); @@ -1202,7 +1192,7 @@ void wxDynamicSashWindowLeaf::ResizeChild(wxSize size) wxPoint pos = m_child->GetPosition(); m_viewport->ScrollWindow(-hpos - pos.x, -vpos - pos.y); } - else + else // !wxDS_MANAGE_SCROLLBARS { m_child->SetSize(size); } @@ -1223,7 +1213,12 @@ wxDynamicSashWindowLeaf::FindScrollBar(const wxWindow *child, int vert) const void wxDynamicSashWindowLeaf::OnSize(wxSizeEvent &WXUNUSED(event)) { m_impl->m_container->Refresh(); - ResizeChild(m_viewport->GetSize()); +} + +void wxDynamicSashWindowLeaf::OnViewSize(wxSizeEvent &WXUNUSED(event)) +{ + if ( m_viewport ) + ResizeChild(m_viewport->GetSize()); } void wxDynamicSashWindowLeaf::OnPaint(wxPaintEvent &WXUNUSED(event))