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: sdtreelb.cxx,v $
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_sd.hxx"
34 #include <sal/types.h>
35 #include <sot/formats.hxx>
36 #include <sot/storage.hxx>
37 #include <vcl/msgbox.hxx>
38 #include <svtools/urihelper.hxx>
39 #include <svx/svditer.hxx>
40 #include <sfx2/docfile.hxx>
41 #include <svx/svdoole2.hxx>
42 #include <vcl/svapp.hxx>
43 #include "cusshow.hxx"
44 #include <sfx2/childwin.hxx>
46 #include <sfx2/viewfrm.hxx>
49 #include "sdtreelb.hxx"
50 #include "DrawDocShell.hxx"
51 #include "drawdoc.hxx"
53 #include "sdresid.hxx"
54 #include "navigatr.hxx"
56 #include "strings.hrc"
58 #include "res_bmp.hrc"
60 #include <com/sun/star/embed/XEmbedPersist.hpp>
61 #include <svtools/embedtransfer.hxx>
62 #include <ViewShell.hxx>
64 using namespace com::sun::star
;
66 class SdPageObjsTLB::IconProvider
74 Image maImgPageObjsExcl
;
79 // High contrast icons.
82 Image maImgPageObjsExclH
;
89 BOOL SD_DLLPRIVATE
SdPageObjsTLB::bIsInDrag
= FALSE
;
91 BOOL
SdPageObjsTLB::IsInDrag()
96 sal_uInt32
SdPageObjsTLB::SdPageObjsTransferable::mnListBoxDropFormatId
= SAL_MAX_UINT32
;
98 // -----------------------------------------
99 // - SdPageObjsTLB::SdPageObjsTransferable -
100 // -----------------------------------------
102 SdPageObjsTLB::SdPageObjsTransferable::SdPageObjsTransferable(
103 SdPageObjsTLB
& rParent
,
104 const INetBookmark
& rBookmark
,
105 ::sd::DrawDocShell
& rDocShell
,
106 NavigatorDragType eDragType
,
107 const ::com::sun::star::uno::Any
& rTreeListBoxData
)
108 : SdTransferable(rDocShell
.GetDoc(), NULL
, TRUE
),
110 maBookmark( rBookmark
),
111 mrDocShell( rDocShell
),
112 meDragType( eDragType
),
113 maTreeListBoxData( rTreeListBoxData
)
120 SdPageObjsTLB::SdPageObjsTransferable::~SdPageObjsTransferable()
124 // -----------------------------------------------------------------------------
126 void SdPageObjsTLB::SdPageObjsTransferable::AddSupportedFormats()
128 AddFormat(SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK
);
129 AddFormat(SOT_FORMATSTR_ID_TREELISTBOX
);
130 AddFormat(GetListBoxDropFormatId());
133 // -----------------------------------------------------------------------------
135 sal_Bool
SdPageObjsTLB::SdPageObjsTransferable::GetData( const ::com::sun::star::datatransfer::DataFlavor
& rFlavor
)
137 ULONG nFormatId
= SotExchange::GetFormat( rFlavor
);
140 case SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK
:
141 SetINetBookmark( maBookmark
, rFlavor
);
144 case SOT_FORMATSTR_ID_TREELISTBOX
:
145 SetAny(maTreeListBoxData
, rFlavor
);
153 // -----------------------------------------------------------------------------
155 void SdPageObjsTLB::SdPageObjsTransferable::DragFinished( sal_Int8 nDropAction
)
157 mrParent
.OnDragFinished( nDropAction
);
160 // -----------------------------------------------------------------------------
162 ::sd::DrawDocShell
& SdPageObjsTLB::SdPageObjsTransferable::GetDocShell() const
167 // -----------------------------------------------------------------------------
169 NavigatorDragType
SdPageObjsTLB::SdPageObjsTransferable::GetDragType() const
174 // -----------------------------------------------------------------------------
176 sal_Int64 SAL_CALL
SdPageObjsTLB::SdPageObjsTransferable::getSomething( const ::com::sun::star::uno::Sequence
< sal_Int8
>& rId
) throw( ::com::sun::star::uno::RuntimeException
)
180 if( ( rId
.getLength() == 16 ) &&
181 ( 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), rId
.getConstArray(), 16 ) ) )
183 nRet
= (sal_Int64
)(sal_IntPtr
)this;
186 nRet
= SdTransferable::getSomething(rId
);
191 // -----------------------------------------------------------------------------
193 const ::com::sun::star::uno::Sequence
< sal_Int8
>& SdPageObjsTLB::SdPageObjsTransferable::getUnoTunnelId()
195 static ::com::sun::star::uno::Sequence
< sal_Int8
> aSeq
;
197 if( !aSeq
.getLength() )
199 static osl::Mutex aCreateMutex
;
200 osl::MutexGuard
aGuard( aCreateMutex
);
203 rtl_createUuid( reinterpret_cast< sal_uInt8
* >( aSeq
.getArray() ), 0, sal_True
);
209 // -----------------------------------------------------------------------------
211 SdPageObjsTLB::SdPageObjsTransferable
* SdPageObjsTLB::SdPageObjsTransferable::getImplementation( const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& rxData
)
216 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XUnoTunnel
> xUnoTunnel( rxData
, ::com::sun::star::uno::UNO_QUERY_THROW
);
218 return reinterpret_cast<SdPageObjsTLB::SdPageObjsTransferable
*>(
219 sal::static_int_cast
<sal_uIntPtr
>(
220 xUnoTunnel
->getSomething( SdPageObjsTLB::SdPageObjsTransferable::getUnoTunnelId()) ) );
222 catch( const ::com::sun::star::uno::Exception
& )
229 sal_uInt32
SdPageObjsTLB::SdPageObjsTransferable::GetListBoxDropFormatId (void)
231 if (mnListBoxDropFormatId
== SAL_MAX_UINT32
)
232 mnListBoxDropFormatId
= SotExchange::RegisterFormatMimeType(
233 ::rtl::OUString::createFromAscii(
234 "application/x-openoffice-treelistbox-moveonly;"
235 "windows_formatname=\"SV_LBOX_DD_FORMAT_MOVE\""));
236 return mnListBoxDropFormatId
;
239 /*************************************************************************
241 |* Ctor1 SdPageObjsTLB
243 \************************************************************************/
245 SdPageObjsTLB::SdPageObjsTLB( Window
* pParentWin
, const SdResId
& rSdResId
)
246 : SvTreeListBox ( pParentWin
, rSdResId
)
247 , mpParent ( pParentWin
)
249 , mpBookmarkDoc ( NULL
)
251 , mpOwnMedium ( NULL
)
252 , maImgOle ( BitmapEx( SdResId( BMP_OLE
) ) )
253 , maImgGraphic ( BitmapEx( SdResId( BMP_GRAPHIC
) ) )
254 , maImgOleH ( BitmapEx( SdResId( BMP_OLE_H
) ) )
255 , maImgGraphicH ( BitmapEx( SdResId( BMP_GRAPHIC_H
) ) )
256 , mbLinkableSelected ( FALSE
)
257 , mpDropNavWin ( NULL
)
258 , mbShowAllShapes ( false )
259 , mbShowAllPages ( false )
262 // Tree-ListBox mit Linien versehen
263 SetWindowBits( WinBits( WB_TABSTOP
| WB_BORDER
| WB_HASLINES
|
264 WB_HASBUTTONS
| // WB_HASLINESATROOT |
265 WB_HSCROLL
| // #31562#
266 WB_HASBUTTONSATROOT
) );
267 SetNodeBitmaps( Bitmap( SdResId( BMP_EXPAND
) ),
268 Bitmap( SdResId( BMP_COLLAPSE
) ) );
270 SetNodeBitmaps( Bitmap( SdResId( BMP_EXPAND_H
) ),
271 Bitmap( SdResId( BMP_COLLAPSE_H
) ),
272 BMP_COLOR_HIGHCONTRAST
);
275 SV_DRAGDROP_CTRL_MOVE
| SV_DRAGDROP_CTRL_COPY
|
276 SV_DRAGDROP_APP_MOVE
| SV_DRAGDROP_APP_COPY
| SV_DRAGDROP_APP_DROP
);
279 /*************************************************************************
281 |* Dtor SdPageObjsTLB
283 \************************************************************************/
285 SdPageObjsTLB::~SdPageObjsTLB()
290 // no document was created from mpMedium, so this object is still the owner of it
294 /*************************************************************************
296 |* return name of object
298 \************************************************************************/
300 String
SdPageObjsTLB::GetObjectName(
301 const SdrObject
* pObject
,
302 const bool bCreate
) const
308 aRet
= pObject
->GetName();
310 if( !aRet
.Len() && pObject
->ISA( SdrOle2Obj
) )
311 aRet
= static_cast< const SdrOle2Obj
* >( pObject
)->GetPersistName();
319 aRet
= SdResId(STR_NAVIGATOR_SHAPE_BASE_NAME
);
320 aRet
.SearchAndReplaceAscii("%1", String::CreateFromInt32(pObject
->GetOrdNum() + 1));
326 /*************************************************************************
328 |* In TreeLB Eintrag selektieren
330 \************************************************************************/
332 BOOL
SdPageObjsTLB::SelectEntry( const String
& rName
)
338 SvLBoxEntry
* pEntry
= NULL
;
341 for( pEntry
= First(); pEntry
&& !bFound
; pEntry
= Next( pEntry
) )
343 aTmp
= GetEntryText( pEntry
);
347 SetCurEntry( pEntry
);
354 /*************************************************************************
356 |* Gibt zurueck, ob Childs des uebergebenen Strings selektiert sind
358 \************************************************************************/
360 BOOL
SdPageObjsTLB::HasSelectedChilds( const String
& rName
)
363 BOOL bChilds
= FALSE
;
367 SvLBoxEntry
* pEntry
= NULL
;
370 for( pEntry
= First(); pEntry
&& !bFound
; pEntry
= Next( pEntry
) )
372 aTmp
= GetEntryText( pEntry
);
376 BOOL bExpanded
= IsExpanded( pEntry
);
377 long nCount
= GetChildSelectionCount( pEntry
);
378 if( bExpanded
&& nCount
> 0 )
387 /*************************************************************************
389 |* TreeLB mit Seiten und Objekten fuellen
391 \************************************************************************/
393 void SdPageObjsTLB::Fill( const SdDrawDocument
* pInDoc
, BOOL bAllPages
,
394 const String
& rDocName
)
397 if( GetSelectionCount() > 0 )
399 aSelection
= GetSelectEntry();
404 maDocName
= rDocName
;
405 mbShowAllPages
= (bAllPages
== TRUE
);
408 SdPage
* pPage
= NULL
;
410 IconProvider aIconProvider
;
412 // first insert all pages including objects
414 const USHORT nMaxPages
= mpDoc
->GetPageCount();
416 while( nPage
< nMaxPages
)
418 pPage
= (SdPage
*) mpDoc
->GetPage( nPage
);
419 if( (mbShowAllPages
|| pPage
->GetPageKind() == PK_STANDARD
)
420 && !(pPage
->GetPageKind()==PK_HANDOUT
) ) //#94954# never list the normal handout page ( handout-masterpage is used instead )
422 BOOL bPageExluded
= pPage
->IsExcluded();
424 bool bPageBelongsToShow
= PageBelongsToCurrentShow (pPage
);
425 bPageExluded
|= !bPageBelongsToShow
;
427 AddShapeList(*pPage
, NULL
, pPage
->GetName(), bPageExluded
, NULL
, aIconProvider
);
432 // dann alle MasterPages incl. Objekte einfuegen
436 const USHORT nMaxMasterPages
= mpDoc
->GetMasterPageCount();
438 while( nPage
< nMaxMasterPages
)
440 pPage
= (SdPage
*) mpDoc
->GetMasterPage( nPage
);
441 AddShapeList(*pPage
, NULL
, pPage
->GetName(), false, NULL
, aIconProvider
);
445 if( aSelection
.Len() )
446 SelectEntry( aSelection
);
449 /*************************************************************************
451 |* Es wird nur der erste Eintrag eingefuegt. Childs werden OnDemand erzeugt
453 \************************************************************************/
455 void SdPageObjsTLB::Fill( const SdDrawDocument
* pInDoc
, SfxMedium
* pInMedium
,
456 const String
& rDocName
)
460 // this object now owns the Medium
461 mpMedium
= pInMedium
;
462 maDocName
= rDocName
;
464 Image aImgDocOpen
=Image( BitmapEx( SdResId( BMP_DOC_OPEN
) ) );
465 Image aImgDocClosed
=Image( BitmapEx( SdResId( BMP_DOC_CLOSED
) ) );
466 Image aImgDocOpenH
=Image( BitmapEx( SdResId( BMP_DOC_OPEN_H
) ) );
467 Image aImgDocClosedH
=Image( BitmapEx( SdResId( BMP_DOC_CLOSED_H
) ) );
469 // Dokumentnamen einfuegen
470 SvLBoxEntry
* pFileEntry
= InsertEntry( maDocName
,
476 reinterpret_cast< void* >( 1 ) );
478 SetExpandedEntryBmp( pFileEntry
, aImgDocOpenH
, BMP_COLOR_HIGHCONTRAST
);
479 SetCollapsedEntryBmp( pFileEntry
, aImgDocClosedH
, BMP_COLOR_HIGHCONTRAST
);
485 void SdPageObjsTLB::AddShapeList (
486 const SdrObjList
& rList
,
488 const ::rtl::OUString
& rsName
,
489 const bool bIsExcluded
,
490 SvLBoxEntry
* pParentEntry
,
491 const IconProvider
& rIconProvider
)
493 Image
aIcon (rIconProvider
.maImgPage
);
495 aIcon
= rIconProvider
.maImgPageExcl
;
496 else if (pShape
!= NULL
)
497 aIcon
= rIconProvider
.maImgGroup
;
499 void* pUserData (reinterpret_cast<void*>(1));
503 SvLBoxEntry
* pEntry
= InsertEntry(
514 bIsExcluded
? rIconProvider
.maImgPageExclH
: rIconProvider
.maImgPageH
,
515 BMP_COLOR_HIGHCONTRAST
);
516 SetCollapsedEntryBmp(
518 bIsExcluded
? rIconProvider
.maImgPageExclH
: rIconProvider
.maImgPageH
,
519 BMP_COLOR_HIGHCONTRAST
);
521 SdrObjListIter
aIter(
523 !rList
.HasObjectNavigationOrder() /* use navigation order, if available */,
525 FALSE
/*not reverse*/);
527 while( aIter
.IsMore() )
529 SdrObject
* pObj
= aIter
.Next();
530 OSL_ASSERT(pObj
!=NULL
);
532 // Get the shape name.
533 String
aStr (GetObjectName( pObj
) );
537 if( pObj
->GetObjInventor() == SdrInventor
&& pObj
->GetObjIdentifier() == OBJ_OLE2
)
539 SvLBoxEntry
* pNewEntry
= InsertEntry( aStr
, maImgOle
, maImgOle
, pEntry
,
540 FALSE
, LIST_APPEND
, pObj
);
542 SetExpandedEntryBmp( pNewEntry
, maImgOleH
, BMP_COLOR_HIGHCONTRAST
);
543 SetCollapsedEntryBmp( pNewEntry
, maImgOleH
, BMP_COLOR_HIGHCONTRAST
);
545 else if( pObj
->GetObjInventor() == SdrInventor
&& pObj
->GetObjIdentifier() == OBJ_GRAF
)
547 SvLBoxEntry
* pNewEntry
= InsertEntry( aStr
, maImgGraphic
, maImgGraphic
, pEntry
,
548 FALSE
, LIST_APPEND
, pObj
);
550 SetExpandedEntryBmp( pNewEntry
, maImgGraphicH
, BMP_COLOR_HIGHCONTRAST
);
551 SetCollapsedEntryBmp( pNewEntry
, maImgGraphicH
, BMP_COLOR_HIGHCONTRAST
);
553 else if (pObj
->IsGroupObject())
565 SvLBoxEntry
* pNewEntry
= InsertEntry( aStr
, rIconProvider
.maImgObjects
, rIconProvider
.maImgObjects
, pEntry
,
566 FALSE
, LIST_APPEND
, pObj
);
568 SetExpandedEntryBmp( pNewEntry
, rIconProvider
.maImgObjectsH
, BMP_COLOR_HIGHCONTRAST
);
569 SetCollapsedEntryBmp( pNewEntry
, rIconProvider
.maImgObjectsH
, BMP_COLOR_HIGHCONTRAST
);
574 if( pEntry
->HasChilds() )
578 bIsExcluded
? rIconProvider
.maImgPageObjsExcl
: rIconProvider
.maImgPageObjs
);
579 SetCollapsedEntryBmp(
581 bIsExcluded
? rIconProvider
.maImgPageObjsExcl
: rIconProvider
.maImgPageObjs
);
584 bIsExcluded
? rIconProvider
.maImgPageObjsExclH
: rIconProvider
.maImgPageObjsH
,
585 BMP_COLOR_HIGHCONTRAST
);
586 SetCollapsedEntryBmp(
588 bIsExcluded
? rIconProvider
.maImgPageObjsExclH
: rIconProvider
.maImgPageObjsH
,
589 BMP_COLOR_HIGHCONTRAST
);
596 void SdPageObjsTLB::SetShowAllShapes (
597 const bool bShowAllShapes
,
598 const bool bFillList
)
600 mbShowAllShapes
= bShowAllShapes
;
603 if (mpMedium
== NULL
)
604 Fill(mpDoc
, mbShowAllPages
, maDocName
);
606 Fill(mpDoc
, mpMedium
, maDocName
);
613 bool SdPageObjsTLB::GetShowAllShapes (void) const
615 return mbShowAllShapes
;
621 /*************************************************************************
623 |* Prueft, ob die Seiten (PK_STANDARD) und die darauf befindlichen Objekte
624 |* des Docs und der TreeLB identisch sind.
625 |* Wird ein Doc uebergeben, wird dieses zum aktuellem Doc (Wichtig bei
626 |* mehreren Documenten).
628 \************************************************************************/
630 BOOL
SdPageObjsTLB::IsEqualToDoc( const SdDrawDocument
* pInDoc
)
638 SdrObject
* pObj
= NULL
;
639 SdPage
* pPage
= NULL
;
640 SvLBoxEntry
* pEntry
= First();
643 // Alle Pages incl. Objekte vergleichen
645 const USHORT nMaxPages
= mpDoc
->GetPageCount();
647 while( nPage
< nMaxPages
)
649 pPage
= (SdPage
*) mpDoc
->GetPage( nPage
);
650 if( pPage
->GetPageKind() == PK_STANDARD
)
654 aName
= GetEntryText( pEntry
);
656 if( pPage
->GetName() != aName
)
659 pEntry
= Next( pEntry
);
661 SdrObjListIter
aIter(
663 !pPage
->HasObjectNavigationOrder() /* use navigation order, if available */,
666 while( aIter
.IsMore() )
670 const String
aObjectName( GetObjectName( pObj
) );
672 if( aObjectName
.Len() )
677 aName
= GetEntryText( pEntry
);
679 if( aObjectName
!= aName
)
682 pEntry
= Next( pEntry
);
688 // Wenn noch Eintraege in der Listbox vorhanden sind, wurden
689 // Objekte (mit Namen) oder Seiten geloescht
693 /*************************************************************************
695 |* Selectierten String zurueckgeben
697 \************************************************************************/
699 String
SdPageObjsTLB::GetSelectEntry()
701 return( GetEntryText( GetCurEntry() ) );
704 /*************************************************************************
706 |* Selektierte Eintrage zurueckgeben
707 |* nDepth == 0 -> Seiten
708 |* nDepth == 1 -> Objekte
710 \************************************************************************/
712 List
* SdPageObjsTLB::GetSelectEntryList( USHORT nDepth
)
715 SvLBoxEntry
* pEntry
= FirstSelected();
719 USHORT nListDepth
= GetModel()->GetDepth( pEntry
);
720 if( nListDepth
== nDepth
)
725 const String
aEntryText( GetEntryText( pEntry
) );
726 pList
->Insert( new String( aEntryText
), LIST_APPEND
);
728 pEntry
= NextSelected( pEntry
);
734 /*************************************************************************
736 |* Alle Pages (und Objekte) des Docs zurueckgeben
737 |* nType == 0 -> Seiten
738 |* nType == 1 -> Objekte
740 \************************************************************************/
742 List
* SdPageObjsTLB::GetBookmarkList( USHORT nType
)
746 if( GetBookmarkDoc() )
748 SdPage
* pPage
= NULL
;
749 String
* pName
= NULL
;
751 const USHORT nMaxPages
= mpBookmarkDoc
->GetSdPageCount( PK_STANDARD
);
753 while( nPage
< nMaxPages
)
755 pPage
= mpBookmarkDoc
->GetSdPage( nPage
, PK_STANDARD
);
757 if( nType
== 0 ) // Seitennamen einfuegen
762 pName
= new String( pPage
->GetRealName() );
763 pList
->Insert( pName
, LIST_APPEND
);
765 else // Objektnamen einfuegen
767 // Ueber Objekte der Seite iterieren
768 SdrObjListIter
aIter( *pPage
, IM_DEEPWITHGROUPS
);
769 while( aIter
.IsMore() )
771 SdrObject
* pObj
= aIter
.Next();
772 String
aStr( GetObjectName( pObj
) );
778 pName
= new String( aStr
);
779 pList
->Insert( pName
, LIST_APPEND
);
789 /*************************************************************************
791 |* Eintraege werden erst auf Anforderung (Doppelklick) eingefuegt
793 \************************************************************************/
795 void SdPageObjsTLB::RequestingChilds( SvLBoxEntry
* pFileEntry
)
797 if( !pFileEntry
->HasChilds() )
799 if( GetBookmarkDoc() )
801 SdrObject
* pObj
= NULL
;
802 SdPage
* pPage
= NULL
;
803 SvLBoxEntry
* pPageEntry
= NULL
;
805 Image aImgPage
=Image( BitmapEx( SdResId( BMP_PAGE
) ) );
806 Image aImgPageObjs
=Image( BitmapEx( SdResId( BMP_PAGEOBJS
) ) );
807 Image aImgObjects
=Image( BitmapEx( SdResId( BMP_OBJECTS
) ) );
808 Image aImgPageH
=Image( BitmapEx( SdResId( BMP_PAGE_H
) ) );
809 Image aImgPageObjsH
=Image( BitmapEx( SdResId( BMP_PAGEOBJS_H
) ) );
810 Image aImgObjectsH
=Image( BitmapEx( SdResId( BMP_OBJECTS_H
) ) );
812 // document name already inserted
814 // only insert all "normal" ? slides with objects
816 const USHORT nMaxPages
= mpBookmarkDoc
->GetPageCount();
818 while( nPage
< nMaxPages
)
820 pPage
= (SdPage
*) mpBookmarkDoc
->GetPage( nPage
);
821 if( pPage
->GetPageKind() == PK_STANDARD
)
823 pPageEntry
= InsertEntry( pPage
->GetName(),
829 reinterpret_cast< void* >( 1 ) );
831 SetExpandedEntryBmp( pPageEntry
, aImgPageH
, BMP_COLOR_HIGHCONTRAST
);
832 SetCollapsedEntryBmp( pPageEntry
, aImgPageH
, BMP_COLOR_HIGHCONTRAST
);
834 SdrObjListIter
aIter( *pPage
, IM_DEEPWITHGROUPS
);
836 while( aIter
.IsMore() )
839 String
aStr( GetObjectName( pObj
) );
842 if( pObj
->GetObjInventor() == SdrInventor
&& pObj
->GetObjIdentifier() == OBJ_OLE2
)
844 SvLBoxEntry
* pNewEntry
= InsertEntry(aStr
, maImgOle
, maImgOle
, pPageEntry
);
847 SetExpandedEntryBmp( pNewEntry
, maImgOleH
, BMP_COLOR_HIGHCONTRAST
);
848 SetCollapsedEntryBmp( pNewEntry
, maImgOleH
, BMP_COLOR_HIGHCONTRAST
);
850 else if( pObj
->GetObjInventor() == SdrInventor
&& pObj
->GetObjIdentifier() == OBJ_GRAF
)
852 SvLBoxEntry
* pNewEntry
= InsertEntry(aStr
, maImgGraphic
, maImgGraphic
, pPageEntry
);
854 SetExpandedEntryBmp( pNewEntry
, maImgGraphicH
, BMP_COLOR_HIGHCONTRAST
);
855 SetCollapsedEntryBmp( pNewEntry
, maImgGraphicH
, BMP_COLOR_HIGHCONTRAST
);
859 SvLBoxEntry
* pNewEntry
= InsertEntry(aStr
, aImgObjects
, aImgObjects
, pPageEntry
);
861 SetExpandedEntryBmp( pNewEntry
, aImgObjectsH
, BMP_COLOR_HIGHCONTRAST
);
862 SetCollapsedEntryBmp( pNewEntry
, aImgObjectsH
, BMP_COLOR_HIGHCONTRAST
);
866 if( pPageEntry
->HasChilds() )
868 SetExpandedEntryBmp( pPageEntry
, aImgPageObjs
);
869 SetCollapsedEntryBmp( pPageEntry
, aImgPageObjs
);
870 SetExpandedEntryBmp( pPageEntry
, aImgPageObjsH
, BMP_COLOR_HIGHCONTRAST
);
871 SetCollapsedEntryBmp( pPageEntry
, aImgPageObjsH
, BMP_COLOR_HIGHCONTRAST
);
879 SvTreeListBox::RequestingChilds( pFileEntry
);
882 /*************************************************************************
884 |* Prueft, ob es sich um eine Draw-Datei handelt und oeffnet anhand des
885 |* uebergebenen Docs das BookmarkDoc
887 \************************************************************************/
889 SdDrawDocument
* SdPageObjsTLB::GetBookmarkDoc(SfxMedium
* pMed
)
893 (pMed
&& (!mpOwnMedium
|| mpOwnMedium
->GetName() != pMed
->GetName()))
896 // create a new BookmarkDoc if now one exists or if a new Medium is provided
897 if (mpOwnMedium
!= pMed
)
904 // it looks that it is undefined if a Medium was set by Fill() allready
905 DBG_ASSERT( !mpMedium
, "SfxMedium confusion!" );
909 // take over this Medium (currently used only be Navigator)
913 DBG_ASSERT( mpMedium
|| pMed
, "No SfxMedium provided!" );
917 // in this mode the document is also owned and controlled by this instance
918 mxBookmarkDocShRef
= new ::sd::DrawDocShell(SFX_CREATE_MODE_STANDARD
, TRUE
);
919 if (mxBookmarkDocShRef
->DoLoad(pMed
))
920 mpBookmarkDoc
= mxBookmarkDocShRef
->GetDoc();
922 mpBookmarkDoc
= NULL
;
925 // in this mode the document is owned and controlled by the SdDrawDocument
926 // it can be released by calling the corresponding CloseBookmarkDoc method
927 // successfull creation of a document makes this the owner of the medium
928 mpBookmarkDoc
= ((SdDrawDocument
*) mpDoc
)->OpenBookmarkDoc(*mpMedium
);
930 if ( !mpBookmarkDoc
)
932 ErrorBox
aErrorBox( this, WB_OK
, String( SdResId( STR_READ_DATA_ERROR
) ) );
934 mpMedium
= 0; //On failure the SfxMedium is invalid
938 return( mpBookmarkDoc
);
941 /*************************************************************************
943 |* Bookmark-Dokument schlieáen und loeschen
945 \************************************************************************/
947 void SdPageObjsTLB::CloseBookmarkDoc()
949 if (mxBookmarkDocShRef
.Is())
951 mxBookmarkDocShRef
->DoClose();
952 mxBookmarkDocShRef
.Clear();
954 // Medium is owned by document, so it's destroyed already
957 else if ( mpBookmarkDoc
)
959 DBG_ASSERT( !mpOwnMedium
, "SfxMedium confusion!" );
962 // The document owns the Medium, so the Medium will be invalid after closing the document
963 ((SdDrawDocument
*) mpDoc
)->CloseBookmarkDoc();
969 // perhaps mpOwnMedium provided, but no successfull creation of BookmarkDoc
974 mpBookmarkDoc
= NULL
;
977 /*************************************************************************
981 \************************************************************************/
983 void SdPageObjsTLB::SelectHdl()
985 SvLBoxEntry
* pEntry
= FirstSelected();
987 mbLinkableSelected
= TRUE
;
989 while( pEntry
&& mbLinkableSelected
)
991 if( NULL
== pEntry
->GetUserData() )
992 mbLinkableSelected
= FALSE
;
994 pEntry
= NextSelected( pEntry
);
997 SvTreeListBox::SelectHdl();
1000 /*************************************************************************
1002 |* Ueberlaedt RETURN mit der Funktionsweise von DoubleClick
1004 \************************************************************************/
1006 void SdPageObjsTLB::KeyInput( const KeyEvent
& rKEvt
)
1008 if( rKEvt
.GetKeyCode().GetCode() == KEY_RETURN
)
1010 // Auskommentierter Code aus svtools/source/contnr/svimpbox.cxx
1011 SvLBoxEntry
* pCursor
= GetCurEntry();
1012 if( pCursor
->HasChilds() || pCursor
->HasChildsOnDemand() )
1014 if( IsExpanded( pCursor
) )
1015 Collapse( pCursor
);
1023 SvTreeListBox::KeyInput( rKEvt
);
1026 /*************************************************************************
1028 |* StartDrag-Request
1030 \************************************************************************/
1032 void SdPageObjsTLB::StartDrag( sal_Int8 nAction
, const Point
& rPosPixel
)
1037 SdNavigatorWin
* pNavWin
= NULL
;
1038 SvLBoxEntry
* pEntry
= GetEntry(rPosPixel
);
1040 if( mpFrame
->HasChildWindow( SID_NAVIGATOR
) )
1041 pNavWin
= (SdNavigatorWin
*) ( mpFrame
->GetChildWindow( SID_NAVIGATOR
)->GetContextWindow( SD_MOD() ) );
1045 && pNavWin
== mpParent
1046 && pNavWin
->GetNavigatorDragType() != NAVIGATOR_DRAGTYPE_NONE
)
1048 // Mark only the children of the page under the mouse as drop
1049 // targets. This prevents moving shapes from one page to another.
1051 // Select all entries and disable them as drop targets.
1052 SetSelectionMode(MULTIPLE_SELECTION
);
1053 SetCursor(NULL
, FALSE
);
1054 SelectAll(TRUE
, FALSE
);
1055 EnableSelectionAsDropTarget(FALSE
, TRUE
);
1057 // Enable only the entries as drop targets that are children of the
1058 // page under the mouse.
1059 SvLBoxEntry
* pParent
= GetRootLevelParent(pEntry
);
1060 if (pParent
!= NULL
)
1062 SelectAll(FALSE
, FALSE
);
1063 Select(pParent
, TRUE
);
1064 // for (SvLBoxEntry*pChild=FirstChild(pParent); pChild!=NULL; pChild=NextSibling(pChild))
1065 // Select(pChild, TRUE);
1066 EnableSelectionAsDropTarget(TRUE
, TRUE
);//FALSE);
1069 // Set selection back to the entry under the mouse.
1070 SelectAll(FALSE
,FALSE
);
1071 SetSelectionMode(SINGLE_SELECTION
);
1072 Select(pEntry
, TRUE
);
1074 // Aus dem ExecuteDrag heraus kann der Navigator geloescht werden
1075 // (beim Umschalten auf einen anderen Dokument-Typ), das wuerde aber
1076 // den StarView MouseMove-Handler, der Command() aufruft, umbringen.
1077 // Deshalb Drag&Drop asynchron:
1078 Application::PostUserEvent( STATIC_LINK( this, SdPageObjsTLB
, ExecDragHdl
) );
1082 /*************************************************************************
1086 \************************************************************************/
1088 void SdPageObjsTLB::DoDrag()
1090 mpDropNavWin
= ( mpFrame
->HasChildWindow( SID_NAVIGATOR
) ) ?
1091 (SdNavigatorWin
*)( mpFrame
->GetChildWindow( SID_NAVIGATOR
)->GetContextWindow( SD_MOD() ) ) :
1096 ::sd::DrawDocShell
* pDocShell
= mpDoc
->GetDocSh();
1097 String aURL
= INetURLObject( pDocShell
->GetMedium()->GetPhysicalName(), INET_PROT_FILE
).GetMainURL( INetURLObject::NO_DECODE
);
1098 NavigatorDragType eDragType
= mpDropNavWin
->GetNavigatorDragType();
1101 aURL
.Append( GetSelectEntry() );
1103 INetBookmark
aBookmark( aURL
, GetSelectEntry() );
1104 sal_Int8 nDNDActions
= DND_ACTION_COPYMOVE
;
1106 if( eDragType
== NAVIGATOR_DRAGTYPE_LINK
)
1107 nDNDActions
= DND_ACTION_LINK
; // #93240# Either COPY *or* LINK, never both!
1109 SvTreeListBox::ReleaseMouse();
1113 SvLBoxDDInfo aDDInfo
;
1114 memset(&aDDInfo
,0,sizeof(SvLBoxDDInfo
));
1115 aDDInfo
.pApp
= GetpApp();
1116 aDDInfo
.pSource
= this;
1117 // aDDInfo.pDDStartEntry = pEntry;
1118 ::com::sun::star::uno::Sequence
<sal_Int8
> aSequence (sizeof(SvLBoxDDInfo
));
1119 memcpy(aSequence
.getArray(), (sal_Char
*)&aDDInfo
, sizeof(SvLBoxDDInfo
));
1120 ::com::sun::star::uno::Any
aTreeListBoxData (aSequence
);
1122 // object is destroyed by internal reference mechanism
1123 SdTransferable
* pTransferable
= new SdPageObjsTLB::SdPageObjsTransferable(
1124 *this, aBookmark
, *pDocShell
, eDragType
, aTreeListBoxData
);
1125 OSL_TRACE("created new SdPageObjsTransferable at %x", pTransferable
);
1128 sd::View
* pView
= NULL
;
1129 if (pDocShell
!= NULL
)
1131 ::sd::ViewShell
* pViewShell
= pDocShell
->GetViewShell();
1132 if (pViewShell
!= NULL
)
1133 pView
= pViewShell
->GetView();
1137 OSL_ASSERT(pView
!=NULL
);
1141 SdrObject
* pObject
= NULL
;
1142 void* pUserData
= GetCurEntry()->GetUserData();
1143 if (pUserData
!= NULL
&& pUserData
!= (void*)1)
1144 pObject
= reinterpret_cast<SdrObject
*>(pUserData
);
1145 if (pObject
== NULL
)
1148 // For shapes without a user supplied name (the automatically
1149 // created name does not count), a different drag and drop technique
1151 if (GetObjectName(pObject
, false).Len() == 0)
1153 AddShapeToTransferable(*pTransferable
, *pObject
);
1154 pTransferable
->SetView(pView
);
1155 SD_MOD()->pTransferDrag
= pTransferable
;
1158 // Unnamed shapes have to be selected to be recognized by the
1159 // current drop implementation. In order to have a consistent
1160 // behaviour for all shapes, every shape that is to be dragged is
1162 SdrPageView
* pPageView
= pView
->GetSdrPageView();
1163 pView
->UnmarkAllObj(pPageView
);
1164 pView
->MarkObj(pObject
, pPageView
);
1166 pTransferable
->StartDrag( this, nDNDActions
);
1170 /*************************************************************************
1174 \************************************************************************/
1176 void SdPageObjsTLB::OnDragFinished( sal_uInt8
)
1178 if( mpFrame
->HasChildWindow( SID_NAVIGATOR
) )
1180 SdNavigatorWin
* pNewNavWin
= (SdNavigatorWin
*) ( mpFrame
->GetChildWindow( SID_NAVIGATOR
)->GetContextWindow( SD_MOD() ) );
1182 if( mpDropNavWin
== pNewNavWin
)
1184 MouseEvent
aMEvt( mpDropNavWin
->GetPointerPosPixel() );
1185 SvTreeListBox::MouseButtonUp( aMEvt
);
1189 mpDropNavWin
= NULL
;
1193 /*************************************************************************
1197 \************************************************************************/
1199 sal_Int8
SdPageObjsTLB::AcceptDrop (const AcceptDropEvent
& rEvent
)
1201 sal_Int8
nResult (DND_ACTION_NONE
);
1203 if ( !bIsInDrag
&& IsDropFormatSupported( FORMAT_FILE
) )
1205 nResult
= rEvent
.mnAction
;
1209 SvLBoxEntry
* pEntry
= GetDropTarget(rEvent
.maPosPixel
);
1210 if (rEvent
.mbLeaving
|| !CheckDragAndDropMode( this, rEvent
.mnAction
))
1212 ImplShowTargetEmphasis( pTargetEntry
, FALSE
);
1214 else if( !nDragDropMode
)
1216 DBG_ERRORFILE( "SdPageObjsTLB::AcceptDrop(): no target" );
1218 else if (IsDropAllowed(pEntry
))
1220 nResult
= DND_ACTION_MOVE
;
1223 if (pEntry
!= pTargetEntry
|| !(nImpFlags
& SVLBOX_TARGEMPH_VIS
))
1225 ImplShowTargetEmphasis( pTargetEntry
, FALSE
);
1226 pTargetEntry
= pEntry
;
1227 ImplShowTargetEmphasis( pTargetEntry
, TRUE
);
1232 // Hide emphasis when there is no valid drop action.
1233 if (nResult
== DND_ACTION_NONE
)
1234 ImplShowTargetEmphasis(pTargetEntry
, FALSE
);
1239 /*************************************************************************
1241 |* ExecuteDrop-Event
1243 \************************************************************************/
1245 sal_Int8
SdPageObjsTLB::ExecuteDrop( const ExecuteDropEvent
& rEvt
)
1247 sal_Int8 nRet
= DND_ACTION_NONE
;
1253 SdNavigatorWin
* pNavWin
= NULL
;
1254 USHORT nId
= SID_NAVIGATOR
;
1256 if( mpFrame
->HasChildWindow( nId
) )
1257 pNavWin
= (SdNavigatorWin
*)( mpFrame
->GetChildWindow( nId
)->GetContextWindow( SD_MOD() ) );
1259 if( pNavWin
&& ( pNavWin
== mpParent
) )
1261 TransferableDataHelper
aDataHelper( rEvt
.maDropEvent
.Transferable
);
1264 if( aDataHelper
.GetString( FORMAT_FILE
, aFile
) &&
1265 ( (SdNavigatorWin
*) mpParent
)->InsertFile( aFile
) )
1267 nRet
= rEvt
.mnAction
;
1272 catch (com::sun::star::uno::Exception
&)
1277 if (nRet
== DND_ACTION_NONE
)
1278 SvTreeListBox::ExecuteDrop(rEvt
, this);
1284 /*************************************************************************
1286 |* Handler fuers Dragging
1288 \************************************************************************/
1290 IMPL_STATIC_LINK(SdPageObjsTLB
, ExecDragHdl
, void*, EMPTYARG
)
1292 // als Link, damit asynchron ohne ImpMouseMoveMsg auf dem Stack auch der
1293 // Navigator geloescht werden darf
1299 bool SdPageObjsTLB::PageBelongsToCurrentShow (const SdPage
* pPage
) const
1301 // Return <TRUE/> as default when there is no custom show or when none
1302 // is used. The page does then belong to the standard show.
1303 bool bBelongsToShow
= true;
1305 if (mpDoc
->getPresentationSettings().mbCustomShow
)
1307 // Get the current custom show.
1308 SdCustomShow
* pCustomShow
= NULL
;
1309 List
* pShowList
= const_cast<SdDrawDocument
*>(mpDoc
)->GetCustomShowList();
1310 if (pShowList
!= NULL
)
1312 ULONG nCurrentShowIndex
= pShowList
->GetCurPos();
1313 void* pObject
= pShowList
->GetObject(nCurrentShowIndex
);
1314 pCustomShow
= static_cast<SdCustomShow
*>(pObject
);
1317 // Check whether the given page is part of that custom show.
1318 if (pCustomShow
!= NULL
)
1320 bBelongsToShow
= false;
1321 ULONG nPageCount
= pCustomShow
->Count();
1322 for (USHORT i
=0; i
<nPageCount
&& !bBelongsToShow
; i
++)
1323 if (pPage
== static_cast<SdPage
*>(pCustomShow
->GetObject (i
)))
1324 bBelongsToShow
= true;
1328 return bBelongsToShow
;
1334 BOOL
SdPageObjsTLB::NotifyMoving(
1335 SvLBoxEntry
* pTarget
,
1336 SvLBoxEntry
* pEntry
,
1337 SvLBoxEntry
*& rpNewParent
,
1338 ULONG
& rNewChildPos
)
1340 SvLBoxEntry
* pDestination
= pTarget
;
1341 while (GetParent(pDestination
) != NULL
&& GetParent(GetParent(pDestination
)) != NULL
)
1342 pDestination
= GetParent(pDestination
);
1344 SdrObject
* pTargetObject
= reinterpret_cast<SdrObject
*>(pDestination
->GetUserData());
1345 SdrObject
* pSourceObject
= reinterpret_cast<SdrObject
*>(pEntry
->GetUserData());
1346 if (pSourceObject
== reinterpret_cast<SdrObject
*>(1))
1347 pSourceObject
= NULL
;
1349 if (pTargetObject
!= NULL
&& pSourceObject
!= NULL
)
1351 SdrPage
* pObjectList
= pSourceObject
->GetPage();
1352 if (pObjectList
!= NULL
)
1354 sal_uInt32 nNewPosition
;
1355 if (pTargetObject
== reinterpret_cast<SdrObject
*>(1))
1358 nNewPosition
= pTargetObject
->GetNavigationPosition() + 1;
1359 pObjectList
->SetObjectNavigationPosition(*pSourceObject
, nNewPosition
);
1362 // Update the tree list.
1363 if (pTarget
== NULL
)
1369 else if (GetParent(pDestination
) == NULL
)
1371 rpNewParent
= pDestination
;
1376 rpNewParent
= GetParent(pDestination
);
1377 rNewChildPos
= pModel
->GetRelPos(pDestination
) + 1;
1378 rNewChildPos
+= nCurEntrySelPos
;
1390 SvLBoxEntry
* SdPageObjsTLB::GetDropTarget (const Point
& rLocation
)
1392 SvLBoxEntry
* pEntry
= SvTreeListBox::GetDropTarget(rLocation
);
1396 OSL_TRACE("entry is %s",
1397 ::rtl::OUStringToOString(GetEntryText(pEntry
), RTL_TEXTENCODING_UTF8
).getStr());
1398 if (GetParent(pEntry
) == NULL
)
1400 // Use page entry as insertion position.
1404 // Go to second hierarchy level, i.e. top level shapes,
1405 // i.e. children of pages.
1406 while (GetParent(pEntry
) != NULL
&& GetParent(GetParent(pEntry
)) != NULL
)
1407 pEntry
= GetParent(pEntry
);
1409 // Advance to next sibling.
1411 sal_uInt16
nDepth (0);
1412 while (pEntry
!= NULL
)
1414 pNext
= dynamic_cast<SvLBoxEntry
*>(NextVisible(pEntry
, &nDepth
));
1415 if (pNext
!= NULL
&& nDepth
> 0 && nDepth
!=0xffff)
1420 OSL_TRACE("returning %s",
1421 ::rtl::OUStringToOString(GetEntryText(pEntry
), RTL_TEXTENCODING_UTF8
).getStr());
1430 bool SdPageObjsTLB::IsDropAllowed (SvLBoxEntry
* pEntry
)
1435 if ( ! IsDropFormatSupported(SdPageObjsTransferable::GetListBoxDropFormatId()))
1438 if ((pEntry
->GetFlags() & SV_ENTRYFLAG_DISABLE_DROP
) != 0)
1447 void SdPageObjsTLB::AddShapeToTransferable (
1448 SdTransferable
& rTransferable
,
1449 SdrObject
& rObject
) const
1451 TransferableObjectDescriptor aObjectDescriptor
;
1452 bool bIsDescriptorFillingPending (true);
1454 const SdrOle2Obj
* pOleObject
= dynamic_cast<const SdrOle2Obj
*>(&rObject
);
1455 if (pOleObject
!= NULL
&& pOleObject
->GetObjRef().is())
1457 // If object has no persistence it must be copied as part of the document
1460 uno::Reference
< embed::XEmbedPersist
> xPersObj (pOleObject
->GetObjRef(), uno::UNO_QUERY
);
1461 if (xPersObj
.is() && xPersObj
->hasEntry())
1463 SvEmbedTransferHelper::FillTransferableObjectDescriptor(
1465 pOleObject
->GetObjRef(),
1466 pOleObject
->GetGraphic(),
1467 pOleObject
->GetAspect());
1468 bIsDescriptorFillingPending
= false;
1471 catch( uno::Exception
& )
1476 ::sd::DrawDocShell
* pDocShell
= mpDoc
->GetDocSh();
1477 if (bIsDescriptorFillingPending
&& pDocShell
!=NULL
)
1479 bIsDescriptorFillingPending
= false;
1480 pDocShell
->FillTransferableObjectDescriptor(aObjectDescriptor
);
1483 Point
aDragPos (rObject
.GetCurrentBoundRect().Center());
1484 //Point aDragPos (0,0);
1485 aObjectDescriptor
.maDragStartPos
= aDragPos
;
1486 // aObjectDescriptor.maSize = GetAllMarkedRect().GetSize();
1487 if (pDocShell
!= NULL
)
1488 aObjectDescriptor
.maDisplayName
= pDocShell
->GetMedium()->GetURLObject().GetURLNoPass();
1490 aObjectDescriptor
.maDisplayName
= String();
1491 aObjectDescriptor
.mbCanLink
= FALSE
;
1493 rTransferable
.SetStartPos(aDragPos
);
1494 rTransferable
.SetObjectDescriptor( aObjectDescriptor
);
1500 //===== IconProvider ==========================================================
1502 SdPageObjsTLB::IconProvider::IconProvider (void)
1503 : maImgPage( BitmapEx( SdResId( BMP_PAGE
) ) ),
1504 maImgPageExcl( BitmapEx( SdResId( BMP_PAGE_EXCLUDED
) ) ),
1505 maImgPageObjsExcl( BitmapEx( SdResId( BMP_PAGEOBJS_EXCLUDED
) ) ),
1506 maImgPageObjs( BitmapEx( SdResId( BMP_PAGEOBJS
) ) ),
1507 maImgObjects( BitmapEx( SdResId( BMP_OBJECTS
) ) ),
1508 maImgGroup( BitmapEx( SdResId( BMP_GROUP
) ) ),
1510 maImgPageH( BitmapEx( SdResId( BMP_PAGE_H
) ) ),
1511 maImgPageExclH( BitmapEx( SdResId( BMP_PAGE_EXCLUDED_H
) ) ),
1512 maImgPageObjsExclH( BitmapEx( SdResId( BMP_PAGEOBJS_EXCLUDED_H
) ) ),
1513 maImgPageObjsH( BitmapEx( SdResId( BMP_PAGEOBJS_H
) ) ),
1514 maImgObjectsH( BitmapEx( SdResId( BMP_OBJECTS_H
) ) ),
1515 maImgGroupH( BitmapEx( SdResId( BMP_GROUP_H
) ) )