Branch data 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 : : #include <sfx2/itemconnect.hxx>
21 : :
22 : : #include <boost/shared_ptr.hpp>
23 : : #include <list>
24 : : #include <svl/itempool.hxx>
25 : :
26 : : // ============================================================================
27 : :
28 : : namespace sfx {
29 : :
30 : : // ============================================================================
31 : : // Helpers
32 : : // ============================================================================
33 : :
34 : : namespace {
35 : :
36 : 0 : TriState lclConvertToTriState( bool bKnown, bool bIsKnownFlag, bool bIsUnknownFlag )
37 : : {
38 [ # # ][ # # ]: 0 : return (bKnown && bIsKnownFlag) ? STATE_CHECK : ((!bKnown && bIsUnknownFlag) ? STATE_NOCHECK : STATE_DONTKNOW);
[ # # ][ # # ]
39 : : }
40 : :
41 : : } // namespace
42 : :
43 : : // ----------------------------------------------------------------------------
44 : :
45 : 0 : sal_uInt16 ItemWrapperHelper::GetWhichId( const SfxItemSet& rItemSet, sal_uInt16 nSlot )
46 : : {
47 : 0 : return rItemSet.GetPool()->GetWhich( nSlot );
48 : : }
49 : :
50 : 0 : bool ItemWrapperHelper::IsKnownItem( const SfxItemSet& rItemSet, sal_uInt16 nSlot )
51 : : {
52 : 0 : return rItemSet.GetItemState( GetWhichId( rItemSet, nSlot ), sal_True ) != SFX_ITEM_UNKNOWN;
53 : : }
54 : :
55 : 0 : const SfxPoolItem* ItemWrapperHelper::GetUniqueItem( const SfxItemSet& rItemSet, sal_uInt16 nSlot )
56 : : {
57 : 0 : sal_uInt16 nWhich = GetWhichId( rItemSet, nSlot );
58 [ # # ]: 0 : return (rItemSet.GetItemState( nWhich, sal_True ) >= SFX_ITEM_DEFAULT) ? rItemSet.GetItem( nWhich, sal_True ) : 0;
59 : : }
60 : :
61 : 0 : const SfxPoolItem& ItemWrapperHelper::GetDefaultItem( const SfxItemSet& rItemSet, sal_uInt16 nSlot )
62 : : {
63 : 0 : return rItemSet.GetPool()->GetDefaultItem( GetWhichId( rItemSet, nSlot ) );
64 : : }
65 : :
66 : 0 : void ItemWrapperHelper::RemoveDefaultItem( SfxItemSet& rDestSet, const SfxItemSet& rOldSet, sal_uInt16 nSlot )
67 : : {
68 : 0 : sal_uInt16 nWhich = GetWhichId( rDestSet, nSlot );
69 [ # # ]: 0 : if( rOldSet.GetItemState( nWhich, sal_False ) == SFX_ITEM_DEFAULT )
70 : 0 : rDestSet.ClearItem( nWhich );
71 : 0 : }
72 : :
73 : : // ============================================================================
74 : : // Base control wrapper classes
75 : : // ============================================================================
76 : :
77 : 0 : ControlWrapperBase::~ControlWrapperBase()
78 : : {
79 [ # # ]: 0 : }
80 : :
81 : : // ============================================================================
82 : : // Single control wrappers
83 : : // ============================================================================
84 : :
85 : 0 : DummyWindowWrapper::DummyWindowWrapper( Window& rWindow ) :
86 : 0 : SingleControlWrapperType( rWindow )
87 : : {
88 : 0 : }
89 : :
90 : 0 : bool DummyWindowWrapper::IsControlDontKnow() const
91 : : {
92 : 0 : return false;
93 : : }
94 : :
95 : 0 : void DummyWindowWrapper::SetControlDontKnow( bool )
96 : : {
97 : 0 : }
98 : :
99 : 0 : void* DummyWindowWrapper::GetControlValue() const
100 : : {
101 : 0 : return 0;
102 : : }
103 : :
104 : 0 : void DummyWindowWrapper::SetControlValue( void* )
105 : : {
106 : 0 : }
107 : :
108 : : // ----------------------------------------------------------------------------
109 : :
110 : 0 : CheckBoxWrapper::CheckBoxWrapper( CheckBox& rCheckBox ) :
111 : 0 : SingleControlWrapperType( rCheckBox )
112 : : {
113 : 0 : }
114 : :
115 : 0 : bool CheckBoxWrapper::IsControlDontKnow() const
116 : : {
117 : 0 : return GetControl().GetState() == STATE_DONTKNOW;
118 : : }
119 : :
120 : 0 : void CheckBoxWrapper::SetControlDontKnow( bool bSet )
121 : : {
122 : 0 : GetControl().EnableTriState( bSet );
123 [ # # ]: 0 : GetControl().SetState( bSet ? STATE_DONTKNOW : STATE_NOCHECK );
124 : 0 : }
125 : :
126 : 0 : sal_Bool CheckBoxWrapper::GetControlValue() const
127 : : {
128 : 0 : return GetControl().IsChecked();
129 : : }
130 : :
131 : 0 : void CheckBoxWrapper::SetControlValue( sal_Bool bValue )
132 : : {
133 : 0 : GetControl().Check( bValue );
134 : 0 : }
135 : :
136 : : // ----------------------------------------------------------------------------
137 : :
138 : 0 : ColorListBoxWrapper::ColorListBoxWrapper(ColorListBox & rListBox):
139 : 0 : SingleControlWrapper< ColorListBox, Color >(rListBox)
140 : 0 : {}
141 : :
142 : 0 : ColorListBoxWrapper::~ColorListBoxWrapper()
143 [ # # ]: 0 : {}
144 : :
145 : 0 : bool ColorListBoxWrapper::IsControlDontKnow() const
146 : : {
147 : 0 : return GetControl().GetSelectEntryCount() == 0;
148 : : }
149 : :
150 : 0 : void ColorListBoxWrapper::SetControlDontKnow( bool bSet )
151 : : {
152 [ # # ]: 0 : if( bSet ) GetControl().SetNoSelection();
153 : 0 : }
154 : :
155 : 0 : Color ColorListBoxWrapper::GetControlValue() const
156 : : {
157 : 0 : return GetControl().GetSelectEntryColor();
158 : : }
159 : :
160 : 0 : void ColorListBoxWrapper::SetControlValue( Color aColor )
161 : : {
162 : 0 : GetControl().SelectEntry( aColor );
163 : 0 : }
164 : :
165 : : // ============================================================================
166 : : // Multi control wrappers
167 : : // ============================================================================
168 : :
169 : : typedef std::vector< ControlWrapperBase* > ControlWrpVec;
170 : : typedef ControlWrpVec::iterator ControlWrpVecI;
171 : : typedef ControlWrpVec::const_iterator ControlWrpVecCI;
172 : :
173 : 0 : struct MultiControlWrapperHelper_Impl
174 : : {
175 : : ControlWrpVec maVec;
176 : : };
177 : :
178 : 0 : MultiControlWrapperHelper::MultiControlWrapperHelper() :
179 [ # # ][ # # ]: 0 : mxImpl( new MultiControlWrapperHelper_Impl )
180 : : {
181 : 0 : }
182 : :
183 : 0 : MultiControlWrapperHelper::~MultiControlWrapperHelper()
184 : : {
185 [ # # ]: 0 : }
186 : :
187 : 0 : void MultiControlWrapperHelper::RegisterControlWrapper( ControlWrapperBase& rWrapper )
188 : : {
189 [ # # ]: 0 : mxImpl->maVec.push_back( &rWrapper );
190 : 0 : }
191 : :
192 : 0 : void MultiControlWrapperHelper::ModifyControl( TriState eEnable, TriState eShow )
193 : : {
194 [ # # ][ # # ]: 0 : for( ControlWrpVecI aIt = mxImpl->maVec.begin(), aEnd = mxImpl->maVec.end(); aIt != aEnd; ++aIt )
[ # # ]
195 [ # # ][ # # ]: 0 : (*aIt)->ModifyControl( eEnable, eShow );
196 : 0 : }
197 : :
198 : 0 : bool MultiControlWrapperHelper::IsControlDontKnow() const
199 : : {
200 : 0 : bool bIs = !mxImpl->maVec.empty();
201 [ # # ][ # # ]: 0 : for( ControlWrpVecCI aIt = mxImpl->maVec.begin(), aEnd = mxImpl->maVec.end(); bIs && (aIt != aEnd); ++aIt )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
202 [ # # ][ # # ]: 0 : bIs &= (*aIt)->IsControlDontKnow();
203 : 0 : return bIs;
204 : : }
205 : :
206 : 0 : void MultiControlWrapperHelper::SetControlDontKnow( bool bSet )
207 : : {
208 [ # # ][ # # ]: 0 : for( ControlWrpVecI aIt = mxImpl->maVec.begin(), aEnd = mxImpl->maVec.end(); aIt != aEnd; ++aIt )
[ # # ]
209 [ # # ][ # # ]: 0 : (*aIt)->SetControlDontKnow( bSet );
210 : 0 : }
211 : :
212 : : // ============================================================================
213 : : // Base connection classes
214 : : // ============================================================================
215 : :
216 : 0 : ItemConnectionBase::ItemConnectionBase( ItemConnFlags nFlags ) :
217 : 0 : mnFlags( nFlags )
218 : : {
219 : 0 : }
220 : :
221 : 0 : ItemConnectionBase::~ItemConnectionBase()
222 : : {
223 [ # # ]: 0 : }
224 : :
225 : 0 : bool ItemConnectionBase::IsActive() const
226 : : {
227 : 0 : return !(mnFlags & ITEMCONN_INACTIVE);
228 : : }
229 : :
230 : 0 : void ItemConnectionBase::DoApplyFlags( const SfxItemSet& rItemSet )
231 : : {
232 [ # # ]: 0 : if( IsActive() )
233 : 0 : ApplyFlags( rItemSet );
234 : 0 : }
235 : :
236 : 0 : void ItemConnectionBase::DoReset( const SfxItemSet& rItemSet )
237 : : {
238 [ # # ]: 0 : if( IsActive() )
239 : 0 : Reset( rItemSet );
240 : 0 : }
241 : :
242 : 0 : bool ItemConnectionBase::DoFillItemSet( SfxItemSet& rDestSet, const SfxItemSet& rOldSet )
243 : : {
244 [ # # ][ # # ]: 0 : return IsActive() && FillItemSet( rDestSet, rOldSet );
245 : : }
246 : :
247 : 0 : TriState ItemConnectionBase::GetEnableState( bool bKnown ) const
248 : : {
249 : 0 : return lclConvertToTriState( bKnown, mnFlags & ITEMCONN_ENABLE_KNOWN, mnFlags & ITEMCONN_DISABLE_UNKNOWN );
250 : : }
251 : :
252 : 0 : TriState ItemConnectionBase::GetShowState( bool bKnown ) const
253 : : {
254 : 0 : return lclConvertToTriState( bKnown, mnFlags & ITEMCONN_SHOW_KNOWN, mnFlags & ITEMCONN_HIDE_UNKNOWN );
255 : : }
256 : :
257 : : // ============================================================================
258 : : // Standard connections
259 : : // ============================================================================
260 : :
261 : 0 : DummyItemConnection::DummyItemConnection( sal_uInt16 nSlot, Window& rWindow, ItemConnFlags nFlags ) :
262 : : ItemConnectionBase( nFlags ),
263 : : DummyWindowWrapper( rWindow ),
264 [ # # ]: 0 : mnSlot( nSlot )
265 : : {
266 : 0 : }
267 : :
268 : 0 : void DummyItemConnection::ApplyFlags( const SfxItemSet& rItemSet )
269 : : {
270 : 0 : bool bKnown = ItemWrapperHelper::IsKnownItem( rItemSet, mnSlot );
271 : 0 : ModifyControl( GetEnableState( bKnown ), GetShowState( bKnown ) );
272 : 0 : }
273 : :
274 : 0 : void DummyItemConnection::Reset( const SfxItemSet& /*rItemSet*/ )
275 : : {
276 : 0 : }
277 : :
278 : 0 : bool DummyItemConnection::FillItemSet( SfxItemSet& /*rDestSet*/, const SfxItemSet& /*rOldSet*/ )
279 : : {
280 : 0 : return false; // item set not changed
281 : : }
282 : :
283 : : // ============================================================================
284 : : // Array of connections
285 : : // ============================================================================
286 : :
287 : 0 : class ItemConnectionArrayImpl
288 : : {
289 : : public:
290 : : void Append( ItemConnectionBase* pConnection );
291 : :
292 : : void ApplyFlags( const SfxItemSet& rItemSet );
293 : : void Reset( const SfxItemSet& rItemSet );
294 : : bool FillItemSet( SfxItemSet& rDestSet, const SfxItemSet& rOldSet );
295 : :
296 : : private:
297 : : typedef boost::shared_ptr< ItemConnectionBase > ItemConnectionRef;
298 : : typedef std::list< ItemConnectionRef > ItemConnectionList;
299 : : typedef ItemConnectionList::iterator ItemConnectionListIt;
300 : :
301 : : ItemConnectionList maList;
302 : : };
303 : :
304 : 0 : void ItemConnectionArrayImpl::Append( ItemConnectionBase* pConnection )
305 : : {
306 [ # # ]: 0 : if( pConnection )
307 [ # # ]: 0 : maList.push_back( ItemConnectionRef( pConnection ) );
308 : 0 : }
309 : :
310 : 0 : void ItemConnectionArrayImpl::ApplyFlags( const SfxItemSet& rItemSet )
311 : : {
312 [ # # ]: 0 : for( ItemConnectionListIt aIt = maList.begin(), aEnd = maList.end(); aIt != aEnd; ++aIt )
313 [ # # ]: 0 : (*aIt)->DoApplyFlags( rItemSet );
314 : 0 : }
315 : :
316 : 0 : void ItemConnectionArrayImpl::Reset( const SfxItemSet& rItemSet )
317 : : {
318 [ # # ]: 0 : for( ItemConnectionListIt aIt = maList.begin(), aEnd = maList.end(); aIt != aEnd; ++aIt )
319 [ # # ]: 0 : (*aIt)->DoReset( rItemSet );
320 : 0 : }
321 : :
322 : 0 : bool ItemConnectionArrayImpl::FillItemSet( SfxItemSet& rDestSet, const SfxItemSet& rOldSet )
323 : : {
324 : 0 : bool bChanged = false;
325 [ # # ]: 0 : for( ItemConnectionListIt aIt = maList.begin(), aEnd = maList.end(); aIt != aEnd; ++aIt )
326 [ # # ]: 0 : bChanged |= (*aIt)->DoFillItemSet( rDestSet, rOldSet );
327 : 0 : return bChanged;
328 : : }
329 : :
330 : : // ----------------------------------------------------------------------------
331 : :
332 : 0 : ItemConnectionArray::ItemConnectionArray() :
333 [ # # ][ # # ]: 0 : mxImpl( new ItemConnectionArrayImpl )
334 : : {
335 : 0 : }
336 : :
337 : 0 : ItemConnectionArray::~ItemConnectionArray()
338 : : {
339 [ # # ]: 0 : }
340 : :
341 : 0 : void ItemConnectionArray::AddConnection( ItemConnectionBase* pConnection )
342 : : {
343 : 0 : mxImpl->Append( pConnection );
344 : 0 : }
345 : :
346 : 0 : void ItemConnectionArray::ApplyFlags( const SfxItemSet& rItemSet )
347 : : {
348 : 0 : mxImpl->ApplyFlags( rItemSet );
349 : 0 : }
350 : :
351 : 0 : void ItemConnectionArray::Reset( const SfxItemSet& rItemSet )
352 : : {
353 : 0 : mxImpl->Reset( rItemSet );
354 : 0 : }
355 : :
356 : 0 : bool ItemConnectionArray::FillItemSet( SfxItemSet& rDestSet, const SfxItemSet& rOldSet )
357 : : {
358 : 0 : return mxImpl->FillItemSet( rDestSet, rOldSet );
359 : : }
360 : :
361 : : // ============================================================================
362 : :
363 : : } // namespace sfx
364 : :
365 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|