summaryrefslogtreecommitdiffstats
path: root/sd/source/console/PresenterProtocolHandler.cxx
blob: ddfb4340c09b69ec8f57ce635fbe80b1ec275820 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <memory>
#include "PresenterProtocolHandler.hxx"
#include "PresenterController.hxx"
#include "PresenterNotesView.hxx"
#include "PresenterPaneContainer.hxx"
#include "PresenterViewFactory.hxx"
#include "PresenterWindowManager.hxx"
#include <cppuhelper/compbase.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <algorithm>
#include <utility>

using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::drawing::framework;

namespace sdext::presenter {

namespace {
    class Command
    {
    public:
        virtual ~Command() {}
        virtual void Execute() = 0;
        virtual bool IsEnabled() const { return true; }
        virtual Any GetState() const { return Any(false); }
    };

    class GotoPreviousSlideCommand : public Command
    {
    public:
        explicit GotoPreviousSlideCommand (
            rtl::Reference<PresenterController> xPresenterController);
        virtual void Execute() override;
        virtual bool IsEnabled() const override;
    private:
        rtl::Reference<PresenterController> mpPresenterController;
    };

    class GotoNextSlideCommand : public Command
    {
    public:
        explicit GotoNextSlideCommand (
            rtl::Reference<PresenterController> xPresenterController);
        virtual void Execute() override;
        // The next slide command is always enabled, even when the current slide
        // is the last slide:  from the last slide it goes to the pause slide,
        // and from there it ends the slide show.
        virtual bool IsEnabled() const override { return true; }
    private:
        rtl::Reference<PresenterController> mpPresenterController;
    };

    class GotoNextEffectCommand : public Command
    {
    public:
        explicit GotoNextEffectCommand (
            rtl::Reference<PresenterController> xPresenterController);
        virtual void Execute() override;
        virtual bool IsEnabled() const override;
    private:
        rtl::Reference<PresenterController> mpPresenterController;
    };

    class SwitchMonitorCommand : public Command
    {
    public:
        explicit SwitchMonitorCommand (
            rtl::Reference<PresenterController> xPresenterController);
        virtual void Execute() override;
    private:
        rtl::Reference<PresenterController> mpPresenterController;
    };

    class PauseResumeCommand : public Command
    {
    public:
        explicit PauseResumeCommand(rtl::Reference<PresenterController> xPresenterController);
        virtual void Execute() override;
        virtual Any GetState() const override;
    private:
        rtl::Reference<PresenterController> mpPresenterController;
    };

    /// This command restarts the presentation timer.
    class RestartTimerCommand : public Command
    {
    public:
        explicit RestartTimerCommand(rtl::Reference<PresenterController> xPresenterController);
        virtual void Execute() override;
    private:
        rtl::Reference<PresenterController> mpPresenterController;
    };

    class SetNotesViewCommand : public Command
    {
    public:
        SetNotesViewCommand (
            const bool bOn,
            rtl::Reference<PresenterController> xPresenterController);
        virtual void Execute() override;
        virtual Any GetState() const override;
    private:
        bool mbOn;
        rtl::Reference<PresenterController> mpPresenterController;
    };

    class SetSlideSorterCommand : public Command
    {
    public:
        SetSlideSorterCommand (
            const bool bOn,
            rtl::Reference<PresenterController> xPresenterController);
        virtual void Execute() override;
        virtual Any GetState() const override;
    private:
        bool mbOn;
        rtl::Reference<PresenterController> mpPresenterController;
    };

    class SetHelpViewCommand : public Command
    {
    public:
        SetHelpViewCommand (
            const bool bOn,
            rtl::Reference<PresenterController> xPresenterController);
        virtual void Execute() override;
        virtual Any GetState() const override;
    private:
        bool mbOn;
        rtl::Reference<PresenterController> mpPresenterController;
    };

    class NotesFontSizeCommand : public Command
    {
    public:
        NotesFontSizeCommand(
            rtl::Reference<PresenterController> xPresenterController,
            const sal_Int32 nSizeChange);
        virtual void Execute() override;
        virtual Any GetState() const override;
    protected:
        ::rtl::Reference<PresenterNotesView> GetNotesView() const;
    private:
        rtl::Reference<PresenterController> mpPresenterController;
        const sal_Int32 mnSizeChange;
    };

