summaryrefslogtreecommitdiff
path: root/indra/llui/llscrolllistcell.h
blob: e7ff5c8424ccb3b5faecc513e28caa87e3832fca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/**
 * @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 "llfontvertexbuffer.h"       // HAlign
#include "llpointer.h"      // LLPointer<>
#include "lluistring.h"
#include "v4color.h"
#include "llui.h"
#include "llgltexture.h"

class LLCheckBoxCtrl;
class LLSD;
class LLUIImage;

/*
 * 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:
    struct Params : public LLInitParam::Block<Params>
    {
        Optional<std::string>       type,
                                    column;

        Optional<S32>               width;
        Optional<bool>              enabled,
                                    visible;

        Optional<void*>             userdata;
        Optional<LLSD>              value; // state of checkbox, icon id/name, date
        Optional<LLSD>              alt_value;
        Optional<std::string>       label; // description or text
        Optional<std::string>       tool_tip;

        Optional<const LLFontGL*>   font;
        Optional<LLColor4>          font_color;
        Optional<LLFontGL::HAlign>  font_halign;

        Optional<LLColor4>          color;

        Params()
        :   type("type", "text"),
            column("column"),
            width("width"),
            enabled("enabled", true),
            visible("visible", true),
            value("value"),
            alt_value("alt_value", ""),
            label("label"),
            tool_tip("tool_tip", ""),
            font("font", LLFontGL::getFontEmojiSmall()),
            font_color("font_color", LLColor4::black),
            color("color", LLColor4::white),
            font_halign("halign", LLFontGL::LEFT)
        {
            addSynonym(column, "name");
            addSynonym(font_color, "font-color");
        }
    };

    static LLScrollListCell* create(const Params&);

    LLScrollListCell(const LLScrollListCell::Params&);
    virtual ~LLScrollListCell() {};

    virtual void            draw(const LLColor4& color, const LLColor4& highlight_color) {};      // 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 const LLSD      getAltValue() const;
    virtual void            setValue(const LLSD& value) { }
    virtual void            setAltValue(const LLSD& value) { }
    virtual const std::string &getToolTip() const { return mToolTip; }
    virtual void            setToolTip(const std::string &str) { mToolTip = str; }
    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 bool            needsToolTip() const { return ! mToolTip.empty(); }
    virtual void            setColor(const LLColor4&) {}
    virtual void            onCommit() {};

    virtual bool            handleClick() { return false; }
    virtual void            setEnabled(bool enable) { }

private:
    S32 mWidth;
    std::string mToolTip;
};

class LLScrollListSpacer : public LLScrollListCell
{
public:
    LLScrollListSpacer(const LLScrollListCell::Params& p) : LLScrollListCell(p) {}
    /*virtual*/ ~LLScrollListSpacer() {};
    /*virtual*/ void            draw(const LLColor4& color, const LLColor4& highlight_color) {}
};

/*
 * Cell displaying a text label.
 */
class LLScrollListText : public LLScrollListCell
{
public:
    LLScrollListText(const LLScrollListCell::Params&);
    /*virtual*/ ~LLScrollListText();

    /*virtual*/ void    draw(const LLColor4& color, const LLColor4& highlight_color);
    /*virtual*/ S32     getContentWidth() const;
    /*virtual*/ S32     getHeight() const;
    /*virtual*/ void    setValue(const LLSD& value);
    /*virtual*/ void    setAltValue(const LLSD& value);
    /*virtual*/ const LLSD getValue() const;
    /*virtual*/ const LLSD getAltValue() const;
    /*virtual*/ bool    getVisible() const;
    /*virtual*/ void    highlightText(S32 offset, S32 num_chars);

    /*virtual*/ void    setColor(const LLColor4&);
    /*virtual*/ bool    isText() const;
    /*virtual*/ const std::string & getToolTip() const;
    /*virtual*/ bool    needsToolTip() const;

    S32             getTextWidth() const { return mTextWidth;}
    void            setTextWidth(S32 value);
    virtual void    setWidth(S32 width);

    void            setText(const LLStringExplicit& text);
    void            setFontStyle(const U8 font_style);
    void            setAlignment(LLFontGL::HAlign align);

protected:

    LLUIString      mText;
    LLUIString      mAltText;
    S32             mTextWidth;
    const LLFontGL* mFont;
    LLFontVertexBuffer mFontBuffer;
    LLColor4        mColor;
    LLColor4        mHighlightColor;
    U8              mUseColor;
    LLFontGL::HAlign mFontAlignment;
    bool            mVisible;
    S32             mHighlightCount;
    S32             mHighlightOffset;

    LLPointer<LLUIImage> mRoundedRectImage;

    static U32 sCount;
};

/*
 * Cell displaying an image. AT the moment, this is specifically UI image
 */
class LLScrollListIcon : public LLScrollListCell
{
public:
    LLScrollListIcon(const LLScrollListCell::Params& p);
    /*virtual*/ ~LLScrollListIcon();
    /*virtual*/ void    draw(const LLColor4& color, const LLColor4& highlight_color);
    /*virtual*/ S32     getWidth() const;
    /*virtual*/ S32     getHeight() const;
    /*virtual*/ const LLSD      getValue() const;
    /*virtual*/ void    setColor(const LLColor4&);
    /*virtual*/ void    setValue(const LLSD& value);

private:
    LLPointer<LLUIImage>    mIcon;
    LLColor4                mColor;
    LLFontGL::HAlign        mAlignment;
};


class LLScrollListBar : public LLScrollListCell
{
public:
    LLScrollListBar(const LLScrollListCell::Params& p);
    /*virtual*/ ~LLScrollListBar();
    /*virtual*/ void    draw(const LLColor4& color, const LLColor4& highlight_color);
    /*virtual*/ S32     getWidth() const;
    /*virtual*/ S32     getHeight() const;
    /*virtual*/ const LLSD      getValue() const;
    /*virtual*/ void    setColor(const LLColor4&);
    /*virtual*/ void    setValue(const LLSD& value);

private:
    LLColor4                    mColor;
    F32                         mRatio;
    S32                         mBottom;
    S32                         mRightPad;
    S32                         mLeftPad;
};
/*
 * An interactive cell containing a check box.
 */
class LLScrollListCheck : public LLScrollListCell
{
public:
    LLScrollListCheck( const LLScrollListCell::Params&);
    /*virtual*/ ~LLScrollListCheck();
    /*virtual*/ void    draw(const LLColor4& color, const LLColor4& highlight_color);
    /*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 LLScrollListCell::Params& p );
    virtual void    setValue(const LLSD& value);
    virtual const LLSD getValue() const;

private:
    LLDate      mDate;
};

/*
* Cell displaying icon and text.
*/

class LLScrollListIconText : public LLScrollListText
{
public:
    LLScrollListIconText(const LLScrollListCell::Params& p);
    /*virtual*/ ~LLScrollListIconText();
    /*virtual*/ void    draw(const LLColor4& color, const LLColor4& highlight_color);
    /*virtual*/ const LLSD      getValue() const;
    /*virtual*/ void    setValue(const LLSD& value);

    /*virtual*/ void    setWidth(S32 width);

private:
    LLPointer<LLUIImage>    mIcon;
    S32                     mPad;
};

#endif