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 _SVLBOXITM_HXX
22 : #define _SVLBOXITM_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 : sal_Bool bDataOk;
52 : SvButtonState eState;
53 :
54 : SVT_DLLPRIVATE void SetWidthAndHeight();
55 : SVT_DLLPRIVATE void InitData( sal_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 : inline long Width();
66 : inline long Height();
67 0 : void SetLink( const Link& rLink) { aLink=rLink; }
68 : const Link& GetLink() const { return aLink; }
69 : sal_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 : inline SvButtonState GetActButtonState() const;
77 : SvTreeListEntry* GetActEntry() const;
78 :
79 : Image aBmps[24]; // Indizes siehe Konstanten BMP_ ....
80 :
81 : void SetDefaultImages( const Control* pControlForSettings = NULL );
82 : // set images acording to the color scheeme of the Control
83 : // pControlForSettings == NULL: settings are taken from Application
84 : sal_Bool HasDefaultImages( void ) const;
85 : };
86 :
87 0 : inline long SvLBoxButtonData::Width()
88 : {
89 0 : if ( !bDataOk )
90 0 : SetWidthAndHeight();
91 0 : return nWidth;
92 : }
93 :
94 0 : inline long SvLBoxButtonData::Height()
95 : {
96 0 : if ( !bDataOk )
97 0 : SetWidthAndHeight();
98 0 : return nHeight;
99 : }
100 :
101 : inline SvButtonState SvLBoxButtonData::GetActButtonState() const
102 : {
103 : return eState;
104 : }
105 :
106 : // **********************************************************************
107 :
108 : class SVT_DLLPUBLIC SvLBoxString : public SvLBoxItem
109 : {
110 : protected:
111 : rtl::OUString maText;
112 : public:
113 : SvLBoxString(SvTreeListEntry*, sal_uInt16 nFlags, const rtl::OUString& rStr);
114 : SvLBoxString();
115 : virtual ~SvLBoxString();
116 : virtual sal_uInt16 GetType() const;
117 : virtual void InitViewData(SvTreeListBox*, SvTreeListEntry*, SvViewDataItem*);
118 0 : rtl::OUString GetText() const { return maText; }
119 0 : void SetText( const rtl::OUString& rText ) { maText = rText; }
120 :
121 : virtual void Paint(
122 : const Point& rPos, SvTreeListBox& rOutDev, const SvViewDataEntry* pView, const SvTreeListEntry* pEntry);
123 :
124 : virtual SvLBoxItem* Create() const;
125 : virtual void Clone( SvLBoxItem* pSource );
126 : };
127 :
128 : class SvLBoxBmp : public SvLBoxItem
129 : {
130 : Image aBmp;
131 : public:
132 : SvLBoxBmp();
133 : virtual ~SvLBoxBmp();
134 : virtual sal_uInt16 GetType() const;
135 : virtual void InitViewData( SvTreeListBox*,SvTreeListEntry*,SvViewDataItem* );
136 : virtual void Paint(
137 : const Point& rPos, SvTreeListBox& rOutDev, const SvViewDataEntry* pView, const SvTreeListEntry* pEntry);
138 : virtual SvLBoxItem* Create() const;
139 : virtual void Clone( SvLBoxItem* pSource );
140 : };
141 :
142 :
143 : #define SV_ITEMSTATE_UNCHECKED 0x0001
144 : #define SV_ITEMSTATE_CHECKED 0x0002
145 : #define SV_ITEMSTATE_TRISTATE 0x0004
146 : #define SV_ITEMSTATE_HILIGHTED 0x0008
147 : #define SV_STATE_MASK 0xFFF8 // zum Loeschen von UNCHECKED,CHECKED,TRISTATE
148 :
149 : class SVT_DLLPUBLIC SvLBoxButton : public SvLBoxItem
150 : {
151 : SvLBoxButtonData* pData;
152 : SvLBoxButtonKind eKind;
153 : sal_uInt16 nItemFlags;
154 : sal_uInt16 nBaseOffs;
155 :
156 : void ImplAdjustBoxSize( Size& io_rCtrlSize, ControlType i_eType, Window* pParent );
157 : public:
158 : // An SvLBoxButton can be of three different kinds: an
159 : // enabled checkbox (the normal kind), a disabled checkbox
160 : // (which cannot be modified via UI), or a static image
161 : // (see SV_BMP_STATICIMAGE; nFlags are effectively ignored
162 : // for that kind).
163 : SvLBoxButton( SvTreeListEntry* pEntry,
164 : SvLBoxButtonKind eTheKind, sal_uInt16 nFlags,
165 : SvLBoxButtonData* pBData );
166 : SvLBoxButton();
167 : virtual ~SvLBoxButton();
168 : virtual void InitViewData( SvTreeListBox*,SvTreeListEntry*,SvViewDataItem* );
169 : virtual sal_uInt16 GetType() const;
170 : virtual sal_Bool ClickHdl(SvTreeListBox* pView, SvTreeListEntry* );
171 : virtual void Paint(
172 : const Point& rPos, SvTreeListBox& rOutDev, const SvViewDataEntry* pView, const SvTreeListEntry* pEntry);
173 : virtual SvLBoxItem* Create() const;
174 : virtual void Clone( SvLBoxItem* pSource );
175 0 : sal_uInt16 GetButtonFlags() const { return nItemFlags; }
176 0 : sal_Bool IsStateChecked() const { return (sal_Bool)(nItemFlags & SV_ITEMSTATE_CHECKED)!=0; }
177 0 : sal_Bool IsStateUnchecked() const { return (sal_Bool)(nItemFlags & SV_ITEMSTATE_UNCHECKED)!=0; }
178 0 : sal_Bool IsStateTristate() const { return (sal_Bool)(nItemFlags & SV_ITEMSTATE_TRISTATE)!=0; }
179 0 : sal_Bool IsStateHilighted() const { return (sal_Bool)(nItemFlags & SV_ITEMSTATE_HILIGHTED)!=0; }
180 : void SetStateChecked();
181 : void SetStateUnchecked();
182 : void SetStateTristate();
183 : void SetStateHilighted( sal_Bool bHilight );
184 :
185 0 : SvLBoxButtonKind GetKind() const { return eKind; }
186 :
187 : void SetBaseOffs( sal_uInt16 nOffs ) { nBaseOffs = nOffs; }
188 : sal_uInt16 GetBaseOffs() const { return nBaseOffs; }
189 :
190 : // Check whether this button can be modified via UI, sounding a beep if it
191 : // cannot be modified:
192 : bool CheckModification() const;
193 : };
194 :
195 0 : inline void SvLBoxButton::SetStateChecked()
196 : {
197 0 : nItemFlags &= SV_STATE_MASK;
198 0 : nItemFlags |= SV_ITEMSTATE_CHECKED;
199 0 : }
200 0 : inline void SvLBoxButton::SetStateUnchecked()
201 : {
202 0 : nItemFlags &= SV_STATE_MASK;
203 0 : nItemFlags |= SV_ITEMSTATE_UNCHECKED;
204 0 : }
205 0 : inline void SvLBoxButton::SetStateTristate()
206 : {
207 0 : nItemFlags &= SV_STATE_MASK;
208 0 : nItemFlags |= SV_ITEMSTATE_TRISTATE;
209 0 : }
210 0 : inline void SvLBoxButton::SetStateHilighted( sal_Bool bHilight )
211 : {
212 0 : if ( bHilight )
213 0 : nItemFlags |= SV_ITEMSTATE_HILIGHTED;
214 : else
215 0 : nItemFlags &= ~SV_ITEMSTATE_HILIGHTED;
216 0 : }
217 :
218 :
219 : struct SvLBoxContextBmp_Impl;
220 : class SVT_DLLPUBLIC SvLBoxContextBmp : public SvLBoxItem
221 : {
222 : SvLBoxContextBmp_Impl* m_pImpl;
223 : public:
224 : SvLBoxContextBmp(
225 : SvTreeListEntry* pEntry, sal_uInt16 nItemFlags, Image aBmp1, Image aBmp2, bool bExpanded);
226 : SvLBoxContextBmp();
227 :
228 : virtual ~SvLBoxContextBmp();
229 : virtual sal_uInt16 GetType() const;
230 : virtual void InitViewData( SvTreeListBox*,SvTreeListEntry*,SvViewDataItem* );
231 : virtual void Paint(
232 : const Point& rPos, SvTreeListBox& rOutDev, const SvViewDataEntry* pView, const SvTreeListEntry* pEntry);
233 : virtual SvLBoxItem* Create() const;
234 : virtual void Clone( SvLBoxItem* pSource );
235 :
236 :
237 : sal_Bool SetModeImages( const Image& _rBitmap1, const Image& _rBitmap2 );
238 : void GetModeImages( Image& _rBitmap1, Image& _rBitmap2 ) const;
239 :
240 : inline void SetBitmap1( const Image& _rImage );
241 : inline void SetBitmap2( const Image& _rImage );
242 : inline const Image& GetBitmap1( ) const;
243 : inline const Image& GetBitmap2( ) const;
244 :
245 : private:
246 : Image& implGetImageStore( sal_Bool _bFirst );
247 : };
248 :
249 0 : inline void SvLBoxContextBmp::SetBitmap1( const Image& _rImage )
250 : {
251 0 : implGetImageStore( sal_True ) = _rImage;
252 0 : }
253 :
254 0 : inline void SvLBoxContextBmp::SetBitmap2( const Image& _rImage )
255 : {
256 0 : implGetImageStore( sal_False ) = _rImage;
257 0 : }
258 :
259 0 : inline const Image& SvLBoxContextBmp::GetBitmap1( ) const
260 : {
261 0 : Image& rImage = const_cast< SvLBoxContextBmp* >( this )->implGetImageStore( sal_True );
262 0 : return rImage;
263 : }
264 :
265 0 : inline const Image& SvLBoxContextBmp::GetBitmap2( ) const
266 : {
267 0 : Image& rImage = const_cast< SvLBoxContextBmp* >( this )->implGetImageStore( sal_False );
268 0 : return rImage;
269 : }
270 :
271 : #endif
272 :
273 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|