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"
74 #include "clipparam.hxx"
76 using namespace com::sun::star
;
78 // Reihenfolge der Kategorien im Navigator -------------------------------------
80 static USHORT pTypeList
[SC_CONTENT_COUNT
] =
82 SC_CONTENT_ROOT
, // ROOT (0) muss vorne stehen
93 BOOL
ScContentTree::bIsInDrag
= FALSE
;
96 ScDocShell
* ScContentTree::GetManualOrCurrent()
98 ScDocShell
* pSh
= NULL
;
99 if ( aManualDoc
.Len() )
101 TypeId aScType
= TYPE(ScDocShell
);
102 SfxObjectShell
* pObjSh
= SfxObjectShell::GetFirst( &aScType
);
103 while ( pObjSh
&& !pSh
)
105 if ( pObjSh
->GetTitle() == aManualDoc
)
106 pSh
= PTR_CAST( ScDocShell
, pObjSh
);
107 pObjSh
= SfxObjectShell::GetNext( *pObjSh
, &aScType
);
112 // Current nur, wenn keine manuell eingestellt ist
113 // (damit erkannt wird, wenn das Dokument nicht mehr existiert)
115 SfxViewShell
* pViewSh
= SfxViewShell::Current();
118 SfxObjectShell
* pObjSh
= pViewSh
->GetViewFrame()->GetObjectShell();
119 pSh
= PTR_CAST( ScDocShell
, pObjSh
);
130 ScContentTree::ScContentTree( Window
* pParent
, const ResId
& rResId
) :
131 SvTreeListBox ( pParent
, rResId
),
132 aEntryImages ( ScResId( RID_IMAGELIST_NAVCONT
) ),
133 aHCEntryImages ( ScResId( RID_IMAGELIST_H_NAVCONT
) ),
134 nRootType ( SC_CONTENT_ROOT
),
135 bHiddenDoc ( FALSE
),
136 pHiddenDocument ( NULL
)
139 for (i
=0; i
<SC_CONTENT_COUNT
; i
++)
140 pPosList
[pTypeList
[i
]] = i
; // invers zum suchen
142 pParentWindow
= (ScNavigatorDlg
*)pParent
;
144 pRootNodes
[0] = NULL
;
145 for (i
=1; i
<SC_CONTENT_COUNT
; i
++)
148 SetNodeDefaultImages();
150 SetDoubleClickHdl( LINK( this, ScContentTree
, ContentDoubleClickHdl
) );
153 ScContentTree::~ScContentTree()
157 void ScContentTree::InitRoot( USHORT nType
)
162 if ( nRootType
&& nRootType
!= nType
) // ausgeblendet ?
164 pRootNodes
[nType
] = NULL
;
168 const Image
& rImage
= aEntryImages
.GetImage( nType
);
169 String
aName( ScResId( SCSTR_CONTENT_ROOT
+ nType
) );
170 // wieder an die richtige Position:
171 USHORT nPos
= nRootType
? 0 : pPosList
[nType
]-1;
172 SvLBoxEntry
* pNew
= InsertEntry( aName
, rImage
, rImage
, NULL
, FALSE
, nPos
);
174 const Image
& rHCImage
= aHCEntryImages
.GetImage( nType
);
175 SetExpandedEntryBmp( pNew
, rHCImage
, BMP_COLOR_HIGHCONTRAST
);
176 SetCollapsedEntryBmp( pNew
, rHCImage
, BMP_COLOR_HIGHCONTRAST
);
178 pRootNodes
[nType
] = pNew
;
181 void ScContentTree::ClearAll()
184 for (USHORT i
=1; i
<SC_CONTENT_COUNT
; i
++)
188 void ScContentTree::ClearType(USHORT nType
)
194 SvLBoxEntry
* pParent
= pRootNodes
[nType
];
195 if ( !pParent
|| GetChildCount(pParent
) ) // nicht, wenn ohne Children schon da
198 GetModel()->Remove( pParent
); // mit allen Children
199 InitRoot( nType
); // ggf. neu eintragen
204 void ScContentTree::InsertContent( USHORT nType
, const String
& rValue
)
206 if (nType
>= SC_CONTENT_COUNT
)
208 DBG_ERROR("ScContentTree::InsertContent mit falschem Typ");
212 SvLBoxEntry
* pParent
= pRootNodes
[nType
];
214 InsertEntry( rValue
, pParent
);
217 DBG_ERROR("InsertContent ohne Parent");
221 void ScContentTree::GetEntryIndexes( USHORT
& rnRootIndex
, ULONG
& rnChildIndex
, SvLBoxEntry
* pEntry
) const
223 rnRootIndex
= SC_CONTENT_ROOT
;
224 rnChildIndex
= SC_CONTENT_NOCHILD
;
229 SvLBoxEntry
* pParent
= GetParent( pEntry
);
231 for( USHORT nRoot
= 1; !bFound
&& (nRoot
< SC_CONTENT_COUNT
); ++nRoot
)
233 if( pEntry
== pRootNodes
[ nRoot
] )
239 else if( pParent
&& (pParent
== pRootNodes
[ nRoot
]) )
243 // search the entry in all child entries of the parent
245 SvLBoxEntry
* pIterEntry
= FirstChild( pParent
);
246 while( !bFound
&& pIterEntry
)
248 if ( pEntry
== pIterEntry
)
250 rnChildIndex
= nEntry
;
251 bFound
= true; // exit the while loop
253 pIterEntry
= NextSibling( pIterEntry
);
257 bFound
= true; // exit the for loop
262 ULONG
ScContentTree::GetChildIndex( SvLBoxEntry
* pEntry
) const
266 GetEntryIndexes( nRoot
, nChild
, pEntry
);
270 String
lcl_GetDBAreaRange( ScDocument
* pDoc
, const String
& rDBName
)
275 ScDBCollection
* pDbNames
= pDoc
->GetDBCollection();
276 USHORT nCount
= pDbNames
->GetCount();
277 for ( USHORT i
=0; i
<nCount
; i
++ )
279 ScDBData
* pData
= (*pDbNames
)[i
];
280 if ( pData
->GetName() == rDBName
)
283 pData
->GetArea(aRange
);
284 aRange
.Format( aRet
, SCR_ABS_3D
, pDoc
);
292 IMPL_LINK( ScContentTree
, ContentDoubleClickHdl
, ScContentTree
*, EMPTYARG
)
296 SvLBoxEntry
* pEntry
= GetCurEntry();
297 GetEntryIndexes( nType
, nChild
, pEntry
);
299 if( pEntry
&& (nType
!= SC_CONTENT_ROOT
) && (nChild
!= SC_CONTENT_NOCHILD
) )
302 return 0; //! spaeter...
304 String
aText( GetEntryText( pEntry
) );
306 if ( aManualDoc
.Len() )
307 pParentWindow
->SetCurrentDoc( aManualDoc
);
311 case SC_CONTENT_TABLE
:
312 pParentWindow
->SetCurrentTableStr( aText
);
315 case SC_CONTENT_RANGENAME
:
316 pParentWindow
->SetCurrentCellStr( aText
);
319 case SC_CONTENT_DBAREA
:
321 // #47905# Wenn gleiche Bereichs- und DB-Namen existieren, wird
322 // bei SID_CURRENTCELL der Bereichsname genommen.
323 // DB-Bereiche darum direkt ueber die Adresse anspringen.
325 String aRangeStr
= lcl_GetDBAreaRange( GetSourceDocument(), aText
);
327 pParentWindow
->SetCurrentCellStr( aRangeStr
);
331 case SC_CONTENT_OLEOBJECT
:
332 case SC_CONTENT_GRAPHIC
:
333 case SC_CONTENT_DRAWING
:
334 pParentWindow
->SetCurrentObject( aText
);
337 case SC_CONTENT_NOTE
:
339 ScAddress aPos
= GetNotePos( nChild
);
340 pParentWindow
->SetCurrentTable( aPos
.Tab() );
341 pParentWindow
->SetCurrentCell( aPos
.Col(), aPos
.Row() );
345 case SC_CONTENT_AREALINK
:
347 const ScAreaLink
* pLink
= GetLink( nChild
);
350 ScRange aRange
= pLink
->GetDestArea();
352 ScDocument
* pSrcDoc
= GetSourceDocument();
353 aRange
.Format( aRangeStr
, SCR_ABS_3D
, pSrcDoc
, pSrcDoc
->GetAddressConvention() );
354 pParentWindow
->SetCurrentCellStr( aRangeStr
);
360 ScNavigatorDlg::ReleaseFocus(); // set focus into document
366 void ScContentTree::MouseButtonDown( const MouseEvent
& rMEvt
)
368 SvTreeListBox::MouseButtonDown( rMEvt
);
372 void ScContentTree::KeyInput( const KeyEvent
& rKEvt
)
376 const KeyCode aCode
= rKEvt
.GetKeyCode();
377 if (aCode
.GetCode() == KEY_RETURN
)
379 switch (aCode
.GetModifier())
382 ToggleRoot(); // toggle root mode (as in Writer)
387 SvLBoxEntry
* pEntry
= GetCurEntry();
392 GetEntryIndexes( nType
, nChild
, pEntry
);
394 if( (nType
!= SC_CONTENT_ROOT
) && (nChild
== SC_CONTENT_NOCHILD
) )
396 String
aText( GetEntryText( pEntry
) );
397 if ( IsExpanded( pEntry
) )
403 ContentDoubleClickHdl(0); // select content as if double clicked
414 SvTreeListBox::KeyInput(rKEvt
);
417 //BOOL __EXPORT ScContentTree::Drop( const DropEvent& rEvt )
419 // return pParentWindow->Drop(rEvt); // Drop auf Navigator
422 //BOOL __EXPORT ScContentTree::QueryDrop( DropEvent& rEvt )
424 // return pParentWindow->QueryDrop(rEvt); // Drop auf Navigator
427 sal_Int8
ScContentTree::AcceptDrop( const AcceptDropEvent
& /* rEvt */ )
429 return DND_ACTION_NONE
;
432 sal_Int8
ScContentTree::ExecuteDrop( const ExecuteDropEvent
& /* rEvt */ )
434 return DND_ACTION_NONE
;
437 void ScContentTree::StartDrag( sal_Int8
/* nAction */, const Point
& /* rPosPixel */ )
442 void ScContentTree::DragFinished( sal_Int8
/* nAction */ )
446 void __EXPORT
ScContentTree::Command( const CommandEvent
& rCEvt
)
450 switch ( rCEvt
.GetCommand() )
452 case COMMAND_STARTDRAG
:
453 // Aus dem ExecuteDrag heraus kann der Navigator geloescht werden
454 // (beim Umschalten auf einen anderen Dokument-Typ), das wuerde aber
455 // den StarView MouseMove-Handler, der Command() aufruft, umbringen.
456 // Deshalb Drag&Drop asynchron:
460 Application::PostUserEvent( STATIC_LINK( this, ScContentTree
, ExecDragHdl
) );
465 case COMMAND_CONTEXTMENU
:
470 ScPopupMenu
aDropMenu( ScResId( RID_POPUP_DROPMODE
) );
471 aDropMenu
.CheckItem( RID_DROPMODE_URL
+ pParentWindow
->GetDropMode() );
472 aPop
.InsertItem( 1, pParentWindow
->GetStrDragMode() );
473 aPop
.SetPopupMenu( 1, &aDropMenu
);
475 // angezeigtes Dokument
477 ScPopupMenu aDocMenu
;
478 aDocMenu
.SetMenuFlags( aDocMenu
.GetMenuFlags() | MENU_FLAG_NOAUTOMNEMONICS
);
481 // geladene Dokumente
482 ScDocShell
* pCurrentSh
= PTR_CAST( ScDocShell
, SfxObjectShell::Current() );
483 SfxObjectShell
* pSh
= SfxObjectShell::GetFirst();
486 if ( pSh
->ISA(ScDocShell
) )
488 String aName
= pSh
->GetTitle();
489 String aEntry
= aName
;
490 if ( pSh
== pCurrentSh
)
491 aEntry
+= pParentWindow
->aStrActive
;
493 aEntry
+= pParentWindow
->aStrNotActive
;
494 aDocMenu
.InsertItem( ++i
, aEntry
);
495 if ( !bHiddenDoc
&& aName
== aManualDoc
)
498 pSh
= SfxObjectShell::GetNext( *pSh
);
501 aDocMenu
.InsertItem( ++i
, pParentWindow
->aStrActiveWin
);
502 if (!bHiddenDoc
&& !aManualDoc
.Len())
504 // verstecktes Dokument
505 if ( aHiddenTitle
.Len() )
507 String aEntry
= aHiddenTitle
;
508 aEntry
+= pParentWindow
->aStrHidden
;
509 aDocMenu
.InsertItem( ++i
, aEntry
);
513 aDocMenu
.CheckItem( nPos
);
514 aPop
.InsertItem( 2, pParentWindow
->GetStrDisplay() );
515 aPop
.SetPopupMenu( 2, &aDocMenu
);
519 aPop
.Execute( this, rCEvt
.GetMousePosPixel() );
521 if ( aDropMenu
.WasHit() ) // Drag-Drop Modus
523 USHORT nId
= aDropMenu
.GetSelected();
524 if ( nId
>= RID_DROPMODE_URL
&& nId
<= RID_DROPMODE_COPY
)
525 pParentWindow
->SetDropMode( nId
- RID_DROPMODE_URL
);
527 else if ( aDocMenu
.WasHit() ) // angezeigtes Dokument
529 USHORT nId
= aDocMenu
.GetSelected();
530 String aName
= aDocMenu
.GetItemText(nId
);
538 SvTreeListBox::Command(rCEvt
);
541 void __EXPORT
ScContentTree::RequestHelp( const HelpEvent
& rHEvt
)
544 if( rHEvt
.GetMode() & HELPMODE_QUICK
)
546 Point
aPos( ScreenToOutputPixel( rHEvt
.GetMousePosPixel() ));
547 SvLBoxEntry
* pEntry
= GetEntry( aPos
);
552 SvLBoxEntry
* pParent
= GetParent(pEntry
);
553 if ( !pParent
) // Top-Level ?
555 aHelpText
= String::CreateFromInt32( GetChildCount(pEntry
) );
557 aHelpText
+= GetEntryText(pEntry
);
560 else if ( pParent
== pRootNodes
[SC_CONTENT_NOTE
] )
562 aHelpText
= GetEntryText(pEntry
); // Notizen als Help-Text
565 else if ( pParent
== pRootNodes
[SC_CONTENT_AREALINK
] )
567 ULONG nIndex
= GetChildIndex(pEntry
);
568 if( nIndex
!= SC_CONTENT_NOCHILD
)
570 const ScAreaLink
* pLink
= GetLink(nIndex
);
573 aHelpText
= pLink
->GetFile(); // Source-Datei als Help-Text
582 SvLBoxString
* pItem
= (SvLBoxString
*)(GetItem( pEntry
, aPos
.X(), &pTab
));
585 aPos
= GetEntryPosition( pEntry
);
586 aPos
.X() = GetTabPos( pEntry
, pTab
);
587 aPos
= OutputToScreenPixel(aPos
);
588 Size
aSize( pItem
->GetSize( this, pEntry
) );
590 Rectangle
aItemRect( aPos
, aSize
);
591 Help::ShowQuickHelp( this, aItemRect
, aHelpText
);
598 Window::RequestHelp( rHEvt
);
601 ScDocument
* ScContentTree::GetSourceDocument()
604 return pHiddenDocument
;
607 ScDocShell
* pSh
= GetManualOrCurrent();
609 return pSh
->GetDocument();
615 void ScContentTree::Refresh( USHORT nType
)
617 if ( bHiddenDoc
&& !pHiddenDocument
)
618 return; // anderes Dokument angezeigt
620 // wenn sich nichts geaendert hat, gleich abbrechen (gegen Geflacker)
622 if ( nType
== SC_CONTENT_NOTE
)
623 if (!NoteStringsChanged())
625 if ( nType
== SC_CONTENT_GRAPHIC
)
626 if (!DrawNamesChanged(SC_CONTENT_GRAPHIC
))
628 if ( nType
== SC_CONTENT_OLEOBJECT
)
629 if (!DrawNamesChanged(SC_CONTENT_OLEOBJECT
))
631 if ( nType
== SC_CONTENT_DRAWING
)
632 if (!DrawNamesChanged(SC_CONTENT_DRAWING
))
635 SetUpdateMode(FALSE
);
639 if ( !nType
|| nType
== SC_CONTENT_TABLE
)
641 if ( !nType
|| nType
== SC_CONTENT_RANGENAME
)
643 if ( !nType
|| nType
== SC_CONTENT_DBAREA
)
645 if ( !nType
|| nType
== SC_CONTENT_GRAPHIC
)
647 if ( !nType
|| nType
== SC_CONTENT_OLEOBJECT
)
649 if ( !nType
|| nType
== SC_CONTENT_DRAWING
)
651 if ( !nType
|| nType
== SC_CONTENT_NOTE
)
653 if ( !nType
|| nType
== SC_CONTENT_AREALINK
)
660 void ScContentTree::GetTableNames()
662 if ( nRootType
&& nRootType
!= SC_CONTENT_TABLE
) // ausgeblendet ?
665 ScDocument
* pDoc
= GetSourceDocument();
670 SCTAB nCount
= pDoc
->GetTableCount();
671 for ( SCTAB i
=0; i
<nCount
; i
++ )
673 pDoc
->GetName( i
, aName
);
674 InsertContent( SC_CONTENT_TABLE
, aName
);
678 void ScContentTree::GetAreaNames()
680 if ( nRootType
&& nRootType
!= SC_CONTENT_RANGENAME
) // ausgeblendet ?
683 ScDocument
* pDoc
= GetSourceDocument();
687 ScRangeName
* pRangeNames
= pDoc
->GetRangeName();
688 USHORT nCount
= pRangeNames
->GetCount();
691 USHORT nValidCount
= 0;
694 for ( i
=0; i
<nCount
; i
++ )
696 ScRangeData
* pData
= (*pRangeNames
)[i
];
697 if (pData
->IsValidReference(aDummy
))
702 ScRangeData
** ppSortArray
= new ScRangeData
* [ nValidCount
];
704 for ( i
=0, j
=0; i
<nCount
; i
++ )
706 ScRangeData
* pData
= (*pRangeNames
)[i
];
707 if (pData
->IsValidReference(aDummy
))
708 ppSortArray
[j
++] = pData
;
711 qsort( (void*)ppSortArray
, nValidCount
, sizeof(ScRangeData
*),
712 &ScRangeData_QsortNameCompare
);
714 qsort( (void*)ppSortArray
, nValidCount
, sizeof(ScRangeData
*),
715 ICCQsortNameCompare
);
717 for ( j
=0; j
<nValidCount
; j
++ )
718 InsertContent( SC_CONTENT_RANGENAME
, ppSortArray
[j
]->GetName() );
719 delete [] ppSortArray
;
724 void ScContentTree::GetDbNames()
726 if ( nRootType
&& nRootType
!= SC_CONTENT_DBAREA
) // ausgeblendet ?
729 ScDocument
* pDoc
= GetSourceDocument();
733 ScDBCollection
* pDbNames
= pDoc
->GetDBCollection();
734 USHORT nCount
= pDbNames
->GetCount();
737 String
aStrNoName( ScGlobal::GetRscString(STR_DB_NONAME
) );
738 for ( USHORT i
=0; i
<nCount
; i
++ )
740 ScDBData
* pData
= (*pDbNames
)[i
];
741 String aStrName
= pData
->GetName();
742 if ( aStrName
!= aStrNoName
)
743 InsertContent( SC_CONTENT_DBAREA
, aStrName
);
748 bool ScContentTree::IsPartOfType( USHORT nContentType
, USHORT nObjIdentifier
) // static
751 switch ( nContentType
)
753 case SC_CONTENT_GRAPHIC
:
754 bRet
= ( nObjIdentifier
== OBJ_GRAF
);
756 case SC_CONTENT_OLEOBJECT
:
757 bRet
= ( nObjIdentifier
== OBJ_OLE2
);
759 case SC_CONTENT_DRAWING
:
760 bRet
= ( nObjIdentifier
!= OBJ_GRAF
&& nObjIdentifier
!= OBJ_OLE2
); // everything else
763 DBG_ERROR("unknown content type");
768 void ScContentTree::GetDrawNames( USHORT nType
)
770 if ( nRootType
&& nRootType
!= nType
) // ausgeblendet ?
773 ScDocument
* pDoc
= GetSourceDocument();
777 // iterate in flat mode for groups
778 SdrIterMode eIter
= ( nType
== SC_CONTENT_DRAWING
) ? IM_FLAT
: IM_DEEPNOGROUPS
;
780 ScDrawLayer
* pDrawLayer
= pDoc
->GetDrawLayer();
781 SfxObjectShell
* pShell
= pDoc
->GetDocumentShell();
782 if (pDrawLayer
&& pShell
)
784 SCTAB nTabCount
= pDoc
->GetTableCount();
785 for (SCTAB nTab
=0; nTab
<nTabCount
; nTab
++)
787 SdrPage
* pPage
= pDrawLayer
->GetPage(static_cast<sal_uInt16
>(nTab
));
788 DBG_ASSERT(pPage
,"Page ?");
791 SdrObjListIter
aIter( *pPage
, eIter
);
792 SdrObject
* pObject
= aIter
.Next();
795 if ( IsPartOfType( nType
, pObject
->GetObjIdentifier() ) )
797 String aName
= ScDrawLayer::GetVisibleName( pObject
);
799 InsertContent( nType
, aName
);
802 pObject
= aIter
.Next();
809 void ScContentTree::GetGraphicNames()
811 GetDrawNames( SC_CONTENT_GRAPHIC
);
814 void ScContentTree::GetOleNames()
816 GetDrawNames( SC_CONTENT_OLEOBJECT
);
819 void ScContentTree::GetDrawingNames()
821 GetDrawNames( SC_CONTENT_DRAWING
);
824 void ScContentTree::GetLinkNames()
826 if ( nRootType
&& nRootType
!= SC_CONTENT_AREALINK
) // ausgeblendet ?
829 ScDocument
* pDoc
= GetSourceDocument();
833 SvxLinkManager
* pLinkManager
= pDoc
->GetLinkManager();
834 DBG_ASSERT(pLinkManager
, "kein LinkManager am Dokument?");
835 const ::sfx2::SvBaseLinks
& rLinks
= pLinkManager
->GetLinks();
836 USHORT nCount
= rLinks
.Count();
837 for (USHORT i
=0; i
<nCount
; i
++)
839 ::sfx2::SvBaseLink
* pBase
= *rLinks
[i
];
840 if (pBase
->ISA(ScAreaLink
))
841 InsertContent( SC_CONTENT_AREALINK
, ((ScAreaLink
*)pBase
)->GetSource() );
843 // in der Liste die Namen der Quellbereiche
847 const ScAreaLink
* ScContentTree::GetLink( ULONG nIndex
)
849 ScDocument
* pDoc
= GetSourceDocument();
854 SvxLinkManager
* pLinkManager
= pDoc
->GetLinkManager();
855 DBG_ASSERT(pLinkManager
, "kein LinkManager am Dokument?");
856 const ::sfx2::SvBaseLinks
& rLinks
= pLinkManager
->GetLinks();
857 USHORT nCount
= rLinks
.Count();
858 for (USHORT i
=0; i
<nCount
; i
++)
860 ::sfx2::SvBaseLink
* pBase
= *rLinks
[i
];
861 if (pBase
->ISA(ScAreaLink
))
863 if (nFound
== nIndex
)
864 return (const ScAreaLink
*) pBase
;
869 DBG_ERROR("Link nicht gefunden");
873 String
lcl_NoteString( const ScPostIt
& rNote
)
875 String aText
= rNote
.GetText();
877 while ( (nAt
= aText
.Search( '\n' )) != STRING_NOTFOUND
)
878 aText
.SetChar( nAt
, ' ' );
882 void ScContentTree::GetNoteStrings()
884 if ( nRootType
&& nRootType
!= SC_CONTENT_NOTE
) // ausgeblendet ?
887 ScDocument
* pDoc
= GetSourceDocument();
891 SCTAB nTabCount
= pDoc
->GetTableCount();
892 for (SCTAB nTab
=0; nTab
<nTabCount
; nTab
++)
894 ScCellIterator
aIter( pDoc
, 0,0,nTab
, MAXCOL
,MAXROW
,nTab
);
895 for( ScBaseCell
* pCell
= aIter
.GetFirst(); pCell
; pCell
= aIter
.GetNext() )
896 if( const ScPostIt
* pNote
= pCell
->GetNote() )
897 InsertContent( SC_CONTENT_NOTE
, lcl_NoteString( *pNote
) );
901 ScAddress
ScContentTree::GetNotePos( ULONG nIndex
)
903 ScDocument
* pDoc
= GetSourceDocument();
908 SCTAB nTabCount
= pDoc
->GetTableCount();
909 for (SCTAB nTab
=0; nTab
<nTabCount
; nTab
++)
911 ScCellIterator
aIter( pDoc
, 0,0,nTab
, MAXCOL
,MAXROW
,nTab
);
912 ScBaseCell
* pCell
= aIter
.GetFirst();
915 if( pCell
->HasNote() )
917 if (nFound
== nIndex
)
918 return ScAddress( aIter
.GetCol(), aIter
.GetRow(), nTab
); // gefunden
921 pCell
= aIter
.GetNext();
925 DBG_ERROR("Notiz nicht gefunden");
929 BOOL
ScContentTree::NoteStringsChanged()
931 ScDocument
* pDoc
= GetSourceDocument();
935 SvLBoxEntry
* pParent
= pRootNodes
[SC_CONTENT_NOTE
];
939 SvLBoxEntry
* pEntry
= FirstChild( pParent
);
942 SCTAB nTabCount
= pDoc
->GetTableCount();
943 for (SCTAB nTab
=0; nTab
<nTabCount
&& bEqual
; nTab
++)
945 ScCellIterator
aIter( pDoc
, 0,0,nTab
, MAXCOL
,MAXROW
,nTab
);
946 ScBaseCell
* pCell
= aIter
.GetFirst();
947 while (pCell
&& bEqual
)
949 if( const ScPostIt
* pNote
= pCell
->GetNote() )
955 if ( lcl_NoteString( *pNote
) != GetEntryText(pEntry
) )
958 pEntry
= NextSibling( pEntry
);
961 pCell
= aIter
.GetNext();
966 bEqual
= FALSE
; // kommt noch was
971 BOOL
ScContentTree::DrawNamesChanged( USHORT nType
)
973 ScDocument
* pDoc
= GetSourceDocument();
977 SvLBoxEntry
* pParent
= pRootNodes
[nType
];
981 SvLBoxEntry
* pEntry
= FirstChild( pParent
);
983 // iterate in flat mode for groups
984 SdrIterMode eIter
= ( nType
== SC_CONTENT_DRAWING
) ? IM_FLAT
: IM_DEEPNOGROUPS
;
987 ScDrawLayer
* pDrawLayer
= pDoc
->GetDrawLayer();
988 SfxObjectShell
* pShell
= pDoc
->GetDocumentShell();
989 if (pDrawLayer
&& pShell
)
991 SCTAB nTabCount
= pDoc
->GetTableCount();
992 for (SCTAB nTab
=0; nTab
<nTabCount
&& bEqual
; nTab
++)
994 SdrPage
* pPage
= pDrawLayer
->GetPage(static_cast<sal_uInt16
>(nTab
));
995 DBG_ASSERT(pPage
,"Page ?");
998 SdrObjListIter
aIter( *pPage
, eIter
);
999 SdrObject
* pObject
= aIter
.Next();
1000 while (pObject
&& bEqual
)
1002 if ( IsPartOfType( nType
, pObject
->GetObjIdentifier() ) )
1008 if ( ScDrawLayer::GetVisibleName( pObject
) != GetEntryText(pEntry
) )
1011 pEntry
= NextSibling( pEntry
);
1014 pObject
= aIter
.Next();
1021 bEqual
= FALSE
; // kommt noch was
1026 BOOL
lcl_GetRange( ScDocument
* pDoc
, USHORT nType
, const String
& rName
, ScRange
& rRange
)
1028 BOOL bFound
= FALSE
;
1031 if ( nType
== SC_CONTENT_RANGENAME
)
1033 ScRangeName
* pList
= pDoc
->GetRangeName();
1035 if (pList
->SearchName( rName
, nPos
))
1036 if ( (*pList
)[nPos
]->IsValidReference( rRange
) )
1039 else if ( nType
== SC_CONTENT_DBAREA
)
1041 ScDBCollection
* pList
= pDoc
->GetDBCollection();
1043 if (pList
->SearchName( rName
, nPos
))
1048 (*pList
)[nPos
]->GetArea(nTab
,nCol1
,nRow1
,nCol2
,nRow2
);
1049 rRange
= ScRange( nCol1
,nRow1
,nTab
, nCol2
,nRow2
,nTab
);
1057 void lcl_DoDragObject( ScDocShell
* pSrcShell
, const String
& rName
, USHORT nType
, Window
* pWin
)
1059 ScDocument
* pSrcDoc
= pSrcShell
->GetDocument();
1060 ScDrawLayer
* pModel
= pSrcDoc
->GetDrawLayer();
1063 BOOL bOle
= ( nType
== SC_CONTENT_OLEOBJECT
);
1064 BOOL bGraf
= ( nType
== SC_CONTENT_GRAPHIC
);
1065 USHORT nDrawId
= sal::static_int_cast
<USHORT
>( bOle
? OBJ_OLE2
: ( bGraf
? OBJ_GRAF
: OBJ_GRUP
) );
1067 SdrObject
* pObject
= pModel
->GetNamedObject( rName
, nDrawId
, nTab
);
1070 SdrView
aEditView( pModel
);
1071 aEditView
.ShowSdrPage(aEditView
.GetModel()->GetPage(nTab
));
1072 SdrPageView
* pPV
= aEditView
.GetSdrPageView();
1073 aEditView
.MarkObj(pObject
, pPV
);
1075 SdrModel
* pDragModel
= aEditView
.GetAllMarkedModel();
1077 TransferableObjectDescriptor aObjDesc
;
1078 pSrcShell
->FillTransferableObjectDescriptor( aObjDesc
);
1079 aObjDesc
.maDisplayName
= pSrcShell
->GetMedium()->GetURLObject().GetURLNoPass();
1080 // maSize is set in ScDrawTransferObj ctor
1082 ScDrawTransferObj
* pTransferObj
= new ScDrawTransferObj( pDragModel
, pSrcShell
, aObjDesc
);
1083 uno::Reference
<datatransfer::XTransferable
> xTransferable( pTransferObj
);
1085 pTransferObj
->SetDragSourceObj( pObject
, nTab
);
1086 pTransferObj
->SetDragSourceFlags( SC_DROP_NAVIGATOR
);
1088 SC_MOD()->SetDragObject( NULL
, pTransferObj
);
1089 pWin
->ReleaseMouse();
1090 pTransferObj
->StartDrag( pWin
, DND_ACTION_COPYMOVE
| DND_ACTION_LINK
);
1095 void lcl_DoDragCells( ScDocShell
* pSrcShell
, const ScRange
& rRange
, USHORT nFlags
, Window
* pWin
)
1098 aMark
.SelectTable( rRange
.aStart
.Tab(), TRUE
);
1099 aMark
.SetMarkArea( rRange
);
1101 ScDocument
* pSrcDoc
= pSrcShell
->GetDocument();
1102 if ( !pSrcDoc
->HasSelectedBlockMatrixFragment( rRange
.aStart
.Col(), rRange
.aStart
.Row(),
1103 rRange
.aEnd
.Col(), rRange
.aEnd
.Row(),
1106 ScDocument
* pClipDoc
= new ScDocument( SCDOCMODE_CLIP
);
1107 ScClipParam
aClipParam(rRange
, false);
1108 pSrcDoc
->CopyToClip(aClipParam
, pClipDoc
, &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 //------------------------------------------------------------------------