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 "clipparam.hxx" 68 69 using namespace com::sun::star; 70 71 // Reihenfolge der Kategorien im Navigator ------------------------------------- 72 73 static sal_uInt16 pTypeList[SC_CONTENT_COUNT] = 74 { 75 SC_CONTENT_ROOT, // ROOT (0) muss vorne stehen 76 SC_CONTENT_TABLE, 77 SC_CONTENT_RANGENAME, 78 SC_CONTENT_DBAREA, 79 SC_CONTENT_AREALINK, 80 SC_CONTENT_GRAPHIC, 81 SC_CONTENT_OLEOBJECT, 82 SC_CONTENT_NOTE, 83 SC_CONTENT_DRAWING 84 }; 85 86 sal_Bool ScContentTree::bIsInDrag = sal_False; 87 88 89 ScDocShell* ScContentTree::GetManualOrCurrent() 90 { 91 ScDocShell* pSh = NULL; 92 if ( aManualDoc.Len() ) 93 { 94 TypeId aScType = TYPE(ScDocShell); 95 SfxObjectShell* pObjSh = SfxObjectShell::GetFirst( &aScType ); 96 while ( pObjSh && !pSh ) 97 { 98 if ( pObjSh->GetTitle() == aManualDoc ) 99 pSh = PTR_CAST( ScDocShell, pObjSh ); 100 pObjSh = SfxObjectShell::GetNext( *pObjSh, &aScType ); 101 } 102 } 103 else 104 { 105 // Current nur, wenn keine manuell eingestellt ist 106 // (damit erkannt wird, wenn das Dokument nicht mehr existiert) 107 108 SfxViewShell* pViewSh = SfxViewShell::Current(); 109 if ( pViewSh ) 110 { 111 SfxObjectShell* pObjSh = pViewSh->GetViewFrame()->GetObjectShell(); 112 pSh = PTR_CAST( ScDocShell, pObjSh ); 113 } 114 } 115 116 return pSh; 117 } 118 119 // 120 // ScContentTree 121 // 122 123 ScContentTree::ScContentTree( Window* pParent, const ResId& rResId ) : 124 SvTreeListBox ( pParent, rResId ), 125 aEntryImages ( ScResId( RID_IMAGELIST_NAVCONT ) ), 126 aHCEntryImages ( ScResId( RID_IMAGELIST_H_NAVCONT ) ), 127 nRootType ( SC_CONTENT_ROOT ), 128 bHiddenDoc ( sal_False ), 129 pHiddenDocument ( NULL ) 130 { 131 sal_uInt16 i; 132 for (i=0; i<SC_CONTENT_COUNT; i++) 133 pPosList[pTypeList[i]] = i; // invers zum suchen 134 135 pParentWindow = (ScNavigatorDlg*)pParent; 136 137 pRootNodes[0] = NULL; 138 for (i=1; i<SC_CONTENT_COUNT; i++) 139 InitRoot(i); 140 141 SetNodeDefaultImages(); 142 143 SetDoubleClickHdl( LINK( this, ScContentTree, ContentDoubleClickHdl ) ); 144 145 SetStyle( GetStyle() | WB_QUICK_SEARCH ); 146 } 147 148 ScContentTree::~ScContentTree() 149 { 150 } 151 152 void ScContentTree::InitRoot( sal_uInt16 nType ) 153 { 154 if ( !nType ) 155 return; 156 157 if ( nRootType && nRootType != nType ) // ausgeblendet ? 158 { 159 pRootNodes[nType] = NULL; 160 return; 161 } 162 163 const Image& rImage = aEntryImages.GetImage( nType ); 164 String aName( ScResId( SCSTR_CONTENT_ROOT + nType ) ); 165 // wieder an die richtige Position: 166 sal_uInt16 nPos = nRootType ? 0 : pPosList[nType]-1; 167 SvLBoxEntry* pNew = InsertEntry( aName, rImage, rImage, NULL, sal_False, nPos ); 168 169 const Image& rHCImage = aHCEntryImages.GetImage( nType ); 170 SetExpandedEntryBmp( pNew, rHCImage, BMP_COLOR_HIGHCONTRAST ); 171 SetCollapsedEntryBmp( pNew, rHCImage, BMP_COLOR_HIGHCONTRAST ); 172 173 pRootNodes[nType] = pNew; 174 } 175 176 void ScContentTree::ClearAll() 177 { 178 Clear(); 179 for (sal_uInt16 i=1; i<SC_CONTENT_COUNT; i++) 180 InitRoot(i); 181 } 182 183 void ScContentTree::ClearType(sal_uInt16 nType) 184 { 185 if (!nType) 186 ClearAll(); 187 else 188 { 189 SvLBoxEntry* pParent = pRootNodes[nType]; 190 if ( !pParent || GetChildCount(pParent) ) // nicht, wenn ohne Children schon da 191 { 192 if (pParent) 193 GetModel()->Remove( pParent ); // mit allen Children 194 InitRoot( nType ); // ggf. neu eintragen 195 } 196 } 197 } 198 199 void ScContentTree::InsertContent( sal_uInt16 nType, const String& rValue ) 200 { 201 if (nType >= SC_CONTENT_COUNT) 202 { 203 DBG_ERROR("ScContentTree::InsertContent mit falschem Typ"); 204 return; 205 } 206 207 SvLBoxEntry* pParent = pRootNodes[nType]; 208 if (pParent) 209 InsertEntry( rValue, pParent ); 210 else 211 { 212 DBG_ERROR("InsertContent ohne Parent"); 213 } 214 } 215 216 void ScContentTree::GetEntryIndexes( sal_uInt16& rnRootIndex, sal_uLong& rnChildIndex, SvLBoxEntry* pEntry ) const 217 { 218 rnRootIndex = SC_CONTENT_ROOT; 219 rnChildIndex = SC_CONTENT_NOCHILD; 220 221 if( !pEntry ) 222 return; 223 224 SvLBoxEntry* pParent = GetParent( pEntry ); 225 bool bFound = false; 226 for( sal_uInt16 nRoot = 1; !bFound && (nRoot < SC_CONTENT_COUNT); ++nRoot ) 227 { 228 if( pEntry == pRootNodes[ nRoot ] ) 229 { 230 rnRootIndex = nRoot; 231 rnChildIndex = ~0UL; 232 bFound = true; 233 } 234 else if( pParent && (pParent == pRootNodes[ nRoot ]) ) 235 { 236 rnRootIndex = nRoot; 237 238 // search the entry in all child entries of the parent 239 sal_uLong nEntry = 0; 240 SvLBoxEntry* pIterEntry = FirstChild( pParent ); 241 while( !bFound && pIterEntry ) 242 { 243 if ( pEntry == pIterEntry ) 244 { 245 rnChildIndex = nEntry; 246 bFound = true; // exit the while loop 247 } 248 pIterEntry = NextSibling( pIterEntry ); 249 ++nEntry; 250 } 251 252 bFound = true; // exit the for loop 253 } 254 } 255 } 256 257 sal_uLong ScContentTree::GetChildIndex( SvLBoxEntry* pEntry ) const 258 { 259 sal_uInt16 nRoot; 260 sal_uLong nChild; 261 GetEntryIndexes( nRoot, nChild, pEntry ); 262 return nChild; 263 } 264 265 String lcl_GetDBAreaRange( ScDocument* pDoc, const String& rDBName ) 266 { 267 String aRet; 268 if (pDoc) 269 { 270 ScDBCollection* pDbNames = pDoc->GetDBCollection(); 271 sal_uInt16 nCount = pDbNames->GetCount(); 272 for ( sal_uInt16 i=0; i<nCount; i++ ) 273 { 274 ScDBData* pData = (*pDbNames)[i]; 275 if ( pData->GetName() == rDBName ) 276 { 277 ScRange aRange; 278 pData->GetArea(aRange); 279 aRange.Format( aRet, SCR_ABS_3D, pDoc ); 280 break; 281 } 282 } 283 } 284 return aRet; 285 } 286 287 IMPL_LINK( ScContentTree, ContentDoubleClickHdl, ScContentTree *, EMPTYARG ) 288 { 289 sal_uInt16 nType; 290 sal_uLong nChild; 291 SvLBoxEntry* pEntry = GetCurEntry(); 292 GetEntryIndexes( nType, nChild, pEntry ); 293 294 if( pEntry && (nType != SC_CONTENT_ROOT) && (nChild != SC_CONTENT_NOCHILD) ) 295 { 296 if ( bHiddenDoc ) 297 return 0; //! spaeter... 298 299 String aText( GetEntryText( pEntry ) ); 300 301 if ( aManualDoc.Len() ) 302 pParentWindow->SetCurrentDoc( aManualDoc ); 303 304 switch( nType ) 305 { 306 case SC_CONTENT_TABLE: 307 pParentWindow->SetCurrentTableStr( aText ); 308 break; 309 310 case SC_CONTENT_RANGENAME: 311 pParentWindow->SetCurrentCellStr( aText ); 312 break; 313 314 case SC_CONTENT_DBAREA: 315 { 316 // #47905# Wenn gleiche Bereichs- und DB-Namen existieren, wird 317 // bei SID_CURRENTCELL der Bereichsname genommen. 318 // DB-Bereiche darum direkt ueber die Adresse anspringen. 319 320 String aRangeStr = lcl_GetDBAreaRange( GetSourceDocument(), aText ); 321 if (aRangeStr.Len()) 322 pParentWindow->SetCurrentCellStr( aRangeStr ); 323 } 324 break; 325 326 case SC_CONTENT_OLEOBJECT: 327 case SC_CONTENT_GRAPHIC: 328 case SC_CONTENT_DRAWING: 329 pParentWindow->SetCurrentObject( aText ); 330 break; 331 332 case SC_CONTENT_NOTE: 333 { 334 ScAddress aPos = GetNotePos( nChild ); 335 pParentWindow->SetCurrentTable( aPos.Tab() ); 336 pParentWindow->SetCurrentCell( aPos.Col(), aPos.Row() ); 337 } 338 break; 339 340 case SC_CONTENT_AREALINK: 341 { 342 const ScAreaLink* pLink = GetLink( nChild ); 343 if( pLink ) 344 { 345 ScRange aRange = pLink->GetDestArea(); 346 String aRangeStr; 347 ScDocument* pSrcDoc = GetSourceDocument(); 348 aRange.Format( aRangeStr, SCR_ABS_3D, pSrcDoc, pSrcDoc->GetAddressConvention() ); 349 pParentWindow->SetCurrentCellStr( aRangeStr ); 350 } 351 } 352 break; 353 } 354 355 ScNavigatorDlg::ReleaseFocus(); // set focus into document 356 } 357 358 return 0; 359 } 360 361 void ScContentTree::MouseButtonDown( const MouseEvent& rMEvt ) 362 { 363 SvTreeListBox::MouseButtonDown( rMEvt ); 364 StoreSettings(); 365 } 366 367 void ScContentTree::KeyInput( const KeyEvent& rKEvt ) 368 { 369 sal_Bool bUsed = sal_False; 370 371 const KeyCode aCode = rKEvt.GetKeyCode(); 372 if (aCode.GetCode() == KEY_RETURN) 373 { 374 switch (aCode.GetModifier()) 375 { 376 case KEY_MOD1: 377 ToggleRoot(); // toggle root mode (as in Writer) 378 bUsed = sal_True; 379 break; 380 case 0: 381 { 382 SvLBoxEntry* pEntry = GetCurEntry(); 383 if( pEntry ) 384 { 385 sal_uInt16 nType; 386 sal_uLong nChild; 387 GetEntryIndexes( nType, nChild, pEntry ); 388 389 if( (nType != SC_CONTENT_ROOT) && (nChild == SC_CONTENT_NOCHILD) ) 390 { 391 String aText( GetEntryText( pEntry ) ); 392 if ( IsExpanded( pEntry ) ) 393 Collapse( pEntry ); 394 else 395 Expand( pEntry ); 396 } 397 else 398 ContentDoubleClickHdl(0); // select content as if double clicked 399 } 400 401 bUsed = sal_True; 402 } 403 break; 404 } 405 } 406 StoreSettings(); 407 408 if( !bUsed ) 409 SvTreeListBox::KeyInput(rKEvt); 410 } 411 412 //sal_Bool __EXPORT ScContentTree::Drop( const DropEvent& rEvt ) 413 //{ 414 // return pParentWindow->Drop(rEvt); // Drop auf Navigator 415 //} 416 417 //sal_Bool __EXPORT ScContentTree::QueryDrop( DropEvent& rEvt ) 418 //{ 419 // return pParentWindow->QueryDrop(rEvt); // Drop auf Navigator 420 //} 421 422 sal_Int8 ScContentTree::AcceptDrop( const AcceptDropEvent& /* rEvt */ ) 423 { 424 return DND_ACTION_NONE; 425 } 426 427 sal_Int8 ScContentTree::ExecuteDrop( const ExecuteDropEvent& /* rEvt */ ) 428 { 429 return DND_ACTION_NONE; 430 } 431 432 void ScContentTree::StartDrag( sal_Int8 /* nAction */, const Point& /* rPosPixel */ ) 433 { 434 DoDrag(); 435 } 436 437 void ScContentTree::DragFinished( sal_Int8 /* nAction */ ) 438 { 439 } 440 441 void __EXPORT ScContentTree::Command( const CommandEvent& rCEvt ) 442 { 443 sal_Bool bDone = sal_False; 444 445 switch ( rCEvt.GetCommand() ) 446 { 447 case COMMAND_STARTDRAG: 448 // Aus dem ExecuteDrag heraus kann der Navigator geloescht werden 449 // (beim Umschalten auf einen anderen Dokument-Typ), das wuerde aber 450 // den StarView MouseMove-Handler, der Command() aufruft, umbringen. 451 // Deshalb Drag&Drop asynchron: 452 453 // DoDrag(); 454 455 Application::PostUserEvent( STATIC_LINK( this, ScContentTree, ExecDragHdl ) ); 456 457 bDone = sal_True; 458 break; 459 460 case COMMAND_CONTEXTMENU: 461 { 462 // Drag-Drop Modus 463 464 PopupMenu aPop; 465 ScPopupMenu aDropMenu( ScResId( RID_POPUP_DROPMODE ) ); 466 aDropMenu.CheckItem( RID_DROPMODE_URL + pParentWindow->GetDropMode() ); 467 aPop.InsertItem( 1, pParentWindow->GetStrDragMode() ); 468 aPop.SetPopupMenu( 1, &aDropMenu ); 469 470 // angezeigtes Dokument 471 472 ScPopupMenu aDocMenu; 473 aDocMenu.SetMenuFlags( aDocMenu.GetMenuFlags() | MENU_FLAG_NOAUTOMNEMONICS ); 474 sal_uInt16 i=0; 475 sal_uInt16 nPos=0; 476 // geladene Dokumente 477 ScDocShell* pCurrentSh = PTR_CAST( ScDocShell, SfxObjectShell::Current() ); 478 SfxObjectShell* pSh = SfxObjectShell::GetFirst(); 479 while ( pSh ) 480 { 481 if ( pSh->ISA(ScDocShell) ) 482 { 483 String aName = pSh->GetTitle(); 484 String aEntry = aName; 485 if ( pSh == pCurrentSh ) 486 aEntry += pParentWindow->aStrActive; 487 else 488 aEntry += pParentWindow->aStrNotActive; 489 aDocMenu.InsertItem( ++i, aEntry ); 490 if ( !bHiddenDoc && aName == aManualDoc ) 491 nPos = i; 492 } 493 pSh = SfxObjectShell::GetNext( *pSh ); 494 } 495 // "aktives Fenster" 496 aDocMenu.InsertItem( ++i, pParentWindow->aStrActiveWin ); 497 if (!bHiddenDoc && !aManualDoc.Len()) 498 nPos = i; 499 // verstecktes Dokument 500 if ( aHiddenTitle.Len() ) 501 { 502 String aEntry = aHiddenTitle; 503 aEntry += pParentWindow->aStrHidden; 504 aDocMenu.InsertItem( ++i, aEntry ); 505 if (bHiddenDoc) 506 nPos = i; 507 } 508 aDocMenu.CheckItem( nPos ); 509 aPop.InsertItem( 2, pParentWindow->GetStrDisplay() ); 510 aPop.SetPopupMenu( 2, &aDocMenu ); 511 512 // ausfuehren 513 514 aPop.Execute( this, rCEvt.GetMousePosPixel() ); 515 516 if ( aDropMenu.WasHit() ) // Drag-Drop Modus 517 { 518 sal_uInt16 nId = aDropMenu.GetSelected(); 519 if ( nId >= RID_DROPMODE_URL && nId <= RID_DROPMODE_COPY ) 520 pParentWindow->SetDropMode( nId - RID_DROPMODE_URL ); 521 } 522 else if ( aDocMenu.WasHit() ) // angezeigtes Dokument 523 { 524 sal_uInt16 nId = aDocMenu.GetSelected(); 525 String aName = aDocMenu.GetItemText(nId); 526 SelectDoc( aName ); 527 } 528 } 529 break; 530 } 531 532 if (!bDone) 533 SvTreeListBox::Command(rCEvt); 534 } 535 536 void __EXPORT ScContentTree::RequestHelp( const HelpEvent& rHEvt ) 537 { 538 sal_Bool bDone = sal_False; 539 if( rHEvt.GetMode() & HELPMODE_QUICK ) 540 { 541 Point aPos( ScreenToOutputPixel( rHEvt.GetMousePosPixel() )); 542 SvLBoxEntry* pEntry = GetEntry( aPos ); 543 if ( pEntry ) 544 { 545 sal_Bool bRet = sal_False; 546 String aHelpText; 547 SvLBoxEntry* pParent = GetParent(pEntry); 548 if ( !pParent ) // Top-Level ? 549 { 550 aHelpText = String::CreateFromInt32( GetChildCount(pEntry) ); 551 aHelpText += ' '; 552 aHelpText += GetEntryText(pEntry); 553 bRet = sal_True; 554 } 555 else if ( pParent == pRootNodes[SC_CONTENT_NOTE] ) 556 { 557 aHelpText = GetEntryText(pEntry); // Notizen als Help-Text 558 bRet = sal_True; 559 } 560 else if ( pParent == pRootNodes[SC_CONTENT_AREALINK] ) 561 { 562 sal_uLong nIndex = GetChildIndex(pEntry); 563 if( nIndex != SC_CONTENT_NOCHILD ) 564 { 565 const ScAreaLink* pLink = GetLink(nIndex); 566 if (pLink) 567 { 568 aHelpText = pLink->GetFile(); // Source-Datei als Help-Text 569 bRet = sal_True; 570 } 571 } 572 } 573 574 if (bRet) 575 { 576 SvLBoxTab* pTab; 577 SvLBoxString* pItem = (SvLBoxString*)(GetItem( pEntry, aPos.X(), &pTab )); 578 if( pItem ) 579 { 580 aPos = GetEntryPosition( pEntry ); 581 aPos.X() = GetTabPos( pEntry, pTab ); 582 aPos = OutputToScreenPixel(aPos); 583 Size aSize( pItem->GetSize( this, pEntry ) ); 584 585 Rectangle aItemRect( aPos, aSize ); 586 Help::ShowQuickHelp( this, aItemRect, aHelpText ); 587 bDone = sal_True; 588 } 589 } 590 } 591 } 592 if (!bDone) 593 Window::RequestHelp( rHEvt ); 594 } 595 596 ScDocument* ScContentTree::GetSourceDocument() 597 { 598 if (bHiddenDoc) 599 return pHiddenDocument; 600 else 601 { 602 ScDocShell* pSh = GetManualOrCurrent(); 603 if (pSh) 604 return pSh->GetDocument(); 605 606 } 607 return NULL; 608 } 609 610 void ScContentTree::Refresh( sal_uInt16 nType ) 611 { 612 if ( bHiddenDoc && !pHiddenDocument ) 613 return; // anderes Dokument angezeigt 614 615 // wenn sich nichts geaendert hat, gleich abbrechen (gegen Geflacker) 616 617 if ( nType == SC_CONTENT_NOTE ) 618 if (!NoteStringsChanged()) 619 return; 620 if ( nType == SC_CONTENT_GRAPHIC ) 621 if (!DrawNamesChanged(SC_CONTENT_GRAPHIC)) 622 return; 623 if ( nType == SC_CONTENT_OLEOBJECT ) 624 if (!DrawNamesChanged(SC_CONTENT_OLEOBJECT)) 625 return; 626 if ( nType == SC_CONTENT_DRAWING ) 627 if (!DrawNamesChanged(SC_CONTENT_DRAWING)) 628 return; 629 630 SetUpdateMode(sal_False); 631 632 ClearType( nType ); 633 634 if ( !nType || nType == SC_CONTENT_TABLE ) 635 GetTableNames(); 636 if ( !nType || nType == SC_CONTENT_RANGENAME ) 637 GetAreaNames(); 638 if ( !nType || nType == SC_CONTENT_DBAREA ) 639 GetDbNames(); 640 if ( !nType || nType == SC_CONTENT_GRAPHIC ) 641 GetGraphicNames(); 642 if ( !nType || nType == SC_CONTENT_OLEOBJECT ) 643 GetOleNames(); 644 if ( !nType || nType == SC_CONTENT_DRAWING ) 645 GetDrawingNames(); 646 if ( !nType || nType == SC_CONTENT_NOTE ) 647 GetNoteStrings(); 648 if ( !nType || nType == SC_CONTENT_AREALINK ) 649 GetLinkNames(); 650 651 ApplySettings(); 652 SetUpdateMode(sal_True); 653 } 654 655 void ScContentTree::GetTableNames() 656 { 657 if ( nRootType && nRootType != SC_CONTENT_TABLE ) // ausgeblendet ? 658 return; 659 660 ScDocument* pDoc = GetSourceDocument(); 661 if (!pDoc) 662 return; 663 664 String aName; 665 SCTAB nCount = pDoc->GetTableCount(); 666 for ( SCTAB i=0; i<nCount; i++ ) 667 { 668 pDoc->GetName( i, aName ); 669 InsertContent( SC_CONTENT_TABLE, aName ); 670 } 671 } 672 673 void ScContentTree::GetAreaNames() 674 { 675 if ( nRootType && nRootType != SC_CONTENT_RANGENAME ) // ausgeblendet ? 676 return; 677 678 ScDocument* pDoc = GetSourceDocument(); 679 if (!pDoc) 680 return; 681 682 ScRangeName* pRangeNames = pDoc->GetRangeName(); 683 sal_uInt16 nCount = pRangeNames->GetCount(); 684 if ( nCount > 0 ) 685 { 686 sal_uInt16 nValidCount = 0; 687 ScRange aDummy; 688 sal_uInt16 i; 689 for ( i=0; i<nCount; i++ ) 690 { 691 ScRangeData* pData = (*pRangeNames)[i]; 692 if (pData->IsValidReference(aDummy)) 693 nValidCount++; 694 } 695 if ( nValidCount ) 696 { 697 ScRangeData** ppSortArray = new ScRangeData* [ nValidCount ]; 698 sal_uInt16 j; 699 for ( i=0, j=0; i<nCount; i++ ) 700 { 701 ScRangeData* pData = (*pRangeNames)[i]; 702 if (pData->IsValidReference(aDummy)) 703 ppSortArray[j++] = pData; 704 } 705 #ifndef ICC 706 qsort( (void*)ppSortArray, nValidCount, sizeof(ScRangeData*), 707 &ScRangeData_QsortNameCompare ); 708 #else 709 qsort( (void*)ppSortArray, nValidCount, sizeof(ScRangeData*), 710 ICCQsortNameCompare ); 711 #endif 712 for ( j=0; j<nValidCount; j++ ) 713 InsertContent( SC_CONTENT_RANGENAME, ppSortArray[j]->GetName() ); 714 delete [] ppSortArray; 715 } 716 } 717 } 718 719 void ScContentTree::GetDbNames() 720 { 721 if ( nRootType && nRootType != SC_CONTENT_DBAREA ) // ausgeblendet ? 722 return; 723 724 ScDocument* pDoc = GetSourceDocument(); 725 if (!pDoc) 726 return; 727 728 ScDBCollection* pDbNames = pDoc->GetDBCollection(); 729 sal_uInt16 nCount = pDbNames->GetCount(); 730 if ( nCount > 0 ) 731 { 732 String aStrNoName( ScGlobal::GetRscString(STR_DB_NONAME) ); 733 for ( sal_uInt16 i=0; i<nCount; i++ ) 734 { 735 ScDBData* pData = (*pDbNames)[i]; 736 String aStrName = pData->GetName(); 737 //if ( aStrName != aStrNoName ) 738 if ( !pData->IsBuildin() ) 739 InsertContent( SC_CONTENT_DBAREA, aStrName ); 740 } 741 } 742 } 743 744 bool ScContentTree::IsPartOfType( sal_uInt16 nContentType, sal_uInt16 nObjIdentifier ) // static 745 { 746 bool bRet = false; 747 switch ( nContentType ) 748 { 749 case SC_CONTENT_GRAPHIC: 750 bRet = ( nObjIdentifier == OBJ_GRAF ); 751 break; 752 case SC_CONTENT_OLEOBJECT: 753 bRet = ( nObjIdentifier == OBJ_OLE2 ); 754 break; 755 case SC_CONTENT_DRAWING: 756 bRet = ( nObjIdentifier != OBJ_GRAF && nObjIdentifier != OBJ_OLE2 ); // everything else 757 break; 758 default: 759 DBG_ERROR("unknown content type"); 760 } 761 return bRet; 762 } 763 764 void ScContentTree::GetDrawNames( sal_uInt16 nType ) 765 { 766 if ( nRootType && nRootType != nType ) // ausgeblendet ? 767 return; 768 769 ScDocument* pDoc = GetSourceDocument(); 770 if (!pDoc) 771 return; 772 773 // iterate in flat mode for groups 774 SdrIterMode eIter = ( nType == SC_CONTENT_DRAWING ) ? IM_FLAT : IM_DEEPNOGROUPS; 775 776 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer(); 777 SfxObjectShell* pShell = pDoc->GetDocumentShell(); 778 if (pDrawLayer && pShell) 779 { 780 SCTAB nTabCount = pDoc->GetTableCount(); 781 for (SCTAB nTab=0; nTab<nTabCount; nTab++) 782 { 783 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab)); 784 DBG_ASSERT(pPage,"Page ?"); 785 if (pPage) 786 { 787 SdrObjListIter aIter( *pPage, eIter ); 788 SdrObject* pObject = aIter.Next(); 789 while (pObject) 790 { 791 if ( IsPartOfType( nType, pObject->GetObjIdentifier() ) ) 792 { 793 String aName = ScDrawLayer::GetVisibleName( pObject ); 794 if (aName.Len()) 795 InsertContent( nType, aName ); 796 } 797 798 pObject = aIter.Next(); 799 } 800 } 801 } 802 } 803 } 804 805 void ScContentTree::GetGraphicNames() 806 { 807 GetDrawNames( SC_CONTENT_GRAPHIC ); 808 } 809 810 void ScContentTree::GetOleNames() 811 { 812 GetDrawNames( SC_CONTENT_OLEOBJECT ); 813 } 814 815 void ScContentTree::GetDrawingNames() 816 { 817 GetDrawNames( SC_CONTENT_DRAWING ); 818 } 819 820 void ScContentTree::GetLinkNames() 821 { 822 if ( nRootType && nRootType != SC_CONTENT_AREALINK ) // ausgeblendet ? 823 return; 824 825 ScDocument* pDoc = GetSourceDocument(); 826 if (!pDoc) 827 return; 828 829 sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager(); 830 DBG_ASSERT(pLinkManager, "kein LinkManager am Dokument?"); 831 const ::sfx2::SvBaseLinks& rLinks = pLinkManager->GetLinks(); 832 sal_uInt16 nCount = rLinks.Count(); 833 for (sal_uInt16 i=0; i<nCount; i++) 834 { 835 ::sfx2::SvBaseLink* pBase = *rLinks[i]; 836 if (pBase->ISA(ScAreaLink)) 837 InsertContent( SC_CONTENT_AREALINK, ((ScAreaLink*)pBase)->GetSource() ); 838 839 // in der Liste die Namen der Quellbereiche 840 } 841 } 842 843 const ScAreaLink* ScContentTree::GetLink( sal_uLong nIndex ) 844 { 845 ScDocument* pDoc = GetSourceDocument(); 846 if (!pDoc) 847 return NULL; 848 849 sal_uLong nFound = 0; 850 sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager(); 851 DBG_ASSERT(pLinkManager, "kein LinkManager am Dokument?"); 852 const ::sfx2::SvBaseLinks& rLinks = pLinkManager->GetLinks(); 853 sal_uInt16 nCount = rLinks.Count(); 854 for (sal_uInt16 i=0; i<nCount; i++) 855 { 856 ::sfx2::SvBaseLink* pBase = *rLinks[i]; 857 if (pBase->ISA(ScAreaLink)) 858 { 859 if (nFound == nIndex) 860 return (const ScAreaLink*) pBase; 861 ++nFound; 862 } 863 } 864 865 DBG_ERROR("Link nicht gefunden"); 866 return NULL; 867 } 868 869 String lcl_NoteString( const ScPostIt& rNote ) 870 { 871 String aText = rNote.GetText(); 872 xub_StrLen nAt; 873 while ( (nAt = aText.Search( '\n' )) != STRING_NOTFOUND ) 874 aText.SetChar( nAt, ' ' ); 875 return aText; 876 } 877 878 void ScContentTree::GetNoteStrings() 879 { 880 if ( nRootType && nRootType != SC_CONTENT_NOTE ) // ausgeblendet ? 881 return; 882 883 ScDocument* pDoc = GetSourceDocument(); 884 if (!pDoc) 885 return; 886 887 SCTAB nTabCount = pDoc->GetTableCount(); 888 for (SCTAB nTab=0; nTab<nTabCount; nTab++) 889 { 890 ScCellIterator aIter( pDoc, 0,0,nTab, MAXCOL,MAXROW,nTab ); 891 for( ScBaseCell* pCell = aIter.GetFirst(); pCell; pCell = aIter.GetNext() ) 892 if( const ScPostIt* pNote = pCell->GetNote() ) 893 InsertContent( SC_CONTENT_NOTE, lcl_NoteString( *pNote ) ); 894 } 895 } 896 897 ScAddress ScContentTree::GetNotePos( sal_uLong nIndex ) 898 { 899 ScDocument* pDoc = GetSourceDocument(); 900 if (!pDoc) 901 return ScAddress(); 902 903 sal_uLong nFound = 0; 904 SCTAB nTabCount = pDoc->GetTableCount(); 905 for (SCTAB nTab=0; nTab<nTabCount; nTab++) 906 { 907 ScCellIterator aIter( pDoc, 0,0,nTab, MAXCOL,MAXROW,nTab ); 908 ScBaseCell* pCell = aIter.GetFirst(); 909 while (pCell) 910 { 911 if( pCell->HasNote() ) 912 { 913 if (nFound == nIndex) 914 return ScAddress( aIter.GetCol(), aIter.GetRow(), nTab ); // gefunden 915 ++nFound; 916 } 917 pCell = aIter.GetNext(); 918 } 919 } 920 921 DBG_ERROR("Notiz nicht gefunden"); 922 return ScAddress(); 923 } 924 925 sal_Bool ScContentTree::NoteStringsChanged() 926 { 927 ScDocument* pDoc = GetSourceDocument(); 928 if (!pDoc) 929 return sal_False; 930 931 SvLBoxEntry* pParent = pRootNodes[SC_CONTENT_NOTE]; 932 if (!pParent) 933 return sal_False; 934 935 SvLBoxEntry* pEntry = FirstChild( pParent ); 936 937 sal_Bool bEqual = sal_True; 938 SCTAB nTabCount = pDoc->GetTableCount(); 939 for (SCTAB nTab=0; nTab<nTabCount && bEqual; nTab++) 940 { 941 ScCellIterator aIter( pDoc, 0,0,nTab, MAXCOL,MAXROW,nTab ); 942 ScBaseCell* pCell = aIter.GetFirst(); 943 while (pCell && bEqual) 944 { 945 if( const ScPostIt* pNote = pCell->GetNote() ) 946 { 947 if ( !pEntry ) 948 bEqual = sal_False; 949 else 950 { 951 if ( lcl_NoteString( *pNote ) != GetEntryText(pEntry) ) 952 bEqual = sal_False; 953 954 pEntry = NextSibling( pEntry ); 955 } 956 } 957 pCell = aIter.GetNext(); 958 } 959 } 960 961 if ( pEntry ) 962 bEqual = sal_False; // kommt noch was 963 964 return !bEqual; 965 } 966 967 sal_Bool ScContentTree::DrawNamesChanged( sal_uInt16 nType ) 968 { 969 ScDocument* pDoc = GetSourceDocument(); 970 if (!pDoc) 971 return sal_False; 972 973 SvLBoxEntry* pParent = pRootNodes[nType]; 974 if (!pParent) 975 return sal_False; 976 977 SvLBoxEntry* pEntry = FirstChild( pParent ); 978 979 // iterate in flat mode for groups 980 SdrIterMode eIter = ( nType == SC_CONTENT_DRAWING ) ? IM_FLAT : IM_DEEPNOGROUPS; 981 982 sal_Bool bEqual = sal_True; 983 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer(); 984 SfxObjectShell* pShell = pDoc->GetDocumentShell(); 985 if (pDrawLayer && pShell) 986 { 987 SCTAB nTabCount = pDoc->GetTableCount(); 988 for (SCTAB nTab=0; nTab<nTabCount && bEqual; nTab++) 989 { 990 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab)); 991 DBG_ASSERT(pPage,"Page ?"); 992 if (pPage) 993 { 994 SdrObjListIter aIter( *pPage, eIter ); 995 SdrObject* pObject = aIter.Next(); 996 while (pObject && bEqual) 997 { 998 if ( IsPartOfType( nType, pObject->GetObjIdentifier() ) ) 999 { 1000 if ( !pEntry ) 1001 bEqual = sal_False; 1002 else 1003 { 1004 if ( ScDrawLayer::GetVisibleName( pObject ) != GetEntryText(pEntry) ) 1005 bEqual = sal_False; 1006 1007 pEntry = NextSibling( pEntry ); 1008 } 1009 } 1010 pObject = aIter.Next(); 1011 } 1012 } 1013 } 1014 } 1015 1016 if ( pEntry ) 1017 bEqual = sal_False; // kommt noch was 1018 1019 return !bEqual; 1020 } 1021 1022 sal_Bool lcl_GetRange( ScDocument* pDoc, sal_uInt16 nType, const String& rName, ScRange& rRange ) 1023 { 1024 sal_Bool bFound = sal_False; 1025 sal_uInt16 nPos; 1026 1027 if ( nType == SC_CONTENT_RANGENAME ) 1028 { 1029 ScRangeName* pList = pDoc->GetRangeName(); 1030 if (pList) 1031 if (pList->SearchName( rName, nPos )) 1032 if ( (*pList)[nPos]->IsValidReference( rRange ) ) 1033 bFound = sal_True; 1034 } 1035 else if ( nType == SC_CONTENT_DBAREA ) 1036 { 1037 ScDBCollection* pList = pDoc->GetDBCollection(); 1038 if (pList) 1039 if (pList->SearchName( rName, nPos )) 1040 { 1041 SCTAB nTab; 1042 SCCOL nCol1, nCol2; 1043 SCROW nRow1, nRow2; 1044 (*pList)[nPos]->GetArea(nTab,nCol1,nRow1,nCol2,nRow2); 1045 rRange = ScRange( nCol1,nRow1,nTab, nCol2,nRow2,nTab ); 1046 bFound = sal_True; 1047 } 1048 } 1049 1050 return bFound; 1051 } 1052 1053 void lcl_DoDragObject( ScDocShell* pSrcShell, const String& rName, sal_uInt16 nType, Window* pWin ) 1054 { 1055 ScDocument* pSrcDoc = pSrcShell->GetDocument(); 1056 ScDrawLayer* pModel = pSrcDoc->GetDrawLayer(); 1057 if (pModel) 1058 { 1059 sal_Bool bOle = ( nType == SC_CONTENT_OLEOBJECT ); 1060 sal_Bool bGraf = ( nType == SC_CONTENT_GRAPHIC ); 1061 sal_uInt16 nDrawId = sal::static_int_cast<sal_uInt16>( bOle ? OBJ_OLE2 : ( bGraf ? OBJ_GRAF : OBJ_GRUP ) ); 1062 SCTAB nTab = 0; 1063 SdrObject* pObject = pModel->GetNamedObject( rName, nDrawId, nTab ); 1064 if (pObject) 1065 { 1066 SdrView aEditView( pModel ); 1067 aEditView.ShowSdrPage(aEditView.GetModel()->GetPage(nTab)); 1068 SdrPageView* pPV = aEditView.GetSdrPageView(); 1069 aEditView.MarkObj(pObject, pPV); 1070 1071 SdrModel* pDragModel = aEditView.GetAllMarkedModel(); 1072 1073 TransferableObjectDescriptor aObjDesc; 1074 pSrcShell->FillTransferableObjectDescriptor( aObjDesc ); 1075 aObjDesc.maDisplayName = pSrcShell->GetMedium()->GetURLObject().GetURLNoPass(); 1076 // maSize is set in ScDrawTransferObj ctor 1077 1078 ScDrawTransferObj* pTransferObj = new ScDrawTransferObj( pDragModel, pSrcShell, aObjDesc ); 1079 uno::Reference<datatransfer::XTransferable> xTransferable( pTransferObj ); 1080 1081 pTransferObj->SetDragSourceObj( pObject, nTab ); 1082 pTransferObj->SetDragSourceFlags( SC_DROP_NAVIGATOR ); 1083 1084 SC_MOD()->SetDragObject( NULL, pTransferObj ); 1085 pWin->ReleaseMouse(); 1086 pTransferObj->StartDrag( pWin, DND_ACTION_COPYMOVE | DND_ACTION_LINK ); 1087 } 1088 } 1089 } 1090 1091 void lcl_DoDragCells( ScDocShell* pSrcShell, const ScRange& rRange, sal_uInt16 nFlags, Window* pWin ) 1092 { 1093 ScMarkData aMark; 1094 aMark.SelectTable( rRange.aStart.Tab(), sal_True ); 1095 aMark.SetMarkArea( rRange ); 1096 1097 ScDocument* pSrcDoc = pSrcShell->GetDocument(); 1098 if ( !pSrcDoc->HasSelectedBlockMatrixFragment( rRange.aStart.Col(), rRange.aStart.Row(), 1099 rRange.aEnd.Col(), rRange.aEnd.Row(), 1100 aMark ) ) 1101 { 1102 ScDocument* pClipDoc = new ScDocument( SCDOCMODE_CLIP ); 1103 ScClipParam aClipParam(rRange, false); 1104 pSrcDoc->CopyToClip(aClipParam, pClipDoc, &aMark); 1105 // pClipDoc->ExtendMerge( rRange, sal_True ); 1106 1107 TransferableObjectDescriptor aObjDesc; 1108 pSrcShell->FillTransferableObjectDescriptor( aObjDesc ); 1109 aObjDesc.maDisplayName = pSrcShell->GetMedium()->GetURLObject().GetURLNoPass(); 1110 // maSize is set in ScTransferObj ctor 1111 1112 ScTransferObj* pTransferObj = new ScTransferObj( pClipDoc, aObjDesc ); 1113 uno::Reference<datatransfer::XTransferable> xTransferable( pTransferObj ); 1114 1115 pTransferObj->SetDragSource( pSrcShell, aMark ); 1116 pTransferObj->SetDragSourceFlags( nFlags ); 1117 1118 SC_MOD()->SetDragObject( pTransferObj, NULL ); // for internal D&D 1119 pWin->ReleaseMouse(); 1120 pTransferObj->StartDrag( pWin, DND_ACTION_COPYMOVE | DND_ACTION_LINK ); 1121 } 1122 } 1123 1124 void ScContentTree::DoDrag() 1125 { 1126 ScDocumentLoader* pDocLoader = NULL; 1127 bIsInDrag = sal_True; 1128 1129 ScModule* pScMod = SC_MOD(); 1130 1131 sal_uInt16 nType; 1132 sal_uLong nChild; 1133 SvLBoxEntry* pEntry = GetCurEntry(); 1134 GetEntryIndexes( nType, nChild, pEntry ); 1135 1136 if( pEntry && 1137 (nChild != SC_CONTENT_NOCHILD) && 1138 (nType != SC_CONTENT_ROOT) && 1139 (nType != SC_CONTENT_NOTE) && 1140 (nType != SC_CONTENT_AREALINK) ) 1141 { 1142 String aText( GetEntryText( pEntry ) ); 1143 1144 ScDocument* pLocalDoc = NULL; // fuer URL-Drop 1145 String aDocName; 1146 if (bHiddenDoc) 1147 aDocName = aHiddenName; 1148 else 1149 { 1150 ScDocShell* pDocSh = GetManualOrCurrent(); 1151 if (pDocSh) 1152 { 1153 if (pDocSh->HasName()) 1154 aDocName = pDocSh->GetMedium()->GetName(); 1155 else 1156 pLocalDoc = pDocSh->GetDocument(); // Drop nur in dieses Dokument 1157 } 1158 } 1159 1160 sal_Bool bDoLinkTrans = sal_False; // use ScLinkTransferObj 1161 String aLinkURL; // for ScLinkTransferObj 1162 String aLinkText; 1163 1164 sal_uInt16 nDropMode = pParentWindow->GetDropMode(); 1165 switch ( nDropMode ) 1166 { 1167 case SC_DROPMODE_URL: 1168 { 1169 String aUrl = aDocName; 1170 aUrl += '#'; 1171 aUrl += aText; 1172 1173 pScMod->SetDragJump( pLocalDoc, aUrl, aText ); 1174 1175 if (aDocName.Len()) 1176 { 1177 // provide URL to outside only if the document has a name 1178 // (without name, only internal D&D via SetDragJump) 1179 1180 aLinkURL = aUrl; 1181 aLinkText = aText; 1182 } 1183 bDoLinkTrans = sal_True; 1184 } 1185 break; 1186 case SC_DROPMODE_LINK: 1187 { 1188 if ( aDocName.Len() ) // link only to named documents 1189 { 1190 // for internal D&D, set flag to insert a link 1191 1192 switch ( nType ) 1193 { 1194 case SC_CONTENT_TABLE: 1195 pScMod->SetDragLink( aDocName, aText, EMPTY_STRING ); 1196 bDoLinkTrans = sal_True; 1197 break; 1198 case SC_CONTENT_RANGENAME: 1199 case SC_CONTENT_DBAREA: 1200 pScMod->SetDragLink( aDocName, EMPTY_STRING, aText ); 1201 bDoLinkTrans = sal_True; 1202 break; 1203 1204 // other types cannot be linked 1205 } 1206 } 1207 } 1208 break; 1209 case SC_DROPMODE_COPY: 1210 { 1211 ScDocShell* pSrcShell = NULL; 1212 if ( bHiddenDoc ) 1213 { 1214 String aFilter, aOptions; 1215 pDocLoader = new ScDocumentLoader( aHiddenName, aFilter, aOptions ); 1216 if (!pDocLoader->IsError()) 1217 pSrcShell = pDocLoader->GetDocShell(); 1218 } 1219 else 1220 pSrcShell = GetManualOrCurrent(); 1221 1222 if ( pSrcShell ) 1223 { 1224 ScDocument* pSrcDoc = pSrcShell->GetDocument(); 1225 if ( nType == SC_CONTENT_RANGENAME || nType == SC_CONTENT_DBAREA ) 1226 { 1227 ScRange aRange; 1228 if ( lcl_GetRange( pSrcDoc, nType, aText, aRange ) ) 1229 { 1230 lcl_DoDragCells( pSrcShell, aRange, SC_DROP_NAVIGATOR, this ); 1231 } 1232 } 1233 else if ( nType == SC_CONTENT_TABLE ) 1234 { 1235 SCTAB nTab; 1236 if ( pSrcDoc->GetTable( aText, nTab ) ) 1237 { 1238 ScRange aRange( 0,0,nTab, MAXCOL,MAXROW,nTab ); 1239 lcl_DoDragCells( pSrcShell, aRange, SC_DROP_NAVIGATOR | SC_DROP_TABLE, this ); 1240 } 1241 } 1242 else if ( nType == SC_CONTENT_GRAPHIC || nType == SC_CONTENT_OLEOBJECT || 1243 nType == SC_CONTENT_DRAWING ) 1244 { 1245 lcl_DoDragObject( pSrcShell, aText, nType, this ); 1246 1247 // in ExecuteDrag kann der Navigator geloescht worden sein 1248 // -> nicht mehr auf Member zugreifen !!! 1249 } 1250 } 1251 } 1252 break; 1253 } 1254 1255 if (bDoLinkTrans) 1256 { 1257 ScLinkTransferObj* pTransferObj = new ScLinkTransferObj; 1258 uno::Reference<datatransfer::XTransferable> xTransferable( pTransferObj ); 1259 1260 if ( aLinkURL.Len() ) 1261 pTransferObj->SetLinkURL( aLinkURL, aLinkText ); 1262 1263 // SetDragJump / SetDragLink has been done above 1264 1265 ReleaseMouse(); 1266 pTransferObj->StartDrag( this, DND_ACTION_COPYMOVE | DND_ACTION_LINK ); 1267 } 1268 } 1269 1270 bIsInDrag = sal_False; // static Member 1271 1272 delete pDocLoader; // falls Dokument zum Draggen geladen wurde 1273 } 1274 1275 IMPL_STATIC_LINK(ScContentTree, ExecDragHdl, void*, EMPTYARG) 1276 { 1277 // als Link, damit asynchron ohne ImpMouseMoveMsg auf dem Stack auch der 1278 // Navigator geloescht werden darf 1279 1280 pThis->DoDrag(); 1281 return 0; 1282 } 1283 1284 //UNUSED2008-05 void ScContentTree::AdjustTitle() 1285 //UNUSED2008-05 { 1286 //UNUSED2008-05 String aTitle = pParentWindow->aTitleBase; 1287 //UNUSED2008-05 if (bHiddenDoc) 1288 //UNUSED2008-05 { 1289 //UNUSED2008-05 aTitle.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " - " )); 1290 //UNUSED2008-05 aTitle += aHiddenTitle; 1291 //UNUSED2008-05 } 1292 //UNUSED2008-05 pParentWindow->SetText(aTitle); 1293 //UNUSED2008-05 } 1294 1295 sal_Bool ScContentTree::LoadFile( const String& rUrl ) 1296 { 1297 String aDocName = rUrl; 1298 xub_StrLen nPos = aDocName.Search('#'); 1299 if ( nPos != STRING_NOTFOUND ) 1300 aDocName.Erase(nPos); // nur der Name, ohne #... 1301 1302 sal_Bool bReturn = sal_False; 1303 String aFilter, aOptions; 1304 ScDocumentLoader aLoader( aDocName, aFilter, aOptions ); 1305 if ( !aLoader.IsError() ) 1306 { 1307 bHiddenDoc = sal_True; 1308 aHiddenName = aDocName; 1309 aHiddenTitle = aLoader.GetTitle(); 1310 pHiddenDocument = aLoader.GetDocument(); 1311 1312 Refresh(); // Inhalte aus geladenem Dokument holen 1313 1314 pHiddenDocument = NULL; 1315 // AdjustTitle(); 1316 1317 pParentWindow->GetDocNames( &aHiddenTitle ); // Liste fuellen 1318 } 1319 else 1320 Sound::Beep(); // Fehler beim Laden 1321 1322 // Dokument wird im dtor von ScDocumentLoader wieder geschlossen 1323 1324 return bReturn; 1325 } 1326 1327 void ScContentTree::InitWindowBits( sal_Bool bButtons ) 1328 { 1329 WinBits nFlags = GetStyle()|WB_CLIPCHILDREN|WB_HSCROLL; 1330 if (bButtons) 1331 nFlags |= WB_HASBUTTONS|WB_HASBUTTONSATROOT; 1332 1333 SetStyle( nFlags ); 1334 } 1335 1336 void ScContentTree::SetRootType( sal_uInt16 nNew ) 1337 { 1338 if ( nNew != nRootType ) 1339 { 1340 nRootType = nNew; 1341 InitWindowBits( nNew == 0 ); 1342 Refresh(); 1343 1344 ScNavipiCfg& rCfg = SC_MOD()->GetNavipiCfg(); 1345 rCfg.SetRootType( nRootType ); 1346 } 1347 } 1348 1349 void ScContentTree::ToggleRoot() // nach Selektion 1350 { 1351 sal_uInt16 nNew = SC_CONTENT_ROOT; 1352 if ( nRootType == SC_CONTENT_ROOT ) 1353 { 1354 SvLBoxEntry* pEntry = GetCurEntry(); 1355 if (pEntry) 1356 { 1357 SvLBoxEntry* pParent = GetParent(pEntry); 1358 for (sal_uInt16 i=1; i<SC_CONTENT_COUNT; i++) 1359 if ( pEntry == pRootNodes[i] || pParent == pRootNodes[i] ) 1360 nNew = i; 1361 } 1362 } 1363 1364 SetRootType( nNew ); 1365 } 1366 1367 void ScContentTree::ResetManualDoc() 1368 { 1369 aManualDoc.Erase(); 1370 bHiddenDoc = sal_False; 1371 1372 ActiveDocChanged(); 1373 } 1374 1375 void ScContentTree::ActiveDocChanged() 1376 { 1377 if ( !bHiddenDoc && !aManualDoc.Len() ) 1378 Refresh(); // Inhalte nur wenn automatisch 1379 1380 // Listbox muss immer geupdated werden, wegen aktiv-Flag 1381 1382 String aCurrent; 1383 if ( bHiddenDoc ) 1384 aCurrent = aHiddenTitle; 1385 else 1386 { 1387 ScDocShell* pSh = GetManualOrCurrent(); 1388 if (pSh) 1389 aCurrent = pSh->GetTitle(); 1390 else 1391 { 1392 // eingestelltes Dokument existiert nicht mehr 1393 1394 aManualDoc.Erase(); // wieder automatisch 1395 Refresh(); 1396 pSh = GetManualOrCurrent(); // sollte jetzt aktives sein 1397 if (pSh) 1398 aCurrent = pSh->GetTitle(); 1399 } 1400 } 1401 pParentWindow->GetDocNames( &aCurrent ); // selektieren 1402 } 1403 1404 void ScContentTree::SetManualDoc(const String& rName) 1405 { 1406 aManualDoc = rName; 1407 if (!bHiddenDoc) 1408 { 1409 Refresh(); 1410 pParentWindow->GetDocNames( &aManualDoc ); // selektieren 1411 } 1412 } 1413 1414 void ScContentTree::SelectDoc(const String& rName) // rName wie im Menue/Listbox angezeigt 1415 { 1416 if ( rName == pParentWindow->aStrActiveWin ) 1417 { 1418 ResetManualDoc(); 1419 return; 1420 } 1421 1422 // "aktiv" oder "inaktiv" weglassen 1423 1424 String aRealName = rName; 1425 xub_StrLen nLen = rName.Len(); 1426 xub_StrLen nActiveStart = nLen - pParentWindow->aStrActive.Len(); 1427 if ( rName.Copy( nActiveStart ) == pParentWindow->aStrActive ) 1428 aRealName = rName.Copy( 0, nActiveStart ); 1429 xub_StrLen nNotActiveStart = nLen - pParentWindow->aStrNotActive.Len(); 1430 if ( rName.Copy( nNotActiveStart ) == pParentWindow->aStrNotActive ) 1431 aRealName = rName.Copy( 0, nNotActiveStart ); 1432 1433 // 1434 1435 sal_Bool bLoaded = sal_False; 1436 1437 // ist es ein normal geladenes Doc ? 1438 1439 SfxObjectShell* pSh = SfxObjectShell::GetFirst(); 1440 while ( pSh && !bLoaded ) 1441 { 1442 if ( pSh->ISA(ScDocShell) ) 1443 if ( pSh->GetTitle() == aRealName ) 1444 bLoaded = sal_True; 1445 pSh = SfxObjectShell::GetNext( *pSh ); 1446 } 1447 1448 if (bLoaded) 1449 { 1450 bHiddenDoc = sal_False; 1451 SetManualDoc(aRealName); 1452 } 1453 else if (aHiddenTitle.Len()) // verstecktes ausgewaehlt 1454 { 1455 if (!bHiddenDoc) 1456 LoadFile(aHiddenName); 1457 } 1458 else 1459 { 1460 DBG_ERROR("SelectDoc: nicht gefunden"); 1461 } 1462 } 1463 1464 void ScContentTree::ApplySettings() 1465 { 1466 const ScNavigatorSettings* pSettings = pParentWindow->GetNavigatorSettings(); 1467 if( pSettings ) 1468 { 1469 sal_uInt16 nRootSel = pSettings->GetRootSelected(); 1470 sal_uLong nChildSel = pSettings->GetChildSelected(); 1471 1472 for( sal_uInt16 nEntry = 1; nEntry < SC_CONTENT_COUNT; ++nEntry ) 1473 { 1474 if( pRootNodes[ nEntry ] ) 1475 { 1476 // expand 1477 sal_Bool bExp = pSettings->IsExpanded( nEntry ); 1478 if( bExp != IsExpanded( pRootNodes[ nEntry ] ) ) 1479 { 1480 if( bExp ) 1481 Expand( pRootNodes[ nEntry ] ); 1482 else 1483 Collapse( pRootNodes[ nEntry ] ); 1484 } 1485 1486 // select 1487 if( nRootSel == nEntry ) 1488 { 1489 SvLBoxEntry* pEntry = NULL; 1490 if( bExp && (nChildSel != SC_CONTENT_NOCHILD) ) 1491 pEntry = GetEntry( pRootNodes[ nEntry ], nChildSel ); 1492 Select( pEntry ? pEntry : pRootNodes[ nEntry ] ); 1493 } 1494 } 1495 } 1496 } 1497 } 1498 1499 void ScContentTree::StoreSettings() const 1500 { 1501 ScNavigatorSettings* pSettings = pParentWindow->GetNavigatorSettings(); 1502 if( pSettings ) 1503 { 1504 for( sal_uInt16 nEntry = 1; nEntry < SC_CONTENT_COUNT; ++nEntry ) 1505 { 1506 sal_Bool bExp = pRootNodes[ nEntry ] && IsExpanded( pRootNodes[ nEntry ] ); 1507 pSettings->SetExpanded( nEntry, bExp ); 1508 } 1509 sal_uInt16 nRoot; 1510 sal_uLong nChild; 1511 GetEntryIndexes( nRoot, nChild, GetCurEntry() ); 1512 pSettings->SetRootSelected( nRoot ); 1513 pSettings->SetChildSelected( nChild ); 1514 } 1515 } 1516 1517 1518 // 1519 //------------------------------------------------------------------------ 1520 // 1521 1522 1523 1524 1525 1526