]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/sashwin.h
Updating corrupt file
[wxWidgets.git] / include / wx / generic / sashwin.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: sashwin.h
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
11 // Licence: wxWindows license
12 /////////////////////////////////////////////////////////////////////////////
13
14 #ifndef _WX_SASHWIN_H_G_
15 #define _WX_SASHWIN_H_G_
16
17 #ifdef __GNUG__
18 #pragma interface "sashwin.h"
19 #endif
20
21 #if wxUSE_SASH
22
23 #include "wx/defs.h"
24 #include "wx/window.h"
25 #include "wx/string.h"
26
27 #define wxSASH_DRAG_NONE 0
28 #define wxSASH_DRAG_DRAGGING 1
29 #define wxSASH_DRAG_LEFT_DOWN 2
30
31 enum wxSashEdgePosition {
32 wxSASH_TOP = 0,
33 wxSASH_RIGHT,
34 wxSASH_BOTTOM,
35 wxSASH_LEFT,
36 wxSASH_NONE = 100
37 };
38
39 /*
40 * wxSashEdge represents one of the four edges of a window.
41 */
42
43 class WXDLLEXPORT wxSashEdge
44 {
45 public:
46 wxSashEdge() { m_show = FALSE; m_border = FALSE; m_margin = 0; }
47
48 bool m_show; // Is the sash showing?
49 bool m_border; // Do we draw a border?
50 int m_margin; // The margin size
51 };
52
53 /*
54 * wxSashWindow flags
55 */
56
57 #define wxSW_3D 0x0004
58
59 /*
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
62 * of wxSashWindow.
63 */
64
65 class WXDLLEXPORT wxSashWindow: public wxWindow
66 {
67 DECLARE_DYNAMIC_CLASS(wxSashWindow)
68
69 public:
70
71 ////////////////////////////////////////////////////////////////////////////
72 // Public API
73
74 // Default constructor
75 wxSashWindow();
76
77 // Normal 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");
80 ~wxSashWindow();
81
82 // Set whether there's a sash in this position
83 void SetSashVisible(wxSashEdgePosition edge, bool sash);
84
85 // Get whether there's a sash in this position
86 inline bool GetSashVisible(wxSashEdgePosition edge) const { return m_sashes[edge].m_show; }
87
88 // Set whether there's a border in this position
89 inline void SetSashBorder(wxSashEdgePosition edge, bool border) { m_sashes[edge].m_border = border; }
90
91 // Get whether there's a border in this position
92 inline bool HasBorder(wxSashEdgePosition edge) const { return m_sashes[edge].m_border; }
93
94 // Get border size
95 inline int GetEdgeMargin(wxSashEdgePosition edge) const { return m_sashes[edge].m_margin; }
96
97 // Sets the default sash border size
98 inline void SetDefaultBorderSize(int width) { m_borderSize = width; }
99
100 // Gets the default sash border size
101 inline int GetDefaultBorderSize() const { return m_borderSize; }
102
103 // Sets the addition border size between child and sash window
104 inline void SetExtraBorderSize(int width) { m_extraBorderSize = width; }
105
106 // Gets the addition border size between child and sash window
107 inline int GetExtraBorderSize() const { return m_extraBorderSize; }
108
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; }
113
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; }
118
119 ////////////////////////////////////////////////////////////////////////////
120 // Implementation
121
122 // Paints the border and sash
123 void OnPaint(wxPaintEvent& event);
124
125 // Handles mouse events
126 void OnMouseEvent(wxMouseEvent& ev);
127
128 // Adjusts the panes
129 void OnSize(wxSizeEvent& event);
130
131 // Draws borders
132 void DrawBorders(wxDC& dc);
133
134 // Draws the sashes
135 void DrawSash(wxSashEdgePosition edge, wxDC& dc);
136
137 // Draws the sashes
138 void DrawSashes(wxDC& dc);
139
140 // Draws the sash tracker (for whilst moving the sash)
141 void DrawSashTracker(wxSashEdgePosition edge, int x, int y);
142
143 // Tests for x, y over sash
144 wxSashEdgePosition SashHitTest(int x, int y, int tolerance = 2);
145
146 // Resizes subwindows
147 void SizeWindows();
148
149 // Initialize colours
150 void InitColours();
151
152 protected:
153 wxSashEdge m_sashes[4];
154 int m_dragMode;
155 wxSashEdgePosition m_draggingEdge;
156 int m_oldX;
157 int m_oldY;
158 int m_borderSize;
159 int m_extraBorderSize;
160 int m_firstX;
161 int m_firstY;
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;
173
174 DECLARE_EVENT_TABLE()
175 };
176
177 #define wxEVT_SASH_DRAGGED (wxEVT_FIRST + 1200)
178
179 enum wxSashDragStatus
180 {
181 wxSASH_STATUS_OK,
182 wxSASH_STATUS_OUT_OF_RANGE
183 };
184
185 class WXDLLEXPORT wxSashEvent: public wxCommandEvent
186 {
187 DECLARE_DYNAMIC_CLASS(wxSashEvent)
188
189 public:
190 inline wxSashEvent(int id = 0, wxSashEdgePosition edge = wxSASH_NONE) {
191 m_eventType = (wxEventType) wxEVT_SASH_DRAGGED; m_id = id; m_edge = edge; }
192
193 inline void SetEdge(wxSashEdgePosition edge) { m_edge = edge; }
194 inline wxSashEdgePosition GetEdge() const { return m_edge; }
195
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; }
199
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; }
204 private:
205 wxSashEdgePosition m_edge;
206 wxRect m_dragRect;
207 wxSashDragStatus m_dragStatus;
208 };
209
210 typedef void (wxEvtHandler::*wxSashEventFunction)(wxSashEvent&);
211
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 },
214
215 #endif // wxUSE_SASH
216
217 #endif
218 // _WX_SASHWIN_H_G_