xref: /aoo41x/main/sd/source/ui/dlg/sdtreelb.cxx (revision 4d7c9de0)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26 
27 #include <sal/types.h>
28 #include <sot/formats.hxx>
29 #include <sot/storage.hxx>
30 #include <vcl/msgbox.hxx>
31 #include <svl/urihelper.hxx>
32 #include <svx/svditer.hxx>
33 #include <sfx2/docfile.hxx>
34 #include <svx/svdoole2.hxx>
35 #include <vcl/svapp.hxx>
36 #include "cusshow.hxx"
37 #include <sfx2/childwin.hxx>
38 
39 #include <sfx2/viewfrm.hxx>
40 
41 #include "strmname.h"
42 #include "sdtreelb.hxx"
43 #include "DrawDocShell.hxx"
44 #include "drawdoc.hxx"
45 #include "sdpage.hxx"
46 #include "sdresid.hxx"
47 #include "navigatr.hxx"
48 #ifndef _SD_CFGID_HXX
49 #include "strings.hrc"
50 #endif
51 #include "res_bmp.hrc"
52 #include "ViewShell.hxx"
53 #include "DrawController.hxx"
54 #include "ViewShellBase.hxx"
55 
56 #include <com/sun/star/embed/XEmbedPersist.hpp>
57 #include <com/sun/star/frame/XDesktop.hpp>
58 #include <com/sun/star/frame/XFramesSupplier.hpp>
59 #include <svtools/embedtransfer.hxx>
60 #include <comphelper/processfactory.hxx>
61 #include <tools/diagnose_ex.h>
62 
63 using namespace com::sun::star;
64 
65 class SdPageObjsTLB::IconProvider
66 {
67 public:
68     IconProvider (void);
69 
70     // Regular icons.
71     Image maImgPage;
72     Image maImgPageExcl;
73     Image maImgPageObjsExcl;
74     Image maImgPageObjs;
75     Image maImgObjects;
76     Image maImgGroup;
77 
78     // High contrast icons.
79     Image maImgPageH;
80     Image maImgPageExclH;
81     Image maImgPageObjsExclH;
82     Image maImgPageObjsH;
83     Image maImgObjectsH;
84     Image maImgGroupH;
85 };
86 
87 
88 sal_Bool SD_DLLPRIVATE SdPageObjsTLB::bIsInDrag = sal_False;
89 
IsInDrag()90 sal_Bool SdPageObjsTLB::IsInDrag()
91 {
92 	return bIsInDrag;
93 }
94 
95 sal_uInt32 SdPageObjsTLB::SdPageObjsTransferable::mnListBoxDropFormatId = SAL_MAX_UINT32;
96 
97 // -----------------------------------------
98 // - SdPageObjsTLB::SdPageObjsTransferable -
99 // -----------------------------------------
100 
SdPageObjsTransferable(SdPageObjsTLB & rParent,const INetBookmark & rBookmark,::sd::DrawDocShell & rDocShell,NavigatorDragType eDragType,const::com::sun::star::uno::Any & rTreeListBoxData)101 SdPageObjsTLB::SdPageObjsTransferable::SdPageObjsTransferable(
102     SdPageObjsTLB& rParent,
103         const INetBookmark& rBookmark,
104     ::sd::DrawDocShell& rDocShell,
105     NavigatorDragType eDragType,
106     const ::com::sun::star::uno::Any& rTreeListBoxData )
107     : SdTransferable(rDocShell.GetDoc(), NULL, sal_True),
108       mrParent( rParent ),
109       maBookmark( rBookmark ),
110       mrDocShell( rDocShell ),
111       meDragType( eDragType ),
112       maTreeListBoxData( rTreeListBoxData )
113 {
114 }
115 
116 
117 
118 
~SdPageObjsTransferable()119 SdPageObjsTLB::SdPageObjsTransferable::~SdPageObjsTransferable()
120 {
121 }
122 
123 // -----------------------------------------------------------------------------
124 
AddSupportedFormats()125 void SdPageObjsTLB::SdPageObjsTransferable::AddSupportedFormats()
126 {
127     AddFormat(SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK);
128     AddFormat(SOT_FORMATSTR_ID_TREELISTBOX);
129     AddFormat(GetListBoxDropFormatId());
130 }
131 
132 // -----------------------------------------------------------------------------
133 
GetData(const::com::sun::star::datatransfer::DataFlavor & rFlavor)134 sal_Bool SdPageObjsTLB::SdPageObjsTransferable::GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor )
135 {
136 	sal_uLong nFormatId = SotExchange::GetFormat( rFlavor );
137     switch (nFormatId)
138     {
139         case SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK:
140             SetINetBookmark( maBookmark, rFlavor );
141             return sal_True;
142 
143         case SOT_FORMATSTR_ID_TREELISTBOX:
144             SetAny(maTreeListBoxData, rFlavor);
145             return sal_True;
146 
147         default:
148             return sal_False;
149     }
150 }
151 
152 // -----------------------------------------------------------------------------
153 
DragFinished(sal_Int8 nDropAction)154 void SdPageObjsTLB::SdPageObjsTransferable::DragFinished( sal_Int8 nDropAction )
155 {
156 	mrParent.OnDragFinished( nDropAction );
157     SdTransferable::DragFinished(nDropAction);
158 }
159 
160 // -----------------------------------------------------------------------------
161 
GetDocShell() const162 ::sd::DrawDocShell& SdPageObjsTLB::SdPageObjsTransferable::GetDocShell() const
163 {
164     return mrDocShell;
165 }
166 
167 // -----------------------------------------------------------------------------
168 
GetDragType() const169 NavigatorDragType SdPageObjsTLB::SdPageObjsTransferable::GetDragType() const
170 {
171     return meDragType;
172 }
173 
174 // -----------------------------------------------------------------------------
175 
getSomething(const::com::sun::star::uno::Sequence<sal_Int8> & rId)176 sal_Int64 SAL_CALL SdPageObjsTLB::SdPageObjsTransferable::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw( ::com::sun::star::uno::RuntimeException )
177 {
178     sal_Int64 nRet;
179 
180     if( ( rId.getLength() == 16 ) &&
181         ( 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) )
182     {
183         nRet = (sal_Int64)(sal_IntPtr)this;
184     }
185     else
186         nRet = SdTransferable::getSomething(rId);
187 
188 	return nRet;
189 }
190 
191 // -----------------------------------------------------------------------------
192 
getUnoTunnelId()193 const ::com::sun::star::uno::Sequence< sal_Int8 >& SdPageObjsTLB::SdPageObjsTransferable::getUnoTunnelId()
194 {
195     static ::com::sun::star::uno::Sequence< sal_Int8 > aSeq;
196 
197 	if( !aSeq.getLength() )
198 	{
199 		static osl::Mutex   aCreateMutex;
200     	osl::MutexGuard     aGuard( aCreateMutex );
201 
202 		aSeq.realloc( 16 );
203     	rtl_createUuid( reinterpret_cast< sal_uInt8* >( aSeq.getArray() ), 0, sal_True );
204 	}
205 
206     return aSeq;
207 }
208 
209 // -----------------------------------------------------------------------------
210 
getImplementation(const::com::sun::star::uno::Reference<::com::sun::star::uno::XInterface> & rxData)211 SdPageObjsTLB::SdPageObjsTransferable* SdPageObjsTLB::SdPageObjsTransferable::getImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rxData )
212     throw()
213 {
214     try
215     {
216 	    ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > xUnoTunnel( rxData, ::com::sun::star::uno::UNO_QUERY_THROW );
217 
218 		return reinterpret_cast<SdPageObjsTLB::SdPageObjsTransferable*>(
219 				sal::static_int_cast<sal_uIntPtr>(
220 					xUnoTunnel->getSomething( SdPageObjsTLB::SdPageObjsTransferable::getUnoTunnelId()) ) );
221     }
222     catch( const ::com::sun::star::uno::Exception& )
223 	{
224 	}
225 	return 0;
226 }
227 
228 
GetListBoxDropFormatId(void)229 sal_uInt32 SdPageObjsTLB::SdPageObjsTransferable::GetListBoxDropFormatId (void)
230 {
231     if (mnListBoxDropFormatId == SAL_MAX_UINT32)
232         mnListBoxDropFormatId = SotExchange::RegisterFormatMimeType(
233             ::rtl::OUString::createFromAscii(
234                 "application/x-openoffice-treelistbox-moveonly;"
235                     "windows_formatname=\"SV_LBOX_DD_FORMAT_MOVE\""));
236     return mnListBoxDropFormatId;
237 }
238 
239 
240 
241 
242 /*************************************************************************
243 |*
244 |* Ctor1 SdPageObjsTLB
245 |*
246 \************************************************************************/
247 
SdPageObjsTLB(Window * pParentWin,const SdResId & rSdResId)248 SdPageObjsTLB::SdPageObjsTLB( Window* pParentWin, const SdResId& rSdResId )
249 :	SvTreeListBox       ( pParentWin, rSdResId )
250 ,   bisInSdNavigatorWin  ( sal_False )
251 ,	mpParent 		    ( pParentWin )
252 ,	mpDoc			    ( NULL )
253 ,	mpBookmarkDoc	    ( NULL )
254 ,	mpMedium 	    	( NULL )
255 ,	mpOwnMedium		    ( NULL )
256 ,	maImgOle             ( BitmapEx( SdResId( BMP_OLE ) ) )
257 ,	maImgGraphic         ( BitmapEx( SdResId( BMP_GRAPHIC ) ) )
258 ,	maImgOleH            ( BitmapEx( SdResId( BMP_OLE_H ) ) )
259 ,	maImgGraphicH        ( BitmapEx( SdResId( BMP_GRAPHIC_H ) ) )
260 ,	mbLinkableSelected  ( sal_False )
261 ,	mpDropNavWin		( NULL )
262 ,   mbShowAllShapes     ( false )
263 ,   mbShowAllPages      ( false )
264 {
265 	// Tree-ListBox mit Linien versehen
266 	SetStyle( GetStyle() | WB_TABSTOP | WB_BORDER | WB_HASLINES |
267 						   WB_HASBUTTONS | // WB_HASLINESATROOT |
268 						   WB_HSCROLL | // #31562#
269 						   WB_HASBUTTONSATROOT |
270                            WB_QUICK_SEARCH /* i31275 */ );
271 	SetNodeBitmaps( Bitmap( SdResId( BMP_EXPAND ) ),
272 					Bitmap( SdResId( BMP_COLLAPSE ) ) );
273 
274 	SetNodeBitmaps( Bitmap( SdResId( BMP_EXPAND_H ) ),
275 					Bitmap( SdResId( BMP_COLLAPSE_H ) ),
276 					BMP_COLOR_HIGHCONTRAST );
277 
278     SetDragDropMode(
279  		SV_DRAGDROP_CTRL_MOVE | SV_DRAGDROP_CTRL_COPY |
280             SV_DRAGDROP_APP_MOVE  | SV_DRAGDROP_APP_COPY  | SV_DRAGDROP_APP_DROP );
281 }
282 
283 /*************************************************************************
284 |*
285 |* Dtor SdPageObjsTLB
286 |*
287 \************************************************************************/
288 
~SdPageObjsTLB()289 SdPageObjsTLB::~SdPageObjsTLB()
290 {
291     if ( mpBookmarkDoc )
292         CloseBookmarkDoc();
293     else
294         // no document was created from mpMedium, so this object is still the owner of it
295         delete mpMedium;
296 }
297 
298 // helper function for 	GetEntryAltText and GetEntryLongDescription
getAltLongDescText(SvLBoxEntry * pEntry,sal_Bool isAltText) const299 String SdPageObjsTLB::getAltLongDescText( SvLBoxEntry* pEntry , sal_Bool isAltText) const
300 {
301 	sal_uInt16 maxPages = mpDoc->GetPageCount();
302 	sal_uInt16 pageNo;
303 	SdrObject*	 pObj = NULL;
304 	SdPage* pPage = NULL;
305 
306 
307 	String ParentName = GetEntryText( GetRootLevelParent( pEntry ) );
308 
309 	for( pageNo = 0;  pageNo < maxPages; pageNo++ )
310 	{
311 		pPage = (SdPage*) mpDoc->GetPage( pageNo );
312 		if( pPage->GetPageKind() != PK_STANDARD ) continue;
313 		if( pPage->GetName() !=  ParentName ) continue;
314 		SdrObjListIter aIter( *pPage, IM_FLAT );
315 		while( aIter.IsMore() )
316 		{
317 			pObj = aIter.Next();
318 			if( GetEntryText(pEntry) ==  GetObjectName( pObj )  )
319 			{
320 				if( isAltText )
321 					return pObj->GetTitle();
322 				else
323 					return pObj->GetDescription();
324 			}
325 		}
326 	}
327 	return String();
328 
329 }
330 
GetEntryAltText(SvLBoxEntry * pEntry) const331 String SdPageObjsTLB::GetEntryAltText( SvLBoxEntry* pEntry ) const
332 {
333 	return getAltLongDescText( pEntry, sal_True );
334 }
335 
GetEntryLongDescription(SvLBoxEntry * pEntry) const336 String SdPageObjsTLB::GetEntryLongDescription( SvLBoxEntry* pEntry ) const
337 {
338 	return getAltLongDescText( pEntry, sal_False);
339 }
340 
MarkCurEntry(const String & rName)341 void  SdPageObjsTLB::MarkCurEntry( const String& rName )
342 {
343 
344 	if( rName.Len() )
345 	{
346 		SvLBoxEntry* pCurEntry =GetCurEntry();
347 		SvLBoxEntry* pEntry =NULL;
348 		String aTmp1;
349 		String aTmp2;
350 
351 	       if( GetParent(pCurEntry)==NULL )
352 	       {
353 	              aTmp1 = GetEntryText( pCurEntry );
354 		       for( pEntry = First(); pEntry ; pEntry = Next( pEntry ) )
355 			{
356 			       if(GetParent( pEntry )==NULL)
357 				   	     continue;
358 				aTmp2 = GetEntryText( GetParent( pEntry ));
359 				if( aTmp1 != aTmp2)
360 				{
361 					// IA2 CWS. MT: Removed in SvLBoxEntry for now - only used in Sw/Sd/ScContentLBoxString, they should decide if they need this
362 					pEntry->SetMarked(sal_False);
363 				}
364 			}
365 
366 	       }
367               else
368               {
369 	              for( pEntry = First(); pEntry ; pEntry = Next( pEntry ) )
370 			{
371 				aTmp2 = GetEntryText( pEntry );
372 				if( aTmp2 == rName)
373 				{
374 					pEntry->SetMarked(sal_True);
375 				}
376 				else
377 				{
378 				        pEntry->SetMarked(sal_False);
379 				}
380 			}
381               }
382 	}
383 	Invalidate();
384 }
385 
FreshCurEntry()386 void  SdPageObjsTLB:: FreshCurEntry()
387 {
388        SvLBoxEntry* pEntry =NULL;
389        for( pEntry = First(); pEntry ; pEntry = Next( pEntry ) )
390 	{
391 		        pEntry->SetMarked(sal_False);
392 	}
393 	Invalidate();
394 }
395 
396 class SdContentLBoxString : public SvLBoxString
397 {
398 public:
SdContentLBoxString(SvLBoxEntry * pEntry,sal_uInt16 nFlags,const String & rStr)399 	SdContentLBoxString( SvLBoxEntry* pEntry, sal_uInt16 nFlags,
400 		const String& rStr ) : SvLBoxString(pEntry,nFlags,rStr)	{}
401 
402 	virtual void Paint( const Point& rPos, SvLBox& rDev, sal_uInt16 nFlags,
403 		SvLBoxEntry* pEntry);
404 };
405 
InitEntry(SvLBoxEntry * pEntry,const XubString & rStr,const Image & rImg1,const Image & rImg2,SvLBoxButtonKind eButtonKind)406 void SdPageObjsTLB::InitEntry(SvLBoxEntry* pEntry,
407 		const XubString& rStr ,const Image& rImg1,const Image& rImg2,SvLBoxButtonKind eButtonKind)
408 {
409 	sal_uInt16 nColToHilite = 1; //0==Bitmap;1=="Spalte1";2=="Spalte2"
410 	SvTreeListBox::InitEntry( pEntry, rStr, rImg1, rImg2, eButtonKind );
411 	SvLBoxString* pCol = (SvLBoxString*)pEntry->GetItem( nColToHilite );
412 	SdContentLBoxString* pStr = new SdContentLBoxString( pEntry, 0, pCol->GetText() );
413 	pEntry->ReplaceItem( pStr, nColToHilite );
414 }
415 
Paint(const Point & rPos,SvLBox & rDev,sal_uInt16 nFlags,SvLBoxEntry * pEntry)416 void SdContentLBoxString::Paint( const Point& rPos, SvLBox& rDev, sal_uInt16 nFlags,
417 	SvLBoxEntry* pEntry )
418 {
419 	// IA2 CWS. MT: Removed for now (also in SvLBoxEntry) - only used in Sw/Sd/ScContentLBoxString, they should decide if they need this
420 	/*
421 	if (pEntry->IsMarked())
422 	{
423 			rDev.DrawText( rPos, GetText() );
424 			XubString str;
425 			str = XubString::CreateFromAscii("*");
426 			Point rPosStar(rPos.X()-6,rPos.Y());
427 			Font aOldFont( rDev.GetFont());
428 			Font aFont(aOldFont);
429 			Color aCol( aOldFont.GetColor() );
430 			aCol.DecreaseLuminance( 200 );
431 			aFont.SetColor( aCol );
432 			rDev.SetFont( aFont );
433 			rDev.DrawText( rPosStar, str);
434 			rDev.SetFont( aOldFont );
435 	}
436 	else
437 	*/
438 		SvLBoxString::Paint( rPos, rDev, nFlags, pEntry);
439 
440 }
441 
SaveExpandedTreeItemState(SvLBoxEntry * pEntry,vector<String> & vectTreeItem)442 void SdPageObjsTLB::SaveExpandedTreeItemState(SvLBoxEntry* pEntry, vector<String>& vectTreeItem)
443 {
444 	if (pEntry)
445 	{
446 		SvLBoxEntry* pListEntry = pEntry;
447 		while (pListEntry)
448 		{
449 			if (pListEntry->HasChilds())
450 			{
451 				if (IsExpanded(pListEntry))
452 					vectTreeItem.push_back(GetEntryText(pListEntry));
453 				SvLBoxEntry* pChildEntry = FirstChild(pListEntry);
454 				SaveExpandedTreeItemState(pChildEntry, vectTreeItem);
455 			}
456 			pListEntry = NextSibling(pListEntry);
457 		}
458 	}
459 }
Clear()460 void SdPageObjsTLB::Clear()
461 {
462 	//Save the expanded tree item
463 	if (mbSaveTreeItemState)
464 	{
465 		maSelectionEntryText = String();
466 		maTreeItem.clear();
467 		if (GetCurEntry())
468 			maSelectionEntryText = GetSelectEntry();
469 		SvLBoxEntry* pEntry = FirstChild(NULL);
470 		SaveExpandedTreeItemState(pEntry, maTreeItem);
471 	}
472 	return SvTreeListBox::Clear();
473 }
474 /*************************************************************************
475 |*
476 |* return name of object
477 |*
478 \************************************************************************/
479 
GetObjectName(const SdrObject * pObject,const bool bCreate) const480 String SdPageObjsTLB::GetObjectName(
481     const SdrObject* pObject,
482     const bool bCreate) const
483 {
484     String aRet;
485 
486     if ( pObject )
487     {
488         aRet = pObject->GetName();
489 
490         if( !aRet.Len() && pObject->ISA( SdrOle2Obj ) )
491             aRet = static_cast< const SdrOle2Obj* >( pObject )->GetPersistName();
492     }
493 
494     if (bCreate
495         && mbShowAllShapes
496         && aRet.Len() == 0
497         && pObject!=NULL)
498     {
499         aRet = SdResId(STR_NAVIGATOR_SHAPE_BASE_NAME);
500         aRet.SearchAndReplaceAscii("%1", String::CreateFromInt32(pObject->GetOrdNum() + 1));
501     }
502 
503     return aRet;
504 }
505 
506 /*************************************************************************
507 |*
508 |* In TreeLB Eintrag selektieren
509 |*
510 \************************************************************************/
511 
SelectEntry(const String & rName)512 sal_Bool SdPageObjsTLB::SelectEntry( const String& rName )
513 {
514 	sal_Bool bFound = sal_False;
515 
516 	if( rName.Len() )
517 	{
518 		SvLBoxEntry* pEntry = NULL;
519 		String aTmp;
520 
521 		for( pEntry = First(); pEntry && !bFound; pEntry = Next( pEntry ) )
522 		{
523 			aTmp = GetEntryText( pEntry );
524 			if( aTmp == rName )
525 			{
526 				bFound = sal_True;
527 				SetCurEntry( pEntry );
528 			}
529 		}
530 	}
531 	return( bFound );
532 }
533 
534 /*************************************************************************
535 |*
536 |* Gibt zurueck, ob Childs des uebergebenen Strings selektiert sind
537 |*
538 \************************************************************************/
539 
HasSelectedChilds(const String & rName)540 sal_Bool SdPageObjsTLB::HasSelectedChilds( const String& rName )
541 {
542 	sal_Bool bFound  = sal_False;
543 	sal_Bool bChilds = sal_False;
544 
545 	if( rName.Len() )
546 	{
547 		SvLBoxEntry* pEntry = NULL;
548 		String aTmp;
549 
550 		for( pEntry = First(); pEntry && !bFound; pEntry = Next( pEntry ) )
551 		{
552 			aTmp = GetEntryText( pEntry );
553 			if( aTmp == rName )
554 			{
555 				bFound = sal_True;
556 				sal_Bool bExpanded = IsExpanded( pEntry );
557 				long nCount = GetChildSelectionCount( pEntry );
558 				if( bExpanded && nCount > 0 )
559 					bChilds = sal_True;
560 			}
561 		}
562 	}
563 	return( bChilds );
564 }
565 
566 
567 /*************************************************************************
568 |*
569 |* TreeLB mit Seiten und Objekten fuellen
570 |*
571 \************************************************************************/
572 
Fill(const SdDrawDocument * pInDoc,sal_Bool bAllPages,const String & rDocName)573 void SdPageObjsTLB::Fill( const SdDrawDocument* pInDoc, sal_Bool bAllPages,
574 						  const String& rDocName)
575 {
576 	String aSelection;
577 	if( GetSelectionCount() > 0 )
578 	{
579 		aSelection = GetSelectEntry();
580 		Clear();
581 	}
582 
583 	mpDoc = pInDoc;
584 	maDocName = rDocName;
585     mbShowAllPages = (bAllPages == sal_True);
586 	mpMedium = NULL;
587 
588 	SdPage* 	 pPage = NULL;
589 
590     IconProvider aIconProvider;
591 
592 	// first insert all pages including objects
593 	sal_uInt16 nPage = 0;
594 	const sal_uInt16 nMaxPages = mpDoc->GetPageCount();
595 
596 	while( nPage < nMaxPages )
597 	{
598 		pPage = (SdPage*) mpDoc->GetPage( nPage );
599 		if(  (mbShowAllPages || pPage->GetPageKind() == PK_STANDARD)
600 		     && !(pPage->GetPageKind()==PK_HANDOUT)   ) //#94954# never list the normal handout page ( handout-masterpage is used instead )
601 		{
602 			sal_Bool bPageExluded = pPage->IsExcluded();
603 
604             bool bPageBelongsToShow = PageBelongsToCurrentShow (pPage);
605             bPageExluded |= !bPageBelongsToShow;
606 
607             AddShapeList(*pPage, NULL, pPage->GetName(), bPageExluded, NULL, aIconProvider);
608 		}
609 		nPage++;
610 	}
611 
612 	// dann alle MasterPages incl. Objekte einfuegen
613 	if( mbShowAllPages )
614 	{
615 		nPage = 0;
616 		const sal_uInt16 nMaxMasterPages = mpDoc->GetMasterPageCount();
617 
618 		while( nPage < nMaxMasterPages )
619 		{
620 			pPage = (SdPage*) mpDoc->GetMasterPage( nPage );
621             AddShapeList(*pPage, NULL, pPage->GetName(), false, NULL, aIconProvider);
622 			nPage++;
623 		}
624 	}
625 	if( aSelection.Len() )
626 		SelectEntry( aSelection );
627 	else if (mbSaveTreeItemState && maSelectionEntryText.Len())
628 	{
629 		SelectEntry(maSelectionEntryText);
630 	}
631 }
632 
633 /*************************************************************************
634 |*
635 |* Es wird nur der erste Eintrag eingefuegt. Childs werden OnDemand erzeugt
636 |*
637 \************************************************************************/
638 
Fill(const SdDrawDocument * pInDoc,SfxMedium * pInMedium,const String & rDocName)639 void SdPageObjsTLB::Fill( const SdDrawDocument* pInDoc, SfxMedium* pInMedium,
640 						  const String& rDocName )
641 {
642 	mpDoc = pInDoc;
643 
644     // this object now owns the Medium
645 	mpMedium = pInMedium;
646 	maDocName = rDocName;
647 
648 	Image aImgDocOpen=Image( BitmapEx( SdResId( BMP_DOC_OPEN ) ) );
649 	Image aImgDocClosed=Image( BitmapEx( SdResId( BMP_DOC_CLOSED ) ) );
650 	Image aImgDocOpenH=Image( BitmapEx( SdResId( BMP_DOC_OPEN_H ) ) );
651 	Image aImgDocClosedH=Image( BitmapEx( SdResId( BMP_DOC_CLOSED_H ) ) );
652 
653 	// Dokumentnamen einfuegen
654 	SvLBoxEntry* pFileEntry = InsertEntry( maDocName,
655 	                          aImgDocOpen,
656 	                          aImgDocClosed,
657 	                          NULL,
658 	                          sal_True,
659 							  LIST_APPEND,
660 							  reinterpret_cast< void* >( 1 ) );
661 
662 	SetExpandedEntryBmp( pFileEntry, aImgDocOpenH, BMP_COLOR_HIGHCONTRAST );
663 	SetCollapsedEntryBmp( pFileEntry, aImgDocClosedH, BMP_COLOR_HIGHCONTRAST );
664 }
665 
666 
667 
668 
AddShapeList(const SdrObjList & rList,SdrObject * pShape,const::rtl::OUString & rsName,const bool bIsExcluded,SvLBoxEntry * pParentEntry,const IconProvider & rIconProvider)669 void SdPageObjsTLB::AddShapeList (
670     const SdrObjList& rList,
671     SdrObject* pShape,
672     const ::rtl::OUString& rsName,
673     const bool bIsExcluded,
674     SvLBoxEntry* pParentEntry,
675     const IconProvider& rIconProvider)
676 {
677     Image aIcon (rIconProvider.maImgPage);
678     if (bIsExcluded)
679         aIcon = rIconProvider.maImgPageExcl;
680     else if (pShape != NULL)
681         aIcon = rIconProvider.maImgGroup;
682 
683     void* pUserData (reinterpret_cast<void*>(1));
684     if (pShape != NULL)
685         pUserData = pShape;
686 
687 	SvLBoxEntry* pEntry = InsertEntry(
688         rsName,
689         aIcon,
690         aIcon,
691         pParentEntry,
692         sal_False,
693         LIST_APPEND,
694         pUserData);
695 
696     SetExpandedEntryBmp(
697         pEntry,
698         bIsExcluded ? rIconProvider.maImgPageExclH : rIconProvider.maImgPageH,
699         BMP_COLOR_HIGHCONTRAST );
700     SetCollapsedEntryBmp(
701         pEntry,
702         bIsExcluded ? rIconProvider.maImgPageExclH : rIconProvider.maImgPageH,
703         BMP_COLOR_HIGHCONTRAST );
704 
705     SdrObjListIter aIter(
706         rList,
707         !rList.HasObjectNavigationOrder() /* use navigation order, if available */,
708         IM_FLAT,
709         sal_False /*not reverse*/);
710 
711 	sal_Bool  bMarked=sal_False;
712 	if(bisInSdNavigatorWin)
713 	{
714 		Window* pWindow=NULL;
715 		SdNavigatorWin* pSdNavigatorWin=NULL;
716 		sd::DrawDocShell* pSdDrawDocShell = NULL;
717 		if(pEntry)
718 			pWindow=(Window*)GetParent(pEntry);
719 		if(pWindow)
720 			pSdNavigatorWin = (SdNavigatorWin*)pWindow;
721 		if( pSdNavigatorWin )
722 			pSdDrawDocShell = pSdNavigatorWin->GetDrawDocShell(mpDoc);
723 		if(pSdDrawDocShell)
724 			bMarked=pSdDrawDocShell->IsMarked(pShape);
725 		if(pEntry)
726 		{
727 			if(bMarked)
728 				pEntry->SetMarked(sal_True);
729 			else
730 				pEntry->SetMarked( sal_False );
731 		}
732 	}
733     while( aIter.IsMore() )
734     {
735         SdrObject* pObj = aIter.Next();
736         OSL_ASSERT(pObj!=NULL);
737 
738         // Get the shape name.
739         String aStr (GetObjectName( pObj ) );
740 
741         if( aStr.Len() )
742         {
743             if( pObj->GetObjInventor() == SdrInventor && pObj->GetObjIdentifier() == OBJ_OLE2 )
744             {
745                 SvLBoxEntry* pNewEntry = InsertEntry( aStr, maImgOle, maImgOle, pEntry,
746                     sal_False, LIST_APPEND, pObj);
747 				if(bisInSdNavigatorWin)
748 				{
749 					Window* pWindow=NULL;
750 					SdNavigatorWin* pSdNavigatorWin=NULL;
751 					sd::DrawDocShell* pSdDrawDocShell = NULL;
752 					if(pNewEntry)
753 						pWindow=(Window*)GetParent(pNewEntry);
754 					if(pWindow)
755 						pSdNavigatorWin = (SdNavigatorWin*)pWindow;
756 					if( pSdNavigatorWin )
757 						pSdDrawDocShell = pSdNavigatorWin->GetDrawDocShell(mpDoc);
758 					if(pSdDrawDocShell)
759 						bMarked=pSdDrawDocShell->IsMarked((SdrObject*)pObj);
760 					if(pNewEntry)
761 					{
762 						if(bMarked)
763 							pNewEntry->SetMarked(sal_True);
764 						else
765 							pNewEntry->SetMarked( sal_False );
766 					}
767 				}
768                 SetExpandedEntryBmp( pNewEntry, maImgOleH, BMP_COLOR_HIGHCONTRAST );
769                 SetCollapsedEntryBmp( pNewEntry, maImgOleH, BMP_COLOR_HIGHCONTRAST );
770             }
771             else if( pObj->GetObjInventor() == SdrInventor && pObj->GetObjIdentifier() == OBJ_GRAF )
772             {
773                 SvLBoxEntry* pNewEntry = InsertEntry( aStr, maImgGraphic, maImgGraphic, pEntry,
774                     sal_False, LIST_APPEND, pObj );
775 				if(bisInSdNavigatorWin)
776 				{
777 					Window* pWindow=NULL;
778 					SdNavigatorWin* pSdNavigatorWin=NULL;
779 					sd::DrawDocShell* pSdDrawDocShell = NULL;
780 					if(pNewEntry)
781 						pWindow=(Window*)GetParent(pNewEntry);
782 					if(pWindow)
783 						pSdNavigatorWin = (SdNavigatorWin*)pWindow;
784 					if( pSdNavigatorWin )
785 						pSdDrawDocShell = pSdNavigatorWin->GetDrawDocShell(mpDoc);
786 					if(pSdDrawDocShell)
787 						bMarked=pSdDrawDocShell->IsMarked((SdrObject*)pObj);
788 					if(pNewEntry)
789 					{
790 						if(bMarked)
791 						{
792 							pNewEntry->SetMarked(sal_True);
793 						}
794 						else
795 						{
796 							pNewEntry->SetMarked( sal_False );
797 						}
798 					}
799 				}
800                 SetExpandedEntryBmp( pNewEntry, maImgGraphicH, BMP_COLOR_HIGHCONTRAST );
801                 SetCollapsedEntryBmp( pNewEntry, maImgGraphicH, BMP_COLOR_HIGHCONTRAST );
802             }
803             else if (pObj->IsGroupObject())
804             {
805                 AddShapeList(
806                     *pObj->GetSubList(),
807                     pObj,
808                     aStr,
809                     false,
810                     pEntry,
811                     rIconProvider);
812             }
813             else
814             {
815                 SvLBoxEntry* pNewEntry = InsertEntry( aStr, rIconProvider.maImgObjects, rIconProvider.maImgObjects, pEntry,
816                     sal_False, LIST_APPEND, pObj );
817 				if(bisInSdNavigatorWin)
818 				{
819 					Window* pWindow=NULL;
820 					SdNavigatorWin* pSdNavigatorWin=NULL;
821 					sd::DrawDocShell* pSdDrawDocShell = NULL;
822 					if(pNewEntry)
823 						pWindow=(Window*)GetParent(pNewEntry);
824 					if(pWindow)
825 						pSdNavigatorWin = (SdNavigatorWin*)pWindow;
826 					if( pSdNavigatorWin )
827 						pSdDrawDocShell = pSdNavigatorWin->GetDrawDocShell(mpDoc);
828 					if(pSdDrawDocShell)
829 						bMarked=pSdDrawDocShell->IsMarked((SdrObject*)pObj);
830 					if(pNewEntry)
831 					{
832 						if(bMarked)
833 						{
834 							pNewEntry->SetMarked(sal_True);
835 						}
836 						else
837 						{
838 							pNewEntry->SetMarked( sal_False );
839 						}
840 					}
841 				}
842                 SetExpandedEntryBmp( pNewEntry, rIconProvider.maImgObjectsH, BMP_COLOR_HIGHCONTRAST );
843                 SetCollapsedEntryBmp( pNewEntry, rIconProvider.maImgObjectsH, BMP_COLOR_HIGHCONTRAST );
844             }
845         }
846     }
847 
848     if( pEntry->HasChilds() )
849     {
850         SetExpandedEntryBmp(
851             pEntry,
852             bIsExcluded ? rIconProvider.maImgPageObjsExcl : rIconProvider.maImgPageObjs);
853         SetCollapsedEntryBmp(
854             pEntry,
855             bIsExcluded ? rIconProvider.maImgPageObjsExcl : rIconProvider.maImgPageObjs);
856         SetExpandedEntryBmp(
857             pEntry,
858             bIsExcluded ? rIconProvider.maImgPageObjsExclH : rIconProvider.maImgPageObjsH,
859             BMP_COLOR_HIGHCONTRAST);
860         SetCollapsedEntryBmp(
861             pEntry,
862             bIsExcluded ? rIconProvider.maImgPageObjsExclH : rIconProvider.maImgPageObjsH,
863             BMP_COLOR_HIGHCONTRAST);
864 		if (mbSaveTreeItemState)
865 		{
866 			vector<String>:: iterator iteStart = maTreeItem.begin();
867 			while (iteStart != maTreeItem.end())
868 			{
869 				String strEntry = GetEntryText(pEntry);
870 				if (*iteStart == strEntry)
871 				{
872 					Expand( pEntry );
873 					break;
874 				}
875 				++iteStart;
876 			}
877 		}
878 		else
879 			Expand( pEntry );
880     }
881 }
882 
883 
884 
885 
SetShowAllShapes(const bool bShowAllShapes,const bool bFillList)886 void SdPageObjsTLB::SetShowAllShapes (
887     const bool bShowAllShapes,
888     const bool bFillList)
889 {
890     mbShowAllShapes = bShowAllShapes;
891     if (bFillList)
892     {
893         if (mpMedium == NULL)
894             Fill(mpDoc, mbShowAllPages, maDocName);
895         else
896             Fill(mpDoc, mpMedium, maDocName);
897     }
898 }
899 
900 
901 
902 
GetShowAllShapes(void) const903 bool SdPageObjsTLB::GetShowAllShapes (void) const
904 {
905     return mbShowAllShapes;
906 }
907 
908 
909 
910 
911 /*************************************************************************
912 |*
913 |* Prueft, ob die Seiten (PK_STANDARD) und die darauf befindlichen Objekte
914 |* des Docs und der TreeLB identisch sind.
915 |* Wird ein Doc uebergeben, wird dieses zum aktuellem Doc (Wichtig bei
916 |* mehreren Documenten).
917 |*
918 \************************************************************************/
919 
IsEqualToDoc(const SdDrawDocument * pInDoc)920 sal_Bool SdPageObjsTLB::IsEqualToDoc( const SdDrawDocument* pInDoc )
921 {
922 	if( pInDoc )
923 		mpDoc = pInDoc;
924 
925 	if( !mpDoc )
926 		return( sal_False );
927 
928 	SdrObject*	 pObj = NULL;
929 	SdPage* 	 pPage = NULL;
930 	SvLBoxEntry* pEntry = First();
931 	String		 aName;
932 
933 	// Alle Pages incl. Objekte vergleichen
934 	sal_uInt16 nPage = 0;
935 	const sal_uInt16 nMaxPages = mpDoc->GetPageCount();
936 
937 	while( nPage < nMaxPages )
938 	{
939 		pPage = (SdPage*) mpDoc->GetPage( nPage );
940 		if( pPage->GetPageKind() == PK_STANDARD )
941 		{
942 			if( !pEntry )
943 				return( sal_False );
944 			aName = GetEntryText( pEntry );
945 
946 			if( pPage->GetName() != aName )
947 				return( sal_False );
948 
949 			pEntry = Next( pEntry );
950 
951 			SdrObjListIter aIter(
952                 *pPage,
953                 !pPage->HasObjectNavigationOrder() /* use navigation order, if available */,
954                 IM_DEEPWITHGROUPS );
955 
956 			while( aIter.IsMore() )
957 			{
958 				pObj = aIter.Next();
959 
960                 const String aObjectName( GetObjectName( pObj ) );
961 
962 				if( aObjectName.Len() )
963 				{
964 					if( !pEntry )
965 						return( sal_False );
966 
967                 	aName = GetEntryText( pEntry );
968 
969 					if( aObjectName != aName )
970 						return( sal_False );
971 
972 					pEntry = Next( pEntry );
973 				}
974 			}
975 		}
976 		nPage++;
977 	}
978 	// Wenn noch Eintraege in der Listbox vorhanden sind, wurden
979 	// Objekte (mit Namen) oder Seiten geloescht
980 	return( !pEntry );
981 }
982 
983 /*************************************************************************
984 |*
985 |* Selectierten String zurueckgeben
986 |*
987 \************************************************************************/
988 
GetSelectEntry()989 String SdPageObjsTLB::GetSelectEntry()
990 {
991 	return( GetEntryText( GetCurEntry() ) );
992 }
993 
994 /*************************************************************************
995 |*
996 |* Selektierte Eintrage zurueckgeben
997 |* nDepth == 0 -> Seiten
998 |* nDepth == 1 -> Objekte
999 |*
1000 \************************************************************************/
1001 
GetSelectEntryList(sal_uInt16 nDepth)1002 List* SdPageObjsTLB::GetSelectEntryList( sal_uInt16 nDepth )
1003 {
1004 	List*		 pList	= NULL;
1005 	SvLBoxEntry* pEntry = FirstSelected();
1006 
1007 	while( pEntry )
1008 	{
1009 		sal_uInt16 nListDepth = GetModel()->GetDepth( pEntry );
1010 		if( nListDepth == nDepth )
1011 		{
1012 			if( !pList )
1013 				pList = new List();
1014 
1015 			const String aEntryText( GetEntryText( pEntry ) );
1016 			pList->Insert( new String( aEntryText ), LIST_APPEND );
1017 		}
1018 		pEntry = NextSelected( pEntry );
1019 	}
1020 
1021 	return( pList );
1022 }
1023 
1024 /*************************************************************************
1025 |*
1026 |* Eintraege werden erst auf Anforderung (Doppelklick) eingefuegt
1027 |*
1028 \************************************************************************/
1029 
RequestingChilds(SvLBoxEntry * pFileEntry)1030 void SdPageObjsTLB::RequestingChilds( SvLBoxEntry* pFileEntry )
1031 {
1032 	if( !pFileEntry->HasChilds() )
1033 	{
1034 		if( GetBookmarkDoc() )
1035 		{
1036 			SdrObject*	 pObj = NULL;
1037 			SdPage* 	 pPage = NULL;
1038 			SvLBoxEntry* pPageEntry = NULL;
1039 
1040 			Image aImgPage=Image( BitmapEx( SdResId( BMP_PAGE ) ) );
1041 			Image aImgPageObjs=Image( BitmapEx( SdResId( BMP_PAGEOBJS ) ) );
1042 			Image aImgObjects=Image( BitmapEx( SdResId( BMP_OBJECTS ) ) );
1043 			Image aImgPageH=Image( BitmapEx( SdResId( BMP_PAGE_H ) ) );
1044 			Image aImgPageObjsH=Image( BitmapEx( SdResId( BMP_PAGEOBJS_H ) ) );
1045 			Image aImgObjectsH=Image( BitmapEx( SdResId( BMP_OBJECTS_H ) ) );
1046 
1047 			// document name already inserted
1048 
1049 			// only insert all "normal" ? slides with objects
1050 			sal_uInt16 nPage = 0;
1051 			const sal_uInt16 nMaxPages = mpBookmarkDoc->GetPageCount();
1052 
1053 			while( nPage < nMaxPages )
1054 			{
1055 				pPage = (SdPage*) mpBookmarkDoc->GetPage( nPage );
1056 				if( pPage->GetPageKind() == PK_STANDARD )
1057 				{
1058 					pPageEntry = InsertEntry( pPage->GetName(),
1059 					                          aImgPage,
1060 					                          aImgPage,
1061 					                          pFileEntry,
1062 							                  sal_False,
1063 								              LIST_APPEND,
1064 								              reinterpret_cast< void* >( 1 ) );
1065 
1066 					SetExpandedEntryBmp( pPageEntry, aImgPageH, BMP_COLOR_HIGHCONTRAST );
1067 					SetCollapsedEntryBmp( pPageEntry, aImgPageH, BMP_COLOR_HIGHCONTRAST );
1068 
1069 					SdrObjListIter aIter( *pPage, IM_DEEPWITHGROUPS );
1070 
1071 					while( aIter.IsMore() )
1072 					{
1073 						pObj = aIter.Next();
1074 						String aStr( GetObjectName( pObj ) );
1075 						if( aStr.Len() )
1076 						{
1077 							if( pObj->GetObjInventor() == SdrInventor && pObj->GetObjIdentifier() == OBJ_OLE2 )
1078 							{
1079 								SvLBoxEntry* pNewEntry = InsertEntry(aStr, maImgOle, maImgOle, pPageEntry);
1080 
1081 
1082 								SetExpandedEntryBmp( pNewEntry, maImgOleH, BMP_COLOR_HIGHCONTRAST );
1083 								SetCollapsedEntryBmp( pNewEntry, maImgOleH, BMP_COLOR_HIGHCONTRAST );
1084 							}
1085 							else if( pObj->GetObjInventor() == SdrInventor && pObj->GetObjIdentifier() == OBJ_GRAF )
1086 							{
1087 								SvLBoxEntry* pNewEntry = InsertEntry(aStr, maImgGraphic, maImgGraphic, pPageEntry);
1088 
1089 								SetExpandedEntryBmp( pNewEntry, maImgGraphicH, BMP_COLOR_HIGHCONTRAST );
1090 								SetCollapsedEntryBmp( pNewEntry, maImgGraphicH, BMP_COLOR_HIGHCONTRAST );
1091 							}
1092 							else
1093 							{
1094 								SvLBoxEntry* pNewEntry = InsertEntry(aStr, aImgObjects, aImgObjects, pPageEntry);
1095 
1096 								SetExpandedEntryBmp( pNewEntry, aImgObjectsH, BMP_COLOR_HIGHCONTRAST );
1097 								SetCollapsedEntryBmp( pNewEntry, aImgObjectsH, BMP_COLOR_HIGHCONTRAST );
1098 							}
1099 						}
1100 					}
1101 					if( pPageEntry->HasChilds() )
1102 					{
1103 						SetExpandedEntryBmp( pPageEntry, aImgPageObjs );
1104 						SetCollapsedEntryBmp( pPageEntry, aImgPageObjs );
1105 						SetExpandedEntryBmp( pPageEntry, aImgPageObjsH, BMP_COLOR_HIGHCONTRAST );
1106 						SetCollapsedEntryBmp( pPageEntry, aImgPageObjsH, BMP_COLOR_HIGHCONTRAST );
1107 					}
1108 				}
1109 				nPage++;
1110 			}
1111 		}
1112 	}
1113 	else
1114 		SvTreeListBox::RequestingChilds( pFileEntry );
1115 }
1116 
1117 /*************************************************************************
1118 |*
1119 |*	Prueft, ob es sich um eine Draw-Datei handelt und oeffnet anhand des
1120 |*	uebergebenen Docs das BookmarkDoc
1121 |*
1122 \************************************************************************/
1123 
GetBookmarkDoc(SfxMedium * pMed)1124 SdDrawDocument* SdPageObjsTLB::GetBookmarkDoc(SfxMedium* pMed)
1125 {
1126 	if (
1127        !mpBookmarkDoc ||
1128 		 (pMed && (!mpOwnMedium || mpOwnMedium->GetName() != pMed->GetName()))
1129       )
1130 	{
1131         // create a new BookmarkDoc if now one exists or if a new Medium is provided
1132         if (mpOwnMedium != pMed)
1133 		{
1134 			CloseBookmarkDoc();
1135 		}
1136 
1137 		if (pMed)
1138 		{
1139             // it looks that it is undefined if a Medium was set by Fill() allready
1140             DBG_ASSERT( !mpMedium, "SfxMedium confusion!" );
1141             delete mpMedium;
1142             mpMedium = NULL;
1143 
1144             // take over this Medium (currently used only be Navigator)
1145 			mpOwnMedium = pMed;
1146         }
1147 
1148         DBG_ASSERT( mpMedium || pMed, "No SfxMedium provided!" );
1149 
1150         if( pMed )
1151         {
1152             // in this mode the document is also owned and controlled by this instance
1153             mxBookmarkDocShRef = new ::sd::DrawDocShell(SFX_CREATE_MODE_STANDARD, sal_True);
1154             if (mxBookmarkDocShRef->DoLoad(pMed))
1155                 mpBookmarkDoc = mxBookmarkDocShRef->GetDoc();
1156             else
1157                 mpBookmarkDoc = NULL;
1158         }
1159         else if ( mpMedium )
1160             // in this mode the document is owned and controlled by the SdDrawDocument
1161             // it can be released by calling the corresponding CloseBookmarkDoc method
1162             // successfull creation of a document makes this the owner of the medium
1163             mpBookmarkDoc = ((SdDrawDocument*) mpDoc)->OpenBookmarkDoc(*mpMedium);
1164 
1165         if ( !mpBookmarkDoc )
1166 		{
1167 			ErrorBox aErrorBox( this, WB_OK, String( SdResId( STR_READ_DATA_ERROR ) ) );
1168 			aErrorBox.Execute();
1169             mpMedium = 0; //On failure the SfxMedium is invalid
1170 		}
1171 	}
1172 
1173 	return( mpBookmarkDoc );
1174 }
1175 
1176 /*************************************************************************
1177 |*
1178 |* Bookmark-Dokument schlie�en und loeschen
1179 |*
1180 \************************************************************************/
1181 
CloseBookmarkDoc()1182 void SdPageObjsTLB::CloseBookmarkDoc()
1183 {
1184 	if (mxBookmarkDocShRef.Is())
1185 	{
1186 		mxBookmarkDocShRef->DoClose();
1187         mxBookmarkDocShRef.Clear();
1188 
1189         // Medium is owned by document, so it's destroyed already
1190         mpOwnMedium = 0;
1191 	}
1192     else if ( mpBookmarkDoc )
1193 	{
1194         DBG_ASSERT( !mpOwnMedium, "SfxMedium confusion!" );
1195         if ( mpDoc )
1196         {
1197             // The document owns the Medium, so the Medium will be invalid after closing the document
1198 			((SdDrawDocument*) mpDoc)->CloseBookmarkDoc();
1199             mpMedium = 0;
1200         }
1201 	}
1202     else
1203     {
1204         // perhaps mpOwnMedium provided, but no successfull creation of BookmarkDoc
1205         delete mpOwnMedium;
1206         mpOwnMedium = NULL;
1207     }
1208 
1209 	mpBookmarkDoc = NULL;
1210 }
1211 
1212 /*************************************************************************
1213 |*
1214 |*
1215 |*
1216 \************************************************************************/
1217 
SelectHdl()1218 void SdPageObjsTLB::SelectHdl()
1219 {
1220 	SvLBoxEntry* pEntry = FirstSelected();
1221 
1222 	mbLinkableSelected = sal_True;
1223 
1224 	while( pEntry && mbLinkableSelected )
1225 	{
1226 	    if( NULL == pEntry->GetUserData() )
1227 	        mbLinkableSelected = sal_False;
1228 
1229 		pEntry = NextSelected( pEntry );
1230 	}
1231 
1232 	SvTreeListBox::SelectHdl();
1233 }
1234 
1235 /*************************************************************************
1236 |*
1237 |* Ueberlaedt RETURN mit der Funktionsweise von DoubleClick
1238 |*
1239 \************************************************************************/
1240 
KeyInput(const KeyEvent & rKEvt)1241 void SdPageObjsTLB::KeyInput( const KeyEvent& rKEvt )
1242 {
1243 	if( rKEvt.GetKeyCode().GetCode() == KEY_RETURN )
1244 	{
1245 		// Auskommentierter Code aus svtools/source/contnr/svimpbox.cxx
1246 		SvLBoxEntry* pCursor = GetCurEntry();
1247 		if( pCursor->HasChilds() || pCursor->HasChildsOnDemand() )
1248 		{
1249 			if( IsExpanded( pCursor ) )
1250 				Collapse( pCursor );
1251 			else
1252 				Expand( pCursor );
1253 		}
1254 
1255 		DoubleClickHdl();
1256 	}
1257 	else if (rKEvt.GetKeyCode().GetCode() == KEY_SPACE)
1258 	{
1259 	   if(bisInSdNavigatorWin)
1260 	   {
1261 		   sal_Bool bMarked=sal_False;
1262 		   SvLBoxEntry* pNewEntry = GetCurEntry();
1263 		   if( GetParent(pNewEntry) == NULL )
1264 			   return;
1265 		   String  aStr=GetSelectEntry();
1266 		   Window* pWindow=NULL;
1267 		   SdNavigatorWin* pSdNavigatorWin=NULL;
1268 		   sd::DrawDocShell* pSdDrawDocShell = NULL;
1269 		   if(pNewEntry)
1270 			   pWindow=(Window*)GetParent(pNewEntry);
1271 		   if(pWindow)
1272 			   pSdNavigatorWin = (SdNavigatorWin*)pWindow;
1273 		   if( pSdNavigatorWin )
1274 			   pSdDrawDocShell = pSdNavigatorWin->GetDrawDocShell(mpDoc);
1275 		   if(pSdDrawDocShell)
1276 		   {
1277 			   pSdDrawDocShell->GotoTreeBookmark(aStr);
1278 			   bMarked=pSdDrawDocShell->GetObjectIsmarked(aStr);
1279 		   }
1280 		   //Removed by yanjun for sym2_6385
1281 		   //The symphony2.0 can support morn than one level tree list, also support to select tow or more items in different level.
1282 		   /*
1283 		   SvLBoxEntry* pBeginEntry = First();
1284 		   if( pBeginEntry )
1285 		   {
1286 			   if( GetParent(pBeginEntry) !=  GetParent(pNewEntry) )
1287 				   pBeginEntry->SetMarked( sal_False );
1288 			   SvLBoxEntry* pNextEntry = Next( pBeginEntry );
1289 			   while( pNextEntry )
1290 			   {
1291 				   if( GetParent(pNextEntry) !=  GetParent(pNewEntry) )
1292 					   pNextEntry->SetMarked( sal_False );
1293 				   pNextEntry =  Next( pNextEntry );
1294 			   }
1295 		   }
1296 		   End*/
1297 		   if(pNewEntry)
1298 		   {
1299 			   if(bMarked)
1300 			   {
1301 				   pNewEntry->SetMarked(sal_True);
1302 			   }
1303 			   else
1304 			   {
1305 				   pNewEntry->SetMarked( sal_False );
1306 			   }
1307 		   }
1308 		   Invalidate();
1309 	   }
1310 	}
1311 	else
1312 		SvTreeListBox::KeyInput( rKEvt );
1313 }
1314 
1315 /*************************************************************************
1316 |*
1317 |* StartDrag-Request
1318 |*
1319 \************************************************************************/
1320 
StartDrag(sal_Int8 nAction,const Point & rPosPixel)1321 void SdPageObjsTLB::StartDrag( sal_Int8 nAction, const Point& rPosPixel)
1322 {
1323     (void)nAction;
1324     (void)rPosPixel;
1325 
1326 	SdNavigatorWin* pNavWin = NULL;
1327     SvLBoxEntry* pEntry = GetEntry(rPosPixel);
1328 
1329 	if( mpFrame->HasChildWindow( SID_NAVIGATOR ) )
1330 		pNavWin = (SdNavigatorWin*) ( mpFrame->GetChildWindow( SID_NAVIGATOR )->GetContextWindow( SD_MOD() ) );
1331 
1332 	if (pEntry != NULL
1333         && pNavWin !=NULL
1334         && pNavWin == mpParent
1335         && pNavWin->GetNavigatorDragType() != NAVIGATOR_DRAGTYPE_NONE )
1336 	{
1337         // Mark only the children of the page under the mouse as drop
1338         // targets.  This prevents moving shapes from one page to another.
1339 
1340         // Select all entries and disable them as drop targets.
1341         SetSelectionMode(MULTIPLE_SELECTION);
1342         SetCursor(NULL, sal_False);
1343         SelectAll(sal_True, sal_False);
1344         EnableSelectionAsDropTarget(sal_False, sal_True);
1345 
1346         // Enable only the entries as drop targets that are children of the
1347         // page under the mouse.
1348         SvLBoxEntry* pParent = GetRootLevelParent(pEntry);
1349         if (pParent != NULL)
1350         {
1351             SelectAll(sal_False, sal_False);
1352             Select(pParent, sal_True);
1353             //            for (SvLBoxEntry*pChild=FirstChild(pParent); pChild!=NULL; pChild=NextSibling(pChild))
1354             //                Select(pChild, sal_True);
1355             EnableSelectionAsDropTarget(sal_True, sal_True);//sal_False);
1356         }
1357 
1358         // Set selection back to the entry under the mouse.
1359         SelectAll(sal_False,sal_False);
1360         SetSelectionMode(SINGLE_SELECTION);
1361         Select(pEntry, sal_True);
1362 
1363 		//  Aus dem ExecuteDrag heraus kann der Navigator geloescht werden
1364 		//  (beim Umschalten auf einen anderen Dokument-Typ), das wuerde aber
1365 		//  den StarView MouseMove-Handler, der Command() aufruft, umbringen.
1366 		//  Deshalb Drag&Drop asynchron:
1367         Application::PostUserEvent( STATIC_LINK( this, SdPageObjsTLB, ExecDragHdl ) );
1368 	}
1369 }
1370 
1371 /*************************************************************************
1372 |*
1373 |* Begin drag
1374 |*
1375 \************************************************************************/
1376 
DoDrag()1377 void SdPageObjsTLB::DoDrag()
1378 {
1379 	mpDropNavWin = ( mpFrame->HasChildWindow( SID_NAVIGATOR ) ) ?
1380 				  (SdNavigatorWin*)( mpFrame->GetChildWindow( SID_NAVIGATOR )->GetContextWindow( SD_MOD() ) ) :
1381 				  NULL;
1382 
1383 	if( mpDropNavWin )
1384 	{
1385 		::sd::DrawDocShell* pDocShell = mpDoc->GetDocSh();
1386         String aURL = INetURLObject( pDocShell->GetMedium()->GetPhysicalName(), INET_PROT_FILE ).GetMainURL( INetURLObject::NO_DECODE );
1387 		NavigatorDragType	eDragType = mpDropNavWin->GetNavigatorDragType();
1388 
1389 		aURL.Append( '#' );
1390 		aURL.Append( GetSelectEntry() );
1391 
1392 		INetBookmark	aBookmark( aURL, GetSelectEntry() );
1393 		sal_Int8		nDNDActions = DND_ACTION_COPYMOVE;
1394 
1395 		if( eDragType == NAVIGATOR_DRAGTYPE_LINK )
1396 			nDNDActions = DND_ACTION_LINK;	// #93240# Either COPY *or* LINK, never both!
1397         else if (mpDoc->GetSdPageCount(PK_STANDARD) == 1)
1398         {
1399             // Can not move away the last slide in a document.
1400             nDNDActions = DND_ACTION_COPY;
1401         }
1402 
1403 		SvTreeListBox::ReleaseMouse();
1404 
1405 		bIsInDrag = sal_True;
1406 
1407         SvLBoxDDInfo aDDInfo;
1408         memset(&aDDInfo,0,sizeof(SvLBoxDDInfo));
1409         aDDInfo.pApp = GetpApp();
1410         aDDInfo.pSource = this;
1411         //            aDDInfo.pDDStartEntry = pEntry;
1412 		::com::sun::star::uno::Sequence<sal_Int8> aSequence (sizeof(SvLBoxDDInfo));
1413 		memcpy(aSequence.getArray(), (sal_Char*)&aDDInfo, sizeof(SvLBoxDDInfo));
1414 		::com::sun::star::uno::Any aTreeListBoxData (aSequence);
1415 
1416 		// object is destroyed by internal reference mechanism
1417 		SdTransferable* pTransferable = new SdPageObjsTLB::SdPageObjsTransferable(
1418             *this, aBookmark, *pDocShell, eDragType, aTreeListBoxData);
1419 
1420         // Get the view.
1421         ::sd::ViewShell* pViewShell = GetViewShellForDocShell(*pDocShell);
1422         if (pViewShell == NULL)
1423         {
1424             OSL_ASSERT(pViewShell!=NULL);
1425             return;
1426         }
1427         sd::View* pView = pViewShell->GetView();
1428         if (pView == NULL)
1429         {
1430             OSL_ASSERT(pView!=NULL);
1431             return;
1432         }
1433 
1434         SdrObject* pObject = NULL;
1435         void* pUserData = GetCurEntry()->GetUserData();
1436         if (pUserData != NULL && pUserData != (void*)1)
1437             pObject = reinterpret_cast<SdrObject*>(pUserData);
1438         if (pObject != NULL)
1439         {
1440             // For shapes without a user supplied name (the automatically
1441             // created name does not count), a different drag and drop technique
1442             // is used.
1443             if (GetObjectName(pObject, false).Len() == 0)
1444             {
1445                 AddShapeToTransferable(*pTransferable, *pObject);
1446                 pTransferable->SetView(pView);
1447                 SD_MOD()->pTransferDrag = pTransferable;
1448             }
1449 
1450             // Unnamed shapes have to be selected to be recognized by the
1451             // current drop implementation.  In order to have a consistent
1452             // behaviour for all shapes, every shape that is to be dragged is
1453             // selected first.
1454             SdrPageView* pPageView = pView->GetSdrPageView();
1455             pView->UnmarkAllObj(pPageView);
1456             pView->MarkObj(pObject, pPageView);
1457         }
1458         else
1459         {
1460             pTransferable->SetView(pView);
1461             SD_MOD()->pTransferDrag = pTransferable;
1462         }
1463 
1464         pTransferable->StartDrag( this, nDNDActions );
1465 	}
1466 }
1467 
1468 /*************************************************************************
1469 |*
1470 |* Drag finished
1471 |*
1472 \************************************************************************/
1473 
OnDragFinished(sal_uInt8)1474 void SdPageObjsTLB::OnDragFinished( sal_uInt8 )
1475 {
1476 	if( mpFrame->HasChildWindow( SID_NAVIGATOR ) )
1477 	{
1478 		SdNavigatorWin* pNewNavWin = (SdNavigatorWin*) ( mpFrame->GetChildWindow( SID_NAVIGATOR )->GetContextWindow( SD_MOD() ) );
1479 
1480 		if( mpDropNavWin == pNewNavWin)
1481 		{
1482 			MouseEvent aMEvt( mpDropNavWin->GetPointerPosPixel() );
1483 			SvTreeListBox::MouseButtonUp( aMEvt );
1484 		}
1485 	}
1486 
1487 	mpDropNavWin = NULL;
1488 	bIsInDrag = sal_False;
1489 }
1490 
1491 /*************************************************************************
1492 |*
1493 |* AcceptDrop-Event
1494 |*
1495 \************************************************************************/
1496 
AcceptDrop(const AcceptDropEvent & rEvent)1497 sal_Int8 SdPageObjsTLB::AcceptDrop (const AcceptDropEvent& rEvent)
1498 {
1499     sal_Int8 nResult (DND_ACTION_NONE);
1500 
1501 	if ( !bIsInDrag && IsDropFormatSupported( FORMAT_FILE ) )
1502     {
1503         nResult = rEvent.mnAction;
1504     }
1505     else
1506     {
1507         SvLBoxEntry* pEntry = GetDropTarget(rEvent.maPosPixel);
1508         if (rEvent.mbLeaving || !CheckDragAndDropMode( this, rEvent.mnAction ))
1509         {
1510             ImplShowTargetEmphasis( pTargetEntry, sal_False );
1511         }
1512         else if( !nDragDropMode )
1513         {
1514             DBG_ERRORFILE( "SdPageObjsTLB::AcceptDrop(): no target" );
1515         }
1516         else if (IsDropAllowed(pEntry))
1517         {
1518             nResult = DND_ACTION_MOVE;
1519 
1520             // Draw emphasis.
1521             if (pEntry != pTargetEntry || !(nImpFlags & SVLBOX_TARGEMPH_VIS))
1522             {
1523                 ImplShowTargetEmphasis( pTargetEntry, sal_False );
1524                 pTargetEntry = pEntry;
1525                 ImplShowTargetEmphasis( pTargetEntry, sal_True );
1526             }
1527         }
1528     }
1529 
1530     // Hide emphasis when there is no valid drop action.
1531     if (nResult == DND_ACTION_NONE)
1532         ImplShowTargetEmphasis(pTargetEntry, sal_False);
1533 
1534     return nResult;
1535 }
1536 
1537 /*************************************************************************
1538 |*
1539 |* ExecuteDrop-Event
1540 |*
1541 \************************************************************************/
1542 
ExecuteDrop(const ExecuteDropEvent & rEvt)1543 sal_Int8 SdPageObjsTLB::ExecuteDrop( const ExecuteDropEvent& rEvt )
1544 {
1545 	sal_Int8 nRet = DND_ACTION_NONE;
1546 
1547     try
1548     {
1549         if( !bIsInDrag )
1550         {
1551             SdNavigatorWin* pNavWin = NULL;
1552             sal_uInt16			nId = SID_NAVIGATOR;
1553 
1554             if( mpFrame->HasChildWindow( nId ) )
1555                 pNavWin = (SdNavigatorWin*)( mpFrame->GetChildWindow( nId )->GetContextWindow( SD_MOD() ) );
1556 
1557             if( pNavWin && ( pNavWin == mpParent ) )
1558             {
1559                 TransferableDataHelper	aDataHelper( rEvt.maDropEvent.Transferable );
1560                 String					aFile;
1561 
1562                 if( aDataHelper.GetString( FORMAT_FILE, aFile ) &&
1563                     ( (SdNavigatorWin*) mpParent)->InsertFile( aFile ) )
1564                 {
1565                     nRet = rEvt.mnAction;
1566                 }
1567             }
1568         }
1569     }
1570     catch (com::sun::star::uno::Exception&)
1571     {
1572         DBG_UNHANDLED_EXCEPTION();
1573     }
1574 
1575     if (nRet == DND_ACTION_NONE)
1576         SvTreeListBox::ExecuteDrop(rEvt, this);
1577 
1578 
1579 	return nRet;
1580 }
1581 
1582 /*************************************************************************
1583 |*
1584 |* Handler fuers Dragging
1585 |*
1586 \************************************************************************/
1587 
IMPL_STATIC_LINK(SdPageObjsTLB,ExecDragHdl,void *,EMPTYARG)1588 IMPL_STATIC_LINK(SdPageObjsTLB, ExecDragHdl, void*, EMPTYARG)
1589 {
1590 	//	als Link, damit asynchron ohne ImpMouseMoveMsg auf dem Stack auch der
1591 	//	Navigator geloescht werden darf
1592 	pThis->DoDrag();
1593 	return 0;
1594 }
1595 
1596 
PageBelongsToCurrentShow(const SdPage * pPage) const1597 bool SdPageObjsTLB::PageBelongsToCurrentShow (const SdPage* pPage) const
1598 {
1599     // Return <TRUE/> as default when there is no custom show or when none
1600     // is used.  The page does then belong to the standard show.
1601     bool bBelongsToShow = true;
1602 
1603     if (mpDoc->getPresentationSettings().mbCustomShow)
1604     {
1605         // Get the current custom show.
1606         SdCustomShow* pCustomShow = NULL;
1607         List* pShowList = const_cast<SdDrawDocument*>(mpDoc)->GetCustomShowList();
1608         if (pShowList != NULL)
1609         {
1610             sal_uLong nCurrentShowIndex = pShowList->GetCurPos();
1611             void* pObject = pShowList->GetObject(nCurrentShowIndex);
1612             pCustomShow = static_cast<SdCustomShow*>(pObject);
1613         }
1614 
1615         // Check whether the given page is part of that custom show.
1616         if (pCustomShow != NULL)
1617         {
1618             bBelongsToShow = false;
1619             sal_uLong nPageCount = pCustomShow->Count();
1620             for (sal_uInt16 i=0; i<nPageCount && !bBelongsToShow; i++)
1621                 if (pPage == static_cast<SdPage*>(pCustomShow->GetObject (i)))
1622                     bBelongsToShow = true;
1623         }
1624     }
1625 
1626     return bBelongsToShow;
1627 }
1628 
1629 
1630 
1631 
NotifyMoving(SvLBoxEntry * pTarget,SvLBoxEntry * pEntry,SvLBoxEntry * & rpNewParent,sal_uLong & rNewChildPos)1632 sal_Bool SdPageObjsTLB::NotifyMoving(
1633     SvLBoxEntry* pTarget,
1634     SvLBoxEntry* pEntry,
1635     SvLBoxEntry*& rpNewParent,
1636     sal_uLong& rNewChildPos)
1637 {
1638     SvLBoxEntry* pDestination = pTarget;
1639     while (GetParent(pDestination) != NULL && GetParent(GetParent(pDestination)) != NULL)
1640         pDestination = GetParent(pDestination);
1641 
1642     SdrObject* pTargetObject = reinterpret_cast<SdrObject*>(pDestination->GetUserData());
1643     SdrObject* pSourceObject = reinterpret_cast<SdrObject*>(pEntry->GetUserData());
1644     if (pSourceObject == reinterpret_cast<SdrObject*>(1))
1645         pSourceObject = NULL;
1646 
1647     if (pTargetObject != NULL && pSourceObject != NULL)
1648     {
1649         SdrPage* pObjectList = pSourceObject->GetPage();
1650         if (pObjectList != NULL)
1651         {
1652             sal_uInt32 nNewPosition;
1653             if (pTargetObject == reinterpret_cast<SdrObject*>(1))
1654                 nNewPosition = 0;
1655             else
1656                 nNewPosition = pTargetObject->GetNavigationPosition() + 1;
1657             pObjectList->SetObjectNavigationPosition(*pSourceObject, nNewPosition);
1658         }
1659 
1660         // Update the tree list.
1661         if (pTarget == NULL)
1662         {
1663             rpNewParent = 0;
1664             rNewChildPos = 0;
1665             return sal_True;
1666         }
1667         else if (GetParent(pDestination) == NULL)
1668         {
1669             rpNewParent = pDestination;
1670             rNewChildPos = 0;
1671         }
1672         else
1673         {
1674             rpNewParent = GetParent(pDestination);
1675             rNewChildPos = pModel->GetRelPos(pDestination) + 1;
1676             rNewChildPos += nCurEntrySelPos;
1677             nCurEntrySelPos++;
1678         }
1679         return sal_True;
1680     }
1681     else
1682         return sal_False;
1683 }
1684 
1685 
1686 
1687 
GetDropTarget(const Point & rLocation)1688 SvLBoxEntry* SdPageObjsTLB::GetDropTarget (const Point& rLocation)
1689 {
1690     SvLBoxEntry* pEntry = SvTreeListBox::GetDropTarget(rLocation);
1691     if (pEntry == NULL)
1692         return NULL;
1693 
1694     if (GetParent(pEntry) == NULL)
1695     {
1696         // Use page entry as insertion position.
1697     }
1698     else
1699     {
1700         // Go to second hierarchy level, i.e. top level shapes,
1701         // i.e. children of pages.
1702         while (GetParent(pEntry) != NULL && GetParent(GetParent(pEntry)) != NULL)
1703             pEntry = GetParent(pEntry);
1704 
1705         // Advance to next sibling.
1706         SvLBoxEntry* pNext;
1707         sal_uInt16 nDepth (0);
1708         while (pEntry != NULL)
1709         {
1710             pNext = dynamic_cast<SvLBoxEntry*>(NextVisible(pEntry, &nDepth));
1711             if (pNext != NULL && nDepth > 0 && nDepth!=0xffff)
1712                 pEntry = pNext;
1713             else
1714                 break;
1715         }
1716     }
1717 
1718     return pEntry;
1719 }
1720 
1721 
1722 
1723 
IsDropAllowed(SvLBoxEntry * pEntry)1724 bool SdPageObjsTLB::IsDropAllowed (SvLBoxEntry* pEntry)
1725 {
1726     if (pEntry == NULL)
1727         return false;
1728 
1729     if ( ! IsDropFormatSupported(SdPageObjsTransferable::GetListBoxDropFormatId()))
1730         return false;
1731 
1732     if ((pEntry->GetFlags() & SV_ENTRYFLAG_DISABLE_DROP) != 0)
1733         return false;
1734 
1735     return true;
1736 }
1737 
1738 
1739 
1740 
AddShapeToTransferable(SdTransferable & rTransferable,SdrObject & rObject) const1741 void SdPageObjsTLB::AddShapeToTransferable (
1742     SdTransferable& rTransferable,
1743     SdrObject& rObject) const
1744 {
1745 	TransferableObjectDescriptor aObjectDescriptor;
1746     bool bIsDescriptorFillingPending (true);
1747 
1748     const SdrOle2Obj* pOleObject = dynamic_cast<const SdrOle2Obj*>(&rObject);
1749     if (pOleObject != NULL && pOleObject->GetObjRef().is())
1750     {
1751         // If object has no persistence it must be copied as part of the document
1752         try
1753         {
1754             uno::Reference< embed::XEmbedPersist > xPersObj (pOleObject->GetObjRef(), uno::UNO_QUERY );
1755             if (xPersObj.is() && xPersObj->hasEntry())
1756             {
1757                 SvEmbedTransferHelper::FillTransferableObjectDescriptor(
1758                     aObjectDescriptor,
1759                     pOleObject->GetObjRef(),
1760                     pOleObject->GetGraphic(),
1761                     pOleObject->GetAspect());
1762                 bIsDescriptorFillingPending = false;
1763             }
1764         }
1765         catch( uno::Exception& )
1766         {
1767         }
1768 	}
1769 
1770     ::sd::DrawDocShell* pDocShell = mpDoc->GetDocSh();
1771 	if (bIsDescriptorFillingPending && pDocShell!=NULL)
1772     {
1773         bIsDescriptorFillingPending = false;
1774         pDocShell->FillTransferableObjectDescriptor(aObjectDescriptor);
1775     }
1776 
1777     Point aDragPos (rObject.GetCurrentBoundRect().Center());
1778     //Point aDragPos (0,0);
1779 	aObjectDescriptor.maDragStartPos = aDragPos;
1780     //	aObjectDescriptor.maSize = GetAllMarkedRect().GetSize();
1781     if (pDocShell != NULL)
1782         aObjectDescriptor.maDisplayName = pDocShell->GetMedium()->GetURLObject().GetURLNoPass();
1783     else
1784         aObjectDescriptor.maDisplayName = String();
1785 	aObjectDescriptor.mbCanLink = sal_False;
1786 
1787 	rTransferable.SetStartPos(aDragPos);
1788 	rTransferable.SetObjectDescriptor( aObjectDescriptor );
1789 }
1790 
1791 
1792 
1793 
GetViewShellForDocShell(::sd::DrawDocShell & rDocShell)1794 ::sd::ViewShell* SdPageObjsTLB::GetViewShellForDocShell (::sd::DrawDocShell& rDocShell)
1795 {
1796     {
1797         ::sd::ViewShell* pViewShell = rDocShell.GetViewShell();
1798         if (pViewShell != NULL)
1799             return pViewShell;
1800     }
1801 
1802     try
1803     {
1804         // Get a component enumeration from the desktop and search it for documents.
1805         uno::Reference<lang::XMultiServiceFactory> xFactory (
1806             ::comphelper::getProcessServiceFactory ());
1807         if ( ! xFactory.is())
1808             return NULL;
1809 
1810         uno::Reference<frame::XDesktop> xDesktop (xFactory->createInstance (
1811                 ::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop")), uno::UNO_QUERY);
1812         if ( ! xDesktop.is())
1813             return NULL;
1814 
1815         uno::Reference<frame::XFramesSupplier> xFrameSupplier (xDesktop, uno::UNO_QUERY);
1816         if ( ! xFrameSupplier.is())
1817             return NULL;
1818 
1819         uno::Reference<container::XIndexAccess> xFrameAccess (xFrameSupplier->getFrames(), uno::UNO_QUERY);
1820         if ( ! xFrameAccess.is())
1821             return NULL;
1822 
1823         for (sal_Int32 nIndex=0,nCount=xFrameAccess->getCount(); nIndex<nCount; ++nIndex)
1824         {
1825             uno::Reference<frame::XFrame> xFrame;
1826             if ( ! (xFrameAccess->getByIndex(nIndex) >>= xFrame))
1827                 continue;
1828 
1829             ::sd::DrawController* pController = dynamic_cast<sd::DrawController*>(xFrame->getController().get());
1830             if (pController == NULL)
1831                 continue;
1832             ::sd::ViewShellBase* pBase = pController->GetViewShellBase();
1833             if (pBase == NULL)
1834                 continue;
1835             if (pBase->GetDocShell() != &rDocShell)
1836                 continue;
1837 
1838             const ::boost::shared_ptr<sd::ViewShell> pViewShell (pBase->GetMainViewShell());
1839             if (pViewShell)
1840                 return pViewShell.get();
1841         }
1842     }
1843     catch (uno::Exception e)
1844     {
1845         // When there is an exception then simply use the default value of
1846         // bIsEnabled and disable the controls.
1847     }
1848     return NULL;
1849 }
1850 
1851 
1852 
1853 
1854 //===== IconProvider ==========================================================
1855 
IconProvider(void)1856 SdPageObjsTLB::IconProvider::IconProvider (void)
1857     : maImgPage( BitmapEx( SdResId( BMP_PAGE ) ) ),
1858       maImgPageExcl( BitmapEx( SdResId( BMP_PAGE_EXCLUDED ) ) ),
1859       maImgPageObjsExcl( BitmapEx( SdResId( BMP_PAGEOBJS_EXCLUDED ) ) ),
1860       maImgPageObjs( BitmapEx( SdResId( BMP_PAGEOBJS ) ) ),
1861       maImgObjects( BitmapEx( SdResId( BMP_OBJECTS ) ) ),
1862       maImgGroup( BitmapEx( SdResId( BMP_GROUP ) ) ),
1863 
1864       maImgPageH( BitmapEx( SdResId( BMP_PAGE_H ) ) ),
1865       maImgPageExclH( BitmapEx( SdResId( BMP_PAGE_EXCLUDED_H ) ) ),
1866       maImgPageObjsExclH( BitmapEx( SdResId( BMP_PAGEOBJS_EXCLUDED_H ) ) ),
1867       maImgPageObjsH( BitmapEx( SdResId( BMP_PAGEOBJS_H ) ) ),
1868       maImgObjectsH( BitmapEx( SdResId( BMP_OBJECTS_H ) ) ),
1869       maImgGroupH( BitmapEx( SdResId( BMP_GROUP_H ) ) )
1870 {
1871 }
1872