PageRenderTime 10ms CodeModel.GetById 2ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llui/llscrolllistcolumn.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 172 lines | 111 code | 26 blank | 35 comment | 0 complexity | 4b2992e013fd3684ed961c09fe875315 MD5 | raw file
  1/** 
  2 * @file llscrollcolumnheader.h
  3 * @brief Scroll lists are composed of rows (items), each of which 
  4 * contains columns (cells).
  5 *
  6 * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  7 * Second Life Viewer Source Code
  8 * Copyright (C) 2010, Linden Research, Inc.
  9 * 
 10 * This library is free software; you can redistribute it and/or
 11 * modify it under the terms of the GNU Lesser General Public
 12 * License as published by the Free Software Foundation;
 13 * version 2.1 of the License only.
 14 * 
 15 * This library is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 18 * Lesser General Public License for more details.
 19 * 
 20 * You should have received a copy of the GNU Lesser General Public
 21 * License along with this library; if not, write to the Free Software
 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 23 * 
 24 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 25 * $/LicenseInfo$
 26 */
 27
 28#ifndef LLSCROLLLISTCOLUMN_H
 29#define LLSCROLLLISTCOLUMN_H
 30
 31#include "llrect.h"
 32#include "lluistring.h"
 33#include "llbutton.h"
 34#include "llinitparam.h"
 35
 36class LLScrollListColumn;
 37class LLResizeBar;
 38class LLScrollListCtrl;
 39
 40class LLScrollColumnHeader : public LLButton
 41{
 42public:
 43	struct Params : public LLInitParam::Block<Params, LLButton::Params>
 44	{
 45		Mandatory<LLScrollListColumn*> column;
 46
 47		Params();
 48	};
 49	LLScrollColumnHeader(const Params&);
 50	~LLScrollColumnHeader();
 51
 52	/*virtual*/ void draw();
 53	/*virtual*/ BOOL handleDoubleClick(S32 x, S32 y, MASK mask);
 54
 55	/*virtual*/ LLView*	findSnapEdge(S32& new_edge_val, const LLCoordGL& mouse_dir, ESnapEdge snap_edge, ESnapType snap_type, S32 threshold, S32 padding);
 56	/*virtual*/ void handleReshape(const LLRect& new_rect, bool by_user = false);
 57	
 58	LLScrollListColumn* getColumn() { return mColumn; }
 59	void setHasResizableElement(BOOL resizable);
 60	void updateResizeBars();
 61	BOOL canResize();
 62	void enableResizeBar(BOOL enable);
 63
 64	void onClick(const LLSD& data);
 65
 66private:
 67	LLScrollListColumn* mColumn;
 68	LLResizeBar*		mResizeBar;
 69	BOOL				mHasResizableElement;
 70};
 71
 72/*
 73 * A simple data class describing a column within a scroll list.
 74 */
 75class LLScrollListColumn
 76{
 77public:
 78	typedef enum e_sort_direction
 79	{
 80		DESCENDING,
 81		ASCENDING
 82	} ESortDirection;
 83
 84	struct SortNames
 85	:	public LLInitParam::TypeValuesHelper<LLScrollListColumn::ESortDirection, SortNames>
 86	{
 87		static void declareValues();
 88	};
 89
 90	struct Params : public LLInitParam::Block<Params>
 91	{
 92		Optional<std::string>				name,
 93											tool_tip;
 94		Optional<std::string>				sort_column;
 95		Optional<ESortDirection, SortNames>	sort_direction;
 96		Optional<bool>						sort_ascending;
 97
 98		struct Width : public LLInitParam::ChoiceBlock<Width>
 99		{
100			Alternative<bool>	dynamic_width;
101			Alternative<S32>		pixel_width;
102			Alternative<F32>		relative_width;
103
104			Width()
105			:	dynamic_width("dynamic_width", false),
106				pixel_width("width"),
107				relative_width("relative_width", -1.f)
108			{
109				addSynonym(relative_width, "relwidth");
110			}
111		};
112		Optional<Width>						width;
113
114		// either an image or label is used in column header
115		struct Header : public LLInitParam::ChoiceBlock<Header>
116		{
117			Alternative<std::string>			label;
118			Alternative<LLUIImage*>			image;
119
120			Header()
121			:	label("label"),
122				image("image")
123			{}
124		};
125		Optional<Header>					header;
126
127		Optional<LLFontGL::HAlign>			halign;
128
129		Params()
130		:	name("name"),
131			tool_tip("tool_tip"),
132			sort_column("sort_column"),
133			sort_direction("sort_direction"),
134			sort_ascending("sort_ascending", true),
135			halign("halign", LLFontGL::LEFT)
136		{
137			// default choice to "dynamic_width"
138			changeDefault(width.dynamic_width, true);
139
140			addSynonym(sort_column, "sort");
141		}
142	};
143
144	static const Params& getDefaultParams();
145
146	//NOTE: this is default constructible so we can store it in a map.
147	LLScrollListColumn(const Params& p = getDefaultParams(), LLScrollListCtrl* = NULL);
148
149	void setWidth(S32 width);
150	S32 getWidth() const { return mWidth; }
151
152public:
153	// Public data is fine so long as this remains a simple struct-like data class.
154	// If it ever gets any smarter than that, these should all become private
155	// with protected or public accessor methods added as needed. -MG
156	std::string				mName;
157	std::string				mSortingColumn;
158	ESortDirection			mSortDirection;
159	LLUIString				mLabel;
160	F32						mRelWidth;
161	BOOL					mDynamicWidth;
162	S32						mMaxContentWidth;
163	S32						mIndex;
164	LLScrollListCtrl*		mParentCtrl;
165	LLScrollColumnHeader*	mHeader;
166	LLFontGL::HAlign		mFontAlignment;
167
168private:
169	S32						mWidth;
170};
171
172#endif