Refactor LLScrollList* and relatives

Breaks out llscrolllistcolumn, llscrolllistcell, and llscrolllistitem from llscrolllistctrl and llflyoutbutton from llcombobox
This commit is contained in:
Lirusaito
2013-07-12 17:47:01 -04:00
parent 1398d8afbc
commit c77f0de9cf
54 changed files with 1974 additions and 1992 deletions

View File

@@ -35,6 +35,7 @@ set(llui_SOURCE_FILES
lleditmenuhandler.cpp
llfiltereditor.cpp
llfloater.cpp
llflyoutbutton.cpp
llfocusmgr.cpp
llfunctorregistry.cpp
lliconctrl.cpp
@@ -59,7 +60,10 @@ set(llui_SOURCE_FILES
llscrollbar.cpp
llscrollcontainer.cpp
llscrollingpanellist.cpp
llscrolllistcell.cpp
llscrolllistcolumn.cpp
llscrolllistctrl.cpp
llscrolllistitem.cpp
llsearcheditor.cpp
llslider.cpp
llsliderctrl.cpp
@@ -105,6 +109,7 @@ set(llui_HEADER_FILES
lleditmenuhandler.h
llfiltereditor.h
llfloater.h
llflyoutbutton.h
llfocusmgr.h
llfunctorregistry.h
llhtmlhelp.h
@@ -134,7 +139,10 @@ set(llui_HEADER_FILES
llscrollbar.h
llscrollcontainer.h
llscrollingpanellist.h
llscrolllistcell.h
llscrolllistcolumn.h
llscrolllistctrl.h
llscrolllistitem.h
llslider.h
llsliderctrl.h
llspinctrl.h

View File

@@ -2,31 +2,25 @@
* @file llcombobox.cpp
* @brief LLComboBox base class
*
* $LicenseInfo:firstyear=2001&license=viewergpl$
*
* Copyright (c) 2001-2009, Linden Research, Inc.
*
* $LicenseInfo:firstyear=2001&license=viewerlgpl$
* Second Life Viewer Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in doc/GPL-license.txt in this distribution, or
* online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
* Copyright (C) 2010, 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.
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or
* online at
* http://secondlifegrid.net/programs/open_source/licensing/flossexception
* 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.
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
* 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
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
@@ -48,6 +42,8 @@
#include "llwindow.h"
#include "llfloater.h"
#include "llscrollbar.h"
#include "llscrolllistcell.h"
#include "llscrolllistitem.h"
#include "llcontrol.h"
#include "llfocusmgr.h"
#include "lllineeditor.h"
@@ -58,10 +54,9 @@ S32 LLCOMBOBOX_HEIGHT = 0;
S32 LLCOMBOBOX_WIDTH = 0;
S32 MAX_COMBO_WIDTH = 500;
static LLRegisterWidget<LLComboBox> r1("combo_box");
static LLRegisterWidget<LLComboBox> register_combo_box("combo_box");
LLComboBox::LLComboBox( const std::string& name, const LLRect &rect, const std::string& label,
commit_callback_t commit_callback)
LLComboBox::LLComboBox(const std::string& name, const LLRect& rect, const std::string& label, commit_callback_t commit_callback)
: LLUICtrl(name, rect, TRUE, commit_callback, FOLLOWS_LEFT | FOLLOWS_TOP),
mTextEntry(NULL),
mTextEntryTentative(TRUE),
@@ -81,9 +76,7 @@ LLComboBox::LLComboBox( const std::string& name, const LLRect &rect, const std::
{
// Always use text box
// Text label button
mButton = new LLButton(mLabel,
LLRect(),
LLStringUtil::null);
mButton = new LLButton(mLabel, LLRect(), LLStringUtil::null);
mButton->setImageUnselected(LLUI::getUIImage("square_btn_32x128.tga"));
mButton->setImageSelected(LLUI::getUIImage("square_btn_selected_32x128.tga"));
mButton->setImageDisabled(LLUI::getUIImage("square_btn_32x128.tga"));
@@ -102,11 +95,11 @@ LLComboBox::LLComboBox( const std::string& name, const LLRect &rect, const std::
addChild(mButton);
// disallow multiple selection
mList = new LLScrollListCtrl(std::string("ComboBox"), LLRect(),
mList = new LLScrollListCtrl(std::string("ComboBox"), LLRect(),
boost::bind(&LLComboBox::onItemSelected, this, _2), FALSE);
mList->setVisible(FALSE);
mList->setVisible(false);
mList->setBgWriteableColor(mListColor);
mList->setCommitOnKeyboardMovement(FALSE);
mList->setCommitOnKeyboardMovement(false);
addChild(mList);
// Mouse-down on button will transfer mouse focus to the list
@@ -117,12 +110,11 @@ LLComboBox::LLComboBox( const std::string& name, const LLRect &rect, const std::
mButton->setImageOverlay("combobox_arrow.tga", LLFontGL::RIGHT);
updateLayout();
mTopLostSignalConnection = setTopLostCallback(boost::bind(&LLComboBox::hideList, this));
}
// virtual
LLXMLNodePtr LLComboBox::getXML(bool save_children) const
{
@@ -131,16 +123,12 @@ LLXMLNodePtr LLComboBox::getXML(bool save_children) const
node->setName(LL_COMBO_BOX_TAG);
// Attributes
node->createChild("allow_text_entry", TRUE)->setBoolValue(mAllowTextEntry);
node->createChild("max_chars", TRUE)->setIntValue(mMaxChars);
// Contents
std::vector<LLScrollListItem*> data_list = mList->getAllData();
std::vector<LLScrollListItem*>::iterator data_itor;
for (data_itor = data_list.begin(); data_itor != data_list.end(); ++data_itor)
for (std::vector<LLScrollListItem*>::iterator data_itor = data_list.begin(); data_itor != data_list.end(); ++data_itor)
{
LLScrollListItem* item = *data_itor;
LLScrollListCell* cell = item->getColumn(0);
@@ -172,9 +160,7 @@ LLView* LLComboBox::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *
S32 max_chars = 20;
node->getAttributeS32("max_chars", max_chars);
LLComboBox* combo_box = new LLComboBox("combo_box",
rect,
label);
LLComboBox* combo_box = new LLComboBox("combo_box", rect, label);
combo_box->setAllowTextEntry(allow_text_entry, max_chars);
const std::string& contents = node->getValue();
@@ -257,7 +243,6 @@ void LLComboBox::onCommit()
mTextEntry->setValue(getSimple());
mTextEntry->setTentative(FALSE);
}
setControlValue(getValue());
LLUICtrl::onCommit();
}
@@ -305,7 +290,6 @@ void LLComboBox::resetTextDirty()
}
}
// add item "name" to menu
LLScrollListItem* LLComboBox::add(const std::string& name, EAddPosition pos, BOOL enabled)
{
@@ -577,7 +561,7 @@ void LLComboBox::updateLayout()
if (!mTextEntry)
{
LLRect text_entry_rect(0, getRect().getHeight(), getRect().getWidth(), 0);
text_entry_rect.mRight -= llmax(8,mArrowImage->getWidth()) + 2 * LLUI::sConfigGroup->getS32("DropShadowButton");
text_entry_rect.mRight -= llmax(8,mArrowImage->getWidth()) + 2 * shadow_size;
// clear label on button
std::string cur_label = mButton->getLabelSelected();
mTextEntry = new LLLineEditor(std::string("combo_text_entry"),
@@ -590,9 +574,9 @@ void LLComboBox::updateLayout()
mTextEntry->setSelectAllonFocusReceived(TRUE);
mTextEntry->setHandleEditKeysDirectly(TRUE);
mTextEntry->setCommitOnFocusLost(FALSE);
mTextEntry->setFollows(FOLLOWS_ALL);
mTextEntry->setText(cur_label);
mTextEntry->setIgnoreTab(TRUE);
mTextEntry->setFollowsAll();
addChild(mTextEntry);
}
else
@@ -617,7 +601,7 @@ void LLComboBox::updateLayout()
{
mTextEntry->setVisible(FALSE);
}
mButton->setFollowsAll();
mButton->setFollows(FOLLOWS_ALL);
}
}
@@ -755,10 +739,6 @@ void LLComboBox::hideList()
}
}
//------------------------------------------------------------------
// static functions
//------------------------------------------------------------------
void LLComboBox::onButtonMouseDown()
{
if (!mList->getVisible())
@@ -896,7 +876,10 @@ BOOL LLComboBox::handleKeyHere(KEY key, MASK mask)
return FALSE;
}
// if selection has changed, pop open list
else if (mList->getLastSelectedItem() != last_selected_item)
else if (mList->getLastSelectedItem() != last_selected_item
|| ((key == KEY_DOWN || key == KEY_UP)
&& mList->getCanSelect()
&& !mList->isEmpty()))
{
showList();
}
@@ -1026,7 +1009,7 @@ void LLComboBox::updateSelection()
if(mSuppressAutoComplete) {
return;
}
LLWString left_wstring = mTextEntry->getWText().substr(0, mTextEntry->getCursor());
// user-entered portion of string, based on assumption that any selected
// text was a result of auto-completion
@@ -1236,168 +1219,3 @@ BOOL LLComboBox::selectItemRange( S32 first, S32 last )
return mList->selectItemRange(first, last);
}
//
// LLFlyoutButton
//
static LLRegisterWidget<LLFlyoutButton> r2("flyout_button");
const S32 FLYOUT_BUTTON_ARROW_WIDTH = 24;
LLFlyoutButton::LLFlyoutButton(
const std::string& name,
const LLRect &rect,
const std::string& label)
: LLComboBox(name, rect, LLStringUtil::null),
mToggleState(FALSE),
mActionButton(NULL)
{
// Always use text box
// Text label button
mActionButton = new LLButton(label,
LLRect(), LLStringUtil::null, boost::bind(&LLFlyoutButton::onActionButtonClick, this));
mActionButton->setScaleImage(TRUE);
mActionButton->setFollowsAll();
mActionButton->setHAlign( LLFontGL::HCENTER );
mActionButton->setLabel(label);
addChild(mActionButton);
mActionButtonImage = LLUI::getUIImage("flyout_btn_left.tga");
mExpanderButtonImage = LLUI::getUIImage("flyout_btn_right.tga");
mActionButtonImageSelected = LLUI::getUIImage("flyout_btn_left_selected.tga");
mExpanderButtonImageSelected = LLUI::getUIImage("flyout_btn_right_selected.tga");
mActionButtonImageDisabled = LLUI::getUIImage("flyout_btn_left_disabled.tga");
mExpanderButtonImageDisabled = LLUI::getUIImage("flyout_btn_right_disabled.tga");
mActionButton->setImageSelected(mActionButtonImageSelected);
mActionButton->setImageUnselected(mActionButtonImage);
mActionButton->setImageDisabled(mActionButtonImageDisabled);
mActionButton->setImageDisabledSelected(LLPointer<LLUIImage>(NULL));
mButton->setImageSelected(mExpanderButtonImageSelected);
mButton->setImageUnselected(mExpanderButtonImage);
mButton->setImageDisabled(mExpanderButtonImageDisabled);
mButton->setImageDisabledSelected(LLPointer<LLUIImage>(NULL));
mButton->setRightHPad(6);
updateLayout();
}
// virtual
LLXMLNodePtr LLFlyoutButton::getXML(bool save_children) const
{
LLXMLNodePtr node = LLComboBox::getXML();
node->setName(LL_FLYOUT_BUTTON_TAG);
LLXMLNodePtr child;
for (child = node->getFirstChild(); child.notNull();)
{
if (child->hasName("combo_item"))
{
child->setName(LL_FLYOUT_BUTTON_ITEM_TAG);
//setName does a delete and add, so we have to start over
child = node->getFirstChild();
}
else
{
child = child->getNextSibling();
}
}
return node;
}
//static
LLView* LLFlyoutButton::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory)
{
std::string label("");
node->getAttributeString("label", label);
LLRect rect;
createRect(node, rect, parent, LLRect());
LLFlyoutButton* flyout_button = new LLFlyoutButton("flyout_button",
rect,
label);
std::string list_position;
node->getAttributeString("list_position", list_position);
if (list_position == "below")
{
flyout_button->mListPosition = BELOW;
}
else if (list_position == "above")
{
flyout_button->mListPosition = ABOVE;
}
flyout_button->initFromXML(node, parent);
LLXMLNodePtr child;
for (child = node->getFirstChild(); child.notNull(); child = child->getNextSibling())
{
if (child->hasName("flyout_button_item"))
{
std::string label = child->getTextContents();
std::string value = label;
child->getAttributeString("value", value);
flyout_button->add(label, LLSD(value) );
}
}
flyout_button->updateLayout();
return flyout_button;
}
void LLFlyoutButton::updateLayout()
{
LLComboBox::updateLayout();
mButton->setOrigin(getRect().getWidth() - FLYOUT_BUTTON_ARROW_WIDTH, 0);
mButton->reshape(FLYOUT_BUTTON_ARROW_WIDTH, getRect().getHeight());
mButton->setFollows(FOLLOWS_RIGHT | FOLLOWS_TOP | FOLLOWS_BOTTOM);
mButton->setTabStop(FALSE);
mButton->setImageOverlay(mListPosition == BELOW ? "down_arrow.tga" : "up_arrow.tga", LLFontGL::RIGHT);
mActionButton->setOrigin(0, 0);
mActionButton->reshape(getRect().getWidth() - FLYOUT_BUTTON_ARROW_WIDTH, getRect().getHeight());
}
void LLFlyoutButton::onActionButtonClick()
{
// remember last list selection?
mList->deselect();
onCommit();
}
void LLFlyoutButton::draw()
{
mActionButton->setToggleState(mToggleState);
mButton->setToggleState(mToggleState);
//FIXME: this should be an attribute of comboboxes, whether they have a distinct label or
// the label reflects the last selected item, for now we have to manually remove the label
mButton->setLabel(LLStringUtil::null);
LLComboBox::draw();
}
void LLFlyoutButton::setEnabled(BOOL enabled)
{
mActionButton->setEnabled(enabled);
LLComboBox::setEnabled(enabled);
}
void LLFlyoutButton::setToggleState(BOOL state)
{
mToggleState = state;
}

View File

@@ -2,31 +2,25 @@
* @file llcombobox.h
* @brief LLComboBox base class
*
* $LicenseInfo:firstyear=2001&license=viewergpl$
*
* Copyright (c) 2001-2009, Linden Research, Inc.
*
* $LicenseInfo:firstyear=2001&license=viewerlgpl$
* Second Life Viewer Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in doc/GPL-license.txt in this distribution, or
* online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
* Copyright (C) 2010, 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.
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or
* online at
* http://secondlifegrid.net/programs/open_source/licensing/flossexception
* 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.
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
* 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
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
@@ -39,15 +33,12 @@
#include "llbutton.h"
#include "lluictrl.h"
#include "llctrlselectioninterface.h"
#include "llimagegl.h"
#include "llrect.h"
#include "llscrolllistctrl.h"
// Classes
class LLFontGL;
class LLButton;
class LLSquareButton;
class LLScrollListCtrl;
class LLLineEditor;
class LLViewBorder;
@@ -64,15 +55,12 @@ public:
BELOW
} EPreferredPosition;
LLComboBox(
const std::string& name,
const LLRect &rect,
const std::string& label,
commit_callback_t commit_callback = NULL
);
virtual ~LLComboBox();
protected:
void prearrangeList(std::string filter = "");
friend class LLFloaterTestImpl;
friend class LLUICtrlFactory;
LLComboBox(const std::string& name, const LLRect& rect, const std::string& label, commit_callback_t commit_callback = NULL);
void prearrangeList(std::string filter = "");
public:
// LLView interface
@@ -191,7 +179,6 @@ public:
void onButtonMouseDown();
void onListMouseUp();
void onItemSelected(const LLSD& data);
void onTextCommit(const LLSD& data);
void setSuppressTentative(bool suppress);
@@ -226,34 +213,4 @@ private:
S32 mLastSelectedIndex;
};
class LLFlyoutButton : public LLComboBox
{
public:
LLFlyoutButton(
const std::string& name,
const LLRect &rect,
const std::string& label);
virtual void updateLayout();
virtual void draw();
virtual void setEnabled(BOOL enabled);
void setToggleState(BOOL state);
virtual LLXMLNodePtr getXML(bool save_children = true) const;
static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory);
void onActionButtonClick();
void onSelectAction(LLUICtrl* ctrl);
protected:
LLButton* mActionButton;
LLPointer<LLUIImage> mActionButtonImage;
LLPointer<LLUIImage> mExpanderButtonImage;
LLPointer<LLUIImage> mActionButtonImageSelected;
LLPointer<LLUIImage> mExpanderButtonImageSelected;
LLPointer<LLUIImage> mActionButtonImageDisabled;
LLPointer<LLUIImage> mExpanderButtonImageDisabled;
BOOL mToggleState;
};
#endif

