Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sd/source/ui/view/ViewShellBase.cxx
Line
Count
Source
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 <comphelper/processfactory.hxx>
21
22
#include <boost/property_tree/json_parser.hpp>
23
24
#include <ViewShellBase.hxx>
25
#include <algorithm>
26
#include <EventMultiplexer.hxx>
27
#include <cache/SlsPageCacheManager.hxx>
28
#include <app.hrc>
29
#include <slideshow.hxx>
30
#include <unokywds.hxx>
31
#include <svx/svxids.hrc>
32
#include <DrawDocShell.hxx>
33
#include <ViewShellManager.hxx>
34
#include <DrawController.hxx>
35
#include <FrameView.hxx>
36
#include <ViewTabBar.hxx>
37
#include <ResourceId.hxx>
38
#include <sfx2/event.hxx>
39
#include <drawdoc.hxx>
40
#include <sdpage.hxx>
41
#include <sfx2/dispatch.hxx>
42
#include <sfx2/request.hxx>
43
#include <sfx2/printer.hxx>
44
#include <DrawViewShell.hxx>
45
#include <OutlineViewShell.hxx>
46
#include <FormShellManager.hxx>
47
#include <ToolBarManager.hxx>
48
#include <Window.hxx>
49
#include <framework/ConfigurationController.hxx>
50
#include <framework/ConfigurationChangeEvent.hxx>
51
#include <DocumentRenderer.hxx>
52
#include <optsitem.hxx>
53
#include <sdmod.hxx>
54
55
#include <com/sun/star/document/XViewDataSupplier.hpp>
56
#include <com/sun/star/container/XIndexAccess.hpp>
57
#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
58
#include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
59
#include <com/sun/star/uno/DeploymentException.hpp>
60
#include <framework/FrameworkHelper.hxx>
61
62
#include <sal/log.hxx>
63
#include <rtl/ref.hxx>
64
#include <sfx2/msg.hxx>
65
#include <sfx2/objface.hxx>
66
#include <sfx2/viewfrm.hxx>
67
#include <svl/intitem.hxx>
68
#include <svl/whiter.hxx>
69
#include <svx/theme/ThemeColorChangerCommon.hxx>
70
#include <vcl/commandinfoprovider.hxx>
71
#include <vcl/settings.hxx>
72
#include <vcl/svapp.hxx>
73
74
#include <sfx2/notebookbar/SfxNotebookBar.hxx>
75
76
#include <comphelper/diagnose_ex.hxx>
77
#include <comphelper/lok.hxx>
78
#include <sfx2/lokhelper.hxx>
79
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
80
#include <editeng/editview.hxx>
81
#include <tools/svborder.hxx>
82
#include <o3tl/unreachable.hxx>
83
84
#include <fubullet.hxx>
85
#include <drawview.hxx>
86
87
using namespace sd;
88
#define ShellClass_ViewShellBase
89
#include <sdslots.hxx>
90
91
using ::sd::framework::FrameworkHelper;
92
93
using namespace com::sun::star;
94
using namespace com::sun::star::beans;
95
using namespace com::sun::star::container;
96
using namespace com::sun::star::drawing::framework;
97
using namespace com::sun::star::lang;
98
using namespace com::sun::star::uno;
99
100
namespace {
101
102
class CurrentPageSetter
103
{
104
public:
105
    explicit CurrentPageSetter (ViewShellBase& rBase);
106
    void operator () (bool);
107
private:
108
    ViewShellBase& mrBase;
109
};
110
111
} // end of anonymous namespace
112
113
namespace sd {
114
115
class ViewShellBase::Implementation
116
{
117
public:
118
    SdViewOptions maViewOptions;
119
120
    /** Main controller of the view shell.  During the switching from one
121
        stacked shell to another this pointer may be NULL.
122
    */
123
    ::rtl::Reference<DrawController> mpController;
124
125
    /** The view tab bar is the control for switching between different
126
        views in one pane.
127
    */
128
    ::rtl::Reference<ViewTabBar> mpViewTabBar;
129
130
    // contains the complete area of the current view relative to the frame window
131
    ::tools::Rectangle maClientArea;
132
133
    // This is set to true when PrepareClose() is called.
134
    bool mbIsClosing;
135
136
    /** The view window is the parent of all UI elements that belong to the
137
        view or ViewShell.  This comprises the rulers, the scroll bars, and
138
        the content window.
139
        It does not include the ViewTabBar.
140
    */
141
    VclPtr<vcl::Window> mpViewWindow;
142
    std::shared_ptr<ToolBarManager> mpToolBarManager;
143
    std::shared_ptr<ViewShellManager> mpViewShellManager;
144
    std::shared_ptr<sdtools::EventMultiplexer> mpEventMultiplexer;
145
    std::unique_ptr<FormShellManager> mpFormShellManager;
146
147
    explicit Implementation (ViewShellBase& rBase);
148
    ~Implementation();
149
150
    void LateInit();
151
152
    /** Show or hide the ViewTabBar.
153
        @param bShow
154
            When <TRUE/> then the ViewTabBar is shown, otherwise it is hidden.
155
    */
156
    void ShowViewTabBar (bool bShow);
157
158
    void SetUserWantsTabBar(bool inValue);
159
0
    bool GetUserWantsTabBar() const { return mbUserWantsTabBar; }
160
161
    /** Common code of ViewShellBase::OuterResizePixel() and
162
        ViewShellBase::InnerResizePixel().
163
    */
164
    void ResizePixel (
165
        const Point& rOrigin,
166
        const Size& rSize,
167
        bool bOuterResize);
168
169
    /** Show or hide the specified pane.  The visibility state is taken
170
        from the given request.
171
        @param rRequest
172
            The request determines the new visibility state.  The state can
173
            either be toggled or be set to a given value.
174
        @param rsPaneURL
175
            This URL specifies the pane whose visibility state to set.
176
        @param rsViewURL
177
            When the pane becomes visible then this view URL specifies which
178
            type of view to show in it.
179
    */
180
    void SetPaneVisibility (
181
        const SfxRequest& rRequest,
182
        const OUString& rsPaneURL,
183
        const OUString& rsViewURL);
184
185
    void GetSlotState (SfxItemSet& rSet);
186
187
    void ProcessRestoreEditingViewSlot();
188
189
private:
190
    ViewShellBase& mrBase;
191
    bool mbUserWantsTabBar;
192
    bool mbTabBarShouldBeVisible;
193
    /** Hold a reference to the page cache manager of the slide sorter in
194
        order to ensure that it stays alive while the ViewShellBase is
195
        alive.
196
    */
197
    std::shared_ptr<slidesorter::cache::PageCacheManager> mpPageCacheManager;
198
};
199
200
namespace {
201
/** The only task of this window is to forward key presses to the content
202
    window of the main view shell.  With the key press it forwards the focus
203
    so that it is not called very often.
204
*/
205
class FocusForwardingWindow : public vcl::Window
206
{
207
public:
208
    FocusForwardingWindow (vcl::Window& rParentWindow, ViewShellBase& rBase);
209
    virtual ~FocusForwardingWindow() override;
210
    virtual void dispose() override;
211
    virtual void KeyInput (const KeyEvent& rEvent) override;
212
    virtual void Command (const CommandEvent& rEvent) override;
213
214
private:
215
    ViewShellBase& mrBase;
216
};
217
} // end of anonymous namespace
218
219
//===== ViewShellBase =========================================================
220
221
222
// We have to expand the SFX_IMPL_VIEWFACTORY macro to call LateInit() after a
223
// new ViewShellBase object has been constructed.
224
225
SFX_IMPL_SUPERCLASS_INTERFACE(ViewShellBase, SfxViewShell)
226
227
void ViewShellBase::InitInterface_Impl()
228
6
{
229
6
}
230
231
ViewShellBase::ViewShellBase (
232
    SfxViewFrame& _rFrame,
233
    SfxViewShell*)
234
0
    : SfxViewShell(_rFrame, SfxViewShellFlags::HAS_PRINTOPTIONS),
235
0
      mpDocShell (nullptr),
236
0
      mpDocument (nullptr)
237
0
{
238
0
    mpImpl.reset(new Implementation(*this));
239
0
    mpImpl->mpViewWindow = VclPtr<FocusForwardingWindow>::Create(_rFrame.GetWindow(),*this);
240
0
    mpImpl->mpViewWindow->SetBackground(Wallpaper());
241
242
0
    _rFrame.GetWindow().SetBackground(Application::GetSettings().GetStyleSettings().GetLightColor());
243
244
    // Set up the members in the correct order.
245
0
    if (auto pDrawDocShell = dynamic_cast< DrawDocShell *>( GetViewFrame().GetObjectShell() ))
246
0
        mpDocShell = pDrawDocShell;
247
0
    if (mpDocShell != nullptr)
248
0
        mpDocument = mpDocShell->GetDoc();
249
0
    mpImpl->mpViewShellManager = std::make_shared<ViewShellManager>(*this);
250
251
0
    SetWindow(mpImpl->mpViewWindow.get());
252
253
    // Hide the window to avoid complaints from Sfx...SwitchViewShell...
254
0
    _rFrame.GetWindow().Hide();
255
0
}
256
257
/** In this destructor the order in which some of the members are destroyed
258
    (and/or being prepared to being destroyed) is important.  Change it only
259
    when you know what you are doing.
260
*/
261
ViewShellBase::~ViewShellBase()
262
0
{
263
    // Notify other LOK views that we are going away.
264
0
    SfxLokHelper::notifyOtherViews(this, LOK_CALLBACK_VIEW_CURSOR_VISIBLE, "visible", "false"_ostr);
265
0
    SfxLokHelper::notifyOtherViews(this, LOK_CALLBACK_TEXT_VIEW_SELECTION, "selection", ""_ostr);
266
0
    SfxLokHelper::notifyOtherViews(this, LOK_CALLBACK_GRAPHIC_VIEW_SELECTION, "selection", "EMPTY"_ostr);
267
268
0
    sfx2::SfxNotebookBar::CloseMethod(GetFrame()->GetBindings());
269
270
0
    rtl::Reference<SlideShow> xSlideShow(SlideShow::GetSlideShow(*this));
271
0
    if (xSlideShow.is() && xSlideShow->dependsOn(this))
272
0
        SlideShow::Stop(*this);
273
0
    xSlideShow.clear();
274
275
    // Tell the controller that the ViewShellBase is not available anymore.
276
0
    if (mpImpl->mpController)
277
0
        mpImpl->mpController->ReleaseViewShellBase();
278
279
    // We have to hide the main window to prevent SFX complaining after a
280
    // reload about it being already visible.
281
0
    ViewShell* pShell = GetMainViewShell().get();
282
0
    if (pShell!=nullptr
283
0
        && pShell->GetActiveWindow()!=nullptr
284
0
        && pShell->GetActiveWindow()->GetParent()!=nullptr)
285
0
    {
286
0
        pShell->GetActiveWindow()->GetParent()->Hide();
287
0
    }
288
289
0
    mpImpl->mpToolBarManager->Shutdown();
290
0
    mpImpl->mpViewShellManager->Shutdown();
291
292
0
    EndListening(GetViewFrame());
293
0
    EndListening(*GetDocShell());
294
295
0
    SetWindow(nullptr);
296
297
0
    mpImpl->mpFormShellManager.reset();
298
0
}
299
300
void ViewShellBase::LateInit (const OUString& rsDefaultView)
301
0
{
302
0
    StartListening(GetViewFrame(), DuplicateHandling::Prevent);
303
0
    StartListening(*GetDocShell(), DuplicateHandling::Prevent);
304
0
    mpImpl->LateInit();
305
0
    InitializeFramework();
306
307
0
    mpImpl->mpEventMultiplexer = std::make_shared<sdtools::EventMultiplexer>(*this);
308
309
0
    mpImpl->mpFormShellManager = std::make_unique<FormShellManager>(*this);
310
311
0
    mpImpl->mpToolBarManager = ToolBarManager::Create(
312
0
        *this,
313
0
        mpImpl->mpEventMultiplexer,
314
0
        mpImpl->mpViewShellManager);
315
316
0
    try
317
0
    {
318
0
        rtl::Reference<::sd::DrawController> xControllerManager (GetDrawController());
319
0
        rtl::Reference<::sd::framework::ConfigurationController> xConfigurationController;
320
0
        if (xControllerManager)
321
0
            xConfigurationController = xControllerManager->getConfigurationController();
322
0
        if (xConfigurationController.is())
323
0
        {
324
0
            OUString sView (rsDefaultView);
325
0
            if (sView.isEmpty())
326
0
                sView = GetInitialViewShellType();
327
328
0
            FrameworkHelper::Instance(*this);
329
330
            // Create the resource ids for the center pane and view.
331
0
            const rtl::Reference<framework::ResourceId> xCenterPaneId (
332
0
                new ::sd::framework::ResourceId(FrameworkHelper::msCenterPaneURL));
333
0
            const rtl::Reference<framework::ResourceId> xCenterViewId (
334
0
                new ::sd::framework::ResourceId(sView, xCenterPaneId));
335
336
            // Request center pane and view.
337
0
            xConfigurationController->requestResourceActivation(xCenterPaneId, framework::ResourceActivationMode::ADD);
338
0
            xConfigurationController->requestResourceActivation(xCenterViewId, framework::ResourceActivationMode::REPLACE);
339
340
            // Process configuration events synchronously until the center view
341
            // has been created.
342
0
            while ( !xConfigurationController->getResource(xCenterViewId).is()
343
0
                    && xConfigurationController->hasPendingRequests())
344
0
            {
345
0
                xConfigurationController->ProcessEvent();
346
0
            }
347
0
        }
348
0
    }
349
0
    catch (const RuntimeException&)
350
0
    {
351
0
    }
352
353
    // AutoLayouts have to be ready.
354
0
    GetDocument()->StopWorkStartupDelay();
355
356
0
    UpdateBorder();
357
358
    // Remember the type of the current main view shell in the frame view.
359
0
    ViewShell* pViewShell = GetMainViewShell().get();
360
0
    if (pViewShell != nullptr)
361
0
    {
362
0
        FrameView* pFrameView = pViewShell->GetFrameView();
363
0
        if (pFrameView != nullptr)
364
0
            pFrameView->SetViewShellTypeOnLoad(pViewShell->GetShellType());
365
0
    }
366
    // Show/Hide the TabBar
367
0
    SdOptions* pOptions = SdModule::get()->GetSdOptions(GetDocument()->GetDocumentType());
368
0
    bool bIsTabBarVisible = pOptions->IsTabBarVisible();
369
0
    mpImpl->SetUserWantsTabBar( bIsTabBarVisible );
370
0
}
371
372
std::shared_ptr<ViewShellManager> const & ViewShellBase::GetViewShellManager() const
373
0
{
374
0
    return mpImpl->mpViewShellManager;
375
0
}
376
377
std::shared_ptr<ViewShell> ViewShellBase::GetMainViewShell() const
378
0
{
379
0
    std::shared_ptr<ViewShell> pMainViewShell (
380
0
        framework::FrameworkHelper::Instance(*const_cast<ViewShellBase*>(this))
381
0
            ->GetViewShell(framework::FrameworkHelper::msCenterPaneURL));
382
0
    if (pMainViewShell == nullptr)
383
0
        pMainViewShell = framework::FrameworkHelper::Instance(*const_cast<ViewShellBase*>(this))
384
0
            ->GetViewShell(framework::FrameworkHelper::msFullScreenPaneURL);
385
0
    return pMainViewShell;
386
0
}
387
388
ViewShellBase* ViewShellBase::GetViewShellBase (SfxViewFrame const * pViewFrame)
389
0
{
390
0
    ViewShellBase* pBase = nullptr;
391
392
0
    if (pViewFrame != nullptr)
393
0
    {
394
        // Get the view shell for the frame and cast it to
395
        // sd::ViewShellBase.
396
0
        SfxViewShell* pSfxViewShell = pViewFrame->GetViewShell();
397
0
        pBase = dynamic_cast< ::sd::ViewShellBase *>( pSfxViewShell );
398
0
    }
399
400
0
    return pBase;
401
0
}
402
403
void ViewShellBase::Notify(SfxBroadcaster& rBC, const SfxHint& rHint)
404
0
{
405
0
    SfxViewShell::Notify(rBC, rHint);
406
407
0
    const SfxHintId nHintId = rHint.GetId();
408
409
0
    if (nHintId == SfxHintId::ThisIsAnSfxEventHint)
410
0
    {
411
0
        switch (static_cast<const SfxEventHint&>(rHint).GetEventId())
412
0
        {
413
0
            case SfxEventHintId::OpenDoc:
414
0
            {
415
0
                const sal_uInt16 nStartingSlide
416
0
                    = GetDocument() ? GetDocument()->GetStartWithPresentation() : 0;
417
0
                if (nStartingSlide)
418
0
                {
419
0
                    SfxUInt16Item aItem(FN_PARAM_1, nStartingSlide);
420
0
                    GetViewFrame().GetDispatcher()->ExecuteList(
421
0
                        SID_PRESENTATION, SfxCallMode::ASYNCHRON, { &aItem });
422
0
                }
423
0
                break;
424
0
            }
425
0
            default:
426
0
                break;
427
0
        }
428
0
    }
429
0
    else
430
0
    {
431
0
        switch (nHintId)
432
0
        {
433
0
            case SfxHintId::LanguageChanged:
434
0
            {
435
0
                GetViewFrame().GetBindings().Invalidate(SID_LANGUAGE_STATUS);
436
0
            }
437
0
            break;
438
439
0
            default:
440
0
                break;
441
0
        }
442
0
    }
443
0
}
444
445
void ViewShellBase::InitializeFramework()
446
0
{
447
0
}
448
449
OUString ViewShellBase::GetSelectionText(bool bCompleteWords, bool /*bOnlyASample*/)
450
0
{
451
0
    std::shared_ptr<ViewShell> const pMainShell(GetMainViewShell());
452
0
    DrawViewShell *const pDrawViewShell(
453
0
            dynamic_cast<DrawViewShell*>(pMainShell.get()));
454
0
    return pDrawViewShell
455
0
        ?   pDrawViewShell->GetSelectionText(bCompleteWords)
456
0
        :   SfxViewShell::GetSelectionText(bCompleteWords);
457
0
}
458
459
bool ViewShellBase::HasSelection(bool bText) const
460
0
{
461
0
    std::shared_ptr<ViewShell> const pMainShell(GetMainViewShell());
462
0
    DrawViewShell *const pDrawViewShell(
463
0
            dynamic_cast<DrawViewShell*>(pMainShell.get()));
464
0
    return pDrawViewShell
465
0
        ?   pDrawViewShell->HasSelection(bText)
466
0
        :   SfxViewShell::HasSelection(bText);
467
0
}
468
469
void ViewShellBase::InnerResizePixel (const Point& rOrigin, const Size &rSize, bool)
470
0
{
471
0
    Size aObjSize = GetObjectShell()->GetVisArea().GetSize();
472
0
    if ( !aObjSize.IsEmpty() )
473
0
    {
474
0
        SvBorder aBorder( GetBorderPixel() );
475
0
        Size aSize( rSize );
476
0
        aSize.AdjustWidth( -(aBorder.Left() + aBorder.Right()) );
477
0
        aSize.AdjustHeight( -(aBorder.Top() + aBorder.Bottom()) );
478
0
        Size aObjSizePixel = mpImpl->mpViewWindow->LogicToPixel(aObjSize, MapMode(MapUnit::Map100thMM));
479
0
        SfxViewShell::SetZoomFactor(
480
0
            Fraction( aSize.Width(), std::max( aObjSizePixel.Width(), static_cast<::tools::Long>(1) ) ),
481
0
            Fraction( aSize.Height(), std::max( aObjSizePixel.Height(), static_cast<::tools::Long>(1)) ) );
482
0
    }
483
484
0
    mpImpl->ResizePixel(rOrigin, rSize, false);
485
0
}
486
487
void ViewShellBase::OuterResizePixel (const Point& rOrigin, const Size &rSize)
488
0
{
489
0
    mpImpl->ResizePixel (rOrigin, rSize, true);
490
0
}
491
492
void ViewShellBase::Rearrange()
493
0
{
494
    // There is a bug in the communication between embedded objects and the
495
    // framework::LayoutManager that leads to missing resize updates.  The
496
    // following workaround enforces such an update by cycling the border to
497
    // zero and back to the current value.
498
0
    if (GetWindow() != nullptr)
499
0
    {
500
0
        SetBorderPixel(SvBorder());
501
0
        UpdateBorder(true);
502
0
    }
503
0
    else
504
0
    {
505
0
        SAL_WARN("sd.view", "Rearrange: window missing");
506
0
    }
507
508
0
    GetViewFrame().Resize(true);
509
0
}
510
511
ErrCode ViewShellBase::DoVerb(sal_Int32 nVerb)
512
0
{
513
0
    ErrCode aResult = ERRCODE_NONE;
514
515
0
    ::sd::ViewShell* pShell = GetMainViewShell().get();
516
0
    if (pShell != nullptr)
517
0
        aResult = pShell->DoVerb(nVerb);
518
519
0
    return aResult;
520
0
}
521
522
Reference<view::XRenderable> ViewShellBase::GetRenderable()
523
0
{
524
    // Create a new DocumentRenderer on every call.  It observes the life
525
    // time of this ViewShellBase object.
526
0
    return Reference<view::XRenderable>(new DocumentRenderer(*this));
527
0
}
528
529
SfxPrinter* ViewShellBase::GetPrinter (bool bCreate)
530
0
{
531
0
    OSL_ASSERT(mpImpl != nullptr);
532
533
0
    return GetDocShell()->GetPrinter (bCreate);
534
0
}
535
536
sal_uInt16 ViewShellBase::SetPrinter (
537
    SfxPrinter* pNewPrinter,
538
    SfxPrinterChangeFlags nDiffFlags)
539
0
{
540
0
    OSL_ASSERT(mpImpl != nullptr);
541
542
0
    GetDocShell()->SetPrinter(pNewPrinter);
543
544
0
    if ( (nDiffFlags & SfxPrinterChangeFlags::CHG_ORIENTATION ||
545
0
          nDiffFlags & SfxPrinterChangeFlags::CHG_SIZE) && pNewPrinter  )
546
0
    {
547
0
        MapMode aMap = pNewPrinter->GetMapMode();
548
0
        aMap.SetMapUnit(MapUnit::Map100thMM);
549
0
        MapMode aOldMap = pNewPrinter->GetMapMode();
550
0
        pNewPrinter->SetMapMode(aMap);
551
0
        Size aNewSize = pNewPrinter->GetOutputSize();
552
553
0
        std::shared_ptr<DrawViewShell> pDrawViewShell (
554
0
            std::dynamic_pointer_cast<DrawViewShell>(GetMainViewShell()));
555
0
        if (pDrawViewShell)
556
0
        {
557
0
            SdPage* pPage = GetDocument()->GetSdPage(
558
0
                0, PageKind::Standard );
559
0
            pDrawViewShell->SetPageSizeAndBorder (
560
0
                pDrawViewShell->GetPageKind(),
561
0
                aNewSize,
562
0
                -1,-1,-1,-1,
563
0
                false/*bScaleAll*/,
564
0
                pNewPrinter->GetOrientation(),
565
0
                pPage->GetPaperBin(),
566
0
                pPage->IsBackgroundFullSize());
567
0
        }
568
569
0
        pNewPrinter->SetMapMode(aOldMap);
570
0
    }
571
572
0
    return 0;
573
0
}
574
575
void ViewShellBase::UIActivating( SfxInPlaceClient* pClient )
576
0
{
577
0
    mpImpl->ShowViewTabBar(false);
578
579
0
    ViewShell* pViewShell = GetMainViewShell().get();
580
0
    if ( pViewShell )
581
0
        pViewShell->UIActivating( pClient );
582
583
0
    SfxViewShell::UIActivating( pClient );
584
0
}
585
586
void ViewShellBase::UIDeactivated( SfxInPlaceClient* pClient )
587
0
{
588
0
    SfxViewShell::UIDeactivated( pClient );
589
590
0
    mpImpl->ShowViewTabBar(true);
591
592
0
    ViewShell* pViewShell = GetMainViewShell().get();
593
0
    if ( pViewShell )
594
0
        pViewShell->UIDeactivated( pClient );
595
0
}
596
597
SvBorder ViewShellBase::GetBorder (bool )
598
0
{
599
0
    int nTop = 0;
600
0
    if (mpImpl->mpViewTabBar.is() && mpImpl->mpViewTabBar->GetTabControl()->IsVisible())
601
0
        nTop = mpImpl->mpViewTabBar->GetHeight();
602
0
    return SvBorder(0,nTop,0,0);
603
0
}
604
605
void ViewShellBase::Execute (SfxRequest& rRequest)
606
0
{
607
0
    sal_uInt16 nSlotId = rRequest.GetSlot();
608
609
0
    switch (nSlotId)
610
0
    {
611
0
        case SID_SWITCH_SHELL:
612
0
        {
613
0
            DrawController* pDrawController(GetDrawController());
614
0
            if (pDrawController)
615
0
            {
616
0
                rtl::Reference<framework::ConfigurationController> xConfigurationController (
617
0
                    pDrawController->getConfigurationController());
618
0
                if (xConfigurationController.is())
619
0
                    xConfigurationController->update();
620
0
            }
621
0
        }
622
0
        break;
623
624
0
        case SID_LEFT_PANE_DRAW:
625
0
            mpImpl->SetPaneVisibility(
626
0
                rRequest,
627
0
                framework::FrameworkHelper::msLeftDrawPaneURL,
628
0
                framework::FrameworkHelper::msSlideSorterURL);
629
0
            break;
630
631
0
        case SID_LEFT_PANE_IMPRESS:
632
0
            mpImpl->SetPaneVisibility(
633
0
                rRequest,
634
0
                framework::FrameworkHelper::msLeftImpressPaneURL,
635
0
                framework::FrameworkHelper::msSlideSorterURL);
636
0
            break;
637
638
0
        case SID_BOTTOM_PANE_IMPRESS:
639
0
            mpImpl->SetPaneVisibility(
640
0
                rRequest,
641
0
                framework::FrameworkHelper::msBottomImpressPaneURL,
642
0
                framework::FrameworkHelper::msNotesPanelViewURL);
643
0
            break;
644
645
0
        case SID_TOGGLE_TABBAR_VISIBILITY:
646
0
        {
647
0
            SdOptions* pOptions = SdModule::get()->GetSdOptions(GetDocument()->GetDocumentType());
648
0
            bool bIsTabBarVisible = pOptions->IsTabBarVisible();
649
0
            pOptions->SetTabBarVisible( !bIsTabBarVisible );
650
0
            mpImpl->SetUserWantsTabBar( !bIsTabBarVisible );
651
0
            rRequest.Done();
652
0
        }
653
0
        break;
654
655
        // draw
656
0
        case SID_DRAWINGMODE:
657
        // impress normal
658
0
        case SID_NORMAL_MULTI_PANE_GUI:
659
0
        case SID_NOTES_MODE:
660
0
        case SID_OUTLINE_MODE:
661
0
        case SID_SLIDE_SORTER_MULTI_PANE_GUI:
662
0
        case SID_SLIDE_SORTER_MODE:
663
        // impress master
664
0
        case SID_SLIDE_MASTER_MODE:
665
0
        case SID_NOTES_MASTER_MODE:
666
0
        case SID_HANDOUT_MASTER_MODE:
667
0
            framework::FrameworkHelper::Instance(*this)->HandleModeChangeSlot(nSlotId, rRequest);
668
0
            break;
669
670
0
        case SID_WIN_FULLSCREEN:
671
            // The full screen mode is not supported.  Ignore the request.
672
0
            break;
673
674
0
        case SID_RESTORE_EDITING_VIEW:
675
0
            mpImpl->ProcessRestoreEditingViewSlot();
676
0
            break;
677
678
0
        case SID_PROTECTPOS:
679
0
        case SID_PROTECTSIZE:
680
0
        {
681
0
            ::sd::DrawDocShell* pDocSh = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() );
682
0
            ::sd::ViewShell* pViewSh = pDocSh ? pDocSh->GetViewShell() : nullptr;
683
0
            ::sd::View* pView = pViewSh ? pViewSh->GetView() : nullptr;
684
0
            if (!pView)
685
0
                break;
686
687
0
            const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
688
0
            assert ( rMarkList.GetMarkCount() == 1 );
689
690
0
            SdrObject* pGraphicObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
691
0
            if (nSlotId == SID_PROTECTSIZE)
692
0
                pGraphicObj->SetResizeProtect(!pGraphicObj->IsResizeProtect());
693
0
            else
694
0
                pGraphicObj->SetMoveProtect(!pGraphicObj->IsMoveProtect());
695
696
0
        }
697
0
        break;
698
699
0
        default:
700
            // Ignore any other slot.
701
0
            rRequest.Ignore ();
702
0
            break;
703
0
    }
704
0
}
705
706
void ViewShellBase::GetState (SfxItemSet& rSet)
707
0
{
708
0
    mpImpl->GetSlotState(rSet);
709
710
0
    FuBullet::GetSlotState( rSet, nullptr, &GetViewFrame() );
711
0
}
712
713
void ViewShellBase::WriteUserDataSequence (
714
    css::uno::Sequence< css::beans::PropertyValue >& rSequence)
715
0
{
716
    // Forward call to main sub shell.
717
0
    ViewShell* pShell = GetMainViewShell().get();
718
0
    if (pShell != nullptr)
719
0
        pShell->WriteUserDataSequence (rSequence);
720
0
}
721
722
void ViewShellBase::ReadUserDataSequence (
723
    const css::uno::Sequence< css::beans::PropertyValue >& rSequence)
724
0
{
725
    // Forward call to main sub shell.
726
0
    ViewShell* pShell = GetMainViewShell().get();
727
0
    if (pShell == nullptr)
728
0
        return;
729
730
0
    pShell->ReadUserDataSequence (rSequence);
731
732
    // For certain shell types ReadUserDataSequence may have changed the
733
    // type to another one.  Make sure that the center pane shows the
734
    // right view shell.
735
0
    switch (pShell->GetShellType())
736
0
    {
737
0
        case ViewShell::ST_IMPRESS:
738
0
        case ViewShell::ST_NOTES:
739
0
        case ViewShell::ST_HANDOUT:
740
0
        {
741
0
            OUString sViewURL;
742
0
            switch (dynamic_cast<DrawViewShell&>(*pShell).GetPageKind())
743
0
            {
744
0
                default:
745
0
                case PageKind::Standard:
746
0
                    sViewURL = framework::FrameworkHelper::msImpressViewURL;
747
0
                    break;
748
0
                case PageKind::Notes:
749
0
                    sViewURL = framework::FrameworkHelper::msNotesViewURL;
750
0
                    break;
751
0
                case PageKind::Handout:
752
0
                    sViewURL = framework::FrameworkHelper::msHandoutViewURL;
753
0
                    break;
754
0
            }
755
0
            if (!sViewURL.isEmpty())
756
0
                framework::FrameworkHelper::Instance(*this)->RequestView(
757
0
                    sViewURL,
758
0
                    framework::FrameworkHelper::msCenterPaneURL);
759
0
        }
760
0
        break;
761
762
0
        default:
763
0
            break;
764
0
    }
765
0
}
766
767
void ViewShellBase::Activate (bool bIsMDIActivate)
768
0
{
769
0
    SfxViewShell::Activate(bIsMDIActivate);
770
771
0
    DrawController* pDrawController(GetDrawController());
772
0
    if (pDrawController)
773
0
    {
774
0
        rtl::Reference<framework::ConfigurationController> xConfigurationController (
775
0
            pDrawController->getConfigurationController());
776
0
        if (xConfigurationController.is())
777
0
            xConfigurationController->update();
778
0
    }
779
0
    GetToolBarManager()->RequestUpdate();
780
0
}
781
782
void ViewShellBase::SetZoomFactor (
783
    const Fraction &rZoomX,
784
    const Fraction &rZoomY)
785
0
{
786
0
    SfxViewShell::SetZoomFactor (rZoomX, rZoomY);
787
    // Forward call to main sub shell.
788
0
    ViewShell* pShell = GetMainViewShell().get();
789
0
    if (pShell != nullptr)
790
0
        pShell->SetZoomFactor (rZoomX, rZoomY);
791
0
}
792
793
bool ViewShellBase::PrepareClose (bool bUI)
794
0
{
795
0
    bool bResult = SfxViewShell::PrepareClose (bUI);
796
797
0
    if (bResult)
798
0
    {
799
0
        mpImpl->mbIsClosing = true;
800
801
        // Forward call to main sub shell.
802
0
        ViewShell* pShell = GetMainViewShell().get();
803
0
        if (pShell != nullptr)
804
0
            bResult = pShell->PrepareClose (bUI);
805
0
    }
806
807
0
    return bResult;
808
0
}
809
810
void ViewShellBase::WriteUserData (OUString& rString, bool bBrowse)
811
0
{
812
0
    SfxViewShell::WriteUserData (rString, bBrowse);
813
814
    // Forward call to main sub shell.
815
0
    ViewShell* pShell = GetMainViewShell().get();
816
0
    if (pShell != nullptr)
817
0
        pShell->WriteUserData();
818
0
}
819
820
void ViewShellBase::ReadUserData (const OUString& rString, bool bBrowse)
821
0
{
822
0
    SfxViewShell::ReadUserData (rString, bBrowse);
823
824
    // Forward call to main sub shell.
825
0
    ViewShell* pShell = GetMainViewShell().get();
826
0
    if (pShell != nullptr)
827
0
        pShell->ReadUserData();
828
0
}
829
830
SdrView* ViewShellBase::GetDrawView() const
831
0
{
832
    // Forward call to main sub shell.
833
0
    ViewShell* pShell = GetMainViewShell().get();
834
0
    if (pShell != nullptr)
835
0
        return pShell->GetDrawView ();
836
837
0
    return nullptr;
838
0
}
839
840
void ViewShellBase::SetBusyState (bool bBusy)
841
0
{
842
0
    if (GetDocShell() != nullptr)
843
0
        GetDocShell()->SetWaitCursor (bBusy);
844
0
}
845
846
void ViewShellBase::UpdateBorder ( bool bForce /* = false */ )
847
0
{
848
    // The following calls to SetBorderPixel() and InvalidateBorder() are
849
    // made only for the main view shell.  This not only avoids unnecessary
850
    // calls for the views in side panes but prevents calling an already
851
    // dying SfxViewShell base class.
852
    // We have to check the existence of the window, too.
853
    // The SfxViewFrame accesses the window without checking it.
854
0
    ViewShell* pMainViewShell = GetMainViewShell().get();
855
0
    if (pMainViewShell == nullptr || GetWindow()==nullptr)
856
0
        return;
857
858
0
    SvBorder aCurrentBorder (GetBorderPixel());
859
0
    bool bOuterResize ( ! GetDocShell()->IsInPlaceActive());
860
0
    SvBorder aBorder (GetBorder(bOuterResize));
861
0
    aBorder += pMainViewShell->GetBorder();
862
863
0
    if (bForce || (aBorder != aCurrentBorder))
864
0
    {
865
0
        SetBorderPixel (aBorder);
866
0
        InvalidateBorder();
867
0
    }
868
0
}
869
870
void ViewShellBase::ShowUIControls (bool bVisible)
871
0
{
872
0
    mpImpl->ShowViewTabBar(bVisible);
873
874
0
    ViewShell* pMainViewShell = GetMainViewShell().get();
875
0
    if (pMainViewShell != nullptr)
876
0
        pMainViewShell->ShowUIControls (bVisible);
877
878
0
    UpdateBorder();
879
0
    if (bVisible)
880
0
        Rearrange();
881
0
}
882
883
OUString ViewShellBase::GetInitialViewShellType() const
884
0
{
885
0
    OUString sRequestedView (FrameworkHelper::msImpressViewURL);
886
887
0
    do
888
0
    {
889
0
        Reference<document::XViewDataSupplier> xViewDataSupplier (
890
0
            GetDocShell()->GetModel(), UNO_QUERY);
891
0
        if ( ! xViewDataSupplier.is())
892
0
            break;
893
894
0
        Reference<container::XIndexAccess> xViewData (xViewDataSupplier->getViewData());
895
0
        if ( ! xViewData.is())
896
0
            break;
897
0
        if (xViewData->getCount() == 0)
898
0
            break;
899
900
0
        css::uno::Any aAny = xViewData->getByIndex(0);
901
0
        Sequence<beans::PropertyValue> aProperties;
902
0
        if ( ! (aAny >>= aProperties))
903
0
            break;
904
905
        // Search the properties for the one that tells us what page kind to
906
        // use.
907
0
        auto pProperty = std::find_if(std::cbegin(aProperties), std::cend(aProperties),
908
0
            [](const beans::PropertyValue& rProperty) { return rProperty.Name == sUNO_View_PageKind; });
909
0
        if (pProperty != std::cend(aProperties))
910
0
        {
911
0
            sal_Int16 nPageKind = 0;
912
0
            pProperty->Value >>= nPageKind;
913
0
            switch (static_cast<PageKind>(nPageKind))
914
0
            {
915
0
                case PageKind::Standard:
916
0
                    sRequestedView = FrameworkHelper::msImpressViewURL;
917
0
                    break;
918
919
0
                case PageKind::Handout:
920
0
                    sRequestedView = FrameworkHelper::msHandoutViewURL;
921
0
                    break;
922
923
0
                case PageKind::Notes:
924
0
                    sRequestedView = FrameworkHelper::msNotesViewURL;
925
0
                    break;
926
927
0
                default:
928
                    // The page kind is invalid.  This is probably an
929
                    // error by the caller.  We use the standard type to
930
                    // keep things going.
931
0
                    SAL_WARN( "sd.view", "ViewShellBase::GetInitialViewShellType: invalid page kind");
932
0
                    sRequestedView = FrameworkHelper::msImpressViewURL;
933
0
                    break;
934
0
            }
935
0
        }
936
0
    }
937
0
    while (false);
938
939
0
    return sRequestedView;
940
0
}
941
942
const SdViewOptions& ViewShellBase::GetViewOptions() const
943
0
{
944
0
    return mpImpl->maViewOptions;
945
0
}
946
947
void ViewShellBase::SetViewOptions(const SdViewOptions& rOptions) const
948
0
{
949
0
    mpImpl->maViewOptions = rOptions;
950
0
}
951
952
std::shared_ptr<sdtools::EventMultiplexer> const & ViewShellBase::GetEventMultiplexer() const
953
0
{
954
0
    OSL_ASSERT(mpImpl != nullptr);
955
0
    OSL_ASSERT(mpImpl->mpEventMultiplexer != nullptr);
956
957
0
    return mpImpl->mpEventMultiplexer;
958
0
}
959
960
const ::tools::Rectangle& ViewShellBase::getClientRectangle() const
961
0
{
962
0
    return mpImpl->maClientArea;
963
0
}
964
965
std::shared_ptr<ToolBarManager> const & ViewShellBase::GetToolBarManager() const
966
0
{
967
0
    OSL_ASSERT(mpImpl != nullptr);
968
0
    OSL_ASSERT(mpImpl->mpToolBarManager != nullptr);
969
970
0
    return mpImpl->mpToolBarManager;
971
0
}
972
973
FormShellManager* ViewShellBase::GetFormShellManager() const
974
0
{
975
0
    OSL_ASSERT(mpImpl != nullptr);
976
0
    OSL_ASSERT(mpImpl->mpFormShellManager != nullptr);
977
978
0
    return mpImpl->mpFormShellManager.get();
979
0
}
980
981
DrawController* ViewShellBase::GetDrawController() const
982
0
{
983
0
    OSL_ASSERT(mpImpl != nullptr);
984
985
0
    return mpImpl->mpController.get();
986
0
}
987
988
void ViewShellBase::SetViewTabBar (const ::rtl::Reference<ViewTabBar>& rViewTabBar)
989
0
{
990
0
    OSL_ASSERT(mpImpl != nullptr);
991
992
0
    mpImpl->mpViewTabBar = rViewTabBar;
993
0
}
994
995
vcl::Window* ViewShellBase::GetViewWindow()
996
0
{
997
0
    OSL_ASSERT(mpImpl != nullptr);
998
999
0
    return mpImpl->mpViewWindow.get();
1000
0
}
1001
1002
OUString ViewShellBase::RetrieveLabelFromCommand( const OUString& aCmdURL ) const
1003
0
{
1004
0
    OUString aModuleName;
1005
0
    if (SfxViewFrame* pViewFrame = GetMainViewShell()->GetViewFrame())
1006
0
        aModuleName = vcl::CommandInfoProvider::GetModuleIdentifier(pViewFrame->GetFrame().GetFrameInterface());
1007
0
    auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(aCmdURL, aModuleName);
1008
0
    return vcl::CommandInfoProvider::GetLabelForCommand(aProperties);
1009
0
}
1010
1011
int ViewShellBase::getPart() const
1012
0
{
1013
0
    ViewShell* pViewShell = framework::FrameworkHelper::Instance(*const_cast<ViewShellBase*>(this))->GetViewShell(FrameworkHelper::msCenterPaneURL).get();
1014
1015
0
    if (DrawViewShell* pDrawViewShell = dynamic_cast<DrawViewShell*>(pViewShell))
1016
0
    {
1017
0
        return pDrawViewShell->GetCurPagePos();
1018
0
    }
1019
1020
0
    return 0;
1021
0
}
1022
1023
int ViewShellBase::getEditMode() const
1024
0
{
1025
0
    ViewShell* pViewShell = framework::FrameworkHelper::Instance(*const_cast<ViewShellBase*>(this))->GetViewShell(FrameworkHelper::msCenterPaneURL).get();
1026
1027
0
    if (DrawViewShell* pDrawViewShell = dynamic_cast<DrawViewShell*>(pViewShell))
1028
0
    {
1029
0
        switch ( pDrawViewShell->GetEditMode() )
1030
0
        {
1031
0
        case EditMode::Page:
1032
0
            switch (pDrawViewShell->GetPageKind())
1033
0
            {
1034
0
                case PageKind::Standard:
1035
0
                    return 0;
1036
0
                case PageKind::Notes:
1037
0
                    return 2;
1038
0
                default:
1039
0
                    assert(!"Unhandled page kind");
1040
0
                    return 0;
1041
0
            }
1042
0
        case EditMode::MasterPage:
1043
0
            switch (pDrawViewShell->GetPageKind())
1044
0
            {
1045
0
                case PageKind::Standard:
1046
0
                    return 1;
1047
0
                default:
1048
0
                    assert(!"Unhandled page kind");
1049
0
                    return 1;
1050
0
            }
1051
0
        }
1052
0
    }
1053
1054
0
    return 0;
1055
0
}
1056
1057
void ViewShellBase::setEditMode(int nMode)
1058
0
{
1059
0
    ViewShell* pViewShell = framework::FrameworkHelper::Instance(*this)->GetViewShell(FrameworkHelper::msCenterPaneURL).get();
1060
1061
0
    if (DrawViewShell* pDrawViewShell = dynamic_cast<DrawViewShell*>(pViewShell))
1062
0
    {
1063
0
        EditMode eOrigEditMode = pDrawViewShell->GetEditMode();
1064
0
        PageKind eOrigPageKind = pDrawViewShell->GetPageKind();
1065
0
        sal_uInt16 nSelectedPage = pDrawViewShell->GetCurPagePos();
1066
1067
0
        switch ( nMode )
1068
0
        {
1069
0
        case 0:
1070
0
            pDrawViewShell->SetPageKind(PageKind::Standard);
1071
0
            pDrawViewShell->ChangeEditMode(EditMode::Page, false);
1072
0
            break;
1073
0
        case 1:
1074
0
            pDrawViewShell->SetPageKind(PageKind::Standard);
1075
0
            pDrawViewShell->ChangeEditMode(EditMode::MasterPage, false);
1076
0
            break;
1077
0
        case 2:
1078
0
            pDrawViewShell->SetPageKind(PageKind::Notes);
1079
0
            pDrawViewShell->ChangeEditMode(EditMode::Page, false);
1080
0
            break;
1081
0
        }
1082
1083
        /*
1084
           If the EditMode is unchanged, then ChangeEditMode was typically a
1085
           no-op, and an additional explicit SwitchPage is required to reselect
1086
           the equivalent page from the other mode, otherwise a switch from
1087
           e.g. Notes to Standard will still render the still selected Note
1088
           page.
1089
        */
1090
0
        if (eOrigEditMode == pDrawViewShell->GetEditMode() &&
1091
0
            eOrigPageKind != pDrawViewShell->GetPageKind())
1092
0
        {
1093
0
            pDrawViewShell->SwitchPage(nSelectedPage);
1094
0
        }
1095
0
    }
1096
0
}
1097
1098
void ViewShellBase::afterCallbackRegistered()
1099
0
{
1100
    // common tasks
1101
0
    SfxViewShell::afterCallbackRegistered();
1102
1103
0
    SfxObjectShell* pDocShell = GetObjectShell();
1104
0
    if (pDocShell)
1105
0
    {
1106
0
        std::shared_ptr<model::ColorSet> pThemeColors = pDocShell->GetThemeColors();
1107
0
        std::set<Color> aDocumentColors = pDocShell->GetDocColors();
1108
0
        svx::theme::notifyLOK(pThemeColors, aDocumentColors);
1109
0
    }
1110
1111
0
    if (comphelper::LibreOfficeKit::isActive() && mpDocument && mpDocument->GetStartWithPresentation())
1112
0
    {
1113
        // Be consistent with SidebarController, emit JSON.
1114
0
        boost::property_tree::ptree aTree;
1115
0
        aTree.put("commandName", ".uno:StartWithPresentation");
1116
0
        aTree.put("state", "true");
1117
0
        std::stringstream aStream;
1118
0
        boost::property_tree::write_json(aStream, aTree);
1119
0
        libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED, OString(aStream.str()));
1120
0
    }
1121
0
}
1122
1123
void ViewShellBase::NotifyCursor(SfxViewShell* pOtherShell) const
1124
0
{
1125
0
    ViewShell* pThisShell = framework::FrameworkHelper::Instance(*const_cast<ViewShellBase*>(this))->GetViewShell(FrameworkHelper::msCenterPaneURL).get();
1126
1127
0
    DrawViewShell* pDrawViewShell = dynamic_cast<DrawViewShell*>(pThisShell);
1128
0
    if (!pDrawViewShell)
1129
0
        return;
1130
1131
0
    if (this == pOtherShell)
1132
0
        return;
1133
1134
0
    DrawView* pDrawView = pDrawViewShell->GetDrawView();
1135
0
    if (!pDrawView)
1136
0
        return;
1137
1138
0
    if (pDrawView->GetTextEditObject())
1139
0
    {
1140
        // Blinking cursor.
1141
0
        EditView& rEditView = pDrawView->GetTextEditOutlinerView()->GetEditView();
1142
0
        rEditView.RegisterOtherShell(pOtherShell);
1143
0
        rEditView.ShowCursor();
1144
0
        rEditView.RegisterOtherShell(nullptr);
1145
        // Text selection, if any.
1146
0
        rEditView.DrawSelectionXOR(pOtherShell);
1147
1148
        // Shape text lock.
1149
0
        if (OutlinerView* pOutlinerView = pDrawView->GetTextEditOutlinerView())
1150
0
        {
1151
0
            ::tools::Rectangle aRectangle = pOutlinerView->GetOutputArea();
1152
0
            vcl::Window* pWin = pThisShell->GetActiveWindow();
1153
0
            if (pWin && pWin->GetMapMode().GetMapUnit() == MapUnit::Map100thMM)
1154
0
                aRectangle = o3tl::toTwips(aRectangle, o3tl::Length::mm100);
1155
0
            OString sRectangle = aRectangle.toString();
1156
0
            SfxLokHelper::notifyOtherView(pDrawViewShell->GetViewShellBase(), pOtherShell, LOK_CALLBACK_VIEW_LOCK, "rectangle", sRectangle);
1157
0
        }
1158
0
    }
1159
0
    else
1160
0
    {
1161
        // Graphic selection.
1162
0
        pDrawView->AdjustMarkHdl(pOtherShell);
1163
0
    }
1164
0
}
1165
1166
::Color ViewShellBase::GetColorConfigColor(svtools::ColorConfigEntry nColorType) const
1167
0
{
1168
0
    Color aColor;
1169
1170
0
    const SdViewOptions& rViewOptions = GetViewOptions();
1171
0
    switch (nColorType)
1172
0
    {
1173
0
        case svtools::ColorConfigEntry::DOCCOLOR:
1174
0
        {
1175
0
            aColor = rViewOptions.mnDocBackgroundColor;
1176
0
            break;
1177
0
        }
1178
        // Should never be called for an unimplemented color type
1179
0
        default:
1180
0
        {
1181
0
            O3TL_UNREACHABLE;
1182
0
        }
1183
0
    }
1184
1185
0
    return aColor;
1186
0
}
1187
1188
//===== ViewShellBase::Implementation =========================================
1189
1190
ViewShellBase::Implementation::Implementation (ViewShellBase& rBase)
1191
0
    : mbIsClosing(false),
1192
0
      mrBase(rBase),
1193
0
      mbUserWantsTabBar(false),
1194
0
      mbTabBarShouldBeVisible(true),
1195
0
      mpPageCacheManager(slidesorter::cache::PageCacheManager::Instance())
1196
0
{
1197
0
}
1198
1199
ViewShellBase::Implementation::~Implementation()
1200
0
{
1201
0
    mpController = nullptr;
1202
0
    mpViewTabBar = nullptr;
1203
0
    mpViewWindow.disposeAndClear();
1204
0
    mpToolBarManager.reset();
1205
0
}
1206
1207
void ViewShellBase::Implementation::LateInit()
1208
0
{
1209
0
    mpController = new DrawController(mrBase);
1210
0
}
1211
1212
void ViewShellBase::Implementation::ProcessRestoreEditingViewSlot()
1213
0
{
1214
0
    ViewShell* pViewShell = mrBase.GetMainViewShell().get();
1215
0
    if (pViewShell == nullptr)
1216
0
        return;
1217
1218
0
    FrameView* pFrameView = pViewShell->GetFrameView();
1219
0
    if (pFrameView == nullptr)
1220
0
        return;
1221
1222
    // Set view shell, edit mode, and page kind.
1223
    // pFrameView->SetViewShEditMode(
1224
    //     pFrameView->GetViewShEditModeOnLoad(),
1225
    //     pFrameView->GetPageKindOnLoad());
1226
0
    pFrameView->SetViewShEditMode(
1227
0
        pFrameView->GetViewShEditModeOnLoad() );
1228
0
    pFrameView->SetPageKind(
1229
0
        pFrameView->GetPageKindOnLoad());
1230
0
    std::shared_ptr<FrameworkHelper> pHelper (FrameworkHelper::Instance(mrBase));
1231
0
    pHelper->RequestView(
1232
0
        FrameworkHelper::GetViewURL(pFrameView->GetViewShellTypeOnLoad()),
1233
0
        FrameworkHelper::msCenterPaneURL);
1234
0
    pHelper->RunOnConfigurationEvent(framework::ConfigurationChangeEventType::ConfigurationUpdateEnd, CurrentPageSetter(mrBase));
1235
0
}
1236
1237
void ViewShellBase::Implementation::SetUserWantsTabBar(bool inValue)
1238
0
{
1239
0
    mbUserWantsTabBar = inValue;
1240
    // Call ShowViewTabBar to refresh the TabBar visibility
1241
0
    ShowViewTabBar(mbTabBarShouldBeVisible);
1242
0
}
1243
1244
void ViewShellBase::Implementation::ShowViewTabBar (bool bShow)
1245
0
{
1246
0
    mbTabBarShouldBeVisible = bShow;
1247
0
    bShow = bShow && mbUserWantsTabBar;
1248
1249
0
    if (mpViewTabBar.is()
1250
0
        && mpViewTabBar->GetTabControl()->IsVisible() != bShow)
1251
0
    {
1252
0
        mpViewTabBar->GetTabControl()->Show(bShow);
1253
0
        mrBase.Rearrange();
1254
0
    }
1255
0
}
1256
1257
void ViewShellBase::Implementation::ResizePixel (
1258
    const Point& rOrigin,
1259
    const Size &rSize,
1260
    bool bOuterResize)
