1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxSashWindow implementation. A sash window has an optional
4 // sash on each edge, allowing it to be dragged. An event
5 // is generated when the sash is released.
6 // Author: Julian Smart
10 // Copyright: (c) Julian Smart
11 // Licence: wxWindows license
12 /////////////////////////////////////////////////////////////////////////////
14 #ifndef _WX_SASHWIN_H_G_
15 #define _WX_SASHWIN_H_G_
18 #pragma interface "sashwin.h"
22 #include "wx/window.h"
23 #include "wx/string.h"
25 #define wxSASH_DRAG_NONE 0
26 #define wxSASH_DRAG_DRAGGING 1
27 #define wxSASH_DRAG_LEFT_DOWN 2
29 enum wxSashEdgePosition
{
38 * wxSashEdge represents one of the four edges of a window.
41 class WXDLLEXPORT wxSashEdge
44 wxSashEdge() { m_show
= FALSE
; m_border
= FALSE
; m_margin
= 0; }
46 bool m_show
; // Is the sash showing?
47 bool m_border
; // Do we draw a border?
48 int m_margin
; // The margin size
55 #define wxSW_3D 0x0004
58 * wxSashWindow allows any of its edges to have a sash which can be dragged
59 * to resize the window. The actual content window will be created as a child
63 class WXDLLEXPORT wxSashWindow
: public wxWindow
65 DECLARE_DYNAMIC_CLASS(wxSashWindow
)
69 ////////////////////////////////////////////////////////////////////////////
72 // Default constructor
76 wxSashWindow(wxWindow
*parent
, wxWindowID id
= -1, const wxPoint
& pos
= wxDefaultPosition
,
77 const wxSize
& size
= wxDefaultSize
, long style
= wxSW_3D
|wxCLIP_CHILDREN
, const wxString
& name
= "sashWindow");
80 // Set whether there's a sash in this position
81 void SetSashVisible(wxSashEdgePosition edge
, bool sash
);
83 // Get whether there's a sash in this position
84 inline bool GetSashVisible(wxSashEdgePosition edge
) const { return m_sashes
[edge
].m_show
; }
86 // Set whether there's a border in this position
87 inline void SetSashBorder(wxSashEdgePosition edge
, bool border
) { m_sashes
[edge
].m_border
= border
; }
89 // Get whether there's a border in this position
90 inline bool HasBorder(wxSashEdgePosition edge
) const { return m_sashes
[edge
].m_border
; }
93 inline int GetEdgeMargin(wxSashEdgePosition edge
) const { return m_sashes
[edge
].m_margin
; }
95 // Sets the default sash border size
96 inline void SetDefaultBorderSize(int width
) { m_borderSize
= width
; }
98 // Gets the default sash border size
99 inline int GetDefaultBorderSize() const { return m_borderSize
; }
101 // Sets the addition border size between child and sash window
102 inline void SetExtraBorderSize(int width
) { m_extraBorderSize
= width
; }
104 // Gets the addition border size between child and sash window
105 inline int GetExtraBorderSize() const { return m_extraBorderSize
; }
107 virtual void SetMinimumSizeX(int min
) { m_minimumPaneSizeX
= min
; }
108 virtual void SetMinimumSizeY(int min
) { m_minimumPaneSizeY
= min
; }
109 virtual int GetMinimumSizeX() const { return m_minimumPaneSizeX
; }
110 virtual int GetMinimumSizeY() const { return m_minimumPaneSizeY
; }
112 virtual void SetMaximumSizeX(int max
) { m_maximumPaneSizeX
= max
; }
113 virtual void SetMaximumSizeY(int max
) { m_maximumPaneSizeY
= max
; }
114 virtual int GetMaximumSizeX() const { return m_maximumPaneSizeX
; }
115 virtual int GetMaximumSizeY() const { return m_maximumPaneSizeY
; }
117 ////////////////////////////////////////////////////////////////////////////
120 // Paints the border and sash
121 void OnPaint(wxPaintEvent
& event
);
123 // Handles mouse events
124 void OnMouseEvent(wxMouseEvent
& ev
);
127 void OnSize(wxSizeEvent
& event
);
130 void DrawBorders(wxDC
& dc
);
133 void DrawSash(wxSashEdgePosition edge
, wxDC
& dc
);
136 void DrawSashes(wxDC
& dc
);
138 // Draws the sash tracker (for whilst moving the sash)
139 void DrawSashTracker(wxSashEdgePosition edge
, int x
, int y
);
141 // Tests for x, y over sash
142 wxSashEdgePosition
SashHitTest(int x
, int y
, int tolerance
= 2);
144 // Resizes subwindows
147 // Initialize colours
151 wxSashEdge m_sashes
[4];
153 wxSashEdgePosition m_draggingEdge
;
157 int m_extraBorderSize
;
160 int m_minimumPaneSizeX
;
161 int m_minimumPaneSizeY
;
162 int m_maximumPaneSizeX
;
163 int m_maximumPaneSizeY
;
164 wxCursor
* m_sashCursorWE
;
165 wxCursor
* m_sashCursorNS
;
166 wxColour m_lightShadowColour
;
167 wxColour m_mediumShadowColour
;
168 wxColour m_darkShadowColour
;
169 wxColour m_hilightColour
;
170 wxColour m_faceColour
;
172 DECLARE_EVENT_TABLE()
175 #define wxEVT_SASH_DRAGGED (wxEVT_FIRST + 1200)
177 enum wxSashDragStatus
180 wxSASH_STATUS_OUT_OF_RANGE
183 class WXDLLEXPORT wxSashEvent
: public wxCommandEvent
185 DECLARE_DYNAMIC_CLASS(wxSashEvent
)
188 inline wxSashEvent(int id
= 0, wxSashEdgePosition edge
= wxSASH_NONE
) {
189 m_eventType
= (wxEventType
) wxEVT_SASH_DRAGGED
; m_id
= id
; m_edge
= edge
; }
191 inline void SetEdge(wxSashEdgePosition edge
) { m_edge
= edge
; }
192 inline wxSashEdgePosition
GetEdge() const { return m_edge
; }
194 //// The rectangle formed by the drag operation
195 inline void SetDragRect(const wxRect
& rect
) { m_dragRect
= rect
; }
196 inline wxRect
GetDragRect() const { return m_dragRect
; }
198 //// Whether the drag caused the rectangle to be reversed (e.g.
199 //// dragging the top below the bottom)
200 inline void SetDragStatus(wxSashDragStatus status
) { m_dragStatus
= status
; }
201 inline wxSashDragStatus
GetDragStatus() const { return m_dragStatus
; }
203 wxSashEdgePosition m_edge
;
205 wxSashDragStatus m_dragStatus
;
208 typedef void (wxEvtHandler::*wxSashEventFunction
)(wxSashEvent
&);
210 #define EVT_SASH_DRAGGED(id, fn) { wxEVT_SASH_DRAGGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxSashEventFunction) & fn, NULL },
211 #define EVT_SASH_DRAGGED_RANGE(id1, id2, fn) { wxEVT_SASH_DRAGGED, id1, id2, (wxObjectEventFunction) (wxEventFunction) (wxSashEventFunction) & fn, NULL },