summaryrefslogtreecommitdiff
path: root/indra/llui
diff options
context:
space:
mode:
authorLeyla Farazha <leyla@lindenlab.com>2011-10-05 15:12:07 -0700
committerLeyla Farazha <leyla@lindenlab.com>2011-10-05 15:12:07 -0700
commit11a0d0cd59c86cee18b6b2fd92fcbac62502ede0 (patch)
tree74dba5131b40874232a8dd50a2a79f9d81d3f143 /indra/llui
parent6f9ed8b303e9e840fcd624b03ec0958dceba3dc7 (diff)
parenteda12bd009d8f71eb82b6e6238335a172d6e5fb0 (diff)
merge
Diffstat (limited to 'indra/llui')
-rw-r--r--indra/llui/llcommandmanager.cpp42
-rw-r--r--indra/llui/llcommandmanager.h56
-rw-r--r--indra/llui/lllineeditor.cpp1
-rw-r--r--indra/llui/lltoolbar.cpp111
-rw-r--r--indra/llui/lltoolbar.h44
-rw-r--r--indra/llui/llui.h57
6 files changed, 224 insertions, 87 deletions
diff --git a/indra/llui/llcommandmanager.cpp b/indra/llui/llcommandmanager.cpp
index b1147134c2..2bd50af7af 100644
--- a/indra/llui/llcommandmanager.cpp
+++ b/indra/llui/llcommandmanager.cpp
@@ -48,24 +48,36 @@ const LLCommandId LLCommandId::null("null command");
//
LLCommand::Params::Params()
- : function("function")
- , available_in_toybox("available_in_toybox", false)
+ : available_in_toybox("available_in_toybox", false)
, icon("icon")
, label_ref("label_ref")
, name("name")
- , parameter("parameter")
, tooltip_ref("tooltip_ref")
+ , execute_function("execute_function")
+ , execute_parameters("execute_parameters")
+ , is_enabled_function("is_enabled_function")
+ , is_enabled_parameters("is_enabled_parameters")
+ , is_running_function("is_running_function")
+ , is_running_parameters("is_running_parameters")
+ , is_starting_function("is_starting_function")
+ , is_starting_parameters("is_starting_parameters")
{
}
LLCommand::LLCommand(const LLCommand::Params& p)
- : mFunction(p.function)
- , mAvailableInToybox(p.available_in_toybox)
+ : mAvailableInToybox(p.available_in_toybox)
, mIcon(p.icon)
, mIdentifier(p.name)
, mLabelRef(p.label_ref)
- , mParameter(p.parameter)
, mTooltipRef(p.tooltip_ref)
+ , mExecuteFunction(p.execute_function)
+ , mExecuteParameters(p.execute_parameters)
+ , mIsEnabledFunction(p.is_enabled_function)
+ , mIsEnabledParameters(p.is_enabled_parameters)
+ , mIsRunningFunction(p.is_running_function)
+ , mIsRunningParameters(p.is_running_parameters)
+ , mIsStartingFunction(p.is_starting_function)
+ , mIsStartingParameters(p.is_starting_parameters)
{
}
@@ -112,9 +124,25 @@ LLCommand * LLCommandManager::getCommand(const LLCommandId& commandId)
return command_match;
}
+LLCommand * LLCommandManager::getCommand(const LLUUID& commandUUID)
+{
+ LLCommand * command_match = NULL;
+
+ CommandUUIDMap::const_iterator found = mCommandUUIDs.find(commandUUID);
+
+ if (found != mCommandUUIDs.end())
+ {
+ command_match = mCommands[found->second];
+ }
+
+ return command_match;
+}
+
void LLCommandManager::addCommand(LLCommand * command)
{
- mCommandIndices[command->id()] = mCommands.size();
+ LLCommandId command_id = command->id();
+ mCommandIndices[command_id] = mCommands.size();
+ mCommandUUIDs[command_id.uuid()] = mCommands.size();
mCommands.push_back(command);
lldebugs << "Successfully added command: " << command->id().name() << llendl;
diff --git a/indra/llui/llcommandmanager.h b/indra/llui/llcommandmanager.h
index 6481a05689..8e5abd6461 100644
--- a/indra/llui/llcommandmanager.h
+++ b/indra/llui/llcommandmanager.h
@@ -52,13 +52,18 @@ public:
LLCommandId(const std::string& name)
: mName(name)
- {}
+ {
+ mUUID = LLUUID::generateNewID(name);
+ }
LLCommandId(const Params& p)
: mName(p.name)
- {}
+ {
+ mUUID = LLUUID::generateNewID(p.name);
+ }
const std::string& name() const { return mName; }
+ const LLUUID& uuid() const { return mUUID; }
bool operator!=(const LLCommandId& command) const
{
@@ -79,45 +84,77 @@ public:
private:
std::string mName;
+ LLUUID mUUID;
};
typedef std::list<LLCommandId> command_id_list_t;
+
class LLCommand
{
public:
struct Params : public LLInitParam::Block<Params>
{
Mandatory<bool> available_in_toybox;
- Mandatory<std::string> function;
Mandatory<std::string> icon;
Mandatory<std::string> label_ref;
Mandatory<std::string> name;
- Optional<LLSD> parameter;
Mandatory<std::string> tooltip_ref;
+ Mandatory<std::string> execute_function;
+ Optional<LLSD> execute_parameters;
+
+ Optional<std::string> is_enabled_function;
+ Optional<LLSD> is_enabled_parameters;
+
+ Optional<std::string> is_running_function;
+ Optional<LLSD> is_running_parameters;
+
+ Optional<std::string> is_starting_function;
+ Optional<LLSD> is_starting_parameters;
+
Params();
};
LLCommand(const LLCommand::Params& p);
const bool availableInToybox() const { return mAvailableInToybox; }
- const std::string& functionName() const { return mFunction; }
const std::string& icon() const { return mIcon; }
const LLCommandId& id() const { return mIdentifier; }
const std::string& labelRef() const { return mLabelRef; }
- const LLSD& parameter() const { return mParameter; }
const std::string& tooltipRef() const { return mTooltipRef; }
+ const std::string& executeFunctionName() const { return mExecuteFunction; }
+ const LLSD& executeParameters() const { return mExecuteParameters; }
+
+ const std::string& isEnabledFunctionName() const { return mIsEnabledFunction; }
+ const LLSD& isEnabledParameters() const { return mIsEnabledParameters; }
+
+ const std::string& isRunningFunctionName() const { return mIsRunningFunction; }
+ const LLSD& isRunningParameters() const { return mIsRunningParameters; }
+
+ const std::string& isStartingFunctionName() const { return mIsStartingFunction; }
+ const LLSD& isStartingParameters() const { return mIsStartingParameters; }
+
private:
LLCommandId mIdentifier;
bool mAvailableInToybox;
- std::string mFunction;
std::string mIcon;
std::string mLabelRef;
- LLSD mParameter;
std::string mTooltipRef;
+
+ std::string mExecuteFunction;
+ LLSD mExecuteParameters;
+
+ std::string mIsEnabledFunction;
+ LLSD mIsEnabledParameters;
+
+ std::string mIsRunningFunction;
+ LLSD mIsRunningParameters;
+
+ std::string mIsStartingFunction;
+ LLSD mIsStartingParameters;
};
@@ -141,6 +178,7 @@ public:
U32 commandCount() const;
LLCommand * getCommand(U32 commandIndex);
LLCommand * getCommand(const LLCommandId& commandId);
+ LLCommand * getCommand(const LLUUID& commandUUID);
static bool load();
@@ -148,11 +186,13 @@ protected:
void addCommand(LLCommand * command);
private:
+ typedef std::map<LLUUID, U32> CommandUUIDMap;
typedef std::map<LLCommandId, U32> CommandIndexMap;
typedef std::vector<LLCommand *> CommandVector;
CommandVector mCommands;
CommandIndexMap mCommandIndices;
+ CommandUUIDMap mCommandUUIDs;
};
diff --git a/indra/llui/lllineeditor.cpp b/indra/llui/lllineeditor.cpp
index ebdd47ae80..06dfc90d83 100644
--- a/indra/llui/lllineeditor.cpp
+++ b/indra/llui/lllineeditor.cpp
@@ -198,6 +198,7 @@ LLLineEditor::~LLLineEditor()
void LLLineEditor::onFocusReceived()
{
+ gEditMenuHandler = this;
LLUICtrl::onFocusReceived();
updateAllowingLanguageInput();
}
diff --git a/indra/llui/lltoolbar.cpp b/indra/llui/lltoolbar.cpp
index efa077ffa1..07beb147d7 100644
--- a/indra/llui/lltoolbar.cpp
+++ b/indra/llui/lltoolbar.cpp
@@ -107,7 +107,6 @@ LLToolBar::LLToolBar(const LLToolBar::Params& p)
{
mButtonParams[LLToolBarEnums::BTNTYPE_ICONS_WITH_TEXT] = p.button_icon_and_text;
mButtonParams[LLToolBarEnums::BTNTYPE_ICONS_ONLY] = p.button_icon;
- mUUID = LLUUID::generateNewID(p.name);
}
LLToolBar::~LLToolBar()
@@ -193,21 +192,71 @@ void LLToolBar::initFromParams(const LLToolBar::Params& p)
mNeedsLayout = true;
}
-bool LLToolBar::addCommand(const LLCommandId& commandId)
+bool LLToolBar::addCommand(const LLCommandId& commandId, int rank)
{
LLCommand * command = LLCommandManager::instance().getCommand(commandId);
if (!command) return false;
- mButtonCommands.push_back(commandId);
+ // Create the button and do the things that don't need ordering
LLToolBarButton* button = createButton(commandId);
- mButtons.push_back(button);
mButtonPanel->addChild(button);
mButtonMap.insert(std::make_pair(commandId, button));
+
+ // Insert the command and button in the right place in their respective lists
+ if ((rank >= mButtonCommands.size()) || (rank < 0))
+ {
+ // In that case, back load
+ mButtonCommands.push_back(commandId);
+ mButtons.push_back(button);
+ }
+ else
+ {
+ // Insert in place: iterate to the right spot...
+ std::list<LLToolBarButton*>::iterator it_button = mButtons.begin();
+ command_id_list_t::iterator it_command = mButtonCommands.begin();
+ while (rank > 0)
+ {
+ ++it_button;
+ ++it_command;
+ rank--;
+ }
+ // ...then insert
+ mButtonCommands.insert(it_command,commandId);
+ mButtons.insert(it_button,button);
+ }
+
mNeedsLayout = true;
return true;
}
+bool LLToolBar::removeCommand(const LLCommandId& commandId)
+{
+ if (!hasCommand(commandId)) return false;
+
+ // First erase the map record
+ command_id_map::iterator it = mButtonMap.find(commandId);
+ mButtonMap.erase(it);
+
+ // Now iterate on the commands and buttons to identify the relevant records
+ std::list<LLToolBarButton*>::iterator it_button = mButtons.begin();
+ command_id_list_t::iterator it_command = mButtonCommands.begin();
+ while (*it_command != commandId)
+ {
+ ++it_button;
+ ++it_command;
+ }
+
+ // Delete the button and erase the command and button records
+ delete (*it_button);
+ mButtonCommands.erase(it_command);
+ mButtons.erase(it_button);
+
+ mNeedsLayout = true;
+
+ return true;
+}
+
void LLToolBar::clearCommandsList()
{
// Clears the commands list
@@ -328,6 +377,33 @@ void LLToolBar::resizeButtonsInRow(std::vector<LLToolBarButton*>& buttons_in_row
}
}
+int LLToolBar::getRankFromPosition(S32 x, S32 y)
+{
+ int rank = 0;
+
+ LLLayoutStack::ELayoutOrientation orientation = getOrientation(mSideType);
+
+ // Simply compare the passed coord with the buttons outbound box
+ std::list<LLToolBarButton*>::iterator it_button = mButtons.begin();
+ std::list<LLToolBarButton*>::iterator end_button = mButtons.end();
+ while (it_button != end_button)
+ {
+ LLRect button_rect = (*it_button)->getRect();
+ if (((orientation == LLLayoutStack::HORIZONTAL) && (button_rect.mRight > x)) ||
+ ((orientation == LLLayoutStack::VERTICAL) && (button_rect.mTop > y)) )
+ {
+ llinfos << "Merov debug : rank compute: orientation = " << orientation << ", x = " << x << ", y = " << y << llendl;
+ llinfos << "Merov debug : rank compute: rect = " << button_rect.mLeft << ", " << button_rect.mTop << ", " << button_rect.mRight << ", " << button_rect.mBottom << llendl;
+ break;
+ }
+ rank++;
+ ++it_button;
+ }
+ llinfos << "Merov debug : rank = " << rank << llendl;
+
+ return rank;
+}
+
void LLToolBar::updateLayoutAsNeeded()
{
if (!mNeedsLayout) return;
@@ -494,6 +570,7 @@ void LLToolBar::createButtons()
delete button;
}
mButtons.clear();
+ mButtonMap.clear();
BOOST_FOREACH(LLCommandId& command_id, mButtonCommands)
{
@@ -503,7 +580,6 @@ void LLToolBar::createButtons()
mButtonMap.insert(std::make_pair(command_id, button));
}
mNeedsLayout = true;
-
}
LLToolBarButton* LLToolBar::createButton(const LLCommandId& id)
@@ -525,8 +601,8 @@ LLToolBarButton* LLToolBar::createButton(const LLCommandId& id)
if (!mReadOnly)
{
LLUICtrl::CommitCallbackParam cbParam;
- cbParam.function_name = commandp->functionName();
- cbParam.parameter = commandp->parameter();
+ cbParam.function_name = commandp->executeFunctionName();
+ cbParam.parameter = commandp->executeParameters();
button->setCommitCallback(cbParam);
button->setStartDragCallback(mStartDragItemCallback);
button->setHandleDragCallback(mHandleDragItemCallback);
@@ -543,20 +619,20 @@ BOOL LLToolBar::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
EAcceptance* accept,
std::string& tooltip_msg)
{
- llinfos << "Merov debug : handleDragAndDrop. drop = " << drop << ", tooltip = " << tooltip_msg << llendl;
+ llinfos << "Merov debug : handleDragAndDrop. drop = " << drop << ", x = " << x << ", y = " << y << llendl;
// If we have a drop callback, that means that we can handle the drop
BOOL handled = (mHandleDropCallback ? TRUE : FALSE);
- // if drop, time to call the drop callback to get the operation done
+ // if drop is set, it's time to call the callback to get the operation done
if (handled && drop)
{
- handled = mHandleDropCallback(cargo_type,cargo_data,mUUID);
+ handled = mHandleDropCallback(cargo_data, x, y ,this);
}
- // We accept multi drop by default
- *accept = (handled ? ACCEPT_YES_MULTI : ACCEPT_NO);
+ // We accept only single tool drop on toolbars
+ *accept = (handled ? ACCEPT_YES_SINGLE : ACCEPT_NO);
- // We'll use that flag to change the visual aspect of the target on draw()
+ // We'll use that flag to change the visual aspect of the toolbar target on draw()
mDragAndDropTarget = handled;
return handled;
@@ -570,7 +646,6 @@ LLToolBarButton::LLToolBarButton(const Params& p)
mDesiredHeight(p.desired_height),
mId("")
{
- mUUID = LLUUID::generateNewID(p.name);
}
BOOL LLToolBarButton::handleMouseDown(S32 x, S32 y, MASK mask)
@@ -589,15 +664,15 @@ BOOL LLToolBarButton::handleHover(S32 x, S32 y, MASK mask)
{
if (!mIsDragged)
{
- mStartDragItemCallback(x,y,mUUID);
+ mStartDragItemCallback(x,y,mId.uuid());
mIsDragged = true;
handled = TRUE;
}
else
- {
- handled = mHandleDragItemCallback(x,y,mUUID,LLAssetType::AT_WIDGET);
- }
+ {
+ handled = mHandleDragItemCallback(x,y,mId.uuid(),LLAssetType::AT_WIDGET);
}
+ }
else
{
handled = LLButton::handleHover(x, y, mask);
diff --git a/indra/llui/lltoolbar.h b/indra/llui/lltoolbar.h
index 407cbde7d2..a35f6d9db1 100644
--- a/indra/llui/lltoolbar.h
+++ b/indra/llui/lltoolbar.h
@@ -35,9 +35,11 @@
#include "llcommandmanager.h"
#include "llassettype.h"
-typedef boost::function<void (S32 x, S32 y, const LLUUID& uuid)> startdrag_callback_t;
-typedef boost::function<BOOL (S32 x, S32 y, const LLUUID& uuid, LLAssetType::EType type)> handledrag_callback_t;
-typedef boost::function<BOOL (EDragAndDropType type, void* data, const LLUUID& uuid)> handledrop_callback_t;
+class LLToolBar;
+
+typedef boost::function<void (S32 x, S32 y, const LLUUID& uuid)> tool_startdrag_callback_t;
+typedef boost::function<BOOL (S32 x, S32 y, const LLUUID& uuid, LLAssetType::EType type)> tool_handledrag_callback_t;
+typedef boost::function<BOOL (void* data, S32 x, S32 y, LLToolBar* toolbar)> tool_handledrop_callback_t;
class LLToolBarButton : public LLButton
{
@@ -45,7 +47,7 @@ class LLToolBarButton : public LLButton
public:
struct Params : public LLInitParam::Block<Params, LLButton::Params>
{
- Optional<LLUI::Range<S32> > button_width;
+ Optional<LLUI::RangeS32> button_width;
Optional<S32> desired_height;
Params()
@@ -61,18 +63,17 @@ public:
BOOL handleHover(S32 x, S32 y, MASK mask);
void setCommandId(const LLCommandId& id) { mId = id; }
- void setStartDragCallback(startdrag_callback_t cb) { mStartDragItemCallback = cb; }
- void setHandleDragCallback(handledrag_callback_t cb) { mHandleDragItemCallback = cb; }
+ void setStartDragCallback(tool_startdrag_callback_t cb) { mStartDragItemCallback = cb; }
+ void setHandleDragCallback(tool_handledrag_callback_t cb) { mHandleDragItemCallback = cb; }
private:
LLCommandId mId;
S32 mMouseDownX;
S32 mMouseDownY;
- LLUI::Range<S32> mWidthRange;
+ LLUI::RangeS32 mWidthRange;
S32 mDesiredHeight;
- bool mIsDragged;
- startdrag_callback_t mStartDragItemCallback;
- handledrag_callback_t mHandleDragItemCallback;
- LLUUID mUUID;
+ bool mIsDragged;
+ tool_startdrag_callback_t mStartDragItemCallback;
+ tool_handledrag_callback_t mHandleDragItemCallback;
};
@@ -143,19 +144,21 @@ public:
// virtuals
void draw();
void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
+ int getRankFromPosition(S32 x, S32 y);
BOOL handleRightMouseDown(S32 x, S32 y, MASK mask);
virtual BOOL handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
EDragAndDropType cargo_type,
void* cargo_data,
EAcceptance* accept,
std::string& tooltip_msg);
-
- bool addCommand(const LLCommandId& commandId);
+
+ bool addCommand(const LLCommandId& commandId, int rank = -1);
+ bool removeCommand(const LLCommandId& commandId);
bool hasCommand(const LLCommandId& commandId) const;
bool enableCommand(const LLCommandId& commandId, bool enabled);
- void setStartDragCallback(startdrag_callback_t cb) { mStartDragItemCallback = cb; }
- void setHandleDragCallback(handledrag_callback_t cb) { mHandleDragItemCallback = cb; }
- void setHandleDropCallback(handledrop_callback_t cb) { mHandleDropCallback = cb; }
+ void setStartDragCallback(tool_startdrag_callback_t cb) { mStartDragItemCallback = cb; }
+ void setHandleDragCallback(tool_handledrag_callback_t cb) { mHandleDragItemCallback = cb; }
+ void setHandleDropCallback(tool_handledrop_callback_t cb) { mHandleDropCallback = cb; }
LLToolBarButton* createButton(const LLCommandId& id);
@@ -165,10 +168,10 @@ protected:
~LLToolBar();
void initFromParams(const Params&);
- startdrag_callback_t mStartDragItemCallback;
- handledrag_callback_t mHandleDragItemCallback;
- handledrop_callback_t mHandleDropCallback;
- bool mDragAndDropTarget;
+ tool_startdrag_callback_t mStartDragItemCallback;
+ tool_handledrag_callback_t mHandleDragItemCallback;
+ tool_handledrop_callback_t mHandleDropCallback;
+ bool mDragAndDropTarget;
public:
// Methods used in loading and saving toolbar settings
@@ -185,7 +188,6 @@ private:
BOOL isSettingChecked(const LLSD& userdata);
void onSettingEnable(const LLSD& userdata);
- LLUUID mUUID;
const bool mReadOnly;
std::list<LLToolBarButton*> mButtons;
diff --git a/indra/llui/llui.h b/indra/llui/llui.h
index 8cec1a16f4..28e84fa444 100644
--- a/indra/llui/llui.h
+++ b/indra/llui/llui.h
@@ -41,6 +41,7 @@
#include <boost/signals2.hpp>
#include "lllazyvalue.h"
#include "llframetimer.h"
+#include <limits>
// LLUIFactory
#include "llsd.h"
@@ -151,47 +152,42 @@ public:
// Classes
//
- template <typename T>
- struct Range
+ struct RangeS32
{
- typedef Range<T> self_t;
-
struct Params : public LLInitParam::Block<Params>
{
- typename Optional<T> minimum,
- maximum;
+ Optional<S32> minimum,
+ maximum;
Params()
: minimum("min", 0),
maximum("max", S32_MAX)
- {
-
- }
+ {}
};
// correct for inverted params
- Range(const Params& p = Params())
- : mMin(p.minimum),
+ RangeS32(const Params& p = Params())
+ : mMin(p.minimum),
mMax(p.maximum)
{
sanitizeRange();
}
- Range(T minimum, T maximum)
- : mMin(minimum),
+ RangeS32(S32 minimum, S32 maximum)
+ : mMin(minimum),
mMax(maximum)
{
sanitizeRange();
}
- S32 clamp(T input)
+ S32 clamp(S32 input)
{
if (input < mMin) return mMin;
if (input > mMax) return mMax;
return input;
}
- void setRange(T minimum, T maximum)
+ void setRange(S32 minimum, S32 maximum)
{
mMin = minimum;
mMax = maximum;
@@ -201,7 +197,7 @@ public:
S32 getMin() { return mMin; }
S32 getMax() { return mMax; }
- bool operator==(const self_t& other) const
+ bool operator==(const RangeS32& other) const
{
return mMin == other.mMin
&& mMax == other.mMax;
@@ -219,16 +215,13 @@ public:
}
- T mMin,
+ S32 mMin,
mMax;
};
- template<typename T>
- struct ClampedValue : public Range<T>
+ struct ClampedS32 : public RangeS32
{
- typedef Range<T> range_t;
-
- struct Params : public LLInitParam::Block<Params, typename range_t::Params>
+ struct Params : public LLInitParam::Block<Params, RangeS32::Params>
{
Mandatory<S32> value;
@@ -239,40 +232,38 @@ public:
}
};
- ClampedValue(const Params& p)
- : range_t(p)
+ ClampedS32(const Params& p)
+ : RangeS32(p)
{}
- ClampedValue(const range_t& range)
- : range_t(range)
+ ClampedS32(const RangeS32& range)
+ : RangeS32(range)
{
// set value here, after range has been sanitized
mValue = clamp(0);
}
- ClampedValue(T value, const range_t& range = range_t())
- : range_t(range)
+ ClampedS32(S32 value, const RangeS32& range = RangeS32())
+ : RangeS32(range)
{
mValue = clamp(value);
}
- T get()
+ S32 get()
{
return mValue;
}
- void set(T value)
+ void set(S32 value)
{
mValue = clamp(value);
}
private:
- T mValue;
+ S32 mValue;
};
- typedef ClampedValue<S32> ClampedS32;
-
//
// Methods
//