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