1 /********************************************************************************
2 *                                                                               *
3 *                       F o u r - W a y   S p l i t t e r                       *
4 *                                                                               *
5 *********************************************************************************
6 * Copyright (C) 1999,2021 by Jeroen van der Zijp.   All Rights Reserved.        *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify          *
9 * it under the terms of the GNU Lesser General Public License as published by   *
10 * the Free Software Foundation; either version 3 of the License, or             *
11 * (at your option) any later version.                                           *
12 *                                                                               *
13 * This library is distributed in the hope that it will be useful,               *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
16 * GNU Lesser General Public License for more details.                           *
17 *                                                                               *
18 * You should have received a copy of the GNU Lesser General Public License      *
19 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
20 ********************************************************************************/
21 #ifndef FX4SPLITTER_H
22 #define FX4SPLITTER_H
23 
24 #ifndef FXCOMPOSITE_H
25 #include "FXComposite.h"
26 #endif
27 
28 namespace FX {
29 
30 // Splitter options
31 enum {
32   FOURSPLITTER_TRACKING   = 0x00008000,	// Track continuously during split
33   FOURSPLITTER_VERTICAL   = 0x00010000, // Prefer vertial expansion of panels
34   FOURSPLITTER_HORIZONTAL = 0,          // Prefer horizontal expansion of panels (default)
35   FOURSPLITTER_NORMAL     = 0
36   };
37 
38 
39 
40 /**
41 * The four-way splitter is a layout manager which manages
42 * four children like four panes in a window.
43 * You can use a four-way splitter for example in a CAD program
44 * where you may want to maintain three orthographic views, and
45 * one oblique view of a model.
46 * The four-way splitter allows interactive repartitioning of the
47 * panes by means of moving the central splitter bars.
48 * When the four-way splitter is itself resized, each child is
49 * proportionally resized, maintaining the same split-percentage.
50 * The four-way splitter widget sends a SEL_CHANGED to its target
51 * during the resizing of the panes; at the end of the resize interaction,
52 * it sends a SEL_COMMAND to signify that the resize operation is complete.
53 * It is possible to expand or collapse one or more of the sub-panes of the
54 * four-way splitter; by default, all four panes are expanded.
55 * When a pane is collapsed, the remaining panes will fill the space left.
56 * If the FOURSPLITTER_HORIZONTAL flag is in effect (default), the remaining
57 * panels expand horizontally to fill the space; conversely, if FOURSPLITTER_VERTICAL
58 * is passed then the remaining panels will expand vertically to accomodate the extra
59 * space.
60 * The flag FOURSPLITTER_TRACKING causes the contents to be redrawn interactively as
61 * the split-division is adjusted; otherwise the contents will be redrawn only after
62 * the resizing is finished.
63 */
64 class FXAPI FX4Splitter : public FXComposite {
65   FXDECLARE(FX4Splitter)
66 private:
67   FXint     splitx;         // Current x split
68   FXint     splity;         // Current y split
69   FXint     barsize;        // Size of the splitter bar
70   FXint     fhor;           // Horizontal split fraction
71   FXint     fver;           // Vertical split fraction
72   FXint     offx;
73   FXint     offy;
74   FXuchar   mode;
75 protected:
76   FX4Splitter();
77   FXuchar getMode(FXint x,FXint y);
78   void moveSplit(FXint x,FXint y);
79   void drawSplit(FXint x,FXint y,FXuint m);
80   void adjustLayout();
81 private:
82   FX4Splitter(const FX4Splitter&);
83   FX4Splitter &operator=(const FX4Splitter&);
84 public:
85   long onLeftBtnPress(FXObject*,FXSelector,void*);
86   long onLeftBtnRelease(FXObject*,FXSelector,void*);
87   long onMotion(FXObject*,FXSelector,void*);
88   long onFocusUp(FXObject*,FXSelector,void*);
89   long onFocusDown(FXObject*,FXSelector,void*);
90   long onFocusLeft(FXObject*,FXSelector,void*);
91   long onFocusRight(FXObject*,FXSelector,void*);
92   long onCmdExpand(FXObject*,FXSelector,void*);
93   long onUpdExpand(FXObject*,FXSelector,void*);
94 public:
95   enum {
96     ExpandNone        = 0,                                  /// None expanded
97     ExpandTopLeft     = 1,                                  /// Expand top left child
98     ExpandTopRight    = 2,                                  /// Expand top right child
99     ExpandBottomLeft  = 4,                                  /// Expand bottom left child
100     ExpandBottomRight = 8,                                  /// Expand bottom right child
101     ExpandTop         = ExpandTopLeft|ExpandTopRight,       /// Expand top children
102     ExpandBottom      = ExpandBottomLeft|ExpandBottomRight, /// Expand bottom children
103     ExpandLeft        = ExpandTopLeft|ExpandBottomLeft,     /// Expand left children
104     ExpandRight       = ExpandTopRight|ExpandBottomRight,   /// Expand right children
105     ExpandCriss       = ExpandTopRight|ExpandBottomLeft,    /// Expand diagonally opposing children
106     ExpandCross       = ExpandTopLeft|ExpandBottomRight,    /// Expand diagonally opposing children
107     ExpandAll         = ExpandLeft|ExpandRight              /// Expand all children
108     };
109 public:
110   enum {
111     ID_EXPAND_NONE=FXComposite::ID_LAST+ExpandNone,
112     ID_EXPAND_TOP=ID_EXPAND_NONE+ExpandTop,
113     ID_EXPAND_BOTTOM=ID_EXPAND_NONE+ExpandBottom,
114     ID_EXPAND_LEFT=ID_EXPAND_NONE+ExpandLeft,
115     ID_EXPAND_RIGHT=ID_EXPAND_NONE+ExpandRight,
116     ID_EXPAND_TOPLEFT=ID_EXPAND_NONE+ExpandTopLeft,
117     ID_EXPAND_TOPRIGHT=ID_EXPAND_NONE+ExpandTopRight,
118     ID_EXPAND_BOTTOMLEFT=ID_EXPAND_NONE+ExpandBottomLeft,
119     ID_EXPAND_BOTTOMRIGHT=ID_EXPAND_NONE+ExpandBottomRight,
120     ID_EXPAND_ALL=ID_EXPAND_NONE+ExpandAll,
121     ID_LAST
122     };
123 public:
124 
125   /// Create 4-way splitter, initially shown as four unexpanded panes
126   FX4Splitter(FXComposite* p,FXuint opts=FOURSPLITTER_NORMAL,FXint x=0,FXint y=0,FXint w=0,FXint h=0);
127 
128   /// Create 4-way splitter, initially shown as four unexpanded panes; notifies target about size changes
129   FX4Splitter(FXComposite* p,FXObject* tgt,FXSelector sel,FXuint opts=FOURSPLITTER_NORMAL,FXint x=0,FXint y=0,FXint w=0,FXint h=0);
130 
131   /// Get top left child, if any
132   FXWindow *getTopLeft() const;
133 
134   /// Get top right child, if any
135   FXWindow *getTopRight() const;
136 
137   /// Get bottom left child, if any
138   FXWindow *getBottomLeft() const;
139 
140   /// Get bottom right child, if any
141   FXWindow *getBottomRight() const;
142 
143   /// Get horizontal split fraction
getHSplit()144   FXint getHSplit() const { return fhor; }
145 
146   /// Get vertical split fraction
getVSplit()147   FXint getVSplit() const { return fver; }
148 
149   /// Change horizontal split fraction
150   void setHSplit(FXint s);
151 
152   /// Change vertical split fraction
153   void setVSplit(FXint s);
154 
155   /// Perform layout
156   virtual void layout();
157 
158   /// Get default width
159   virtual FXint getDefaultWidth();
160 
161   /// Get default height
162   virtual FXint getDefaultHeight();
163 
164   /// Return current splitter style
165   FXuint getSplitterStyle() const;
166 
167   /// Change splitter style
168   void setSplitterStyle(FXuint style);
169 
170   /// Change splitter bar width
171   void setBarSize(FXint bs);
172 
173   /// Get splitter bar width
getBarSize()174   FXint getBarSize() const { return barsize; }
175 
176   /// Change set of expanded children
177   void setExpanded(FXuint set=FX4Splitter::ExpandAll);
178 
179   /// Get set of expanded children
180   FXuint getExpanded() const;
181 
182   /// Save to stream
183   virtual void save(FXStream& store) const;
184 
185   /// Load from stream
186   virtual void load(FXStream& store);
187   };
188 
189 }
190 
191 #endif
192