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"
24 #include "wx/window.h"
25 #include "wx/string.h"
27 #define wxSASH_DRAG_NONE 0
28 #define wxSASH_DRAG_DRAGGING 1
29 #define wxSASH_DRAG_LEFT_DOWN 2
31 enum wxSashEdgePosition
{
40 * wxSashEdge represents one of the four edges of a window.
43 class WXDLLEXPORT wxSashEdge
46 wxSashEdge() { m_show
= FALSE
; m_border
= FALSE
; m_margin
= 0; }
48 bool m_show
; // Is the sash showing?
49 bool m_border
; // Do we draw a border?
50 int m_margin
; // The margin size
57 #define wxSW_3D 0x0004
60 * wxSashWindow allows any of its edges to have a sash which can be dragged
61 * to resize the window. The actual content window will be created as a child
65 class WXDLLEXPORT wxSashWindow
: public wxWindow
67 DECLARE_DYNAMIC_CLASS(wxSashWindow
)
71 ////////////////////////////////////////////////////////////////////////////
74 // Default constructor
78 wxSashWindow(wxWindow
*parent
, wxWindowID id
= -1, const wxPoint
& pos
= wxDefaultPosition
,
79 const wxSize
& size
= wxDefaultSize
, long style
= wxSW_3D
|wxCLIP_CHILDREN
, const wxString
& name
= "sashWindow");
82 // Set whether there's a sash in this position
83 void SetSashVisible(wxSashEdgePosition edge
, bool sash
);
85 // Get whether there's a sash in this position
86 inline bool GetSashVisible(wxSashEdgePosition edge
) const { return m_sashes
[edge
].m_show
; }
88 // Set whether there's a border in this position
89 inline void SetSashBorder(wxSashEdgePosition edge
, bool border
) { m_sashes
[edge
].m_border
= border
; }
91 // Get whether there's a border in this position
92 inline bool HasBorder(wxSashEdgePosition edge
) const { return m_sashes
[edge
].m_border
; }
95 inline int GetEdgeMargin(wxSashEdgePosition edge
) const { return m_sashes
[edge
].m_margin
; }
97 // Sets the default sash border size
98 inline void SetDefaultBorderSize(int width
) { m_borderSize
= width
; }
100 // Gets the default sash border size
101 inline int GetDefaultBorderSize() const { return m_borderSize
; }
103 // Sets the addition border size between child and sash window
104 inline void SetExtraBorderSize(int width
) { m_extraBorderSize
= width
; }
106 // Gets the addition border size between child and sash window
107 inline int GetExtraBorderSize() const { return m_extraBorderSize
; }
109 virtual void SetMinimumSizeX(int min
) { m_minimumPaneSizeX
= min
; }
110 virtual void SetMinimumSizeY(int min
) { m_minimumPaneSizeY
= min
; }
111 virtual int GetMinimumSizeX() const { return m_minimumPaneSizeX
; }
112 virtual int GetMinimumSizeY() const { return m_minimumPaneSizeY
; }
114 virtual void SetMaximumSizeX(int max
) { m_maximumPaneSizeX
= max
; }
115 virtual void SetMaximumSizeY(int max
) { m_maximumPaneSizeY
= max
; }
116 virtual int GetMaximumSizeX() const { return m_maximumPaneSizeX
; }
117 virtual int GetMaximumSizeY() const { return m_maximumPaneSizeY
; }
119 ////////////////////////////////////////////////////////////////////////////
122 // Paints the border and sash
123 void OnPaint(wxPaintEvent
& event
);
125 // Handles mouse events
126 void OnMouseEvent(wxMouseEvent
& ev
);
129 void OnSize(wxSizeEvent
& event
);
132 void DrawBorders(wxDC
& dc
);
135 void DrawSash(wxSashEdgePosition edge
, wxDC
& dc
);
138 void DrawSashes(wxDC
& dc
);
140 // Draws the sash tracker (for whilst moving the sash)
141 void DrawSashTracker(wxSashEdgePosition edge
, int x
, int y
);
143 // Tests for x, y over sash
144 wxSashEdgePosition
SashHitTest(int x
, int y
, int tolerance
= 2);
146 // Resizes subwindows
149 // Initialize colours
153 wxSashEdge m_sashes
[4];
155 wxSashEdgePosition m_draggingEdge
;
159 int m_extraBorderSize
;
162 int m_minimumPaneSizeX
;
163 int m_minimumPaneSizeY
;
164 int m_maximumPaneSizeX
;
165 int m_maximumPaneSizeY
;
166 wxCursor
* m_sashCursorWE
;
167 wxCursor
* m_sashCursorNS
;
168 wxColour m_lightShadowColour
;
169 wxColour m_mediumShadowColour
;
170 wxColour m_darkShadowColour
;
171 wxColour m_hilightColour
;
172 wxColour m_faceColour
;
174 DECLARE_EVENT_TABLE()
177 #define wxEVT_SASH_DRAGGED (wxEVT_FIRST + 1200)
179 enum wxSashDragStatus
182 wxSASH_STATUS_OUT_OF_RANGE
185 class WXDLLEXPORT wxSashEvent
: public wxCommandEvent
187 DECLARE_DYNAMIC_CLASS(wxSashEvent
)
190 inline wxSashEvent(int id
= 0, wxSashEdgePosition edge
= wxSASH_NONE
) {
191 m_eventType
= (wxEventType
) wxEVT_SASH_DRAGGED
; m_id
= id
; m_edge
= edge
; }
193 inline void SetEdge(wxSashEdgePosition edge
) { m_edge
= edge
; }
194 inline wxSashEdgePosition
GetEdge() const { return m_edge
; }
196 //// The rectangle formed by the drag operation
197 inline void SetDragRect(const wxRect
& rect
) { m_dragRect
= rect
; }
198 inline wxRect
GetDragRect() const { return m_dragRect
; }
200 //// Whether the drag caused the rectangle to be reversed (e.g.
201 //// dragging the top below the bottom)
202 inline void SetDragStatus(wxSashDragStatus status
) { m_dragStatus
= status
; }
203 inline wxSashDragStatus
GetDragStatus() const { return m_dragStatus
; }
205 wxSashEdgePosition m_edge
;
207 wxSashDragStatus m_dragStatus
;
210 typedef void (wxEvtHandler::*wxSashEventFunction
)(wxSashEvent
&);
212 #define EVT_SASH_DRAGGED(id, fn) { wxEVT_SASH_DRAGGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxSashEventFunction) & fn, NULL },
213 #define EVT_SASH_DRAGGED_RANGE(id1, id2, fn) { wxEVT_SASH_DRAGGED, id1, id2, (wxObjectEventFunction) (wxEventFunction) (wxSashEventFunction) & fn, NULL },