49
_processCancel(false),
56
55
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
59
for(unsigned int i = 0; i < _ourFocusList.size(); ++i)
60
_ourFocusList[i].focusList.clear();
58
_myFocus.list.clear();
62
61
delete _firstWidget;
63
62
_firstWidget = NULL;
65
_ourButtonGroup.clear();
68
67
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
68
void Dialog::open(bool refresh)
74
70
// Make sure we have a valid surface to draw into
75
71
// Technically, this shouldn't be needed until drawDialog(), but some
76
72
// dialogs cause drawing to occur within loadConfig()
80
76
// However, this policy is left entirely to the framebuffer
81
77
// We suggest the hint here, but specific framebuffers are free to
83
_surface = instance().frameBuffer().surface(_surfaceID);
84
79
if(_surface == NULL)
86
_surfaceID = instance().frameBuffer().allocateSurface(_w, _h, _isBase);
87
_surface = instance().frameBuffer().surface(_surfaceID);
81
uInt32 surfaceID = instance().frameBuffer().allocateSurface(_w, _h, _isBase);
82
_surface = instance().frameBuffer().surface(surfaceID);
84
parent().addDialog(this);
93
89
// (Re)-build the focus list to use for the widgets which are currently
95
buildFocusWidgetList(_focusID);
91
buildCurrentFocusList();
96
instance().frameBuffer().refresh();
98
99
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
100
void Dialog::close(bool refresh)
101
102
if (_mouseWidget)
135
140
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
136
141
void Dialog::addFocusWidget(Widget* w)
138
// All focusable widgets should retain focus
140
w->setFlags(WIDGET_RETAIN_FOCUS);
142
if(_ourFocusList.size() == 0)
146
// All focusable widgets should retain focus
147
w->setFlags(WIDGET_RETAIN_FOCUS);
150
_myFocus.list.push_back(w);
153
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
154
void Dialog::addToFocusList(WidgetArray& list)
156
// All focusable widgets should retain focus
157
for(uInt32 i = 0; i < list.size(); ++i)
158
list[i]->setFlags(WIDGET_RETAIN_FOCUS);
160
_myFocus.list.push_back(list);
161
_focusList = _myFocus.list;
164
_myFocus.widget = list[0];
167
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
168
void Dialog::addToFocusList(WidgetArray& list, TabWidget* w, int tabId)
170
// Only add the list if the tab actually exists
171
if(!w || w->getID() < 0 || (uInt32)w->getID() >= _myTabList.size())
174
assert(w == _myTabList[w->getID()].widget);
176
// All focusable widgets should retain focus
177
for(uInt32 i = 0; i < list.size(); ++i)
178
list[i]->setFlags(WIDGET_RETAIN_FOCUS);
180
// First get the appropriate focus list
181
FocusList& focus = _myTabList[w->getID()].focus;
183
// Now insert in the correct place in that focus list
185
if(id < focus.size())
186
focus[id].list.push_back(list);
146
_ourFocusList.push_back(f);
189
// Make sure the array is large enough
190
while(focus.size() <= id)
191
focus.push_back(Focus());
193
focus[id].list.push_back(list);
148
_ourFocusList[0].focusedWidget = w;
149
_ourFocusList[0].focusList.push_back(w);
197
focus[id].widget = list[0];
152
200
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
153
void Dialog::addToFocusList(WidgetArray& list, int id)
201
void Dialog::addTabWidget(TabWidget* w)
155
// All focusable widgets should retain focus
156
for(unsigned int i = 0; i < list.size(); ++i)
157
list[i]->setFlags(WIDGET_RETAIN_FOCUS);
159
id++; // Arrays start at 0, not -1.
203
if(!w || w->getID() < 0)
161
206
// Make sure the array is large enough
162
while((int)_ourFocusList.size() <= id)
165
f.focusedWidget = NULL;
166
_ourFocusList.push_back(f);
169
_ourFocusList[id].focusList.push_back(list);
170
if(id == 0 && _ourFocusList.size() > 0)
171
_focusList = _ourFocusList[0].focusList;
174
_ourFocusList[id].focusedWidget = list[0];
207
uInt32 id = w->getID();
208
while(_myTabList.size() < id)
209
_myTabList.push_back(TabFocus());
211
_myTabList.push_back(TabFocus(w));
177
214
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
184
221
// Redraw widgets for new focus
185
222
_focusedWidget = Widget::setFocusForChain(this, getFocusList(), w, 0);
224
// Update current tab based on new focused widget
225
getTabIdForWidget(_focusedWidget);
189
229
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
190
void Dialog::buildFocusWidgetList(int id)
230
void Dialog::buildCurrentFocusList(int tabID)
192
232
// Yes, this is hideously complex. That's the price we pay for
193
233
// tab navigation ...
195
// Remember which item previously had focus, but only if it belongs
196
// to this focus list
197
if(_focusID < (int)_ourFocusList.size() &&
198
Widget::isWidgetInChain(_ourFocusList[_focusID].focusList, _focusedWidget))
199
_ourFocusList[_focusID].focusedWidget = _focusedWidget;
203
// Create a focuslist for items currently onscreen
204
// We do this by starting with any dialog focus list (at index 0 in the
205
// focus lists, then appending the list indicated by 'id'.
206
if(_focusID < (int)_ourFocusList.size())
236
// Remember which tab item previously had focus, if applicable
237
// This only applies if this method was called for a tab change
238
Widget* tabFocusWidget = 0;
239
if(tabID >= 0 && tabID < (int)_myTabList.size())
209
_focusList.push_back(_ourFocusList[0].focusList);
211
// Append extra focus list
213
_focusList.push_back(_ourFocusList[_focusID].focusList);
215
// Add button group at end of current focus list
216
// We do it this way for TabWidget, so that buttons are scanned
217
// *after* the widgets in the current tab
218
if(_ourButtonGroup.size() > 0)
219
_focusList.push_back(_ourButtonGroup);
221
// Only update _focusedWidget if it doesn't belong to the main focus list
222
// HACK - figure out how to properly deal with only one focus-able widget
223
// in a tab -- TabWidget is the spawn of the devil
224
if(_focusList.size() == 1)
225
_focusedWidget = _focusList[0];
226
else if(!Widget::isWidgetInChain(_ourFocusList[0].focusList, _focusedWidget))
227
_focusedWidget = _ourFocusList[_focusID].focusedWidget;
241
// Save focus in previously selected tab column,
242
// and get focus for new tab column
243
TabFocus& tabfocus = _myTabList[tabID];
244
tabfocus.saveCurrentFocus(_focusedWidget);
245
tabFocusWidget = tabfocus.getNewFocus();
250
// Add appropriate items from tablist (if present)
251
for(uInt32 id = 0; id < _myTabList.size(); ++id)
252
_myTabList[id].appendFocusList(_focusList);
254
// Add remaining items from main focus list
255
_focusList.push_back(_myFocus.list);
257
// Add button group at end of current focus list
258
// We do it this way for TabWidget, so that buttons are scanned
259
// *after* the widgets in the current tab
260
if(_buttonGroup.size() > 0)
261
_focusList.push_back(_buttonGroup);
263
// Finally, the moment we've all been waiting for :)
264
// Set the actual focus widget
266
_focusedWidget = tabFocusWidget;
267
else if(!_focusedWidget && _focusList.size() > 0)
268
_focusedWidget = _focusList[0];
233
271
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
338
370
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
339
371
void Dialog::handleMouseDown(int x, int y, int button, int clickCount)
342
w = findWidget(x, y);
373
Widget* w = findWidget(x, y);
349
w->handleMouseDown(x - (w->getAbsX() - _x), y - (w->getAbsY() - _y), button, clickCount);
379
w->handleMouseDown(x - (w->getAbsX() - _x), y - (w->getAbsY() - _y),
352
383
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
353
384
void Dialog::handleMouseUp(int x, int y, int button, int clickCount)
357
386
if(_focusedWidget)
359
388
// Lose focus on mouseup unless the widget requested to retain the focus
372
401
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
373
402
void Dialog::handleMouseWheel(int x, int y, int direction)
377
404
// This may look a bit backwards, but I think it makes more sense for
378
405
// the mouse wheel to primarily affect the widget the mouse is at than
379
406
// the widget that happens to be focused.
381
w = findWidget(x, y);
408
Widget* w = findWidget(x, y);
383
410
w = _focusedWidget;
385
412
w->handleMouseWheel(x, y, direction);
557
598
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
599
void Dialog::getTabIdForWidget(Widget* w)
601
if(_myTabList.size() == 0 || !w)
604
for(uInt32 id = 0; id < _myTabList.size(); ++id)
606
if(w->_boss == _myTabList[id].widget)
614
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
615
bool Dialog::cycleTab(int direction)
617
if(_tabID >= 0 && _tabID < (int)_myTabList.size())
619
_myTabList[_tabID].widget->cycleTab(direction);
625
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
558
626
void Dialog::handleCommand(CommandSender* sender, int cmd, int data, int id)
562
630
case kTabChangedCmd:
563
// Add this focus list for the given tab to the global focus list
564
buildFocusWidgetList(++data);
632
buildCurrentFocusList(id);
686
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
687
Dialog::Focus::Focus(Widget* w)
692
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
693
Dialog::Focus::~Focus()
698
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
699
Dialog::TabFocus::TabFocus(TabWidget* w)
705
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
706
Dialog::TabFocus::~TabFocus()
711
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
712
void Dialog::TabFocus::appendFocusList(WidgetArray& list)
714
int active = widget->getActiveTab();
716
if(active >= 0 && active < (int)focus.size())
717
list.push_back(focus[active].list);
720
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
721
void Dialog::TabFocus::saveCurrentFocus(Widget* w)
723
if(currentTab < focus.size() &&
724
Widget::isWidgetInChain(focus[currentTab].list, w))
725
focus[currentTab].widget = w;
728
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
729
Widget* Dialog::TabFocus::getNewFocus()
731
currentTab = widget->getActiveTab();
733
return (currentTab < focus.size()) ? focus[currentTab].widget : 0;