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 .
22 #include <sal/config.h>
23 #include <rtl/ref.hxx>
24 #include <sfx2/docinsert.hxx>
25 #include <sfx2/dockwin.hxx>
26 #include <sfx2/viewsh.hxx>
27 #include <sfx2/ctrlitem.hxx>
28 #include <sfx2/shell.hxx>
29 #include <sfx2/viewfrm.hxx>
30 #include <vcl/InterimItemWindow.hxx>
31 #include <vcl/timer.hxx>
32 #include "document.hxx"
36 class SmPrintUIOptions
;
37 class SmGraphicAccessible
;
38 class SmGraphicWidget
;
40 class SmGraphicWindow final
: public InterimItemWindow
43 Point aPixOffset
; // offset to virtual window (pixel)
44 Size aTotPixSz
; // total size of virtual window (pixel)
45 tools::Long nLinePixH
; // size of a line/column (pixel)
46 tools::Long nColumnPixW
;
49 std::unique_ptr
<weld::ScrolledWindow
> mxScrolledWindow
;
50 std::unique_ptr
<SmGraphicWidget
> mxGraphic
;
51 std::unique_ptr
<weld::CustomWeld
> mxGraphicWin
;
53 DECL_LINK(ScrollHdl
, weld::ScrolledWindow
&, void);
56 explicit SmGraphicWindow(SmViewShell
& rShell
);
57 virtual void dispose() override
;
58 virtual ~SmGraphicWindow() override
;
60 virtual bool IsStarMath() const override
{ return true; }
62 void SetTotalSize(const Size
& rNewSize
);
63 Size
GetTotalSize() const;
65 void SetZoom(sal_uInt16 Factor
);
66 sal_uInt16
GetZoom() const { return nZoom
; }
68 void ZoomToFitInWindow();
70 virtual void Resize() override
;
71 void ShowContextMenu(const CommandEvent
& rCEvt
);
73 void SetGraphicMapMode(const MapMode
& rNewMapMode
);
74 MapMode
GetGraphicMapMode() const;
76 SmGraphicWidget
& GetGraphicWidget()
81 const SmGraphicWidget
& GetGraphicWidget() const
87 class SmGraphicWidget final
: public weld::CustomWidgetController
90 bool IsCursorVisible() const
92 return bIsCursorVisible
;
94 void ShowCursor(bool bShow
);
95 bool IsLineVisible() const
97 return bIsLineVisible
;
99 void ShowLine(bool bShow
);
100 const SmNode
* SetCursorPos(sal_uInt16 nRow
, sal_uInt16 nCol
);
102 explicit SmGraphicWidget(SmViewShell
& rShell
, SmGraphicWindow
& rGraphicWindow
);
103 virtual ~SmGraphicWidget() override
;
105 // CustomWidgetController
106 virtual void SetDrawingArea(weld::DrawingArea
* pDrawingArea
) override
;
107 virtual bool MouseButtonDown(const MouseEvent
&rMEvt
) override
;
108 virtual bool MouseMove(const MouseEvent
&rMEvt
) override
;
109 virtual void GetFocus() override
;
110 virtual void LoseFocus() override
;
111 virtual bool KeyInput(const KeyEvent
& rKEvt
) override
;
115 SmViewShell
& GetView() { return mrViewShell
; }
116 SmDocShell
* GetDoc();
117 SmCursor
& GetCursor();
119 const Point
& GetFormulaDrawPos() const
121 return aFormulaDrawPos
;
125 virtual css::uno::Reference
<css::accessibility::XAccessible
> CreateAccessible() override
;
127 SmGraphicAccessible
* GetAccessible_Impl()
129 return mxAccessible
.get();
132 OutputDevice
& GetOutputDevice()
134 assert(GetDrawingArea());
135 return GetDrawingArea()->get_ref_device();
139 void SetIsCursorVisible(bool bVis
);
140 void SetCursor(const SmNode
*pNode
);
141 void SetCursor(const tools::Rectangle
&rRect
);
143 virtual void Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
&) override
;
144 virtual bool Command(const CommandEvent
& rCEvt
) override
;
146 void RepaintViewShellDoc();
147 DECL_LINK(CaretBlinkTimerHdl
, Timer
*, void);
148 void CaretBlinkInit();
149 void CaretBlinkStart();
150 void CaretBlinkStop();
152 SmGraphicWindow
& mrGraphicWindow
;
154 Point aFormulaDrawPos
;
155 // old style editing pieces
156 tools::Rectangle aCursorRect
;
157 bool bIsCursorVisible
;
159 AutoTimer aCaretBlinkTimer
;
160 rtl::Reference
<SmGraphicAccessible
> mxAccessible
;
161 SmViewShell
& mrViewShell
;
162 double mfLastZoomScale
= 0;
163 double mfAccumulatedZoom
= 0;
166 class SmGraphicController final
: public SfxControllerItem
168 SmGraphicWidget
&rGraphic
;
170 SmGraphicController(SmGraphicWidget
&, sal_uInt16
, SfxBindings
& );
171 virtual void StateChangedAtToolBoxControl(sal_uInt16 nSID
,
173 const SfxPoolItem
* pState
) override
;
176 class SmEditController final
: public SfxControllerItem
181 SmEditController(SmEditWindow
&, sal_uInt16
, SfxBindings
& );
183 virtual void StateChangedAtToolBoxControl(sal_uInt16 nSID
, SfxItemState eState
, const SfxPoolItem
* pState
) override
;
186 class SmCmdBoxWindow final
: public SfxDockingWindow
188 std::unique_ptr
<SmEditWindow
, o3tl::default_delete
<SmEditWindow
>> m_xEdit
;
189 SmEditController aController
;
192 Timer aInitialFocusTimer
;
194 DECL_LINK(InitialFocusTimerHdl
, Timer
*, void);
196 virtual Size
CalcDockingSize(SfxChildAlignment eAlign
) override
;
197 virtual SfxChildAlignment
CheckAlignment(SfxChildAlignment eActual
,
198 SfxChildAlignment eWish
) override
;
200 virtual void ToggleFloatingMode() override
;
203 SmCmdBoxWindow(SfxBindings
*pBindings
,
204 SfxChildWindow
*pChildWindow
,
207 virtual ~SmCmdBoxWindow () override
;
208 virtual void dispose() override
;
211 virtual void GetFocus() override
;
212 virtual void StateChanged( StateChangedType nStateChange
) override
;
213 virtual void Command(const CommandEvent
& rCEvt
) override
;
215 Point
WidgetToWindowPos(const weld::Widget
& rWidget
, const Point
& rPos
);
217 void ShowContextMenu(const Point
& rPos
);
219 void AdjustPosition();
221 SmEditWindow
& GetEditWindow()
225 SmViewShell
* GetView();
228 class SmCmdBoxWrapper final
: public SfxChildWindow
230 SFX_DECL_CHILDWINDOW_WITHID(SmCmdBoxWrapper
);
232 SmCmdBoxWrapper(vcl::Window
* pParentWindow
, sal_uInt16 nId
, SfxBindings
* pBindings
, SfxChildWinInfo
* pInfo
);
236 SmEditWindow
& GetEditWindow()
238 return static_cast<SmCmdBoxWindow
*>(GetWindow())->GetEditWindow();
242 namespace sfx2
{ class FileDialogHelper
; }
244 class SmViewShell final
: public SfxViewShell
246 std::unique_ptr
<sfx2::DocumentInserter
> mpDocInserter
;
247 std::unique_ptr
<SfxRequest
> mpRequest
;
248 VclPtr
<SmGraphicWindow
> mxGraphicWindow
;
249 SmGraphicController maGraphicController
;
250 OUString maStatusText
;
252 /** Used to determine whether insertions using SID_INSERTSPECIAL and SID_INSERTCOMMANDTEXT
253 * should be inserted into SmEditWindow or directly into the SmDocShell as done if the
254 * visual editor was last to have focus.
256 bool mbInsertIntoEditWindow
;
258 DECL_LINK( DialogClosedHdl
, sfx2::FileDialogHelper
*, void );
259 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
261 static Size
GetTextLineSize(OutputDevice
const & rDevice
,
262 const OUString
& rLine
);
263 static Size
GetTextSize(OutputDevice
const & rDevice
,
264 std::u16string_view rText
,
265 tools::Long MaxWidth
);
266 static void DrawTextLine(OutputDevice
& rDevice
,
267 const Point
& rPosition
,
268 const OUString
& rLine
);
269 static void DrawText(OutputDevice
& rDevice
,
270 const Point
& rPosition
,
271 std::u16string_view rText
,
272 sal_uInt16 MaxWidth
);
274 virtual SfxPrinter
*GetPrinter(bool bCreate
= false) override
;
275 virtual sal_uInt16
SetPrinter(SfxPrinter
*pNewPrinter
,
276 SfxPrinterChangeFlags nDiffFlags
= SFX_PRINTER_ALL
) override
;
278 void Insert( SfxMedium
& rMedium
);
279 void InsertFrom(SfxMedium
&rMedium
);
281 virtual bool HasPrintOptionsPage() const override
;
282 virtual std::unique_ptr
<SfxTabPage
> CreatePrintOptionsPage(weld::Container
* pPage
, weld::DialogController
* pController
,
283 const SfxItemSet
&rOptions
) override
;
284 virtual void Deactivate(bool IsMDIActivate
) override
;
285 virtual void Activate(bool IsMDIActivate
) override
;
286 virtual void InnerResizePixel(const Point
&rOfs
, const Size
&rSize
, bool inplaceEditModeChange
) override
;
287 virtual void OuterResizePixel(const Point
&rOfs
, const Size
&rSize
) override
;
288 virtual void QueryObjAreaPixel( tools::Rectangle
& rRect
) const override
;
289 virtual void SetZoomFactor( const Fraction
&rX
, const Fraction
&rY
) override
;
290 virtual std::optional
<OString
> getLOKPayload(int nType
, int nViewId
) const override
;
294 SmViewShell(SfxViewFrame
& rFrame
, SfxViewShell
*pOldSh
);
295 virtual ~SmViewShell() override
;
297 SmDocShell
* GetDoc() const
299 return static_cast<SmDocShell
*>( GetViewFrame().GetObjectShell() );
302 SmEditWindow
* GetEditWindow();
304 SmGraphicWidget
& GetGraphicWidget()
306 return mxGraphicWindow
->GetGraphicWidget();
308 const SmGraphicWidget
& GetGraphicWidget() const
310 return mxGraphicWindow
->GetGraphicWidget();
313 SmGraphicWindow
& GetGraphicWindow()
315 return *mxGraphicWindow
;
318 void SetStatusText(const OUString
& rText
);
320 void ShowError( const SmErrorDesc
*pErrorDesc
);
324 SFX_DECL_INTERFACE(SFX_INTERFACE_SMA_START
+SfxInterfaceId(2))
325 SFX_DECL_VIEWFACTORY(SmViewShell
);
327 void SendCaretToLOK() const;
330 /// SfxInterface initializer.
331 static void InitInterface_Impl();
334 void Execute( SfxRequest
& rReq
);
335 void GetState(SfxItemSet
&);
337 void Impl_Print( OutputDevice
&rOutDev
, const SmPrintUIOptions
&rPrintUIOptions
,
338 tools::Rectangle aOutRect
);
340 /** Set bInsertIntoEditWindow so we know where to insert
342 * This method is called whenever SmGraphicWidget or SmEditWindow gets focus,
343 * so that when text is inserted from catalog or elsewhere we know whether to
344 * insert for the visual editor, or the text editor.
346 void SetInsertIntoEditWindow(bool bEditWindowHadFocusLast
){
347 mbInsertIntoEditWindow
= bEditWindowHadFocusLast
;
349 static bool IsInlineEditEnabled();
352 void ZoomByItemSet(const SfxItemSet
*pSet
);
355 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */