xref: /trunk/main/sd/source/ui/dlg/navigatr.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 
28 #include <tools/urlobj.hxx>
29 #include <unotools/localfilehelper.hxx>
30 #include <sfx2/imgmgr.hxx>
31 #include <sfx2/fcontnr.hxx>
32 #include <svl/eitem.hxx>
33 #include <svl/stritem.hxx>
34 #include <sfx2/docfilt.hxx>
35 #include <sfx2/docfile.hxx>
36 #include <svl/intitem.hxx>
37 #include <sfx2/dispatch.hxx>
38 #include <svx/svxids.hrc>
39 #include <vcl/menu.hxx>
40 
41 #include <sfx2/viewfrm.hxx>
42 #include <sfx2/dockwin.hxx>
43 #include <sfx2/sfxresid.hxx>
44 
45 #include "pres.hxx"
46 #include "navigatr.hxx"
47 #include "navigatr.hrc"
48 #include "pgjump.hxx"
49 #include "app.hrc"
50 #include "strings.hrc"
51 #include "res_bmp.hrc"
52 #include "drawdoc.hxx"
53 #include "DrawDocShell.hxx"
54 #include "sdresid.hxx"
55 #include "ViewShell.hxx"
56 #include "ViewShellBase.hxx"
57 #include "DrawViewShell.hxx"
58 #include "slideshow.hxx"
59 #include "FrameView.hxx"
60 #include "helpids.h"
61 
62 namespace {
63 static const sal_uInt16 nShowNamedShapesFilter=1;
64 static const sal_uInt16 nShowAllShapesFilter=2;
65 }
66 
67 /*************************************************************************
68 |*	SdNavigatorWin - FloatingWindow
69 \************************************************************************/
70 
SdNavigatorWin(::Window * pParent,::sd::NavigatorChildWindow * pChWinCtxt,const SdResId & rSdResId,SfxBindings * pInBindings,const UpdateRequestFunctor & rUpdateRequest)71 SdNavigatorWin::SdNavigatorWin(
72     ::Window* pParent,
73     ::sd::NavigatorChildWindow* pChWinCtxt,
74     const SdResId& rSdResId,
75     SfxBindings* pInBindings,
76     const UpdateRequestFunctor& rUpdateRequest)
77     : ::Window( pParent, rSdResId ),
78       maToolbox        ( this, SdResId( 1 ) ),
79       maTlbObjects( this, SdResId( TLB_OBJECTS ) ),
80       maLbDocs         ( this, SdResId( LB_DOCS ) ),
81       mpChildWinContext( pChWinCtxt ),
82       mbDocImported	( sal_False ),
83       // Bei Aenderung des DragTypes: SelectionMode der TLB anpassen!
84       meDragType		( NAVIGATOR_DRAGTYPE_EMBEDDED ),
85       mpBindings		( pInBindings ),
86       maImageList		( SdResId( IL_NAVIGATR ) ),
87       maImageListH	( SdResId( ILH_NAVIGATR ) )
88 {
89     maTlbObjects.SetViewFrame( mpBindings->GetDispatcher()->GetFrame() );
90 
91     FreeResource();
92 
93     maTlbObjects.SetAccessibleName(String(SdResId(STR_OBJECTS_TREE)));
94 
95     mpNavigatorCtrlItem = new SdNavigatorControllerItem( SID_NAVIGATOR_STATE, this, mpBindings, rUpdateRequest);
96     mpPageNameCtrlItem = new SdPageNameControllerItem( SID_NAVIGATOR_PAGENAME, this, mpBindings, rUpdateRequest);
97     mpDocList = new List();
98 
99     ApplyImageList(); // load images *before* calculating sizes to get something useful !!!
100 
101     Size aTbxSize( maToolbox.CalcWindowSizePixel() );
102     maToolbox.SetOutputSizePixel( aTbxSize );
103     maToolbox.SetSelectHdl( LINK( this, SdNavigatorWin, SelectToolboxHdl ) );
104     maToolbox.SetClickHdl( LINK( this, SdNavigatorWin, ClickToolboxHdl ) );
105     maToolbox.SetDropdownClickHdl( LINK(this, SdNavigatorWin, DropdownClickToolBoxHdl) );
106     maToolbox.SetItemBits( TBI_DRAGTYPE, maToolbox.GetItemBits( TBI_DRAGTYPE ) | TIB_DROPDOWNONLY );
107 
108     // Shape filter drop down menu.
109     maToolbox.SetItemBits(
110         TBI_SHAPE_FILTER,
111         maToolbox.GetItemBits(TBI_SHAPE_FILTER) | TIB_DROPDOWNONLY);
112 
113     // TreeListBox
114     // set position below toolbox
115     long nListboxYPos = maToolbox.GetPosPixel().Y() + maToolbox.GetSizePixel().Height() + 4;
116     maTlbObjects.SetPosSizePixel( 0, nListboxYPos, 0, 0, WINDOW_POSSIZE_Y );
117     maTlbObjects.SetDoubleClickHdl( LINK( this, SdNavigatorWin, ClickObjectHdl ) );
118     maTlbObjects.SetSelectionMode( SINGLE_SELECTION );
119     // set focus to listbox, otherwise it is in the toolbox which is only useful
120     // for keyboard navigation
121     maTlbObjects.GrabFocus();
122        maTlbObjects.SetSdNavigatorWinFlag(sal_True);
123 
124     // DragTypeListBox
125     maLbDocs.SetSelectHdl( LINK( this, SdNavigatorWin, SelectDocumentHdl ) );
126     // set position below treelistbox
127     nListboxYPos = maTlbObjects.GetPosPixel().Y() + maTlbObjects.GetSizePixel().Height() + 4;
128     maLbDocs.SetPosSizePixel( 0, nListboxYPos, 0, 0, WINDOW_POSSIZE_Y );
129 
130     // assure that tool box is at least as wide as the tree list box
131     {
132         const Size aTlbSize( maTlbObjects.GetOutputSizePixel() );
133         if ( aTlbSize.Width() > aTbxSize.Width() )
134         {
135             maToolbox.SetPosSizePixel( 0, 0, aTlbSize.Width(), 0, WINDOW_POSSIZE_WIDTH );
136             aTbxSize = maToolbox.GetOutputSizePixel();
137         }
138     }
139 
140     // set min outputsize after all sizes are known
141     const long nFullHeight = nListboxYPos + maLbDocs.GetSizePixel().Height() + 4;
142     maSize = GetOutputSizePixel();
143     if( maSize.Height() < nFullHeight )
144     {
145         maSize.Height() = nFullHeight;
146         SetOutputSizePixel( maSize );
147     }
148     maMinSize = maSize;
149     const long nMinWidth = 2*maToolbox.GetPosPixel().X() + aTbxSize.Width(); // never clip the toolbox
150     if( nMinWidth > maMinSize.Width() )
151         maMinSize.Width() = nMinWidth;
152     maMinSize.Height() -= 40;
153     SfxDockingWindow* pDockingParent = dynamic_cast<SfxDockingWindow*>(GetParent());
154     if (pDockingParent != NULL)
155         pDockingParent->SetMinOutputSizePixel( maMinSize );
156 
157     // InitTlb; Wird ueber Slot initiiert
158     if (rUpdateRequest)
159         rUpdateRequest();
160 }
161 
162 // -----------------------------------------------------------------------
163 
~SdNavigatorWin()164 SdNavigatorWin::~SdNavigatorWin()
165 {
166 	delete mpNavigatorCtrlItem;
167 	delete mpPageNameCtrlItem;
168 
169 	// Liste der DocInfos loeschen
170 	long nCount = mpDocList->Count();
171 	while( nCount-- )
172 		delete (NavDocInfo*) mpDocList->Remove( (sal_uLong)0 );
173 
174 	delete mpDocList;
175 }
176 
177 // -----------------------------------------------------------------------
178 
179 //Solution: when object is marked , fresh the corresponding entry tree .
180 //==================================================
FreshTree(const SdDrawDocument * pDoc)181 void SdNavigatorWin::FreshTree( const SdDrawDocument* pDoc )
182 {
183 	SdDrawDocument* pNonConstDoc = (SdDrawDocument*) pDoc; // const as const can...
184 	sd::DrawDocShell* pDocShell = pNonConstDoc->GetDocSh();
185 	String aDocShName( pDocShell->GetName() );
186 	String aDocName = pDocShell->GetMedium()->GetName();
187 	maTlbObjects.SetSaveTreeItemStateFlag(sal_True); //Added by yanjun for sym2_6385
188 	maTlbObjects.Clear();
189 	maTlbObjects.Fill( pDoc, sal_False, aDocName ); // Nur normale Seiten
190 	maTlbObjects.SetSaveTreeItemStateFlag(sal_False); //Added by yanjun for sym2_6385
191 	RefreshDocumentLB();
192 	maLbDocs.SelectEntry( aDocShName );
193 }
FreshEntry()194 void SdNavigatorWin::FreshEntry( )
195 {
196 	maTlbObjects.FreshCurEntry();
197 }
198 //==================================================
InitTreeLB(const SdDrawDocument * pDoc)199 void SdNavigatorWin::InitTreeLB( const SdDrawDocument* pDoc )
200 {
201 	SdDrawDocument* pNonConstDoc = (SdDrawDocument*) pDoc; // const as const can...
202 	::sd::DrawDocShell* pDocShell = pNonConstDoc->GetDocSh();
203 	String aDocShName( pDocShell->GetName() );
204 	::sd::ViewShell* pViewShell = pDocShell->GetViewShell();
205 
206     // Restore the 'ShowAllShapes' flag from the last time (in this session)
207     // that the navigator was shown.
208     if (pViewShell != NULL)
209     {
210         ::sd::FrameView* pFrameView = pViewShell->GetFrameView();
211         if (pFrameView != NULL)
212             maTlbObjects.SetShowAllShapes(pFrameView->IsNavigatorShowingAllShapes(), false);
213     }
214 
215     // Disable the shape filter drop down menu when there is a running slide
216     // show.
217 	if (pViewShell!=NULL && sd::SlideShow::IsRunning( pViewShell->GetViewShellBase() ))
218         maToolbox.EnableItem(TBI_SHAPE_FILTER, sal_False);
219     else
220         maToolbox.EnableItem(TBI_SHAPE_FILTER);
221 
222 	if( !maTlbObjects.IsEqualToDoc( pDoc ) )
223 	{
224 		String aDocName = pDocShell->GetMedium()->GetName();
225 		maTlbObjects.Clear();
226 		maTlbObjects.Fill( pDoc, (sal_Bool) sal_False, aDocName ); // Nur normale Seiten
227 
228 		RefreshDocumentLB();
229 		maLbDocs.SelectEntry( aDocShName );
230 	}
231 	else
232 	{
233 		maLbDocs.SetNoSelection();
234 		maLbDocs.SelectEntry( aDocShName );
235 
236 // auskommentiert um 30246 zu fixen
237 //		  if( maLbDocs.GetSelectEntryCount() == 0 )
238 		{
239 			RefreshDocumentLB();
240 			maLbDocs.SelectEntry( aDocShName );
241 		}
242 	}
243 
244 	SfxViewFrame* pViewFrame = ( ( pViewShell && pViewShell->GetViewFrame() ) ? pViewShell->GetViewFrame() : SfxViewFrame::Current() );
245 	if( pViewFrame )
246 		pViewFrame->GetBindings().Invalidate(SID_NAVIGATOR_PAGENAME, sal_True, sal_True);
247 }
248 
249 /*************************************************************************
250 |*
251 |* DragType wird in Abhaengigkeit davon gesetzt, ob ein Drag ueberhaupt
252 |* moeglich ist. Graphiken duerfen beispielsweise unter gewissen Umstaenden
253 |* nicht gedragt werden (#31038#).
254 |*
255 \************************************************************************/
256 
GetNavigatorDragType()257 NavigatorDragType SdNavigatorWin::GetNavigatorDragType()
258 {
259 	NavigatorDragType   eDT = meDragType;
260 	NavDocInfo*         pInfo = GetDocInfo();
261 
262 	if( ( eDT == NAVIGATOR_DRAGTYPE_LINK ) && ( ( pInfo && !pInfo->HasName() ) || !maTlbObjects.IsLinkableSelected() ) )
263 		eDT = NAVIGATOR_DRAGTYPE_NONE;
264 
265 	return( eDT );
266 }
267 
268 // -----------------------------------------------------------------------
269 //Solution: Get  SdDrawDocShell
GetDrawDocShell(const SdDrawDocument * pDoc)270 sd::DrawDocShell* SdNavigatorWin::GetDrawDocShell( const SdDrawDocument* pDoc )
271 {
272 	if( !pDoc )
273 		return NULL; // const as const can...
274 	sd::DrawDocShell* pDocShell = pDoc->GetDocSh();
275 	return pDocShell;
276 }
277 
IMPL_LINK(SdNavigatorWin,SelectToolboxHdl,void *,EMPTYARG)278 IMPL_LINK( SdNavigatorWin, SelectToolboxHdl, void *, EMPTYARG )
279 {
280 	sal_uInt16 nId = maToolbox.GetCurItemId();
281 	sal_uInt16 nSId = 0;
282 	PageJump ePage = PAGE_NONE;
283 
284 	switch( nId )
285 	{
286 		case TBI_PEN:
287 		{
288 			if( nId == TBI_PEN )
289 			{
290 				nSId = SID_NAVIGATOR_PEN;
291 			}
292 
293 			if( nSId > 0 )
294 			{
295 				SfxBoolItem aItem( nSId, sal_True );
296 				mpBindings->GetDispatcher()->Execute(
297 					nSId, SFX_CALLMODE_SLOT |SFX_CALLMODE_RECORD, &aItem, 0L );
298 			}
299 		}
300 		break;
301 
302 		case TBI_FIRST:
303 		case TBI_PREVIOUS:
304 		case TBI_NEXT:
305 		case TBI_LAST:
306 		{
307 			if( nId == TBI_FIRST )
308 				ePage = PAGE_FIRST;
309 			else if( nId == TBI_PREVIOUS )
310 				ePage = PAGE_PREVIOUS;
311 			else if( nId == TBI_NEXT )
312 				ePage = PAGE_NEXT;
313 			else if( nId == TBI_LAST )
314 				ePage = PAGE_LAST;
315 
316 			if( ePage != PAGE_NONE )
317 			{
318 				SfxUInt16Item aItem( SID_NAVIGATOR_PAGE, (sal_uInt16)ePage );
319 				mpBindings->GetDispatcher()->Execute(
320 					SID_NAVIGATOR_PAGE, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD, &aItem, 0L );
321 			}
322 		}
323 		break;
324 	}
325 	return 0;
326 }
327 
328 // -----------------------------------------------------------------------
329 
330 
IMPL_LINK(SdNavigatorWin,ClickToolboxHdl,ToolBox *,EMPTYARG)331 IMPL_LINK( SdNavigatorWin, ClickToolboxHdl, ToolBox*, EMPTYARG )
332 {
333 	return 0;
334 }
335 
336 // -----------------------------------------------------------------------
337 
IMPL_LINK(SdNavigatorWin,DropdownClickToolBoxHdl,ToolBox *,pBox)338 IMPL_LINK( SdNavigatorWin, DropdownClickToolBoxHdl, ToolBox*, pBox )
339 {
340 	sal_uInt16 nId = maToolbox.GetCurItemId();
341 
342 	switch( nId )
343 	{
344 		case TBI_DRAGTYPE:
345 		{
346 			// Popup-Menu wird in Abhaengigkeit davon erzeugt, ob Dokument
347 			// gespeichert ist oder nicht
348 			PopupMenu *pMenu = new PopupMenu;
349 
350             static const char* aHIDs[] =
351             {
352                  HID_SD_NAVIGATOR_MENU1,
353                  HID_SD_NAVIGATOR_MENU2,
354                  HID_SD_NAVIGATOR_MENU3,
355                  0
356             };
357 
358 			for( sal_uInt16 nID = NAVIGATOR_DRAGTYPE_URL;
359 				 nID < NAVIGATOR_DRAGTYPE_COUNT;
360 				 nID++ )
361 			{
362 				sal_uInt16 nRId = GetDragTypeSdResId( (NavigatorDragType)nID );
363 				if( nRId > 0 )
364 				{
365                     DBG_ASSERT(aHIDs[nID-NAVIGATOR_DRAGTYPE_URL],"HelpId not added!");
366 					pMenu->InsertItem( nID, String( SdResId( nRId ) ) );
367 					pMenu->SetHelpId( nID, aHIDs[nID - NAVIGATOR_DRAGTYPE_URL] );
368 				}
369 
370 			}
371 			NavDocInfo* pInfo = GetDocInfo();
372 
373 			if( ( pInfo && !pInfo->HasName() ) || !maTlbObjects.IsLinkableSelected() )
374 			{
375 				pMenu->EnableItem( NAVIGATOR_DRAGTYPE_LINK, sal_False );
376 				pMenu->EnableItem( NAVIGATOR_DRAGTYPE_URL, sal_False );
377 				meDragType = NAVIGATOR_DRAGTYPE_EMBEDDED;
378 			}
379 
380 			pMenu->CheckItem( (sal_uInt16)meDragType );
381 			pMenu->SetSelectHdl( LINK( this, SdNavigatorWin, MenuSelectHdl ) );
382 
383 			pMenu->Execute( this, maToolbox.GetItemRect( nId ), POPUPMENU_EXECUTE_DOWN );
384 			pBox->EndSelection();
385 			delete pMenu;
386 		}
387 		break;
388 
389 		case TBI_SHAPE_FILTER:
390 		{
391 			PopupMenu *pMenu = new PopupMenu;
392 
393             pMenu->InsertItem(
394                 nShowNamedShapesFilter,
395                 String(SdResId(STR_NAVIGATOR_SHOW_NAMED_SHAPES)));
396             pMenu->InsertItem(
397                 nShowAllShapesFilter,
398                 String(SdResId(STR_NAVIGATOR_SHOW_ALL_SHAPES)));
399 
400             if (maTlbObjects.GetShowAllShapes())
401                 pMenu->CheckItem(nShowAllShapesFilter);
402             else
403                 pMenu->CheckItem(nShowNamedShapesFilter);
404 			pMenu->SetSelectHdl( LINK( this, SdNavigatorWin, ShapeFilterCallback ) );
405 
406 			pMenu->Execute( this, maToolbox.GetItemRect( nId ), POPUPMENU_EXECUTE_DOWN );
407 			pBox->EndSelection();
408 			delete pMenu;
409 		}
410 		break;
411 	}
412 	return 0;
413 }
414 
415 // -----------------------------------------------------------------------
416 
IMPL_LINK(SdNavigatorWin,ClickObjectHdl,void *,EMPTYARG)417 IMPL_LINK( SdNavigatorWin, ClickObjectHdl, void *, EMPTYARG )
418 {
419 	if( !mbDocImported || maLbDocs.GetSelectEntryPos() != 0 )
420 	{
421 		NavDocInfo* pInfo = GetDocInfo();
422 
423 		// Nur wenn es sich um das aktive Fenster handelt, wird
424 		// auf die Seite gesprungen
425 		if( pInfo && pInfo->IsActive() )
426 		{
427 			String aStr( maTlbObjects.GetSelectEntry() );
428 
429 			if( aStr.Len() > 0 )
430 			{
431 				SfxStringItem aItem( SID_NAVIGATOR_OBJECT, aStr );
432 				mpBindings->GetDispatcher()->Execute(
433 					SID_NAVIGATOR_OBJECT, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD, &aItem, 0L );
434 				//Solution: set sign variable
435 				maTlbObjects.MarkCurEntry(aStr);
436 
437                 // #98821# moved here from SetGetFocusHdl. Reset the
438                 // focus only if something has been selected in the
439                 // document.
440                 SfxViewShell* pCurSh = SfxViewShell::Current();
441 
442                 if ( pCurSh )
443                 {
444                     Window* pShellWnd = pCurSh->GetWindow();
445                     if ( pShellWnd )
446                         pShellWnd->GrabFocus();
447                 }
448 			}
449 		}
450 	}
451 	return( 0L );
452 }
453 
454 // -----------------------------------------------------------------------
455 
IMPL_LINK(SdNavigatorWin,SelectDocumentHdl,void *,EMPTYARG)456 IMPL_LINK( SdNavigatorWin, SelectDocumentHdl, void *, EMPTYARG )
457 {
458 	String aStrLb = maLbDocs.GetSelectEntry();
459 	long   nPos = maLbDocs.GetSelectEntryPos();
460 	sal_Bool   bFound = sal_False;
461 	::sd::DrawDocShell* pDocShell = NULL;
462 	NavDocInfo* pInfo = GetDocInfo();
463 
464 	// Handelt es sich um ein gedragtes Objekt?
465 	if( mbDocImported && nPos == 0 )
466 	{
467 		// Dokument in TLB aufbauen
468 		InsertFile( aStrLb );
469 	}
470 	else if (pInfo)
471 	{
472 		pDocShell = pInfo->mpDocShell;
473 
474 		bFound = sal_True;
475 	}
476 
477 	if( bFound )
478 	{
479 		SdDrawDocument* pDoc = pDocShell->GetDoc();
480 		if( !maTlbObjects.IsEqualToDoc( pDoc ) )
481 		{
482 			SdDrawDocument* pNonConstDoc = (SdDrawDocument*) pDoc; // const as const can...
483 			::sd::DrawDocShell* pNCDocShell = pNonConstDoc->GetDocSh();
484 			String aDocName = pNCDocShell->GetMedium()->GetName();
485 			maTlbObjects.Clear();
486 			maTlbObjects.Fill( pDoc, (sal_Bool) sal_False, aDocName ); // Nur normale Seiten
487 		}
488 	}
489 
490 	// Pruefen, ob Link oder URL moeglich ist
491 	if( ( pInfo && !pInfo->HasName() ) || !maTlbObjects.IsLinkableSelected() || ( meDragType != NAVIGATOR_DRAGTYPE_EMBEDDED ) )
492 	{
493 		meDragType = NAVIGATOR_DRAGTYPE_EMBEDDED;
494 		SetDragImage();
495 	}
496 
497 	return( 0L );
498 }
499 
500 /*************************************************************************
501 |*
502 |* DrageType wird gesetzt und Image wird entspr. gesetzt.
503 |* Sollte Handler mit NULL gerufen werden, so wird der Default (URL) gesetzt.
504 |*
505 \************************************************************************/
506 
IMPL_LINK(SdNavigatorWin,MenuSelectHdl,Menu *,pMenu)507 IMPL_LINK( SdNavigatorWin, MenuSelectHdl, Menu *, pMenu )
508 {
509 	sal_uInt16 nMenuId;
510 	if( pMenu )
511 		nMenuId = pMenu->GetCurItemId();
512 	else
513 		nMenuId = NAVIGATOR_DRAGTYPE_URL;
514 
515 	if( nMenuId != USHRT_MAX ) // Notwendig ?
516 	{
517 		NavigatorDragType eDT = (NavigatorDragType) nMenuId;
518 		if( meDragType != eDT )
519 		{
520 			meDragType = eDT;
521 			SetDragImage();
522 
523 			if( meDragType == NAVIGATOR_DRAGTYPE_URL )
524 			{
525 				// Fix, um Endlosschleife zu unterbinden
526 				if( maTlbObjects.GetSelectionCount() > 1 )
527 					maTlbObjects.SelectAll( sal_False );
528 
529 				maTlbObjects.SetSelectionMode( SINGLE_SELECTION );
530 			}
531 			else
532 				maTlbObjects.SetSelectionMode( MULTIPLE_SELECTION );
533 		}
534 	}
535 	return( 0 );
536 }
537 
538 
539 
540 
IMPL_LINK(SdNavigatorWin,ShapeFilterCallback,Menu *,pMenu)541 IMPL_LINK( SdNavigatorWin, ShapeFilterCallback, Menu *, pMenu )
542 {
543 	if (pMenu != NULL)
544     {
545         bool bShowAllShapes (maTlbObjects.GetShowAllShapes());
546         sal_uInt16 nMenuId (pMenu->GetCurItemId());
547         switch (nMenuId)
548         {
549             case nShowNamedShapesFilter:
550                 bShowAllShapes = false;
551                 break;
552 
553             case nShowAllShapesFilter:
554                 bShowAllShapes = true;
555                 break;
556 
557             default:
558                 OSL_ENSURE(
559                     false, "SdNavigatorWin::ShapeFilterCallback called for unknown menu entry");
560                 break;
561         }
562 
563         maTlbObjects.SetShowAllShapes(bShowAllShapes, true);
564 
565         // Remember the selection in the FrameView.
566         NavDocInfo* pInfo = GetDocInfo();
567         if (pInfo != NULL)
568         {
569             ::sd::DrawDocShell* pDocShell = pInfo->mpDocShell;
570             if (pDocShell != NULL)
571             {
572                 ::sd::ViewShell* pViewShell = pDocShell->GetViewShell();
573                 if (pViewShell != NULL)
574                 {
575                     ::sd::FrameView* pFrameView = pViewShell->GetFrameView();
576                     if (pFrameView != NULL)
577                     {
578                         pFrameView->SetIsNavigatorShowingAllShapes(bShowAllShapes);
579                     }
580                 }
581             }
582         }
583 	}
584 
585 	return 0;
586 }
587 
588 // -----------------------------------------------------------------------
589 
Resize()590 void SdNavigatorWin::Resize()
591 {
592 	Size aWinSize( GetOutputSizePixel() );
593 	if( aWinSize.Height() >= maMinSize.Height() )
594 		//aWinSize.Width() >= maMinSize.Width() )
595 	{
596 		Size aDiffSize;
597 		aDiffSize.Width() = aWinSize.Width() - maSize.Width();
598 		aDiffSize.Height() = aWinSize.Height() - maSize.Height();
599 
600 		// Umgroessern der Toolbox
601 		Size aObjSize( maToolbox.GetOutputSizePixel() );
602 		aObjSize.Width() += aDiffSize.Width();
603 		maToolbox.SetOutputSizePixel( aObjSize );
604 
605 		// Umgroessern der TreeLB
606 		aObjSize = maTlbObjects.Control::GetOutputSizePixel();
607 		aObjSize.Width() += aDiffSize.Width();
608 		aObjSize.Height() += aDiffSize.Height();
609 		maTlbObjects.SetOutputSizePixel( aObjSize );
610 
611 		Point aPt( 0, aDiffSize.Height() );
612 
613 		// Verschieben der anderen Controls (DocumentLB)
614 		maLbDocs.Hide();
615 		aObjSize = maLbDocs.GetOutputSizePixel();
616 		aObjSize.Width() += aDiffSize.Width();
617 		maLbDocs.SetPosPixel( maLbDocs.GetPosPixel() + aPt );
618 		maLbDocs.SetOutputSizePixel( aObjSize );
619 		maLbDocs.Show();
620 
621 		maSize = aWinSize;
622 	}
623 	Window::Resize();
624 }
625 
626 // -----------------------------------------------------------------------
627 
InsertFile(const String & rFileName)628 sal_Bool SdNavigatorWin::InsertFile(const String& rFileName)
629 {
630 	INetURLObject	aURL( rFileName );
631 	sal_Bool			bReturn = sal_True;
632 
633 	if( aURL.GetProtocol() == INET_PROT_NOT_VALID )
634 	{
635 		String aURLStr;
636 		::utl::LocalFileHelper::ConvertPhysicalNameToURL( rFileName, aURLStr );
637 		aURL = INetURLObject( aURLStr );
638 	}
639 
640 	// get adjusted FileName
641 	String aFileName( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
642 
643 	if (!aFileName.Len())
644 	{
645 		/**********************************************************************
646 		* Wieder aktuelles Dokument anzeigen
647 		**********************************************************************/
648 		maDropFileName = aFileName;
649 	}
650 	else
651 	{
652 		/**********************************************************************
653 		* Hineingedraggtes Dokument anzeigen
654 		**********************************************************************/
655 		const SfxFilter* pFilter = NULL;
656 		ErrCode nErr = 0;
657 
658 		if (aFileName != maDropFileName)
659 		{
660 			SfxMedium aMed(aFileName, (STREAM_READ | STREAM_SHARE_DENYNONE), sal_False);
661 			SfxFilterMatcher aMatch( String::CreateFromAscii("simpress") );
662             aMed.UseInteractionHandler( sal_True );
663 			nErr = aMatch.GuessFilter(aMed, &pFilter);
664 		}
665 
666 		if ((pFilter && !nErr) || aFileName == maDropFileName)
667 		{
668 			// Das Medium muss ggf. mit READ/WRITE geoeffnet werden, daher wird
669 			// ersteinmal nachgeschaut, ob es einen Storage enthaelt
670 			SfxMedium* pMedium = new SfxMedium( aFileName,
671 												STREAM_READ | STREAM_NOCREATE,
672 												sal_True);				  // Download
673 
674 			if (pMedium->IsStorage())
675 			{
676 				// Jetzt modusabhaengig:
677 				// maTlbObjects.SetSelectionMode(MULTIPLE_SELECTION);
678 				// Eigentuemeruebergabe von pMedium;
679 				SdDrawDocument* pDropDoc = maTlbObjects.GetBookmarkDoc(pMedium);
680 
681 				if (pDropDoc)
682 				{
683 					maTlbObjects.Clear();
684 					maDropFileName = aFileName;
685 
686 					if( !maTlbObjects.IsEqualToDoc( pDropDoc ) )
687 					{
688 						// Nur normale Seiten
689 						maTlbObjects.Fill(pDropDoc, (sal_Bool) sal_False, maDropFileName);
690 						RefreshDocumentLB( &maDropFileName );
691 					}
692 				}
693 			}
694 			else
695 			{
696 				bReturn = sal_False;
697 				delete pMedium;
698 			}
699 		}
700 		else
701 		{
702 			bReturn = sal_False;
703 		}
704 	}
705 
706 	return (bReturn);
707 }
708 
709 // -----------------------------------------------------------------------
710 
RefreshDocumentLB(const String * pDocName)711 void SdNavigatorWin::RefreshDocumentLB( const String* pDocName )
712 {
713 	sal_uInt16 nPos = 0;
714 
715 	if( pDocName )
716 	{
717 		if( mbDocImported )
718 			maLbDocs.RemoveEntry( 0 );
719 
720 		maLbDocs.InsertEntry( *pDocName, 0 );
721 		mbDocImported = sal_True;
722 	}
723 	else
724 	{
725 		nPos = maLbDocs.GetSelectEntryPos();
726 		if( nPos == LISTBOX_ENTRY_NOTFOUND )
727 			nPos = 0;
728 
729 		String aStr;
730 		if( mbDocImported )
731 			aStr = maLbDocs.GetEntry( 0 );
732 
733 		maLbDocs.Clear();
734 
735 		// Liste der DocInfos loeschen
736 		long nCount = mpDocList->Count();
737 		while( nCount-- )
738 			delete (NavDocInfo*) mpDocList->Remove( (sal_uLong)0 );
739 
740 		if( mbDocImported )
741 			maLbDocs.InsertEntry( aStr, 0 );
742 
743 		::sd::DrawDocShell* pCurrentDocShell =
744               PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current() );
745 		SfxObjectShell* pSfxDocShell = SfxObjectShell::GetFirst(0, sal_False);
746 		while( pSfxDocShell )
747 		{
748 			::sd::DrawDocShell* pDocShell = PTR_CAST(::sd::DrawDocShell, pSfxDocShell );
749 			if( pDocShell  && !pDocShell->IsInDestruction() && ( pDocShell->GetCreateMode() != SFX_CREATE_MODE_EMBEDDED ) )
750 			{
751 				NavDocInfo* pInfo = new NavDocInfo();
752 				pInfo->mpDocShell = pDocShell;
753 
754 				aStr = pDocShell->GetMedium()->GetName();
755 				if( aStr.Len() )
756 					pInfo->SetName();
757 				else
758 					pInfo->SetName( sal_False );
759 				// z.Z. wird wieder der Name der Shell genommen (also ohne Pfad)
760 				// da Koose es als Fehler ansieht, wenn er Pfad in URL-Notation
761 				// angezeigt wird!
762 				aStr = pDocShell->GetName();
763 
764 				maLbDocs.InsertEntry( aStr, LISTBOX_APPEND );
765 
766 				//
767 				if( pDocShell == pCurrentDocShell )
768 					pInfo->SetActive();
769 				else
770 					pInfo->SetActive( sal_False );
771 
772 				mpDocList->Insert( pInfo, LIST_APPEND );
773 			}
774 			pSfxDocShell = SfxObjectShell::GetNext( *pSfxDocShell, 0 , sal_False );
775 		}
776 	}
777 	maLbDocs.SelectEntryPos( nPos );
778 }
779 
780 //------------------------------------------------------------------------
781 
GetDragTypeSdResId(NavigatorDragType eDT,sal_Bool bImage)782 sal_uInt16 SdNavigatorWin::GetDragTypeSdResId( NavigatorDragType eDT, sal_Bool bImage )
783 {
784 	switch( eDT )
785 	{
786 		case NAVIGATOR_DRAGTYPE_NONE:
787 				return( bImage ? 0 : STR_NONE );
788 		case NAVIGATOR_DRAGTYPE_URL:
789 				return( bImage ? TBI_HYPERLINK : STR_DRAGTYPE_URL );
790 		case NAVIGATOR_DRAGTYPE_EMBEDDED:
791 				return( bImage ? TBI_EMBEDDED : STR_DRAGTYPE_EMBEDDED );
792 		case NAVIGATOR_DRAGTYPE_LINK:
793 				return( bImage ? TBI_LINK : STR_DRAGTYPE_LINK );
794 		default: DBG_ERROR( "Keine Resource fuer DragType vorhanden!" );
795 	}
796 	return( 0 );
797 }
798 
799 //------------------------------------------------------------------------
800 
GetDocInfo()801 NavDocInfo* SdNavigatorWin::GetDocInfo()
802 {
803 	long nPos = maLbDocs.GetSelectEntryPos();
804 
805 	if( mbDocImported )
806 	{
807 		if( nPos == 0 )
808 		{
809 			return( NULL );
810 		}
811 		nPos--;
812 	}
813 
814 	NavDocInfo* pInfo = (NavDocInfo*)mpDocList->GetObject( nPos );
815 
816 	return( pInfo );
817 }
818 
819 /*************************************************************************
820 |*
821 |* PreNotify
822 |*
823 \************************************************************************/
824 
Notify(NotifyEvent & rNEvt)825 long SdNavigatorWin::Notify(NotifyEvent& rNEvt)
826 {
827 	const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
828 	long			nOK = sal_False;
829 
830 	if( pKEvt )
831 	{
832 		if( KEY_ESCAPE == pKEvt->GetKeyCode().GetCode() )
833 		{
834 			if( SdPageObjsTLB::IsInDrag() )
835 			{
836 				// during drag'n'drop we just stop the drag but do not close the navigator
837 				nOK = sal_True;
838 			}
839 			else
840 			{
841                 ::sd::ViewShellBase* pBase = ::sd::ViewShellBase::GetViewShellBase( mpBindings->GetDispatcher()->GetFrame());
842                 if( pBase )
843                 {
844                     sd::SlideShow::Stop( *pBase );
845                     // Stopping the slide show may result in a synchronous
846                     // deletion of the navigator window.  Calling the
847                     // parents Notify after this is unsafe.  Therefore we
848                     // return now.
849                     return sal_True;
850                 }
851             }
852         }
853     }
854 
855     if( !nOK )
856 		nOK = Window::Notify( rNEvt );
857 
858 	return( nOK );
859 }
860 
861 
862 /*************************************************************************
863 |*
864 |* KeyInput: ESCAPE abfangen, um Show zu beenden
865 |*
866 \************************************************************************/
867 
KeyInput(const KeyEvent & rKEvt)868 void SdNavigatorWin::KeyInput( const KeyEvent& rKEvt )
869 {
870 	long nOK = sal_False;
871 
872 	if (rKEvt.GetKeyCode().GetCode() == KEY_ESCAPE)
873 	{
874 		if( SdPageObjsTLB::IsInDrag() )
875 		{
876 			// during drag'n'drop we just stop the drag but do not close the navigator
877 			nOK = sal_True;
878 		}
879 		else
880 		{
881             ::sd::ViewShellBase* pBase = ::sd::ViewShellBase::GetViewShellBase( mpBindings->GetDispatcher()->GetFrame());
882 			if(pBase)
883 			{
884 				::sd::SlideShow::Stop( *pBase );
885 			}
886 		}
887 	}
888 
889 	if (!nOK)
890 	{
891 		Window::KeyInput(rKEvt);
892 	}
893 }
894 
DataChanged(const DataChangedEvent & rDCEvt)895 void SdNavigatorWin::DataChanged( const DataChangedEvent& rDCEvt )
896 {
897 	if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
898             ApplyImageList();
899 
900     Window::DataChanged( rDCEvt );
901 }
902 
SetDragImage()903 void SdNavigatorWin::SetDragImage()
904 {
905 	maToolbox.SetItemImage( TBI_DRAGTYPE, maToolbox.GetImageList().GetImage( GetDragTypeSdResId( meDragType, sal_True ) ) );
906 }
907 
ApplyImageList()908 void SdNavigatorWin::ApplyImageList()
909 {
910 	const bool bHighContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
911 
912 	maToolbox.SetImageList( bHighContrast ? maImageListH : maImageList );
913 
914     maToolbox.SetItemImage(TBI_SHAPE_FILTER, BitmapEx(SdResId( bHighContrast ? BMP_GRAPHIC_H : BMP_GRAPHIC)));
915 
916 	SetDragImage();
917 }
918 
919 
920 
921 /*************************************************************************
922 |*
923 |* ControllerItem fuer Navigator
924 |*
925 \************************************************************************/
926 
SdNavigatorControllerItem(sal_uInt16 _nId,SdNavigatorWin * pNavWin,SfxBindings * _pBindings,const SdNavigatorWin::UpdateRequestFunctor & rUpdateRequest)927 SdNavigatorControllerItem::SdNavigatorControllerItem(
928     sal_uInt16 _nId,
929     SdNavigatorWin* pNavWin,
930     SfxBindings*	_pBindings,
931     const SdNavigatorWin::UpdateRequestFunctor& rUpdateRequest)
932     : SfxControllerItem( _nId, *_pBindings ),
933       pNavigatorWin( pNavWin ),
934       maUpdateRequest(rUpdateRequest)
935 {
936 }
937 
938 // -----------------------------------------------------------------------
939 
StateChanged(sal_uInt16 nSId,SfxItemState eState,const SfxPoolItem * pItem)940 void SdNavigatorControllerItem::StateChanged( sal_uInt16 nSId,
941 						SfxItemState eState, const SfxPoolItem* pItem )
942 {
943 	if( eState >= SFX_ITEM_AVAILABLE && nSId == SID_NAVIGATOR_STATE )
944 	{
945 		const SfxUInt32Item* pStateItem = PTR_CAST( SfxUInt32Item, pItem );
946 		DBG_ASSERT( pStateItem, "SfxUInt16Item erwartet");
947 		sal_uInt32 nState = pStateItem->GetValue();
948 
949 		// Stift
950 		if( nState & NAVBTN_PEN_ENABLED &&
951 			!pNavigatorWin->maToolbox.IsItemEnabled( TBI_PEN ) )
952 			pNavigatorWin->maToolbox.EnableItem( TBI_PEN );
953 		if( nState & NAVBTN_PEN_DISABLED &&
954 			pNavigatorWin->maToolbox.IsItemEnabled( TBI_PEN ) )
955 			pNavigatorWin->maToolbox.EnableItem( TBI_PEN, sal_False );
956 		if( nState & NAVBTN_PEN_CHECKED &&
957 			!pNavigatorWin->maToolbox.IsItemChecked( TBI_PEN ) )
958 			pNavigatorWin->maToolbox.CheckItem( TBI_PEN );
959 		if( nState & NAVBTN_PEN_UNCHECKED &&
960 			pNavigatorWin->maToolbox.IsItemChecked( TBI_PEN ) )
961 			pNavigatorWin->maToolbox.CheckItem( TBI_PEN, sal_False );
962 
963 		// Nur wenn Doc in LB das Aktive ist
964 		NavDocInfo* pInfo = pNavigatorWin->GetDocInfo();
965 		if( pInfo && pInfo->IsActive() )
966 		{
967 			// First
968 			if( nState & NAVBTN_FIRST_ENABLED &&
969 				!pNavigatorWin->maToolbox.IsItemEnabled( TBI_FIRST ) )
970 				pNavigatorWin->maToolbox.EnableItem( TBI_FIRST );
971 			if( nState & NAVBTN_FIRST_DISABLED &&
972 				pNavigatorWin->maToolbox.IsItemEnabled( TBI_FIRST ) )
973 				pNavigatorWin->maToolbox.EnableItem( TBI_FIRST, sal_False );
974 
975 			// Prev
976 			if( nState & NAVBTN_PREV_ENABLED &&
977 				!pNavigatorWin->maToolbox.IsItemEnabled( TBI_PREVIOUS ) )
978 				pNavigatorWin->maToolbox.EnableItem( TBI_PREVIOUS );
979 			if( nState & NAVBTN_PREV_DISABLED &&
980 				pNavigatorWin->maToolbox.IsItemEnabled( TBI_PREVIOUS ) )
981 				pNavigatorWin->maToolbox.EnableItem( TBI_PREVIOUS, sal_False );
982 
983 			// Last
984 			if( nState & NAVBTN_LAST_ENABLED &&
985 				!pNavigatorWin->maToolbox.IsItemEnabled( TBI_LAST ) )
986 				pNavigatorWin->maToolbox.EnableItem( TBI_LAST );
987 			if( nState & NAVBTN_LAST_DISABLED &&
988 				pNavigatorWin->maToolbox.IsItemEnabled( TBI_LAST ) )
989 				pNavigatorWin->maToolbox.EnableItem( TBI_LAST, sal_False );
990 
991 			// Next
992 			if( nState & NAVBTN_NEXT_ENABLED &&
993 				!pNavigatorWin->maToolbox.IsItemEnabled( TBI_NEXT ) )
994 				pNavigatorWin->maToolbox.EnableItem( TBI_NEXT );
995 			if( nState & NAVBTN_NEXT_DISABLED &&
996 				pNavigatorWin->maToolbox.IsItemEnabled( TBI_NEXT ) )
997 				pNavigatorWin->maToolbox.EnableItem( TBI_NEXT, sal_False );
998 
999 			if( nState & NAVTLB_UPDATE )
1000 			{
1001 				// InitTlb; Wird ueber Slot initiiert
1002                 if (maUpdateRequest)
1003                     maUpdateRequest();
1004 			}
1005 		}
1006 	}
1007 }
1008 
1009 /*************************************************************************
1010 |*
1011 |* ControllerItem fuer Navigator, um die Seite in der TreeLB anzuzeigen
1012 |*
1013 \************************************************************************/
1014 
SdPageNameControllerItem(sal_uInt16 _nId,SdNavigatorWin * pNavWin,SfxBindings * _pBindings,const SdNavigatorWin::UpdateRequestFunctor & rUpdateRequest)1015 SdPageNameControllerItem::SdPageNameControllerItem(
1016     sal_uInt16 _nId,
1017     SdNavigatorWin* pNavWin,
1018     SfxBindings*	_pBindings,
1019     const SdNavigatorWin::UpdateRequestFunctor& rUpdateRequest)
1020 	: SfxControllerItem( _nId, *_pBindings ),
1021       pNavigatorWin( pNavWin ),
1022       maUpdateRequest(rUpdateRequest)
1023 {
1024 }
1025 
1026 // -----------------------------------------------------------------------
1027 
StateChanged(sal_uInt16 nSId,SfxItemState eState,const SfxPoolItem * pItem)1028 void SdPageNameControllerItem::StateChanged( sal_uInt16 nSId,
1029 						SfxItemState eState, const SfxPoolItem* pItem )
1030 {
1031 	if( eState >= SFX_ITEM_AVAILABLE && nSId == SID_NAVIGATOR_PAGENAME )
1032 	{
1033 		// Nur wenn Doc in LB das Aktive ist
1034 		NavDocInfo* pInfo = pNavigatorWin->GetDocInfo();
1035 		if( pInfo && pInfo->IsActive() )
1036 		{
1037 			const SfxStringItem* pStateItem = PTR_CAST( SfxStringItem, pItem );
1038 			DBG_ASSERT( pStateItem, "SfxStringItem erwartet");
1039 			String aPageName = pStateItem->GetValue();
1040 
1041 			if( !pNavigatorWin->maTlbObjects.HasSelectedChilds( aPageName ) )
1042 			{
1043 				if( pNavigatorWin->maTlbObjects.GetSelectionMode() == MULTIPLE_SELECTION )
1044 				{
1045 					// Weil sonst immer dazuselektiert wird
1046 					pNavigatorWin->maTlbObjects.SelectAll( sal_False );
1047 				}
1048 				pNavigatorWin->maTlbObjects.SelectEntry( aPageName );
1049 			}
1050 		}
1051 	}
1052 }
1053