~macslow/nux/nux.fix-839476

« back to all changes in this revision

Viewing changes to Nux/GroupBox.cpp

  • Committer: Neil Jagdish Patel
  • Date: 2010-09-01 22:11:16 UTC
  • Revision ID: neil.patel@canonical.com-20100901221116-4hb351fcg6s5nka0
Initial Nux integration

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2010 Inalogic Inc.
 
3
 *
 
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.
 
7
 *
 
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.
 
13
 * 
 
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/>
 
17
 *
 
18
 * Authored by: Jay Taoko <jay.taoko_AT_gmail_DOT_com>
 
19
 *
 
20
 */
 
21
 
 
22
 
 
23
#include "Nux.h"
 
24
#include "Layout.h"
 
25
#include "GroupBox.h"
 
26
 
 
27
NAMESPACE_BEGIN_GUI
 
28
 
 
29
GroupBox::GroupBox(const TCHAR* Caption)
 
30
:   bCaptionAvailable(false)
 
31
,   m_layout(0)
 
32
{
 
33
    m_CaptionArea.SetMinimumSize(DEFAULT_WIDGET_WIDTH, PRACTICAL_WIDGET_HEIGHT);
 
34
    m_CaptionArea.SetBaseSize(DEFAULT_WIDGET_WIDTH, PRACTICAL_WIDGET_HEIGHT);
 
35
 
 
36
    SetMinimumSize(DEFAULT_WIDGET_WIDTH+5, PRACTICAL_WIDGET_HEIGHT+5);
 
37
    SetBaseSize(DEFAULT_WIDGET_WIDTH+5, 2*PRACTICAL_WIDGET_HEIGHT);
 
38
    setCaption("");
 
39
}
 
40
 
 
41
GroupBox::~GroupBox()
 
42
{
 
43
 
 
44
}
 
45
 
 
46
long GroupBox::ProcessEvent(IEvent &ievent, long TraverseInfo, long ProcessEventInfo)
 
47
{
 
48
    long ret = TraverseInfo;
 
49
    long ProcEvInfo = 0;
 
50
    if(ievent.e_event == INL_MOUSE_PRESSED)
 
51
    {
 
52
        if(!m_Geometry.IsPointInside(ievent.e_x, ievent.e_y))
 
53
        {
 
54
            ProcEvInfo = eDoNotProcess;
 
55
        }
 
56
    }
 
57
 
 
58
    if(m_layout != 0)
 
59
    {
 
60
        ret = m_layout->ProcessEvent(ievent, ret, ProcEvInfo);
 
61
    }
 
62
    ret = PostProcessEvent2(ievent, ret, 0);
 
63
    return ret;
 
64
}
 
65
 
 
66
 
 
67
void GroupBox::Draw(GraphicsContext& GfxContext, bool force_draw)
 
68
{
 
69
    GfxContext.PushClippingRectangle(GetGeometry());
 
70
    
 
71
    Geometry wireborder_geo = GetGeometry();
 
72
    
 
73
    //if(bCaptionAvailable)
 
74
    {
 
75
        wireborder_geo.OffsetPosition(0, 10);
 
76
        wireborder_geo.OffsetSize(0, -10);
 
77
    }
 
78
//    else
 
79
//    {
 
80
//        wireborder_geo.OffsetPosition(0, 0);
 
81
//        wireborder_geo.OffsetSize(0, 0);
 
82
//    }
 
83
 
 
84
    //if(bCaptionAvailable)
 
85
    {
 
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);
 
90
    }
 
91
    if(m_layout != 0)
 
92
    {
 
93
        m_layout->NeedRedraw();
 
94
    }
 
95
 
 
96
    GfxContext.PopClippingRectangle();
 
97
}
 
98
 
 
99
void GroupBox::DrawContent(GraphicsContext& GfxContext, bool force_draw)
 
100
{
 
101
    GfxContext.PushClippingRectangle(GetGeometry());
 
102
 
 
103
    if(m_layout.IsValid())
 
104
    {
 
105
        GfxContext.PushClippingRectangle(m_layout->GetGeometry());
 
106
        m_layout->ProcessDraw(GfxContext, force_draw);
 
107
        GfxContext.PopClippingRectangle();
 
108
    }
 
109
 
 
110
    GfxContext.PopClippingRectangle();
 
111
}
 
112
 
 
113
void GroupBox::PostDraw(GraphicsContext& GfxContext, bool force_draw)
 
114
{
 
115
 
 
116
}
 
117
 
 
118
void GroupBox::setLayout(smptr(Layout) layout)
 
119
{
 
120
    if(layout == 0)
 
121
        return;
 
122
 
 
123
    m_layout = layout;
 
124
    SetCompositionLayout(m_layout);
 
125
 
 
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);
 
130
}
 
131
 
 
132
void GroupBox::PreLayoutManagement()
 
133
{
 
134
    // Give the managed layout appropriate size and position..
 
135
    if(m_CompositionLayout.IsValid())
 
136
    {
 
137
        Geometry layout_geo = GetGeometry();
 
138
        //if(bCaptionAvailable)
 
139
        {
 
140
            layout_geo.OffsetPosition(2, 20);
 
141
            layout_geo.OffsetSize(-4, -22);
 
142
        }
 
143
//        else
 
144
//        {
 
145
//            layout_geo.OffsetPosition(2, 2);
 
146
//            layout_geo.OffsetSize(-4, -4);
 
147
//        }
 
148
        m_CompositionLayout->setGeometry(layout_geo);
 
149
    }
 
150
}
 
151
 
 
152
long GroupBox::PostLayoutManagement(long LayoutResult)
 
153
{
 
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.
 
157
 
 
158
    long ret = 0;
 
159
    Geometry old_geo = BaseObject::GetGeometry();
 
160
    if(m_CompositionLayout.IsValid())
 
161
    {
 
162
        Geometry base = m_CompositionLayout->GetGeometry();
 
163
        //if(bCaptionAvailable)
 
164
        {
 
165
            base.OffsetPosition(-2, -20);
 
166
            base.OffsetSize(4, 22);
 
167
        }
 
168
//        else
 
169
//        {
 
170
//            base.OffsetPosition(-2, -2);
 
171
//            base.OffsetSize(4, 4);
 
172
//        }
 
173
        BaseObject::setGeometry(base);
 
174
    }
 
175
    Geometry base = GetGeometry();
 
176
    m_CaptionArea.SetBaseXY(base.x+6, base.y);
 
177
 
 
178
    if(old_geo.GetWidth() > base.GetWidth())
 
179
        ret |= eLargerWidth;
 
180
    else if(old_geo.GetWidth() < base.GetWidth())
 
181
        ret |= eSmallerWidth;
 
182
    else
 
183
        ret |= eCompliantWidth;
 
184
 
 
185
    if(old_geo.GetHeight() > base.GetHeight())
 
186
        ret |= eLargerHeight;
 
187
    else if(old_geo.GetHeight() < base.GetHeight())
 
188
        ret |= eSmallerHeight;
 
189
    else
 
190
        ret |= eCompliantHeight;
 
191
 
 
192
    return ret;
 
193
}
 
194
 
 
195
void GroupBox::PositionChildLayout(float offsetX, float offsetY)
 
196
{
 
197
    if(m_CompositionLayout.IsValid())
 
198
    {
 
199
        //if(bCaptionAvailable)
 
200
        {
 
201
            m_CompositionLayout->SetBaseX(GetBaseX() + 2);
 
202
            m_CompositionLayout->SetBaseY(GetBaseY() + 20);
 
203
        }
 
204
//        else
 
205
//        {
 
206
//            m_CompositionLayout->SetX(GetX() + 2);
 
207
//            m_CompositionLayout->SetY(GetY() + 2);
 
208
//        }
 
209
        m_CompositionLayout->ComputePosition2(offsetX, offsetY);
 
210
    }
 
211
    Geometry base = GetGeometry();
 
212
    m_CaptionArea.SetBaseXY(base.x+6, base.y);
 
213
}
 
214
 
 
215
void GroupBox::setCaption(const char* name)
 
216
{
 
217
    if((name == 0) || strlen(name) == 0)
 
218
    {
 
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);
 
223
    }
 
224
    else
 
225
    {
 
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);
 
230
    }
 
231
}
 
232
 
 
233
NAMESPACE_END_GUI