]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/sashwin.h
Add new wxEVT_COMMAND_WEB_VIEW_TITLE_CHANGED event. Implement for all backends, exten...
[wxWidgets.git] / include / wx / generic / sashwin.h
CommitLineData
a6d70308 1/////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: wx/generic/sashwin.h
a6d70308
JS
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
7// Modified by:
8// Created: 01/02/97
9// RCS-ID: $Id$
10// Copyright: (c) Julian Smart
65571936 11// Licence: wxWindows licence
a6d70308
JS
12/////////////////////////////////////////////////////////////////////////////
13
14#ifndef _WX_SASHWIN_H_G_
15#define _WX_SASHWIN_H_G_
16
88ac883a
VZ
17#if wxUSE_SASH
18
a6d70308
JS
19#include "wx/defs.h"
20#include "wx/window.h"
21#include "wx/string.h"
22
23#define wxSASH_DRAG_NONE 0
24#define wxSASH_DRAG_DRAGGING 1
25#define wxSASH_DRAG_LEFT_DOWN 2
26
27enum wxSashEdgePosition {
28 wxSASH_TOP = 0,
29 wxSASH_RIGHT,
30 wxSASH_BOTTOM,
31 wxSASH_LEFT,
32 wxSASH_NONE = 100
33};
34
35/*
36 * wxSashEdge represents one of the four edges of a window.
37 */
38
12f190b0 39class WXDLLIMPEXP_ADV wxSashEdge
a6d70308
JS
40{
41public:
8cd96c6b
JS
42 wxSashEdge()
43 { m_show = false;
44#if WXWIN_COMPATIBILITY_2_6
45 m_border = false;
46#endif
47 m_margin = 0; }
a6d70308
JS
48
49 bool m_show; // Is the sash showing?
8cd96c6b 50#if WXWIN_COMPATIBILITY_2_6
a6d70308 51 bool m_border; // Do we draw a border?
8cd96c6b 52#endif
a6d70308
JS
53 int m_margin; // The margin size
54};
55
56/*
57 * wxSashWindow flags
58 */
59
448af9a4 60#define wxSW_NOBORDER 0x0000
f6bcfd97 61//#define wxSW_3D 0x0010
448af9a4 62#define wxSW_BORDER 0x0020
f6bcfd97
BP
63#define wxSW_3DSASH 0x0040
64#define wxSW_3DBORDER 0x0080
65#define wxSW_3D (wxSW_3DSASH | wxSW_3DBORDER)
a6d70308
JS
66
67/*
68 * wxSashWindow allows any of its edges to have a sash which can be dragged
69 * to resize the window. The actual content window will be created as a child
70 * of wxSashWindow.
71 */
72
12f190b0 73class WXDLLIMPEXP_ADV wxSashWindow: public wxWindow
a6d70308 74{
a6d70308 75public:
a6d70308 76 // Default constructor
f6bcfd97
BP
77 wxSashWindow()
78 {
79 Init();
80 }
a6d70308
JS
81
82 // Normal constructor
ca65c044 83 wxSashWindow(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
2b5f62a0 84 const wxSize& size = wxDefaultSize, long style = wxSW_3D|wxCLIP_CHILDREN, const wxString& name = wxT("sashWindow"))
f6bcfd97
BP
85 {
86 Init();
87 Create(parent, id, pos, size, style, name);
88 }
89
d3c7fc99 90 virtual ~wxSashWindow();
a6d70308 91
ca65c044 92 bool Create(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
2b5f62a0 93 const wxSize& size = wxDefaultSize, long style = wxSW_3D|wxCLIP_CHILDREN, const wxString& name = wxT("sashWindow"));
f6bcfd97 94
a6d70308
JS
95 // Set whether there's a sash in this position
96 void SetSashVisible(wxSashEdgePosition edge, bool sash);
97
98 // Get whether there's a sash in this position
40717c90 99 bool GetSashVisible(wxSashEdgePosition edge) const { return m_sashes[edge].m_show; }
a6d70308 100
8cd96c6b 101#if WXWIN_COMPATIBILITY_2_6
a6d70308 102 // Set whether there's a border in this position
8cd96c6b 103 // This value is unused in wxSashWindow.
40717c90 104 void SetSashBorder(wxSashEdgePosition edge, bool border) { m_sashes[edge].m_border = border; }
a6d70308
JS
105
106 // Get whether there's a border in this position
8cd96c6b 107 // This value is unused in wxSashWindow.
40717c90 108 bool HasBorder(wxSashEdgePosition edge) const { return m_sashes[edge].m_border; }
8cd96c6b 109#endif
a6d70308
JS
110
111 // Get border size
40717c90 112 int GetEdgeMargin(wxSashEdgePosition edge) const { return m_sashes[edge].m_margin; }
a6d70308
JS
113
114 // Sets the default sash border size
40717c90 115 void SetDefaultBorderSize(int width) { m_borderSize = width; }
a6d70308
JS
116
117 // Gets the default sash border size
40717c90 118 int GetDefaultBorderSize() const { return m_borderSize; }
a6d70308
JS
119
120 // Sets the addition border size between child and sash window
40717c90 121 void SetExtraBorderSize(int width) { m_extraBorderSize = width; }
a6d70308
JS
122
123 // Gets the addition border size between child and sash window
40717c90 124 int GetExtraBorderSize() const { return m_extraBorderSize; }
a6d70308
JS
125
126 virtual void SetMinimumSizeX(int min) { m_minimumPaneSizeX = min; }
127 virtual void SetMinimumSizeY(int min) { m_minimumPaneSizeY = min; }
128 virtual int GetMinimumSizeX() const { return m_minimumPaneSizeX; }
129 virtual int GetMinimumSizeY() const { return m_minimumPaneSizeY; }
130
131 virtual void SetMaximumSizeX(int max) { m_maximumPaneSizeX = max; }
132 virtual void SetMaximumSizeY(int max) { m_maximumPaneSizeY = max; }
133 virtual int GetMaximumSizeX() const { return m_maximumPaneSizeX; }
134 virtual int GetMaximumSizeY() const { return m_maximumPaneSizeY; }
135
136////////////////////////////////////////////////////////////////////////////
137// Implementation
138
139 // Paints the border and sash
140 void OnPaint(wxPaintEvent& event);
141
142 // Handles mouse events
143 void OnMouseEvent(wxMouseEvent& ev);
144
145 // Adjusts the panes
146 void OnSize(wxSizeEvent& event);
147
91ce04cf 148#if defined(__WXMSW__) || defined(__WXMAC__)
2b5f62a0
VZ
149 // Handle cursor correctly
150 void OnSetCursor(wxSetCursorEvent& event);
151#endif // wxMSW
152
a6d70308
JS
153 // Draws borders
154 void DrawBorders(wxDC& dc);
155
156 // Draws the sashes
157 void DrawSash(wxSashEdgePosition edge, wxDC& dc);
158
159 // Draws the sashes
160 void DrawSashes(wxDC& dc);
161
162 // Draws the sash tracker (for whilst moving the sash)
163 void DrawSashTracker(wxSashEdgePosition edge, int x, int y);
164
165 // Tests for x, y over sash
166 wxSashEdgePosition SashHitTest(int x, int y, int tolerance = 2);
167
168 // Resizes subwindows
169 void SizeWindows();
170
171 // Initialize colours
172 void InitColours();
173
f6bcfd97
BP
174private:
175 void Init();
176
a6d70308
JS
177 wxSashEdge m_sashes[4];
178 int m_dragMode;
179 wxSashEdgePosition m_draggingEdge;
180 int m_oldX;
181 int m_oldY;
182 int m_borderSize;
183 int m_extraBorderSize;
184 int m_firstX;
185 int m_firstY;
186 int m_minimumPaneSizeX;
187 int m_minimumPaneSizeY;
188 int m_maximumPaneSizeX;
189 int m_maximumPaneSizeY;
190 wxCursor* m_sashCursorWE;
191 wxCursor* m_sashCursorNS;
192 wxColour m_lightShadowColour;
193 wxColour m_mediumShadowColour;
194 wxColour m_darkShadowColour;
195 wxColour m_hilightColour;
196 wxColour m_faceColour;
621f9767 197 bool m_mouseCaptured;
2b5f62a0 198 wxCursor* m_currentCursor;
a6d70308 199
2b5f62a0
VZ
200private:
201 DECLARE_DYNAMIC_CLASS(wxSashWindow)
202 DECLARE_EVENT_TABLE()
c0c133e1 203 wxDECLARE_NO_COPY_CLASS(wxSashWindow);
a6d70308
JS
204};
205
3c778901
VZ
206class WXDLLIMPEXP_FWD_ADV wxSashEvent;
207
9b11752c 208wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_SASH_DRAGGED, wxSashEvent );
32956769 209
a6d70308
JS
210enum wxSashDragStatus
211{
212 wxSASH_STATUS_OK,
213 wxSASH_STATUS_OUT_OF_RANGE
214};
215
12f190b0 216class WXDLLIMPEXP_ADV wxSashEvent: public wxCommandEvent
a6d70308 217{
2b5f62a0 218public:
40717c90
VZ
219 wxSashEvent(int id = 0, wxSashEdgePosition edge = wxSASH_NONE)
220 {
221 m_eventType = (wxEventType) wxEVT_SASH_DRAGGED;
222 m_id = id;
223 m_edge = edge;
224 }
a6d70308 225
f8a5d9da
FM
226 wxSashEvent(const wxSashEvent& event)
227 : wxCommandEvent(event),
228 m_edge(event.m_edge),
229 m_dragRect(event.m_dragRect),
230 m_dragStatus(event.m_dragStatus) { }
231
40717c90
VZ
232 void SetEdge(wxSashEdgePosition edge) { m_edge = edge; }
233 wxSashEdgePosition GetEdge() const { return m_edge; }
a6d70308
JS
234
235 //// The rectangle formed by the drag operation
40717c90
VZ
236 void SetDragRect(const wxRect& rect) { m_dragRect = rect; }
237 wxRect GetDragRect() const { return m_dragRect; }
a6d70308
JS
238
239 //// Whether the drag caused the rectangle to be reversed (e.g.
240 //// dragging the top below the bottom)
40717c90
VZ
241 void SetDragStatus(wxSashDragStatus status) { m_dragStatus = status; }
242 wxSashDragStatus GetDragStatus() const { return m_dragStatus; }
ca65c044 243
f8a5d9da
FM
244 virtual wxEvent *Clone() const { return new wxSashEvent(*this); }
245
2b5f62a0 246private:
a6d70308
JS
247 wxSashEdgePosition m_edge;
248 wxRect m_dragRect;
249 wxSashDragStatus m_dragStatus;
2b5f62a0
VZ
250
251private:
f8a5d9da 252 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxSashEvent)
a6d70308
JS
253};
254
255typedef void (wxEvtHandler::*wxSashEventFunction)(wxSashEvent&);
256
40717c90 257#define wxSashEventHandler(func) \
3c778901 258 wxEVENT_HANDLER_CAST(wxSashEventFunction, func)
40717c90 259
82a5f02c 260#define EVT_SASH_DRAGGED(id, fn) \
40717c90 261 wx__DECLARE_EVT1(wxEVT_SASH_DRAGGED, id, wxSashEventHandler(fn))
82a5f02c 262#define EVT_SASH_DRAGGED_RANGE(id1, id2, fn) \
40717c90 263 wx__DECLARE_EVT2(wxEVT_SASH_DRAGGED, id1, id2, wxSashEventHandler(fn))
a6d70308 264
88ac883a
VZ
265#endif // wxUSE_SASH
266
a6d70308
JS
267#endif
268 // _WX_SASHWIN_H_G_