1 /********************************************************************************
2 *                                                                               *
3 *                S p l i t t e r   W i n d o w   W i d g e t                    *
4 *                                                                               *
5 *********************************************************************************
6 * Copyright (C) 1997,2020 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 FXSPLITTER_H
22 #define FXSPLITTER_H
23 
24 #ifndef FXCOMPOSITE_H
25 #include "FXComposite.h"
26 #endif
27 
28 namespace FX {
29 
30 
31 /// Splitter options
32 enum {
33   SPLITTER_HORIZONTAL = 0,                  /// Split horizontally
34   SPLITTER_VERTICAL   = 0x00008000,         /// Split vertically
35   SPLITTER_REVERSED   = 0x00010000,         /// Reverse-anchored
36   SPLITTER_TRACKING   = 0x00020000,         /// Track continuous during split
37   SPLITTER_NORMAL     = SPLITTER_HORIZONTAL
38   };
39 
40 
41 
42 /**
43 * Splitter window is used to interactively repartition
44 * two or more subpanels.
45 * Space may be subdivided horizontally (SPLITTER_HORIZONTAL, which
46 * the default) or vertically (SPLITTER_VERTICAL option).
47 * When the splitter is itself resized, the right-most (bottom-most)
48 * child window will be resized unless the splitter window is reversed;
49 * if the splitter is reversed, the left-most (top-most) child window
50 * will be resized instead.
51 * The splitter widget sends a SEL_CHANGED to its target
52 * during the resizing of the panels; at the end of the resize interaction,
53 * it sends a SEL_COMMAND to signify that the resize operation is complete.
54 * Normally, children are resizable from 0 upwards; however, if the child
55 * in a horizontally oriented splitter has LAYOUT_FILL_X in combination with
56 * LAYOUT_FIX_WIDTH, it will not be made smaller than its default width,
57 * except when the child is the last visible widget (or first when the option
58 * SPLITTER_REVERSED has been passed to the splitter).
59 * In a vertically oriented splitter, children with LAYOUT_FILL_Y and
60 * LAYOUT_FIX_HEIGHT behave analogously.
61 */
62 class FXAPI FXSplitter : public FXComposite {
63   FXDECLARE(FXSplitter)
64 private:
65   FXWindow *window;         // Window being resized
66   FXint     split;          // Split value
67   FXint     offset;         // Mouse offset
68   FXint     barsize;        // Size of the splitter bar
69 protected:
70   FXSplitter();
71   void adjustHLayout();
72   void adjustVLayout();
73   void moveHSplit(FXint amount);
74   void moveVSplit(FXint amount);
75   void drawHSplit(FXint pos);
76   void drawVSplit(FXint pos);
77   FXWindow* findHSplit(FXint pos);
78   FXWindow* findVSplit(FXint pos);
79 private:
80   FXSplitter(const FXSplitter&);
81   FXSplitter& operator=(const FXSplitter&);
82 public:
83   long onLeftBtnPress(FXObject*,FXSelector,void*);
84   long onLeftBtnRelease(FXObject*,FXSelector,void*);
85   long onMotion(FXObject*,FXSelector,void*);
86   long onFocusNext(FXObject*,FXSelector,void*);
87   long onFocusPrev(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 public:
93 
94   /// Construct new splitter widget
95   FXSplitter(FXComposite* p,FXuint opts=SPLITTER_NORMAL,FXint x=0,FXint y=0,FXint w=0,FXint h=0);
96 
97   /// Construct new splitter widget, which will notify target about size changes
98   FXSplitter(FXComposite* p,FXObject* tgt,FXSelector sel,FXuint opts=SPLITTER_NORMAL,FXint x=0,FXint y=0,FXint w=0,FXint h=0);
99 
100   /// Get default width
101   virtual FXint getDefaultWidth();
102 
103   /// Get default height
104   virtual FXint getDefaultHeight();
105 
106   /// Perform layout
107   virtual void layout();
108 
109   /// Return size of the panel at index
110   FXint getSplit(FXint index) const;
111 
112   /// Change the size of panel at the given index
113   void setSplit(FXint index,FXint size);
114 
115   /// Change splitter style
116   void setSplitterStyle(FXuint style);
117 
118   /// Return current splitter style
119   FXuint getSplitterStyle() const;
120 
121   /// Change splitter bar size
122   void setBarSize(FXint bs);
123 
124   /// Return current bar size
getBarSize()125   FXint getBarSize() const { return barsize; }
126 
127   /// Save to stream
128   virtual void save(FXStream& store) const;
129 
130   /// Load from stream
131   virtual void load(FXStream& store);
132 
133   /// Destroy splitter
134   virtual ~FXSplitter();
135   };
136 
137 }
138 
139 #endif
140