1261
0
{
1262
0
    if (mbIsClosing)
1263
0
        return;
1264
1265
    // Forward the call to both the base class and the main stacked sub
1266
    // shell only when main sub shell exists.
1267
0
    ViewShell* pMainViewShell = mrBase.GetMainViewShell().get();
1268
1269
    // Set the ViewTabBar temporarily to full size so that, when asked
1270
    // later, it can return its true height.
1271
0
    mrBase.SetWindow (mpViewWindow.get());
1272
0
    if (mpViewTabBar.is() && mpViewTabBar->GetTabControl()->IsVisible())
1273
0
        mpViewTabBar->GetTabControl()->SetPosSizePixel (rOrigin, rSize);
1274
1275
    // Calculate and set the border before the controls are placed.
1276
0
    SvBorder aBorder;
1277
0
    if (pMainViewShell != nullptr)
1278
0
        aBorder = pMainViewShell->GetBorder();
1279
0
    aBorder += mrBase.GetBorder(bOuterResize);
1280
0
    if (mrBase.GetBorderPixel() != aBorder)
1281
0
        mrBase.SetBorderPixel(aBorder);
1282
1283
    // Place the ViewTabBar at the top.  It is part of the border.
1284
0
    SvBorder aBaseBorder;
1285
0
    if (mpViewTabBar.is() && mpViewTabBar->GetTabControl()->IsVisible())
1286
0
    {
1287
0
        aBaseBorder.Top() = mpViewTabBar->GetHeight();
1288
0
        mpViewTabBar->GetTabControl()->SetPosSizePixel(
1289
0
            rOrigin, Size(rSize.Width(),aBaseBorder.Top()));
1290
0
    }
1291
1292
    // The view window gets the remaining space.
1293
0
    Point aViewWindowPosition (
1294
0
        rOrigin.X()+aBaseBorder.Left(),
1295
0
        rOrigin.Y()+aBaseBorder.Top());
1296
1297
0
    Size aViewWindowSize (
1298
0
        rSize.Width() - aBaseBorder.Left() - aBaseBorder.Right(),
1299
0
        rSize.Height() - aBaseBorder.Top() - aBaseBorder.Bottom());
1300
0
    mpViewWindow->SetPosSizePixel(aViewWindowPosition, aViewWindowSize);
1301
1302
0
    maClientArea = ::tools::Rectangle(Point(0,0), aViewWindowSize);
1303
0
}
1304
1305
void ViewShellBase::Implementation::SetPaneVisibility (
1306
    const SfxRequest& rRequest,
1307
    const OUString& rsPaneURL,
1308
    const OUString& rsViewURL)
