diff --git a/samples/splitter/splitter.cpp b/samples/splitter/splitter.cpp index d872e841d2..4e59415c88 100644 --- a/samples/splitter/splitter.cpp +++ b/samples/splitter/splitter.cpp @@ -129,7 +129,7 @@ private: wxSplitterWindow* m_splitter; wxWindow *m_replacewindow; int m_sashPos; - bool m_lockSash:1; + bool m_lockSash; wxDECLARE_EVENT_TABLE(); wxDECLARE_NO_COPY_CLASS(MyFrame); @@ -277,7 +277,7 @@ MyFrame::MyFrame() splitMenu->Append(SPLIT_SETGRAVITY, "Set &gravity\tCtrl-G", "Set gravity of sash"); - splitMenu->Append(SPLIT_LOCKSASH, + splitMenu->AppendCheckItem(SPLIT_LOCKSASH, "Toggle sash &lock on resize\tCtrl-R", "Keep the sash in a fixed position while resizing"); splitMenu->AppendSeparator(); @@ -550,8 +550,6 @@ void MySplitterWindow::OnPositionChanged(wxSplitterEvent& event) // new position. If the sash is not locked, this has no effect but // doesn't hurt either. m_frame->SetSashPos(event.GetSashPosition()); - - event.Skip(); } void MySplitterWindow::OnPositionResize(wxSplitterEvent &event) @@ -560,17 +558,19 @@ void MySplitterWindow::OnPositionResize(wxSplitterEvent &event) // if it is not locked. Otherwise we hold it at the position // the user specified by manually dragging. if (m_frame->IsSashLocked()) + { + // We set the last known position to keep the sash in place. + // For this particular example we could also simply use + // event.Veto() + // as well and it would have the same effect. event.SetSashPosition(m_frame->GetSashPos()); - - event.Skip(); + } } void MySplitterWindow::OnPositionChanging(wxSplitterEvent& event) { wxLogStatus(m_frame, "Position is changing, now = %d (or %d)", event.GetSashPosition(), GetSashPosition()); - - event.Skip(); } void MySplitterWindow::OnDClick(wxSplitterEvent& event) @@ -579,6 +579,7 @@ void MySplitterWindow::OnDClick(wxSplitterEvent& event) m_frame->SetStatusText("Splitter double clicked", 1); #endif // wxUSE_STATUSBAR + // Let the splitter window handle the event as well. event.Skip(); } @@ -588,6 +589,7 @@ void MySplitterWindow::OnUnsplitEvent(wxSplitterEvent& event) m_frame->SetStatusText("Splitter unsplit", 1); #endif // wxUSE_STATUSBAR + // Let the splitter window handle the event as well. event.Skip(); } diff --git a/src/generic/splitter.cpp b/src/generic/splitter.cpp index 8ebcb8a0e0..aefc367753 100644 --- a/src/generic/splitter.cpp +++ b/src/generic/splitter.cpp @@ -488,19 +488,22 @@ void wxSplitterWindow::OnSize(wxSizeEvent& event) update.m_data.resize.oldSize = old_size; update.m_data.resize.newSize = size; - if (!DoSendEvent(update)) + if (DoSendEvent(update)) { - // the event handler vetoed the change - newPosition = -1; - } - else - { - // If the user set the sashposition to -1 - // we keep the already calculated value, - // otherwise the user provided the new position. - int userPos = update.GetSashPosition(); - if (userPos != -1) - newPosition = userPos; + if (update.IsAllowed()) + { + // If the user set the sashposition to -1 + // we keep the already calculated value, otherwise + // the user provided the new position. + int userPos = update.GetSashPosition(); + if (userPos != -1) + newPosition = userPos; + } + else + { + // the event handler vetoed the change + newPosition = -1; + } } // Also check if the second window became too small. @@ -925,7 +928,7 @@ void wxSplitterWindow::UpdateSize() bool wxSplitterWindow::DoSendEvent(wxSplitterEvent& event) { - return !GetEventHandler()->ProcessEvent(event) || event.IsAllowed(); + return GetEventHandler()->ProcessEvent(event); } wxSize wxSplitterWindow::DoGetBestSize() const @@ -1032,15 +1035,18 @@ int wxSplitterWindow::OnSashPositionChanging(int newSashPosition) wxSplitterEvent event(wxEVT_SPLITTER_SASH_POS_CHANGING, this); event.m_data.resize.pos = newSashPosition; - if ( !DoSendEvent(event) ) + if (DoSendEvent(event)) { - // the event handler vetoed the change - newSashPosition = -1; - } - else - { - // it could have been changed by it - newSashPosition = event.GetSashPosition(); + if (event.IsAllowed()) + { + // it could have been changed by it + newSashPosition = event.GetSashPosition(); + } + else + { + // the event handler vetoed the change + newSashPosition = -1; + } } return newSashPosition;