summaryrefslogtreecommitdiff
path: root/indra/newview/llfloaterpreference.cpp
diff options
context:
space:
mode:
authorandreykproductengine <andreykproductengine@lindenlab.com>2019-10-03 19:46:12 +0300
committerAndrey Kleshchev <andreykproductengine@lindenlab.com>2020-06-23 14:50:02 +0300
commit13a25be08f0c81a759076907d7950baf4f2c3ef2 (patch)
tree34e9b80bd35c2594a07df9a877a16804b1dd3551 /indra/newview/llfloaterpreference.cpp
parent2e656ed358af28f56c8b900345956d431f8c7b4d (diff)
SL-6109 Better menu accelerator support and slight reorganization
Diffstat (limited to 'indra/newview/llfloaterpreference.cpp')
-rw-r--r--indra/newview/llfloaterpreference.cpp306
1 files changed, 3 insertions, 303 deletions
diff --git a/indra/newview/llfloaterpreference.cpp b/indra/newview/llfloaterpreference.cpp
index 3668f71feb..e71c7d58e2 100644
--- a/indra/newview/llfloaterpreference.cpp
+++ b/indra/newview/llfloaterpreference.cpp
@@ -43,7 +43,6 @@
#include "llcombobox.h"
#include "llcommandhandler.h"
#include "lldirpicker.h"
-#include "lldrawfrustum.h"
#include "lleventtimer.h"
#include "llfeaturemanager.h"
#include "llfocusmgr.h"
@@ -161,306 +160,6 @@ struct LabelTable : public LLInitParam::Block<LabelTable>
{}
};
-// Filters for LLSetKeyBindDialog
-static const U32 ALLOW_MOUSE = 1;
-static const U32 ALLOW_MASK_MOUSE = 2;
-static const U32 ALLOW_KEYS = 4; //keyboard
-static const U32 ALLOW_MASK_KEYS = 8;
-static const U32 ALLOW_MASKS = 16;
-static const U32 CAN_IGNORE_MASKS = 32; // For example W (aka Forward) should work regardless of SHIFT being pressed
-static const U32 DEFAULT_KEY_FILTER = ALLOW_MOUSE | ALLOW_MASK_MOUSE | ALLOW_KEYS | ALLOW_MASK_KEYS | CAN_IGNORE_MASKS;
-
-class LLSetKeyBindDialog : public LLModalDialog, public LLDrawFrustum
-{
-public:
- LLSetKeyBindDialog(const LLSD& key);
- ~LLSetKeyBindDialog();
-
- /*virtual*/ BOOL postBuild();
- /*virtual*/ void onClose(bool app_quiting);
- /*virtual*/ void draw();
-
- void setParent(LLPanelPreferenceControls* parent, U32 key_mask = DEFAULT_KEY_FILTER);
-
- BOOL handleKeyHere(KEY key, MASK mask);
- BOOL handleAnyMouseClick(S32 x, S32 y, MASK mask, EMouseClickType clicktype, BOOL down);
- static void onCancel(void* user_data);
- static void onBlank(void* user_data);
- static void onDefault(void* user_data);
- static void onClickTimeout(void* user_data, MASK mask);
-
- class Updater;
-
-private:
- void setKeyBind(EMouseClickType click, KEY key, MASK mask, bool ignore);
- LLPanelPreferenceControls* pParent;
- LLCheckBoxCtrl* pCheckBox;
-
- U32 mKeyFilterMask;
- Updater *pUpdater;
-};
-
-class LLSetKeyBindDialog::Updater : public LLEventTimer
-{
-public:
-
- typedef boost::function<void(MASK)> callback_t;
-
- Updater(callback_t cb, F32 period, MASK mask)
- :LLEventTimer(period),
- mMask(mask),
- mCallback(cb)
- {
- mEventTimer.start();
- }
-
- virtual ~Updater(){}
-
-protected:
- BOOL tick()
- {
- mCallback(mMask);
- // Deletes itseft after execution
- return TRUE;
- }
-
-private:
- MASK mMask;
- callback_t mCallback;
-};
-
-LLSetKeyBindDialog::LLSetKeyBindDialog(const LLSD& key)
- : LLModalDialog(key),
- pParent(NULL),
- mKeyFilterMask(DEFAULT_KEY_FILTER),
- pUpdater(NULL)
-{
-}
-
-LLSetKeyBindDialog::~LLSetKeyBindDialog()
-{
-}
-
-//virtual
-BOOL LLSetKeyBindDialog::postBuild()
-{
- childSetAction("SetEmpty", onBlank, this);
- childSetAction("Default", onDefault, this);
- childSetAction("Cancel", onCancel, this);
- getChild<LLUICtrl>("Cancel")->setFocus(TRUE);
-
- pCheckBox = getChild<LLCheckBoxCtrl>("ignore_masks");
-
- gFocusMgr.setKeystrokesOnly(TRUE);
-
- return TRUE;
-}
-
-//virtual
-void LLSetKeyBindDialog::onClose(bool app_quiting)
-{
- if (pParent)
- {
- pParent->onCancelKeyBind();
- pParent = NULL;
- }
- if (pUpdater)
- {
- // Doubleclick timer has't fired, delete it
- delete pUpdater;
- pUpdater = NULL;
- }
- LLModalDialog::onClose(app_quiting);
-}
-
-//virtual
-void LLSetKeyBindDialog::draw()
-{
- LLRect local_rect;
- drawFrustum(local_rect, this, (LLView*)getDragHandle(), hasFocus());
- LLModalDialog::draw();
-}
-
-void LLSetKeyBindDialog::setParent(LLPanelPreferenceControls* parent, U32 key_mask)
-{
- pParent = parent;
- setFrustumOrigin(parent);
- mKeyFilterMask = key_mask;
-
- LLTextBase *text_ctrl = getChild<LLTextBase>("descritption");
-
- std::string input;
- if ((key_mask & ALLOW_MOUSE) != 0)
- {
- input = getString("mouse");
- }
- if ((key_mask & ALLOW_KEYS) != 0)
- {
- if (!input.empty())
- {
- input += ", ";
- }
- input += getString("keyboard");
- }
- text_ctrl->setTextArg("[INPUT]", input);
-
- bool can_ignore_masks = (key_mask & CAN_IGNORE_MASKS) != 0;
- pCheckBox->setVisible(can_ignore_masks);
- pCheckBox->setValue(false);
-}
-
-BOOL LLSetKeyBindDialog::handleKeyHere(KEY key, MASK mask)
-{
- if ((key == 'Q' && mask == MASK_CONTROL)
- || key == KEY_ESCAPE)
- {
- closeFloater();
- return TRUE;
- }
-
- if (key == KEY_DELETE)
- {
- setKeyBind(CLICK_NONE, KEY_NONE, MASK_NONE, false);
- closeFloater();
- return FALSE;
- }
-
- // forbidden keys
- if (key == KEY_NONE
- || key == KEY_RETURN
- || key == KEY_BACKSPACE)
- {
- return FALSE;
- }
-
- if ((mKeyFilterMask & ALLOW_MASKS) == 0
- && (key == KEY_CONTROL || key == KEY_SHIFT || key == KEY_ALT))
- {
- // mask by themself are not allowed
- return FALSE;
- }
- else if ((mKeyFilterMask & ALLOW_KEYS) == 0)
- {
- // basic keys not allowed
- return FALSE;
- }
- else if ((mKeyFilterMask & ALLOW_MASK_KEYS) == 0 && mask != 0)
- {
- // masked keys not allowed
- return FALSE;
- }
-
- setKeyBind(CLICK_NONE, key, mask, pCheckBox->getValue().asBoolean());
- closeFloater();
- return TRUE;
-}
-
-BOOL LLSetKeyBindDialog::handleAnyMouseClick(S32 x, S32 y, MASK mask, EMouseClickType clicktype, BOOL down)
-{
- BOOL result = FALSE;
- if (!pParent)
- {
- // we already processed 'down' event, this is 'up', consume
- closeFloater();
- result = TRUE;
- }
- if (!result && clicktype == CLICK_LEFT)
- {
- // try handling buttons first
- if (down)
- {
- result = LLView::handleMouseDown(x, y, mask);
- }
- else
- {
- result = LLView::handleMouseUp(x, y, mask);
- }
- if (result)
- {
- setFocus(TRUE);
- gFocusMgr.setKeystrokesOnly(TRUE);
- }
- // ignore selection related combinations
- else if (down && (mask & (MASK_SHIFT | MASK_CONTROL)) == 0)
- {
- // this can be a double click, wait a bit;
- if (!pUpdater)
- {
- // Note: default doubleclick time is 500ms, but can stretch up to 5s
- pUpdater = new Updater(boost::bind(&onClickTimeout, this, _1), 0.7f, mask);
- result = TRUE;
- }
- }
- }
-
- if (!result
- && (clicktype != CLICK_LEFT) // subcases were handled above
- && ((mKeyFilterMask & ALLOW_MOUSE) != 0)
- && (clicktype != CLICK_RIGHT || mask != 0) // reassigning menu button is not supported
- && ((mKeyFilterMask & ALLOW_MASK_MOUSE) != 0 || mask == 0)) // reserved for selection
- {
- setKeyBind(clicktype, KEY_NONE, mask, pCheckBox->getValue().asBoolean());
- result = TRUE;
- if (!down)
- {
- // wait for 'up' event before closing
- // alternative: set pUpdater
- closeFloater();
- }
- }
-
- return result;
-}
-
-//static
-void LLSetKeyBindDialog::onCancel(void* user_data)
-{
- LLSetKeyBindDialog* self = (LLSetKeyBindDialog*)user_data;
- self->closeFloater();
-}
-
-//static
-void LLSetKeyBindDialog::onBlank(void* user_data)
-{
- LLSetKeyBindDialog* self = (LLSetKeyBindDialog*)user_data;
- // tmp needs 'no key' button
- self->setKeyBind(CLICK_NONE, KEY_NONE, MASK_NONE, false);
- self->closeFloater();
-}
-
-//static
-void LLSetKeyBindDialog::onDefault(void* user_data)
-{
- LLSetKeyBindDialog* self = (LLSetKeyBindDialog*)user_data;
- if (self->pParent)
- {
- self->pParent->onDefaultKeyBind();
- self->pParent = NULL;
- }
- self->closeFloater();
-}
-
-//static
-void LLSetKeyBindDialog::onClickTimeout(void* user_data, MASK mask)
-{
- LLSetKeyBindDialog* self = (LLSetKeyBindDialog*)user_data;
-
- // timer will delete itself after timeout
- self->pUpdater = NULL;
-
- self->setKeyBind(CLICK_LEFT, KEY_NONE, mask, self->pCheckBox->getValue().asBoolean());
- self->closeFloater();
-}
-
-void LLSetKeyBindDialog::setKeyBind(EMouseClickType click, KEY key, MASK mask, bool ignore)
-{
- if (pParent)
- {
- pParent->onSetKeyBind(click, key, mask, ignore);
- pParent = NULL;
- }
-}
-
// global functions
@@ -3197,11 +2896,11 @@ void LLPanelPreferenceControls::onModeCommit()
}
// todo: copy onSetKeyBind to interface and inherit from interface
-void LLPanelPreferenceControls::onSetKeyBind(EMouseClickType click, KEY key, MASK mask, bool ignore_mask)
+bool LLPanelPreferenceControls::onSetKeyBind(EMouseClickType click, KEY key, MASK mask, bool ignore_mask)
{
if (!mConflictHandler[mEditingMode].canAssignControl(mEditingControl))
{
- return;
+ return true;
}
if ( mEditingColumn > 0)
@@ -3210,6 +2909,7 @@ void LLPanelPreferenceControls::onSetKeyBind(EMouseClickType click, KEY key, MAS
}
updateTable();
+ return true;
}
void LLPanelPreferenceControls::onRestoreDefaults()