summaryrefslogtreecommitdiff
path: root/include/svtools/svlbitm.hxx
blob: a5e2ee29d85550baa6d885f865f34d1e4b057620 (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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */


#ifndef INCLUDED_SVTOOLS_SVLBITM_HXX
#define INCLUDED_SVTOOLS_SVLBITM_HXX

#include <svtools/svtdllapi.h>
#include <tools/link.hxx>
#include <vcl/image.hxx>
#include <svtools/treelistbox.hxx>
#include <o3tl/typed_flags_set.hxx>

class SvTreeListEntry;


enum class SvBmp
{
    UNCHECKED        = 0,
    CHECKED          = 1,
    TRISTATE         = 2,
    HIUNCHECKED      = 3,
    HICHECKED        = 4,
    HITRISTATE       = 5,
    STATICIMAGE      = 6
};

enum class SvItemStateFlags
{
    NONE               = 0x00,
    UNCHECKED          = 0x01,
    CHECKED            = 0x02,
    TRISTATE           = 0x04,
    HILIGHTED          = 0x08
};
namespace o3tl
{
    template<> struct typed_flags<SvItemStateFlags> : is_typed_flags<SvItemStateFlags, 0x0f> {};
}

struct SvLBoxButtonData_Impl;

class SVT_DLLPUBLIC SvLBoxButtonData
{
private:
    Link<>                  aLink;
    long                    nWidth;
    long                    nHeight;
    SvLBoxButtonData_Impl*  pImpl;
    bool                    bDataOk;
    SvButtonState           eState;
    std::vector<Image>      aBmps;  // indices s. constants BMP_ ....

    SVT_DLLPRIVATE void     SetWidthAndHeight();
    SVT_DLLPRIVATE void     InitData( bool bImagesFromDefault,
                                      bool _bRadioBtn, const Control* pControlForSettings = NULL );
public:
                            // include creating default images (CheckBox or RadioButton)
                            SvLBoxButtonData( const Control* pControlForSettings );
                            SvLBoxButtonData( const Control* pControlForSettings, bool _bRadioBtn );

                            ~SvLBoxButtonData();

    static SvBmp            GetIndex( SvItemStateFlags nItemState );
    long                    Width();
    long                    Height();
    void                    SetLink( const Link<>& rLink) { aLink=rLink; }
    const Link<>&           GetLink() const { return aLink; }
    bool                    IsRadio();
    // as buttons are not derived from LinkHdl
    void                    CallLink();

    void                    StoreButtonState( SvTreeListEntry* pEntry, SvItemStateFlags nItemFlags );
    static SvButtonState    ConvertToButtonState( SvItemStateFlags nItemFlags );

    SvButtonState           GetActButtonState() const { return eState; }

    SvTreeListEntry*        GetActEntry() const;

    void                    SetImage(SvBmp nIndex, const Image& aImage) { aBmps[(int)nIndex] = aImage; }
    Image&                  GetImage(SvBmp nIndex) { return aBmps[(int)nIndex]; }

    void                    SetDefaultImages( const Control* pControlForSettings = NULL );
                                // set images according to the color scheeme of the Control
                                // pControlForSettings == NULL: settings are taken from Application
    bool                    HasDefaultImages() const;
};

// **********************************************************************

class SVT_DLLPUBLIC SvLBoxString : public SvLBoxItem
{
protected:
    OUString maText;

public:
    SvLBoxString(SvTreeListEntry*, sal_uInt16 nFlags, const OUString& rText);
    SvLBoxString();
    virtual ~SvLBoxString();

    virtual sal_uInt16 GetType() const SAL_OVERRIDE;
    virtual void InitViewData(SvTreeListBox* pView,
                              SvTreeListEntry* pEntry,
                              SvViewDataItem* pViewData) SAL_OVERRIDE;

    OUString GetText() const
    {
        return maText;
    }
    void SetText(const OUString& rText)
    {
        maText = rText;
    }

    virtual void Paint(const Point& rPos,
                       SvTreeListBox& rOutDev,
                       const SvViewDataEntry* pView,
                       const SvTreeListEntry* pEntry) SAL_OVERRIDE;

    virtual SvLBoxItem* Create() const SAL_OVERRIDE;
    virtual void Clone(SvLBoxItem* pSource) SAL_OVERRIDE;
};

class SvLBoxBmp : public SvLBoxItem
{
    Image aBmp;
public:
                    SvLBoxBmp();
    virtual         ~SvLBoxBmp();
    virtual sal_uInt16 GetType() const SAL_OVERRIDE;
    virtual void    InitViewData( SvTreeListBox*,SvTreeListEntry*,SvViewDataItem* ) SAL_OVERRIDE;
    virtual void Paint(
        const Point& rPos, SvTreeListBox& rOutDev, const SvViewDataEntry* pView, const SvTreeListEntry* pEntry) SAL_OVERRIDE;
    virtual SvLBoxItem* Create() const SAL_OVERRIDE;
    virtual void    Clone( SvLBoxItem* pSource ) SAL_OVERRIDE;
};


class SVT_DLLPUBLIC SvLBoxButton : public SvLBoxItem
{
    bool    isVis;
    SvLBoxButtonData*   pData;
    SvLBoxButtonKind eKind;
    SvItemStateFlags nItemFlags;

    static void ImplAdjustBoxSize( Size& io_rCtrlSize, ControlType i_eType, vcl::Window* pParent );
public:
    // An SvLBoxButton can be of three different kinds: an
    // enabled checkbox (the normal kind), a disabled checkbox
    // (which cannot be modified via UI), or a static image
    // (see SV_BMP_STATICIMAGE; nFlags are effectively ignored
    // for that kind).
    SvLBoxButton( SvTreeListEntry* pEntry,
                  SvLBoxButtonKind eTheKind, sal_uInt16 nFlags,
                  SvLBoxButtonData* pBData );
    SvLBoxButton();
    virtual ~SvLBoxButton();
    virtual void InitViewData(SvTreeListBox* pView,
                              SvTreeListEntry* pEntry,
                              SvViewDataItem* pViewData) SAL_OVERRIDE;

    virtual sal_uInt16 GetType() const SAL_OVERRIDE;
    bool ClickHdl(SvTreeListBox* pView, SvTreeListEntry* );

    virtual void Paint(const Point& rPos,
                       SvTreeListBox& rOutDev,
                       const SvViewDataEntry* pView,
                       const SvTreeListEntry* pEntry) SAL_OVERRIDE;

    virtual SvLBoxItem* Create() const SAL_OVERRIDE;

    virtual void Clone(SvLBoxItem* pSource) SAL_OVERRIDE;
    SvItemStateFlags GetButtonFlags() const
    {
        return nItemFlags;
    }
    bool IsStateChecked() const
    {
        return bool(nItemFlags & SvItemStateFlags::CHECKED);
    }
    bool IsStateUnchecked() const
    {
        return bool(nItemFlags & SvItemStateFlags::UNCHECKED);
    }
    bool IsStateTristate() const
    {
        return bool(nItemFlags & SvItemStateFlags::TRISTATE);
    }
    bool IsStateHilighted() const
    {
        return bool(nItemFlags & SvItemStateFlags::HILIGHTED);
    }
    void SetStateChecked();
    void SetStateUnchecked();
    void SetStateTristate();
    void SetStateHilighted(bool bHilight);
    void SetStateInvisible();

    SvLBoxButtonKind GetKind() const { return eKind; }

    // Check whether this button can be modified via UI
    bool CheckModification() const;
    SvLBoxButtonData* GetButtonData() const
    {
        return pData;
    }
};

inline void SvLBoxButton::SetStateChecked()
{
    nItemFlags &= SvItemStateFlags::HILIGHTED;
    nItemFlags |= SvItemStateFlags::CHECKED;
}

inline void SvLBoxButton::SetStateUnchecked()
{
    nItemFlags &= SvItemStateFlags::HILIGHTED;
    nItemFlags |= SvItemStateFlags::UNCHECKED;
}
inline void SvLBoxButton::SetStateTristate()
{
    nItemFlags &= SvItemStateFlags::HILIGHTED;
    nItemFlags |= SvItemStateFlags::TRISTATE;
}
inline void SvLBoxButton::SetStateHilighted( bool bHilight )
{
    if ( bHilight )
        nItemFlags |= SvItemStateFlags::HILIGHTED;
    else
        nItemFlags &= ~SvItemStateFlags::HILIGHTED;
}

struct SvLBoxContextBmp_Impl;

class SVT_DLLPUBLIC SvLBoxContextBmp : public SvLBoxItem
{
    SvLBoxContextBmp_Impl*  m_pImpl;
public:
    SvLBoxContextBmp(SvTreeListEntry* pEntry,
                     sal_uInt16 nItemFlags,
                     Image aBmp1,
                     Image aBmp2,
                     bool bExpanded);
    SvLBoxContextBmp();
    virtual ~SvLBoxContextBmp();

    virtual sal_uInt16 GetType() const SAL_OVERRIDE;
    virtual void InitViewData(SvTreeListBox* pView,
                              SvTreeListEntry* pEntry,
                              SvViewDataItem* pViewData) SAL_OVERRIDE;
    virtual void Paint(const Point& rPos,
                       SvTreeListBox& rOutDev,
                       const SvViewDataEntry* pView,
                       const SvTreeListEntry* pEntry) SAL_OVERRIDE;

    virtual SvLBoxItem* Create() const SAL_OVERRIDE;
    virtual void Clone(SvLBoxItem* pSource) SAL_OVERRIDE;


    bool SetModeImages(const Image& rBitmap1, const Image& rBitmap2);
    void  GetModeImages(Image& rBitmap1, Image& rBitmap2) const;

    inline void SetBitmap1(const Image& rImage);
    inline void SetBitmap2(const Image& rImage);
    inline const Image& GetBitmap1() const;
    inline const Image& GetBitmap2() const;

private:
    Image& implGetImageStore(bool bFirst);
};

inline void SvLBoxContextBmp::SetBitmap1(const Image& _rImage)
{
    implGetImageStore(true) = _rImage;
}

inline void SvLBoxContextBmp::SetBitmap2(const Image& _rImage)
{
    implGetImageStore(false) = _rImage;
}

inline const Image& SvLBoxContextBmp::GetBitmap1() const
{
    Image& rImage = const_cast<SvLBoxContextBmp*>(this)->implGetImageStore(true);
    return rImage;
}

inline const Image& SvLBoxContextBmp::GetBitmap2() const
{
    Image& rImage = const_cast<SvLBoxContextBmp*>(this)->implGetImageStore(false);
    return rImage;
}

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */