Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <tools/urlobj.hxx>
21 : #include <unotools/localfilehelper.hxx>
22 : #include <sfx2/imgmgr.hxx>
23 : #include <sfx2/fcontnr.hxx>
24 : #include <svl/eitem.hxx>
25 : #include <svl/stritem.hxx>
26 : #include <sfx2/docfilt.hxx>
27 : #include <sfx2/docfile.hxx>
28 : #include <svl/intitem.hxx>
29 : #include <sfx2/dispatch.hxx>
30 : #include <svx/svxids.hrc>
31 :
32 : #include <vcl/menu.hxx>
33 : #include <vcl/settings.hxx>
34 :
35 : #include <sfx2/viewfrm.hxx>
36 : #include <sfx2/dockwin.hxx>
37 : #include <sfx2/sfxresid.hxx>
38 :
39 : #include "pres.hxx"
40 : #include "navigatr.hxx"
41 : #include "navigatr.hrc"
42 : #include "pgjump.hxx"
43 : #include "app.hrc"
44 : #include "strings.hrc"
45 : #include "res_bmp.hrc"
46 : #include "drawdoc.hxx"
47 : #include "DrawDocShell.hxx"
48 : #include "sdresid.hxx"
49 : #include "ViewShell.hxx"
50 : #include "ViewShellBase.hxx"
51 : #include "DrawViewShell.hxx"
52 : #include "slideshow.hxx"
53 : #include "FrameView.hxx"
54 : #include "helpids.h"
55 :
56 : namespace {
57 : static const sal_uInt16 nShowNamedShapesFilter=1;
58 : static const sal_uInt16 nShowAllShapesFilter=2;
59 : }
60 :
61 : /**
62 : * SdNavigatorWin - FloatingWindow
63 : */
64 0 : SdNavigatorWin::SdNavigatorWin(
65 : ::Window* pParent,
66 : ::sd::NavigatorChildWindow* pChWinCtxt,
67 : const SdResId& rSdResId,
68 : SfxBindings* pInBindings,
69 : const UpdateRequestFunctor& rUpdateRequest)
70 : : ::Window( pParent, rSdResId )
71 : , maToolbox ( this, SdResId( 1 ) )
72 : , maTlbObjects( this, SdResId( TLB_OBJECTS ) )
73 : , maLbDocs ( this, SdResId( LB_DOCS ) )
74 : , mpChildWinContext( pChWinCtxt )
75 : , mbDocImported ( sal_False )
76 : // On changes of the DragType: adjust SelectionMode of TLB!
77 : , meDragType ( NAVIGATOR_DRAGTYPE_EMBEDDED )
78 : , mpBindings ( pInBindings )
79 0 : , maImageList ( SdResId( IL_NAVIGATR ) )
80 : {
81 0 : maTlbObjects.SetViewFrame( mpBindings->GetDispatcher()->GetFrame() );
82 :
83 0 : FreeResource();
84 :
85 0 : maTlbObjects.SetAccessibleName(SD_RESSTR(STR_OBJECTS_TREE));
86 :
87 0 : mpNavigatorCtrlItem = new SdNavigatorControllerItem( SID_NAVIGATOR_STATE, this, mpBindings, rUpdateRequest);
88 0 : mpPageNameCtrlItem = new SdPageNameControllerItem( SID_NAVIGATOR_PAGENAME, this, mpBindings, rUpdateRequest);
89 :
90 0 : ApplyImageList(); // load images *before* calculating sizes to get something useful !!!
91 :
92 0 : Size aTbxSize( maToolbox.CalcWindowSizePixel() );
93 0 : maToolbox.SetOutputSizePixel( aTbxSize );
94 0 : maToolbox.SetSelectHdl( LINK( this, SdNavigatorWin, SelectToolboxHdl ) );
95 0 : maToolbox.SetClickHdl( LINK( this, SdNavigatorWin, ClickToolboxHdl ) );
96 0 : maToolbox.SetDropdownClickHdl( LINK(this, SdNavigatorWin, DropdownClickToolBoxHdl) );
97 0 : maToolbox.SetItemBits( TBI_DRAGTYPE, maToolbox.GetItemBits( TBI_DRAGTYPE ) | TIB_DROPDOWNONLY );
98 :
99 : // Shape filter drop down menu.
100 : maToolbox.SetItemBits(
101 : TBI_SHAPE_FILTER,
102 0 : maToolbox.GetItemBits(TBI_SHAPE_FILTER) | TIB_DROPDOWNONLY);
103 :
104 : // TreeListBox
105 : // set position below toolbox
106 0 : long nListboxYPos = maToolbox.GetPosPixel().Y() + maToolbox.GetSizePixel().Height() + 4;
107 0 : maTlbObjects.setPosSizePixel( 0, nListboxYPos, 0, 0, WINDOW_POSSIZE_Y );
108 0 : maTlbObjects.SetDoubleClickHdl( LINK( this, SdNavigatorWin, ClickObjectHdl ) );
109 0 : maTlbObjects.SetSelectionMode( SINGLE_SELECTION );
110 : // set focus to listbox, otherwise it is in the toolbox which is only useful
111 : // for keyboard navigation
112 0 : maTlbObjects.GrabFocus();
113 0 : maTlbObjects.SetSdNavigatorWinFlag(sal_True);
114 :
115 : // DragTypeListBox
116 0 : maLbDocs.SetSelectHdl( LINK( this, SdNavigatorWin, SelectDocumentHdl ) );
117 : // set position below treelistbox
118 0 : nListboxYPos = maTlbObjects.GetPosPixel().Y() + maTlbObjects.GetSizePixel().Height() + 4;
119 0 : maLbDocs.setPosSizePixel( 0, nListboxYPos, 0, 0, WINDOW_POSSIZE_Y );
120 :
121 : // assure that tool box is at least as wide as the tree list box
122 : {
123 0 : const Size aTlbSize( maTlbObjects.GetOutputSizePixel() );
124 0 : if ( aTlbSize.Width() > aTbxSize.Width() )
125 : {
126 0 : maToolbox.setPosSizePixel( 0, 0, aTlbSize.Width(), 0, WINDOW_POSSIZE_WIDTH );
127 0 : aTbxSize = maToolbox.GetOutputSizePixel();
128 : }
129 : }
130 :
131 : // set min outputsize after all sizes are known
132 0 : const long nFullHeight = nListboxYPos + maLbDocs.GetSizePixel().Height() + 4;
133 0 : maSize = GetOutputSizePixel();
134 0 : if( maSize.Height() < nFullHeight )
135 : {
136 0 : maSize.Height() = nFullHeight;
137 0 : SetOutputSizePixel( maSize );
138 : }
139 0 : maMinSize = maSize;
140 0 : const long nMinWidth = 2*maToolbox.GetPosPixel().X() + aTbxSize.Width(); // never clip the toolbox
141 0 : if( nMinWidth > maMinSize.Width() )
142 0 : maMinSize.Width() = nMinWidth;
143 0 : maMinSize.Height() -= 40;
144 0 : SfxDockingWindow* pDockingParent = dynamic_cast<SfxDockingWindow*>(GetParent());
145 0 : if (pDockingParent != NULL)
146 0 : pDockingParent->SetMinOutputSizePixel( maMinSize );
147 :
148 : // InitTlb; is initiated over Slot
149 0 : if (rUpdateRequest)
150 0 : rUpdateRequest();
151 0 : }
152 :
153 :
154 :
155 0 : SdNavigatorWin::~SdNavigatorWin()
156 : {
157 0 : delete mpNavigatorCtrlItem;
158 0 : delete mpPageNameCtrlItem;
159 0 : }
160 :
161 :
162 :
163 : //when object is marked , fresh the corresponding entry tree .
164 0 : void SdNavigatorWin::FreshTree( const SdDrawDocument* pDoc )
165 : {
166 0 : SdDrawDocument* pNonConstDoc = (SdDrawDocument*) pDoc; // const as const can...
167 0 : sd::DrawDocShell* pDocShell = pNonConstDoc->GetDocSh();
168 0 : OUString aDocShName( pDocShell->GetName() );
169 0 : OUString aDocName = pDocShell->GetMedium()->GetName();
170 0 : maTlbObjects.SetSaveTreeItemStateFlag(sal_True); //Added by yanjun for sym2_6385
171 0 : maTlbObjects.Clear();
172 0 : maTlbObjects.Fill( pDoc, sal_False, aDocName ); // Nur normale Seiten
173 0 : maTlbObjects.SetSaveTreeItemStateFlag(sal_False); //Added by yanjun for sym2_6385
174 0 : RefreshDocumentLB();
175 0 : maLbDocs.SelectEntry( aDocShName );
176 0 : }
177 :
178 0 : void SdNavigatorWin::FreshEntry( )
179 : {
180 0 : maTlbObjects.FreshCurEntry();
181 0 : }
182 :
183 0 : void SdNavigatorWin::InitTreeLB( const SdDrawDocument* pDoc )
184 : {
185 0 : SdDrawDocument* pNonConstDoc = (SdDrawDocument*) pDoc; // const as const can...
186 0 : ::sd::DrawDocShell* pDocShell = pNonConstDoc->GetDocSh();
187 0 : OUString aDocShName( pDocShell->GetName() );
188 0 : ::sd::ViewShell* pViewShell = pDocShell->GetViewShell();
189 :
190 : // Restore the 'ShowAllShapes' flag from the last time (in this session)
191 : // that the navigator was shown.
192 0 : if (pViewShell != NULL)
193 : {
194 0 : ::sd::FrameView* pFrameView = pViewShell->GetFrameView();
195 0 : if (pFrameView != NULL)
196 0 : maTlbObjects.SetShowAllShapes(pFrameView->IsNavigatorShowingAllShapes(), false);
197 : }
198 :
199 : // Disable the shape filter drop down menu when there is a running slide
200 : // show.
201 0 : if (pViewShell!=NULL && sd::SlideShow::IsRunning( pViewShell->GetViewShellBase() ))
202 0 : maToolbox.EnableItem(TBI_SHAPE_FILTER, false);
203 : else
204 0 : maToolbox.EnableItem(TBI_SHAPE_FILTER);
205 :
206 0 : if( !maTlbObjects.IsEqualToDoc( pDoc ) )
207 : {
208 0 : OUString aDocName = pDocShell->GetMedium()->GetName();
209 0 : maTlbObjects.Clear();
210 0 : maTlbObjects.Fill( pDoc, (sal_Bool) sal_False, aDocName ); // only normal pages
211 :
212 0 : RefreshDocumentLB();
213 0 : maLbDocs.SelectEntry( aDocShName );
214 : }
215 : else
216 : {
217 0 : maLbDocs.SetNoSelection();
218 0 : maLbDocs.SelectEntry( aDocShName );
219 :
220 : // commented in order to fix 30246
221 : // if( maLbDocs.GetSelectEntryCount() == 0 )
222 : {
223 0 : RefreshDocumentLB();
224 0 : maLbDocs.SelectEntry( aDocShName );
225 : }
226 : }
227 :
228 0 : SfxViewFrame* pViewFrame = ( ( pViewShell && pViewShell->GetViewFrame() ) ? pViewShell->GetViewFrame() : SfxViewFrame::Current() );
229 0 : if( pViewFrame )
230 0 : pViewFrame->GetBindings().Invalidate(SID_NAVIGATOR_PAGENAME, true, true);
231 0 : }
232 :
233 : /**
234 : * DragType is set on dependance if a Drag is even possible. For example,
235 : * under certain circumstances, it is not allowed to drag graphics (#31038#).
236 : */
237 0 : NavigatorDragType SdNavigatorWin::GetNavigatorDragType()
238 : {
239 0 : NavigatorDragType eDT = meDragType;
240 0 : NavDocInfo* pInfo = GetDocInfo();
241 :
242 0 : if( ( eDT == NAVIGATOR_DRAGTYPE_LINK ) && ( ( pInfo && !pInfo->HasName() ) || !maTlbObjects.IsLinkableSelected() ) )
243 0 : eDT = NAVIGATOR_DRAGTYPE_NONE;
244 :
245 0 : return( eDT );
246 : }
247 :
248 : //Get SdDrawDocShell
249 0 : sd::DrawDocShell* SdNavigatorWin::GetDrawDocShell( const SdDrawDocument* pDoc )
250 : {
251 0 : if( !pDoc )
252 0 : return NULL; // const as const can...
253 0 : sd::DrawDocShell* pDocShell = pDoc->GetDocSh();
254 0 : return pDocShell;
255 : }
256 :
257 0 : IMPL_LINK_NOARG(SdNavigatorWin, SelectToolboxHdl)
258 : {
259 0 : sal_uInt16 nId = maToolbox.GetCurItemId();
260 0 : sal_uInt16 nSId = 0;
261 0 : PageJump ePage = PAGE_NONE;
262 :
263 0 : switch( nId )
264 : {
265 : case TBI_PEN:
266 : {
267 0 : if( nId == TBI_PEN )
268 : {
269 0 : nSId = SID_NAVIGATOR_PEN;
270 : }
271 :
272 0 : if( nSId > 0 )
273 : {
274 0 : SfxBoolItem aItem( nSId, true );
275 : mpBindings->GetDispatcher()->Execute(
276 0 : nSId, SFX_CALLMODE_SLOT |SFX_CALLMODE_RECORD, &aItem, 0L );
277 : }
278 : }
279 0 : break;
280 :
281 : case TBI_FIRST:
282 : case TBI_PREVIOUS:
283 : case TBI_NEXT:
284 : case TBI_LAST:
285 : {
286 0 : if( nId == TBI_FIRST )
287 0 : ePage = PAGE_FIRST;
288 0 : else if( nId == TBI_PREVIOUS )
289 0 : ePage = PAGE_PREVIOUS;
290 0 : else if( nId == TBI_NEXT )
291 0 : ePage = PAGE_NEXT;
292 0 : else if( nId == TBI_LAST )
293 0 : ePage = PAGE_LAST;
294 :
295 0 : if( ePage != PAGE_NONE )
296 : {
297 0 : SfxUInt16Item aItem( SID_NAVIGATOR_PAGE, (sal_uInt16)ePage );
298 : mpBindings->GetDispatcher()->Execute(
299 0 : SID_NAVIGATOR_PAGE, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD, &aItem, 0L );
300 : }
301 : }
302 0 : break;
303 : }
304 0 : return 0;
305 : }
306 :
307 :
308 :
309 :
310 0 : IMPL_LINK_NOARG(SdNavigatorWin, ClickToolboxHdl)
311 : {
312 0 : return 0;
313 : }
314 :
315 :
316 :
317 0 : IMPL_LINK( SdNavigatorWin, DropdownClickToolBoxHdl, ToolBox*, pBox )
318 : {
319 0 : sal_uInt16 nId = maToolbox.GetCurItemId();
320 :
321 0 : switch( nId )
322 : {
323 : case TBI_DRAGTYPE:
324 : {
325 : // Popup menu is created depending if the document is saved or not
326 0 : PopupMenu *pMenu = new PopupMenu;
327 :
328 : static const char* aHIDs[] =
329 : {
330 : HID_SD_NAVIGATOR_MENU1,
331 : HID_SD_NAVIGATOR_MENU2,
332 : HID_SD_NAVIGATOR_MENU3,
333 : 0
334 : };
335 :
336 0 : for( sal_uInt16 nID = NAVIGATOR_DRAGTYPE_URL;
337 : nID < NAVIGATOR_DRAGTYPE_COUNT;
338 : nID++ )
339 : {
340 0 : sal_uInt16 nRId = GetDragTypeSdResId( (NavigatorDragType)nID );
341 0 : if( nRId > 0 )
342 : {
343 : DBG_ASSERT(aHIDs[nID-NAVIGATOR_DRAGTYPE_URL],"HelpId not added!");
344 0 : pMenu->InsertItem( nID, SD_RESSTR( nRId ) );
345 0 : pMenu->SetHelpId( nID, aHIDs[nID - NAVIGATOR_DRAGTYPE_URL] );
346 : }
347 :
348 : }
349 0 : NavDocInfo* pInfo = GetDocInfo();
350 :
351 0 : if( ( pInfo && !pInfo->HasName() ) || !maTlbObjects.IsLinkableSelected() )
352 : {
353 0 : pMenu->EnableItem( NAVIGATOR_DRAGTYPE_LINK, false );
354 0 : pMenu->EnableItem( NAVIGATOR_DRAGTYPE_URL, false );
355 0 : meDragType = NAVIGATOR_DRAGTYPE_EMBEDDED;
356 : }
357 :
358 0 : pMenu->CheckItem( (sal_uInt16)meDragType );
359 0 : pMenu->SetSelectHdl( LINK( this, SdNavigatorWin, MenuSelectHdl ) );
360 :
361 0 : pMenu->Execute( this, maToolbox.GetItemRect( nId ), POPUPMENU_EXECUTE_DOWN );
362 0 : pBox->EndSelection();
363 0 : delete pMenu;
364 : }
365 0 : break;
366 :
367 : case TBI_SHAPE_FILTER:
368 : {
369 0 : PopupMenu *pMenu = new PopupMenu;
370 :
371 : pMenu->InsertItem(
372 : nShowNamedShapesFilter,
373 0 : SD_RESSTR(STR_NAVIGATOR_SHOW_NAMED_SHAPES));
374 : pMenu->InsertItem(
375 : nShowAllShapesFilter,
376 0 : SD_RESSTR(STR_NAVIGATOR_SHOW_ALL_SHAPES));
377 :
378 0 : if (maTlbObjects.GetShowAllShapes())
379 0 : pMenu->CheckItem(nShowAllShapesFilter);
380 : else
381 0 : pMenu->CheckItem(nShowNamedShapesFilter);
382 0 : pMenu->SetSelectHdl( LINK( this, SdNavigatorWin, ShapeFilterCallback ) );
383 :
384 0 : pMenu->Execute( this, maToolbox.GetItemRect( nId ), POPUPMENU_EXECUTE_DOWN );
385 0 : pBox->EndSelection();
386 0 : delete pMenu;
387 : }
388 0 : break;
389 : }
390 0 : return 0;
391 : }
392 :
393 :
394 :
395 0 : IMPL_LINK_NOARG(SdNavigatorWin, ClickObjectHdl)
396 : {
397 0 : if( !mbDocImported || maLbDocs.GetSelectEntryPos() != 0 )
398 : {
399 0 : NavDocInfo* pInfo = GetDocInfo();
400 :
401 : // if it is the active window, we jump to the page
402 0 : if( pInfo && pInfo->IsActive() )
403 : {
404 0 : OUString aStr( maTlbObjects.GetSelectEntry() );
405 :
406 0 : if( !aStr.isEmpty() )
407 : {
408 0 : SfxStringItem aItem( SID_NAVIGATOR_OBJECT, aStr );
409 : mpBindings->GetDispatcher()->Execute(
410 0 : SID_NAVIGATOR_OBJECT, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD, &aItem, 0L );
411 : //set sign variable
412 0 : maTlbObjects.MarkCurEntry(aStr);
413 :
414 : // moved here from SetGetFocusHdl. Reset the
415 : // focus only if something has been selected in the
416 : // document.
417 0 : SfxViewShell* pCurSh = SfxViewShell::Current();
418 :
419 0 : if ( pCurSh )
420 : {
421 0 : Window* pShellWnd = pCurSh->GetWindow();
422 0 : if ( pShellWnd )
423 0 : pShellWnd->GrabFocus();
424 0 : }
425 0 : }
426 : }
427 : }
428 0 : return( 0L );
429 : }
430 :
431 :
432 :
433 0 : IMPL_LINK_NOARG(SdNavigatorWin, SelectDocumentHdl)
434 : {
435 0 : OUString aStrLb = maLbDocs.GetSelectEntry();
436 0 : long nPos = maLbDocs.GetSelectEntryPos();
437 0 : sal_Bool bFound = sal_False;
438 0 : ::sd::DrawDocShell* pDocShell = NULL;
439 0 : NavDocInfo* pInfo = GetDocInfo();
440 :
441 : // is it a dragged object?
442 0 : if( mbDocImported && nPos == 0 )
443 : {
444 : // construct document in TLB
445 0 : InsertFile( aStrLb );
446 : }
447 0 : else if (pInfo)
448 : {
449 0 : pDocShell = pInfo->mpDocShell;
450 :
451 0 : bFound = sal_True;
452 : }
453 :
454 0 : if( bFound )
455 : {
456 0 : SdDrawDocument* pDoc = pDocShell->GetDoc();
457 0 : if( !maTlbObjects.IsEqualToDoc( pDoc ) )
458 : {
459 0 : SdDrawDocument* pNonConstDoc = (SdDrawDocument*) pDoc; // const as const can...
460 0 : ::sd::DrawDocShell* pNCDocShell = pNonConstDoc->GetDocSh();
461 0 : OUString aDocName = pNCDocShell->GetMedium()->GetName();
462 0 : maTlbObjects.Clear();
463 0 : maTlbObjects.Fill( pDoc, (sal_Bool) sal_False, aDocName ); // only normal pages
464 : }
465 : }
466 :
467 : // check if link or url is possible
468 0 : if( ( pInfo && !pInfo->HasName() ) || !maTlbObjects.IsLinkableSelected() || ( meDragType != NAVIGATOR_DRAGTYPE_EMBEDDED ) )
469 : {
470 0 : meDragType = NAVIGATOR_DRAGTYPE_EMBEDDED;
471 0 : SetDragImage();
472 : }
473 :
474 0 : return( 0L );
475 : }
476 :
477 : /**
478 : * Set DrageType and set image accordingly to it.
479 : * If the handler is called with NULL, the default (URL) is set.
480 : */
481 0 : IMPL_LINK( SdNavigatorWin, MenuSelectHdl, Menu *, pMenu )
482 : {
483 : sal_uInt16 nMenuId;
484 0 : if( pMenu )
485 0 : nMenuId = pMenu->GetCurItemId();
486 : else
487 0 : nMenuId = NAVIGATOR_DRAGTYPE_URL;
488 :
489 0 : if( nMenuId != USHRT_MAX ) // Necessary ?
490 : {
491 0 : NavigatorDragType eDT = (NavigatorDragType) nMenuId;
492 0 : if( meDragType != eDT )
493 : {
494 0 : meDragType = eDT;
495 0 : SetDragImage();
496 :
497 0 : if( meDragType == NAVIGATOR_DRAGTYPE_URL )
498 : {
499 : // patch, prevents endless loop
500 0 : if( maTlbObjects.GetSelectionCount() > 1 )
501 0 : maTlbObjects.SelectAll( false );
502 :
503 0 : maTlbObjects.SetSelectionMode( SINGLE_SELECTION );
504 : }
505 : else
506 0 : maTlbObjects.SetSelectionMode( MULTIPLE_SELECTION );
507 : }
508 : }
509 0 : return( 0 );
510 : }
511 :
512 :
513 :
514 :
515 0 : IMPL_LINK( SdNavigatorWin, ShapeFilterCallback, Menu *, pMenu )
516 : {
517 0 : if (pMenu != NULL)
518 : {
519 0 : bool bShowAllShapes (maTlbObjects.GetShowAllShapes());
520 0 : sal_uInt16 nMenuId (pMenu->GetCurItemId());
521 0 : switch (nMenuId)
522 : {
523 : case nShowNamedShapesFilter:
524 0 : bShowAllShapes = false;
525 0 : break;
526 :
527 : case nShowAllShapesFilter:
528 0 : bShowAllShapes = true;
529 0 : break;
530 :
531 : default:
532 : OSL_FAIL(
533 : "SdNavigatorWin::ShapeFilterCallback called for unknown menu entry");
534 0 : break;
535 : }
536 :
537 0 : maTlbObjects.SetShowAllShapes(bShowAllShapes, true);
538 :
539 : // Remember the selection in the FrameView.
540 0 : NavDocInfo* pInfo = GetDocInfo();
541 0 : if (pInfo != NULL)
542 : {
543 0 : ::sd::DrawDocShell* pDocShell = pInfo->mpDocShell;
544 0 : if (pDocShell != NULL)
545 : {
546 0 : ::sd::ViewShell* pViewShell = pDocShell->GetViewShell();
547 0 : if (pViewShell != NULL)
548 : {
549 0 : ::sd::FrameView* pFrameView = pViewShell->GetFrameView();
550 0 : if (pFrameView != NULL)
551 : {
552 0 : pFrameView->SetIsNavigatorShowingAllShapes(bShowAllShapes);
553 : }
554 : }
555 : }
556 : }
557 : }
558 :
559 0 : return 0;
560 : }
561 :
562 :
563 :
564 0 : void SdNavigatorWin::Resize()
565 : {
566 0 : Size aWinSize( GetOutputSizePixel() );
567 0 : if( aWinSize.Height() >= maMinSize.Height() )
568 : //aWinSize.Width() >= maMinSize.Width() )
569 : {
570 0 : Size aDiffSize;
571 0 : aDiffSize.Width() = aWinSize.Width() - maSize.Width();
572 0 : aDiffSize.Height() = aWinSize.Height() - maSize.Height();
573 :
574 : // change size of Toolbox
575 0 : Size aObjSize( maToolbox.GetOutputSizePixel() );
576 0 : aObjSize.Width() += aDiffSize.Width();
577 0 : maToolbox.SetOutputSizePixel( aObjSize );
578 :
579 : // change size of TreeLB
580 0 : aObjSize = maTlbObjects.GetSizePixel();
581 0 : aObjSize.Width() += aDiffSize.Width();
582 0 : aObjSize.Height() = maLbDocs.GetPosPixel().Y() + aDiffSize.Height() -
583 0 : maTlbObjects.GetPosPixel().Y() - 4;
584 0 : maTlbObjects.SetSizePixel( aObjSize );
585 :
586 0 : Point aPt( 0, aDiffSize.Height() );
587 :
588 : // move other controls (DocumentLB)
589 0 : maLbDocs.Hide();
590 0 : aObjSize = maLbDocs.GetOutputSizePixel();
591 0 : aObjSize.Width() += aDiffSize.Width();
592 0 : maLbDocs.SetPosPixel( maLbDocs.GetPosPixel() + aPt );
593 0 : maLbDocs.SetOutputSizePixel( aObjSize );
594 0 : maLbDocs.Show();
595 :
596 0 : maSize = aWinSize;
597 : }
598 0 : Window::Resize();
599 0 : }
600 :
601 :
602 :
603 0 : bool SdNavigatorWin::InsertFile(const OUString& rFileName)
604 : {
605 0 : INetURLObject aURL( rFileName );
606 :
607 0 : if( aURL.GetProtocol() == INET_PROT_NOT_VALID )
608 : {
609 0 : OUString aURLStr;
610 0 : ::utl::LocalFileHelper::ConvertPhysicalNameToURL( rFileName, aURLStr );
611 0 : aURL = INetURLObject( aURLStr );
612 : }
613 :
614 : // get adjusted FileName
615 0 : OUString aFileName( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
616 :
617 0 : if (aFileName.isEmpty())
618 : {
619 : // show actual document again
620 0 : maDropFileName = aFileName;
621 : }
622 : else
623 : {
624 : // show dragged-in document
625 0 : const SfxFilter* pFilter = NULL;
626 0 : ErrCode nErr = 0;
627 :
628 0 : if (aFileName != maDropFileName)
629 : {
630 0 : SfxMedium aMed(aFileName, (STREAM_READ | STREAM_SHARE_DENYNONE));
631 0 : SfxFilterMatcher aMatch( OUString("simpress") );
632 0 : aMed.UseInteractionHandler( true );
633 0 : nErr = aMatch.GuessFilter(aMed, &pFilter);
634 : }
635 :
636 0 : if ((pFilter && !nErr) || aFileName == maDropFileName)
637 : {
638 : // The medium may be opened with READ/WRITE. Therefore, we first
639 : // check if it contains a Storage.
640 : SfxMedium* pMedium = new SfxMedium( aFileName,
641 0 : STREAM_READ | STREAM_NOCREATE);
642 :
643 0 : if (pMedium->IsStorage())
644 : {
645 : // Now depending on mode:
646 : // maTlbObjects.SetSelectionMode(MULTIPLE_SELECTION);
647 : // handover of ownership of pMedium;
648 0 : SdDrawDocument* pDropDoc = maTlbObjects.GetBookmarkDoc(pMedium);
649 :
650 0 : if (pDropDoc)
651 : {
652 0 : maTlbObjects.Clear();
653 0 : maDropFileName = aFileName;
654 :
655 0 : if( !maTlbObjects.IsEqualToDoc( pDropDoc ) )
656 : {
657 : // only normal pages
658 0 : maTlbObjects.Fill(pDropDoc, (sal_Bool) sal_False, maDropFileName);
659 0 : RefreshDocumentLB( &maDropFileName );
660 : }
661 : }
662 : }
663 : else
664 : {
665 0 : delete pMedium;
666 0 : return false;
667 : }
668 : }
669 : else
670 : {
671 0 : return false;
672 : }
673 : }
674 :
675 0 : return true;
676 : }
677 :
678 :
679 :
680 0 : void SdNavigatorWin::RefreshDocumentLB( const OUString* pDocName )
681 : {
682 0 : sal_Int32 nPos = 0;
683 :
684 0 : if( pDocName )
685 : {
686 0 : if( mbDocImported )
687 0 : maLbDocs.RemoveEntry( 0 );
688 :
689 0 : maLbDocs.InsertEntry( *pDocName, 0 );
690 0 : mbDocImported = sal_True;
691 : }
692 : else
693 : {
694 0 : nPos = maLbDocs.GetSelectEntryPos();
695 0 : if( nPos == LISTBOX_ENTRY_NOTFOUND )
696 0 : nPos = 0;
697 :
698 0 : OUString aStr;
699 0 : if( mbDocImported )
700 0 : aStr = maLbDocs.GetEntry( 0 );
701 :
702 0 : maLbDocs.Clear();
703 :
704 : // delete list of DocInfos
705 0 : maDocList.clear();
706 :
707 0 : if( mbDocImported )
708 0 : maLbDocs.InsertEntry( aStr, 0 );
709 :
710 : ::sd::DrawDocShell* pCurrentDocShell =
711 0 : PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current() );
712 0 : SfxObjectShell* pSfxDocShell = SfxObjectShell::GetFirst(0, false);
713 0 : while( pSfxDocShell )
714 : {
715 0 : ::sd::DrawDocShell* pDocShell = PTR_CAST(::sd::DrawDocShell, pSfxDocShell );
716 0 : if( pDocShell && !pDocShell->IsInDestruction() && ( pDocShell->GetCreateMode() != SFX_CREATE_MODE_EMBEDDED ) )
717 : {
718 0 : NavDocInfo aInfo ;
719 0 : aInfo.mpDocShell = pDocShell;
720 :
721 0 : SfxMedium *pMedium = pDocShell->GetMedium();
722 0 : aStr = pMedium ? pMedium->GetName() : OUString();
723 0 : if( !aStr.isEmpty() )
724 0 : aInfo.SetName();
725 : else
726 0 : aInfo.SetName( sal_False );
727 : // at the moment, we use the name of the shell again (i.e.
728 : // without path) since Koose thinks it is an error if the path
729 : // is shown in url notation!
730 0 : aStr = pDocShell->GetName();
731 :
732 0 : maLbDocs.InsertEntry( aStr, LISTBOX_APPEND );
733 :
734 0 : if( pDocShell == pCurrentDocShell )
735 0 : aInfo.SetActive();
736 : else
737 0 : aInfo.SetActive( sal_False );
738 :
739 0 : maDocList.push_back( aInfo );
740 : }
741 0 : pSfxDocShell = SfxObjectShell::GetNext( *pSfxDocShell, 0, false );
742 0 : }
743 : }
744 0 : maLbDocs.SelectEntryPos( nPos );
745 0 : }
746 :
747 :
748 :
749 0 : sal_uInt16 SdNavigatorWin::GetDragTypeSdResId( NavigatorDragType eDT, sal_Bool bImage )
750 : {
751 0 : switch( eDT )
752 : {
753 : case NAVIGATOR_DRAGTYPE_NONE:
754 0 : return( bImage ? 0 : STR_NONE );
755 : case NAVIGATOR_DRAGTYPE_URL:
756 0 : return( bImage ? TBI_HYPERLINK : STR_DRAGTYPE_URL );
757 : case NAVIGATOR_DRAGTYPE_EMBEDDED:
758 0 : return( bImage ? TBI_EMBEDDED : STR_DRAGTYPE_EMBEDDED );
759 : case NAVIGATOR_DRAGTYPE_LINK:
760 0 : return( bImage ? TBI_LINK : STR_DRAGTYPE_LINK );
761 : default: OSL_FAIL( "No resource for DragType available!" );
762 : }
763 0 : return( 0 );
764 : }
765 :
766 :
767 :
768 0 : NavDocInfo* SdNavigatorWin::GetDocInfo()
769 : {
770 0 : sal_uInt32 nPos = maLbDocs.GetSelectEntryPos();
771 :
772 0 : if( mbDocImported )
773 : {
774 0 : if( nPos == 0 )
775 : {
776 0 : return( NULL );
777 : }
778 0 : nPos--;
779 : }
780 :
781 0 : return nPos < maDocList.size() ? &(maDocList[ nPos ]) : NULL;
782 : }
783 :
784 : /**
785 : * PreNotify
786 : */
787 0 : bool SdNavigatorWin::Notify(NotifyEvent& rNEvt)
788 : {
789 0 : const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
790 0 : bool nOK = false;
791 :
792 0 : if( pKEvt )
793 : {
794 0 : if( KEY_ESCAPE == pKEvt->GetKeyCode().GetCode() )
795 : {
796 0 : if( SdPageObjsTLB::IsInDrag() )
797 : {
798 : // during drag'n'drop we just stop the drag but do not close the navigator
799 0 : nOK = true;
800 : }
801 : else
802 : {
803 0 : ::sd::ViewShellBase* pBase = ::sd::ViewShellBase::GetViewShellBase( mpBindings->GetDispatcher()->GetFrame());
804 0 : if( pBase )
805 : {
806 0 : 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 0 : return true;
812 : }
813 : }
814 : }
815 : }
816 :
817 0 : if( !nOK )
818 0 : nOK = Window::Notify( rNEvt );
819 :
820 0 : return( nOK );
821 : }
822 :
823 :
824 : /**
825 : * catch ESCAPE in order to end show
826 : */
827 0 : void SdNavigatorWin::KeyInput( const KeyEvent& rKEvt )
828 : {
829 0 : long nOK = sal_False;
830 :
831 0 : if (rKEvt.GetKeyCode().GetCode() == KEY_ESCAPE)
832 : {
833 0 : if( SdPageObjsTLB::IsInDrag() )
834 : {
835 : // during drag'n'drop we just stop the drag but do not close the navigator
836 0 : nOK = sal_True;
837 : }
838 : else
839 : {
840 0 : ::sd::ViewShellBase* pBase = ::sd::ViewShellBase::GetViewShellBase( mpBindings->GetDispatcher()->GetFrame());
841 0 : if(pBase)
842 : {
843 0 : ::sd::SlideShow::Stop( *pBase );
844 : }
845 : }
846 : }
847 :
848 0 : if (!nOK)
849 : {
850 0 : Window::KeyInput(rKEvt);
851 : }
852 0 : }
853 :
854 0 : void SdNavigatorWin::DataChanged( const DataChangedEvent& rDCEvt )
855 : {
856 0 : if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
857 0 : ApplyImageList();
858 :
859 0 : Window::DataChanged( rDCEvt );
860 0 : }
861 :
862 0 : void SdNavigatorWin::SetDragImage()
863 : {
864 0 : maToolbox.SetItemImage( TBI_DRAGTYPE, maToolbox.GetImageList().GetImage( GetDragTypeSdResId( meDragType, sal_True ) ) );
865 0 : }
866 :
867 0 : void SdNavigatorWin::ApplyImageList()
868 : {
869 :
870 0 : maToolbox.SetImageList( maImageList );
871 0 : maToolbox.SetItemImage(TBI_SHAPE_FILTER, Image(BitmapEx(SdResId(BMP_GRAPHIC))));
872 :
873 0 : SetDragImage();
874 0 : }
875 :
876 :
877 :
878 : /**
879 : * ControllerItem for Navigator
880 : */
881 0 : SdNavigatorControllerItem::SdNavigatorControllerItem(
882 : sal_uInt16 _nId,
883 : SdNavigatorWin* pNavWin,
884 : SfxBindings* _pBindings,
885 : const SdNavigatorWin::UpdateRequestFunctor& rUpdateRequest)
886 : : SfxControllerItem( _nId, *_pBindings ),
887 : pNavigatorWin( pNavWin ),
888 0 : maUpdateRequest(rUpdateRequest)
889 : {
890 0 : }
891 :
892 :
893 :
894 0 : void SdNavigatorControllerItem::StateChanged( sal_uInt16 nSId,
895 : SfxItemState eState, const SfxPoolItem* pItem )
896 : {
897 0 : if( eState >= SFX_ITEM_AVAILABLE && nSId == SID_NAVIGATOR_STATE )
898 : {
899 0 : const SfxUInt32Item* pStateItem = PTR_CAST( SfxUInt32Item, pItem );
900 : DBG_ASSERT( pStateItem, "SfxUInt16Item expected");
901 0 : sal_uInt32 nState = pStateItem->GetValue();
902 :
903 : // pen
904 0 : if( nState & NAVBTN_PEN_ENABLED &&
905 0 : !pNavigatorWin->maToolbox.IsItemEnabled( TBI_PEN ) )
906 0 : pNavigatorWin->maToolbox.EnableItem( TBI_PEN );
907 0 : if( nState & NAVBTN_PEN_DISABLED &&
908 0 : pNavigatorWin->maToolbox.IsItemEnabled( TBI_PEN ) )
909 0 : pNavigatorWin->maToolbox.EnableItem( TBI_PEN, false );
910 0 : if( nState & NAVBTN_PEN_CHECKED &&
911 0 : !pNavigatorWin->maToolbox.IsItemChecked( TBI_PEN ) )
912 0 : pNavigatorWin->maToolbox.CheckItem( TBI_PEN );
913 0 : if( nState & NAVBTN_PEN_UNCHECKED &&
914 0 : pNavigatorWin->maToolbox.IsItemChecked( TBI_PEN ) )
915 0 : pNavigatorWin->maToolbox.CheckItem( TBI_PEN, false );
916 :
917 : // only if doc in LB is the active
918 0 : NavDocInfo* pInfo = pNavigatorWin->GetDocInfo();
919 0 : if( pInfo && pInfo->IsActive() )
920 : {
921 : // First
922 0 : if( nState & NAVBTN_FIRST_ENABLED &&
923 0 : !pNavigatorWin->maToolbox.IsItemEnabled( TBI_FIRST ) )
924 0 : pNavigatorWin->maToolbox.EnableItem( TBI_FIRST );
925 0 : if( nState & NAVBTN_FIRST_DISABLED &&
926 0 : pNavigatorWin->maToolbox.IsItemEnabled( TBI_FIRST ) )
927 0 : pNavigatorWin->maToolbox.EnableItem( TBI_FIRST, false );
928 :
929 : // Prev
930 0 : if( nState & NAVBTN_PREV_ENABLED &&
931 0 : !pNavigatorWin->maToolbox.IsItemEnabled( TBI_PREVIOUS ) )
932 0 : pNavigatorWin->maToolbox.EnableItem( TBI_PREVIOUS );
933 0 : if( nState & NAVBTN_PREV_DISABLED &&
934 0 : pNavigatorWin->maToolbox.IsItemEnabled( TBI_PREVIOUS ) )
935 0 : pNavigatorWin->maToolbox.EnableItem( TBI_PREVIOUS, false );
936 :
937 : // Last
938 0 : if( nState & NAVBTN_LAST_ENABLED &&
939 0 : !pNavigatorWin->maToolbox.IsItemEnabled( TBI_LAST ) )
940 0 : pNavigatorWin->maToolbox.EnableItem( TBI_LAST );
941 0 : if( nState & NAVBTN_LAST_DISABLED &&
942 0 : pNavigatorWin->maToolbox.IsItemEnabled( TBI_LAST ) )
943 0 : pNavigatorWin->maToolbox.EnableItem( TBI_LAST, false );
944 :
945 : // Next
946 0 : if( nState & NAVBTN_NEXT_ENABLED &&
947 0 : !pNavigatorWin->maToolbox.IsItemEnabled( TBI_NEXT ) )
948 0 : pNavigatorWin->maToolbox.EnableItem( TBI_NEXT );
949 0 : if( nState & NAVBTN_NEXT_DISABLED &&
950 0 : pNavigatorWin->maToolbox.IsItemEnabled( TBI_NEXT ) )
951 0 : pNavigatorWin->maToolbox.EnableItem( TBI_NEXT, false );
952 :
953 0 : if( nState & NAVTLB_UPDATE )
954 : {
955 : // InitTlb; is initiated by Slot
956 0 : if (maUpdateRequest)
957 0 : maUpdateRequest();
958 : }
959 : }
960 : }
961 0 : }
962 :
963 : /**
964 : * ControllerItem for Navigator to show page in TreeLB
965 : */
966 0 : SdPageNameControllerItem::SdPageNameControllerItem(
967 : sal_uInt16 _nId,
968 : SdNavigatorWin* pNavWin,
969 : SfxBindings* _pBindings,
970 : const SdNavigatorWin::UpdateRequestFunctor& rUpdateRequest)
971 : : SfxControllerItem( _nId, *_pBindings ),
972 : pNavigatorWin( pNavWin ),
973 0 : maUpdateRequest(rUpdateRequest)
974 : {
975 0 : }
976 :
977 :
978 :
979 0 : void SdPageNameControllerItem::StateChanged( sal_uInt16 nSId,
980 : SfxItemState eState, const SfxPoolItem* pItem )
981 : {
982 0 : if( eState >= SFX_ITEM_AVAILABLE && nSId == SID_NAVIGATOR_PAGENAME )
983 : {
984 : // only if doc in LB is the active
985 0 : NavDocInfo* pInfo = pNavigatorWin->GetDocInfo();
986 0 : if( pInfo && pInfo->IsActive() )
987 : {
988 0 : const SfxStringItem* pStateItem = PTR_CAST( SfxStringItem, pItem );
989 : DBG_ASSERT( pStateItem, "SfxStringItem expected");
990 0 : OUString aPageName = pStateItem->GetValue();
991 :
992 0 : if( !pNavigatorWin->maTlbObjects.HasSelectedChildren( aPageName ) )
993 : {
994 0 : if( pNavigatorWin->maTlbObjects.GetSelectionMode() == MULTIPLE_SELECTION )
995 : {
996 : // because otherwise it is always additional select
997 0 : pNavigatorWin->maTlbObjects.SelectAll( false );
998 : }
999 0 : pNavigatorWin->maTlbObjects.SelectEntry( aPageName );
1000 0 : }
1001 : }
1002 : }
1003 0 : }
1004 :
1005 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|