summaryrefslogtreecommitdiffstats
path: root/svx/source/inc/fmtextcontrolshell.hxx
blob: 77ea5c5d2f94f5205f84a8bf2603026c6f0104c6 (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
/* -*- 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_SVX_SOURCE_INC_FMTEXTCONTROLSHELL_HXX
#define INCLUDED_SVX_SOURCE_INC_FMTEXTCONTROLSHELL_HXX

#include <com/sun/star/frame/XDispatchProvider.hpp>
#include <com/sun/star/awt/FocusEvent.hpp>
#include <com/sun/star/awt/XTextComponent.hpp>
#include <com/sun/star/form/runtime/XFormController.hpp>
#include <com/sun/star/awt/XControl.hpp>
#include <com/sun/star/util/XURLTransformer.hpp>
#include <rtl/ref.hxx>
#include <tools/link.hxx>
#include <vcl/timer.hxx>
#include "fmslotinvalidator.hxx"

#include <vector>
#include <map>

class SfxRequest;
class SfxItemSet;
class SfxAllItemSet;
class SfxBindings;
class SfxViewFrame;
class SfxApplication;


namespace svx
{


    class FmFocusListenerAdapter;
    class FmTextControlFeature;
    class FmMouseListenerAdapter;

    class IFocusObserver
    {
    public:
        virtual void    focusGained( const css::awt::FocusEvent& _rEvent ) = 0;
        virtual void    focusLost( const css::awt::FocusEvent& _rEvent ) = 0;

    protected:
        ~IFocusObserver() {}
    };


    //= IFocusObserver

    class IContextRequestObserver
    {
    public:
        virtual void    contextMenuRequested() = 0;

    protected:
        ~IContextRequestObserver() {}
    };

    class FmTextControlShell final : public IFocusObserver
                             ,public IContextRequestObserver
    {
    private:
        css::uno::Reference< css::util::XURLTransformer >             m_xURLTransformer;
        css::uno::Reference< css::awt::XControl >                     m_xActiveControl;
        css::uno::Reference< css::awt::XTextComponent >               m_xActiveTextComponent;
        css::uno::Reference< css::form::runtime::XFormController >    m_xActiveController;
#ifndef DONT_REMEMBER_LAST_CONTROL
        // without this define, m_xActiveControl remembers the *last* active control, even
        // if it, in the meantime, already lost the focus
        bool                                                          m_bActiveControl;
            // so we need an additional boolean flag telling whether the active control
            // is really focused
#endif
        bool                                                          m_bActiveControlIsReadOnly;
        bool                                                          m_bActiveControlIsRichText;

        // listening at all controls of the active controller for focus changes
        typedef rtl::Reference<FmFocusListenerAdapter> FocusListenerAdapter;
        typedef ::std::vector< FocusListenerAdapter >  FocusListenerAdapters;
        FocusListenerAdapters                                         m_aControlObservers;

        typedef rtl::Reference<FmMouseListenerAdapter> MouseListenerAdapter;
        MouseListenerAdapter                                         m_aContextMenuObserver;

        // translating between "slots" of the framework and "features" of the active control
        typedef rtl::Reference<FmTextControlFeature> ControlFeature;
        typedef ::std::map< SfxSlotId, ControlFeature >   ControlFeatures;
        ControlFeatures                                             m_aControlFeatures;

        SfxViewFrame*                                               m_pViewFrame;
        // invalidating slots
        SfxBindings&                                                m_rBindings;
        Link<LinkParamNone*,void>                                   m_aControlActivationHandler;
        AutoTimer                                                   m_aClipboardInvalidation;
        bool                                                        m_bNeedClipboardInvalidation;

    public:
        FmTextControlShell( SfxViewFrame* _pFrame );
        virtual ~FmTextControlShell();

        // clean up any resources associated with this instance
        void    dispose();

        void    ExecuteTextAttribute( SfxRequest& _rReq );
        void    GetTextAttributeState( SfxItemSet& _rSet );
        bool    IsActiveControl( bool _bCountRichTextOnly = false ) const;
        void    ForgetActiveControl();
        void    SetControlActivationHandler( const Link<LinkParamNone*,void>& _rHdl ) { m_aControlActivationHandler = _rHdl; }

        /** to be called when a form in our document has been activated
        */
        void    formActivated( const css::uno::Reference< css::form::runtime::XFormController >& _rxController );
        /** to be called when a form in our document has been deactivated
        */
        void    formDeactivated( const css::uno::Reference< css::form::runtime::XFormController >& _rxController );

        /** notifies the instance that the design mode has changed
        */
        void    designModeChanged();

        void    Invalidate( SfxSlotId _nSlot );

    private:
        // IFocusObserver
        virtual void    focusGained( const css::awt::FocusEvent& _rEvent ) override;
        virtual void    focusLost( const css::awt::FocusEvent& _rEvent ) override;

        // IContextRequestObserver
        virtual void    contextMenuRequested() override;

        enum AttributeSet { eCharAttribs, eParaAttribs };
        void    executeAttributeDialog( AttributeSet _eSet, SfxRequest& _rReq );
        void    executeSelectAll( );
        void    executeClipboardSlot( SfxSlotId _nSlot );

        bool    isControllerListening() const { return !m_aControlObservers.empty(); }

        rtl::Reference<FmTextControlFeature>
                        implGetFeatureDispatcher(
                            const css::uno::Reference< css::frame::XDispatchProvider >& _rxProvider,
                            SfxApplication const * _pApplication,
                            SfxSlotId _nSlot
                        );

        // fills the given structure with dispatchers for the given slots, for the given control
        void            fillFeatureDispatchers(
                            const css::uno::Reference< css::awt::XControl >& _rxControl,
                            SfxSlotId* _pZeroTerminatedSlots,
                            ControlFeatures& _rDispatchers
                        );

        /// creates SfxPoolItes for all features in the given set, and puts them into the given SfxAllItemSet
        static void     transferFeatureStatesToItemSet(
                            ControlFeatures& _rDispatchers,
                            SfxAllItemSet& _rSet,
                            bool _bTranslateLatin
                        );

        /// to be called when a control has been activated
        void    controlActivated( const css::uno::Reference< css::awt::XControl >& _rxControl );
        /// to be called when the currently active control has been deactivated
        void    controlDeactivated( );

        void    implClearActiveControlRef();

        /** starts listening at all controls of the given controller for focus events
        @precond
            we don't have an active controller currently
        */
        void    startControllerListening( const css::uno::Reference< css::form::runtime::XFormController >& _rxController );
        /** stops listening at the active controller
        @precond
            we have an active controller currently
        */
        void    stopControllerListening( );

        DECL_LINK( OnInvalidateClipboard, Timer*, void );
    };


}


#endif // INCLUDED_SVX_SOURCE_INC_FMTEXTCONTROLSHELL_HXX

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