1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_sc.hxx" 26 27 // INCLUDE --------------------------------------------------------------- 28 29 #include <svx/svditer.hxx> 30 #include <svx/svdobj.hxx> 31 #include <svx/svdpage.hxx> 32 #include <svx/svdpagv.hxx> 33 #include <svx/svdview.hxx> 34 #include <svx/svdxcgv.hxx> 35 #include <sfx2/linkmgr.hxx> 36 #include <sfx2/docfile.hxx> 37 #include <sfx2/viewfrm.hxx> 38 #include <vcl/help.hxx> 39 #include <vcl/sound.hxx> 40 #include <vcl/svapp.hxx> 41 #include <tools/urlobj.hxx> 42 #include <svl/urlbmk.hxx> 43 #include <stdlib.h> 44 45 #include "content.hxx" 46 #include "navipi.hxx" 47 #include "global.hxx" 48 #include "docsh.hxx" 49 #include "scmod.hxx" 50 #include "rangenam.hxx" 51 #include "dbcolect.hxx" 52 #include "tablink.hxx" // fuer Loader 53 #include "popmenu.hxx" 54 #include "drwlayer.hxx" 55 #include "transobj.hxx" 56 #include "drwtrans.hxx" 57 #include "lnktrans.hxx" 58 #include "cell.hxx" 59 #include "dociter.hxx" 60 #include "scresid.hxx" 61 #include "globstr.hrc" 62 #include "navipi.hrc" 63 #include "arealink.hxx" 64 #include "navicfg.hxx" 65 #include "navsett.hxx" 66 #include "postit.hxx" 67 #include "tabvwsh.hxx" 68 #include "drawview.hxx" 69 #include "clipparam.hxx" 70 71 using namespace com::sun::star; 72 73 // Reihenfolge der Kategorien im Navigator ------------------------------------- 74 75 static sal_uInt16 pTypeList[SC_CONTENT_COUNT] = 76 { 77 SC_CONTENT_ROOT, // ROOT (0) muss vorne stehen 78 SC_CONTENT_TABLE, 79 SC_CONTENT_RANGENAME, 80 SC_CONTENT_DBAREA, 81 SC_CONTENT_AREALINK, 82 SC_CONTENT_GRAPHIC, 83 SC_CONTENT_OLEOBJECT, 84 SC_CONTENT_NOTE, 85 SC_CONTENT_DRAWING 86 }; 87 88 sal_Bool ScContentTree::bIsInDrag = sal_False; 89 90 91 ScDocShell* ScContentTree::GetManualOrCurrent() 92 { 93 ScDocShell* pSh = NULL; 94 if ( aManualDoc.Len() ) 95 { 96 TypeId aScType = TYPE(ScDocShell); 97 SfxObjectShell* pObjSh = SfxObjectShell::GetFirst( &aScType ); 98 while ( pObjSh && !pSh ) 99 { 100 if ( pObjSh->GetTitle() == aManualDoc ) 101 pSh = PTR_CAST( ScDocShell, pObjSh ); 102 pObjSh = SfxObjectShell::GetNext( *pObjSh, &aScType ); 103 } 104 } 105 else 106 { 107 // Current nur, wenn keine manuell eingestellt ist 108 // (damit erkannt wird, wenn das Dokument nicht mehr existiert) 109 110 SfxViewShell* pViewSh = SfxViewShell::Current(); 111 if ( pViewSh ) 112 { 113 SfxObjectShell* pObjSh = pViewSh->GetViewFrame()->GetObjectShell(); 114 pSh = PTR_CAST( ScDocShell, pObjSh ); 115 } 116 } 117 118 return pSh; 119 } 120 121 // 122 // ScContentTree 123 // 124 125 ScContentTree::ScContentTree( Window* pParent, const ResId& rResId ) : 126 SvTreeListBox ( pParent, rResId ), 127 aEntryImages ( ScResId( RID_IMAGELIST_NAVCONT ) ), 128 aHCEntryImages ( ScResId( RID_IMAGELIST_H_NAVCONT ) ), 129 nRootType ( SC_CONTENT_ROOT ), 130 bHiddenDoc ( sal_False ), 131 pHiddenDocument ( NULL ), 132 bisInNavigatoeDlg ( sal_False ) 133 { 134 sal_uInt16 i; 135 for (i=0; i<SC_CONTENT_COUNT; i++) 136 pPosList[pTypeList[i]] = i; // invers zum suchen 137 138 pParentWindow = (ScNavigatorDlg*)pParent; 139 140 pRootNodes[0] = NULL; 141 for (i=1; i<SC_CONTENT_COUNT; i++) 142 InitRoot(i); 143 144 SetNodeDefaultImages(); 145 146 SetDoubleClickHdl( LINK( this, ScContentTree, ContentDoubleClickHdl ) ); 147 148 pTmpEntry= NULL; 149 m_bFirstPaint=true; 150 151 SetStyle( GetStyle() | WB_QUICK_SEARCH ); 152 } 153 154 ScContentTree::~ScContentTree() 155 { 156 } 157 // helper function for GetEntryAltText and GetEntryLongDescription 158 String ScContentTree::getAltLongDescText( SvLBoxEntry* pEntry , sal_Bool isAltText) const 159 { 160 SdrObject* pFound = NULL; 161 162 sal_uInt16 nType; 163 sal_uLong nChild; 164 GetEntryIndexes( nType, nChild, pEntry ); 165 switch( nType ) 166 { 167 case SC_CONTENT_OLEOBJECT: 168 case SC_CONTENT_GRAPHIC: 169 case SC_CONTENT_DRAWING: 170 { 171 ScDocument* pDoc = ( const_cast< ScContentTree* >(this) )->GetSourceDocument(); 172 SdrIterMode eIter = ( nType == SC_CONTENT_DRAWING ) ? IM_FLAT : IM_DEEPNOGROUPS; 173 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer(); 174 SfxObjectShell* pShell = pDoc->GetDocumentShell(); 175 if (pDrawLayer && pShell) 176 { 177 sal_uInt16 nTabCount = pDoc->GetTableCount(); 178 for (sal_uInt16 nTab=0; nTab<nTabCount; nTab++) 179 { 180 SdrPage* pPage = pDrawLayer->GetPage(nTab); 181 DBG_ASSERT(pPage,"Page ?"); 182 if (pPage) 183 { 184 SdrObjListIter aIter( *pPage, eIter ); 185 SdrObject* pObject = aIter.Next(); 186 while (pObject) 187 { 188 if( ScDrawLayer::GetVisibleName( pObject ) == GetEntryText( pEntry ) ) 189 { 190 pFound = pObject; 191 break; 192 } 193 pObject = aIter.Next(); 194 } 195 } 196 } 197 } 198 if( pFound ) 199 { 200 if( isAltText ) 201 return pFound->GetTitle(); 202 else 203 return pFound->GetDescription(); 204 } 205 } 206 break; 207 } 208 return String(); 209 } 210 String ScContentTree::GetEntryAltText( SvLBoxEntry* pEntry ) const 211 { 212 return getAltLongDescText( pEntry, sal_True ); 213 } 214 String ScContentTree::GetEntryLongDescription( SvLBoxEntry* pEntry ) const 215 { 216 return getAltLongDescText( pEntry, sal_False); 217 } 218 219 void ScContentTree::InitRoot( sal_uInt16 nType ) 220 { 221 if ( !nType ) 222 return; 223 224 if ( nRootType && nRootType != nType ) // ausgeblendet ? 225 { 226 pRootNodes[nType] = NULL; 227 return; 228 } 229 230 const Image& rImage = aEntryImages.GetImage( nType ); 231 String aName( ScResId( SCSTR_CONTENT_ROOT + nType ) ); 232 // wieder an die richtige Position: 233 sal_uInt16 nPos = nRootType ? 0 : pPosList[nType]-1; 234 SvLBoxEntry* pNew = InsertEntry( aName, rImage, rImage, NULL, sal_False, nPos ); 235 236 const Image& rHCImage = aHCEntryImages.GetImage( nType ); 237 SetExpandedEntryBmp( pNew, rHCImage, BMP_COLOR_HIGHCONTRAST ); 238 SetCollapsedEntryBmp( pNew, rHCImage, BMP_COLOR_HIGHCONTRAST ); 239 240 pRootNodes[nType] = pNew; 241 } 242 243 void ScContentTree::ClearAll() 244 { 245 //There are one method in Control::SetUpdateMode(), and one override method SvTreeListBox::SetUpdateMode(). Here although 246 //SvTreeListBox::SetUpdateMode() is called in refresh method, it only call SvTreeListBox::SetUpdateMode(), not Control::SetUpdateMode(). 247 //In SvTreeList::Clear(), Broadcast( LISTACTION_CLEARED ) will be called and finally, it will be trapped into the event yield() loop. And 248 //the InitRoot() method won't be called. Then if a user click or press key to update the navigator tree, crash happens. 249 //So the solution is to disable the UpdateMode of Control, then call Clear(), then recover the update mode 250 sal_Bool bOldUpdate = Control::IsUpdateMode(); 251 Control::SetUpdateMode(sal_False); 252 Clear(); 253 Control::SetUpdateMode(bOldUpdate); 254 for (sal_uInt16 i=1; i<SC_CONTENT_COUNT; i++) 255 InitRoot(i); 256 } 257 258 void ScContentTree::ClearType(sal_uInt16 nType) 259 { 260 if (!nType) 261 ClearAll(); 262 else 263 { 264 SvLBoxEntry* pParent = pRootNodes[nType]; 265 if ( !pParent || GetChildCount(pParent) ) // nicht, wenn ohne Children schon da 266 { 267 if (pParent) 268 GetModel()->Remove( pParent ); // mit allen Children 269 InitRoot( nType ); // ggf. neu eintragen 270 } 271 } 272 } 273 274 void ScContentTree::InsertContent( sal_uInt16 nType, const String& rValue ) 275 { 276 if (nType >= SC_CONTENT_COUNT) 277 { 278 DBG_ERROR("ScContentTree::InsertContent mit falschem Typ"); 279 return; 280 } 281 282 SvLBoxEntry* pParent = pRootNodes[nType]; 283 if (pParent) 284 InsertEntry( rValue, pParent ); 285 else 286 { 287 DBG_ERROR("InsertContent ohne Parent"); 288 } 289 } 290 291 void ScContentTree::GetEntryIndexes( sal_uInt16& rnRootIndex, sal_uLong& rnChildIndex, SvLBoxEntry* pEntry ) const 292 { 293 rnRootIndex = SC_CONTENT_ROOT; 294 rnChildIndex = SC_CONTENT_NOCHILD; 295 296 if( !pEntry ) 297 return; 298 299 SvLBoxEntry* pParent = GetParent( pEntry ); 300 bool bFound = false; 301 for( sal_uInt16 nRoot = 1; !bFound && (nRoot < SC_CONTENT_COUNT); ++nRoot ) 302 { 303 if( pEntry == pRootNodes[ nRoot ] ) 304 { 305 rnRootIndex = nRoot; 306 rnChildIndex = ~0UL; 307 bFound = true; 308 } 309 else if( pParent && (pParent == pRootNodes[ nRoot ]) ) 310 { 311 rnRootIndex = nRoot; 312 313 // search the entry in all child entries of the parent 314 sal_uLong nEntry = 0; 315 SvLBoxEntry* pIterEntry = FirstChild( pParent ); 316 while( !bFound && pIterEntry ) 317 { 318 if ( pEntry == pIterEntry ) 319 { 320 rnChildIndex = nEntry; 321 bFound = true; // exit the while loop 322 } 323 pIterEntry = NextSibling( pIterEntry ); 324 ++nEntry; 325 } 326 327 bFound = true; // exit the for loop 328 } 329 } 330 } 331 332 sal_uLong ScContentTree::GetChildIndex( SvLBoxEntry* pEntry ) const 333 { 334 sal_uInt16 nRoot; 335 sal_uLong nChild; 336 GetEntryIndexes( nRoot, nChild, pEntry ); 337 return nChild; 338 } 339 340 String lcl_GetDBAreaRange( ScDocument* pDoc, const String& rDBName ) 341 { 342 String aRet; 343 if (pDoc) 344 { 345 ScDBCollection* pDbNames = pDoc->GetDBCollection(); 346 sal_uInt16 nCount = pDbNames->GetCount(); 347 for ( sal_uInt16 i=0; i<nCount; i++ ) 348 { 349 ScDBData* pData = (*pDbNames)[i]; 350 if ( pData->GetName() == rDBName ) 351 { 352 ScRange aRange; 353 pData->GetArea(aRange); 354 aRange.Format( aRet, SCR_ABS_3D, pDoc ); 355 break; 356 } 357 } 358 } 359 return aRet; 360 } 361 362 IMPL_LINK( ScContentTree, ContentDoubleClickHdl, ScContentTree *, EMPTYARG ) 363 { 364 sal_uInt16 nType; 365 sal_uLong nChild; 366 SvLBoxEntry* pEntry = GetCurEntry(); 367 GetEntryIndexes( nType, nChild, pEntry ); 368 369 if( pEntry && (nType != SC_CONTENT_ROOT) && (nChild != SC_CONTENT_NOCHILD) ) 370 { 371 if ( bHiddenDoc ) 372 return 0; //! spaeter... 373 374 String aText( GetEntryText( pEntry ) ); 375 376 if ( aManualDoc.Len() ) 377 pParentWindow->SetCurrentDoc( aManualDoc ); 378 379 switch( nType ) 380 { 381 case SC_CONTENT_TABLE: 382 pParentWindow->SetCurrentTableStr( aText ); 383 break; 384 385 case SC_CONTENT_RANGENAME: 386 pParentWindow->SetCurrentCellStr( aText ); 387 break; 388 389 case SC_CONTENT_DBAREA: 390 { 391 // #47905# Wenn gleiche Bereichs- und DB-Namen existieren, wird 392 // bei SID_CURRENTCELL der Bereichsname genommen. 393 // DB-Bereiche darum direkt ueber die Adresse anspringen. 394 395 String aRangeStr = lcl_GetDBAreaRange( GetSourceDocument(), aText ); 396 if (aRangeStr.Len()) 397 pParentWindow->SetCurrentCellStr( aRangeStr ); 398 } 399 break; 400 401 case SC_CONTENT_OLEOBJECT: 402 case SC_CONTENT_GRAPHIC: 403 case SC_CONTENT_DRAWING: 404 pParentWindow->SetCurrentObject( aText ); 405 break; 406 407 case SC_CONTENT_NOTE: 408 { 409 ScAddress aPos = GetNotePos( nChild ); 410 pParentWindow->SetCurrentTable( aPos.Tab() ); 411 pParentWindow->SetCurrentCell( aPos.Col(), aPos.Row() ); 412 } 413 break; 414 415 case SC_CONTENT_AREALINK: 416 { 417 const ScAreaLink* pLink = GetLink( nChild ); 418 if( pLink ) 419 { 420 ScRange aRange = pLink->GetDestArea(); 421 String aRangeStr; 422 ScDocument* pSrcDoc = GetSourceDocument(); 423 aRange.Format( aRangeStr, SCR_ABS_3D, pSrcDoc, pSrcDoc->GetAddressConvention() ); 424 pParentWindow->SetCurrentCellStr( aRangeStr ); 425 } 426 } 427 break; 428 } 429 430 ScNavigatorDlg::ReleaseFocus(); // set focus into document 431 } 432 433 return 0; 434 } 435 436 void ScContentTree::MouseButtonDown( const MouseEvent& rMEvt ) 437 { 438 SvTreeListBox::MouseButtonDown( rMEvt ); 439 StoreSettings(); 440 } 441 442 void ScContentTree::KeyInput( const KeyEvent& rKEvt ) 443 { 444 sal_Bool bUsed = sal_False; 445 446 const KeyCode aCode = rKEvt.GetKeyCode(); 447 if (aCode.GetCode() == KEY_RETURN) 448 { 449 switch (aCode.GetModifier()) 450 { 451 case KEY_MOD1: 452 ToggleRoot(); // toggle root mode (as in Writer) 453 bUsed = sal_True; 454 break; 455 case 0: 456 { 457 SvLBoxEntry* pEntry = GetCurEntry(); 458 if( pEntry ) 459 { 460 sal_uInt16 nType; 461 sal_uLong nChild; 462 GetEntryIndexes( nType, nChild, pEntry ); 463 464 if( (nType != SC_CONTENT_ROOT) && (nChild == SC_CONTENT_NOCHILD) ) 465 { 466 String aText( GetEntryText( pEntry ) ); 467 if ( IsExpanded( pEntry ) ) 468 Collapse( pEntry ); 469 else 470 Expand( pEntry ); 471 } 472 else 473 ContentDoubleClickHdl(0); // select content as if double clicked 474 } 475 476 bUsed = sal_True; 477 } 478 break; 479 } 480 } 481 //Solution: Make KEY_SPACE has same function as DoubleClick 482 if ( bisInNavigatoeDlg ) 483 { 484 if(aCode.GetCode() == KEY_SPACE ) 485 { 486 bUsed = sal_True; 487 sal_uInt16 nType; 488 sal_uLong nChild; 489 SvLBoxEntry* pEntry = GetCurEntry(); 490 GetEntryIndexes( nType, nChild, pEntry ); 491 if( pEntry && (nType != SC_CONTENT_ROOT) && (nChild != SC_CONTENT_NOCHILD) ) 492 { 493 if ( bHiddenDoc ) 494 return ; //! spaeter... 495 String aText( GetEntryText( pEntry ) ); 496 sKeyString = aText; 497 if ( aManualDoc.Len() ) 498 pParentWindow->SetCurrentDoc( aManualDoc ); 499 switch( nType ) 500 { 501 case SC_CONTENT_OLEOBJECT: 502 case SC_CONTENT_GRAPHIC: 503 case SC_CONTENT_DRAWING: 504 { 505 Window* pWindow=(Window*)GetParent(pEntry); 506 ScNavigatorDlg* pScNavigatorDlg = (ScNavigatorDlg*)pWindow; 507 ScTabViewShell* pScTabViewShell = NULL; 508 ScDrawView* pScDrawView = NULL; 509 if (pScNavigatorDlg!=NULL) 510 pScTabViewShell=pScNavigatorDlg->GetTabViewShell(); 511 if(pScTabViewShell !=NULL) 512 pScDrawView =pScTabViewShell->GetViewData()->GetScDrawView(); 513 if(pScDrawView!=NULL) 514 { 515 pScDrawView->SelectCurrentViewObject(aText ); 516 sal_Bool bHasMakredObject = sal_False; 517 SvLBoxEntry* pParent = pRootNodes[nType]; 518 SvLBoxEntry* pBeginEntry = NULL; 519 if( pParent ) 520 pBeginEntry = FirstChild(pParent); 521 while( pBeginEntry ) 522 { 523 String aTempText( GetEntryText( pBeginEntry ) ); 524 if( pScDrawView->GetObjectIsMarked( pScDrawView->GetObjectByName( aTempText ) ) ) 525 { 526 bHasMakredObject = sal_True; 527 break; 528 } 529 pBeginEntry = Next( pBeginEntry ); 530 } 531 if( !bHasMakredObject && pScTabViewShell) 532 pScTabViewShell->SetDrawShell(sal_False); 533 ObjectFresh( nType,pEntry ); 534 } 535 } 536 break; 537 } 538 } 539 } 540 } 541 //StoreSettings(); 542 543 if( !bUsed ) 544 { 545 if(aCode.GetCode() == KEY_F5 ) 546 { 547 StoreSettings(); 548 SvTreeListBox::KeyInput(rKEvt); 549 } 550 else 551 { 552 SvTreeListBox::KeyInput(rKEvt); 553 StoreSettings(); 554 } 555 } 556 } 557 558 //sal_Bool __EXPORT ScContentTree::Drop( const DropEvent& rEvt ) 559 //{ 560 // return pParentWindow->Drop(rEvt); // Drop auf Navigator 561 //} 562 563 //sal_Bool __EXPORT ScContentTree::QueryDrop( DropEvent& rEvt ) 564 //{ 565 // return pParentWindow->QueryDrop(rEvt); // Drop auf Navigator 566 //} 567 568 sal_Int8 ScContentTree::AcceptDrop( const AcceptDropEvent& /* rEvt */ ) 569 { 570 return DND_ACTION_NONE; 571 } 572 573 sal_Int8 ScContentTree::ExecuteDrop( const ExecuteDropEvent& /* rEvt */ ) 574 { 575 return DND_ACTION_NONE; 576 } 577 578 void ScContentTree::StartDrag( sal_Int8 /* nAction */, const Point& /* rPosPixel */ ) 579 { 580 DoDrag(); 581 } 582 583 void ScContentTree::DragFinished( sal_Int8 /* nAction */ ) 584 { 585 } 586 587 void __EXPORT ScContentTree::Command( const CommandEvent& rCEvt ) 588 { 589 sal_Bool bDone = sal_False; 590 591 switch ( rCEvt.GetCommand() ) 592 { 593 case COMMAND_STARTDRAG: 594 // Aus dem ExecuteDrag heraus kann der Navigator geloescht werden 595 // (beim Umschalten auf einen anderen Dokument-Typ), das wuerde aber 596 // den StarView MouseMove-Handler, der Command() aufruft, umbringen. 597 // Deshalb Drag&Drop asynchron: 598 599 // DoDrag(); 600 601 Application::PostUserEvent( STATIC_LINK( this, ScContentTree, ExecDragHdl ) ); 602 603 bDone = sal_True; 604 break; 605 606 case COMMAND_CONTEXTMENU: 607 { 608 // Drag-Drop Modus 609 610 PopupMenu aPop; 611 ScPopupMenu aDropMenu( ScResId( RID_POPUP_DROPMODE ) ); 612 aDropMenu.CheckItem( RID_DROPMODE_URL + pParentWindow->GetDropMode() ); 613 aPop.InsertItem( 1, pParentWindow->GetStrDragMode() ); 614 aPop.SetPopupMenu( 1, &aDropMenu ); 615 616 // angezeigtes Dokument 617 618 ScPopupMenu aDocMenu; 619 aDocMenu.SetMenuFlags( aDocMenu.GetMenuFlags() | MENU_FLAG_NOAUTOMNEMONICS ); 620 sal_uInt16 i=0; 621 sal_uInt16 nPos=0; 622 // geladene Dokumente 623 ScDocShell* pCurrentSh = PTR_CAST( ScDocShell, SfxObjectShell::Current() ); 624 SfxObjectShell* pSh = SfxObjectShell::GetFirst(); 625 while ( pSh ) 626 { 627 if ( pSh->ISA(ScDocShell) ) 628 { 629 String aName = pSh->GetTitle(); 630 String aEntry = aName; 631 if ( pSh == pCurrentSh ) 632 aEntry += pParentWindow->aStrActive; 633 else 634 aEntry += pParentWindow->aStrNotActive; 635 aDocMenu.InsertItem( ++i, aEntry ); 636 if ( !bHiddenDoc && aName == aManualDoc ) 637 nPos = i; 638 } 639 pSh = SfxObjectShell::GetNext( *pSh ); 640 } 641 // "aktives Fenster" 642 aDocMenu.InsertItem( ++i, pParentWindow->aStrActiveWin ); 643 if (!bHiddenDoc && !aManualDoc.Len()) 644 nPos = i; 645 // verstecktes Dokument 646 if ( aHiddenTitle.Len() ) 647 { 648 String aEntry = aHiddenTitle; 649 aEntry += pParentWindow->aStrHidden; 650 aDocMenu.InsertItem( ++i, aEntry ); 651 if (bHiddenDoc) 652 nPos = i; 653 } 654 aDocMenu.CheckItem( nPos ); 655 aPop.InsertItem( 2, pParentWindow->GetStrDisplay() ); 656 aPop.SetPopupMenu( 2, &aDocMenu ); 657 658 // ausfuehren 659 660 aPop.Execute( this, rCEvt.GetMousePosPixel() ); 661 662 if ( aDropMenu.WasHit() ) // Drag-Drop Modus 663 { 664 sal_uInt16 nId = aDropMenu.GetSelected(); 665 if ( nId >= RID_DROPMODE_URL && nId <= RID_DROPMODE_COPY ) 666 pParentWindow->SetDropMode( nId - RID_DROPMODE_URL ); 667 } 668 else if ( aDocMenu.WasHit() ) // angezeigtes Dokument 669 { 670 sal_uInt16 nId = aDocMenu.GetSelected(); 671 String aName = aDocMenu.GetItemText(nId); 672 SelectDoc( aName ); 673 } 674 } 675 break; 676 } 677 678 if (!bDone) 679 SvTreeListBox::Command(rCEvt); 680 } 681 682 void __EXPORT ScContentTree::RequestHelp( const HelpEvent& rHEvt ) 683 { 684 sal_Bool bDone = sal_False; 685 if( rHEvt.GetMode() & HELPMODE_QUICK ) 686 { 687 Point aPos( ScreenToOutputPixel( rHEvt.GetMousePosPixel() )); 688 SvLBoxEntry* pEntry = GetEntry( aPos ); 689 if ( pEntry ) 690 { 691 sal_Bool bRet = sal_False; 692 String aHelpText; 693 SvLBoxEntry* pParent = GetParent(pEntry); 694 if ( !pParent ) // Top-Level ? 695 { 696 aHelpText = String::CreateFromInt32( GetChildCount(pEntry) ); 697 aHelpText += ' '; 698 aHelpText += GetEntryText(pEntry); 699 bRet = sal_True; 700 } 701 else if ( pParent == pRootNodes[SC_CONTENT_NOTE] ) 702 { 703 aHelpText = GetEntryText(pEntry); // Notizen als Help-Text 704 bRet = sal_True; 705 } 706 else if ( pParent == pRootNodes[SC_CONTENT_AREALINK] ) 707 { 708 sal_uLong nIndex = GetChildIndex(pEntry); 709 if( nIndex != SC_CONTENT_NOCHILD ) 710 { 711 const ScAreaLink* pLink = GetLink(nIndex); 712 if (pLink) 713 { 714 aHelpText = pLink->GetFile(); // Source-Datei als Help-Text 715 bRet = sal_True; 716 } 717 } 718 } 719 720 if (bRet) 721 { 722 SvLBoxTab* pTab; 723 SvLBoxString* pItem = (SvLBoxString*)(GetItem( pEntry, aPos.X(), &pTab )); 724 if( pItem ) 725 { 726 aPos = GetEntryPosition( pEntry ); 727 aPos.X() = GetTabPos( pEntry, pTab ); 728 aPos = OutputToScreenPixel(aPos); 729 Size aSize( pItem->GetSize( this, pEntry ) ); 730 731 Rectangle aItemRect( aPos, aSize ); 732 Help::ShowQuickHelp( this, aItemRect, aHelpText ); 733 bDone = sal_True; 734 } 735 } 736 } 737 } 738 if (!bDone) 739 Window::RequestHelp( rHEvt ); 740 } 741 742 ScDocument* ScContentTree::GetSourceDocument() 743 { 744 if (bHiddenDoc) 745 return pHiddenDocument; 746 else 747 { 748 ScDocShell* pSh = GetManualOrCurrent(); 749 if (pSh) 750 return pSh->GetDocument(); 751 752 } 753 return NULL; 754 } 755 756 //Solution: move along and draw "*" sign . 757 void ScContentTree::ObjectFresh( sal_uInt16 nType,SvLBoxEntry* pEntry ) 758 { 759 if ( bHiddenDoc && !pHiddenDocument ) 760 return; // anderes Dokument angezeigt 761 if(nType ==SC_CONTENT_GRAPHIC||nType ==SC_CONTENT_OLEOBJECT||nType ==SC_CONTENT_DRAWING) 762 { 763 SetUpdateMode(sal_False); 764 ClearType( nType ); 765 /*sal_uInt16 nId = OBJ_GRAF; 766 switch( nType ) 767 { 768 case SC_CONTENT_OLEOBJECT: 769 nId = OBJ_OLE2; 770 break; 771 case SC_CONTENT_DRAWING: 772 nId = OBJ_GRUP; 773 break; 774 }*/ 775 GetDrawNames( nType/*, nId*/ ); 776 if( !pEntry ) 777 ApplySettings(); 778 SetUpdateMode(sal_True); 779 if( pEntry ) 780 { 781 SvLBoxEntry* pParent = pRootNodes[nType]; 782 SvLBoxEntry* pBeginEntry = NULL; 783 SvLBoxEntry* pOldEntry = NULL; 784 if( pParent ) 785 pBeginEntry = FirstChild(pParent); 786 while( pBeginEntry ) 787 { 788 String aTempText( GetEntryText( pBeginEntry ) ); 789 if( aTempText == sKeyString ) 790 { 791 pOldEntry = pBeginEntry; 792 break; 793 } 794 pBeginEntry = Next( pBeginEntry ); 795 } 796 if( pOldEntry ) 797 { 798 Expand(pParent); 799 Select( pOldEntry,sal_True); 800 } 801 } 802 } 803 } 804 void ScContentTree::Refresh( sal_uInt16 nType ) 805 { 806 if ( bHiddenDoc && !pHiddenDocument ) 807 return; // anderes Dokument angezeigt 808 809 // wenn sich nichts geaendert hat, gleich abbrechen (gegen Geflacker) 810 811 if ( nType == SC_CONTENT_NOTE ) 812 if (!NoteStringsChanged()) 813 return; 814 if ( nType == SC_CONTENT_GRAPHIC ) 815 if (!DrawNamesChanged(SC_CONTENT_GRAPHIC)) 816 return; 817 if ( nType == SC_CONTENT_OLEOBJECT ) 818 if (!DrawNamesChanged(SC_CONTENT_OLEOBJECT)) 819 return; 820 if ( nType == SC_CONTENT_DRAWING ) 821 if (!DrawNamesChanged(SC_CONTENT_DRAWING)) 822 return; 823 824 SetUpdateMode(sal_False); 825 826 ClearType( nType ); 827 828 if ( !nType || nType == SC_CONTENT_TABLE ) 829 GetTableNames(); 830 if ( !nType || nType == SC_CONTENT_RANGENAME ) 831 GetAreaNames(); 832 if ( !nType || nType == SC_CONTENT_DBAREA ) 833 GetDbNames(); 834 if ( !nType || nType == SC_CONTENT_GRAPHIC ) 835 GetGraphicNames(); 836 if ( !nType || nType == SC_CONTENT_OLEOBJECT ) 837 GetOleNames(); 838 if ( !nType || nType == SC_CONTENT_DRAWING ) 839 GetDrawingNames(); 840 if ( !nType || nType == SC_CONTENT_NOTE ) 841 GetNoteStrings(); 842 if ( !nType || nType == SC_CONTENT_AREALINK ) 843 GetLinkNames(); 844 845 ApplySettings(); 846 SetUpdateMode(sal_True); 847 } 848 849 void ScContentTree::GetTableNames() 850 { 851 if ( nRootType && nRootType != SC_CONTENT_TABLE ) // ausgeblendet ? 852 return; 853 854 ScDocument* pDoc = GetSourceDocument(); 855 if (!pDoc) 856 return; 857 858 String aName; 859 SCTAB nCount = pDoc->GetTableCount(); 860 for ( SCTAB i=0; i<nCount; i++ ) 861 { 862 pDoc->GetName( i, aName ); 863 InsertContent( SC_CONTENT_TABLE, aName ); 864 } 865 } 866 867 void ScContentTree::GetAreaNames() 868 { 869 if ( nRootType && nRootType != SC_CONTENT_RANGENAME ) // ausgeblendet ? 870 return; 871 872 ScDocument* pDoc = GetSourceDocument(); 873 if (!pDoc) 874 return; 875 876 ScRangeName* pRangeNames = pDoc->GetRangeName(); 877 sal_uInt16 nCount = pRangeNames->GetCount(); 878 if ( nCount > 0 ) 879 { 880 sal_uInt16 nValidCount = 0; 881 ScRange aDummy; 882 sal_uInt16 i; 883 for ( i=0; i<nCount; i++ ) 884 { 885 ScRangeData* pData = (*pRangeNames)[i]; 886 if (pData->IsValidReference(aDummy)) 887 nValidCount++; 888 } 889 if ( nValidCount ) 890 { 891 ScRangeData** ppSortArray = new ScRangeData* [ nValidCount ]; 892 sal_uInt16 j; 893 for ( i=0, j=0; i<nCount; i++ ) 894 { 895 ScRangeData* pData = (*pRangeNames)[i]; 896 if (pData->IsValidReference(aDummy)) 897 ppSortArray[j++] = pData; 898 } 899 #ifndef ICC 900 qsort( (void*)ppSortArray, nValidCount, sizeof(ScRangeData*), 901 &ScRangeData_QsortNameCompare ); 902 #else 903 qsort( (void*)ppSortArray, nValidCount, sizeof(ScRangeData*), 904 ICCQsortNameCompare ); 905 #endif 906 for ( j=0; j<nValidCount; j++ ) 907 InsertContent( SC_CONTENT_RANGENAME, ppSortArray[j]->GetName() ); 908 delete [] ppSortArray; 909 } 910 } 911 } 912 913 void ScContentTree::GetDbNames() 914 { 915 if ( nRootType && nRootType != SC_CONTENT_DBAREA ) // ausgeblendet ? 916 return; 917 918 ScDocument* pDoc = GetSourceDocument(); 919 if (!pDoc) 920 return; 921 922 ScDBCollection* pDbNames = pDoc->GetDBCollection(); 923 sal_uInt16 nCount = pDbNames->GetCount(); 924 if ( nCount > 0 ) 925 { 926 for ( sal_uInt16 i=0; i<nCount; i++ ) 927 { 928 ScDBData* pData = (*pDbNames)[i]; 929 String aStrName = pData->GetName(); 930 if ( !pData->IsInternalUnnamed() 931 && !pData->IsInternalForAutoFilter() ) 932 { 933 InsertContent( SC_CONTENT_DBAREA, aStrName ); 934 } 935 } 936 } 937 } 938 939 bool ScContentTree::IsPartOfType( sal_uInt16 nContentType, sal_uInt16 nObjIdentifier ) // static 940 { 941 bool bRet = false; 942 switch ( nContentType ) 943 { 944 case SC_CONTENT_GRAPHIC: 945 bRet = ( nObjIdentifier == OBJ_GRAF ); 946 break; 947 case SC_CONTENT_OLEOBJECT: 948 bRet = ( nObjIdentifier == OBJ_OLE2 ); 949 break; 950 case SC_CONTENT_DRAWING: 951 bRet = ( nObjIdentifier != OBJ_GRAF && nObjIdentifier != OBJ_OLE2 ); // everything else 952 break; 953 default: 954 DBG_ERROR("unknown content type"); 955 } 956 return bRet; 957 } 958 959 void ScContentTree::GetDrawNames( sal_uInt16 nType ) 960 { 961 if ( nRootType && nRootType != nType ) // ausgeblendet ? 962 return; 963 964 ScDocument* pDoc = GetSourceDocument(); 965 if (!pDoc) 966 return; 967 968 // iterate in flat mode for groups 969 SdrIterMode eIter = ( nType == SC_CONTENT_DRAWING ) ? IM_FLAT : IM_DEEPNOGROUPS; 970 971 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer(); 972 SfxObjectShell* pShell = pDoc->GetDocumentShell(); 973 if (pDrawLayer && pShell) 974 { 975 SCTAB nTabCount = pDoc->GetTableCount(); 976 for (SCTAB nTab=0; nTab<nTabCount; nTab++) 977 { 978 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab)); 979 DBG_ASSERT(pPage,"Page ?"); 980 if (pPage) 981 { 982 SdrObjListIter aIter( *pPage, eIter ); 983 SdrObject* pObject = aIter.Next(); 984 while (pObject) 985 { 986 if ( IsPartOfType( nType, pObject->GetObjIdentifier() ) ) 987 { 988 String aName = ScDrawLayer::GetVisibleName( pObject ); 989 if (aName.Len()) 990 { 991 //InsertContent( nType, aName ); 992 if( bisInNavigatoeDlg ) 993 { 994 if (nType >= SC_CONTENT_COUNT) 995 { 996 DBG_ERROR("ScContentTree::InsertContent mit falschem Typ"); 997 return; 998 } 999 SvLBoxEntry* pParent = pRootNodes[nType]; 1000 if (pParent) 1001 { 1002 SvLBoxEntry* pChild=InsertEntry( aName, pParent ); 1003 if(pChild) 1004 pChild->SetMarked( sal_False); 1005 Window* pWindow=NULL; 1006 ScTabViewShell* pScTabViewShell=NULL; 1007 ScDrawView* pScDrawView=NULL; 1008 ScNavigatorDlg* pScNavigatorDlg=NULL; 1009 if(pChild) 1010 pWindow=(Window*)GetParent(pChild); 1011 if(pWindow) 1012 pScNavigatorDlg = (ScNavigatorDlg*)pWindow; 1013 if (pScNavigatorDlg!=NULL) 1014 pScTabViewShell=pScNavigatorDlg->GetTabViewShell(); 1015 if(pScTabViewShell !=NULL) 1016 pScDrawView =pScTabViewShell->GetViewData()->GetScDrawView(); 1017 if(pScDrawView!=NULL) 1018 { 1019 sal_Bool bMarked =pScDrawView->GetObjectIsMarked(pObject); 1020 pChild->SetMarked( bMarked ); 1021 } 1022 }//end if parent 1023 else 1024 DBG_ERROR("InsertContent ohne Parent"); 1025 } 1026 } 1027 } 1028 pObject = aIter.Next(); 1029 } 1030 } 1031 } 1032 } 1033 } 1034 1035 void ScContentTree::GetGraphicNames() 1036 { 1037 GetDrawNames( SC_CONTENT_GRAPHIC ); 1038 } 1039 1040 void ScContentTree::GetOleNames() 1041 { 1042 GetDrawNames( SC_CONTENT_OLEOBJECT ); 1043 } 1044 1045 void ScContentTree::GetDrawingNames() 1046 { 1047 GetDrawNames( SC_CONTENT_DRAWING ); 1048 } 1049 1050 void ScContentTree::GetLinkNames() 1051 { 1052 if ( nRootType && nRootType != SC_CONTENT_AREALINK ) // ausgeblendet ? 1053 return; 1054 1055 ScDocument* pDoc = GetSourceDocument(); 1056 if (!pDoc) 1057 return; 1058 1059 sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager(); 1060 DBG_ASSERT(pLinkManager, "kein LinkManager am Dokument?"); 1061 const ::sfx2::SvBaseLinks& rLinks = pLinkManager->GetLinks(); 1062 sal_uInt16 nCount = rLinks.Count(); 1063 for (sal_uInt16 i=0; i<nCount; i++) 1064 { 1065 ::sfx2::SvBaseLink* pBase = *rLinks[i]; 1066 if (pBase->ISA(ScAreaLink)) 1067 InsertContent( SC_CONTENT_AREALINK, ((ScAreaLink*)pBase)->GetSource() ); 1068 1069 // in der Liste die Namen der Quellbereiche 1070 } 1071 } 1072 1073 const ScAreaLink* ScContentTree::GetLink( sal_uLong nIndex ) 1074 { 1075 ScDocument* pDoc = GetSourceDocument(); 1076 if (!pDoc) 1077 return NULL; 1078 1079 sal_uLong nFound = 0; 1080 sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager(); 1081 DBG_ASSERT(pLinkManager, "kein LinkManager am Dokument?"); 1082 const ::sfx2::SvBaseLinks& rLinks = pLinkManager->GetLinks(); 1083 sal_uInt16 nCount = rLinks.Count(); 1084 for (sal_uInt16 i=0; i<nCount; i++) 1085 { 1086 ::sfx2::SvBaseLink* pBase = *rLinks[i]; 1087 if (pBase->ISA(ScAreaLink)) 1088 { 1089 if (nFound == nIndex) 1090 return (const ScAreaLink*) pBase; 1091 ++nFound; 1092 } 1093 } 1094 1095 DBG_ERROR("Link nicht gefunden"); 1096 return NULL; 1097 } 1098 1099 String lcl_NoteString( const ScPostIt& rNote ) 1100 { 1101 String aText = rNote.GetText(); 1102 xub_StrLen nAt; 1103 while ( (nAt = aText.Search( '\n' )) != STRING_NOTFOUND ) 1104 aText.SetChar( nAt, ' ' ); 1105 return aText; 1106 } 1107 1108 void ScContentTree::GetNoteStrings() 1109 { 1110 if ( nRootType && nRootType != SC_CONTENT_NOTE ) // ausgeblendet ? 1111 return; 1112 1113 ScDocument* pDoc = GetSourceDocument(); 1114 if (!pDoc) 1115 return; 1116 1117 SCTAB nTabCount = pDoc->GetTableCount(); 1118 for (SCTAB nTab=0; nTab<nTabCount; nTab++) 1119 { 1120 ScCellIterator aIter( pDoc, 0,0,nTab, MAXCOL,MAXROW,nTab ); 1121 for( ScBaseCell* pCell = aIter.GetFirst(); pCell; pCell = aIter.GetNext() ) 1122 if( const ScPostIt* pNote = pCell->GetNote() ) 1123 InsertContent( SC_CONTENT_NOTE, lcl_NoteString( *pNote ) ); 1124 } 1125 } 1126 1127 ScAddress ScContentTree::GetNotePos( sal_uLong nIndex ) 1128 { 1129 ScDocument* pDoc = GetSourceDocument(); 1130 if (!pDoc) 1131 return ScAddress(); 1132 1133 sal_uLong nFound = 0; 1134 SCTAB nTabCount = pDoc->GetTableCount(); 1135 for (SCTAB nTab=0; nTab<nTabCount; nTab++) 1136 { 1137 ScCellIterator aIter( pDoc, 0,0,nTab, MAXCOL,MAXROW,nTab ); 1138 ScBaseCell* pCell = aIter.GetFirst(); 1139 while (pCell) 1140 { 1141 if( pCell->HasNote() ) 1142 { 1143 if (nFound == nIndex) 1144 return ScAddress( aIter.GetCol(), aIter.GetRow(), nTab ); // gefunden 1145 ++nFound; 1146 } 1147 pCell = aIter.GetNext(); 1148 } 1149 } 1150 1151 DBG_ERROR("Notiz nicht gefunden"); 1152 return ScAddress(); 1153 } 1154 1155 sal_Bool ScContentTree::NoteStringsChanged() 1156 { 1157 ScDocument* pDoc = GetSourceDocument(); 1158 if (!pDoc) 1159 return sal_False; 1160 1161 SvLBoxEntry* pParent = pRootNodes[SC_CONTENT_NOTE]; 1162 if (!pParent) 1163 return sal_False; 1164 1165 SvLBoxEntry* pEntry = FirstChild( pParent ); 1166 1167 sal_Bool bEqual = sal_True; 1168 SCTAB nTabCount = pDoc->GetTableCount(); 1169 for (SCTAB nTab=0; nTab<nTabCount && bEqual; nTab++) 1170 { 1171 ScCellIterator aIter( pDoc, 0,0,nTab, MAXCOL,MAXROW,nTab ); 1172 ScBaseCell* pCell = aIter.GetFirst(); 1173 while (pCell && bEqual) 1174 { 1175 if( const ScPostIt* pNote = pCell->GetNote() ) 1176 { 1177 if ( !pEntry ) 1178 bEqual = sal_False; 1179 else 1180 { 1181 if ( lcl_NoteString( *pNote ) != GetEntryText(pEntry) ) 1182 bEqual = sal_False; 1183 1184 pEntry = NextSibling( pEntry ); 1185 } 1186 } 1187 pCell = aIter.GetNext(); 1188 } 1189 } 1190 1191 if ( pEntry ) 1192 bEqual = sal_False; // kommt noch was 1193 1194 return !bEqual; 1195 } 1196 1197 sal_Bool ScContentTree::DrawNamesChanged( sal_uInt16 nType ) 1198 { 1199 ScDocument* pDoc = GetSourceDocument(); 1200 if (!pDoc) 1201 return sal_False; 1202 1203 SvLBoxEntry* pParent = pRootNodes[nType]; 1204 if (!pParent) 1205 return sal_False; 1206 1207 SvLBoxEntry* pEntry = FirstChild( pParent ); 1208 1209 // iterate in flat mode for groups 1210 SdrIterMode eIter = ( nType == SC_CONTENT_DRAWING ) ? IM_FLAT : IM_DEEPNOGROUPS; 1211 1212 sal_Bool bEqual = sal_True; 1213 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer(); 1214 SfxObjectShell* pShell = pDoc->GetDocumentShell(); 1215 if (pDrawLayer && pShell) 1216 { 1217 SCTAB nTabCount = pDoc->GetTableCount(); 1218 for (SCTAB nTab=0; nTab<nTabCount && bEqual; nTab++) 1219 { 1220 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab)); 1221 DBG_ASSERT(pPage,"Page ?"); 1222 if (pPage) 1223 { 1224 SdrObjListIter aIter( *pPage, eIter ); 1225 SdrObject* pObject = aIter.Next(); 1226 while (pObject && bEqual) 1227 { 1228 if ( IsPartOfType( nType, pObject->GetObjIdentifier() ) ) 1229 { 1230 if ( !pEntry ) 1231 bEqual = sal_False; 1232 else 1233 { 1234 if ( ScDrawLayer::GetVisibleName( pObject ) != GetEntryText(pEntry) ) 1235 bEqual = sal_False; 1236 1237 pEntry = NextSibling( pEntry ); 1238 } 1239 } 1240 pObject = aIter.Next(); 1241 } 1242 } 1243 } 1244 } 1245 1246 if ( pEntry ) 1247 bEqual = sal_False; // kommt noch was 1248 1249 return !bEqual; 1250 } 1251 1252 sal_Bool lcl_GetRange( ScDocument* pDoc, sal_uInt16 nType, const String& rName, ScRange& rRange ) 1253 { 1254 sal_Bool bFound = sal_False; 1255 sal_uInt16 nPos; 1256 1257 if ( nType == SC_CONTENT_RANGENAME ) 1258 { 1259 ScRangeName* pList = pDoc->GetRangeName(); 1260 if (pList) 1261 if (pList->SearchName( rName, nPos )) 1262 if ( (*pList)[nPos]->IsValidReference( rRange ) ) 1263 bFound = sal_True; 1264 } 1265 else if ( nType == SC_CONTENT_DBAREA ) 1266 { 1267 ScDBCollection* pList = pDoc->GetDBCollection(); 1268 if (pList) 1269 if (pList->SearchName( rName, nPos )) 1270 { 1271 SCTAB nTab; 1272 SCCOL nCol1, nCol2; 1273 SCROW nRow1, nRow2; 1274 (*pList)[nPos]->GetArea(nTab,nCol1,nRow1,nCol2,nRow2); 1275 rRange = ScRange( nCol1,nRow1,nTab, nCol2,nRow2,nTab ); 1276 bFound = sal_True; 1277 } 1278 } 1279 1280 return bFound; 1281 } 1282 1283 void lcl_DoDragObject( ScDocShell* pSrcShell, const String& rName, sal_uInt16 nType, Window* pWin ) 1284 { 1285 ScDocument* pSrcDoc = pSrcShell->GetDocument(); 1286 ScDrawLayer* pModel = pSrcDoc->GetDrawLayer(); 1287 if (pModel) 1288 { 1289 sal_Bool bOle = ( nType == SC_CONTENT_OLEOBJECT ); 1290 sal_Bool bGraf = ( nType == SC_CONTENT_GRAPHIC ); 1291 sal_uInt16 nDrawId = sal::static_int_cast<sal_uInt16>( bOle ? OBJ_OLE2 : ( bGraf ? OBJ_GRAF : OBJ_GRUP ) ); 1292 SCTAB nTab = 0; 1293 SdrObject* pObject = pModel->GetNamedObject( rName, nDrawId, nTab ); 1294 if (pObject) 1295 { 1296 SdrView aEditView( pModel ); 1297 aEditView.ShowSdrPage(aEditView.GetModel()->GetPage(nTab)); 1298 SdrPageView* pPV = aEditView.GetSdrPageView(); 1299 aEditView.MarkObj(pObject, pPV); 1300 1301 SdrModel* pDragModel = aEditView.GetAllMarkedModel(); 1302 1303 TransferableObjectDescriptor aObjDesc; 1304 pSrcShell->FillTransferableObjectDescriptor( aObjDesc ); 1305 aObjDesc.maDisplayName = pSrcShell->GetMedium()->GetURLObject().GetURLNoPass(); 1306 // maSize is set in ScDrawTransferObj ctor 1307 1308 ScDrawTransferObj* pTransferObj = new ScDrawTransferObj( pDragModel, pSrcShell, aObjDesc ); 1309 uno::Reference<datatransfer::XTransferable> xTransferable( pTransferObj ); 1310 1311 pTransferObj->SetDragSourceObj( pObject, nTab ); 1312 pTransferObj->SetDragSourceFlags( SC_DROP_NAVIGATOR ); 1313 1314 SC_MOD()->SetDragObject( NULL, pTransferObj ); 1315 pWin->ReleaseMouse(); 1316 pTransferObj->StartDrag( pWin, DND_ACTION_COPYMOVE | DND_ACTION_LINK ); 1317 } 1318 } 1319 } 1320 1321 void lcl_DoDragCells( ScDocShell* pSrcShell, const ScRange& rRange, sal_uInt16 nFlags, Window* pWin ) 1322 { 1323 ScMarkData aMark; 1324 aMark.SelectTable( rRange.aStart.Tab(), sal_True ); 1325 aMark.SetMarkArea( rRange ); 1326 1327 ScDocument* pSrcDoc = pSrcShell->GetDocument(); 1328 if ( !pSrcDoc->HasSelectedBlockMatrixFragment( rRange.aStart.Col(), rRange.aStart.Row(), 1329 rRange.aEnd.Col(), rRange.aEnd.Row(), 1330 aMark ) ) 1331 { 1332 ScDocument* pClipDoc = new ScDocument( SCDOCMODE_CLIP ); 1333 ScClipParam aClipParam(rRange, false); 1334 pSrcDoc->CopyToClip(aClipParam, pClipDoc, &aMark); 1335 // pClipDoc->ExtendMerge( rRange, sal_True ); 1336 1337 TransferableObjectDescriptor aObjDesc; 1338 pSrcShell->FillTransferableObjectDescriptor( aObjDesc ); 1339 aObjDesc.maDisplayName = pSrcShell->GetMedium()->GetURLObject().GetURLNoPass(); 1340 // maSize is set in ScTransferObj ctor 1341 1342 ScTransferObj* pTransferObj = new ScTransferObj( pClipDoc, aObjDesc ); 1343 uno::Reference<datatransfer::XTransferable> xTransferable( pTransferObj ); 1344 1345 pTransferObj->SetDragSource( pSrcShell, aMark ); 1346 pTransferObj->SetDragSourceFlags( nFlags ); 1347 1348 SC_MOD()->SetDragObject( pTransferObj, NULL ); // for internal D&D 1349 pWin->ReleaseMouse(); 1350 pTransferObj->StartDrag( pWin, DND_ACTION_COPYMOVE | DND_ACTION_LINK ); 1351 } 1352 } 1353 1354 void ScContentTree::DoDrag() 1355 { 1356 ScDocumentLoader* pDocLoader = NULL; 1357 bIsInDrag = sal_True; 1358 1359 ScModule* pScMod = SC_MOD(); 1360 1361 sal_uInt16 nType; 1362 sal_uLong nChild; 1363 SvLBoxEntry* pEntry = GetCurEntry(); 1364 GetEntryIndexes( nType, nChild, pEntry ); 1365 1366 if( pEntry && 1367 (nChild != SC_CONTENT_NOCHILD) && 1368 (nType != SC_CONTENT_ROOT) && 1369 (nType != SC_CONTENT_NOTE) && 1370 (nType != SC_CONTENT_AREALINK) ) 1371 { 1372 String aText( GetEntryText( pEntry ) ); 1373 1374 ScDocument* pLocalDoc = NULL; // fuer URL-Drop 1375 String aDocName; 1376 if (bHiddenDoc) 1377 aDocName = aHiddenName; 1378 else 1379 { 1380 ScDocShell* pDocSh = GetManualOrCurrent(); 1381 if (pDocSh) 1382 { 1383 if (pDocSh->HasName()) 1384 aDocName = pDocSh->GetMedium()->GetName(); 1385 else 1386 pLocalDoc = pDocSh->GetDocument(); // Drop nur in dieses Dokument 1387 } 1388 } 1389 1390 sal_Bool bDoLinkTrans = sal_False; // use ScLinkTransferObj 1391 String aLinkURL; // for ScLinkTransferObj 1392 String aLinkText; 1393 1394 sal_uInt16 nDropMode = pParentWindow->GetDropMode(); 1395 switch ( nDropMode ) 1396 { 1397 case SC_DROPMODE_URL: 1398 { 1399 String aUrl = aDocName; 1400 aUrl += '#'; 1401 aUrl += aText; 1402 1403 pScMod->SetDragJump( pLocalDoc, aUrl, aText ); 1404 1405 if (aDocName.Len()) 1406 { 1407 // provide URL to outside only if the document has a name 1408 // (without name, only internal D&D via SetDragJump) 1409 1410 aLinkURL = aUrl; 1411 aLinkText = aText; 1412 } 1413 bDoLinkTrans = sal_True; 1414 } 1415 break; 1416 case SC_DROPMODE_LINK: 1417 { 1418 if ( aDocName.Len() ) // link only to named documents 1419 { 1420 // for internal D&D, set flag to insert a link 1421 1422 switch ( nType ) 1423 { 1424 case SC_CONTENT_TABLE: 1425 pScMod->SetDragLink( aDocName, aText, EMPTY_STRING ); 1426 bDoLinkTrans = sal_True; 1427 break; 1428 case SC_CONTENT_RANGENAME: 1429 case SC_CONTENT_DBAREA: 1430 pScMod->SetDragLink( aDocName, EMPTY_STRING, aText ); 1431 bDoLinkTrans = sal_True; 1432 break; 1433 1434 // other types cannot be linked 1435 } 1436 } 1437 } 1438 break; 1439 case SC_DROPMODE_COPY: 1440 { 1441 ScDocShell* pSrcShell = NULL; 1442 if ( bHiddenDoc ) 1443 { 1444 String aFilter, aOptions; 1445 pDocLoader = new ScDocumentLoader( aHiddenName, aFilter, aOptions ); 1446 if (!pDocLoader->IsError()) 1447 pSrcShell = pDocLoader->GetDocShell(); 1448 } 1449 else 1450 pSrcShell = GetManualOrCurrent(); 1451 1452 if ( pSrcShell ) 1453 { 1454 ScDocument* pSrcDoc = pSrcShell->GetDocument(); 1455 if ( nType == SC_CONTENT_RANGENAME || nType == SC_CONTENT_DBAREA ) 1456 { 1457 ScRange aRange; 1458 if ( lcl_GetRange( pSrcDoc, nType, aText, aRange ) ) 1459 { 1460 lcl_DoDragCells( pSrcShell, aRange, SC_DROP_NAVIGATOR, this ); 1461 } 1462 } 1463 else if ( nType == SC_CONTENT_TABLE ) 1464 { 1465 SCTAB nTab; 1466 if ( pSrcDoc->GetTable( aText, nTab ) ) 1467 { 1468 ScRange aRange( 0,0,nTab, MAXCOL,MAXROW,nTab ); 1469 lcl_DoDragCells( pSrcShell, aRange, SC_DROP_NAVIGATOR | SC_DROP_TABLE, this ); 1470 } 1471 } 1472 else if ( nType == SC_CONTENT_GRAPHIC || nType == SC_CONTENT_OLEOBJECT || 1473 nType == SC_CONTENT_DRAWING ) 1474 { 1475 lcl_DoDragObject( pSrcShell, aText, nType, this ); 1476 1477 // in ExecuteDrag kann der Navigator geloescht worden sein 1478 // -> nicht mehr auf Member zugreifen !!! 1479 } 1480 } 1481 } 1482 break; 1483 } 1484 1485 if (bDoLinkTrans) 1486 { 1487 ScLinkTransferObj* pTransferObj = new ScLinkTransferObj; 1488 uno::Reference<datatransfer::XTransferable> xTransferable( pTransferObj ); 1489 1490 if ( aLinkURL.Len() ) 1491 pTransferObj->SetLinkURL( aLinkURL, aLinkText ); 1492 1493 // SetDragJump / SetDragLink has been done above 1494 1495 ReleaseMouse(); 1496 pTransferObj->StartDrag( this, DND_ACTION_COPYMOVE | DND_ACTION_LINK ); 1497 } 1498 } 1499 1500 bIsInDrag = sal_False; // static Member 1501 1502 delete pDocLoader; // falls Dokument zum Draggen geladen wurde 1503 } 1504 1505 IMPL_STATIC_LINK(ScContentTree, ExecDragHdl, void*, EMPTYARG) 1506 { 1507 // als Link, damit asynchron ohne ImpMouseMoveMsg auf dem Stack auch der 1508 // Navigator geloescht werden darf 1509 1510 pThis->DoDrag(); 1511 return 0; 1512 } 1513 1514 //UNUSED2008-05 void ScContentTree::AdjustTitle() 1515 //UNUSED2008-05 { 1516 //UNUSED2008-05 String aTitle = pParentWindow->aTitleBase; 1517 //UNUSED2008-05 if (bHiddenDoc) 1518 //UNUSED2008-05 { 1519 //UNUSED2008-05 aTitle.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " - " )); 1520 //UNUSED2008-05 aTitle += aHiddenTitle; 1521 //UNUSED2008-05 } 1522 //UNUSED2008-05 pParentWindow->SetText(aTitle); 1523 //UNUSED2008-05 } 1524 1525 sal_Bool ScContentTree::LoadFile( const String& rUrl ) 1526 { 1527 String aDocName = rUrl; 1528 xub_StrLen nPos = aDocName.Search('#'); 1529 if ( nPos != STRING_NOTFOUND ) 1530 aDocName.Erase(nPos); // nur der Name, ohne #... 1531 1532 sal_Bool bReturn = sal_False; 1533 String aFilter, aOptions; 1534 ScDocumentLoader aLoader( aDocName, aFilter, aOptions ); 1535 if ( !aLoader.IsError() ) 1536 { 1537 bHiddenDoc = sal_True; 1538 aHiddenName = aDocName; 1539 aHiddenTitle = aLoader.GetTitle(); 1540 pHiddenDocument = aLoader.GetDocument(); 1541 1542 Refresh(); // Inhalte aus geladenem Dokument holen 1543 1544 pHiddenDocument = NULL; 1545 // AdjustTitle(); 1546 1547 pParentWindow->GetDocNames( &aHiddenTitle ); // Liste fuellen 1548 } 1549 else 1550 Sound::Beep(); // Fehler beim Laden 1551 1552 // Dokument wird im dtor von ScDocumentLoader wieder geschlossen 1553 1554 return bReturn; 1555 } 1556 1557 void ScContentTree::InitWindowBits( sal_Bool bButtons ) 1558 { 1559 WinBits nFlags = GetStyle()|WB_CLIPCHILDREN|WB_HSCROLL; 1560 if (bButtons) 1561 nFlags |= WB_HASBUTTONS|WB_HASBUTTONSATROOT; 1562 1563 SetStyle( nFlags ); 1564 } 1565 1566 void ScContentTree::SetRootType( sal_uInt16 nNew ) 1567 { 1568 if ( nNew != nRootType ) 1569 { 1570 nRootType = nNew; 1571 InitWindowBits( nNew == 0 ); 1572 Refresh(); 1573 1574 ScNavipiCfg& rCfg = SC_MOD()->GetNavipiCfg(); 1575 rCfg.SetRootType( nRootType ); 1576 } 1577 } 1578 1579 void ScContentTree::ToggleRoot() // nach Selektion 1580 { 1581 sal_uInt16 nNew = SC_CONTENT_ROOT; 1582 if ( nRootType == SC_CONTENT_ROOT ) 1583 { 1584 SvLBoxEntry* pEntry = GetCurEntry(); 1585 if (pEntry) 1586 { 1587 SvLBoxEntry* pParent = GetParent(pEntry); 1588 for (sal_uInt16 i=1; i<SC_CONTENT_COUNT; i++) 1589 if ( pEntry == pRootNodes[i] || pParent == pRootNodes[i] ) 1590 nNew = i; 1591 } 1592 } 1593 1594 SetRootType( nNew ); 1595 } 1596 1597 void ScContentTree::ResetManualDoc() 1598 { 1599 aManualDoc.Erase(); 1600 bHiddenDoc = sal_False; 1601 1602 ActiveDocChanged(); 1603 } 1604 1605 void ScContentTree::ActiveDocChanged() 1606 { 1607 if ( !bHiddenDoc && !aManualDoc.Len() ) 1608 Refresh(); // Inhalte nur wenn automatisch 1609 1610 // Listbox muss immer geupdated werden, wegen aktiv-Flag 1611 1612 String aCurrent; 1613 if ( bHiddenDoc ) 1614 aCurrent = aHiddenTitle; 1615 else 1616 { 1617 ScDocShell* pSh = GetManualOrCurrent(); 1618 if (pSh) 1619 aCurrent = pSh->GetTitle(); 1620 else 1621 { 1622 // eingestelltes Dokument existiert nicht mehr 1623 1624 aManualDoc.Erase(); // wieder automatisch 1625 Refresh(); 1626 pSh = GetManualOrCurrent(); // sollte jetzt aktives sein 1627 if (pSh) 1628 aCurrent = pSh->GetTitle(); 1629 } 1630 } 1631 pParentWindow->GetDocNames( &aCurrent ); // selektieren 1632 } 1633 1634 void ScContentTree::SetManualDoc(const String& rName) 1635 { 1636 aManualDoc = rName; 1637 if (!bHiddenDoc) 1638 { 1639 Refresh(); 1640 pParentWindow->GetDocNames( &aManualDoc ); // selektieren 1641 } 1642 } 1643 1644 void ScContentTree::SelectDoc(const String& rName) // rName wie im Menue/Listbox angezeigt 1645 { 1646 if ( rName == pParentWindow->aStrActiveWin ) 1647 { 1648 ResetManualDoc(); 1649 return; 1650 } 1651 1652 // "aktiv" oder "inaktiv" weglassen 1653 1654 String aRealName = rName; 1655 xub_StrLen nLen = rName.Len(); 1656 xub_StrLen nActiveStart = nLen - pParentWindow->aStrActive.Len(); 1657 if ( rName.Copy( nActiveStart ) == pParentWindow->aStrActive ) 1658 aRealName = rName.Copy( 0, nActiveStart ); 1659 xub_StrLen nNotActiveStart = nLen - pParentWindow->aStrNotActive.Len(); 1660 if ( rName.Copy( nNotActiveStart ) == pParentWindow->aStrNotActive ) 1661 aRealName = rName.Copy( 0, nNotActiveStart ); 1662 1663 // 1664 1665 sal_Bool bLoaded = sal_False; 1666 1667 // ist es ein normal geladenes Doc ? 1668 1669 SfxObjectShell* pSh = SfxObjectShell::GetFirst(); 1670 while ( pSh && !bLoaded ) 1671 { 1672 if ( pSh->ISA(ScDocShell) ) 1673 if ( pSh->GetTitle() == aRealName ) 1674 bLoaded = sal_True; 1675 pSh = SfxObjectShell::GetNext( *pSh ); 1676 } 1677 1678 if (bLoaded) 1679 { 1680 bHiddenDoc = sal_False; 1681 SetManualDoc(aRealName); 1682 } 1683 else if (aHiddenTitle.Len()) // verstecktes ausgewaehlt 1684 { 1685 if (!bHiddenDoc) 1686 LoadFile(aHiddenName); 1687 } 1688 else 1689 { 1690 DBG_ERROR("SelectDoc: nicht gefunden"); 1691 } 1692 } 1693 1694 void ScContentTree::ApplySettings() 1695 { 1696 const ScNavigatorSettings* pSettings = pParentWindow->GetNavigatorSettings(); 1697 if( pSettings ) 1698 { 1699 sal_uInt16 nRootSel = pSettings->GetRootSelected(); 1700 sal_uLong nChildSel = pSettings->GetChildSelected(); 1701 1702 for( sal_uInt16 nEntry = 1; nEntry < SC_CONTENT_COUNT; ++nEntry ) 1703 { 1704 if( pRootNodes[ nEntry ] ) 1705 { 1706 // expand 1707 sal_Bool bExp = pSettings->IsExpanded( nEntry ); 1708 if( bExp != IsExpanded( pRootNodes[ nEntry ] ) ) 1709 { 1710 if( bExp ) 1711 Expand( pRootNodes[ nEntry ] ); 1712 else 1713 Collapse( pRootNodes[ nEntry ] ); 1714 } 1715 1716 // select 1717 if( nRootSel == nEntry ) 1718 { 1719 SvLBoxEntry* pEntry = NULL; 1720 if( bExp && (nChildSel != SC_CONTENT_NOCHILD) ) 1721 pEntry = GetEntry( pRootNodes[ nEntry ], nChildSel ); 1722 Select( pEntry ? pEntry : pRootNodes[ nEntry ] ); 1723 } 1724 } 1725 } 1726 } 1727 } 1728 1729 void ScContentTree::StoreSettings() const 1730 { 1731 ScNavigatorSettings* pSettings = pParentWindow->GetNavigatorSettings(); 1732 if( pSettings ) 1733 { 1734 for( sal_uInt16 nEntry = 1; nEntry < SC_CONTENT_COUNT; ++nEntry ) 1735 { 1736 sal_Bool bExp = pRootNodes[ nEntry ] && IsExpanded( pRootNodes[ nEntry ] ); 1737 pSettings->SetExpanded( nEntry, bExp ); 1738 } 1739 sal_uInt16 nRoot; 1740 sal_uLong nChild; 1741 GetEntryIndexes( nRoot, nChild, GetCurEntry() ); 1742 pSettings->SetRootSelected( nRoot ); 1743 pSettings->SetChildSelected( nChild ); 1744 } 1745 } 1746 1747 class ScContentLBoxString : public SvLBoxString 1748 { 1749 public: 1750 ScContentLBoxString( SvLBoxEntry* pEntry, sal_uInt16 nFlags, 1751 const String& rStr ) : SvLBoxString(pEntry,nFlags,rStr) {} 1752 1753 virtual void Paint( const Point& rPos, SvLBox& rDev, sal_uInt16 nFlags, 1754 SvLBoxEntry* pEntry); 1755 }; 1756 void ScContentTree::InitEntry(SvLBoxEntry* pEntry, 1757 const XubString& rStr ,const Image& rImg1,const Image& rImg2, SvLBoxButtonKind eButtonKind) 1758 { 1759 sal_uInt16 nColToHilite = 1; //0==Bitmap;1=="Spalte1";2=="Spalte2" 1760 SvTreeListBox::InitEntry( pEntry, rStr, rImg1, rImg2, eButtonKind ); 1761 SvLBoxString* pCol = (SvLBoxString*)pEntry->GetItem( nColToHilite ); 1762 ScContentLBoxString* pStr = new ScContentLBoxString( pEntry, 0, pCol->GetText() ); 1763 pEntry->ReplaceItem( pStr, nColToHilite ); 1764 } 1765 void ScContentLBoxString::Paint( const Point& rPos, SvLBox& rDev, sal_uInt16 nFlags, 1766 SvLBoxEntry* pEntry ) 1767 { 1768 // IA2 CWS. MT: Removed for now (also in SvLBoxEntry) - only used in Sw/Sd/ScContentLBoxString, they should decide if they need this 1769 /* 1770 if (pEntry->IsMarked()) 1771 { 1772 rDev.DrawText( rPos, GetText() ); 1773 XubString str; 1774 str = XubString::CreateFromAscii("*"); 1775 Point rPosStar(rPos.X()-6,rPos.Y()); 1776 Font aOldFont( rDev.GetFont()); 1777 Font aFont(aOldFont); 1778 Color aCol( aOldFont.GetColor() ); 1779 aCol.DecreaseLuminance( 200 ); 1780 aFont.SetColor( aCol ); 1781 rDev.SetFont( aFont ); 1782 rDev.DrawText( rPosStar, str); 1783 rDev.SetFont( aOldFont ); 1784 } 1785 else 1786 */ 1787 SvLBoxString::Paint( rPos, rDev, nFlags, pEntry); 1788 } 1789 // 1790 //------------------------------------------------------------------------ 1791 // 1792 1793 1794 1795 1796 1797