~macslow/nux/nux.fix-839476

« back to all changes in this revision

Viewing changes to Nux/HToolBar.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
 
 
25
#include "HToolBar.h"
 
26
#include "HLayout.h"
 
27
#include "ToolButton.h"
 
28
#include "ActionItem.h"
 
29
#include "AbstractSeparator.h"
 
30
#include "VSeparator.h"
 
31
#include "EditTextBox.h"
 
32
#include "StaticTextBox.h"
 
33
NAMESPACE_BEGIN_GUI
 
34
HToolBar::HToolBar()
 
35
:   m_hlayout(0)
 
36
 
37
    InitializeLayout();
 
38
    InitializeWidgets();
 
39
}
 
40
 
 
41
HToolBar::~HToolBar()
 
42
{
 
43
    DestroyLayout();
 
44
}
 
45
 
 
46
void HToolBar::InitializeWidgets()
 
47
{
 
48
    m_hlayout->SetHorizontalInternalMargin(2);
 
49
    m_hlayout->SetHorizontalExternalMargin(0);
 
50
    m_hlayout->SetVerticalExternalMargin(0);
 
51
    m_hlayout->SetContentStacking(eStackLeft);
 
52
    SetMinimumSize(200, 32);
 
53
    SetMaximumHeight(32);
 
54
    setGeometry(Geometry(0, 0, 200, 20));
 
55
    SetCompositionLayout(m_hlayout);
 
56
}
 
57
 
 
58
void HToolBar::InitializeLayout()
 
59
{
 
60
    m_hlayout = smptr(HLayout)(new HLayout());
 
61
}
 
62
 
 
63
void HToolBar::DestroyLayout()
 
64
{
 
65
}
 
66
 
 
67
long HToolBar::ProcessEvent(IEvent &ievent, long TraverseInfo, long ProcessEventInfo)
 
68
{
 
69
    long ret = TraverseInfo;
 
70
 
 
71
    ret = m_hlayout->ProcessEvent(ievent, TraverseInfo, ProcessEventInfo);
 
72
 
 
73
    // PostProcessEvent2 must always have its last parameter set to 0
 
74
    // because the m_BackgroundArea is the real physical limit of the window.
 
75
    // So the previous test about IsPointInside do not prevail over m_BackgroundArea 
 
76
    // testing the event by itself.
 
77
    ret = PostProcessEvent2(ievent, ret, 0);
 
78
    return ret;
 
79
}
 
80
 
 
81
void HToolBar::Draw(GraphicsContext& GfxContext, bool force_draw)
 
82
{
 
83
    Geometry base = GetGeometry();
 
84
    GfxContext.PushClippingRectangle(base);
 
85
    GfxContext.SetEnvModeSelectColor(GL_TEXTURE0);
 
86
    GfxContext.QRP_GLSL_Color(base.x, base.y, base.GetWidth(), base.GetHeight(), COLOR_BACKGROUND_PRIMARY);
 
87
 
 
88
    GfxContext.PopClippingRectangle();
 
89
}
 
90
 
 
91
void HToolBar::DrawContent(GraphicsContext& GfxContext, bool force_draw)
 
92
{
 
93
    Geometry base = GetGeometry();
 
94
    GfxContext.PushClippingRectangle(base);
 
95
    gPainter.PushColorLayer(GfxContext, base, COLOR_BACKGROUND_PRIMARY);
 
96
    m_hlayout->ProcessDraw(GfxContext, force_draw);
 
97
    gPainter.PopBackground();
 
98
    GfxContext.PopClippingRectangle();
 
99
}
 
100
 
 
101
void HToolBar::PostDraw(GraphicsContext& GfxContext, bool force_draw)
 
102
{
 
103
 
 
104
}
 
105
 
 
106
void HToolBar::AddToolButton(smptr(ToolButton) toolbutton)
 
107
{
 
108
    nuxAssert(toolbutton.IsValid());
 
109
    if(toolbutton == 0)
 
110
        return;
 
111
 
 
112
    m_hlayout->AddActiveInterfaceObject(toolbutton, 0, eCenter, eFix);
 
113
    // 0: the WidgetLayout geometry will be set to setGeometry(0,0,1,1);
 
114
    // and the children will take their natural size by expending WidgetLayout.
 
115
    // If the parent of WidgetLayout offers more space, it won't be used by WidgetLayout.
 
116
    ComputeChildLayout();
 
117
}
 
