Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #ifndef _SVLBOXITM_HXX
31 : : #define _SVLBOXITM_HXX
32 : :
33 : : #include "svtools/svtdllapi.h"
34 : :
35 : : #include <tools/link.hxx>
36 : :
37 : : #include <vcl/image.hxx>
38 : : #include <svtools/svlbox.hxx>
39 : :
40 : : class SvLBoxEntry;
41 : :
42 : : #define SV_ITEM_ID_LBOXSTRING 1
43 : : #define SV_ITEM_ID_LBOXBMP 2
44 : : #define SV_ITEM_ID_LBOXBUTTON 3
45 : : #define SV_ITEM_ID_LBOXCONTEXTBMP 4
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 : :
79 : : sal_uInt16 GetIndex( sal_uInt16 nItemState );
80 : : inline long Width();
81 : : inline long Height();
82 : 0 : void SetLink( const Link& rLink) { aLink=rLink; }
83 : : const Link& GetLink() const { return aLink; }
84 : : sal_Bool IsRadio();
85 : : // weil Buttons nicht von LinkHdl abgeleitet sind
86 : : void CallLink();
87 : :
88 : : void StoreButtonState( SvLBoxEntry* pEntry, sal_uInt16 nItemFlags );
89 : : SvButtonState ConvertToButtonState( sal_uInt16 nItemFlags ) const;
90 : :
91 : : inline SvButtonState GetActButtonState() const;
92 : : SvLBoxEntry* GetActEntry() const;
93 : :
94 : : Image aBmps[24]; // Indizes siehe Konstanten BMP_ ....
95 : :
96 : : void SetDefaultImages( const Control* pControlForSettings = NULL );
97 : : // set images acording to the color scheeme of the Control
98 : : // pControlForSettings == NULL: settings are taken from Application
99 : : sal_Bool HasDefaultImages( void ) const;
100 : : };
101 : :
102 : 0 : inline long SvLBoxButtonData::Width()
103 : : {
104 [ # # ]: 0 : if ( !bDataOk )
105 : 0 : SetWidthAndHeight();
106 : 0 : return nWidth;
107 : : }
108 : :
109 : 0 : inline long SvLBoxButtonData::Height()
110 : : {
111 [ # # ]: 0 : if ( !bDataOk )
112 : 0 : SetWidthAndHeight();
113 : 0 : return nHeight;
114 : : }
115 : :
116 : : inline SvButtonState SvLBoxButtonData::GetActButtonState() const
117 : : {
118 : : return eState;
119 : : }
120 : :
121 : : // **********************************************************************
122 : :
123 : : class SVT_DLLPUBLIC SvLBoxString : public SvLBoxItem
124 : : {
125 : : protected:
126 : : rtl::OUString maText;
127 : : public:
128 : : SvLBoxString(SvLBoxEntry*, sal_uInt16 nFlags, const rtl::OUString& rStr);
129 : : SvLBoxString();
130 : : virtual ~SvLBoxString();
131 : : virtual sal_uInt16 IsA();
132 : : virtual void InitViewData(SvLBox*, SvLBoxEntry*, SvViewDataItem*);
133 : 23685 : rtl::OUString GetText() const { return maText; }
134 : 2406 : void SetText( const rtl::OUString& rText ) { maText = rText; }
135 : : virtual void Paint( const Point&, SvLBox& rDev, sal_uInt16 nFlags,SvLBoxEntry* );
136 : : virtual SvLBoxItem* Create() const;
137 : : virtual void Clone( SvLBoxItem* pSource );
138 : : };
139 : :
140 : : class SvLBoxBmp : public SvLBoxItem
141 : : {
142 : : Image aBmp;
143 : : public:
144 : : SvLBoxBmp();
145 : : virtual ~SvLBoxBmp();
146 : : virtual sal_uInt16 IsA();
147 : : virtual void InitViewData( SvLBox*,SvLBoxEntry*,SvViewDataItem* );
148 : : virtual void Paint( const Point&, SvLBox& rView, sal_uInt16 nFlags,SvLBoxEntry* );
149 : : virtual SvLBoxItem* Create() const;
150 : : virtual void Clone( SvLBoxItem* pSource );
151 : : };
152 : :
153 : :
154 : : #define SV_ITEMSTATE_UNCHECKED 0x0001
155 : : #define SV_ITEMSTATE_CHECKED 0x0002
156 : : #define SV_ITEMSTATE_TRISTATE 0x0004
157 : : #define SV_ITEMSTATE_HILIGHTED 0x0008
158 : : #define SV_STATE_MASK 0xFFF8 // zum Loeschen von UNCHECKED,CHECKED,TRISTATE
159 : :
160 : : enum SvLBoxButtonKind
161 : : {
162 : : SvLBoxButtonKind_enabledCheckbox,
163 : : SvLBoxButtonKind_disabledCheckbox,
164 : : SvLBoxButtonKind_staticImage
165 : : };
166 : :
167 : : class SVT_DLLPUBLIC SvLBoxButton : public SvLBoxItem
168 : : {
169 : : SvLBoxButtonData* pData;
170 : : SvLBoxButtonKind eKind;
171 : : sal_uInt16 nItemFlags;
172 : : sal_uInt16 nBaseOffs;
173 : :
174 : : void ImplAdjustBoxSize( Size& io_rCtrlSize, ControlType i_eType, Window* pParent );
175 : : public:
176 : : // An SvLBoxButton can be of three different kinds: an
177 : : // enabled checkbox (the normal kind), a disabled checkbox
178 : : // (which cannot be modified via UI), or a static image
179 : : // (see SV_BMP_STATICIMAGE; nFlags are effectively ignored
180 : : // for that kind).
181 : : SvLBoxButton( SvLBoxEntry* pEntry,
182 : : SvLBoxButtonKind eTheKind, sal_uInt16 nFlags,
183 : : SvLBoxButtonData* pBData );
184 : : SvLBoxButton();
185 : : virtual ~SvLBoxButton();
186 : : virtual void InitViewData( SvLBox*,SvLBoxEntry*,SvViewDataItem* );
187 : : virtual sal_uInt16 IsA();
188 : : virtual sal_Bool ClickHdl(SvLBox* pView, SvLBoxEntry* );
189 : : virtual void Paint( const Point&, SvLBox& rView, sal_uInt16 nFlags,SvLBoxEntry* );
190 : : virtual SvLBoxItem* Create() const;
191 : : virtual void Clone( SvLBoxItem* pSource );
192 : 0 : sal_uInt16 GetButtonFlags() const { return nItemFlags; }
193 : 0 : sal_Bool IsStateChecked() const { return (sal_Bool)(nItemFlags & SV_ITEMSTATE_CHECKED)!=0; }
194 : 0 : sal_Bool IsStateUnchecked() const { return (sal_Bool)(nItemFlags & SV_ITEMSTATE_UNCHECKED)!=0; }
195 : 0 : sal_Bool IsStateTristate() const { return (sal_Bool)(nItemFlags & SV_ITEMSTATE_TRISTATE)!=0; }
196 : 0 : sal_Bool IsStateHilighted() const { return (sal_Bool)(nItemFlags & SV_ITEMSTATE_HILIGHTED)!=0; }
197 : : void SetStateChecked();
198 : : void SetStateUnchecked();
199 : : void SetStateTristate();
200 : : void SetStateHilighted( sal_Bool bHilight );
201 : :
202 : 0 : SvLBoxButtonKind GetKind() const { return eKind; }
203 : :
204 : : void SetBaseOffs( sal_uInt16 nOffs ) { nBaseOffs = nOffs; }
205 : : sal_uInt16 GetBaseOffs() const { return nBaseOffs; }
206 : :
207 : : // Check whether this button can be modified via UI, sounding a beep if it
208 : : // cannot be modified:
209 : : bool CheckModification() const;
210 : : };
211 : :
212 : 0 : inline void SvLBoxButton::SetStateChecked()
213 : : {
214 : 0 : nItemFlags &= SV_STATE_MASK;
215 : 0 : nItemFlags |= SV_ITEMSTATE_CHECKED;
216 : 0 : }
217 : 0 : inline void SvLBoxButton::SetStateUnchecked()
218 : : {
219 : 0 : nItemFlags &= SV_STATE_MASK;
220 : 0 : nItemFlags |= SV_ITEMSTATE_UNCHECKED;
221 : 0 : }
222 : 0 : inline void SvLBoxButton::SetStateTristate()
223 : : {
224 : 0 : nItemFlags &= SV_STATE_MASK;
225 : 0 : nItemFlags |= SV_ITEMSTATE_TRISTATE;
226 : 0 : }
227 : 0 : inline void SvLBoxButton::SetStateHilighted( sal_Bool bHilight )
228 : : {
229 [ # # ]: 0 : if ( bHilight )
230 : 0 : nItemFlags |= SV_ITEMSTATE_HILIGHTED;
231 : : else
232 : 0 : nItemFlags &= ~SV_ITEMSTATE_HILIGHTED;
233 : 0 : }
234 : :
235 : :
236 : : struct SvLBoxContextBmp_Impl;
237 : : class SVT_DLLPUBLIC SvLBoxContextBmp : public SvLBoxItem
238 : : {
239 : : SvLBoxContextBmp_Impl* m_pImpl;
240 : : public:
241 : : SvLBoxContextBmp( SvLBoxEntry*,sal_uInt16 nFlags,Image,Image,
242 : : sal_uInt16 nEntryFlagsBmp1);
243 : : SvLBoxContextBmp();
244 : : virtual ~SvLBoxContextBmp();
245 : : virtual sal_uInt16 IsA();
246 : : virtual void InitViewData( SvLBox*,SvLBoxEntry*,SvViewDataItem* );
247 : : virtual void Paint( const Point&, SvLBox& rView, sal_uInt16 nFlags,SvLBoxEntry* );
248 : : virtual SvLBoxItem* Create() const;
249 : : virtual void Clone( SvLBoxItem* pSource );
250 : :
251 : :
252 : : sal_Bool SetModeImages( const Image& _rBitmap1, const Image& _rBitmap2 );
253 : : void GetModeImages( Image& _rBitmap1, Image& _rBitmap2 ) const;
254 : :
255 : : inline void SetBitmap1( const Image& _rImage );
256 : : inline void SetBitmap2( const Image& _rImage );
257 : : inline const Image& GetBitmap1( ) const;
258 : : inline const Image& GetBitmap2( ) const;
259 : :
260 : : private:
261 : : Image& implGetImageStore( sal_Bool _bFirst );
262 : : };
263 : :
264 : 2 : inline void SvLBoxContextBmp::SetBitmap1( const Image& _rImage )
265 : : {
266 : 2 : implGetImageStore( sal_True ) = _rImage;
267 : 2 : }
268 : :
269 : 2 : inline void SvLBoxContextBmp::SetBitmap2( const Image& _rImage )
270 : : {
271 : 2 : implGetImageStore( sal_False ) = _rImage;
272 : 2 : }
273 : :
274 : 2406 : inline const Image& SvLBoxContextBmp::GetBitmap1( ) const
275 : : {
276 : 2406 : Image& rImage = const_cast< SvLBoxContextBmp* >( this )->implGetImageStore( sal_True );
277 : 2406 : return rImage;
278 : : }
279 : :
280 : 2406 : inline const Image& SvLBoxContextBmp::GetBitmap2( ) const
281 : : {
282 : 2406 : Image& rImage = const_cast< SvLBoxContextBmp* >( this )->implGetImageStore( sal_False );
283 : 2406 : return rImage;
284 : : }
285 : :
286 : : #endif
287 : :
288 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|