View File

@@ -0,0 +1,172 @@
/**
* @file llflyoutbutton.cpp
* @brief LLFlyoutButton base class
*
* $LicenseInfo:firstyear=2001&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, 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"
// file includes
#include "llflyoutbutton.h"
static LLRegisterWidget<LLFlyoutButton> r2("flyout_button");
const S32 FLYOUT_BUTTON_ARROW_WIDTH = 24;
LLFlyoutButton::LLFlyoutButton(const std::string& name, const LLRect& rect, const std::string& label)
: LLComboBox(name, rect, LLStringUtil::null),
mToggleState(FALSE),
mActionButton(NULL)
{
// Always use text box
// Text label button
mActionButton = new LLButton(label, LLRect(), LLStringUtil::null, boost::bind(&LLFlyoutButton::onActionButtonClick, this, _2));
mActionButton->setScaleImage(true);
mActionButton->setFollowsAll();
mActionButton->setHAlign(LLFontGL::HCENTER);
mActionButton->setLabel(label);
addChild(mActionButton);
mActionButton->setImageSelected(LLUI::getUIImage("flyout_btn_left_selected.tga"));
mActionButton->setImageUnselected(LLUI::getUIImage("flyout_btn_left.tga"));
mActionButton->setImageDisabled(LLUI::getUIImage("flyout_btn_left_disabled.tga"));
mActionButton->setImageDisabledSelected(LLPointer<LLUIImage>(NULL));
mButton->setImageSelected(LLUI::getUIImage("flyout_btn_right_selected.tga"));
mButton->setImageUnselected(LLUI::getUIImage("flyout_btn_right.tga"));
mButton->setImageDisabled(LLUI::getUIImage("flyout_btn_right_disabled.tga"));
mButton->setImageDisabledSelected(LLPointer<LLUIImage>(NULL));
mButton->setRightHPad(6);
updateLayout();
}
// virtual
LLXMLNodePtr LLFlyoutButton::getXML(bool save_children) const
{
LLXMLNodePtr node = LLComboBox::getXML();
node->setName(LL_FLYOUT_BUTTON_TAG);
for (LLXMLNodePtr child = node->getFirstChild(); child.notNull();)
{
if (child->hasName("combo_item"))
{
child->setName(LL_FLYOUT_BUTTON_ITEM_TAG);
//setName does a delete and add, so we have to start over
child = node->getFirstChild();
}
else
{
child = child->getNextSibling();
}
}
return node;
}
//static
LLView* LLFlyoutButton::fromXML(LLXMLNodePtr node, LLView* parent, LLUICtrlFactory* factory)
{
std::string label("");
node->getAttributeString("label", label);
LLRect rect;
createRect(node, rect, parent, LLRect());
LLFlyoutButton* flyout_button = new LLFlyoutButton("flyout_button", rect, label);
std::string list_position;
node->getAttributeString("list_position", list_position);
if (list_position == "below")
{
flyout_button->mListPosition = BELOW;
}
else if (list_position == "above")
{
flyout_button->mListPosition = ABOVE;
}
flyout_button->initFromXML(node, parent);
for (LLXMLNodePtr child = node->getFirstChild(); child.notNull(); child = child->getNextSibling())
{
if (child->hasName(LL_FLYOUT_BUTTON_ITEM_TAG))
{
std::string label(child->getTextContents());
std::string value(label);
child->getAttributeString("value", value);
flyout_button->add(label, LLSD(value));
}
}
flyout_button->updateLayout();
return flyout_button;
}
void LLFlyoutButton::updateLayout()
{
LLComboBox::updateLayout();
mButton->setOrigin(getRect().getWidth() - FLYOUT_BUTTON_ARROW_WIDTH, 0);
mButton->reshape(FLYOUT_BUTTON_ARROW_WIDTH, getRect().getHeight());
mButton->setFollows(FOLLOWS_RIGHT | FOLLOWS_TOP | FOLLOWS_BOTTOM);
mButton->setTabStop(false);
mButton->setImageOverlay(mListPosition == BELOW ? "down_arrow.tga" : "up_arrow.tga", LLFontGL::RIGHT);
mActionButton->setOrigin(0, 0);
mActionButton->reshape(getRect().getWidth() - FLYOUT_BUTTON_ARROW_WIDTH, getRect().getHeight());
}
void LLFlyoutButton::onActionButtonClick(const LLSD& data)
{
// remember last list selection?
mList->deselect();
onCommit();
}
void LLFlyoutButton::draw()
{
mActionButton->setToggleState(mToggleState);
mButton->setToggleState(mToggleState);
//FIXME: this should be an attribute of comboboxes, whether they have a distinct label or
// the label reflects the last selected item, for now we have to manually remove the label
mButton->setLabel(LLStringUtil::null);
LLComboBox::draw();
}
void LLFlyoutButton::setEnabled(BOOL enabled)
{
mActionButton->setEnabled(enabled);
LLComboBox::setEnabled(enabled);
}
void LLFlyoutButton::setToggleState(BOOL state)
{
mToggleState = state;
}

View File

@@ -0,0 +1,59 @@
/**
* @file llflyoutbutton.h
* @brief LLFlyoutButton base class
*
* $LicenseInfo:firstyear=2001&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, 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 choices.
#ifndef LL_LLFLYOUTBUTTON_H
#define LL_LLFLYOUTBUTTON_H
#include "llcombobox.h"
// Classes
class LLFlyoutButton : public LLComboBox
{
protected:
LLFlyoutButton(const std::string& name, const LLRect& rect, const std::string& label);
friend class LLUICtrlFactory;
public:
virtual void updateLayout();
virtual void draw();
virtual void setEnabled(BOOL enabled);
void setToggleState(BOOL state);
virtual LLXMLNodePtr getXML(bool save_children = true) const;
static LLView* fromXML(LLXMLNodePtr node, LLView* parent, LLUICtrlFactory* factory);
void onActionButtonClick(const LLSD& data);
void onSelectAction(LLUICtrl* ctrl);
protected:
LLButton* mActionButton;
BOOL mToggleState;
};
#endif // LL_LLFLYOUTBUTTON_H

View File

@@ -0,0 +1,364 @@
/**
* @file llscrolllistcell.cpp
* @brief Scroll lists are composed of rows (items), each of which
* contains columns (cells).
*
* $LicenseInfo:firstyear=2007&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, 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 "llscrolllistcell.h"
#include "llcheckboxctrl.h"
LLScrollListCell::LLScrollListCell(S32 width)
: mWidth(width)
{}
// virtual
const LLSD LLScrollListCell::getValue() const
{
return LLStringUtil::null;
}
//
// LLScrollListIcon
//
LLScrollListIcon::LLScrollListIcon(const LLSD& value, S32 width)
: LLScrollListCell(width),
// <edit>
mCallback(NULL),
// </edit>
mColor(LLColor4::white)
{
setValue(value);
}
LLScrollListIcon::~LLScrollListIcon()
{
}
/*virtual*/
S32 LLScrollListIcon::getHeight() const
{ return mIcon ? mIcon->getHeight() : 0; }
/*virtual*/
const LLSD LLScrollListIcon::getValue() const
{ return mIcon.isNull() ? LLStringUtil::null : mIcon->getName(); }
void LLScrollListIcon::setValue(const LLSD& value)
{
if (value.isUUID())
{
// don't use default image specified by LLUUID::null, use no image in that case
LLUUID image_id = value.asUUID();
mIcon = image_id.notNull() ? LLUI::getUIImageByID(image_id) : LLUIImagePtr(NULL);
}
else
{
std::string value_string = value.asString();
if (LLUUID::validate(value_string))
{
setValue(LLUUID(value_string));
}
else if (!value_string.empty())
{
mIcon = LLUI::getUIImage(value.asString());
}
else
{
mIcon = NULL;
}
}
}
void LLScrollListIcon::setColor(const LLColor4& color)
{
mColor = color;
}
S32 LLScrollListIcon::getWidth() const
{
// if no specified fix width, use width of icon
if (LLScrollListCell::getWidth() == 0 && mIcon.notNull())
{
return mIcon->getWidth();
}
return LLScrollListCell::getWidth();
}
void LLScrollListIcon::draw(const LLColor4& color, const LLColor4& highlight_color) const
{
if (mIcon)
{
mIcon->draw(0, 0, mColor);
}
}
//
// LLScrollListText
//
U32 LLScrollListText::sCount = 0;
LLScrollListText::LLScrollListText(const std::string& text, const LLFontGL* font, S32 width, U8 font_style, LLFontGL::HAlign font_alignment, LLColor4& color, BOOL use_color, BOOL visible)
: LLScrollListCell(width),
mText(text),
mFont(font),
mColor(color),
mUseColor(use_color),
mFontStyle(font_style),
mFontAlignment(font_alignment),
mVisible(visible),
mHighlightCount( 0 ),
mHighlightOffset( 0 )
{
sCount++;
mTextWidth = getWidth();
// initialize rounded rect image
if (!mRoundedRectImage)
{
mRoundedRectImage = LLUI::getUIImage("rounded_square.tga");
}
}
//virtual
void LLScrollListText::highlightText(S32 offset, S32 num_chars)
{
mHighlightOffset = offset;
mHighlightCount = num_chars;
}
//virtual
BOOL LLScrollListText::isText() const
{
return TRUE;
}
//virtual
BOOL LLScrollListText::getVisible() const
{
return mVisible;
}
//virtual
S32 LLScrollListText::getHeight() const
{
return llround(mFont->getLineHeight());
}
LLScrollListText::~LLScrollListText()
{
sCount--;
}
S32 LLScrollListText::getContentWidth() const
{
return mFont->getWidth(mText.getString());
}
void LLScrollListText::setColor(const LLColor4& color)
{
mColor = color;
mUseColor = TRUE;
}
void LLScrollListText::setText(const LLStringExplicit& text)
{
mText = text;
}
void LLScrollListText::setFontStyle(const U8 font_style)
{
mFontStyle = font_style;
}
//virtual
void LLScrollListText::setValue(const LLSD& text)
{
setText(text.asString());
}
//virtual
const LLSD LLScrollListText::getValue() const
{
return LLSD(mText.getString());
}
void LLScrollListText::draw(const LLColor4& color, const LLColor4& highlight_color) const
{
LLColor4 display_color;
if (mUseColor)
{
display_color = mColor;
}
else
{
display_color = color;
}
if (mHighlightCount > 0)
{
S32 left = 0;
switch(mFontAlignment)
{
case LLFontGL::LEFT:
left = mFont->getWidth(mText.getString(), 0, mHighlightOffset);
break;
case LLFontGL::RIGHT:
left = getWidth() - mFont->getWidth(mText.getString(), mHighlightOffset, S32_MAX);
break;
case LLFontGL::HCENTER:
left = (getWidth() - mFont->getWidth(mText.getString())) / 2;
break;
}
LLRect highlight_rect(left - 2,
llround(mFont->getLineHeight()) + 1,
left + mFont->getWidth(mText.getString(), mHighlightOffset, mHighlightCount) + 1,
1);
mRoundedRectImage->draw(highlight_rect, highlight_color);
}
// Try to draw the entire string
F32 right_x;
U32 string_chars = mText.length();
F32 start_x = 0.f;
switch(mFontAlignment)
{
case LLFontGL::LEFT:
start_x = (mFontStyle & LLFontGL::ITALIC) ? 2.f : 0.f; //Italic text seems to need a little padding.
break;
case LLFontGL::RIGHT:
start_x = (F32)getWidth();
break;
case LLFontGL::HCENTER:
start_x = (F32)getWidth() * 0.5f;
break;
}
mFont->render(mText.getWString(), 0,
start_x, 2.f,
display_color,
mFontAlignment,
LLFontGL::BOTTOM,
mFontStyle,
LLFontGL::NO_SHADOW,
string_chars,
getTextWidth(),
&right_x,
FALSE,
TRUE);
}
//
// LLScrollListCheck
//
LLScrollListCheck::LLScrollListCheck(LLCheckBoxCtrl* check_box, S32 width)
: LLScrollListCell(width)
{
mCheckBox = check_box;
LLRect rect(mCheckBox->getRect());
if (width)
{
rect.mRight = rect.mLeft + width;
mCheckBox->setRect(rect);
setWidth(width);
}
else
{
setWidth(rect.getWidth()); //check_box->getWidth();
}
}
LLScrollListCheck::~LLScrollListCheck()
{
delete mCheckBox;
mCheckBox = NULL;
}
void LLScrollListCheck::draw(const LLColor4& color, const LLColor4& highlight_color) const
{
mCheckBox->draw();
}
BOOL LLScrollListCheck::handleClick()
{
if (mCheckBox->getEnabled())
{
mCheckBox->toggle();
}
// don't change selection when clicking on embedded checkbox
return TRUE;
}
/*virtual*/
const LLSD LLScrollListCheck::getValue() const
{
return mCheckBox->getValue();
}
/*virtual*/
void LLScrollListCheck::setValue(const LLSD& value)
{
mCheckBox->setValue(value);
}
/*virtual*/
void LLScrollListCheck::onCommit()
{
mCheckBox->onCommit();
}
/*virtual*/
void LLScrollListCheck::setEnabled(BOOL enable)
{
mCheckBox->setEnabled(enable);
}
//
// LLScrollListDate
//
LLScrollListDate::LLScrollListDate( const LLDate& date, const LLFontGL* font, S32 width, U8 font_style, LLFontGL::HAlign font_alignment, LLColor4& color, BOOL use_color, BOOL visible)
: LLScrollListText(date.asRFC1123(), font, width, font_style, font_alignment, color, use_color, visible),
mDate(date)
{}
void LLScrollListDate::setValue(const LLSD& value)
{
mDate = value.asDate();
LLScrollListText::setValue(mDate.asRFC1123());
}
const LLSD LLScrollListDate::getValue() const
{
return mDate;
}

