]> git.tdb.fi Git - libs/gltk.git/blob - source/arrangement.h
31001c4d081686e8932e68acf541f1a0b6fb957e
[libs/gltk.git] / source / arrangement.h
1 #ifndef MSP_GLTK_ARRANGEMENT_H_
2 #define MSP_GLTK_ARRANGEMENT_H_
3
4 #include <list>
5 #include <stdexcept>
6 #include "layout.h"
7 #include "mspgltk_api.h"
8
9 namespace Msp {
10 namespace GLtk {
11
12 class Widget;
13
14 class MSPGLTK_API arrangement_error: public std::logic_error
15 {
16 public:
17         arrangement_error(const std::string &w): std::logic_error(w) { }
18         virtual ~arrangement_error() throw() { }
19 };
20
21 class MSPGLTK_API Arrangement
22 {
23 protected:
24         enum Side
25         {
26                 TOP,
27                 RIGHT,
28                 BOTTOM,
29                 LEFT
30         };
31
32         struct Edge
33         {
34                 std::list<Widget *> widgets;
35                 bool aligned;
36
37                 Edge();
38
39                 bool empty() { return widgets.empty(); }
40                 void clear();
41                 void add(Widget &, bool);
42                 void align();
43         };
44
45         Layout &layout;
46         Arrangement *parent;
47         Edge edges[4];
48
49         Arrangement(Layout &);
50 public:
51         virtual ~Arrangement();
52
53         void arrange(Widget &);
54         void arrange(Arrangement &);
55
56 protected:
57         virtual void process_widget(Widget &, Side, bool) = 0;
58         virtual void finish_widget(Widget &) = 0;
59         virtual void finish_slot() = 0;
60         const Edge &get_edge(Side s) const { return edges[s]; }
61         void add_constraint(Widget &, Layout::ConstraintType, Side, int = -1);
62         void add_constraint(Widget &, Layout::ConstraintType, const Edge &, int = -1);
63
64         static Layout::ConstraintType get_order_constraint(Side, bool);
65         static Layout::ConstraintType get_align_constraint(Side);
66 };
67
68 } // namespace GLtk
69 } // namespace Msp
70
71 #endif