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