From e1e492f62253e29e90bfb1a0a14c70f66124277a Mon Sep 17 00:00:00 2001 From: stephena Date: Wed, 21 Dec 2005 01:50:16 +0000 Subject: [PATCH] Finally fixed widget focus issue with the EventMappingWidget and the TabWidget. The fix is not as clean as I'd like, since it basically checks for a certain case only (a hack). The TabWidget really does cause a lot of problems, but for now I just work around it. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@921 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- stella/src/gui/Dialog.cxx | 23 ++++++++++------------- stella/src/gui/EventMappingWidget.cxx | 3 +-- stella/src/gui/InputDialog.cxx | 10 +++------- stella/src/gui/TabWidget.cxx | 9 ++++++++- stella/src/gui/TabWidget.hxx | 3 ++- stella/src/gui/Widget.cxx | 11 ++++++----- stella/src/gui/Widget.hxx | 5 +++-- 7 files changed, 33 insertions(+), 31 deletions(-) diff --git a/stella/src/gui/Dialog.cxx b/stella/src/gui/Dialog.cxx index 6a7e2f5e8..811e0bce9 100644 --- a/stella/src/gui/Dialog.cxx +++ b/stella/src/gui/Dialog.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: Dialog.cxx,v 1.36 2005-12-20 19:05:16 stephena Exp $ +// $Id: Dialog.cxx,v 1.37 2005-12-21 01:50:16 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -101,6 +101,7 @@ void Dialog::addFocusWidget(Widget* w) if(_ourFocusList.size() == 0) { Focus f; + f.focusedWidget = 0; _ourFocusList.push_back(f); } _ourFocusList[0].focusedWidget = w; @@ -121,8 +122,8 @@ void Dialog::addToFocusList(WidgetArray& list, int id) } _ourFocusList[id].focusList.push_back(list); - if(id == 0) - _focusList = _ourFocusList[id].focusList; + if(id == 0 && _ourFocusList.size() > 0) + _focusList = _ourFocusList[0].focusList; if(list.size() > 0 && !(list[0]->getFlags() & WIDGET_NODRAW_FOCUS)) _ourFocusList[id].focusedWidget = list[0]; @@ -167,7 +168,11 @@ void Dialog::buildFocusWidgetList(int id) _focusList.push_back(_ourFocusList[_focusID].focusList); // Only update _focusedWidget if it doesn't belong to the main focus list - if(!Widget::isWidgetInChain(_ourFocusList[0].focusList, _focusedWidget)) + // HACK - figure out how to properly deal with only one focus-able widget + // in a tab -- TabWidget is the spawn of the devil + if(_focusList.size() == 1) + _focusedWidget = _focusList[0]; + else if(!Widget::isWidgetInChain(_ourFocusList[0].focusList, _focusedWidget)) _focusedWidget = _ourFocusList[_focusID].focusedWidget; } else @@ -230,13 +235,7 @@ void Dialog::handleMouseDown(int x, int y, int button, int clickCount) _dragWidget = w; - // If the click occured inside a widget which is not the currently - // focused one, change the focus to that widget. - if(w && w != _focusedWidget && w->wantsFocus()) - { - // Redraw widgets for new focus - _focusedWidget = Widget::setFocusForChain(this, getFocusList(), w, 0); - } + setFocus(w); if(w) w->handleMouseDown(x - (w->getAbsX() - _x), y - (w->getAbsY() - _y), button, clickCount); @@ -265,8 +264,6 @@ void Dialog::handleMouseUp(int x, int y, int button, int clickCount) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Dialog::handleMouseWheel(int x, int y, int direction) { -cerr << "_focusedWidget = " << _focusedWidget << endl; - Widget* w; // This may look a bit backwards, but I think it makes more sense for diff --git a/stella/src/gui/EventMappingWidget.cxx b/stella/src/gui/EventMappingWidget.cxx index c9b2ddecb..e1f631990 100644 --- a/stella/src/gui/EventMappingWidget.cxx +++ b/stella/src/gui/EventMappingWidget.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: EventMappingWidget.cxx,v 1.3 2005-12-20 19:05:16 stephena Exp $ +// $Id: EventMappingWidget.cxx,v 1.4 2005-12-21 01:50:16 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -152,7 +152,6 @@ void EventMappingWidget::stopRemapping() myCancelMapButton->setEnabled(false); // Make sure the list widget is in a known state -cerr << "myActionSelected = " << myActionSelected << endl; if(myActionSelected >= 0) { drawKeyMapping(); diff --git a/stella/src/gui/InputDialog.cxx b/stella/src/gui/InputDialog.cxx index c1f584b2a..aa384c65b 100644 --- a/stella/src/gui/InputDialog.cxx +++ b/stella/src/gui/InputDialog.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: InputDialog.cxx,v 1.7 2005-12-20 19:05:16 stephena Exp $ +// $Id: InputDialog.cxx,v 1.8 2005-12-21 01:50:16 stephena Exp $ //============================================================================ #include "OSystem.hxx" @@ -56,13 +56,11 @@ InputDialog::InputDialog( myTab->setParentWidget(tabID, myEventMapper); addToFocusList(myEventMapper->getFocusList(), tabID); -cerr << "size = " << myEventMapper->getFocusList().size() - << ", tabid = " << tabID << endl; - // 2) Virtual device support addVDeviceTab(); - // Activate the first tab + // Finalize the tabs, and activate the first tab + myTab->activateTabs(); myTab->setActiveTab(0); // Add OK and Cancel buttons @@ -182,8 +180,6 @@ void InputDialog::addVDeviceTab() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void InputDialog::loadConfig() { - myEventMapper->loadConfig(); - // Left & right ports const string& sa1 = instance()->settings().getString("sa1"); int lport = sa1 == "right" ? 2 : 1; diff --git a/stella/src/gui/TabWidget.cxx b/stella/src/gui/TabWidget.cxx index b909bb926..d6166494c 100644 --- a/stella/src/gui/TabWidget.cxx +++ b/stella/src/gui/TabWidget.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: TabWidget.cxx,v 1.18 2005-09-29 18:50:51 stephena Exp $ +// $Id: TabWidget.cxx,v 1.19 2005-12-21 01:50:16 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -126,6 +126,13 @@ void TabWidget::updateActiveTab() _boss->redrawFocus(); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void TabWidget::activateTabs() +{ + for(unsigned int i = 0; i <_tabs.size(); ++i) + sendCommand(kTabChangedCmd, i-1, -1); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void TabWidget::cycleTab(int direction) { diff --git a/stella/src/gui/TabWidget.hxx b/stella/src/gui/TabWidget.hxx index 2cfeb616a..b12e8f047 100644 --- a/stella/src/gui/TabWidget.hxx +++ b/stella/src/gui/TabWidget.hxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: TabWidget.hxx,v 1.10 2005-12-09 01:16:14 stephena Exp $ +// $Id: TabWidget.hxx,v 1.11 2005-12-21 01:50:16 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -58,6 +58,7 @@ class TabWidget : public Widget, public CommandSender //void removeTab(int tabID); // Setting the active tab: void setActiveTab(int tabID, bool show = false); + void activateTabs(); void cycleTab(int direction); // setActiveTab changes the value of _firstWidget. This means Widgets added afterwards // will be added to the active tab. diff --git a/stella/src/gui/Widget.cxx b/stella/src/gui/Widget.cxx index 7357f0ec2..dc97f5cc3 100644 --- a/stella/src/gui/Widget.cxx +++ b/stella/src/gui/Widget.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: Widget.cxx,v 1.39 2005-12-19 02:19:49 stephena Exp $ +// $Id: Widget.cxx,v 1.40 2005-12-21 01:50:16 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -333,10 +333,11 @@ void StaticTextWidget::drawWidget(bool hilite) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ButtonWidget::ButtonWidget(GuiObject *boss, int x, int y, int w, int h, const string& label, int cmd, uInt8 hotkey) - : StaticTextWidget(boss, x, y, w, h, label, kTextAlignCenter), - CommandSender(boss), - _cmd(cmd), - _hotkey(hotkey) + : StaticTextWidget(boss, x, y, w, h, label, kTextAlignCenter), + CommandSender(boss), + _cmd(cmd), + _editable(false), + _hotkey(hotkey) { _flags = WIDGET_ENABLED | WIDGET_BORDER | WIDGET_CLEARBG; _type = kButtonWidget; diff --git a/stella/src/gui/Widget.hxx b/stella/src/gui/Widget.hxx index c8b04e70b..94edd6c45 100644 --- a/stella/src/gui/Widget.hxx +++ b/stella/src/gui/Widget.hxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: Widget.hxx,v 1.41 2005-12-19 02:19:49 stephena Exp $ +// $Id: Widget.hxx,v 1.42 2005-12-21 01:50:16 stephena Exp $ // // Based on code from ScummVM - Scumm Interpreter // Copyright (C) 2002-2004 The ScummVM project @@ -72,7 +72,7 @@ enum { This is the base class for all widgets. @author Stephen Anthony - @version $Id: Widget.hxx,v 1.41 2005-12-19 02:19:49 stephena Exp $ + @version $Id: Widget.hxx,v 1.42 2005-12-21 01:50:16 stephena Exp $ */ class Widget : public GuiObject { @@ -212,6 +212,7 @@ class ButtonWidget : public StaticTextWidget, public CommandSender protected: int _cmd; + bool _editable; uInt8 _hotkey; };