Repository navigation
Expand file tree
/
Copy pathTableLayout.h
More file actions
192 lines (163 loc) · 4.36 KB
/
Copy pathTableLayout.h
File metadata and controls
192 lines (163 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/// \file
/// \author Matthew Allen <fret@memecode.com>
/// \brief A control layout manager for font sensitive GUI's.
#ifndef _GTABLE_LAYOUT_H_
#define _GTABLE_LAYOUT_H_
#include "lgi/common/Css.h"
#include "lgi/common/Notifications.h"
#include "lgi/common/Layout.h"
/// A layout cell, not currently implemented.
class LLayoutCell : public LDom, public LCss
{
public:
bool Debug;
LLayoutCell() { Debug = false; }
virtual ~LLayoutCell() {}
const char *GetClass() override { return "LLayoutCell"; }
virtual class LTableLayout *GetTable() = 0;
virtual bool Add(LView *v) = 0;
virtual bool Remove(LView *v) = 0;
virtual LArray<LView*> GetChildren() = 0;
};
/// A table layout control. This uses techniques similar to HTML table layout to set the position
/// and size of the child controls. Child controls exist in a particular cell of the table. Cells
/// can span multiple rows and columns. The only way to create/edit these at the moment is via the lr8
/// resource file and LgiRes.
class LgiClass LTableLayout :
public LLayout,
public ResObject,
public LDom
{
friend class TableCell;
class LTableLayoutPrivate *d;
bool SizeChanged();
public:
/// The system default cell spacing for all tables. Individual tables can have their own
/// cell spacing by setting the CSS property 'border-spacing'.
static int CellSpacing;
LTableLayout(int id = -1);
~LTableLayout();
const char *GetClass() override { return "LTableLayout"; }
LStream &Log();
/// Return the number of cells across (columns).
int CellX();
/// Returns the number of cell high (rows).
int CellY();
/// Returns the cell at a given location.
LLayoutCell *CellAt(int x, int y);
/// Returns area being used by cells
LRect GetUsedArea();
/// Invalidates the layout, causing the control to relay all the children
void InvalidateLayout();
/// Create a cell
LLayoutCell *GetCell(int x, int y, bool create = true, int colspan = 1, int rowspan = 1);
/// Clear all cells;
void Empty(LRect *Range = NULL);
// Impl
void OnFocus(bool b) override;
void OnCreate() override;
void OnPosChange() override;
void OnPaint(LSurface *pDC) override;
bool GetVariant(const char *Name, LVariant &Value, const char *Array = 0) override;
bool SetVariant(const char *Name, LVariant &Value, const char *Array = 0) override;
void OnChildrenChanged(LViewI *Wnd, bool Attaching) override;
int64 Value() override;
void Value(int64 v) override;
int OnNotify(LViewI *c, const LNotification &n) override;
LMessage::Result OnEvent(LMessage *m) override;
};
/// This is just a light-weight layout system for doing things manually.
class LLayoutRect : public LRect
{
int Spacing;
public:
LLayoutRect(LViewI *c, int spacing = LTableLayout::CellSpacing)
{
Spacing = spacing;
((LRect&)*this) = c->GetClient();
Inset(Spacing, Spacing);
}
LLayoutRect(LRect rc, int spacing = LTableLayout::CellSpacing)
{
Spacing = spacing;
((LRect&)*this) = rc;
}
// Allocate object on left edge
// ------------------------------------
LLayoutRect Left(LRect &rc, int Px)
{
rc = *this;
rc.x2 = rc.x1 + Px - 1;
x1 = rc.x2 + Spacing;
return *this;
}
LLayoutRect Left(LViewI *v, int Px)
{
LRect r;
Left(r, Px);
if (v) v->SetPos(r);
return *this;
}
// Allocate on right edge...
// ------------------------------------
LLayoutRect Right(LRect &rc, int Px)
{
rc = *this;
rc.x1 = rc.x2 - Px + 1;
x2 = rc.x1 - Spacing;
return *this;
}
LLayoutRect Right(LViewI *v, int Px)
{
LRect r;
Right(r, Px);
if (v) v->SetPos(r);
return *this;
}
// Allocate on top edge...
// ------------------------------------
LLayoutRect Top(LRect &rc, int Px)
{
rc = *this;
rc.y2 = rc.y1 + Px - 1;
y1 = rc.y2 + Spacing;
return *this;
}
LLayoutRect Top(LViewI *v, int Px)
{
LRect r;
Top(r, Px);
if (v) v->SetPos(r);
return *this;
}
// Allocate on top edge...
// ------------------------------------
LLayoutRect Bottom(LRect &rc, int Px)
{
rc = *this;
rc.y2 = rc.y1 + Px - 1;
y1 = rc.y2 + Spacing;
return *this;
}
LLayoutRect Bottom(LViewI *v, int Px)
{
LRect r;
Bottom(r, Px);
if (v) v->SetPos(r);
return *this;
}
// Allocate all remaining space.
// ------------------------------------
void Remaining(LRect &rc)
{
rc = *this;
ZOff(-1, -1);
}
void Remaining(LViewI *v)
{
if (v)
v->SetPos(*this);
ZOff(-1, -1);
}
};
#endif