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 #ifndef INCLUDED_SVX_FMSHELL_HXX
20 #define INCLUDED_SVX_FMSHELL_HXX
21 
22 // ***************************************************************************************************
23 // ***************************************************************************************************
24 // ***************************************************************************************************
25 
26 #include <memory>
27 #include <rtl/ref.hxx>
28 #include <sfx2/shell.hxx>
29 #include <vcl/outdev.hxx>
30 
31 #include <svx/svxdllapi.h>
32 #include <svx/ifaceids.hxx>
33 #include <svl/hint.hxx>
34 
35 #include <com/sun/star/uno/Reference.hxx>
36 
37 class FmFormModel;
38 class FmFormPage;
39 class FmXFormShell;
40 class FmFormView;
41 class SdrView;
42 class SdrUnoObj;
43 class LinkParamNone;
44 
45 namespace com::sun::star::form {
46     class XForm;
47     namespace runtime {
48         class XFormController;
49     }
50 }
51 
52 namespace com::sun::star::awt { class XControl; }
53 namespace com::sun::star::awt { class XControlModel; }
54 template <typename Arg, typename Ret> class Link;
55 
56 namespace svx
57 {
58     class ISdrObjectFilter;
59 }
60 
61 
62 class SAL_WARN_UNUSED SVXCORE_DLLPUBLIC FmDesignModeChangedHint final : public SfxHint
63 {
64     bool m_bDesignMode;
65 
66 public:
67     FmDesignModeChangedHint( bool bDesMode );
68     virtual ~FmDesignModeChangedHint() override;
69 
GetDesignMode() const70     bool GetDesignMode() const { return m_bDesignMode; }
71 };
72 
73 class SVXCORE_DLLPUBLIC FmFormShell final : public SfxShell
74 {
75     friend class FmFormView;
76     friend class FmXFormShell;
77 
78     rtl::Reference<FmXFormShell> m_pImpl;
79     FmFormView*     m_pFormView;
80     FmFormModel*    m_pFormModel;
81 
82     sal_uInt16  m_nLastSlot;
83     bool        m_bDesignMode : 1;
84     bool        m_bHasForms : 1;    // flag storing if the forms on a page exist,
85                                         // only for the DesignMode, see UIFeatureChanged!
86 
87     // the marks of a FormView have changed...
88     void NotifyMarkListChanged(FmFormView*);
89         // (the FormView itself is not a broadcaster, therefore it can't always correctly notify the
90         // form explorer who is interested in the event)
91 
92 public:
93     SFX_DECL_INTERFACE(SVX_INTERFACE_FORM_SH)
94 
95 private:
96     /// SfxInterface initializer.
97     static void InitInterface_Impl();
98 
99 public:
100     FmFormShell(SfxViewShell* pParent, FmFormView* pView = nullptr);
101     virtual ~FmFormShell() override;
102 
103     void Execute( SfxRequest& );
104     void GetState( SfxItemSet& );
105     virtual bool HasUIFeature(SfxShellFeature nFeature) const override;
106 
107     void ExecuteTextAttribute( SfxRequest& );
108     void GetTextAttributeState( SfxItemSet& );
109 
110     bool GetY2KState(sal_uInt16& nReturn);
111     void SetY2KState(sal_uInt16 n);
112 
113     void SetView(FmFormView* pView);
114 
GetFormView() const115     FmFormView*  GetFormView() const { return m_pFormView; }
GetFormModel() const116     FmFormModel* GetFormModel() const { return m_pFormModel; }
117     FmFormPage*  GetCurPage() const;
GetImpl() const118     FmXFormShell* GetImpl() const {return m_pImpl.get();};
119 
120     bool PrepareClose(bool bUI = true);
121 
122     bool        IsActiveControl() const;
123     void        ForgetActiveControl();
124     void        SetControlActivationHandler( const Link<LinkParamNone*,void>& _rHdl );
125 
126     virtual void    Activate(bool bMDI) override;
127     virtual void    Deactivate(bool bMDI) override;
128 
129     // helper methods for implementing XFormLayerAccess
130     SdrUnoObj* GetFormControl(
131         const css::uno::Reference< css::awt::XControlModel >& _rxModel,
132         const SdrView& _rView,
133         const OutputDevice& _rDevice,
134         css::uno::Reference< css::awt::XControl >& _out_rxControl
135     ) const;
136 
137     static css::uno::Reference< css::form::runtime::XFormController > GetFormController(
138         const css::uno::Reference< css::form::XForm >& _rxForm,
139         const SdrView& _rView,
140         const OutputDevice& _rDevice
141     );
142 
143     /** puts the focus into the document window, if current a form control has the focus. Otherwise, moves the focus
144         to the control belonging to the given SdrUnoObj.
145     */
146     void    ToggleControlFocus(
147         const SdrUnoObj& i_rNextCandidate,
148         const SdrView& i_rView,
149               OutputDevice& i_rDevice
150     ) const;
151 
152     static ::std::unique_ptr< svx::ISdrObjectFilter >
153             CreateFocusableControlFilter(
154                 const SdrView& i_rView,
155                 const OutputDevice& i_rDevice
156             );
157 
IsDesignMode() const158     virtual bool IsDesignMode() const override { return m_bDesignMode; }
159     void         SetDesignMode( bool _bDesignMode );
160 
161 private:
162     void GetFormState(SfxItemSet &rSet, sal_uInt16 nWhich);
163 
164     // is there a form on the current page?
165     void DetermineForms(bool bInvalidate);
166     void impl_setDesignMode( bool bDesign);
167 };
168 
169 #endif // INCLUDED_SVX_FMSHELL_HXX
170 
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
172