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