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_SFX2_VIEWFRM_HXX
20 #define INCLUDED_SFX2_VIEWFRM_HXX
21 
22 #include <memory>
23 #include <sal/config.h>
24 #include <sfx2/dllapi.h>
25 #include <sal/types.h>
26 #include <svl/lstner.hxx>
27 #include <sfx2/frame.hxx>
28 #include <sfx2/objsh.hxx>
29 #include <sfx2/shell.hxx>
30 #include <svl/poolitem.hxx>
31 
32 class Button;
33 class SvBorder;
34 class SfxDispatcher;
35 class SfxBindings;
36 class SfxProgress;
37 class SfxViewShell;
38 class Point;
39 class Size;
40 class SfxChildWindow;
41 class SfxInfoBarWindow;
42 enum class InfobarType;
43 
44 class SFX2_DLLPUBLIC SfxViewFrame: public SfxShell, public SfxListener
45 {
46     std::unique_ptr<struct SfxViewFrame_Impl>   m_pImpl;
47 
48     SfxObjectShellRef           m_xObjSh;
49     std::unique_ptr<SfxDispatcher> m_pDispatcher;
50     SfxBindings*                m_pBindings;
51     sal_uInt16                  m_nAdjustPosPixelLock;
52 
53 private:
54     SAL_DLLPRIVATE void Construct_Impl( SfxObjectShell *pObjSh );
55 
56 protected:
57     virtual void            Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
58 
59     DECL_LINK(GetInvolvedHandler, Button*, void);
60     DECL_LINK(DonationHandler, Button*, void);
61     DECL_LINK(WhatsNewHandler, Button*, void);
62     DECL_LINK(SwitchReadOnlyHandler, Button*, void);
63     DECL_LINK(SignDocumentHandler, Button*, void);
64     SAL_DLLPRIVATE void KillDispatcher_Impl();
65 
66     virtual                 ~SfxViewFrame() override;
67 
68 public:
69                             SfxViewFrame( SfxFrame& rFrame, SfxObjectShell *pDoc );
70 
71                             SFX_DECL_INTERFACE(SFX_INTERFACE_SFXVIEWFRM)
72 
73 private:
74     /// SfxInterface initializer.
75     static void InitInterface_Impl();
76 
77 public:
78 
79     static void             SetViewFrame( SfxViewFrame* );
80 
81     static SfxViewFrame*    LoadHiddenDocument( SfxObjectShell const & i_rDoc, SfxInterfaceId i_nViewId );
82     static SfxViewFrame*    LoadDocument( SfxObjectShell const & i_rDoc, SfxInterfaceId i_nViewId );
83     static SfxViewFrame*    LoadDocumentIntoFrame( SfxObjectShell const & i_rDoc, const SfxFrameItem* i_pFrameItem, SfxInterfaceId i_nViewId );
84     static SfxViewFrame*    LoadDocumentIntoFrame( SfxObjectShell const & i_rDoc, const css::uno::Reference< css::frame::XFrame >& i_rFrameItem );
85     static SfxViewFrame*    DisplayNewDocument( SfxObjectShell const & i_rDoc, const SfxRequest& i_rCreateDocRequest );
86 
87     static SfxViewFrame*    Current();
88     static SfxViewFrame*    GetFirst( const SfxObjectShell* pDoc = nullptr, bool bOnlyVisible = true );
89     static SfxViewFrame*    GetNext( const SfxViewFrame& rPrev, const SfxObjectShell* pDoc = nullptr, bool bOnlyVisible = true );
90 
91     static SfxViewFrame*    Get( const css::uno::Reference< css::frame::XController>& i_rController, const SfxObjectShell* i_pDoc );
92 
93             void            DoActivate(bool bMDI);
94             void            DoDeactivate(bool bMDI, SfxViewFrame const *pOld);
95 
96     using SfxShell::GetDispatcher;
GetDispatcher()97     SfxDispatcher*          GetDispatcher() { return m_pDispatcher.get(); }
GetBindings()98     SfxBindings&            GetBindings() { return *m_pBindings; }
GetBindings() const99     const SfxBindings&      GetBindings() const  { return *m_pBindings; }
100     vcl::Window&            GetWindow() const;
101 
102     SfxProgress*            GetProgress() const;
103 
LockAdjustPosSizePixel()104     void                    LockAdjustPosSizePixel()
105                             { m_nAdjustPosPixelLock++; }
UnlockAdjustPosSizePixel()106     void                    UnlockAdjustPosSizePixel()
107                             { m_nAdjustPosPixelLock--; }
108     void                    DoAdjustPosSizePixel( SfxViewShell * pSh,
109                                         const Point &rPos, const Size &rSize,
110                                         bool inplaceEditModeChange );
111     void                    Show();
112     bool                    IsVisible() const;
113     void                    ToTop();
114     void                    Enable( bool bEnable );
115     void                    Close();
116     virtual void            Activate( bool bUI ) override;
117     virtual void            Deactivate( bool bUI ) override;
118 
119     void                    UpdateTitle();
120 
121     // interne Handler
122     SAL_DLLPRIVATE void SetBorderPixelImpl( const SfxViewShell *pSh, const SvBorder &rBorder );
123     SAL_DLLPRIVATE const SvBorder& GetBorderPixelImpl() const;
124     SAL_DLLPRIVATE void InvalidateBorderImpl( const SfxViewShell *pSh );
125 
126     virtual SfxObjectShell* GetObjectShell() override;
127     SfxInterfaceId          GetCurViewId() const;
128     SfxFrame&               GetFrame() const;
129     SfxViewFrame*           GetTopViewFrame() const;
130 
131     bool                    DoClose();
GetHasTitle() const132     bool                    GetHasTitle() const
133                             { return GetFrame().GetHasTitle(); }
GetTargetList(TargetList & rList)134     static void             GetTargetList( TargetList& rList )
135                             { SfxFrame::GetDefaultTargetList( rList ); }
136 
137     void                    SetModalMode( bool );
138     bool                    IsInModalMode() const;
139     void                    Resize(bool bForce=false);
140 
141     void                    SetChildWindow(sal_uInt16 nId, bool bVisible, bool bSetFocus=true);
142     void                    ToggleChildWindow(sal_uInt16);
143     bool                    HasChildWindow(sal_uInt16);
144     bool                    KnowsChildWindow(sal_uInt16);
145     void                    ShowChildWindow(sal_uInt16,bool bVisible=true);
146     SfxChildWindow*         GetChildWindow(sal_uInt16);
147     void                    ChildWindowExecute(SfxRequest&);
148     void                    ChildWindowState(SfxItemSet&);
149 
150     /** Append a new InfoBar (see https://wiki.documentfoundation.org/Design/Whiteboards/Infobar).
151 
152         The buttons will be added from Right to Left at the right of the info bar. The parent, size
153         and position of each button will be changed: only the width will remain unchanged.
154       */
155     VclPtr<SfxInfoBarWindow> AppendInfoBar(const OUString& sId,
156                                     const OUString& sPrimaryMessage,
157                                     const OUString& sSecondaryMessage,
158                                     InfobarType aInfobarType,
159                                     bool bShowCloseButton=true);
160     void              RemoveInfoBar(const OUString& sId);
161     void              UpdateInfoBar(const OUString& sId, const OUString& sPrimaryMessage,
162                                     const OUString& sSecondaryMessage,
163                                     InfobarType eType);
164     bool              HasInfoBarWithID(const OUString& sId);
165 
166     SAL_DLLPRIVATE void GetDocNumber_Impl();
167     SAL_DLLPRIVATE void SetViewShell_Impl( SfxViewShell *pVSh );
168     SAL_DLLPRIVATE void ReleaseObjectShell_Impl();
169 
170     SAL_DLLPRIVATE void GetState_Impl( SfxItemSet &rSet );
171     SAL_DLLPRIVATE void ExecReload_Impl( SfxRequest &rReq );
172     SAL_DLLPRIVATE void StateReload_Impl( SfxItemSet &rSet );
173     SAL_DLLPRIVATE void ExecView_Impl( SfxRequest &rReq );
174     SAL_DLLPRIVATE void StateView_Impl( SfxItemSet &rSet );
175     SAL_DLLPRIVATE void ExecHistory_Impl( SfxRequest &rReq );
176     SAL_DLLPRIVATE void StateHistory_Impl( SfxItemSet &rSet );
177     SAL_DLLPRIVATE void ForceOuterResize_Impl();
178     SAL_DLLPRIVATE void UpdateDocument_Impl();
179 
180     SAL_DLLPRIVATE void LockObjectShell_Impl();
181 
182     SAL_DLLPRIVATE void MakeActive_Impl( bool bActivate );
183     SAL_DLLPRIVATE const Size& GetMargin_Impl() const;
184     SAL_DLLPRIVATE OUString GetActualPresentationURL_Impl() const;
185     SAL_DLLPRIVATE void MiscExec_Impl(SfxRequest &);
186     SAL_DLLPRIVATE void MiscState_Impl(SfxItemSet &);
187     SAL_DLLPRIVATE SfxWorkWindow* GetWorkWindow_Impl();
188     SAL_DLLPRIVATE void AddDispatchMacroToBasic_Impl(const OUString& sMacro);
189 
190     SAL_DLLPRIVATE void Exec_Impl(SfxRequest &);
191     SAL_DLLPRIVATE void INetExecute_Impl(SfxRequest &);
192     SAL_DLLPRIVATE void INetState_Impl(SfxItemSet &);
193 
194     SAL_DLLPRIVATE void SetCurViewId_Impl( const SfxInterfaceId i_nID );
195 
196 private:
197     SAL_DLLPRIVATE bool SwitchToViewShell_Impl( sal_uInt16 nNo, bool bIsIndex = false );
198     SAL_DLLPRIVATE void PopShellAndSubShells_Impl( SfxViewShell& i_rViewShell );
199     SAL_DLLPRIVATE void SaveCurrentViewData_Impl( const SfxInterfaceId i_nNewViewId );
200 
201     /** loads the given existing document into the given frame
202 
203         This is done using the XComponentLoader interface of the frame, so the SFX document loader is invoked.
204 
205         @param i_rDoc
206             the document to load
207         @param i_rFrame
208             the frame to load the document into
209         @param i_rLoadArgs
210             the arguments to pass to the component loader. If this sequence is empty, then the current arguments of the
211             model will be obtained, and passed to the loader. This ensures that any arguments in the model will be preserved,
212             instead of being reset.
213         @param i_nViewId
214             the ID of the view to create
215         @throws Exception
216             if something goes wrong. The caller is responsible for handling this.
217     */
218     SAL_DLLPRIVATE static SfxViewShell* LoadViewIntoFrame_Impl(
219                             const SfxObjectShell& i_rDoc,
220                             const css::uno::Reference< css::frame::XFrame >& i_rFrame,
221                             const css::uno::Sequence< css::beans::PropertyValue >& i_rLoadArgs,
222                             const SfxInterfaceId i_nViewId,
223                             const bool i_bHidden
224                         );
225 
226     /** loads the given existing document into the given frame
227 
228         This is done using the XComponentLoader interface of the frame, so the SFX document loader is invoked.
229 
230         If no frame is given, a blank top level frame is created.
231 
232         If anything fails during the process, as much as possible is cleaned up.
233 
234         @param i_rDoc
235             the document to load
236         @param i_rFrame
237             the frame to load the document into. Might be <NULL/>, in which case a new frame is created.
238         @param i_nViewId
239             the ID of the view to create
240     */
241     SAL_DLLPRIVATE static SfxViewFrame* LoadViewIntoFrame_Impl_NoThrow(
242                             const SfxObjectShell& i_rDoc,
243                             const css::uno::Reference< css::frame::XFrame >& i_rFrame,
244                             const SfxInterfaceId i_nViewId,
245                             const bool i_bHidden
246                         );
247 };
248 
249 
250 class SFX2_DLLPUBLIC SfxViewFrameItem final : public SfxPoolItem
251 {
252     SfxViewFrame* const     pFrame;
253 
254 public:
SfxViewFrameItem(SfxViewFrame * pViewFrame)255                             SfxViewFrameItem( SfxViewFrame *pViewFrame ):
256                                 SfxPoolItem( 0 ),
257                                 pFrame( pViewFrame)
258                             {}
259 
260     virtual bool            operator==( const SfxPoolItem& ) const override;
261     virtual SfxPoolItem*    Clone( SfxItemPool *pPool = nullptr ) const override;
262 
GetFrame() const263     SfxViewFrame*           GetFrame() const
264                             { return pFrame; }
265 };
266 
267 #endif
268 
269 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
270