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/uno/Reference.h>
27 #include <svl/lstner.hxx>
28 #include <sfx2/shell.hxx>
29 #include <i18nlangtag/languagetag.hxx>
30 #include <vcl/IDialogRenderable.hxx>
31 #include <vcl/errcode.hxx>
32 #include <o3tl/typed_flags_set.hxx>
33 #include <vcl/vclptr.hxx>
34 #include <LibreOfficeKit/LibreOfficeKitTypes.h>
35 #include <editeng/outliner.hxx>
39 class SfxBaseController
;
45 class DialogController
;
57 class SfxInPlaceClient
;
58 namespace vcl
{ class PrinterController
; }
60 namespace com::sun::star::datatransfer
{ namespace clipboard
{ class XClipboardListener
; } }
61 namespace com::sun::star::datatransfer
{ namespace clipboard
{ class XClipboardNotifier
; } }
62 namespace com::sun::star::embed
{ class XEmbeddedObject
; }
63 namespace com::sun::star::frame
{ class XController
; }
64 namespace com::sun::star::frame
{ class XModel
; }
65 namespace com::sun::star::ui
{ class XContextMenuInterceptor
; }
66 namespace com::sun::star::ui
{ struct ContextMenuExecuteEvent
; }
67 namespace com::sun::star::view
{ class XRenderable
; }
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 NO_NEWWINDOW
= 0x0100, /* Allow N View */
102 template<> struct typed_flags
<SfxViewShellFlags
> : is_typed_flags
<SfxViewShellFlags
, 0x0110> {};
107 The SfxViewShell flags control the behavior of SfxViewShell for the
108 duration of its lifetime. They are defined in the constructor of
112 enum class LOKDeviceFormFactor
120 class SfxViewFactory
;
121 #define SFX_DECL_VIEWFACTORY(Class) \
123 static SfxViewFactory *pFactory; \
125 static SfxViewShell *CreateInstance(SfxViewFrame *pFrame, SfxViewShell *pOldView); \
126 static void RegisterFactory( SfxInterfaceId nPrio ); \
127 static SfxViewFactory*Factory() { return pFactory; } \
128 static void InitFactory()
130 #define SFX_IMPL_NAMED_VIEWFACTORY(Class, AsciiViewName) \
131 SfxViewFactory* Class::pFactory; \
132 SfxViewShell* Class::CreateInstance(SfxViewFrame *pFrame, SfxViewShell *pOldView) \
133 { return new Class(pFrame, pOldView); } \
134 void Class::RegisterFactory( SfxInterfaceId nPrio ) \
136 pFactory = new SfxViewFactory(&CreateInstance,nPrio,AsciiViewName);\
139 void Class::InitFactory()
141 #define SFX_VIEW_REGISTRATION(DocClass) \
142 DocClass::Factory().RegisterViewFactory( *Factory() )
144 template<class T
> bool checkSfxViewShell(const SfxViewShell
* pShell
)
146 return dynamic_cast<const T
*>(pShell
) != nullptr;
149 class SFX2_DLLPUBLIC SfxViewShell
: public SfxShell
, public SfxListener
, public OutlinerViewShell
, public vcl::ILibreOfficeKitNotifier
151 friend class SfxViewFrame
;
152 friend class SfxBaseController
;
153 friend class SfxPrinterController
;
155 std::unique_ptr
<struct SfxViewShell_Impl
> pImpl
;
156 SfxViewFrame
* pFrame
;
157 VclPtr
<vcl::Window
> pWindow
;
159 bool mbPrinterSettingsModified
;
160 LanguageTag maLOKLanguageTag
;
161 LanguageTag maLOKLocale
;
162 LOKDeviceFormFactor maLOKDeviceFormFactor
;
164 /// Used to set the DocId at construction time. See SetCurrentDocId.
165 static ViewShellDocId mnCurrentDocId
;
168 virtual void Activate(bool IsMDIActivate
) override
;
169 virtual void Deactivate(bool IsMDIActivate
) override
;
171 virtual void InnerResizePixel( const Point
&rOfs
, const Size
&rSize
, bool inplaceEditModeChange
);
172 virtual void OuterResizePixel( const Point
&rOfs
, const Size
&rSize
);
173 virtual void SetZoomFactor( const Fraction
&rZoomX
, const Fraction
&rZoomY
);
177 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
181 static SfxViewShell
* GetFirst( bool bOnlyVisible
= true, const std::function
<bool ( const SfxViewShell
* )>& isViewShell
= nullptr );
182 static SfxViewShell
* GetNext( const SfxViewShell
& rPrev
,
183 bool bOnlyVisible
= true,
184 const std::function
<bool ( const SfxViewShell
* )>& isViewShell
= nullptr );
185 static SfxViewShell
* Current();
187 static SfxViewShell
* Get( const css::uno::Reference
< css::frame::XController
>& i_rController
);
189 // Initialize Constructors/Destructors
190 SFX_DECL_INTERFACE(SFX_INTERFACE_SFXVIEWSH
)
193 /// SfxInterface initializer.
194 static void InitInterface_Impl();
198 SfxViewShell( SfxViewFrame
*pFrame
, SfxViewShellFlags nFlags
);
199 virtual ~SfxViewShell() override
;
201 SfxInPlaceClient
* GetIPClient() const;
202 SfxInPlaceClient
* GetUIActiveClient() const;
203 SfxInPlaceClient
* FindIPClient( const css::uno::Reference
< css::embed::XEmbeddedObject
>& xObj
, vcl::Window
*pObjParentWin
) const;
205 virtual ErrCode
DoVerb(long nVerb
);
207 void OutplaceActivated( bool bActive
);
208 virtual void UIActivating( SfxInPlaceClient
* pClient
);
209 virtual void UIDeactivated( SfxInPlaceClient
* pClient
);
211 void JumpToMark( const OUString
& rMark
);
212 void VisAreaChanged();
217 * Initialize is called after the frame has been loaded and the controller
218 * has been set. By the time this is called the document has been fully
221 virtual bool PrepareClose( bool bUI
= true );
222 virtual OUString
GetSelectionText( bool bCompleteWords
= false );
223 virtual bool HasSelection( bool bText
= true ) const;
224 virtual SdrView
* GetDrawView() const;
226 void AddSubShell( SfxShell
& rShell
);
227 void RemoveSubShell( SfxShell
*pShell
=nullptr );
228 SfxShell
* GetSubShell( sal_uInt16
);
230 virtual SfxShell
* GetFormShell() { return nullptr; };
231 virtual const SfxShell
* GetFormShell() const { return nullptr; };
233 // ILibreOfficeKitNotifier
234 virtual void notifyWindow(vcl::LOKWindowId nLOKWindowId
, const OUString
& rAction
, const std::vector
<vcl::LOKPayloadItem
>& rPayload
= std::vector
<vcl::LOKPayloadItem
>()) const override
;
236 // Focus, KeyInput, Cursor
237 virtual void ShowCursor( bool bOn
= true );
238 virtual bool KeyInput( const KeyEvent
&rKeyEvent
);
242 vcl::Window
* GetWindow() const { return pWindow
; }
243 weld::Window
* GetFrameWeld() const;
244 void SetWindow( vcl::Window
*pViewPort
);
245 const SvBorder
& GetBorderPixel() const;
246 void SetBorderPixel( const SvBorder
&rBorder
);
247 void InvalidateBorder();
248 inline SfxViewFrame
* GetViewFrame() const;
250 // Printing Interface
251 virtual SfxPrinter
* GetPrinter( bool bCreate
= false );
252 virtual sal_uInt16
SetPrinter( SfxPrinter
*pNewPrinter
, SfxPrinterChangeFlags nDiffFlags
= SFX_PRINTER_ALL
);
253 virtual bool HasPrintOptionsPage() const;
254 virtual std::unique_ptr
<SfxTabPage
> CreatePrintOptionsPage(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
&rOptions
);
255 Printer
* GetActivePrinter() const;
258 virtual void WriteUserData( OUString
&, bool bBrowse
= false );
259 virtual void ReadUserData( const OUString
&, bool bBrowse
= false );
260 virtual void WriteUserDataSequence ( css::uno::Sequence
< css::beans::PropertyValue
>& );
261 virtual void ReadUserDataSequence ( const css::uno::Sequence
< css::beans::PropertyValue
>& );
262 virtual void QueryObjAreaPixel( tools::Rectangle
& rRect
) const;
264 virtual SfxObjectShell
* GetObjectShell() override
;
266 /** retrieves the document which shall be considered the "current document" when the frame is active
268 The default implementation simply returns the XModel of the associated SfxObjectShell. You will rarely
269 need to overwrite this behavior.
271 virtual css::uno::Reference
< css::frame::XModel
>
272 GetCurrentDocument() const;
274 /** forwards the current document, as returned by ->GetCurrentDocument, to SfxObjectShell::SetWorkingDocument
276 void SetCurrentDocument() const;
278 /** get an XRenderable instance that can render this document
280 virtual css::uno::Reference
< css::view::XRenderable
> GetRenderable();
283 virtual void MarginChanged();
284 const Size
& GetMargin() const;
285 void SetMargin( const Size
& );
286 void DisconnectAllClients();
287 bool NewWindowAllowed() const { return !bNoNewWindow
; }
288 void SetNewWindowAllowed( bool bSet
) { bNoNewWindow
= !bSet
; }
290 void SetController( SfxBaseController
* pController
);
291 css::uno::Reference
<css::frame::XController
> GetController() const;
293 bool TryContextMenuInterception( Menu
& rIn
, const OUString
& rMenuIdentifier
, VclPtr
<Menu
>& rpOut
, css::ui::ContextMenuExecuteEvent aEvent
);
294 bool TryContextMenuInterception( Menu
& rMenu
, const OUString
& rMenuIdentifier
, css::ui::ContextMenuExecuteEvent aEvent
);
296 void ExecPrint( const css::uno::Sequence
< css::beans::PropertyValue
>&, bool, bool );
297 // Like ExecPrint(), but only sets up for printing. Use Printer::ExecutePrintJob() and Printer::FinishPrintJob() afterwards.
298 void StartPrint( const css::uno::Sequence
< css::beans::PropertyValue
>&, bool, bool );
299 const std::shared_ptr
< vcl::PrinterController
>& GetPrinterController() const;
301 void AddRemoveClipboardListener( const css::uno::Reference
< css::datatransfer::clipboard::XClipboardListener
>&, bool );
302 css::uno::Reference
< css::datatransfer::clipboard::XClipboardNotifier
> GetClipboardNotifier() const;
303 bool isContentExtractionLocked();
304 bool isExportLocked();
305 bool isPrintLocked();
307 bool isEditDocLocked();
309 SAL_DLLPRIVATE SfxInPlaceClient
* GetUIActiveIPClient_Impl() const;
310 SAL_DLLPRIVATE
void AddContextMenuInterceptor_Impl( const css::uno::Reference
< css::ui::XContextMenuInterceptor
>& xInterceptor
);
311 SAL_DLLPRIVATE
void RemoveContextMenuInterceptor_Impl( const css::uno::Reference
< css::ui::XContextMenuInterceptor
>& xInterceptor
);
312 SAL_DLLPRIVATE
bool GlobalKeyInput_Impl( const KeyEvent
&rKeyEvent
);
314 SAL_DLLPRIVATE
void NewIPClient_Impl( SfxInPlaceClient
*pIPClient
);
315 SAL_DLLPRIVATE
void IPClientGone_Impl( SfxInPlaceClient
const *pIPClient
);
316 SAL_DLLPRIVATE
void ResetAllClients_Impl( SfxInPlaceClient
const *pIP
);
318 SAL_DLLPRIVATE
void SetPrinter_Impl( VclPtr
<SfxPrinter
>& pNewPrinter
);
320 SAL_DLLPRIVATE
bool HandleNotifyEvent_Impl( NotifyEvent
const & rEvent
);
321 SAL_DLLPRIVATE
bool HasKeyListeners_Impl() const;
322 SAL_DLLPRIVATE
bool HasMouseClickListeners_Impl() const;
324 SAL_DLLPRIVATE SfxBaseController
* GetBaseController_Impl() const;
327 SAL_DLLPRIVATE
void ExecPrint_Impl(SfxRequest
&);
328 SAL_DLLPRIVATE
void ExecMisc_Impl(SfxRequest
&);
329 SAL_DLLPRIVATE
void GetState_Impl(SfxItemSet
&);
330 SAL_DLLPRIVATE
void CheckIPClient_Impl(SfxInPlaceClient
const *, const tools::Rectangle
&);
331 SAL_DLLPRIVATE
void PushSubShells_Impl( bool bPush
=true );
332 SAL_DLLPRIVATE
void PopSubShells_Impl() { PushSubShells_Impl( false ); }
333 SAL_DLLPRIVATE
bool ExecKey_Impl(const KeyEvent
& aKey
);
335 /// The actual per-view implementation of lok::Document::registerCallback().
336 void registerLibreOfficeKitViewCallback(LibreOfficeKitCallback pCallback
, void* pLibreOfficeKitData
);
337 /// Invokes the registered callback, if there are any.
338 void libreOfficeKitViewCallback(int nType
, const char* pPayload
) const override
;
339 /// Set if we are doing tiled searching.
340 void setTiledSearching(bool bTiledSearching
);
341 /// See lok::Document::getPart().
342 virtual int getPart() const;
343 virtual void dumpAsXml(xmlTextWriterPtr pWriter
) const;
344 /// See OutlinerViewShell::GetViewShellId().
345 ViewShellId
GetViewShellId() const override
;
347 /// Set the current DocId, which is used by Mobile LOKit to
348 /// load multiple documents and yet identify the views of each.
349 /// There are events that are fired while creating a new view,
350 /// and if we don't have a DocId, we can't know which other views
351 /// within the same document (if any) should get those events.
352 /// By setting this static value, we are able to set the DocId
353 /// of each SfxViewShell at construction time.
354 static void SetCurrentDocId(ViewShellDocId nId
);
355 /// Get the DocId used by Mobile LOKit to load multiple documents.
356 ViewShellDocId
GetDocId() const override
;
358 /// See OutlinerViewShell::NotifyOtherViews().
359 void NotifyOtherViews(int nType
, const OString
& rKey
, const OString
& rPayload
) override
;
360 /// See OutlinerViewShell::NotifyOtherView().
361 void NotifyOtherView(OutlinerViewShell
* pOtherShell
, int nType
, const OString
& rKey
, const OString
& rPayload
) override
;
362 /// Ask this view to send its cursor position to pViewShell.
363 virtual void NotifyCursor(SfxViewShell
* /*pViewShell*/) const;
364 /// Where a new view can perform some update/initialization soon after the callback has been registered.
365 virtual void afterCallbackRegistered();
366 /// See OutlinerViewShell::GetEditWindowForActiveOLEObj().
367 virtual vcl::Window
* GetEditWindowForActiveOLEObj() const override
;
369 /// Set the LibreOfficeKit language of this view.
370 void SetLOKLanguageTag(const OUString
& rBcp47LanguageTag
);
371 /// Get the LibreOfficeKit language of this view.
372 const LanguageTag
& GetLOKLanguageTag() const { return maLOKLanguageTag
; }
374 /// Set the LibreOfficeKit locale of this view.
375 void SetLOKLocale(const OUString
& rBcp47LanguageTag
);
376 /// Get the LibreOfficeKit locale of this view.
377 const LanguageTag
& GetLOKLocale() const { return maLOKLocale
; }
378 /// Get the form factor of the device where the lok client is running.
379 LOKDeviceFormFactor
GetLOKDeviceFormFactor() const { return maLOKDeviceFormFactor
; }
380 /// Check if the lok client is running on a desktop machine.
381 bool isLOKDesktop() const { return maLOKDeviceFormFactor
== LOKDeviceFormFactor::DESKTOP
; }
382 /// Check if the lok client is running on a tablet.
383 bool isLOKTablet() const { return maLOKDeviceFormFactor
== LOKDeviceFormFactor::TABLET
; }
384 /// Check if the lok client is running on a mobile device.
385 bool isLOKMobilePhone() const { return maLOKDeviceFormFactor
== LOKDeviceFormFactor::MOBILE
; }
389 inline SfxViewFrame
* SfxViewShell::GetViewFrame() const
393 This method returns a pointer to the <SfxViewFrame> Instance in which
394 this SfxViewShell is displayed. This is the instance that was passed
395 on in the constructor. It is guaranteed that the returned pointer
396 points on the valid SfxViewFrame instance.
400 <SfxShell::GetFrame()const>
407 #endif // INCLUDED_SFX2_VIEWSH_HXX
410 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */