bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / dlg / navigatr.cxx
blobf3170a445993d329a6f559182531842327d6fd2a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <memory>
21 #include <sal/config.h>
23 #include <osl/file.hxx>
24 #include <tools/urlobj.hxx>
25 #include <sfx2/fcontnr.hxx>
26 #include <svl/stritem.hxx>
27 #include <sfx2/docfile.hxx>
28 #include <svl/intitem.hxx>
29 #include <sfx2/dispatch.hxx>
31 #include <vcl/menu.hxx>
33 #include <sfx2/viewfrm.hxx>
35 #include <pres.hxx>
36 #include <navigatr.hxx>
37 #include <pgjump.hxx>
38 #include <app.hrc>
39 #include <strings.hrc>
41 #include <bitmaps.hlst>
42 #include <drawdoc.hxx>
43 #include <DrawDocShell.hxx>
44 #include <sdresid.hxx>
45 #include <ViewShell.hxx>
46 #include <ViewShellBase.hxx>
47 #include <slideshow.hxx>
48 #include <FrameView.hxx>
49 #include <helpids.h>
50 #include <Window.hxx>
52 namespace {
53 static const sal_uInt16 nShowNamedShapesFilter=1;
54 static const sal_uInt16 nShowAllShapesFilter=2;
57 /**
58 * SdNavigatorWin - FloatingWindow
60 SdNavigatorWin::SdNavigatorWin(vcl::Window* pParent, SfxBindings* pInBindings)
61 : PanelLayout(pParent, "NavigatorPanel", "modules/simpress/ui/navigatorpanel.ui", nullptr)
62 , mbDocImported ( false )
63 // On changes of the DragType: adjust SelectionMode of TLB!
64 , meDragType ( NAVIGATOR_DRAGTYPE_EMBEDDED )
65 , mpBindings ( pInBindings )
67 get(maToolbox, "toolbox");
68 get(maTlbObjects, "tree");
69 Size aSize(maTlbObjects->LogicToPixel(Size(97, 67), MapMode(MapUnit::MapAppFont)));
70 maTlbObjects->set_height_request(aSize.Width());
71 maTlbObjects->set_width_request(aSize.Height());
72 get(maLbDocs, "documents");
74 maTlbObjects->SetViewFrame( mpBindings->GetDispatcher()->GetFrame() );
76 maTlbObjects->SetAccessibleName(SdResId(STR_OBJECTS_TREE));
78 maTlbObjects->SetDoubleClickHdl(LINK(this, SdNavigatorWin, ClickObjectHdl));
79 maTlbObjects->SetSelectionMode(SelectionMode::Single);
81 maToolbox->SetSelectHdl( LINK( this, SdNavigatorWin, SelectToolboxHdl ) );
82 maToolbox->SetDropdownClickHdl( LINK(this, SdNavigatorWin, DropdownClickToolBoxHdl) );
83 const sal_uInt16 nDragTypeId = maToolbox->GetItemId("dragmode");
84 maToolbox->SetItemBits(nDragTypeId, maToolbox->GetItemBits(nDragTypeId) | ToolBoxItemBits::DROPDOWNONLY);
86 // Shape filter drop down menu.
87 const sal_uInt16 nShapeId = maToolbox->GetItemId("shapes");
88 maToolbox->SetItemBits(nShapeId, maToolbox->GetItemBits(nShapeId) | ToolBoxItemBits::DROPDOWNONLY);
90 // set focus to listbox, otherwise it is in the toolbox which is only useful
91 // for keyboard navigation
92 maTlbObjects->GrabFocus();
93 maTlbObjects->SetSdNavigator(this);
95 // DragTypeListBox
96 maLbDocs->SetSelectHdl( LINK( this, SdNavigatorWin, SelectDocumentHdl ) );
99 void SdNavigatorWin::SetUpdateRequestFunctor(const UpdateRequestFunctor& rUpdateRequest)
101 mpNavigatorCtrlItem.reset( new SdNavigatorControllerItem(SID_NAVIGATOR_STATE, this, mpBindings, rUpdateRequest) );
102 mpPageNameCtrlItem.reset( new SdPageNameControllerItem(SID_NAVIGATOR_PAGENAME, this, mpBindings) );
104 // InitTlb; is initiated over Slot
105 if (rUpdateRequest)
106 rUpdateRequest();
109 SdNavigatorWin::~SdNavigatorWin()
111 disposeOnce();
114 void SdNavigatorWin::dispose()
116 mpNavigatorCtrlItem.reset();
117 mpPageNameCtrlItem.reset();
118 maToolbox.clear();
119 maTlbObjects.clear();
120 maLbDocs.clear();
121 PanelLayout::dispose();
124 //when object is marked , fresh the corresponding entry tree .
125 void SdNavigatorWin::FreshTree( const SdDrawDocument* pDoc )
127 SdDrawDocument* pNonConstDoc = const_cast<SdDrawDocument*>(pDoc); // const as const can...
128 sd::DrawDocShell* pDocShell = pNonConstDoc->GetDocSh();
129 const OUString& aDocShName( pDocShell->GetName() );
130 OUString aDocName = pDocShell->GetMedium()->GetName();
131 maTlbObjects->SetSaveTreeItemStateFlag(true); //Added by yanjun for sym2_6385
132 maTlbObjects->Clear();
133 maTlbObjects->Fill( pDoc, false, aDocName ); // Only normal pages
134 maTlbObjects->SetSaveTreeItemStateFlag(false); //Added by yanjun for sym2_6385
135 RefreshDocumentLB();
136 maLbDocs->SelectEntry( aDocShName );
139 void SdNavigatorWin::FreshEntry( )
141 maTlbObjects->Invalidate();
144 void SdNavigatorWin::InitTreeLB( const SdDrawDocument* pDoc )
146 SdDrawDocument* pNonConstDoc = const_cast<SdDrawDocument*>(pDoc); // const as const can...
147 ::sd::DrawDocShell* pDocShell = pNonConstDoc->GetDocSh();
148 OUString aDocShName( pDocShell->GetName() );
149 ::sd::ViewShell* pViewShell = pDocShell->GetViewShell();
151 // Restore the 'ShowAllShapes' flag from the last time (in this session)
152 // that the navigator was shown.
153 if (pViewShell != nullptr)
155 ::sd::FrameView* pFrameView = pViewShell->GetFrameView();
156 if (pFrameView != nullptr)
157 maTlbObjects->SetShowAllShapes(pFrameView->IsNavigatorShowingAllShapes(), false);
160 // Disable the shape filter drop down menu when there is a running slide
161 // show.
162 const sal_uInt16 nShapeId = maToolbox->GetItemId("shapes");
163 if (pViewShell!=nullptr && sd::SlideShow::IsRunning( pViewShell->GetViewShellBase() ))
164 maToolbox->EnableItem(nShapeId, false);
165 else
166 maToolbox->EnableItem(nShapeId);
168 if( !maTlbObjects->IsEqualToDoc( pDoc ) )
170 OUString aDocName = pDocShell->GetMedium()->GetName();
171 maTlbObjects->Clear();
172 maTlbObjects->Fill( pDoc, false, aDocName ); // only normal pages
174 RefreshDocumentLB();
175 maLbDocs->SelectEntry( aDocShName );
177 else
179 maLbDocs->SetNoSelection();
180 maLbDocs->SelectEntry( aDocShName );
182 // commented in order to fix 30246
183 // if( maLbDocs->GetSelectedEntryCount() == 0 )
185 RefreshDocumentLB();
186 maLbDocs->SelectEntry( aDocShName );
190 SfxViewFrame* pViewFrame = ( ( pViewShell && pViewShell->GetViewFrame() ) ? pViewShell->GetViewFrame() : SfxViewFrame::Current() );
191 if( pViewFrame )
192 pViewFrame->GetBindings().Invalidate(SID_NAVIGATOR_PAGENAME, true, true);
196 * DragType is set on dependence if a Drag is even possible. For example,
197 * under certain circumstances, it is not allowed to drag graphics (#31038#).
199 NavigatorDragType SdNavigatorWin::GetNavigatorDragType()
201 NavigatorDragType eDT = meDragType;
202 NavDocInfo* pInfo = GetDocInfo();
204 if( ( eDT == NAVIGATOR_DRAGTYPE_LINK ) && ( ( pInfo && !pInfo->HasName() ) || !maTlbObjects->IsLinkableSelected() ) )
205 eDT = NAVIGATOR_DRAGTYPE_NONE;
207 return eDT;
210 VclPtr<SdPageObjsTLB> const & SdNavigatorWin::GetObjects()
212 return maTlbObjects;
215 IMPL_LINK_NOARG(SdNavigatorWin, SelectToolboxHdl, ToolBox *, void)
217 sal_uInt16 nId = maToolbox->GetCurItemId();
218 const OUString sCommand = maToolbox->GetItemCommand(nId);
219 PageJump ePage = PAGE_NONE;
221 if (sCommand == "first")
223 ePage = PAGE_FIRST;
224 maTlbObjects->Select( maTlbObjects->GetFirstEntryInView() );
226 else if (sCommand == "previous")
228 ePage = PAGE_PREVIOUS;
229 if( maTlbObjects->GetPrevEntryInView( maTlbObjects->GetCurEntry() ) != nullptr )
230 maTlbObjects->Select( maTlbObjects->GetPrevEntryInView( maTlbObjects->GetCurEntry() ) );
232 else if (sCommand == "next")
234 ePage = PAGE_NEXT;
235 if( maTlbObjects->GetNextEntryInView( maTlbObjects->GetCurEntry() ) != nullptr )
236 maTlbObjects->Select( maTlbObjects->GetNextEntryInView( maTlbObjects->GetCurEntry() ) );
238 else if (sCommand == "last")
240 ePage = PAGE_LAST;
241 maTlbObjects->Select( maTlbObjects->GetLastEntryInView() );
244 if (ePage != PAGE_NONE)
246 SfxUInt16Item aItem( SID_NAVIGATOR_PAGE, static_cast<sal_uInt16>(ePage) );
247 mpBindings->GetDispatcher()->ExecuteList(SID_NAVIGATOR_PAGE,
248 SfxCallMode::SLOT | SfxCallMode::RECORD, { &aItem });
252 IMPL_LINK( SdNavigatorWin, DropdownClickToolBoxHdl, ToolBox*, pBox, void )
254 sal_uInt16 nId = maToolbox->GetCurItemId();
255 const OUString sCommand = maToolbox->GetItemCommand(nId);
257 if (sCommand == "dragmode")
259 // Popup menu is created depending if the document is saved or not
260 ScopedVclPtrInstance<PopupMenu> pMenu;
262 static const char* aHIDs[] =
264 HID_SD_NAVIGATOR_MENU1,
265 HID_SD_NAVIGATOR_MENU2,
266 HID_SD_NAVIGATOR_MENU3,
267 nullptr
270 for (sal_uInt16 nID = NAVIGATOR_DRAGTYPE_URL; nID < NAVIGATOR_DRAGTYPE_COUNT; ++nID)
272 const char* pRId = GetDragTypeSdStrId(static_cast<NavigatorDragType>(nID));
273 if (pRId)
275 DBG_ASSERT(aHIDs[nID-NAVIGATOR_DRAGTYPE_URL],"HelpId not added!");
276 pMenu->InsertItem(nID, SdResId(pRId), MenuItemBits::RADIOCHECK);
277 pMenu->SetHelpId(nID, aHIDs[nID - NAVIGATOR_DRAGTYPE_URL]);
281 NavDocInfo* pInfo = GetDocInfo();
283 if( ( pInfo && !pInfo->HasName() ) || !maTlbObjects->IsLinkableSelected() )
285 pMenu->EnableItem( NAVIGATOR_DRAGTYPE_LINK, false );
286 pMenu->EnableItem( NAVIGATOR_DRAGTYPE_URL, false );
287 meDragType = NAVIGATOR_DRAGTYPE_EMBEDDED;
290 pMenu->CheckItem( static_cast<sal_uInt16>(meDragType) );
291 pMenu->SetSelectHdl( LINK( this, SdNavigatorWin, MenuSelectHdl ) );
293 pMenu->Execute( this, maToolbox->GetItemRect( nId ), PopupMenuFlags::ExecuteDown );
294 pBox->EndSelection();
296 else if (sCommand == "shapes")
298 ScopedVclPtrInstance<PopupMenu> pMenu;
300 pMenu->InsertItem(
301 nShowNamedShapesFilter,
302 SdResId(STR_NAVIGATOR_SHOW_NAMED_SHAPES),
303 MenuItemBits::RADIOCHECK);
304 pMenu->InsertItem(
305 nShowAllShapesFilter,
306 SdResId(STR_NAVIGATOR_SHOW_ALL_SHAPES),
307 MenuItemBits::RADIOCHECK);
309 if (maTlbObjects->GetShowAllShapes())
310 pMenu->CheckItem(nShowAllShapesFilter);
311 else
312 pMenu->CheckItem(nShowNamedShapesFilter);
313 pMenu->SetSelectHdl( LINK( this, SdNavigatorWin, ShapeFilterCallback ) );
315 pMenu->Execute( this, maToolbox->GetItemRect( nId ), PopupMenuFlags::ExecuteDown );
316 pBox->EndSelection();
320 IMPL_LINK_NOARG(SdNavigatorWin, ClickObjectHdl, SvTreeListBox*, bool)
322 if( !mbDocImported || maLbDocs->GetSelectedEntryPos() != 0 )
324 NavDocInfo* pInfo = GetDocInfo();
326 // if it is the active window, we jump to the page
327 if( pInfo && pInfo->IsActive() )
329 OUString aStr( maTlbObjects->GetSelectedEntry() );
331 if( !aStr.isEmpty() )
333 SfxStringItem aItem( SID_NAVIGATOR_OBJECT, aStr );
334 mpBindings->GetDispatcher()->ExecuteList(
335 SID_NAVIGATOR_OBJECT,
336 SfxCallMode::SLOT | SfxCallMode::RECORD, { &aItem });
337 //set sign variable
338 maTlbObjects->Invalidate();
340 // moved here from SetGetFocusHdl. Reset the
341 // focus only if something has been selected in the
342 // document.
343 SfxViewShell* pCurSh = SfxViewShell::Current();
345 if ( pCurSh )
347 vcl::Window* pShellWnd = pCurSh->GetWindow();
348 if ( pShellWnd )
349 pShellWnd->GrabFocus();
352 // We navigated to an object, but the current shell may be
353 // still the slide sorter. Explicitly try to grab the draw
354 // shell focus, so follow-up operations work with the object
355 // and not with the whole slide.
356 sd::DrawDocShell* pDocShell = pInfo->mpDocShell;
357 if (pDocShell)
359 sd::ViewShell* pViewShell = pDocShell->GetViewShell();
360 if (pViewShell)
362 vcl::Window* pWindow = pViewShell->GetActiveWindow();
363 if (pWindow)
364 pWindow->GrabFocus();
368 if (!maTlbObjects->IsNavigationGrabsFocus())
369 // This is the case when keyboard navigation inside the
370 // navigator should continue to work.
371 maTlbObjects->GrabFocus();
375 return false;
378 IMPL_LINK_NOARG(SdNavigatorWin, SelectDocumentHdl, ListBox&, void)
380 OUString aStrLb = maLbDocs->GetSelectedEntry();
381 long nPos = maLbDocs->GetSelectedEntryPos();
382 bool bFound = false;
383 ::sd::DrawDocShell* pDocShell = nullptr;
384 NavDocInfo* pInfo = GetDocInfo();
386 // is it a dragged object?
387 if( mbDocImported && nPos == 0 )
389 // construct document in TLB
390 InsertFile( aStrLb );
392 else if (pInfo)
394 pDocShell = pInfo->mpDocShell;
396 bFound = true;
399 if( bFound )
401 SdDrawDocument* pDoc = pDocShell->GetDoc();
402 if( !maTlbObjects->IsEqualToDoc( pDoc ) )
404 SdDrawDocument* pNonConstDoc = pDoc; // const as const can...
405 ::sd::DrawDocShell* pNCDocShell = pNonConstDoc->GetDocSh();
406 OUString aDocName = pNCDocShell->GetMedium()->GetName();
407 maTlbObjects->Clear();
408 maTlbObjects->Fill( pDoc, false, aDocName ); // only normal pages
412 // check if link or url is possible
413 if( ( pInfo && !pInfo->HasName() ) || !maTlbObjects->IsLinkableSelected() || ( meDragType != NAVIGATOR_DRAGTYPE_EMBEDDED ) )
415 meDragType = NAVIGATOR_DRAGTYPE_EMBEDDED;
416 SetDragImage();
421 * Set DrageType and set image accordingly to it.
422 * If the handler is called with NULL, the default (URL) is set.
424 IMPL_LINK( SdNavigatorWin, MenuSelectHdl, Menu *, pMenu, bool )
426 sal_uInt16 nMenuId;
427 if( pMenu )
428 nMenuId = pMenu->GetCurItemId();
429 else
430 nMenuId = NAVIGATOR_DRAGTYPE_URL;
432 if( nMenuId != USHRT_MAX ) // Necessary ?
434 NavigatorDragType eDT = static_cast<NavigatorDragType>(nMenuId);
435 if( meDragType != eDT )
437 meDragType = eDT;
438 SetDragImage();
440 if( meDragType == NAVIGATOR_DRAGTYPE_URL )
442 // patch, prevents endless loop
443 if( maTlbObjects->GetSelectionCount() > 1 )
444 maTlbObjects->SelectAll( false );
446 maTlbObjects->SetSelectionMode( SelectionMode::Single );
448 else
449 maTlbObjects->SetSelectionMode( SelectionMode::Multiple );
452 return false;
455 IMPL_LINK( SdNavigatorWin, ShapeFilterCallback, Menu *, pMenu, bool )
457 if (pMenu != nullptr)
459 bool bShowAllShapes (maTlbObjects->GetShowAllShapes());
460 sal_uInt16 nMenuId (pMenu->GetCurItemId());
461 switch (nMenuId)
463 case nShowNamedShapesFilter:
464 bShowAllShapes = false;
465 break;
467 case nShowAllShapesFilter:
468 bShowAllShapes = true;
469 break;
471 default:
472 OSL_FAIL(
473 "SdNavigatorWin::ShapeFilterCallback called for unknown menu entry");
474 break;
477 maTlbObjects->SetShowAllShapes(bShowAllShapes, true);
479 // Remember the selection in the FrameView.
480 NavDocInfo* pInfo = GetDocInfo();
481 if (pInfo != nullptr)
483 ::sd::DrawDocShell* pDocShell = pInfo->mpDocShell;
484 if (pDocShell != nullptr)
486 ::sd::ViewShell* pViewShell = pDocShell->GetViewShell();
487 if (pViewShell != nullptr)
489 ::sd::FrameView* pFrameView = pViewShell->GetFrameView();
490 if (pFrameView != nullptr)
492 pFrameView->SetIsNavigatorShowingAllShapes(bShowAllShapes);
499 return false;
502 bool SdNavigatorWin::InsertFile(const OUString& rFileName)
504 INetURLObject aURL( rFileName );
506 if( aURL.GetProtocol() == INetProtocol::NotValid )
508 OUString aURLStr;
509 osl::FileBase::getFileURLFromSystemPath( rFileName, aURLStr );
510 aURL = INetURLObject( aURLStr );
513 // get adjusted FileName
514 OUString aFileName( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
516 if (aFileName.isEmpty())
518 // show actual document again
519 maDropFileName = aFileName;
521 else
523 // show dragged-in document
524 std::shared_ptr<const SfxFilter> pFilter;
525 ErrCode nErr = ERRCODE_NONE;
527 if (aFileName != maDropFileName)
529 SfxMedium aMed(aFileName, (StreamMode::READ | StreamMode::SHARE_DENYNONE));
530 SfxFilterMatcher aMatch( "simpress" );
531 aMed.UseInteractionHandler( true );
532 nErr = aMatch.GuessFilter(aMed, pFilter);
535 if ((pFilter && !nErr) || aFileName == maDropFileName)
537 // The medium may be opened with READ/WRITE. Therefore, we first
538 // check if it contains a Storage.
539 std::unique_ptr<SfxMedium> xMedium(new SfxMedium(aFileName,
540 StreamMode::READ | StreamMode::NOCREATE));
542 if (xMedium->IsStorage())
544 // Now depending on mode:
545 // maTlbObjects->SetSelectionMode(SelectionMode::Multiple);
546 // handover of ownership of xMedium;
547 SdDrawDocument* pDropDoc = maTlbObjects->GetBookmarkDoc(xMedium.release());
549 if (pDropDoc)
551 maTlbObjects->Clear();
552 maDropFileName = aFileName;
554 if( !maTlbObjects->IsEqualToDoc( pDropDoc ) )
556 // only normal pages
557 maTlbObjects->Fill(pDropDoc, false, maDropFileName);
558 RefreshDocumentLB( &maDropFileName );
562 else
564 return false;
567 else
569 return false;
573 return true;
576 void SdNavigatorWin::RefreshDocumentLB( const OUString* pDocName )
578 sal_Int32 nPos = 0;
580 if( pDocName )
582 if( mbDocImported )
583 maLbDocs->RemoveEntry( 0 );
585 maLbDocs->InsertEntry( *pDocName, 0 );
586 mbDocImported = true;
588 else
590 nPos = maLbDocs->GetSelectedEntryPos();
591 if( nPos == LISTBOX_ENTRY_NOTFOUND )
592 nPos = 0;
594 OUString aStr;
595 if( mbDocImported )
596 aStr = maLbDocs->GetEntry( 0 );
598 maLbDocs->Clear();
600 // delete list of DocInfos
601 maDocList.clear();
603 if( mbDocImported )
604 maLbDocs->InsertEntry( aStr, 0 );
606 ::sd::DrawDocShell* pCurrentDocShell =
607 dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() );
608 SfxObjectShell* pSfxDocShell = SfxObjectShell::GetFirst([](const SfxObjectShell*){return true;}, false);
609 while( pSfxDocShell )
611 ::sd::DrawDocShell* pDocShell = dynamic_cast< ::sd::DrawDocShell *>( pSfxDocShell );
612 if( pDocShell && !pDocShell->IsInDestruction() && ( pDocShell->GetCreateMode() != SfxObjectCreateMode::EMBEDDED ) )
614 NavDocInfo aInfo ;
615 aInfo.mpDocShell = pDocShell;
617 SfxMedium *pMedium = pDocShell->GetMedium();
618 aStr = pMedium ? pMedium->GetName() : OUString();
619 if( !aStr.isEmpty() )
620 aInfo.SetName( true );
621 else
622 aInfo.SetName( false );
623 // at the moment, we use the name of the shell again (i.e.
624 // without path) since Koose thinks it is an error if the path
625 // is shown in url notation!
626 aStr = pDocShell->GetName();
628 maLbDocs->InsertEntry( aStr );
630 if( pDocShell == pCurrentDocShell )
631 aInfo.SetActive( true );
632 else
633 aInfo.SetActive( false );
635 maDocList.push_back( aInfo );
637 pSfxDocShell = SfxObjectShell::GetNext( *pSfxDocShell, [](const SfxObjectShell*){return true;}, false );
640 maLbDocs->SelectEntryPos( nPos );
643 const char* SdNavigatorWin::GetDragTypeSdStrId(NavigatorDragType eDT)
645 switch( eDT )
647 case NAVIGATOR_DRAGTYPE_NONE:
648 return STR_SD_NONE;
649 case NAVIGATOR_DRAGTYPE_URL:
650 return STR_DRAGTYPE_URL;
651 case NAVIGATOR_DRAGTYPE_EMBEDDED:
652 return STR_DRAGTYPE_EMBEDDED;
653 case NAVIGATOR_DRAGTYPE_LINK:
654 return STR_DRAGTYPE_LINK;
655 default: OSL_FAIL( "No resource for DragType available!" );
657 return nullptr;
660 OUString SdNavigatorWin::GetDragTypeSdBmpId(NavigatorDragType eDT)
662 switch( eDT )
664 case NAVIGATOR_DRAGTYPE_NONE:
665 return OUString();
666 case NAVIGATOR_DRAGTYPE_URL:
667 return OUString(BMP_HYPERLINK);
668 case NAVIGATOR_DRAGTYPE_EMBEDDED:
669 return OUString(BMP_EMBEDDED);
670 case NAVIGATOR_DRAGTYPE_LINK:
671 return OUString(BMP_LINK);
672 default: OSL_FAIL( "No resource for DragType available!" );
674 return OUString();
677 NavDocInfo* SdNavigatorWin::GetDocInfo()
679 sal_uInt32 nPos = maLbDocs->GetSelectedEntryPos();
681 if( mbDocImported )
683 if( nPos == 0 )
685 return nullptr;
687 nPos--;
690 return nPos < maDocList.size() ? &(maDocList[ nPos ]) : nullptr;
694 * PreNotify
696 bool SdNavigatorWin::EventNotify(NotifyEvent& rNEvt)
698 const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
699 bool bOK = false;
701 if( pKEvt )
703 if( KEY_ESCAPE == pKEvt->GetKeyCode().GetCode() )
705 if( SdPageObjsTLB::IsInDrag() )
707 // during drag'n'drop we just stop the drag but do not close the navigator
708 bOK = true;
710 else
712 ::sd::ViewShellBase* pBase = ::sd::ViewShellBase::GetViewShellBase( mpBindings->GetDispatcher()->GetFrame());
713 if( pBase )
715 sd::SlideShow::Stop( *pBase );
716 // Stopping the slide show may result in a synchronous
717 // deletion of the navigator window. Calling the
718 // parent's EventNotify after this is unsafe. Therefore we
719 // return now.
720 return true;
726 if( !bOK )
727 bOK = Window::EventNotify(rNEvt);
729 return bOK;
733 * catch ESCAPE in order to end show
735 void SdNavigatorWin::KeyInput( const KeyEvent& rKEvt )
737 bool bOK = false;
739 if (rKEvt.GetKeyCode().GetCode() == KEY_ESCAPE)
741 if( SdPageObjsTLB::IsInDrag() )
743 // during drag'n'drop we just stop the drag but do not close the navigator
744 bOK = true;
746 else
748 ::sd::ViewShellBase* pBase = ::sd::ViewShellBase::GetViewShellBase( mpBindings->GetDispatcher()->GetFrame());
749 if(pBase)
751 ::sd::SlideShow::Stop( *pBase );
756 if (!bOK)
758 Window::KeyInput(rKEvt);
762 void SdNavigatorWin::SetDragImage()
764 const sal_uInt16 nDragTypeId = maToolbox->GetItemId("dragmode");
765 maToolbox->SetItemImage(nDragTypeId, Image(StockImage::Yes, GetDragTypeSdBmpId(meDragType)));
769 * ControllerItem for Navigator
771 SdNavigatorControllerItem::SdNavigatorControllerItem(
772 sal_uInt16 _nId,
773 SdNavigatorWin* pNavWin,
774 SfxBindings* _pBindings,
775 const SdNavigatorWin::UpdateRequestFunctor& rUpdateRequest)
776 : SfxControllerItem( _nId, *_pBindings ),
777 pNavigatorWin( pNavWin ),
778 maUpdateRequest(rUpdateRequest)
782 void SdNavigatorControllerItem::StateChanged( sal_uInt16 nSId,
783 SfxItemState eState, const SfxPoolItem* pItem )
785 if( !(eState >= SfxItemState::DEFAULT && nSId == SID_NAVIGATOR_STATE) )
786 return;
788 const SfxUInt32Item& rStateItem = dynamic_cast<const SfxUInt32Item&>(*pItem);
789 NavState nState = static_cast<NavState>(rStateItem.GetValue());
791 // only if doc in LB is the active
792 NavDocInfo* pInfo = pNavigatorWin->GetDocInfo();
793 if( !(pInfo && pInfo->IsActive()) )
794 return;
796 sal_uInt16 nFirstId = pNavigatorWin->maToolbox->GetItemId("first");
797 sal_uInt16 nPrevId = pNavigatorWin->maToolbox->GetItemId("previous");
798 sal_uInt16 nLastId = pNavigatorWin->maToolbox->GetItemId("last");
799 sal_uInt16 nNextId = pNavigatorWin->maToolbox->GetItemId("next");
801 // First
802 if (nState & NavState::BtnFirstEnabled &&
803 !pNavigatorWin->maToolbox->IsItemEnabled(nFirstId))
804 pNavigatorWin->maToolbox->EnableItem(nFirstId);
805 if (nState & NavState::BtnFirstDisabled &&
806 pNavigatorWin->maToolbox->IsItemEnabled(nFirstId))
807 pNavigatorWin->maToolbox->EnableItem(nFirstId, false);
809 // Prev
810 if (nState & NavState::BtnPrevEnabled &&
811 !pNavigatorWin->maToolbox->IsItemEnabled(nPrevId))
812 pNavigatorWin->maToolbox->EnableItem(nPrevId);
813 if (nState & NavState::BtnPrevDisabled &&
814 pNavigatorWin->maToolbox->IsItemEnabled(nPrevId))
815 pNavigatorWin->maToolbox->EnableItem(nPrevId, false);
817 // Last
818 if (nState & NavState::BtnLastEnabled &&
819 !pNavigatorWin->maToolbox->IsItemEnabled(nLastId))
820 pNavigatorWin->maToolbox->EnableItem(nLastId);
821 if (nState & NavState::BtnLastDisabled &&
822 pNavigatorWin->maToolbox->IsItemEnabled(nLastId))
823 pNavigatorWin->maToolbox->EnableItem(nLastId, false);
825 // Next
826 if (nState & NavState::BtnNextEnabled &&
827 !pNavigatorWin->maToolbox->IsItemEnabled(nNextId))
828 pNavigatorWin->maToolbox->EnableItem(nNextId);
829 if (nState & NavState::BtnNextDisabled &&
830 pNavigatorWin->maToolbox->IsItemEnabled(nNextId))
831 pNavigatorWin->maToolbox->EnableItem(nNextId, false);
833 if (nState & NavState::TableUpdate)
835 // InitTlb; is initiated by Slot
836 if (maUpdateRequest)
837 maUpdateRequest();
842 * ControllerItem for Navigator to show page in TreeLB
844 SdPageNameControllerItem::SdPageNameControllerItem(
845 sal_uInt16 _nId,
846 SdNavigatorWin* pNavWin,
847 SfxBindings* _pBindings)
848 : SfxControllerItem( _nId, *_pBindings ),
849 pNavigatorWin( pNavWin )
853 void SdPageNameControllerItem::StateChanged( sal_uInt16 nSId,
854 SfxItemState eState, const SfxPoolItem* pItem )
856 if( !(eState >= SfxItemState::DEFAULT && nSId == SID_NAVIGATOR_PAGENAME) )
857 return;
859 // only if doc in LB is the active
860 NavDocInfo* pInfo = pNavigatorWin->GetDocInfo();
861 if( !(pInfo && pInfo->IsActive()) )
862 return;
864 const SfxStringItem& rStateItem = dynamic_cast<const SfxStringItem&>(*pItem);
865 const OUString& aPageName = rStateItem.GetValue();
867 if( !pNavigatorWin->maTlbObjects->HasSelectedChildren( aPageName ) )
869 if( pNavigatorWin->maTlbObjects->GetSelectionMode() == SelectionMode::Multiple )
871 // because otherwise it is always additional select
872 pNavigatorWin->maTlbObjects->SelectAll( false );
874 pNavigatorWin->maTlbObjects->SelectEntry( aPageName );
878 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */