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