1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: content.cxx,v $
10 * $Revision: 1.26.102.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 // INCLUDE ---------------------------------------------------------------
36 #include <svx/svditer.hxx>
37 #include <svx/svdobj.hxx>
38 #include <svx/svdpage.hxx>
39 #include <svx/svdpagv.hxx>
40 #include <svx/svdview.hxx>
41 #include <svx/svdxcgv.hxx>
42 #include <svx/linkmgr.hxx>
43 #include <sfx2/docfile.hxx>
44 #include <sfx2/viewfrm.hxx>
45 #include <vcl/help.hxx>
46 #include <vcl/sound.hxx>
47 #include <vcl/svapp.hxx>
48 #include <tools/urlobj.hxx>
49 #include <svtools/urlbmk.hxx>
52 #include "content.hxx"
57 #include "rangenam.hxx"
58 #include "dbcolect.hxx"
59 #include "tablink.hxx" // fuer Loader
60 #include "popmenu.hxx"
61 #include "drwlayer.hxx"
62 #include "transobj.hxx"
63 #include "drwtrans.hxx"
64 #include "lnktrans.hxx"
66 #include "dociter.hxx"
67 #include "scresid.hxx"
68 #include "globstr.hrc"
70 #include "arealink.hxx"
71 #include "navicfg.hxx"
72 #include "navsett.hxx"
75 using namespace com::sun::star
;
77 // Reihenfolge der Kategorien im Navigator -------------------------------------
79 static USHORT pTypeList
[SC_CONTENT_COUNT
] =
81 SC_CONTENT_ROOT
, // ROOT (0) muss vorne stehen
92 BOOL
ScContentTree::bIsInDrag
= FALSE
;
95 ScDocShell
* ScContentTree::GetManualOrCurrent()
97 ScDocShell
* pSh
= NULL
;
98 if ( aManualDoc
.Len() )
100 TypeId aScType
= TYPE(ScDocShell
);
101 SfxObjectShell
* pObjSh
= SfxObjectShell::GetFirst( &aScType
);
102 while ( pObjSh
&& !pSh
)
104 if ( pObjSh
->GetTitle() == aManualDoc
)
105 pSh
= PTR_CAST( ScDocShell
, pObjSh
);
106 pObjSh
= SfxObjectShell::GetNext( *pObjSh
, &aScType
);
111 // Current nur, wenn keine manuell eingestellt ist
112 // (damit erkannt wird, wenn das Dokument nicht mehr existiert)
114 SfxViewShell
* pViewSh
= SfxViewShell::Current();
117 SfxObjectShell
* pObjSh
= pViewSh
->GetViewFrame()->GetObjectShell();
118 pSh
= PTR_CAST( ScDocShell
, pObjSh
);
129 ScContentTree::ScContentTree( Window
* pParent
, const ResId
& rResId
) :
130 SvTreeListBox ( pParent
, rResId
),
131 aEntryImages ( ScResId( RID_IMAGELIST_NAVCONT
) ),
132 aHCEntryImages ( ScResId( RID_IMAGELIST_H_NAVCONT
) ),
133 nRootType ( SC_CONTENT_ROOT
),
134 bHiddenDoc ( FALSE
),
135 pHiddenDocument ( NULL
)
138 for (i
=0; i
<SC_CONTENT_COUNT
; i
++)
139 pPosList
[pTypeList
[i
]] = i
; // invers zum suchen
141 pParentWindow
= (ScNavigatorDlg
*)pParent
;
143 pRootNodes
[0] = NULL
;
144 for (i
=1; i
<SC_CONTENT_COUNT
; i
++)
147 SetNodeDefaultImages();
149 SetDoubleClickHdl( LINK( this, ScContentTree
, ContentDoubleClickHdl
) );
152 ScContentTree::~ScContentTree()
156 void ScContentTree::InitRoot( USHORT nType
)
161 if ( nRootType
&& nRootType
!= nType
) // ausgeblendet ?
163 pRootNodes
[nType
] = NULL
;
167 const Image
& rImage
= aEntryImages
.GetImage( nType
);
168 String
aName( ScResId( SCSTR_CONTENT_ROOT
+ nType
) );
169 // wieder an die richtige Position:
170 USHORT nPos
= nRootType
? 0 : pPosList
[nType
]-1;
171 SvLBoxEntry
* pNew
= InsertEntry( aName
, rImage
, rImage
, NULL
, FALSE
, nPos
);
173 const Image
& rHCImage
= aHCEntryImages
.GetImage( nType
);
174 SetExpandedEntryBmp( pNew
, rHCImage
, BMP_COLOR_HIGHCONTRAST
);
175 SetCollapsedEntryBmp( pNew
, rHCImage
, BMP_COLOR_HIGHCONTRAST
);
177 pRootNodes
[nType
] = pNew
;
180 void ScContentTree::ClearAll()
183 for (USHORT i
=1; i
<SC_CONTENT_COUNT
; i
++)
187 void ScContentTree::ClearType(USHORT nType
)
193 SvLBoxEntry
* pParent
= pRootNodes
[nType
];
194 if ( !pParent
|| GetChildCount(pParent
) ) // nicht, wenn ohne Children schon da
197 GetModel()->Remove( pParent
); // mit allen Children
198 InitRoot( nType
); // ggf. neu eintragen
203 void ScContentTree::InsertContent( USHORT nType
, const String
& rValue
)
205 if (nType
>= SC_CONTENT_COUNT
)
207 DBG_ERROR("ScContentTree::InsertContent mit falschem Typ");
211 SvLBoxEntry
* pParent
= pRootNodes
[nType
];
213 InsertEntry( rValue
, pParent
);
216 DBG_ERROR("InsertContent ohne Parent");
220 void ScContentTree::GetEntryIndexes( USHORT
& rnRootIndex
, ULONG
& rnChildIndex
, SvLBoxEntry
* pEntry
) const
222 rnRootIndex
= SC_CONTENT_ROOT
;
223 rnChildIndex
= SC_CONTENT_NOCHILD
;
228 SvLBoxEntry
* pParent
= GetParent( pEntry
);
230 for( USHORT nRoot
= 1; !bFound
&& (nRoot
< SC_CONTENT_COUNT
); ++nRoot
)
232 if( pEntry
== pRootNodes
[ nRoot
] )
238 else if( pParent
&& (pParent
== pRootNodes
[ nRoot
]) )
242 // search the entry in all child entries of the parent
244 SvLBoxEntry
* pIterEntry
= FirstChild( pParent
);
245 while( !bFound
&& pIterEntry
)
247 if ( pEntry
== pIterEntry
)
249 rnChildIndex
= nEntry
;
250 bFound
= true; // exit the while loop
252 pIterEntry
= NextSibling( pIterEntry
);
256 bFound
= true; // exit the for loop
261 ULONG
ScContentTree::GetChildIndex( SvLBoxEntry
* pEntry
) const
265 GetEntryIndexes( nRoot
, nChild
, pEntry
);
269 String
lcl_GetDBAreaRange( ScDocument
* pDoc
, const String
& rDBName
)
274 ScDBCollection
* pDbNames
= pDoc
->GetDBCollection();
275 USHORT nCount
= pDbNames
->GetCount();
276 for ( USHORT i
=0; i
<nCount
; i
++ )
278 ScDBData
* pData
= (*pDbNames
)[i
];
279 if ( pData
->GetName() == rDBName
)
282 pData
->GetArea(aRange
);
283 aRange
.Format( aRet
, SCR_ABS_3D
, pDoc
);
291 IMPL_LINK( ScContentTree
, ContentDoubleClickHdl
, ScContentTree
*, EMPTYARG
)
295 SvLBoxEntry
* pEntry
= GetCurEntry();
296 GetEntryIndexes( nType
, nChild
, pEntry
);
298 if( pEntry
&& (nType
!= SC_CONTENT_ROOT
) && (nChild
!= SC_CONTENT_NOCHILD
) )
301 return 0; //! spaeter...
303 String
aText( GetEntryText( pEntry
) );
305 if ( aManualDoc
.Len() )
306 pParentWindow
->SetCurrentDoc( aManualDoc
);
310 case SC_CONTENT_TABLE
:
311 pParentWindow
->SetCurrentTableStr( aText
);
314 case SC_CONTENT_RANGENAME
:
315 pParentWindow
->SetCurrentCellStr( aText
);
318 case SC_CONTENT_DBAREA
:
320 // #47905# Wenn gleiche Bereichs- und DB-Namen existieren, wird
321 // bei SID_CURRENTCELL der Bereichsname genommen.
322 // DB-Bereiche darum direkt ueber die Adresse anspringen.
324 String aRangeStr
= lcl_GetDBAreaRange( GetSourceDocument(), aText
);
326 pParentWindow
->SetCurrentCellStr( aRangeStr
);
330 case SC_CONTENT_OLEOBJECT
:
331 case SC_CONTENT_GRAPHIC
:
332 case SC_CONTENT_DRAWING
:
333 pParentWindow
->SetCurrentObject( aText
);
336 case SC_CONTENT_NOTE
:
338 ScAddress aPos
= GetNotePos( nChild
);
339 pParentWindow
->SetCurrentTable( aPos
.Tab() );
340 pParentWindow
->SetCurrentCell( aPos
.Col(), aPos
.Row() );
344 case SC_CONTENT_AREALINK
:
346 const ScAreaLink
* pLink
= GetLink( nChild
);
349 ScRange aRange
= pLink
->GetDestArea();
351 ScDocument
* pSrcDoc
= GetSourceDocument();
352 aRange
.Format( aRangeStr
, SCR_ABS_3D
, pSrcDoc
, pSrcDoc
->GetAddressConvention() );
353 pParentWindow
->SetCurrentCellStr( aRangeStr
);
359 ScNavigatorDlg::ReleaseFocus(); // set focus into document
365 void ScContentTree::MouseButtonDown( const MouseEvent
& rMEvt
)
367 SvTreeListBox::MouseButtonDown( rMEvt
);
371 void ScContentTree::KeyInput( const KeyEvent
& rKEvt
)
375 const KeyCode aCode
= rKEvt
.GetKeyCode();
376 if (aCode
.GetCode() == KEY_RETURN
)
378 switch (aCode
.GetModifier())
381 ToggleRoot(); // toggle root mode (as in Writer)
386 SvLBoxEntry
* pEntry
= GetCurEntry();
391 GetEntryIndexes( nType
, nChild
, pEntry
);
393 if( (nType
!= SC_CONTENT_ROOT
) && (nChild
== SC_CONTENT_NOCHILD
) )
395 String
aText( GetEntryText( pEntry
) );
396 if ( IsExpanded( pEntry
) )
402 ContentDoubleClickHdl(0); // select content as if double clicked
413 SvTreeListBox::KeyInput(rKEvt
);
416 //BOOL __EXPORT ScContentTree::Drop( const DropEvent& rEvt )
418 // return pParentWindow->Drop(rEvt); // Drop auf Navigator
421 //BOOL __EXPORT ScContentTree::QueryDrop( DropEvent& rEvt )
423 // return pParentWindow->QueryDrop(rEvt); // Drop auf Navigator
426 sal_Int8
ScContentTree::AcceptDrop( const AcceptDropEvent
& /* rEvt */ )
428 return DND_ACTION_NONE
;
431 sal_Int8
ScContentTree::ExecuteDrop( const ExecuteDropEvent
& /* rEvt */ )
433 return DND_ACTION_NONE
;
436 void ScContentTree::StartDrag( sal_Int8
/* nAction */, const Point
& /* rPosPixel */ )
441 void ScContentTree::DragFinished( sal_Int8
/* nAction */ )
445 void __EXPORT
ScContentTree::Command( const CommandEvent
& rCEvt
)
449 switch ( rCEvt
.GetCommand() )
451 case COMMAND_STARTDRAG
:
452 // Aus dem ExecuteDrag heraus kann der Navigator geloescht werden
453 // (beim Umschalten auf einen anderen Dokument-Typ), das wuerde aber
454 // den StarView MouseMove-Handler, der Command() aufruft, umbringen.
455 // Deshalb Drag&Drop asynchron:
459 Application::PostUserEvent( STATIC_LINK( this, ScContentTree
, ExecDragHdl
) );
464 case COMMAND_CONTEXTMENU
:
469 ScPopupMenu
aDropMenu( ScResId( RID_POPUP_DROPMODE
) );
470 aDropMenu
.CheckItem( RID_DROPMODE_URL
+ pParentWindow
->GetDropMode() );
471 aPop
.InsertItem( 1, pParentWindow
->GetStrDragMode() );
472 aPop
.SetPopupMenu( 1, &aDropMenu
);
474 // angezeigtes Dokument
476 ScPopupMenu aDocMenu
;
477 aDocMenu
.SetMenuFlags( aDocMenu
.GetMenuFlags() | MENU_FLAG_NOAUTOMNEMONICS
);
480 // geladene Dokumente
481 ScDocShell
* pCurrentSh
= PTR_CAST( ScDocShell
, SfxObjectShell::Current() );
482 SfxObjectShell
* pSh
= SfxObjectShell::GetFirst();
485 if ( pSh
->ISA(ScDocShell
) )
487 String aName
= pSh
->GetTitle();
488 String aEntry
= aName
;
489 if ( pSh
== pCurrentSh
)
490 aEntry
+= pParentWindow
->aStrActive
;
492 aEntry
+= pParentWindow
->aStrNotActive
;
493 aDocMenu
.InsertItem( ++i
, aEntry
);
494 if ( !bHiddenDoc
&& aName
== aManualDoc
)
497 pSh
= SfxObjectShell::GetNext( *pSh
);
500 aDocMenu
.InsertItem( ++i
, pParentWindow
->aStrActiveWin
);
501 if (!bHiddenDoc
&& !aManualDoc
.Len())
503 // verstecktes Dokument
504 if ( aHiddenTitle
.Len() )
506 String aEntry
= aHiddenTitle
;
507 aEntry
+= pParentWindow
->aStrHidden
;
508 aDocMenu
.InsertItem( ++i
, aEntry
);
512 aDocMenu
.CheckItem( nPos
);
513 aPop
.InsertItem( 2, pParentWindow
->GetStrDisplay() );
514 aPop
.SetPopupMenu( 2, &aDocMenu
);
518 aPop
.Execute( this, rCEvt
.GetMousePosPixel() );
520 if ( aDropMenu
.WasHit() ) // Drag-Drop Modus
522 USHORT nId
= aDropMenu
.GetSelected();
523 if ( nId
>= RID_DROPMODE_URL
&& nId
<= RID_DROPMODE_COPY
)
524 pParentWindow
->SetDropMode( nId
- RID_DROPMODE_URL
);
526 else if ( aDocMenu
.WasHit() ) // angezeigtes Dokument
528 USHORT nId
= aDocMenu
.GetSelected();
529 String aName
= aDocMenu
.GetItemText(nId
);
537 SvTreeListBox::Command(rCEvt
);
540 void __EXPORT
ScContentTree::RequestHelp( const HelpEvent
& rHEvt
)
543 if( rHEvt
.GetMode() & HELPMODE_QUICK
)
545 Point
aPos( ScreenToOutputPixel( rHEvt
.GetMousePosPixel() ));
546 SvLBoxEntry
* pEntry
= GetEntry( aPos
);
551 SvLBoxEntry
* pParent
= GetParent(pEntry
);
552 if ( !pParent
) // Top-Level ?
554 aHelpText
= String::CreateFromInt32( GetChildCount(pEntry
) );
556 aHelpText
+= GetEntryText(pEntry
);
559 else if ( pParent
== pRootNodes
[SC_CONTENT_NOTE
] )
561 aHelpText
= GetEntryText(pEntry
); // Notizen als Help-Text
564 else if ( pParent
== pRootNodes
[SC_CONTENT_AREALINK
] )
566 ULONG nIndex
= GetChildIndex(pEntry
);
567 if( nIndex
!= SC_CONTENT_NOCHILD
)
569 const ScAreaLink
* pLink
= GetLink(nIndex
);
572 aHelpText
= pLink
->GetFile(); // Source-Datei als Help-Text
581 SvLBoxString
* pItem
= (SvLBoxString
*)(GetItem( pEntry
, aPos
.X(), &pTab
));
584 aPos
= GetEntryPosition( pEntry
);
585 aPos
.X() = GetTabPos( pEntry
, pTab
);
586 aPos
= OutputToScreenPixel(aPos
);
587 Size
aSize( pItem
->GetSize( this, pEntry
) );
589 Rectangle
aItemRect( aPos
, aSize
);
590 Help::ShowQuickHelp( this, aItemRect
, aHelpText
);
597 Window::RequestHelp( rHEvt
);
600 ScDocument
* ScContentTree::GetSourceDocument()
603 return pHiddenDocument
;
606 ScDocShell
* pSh
= GetManualOrCurrent();
608 return pSh
->GetDocument();
614 void ScContentTree::Refresh( USHORT nType
)
616 if ( bHiddenDoc
&& !pHiddenDocument
)
617 return; // anderes Dokument angezeigt
619 // wenn sich nichts geaendert hat, gleich abbrechen (gegen Geflacker)
621 if ( nType
== SC_CONTENT_NOTE
)
622 if (!NoteStringsChanged())
624 if ( nType
== SC_CONTENT_GRAPHIC
)
625 if (!DrawNamesChanged(SC_CONTENT_GRAPHIC
))
627 if ( nType
== SC_CONTENT_OLEOBJECT
)
628 if (!DrawNamesChanged(SC_CONTENT_OLEOBJECT
))
630 if ( nType
== SC_CONTENT_DRAWING
)
631 if (!DrawNamesChanged(SC_CONTENT_DRAWING
))
634 SetUpdateMode(FALSE
);
638 if ( !nType
|| nType
== SC_CONTENT_TABLE
)
640 if ( !nType
|| nType
== SC_CONTENT_RANGENAME
)
642 if ( !nType
|| nType
== SC_CONTENT_DBAREA
)
644 if ( !nType
|| nType
== SC_CONTENT_GRAPHIC
)
646 if ( !nType
|| nType
== SC_CONTENT_OLEOBJECT
)
648 if ( !nType
|| nType
== SC_CONTENT_DRAWING
)
650 if ( !nType
|| nType
== SC_CONTENT_NOTE
)
652 if ( !nType
|| nType
== SC_CONTENT_AREALINK
)
659 void ScContentTree::GetTableNames()
661 if ( nRootType
&& nRootType
!= SC_CONTENT_TABLE
) // ausgeblendet ?
664 ScDocument
* pDoc
= GetSourceDocument();
669 SCTAB nCount
= pDoc
->GetTableCount();
670 for ( SCTAB i
=0; i
<nCount
; i
++ )
672 pDoc
->GetName( i
, aName
);
673 InsertContent( SC_CONTENT_TABLE
, aName
);
677 void ScContentTree::GetAreaNames()
679 if ( nRootType
&& nRootType
!= SC_CONTENT_RANGENAME
) // ausgeblendet ?
682 ScDocument
* pDoc
= GetSourceDocument();
686 ScRangeName
* pRangeNames
= pDoc
->GetRangeName();
687 USHORT nCount
= pRangeNames
->GetCount();
690 USHORT nValidCount
= 0;
693 for ( i
=0; i
<nCount
; i
++ )
695 ScRangeData
* pData
= (*pRangeNames
)[i
];
696 if (pData
->IsValidReference(aDummy
))
701 ScRangeData
** ppSortArray
= new ScRangeData
* [ nValidCount
];
703 for ( i
=0, j
=0; i
<nCount
; i
++ )
705 ScRangeData
* pData
= (*pRangeNames
)[i
];
706 if (pData
->IsValidReference(aDummy
))
707 ppSortArray
[j
++] = pData
;
710 qsort( (void*)ppSortArray
, nValidCount
, sizeof(ScRangeData
*),
711 &ScRangeData_QsortNameCompare
);
713 qsort( (void*)ppSortArray
, nValidCount
, sizeof(ScRangeData
*),
714 ICCQsortNameCompare
);
716 for ( j
=0; j
<nValidCount
; j
++ )
717 InsertContent( SC_CONTENT_RANGENAME
, ppSortArray
[j
]->GetName() );
718 delete [] ppSortArray
;
723 void ScContentTree::GetDbNames()
725 if ( nRootType
&& nRootType
!= SC_CONTENT_DBAREA
) // ausgeblendet ?
728 ScDocument
* pDoc
= GetSourceDocument();
732 ScDBCollection
* pDbNames
= pDoc
->GetDBCollection();
733 USHORT nCount
= pDbNames
->GetCount();
736 String
aStrNoName( ScGlobal::GetRscString(STR_DB_NONAME
) );
737 for ( USHORT i
=0; i
<nCount
; i
++ )
739 ScDBData
* pData
= (*pDbNames
)[i
];
740 String aStrName
= pData
->GetName();
741 if ( aStrName
!= aStrNoName
)
742 InsertContent( SC_CONTENT_DBAREA
, aStrName
);
747 bool ScContentTree::IsPartOfType( USHORT nContentType
, USHORT nObjIdentifier
) // static
750 switch ( nContentType
)
752 case SC_CONTENT_GRAPHIC
:
753 bRet
= ( nObjIdentifier
== OBJ_GRAF
);
755 case SC_CONTENT_OLEOBJECT
:
756 bRet
= ( nObjIdentifier
== OBJ_OLE2
);
758 case SC_CONTENT_DRAWING
:
759 bRet
= ( nObjIdentifier
!= OBJ_GRAF
&& nObjIdentifier
!= OBJ_OLE2
); // everything else
762 DBG_ERROR("unknown content type");
767 void ScContentTree::GetDrawNames( USHORT nType
)
769 if ( nRootType
&& nRootType
!= nType
) // ausgeblendet ?
772 ScDocument
* pDoc
= GetSourceDocument();
776 // iterate in flat mode for groups
777 SdrIterMode eIter
= ( nType
== SC_CONTENT_DRAWING
) ? IM_FLAT
: IM_DEEPNOGROUPS
;
779 ScDrawLayer
* pDrawLayer
= pDoc
->GetDrawLayer();
780 SfxObjectShell
* pShell
= pDoc
->GetDocumentShell();
781 if (pDrawLayer
&& pShell
)
783 SCTAB nTabCount
= pDoc
->GetTableCount();
784 for (SCTAB nTab
=0; nTab
<nTabCount
; nTab
++)
786 SdrPage
* pPage
= pDrawLayer
->GetPage(static_cast<sal_uInt16
>(nTab
));
787 DBG_ASSERT(pPage
,"Page ?");
790 SdrObjListIter
aIter( *pPage
, eIter
);
791 SdrObject
* pObject
= aIter
.Next();
794 if ( IsPartOfType( nType
, pObject
->GetObjIdentifier() ) )
796 String aName
= ScDrawLayer::GetVisibleName( pObject
);
798 InsertContent( nType
, aName
);
801 pObject
= aIter
.Next();
808 void ScContentTree::GetGraphicNames()
810 GetDrawNames( SC_CONTENT_GRAPHIC
);
813 void ScContentTree::GetOleNames()
815 GetDrawNames( SC_CONTENT_OLEOBJECT
);
818 void ScContentTree::GetDrawingNames()
820 GetDrawNames( SC_CONTENT_DRAWING
);
823 void ScContentTree::GetLinkNames()
825 if ( nRootType
&& nRootType
!= SC_CONTENT_AREALINK
) // ausgeblendet ?
828 ScDocument
* pDoc
= GetSourceDocument();
832 SvxLinkManager
* pLinkManager
= pDoc
->GetLinkManager();
833 DBG_ASSERT(pLinkManager
, "kein LinkManager am Dokument?");
834 const ::sfx2::SvBaseLinks
& rLinks
= pLinkManager
->GetLinks();
835 USHORT nCount
= rLinks
.Count();
836 for (USHORT i
=0; i
<nCount
; i
++)
838 ::sfx2::SvBaseLink
* pBase
= *rLinks
[i
];
839 if (pBase
->ISA(ScAreaLink
))
840 InsertContent( SC_CONTENT_AREALINK
, ((ScAreaLink
*)pBase
)->GetSource() );
842 // in der Liste die Namen der Quellbereiche
846 const ScAreaLink
* ScContentTree::GetLink( ULONG nIndex
)
848 ScDocument
* pDoc
= GetSourceDocument();
853 SvxLinkManager
* pLinkManager
= pDoc
->GetLinkManager();
854 DBG_ASSERT(pLinkManager
, "kein LinkManager am Dokument?");
855 const ::sfx2::SvBaseLinks
& rLinks
= pLinkManager
->GetLinks();
856 USHORT nCount
= rLinks
.Count();
857 for (USHORT i
=0; i
<nCount
; i
++)
859 ::sfx2::SvBaseLink
* pBase
= *rLinks
[i
];
860 if (pBase
->ISA(ScAreaLink
))
862 if (nFound
== nIndex
)
863 return (const ScAreaLink
*) pBase
;
868 DBG_ERROR("Link nicht gefunden");
872 String
lcl_NoteString( const ScPostIt
& rNote
)
874 String aText
= rNote
.GetText();
876 while ( (nAt
= aText
.Search( '\n' )) != STRING_NOTFOUND
)
877 aText
.SetChar( nAt
, ' ' );
881 void ScContentTree::GetNoteStrings()
883 if ( nRootType
&& nRootType
!= SC_CONTENT_NOTE
) // ausgeblendet ?
886 ScDocument
* pDoc
= GetSourceDocument();
890 SCTAB nTabCount
= pDoc
->GetTableCount();
891 for (SCTAB nTab
=0; nTab
<nTabCount
; nTab
++)
893 ScCellIterator
aIter( pDoc
, 0,0,nTab
, MAXCOL
,MAXROW
,nTab
);
894 for( ScBaseCell
* pCell
= aIter
.GetFirst(); pCell
; pCell
= aIter
.GetNext() )
895 if( const ScPostIt
* pNote
= pCell
->GetNote() )
896 InsertContent( SC_CONTENT_NOTE
, lcl_NoteString( *pNote
) );
900 ScAddress
ScContentTree::GetNotePos( ULONG nIndex
)
902 ScDocument
* pDoc
= GetSourceDocument();
907 SCTAB nTabCount
= pDoc
->GetTableCount();
908 for (SCTAB nTab
=0; nTab
<nTabCount
; nTab
++)
910 ScCellIterator
aIter( pDoc
, 0,0,nTab
, MAXCOL
,MAXROW
,nTab
);
911 ScBaseCell
* pCell
= aIter
.GetFirst();
914 if( pCell
->HasNote() )
916 if (nFound
== nIndex
)
917 return ScAddress( aIter
.GetCol(), aIter
.GetRow(), nTab
); // gefunden
920 pCell
= aIter
.GetNext();
924 DBG_ERROR("Notiz nicht gefunden");
928 BOOL
ScContentTree::NoteStringsChanged()
930 ScDocument
* pDoc
= GetSourceDocument();
934 SvLBoxEntry
* pParent
= pRootNodes
[SC_CONTENT_NOTE
];
938 SvLBoxEntry
* pEntry
= FirstChild( pParent
);
941 SCTAB nTabCount
= pDoc
->GetTableCount();
942 for (SCTAB nTab
=0; nTab
<nTabCount
&& bEqual
; nTab
++)
944 ScCellIterator
aIter( pDoc
, 0,0,nTab
, MAXCOL
,MAXROW
,nTab
);
945 ScBaseCell
* pCell
= aIter
.GetFirst();
946 while (pCell
&& bEqual
)
948 if( const ScPostIt
* pNote
= pCell
->GetNote() )
954 if ( lcl_NoteString( *pNote
) != GetEntryText(pEntry
) )
957 pEntry
= NextSibling( pEntry
);
960 pCell
= aIter
.GetNext();
965 bEqual
= FALSE
; // kommt noch was
970 BOOL
ScContentTree::DrawNamesChanged( USHORT nType
)
972 ScDocument
* pDoc
= GetSourceDocument();
976 SvLBoxEntry
* pParent
= pRootNodes
[nType
];
980 SvLBoxEntry
* pEntry
= FirstChild( pParent
);
982 // iterate in flat mode for groups
983 SdrIterMode eIter
= ( nType
== SC_CONTENT_DRAWING
) ? IM_FLAT
: IM_DEEPNOGROUPS
;
986 ScDrawLayer
* pDrawLayer
= pDoc
->GetDrawLayer();
987 SfxObjectShell
* pShell
= pDoc
->GetDocumentShell();
988 if (pDrawLayer
&& pShell
)
990 SCTAB nTabCount
= pDoc
->GetTableCount();
991 for (SCTAB nTab
=0; nTab
<nTabCount
&& bEqual
; nTab
++)
993 SdrPage
* pPage
= pDrawLayer
->GetPage(static_cast<sal_uInt16
>(nTab
));
994 DBG_ASSERT(pPage
,"Page ?");
997 SdrObjListIter
aIter( *pPage
, eIter
);
998 SdrObject
* pObject
= aIter
.Next();
999 while (pObject
&& bEqual
)
1001 if ( IsPartOfType( nType
, pObject
->GetObjIdentifier() ) )
1007 if ( ScDrawLayer::GetVisibleName( pObject
) != GetEntryText(pEntry
) )
1010 pEntry
= NextSibling( pEntry
);
1013 pObject
= aIter
.Next();
1020 bEqual
= FALSE
; // kommt noch was
1025 BOOL
lcl_GetRange( ScDocument
* pDoc
, USHORT nType
, const String
& rName
, ScRange
& rRange
)
1027 BOOL bFound
= FALSE
;
1030 if ( nType
== SC_CONTENT_RANGENAME
)
1032 ScRangeName
* pList
= pDoc
->GetRangeName();
1034 if (pList
->SearchName( rName
, nPos
))
1035 if ( (*pList
)[nPos
]->IsValidReference( rRange
) )
1038 else if ( nType
== SC_CONTENT_DBAREA
)
1040 ScDBCollection
* pList
= pDoc
->GetDBCollection();
1042 if (pList
->SearchName( rName
, nPos
))
1047 (*pList
)[nPos
]->GetArea(nTab
,nCol1
,nRow1
,nCol2
,nRow2
);
1048 rRange
= ScRange( nCol1
,nRow1
,nTab
, nCol2
,nRow2
,nTab
);
1056 void lcl_DoDragObject( ScDocShell
* pSrcShell
, const String
& rName
, USHORT nType
, Window
* pWin
)
1058 ScDocument
* pSrcDoc
= pSrcShell
->GetDocument();
1059 ScDrawLayer
* pModel
= pSrcDoc
->GetDrawLayer();
1062 BOOL bOle
= ( nType
== SC_CONTENT_OLEOBJECT
);
1063 BOOL bGraf
= ( nType
== SC_CONTENT_GRAPHIC
);
1064 USHORT nDrawId
= sal::static_int_cast
<USHORT
>( bOle
? OBJ_OLE2
: ( bGraf
? OBJ_GRAF
: OBJ_GRUP
) );
1066 SdrObject
* pObject
= pModel
->GetNamedObject( rName
, nDrawId
, nTab
);
1069 SdrView
aEditView( pModel
);
1070 aEditView
.ShowSdrPage(aEditView
.GetModel()->GetPage(nTab
));
1071 SdrPageView
* pPV
= aEditView
.GetSdrPageView();
1072 aEditView
.MarkObj(pObject
, pPV
);
1074 SdrModel
* pDragModel
= aEditView
.GetAllMarkedModel();
1076 TransferableObjectDescriptor aObjDesc
;
1077 pSrcShell
->FillTransferableObjectDescriptor( aObjDesc
);
1078 aObjDesc
.maDisplayName
= pSrcShell
->GetMedium()->GetURLObject().GetURLNoPass();
1079 // maSize is set in ScDrawTransferObj ctor
1081 ScDrawTransferObj
* pTransferObj
= new ScDrawTransferObj( pDragModel
, pSrcShell
, aObjDesc
);
1082 uno::Reference
<datatransfer::XTransferable
> xTransferable( pTransferObj
);
1084 pTransferObj
->SetDragSourceObj( pObject
, nTab
);
1085 pTransferObj
->SetDragSourceFlags( SC_DROP_NAVIGATOR
);
1087 SC_MOD()->SetDragObject( NULL
, pTransferObj
);
1088 pWin
->ReleaseMouse();
1089 pTransferObj
->StartDrag( pWin
, DND_ACTION_COPYMOVE
| DND_ACTION_LINK
);
1094 void lcl_DoDragCells( ScDocShell
* pSrcShell
, const ScRange
& rRange
, USHORT nFlags
, Window
* pWin
)
1097 aMark
.SelectTable( rRange
.aStart
.Tab(), TRUE
);
1098 aMark
.SetMarkArea( rRange
);
1100 ScDocument
* pSrcDoc
= pSrcShell
->GetDocument();
1101 if ( !pSrcDoc
->HasSelectedBlockMatrixFragment( rRange
.aStart
.Col(), rRange
.aStart
.Row(),
1102 rRange
.aEnd
.Col(), rRange
.aEnd
.Row(),
1105 ScDocument
* pClipDoc
= new ScDocument( SCDOCMODE_CLIP
);
1106 pSrcDoc
->CopyToClip( rRange
.aStart
.Col(), rRange
.aStart
.Row(),
1107 rRange
.aEnd
.Col(), rRange
.aEnd
.Row(),
1108 FALSE
, pClipDoc
, FALSE
, &aMark
);
1109 // pClipDoc->ExtendMerge( rRange, TRUE );
1111 TransferableObjectDescriptor aObjDesc
;
1112 pSrcShell
->FillTransferableObjectDescriptor( aObjDesc
);
1113 aObjDesc
.maDisplayName
= pSrcShell
->GetMedium()->GetURLObject().GetURLNoPass();
1114 // maSize is set in ScTransferObj ctor
1116 ScTransferObj
* pTransferObj
= new ScTransferObj( pClipDoc
, aObjDesc
);
1117 uno::Reference
<datatransfer::XTransferable
> xTransferable( pTransferObj
);
1119 pTransferObj
->SetDragSource( pSrcShell
, aMark
);
1120 pTransferObj
->SetDragSourceFlags( nFlags
);
1122 SC_MOD()->SetDragObject( pTransferObj
, NULL
); // for internal D&D
1123 pWin
->ReleaseMouse();
1124 pTransferObj
->StartDrag( pWin
, DND_ACTION_COPYMOVE
| DND_ACTION_LINK
);
1128 void ScContentTree::DoDrag()
1130 ScDocumentLoader
* pDocLoader
= NULL
;
1133 ScModule
* pScMod
= SC_MOD();
1137 SvLBoxEntry
* pEntry
= GetCurEntry();
1138 GetEntryIndexes( nType
, nChild
, pEntry
);
1141 (nChild
!= SC_CONTENT_NOCHILD
) &&
1142 (nType
!= SC_CONTENT_ROOT
) &&
1143 (nType
!= SC_CONTENT_NOTE
) &&
1144 (nType
!= SC_CONTENT_AREALINK
) )
1146 String
aText( GetEntryText( pEntry
) );
1148 ScDocument
* pLocalDoc
= NULL
; // fuer URL-Drop
1151 aDocName
= aHiddenName
;
1154 ScDocShell
* pDocSh
= GetManualOrCurrent();
1157 if (pDocSh
->HasName())
1158 aDocName
= pDocSh
->GetMedium()->GetName();
1160 pLocalDoc
= pDocSh
->GetDocument(); // Drop nur in dieses Dokument
1164 BOOL bDoLinkTrans
= FALSE
; // use ScLinkTransferObj
1165 String aLinkURL
; // for ScLinkTransferObj
1168 USHORT nDropMode
= pParentWindow
->GetDropMode();
1169 switch ( nDropMode
)
1171 case SC_DROPMODE_URL
:
1173 String aUrl
= aDocName
;
1177 pScMod
->SetDragJump( pLocalDoc
, aUrl
, aText
);
1181 // provide URL to outside only if the document has a name
1182 // (without name, only internal D&D via SetDragJump)
1187 bDoLinkTrans
= TRUE
;
1190 case SC_DROPMODE_LINK
:
1192 if ( aDocName
.Len() ) // link only to named documents
1194 // for internal D&D, set flag to insert a link
1198 case SC_CONTENT_TABLE
:
1199 pScMod
->SetDragLink( aDocName
, aText
, EMPTY_STRING
);
1200 bDoLinkTrans
= TRUE
;
1202 case SC_CONTENT_RANGENAME
:
1203 case SC_CONTENT_DBAREA
:
1204 pScMod
->SetDragLink( aDocName
, EMPTY_STRING
, aText
);
1205 bDoLinkTrans
= TRUE
;
1208 // other types cannot be linked
1213 case SC_DROPMODE_COPY
:
1215 ScDocShell
* pSrcShell
= NULL
;
1218 String aFilter
, aOptions
;
1219 pDocLoader
= new ScDocumentLoader( aHiddenName
, aFilter
, aOptions
);
1220 if (!pDocLoader
->IsError())
1221 pSrcShell
= pDocLoader
->GetDocShell();
1224 pSrcShell
= GetManualOrCurrent();
1228 ScDocument
* pSrcDoc
= pSrcShell
->GetDocument();
1229 if ( nType
== SC_CONTENT_RANGENAME
|| nType
== SC_CONTENT_DBAREA
)
1232 if ( lcl_GetRange( pSrcDoc
, nType
, aText
, aRange
) )
1234 lcl_DoDragCells( pSrcShell
, aRange
, SC_DROP_NAVIGATOR
, this );
1237 else if ( nType
== SC_CONTENT_TABLE
)
1240 if ( pSrcDoc
->GetTable( aText
, nTab
) )
1242 ScRange
aRange( 0,0,nTab
, MAXCOL
,MAXROW
,nTab
);
1243 lcl_DoDragCells( pSrcShell
, aRange
, SC_DROP_NAVIGATOR
| SC_DROP_TABLE
, this );
1246 else if ( nType
== SC_CONTENT_GRAPHIC
|| nType
== SC_CONTENT_OLEOBJECT
||
1247 nType
== SC_CONTENT_DRAWING
)
1249 lcl_DoDragObject( pSrcShell
, aText
, nType
, this );
1251 // in ExecuteDrag kann der Navigator geloescht worden sein
1252 // -> nicht mehr auf Member zugreifen !!!
1261 ScLinkTransferObj
* pTransferObj
= new ScLinkTransferObj
;
1262 uno::Reference
<datatransfer::XTransferable
> xTransferable( pTransferObj
);
1264 if ( aLinkURL
.Len() )
1265 pTransferObj
->SetLinkURL( aLinkURL
, aLinkText
);
1267 // SetDragJump / SetDragLink has been done above
1270 pTransferObj
->StartDrag( this, DND_ACTION_COPYMOVE
| DND_ACTION_LINK
);
1274 bIsInDrag
= FALSE
; // static Member
1276 delete pDocLoader
; // falls Dokument zum Draggen geladen wurde
1279 IMPL_STATIC_LINK(ScContentTree
, ExecDragHdl
, void*, EMPTYARG
)
1281 // als Link, damit asynchron ohne ImpMouseMoveMsg auf dem Stack auch der
1282 // Navigator geloescht werden darf
1288 //UNUSED2008-05 void ScContentTree::AdjustTitle()
1290 //UNUSED2008-05 String aTitle = pParentWindow->aTitleBase;
1291 //UNUSED2008-05 if (bHiddenDoc)
1293 //UNUSED2008-05 aTitle.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " - " ));
1294 //UNUSED2008-05 aTitle += aHiddenTitle;
1296 //UNUSED2008-05 pParentWindow->SetText(aTitle);
1299 BOOL
ScContentTree::LoadFile( const String
& rUrl
)
1301 String aDocName
= rUrl
;
1302 xub_StrLen nPos
= aDocName
.Search('#');
1303 if ( nPos
!= STRING_NOTFOUND
)
1304 aDocName
.Erase(nPos
); // nur der Name, ohne #...
1306 BOOL bReturn
= FALSE
;
1307 String aFilter
, aOptions
;
1308 ScDocumentLoader
aLoader( aDocName
, aFilter
, aOptions
);
1309 if ( !aLoader
.IsError() )
1312 aHiddenName
= aDocName
;
1313 aHiddenTitle
= aLoader
.GetTitle();
1314 pHiddenDocument
= aLoader
.GetDocument();
1316 Refresh(); // Inhalte aus geladenem Dokument holen
1318 pHiddenDocument
= NULL
;
1321 pParentWindow
->GetDocNames( &aHiddenTitle
); // Liste fuellen
1324 Sound::Beep(); // Fehler beim Laden
1326 // Dokument wird im dtor von ScDocumentLoader wieder geschlossen
1331 void ScContentTree::InitWindowBits( BOOL bButtons
)
1333 WinBits nFlags
= WB_CLIPCHILDREN
|WB_HSCROLL
;
1335 nFlags
|= WB_HASBUTTONS
|WB_HASBUTTONSATROOT
;
1337 SetWindowBits( nFlags
);
1340 void ScContentTree::SetRootType( USHORT nNew
)
1342 if ( nNew
!= nRootType
)
1345 InitWindowBits( nNew
== 0 );
1348 ScNavipiCfg
& rCfg
= SC_MOD()->GetNavipiCfg();
1349 rCfg
.SetRootType( nRootType
);
1353 void ScContentTree::ToggleRoot() // nach Selektion
1355 USHORT nNew
= SC_CONTENT_ROOT
;
1356 if ( nRootType
== SC_CONTENT_ROOT
)
1358 SvLBoxEntry
* pEntry
= GetCurEntry();
1361 SvLBoxEntry
* pParent
= GetParent(pEntry
);
1362 for (USHORT i
=1; i
<SC_CONTENT_COUNT
; i
++)
1363 if ( pEntry
== pRootNodes
[i
] || pParent
== pRootNodes
[i
] )
1368 SetRootType( nNew
);
1371 void ScContentTree::ResetManualDoc()
1379 void ScContentTree::ActiveDocChanged()
1381 if ( !bHiddenDoc
&& !aManualDoc
.Len() )
1382 Refresh(); // Inhalte nur wenn automatisch
1384 // Listbox muss immer geupdated werden, wegen aktiv-Flag
1388 aCurrent
= aHiddenTitle
;
1391 ScDocShell
* pSh
= GetManualOrCurrent();
1393 aCurrent
= pSh
->GetTitle();
1396 // eingestelltes Dokument existiert nicht mehr
1398 aManualDoc
.Erase(); // wieder automatisch
1400 pSh
= GetManualOrCurrent(); // sollte jetzt aktives sein
1402 aCurrent
= pSh
->GetTitle();
1405 pParentWindow
->GetDocNames( &aCurrent
); // selektieren
1408 void ScContentTree::SetManualDoc(const String
& rName
)
1414 pParentWindow
->GetDocNames( &aManualDoc
); // selektieren
1418 void ScContentTree::SelectDoc(const String
& rName
) // rName wie im Menue/Listbox angezeigt
1420 if ( rName
== pParentWindow
->aStrActiveWin
)
1426 // "aktiv" oder "inaktiv" weglassen
1428 String aRealName
= rName
;
1429 xub_StrLen nLen
= rName
.Len();
1430 xub_StrLen nActiveStart
= nLen
- pParentWindow
->aStrActive
.Len();
1431 if ( rName
.Copy( nActiveStart
) == pParentWindow
->aStrActive
)
1432 aRealName
= rName
.Copy( 0, nActiveStart
);
1433 xub_StrLen nNotActiveStart
= nLen
- pParentWindow
->aStrNotActive
.Len();
1434 if ( rName
.Copy( nNotActiveStart
) == pParentWindow
->aStrNotActive
)
1435 aRealName
= rName
.Copy( 0, nNotActiveStart
);
1439 BOOL bLoaded
= FALSE
;
1441 // ist es ein normal geladenes Doc ?
1443 SfxObjectShell
* pSh
= SfxObjectShell::GetFirst();
1444 while ( pSh
&& !bLoaded
)
1446 if ( pSh
->ISA(ScDocShell
) )
1447 if ( pSh
->GetTitle() == aRealName
)
1449 pSh
= SfxObjectShell::GetNext( *pSh
);
1455 SetManualDoc(aRealName
);
1457 else if (aHiddenTitle
.Len()) // verstecktes ausgewaehlt
1460 LoadFile(aHiddenName
);
1464 DBG_ERROR("SelectDoc: nicht gefunden");
1468 void ScContentTree::ApplySettings()
1470 const ScNavigatorSettings
* pSettings
= pParentWindow
->GetNavigatorSettings();
1473 USHORT nRootSel
= pSettings
->GetRootSelected();
1474 ULONG nChildSel
= pSettings
->GetChildSelected();
1476 for( USHORT nEntry
= 1; nEntry
< SC_CONTENT_COUNT
; ++nEntry
)
1478 if( pRootNodes
[ nEntry
] )
1481 BOOL bExp
= pSettings
->IsExpanded( nEntry
);
1482 if( bExp
!= IsExpanded( pRootNodes
[ nEntry
] ) )
1485 Expand( pRootNodes
[ nEntry
] );
1487 Collapse( pRootNodes
[ nEntry
] );
1491 if( nRootSel
== nEntry
)
1493 SvLBoxEntry
* pEntry
= NULL
;
1494 if( bExp
&& (nChildSel
!= SC_CONTENT_NOCHILD
) )
1495 pEntry
= GetEntry( pRootNodes
[ nEntry
], nChildSel
);
1496 Select( pEntry
? pEntry
: pRootNodes
[ nEntry
] );
1503 void ScContentTree::StoreSettings() const
1505 ScNavigatorSettings
* pSettings
= pParentWindow
->GetNavigatorSettings();
1508 for( USHORT nEntry
= 1; nEntry
< SC_CONTENT_COUNT
; ++nEntry
)
1510 BOOL bExp
= pRootNodes
[ nEntry
] && IsExpanded( pRootNodes
[ nEntry
] );
1511 pSettings
->SetExpanded( nEntry
, bExp
);
1515 GetEntryIndexes( nRoot
, nChild
, GetCurEntry() );
1516 pSettings
->SetRootSelected( nRoot
);
1517 pSettings
->SetChildSelected( nChild
);
1523 //------------------------------------------------------------------------