tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / sd / source / ui / dlg / navigatr.cxx
blobd4f189277fd7d98b45220fb7fd4f55163efc7f45
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/diagnose.h>
24 #include <osl/file.hxx>
25 #include <tools/urlobj.hxx>
26 #include <sfx2/fcontnr.hxx>
27 #include <svl/stritem.hxx>
28 #include <sfx2/docfile.hxx>
29 #include <svl/intitem.hxx>
30 #include <sfx2/dispatch.hxx>
32 #include <sfx2/viewfrm.hxx>
34 #include <pres.hxx>
35 #include <navigatr.hxx>
36 #include <pgjump.hxx>
37 #include <app.hrc>
39 #include <bitmaps.hlst>
40 #include <drawdoc.hxx>
41 #include <DrawDocShell.hxx>
42 #include <ViewShell.hxx>
43 #include <ViewShellBase.hxx>
44 #include <slideshow.hxx>
45 #include <FrameView.hxx>
46 #include <Window.hxx>
48 #include <DrawViewShell.hxx>
49 #include <utility>
51 #include <vcl/commandevent.hxx>
52 #include <comphelper/lok.hxx>
54 #include <sdpage.hxx>
56 /**
57 * SdNavigatorWin - FloatingWindow
59 SdNavigatorWin::SdNavigatorWin(weld::Widget* pParent, SfxBindings* pInBindings, SfxNavigator* pNavigatorDlg)
60 : PanelLayout(pParent, u"NavigatorPanel"_ustr, u"modules/simpress/ui/navigatorpanel.ui"_ustr)
61 , mxToolbox(m_xBuilder->weld_toolbar(u"toolbox"_ustr))
62 , mxTlbObjects(new SdPageObjsTLV(m_xBuilder->weld_tree_view(u"tree"_ustr)))
63 , mxLbDocs(m_xBuilder->weld_combo_box(u"documents"_ustr))
64 , mxDragModeMenu(m_xBuilder->weld_menu(u"dragmodemenu"_ustr))
65 , mxShapeMenu(m_xBuilder->weld_menu(u"shapemenu"_ustr))
66 , mxNavigatorDlg(pNavigatorDlg)
67 , mbDocImported ( false )
68 // On changes of the DragType: adjust SelectionMode of TLB!
69 , meDragType ( NAVIGATOR_DRAGTYPE_EMBEDDED )
70 , mpBindings ( pInBindings )
72 mxTlbObjects->SetViewFrame( mpBindings->GetDispatcher()->GetFrame() );
74 mxTlbObjects->connect_row_activated(LINK(this, SdNavigatorWin, ClickObjectHdl));
75 mxTlbObjects->set_selection_mode(SelectionMode::Multiple);
76 mxTlbObjects->connect_mouse_release(LINK(this, SdNavigatorWin, MouseReleaseHdl));
77 mxTlbObjects->connect_popup_menu(LINK(this, SdNavigatorWin, CommandHdl));
79 mxToolbox->connect_clicked(LINK(this, SdNavigatorWin, SelectToolboxHdl));
80 mxToolbox->connect_menu_toggled(LINK(this, SdNavigatorWin, DropdownClickToolBoxHdl));
82 mxToolbox->set_item_menu(u"dragmode"_ustr, mxDragModeMenu.get());
83 mxDragModeMenu->connect_activate(LINK(this, SdNavigatorWin, MenuSelectHdl));
85 // Shape filter drop down menu.
86 mxToolbox->set_item_menu(u"shapes"_ustr, mxShapeMenu.get());
87 mxShapeMenu->connect_activate(LINK(this, SdNavigatorWin, ShapeFilterCallback));
89 mxTlbObjects->SetSdNavigator(this);
91 // DragTypeListBox
92 mxLbDocs->set_size_request(42, -1); // set a nominal width so it takes width of surroundings
93 mxLbDocs->connect_changed(LINK(this, SdNavigatorWin, SelectDocumentHdl));
95 SetDragImage();
97 mxToolbox->connect_key_press(LINK(this, SdNavigatorWin, KeyInputHdl));
98 mxTlbObjects->connect_key_press(LINK(this, SdNavigatorWin, KeyInputHdl));
99 mxLbDocs->connect_key_press(LINK(this, SdNavigatorWin, KeyInputHdl));
100 if(comphelper::LibreOfficeKit::isActive())
102 mxToolbox->hide();
103 mxLbDocs->hide();
107 void SdNavigatorWin::FirstFocus()
109 // set focus to listbox, otherwise it is in the toolbox which is only useful
110 // for keyboard navigation
111 mxTlbObjects->grab_focus();
114 weld::Window* SdNavigatorWin::GetFrameWeld() const
116 if (mxNavigatorDlg)
117 return mxNavigatorDlg->GetFrameWeld();
118 return PanelLayout::GetFrameWeld();
121 void SdNavigatorWin::SetUpdateRequestFunctor(const UpdateRequestFunctor& rUpdateRequest)
123 mpNavigatorCtrlItem.reset( new SdNavigatorControllerItem(SID_NAVIGATOR_STATE, this, mpBindings, rUpdateRequest) );
124 mpPageNameCtrlItem.reset( new SdPageNameControllerItem(SID_NAVIGATOR_PAGENAME, this, mpBindings) );
126 // InitTlb; is initiated over Slot
127 if (rUpdateRequest)
128 rUpdateRequest();
131 SdNavigatorWin::~SdNavigatorWin()
133 mpNavigatorCtrlItem.reset();
134 mpPageNameCtrlItem.reset();
135 mxDragModeMenu.reset();
136 mxShapeMenu.reset();
137 mxToolbox.reset();
138 mxTlbObjects.reset();
139 mxLbDocs.reset();
142 static void lcl_select_marked_objects(sd::ViewShell* pViewShell, SdPageObjsTLV* pTlbObjects)
144 if (const SdrView* pView = pViewShell->GetDrawView())
146 auto vMarkedObjects = pView->GetMarkedObjects();
147 if (vMarkedObjects.size())
149 pTlbObjects->unselect_all();
150 for (auto rMarkedObject: vMarkedObjects)
151 pTlbObjects->SelectEntry(rMarkedObject);
153 else
155 if (SdPage* pPage = pViewShell->GetActualPage())
156 pTlbObjects->SelectEntry(pPage->GetName());
161 void SdNavigatorWin::InitTreeLB( const SdDrawDocument* pDoc )
163 SdDrawDocument* pNonConstDoc = const_cast<SdDrawDocument*>(pDoc); // const as const can...
164 ::sd::DrawDocShell* pDocShell = pNonConstDoc->GetDocSh();
165 OUString aDocShName( pDocShell->GetName() );
166 ::sd::ViewShell* pViewShell = pDocShell->GetViewShell();
168 // tdf#160190
169 if (!pViewShell)
170 return;
172 // tdf#139944 disable navigator in master mode
173 if (const sd::DrawViewShell* pDrawViewShell = static_cast<::sd::DrawViewShell*>(pViewShell))
175 if (pDrawViewShell->GetEditMode() == EditMode::MasterPage)
177 m_xContainer->set_sensitive(false);
178 mxTlbObjects->clear();
179 RefreshDocumentLB();
180 return;
182 else
183 m_xContainer->set_sensitive(true);
186 // Restore the 'ShowAllShapes' flag from the last time (in this session)
187 // that the navigator was shown.
188 ::sd::FrameView* pFrameView = pViewShell->GetFrameView();
189 if (pFrameView != nullptr)
190 mxTlbObjects->SetShowAllShapes(pFrameView->IsNavigatorShowingAllShapes(), false);
192 // Disable the shape filter drop down menu when there is a running slide
193 // show.
194 if (sd::SlideShow::IsRunning( pViewShell->GetViewShellBase() )
195 && !sd::SlideShow::IsInteractiveSlideshow( &pViewShell->GetViewShellBase() ) ) // IASS
196 mxToolbox->set_item_sensitive(u"shapes"_ustr, false);
197 else
198 mxToolbox->set_item_sensitive(u"shapes"_ustr, true);
200 if( !mxTlbObjects->IsEqualToDoc( pDoc ) )
202 OUString aDocName = pDocShell->GetMedium()->GetName();
203 mxTlbObjects->clear();
204 mxTlbObjects->Fill( pDoc, false, aDocName ); // only normal pages
206 RefreshDocumentLB();
207 mxLbDocs->set_active_text(aDocShName);
209 else
211 mxLbDocs->set_active(-1);
212 mxLbDocs->set_active_text(aDocShName);
214 // commented in order to fix 30246
215 // if( mxLbDocs->get_active() == -1 )
217 RefreshDocumentLB();
218 mxLbDocs->set_active_text(aDocShName);
222 lcl_select_marked_objects(pViewShell, mxTlbObjects.get());
226 * DragType is set on dependence if a Drag is even possible. For example,
227 * under certain circumstances, it is not allowed to drag graphics (#31038#).
229 NavigatorDragType SdNavigatorWin::GetNavigatorDragType()
231 NavigatorDragType eDT = meDragType;
232 NavDocInfo* pInfo = GetDocInfo();
234 if( ( eDT == NAVIGATOR_DRAGTYPE_LINK ) && ( ( pInfo && !pInfo->HasName() ) || !mxTlbObjects->IsLinkableSelected() ) )
235 eDT = NAVIGATOR_DRAGTYPE_NONE;
237 return eDT;
240 SdPageObjsTLV& SdNavigatorWin::GetObjects()
242 return *mxTlbObjects;
245 IMPL_STATIC_LINK_NOARG(SdNavigatorWin, MouseReleaseHdl, const MouseEvent&, bool)
247 return true;
250 IMPL_LINK(SdNavigatorWin, CommandHdl, const CommandEvent&, rCEvt, bool)
252 if (NavDocInfo* pInfo = GetDocInfo(); !pInfo || !pInfo->IsActive())
253 return false;
254 if (rCEvt.GetCommand() != CommandEventId::ContextMenu)
255 return false;
256 weld::TreeView& rTreeView = GetObjects().get_treeview();
257 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(&rTreeView,
258 u"modules/sdraw/ui/navigatorcontextmenu.ui"_ustr));
259 std::unique_ptr<weld::Menu> xPop = xBuilder->weld_menu(u"navmenu"_ustr);
260 OUString sCommand = xPop->popup_at_rect(&rTreeView,
261 tools::Rectangle(rCEvt.GetMousePosPixel(), Size(1,1)));
262 if (!sCommand.isEmpty())
263 ExecuteContextMenuAction(sCommand);
264 return true;
267 void SdNavigatorWin::ExecuteContextMenuAction(std::u16string_view rSelectedPopupEntry)
269 if (rSelectedPopupEntry == u"rename")
271 weld::TreeView& rTreeView = GetObjects().get_treeview();
272 std::unique_ptr<weld::TreeIter> xIter(rTreeView.make_iterator());
273 if (rTreeView.get_selected(xIter.get()))
275 // grab the shell focus so the navigator will update
276 if (SfxViewShell* pCurSh = SfxViewShell::Current())
278 if (vcl::Window* pShellWnd = pCurSh->GetWindow())
279 pShellWnd->GrabFocus();
281 if (rTreeView.get_iter_depth(*xIter) > 0)
282 mpBindings->Execute(SID_NAME_GROUP);
283 else
284 mpBindings->Execute(SID_RENAMEPAGE);
289 IMPL_LINK(SdNavigatorWin, SelectToolboxHdl, const OUString&, rCommand, void)
291 PageJump ePage = PAGE_NONE;
293 if (rCommand == "first")
294 ePage = PAGE_FIRST;
295 else if (rCommand == "previous")
296 ePage = PAGE_PREVIOUS;
297 else if (rCommand == "next")
298 ePage = PAGE_NEXT;
299 else if (rCommand == "last")
300 ePage = PAGE_LAST;
301 else if (rCommand == "dragmode")
302 mxToolbox->set_menu_item_active(u"dragmode"_ustr, !mxToolbox->get_menu_item_active(u"dragmode"_ustr));
303 else if (rCommand == "shapes")
304 mxToolbox->set_menu_item_active(u"shapes"_ustr, !mxToolbox->get_menu_item_active(u"shapes"_ustr));
306 if (ePage != PAGE_NONE)
308 SfxUInt16Item aItem( SID_NAVIGATOR_PAGE, static_cast<sal_uInt16>(ePage) );
309 mpBindings->GetDispatcher()->ExecuteList(SID_NAVIGATOR_PAGE,
310 SfxCallMode::SLOT | SfxCallMode::RECORD, { &aItem });
314 IMPL_LINK(SdNavigatorWin, DropdownClickToolBoxHdl, const OUString&, rCommand, void)
316 if (!mxToolbox->get_menu_item_active(rCommand))
317 return;
319 if (rCommand == "dragmode")
321 NavDocInfo* pInfo = GetDocInfo();
322 if( ( pInfo && !pInfo->HasName() ) || !mxTlbObjects->IsLinkableSelected() )
324 mxDragModeMenu->set_sensitive(OUString::number(NAVIGATOR_DRAGTYPE_LINK), false);
325 mxDragModeMenu->set_sensitive(OUString::number(NAVIGATOR_DRAGTYPE_URL), false);
326 meDragType = NAVIGATOR_DRAGTYPE_EMBEDDED;
329 mxDragModeMenu->set_active(OUString::number(meDragType), true);
331 else if (rCommand == "shapes")
333 bool bAll = mxTlbObjects->GetShowAllShapes();
334 mxShapeMenu->set_active(u"named"_ustr, !bAll);
335 mxShapeMenu->set_active(u"all"_ustr, bAll);
336 bool bOrderFrontToBack = mxTlbObjects->GetOrderFrontToBack();
337 mxShapeMenu->set_active(u"fronttoback"_ustr, bOrderFrontToBack);
338 mxShapeMenu->set_active(u"backtofront"_ustr, !bOrderFrontToBack);
342 IMPL_LINK_NOARG(SdNavigatorWin, ClickObjectHdl, weld::TreeView&, bool)
344 if( !mbDocImported || mxLbDocs->get_active() != 0 )
346 NavDocInfo* pInfo = GetDocInfo();
348 // if it is the active window, we jump to the page
349 if( pInfo && pInfo->IsActive() )
351 OUString aStr(mxTlbObjects->get_cursor_text());
353 if( !aStr.isEmpty() )
355 sd::DrawDocShell* pDocShell = pInfo->mpDocShell;
356 if (!pDocShell)
357 return false;
358 sd::ViewShell* pViewShell = pDocShell->GetViewShell();
359 if (!pViewShell)
360 return false;
361 SdrView* pDrawView = pViewShell->GetDrawView();
362 if (!pDrawView)
363 return false;
365 // Save the selected tree entries re-mark the objects in the view after navigation.
366 auto vSelectedEntryIds = mxTlbObjects->GetSelectedEntryIds();
368 // Page entries in the tree have id value 1. Object entries have id value of
369 // the address of the pointer to the object.
370 const auto aCursorEntryId = mxTlbObjects->get_cursor_id();
371 auto nCursorEntryId = aCursorEntryId.toInt64();
372 SdrObject* pCursorEntryObject = weld::fromId<SdrObject*>(aCursorEntryId);
374 bool bIsCursorEntrySelected(std::find(vSelectedEntryIds.begin(),
375 vSelectedEntryIds.end(),
376 aCursorEntryId) != vSelectedEntryIds.end());
378 if (bIsCursorEntrySelected)
380 // Set a temporary name, if need be, so the object can be navigated to.
381 bool bCursorEntryObjectHasEmptyName = false;
382 if (nCursorEntryId != 1 && pCursorEntryObject
383 && pCursorEntryObject->GetName().isEmpty())
385 bCursorEntryObjectHasEmptyName = true;
386 bool bUndo = pCursorEntryObject->getSdrModelFromSdrObject().IsUndoEnabled();
387 pCursorEntryObject->getSdrModelFromSdrObject().EnableUndo(false);
388 pCursorEntryObject->SetName(aStr, false);
389 pCursorEntryObject->getSdrModelFromSdrObject().EnableUndo(bUndo);
392 // All objects are unmarked when navigating to an object.
393 SfxStringItem aItem(SID_NAVIGATOR_OBJECT, aStr);
394 mpBindings->GetDispatcher()->ExecuteList(SID_NAVIGATOR_OBJECT,
395 SfxCallMode::SLOT | SfxCallMode::RECORD, { &aItem });
397 if (bCursorEntryObjectHasEmptyName)
399 bool bUndo = pCursorEntryObject->getSdrModelFromSdrObject().IsUndoEnabled();
400 pCursorEntryObject->getSdrModelFromSdrObject().EnableUndo(false);
401 pCursorEntryObject->SetName(OUString(), false);
402 pCursorEntryObject->getSdrModelFromSdrObject().EnableUndo(bUndo);
405 // re-mark the objects
406 if (bIsCursorEntrySelected)
408 // Mark the objects in the view that are selected in the Navigator tree.
409 for (auto& rEntryId: vSelectedEntryIds)
411 if (rEntryId != "1")
413 SdrObject* pEntryObject = weld::fromId<SdrObject*>(rEntryId);
414 if (pEntryObject)
415 pDrawView->MarkObj(pEntryObject, pDrawView->GetSdrPageView());
420 else if (nCursorEntryId != 1 && pCursorEntryObject)
422 // unmark
423 pDrawView->MarkObj(pCursorEntryObject, pDrawView->GetSdrPageView(), true);
426 // SID_NAVIGATOR_STATE invalidate is done in DrawViewShell::ExecNavigatorWin
427 // and DrawDocShell::GotoBookmark. Update the bindings here to speed up Navigator
428 // state update.
429 mpBindings->Update();
431 if (mxTlbObjects->IsNavigationGrabsFocus())
433 // moved here from SetGetFocusHdl. Reset the
434 // focus only if something has been selected in the
435 // document.
436 SfxViewShell* pCurSh = SfxViewShell::Current();
438 if ( pCurSh )
440 vcl::Window* pShellWnd = pCurSh->GetWindow();
441 if ( pShellWnd )
442 pShellWnd->GrabFocus();
445 // We navigated to an object, but the current shell may be
446 // still the slide sorter. Explicitly try to grab the draw
447 // shell focus, so follow-up operations work with the object
448 // and not with the whole slide.
449 vcl::Window* pWindow = pViewShell->GetActiveWindow();
450 if (pWindow)
451 pWindow->GrabFocus();
456 return false;
459 IMPL_LINK_NOARG(SdNavigatorWin, SelectDocumentHdl, weld::ComboBox&, void)
461 OUString aStrLb = mxLbDocs->get_active_text();
462 tools::Long nPos = mxLbDocs->get_active();
463 bool bFound = false;
464 ::sd::DrawDocShell* pDocShell = nullptr;
465 NavDocInfo* pInfo = GetDocInfo();
467 // is it a dragged object?
468 if( mbDocImported && nPos == 0 )
470 // construct document in TLB
471 InsertFile( aStrLb );
473 else if (pInfo)
475 pDocShell = pInfo->mpDocShell;
477 bFound = true;
480 if( bFound )
482 SdDrawDocument* pDoc = pDocShell->GetDoc();
483 if( !mxTlbObjects->IsEqualToDoc( pDoc ) )
485 SdDrawDocument* pNonConstDoc = pDoc; // const as const can...
486 ::sd::DrawDocShell* pNCDocShell = pNonConstDoc->GetDocSh();
487 OUString aDocName = pNCDocShell->GetMedium()->GetName();
488 mxTlbObjects->clear();
489 mxTlbObjects->Fill( pDoc, false, aDocName ); // only normal pages
493 // check if link or url is possible
494 if( ( pInfo && !pInfo->HasName() ) || !mxTlbObjects->IsLinkableSelected() || ( meDragType != NAVIGATOR_DRAGTYPE_EMBEDDED ) )
496 meDragType = NAVIGATOR_DRAGTYPE_EMBEDDED;
497 SetDragImage();
502 * Set DrageType and set image accordingly to it.
504 IMPL_LINK(SdNavigatorWin, MenuSelectHdl, const OUString&, rIdent, void)
506 sal_uInt32 nMenuId = rIdent.toUInt32();
508 NavigatorDragType eDT = static_cast<NavigatorDragType>(nMenuId);
509 if( meDragType == eDT )
510 return;
512 meDragType = eDT;
513 SetDragImage();
515 if( meDragType == NAVIGATOR_DRAGTYPE_URL )
517 // patch, prevents endless loop
518 if (mxTlbObjects->count_selected_rows() > 1)
519 mxTlbObjects->unselect_all();
521 mxTlbObjects->set_selection_mode(SelectionMode::Single);
523 else
524 mxTlbObjects->set_selection_mode(SelectionMode::Multiple);
527 IMPL_LINK( SdNavigatorWin, ShapeFilterCallback, const OUString&, rIdent, void )
529 bool bShowAllShapes(mxTlbObjects->GetShowAllShapes());
530 bool bOrderFrontToBack(mxTlbObjects->GetOrderFrontToBack());
531 if (rIdent == "named")
532 bShowAllShapes = false;
533 else if (rIdent == "all")
534 bShowAllShapes = true;
535 else if (rIdent == "fronttoback")
536 bOrderFrontToBack = true;
537 else if (rIdent == "backtofront")
538 bOrderFrontToBack = false;
539 else
540 OSL_FAIL("SdNavigatorWin::ShapeFilterCallback called for unknown menu entry");
542 mxTlbObjects->SetOrderFrontToBack(bOrderFrontToBack);
543 mxTlbObjects->SetShowAllShapes(bShowAllShapes, true);
545 // Remember the selection in the FrameView.
546 NavDocInfo* pInfo = GetDocInfo();
547 if (pInfo == nullptr)
548 return;
550 ::sd::DrawDocShell* pDocShell = pInfo->mpDocShell;
551 if (pDocShell != nullptr)
553 ::sd::ViewShell* pViewShell = pDocShell->GetViewShell();
554 if (pViewShell != nullptr)
556 ::sd::FrameView* pFrameView = pViewShell->GetFrameView();
557 if (pFrameView != nullptr)
559 pFrameView->SetIsNavigatorShowingAllShapes(bShowAllShapes);
561 lcl_select_marked_objects(pViewShell, mxTlbObjects.get());
566 bool SdNavigatorWin::InsertFile(const OUString& rFileName)
568 INetURLObject aURL( rFileName );
570 if( aURL.GetProtocol() == INetProtocol::NotValid )
572 OUString aURLStr;
573 osl::FileBase::getFileURLFromSystemPath( rFileName, aURLStr );
574 aURL = INetURLObject( aURLStr );
577 // get adjusted FileName
578 OUString aFileName( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
580 if (aFileName.isEmpty())
582 // show actual document again
583 maDropFileName = aFileName;
585 else
587 // show dragged-in document
588 std::shared_ptr<const SfxFilter> pFilter;
589 ErrCode nErr = ERRCODE_NONE;
591 if (aFileName != maDropFileName)
593 SfxMedium aMed(aFileName, (StreamMode::READ | StreamMode::SHARE_DENYNONE));
594 SfxFilterMatcher aMatch( u"simpress"_ustr );
595 aMed.UseInteractionHandler( true );
596 nErr = aMatch.GuessFilter(aMed, pFilter);
599 if ((pFilter && !nErr) || aFileName == maDropFileName)
601 // The medium may be opened with READ/WRITE. Therefore, we first
602 // check if it contains a Storage.
603 std::unique_ptr<SfxMedium> xMedium(new SfxMedium(aFileName,
604 StreamMode::READ | StreamMode::NOCREATE));
606 if (xMedium->IsStorage())
608 // Now depending on mode:
609 // mxTlbObjects->set_selection_mode(SelectionMode::Multiple);
610 // handover of ownership of xMedium;
611 SdDrawDocument* pDropDoc = mxTlbObjects->GetBookmarkDoc(xMedium.release());
613 if (pDropDoc)
615 mxTlbObjects->clear();
616 maDropFileName = aFileName;
618 if( !mxTlbObjects->IsEqualToDoc( pDropDoc ) )
620 // only normal pages
621 mxTlbObjects->Fill(pDropDoc, false, maDropFileName);
622 RefreshDocumentLB( &maDropFileName );
626 else
628 return false;
631 else
633 return false;
637 return true;
640 void SdNavigatorWin::RefreshDocumentLB( const OUString* pDocName )
642 sal_Int32 nPos = 0;
644 if( pDocName )
646 if( mbDocImported )
647 mxLbDocs->remove(0);
649 mxLbDocs->insert_text(0, *pDocName);
650 mbDocImported = true;
652 else
654 nPos = mxLbDocs->get_active();
655 if (nPos == -1)
656 nPos = 0;
658 OUString aStr;
659 if( mbDocImported )
660 aStr = mxLbDocs->get_text(0);
662 mxLbDocs->clear();
664 // delete list of DocInfos
665 maDocList.clear();
667 if( mbDocImported )
668 mxLbDocs->insert_text(0, aStr);
670 ::sd::DrawDocShell* pCurrentDocShell =
671 dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() );
672 SfxObjectShell* pSfxDocShell = SfxObjectShell::GetFirst();
673 while( pSfxDocShell )
675 ::sd::DrawDocShell* pDocShell = dynamic_cast< ::sd::DrawDocShell *>( pSfxDocShell );
676 if( pDocShell && !pDocShell->IsInDestruction() && ( pDocShell->GetCreateMode() != SfxObjectCreateMode::EMBEDDED ) )
678 NavDocInfo aInfo ;
679 aInfo.mpDocShell = pDocShell;
681 SfxMedium *pMedium = pDocShell->GetMedium();
682 aStr = pMedium ? pMedium->GetName() : OUString();
683 if( !aStr.isEmpty() )
684 aInfo.SetName( true );
685 else
686 aInfo.SetName( false );
687 // at the moment, we use the name of the shell again (i.e.
688 // without path) since Koose thinks it is an error if the path
689 // is shown in url notation!
690 aStr = pDocShell->GetName();
692 mxLbDocs->append_text(aStr);
694 if( pDocShell == pCurrentDocShell )
695 aInfo.SetActive( true );
696 else
697 aInfo.SetActive( false );
699 maDocList.push_back( aInfo );
701 pSfxDocShell = SfxObjectShell::GetNext(*pSfxDocShell);
704 mxLbDocs->set_active(nPos);
707 const OUString & SdNavigatorWin::GetDragTypeSdBmpId(NavigatorDragType eDT)
709 switch( eDT )
711 case NAVIGATOR_DRAGTYPE_NONE:
712 return EMPTY_OUSTRING;
713 case NAVIGATOR_DRAGTYPE_URL:
714 return BMP_HYPERLINK;
715 case NAVIGATOR_DRAGTYPE_EMBEDDED:
716 return BMP_EMBEDDED;
717 case NAVIGATOR_DRAGTYPE_LINK:
718 return BMP_LINK;
719 default: OSL_FAIL( "No resource for DragType available!" );
721 return EMPTY_OUSTRING;
724 NavDocInfo* SdNavigatorWin::GetDocInfo()
726 sal_uInt32 nPos = mxLbDocs->get_active();
728 if( mbDocImported )
730 if( nPos == 0 )
732 return nullptr;
734 nPos--;
737 return nPos < maDocList.size() ? &(maDocList[ nPos ]) : nullptr;
741 * catch ESCAPE in order to end show
743 IMPL_LINK(SdNavigatorWin, KeyInputHdl, const KeyEvent&, rKEvt, bool)
745 bool bConsumed = false;
747 if (KEY_ESCAPE == rKEvt.GetKeyCode().GetCode())
749 // during drag'n'drop we just stop the drag but do not close the navigator
750 if (!SdPageObjsTLV::IsInDrag() && !GetObjects().IsEditingActive())
752 ::sd::ViewShellBase* pBase = ::sd::ViewShellBase::GetViewShellBase( mpBindings->GetDispatcher()->GetFrame());
753 if (pBase)
754 sd::SlideShow::Stop(*pBase);
755 bConsumed = true;
759 return bConsumed;
762 void SdNavigatorWin::SetDragImage()
764 mxToolbox->set_item_icon_name(u"dragmode"_ustr, GetDragTypeSdBmpId(meDragType));
767 // for the sidebar to make the panel invisible when the shell type is outline or slide sorter
768 void SdNavigatorWin::HandleContextChange(const vcl::EnumContext& eContext)
770 if (eContext.GetApplication() != vcl::EnumContext::Application::Impress)
771 return;
773 ::sd::DrawDocShell* pCurrentDocShell
774 = dynamic_cast<::sd::DrawDocShell*>(SfxObjectShell::Current());
775 if (!pCurrentDocShell)
776 return;
778 const ::sd::DrawViewShell* pDrawViewShell
779 = static_cast<::sd::DrawViewShell*>(pCurrentDocShell->GetViewShell());
780 if (!pDrawViewShell)
781 return;
783 sd::ViewShell::ShellType eShellType = pDrawViewShell->GetShellType();
784 m_xContainer->set_visible(eShellType != sd::ViewShell::ST_OUTLINE
785 && eShellType != sd::ViewShell::ST_SLIDE_SORTER);
789 * ControllerItem for Navigator
791 SdNavigatorControllerItem::SdNavigatorControllerItem(
792 sal_uInt16 _nId,
793 SdNavigatorWin* pNavWin,
794 SfxBindings* _pBindings,
795 SdNavigatorWin::UpdateRequestFunctor aUpdateRequest)
796 : SfxControllerItem( _nId, *_pBindings ),
797 pNavigatorWin( pNavWin ),
798 maUpdateRequest(std::move(aUpdateRequest))
802 void SdNavigatorControllerItem::StateChangedAtToolBoxControl( sal_uInt16 nSId,
803 SfxItemState eState, const SfxPoolItem* pItem )
805 if( eState < SfxItemState::DEFAULT || nSId != SID_NAVIGATOR_STATE )
806 return;
808 // only if doc in LB is the active
809 NavDocInfo* pInfo = pNavigatorWin->GetDocInfo();
810 if( !(pInfo && pInfo->IsActive()) )
811 return;
813 const SfxUInt32Item& rStateItem = dynamic_cast<const SfxUInt32Item&>(*pItem);
814 NavState nState = static_cast<NavState>(rStateItem.GetValue());
816 // First
817 if (nState & NavState::BtnFirstEnabled &&
818 !pNavigatorWin->mxToolbox->get_item_sensitive(u"first"_ustr))
819 pNavigatorWin->mxToolbox->set_item_sensitive(u"first"_ustr, true);
820 if (nState & NavState::BtnFirstDisabled &&
821 pNavigatorWin->mxToolbox->get_item_sensitive(u"first"_ustr))
822 pNavigatorWin->mxToolbox->set_item_sensitive(u"first"_ustr, false);
824 // Prev
825 if (nState & NavState::BtnPrevEnabled &&
826 !pNavigatorWin->mxToolbox->get_item_sensitive(u"previous"_ustr))
827 pNavigatorWin->mxToolbox->set_item_sensitive(u"previous"_ustr, true);
828 if (nState & NavState::BtnPrevDisabled &&
829 pNavigatorWin->mxToolbox->get_item_sensitive(u"previous"_ustr))
830 pNavigatorWin->mxToolbox->set_item_sensitive(u"previous"_ustr, false);
832 // Last
833 if (nState & NavState::BtnLastEnabled &&
834 !pNavigatorWin->mxToolbox->get_item_sensitive(u"last"_ustr))
835 pNavigatorWin->mxToolbox->set_item_sensitive(u"last"_ustr, true);
836 if (nState & NavState::BtnLastDisabled &&
837 pNavigatorWin->mxToolbox->get_item_sensitive(u"last"_ustr))
838 pNavigatorWin->mxToolbox->set_item_sensitive(u"last"_ustr, false);
840 // Next
841 if (nState & NavState::BtnNextEnabled &&
842 !pNavigatorWin->mxToolbox->get_item_sensitive(u"next"_ustr))
843 pNavigatorWin->mxToolbox->set_item_sensitive(u"next"_ustr, true);
844 if (nState & NavState::BtnNextDisabled &&
845 pNavigatorWin->mxToolbox->get_item_sensitive(u"next"_ustr))
846 pNavigatorWin->mxToolbox->set_item_sensitive(u"next"_ustr, false);
848 if (nState & NavState::TableUpdate)
850 // InitTlb; is initiated by Slot
851 if (maUpdateRequest && !pNavigatorWin->GetObjects().get_treeview().has_focus())
852 maUpdateRequest();
857 * ControllerItem for Navigator to show page in TreeLB
859 SdPageNameControllerItem::SdPageNameControllerItem(
860 sal_uInt16 _nId,
861 SdNavigatorWin* pNavWin,
862 SfxBindings* _pBindings)
863 : SfxControllerItem( _nId, *_pBindings ),
864 pNavigatorWin( pNavWin )
868 void SdPageNameControllerItem::StateChangedAtToolBoxControl( sal_uInt16 nSId,
869 SfxItemState eState, const SfxPoolItem* pItem )
871 if( eState < SfxItemState::DEFAULT || nSId != SID_NAVIGATOR_PAGENAME )
872 return;
874 // only if doc in LB is the active
875 NavDocInfo* pInfo = pNavigatorWin->GetDocInfo();
876 if( !(pInfo && pInfo->IsActive()) )
877 return;
879 // Without a test for marked objects the page name entry is not selected when there are no
880 // marked objects. The HasSelectedChildren test is required when in 'Named Shapes' mode in
881 // order to select the page name when none of the marked objects have a name.
882 bool bDrawViewHasMarkedObjects = false;
883 if (pInfo->GetDrawDocShell() && pInfo->GetDrawDocShell()->GetViewShell())
885 const SdrView* pDrawView = pInfo->GetDrawDocShell()->GetViewShell()->GetDrawView();
886 if (pDrawView && pDrawView->GetMarkedObjectList().GetMarkCount())
887 bDrawViewHasMarkedObjects = true;
890 const SfxStringItem& rStateItem = dynamic_cast<const SfxStringItem&>(*pItem);
891 const OUString& aPageName = rStateItem.GetValue();
893 if (!bDrawViewHasMarkedObjects || !pNavigatorWin->mxTlbObjects->HasSelectedChildren(aPageName))
895 if (pNavigatorWin->mxTlbObjects->get_selection_mode() == SelectionMode::Multiple)
897 // because otherwise it is always additional select
898 pNavigatorWin->mxTlbObjects->unselect_all();
900 pNavigatorWin->mxTlbObjects->SelectEntry( aPageName );
904 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */