projects
/
wxWidgets.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
made multiple selection behave more consistently with the usual (Windows) way
[wxWidgets.git]
/
src
/
generic
/
splitter.cpp
diff --git
a/src/generic/splitter.cpp
b/src/generic/splitter.cpp
index 3da3fa0472a55dde7388b311a2b6d3497ac4e3df..98b0c13ce35d9d438a0b3e237fd2e3bd43f6e75a 100644
(file)
--- a/
src/generic/splitter.cpp
+++ b/
src/generic/splitter.cpp
@@
-1,12
+1,12
@@
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
-// Name: splitter.cpp
+// Name: s
rc/generic/s
plitter.cpp
// Purpose: wxSplitterWindow implementation
// Author: Julian Smart
// Modified by:
// Created: 01/02/97
// RCS-ID: $Id$
// Purpose: wxSplitterWindow implementation
// Author: Julian Smart
// Modified by:
// Created: 01/02/97
// RCS-ID: $Id$
-// Copyright: (c) Julian Smart
and Markus Holzem
-// Licence: wxWindows licen
s
e
+// Copyright: (c) Julian Smart
+// Licence: wxWindows licen
c
e
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
@@
-16,24
+16,28
@@
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
+#if wxUSE_SPLITTER
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
+ #include "wx/string.h"
+ #include "wx/utils.h"
+ #include "wx/log.h"
+
+ #include "wx/dcscreen.h"
+
#include "wx/window.h"
#include "wx/dialog.h"
#include "wx/frame.h"
#include "wx/window.h"
#include "wx/dialog.h"
#include "wx/frame.h"
-#endif
-#include <stdlib.h>
+ #include "wx/settings.h"
+#endif
-#include "wx/string.h"
#include "wx/splitter.h"
#include "wx/splitter.h"
-#include "wx/dcscreen.h"
-#include "wx/settings.h"
-#include "wx/log.h"
-#include "wx/utils.h"
+
+#include <stdlib.h>
DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING)
@@
-49,7
+53,7
@@
BEGIN_EVENT_TABLE(wxSplitterWindow, wxWindow)
EVT_IDLE(wxSplitterWindow::OnIdle)
EVT_MOUSE_EVENTS(wxSplitterWindow::OnMouseEvent)
EVT_IDLE(wxSplitterWindow::OnIdle)
EVT_MOUSE_EVENTS(wxSplitterWindow::OnMouseEvent)
-#if
def __WXMSW__
+#if
defined( __WXMSW__ ) || defined( __WXMAC__)
EVT_SET_CURSOR(wxSplitterWindow::OnSetCursor)
#endif // wxMSW
EVT_SET_CURSOR(wxSplitterWindow::OnSetCursor)
#endif // wxMSW
@@
-107,8
+111,8
@@
void wxSplitterWindow::Init()
m_oldY = 0;
m_firstX = 0;
m_firstY = 0;
m_oldY = 0;
m_firstX = 0;
m_firstY = 0;
- m_sashSize =
7
;
- m_borderSize =
2
;
+ m_sashSize =
3
;
+ m_borderSize =
0
;
m_sashPosition = m_requestedSashPosition = 0;
m_minimumPaneSize = 0;
m_sashCursorWE = wxCursor(wxCURSOR_SIZEWE);
m_sashPosition = m_requestedSashPosition = 0;
m_minimumPaneSize = 0;
m_sashCursorWE = wxCursor(wxCURSOR_SIZEWE);
@@
-121,9
+125,6
@@
void wxSplitterWindow::Init()
m_facePen = (wxPen *) NULL;
m_hilightPen = (wxPen *) NULL;
m_facePen = (wxPen *) NULL;
m_hilightPen = (wxPen *) NULL;
- m_borderSize = 0;
- m_sashSize = 3;
-
InitColours();
m_needUpdating = FALSE;
InitColours();
m_needUpdating = FALSE;
@@
-168,11
+169,8
@@
void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event)
int x = (int)event.GetX(),
y = (int)event.GetY();
int x = (int)event.GetX(),
y = (int)event.GetY();
- // reset the cursor
-#ifdef __WXMOTIF__
- SetCursor(* wxSTANDARD_CURSOR);
-#elif defined(__WXMSW__)
- SetCursor(wxCursor());
+#if defined(__WXMSW__)
+ // SetCursor(wxCursor()); // Is this required?
#endif
if (GetWindowStyle() & wxSP_NOSASH)
#endif
if (GetWindowStyle() & wxSP_NOSASH)
@@
-188,9
+186,12
@@
void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event)
{
if ( SashHitTest(x, y) )
{
{
if ( SashHitTest(x, y) )
{
- CaptureMouse();
-
+ // Start the drag now
m_dragMode = wxSPLIT_DRAG_DRAGGING;
m_dragMode = wxSPLIT_DRAG_DRAGGING;
+
+ // Capture mouse and set the cursor
+ CaptureMouse();
+ SetResizeCursor();
if ( !isLive )
{
if ( !isLive )
{
@@
-212,7
+213,16
@@
void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event)
{
// We can stop dragging now and see what we've got.
m_dragMode = wxSPLIT_DRAG_NONE;
{
// We can stop dragging now and see what we've got.
m_dragMode = wxSPLIT_DRAG_NONE;
+
+ // Release mouse and unset the cursor
ReleaseMouse();
ReleaseMouse();
+ SetCursor(* wxSTANDARD_CURSOR);
+
+ // exit if unsplit after doubleclick
+ if ( !IsSplit() )
+ {
+ return;
+ }
// Erase old tracker
if ( !isLive )
// Erase old tracker
if ( !isLive )
@@
-243,7
+253,10
@@
void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event)
m_windowOne = m_windowTwo;
m_windowTwo = (wxWindow *) NULL;
OnUnsplit(removedWindow);
m_windowOne = m_windowTwo;
m_windowTwo = (wxWindow *) NULL;
OnUnsplit(removedWindow);
- DoSetSashPosition(0);
+ wxSplitterEvent event(wxEVT_COMMAND_SPLITTER_UNSPLIT, this);
+ event.m_data.win = removedWindow;
+ (void)DoSendEvent(event);
+ SetSashPositionAndNotify(0);
}
else if ( posSashNew == GetWindowSize() )
{
}
else if ( posSashNew == GetWindowSize() )
{
@@
-251,49
+264,39
@@
void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event)
wxWindow *removedWindow = m_windowTwo;
m_windowTwo = (wxWindow *) NULL;
OnUnsplit(removedWindow);
wxWindow *removedWindow = m_windowTwo;
m_windowTwo = (wxWindow *) NULL;
OnUnsplit(removedWindow);
- DoSetSashPosition(0);
+ wxSplitterEvent event(wxEVT_COMMAND_SPLITTER_UNSPLIT, this);
+ event.m_data.win = removedWindow;
+ (void)DoSendEvent(event);
+ SetSashPositionAndNotify(0);
}
else
{
}
else
{
-
DoSetSashPosition
(posSashNew);
+
SetSashPositionAndNotify
(posSashNew);
}
}
else
{
}
}
else
{
-
DoSetSashPosition
(posSashNew);
+
SetSashPositionAndNotify
(posSashNew);
}
SizeWindows();
} // left up && dragging
else if (event.Moving() && !event.Dragging())
{
}
SizeWindows();
} // left up && dragging
else if (event.Moving() && !event.Dragging())
{
- // Just change the cursor
if
required
+ // Just change the cursor
as
required
if ( SashHitTest(x, y) )
if ( SashHitTest(x, y) )
- {
SetResizeCursor();
SetResizeCursor();
- }
-#if defined(__WXGTK__) || defined(__WXMSW__)
else
else
- {
- // We must set the normal cursor in MSW, because
- // if the child window doesn't have a cursor, the
- // parent's (splitter window) will be used, and this
- // must be the standard cursor.
-
- // where else do we unset the cursor?
SetCursor(* wxSTANDARD_CURSOR);
SetCursor(* wxSTANDARD_CURSOR);
- }
-#endif // __WXGTK__
}
else if (event.Dragging() && (m_dragMode == wxSPLIT_DRAG_DRAGGING))
{
}
else if (event.Dragging() && (m_dragMode == wxSPLIT_DRAG_DRAGGING))
{
-#ifdef __WXMSW__
- // Otherwise, the cursor sometimes reverts to the normal cursor
- // during dragging.
- SetResizeCursor();
-#endif // __WXMSW__
-
int diff = m_splitMode == wxSPLIT_VERTICAL ? x - m_oldX : y - m_oldY;
int diff = m_splitMode == wxSPLIT_VERTICAL ? x - m_oldX : y - m_oldY;
+ if ( !diff )
+ {
+ // nothing to do, mouse didn't really move far enough
+ return;
+ }
int posSashOld = isLive ? m_sashPosition : m_sashPositionCurrent;
int posSashNew = OnSashPositionChanging(posSashOld + diff);
int posSashOld = isLive ? m_sashPosition : m_sashPositionCurrent;
int posSashNew = OnSashPositionChanging(posSashOld + diff);
@@
-343,11
+346,11
@@
void wxSplitterWindow::OnMouseEvent(wxMouseEvent& event)
}
else
{
}
else
{
-
DoSetSashPosition
(posSashNew);
+
SetSashPositionAndNotify
(posSashNew);
m_needUpdating = TRUE;
}
}
m_needUpdating = TRUE;
}
}
- else if ( event.LeftDClick() )
+ else if ( event.LeftDClick()
&& m_windowTwo
)
{
OnDoubleClickSash(x, y);
}
{
OnDoubleClickSash(x, y);
}
@@
-384,7
+387,7
@@
void wxSplitterWindow::OnSize(wxSizeEvent& event)
iconized = FALSE;
}
#endif
iconized = FALSE;
}
#endif
-
+
if ( iconized )
{
event.Skip();
if ( iconized )
{
event.Skip();
@@
-399,12
+402,12
@@
void wxSplitterWindow::OnSize(wxSizeEvent& event)
if ( m_splitMode == wxSPLIT_VERTICAL )
{
if ( m_sashPosition >= (cw - 5) )
if ( m_splitMode == wxSPLIT_VERTICAL )
{
if ( m_sashPosition >= (cw - 5) )
-
DoSetSashPosition
(wxMax(10, cw - 40));
+
SetSashPositionAndNotify
(wxMax(10, cw - 40));
}
else // m_splitMode == wxSPLIT_HORIZONTAL
{
if ( m_sashPosition >= (ch - 5) )
}
else // m_splitMode == wxSPLIT_HORIZONTAL
{
if ( m_sashPosition >= (ch - 5) )
-
DoSetSashPosition
(wxMax(10, ch - 40));
+
SetSashPositionAndNotify
(wxMax(10, ch - 40));
}
}
}
}
@@
-532,7
+535,7
@@
void wxSplitterWindow::DrawSash(wxDC& dc)
dc.DrawLine(m_sashPosition+1, h-m_borderSize-1, m_sashPosition+m_sashSize-1, h-m_borderSize-1);
}
}
dc.DrawLine(m_sashPosition+1, h-m_borderSize-1, m_sashPosition+m_sashSize-1, h-m_borderSize-1);
}
}
- else
+ else
// wxSPLIT_HORIZONTAL
{
dc.SetPen(*m_facePen);
if (HasFlag( wxSP_SASH_AQUA ))
{
dc.SetPen(*m_facePen);
if (HasFlag( wxSP_SASH_AQUA ))
@@
-572,12
+575,12
@@
void wxSplitterWindow::DrawSash(wxDC& dc)
}
}
}
}
}
}
- else
+ else
// !wxSP_3DSASH
{
{
+ dc.SetPen(*wxTRANSPARENT_PEN);
+ dc.SetBrush(*m_faceBrush);
if ( m_splitMode == wxSPLIT_VERTICAL )
{
if ( m_splitMode == wxSPLIT_VERTICAL )
{
- dc.SetPen(*wxBLACK_PEN);
- dc.SetBrush(*wxBLACK_BRUSH);
int h1 = h-1;
int y1 = 0;
if ( (GetWindowStyleFlag() & wxSP_BORDER) != wxSP_BORDER && (GetWindowStyleFlag() & wxSP_3DBORDER) != wxSP_3DBORDER )
int h1 = h-1;
int y1 = 0;
if ( (GetWindowStyleFlag() & wxSP_BORDER) != wxSP_BORDER && (GetWindowStyleFlag() & wxSP_3DBORDER) != wxSP_3DBORDER )
@@
-588,10
+591,8
@@
void wxSplitterWindow::DrawSash(wxDC& dc)
}
dc.DrawRectangle(m_sashPosition, y1, m_sashSize, h1);
}
}
dc.DrawRectangle(m_sashPosition, y1, m_sashSize, h1);
}
- else
+ else
// wxSPLIT_HORIZONTAL
{
{
- dc.SetPen(*wxBLACK_PEN);
- dc.SetBrush(*wxBLACK_BRUSH);
int w1 = w-1;
int x1 = 0;
if ( (GetWindowStyleFlag() & wxSP_BORDER) != wxSP_BORDER && (GetWindowStyleFlag() & wxSP_3DBORDER) != wxSP_3DBORDER )
int w1 = w-1;
int x1 = 0;
if ( (GetWindowStyleFlag() & wxSP_BORDER) != wxSP_BORDER && (GetWindowStyleFlag() & wxSP_3DBORDER) != wxSP_3DBORDER )
@@
-602,7
+603,6
@@
void wxSplitterWindow::DrawSash(wxDC& dc)
}
dc.DrawRectangle(x1, m_sashPosition, w1, m_sashSize);
}
}
dc.DrawRectangle(x1, m_sashPosition, w1, m_sashSize);
}
-
}
dc.SetPen(wxNullPen);
}
dc.SetPen(wxNullPen);
@@
-712,14
+712,22
@@
int wxSplitterWindow::AdjustSashPosition(int sashPos) const
return sashPos;
}
return sashPos;
}
-
void
wxSplitterWindow::DoSetSashPosition(int sashPos)
+
bool
wxSplitterWindow::DoSetSashPosition(int sashPos)
{
int newSashPosition = AdjustSashPosition(sashPos);
{
int newSashPosition = AdjustSashPosition(sashPos);
- if ( newSashPosition != m_sashPosition )
- {
- m_sashPosition = newSashPosition;
+ if ( newSashPosition == m_sashPosition )
+ return FALSE;
+
+ m_sashPosition = newSashPosition;
+ return TRUE;
+}
+
+void wxSplitterWindow::SetSashPositionAndNotify(int sashPos)
+{
+ if ( DoSetSashPosition(sashPos) )
+ {
wxSplitterEvent event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED, this);
event.m_data.pos = m_sashPosition;
wxSplitterEvent event(wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED, this);
event.m_data.pos = m_sashPosition;
@@
-741,7
+749,8
@@
void wxSplitterWindow::SizeWindows()
DoSetSashPosition(newSashPosition);
}
DoSetSashPosition(newSashPosition);
}
- if ( newSashPosition == m_sashPosition )
+ if ( newSashPosition <= m_sashPosition
+ && newSashPosition >= m_sashPosition - GetBorderSize() )
{
// don't update it any more
m_requestedSashPosition = INT_MAX;
{
// don't update it any more
m_requestedSashPosition = INT_MAX;
@@
-753,7
+762,7
@@
void wxSplitterWindow::SizeWindows()
if ( GetWindow1() && !GetWindow2() )
{
if ( GetWindow1() && !GetWindow2() )
{
- GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(),
+ GetWindow1()->SetSize(GetBorderSize(), GetBorderSize(),
w - 2*GetBorderSize(), h - 2*GetBorderSize());
}
else if ( GetWindow1() && GetWindow2() )
w - 2*GetBorderSize(), h - 2*GetBorderSize());
}
else if ( GetWindow1() && GetWindow2() )
@@
-792,6
+801,9
@@
void wxSplitterWindow::SizeWindows()
// Set pane for unsplit window
void wxSplitterWindow::Initialize(wxWindow *window)
{
// Set pane for unsplit window
void wxSplitterWindow::Initialize(wxWindow *window)
{
+ wxASSERT_MSG( window && window->GetParent() == this,
+ _T("windows in the splitter should have it as parent!") );
+
m_windowOne = window;
m_windowTwo = (wxWindow *) NULL;
DoSetSashPosition(0);
m_windowOne = window;
m_windowTwo = (wxWindow *) NULL;
DoSetSashPosition(0);
@@
-807,6
+819,12
@@
bool wxSplitterWindow::DoSplit(wxSplitMode mode,
if ( IsSplit() )
return FALSE;
if ( IsSplit() )
return FALSE;
+ wxCHECK_MSG( window1 && window2, FALSE,
+ _T("can not split with NULL window(s)") );
+
+ wxCHECK_MSG( window1->GetParent() == this && window2->GetParent() == this, FALSE,
+ _T("windows in the splitter should have it as parent!") );
+
m_splitMode = mode;
m_windowOne = window1;
m_windowTwo = window2;
m_splitMode = mode;
m_windowOne = window1;
m_windowTwo = window2;
@@
-1036,6
+1054,8
@@
int wxSplitterWindow::OnSashPositionChanging(int newSashPosition)
// the sash if the minimum pane size is zero.
void wxSplitterWindow::OnDoubleClickSash(int x, int y)
{
// the sash if the minimum pane size is zero.
void wxSplitterWindow::OnDoubleClickSash(int x, int y)
{
+ wxCHECK_RET(m_windowTwo, wxT("splitter: no window to remove"));
+
// new code should handle events instead of using the virtual functions
wxSplitterEvent event(wxEVT_COMMAND_SPLITTER_DOUBLECLICKED, this);
event.m_data.pt.x = x;
// new code should handle events instead of using the virtual functions
wxSplitterEvent event(wxEVT_COMMAND_SPLITTER_DOUBLECLICKED, this);
event.m_data.pt.x = x;
@@
-1044,7
+1064,13
@@
void wxSplitterWindow::OnDoubleClickSash(int x, int y)
{
if ( GetMinimumPaneSize() == 0 || m_permitUnsplitAlways )
{
{
if ( GetMinimumPaneSize() == 0 || m_permitUnsplitAlways )
{
- Unsplit();
+ wxWindow* win = m_windowTwo;
+ if ( Unsplit(win) )
+ {
+ wxSplitterEvent unsplitEvent(wxEVT_COMMAND_SPLITTER_UNSPLIT, this);
+ unsplitEvent.m_data.win = win;
+ (void)DoSendEvent(unsplitEvent);
+ }
}
}
//else: blocked by user
}
}
//else: blocked by user
@@
-1052,16
+1078,11
@@
void wxSplitterWindow::OnDoubleClickSash(int x, int y)
void wxSplitterWindow::OnUnsplit(wxWindow *winRemoved)
{
void wxSplitterWindow::OnUnsplit(wxWindow *winRemoved)
{
- //
do it
before calling the event handler which may delete the window
+ //
call this
before calling the event handler which may delete the window
winRemoved->Show(FALSE);
winRemoved->Show(FALSE);
-
- wxSplitterEvent event(wxEVT_COMMAND_SPLITTER_UNSPLIT, this);
- event.m_data.win = winRemoved;
-
- (void)DoSendEvent(event);
}
}
-#if
def __WXMSW__
+#if
defined( __WXMSW__ ) || defined( __WXMAC__)
// this is currently called (and needed) under MSW only...
void wxSplitterWindow::OnSetCursor(wxSetCursorEvent& event)
// this is currently called (and needed) under MSW only...
void wxSplitterWindow::OnSetCursor(wxSetCursorEvent& event)
@@
-1078,5
+1099,6
@@
void wxSplitterWindow::OnSetCursor(wxSetCursorEvent& event)
//else: do nothing, in particular, don't call Skip()
}
//else: do nothing, in particular, don't call Skip()
}
+#endif // wxUSE_SPLITTER
#endif // wxMSW
#endif // wxMSW