View File

@@ -0,0 +1,180 @@
/**
* @file llscrolllistcell.h
* @brief Scroll lists are composed of rows (items), each of which
* contains columns (cells).
*
* $LicenseInfo:firstyear=2007&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, 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 LLSCROLLLISTCELL_H
#define LLSCROLLLISTCELL_H
#include "llfontgl.h" // HAlign
#include "llpointer.h" // LLPointer<>
#include "lluistring.h"
#include "v4color.h"
#include "llui.h"
class LLCheckBoxCtrl;
class LLSD;
/*
* Represents a cell in a scrollable table.
*
* Sub-classes must return height and other properties
* though width accessors are implemented by the base class.
* It is therefore important for sub-class constructors to call
* setWidth() with realistic values.
*/
class LLScrollListCell
{
public:
LLScrollListCell(S32 width = 0);
virtual ~LLScrollListCell() {};
virtual void draw(const LLColor4& color, const LLColor4& highlight_color) const {}; // truncate to given width, if possible
virtual S32 getWidth() const {return mWidth;}
virtual S32 getContentWidth() const { return 0; }
virtual S32 getHeight() const { return 0; }
virtual const LLSD getValue() const;
virtual void setValue(const LLSD& value) { }
virtual BOOL getVisible() const { return TRUE; }
virtual void setWidth(S32 width) { mWidth = width; }
virtual void highlightText(S32 offset, S32 num_chars) {}
virtual BOOL isText() const { return FALSE; }
virtual void setColor(const LLColor4&) {}
virtual void onCommit() {};
virtual BOOL handleClick() { return FALSE; }
virtual void setEnabled(BOOL enable) { }
private:
S32 mWidth;
};
/*
* Cell displaying a text label.
*/
class LLScrollListText : public LLScrollListCell
{
public:
LLScrollListText(const std::string& text, const LLFontGL* font, S32 width = 0, U8 font_style = LLFontGL::NORMAL, LLFontGL::HAlign font_alignment = LLFontGL::LEFT, LLColor4& color = LLColor4::black, BOOL use_color = FALSE, BOOL visible = TRUE);
/*virtual*/ ~LLScrollListText();
/*virtual*/ void draw(const LLColor4& color, const LLColor4& highlight_color) const;
/*virtual*/ S32 getContentWidth() const;
/*virtual*/ S32 getHeight() const;
/*virtual*/ void setValue(const LLSD& value);
/*virtual*/ const LLSD getValue() const;
/*virtual*/ BOOL getVisible() const;
/*virtual*/ void highlightText(S32 offset, S32 num_chars);
/*virtual*/ void setColor(const LLColor4&);
/*virtual*/ BOOL isText() const;
S32 getTextWidth() const { return mTextWidth;}
void setTextWidth(S32 value) { mTextWidth = value;}
virtual void setWidth(S32 width) { LLScrollListCell::setWidth(width); mTextWidth = width; }
void setText(const LLStringExplicit& text);
void setFontStyle(const U8 font_style);
private:
LLUIString mText;
S32 mTextWidth;
const LLFontGL* mFont;
LLColor4 mColor;
U8 mUseColor;
U8 mFontStyle;
LLFontGL::HAlign mFontAlignment;
BOOL mVisible;
S32 mHighlightCount;
S32 mHighlightOffset;
LLPointer<LLUIImage> mRoundedRectImage;
static U32 sCount;
};
/*
* Cell displaying an image.
*/
class LLScrollListIcon : public LLScrollListCell
{
public:
LLScrollListIcon( LLUIImagePtr icon, S32 width = 0);
LLScrollListIcon(const LLSD& value, S32 width = 0);
/*virtual*/ ~LLScrollListIcon();
/*virtual*/ void draw(const LLColor4& color, const LLColor4& highlight_color) const;
/*virtual*/ S32 getWidth() const;
/*virtual*/ S32 getHeight() const;
/*virtual*/ const LLSD getValue() const;
/*virtual*/ void setColor(const LLColor4&);
/*virtual*/ void setValue(const LLSD& value);
// <edit>
void setClickCallback(boost::function<bool (void)> cb) { mCallback = cb; }
/*virtual*/ BOOL handleClick() { return mCallback ? mCallback() : false; }
// </edit>
private:
LLPointer<LLUIImage> mIcon;
LLColor4 mColor;
// <edit>
boost::function<bool (void)> mCallback;
// </edit>
};
/*
* An interactive cell containing a check box.
*/
class LLScrollListCheck : public LLScrollListCell
{
public:
LLScrollListCheck( LLCheckBoxCtrl* check_box, S32 width = 0);
/*virtual*/ ~LLScrollListCheck();
/*virtual*/ void draw(const LLColor4& color, const LLColor4& highlight_color) const;
/*virtual*/ S32 getHeight() const { return 0; }
/*virtual*/ const LLSD getValue() const;
/*virtual*/ void setValue(const LLSD& value);
/*virtual*/ void onCommit();
/*virtual*/ BOOL handleClick();
/*virtual*/ void setEnabled(BOOL enable);
LLCheckBoxCtrl* getCheckBox() { return mCheckBox; }
private:
LLCheckBoxCtrl* mCheckBox;
};
class LLScrollListDate : public LLScrollListText
{
public:
LLScrollListDate( const LLDate& date, const LLFontGL* font, S32 width=0, U8 font_style = LLFontGL::NORMAL, LLFontGL::HAlign font_alignment = LLFontGL::LEFT, LLColor4& color = LLColor4::black, BOOL use_color = FALSE, BOOL visible = TRUE);
virtual void setValue(const LLSD& value);
virtual const LLSD getValue() const;
private:
LLDate mDate;
};
#endif

View File

@@ -0,0 +1,484 @@
/**
* @file llscrollcolumnheader.cpp
* @brief Scroll lists are composed of rows (items), each of which
* contains columns (cells).
*
* $LicenseInfo:firstyear=2007&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, 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 "llscrolllistcolumn.h"
#include "llbutton.h"
#include "llkeyboard.h" // For gKeyboard
#include "llresizebar.h"
#include "lluictrlfactory.h"
const S32 MIN_COLUMN_WIDTH = 20;
//---------------------------------------------------------------------------
// LLScrollColumnHeader
//---------------------------------------------------------------------------
LLScrollColumnHeader::LLScrollColumnHeader(const std::string& label, const LLRect& rect, LLScrollListColumn* column, const LLFontGL* fontp)
: LLComboBox(label, rect, label),
mColumn(column),
mOrigLabel(label),
mHasResizableElement(FALSE)
{
mListPosition = LLComboBox::ABOVE;
setCommitCallback(boost::bind(&LLScrollColumnHeader::onSelectSort, this));
mButton->setTabStop(FALSE);
mButton->setClickedCallback(boost::bind(&LLScrollColumnHeader::onClick, this, _2));
mButton->setToolTip(label);
mAscendingText = std::string("[LOW]...[HIGH](Ascending)"); // *TODO: Translate
mDescendingText = std::string("[HIGH]...[LOW](Descending)"); // *TODO: Translate
mList->reshape(llmax(mList->getRect().getWidth(), 110, getRect().getWidth()), mList->getRect().getHeight());
// resize handles on left and right
const S32 RESIZE_BAR_THICKNESS = 3;
LLResizeBar::Params resize_bar_p;
resize_bar_p.resizing_view(this);
resize_bar_p.rect(LLRect(getRect().getWidth() - RESIZE_BAR_THICKNESS, getRect().getHeight(), getRect().getWidth(), 0));
resize_bar_p.min_size(MIN_COLUMN_WIDTH);
resize_bar_p.side(LLResizeBar::RIGHT);
resize_bar_p.enabled(false);
mResizeBar = LLUICtrlFactory::create<LLResizeBar>(resize_bar_p);
addChild(mResizeBar);
mImageOverlayAlignment = LLFontGL::HCENTER;
mImageOverlayColor = LLColor4::white;
}
LLScrollColumnHeader::~LLScrollColumnHeader()
{}
void LLScrollColumnHeader::draw()
{
std::string sort_column = mColumn->mParentCtrl->getSortColumnName();
BOOL draw_arrow = !mColumn->mLabel.empty()
&& mColumn->mParentCtrl->isSorted()
// check for indirect sorting column as well as column's sorting name
&& (sort_column == mColumn->mSortingColumn || sort_column == mColumn->mName);
BOOL is_ascending = mColumn->mParentCtrl->getSortAscending();
if (draw_arrow)
{
mButton->setImageOverlay(is_ascending ? "up_arrow.tga" : "down_arrow.tga", LLFontGL::RIGHT, LLColor4::white);
}
else
{
mButton->setImageOverlay(LLUUID::null);
}
mArrowImage = mButton->getImageOverlay();
// Draw children
LLComboBox::draw();
if (mImageOverlay.notNull()) //Ugly dupe code from llbutton...
{
BOOL pressed_by_keyboard = FALSE;
if (mButton->hasFocus())
{
pressed_by_keyboard = gKeyboard->getKeyDown(' ') || (mButton->getCommitOnReturn() && gKeyboard->getKeyDown(KEY_RETURN));
}
// Unselected image assignments
S32 local_mouse_x;
S32 local_mouse_y;
LLUI::getMousePositionLocal(mButton, &local_mouse_x, &local_mouse_y);
BOOL pressed = pressed_by_keyboard
|| (mButton->hasMouseCapture() && mButton->pointInView(local_mouse_x, local_mouse_y))
|| mButton->getToggleState();
// Now draw special overlay..
// let overlay image and text play well together
S32 button_width = mButton->getRect().getWidth();
S32 button_height = mButton->getRect().getHeight();
S32 text_left = mButton->getLeftHPad();
S32 text_right = button_width - mButton->getRightHPad();
S32 text_width = text_right - text_left;
// draw overlay image
// get max width and height (discard level 0)
S32 overlay_width = mImageOverlay->getWidth();
S32 overlay_height = mImageOverlay->getHeight();
F32 scale_factor = llmin((F32)button_width / (F32)overlay_width, (F32)button_height / (F32)overlay_height, 1.f);
overlay_width = llround((F32)overlay_width * scale_factor);
overlay_height = llround((F32)overlay_height * scale_factor);
S32 center_x = mButton->getLocalRect().getCenterX();
S32 center_y = mButton->getLocalRect().getCenterY();
//FUGLY HACK FOR "DEPRESSED" BUTTONS
if (pressed)
{
center_y--;
center_x++;
}
// fade out overlay images on disabled buttons
LLColor4 overlay_color = mImageOverlayColor;
if (!mButton->getEnabled())
{
overlay_color.mV[VALPHA] = 0.5f;
}
switch(mImageOverlayAlignment)
{
case LLFontGL::LEFT:
text_left += overlay_width + 1;
text_width -= overlay_width + 1;
mImageOverlay->draw(
text_left,
center_y - (overlay_height / 2),
overlay_width,
overlay_height,
overlay_color);
break;
case LLFontGL::HCENTER:
mImageOverlay->draw(
center_x - (overlay_width / 2),
center_y - (overlay_height / 2),
overlay_width,
overlay_height,
overlay_color);
break;
case LLFontGL::RIGHT:
text_right -= overlay_width + 1;
text_width -= overlay_width + 1;
mImageOverlay->draw(
text_right - overlay_width,
center_y - (overlay_height / 2),
overlay_width,
overlay_height,
overlay_color);
break;
default:
// draw nothing
break;
}
}
if (mList->getVisible())
{
// sync sort order with list selection every frame
mColumn->mParentCtrl->sortByColumn(mColumn->mSortingColumn, getCurrentIndex() == 0);
}
}
BOOL LLScrollColumnHeader::handleDoubleClick(S32 x, S32 y, MASK mask)
{
if (canResize() && mResizeBar->getRect().pointInRect(x, y))
{
// reshape column to max content width
mColumn->mParentCtrl->calcMaxContentWidth();
LLRect column_rect = getRect();
column_rect.mRight = column_rect.mLeft + mColumn->mMaxContentWidth;
setShape(column_rect, true);
}
else
{
onClick(LLSD());
}
return TRUE;
}
void LLScrollColumnHeader::setImage(const std::string& image_name)
{
if (mButton)
{
mButton->setImageSelected(LLUI::getUIImage(image_name));
mButton->setImageUnselected(LLUI::getUIImage(image_name));
}
}
void LLScrollColumnHeader::setImageOverlay(const std::string& image_name, LLFontGL::HAlign alignment, const LLColor4& color)
{
if (image_name.empty())
{
mImageOverlay = NULL;
}
else
{
mImageOverlay = LLUI::getUIImage(image_name);
mImageOverlayAlignment = alignment;
mImageOverlayColor = color;
}
}
void LLScrollColumnHeader::onClick(const LLSD& data)
{
if (mColumn)
{
if (mList->getVisible()) hideList();
LLScrollListCtrl::onClickColumn(mColumn);
// propagate new sort order to sort order list
mList->selectNthItem(mColumn->mParentCtrl->getSortAscending() ? 0 : 1);
mList->setFocus(true);
}
}
void LLScrollColumnHeader::onSelectSort()
{
if (!mColumn) return;
LLScrollListCtrl* parent = mColumn->mParentCtrl;
if (!parent) return;
parent->sortByColumn(mColumn->mSortingColumn, getCurrentIndex() == 0);
// restore original column header
setLabel(mOrigLabel);
}
LLView* LLScrollColumnHeader::findSnapEdge(S32& new_edge_val, const LLCoordGL& mouse_dir, ESnapEdge snap_edge, ESnapType snap_type, S32 threshold, S32 padding)
{
// this logic assumes dragging on right
llassert(snap_edge == SNAP_RIGHT);
// use higher snap threshold for column headers
threshold = llmin(threshold, 10);
LLRect snap_rect = getSnapRect();
S32 snap_delta = mColumn->mMaxContentWidth - snap_rect.getWidth();
// x coord growing means column growing, so same signs mean we're going in right direction
if (llabs(snap_delta) <= threshold && mouse_dir.mX * snap_delta > 0 )
{
new_edge_val = snap_rect.mRight + snap_delta;
}
else
{
LLScrollListColumn* next_column = mColumn->mParentCtrl->getColumn(mColumn->mIndex + 1);
while (next_column)
{
if (next_column->mHeader)
{
snap_delta = (next_column->mHeader->getSnapRect().mRight - next_column->mMaxContentWidth) - snap_rect.mRight;
if (llabs(snap_delta) <= threshold && mouse_dir.mX * snap_delta > 0 )
{
new_edge_val = snap_rect.mRight + snap_delta;
}
break;
}
next_column = mColumn->mParentCtrl->getColumn(next_column->mIndex + 1);
}
}
return this;
}
void LLScrollColumnHeader::handleReshape(const LLRect& new_rect, bool by_user)
{
S32 new_width = new_rect.getWidth();
S32 delta_width = new_width - (getRect().getWidth() /*+ mColumn->mParentCtrl->getColumnPadding()*/);
if (delta_width != 0)
{
S32 remaining_width = -delta_width;
S32 col;
for (col = mColumn->mIndex + 1; col < mColumn->mParentCtrl->getNumColumns(); col++)
{
LLScrollListColumn* columnp = mColumn->mParentCtrl->getColumn(col);
if (!columnp) continue;
if (columnp->mHeader && columnp->mHeader->canResize())
{
// how many pixels in width can this column afford to give up?
S32 resize_buffer_amt = llmax(0, columnp->getWidth() - MIN_COLUMN_WIDTH);
// user shrinking column, need to add width to other columns
if (delta_width < 0)
{
if (columnp->getWidth() > 0)
{
// statically sized column, give all remaining width to this column
columnp->setWidth(columnp->getWidth() + remaining_width);
if (columnp->mRelWidth > 0.f)
{
columnp->mRelWidth = (F32)columnp->getWidth() / (F32)mColumn->mParentCtrl->getItemListRect().getWidth();
}
// all padding went to this widget, we're done
break;
}
}
else
{
// user growing column, need to take width from other columns
remaining_width += resize_buffer_amt;
if (columnp->getWidth() > 0)
{
columnp->setWidth(columnp->getWidth() - llmin(columnp->getWidth() - MIN_COLUMN_WIDTH, delta_width));
if (columnp->mRelWidth > 0.f)
{
columnp->mRelWidth = (F32)columnp->getWidth() / (F32)mColumn->mParentCtrl->getItemListRect().getWidth();
}
}
if (remaining_width >= 0)
{
// width sucked up from neighboring columns, done
break;
}
}
}
}
// clamp resize amount to maximum that can be absorbed by other columns
if (delta_width > 0)
{
delta_width += llmin(remaining_width, 0);
}
// propagate constrained delta_width to new width for this column
new_width = getRect().getWidth() + delta_width - mColumn->mParentCtrl->getColumnPadding();
// use requested width
mColumn->setWidth(new_width);
// update proportional spacing
if (mColumn->mRelWidth > 0.f)
{
mColumn->mRelWidth = (F32)new_width / (F32)mColumn->mParentCtrl->getItemListRect().getWidth();
}
// tell scroll list to layout columns again
// do immediate update to get proper feedback to resize handle
// which needs to know how far the resize actually went
mColumn->mParentCtrl->dirtyColumns(); //Must flag as dirty, else updateColumns will probably be a noop.
mColumn->mParentCtrl->updateColumns();
}
}
void LLScrollColumnHeader::setHasResizableElement(BOOL resizable)
{
if (mHasResizableElement != resizable)
{
mColumn->mParentCtrl->dirtyColumns();
mHasResizableElement = resizable;
}
}
void LLScrollColumnHeader::updateResizeBars()
{
S32 num_resizable_columns = 0;
S32 col;
for (col = 0; col < mColumn->mParentCtrl->getNumColumns(); col++)
{
LLScrollListColumn* columnp = mColumn->mParentCtrl->getColumn(col);
if (columnp->mHeader && columnp->mHeader->canResize())
{
num_resizable_columns++;
}
}
S32 num_resizers_enabled = 0;
// now enable/disable resize handles on resizable columns if we have at least two
for (col = 0; col < mColumn->mParentCtrl->getNumColumns(); col++)
{
LLScrollListColumn* columnp = mColumn->mParentCtrl->getColumn(col);
if (!columnp->mHeader) continue;
BOOL enable = num_resizable_columns >= 2 && num_resizers_enabled < (num_resizable_columns - 1) && columnp->mHeader->canResize();
columnp->mHeader->enableResizeBar(enable);
if (enable)
{
num_resizers_enabled++;
}
}
}
void LLScrollColumnHeader::enableResizeBar(BOOL enable)
{
mResizeBar->setEnabled(enable);
}
BOOL LLScrollColumnHeader::canResize()
{
return getVisible() && (mHasResizableElement || mColumn->mDynamicWidth);
}
//
// LLScrollListColumn
//
// Default constructor
LLScrollListColumn::LLScrollListColumn() : mName(), mSortingColumn(), mSortDirection(ASCENDING), mLabel(), mWidth(-1), mRelWidth(-1.0), mDynamicWidth(false), mMaxContentWidth(0), mIndex(-1), mParentCtrl(NULL), mHeader(NULL), mFontAlignment(LLFontGL::LEFT)
{
}
LLScrollListColumn::LLScrollListColumn(const LLSD& sd, LLScrollListCtrl* parent)
: mWidth(0),
mIndex (-1),
mParentCtrl(parent),
mName(sd.get("name").asString()),
mLabel(sd.get("label").asString()),
mHeader(NULL),
mMaxContentWidth(0),
mDynamicWidth(sd.has("dynamicwidth") && sd.get("dynamicwidth").asBoolean()),
mRelWidth(-1.f),
mFontAlignment(LLFontGL::LEFT),
mSortingColumn(sd.has("sort") ? sd.get("sort").asString() : mName)
{
if (sd.has("sort_ascending"))
{
mSortDirection = sd.get("sort_ascending").asBoolean() ? ASCENDING : DESCENDING;
}
else
{
mSortDirection = ASCENDING;
}
if (sd.has("relwidth") && sd.get("relwidth").asFloat() > 0)
{
mRelWidth = sd.get("relwidth").asFloat();
if (mRelWidth > 1) mRelWidth = 1;
mDynamicWidth = false;
}
else if (!mDynamicWidth)
{
setWidth(sd.get("width").asInteger());
}
if (sd.has("halign"))
{
mFontAlignment = (LLFontGL::HAlign)llclamp(sd.get("halign").asInteger(), (S32)LLFontGL::LEFT, (S32)LLFontGL::HCENTER);
}
}
void LLScrollListColumn::setWidth(S32 width)
{
if (!mDynamicWidth && mRelWidth <= 0.f)
{
mParentCtrl->updateStaticColumnWidth(this, width);
}
mWidth = width;
}

View File

@@ -0,0 +1,116 @@
/**
* @file llscrollcolumnheader.h
* @brief Scroll lists are composed of rows (items), each of which
* contains columns (cells).
*
* $LicenseInfo:firstyear=2007&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, 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 LLSCROLLLISTCOLUMN_H
#define LLSCROLLLISTCOLUMN_H
#include "llrect.h"
#include "lluistring.h"
#include "llcombobox.h"
class LLScrollListColumn;
class LLResizeBar;
class LLScrollListCtrl;
class LLScrollColumnHeader : public LLComboBox
{
public:
LLScrollColumnHeader(const std::string& label, const LLRect& rect, LLScrollListColumn* column, const LLFontGL* font = NULL);
~LLScrollColumnHeader();
/*virtual*/ void draw();
/*virtual*/ BOOL handleDoubleClick(S32 x, S32 y, MASK mask);
/*virtual*/ void showList() {}; // block the normal showList() behavior
/*virtual*/ LLView* findSnapEdge(S32& new_edge_val, const LLCoordGL& mouse_dir, ESnapEdge snap_edge, ESnapType snap_type, S32 threshold, S32 padding);
/*virtual*/ void handleReshape(const LLRect& new_rect, bool by_user = false);
void setImage(const std::string& image_name);
void setImageOverlay(const std::string& overlay_image, LLFontGL::HAlign alignment = LLFontGL::HCENTER, const LLColor4& color = LLColor4::white);
LLScrollListColumn* getColumn() { return mColumn; }
void setHasResizableElement(BOOL resizable);
void updateResizeBars();
BOOL canResize();
void enableResizeBar(BOOL enable);
std::string getLabel() { return mOrigLabel; }
void onSelectSort();
void onClick(const LLSD& data);
private:
LLScrollListColumn* mColumn;
LLResizeBar* mResizeBar;
std::string mOrigLabel;
LLUIString mAscendingText;
LLUIString mDescendingText;
BOOL mHasResizableElement;
LLPointer<LLUIImage> mImageOverlay;
LLFontGL::HAlign mImageOverlayAlignment;
LLColor4 mImageOverlayColor;
};
/*
* A simple data class describing a column within a scroll list.
*/
class LLScrollListColumn
{
public:
typedef enum e_sort_direction
{
DESCENDING,
ASCENDING
} ESortDirection;
//NOTE: this is default constructible so we can store it in a map.
LLScrollListColumn();
LLScrollListColumn(const LLSD& sd, LLScrollListCtrl* parent = NULL);
void setWidth(S32 width);
S32 getWidth() const { return mWidth; }
public:
// Public data is fine so long as this remains a simple struct-like data class.
// If it ever gets any smarter than that, these should all become private
// with protected or public accessor methods added as needed. -MG
std::string mName;
std::string mSortingColumn;
ESortDirection mSortDirection;
LLUIString mLabel;
F32 mRelWidth;
BOOL mDynamicWidth;
S32 mMaxContentWidth;
S32 mIndex;
LLScrollListCtrl* mParentCtrl;
LLScrollColumnHeader* mHeader;
LLFontGL::HAlign mFontAlignment;
private:
S32 mWidth;
};
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,31 +1,28 @@
/**
* @file llscrolllistctrl.h
* @brief A scrolling list of items. This is the one you want to use
* in UI code. LLScrollListCell, LLScrollListItem, etc. are utility
* classes.
*
* $LicenseInfo:firstyear=2001&license=viewergpl$
*
* Copyright (c) 2001-2009, Linden Research, Inc.
*
* $LicenseInfo:firstyear=2001&license=viewerlgpl$
* Second Life Viewer Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in doc/GPL-license.txt in this distribution, or
* online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
* Copyright (C) 2010, Linden Research, Inc.
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or
* online at
* http://secondlifegrid.net/programs/open_source/licensing/flossexception
* 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.
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
* 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.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* 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$
*/
@@ -37,293 +34,16 @@
#include "lluictrl.h"
#include "llctrlselectioninterface.h"
#include "lldarray.h"
//#include "lldarray.h"
#include "llfontgl.h"
#include "llui.h"
#include "llstring.h"
#include "llimagegl.h"
#include "llstring.h" // LLWString
#include "lleditmenuhandler.h"
#include "llframetimer.h"
#include "llcheckboxctrl.h"
#include "llcombobox.h"
#include "llscrollbar.h"
#include "llresizebar.h"
#include "lldate.h"
// <edit>
#include <boost/function.hpp>
// </edit>
/*
* Represents a cell in a scrollable table.
*
* Sub-classes must return height and other properties
* though width accessors are implemented by the base class.
* It is therefore important for sub-class constructors to call
* setWidth() with realistic values.
*/
class LLScrollListCell
{
public:
LLScrollListCell(S32 width = 0) : mWidth(width) {};
virtual ~LLScrollListCell() {};
virtual void draw(const LLColor4& color, const LLColor4& highlight_color) const = 0; // truncate to given width, if possible
virtual S32 getWidth() const {return mWidth;}
virtual S32 getContentWidth() const { return 0; }
virtual S32 getHeight() const { return 0; }
virtual const LLSD getValue() const { return LLStringUtil::null; }
virtual void setValue(const LLSD& value) { }
virtual BOOL getVisible() const { return TRUE; }
virtual void setWidth(S32 width) { mWidth = width; }
virtual void highlightText(S32 offset, S32 num_chars) {}
virtual BOOL isText() const { return FALSE; }
virtual void setColor(const LLColor4&) {}
virtual void onCommit() {};
virtual BOOL handleClick() { return FALSE; }
virtual void setEnabled(BOOL enable) { }
private:
S32 mWidth;
};
/*
* Cell displaying a text label.
*/
class LLScrollListText : public LLScrollListCell
{
public:
LLScrollListText( const std::string& text, const LLFontGL* font, S32 width = 0, U8 font_style = LLFontGL::NORMAL, LLFontGL::HAlign font_alignment = LLFontGL::LEFT, LLColor4& color = LLColor4::black, BOOL use_color = FALSE, BOOL visible = TRUE);
/*virtual*/ ~LLScrollListText();
/*virtual*/ void draw(const LLColor4& color, const LLColor4& highlight_color) const;
/*virtual*/ S32 getContentWidth() const;
/*virtual*/ S32 getHeight() const;
/*virtual*/ void setValue(const LLSD& value);
/*virtual*/ const LLSD getValue() const;
/*virtual*/ BOOL getVisible() const;
/*virtual*/ void highlightText(S32 offset, S32 num_chars);
/*virtual*/ void setColor(const LLColor4&);
/*virtual*/ BOOL isText() const;
S32 getTextWidth() const { return mTextWidth;}
void setTextWidth(S32 value) { mTextWidth = value;}
virtual void setWidth(S32 width) { LLScrollListCell::setWidth(width); mTextWidth = width; }
void setText(const LLStringExplicit& text);
void setFontStyle(const U8 font_style);
private:
LLUIString mText;
S32 mTextWidth;
const LLFontGL* mFont;
LLColor4 mColor;
U8 mUseColor;
U8 mFontStyle;
LLFontGL::HAlign mFontAlignment;
BOOL mVisible;
S32 mHighlightCount;
S32 mHighlightOffset;
LLPointer<LLUIImage> mRoundedRectImage;
static U32 sCount;
};
/*
* Cell displaying an image.
*/
class LLScrollListIcon : public LLScrollListCell
{
public:
LLScrollListIcon(const LLSD& value, S32 width = 0);
/*virtual*/ ~LLScrollListIcon();
/*virtual*/ void draw(const LLColor4& color, const LLColor4& highlight_color) const;
/*virtual*/ S32 getWidth() const;
/*virtual*/ S32 getHeight() const;
/*virtual*/ const LLSD getValue() const;
/*virtual*/ void setColor(const LLColor4&);
/*virtual*/ void setValue(const LLSD& value);
// <edit>
void setClickCallback(boost::function<bool (void)> cb);
virtual BOOL handleClick();
// </edit>
private:
LLPointer<LLUIImage> mIcon;
LLColor4 mColor;
// <edit>
boost::function<bool (void)> mCallback;
// </edit>
};
/*
* An interactive cell containing a check box.
*/
class LLScrollListCheck : public LLScrollListCell
{
public:
LLScrollListCheck( LLCheckBoxCtrl* check_box, S32 width = 0);
/*virtual*/ ~LLScrollListCheck();
/*virtual*/ void draw(const LLColor4& color, const LLColor4& highlight_color) const;
/*virtual*/ S32 getHeight() const { return 0; }
/*virtual*/ const LLSD getValue() const;
/*virtual*/ void setValue(const LLSD& value);
/*virtual*/ void onCommit();
/*virtual*/ BOOL handleClick();
/*virtual*/ void setEnabled(BOOL enable);
LLCheckBoxCtrl* getCheckBox() { return mCheckBox; }
private:
LLCheckBoxCtrl* mCheckBox;
};
class LLScrollListDate : public LLScrollListText
{
public:
LLScrollListDate( const LLDate& date, const LLFontGL* font, S32 width=0, U8 font_style = LLFontGL::NORMAL, LLFontGL::HAlign font_alignment = LLFontGL::LEFT, LLColor4& color = LLColor4::black, BOOL use_color = FALSE, BOOL visible = TRUE);
virtual void setValue(const LLSD& value);
virtual const LLSD getValue() const;
private:
LLDate mDate;
};
class LLScrollListColumn;
class LLScrollColumnHeader : public LLComboBox
{
public:
LLScrollColumnHeader(const std::string& label, const LLRect &rect, LLScrollListColumn* column, const LLFontGL *font = NULL);
~LLScrollColumnHeader();
/*virtual*/ void draw();
/*virtual*/ BOOL handleDoubleClick(S32 x, S32 y, MASK mask);
/*virtual*/ void showList();
/*virtual*/ LLView* findSnapEdge(S32& new_edge_val, const LLCoordGL& mouse_dir, ESnapEdge snap_edge, ESnapType snap_type, S32 threshold, S32 padding);
/*virtual*/ void handleReshape(const LLRect& new_rect, bool by_user = false);
void setImage(const std::string &image_name);
void setImageOverlay(const std::string &overlay_image, LLFontGL::HAlign alignment = LLFontGL::HCENTER, const LLColor4& color = LLColor4::white);
LLScrollListColumn* getColumn() { return mColumn; }
void setHasResizableElement(BOOL resizable);
void updateResizeBars();
BOOL canResize();
void enableResizeBar(BOOL enable);
std::string getLabel() { return mOrigLabel; }
void onSelectSort();
void onClick();
void onMouseDown();
private:
LLScrollListColumn* mColumn;
LLResizeBar* mResizeBar;
std::string mOrigLabel;
LLUIString mAscendingText;
LLUIString mDescendingText;
BOOL mShowSortOptions;
BOOL mHasResizableElement;
LLPointer<LLUIImage> mImageOverlay;
LLFontGL::HAlign mImageOverlayAlignment;
LLColor4 mImageOverlayColor;
};
/*
* A simple data class describing a column within a scroll list.
*/
class LLScrollListColumn
{
public:
typedef enum e_sort_direction
{
DESCENDING,
ASCENDING
} ESortDirection;
LLScrollListColumn();
LLScrollListColumn(const LLSD &sd, LLScrollListCtrl* parent);
void setWidth(S32 width);
S32 getWidth() const { return mWidth; }
// Public data is fine so long as this remains a simple struct-like data class.
// If it ever gets any smarter than that, these should all become private
// with protected or public accessor methods added as needed. -MG
std::string mName;
std::string mSortingColumn;
ESortDirection mSortDirection;
std::string mLabel;
F32 mRelWidth;
BOOL mDynamicWidth;
S32 mMaxContentWidth;
S32 mIndex;
LLScrollListCtrl* mParentCtrl;
LLScrollColumnHeader* mHeader;
LLFontGL::HAlign mFontAlignment;
private:
S32 mWidth;
};
class LLScrollListItem : public LLHandleProvider<LLScrollListItem>
{
public:
LLScrollListItem( BOOL enabled = TRUE, void* userdata = NULL, const LLUUID& uuid = LLUUID::null )
: mSelected(FALSE), mEnabled( enabled ), mUserdata( userdata ), mItemValue( uuid ), mColumns() {}
LLScrollListItem( LLSD item_value, void* userdata = NULL )
: mSelected(FALSE), mEnabled( TRUE ), mUserdata( userdata ), mItemValue( item_value ), mColumns() {}
virtual ~LLScrollListItem();
void setSelected( BOOL b ) { mSelected = b; }
BOOL getSelected() const { return mSelected; }
void setEnabled( BOOL b ) { mEnabled = b; }
BOOL getEnabled() const { return mEnabled; }
void setUserdata( void* userdata ) { mUserdata = userdata; }
void* getUserdata() const { return mUserdata; }
void setToolTip(const std::string tool_tip) { mToolTip=tool_tip; }
std::string getToolTip() { return mToolTip; }
virtual LLUUID getUUID() const { return mItemValue.asUUID(); }
LLSD getValue() const { return mItemValue; }
void setRect(LLRect rect) { mRectangle = rect; }
LLRect getRect() const { return mRectangle; }
// If width = 0, just use the width of the text. Otherwise override with
// specified width in pixels.
void addColumn( const std::string& text, const LLFontGL* font, S32 width = 0 , U8 font_style = LLFontGL::NORMAL, LLFontGL::HAlign font_alignment = LLFontGL::LEFT, BOOL visible = TRUE)
{ mColumns.push_back( new LLScrollListText(text, font, width, font_style, font_alignment, LLColor4::black, FALSE, visible) ); }
void setNumColumns(S32 columns);
void setColumn( S32 column, LLScrollListCell *cell );
S32 getNumColumns() const;
LLScrollListCell *getColumn(const S32 i) const;
std::string getContentsCSV() const;
virtual void draw(const LLRect& rect, const LLColor4& fg_color, const LLColor4& bg_color, const LLColor4& highlight_color, S32 column_padding);
private:
BOOL mSelected;
BOOL mEnabled;
void* mUserdata;
LLSD mItemValue;
std::string mToolTip;
std::vector<LLScrollListCell *> mColumns;
LLRect mRectangle;
};
class LLScrollListCtrl : public LLUICtrl, public LLEditMenuHandler,
public LLCtrlListInterface, public LLCtrlScrollInterface
@@ -354,13 +74,10 @@ public:
typedef boost::signals2::signal<S32 (S32,const LLScrollListItem*,const LLScrollListItem*),maximum<S32> > sort_signal_t;
LLScrollListCtrl(
const std::string& name,
const LLRect& rect,
commit_callback_t commit_callback,
BOOL allow_multiple_selection,
BOOL draw_border = TRUE, bool draw_heading = false);
LLScrollListCtrl(const std::string& name, const LLRect& rect, commit_callback_t commit_callback, bool multi_select, bool has_border = true, bool draw_heading = false);
public:
virtual ~LLScrollListCtrl();
virtual LLXMLNodePtr getXML(bool save_children = true) const;
@@ -372,7 +89,7 @@ public:
void deleteAllItems() { clearRows(); }
// Sets an array of column descriptors
void setColumnHeadings(LLSD headings);
void setColumnHeadings(const LLSD& headings);
void sortByColumnIndex(U32 column, BOOL ascending);
// LLCtrlListInterface functions
@@ -381,7 +98,6 @@ public:
virtual void addColumn(const LLSD& column, EAddPosition pos = ADD_BOTTOM);
virtual void clearColumns();
virtual void setColumnLabel(const std::string& column, const std::string& label);
virtual LLScrollListColumn* getColumn(S32 index);
virtual LLScrollListColumn* getColumn(const std::string& name);
virtual S32 getNumColumns() const { return mColumnsIndexed.size(); }
@@ -389,7 +105,7 @@ public:
// Adds a single element, from an array of:
// "columns" => [ "column" => column name, "value" => value, "type" => type, "font" => font, "font-style" => style ], "id" => uuid
// Creates missing columns automatically.
virtual LLScrollListItem* addElement(const LLSD& value, EAddPosition pos = ADD_BOTTOM, void* userdata = NULL);
virtual LLScrollListItem* addElement(const LLSD& element, EAddPosition pos = ADD_BOTTOM, void* userdata = NULL);
// Simple add element. Takes a single array of:
// [ "value" => value, "font" => font, "font-style" => style ]
virtual void clearRows(); // clears all elements
@@ -441,8 +157,8 @@ public:
S32 getHighlightedItemInx() const { return mHighlightedItem; }
void setDoubleClickCallback( callback_t cb ) { mOnDoubleClickCallback = cb; }
void setMaximumSelectCallback( callback_t cb ) { mOnMaximumSelectCallback = cb; }
void setSortChangedCallback( callback_t cb ) { mOnSortChangedCallback = cb; }
void setMaximumSelectCallback( callback_t cb) { mOnMaximumSelectCallback = cb; }
void setSortChangedCallback( callback_t cb) { mOnSortChangedCallback = cb; }
// Convenience function; *TODO: replace with setter above + boost::bind() in calling code
void setDoubleClickCallback( boost::function<void (void* userdata)> cb, void* userdata) { mOnDoubleClickCallback = boost::bind(cb, userdata); }
@@ -463,7 +179,6 @@ public:
// one of which can be selected at a time.
virtual LLScrollListItem* addSimpleElement(const std::string& value, EAddPosition pos = ADD_BOTTOM, const LLSD& id = LLSD());
BOOL selectItemByLabel( const std::string& item, BOOL case_sensitive = TRUE ); // FALSE if item not found
BOOL selectItemByPrefix(const std::string& target, BOOL case_sensitive = TRUE);
BOOL selectItemByPrefix(const LLWString& target, BOOL case_sensitive = TRUE);
@@ -499,7 +214,7 @@ public:
void setBgStripeColor(const LLColor4& c) { mBgStripeColor = c; }
void setFgSelectedColor(const LLColor4 &c) { mFgSelectedColor = c; }
void setFgUnselectedColor(const LLColor4 &c){ mFgUnselectedColor = c; }
void setHighlightedColor(const LLColor4 &c) { mHighlightedColor = c; }
void setHighlightedColor(const LLColor4 &c) { mHighlightedColor = c; }
void setFgDisableColor(const LLColor4 &c) { mFgDisabledColor = c; }
void setBackgroundVisible(BOOL b) { mBackgroundVisible = b; }
@@ -516,11 +231,11 @@ public:
virtual S32 getScrollPos() const;
virtual void setScrollPos( S32 pos );
// <edit>
S32 getPageLines() { return mPageLines; }
// </edit>
S32 getSearchColumn();
void setSearchColumn(S32 column) { mSearchColumn = column; }
S32 getColumnIndexFromOffset(S32 x);
@@ -560,7 +275,7 @@ public:
LLRect getCellRect(S32 row_index, S32 column_index);
// Used "internally" by the scroll bar.
void onScrollChange( S32 new_pos, LLScrollbar* src);
void onScrollChange( S32 new_pos, LLScrollbar* src );
static void onClickColumn(void *userdata);
@@ -628,6 +343,7 @@ public:
return mSortCallback->connect(cb);
}
protected:
// "Full" interface: use this when you're creating a list that has one or more of the following:
// * contains icons
@@ -741,5 +457,4 @@ private:
sort_signal_t* mSortCallback;
}; // end class LLScrollListCtrl
#endif // LL_SCROLLLISTCTRL_H

