fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / navipi / content.cxx
blob571dfd63a8bbc066883a6fbb1f6a2dc6ff43264e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svx/svditer.hxx>
21 #include <svx/svdobj.hxx>
22 #include <svx/svdpage.hxx>
23 #include <svx/svdpagv.hxx>
24 #include <svx/svdview.hxx>
25 #include <svx/svdxcgv.hxx>
26 #include <sfx2/linkmgr.hxx>
27 #include <sfx2/docfile.hxx>
28 #include <sfx2/viewfrm.hxx>
29 #include <vcl/help.hxx>
30 #include <vcl/svapp.hxx>
31 #include <tools/urlobj.hxx>
32 #include <svl/urlbmk.hxx>
33 #include <svtools/svlbitm.hxx>
34 #include <svtools/treelistentry.hxx>
35 #include <stdlib.h>
37 #include "content.hxx"
38 #include "navipi.hxx"
39 #include "global.hxx"
40 #include "docsh.hxx"
41 #include "scmod.hxx"
42 #include "rangenam.hxx"
43 #include "dbdata.hxx"
44 #include "tablink.hxx"
45 #include "popmenu.hxx"
46 #include "drwlayer.hxx"
47 #include "transobj.hxx"
48 #include "drwtrans.hxx"
49 #include "lnktrans.hxx"
50 #include "formulacell.hxx"
51 #include "dociter.hxx"
52 #include "scresid.hxx"
53 #include "globstr.hrc"
54 #include "navipi.hrc"
55 #include "arealink.hxx"
56 #include "navicfg.hxx"
57 #include "navsett.hxx"
58 #include "postit.hxx"
59 #include "tabvwsh.hxx"
60 #include "drawview.hxx"
61 #include "clipparam.hxx"
62 #include "markdata.hxx"
64 using namespace com::sun::star;
66 // Reihenfolge der Kategorien im Navigator -------------------------------------
68 static const sal_uInt16 pTypeList[SC_CONTENT_COUNT] =
70 SC_CONTENT_ROOT, // ROOT (0) muss vorne stehen
71 SC_CONTENT_TABLE,
72 SC_CONTENT_RANGENAME,
73 SC_CONTENT_DBAREA,
74 SC_CONTENT_AREALINK,
75 SC_CONTENT_GRAPHIC,
76 SC_CONTENT_OLEOBJECT,
77 SC_CONTENT_NOTE,
78 SC_CONTENT_DRAWING
81 bool ScContentTree::bIsInDrag = false;
83 ScDocShell* ScContentTree::GetManualOrCurrent()
85 ScDocShell* pSh = NULL;
86 if ( !aManualDoc.isEmpty() )
88 TypeId aScType = TYPE(ScDocShell);
89 SfxObjectShell* pObjSh = SfxObjectShell::GetFirst( &aScType );
90 while ( pObjSh && !pSh )
92 if ( pObjSh->GetTitle() == aManualDoc )
93 pSh = PTR_CAST( ScDocShell, pObjSh );
94 pObjSh = SfxObjectShell::GetNext( *pObjSh, &aScType );
97 else
99 // Current nur, wenn keine manuell eingestellt ist
100 // (damit erkannt wird, wenn das Dokument nicht mehr existiert)
102 SfxViewShell* pViewSh = SfxViewShell::Current();
103 if ( pViewSh )
105 SfxObjectShell* pObjSh = pViewSh->GetViewFrame()->GetObjectShell();
106 pSh = PTR_CAST( ScDocShell, pObjSh );
110 return pSh;
113 // ScContentTree
115 ScContentTree::ScContentTree( vcl::Window* pParent, const ResId& rResId ) :
116 SvTreeListBox ( pParent, rResId ),
117 aEntryImages ( ScResId( RID_IMAGELIST_NAVCONT ) ),
118 nRootType ( SC_CONTENT_ROOT ),
119 bHiddenDoc ( false ),
120 pHiddenDocument ( NULL ),
121 bisInNavigatoeDlg ( false )
123 sal_uInt16 i;
124 for (i=0; i<SC_CONTENT_COUNT; i++)
125 pPosList[pTypeList[i]] = i; // invers zum suchen
127 pParentWindow = static_cast<ScNavigatorDlg*>(pParent);
129 pRootNodes[0] = NULL;
130 for (i=1; i<SC_CONTENT_COUNT; i++)
131 InitRoot(i);
133 SetNodeDefaultImages();
135 SetDoubleClickHdl( LINK( this, ScContentTree, ContentDoubleClickHdl ) );
137 pTmpEntry= NULL;
138 m_bFirstPaint=true;
140 SetStyle( GetStyle() | WB_QUICK_SEARCH );
143 ScContentTree::~ScContentTree()
145 disposeOnce();
148 void ScContentTree::dispose()
150 pParentWindow.clear();
151 SvTreeListBox::dispose();
154 // helper function for GetEntryAltText and GetEntryLongDescription
155 OUString ScContentTree::getAltLongDescText( SvTreeListEntry* pEntry, bool isAltText) const
157 SdrObject* pFound = NULL;
159 sal_uInt16 nType;
160 sal_uLong nChild;
161 GetEntryIndexes( nType, nChild, pEntry );
162 switch( nType )
164 case SC_CONTENT_OLEOBJECT:
165 case SC_CONTENT_GRAPHIC:
166 case SC_CONTENT_DRAWING:
168 ScDocument* pDoc = ( const_cast< ScContentTree* >(this) )->GetSourceDocument();
169 SdrIterMode eIter = ( nType == SC_CONTENT_DRAWING ) ? IM_FLAT : IM_DEEPNOGROUPS;
170 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
171 SfxObjectShell* pShell = pDoc->GetDocumentShell();
172 if (pDrawLayer && pShell)
174 sal_uInt16 nTabCount = pDoc->GetTableCount();
175 for (sal_uInt16 nTab=0; nTab<nTabCount; nTab++)
177 SdrPage* pPage = pDrawLayer->GetPage(nTab);
178 DBG_ASSERT(pPage,"Page ?");
179 if (pPage)
181 SdrObjListIter aIter( *pPage, eIter );
182 SdrObject* pObject = aIter.Next();
183 while (pObject)
185 if( ScDrawLayer::GetVisibleName( pObject ) == GetEntryText( pEntry ) )
187 pFound = pObject;
188 break;
190 pObject = aIter.Next();
195 if( pFound )
197 if( isAltText )
198 return pFound->GetTitle();
199 else
200 return pFound->GetDescription();
203 break;
205 return OUString();
208 OUString ScContentTree::GetEntryAltText( SvTreeListEntry* pEntry ) const
210 return getAltLongDescText( pEntry, true );
213 OUString ScContentTree::GetEntryLongDescription( SvTreeListEntry* pEntry ) const
215 return getAltLongDescText( pEntry, false );
218 void ScContentTree::InitRoot( sal_uInt16 nType )
220 if ( !nType )
221 return;
223 if ( nRootType && nRootType != nType ) // ausgeblendet ?
225 pRootNodes[nType] = NULL;
226 return;
229 const Image& rImage = aEntryImages.GetImage( nType );
230 OUString aName( ScResId( SCSTR_CONTENT_ROOT + nType ) );
231 // wieder an die richtige Position:
232 sal_uInt16 nPos = nRootType ? 0 : pPosList[nType]-1;
233 SvTreeListEntry* pNew = InsertEntry( aName, rImage, rImage, NULL, false, nPos );
235 pRootNodes[nType] = pNew;
238 void ScContentTree::ClearAll()
240 //There are one method in Control::SetUpdateMode(), and one override method SvTreeListBox::SetUpdateMode(). Here although
241 //SvTreeListBox::SetUpdateMode() is called in refresh method, it only call SvTreeListBox::SetUpdateMode(), not Control::SetUpdateMode().
242 //In SvTreeList::Clear(), Broadcast( LISTACTION_CLEARED ) will be called and finally, it will be trapped into the event yield() loop. And
243 //the InitRoot() method won't be called. Then if a user click or press key to update the navigator tree, crash happens.
244 //So the solution is to disable the UpdateMode of Control, then call Clear(), then recover the update mode
245 bool bOldUpdate = Control::IsUpdateMode();
246 Control::SetUpdateMode(false);
247 Clear();
248 Control::SetUpdateMode(bOldUpdate);
249 for (sal_uInt16 i=1; i<SC_CONTENT_COUNT; i++)
250 InitRoot(i);
253 void ScContentTree::ClearType(sal_uInt16 nType)
255 if (!nType)
256 ClearAll();
257 else
259 SvTreeListEntry* pParent = pRootNodes[nType];
260 if ( !pParent || GetChildCount(pParent) ) // nicht, wenn ohne Children schon da
262 if (pParent)
263 GetModel()->Remove( pParent ); // mit allen Children
264 InitRoot( nType ); // ggf. neu eintragen
269 void ScContentTree::InsertContent( sal_uInt16 nType, const OUString& rValue )
271 if (nType >= SC_CONTENT_COUNT)
273 OSL_FAIL("ScContentTree::InsertContent mit falschem Typ");
274 return;
277 SvTreeListEntry* pParent = pRootNodes[nType];
278 if (pParent)
279 InsertEntry( rValue, pParent );
280 else
282 OSL_FAIL("InsertContent ohne Parent");
286 void ScContentTree::GetEntryIndexes( sal_uInt16& rnRootIndex, sal_uLong& rnChildIndex, SvTreeListEntry* pEntry ) const
288 rnRootIndex = SC_CONTENT_ROOT;
289 rnChildIndex = SC_CONTENT_NOCHILD;
291 if( !pEntry )
292 return;
294 SvTreeListEntry* pParent = GetParent( pEntry );
295 bool bFound = false;
296 for( sal_uInt16 nRoot = 1; !bFound && (nRoot < SC_CONTENT_COUNT); ++nRoot )
298 if( pEntry == pRootNodes[ nRoot ] )
300 rnRootIndex = nRoot;
301 rnChildIndex = ~0UL;
302 bFound = true;
304 else if( pParent && (pParent == pRootNodes[ nRoot ]) )
306 rnRootIndex = nRoot;
308 // search the entry in all child entries of the parent
309 sal_uLong nEntry = 0;
310 SvTreeListEntry* pIterEntry = FirstChild( pParent );
311 while( !bFound && pIterEntry )
313 if ( pEntry == pIterEntry )
315 rnChildIndex = nEntry;
316 bFound = true; // exit the while loop
318 pIterEntry = NextSibling( pIterEntry );
319 ++nEntry;
322 bFound = true; // exit the for loop
327 sal_uLong ScContentTree::GetChildIndex( SvTreeListEntry* pEntry ) const
329 sal_uInt16 nRoot;
330 sal_uLong nChild;
331 GetEntryIndexes( nRoot, nChild, pEntry );
332 return nChild;
335 static OUString lcl_GetDBAreaRange( ScDocument* pDoc, const OUString& rDBName )
337 OUString aRet;
338 if (pDoc)
340 ScDBCollection* pDbNames = pDoc->GetDBCollection();
341 const ScDBData* pData = pDbNames->getNamedDBs().findByUpperName(ScGlobal::pCharClass->uppercase(rDBName));
342 if (pData)
344 ScRange aRange;
345 pData->GetArea(aRange);
346 aRet = aRange.Format(SCR_ABS_3D, pDoc);
349 return aRet;
352 IMPL_LINK_NOARG(ScContentTree, ContentDoubleClickHdl)
354 sal_uInt16 nType;
355 sal_uLong nChild;
356 SvTreeListEntry* pEntry = GetCurEntry();
357 GetEntryIndexes( nType, nChild, pEntry );
359 if( pEntry && (nType != SC_CONTENT_ROOT) && (nChild != SC_CONTENT_NOCHILD) )
361 if ( bHiddenDoc )
362 return 0; //! spaeter...
364 OUString aText( GetEntryText( pEntry ) );
366 if ( !aManualDoc.isEmpty() )
367 pParentWindow->SetCurrentDoc( aManualDoc );
369 switch( nType )
371 case SC_CONTENT_TABLE:
372 pParentWindow->SetCurrentTableStr( aText );
373 break;
375 case SC_CONTENT_RANGENAME:
376 pParentWindow->SetCurrentCellStr( aText );
377 break;
379 case SC_CONTENT_DBAREA:
381 // Wenn gleiche Bereichs- und DB-Namen existieren, wird
382 // bei SID_CURRENTCELL der Bereichsname genommen.
383 // DB-Bereiche darum direkt ueber die Adresse anspringen.
385 OUString aRangeStr = lcl_GetDBAreaRange( GetSourceDocument(), aText );
386 if (!aRangeStr.isEmpty())
387 pParentWindow->SetCurrentCellStr( aRangeStr );
389 break;
391 case SC_CONTENT_OLEOBJECT:
392 case SC_CONTENT_GRAPHIC:
393 case SC_CONTENT_DRAWING:
394 pParentWindow->SetCurrentObject( aText );
395 break;
397 case SC_CONTENT_NOTE:
399 ScAddress aPos = GetNotePos( nChild );
400 pParentWindow->SetCurrentTable( aPos.Tab() );
401 pParentWindow->SetCurrentCell( aPos.Col(), aPos.Row() );
403 break;
405 case SC_CONTENT_AREALINK:
407 const ScAreaLink* pLink = GetLink( nChild );
408 if( pLink )
410 ScRange aRange = pLink->GetDestArea();
411 ScDocument* pSrcDoc = GetSourceDocument();
412 OUString aRangeStr(aRange.Format(SCR_ABS_3D, pSrcDoc, pSrcDoc->GetAddressConvention()));
413 pParentWindow->SetCurrentCellStr( aRangeStr );
416 break;
419 ScNavigatorDlg::ReleaseFocus(); // set focus into document
422 return 0;
425 void ScContentTree::MouseButtonDown( const MouseEvent& rMEvt )
427 SvTreeListBox::MouseButtonDown( rMEvt );
428 StoreNavigatorSettings();
431 void ScContentTree::KeyInput( const KeyEvent& rKEvt )
433 bool bUsed = false;
435 const vcl::KeyCode aCode = rKEvt.GetKeyCode();
436 if (aCode.GetCode() == KEY_RETURN)
438 switch (aCode.GetModifier())
440 case KEY_MOD1:
441 ToggleRoot(); // toggle root mode (as in Writer)
442 bUsed = true;
443 break;
444 case 0:
446 SvTreeListEntry* pEntry = GetCurEntry();
447 if( pEntry )
449 sal_uInt16 nType;
450 sal_uLong nChild;
451 GetEntryIndexes( nType, nChild, pEntry );
453 if( (nType != SC_CONTENT_ROOT) && (nChild == SC_CONTENT_NOCHILD) )
455 if ( IsExpanded( pEntry ) )
456 Collapse( pEntry );
457 else
458 Expand( pEntry );
460 else
461 ContentDoubleClickHdl(0); // select content as if double clicked
464 bUsed = true;
466 break;
469 //Make KEY_SPACE has same function as DoubleClick
470 if ( bisInNavigatoeDlg )
472 if(aCode.GetCode() == KEY_SPACE )
474 bUsed = true;
475 sal_uInt16 nType;
476 sal_uLong nChild;
477 SvTreeListEntry* pEntry = GetCurEntry();
478 GetEntryIndexes( nType, nChild, pEntry );
479 if( pEntry && (nType != SC_CONTENT_ROOT) && (nChild != SC_CONTENT_NOCHILD) )
481 if ( bHiddenDoc )
482 return ; //! spaeter...
483 OUString aText( GetEntryText( pEntry ) );
484 sKeyString = aText;
485 if (!aManualDoc.isEmpty())
486 pParentWindow->SetCurrentDoc( aManualDoc );
487 switch( nType )
489 case SC_CONTENT_OLEOBJECT:
490 case SC_CONTENT_GRAPHIC:
491 case SC_CONTENT_DRAWING:
493 vcl::Window* pWindow=reinterpret_cast<vcl::Window*>(GetParent(pEntry));
494 ScNavigatorDlg* pScNavigatorDlg = static_cast<ScNavigatorDlg*>(pWindow);
495 ScTabViewShell* pScTabViewShell = NULL;
496 ScDrawView* pScDrawView = NULL;
497 if (pScNavigatorDlg!=NULL)
498 pScTabViewShell = ScNavigatorDlg::GetTabViewShell();
499 if(pScTabViewShell !=NULL)
500 pScDrawView =pScTabViewShell->GetViewData().GetScDrawView();
501 if(pScDrawView!=NULL)
503 pScDrawView->SelectCurrentViewObject(aText );
504 bool bHasMakredObject = false;
505 SvTreeListEntry* pParent = pRootNodes[nType];
506 SvTreeListEntry* pBeginEntry = NULL;
507 if( pParent )
508 pBeginEntry = FirstChild(pParent);
509 while( pBeginEntry )
511 OUString aTempText( GetEntryText( pBeginEntry ) );
512 if( pScDrawView->GetObjectIsMarked( pScDrawView->GetObjectByName( aTempText ) ) )
514 bHasMakredObject = true;
515 break;
517 pBeginEntry = Next( pBeginEntry );
519 if( !bHasMakredObject && pScTabViewShell)
520 pScTabViewShell->SetDrawShell(false);
521 ObjectFresh( nType,pEntry );
524 break;
530 if( !bUsed )
532 if(aCode.GetCode() == KEY_F5 )
534 StoreNavigatorSettings();
535 SvTreeListBox::KeyInput(rKEvt);
537 else
539 SvTreeListBox::KeyInput(rKEvt);
540 StoreNavigatorSettings();
545 sal_Int8 ScContentTree::AcceptDrop( const AcceptDropEvent& /* rEvt */ )
547 return DND_ACTION_NONE;
550 sal_Int8 ScContentTree::ExecuteDrop( const ExecuteDropEvent& /* rEvt */ )
552 return DND_ACTION_NONE;
555 void ScContentTree::StartDrag( sal_Int8 /* nAction */, const Point& /* rPosPixel */ )
557 DoDrag();
560 void ScContentTree::DragFinished( sal_Int8 /* nAction */ )
564 void ScContentTree::Command( const CommandEvent& rCEvt )
566 bool bDone = false;
568 switch ( rCEvt.GetCommand() )
570 case CommandEventId::StartDrag:
571 // Aus dem ExecuteDrag heraus kann der Navigator geloescht werden
572 // (beim Umschalten auf einen anderen Dokument-Typ), das wuerde aber
573 // den StarView MouseMove-Handler, der Command() aufruft, umbringen.
574 // Deshalb Drag&Drop asynchron:
576 Application::PostUserEvent( LINK( this, ScContentTree, ExecDragHdl ), NULL, true );
578 bDone = true;
579 break;
581 case CommandEventId::ContextMenu:
583 // Drag-Drop Modus
585 PopupMenu aPop;
586 ScPopupMenu aDropMenu( ScResId( RID_POPUP_DROPMODE ) );
587 aDropMenu.CheckItem( RID_DROPMODE_URL + pParentWindow->GetDropMode() );
588 aPop.InsertItem( 1, pParentWindow->GetStrDragMode() );
589 aPop.SetPopupMenu( 1, &aDropMenu );
591 // angezeigtes Dokument
593 ScPopupMenu aDocMenu;
594 aDocMenu.SetMenuFlags( aDocMenu.GetMenuFlags() | MenuFlags::NoAutoMnemonics );
595 sal_uInt16 i=0;
596 sal_uInt16 nPos=0;
597 // geladene Dokumente
598 ScDocShell* pCurrentSh = PTR_CAST( ScDocShell, SfxObjectShell::Current() );
599 SfxObjectShell* pSh = SfxObjectShell::GetFirst();
600 while ( pSh )
602 if ( pSh->ISA(ScDocShell) )
604 OUString aName = pSh->GetTitle();
605 OUString aEntry = aName;
606 if ( pSh == pCurrentSh )
607 aEntry += pParentWindow->aStrActive;
608 else
609 aEntry += pParentWindow->aStrNotActive;
610 aDocMenu.InsertItem( ++i, aEntry );
611 if ( !bHiddenDoc && aName == aManualDoc )
612 nPos = i;
614 pSh = SfxObjectShell::GetNext( *pSh );
616 // "aktives Fenster"
617 aDocMenu.InsertItem( ++i, pParentWindow->aStrActiveWin );
618 if (!bHiddenDoc && aManualDoc.isEmpty())
619 nPos = i;
620 // verstecktes Dokument
621 if ( !aHiddenTitle.isEmpty() )
623 OUString aEntry = aHiddenTitle;
624 aEntry += pParentWindow->aStrHidden;
625 aDocMenu.InsertItem( ++i, aEntry );
626 if (bHiddenDoc)
627 nPos = i;
629 aDocMenu.CheckItem( nPos );
630 aPop.InsertItem( 2, pParentWindow->GetStrDisplay() );
631 aPop.SetPopupMenu( 2, &aDocMenu );
633 // ausfuehren
635 aPop.Execute( this, rCEvt.GetMousePosPixel() );
637 if ( aDropMenu.WasHit() ) // Drag-Drop Modus
639 sal_uInt16 nId = aDropMenu.GetSelected();
640 if ( nId >= RID_DROPMODE_URL && nId <= RID_DROPMODE_COPY )
641 pParentWindow->SetDropMode( nId - RID_DROPMODE_URL );
643 else if ( aDocMenu.WasHit() ) // angezeigtes Dokument
645 sal_uInt16 nId = aDocMenu.GetSelected();
646 OUString aName = aDocMenu.GetItemText(nId);
647 SelectDoc( aName );
650 break;
651 default: break;
654 if (!bDone)
655 SvTreeListBox::Command(rCEvt);
658 void ScContentTree::RequestHelp( const HelpEvent& rHEvt )
660 bool bDone = false;
661 if( rHEvt.GetMode() & HelpEventMode::QUICK )
663 Point aPos( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ));
664 SvTreeListEntry* pEntry = GetEntry( aPos );
665 if ( pEntry )
667 bool bRet = false;
668 OUString aHelpText;
669 SvTreeListEntry* pParent = GetParent(pEntry);
670 if ( !pParent ) // Top-Level ?
672 aHelpText = OUString::number( GetChildCount(pEntry) ) +
673 " " + GetEntryText(pEntry);
674 bRet = true;
676 else if ( pParent == pRootNodes[SC_CONTENT_NOTE] )
678 aHelpText = GetEntryText(pEntry); // Notizen als Help-Text
679 bRet = true;
681 else if ( pParent == pRootNodes[SC_CONTENT_AREALINK] )
683 sal_uLong nIndex = GetChildIndex(pEntry);
684 if( nIndex != SC_CONTENT_NOCHILD )
686 const ScAreaLink* pLink = GetLink(nIndex);
687 if (pLink)
689 aHelpText = pLink->GetFile(); // Source-Datei als Help-Text
690 bRet = true;
695 if (bRet)
697 SvLBoxTab* pTab;
698 SvLBoxString* pItem = static_cast<SvLBoxString*>(GetItem( pEntry, aPos.X(), &pTab ));
699 if( pItem )
701 aPos = GetEntryPosition( pEntry );
702 aPos.X() = GetTabPos( pEntry, pTab );
703 aPos = OutputToScreenPixel(aPos);
704 Size aSize( pItem->GetSize( this, pEntry ) );
706 Rectangle aItemRect( aPos, aSize );
707 Help::ShowQuickHelp( this, aItemRect, aHelpText );
708 bDone = true;
713 if (!bDone)
714 Window::RequestHelp( rHEvt );
717 ScDocument* ScContentTree::GetSourceDocument()
719 if (bHiddenDoc)
720 return pHiddenDocument;
721 else
723 ScDocShell* pSh = GetManualOrCurrent();
724 if (pSh)
725 return &pSh->GetDocument();
728 return NULL;
731 //Move along and draw "*" sign .
732 void ScContentTree::ObjectFresh( sal_uInt16 nType, SvTreeListEntry* pEntry )
734 if ( bHiddenDoc && !pHiddenDocument )
735 return; // anderes Dokument angezeigt
736 if(nType ==SC_CONTENT_GRAPHIC||nType ==SC_CONTENT_OLEOBJECT||nType ==SC_CONTENT_DRAWING)
738 SetUpdateMode(false);
739 ClearType( nType );
740 GetDrawNames( nType/*, nId*/ );
741 if( !pEntry )
742 ApplyNavigatorSettings();
743 SetUpdateMode(true);
744 if( pEntry )
746 SvTreeListEntry* pParent = pRootNodes[nType];
747 SvTreeListEntry* pBeginEntry = NULL;
748 SvTreeListEntry* pOldEntry = NULL;
749 if( pParent )
750 pBeginEntry = FirstChild(pParent);
751 while( pBeginEntry )
753 OUString aTempText( GetEntryText( pBeginEntry ) );
754 if( aTempText == sKeyString )
756 pOldEntry = pBeginEntry;
757 break;
759 pBeginEntry = Next( pBeginEntry );
761 if( pOldEntry )
763 Expand(pParent);
764 Select( pOldEntry, true);
770 void ScContentTree::Refresh( sal_uInt16 nType )
772 if ( bHiddenDoc && !pHiddenDocument )
773 return; // anderes Dokument angezeigt
775 // wenn sich nichts geaendert hat, gleich abbrechen (gegen Geflacker)
777 if ( nType == SC_CONTENT_NOTE )
778 if (!NoteStringsChanged())
779 return;
780 if ( nType == SC_CONTENT_GRAPHIC )
781 if (!DrawNamesChanged(SC_CONTENT_GRAPHIC))
782 return;
783 if ( nType == SC_CONTENT_OLEOBJECT )
784 if (!DrawNamesChanged(SC_CONTENT_OLEOBJECT))
785 return;
786 if ( nType == SC_CONTENT_DRAWING )
787 if (!DrawNamesChanged(SC_CONTENT_DRAWING))
788 return;
790 SetUpdateMode(false);
792 ClearType( nType );
794 if ( !nType || nType == SC_CONTENT_TABLE )
795 GetTableNames();
796 if ( !nType || nType == SC_CONTENT_RANGENAME )
797 GetAreaNames();
798 if ( !nType || nType == SC_CONTENT_DBAREA )
799 GetDbNames();
800 if ( !nType || nType == SC_CONTENT_GRAPHIC )
801 GetGraphicNames();
802 if ( !nType || nType == SC_CONTENT_OLEOBJECT )
803 GetOleNames();
804 if ( !nType || nType == SC_CONTENT_DRAWING )
805 GetDrawingNames();
806 if ( !nType || nType == SC_CONTENT_NOTE )
807 GetNoteStrings();
808 if ( !nType || nType == SC_CONTENT_AREALINK )
809 GetLinkNames();
811 ApplyNavigatorSettings();
812 SetUpdateMode(true);
815 void ScContentTree::GetTableNames()
817 if ( nRootType && nRootType != SC_CONTENT_TABLE ) // ausgeblendet ?
818 return;
820 ScDocument* pDoc = GetSourceDocument();
821 if (!pDoc)
822 return;
824 OUString aName;
825 SCTAB nCount = pDoc->GetTableCount();
826 for ( SCTAB i=0; i<nCount; i++ )
828 pDoc->GetName( i, aName );
829 InsertContent( SC_CONTENT_TABLE, aName );
833 namespace {
835 OUString createLocalRangeName(const OUString& rName, const OUString& rTableName)
837 OUStringBuffer aString (rName);
838 aString.append(" (");
839 aString.append(rTableName);
840 aString.append(")");
841 return aString.makeStringAndClear();
845 void ScContentTree::GetAreaNames()
847 if ( nRootType && nRootType != SC_CONTENT_RANGENAME ) // ausgeblendet ?
848 return;
850 ScDocument* pDoc = GetSourceDocument();
851 if (!pDoc)
852 return;
854 ScRange aDummy;
855 std::set<OUString> aSet;
856 ScRangeName* pRangeNames = pDoc->GetRangeName();
857 if (!pRangeNames->empty())
859 ScRangeName::const_iterator itrBeg = pRangeNames->begin(), itrEnd = pRangeNames->end();
860 for (ScRangeName::const_iterator itr = itrBeg; itr != itrEnd; ++itr)
862 if (itr->second->IsValidReference(aDummy))
863 aSet.insert(itr->second->GetName());
866 for (SCTAB i = 0; i < pDoc->GetTableCount(); ++i)
868 ScRangeName* pLocalRangeName = pDoc->GetRangeName(i);
869 if (pLocalRangeName && !pLocalRangeName->empty())
871 OUString aTableName;
872 pDoc->GetName(i, aTableName);
873 for (ScRangeName::const_iterator itr = pLocalRangeName->begin(); itr != pLocalRangeName->end(); ++itr)
875 if (itr->second->IsValidReference(aDummy))
876 aSet.insert(createLocalRangeName(itr->second->GetName(), aTableName));
881 if (!aSet.empty())
883 for (std::set<OUString>::iterator itr = aSet.begin();
884 itr != aSet.end(); ++itr)
886 InsertContent(SC_CONTENT_RANGENAME, *itr);
891 void ScContentTree::GetDbNames()
893 if ( nRootType && nRootType != SC_CONTENT_DBAREA ) // ausgeblendet ?
894 return;
896 ScDocument* pDoc = GetSourceDocument();
897 if (!pDoc)
898 return;
900 ScDBCollection* pDbNames = pDoc->GetDBCollection();
901 const ScDBCollection::NamedDBs& rDBs = pDbNames->getNamedDBs();
902 ScDBCollection::NamedDBs::const_iterator itr = rDBs.begin(), itrEnd = rDBs.end();
903 for (; itr != itrEnd; ++itr)
905 const OUString& aStrName = itr->GetName();
906 InsertContent(SC_CONTENT_DBAREA, aStrName);
910 bool ScContentTree::IsPartOfType( sal_uInt16 nContentType, sal_uInt16 nObjIdentifier )
912 bool bRet = false;
913 switch ( nContentType )
915 case SC_CONTENT_GRAPHIC:
916 bRet = ( nObjIdentifier == OBJ_GRAF );
917 break;
918 case SC_CONTENT_OLEOBJECT:
919 bRet = ( nObjIdentifier == OBJ_OLE2 );
920 break;
921 case SC_CONTENT_DRAWING:
922 bRet = ( nObjIdentifier != OBJ_GRAF && nObjIdentifier != OBJ_OLE2 ); // everything else
923 break;
924 default:
925 OSL_FAIL("unknown content type");
927 return bRet;
930 void ScContentTree::GetDrawNames( sal_uInt16 nType )
932 if ( nRootType && nRootType != nType ) // ausgeblendet ?
933 return;
935 ScDocument* pDoc = GetSourceDocument();
936 if (!pDoc)
937 return;
939 // iterate in flat mode for groups
940 SdrIterMode eIter = ( nType == SC_CONTENT_DRAWING ) ? IM_FLAT : IM_DEEPNOGROUPS;
942 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
943 SfxObjectShell* pShell = pDoc->GetDocumentShell();
944 if (pDrawLayer && pShell)
946 SCTAB nTabCount = pDoc->GetTableCount();
947 for (SCTAB nTab=0; nTab<nTabCount; nTab++)
949 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
950 OSL_ENSURE(pPage,"Page ?");
951 if (pPage)
953 SdrObjListIter aIter( *pPage, eIter );
954 SdrObject* pObject = aIter.Next();
955 while (pObject)
957 if ( IsPartOfType( nType, pObject->GetObjIdentifier() ) )
959 OUString aName = ScDrawLayer::GetVisibleName( pObject );
960 if (!aName.isEmpty())
962 if( bisInNavigatoeDlg )
964 if (nType >= SC_CONTENT_COUNT)
966 SAL_WARN("sc", "ScContentTree::InsertContent mit falschem Typ");
967 return;
970 SvTreeListEntry* pParent = pRootNodes[nType];
971 if (pParent)
973 SvTreeListEntry* pChild=InsertEntry( aName, pParent );
974 if(pChild)
975 pChild->SetMarked(false);
976 vcl::Window* pWindow=NULL;
977 ScTabViewShell* pScTabViewShell=NULL;
978 ScDrawView* pScDrawView=NULL;
979 ScNavigatorDlg* pScNavigatorDlg=NULL;
980 if(pChild)
981 pWindow=reinterpret_cast<vcl::Window*>(GetParent(pChild));
982 if(pWindow)
983 pScNavigatorDlg = static_cast<ScNavigatorDlg*>(pWindow);
984 if (pScNavigatorDlg!=NULL)
985 pScTabViewShell = ScNavigatorDlg::GetTabViewShell();
986 if(pScTabViewShell !=NULL)
987 pScDrawView =pScTabViewShell->GetViewData().GetScDrawView();
988 if(pScDrawView!=NULL)
990 bool bMarked =pScDrawView->GetObjectIsMarked(pObject);
991 pChild->SetMarked( bMarked );
993 }//end if parent
994 else
995 SAL_WARN("sc", "InsertContent ohne Parent");
1001 pObject = aIter.Next();
1008 void ScContentTree::GetGraphicNames()
1010 GetDrawNames( SC_CONTENT_GRAPHIC );
1013 void ScContentTree::GetOleNames()
1015 GetDrawNames( SC_CONTENT_OLEOBJECT );
1018 void ScContentTree::GetDrawingNames()
1020 GetDrawNames( SC_CONTENT_DRAWING );
1023 void ScContentTree::GetLinkNames()
1025 if ( nRootType && nRootType != SC_CONTENT_AREALINK ) // ausgeblendet ?
1026 return;
1028 ScDocument* pDoc = GetSourceDocument();
1029 if (!pDoc)
1030 return;
1032 sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
1033 OSL_ENSURE(pLinkManager, "kein LinkManager am Dokument?");
1034 const ::sfx2::SvBaseLinks& rLinks = pLinkManager->GetLinks();
1035 sal_uInt16 nCount = rLinks.size();
1036 for (sal_uInt16 i=0; i<nCount; i++)
1038 ::sfx2::SvBaseLink* pBase = *rLinks[i];
1039 if (pBase->ISA(ScAreaLink))
1040 InsertContent( SC_CONTENT_AREALINK, static_cast<ScAreaLink*>(pBase)->GetSource() );
1042 // in der Liste die Namen der Quellbereiche
1046 const ScAreaLink* ScContentTree::GetLink( sal_uLong nIndex )
1048 ScDocument* pDoc = GetSourceDocument();
1049 if (!pDoc)
1050 return NULL;
1052 sal_uLong nFound = 0;
1053 sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
1054 OSL_ENSURE(pLinkManager, "kein LinkManager am Dokument?");
1055 const ::sfx2::SvBaseLinks& rLinks = pLinkManager->GetLinks();
1056 sal_uInt16 nCount = rLinks.size();
1057 for (sal_uInt16 i=0; i<nCount; i++)
1059 ::sfx2::SvBaseLink* pBase = *rLinks[i];
1060 if (pBase->ISA(ScAreaLink))
1062 if (nFound == nIndex)
1063 return static_cast<const ScAreaLink*>(pBase);
1064 ++nFound;
1068 OSL_FAIL("link not found");
1069 return NULL;
1072 static OUString lcl_NoteString( const ScPostIt& rNote )
1074 OUString aText = rNote.GetText();
1075 sal_Int32 nAt;
1076 while ( (nAt = aText.indexOf( '\n' )) != -1 )
1077 aText = aText.replaceAt( nAt, 1, " " );
1078 return aText;
1081 void ScContentTree::GetNoteStrings()
1083 if ( nRootType && nRootType != SC_CONTENT_NOTE ) // ausgeblendet ?
1084 return;
1086 ScDocument* pDoc = GetSourceDocument();
1087 if (!pDoc)
1088 return;
1090 // loop over cell notes
1091 std::vector<sc::NoteEntry> aEntries;
1092 pDoc->GetAllNoteEntries(aEntries);
1093 std::vector<sc::NoteEntry>::const_iterator it = aEntries.begin(), itEnd = aEntries.end();
1094 for (; it != itEnd; ++it)
1095 InsertContent(SC_CONTENT_NOTE, lcl_NoteString(*it->mpNote));
1098 ScAddress ScContentTree::GetNotePos( sal_uLong nIndex )
1100 ScDocument* pDoc = GetSourceDocument();
1101 if (!pDoc)
1102 return ScAddress();
1104 return pDoc->GetNotePosition(nIndex);
1107 bool ScContentTree::NoteStringsChanged()
1109 ScDocument* pDoc = GetSourceDocument();
1110 if (!pDoc)
1111 return false;
1113 SvTreeListEntry* pParent = pRootNodes[SC_CONTENT_NOTE];
1114 if (!pParent)
1115 return false;
1117 SvTreeListEntry* pEntry = FirstChild( pParent );
1119 std::vector<sc::NoteEntry> aEntries;
1120 pDoc->GetAllNoteEntries(aEntries);
1121 std::vector<sc::NoteEntry>::const_iterator it = aEntries.begin(), itEnd = aEntries.end();
1122 for (; it != itEnd; ++it)
1124 const ScPostIt* pNote = it->mpNote;
1125 if (!pEntry)
1126 return true;
1128 if (lcl_NoteString(*pNote) != GetEntryText(pEntry))
1129 return true;
1131 pEntry = NextSibling(pEntry);
1134 if ( pEntry )
1135 return true;
1137 return false;
1140 bool ScContentTree::DrawNamesChanged( sal_uInt16 nType )
1142 ScDocument* pDoc = GetSourceDocument();
1143 if (!pDoc)
1144 return false;
1146 SvTreeListEntry* pParent = pRootNodes[nType];
1147 if (!pParent)
1148 return false;
1150 SvTreeListEntry* pEntry = FirstChild( pParent );
1152 // iterate in flat mode for groups
1153 SdrIterMode eIter = ( nType == SC_CONTENT_DRAWING ) ? IM_FLAT : IM_DEEPNOGROUPS;
1155 bool bEqual = true;
1156 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
1157 SfxObjectShell* pShell = pDoc->GetDocumentShell();
1158 if (pDrawLayer && pShell)
1160 SCTAB nTabCount = pDoc->GetTableCount();
1161 for (SCTAB nTab=0; nTab<nTabCount && bEqual; nTab++)
1163 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
1164 OSL_ENSURE(pPage,"Page ?");
1165 if (pPage)
1167 SdrObjListIter aIter( *pPage, eIter );
1168 SdrObject* pObject = aIter.Next();
1169 while (pObject && bEqual)
1171 if ( IsPartOfType( nType, pObject->GetObjIdentifier() ) )
1173 if ( !pEntry )
1174 bEqual = false;
1175 else
1177 if ( ScDrawLayer::GetVisibleName( pObject ) != GetEntryText(pEntry) )
1178 bEqual = false;
1180 pEntry = NextSibling( pEntry );
1183 pObject = aIter.Next();
1189 if ( pEntry )
1190 bEqual = false; // kommt noch was
1192 return !bEqual;
1195 static bool lcl_GetRange( ScDocument* pDoc, sal_uInt16 nType, const OUString& rName, ScRange& rRange )
1197 bool bFound = false;
1199 if ( nType == SC_CONTENT_RANGENAME )
1201 ScRangeName* pList = pDoc->GetRangeName();
1202 if (pList)
1204 const ScRangeData* p = pList->findByUpperName(ScGlobal::pCharClass->uppercase(rName));
1205 if (p && p->IsValidReference(rRange))
1206 bFound = true;
1209 else if ( nType == SC_CONTENT_DBAREA )
1211 ScDBCollection* pList = pDoc->GetDBCollection();
1212 if (pList)
1214 const ScDBData* p = pList->getNamedDBs().findByUpperName(ScGlobal::pCharClass->uppercase(rName));
1215 if (p)
1217 SCTAB nTab;
1218 SCCOL nCol1, nCol2;
1219 SCROW nRow1, nRow2;
1220 p->GetArea(nTab, nCol1, nRow1, nCol2, nRow2);
1221 rRange = ScRange(nCol1, nRow1, nTab, nCol2, nRow2, nTab);
1222 bFound = true;
1227 return bFound;
1230 static void lcl_DoDragObject( ScDocShell* pSrcShell, const OUString& rName, sal_uInt16 nType, vcl::Window* pWin )
1232 ScDocument& rSrcDoc = pSrcShell->GetDocument();
1233 ScDrawLayer* pModel = rSrcDoc.GetDrawLayer();
1234 if (pModel)
1236 bool bOle = ( nType == SC_CONTENT_OLEOBJECT );
1237 bool bGraf = ( nType == SC_CONTENT_GRAPHIC );
1238 sal_uInt16 nDrawId = sal::static_int_cast<sal_uInt16>( bOle ? OBJ_OLE2 : ( bGraf ? OBJ_GRAF : OBJ_GRUP ) );
1239 SCTAB nTab = 0;
1240 SdrObject* pObject = pModel->GetNamedObject( rName, nDrawId, nTab );
1241 if (pObject)
1243 SdrView aEditView( pModel );
1244 aEditView.ShowSdrPage(aEditView.GetModel()->GetPage(nTab));
1245 SdrPageView* pPV = aEditView.GetSdrPageView();
1246 aEditView.MarkObj(pObject, pPV);
1248 SdrModel* pDragModel = aEditView.GetMarkedObjModel();
1250 TransferableObjectDescriptor aObjDesc;
1251 pSrcShell->FillTransferableObjectDescriptor( aObjDesc );
1252 aObjDesc.maDisplayName = pSrcShell->GetMedium()->GetURLObject().GetURLNoPass();
1253 // maSize is set in ScDrawTransferObj ctor
1255 ScDrawTransferObj* pTransferObj = new ScDrawTransferObj( pDragModel, pSrcShell, aObjDesc );
1256 uno::Reference<datatransfer::XTransferable> xTransferable( pTransferObj );
1258 pTransferObj->SetDragSourceObj( pObject, nTab );
1259 pTransferObj->SetDragSourceFlags( SC_DROP_NAVIGATOR );
1261 SC_MOD()->SetDragObject( NULL, pTransferObj );
1262 pWin->ReleaseMouse();
1263 pTransferObj->StartDrag( pWin, DND_ACTION_COPYMOVE | DND_ACTION_LINK );
1268 static void lcl_DoDragCells( ScDocShell* pSrcShell, const ScRange& rRange, sal_uInt16 nFlags, vcl::Window* pWin )
1270 ScMarkData aMark;
1271 aMark.SelectTable( rRange.aStart.Tab(), true );
1272 aMark.SetMarkArea( rRange );
1274 ScDocument& rSrcDoc = pSrcShell->GetDocument();
1275 if ( !rSrcDoc.HasSelectedBlockMatrixFragment( rRange.aStart.Col(), rRange.aStart.Row(),
1276 rRange.aEnd.Col(), rRange.aEnd.Row(),
1277 aMark ) )
1279 ScDocument* pClipDoc = new ScDocument( SCDOCMODE_CLIP );
1280 ScClipParam aClipParam(rRange, false);
1281 rSrcDoc.CopyToClip(aClipParam, pClipDoc, &aMark);
1282 // pClipDoc->ExtendMerge( rRange, sal_True );
1284 TransferableObjectDescriptor aObjDesc;
1285 pSrcShell->FillTransferableObjectDescriptor( aObjDesc );
1286 aObjDesc.maDisplayName = pSrcShell->GetMedium()->GetURLObject().GetURLNoPass();
1287 // maSize is set in ScTransferObj ctor
1289 ScTransferObj* pTransferObj = new ScTransferObj( pClipDoc, aObjDesc );
1290 uno::Reference<datatransfer::XTransferable> xTransferable( pTransferObj );
1292 pTransferObj->SetDragSource( pSrcShell, aMark );
1293 pTransferObj->SetDragSourceFlags( nFlags );
1295 SC_MOD()->SetDragObject( pTransferObj, NULL ); // for internal D&D
1296 pWin->ReleaseMouse();
1297 pTransferObj->StartDrag( pWin, DND_ACTION_COPYMOVE | DND_ACTION_LINK );
1301 void ScContentTree::DoDrag()
1303 ScDocumentLoader* pDocLoader = NULL;
1304 bIsInDrag = true;
1306 ScModule* pScMod = SC_MOD();
1308 sal_uInt16 nType;
1309 sal_uLong nChild;
1310 SvTreeListEntry* pEntry = GetCurEntry();
1311 GetEntryIndexes( nType, nChild, pEntry );
1313 if( pEntry &&
1314 (nChild != SC_CONTENT_NOCHILD) &&
1315 (nType != SC_CONTENT_ROOT) &&
1316 (nType != SC_CONTENT_NOTE) &&
1317 (nType != SC_CONTENT_AREALINK) )
1319 OUString aText( GetEntryText( pEntry ) );
1321 ScDocument* pLocalDoc = NULL; // fuer URL-Drop
1322 OUString aDocName;
1323 if (bHiddenDoc)
1324 aDocName = aHiddenName;
1325 else
1327 ScDocShell* pDocSh = GetManualOrCurrent();
1328 if (pDocSh)
1330 if (pDocSh->HasName())
1331 aDocName = pDocSh->GetMedium()->GetName();
1332 else
1333 pLocalDoc = &pDocSh->GetDocument(); // Drop nur in dieses Dokument
1337 bool bDoLinkTrans = false; // use ScLinkTransferObj
1338 OUString aLinkURL; // for ScLinkTransferObj
1339 OUString aLinkText;
1341 sal_uInt16 nDropMode = pParentWindow->GetDropMode();
1342 switch ( nDropMode )
1344 case SC_DROPMODE_URL:
1346 OUString aUrl = aDocName + "#" + aText;
1348 pScMod->SetDragJump( pLocalDoc, aUrl, aText );
1350 if (!aDocName.isEmpty())
1352 // provide URL to outside only if the document has a name
1353 // (without name, only internal D&D via SetDragJump)
1355 aLinkURL = aUrl;
1356 aLinkText = aText;
1358 bDoLinkTrans = true;
1360 break;
1361 case SC_DROPMODE_LINK:
1363 if ( !aDocName.isEmpty() ) // link only to named documents
1365 // for internal D&D, set flag to insert a link
1367 switch ( nType )
1369 case SC_CONTENT_TABLE:
1370 pScMod->SetDragLink( aDocName, aText, EMPTY_OUSTRING );
1371 bDoLinkTrans = true;
1372 break;
1373 case SC_CONTENT_RANGENAME:
1374 case SC_CONTENT_DBAREA:
1375 pScMod->SetDragLink( aDocName, EMPTY_OUSTRING, aText );
1376 bDoLinkTrans = true;
1377 break;
1379 // other types cannot be linked
1383 break;
1384 case SC_DROPMODE_COPY:
1386 ScDocShell* pSrcShell = NULL;
1387 if ( bHiddenDoc )
1389 OUString aFilter, aOptions;
1390 OUString aURL = aHiddenName;
1391 pDocLoader = new ScDocumentLoader( aURL, aFilter, aOptions );
1392 if (!pDocLoader->IsError())
1393 pSrcShell = pDocLoader->GetDocShell();
1395 else
1396 pSrcShell = GetManualOrCurrent();
1398 if ( pSrcShell )
1400 ScDocument& rSrcDoc = pSrcShell->GetDocument();
1401 if ( nType == SC_CONTENT_RANGENAME || nType == SC_CONTENT_DBAREA )
1403 ScRange aRange;
1404 if ( lcl_GetRange( &rSrcDoc, nType, aText, aRange ) )
1406 lcl_DoDragCells( pSrcShell, aRange, SC_DROP_NAVIGATOR, this );
1409 else if ( nType == SC_CONTENT_TABLE )
1411 SCTAB nTab;
1412 if ( rSrcDoc.GetTable( aText, nTab ) )
1414 ScRange aRange( 0,0,nTab, MAXCOL,MAXROW,nTab );
1415 lcl_DoDragCells( pSrcShell, aRange, SC_DROP_NAVIGATOR | SC_DROP_TABLE, this );
1418 else if ( nType == SC_CONTENT_GRAPHIC || nType == SC_CONTENT_OLEOBJECT ||
1419 nType == SC_CONTENT_DRAWING )
1421 lcl_DoDragObject( pSrcShell, aText, nType, this );
1423 // in ExecuteDrag kann der Navigator geloescht worden sein
1424 // -> nicht mehr auf Member zugreifen !!!
1428 break;
1431 if (bDoLinkTrans)
1433 ScLinkTransferObj* pTransferObj = new ScLinkTransferObj;
1434 uno::Reference<datatransfer::XTransferable> xTransferable( pTransferObj );
1436 if ( !aLinkURL.isEmpty() )
1437 pTransferObj->SetLinkURL( aLinkURL, aLinkText );
1439 // SetDragJump / SetDragLink has been done above
1441 ReleaseMouse();
1442 pTransferObj->StartDrag( this, DND_ACTION_COPYMOVE | DND_ACTION_LINK );
1446 bIsInDrag = false; // static Member
1448 delete pDocLoader; // falls Dokument zum Draggen geladen wurde
1451 IMPL_LINK_NOARG(ScContentTree, ExecDragHdl)
1453 // als Link, damit asynchron ohne ImpMouseMoveMsg auf dem Stack auch der
1454 // Navigator geloescht werden darf
1456 DoDrag();
1457 return 0;
1460 bool ScContentTree::LoadFile( const OUString& rUrl )
1462 OUString aDocName = rUrl;
1463 sal_Int32 nPos = aDocName.indexOf('#');
1464 if ( nPos != -1 )
1465 aDocName = aDocName.copy(0, nPos); // nur der Name, ohne #...
1467 bool bReturn = false;
1468 OUString aURL = aDocName;
1469 OUString aFilter, aOptions;
1470 ScDocumentLoader aLoader( aURL, aFilter, aOptions );
1471 if ( !aLoader.IsError() )
1473 bHiddenDoc = true;
1474 aHiddenName = aDocName;
1475 aHiddenTitle = aLoader.GetTitle();
1476 pHiddenDocument = aLoader.GetDocument();
1478 Refresh(); // Inhalte aus geladenem Dokument holen
1480 pHiddenDocument = NULL;
1482 pParentWindow->GetDocNames( &aHiddenTitle ); // Liste fuellen
1485 // Dokument wird im dtor von ScDocumentLoader wieder geschlossen
1487 return bReturn;
1490 void ScContentTree::InitWindowBits( bool bButtons )
1492 WinBits nFlags = GetStyle() | WB_CLIPCHILDREN | WB_HSCROLL;
1493 if (bButtons)
1494 nFlags |= WB_HASBUTTONS | WB_HASBUTTONSATROOT;
1496 SetStyle( nFlags );
1499 void ScContentTree::SetRootType( sal_uInt16 nNew )
1501 if ( nNew != nRootType )
1503 nRootType = nNew;
1504 InitWindowBits( nNew == 0 );
1505 Refresh();
1507 ScNavipiCfg& rCfg = SC_MOD()->GetNavipiCfg();
1508 rCfg.SetRootType( nRootType );
1512 void ScContentTree::ToggleRoot() // nach Selektion
1514 sal_uInt16 nNew = SC_CONTENT_ROOT;
1515 if ( nRootType == SC_CONTENT_ROOT )
1517 SvTreeListEntry* pEntry = GetCurEntry();
1518 if (pEntry)
1520 SvTreeListEntry* pParent = GetParent(pEntry);
1521 for (sal_uInt16 i=1; i<SC_CONTENT_COUNT; i++)
1522 if ( pEntry == pRootNodes[i] || pParent == pRootNodes[i] )
1523 nNew = i;
1527 SetRootType( nNew );
1530 void ScContentTree::ResetManualDoc()
1532 aManualDoc.clear();
1533 bHiddenDoc = false;
1535 ActiveDocChanged();
1538 void ScContentTree::ActiveDocChanged()
1540 if ( !bHiddenDoc && aManualDoc.isEmpty() )
1541 Refresh(); // Inhalte nur wenn automatisch
1543 // Listbox muss immer geupdated werden, wegen aktiv-Flag
1545 OUString aCurrent;
1546 if ( bHiddenDoc )
1547 aCurrent = aHiddenTitle;
1548 else
1550 ScDocShell* pSh = GetManualOrCurrent();
1551 if (pSh)
1552 aCurrent = pSh->GetTitle();
1553 else
1555 // eingestelltes Dokument existiert nicht mehr
1557 aManualDoc.clear(); // wieder automatisch
1558 Refresh();
1559 pSh = GetManualOrCurrent(); // sollte jetzt aktives sein
1560 if (pSh)
1561 aCurrent = pSh->GetTitle();
1564 pParentWindow->GetDocNames( &aCurrent ); // selektieren
1567 void ScContentTree::SetManualDoc(const OUString& rName)
1569 aManualDoc = rName;
1570 if (!bHiddenDoc)
1572 Refresh();
1573 pParentWindow->GetDocNames( &aManualDoc ); // selektieren
1577 void ScContentTree::SelectDoc(const OUString& rName) // rName wie im Menue/Listbox angezeigt
1579 if ( rName == pParentWindow->aStrActiveWin )
1581 ResetManualDoc();
1582 return;
1585 // "aktiv" oder "inaktiv" weglassen
1587 OUString aRealName = rName;
1588 sal_Int32 nLen = rName.getLength();
1589 sal_Int32 nActiveStart = nLen - pParentWindow->aStrActive.getLength();
1590 if ( rName.copy( nActiveStart ) == pParentWindow->aStrActive )
1591 aRealName = rName.copy( 0, nActiveStart );
1592 sal_Int32 nNotActiveStart = nLen - pParentWindow->aStrNotActive.getLength();
1593 if ( rName.copy( nNotActiveStart ) == pParentWindow->aStrNotActive )
1594 aRealName = rName.copy( 0, nNotActiveStart );
1596 bool bLoaded = false;
1598 // ist es ein normal geladenes Doc ?
1600 SfxObjectShell* pSh = SfxObjectShell::GetFirst();
1601 while ( pSh && !bLoaded )
1603 if ( pSh->ISA(ScDocShell) )
1604 if ( pSh->GetTitle() == aRealName )
1605 bLoaded = true;
1606 pSh = SfxObjectShell::GetNext( *pSh );
1609 if (bLoaded)
1611 bHiddenDoc = false;
1612 SetManualDoc(aRealName);
1614 else if (!aHiddenTitle.isEmpty()) // verstecktes ausgewaehlt
1616 if (!bHiddenDoc)
1617 LoadFile(aHiddenName);
1619 else
1621 OSL_FAIL("SelectDoc: nicht gefunden");
1625 void ScContentTree::ApplyNavigatorSettings()
1627 const ScNavigatorSettings* pSettings = ScNavigatorDlg::GetNavigatorSettings();
1628 if( pSettings )
1630 sal_uInt16 nRootSel = pSettings->GetRootSelected();
1631 sal_uLong nChildSel = pSettings->GetChildSelected();
1633 for( sal_uInt16 nEntry = 1; nEntry < SC_CONTENT_COUNT; ++nEntry )
1635 if( pRootNodes[ nEntry ] )
1637 // expand
1638 bool bExp = pSettings->IsExpanded( nEntry );
1639 if( bExp != IsExpanded( pRootNodes[ nEntry ] ) )
1641 if( bExp )
1642 Expand( pRootNodes[ nEntry ] );
1643 else
1644 Collapse( pRootNodes[ nEntry ] );
1647 // select
1648 if( nRootSel == nEntry )
1650 SvTreeListEntry* pEntry = NULL;
1651 if( bExp && (nChildSel != SC_CONTENT_NOCHILD) )
1652 pEntry = GetEntry( pRootNodes[ nEntry ], nChildSel );
1653 Select( pEntry ? pEntry : pRootNodes[ nEntry ] );
1660 void ScContentTree::StoreNavigatorSettings() const
1662 ScNavigatorSettings* pSettings = ScNavigatorDlg::GetNavigatorSettings();
1663 if( pSettings )
1665 for( sal_uInt16 nEntry = 1; nEntry < SC_CONTENT_COUNT; ++nEntry )
1667 bool bExp = pRootNodes[ nEntry ] && IsExpanded( pRootNodes[ nEntry ] );
1668 pSettings->SetExpanded( nEntry, bExp );
1670 sal_uInt16 nRoot;
1671 sal_uLong nChild;
1672 GetEntryIndexes( nRoot, nChild, GetCurEntry() );
1673 pSettings->SetRootSelected( nRoot );
1674 pSettings->SetChildSelected( nChild );
1678 void ScContentTree::InitEntry(SvTreeListEntry* pEntry,
1679 const OUString& rStr, const Image& rImg1, const Image& rImg2, SvLBoxButtonKind eButtonKind)
1681 sal_uInt16 nColToHilite = 1; //0==Bitmap;1=="Spalte1";2=="Spalte2"
1682 SvTreeListBox::InitEntry( pEntry, rStr, rImg1, rImg2, eButtonKind );
1683 SvLBoxString* pCol = static_cast<SvLBoxString*>(pEntry->GetItem( nColToHilite ));
1684 SvLBoxString* pStr = new SvLBoxString( pEntry, 0, pCol->GetText() );
1685 pEntry->ReplaceItem( pStr, nColToHilite );
1688 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */