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