File: | home/maarten/src/libreoffice/core/include/rtl/ref.hxx |
Warning: | line 113, column 13 Use of memory after it is freed |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
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 <sal/config.h> | ||||||||||
21 | |||||||||||
22 | #include <string_view> | ||||||||||
23 | |||||||||||
24 | #include <svx/fmgridif.hxx> | ||||||||||
25 | #include <fmprop.hxx> | ||||||||||
26 | #include <fmservs.hxx> | ||||||||||
27 | #include <svx/fmtools.hxx> | ||||||||||
28 | #include <fmurl.hxx> | ||||||||||
29 | #include <formcontrolfactory.hxx> | ||||||||||
30 | #include <gridcell.hxx> | ||||||||||
31 | #include <sdbdatacolumn.hxx> | ||||||||||
32 | #include <svx/fmgridcl.hxx> | ||||||||||
33 | #include <tools/urlobj.hxx> | ||||||||||
34 | |||||||||||
35 | #include <com/sun/star/awt/PosSize.hpp> | ||||||||||
36 | #include <com/sun/star/beans/PropertyAttribute.hpp> | ||||||||||
37 | #include <com/sun/star/form/FormComponentType.hpp> | ||||||||||
38 | #include <com/sun/star/form/XFormComponent.hpp> | ||||||||||
39 | #include <com/sun/star/form/XLoadable.hpp> | ||||||||||
40 | #include <com/sun/star/form/XReset.hpp> | ||||||||||
41 | #include <com/sun/star/lang/DisposedException.hpp> | ||||||||||
42 | #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> | ||||||||||
43 | #include <com/sun/star/lang/NoSupportException.hpp> | ||||||||||
44 | #include <com/sun/star/sdbc/ResultSetType.hpp> | ||||||||||
45 | #include <com/sun/star/sdbcx/XColumnsSupplier.hpp> | ||||||||||
46 | #include <com/sun/star/util/URLTransformer.hpp> | ||||||||||
47 | #include <com/sun/star/util/XURLTransformer.hpp> | ||||||||||
48 | #include <com/sun/star/view/XSelectionSupplier.hpp> | ||||||||||
49 | #include <com/sun/star/sdbcx/XRowLocate.hpp> | ||||||||||
50 | |||||||||||
51 | #include <comphelper/enumhelper.hxx> | ||||||||||
52 | #include <comphelper/processfactory.hxx> | ||||||||||
53 | #include <comphelper/property.hxx> | ||||||||||
54 | #include <comphelper/sequence.hxx> | ||||||||||
55 | #include <comphelper/types.hxx> | ||||||||||
56 | #include <cppuhelper/supportsservice.hxx> | ||||||||||
57 | #include <cppuhelper/queryinterface.hxx> | ||||||||||
58 | #include <vcl/unohelp.hxx> | ||||||||||
59 | #include <vcl/svapp.hxx> | ||||||||||
60 | #include <tools/debug.hxx> | ||||||||||
61 | #include <tools/diagnose_ex.h> | ||||||||||
62 | #include <sal/macros.h> | ||||||||||
63 | |||||||||||
64 | using namespace ::svxform; | ||||||||||
65 | using namespace ::com::sun::star::container; | ||||||||||
66 | using namespace ::com::sun::star::sdb; | ||||||||||
67 | using namespace ::com::sun::star::sdbc; | ||||||||||
68 | using namespace ::com::sun::star::uno; | ||||||||||
69 | using namespace ::com::sun::star::view; | ||||||||||
70 | using namespace ::com::sun::star::beans; | ||||||||||
71 | using namespace ::com::sun::star::lang; | ||||||||||
72 | using namespace ::com::sun::star::form; | ||||||||||
73 | using namespace ::com::sun::star::util; | ||||||||||
74 | using namespace ::com::sun::star; | ||||||||||
75 | |||||||||||
76 | using ::com::sun::star::sdbcx::XColumnsSupplier; | ||||||||||
77 | using ::com::sun::star::frame::XDispatchProviderInterceptor; | ||||||||||
78 | using ::com::sun::star::frame::XDispatchProvider; | ||||||||||
79 | using ::com::sun::star::accessibility::XAccessible; | ||||||||||
80 | using ::com::sun::star::accessibility::XAccessibleContext; | ||||||||||
81 | using ::com::sun::star::sdb::XRowSetSupplier; | ||||||||||
82 | using ::com::sun::star::awt::XVclWindowPeer; | ||||||||||
83 | |||||||||||
84 | |||||||||||
85 | static css::awt::FontDescriptor ImplCreateFontDescriptor( const vcl::Font& rFont ) | ||||||||||
86 | { | ||||||||||
87 | css::awt::FontDescriptor aFD; | ||||||||||
88 | aFD.Name = rFont.GetFamilyName(); | ||||||||||
89 | aFD.StyleName = rFont.GetStyleName(); | ||||||||||
90 | aFD.Height = static_cast<sal_Int16>(rFont.GetFontSize().Height()); | ||||||||||
91 | aFD.Width = static_cast<sal_Int16>(rFont.GetFontSize().Width()); | ||||||||||
92 | aFD.Family = static_cast<sal_Int16>(rFont.GetFamilyType()); | ||||||||||
93 | aFD.CharSet = rFont.GetCharSet(); | ||||||||||
94 | aFD.Pitch = static_cast<sal_Int16>(rFont.GetPitch()); | ||||||||||
95 | aFD.CharacterWidth = vcl::unohelper::ConvertFontWidth( rFont.GetWidthType() ); | ||||||||||
96 | aFD.Weight= vcl::unohelper::ConvertFontWeight( rFont.GetWeight() ); | ||||||||||
97 | aFD.Slant = vcl::unohelper::ConvertFontSlant( rFont.GetItalic() ); | ||||||||||
98 | aFD.Underline = static_cast<sal_Int16>(rFont.GetUnderline()); | ||||||||||
99 | aFD.Strikeout = static_cast<sal_Int16>(rFont.GetStrikeout()); | ||||||||||
100 | aFD.Orientation = rFont.GetOrientation(); | ||||||||||
101 | aFD.Kerning = rFont.IsKerning(); | ||||||||||
102 | aFD.WordLineMode = rFont.IsWordLineMode(); | ||||||||||
103 | aFD.Type = 0; // ??? => only to metric... | ||||||||||
104 | return aFD; | ||||||||||
105 | } | ||||||||||
106 | |||||||||||
107 | |||||||||||
108 | static vcl::Font ImplCreateFont( const css::awt::FontDescriptor& rDescr ) | ||||||||||
109 | { | ||||||||||
110 | vcl::Font aFont; | ||||||||||
111 | aFont.SetFamilyName( rDescr.Name ); | ||||||||||
112 | aFont.SetStyleName( rDescr.StyleName ); | ||||||||||
113 | aFont.SetFontSize( ::Size( rDescr.Width, rDescr.Height ) ); | ||||||||||
114 | aFont.SetFamily( static_cast<FontFamily>(rDescr.Family) ); | ||||||||||
115 | aFont.SetCharSet( static_cast<rtl_TextEncoding>(rDescr.CharSet) ); | ||||||||||
116 | aFont.SetPitch( static_cast<FontPitch>(rDescr.Pitch) ); | ||||||||||
117 | aFont.SetWidthType( vcl::unohelper::ConvertFontWidth( rDescr.CharacterWidth ) ); | ||||||||||
118 | aFont.SetWeight( vcl::unohelper::ConvertFontWeight( rDescr.Weight ) ); | ||||||||||
119 | aFont.SetItalic( static_cast<FontItalic>(rDescr.Slant) ); | ||||||||||
120 | aFont.SetUnderline( static_cast<::FontLineStyle>(rDescr.Underline) ); | ||||||||||
121 | aFont.SetStrikeout( static_cast<::FontStrikeout>(rDescr.Strikeout) ); | ||||||||||
122 | aFont.SetOrientation( static_cast<sal_Int16>(rDescr.Orientation) ); | ||||||||||
123 | aFont.SetKerning( static_cast<FontKerning>(rDescr.Kerning) ); | ||||||||||
124 | aFont.SetWordLineMode( rDescr.WordLineMode ); | ||||||||||
125 | return aFont; | ||||||||||
126 | } | ||||||||||
127 | |||||||||||
128 | FmXModifyMultiplexer::FmXModifyMultiplexer( ::cppu::OWeakObject& rSource, ::osl::Mutex& _rMutex ) | ||||||||||
129 | :OWeakSubObject( rSource ) | ||||||||||
130 | ,OInterfaceContainerHelper2( _rMutex ) | ||||||||||
131 | { | ||||||||||
132 | } | ||||||||||
133 | |||||||||||
134 | |||||||||||
135 | Any SAL_CALL FmXModifyMultiplexer::queryInterface(const Type& _rType) | ||||||||||
136 | { | ||||||||||
137 | Any aReturn = ::cppu::queryInterface(_rType, | ||||||||||
138 | static_cast< css::util::XModifyListener*>(this), | ||||||||||
139 | static_cast< XEventListener*>(this) | ||||||||||
140 | ); | ||||||||||
141 | |||||||||||
142 | if (!aReturn.hasValue()) | ||||||||||
143 | aReturn = OWeakSubObject::queryInterface( _rType ); | ||||||||||
144 | |||||||||||
145 | return aReturn; | ||||||||||
146 | } | ||||||||||
147 | |||||||||||
148 | |||||||||||
149 | void FmXModifyMultiplexer::disposing(const EventObject& ) | ||||||||||
150 | { | ||||||||||
151 | } | ||||||||||
152 | |||||||||||
153 | |||||||||||
154 | void FmXModifyMultiplexer::modified(const EventObject& e) | ||||||||||
155 | { | ||||||||||
156 | EventObject aMulti( e); | ||||||||||
157 | aMulti.Source = &m_rParent; | ||||||||||
158 | notifyEach( &XModifyListener::modified, aMulti ); | ||||||||||
159 | } | ||||||||||
160 | |||||||||||
161 | FmXUpdateMultiplexer::FmXUpdateMultiplexer( ::cppu::OWeakObject& rSource, ::osl::Mutex& _rMutex ) | ||||||||||
162 | :OWeakSubObject( rSource ) | ||||||||||
163 | ,OInterfaceContainerHelper2( _rMutex ) | ||||||||||
164 | { | ||||||||||
165 | } | ||||||||||
166 | |||||||||||
167 | |||||||||||
168 | Any SAL_CALL FmXUpdateMultiplexer::queryInterface(const Type& _rType) | ||||||||||
169 | { | ||||||||||
170 | Any aReturn = ::cppu::queryInterface(_rType, | ||||||||||
171 | static_cast< XUpdateListener*>(this), | ||||||||||
172 | static_cast< XEventListener*>(this) | ||||||||||
173 | ); | ||||||||||
174 | |||||||||||
175 | if (!aReturn.hasValue()) | ||||||||||
176 | aReturn = OWeakSubObject::queryInterface( _rType ); | ||||||||||
177 | |||||||||||
178 | return aReturn; | ||||||||||
179 | } | ||||||||||
180 | |||||||||||
181 | |||||||||||
182 | void FmXUpdateMultiplexer::disposing(const EventObject& ) | ||||||||||
183 | { | ||||||||||
184 | } | ||||||||||
185 | |||||||||||
186 | |||||||||||
187 | sal_Bool FmXUpdateMultiplexer::approveUpdate(const EventObject &e) | ||||||||||
188 | { | ||||||||||
189 | EventObject aMulti( e ); | ||||||||||
190 | aMulti.Source = &m_rParent; | ||||||||||
191 | |||||||||||
192 | bool bResult = true; | ||||||||||
193 | if (getLength()) | ||||||||||
194 | { | ||||||||||
195 | ::comphelper::OInterfaceIteratorHelper2 aIter(*this); | ||||||||||
196 | while ( bResult && aIter.hasMoreElements() ) | ||||||||||
197 | bResult = static_cast< XUpdateListener* >( aIter.next() )->approveUpdate( aMulti ); | ||||||||||
198 | } | ||||||||||
199 | |||||||||||
200 | return bResult; | ||||||||||
201 | } | ||||||||||
202 | |||||||||||
203 | |||||||||||
204 | void FmXUpdateMultiplexer::updated(const EventObject &e) | ||||||||||
205 | { | ||||||||||
206 | EventObject aMulti( e ); | ||||||||||
207 | aMulti.Source = &m_rParent; | ||||||||||
208 | notifyEach( &XUpdateListener::updated, aMulti ); | ||||||||||
209 | } | ||||||||||
210 | |||||||||||
211 | FmXSelectionMultiplexer::FmXSelectionMultiplexer( ::cppu::OWeakObject& rSource, ::osl::Mutex& _rMutex ) | ||||||||||
212 | :OWeakSubObject( rSource ) | ||||||||||
213 | ,OInterfaceContainerHelper2( _rMutex ) | ||||||||||
214 | { | ||||||||||
215 | } | ||||||||||
216 | |||||||||||
217 | |||||||||||
218 | Any SAL_CALL FmXSelectionMultiplexer::queryInterface(const Type& _rType) | ||||||||||
219 | { | ||||||||||
220 | Any aReturn = ::cppu::queryInterface(_rType, | ||||||||||
221 | static_cast< XSelectionChangeListener*>(this), | ||||||||||
222 | static_cast< XEventListener*>(this) | ||||||||||
223 | ); | ||||||||||
224 | |||||||||||
225 | if (!aReturn.hasValue()) | ||||||||||
226 | aReturn = OWeakSubObject::queryInterface( _rType ); | ||||||||||
227 | |||||||||||
228 | return aReturn; | ||||||||||
229 | } | ||||||||||
230 | |||||||||||
231 | |||||||||||
232 | void FmXSelectionMultiplexer::disposing(const EventObject& ) | ||||||||||
233 | { | ||||||||||
234 | } | ||||||||||
235 | |||||||||||
236 | |||||||||||
237 | void SAL_CALL FmXSelectionMultiplexer::selectionChanged( const EventObject& _rEvent ) | ||||||||||
238 | { | ||||||||||
239 | EventObject aMulti(_rEvent); | ||||||||||
240 | aMulti.Source = &m_rParent; | ||||||||||
241 | notifyEach( &XSelectionChangeListener::selectionChanged, aMulti ); | ||||||||||
242 | } | ||||||||||
243 | |||||||||||
244 | FmXContainerMultiplexer::FmXContainerMultiplexer( ::cppu::OWeakObject& rSource, ::osl::Mutex& _rMutex ) | ||||||||||
245 | :OWeakSubObject( rSource ) | ||||||||||
246 | ,OInterfaceContainerHelper2( _rMutex ) | ||||||||||
247 | { | ||||||||||
248 | } | ||||||||||
249 | |||||||||||
250 | |||||||||||
251 | Any SAL_CALL FmXContainerMultiplexer::queryInterface(const Type& _rType) | ||||||||||
252 | { | ||||||||||
253 | Any aReturn = ::cppu::queryInterface(_rType, | ||||||||||
254 | static_cast< XContainerListener*>(this), | ||||||||||
255 | static_cast< XEventListener*>(this) | ||||||||||
256 | ); | ||||||||||
257 | |||||||||||
258 | if (!aReturn.hasValue()) | ||||||||||
259 | aReturn = OWeakSubObject::queryInterface( _rType ); | ||||||||||
260 | |||||||||||
261 | return aReturn; | ||||||||||
262 | } | ||||||||||
263 | |||||||||||
264 | |||||||||||
265 | void FmXContainerMultiplexer::disposing(const EventObject& ) | ||||||||||
266 | { | ||||||||||
267 | } | ||||||||||
268 | |||||||||||
269 | void FmXContainerMultiplexer::elementInserted(const ContainerEvent& e) | ||||||||||
270 | { | ||||||||||
271 | ContainerEvent aMulti( e ); | ||||||||||
272 | aMulti.Source = &m_rParent; | ||||||||||
273 | notifyEach( &XContainerListener::elementInserted, aMulti ); | ||||||||||
274 | } | ||||||||||
275 | |||||||||||
276 | |||||||||||
277 | void FmXContainerMultiplexer::elementRemoved(const ContainerEvent& e) | ||||||||||
278 | { | ||||||||||
279 | ContainerEvent aMulti( e ); | ||||||||||
280 | aMulti.Source = &m_rParent; | ||||||||||
281 | notifyEach( &XContainerListener::elementRemoved, aMulti ); | ||||||||||
282 | } | ||||||||||
283 | |||||||||||
284 | |||||||||||
285 | void FmXContainerMultiplexer::elementReplaced(const ContainerEvent& e) | ||||||||||
286 | { | ||||||||||
287 | ContainerEvent aMulti( e ); | ||||||||||
288 | aMulti.Source = &m_rParent; | ||||||||||
289 | notifyEach( &XContainerListener::elementReplaced, aMulti ); | ||||||||||
290 | } | ||||||||||
291 | |||||||||||
292 | FmXGridControlMultiplexer::FmXGridControlMultiplexer( ::cppu::OWeakObject& rSource, ::osl::Mutex& _rMutex ) | ||||||||||
293 | :OWeakSubObject( rSource ) | ||||||||||
294 | ,OInterfaceContainerHelper2( _rMutex ) | ||||||||||
295 | { | ||||||||||
296 | } | ||||||||||
297 | |||||||||||
298 | |||||||||||
299 | Any SAL_CALL FmXGridControlMultiplexer::queryInterface(const Type& _rType) | ||||||||||
300 | { | ||||||||||
301 | Any aReturn = ::cppu::queryInterface( _rType, | ||||||||||
302 | static_cast< XGridControlListener*>(this) | ||||||||||
303 | ); | ||||||||||
304 | |||||||||||
305 | if (!aReturn.hasValue()) | ||||||||||
306 | aReturn = OWeakSubObject::queryInterface( _rType ); | ||||||||||
307 | |||||||||||
308 | return aReturn; | ||||||||||
309 | } | ||||||||||
310 | |||||||||||
311 | |||||||||||
312 | void FmXGridControlMultiplexer::disposing( const EventObject& ) | ||||||||||
313 | { | ||||||||||
314 | } | ||||||||||
315 | |||||||||||
316 | |||||||||||
317 | void SAL_CALL FmXGridControlMultiplexer::columnChanged( const EventObject& _event ) | ||||||||||
318 | { | ||||||||||
319 | EventObject aForwardedEvent( _event ); | ||||||||||
320 | aForwardedEvent.Source = &m_rParent; | ||||||||||
321 | notifyEach( &XGridControlListener::columnChanged, aForwardedEvent ); | ||||||||||
322 | } | ||||||||||
323 | |||||||||||
324 | |||||||||||
325 | //= FmXGridControl | ||||||||||
326 | |||||||||||
327 | |||||||||||
328 | Reference< XInterface > FmXGridControl_NewInstance_Impl(const Reference< XMultiServiceFactory>& _rxFactory) | ||||||||||
329 | { | ||||||||||
330 | return *(new FmXGridControl( comphelper::getComponentContext(_rxFactory) )); | ||||||||||
331 | } | ||||||||||
332 | |||||||||||
333 | FmXGridControl::FmXGridControl(const Reference< XComponentContext >& _rxContext) | ||||||||||
334 | :UnoControl() | ||||||||||
335 | ,m_aModifyListeners(*this, GetMutex()) | ||||||||||
336 | ,m_aUpdateListeners(*this, GetMutex()) | ||||||||||
337 | ,m_aContainerListeners(*this, GetMutex()) | ||||||||||
338 | ,m_aSelectionListeners(*this, GetMutex()) | ||||||||||
339 | ,m_aGridControlListeners(*this, GetMutex()) | ||||||||||
340 | ,m_bInDraw(false) | ||||||||||
341 | ,m_xContext(_rxContext) | ||||||||||
342 | { | ||||||||||
343 | } | ||||||||||
344 | |||||||||||
345 | |||||||||||
346 | FmXGridControl::~FmXGridControl() | ||||||||||
347 | { | ||||||||||
348 | } | ||||||||||
349 | |||||||||||
350 | |||||||||||
351 | Any SAL_CALL FmXGridControl::queryAggregation(const Type& _rType) | ||||||||||
352 | { | ||||||||||
353 | Any aReturn = FmXGridControl_BASE::queryInterface(_rType); | ||||||||||
354 | |||||||||||
355 | if (!aReturn.hasValue()) | ||||||||||
356 | aReturn = UnoControl::queryAggregation( _rType ); | ||||||||||
357 | return aReturn; | ||||||||||
358 | } | ||||||||||
359 | |||||||||||
360 | |||||||||||
361 | Sequence< Type> SAL_CALL FmXGridControl::getTypes( ) | ||||||||||
362 | { | ||||||||||
363 | return comphelper::concatSequences(UnoControl::getTypes(),FmXGridControl_BASE::getTypes()); | ||||||||||
364 | } | ||||||||||
365 | |||||||||||
366 | |||||||||||
367 | Sequence<sal_Int8> SAL_CALL FmXGridControl::getImplementationId( ) | ||||||||||
368 | { | ||||||||||
369 | return css::uno::Sequence<sal_Int8>(); | ||||||||||
370 | } | ||||||||||
371 | |||||||||||
372 | // XServiceInfo | ||||||||||
373 | sal_Bool SAL_CALL FmXGridControl::supportsService(const OUString& ServiceName) | ||||||||||
374 | { | ||||||||||
375 | return cppu::supportsService(this, ServiceName); | ||||||||||
376 | } | ||||||||||
377 | |||||||||||
378 | OUString SAL_CALL FmXGridControl::getImplementationName() | ||||||||||
379 | { | ||||||||||
380 | return "com.sun.star.form.FmXGridControl"; | ||||||||||
381 | } | ||||||||||
382 | |||||||||||
383 | css::uno::Sequence<OUString> SAL_CALL FmXGridControl::getSupportedServiceNames() | ||||||||||
384 | { | ||||||||||
385 | return { FM_SUN_CONTROL_GRIDCONTROL"com.sun.star.form.control.GridControl", "com.sun.star.awt.UnoControl" }; | ||||||||||
386 | } | ||||||||||
387 | |||||||||||
388 | |||||||||||
389 | void SAL_CALL FmXGridControl::dispose() | ||||||||||
390 | { | ||||||||||
391 | SolarMutexGuard aGuard; | ||||||||||
392 | |||||||||||
393 | EventObject aEvt; | ||||||||||
394 | aEvt.Source = static_cast< ::cppu::OWeakObject* >(this); | ||||||||||
395 | m_aModifyListeners.disposeAndClear(aEvt); | ||||||||||
396 | m_aUpdateListeners.disposeAndClear(aEvt); | ||||||||||
397 | m_aContainerListeners.disposeAndClear(aEvt); | ||||||||||
398 | |||||||||||
399 | UnoControl::dispose(); | ||||||||||
400 | } | ||||||||||
401 | |||||||||||
402 | |||||||||||
403 | OUString FmXGridControl::GetComponentServiceName() | ||||||||||
404 | { | ||||||||||
405 | return "DBGrid"; | ||||||||||
406 | } | ||||||||||
407 | |||||||||||
408 | |||||||||||
409 | sal_Bool SAL_CALL FmXGridControl::setModel(const Reference< css::awt::XControlModel >& rModel) | ||||||||||
410 | { | ||||||||||
411 | SolarMutexGuard aGuard; | ||||||||||
412 | |||||||||||
413 | if (!UnoControl::setModel(rModel)) | ||||||||||
414 | return false; | ||||||||||
415 | |||||||||||
416 | Reference< XGridPeer > xGridPeer(getPeer(), UNO_QUERY); | ||||||||||
417 | if (xGridPeer.is()) | ||||||||||
418 | { | ||||||||||
419 | Reference< XIndexContainer > xCols(mxModel, UNO_QUERY); | ||||||||||
420 | xGridPeer->setColumns(xCols); | ||||||||||
421 | } | ||||||||||
422 | return true; | ||||||||||
423 | } | ||||||||||
424 | |||||||||||
425 | |||||||||||
426 | FmXGridPeer* FmXGridControl::imp_CreatePeer(vcl::Window* pParent) | ||||||||||
427 | { | ||||||||||
428 | FmXGridPeer* pReturn = new FmXGridPeer(m_xContext); | ||||||||||
429 | |||||||||||
430 | // translate properties into WinBits | ||||||||||
431 | WinBits nStyle = WB_TABSTOP; | ||||||||||
432 | Reference< XPropertySet > xModelSet(getModel(), UNO_QUERY); | ||||||||||
433 | if (xModelSet.is()) | ||||||||||
434 | { | ||||||||||
435 | try | ||||||||||
436 | { | ||||||||||
437 | if (::comphelper::getINT16(xModelSet->getPropertyValue(FM_PROP_BORDER"Border"))) | ||||||||||
438 | nStyle |= WB_BORDER; | ||||||||||
439 | } | ||||||||||
440 | catch(const Exception&) | ||||||||||
441 | { | ||||||||||
442 | OSL_FAIL("Can not get style")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/svx/source/fmcomp/fmgridif.cxx" ":" "442" ": "), "%s", "Can not get style"); } } while (false ); | ||||||||||
443 | } | ||||||||||
444 | } | ||||||||||
445 | |||||||||||
446 | pReturn->Create(pParent, nStyle); | ||||||||||
447 | return pReturn; | ||||||||||
448 | } | ||||||||||
449 | |||||||||||
450 | |||||||||||
451 | void SAL_CALL FmXGridControl::createPeer(const Reference< css::awt::XToolkit >& /*rToolkit*/, const Reference< css::awt::XWindowPeer >& rParentPeer) | ||||||||||
452 | { | ||||||||||
453 | if ( !mxModel.is() ) | ||||||||||
454 | throw DisposedException( OUString(), *this ); | ||||||||||
455 | |||||||||||
456 | DBG_ASSERT(/*(0 == m_nPeerCreationLevel) && */!mbCreatingPeer, "FmXGridControl::createPeer : recursion!")do { if (true && (!(!mbCreatingPeer))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/svx/source/fmcomp/fmgridif.cxx" ":" "456" ": "), "%s", "FmXGridControl::createPeer : recursion!" ); } } while (false); | ||||||||||
457 | // I think this should never assert, now that we're using the base class' mbCreatingPeer in addition to | ||||||||||
458 | // our own m_nPeerCreationLevel | ||||||||||
459 | // But I'm not sure as I don't _fully_ understand the underlying toolkit implementations... | ||||||||||
460 | // (if this asserts, we still need m_nPeerCreationLevel. If not, we could omit it...) | ||||||||||
461 | // 14.05.2001 - 86836 - frank.schoenheit@germany.sun.com | ||||||||||
462 | |||||||||||
463 | // TODO: why the hell this whole class does not use any mutex? | ||||||||||
464 | |||||||||||
465 | if (getPeer().is()) | ||||||||||
466 | return; | ||||||||||
467 | |||||||||||
468 | mbCreatingPeer = true; | ||||||||||
469 | // mbCreatingPeer is virtually the same as m_nPeerCreationLevel, but it's the base class' method | ||||||||||
470 | // to prevent recursion. | ||||||||||
471 | |||||||||||
472 | vcl::Window* pParentWin = nullptr; | ||||||||||
473 | if (rParentPeer.is()) | ||||||||||
474 | { | ||||||||||
475 | VCLXWindow* pParent = comphelper::getUnoTunnelImplementation<VCLXWindow>(rParentPeer); | ||||||||||
476 | if (pParent) | ||||||||||
477 | pParentWin = pParent->GetWindow().get(); | ||||||||||
478 | } | ||||||||||
479 | |||||||||||
480 | FmXGridPeer* pPeer = imp_CreatePeer(pParentWin); | ||||||||||
481 | DBG_ASSERT(pPeer != nullptr, "FmXGridControl::createPeer : imp_CreatePeer didn't return a peer !")do { if (true && (!(pPeer != nullptr))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/svx/source/fmcomp/fmgridif.cxx" ":" "481" ": "), "%s", "FmXGridControl::createPeer : imp_CreatePeer didn't return a peer !" ); } } while (false); | ||||||||||
482 | setPeer( pPeer ); | ||||||||||
483 | |||||||||||
484 | // reading the properties from the model | ||||||||||
485 | // ++m_nPeerCreationLevel; | ||||||||||
486 | updateFromModel(); | ||||||||||
487 | |||||||||||
488 | // consider the following ugly scenario: updateFromModel leads to a propertiesChanges on the Control, | ||||||||||
489 | // which determines, dat a "critical" property has changed (e.g. "Border") and therefore starts a new | ||||||||||
490 | // Peer, which lands again here in createPeer we also start a second FmXGridPeer and initialise it. | ||||||||||
491 | // Then we exit from the first incarnation's updateFromModel and continue working with the pPeer, | ||||||||||
492 | // that is in fact now already obsolete (as another peer is being started in the second incarnation). | ||||||||||
493 | // Therefore the effort with the PeerCreationLevel, which ensures that we really use the Peer | ||||||||||
494 | // created at the deepest level, but first initialise it in the top-level. | ||||||||||
495 | // if (--m_nPeerCreationLevel == 0) | ||||||||||
496 | { | ||||||||||
497 | DBG_ASSERT(getPeer().is(), "FmXGridControl::createPeer : something went wrong ... no top level peer !")do { if (true && (!(getPeer().is()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/svx/source/fmcomp/fmgridif.cxx" ":" "497" ": "), "%s", "FmXGridControl::createPeer : something went wrong ... no top level peer !" ); } } while (false); | ||||||||||
498 | pPeer = comphelper::getUnoTunnelImplementation<FmXGridPeer>(getPeer()); | ||||||||||
499 | |||||||||||
500 | setPosSize( maComponentInfos.nX, maComponentInfos.nY, maComponentInfos.nWidth, maComponentInfos.nHeight, css::awt::PosSize::POSSIZE ); | ||||||||||
501 | |||||||||||
502 | Reference< XIndexContainer > xColumns(getModel(), UNO_QUERY); | ||||||||||
503 | if (xColumns.is()) | ||||||||||
504 | pPeer->setColumns(xColumns); | ||||||||||
505 | |||||||||||
506 | if (maComponentInfos.bVisible) | ||||||||||
507 | pPeer->setVisible(true); | ||||||||||
508 | |||||||||||
509 | if (!maComponentInfos.bEnable) | ||||||||||
510 | pPeer->setEnable(false); | ||||||||||
511 | |||||||||||
512 | if (maWindowListeners.getLength()) | ||||||||||
513 | pPeer->addWindowListener( &maWindowListeners ); | ||||||||||
514 | |||||||||||
515 | if (maFocusListeners.getLength()) | ||||||||||
516 | pPeer->addFocusListener( &maFocusListeners ); | ||||||||||
517 | |||||||||||
518 | if (maKeyListeners.getLength()) | ||||||||||
519 | pPeer->addKeyListener( &maKeyListeners ); | ||||||||||
520 | |||||||||||
521 | if (maMouseListeners.getLength()) | ||||||||||
522 | pPeer->addMouseListener( &maMouseListeners ); | ||||||||||
523 | |||||||||||
524 | if (maMouseMotionListeners.getLength()) | ||||||||||
525 | pPeer->addMouseMotionListener( &maMouseMotionListeners ); | ||||||||||
526 | |||||||||||
527 | if (maPaintListeners.getLength()) | ||||||||||
528 | pPeer->addPaintListener( &maPaintListeners ); | ||||||||||
529 | |||||||||||
530 | if (m_aModifyListeners.getLength()) | ||||||||||
531 | pPeer->addModifyListener( &m_aModifyListeners ); | ||||||||||
532 | |||||||||||
533 | if (m_aUpdateListeners.getLength()) | ||||||||||
534 | pPeer->addUpdateListener( &m_aUpdateListeners ); | ||||||||||
535 | |||||||||||
536 | if (m_aContainerListeners.getLength()) | ||||||||||
537 | pPeer->addContainerListener( &m_aContainerListeners ); | ||||||||||
538 | |||||||||||
539 | // forward the design mode | ||||||||||
540 | bool bForceAlivePeer = m_bInDraw && !maComponentInfos.bVisible; | ||||||||||
541 | // (we force an alive-mode peer if we're in "draw", cause in this case the peer will be used for drawing in | ||||||||||
542 | // foreign devices. We ensure this with the visibility check as a living peer is assumed to be noncritical | ||||||||||
543 | // only if invisible) | ||||||||||
544 | Any aOldCursorBookmark; | ||||||||||
545 | if (!mbDesignMode || bForceAlivePeer) | ||||||||||
546 | { | ||||||||||
547 | Reference< XFormComponent > xComp(getModel(), UNO_QUERY); | ||||||||||
548 | if (xComp.is()) | ||||||||||
549 | { | ||||||||||
550 | Reference< XRowSet > xForm(xComp->getParent(), UNO_QUERY); | ||||||||||
551 | // is the form alive? | ||||||||||
552 | // we can see that if the form contains columns | ||||||||||
553 | Reference< css::sdbcx::XColumnsSupplier > xColumnsSupplier(xForm, UNO_QUERY); | ||||||||||
554 | if (xColumnsSupplier.is()) | ||||||||||
555 | { | ||||||||||
556 | if (Reference< XIndexAccess > (xColumnsSupplier->getColumns(),UNO_QUERY_THROW)->getCount()) | ||||||||||
557 | { | ||||||||||
558 | // we get only a new bookmark if the resultset is not forwardonly | ||||||||||
559 | if (::comphelper::getINT32(Reference< XPropertySet > (xForm, UNO_QUERY_THROW)->getPropertyValue(FM_PROP_RESULTSET_TYPE"ResultSetType")) != ResultSetType::FORWARD_ONLY) | ||||||||||
560 | { | ||||||||||
561 | // as the FmGridControl touches the data source it is connected to we have to remember the current | ||||||||||
562 | // cursor position (and restore afterwards) | ||||||||||
563 | // OJ: but only when we stand on a valid row | ||||||||||
564 | if ( !xForm->isBeforeFirst() && !xForm->isAfterLast() ) | ||||||||||
565 | { | ||||||||||
566 | try | ||||||||||
567 | { | ||||||||||
568 | aOldCursorBookmark = Reference< css::sdbcx::XRowLocate > (xForm, UNO_QUERY_THROW)->getBookmark(); | ||||||||||
569 | } | ||||||||||
570 | catch( const Exception& ) | ||||||||||
571 | { | ||||||||||
572 | DBG_UNHANDLED_EXCEPTION("svx")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/svx/source/fmcomp/fmgridif.cxx" ":" "572" ": ", "svx" );; | ||||||||||
573 | } | ||||||||||
574 | } | ||||||||||
575 | } | ||||||||||
576 | } | ||||||||||
577 | } | ||||||||||
578 | pPeer->setRowSet(xForm); | ||||||||||
579 | } | ||||||||||
580 | } | ||||||||||
581 | pPeer->setDesignMode(mbDesignMode && !bForceAlivePeer); | ||||||||||
582 | |||||||||||
583 | try | ||||||||||
584 | { | ||||||||||
585 | if (aOldCursorBookmark.hasValue()) | ||||||||||
586 | { // we have a valid bookmark, so we have to restore the cursor's position | ||||||||||
587 | Reference< XFormComponent > xComp(getModel(), UNO_QUERY); | ||||||||||
588 | Reference< css::sdbcx::XRowLocate > xLocate(xComp->getParent(), UNO_QUERY); | ||||||||||
589 | xLocate->moveToBookmark(aOldCursorBookmark); | ||||||||||
590 | } | ||||||||||
591 | } | ||||||||||
592 | catch( const Exception& ) | ||||||||||
593 | { | ||||||||||
594 | DBG_UNHANDLED_EXCEPTION("svx")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/svx/source/fmcomp/fmgridif.cxx" ":" "594" ": ", "svx" );; | ||||||||||
595 | } | ||||||||||
596 | |||||||||||
597 | Reference< css::awt::XView > xPeerView(getPeer(), UNO_QUERY); | ||||||||||
598 | xPeerView->setZoom( maComponentInfos.nZoomX, maComponentInfos.nZoomY ); | ||||||||||
599 | xPeerView->setGraphics( mxGraphics ); | ||||||||||
600 | } | ||||||||||
601 | mbCreatingPeer = false; | ||||||||||
602 | } | ||||||||||
603 | |||||||||||
604 | |||||||||||
605 | void FmXGridControl::addModifyListener(const Reference< css::util::XModifyListener >& l) | ||||||||||
606 | { | ||||||||||
607 | m_aModifyListeners.addInterface( l ); | ||||||||||
608 | if( getPeer().is() && m_aModifyListeners.getLength() == 1 ) | ||||||||||
609 | { | ||||||||||
610 | Reference< css::util::XModifyBroadcaster > xGrid(getPeer(), UNO_QUERY); | ||||||||||
611 | xGrid->addModifyListener( &m_aModifyListeners); | ||||||||||
612 | } | ||||||||||
613 | } | ||||||||||
614 | |||||||||||
615 | |||||||||||
616 | sal_Bool SAL_CALL FmXGridControl::select( const Any& _rSelection ) | ||||||||||
617 | { | ||||||||||
618 | SolarMutexGuard aGuard; | ||||||||||
619 | Reference< XSelectionSupplier > xPeer(getPeer(), UNO_QUERY); | ||||||||||
620 | return xPeer->select(_rSelection); | ||||||||||
621 | } | ||||||||||
622 | |||||||||||
623 | |||||||||||
624 | Any SAL_CALL FmXGridControl::getSelection( ) | ||||||||||
625 | { | ||||||||||
626 | SolarMutexGuard aGuard; | ||||||||||
627 | Reference< XSelectionSupplier > xPeer(getPeer(), UNO_QUERY); | ||||||||||
628 | return xPeer->getSelection(); | ||||||||||
629 | } | ||||||||||
630 | |||||||||||
631 | |||||||||||
632 | void SAL_CALL FmXGridControl::addSelectionChangeListener( const Reference< XSelectionChangeListener >& _rxListener ) | ||||||||||
633 | { | ||||||||||
634 | m_aSelectionListeners.addInterface( _rxListener ); | ||||||||||
635 | if( getPeer().is() && 1 == m_aSelectionListeners.getLength() ) | ||||||||||
636 | { | ||||||||||
637 | Reference< XSelectionSupplier > xGrid(getPeer(), UNO_QUERY); | ||||||||||
638 | xGrid->addSelectionChangeListener( &m_aSelectionListeners); | ||||||||||
639 | } | ||||||||||
640 | } | ||||||||||
641 | |||||||||||
642 | |||||||||||
643 | void SAL_CALL FmXGridControl::removeSelectionChangeListener( const Reference< XSelectionChangeListener >& _rxListener ) | ||||||||||
644 | { | ||||||||||
645 | if( getPeer().is() && 1 == m_aSelectionListeners.getLength() ) | ||||||||||
646 | { | ||||||||||
647 | Reference< XSelectionSupplier > xGrid(getPeer(), UNO_QUERY); | ||||||||||
648 | xGrid->removeSelectionChangeListener( &m_aSelectionListeners); | ||||||||||
649 | } | ||||||||||
650 | m_aSelectionListeners.removeInterface( _rxListener ); | ||||||||||
651 | } | ||||||||||
652 | |||||||||||
653 | |||||||||||
654 | Sequence< sal_Bool > SAL_CALL FmXGridControl::queryFieldDataType( const Type& xType ) | ||||||||||
655 | { | ||||||||||
656 | if (getPeer().is()) | ||||||||||
657 | { | ||||||||||
658 | Reference< XGridFieldDataSupplier > xPeerSupplier(getPeer(), UNO_QUERY); | ||||||||||
659 | if (xPeerSupplier.is()) | ||||||||||
660 | return xPeerSupplier->queryFieldDataType(xType); | ||||||||||
661 | } | ||||||||||
662 | |||||||||||
663 | return Sequence<sal_Bool>(); | ||||||||||
664 | } | ||||||||||
665 | |||||||||||
666 | |||||||||||
667 | Sequence< Any > SAL_CALL FmXGridControl::queryFieldData( sal_Int32 nRow, const Type& xType ) | ||||||||||
668 | { | ||||||||||
669 | if (getPeer().is()) | ||||||||||
670 | { | ||||||||||
671 | Reference< XGridFieldDataSupplier > xPeerSupplier(getPeer(), UNO_QUERY); | ||||||||||
672 | if (xPeerSupplier.is()) | ||||||||||
673 | return xPeerSupplier->queryFieldData(nRow, xType); | ||||||||||
674 | } | ||||||||||
675 | |||||||||||
676 | return Sequence< Any>(); | ||||||||||
677 | } | ||||||||||
678 | |||||||||||
679 | |||||||||||
680 | void SAL_CALL FmXGridControl::removeModifyListener(const Reference< css::util::XModifyListener >& l) | ||||||||||
681 | { | ||||||||||
682 | if( getPeer().is() && m_aModifyListeners.getLength() == 1 ) | ||||||||||
683 | { | ||||||||||
684 | Reference< css::util::XModifyBroadcaster > xGrid(getPeer(), UNO_QUERY); | ||||||||||
685 | xGrid->removeModifyListener( &m_aModifyListeners); | ||||||||||
686 | } | ||||||||||
687 | m_aModifyListeners.removeInterface( l ); | ||||||||||
688 | } | ||||||||||
689 | |||||||||||
690 | |||||||||||
691 | void SAL_CALL FmXGridControl::draw( sal_Int32 x, sal_Int32 y ) | ||||||||||
692 | { | ||||||||||
693 | SolarMutexGuard aGuard; | ||||||||||
694 | m_bInDraw = true; | ||||||||||
695 | UnoControl::draw(x, y); | ||||||||||
696 | m_bInDraw = false; | ||||||||||
697 | } | ||||||||||
698 | |||||||||||
699 | |||||||||||
700 | void SAL_CALL FmXGridControl::setDesignMode(sal_Bool bOn) | ||||||||||
701 | { | ||||||||||
702 | css::util::ModeChangeEvent aModeChangeEvent; | ||||||||||
703 | |||||||||||
704 | // --- <mutex_lock> --- | ||||||||||
705 | { | ||||||||||
706 | SolarMutexGuard aGuard; | ||||||||||
707 | |||||||||||
708 | Reference< XRowSetSupplier > xGrid(getPeer(), UNO_QUERY); | ||||||||||
709 | |||||||||||
710 | if (xGrid.is() && (bool(bOn) != mbDesignMode || (!bOn && !xGrid->getRowSet().is()))) | ||||||||||
711 | { | ||||||||||
712 | if (bOn) | ||||||||||
713 | { | ||||||||||
714 | xGrid->setRowSet(Reference< XRowSet > ()); | ||||||||||
715 | } | ||||||||||
716 | else | ||||||||||
717 | { | ||||||||||
718 | Reference< XFormComponent > xComp(getModel(), UNO_QUERY); | ||||||||||
719 | if (xComp.is()) | ||||||||||
720 | { | ||||||||||
721 | Reference< XRowSet > xForm(xComp->getParent(), UNO_QUERY); | ||||||||||
722 | xGrid->setRowSet(xForm); | ||||||||||
723 | } | ||||||||||
724 | } | ||||||||||
725 | |||||||||||
726 | // Avoid infinite recursion when calling XVclWindowPeer::setDesignMode below | ||||||||||
727 | mbDesignMode = bOn; | ||||||||||
728 | |||||||||||
729 | Reference< XVclWindowPeer > xVclWindowPeer( getPeer(), UNO_QUERY ); | ||||||||||
730 | if (xVclWindowPeer.is()) | ||||||||||
731 | xVclWindowPeer->setDesignMode(bOn); | ||||||||||
732 | } | ||||||||||
733 | else | ||||||||||
734 | { | ||||||||||
735 | mbDesignMode = bOn; | ||||||||||
736 | } | ||||||||||
737 | |||||||||||
738 | // dispose our current AccessibleContext, if we have one | ||||||||||
739 | // (changing the design mode implies having a new implementation for this context, | ||||||||||
740 | // so the old one must be declared DEFUNC) | ||||||||||
741 | DisposeAccessibleContext( | ||||||||||
742 | Reference<XComponent>(maAccessibleContext, UNO_QUERY)); | ||||||||||
743 | maAccessibleContext.clear(); | ||||||||||
744 | |||||||||||
745 | // prepare firing an event | ||||||||||
746 | aModeChangeEvent.Source = *this; | ||||||||||
747 | aModeChangeEvent.NewMode = mbDesignMode ? std::u16string_view( u"design" ) : std::u16string_view( u"alive" ); | ||||||||||
748 | } | ||||||||||
749 | |||||||||||
750 | // --- </mutex_lock> --- | ||||||||||
751 | maModeChangeListeners.notifyEach( &XModeChangeListener::modeChanged, aModeChangeEvent ); | ||||||||||
752 | } | ||||||||||
753 | |||||||||||
754 | // XBoundComponent | ||||||||||
755 | |||||||||||
756 | void SAL_CALL FmXGridControl::addUpdateListener(const Reference< XUpdateListener >& l) | ||||||||||
757 | { | ||||||||||
758 | m_aUpdateListeners.addInterface( l ); | ||||||||||
759 | if( getPeer().is() && m_aUpdateListeners.getLength() == 1 ) | ||||||||||
760 | { | ||||||||||
761 | Reference< XBoundComponent > xBound(getPeer(), UNO_QUERY); | ||||||||||
762 | xBound->addUpdateListener( &m_aUpdateListeners); | ||||||||||
763 | } | ||||||||||
764 | } | ||||||||||
765 | |||||||||||
766 | |||||||||||
767 | void SAL_CALL FmXGridControl::removeUpdateListener(const Reference< XUpdateListener >& l) | ||||||||||
768 | { | ||||||||||
769 | if( getPeer().is() && m_aUpdateListeners.getLength() == 1 ) | ||||||||||
770 | { | ||||||||||
771 | Reference< XBoundComponent > xBound(getPeer(), UNO_QUERY); | ||||||||||
772 | xBound->removeUpdateListener( &m_aUpdateListeners); | ||||||||||
773 | } | ||||||||||
774 | m_aUpdateListeners.removeInterface( l ); | ||||||||||
775 | } | ||||||||||
776 | |||||||||||
777 | |||||||||||
778 | sal_Bool SAL_CALL FmXGridControl::commit() | ||||||||||
779 | { | ||||||||||
780 | Reference< XBoundComponent > xBound(getPeer(), UNO_QUERY); | ||||||||||
781 | if (xBound.is()) | ||||||||||
782 | return xBound->commit(); | ||||||||||
783 | else | ||||||||||
784 | return true; | ||||||||||
785 | } | ||||||||||
786 | |||||||||||
787 | // XContainer | ||||||||||
788 | |||||||||||
789 | void SAL_CALL FmXGridControl::addContainerListener(const Reference< XContainerListener >& l) | ||||||||||
790 | { | ||||||||||
791 | m_aContainerListeners.addInterface( l ); | ||||||||||
792 | if( getPeer().is() && m_aContainerListeners.getLength() == 1 ) | ||||||||||
793 | { | ||||||||||
794 | Reference< XContainer > xContainer(getPeer(), UNO_QUERY); | ||||||||||
795 | xContainer->addContainerListener( &m_aContainerListeners); | ||||||||||
796 | } | ||||||||||
797 | } | ||||||||||
798 | |||||||||||
799 | |||||||||||
800 | void SAL_CALL FmXGridControl::removeContainerListener(const Reference< XContainerListener >& l) | ||||||||||
801 | { | ||||||||||
802 | if( getPeer().is() && m_aContainerListeners.getLength() == 1 ) | ||||||||||
803 | { | ||||||||||
804 | Reference< XContainer > xContainer(getPeer(), UNO_QUERY); | ||||||||||
805 | xContainer->removeContainerListener( &m_aContainerListeners); | ||||||||||
806 | } | ||||||||||
807 | m_aContainerListeners.removeInterface( l ); | ||||||||||
808 | } | ||||||||||
809 | |||||||||||
810 | |||||||||||
811 | Reference< css::frame::XDispatch > SAL_CALL FmXGridControl::queryDispatch(const css::util::URL& aURL, const OUString& aTargetFrameName, sal_Int32 nSearchFlags) | ||||||||||
812 | { | ||||||||||
813 | Reference< css::frame::XDispatchProvider > xPeerProvider(getPeer(), UNO_QUERY); | ||||||||||
814 | if (xPeerProvider.is()) | ||||||||||
815 | return xPeerProvider->queryDispatch(aURL, aTargetFrameName, nSearchFlags); | ||||||||||
816 | else | ||||||||||
817 | return Reference< css::frame::XDispatch > (); | ||||||||||
818 | } | ||||||||||
819 | |||||||||||
820 | |||||||||||
821 | Sequence< Reference< css::frame::XDispatch > > SAL_CALL FmXGridControl::queryDispatches(const Sequence< css::frame::DispatchDescriptor>& aDescripts) | ||||||||||
822 | { | ||||||||||
823 | Reference< css::frame::XDispatchProvider > xPeerProvider(getPeer(), UNO_QUERY); | ||||||||||
824 | if (xPeerProvider.is()) | ||||||||||
825 | return xPeerProvider->queryDispatches(aDescripts); | ||||||||||
826 | else | ||||||||||
827 | return Sequence< Reference< css::frame::XDispatch > >(); | ||||||||||
828 | } | ||||||||||
829 | |||||||||||
830 | |||||||||||
831 | void SAL_CALL FmXGridControl::registerDispatchProviderInterceptor(const Reference< css::frame::XDispatchProviderInterceptor >& _xInterceptor) | ||||||||||
832 | { | ||||||||||
833 | Reference< css::frame::XDispatchProviderInterception > xPeerInterception(getPeer(), UNO_QUERY); | ||||||||||
834 | if (xPeerInterception.is()) | ||||||||||
835 | xPeerInterception->registerDispatchProviderInterceptor(_xInterceptor); | ||||||||||
836 | } | ||||||||||
837 | |||||||||||
838 | |||||||||||
839 | void SAL_CALL FmXGridControl::releaseDispatchProviderInterceptor(const Reference< css::frame::XDispatchProviderInterceptor >& _xInterceptor) | ||||||||||
840 | { | ||||||||||
841 | Reference< css::frame::XDispatchProviderInterception > xPeerInterception(getPeer(), UNO_QUERY); | ||||||||||
842 | if (xPeerInterception.is()) | ||||||||||
843 | xPeerInterception->releaseDispatchProviderInterceptor(_xInterceptor); | ||||||||||
844 | } | ||||||||||
845 | |||||||||||
846 | |||||||||||
847 | void SAL_CALL FmXGridControl::addGridControlListener( const Reference< XGridControlListener >& _listener ) | ||||||||||
848 | { | ||||||||||
849 | ::osl::MutexGuard aGuard( GetMutex() ); | ||||||||||
850 | |||||||||||
851 | m_aGridControlListeners.addInterface( _listener ); | ||||||||||
852 | if ( getPeer().is() && 1 == m_aGridControlListeners.getLength() ) | ||||||||||
853 | { | ||||||||||
854 | Reference< XGridControl > xPeerGrid( getPeer(), UNO_QUERY ); | ||||||||||
855 | if ( xPeerGrid.is() ) | ||||||||||
856 | xPeerGrid->addGridControlListener( &m_aGridControlListeners ); | ||||||||||
857 | } | ||||||||||
858 | } | ||||||||||
859 | |||||||||||
860 | |||||||||||
861 | void SAL_CALL FmXGridControl::removeGridControlListener( const Reference< XGridControlListener >& _listener ) | ||||||||||
862 | { | ||||||||||
863 | ::osl::MutexGuard aGuard( GetMutex() ); | ||||||||||
864 | |||||||||||
865 | if( getPeer().is() && 1 == m_aGridControlListeners.getLength() ) | ||||||||||
866 | { | ||||||||||
867 | Reference< XGridControl > xPeerGrid( getPeer(), UNO_QUERY ); | ||||||||||
868 | if ( xPeerGrid.is() ) | ||||||||||
869 | xPeerGrid->removeGridControlListener( &m_aGridControlListeners ); | ||||||||||
870 | } | ||||||||||
871 | |||||||||||
872 | m_aGridControlListeners.removeInterface( _listener ); | ||||||||||
873 | } | ||||||||||
874 | |||||||||||
875 | |||||||||||
876 | sal_Int16 SAL_CALL FmXGridControl::getCurrentColumnPosition() | ||||||||||
877 | { | ||||||||||
878 | Reference< XGridControl > xGrid( getPeer(), UNO_QUERY ); | ||||||||||
879 | return xGrid.is() ? xGrid->getCurrentColumnPosition() : -1; | ||||||||||
880 | } | ||||||||||
881 | |||||||||||
882 | |||||||||||
883 | void SAL_CALL FmXGridControl::setCurrentColumnPosition(sal_Int16 nPos) | ||||||||||
884 | { | ||||||||||
885 | Reference< XGridControl > xGrid( getPeer(), UNO_QUERY ); | ||||||||||
886 | if ( xGrid.is() ) | ||||||||||
887 | { | ||||||||||
888 | SolarMutexGuard aGuard; | ||||||||||
889 | xGrid->setCurrentColumnPosition( nPos ); | ||||||||||
890 | } | ||||||||||
891 | } | ||||||||||
892 | |||||||||||
893 | // XElementAccess | ||||||||||
894 | |||||||||||
895 | sal_Bool SAL_CALL FmXGridControl::hasElements() | ||||||||||
896 | { | ||||||||||
897 | Reference< XElementAccess > xPeer(getPeer(), UNO_QUERY); | ||||||||||
898 | return xPeer.is() && xPeer->hasElements(); | ||||||||||
899 | } | ||||||||||
900 | |||||||||||
901 | |||||||||||
902 | Type SAL_CALL FmXGridControl::getElementType( ) | ||||||||||
903 | { | ||||||||||
904 | return cppu::UnoType<css::awt::XTextComponent>::get(); | ||||||||||
905 | } | ||||||||||
906 | |||||||||||
907 | // XEnumerationAccess | ||||||||||
908 | |||||||||||
909 | Reference< XEnumeration > SAL_CALL FmXGridControl::createEnumeration() | ||||||||||
910 | { | ||||||||||
911 | Reference< XEnumerationAccess > xPeer(getPeer(), UNO_QUERY); | ||||||||||
912 | if (xPeer.is()) | ||||||||||
913 | return xPeer->createEnumeration(); | ||||||||||
914 | else | ||||||||||
915 | return new ::comphelper::OEnumerationByIndex(this); | ||||||||||
916 | } | ||||||||||
917 | |||||||||||
918 | // XIndexAccess | ||||||||||
919 | |||||||||||
920 | sal_Int32 SAL_CALL FmXGridControl::getCount() | ||||||||||
921 | { | ||||||||||
922 | Reference< XIndexAccess > xPeer(getPeer(), UNO_QUERY); | ||||||||||
923 | return xPeer.is() ? xPeer->getCount() : 0; | ||||||||||
924 | } | ||||||||||
925 | |||||||||||
926 | |||||||||||
927 | Any SAL_CALL FmXGridControl::getByIndex(sal_Int32 _nIndex) | ||||||||||
928 | { | ||||||||||
929 | Reference< XIndexAccess > xPeer(getPeer(), UNO_QUERY); | ||||||||||
930 | if (!xPeer.is()) | ||||||||||
931 | throw IndexOutOfBoundsException(); | ||||||||||
932 | |||||||||||
933 | return xPeer->getByIndex(_nIndex); | ||||||||||
934 | } | ||||||||||
935 | |||||||||||
936 | // css::util::XModeSelector | ||||||||||
937 | |||||||||||
938 | void SAL_CALL FmXGridControl::setMode(const OUString& Mode) | ||||||||||
939 | { | ||||||||||
940 | Reference< css::util::XModeSelector > xPeer(getPeer(), UNO_QUERY); | ||||||||||
941 | if (!xPeer.is()) | ||||||||||
942 | throw NoSupportException(); | ||||||||||
943 | |||||||||||
944 | xPeer->setMode(Mode); | ||||||||||
945 | } | ||||||||||
946 | |||||||||||
947 | |||||||||||
948 | OUString SAL_CALL FmXGridControl::getMode() | ||||||||||
949 | { | ||||||||||
950 | Reference< css::util::XModeSelector > xPeer(getPeer(), UNO_QUERY); | ||||||||||
951 | return xPeer.is() ? xPeer->getMode() : OUString(); | ||||||||||
952 | } | ||||||||||
953 | |||||||||||
954 | |||||||||||
955 | css::uno::Sequence<OUString> SAL_CALL FmXGridControl::getSupportedModes() | ||||||||||
956 | { | ||||||||||
957 | Reference< css::util::XModeSelector > xPeer(getPeer(), UNO_QUERY); | ||||||||||
958 | return xPeer.is() ? xPeer->getSupportedModes() : css::uno::Sequence<OUString>(); | ||||||||||
959 | } | ||||||||||
960 | |||||||||||
961 | |||||||||||
962 | sal_Bool SAL_CALL FmXGridControl::supportsMode(const OUString& Mode) | ||||||||||
963 | { | ||||||||||
964 | Reference< css::util::XModeSelector > xPeer(getPeer(), UNO_QUERY); | ||||||||||
965 | return xPeer.is() && xPeer->supportsMode(Mode); | ||||||||||
966 | } | ||||||||||
967 | |||||||||||
968 | void SAL_CALL FmXGridControl::setFocus() | ||||||||||
969 | { | ||||||||||
970 | FmXGridPeer* pPeer = comphelper::getUnoTunnelImplementation<FmXGridPeer>(getPeer()); | ||||||||||
971 | if (pPeer) | ||||||||||
972 | { | ||||||||||
973 | VclPtr<FmGridControl> xGrid = pPeer->GetAs<FmGridControl>(); | ||||||||||
974 | bool bAlreadyHasFocus = xGrid->HasChildPathFocus() || xGrid->ControlHasFocus(); | ||||||||||
975 | // if the focus is already in the control don't grab focus again which | ||||||||||
976 | // would grab focus away from any native widgets hosted in the control | ||||||||||
977 | if (bAlreadyHasFocus) | ||||||||||
978 | return; | ||||||||||
979 | } | ||||||||||
980 | UnoControl::setFocus(); | ||||||||||
981 | } | ||||||||||
982 | |||||||||||
983 | // helper class which prevents that in the peer's header the FmGridListener must be known | ||||||||||
984 | class FmXGridPeer::GridListenerDelegator : public FmGridListener | ||||||||||
985 | { | ||||||||||
986 | protected: | ||||||||||
987 | FmXGridPeer* m_pPeer; | ||||||||||
988 | |||||||||||
989 | public: | ||||||||||
990 | explicit GridListenerDelegator( FmXGridPeer* _pPeer ); | ||||||||||
991 | virtual ~GridListenerDelegator(); | ||||||||||
992 | |||||||||||
993 | protected: | ||||||||||
994 | virtual void selectionChanged() override; | ||||||||||
995 | virtual void columnChanged() override; | ||||||||||
996 | }; | ||||||||||
997 | |||||||||||
998 | |||||||||||
999 | FmXGridPeer::GridListenerDelegator::GridListenerDelegator(FmXGridPeer* _pPeer) | ||||||||||
1000 | :m_pPeer(_pPeer) | ||||||||||
1001 | { | ||||||||||
1002 | DBG_ASSERT(m_pPeer, "GridListenerDelegator::GridListenerDelegator")do { if (true && (!(m_pPeer))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/svx/source/fmcomp/fmgridif.cxx" ":" "1002" ": "), "%s", "GridListenerDelegator::GridListenerDelegator" ); } } while (false); | ||||||||||
1003 | } | ||||||||||
1004 | |||||||||||
1005 | FmXGridPeer::GridListenerDelegator::~GridListenerDelegator() | ||||||||||
1006 | { | ||||||||||
1007 | } | ||||||||||
1008 | |||||||||||
1009 | |||||||||||
1010 | void FmXGridPeer::GridListenerDelegator::selectionChanged() | ||||||||||
1011 | { | ||||||||||
1012 | m_pPeer->selectionChanged(); | ||||||||||
1013 | } | ||||||||||
1014 | |||||||||||
1015 | |||||||||||
1016 | void FmXGridPeer::GridListenerDelegator::columnChanged() | ||||||||||
1017 | { | ||||||||||
1018 | m_pPeer->columnChanged(); | ||||||||||
1019 | } | ||||||||||
1020 | |||||||||||
1021 | void FmXGridPeer::selectionChanged() | ||||||||||
1022 | { | ||||||||||
1023 | EventObject aSource; | ||||||||||
1024 | aSource.Source = static_cast< ::cppu::OWeakObject* >(this); | ||||||||||
1025 | m_aSelectionListeners.notifyEach( &XSelectionChangeListener::selectionChanged, aSource); | ||||||||||
1026 | } | ||||||||||
1027 | |||||||||||
1028 | |||||||||||
1029 | void FmXGridPeer::columnChanged() | ||||||||||
1030 | { | ||||||||||
1031 | EventObject aEvent( *this ); | ||||||||||
1032 | m_aGridControlListeners.notifyEach( &XGridControlListener::columnChanged, aEvent ); | ||||||||||
1033 | } | ||||||||||
1034 | |||||||||||
1035 | |||||||||||
1036 | FmXGridPeer::FmXGridPeer(const Reference< XComponentContext >& _rxContext) | ||||||||||
1037 | :m_xContext(_rxContext) | ||||||||||
1038 | ,m_aModifyListeners(m_aMutex) | ||||||||||
1039 | ,m_aUpdateListeners(m_aMutex) | ||||||||||
1040 | ,m_aContainerListeners(m_aMutex) | ||||||||||
1041 | ,m_aSelectionListeners(m_aMutex) | ||||||||||
1042 | ,m_aGridControlListeners(m_aMutex) | ||||||||||
1043 | ,m_aMode("DataMode") | ||||||||||
1044 | ,m_nCursorListening(0) | ||||||||||
1045 | ,m_bInterceptingDispatch(false) | ||||||||||
1046 | { | ||||||||||
1047 | // Create must be called after this constructor | ||||||||||
1048 | m_pGridListener.reset( new GridListenerDelegator( this ) ); | ||||||||||
1049 | } | ||||||||||
1050 | |||||||||||
1051 | |||||||||||
1052 | VclPtr<FmGridControl> FmXGridPeer::imp_CreateControl(vcl::Window* pParent, WinBits nStyle) | ||||||||||
1053 | { | ||||||||||
1054 | return VclPtr<FmGridControl>::Create(m_xContext, pParent, this, nStyle); | ||||||||||
1055 | } | ||||||||||
1056 | |||||||||||
1057 | |||||||||||
1058 | void FmXGridPeer::Create(vcl::Window* pParent, WinBits nStyle) | ||||||||||
1059 | { | ||||||||||
1060 | VclPtr<FmGridControl> pWin = imp_CreateControl(pParent, nStyle); | ||||||||||
1061 | DBG_ASSERT(pWin != nullptr, "FmXGridPeer::Create : imp_CreateControl didn't return a control !")do { if (true && (!(pWin != nullptr))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/svx/source/fmcomp/fmgridif.cxx" ":" "1061" ": "), "%s", "FmXGridPeer::Create : imp_CreateControl didn't return a control !" ); } } while (false); | ||||||||||
1062 | |||||||||||
1063 | pWin->SetStateProvider(LINK(this, FmXGridPeer, OnQueryGridSlotState)::tools::detail::makeLink( ::tools::detail::castTo<FmXGridPeer *>(this), &FmXGridPeer::LinkStubOnQueryGridSlotState)); | ||||||||||
1064 | pWin->SetSlotExecutor(LINK(this, FmXGridPeer, OnExecuteGridSlot)::tools::detail::makeLink( ::tools::detail::castTo<FmXGridPeer *>(this), &FmXGridPeer::LinkStubOnExecuteGridSlot)); | ||||||||||
1065 | |||||||||||
1066 | // want to hear about row selections | ||||||||||
1067 | pWin->setGridListener( m_pGridListener.get() ); | ||||||||||
1068 | |||||||||||
1069 | // Init must always be called | ||||||||||
1070 | pWin->Init(); | ||||||||||
1071 | pWin->SetComponentInterface(this); | ||||||||||
1072 | |||||||||||
1073 | getSupportedURLs(); | ||||||||||
1074 | } | ||||||||||
1075 | |||||||||||
1076 | FmXGridPeer::~FmXGridPeer() | ||||||||||
1077 | { | ||||||||||
1078 | setRowSet(Reference< XRowSet > ()); | ||||||||||
1079 | setColumns(Reference< XIndexContainer > ()); | ||||||||||
1080 | } | ||||||||||
1081 | |||||||||||
1082 | UNO3_GETIMPLEMENTATION2_IMPL(FmXGridPeer, VCLXWindow)namespace { class theFmXGridPeerUnoTunnelId : public rtl::Static < UnoTunnelIdInit, theFmXGridPeerUnoTunnelId> {}; } const css::uno::Sequence< sal_Int8 > & FmXGridPeer::getUnoTunnelId () throw() { return theFmXGridPeerUnoTunnelId::get().getSeq() ; }sal_Int64 FmXGridPeer::getSomething( const css::uno::Sequence < sal_Int8 >& rId ) { if( isUnoTunnelId<FmXGridPeer >(rId) ) { return sal::static_int_cast<sal_Int64>(reinterpret_cast <sal_IntPtr>(this)); } else { return VCLXWindow::getSomething ( rId ); } }; | ||||||||||
1083 | |||||||||||
1084 | // XEventListener | ||||||||||
1085 | |||||||||||
1086 | void FmXGridPeer::disposing(const EventObject& e) | ||||||||||
1087 | { | ||||||||||
1088 | bool bKnownSender = false; | ||||||||||
1089 | |||||||||||
1090 | Reference< XIndexContainer > xCols( e.Source, UNO_QUERY ); | ||||||||||
1091 | if ( xCols.is() ) | ||||||||||
1092 | { | ||||||||||
1093 | setColumns(Reference< XIndexContainer > ()); | ||||||||||
1094 | bKnownSender = true; | ||||||||||
1095 | } | ||||||||||
1096 | |||||||||||
1097 | Reference< XRowSet > xCursor(e.Source, UNO_QUERY); | ||||||||||
1098 | if (xCursor.is()) | ||||||||||
1099 | { | ||||||||||
1100 | setRowSet( m_xCursor ); | ||||||||||
1101 | m_xCursor = nullptr; | ||||||||||
1102 | bKnownSender = true; | ||||||||||
1103 | } | ||||||||||
1104 | |||||||||||
1105 | |||||||||||
1106 | if ( !bKnownSender && m_pDispatchers ) | ||||||||||
1107 | { | ||||||||||
1108 | const Sequence< URL>& aSupportedURLs = getSupportedURLs(); | ||||||||||
1109 | const URL* pSupportedURLs = aSupportedURLs.getConstArray(); | ||||||||||
1110 | for ( sal_Int32 i=0; i < ( aSupportedURLs.getLength() ) && !bKnownSender; ++i, ++pSupportedURLs ) | ||||||||||
1111 | { | ||||||||||
1112 | if ( m_pDispatchers[i] == e.Source ) | ||||||||||
1113 | { | ||||||||||
1114 | m_pDispatchers[i]->removeStatusListener( static_cast< css::frame::XStatusListener* >( this ), *pSupportedURLs ); | ||||||||||
1115 | m_pDispatchers[i] = nullptr; | ||||||||||
1116 | m_pStateCache[i] = false; | ||||||||||
1117 | bKnownSender = true; | ||||||||||
1118 | } | ||||||||||
1119 | } | ||||||||||
1120 | } | ||||||||||
1121 | |||||||||||
1122 | if ( !bKnownSender ) | ||||||||||
1123 | VCLXWindow::disposing(e); | ||||||||||
1124 | } | ||||||||||
1125 | |||||||||||
1126 | |||||||||||
1127 | void FmXGridPeer::addModifyListener(const Reference< css::util::XModifyListener >& l) | ||||||||||
1128 | { | ||||||||||
1129 | m_aModifyListeners.addInterface( l ); | ||||||||||
1130 | } | ||||||||||
1131 | |||||||||||
1132 | |||||||||||
1133 | void FmXGridPeer::removeModifyListener(const Reference< css::util::XModifyListener >& l) | ||||||||||
1134 | { | ||||||||||
1135 | m_aModifyListeners.removeInterface( l ); | ||||||||||
1136 | } | ||||||||||
1137 | |||||||||||
1138 | |||||||||||
1139 | #define LAST_KNOWN_TYPEFormComponentType::PATTERNFIELD FormComponentType::PATTERNFIELD | ||||||||||
1140 | Sequence< sal_Bool > SAL_CALL FmXGridPeer::queryFieldDataType( const Type& xType ) | ||||||||||
1141 | { | ||||||||||
1142 | // a 'conversion table' | ||||||||||
1143 | static const bool bCanConvert[LAST_KNOWN_TYPEFormComponentType::PATTERNFIELD][4] = | ||||||||||
1144 | { | ||||||||||
1145 | { false, false, false, false }, // FormComponentType::CONTROL | ||||||||||
1146 | { false, false, false, false }, // FormComponentType::COMMANDBUTTON | ||||||||||
1147 | { false, false, false, false }, // FormComponentType::RADIOBUTTON | ||||||||||
1148 | { false, false, false, false }, // FormComponentType::IMAGEBUTTON | ||||||||||
1149 | { false, false, false, true }, // FormComponentType::CHECKBOX | ||||||||||
1150 | { false, false, false, false }, // FormComponentType::LISTBOX | ||||||||||
1151 | { false, false, false, false }, // FormComponentType::COMBOBOX | ||||||||||
1152 | { false, false, false, false }, // FormComponentType::GROUPBOX | ||||||||||
1153 | { true , false, false, false }, // FormComponentType::TEXTFIELD | ||||||||||
1154 | { false, false, false, false }, // FormComponentType::FIXEDTEXT | ||||||||||
1155 | { false, false, false, false }, // FormComponentType::GRIDCONTROL | ||||||||||
1156 | { false, false, false, false }, // FormComponentType::FILECONTROL | ||||||||||
1157 | { false, false, false, false }, // FormComponentType::HIDDENCONTROL | ||||||||||
1158 | { false, false, false, false }, // FormComponentType::IMAGECONTROL | ||||||||||
1159 | { true , true , true , false }, // FormComponentType::DATEFIELD | ||||||||||
1160 | { true , true , false, false }, // FormComponentType::TIMEFIELD | ||||||||||
1161 | { true , true , false, false }, // FormComponentType::NUMERICFIELD | ||||||||||
1162 | { true , true , false, false }, // FormComponentType::CURRENCYFIELD | ||||||||||
1163 | { true , false, false, false } // FormComponentType::PATTERNFIELD | ||||||||||
1164 | }; | ||||||||||
1165 | |||||||||||
1166 | |||||||||||
1167 | sal_Int16 nMapColumn = -1; | ||||||||||
1168 | switch (xType.getTypeClass()) | ||||||||||
1169 | { | ||||||||||
1170 | case TypeClass_STRING : nMapColumn = 0; break; | ||||||||||
1171 | case TypeClass_FLOAT: | ||||||||||
1172 | case TypeClass_DOUBLE : nMapColumn = 1; break; | ||||||||||
1173 | case TypeClass_SHORT: | ||||||||||
1174 | case TypeClass_LONG: | ||||||||||
1175 | case TypeClass_UNSIGNED_LONG: | ||||||||||
1176 | case TypeClass_UNSIGNED_SHORT : nMapColumn = 2; break; | ||||||||||
1177 | case TypeClass_BOOLEAN : nMapColumn = 3; break; | ||||||||||
1178 | default: | ||||||||||
1179 | break; | ||||||||||
1180 | } | ||||||||||
1181 | |||||||||||
1182 | Reference< XIndexContainer > xColumns = getColumns(); | ||||||||||
1183 | |||||||||||
1184 | VclPtr< FmGridControl > pGrid = GetAs< FmGridControl >(); | ||||||||||
1185 | sal_Int32 nColumns = pGrid->GetViewColCount(); | ||||||||||
1186 | |||||||||||
1187 | std::vector< std::unique_ptr<DbGridColumn> > const & aColumns = pGrid->GetColumns(); | ||||||||||
1188 | |||||||||||
1189 | Sequence<sal_Bool> aReturnSequence(nColumns); | ||||||||||
1190 | sal_Bool* pReturnArray = aReturnSequence.getArray(); | ||||||||||
1191 | |||||||||||
1192 | bool bRequestedAsAny = (xType.getTypeClass() == TypeClass_ANY); | ||||||||||
1193 | |||||||||||
1194 | DbGridColumn* pCol; | ||||||||||
1195 | Reference< css::sdb::XColumn > xFieldContent; | ||||||||||
1196 | Reference< XPropertySet > xCurrentColumn; | ||||||||||
1197 | for (sal_Int32 i=0; i<nColumns; ++i) | ||||||||||
1198 | { | ||||||||||
1199 | if (bRequestedAsAny) | ||||||||||
1200 | { | ||||||||||
1201 | pReturnArray[i] = true; | ||||||||||
1202 | continue; | ||||||||||
1203 | } | ||||||||||
1204 | |||||||||||
1205 | pReturnArray[i] = false; | ||||||||||
1206 | |||||||||||
1207 | sal_uInt16 nModelPos = pGrid->GetModelColumnPos(pGrid->GetColumnIdFromViewPos(static_cast<sal_uInt16>(i))); | ||||||||||
1208 | DBG_ASSERT(nModelPos != sal_uInt16(-1), "FmXGridPeer::queryFieldDataType : no model pos !")do { if (true && (!(nModelPos != sal_uInt16(-1)))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/svx/source/fmcomp/fmgridif.cxx" ":" "1208" ": "), "%s", "FmXGridPeer::queryFieldDataType : no model pos !" ); } } while (false); | ||||||||||
1209 | |||||||||||
1210 | pCol = aColumns[ nModelPos ].get(); | ||||||||||
1211 | const DbGridRowRef xRow = pGrid->GetSeekRow(); | ||||||||||
1212 | xFieldContent = (xRow.is() && xRow->HasField(pCol->GetFieldPos())) ? xRow->GetField(pCol->GetFieldPos()).getColumn() : Reference< css::sdb::XColumn > (); | ||||||||||
1213 | if (!xFieldContent.is()) | ||||||||||
1214 | // can't supply anything without a field content | ||||||||||
1215 | // FS - 07.12.99 - 54391 | ||||||||||
1216 | continue; | ||||||||||
1217 | |||||||||||
1218 | xColumns->getByIndex(nModelPos) >>= xCurrentColumn; | ||||||||||
1219 | if (!::comphelper::hasProperty(FM_PROP_CLASSID"ClassId", xCurrentColumn)) | ||||||||||
1220 | continue; | ||||||||||
1221 | |||||||||||
1222 | sal_Int16 nClassId = sal_Int16(); | ||||||||||
1223 | xCurrentColumn->getPropertyValue(FM_PROP_CLASSID"ClassId") >>= nClassId; | ||||||||||
1224 | if (nClassId>LAST_KNOWN_TYPEFormComponentType::PATTERNFIELD) | ||||||||||
1225 | continue; | ||||||||||
1226 | DBG_ASSERT(nClassId>0, "FmXGridPeer::queryFieldDataType : somebody changed the definition of the FormComponentType enum !")do { if (true && (!(nClassId>0))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/svx/source/fmcomp/fmgridif.cxx" ":" "1226" ": "), "%s", "FmXGridPeer::queryFieldDataType : somebody changed the definition of the FormComponentType enum !" ); } } while (false); | ||||||||||
1227 | |||||||||||
1228 | if (nMapColumn != -1) | ||||||||||
1229 | pReturnArray[i] = bCanConvert[nClassId-1][nMapColumn]; | ||||||||||
1230 | } | ||||||||||
1231 | |||||||||||
1232 | return aReturnSequence; | ||||||||||
1233 | } | ||||||||||
1234 | |||||||||||
1235 | |||||||||||
1236 | Sequence< Any > SAL_CALL FmXGridPeer::queryFieldData( sal_Int32 nRow, const Type& xType ) | ||||||||||
1237 | { | ||||||||||
1238 | VclPtr< FmGridControl > pGrid = GetAs< FmGridControl >(); | ||||||||||
1239 | DBG_ASSERT(pGrid && pGrid->IsOpen(), "FmXGridPeer::queryFieldData : have no valid grid window !")do { if (true && (!(pGrid && pGrid->IsOpen ()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools" ), ("/home/maarten/src/libreoffice/core/svx/source/fmcomp/fmgridif.cxx" ":" "1239" ": "), "%s", "FmXGridPeer::queryFieldData : have no valid grid window !" ); } } while (false); | ||||||||||
1240 | if (!pGrid || !pGrid->IsOpen()) | ||||||||||
1241 | return Sequence< Any>(); | ||||||||||
1242 | |||||||||||
1243 | // move the control to the specified row | ||||||||||
1244 | if (!pGrid->SeekRow(nRow)) | ||||||||||
1245 | { | ||||||||||
1246 | throw IllegalArgumentException(); | ||||||||||
1247 | } | ||||||||||
1248 | |||||||||||
1249 | // don't use GetCurrentRow as this isn't affected by the above SeekRow | ||||||||||
1250 | // FS - 30.09.99 - 68644 | ||||||||||
1251 | DbGridRowRef xPaintRow = pGrid->GetPaintRow(); | ||||||||||
1252 | ENSURE_OR_THROW( xPaintRow.is(), "invalid paint row" )if( !(xPaintRow.is()) ){ do { if (true && (!(xPaintRow .is()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ( "legacy.osl"), ("/home/maarten/src/libreoffice/core/svx/source/fmcomp/fmgridif.cxx" ":" "1252" ": "), "%s", "invalid paint row"); } } while (false ); throw css::uno::RuntimeException( __func__ + OUStringLiteral (u",\n" "invalid paint row"), css::uno::Reference< css::uno ::XInterface >() ); }; | ||||||||||
1253 | |||||||||||
1254 | // I need the columns of the control for GetFieldText | ||||||||||
1255 | std::vector< std::unique_ptr<DbGridColumn> > const & aColumns = pGrid->GetColumns(); | ||||||||||
1256 | |||||||||||
1257 | // and through all the columns | ||||||||||
1258 | sal_Int32 nColumnCount = pGrid->GetViewColCount(); | ||||||||||
1259 | |||||||||||
1260 | Sequence< Any> aReturnSequence(nColumnCount); | ||||||||||
1261 | Any* pReturnArray = aReturnSequence.getArray(); | ||||||||||
1262 | |||||||||||
1263 | bool bRequestedAsAny = (xType.getTypeClass() == TypeClass_ANY); | ||||||||||
1264 | Reference< css::sdb::XColumn > xFieldContent; | ||||||||||
1265 | for (sal_Int32 i=0; i < nColumnCount; ++i) | ||||||||||
1266 | { | ||||||||||
1267 | sal_uInt16 nModelPos = pGrid->GetModelColumnPos(pGrid->GetColumnIdFromViewPos(static_cast<sal_uInt16>(i))); | ||||||||||
1268 | DBG_ASSERT(nModelPos != sal_uInt16(-1), "FmXGridPeer::queryFieldData : invalid model pos !")do { if (true && (!(nModelPos != sal_uInt16(-1)))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/svx/source/fmcomp/fmgridif.cxx" ":" "1268" ": "), "%s", "FmXGridPeer::queryFieldData : invalid model pos !" ); } } while (false); | ||||||||||
1269 | |||||||||||
1270 | // don't use GetCurrentFieldValue to determine the field content as this isn't affected by the above SeekRow | ||||||||||
1271 | // FS - 30.09.99 - 68644 | ||||||||||
1272 | DbGridColumn* pCol = aColumns[ nModelPos ].get(); | ||||||||||
1273 | xFieldContent = xPaintRow->HasField( pCol->GetFieldPos() ) | ||||||||||
1274 | ? xPaintRow->GetField( pCol->GetFieldPos() ).getColumn() | ||||||||||
1275 | : Reference< XColumn > (); | ||||||||||
1276 | |||||||||||
1277 | if ( !xFieldContent.is() ) | ||||||||||
1278 | continue; | ||||||||||
1279 | |||||||||||
1280 | if (bRequestedAsAny) | ||||||||||
1281 | { | ||||||||||
1282 | Reference< XPropertySet > xFieldSet(xFieldContent, UNO_QUERY); | ||||||||||
1283 | pReturnArray[i] = xFieldSet->getPropertyValue(FM_PROP_VALUE"Value"); | ||||||||||
1284 | } | ||||||||||
1285 | else | ||||||||||
1286 | { | ||||||||||
1287 | switch (xType.getTypeClass()) | ||||||||||
1288 | { | ||||||||||
1289 | // Strings are dealt with directly by the GetFieldText | ||||||||||
1290 | case TypeClass_STRING : | ||||||||||
1291 | { | ||||||||||
1292 | OUString sText = aColumns[ nModelPos ]->GetCellText( xPaintRow.get(), pGrid->getNumberFormatter() ); | ||||||||||
1293 | pReturnArray[i] <<= sText; | ||||||||||
1294 | } | ||||||||||
1295 | break; | ||||||||||
1296 | // everything else is requested in the DatabaseVariant | ||||||||||
1297 | case TypeClass_FLOAT : pReturnArray[i] <<= xFieldContent->getFloat(); break; | ||||||||||
1298 | case TypeClass_DOUBLE : pReturnArray[i] <<= xFieldContent->getDouble(); break; | ||||||||||
1299 | case TypeClass_SHORT : pReturnArray[i] <<= xFieldContent->getShort(); break; | ||||||||||
1300 | case TypeClass_LONG : pReturnArray[i] <<= static_cast<sal_Int32>(xFieldContent->getLong()); break; | ||||||||||
1301 | case TypeClass_UNSIGNED_SHORT : pReturnArray[i] <<= static_cast<sal_uInt16>(xFieldContent->getShort()); break; | ||||||||||
1302 | case TypeClass_UNSIGNED_LONG : pReturnArray[i] <<= static_cast<sal_uInt32>(xFieldContent->getLong()); break; | ||||||||||
1303 | case TypeClass_BOOLEAN : pReturnArray[i] <<= xFieldContent->getBoolean(); break; | ||||||||||
1304 | default: | ||||||||||
1305 | { | ||||||||||
1306 | throw IllegalArgumentException(); | ||||||||||
1307 | } | ||||||||||
1308 | } | ||||||||||
1309 | } | ||||||||||
1310 | } | ||||||||||
1311 | return aReturnSequence; | ||||||||||
1312 | } | ||||||||||
1313 | |||||||||||
1314 | |||||||||||
1315 | void FmXGridPeer::CellModified() | ||||||||||
1316 | { | ||||||||||
1317 | EventObject aEvt; | ||||||||||
1318 | aEvt.Source = static_cast< ::cppu::OWeakObject* >(this); | ||||||||||
1319 | m_aModifyListeners.notifyEach( &XModifyListener::modified, aEvt ); | ||||||||||
1320 | } | ||||||||||
1321 | |||||||||||
1322 | // XPropertyChangeListener | ||||||||||
1323 | |||||||||||
1324 | void FmXGridPeer::propertyChange(const PropertyChangeEvent& evt) | ||||||||||
1325 | { | ||||||||||
1326 | SolarMutexGuard aGuard; | ||||||||||
1327 | // want to do a lot of VCL stuff here ... | ||||||||||
1328 | // this should not be (deadlock) critical, as by definition, every component should release | ||||||||||
1329 | // any own mutexes before notifying | ||||||||||
1330 | |||||||||||
1331 | VclPtr< FmGridControl > pGrid = GetAs< FmGridControl >(); | ||||||||||
1332 | if (!pGrid) | ||||||||||
1333 | return; | ||||||||||
1334 | |||||||||||
1335 | // Database event | ||||||||||
1336 | if (evt.PropertyName == FM_PROP_VALUE"Value" || m_xCursor == evt.Source) | ||||||||||
1337 | pGrid->propertyChange(evt); | ||||||||||
1338 | else if (pGrid && m_xColumns.is() && m_xColumns->hasElements()) | ||||||||||
1339 | { | ||||||||||
1340 | // next find which column has changed | ||||||||||
1341 | css::uno::Reference<css::uno::XInterface> xCurrent; | ||||||||||
1342 | sal_Int32 i; | ||||||||||
1343 | |||||||||||
1344 | for ( i = 0; i < m_xColumns->getCount(); i++) | ||||||||||
1345 | { | ||||||||||
1346 | xCurrent.set(m_xColumns->getByIndex(i), css::uno::UNO_QUERY); | ||||||||||
1347 | if (evt.Source == xCurrent) | ||||||||||
1348 | break; | ||||||||||
1349 | } | ||||||||||
1350 | |||||||||||
1351 | if (i >= m_xColumns->getCount()) | ||||||||||
1352 | // this is valid because we are listening at the cursor, too (RecordCount, -status, edit mode) | ||||||||||
1353 | return; | ||||||||||
1354 | |||||||||||
1355 | sal_uInt16 nId = pGrid->GetColumnIdFromModelPos(static_cast<sal_uInt16>(i)); | ||||||||||
1356 | bool bInvalidateColumn = false; | ||||||||||
1357 | |||||||||||
1358 | if (evt.PropertyName == FM_PROP_LABEL"Label") | ||||||||||
1359 | { | ||||||||||
1360 | OUString aName = ::comphelper::getString(evt.NewValue); | ||||||||||
1361 | if (aName != pGrid->GetColumnTitle(nId)) | ||||||||||
1362 | pGrid->SetColumnTitle(nId, aName); | ||||||||||
1363 | } | ||||||||||
1364 | else if (evt.PropertyName == FM_PROP_WIDTH"Width") | ||||||||||
1365 | { | ||||||||||
1366 | sal_Int32 nWidth = 0; | ||||||||||
1367 | if (evt.NewValue.getValueType().getTypeClass() == TypeClass_VOID) | ||||||||||
1368 | nWidth = pGrid->GetDefaultColumnWidth(pGrid->GetColumnTitle(nId)); | ||||||||||
1369 | // GetDefaultColumnWidth already considered the zoom factor | ||||||||||
1370 | else | ||||||||||
1371 | { | ||||||||||
1372 | sal_Int32 nTest = 0; | ||||||||||
1373 | if (evt.NewValue >>= nTest) | ||||||||||
1374 | { | ||||||||||
1375 | nWidth = pGrid->LogicToPixel(Point(nTest, 0), MapMode(MapUnit::Map10thMM)).X(); | ||||||||||
1376 | // take the zoom factor into account | ||||||||||
1377 | nWidth = pGrid->CalcZoom(nWidth); | ||||||||||
1378 | } | ||||||||||
1379 | } | ||||||||||
1380 | if (nWidth != (sal_Int32(pGrid->GetColumnWidth(nId)))) | ||||||||||
1381 | { | ||||||||||
1382 | if (pGrid->IsEditing()) | ||||||||||
1383 | { | ||||||||||
1384 | pGrid->DeactivateCell(); | ||||||||||
1385 | pGrid->ActivateCell(); | ||||||||||
1386 | } | ||||||||||
1387 | pGrid->SetColumnWidth(nId, nWidth); | ||||||||||
1388 | } | ||||||||||
1389 | } | ||||||||||
1390 | else if (evt.PropertyName == FM_PROP_HIDDEN"Hidden") | ||||||||||
1391 | { | ||||||||||
1392 | DBG_ASSERT(evt.NewValue.getValueType().getTypeClass() == TypeClass_BOOLEAN,do { if (true && (!(evt.NewValue.getValueType().getTypeClass () == TypeClass_BOOLEAN))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/svx/source/fmcomp/fmgridif.cxx" ":" "1393" ": "), "%s", "FmXGridPeer::propertyChange : the property 'hidden' should be of type boolean !" ); } } while (false) | ||||||||||
1393 | "FmXGridPeer::propertyChange : the property 'hidden' should be of type boolean !")do { if (true && (!(evt.NewValue.getValueType().getTypeClass () == TypeClass_BOOLEAN))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/svx/source/fmcomp/fmgridif.cxx" ":" "1393" ": "), "%s", "FmXGridPeer::propertyChange : the property 'hidden' should be of type boolean !" ); } } while (false); | ||||||||||
1394 | if (::comphelper::getBOOL(evt.NewValue)) | ||||||||||
1395 | pGrid->HideColumn(nId); | ||||||||||
1396 | else | ||||||||||
1397 | pGrid->ShowColumn(nId); | ||||||||||
1398 | } | ||||||||||
1399 | else if (evt.PropertyName == FM_PROP_ALIGN"Align") | ||||||||||
1400 | { | ||||||||||
1401 | // in design mode it doesn't matter | ||||||||||
1402 | if (!isDesignMode()) | ||||||||||
1403 | { | ||||||||||
1404 | DbGridColumn* pCol = pGrid->GetColumns()[i].get(); | ||||||||||
1405 | |||||||||||
1406 | pCol->SetAlignmentFromModel(-1); | ||||||||||
1407 | bInvalidateColumn = true; | ||||||||||
1408 | } | ||||||||||
1409 | } | ||||||||||
1410 | else if (evt.PropertyName == FM_PROP_FORMATKEY"FormatKey") | ||||||||||
1411 | { | ||||||||||
1412 | if (!isDesignMode()) | ||||||||||
1413 | bInvalidateColumn = true; | ||||||||||
1414 | } | ||||||||||
1415 | |||||||||||
1416 | // need to invalidate the affected column ? | ||||||||||
1417 | if (bInvalidateColumn) | ||||||||||
1418 | { | ||||||||||
1419 | bool bWasEditing = pGrid->IsEditing(); | ||||||||||
1420 | if (bWasEditing) | ||||||||||
1421 | pGrid->DeactivateCell(); | ||||||||||
1422 | |||||||||||
1423 | ::tools::Rectangle aColRect = pGrid->GetFieldRect(nId); | ||||||||||
1424 | aColRect.SetTop( 0 ); | ||||||||||
1425 | aColRect.SetBottom( pGrid->GetSizePixel().Height() ); | ||||||||||
1426 | pGrid->Invalidate(aColRect); | ||||||||||
1427 | |||||||||||
1428 | if (bWasEditing) | ||||||||||
1429 | pGrid->ActivateCell(); | ||||||||||
1430 | } | ||||||||||
1431 | } | ||||||||||
1432 | } | ||||||||||
1433 | |||||||||||
1434 | // XBoundComponent | ||||||||||
1435 | |||||||||||
1436 | void FmXGridPeer::addUpdateListener(const Reference< XUpdateListener >& l) | ||||||||||
1437 | { | ||||||||||
1438 | m_aUpdateListeners.addInterface(l); | ||||||||||
1439 | } | ||||||||||
1440 | |||||||||||
1441 | |||||||||||
1442 | void FmXGridPeer::removeUpdateListener(const Reference< XUpdateListener >& l) | ||||||||||
1443 | { | ||||||||||
1444 | m_aUpdateListeners.removeInterface(l); | ||||||||||
1445 | } | ||||||||||
1446 | |||||||||||
1447 | |||||||||||
1448 | sal_Bool FmXGridPeer::commit() | ||||||||||
1449 | { | ||||||||||
1450 | VclPtr< FmGridControl > pGrid = GetAs< FmGridControl >(); | ||||||||||
1451 | if (!m_xCursor.is() || !pGrid) | ||||||||||
1452 | return true; | ||||||||||
1453 | |||||||||||
1454 | EventObject aEvt(static_cast< ::cppu::OWeakObject* >(this)); | ||||||||||
1455 | ::comphelper::OInterfaceIteratorHelper2 aIter(m_aUpdateListeners); | ||||||||||
1456 | bool bCancel = false; | ||||||||||
1457 | while (aIter.hasMoreElements() && !bCancel) | ||||||||||
1458 | if ( !static_cast< XUpdateListener* >( aIter.next() )->approveUpdate( aEvt ) ) | ||||||||||
1459 | bCancel = true; | ||||||||||
1460 | |||||||||||
1461 | if (!bCancel) | ||||||||||
1462 | bCancel = !pGrid->commit(); | ||||||||||
1463 | |||||||||||
1464 | if (!bCancel) | ||||||||||
1465 | m_aUpdateListeners.notifyEach( &XUpdateListener::updated, aEvt ); | ||||||||||
1466 | return !bCancel; | ||||||||||
1467 | } | ||||||||||
1468 | |||||||||||
1469 | |||||||||||
1470 | void FmXGridPeer::cursorMoved(const EventObject& _rEvent) | ||||||||||
1471 | { | ||||||||||
1472 | VclPtr< FmGridControl > pGrid = GetAs< FmGridControl >(); | ||||||||||
1473 | // we are not interested in moving to insert row only in the reset event | ||||||||||
1474 | // which is fired after positioning and the insert row | ||||||||||
1475 | if (pGrid && pGrid->IsOpen() && !::comphelper::getBOOL(Reference< XPropertySet > (_rEvent.Source, UNO_QUERY_THROW)->getPropertyValue(FM_PROP_ISNEW"IsNew"))) | ||||||||||
1476 | pGrid->positioned(); | ||||||||||
1477 | } | ||||||||||
1478 | |||||||||||
1479 | |||||||||||
1480 | void FmXGridPeer::rowChanged(const EventObject& /*_rEvent*/) | ||||||||||
1481 | { | ||||||||||
1482 | VclPtr< FmGridControl > pGrid = GetAs< FmGridControl >(); | ||||||||||
1483 | if (pGrid && pGrid->IsOpen()) | ||||||||||
1484 | { | ||||||||||
1485 | if (m_xCursor->rowUpdated() && !pGrid->IsCurrentAppending()) | ||||||||||
1486 | pGrid->RowModified(pGrid->GetCurrentPos()); | ||||||||||
1487 | else if (m_xCursor->rowInserted()) | ||||||||||
1488 | pGrid->inserted(); | ||||||||||
1489 | } | ||||||||||
1490 | } | ||||||||||
1491 | |||||||||||
1492 | |||||||||||
1493 | void FmXGridPeer::rowSetChanged(const EventObject& /*event*/) | ||||||||||
1494 | { | ||||||||||
1495 | // not interested in ... | ||||||||||
1496 | // (our parent is a form which means we get a loaded or reloaded after this rowSetChanged) | ||||||||||
1497 | } | ||||||||||
1498 | |||||||||||
1499 | // XLoadListener | ||||||||||
1500 | |||||||||||
1501 | void FmXGridPeer::loaded(const EventObject& /*rEvent*/) | ||||||||||
1502 | { | ||||||||||
1503 | updateGrid(m_xCursor); | ||||||||||
1504 | } | ||||||||||
1505 | |||||||||||
1506 | |||||||||||
1507 | void FmXGridPeer::unloaded(const EventObject& /*rEvent*/) | ||||||||||
1508 | { | ||||||||||
1509 | updateGrid( Reference< XRowSet > (nullptr) ); | ||||||||||
1510 | } | ||||||||||
1511 | |||||||||||
1512 | |||||||||||
1513 | void FmXGridPeer::reloading(const EventObject& /*aEvent*/) | ||||||||||
1514 | { | ||||||||||
1515 | // empty the grid | ||||||||||
1516 | updateGrid( Reference< XRowSet > (nullptr) ); | ||||||||||
1517 | } | ||||||||||
1518 | |||||||||||
1519 | |||||||||||
1520 | void FmXGridPeer::unloading(const EventObject& /*aEvent*/) | ||||||||||
1521 | { | ||||||||||
1522 | // empty the grid | ||||||||||
1523 | updateGrid( Reference< XRowSet > (nullptr) ); | ||||||||||
1524 | } | ||||||||||
1525 | |||||||||||
1526 | |||||||||||
1527 | void FmXGridPeer::reloaded(const EventObject& aEvent) | ||||||||||
1528 | { | ||||||||||
1529 | { | ||||||||||
1530 | const sal_Int32 cnt = m_xColumns->getCount(); | ||||||||||
1531 | for(sal_Int32 i=0; i<cnt; ++i) | ||||||||||
1532 | { | ||||||||||
1533 | Reference< XLoadListener> xll(m_xColumns->getByIndex(i), UNO_QUERY); | ||||||||||
1534 | if(xll.is()) | ||||||||||
1535 | { | ||||||||||
1536 | xll->reloaded(aEvent); | ||||||||||
1537 | } | ||||||||||
1538 | } | ||||||||||
1539 | } | ||||||||||
1540 | updateGrid(m_xCursor); | ||||||||||
1541 | } | ||||||||||
1542 | |||||||||||
1543 | // XGridPeer | ||||||||||
1544 | |||||||||||
1545 | Reference< XIndexContainer > FmXGridPeer::getColumns() | ||||||||||
1546 | { | ||||||||||
1547 | return m_xColumns; | ||||||||||
1548 | } | ||||||||||
1549 | |||||||||||
1550 | |||||||||||
1551 | void FmXGridPeer::addColumnListeners(const Reference< XPropertySet >& xCol) | ||||||||||
1552 | { | ||||||||||
1553 | static const std::u16string_view aPropsListenedTo[] = | ||||||||||
1554 | { | ||||||||||
1555 | u"" FM_PROP_LABEL"Label", u"" FM_PROP_WIDTH"Width", u"" FM_PROP_HIDDEN"Hidden", u"" FM_PROP_ALIGN"Align", | ||||||||||
1556 | u"" FM_PROP_FORMATKEY"FormatKey" | ||||||||||
1557 | }; | ||||||||||
1558 | |||||||||||
1559 | // as not all properties have to be supported by all columns we have to check this | ||||||||||
1560 | // before adding a listener | ||||||||||
1561 | Reference< XPropertySetInfo > xInfo = xCol->getPropertySetInfo(); | ||||||||||
1562 | for (size_t i=0; i<SAL_N_ELEMENTS(aPropsListenedTo)(sizeof(sal_n_array_size(aPropsListenedTo))); ++i) | ||||||||||
1563 | { | ||||||||||
1564 | if ( xInfo->hasPropertyByName( aPropsListenedTo[i] ) ) | ||||||||||
1565 | { | ||||||||||
1566 | Property aPropDesc = xInfo->getPropertyByName( aPropsListenedTo[i] ); | ||||||||||
1567 | if ( 0 != ( aPropDesc.Attributes & PropertyAttribute::BOUND ) ) | ||||||||||
1568 | xCol->addPropertyChangeListener( aPropsListenedTo[i], this ); | ||||||||||
1569 | } | ||||||||||
1570 | } | ||||||||||
1571 | } | ||||||||||
1572 | |||||||||||
1573 | |||||||||||
1574 | void FmXGridPeer::removeColumnListeners(const Reference< XPropertySet >& xCol) | ||||||||||
1575 | { | ||||||||||
1576 | // the same props as in addColumnListeners... linux has problems with global static UStrings, so | ||||||||||
1577 | // we have to do it this way... | ||||||||||
1578 | static const std::u16string_view aPropsListenedTo[] = | ||||||||||
1579 | { | ||||||||||
1580 | u"" FM_PROP_LABEL"Label", u"" FM_PROP_WIDTH"Width", u"" FM_PROP_HIDDEN"Hidden", u"" FM_PROP_ALIGN"Align", | ||||||||||
1581 | u"" FM_PROP_FORMATKEY"FormatKey" | ||||||||||
1582 | }; | ||||||||||
1583 | |||||||||||
1584 | Reference< XPropertySetInfo > xInfo = xCol->getPropertySetInfo(); | ||||||||||
1585 | for (const auto & i : aPropsListenedTo) | ||||||||||
1586 | if (xInfo->hasPropertyByName(i)) | ||||||||||
1587 | xCol->removePropertyChangeListener(i, this); | ||||||||||
1588 | } | ||||||||||
1589 | |||||||||||
1590 | |||||||||||
1591 | void FmXGridPeer::setColumns(const Reference< XIndexContainer >& Columns) | ||||||||||
1592 | { | ||||||||||
1593 | SolarMutexGuard aGuard; | ||||||||||
1594 | |||||||||||
1595 | VclPtr< FmGridControl > pGrid = GetAs< FmGridControl >(); | ||||||||||
1596 | |||||||||||
1597 | if (m_xColumns.is()) | ||||||||||
1598 | { | ||||||||||
1599 | Reference< XPropertySet > xCol; | ||||||||||
1600 | for (sal_Int32 i = 0; i < m_xColumns->getCount(); i++) | ||||||||||
1601 | { | ||||||||||
1602 | xCol.set(m_xColumns->getByIndex(i), css::uno::UNO_QUERY); | ||||||||||
1603 | removeColumnListeners(xCol); | ||||||||||
1604 | } | ||||||||||
1605 | Reference< XContainer > xContainer(m_xColumns, UNO_QUERY); | ||||||||||
1606 | xContainer->removeContainerListener(this); | ||||||||||
1607 | |||||||||||
1608 | Reference< XSelectionSupplier > xSelSupplier(m_xColumns, UNO_QUERY); | ||||||||||
1609 | xSelSupplier->removeSelectionChangeListener(this); | ||||||||||
1610 | |||||||||||
1611 | Reference< XReset > xColumnReset(m_xColumns, UNO_QUERY); | ||||||||||
1612 | if (xColumnReset.is()) | ||||||||||
1613 | xColumnReset->removeResetListener(static_cast<XResetListener*>(this)); | ||||||||||
1614 | } | ||||||||||
1615 | if (Columns.is()) | ||||||||||
1616 | { | ||||||||||
1617 | Reference< XContainer > xContainer(Columns, UNO_QUERY); | ||||||||||
1618 | xContainer->addContainerListener(this); | ||||||||||
1619 | |||||||||||
1620 | Reference< XSelectionSupplier > xSelSupplier(Columns, UNO_QUERY); | ||||||||||
1621 | xSelSupplier->addSelectionChangeListener(this); | ||||||||||
1622 | |||||||||||
1623 | Reference< XPropertySet > xCol; | ||||||||||
1624 | for (sal_Int32 i = 0; i < Columns->getCount(); i++) | ||||||||||
1625 | { | ||||||||||
1626 | xCol.set(Columns->getByIndex(i), css::uno::UNO_QUERY); | ||||||||||
1627 | addColumnListeners(xCol); | ||||||||||
1628 | } | ||||||||||
1629 | |||||||||||
1630 | Reference< XReset > xColumnReset(Columns, UNO_QUERY); | ||||||||||
1631 | if (xColumnReset.is()) | ||||||||||
1632 | xColumnReset->addResetListener(static_cast<XResetListener*>(this)); | ||||||||||
1633 | } | ||||||||||
1634 | m_xColumns = Columns; | ||||||||||
1635 | if (pGrid) | ||||||||||
1636 | { | ||||||||||
1637 | pGrid->InitColumnsByModels(m_xColumns); | ||||||||||
1638 | |||||||||||
1639 | if (m_xColumns.is()) | ||||||||||
1640 | { | ||||||||||
1641 | EventObject aEvt(m_xColumns); | ||||||||||
1642 | selectionChanged(aEvt); | ||||||||||
1643 | } | ||||||||||
1644 | } | ||||||||||
1645 | } | ||||||||||
1646 | |||||||||||
1647 | |||||||||||
1648 | void FmXGridPeer::setDesignMode(sal_Bool bOn) | ||||||||||
1649 | { | ||||||||||
1650 | if (bOn != isDesignMode()) | ||||||||||
1651 | { | ||||||||||
1652 | VclPtr<vcl::Window> pWin = GetWindow(); | ||||||||||
1653 | if (pWin) | ||||||||||
1654 | static_cast<FmGridControl*>(pWin.get())->SetDesignMode(bOn); | ||||||||||
1655 | } | ||||||||||
1656 | |||||||||||
1657 | if (bOn) | ||||||||||
1658 | DisConnectFromDispatcher(); | ||||||||||
1659 | else | ||||||||||
1660 | UpdateDispatches(); // will connect if not already connected and just update else | ||||||||||
1661 | } | ||||||||||
1662 | |||||||||||
1663 | |||||||||||
1664 | sal_Bool FmXGridPeer::isDesignMode() | ||||||||||
1665 | { | ||||||||||
1666 | VclPtr<vcl::Window> pWin = GetWindow(); | ||||||||||
1667 | if (pWin) | ||||||||||
1668 | return static_cast<FmGridControl*>(pWin.get())->IsDesignMode(); | ||||||||||
1669 | else | ||||||||||
1670 | return false; | ||||||||||
1671 | } | ||||||||||
1672 | |||||||||||
1673 | |||||||||||
1674 | void FmXGridPeer::elementInserted(const ContainerEvent& evt) | ||||||||||
1675 | { | ||||||||||
1676 | SolarMutexGuard aGuard; | ||||||||||
1677 | |||||||||||
1678 | VclPtr< FmGridControl > pGrid = GetAs< FmGridControl >(); | ||||||||||
1679 | // take handle column into account | ||||||||||
1680 | if (!pGrid || !m_xColumns.is() || pGrid->IsInColumnMove() || m_xColumns->getCount() == static_cast<sal_Int32>(pGrid->GetModelColCount())) | ||||||||||
1681 | return; | ||||||||||
1682 | |||||||||||
1683 | Reference< XPropertySet > xNewColumn(evt.Element, css::uno::UNO_QUERY); | ||||||||||
1684 | addColumnListeners(xNewColumn); | ||||||||||
1685 | |||||||||||
1686 | OUString aName = ::comphelper::getString(xNewColumn->getPropertyValue(FM_PROP_LABEL"Label")); | ||||||||||
1687 | Any aWidth = xNewColumn->getPropertyValue(FM_PROP_WIDTH"Width"); | ||||||||||
1688 | sal_Int32 nWidth = 0; | ||||||||||
1689 | if (aWidth >>= nWidth) | ||||||||||
1690 | nWidth = pGrid->LogicToPixel(Point(nWidth, 0), MapMode(MapUnit::Map10thMM)).X(); | ||||||||||
1691 | |||||||||||
1692 | pGrid->AppendColumn(aName, static_cast<sal_uInt16>(nWidth), static_cast<sal_Int16>(::comphelper::getINT32(evt.Accessor))); | ||||||||||
1693 | |||||||||||
1694 | // now set the column | ||||||||||
1695 | DbGridColumn* pCol = pGrid->GetColumns()[ ::comphelper::getINT32(evt.Accessor) ].get(); | ||||||||||
1696 | pCol->setModel(xNewColumn); | ||||||||||
1697 | |||||||||||
1698 | Any aHidden = xNewColumn->getPropertyValue(FM_PROP_HIDDEN"Hidden"); | ||||||||||
1699 | if (::comphelper::getBOOL(aHidden)) | ||||||||||
1700 | pGrid->HideColumn(pCol->GetId()); | ||||||||||
1701 | |||||||||||
1702 | FormControlFactory( m_xContext ).initializeTextFieldLineEnds( xNewColumn ); | ||||||||||
1703 | } | ||||||||||
1704 | |||||||||||
1705 | |||||||||||
1706 | void FmXGridPeer::elementReplaced(const ContainerEvent& evt) | ||||||||||
1707 | { | ||||||||||
1708 | SolarMutexGuard aGuard; | ||||||||||
1709 | |||||||||||
1710 | VclPtr< FmGridControl > pGrid = GetAs< FmGridControl >(); | ||||||||||
1711 | |||||||||||
1712 | // take handle column into account | ||||||||||
1713 | if (!pGrid || !m_xColumns.is() || pGrid->IsInColumnMove()) | ||||||||||
1714 | return; | ||||||||||
1715 | |||||||||||
1716 | Reference< XPropertySet > xNewColumn(evt.Element, css::uno::UNO_QUERY); | ||||||||||
1717 | Reference< XPropertySet > xOldColumn( | ||||||||||
1718 | evt.ReplacedElement, css::uno::UNO_QUERY); | ||||||||||
1719 | |||||||||||
1720 | bool bWasEditing = pGrid->IsEditing(); | ||||||||||
1721 | if (bWasEditing) | ||||||||||
1722 | pGrid->DeactivateCell(); | ||||||||||
1723 | |||||||||||
1724 | pGrid->RemoveColumn(pGrid->GetColumnIdFromModelPos(static_cast<sal_uInt16>(::comphelper::getINT32(evt.Accessor)))); | ||||||||||
1725 | |||||||||||
1726 | removeColumnListeners(xOldColumn); | ||||||||||
1727 | addColumnListeners(xNewColumn); | ||||||||||
1728 | |||||||||||
1729 | OUString aName = ::comphelper::getString(xNewColumn->getPropertyValue(FM_PROP_LABEL"Label")); | ||||||||||
1730 | Any aWidth = xNewColumn->getPropertyValue(FM_PROP_WIDTH"Width"); | ||||||||||
1731 | sal_Int32 nWidth = 0; | ||||||||||
1732 | if (aWidth >>= nWidth) | ||||||||||
1733 | nWidth = pGrid->LogicToPixel(Point(nWidth, 0), MapMode(MapUnit::Map10thMM)).X(); | ||||||||||
1734 | sal_uInt16 nNewId = pGrid->AppendColumn(aName, static_cast<sal_uInt16>(nWidth), static_cast<sal_Int16>(::comphelper::getINT32(evt.Accessor))); | ||||||||||
1735 | sal_uInt16 nNewPos = pGrid->GetModelColumnPos(nNewId); | ||||||||||
1736 | |||||||||||
1737 | // set the model of the new column | ||||||||||
1738 | DbGridColumn* pCol = pGrid->GetColumns()[ nNewPos ].get(); | ||||||||||
1739 | |||||||||||
1740 | // for initializing this grid column, we need the fields of the grid's data source | ||||||||||
1741 | Reference< XColumnsSupplier > xSuppColumns; | ||||||||||
1742 | CursorWrapper* pGridDataSource = pGrid->getDataSource(); | ||||||||||
1743 | if ( pGridDataSource ) | ||||||||||
1744 | xSuppColumns.set(Reference< XInterface >( *pGridDataSource ), css::uno::UNO_QUERY); | ||||||||||
1745 | Reference< XNameAccess > xColumnsByName; | ||||||||||
1746 | if ( xSuppColumns.is() ) | ||||||||||
1747 | xColumnsByName = xSuppColumns->getColumns(); | ||||||||||
1748 | Reference< XIndexAccess > xColumnsByIndex( xColumnsByName, UNO_QUERY ); | ||||||||||
1749 | |||||||||||
1750 | if ( xColumnsByIndex.is() ) | ||||||||||
1751 | FmGridControl::InitColumnByField( pCol, xNewColumn, xColumnsByName, xColumnsByIndex ); | ||||||||||
1752 | else | ||||||||||
1753 | // the simple version, applies when the grid is not yet connected to a data source | ||||||||||
1754 | pCol->setModel(xNewColumn); | ||||||||||
1755 | |||||||||||
1756 | if (bWasEditing) | ||||||||||
1757 | pGrid->ActivateCell(); | ||||||||||
1758 | } | ||||||||||
1759 | |||||||||||
1760 | |||||||||||
1761 | void FmXGridPeer::elementRemoved(const ContainerEvent& evt) | ||||||||||
1762 | { | ||||||||||
1763 | SolarMutexGuard aGuard; | ||||||||||
1764 | |||||||||||
1765 | VclPtr< FmGridControl > pGrid = GetAs< FmGridControl >(); | ||||||||||
1766 | |||||||||||
1767 | // take handle column into account | ||||||||||
1768 | if (!pGrid || !m_xColumns.is() || pGrid->IsInColumnMove() || m_xColumns->getCount() == static_cast<sal_Int32>(pGrid->GetModelColCount())) | ||||||||||
1769 | return; | ||||||||||
1770 | |||||||||||
1771 | pGrid->RemoveColumn(pGrid->GetColumnIdFromModelPos(static_cast<sal_uInt16>(::comphelper::getINT32(evt.Accessor)))); | ||||||||||
1772 | |||||||||||
1773 | Reference< XPropertySet > xOldColumn(evt.Element, css::uno::UNO_QUERY); | ||||||||||
1774 | removeColumnListeners(xOldColumn); | ||||||||||
1775 | } | ||||||||||
1776 | |||||||||||
1777 | |||||||||||
1778 | void FmXGridPeer::setProperty( const OUString& PropertyName, const Any& Value) | ||||||||||
1779 | { | ||||||||||
1780 | SolarMutexGuard aGuard; | ||||||||||
1781 | |||||||||||
1782 | VclPtr< FmGridControl > pGrid = GetAs< FmGridControl >(); | ||||||||||
| |||||||||||
1783 | |||||||||||
1784 | bool bVoid = !Value.hasValue(); | ||||||||||
1785 | |||||||||||
1786 | if ( PropertyName == FM_PROP_TEXTLINECOLOR"TextLineColor" ) | ||||||||||
1787 | { | ||||||||||
1788 | ::Color aTextLineColor( bVoid
| ||||||||||
1789 | if (bVoid
| ||||||||||
1790 | { | ||||||||||
1791 | pGrid->SetTextLineColor(); | ||||||||||
1792 | pGrid->GetDataWindow().SetTextLineColor(); | ||||||||||
1793 | } | ||||||||||
1794 | else | ||||||||||
1795 | { | ||||||||||
1796 | pGrid->SetTextLineColor(aTextLineColor); | ||||||||||
1797 | pGrid->GetDataWindow().SetTextLineColor(aTextLineColor); | ||||||||||
1798 | } | ||||||||||
1799 | |||||||||||
1800 | // need to forward this to the columns | ||||||||||
1801 | std::vector< std::unique_ptr<DbGridColumn> > const & rColumns = pGrid->GetColumns(); | ||||||||||
1802 | for (auto const & pLoop : rColumns) | ||||||||||
1803 | { | ||||||||||
1804 | FmXGridCell* pXCell = pLoop->GetCell(); | ||||||||||
1805 | if (pXCell) | ||||||||||
1806 | { | ||||||||||
1807 | if (bVoid) | ||||||||||
1808 | pXCell->SetTextLineColor(); | ||||||||||
1809 | else | ||||||||||
1810 | pXCell->SetTextLineColor(aTextLineColor); | ||||||||||
1811 | } | ||||||||||
1812 | } | ||||||||||
1813 | |||||||||||
1814 | if (isDesignMode()) | ||||||||||
1815 | pGrid->Invalidate(); | ||||||||||
1816 | } | ||||||||||
1817 | else if ( PropertyName == FM_PROP_FONTEMPHASISMARK"FontEmphasisMark" ) | ||||||||||
1818 | { | ||||||||||
1819 | vcl::Font aGridFont = pGrid->GetControlFont(); | ||||||||||
1820 | sal_Int16 nValue = ::comphelper::getINT16(Value); | ||||||||||
1821 | aGridFont.SetEmphasisMark( static_cast<FontEmphasisMark>(nValue) ); | ||||||||||
1822 | pGrid->SetControlFont( aGridFont ); | ||||||||||
1823 | } | ||||||||||
1824 | else if ( PropertyName == FM_PROP_FONTRELIEF"FontRelief" ) | ||||||||||
1825 | { | ||||||||||
1826 | vcl::Font aGridFont = pGrid->GetControlFont(); | ||||||||||
1827 | sal_Int16 nValue = ::comphelper::getINT16(Value); | ||||||||||
1828 | aGridFont.SetRelief( static_cast<FontRelief>(nValue) ); | ||||||||||
1829 | pGrid->SetControlFont( aGridFont ); | ||||||||||
1830 | } | ||||||||||
1831 | else if ( PropertyName == FM_PROP_HELPURL"HelpURL" ) | ||||||||||
1832 | { | ||||||||||
1833 | OUString sHelpURL; | ||||||||||
1834 | OSL_VERIFY( Value >>= sHelpURL )do { if (!(Value >>= sHelpURL)) do { if (true && (!(0))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ( "legacy.osl"), ("/home/maarten/src/libreoffice/core/svx/source/fmcomp/fmgridif.cxx" ":" "1834" ": "), "OSL_ASSERT: %s", "0"); } } while (false); } while (0); | ||||||||||
1835 | INetURLObject aHID( sHelpURL ); | ||||||||||
1836 | if ( aHID.GetProtocol() == INetProtocol::Hid ) | ||||||||||
1837 | sHelpURL = aHID.GetURLPath(); | ||||||||||
1838 | pGrid->SetHelpId( OUStringToOString( sHelpURL, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)) ) ); | ||||||||||
1839 | } | ||||||||||
1840 | else if ( PropertyName == FM_PROP_DISPLAYSYNCHRON"DisplayIsSynchron" ) | ||||||||||
1841 | { | ||||||||||
1842 | pGrid->setDisplaySynchron(::comphelper::getBOOL(Value)); | ||||||||||
1843 | } | ||||||||||
1844 | else if ( PropertyName == FM_PROP_CURSORCOLOR"CursorColor" ) | ||||||||||
1845 | { | ||||||||||
1846 | if (bVoid) | ||||||||||
1847 | pGrid->SetCursorColor(COL_TRANSPARENT); | ||||||||||
1848 | else | ||||||||||
1849 | pGrid->SetCursorColor( ::Color(::comphelper::getINT32(Value))); | ||||||||||
1850 | if (isDesignMode()) | ||||||||||
1851 | pGrid->Invalidate(); | ||||||||||
1852 | } | ||||||||||
1853 | else if ( PropertyName == FM_PROP_ALWAYSSHOWCURSOR"AlwaysShowCursor" ) | ||||||||||
1854 | { | ||||||||||
1855 | pGrid->EnablePermanentCursor(::comphelper::getBOOL(Value)); | ||||||||||
1856 | if (isDesignMode()) | ||||||||||
1857 | pGrid->Invalidate(); | ||||||||||
1858 | } | ||||||||||
1859 | else if ( PropertyName == FM_PROP_FONT"FontDescriptor" ) | ||||||||||
1860 | { | ||||||||||
1861 | if ( bVoid ) | ||||||||||
1862 | pGrid->SetControlFont( vcl::Font() ); | ||||||||||
1863 | else | ||||||||||
1864 | { | ||||||||||
1865 | css::awt::FontDescriptor aFont; | ||||||||||
1866 | if (Value >>= aFont) | ||||||||||
1867 | { | ||||||||||
1868 | vcl::Font aNewVclFont; | ||||||||||
1869 | if (aFont != ::comphelper::getDefaultFont()) // is this the default | ||||||||||
1870 | aNewVclFont = ImplCreateFont( aFont ); | ||||||||||
1871 | |||||||||||
1872 | // need to add relief and emphasis (they're stored in a VCL-Font, but not in a FontDescriptor | ||||||||||
1873 | vcl::Font aOldVclFont = pGrid->GetControlFont(); | ||||||||||
1874 | aNewVclFont.SetRelief( aOldVclFont.GetRelief() ); | ||||||||||
1875 | aNewVclFont.SetEmphasisMark( aOldVclFont.GetEmphasisMark() ); | ||||||||||
1876 | |||||||||||
1877 | // now set it ... | ||||||||||
1878 | pGrid->SetControlFont( aNewVclFont ); | ||||||||||
1879 | |||||||||||
1880 | // if our row-height property is void (which means "calculate it font-dependent") we have | ||||||||||
1881 | // to adjust the control's row height | ||||||||||
1882 | Reference< XPropertySet > xModelSet(getColumns(), UNO_QUERY); | ||||||||||
1883 | if (xModelSet.is() && ::comphelper::hasProperty(FM_PROP_ROWHEIGHT"RowHeight", xModelSet)) | ||||||||||
1884 | { | ||||||||||
1885 | Any aHeight = xModelSet->getPropertyValue(FM_PROP_ROWHEIGHT"RowHeight"); | ||||||||||
1886 | if (!aHeight.hasValue()) | ||||||||||
1887 | pGrid->SetDataRowHeight(0); | ||||||||||
1888 | } | ||||||||||
1889 | |||||||||||
1890 | } | ||||||||||
1891 | } | ||||||||||
1892 | } | ||||||||||
1893 | else if ( PropertyName == FM_PROP_BACKGROUNDCOLOR"BackgroundColor" ) | ||||||||||
1894 | { | ||||||||||
1895 | if ( bVoid ) | ||||||||||
1896 | { | ||||||||||
1897 | pGrid->SetControlBackground(); | ||||||||||
1898 | } | ||||||||||
1899 | else | ||||||||||
1900 | { | ||||||||||
1901 | ::Color aColor( ::comphelper::getINT32(Value) ); | ||||||||||
1902 | pGrid->SetBackground( aColor ); | ||||||||||
1903 | pGrid->SetControlBackground( aColor ); | ||||||||||
1904 | } | ||||||||||
1905 | } | ||||||||||
1906 | else if ( PropertyName == FM_PROP_TEXTCOLOR"TextColor" ) | ||||||||||
1907 | { | ||||||||||
1908 | if ( bVoid ) | ||||||||||
1909 | { | ||||||||||
1910 | pGrid->SetControlForeground(); | ||||||||||
1911 | } | ||||||||||
1912 | else | ||||||||||
1913 | { | ||||||||||
1914 | ::Color aColor( ::comphelper::getINT32(Value) ); | ||||||||||
1915 | pGrid->SetTextColor( aColor ); | ||||||||||
1916 | pGrid->SetControlForeground( aColor ); | ||||||||||
1917 | } | ||||||||||
1918 | } | ||||||||||
1919 | else if ( PropertyName == FM_PROP_ROWHEIGHT"RowHeight" ) | ||||||||||
1920 | { | ||||||||||
1921 | sal_Int32 nLogHeight(0); | ||||||||||
1922 | if (Value >>= nLogHeight) | ||||||||||
1923 | { | ||||||||||
1924 | sal_Int32 nHeight = pGrid->LogicToPixel(Point(0, nLogHeight), MapMode(MapUnit::Map10thMM)).Y(); | ||||||||||
1925 | // take the zoom factor into account | ||||||||||
1926 | nHeight = pGrid->CalcZoom(nHeight); | ||||||||||
1927 | pGrid->SetDataRowHeight(nHeight); | ||||||||||
1928 | } | ||||||||||
1929 | else if (bVoid) | ||||||||||
1930 | pGrid->SetDataRowHeight(0); | ||||||||||
1931 | } | ||||||||||
1932 | else if ( PropertyName == FM_PROP_HASNAVIGATION"HasNavigationBar" ) | ||||||||||
1933 | { | ||||||||||
1934 | bool bValue( true ); | ||||||||||
1935 | OSL_VERIFY( Value >>= bValue )do { if (!(Value >>= bValue)) do { if (true && ( !(0))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/home/maarten/src/libreoffice/core/svx/source/fmcomp/fmgridif.cxx" ":" "1935" ": "), "OSL_ASSERT: %s", "0"); } } while (false); } while (0); | ||||||||||
1936 | pGrid->EnableNavigationBar( bValue ); | ||||||||||
1937 | } | ||||||||||
1938 | else if ( PropertyName == FM_PROP_RECORDMARKER"HasRecordMarker" ) | ||||||||||
1939 | { | ||||||||||
1940 | bool bValue( true ); | ||||||||||
1941 | OSL_VERIFY( Value >>= bValue )do { if (!(Value >>= bValue)) do { if (true && ( !(0))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/home/maarten/src/libreoffice/core/svx/source/fmcomp/fmgridif.cxx" ":" "1941" ": "), "OSL_ASSERT: %s", "0"); } } while (false); } while (0); | ||||||||||
1942 | pGrid->EnableHandle( bValue ); | ||||||||||
1943 | } | ||||||||||
1944 | else if ( PropertyName == FM_PROP_ENABLED"Enabled" ) | ||||||||||
1945 | { | ||||||||||
1946 | bool bValue( true ); | ||||||||||
1947 | OSL_VERIFY( Value >>= bValue )do { if (!(Value >>= bValue)) do { if (true && ( !(0))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/home/maarten/src/libreoffice/core/svx/source/fmcomp/fmgridif.cxx" ":" "1947" ": "), "OSL_ASSERT: %s", "0"); } } while (false); } while (0); | ||||||||||
1948 | |||||||||||
1949 | // In design mode, disable only the data window. | ||||||||||
1950 | // Else the control cannot be configured anymore. | ||||||||||
1951 | if (isDesignMode()) | ||||||||||
1952 | pGrid->GetDataWindow().Enable( bValue ); | ||||||||||
1953 | else | ||||||||||
1954 | pGrid->Enable( bValue ); | ||||||||||
1955 | } | ||||||||||
1956 | else | ||||||||||
1957 | VCLXWindow::setProperty( PropertyName, Value ); | ||||||||||
1958 | } | ||||||||||
1959 | |||||||||||
1960 | |||||||||||
1961 | Reference< XAccessibleContext > FmXGridPeer::CreateAccessibleContext() | ||||||||||
1962 | { | ||||||||||
1963 | Reference< XAccessibleContext > xContext; | ||||||||||
1964 | |||||||||||
1965 | // use the AccessibleContext provided by the VCL window | ||||||||||
1966 | VclPtr<vcl::Window> pGrid = GetWindow(); | ||||||||||
1967 | if ( pGrid ) | ||||||||||
1968 | { | ||||||||||
1969 | Reference< XAccessible > xAcc( pGrid->GetAccessible() ); | ||||||||||
1970 | if ( xAcc.is() ) | ||||||||||
1971 | xContext = xAcc->getAccessibleContext(); | ||||||||||
1972 | // TODO: this has a slight conceptual problem: | ||||||||||
1973 | |||||||||||
1974 | // We know that the XAccessible and XAccessibleContext implementation of the browse | ||||||||||
1975 | // box is the same (the class implements both interfaces), which, speaking strictly, | ||||||||||
1976 | // is bad here (means when a browse box acts as UnoControl): We (the FmXGridPeer) are | ||||||||||
1977 | // the XAccessible here, and the browse box should be able to provide us an XAccessibleContext, | ||||||||||
1978 | // but it should _not_ be the XAccessible itself. | ||||||||||
1979 | // However, as long as no client implementation uses dirty hacks such as querying an | ||||||||||
1980 | // XAccessibleContext for XAccessible, this should not be a problem. | ||||||||||
1981 | } | ||||||||||
1982 | |||||||||||
1983 | if ( !xContext.is() ) | ||||||||||
1984 | xContext = VCLXWindow::CreateAccessibleContext( ); | ||||||||||
1985 | |||||||||||
1986 | return xContext; | ||||||||||
1987 | } | ||||||||||
1988 | |||||||||||
1989 | |||||||||||
1990 | Any FmXGridPeer::getProperty( const OUString& _rPropertyName ) | ||||||||||
1991 | { | ||||||||||
1992 | Any aProp; | ||||||||||
1993 | if (GetWindow()) | ||||||||||
1994 | { | ||||||||||
1995 | VclPtr< FmGridControl > pGrid = GetAs< FmGridControl >(); | ||||||||||
1996 | vcl::Window* pDataWindow = &pGrid->GetDataWindow(); | ||||||||||
1997 | |||||||||||
1998 | if ( _rPropertyName == FM_PROP_NAME"Name" ) | ||||||||||
1999 | { | ||||||||||
2000 | vcl::Font aFont = pDataWindow->GetControlFont(); | ||||||||||
2001 | aProp <<= ImplCreateFontDescriptor( aFont ); | ||||||||||
2002 | } | ||||||||||
2003 | else if ( _rPropertyName == FM_PROP_TEXTCOLOR"TextColor" ) | ||||||||||
2004 | { | ||||||||||
2005 | aProp <<= pDataWindow->GetControlForeground(); | ||||||||||
2006 | } | ||||||||||
2007 | else if ( _rPropertyName == FM_PROP_BACKGROUNDCOLOR"BackgroundColor" ) | ||||||||||
2008 | { | ||||||||||
2009 | aProp <<= pDataWindow->GetControlBackground(); | ||||||||||
2010 | } | ||||||||||
2011 | else if ( _rPropertyName == FM_PROP_ROWHEIGHT"RowHeight" ) | ||||||||||
2012 | { | ||||||||||
2013 | sal_Int32 nPixelHeight = pGrid->GetDataRowHeight(); | ||||||||||
2014 | // take the zoom factor into account | ||||||||||
2015 | nPixelHeight = pGrid->CalcReverseZoom(nPixelHeight); | ||||||||||
2016 | aProp <<= static_cast<sal_Int32>(pGrid->PixelToLogic(Point(0, nPixelHeight), MapMode(MapUnit::Map10thMM)).Y()); | ||||||||||
2017 | } | ||||||||||
2018 | else if ( _rPropertyName == FM_PROP_HASNAVIGATION"HasNavigationBar" ) | ||||||||||
2019 | { | ||||||||||
2020 | bool bHasNavBar = pGrid->HasNavigationBar(); | ||||||||||
2021 | aProp <<= bHasNavBar; | ||||||||||
2022 | } | ||||||||||
2023 | else if ( _rPropertyName == FM_PROP_RECORDMARKER"HasRecordMarker" ) | ||||||||||
2024 | { | ||||||||||
2025 | bool bHasHandle = pGrid->HasHandle(); | ||||||||||
2026 | aProp <<= bHasHandle; | ||||||||||
2027 | } | ||||||||||
2028 | else if ( _rPropertyName == FM_PROP_ENABLED"Enabled" ) | ||||||||||
2029 | { | ||||||||||
2030 | aProp <<= pDataWindow->IsEnabled(); | ||||||||||
2031 | } | ||||||||||
2032 | else | ||||||||||
2033 | aProp = VCLXWindow::getProperty( _rPropertyName ); | ||||||||||
2034 | } | ||||||||||
2035 | return aProp; | ||||||||||
2036 | } | ||||||||||
2037 | |||||||||||
2038 | |||||||||||
2039 | void FmXGridPeer::dispose() | ||||||||||
2040 | { | ||||||||||
2041 | EventObject aEvt; | ||||||||||
2042 | aEvt.Source = static_cast< ::cppu::OWeakObject* >(this); | ||||||||||
2043 | m_aModifyListeners.disposeAndClear(aEvt); | ||||||||||
2044 | m_aUpdateListeners.disposeAndClear(aEvt); | ||||||||||
2045 | m_aContainerListeners.disposeAndClear(aEvt); | ||||||||||
2046 | VCLXWindow::dispose(); | ||||||||||
2047 | |||||||||||
2048 | // release all interceptors | ||||||||||
2049 | Reference< XDispatchProviderInterceptor > xInterceptor( m_xFirstDispatchInterceptor ); | ||||||||||
2050 | m_xFirstDispatchInterceptor.clear(); | ||||||||||
2051 | while ( xInterceptor.is() ) | ||||||||||
2052 | { | ||||||||||
2053 | // tell the interceptor it has a new (means no) predecessor | ||||||||||
2054 | xInterceptor->setMasterDispatchProvider( nullptr ); | ||||||||||
2055 | |||||||||||
2056 | // ask for its successor | ||||||||||
2057 | Reference< XDispatchProvider > xSlave = xInterceptor->getSlaveDispatchProvider(); | ||||||||||
2058 | // and give it the new (means no) successoert | ||||||||||
2059 | xInterceptor->setSlaveDispatchProvider( nullptr ); | ||||||||||
2060 | |||||||||||
2061 | // start over with the next chain element | ||||||||||
2062 | xInterceptor.set(xSlave, css::uno::UNO_QUERY); | ||||||||||
2063 | } | ||||||||||
2064 | |||||||||||
2065 | DisConnectFromDispatcher(); | ||||||||||
2066 | setRowSet(Reference< XRowSet > ()); | ||||||||||
2067 | } | ||||||||||
2068 | |||||||||||
2069 | // XContainer | ||||||||||
2070 | |||||||||||
2071 | void FmXGridPeer::addContainerListener(const Reference< XContainerListener >& l) | ||||||||||
2072 | { | ||||||||||
2073 | m_aContainerListeners.addInterface( l ); | ||||||||||
2074 | } | ||||||||||
2075 | |||||||||||
2076 | void FmXGridPeer::removeContainerListener(const Reference< XContainerListener >& l) | ||||||||||
2077 | { | ||||||||||
2078 | m_aContainerListeners.removeInterface( l ); | ||||||||||
2079 | } | ||||||||||
2080 | |||||||||||
2081 | // css::data::XDatabaseCursorSupplier | ||||||||||
2082 | |||||||||||
2083 | void FmXGridPeer::startCursorListening() | ||||||||||
2084 | { | ||||||||||
2085 | if (!m_nCursorListening) | ||||||||||
2086 | { | ||||||||||
2087 | if (m_xCursor.is()) | ||||||||||
2088 | m_xCursor->addRowSetListener(this); | ||||||||||
2089 | |||||||||||
2090 | Reference< XReset > xReset(m_xCursor, UNO_QUERY); | ||||||||||
2091 | if (xReset.is()) | ||||||||||
2092 | xReset->addResetListener(this); | ||||||||||
2093 | |||||||||||
2094 | // register all listeners | ||||||||||
2095 | Reference< XPropertySet > xSet(m_xCursor, UNO_QUERY); | ||||||||||
2096 | if (xSet.is()) | ||||||||||
2097 | { | ||||||||||
2098 | xSet->addPropertyChangeListener(FM_PROP_ISMODIFIED"IsModified", this); | ||||||||||
2099 | xSet->addPropertyChangeListener(FM_PROP_ROWCOUNT"RowCount", this); | ||||||||||
2100 | } | ||||||||||
2101 | } | ||||||||||
2102 | m_nCursorListening++; | ||||||||||
2103 | } | ||||||||||
2104 | |||||||||||
2105 | |||||||||||
2106 | void FmXGridPeer::stopCursorListening() | ||||||||||
2107 | { | ||||||||||
2108 | if (--m_nCursorListening) | ||||||||||
2109 | return; | ||||||||||
2110 | |||||||||||
2111 | if (m_xCursor.is()) | ||||||||||
2112 | m_xCursor->removeRowSetListener(this); | ||||||||||
2113 | |||||||||||
2114 | Reference< XReset > xReset(m_xCursor, UNO_QUERY); | ||||||||||
2115 | if (xReset.is()) | ||||||||||
2116 | xReset->removeResetListener(this); | ||||||||||
2117 | |||||||||||
2118 | Reference< XPropertySet > xSet(m_xCursor, UNO_QUERY); | ||||||||||
2119 | if (xSet.is()) | ||||||||||
2120 | { | ||||||||||
2121 | xSet->removePropertyChangeListener(FM_PROP_ISMODIFIED"IsModified", this); | ||||||||||
2122 | xSet->removePropertyChangeListener(FM_PROP_ROWCOUNT"RowCount", this); | ||||||||||
2123 | } | ||||||||||
2124 | } | ||||||||||
2125 | |||||||||||
2126 | |||||||||||
2127 | void FmXGridPeer::updateGrid(const Reference< XRowSet >& _rxCursor) | ||||||||||
2128 | { | ||||||||||
2129 | VclPtr< FmGridControl > pGrid = GetAs< FmGridControl >(); | ||||||||||
2130 | if (pGrid) | ||||||||||
2131 | pGrid->setDataSource(_rxCursor); | ||||||||||
2132 | } | ||||||||||
2133 | |||||||||||
2134 | |||||||||||
2135 | Reference< XRowSet > FmXGridPeer::getRowSet() | ||||||||||
2136 | { | ||||||||||
2137 | return m_xCursor; | ||||||||||
2138 | } | ||||||||||
2139 | |||||||||||
2140 | |||||||||||
2141 | void FmXGridPeer::setRowSet(const Reference< XRowSet >& _rDatabaseCursor) | ||||||||||
2142 | { | ||||||||||
2143 | VclPtr< FmGridControl > pGrid = GetAs< FmGridControl >(); | ||||||||||
2144 | if (!pGrid || !m_xColumns.is() || !m_xColumns->getCount()) | ||||||||||
2145 | return; | ||||||||||
2146 | // unregister all listeners | ||||||||||
2147 | if (m_xCursor.is()) | ||||||||||
2148 | { | ||||||||||
2149 | Reference< XLoadable > xLoadable(m_xCursor, UNO_QUERY); | ||||||||||
2150 | // only if the form is loaded we set the rowset | ||||||||||
2151 | if (xLoadable.is()) | ||||||||||
2152 | { | ||||||||||
2153 | stopCursorListening(); | ||||||||||
2154 | xLoadable->removeLoadListener(this); | ||||||||||
2155 | } | ||||||||||
2156 | } | ||||||||||
2157 | |||||||||||
2158 | m_xCursor = _rDatabaseCursor; | ||||||||||
2159 | |||||||||||
2160 | if (!pGrid) | ||||||||||
2161 | return; | ||||||||||
2162 | |||||||||||
2163 | Reference< XLoadable > xLoadable(m_xCursor, UNO_QUERY); | ||||||||||
2164 | // only if the form is loaded we set the rowset | ||||||||||
2165 | if (xLoadable.is() && xLoadable->isLoaded()) | ||||||||||
2166 | pGrid->setDataSource(m_xCursor); | ||||||||||
2167 | else | ||||||||||
2168 | pGrid->setDataSource(Reference< XRowSet > ()); | ||||||||||
2169 | |||||||||||
2170 | if (xLoadable.is()) | ||||||||||
2171 | { | ||||||||||
2172 | startCursorListening(); | ||||||||||
2173 | xLoadable->addLoadListener(this); | ||||||||||
2174 | } | ||||||||||
2175 | } | ||||||||||
2176 | |||||||||||
2177 | |||||||||||
2178 | void SAL_CALL FmXGridPeer::addGridControlListener( const Reference< XGridControlListener >& _listener ) | ||||||||||
2179 | { | ||||||||||
2180 | m_aGridControlListeners.addInterface( _listener ); | ||||||||||
2181 | } | ||||||||||
2182 | |||||||||||
2183 | |||||||||||
2184 | void SAL_CALL FmXGridPeer::removeGridControlListener( const Reference< XGridControlListener >& _listener ) | ||||||||||
2185 | { | ||||||||||
2186 | m_aGridControlListeners.removeInterface( _listener ); | ||||||||||
2187 | } | ||||||||||
2188 | |||||||||||
2189 | |||||||||||
2190 | sal_Int16 FmXGridPeer::getCurrentColumnPosition() | ||||||||||
2191 | { | ||||||||||
2192 | VclPtr< FmGridControl > pGrid = GetAs< FmGridControl >(); | ||||||||||
2193 | return pGrid ? pGrid->GetViewColumnPos(pGrid->GetCurColumnId()) : -1; | ||||||||||
2194 | } | ||||||||||
2195 | |||||||||||
2196 | |||||||||||
2197 | void FmXGridPeer::setCurrentColumnPosition(sal_Int16 nPos) | ||||||||||
2198 | { | ||||||||||
2199 | VclPtr< FmGridControl > pGrid = GetAs< FmGridControl >(); | ||||||||||
2200 | if (pGrid) | ||||||||||
2201 | pGrid->GoToColumnId(pGrid->GetColumnIdFromViewPos(nPos)); | ||||||||||
2202 | } | ||||||||||
2203 | |||||||||||
2204 | |||||||||||
2205 | void FmXGridPeer::selectionChanged(const EventObject& evt) | ||||||||||
2206 | { | ||||||||||
2207 | SolarMutexGuard aGuard; | ||||||||||
2208 | |||||||||||
2209 | VclPtr< FmGridControl > pGrid = GetAs< FmGridControl >(); | ||||||||||
2210 | if (!pGrid) | ||||||||||
2211 | return; | ||||||||||
2212 | |||||||||||
2213 | Reference< css::view::XSelectionSupplier > xSelSupplier(evt.Source, UNO_QUERY); | ||||||||||
2214 | Any aSelection = xSelSupplier->getSelection(); | ||||||||||
2215 | DBG_ASSERT(aSelection.getValueType().getTypeClass() == TypeClass_INTERFACE, "FmXGridPeer::selectionChanged : invalid selection !")do { if (true && (!(aSelection.getValueType().getTypeClass () == TypeClass_INTERFACE))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/svx/source/fmcomp/fmgridif.cxx" ":" "2215" ": "), "%s", "FmXGridPeer::selectionChanged : invalid selection !" ); } } while (false); | ||||||||||
2216 | Reference< XPropertySet > xSelection; | ||||||||||
2217 | aSelection >>= xSelection; | ||||||||||
2218 | if (xSelection.is()) | ||||||||||
2219 | { | ||||||||||
2220 | Reference< XPropertySet > xCol; | ||||||||||
2221 | sal_Int32 i = 0; | ||||||||||
2222 | sal_Int32 nColCount = m_xColumns->getCount(); | ||||||||||
2223 | |||||||||||
2224 | for (; i < nColCount; ++i) | ||||||||||
2225 | { | ||||||||||
2226 | m_xColumns->getByIndex(i) >>= xCol; | ||||||||||
2227 | if ( xCol == xSelection ) | ||||||||||
2228 | { | ||||||||||
2229 | pGrid->markColumn(pGrid->GetColumnIdFromModelPos(static_cast<sal_uInt16>(i))); | ||||||||||
2230 | break; | ||||||||||
2231 | } | ||||||||||
2232 | } | ||||||||||
2233 | // The columns have to be 1-based for the VCL control. | ||||||||||
2234 | // If necessary, pass on the selection to the VCL control | ||||||||||
2235 | if ( i != pGrid->GetSelectedColumn() ) | ||||||||||
2236 | { // (if this does not take effect, the selectionChanged was implicitly triggered by the control itself) | ||||||||||
2237 | if ( i < nColCount ) | ||||||||||
2238 | { | ||||||||||
2239 | pGrid->SelectColumnPos(pGrid->GetViewColumnPos(pGrid->GetColumnIdFromModelPos( static_cast<sal_uInt16>(i) )) + 1); | ||||||||||
2240 | // SelectColumnPos has led to an implicit ActivateCell again | ||||||||||
2241 | if (pGrid->IsEditing()) | ||||||||||
2242 | pGrid->DeactivateCell(); | ||||||||||
2243 | } | ||||||||||
2244 | else | ||||||||||
2245 | pGrid->SetNoSelection(); | ||||||||||
2246 | } | ||||||||||
2247 | } | ||||||||||
2248 | else | ||||||||||
2249 | pGrid->markColumn(USHRT_MAX(32767 *2 +1)); | ||||||||||
2250 | } | ||||||||||
2251 | |||||||||||
2252 | // XElementAccess | ||||||||||
2253 | |||||||||||
2254 | sal_Bool FmXGridPeer::hasElements() | ||||||||||
2255 | { | ||||||||||
2256 | return getCount() != 0; | ||||||||||
2257 | } | ||||||||||
2258 | |||||||||||
2259 | |||||||||||
2260 | Type SAL_CALL FmXGridPeer::getElementType( ) | ||||||||||
2261 | { | ||||||||||
2262 | return cppu::UnoType<css::awt::XControl>::get(); | ||||||||||
2263 | } | ||||||||||
2264 | |||||||||||
2265 | // XEnumerationAccess | ||||||||||
2266 | |||||||||||
2267 | Reference< XEnumeration > FmXGridPeer::createEnumeration() | ||||||||||
2268 | { | ||||||||||
2269 | return new ::comphelper::OEnumerationByIndex(this); | ||||||||||
2270 | } | ||||||||||
2271 | |||||||||||
2272 | // XIndexAccess | ||||||||||
2273 | |||||||||||
2274 | sal_Int32 FmXGridPeer::getCount() | ||||||||||
2275 | { | ||||||||||
2276 | VclPtr< FmGridControl > pGrid = GetAs< FmGridControl >(); | ||||||||||
2277 | if (pGrid) | ||||||||||
2278 | return pGrid->GetViewColCount(); | ||||||||||
2279 | else | ||||||||||
2280 | return 0; | ||||||||||
2281 | } | ||||||||||
2282 | |||||||||||
2283 | |||||||||||
2284 | Any FmXGridPeer::getByIndex(sal_Int32 _nIndex) | ||||||||||
2285 | { | ||||||||||
2286 | VclPtr< FmGridControl > pGrid = GetAs< FmGridControl >(); | ||||||||||
2287 | if (_nIndex < 0 || | ||||||||||
2288 | _nIndex >= getCount() || !pGrid) | ||||||||||
2289 | throw IndexOutOfBoundsException(); | ||||||||||
2290 | |||||||||||
2291 | Any aElement; | ||||||||||
2292 | // get the columnid | ||||||||||
2293 | sal_uInt16 nId = pGrid->GetColumnIdFromViewPos(static_cast<sal_uInt16>(_nIndex)); | ||||||||||
2294 | // get the list position | ||||||||||
2295 | sal_uInt16 nPos = pGrid->GetModelColumnPos(nId); | ||||||||||
2296 | |||||||||||
2297 | if ( nPos == GRID_COLUMN_NOT_FOUND((sal_uInt16) 0xFFFF) ) | ||||||||||
2298 | return aElement; | ||||||||||
2299 | |||||||||||
2300 | DbGridColumn* pCol = pGrid->GetColumns()[ nPos ].get(); | ||||||||||
2301 | Reference< css::awt::XControl > xControl(pCol->GetCell()); | ||||||||||
2302 | aElement <<= xControl; | ||||||||||
2303 | |||||||||||
2304 | return aElement; | ||||||||||
2305 | } | ||||||||||
2306 | |||||||||||
2307 | // css::util::XModeSelector | ||||||||||
2308 | |||||||||||
2309 | void FmXGridPeer::setMode(const OUString& Mode) | ||||||||||
2310 | { | ||||||||||
2311 | if (!supportsMode(Mode)) | ||||||||||
2312 | throw NoSupportException(); | ||||||||||
2313 | |||||||||||
2314 | if (Mode == m_aMode) | ||||||||||
2315 | return; | ||||||||||
2316 | |||||||||||
2317 | m_aMode = Mode; | ||||||||||
2318 | |||||||||||
2319 | VclPtr< FmGridControl > pGrid = GetAs< FmGridControl >(); | ||||||||||
2320 | if ( Mode == "FilterMode" ) | ||||||||||
2321 | pGrid->SetFilterMode(true); | ||||||||||
2322 | else | ||||||||||
2323 | { | ||||||||||
2324 | pGrid->SetFilterMode(false); | ||||||||||
2325 | pGrid->setDataSource(m_xCursor); | ||||||||||
2326 | } | ||||||||||
2327 | } | ||||||||||
2328 | |||||||||||
2329 | |||||||||||
2330 | OUString FmXGridPeer::getMode() | ||||||||||
2331 | { | ||||||||||
2332 | return m_aMode; | ||||||||||
2333 | } | ||||||||||
2334 | |||||||||||
2335 | |||||||||||
2336 | css::uno::Sequence<OUString> FmXGridPeer::getSupportedModes() | ||||||||||
2337 | { | ||||||||||
2338 | static css::uno::Sequence<OUString> const aModes | ||||||||||
2339 | { | ||||||||||
2340 | "DataMode", | ||||||||||
2341 | "FilterMode" | ||||||||||
2342 | }; | ||||||||||
2343 | return aModes; | ||||||||||
2344 | } | ||||||||||
2345 | |||||||||||
2346 | |||||||||||
2347 | sal_Bool FmXGridPeer::supportsMode(const OUString& Mode) | ||||||||||
2348 | { | ||||||||||
2349 | css::uno::Sequence<OUString> aModes(getSupportedModes()); | ||||||||||
2350 | return comphelper::findValue(aModes, Mode) != -1; | ||||||||||
2351 | } | ||||||||||
2352 | |||||||||||
2353 | |||||||||||
2354 | void FmXGridPeer::columnVisible(DbGridColumn const * pColumn) | ||||||||||
2355 | { | ||||||||||
2356 | VclPtr< FmGridControl > pGrid = GetAs< FmGridControl >(); | ||||||||||
2357 | |||||||||||
2358 | sal_Int32 _nIndex = pGrid->GetModelColumnPos(pColumn->GetId()); | ||||||||||
2359 | Reference< css::awt::XControl > xControl(pColumn->GetCell()); | ||||||||||
2360 | ContainerEvent aEvt; | ||||||||||
2361 | aEvt.Source = static_cast<XContainer*>(this); | ||||||||||
2362 | aEvt.Accessor <<= _nIndex; | ||||||||||
2363 | aEvt.Element <<= xControl; | ||||||||||
2364 | |||||||||||
2365 | m_aContainerListeners.notifyEach( &XContainerListener::elementInserted, aEvt ); | ||||||||||
2366 | } | ||||||||||
2367 | |||||||||||
2368 | |||||||||||
2369 | void FmXGridPeer::columnHidden(DbGridColumn const * pColumn) | ||||||||||
2370 | { | ||||||||||
2371 | VclPtr< FmGridControl > pGrid = GetAs< FmGridControl >(); | ||||||||||
2372 | |||||||||||
2373 | sal_Int32 _nIndex = pGrid->GetModelColumnPos(pColumn->GetId()); | ||||||||||
2374 | Reference< css::awt::XControl > xControl(pColumn->GetCell()); | ||||||||||
2375 | ContainerEvent aEvt; | ||||||||||
2376 | aEvt.Source = static_cast<XContainer*>(this); | ||||||||||
2377 | aEvt.Accessor <<= _nIndex; | ||||||||||
2378 | aEvt.Element <<= xControl; | ||||||||||
2379 | |||||||||||
2380 | m_aContainerListeners.notifyEach( &XContainerListener::elementRemoved, aEvt ); | ||||||||||
2381 | } | ||||||||||
2382 | |||||||||||
2383 | |||||||||||
2384 | void FmXGridPeer::draw( sal_Int32 x, sal_Int32 y ) | ||||||||||
2385 | { | ||||||||||
2386 | VclPtr< FmGridControl > pGrid = GetAs< FmGridControl >(); | ||||||||||
2387 | EditBrowseBoxFlags nOldFlags = pGrid->GetBrowserFlags(); | ||||||||||
2388 | pGrid->SetBrowserFlags(nOldFlags | EditBrowseBoxFlags::NO_HANDLE_COLUMN_CONTENT); | ||||||||||
2389 | |||||||||||
2390 | VCLXWindow::draw(x, y); | ||||||||||
2391 | |||||||||||
2392 | pGrid->SetBrowserFlags(nOldFlags); | ||||||||||
2393 | } | ||||||||||
2394 | |||||||||||
2395 | |||||||||||
2396 | Reference< css::frame::XDispatch > FmXGridPeer::queryDispatch(const css::util::URL& aURL, const OUString& aTargetFrameName, sal_Int32 nSearchFlags) | ||||||||||
2397 | { | ||||||||||
2398 | Reference< css::frame::XDispatch > xResult; | ||||||||||
2399 | |||||||||||
2400 | // first ask our interceptor chain | ||||||||||
2401 | if (m_xFirstDispatchInterceptor.is() && !m_bInterceptingDispatch) | ||||||||||
2402 | { | ||||||||||
2403 | m_bInterceptingDispatch = true; | ||||||||||
2404 | // safety against recursion : as we are master of the first chain element and slave of the last one we would | ||||||||||
2405 | // have an infinite loop without this if no dispatcher can fulfill the request | ||||||||||
2406 | xResult = m_xFirstDispatchInterceptor->queryDispatch(aURL, aTargetFrameName, nSearchFlags); | ||||||||||
2407 | m_bInterceptingDispatch = false; | ||||||||||
2408 | } | ||||||||||
2409 | |||||||||||
2410 | // then ask ourself : we don't have any dispatches | ||||||||||
2411 | return xResult; | ||||||||||
2412 | } | ||||||||||
2413 | |||||||||||
2414 | |||||||||||
2415 | Sequence< Reference< css::frame::XDispatch > > FmXGridPeer::queryDispatches(const Sequence< css::frame::DispatchDescriptor>& aDescripts) | ||||||||||
2416 | { | ||||||||||
2417 | if (m_xFirstDispatchInterceptor.is()) | ||||||||||
2418 | return m_xFirstDispatchInterceptor->queryDispatches(aDescripts); | ||||||||||
2419 | |||||||||||
2420 | // then ask ourself : we don't have any dispatches | ||||||||||
2421 | return Sequence< Reference< css::frame::XDispatch > >(); | ||||||||||
2422 | } | ||||||||||
2423 | |||||||||||
2424 | |||||||||||
2425 | void FmXGridPeer::registerDispatchProviderInterceptor(const Reference< css::frame::XDispatchProviderInterceptor >& _xInterceptor) | ||||||||||
2426 | { | ||||||||||
2427 | if (!_xInterceptor.is()) | ||||||||||
2428 | return; | ||||||||||
2429 | |||||||||||
2430 | if (m_xFirstDispatchInterceptor.is()) | ||||||||||
2431 | { | ||||||||||
2432 | // there is already an interceptor; the new one will become its master | ||||||||||
2433 | _xInterceptor->setSlaveDispatchProvider(m_xFirstDispatchInterceptor); | ||||||||||
2434 | m_xFirstDispatchInterceptor->setMasterDispatchProvider(m_xFirstDispatchInterceptor); | ||||||||||
2435 | } | ||||||||||
2436 | else | ||||||||||
2437 | { | ||||||||||
2438 | // it is the first interceptor; set ourself as slave | ||||||||||
2439 | _xInterceptor->setSlaveDispatchProvider(static_cast<css::frame::XDispatchProvider*>(this)); | ||||||||||
2440 | } | ||||||||||
2441 | |||||||||||
2442 | // we are the master of the chain's first interceptor | ||||||||||
2443 | m_xFirstDispatchInterceptor = _xInterceptor; | ||||||||||
2444 | m_xFirstDispatchInterceptor->setMasterDispatchProvider(static_cast<css::frame::XDispatchProvider*>(this)); | ||||||||||
2445 | |||||||||||
2446 | // we have a new interceptor and we're alive ? | ||||||||||
2447 | if (!isDesignMode()) | ||||||||||
2448 | // -> check for new dispatchers | ||||||||||
2449 | UpdateDispatches(); | ||||||||||
2450 | } | ||||||||||
2451 | |||||||||||
2452 | |||||||||||
2453 | void FmXGridPeer::releaseDispatchProviderInterceptor(const Reference< css::frame::XDispatchProviderInterceptor >& _xInterceptor) | ||||||||||
2454 | { | ||||||||||
2455 | if (!_xInterceptor.is()) | ||||||||||
2456 | return; | ||||||||||
2457 | |||||||||||
2458 | Reference< css::frame::XDispatchProviderInterceptor > xChainWalk(m_xFirstDispatchInterceptor); | ||||||||||
2459 | |||||||||||
2460 | if (m_xFirstDispatchInterceptor == _xInterceptor) | ||||||||||
2461 | { // our chain will have a new first element | ||||||||||
2462 | Reference< css::frame::XDispatchProviderInterceptor > xSlave(m_xFirstDispatchInterceptor->getSlaveDispatchProvider(), UNO_QUERY); | ||||||||||
2463 | m_xFirstDispatchInterceptor = xSlave; | ||||||||||
2464 | } | ||||||||||
2465 | // do this before removing the interceptor from the chain as we won't know it's slave afterwards) | ||||||||||
2466 | |||||||||||
2467 | while (xChainWalk.is()) | ||||||||||
2468 | { | ||||||||||
2469 | // walk along the chain of interceptors and look for the interceptor that has to be removed | ||||||||||
2470 | Reference< css::frame::XDispatchProviderInterceptor > xSlave(xChainWalk->getSlaveDispatchProvider(), UNO_QUERY); | ||||||||||
2471 | |||||||||||
2472 | if (xChainWalk == _xInterceptor) | ||||||||||
2473 | { | ||||||||||
2474 | // old master may be an interceptor too | ||||||||||
2475 | Reference< css::frame::XDispatchProviderInterceptor > xMaster(xChainWalk->getMasterDispatchProvider(), UNO_QUERY); | ||||||||||
2476 | |||||||||||
2477 | // unchain the interceptor that has to be removed | ||||||||||
2478 | xChainWalk->setSlaveDispatchProvider(Reference< css::frame::XDispatchProvider > ()); | ||||||||||
2479 | xChainWalk->setMasterDispatchProvider(Reference< css::frame::XDispatchProvider > ()); | ||||||||||
2480 | |||||||||||
2481 | // reconnect the chain | ||||||||||
2482 | if (xMaster.is()) | ||||||||||
2483 | { | ||||||||||
2484 | if (xSlave.is()) | ||||||||||
2485 | xMaster->setSlaveDispatchProvider(Reference< css::frame::XDispatchProvider >::query(xSlave)); | ||||||||||
2486 | else | ||||||||||
2487 | // it's the first interceptor of the chain, set ourself as slave | ||||||||||
2488 | xMaster->setSlaveDispatchProvider(static_cast<css::frame::XDispatchProvider*>(this)); | ||||||||||
2489 | } | ||||||||||
2490 | else | ||||||||||
2491 | { | ||||||||||
2492 | // the chain's first element was removed, set ourself as new master of the second one | ||||||||||
2493 | if (xSlave.is()) | ||||||||||
2494 | xSlave->setMasterDispatchProvider(static_cast<css::frame::XDispatchProvider*>(this)); | ||||||||||
2495 | } | ||||||||||
2496 | } | ||||||||||
2497 | |||||||||||
2498 | xChainWalk = xSlave; | ||||||||||
2499 | } | ||||||||||
2500 | // our interceptor chain has changed and we're alive ? | ||||||||||
2501 | if (!isDesignMode()) | ||||||||||
2502 | // -> check the dispatchers | ||||||||||
2503 | UpdateDispatches(); | ||||||||||
2504 | } | ||||||||||
2505 | |||||||||||
2506 | |||||||||||
2507 | void FmXGridPeer::statusChanged(const css::frame::FeatureStateEvent& Event) | ||||||||||
2508 | { | ||||||||||
2509 | DBG_ASSERT(m_pStateCache, "FmXGridPeer::statusChanged : invalid call !")do { if (true && (!(m_pStateCache))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/svx/source/fmcomp/fmgridif.cxx" ":" "2509" ": "), "%s", "FmXGridPeer::statusChanged : invalid call !" ); } } while (false); | ||||||||||
2510 | DBG_ASSERT(m_pDispatchers, "FmXGridPeer::statusChanged : invalid call !")do { if (true && (!(m_pDispatchers))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/svx/source/fmcomp/fmgridif.cxx" ":" "2510" ": "), "%s", "FmXGridPeer::statusChanged : invalid call !" ); } } while (false); | ||||||||||
2511 | |||||||||||
2512 | Sequence< css::util::URL>& aUrls = getSupportedURLs(); | ||||||||||
2513 | |||||||||||
2514 | const std::vector<DbGridControlNavigationBarState>& aSlots = getSupportedGridSlots(); | ||||||||||
2515 | |||||||||||
2516 | auto pUrl = std::find_if(aUrls.begin(), aUrls.end(), | ||||||||||
2517 | [&Event](const css::util::URL& rUrl) { return rUrl.Main == Event.FeatureURL.Main; }); | ||||||||||
2518 | if (pUrl != aUrls.end()) | ||||||||||
2519 | { | ||||||||||
2520 | auto i = static_cast<sal_uInt32>(std::distance(aUrls.begin(), pUrl)); | ||||||||||
2521 | DBG_ASSERT(m_pDispatchers[i] == Event.Source, "FmXGridPeer::statusChanged : the event source is a little bit suspect !")do { if (true && (!(m_pDispatchers[i] == Event.Source ))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools" ), ("/home/maarten/src/libreoffice/core/svx/source/fmcomp/fmgridif.cxx" ":" "2521" ": "), "%s", "FmXGridPeer::statusChanged : the event source is a little bit suspect !" ); } } while (false); | ||||||||||
2522 | m_pStateCache[i] = Event.IsEnabled; | ||||||||||
2523 | VclPtr< FmGridControl > pGrid = GetAs< FmGridControl >(); | ||||||||||
2524 | if (aSlots[i] != DbGridControlNavigationBarState::Undo) | ||||||||||
2525 | pGrid->GetNavigationBar().InvalidateState(aSlots[i]); | ||||||||||
2526 | } | ||||||||||
2527 | DBG_ASSERT(pUrl != aUrls.end(), "FmXGridPeer::statusChanged : got a call for an unknown url !")do { if (true && (!(pUrl != aUrls.end()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/svx/source/fmcomp/fmgridif.cxx" ":" "2527" ": "), "%s", "FmXGridPeer::statusChanged : got a call for an unknown url !" ); } } while (false); | ||||||||||
2528 | } | ||||||||||
2529 | |||||||||||
2530 | |||||||||||
2531 | sal_Bool FmXGridPeer::approveReset(const EventObject& /*rEvent*/) | ||||||||||
2532 | { | ||||||||||
2533 | return true; | ||||||||||
2534 | } | ||||||||||
2535 | |||||||||||
2536 | |||||||||||
2537 | sal_Bool SAL_CALL FmXGridPeer::select( const Any& _rSelection ) | ||||||||||
2538 | { | ||||||||||
2539 | Sequence< Any > aBookmarks; | ||||||||||
2540 | if ( !( _rSelection >>= aBookmarks ) ) | ||||||||||
2541 | throw IllegalArgumentException(); | ||||||||||
2542 | |||||||||||
2543 | return GetAs< FmGridControl >()->selectBookmarks(aBookmarks); | ||||||||||
2544 | |||||||||||
2545 | // TODO: | ||||||||||
2546 | // speaking strictly, we would have to adjust our model, as our ColumnSelection may have changed. | ||||||||||
2547 | // Our model is a XSelectionSupplier, too, it handles the selection of single columns. | ||||||||||
2548 | // This is somewhat strange, as selection should be a view (not a model) aspect. | ||||||||||
2549 | // So for a clean solution, we should handle column selection ourself, and the model shouldn't | ||||||||||
2550 | // deal with selection at all. | ||||||||||
2551 | } | ||||||||||
2552 | |||||||||||
2553 | |||||||||||
2554 | Any SAL_CALL FmXGridPeer::getSelection( ) | ||||||||||
2555 | { | ||||||||||
2556 | VclPtr< FmGridControl > pVclControl = GetAs< FmGridControl >(); | ||||||||||
2557 | Sequence< Any > aSelectionBookmarks = pVclControl->getSelectionBookmarks(); | ||||||||||
2558 | return makeAny(aSelectionBookmarks); | ||||||||||
2559 | } | ||||||||||
2560 | |||||||||||
2561 | |||||||||||
2562 | void SAL_CALL FmXGridPeer::addSelectionChangeListener( const Reference< XSelectionChangeListener >& _rxListener ) | ||||||||||
2563 | { | ||||||||||
2564 | m_aSelectionListeners.addInterface( _rxListener ); | ||||||||||
2565 | } | ||||||||||
2566 | |||||||||||
2567 | |||||||||||
2568 | void SAL_CALL FmXGridPeer::removeSelectionChangeListener( const Reference< XSelectionChangeListener >& _rxListener ) | ||||||||||
2569 | { | ||||||||||
2570 | m_aSelectionListeners.removeInterface( _rxListener ); | ||||||||||
2571 | } | ||||||||||
2572 | |||||||||||
2573 | |||||||||||
2574 | void FmXGridPeer::resetted(const EventObject& rEvent) | ||||||||||
2575 | { | ||||||||||
2576 | if (m_xColumns == rEvent.Source) | ||||||||||
2577 | { // my model was reset -> refresh the grid content | ||||||||||
2578 | SolarMutexGuard aGuard; | ||||||||||
2579 | VclPtr< FmGridControl > pGrid = GetAs< FmGridControl >(); | ||||||||||
2580 | if (!pGrid) | ||||||||||
2581 | return; | ||||||||||
2582 | pGrid->resetCurrentRow(); | ||||||||||
2583 | } | ||||||||||
2584 | // if the cursor fired a reset event we seem to be on the insert row | ||||||||||
2585 | else if (m_xCursor == rEvent.Source) | ||||||||||
2586 | { | ||||||||||
2587 | SolarMutexGuard aGuard; | ||||||||||
2588 | VclPtr< FmGridControl > pGrid = GetAs< FmGridControl >(); | ||||||||||
2589 | if (pGrid && pGrid->IsOpen()) | ||||||||||
2590 | pGrid->positioned(); | ||||||||||
2591 | } | ||||||||||
2592 | } | ||||||||||
2593 | |||||||||||
2594 | |||||||||||
2595 | const std::vector<DbGridControlNavigationBarState>& FmXGridPeer::getSupportedGridSlots() | ||||||||||
2596 | { | ||||||||||
2597 | static const std::vector<DbGridControlNavigationBarState> aSupported { | ||||||||||
2598 | DbGridControlNavigationBarState::First, | ||||||||||
2599 | DbGridControlNavigationBarState::Prev, | ||||||||||
2600 | DbGridControlNavigationBarState::Next, | ||||||||||
2601 | DbGridControlNavigationBarState::Last, | ||||||||||
2602 | DbGridControlNavigationBarState::New, | ||||||||||
2603 | DbGridControlNavigationBarState::Undo | ||||||||||
2604 | }; | ||||||||||
2605 | return aSupported; | ||||||||||
2606 | } | ||||||||||
2607 | |||||||||||
2608 | |||||||||||
2609 | Sequence< css::util::URL>& FmXGridPeer::getSupportedURLs() | ||||||||||
2610 | { | ||||||||||
2611 | static Sequence< css::util::URL> aSupported = [&]() | ||||||||||
2612 | { | ||||||||||
2613 | static const char* sSupported[] = { | ||||||||||
2614 | FMURL_RECORD_MOVEFIRST".uno:FormController/moveToFirst", | ||||||||||
2615 | FMURL_RECORD_MOVEPREV".uno:FormController/moveToPrev", | ||||||||||
2616 | FMURL_RECORD_MOVENEXT".uno:FormController/moveToNext", | ||||||||||
2617 | FMURL_RECORD_MOVELAST".uno:FormController/moveToLast", | ||||||||||
2618 | FMURL_RECORD_MOVETONEW".uno:FormController/moveToNew", | ||||||||||
2619 | FMURL_RECORD_UNDO".uno:FormController/undoRecord" | ||||||||||
2620 | }; | ||||||||||
2621 | Sequence< css::util::URL> tmp(SAL_N_ELEMENTS(sSupported)(sizeof(sal_n_array_size(sSupported)))); | ||||||||||
2622 | css::util::URL* pSupported = tmp.getArray(); | ||||||||||
2623 | |||||||||||
2624 | for ( sal_Int32 i = 0; i < tmp.getLength(); ++i, ++pSupported) | ||||||||||
2625 | pSupported->Complete = OUString::createFromAscii(sSupported[i]); | ||||||||||
2626 | |||||||||||
2627 | // let a css::util::URL-transformer normalize the URLs | ||||||||||
2628 | Reference< css::util::XURLTransformer > xTransformer( | ||||||||||
2629 | util::URLTransformer::create(::comphelper::getProcessComponentContext()) ); | ||||||||||
2630 | for (css::util::URL & rURL : tmp) | ||||||||||
2631 | xTransformer->parseStrict(rURL); | ||||||||||
2632 | return tmp; | ||||||||||
2633 | }(); | ||||||||||
2634 | |||||||||||
2635 | return aSupported; | ||||||||||
2636 | } | ||||||||||
2637 | |||||||||||
2638 | |||||||||||
2639 | void FmXGridPeer::UpdateDispatches() | ||||||||||
2640 | { | ||||||||||
2641 | if (!m_pStateCache) | ||||||||||
2642 | { // we don't have any dispatchers yet -> do the initial connect | ||||||||||
2643 | ConnectToDispatcher(); | ||||||||||
2644 | return; | ||||||||||
2645 | } | ||||||||||
2646 | |||||||||||
2647 | sal_uInt16 nDispatchersGot = 0; | ||||||||||
2648 | const Sequence< css::util::URL>& aSupportedURLs = getSupportedURLs(); | ||||||||||
2649 | const css::util::URL* pSupportedURLs = aSupportedURLs.getConstArray(); | ||||||||||
2650 | Reference< css::frame::XDispatch > xNewDispatch; | ||||||||||
2651 | for (sal_Int32 i=0; i<aSupportedURLs.getLength(); ++i, ++pSupportedURLs) | ||||||||||
2652 | { | ||||||||||
2653 | xNewDispatch = queryDispatch(*pSupportedURLs, OUString(), 0); | ||||||||||
2654 | if (xNewDispatch != m_pDispatchers[i]) | ||||||||||
2655 | { | ||||||||||
2656 | if (m_pDispatchers[i].is()) | ||||||||||
2657 | m_pDispatchers[i]->removeStatusListener(static_cast<css::frame::XStatusListener*>(this), *pSupportedURLs); | ||||||||||
2658 | m_pDispatchers[i] = xNewDispatch; | ||||||||||
2659 | if (m_pDispatchers[i].is()) | ||||||||||
2660 | m_pDispatchers[i]->addStatusListener(static_cast<css::frame::XStatusListener*>(this), *pSupportedURLs); | ||||||||||
2661 | } | ||||||||||
2662 | if (m_pDispatchers[i].is()) | ||||||||||
2663 | ++nDispatchersGot; | ||||||||||
2664 | } | ||||||||||
2665 | |||||||||||
2666 | if (!nDispatchersGot) | ||||||||||
2667 | { | ||||||||||
2668 | m_pStateCache.reset(); | ||||||||||
2669 | m_pDispatchers.reset(); | ||||||||||
2670 | } | ||||||||||
2671 | } | ||||||||||
2672 | |||||||||||
2673 | |||||||||||
2674 | void FmXGridPeer::ConnectToDispatcher() | ||||||||||
2675 | { | ||||||||||
2676 | DBG_ASSERT((m_pStateCache != nullptr) == (m_pDispatchers != nullptr), "FmXGridPeer::ConnectToDispatcher : inconsistent !")do { if (true && (!((m_pStateCache != nullptr) == (m_pDispatchers != nullptr)))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/svx/source/fmcomp/fmgridif.cxx" ":" "2676" ": "), "%s", "FmXGridPeer::ConnectToDispatcher : inconsistent !" ); } } while (false); | ||||||||||
2677 | if (m_pStateCache) | ||||||||||
2678 | { // already connected -> just do an update | ||||||||||
2679 | UpdateDispatches(); | ||||||||||
2680 | return; | ||||||||||
2681 | } | ||||||||||
2682 | |||||||||||
2683 | const Sequence< css::util::URL>& aSupportedURLs = getSupportedURLs(); | ||||||||||
2684 | |||||||||||
2685 | // _before_ adding the status listeners (as the add should result in a statusChanged-call) ! | ||||||||||
2686 | m_pStateCache.reset(new bool[aSupportedURLs.getLength()]); | ||||||||||
2687 | m_pDispatchers.reset(new Reference< css::frame::XDispatch > [aSupportedURLs.getLength()]); | ||||||||||
2688 | |||||||||||
2689 | sal_uInt16 nDispatchersGot = 0; | ||||||||||
2690 | const css::util::URL* pSupportedURLs = aSupportedURLs.getConstArray(); | ||||||||||
2691 | for (sal_Int32 i=0; i<aSupportedURLs.getLength(); ++i, ++pSupportedURLs) | ||||||||||
2692 | { | ||||||||||
2693 | m_pStateCache[i] = false; | ||||||||||
2694 | m_pDispatchers[i] = queryDispatch(*pSupportedURLs, OUString(), 0); | ||||||||||
2695 | if (m_pDispatchers[i].is()) | ||||||||||
2696 | { | ||||||||||
2697 | m_pDispatchers[i]->addStatusListener(static_cast<css::frame::XStatusListener*>(this), *pSupportedURLs); | ||||||||||
2698 | ++nDispatchersGot; | ||||||||||
2699 | } | ||||||||||
2700 | } | ||||||||||
2701 | |||||||||||
2702 | if (!nDispatchersGot) | ||||||||||
2703 | { | ||||||||||
2704 | m_pStateCache.reset(); | ||||||||||
2705 | m_pDispatchers.reset(); | ||||||||||
2706 | } | ||||||||||
2707 | } | ||||||||||
2708 | |||||||||||
2709 | |||||||||||
2710 | void FmXGridPeer::DisConnectFromDispatcher() | ||||||||||
2711 | { | ||||||||||
2712 | if (!m_pStateCache || !m_pDispatchers) | ||||||||||
2713 | return; | ||||||||||
2714 | // we're not connected | ||||||||||
2715 | |||||||||||
2716 | const Sequence< css::util::URL>& aSupportedURLs = getSupportedURLs(); | ||||||||||
2717 | const css::util::URL* pSupportedURLs = aSupportedURLs.getConstArray(); | ||||||||||
2718 | for (sal_Int32 i=0; i<aSupportedURLs.getLength(); ++i, ++pSupportedURLs) | ||||||||||
2719 | { | ||||||||||
2720 | if (m_pDispatchers[i].is()) | ||||||||||
2721 | m_pDispatchers[i]->removeStatusListener(static_cast<css::frame::XStatusListener*>(this), *pSupportedURLs); | ||||||||||
2722 | } | ||||||||||
2723 | |||||||||||
2724 | m_pStateCache.reset(); | ||||||||||
2725 | m_pDispatchers.reset(); | ||||||||||
2726 | } | ||||||||||
2727 | |||||||||||
2728 | |||||||||||
2729 | IMPL_LINK(FmXGridPeer, OnQueryGridSlotState, DbGridControlNavigationBarState, nSlot, int)int FmXGridPeer::LinkStubOnQueryGridSlotState(void * instance , DbGridControlNavigationBarState data) { return static_cast< FmXGridPeer *>(instance)->OnQueryGridSlotState(data); } int FmXGridPeer::OnQueryGridSlotState(DbGridControlNavigationBarState nSlot) | ||||||||||
2730 | { | ||||||||||
2731 | if (!m_pStateCache) | ||||||||||
2732 | return -1; // unspecified | ||||||||||
2733 | |||||||||||
2734 | // search the given slot with our supported sequence | ||||||||||
2735 | const std::vector<DbGridControlNavigationBarState>& aSupported = getSupportedGridSlots(); | ||||||||||
2736 | for (size_t i=0; i<aSupported.size(); ++i) | ||||||||||
2737 | { | ||||||||||
2738 | if (aSupported[i] == nSlot) | ||||||||||
2739 | { | ||||||||||
2740 | if (!m_pDispatchers[i].is()) | ||||||||||
2741 | return -1; // nothing known about this slot | ||||||||||
2742 | else | ||||||||||
2743 | return m_pStateCache[i] ? 1 : 0; | ||||||||||
2744 | } | ||||||||||
2745 | } | ||||||||||
2746 | |||||||||||
2747 | return -1; | ||||||||||
2748 | } | ||||||||||
2749 | |||||||||||
2750 | |||||||||||
2751 | IMPL_LINK(FmXGridPeer, OnExecuteGridSlot, DbGridControlNavigationBarState, nSlot, bool)bool FmXGridPeer::LinkStubOnExecuteGridSlot(void * instance, DbGridControlNavigationBarState data) { return static_cast<FmXGridPeer *>(instance)-> OnExecuteGridSlot(data); } bool FmXGridPeer::OnExecuteGridSlot (DbGridControlNavigationBarState nSlot) | ||||||||||
2752 | { | ||||||||||
2753 | if (!m_pDispatchers) | ||||||||||
2754 | return false; // not handled | ||||||||||
2755 | |||||||||||
2756 | Sequence< css::util::URL>& aUrls = getSupportedURLs(); | ||||||||||
2757 | const css::util::URL* pUrls = aUrls.getConstArray(); | ||||||||||
2758 | |||||||||||
2759 | const std::vector<DbGridControlNavigationBarState>& aSlots = getSupportedGridSlots(); | ||||||||||
2760 | |||||||||||
2761 | DBG_ASSERT(static_cast<sal_Int32>(aSlots.size()) == aUrls.getLength(), "FmXGridPeer::OnExecuteGridSlot : inconsistent data returned by getSupportedURLs/getSupportedGridSlots!")do { if (true && (!(static_cast<sal_Int32>(aSlots .size()) == aUrls.getLength()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/svx/source/fmcomp/fmgridif.cxx" ":" "2761" ": "), "%s", "FmXGridPeer::OnExecuteGridSlot : inconsistent data returned by getSupportedURLs/getSupportedGridSlots!" ); } } while (false); | ||||||||||
2762 | |||||||||||
2763 | for (size_t i=0; i<aSlots.size(); ++i, ++pUrls) | ||||||||||
2764 | { | ||||||||||
2765 | if (aSlots[i] == nSlot) | ||||||||||
2766 | { | ||||||||||
2767 | if (m_pDispatchers[i].is()) | ||||||||||
2768 | { | ||||||||||
2769 | // commit any changes done so far, if it's not the undoRecord URL | ||||||||||
2770 | if ( pUrls->Complete == FMURL_RECORD_UNDO".uno:FormController/undoRecord" || commit() ) | ||||||||||
2771 | m_pDispatchers[i]->dispatch(*pUrls, Sequence< PropertyValue>()); | ||||||||||
2772 | |||||||||||
2773 | return true; // handled | ||||||||||
2774 | } | ||||||||||
2775 | } | ||||||||||
2776 | } | ||||||||||
2777 | |||||||||||
2778 | return false; // not handled | ||||||||||
2779 | } | ||||||||||
2780 | |||||||||||
2781 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | #ifndef INCLUDED_TOOLKIT_AWT_VCLXWINDOW_HXX |
21 | #define INCLUDED_TOOLKIT_AWT_VCLXWINDOW_HXX |
22 | |
23 | #include <toolkit/dllapi.h> |
24 | #include <toolkit/awt/vclxdevice.hxx> |
25 | #include <vcl/window.hxx> |
26 | |
27 | #include <com/sun/star/awt/XWindow2.hpp> |
28 | #include <com/sun/star/awt/XVclWindowPeer.hpp> |
29 | #include <com/sun/star/awt/XLayoutConstrains.hpp> |
30 | #include <com/sun/star/awt/XView.hpp> |
31 | #include <com/sun/star/beans/XPropertySetInfo.hpp> |
32 | #include <com/sun/star/accessibility/XAccessible.hpp> |
33 | #include <com/sun/star/awt/XDockableWindow.hpp> |
34 | #include <com/sun/star/awt/XStyleSettingsSupplier.hpp> |
35 | |
36 | #include <comphelper/servicehelper.hxx> |
37 | #include <cppuhelper/implbase.hxx> |
38 | |
39 | #include <tools/gen.hxx> |
40 | #include <tools/link.hxx> |
41 | |
42 | #include <memory> |
43 | #include <vector> |
44 | #include <functional> |
45 | |
46 | namespace comphelper { class OInterfaceContainerHelper2; } |
47 | namespace com::sun::star::accessibility { class XAccessibleContext; } |
48 | |
49 | class VclWindowEvent; |
50 | |
51 | namespace toolkit |
52 | { |
53 | class IAccessibleFactory; |
54 | } |
55 | |
56 | |
57 | class UnoPropertyArrayHelper; |
58 | class VCLXWindowImpl; |
59 | typedef cppu::ImplInheritanceHelper< VCLXDevice, |
60 | css::awt::XWindow2, |
61 | css::awt::XVclWindowPeer, |
62 | css::awt::XLayoutConstrains, |
63 | css::awt::XView, |
64 | css::awt::XDockableWindow, |
65 | css::accessibility::XAccessible, |
66 | css::lang::XEventListener, |
67 | css::beans::XPropertySetInfo, |
68 | css::awt::XStyleSettingsSupplier |
69 | > VCLXWindow_Base; |
70 | |
71 | class TOOLKIT_DLLPUBLIC__attribute__ ((visibility("default"))) VCLXWindow : public VCLXWindow_Base |
72 | { |
73 | private: |
74 | std::unique_ptr<VCLXWindowImpl> mpImpl; |
75 | |
76 | UnoPropertyArrayHelper *GetPropHelper(); |
77 | |
78 | protected: |
79 | Size ImplCalcWindowSize( const Size& rOutSz ) const; |
80 | DECL_LINK(WindowEventListener, VclWindowEvent&, void )static void LinkStubWindowEventListener(void *, VclWindowEvent &); void WindowEventListener(VclWindowEvent&); |
81 | |
82 | virtual void ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ); |
83 | virtual css::uno::Reference< css::accessibility::XAccessibleContext > |
84 | CreateAccessibleContext(); |
85 | |
86 | void SetSynthesizingVCLEvent( bool b ); |
87 | bool IsSynthesizingVCLEvent() const; |
88 | |
89 | void SetSystemParent_Impl( const css::uno::Any& rHandle ); |
90 | |
91 | ::toolkit::IAccessibleFactory& getAccessibleFactory(); |
92 | |
93 | // helper ... |
94 | static void PushPropertyIds( std::vector< sal_uInt16 > &aIds, int nFirstId, ...); |
95 | // for use in controls/ |
96 | static void ImplGetPropertyIds( std::vector< sal_uInt16 > &aIds, |
97 | bool bWithDefaults = false ); |
98 | virtual void GetPropertyIds( std::vector< sal_uInt16 > &aIds ); |
99 | |
100 | ::comphelper::OInterfaceContainerHelper2& GetContainerListeners(); |
101 | ::comphelper::OInterfaceContainerHelper2& GetTopWindowListeners(); |
102 | |
103 | public: |
104 | typedef ::std::function<void ()> Callback; |
105 | |
106 | protected: |
107 | /** executes the given callback asynchronously |
108 | |
109 | At the moment the callback is called, the Solar Mutex is not locked. In particular, this implies that |
110 | you cannot rely on |this| not being disposed. However, you *can* rely on |this| being still alive (i.e. |
111 | having a ref count > 0). |
112 | |
113 | As a consequence, this can be used for doing listener notifications, using event multiplexers. Those multiplexers |
114 | care for the disposed state themself, and are alive as long as |this| is alive. |
115 | */ |
116 | void ImplExecuteAsyncWithoutSolarLock( |
117 | const Callback& i_callback |
118 | ); |
119 | |
120 | public: |
121 | VCLXWindow( bool bWithDefaultProps = false ); |
122 | virtual ~VCLXWindow() override; |
123 | |
124 | virtual void SetWindow( const VclPtr< vcl::Window > &pWindow ); |
125 | template< class derived_type > VclPtr< derived_type > GetAs() const { |
126 | return VclPtr< derived_type >( static_cast< derived_type * >( GetOutputDevice().get() ) ); } |
127 | template< class derived_type > VclPtr< derived_type > GetAsDynamic() const { |
128 | return VclPtr< derived_type >( dynamic_cast< derived_type * >( GetOutputDevice().get() ) ); } |
129 | VclPtr<vcl::Window> GetWindow() const { return GetAs<vcl::Window>(); } |
130 | |
131 | void suspendVclEventListening( ); |
132 | void resumeVclEventListening( ); |
133 | |
134 | void notifyWindowRemoved( vcl::Window const & _rWindow ); |
135 | |
136 | // css::lang::XUnoTunnel |
137 | UNO3_GETIMPLEMENTATION_DECL(VCLXWindow)static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId () throw(); virtual sal_Int64 getSomething( const css::uno::Sequence < sal_Int8 >& aIdentifier ) override; |
138 | |
139 | // css::lang::XEventListener |
140 | virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override; |
141 | |
142 | // css::lang::XComponent |
143 | void SAL_CALL dispose( ) override; |
144 | void SAL_CALL addEventListener( const css::uno::Reference< css::lang::XEventListener >& rxListener ) override; |
145 | void SAL_CALL removeEventListener( const css::uno::Reference< css::lang::XEventListener >& rxListener ) override; |
146 | |
147 | // css::awt::XWindow |
148 | void SAL_CALL setPosSize( sal_Int32 X, sal_Int32 Y, sal_Int32 Width, sal_Int32 Height, sal_Int16 Flags ) override; |
149 | css::awt::Rectangle SAL_CALL getPosSize( ) override; |
150 | void SAL_CALL setVisible( sal_Bool Visible ) override; |
151 | void SAL_CALL setEnable( sal_Bool Enable ) override; |
152 | void SAL_CALL setFocus( ) override; |
153 | void SAL_CALL addWindowListener( const css::uno::Reference< css::awt::XWindowListener >& rrxListener ) override; |
154 | void SAL_CALL removeWindowListener( const css::uno::Reference< css::awt::XWindowListener >& rrxListener ) override; |
155 | void SAL_CALL addFocusListener( const css::uno::Reference< css::awt::XFocusListener >& rrxListener ) override; |
156 | void SAL_CALL removeFocusListener( const css::uno::Reference< css::awt::XFocusListener >& rrxListener ) override; |
157 | void SAL_CALL addKeyListener( const css::uno::Reference< css::awt::XKeyListener >& rrxListener ) override; |
158 | void SAL_CALL removeKeyListener( const css::uno::Reference< css::awt::XKeyListener >& rrxListener ) override; |
159 | void SAL_CALL addMouseListener( const css::uno::Reference< css::awt::XMouseListener >& rrxListener ) override; |
160 | void SAL_CALL removeMouseListener( const css::uno::Reference< css::awt::XMouseListener >& rrxListener ) override; |
161 | void SAL_CALL addMouseMotionListener( const css::uno::Reference< css::awt::XMouseMotionListener >& rrxListener ) override; |
162 | void SAL_CALL removeMouseMotionListener( const css::uno::Reference< css::awt::XMouseMotionListener >& rrxListener ) override; |
163 | void SAL_CALL addPaintListener( const css::uno::Reference< css::awt::XPaintListener >& rrxListener ) override; |
164 | void SAL_CALL removePaintListener( const css::uno::Reference< css::awt::XPaintListener >& rrxListener ) override; |
165 | |
166 | // css::awt::XWindowPeer |
167 | css::uno::Reference< css::awt::XToolkit > SAL_CALL getToolkit( ) override; |
168 | void SAL_CALL setPointer( const css::uno::Reference< css::awt::XPointer >& Pointer ) override; |
169 | void SAL_CALL setBackground( sal_Int32 Color ) override; |
170 | void SAL_CALL invalidate( sal_Int16 Flags ) override; |
171 | void SAL_CALL invalidateRect( const css::awt::Rectangle& Rect, sal_Int16 Flags ) override; |
172 | |
173 | // css::awt::XVclWindowPeer |
174 | sal_Bool SAL_CALL isChild( const css::uno::Reference< css::awt::XWindowPeer >& Peer ) override; |
175 | void SAL_CALL setDesignMode( sal_Bool bOn ) override; |
176 | sal_Bool SAL_CALL isDesignMode( ) override; |
177 | void SAL_CALL enableClipSiblings( sal_Bool bClip ) override; |
178 | void SAL_CALL setForeground( sal_Int32 Color ) override; |
179 | void SAL_CALL setControlFont( const css::awt::FontDescriptor& aFont ) override; |
180 | void SAL_CALL getStyles( sal_Int16 nType, css::awt::FontDescriptor& Font, sal_Int32& ForegroundColor, sal_Int32& BackgroundColor ) override; |
181 | void SAL_CALL setProperty( const OUString& PropertyName, const css::uno::Any& Value ) override; |
182 | css::uno::Any SAL_CALL getProperty( const OUString& PropertyName ) override; |
183 | |
184 | // css::awt::XLayoutConstrains |
185 | css::awt::Size SAL_CALL getMinimumSize( ) override; |
186 | css::awt::Size SAL_CALL getPreferredSize( ) override; |
187 | css::awt::Size SAL_CALL calcAdjustedSize( const css::awt::Size& aNewSize ) override; |
188 | |
189 | // css::awt::XView |
190 | sal_Bool SAL_CALL setGraphics( const css::uno::Reference< css::awt::XGraphics >& aDevice ) override; |
191 | css::uno::Reference< css::awt::XGraphics > SAL_CALL getGraphics( ) override; |
192 | css::awt::Size SAL_CALL getSize( ) override; |
193 | void SAL_CALL draw( sal_Int32 nX, sal_Int32 nY ) override; |
194 | void SAL_CALL setZoom( float fZoomX, float fZoomY ) override; |
195 | |
196 | // css::accessibility::XAccessible |
197 | css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext( ) override; |
198 | |
199 | // css::awt::XDockableWindow |
200 | void SAL_CALL addDockableWindowListener( const css::uno::Reference< css::awt::XDockableWindowListener >& xListener ) override; |
201 | void SAL_CALL removeDockableWindowListener( const css::uno::Reference< css::awt::XDockableWindowListener >& xListener ) override; |
202 | void SAL_CALL enableDocking( sal_Bool bEnable ) override; |
203 | sal_Bool SAL_CALL isFloating( ) override; |
204 | void SAL_CALL setFloatingMode( sal_Bool bFloating ) override; |
205 | void SAL_CALL lock( ) override; |
206 | void SAL_CALL unlock( ) override; |
207 | sal_Bool SAL_CALL isLocked( ) override; |
208 | void SAL_CALL startPopupMode( const css::awt::Rectangle& WindowRect ) override; |
209 | sal_Bool SAL_CALL isInPopupMode( ) override; |
210 | |
211 | // css::awt::XWindow2 |
212 | void SAL_CALL setOutputSize( const css::awt::Size& aSize ) override; |
213 | css::awt::Size SAL_CALL getOutputSize( ) override; |
214 | sal_Bool SAL_CALL isVisible( ) override; |
215 | sal_Bool SAL_CALL isActive( ) override; |
216 | sal_Bool SAL_CALL isEnabled( ) override; |
217 | sal_Bool SAL_CALL hasFocus( ) override; |
218 | |
219 | // css::beans::XPropertySetInfo |
220 | css::uno::Sequence< css::beans::Property > SAL_CALL getProperties( ) override; |
221 | css::beans::Property SAL_CALL getPropertyByName( const OUString& aName ) override; |
222 | sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) override; |
223 | |
224 | // XStyleSettingsSupplier |
225 | virtual css::uno::Reference< css::awt::XStyleSettings > SAL_CALL getStyleSettings() override; |
226 | }; |
227 | |
228 | #endif // INCLUDED_TOOLKIT_AWT_VCLXWINDOW_HXX |
229 | |
230 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | #ifndef INCLUDED_VCL_PTR_HXX |
21 | #define INCLUDED_VCL_PTR_HXX |
22 | |
23 | #include <sal/config.h> |
24 | |
25 | #include <rtl/ref.hxx> |
26 | |
27 | #include <utility> |
28 | #include <type_traits> |
29 | |
30 | #ifdef DBG_UTIL |
31 | #ifndef _WIN32 |
32 | #include <vcl/vclmain.hxx> |
33 | #endif |
34 | #endif |
35 | |
36 | class VclReferenceBase; |
37 | |
38 | namespace vcl::detail { |
39 | |
40 | template<typename> |
41 | constexpr bool isIncompleteOrDerivedFromVclReferenceBase(...) { return true; } |
42 | |
43 | template<typename T> constexpr bool isIncompleteOrDerivedFromVclReferenceBase( |
44 | int (*)[sizeof(T)]) |
45 | { return std::is_base_of<VclReferenceBase, T>::value; } |
46 | |
47 | } // namespace vcl::detail |
48 | |
49 | /** |
50 | * A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for references to vcl::Window subclasses. |
51 | * |
52 | * For more details on the design please see vcl/README.lifecycle |
53 | * |
54 | * @param reference_type must be a subclass of vcl::Window |
55 | */ |
56 | template <class reference_type> |
57 | class VclPtr |
58 | { |
59 | static_assert( |
60 | vcl::detail::isIncompleteOrDerivedFromVclReferenceBase<reference_type>( |
61 | nullptr), |
62 | "template argument type must be derived from VclReferenceBase"); |
63 | |
64 | ::rtl::Reference<reference_type> m_rInnerRef; |
65 | |
66 | public: |
67 | /** Constructor... |
68 | */ |
69 | VclPtr() |
70 | : m_rInnerRef() |
71 | {} |
72 | |
73 | /** Constructor... |
74 | */ |
75 | VclPtr (reference_type * pBody) |
76 | : m_rInnerRef(pBody) |
77 | {} |
78 | |
79 | /** Constructor... that doesn't take a ref. |
80 | */ |
81 | VclPtr (reference_type * pBody, __sal_NoAcquire) |
82 | : m_rInnerRef(pBody, SAL_NO_ACQUIRE) |
83 | {} |
84 | |
85 | /** Up-casting conversion constructor: Copies interface reference. |
86 | |
87 | Does not work for up-casts to ambiguous bases. For the special case of |
88 | up-casting to Reference< XInterface >, see the corresponding conversion |
89 | operator. |
90 | |
91 | @param rRef another reference |
92 | */ |
93 | template< class derived_type > |
94 | VclPtr( |
95 | const VclPtr< derived_type > & rRef, |
96 | typename std::enable_if< |
97 | std::is_base_of<reference_type, derived_type>::value, int>::type |
98 | = 0 ) |
99 | : m_rInnerRef( static_cast<reference_type*>(rRef) ) |
100 | { |
101 | } |
102 | |
103 | #if defined(DBG_UTIL) && !defined(_WIN32) |
104 | virtual ~VclPtr() |
105 | { |
106 | assert(m_rInnerRef.get() == nullptr || vclmain::isAlive())(static_cast <bool> (m_rInnerRef.get() == nullptr || vclmain ::isAlive()) ? void (0) : __assert_fail ("m_rInnerRef.get() == nullptr || vclmain::isAlive()" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 106, __extension__ __PRETTY_FUNCTION__)); |
107 | // We can be one of the intermediate counts, but if we are the last |
108 | // VclPtr keeping this object alive, then something forgot to call dispose(). |
109 | assert((!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1)(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef ->isDisposed() || m_rInnerRef->getRefCount() > 1) && "someone forgot to call dispose()") ? void (0) : __assert_fail ("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\"" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 110, __extension__ __PRETTY_FUNCTION__)) |
110 | && "someone forgot to call dispose()")(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef ->isDisposed() || m_rInnerRef->getRefCount() > 1) && "someone forgot to call dispose()") ? void (0) : __assert_fail ("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\"" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 110, __extension__ __PRETTY_FUNCTION__)); |
111 | } |
112 | VclPtr(VclPtr const &) = default; |
113 | VclPtr(VclPtr &&) = default; |
114 | VclPtr & operator =(VclPtr const &) = default; |
115 | VclPtr & operator =(VclPtr &&) = default; |
116 | #endif |
117 | |
118 | /** |
119 | * A construction helper for VclPtr. Since VclPtr types are created |
120 | * with a reference-count of one - to help fit into the existing |
121 | * code-flow; this helps us to construct them easily. |
122 | * |
123 | * For more details on the design please see vcl/README.lifecycle |
124 | * |
125 | * @tparam reference_type must be a subclass of vcl::Window |
126 | */ |
127 | template<typename... Arg> [[nodiscard]] static VclPtr< reference_type > Create(Arg &&... arg) |
128 | { |
129 | return VclPtr< reference_type >( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ); |
130 | } |
131 | |
132 | /** Probably most common used: handle->someBodyOp(). |
133 | */ |
134 | reference_type * operator->() const |
135 | { |
136 | return m_rInnerRef.get(); |
137 | } |
138 | |
139 | /** Get the body. Can be used instead of operator->(). |
140 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() |
141 | are the same. |
142 | */ |
143 | reference_type * get() const |
144 | { |
145 | return m_rInnerRef.get(); |
146 | } |
147 | |
148 | void set(reference_type *pBody) |
149 | { |
150 | m_rInnerRef.set(pBody); |
151 | } |
152 | |
153 | void reset(reference_type *pBody) |
154 | { |
155 | m_rInnerRef.set(pBody); |
156 | } |
157 | |
158 | /** Up-casting copy assignment operator. |
159 | |
160 | Does not work for up-casts to ambiguous bases. |
161 | |
162 | @param rRef another reference |
163 | */ |
164 | template<typename derived_type> |
165 | typename std::enable_if< |
166 | std::is_base_of<reference_type, derived_type>::value, |
167 | VclPtr &>::type |
168 | operator =(VclPtr<derived_type> const & rRef) |
169 | { |
170 | m_rInnerRef.set(rRef.get()); |
171 | return *this; |
172 | } |
173 | |
174 | VclPtr & operator =(reference_type * pBody) |
175 | { |
176 | m_rInnerRef.set(pBody); |
177 | return *this; |
178 | } |
179 | |
180 | operator reference_type * () const |
181 | { |
182 | return m_rInnerRef.get(); |
183 | } |
184 | |
185 | explicit operator bool () const |
186 | { |
187 | return m_rInnerRef.get() != nullptr; |
188 | } |
189 | |
190 | void clear() |
191 | { |
192 | m_rInnerRef.clear(); |
193 | } |
194 | |
195 | void reset() |
196 | { |
197 | m_rInnerRef.clear(); |
198 | } |
199 | |
200 | void disposeAndClear() |
201 | { |
202 | // hold it alive for the lifetime of this method |
203 | ::rtl::Reference<reference_type> aTmp(m_rInnerRef); |
204 | m_rInnerRef.clear(); // we should use some 'swap' method ideally ;-) |
205 | if (aTmp.get()) { |
206 | aTmp->disposeOnce(); |
207 | } |
208 | } |
209 | |
210 | /** Needed to place VclPtr's into STL collection. |
211 | */ |
212 | bool operator< (const VclPtr<reference_type> & handle) const |
213 | { |
214 | return (m_rInnerRef < handle.m_rInnerRef); |
215 | } |
216 | }; // class VclPtr |
217 | |
218 | template<typename T1, typename T2> |
219 | inline bool operator ==(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
220 | return p1.get() == p2.get(); |
221 | } |
222 | |
223 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T const * p2) |
224 | { |
225 | return p1.get() == p2; |
226 | } |
227 | |
228 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T * p2) { |
229 | return p1.get() == p2; |
230 | } |
231 | |
232 | template<typename T> inline bool operator ==(T const * p1, VclPtr<T> const & p2) |
233 | { |
234 | return p1 == p2.get(); |
235 | } |
236 | |
237 | template<typename T> inline bool operator ==(T * p1, VclPtr<T> const & p2) { |
238 | return p1 == p2.get(); |
239 | } |
240 | |
241 | template<typename T1, typename T2> |
242 | inline bool operator !=(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
243 | return !(p1 == p2); |
244 | } |
245 | |
246 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T const * p2) |
247 | { |
248 | return !(p1 == p2); |
249 | } |
250 | |
251 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T * p2) { |
252 | return !(p1 == p2); |
253 | } |
254 | |
255 | template<typename T> inline bool operator !=(T const * p1, VclPtr<T> const & p2) |
256 | { |
257 | return !(p1 == p2); |
258 | } |
259 | |
260 | template<typename T> inline bool operator !=(T * p1, VclPtr<T> const & p2) { |
261 | return !(p1 == p2); |
262 | } |
263 | |
264 | /** |
265 | * A construction helper for a temporary VclPtr. Since VclPtr types |
266 | * are created with a reference-count of one - to help fit into |
267 | * the existing code-flow; this helps us to construct them easily. |
268 | * see also VclPtr::Create and ScopedVclPtr |
269 | * |
270 | * For more details on the design please see vcl/README.lifecycle |
271 | * |
272 | * @param reference_type must be a subclass of vcl::Window |
273 | */ |
274 | template <class reference_type> |
275 | class SAL_WARN_UNUSED__attribute__((warn_unused)) VclPtrInstance final : public VclPtr<reference_type> |
276 | { |
277 | public: |
278 | template<typename... Arg> VclPtrInstance(Arg &&... arg) |
279 | : VclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ) |
280 | { |
281 | } |
282 | |
283 | /** |
284 | * Override and disallow this, to prevent people accidentally calling it and actually |
285 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
286 | */ |
287 | template<typename... Arg> static VclPtrInstance< reference_type > Create(Arg &&... ) = delete; |
288 | }; |
289 | |
290 | template <class reference_type> |
291 | class ScopedVclPtr : public VclPtr<reference_type> |
292 | { |
293 | public: |
294 | /** Constructor... |
295 | */ |
296 | ScopedVclPtr() |
297 | : VclPtr<reference_type>() |
298 | {} |
299 | |
300 | /** Constructor |
301 | */ |
302 | ScopedVclPtr (reference_type * pBody) |
303 | : VclPtr<reference_type>(pBody) |
304 | {} |
305 | |
306 | /** Copy constructor... |
307 | */ |
308 | ScopedVclPtr (const VclPtr<reference_type> & handle) |
309 | : VclPtr<reference_type>(handle) |
310 | {} |
311 | |
312 | /** |
313 | Assignment that releases the last reference. |
314 | */ |
315 | void disposeAndReset(reference_type *pBody) |
316 | { |
317 | if (pBody != this->get()) { |
318 | VclPtr<reference_type>::disposeAndClear(); |
319 | VclPtr<reference_type>::set(pBody); |
320 | } |
321 | } |
322 | |
323 | /** |
324 | Assignment that releases the last reference. |
325 | */ |
326 | ScopedVclPtr<reference_type>& operator = (reference_type * pBody) |
327 | { |
328 | disposeAndReset(pBody); |
329 | return *this; |
330 | } |
331 | |
332 | /** Up-casting conversion constructor: Copies interface reference. |
333 | |
334 | Does not work for up-casts to ambiguous bases. For the special case of |
335 | up-casting to Reference< XInterface >, see the corresponding conversion |
336 | operator. |
337 | |
338 | @param rRef another reference |
339 | */ |
340 | template< class derived_type > |
341 | ScopedVclPtr( |
342 | const VclPtr< derived_type > & rRef, |
343 | typename std::enable_if< |
344 | std::is_base_of<reference_type, derived_type>::value, int>::type |
345 | = 0 ) |
346 | : VclPtr<reference_type>( rRef ) |
347 | { |
348 | } |
349 | |
350 | /** Up-casting assignment operator. |
351 | |
352 | Does not work for up-casts to ambiguous bases. |
353 | |
354 | @param rRef another VclPtr |
355 | */ |
356 | template<typename derived_type> |
357 | typename std::enable_if< |
358 | std::is_base_of<reference_type, derived_type>::value, |
359 | ScopedVclPtr &>::type |
360 | operator =(VclPtr<derived_type> const & rRef) |
361 | { |
362 | disposeAndReset(rRef.get()); |
363 | return *this; |
364 | } |
365 | |
366 | /** |
367 | * Override and disallow this, to prevent people accidentally calling it and actually |
368 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
369 | */ |
370 | template<typename... Arg> static ScopedVclPtr< reference_type > Create(Arg &&... ) = delete; |
371 | |
372 | ~ScopedVclPtr() |
373 | { |
374 | VclPtr<reference_type>::disposeAndClear(); |
375 | assert(VclPtr<reference_type>::get() == nullptr)(static_cast <bool> (VclPtr<reference_type>::get( ) == nullptr) ? void (0) : __assert_fail ("VclPtr<reference_type>::get() == nullptr" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 375, __extension__ __PRETTY_FUNCTION__)); // make sure there are no lingering references |
376 | } |
377 | |
378 | private: |
379 | // Most likely we don't want this default copy-constructor. |
380 | ScopedVclPtr (const ScopedVclPtr<reference_type> &) = delete; |
381 | // And certainly we don't want a default assignment operator. |
382 | ScopedVclPtr<reference_type>& operator = (const ScopedVclPtr<reference_type> &) = delete; |
383 | // And disallow reset as that doesn't call disposeAndClear on the original reference |
384 | void reset() = delete; |
385 | void reset(reference_type *pBody) = delete; |
386 | |
387 | protected: |
388 | ScopedVclPtr (reference_type * pBody, __sal_NoAcquire) |
389 | : VclPtr<reference_type>(pBody, SAL_NO_ACQUIRE) |
390 | {} |
391 | }; |
392 | |
393 | /** |
394 | * A construction helper for ScopedVclPtr. Since VclPtr types are created |
395 | * with a reference-count of one - to help fit into the existing |
396 | * code-flow; this helps us to construct them easily. |
397 | * |
398 | * For more details on the design please see vcl/README.lifecycle |
399 | * |
400 | * @param reference_type must be a subclass of vcl::Window |
401 | */ |
402 | #if defined _MSC_VER |
403 | #pragma warning(push) |
404 | #pragma warning(disable: 4521) // " multiple copy constructors specified" |
405 | #endif |
406 | template <class reference_type> |
407 | class SAL_WARN_UNUSED__attribute__((warn_unused)) ScopedVclPtrInstance final : public ScopedVclPtr<reference_type> |
408 | { |
409 | public: |
410 | template<typename... Arg> ScopedVclPtrInstance(Arg &&... arg) |
411 | : ScopedVclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ) |
412 | { |
413 | } |
414 | |
415 | /** |
416 | * Override and disallow this, to prevent people accidentally calling it and actually |
417 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
418 | */ |
419 | template<typename... Arg> static ScopedVclPtrInstance< reference_type > Create(Arg &&...) = delete; |
420 | |
421 | private: |
422 | // Prevent the above perfect forwarding ctor from hijacking (accidental) |
423 | // attempts at ScopedVclPtrInstance copy construction (where the hijacking |
424 | // would typically lead to somewhat obscure error messages); both non-const |
425 | // and const variants are needed here, as the ScopedVclPtr base class has a |
426 | // const--variant copy ctor, so the implicitly declared copy ctor for |
427 | // ScopedVclPtrInstance would also be the const variant, so non-const copy |
428 | // construction attempts would be hijacked by the perfect forwarding ctor; |
429 | // but if we only declared a non-const variant here, the const variant would |
430 | // no longer be implicitly declared (as there would already be an explicitly |
431 | // declared copy ctor), so const copy construction attempts would then be |
432 | // hijacked by the perfect forwarding ctor: |
433 | ScopedVclPtrInstance(ScopedVclPtrInstance &) = delete; |
434 | ScopedVclPtrInstance(ScopedVclPtrInstance const &) = delete; |
435 | }; |
436 | #if defined _MSC_VER |
437 | #pragma warning(pop) |
438 | #endif |
439 | |
440 | #endif // INCLUDED_VCL_PTR_HXX |
441 | |
442 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | #ifndef INCLUDED_RTL_REF_HXX | ||||||||||||||||||||
21 | #define INCLUDED_RTL_REF_HXX | ||||||||||||||||||||
22 | |||||||||||||||||||||
23 | #include "sal/config.h" | ||||||||||||||||||||
24 | |||||||||||||||||||||
25 | #include <cassert> | ||||||||||||||||||||
26 | #include <cstddef> | ||||||||||||||||||||
27 | #include <functional> | ||||||||||||||||||||
28 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||||||||||||||
29 | #include <type_traits> | ||||||||||||||||||||
30 | #endif | ||||||||||||||||||||
31 | |||||||||||||||||||||
32 | #include "sal/types.h" | ||||||||||||||||||||
33 | |||||||||||||||||||||
34 | namespace rtl | ||||||||||||||||||||
35 | { | ||||||||||||||||||||
36 | |||||||||||||||||||||
37 | /** Template reference class for reference type. | ||||||||||||||||||||
38 | */ | ||||||||||||||||||||
39 | template <class reference_type> | ||||||||||||||||||||
40 | class Reference | ||||||||||||||||||||
41 | { | ||||||||||||||||||||
42 | /** The <b>reference_type</b> body pointer. | ||||||||||||||||||||
43 | */ | ||||||||||||||||||||
44 | reference_type * m_pBody; | ||||||||||||||||||||
45 | |||||||||||||||||||||
46 | |||||||||||||||||||||
47 | public: | ||||||||||||||||||||
48 | /** Constructor... | ||||||||||||||||||||
49 | */ | ||||||||||||||||||||
50 | Reference() | ||||||||||||||||||||
51 | : m_pBody (NULL__null) | ||||||||||||||||||||
52 | {} | ||||||||||||||||||||
53 | |||||||||||||||||||||
54 | |||||||||||||||||||||
55 | /** Constructor... | ||||||||||||||||||||
56 | */ | ||||||||||||||||||||
57 | Reference (reference_type * pBody, __sal_NoAcquire) | ||||||||||||||||||||
58 | : m_pBody (pBody) | ||||||||||||||||||||
59 | { | ||||||||||||||||||||
60 | } | ||||||||||||||||||||
61 | |||||||||||||||||||||
62 | /** Constructor... | ||||||||||||||||||||
63 | */ | ||||||||||||||||||||
64 | Reference (reference_type * pBody) | ||||||||||||||||||||
65 | : m_pBody (pBody) | ||||||||||||||||||||
66 | { | ||||||||||||||||||||
67 | if (m_pBody) | ||||||||||||||||||||
68 | m_pBody->acquire(); | ||||||||||||||||||||
69 | } | ||||||||||||||||||||
70 | |||||||||||||||||||||
71 | /** Copy constructor... | ||||||||||||||||||||
72 | */ | ||||||||||||||||||||
73 | Reference (const Reference<reference_type> & handle) | ||||||||||||||||||||
74 | : m_pBody (handle.m_pBody) | ||||||||||||||||||||
75 | { | ||||||||||||||||||||
76 | if (m_pBody) | ||||||||||||||||||||
77 | m_pBody->acquire(); | ||||||||||||||||||||
78 | } | ||||||||||||||||||||
79 | |||||||||||||||||||||
80 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||||||||||||||
81 | /** Move constructor... | ||||||||||||||||||||
82 | */ | ||||||||||||||||||||
83 | Reference (Reference<reference_type> && handle) noexcept | ||||||||||||||||||||
84 | : m_pBody (handle.m_pBody) | ||||||||||||||||||||
85 | { | ||||||||||||||||||||
86 | handle.m_pBody = nullptr; | ||||||||||||||||||||
87 | } | ||||||||||||||||||||
88 | #endif | ||||||||||||||||||||
89 | |||||||||||||||||||||
90 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||||||||||||||
91 | /** Up-casting conversion constructor: Copies interface reference. | ||||||||||||||||||||
92 | |||||||||||||||||||||
93 | Does not work for up-casts to ambiguous bases. | ||||||||||||||||||||
94 | |||||||||||||||||||||
95 | @param rRef another reference | ||||||||||||||||||||
96 | */ | ||||||||||||||||||||
97 | template< class derived_type > | ||||||||||||||||||||
98 | inline Reference( | ||||||||||||||||||||
99 | const Reference< derived_type > & rRef, | ||||||||||||||||||||
100 | std::enable_if_t<std::is_base_of_v<reference_type, derived_type>, int> = 0 ) | ||||||||||||||||||||
101 | : m_pBody (rRef.get()) | ||||||||||||||||||||
102 | { | ||||||||||||||||||||
103 | if (m_pBody) | ||||||||||||||||||||
104 | m_pBody->acquire(); | ||||||||||||||||||||
105 | } | ||||||||||||||||||||
106 | #endif | ||||||||||||||||||||
107 | |||||||||||||||||||||
108 | /** Destructor... | ||||||||||||||||||||
109 | */ | ||||||||||||||||||||
110 | ~Reference() COVERITY_NOEXCEPT_FALSE | ||||||||||||||||||||
111 | { | ||||||||||||||||||||
112 | if (m_pBody
| ||||||||||||||||||||
113 | m_pBody->release(); | ||||||||||||||||||||
| |||||||||||||||||||||
114 | } | ||||||||||||||||||||
115 | |||||||||||||||||||||
116 | /** Set... | ||||||||||||||||||||
117 | Similar to assignment. | ||||||||||||||||||||
118 | */ | ||||||||||||||||||||
119 | Reference<reference_type> & | ||||||||||||||||||||
120 | SAL_CALL set (reference_type * pBody) | ||||||||||||||||||||
121 | { | ||||||||||||||||||||
122 | if (pBody) | ||||||||||||||||||||
123 | pBody->acquire(); | ||||||||||||||||||||
124 | reference_type * const pOld = m_pBody; | ||||||||||||||||||||
125 | m_pBody = pBody; | ||||||||||||||||||||
126 | if (pOld) | ||||||||||||||||||||
127 | pOld->release(); | ||||||||||||||||||||
128 | return *this; | ||||||||||||||||||||
129 | } | ||||||||||||||||||||
130 | |||||||||||||||||||||
131 | /** Assignment. | ||||||||||||||||||||
132 | Unbinds this instance from its body (if bound) and | ||||||||||||||||||||
133 | bind it to the body represented by the handle. | ||||||||||||||||||||
134 | */ | ||||||||||||||||||||
135 | Reference<reference_type> & | ||||||||||||||||||||
136 | SAL_CALL operator= (const Reference<reference_type> & handle) | ||||||||||||||||||||
137 | { | ||||||||||||||||||||
138 | return set( handle.m_pBody ); | ||||||||||||||||||||
139 | } | ||||||||||||||||||||
140 | |||||||||||||||||||||
141 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||||||||||||||
142 | /** Assignment. | ||||||||||||||||||||
143 | * Unbinds this instance from its body (if bound), | ||||||||||||||||||||
144 | * bind it to the body represented by the handle, and | ||||||||||||||||||||
145 | * set the body represented by the handle to nullptr. | ||||||||||||||||||||
146 | */ | ||||||||||||||||||||
147 | Reference<reference_type> & | ||||||||||||||||||||
148 | operator= (Reference<reference_type> && handle) | ||||||||||||||||||||
149 | { | ||||||||||||||||||||
150 | // self-movement guts ourself | ||||||||||||||||||||
151 | if (m_pBody) | ||||||||||||||||||||
152 | m_pBody->release(); | ||||||||||||||||||||
153 | m_pBody = handle.m_pBody; | ||||||||||||||||||||
154 | handle.m_pBody = nullptr; | ||||||||||||||||||||
155 | return *this; | ||||||||||||||||||||
156 | } | ||||||||||||||||||||
157 | #endif | ||||||||||||||||||||
158 | |||||||||||||||||||||
159 | /** Assignment... | ||||||||||||||||||||
160 | */ | ||||||||||||||||||||
161 | Reference<reference_type> & | ||||||||||||||||||||
162 | SAL_CALL operator= (reference_type * pBody) | ||||||||||||||||||||
163 | { | ||||||||||||||||||||
164 | return set( pBody ); | ||||||||||||||||||||
165 | } | ||||||||||||||||||||
166 | |||||||||||||||||||||
167 | /** Unbind the body from this handle. | ||||||||||||||||||||
168 | Note that for a handle representing a large body, | ||||||||||||||||||||
169 | "handle.clear().set(new body());" _might_ | ||||||||||||||||||||
170 | perform a little bit better than "handle.set(new body());", | ||||||||||||||||||||
171 | since in the second case two large objects exist in memory | ||||||||||||||||||||
172 | (the old body and the new body). | ||||||||||||||||||||
173 | */ | ||||||||||||||||||||
174 | Reference<reference_type> & SAL_CALL clear() | ||||||||||||||||||||
175 | { | ||||||||||||||||||||
176 | if (m_pBody) | ||||||||||||||||||||
177 | { | ||||||||||||||||||||
178 | reference_type * const pOld = m_pBody; | ||||||||||||||||||||
179 | m_pBody = NULL__null; | ||||||||||||||||||||
180 | pOld->release(); | ||||||||||||||||||||
181 | } | ||||||||||||||||||||
182 | return *this; | ||||||||||||||||||||
183 | } | ||||||||||||||||||||
184 | |||||||||||||||||||||
185 | |||||||||||||||||||||
186 | /** Get the body. Can be used instead of operator->(). | ||||||||||||||||||||
187 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() | ||||||||||||||||||||
188 | are the same. | ||||||||||||||||||||
189 | */ | ||||||||||||||||||||
190 | reference_type * SAL_CALL get() const | ||||||||||||||||||||
191 | { | ||||||||||||||||||||
192 | return m_pBody; | ||||||||||||||||||||
193 | } | ||||||||||||||||||||
194 | |||||||||||||||||||||
195 | |||||||||||||||||||||
196 | /** Probably most common used: handle->someBodyOp(). | ||||||||||||||||||||
197 | */ | ||||||||||||||||||||
198 | reference_type * SAL_CALL operator->() const | ||||||||||||||||||||
199 | { | ||||||||||||||||||||
200 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 200, __extension__ __PRETTY_FUNCTION__)); | ||||||||||||||||||||
201 | return m_pBody; | ||||||||||||||||||||
202 | } | ||||||||||||||||||||
203 | |||||||||||||||||||||
204 | |||||||||||||||||||||
205 | /** Allows (*handle).someBodyOp(). | ||||||||||||||||||||
206 | */ | ||||||||||||||||||||
207 | reference_type & SAL_CALL operator*() const | ||||||||||||||||||||
208 | { | ||||||||||||||||||||
209 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 209, __extension__ __PRETTY_FUNCTION__)); | ||||||||||||||||||||
210 | return *m_pBody; | ||||||||||||||||||||
211 | } | ||||||||||||||||||||
212 | |||||||||||||||||||||
213 | |||||||||||||||||||||
214 | /** Returns True if the handle does point to a valid body. | ||||||||||||||||||||
215 | */ | ||||||||||||||||||||
216 | bool SAL_CALL is() const | ||||||||||||||||||||
217 | { | ||||||||||||||||||||
218 | return (m_pBody != NULL__null); | ||||||||||||||||||||
219 | } | ||||||||||||||||||||
220 | |||||||||||||||||||||
221 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||||||||||||||
222 | /** Returns True if the handle does point to a valid body. | ||||||||||||||||||||
223 | */ | ||||||||||||||||||||
224 | explicit operator bool() const | ||||||||||||||||||||
225 | { | ||||||||||||||||||||
226 | return is(); | ||||||||||||||||||||
227 | } | ||||||||||||||||||||
228 | #endif | ||||||||||||||||||||
229 | |||||||||||||||||||||
230 | /** Returns True if this points to pBody. | ||||||||||||||||||||
231 | */ | ||||||||||||||||||||
232 | bool SAL_CALL operator== (const reference_type * pBody) const | ||||||||||||||||||||
233 | { | ||||||||||||||||||||
234 | return (m_pBody == pBody); | ||||||||||||||||||||
235 | } | ||||||||||||||||||||
236 | |||||||||||||||||||||
237 | |||||||||||||||||||||
238 | /** Returns True if handle points to the same body. | ||||||||||||||||||||
239 | */ | ||||||||||||||||||||
240 | bool | ||||||||||||||||||||
241 | SAL_CALL operator== (const Reference<reference_type> & handle) const | ||||||||||||||||||||
242 | { | ||||||||||||||||||||
243 | return (m_pBody == handle.m_pBody); | ||||||||||||||||||||
244 | } | ||||||||||||||||||||
245 | |||||||||||||||||||||
246 | |||||||||||||||||||||
247 | /** Needed to place References into STL collection. | ||||||||||||||||||||
248 | */ | ||||||||||||||||||||
249 | bool | ||||||||||||||||||||
250 | SAL_CALL operator!= (const Reference<reference_type> & handle) const | ||||||||||||||||||||
251 | { | ||||||||||||||||||||
252 | return (m_pBody != handle.m_pBody); | ||||||||||||||||||||
253 | } | ||||||||||||||||||||
254 | |||||||||||||||||||||
255 | |||||||||||||||||||||
256 | /** Needed to place References into STL collection. | ||||||||||||||||||||
257 | */ | ||||||||||||||||||||
258 | bool | ||||||||||||||||||||
259 | SAL_CALL operator< (const Reference<reference_type> & handle) const | ||||||||||||||||||||
260 | { | ||||||||||||||||||||
261 | return (m_pBody < handle.m_pBody); | ||||||||||||||||||||
262 | } | ||||||||||||||||||||
263 | |||||||||||||||||||||
264 | |||||||||||||||||||||
265 | /** Needed to place References into STL collection. | ||||||||||||||||||||
266 | */ | ||||||||||||||||||||
267 | bool | ||||||||||||||||||||
268 | SAL_CALL operator> (const Reference<reference_type> & handle) const | ||||||||||||||||||||
269 | { | ||||||||||||||||||||
270 | return (m_pBody > handle.m_pBody); | ||||||||||||||||||||
271 | } | ||||||||||||||||||||
272 | }; | ||||||||||||||||||||
273 | |||||||||||||||||||||
274 | } // namespace rtl | ||||||||||||||||||||
275 | |||||||||||||||||||||
276 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||||||||||||||
277 | namespace std | ||||||||||||||||||||
278 | { | ||||||||||||||||||||
279 | |||||||||||||||||||||
280 | /// @cond INTERNAL | ||||||||||||||||||||
281 | /** | ||||||||||||||||||||
282 | Make rtl::Reference hashable by default for use in STL containers. | ||||||||||||||||||||
283 | |||||||||||||||||||||
284 | @since LibreOffice 6.3 | ||||||||||||||||||||
285 | */ | ||||||||||||||||||||
286 | template<typename T> | ||||||||||||||||||||
287 | struct hash<::rtl::Reference<T>> | ||||||||||||||||||||
288 | { | ||||||||||||||||||||
289 | std::size_t operator()(::rtl::Reference<T> const & s) const | ||||||||||||||||||||
290 | { return std::size_t(s.get()); } | ||||||||||||||||||||
291 | }; | ||||||||||||||||||||
292 | /// @endcond | ||||||||||||||||||||
293 | |||||||||||||||||||||
294 | } | ||||||||||||||||||||
295 | |||||||||||||||||||||
296 | #endif | ||||||||||||||||||||
297 | |||||||||||||||||||||
298 | #endif /* ! INCLUDED_RTL_REF_HXX */ | ||||||||||||||||||||
299 | |||||||||||||||||||||
300 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | #ifndef INCLUDED_VCL_Reference_HXX |
20 | #define INCLUDED_VCL_Reference_HXX |
21 | |
22 | #include <vcl/dllapi.h> |
23 | #include <osl/interlck.h> |
24 | |
25 | class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase |
26 | { |
27 | mutable oslInterlockedCount mnRefCnt; |
28 | |
29 | template<typename T> friend class VclPtr; |
30 | |
31 | public: |
32 | void acquire() const |
33 | { |
34 | osl_atomic_increment(&mnRefCnt)__sync_add_and_fetch((&mnRefCnt), 1); |
35 | } |
36 | |
37 | void release() const |
38 | { |
39 | if (osl_atomic_decrement(&mnRefCnt)__sync_sub_and_fetch((&mnRefCnt), 1) == 0) |
40 | delete this; |
41 | } |
42 | #ifdef DBG_UTIL |
43 | #ifndef _WIN32 |
44 | sal_Int32 getRefCount() const { return mnRefCnt; } |
45 | #endif |
46 | #endif |
47 | |
48 | |
49 | private: |
50 | VclReferenceBase(const VclReferenceBase&) = delete; |
51 | VclReferenceBase& operator=(const VclReferenceBase&) = delete; |
52 | |
53 | bool mbDisposed : 1; |
54 | |
55 | protected: |
56 | VclReferenceBase(); |
57 | protected: |
58 | virtual ~VclReferenceBase(); |
59 | |
60 | protected: |
61 | virtual void dispose(); |
62 | |
63 | public: |
64 | void disposeOnce(); |
65 | bool isDisposed() const { return mbDisposed; } |
66 | |
67 | }; |
68 | #endif |