fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / sd / source / ui / dlg / sdtreelb.cxx
blobf769db33e8f8843cf28c31210dcc5990b87c2766
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
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>
35 #include "strmname.h"
36 #include "sdtreelb.hxx"
37 #include "DrawDocShell.hxx"
38 #include "drawdoc.hxx"
39 #include "sdpage.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
62 public:
63 IconProvider (void);
65 // Regular icons.
66 Image maImgPage;
67 Image maImgPageExcl;
68 Image maImgPageObjsExcl;
69 Image maImgPageObjs;
70 Image maImgObjects;
71 Image maImgGroup;
75 sal_Bool SAL_DLLPRIVATE SdPageObjsTLB::bIsInDrag = sal_False;
77 sal_Bool SdPageObjsTLB::IsInDrag()
79 return bIsInDrag;
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),
95 mrParent( rParent ),
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 );
124 switch (nFormatId)
126 case SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK:
127 SetINetBookmark( maBookmark, rFlavor );
128 return sal_True;
130 case SOT_FORMATSTR_ID_TREELISTBOX:
131 SetAny(maTreeListBoxData, rFlavor);
132 return sal_True;
134 default:
135 return sal_False;
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
151 return mrDocShell;
154 // -----------------------------------------------------------------------------
156 NavigatorDragType SdPageObjsTLB::SdPageObjsTransferable::GetDragType() const
158 return meDragType;
161 // -----------------------------------------------------------------------------
163 sal_Int64 SAL_CALL SdPageObjsTLB::SdPageObjsTransferable::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw( ::com::sun::star::uno::RuntimeException )
165 sal_Int64 nRet;
167 if( ( rId.getLength() == 16 ) &&
168 ( 0 == memcmp( getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) )
170 nRet = (sal_Int64)(sal_IntPtr)this;
172 else
173 nRet = SdTransferable::getSomething(rId);
175 return nRet;
178 namespace
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 )
191 throw()
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& )
204 return 0;
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 )
220 , mpDoc ( NULL )
221 , mpBookmarkDoc ( NULL )
222 , mpMedium ( 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 |
235 WB_HSCROLL |
236 WB_HASBUTTONSATROOT |
237 WB_QUICK_SEARCH /* i31275 */ );
238 SetNodeBitmaps( Bitmap( SdResId( BMP_EXPAND ) ),
239 Bitmap( SdResId( BMP_COLLAPSE ) ) );
241 SetDragDropMode(
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()
249 if ( mpBookmarkDoc )
250 CloseBookmarkDoc();
251 else
252 // no document was created from mpMedium, so this object is still the owner of it
253 delete mpMedium;
256 String SdPageObjsTLB::GetObjectName(
257 const SdrObject* pObject,
258 const bool bCreate) const
260 String aRet;
262 if ( pObject )
264 aRet = pObject->GetName();
266 if( !aRet.Len() && pObject->ISA( SdrOle2Obj ) )
267 aRet = static_cast< const SdrOle2Obj* >( pObject )->GetPersistName();
270 if (bCreate
271 && mbShowAllShapes
272 && aRet.Len() == 0
273 && pObject!=NULL)
275 aRet = SD_RESSTR(STR_NAVIGATOR_SHAPE_BASE_NAME);
276 aRet.SearchAndReplaceAscii("%1", OUString::number(pObject->GetOrdNum() + 1));
279 return aRet;
283 * select a entry in TreeLB
285 sal_Bool SdPageObjsTLB::SelectEntry( const String& rName )
287 sal_Bool bFound = sal_False;
289 if( rName.Len() )
291 SvTreeListEntry* pEntry = NULL;
292 String aTmp;
294 for( pEntry = First(); pEntry && !bFound; pEntry = Next( pEntry ) )
296 aTmp = GetEntryText( pEntry );
297 if( aTmp == rName )
299 bFound = sal_True;
300 SetCurEntry( pEntry );
304 return( bFound );
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;
315 if( rName.Len() )
317 SvTreeListEntry* pEntry = NULL;
318 String aTmp;
320 for( pEntry = First(); pEntry && !bFound; pEntry = Next( pEntry ) )
322 aTmp = GetEntryText( pEntry );
323 if( aTmp == rName )
325 bFound = sal_True;
326 sal_Bool bExpanded = IsExpanded( pEntry );
327 long nCount = GetChildSelectionCount( pEntry );
328 if( bExpanded && nCount > 0 )
329 bChildren = sal_True;
333 return( bChildren );
338 * Fill TreeLB with pages and objects
340 void SdPageObjsTLB::Fill( const SdDrawDocument* pInDoc, sal_Bool bAllPages,
341 const String& rDocName)
343 String aSelection;
344 if( GetSelectionCount() > 0 )
346 aSelection = GetSelectEntry();
347 Clear();
350 mpDoc = pInDoc;
351 maDocName = rDocName;
352 mbShowAllPages = (bAllPages == sal_True);
353 mpMedium = NULL;
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);
376 nPage++;
379 // then insert all master pages including objects
380 if( mbShowAllPages )
382 nPage = 0;
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);
389 nPage++;
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 )
402 mpDoc = pInDoc;
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,
422 SdrObject* pShape,
423 const OUString& rsName,
424 const bool bIsExcluded,
425 SvTreeListEntry* pParentEntry,
426 const IconProvider& rIconProvider)
428 Image aIcon (rIconProvider.maImgPage);
429 if (bIsExcluded)
430 aIcon = rIconProvider.maImgPageExcl;
431 else if (pShape != NULL)
432 aIcon = rIconProvider.maImgGroup;
434 void* pUserData (reinterpret_cast<void*>(1));
435 if (pShape != NULL)
436 pUserData = pShape;
438 SvTreeListEntry* pEntry = InsertEntry(
439 rsName,
440 aIcon,
441 aIcon,
442 pParentEntry,
443 sal_False,
444 LIST_APPEND,
445 pUserData);
447 SdrObjListIter aIter(
448 rList,
449 !rList.HasObjectNavigationOrder() /* use navigation order, if available */,
450 IM_FLAT,
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 ) );
461 if( aStr.Len() )
463 if( pObj->GetObjInventor() == SdrInventor && pObj->GetObjIdentifier() == OBJ_OLE2 )
465 InsertEntry(
466 aStr,
467 maImgOle,
468 maImgOle,
469 pEntry,
470 sal_False,
471 LIST_APPEND,
472 pObj
475 else if( pObj->GetObjInventor() == SdrInventor && pObj->GetObjIdentifier() == OBJ_GRAF )
477 InsertEntry(
478 aStr,
479 maImgGraphic,
480 maImgGraphic,
481 pEntry,
482 sal_False,
483 LIST_APPEND,
484 pObj
487 else if (pObj->IsGroupObject())
489 AddShapeList(
490 *pObj->GetSubList(),
491 pObj,
492 aStr,
493 false,
494 pEntry,
495 rIconProvider
498 else
500 InsertEntry(
501 aStr,
502 rIconProvider.maImgObjects,
503 rIconProvider.maImgObjects,
504 pEntry,
505 sal_False,
506 LIST_APPEND,
507 pObj
513 if( pEntry->HasChildren() )
515 SetExpandedEntryBmp(
516 pEntry,
517 bIsExcluded ? rIconProvider.maImgPageObjsExcl : rIconProvider.maImgPageObjs);
518 SetCollapsedEntryBmp(
519 pEntry,
520 bIsExcluded ? rIconProvider.maImgPageObjsExcl : rIconProvider.maImgPageObjs);
527 void SdPageObjsTLB::SetShowAllShapes (
528 const bool bShowAllShapes,
529 const bool bFillList)
531 mbShowAllShapes = bShowAllShapes;
532 if (bFillList)
534 if (mpMedium == NULL)
535 Fill(mpDoc, mbShowAllPages, maDocName);
536 else
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
556 * one document).
558 sal_Bool SdPageObjsTLB::IsEqualToDoc( const SdDrawDocument* pInDoc )
560 if( pInDoc )
561 mpDoc = pInDoc;
563 if( !mpDoc )
564 return( sal_False );
566 SdrObject* pObj = NULL;
567 SdPage* pPage = NULL;
568 SvTreeListEntry* pEntry = First();
569 String aName;
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 )
580 if( !pEntry )
581 return( sal_False );
582 aName = GetEntryText( pEntry );
584 if( pPage->GetName() != aName )
585 return( sal_False );
587 pEntry = Next( pEntry );
589 SdrObjListIter aIter(
590 *pPage,
591 !pPage->HasObjectNavigationOrder() /* use navigation order, if available */,
592 IM_DEEPWITHGROUPS );
594 while( aIter.IsMore() )
596 pObj = aIter.Next();
598 const String aObjectName( GetObjectName( pObj ) );
600 if( aObjectName.Len() )
602 if( !pEntry )
603 return( sal_False );
605 aName = GetEntryText( pEntry );
607 if( aObjectName != aName )
608 return( sal_False );
610 pEntry = Next( pEntry );
614 nPage++;
616 // If there are still entries in the listbox,
617 // then objects (with names) or pages were deleted
618 return( !pEntry );
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();
634 while( pEntry )
636 sal_uInt16 nListDepth = GetModel()->GetDepth( pEntry );
638 if( nListDepth == nDepth )
639 aEntries.push_back(GetEntryText(pEntry));
641 pEntry = NextSelected( pEntry );
644 return aEntries;
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(),
676 aImgPage,
677 aImgPage,
678 pFileEntry,
679 sal_False,
680 LIST_APPEND,
681 reinterpret_cast< void* >( 1 ) );
683 SdrObjListIter aIter( *pPage, IM_DEEPWITHGROUPS );
685 while( aIter.IsMore() )
687 pObj = aIter.Next();
688 String aStr( GetObjectName( pObj ) );
689 if( aStr.Len() )
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);
699 else
701 InsertEntry(aStr, aImgObjects, aImgObjects, pPageEntry);
705 if( pPageEntry->HasChildren() )
707 SetExpandedEntryBmp( pPageEntry, aImgPageObjs );
708 SetCollapsedEntryBmp( pPageEntry, aImgPageObjs );
711 nPage++;
715 else
716 SvTreeListBox::RequestingChildren( pFileEntry );
720 * Checks if it is a draw file and opens the BookmarkDoc depending of
721 * the provided Docs
723 SdDrawDocument* SdPageObjsTLB::GetBookmarkDoc(SfxMedium* pMed)
725 if (
726 !mpBookmarkDoc ||
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)
733 CloseBookmarkDoc();
736 if (pMed)
738 // it looks that it is undefined if a Medium was set by Fill() already
739 DBG_ASSERT( !mpMedium, "SfxMedium confusion!" );
740 delete mpMedium;
741 mpMedium = NULL;
743 // take over this Medium (currently used only be Navigator)
744 mpOwnMedium = pMed;
747 DBG_ASSERT( mpMedium || pMed, "No SfxMedium provided!" );
749 if( pMed )
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();
755 else
756 mpBookmarkDoc = NULL;
758 else if ( mpMedium )
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 ) ) );
767 aErrorBox.Execute();
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
786 mpOwnMedium = 0;
788 else if ( mpBookmarkDoc )
790 DBG_ASSERT( !mpOwnMedium, "SfxMedium confusion!" );
791 if ( mpDoc )
793 // The document owns the Medium, so the Medium will be invalid after closing the document
794 ((SdDrawDocument*) mpDoc)->CloseBookmarkDoc();
795 mpMedium = 0;
798 else
800 // perhaps mpOwnMedium provided, but no successful creation of BookmarkDoc
801 delete mpOwnMedium;
802 mpOwnMedium = NULL;
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 ) )
837 Collapse( pCursor );
838 else
839 Expand( pCursor );
842 DoubleClickHdl();
844 else
845 SvTreeListBox::KeyInput( rKEvt );
849 * StartDrag-Request
851 void SdPageObjsTLB::StartDrag( sal_Int8 nAction, const Point& rPosPixel)
853 (void)nAction;
854 (void)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() ) );
862 if (pEntry != NULL
863 && pNavWin !=NULL
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);
879 if (pParent != NULL)
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 ) );
902 * Begin drag
904 void SdPageObjsTLB::DoDrag()
906 mpDropNavWin = ( mpFrame->HasChildWindow( SID_NAVIGATOR ) ) ?
907 (SdNavigatorWin*)( mpFrame->GetChildWindow( SID_NAVIGATOR )->GetContextWindow( SD_MOD() ) ) :
908 NULL;
910 if( mpDropNavWin )
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();
916 aURL.Append( '#' );
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);
947 // Get the view.
948 ::sd::ViewShell* pViewShell = GetViewShellForDocShell(*pDocShell);
949 if (pViewShell == NULL)
951 OSL_ASSERT(pViewShell!=NULL);
952 return;
954 sd::View* pView = pViewShell->GetView();
955 if (pView == NULL)
957 OSL_ASSERT(pView!=NULL);
958 return;
961 SdrObject* pObject = NULL;
962 void* pUserData = GetCurEntry()->GetUserData();
963 if (pUserData != NULL && pUserData != (void*)1)
964 pObject = reinterpret_cast<SdrObject*>(pUserData);
965 if (pObject != NULL)
967 // For shapes without a user supplied name (the automatically
968 // created name does not count), a different drag and drop technique
969 // is used.
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
980 // selected first.
981 SdrPageView* pPageView = pView->GetSdrPageView();
982 pView->UnmarkAllObj(pPageView);
983 pView->MarkObj(pObject, pPageView);
985 else
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;
1013 * AcceptDrop-Event
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;
1023 else
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;
1038 // Draw emphasis.
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);
1052 return nResult;
1056 * ExecuteDrop-Event
1058 sal_Int8 SdPageObjsTLB::ExecuteDrop( const ExecuteDropEvent& rEvt )
1060 sal_Int8 nRet = DND_ACTION_NONE;
1064 if( !bIsInDrag )
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 );
1075 String aFile;
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);
1094 return nRet;
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
1104 pThis->DoDrag();
1105 return 0;
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))
1165 nNewPosition = 0;
1166 else
1167 nNewPosition = pTargetObject->GetNavigationPosition() + 1;
1168 pObjectList->SetObjectNavigationPosition(*pSourceObject, nNewPosition);
1171 // Update the tree list.
1172 if (pTarget == NULL)
1174 rpNewParent = 0;
1175 rNewChildPos = 0;
1176 return sal_True;
1178 else if (GetParent(pDestination) == NULL)
1180 rpNewParent = pDestination;
1181 rNewChildPos = 0;
1183 else
1185 rpNewParent = GetParent(pDestination);
1186 rNewChildPos = pModel->GetRelPos(pDestination) + 1;
1187 rNewChildPos += nCurEntrySelPos;
1188 nCurEntrySelPos++;
1190 return sal_True;
1192 else
1193 return sal_False;
1199 SvTreeListEntry* SdPageObjsTLB::GetDropTarget (const Point& rLocation)
1201 SvTreeListEntry* pEntry = SvTreeListBox::GetDropTarget(rLocation);
1202 if (pEntry == NULL)
1203 return NULL;
1205 if (GetParent(pEntry) == NULL)
1207 // Use page entry as insertion position.
1209 else
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)
1223 pEntry = pNext;
1224 else
1225 break;
1229 return pEntry;
1235 bool SdPageObjsTLB::IsDropAllowed (SvTreeListEntry* pEntry)
1237 if (pEntry == NULL)
1238 return false;
1240 if ( ! IsDropFormatSupported(SdPageObjsTransferable::GetListBoxDropFormatId()))
1241 return false;
1243 if ((pEntry->GetFlags() & SV_ENTRYFLAG_DISABLE_DROP) != 0)
1244 return false;
1246 return true;
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(
1269 aObjectDescriptor,
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();
1293 else
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)
1309 return pViewShell;
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())
1321 return NULL;
1323 uno::Reference<container::XIndexAccess> xFrameAccess (xFrameSupplier->getFrames(), uno::UNO_QUERY);
1324 if ( ! xFrameAccess.is())
1325 return NULL;
1327 for (sal_Int32 nIndex=0,nCount=xFrameAccess->getCount(); nIndex<nCount; ++nIndex)
1329 uno::Reference<frame::XFrame> xFrame;
1330 if ( ! (xFrameAccess->getByIndex(nIndex) >>= xFrame))
1331 continue;
1333 ::sd::DrawController* pController = dynamic_cast<sd::DrawController*>(xFrame->getController().get());
1334 if (pController == NULL)
1335 continue;
1336 ::sd::ViewShellBase* pBase = pController->GetViewShellBase();
1337 if (pBase == NULL)
1338 continue;
1339 if (pBase->GetDocShell() != &rDocShell)
1340 continue;
1342 const ::boost::shared_ptr<sd::ViewShell> pViewShell (pBase->GetMainViewShell());
1343 if (pViewShell)
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.
1352 return NULL;
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: */