118
 
 
119
void HToolBar::AddAction(smptr(ActionItem) action)
 
120
{
 
121
//    nuxAssert(action);
 
122
//    if(action == 0)
 
123
//        return;
 
124
 
 
125
    smptr(ToolButton) tool_button(new ToolButton);
 
126
    tool_button->SetAction(*action);
 
127
 
 
128
    m_hlayout->AddActiveInterfaceObject(tool_button, 0, eCenter, eFix);
 
129
    // 0: the WidgetLayout geometry will be set to setGeometry(0,0,1,1);
 
130
    // and the children will take their natural size by expending WidgetLayout.
 
131
    // If the parent of WidgetLayout offers more space, it won't be used by WidgetLayout.
 
132
    ComputeChildLayout();
 
133
}
 
134
 
 
135
void HToolBar::AddSpace(int size)
 
136
{
 
137
    smptr(SpaceLayout) layout(new SpaceLayout());
 
138
    layout->SetMaximumWidth(size);
 
139
    layout->SetMinimumWidth(size);
 
140
    m_hlayout->AddLayout(layout);
 
141
    ComputeChildLayout();
 
142
}
 
143
 
 
144
void HToolBar::AddSeparator()
 
145
{
 
146
    smptr(VSeparator) separator(new VSeparator());
 
147
    m_hlayout->AddActiveInterfaceObject(separator, 0);
 
148
    ComputeChildLayout();
 
149
}
 
150
 
 
151
void HToolBar::AddEditTextLine(smptr(EditTextBox) edittextline)
 
152
{
 
153
    nuxAssert(edittextline.IsValid());
 
154
    if(edittextline == 0)
 
155
        return;
 
156
 
 
157
    m_hlayout->AddActiveInterfaceObject(edittextline, 0, eCenter, eFix);
 
158
    // 0: the WidgetLayout geometry will be set to setGeometry(0,0,1,1);
 
159
    // and the children will take their natural size by expending WidgetLayout.
 
160
    // If the parent of WidgetLayout offers more space, it won't be used by WidgetLayout.
 
161
    ComputeChildLayout();
 
162
}
 
163
 
 
164
void HToolBar::AddStaticTextLine(smptr(StaticTextBox) statictextline)
 
165
{
 
166
    nuxAssert(statictextline.IsValid());
 
167
    if(statictextline == 0)
 
168
        return;
 
169
 
 
170
    m_hlayout->AddActiveInterfaceObject(statictextline, 0, eCenter, eFix);
 
171
    // 0: the WidgetLayout geometry will be set to setGeometry(0,0,1,1);
 
172
    // and the children will take their natural size by expending WidgetLayout.
 
173
    // If the parent of WidgetLayout offers more space, it won't be used by WidgetLayout.
 
174
    ComputeChildLayout();
 
175
}
 
176
 
 
177
void HToolBar::ClearWidget()
 
178
{
 
179
    m_CompositionLayout->Clear();
 
180
}
 
181
 
 
182
void HToolBar::RecvMouseDownOnIcon(int x, int y, unsigned long button_flags, unsigned long key_flags)
 
183
{
 
184
    NeedRedraw();
 
185
}
 
186
 
 
187
void HToolBar::RecvMouseUpOnIcon(int x, int y, unsigned long button_flags, unsigned long key_flags)
 
188
{
 
189
    NeedRedraw();
 
190
}
 
191
 
 
192
void HToolBar::RecvMouseMoveOnIcon(int x, int y, unsigned long button_flags, unsigned long key_flags)
 
193
{
 
194
    NeedRedraw();
 
195
}
 
196
 
 
197
void HToolBar::RecvMouseDragOnIcon(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags)
 
198
{
 
199
    NeedRedraw();
 
200
}
 
201
 
 
202
void HToolBar::RecvMouseEnterIcon(int x, int y, unsigned long button_flags, unsigned long key_flags)
 
203
{
 
204
    NeedRedraw();
 
205
}
 
206
 
 
207
void HToolBar::RecvMouseLeaveIcon(int x, int y, unsigned long button_flags, unsigned long key_flags)
 
208
{
 
209
    NeedRedraw();
 
210
}
 
211
NAMESPACE_END_GUI