summaryrefslogtreecommitdiffstats
path: root/slideshow/source/inc/eventmultiplexer.hxx
blob: e0dd6fd31eb56be36055e58b6d28d7392f6eae28 (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
/* -*- 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 .
 */
#ifndef INCLUDED_SLIDESHOW_SOURCE_INC_EVENTMULTIPLEXER_HXX
#define INCLUDED_SLIDESHOW_SOURCE_INC_EVENTMULTIPLEXER_HXX

#include "eventhandler.hxx"
#include "mouseeventhandler.hxx"
#include "animationeventhandler.hxx"
#include "pauseeventhandler.hxx"
#include "shapelistenereventhandler.hxx"
#include "vieweventhandler.hxx"

#include <memory>
#include <com/sun/star/uno/Reference.hxx>

#include "unoview.hxx"

namespace com::sun::star::drawing { class XShape; }

namespace slideshow::internal {

class EventQueue;
class UnoViewContainer;
class AnimationNode;

struct EventMultiplexerImpl;

class RGBColor;

/** Interface for handling view repaint events.

    Classes implementing this interface can be added to an
    EventMultiplexer object, and are called from there to
    handle view repaint events.
*/
class ViewRepaintHandler
{
public:
    virtual ~ViewRepaintHandler() {}

    /** Notify clobbered view.

      Reasons for a viewChanged notification can be
      different view size, transformation, or other device
      properties (color resolution or profile, etc.)

      @param rView
      The changed view
     */
    virtual void viewClobbered( const UnoViewSharedPtr& rView ) = 0;
};

typedef ::std::shared_ptr< ViewRepaintHandler > ViewRepaintHandlerSharedPtr;

/** Interface for handling hyperlink clicks.

  Classes implementing this interface can be added to an
  EventMultiplexer object, and are called from there to
  handle hyperlink events.
 */
class HyperlinkHandler
{
public:
    /** Handle the event.

        @param rLink
        The actual hyperlink URI

        @return true, if this handler has successfully
        processed the event. When this method returns false,
        possibly other, less prioritized handlers are called,
        too.
    */
    virtual bool handleHyperlink( OUString const& rLink ) = 0;

protected:
    ~HyperlinkHandler() {}
};

typedef ::std::shared_ptr< HyperlinkHandler > HyperlinkHandlerSharedPtr;

/** Interface for handling user paint state changes.

    Classes implementing this interface can be added to an
    EventMultiplexer object, and are called from there to
    handle user paint events.
*/
class UserPaintEventHandler
{
public:
    virtual ~UserPaintEventHandler() {}
    virtual bool colorChanged( RGBColor const& rUserColor ) = 0;
    virtual bool widthChanged( double nUserStrokeWidth ) = 0;
    virtual bool eraseAllInkChanged(bool bEraseAllInk) =0;
    virtual bool eraseInkWidthChanged(sal_Int32 rEraseInkSize) =0;
    virtual bool switchEraserMode() = 0;
    virtual bool switchPenMode() = 0;
    virtual bool disable() = 0;
};

typedef ::std::shared_ptr< UserPaintEventHandler > UserPaintEventHandlerSharedPtr;

/** This class multiplexes user-activated and
    slide-show global events.

    This class listens at the XSlideShowView and fires events
    registered for certain user actions. Furthermore, global
    slide show state changes (such as start or end of a slide)
    are handled as well. Note that registered events which
    have a non-zero timeout (i.e. events that return non-zero
    from getActivationTime()) will not be fired immediately
    after the user action occurred, but only after the given
    timeout. Which is actually a feature.
*/
class EventMultiplexer
{
public:
    /** Create an event multiplexer

        @param rEventQueue
        Reference to the main event queue. Since we hold this
        object by plain reference, it must live longer than we
        do. On the other hand, that queue must not fire events
        after this object is destroyed, since we might
        schedule events there which itself contain plain
        references to this object. Basically, EventQueue and
        EventMultiplexer should have the same lifetime, and since
        this is not possible, both must be destructed in a
        phased mode: first clear both of any remaining events,
        then destruct them.

        @param rViewContainer
        Globally managed list of all registered views. Used to
        determine event sources, and for registering view listeners
        at.
    */
    EventMultiplexer( EventQueue&             rEventQueue,
                      UnoViewContainer const& rViewContainer );
    ~EventMultiplexer();
    EventMultiplexer(const EventMultiplexer&) = delete;
    EventMultiplexer& operator=(const EventMultiplexer&) = delete;

    // Management methods


    /** Clear all registered handlers.
     */
    void clear();


    // Automatic mode methods


    /** Change automatic mode.

        @param bIsAuto
        When true, events will be fired automatically, not
        only triggered by UI events. When false, auto events
        will quit.
    */
    void setAutomaticMode( bool bIsAuto );

    /** Get automatic mode setting.
     */
    bool getAutomaticMode() const;

    /** Set the timeout for automatic mode.

        @param nTimeout
        Timeout, between end of effect until start of next
        effect.
    */
    void setAutomaticTimeout( double nTimeout );

    /** Get automatic mode timeout value.
     */
    double getAutomaticTimeout() const;

    // Handler registration methods


    /** Register an event handler that will be called when views are
        changed.

        For each view added, viewAdded() will be called on the
        handler. For each view removed, viewRemoved() will be
        called. Each modified view will cause a viewChanged() call on
        each handler.

        You don't need to deregister the handler, it will be
        automatically removed, once the pointee becomes stale.

        @param rHandler
        Handler to call.
    */
    void addViewHandler( const ViewEventHandlerWeakPtr& rHandler );
    void removeViewHandler( const ViewEventHandlerWeakPtr& rHandler );

    /** Register an event handler that will be called when a view gets
        clobbered.

        Note that <em>all</em> registered handlers will be called when
        the event. This is in contrast to the mouse events below.

        @param rHandler
        Handler to call when a view needs a repaint
    */
    void addViewRepaintHandler( const ViewRepaintHandlerSharedPtr& rHandler );
    void removeViewRepaintHandler( const ViewRepaintHandlerSharedPtr& rHandler );

    /** Register an event handler that will be called when
        XShapeListeners are changed.

        @param rHandler
        Handler to call when a shape listener changes
    */
    void addShapeListenerHandler( const ShapeListenerEventHandlerSharedPtr& rHandler );
    void removeShapeListenerHandler( const ShapeListenerEventHandlerSharedPtr& rHandler );

    /** Register an event handler that will be called when
        user paint parameters change.

        @param rHandler
        Handler to call when a shape listener changes
    */
    void addUserPaintHandler( const UserPaintEventHandlerSharedPtr& rHandler );

    /** Register an event handler that will be called when the
        user requests the next effect.

        For every nextEffect event, only one of the handlers
        registered here is called. The handlers are considered
        with decreasing priority, i.e. the handler with the
        currently highest priority will be called.

        @param rHandler
        Handler to call when the next effect should start

        @param nPriority
        Priority with which the handlers are called. The
        higher the priority, the earlier this handler will be
        tried.
    */
    void addNextEffectHandler( const EventHandlerSharedPtr& rHandler,
                               double                       nPriority );
    void removeNextEffectHandler( const EventHandlerSharedPtr& rHandler );

    /** Register an event handler that will be called when the
        slide is just shown.

        Note that <em>all</em> registered handlers will be called
        when the slide start occurs. This is in contrast to
        the mouse events below.

        @param rHandler
        Handler to call when the next slide starts
    */
    void addSlideStartHandler( const EventHandlerSharedPtr& rHandler );
    void removeSlideStartHandler( const EventHandlerSharedPtr& rHandler );

    /** Register an event handler that will be called when the
        slide is about to vanish.

        Note that <em>all</em> registered handlers will be
        called when the slide end occurs. This is in contrast
        to the mouse events below.

        @param rHandler
        Handler to call when the current slide ends
    */
    void addSlideEndHandler( const EventHandlerSharedPtr& rHandler );
    void removeSlideEndHandler( const EventHandlerSharedPtr& rHandler );

    /** Register an event handler that will be called when an
        XAnimationNode starts its active duration.

        Note that <em>all</em> registered handlers will be called
        when the animation start occurs. This is in contrast to
        the mouse events below.

        @param rHandler
        Handler to call when the animation start
    */
    void addAnimationStartHandler(
        const AnimationEventHandlerSharedPtr& rHandler );
    void removeAnimationStartHandler(
        const AnimationEventHandlerSharedPtr& rHandler );

    /** Register an event handler that will be called when an
        XAnimationNode ends its active duration.

        Note that <em>all</em> registered handlers will be called
        when the animation end occurs. This is in contrast to
        the mouse events below.

        @param rHandler
        Handler to call when the animation ends
    */
    void addAnimationEndHandler(
        const AnimationEventHandlerSharedPtr& rHandler );
    void removeAnimationEndHandler(
        const AnimationEventHandlerSharedPtr& rHandler );

    /** Register an event handler that will be called when the
        main animation sequence of a slide ends its active
        duration.

        Note that <em>all</em> registered handlers will be
        called when the animation end occurs. This is in
        contrast to the mouse events below.

        @param rHandler
        Handler to call when the animation ends
    */
    void addSlideAnimationsEndHandler(
        const EventHandlerSharedPtr& rHandler );
    void removeSlideAnimationsEndHandler(
        const EventHandlerSharedPtr& rHandler );

    /** Register an event handler that will be called when an
        XAudio node's sound stops playing.

        Note that <em>all</em> registered handlers will be
        called when the audio stops. This is in contrast to
        the mouse events below.

        @param rHandler
        Handler to call when the audio stops
    */
    void addAudioStoppedHandler(
        const AnimationEventHandlerSharedPtr& rHandler );
    void removeAudioStoppedHandler(
        const AnimationEventHandlerSharedPtr& rHandler );

    /** Register an event handler that will be called when an
        XCommand node's with the command STOPAUDIO is activated.

        Note that <em>all</em> registered handlers will be
        called when the audio stops. This is in contrast to
        the mouse events below.

        @param rHandler
        Handler to call when command is activated
    */
    void addCommandStopAudioHandler(
        const AnimationEventHandlerSharedPtr& rHandler );
    void removeCommandStopAudioHandler(
        const AnimationEventHandlerSharedPtr& rHandler );

    /** Register a handler that is called when the show enters
        or exits pause mode.
    */
    void addPauseHandler( const PauseEventHandlerSharedPtr& rHandler );
    void removePauseHandler( const PauseEventHandlerSharedPtr& rHandler );

    /** Register a mouse handler that is called on mouse click

        For every mouse click, only one of the handlers
        registered here is called. The handlers are considered
        with decreasing priority, i.e. the handler with the
        currently highest priority will be called.

        Since the handlers can reject down and up events
        individually, handlers should expect to be called with
        non-matching down and up-press counts. If your handler
        cannot cope with that, it must have the highest
        priority of all added handlers.
    */
    void addClickHandler( const MouseEventHandlerSharedPtr& rHandler,
                          double                            nPriority );
    void removeClickHandler( const MouseEventHandlerSharedPtr& rHandler );

    /** Register a mouse handler that is called on a double
        mouse click

        For every mouse double click, only one of the handlers
        registered here is called. The handlers are considered
        with decreasing priority, i.e. the handler with the
        currently highest priority will be called.

        Since the handlers can reject down and up events
        individually, handlers should expect to be called with
        non-matching down and up-press counts. If your handler
        cannot cope with that, it must have the highest
        priority of all added handlers.
    */
    void addDoubleClickHandler( const MouseEventHandlerSharedPtr&   rHandler,
                                double                              nPriority );
    void removeDoubleClickHandler( const MouseEventHandlerSharedPtr& rHandler );

    /** Register a mouse handler that is called for mouse moves.

        For every mouse move, only one of the handlers
        registered here is called. The handlers are considered
        with decreasing priority, i.e. the handler with the
        currently highest priority will be called.
    */
    void addMouseMoveHandler( const MouseEventHandlerSharedPtr& rHandler,
                              double                            nPriority );
    void removeMouseMoveHandler( const MouseEventHandlerSharedPtr& rHandler );


    /** Registers a hyperlink click handler.

        For every hyperlink click, only one of the handlers registered
        here is called. The handlers are considered with decreasing
        priority, i.e. the handler with the currently highest priority
        will be called.

        @param rHandler
        @param nPriority
    */
    void addHyperlinkHandler( const HyperlinkHandlerSharedPtr& rHandler,
                              double                           nPriority );
    void removeHyperlinkHandler( const HyperlinkHandlerSharedPtr& rHandler );


    // External event notifications


    /** View added.

        This method adds another view, which the show is
        displayed on. On every added view, the EventMultiplexer
        registers mouse and motion event listeners.
    */
    void notifyViewAdded( const UnoViewSharedPtr& rView );

    /** View removed

        This method removes a view. Registered mouse and
        motion event listeners are revoked.
    */
    void notifyViewRemoved( const UnoViewSharedPtr& rView );

    /** View changed

        This method announces a changed view to all view
        listeners. View changes include size and transformation.

        @param rView
        View that has changed
    */
    void notifyViewChanged( const UnoViewSharedPtr& rView );

    /** View changed

        This method announces a changed view to all view
        listeners. View changes include size and transformation.

        @param xView
        View that has changed
    */
    void notifyViewChanged( const css::uno::Reference<css::presentation::XSlideShowView>& xView );

    /** All Views changed

        This method announces to all view listeners that
        <em>every</em> known view has changed. View changes include
        size and transformation.
    */
    void notifyViewsChanged();

    /** View clobbered

        This method announces that the given view has been clobbered
        by something external to the slideshow, and needs an update.

        @param xView
        View that has been clobbered
    */
    void notifyViewClobbered( const css::uno::Reference<css::presentation::XSlideShowView>& xView );

    /** New shape event listener added

        This method announces that the given listener was added for
        the specified shape.
     */
    void notifyShapeListenerAdded( const css::uno::Reference<css::drawing::XShape>& xShape );

    /** A shape event listener was removed

        This method announces that the given listener was removed for
        the specified shape.
     */
    void notifyShapeListenerRemoved( const css::uno::Reference<css::drawing::XShape>& xShape );

    /** Notify a new user paint color

        Sending this notification also implies that user paint is
        enabled. User paint denotes the feature to draw colored lines
        on top of the slide content.
    */
    void notifyUserPaintColor( RGBColor const& rUserColor );

    /** Notify a new user paint width

         Sending this notification also implies that user paint is
         enabled. .
    */
    void notifyUserPaintStrokeWidth( double rUserStrokeWidth );


    /** Notify a new user paint erase all ink mode

     Sending this notification also implies that user paint is
     enabled. User paint denotes the feature to draw colored lines
     on top of the slide content.
     */
    void notifyEraseAllInk( bool bEraseAllInk );
    void notifySwitchPenMode();
    void notifySwitchEraserMode();
    void notifyEraseInkWidth( sal_Int32 rEraseInkSize );

    /** Notify that user paint is disabled

        User paint denotes the feature to draw colored lines on top of
        the slide content.
    */
    void notifyUserPaintDisabled();

    /** Notify that the user requested the next effect.

        This requests the slideshow to display the next
        effect, or move to the next slide, if none are left.

        @return true, if this event was processed by
        anybody. If false is returned, no handler processed
        this event (and probably, nothing will happen at all)
    */
    bool notifyNextEffect();

    /** Notify that a new slide has started

        This method is to be used from the Presentation object
        to signal that a new slide is starting now. This will
        invoke all registered slide start handlers.
    */
    void notifySlideStartEvent();

    /** Notify that a slide has ended

        This method is to be used from the Presentation object
        to signal that a slide is ending now. This will invoke
        all registered slide end handlers.

        @return true, if this event was processed by
        anybody. If false is returned, no handler processed
        this event (and probably, nothing will happen at all)
    */
    bool notifySlideEndEvent();

    /** Notify that the given node enters its active duration.

        This method is to be used from the AnimationNode
        objects to signal that the active duration
        begins. This will invoke all registered animation
        start handlers.

        @param rNode
        Node which enters active duration.

        @return true, if this event was processed by
        anybody. If false is returned, no handler processed
        this event (and probably, nothing will happen at all)
    */
    bool notifyAnimationStart( const AnimationNodeSharedPtr& rNode );

    /** Notify that the given node leaves its active duration.

        This method is to be used from the AnimationNode
        objects to signal that the active duration
        ends now. This will invoke all registered animation
        end handlers.

        @param rNode
        Node which leaves active duration.

        @return true, if this event was processed by
        anybody. If false is returned, no handler processed
        this event (and probably, nothing will happen at all)
    */
    bool notifyAnimationEnd( const AnimationNodeSharedPtr& rNode );

    /** Notify that the slide animations sequence leaves its
        active duration.

        @return true, if this event was processed by
        anybody. If false is returned, no handler processed
        this event (and probably, nothing will happen at all)
    */
    bool notifySlideAnimationsEnd();

    /** Notify that for the given node, audio output has stopped.

        This method is to be used from the AnimationNode
        objects to signal that audio playback has just
        stopped. This will invoke all registered audio
        stopped handlers.

        @param rNode
        Node for which audio has stopped.

        @return true, if this event was processed by
        anybody. If false is returned, no handler processed
        this event (and probably, nothing will happen at all)
    */
    bool notifyAudioStopped( const AnimationNodeSharedPtr& rNode );

    /** Notify that the show has entered or exited pause mode

        This method is to be used from the Presentation object
        to signal that a slide is entering (bPauseShow=true)
        or exiting (bPauseShow=false) pause mode. This will
        invoke all registered slide end handlers.
    */
    void notifyPauseMode( bool bPauseShow );

    /** Notify that all audio has to be stopped.

        This method is used by XCommand nodes and all sound
        playing nodes should listen for this command and
        stop their sounds when it's fired.

        @return true, if this event was processed by
        anybody. If false is returned, no handler processed
        this event (and probably, nothing will happen at all)
    */
    bool notifyCommandStopAudio( const AnimationNodeSharedPtr& rNode );

    /** Notifies that a hyperlink has been clicked.
    */
    void notifyHyperlinkClicked( OUString const& hyperLink );

private:
    std::unique_ptr<EventMultiplexerImpl> mpImpl;
};

} // namespace Presentation::internal

#endif // INCLUDED_SLIDESHOW_SOURCE_INC_EVENTMULTIPLEXER_HXX

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