]> git.lyx.org Git - features.git/blob - src/frontends/xforms/LayoutEngine.h
c15379eda5e7d5ebf92ecb6dec585d5896f0fdb2
[features.git] / src / frontends / xforms / LayoutEngine.h
1 // -*- C++ -*-
2 /**
3  * \file LayoutEngine.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  *
11  * A generic layout engine that draws heavily on GTK+.
12  */
13
14 #ifndef LAYOUT_ENGINE_H
15 #define LAYOUT_ENGINE_H
16
17 #include "forms_fwd.h"
18 #include <list>
19 #include <map>
20
21 namespace lyx {
22 namespace frontend {
23
24 class Box;
25
26 class BoxList {
27 public:
28         typedef std::list<Box> Container;
29         typedef Container::size_type size_type;
30         typedef Container::iterator iterator;
31         typedef Container::const_iterator const_iterator;
32
33         bool empty() const;
34         size_type size() const;
35
36         void clear();
37         Box & push_back(Box const &);
38
39         iterator begin();
40         iterator end();
41
42         const_iterator begin() const;
43         const_iterator end() const;
44
45         iterator erase(iterator where);
46         iterator erase(iterator begin, iterator end);
47
48 private:
49         Container data_;
50 };
51
52
53 class Box {
54 public:
55         typedef unsigned int dimension_t;
56
57         /** \param min_w the minimum allowed width of the box.
58          *  \param min_h the minimum allowed height of the box.
59          */
60         Box(dimension_t min_w, dimension_t min_h);
61
62         void setMinimumDimensions(dimension_t min_w, dimension_t min_h);
63
64         /** \name Child Orientation
65          *  The enum prescribes whether children are aligned
66          *  horizontally or vertically.
67          */
68         //@{
69         enum Orientation {
70                 Vertical,
71                 Horizontal
72         };
73
74         Orientation orientation() const;
75         void set(Orientation);
76
77         /// Initially set to Vertical
78         static Orientation defaultOrientation();
79         static void setDefault(Orientation);
80         //@}
81
82         /** \name Packing
83          *  Do the children receive extra space when the parent grows?
84          */
85         //@{
86         enum Packing {
87                 Shrink,
88                 Expand
89         };
90
91         Packing packing() const;
92         void set(Packing);
93
94         /// Initially set to Shrink
95         static Packing defaultPacking();
96         static void setDefault(Packing);
97
98         /** returns true if this Box or any of its children have
99          *  packing() == Expand.
100          */
101         bool expandable() const;
102         //@}
103
104         /** \name Prefered Visibility
105          *  If the parent container is visible, should this Box be
106          *  visible or not?
107          */
108         //@{
109         enum PreferedVisibility {
110                 Visible,
111                 Invisible
112         };
113
114         PreferedVisibility preferedVisibility() const;
115         /// If \pv == Invisible, also calls hide().
116         void set(PreferedVisibility pv);
117         //@}
118
119         /** \name Actual Visibility
120          */
121         //@{
122         bool visible() const;
123         /// Does nothing if preferedVisibility() == Invisible.
124         void show();
125         /// Always hides.
126         void hide();
127         //@}
128
129         BoxList & children();
130         BoxList const & children() const;
131
132         dimension_t width() const;
133         dimension_t height() const;
134         dimension_t xorigin() const;
135         dimension_t yorigin() const;
136
137         void updateMetrics();
138
139 private:
140         void shrinkMetrics();
141         void expandMetrics(dimension_t x, dimension_t y,
142                            dimension_t w, dimension_t h);
143         void expandHbox(dimension_t x, dimension_t y,
144                         dimension_t w, dimension_t h);
145         void expandVbox(dimension_t x, dimension_t y,
146                         dimension_t w, dimension_t h);
147
148         static Orientation default_orientation_;
149         static Packing default_packing_;
150
151         BoxList children_;
152         bool visible_;
153         dimension_t min_w_;
154         dimension_t min_h_;
155         dimension_t w_;
156         dimension_t h_;
157         dimension_t x_;
158         dimension_t y_;
159         Orientation orientation_;
160         Packing packing_;
161         PreferedVisibility prefered_visibility_;
162 };
163
164
165 class WidgetMap {
166 public:
167         typedef Box::dimension_t dimension_t;
168
169         /// \returns the just-added Box.
170         Box & add(FL_OBJECT * widget, BoxList & container,
171                   dimension_t min_w, dimension_t min_h); 
172         void updateMetrics() const;
173
174 private:
175         typedef std::map<FL_OBJECT *, Box *> DataMap;
176         DataMap widgets_;
177 };
178
179
180 /** Embed \c ob in \c container inside a border of width \c bw.
181  *  Thereafter, hand control of its metrics to \c widgets.
182  *  \returns the Box containing \c ob.
183  */
184 Box & embed(FL_OBJECT * ob, BoxList & container, WidgetMap & widgets, int bw);
185
186 } // namespace frontend
187 } // namespace lyx
188
189 #endif // NOT LAYOUT_ENGINE_H