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>
30
Button::Button (const TCHAR *Caption, NUX_FILE_LINE_DECL)
31
: AbstractButton (Caption, NUX_FILE_LINE_PARAM)
39
SetCheckable (m_Checkable, m_State, false);
48
void Button::InitializeWidgets()
51
OnMouseClick.connect (sigc::mem_fun (this, &Button::RecvClick) );
52
OnMouseDown.connect (sigc::mem_fun (this, &Button::RecvMouseDown) );
53
OnMouseDoubleClick.connect (sigc::mem_fun (this, &Button::RecvMouseDown) );
54
OnMouseUp.connect (sigc::mem_fun (this, &Button::RecvMouseUp) );
55
OnMouseMove.connect (sigc::mem_fun (this, &Button::RecvMouseMove) );
56
OnMouseEnter.connect (sigc::mem_fun (this, &Button::RecvMouseEnter) );
57
OnMouseLeave.connect (sigc::mem_fun (this, &Button::RecvMouseLeave) );
60
SetMinimumSize (DEFAULT_WIDGET_WIDTH, PRACTICAL_WIDGET_HEIGHT);
62
m_hlayout->SetVerticalExternalMargin (0);
63
m_hlayout->SetHorizontalExternalMargin (0);
64
SetCompositionLayout (m_hlayout);
65
SetTextColor (Color::Black);
68
void Button::InitializeLayout()
70
m_hlayout = new HLayout();
73
void Button::DestroyLayout()
77
long Button::ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo)
79
long ret = TraverseInfo;
80
ret = PostProcessEvent2 (ievent, ret, ProcessEventInfo);
84
void Button::Draw (GraphicsEngine &GfxContext, bool force_draw)
86
Geometry base = GetGeometry();
90
is.is_focus = HasMouseFocus();
92
is.is_prelight = IsMouseInside();
98
GetPainter().PushDrawSliceScaledTextureLayer (GfxContext, base, eBUTTON_FOCUS, Color::White, eAllCorners);
99
GetPainter().PopBackground();
103
GetPainter().PushDrawSliceScaledTextureLayer (GfxContext, base, eBUTTON_NORMAL, Color::White, eAllCorners);
104
GetPainter().PopBackground();
111
GetPainter().PushDrawSliceScaledTextureLayer (GfxContext, base, eBUTTON_FOCUS, Color::White, eAllCorners);
112
GetPainter().PopBackground();
114
else if (is.is_prelight)
116
GetPainter().PushDrawSliceScaledTextureLayer (GfxContext, base, eBUTTON_PRELIGHT, Color::White, eAllCorners);
117
GetPainter().PopBackground();
121
GetPainter().PushDrawSliceScaledTextureLayer (GfxContext, base, eBUTTON_NORMAL, Color::White, eAllCorners);
122
GetPainter().PopBackground();
126
GetPainter().PaintTextLineStatic (GfxContext, GetFont(), base, GetBaseString().GetTCharPtr(), GetTextColor(), true, eAlignTextCenter);
129
void Button::DrawContent (GraphicsEngine &GfxContext, bool force_draw)
134
void Button::PostDraw (GraphicsEngine &GfxContext, bool force_draw)
139
void Button::SetCaption (const TCHAR *Caption)
141
if (Caption == 0 || (StringLength (Caption) == 0) )
143
SetBaseString (TEXT ("") );
146
SetBaseString (Caption);
149
const NString &Button::GetCaption() const
151
return GetBaseString();
154
void Button::SetState (bool b)
160
void Button::SetState (bool State, bool EmitSignal)
171
sigStateChanged.emit (m_State);
178
bool Button::GetState() const
183
void Button::SetCheckable (bool b)
189
void Button::SetCheckable (bool b, bool CurrentState, bool EmitSignal)
192
m_State = CurrentState;
202
void Button::RecvClick (int x, int y, unsigned long button_flags, unsigned long key_flags)
209
void Button::RecvMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags)
214
void Button::RecvMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags)
219
void Button::RecvMouseMove (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags)
224
void Button::RecvMouseEnter (int x, int y, unsigned long button_flags, unsigned long key_flags)
229
void Button::RecvMouseLeave (int x, int y, unsigned long button_flags, unsigned long key_flags)