1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_SFX2_VIEWSH_HXX
20 #define INCLUDED_SFX2_VIEWSH_HXX
22 #include <sal/config.h>
24 #include <sfx2/dllapi.h>
25 #include <sal/types.h>
26 #include <com/sun/star/embed/XEmbeddedObject.hpp>
27 #include <com/sun/star/frame/XController.hpp>
28 #include <com/sun/star/view/XRenderable.hpp>
29 #include <com/sun/star/uno/Reference.h>
30 #include <svl/lstner.hxx>
31 #include <com/sun/star/ui/XContextMenuInterceptor.hpp>
32 #include <com/sun/star/datatransfer/clipboard/XClipboardListener.hpp>
33 #include <com/sun/star/datatransfer/clipboard/XClipboardNotifier.hpp>
34 #include <cppuhelper/interfacecontainer.hxx>
35 #include <sfx2/shell.hxx>
36 #include <tools/gen.hxx>
37 #include <tools/errcode.hxx>
38 #include <vcl/jobset.hxx>
39 #include <o3tl/typed_flags_set.hxx>
40 #include <vcl/vclptr.hxx>
41 #include <sfx2/tabdlg.hxx>
42 #include <LibreOfficeKit/LibreOfficeKitTypes.h>
45 class SfxBaseController
;
48 namespace vcl
{ class Window
; }
58 class SfxFrameSetDescriptor
;
66 class SfxInPlaceClient
;
67 namespace vcl
{ class PrinterController
; }
70 enum class SfxPrinterChangeFlags
73 PRINTER
= 1, // without JOB SETUP => Temporary
81 template<> struct typed_flags
<SfxPrinterChangeFlags
> : is_typed_flags
<SfxPrinterChangeFlags
, 31> {};
83 #define SFX_PRINTER_ALL (SfxPrinterChangeFlags::PRINTER | SfxPrinterChangeFlags::JOBSETUP | SfxPrinterChangeFlags::OPTIONS | SfxPrinterChangeFlags::CHG_ORIENTATION | SfxPrinterChangeFlags::CHG_SIZE)
85 #define SFX_PRINTERROR_BUSY 1
87 // "Verified" using www.apple.com and Netscape 3.01
88 #define DEFAULT_MARGIN_WIDTH 8
89 #define DEFAULT_MARGIN_HEIGHT 12
92 // @[SfxViewShell-Flags]
94 enum class SfxViewShellFlags
97 HAS_PRINTOPTIONS
= 0x0010, /* Options-Button and Options-Dialog in PrintDialog */
98 CAN_PRINT
= 0x0020, /* Printing enabled without having to create a Printer */
99 NO_SHOW
= 0x0040, /* Window of the ViewShell shall not be showed automatically */
100 NO_NEWWINDOW
= 0x0100, /* Allow N View */
104 template<> struct typed_flags
<SfxViewShellFlags
> : is_typed_flags
<SfxViewShellFlags
, 0x0170> {};
109 The SfxViewShell flags control the behavior of SfxViewShell for the
110 duration of its lifetime. They are defined in the constructor of
115 #define SFX_DECL_VIEWFACTORY(Class) \
117 static SfxViewFactory *pFactory; \
119 static SfxViewShell *CreateInstance(SfxViewFrame *pFrame, SfxViewShell *pOldView); \
120 static void RegisterFactory( sal_uInt16 nPrio = USHRT_MAX ); \
121 static SfxViewFactory*Factory() { return pFactory; } \
122 static void InitFactory()
124 #define SFX_IMPL_NAMED_VIEWFACTORY(Class, AsciiViewName) \
125 SfxViewFactory* Class::pFactory; \
126 SfxViewShell* Class::CreateInstance(SfxViewFrame *pFrame, SfxViewShell *pOldView) \
127 { return new Class(pFrame, pOldView); } \
128 void Class::RegisterFactory( sal_uInt16 nPrio ) \
130 pFactory = new SfxViewFactory(&CreateInstance,nPrio,AsciiViewName);\
133 void Class::InitFactory()
135 #define SFX_VIEW_REGISTRATION(DocClass) \
136 DocClass::Factory().RegisterViewFactory( *Factory() )
138 template<class T
> bool checkSfxViewShell(const SfxViewShell
* pShell
)
140 return dynamic_cast<const T
*>(pShell
) != nullptr;
143 class SFX2_DLLPUBLIC SfxViewShell
: public SfxShell
, public SfxListener
145 #ifdef INCLUDED_SFX2_VIEWSH_HXX
146 friend class SfxViewFrame
;
147 friend class SfxBaseController
;
148 friend class SfxPrinterController
;
151 struct SfxViewShell_Impl
* pImp
;
152 SfxViewFrame
* pFrame
;
154 VclPtr
<vcl::Window
> pWindow
;
156 bool mbPrinterSettingsModified
;
159 virtual void Activate(bool IsMDIActivate
) override
;
160 virtual void Deactivate(bool IsMDIActivate
) override
;
162 virtual void InnerResizePixel( const Point
&rOfs
, const Size
&rSize
);
163 virtual void OuterResizePixel( const Point
&rOfs
, const Size
&rSize
);
164 virtual void SetZoomFactor( const Fraction
&rZoomX
, const Fraction
&rZoomY
);
168 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
172 static SfxViewShell
* GetFirst( bool bOnlyVisible
= true, const std::function
<bool ( const SfxViewShell
* )>& isViewShell
= nullptr );
173 static SfxViewShell
* GetNext( const SfxViewShell
& rPrev
,
174 bool bOnlyVisible
= true,
175 const std::function
<bool ( const SfxViewShell
* )>& isViewShell
= nullptr );
176 static SfxViewShell
* Current();
178 static SfxViewShell
* Get( const css::uno::Reference
< css::frame::XController
>& i_rController
);
180 // Initialize Constructors/Destructors
181 SFX_DECL_INTERFACE(SFX_INTERFACE_SFXVIEWSH
)
184 /// SfxInterface initializer.
185 static void InitInterface_Impl();
189 SfxViewShell( SfxViewFrame
*pFrame
, SfxViewShellFlags nFlags
= SfxViewShellFlags::NONE
);
190 virtual ~SfxViewShell();
192 SfxInPlaceClient
* GetIPClient() const;
193 SfxInPlaceClient
* GetUIActiveClient() const;
194 SfxInPlaceClient
* FindIPClient( const css::uno::Reference
< css::embed::XEmbeddedObject
>& xObj
, vcl::Window
*pObjParentWin
) const;
196 virtual ErrCode
DoVerb(long nVerb
);
198 void OutplaceActivated( bool bActive
, SfxInPlaceClient
* pClient
);
199 virtual void UIActivating( SfxInPlaceClient
* pClient
);
200 virtual void UIDeactivated( SfxInPlaceClient
* pClient
);
202 void JumpToMark( const OUString
& rMark
);
203 void VisAreaChanged(const Rectangle
& rRect
);
208 * Initialize is called after the frame has been loaded and the controller
209 * has been set. By the time this is called the document has been fully
212 virtual bool PrepareClose( bool bUI
= true );
213 virtual OUString
GetSelectionText( bool bCompleteWords
= false );
214 virtual bool HasSelection( bool bText
= true ) const;
215 virtual SdrView
* GetDrawView() const;
217 SfxShell
* GetSubShell() const { return pSubShell
; }
218 void AddSubShell( SfxShell
& rShell
);
219 void RemoveSubShell( SfxShell
*pShell
=nullptr );
220 SfxShell
* GetSubShell( sal_uInt16
);
222 virtual SfxShell
* GetFormShell() { return nullptr; };
223 virtual const SfxShell
* GetFormShell() const { return nullptr; };
225 // Focus, KeyInput, Cursor
226 virtual void ShowCursor( bool bOn
= true );
227 virtual bool KeyInput( const KeyEvent
&rKeyEvent
);
231 vcl::Window
* GetWindow() const { return pWindow
; }
232 void SetWindow( vcl::Window
*pViewPort
);
233 virtual void AdjustPosSizePixel( const Point
&rOfs
, const Size
&rSize
);
234 const SvBorder
& GetBorderPixel() const;
235 void SetBorderPixel( const SvBorder
&rBorder
);
236 void InvalidateBorder();
237 inline SfxViewFrame
* GetViewFrame() const;
239 // Printing Interface
240 virtual SfxPrinter
* GetPrinter( bool bCreate
= false );
241 virtual sal_uInt16
SetPrinter( SfxPrinter
*pNewPrinter
, SfxPrinterChangeFlags nDiffFlags
= SFX_PRINTER_ALL
);
242 virtual bool HasPrintOptionsPage() const;
243 virtual VclPtr
<SfxTabPage
> CreatePrintOptionsPage( vcl::Window
*pParent
, const SfxItemSet
&rOptions
);
244 static JobSetup
GetJobSetup();
245 Printer
* GetActivePrinter() const;
248 virtual void WriteUserData( OUString
&, bool bBrowse
= false );
249 virtual void ReadUserData( const OUString
&, bool bBrowse
= false );
250 virtual void WriteUserDataSequence ( css::uno::Sequence
< css::beans::PropertyValue
>& );
251 virtual void ReadUserDataSequence ( const css::uno::Sequence
< css::beans::PropertyValue
>& );
252 virtual void QueryObjAreaPixel( Rectangle
& rRect
) const;
254 virtual SfxObjectShell
* GetObjectShell() override
;
256 /** retrieves the document which shall be considered the "current document" when the frame is active
258 The default implementation simply returns the XModel of the associated SfxObjectShell. You will rarely
259 need to overwrite this behavior.
261 virtual css::uno::Reference
< css::frame::XModel
>
262 GetCurrentDocument() const;
264 /** forwards the current document, as returned by ->GetCurrentDocument, to SfxObjectShell::SetWorkingDocument
266 void SetCurrentDocument() const;
268 /** get an XRenderable instance that can render this document
270 virtual css::uno::Reference
< css::view::XRenderable
> GetRenderable();
273 virtual void MarginChanged();
274 const Size
& GetMargin() const;
275 void SetMargin( const Size
& );
276 void DisconnectAllClients();
277 bool NewWindowAllowed() const { return !bNoNewWindow
; }
278 void SetNewWindowAllowed( bool bSet
) { bNoNewWindow
= !bSet
; }
280 void SetController( SfxBaseController
* pController
);
281 css::uno::Reference
< css::frame::XController
>
284 bool TryContextMenuInterception( Menu
& rIn
, const OUString
& rMenuIdentifier
, Menu
*& rpOut
, css::ui::ContextMenuExecuteEvent aEvent
);
285 bool TryContextMenuInterception( Menu
& rMenu
, const OUString
& rMenuIdentifier
, css::ui::ContextMenuExecuteEvent aEvent
);
287 void ExecPrint( const css::uno::Sequence
< css::beans::PropertyValue
>&, bool, bool );
288 // Like ExecPrint(), but only sets up for printing. Use Printer::ExecutePrintJob() and Printer::FinishPrintJob() afterwards.
289 void StartPrint( const css::uno::Sequence
< css::beans::PropertyValue
>&, bool, bool );
290 const std::shared_ptr
< vcl::PrinterController
>& GetPrinterController() const;
292 void AddRemoveClipboardListener( const css::uno::Reference
< css::datatransfer::clipboard::XClipboardListener
>&, bool );
293 css::uno::Reference
< css::datatransfer::clipboard::XClipboardNotifier
> GetClipboardNotifier();
295 SAL_DLLPRIVATE SfxInPlaceClient
* GetUIActiveIPClient_Impl() const;
296 SAL_DLLPRIVATE
void AddContextMenuInterceptor_Impl( const css::uno::Reference
< css::ui::XContextMenuInterceptor
>& xInterceptor
);
297 SAL_DLLPRIVATE
void RemoveContextMenuInterceptor_Impl( const css::uno::Reference
< css::ui::XContextMenuInterceptor
>& xInterceptor
);
298 SAL_DLLPRIVATE
bool GlobalKeyInput_Impl( const KeyEvent
&rKeyEvent
);
300 SAL_DLLPRIVATE
void NewIPClient_Impl( SfxInPlaceClient
*pIPClient
);
301 SAL_DLLPRIVATE
void IPClientGone_Impl( SfxInPlaceClient
*pIPClient
);
302 SAL_DLLPRIVATE
void ResetAllClients_Impl( SfxInPlaceClient
*pIP
);
303 SAL_DLLPRIVATE
void DiscardClients_Impl();
305 SAL_DLLPRIVATE
void SetPrinter_Impl( VclPtr
<SfxPrinter
>& pNewPrinter
);
306 SAL_DLLPRIVATE
bool IsShowView_Impl() const;
308 SAL_DLLPRIVATE
bool HandleNotifyEvent_Impl( NotifyEvent
& rEvent
);
309 SAL_DLLPRIVATE
bool HasKeyListeners_Impl();
310 SAL_DLLPRIVATE
bool HasMouseClickListeners_Impl();
312 SAL_DLLPRIVATE SfxBaseController
* GetBaseController_Impl() const;
315 SAL_DLLPRIVATE
void ExecPrint_Impl(SfxRequest
&);
316 SAL_DLLPRIVATE
void ExecMisc_Impl(SfxRequest
&);
317 SAL_DLLPRIVATE
void GetState_Impl(SfxItemSet
&);
318 SAL_DLLPRIVATE
void CheckIPClient_Impl(SfxInPlaceClient
*, const Rectangle
&);
319 SAL_DLLPRIVATE
void PushSubShells_Impl( bool bPush
=true );
320 SAL_DLLPRIVATE
void PopSubShells_Impl() { PushSubShells_Impl( false ); }
321 SAL_DLLPRIVATE
void TakeOwnership_Impl();
322 SAL_DLLPRIVATE
void TakeFrameOwnership_Impl();
323 SAL_DLLPRIVATE
bool ExecKey_Impl(const KeyEvent
& aKey
);
325 /// The actual per-view implementation of lok::Document::registerCallback().
326 void registerLibreOfficeKitViewCallback(LibreOfficeKitCallback pCallback
, void* pLibreOfficeKitData
);
327 /// Invokes the registered callback, if there are any.
328 void libreOfficeKitViewCallback(int nType
, const char* pPayload
) const;
332 inline SfxViewFrame
* SfxViewShell::GetViewFrame() const
336 This method returns a pointer to the <SfxViewFrame> Instance in which
337 this SfxViewShell is displayed. This is the instance that was passed
338 on in the constructor. It is guaranteed that the returned pointer
339 points on the valid SfxViewFrame instance.
343 <SfxShell::GetFrame()const>
350 #endif // INCLUDED_SFX2_VIEWSH_HXX
353 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */