Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
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>
32 :
33 : #include <sfx2/viewfrm.hxx>
34 :
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"
48 :
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/svlbitm.hxx>
54 : #include <svtools/treelistentry.hxx>
55 : #include <comphelper/servicehelper.hxx>
56 : #include <comphelper/processfactory.hxx>
57 : #include <tools/diagnose_ex.h>
58 :
59 : using namespace com::sun::star;
60 :
61 0 : class SdPageObjsTLB::IconProvider
62 : {
63 : public:
64 : IconProvider (void);
65 :
66 : // Regular icons.
67 : Image maImgPage;
68 : Image maImgPageExcl;
69 : Image maImgPageObjsExcl;
70 : Image maImgPageObjs;
71 : Image maImgObjects;
72 : Image maImgGroup;
73 : };
74 :
75 :
76 : sal_Bool SdPageObjsTLB::bIsInDrag = sal_False;
77 :
78 0 : sal_Bool SdPageObjsTLB::IsInDrag()
79 : {
80 0 : return bIsInDrag;
81 : }
82 :
83 : sal_uInt32 SdPageObjsTLB::SdPageObjsTransferable::mnListBoxDropFormatId = SAL_MAX_UINT32;
84 :
85 :
86 : // - SdPageObjsTLB::SdPageObjsTransferable -
87 :
88 :
89 0 : SdPageObjsTLB::SdPageObjsTransferable::SdPageObjsTransferable(
90 : SdPageObjsTLB& rParent,
91 : const INetBookmark& rBookmark,
92 : ::sd::DrawDocShell& rDocShell,
93 : NavigatorDragType eDragType,
94 : const ::com::sun::star::uno::Any& rTreeListBoxData )
95 : : SdTransferable(rDocShell.GetDoc(), NULL, sal_True),
96 : mrParent( rParent ),
97 : maBookmark( rBookmark ),
98 : mrDocShell( rDocShell ),
99 : meDragType( eDragType ),
100 0 : maTreeListBoxData( rTreeListBoxData )
101 : {
102 0 : }
103 :
104 0 : extern "C" SAL_DLLPUBLIC_EXPORT ::Window* SAL_CALL makeSdPageObjsTLB(::Window *pParent, VclBuilder::stringmap &rMap)
105 : {
106 0 : WinBits nWinStyle = WB_TABSTOP;
107 0 : OString sBorder = VclBuilder::extractCustomProperty(rMap);
108 0 : if (!sBorder.isEmpty())
109 0 : nWinStyle |= WB_BORDER;
110 0 : return new SdPageObjsTLB(pParent, nWinStyle);
111 : }
112 :
113 0 : SdPageObjsTLB::SdPageObjsTransferable::~SdPageObjsTransferable()
114 : {
115 0 : }
116 :
117 :
118 :
119 0 : void SdPageObjsTLB::SdPageObjsTransferable::AddSupportedFormats()
120 : {
121 0 : AddFormat(SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK);
122 0 : AddFormat(SOT_FORMATSTR_ID_TREELISTBOX);
123 0 : AddFormat(GetListBoxDropFormatId());
124 0 : }
125 :
126 :
127 :
128 0 : bool SdPageObjsTLB::SdPageObjsTransferable::GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor )
129 : {
130 0 : sal_uLong nFormatId = SotExchange::GetFormat( rFlavor );
131 0 : switch (nFormatId)
132 : {
133 : case SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK:
134 0 : SetINetBookmark( maBookmark, rFlavor );
135 0 : return true;
136 :
137 : case SOT_FORMATSTR_ID_TREELISTBOX:
138 0 : SetAny(maTreeListBoxData, rFlavor);
139 0 : return true;
140 :
141 : default:
142 0 : return false;
143 : }
144 : }
145 :
146 :
147 :
148 0 : void SdPageObjsTLB::SdPageObjsTransferable::DragFinished( sal_Int8 nDropAction )
149 : {
150 0 : mrParent.OnDragFinished( nDropAction );
151 0 : SdTransferable::DragFinished(nDropAction);
152 0 : }
153 :
154 :
155 :
156 0 : ::sd::DrawDocShell& SdPageObjsTLB::SdPageObjsTransferable::GetDocShell() const
157 : {
158 0 : return mrDocShell;
159 : }
160 :
161 :
162 :
163 0 : NavigatorDragType SdPageObjsTLB::SdPageObjsTransferable::GetDragType() const
164 : {
165 0 : return meDragType;
166 : }
167 :
168 :
169 :
170 0 : sal_Int64 SAL_CALL SdPageObjsTLB::SdPageObjsTransferable::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw( ::com::sun::star::uno::RuntimeException, std::exception )
171 : {
172 : sal_Int64 nRet;
173 :
174 0 : if( ( rId.getLength() == 16 ) &&
175 0 : ( 0 == memcmp( getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) )
176 : {
177 0 : nRet = (sal_Int64)(sal_IntPtr)this;
178 : }
179 : else
180 0 : nRet = SdTransferable::getSomething(rId);
181 :
182 0 : return nRet;
183 : }
184 :
185 : namespace
186 : {
187 : class theSdPageObjsTLBUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSdPageObjsTLBUnoTunnelId > {};
188 : }
189 :
190 0 : const ::com::sun::star::uno::Sequence< sal_Int8 >& SdPageObjsTLB::SdPageObjsTransferable::getUnoTunnelId()
191 : {
192 0 : return theSdPageObjsTLBUnoTunnelId::get().getSeq();
193 : }
194 :
195 :
196 :
197 0 : SdPageObjsTLB::SdPageObjsTransferable* SdPageObjsTLB::SdPageObjsTransferable::getImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rxData )
198 : throw()
199 : {
200 : try
201 : {
202 0 : ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > xUnoTunnel( rxData, ::com::sun::star::uno::UNO_QUERY_THROW );
203 :
204 : return reinterpret_cast<SdPageObjsTLB::SdPageObjsTransferable*>(
205 : sal::static_int_cast<sal_uIntPtr>(
206 0 : xUnoTunnel->getSomething( SdPageObjsTLB::SdPageObjsTransferable::getUnoTunnelId()) ) );
207 : }
208 0 : catch( const ::com::sun::star::uno::Exception& )
209 : {
210 : }
211 0 : return 0;
212 : }
213 :
214 :
215 0 : sal_uInt32 SdPageObjsTLB::SdPageObjsTransferable::GetListBoxDropFormatId (void)
216 : {
217 0 : if (mnListBoxDropFormatId == SAL_MAX_UINT32)
218 : mnListBoxDropFormatId = SotExchange::RegisterFormatMimeType(OUString(
219 0 : "application/x-openoffice-treelistbox-moveonly;windows_formatname=\"SV_LBOX_DD_FORMAT_MOVE\""));
220 0 : return mnListBoxDropFormatId;
221 : }
222 :
223 :
224 0 : SdPageObjsTLB::SdPageObjsTLB( Window* pParentWin, const SdResId& rSdResId )
225 : : SvTreeListBox ( pParentWin, rSdResId )
226 : , bisInSdNavigatorWin ( sal_False )
227 : , mpParent ( pParentWin )
228 : , mpDoc ( NULL )
229 : , mpBookmarkDoc ( NULL )
230 : , mpMedium ( NULL )
231 : , mpOwnMedium ( NULL )
232 : , maImgOle ( BitmapEx( SdResId( BMP_OLE ) ) )
233 : , maImgGraphic ( BitmapEx( SdResId( BMP_GRAPHIC ) ) )
234 : , mbLinkableSelected ( sal_False )
235 : , mpDropNavWin ( NULL )
236 : , mpFrame ( NULL )
237 : , mbSaveTreeItemState ( false )
238 : , mbShowAllShapes ( false )
239 0 : , mbShowAllPages ( false )
240 : {
241 : // add lines to Tree-ListBox
242 0 : SetStyle( GetStyle() | WB_TABSTOP | WB_BORDER | WB_HASLINES |
243 : WB_HASBUTTONS | // WB_HASLINESATROOT |
244 : WB_HSCROLL |
245 : WB_HASBUTTONSATROOT |
246 0 : WB_QUICK_SEARCH /* i31275 */ );
247 : SetNodeBitmaps( Image(Bitmap( SdResId(BMP_EXPAND) )),
248 0 : Image(Bitmap( SdResId(BMP_COLLAPSE) )));
249 :
250 : SetDragDropMode(
251 : SV_DRAGDROP_CTRL_MOVE | SV_DRAGDROP_CTRL_COPY |
252 0 : SV_DRAGDROP_APP_MOVE | SV_DRAGDROP_APP_COPY | SV_DRAGDROP_APP_DROP );
253 0 : }
254 :
255 0 : SdPageObjsTLB::SdPageObjsTLB( Window* pParentWin, WinBits nStyle )
256 : : SvTreeListBox ( pParentWin, nStyle )
257 : , bisInSdNavigatorWin ( false )
258 : , mpParent ( pParentWin )
259 : , mpDoc ( NULL )
260 : , mpBookmarkDoc ( NULL )
261 : , mpMedium ( NULL )
262 : , mpOwnMedium ( NULL )
263 : , maImgOle ( BitmapEx( SdResId( BMP_OLE ) ) )
264 : , maImgGraphic ( BitmapEx( SdResId( BMP_GRAPHIC ) ) )
265 : , mbLinkableSelected ( sal_False )
266 : , mpDropNavWin ( NULL )
267 : , mpFrame ( NULL )
268 : , mbSaveTreeItemState ( false )
269 : , mbShowAllShapes ( false )
270 0 : , mbShowAllPages ( false )
271 : {
272 : // add lines to Tree-ListBox
273 0 : SetStyle( GetStyle() | WB_TABSTOP | WB_BORDER | WB_HASLINES |
274 : WB_HASBUTTONS | // WB_HASLINESATROOT |
275 : WB_HSCROLL |
276 : WB_HASBUTTONSATROOT |
277 0 : WB_QUICK_SEARCH /* i31275 */ );
278 : SetNodeBitmaps( Image(Bitmap( SdResId(BMP_EXPAND) )),
279 0 : Image(Bitmap( SdResId(BMP_COLLAPSE) )));
280 :
281 : SetDragDropMode(
282 : SV_DRAGDROP_CTRL_MOVE | SV_DRAGDROP_CTRL_COPY |
283 0 : SV_DRAGDROP_APP_MOVE | SV_DRAGDROP_APP_COPY | SV_DRAGDROP_APP_DROP );
284 0 : }
285 :
286 :
287 0 : SdPageObjsTLB::~SdPageObjsTLB()
288 : {
289 0 : if ( mpBookmarkDoc )
290 0 : CloseBookmarkDoc();
291 : else
292 : // no document was created from mpMedium, so this object is still the owner of it
293 0 : delete mpMedium;
294 0 : }
295 :
296 : // helper function for GetEntryAltText and GetEntryLongDescription
297 0 : OUString SdPageObjsTLB::getAltLongDescText(SvTreeListEntry* pEntry , sal_Bool isAltText) const
298 : {
299 0 : sal_uInt16 maxPages = mpDoc->GetPageCount();
300 : sal_uInt16 pageNo;
301 0 : SdrObject* pObj = NULL;
302 0 : SdPage* pPage = NULL;
303 :
304 :
305 0 : OUString ParentName = GetEntryText( GetRootLevelParent( pEntry ) );
306 :
307 0 : for( pageNo = 0; pageNo < maxPages; pageNo++ )
308 : {
309 0 : pPage = (SdPage*) mpDoc->GetPage( pageNo );
310 0 : if( pPage->GetPageKind() != PK_STANDARD ) continue;
311 0 : if( pPage->GetName() != ParentName ) continue;
312 0 : SdrObjListIter aIter( *pPage, IM_FLAT );
313 0 : while( aIter.IsMore() )
314 : {
315 0 : pObj = aIter.Next();
316 0 : if( GetEntryText(pEntry) == GetObjectName( pObj ) )
317 : {
318 0 : if( isAltText )
319 0 : return pObj->GetTitle();
320 : else
321 0 : return pObj->GetDescription();
322 : }
323 : }
324 0 : }
325 0 : return OUString();
326 :
327 : }
328 :
329 0 : OUString SdPageObjsTLB::GetEntryAltText( SvTreeListEntry* pEntry ) const
330 : {
331 0 : return getAltLongDescText( pEntry, sal_True );
332 : }
333 :
334 0 : OUString SdPageObjsTLB::GetEntryLongDescription( SvTreeListEntry* pEntry ) const
335 : {
336 0 : return getAltLongDescText( pEntry, sal_False);
337 : }
338 :
339 0 : void SdPageObjsTLB::MarkCurEntry( const OUString& rName )
340 : {
341 :
342 0 : if (!rName.isEmpty())
343 : {
344 0 : SvTreeListEntry* pCurEntry =GetCurEntry();
345 0 : SvTreeListEntry* pEntry =NULL;
346 0 : OUString aTmp1;
347 0 : OUString aTmp2;
348 :
349 0 : if( GetParent(pCurEntry)==NULL )
350 : {
351 0 : aTmp1 = GetEntryText( pCurEntry );
352 0 : for( pEntry = First(); pEntry ; pEntry = Next( pEntry ) )
353 : {
354 0 : if(GetParent( pEntry )==NULL)
355 0 : continue;
356 0 : aTmp2 = GetEntryText( GetParent( pEntry ));
357 0 : if( aTmp1 != aTmp2)
358 : {
359 : // IA2 CWS. MT: Removed in SvTreeListEntry for now - only used in Sw/Sd/ScContentLBoxString, they should decide if they need this
360 0 : pEntry->SetMarked(false);
361 : }
362 : }
363 : }
364 : else
365 : {
366 0 : for( pEntry = First(); pEntry ; pEntry = Next( pEntry ) )
367 : {
368 0 : aTmp2 = GetEntryText( pEntry );
369 0 : if( aTmp2 == rName)
370 : {
371 0 : pEntry->SetMarked(true);
372 : }
373 : else
374 : {
375 0 : pEntry->SetMarked(false);
376 : }
377 : }
378 0 : }
379 : }
380 0 : Invalidate();
381 0 : }
382 :
383 0 : void SdPageObjsTLB:: FreshCurEntry()
384 : {
385 0 : SvTreeListEntry* pEntry =NULL;
386 0 : for( pEntry = First(); pEntry ; pEntry = Next( pEntry ) )
387 : {
388 0 : pEntry->SetMarked(false);
389 : }
390 0 : Invalidate();
391 0 : }
392 :
393 0 : void SdPageObjsTLB::InitEntry(SvTreeListEntry* pEntry,
394 : const OUString& rStr, const Image& rImg1, const Image& rImg2, SvLBoxButtonKind eButtonKind)
395 : {
396 0 : sal_uInt16 nColToHilite = 1; //0==Bitmap;1=="Spalte1";2=="Spalte2"
397 0 : SvTreeListBox::InitEntry( pEntry, rStr, rImg1, rImg2, eButtonKind );
398 0 : SvLBoxString* pCol = (SvLBoxString*)pEntry->GetItem( nColToHilite );
399 0 : SvLBoxString* pStr = new SvLBoxString( pEntry, 0, pCol->GetText() );
400 0 : pEntry->ReplaceItem( pStr, nColToHilite );
401 0 : }
402 :
403 0 : void SdPageObjsTLB::SaveExpandedTreeItemState(SvTreeListEntry* pEntry, vector<OUString>& vectTreeItem)
404 : {
405 0 : if (pEntry)
406 : {
407 0 : SvTreeListEntry* pListEntry = pEntry;
408 0 : while (pListEntry)
409 : {
410 0 : if (pListEntry->HasChildren())
411 : {
412 0 : if (IsExpanded(pListEntry))
413 0 : vectTreeItem.push_back(GetEntryText(pListEntry));
414 0 : SvTreeListEntry* pChildEntry = FirstChild(pListEntry);
415 0 : SaveExpandedTreeItemState(pChildEntry, vectTreeItem);
416 : }
417 0 : pListEntry = NextSibling(pListEntry);
418 : }
419 : }
420 0 : }
421 0 : void SdPageObjsTLB::Clear()
422 : {
423 : //Save the expanded tree item
424 0 : if (mbSaveTreeItemState)
425 : {
426 0 : maSelectionEntryText = OUString();
427 0 : maTreeItem.clear();
428 0 : if (GetCurEntry())
429 0 : maSelectionEntryText = GetSelectEntry();
430 0 : SvTreeListEntry* pEntry = FirstChild(NULL);
431 0 : SaveExpandedTreeItemState(pEntry, maTreeItem);
432 : }
433 0 : return SvTreeListBox::Clear();
434 : }
435 :
436 0 : OUString SdPageObjsTLB::GetObjectName(
437 : const SdrObject* pObject,
438 : const bool bCreate) const
439 : {
440 0 : OUString aRet;
441 :
442 0 : if ( pObject )
443 : {
444 0 : aRet = pObject->GetName();
445 :
446 0 : if (aRet.isEmpty() && pObject->ISA(SdrOle2Obj))
447 0 : aRet = static_cast< const SdrOle2Obj* >( pObject )->GetPersistName();
448 : }
449 :
450 0 : if (bCreate
451 0 : && mbShowAllShapes
452 0 : && aRet.isEmpty()
453 0 : && pObject!=NULL)
454 : {
455 0 : aRet = SD_RESSTR(STR_NAVIGATOR_SHAPE_BASE_NAME);
456 0 : aRet = aRet.replaceFirst("%1", OUString::number(pObject->GetOrdNum() + 1));
457 : }
458 :
459 0 : return aRet;
460 : }
461 :
462 : /**
463 : * select a entry in TreeLB
464 : */
465 0 : sal_Bool SdPageObjsTLB::SelectEntry( const OUString& rName )
466 : {
467 0 : sal_Bool bFound = sal_False;
468 :
469 0 : if( !rName.isEmpty() )
470 : {
471 0 : SvTreeListEntry* pEntry = NULL;
472 0 : OUString aTmp;
473 :
474 0 : for( pEntry = First(); pEntry && !bFound; pEntry = Next( pEntry ) )
475 : {
476 0 : aTmp = GetEntryText( pEntry );
477 0 : if( aTmp == rName )
478 : {
479 0 : bFound = sal_True;
480 0 : SetCurEntry( pEntry );
481 : }
482 0 : }
483 : }
484 0 : return( bFound );
485 : }
486 :
487 : /**
488 : * @return true if children of the specified string are selected
489 : */
490 0 : sal_Bool SdPageObjsTLB::HasSelectedChildren( const OUString& rName )
491 : {
492 0 : sal_Bool bFound = sal_False;
493 0 : sal_Bool bChildren = sal_False;
494 :
495 0 : if( !rName.isEmpty() )
496 : {
497 0 : SvTreeListEntry* pEntry = NULL;
498 0 : OUString aTmp;
499 :
500 0 : for( pEntry = First(); pEntry && !bFound; pEntry = Next( pEntry ) )
501 : {
502 0 : aTmp = GetEntryText( pEntry );
503 0 : if( aTmp == rName )
504 : {
505 0 : bFound = sal_True;
506 0 : sal_Bool bExpanded = IsExpanded( pEntry );
507 0 : long nCount = GetChildSelectionCount( pEntry );
508 0 : if( bExpanded && nCount > 0 )
509 0 : bChildren = sal_True;
510 : }
511 0 : }
512 : }
513 0 : return( bChildren );
514 : }
515 :
516 :
517 : /**
518 : * Fill TreeLB with pages and objects
519 : */
520 0 : void SdPageObjsTLB::Fill( const SdDrawDocument* pInDoc, sal_Bool bAllPages,
521 : const OUString& rDocName)
522 : {
523 0 : OUString aSelection;
524 0 : if( GetSelectionCount() > 0 )
525 : {
526 0 : aSelection = GetSelectEntry();
527 0 : Clear();
528 : }
529 :
530 0 : mpDoc = pInDoc;
531 0 : maDocName = rDocName;
532 0 : mbShowAllPages = (bAllPages == sal_True);
533 0 : mpMedium = NULL;
534 :
535 0 : SdPage* pPage = NULL;
536 :
537 0 : IconProvider aIconProvider;
538 :
539 : // first insert all pages including objects
540 0 : sal_uInt16 nPage = 0;
541 0 : const sal_uInt16 nMaxPages = mpDoc->GetPageCount();
542 :
543 0 : while( nPage < nMaxPages )
544 : {
545 0 : pPage = (SdPage*) mpDoc->GetPage( nPage );
546 0 : if( (mbShowAllPages || pPage->GetPageKind() == PK_STANDARD)
547 0 : && !(pPage->GetPageKind()==PK_HANDOUT) ) //#94954# never list the normal handout page ( handout-masterpage is used instead )
548 : {
549 0 : bool bPageExluded = pPage->IsExcluded();
550 :
551 0 : bool bPageBelongsToShow = PageBelongsToCurrentShow (pPage);
552 0 : bPageExluded |= !bPageBelongsToShow;
553 :
554 0 : AddShapeList(*pPage, NULL, pPage->GetName(), bPageExluded, NULL, aIconProvider);
555 : }
556 0 : nPage++;
557 : }
558 :
559 : // then insert all master pages including objects
560 0 : if( mbShowAllPages )
561 : {
562 0 : nPage = 0;
563 0 : const sal_uInt16 nMaxMasterPages = mpDoc->GetMasterPageCount();
564 :
565 0 : while( nPage < nMaxMasterPages )
566 : {
567 0 : pPage = (SdPage*) mpDoc->GetMasterPage( nPage );
568 0 : AddShapeList(*pPage, NULL, pPage->GetName(), false, NULL, aIconProvider);
569 0 : nPage++;
570 : }
571 : }
572 0 : if( !aSelection.isEmpty() )
573 0 : SelectEntry( aSelection );
574 0 : else if (mbSaveTreeItemState && !maSelectionEntryText.isEmpty())
575 : {
576 0 : SelectEntry(maSelectionEntryText);
577 0 : }
578 0 : }
579 :
580 : /**
581 : * We insert only the first entry. Children are created on demand.
582 : */
583 0 : void SdPageObjsTLB::Fill( const SdDrawDocument* pInDoc, SfxMedium* pInMedium,
584 : const OUString& rDocName )
585 : {
586 0 : mpDoc = pInDoc;
587 :
588 : // this object now owns the Medium
589 0 : mpMedium = pInMedium;
590 0 : maDocName = rDocName;
591 :
592 0 : Image aImgDocOpen=Image( BitmapEx( SdResId( BMP_DOC_OPEN ) ) );
593 0 : Image aImgDocClosed=Image( BitmapEx( SdResId( BMP_DOC_CLOSED ) ) );
594 :
595 : // insert document name
596 : InsertEntry( maDocName, aImgDocOpen, aImgDocClosed, NULL, true, TREELIST_APPEND,
597 : reinterpret_cast< void* >( 1 )
598 0 : );
599 0 : }
600 :
601 :
602 :
603 :
604 0 : void SdPageObjsTLB::AddShapeList (
605 : const SdrObjList& rList,
606 : SdrObject* pShape,
607 : const OUString& rsName,
608 : const bool bIsExcluded,
609 : SvTreeListEntry* pParentEntry,
610 : const IconProvider& rIconProvider)
611 : {
612 0 : Image aIcon (rIconProvider.maImgPage);
613 0 : if (bIsExcluded)
614 0 : aIcon = rIconProvider.maImgPageExcl;
615 0 : else if (pShape != NULL)
616 0 : aIcon = rIconProvider.maImgGroup;
617 :
618 0 : void* pUserData (reinterpret_cast<void*>(1));
619 0 : if (pShape != NULL)
620 0 : pUserData = pShape;
621 :
622 : SvTreeListEntry* pEntry = InsertEntry(
623 : rsName,
624 : aIcon,
625 : aIcon,
626 : pParentEntry,
627 : false,
628 : TREELIST_APPEND,
629 0 : pUserData);
630 :
631 : SdrObjListIter aIter(
632 : rList,
633 0 : !rList.HasObjectNavigationOrder() /* use navigation order, if available */,
634 : IM_FLAT,
635 0 : false /*not reverse*/);
636 :
637 0 : sal_Bool bMarked=sal_False;
638 0 : if(bisInSdNavigatorWin)
639 : {
640 0 : Window* pWindow=NULL;
641 0 : SdNavigatorWin* pSdNavigatorWin=NULL;
642 0 : sd::DrawDocShell* pSdDrawDocShell = NULL;
643 0 : if(pEntry)
644 0 : pWindow=(Window*)GetParent(pEntry);
645 0 : if(pWindow)
646 0 : pSdNavigatorWin = (SdNavigatorWin*)pWindow;
647 0 : if( pSdNavigatorWin )
648 0 : pSdDrawDocShell = pSdNavigatorWin->GetDrawDocShell(mpDoc);
649 0 : if(pSdDrawDocShell)
650 0 : bMarked=pSdDrawDocShell->IsMarked(pShape);
651 0 : if(pEntry)
652 : {
653 0 : if(bMarked)
654 0 : pEntry->SetMarked(true);
655 : else
656 0 : pEntry->SetMarked(false);
657 : }
658 : }
659 0 : while( aIter.IsMore() )
660 : {
661 0 : SdrObject* pObj = aIter.Next();
662 : OSL_ASSERT(pObj!=NULL);
663 :
664 : // Get the shape name.
665 0 : OUString aStr (GetObjectName( pObj ) );
666 :
667 0 : if( !aStr.isEmpty() )
668 : {
669 0 : if( pObj->GetObjInventor() == SdrInventor && pObj->GetObjIdentifier() == OBJ_OLE2 )
670 : {
671 : SvTreeListEntry *pNewEntry = InsertEntry(
672 : aStr,
673 : maImgOle,
674 : maImgOle,
675 : pEntry,
676 : false,
677 : TREELIST_APPEND,
678 : pObj
679 0 : );
680 :
681 0 : if(bisInSdNavigatorWin)
682 : {
683 0 : Window* pWindow=NULL;
684 0 : SdNavigatorWin* pSdNavigatorWin=NULL;
685 0 : sd::DrawDocShell* pSdDrawDocShell = NULL;
686 0 : if(pNewEntry)
687 0 : pWindow=(Window*)GetParent(pNewEntry);
688 0 : if(pWindow)
689 0 : pSdNavigatorWin = (SdNavigatorWin*)pWindow;
690 0 : if( pSdNavigatorWin )
691 0 : pSdDrawDocShell = pSdNavigatorWin->GetDrawDocShell(mpDoc);
692 0 : if(pSdDrawDocShell)
693 0 : bMarked=pSdDrawDocShell->IsMarked((SdrObject*)pObj);
694 0 : if(pNewEntry)
695 : {
696 0 : if(bMarked)
697 0 : pNewEntry->SetMarked(true);
698 : else
699 0 : pNewEntry->SetMarked(false);
700 : }
701 : }
702 : }
703 0 : else if( pObj->GetObjInventor() == SdrInventor && pObj->GetObjIdentifier() == OBJ_GRAF )
704 : {
705 : SvTreeListEntry *pNewEntry = InsertEntry(
706 : aStr,
707 : maImgGraphic,
708 : maImgGraphic,
709 : pEntry,
710 : false,
711 : TREELIST_APPEND,
712 : pObj
713 0 : );
714 :
715 0 : if(bisInSdNavigatorWin)
716 : {
717 0 : Window* pWindow=NULL;
718 0 : SdNavigatorWin* pSdNavigatorWin=NULL;
719 0 : sd::DrawDocShell* pSdDrawDocShell = NULL;
720 0 : if(pNewEntry)
721 0 : pWindow=(Window*)GetParent(pNewEntry);
722 0 : if(pWindow)
723 0 : pSdNavigatorWin = (SdNavigatorWin*)pWindow;
724 0 : if( pSdNavigatorWin )
725 0 : pSdDrawDocShell = pSdNavigatorWin->GetDrawDocShell(mpDoc);
726 0 : if(pSdDrawDocShell)
727 0 : bMarked=pSdDrawDocShell->IsMarked((SdrObject*)pObj);
728 0 : if(pNewEntry)
729 : {
730 0 : if(bMarked)
731 : {
732 0 : pNewEntry->SetMarked(true);
733 : }
734 : else
735 : {
736 0 : pNewEntry->SetMarked(false);
737 : }
738 : }
739 : }
740 : }
741 0 : else if (pObj->IsGroupObject())
742 : {
743 : AddShapeList(
744 0 : *pObj->GetSubList(),
745 : pObj,
746 : aStr,
747 : false,
748 : pEntry,
749 : rIconProvider
750 0 : );
751 : }
752 : else
753 : {
754 : SvTreeListEntry *pNewEntry = InsertEntry(
755 : aStr,
756 : rIconProvider.maImgObjects,
757 : rIconProvider.maImgObjects,
758 : pEntry,
759 : false,
760 : TREELIST_APPEND,
761 : pObj
762 0 : );
763 :
764 0 : if(bisInSdNavigatorWin)
765 : {
766 0 : Window* pWindow=NULL;
767 0 : SdNavigatorWin* pSdNavigatorWin=NULL;
768 0 : sd::DrawDocShell* pSdDrawDocShell = NULL;
769 0 : if(pNewEntry)
770 0 : pWindow=(Window*)GetParent(pNewEntry);
771 0 : if(pWindow)
772 0 : pSdNavigatorWin = (SdNavigatorWin*)pWindow;
773 0 : if( pSdNavigatorWin )
774 0 : pSdDrawDocShell = pSdNavigatorWin->GetDrawDocShell(mpDoc);
775 0 : if(pSdDrawDocShell)
776 0 : bMarked=pSdDrawDocShell->IsMarked((SdrObject*)pObj);
777 0 : if(pNewEntry)
778 : {
779 0 : if(bMarked)
780 : {
781 0 : pNewEntry->SetMarked(true);
782 : }
783 : else
784 : {
785 0 : pNewEntry->SetMarked(false);
786 : }
787 : }
788 : }
789 : }
790 : }
791 0 : }
792 :
793 0 : if( pEntry->HasChildren() )
794 : {
795 : SetExpandedEntryBmp(
796 : pEntry,
797 0 : bIsExcluded ? rIconProvider.maImgPageObjsExcl : rIconProvider.maImgPageObjs);
798 : SetCollapsedEntryBmp(
799 : pEntry,
800 0 : bIsExcluded ? rIconProvider.maImgPageObjsExcl : rIconProvider.maImgPageObjs);
801 0 : if (mbSaveTreeItemState)
802 : {
803 0 : vector<OUString>::iterator iteStart = maTreeItem.begin();
804 0 : while (iteStart != maTreeItem.end())
805 : {
806 0 : OUString strEntry = GetEntryText(pEntry);
807 0 : if (*iteStart == strEntry)
808 : {
809 0 : Expand( pEntry );
810 0 : break;
811 : }
812 0 : ++iteStart;
813 0 : }
814 : }
815 : else
816 0 : Expand( pEntry );
817 0 : }
818 0 : }
819 :
820 :
821 :
822 :
823 0 : void SdPageObjsTLB::SetShowAllShapes (
824 : const bool bShowAllShapes,
825 : const bool bFillList)
826 : {
827 0 : mbShowAllShapes = bShowAllShapes;
828 0 : if (bFillList)
829 : {
830 0 : if (mpMedium == NULL)
831 0 : Fill(mpDoc, mbShowAllPages, maDocName);
832 : else
833 0 : Fill(mpDoc, mpMedium, maDocName);
834 : }
835 0 : }
836 :
837 :
838 :
839 :
840 0 : bool SdPageObjsTLB::GetShowAllShapes (void) const
841 : {
842 0 : return mbShowAllShapes;
843 : }
844 :
845 :
846 :
847 :
848 : /**
849 : * Checks if the pages (PK_STANDARD) of a doc and the objects on the pages
850 : * are identical to the TreeLB.
851 : * If a doc is provided, this will be the used doc (important by more than
852 : * one document).
853 : */
854 0 : sal_Bool SdPageObjsTLB::IsEqualToDoc( const SdDrawDocument* pInDoc )
855 : {
856 0 : if( pInDoc )
857 0 : mpDoc = pInDoc;
858 :
859 0 : if( !mpDoc )
860 0 : return( sal_False );
861 :
862 0 : SdrObject* pObj = NULL;
863 0 : SdPage* pPage = NULL;
864 0 : SvTreeListEntry* pEntry = First();
865 0 : OUString aName;
866 :
867 : // compare all pages including the objects
868 0 : sal_uInt16 nPage = 0;
869 0 : const sal_uInt16 nMaxPages = mpDoc->GetPageCount();
870 :
871 0 : while( nPage < nMaxPages )
872 : {
873 0 : pPage = (SdPage*) mpDoc->GetPage( nPage );
874 0 : if( pPage->GetPageKind() == PK_STANDARD )
875 : {
876 0 : if( !pEntry )
877 0 : return( sal_False );
878 0 : aName = GetEntryText( pEntry );
879 :
880 0 : if( pPage->GetName() != aName )
881 0 : return( sal_False );
882 :
883 0 : pEntry = Next( pEntry );
884 :
885 : SdrObjListIter aIter(
886 : *pPage,
887 0 : !pPage->HasObjectNavigationOrder() /* use navigation order, if available */,
888 0 : IM_DEEPWITHGROUPS );
889 :
890 0 : while( aIter.IsMore() )
891 : {
892 0 : pObj = aIter.Next();
893 :
894 0 : const OUString aObjectName( GetObjectName( pObj ) );
895 :
896 0 : if( !aObjectName.isEmpty() )
897 : {
898 0 : if( !pEntry )
899 0 : return( sal_False );
900 :
901 0 : aName = GetEntryText( pEntry );
902 :
903 0 : if( aObjectName != aName )
904 0 : return( sal_False );
905 :
906 0 : pEntry = Next( pEntry );
907 : }
908 0 : }
909 : }
910 0 : nPage++;
911 : }
912 : // If there are still entries in the listbox,
913 : // then objects (with names) or pages were deleted
914 0 : return( !pEntry );
915 : }
916 :
917 : /**
918 : * @return selected string
919 : */
920 0 : OUString SdPageObjsTLB::GetSelectEntry()
921 : {
922 0 : return( GetEntryText( GetCurEntry() ) );
923 : }
924 :
925 0 : std::vector<OUString> SdPageObjsTLB::GetSelectEntryList( const sal_uInt16 nDepth ) const
926 : {
927 0 : std::vector<OUString> aEntries;
928 0 : SvTreeListEntry* pEntry = FirstSelected();
929 :
930 0 : while( pEntry )
931 : {
932 0 : sal_uInt16 nListDepth = GetModel()->GetDepth( pEntry );
933 :
934 0 : if( nListDepth == nDepth )
935 0 : aEntries.push_back(GetEntryText(pEntry));
936 :
937 0 : pEntry = NextSelected( pEntry );
938 : }
939 :
940 0 : return aEntries;
941 : }
942 :
943 : /**
944 : * Entries are inserted only by request (double click)
945 : */
946 0 : void SdPageObjsTLB::RequestingChildren( SvTreeListEntry* pFileEntry )
947 : {
948 0 : if( !pFileEntry->HasChildren() )
949 : {
950 0 : if( GetBookmarkDoc() )
951 : {
952 0 : SdrObject* pObj = NULL;
953 0 : SdPage* pPage = NULL;
954 0 : SvTreeListEntry* pPageEntry = NULL;
955 :
956 0 : Image aImgPage = Image( BitmapEx( SdResId( BMP_PAGE ) ) );
957 0 : Image aImgPageObjs = Image( BitmapEx( SdResId( BMP_PAGEOBJS ) ) );
958 0 : Image aImgObjects = Image( BitmapEx( SdResId( BMP_OBJECTS ) ) );
959 :
960 : // document name already inserted
961 :
962 : // only insert all "normal" ? slides with objects
963 0 : sal_uInt16 nPage = 0;
964 0 : const sal_uInt16 nMaxPages = mpBookmarkDoc->GetPageCount();
965 :
966 0 : while( nPage < nMaxPages )
967 : {
968 0 : pPage = (SdPage*) mpBookmarkDoc->GetPage( nPage );
969 0 : if( pPage->GetPageKind() == PK_STANDARD )
970 : {
971 0 : pPageEntry = InsertEntry( pPage->GetName(),
972 : aImgPage,
973 : aImgPage,
974 : pFileEntry,
975 : false,
976 : TREELIST_APPEND,
977 0 : reinterpret_cast< void* >( 1 ) );
978 :
979 0 : SdrObjListIter aIter( *pPage, IM_DEEPWITHGROUPS );
980 :
981 0 : while( aIter.IsMore() )
982 : {
983 0 : pObj = aIter.Next();
984 0 : OUString aStr( GetObjectName( pObj ) );
985 0 : if( !aStr.isEmpty() )
986 : {
987 0 : if( pObj->GetObjInventor() == SdrInventor && pObj->GetObjIdentifier() == OBJ_OLE2 )
988 : {
989 0 : InsertEntry(aStr, maImgOle, maImgOle, pPageEntry);
990 : }
991 0 : else if( pObj->GetObjInventor() == SdrInventor && pObj->GetObjIdentifier() == OBJ_GRAF )
992 : {
993 0 : InsertEntry(aStr, maImgGraphic, maImgGraphic, pPageEntry);
994 : }
995 : else
996 : {
997 0 : InsertEntry(aStr, aImgObjects, aImgObjects, pPageEntry);
998 : }
999 : }
1000 0 : }
1001 0 : if( pPageEntry->HasChildren() )
1002 : {
1003 0 : SetExpandedEntryBmp( pPageEntry, aImgPageObjs );
1004 0 : SetCollapsedEntryBmp( pPageEntry, aImgPageObjs );
1005 0 : }
1006 : }
1007 0 : nPage++;
1008 0 : }
1009 : }
1010 : }
1011 : else
1012 0 : SvTreeListBox::RequestingChildren( pFileEntry );
1013 0 : }
1014 :
1015 : /**
1016 : * Checks if it is a draw file and opens the BookmarkDoc depending of
1017 : * the provided Docs
1018 : */
1019 0 : SdDrawDocument* SdPageObjsTLB::GetBookmarkDoc(SfxMedium* pMed)
1020 : {
1021 0 : if (
1022 0 : !mpBookmarkDoc ||
1023 0 : (pMed && (!mpOwnMedium || mpOwnMedium->GetName() != pMed->GetName()))
1024 : )
1025 : {
1026 : // create a new BookmarkDoc if now one exists or if a new Medium is provided
1027 0 : if (mpOwnMedium != pMed)
1028 : {
1029 0 : CloseBookmarkDoc();
1030 : }
1031 :
1032 0 : if (pMed)
1033 : {
1034 : // it looks that it is undefined if a Medium was set by Fill() already
1035 : DBG_ASSERT( !mpMedium, "SfxMedium confusion!" );
1036 0 : delete mpMedium;
1037 0 : mpMedium = NULL;
1038 :
1039 : // take over this Medium (currently used only be Navigator)
1040 0 : mpOwnMedium = pMed;
1041 : }
1042 :
1043 : DBG_ASSERT( mpMedium || pMed, "No SfxMedium provided!" );
1044 :
1045 0 : if( pMed )
1046 : {
1047 : // in this mode the document is also owned and controlled by this instance
1048 0 : mxBookmarkDocShRef = new ::sd::DrawDocShell(SFX_CREATE_MODE_STANDARD, sal_True);
1049 0 : if (mxBookmarkDocShRef->DoLoad(pMed))
1050 0 : mpBookmarkDoc = mxBookmarkDocShRef->GetDoc();
1051 : else
1052 0 : mpBookmarkDoc = NULL;
1053 : }
1054 0 : else if ( mpMedium )
1055 : // in this mode the document is owned and controlled by the SdDrawDocument
1056 : // it can be released by calling the corresponding CloseBookmarkDoc method
1057 : // successful creation of a document makes this the owner of the medium
1058 0 : mpBookmarkDoc = ((SdDrawDocument*) mpDoc)->OpenBookmarkDoc(*mpMedium);
1059 :
1060 0 : if ( !mpBookmarkDoc )
1061 : {
1062 0 : ErrorBox aErrorBox( this, WB_OK, SD_RESSTR( STR_READ_DATA_ERROR ) );
1063 0 : aErrorBox.Execute();
1064 0 : mpMedium = 0; //On failure the SfxMedium is invalid
1065 : }
1066 : }
1067 :
1068 0 : return( mpBookmarkDoc );
1069 : }
1070 :
1071 : /**
1072 : * Close and delete bookmark document
1073 : */
1074 0 : void SdPageObjsTLB::CloseBookmarkDoc()
1075 : {
1076 0 : if (mxBookmarkDocShRef.Is())
1077 : {
1078 0 : mxBookmarkDocShRef->DoClose();
1079 0 : mxBookmarkDocShRef.Clear();
1080 :
1081 : // Medium is owned by document, so it's destroyed already
1082 0 : mpOwnMedium = 0;
1083 : }
1084 0 : else if ( mpBookmarkDoc )
1085 : {
1086 : DBG_ASSERT( !mpOwnMedium, "SfxMedium confusion!" );
1087 0 : if ( mpDoc )
1088 : {
1089 : // The document owns the Medium, so the Medium will be invalid after closing the document
1090 0 : ((SdDrawDocument*) mpDoc)->CloseBookmarkDoc();
1091 0 : mpMedium = 0;
1092 : }
1093 : }
1094 : else
1095 : {
1096 : // perhaps mpOwnMedium provided, but no successful creation of BookmarkDoc
1097 0 : delete mpOwnMedium;
1098 0 : mpOwnMedium = NULL;
1099 : }
1100 :
1101 0 : mpBookmarkDoc = NULL;
1102 0 : }
1103 :
1104 0 : void SdPageObjsTLB::SelectHdl()
1105 : {
1106 0 : SvTreeListEntry* pEntry = FirstSelected();
1107 :
1108 0 : mbLinkableSelected = sal_True;
1109 :
1110 0 : while( pEntry && mbLinkableSelected )
1111 : {
1112 0 : if( NULL == pEntry->GetUserData() )
1113 0 : mbLinkableSelected = sal_False;
1114 :
1115 0 : pEntry = NextSelected( pEntry );
1116 : }
1117 :
1118 0 : SvTreeListBox::SelectHdl();
1119 0 : }
1120 :
1121 : /**
1122 : * Overloads RETURN with the functionality of DoubleClick
1123 : */
1124 0 : void SdPageObjsTLB::KeyInput( const KeyEvent& rKEvt )
1125 : {
1126 0 : if( rKEvt.GetKeyCode().GetCode() == KEY_RETURN )
1127 : {
1128 : // commented code from svtools/source/contnr/svimpbox.cxx
1129 0 : SvTreeListEntry* pCursor = GetCurEntry();
1130 0 : if( pCursor->HasChildren() || pCursor->HasChildrenOnDemand() )
1131 : {
1132 0 : if( IsExpanded( pCursor ) )
1133 0 : Collapse( pCursor );
1134 : else
1135 0 : Expand( pCursor );
1136 : }
1137 :
1138 0 : DoubleClickHdl();
1139 : }
1140 0 : else if (rKEvt.GetKeyCode().GetCode() == KEY_SPACE)
1141 : {
1142 0 : if(bisInSdNavigatorWin)
1143 : {
1144 0 : sal_Bool bMarked=sal_False;
1145 0 : SvTreeListEntry* pNewEntry = GetCurEntry();
1146 0 : if (!pNewEntry)
1147 0 : return;
1148 0 : SvTreeListEntry* pParentEntry = GetParent(pNewEntry);
1149 0 : if (!pParentEntry)
1150 0 : return;
1151 0 : OUString aStr(GetSelectEntry());
1152 0 : SdNavigatorWin* pSdNavigatorWin = (SdNavigatorWin*)pParentEntry;
1153 0 : sd::DrawDocShell* pSdDrawDocShell = pSdNavigatorWin->GetDrawDocShell(mpDoc);
1154 0 : if (pSdDrawDocShell)
1155 : {
1156 0 : pSdDrawDocShell->GotoTreeBookmark(aStr);
1157 0 : bMarked=pSdDrawDocShell->GetObjectIsmarked(aStr);
1158 : }
1159 0 : pNewEntry->SetMarked(bMarked);
1160 0 : Invalidate();
1161 : }
1162 : }
1163 : else
1164 0 : SvTreeListBox::KeyInput( rKEvt );
1165 : }
1166 :
1167 : /**
1168 : * StartDrag-Request
1169 : */
1170 0 : void SdPageObjsTLB::StartDrag( sal_Int8 nAction, const Point& rPosPixel)
1171 : {
1172 : (void)nAction;
1173 : (void)rPosPixel;
1174 :
1175 0 : SdNavigatorWin* pNavWin = NULL;
1176 0 : SvTreeListEntry* pEntry = GetEntry(rPosPixel);
1177 :
1178 0 : if( mpFrame->HasChildWindow( SID_NAVIGATOR ) )
1179 0 : pNavWin = (SdNavigatorWin*) ( mpFrame->GetChildWindow( SID_NAVIGATOR )->GetContextWindow( SD_MOD() ) );
1180 :
1181 0 : if (pEntry != NULL
1182 0 : && pNavWin !=NULL
1183 0 : && pNavWin == mpParent
1184 0 : && pNavWin->GetNavigatorDragType() != NAVIGATOR_DRAGTYPE_NONE )
1185 : {
1186 : // Mark only the children of the page under the mouse as drop
1187 : // targets. This prevents moving shapes from one page to another.
1188 :
1189 : // Select all entries and disable them as drop targets.
1190 0 : SetSelectionMode(MULTIPLE_SELECTION);
1191 0 : SetCursor(NULL, false);
1192 0 : SelectAll(true, false);
1193 0 : EnableSelectionAsDropTarget(false, true);
1194 :
1195 : // Enable only the entries as drop targets that are children of the
1196 : // page under the mouse.
1197 0 : SvTreeListEntry* pParent = GetRootLevelParent(pEntry);
1198 0 : if (pParent != NULL)
1199 : {
1200 0 : SelectAll(false, false);
1201 0 : Select(pParent, true);
1202 : // for (SvTreeListEntry*pChild=FirstChild(pParent); pChild!=NULL; pChild=NextSibling(pChild))
1203 : // Select(pChild, sal_True);
1204 0 : EnableSelectionAsDropTarget(true, true);//sal_False);
1205 : }
1206 :
1207 : // Set selection back to the entry under the mouse.
1208 0 : SelectAll(false, false);
1209 0 : SetSelectionMode(SINGLE_SELECTION);
1210 0 : Select(pEntry, true);
1211 :
1212 : // We can delete the Navigator from ExecuteDrag (when switching to
1213 : // another document type), but that would kill the StarView MouseMove
1214 : // Handler which is calling Command().
1215 : // For this reason, Drag&Drop is asynchronous.
1216 0 : Application::PostUserEvent( STATIC_LINK( this, SdPageObjsTLB, ExecDragHdl ) );
1217 : }
1218 0 : }
1219 :
1220 : /**
1221 : * Begin drag
1222 : */
1223 0 : void SdPageObjsTLB::DoDrag()
1224 : {
1225 0 : mpDropNavWin = ( mpFrame->HasChildWindow( SID_NAVIGATOR ) ) ?
1226 0 : (SdNavigatorWin*)( mpFrame->GetChildWindow( SID_NAVIGATOR )->GetContextWindow( SD_MOD() ) ) :
1227 0 : NULL;
1228 :
1229 0 : if( mpDropNavWin )
1230 : {
1231 0 : ::sd::DrawDocShell* pDocShell = mpDoc->GetDocSh();
1232 0 : OUString aURL = INetURLObject( pDocShell->GetMedium()->GetPhysicalName(), INET_PROT_FILE ).GetMainURL( INetURLObject::NO_DECODE );
1233 0 : NavigatorDragType eDragType = mpDropNavWin->GetNavigatorDragType();
1234 :
1235 0 : aURL += "#" + GetSelectEntry();
1236 :
1237 0 : INetBookmark aBookmark( aURL, GetSelectEntry() );
1238 0 : sal_Int8 nDNDActions = DND_ACTION_COPYMOVE;
1239 :
1240 0 : if( eDragType == NAVIGATOR_DRAGTYPE_LINK )
1241 0 : nDNDActions = DND_ACTION_LINK; // Either COPY *or* LINK, never both!
1242 0 : else if (mpDoc->GetSdPageCount(PK_STANDARD) == 1)
1243 : {
1244 : // Can not move away the last slide in a document.
1245 0 : nDNDActions = DND_ACTION_COPY;
1246 : }
1247 :
1248 0 : SvTreeListBox::ReleaseMouse();
1249 :
1250 0 : bIsInDrag = sal_True;
1251 :
1252 : SvLBoxDDInfo aDDInfo;
1253 0 : memset(&aDDInfo,0,sizeof(SvLBoxDDInfo));
1254 0 : aDDInfo.pApp = GetpApp();
1255 0 : aDDInfo.pSource = this;
1256 : // aDDInfo.pDDStartEntry = pEntry;
1257 0 : ::com::sun::star::uno::Sequence<sal_Int8> aSequence (sizeof(SvLBoxDDInfo));
1258 0 : memcpy(aSequence.getArray(), (sal_Char*)&aDDInfo, sizeof(SvLBoxDDInfo));
1259 0 : ::com::sun::star::uno::Any aTreeListBoxData (aSequence);
1260 :
1261 : // object is destroyed by internal reference mechanism
1262 : SdTransferable* pTransferable = new SdPageObjsTLB::SdPageObjsTransferable(
1263 0 : *this, aBookmark, *pDocShell, eDragType, aTreeListBoxData);
1264 :
1265 : // Get the view.
1266 0 : ::sd::ViewShell* pViewShell = GetViewShellForDocShell(*pDocShell);
1267 0 : if (pViewShell == NULL)
1268 : {
1269 : OSL_ASSERT(pViewShell!=NULL);
1270 0 : return;
1271 : }
1272 0 : sd::View* pView = pViewShell->GetView();
1273 0 : if (pView == NULL)
1274 : {
1275 : OSL_ASSERT(pView!=NULL);
1276 0 : return;
1277 : }
1278 :
1279 0 : SdrObject* pObject = NULL;
1280 0 : void* pUserData = GetCurEntry()->GetUserData();
1281 0 : if (pUserData != NULL && pUserData != (void*)1)
1282 0 : pObject = reinterpret_cast<SdrObject*>(pUserData);
1283 0 : if (pObject != NULL)
1284 : {
1285 : // For shapes without a user supplied name (the automatically
1286 : // created name does not count), a different drag and drop technique
1287 : // is used.
1288 0 : if (GetObjectName(pObject, false).isEmpty())
1289 : {
1290 0 : AddShapeToTransferable(*pTransferable, *pObject);
1291 0 : pTransferable->SetView(pView);
1292 0 : SD_MOD()->pTransferDrag = pTransferable;
1293 : }
1294 :
1295 : // Unnamed shapes have to be selected to be recognized by the
1296 : // current drop implementation. In order to have a consistent
1297 : // behaviour for all shapes, every shape that is to be dragged is
1298 : // selected first.
1299 0 : SdrPageView* pPageView = pView->GetSdrPageView();
1300 0 : pView->UnmarkAllObj(pPageView);
1301 0 : pView->MarkObj(pObject, pPageView);
1302 : }
1303 : else
1304 : {
1305 0 : pTransferable->SetView(pView);
1306 0 : SD_MOD()->pTransferDrag = pTransferable;
1307 : }
1308 :
1309 0 : pTransferable->StartDrag( this, nDNDActions );
1310 : }
1311 : }
1312 :
1313 0 : void SdPageObjsTLB::OnDragFinished( sal_uInt8 )
1314 : {
1315 0 : if( mpFrame->HasChildWindow( SID_NAVIGATOR ) )
1316 : {
1317 0 : SdNavigatorWin* pNewNavWin = (SdNavigatorWin*) ( mpFrame->GetChildWindow( SID_NAVIGATOR )->GetContextWindow( SD_MOD() ) );
1318 :
1319 0 : if( mpDropNavWin == pNewNavWin)
1320 : {
1321 0 : MouseEvent aMEvt( mpDropNavWin->GetPointerPosPixel() );
1322 0 : SvTreeListBox::MouseButtonUp( aMEvt );
1323 : }
1324 : }
1325 :
1326 0 : mpDropNavWin = NULL;
1327 0 : bIsInDrag = sal_False;
1328 0 : }
1329 :
1330 : /**
1331 : * AcceptDrop-Event
1332 : */
1333 0 : sal_Int8 SdPageObjsTLB::AcceptDrop (const AcceptDropEvent& rEvent)
1334 : {
1335 0 : sal_Int8 nResult (DND_ACTION_NONE);
1336 :
1337 0 : if ( !bIsInDrag && IsDropFormatSupported( FORMAT_FILE ) )
1338 : {
1339 0 : nResult = rEvent.mnAction;
1340 : }
1341 : else
1342 : {
1343 0 : SvTreeListEntry* pEntry = GetDropTarget(rEvent.maPosPixel);
1344 0 : if (rEvent.mbLeaving || !CheckDragAndDropMode( this, rEvent.mnAction ))
1345 : {
1346 0 : ImplShowTargetEmphasis( pTargetEntry, false );
1347 : }
1348 0 : else if( !GetDragDropMode() )
1349 : {
1350 : SAL_WARN( "sc.ui", "SdPageObjsTLB::AcceptDrop(): no target" );
1351 : }
1352 0 : else if (IsDropAllowed(pEntry))
1353 : {
1354 0 : nResult = DND_ACTION_MOVE;
1355 :
1356 : // Draw emphasis.
1357 0 : if (pEntry != pTargetEntry || !(nImpFlags & SVLBOX_TARGEMPH_VIS))
1358 : {
1359 0 : ImplShowTargetEmphasis( pTargetEntry, false );
1360 0 : pTargetEntry = pEntry;
1361 0 : ImplShowTargetEmphasis( pTargetEntry, true );
1362 : }
1363 : }
1364 : }
1365 :
1366 : // Hide emphasis when there is no valid drop action.
1367 0 : if (nResult == DND_ACTION_NONE)
1368 0 : ImplShowTargetEmphasis(pTargetEntry, false);
1369 :
1370 0 : return nResult;
1371 : }
1372 :
1373 : /**
1374 : * ExecuteDrop-Event
1375 : */
1376 0 : sal_Int8 SdPageObjsTLB::ExecuteDrop( const ExecuteDropEvent& rEvt )
1377 : {
1378 0 : sal_Int8 nRet = DND_ACTION_NONE;
1379 :
1380 : try
1381 : {
1382 0 : if( !bIsInDrag )
1383 : {
1384 0 : SdNavigatorWin* pNavWin = NULL;
1385 0 : sal_uInt16 nId = SID_NAVIGATOR;
1386 :
1387 0 : if( mpFrame->HasChildWindow( nId ) )
1388 0 : pNavWin = (SdNavigatorWin*)( mpFrame->GetChildWindow( nId )->GetContextWindow( SD_MOD() ) );
1389 :
1390 0 : if( pNavWin && ( pNavWin == mpParent ) )
1391 : {
1392 0 : TransferableDataHelper aDataHelper( rEvt.maDropEvent.Transferable );
1393 0 : OUString aFile;
1394 :
1395 0 : if( aDataHelper.GetString( FORMAT_FILE, aFile ) &&
1396 0 : ( (SdNavigatorWin*) mpParent)->InsertFile( aFile ) )
1397 : {
1398 0 : nRet = rEvt.mnAction;
1399 0 : }
1400 : }
1401 : }
1402 : }
1403 0 : catch (com::sun::star::uno::Exception&)
1404 : {
1405 : DBG_UNHANDLED_EXCEPTION();
1406 : }
1407 :
1408 0 : if (nRet == DND_ACTION_NONE)
1409 0 : SvTreeListBox::ExecuteDrop(rEvt, this);
1410 :
1411 :
1412 0 : return nRet;
1413 : }
1414 :
1415 : /**
1416 : * Handler for Dragging
1417 : */
1418 0 : IMPL_STATIC_LINK(SdPageObjsTLB, ExecDragHdl, void*, EMPTYARG)
1419 : {
1420 : // as link, then it is allowed to asynchronous, without ImpMouseMoveMsg on
1421 : // the stack, delete the Navigator
1422 0 : pThis->DoDrag();
1423 0 : return 0;
1424 : }
1425 :
1426 :
1427 0 : bool SdPageObjsTLB::PageBelongsToCurrentShow (const SdPage* pPage) const
1428 : {
1429 : // Return <TRUE/> as default when there is no custom show or when none
1430 : // is used. The page does then belong to the standard show.
1431 0 : bool bBelongsToShow = true;
1432 :
1433 0 : if (mpDoc->getPresentationSettings().mbCustomShow)
1434 : {
1435 : // Get the current custom show.
1436 0 : SdCustomShow* pCustomShow = NULL;
1437 0 : SdCustomShowList* pShowList = const_cast<SdDrawDocument*>(mpDoc)->GetCustomShowList();
1438 0 : if (pShowList != NULL)
1439 : {
1440 0 : sal_uLong nCurrentShowIndex = pShowList->GetCurPos();
1441 0 : pCustomShow = (*pShowList)[nCurrentShowIndex];
1442 : }
1443 :
1444 : // Check whether the given page is part of that custom show.
1445 0 : if (pCustomShow != NULL)
1446 : {
1447 0 : bBelongsToShow = false;
1448 0 : size_t nPageCount = pCustomShow->PagesVector().size();
1449 0 : for (size_t i=0; i<nPageCount && !bBelongsToShow; i++)
1450 0 : if (pPage == pCustomShow->PagesVector()[i])
1451 0 : bBelongsToShow = true;
1452 : }
1453 : }
1454 :
1455 0 : return bBelongsToShow;
1456 : }
1457 :
1458 0 : TriState SdPageObjsTLB::NotifyMoving(
1459 : SvTreeListEntry* pTarget,
1460 : SvTreeListEntry* pEntry,
1461 : SvTreeListEntry*& rpNewParent,
1462 : sal_uLong& rNewChildPos)
1463 : {
1464 0 : SvTreeListEntry* pDestination = pTarget;
1465 0 : while (GetParent(pDestination) != NULL && GetParent(GetParent(pDestination)) != NULL)
1466 0 : pDestination = GetParent(pDestination);
1467 :
1468 0 : SdrObject* pTargetObject = reinterpret_cast<SdrObject*>(pDestination->GetUserData());
1469 0 : SdrObject* pSourceObject = reinterpret_cast<SdrObject*>(pEntry->GetUserData());
1470 0 : if (pSourceObject == reinterpret_cast<SdrObject*>(1))
1471 0 : pSourceObject = NULL;
1472 :
1473 0 : if (pTargetObject != NULL && pSourceObject != NULL)
1474 : {
1475 0 : SdrPage* pObjectList = pSourceObject->GetPage();
1476 0 : if (pObjectList != NULL)
1477 : {
1478 : sal_uInt32 nNewPosition;
1479 0 : if (pTargetObject == reinterpret_cast<SdrObject*>(1))
1480 0 : nNewPosition = 0;
1481 : else
1482 0 : nNewPosition = pTargetObject->GetNavigationPosition() + 1;
1483 0 : pObjectList->SetObjectNavigationPosition(*pSourceObject, nNewPosition);
1484 : }
1485 :
1486 : // Update the tree list.
1487 0 : if (GetParent(pDestination) == NULL)
1488 : {
1489 0 : rpNewParent = pDestination;
1490 0 : rNewChildPos = 0;
1491 : }
1492 : else
1493 : {
1494 0 : rpNewParent = GetParent(pDestination);
1495 0 : rNewChildPos = pModel->GetRelPos(pDestination) + 1;
1496 0 : rNewChildPos += nCurEntrySelPos;
1497 0 : nCurEntrySelPos++;
1498 : }
1499 0 : return TRISTATE_TRUE;
1500 : }
1501 : else
1502 0 : return TRISTATE_FALSE;
1503 : }
1504 :
1505 0 : SvTreeListEntry* SdPageObjsTLB::GetDropTarget (const Point& rLocation)
1506 : {
1507 0 : SvTreeListEntry* pEntry = SvTreeListBox::GetDropTarget(rLocation);
1508 0 : if (pEntry == NULL)
1509 0 : return NULL;
1510 :
1511 0 : if (GetParent(pEntry) == NULL)
1512 : {
1513 : // Use page entry as insertion position.
1514 : }
1515 : else
1516 : {
1517 : // Go to second hierarchy level, i.e. top level shapes,
1518 : // i.e. children of pages.
1519 0 : while (GetParent(pEntry) != NULL && GetParent(GetParent(pEntry)) != NULL)
1520 0 : pEntry = GetParent(pEntry);
1521 :
1522 : // Advance to next sibling.
1523 : SvTreeListEntry* pNext;
1524 0 : sal_uInt16 nDepth (0);
1525 0 : while (pEntry != NULL)
1526 : {
1527 0 : pNext = dynamic_cast<SvTreeListEntry*>(NextVisible(pEntry, &nDepth));
1528 0 : if (pNext != NULL && nDepth > 0 && nDepth!=0xffff)
1529 0 : pEntry = pNext;
1530 : else
1531 : break;
1532 : }
1533 : }
1534 :
1535 0 : return pEntry;
1536 : }
1537 :
1538 :
1539 :
1540 :
1541 0 : bool SdPageObjsTLB::IsDropAllowed (SvTreeListEntry* pEntry)
1542 : {
1543 0 : if (pEntry == NULL)
1544 0 : return false;
1545 :
1546 0 : if ( ! IsDropFormatSupported(SdPageObjsTransferable::GetListBoxDropFormatId()))
1547 0 : return false;
1548 :
1549 0 : if ((pEntry->GetFlags() & SV_ENTRYFLAG_DISABLE_DROP) != 0)
1550 0 : return false;
1551 :
1552 0 : return true;
1553 : }
1554 :
1555 :
1556 :
1557 :
1558 0 : void SdPageObjsTLB::AddShapeToTransferable (
1559 : SdTransferable& rTransferable,
1560 : SdrObject& rObject) const
1561 : {
1562 0 : TransferableObjectDescriptor aObjectDescriptor;
1563 0 : bool bIsDescriptorFillingPending (true);
1564 :
1565 0 : const SdrOle2Obj* pOleObject = dynamic_cast<const SdrOle2Obj*>(&rObject);
1566 0 : if (pOleObject != NULL && pOleObject->GetObjRef().is())
1567 : {
1568 : // If object has no persistence it must be copied as part of the document
1569 : try
1570 : {
1571 0 : uno::Reference< embed::XEmbedPersist > xPersObj (pOleObject->GetObjRef(), uno::UNO_QUERY );
1572 0 : if (xPersObj.is() && xPersObj->hasEntry())
1573 : {
1574 : SvEmbedTransferHelper::FillTransferableObjectDescriptor(
1575 : aObjectDescriptor,
1576 : pOleObject->GetObjRef(),
1577 : pOleObject->GetGraphic(),
1578 0 : pOleObject->GetAspect());
1579 0 : bIsDescriptorFillingPending = false;
1580 0 : }
1581 : }
1582 0 : catch( uno::Exception& )
1583 : {
1584 : }
1585 : }
1586 :
1587 0 : ::sd::DrawDocShell* pDocShell = mpDoc->GetDocSh();
1588 0 : if (bIsDescriptorFillingPending && pDocShell!=NULL)
1589 : {
1590 0 : pDocShell->FillTransferableObjectDescriptor(aObjectDescriptor);
1591 : }
1592 :
1593 0 : Point aDragPos (rObject.GetCurrentBoundRect().Center());
1594 : //Point aDragPos (0,0);
1595 0 : aObjectDescriptor.maDragStartPos = aDragPos;
1596 : // aObjectDescriptor.maSize = GetAllMarkedRect().GetSize();
1597 0 : if (pDocShell != NULL)
1598 0 : aObjectDescriptor.maDisplayName = pDocShell->GetMedium()->GetURLObject().GetURLNoPass();
1599 : else
1600 0 : aObjectDescriptor.maDisplayName = OUString();
1601 0 : aObjectDescriptor.mbCanLink = false;
1602 :
1603 0 : rTransferable.SetStartPos(aDragPos);
1604 0 : rTransferable.SetObjectDescriptor( aObjectDescriptor );
1605 0 : }
1606 :
1607 :
1608 :
1609 :
1610 0 : ::sd::ViewShell* SdPageObjsTLB::GetViewShellForDocShell (::sd::DrawDocShell& rDocShell)
1611 : {
1612 : {
1613 0 : ::sd::ViewShell* pViewShell = rDocShell.GetViewShell();
1614 0 : if (pViewShell != NULL)
1615 0 : return pViewShell;
1616 : }
1617 :
1618 : try
1619 : {
1620 : // Get a component enumeration from the desktop and search it for documents.
1621 0 : uno::Reference<uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext());
1622 :
1623 0 : uno::Reference<frame::XDesktop2> xDesktop = frame::Desktop::create(xContext);
1624 :
1625 0 : uno::Reference<frame::XFramesSupplier> xFrameSupplier (xDesktop, uno::UNO_QUERY);
1626 0 : if ( ! xFrameSupplier.is())
1627 0 : return NULL;
1628 :
1629 0 : uno::Reference<container::XIndexAccess> xFrameAccess (xFrameSupplier->getFrames(), uno::UNO_QUERY);
1630 0 : if ( ! xFrameAccess.is())
1631 0 : return NULL;
1632 :
1633 0 : for (sal_Int32 nIndex=0,nCount=xFrameAccess->getCount(); nIndex<nCount; ++nIndex)
1634 : {
1635 0 : uno::Reference<frame::XFrame> xFrame;
1636 0 : if ( ! (xFrameAccess->getByIndex(nIndex) >>= xFrame))
1637 0 : continue;
1638 :
1639 0 : ::sd::DrawController* pController = dynamic_cast<sd::DrawController*>(xFrame->getController().get());
1640 0 : if (pController == NULL)
1641 0 : continue;
1642 0 : ::sd::ViewShellBase* pBase = pController->GetViewShellBase();
1643 0 : if (pBase == NULL)
1644 0 : continue;
1645 0 : if (pBase->GetDocShell() != &rDocShell)
1646 0 : continue;
1647 :
1648 0 : const ::boost::shared_ptr<sd::ViewShell> pViewShell (pBase->GetMainViewShell());
1649 0 : if (pViewShell)
1650 0 : return pViewShell.get();
1651 0 : }
1652 : }
1653 0 : catch (uno::Exception &)
1654 : {
1655 : // When there is an exception then simply use the default value of
1656 : // bIsEnabled and disable the controls.
1657 : }
1658 0 : return NULL;
1659 : }
1660 :
1661 :
1662 :
1663 :
1664 : //===== IconProvider ==========================================================
1665 :
1666 0 : SdPageObjsTLB::IconProvider::IconProvider (void)
1667 : : maImgPage( BitmapEx( SdResId( BMP_PAGE ) ) ),
1668 : maImgPageExcl( BitmapEx( SdResId( BMP_PAGE_EXCLUDED ) ) ),
1669 : maImgPageObjsExcl( BitmapEx( SdResId( BMP_PAGEOBJS_EXCLUDED ) ) ),
1670 : maImgPageObjs( BitmapEx( SdResId( BMP_PAGEOBJS ) ) ),
1671 : maImgObjects( BitmapEx( SdResId( BMP_OBJECTS ) ) ),
1672 0 : maImgGroup( BitmapEx( SdResId( BMP_GROUP ) ) )
1673 : {
1674 0 : }
1675 :
1676 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|