1309
0
{
1310
0
    try
1311
0
    {
1312
0
        DrawController* pDrawController(mrBase.GetDrawController());
1313
0
        if (!pDrawController)
1314
0
            return;
1315
1316
0
        rtl::Reference<framework::ResourceId> xPaneId (new sd::framework::ResourceId(
1317
0
            rsPaneURL));
1318
0
        rtl::Reference<framework::ResourceId> xViewId (new sd::framework::ResourceId(
1319
0
            rsViewURL, rsPaneURL));
1320
1321
        // Determine the new visibility state.
1322
0
        const SfxItemSet* pArguments = rRequest.GetArgs();
1323
0
        bool bShowChildWindow;
1324
0
        sal_uInt16 nSlotId = rRequest.GetSlot();
1325
0
        if (pArguments != nullptr)
1326
0
            bShowChildWindow = static_cast<const SfxBoolItem&>(
1327
0
                pArguments->Get(nSlotId)).GetValue();
1328
0
        else
1329
0
        {
1330
0
            rtl::Reference<sd::framework::ConfigurationController> xConfigurationController (
1331
0
                pDrawController->getConfigurationController());
1332
0
            if ( ! xConfigurationController.is())
1333
0
                throw RuntimeException();
1334
0
            rtl::Reference<framework::Configuration> xConfiguration (
1335
0
                xConfigurationController->getRequestedConfiguration());
1336
0
            if ( ! xConfiguration.is())
1337
0
                throw RuntimeException();
1338
1339
0
            bShowChildWindow = ! xConfiguration->hasResource(xPaneId);
1340
0
        }
1341
1342
        // Set the desired visibility state at the current configuration
1343
        // and update it accordingly.
1344
0
        rtl::Reference<sd::framework::ConfigurationController> xConfigurationController (
1345
0
            pDrawController->getConfigurationController());
1346
0
        if ( ! xConfigurationController.is())
1347
0
            throw RuntimeException();
1348
0
        if (bShowChildWindow)
1349
0
        {
1350
0
            xConfigurationController->requestResourceActivation(
1351
0
                xPaneId,
1352
0
                framework::ResourceActivationMode::ADD);
1353
0
            xConfigurationController->requestResourceActivation(
1354
0
                xViewId,
1355
0
                framework::ResourceActivationMode::REPLACE);
1356
0
        }
1357
0
        else
1358
0
            xConfigurationController->requestResourceDeactivation(
1359
0
                xPaneId);
1360
0
    }
1361
0
    catch (const Exception&)
1362
0
    {
1363
0
        DBG_UNHANDLED_EXCEPTION("sd.view");
1364
0
    }
1365
0
}
1366
1367
void ViewShellBase::Implementation::GetSlotState (SfxItemSet& rSet)
1368
0
{
1369
0
    try
1370
0
    {
1371
        // Get some frequently used values.
1372
0
        DrawController* pDrawController(mrBase.GetDrawController());
1373
0
        if (!pDrawController)
1374
0
            return;
1375
0
        rtl::Reference<sd::framework::ConfigurationController> xConfigurationController (
1376
0
            pDrawController->getConfigurationController());
1377
0
        if ( ! xConfigurationController.is())
1378
0
            throw RuntimeException();
1379
0
        rtl::Reference<sd::framework::Configuration> xConfiguration (
1380
0
            xConfigurationController->getRequestedConfiguration());
1381
0
        if ( ! xConfiguration.is())
1382
0
            throw RuntimeException();
1383
1384
0
        SfxWhichIter aSetIterator (rSet);
1385
0
        sal_uInt16 nItemId (aSetIterator.FirstWhich());
1386
1387
0
        while (nItemId > 0)
1388
0
        {
1389
0
            bool bState (false);
1390
0
            bool bEnabled;
1391
0
            rtl::Reference<framework::ResourceId> xResourceId;
1392
0
            try
1393
0
            {
1394
0
                bEnabled = true;
1395
                // Check if the right view is active
1396
0
                switch (nItemId)
1397
0
                {
1398
0
                    case SID_LEFT_PANE_IMPRESS:
1399
0
                        xResourceId = new sd::framework::ResourceId(
1400
0
                            FrameworkHelper::msLeftImpressPaneURL);
1401
0
                        bState = xConfiguration->hasResource(xResourceId);
1402
0
                        break;
1403
1404
0
                    case SID_LEFT_PANE_DRAW:
1405
0
                        xResourceId = new sd::framework::ResourceId(
1406
0
                            FrameworkHelper::msLeftDrawPaneURL);
1407
0
                        bState = xConfiguration->hasResource(xResourceId);
1408
0
                        break;
1409
1410
0
                    case SID_BOTTOM_PANE_IMPRESS:
1411
0
                        xResourceId = new sd::framework::ResourceId(
1412
0
                            FrameworkHelper::msBottomImpressPaneURL);
1413
0
                        bState = xConfiguration->hasResource(xResourceId);
1414
0
                        break;
1415
1416
0
                    case SID_DRAWINGMODE:
1417
0
                    case SID_NORMAL_MULTI_PANE_GUI:
1418
0
                    case SID_SLIDE_MASTER_MODE:
1419
0
                        xResourceId = new sd::framework::ResourceId(
1420
0
                            FrameworkHelper::msImpressViewURL,
1421
0
                            FrameworkHelper::msCenterPaneURL);
1422
0
                        bState = xConfiguration->hasResource(xResourceId);
1423
0
                        break;
1424
1425
0
                    case SID_SLIDE_SORTER_MULTI_PANE_GUI:
1426
0
                    case SID_SLIDE_SORTER_MODE:
1427
0
                        xResourceId = new sd::framework::ResourceId(
1428
0
                            FrameworkHelper::msSlideSorterURL,
1429
0
                            FrameworkHelper::msCenterPaneURL);
1430
0
                        bState = xConfiguration->hasResource(xResourceId);
1431
0
                        break;
1432
1433
0
                    case SID_OUTLINE_MODE:
1434
0
                        xResourceId = new sd::framework::ResourceId(
1435
0
                            FrameworkHelper::msOutlineViewURL,
1436
0
                            FrameworkHelper::msCenterPaneURL);
1437
0
                        bState = xConfiguration->hasResource(xResourceId);
1438
0
                        break;
1439
1440
0
                    case SID_HANDOUT_MASTER_MODE:
1441
0
                        xResourceId = new sd::framework::ResourceId(
1442
0
                            FrameworkHelper::msHandoutViewURL,
1443
0
                            FrameworkHelper::msCenterPaneURL);
1444
0
                        bState = xConfiguration->hasResource(xResourceId);
1445
0
                        break;
1446
1447
0
                    case SID_NOTES_MODE:
1448
0
                    case SID_NOTES_MASTER_MODE:
1449
0
                        xResourceId = new sd::framework::ResourceId(
1450
0
                            FrameworkHelper::msNotesViewURL,
1451
0
                            FrameworkHelper::msCenterPaneURL);
1452
0
                        bState = xConfiguration->hasResource(xResourceId);
1453
0
                        break;
1454
1455
0
                    case SID_TOGGLE_TABBAR_VISIBILITY:
1456
0
                        bState = GetUserWantsTabBar();
1457
0
                        break;
1458
0
                    case SID_PROTECTPOS:
1459
0
                    case SID_PROTECTSIZE:
1460
0
                    {
1461
0
                        ::sd::DrawDocShell* pDocSh = dynamic_cast<::sd::DrawDocShell*>(SfxObjectShell::Current());
1462
0
                        ::sd::ViewShell* pViewSh = pDocSh ? pDocSh->GetViewShell() : nullptr;
1463
0
                        ::sd::View* pView = pViewSh ? pViewSh->GetView() : nullptr;
1464
0
                        if (pView)
1465
0
                        {
1466
0
                            const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
1467
0
                            if ( rMarkList.GetMarkCount() == 1 ) // graphic menu only effective on single item
1468
0
                            {
1469
0
                                const SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
1470
0
                                const SdrObjKind nSdrObjKind = pObj->GetObjIdentifier();
1471
1472
0
                                if ( nSdrObjKind == SdrObjKind::Graphic )
1473
0
                                {
1474
0
                                    if ( nItemId == SID_PROTECTSIZE )
1475
0
                                    {
1476
0
                                        bState = pObj->IsResizeProtect();
1477
0
                                        if ( pObj->IsMoveProtect() )
1478
0
                                            bEnabled = false;
1479
0
                                    }
1480
0
                                    else
1481
0
                                        bState = pObj->IsMoveProtect();
1482
1483
0
                                    break;
1484
0
                                }
1485
0
                            }
1486
0
                        }
1487
0
                        bEnabled = false;
1488
0
                    }
1489
0
                    break;
1490
1491
0
                    default:
1492
                        // Ignore all other items.  They are not meant to be
1493
                        // handled by us.
1494
0
                        break;
1495
0
                }
1496
0
            }
1497
0
            catch (const DeploymentException&)
1498
0
            {
1499
0
            }
1500
1501
            // Check if edit mode fits too
1502
0
            if (bState && bEnabled)
1503
0
            {
1504
0
                ViewShell* const pCenterViewShell = FrameworkHelper::Instance(mrBase)->GetViewShell(
1505
0
                    FrameworkHelper::msCenterPaneURL).get();
1506
0
                DrawViewShell* const pShell = dynamic_cast<DrawViewShell*>(pCenterViewShell);
1507
0
                if (pShell)
1508
0
                {
1509
0
                    switch (nItemId)
1510
0
                    {
1511
0
                        case SID_DRAWINGMODE:
1512
0
                        case SID_NORMAL_MULTI_PANE_GUI:
1513
0
                        case SID_NOTES_MODE:
1514
0
                            bState = pShell->GetEditMode() == EditMode::Page;
1515
0
                            break;
1516
0
                        case SID_SLIDE_MASTER_MODE:
1517
0
                        case SID_NOTES_MASTER_MODE:
1518
0
                            bState = pShell->GetEditMode() == EditMode::MasterPage;
1519
0
                            break;
1520
0
                    }
1521
0
                }
1522
0
            }
1523
1524
            // And finally set the state.
1525
0
            rSet.Put(SfxBoolItem(nItemId, bState));
1526
0
            if (!bEnabled)
1527
0
                rSet.DisableItem( nItemId );
1528
1529
0
            nItemId = aSetIterator.NextWhich();
1530
0
        }
1531
0
    }
1532
0
    catch (const RuntimeException&)
1533
0
    {
1534
0
        DBG_UNHANDLED_EXCEPTION("sd.view");
1535
0
    }
1536
1537
0
}
1538
1539
} // end of namespace sd
1540
1541
//===== CurrentPageSetter ===========================================
1542
1543
namespace {
1544
1545
CurrentPageSetter::CurrentPageSetter (ViewShellBase& rBase)
1546
0
    : mrBase(rBase)
1547
0
{
1548
0
}
1549
1550
void CurrentPageSetter::operator() (bool)
1551
0
{
1552
0
    FrameView* pFrameView = nullptr;
1553
1554
0
    if (auto pViewShell = mrBase.GetMainViewShell().get())
1555
0
    {
1556
0
        pFrameView = pViewShell->GetFrameView();
1557
0
    }
1558
1559
0
    if (pFrameView==nullptr)
1560
0
        return;
1561
1562
0
    try
1563
0
    {
1564
        // Get the current page either from the DrawPagesSupplier or the
1565
        // MasterPagesSupplier.
1566
0
        Any aPage;
1567
0
        if (pFrameView->GetViewShEditModeOnLoad() == EditMode::Page)
1568
0
        {
1569
0
            Reference<drawing::XDrawPagesSupplier> xPagesSupplier (
1570
0
                mrBase.GetController()->getModel(), UNO_QUERY_THROW);
1571
0
            Reference<container::XIndexAccess> xPages (
1572
0
                xPagesSupplier->getDrawPages(), UNO_QUERY_THROW);
1573
0
            aPage = xPages->getByIndex(pFrameView->GetSelectedPageOnLoad());
1574
0
        }
1575
0
        else
1576
0
        {
1577
0
            Reference<drawing::XMasterPagesSupplier> xPagesSupplier (
1578
0
                mrBase.GetController()->getModel(), UNO_QUERY_THROW);
1579
0
            Reference<container::XIndexAccess> xPages (
1580
0
                xPagesSupplier->getMasterPages(), UNO_QUERY_THROW);
1581
0
            aPage = xPages->getByIndex(pFrameView->GetSelectedPageOnLoad());
1582
0
        }
1583
        // Switch to the page last edited by setting the CurrentPage
1584
        // property.
1585
0
        DrawController* pDrawController = mrBase.GetDrawController();
1586
0
        pDrawController->setPropertyValue (u"CurrentPage"_ustr, aPage);
1587
0
    }
1588
0
    catch (const RuntimeException&)
1589
0
    {
1590
        // We have not been able to set the current page at the main view.
1591
        // This is sad but still leaves us in a valid state.  Therefore,
1592
        // this exception is silently ignored.
1593
0
    }
1594
0
    catch (const beans::UnknownPropertyException&)
1595
0
    {
1596
0
        SAL_WARN("sd.view", "CurrentPage property unknown");
1597
0
    }
1598
0
}
1599
1600
} // end of anonymous namespace
1601
1602
SdViewOptions::SdViewOptions()
1603
0
    : msColorSchemeName(u"Default"_ustr)
