From a82b200ae71f6b5ee9a13778974f33983e0a32aa Mon Sep 17 00:00:00 2001 From: Cameron Cawley Date: Wed, 6 Jan 2021 22:13:14 +0000 Subject: [PATCH] GUI: Allow specifying a command for PopUp widgets --- gui/options.cpp | 5 +++-- gui/widgets/popup.cpp | 10 ++++++---- gui/widgets/popup.h | 11 ++++------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/gui/options.cpp b/gui/options.cpp index ca78c7152a5..131f64340a2 100644 --- a/gui/options.cpp +++ b/gui/options.cpp @@ -113,6 +113,7 @@ enum { #ifdef USE_CLOUD enum { + kStoragePopUpCmd = 'sPup', kSyncSavesStorageCmd = 'ssst', kDownloadStorageCmd = 'dlst', kRunServerCmd = 'rnsv', @@ -2194,7 +2195,7 @@ void GlobalOptionsDialog::addMiscControls(GuiObject *boss, const Common::String #ifdef USE_LIBCURL void GlobalOptionsDialog::addCloudControls(GuiObject *boss, const Common::String &prefix, bool lowres) { _storagePopUpDesc = new StaticTextWidget(boss, prefix + "StoragePopupDesc", _("Active storage:"), _("Active cloud storage")); - _storagePopUp = new PopUpWidget(boss, prefix + "StoragePopup"); + _storagePopUp = new PopUpWidget(boss, prefix + "StoragePopup", Common::U32String(), kStoragePopUpCmd); Common::StringArray list = CloudMan.listStorages(); for (uint32 i = 0; i < list.size(); ++i) { _storagePopUp->appendEntry(_(list[i]), i); @@ -2643,7 +2644,7 @@ void GlobalOptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3 setupCloudTab(); break; } - case kPopUpItemSelectedCmd: { + case kStoragePopUpCmd: { if (_storageWizardCodeBox) _storageWizardCodeBox->setEditString(Common::U32String()); // update container's scrollbar diff --git a/gui/widgets/popup.cpp b/gui/widgets/popup.cpp index 148abd7be09..8170bdb71dc 100644 --- a/gui/widgets/popup.cpp +++ b/gui/widgets/popup.cpp @@ -428,19 +428,21 @@ void PopUpDialog::drawMenuEntry(int entry, bool hilite) { // PopUpWidget // -PopUpWidget::PopUpWidget(GuiObject *boss, const String &name, const U32String &tooltip) +PopUpWidget::PopUpWidget(GuiObject *boss, const String &name, const U32String &tooltip, uint32 cmd) : Widget(boss, name, tooltip), CommandSender(boss) { setFlags(WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_IGNORE_DRAG); _type = kPopUpWidget; + _cmd = cmd; _selectedItem = -1; _leftPadding = _rightPadding = 0; } -PopUpWidget::PopUpWidget(GuiObject *boss, int x, int y, int w, int h, const U32String &tooltip) +PopUpWidget::PopUpWidget(GuiObject *boss, int x, int y, int w, int h, const U32String &tooltip, uint32 cmd) : Widget(boss, x, y, w, h, tooltip), CommandSender(boss) { setFlags(WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_IGNORE_DRAG); _type = kPopUpWidget; + _cmd = cmd; _selectedItem = -1; @@ -463,7 +465,7 @@ void PopUpWidget::handleMouseDown(int x, int y, int button, int clickCount) { int newSel = popupDialog.runModal(); if (newSel != -1 && _selectedItem != newSel) { _selectedItem = newSel; - sendCommand(kPopUpItemSelectedCmd, _entries[_selectedItem].tag); + sendCommand(_cmd, _entries[_selectedItem].tag); markAsDirty(); } } @@ -483,7 +485,7 @@ void PopUpWidget::handleMouseWheel(int x, int y, int direction) { if ((newSelection >= 0) && (newSelection < (int)_entries.size()) && (newSelection != _selectedItem)) { _selectedItem = newSelection; - sendCommand(kPopUpItemSelectedCmd, _entries[_selectedItem].tag); + sendCommand(_cmd, _entries[_selectedItem].tag); markAsDirty(); } } diff --git a/gui/widgets/popup.h b/gui/widgets/popup.h index 79e0f574499..b066aa56137 100644 --- a/gui/widgets/popup.h +++ b/gui/widgets/popup.h @@ -30,15 +30,11 @@ namespace GUI { -enum { - kPopUpItemSelectedCmd = 'POPs' -}; - /** * Popup or dropdown widget which, when clicked, "pop up" a list of items and * lets the user pick on of them. * - * Implementation wise, when the user selects an item, then a kPopUpItemSelectedCmd + * Implementation wise, when the user selects an item, then the specified command * is broadcast, with data being equal to the tag value of the selected entry. */ class PopUpWidget : public Widget, public CommandSender { @@ -56,10 +52,11 @@ protected: int _leftPadding; int _rightPadding; + uint32 _cmd; public: - PopUpWidget(GuiObject *boss, const String &name, const U32String &tooltip = U32String()); - PopUpWidget(GuiObject *boss, int x, int y, int w, int h, const U32String &tooltip = U32String()); + PopUpWidget(GuiObject *boss, const String &name, const U32String &tooltip = U32String(), uint32 cmd = 0); + PopUpWidget(GuiObject *boss, int x, int y, int w, int h, const U32String &tooltip = U32String(), uint32 cmd = 0); void handleMouseDown(int x, int y, int button, int clickCount) override; void handleMouseWheel(int x, int y, int direction) override;