View File

@@ -0,0 +1,147 @@
/**
* @file llscrolllistitem.cpp
* @brief Scroll lists are composed of rows (items), each of which
* contains columns (cells).
*
* $LicenseInfo:firstyear=2001&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, 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 "llscrolllistitem.h"
//---------------------------------------------------------------------------
// LLScrollListItem
//---------------------------------------------------------------------------
LLScrollListItem::LLScrollListItem( bool enabled, const LLSD& value, void* userdata )
: mSelected(FALSE),
mEnabled(enabled),
mUserdata(userdata),
mItemValue(value),
mColumns()
{
}
LLScrollListItem::~LLScrollListItem()
{
std::for_each(mColumns.begin(), mColumns.end(), DeletePointer());
}
void LLScrollListItem::addColumn(const std::string& text, const LLFontGL* font, S32 width, U8 font_style, LLFontGL::HAlign font_alignment, bool visible)
{
mColumns.push_back(new LLScrollListText(text, font, width, font_style, font_alignment, LLColor4::black, false, visible));
}
void LLScrollListItem::setNumColumns(S32 columns)
{
S32 prev_columns = mColumns.size();
if (columns < prev_columns)
{
std::for_each(mColumns.begin()+columns, mColumns.end(), DeletePointer());
}
mColumns.resize(columns);
for (S32 col = prev_columns; col < columns; ++col)
{
mColumns[col] = NULL;
}
}
void LLScrollListItem::setColumn( S32 column, LLScrollListCell *cell )
{
if (column < (S32)mColumns.size())
{
delete mColumns[column];
mColumns[column] = cell;
}
else
{
llerrs << "LLScrollListItem::setColumn: bad column: " << column << llendl;
}
}
S32 LLScrollListItem::getNumColumns() const
{
return mColumns.size();
}
LLScrollListCell* LLScrollListItem::getColumn(const S32 i) const
{
if (0 <= i && i < (S32)mColumns.size())
{
return mColumns[i];
}
return NULL;
}
std::string LLScrollListItem::getContentsCSV() const
{
std::string ret;
S32 count = getNumColumns();
for (S32 i=0; i<count; ++i)
{
ret += getColumn(i)->getValue().asString();
if (i < count-1)
{
ret += ", ";
}
}
return ret;
}
void LLScrollListItem::draw(const LLRect& rect, const LLColor4& fg_color, const LLColor4& bg_color, const LLColor4& highlight_color, S32 column_padding)
{
// draw background rect
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
LLRect bg_rect = rect;
gl_rect_2d( bg_rect, bg_color );
S32 cur_x = rect.mLeft;
S32 num_cols = getNumColumns();
S32 cur_col = 0;
for (LLScrollListCell* cell = getColumn(0); cur_col < num_cols; cell = getColumn(++cur_col))
{
// Two ways a cell could be hidden
if (cell->getWidth() < 0
|| !cell->getVisible()) continue;
LLUI::pushMatrix();
{
LLUI::translate((F32) cur_x, (F32) rect.mBottom);
cell->draw( fg_color, highlight_color );
}
LLUI::popMatrix();
cur_x += cell->getWidth() + column_padding;
}
}

View File

@@ -0,0 +1,92 @@
/**
* @file llscrolllistitem.h
* @brief Scroll lists are composed of rows (items), each of which
* contains columns (cells).
*
* $LicenseInfo:firstyear=2007&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, 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 LLSCROLLLISTITEM_H
#define LLSCROLLLISTITEM_H
#include "llrefcount.h"
#include "llhandle.h"
#include "llsd.h"
#include "llscrolllistcell.h"
//---------------------------------------------------------------------------
// LLScrollListItem
//---------------------------------------------------------------------------
class LLScrollListItem
: public LLHandleProvider<LLScrollListItem> // Singu TODO: Break out into LLNameListItem
{
friend class LLScrollListCtrl;
public:
virtual ~LLScrollListItem();
void setSelected( BOOL b ) { mSelected = b; }
BOOL getSelected() const { return mSelected; }
void setEnabled( BOOL b ) { mEnabled = b; }
BOOL getEnabled() const { return mEnabled; }
void setUserdata( void* userdata ) { mUserdata = userdata; }
void* getUserdata() const { return mUserdata; }
void setToolTip(const std::string tool_tip) { mToolTip=tool_tip; }
std::string getToolTip() { return mToolTip; }
virtual LLUUID getUUID() const { return mItemValue.asUUID(); }
LLSD getValue() const { return mItemValue; }
void setRect(LLRect rect) { mRectangle = rect; }
LLRect getRect() const { return mRectangle; }
void addColumn( const std::string& text, const LLFontGL* font, S32 width = 0, U8 font_style = LLFontGL::NORMAL, LLFontGL::HAlign font_alignment = LLFontGL::LEFT, bool visible = true );
void setNumColumns(S32 columns);
void setColumn( S32 column, LLScrollListCell *cell );
S32 getNumColumns() const;
LLScrollListCell *getColumn(const S32 i) const;
std::string getContentsCSV() const;
virtual void draw(const LLRect& rect, const LLColor4& fg_color, const LLColor4& bg_color, const LLColor4& highlight_color, S32 column_padding);
protected:
LLScrollListItem( bool enabled = true, const LLSD& value = LLSD(), void* userdata = NULL );
private:
BOOL mSelected;
BOOL mEnabled;
void* mUserdata;
LLSD mItemValue;
std::string mToolTip;
std::vector<LLScrollListCell *> mColumns;
LLRect mRectangle;
};
#endif