~loic.molinari/nux/nux-unity-support-test-improvements

« back to all changes in this revision

Viewing changes to Nux/ComboBoxSimple.cpp

  • Committer: Gord Allott
  • Date: 2011-03-23 18:24:39 UTC
  • mfrom: (292.1.2 combo-box-focus)
  • Revision ID: gord.allott@canonical.com-20110323182439-ojb652v1hbinvidk
simple combo box support for focus and a few bugfixes to text entry

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include "TableCtrl.h"
29
29
#include "StaticText.h"
30
30
 
 
31
 
31
32
namespace nux
32
33
{
33
34
 
34
35
  ComboBoxSimple::ComboBoxSimple (NUX_FILE_LINE_DECL)
35
36
    :   AbstractComboBox (NUX_FILE_LINE_PARAM)
36
37
  {
 
38
    m_block_focus       = false;
 
39
    _can_pass_focus_to_composite_layout = false;
37
40
    m_SelectedAction    = 0;
38
41
    m_CurrentMenu       = 0;
39
42
 
66
69
    m_CurrentMenu->Dispose ();
67
70
  }
68
71
 
 
72
  void ComboBoxSimple::DoSetFocused (bool focused)
 
73
  {
 
74
    View::DoSetFocused (focused);
 
75
    if (focused == true)
 
76
    {
 
77
      m_block_focus = true;
 
78
      // we need to grab focus control from our parent layout
 
79
      // so that we can handle the key inputs ourself
 
80
      Area *_parent = GetParentObject();
 
81
      if (_parent == NULL)
 
82
        return;
 
83
 
 
84
      if (_parent->IsView ())
 
85
      {
 
86
        View *parent = (View*)_parent;
 
87
        parent->SetFocusControl (false);
 
88
      }
 
89
      else if (_parent->IsLayout ())
 
90
      {
 
91
        Layout *parent = (Layout *)_parent;
 
92
        parent->SetFocusControl (false);
 
93
      }
 
94
    }
 
95
    NeedRedraw();
 
96
  }
 
97
 
69
98
  long ComboBoxSimple::ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo)
70
99
  {
71
100
    long ret = TraverseInfo;
94
123
      }
95
124
    }
96
125
 
 
126
    /* must do focus processing after sending events to children */
 
127
    if (ievent.e_event == NUX_KEYDOWN && GetFocused () && m_block_focus == false)
 
128
    {
 
129
      FocusDirection direction;
 
130
      FocusEventType type;
 
131
 
 
132
      direction = FOCUS_DIRECTION_NONE;
 
133
 
 
134
      type = Focusable::GetFocusableEventType (ievent.e_event,
 
135
                                               ievent.GetKeySym(),
 
136
                                               ievent.GetText(),
 
137
                                               &direction);
 
138
      if (type == FOCUS_EVENT_DIRECTION)
 
139
      {
 
140
        if (direction == FOCUS_DIRECTION_PREV || direction == FOCUS_DIRECTION_NEXT ||
 
141
          direction == FOCUS_DIRECTION_LEFT || direction == FOCUS_DIRECTION_RIGHT)
 
142
        {
 
143
          // not pressed UP or Down so send focus to our parent layout
 
144
          Area *area = GetParentObject ();
 
145
          // if parent is null return, thats a valid usecase so no warnings.
 
146
          if (area)
 
147
          {
 
148
            long ret = 0;
 
149
            if ( area->IsView() )
 
150
            {
 
151
              View *ic = NUX_STATIC_CAST (View *, area );
 
152
              ic->SetFocusControl (true);
 
153
              ret = ic->ProcessFocusEvent (ievent, ret, ProcessEventInfo);
 
154
            }
 
155
            else if ( area->IsLayout() )
 
156
            {
 
157
              Layout *layout = NUX_STATIC_CAST (Layout *, area );
 
158
              layout->SetFocusControl (true);
 
159
              ret = layout->ProcessFocusEvent (ievent, ret, ProcessEventInfo);
 
160
            }
 
161
          }
 
162
        }
 
163
        else if (direction == FOCUS_DIRECTION_UP)
 
164
        {
 
165
          MoveSelectionUp ();
 
166
          sigTriggered.emit (this);
 
167
          sigActionTriggered.emit (GetItem (GetSelectionIndex ()));
 
168
        }
 
169
        else if (direction == FOCUS_DIRECTION_DOWN)
 
170
        {
 
171
          MoveSelectionDown ();
 
172
          sigTriggered.emit (this);
 
173
          sigActionTriggered.emit (GetItem (GetSelectionIndex ()));
 
174
        }
 
175
      }
 
176
    }
 
177
 
 
178
    if (m_block_focus == true)
 
179
      m_block_focus = false;
 
180
 
97
181
    ret = PostProcessEvent2 (ievent, ret, ProcessEventInfo);
98
182
    return ret;
99
183
  }
100
184
 
 
185
  void ComboBoxSimple::MoveSelectionUp ()
 
186
  {
 
187
    int current_index = GetSelectionIndex ();
 
188
    SetSelectionIndex (current_index - 1);
 
189
  }
 
190
 
 
191
  void ComboBoxSimple::MoveSelectionDown ()
 
192
  {
 
193
    int current_index = GetSelectionIndex ();
 
194
    SetSelectionIndex (current_index + 1);
 
195
  }
 
196
 
101
197
  ActionItem *ComboBoxSimple::AddItem (const TCHAR *label, int Uservalue)
102
198
  {
103
199
    if (m_CurrentMenu->GetNumItem() == 0)