1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24
25 #ifndef _SVLBOXITM_HXX
26 #define _SVLBOXITM_HXX
27
28 #include "svtools/svtdllapi.h"
29
30 #ifndef LINK_HXX
31 #include <tools/link.hxx>
32 #endif
33
34 #ifndef _IMAGE_HXX
35 #include <vcl/image.hxx>
36 #endif
37 #include <svtools/svlbox.hxx>
38
39 class SvLBoxEntry;
40
41 #define SV_ITEM_ID_LBOXSTRING 1
42 #define SV_ITEM_ID_LBOXBMP 2
43 #define SV_ITEM_ID_LBOXBUTTON 3
44 #define SV_ITEM_ID_LBOXCONTEXTBMP 4
45 #define SV_ITEM_ID_EXTENDRLBOXSTRING 5
46
47 enum SvButtonState { SV_BUTTON_UNCHECKED, SV_BUTTON_CHECKED, SV_BUTTON_TRISTATE };
48
49 #define SV_BMP_UNCHECKED 0
50 #define SV_BMP_CHECKED 1
51 #define SV_BMP_TRISTATE 2
52 #define SV_BMP_HIUNCHECKED 3
53 #define SV_BMP_HICHECKED 4
54 #define SV_BMP_HITRISTATE 5
55 #define SV_BMP_STATICIMAGE 6
56
57 struct SvLBoxButtonData_Impl;
58
59 class SVT_DLLPUBLIC SvLBoxButtonData
60 {
61 private:
62 Link aLink;
63 long nWidth;
64 long nHeight;
65 SvLBoxButtonData_Impl* pImpl;
66 sal_Bool bDataOk;
67 SvButtonState eState;
68
69 SVT_DLLPRIVATE void SetWidthAndHeight();
70 SVT_DLLPRIVATE void InitData( sal_Bool bImagesFromDefault,
71 bool _bRadioBtn, const Control* pControlForSettings = NULL );
72 public:
73 // include creating default images (CheckBox or RadioButton)
74 SvLBoxButtonData( const Control* pControlForSettings );
75 SvLBoxButtonData( const Control* pControlForSettings, bool _bRadioBtn );
76
77 SvLBoxButtonData();
78 ~SvLBoxButtonData();
79
80 sal_uInt16 GetIndex( sal_uInt16 nItemState );
81 inline long Width();
82 inline long Height();
SetLink(const Link & rLink)83 void SetLink( const Link& rLink) { aLink=rLink; }
GetLink() const84 const Link& GetLink() const { return aLink; }
85 sal_Bool IsRadio();
86 // weil Buttons nicht von LinkHdl abgeleitet sind
87 void CallLink();
88
89 void StoreButtonState( SvLBoxEntry* pEntry, sal_uInt16 nItemFlags );
90 SvButtonState ConvertToButtonState( sal_uInt16 nItemFlags ) const;
91
92 inline SvButtonState GetActButtonState() const;
93 SvLBoxEntry* GetActEntry() const;
94
95 Image aBmps[24]; // Indizes siehe Konstanten BMP_ ....
96
97 void SetDefaultImages( const Control* pControlForSettings = NULL );
98 // set images according to the color scheeme of the Control
99 // pControlForSettings == NULL: settings are taken from Application
100 sal_Bool HasDefaultImages( void ) const;
101 };
102
Width()103 inline long SvLBoxButtonData::Width()
104 {
105 if ( !bDataOk )
106 SetWidthAndHeight();
107 return nWidth;
108 }
109
Height()110 inline long SvLBoxButtonData::Height()
111 {
112 if ( !bDataOk )
113 SetWidthAndHeight();
114 return nHeight;
115 }
116
GetActButtonState() const117 inline SvButtonState SvLBoxButtonData::GetActButtonState() const
118 {
119 return eState;
120 }
121
122 // **********************************************************************
123
124 class SVT_DLLPUBLIC SvLBoxString : public SvLBoxItem
125 {
126 XubString aStr;
127 public:
128 SvLBoxString( SvLBoxEntry*,sal_uInt16 nFlags,const XubString& rStr);
129 SvLBoxString();
130 virtual ~SvLBoxString();
131 virtual sal_uInt16 IsA();
132 void InitViewData( SvLBox*,SvLBoxEntry*,SvViewDataItem* );
GetText() const133 XubString GetText() const { return aStr; }
GetExtendText() const134 virtual XubString GetExtendText() const {return XubString();}
135 void SetText( SvLBoxEntry*, const XubString& rStr );
136 void Paint( const Point&, SvLBox& rDev, sal_uInt16 nFlags,SvLBoxEntry* );
137 SvLBoxItem* Create() const;
138 void Clone( SvLBoxItem* pSource );
139 };
140
141 class SvLBoxBmp : public SvLBoxItem
142 {
143 Image aBmp;
144 public:
145 SvLBoxBmp( SvLBoxEntry*, sal_uInt16 nFlags, Image );
146 SvLBoxBmp();
147 virtual ~SvLBoxBmp();
148 virtual sal_uInt16 IsA();
149 void InitViewData( SvLBox*,SvLBoxEntry*,SvViewDataItem* );
150 void SetBitmap( SvLBoxEntry*, Image );
151 void Paint( const Point&, SvLBox& rView, sal_uInt16 nFlags,SvLBoxEntry* );
152 SvLBoxItem* Create() const;
153 void Clone( SvLBoxItem* pSource );
154 };
155
156
157 #define SV_ITEMSTATE_UNCHECKED 0x0001
158 #define SV_ITEMSTATE_CHECKED 0x0002
159 #define SV_ITEMSTATE_TRISTATE 0x0004
160 #define SV_ITEMSTATE_HILIGHTED 0x0008
161 #define SV_STATE_MASK 0xFFF8 // zum Loeschen von UNCHECKED,CHECKED,TRISTATE
162
163 enum SvLBoxButtonKind
164 {
165 SvLBoxButtonKind_enabledCheckbox,
166 SvLBoxButtonKind_disabledCheckbox,
167 SvLBoxButtonKind_staticImage
168 };
169
170 class SVT_DLLPUBLIC SvLBoxButton : public SvLBoxItem
171 {
172 SvLBoxButtonData* pData;
173 SvLBoxButtonKind eKind;
174 sal_uInt16 nItemFlags;
175 sal_uInt16 nImgArrOffs;
176 sal_uInt16 nBaseOffs;
177
178 void ImplAdjustBoxSize( Size& io_rCtrlSize, ControlType i_eType, Window* pParent );
179 public:
180 // An SvLBoxButton can be of three different kinds: an
181 // enabled checkbox (the normal kind), a disabled checkbox
182 // (which cannot be modified via UI), or a static image
183 // (see SV_BMP_STATICIMAGE; nFlags are effectively ignored
184 // for that kind).
185 SvLBoxButton( SvLBoxEntry* pEntry,
186 SvLBoxButtonKind eTheKind, sal_uInt16 nFlags,
187 SvLBoxButtonData* pBData );
188 SvLBoxButton();
189 virtual ~SvLBoxButton();
190 void InitViewData( SvLBox*,SvLBoxEntry*,SvViewDataItem* );
191 virtual sal_uInt16 IsA();
192 void Check( SvLBox* pView, SvLBoxEntry*, sal_Bool bCheck );
193 virtual sal_Bool ClickHdl(SvLBox* pView, SvLBoxEntry* );
194 void Paint( const Point&, SvLBox& rView, sal_uInt16 nFlags,SvLBoxEntry* );
195 SvLBoxItem* Create() const;
196 void Clone( SvLBoxItem* pSource );
GetButtonFlags() const197 sal_uInt16 GetButtonFlags() const { return nItemFlags; }
IsStateChecked() const198 sal_Bool IsStateChecked() const { return (sal_Bool)(nItemFlags & SV_ITEMSTATE_CHECKED)!=0; }
IsStateUnchecked() const199 sal_Bool IsStateUnchecked() const { return (sal_Bool)(nItemFlags & SV_ITEMSTATE_UNCHECKED)!=0; }
IsStateTristate() const200 sal_Bool IsStateTristate() const { return (sal_Bool)(nItemFlags & SV_ITEMSTATE_TRISTATE)!=0; }
IsStateHilighted() const201 sal_Bool IsStateHilighted() const { return (sal_Bool)(nItemFlags & SV_ITEMSTATE_HILIGHTED)!=0; }
202 void SetStateChecked();
203 void SetStateUnchecked();
204 void SetStateTristate();
205 void SetStateHilighted( sal_Bool bHilight );
206
GetKind() const207 SvLBoxButtonKind GetKind() const { return eKind; }
208
SetBaseOffs(sal_uInt16 nOffs)209 void SetBaseOffs( sal_uInt16 nOffs ) { nBaseOffs = nOffs; }
GetBaseOffs() const210 sal_uInt16 GetBaseOffs() const { return nBaseOffs; }
211
212 // Check whether this button can be modified via UI, sounding a beep if it
213 // cannot be modified:
214 bool CheckModification() const;
GetButtonData() const215 SvLBoxButtonData* GetButtonData() const{ return pData;}
216 };
217
SetStateChecked()218 inline void SvLBoxButton::SetStateChecked()
219 {
220 nItemFlags &= SV_STATE_MASK;
221 nItemFlags |= SV_ITEMSTATE_CHECKED;
222 }
SetStateUnchecked()223 inline void SvLBoxButton::SetStateUnchecked()
224 {
225 nItemFlags &= SV_STATE_MASK;
226 nItemFlags |= SV_ITEMSTATE_UNCHECKED;
227 }
SetStateTristate()228 inline void SvLBoxButton::SetStateTristate()
229 {
230 nItemFlags &= SV_STATE_MASK;
231 nItemFlags |= SV_ITEMSTATE_TRISTATE;
232 }
SetStateHilighted(sal_Bool bHilight)233 inline void SvLBoxButton::SetStateHilighted( sal_Bool bHilight )
234 {
235 if ( bHilight )
236 nItemFlags |= SV_ITEMSTATE_HILIGHTED;
237 else
238 nItemFlags &= ~SV_ITEMSTATE_HILIGHTED;
239 }
240
241
242 struct SvLBoxContextBmp_Impl;
243 class SVT_DLLPUBLIC SvLBoxContextBmp : public SvLBoxItem
244 {
245 SvLBoxContextBmp_Impl* m_pImpl;
246 public:
247 SvLBoxContextBmp( SvLBoxEntry*,sal_uInt16 nFlags,Image,Image,
248 sal_uInt16 nEntryFlagsBmp1);
249 SvLBoxContextBmp();
250 virtual ~SvLBoxContextBmp();
251 virtual sal_uInt16 IsA();
252 void InitViewData( SvLBox*,SvLBoxEntry*,SvViewDataItem* );
253 void Paint( const Point&, SvLBox& rView, sal_uInt16 nFlags,SvLBoxEntry* );
254 SvLBoxItem* Create() const;
255 void Clone( SvLBoxItem* pSource );
256
257
258 sal_Bool SetModeImages( const Image& _rBitmap1, const Image& _rBitmap2, BmpColorMode _eMode = BMP_COLOR_NORMAL );
259 void GetModeImages( Image& _rBitmap1, Image& _rBitmap2, BmpColorMode _eMode = BMP_COLOR_NORMAL ) const;
260
261 inline void SetBitmap1( const Image& _rImage, BmpColorMode _eMode = BMP_COLOR_NORMAL );
262 inline void SetBitmap2( const Image& _rImage, BmpColorMode _eMode = BMP_COLOR_NORMAL );
263 inline const Image& GetBitmap1( BmpColorMode _eMode = BMP_COLOR_NORMAL ) const;
264 inline const Image& GetBitmap2( BmpColorMode _eMode = BMP_COLOR_NORMAL ) const;
265
266 private:
267 Image& implGetImageStore( sal_Bool _bFirst, BmpColorMode _eMode );
268 };
269
SetBitmap1(const Image & _rImage,BmpColorMode _eMode)270 inline void SvLBoxContextBmp::SetBitmap1( const Image& _rImage, BmpColorMode _eMode )
271 {
272 implGetImageStore( sal_True, _eMode ) = _rImage;
273 }
274
SetBitmap2(const Image & _rImage,BmpColorMode _eMode)275 inline void SvLBoxContextBmp::SetBitmap2( const Image& _rImage, BmpColorMode _eMode )
276 {
277 implGetImageStore( sal_False, _eMode ) = _rImage;
278 }
279
GetBitmap1(BmpColorMode _eMode) const280 inline const Image& SvLBoxContextBmp::GetBitmap1( BmpColorMode _eMode ) const
281 {
282 Image& rImage = const_cast< SvLBoxContextBmp* >( this )->implGetImageStore( sal_True, _eMode );
283 if ( !rImage )
284 // fallback to the "normal" image
285 rImage = const_cast< SvLBoxContextBmp* >( this )->implGetImageStore( sal_True, BMP_COLOR_NORMAL );
286 return rImage;
287 }
288
GetBitmap2(BmpColorMode _eMode) const289 inline const Image& SvLBoxContextBmp::GetBitmap2( BmpColorMode _eMode ) const
290 {
291 Image& rImage = const_cast< SvLBoxContextBmp* >( this )->implGetImageStore( sal_False, _eMode );
292 if ( !rImage )
293 // fallback to the "normal" image
294 rImage = const_cast< SvLBoxContextBmp* >( this )->implGetImageStore( sal_True, BMP_COLOR_NORMAL );
295 return rImage;
296 }
297
298 #endif
299