diff options
author | Leyla Farazha <leyla@lindenlab.com> | 2011-09-23 16:39:09 -0700 |
---|---|---|
committer | Leyla Farazha <leyla@lindenlab.com> | 2011-09-23 16:39:09 -0700 |
commit | 80bb16b36a3bf43514ee0f918dd6d97cbbc1e49f (patch) | |
tree | f05d780fb077be7460bd6a38c90fcd900fbf6974 /indra/llui | |
parent | 74d9663ff6444899bd5eedd29da197746a3ae226 (diff) | |
parent | e42a9ec70c0e5fc98282c98358039445d0d68b84 (diff) |
merge
Diffstat (limited to 'indra/llui')
-rw-r--r-- | indra/llui/CMakeLists.txt | 4 | ||||
-rw-r--r-- | indra/llui/llbutton.cpp | 4 | ||||
-rw-r--r-- | indra/llui/llbutton.h | 21 | ||||
-rw-r--r-- | indra/llui/llcommandmanager.cpp | 146 | ||||
-rw-r--r-- | indra/llui/llcommandmanager.h | 103 | ||||
-rw-r--r-- | indra/llui/llfloaterreg.cpp | 11 | ||||
-rw-r--r-- | indra/llui/llfloaterreg.h | 1 | ||||
-rw-r--r-- | indra/llui/lllayoutstack.cpp | 14 | ||||
-rw-r--r-- | indra/llui/lllayoutstack.h | 26 | ||||
-rw-r--r-- | indra/llui/llnotifications.cpp | 1 | ||||
-rw-r--r-- | indra/llui/llnotificationtemplate.h | 4 | ||||
-rw-r--r-- | indra/llui/llscrollcontainer.cpp | 9 | ||||
-rw-r--r-- | indra/llui/llscrollcontainer.h | 1 | ||||
-rw-r--r-- | indra/llui/llsdparam.cpp | 2 | ||||
-rw-r--r-- | indra/llui/lltoolbar.cpp | 311 | ||||
-rw-r--r-- | indra/llui/lltoolbar.h | 92 | ||||
-rw-r--r-- | indra/llui/lltoolbarview.cpp | 93 | ||||
-rw-r--r-- | indra/llui/lltoolbarview.h | 56 | ||||
-rw-r--r-- | indra/llui/llui.cpp | 6 | ||||
-rw-r--r-- | indra/llui/lluictrlfactory.h | 10 |
20 files changed, 849 insertions, 66 deletions
diff --git a/indra/llui/CMakeLists.txt b/indra/llui/CMakeLists.txt index cf3f9b1a7b..4212812558 100644 --- a/indra/llui/CMakeLists.txt +++ b/indra/llui/CMakeLists.txt @@ -35,6 +35,7 @@ set(llui_SOURCE_FILES llcheckboxctrl.cpp llclipboard.cpp llcombobox.cpp + llcommandmanager.cpp llconsole.cpp llcontainerview.cpp llctrlselectioninterface.cpp @@ -100,6 +101,7 @@ set(llui_SOURCE_FILES lltransutil.cpp lltoggleablemenu.cpp lltoolbar.cpp + lltoolbarview.cpp lltooltip.cpp llui.cpp lluicolortable.cpp @@ -132,6 +134,7 @@ set(llui_HEADER_FILES llcheckboxctrl.h llclipboard.h llcombobox.h + llcommandmanager.h llconsole.h llcontainerview.h llctrlselectioninterface.h @@ -202,6 +205,7 @@ set(llui_HEADER_FILES lltimectrl.h lltoggleablemenu.h lltoolbar.h + lltoolbarview.h lltooltip.h lltransutil.h lluicolortable.h diff --git a/indra/llui/llbutton.cpp b/indra/llui/llbutton.cpp index 2459429f6e..6c08ec7431 100644 --- a/indra/llui/llbutton.cpp +++ b/indra/llui/llbutton.cpp @@ -314,7 +314,7 @@ boost::signals2::connection LLButton::setHeldDownCallback( const commit_signal_t } -// *TODO: Deprecate (for backwards compatability only) +// *TODO: Deprecate (for backwards compatibility only) boost::signals2::connection LLButton::setClickedCallback( button_callback_t cb, void* data ) { return setClickedCallback(boost::bind(cb, data)); @@ -919,7 +919,7 @@ void LLButton::setToggleState(BOOL b) void LLButton::setFlashing( BOOL b ) { - if (b != mFlashing) + if ((bool)b != mFlashing) { mFlashing = b; mFlashingTimer.reset(); diff --git a/indra/llui/llbutton.h b/indra/llui/llbutton.h index 5968916006..bc5e69fad5 100644 --- a/indra/llui/llbutton.h +++ b/indra/llui/llbutton.h @@ -327,15 +327,14 @@ private: LLUIColor mImageColor; LLUIColor mDisabledImageColor; - BOOL mIsToggle; - BOOL mScaleImage; + bool mIsToggle; + bool mScaleImage; - BOOL mDropShadowedText; - BOOL mAutoResize; - BOOL mUseEllipses; - BOOL mBorderEnabled; - - BOOL mFlashing; + bool mDropShadowedText; + bool mAutoResize; + bool mUseEllipses; + bool mBorderEnabled; + bool mFlashing; LLFontGL::HAlign mHAlign; S32 mLeftHPad; @@ -355,9 +354,9 @@ private: F32 mHoverGlowStrength; F32 mCurGlowStrength; - BOOL mNeedsHighlight; - BOOL mCommitOnReturn; - BOOL mFadeWhenDisabled; + bool mNeedsHighlight; + bool mCommitOnReturn; + bool mFadeWhenDisabled; bool mForcePressedState; LLFrameTimer mFlashingTimer; diff --git a/indra/llui/llcommandmanager.cpp b/indra/llui/llcommandmanager.cpp new file mode 100644 index 0000000000..6be616b980 --- /dev/null +++ b/indra/llui/llcommandmanager.cpp @@ -0,0 +1,146 @@ +/** + * @file llcommandmanager.cpp + * @brief LLCommandManager class + * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +// A control that displays the name of the chosen item, which when +// clicked shows a scrolling box of options. + +#include "linden_common.h" + +#include "llcommandmanager.h" +#include "lldir.h" +#include "llerror.h" +#include "llxuiparser.h" + +#include <boost/foreach.hpp> + + +// +// LLCommand class +// + +LLCommand::Params::Params() + : function("function") + , icon("icon") + , label_ref("label_ref") + , name("name") + , param("param") + , tooltip_ref("tooltip_ref") +{ +} + +LLCommand::LLCommand(const LLCommand::Params& p) + : mFunction(p.function) + , mIcon(p.icon) + , mLabelRef(p.label_ref) + , mName(p.name) + , mParam(p.param) + , mTooltipRef(p.tooltip_ref) +{ +} + + +// +// LLCommandManager class +// + +LLCommandManager::LLCommandManager() +{ +} + +LLCommandManager::~LLCommandManager() +{ + for (CommandVector::iterator cmdIt = mCommands.begin(); cmdIt != mCommands.end(); ++cmdIt) + { + LLCommand * command = *cmdIt; + + delete command; + } +} + +U32 LLCommandManager::commandCount() const +{ + return mCommands.size(); +} + +LLCommand * LLCommandManager::getCommand(U32 commandIndex) +{ + return mCommands[commandIndex]; +} + +LLCommand * LLCommandManager::getCommand(const std::string& commandName) +{ + LLCommand * command_name_match = NULL; + + CommandIndexMap::const_iterator found = mCommandIndices.find(commandName); + + if (found != mCommandIndices.end()) + { + command_name_match = mCommands[found->second]; + } + + return command_name_match; +} + +void LLCommandManager::addCommand(LLCommand * command) +{ + mCommandIndices[command->name()] = mCommands.size(); + mCommands.push_back(command); + + llinfos << "Successfully added command: " << command->name() << llendl; +} + +//static +bool LLCommandManager::load() +{ + LLCommandManager& mgr = LLCommandManager::instance(); + + std::string commands_file = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "commands.xml"); + + LLCommandManager::Params commandsParams; + + LLSimpleXUIParser parser; + + if (!parser.readXUI(commands_file, commandsParams)) + { + llerrs << "Unable to load xml file: " << commands_file << llendl; + return false; + } + + if (!commandsParams.validateBlock()) + { + llerrs << "Unable to validate commands param block from file: " << commands_file << llendl; + return false; + } + + BOOST_FOREACH(LLCommand::Params& commandParams, commandsParams.commands) + { + LLCommand * command = new LLCommand(commandParams); + + mgr.addCommand(command); + } + + return true; +} diff --git a/indra/llui/llcommandmanager.h b/indra/llui/llcommandmanager.h new file mode 100644 index 0000000000..24378ecd62 --- /dev/null +++ b/indra/llui/llcommandmanager.h @@ -0,0 +1,103 @@ +/** + * @file llcommandmanager.h + * @brief LLCommandManager class to hold commands + * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_LLCOMMANDMANAGER_H +#define LL_LLCOMMANDMANAGER_H + +#include "llinitparam.h" +#include "llsingleton.h" + + +class LLCommand +{ +public: + struct Params : public LLInitParam::Block<Params> + { + Mandatory<std::string> function; + Mandatory<std::string> icon; + Mandatory<std::string> label_ref; + Mandatory<std::string> name; + Optional<std::string> param; + Mandatory<std::string> tooltip_ref; + + Params(); + }; + + LLCommand(const LLCommand::Params& p); + + const std::string& functionName() const { return mFunction; } + const std::string& icon() const { return mIcon; } + const std::string& labelRef() const { return mLabelRef; } + const std::string& name() const { return mName; } + const std::string& param() const { return mParam; } + const std::string& tooltipRef() const { return mTooltipRef; } + +private: + std::string mFunction; + std::string mIcon; + std::string mLabelRef; + std::string mName; + std::string mParam; + std::string mTooltipRef; +}; + + +class LLCommandManager +: public LLSingleton<LLCommandManager> +{ +public: + struct Params : public LLInitParam::Block<Params> + { + Multiple< LLCommand::Params, AtLeast<1> > commands; + + Params() + : commands("command") + { + } + }; + + LLCommandManager(); + ~LLCommandManager(); + + U32 commandCount() const; + LLCommand * getCommand(U32 commandIndex); + LLCommand * getCommand(const std::string& commandName); + + static bool load(); + +protected: + void addCommand(LLCommand * command); + +private: + typedef std::map<std::string, U32> CommandIndexMap; + typedef std::vector<LLCommand *> CommandVector; + + CommandVector mCommands; + CommandIndexMap mCommandIndices; +}; + + +#endif // LL_LLCOMMANDMANAGER_H diff --git a/indra/llui/llfloaterreg.cpp b/indra/llui/llfloaterreg.cpp index fc7dcfcc4e..bc740dde17 100644 --- a/indra/llui/llfloaterreg.cpp +++ b/indra/llui/llfloaterreg.cpp @@ -453,6 +453,17 @@ void LLFloaterReg::toggleFloaterInstance(const LLSD& sdname) } //static +void LLFloaterReg::toggleToolbarFloaterInstance(const LLSD& sdname) +{ + // Do some extra logic here for 3-state toolbar floater toggling madness :) + + LLSD key; + std::string name = sdname.asString(); + parse_name_key(name, key); + toggleInstance(name, key); +} + +//static bool LLFloaterReg::floaterInstanceVisible(const LLSD& sdname) { LLSD key; diff --git a/indra/llui/llfloaterreg.h b/indra/llui/llfloaterreg.h index a2027a77a0..6239d98a7d 100644 --- a/indra/llui/llfloaterreg.h +++ b/indra/llui/llfloaterreg.h @@ -127,6 +127,7 @@ public: static void showFloaterInstance(const LLSD& sdname); static void hideFloaterInstance(const LLSD& sdname); static void toggleFloaterInstance(const LLSD& sdname); + static void toggleToolbarFloaterInstance(const LLSD& sdname); static bool floaterInstanceVisible(const LLSD& sdname); static bool floaterInstanceMinimized(const LLSD& sdname); diff --git a/indra/llui/lllayoutstack.cpp b/indra/llui/lllayoutstack.cpp index a250404292..0d1f608e61 100644 --- a/indra/llui/lllayoutstack.cpp +++ b/indra/llui/lllayoutstack.cpp @@ -55,6 +55,7 @@ LLLayoutPanel::LLLayoutPanel(const Params& p) mMaxDim(p.max_dim), mAutoResize(p.auto_resize), mUserResize(p.user_resize), + mFitContent(p.fit_content), mCollapsed(FALSE), mCollapseAmt(0.f), mVisibleAmt(1.f), // default to fully visible @@ -104,6 +105,14 @@ F32 LLLayoutPanel::getCollapseFactor(LLLayoutStack::ELayoutOrientation orientati } } +void LLLayoutPanel::fitToContent() +{ + if (mFitContent) + { + setShape(calcBoundingRect()); + } +} + // // LLLayoutStack // @@ -324,6 +333,7 @@ void LLLayoutStack::updateLayout(BOOL force_resize) for (panel_it = mPanels.begin(); panel_it != mPanels.end(); ++panel_it) { LLLayoutPanel* panelp = (*panel_it); + panelp->fitToContent(); if (panelp->getVisible()) { if (mAnimate) @@ -478,7 +488,9 @@ void LLLayoutStack::updateLayout(BOOL force_resize) { // shrink proportionally to amount over minimum // so we can do this in one pass - delta_size = (shrink_headroom_available > 0) ? llround((F32)pixels_to_distribute * ((F32)(cur_width - relevant_min) / (F32)shrink_headroom_available)) : 0; + delta_size = (shrink_headroom_available > 0) + ? llround((F32)pixels_to_distribute * ((F32)(cur_width - relevant_min) / (F32)shrink_headroom_available)) + : 0; shrink_headroom_available -= (cur_width - relevant_min); } else diff --git a/indra/llui/lllayoutstack.h b/indra/llui/lllayoutstack.h index d8ef0aeaca..2ed32a2fa9 100644 --- a/indra/llui/lllayoutstack.h +++ b/indra/llui/lllayoutstack.h @@ -161,14 +161,16 @@ public: min_dim, max_dim; Optional<bool> user_resize, - auto_resize; + auto_resize, + fit_content; Params() : expanded_min_dim("expanded_min_dim", 0), min_dim("min_dim", 0), max_dim("max_dim", 0), user_resize("user_resize", true), - auto_resize("auto_resize", true) + auto_resize("auto_resize", true), + fit_content("fit_content", false) { addSynonym(min_dim, "min_width"); addSynonym(min_dim, "min_height"); @@ -206,18 +208,20 @@ protected: LLLayoutPanel(const Params& p); F32 getCollapseFactor(LLLayoutStack::ELayoutOrientation orientation); + void fitToContent(); - bool mExpandedMinDimSpecified; - S32 mExpandedMinDim; + bool mExpandedMinDimSpecified; + S32 mExpandedMinDim; - S32 mMinDim; - S32 mMaxDim; - BOOL mAutoResize; - BOOL mUserResize; - BOOL mCollapsed; + S32 mMinDim; + S32 mMaxDim; + bool mAutoResize; + bool mUserResize; + bool mCollapsed; + bool mFitContent; + F32 mVisibleAmt; + F32 mCollapseAmt; class LLResizeBar* mResizeBar; - F32 mVisibleAmt; - F32 mCollapseAmt; }; diff --git a/indra/llui/llnotifications.cpp b/indra/llui/llnotifications.cpp index 6085c61f9a..ffe5908a9d 100644 --- a/indra/llui/llnotifications.cpp +++ b/indra/llui/llnotifications.cpp @@ -245,7 +245,6 @@ LLNotificationForm::LLNotificationForm(const std::string& name, const LLNotifica LLParamSDParser parser; parser.writeSD(mFormData, p.form_elements); - mFormData = mFormData[""]; if (!mFormData.isArray()) { // change existing contents to a one element array diff --git a/indra/llui/llnotificationtemplate.h b/indra/llui/llnotificationtemplate.h index eff572b553..ab777d37a5 100644 --- a/indra/llui/llnotificationtemplate.h +++ b/indra/llui/llnotificationtemplate.h @@ -88,10 +88,10 @@ struct LLNotificationTemplate { private: // this idiom allows - // <notification unique="true"> + // <notification> <unique/> </notification> // as well as // <notification> <unique> <context></context> </unique>... - Optional<bool> dummy_val; + Flag dummy_val; public: Multiple<UniquenessContext> contexts; diff --git a/indra/llui/llscrollcontainer.cpp b/indra/llui/llscrollcontainer.cpp index b44b4c36b6..fe3f688fc5 100644 --- a/indra/llui/llscrollcontainer.cpp +++ b/indra/llui/llscrollcontainer.cpp @@ -223,6 +223,15 @@ BOOL LLScrollContainer::handleKeyHere(KEY key, MASK mask) return FALSE; } +BOOL LLScrollContainer::handleUnicodeCharHere(llwchar uni_char) +{ + if (mScrolledView && mScrolledView->handleUnicodeCharHere(uni_char)) + { + return TRUE; + } + return FALSE; +} + BOOL LLScrollContainer::handleScrollWheel( S32 x, S32 y, S32 clicks ) { // Give event to my child views - they may have scroll bars diff --git a/indra/llui/llscrollcontainer.h b/indra/llui/llscrollcontainer.h index 46a71a7e30..3aa79cc255 100644 --- a/indra/llui/llscrollcontainer.h +++ b/indra/llui/llscrollcontainer.h @@ -103,6 +103,7 @@ public: // LLView functionality virtual void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE); virtual BOOL handleKeyHere(KEY key, MASK mask); + virtual BOOL handleUnicodeCharHere(llwchar uni_char); virtual BOOL handleScrollWheel( S32 x, S32 y, S32 clicks ); virtual BOOL handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop, EDragAndDropType cargo_type, diff --git a/indra/llui/llsdparam.cpp b/indra/llui/llsdparam.cpp index 9ad13054cb..04919e6991 100644 --- a/indra/llui/llsdparam.cpp +++ b/indra/llui/llsdparam.cpp @@ -183,7 +183,7 @@ LLSD* LLParamSDParser::getSDWriteNode(const parser_t::name_stack_t& name_stack) } } - LLSD* child_sd = &(*sd_to_write)[it->first]; + LLSD* child_sd = it->first.empty() ? sd_to_write : &(*sd_to_write)[it->first]; if (child_sd->isArray()) { diff --git a/indra/llui/lltoolbar.cpp b/indra/llui/lltoolbar.cpp index 0356fd5c8a..e052c1c876 100644 --- a/indra/llui/lltoolbar.cpp +++ b/indra/llui/lltoolbar.cpp @@ -27,51 +27,308 @@ #include "linden_common.h" -#include "boost/foreach.hpp" +#include <boost/foreach.hpp> #include "lltoolbar.h" -//static LLDefaultChildRegistry::Register<LLToolBar> r1("toolbar"); +#include "llcommandmanager.h" +#include "lltrans.h" + +static LLDefaultChildRegistry::Register<LLToolBar> r1("toolbar"); + +namespace LLToolBarEnums +{ + LLLayoutStack::ELayoutOrientation getOrientation(SideType sideType) + { + LLLayoutStack::ELayoutOrientation orientation = LLLayoutStack::HORIZONTAL; + + if ((sideType == SIDE_LEFT) || (sideType == SIDE_RIGHT)) + { + orientation = LLLayoutStack::VERTICAL; + } + + return orientation; + } +} +using namespace LLToolBarEnums; LLToolBar::Params::Params() -: orientation("orientation"), - buttons("button") +: button_display_mode("button_display_mode"), + buttons("button"), + side("side"), + button_icon("button_icon"), + button_icon_and_text("button_icon_and_text"), + wrap("wrap", true), + min_button_width("min_button_width", 0), + max_button_width("max_button_width", S32_MAX), + background_image("background_image") {} -LLToolBar::LLToolBar(const Params& p) +LLToolBar::LLToolBar(const LLToolBar::Params& p) : LLUICtrl(p), - mOrientation(p.orientation), - mStack(NULL) + mButtonType(p.button_display_mode), + mSideType(p.side), + mWrap(p.wrap), + mNeedsLayout(false), + mCenterPanel(NULL), + mCenteringStack(NULL), + mMinButtonWidth(p.min_button_width), + mMaxButtonWidth(p.max_button_width), + mBackgroundImage(p.background_image) +{ + mButtonParams[LLToolBarEnums::BTNTYPE_ICONS_ONLY] = p.button_icon; + mButtonParams[LLToolBarEnums::BTNTYPE_ICONS_WITH_TEXT] = p.button_icon_and_text; +} + +void LLToolBar::initFromParams(const LLToolBar::Params& p) { + // Initialize the base object + LLUICtrl::initFromParams(p); + + LLLayoutStack::ELayoutOrientation orientation = getOrientation(p.side); + + LLLayoutStack::Params centering_stack_p; + centering_stack_p.name = "centering_stack"; + centering_stack_p.rect = getLocalRect(); + centering_stack_p.follows.flags = FOLLOWS_ALL; + centering_stack_p.orientation = orientation; + + mCenteringStack = LLUICtrlFactory::create<LLLayoutStack>(centering_stack_p); + addChild(mCenteringStack); + + LLLayoutPanel::Params border_panel_p; + border_panel_p.name = "border_panel"; + border_panel_p.rect = getLocalRect(); + border_panel_p.auto_resize = true; + border_panel_p.user_resize = false; + + mCenteringStack->addChild(LLUICtrlFactory::create<LLLayoutPanel>(border_panel_p)); + + LLLayoutPanel::Params center_panel_p; + center_panel_p.name = "center_panel"; + center_panel_p.rect = getLocalRect(); + center_panel_p.auto_resize = false; + center_panel_p.user_resize = false; + center_panel_p.fit_content = true; + mCenterPanel = LLUICtrlFactory::create<LLLayoutPanel>(center_panel_p); + mCenteringStack->addChild(mCenterPanel); + + mCenteringStack->addChild(LLUICtrlFactory::create<LLLayoutPanel>(border_panel_p)); + + BOOST_FOREACH (LLToolBarButton::Params button_p, p.buttons) + { + // buttons always follow left and top, for all orientations + button_p.follows.flags = FOLLOWS_LEFT|FOLLOWS_TOP; + button_p.fillFrom(mButtonParams[mButtonType]); + + LLRect button_rect(button_p.rect); + { // remove any offset from button + if (orientation == LLLayoutStack::HORIZONTAL) + { + button_rect.setOriginAndSize(0, 0, mMinButtonWidth, button_rect.getHeight()); + } + else // VERTICAL + { + button_rect.setOriginAndSize(0, 0, mMinButtonWidth, button_rect.getHeight()); + } + } + // use our calculated rect + button_p.rect = button_rect; + LLToolBarButton* buttonp = LLUICtrlFactory::create<LLToolBarButton>(button_p); + + mButtons.push_back(buttonp); + mCenterPanel->addChild(buttonp); + + mNeedsLayout = true; + } } +bool LLToolBar::addCommand(LLCommand * command) +{ + // + // Init basic toolbar button params + // + + LLToolBarButton::Params button_p; + button_p.fillFrom(mButtonParams[mButtonType]); + + button_p.name = command->name(); + button_p.label = LLTrans::getString(command->labelRef()); + button_p.tool_tip = LLTrans::getString(command->tooltipRef()); + + // + // Set up the button rectangle + // + + S32 btn_width = mMinButtonWidth; + S32 btn_height = mButtonParams[mButtonType].rect.height; + + if ((mSideType == LLToolBarEnums::SIDE_BOTTOM) || (mSideType == LLToolBarEnums::SIDE_TOP)) + { + btn_height = getRect().getHeight(); + } + + LLRect button_rect; + button_rect.setOriginAndSize(0, 0, btn_width, btn_height); + + button_p.rect = button_rect; + + // + // Add it to the list of buttons + // + + LLToolBarButton * toolbar_button = LLUICtrlFactory::create<LLToolBarButton>(button_p); + + toolbar_button->reshape(llclamp(toolbar_button->getRect().getWidth(), mMinButtonWidth, mMaxButtonWidth), toolbar_button->getRect().getHeight()); + + mButtons.push_back(toolbar_button); + mCenterPanel->addChild(toolbar_button); + + mNeedsLayout = true; + + return true; +} + +void LLToolBar::updateLayoutAsNeeded() +{ + if (!mNeedsLayout) return; + + LLLayoutStack::ELayoutOrientation orientation = getOrientation(mSideType); + + // our terminology for orientation-agnostic layout is that + // length refers to a distance in the direction we stack the buttons + // and girth refers to a distance in the direction buttons wrap + S32 row_running_length = 0; + S32 max_length = (orientation == LLLayoutStack::HORIZONTAL) + ? getRect().getWidth() + : getRect().getHeight(); + S32 max_row_girth = 0; + S32 cur_start = 0; + S32 cur_row = 0; + + LLRect panel_rect = mCenterPanel->getLocalRect(); + + std::vector<LLToolBarButton*> buttons_in_row; + + BOOST_FOREACH(LLToolBarButton* button, mButtons) + { + S32 button_clamped_width = llclamp(button->getRect().getWidth(), mMinButtonWidth, mMaxButtonWidth); + S32 button_length = (orientation == LLLayoutStack::HORIZONTAL) + ? button_clamped_width + : button->getRect().getHeight(); + S32 button_girth = (orientation == LLLayoutStack::HORIZONTAL) + ? button->getRect().getHeight() + : button_clamped_width; + + // handle wrapping + if (row_running_length + button_length > max_length + && cur_start != 0) // not first button in row + { // go ahead and wrap + if (orientation == LLLayoutStack::VERTICAL) + { + // row girth is clamped to allowable button widths + max_row_girth = llclamp(max_row_girth, mMinButtonWidth, mMaxButtonWidth); + } + // make buttons in current row all same girth + BOOST_FOREACH(LLToolBarButton* button, buttons_in_row) + { + if (orientation == LLLayoutStack::HORIZONTAL) + { + button->reshape(llclamp(button->getRect().getWidth(), mMinButtonWidth, mMaxButtonWidth), max_row_girth); + } + else // VERTICAL + { + button->reshape(max_row_girth, button->getRect().getHeight()); + } + } + buttons_in_row.clear(); + + row_running_length = 0; + cur_start = 0; + cur_row += max_row_girth; + max_row_girth = 0; + } + + LLRect button_rect; + if (orientation == LLLayoutStack::HORIZONTAL) + { + button_rect.setLeftTopAndSize(cur_start, panel_rect.mTop - cur_row, button_clamped_width, button->getRect().getHeight()); + } + else // VERTICAL + { + button_rect.setLeftTopAndSize(cur_row, panel_rect.mTop - cur_start, button_clamped_width, button->getRect().getHeight()); + } + button->setShape(button_rect); + + buttons_in_row.push_back(button); + + row_running_length += button_length; + cur_start = row_running_length; + max_row_girth = llmax(button_girth, max_row_girth); + } + + // final resizing in "girth" direction + S32 total_girth = cur_row + max_row_girth; // increment by size of final row + + // grow and optionally shift toolbar to accomodate buttons + if (orientation == LLLayoutStack::HORIZONTAL) + { + if (mSideType == SIDE_TOP) + { // shift down to maintain top edge + translate(0, getRect().getHeight() - total_girth); + } + + reshape(getRect().getWidth(), total_girth); + } + else // VERTICAL + { + if (mSideType == SIDE_RIGHT) + { // shift left to maintain right edge + translate(getRect().getWidth() - total_girth, 0); + } + reshape(total_girth, getRect().getHeight()); + } + + // recenter toolbar buttons + mCenteringStack->updateLayout(); + + // don't clear flag until after we've resized ourselves, to avoid laying out every frame + mNeedsLayout = false; +} + + void LLToolBar::draw() { - gl_rect_2d(getLocalRect(), LLColor4::blue, TRUE); + updateLayoutAsNeeded(); + + { // draw background + LLRect bg_rect; + localRectToOtherView(mCenterPanel->getRect(),&bg_rect, this); + mBackgroundImage->draw(bg_rect); + } + LLUICtrl::draw(); } -void LLToolBar::initFromParams(const LLToolBar::Params& p) +void LLToolBar::reshape(S32 width, S32 height, BOOL called_from_parent) { - LLLayoutStack::Params stack_p; - stack_p.rect = getLocalRect(); - stack_p.follows.flags = FOLLOWS_ALL; - stack_p.name = "button_stack"; - stack_p.orientation = p.orientation; + LLUICtrl::reshape(width, height, called_from_parent); + mNeedsLayout = true; +} - mStack = LLUICtrlFactory::create<LLLayoutStack>(stack_p); - addChild(mStack); +namespace LLInitParam +{ + void TypeValues<ButtonType>::declareValues() + { + declare("icons_only", BTNTYPE_ICONS_ONLY); + declare("icons_with_text", BTNTYPE_ICONS_WITH_TEXT); + } - BOOST_FOREACH (LLButton::Params button_p, p.buttons) + void TypeValues<SideType>::declareValues() { - LLLayoutPanel::Params panel_p; - panel_p.name = button_p.name() + "_panel"; - panel_p.rect = button_p.rect; - panel_p.user_resize = false; - panel_p.auto_resize= false; - - LLLayoutPanel* panel = LLUICtrlFactory::create<LLLayoutPanel>(panel_p); - LLButton* button = LLUICtrlFactory::create<LLButton>(button_p); - panel->addChild(button); - mStack->addChild(panel); + declare("none", SIDE_NONE); + declare("bottom", SIDE_BOTTOM); + declare("left", SIDE_LEFT); + declare("right", SIDE_RIGHT); + declare("top", SIDE_TOP); } } diff --git a/indra/llui/lltoolbar.h b/indra/llui/lltoolbar.h index dd454e3f0b..85cd6d5170 100644 --- a/indra/llui/lltoolbar.h +++ b/indra/llui/lltoolbar.h @@ -32,28 +32,112 @@ #include "lllayoutstack.h" #include "llbutton.h" + +class LLCommand; + + +class LLToolBarButton : public LLButton +{ +public: + struct Params : public LLInitParam::Block<Params, LLButton::Params> + { + }; + + LLToolBarButton(const Params& p) : LLButton(p) {} +}; + + +namespace LLToolBarEnums +{ + enum ButtonType + { + BTNTYPE_ICONS_ONLY = 0, + BTNTYPE_ICONS_WITH_TEXT, + + BTNTYPE_COUNT + }; + + enum SideType + { + SIDE_NONE = 0, + SIDE_BOTTOM, + SIDE_LEFT, + SIDE_RIGHT, + SIDE_TOP, + }; +} + +// NOTE: This needs to occur before Param block declaration for proper compilation. +namespace LLInitParam +{ + template<> + struct TypeValues<LLToolBarEnums::ButtonType> : public TypeValuesHelper<LLToolBarEnums::ButtonType> + { + static void declareValues(); + }; + + template<> + struct TypeValues<LLToolBarEnums::SideType> : public TypeValuesHelper<LLToolBarEnums::SideType> + { + static void declareValues(); + }; +} + + class LLToolBar : public LLUICtrl { public: + struct Params : public LLInitParam::Block<Params, LLUICtrl::Params> { - Mandatory<LLLayoutStack::ELayoutOrientation> orientation; - Multiple<LLButton::Params> buttons; + Mandatory<LLToolBarEnums::ButtonType> button_display_mode; + Mandatory<LLToolBarEnums::SideType> side; + + Optional<LLToolBarButton::Params> button_icon, + button_icon_and_text; + + Optional<bool> wrap; + Optional<S32> min_button_width, + max_button_width; + // get rid of this + Multiple<LLToolBarButton::Params> buttons; + + Optional<LLUIImage*> background_image; Params(); }; + // virtuals void draw(); + void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE); + + bool addCommand(LLCommand * command); protected: friend class LLUICtrlFactory; LLToolBar(const Params&); + void initFromParams(const Params&); private: - LLLayoutStack::ELayoutOrientation mOrientation; - LLLayoutStack* mStack; + void updateLayoutAsNeeded(); + + std::list<LLToolBarButton*> mButtons; + LLToolBarEnums::ButtonType mButtonType; + LLLayoutStack* mCenteringStack; + LLLayoutStack* mWrapStack; + LLLayoutPanel* mCenterPanel; + LLToolBarEnums::SideType mSideType; + + bool mWrap; + bool mNeedsLayout; + S32 mMinButtonWidth, + mMaxButtonWidth; + + LLUIImagePtr mBackgroundImage; + + LLToolBarButton::Params mButtonParams[LLToolBarEnums::BTNTYPE_COUNT]; }; diff --git a/indra/llui/lltoolbarview.cpp b/indra/llui/lltoolbarview.cpp new file mode 100644 index 0000000000..590cd4ffca --- /dev/null +++ b/indra/llui/lltoolbarview.cpp @@ -0,0 +1,93 @@ +/** + * @file lltoolbarview.cpp + * @author Merov Linden + * @brief User customizable toolbar class + * + * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "linden_common.h" + +#include "lltoolbarview.h" + +#include "lltoolbar.h" +#include "llbutton.h" + +LLToolBarView* gToolBarView = NULL; + +static LLDefaultChildRegistry::Register<LLToolBarView> r("toolbar_view"); + +LLToolBarView::LLToolBarView(const LLToolBarView::Params& p) +: LLUICtrl(p) +{ +} + +void LLToolBarView::initFromParams(const LLToolBarView::Params& p) +{ + // Initialize the base object + LLUICtrl::initFromParams(p); +} + +LLToolBarView::~LLToolBarView() +{ +} + +void LLToolBarView::draw() +{ + static bool debug_print = true; + static S32 old_width = 0; + static S32 old_height = 0; + + LLToolBar* toolbar_bottom = getChild<LLToolBar>("toolbar_bottom"); + LLToolBar* toolbar_left = getChild<LLToolBar>("toolbar_left"); + LLToolBar* toolbar_right = getChild<LLToolBar>("toolbar_right"); + LLPanel* sizer_left = getChild<LLPanel>("sizer_left"); + + LLRect bottom_rect = toolbar_bottom->getRect(); + LLRect left_rect = toolbar_left->getRect(); + LLRect right_rect = toolbar_right->getRect(); + LLRect sizer_left_rect = sizer_left->getRect(); + + if ((old_width != getRect().getWidth()) || (old_height != getRect().getHeight())) + debug_print = true; + if (debug_print) + { + LLRect ctrl_rect = getRect(); + llinfos << "Merov debug : draw control rect = " << ctrl_rect.mLeft << ", " << ctrl_rect.mTop << ", " << ctrl_rect.mRight << ", " << ctrl_rect.mBottom << llendl; + llinfos << "Merov debug : draw bottom rect = " << bottom_rect.mLeft << ", " << bottom_rect.mTop << ", " << bottom_rect.mRight << ", " << bottom_rect.mBottom << llendl; + llinfos << "Merov debug : draw left rect = " << left_rect.mLeft << ", " << left_rect.mTop << ", " << left_rect.mRight << ", " << left_rect.mBottom << llendl; + llinfos << "Merov debug : draw right rect = " << right_rect.mLeft << ", " << right_rect.mTop << ", " << right_rect.mRight << ", " << right_rect.mBottom << llendl; + llinfos << "Merov debug : draw s left rect = " << sizer_left_rect.mLeft << ", " << sizer_left_rect.mTop << ", " << sizer_left_rect.mRight << ", " << sizer_left_rect.mBottom << llendl; + old_width = ctrl_rect.getWidth(); + old_height = ctrl_rect.getHeight(); + debug_print = false; + } + // Debug draw + LLColor4 back_color = LLColor4::blue; + back_color[VALPHA] = 0.5f; +// gl_rect_2d(getLocalRect(), back_color, TRUE); +// gl_rect_2d(bottom_rect, LLColor4::red, TRUE); +// gl_rect_2d(left_rect, LLColor4::green, TRUE); +// gl_rect_2d(right_rect, LLColor4::yellow, TRUE); + + LLUICtrl::draw(); +} diff --git a/indra/llui/lltoolbarview.h b/indra/llui/lltoolbarview.h new file mode 100644 index 0000000000..73278e226b --- /dev/null +++ b/indra/llui/lltoolbarview.h @@ -0,0 +1,56 @@ +/** + * @file lltoolbarview.h + * @author Merov Linden + * @brief User customizable toolbar class + * + * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_LLTOOLBARVIEW_H +#define LL_LLTOOLBARVIEW_H + +#include "lluictrl.h" + +class LLUICtrlFactory; + +// Parent of all LLToolBar + +class LLToolBarView : public LLUICtrl +{ +public: + struct Params : public LLInitParam::Block<Params, LLUICtrl::Params> {}; + virtual ~LLToolBarView(); + virtual void draw(); + +protected: + friend class LLUICtrlFactory; + LLToolBarView(const Params&); + + void initFromParams(const Params&); + +private: + LLHandle<LLView> mSnapView; +}; + +extern LLToolBarView* gToolBarView; + +#endif // LL_LLTOOLBARVIEW_H diff --git a/indra/llui/llui.cpp b/indra/llui/llui.cpp index 593354ee9b..a4303780fd 100644 --- a/indra/llui/llui.cpp +++ b/indra/llui/llui.cpp @@ -41,6 +41,7 @@ #include "llgl.h" // Project includes +#include "llcommandmanager.h" #include "llcontrol.h" #include "llui.h" #include "lluicolortable.h" @@ -92,7 +93,6 @@ std::list<std::string> gUntranslated; static LLDefaultChildRegistry::Register<LLFilterEditor> register_filter_editor("filter_editor"); static LLDefaultChildRegistry::Register<LLFlyoutButton> register_flyout_button("flyout_button"); static LLDefaultChildRegistry::Register<LLSearchEditor> register_search_editor("search_editor"); -static LLDefaultChildRegistry::Register<LLToolBar> r1("toolbar"); // register other widgets which otherwise may not be linked in static LLDefaultChildRegistry::Register<LLLoadingIndicator> register_loading_indicator("loading_indicator"); @@ -1617,6 +1617,7 @@ void LLUI::initClass(const settings_map_t& settings, // Callbacks for associating controls with floater visibilty: reg.add("Floater.Toggle", boost::bind(&LLFloaterReg::toggleFloaterInstance, _2)); + reg.add("Floater.ToolbarToggle", boost::bind(&LLFloaterReg::toggleToolbarFloaterInstance, _2)); reg.add("Floater.Show", boost::bind(&LLFloaterReg::showFloaterInstance, _2)); reg.add("Floater.Hide", boost::bind(&LLFloaterReg::hideFloaterInstance, _2)); reg.add("Floater.InitToVisibilityControl", boost::bind(&LLFloaterReg::initUICtrlToFloaterVisibilityControl, _1, _2)); @@ -1635,6 +1636,9 @@ void LLUI::initClass(const settings_map_t& settings, // Used by menus along with Floater.Toggle to display visibility as a checkmark LLUICtrl::EnableCallbackRegistry::defaultRegistrar().add("Floater.Visible", boost::bind(&LLFloaterReg::floaterInstanceVisible, _2)); + + // Parse the master list of commands + LLCommandManager::load(); } void LLUI::cleanupClass() diff --git a/indra/llui/lluictrlfactory.h b/indra/llui/lluictrlfactory.h index f0ba7fc7d7..71c38237c1 100644 --- a/indra/llui/lluictrlfactory.h +++ b/indra/llui/lluictrlfactory.h @@ -125,12 +125,12 @@ private: // base case for recursion, there are NO base classes of LLInitParam::BaseBlock template<int DUMMY> - class ParamDefaults<LLInitParam::BaseBlock, DUMMY> : public LLSingleton<ParamDefaults<LLInitParam::BaseBlock, DUMMY> > + class ParamDefaults<LLInitParam::BaseBlockWithFlags, DUMMY> : public LLSingleton<ParamDefaults<LLInitParam::BaseBlockWithFlags, DUMMY> > { public: - const LLInitParam::BaseBlock& get() { return mBaseBlock; } + const LLInitParam::BaseBlockWithFlags& get() { return mBaseBlock; } private: - LLInitParam::BaseBlock mBaseBlock; + LLInitParam::BaseBlockWithFlags mBaseBlock; }; public: @@ -172,7 +172,7 @@ public: static T* createFromFile(const std::string &filename, LLView *parent, const widget_registry_t& registry, LLXMLNodePtr output_node = NULL) { T* widget = NULL; - + std::string skinned_filename = findSkinnedFilename(filename); instance().pushFileName(filename); { @@ -201,10 +201,10 @@ public: // not of right type, so delete it if (!widget) { + llwarns << "Widget in " << filename << " was of type " << typeid(view).name() << " instead of expected type " << typeid(T).name() << llendl; delete view; view = NULL; } - } } fail: |