2
* Copyright 2010 Inalogic Inc.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License version 3, as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the applicable version of the GNU Lesser General Public
12
* License for more details.
14
* You should have received a copy of both the GNU Lesser General Public
15
* License version 3 along with this program. If not, see
16
* <http://www.gnu.org/licenses/>
18
* Authored by: Jay Taoko <jay.taoko_AT_gmail_DOT_com>
29
GroupBox::GroupBox(const TCHAR* Caption)
30
: bCaptionAvailable(false)
33
m_CaptionArea.SetMinimumSize(DEFAULT_WIDGET_WIDTH, PRACTICAL_WIDGET_HEIGHT);
34
m_CaptionArea.SetBaseSize(DEFAULT_WIDGET_WIDTH, PRACTICAL_WIDGET_HEIGHT);
36
SetMinimumSize(DEFAULT_WIDGET_WIDTH+5, PRACTICAL_WIDGET_HEIGHT+5);
37
SetBaseSize(DEFAULT_WIDGET_WIDTH+5, 2*PRACTICAL_WIDGET_HEIGHT);
46
long GroupBox::ProcessEvent(IEvent &ievent, long TraverseInfo, long ProcessEventInfo)
48
long ret = TraverseInfo;
50
if(ievent.e_event == INL_MOUSE_PRESSED)
52
if(!m_Geometry.IsPointInside(ievent.e_x, ievent.e_y))
54
ProcEvInfo = eDoNotProcess;
60
ret = m_layout->ProcessEvent(ievent, ret, ProcEvInfo);
62
ret = PostProcessEvent2(ievent, ret, 0);
67
void GroupBox::Draw(GraphicsContext& GfxContext, bool force_draw)
69
GfxContext.PushClippingRectangle(GetGeometry());
71
Geometry wireborder_geo = GetGeometry();
73
//if(bCaptionAvailable)
75
wireborder_geo.OffsetPosition(0, 10);
76
wireborder_geo.OffsetSize(0, -10);
80
// wireborder_geo.OffsetPosition(0, 0);
81
// wireborder_geo.OffsetSize(0, 0);
84
//if(bCaptionAvailable)
86
//gPainter.Paint2DQuadColor(m_CaptionArea.GetGeometry(), COLOR_BACKGROUND_PRIMARY);
87
//gPainter.PaintTextLineStatic(m_CaptionArea.GetGeometry(), m_CaptionArea.GetCaptionString(), eAlignTextCenter);
88
gPainter.PaintTextLineStatic(GfxContext, GFontBold, m_CaptionArea.GetGeometry(), m_CaptionArea.GetBaseString().GetTCharPtr(), GetTextColor(),
89
true, eAlignTextCenter);
93
m_layout->NeedRedraw();
96
GfxContext.PopClippingRectangle();
99
void GroupBox::DrawContent(GraphicsContext& GfxContext, bool force_draw)
101
GfxContext.PushClippingRectangle(GetGeometry());
103
if(m_layout.IsValid())
105
GfxContext.PushClippingRectangle(m_layout->GetGeometry());
106
m_layout->ProcessDraw(GfxContext, force_draw);
107
GfxContext.PopClippingRectangle();
110
GfxContext.PopClippingRectangle();
113
void GroupBox::PostDraw(GraphicsContext& GfxContext, bool force_draw)
118
void GroupBox::setLayout(smptr(Layout) layout)
124
SetCompositionLayout(m_layout);
126
// Geometry geo = GetGeometry();
127
// Geometry layout_geo = Geometry(geo.x + m_border, geo.y + m_top_border,
128
// geo.GetWidth() - 2*m_border, geo.GetHeight() - m_border - m_top_border);
129
// m_layout->setGeometry(layout_geo);
132
void GroupBox::PreLayoutManagement()
134
// Give the managed layout appropriate size and position..
135
if(m_CompositionLayout.IsValid())
137
Geometry layout_geo = GetGeometry();
138
//if(bCaptionAvailable)
140
layout_geo.OffsetPosition(2, 20);
141
layout_geo.OffsetSize(-4, -22);
145
// layout_geo.OffsetPosition(2, 2);
146
// layout_geo.OffsetSize(-4, -4);
148
m_CompositionLayout->setGeometry(layout_geo);
152
long GroupBox::PostLayoutManagement(long LayoutResult)
154
// A Group box must tightly group its children.
155
// So it must embrace the size that was compute for the composition layout.
156
// Only the size is change is important here of the GroupBox is important here.
159
Geometry old_geo = BaseObject::GetGeometry();
160
if(m_CompositionLayout.IsValid())
162
Geometry base = m_CompositionLayout->GetGeometry();
163
//if(bCaptionAvailable)
165
base.OffsetPosition(-2, -20);
166
base.OffsetSize(4, 22);
170
// base.OffsetPosition(-2, -2);
171
// base.OffsetSize(4, 4);
173
BaseObject::setGeometry(base);
175
Geometry base = GetGeometry();
176
m_CaptionArea.SetBaseXY(base.x+6, base.y);
178
if(old_geo.GetWidth() > base.GetWidth())
180
else if(old_geo.GetWidth() < base.GetWidth())
181
ret |= eSmallerWidth;
183
ret |= eCompliantWidth;
185
if(old_geo.GetHeight() > base.GetHeight())
186
ret |= eLargerHeight;
187
else if(old_geo.GetHeight() < base.GetHeight())
188
ret |= eSmallerHeight;
190
ret |= eCompliantHeight;
195
void GroupBox::PositionChildLayout(float offsetX, float offsetY)
197
if(m_CompositionLayout.IsValid())
199
//if(bCaptionAvailable)
201
m_CompositionLayout->SetBaseX(GetBaseX() + 2);
202
m_CompositionLayout->SetBaseY(GetBaseY() + 20);
206
// m_CompositionLayout->SetX(GetX() + 2);
207
// m_CompositionLayout->SetY(GetY() + 2);
209
m_CompositionLayout->ComputePosition2(offsetX, offsetY);
211
Geometry base = GetGeometry();
212
m_CaptionArea.SetBaseXY(base.x+6, base.y);
215
void GroupBox::setCaption(const char* name)
217
if((name == 0) || strlen(name) == 0)
219
//bCaptionAvailable = false;
220
m_CaptionArea.SetBaseString(TEXT(""));
221
m_CaptionArea.SetMinimumSize(DEFAULT_WIDGET_WIDTH, PRACTICAL_WIDGET_HEIGHT);
222
m_CaptionArea.SetBaseSize(DEFAULT_WIDGET_WIDTH, PRACTICAL_WIDGET_HEIGHT);
226
//bCaptionAvailable = true;
227
m_CaptionArea.SetBaseString(name);
228
m_CaptionArea.SetMinimumSize(4 + GFontBold->GetStringWidth(name), PRACTICAL_WIDGET_HEIGHT);
229
m_CaptionArea.SetBaseSize(4 + GFontBold->GetStringWidth(name), PRACTICAL_WIDGET_HEIGHT);