1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <sal/types.h>
22 #include <sot/formats.hxx>
23 #include <sot/storage.hxx>
24 #include <vcl/msgbox.hxx>
25 #include <svl/urihelper.hxx>
26 #include <svx/svditer.hxx>
27 #include <sfx2/docfile.hxx>
28 #include <svx/svdoole2.hxx>
29 #include <vcl/svapp.hxx>
30 #include "cusshow.hxx"
31 #include <sfx2/childwin.hxx>
33 #include <sfx2/viewfrm.hxx>
36 #include "sdtreelb.hxx"
37 #include "DrawDocShell.hxx"
38 #include "drawdoc.hxx"
40 #include "sdresid.hxx"
41 #include "navigatr.hxx"
42 #include "strings.hrc"
43 #include "res_bmp.hrc"
44 #include "customshowlist.hxx"
45 #include "ViewShell.hxx"
46 #include "DrawController.hxx"
47 #include "ViewShellBase.hxx"
49 #include <com/sun/star/embed/XEmbedPersist.hpp>
50 #include <com/sun/star/frame/Desktop.hpp>
51 #include <com/sun/star/frame/XFramesSupplier.hpp>
52 #include <svtools/embedtransfer.hxx>
53 #include "svtools/treelistentry.hxx"
54 #include <comphelper/servicehelper.hxx>
55 #include <comphelper/processfactory.hxx>
56 #include <tools/diagnose_ex.h>
58 using namespace com::sun::star
;
60 class SdPageObjsTLB::IconProvider
68 Image maImgPageObjsExcl
;
75 sal_Bool SAL_DLLPRIVATE
SdPageObjsTLB::bIsInDrag
= sal_False
;
77 sal_Bool
SdPageObjsTLB::IsInDrag()
82 sal_uInt32
SdPageObjsTLB::SdPageObjsTransferable::mnListBoxDropFormatId
= SAL_MAX_UINT32
;
84 // -----------------------------------------
85 // - SdPageObjsTLB::SdPageObjsTransferable -
86 // -----------------------------------------
88 SdPageObjsTLB::SdPageObjsTransferable::SdPageObjsTransferable(
89 SdPageObjsTLB
& rParent
,
90 const INetBookmark
& rBookmark
,
91 ::sd::DrawDocShell
& rDocShell
,
92 NavigatorDragType eDragType
,
93 const ::com::sun::star::uno::Any
& rTreeListBoxData
)
94 : SdTransferable(rDocShell
.GetDoc(), NULL
, sal_True
),
96 maBookmark( rBookmark
),
97 mrDocShell( rDocShell
),
98 meDragType( eDragType
),
99 maTreeListBoxData( rTreeListBoxData
)
106 SdPageObjsTLB::SdPageObjsTransferable::~SdPageObjsTransferable()
110 // -----------------------------------------------------------------------------
112 void SdPageObjsTLB::SdPageObjsTransferable::AddSupportedFormats()
114 AddFormat(SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK
);
115 AddFormat(SOT_FORMATSTR_ID_TREELISTBOX
);
116 AddFormat(GetListBoxDropFormatId());
119 // -----------------------------------------------------------------------------
121 sal_Bool
SdPageObjsTLB::SdPageObjsTransferable::GetData( const ::com::sun::star::datatransfer::DataFlavor
& rFlavor
)
123 sal_uLong nFormatId
= SotExchange::GetFormat( rFlavor
);
126 case SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK
:
127 SetINetBookmark( maBookmark
, rFlavor
);
130 case SOT_FORMATSTR_ID_TREELISTBOX
:
131 SetAny(maTreeListBoxData
, rFlavor
);
139 // -----------------------------------------------------------------------------
141 void SdPageObjsTLB::SdPageObjsTransferable::DragFinished( sal_Int8 nDropAction
)
143 mrParent
.OnDragFinished( nDropAction
);
144 SdTransferable::DragFinished(nDropAction
);
147 // -----------------------------------------------------------------------------
149 ::sd::DrawDocShell
& SdPageObjsTLB::SdPageObjsTransferable::GetDocShell() const
154 // -----------------------------------------------------------------------------
156 NavigatorDragType
SdPageObjsTLB::SdPageObjsTransferable::GetDragType() const
161 // -----------------------------------------------------------------------------
163 sal_Int64 SAL_CALL
SdPageObjsTLB::SdPageObjsTransferable::getSomething( const ::com::sun::star::uno::Sequence
< sal_Int8
>& rId
) throw( ::com::sun::star::uno::RuntimeException
)
167 if( ( rId
.getLength() == 16 ) &&
168 ( 0 == memcmp( getUnoTunnelId().getConstArray(), rId
.getConstArray(), 16 ) ) )
170 nRet
= (sal_Int64
)(sal_IntPtr
)this;
173 nRet
= SdTransferable::getSomething(rId
);
180 class theSdPageObjsTLBUnoTunnelId
: public rtl::Static
< UnoTunnelIdInit
, theSdPageObjsTLBUnoTunnelId
> {};
183 const ::com::sun::star::uno::Sequence
< sal_Int8
>& SdPageObjsTLB::SdPageObjsTransferable::getUnoTunnelId()
185 return theSdPageObjsTLBUnoTunnelId::get().getSeq();
188 // -----------------------------------------------------------------------------
190 SdPageObjsTLB::SdPageObjsTransferable
* SdPageObjsTLB::SdPageObjsTransferable::getImplementation( const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& rxData
)
195 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XUnoTunnel
> xUnoTunnel( rxData
, ::com::sun::star::uno::UNO_QUERY_THROW
);
197 return reinterpret_cast<SdPageObjsTLB::SdPageObjsTransferable
*>(
198 sal::static_int_cast
<sal_uIntPtr
>(
199 xUnoTunnel
->getSomething( SdPageObjsTLB::SdPageObjsTransferable::getUnoTunnelId()) ) );
201 catch( const ::com::sun::star::uno::Exception
& )
208 sal_uInt32
SdPageObjsTLB::SdPageObjsTransferable::GetListBoxDropFormatId (void)
210 if (mnListBoxDropFormatId
== SAL_MAX_UINT32
)
211 mnListBoxDropFormatId
= SotExchange::RegisterFormatMimeType(OUString(
212 "application/x-openoffice-treelistbox-moveonly;windows_formatname=\"SV_LBOX_DD_FORMAT_MOVE\""));
213 return mnListBoxDropFormatId
;
217 SdPageObjsTLB::SdPageObjsTLB( Window
* pParentWin
, const SdResId
& rSdResId
)
218 : SvTreeListBox ( pParentWin
, rSdResId
)
219 , mpParent ( pParentWin
)
221 , mpBookmarkDoc ( NULL
)
223 , mpOwnMedium ( NULL
)
224 , maImgOle ( BitmapEx( SdResId( BMP_OLE
) ) )
225 , maImgGraphic ( BitmapEx( SdResId( BMP_GRAPHIC
) ) )
226 , mbLinkableSelected ( sal_False
)
227 , mpDropNavWin ( NULL
)
228 , mbShowAllShapes ( false )
229 , mbShowAllPages ( false )
232 // add lines to Tree-ListBox
233 SetStyle( GetStyle() | WB_TABSTOP
| WB_BORDER
| WB_HASLINES
|
234 WB_HASBUTTONS
| // WB_HASLINESATROOT |
236 WB_HASBUTTONSATROOT
|
237 WB_QUICK_SEARCH
/* i31275 */ );
238 SetNodeBitmaps( Bitmap( SdResId( BMP_EXPAND
) ),
239 Bitmap( SdResId( BMP_COLLAPSE
) ) );
242 SV_DRAGDROP_CTRL_MOVE
| SV_DRAGDROP_CTRL_COPY
|
243 SV_DRAGDROP_APP_MOVE
| SV_DRAGDROP_APP_COPY
| SV_DRAGDROP_APP_DROP
);
247 SdPageObjsTLB::~SdPageObjsTLB()
252 // no document was created from mpMedium, so this object is still the owner of it
256 String
SdPageObjsTLB::GetObjectName(
257 const SdrObject
* pObject
,
258 const bool bCreate
) const
264 aRet
= pObject
->GetName();
266 if( !aRet
.Len() && pObject
->ISA( SdrOle2Obj
) )
267 aRet
= static_cast< const SdrOle2Obj
* >( pObject
)->GetPersistName();
275 aRet
= SD_RESSTR(STR_NAVIGATOR_SHAPE_BASE_NAME
);
276 aRet
.SearchAndReplaceAscii("%1", OUString::number(pObject
->GetOrdNum() + 1));
283 * select a entry in TreeLB
285 sal_Bool
SdPageObjsTLB::SelectEntry( const String
& rName
)
287 sal_Bool bFound
= sal_False
;
291 SvTreeListEntry
* pEntry
= NULL
;
294 for( pEntry
= First(); pEntry
&& !bFound
; pEntry
= Next( pEntry
) )
296 aTmp
= GetEntryText( pEntry
);
300 SetCurEntry( pEntry
);
308 * @return true if children of the specified string are selected
310 sal_Bool
SdPageObjsTLB::HasSelectedChildren( const String
& rName
)
312 sal_Bool bFound
= sal_False
;
313 sal_Bool bChildren
= sal_False
;
317 SvTreeListEntry
* pEntry
= NULL
;
320 for( pEntry
= First(); pEntry
&& !bFound
; pEntry
= Next( pEntry
) )
322 aTmp
= GetEntryText( pEntry
);
326 sal_Bool bExpanded
= IsExpanded( pEntry
);
327 long nCount
= GetChildSelectionCount( pEntry
);
328 if( bExpanded
&& nCount
> 0 )
329 bChildren
= sal_True
;
338 * Fill TreeLB with pages and objects
340 void SdPageObjsTLB::Fill( const SdDrawDocument
* pInDoc
, sal_Bool bAllPages
,
341 const String
& rDocName
)
344 if( GetSelectionCount() > 0 )
346 aSelection
= GetSelectEntry();
351 maDocName
= rDocName
;
352 mbShowAllPages
= (bAllPages
== sal_True
);
355 SdPage
* pPage
= NULL
;
357 IconProvider aIconProvider
;
359 // first insert all pages including objects
360 sal_uInt16 nPage
= 0;
361 const sal_uInt16 nMaxPages
= mpDoc
->GetPageCount();
363 while( nPage
< nMaxPages
)
365 pPage
= (SdPage
*) mpDoc
->GetPage( nPage
);
366 if( (mbShowAllPages
|| pPage
->GetPageKind() == PK_STANDARD
)
367 && !(pPage
->GetPageKind()==PK_HANDOUT
) ) //#94954# never list the normal handout page ( handout-masterpage is used instead )
369 sal_Bool bPageExluded
= pPage
->IsExcluded();
371 bool bPageBelongsToShow
= PageBelongsToCurrentShow (pPage
);
372 bPageExluded
|= !bPageBelongsToShow
;
374 AddShapeList(*pPage
, NULL
, pPage
->GetName(), bPageExluded
, NULL
, aIconProvider
);
379 // then insert all master pages including objects
383 const sal_uInt16 nMaxMasterPages
= mpDoc
->GetMasterPageCount();
385 while( nPage
< nMaxMasterPages
)
387 pPage
= (SdPage
*) mpDoc
->GetMasterPage( nPage
);
388 AddShapeList(*pPage
, NULL
, pPage
->GetName(), false, NULL
, aIconProvider
);
392 if( aSelection
.Len() )
393 SelectEntry( aSelection
);
397 * We insert only the first entry. Children are created on demand.
399 void SdPageObjsTLB::Fill( const SdDrawDocument
* pInDoc
, SfxMedium
* pInMedium
,
400 const String
& rDocName
)
404 // this object now owns the Medium
405 mpMedium
= pInMedium
;
406 maDocName
= rDocName
;
408 Image aImgDocOpen
=Image( BitmapEx( SdResId( BMP_DOC_OPEN
) ) );
409 Image aImgDocClosed
=Image( BitmapEx( SdResId( BMP_DOC_CLOSED
) ) );
411 // insert document name
412 InsertEntry( maDocName
, aImgDocOpen
, aImgDocClosed
, NULL
, sal_True
, LIST_APPEND
,
413 reinterpret_cast< void* >( 1 )
420 void SdPageObjsTLB::AddShapeList (
421 const SdrObjList
& rList
,
423 const OUString
& rsName
,
424 const bool bIsExcluded
,
425 SvTreeListEntry
* pParentEntry
,
426 const IconProvider
& rIconProvider
)
428 Image
aIcon (rIconProvider
.maImgPage
);
430 aIcon
= rIconProvider
.maImgPageExcl
;
431 else if (pShape
!= NULL
)
432 aIcon
= rIconProvider
.maImgGroup
;
434 void* pUserData (reinterpret_cast<void*>(1));
438 SvTreeListEntry
* pEntry
= InsertEntry(
447 SdrObjListIter
aIter(
449 !rList
.HasObjectNavigationOrder() /* use navigation order, if available */,
451 sal_False
/*not reverse*/);
453 while( aIter
.IsMore() )
455 SdrObject
* pObj
= aIter
.Next();
456 OSL_ASSERT(pObj
!=NULL
);
458 // Get the shape name.
459 String
aStr (GetObjectName( pObj
) );
463 if( pObj
->GetObjInventor() == SdrInventor
&& pObj
->GetObjIdentifier() == OBJ_OLE2
)
475 else if( pObj
->GetObjInventor() == SdrInventor
&& pObj
->GetObjIdentifier() == OBJ_GRAF
)
487 else if (pObj
->IsGroupObject())
502 rIconProvider
.maImgObjects
,
503 rIconProvider
.maImgObjects
,
513 if( pEntry
->HasChildren() )
517 bIsExcluded
? rIconProvider
.maImgPageObjsExcl
: rIconProvider
.maImgPageObjs
);
518 SetCollapsedEntryBmp(
520 bIsExcluded
? rIconProvider
.maImgPageObjsExcl
: rIconProvider
.maImgPageObjs
);
527 void SdPageObjsTLB::SetShowAllShapes (
528 const bool bShowAllShapes
,
529 const bool bFillList
)
531 mbShowAllShapes
= bShowAllShapes
;
534 if (mpMedium
== NULL
)
535 Fill(mpDoc
, mbShowAllPages
, maDocName
);
537 Fill(mpDoc
, mpMedium
, maDocName
);
544 bool SdPageObjsTLB::GetShowAllShapes (void) const
546 return mbShowAllShapes
;
553 * Checks if the pages (PK_STANDARD) of a doc and the objects on the pages
554 * are identical to the TreeLB.
555 * If a doc is provided, this will be the used doc (important by more than
558 sal_Bool
SdPageObjsTLB::IsEqualToDoc( const SdDrawDocument
* pInDoc
)
566 SdrObject
* pObj
= NULL
;
567 SdPage
* pPage
= NULL
;
568 SvTreeListEntry
* pEntry
= First();
571 // compare all pages including the objects
572 sal_uInt16 nPage
= 0;
573 const sal_uInt16 nMaxPages
= mpDoc
->GetPageCount();
575 while( nPage
< nMaxPages
)
577 pPage
= (SdPage
*) mpDoc
->GetPage( nPage
);
578 if( pPage
->GetPageKind() == PK_STANDARD
)
582 aName
= GetEntryText( pEntry
);
584 if( pPage
->GetName() != aName
)
587 pEntry
= Next( pEntry
);
589 SdrObjListIter
aIter(
591 !pPage
->HasObjectNavigationOrder() /* use navigation order, if available */,
594 while( aIter
.IsMore() )
598 const String
aObjectName( GetObjectName( pObj
) );
600 if( aObjectName
.Len() )
605 aName
= GetEntryText( pEntry
);
607 if( aObjectName
!= aName
)
610 pEntry
= Next( pEntry
);
616 // If there are still entries in the listbox,
617 // then objects (with names) or pages were deleted
622 * @return selected string
624 String
SdPageObjsTLB::GetSelectEntry()
626 return( GetEntryText( GetCurEntry() ) );
629 std::vector
<OUString
> SdPageObjsTLB::GetSelectEntryList( const sal_uInt16 nDepth
) const
631 std::vector
<OUString
> aEntries
;
632 SvTreeListEntry
* pEntry
= FirstSelected();
636 sal_uInt16 nListDepth
= GetModel()->GetDepth( pEntry
);
638 if( nListDepth
== nDepth
)
639 aEntries
.push_back(GetEntryText(pEntry
));
641 pEntry
= NextSelected( pEntry
);
648 * Entries are inserted only by request (double click)
650 void SdPageObjsTLB::RequestingChildren( SvTreeListEntry
* pFileEntry
)
652 if( !pFileEntry
->HasChildren() )
654 if( GetBookmarkDoc() )
656 SdrObject
* pObj
= NULL
;
657 SdPage
* pPage
= NULL
;
658 SvTreeListEntry
* pPageEntry
= NULL
;
660 Image aImgPage
= Image( BitmapEx( SdResId( BMP_PAGE
) ) );
661 Image aImgPageObjs
= Image( BitmapEx( SdResId( BMP_PAGEOBJS
) ) );
662 Image aImgObjects
= Image( BitmapEx( SdResId( BMP_OBJECTS
) ) );
664 // document name already inserted
666 // only insert all "normal" ? slides with objects
667 sal_uInt16 nPage
= 0;
668 const sal_uInt16 nMaxPages
= mpBookmarkDoc
->GetPageCount();
670 while( nPage
< nMaxPages
)
672 pPage
= (SdPage
*) mpBookmarkDoc
->GetPage( nPage
);
673 if( pPage
->GetPageKind() == PK_STANDARD
)
675 pPageEntry
= InsertEntry( pPage
->GetName(),
681 reinterpret_cast< void* >( 1 ) );
683 SdrObjListIter
aIter( *pPage
, IM_DEEPWITHGROUPS
);
685 while( aIter
.IsMore() )
688 String
aStr( GetObjectName( pObj
) );
691 if( pObj
->GetObjInventor() == SdrInventor
&& pObj
->GetObjIdentifier() == OBJ_OLE2
)
693 InsertEntry(aStr
, maImgOle
, maImgOle
, pPageEntry
);
695 else if( pObj
->GetObjInventor() == SdrInventor
&& pObj
->GetObjIdentifier() == OBJ_GRAF
)
697 InsertEntry(aStr
, maImgGraphic
, maImgGraphic
, pPageEntry
);
701 InsertEntry(aStr
, aImgObjects
, aImgObjects
, pPageEntry
);
705 if( pPageEntry
->HasChildren() )
707 SetExpandedEntryBmp( pPageEntry
, aImgPageObjs
);
708 SetCollapsedEntryBmp( pPageEntry
, aImgPageObjs
);
716 SvTreeListBox::RequestingChildren( pFileEntry
);
720 * Checks if it is a draw file and opens the BookmarkDoc depending of
723 SdDrawDocument
* SdPageObjsTLB::GetBookmarkDoc(SfxMedium
* pMed
)
727 (pMed
&& (!mpOwnMedium
|| mpOwnMedium
->GetName() != pMed
->GetName()))
730 // create a new BookmarkDoc if now one exists or if a new Medium is provided
731 if (mpOwnMedium
!= pMed
)
738 // it looks that it is undefined if a Medium was set by Fill() already
739 DBG_ASSERT( !mpMedium
, "SfxMedium confusion!" );
743 // take over this Medium (currently used only be Navigator)
747 DBG_ASSERT( mpMedium
|| pMed
, "No SfxMedium provided!" );
751 // in this mode the document is also owned and controlled by this instance
752 mxBookmarkDocShRef
= new ::sd::DrawDocShell(SFX_CREATE_MODE_STANDARD
, sal_True
);
753 if (mxBookmarkDocShRef
->DoLoad(pMed
))
754 mpBookmarkDoc
= mxBookmarkDocShRef
->GetDoc();
756 mpBookmarkDoc
= NULL
;
759 // in this mode the document is owned and controlled by the SdDrawDocument
760 // it can be released by calling the corresponding CloseBookmarkDoc method
761 // successful creation of a document makes this the owner of the medium
762 mpBookmarkDoc
= ((SdDrawDocument
*) mpDoc
)->OpenBookmarkDoc(*mpMedium
);
764 if ( !mpBookmarkDoc
)
766 ErrorBox
aErrorBox( this, WB_OK
, String( SdResId( STR_READ_DATA_ERROR
) ) );
768 mpMedium
= 0; //On failure the SfxMedium is invalid
772 return( mpBookmarkDoc
);
776 * Close and delete bookmark document
778 void SdPageObjsTLB::CloseBookmarkDoc()
780 if (mxBookmarkDocShRef
.Is())
782 mxBookmarkDocShRef
->DoClose();
783 mxBookmarkDocShRef
.Clear();
785 // Medium is owned by document, so it's destroyed already
788 else if ( mpBookmarkDoc
)
790 DBG_ASSERT( !mpOwnMedium
, "SfxMedium confusion!" );
793 // The document owns the Medium, so the Medium will be invalid after closing the document
794 ((SdDrawDocument
*) mpDoc
)->CloseBookmarkDoc();
800 // perhaps mpOwnMedium provided, but no successful creation of BookmarkDoc
805 mpBookmarkDoc
= NULL
;
808 void SdPageObjsTLB::SelectHdl()
810 SvTreeListEntry
* pEntry
= FirstSelected();
812 mbLinkableSelected
= sal_True
;
814 while( pEntry
&& mbLinkableSelected
)
816 if( NULL
== pEntry
->GetUserData() )
817 mbLinkableSelected
= sal_False
;
819 pEntry
= NextSelected( pEntry
);
822 SvTreeListBox::SelectHdl();
826 * Overloads RETURN with the functionality of DoubleClick
828 void SdPageObjsTLB::KeyInput( const KeyEvent
& rKEvt
)
830 if( rKEvt
.GetKeyCode().GetCode() == KEY_RETURN
)
832 // commented code from svtools/source/contnr/svimpbox.cxx
833 SvTreeListEntry
* pCursor
= GetCurEntry();
834 if( pCursor
->HasChildren() || pCursor
->HasChildrenOnDemand() )
836 if( IsExpanded( pCursor
) )
845 SvTreeListBox::KeyInput( rKEvt
);
851 void SdPageObjsTLB::StartDrag( sal_Int8 nAction
, const Point
& rPosPixel
)
856 SdNavigatorWin
* pNavWin
= NULL
;
857 SvTreeListEntry
* pEntry
= GetEntry(rPosPixel
);
859 if( mpFrame
->HasChildWindow( SID_NAVIGATOR
) )
860 pNavWin
= (SdNavigatorWin
*) ( mpFrame
->GetChildWindow( SID_NAVIGATOR
)->GetContextWindow( SD_MOD() ) );
864 && pNavWin
== mpParent
865 && pNavWin
->GetNavigatorDragType() != NAVIGATOR_DRAGTYPE_NONE
)
867 // Mark only the children of the page under the mouse as drop
868 // targets. This prevents moving shapes from one page to another.
870 // Select all entries and disable them as drop targets.
871 SetSelectionMode(MULTIPLE_SELECTION
);
872 SetCursor(NULL
, sal_False
);
873 SelectAll(sal_True
, sal_False
);
874 EnableSelectionAsDropTarget(sal_False
, sal_True
);
876 // Enable only the entries as drop targets that are children of the
877 // page under the mouse.
878 SvTreeListEntry
* pParent
= GetRootLevelParent(pEntry
);
881 SelectAll(sal_False
, sal_False
);
882 Select(pParent
, sal_True
);
883 // for (SvTreeListEntry*pChild=FirstChild(pParent); pChild!=NULL; pChild=NextSibling(pChild))
884 // Select(pChild, sal_True);
885 EnableSelectionAsDropTarget(sal_True
, sal_True
);//sal_False);
888 // Set selection back to the entry under the mouse.
889 SelectAll(sal_False
,sal_False
);
890 SetSelectionMode(SINGLE_SELECTION
);
891 Select(pEntry
, sal_True
);
893 // We can delete the Navigator from ExecuteDrag (when switching to
894 // another document type), but that would kill the StarView MouseMove
895 // Handler which is calling Command().
896 // For this reason, Drag&Drop is asynchronous.
897 Application::PostUserEvent( STATIC_LINK( this, SdPageObjsTLB
, ExecDragHdl
) );
904 void SdPageObjsTLB::DoDrag()
906 mpDropNavWin
= ( mpFrame
->HasChildWindow( SID_NAVIGATOR
) ) ?
907 (SdNavigatorWin
*)( mpFrame
->GetChildWindow( SID_NAVIGATOR
)->GetContextWindow( SD_MOD() ) ) :
912 ::sd::DrawDocShell
* pDocShell
= mpDoc
->GetDocSh();
913 String aURL
= INetURLObject( pDocShell
->GetMedium()->GetPhysicalName(), INET_PROT_FILE
).GetMainURL( INetURLObject::NO_DECODE
);
914 NavigatorDragType eDragType
= mpDropNavWin
->GetNavigatorDragType();
917 aURL
.Append( GetSelectEntry() );
919 INetBookmark
aBookmark( aURL
, GetSelectEntry() );
920 sal_Int8 nDNDActions
= DND_ACTION_COPYMOVE
;
922 if( eDragType
== NAVIGATOR_DRAGTYPE_LINK
)
923 nDNDActions
= DND_ACTION_LINK
; // Either COPY *or* LINK, never both!
924 else if (mpDoc
->GetSdPageCount(PK_STANDARD
) == 1)
926 // Can not move away the last slide in a document.
927 nDNDActions
= DND_ACTION_COPY
;
930 SvTreeListBox::ReleaseMouse();
932 bIsInDrag
= sal_True
;
934 SvLBoxDDInfo aDDInfo
;
935 memset(&aDDInfo
,0,sizeof(SvLBoxDDInfo
));
936 aDDInfo
.pApp
= GetpApp();
937 aDDInfo
.pSource
= this;
938 // aDDInfo.pDDStartEntry = pEntry;
939 ::com::sun::star::uno::Sequence
<sal_Int8
> aSequence (sizeof(SvLBoxDDInfo
));
940 memcpy(aSequence
.getArray(), (sal_Char
*)&aDDInfo
, sizeof(SvLBoxDDInfo
));
941 ::com::sun::star::uno::Any
aTreeListBoxData (aSequence
);
943 // object is destroyed by internal reference mechanism
944 SdTransferable
* pTransferable
= new SdPageObjsTLB::SdPageObjsTransferable(
945 *this, aBookmark
, *pDocShell
, eDragType
, aTreeListBoxData
);
948 ::sd::ViewShell
* pViewShell
= GetViewShellForDocShell(*pDocShell
);
949 if (pViewShell
== NULL
)
951 OSL_ASSERT(pViewShell
!=NULL
);
954 sd::View
* pView
= pViewShell
->GetView();
957 OSL_ASSERT(pView
!=NULL
);
961 SdrObject
* pObject
= NULL
;
962 void* pUserData
= GetCurEntry()->GetUserData();
963 if (pUserData
!= NULL
&& pUserData
!= (void*)1)
964 pObject
= reinterpret_cast<SdrObject
*>(pUserData
);
967 // For shapes without a user supplied name (the automatically
968 // created name does not count), a different drag and drop technique
970 if (GetObjectName(pObject
, false).Len() == 0)
972 AddShapeToTransferable(*pTransferable
, *pObject
);
973 pTransferable
->SetView(pView
);
974 SD_MOD()->pTransferDrag
= pTransferable
;
977 // Unnamed shapes have to be selected to be recognized by the
978 // current drop implementation. In order to have a consistent
979 // behaviour for all shapes, every shape that is to be dragged is
981 SdrPageView
* pPageView
= pView
->GetSdrPageView();
982 pView
->UnmarkAllObj(pPageView
);
983 pView
->MarkObj(pObject
, pPageView
);
987 pTransferable
->SetView(pView
);
988 SD_MOD()->pTransferDrag
= pTransferable
;
991 pTransferable
->StartDrag( this, nDNDActions
);
995 void SdPageObjsTLB::OnDragFinished( sal_uInt8
)
997 if( mpFrame
->HasChildWindow( SID_NAVIGATOR
) )
999 SdNavigatorWin
* pNewNavWin
= (SdNavigatorWin
*) ( mpFrame
->GetChildWindow( SID_NAVIGATOR
)->GetContextWindow( SD_MOD() ) );
1001 if( mpDropNavWin
== pNewNavWin
)
1003 MouseEvent
aMEvt( mpDropNavWin
->GetPointerPosPixel() );
1004 SvTreeListBox::MouseButtonUp( aMEvt
);
1008 mpDropNavWin
= NULL
;
1009 bIsInDrag
= sal_False
;
1015 sal_Int8
SdPageObjsTLB::AcceptDrop (const AcceptDropEvent
& rEvent
)
1017 sal_Int8
nResult (DND_ACTION_NONE
);
1019 if ( !bIsInDrag
&& IsDropFormatSupported( FORMAT_FILE
) )
1021 nResult
= rEvent
.mnAction
;
1025 SvTreeListEntry
* pEntry
= GetDropTarget(rEvent
.maPosPixel
);
1026 if (rEvent
.mbLeaving
|| !CheckDragAndDropMode( this, rEvent
.mnAction
))
1028 ImplShowTargetEmphasis( pTargetEntry
, sal_False
);
1030 else if( !GetDragDropMode() )
1032 SAL_WARN( "sc.ui", "SdPageObjsTLB::AcceptDrop(): no target" );
1034 else if (IsDropAllowed(pEntry
))
1036 nResult
= DND_ACTION_MOVE
;
1039 if (pEntry
!= pTargetEntry
|| !(nImpFlags
& SVLBOX_TARGEMPH_VIS
))
1041 ImplShowTargetEmphasis( pTargetEntry
, sal_False
);
1042 pTargetEntry
= pEntry
;
1043 ImplShowTargetEmphasis( pTargetEntry
, sal_True
);
1048 // Hide emphasis when there is no valid drop action.
1049 if (nResult
== DND_ACTION_NONE
)
1050 ImplShowTargetEmphasis(pTargetEntry
, sal_False
);
1058 sal_Int8
SdPageObjsTLB::ExecuteDrop( const ExecuteDropEvent
& rEvt
)
1060 sal_Int8 nRet
= DND_ACTION_NONE
;
1066 SdNavigatorWin
* pNavWin
= NULL
;
1067 sal_uInt16 nId
= SID_NAVIGATOR
;
1069 if( mpFrame
->HasChildWindow( nId
) )
1070 pNavWin
= (SdNavigatorWin
*)( mpFrame
->GetChildWindow( nId
)->GetContextWindow( SD_MOD() ) );
1072 if( pNavWin
&& ( pNavWin
== mpParent
) )
1074 TransferableDataHelper
aDataHelper( rEvt
.maDropEvent
.Transferable
);
1077 if( aDataHelper
.GetString( FORMAT_FILE
, aFile
) &&
1078 ( (SdNavigatorWin
*) mpParent
)->InsertFile( aFile
) )
1080 nRet
= rEvt
.mnAction
;
1085 catch (com::sun::star::uno::Exception
&)
1087 DBG_UNHANDLED_EXCEPTION();
1090 if (nRet
== DND_ACTION_NONE
)
1091 SvTreeListBox::ExecuteDrop(rEvt
, this);
1098 * Handler for Dragging
1100 IMPL_STATIC_LINK(SdPageObjsTLB
, ExecDragHdl
, void*, EMPTYARG
)
1102 // as link, then it is allowed to asynchronous, without ImpMouseMoveMsg on
1103 // the stack, delete the Navigator
1109 bool SdPageObjsTLB::PageBelongsToCurrentShow (const SdPage
* pPage
) const
1111 // Return <TRUE/> as default when there is no custom show or when none
1112 // is used. The page does then belong to the standard show.
1113 bool bBelongsToShow
= true;
1115 if (mpDoc
->getPresentationSettings().mbCustomShow
)
1117 // Get the current custom show.
1118 SdCustomShow
* pCustomShow
= NULL
;
1119 SdCustomShowList
* pShowList
= const_cast<SdDrawDocument
*>(mpDoc
)->GetCustomShowList();
1120 if (pShowList
!= NULL
)
1122 sal_uLong nCurrentShowIndex
= pShowList
->GetCurPos();
1123 pCustomShow
= (*pShowList
)[nCurrentShowIndex
];
1126 // Check whether the given page is part of that custom show.
1127 if (pCustomShow
!= NULL
)
1129 bBelongsToShow
= false;
1130 sal_uLong nPageCount
= pCustomShow
->PagesVector().size();
1131 for (sal_uInt16 i
=0; i
<nPageCount
&& !bBelongsToShow
; i
++)
1132 if (pPage
== pCustomShow
->PagesVector()[i
])
1133 bBelongsToShow
= true;
1137 return bBelongsToShow
;
1143 sal_Bool
SdPageObjsTLB::NotifyMoving(
1144 SvTreeListEntry
* pTarget
,
1145 SvTreeListEntry
* pEntry
,
1146 SvTreeListEntry
*& rpNewParent
,
1147 sal_uLong
& rNewChildPos
)
1149 SvTreeListEntry
* pDestination
= pTarget
;
1150 while (GetParent(pDestination
) != NULL
&& GetParent(GetParent(pDestination
)) != NULL
)
1151 pDestination
= GetParent(pDestination
);
1153 SdrObject
* pTargetObject
= reinterpret_cast<SdrObject
*>(pDestination
->GetUserData());
1154 SdrObject
* pSourceObject
= reinterpret_cast<SdrObject
*>(pEntry
->GetUserData());
1155 if (pSourceObject
== reinterpret_cast<SdrObject
*>(1))
1156 pSourceObject
= NULL
;
1158 if (pTargetObject
!= NULL
&& pSourceObject
!= NULL
)
1160 SdrPage
* pObjectList
= pSourceObject
->GetPage();
1161 if (pObjectList
!= NULL
)
1163 sal_uInt32 nNewPosition
;
1164 if (pTargetObject
== reinterpret_cast<SdrObject
*>(1))
1167 nNewPosition
= pTargetObject
->GetNavigationPosition() + 1;
1168 pObjectList
->SetObjectNavigationPosition(*pSourceObject
, nNewPosition
);
1171 // Update the tree list.
1172 if (pTarget
== NULL
)
1178 else if (GetParent(pDestination
) == NULL
)
1180 rpNewParent
= pDestination
;
1185 rpNewParent
= GetParent(pDestination
);
1186 rNewChildPos
= pModel
->GetRelPos(pDestination
) + 1;
1187 rNewChildPos
+= nCurEntrySelPos
;
1199 SvTreeListEntry
* SdPageObjsTLB::GetDropTarget (const Point
& rLocation
)
1201 SvTreeListEntry
* pEntry
= SvTreeListBox::GetDropTarget(rLocation
);
1205 if (GetParent(pEntry
) == NULL
)
1207 // Use page entry as insertion position.
1211 // Go to second hierarchy level, i.e. top level shapes,
1212 // i.e. children of pages.
1213 while (GetParent(pEntry
) != NULL
&& GetParent(GetParent(pEntry
)) != NULL
)
1214 pEntry
= GetParent(pEntry
);
1216 // Advance to next sibling.
1217 SvTreeListEntry
* pNext
;
1218 sal_uInt16
nDepth (0);
1219 while (pEntry
!= NULL
)
1221 pNext
= dynamic_cast<SvTreeListEntry
*>(NextVisible(pEntry
, &nDepth
));
1222 if (pNext
!= NULL
&& nDepth
> 0 && nDepth
!=0xffff)
1235 bool SdPageObjsTLB::IsDropAllowed (SvTreeListEntry
* pEntry
)
1240 if ( ! IsDropFormatSupported(SdPageObjsTransferable::GetListBoxDropFormatId()))
1243 if ((pEntry
->GetFlags() & SV_ENTRYFLAG_DISABLE_DROP
) != 0)
1252 void SdPageObjsTLB::AddShapeToTransferable (
1253 SdTransferable
& rTransferable
,
1254 SdrObject
& rObject
) const
1256 TransferableObjectDescriptor aObjectDescriptor
;
1257 bool bIsDescriptorFillingPending (true);
1259 const SdrOle2Obj
* pOleObject
= dynamic_cast<const SdrOle2Obj
*>(&rObject
);
1260 if (pOleObject
!= NULL
&& pOleObject
->GetObjRef().is())
1262 // If object has no persistence it must be copied as part of the document
1265 uno::Reference
< embed::XEmbedPersist
> xPersObj (pOleObject
->GetObjRef(), uno::UNO_QUERY
);
1266 if (xPersObj
.is() && xPersObj
->hasEntry())
1268 SvEmbedTransferHelper::FillTransferableObjectDescriptor(
1270 pOleObject
->GetObjRef(),
1271 pOleObject
->GetGraphic(),
1272 pOleObject
->GetAspect());
1273 bIsDescriptorFillingPending
= false;
1276 catch( uno::Exception
& )
1281 ::sd::DrawDocShell
* pDocShell
= mpDoc
->GetDocSh();
1282 if (bIsDescriptorFillingPending
&& pDocShell
!=NULL
)
1284 pDocShell
->FillTransferableObjectDescriptor(aObjectDescriptor
);
1287 Point
aDragPos (rObject
.GetCurrentBoundRect().Center());
1288 //Point aDragPos (0,0);
1289 aObjectDescriptor
.maDragStartPos
= aDragPos
;
1290 // aObjectDescriptor.maSize = GetAllMarkedRect().GetSize();
1291 if (pDocShell
!= NULL
)
1292 aObjectDescriptor
.maDisplayName
= pDocShell
->GetMedium()->GetURLObject().GetURLNoPass();
1294 aObjectDescriptor
.maDisplayName
= String();
1295 aObjectDescriptor
.mbCanLink
= sal_False
;
1297 rTransferable
.SetStartPos(aDragPos
);
1298 rTransferable
.SetObjectDescriptor( aObjectDescriptor
);
1304 ::sd::ViewShell
* SdPageObjsTLB::GetViewShellForDocShell (::sd::DrawDocShell
& rDocShell
)
1307 ::sd::ViewShell
* pViewShell
= rDocShell
.GetViewShell();
1308 if (pViewShell
!= NULL
)
1314 // Get a component enumeration from the desktop and search it for documents.
1315 uno::Reference
<uno::XComponentContext
> xContext( ::comphelper::getProcessComponentContext());
1317 uno::Reference
<frame::XDesktop2
> xDesktop
= frame::Desktop::create(xContext
);
1319 uno::Reference
<frame::XFramesSupplier
> xFrameSupplier (xDesktop
, uno::UNO_QUERY
);
1320 if ( ! xFrameSupplier
.is())
1323 uno::Reference
<container::XIndexAccess
> xFrameAccess (xFrameSupplier
->getFrames(), uno::UNO_QUERY
);
1324 if ( ! xFrameAccess
.is())
1327 for (sal_Int32 nIndex
=0,nCount
=xFrameAccess
->getCount(); nIndex
<nCount
; ++nIndex
)
1329 uno::Reference
<frame::XFrame
> xFrame
;
1330 if ( ! (xFrameAccess
->getByIndex(nIndex
) >>= xFrame
))
1333 ::sd::DrawController
* pController
= dynamic_cast<sd::DrawController
*>(xFrame
->getController().get());
1334 if (pController
== NULL
)
1336 ::sd::ViewShellBase
* pBase
= pController
->GetViewShellBase();
1339 if (pBase
->GetDocShell() != &rDocShell
)
1342 const ::boost::shared_ptr
<sd::ViewShell
> pViewShell (pBase
->GetMainViewShell());
1344 return pViewShell
.get();
1347 catch (uno::Exception
&)
1349 // When there is an exception then simply use the default value of
1350 // bIsEnabled and disable the controls.
1358 //===== IconProvider ==========================================================
1360 SdPageObjsTLB::IconProvider::IconProvider (void)
1361 : maImgPage( BitmapEx( SdResId( BMP_PAGE
) ) ),
1362 maImgPageExcl( BitmapEx( SdResId( BMP_PAGE_EXCLUDED
) ) ),
1363 maImgPageObjsExcl( BitmapEx( SdResId( BMP_PAGEOBJS_EXCLUDED
) ) ),
1364 maImgPageObjs( BitmapEx( SdResId( BMP_PAGEOBJS
) ) ),
1365 maImgObjects( BitmapEx( SdResId( BMP_OBJECTS
) ) ),
1366 maImgGroup( BitmapEx( SdResId( BMP_GROUP
) ) )
1370 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */