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 InsertContent( SC_CONTENT_DBAREA, aStrName ); 739 } 740 } 741 } 742 743 bool ScContentTree::IsPartOfType( sal_uInt16 nContentType, sal_uInt16 nObjIdentifier ) // static 744 { 745 bool bRet = false; 746 switch ( nContentType ) 747 { 748 case SC_CONTENT_GRAPHIC: 749 bRet = ( nObjIdentifier == OBJ_GRAF ); 750 break; 751 case SC_CONTENT_OLEOBJECT: 752 bRet = ( nObjIdentifier == OBJ_OLE2 ); 753 break; 754 case SC_CONTENT_DRAWING: 755 bRet = ( nObjIdentifier != OBJ_GRAF && nObjIdentifier != OBJ_OLE2 ); // everything else 756 break; 757 default: 758 DBG_ERROR("unknown content type"); 759 } 760 return bRet; 761 } 762 763 void ScContentTree::GetDrawNames( sal_uInt16 nType ) 764 { 765 if ( nRootType && nRootType != nType ) // ausgeblendet ? 766 return; 767 768 ScDocument* pDoc = GetSourceDocument(); 769 if (!pDoc) 770 return; 771 772 // iterate in flat mode for groups 773 SdrIterMode eIter = ( nType == SC_CONTENT_DRAWING ) ? IM_FLAT : IM_DEEPNOGROUPS; 774 775 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer(); 776 SfxObjectShell* pShell = pDoc->GetDocumentShell(); 777 if (pDrawLayer && pShell) 778 { 779 SCTAB nTabCount = pDoc->GetTableCount(); 780 for (SCTAB nTab=0; nTab<nTabCount; nTab++) 781 { 782 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab)); 783 DBG_ASSERT(pPage,"Page ?"); 784 if (pPage) 785 { 786 SdrObjListIter aIter( *pPage, eIter ); 787 SdrObject* pObject = aIter.Next(); 788 while (pObject) 789 { 790 if ( IsPartOfType( nType, pObject->GetObjIdentifier() ) ) 791 { 792 String aName = ScDrawLayer::GetVisibleName( pObject ); 793 if (aName.Len()) 794 InsertContent( nType, aName ); 795 } 796 797 pObject = aIter.Next(); 798 } 799 } 800 } 801 } 802 } 803 804 void ScContentTree::GetGraphicNames() 805 { 806 GetDrawNames( SC_CONTENT_GRAPHIC ); 807 } 808 809 void ScContentTree::GetOleNames() 810 { 811 GetDrawNames( SC_CONTENT_OLEOBJECT ); 812 } 813 814 void ScContentTree::GetDrawingNames() 815 { 816 GetDrawNames( SC_CONTENT_DRAWING ); 817 } 818 819 void ScContentTree::GetLinkNames() 820 { 821 if ( nRootType && nRootType != SC_CONTENT_AREALINK ) // ausgeblendet ? 822 return; 823 824 ScDocument* pDoc = GetSourceDocument(); 825 if (!pDoc) 826 return; 827 828 sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager(); 829 DBG_ASSERT(pLinkManager, "kein LinkManager am Dokument?"); 830 const ::sfx2::SvBaseLinks& rLinks = pLinkManager->GetLinks(); 831 sal_uInt16 nCount = rLinks.Count(); 832 for (sal_uInt16 i=0; i<nCount; i++) 833 { 834 ::sfx2::SvBaseLink* pBase = *rLinks[i]; 835 if (pBase->ISA(ScAreaLink)) 836 InsertContent( SC_CONTENT_AREALINK, ((ScAreaLink*)pBase)->GetSource() ); 837 838 // in der Liste die Namen der Quellbereiche 839 } 840 } 841 842 const ScAreaLink* ScContentTree::GetLink( sal_uLong nIndex ) 843 { 844 ScDocument* pDoc = GetSourceDocument(); 845 if (!pDoc) 846 return NULL; 847 848 sal_uLong nFound = 0; 849 sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager(); 850 DBG_ASSERT(pLinkManager, "kein LinkManager am Dokument?"); 851 const ::sfx2::SvBaseLinks& rLinks = pLinkManager->GetLinks(); 852 sal_uInt16 nCount = rLinks.Count(); 853 for (sal_uInt16 i=0; i<nCount; i++) 854 { 855 ::sfx2::SvBaseLink* pBase = *rLinks[i]; 856 if (pBase->ISA(ScAreaLink)) 857 { 858 if (nFound == nIndex) 859 return (const ScAreaLink*) pBase; 860 ++nFound; 861 } 862 } 863 864 DBG_ERROR("Link nicht gefunden"); 865 return NULL; 866 } 867 868 String lcl_NoteString( const ScPostIt& rNote ) 869 { 870 String aText = rNote.GetText(); 871 xub_StrLen nAt; 872 while ( (nAt = aText.Search( '\n' )) != STRING_NOTFOUND ) 873 aText.SetChar( nAt, ' ' ); 874 return aText; 875 } 876 877 void ScContentTree::GetNoteStrings() 878 { 879 if ( nRootType && nRootType != SC_CONTENT_NOTE ) // ausgeblendet ? 880 return; 881 882 ScDocument* pDoc = GetSourceDocument(); 883 if (!pDoc) 884 return; 885 886 SCTAB nTabCount = pDoc->GetTableCount(); 887 for (SCTAB nTab=0; nTab<nTabCount; nTab++) 888 { 889 ScCellIterator aIter( pDoc, 0,0,nTab, MAXCOL,MAXROW,nTab ); 890 for( ScBaseCell* pCell = aIter.GetFirst(); pCell; pCell = aIter.GetNext() ) 891 if( const ScPostIt* pNote = pCell->GetNote() ) 892 InsertContent( SC_CONTENT_NOTE, lcl_NoteString( *pNote ) ); 893 } 894 } 895 896 ScAddress ScContentTree::GetNotePos( sal_uLong nIndex ) 897 { 898 ScDocument* pDoc = GetSourceDocument(); 899 if (!pDoc) 900 return ScAddress(); 901 902 sal_uLong nFound = 0; 903 SCTAB nTabCount = pDoc->GetTableCount(); 904 for (SCTAB nTab=0; nTab<nTabCount; nTab++) 905 { 906 ScCellIterator aIter( pDoc, 0,0,nTab, MAXCOL,MAXROW,nTab ); 907 ScBaseCell* pCell = aIter.GetFirst(); 908 while (pCell) 909 { 910 if( pCell->HasNote() ) 911 { 912 if (nFound == nIndex) 913 return ScAddress( aIter.GetCol(), aIter.GetRow(), nTab ); // gefunden 914 ++nFound; 915 } 916 pCell = aIter.GetNext(); 917 } 918 } 919 920 DBG_ERROR("Notiz nicht gefunden"); 921 return ScAddress(); 922 } 923 924 sal_Bool ScContentTree::NoteStringsChanged() 925 { 926 ScDocument* pDoc = GetSourceDocument(); 927 if (!pDoc) 928 return sal_False; 929 930 SvLBoxEntry* pParent = pRootNodes[SC_CONTENT_NOTE]; 931 if (!pParent) 932 return sal_False; 933 934 SvLBoxEntry* pEntry = FirstChild( pParent ); 935 936 sal_Bool bEqual = sal_True; 937 SCTAB nTabCount = pDoc->GetTableCount(); 938 for (SCTAB nTab=0; nTab<nTabCount && bEqual; nTab++) 939 { 940 ScCellIterator aIter( pDoc, 0,0,nTab, MAXCOL,MAXROW,nTab ); 941 ScBaseCell* pCell = aIter.GetFirst(); 942 while (pCell && bEqual) 943 { 944 if( const ScPostIt* pNote = pCell->GetNote() ) 945 { 946 if ( !pEntry ) 947 bEqual = sal_False; 948 else 949 { 950 if ( lcl_NoteString( *pNote ) != GetEntryText(pEntry) ) 951 bEqual = sal_False; 952 953 pEntry = NextSibling( pEntry ); 954 } 955 } 956 pCell = aIter.GetNext(); 957 } 958 } 959 960 if ( pEntry ) 961 bEqual = sal_False; // kommt noch was 962 963 return !bEqual; 964 } 965 966 sal_Bool ScContentTree::DrawNamesChanged( sal_uInt16 nType ) 967 { 968 ScDocument* pDoc = GetSourceDocument(); 969 if (!pDoc) 970 return sal_False; 971 972 SvLBoxEntry* pParent = pRootNodes[nType]; 973 if (!pParent) 974 return sal_False; 975 976 SvLBoxEntry* pEntry = FirstChild( pParent ); 977 978 // iterate in flat mode for groups 979 SdrIterMode eIter = ( nType == SC_CONTENT_DRAWING ) ? IM_FLAT : IM_DEEPNOGROUPS; 980 981 sal_Bool bEqual = sal_True; 982 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer(); 983 SfxObjectShell* pShell = pDoc->GetDocumentShell(); 984 if (pDrawLayer && pShell) 985 { 986 SCTAB nTabCount = pDoc->GetTableCount(); 987 for (SCTAB nTab=0; nTab<nTabCount && bEqual; nTab++) 988 { 989 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab)); 990 DBG_ASSERT(pPage,"Page ?"); 991 if (pPage) 992 { 993 SdrObjListIter aIter( *pPage, eIter ); 994 SdrObject* pObject = aIter.Next(); 995 while (pObject && bEqual) 996 { 997 if ( IsPartOfType( nType, pObject->GetObjIdentifier() ) ) 998 { 999 if ( !pEntry ) 1000 bEqual = sal_False; 1001 else 1002 { 1003 if ( ScDrawLayer::GetVisibleName( pObject ) != GetEntryText(pEntry) ) 1004 bEqual = sal_False; 1005 1006 pEntry = NextSibling( pEntry ); 1007 } 1008 } 1009 pObject = aIter.Next(); 1010 } 1011 } 1012 } 1013 } 1014 1015 if ( pEntry ) 1016 bEqual = sal_False; // kommt noch was 1017 1018 return !bEqual; 1019 } 1020 1021 sal_Bool lcl_GetRange( ScDocument* pDoc, sal_uInt16 nType, const String& rName, ScRange& rRange ) 1022 { 1023 sal_Bool bFound = sal_False; 1024 sal_uInt16 nPos; 1025 1026 if ( nType == SC_CONTENT_RANGENAME ) 1027 { 1028 ScRangeName* pList = pDoc->GetRangeName(); 1029 if (pList) 1030 if (pList->SearchName( rName, nPos )) 1031 if ( (*pList)[nPos]->IsValidReference( rRange ) ) 1032 bFound = sal_True; 1033 } 1034 else if ( nType == SC_CONTENT_DBAREA ) 1035 { 1036 ScDBCollection* pList = pDoc->GetDBCollection(); 1037 if (pList) 1038 if (pList->SearchName( rName, nPos )) 1039 { 1040 SCTAB nTab; 1041 SCCOL nCol1, nCol2; 1042 SCROW nRow1, nRow2; 1043 (*pList)[nPos]->GetArea(nTab,nCol1,nRow1,nCol2,nRow2); 1044 rRange = ScRange( nCol1,nRow1,nTab, nCol2,nRow2,nTab ); 1045 bFound = sal_True; 1046 } 1047 } 1048 1049 return bFound; 1050 } 1051 1052 void lcl_DoDragObject( ScDocShell* pSrcShell, const String& rName, sal_uInt16 nType, Window* pWin ) 1053 { 1054 ScDocument* pSrcDoc = pSrcShell->GetDocument(); 1055 ScDrawLayer* pModel = pSrcDoc->GetDrawLayer(); 1056 if (pModel) 1057 { 1058 sal_Bool bOle = ( nType == SC_CONTENT_OLEOBJECT ); 1059 sal_Bool bGraf = ( nType == SC_CONTENT_GRAPHIC ); 1060 sal_uInt16 nDrawId = sal::static_int_cast<sal_uInt16>( bOle ? OBJ_OLE2 : ( bGraf ? OBJ_GRAF : OBJ_GRUP ) ); 1061 SCTAB nTab = 0; 1062 SdrObject* pObject = pModel->GetNamedObject( rName, nDrawId, nTab ); 1063 if (pObject) 1064 { 1065 SdrView aEditView( pModel ); 1066 aEditView.ShowSdrPage(aEditView.GetModel()->GetPage(nTab)); 1067 SdrPageView* pPV = aEditView.GetSdrPageView(); 1068 aEditView.MarkObj(pObject, pPV); 1069 1070 SdrModel* pDragModel = aEditView.GetAllMarkedModel(); 1071 1072 TransferableObjectDescriptor aObjDesc; 1073 pSrcShell->FillTransferableObjectDescriptor( aObjDesc ); 1074 aObjDesc.maDisplayName = pSrcShell->GetMedium()->GetURLObject().GetURLNoPass(); 1075 // maSize is set in ScDrawTransferObj ctor 1076 1077 ScDrawTransferObj* pTransferObj = new ScDrawTransferObj( pDragModel, pSrcShell, aObjDesc ); 1078 uno::Reference<datatransfer::XTransferable> xTransferable( pTransferObj ); 1079 1080 pTransferObj->SetDragSourceObj( pObject, nTab ); 1081 pTransferObj->SetDragSourceFlags( SC_DROP_NAVIGATOR ); 1082 1083 SC_MOD()->SetDragObject( NULL, pTransferObj ); 1084 pWin->ReleaseMouse(); 1085 pTransferObj->StartDrag( pWin, DND_ACTION_COPYMOVE | DND_ACTION_LINK ); 1086 } 1087 } 1088 } 1089 1090 void lcl_DoDragCells( ScDocShell* pSrcShell, const ScRange& rRange, sal_uInt16 nFlags, Window* pWin ) 1091 { 1092 ScMarkData aMark; 1093 aMark.SelectTable( rRange.aStart.Tab(), sal_True ); 1094 aMark.SetMarkArea( rRange ); 1095 1096 ScDocument* pSrcDoc = pSrcShell->GetDocument(); 1097 if ( !pSrcDoc->HasSelectedBlockMatrixFragment( rRange.aStart.Col(), rRange.aStart.Row(), 1098 rRange.aEnd.Col(), rRange.aEnd.Row(), 1099 aMark ) ) 1100 { 1101 ScDocument* pClipDoc = new ScDocument( SCDOCMODE_CLIP ); 1102 ScClipParam aClipParam(rRange, false); 1103 pSrcDoc->CopyToClip(aClipParam, pClipDoc, &aMark); 1104 // pClipDoc->ExtendMerge( rRange, sal_True ); 1105 1106 TransferableObjectDescriptor aObjDesc; 1107 pSrcShell->FillTransferableObjectDescriptor( aObjDesc ); 1108 aObjDesc.maDisplayName = pSrcShell->GetMedium()->GetURLObject().GetURLNoPass(); 1109 // maSize is set in ScTransferObj ctor 1110 1111 ScTransferObj* pTransferObj = new ScTransferObj( pClipDoc, aObjDesc ); 1112 uno::Reference<datatransfer::XTransferable> xTransferable( pTransferObj ); 1113 1114 pTransferObj->SetDragSource( pSrcShell, aMark ); 1115 pTransferObj->SetDragSourceFlags( nFlags ); 1116 1117 SC_MOD()->SetDragObject( pTransferObj, NULL ); // for internal D&D 1118 pWin->ReleaseMouse(); 1119 pTransferObj->StartDrag( pWin, DND_ACTION_COPYMOVE | DND_ACTION_LINK ); 1120 } 1121 } 1122 1123 void ScContentTree::DoDrag() 1124 { 1125 ScDocumentLoader* pDocLoader = NULL; 1126 bIsInDrag = sal_True; 1127 1128 ScModule* pScMod = SC_MOD(); 1129 1130 sal_uInt16 nType; 1131 sal_uLong nChild; 1132 SvLBoxEntry* pEntry = GetCurEntry(); 1133 GetEntryIndexes( nType, nChild, pEntry ); 1134 1135 if( pEntry && 1136 (nChild != SC_CONTENT_NOCHILD) && 1137 (nType != SC_CONTENT_ROOT) && 1138 (nType != SC_CONTENT_NOTE) && 1139 (nType != SC_CONTENT_AREALINK) ) 1140 { 1141 String aText( GetEntryText( pEntry ) ); 1142 1143 ScDocument* pLocalDoc = NULL; // fuer URL-Drop 1144 String aDocName; 1145 if (bHiddenDoc) 1146 aDocName = aHiddenName; 1147 else 1148 { 1149 ScDocShell* pDocSh = GetManualOrCurrent(); 1150 if (pDocSh) 1151 { 1152 if (pDocSh->HasName()) 1153 aDocName = pDocSh->GetMedium()->GetName(); 1154 else 1155 pLocalDoc = pDocSh->GetDocument(); // Drop nur in dieses Dokument 1156 } 1157 } 1158 1159 sal_Bool bDoLinkTrans = sal_False; // use ScLinkTransferObj 1160 String aLinkURL; // for ScLinkTransferObj 1161 String aLinkText; 1162 1163 sal_uInt16 nDropMode = pParentWindow->GetDropMode(); 1164 switch ( nDropMode ) 1165 { 1166 case SC_DROPMODE_URL: 1167 { 1168 String aUrl = aDocName; 1169 aUrl += '#'; 1170 aUrl += aText; 1171 1172 pScMod->SetDragJump( pLocalDoc, aUrl, aText ); 1173 1174 if (aDocName.Len()) 1175 { 1176 // provide URL to outside only if the document has a name 1177 // (without name, only internal D&D via SetDragJump) 1178 1179 aLinkURL = aUrl; 1180 aLinkText = aText; 1181 } 1182 bDoLinkTrans = sal_True; 1183 } 1184 break; 1185 case SC_DROPMODE_LINK: 1186 { 1187 if ( aDocName.Len() ) // link only to named documents 1188 { 1189 // for internal D&D, set flag to insert a link 1190 1191 switch ( nType ) 1192 { 1193 case SC_CONTENT_TABLE: 1194 pScMod->SetDragLink( aDocName, aText, EMPTY_STRING ); 1195 bDoLinkTrans = sal_True; 1196 break; 1197 case SC_CONTENT_RANGENAME: 1198 case SC_CONTENT_DBAREA: 1199 pScMod->SetDragLink( aDocName, EMPTY_STRING, aText ); 1200 bDoLinkTrans = sal_True; 1201 break; 1202 1203 // other types cannot be linked 1204 } 1205 } 1206 } 1207 break; 1208 case SC_DROPMODE_COPY: 1209 { 1210 ScDocShell* pSrcShell = NULL; 1211 if ( bHiddenDoc ) 1212 { 1213 String aFilter, aOptions; 1214 pDocLoader = new ScDocumentLoader( aHiddenName, aFilter, aOptions ); 1215 if (!pDocLoader->IsError()) 1216 pSrcShell = pDocLoader->GetDocShell(); 1217 } 1218 else 1219 pSrcShell = GetManualOrCurrent(); 1220 1221 if ( pSrcShell ) 1222 { 1223 ScDocument* pSrcDoc = pSrcShell->GetDocument(); 1224 if ( nType == SC_CONTENT_RANGENAME || nType == SC_CONTENT_DBAREA ) 1225 { 1226 ScRange aRange; 1227 if ( lcl_GetRange( pSrcDoc, nType, aText, aRange ) ) 1228 { 1229 lcl_DoDragCells( pSrcShell, aRange, SC_DROP_NAVIGATOR, this ); 1230 } 1231 } 1232 else if ( nType == SC_CONTENT_TABLE ) 1233 { 1234 SCTAB nTab; 1235 if ( pSrcDoc->GetTable( aText, nTab ) ) 1236 { 1237 ScRange aRange( 0,0,nTab, MAXCOL,MAXROW,nTab ); 1238 lcl_DoDragCells( pSrcShell, aRange, SC_DROP_NAVIGATOR | SC_DROP_TABLE, this ); 1239 } 1240 } 1241 else if ( nType == SC_CONTENT_GRAPHIC || nType == SC_CONTENT_OLEOBJECT || 1242 nType == SC_CONTENT_DRAWING ) 1243 { 1244 lcl_DoDragObject( pSrcShell, aText, nType, this ); 1245 1246 // in ExecuteDrag kann der Navigator geloescht worden sein 1247 // -> nicht mehr auf Member zugreifen !!! 1248 } 1249 } 1250 } 1251 break; 1252 } 1253 1254 if (bDoLinkTrans) 1255 { 1256 ScLinkTransferObj* pTransferObj = new ScLinkTransferObj; 1257 uno::Reference<datatransfer::XTransferable> xTransferable( pTransferObj ); 1258 1259 if ( aLinkURL.Len() ) 1260 pTransferObj->SetLinkURL( aLinkURL, aLinkText ); 1261 1262 // SetDragJump / SetDragLink has been done above 1263 1264 ReleaseMouse(); 1265 pTransferObj->StartDrag( this, DND_ACTION_COPYMOVE | DND_ACTION_LINK ); 1266 } 1267 } 1268 1269 bIsInDrag = sal_False; // static Member 1270 1271 delete pDocLoader; // falls Dokument zum Draggen geladen wurde 1272 } 1273 1274 IMPL_STATIC_LINK(ScContentTree, ExecDragHdl, void*, EMPTYARG) 1275 { 1276 // als Link, damit asynchron ohne ImpMouseMoveMsg auf dem Stack auch der 1277 // Navigator geloescht werden darf 1278 1279 pThis->DoDrag(); 1280 return 0; 1281 } 1282 1283 //UNUSED2008-05 void ScContentTree::AdjustTitle() 1284 //UNUSED2008-05 { 1285 //UNUSED2008-05 String aTitle = pParentWindow->aTitleBase; 1286 //UNUSED2008-05 if (bHiddenDoc) 1287 //UNUSED2008-05 { 1288 //UNUSED2008-05 aTitle.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " - " )); 1289 //UNUSED2008-05 aTitle += aHiddenTitle; 1290 //UNUSED2008-05 } 1291 //UNUSED2008-05 pParentWindow->SetText(aTitle); 1292 //UNUSED2008-05 } 1293 1294 sal_Bool ScContentTree::LoadFile( const String& rUrl ) 1295 { 1296 String aDocName = rUrl; 1297 xub_StrLen nPos = aDocName.Search('#'); 1298 if ( nPos != STRING_NOTFOUND ) 1299 aDocName.Erase(nPos); // nur der Name, ohne #... 1300 1301 sal_Bool bReturn = sal_False; 1302 String aFilter, aOptions; 1303 ScDocumentLoader aLoader( aDocName, aFilter, aOptions ); 1304 if ( !aLoader.IsError() ) 1305 { 1306 bHiddenDoc = sal_True; 1307 aHiddenName = aDocName; 1308 aHiddenTitle = aLoader.GetTitle(); 1309 pHiddenDocument = aLoader.GetDocument(); 1310 1311 Refresh(); // Inhalte aus geladenem Dokument holen 1312 1313 pHiddenDocument = NULL; 1314 // AdjustTitle(); 1315 1316 pParentWindow->GetDocNames( &aHiddenTitle ); // Liste fuellen 1317 } 1318 else 1319 Sound::Beep(); // Fehler beim Laden 1320 1321 // Dokument wird im dtor von ScDocumentLoader wieder geschlossen 1322 1323 return bReturn; 1324 } 1325 1326 void ScContentTree::InitWindowBits( sal_Bool bButtons ) 1327 { 1328 WinBits nFlags = GetStyle()|WB_CLIPCHILDREN|WB_HSCROLL; 1329 if (bButtons) 1330 nFlags |= WB_HASBUTTONS|WB_HASBUTTONSATROOT; 1331 1332 SetStyle( nFlags ); 1333 } 1334 1335 void ScContentTree::SetRootType( sal_uInt16 nNew ) 1336 { 1337 if ( nNew != nRootType ) 1338 { 1339 nRootType = nNew; 1340 InitWindowBits( nNew == 0 ); 1341 Refresh(); 1342 1343 ScNavipiCfg& rCfg = SC_MOD()->GetNavipiCfg(); 1344 rCfg.SetRootType( nRootType ); 1345 } 1346 } 1347 1348 void ScContentTree::ToggleRoot() // nach Selektion 1349 { 1350 sal_uInt16 nNew = SC_CONTENT_ROOT; 1351 if ( nRootType == SC_CONTENT_ROOT ) 1352 { 1353 SvLBoxEntry* pEntry = GetCurEntry(); 1354 if (pEntry) 1355 { 1356 SvLBoxEntry* pParent = GetParent(pEntry); 1357 for (sal_uInt16 i=1; i<SC_CONTENT_COUNT; i++) 1358 if ( pEntry == pRootNodes[i] || pParent == pRootNodes[i] ) 1359 nNew = i; 1360 } 1361 } 1362 1363 SetRootType( nNew ); 1364 } 1365 1366 void ScContentTree::ResetManualDoc() 1367 { 1368 aManualDoc.Erase(); 1369 bHiddenDoc = sal_False; 1370 1371 ActiveDocChanged(); 1372 } 1373 1374 void ScContentTree::ActiveDocChanged() 1375 { 1376 if ( !bHiddenDoc && !aManualDoc.Len() ) 1377 Refresh(); // Inhalte nur wenn automatisch 1378 1379 // Listbox muss immer geupdated werden, wegen aktiv-Flag 1380 1381 String aCurrent; 1382 if ( bHiddenDoc ) 1383 aCurrent = aHiddenTitle; 1384 else 1385 { 1386 ScDocShell* pSh = GetManualOrCurrent(); 1387 if (pSh) 1388 aCurrent = pSh->GetTitle(); 1389 else 1390 { 1391 // eingestelltes Dokument existiert nicht mehr 1392 1393 aManualDoc.Erase(); // wieder automatisch 1394 Refresh(); 1395 pSh = GetManualOrCurrent(); // sollte jetzt aktives sein 1396 if (pSh) 1397 aCurrent = pSh->GetTitle(); 1398 } 1399 } 1400 pParentWindow->GetDocNames( &aCurrent ); // selektieren 1401 } 1402 1403 void ScContentTree::SetManualDoc(const String& rName) 1404 { 1405 aManualDoc = rName; 1406 if (!bHiddenDoc) 1407 { 1408 Refresh(); 1409 pParentWindow->GetDocNames( &aManualDoc ); // selektieren 1410 } 1411 } 1412 1413 void ScContentTree::SelectDoc(const String& rName) // rName wie im Menue/Listbox angezeigt 1414 { 1415 if ( rName == pParentWindow->aStrActiveWin ) 1416 { 1417 ResetManualDoc(); 1418 return; 1419 } 1420 1421 // "aktiv" oder "inaktiv" weglassen 1422 1423 String aRealName = rName; 1424 xub_StrLen nLen = rName.Len(); 1425 xub_StrLen nActiveStart = nLen - pParentWindow->aStrActive.Len(); 1426 if ( rName.Copy( nActiveStart ) == pParentWindow->aStrActive ) 1427 aRealName = rName.Copy( 0, nActiveStart ); 1428 xub_StrLen nNotActiveStart = nLen - pParentWindow->aStrNotActive.Len(); 1429 if ( rName.Copy( nNotActiveStart ) == pParentWindow->aStrNotActive ) 1430 aRealName = rName.Copy( 0, nNotActiveStart ); 1431 1432 // 1433 1434 sal_Bool bLoaded = sal_False; 1435 1436 // ist es ein normal geladenes Doc ? 1437 1438 SfxObjectShell* pSh = SfxObjectShell::GetFirst(); 1439 while ( pSh && !bLoaded ) 1440 { 1441 if ( pSh->ISA(ScDocShell) ) 1442 if ( pSh->GetTitle() == aRealName ) 1443 bLoaded = sal_True; 1444 pSh = SfxObjectShell::GetNext( *pSh ); 1445 } 1446 1447 if (bLoaded) 1448 { 1449 bHiddenDoc = sal_False; 1450 SetManualDoc(aRealName); 1451 } 1452 else if (aHiddenTitle.Len()) // verstecktes ausgewaehlt 1453 { 1454 if (!bHiddenDoc) 1455 LoadFile(aHiddenName); 1456 } 1457 else 1458 { 1459 DBG_ERROR("SelectDoc: nicht gefunden"); 1460 } 1461 } 1462 1463 void ScContentTree::ApplySettings() 1464 { 1465 const ScNavigatorSettings* pSettings = pParentWindow->GetNavigatorSettings(); 1466 if( pSettings ) 1467 { 1468 sal_uInt16 nRootSel = pSettings->GetRootSelected(); 1469 sal_uLong nChildSel = pSettings->GetChildSelected(); 1470 1471 for( sal_uInt16 nEntry = 1; nEntry < SC_CONTENT_COUNT; ++nEntry ) 1472 { 1473 if( pRootNodes[ nEntry ] ) 1474 { 1475 // expand 1476 sal_Bool bExp = pSettings->IsExpanded( nEntry ); 1477 if( bExp != IsExpanded( pRootNodes[ nEntry ] ) ) 1478 { 1479 if( bExp ) 1480 Expand( pRootNodes[ nEntry ] ); 1481 else 1482 Collapse( pRootNodes[ nEntry ] ); 1483 } 1484 1485 // select 1486 if( nRootSel == nEntry ) 1487 { 1488 SvLBoxEntry* pEntry = NULL; 1489 if( bExp && (nChildSel != SC_CONTENT_NOCHILD) ) 1490 pEntry = GetEntry( pRootNodes[ nEntry ], nChildSel ); 1491 Select( pEntry ? pEntry : pRootNodes[ nEntry ] ); 1492 } 1493 } 1494 } 1495 } 1496 } 1497 1498 void ScContentTree::StoreSettings() const 1499 { 1500 ScNavigatorSettings* pSettings = pParentWindow->GetNavigatorSettings(); 1501 if( pSettings ) 1502 { 1503 for( sal_uInt16 nEntry = 1; nEntry < SC_CONTENT_COUNT; ++nEntry ) 1504 { 1505 sal_Bool bExp = pRootNodes[ nEntry ] && IsExpanded( pRootNodes[ nEntry ] ); 1506 pSettings->SetExpanded( nEntry, bExp ); 1507 } 1508 sal_uInt16 nRoot; 1509 sal_uLong nChild; 1510 GetEntryIndexes( nRoot, nChild, GetCurEntry() ); 1511 pSettings->SetRootSelected( nRoot ); 1512 pSettings->SetChildSelected( nChild ); 1513 } 1514 } 1515 1516 1517 // 1518 //------------------------------------------------------------------------ 1519 // 1520 1521 1522 1523 1524 1525