~karl-qdh/nux/nux.gtkentry-wrapper

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
193
194
195
196
197
198
199
200
/*
 * Copyright 2010 Inalogic Inc.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version 3, as
 * published by the  Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the applicable version of the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of both the GNU Lesser General Public
 * License version 3 along with this program.  If not, see
 * <http://www.gnu.org/licenses/>
 *
 * Authored by: Jay Taoko <jaytaoko@inalogic.com>
 *
 */


#include "Nux.h"
#include "Button.h"
#include "HLayout.h"

namespace nux
{

  Button::Button (const TCHAR *Caption, NUX_FILE_LINE_DECL)
    :   AbstractButton (Caption, NUX_FILE_LINE_PARAM)
  {
    _state     = false;

    InitializeLayout();
    InitializeWidgets();
    SetCaption (Caption);
  }

  Button::~Button()
  {
    DestroyLayout();
  }

  void Button::InitializeWidgets()
  {
    // Set Signals
    OnMouseClick.connect (sigc::mem_fun (this, &Button::RecvClick) );
    OnMouseDown.connect (sigc::mem_fun (this, &Button::RecvMouseDown) );
    OnMouseDoubleClick.connect (sigc::mem_fun (this, &Button::RecvMouseDown) );
    OnMouseUp.connect (sigc::mem_fun (this, &Button::RecvMouseUp) );
    OnMouseMove.connect (sigc::mem_fun (this, &Button::RecvMouseMove) );
    OnMouseEnter.connect (sigc::mem_fun (this, &Button::RecvMouseEnter) );
    OnMouseLeave.connect (sigc::mem_fun (this, &Button::RecvMouseLeave) );

    // Set Geometry
    SetMinimumSize (DEFAULT_WIDGET_WIDTH, PRACTICAL_WIDGET_HEIGHT);

    SetTextColor (Color::Black);
  }

  void Button::InitializeLayout()
  {
  }

  void Button::DestroyLayout()
  {
  }

  long Button::ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo)
  {
    long ret = TraverseInfo;
    ret = PostProcessEvent2 (ievent, ret, ProcessEventInfo);
    return ret;
  }

  void Button::Draw (GraphicsEngine &GfxContext, bool force_draw)
  {
    Geometry base = GetGeometry();
    InteractState is;
    is.is_on = _state;
    is.is_focus = HasMouseFocus();
    is.is_prelight = IsMouseInside();

    if (is.is_focus || is.is_on)
    {
      GetPainter().PushDrawSliceScaledTextureLayer (GfxContext, base, eBUTTON_FOCUS, Color::White, eAllCorners);
      GetPainter().PopBackground();
    }
    else if (is.is_prelight)
    {
      GetPainter().PushDrawSliceScaledTextureLayer (GfxContext, base, eBUTTON_PRELIGHT, Color::White, eAllCorners);
      GetPainter().PopBackground();
    }
    else
    {
      GetPainter().PushDrawSliceScaledTextureLayer (GfxContext, base, eBUTTON_NORMAL, Color::White, eAllCorners);
      GetPainter().PopBackground();
    }

    //if (_state)
    //{
    //  GetPainter().PushDrawSliceScaledTextureLayer (GfxContext, base, eBUTTON_FOCUS, Color::White, eAllCorners);
    //  GetPainter().PopBackground();
    //}
    //else
    //{
    //  GetPainter().PushDrawSliceScaledTextureLayer (GfxContext, base, eBUTTON_NORMAL, Color::White, eAllCorners);
    //  GetPainter().PopBackground();
    //}
    GetPainter().PaintTextLineStatic (GfxContext, GetFont(), base, GetBaseString().GetTCharPtr(), GetTextColor(), true, eAlignTextCenter);
  }

  void Button::DrawContent (GraphicsEngine &GfxContext, bool force_draw)
  {

  }

  void Button::PostDraw (GraphicsEngine &GfxContext, bool force_draw)
  {

  }

  void Button::SetCaption (const TCHAR *Caption)
  {
    if (Caption == 0 || (StringLength (Caption) == 0) )
    {
      SetBaseString (TEXT ("") );
    }
    else
      SetBaseString (Caption);
  }

  const NString &Button::GetCaption() const
  {
    return GetBaseString();
  }

  void Button::SetState (bool b)
  {
    _state = b;
    NeedRedraw();
  }

  void Button::SetState (bool State, bool EmitSignal)
  {
    _state = State;

    if (EmitSignal)
    {
      sigClick.emit();
      sigToggled.emit();
      sigStateChanged.emit (_state);

    }

    NeedRedraw();
  }

  bool Button::GetState() const
  {
    return _state;
  }

  void Button::RecvClick (int x, int y, unsigned long button_flags, unsigned long key_flags)
  {
    _state = !_state;
    sigClick.emit();
    NeedRedraw();
  }

  void Button::RecvMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags)
  {
    NeedRedraw();
  }

  void Button::RecvMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags)
  {
    NeedRedraw();
  }

  void Button::RecvMouseMove (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags)
  {

  }

  void Button::RecvMouseEnter (int x, int y, unsigned long button_flags, unsigned long key_flags)
  {
    NeedRedraw();
  }

  void Button::RecvMouseLeave (int x, int y, unsigned long button_flags, unsigned long key_flags)
  {
    NeedRedraw();
  }




}