    class ExitPresenterCommand : public Command
    {
    public:
        explicit ExitPresenterCommand(rtl::Reference<PresenterController> xPresenterController);
        virtual void Execute() override;
    private:
        rtl::Reference<PresenterController> mpPresenterController;
    };

} // end of anonymous namespace

namespace {
    typedef ::cppu::WeakComponentImplHelper <
        css::frame::XDispatch,
        css::document::XEventListener
        > PresenterDispatchInterfaceBase;
}

class PresenterProtocolHandler::Dispatch
    : protected ::cppu::BaseMutex,
      public PresenterDispatchInterfaceBase
{
public:
    /** Create a new Dispatch object.  When the given command name
        (rsURLPath) is not known then an empty reference is returned.
    */
    static Reference<frame::XDispatch> Create (
        const OUString& rsURLPath,
        const ::rtl::Reference<PresenterController>& rpPresenterController);

    void SAL_CALL disposing() override;
    static Command* CreateCommand (
        std::u16string_view rsURLPath,
        const ::rtl::Reference<PresenterController>& rpPresenterController);

    // XDispatch
    virtual void SAL_CALL dispatch(
        const css::util::URL& aURL,
        const css::uno::Sequence<css::beans::PropertyValue>& rArguments) override;

    virtual void SAL_CALL addStatusListener(
        const css::uno::Reference<css::frame::XStatusListener>& rxListener,
        const css::util::URL& rURL) override;

    virtual void SAL_CALL removeStatusListener (
        const css::uno::Reference<css::frame::XStatusListener>& rxListener,
        const css::util::URL& rURL) override;

    // document::XEventListener

    virtual void SAL_CALL notifyEvent (const css::document::EventObject& rEvent) override;

    // lang::XEventListener

    virtual void SAL_CALL disposing (const css::lang::EventObject& rEvent) override;

private:
    OUString msURLPath;
    std::unique_ptr<Command> mpCommand;
    ::rtl::Reference<PresenterController> mpPresenterController;
    typedef ::std::vector<Reference<frame::XStatusListener> > StatusListenerContainer;
    StatusListenerContainer maStatusListenerContainer;
    bool mbIsListeningToWindowManager;

    Dispatch (
        const OUString& rsURLPath,
        const ::rtl::Reference<PresenterController>& rpPresenterController);
    virtual ~Dispatch() override;
};


//===== PresenterProtocolHandler =========================================================

PresenterProtocolHandler::PresenterProtocolHandler ()
    : PresenterProtocolHandlerInterfaceBase(m_aMutex)
{
}

PresenterProtocolHandler::~PresenterProtocolHandler()
{
}

void SAL_CALL PresenterProtocolHandler::disposing()
{
}

//----- XInitialize -----------------------------------------------------------

void SAL_CALL PresenterProtocolHandler::initialize (const Sequence<Any>& aArguments)
{
    ThrowIfDisposed();
    if (aArguments.getLength() <= 0)
        return;

    try
    {
        Reference<frame::XFrame> xFrame;
        if (aArguments[0] >>= xFrame)
        {
            mpPresenterController = PresenterController::Instance(xFrame);
        }
    }
    catch (RuntimeException&)
    {
        OSL_ASSERT(false);
    }
}

OUString PresenterProtocolHandler::getImplementationName()
{
    return "org.libreoffice.comp.PresenterScreenProtocolHandler";
}

sal_Bool PresenterProtocolHandler::supportsService(OUString const & ServiceName)
{
    return cppu::supportsService(this, ServiceName);
}

css::uno::Sequence<OUString>
PresenterProtocolHandler::getSupportedServiceNames()
{
    return { "com.sun.star.frame.ProtocolHandler" };
}

extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
sd_PresenterProtocolHandler_get_implementation(
    css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&)
{
    return cppu::acquire(new PresenterProtocolHandler());
}

//----- XDispatchProvider -----------------------------------------------------

Reference<frame::XDispatch> SAL_CALL PresenterProtocolHandler::queryDispatch (
    const css::util::URL& rURL,
    const OUString&,
    sal_Int32)
{
    ThrowIfDisposed();

    Reference<frame::XDispatch> xDispatch;

    // tdf#154546 skip dispatch when presenter controller is not set
    // mpPresenterController is sometimes unset and this will cause a
    // crash when pressing the presenter console's Exchange button.
    if (rURL.Protocol == "vnd.org.libreoffice.presenterscreen:" && mpPresenterController.is())
    {
        xDispatch.set(Dispatch::Create(rURL.Path, mpPresenterController));
    }

    return xDispatch;
}

Sequence<Reference<frame::XDispatch> > SAL_CALL PresenterProtocolHandler::queryDispatches(
    const Sequence<frame::DispatchDescriptor>&)
{
    ThrowIfDisposed();
    return Sequence<Reference<frame::XDispatch> >();
}


void PresenterProtocolHandler::ThrowIfDisposed() const
{
    if (rBHelper.bDisposed || rBHelper.bInDispose)
    {
        throw lang::DisposedException (
            "PresenterProtocolHandler object has already been disposed",
            const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
    }
}

//===== PresenterProtocolHandler::Dispatch ====================================

Reference<frame::XDispatch> PresenterProtocolHandler::Dispatch::Create (
    const OUString& rsURLPath,
    const ::rtl::Reference<PresenterController>& rpPresenterController)
{
    ::rtl::Reference<Dispatch> pDispatch (new Dispatch (rsURLPath, rpPresenterController));
    if (pDispatch->mpCommand != nullptr)
        return pDispatch;
    else
        return nullptr;
}

PresenterProtocolHandler::Dispatch::Dispatch (
    const OUString& rsURLPath,
    const ::rtl::Reference<PresenterController>& rpPresenterController)
    : PresenterDispatchInterfaceBase(m_aMutex),
      msURLPath(rsURLPath),
      mpCommand(CreateCommand(rsURLPath, rpPresenterController)),
      mpPresenterController(rpPresenterController),
      mbIsListeningToWindowManager(false)
{
    if (mpCommand != nullptr)
    {
        mpPresenterController->GetWindowManager()->AddLayoutListener(this);
        mbIsListeningToWindowManager = true;
    }
}

Command* PresenterProtocolHandler::Dispatch::CreateCommand (
    std::u16string_view rsURLPath,
    const ::rtl::Reference<PresenterController>& rpPresenterController)
{
    if (rsURLPath.size() <= 5)
        return nullptr;

    if (rsURLPath == u"CloseNotes")
        return new SetNotesViewCommand(false, rpPresenterController);
    if (rsURLPath == u"CloseSlideSorter")
        return new SetSlideSorterCommand(false, rpPresenterController);
    if (rsURLPath == u"CloseHelp")
        return new SetHelpViewCommand(false, rpPresenterController);
    if (rsURLPath == u"GrowNotesFont")
        return new NotesFontSizeCommand(rpPresenterController, +1);
    if (rsURLPath == u"NextEffect")
        return new GotoNextEffectCommand(rpPresenterController);
    if (rsURLPath == u"NextSlide")
        return new GotoNextSlideCommand(rpPresenterController);
    if (rsURLPath == u"PrevSlide")
        return new GotoPreviousSlideCommand(rpPresenterController);
    if (rsURLPath == u"SwitchMonitor")
        return new SwitchMonitorCommand(rpPresenterController);
    if (rsURLPath == u"PauseResumeTimer")
        return new PauseResumeCommand(rpPresenterController);
    if (rsURLPath == u"RestartTimer")
        return new RestartTimerCommand(rpPresenterController);
    if (rsURLPath == u"ShowNotes")
        return new SetNotesViewCommand(true, rpPresenterController);
    if (rsURLPath == u"ShowSlideSorter")
        return new SetSlideSorterCommand(true, rpPresenterController);
    if (rsURLPath == u"ShowHelp")
        return new SetHelpViewCommand(true, rpPresenterController);
    if (rsURLPath == u"ShrinkNotesFont")
        return new NotesFontSizeCommand(rpPresenterController, -1);
    if (rsURLPath == u"ExitPresenter")
        return new ExitPresenterCommand(rpPresenterController);

    return nullptr;
}

PresenterProtocolHandler::Dispatch::~Dispatch()
{
}

void PresenterProtocolHandler::Dispatch::disposing()
{
    if (mbIsListeningToWindowManager)
    {
        if (mpPresenterController)
            mpPresenterController->GetWindowManager()->RemoveLayoutListener(this);
        mbIsListeningToWindowManager = false;
    }

    msURLPath.clear();
    mpCommand.reset();
}

//----- XDispatch -------------------------------------------------------------

void SAL_CALL PresenterProtocolHandler::Dispatch::dispatch(
    const css::util::URL& rURL,
    const css::uno::Sequence<css::beans::PropertyValue>& /*rArguments*/)
{
    if (rBHelper.bDisposed || rBHelper.bInDispose)
    {
        throw lang::DisposedException (
            "PresenterProtocolHandler::Dispatch object has already been disposed",
            static_cast<uno::XWeak*>(this));
    }

    if (rURL.Protocol != "vnd.org.libreoffice.presenterscreen:"
        || rURL.Path != msURLPath)
    {
        // We can not throw an IllegalArgumentException
        throw RuntimeException();
    }

    if (mpCommand != nullptr)
        mpCommand->Execute();
}

void SAL_CALL PresenterProtocolHandler::Dispatch::addStatusListener(
    const css::uno::Reference<css::frame::XStatusListener>& rxListener,
    const css::util::URL& rURL)
{
    if (rURL.Path != msURLPath)
        throw RuntimeException();

    maStatusListenerContainer.push_back(rxListener);

    frame::FeatureStateEvent aEvent;
    aEvent.FeatureURL = rURL;
    aEvent.IsEnabled = mpCommand->IsEnabled();
    aEvent.Requery = false;
    aEvent.State = mpCommand->GetState();
    rxListener->statusChanged(aEvent);
}

void SAL_CALL PresenterProtocolHandler::Dispatch::removeStatusListener (
    const css::uno::Reference<css::frame::XStatusListener>& rxListener,
    const css::util::URL& rURL)
{
    if (rURL.Path != msURLPath)
        throw RuntimeException();

    StatusListenerContainer::iterator iListener (
        ::std::find(
            maStatusListenerContainer.begin(),
            maStatusListenerContainer.end(),
            rxListener));
    if (iListener != maStatusListenerContainer.end())
        maStatusListenerContainer.erase(iListener);
}

//----- document::XEventListener ----------------------------------------------

void SAL_CALL PresenterProtocolHandler::Dispatch::notifyEvent (
    const css::document::EventObject&)
{
    mpCommand->GetState();
}

//----- lang::XEventListener --------------------------------------------------

void SAL_CALL PresenterProtocolHandler::Dispatch::disposing (const css::lang::EventObject&)
{
    mbIsListeningToWindowManager = false;
}

//===== GotoPreviousSlideCommand ==============================================

GotoPreviousSlideCommand::GotoPreviousSlideCommand (
    rtl::Reference<PresenterController> xPresenterController)
    : mpPresenterController(std::move(xPresenterController))
{
}

void GotoPreviousSlideCommand::Execute()
{
    if ( ! mpPresenterController.is())
        return;

    if ( ! mpPresenterController->GetSlideShowController().is())
        return;

    mpPresenterController->GetSlideShowController()->gotoPreviousSlide();
}

bool GotoPreviousSlideCommand::IsEnabled() const
{
    if ( ! mpPresenterController.is())
        return false;

    if ( ! mpPresenterController->GetSlideShowController().is())
        return false;

    return mpPresenterController->GetSlideShowController()->getCurrentSlideIndex()>0;
}

//===== GotoNextEffect ========================================================

GotoNextEffectCommand::GotoNextEffectCommand (
    rtl::Reference<PresenterController> xPresenterController)
    : mpPresenterController(std::move(xPresenterController))
{
}

void GotoNextEffectCommand::Execute()
{
    if ( ! mpPresenterController.is())
        return;

    if ( ! mpPresenterController->GetSlideShowController().is())
        return;

    mpPresenterController->GetSlideShowController()->gotoNextEffect();
}

bool GotoNextEffectCommand::IsEnabled() const
{
    if ( ! mpPresenterController.is())
        return false;

    if ( ! mpPresenterController->GetSlideShowController().is())
        return false;

    return ( mpPresenterController->GetSlideShowController()->getNextSlideIndex() < mpPresenterController->GetSlideShowController()->getSlideCount() );

}

//===== GotoNextSlide =========================================================

GotoNextSlideCommand::GotoNextSlideCommand (
    rtl::Reference<PresenterController> xPresenterController)
    : mpPresenterController(std::move(xPresenterController))
{
}

void GotoNextSlideCommand::Execute()
{
    if ( ! mpPresenterController.is())
        return;

    if ( ! mpPresenterController->GetSlideShowController().is())
        return;

    mpPresenterController->GetSlideShowController()->gotoNextSlide();
}

//===== SwitchMonitorCommand ==============================================

SwitchMonitorCommand::SwitchMonitorCommand (
    rtl::Reference<PresenterController> xPresenterController)
    : mpPresenterController(std::move(xPresenterController))
{
}

void SwitchMonitorCommand::Execute()
{
    mpPresenterController->SwitchMonitors();
}

//===== PauseResumeCommand ==============================================

PauseResumeCommand::PauseResumeCommand (rtl::Reference<PresenterController> xPresenterController)
: mpPresenterController(std::move(xPresenterController))
{
}

void PauseResumeCommand::Execute()
{
    if ( ! mpPresenterController.is())
        return;

    ::rtl::Reference<PresenterWindowManager> pWindowManager (
        mpPresenterController->GetWindowManager());
    if ( ! pWindowManager.is())
        return;

    IPresentationTime* pPresentationTime = mpPresenterController->GetPresentationTime();
    if (!pPresentationTime)
        return;

    if(pPresentationTime->isPaused())
    {
        pPresentationTime->setPauseStatus(false);
        pWindowManager->SetPauseState(false);
    }
    else
    {
        pPresentationTime->setPauseStatus(true);
        pWindowManager->SetPauseState(true);
    }
}

Any PauseResumeCommand::GetState() const
{
    if ( ! mpPresenterController.is())
        return Any(false);

    ::rtl::Reference<PresenterWindowManager> pWindowManager (
        mpPresenterController->GetWindowManager());
    if ( ! pWindowManager.is())
        return Any(false);

    if (IPresentationTime* pPresentationTime = mpPresenterController->GetPresentationTime())
    {
        return Any(pPresentationTime->isPaused());
    }
    else
        return Any(false);
}

RestartTimerCommand::RestartTimerCommand (rtl::Reference<PresenterController> xPresenterController)
: mpPresenterController(std::move(xPresenterController))
{
}

void RestartTimerCommand::Execute()
{
    if ( ! mpPresenterController.is())
        return;

    ::rtl::Reference<PresenterWindowManager> pWindowManager (
        mpPresenterController->GetWindowManager());
    if ( ! pWindowManager.is())
        return;

    if (IPresentationTime* pPresentationTime = mpPresenterController->GetPresentationTime())
    {
        //Resets the pause status and restarts the timer
        pPresentationTime->setPauseStatus(false);
        pWindowManager->SetPauseState(false);
        pPresentationTime->restart();
    }
}

//===== SetNotesViewCommand ===================================================

SetNotesViewCommand::SetNotesViewCommand (
    const bool bOn,
    rtl::Reference<PresenterController> xPresenterController)
    : mbOn(bOn),
      mpPresenterController(std::move(xPresenterController))
{
}

void SetNotesViewCommand::Execute()
{
    if ( ! mpPresenterController.is())
        return;

    ::rtl::Reference<PresenterWindowManager> pWindowManager (
        mpPresenterController->GetWindowManager());
    if ( ! pWindowManager.is())
        return;

    if (mbOn)
        pWindowManager->SetViewMode(PresenterWindowManager::VM_Notes);
    else
        pWindowManager->SetViewMode(PresenterWindowManager::VM_Standard);
}

Any SetNotesViewCommand::GetState() const
{
    if ( ! mpPresenterController.is())
        return Any(false);

    ::rtl::Reference<PresenterWindowManager> pWindowManager (
        mpPresenterController->GetWindowManager());
    if ( ! pWindowManager.is())
        return Any(false);

    return Any(pWindowManager->GetViewMode() == PresenterWindowManager::VM_Notes);
}

//===== SetSlideSorterCommand =================================================

SetSlideSorterCommand::SetSlideSorterCommand (
    const bool bOn,
    rtl::Reference<PresenterController> xPresenterController)
    : mbOn(bOn),
      mpPresenterController(std::move(xPresenterController))
{
}

void SetSlideSorterCommand::Execute()
{
    if ( ! mpPresenterController.is())
        return;

    ::rtl::Reference<PresenterWindowManager> pWindowManager (
        mpPresenterController->GetWindowManager());
    if ( ! pWindowManager.is())
        return;

    pWindowManager->SetSlideSorterState(mbOn);
}

Any SetSlideSorterCommand::GetState() const
{
    if ( ! mpPresenterController.is())
        return Any(false);

    ::rtl::Reference<PresenterWindowManager> pWindowManager (
        mpPresenterController->GetWindowManager());
    if ( ! pWindowManager.is())
        return Any(false);

    return Any(pWindowManager->GetViewMode()==PresenterWindowManager::VM_SlideOverview);
}

//===== SetHelpViewCommand ===================================================

SetHelpViewCommand::SetHelpViewCommand (
    const bool bOn,
    rtl::Reference<PresenterController> xPresenterController)
    : mbOn(bOn),
      mpPresenterController(std::move(xPresenterController))
{
}

void SetHelpViewCommand::Execute()
{
    if ( ! mpPresenterController.is())
        return;

    ::rtl::Reference<PresenterWindowManager> pWindowManager (
        mpPresenterController->GetWindowManager());
    if ( ! pWindowManager.is())
        return;

    pWindowManager->SetHelpViewState(mbOn);
}

Any SetHelpViewCommand::GetState() const
{
    if ( ! mpPresenterController.is())
        return Any(false);

    ::rtl::Reference<PresenterWindowManager> pWindowManager (
        mpPresenterController->GetWindowManager());
    if ( ! pWindowManager.is())
        return Any(false);

    return Any(pWindowManager->GetViewMode()==PresenterWindowManager::VM_Help);
}

//===== NotesFontSizeCommand ==================================================

NotesFontSizeCommand::NotesFontSizeCommand(
    rtl::Reference<PresenterController> xPresenterController,
    const sal_Int32 nSizeChange)
    : mpPresenterController(std::move(xPresenterController)),
      mnSizeChange(nSizeChange)
{
}

::rtl::Reference<PresenterNotesView> NotesFontSizeCommand::GetNotesView() const
{
    if (!mpPresenterController)
        return nullptr;

    PresenterPaneContainer::SharedPaneDescriptor pDescriptor (
        mpPresenterController->GetPaneContainer()->FindViewURL(
            PresenterViewFactory::msNotesViewURL));
    if (!pDescriptor)
        return nullptr;

    return dynamic_cast<PresenterNotesView*>(pDescriptor->mxView.get());
}

void NotesFontSizeCommand::Execute()
{
    ::rtl::Reference<PresenterNotesView> pView (GetNotesView());
    if (pView.is())
        pView->ChangeFontSize(mnSizeChange);
}

Any NotesFontSizeCommand::GetState() const
{
    return Any();
}

//===== ExitPresenterCommand ==================================================

ExitPresenterCommand::ExitPresenterCommand (rtl::Reference<PresenterController> xPresenterController)
: mpPresenterController(std::move(xPresenterController))
{
}

void ExitPresenterCommand::Execute()
{
    if ( ! mpPresenterController.is())
        return;

    mpPresenterController->ExitPresenter();
}

} // end of namespace ::sdext::presenter

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */