Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #ifndef INCLUDED_SVTOOLS_SVLBITM_HXX
22 : #define INCLUDED_SVTOOLS_SVLBITM_HXX
23 :
24 : #include <svtools/svtdllapi.h>
25 :
26 : #include <tools/link.hxx>
27 :
28 : #include <vcl/image.hxx>
29 : #include <svtools/treelistbox.hxx>
30 :
31 : class SvTreeListEntry;
32 :
33 :
34 : #define SV_BMP_UNCHECKED 0
35 : #define SV_BMP_CHECKED 1
36 : #define SV_BMP_TRISTATE 2
37 : #define SV_BMP_HIUNCHECKED 3
38 : #define SV_BMP_HICHECKED 4
39 : #define SV_BMP_HITRISTATE 5
40 : #define SV_BMP_STATICIMAGE 6
41 :
42 : struct SvLBoxButtonData_Impl;
43 :
44 : class SVT_DLLPUBLIC SvLBoxButtonData
45 : {
46 : private:
47 : Link aLink;
48 : long nWidth;
49 : long nHeight;
50 : SvLBoxButtonData_Impl* pImpl;
51 : bool bDataOk;
52 : SvButtonState eState;
53 :
54 : SVT_DLLPRIVATE void SetWidthAndHeight();
55 : SVT_DLLPRIVATE void InitData( bool bImagesFromDefault,
56 : bool _bRadioBtn, const Control* pControlForSettings = NULL );
57 : public:
58 : // include creating default images (CheckBox or RadioButton)
59 : SvLBoxButtonData( const Control* pControlForSettings );
60 : SvLBoxButtonData( const Control* pControlForSettings, bool _bRadioBtn );
61 :
62 : ~SvLBoxButtonData();
63 :
64 : sal_uInt16 GetIndex( sal_uInt16 nItemState );
65 : long Width();
66 : long Height();
67 0 : void SetLink( const Link& rLink) { aLink=rLink; }
68 : const Link& GetLink() const { return aLink; }
69 : bool IsRadio();
70 : // weil Buttons nicht von LinkHdl abgeleitet sind
71 : void CallLink();
72 :
73 : void StoreButtonState( SvTreeListEntry* pEntry, sal_uInt16 nItemFlags );
74 : SvButtonState ConvertToButtonState( sal_uInt16 nItemFlags ) const;
75 :
76 : SvButtonState GetActButtonState() const
77 : {
78 : return eState;
79 : }
80 :
81 : SvTreeListEntry* GetActEntry() const;
82 :
83 : Image aBmps[24]; // Indizes siehe Konstanten BMP_ ....
84 :
85 : void SetDefaultImages( const Control* pControlForSettings = NULL );
86 : // set images acording to the color scheeme of the Control
87 : // pControlForSettings == NULL: settings are taken from Application
88 : bool HasDefaultImages( void ) const;
89 : };
90 :
91 : // **********************************************************************
92 :
93 : class SVT_DLLPUBLIC SvLBoxString : public SvLBoxItem
94 : {
95 : protected:
96 : OUString maText;
97 : public:
98 : SvLBoxString(SvTreeListEntry*, sal_uInt16 nFlags, const OUString& rStr);
99 : SvLBoxString();
100 : virtual ~SvLBoxString();
101 : virtual sal_uInt16 GetType() const SAL_OVERRIDE;
102 : virtual void InitViewData(SvTreeListBox*, SvTreeListEntry*, SvViewDataItem*) SAL_OVERRIDE;
103 0 : OUString GetText() const { return maText; }
104 0 : virtual OUString GetExtendText() const { return OUString(); }
105 0 : void SetText( const OUString& rText ) { maText = rText; }
106 :
107 : virtual void Paint(
108 : const Point& rPos, SvTreeListBox& rOutDev, const SvViewDataEntry* pView, const SvTreeListEntry* pEntry) SAL_OVERRIDE;
109 :
110 : virtual SvLBoxItem* Create() const SAL_OVERRIDE;
111 : virtual void Clone( SvLBoxItem* pSource ) SAL_OVERRIDE;
112 : };
113 :
114 : class SvLBoxBmp : public SvLBoxItem
115 : {
116 : Image aBmp;
117 : public:
118 : SvLBoxBmp();
119 : virtual ~SvLBoxBmp();
120 : virtual sal_uInt16 GetType() const SAL_OVERRIDE;
121 : virtual void InitViewData( SvTreeListBox*,SvTreeListEntry*,SvViewDataItem* ) SAL_OVERRIDE;
122 : virtual void Paint(
123 : const Point& rPos, SvTreeListBox& rOutDev, const SvViewDataEntry* pView, const SvTreeListEntry* pEntry) SAL_OVERRIDE;
124 : virtual SvLBoxItem* Create() const SAL_OVERRIDE;
125 : virtual void Clone( SvLBoxItem* pSource ) SAL_OVERRIDE;
126 : };
127 :
128 :
129 : #define SV_ITEMSTATE_UNCHECKED 0x0001
130 : #define SV_ITEMSTATE_CHECKED 0x0002
131 : #define SV_ITEMSTATE_TRISTATE 0x0004
132 : #define SV_ITEMSTATE_HILIGHTED 0x0008
133 : #define SV_STATE_MASK 0xFFF8 // zum Loeschen von UNCHECKED,CHECKED,TRISTATE
134 :
135 : class SVT_DLLPUBLIC SvLBoxButton : public SvLBoxItem
136 : {
137 : bool isVis;
138 : SvLBoxButtonData* pData;
139 : SvLBoxButtonKind eKind;
140 : sal_uInt16 nItemFlags;
141 : sal_uInt16 nBaseOffs;
142 :
143 : void ImplAdjustBoxSize( Size& io_rCtrlSize, ControlType i_eType, Window* pParent );
144 : public:
145 : // An SvLBoxButton can be of three different kinds: an
146 : // enabled checkbox (the normal kind), a disabled checkbox
147 : // (which cannot be modified via UI), or a static image
148 : // (see SV_BMP_STATICIMAGE; nFlags are effectively ignored
149 : // for that kind).
150 : SvLBoxButton( SvTreeListEntry* pEntry,
151 : SvLBoxButtonKind eTheKind, sal_uInt16 nFlags,
152 : SvLBoxButtonData* pBData );
153 : SvLBoxButton();
154 : virtual ~SvLBoxButton();
155 : virtual void InitViewData( SvTreeListBox*,SvTreeListEntry*,SvViewDataItem* ) SAL_OVERRIDE;
156 : virtual sal_uInt16 GetType() const SAL_OVERRIDE;
157 : virtual bool ClickHdl(SvTreeListBox* pView, SvTreeListEntry* );
158 : virtual void Paint(
159 : const Point& rPos, SvTreeListBox& rOutDev, const SvViewDataEntry* pView, const SvTreeListEntry* pEntry) SAL_OVERRIDE;
160 : virtual SvLBoxItem* Create() const SAL_OVERRIDE;
161 : virtual void Clone( SvLBoxItem* pSource ) SAL_OVERRIDE;
162 0 : sal_uInt16 GetButtonFlags() const { return nItemFlags; }
163 0 : bool IsStateChecked() const { return (nItemFlags & SV_ITEMSTATE_CHECKED)!=0; }
164 0 : bool IsStateUnchecked() const { return (nItemFlags & SV_ITEMSTATE_UNCHECKED)!=0; }
165 0 : bool IsStateTristate() const { return (nItemFlags & SV_ITEMSTATE_TRISTATE)!=0; }
166 0 : bool IsStateHilighted() const { return (nItemFlags & SV_ITEMSTATE_HILIGHTED)!=0; }
167 : void SetStateChecked();
168 : void SetStateUnchecked();
169 : void SetStateTristate();
170 : void SetStateHilighted( bool bHilight );
171 : void SetStateInvisible();
172 :
173 0 : SvLBoxButtonKind GetKind() const { return eKind; }
174 :
175 : void SetBaseOffs( sal_uInt16 nOffs ) { nBaseOffs = nOffs; }
176 : sal_uInt16 GetBaseOffs() const { return nBaseOffs; }
177 :
178 : // Check whether this button can be modified via UI
179 : bool CheckModification() const;
180 : SvLBoxButtonData* GetButtonData() const{ return pData;}
181 : };
182 :
183 0 : inline void SvLBoxButton::SetStateChecked()
184 : {
185 0 : nItemFlags &= SV_STATE_MASK;
186 0 : nItemFlags |= SV_ITEMSTATE_CHECKED;
187 0 : }
188 0 : inline void SvLBoxButton::SetStateUnchecked()
189 : {
190 0 : nItemFlags &= SV_STATE_MASK;
191 0 : nItemFlags |= SV_ITEMSTATE_UNCHECKED;
192 0 : }
193 0 : inline void SvLBoxButton::SetStateTristate()
194 : {
195 0 : nItemFlags &= SV_STATE_MASK;
196 0 : nItemFlags |= SV_ITEMSTATE_TRISTATE;
197 0 : }
198 0 : inline void SvLBoxButton::SetStateHilighted( bool bHilight )
199 : {
200 0 : if ( bHilight )
201 0 : nItemFlags |= SV_ITEMSTATE_HILIGHTED;
202 : else
203 0 : nItemFlags &= ~SV_ITEMSTATE_HILIGHTED;
204 0 : }
205 :
206 :
207 : struct SvLBoxContextBmp_Impl;
208 : class SVT_DLLPUBLIC SvLBoxContextBmp : public SvLBoxItem
209 : {
210 : SvLBoxContextBmp_Impl* m_pImpl;
211 : public:
212 : SvLBoxContextBmp(
213 : SvTreeListEntry* pEntry, sal_uInt16 nItemFlags, Image aBmp1, Image aBmp2, bool bExpanded);
214 : SvLBoxContextBmp();
215 :
216 : virtual ~SvLBoxContextBmp();
217 : virtual sal_uInt16 GetType() const SAL_OVERRIDE;
218 : virtual void InitViewData( SvTreeListBox*,SvTreeListEntry*,SvViewDataItem* ) SAL_OVERRIDE;
219 : virtual void Paint(
220 : const Point& rPos, SvTreeListBox& rOutDev, const SvViewDataEntry* pView, const SvTreeListEntry* pEntry) SAL_OVERRIDE;
221 : virtual SvLBoxItem* Create() const SAL_OVERRIDE;
222 : virtual void Clone( SvLBoxItem* pSource ) SAL_OVERRIDE;
223 :
224 :
225 : bool SetModeImages( const Image& _rBitmap1, const Image& _rBitmap2 );
226 : void GetModeImages( Image& _rBitmap1, Image& _rBitmap2 ) const;
227 :
228 : inline void SetBitmap1( const Image& _rImage );
229 : inline void SetBitmap2( const Image& _rImage );
230 : inline const Image& GetBitmap1( ) const;
231 : inline const Image& GetBitmap2( ) const;
232 :
233 : private:
234 : Image& implGetImageStore( bool _bFirst );
235 : };
236 :
237 0 : inline void SvLBoxContextBmp::SetBitmap1( const Image& _rImage )
238 : {
239 0 : implGetImageStore( true ) = _rImage;
240 0 : }
241 :
242 0 : inline void SvLBoxContextBmp::SetBitmap2( const Image& _rImage )
243 : {
244 0 : implGetImageStore( false ) = _rImage;
245 0 : }
246 :
247 0 : inline const Image& SvLBoxContextBmp::GetBitmap1( ) const
248 : {
249 0 : Image& rImage = const_cast< SvLBoxContextBmp* >( this )->implGetImageStore( true );
250 0 : return rImage;
251 : }
252 :
253 0 : inline const Image& SvLBoxContextBmp::GetBitmap2( ) const
254 : {
255 0 : Image& rImage = const_cast< SvLBoxContextBmp* >( this )->implGetImageStore( false );
256 0 : return rImage;
257 : }
258 :
259 : #endif
260 :
261 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|