Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : :
21 : : #include "sbagrid.hrc"
22 : :
23 : : #include <svx/svxids.hrc>
24 : :
25 : : #include <svx/numinf.hxx>
26 : : #include <svx/dbaexchange.hxx>
27 : : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
28 : :
29 : : #include "sbagrid.hxx"
30 : : #include "dlgattr.hxx"
31 : : #include "dlgsize.hxx"
32 : : #include <com/sun/star/form/XLoadable.hpp>
33 : : #include <com/sun/star/sdb/CommandType.hpp>
34 : : #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
35 : : #include <com/sun/star/sdb/XResultSetAccess.hpp>
36 : : #include <com/sun/star/form/XForm.hpp>
37 : : #include <com/sun/star/container/XIndexContainer.hpp>
38 : : #include <com/sun/star/util/NumberFormat.hpp>
39 : :
40 : : #include <com/sun/star/view/XSelectionSupplier.hpp>
41 : : #include <com/sun/star/form/DataSelectionType.hpp>
42 : : #include <com/sun/star/awt/TextAlign.hpp>
43 : : #include <com/sun/star/awt/XTextComponent.hpp>
44 : : #include <com/sun/star/util/Date.hpp>
45 : : #include <com/sun/star/util/Time.hpp>
46 : : #include <com/sun/star/util/DateTime.hpp>
47 : : #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
48 : : #include <tools/diagnose_ex.h>
49 : :
50 : : #include <svl/intitem.hxx>
51 : :
52 : : #include <svx/algitem.hxx>
53 : :
54 : : #include <tools/multisel.hxx>
55 : :
56 : : #include <svl/numuno.hxx>
57 : :
58 : : #include <svl/itempool.hxx>
59 : :
60 : : #include <svl/itemset.hxx>
61 : :
62 : : #include <svl/rngitem.hxx>
63 : :
64 : : #include <vcl/waitobj.hxx>
65 : : #include <toolkit/helper/vclunohelper.hxx>
66 : :
67 : : #include <svl/zforlist.hxx>
68 : : #include <cppuhelper/queryinterface.hxx>
69 : : #include <connectivity/dbtools.hxx>
70 : : #include <connectivity/dbconversion.hxx>
71 : : #include <cppuhelper/typeprovider.hxx>
72 : : #include <rtl/memory.h>
73 : : #include <comphelper/extract.hxx>
74 : : #include <comphelper/servicehelper.hxx>
75 : : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
76 : : #include <com/sun/star/sdbc/DataType.hpp>
77 : : #include <vcl/msgbox.hxx>
78 : : #include "dbu_brw.hrc"
79 : : #include "browserids.hxx"
80 : : #include "dbustrings.hrc"
81 : : #include "dbu_reghelper.hxx"
82 : : #include "dbexchange.hxx"
83 : : #include "TableRowExchange.hxx"
84 : : #include "TableRow.hxx"
85 : : #include "FieldDescriptions.hxx"
86 : : #include <svtools/stringtransfer.hxx>
87 : : #include <vcl/stdtext.hxx>
88 : : #include "UITools.hxx"
89 : : #include "TokenWriter.hxx"
90 : : #include <osl/diagnose.h>
91 : :
92 : : using namespace ::com::sun::star::ui::dialogs;
93 : : using namespace ::com::sun::star::uno;
94 : : using namespace ::com::sun::star::sdb;
95 : : using namespace ::com::sun::star::sdbc;
96 : : using namespace ::com::sun::star::sdbcx;
97 : : using namespace ::com::sun::star::beans;
98 : : using namespace ::com::sun::star::container;
99 : : using namespace ::com::sun::star::datatransfer;
100 : : using namespace ::com::sun::star::lang;
101 : : using namespace ::com::sun::star::view;
102 : : using namespace ::com::sun::star::form;
103 : : using namespace ::com::sun::star::frame;
104 : : using namespace ::com::sun::star::util;
105 : : using namespace ::dbaui;
106 : : using namespace ::dbtools;
107 : : using namespace ::svx;
108 : : using namespace ::svt;
109 : :
110 : 8 : extern "C" void SAL_CALL createRegistryInfo_SbaXGridControl()
111 : : {
112 [ + - ][ + - ]: 8 : static OMultiInstanceAutoRegistration< SbaXGridControl > aAutoRegistration;
[ + - ][ # # ]
113 : 8 : }
114 : : //-------------------------------------------------------------------------
115 : 0 : ::comphelper::StringSequence SAL_CALL SbaXGridControl::getSupportedServiceNames() throw()
116 : : {
117 : 0 : return getSupportedServiceNames_Static();
118 : : }
119 : : // -------------------------------------------------------------------------
120 : 20 : Reference< XInterface > SAL_CALL SbaXGridControl::Create(const Reference<XMultiServiceFactory >& _rxFactory)
121 : : {
122 [ + - ]: 20 : return *(new SbaXGridControl(_rxFactory));
123 : : }
124 : :
125 : : //------------------------------------------------------------------
126 : :
127 : : //------------------------------------------------------------------
128 : : //=======================================================================================
129 : : // SbaXGridControl
130 : : //=======================================================================================
131 : :
132 : : //------------------------------------------------------------------------------
133 : 0 : ::rtl::OUString SAL_CALL SbaXGridControl::getImplementationName() throw()
134 : : {
135 : 0 : return getImplementationName_Static();
136 : : }
137 : :
138 : : //------------------------------------------------------------------------------
139 : 16 : ::rtl::OUString SbaXGridControl::getImplementationName_Static() throw( RuntimeException )
140 : : {
141 : 16 : return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.dbu.SbaXGridControl"));
142 : : }
143 : :
144 : : //------------------------------------------------------------------------------
145 : 8 : Sequence< ::rtl::OUString> SbaXGridControl::getSupportedServiceNames_Static(void) throw( RuntimeException )
146 : : {
147 : 8 : Sequence< ::rtl::OUString> aSupported(3);
148 [ + - ][ + - ]: 8 : aSupported[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.control.InteractionGridControl"));
149 [ + - ][ + - ]: 8 : aSupported[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.control.GridControl"));
150 [ + - ][ + - ]: 8 : aSupported[2] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControl"));
151 : 8 : return aSupported;
152 : : }
153 : : DBG_NAME(SbaXGridControl );
154 : : //---------------------------------------------------------------------------------------
155 : 22 : SbaXGridControl::SbaXGridControl(const Reference< XMultiServiceFactory >& _rM)
156 [ + - ]: 22 : : FmXGridControl(_rM)
157 : : {
158 : : DBG_CTOR(SbaXGridControl ,NULL);
159 : 22 : }
160 : :
161 : : //---------------------------------------------------------------------------------------
162 : 22 : SbaXGridControl::~SbaXGridControl()
163 : : {
164 : : DBG_DTOR(SbaXGridControl ,NULL);
165 [ - + ]: 44 : }
166 : :
167 : : //---------------------------------------------------------------------------------------
168 : 40 : FmXGridPeer* SbaXGridControl::imp_CreatePeer(Window* pParent)
169 : : {
170 [ + - ]: 40 : FmXGridPeer* pReturn = new SbaXGridPeer(m_xServiceFactory);
171 : :
172 : : // translate properties into WinBits
173 : 40 : WinBits nStyle = WB_TABSTOP;
174 [ + - ][ + - ]: 40 : Reference< XPropertySet > xModelSet(getModel(), UNO_QUERY);
175 [ + - ]: 40 : if (xModelSet.is())
176 : : {
177 : : try
178 : : {
179 [ + - ][ + - ]: 40 : if (::comphelper::getINT16(xModelSet->getPropertyValue(PROPERTY_BORDER)))
[ + - ][ + - ]
[ + - # # ]
180 : 40 : nStyle |= WB_BORDER;
181 : : }
182 [ # # ]: 0 : catch(Exception&)
183 : : {
184 : : }
185 : :
186 : : }
187 : :
188 [ + - ]: 40 : pReturn->Create(pParent, nStyle);
189 : 40 : return pReturn;
190 : : }
191 : :
192 : : //------------------------------------------------------------------------------
193 : 911 : Any SAL_CALL SbaXGridControl::queryInterface(const Type& _rType) throw (RuntimeException)
194 : : {
195 [ + - ]: 911 : Any aRet = FmXGridControl::queryInterface(_rType);
196 [ + + ][ + - ]: 911 : return aRet.hasValue() ? aRet : ::cppu::queryInterface(_rType,(::com::sun::star::frame::XDispatch*)this);
197 : : }
198 : :
199 : : //------------------------------------------------------------------------------
200 : 0 : Sequence< Type > SAL_CALL SbaXGridControl::getTypes( ) throw (RuntimeException)
201 : : {
202 : 0 : Sequence< Type > aTypes = FmXGridControl::getTypes();
203 : :
204 : 0 : sal_Int32 nTypes = aTypes.getLength();
205 [ # # ]: 0 : aTypes.realloc(nTypes + 1);
206 [ # # ][ # # ]: 0 : aTypes[nTypes] = ::getCppuType(static_cast< Reference< ::com::sun::star::frame::XDispatch >* >(NULL));
207 : :
208 : 0 : return aTypes;
209 : : }
210 : :
211 : : //------------------------------------------------------------------------------
212 : 0 : Sequence< sal_Int8 > SAL_CALL SbaXGridControl::getImplementationId( ) throw (RuntimeException)
213 : : {
214 : : static ::cppu::OImplementationId * pId = 0;
215 [ # # ]: 0 : if (! pId)
216 : : {
217 [ # # ][ # # ]: 0 : ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
218 [ # # ]: 0 : if (! pId)
219 : : {
220 [ # # ][ # # ]: 0 : static ::cppu::OImplementationId aId;
221 : 0 : pId = &aId;
222 [ # # ]: 0 : }
223 : : }
224 : 0 : return pId->getImplementationId();
225 : : }
226 : :
227 : : //---------------------------------------------------------------------------------------
228 : 40 : void SAL_CALL SbaXGridControl::createPeer(const Reference< ::com::sun::star::awt::XToolkit > & rToolkit, const Reference< ::com::sun::star::awt::XWindowPeer > & rParentPeer) throw( RuntimeException )
229 : : {
230 [ + - ]: 40 : FmXGridControl::createPeer(rToolkit, rParentPeer);
231 : :
232 : : OSL_ENSURE(!mbCreatingPeer, "FmXGridControl::createPeer : recursion!");
233 : : // see the base class' createPeer for a comment on this
234 : :
235 : : // TODO: why the hell this whole class does not use any mutex?
236 : :
237 [ + - ][ + - ]: 40 : Reference< ::com::sun::star::frame::XDispatch > xDisp(getPeer(), UNO_QUERY);
238 [ - + ]: 80 : for ( StatusMultiplexerArray::iterator aIter = m_aStatusMultiplexer.begin();
239 : 40 : aIter != m_aStatusMultiplexer.end();
240 : : ++aIter)
241 : : {
242 [ # # ][ # # ]: 0 : if ((*aIter).second && (*aIter).second->getLength())
[ # # ][ # # ]
243 [ # # ][ # # ]: 0 : xDisp->addStatusListener((*aIter).second, (*aIter).first);
[ # # ][ # # ]
244 : 40 : }
245 : 40 : }
246 : :
247 : : //---------------------------------------------------------------------------------------
248 : 0 : void SAL_CALL SbaXGridControl::dispatch(const ::com::sun::star::util::URL& aURL, const Sequence< PropertyValue >& aArgs) throw( RuntimeException )
249 : : {
250 [ # # ][ # # ]: 0 : Reference< ::com::sun::star::frame::XDispatch > xDisp(getPeer(), UNO_QUERY);
251 [ # # ]: 0 : if (xDisp.is())
252 [ # # ][ # # ]: 0 : xDisp->dispatch(aURL, aArgs);
253 : 0 : }
254 : : //---------------------------------------------------------------------------------------
255 : 0 : void SAL_CALL SbaXGridControl::addStatusListener( const Reference< XStatusListener > & _rxListener, const URL& _rURL ) throw( RuntimeException )
256 : : {
257 [ # # ]: 0 : ::osl::MutexGuard aGuard( GetMutex() );
258 [ # # ]: 0 : if ( _rxListener.is() )
259 : : {
260 [ # # ]: 0 : SbaXStatusMultiplexer*& pMultiplexer = m_aStatusMultiplexer[ _rURL ];
261 [ # # ]: 0 : if ( !pMultiplexer )
262 : : {
263 [ # # ][ # # ]: 0 : pMultiplexer = new SbaXStatusMultiplexer( *this, GetMutex() );
264 : 0 : pMultiplexer->acquire();
265 : : }
266 : :
267 [ # # ]: 0 : pMultiplexer->addInterface( _rxListener );
268 [ # # ][ # # ]: 0 : if ( getPeer().is() )
269 : : {
270 [ # # ][ # # ]: 0 : if ( 1 == pMultiplexer->getLength() )
271 : : { // the first external listener for this URL
272 [ # # ][ # # ]: 0 : Reference< XDispatch > xDisp( getPeer(), UNO_QUERY );
273 [ # # ][ # # ]: 0 : xDisp->addStatusListener( pMultiplexer, _rURL );
[ # # ][ # # ]
274 : : }
275 : : else
276 : : { // already have other listeners for this URL
277 [ # # ][ # # ]: 0 : _rxListener->statusChanged( pMultiplexer->getLastEvent() );
[ # # ][ # # ]
278 : : }
279 : : }
280 [ # # ]: 0 : }
281 : 0 : }
282 : :
283 : : //---------------------------------------------------------------------------------------
284 : 0 : void SAL_CALL SbaXGridControl::removeStatusListener(const Reference< ::com::sun::star::frame::XStatusListener > & _rxListener, const ::com::sun::star::util::URL& _rURL) throw( RuntimeException )
285 : : {
286 [ # # ]: 0 : ::osl::MutexGuard aGuard( GetMutex() );
287 : :
288 [ # # ]: 0 : SbaXStatusMultiplexer*& pMultiplexer = m_aStatusMultiplexer[_rURL];
289 [ # # ]: 0 : if (!pMultiplexer)
290 : : {
291 [ # # ][ # # ]: 0 : pMultiplexer = new SbaXStatusMultiplexer(*this,GetMutex());
292 : 0 : pMultiplexer->acquire();
293 : : }
294 : :
295 [ # # ][ # # ]: 0 : if (getPeer().is() && pMultiplexer->getLength() == 1)
[ # # ][ # # ]
[ # # ]
[ # # # # ]
296 : : {
297 [ # # ][ # # ]: 0 : Reference< ::com::sun::star::frame::XDispatch > xDisp(getPeer(), UNO_QUERY);
298 [ # # ][ # # ]: 0 : xDisp->removeStatusListener(pMultiplexer, _rURL);
[ # # ][ # # ]
299 : : }
300 [ # # ][ # # ]: 0 : pMultiplexer->removeInterface( _rxListener );
301 : 0 : }
302 : :
303 : : //---------------------------------------------------------------------------------------
304 : 24 : void SAL_CALL SbaXGridControl::dispose(void) throw( RuntimeException )
305 : : {
306 [ + - ]: 24 : SolarMutexGuard aGuard;
307 : :
308 [ + - ]: 24 : EventObject aEvt;
309 [ + - ][ + - ]: 24 : aEvt.Source = *this;
310 : :
311 [ - + ]: 48 : for ( StatusMultiplexerArray::iterator aIter = m_aStatusMultiplexer.begin();
312 : 24 : aIter != m_aStatusMultiplexer.end();
313 : : ++aIter)
314 : : {
315 [ # # ]: 0 : if ((*aIter).second)
316 : : {
317 [ # # ]: 0 : (*aIter).second->disposeAndClear(aEvt);
318 : 0 : (*aIter).second->release();
319 : 0 : (*aIter).second = NULL;
320 : : }
321 : : }
322 [ + - ][ + - ]: 24 : StatusMultiplexerArray().swap(m_aStatusMultiplexer);
323 : :
324 [ + - ][ + - ]: 24 : FmXGridControl::dispose();
[ + - ]
325 : 24 : }
326 : :
327 : : //=======================================================================================
328 : : // SbaXGridPeer
329 : : //=======================================================================================
330 : : DBG_NAME(SbaXGridPeer )
331 : : //---------------------------------------------------------------------------------------
332 : 40 : SbaXGridPeer::SbaXGridPeer(const Reference< XMultiServiceFactory >& _rM)
333 : : : FmXGridPeer(_rM)
334 [ + - ][ + - ]: 40 : ,m_aStatusListeners(m_aMutex)
[ + - ][ + - ]
335 : : {
336 : : DBG_CTOR(SbaXGridPeer ,NULL);
337 : 40 : }
338 : :
339 : : //---------------------------------------------------------------------------------------
340 [ + - ]: 40 : SbaXGridPeer::~SbaXGridPeer()
341 : : {
342 : : DBG_DTOR(SbaXGridPeer ,NULL);
343 [ - + ]: 80 : }
344 : :
345 : : //---------------------------------------------------------------------------------------
346 : 80 : void SAL_CALL SbaXGridPeer::dispose(void) throw( RuntimeException )
347 : : {
348 [ + - ][ + - ]: 80 : EventObject aEvt(*this);
349 : :
350 [ + - ]: 80 : m_aStatusListeners.disposeAndClear(aEvt);
351 : :
352 [ + - ][ + - ]: 80 : FmXGridPeer::dispose();
353 : 80 : }
354 : :
355 : : //---------------------------------------------------------------------------------------
356 : 0 : void SbaXGridPeer::NotifyStatusChanged(const ::com::sun::star::util::URL& _rUrl, const Reference< ::com::sun::star::frame::XStatusListener > & xControl)
357 : : {
358 : 0 : SbaGridControl* pGrid = (SbaGridControl*) GetWindow();
359 [ # # ]: 0 : if (!pGrid)
360 : 0 : return;
361 : :
362 [ # # ]: 0 : ::com::sun::star::frame::FeatureStateEvent aEvt;
363 [ # # ][ # # ]: 0 : aEvt.Source = *this;
364 [ # # ]: 0 : aEvt.IsEnabled = !pGrid->IsReadOnlyDB();
365 : 0 : aEvt.FeatureURL = _rUrl;
366 : :
367 [ # # ][ # # ]: 0 : ConstMapDispatchToBoolIterator aURLStatePos = m_aDispatchStates.find( classifyDispatchURL( _rUrl ) );
[ # # ]
368 [ # # ][ # # ]: 0 : if ( m_aDispatchStates.end() != aURLStatePos )
369 [ # # ][ # # ]: 0 : aEvt.State <<= aURLStatePos->second;
370 : : else
371 [ # # ]: 0 : aEvt.State <<= sal_False;
372 : :
373 [ # # ]: 0 : if (xControl.is())
374 [ # # ][ # # ]: 0 : xControl->statusChanged(aEvt);
375 : : else
376 : : {
377 [ # # ]: 0 : ::cppu::OInterfaceContainerHelper * pIter = m_aStatusListeners.getContainer(_rUrl);
378 : :
379 [ # # ]: 0 : if (pIter)
380 : : {
381 [ # # ]: 0 : ::cppu::OInterfaceIteratorHelper aListIter(*pIter);
382 [ # # ]: 0 : while (aListIter.hasMoreElements())
383 [ # # ][ # # ]: 0 : ((::com::sun::star::frame::XStatusListener*)aListIter.next())->statusChanged(aEvt);
[ # # ]
384 : : }
385 [ # # ]: 0 : }
386 : : }
387 : :
388 : : //------------------------------------------------------------------------------
389 : 2720 : Any SAL_CALL SbaXGridPeer::queryInterface(const Type& _rType) throw (RuntimeException)
390 : : {
391 [ + - ]: 2720 : Any aRet = ::cppu::queryInterface(_rType,(::com::sun::star::frame::XDispatch*)this);
392 [ + + ]: 2720 : if(aRet.hasValue())
393 : 40 : return aRet;
394 [ + - ]: 2720 : return FmXGridPeer::queryInterface(_rType);
395 : : }
396 : :
397 : : //---------------------------------------------------------------------------------------
398 : 42 : Reference< ::com::sun::star::frame::XDispatch > SAL_CALL SbaXGridPeer::queryDispatch(const ::com::sun::star::util::URL& aURL, const ::rtl::OUString& aTargetFrameName, sal_Int32 nSearchFlags) throw( RuntimeException )
399 : : {
400 [ + - ][ + - : 126 : if ( ( aURL.Complete == ".uno:GridSlots/BrowserAttribs" ) || ( aURL.Complete == ".uno:GridSlots/RowHeight" )
+ - - + ]
[ - + ]
401 : 84 : || ( aURL.Complete == ".uno:GridSlots/ColumnAttribs" ) || ( aURL.Complete == ".uno:GridSlots/ColumnWidth" )
402 : : )
403 : : {
404 : 0 : return (::com::sun::star::frame::XDispatch*)this;
405 : : }
406 : :
407 : 42 : return FmXGridPeer::queryDispatch(aURL, aTargetFrameName, nSearchFlags);
408 : : }
409 : :
410 : : //---------------------------------------------------------------------------------------
411 : 0 : IMPL_LINK( SbaXGridPeer, OnDispatchEvent, void*, /*NOTINTERESTEDIN*/ )
412 : : {
413 : 0 : SbaGridControl* pGrid = static_cast< SbaGridControl* >( GetWindow() );
414 [ # # ]: 0 : if ( pGrid ) // if this fails, we were disposing before arriving here
415 : : {
416 [ # # ]: 0 : if ( Application::GetMainThreadIdentifier() != ::osl::Thread::getCurrentIdentifier() )
417 : : {
418 : : // still not in the main thread (see SbaXGridPeer::dispatch). post an event, again
419 : : // without moving the special even to the back of the queue
420 [ # # ]: 0 : pGrid->PostUserEvent( LINK( this, SbaXGridPeer, OnDispatchEvent ) );
421 : : }
422 : : else
423 : : {
424 [ # # ][ # # ]: 0 : DispatchArgs aArgs = m_aDispatchArgs.front();
425 [ # # ]: 0 : m_aDispatchArgs.pop();
426 : :
427 [ # # ][ # # ]: 0 : SbaXGridPeer::dispatch( aArgs.aURL, aArgs.aArgs );
428 : : }
429 : : }
430 : :
431 : 0 : return 0;
432 : : }
433 : :
434 : : //---------------------------------------------------------------------------------------
435 : 0 : SbaXGridPeer::DispatchType SbaXGridPeer::classifyDispatchURL( const URL& _rURL )
436 : : {
437 : 0 : DispatchType eURLType = dtUnknown;
438 [ # # ]: 0 : if ( _rURL.Complete == ".uno:GridSlots/BrowserAttribs" )
439 : 0 : eURLType = dtBrowserAttribs;
440 [ # # ]: 0 : else if ( _rURL.Complete == ".uno:GridSlots/RowHeight" )
441 : 0 : eURLType = dtRowHeight;
442 [ # # ]: 0 : else if ( _rURL.Complete == ".uno:GridSlots/ColumnAttribs" )
443 : 0 : eURLType = dtColumnAttribs;
444 [ # # ]: 0 : else if ( _rURL.Complete == ".uno:GridSlots/ColumnWidth" )
445 : 0 : eURLType = dtColumnWidth;
446 : 0 : return eURLType;
447 : : }
448 : :
449 : : //---------------------------------------------------------------------------------------
450 : 0 : void SAL_CALL SbaXGridPeer::dispatch(const URL& aURL, const Sequence< PropertyValue >& aArgs) throw( RuntimeException )
451 : : {
452 : 0 : SbaGridControl* pGrid = (SbaGridControl*)GetWindow();
453 [ # # ]: 0 : if (!pGrid)
454 : : return;
455 : :
456 [ # # ][ # # ]: 0 : if ( Application::GetMainThreadIdentifier() != ::osl::Thread::getCurrentIdentifier() )
[ # # ]
457 : : {
458 : : // we're not in the main thread. This is bad, as we want to raise windows here,
459 : : // and VCL does not like windows to be opened in non-main threads (at least on Win32).
460 : : // Okay, do this async. No problem with this, as XDispatch::dispatch is defined to be
461 : : // a one-way method.
462 : :
463 : : // save the args
464 [ # # ]: 0 : DispatchArgs aDispatchArgs;
465 : 0 : aDispatchArgs.aURL = aURL;
466 [ # # ]: 0 : aDispatchArgs.aArgs = aArgs;
467 [ # # ]: 0 : m_aDispatchArgs.push( aDispatchArgs );
468 : :
469 : : // post an event
470 : : // we use the Window::PostUserEvent here, instead of the application::PostUserEvent
471 : : // this saves us from keeping track of these events - as soon as the window dies,
472 : : // the events are deleted automatically. For the application way, we would need to
473 : : // do this ourself.
474 : : // As we use our grid as window, and the grid dies before we dy, this should be no problem.
475 [ # # ][ # # ]: 0 : pGrid->PostUserEvent( LINK( this, SbaXGridPeer, OnDispatchEvent ) );
476 [ # # ]: 0 : return;
477 : : }
478 : :
479 [ # # ]: 0 : SolarMutexGuard aGuard;
480 : 0 : sal_Int16 nColId = -1;
481 : 0 : const PropertyValue* pArgs = aArgs.getConstArray();
482 [ # # ]: 0 : for (sal_uInt16 i=0; i<aArgs.getLength(); ++i, ++pArgs)
483 : : {
484 [ # # ][ # # ]: 0 : if (pArgs->Name == ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ColumnViewPos")))
485 : : {
486 [ # # ][ # # ]: 0 : nColId = pGrid->GetColumnIdFromViewPos(::comphelper::getINT16(pArgs->Value));
487 : 0 : break;
488 : : }
489 [ # # ][ # # ]: 0 : if (pArgs->Name == ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ColumnModelPos")))
490 : : {
491 [ # # ][ # # ]: 0 : nColId = pGrid->GetColumnIdFromModelPos(::comphelper::getINT16(pArgs->Value));
492 : 0 : break;
493 : : }
494 [ # # ][ # # ]: 0 : if (pArgs->Name == ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ColumnId")))
495 : : {
496 [ # # ]: 0 : nColId = ::comphelper::getINT16(pArgs->Value);
497 : 0 : break;
498 : : }
499 : : }
500 : :
501 [ # # ]: 0 : DispatchType eURLType = classifyDispatchURL( aURL );
502 : :
503 [ # # ]: 0 : if ( dtUnknown != eURLType )
504 : : {
505 : : // notify any status listeners that the dialog is now active (well, about to be active)
506 [ # # ][ # # ]: 0 : MapDispatchToBool::iterator aThisURLState = m_aDispatchStates.insert( MapDispatchToBool::value_type( eURLType, sal_True ) ).first;
507 [ # # ][ # # ]: 0 : NotifyStatusChanged( aURL, NULL );
508 : :
509 : : // execute the dialog
510 [ # # # # : 0 : switch ( eURLType )
# # ]
511 : : {
512 : : case dtBrowserAttribs:
513 [ # # ]: 0 : pGrid->SetBrowserAttrs();
514 : 0 : break;
515 : :
516 : : case dtRowHeight:
517 [ # # ]: 0 : pGrid->SetRowHeight();
518 : 0 : break;
519 : :
520 : : case dtColumnAttribs:
521 : : {
522 : : OSL_ENSURE(nColId != -1, "SbaXGridPeer::dispatch : invalid parameter !");
523 [ # # ]: 0 : if (nColId != -1)
524 : 0 : break;
525 [ # # ]: 0 : pGrid->SetColAttrs(nColId);
526 : : }
527 : 0 : break;
528 : :
529 : : case dtColumnWidth:
530 : : {
531 : : OSL_ENSURE(nColId != -1, "SbaXGridPeer::dispatch : invalid parameter !");
532 [ # # ]: 0 : if (nColId != -1)
533 : 0 : break;
534 [ # # ]: 0 : pGrid->SetColWidth(nColId);
535 : : }
536 : 0 : break;
537 : :
538 : : case dtUnknown:
539 : 0 : break;
540 : : }
541 : :
542 : : // notify any status listeners that the dialog vanished
543 [ # # ]: 0 : m_aDispatchStates.erase( aThisURLState );
544 [ # # ][ # # ]: 0 : NotifyStatusChanged( aURL, NULL );
545 [ # # ]: 0 : }
546 : : }
547 : :
548 : : //---------------------------------------------------------------------------------------
549 : 0 : void SAL_CALL SbaXGridPeer::addStatusListener(const Reference< ::com::sun::star::frame::XStatusListener > & xControl, const ::com::sun::star::util::URL& aURL) throw( RuntimeException )
550 : : {
551 : 0 : ::cppu::OInterfaceContainerHelper* pCont = m_aStatusListeners.getContainer(aURL);
552 [ # # ]: 0 : if (!pCont)
553 : 0 : m_aStatusListeners.addInterface(aURL,xControl);
554 : : else
555 : 0 : pCont->addInterface(xControl);
556 : 0 : NotifyStatusChanged(aURL, xControl);
557 : 0 : }
558 : :
559 : : //---------------------------------------------------------------------------------------
560 : 0 : void SAL_CALL SbaXGridPeer::removeStatusListener(const Reference< ::com::sun::star::frame::XStatusListener > & xControl, const ::com::sun::star::util::URL& aURL) throw( RuntimeException )
561 : : {
562 : 0 : ::cppu::OInterfaceContainerHelper* pCont = m_aStatusListeners.getContainer(aURL);
563 [ # # ]: 0 : if ( pCont )
564 : 0 : pCont->removeInterface(xControl);
565 : 0 : }
566 : :
567 : : namespace
568 : : {
569 : : class theSbaXGridPeerUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSbaXGridPeerUnoTunnelId > {};
570 : : }
571 : :
572 : 512 : const Sequence< sal_Int8 > & SbaXGridPeer::getUnoTunnelId()
573 : : {
574 : 512 : return theSbaXGridPeerUnoTunnelId::get().getSeq();
575 : : }
576 : :
577 : 0 : Sequence< Type > SAL_CALL SbaXGridPeer::getTypes() throw (RuntimeException)
578 : : {
579 : 0 : Sequence< Type > aTypes = FmXGridPeer::getTypes();
580 : 0 : sal_Int32 nOldLen = aTypes.getLength();
581 [ # # ]: 0 : aTypes.realloc(nOldLen + 1);
582 [ # # ][ # # ]: 0 : aTypes.getArray()[nOldLen] = ::getCppuType( static_cast< Reference< ::com::sun::star::frame::XDispatch >* >(0) );
583 : :
584 : 0 : return aTypes;
585 : : }
586 : :
587 : : // return implementation specific data
588 : : //------------------------------------------------------------------
589 : 510 : sal_Int64 SAL_CALL SbaXGridPeer::getSomething( const Sequence< sal_Int8 > & rId ) throw(::com::sun::star::uno::RuntimeException)
590 : : {
591 [ + - ][ + + ]: 510 : if( rId.getLength() == 16 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) )
[ + + ]
592 : 2 : return reinterpret_cast< sal_Int64 >( this );
593 : :
594 : 510 : return FmXGridPeer::getSomething(rId);
595 : : }
596 : :
597 : : //---------------------------------------------------------------------------------------
598 : 2 : SbaXGridPeer* SbaXGridPeer::getImplementation(const Reference< XInterface >& _rxIFace)
599 : : {
600 : : Reference< XUnoTunnel > xTunnel(
601 [ + - ]: 2 : _rxIFace, UNO_QUERY);
602 [ + - ]: 2 : if (xTunnel.is())
603 [ + - ][ + - ]: 2 : return reinterpret_cast<SbaXGridPeer*>(xTunnel->getSomething(getUnoTunnelId()));
[ + - ]
604 : 2 : return NULL;
605 : : }
606 : :
607 : : //---------------------------------------------------------------------------------------
608 : 40 : FmGridControl* SbaXGridPeer::imp_CreateControl(Window* pParent, WinBits nStyle)
609 : : {
610 [ + - ][ + - ]: 40 : return new SbaGridControl(m_xServiceFactory, pParent, this, nStyle);
611 : : }
612 : :
613 : : //==================================================================
614 : : // SbaGridHeader
615 : : //==================================================================
616 : :
617 : : //---------------------------------------------------------------------------------------
618 : 40 : SbaGridHeader::SbaGridHeader(BrowseBox* pParent, WinBits nWinBits)
619 : : :FmGridHeader(pParent, nWinBits)
620 [ + - ]: 40 : ,DragSourceHelper(this)
621 : : {
622 : 40 : }
623 : :
624 : : //---------------------------------------------------------------------------------------
625 : 0 : void SbaGridHeader::StartDrag( sal_Int8 _nAction, const Point& _rPosPixel )
626 : : {
627 [ # # ]: 0 : SolarMutexGuard aGuard;
628 : : // in the new DnD API, the solar mutex is not locked when StartDrag get's called
629 : :
630 [ # # ][ # # ]: 0 : ImplStartColumnDrag( _nAction, _rPosPixel );
631 : 0 : }
632 : :
633 : : //---------------------------------------------------------------------------------------
634 : 0 : void SbaGridHeader::MouseButtonDown( const MouseEvent& _rMEvt )
635 : : {
636 [ # # ]: 0 : if (_rMEvt.IsLeft())
637 : 0 : if (_rMEvt.GetClicks() != 2)
638 : : {
639 : : // the base class will start a column move here, which we don't want to allow
640 : : // (at the moment. If we store relative positions with the columns, we can allow column moves ....)
641 : :
642 : : }
643 : :
644 : 0 : FmGridHeader::MouseButtonDown(_rMEvt);
645 : 0 : }
646 : :
647 : : //---------------------------------------------------------------------------------------
648 : 0 : sal_Bool SbaGridHeader::ImplStartColumnDrag(sal_Int8 _nAction, const Point& _rMousePos)
649 : : {
650 : 0 : sal_uInt16 nId = GetItemId(_rMousePos);
651 : 0 : sal_Bool bResizingCol = sal_False;
652 [ # # ]: 0 : if (HEADERBAR_ITEM_NOTFOUND != nId)
653 : : {
654 [ # # ]: 0 : Rectangle aColRect = GetItemRect(nId);
655 [ # # ]: 0 : aColRect.Left() += nId ? 3 : 0; // the handle col (nId == 0) does not have a left margin for resizing
656 : 0 : aColRect.Right() -= 3;
657 [ # # ]: 0 : bResizingCol = !aColRect.IsInside(_rMousePos);
658 : : }
659 [ # # ]: 0 : if (!bResizingCol)
660 : : {
661 : : // force the the base class to end it's drag mode
662 : 0 : EndTracking(ENDTRACK_CANCEL | ENDTRACK_END);
663 : :
664 : : // because we have 3d-buttons the select handler is called from MouseButtonUp, but StartDrag
665 : : // occures earlier (while the mouse button is down)
666 : : // so for optical reasons we select the column before really starting the drag operation.
667 : 0 : notifyColumnSelect(nId);
668 : :
669 : 0 : static_cast<SbaGridControl*>(GetParent())->StartDrag(_nAction,
670 : : Point(
671 [ # # ]: 0 : _rMousePos.X() + GetPosPixel().X(), // we aren't left-justified with our parent, in contrast to the data window
672 : 0 : _rMousePos.Y() - GetSizePixel().Height()
673 : : )
674 [ # # ]: 0 : );
675 : 0 : return sal_True;
676 : : }
677 : :
678 : 0 : return sal_False;
679 : : }
680 : :
681 : : //---------------------------------------------------------------------------------------
682 : 0 : void SbaGridHeader::PreExecuteColumnContextMenu(sal_uInt16 nColId, PopupMenu& rMenu)
683 : : {
684 : 0 : FmGridHeader::PreExecuteColumnContextMenu(nColId, rMenu);
685 : :
686 : : // some items are valid only if the db isn't readonly
687 : 0 : sal_Bool bDBIsReadOnly = ((SbaGridControl*)GetParent())->IsReadOnlyDB();
688 : :
689 [ # # ]: 0 : if (bDBIsReadOnly)
690 : : {
691 : 0 : rMenu.EnableItem(SID_FM_HIDECOL, sal_False);
692 : 0 : PopupMenu* pShowColsMenu = rMenu.GetPopupMenu(SID_FM_SHOWCOLS);
693 [ # # ]: 0 : if (pShowColsMenu)
694 : : {
695 : : // at most 16 items which mean "show column <name>"
696 [ # # ]: 0 : for (sal_uInt16 i=1; i<16; ++i)
697 : 0 : pShowColsMenu->EnableItem(i, sal_False);
698 : : // "show cols/more..." and "show cols/all"
699 : 0 : pShowColsMenu->EnableItem(SID_FM_SHOWCOLS_MORE, sal_False);
700 : 0 : pShowColsMenu->EnableItem(SID_FM_SHOWALLCOLS, sal_False);
701 : : }
702 : : }
703 : :
704 : : // prepend some new items
705 [ # # ][ # # ]: 0 : sal_Bool bColAttrs = (nColId != (sal_uInt16)-1) && (nColId != 0);
706 [ # # ][ # # ]: 0 : if ( bColAttrs && !bDBIsReadOnly)
707 : : {
708 [ # # ][ # # ]: 0 : PopupMenu aNewItems(ModuleRes(RID_SBA_GRID_COLCTXMENU));
709 : 0 : sal_uInt16 nPos = 0;
710 [ # # ][ # # ]: 0 : sal_uInt16 nModelPos = ((SbaGridControl*)GetParent())->GetModelColumnPos(nColId);
711 [ # # ][ # # ]: 0 : Reference< XPropertySet > xField = ((SbaGridControl*)GetParent())->getField(nModelPos);
712 : :
713 [ # # ]: 0 : if ( xField.is() )
714 : : {
715 [ # # ][ # # ]: 0 : switch( ::comphelper::getINT32(xField->getPropertyValue(PROPERTY_TYPE)) )
[ # # ][ # # ]
[ # # ]
716 : : {
717 : : case DataType::BINARY:
718 : : case DataType::VARBINARY:
719 : : case DataType::LONGVARBINARY:
720 : : case DataType::SQLNULL:
721 : : case DataType::OBJECT:
722 : : case DataType::BLOB:
723 : : case DataType::CLOB:
724 : : case DataType::REF:
725 : 0 : break;
726 : : default:
727 [ # # ][ # # ]: 0 : rMenu.InsertItem(ID_BROWSER_COLATTRSET, aNewItems.GetItemText(ID_BROWSER_COLATTRSET), 0, nPos++);
[ # # ]
728 [ # # ][ # # ]: 0 : rMenu.SetHelpId(ID_BROWSER_COLATTRSET, aNewItems.GetHelpId(ID_BROWSER_COLATTRSET));
729 [ # # ]: 0 : rMenu.InsertSeparator(nPos++);
730 : : }
731 : : }
732 : :
733 [ # # ][ # # ]: 0 : rMenu.InsertItem(ID_BROWSER_COLWIDTH, aNewItems.GetItemText(ID_BROWSER_COLWIDTH), 0, nPos++);
[ # # ]
734 [ # # ][ # # ]: 0 : rMenu.SetHelpId(ID_BROWSER_COLWIDTH, aNewItems.GetHelpId(ID_BROWSER_COLWIDTH));
735 [ # # ][ # # ]: 0 : rMenu.InsertSeparator(nPos++);
736 : : }
737 : 0 : }
738 : :
739 : : //---------------------------------------------------------------------------------------
740 : 0 : void SbaGridHeader::PostExecuteColumnContextMenu(sal_uInt16 nColId, const PopupMenu& rMenu, sal_uInt16 nExecutionResult)
741 : : {
742 [ # # # # ]: 0 : switch (nExecutionResult)
743 : : {
744 : : case ID_BROWSER_COLWIDTH:
745 : 0 : ((SbaGridControl*)GetParent())->SetColWidth(nColId);
746 : 0 : break;
747 : :
748 : : case ID_BROWSER_COLATTRSET:
749 : 0 : ((SbaGridControl*)GetParent())->SetColAttrs(nColId);
750 : 0 : break;
751 : : case ID_BROWSER_COLUMNINFO:
752 : : {
753 [ # # ][ # # ]: 0 : sal_uInt16 nModelPos = ((SbaGridControl*)GetParent())->GetModelColumnPos(nColId);
754 [ # # ][ # # ]: 0 : Reference< XPropertySet > xField = ((SbaGridControl*)GetParent())->getField(nModelPos);
755 : :
756 [ # # ]: 0 : if(!xField.is())
757 : : break;
758 [ # # ]: 0 : ::std::vector< ::boost::shared_ptr<OTableRow> > vClipboardList;
759 : : // send it to the clipboard
760 [ # # ][ # # ]: 0 : vClipboardList.push_back(::boost::shared_ptr<OTableRow>(new OTableRow(xField)));
[ # # ][ # # ]
[ # # ]
761 [ # # ]: 0 : OTableRowExchange* pData = new OTableRowExchange(vClipboardList);
762 [ # # ][ # # ]: 0 : Reference< ::com::sun::star::datatransfer::XTransferable> xRef = pData;
763 [ # # ][ # # ]: 0 : pData->CopyToClipboard(GetParent());
[ # # ]
764 : : }
765 : 0 : break;
766 : :
767 : 0 : default: FmGridHeader::PostExecuteColumnContextMenu(nColId, rMenu, nExecutionResult);
768 : : }
769 : 0 : }
770 : :
771 : : //==================================================================
772 : : // SbaGridControl
773 : : //==================================================================
774 : : DBG_NAME(SbaGridControl );
775 : : //---------------------------------------------------------------------------------------
776 : 40 : SbaGridControl::SbaGridControl(Reference< XMultiServiceFactory > _rM,
777 : : Window* pParent, FmXGridPeer* _pPeer, WinBits nBits)
778 : : :FmGridControl(_rM,pParent, _pPeer, nBits)
779 : : ,m_pMasterListener(NULL)
780 : : ,m_nAsyncDropEvent(0)
781 : : ,m_nCurrentActionColId((sal_uInt16)-1)
782 [ + - ][ + - ]: 40 : ,m_bActivatingForDrop(sal_False)
783 : : {
784 : : DBG_CTOR(SbaGridControl ,NULL);
785 : 40 : }
786 : :
787 : : //---------------------------------------------------------------------------------------
788 [ + - ]: 40 : SbaGridControl::~SbaGridControl()
789 : : {
790 : : DBG_DTOR(SbaGridControl ,NULL);
791 [ - + ]: 40 : if (m_nAsyncDropEvent)
792 [ # # ]: 0 : Application::RemoveUserEvent(m_nAsyncDropEvent);
793 [ - + ]: 80 : }
794 : :
795 : : //---------------------------------------------------------------------------------------
796 : 40 : BrowserHeader* SbaGridControl::imp_CreateHeaderBar(BrowseBox* pParent)
797 : : {
798 [ + - ]: 40 : return new SbaGridHeader(pParent);
799 : : }
800 : :
801 : : //---------------------------------------------------------------------------------------
802 : 0 : CellController* SbaGridControl::GetController(long nRow, sal_uInt16 nCol)
803 : : {
804 [ # # ]: 0 : if ( m_bActivatingForDrop )
805 : 0 : return NULL;
806 : :
807 : 0 : return FmGridControl::GetController(nRow, nCol);
808 : : }
809 : :
810 : : //---------------------------------------------------------------------------------------
811 : 0 : void SbaGridControl::PreExecuteRowContextMenu(sal_uInt16 nRow, PopupMenu& rMenu)
812 : : {
813 [ # # ]: 0 : FmGridControl::PreExecuteRowContextMenu(nRow, rMenu);
814 : :
815 [ # # ][ # # ]: 0 : PopupMenu aNewItems(ModuleRes(RID_SBA_GRID_ROWCTXMENU));
816 : 0 : sal_uInt16 nPos = 0;
817 : :
818 [ # # ][ # # ]: 0 : if (!IsReadOnlyDB())
819 : : {
820 [ # # ][ # # ]: 0 : rMenu.InsertItem(ID_BROWSER_TABLEATTR, aNewItems.GetItemText(ID_BROWSER_TABLEATTR), 0, nPos++);
[ # # ]
821 [ # # ][ # # ]: 0 : rMenu.SetHelpId(ID_BROWSER_TABLEATTR, aNewItems.GetHelpId(ID_BROWSER_TABLEATTR));
822 : :
823 [ # # ][ # # ]: 0 : rMenu.InsertItem(ID_BROWSER_ROWHEIGHT, aNewItems.GetItemText(ID_BROWSER_ROWHEIGHT), 0, nPos++);
[ # # ]
824 [ # # ][ # # ]: 0 : rMenu.SetHelpId(ID_BROWSER_ROWHEIGHT, aNewItems.GetHelpId(ID_BROWSER_ROWHEIGHT));
825 [ # # ]: 0 : rMenu.InsertSeparator(nPos++);
826 : : }
827 : :
828 [ # # ][ # # ]: 0 : if ( GetSelectRowCount() > 0 )
829 : : {
830 [ # # ][ # # ]: 0 : rMenu.InsertItem(ID_BROWSER_COPY, aNewItems.GetItemText(SID_COPY), 0, nPos++);
[ # # ]
831 [ # # ][ # # ]: 0 : rMenu.SetHelpId(ID_BROWSER_COPY, aNewItems.GetHelpId(SID_COPY));
832 : :
833 [ # # ]: 0 : rMenu.InsertSeparator(nPos++);
834 [ # # ]: 0 : }
835 : 0 : }
836 : :
837 : : //------------------------------------------------------------------------------
838 : 0 : SvNumberFormatter* SbaGridControl::GetDatasourceFormatter()
839 : : {
840 [ # # ][ # # ]: 0 : Reference< ::com::sun::star::util::XNumberFormatsSupplier > xSupplier = ::dbtools::getNumberFormats(::dbtools::getConnection(Reference< XRowSet > (getDataSource(),UNO_QUERY)), sal_True,getServiceManager());
[ # # ][ # # ]
[ # # ]
841 : :
842 [ # # ]: 0 : SvNumberFormatsSupplierObj* pSupplierImpl = SvNumberFormatsSupplierObj::getImplementation( xSupplier );
843 [ # # ]: 0 : if ( !pSupplierImpl )
844 : 0 : return NULL;
845 : :
846 [ # # ]: 0 : SvNumberFormatter* pFormatter = pSupplierImpl->GetNumberFormatter();
847 : 0 : return pFormatter;
848 : : }
849 : :
850 : : //------------------------------------------------------------------------------
851 : 0 : void SbaGridControl::SetColWidth(sal_uInt16 nColId)
852 : : {
853 : : // get the (UNO) column model
854 [ # # ]: 0 : sal_uInt16 nModelPos = GetModelColumnPos(nColId);
855 [ # # ][ # # ]: 0 : Reference< XIndexAccess > xCols(GetPeer()->getColumns(), UNO_QUERY);
856 : 0 : Reference< XPropertySet > xAffectedCol;
857 [ # # ][ # # ]: 0 : if (xCols.is() && (nModelPos != (sal_uInt16)-1))
[ # # ]
858 [ # # ][ # # ]: 0 : ::cppu::extractInterface(xAffectedCol,xCols->getByIndex(nModelPos));
[ # # ]
859 : :
860 [ # # ]: 0 : if (xAffectedCol.is())
861 : : {
862 [ # # ][ # # ]: 0 : Any aWidth = xAffectedCol->getPropertyValue(PROPERTY_WIDTH);
[ # # ]
863 [ # # ][ # # ]: 0 : sal_Int32 nCurWidth = aWidth.hasValue() ? ::comphelper::getINT32(aWidth) : -1;
864 : :
865 [ # # ]: 0 : DlgSize aDlgColWidth(this, nCurWidth, sal_False);
866 [ # # ][ # # ]: 0 : if (aDlgColWidth.Execute())
867 : : {
868 [ # # ]: 0 : sal_Int32 nValue = aDlgColWidth.GetValue();
869 : 0 : Any aNewWidth;
870 [ # # ]: 0 : if (-1 == nValue)
871 : : { // set to default
872 [ # # ]: 0 : Reference< XPropertyState > xPropState(xAffectedCol, UNO_QUERY);
873 [ # # ]: 0 : if (xPropState.is())
874 : : {
875 [ # # ][ # # ]: 0 : try { aNewWidth = xPropState->getPropertyDefault(PROPERTY_WIDTH); } catch(Exception&) { } ;
[ # # ]
[ # # # # ]
876 : 0 : }
877 : : }
878 : : else
879 [ # # ]: 0 : aNewWidth <<= nValue;
880 [ # # ][ # # ]: 0 : try { xAffectedCol->setPropertyValue(PROPERTY_WIDTH, aNewWidth); } catch(Exception&) { } ;
[ # # ]
[ # # # # ]
881 [ # # ]: 0 : }
882 : 0 : }
883 : 0 : }
884 : :
885 : : //------------------------------------------------------------------------------
886 : 0 : void SbaGridControl::SetRowHeight()
887 : : {
888 [ # # ][ # # ]: 0 : Reference< XPropertySet > xCols(GetPeer()->getColumns(), UNO_QUERY);
889 [ # # ]: 0 : if (!xCols.is())
890 : 0 : return;
891 : :
892 [ # # ][ # # ]: 0 : Any aHeight = xCols->getPropertyValue(PROPERTY_ROW_HEIGHT);
[ # # ]
893 [ # # ][ # # ]: 0 : sal_Int32 nCurHeight = aHeight.hasValue() ? ::comphelper::getINT32(aHeight) : -1;
894 : :
895 [ # # ]: 0 : DlgSize aDlgRowHeight(this, nCurHeight, sal_True);
896 [ # # ][ # # ]: 0 : if (aDlgRowHeight.Execute())
897 : : {
898 [ # # ]: 0 : sal_Int32 nValue = aDlgRowHeight.GetValue();
899 : 0 : Any aNewHeight;
900 [ # # ]: 0 : if ((sal_Int16)-1 == nValue)
901 : : { // set to default
902 [ # # ]: 0 : Reference< XPropertyState > xPropState(xCols, UNO_QUERY);
903 [ # # ]: 0 : if (xPropState.is())
904 : : {
905 : : try
906 : : {
907 [ # # ][ # # ]: 0 : aNewHeight = xPropState->getPropertyDefault(PROPERTY_ROW_HEIGHT);
[ # # ][ # # ]
908 : : }
909 [ # # ]: 0 : catch(Exception&)
910 : : { }
911 : 0 : }
912 : : }
913 : : else
914 [ # # ]: 0 : aNewHeight <<= nValue;
915 : : try
916 : : {
917 [ # # ][ # # ]: 0 : xCols->setPropertyValue(PROPERTY_ROW_HEIGHT, aNewHeight);
[ # # ][ # # ]
918 : : }
919 [ # # ]: 0 : catch(Exception&)
920 : : {
921 : : OSL_FAIL("setPropertyValue: PROPERTY_ROW_HEIGHT throws a exception");
922 : 0 : }
923 [ # # ][ # # ]: 0 : }
924 : : }
925 : :
926 : : //------------------------------------------------------------------------------
927 : 0 : void SbaGridControl::SetColAttrs(sal_uInt16 nColId)
928 : : {
929 [ # # ]: 0 : SvNumberFormatter* pFormatter = GetDatasourceFormatter();
930 [ # # ]: 0 : if (!pFormatter)
931 : 0 : return;
932 : :
933 [ # # ]: 0 : sal_uInt16 nModelPos = GetModelColumnPos(nColId);
934 : :
935 : : // get the (UNO) column model
936 [ # # ][ # # ]: 0 : Reference< XIndexAccess > xCols(GetPeer()->getColumns(), UNO_QUERY);
937 : 0 : Reference< XPropertySet > xAffectedCol;
938 [ # # ][ # # ]: 0 : if (xCols.is() && (nModelPos != (sal_uInt16)-1))
[ # # ]
939 [ # # ][ # # ]: 0 : ::cppu::extractInterface(xAffectedCol,xCols->getByIndex(nModelPos));
[ # # ]
940 : :
941 : : // get the field the column is bound to
942 [ # # ]: 0 : Reference< XPropertySet > xField = getField(nModelPos);
943 [ # # ]: 0 : ::dbaui::callColumnFormatDialog(xAffectedCol,xField,pFormatter,this);//(Window::GetSettings().GetLanguage());
944 : : }
945 : :
946 : :
947 : : //------------------------------------------------------------------------------
948 : 0 : void SbaGridControl::SetBrowserAttrs()
949 : : {
950 [ # # ][ # # ]: 0 : Reference< XPropertySet > xGridModel(GetPeer()->getColumns(), UNO_QUERY);
951 [ # # ]: 0 : if (!xGridModel.is())
952 : : return;
953 : :
954 : : try
955 : : {
956 : 0 : PropertyValue aArg;
957 [ # # ]: 0 : aArg.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IntrospectedObject"));
958 [ # # ]: 0 : aArg.Value <<= xGridModel;
959 [ # # ]: 0 : Sequence< Any > aDialogArgs(1);
960 [ # # ][ # # ]: 0 : aDialogArgs[0] <<= aArg;
961 : :
962 [ # # ][ # # ]: 0 : Reference< XInterface > xDialog = getServiceManager()->createInstanceWithArguments(
963 : : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.ControlFontDialog")),
964 : : aDialogArgs
965 [ # # ][ # # ]: 0 : );
966 [ # # ]: 0 : if (!xDialog.is())
967 : : {
968 [ # # ][ # # ]: 0 : ShowServiceNotAvailableError(this, rtl::OUString("com.sun.star.form.ControlFontDialog"), sal_True);
[ # # ]
969 : : return;
970 : : }
971 : :
972 [ # # ]: 0 : Reference< XExecutableDialog > xExecute(xDialog, UNO_QUERY);
973 : : OSL_ENSURE(xExecute.is(), "SbaGridControl::SetBrowserAttrs: missing an interface on the dialog!");
974 [ # # ]: 0 : if (xExecute.is())
975 [ # # ][ # # ]: 0 : xExecute->execute();
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
976 : : }
977 [ # # ]: 0 : catch( const Exception& )
978 : : {
979 : : DBG_UNHANDLED_EXCEPTION();
980 [ # # ]: 0 : }
981 : : }
982 : :
983 : : //---------------------------------------------------------------------------------------
984 : 0 : void SbaGridControl::PostExecuteRowContextMenu(sal_uInt16 nRow, const PopupMenu& rMenu, sal_uInt16 nExecutionResult)
985 : : {
986 [ # # # # ]: 0 : switch (nExecutionResult)
987 : : {
988 : : case ID_BROWSER_TABLEATTR:
989 : 0 : SetBrowserAttrs();
990 : 0 : break;
991 : : case ID_BROWSER_ROWHEIGHT:
992 : 0 : SetRowHeight();
993 : 0 : break;
994 : : case ID_BROWSER_COPY:
995 : 0 : CopySelectedRowsToClipboard();
996 : 0 : break;
997 : :
998 : : default:
999 : 0 : FmGridControl::PostExecuteRowContextMenu(nRow, rMenu, nExecutionResult);
1000 : 0 : break;
1001 : : }
1002 : 0 : }
1003 : :
1004 : : //---------------------------------------------------------------------------------------
1005 : 0 : void SbaGridControl::Select()
1006 : : {
1007 : : // Some selection has changed ...
1008 : 0 : FmGridControl::Select();
1009 : :
1010 [ # # ]: 0 : if (m_pMasterListener)
1011 : 0 : m_pMasterListener->SelectionChanged();
1012 : 0 : }
1013 : :
1014 : : //---------------------------------------------------------------------------------------
1015 : 75 : void SbaGridControl::CursorMoved()
1016 : : {
1017 : 75 : FmGridControl::CursorMoved();
1018 : 75 : }
1019 : :
1020 : : //---------------------------------------------------------------------------------------
1021 : 75 : void SbaGridControl::ActivateCell(long nRow, sal_uInt16 nCol, sal_Bool bSetCellFocus /*= sal_True*/ )
1022 : : {
1023 : 75 : FmGridControl::ActivateCell(nRow, nCol, bSetCellFocus);
1024 [ + + ]: 75 : if (m_pMasterListener)
1025 : 10 : m_pMasterListener->CellActivated();
1026 : 75 : }
1027 : :
1028 : : //---------------------------------------------------------------------------------------
1029 : 26 : void SbaGridControl::DeactivateCell(sal_Bool bUpdate /*= sal_True*/)
1030 : : {
1031 : 26 : FmGridControl::DeactivateCell(bUpdate);
1032 [ + + ]: 26 : if (m_pMasterListener)
1033 : 4 : m_pMasterListener->CellDeactivated();
1034 : 26 : }
1035 : :
1036 : : //---------------------------------------------------------------------------------------
1037 : 4 : void SbaGridControl::onRowChange()
1038 : : {
1039 [ + - ]: 4 : if ( m_pMasterListener )
1040 : 4 : m_pMasterListener->RowChanged();
1041 : 4 : }
1042 : :
1043 : : //---------------------------------------------------------------------------------------
1044 : 2 : void SbaGridControl::onColumnChange()
1045 : : {
1046 [ + - ]: 2 : if ( m_pMasterListener )
1047 : 2 : m_pMasterListener->ColumnChanged();
1048 : 2 : }
1049 : :
1050 : : //---------------------------------------------------------------------------------------
1051 : 0 : void SbaGridControl::BeforeDrop()
1052 : : {
1053 [ # # ]: 0 : if (m_pMasterListener)
1054 : 0 : m_pMasterListener->BeforeDrop();
1055 : 0 : }
1056 : : //---------------------------------------------------------------------------------------
1057 : 0 : void SbaGridControl::AfterDrop()
1058 : : {
1059 [ # # ]: 0 : if (m_pMasterListener)
1060 : 0 : m_pMasterListener->AfterDrop();
1061 : 0 : }
1062 : :
1063 : :
1064 : : //------------------------------------------------------------------------------
1065 : 0 : Reference< XPropertySet > SbaGridControl::getField(sal_uInt16 nModelPos)
1066 : : {
1067 : 0 : Reference< XPropertySet > xEmptyReturn;
1068 : : try
1069 : : {
1070 : : // first get the name of the column
1071 [ # # ][ # # ]: 0 : Reference< XIndexAccess > xCols(GetPeer()->getColumns(), UNO_QUERY);
1072 [ # # ][ # # ]: 0 : if ( xCols.is() && xCols->getCount() > nModelPos )
[ # # ][ # # ]
[ # # ]
1073 : : {
1074 [ # # ][ # # ]: 0 : Reference< XPropertySet > xCol(xCols->getByIndex(nModelPos),UNO_QUERY);
[ # # ]
1075 [ # # ]: 0 : if ( xCol.is() )
1076 [ # # ][ # # ]: 0 : xEmptyReturn.set(xCol->getPropertyValue(PROPERTY_BOUNDFIELD),UNO_QUERY);
[ # # ][ # # ]
1077 : : }
1078 : : else
1079 [ # # ]: 0 : OSL_FAIL("SbaGridControl::getField getColumns returns NULL or ModelPos is > than count!");
1080 : : }
1081 [ # # ]: 0 : catch(Exception&)
1082 : : {
1083 : : OSL_FAIL("SbaGridControl::getField Exception occurred!");
1084 : : }
1085 : :
1086 : 0 : return xEmptyReturn;
1087 : : }
1088 : :
1089 : : //---------------------------------------------------------------------------------------
1090 : 0 : sal_Bool SbaGridControl::IsReadOnlyDB() const
1091 : : {
1092 : : // assume yes if anything fails
1093 : 0 : sal_Bool bDBIsReadOnly = sal_True;
1094 : :
1095 : : // the db is the implemented by the parent of the grid control's model ...
1096 [ # # ][ # # ]: 0 : Reference< XChild > xColumns(GetPeer()->getColumns(), UNO_QUERY);
1097 [ # # ]: 0 : if (xColumns.is())
1098 : : {
1099 [ # # ][ # # ]: 0 : Reference< XRowSet > xDataSource(xColumns->getParent(), UNO_QUERY);
[ # # ]
1100 [ # # ][ # # ]: 0 : Reference< XChild > xConn(::dbtools::getConnection(xDataSource),UNO_QUERY);
1101 [ # # ]: 0 : if (xConn.is())
1102 : : {
1103 : : // ... and the RO-flag simply is implemented by a property
1104 [ # # ][ # # ]: 0 : Reference< XPropertySet > xDbProps(xConn->getParent(), UNO_QUERY);
[ # # ]
1105 [ # # ]: 0 : if (xDbProps.is())
1106 : : {
1107 [ # # ][ # # ]: 0 : Reference< XPropertySetInfo > xInfo = xDbProps->getPropertySetInfo();
1108 [ # # ][ # # ]: 0 : if (xInfo->hasPropertyByName(PROPERTY_ISREADONLY))
[ # # ][ # # ]
1109 [ # # ][ # # ]: 0 : bDBIsReadOnly = ::comphelper::getBOOL(xDbProps->getPropertyValue(PROPERTY_ISREADONLY));
[ # # ][ # # ]
1110 : 0 : }
1111 : 0 : }
1112 : : }
1113 : 0 : return bDBIsReadOnly;
1114 : : }
1115 : :
1116 : : //---------------------------------------------------------------------------------------
1117 : 0 : void SbaGridControl::MouseButtonDown( const BrowserMouseEvent& rMEvt)
1118 : : {
1119 : 0 : long nRow = GetRowAtYPosPixel(rMEvt.GetPosPixel().Y());
1120 : 0 : sal_uInt16 nColPos = GetColumnAtXPosPixel(rMEvt.GetPosPixel().X());
1121 [ # # ]: 0 : sal_uInt16 nViewPos = (nColPos == BROWSER_INVALIDID) ? (sal_uInt16)-1 : nColPos-1;
1122 : : // 'the handle column' and 'no valid column' will both result in a view position of -1 !
1123 : :
1124 [ # # ][ # # ]: 0 : sal_Bool bHitEmptySpace = (nRow > GetRowCount()) || (nViewPos == (sal_uInt16)-1);
1125 : :
1126 [ # # ][ # # ]: 0 : if (bHitEmptySpace && (rMEvt.GetClicks() == 2) && rMEvt.IsMod1())
[ # # ][ # # ]
1127 : 0 : Control::MouseButtonDown(rMEvt);
1128 : : else
1129 : 0 : FmGridControl::MouseButtonDown(rMEvt);
1130 : 0 : }
1131 : :
1132 : : //---------------------------------------------------------------------------------------
1133 : 0 : void SbaGridControl::StartDrag( sal_Int8 _nAction, const Point& _rPosPixel )
1134 : : {
1135 [ # # ]: 0 : SolarMutexGuard aGuard;
1136 : : // in the new DnD API, the solar mutex is not locked when StartDrag get's called
1137 : :
1138 : 0 : sal_Bool bHandled = sal_False;
1139 : :
1140 : : do
1141 : : {
1142 : : // determine if dragging is allowed
1143 : : // (Yes, this is controller (not view) functionality. But collecting and evaluating all the
1144 : : // informations necessary via UNO would be quite difficult (if not impossible) so
1145 : : // my laziness says 'do it here' ...)
1146 [ # # ]: 0 : long nRow = GetRowAtYPosPixel(_rPosPixel.Y());
1147 [ # # ]: 0 : sal_uInt16 nColPos = GetColumnAtXPosPixel(_rPosPixel.X());
1148 [ # # ]: 0 : sal_uInt16 nViewPos = (nColPos == BROWSER_INVALIDID) ? (sal_uInt16)-1 : nColPos-1;
1149 : : // 'the handle column' and 'no valid column' will both result in a view position of -1 !
1150 : :
1151 [ # # ][ # # ]: 0 : sal_Bool bCurrentRowVirtual = IsCurrentAppending() && IsModified();
[ # # ][ # # ]
1152 : : // the current row doesn't really exist : the user's appendign a new one and already has entered some data,
1153 : : // so the row contains data which has no counter part within the data source
1154 : :
1155 [ # # ]: 0 : long nCorrectRowCount = GetRowCount();
1156 [ # # ]: 0 : if (GetOptions() & OPT_INSERT)
1157 : 0 : --nCorrectRowCount; // there is a empty row for inserting records
1158 [ # # ]: 0 : if (bCurrentRowVirtual)
1159 : 0 : --nCorrectRowCount;
1160 : :
1161 [ # # ][ # # ]: 0 : if ((nColPos == BROWSER_INVALIDID) || (nRow >= nCorrectRowCount))
1162 : 0 : break;
1163 : :
1164 : 0 : sal_Bool bHitHandle = (nColPos == 0);
1165 : :
1166 : : // check which kind of dragging has to be initiated
1167 [ # # ][ # # ]: 0 : if ( bHitHandle // the handle column
[ # # ]
[ # # # # ]
[ # # ][ # # ]
[ # # ]
1168 : : // AND
1169 [ # # ]: 0 : && ( GetSelectRowCount() // at least one row is selected
1170 : : // OR
1171 : : || ( (nRow >= 0) // a row below the header
1172 : : && !bCurrentRowVirtual // we aren't appending a new record
1173 : 0 : && (nRow != GetCurrentPos()) // a row which is not the current one
1174 : : ) // OR
1175 [ # # ]: 0 : || ( (0 == GetSelectRowCount()) // no rows selected
1176 : : && (-1 == nRow) // hit the header
1177 : : )
1178 : : )
1179 : : )
1180 : : { // => start dragging the row
1181 [ # # ][ # # ]: 0 : if (GetDataWindow().IsMouseCaptured())
1182 [ # # ]: 0 : GetDataWindow().ReleaseMouse();
1183 : :
1184 [ # # ][ # # ]: 0 : if (0 == GetSelectRowCount())
1185 : : // no rows selected, but here in this branch
1186 : : // -> the user started dragging the upper left corner, which symbolizes the whole table
1187 [ # # ]: 0 : SelectAll();
1188 : :
1189 [ # # ]: 0 : getMouseEvent().Clear();
1190 [ # # ]: 0 : DoRowDrag((sal_Int16)nRow);
1191 : :
1192 : 0 : bHandled = sal_True;
1193 : : }
1194 [ # # ][ # # ]: 0 : else if ( (nRow < 0) // the header
[ # # ][ # # ]
1195 : : && (!bHitHandle) // non-handle column
1196 [ # # ]: 0 : && (nViewPos < GetViewColCount()) // valid (existing) column
1197 : : )
1198 : : { // => start dragging the column
1199 [ # # ][ # # ]: 0 : if (GetDataWindow().IsMouseCaptured())
1200 [ # # ]: 0 : GetDataWindow().ReleaseMouse();
1201 : :
1202 [ # # ]: 0 : getMouseEvent().Clear();
1203 [ # # ]: 0 : DoColumnDrag(nViewPos);
1204 : :
1205 : 0 : bHandled = sal_True;
1206 : : }
1207 [ # # ][ # # ]: 0 : else if ( !bHitHandle // non-handle column
1208 : : && (nRow >= 0) // non-header row
1209 : : )
1210 : : { // => start dragging the field content
1211 [ # # ][ # # ]: 0 : if (GetDataWindow().IsMouseCaptured())
1212 [ # # ]: 0 : GetDataWindow().ReleaseMouse();
1213 : :
1214 [ # # ]: 0 : getMouseEvent().Clear();
1215 [ # # ]: 0 : DoFieldDrag(nViewPos, (sal_Int16)nRow);
1216 : :
1217 : 0 : bHandled = sal_True;
1218 : : }
1219 : : }
1220 : : while (sal_False);
1221 : :
1222 [ # # ]: 0 : if (!bHandled)
1223 [ # # ][ # # ]: 0 : FmGridControl::StartDrag(_nAction, _rPosPixel);
1224 : 0 : }
1225 : :
1226 : : //------------------------------------------------------------------------------
1227 : 0 : void SbaGridControl::Command(const CommandEvent& rEvt)
1228 : : {
1229 : 0 : FmGridControl::Command(rEvt);
1230 : 0 : }
1231 : :
1232 : : // -----------------------------------------------------------------------
1233 : 0 : void SbaGridControl::DoColumnDrag(sal_uInt16 nColumnPos)
1234 : : {
1235 [ # # ][ # # ]: 0 : Reference< XPropertySet > xDataSource(getDataSource(), UNO_QUERY);
1236 : : OSL_ENSURE(xDataSource.is(), "SbaGridControl::DoColumnDrag : invalid data source !");
1237 : :
1238 : 0 : Reference< XPropertySet > xAffectedCol;
1239 : 0 : Reference< XPropertySet > xAffectedField;
1240 : 0 : Reference< XConnection > xActiveConnection;
1241 : :
1242 : : // determine the field to drag
1243 : 0 : ::rtl::OUString sField;
1244 : : try
1245 : : {
1246 [ # # ][ # # ]: 0 : xActiveConnection = ::dbtools::getConnection(Reference< XRowSet >(getDataSource(),UNO_QUERY));
[ # # ][ # # ]
1247 : :
1248 [ # # ][ # # ]: 0 : sal_uInt16 nModelPos = GetModelColumnPos(GetColumnIdFromViewPos(nColumnPos));
1249 [ # # ][ # # ]: 0 : Reference< XIndexContainer > xCols(GetPeer()->getColumns(), UNO_QUERY);
1250 [ # # ][ # # ]: 0 : xAffectedCol.set(xCols->getByIndex(nModelPos),UNO_QUERY);
[ # # ]
1251 [ # # ]: 0 : if (xAffectedCol.is())
1252 : : {
1253 [ # # ][ # # ]: 0 : xAffectedCol->getPropertyValue(PROPERTY_CONTROLSOURCE) >>= sField;
[ # # ]
1254 [ # # ][ # # ]: 0 : xAffectedField.set(xAffectedCol->getPropertyValue(PROPERTY_BOUNDFIELD),UNO_QUERY);
[ # # ][ # # ]
1255 [ # # ]: 0 : }
1256 : : }
1257 [ # # ]: 0 : catch(Exception&)
1258 : : {
1259 : : OSL_FAIL("SbaGridControl::DoColumnDrag : something went wrong while getting the column");
1260 : : }
1261 [ # # ]: 0 : if (sField.isEmpty())
1262 : 0 : return;
1263 : :
1264 [ # # ]: 0 : OColumnTransferable* pDataTransfer = new OColumnTransferable(xDataSource, sField, xAffectedField, xActiveConnection, CTF_FIELD_DESCRIPTOR | CTF_COLUMN_DESCRIPTOR);
1265 [ # # ][ # # ]: 0 : Reference< XTransferable > xEnsureDelete = pDataTransfer;
1266 [ # # ][ # # ]: 0 : pDataTransfer->StartDrag(this, DND_ACTION_COPY | DND_ACTION_LINK);
[ # # ][ # # ]
[ # # ][ # # ]
1267 : : }
1268 : :
1269 : : // -----------------------------------------------------------------------
1270 : 0 : void SbaGridControl::CopySelectedRowsToClipboard()
1271 : : {
1272 : : OSL_ENSURE( GetSelectRowCount() > 0, "SbaGridControl::CopySelectedRowsToClipboard: invalid call!" );
1273 : 0 : implTransferSelectedRows( (sal_Int16)FirstSelectedRow(), true );
1274 : 0 : }
1275 : :
1276 : : // -----------------------------------------------------------------------
1277 : 0 : void SbaGridControl::DoRowDrag( sal_Int16 nRowPos )
1278 : : {
1279 : 0 : implTransferSelectedRows( nRowPos, false );
1280 : 0 : }
1281 : :
1282 : : // -----------------------------------------------------------------------
1283 : 0 : void SbaGridControl::implTransferSelectedRows( sal_Int16 nRowPos, bool _bTrueIfClipboardFalseIfDrag )
1284 : : {
1285 [ # # ][ # # ]: 0 : Reference< XPropertySet > xForm( getDataSource(), UNO_QUERY );
1286 : : OSL_ENSURE( xForm.is(), "SbaGridControl::implTransferSelectedRows: invalid form!" );
1287 : :
1288 : : // build the sequence of numbers of selected rows
1289 [ # # ]: 0 : Sequence< Any > aSelectedRows;
1290 : 0 : sal_Bool bSelectionBookmarks = sal_True;
1291 : :
1292 : : // collect the affected rows
1293 [ # # ][ # # ]: 0 : if ((GetSelectRowCount() == 0) && (nRowPos >= 0))
[ # # ][ # # ]
1294 : : {
1295 [ # # ]: 0 : aSelectedRows.realloc( 1 );
1296 [ # # ][ # # ]: 0 : aSelectedRows[0] <<= (sal_Int32)(nRowPos + 1);
1297 : 0 : bSelectionBookmarks = sal_False;
1298 : : }
1299 [ # # ][ # # ]: 0 : else if ( !IsAllSelected() && GetSelectRowCount() )
[ # # ][ # # ]
[ # # ]
1300 : : {
1301 [ # # ][ # # ]: 0 : aSelectedRows = getSelectionBookmarks();
[ # # ]
1302 : 0 : bSelectionBookmarks = sal_True;
1303 : : }
1304 : :
1305 : 0 : Reference< XResultSet> xRowSetClone;
1306 : : try
1307 : : {
1308 [ # # ][ # # ]: 0 : ODataClipboard* pTransfer = new ODataClipboard( xForm, aSelectedRows, bSelectionBookmarks, getServiceManager() );
1309 : :
1310 [ # # ][ # # ]: 0 : Reference< XTransferable > xEnsureDelete = pTransfer;
1311 [ # # ]: 0 : if ( _bTrueIfClipboardFalseIfDrag )
1312 [ # # ]: 0 : pTransfer->CopyToClipboard( this );
1313 : : else
1314 [ # # ][ # # ]: 0 : pTransfer->StartDrag(this, DND_ACTION_COPY | DND_ACTION_LINK);
1315 : : }
1316 [ # # ]: 0 : catch(Exception&)
1317 : : {
1318 [ # # ]: 0 : }
1319 : 0 : }
1320 : :
1321 : : // -----------------------------------------------------------------------
1322 : 0 : void SbaGridControl::DoFieldDrag(sal_uInt16 nColumnPos, sal_Int16 nRowPos)
1323 : : {
1324 : : // the only thing to do here is dragging the pure cell text
1325 : : // the old implementation copied a SBA_FIELDDATAEXCHANGE_FORMAT, too, (which was rather expensive to obtain),
1326 : : // but we have no client for this DnD format anymore (the mail part of SO 5.2 was the only client)
1327 : :
1328 : 0 : ::rtl::OUString sCellText;
1329 : : try
1330 : : {
1331 [ # # ][ # # ]: 0 : Reference< XGridFieldDataSupplier > xFieldData(static_cast< XGridPeer* >(GetPeer()), UNO_QUERY);
1332 [ # # ][ # # ]: 0 : Sequence<sal_Bool> aSupportingText = xFieldData->queryFieldDataType(::getCppuType(&sCellText));
[ # # ]
1333 [ # # ]: 0 : if (aSupportingText.getConstArray()[nColumnPos])
1334 : : {
1335 [ # # ][ # # ]: 0 : Sequence< Any> aCellContents = xFieldData->queryFieldData(nRowPos, ::getCppuType(&sCellText));
[ # # ]
1336 [ # # ]: 0 : sCellText = ::comphelper::getString(aCellContents.getConstArray()[nColumnPos]);
1337 [ # # ][ # # ]: 0 : ::svt::OStringTransfer::StartStringDrag(sCellText, this, DND_ACTION_COPY);
1338 [ # # ][ # # ]: 0 : }
1339 : : }
1340 [ # # ]: 0 : catch(Exception&)
1341 : : {
1342 : : OSL_FAIL("SbaGridControl::DoFieldDrag : could not retrieve the cell's contents !");
1343 : 0 : return;
1344 [ # # ]: 0 : }
1345 : :
1346 : : }
1347 : : /// unary_function Functor object for class ZZ returntype is void
1348 : : struct SbaGridControlPrec : ::std::unary_function<DataFlavorExVector::value_type,bool>
1349 : : {
1350 : : sal_Bool bQueryDrop;
1351 : 0 : SbaGridControlPrec(sal_Bool _bQueryDrop)
1352 : 0 : : bQueryDrop(_bQueryDrop)
1353 : : {
1354 : 0 : }
1355 : :
1356 : 0 : inline bool operator()(const DataFlavorExVector::value_type& _aType)
1357 : : {
1358 [ # # ]: 0 : switch (_aType.mnSotId)
1359 : : {
1360 : : case SOT_FORMATSTR_ID_DBACCESS_TABLE: // table descriptor
1361 : : case SOT_FORMATSTR_ID_DBACCESS_QUERY: // query descriptor
1362 : : case SOT_FORMATSTR_ID_DBACCESS_COMMAND: // SQL command
1363 : 0 : return true;
1364 : : }
1365 : 0 : return false;
1366 : : }
1367 : : };
1368 : : //------------------------------------------------------------------------------
1369 : 0 : sal_Int8 SbaGridControl::AcceptDrop( const BrowserAcceptDropEvent& rEvt )
1370 : : {
1371 : 0 : sal_Int8 nAction = DND_ACTION_NONE;
1372 : :
1373 : : // we need a valid connection
1374 [ # # ][ # # ]: 0 : if (!::dbtools::getConnection(Reference< XRowSet > (getDataSource(),UNO_QUERY)).is())
[ # # ]
1375 : 0 : return nAction;
1376 : :
1377 [ # # ]: 0 : if ( IsDropFormatSupported( FORMAT_STRING ) ) do
1378 : : { // odd construction, but spares us a lot of (explicit ;) goto's
1379 : :
1380 [ # # ]: 0 : if (!GetEmptyRow().Is())
1381 : : // without an empty row we're not in update mode
1382 : : break;
1383 : :
1384 [ # # ]: 0 : long nRow = GetRowAtYPosPixel(rEvt.maPosPixel.Y(), sal_False);
1385 [ # # ]: 0 : sal_uInt16 nCol = GetColumnAtXPosPixel(rEvt.maPosPixel.X(), sal_False);
1386 : :
1387 [ # # ]: 0 : long nCorrectRowCount = GetRowCount();
1388 [ # # ]: 0 : if (GetOptions() & OPT_INSERT)
1389 : 0 : --nCorrectRowCount; // there is a empty row for inserting records
1390 [ # # ][ # # ]: 0 : if (IsCurrentAppending())
1391 : 0 : --nCorrectRowCount; // the current data record doesn't really exist, we are appending a new one
1392 : :
1393 [ # # ][ # # ]: 0 : if ((nCol == BROWSER_INVALIDID) || (nRow >= nCorrectRowCount) || GetColumnId(nCol) == 0 || GetColumnId(nCol) == BROWSER_INVALIDID )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
1394 : : // no valid cell under the mouse cursor
1395 : : break;
1396 : :
1397 [ # # ]: 0 : Rectangle aRect = GetCellRect(nRow, nCol, sal_False);
1398 [ # # ][ # # ]: 0 : if (!aRect.IsInside(rEvt.maPosPixel))
1399 : : // not dropped within a cell (a cell isn't as wide as the column - the are small spaces)
1400 : : break;
1401 : :
1402 [ # # ][ # # ]: 0 : if ((IsModified() || (GetCurrentRow().Is() && GetCurrentRow()->IsModified())) && (GetCurrentPos() != nRow))
[ # # ][ # # ]
[ # # ][ # # ]
1403 : : // there is a current and modified row or cell and he text is to be dropped into another one
1404 : : break;
1405 : :
1406 [ # # ]: 0 : CellControllerRef xCurrentController = Controller();
1407 [ # # ][ # # ]: 0 : if (xCurrentController.Is() && xCurrentController->IsModified() && ((nRow != GetCurRow()) || (nCol != GetCurColumnId())))
[ # # ][ # # ]
[ # # ][ # # ]
1408 : : // the current controller is modified and the user wants to drop in another cell -> no chance
1409 : : // (when leaving the modified cell a error may occur - this is deadly while dragging)
1410 : : break;
1411 : :
1412 [ # # ][ # # ]: 0 : Reference< XPropertySet > xField = getField(GetModelColumnPos(nCol));
1413 [ # # ]: 0 : if (!xField.is())
1414 : : // the column is not valid bound (for instance a binary field)
1415 : : break;
1416 : :
1417 : : try
1418 : : {
1419 [ # # ][ # # ]: 0 : if (::comphelper::getBOOL(xField->getPropertyValue(PROPERTY_ISREADONLY)))
[ # # ][ # # ]
[ # # ][ # # ]
1420 : : break;
1421 : : }
1422 [ # # ]: 0 : catch (const Exception& e )
1423 : : {
1424 : : (void)e; // make compiler happy
1425 : : // assume RO
1426 : : break;
1427 : : }
1428 : :
1429 : : try
1430 : : {
1431 : : // assume that text can be dropped into a field if the column has a ::com::sun::star::awt::XTextComponent interface
1432 [ # # ][ # # ]: 0 : Reference< XIndexAccess > xColumnControls((::com::sun::star::form::XGridPeer*)GetPeer(), UNO_QUERY);
1433 [ # # ]: 0 : if (xColumnControls.is())
1434 : : {
1435 : 0 : Reference< ::com::sun::star::awt::XTextComponent > xColControl;
1436 [ # # ][ # # ]: 0 : ::cppu::extractInterface(xColControl,xColumnControls->getByIndex(GetViewColumnPos(nCol)));
[ # # ][ # # ]
1437 [ # # ]: 0 : if (xColControl.is())
1438 : : {
1439 : 0 : m_bActivatingForDrop = sal_True;
1440 [ # # ]: 0 : GoToRowColumnId(nRow, nCol);
1441 : 0 : m_bActivatingForDrop = sal_False;
1442 : :
1443 : 0 : nAction = DND_ACTION_COPY;
1444 : 0 : }
1445 [ # # ]: 0 : }
1446 : : }
1447 [ # # ]: 0 : catch( const Exception& )
1448 : : {
1449 : : DBG_UNHANDLED_EXCEPTION();
1450 [ # # ][ # # ]: 0 : }
[ # # ]
1451 : :
1452 : : } while (sal_False);
1453 : :
1454 [ # # ][ # # ]: 0 : if(nAction != DND_ACTION_COPY && GetEmptyRow().Is())
[ # # ]
1455 : : {
1456 : 0 : const DataFlavorExVector& _rFlavors = GetDataFlavors();
1457 [ # # ][ # # ]: 0 : if(::std::find_if(_rFlavors.begin(),_rFlavors.end(),SbaGridControlPrec(sal_True)) != _rFlavors.end())
[ # # ]
1458 : 0 : nAction = DND_ACTION_COPY;
1459 : : }
1460 : :
1461 [ # # ]: 0 : return (DND_ACTION_NONE != nAction) ? nAction : FmGridControl::AcceptDrop(rEvt);
1462 : : }
1463 : :
1464 : : //------------------------------------------------------------------------------
1465 : 0 : sal_Int8 SbaGridControl::ExecuteDrop( const BrowserExecuteDropEvent& rEvt )
1466 : : {
1467 : : // we need some properties of our data source
1468 [ # # ]: 0 : Reference< XPropertySet > xDataSource = getDataSource();
1469 [ # # ]: 0 : if (!xDataSource.is())
1470 : 0 : return DND_ACTION_NONE;
1471 : :
1472 : : // we need a valid connection
1473 [ # # ][ # # ]: 0 : if (!::dbtools::getConnection(Reference< XRowSet > (xDataSource,UNO_QUERY)).is())
[ # # ]
1474 : 0 : return DND_ACTION_NONE;
1475 : :
1476 [ # # ][ # # ]: 0 : if ( IsDropFormatSupported( FORMAT_STRING ) )
1477 : : {
1478 [ # # ]: 0 : long nRow = GetRowAtYPosPixel(rEvt.maPosPixel.Y(), sal_False);
1479 [ # # ]: 0 : sal_uInt16 nCol = GetColumnAtXPosPixel(rEvt.maPosPixel.X(), sal_False);
1480 : :
1481 [ # # ]: 0 : long nCorrectRowCount = GetRowCount();
1482 [ # # ]: 0 : if (GetOptions() & OPT_INSERT)
1483 : 0 : --nCorrectRowCount; // there is a empty row for inserting records
1484 [ # # ][ # # ]: 0 : if (IsCurrentAppending())
1485 : 0 : --nCorrectRowCount; // the current data record doesn't really exist, we are appending a new one
1486 : :
1487 : : OSL_ENSURE((nCol != BROWSER_INVALIDID) && (nRow < nCorrectRowCount), "SbaGridControl::Drop : dropped on an invalid position !");
1488 : : // AcceptDrop should have caught this
1489 : :
1490 : : // from now we work with ids instead of positions
1491 [ # # ]: 0 : nCol = GetColumnId(nCol);
1492 : :
1493 [ # # ]: 0 : GoToRowColumnId(nRow, nCol);
1494 [ # # ]: 0 : if (!IsEditing())
1495 [ # # ]: 0 : ActivateCell();
1496 : :
1497 [ # # ]: 0 : CellControllerRef xCurrentController = Controller();
1498 [ # # ][ # # ]: 0 : if (!xCurrentController.Is() || !xCurrentController->ISA(EditCellController))
[ # # ][ # # ]
[ # # ]
1499 : 0 : return DND_ACTION_NONE;
1500 : 0 : Edit& rEdit = (Edit&)xCurrentController->GetWindow();
1501 : :
1502 : : // get the dropped string
1503 [ # # ]: 0 : TransferableDataHelper aDropped( rEvt.maDropEvent.Transferable );
1504 [ # # ]: 0 : String sDropped;
1505 [ # # ][ # # ]: 0 : if ( !aDropped.GetString( FORMAT_STRING, sDropped ) )
1506 : 0 : return DND_ACTION_NONE;
1507 : :
1508 [ # # ]: 0 : rEdit.SetText( sDropped );
1509 [ # # ]: 0 : xCurrentController->SetModified();
1510 [ # # ]: 0 : rEdit.Modify();
1511 : : // SetText itself doesn't call a Modify as it isn't a user interaction
1512 : :
1513 [ # # ][ # # ]: 0 : return DND_ACTION_COPY;
[ # # ]
1514 : : }
1515 : :
1516 [ # # ]: 0 : if(GetEmptyRow().Is())
1517 : : {
1518 [ # # ]: 0 : const DataFlavorExVector& _rFlavors = GetDataFlavors();
1519 [ # # ]: 0 : DataFlavorExVector::const_iterator aFind = ::std::find_if(_rFlavors.begin(),_rFlavors.end(),SbaGridControlPrec(sal_True));
1520 [ # # ][ # # ]: 0 : if( aFind != _rFlavors.end())
1521 : : {
1522 [ # # ]: 0 : TransferableDataHelper aDropped( rEvt.maDropEvent.Transferable );
1523 [ # # ][ # # ]: 0 : m_aDataDescriptor = ODataAccessObjectTransferable::extractObjectDescriptor(aDropped);
[ # # ]
1524 [ # # ]: 0 : if (m_nAsyncDropEvent)
1525 [ # # ]: 0 : Application::RemoveUserEvent(m_nAsyncDropEvent);
1526 [ # # ][ # # ]: 0 : m_nAsyncDropEvent = Application::PostUserEvent(LINK(this, SbaGridControl, AsynchDropEvent));
1527 [ # # ]: 0 : return DND_ACTION_COPY;
1528 : : }
1529 : : }
1530 : :
1531 : 0 : return DND_ACTION_NONE;
1532 : : }
1533 : :
1534 : : //------------------------------------------------------------------------------
1535 : 0 : Reference< XPropertySet > SbaGridControl::getDataSource() const
1536 : : {
1537 : 0 : Reference< XPropertySet > xReturn;
1538 : :
1539 [ # # ][ # # ]: 0 : Reference< XChild > xColumns(GetPeer()->getColumns(), UNO_QUERY);
1540 : 0 : Reference< XPropertySet > xDataSource;
1541 [ # # ]: 0 : if (xColumns.is())
1542 [ # # ][ # # ]: 0 : xReturn = Reference< XPropertySet > (xColumns->getParent(), UNO_QUERY);
[ # # ][ # # ]
1543 : :
1544 : 0 : return xReturn;
1545 : : }
1546 : : // -----------------------------------------------------------------------------
1547 : 0 : IMPL_LINK(SbaGridControl, AsynchDropEvent, void*, /*EMPTY_ARG*/)
1548 : : {
1549 : 0 : m_nAsyncDropEvent = 0;
1550 : :
1551 [ # # ]: 0 : Reference< XPropertySet > xDataSource = getDataSource();
1552 [ # # ]: 0 : if ( xDataSource.is() )
1553 : : {
1554 : 0 : sal_Bool bCountFinal = sal_False;
1555 [ # # ][ # # ]: 0 : xDataSource->getPropertyValue(PROPERTY_ISROWCOUNTFINAL) >>= bCountFinal;
[ # # ]
1556 [ # # ]: 0 : if ( !bCountFinal )
1557 [ # # ][ # # ]: 0 : setDataSource(NULL); // deattach from grid control
1558 [ # # ]: 0 : Reference< XResultSetUpdate > xResultSetUpdate(xDataSource,UNO_QUERY);
1559 [ # # ][ # # ]: 0 : ODatabaseImportExport* pImExport = new ORowSetImportExport(this,xResultSetUpdate,m_aDataDescriptor,getServiceManager());
[ # # ][ # # ]
1560 [ # # ][ # # ]: 0 : Reference<XEventListener> xHolder = pImExport;
1561 [ # # ]: 0 : Hide();
1562 : : try
1563 : : {
1564 [ # # ]: 0 : pImExport->initialize(m_aDataDescriptor);
1565 [ # # ]: 0 : BeforeDrop();
1566 [ # # ][ # # ]: 0 : if(!pImExport->Read())
1567 : : {
1568 [ # # ][ # # ]: 0 : String sError = String(ModuleRes(STR_NO_COLUMNNAME_MATCHING));
1569 [ # # ][ # # ]: 0 : throwGenericSQLException(sError,NULL);
[ # # ][ # # ]
1570 : : }
1571 [ # # ]: 0 : AfterDrop();
1572 [ # # ]: 0 : Show();
1573 : : }
1574 [ # # ]: 0 : catch(const SQLException& e)
1575 : : {
1576 [ # # ]: 0 : AfterDrop();
1577 [ # # ]: 0 : Show();
1578 [ # # # # : 0 : ::dbaui::showError(::dbtools::SQLExceptionInfo(e),this,getServiceManager());
# # # # ]
1579 : : }
1580 [ # # # # : 0 : catch(const Exception& )
# ]
1581 : : {
1582 [ # # ]: 0 : AfterDrop();
1583 [ # # ]: 0 : Show();
1584 : : DBG_UNHANDLED_EXCEPTION();
1585 : : }
1586 [ # # ]: 0 : if ( !bCountFinal )
1587 [ # # ][ # # ]: 0 : setDataSource(Reference< XRowSet >(xDataSource,UNO_QUERY));
1588 : : }
1589 [ # # ]: 0 : m_aDataDescriptor.clear();
1590 : :
1591 : 0 : return 0L;
1592 : : }
1593 : : // -------------------------------------------------------------------------
1594 : 0 : ::rtl::OUString SbaGridControl::GetAccessibleObjectDescription( ::svt::AccessibleBrowseBoxObjType eObjType,sal_Int32 _nPosition) const
1595 : : {
1596 : 0 : ::rtl::OUString sRet;
1597 [ # # ]: 0 : if ( ::svt::BBTYPE_BROWSEBOX == eObjType )
1598 : : {
1599 [ # # ]: 0 : SolarMutexGuard aGuard;
1600 [ # # ][ # # ]: 0 : sRet = String(ModuleRes(STR_DATASOURCE_GRIDCONTROL_DESC));
[ # # ][ # # ]
[ # # ]
1601 : : }
1602 : : else
1603 [ # # ]: 0 : sRet = FmGridControl::GetAccessibleObjectDescription( eObjType,_nPosition);
1604 : 0 : return sRet;
1605 : : }
1606 : : // -----------------------------------------------------------------------------
1607 : 0 : void SbaGridControl::DeleteSelectedRows()
1608 : : {
1609 : 0 : FmGridControl::DeleteSelectedRows();
1610 : 0 : }
1611 : :
1612 : :
1613 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|