]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: splitter.h | |
3 | // Purpose: wxSplitterWindow class | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
0d559d69 | 9 | // Licence: wxWindows license |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef __SPLITTERH_G__ | |
13 | #define __SPLITTERH_G__ | |
14 | ||
15 | #ifdef __GNUG__ | |
16 | #pragma interface "splitter.h" | |
17 | #endif | |
18 | ||
19 | #include "wx/defs.h" | |
20 | #include "wx/window.h" | |
21 | #include "wx/string.h" | |
22 | ||
23 | #define WXSPLITTER_VERSION 1.0 | |
24 | ||
25 | #define wxSPLIT_HORIZONTAL 1 | |
26 | #define wxSPLIT_VERTICAL 2 | |
27 | ||
28 | #define wxSPLIT_DRAG_NONE 0 | |
29 | #define wxSPLIT_DRAG_DRAGGING 1 | |
30 | #define wxSPLIT_DRAG_LEFT_DOWN 2 | |
31 | ||
32 | /* | |
33 | * wxSplitterWindow maintains one or two panes, with | |
34 | * an optional vertical or horizontal split which | |
35 | * can be used with the mouse or programmatically. | |
36 | */ | |
37 | ||
38 | // TODO: | |
39 | // 1) Perhaps make the borders sensitive to dragging in order to create a split. | |
40 | // The MFC splitter window manages scrollbars as well so is able to | |
41 | // put sash buttons on the scrollbars, but we probably don't want to go down | |
42 | // this path. | |
43 | // 2) for wxWindows 2.0, we must find a way to set the WS_CLIPCHILDREN style | |
44 | // to prevent flickering. (WS_CLIPCHILDREN doesn't work in all cases so can't be | |
45 | // standard). | |
46 | ||
47 | class WXDLLEXPORT wxSplitterWindow: public wxWindow | |
48 | { | |
0d559d69 | 49 | public: |
c801d85f KB |
50 | |
51 | //////////////////////////////////////////////////////////////////////////// | |
52 | // Public API | |
53 | ||
54 | // Default constructor | |
0d559d69 | 55 | wxSplitterWindow(); |
c801d85f KB |
56 | |
57 | // Normal constructor | |
0d559d69 VZ |
58 | wxSplitterWindow(wxWindow *parent, wxWindowID id = -1, |
59 | const wxPoint& pos = wxDefaultPosition, | |
60 | const wxSize& size = wxDefaultSize, | |
61 | long style = wxSP_3D|wxCLIP_CHILDREN, | |
62 | const wxString& name = "splitter"); | |
63 | ~wxSplitterWindow(); | |
c801d85f KB |
64 | |
65 | // Gets the only or left/top pane | |
0d559d69 | 66 | wxWindow *GetWindow1() const { return m_windowOne; } |
c801d85f KB |
67 | |
68 | // Gets the right/bottom pane | |
0d559d69 | 69 | wxWindow *GetWindow2() const { return m_windowTwo; } |
c801d85f KB |
70 | |
71 | // Sets the split mode | |
0d559d69 | 72 | void SetSplitMode(int mode) { m_splitMode = mode; } |
c801d85f KB |
73 | |
74 | // Gets the split mode | |
0d559d69 | 75 | int GetSplitMode() const { return m_splitMode; }; |
c801d85f KB |
76 | |
77 | // Initialize with one window | |
78 | void Initialize(wxWindow *window); | |
79 | ||
80 | // Associates the given window with window 2, drawing the appropriate sash | |
81 | // and changing the split mode. | |
82 | // Does nothing and returns FALSE if the window is already split. | |
0d559d69 VZ |
83 | // A sashPosition of 0 means choose a default sash position, |
84 | // negative sashPosition specifies the size of right/lower pane as it's | |
85 | // absolute value rather than the size of left/upper pane. | |
cce4b3fe VZ |
86 | virtual bool SplitVertically(wxWindow *window1, |
87 | wxWindow *window2, | |
88 | int sashPosition = 0); | |
89 | virtual bool SplitHorizontally(wxWindow *window1, | |
90 | wxWindow *window2, | |
91 | int sashPosition = 0); | |
c801d85f KB |
92 | |
93 | // Removes the specified (or second) window from the view | |
94 | // Doesn't actually delete the window. | |
c67daf87 | 95 | bool Unsplit(wxWindow *toRemove = (wxWindow *) NULL); |
c801d85f | 96 | |
3ad5e06b VZ |
97 | // Replaces one of the windows with another one (neither old nor new |
98 | // parameter should be NULL) | |
99 | bool ReplaceWindow(wxWindow *winOld, wxWindow *winNew); | |
100 | ||
c801d85f | 101 | // Is the window split? |
0d559d69 | 102 | bool IsSplit() const { return (m_windowTwo != NULL); } |
c801d85f KB |
103 | |
104 | // Sets the sash size | |
0d559d69 | 105 | void SetSashSize(int width) { m_sashSize = width; } |
c801d85f KB |
106 | |
107 | // Sets the border size | |
0d559d69 | 108 | void SetBorderSize(int width) { m_borderSize = width; } |
c801d85f KB |
109 | |
110 | // Gets the sash size | |
0d559d69 | 111 | int GetSashSize() const { return m_sashSize; } |
c801d85f KB |
112 | |
113 | // Gets the border size | |
0d559d69 | 114 | int GetBorderSize() const { return m_borderSize; } |
c801d85f KB |
115 | |
116 | // Set the sash position | |
debe6624 | 117 | void SetSashPosition(int position, bool redaw = TRUE); |
c801d85f KB |
118 | |
119 | // Gets the sash position | |
0d559d69 | 120 | int GetSashPosition() const { return m_sashPosition; } |
c801d85f KB |
121 | |
122 | // If this is zero, we can remove panes by dragging the sash. | |
0d559d69 VZ |
123 | void SetMinimumPaneSize(int min) { m_minimumPaneSize = min; } |
124 | int GetMinimumPaneSize() const { return m_minimumPaneSize; } | |
125 | ||
126 | // Called when the sash position is about to be changed, return | |
127 | // FALSE from here to prevent the change from taking place. | |
021e7626 | 128 | // Repositions sash to minimum position if pane would be too small. |
0d559d69 | 129 | // newSashPosition here is always positive or zero. |
021e7626 | 130 | virtual bool OnSashPositionChange(int& newSashPosition); |
c801d85f KB |
131 | |
132 | // If the sash is moved to an extreme position, a subwindow | |
133 | // is removed from the splitter window, and the app is | |
134 | // notified. The app should delete or hide the window. | |
135 | virtual void OnUnsplit(wxWindow *removed) { removed->Show(FALSE); } | |
136 | ||
137 | // Called when the sash is double-clicked. | |
138 | // The default behaviour is to remove the sash if the | |
139 | // minimum pane size is zero. | |
140 | virtual void OnDoubleClickSash(int x, int y); | |
141 | ||
142 | //////////////////////////////////////////////////////////////////////////// | |
143 | // Implementation | |
144 | ||
145 | // Paints the border and sash | |
146 | void OnPaint(wxPaintEvent& event); | |
147 | ||
148 | // Handles mouse events | |
149 | void OnMouseEvent(wxMouseEvent& ev); | |
150 | ||
151 | // Adjusts the panes | |
152 | void OnSize(wxSizeEvent& event); | |
153 | ||
154 | // Draws borders | |
155 | void DrawBorders(wxDC& dc); | |
156 | ||
157 | // Draws the sash | |
158 | void DrawSash(wxDC& dc); | |
159 | ||
160 | // Draws the sash tracker (for whilst moving the sash) | |
debe6624 | 161 | void DrawSashTracker(int x, int y); |
c801d85f KB |
162 | |
163 | // Tests for x, y over sash | |
debe6624 | 164 | bool SashHitTest(int x, int y, int tolerance = 2); |
c801d85f KB |
165 | |
166 | // Resizes subwindows | |
0d559d69 | 167 | void SizeWindows(); |
c801d85f KB |
168 | |
169 | // Initialize colours | |
0d559d69 | 170 | void InitColours(); |
c801d85f | 171 | |
0d559d69 | 172 | protected: |
c801d85f KB |
173 | int m_splitMode; |
174 | wxWindow* m_windowOne; | |
175 | wxWindow* m_windowTwo; | |
176 | int m_dragMode; | |
177 | int m_oldX; | |
178 | int m_oldY; | |
179 | int m_borderSize; | |
180 | int m_sashSize; // Sash width or height | |
181 | int m_sashPosition; // Number of pixels from left or top | |
182 | int m_firstX; | |
183 | int m_firstY; | |
184 | int m_minimumPaneSize; | |
185 | wxCursor* m_sashCursorWE; | |
186 | wxCursor* m_sashCursorNS; | |
187 | wxPen* m_sashTrackerPen; | |
188 | wxPen* m_lightShadowPen; | |
189 | wxPen* m_mediumShadowPen; | |
190 | wxPen* m_darkShadowPen; | |
191 | wxPen* m_hilightPen; | |
192 | wxBrush* m_faceBrush; | |
193 | wxPen* m_facePen; | |
0d559d69 VZ |
194 | |
195 | private: | |
196 | DECLARE_DYNAMIC_CLASS(wxSplitterWindow) | |
197 | DECLARE_EVENT_TABLE() | |
c801d85f KB |
198 | }; |
199 | ||
0d559d69 | 200 | #endif // __SPLITTERH_G__ |