1604
0
{
1605
0
    const svtools::ColorConfig& rColorConfig = SdModule::get()->GetColorConfig();
1606
0
    mnAppBackgroundColor = rColorConfig.GetColorValue(svtools::APPBACKGROUND).nColor;
1607
0
    mnDocBackgroundColor = rColorConfig.GetColorValue(svtools::DOCCOLOR).nColor;
1608
0
}
1609
1610
//===== FocusForwardingWindow =================================================
1611
1612
namespace sd {
1613
namespace {
1614
1615
FocusForwardingWindow::FocusForwardingWindow (
1616
    vcl::Window& rParentWindow,
1617
    ViewShellBase& rBase)
1618
0
    : vcl::Window(&rParentWindow, WinBits(WB_CLIPCHILDREN | WB_DIALOGCONTROL)),
1619
0
        mrBase(rBase)
1620
0
{
1621
0
    SAL_INFO("sd.view", "created FocusForwardingWindow at " << this);
1622
0
}
1623
1624
FocusForwardingWindow::~FocusForwardingWindow()
1625
0
{
1626
0
    disposeOnce();
1627
0
}
1628
1629
void FocusForwardingWindow::dispose()
1630
0
{
1631
0
    SAL_INFO("sd.view", "destroyed FocusForwardingWindow at " << this);
1632
0
    vcl::Window::dispose();
1633
0
}
1634
1635
void FocusForwardingWindow::KeyInput (const KeyEvent& rKEvt)
1636
0
{
1637
0
    std::shared_ptr<ViewShell> pViewShell = mrBase.GetMainViewShell();
1638
0
    if (pViewShell != nullptr)
1639
0
    {
1640
0
        vcl::Window* pWindow = pViewShell->GetActiveWindow();
1641
0
        if (pWindow != nullptr)
1642
0
        {
1643
            // Forward the focus so that the window is called directly the
1644
            // next time.
1645
0
            pWindow->GrabFocus();
1646
            // Forward the key press as well.
1647
0
            pWindow->KeyInput(rKEvt);
1648
0
        }
1649
0
    }
1650
0
}
1651
1652
void FocusForwardingWindow::Command (const CommandEvent& rEvent)
1653
0
{
1654
0
    std::shared_ptr<ViewShell> pViewShell = mrBase.GetMainViewShell();
1655
0
    if (pViewShell != nullptr)
1656
0
    {
1657
0
        vcl::Window* pWindow = pViewShell->GetActiveWindow();
1658
0
        if (pWindow != nullptr)
1659
0
        {
1660
0
            pWindow->Command(rEvent);
1661
0
        }
1662
0
    }
1663
0
}
1664
1665
} // end of anonymous namespace
1666
1667
} // end of namespace sd
1668
1669
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */