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 constexpr sal_uInt16 MINZOOM
= 25;
41 constexpr sal_uInt16 MAXZOOM
= 800;
43 class SmGraphicWindow final
: public InterimItemWindow
46 Point aPixOffset
; // offset to virtual window (pixel)
47 Size aTotPixSz
; // total size of virtual window (pixel)
48 tools::Long nLinePixH
; // size of a line/column (pixel)
49 tools::Long nColumnPixW
;
52 std::unique_ptr
<weld::ScrolledWindow
> mxScrolledWindow
;
53 std::unique_ptr
<SmGraphicWidget
> mxGraphic
;
54 std::unique_ptr
<weld::CustomWeld
> mxGraphicWin
;
56 DECL_LINK(ScrollHdl
, weld::ScrolledWindow
&, void);
59 explicit SmGraphicWindow(SmViewShell
& rShell
);
60 virtual void dispose() override
;
61 virtual ~SmGraphicWindow() override
;
63 virtual bool IsStarMath() const override
{ return true; }
65 void SetTotalSize(const Size
& rNewSize
);
66 Size
GetTotalSize() const;
68 void SetZoom(sal_uInt16 Factor
);
69 sal_uInt16
GetZoom() const { return nZoom
; }
71 void ZoomToFitInWindow();
73 virtual void Resize() override
;
74 void ShowContextMenu(const CommandEvent
& rCEvt
);
76 void SetGraphicMapMode(const MapMode
& rNewMapMode
);
77 MapMode
GetGraphicMapMode() const;
79 SmGraphicWidget
& GetGraphicWidget()
84 const SmGraphicWidget
& GetGraphicWidget() const
90 class SmGraphicWidget final
: public weld::CustomWidgetController
93 bool IsCursorVisible() const
95 return bIsCursorVisible
;
97 void ShowCursor(bool bShow
);
98 bool IsLineVisible() const
100 return bIsLineVisible
;
102 void ShowLine(bool bShow
);
103 const SmNode
* SetCursorPos(sal_uInt16 nRow
, sal_uInt16 nCol
);
105 explicit SmGraphicWidget(SmViewShell
& rShell
, SmGraphicWindow
& rGraphicWindow
);
106 virtual ~SmGraphicWidget() override
;
108 // CustomWidgetController
109 virtual void SetDrawingArea(weld::DrawingArea
* pDrawingArea
) override
;
110 virtual bool MouseButtonDown(const MouseEvent
&rMEvt
) override
;
111 virtual bool MouseMove(const MouseEvent
&rMEvt
) override
;
112 virtual void GetFocus() override
;
113 virtual void LoseFocus() override
;
114 virtual bool KeyInput(const KeyEvent
& rKEvt
) override
;
118 SmViewShell
& GetView() { return mrViewShell
; }
119 SmDocShell
* GetDoc();
120 SmCursor
& GetCursor();
122 const Point
& GetFormulaDrawPos() const
124 return aFormulaDrawPos
;
128 virtual css::uno::Reference
<css::accessibility::XAccessible
> CreateAccessible() override
;
130 SmGraphicAccessible
* GetAccessible_Impl()
132 return mxAccessible
.get();
135 OutputDevice
& GetOutputDevice()
137 assert(GetDrawingArea());
138 return GetDrawingArea()->get_ref_device();
142 void SetIsCursorVisible(bool bVis
);
143 void SetCursor(const SmNode
*pNode
);
144 void SetCursor(const tools::Rectangle
&rRect
);
146 virtual void Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
&) override
;
147 virtual bool Command(const CommandEvent
& rCEvt
) override
;
149 void RepaintViewShellDoc();
150 DECL_LINK(CaretBlinkTimerHdl
, Timer
*, void);
151 void CaretBlinkInit();
152 void CaretBlinkStart();
153 void CaretBlinkStop();
155 SmGraphicWindow
& mrGraphicWindow
;
157 Point aFormulaDrawPos
;
158 // old style editing pieces
159 tools::Rectangle aCursorRect
;
160 bool bIsCursorVisible
;
162 AutoTimer aCaretBlinkTimer
;
163 rtl::Reference
<SmGraphicAccessible
> mxAccessible
;
164 SmViewShell
& mrViewShell
;
165 double mfLastZoomScale
= 0;
166 double mfAccumulatedZoom
= 0;
169 class SmGraphicController final
: public SfxControllerItem
171 SmGraphicWidget
&rGraphic
;
173 SmGraphicController(SmGraphicWidget
&, sal_uInt16
, SfxBindings
& );
174 virtual void StateChangedAtToolBoxControl(sal_uInt16 nSID
,
176 const SfxPoolItem
* pState
) override
;
179 class SmEditController final
: public SfxControllerItem
184 SmEditController(SmEditWindow
&, sal_uInt16
, SfxBindings
& );
186 virtual void StateChangedAtToolBoxControl(sal_uInt16 nSID
, SfxItemState eState
, const SfxPoolItem
* pState
) override
;
189 class SmCmdBoxWindow final
: public SfxDockingWindow
191 std::unique_ptr
<SmEditWindow
, o3tl::default_delete
<SmEditWindow
>> m_xEdit
;
192 SmEditController aController
;
195 Timer aInitialFocusTimer
;
197 DECL_LINK(InitialFocusTimerHdl
, Timer
*, void);
199 virtual Size
CalcDockingSize(SfxChildAlignment eAlign
) override
;
200 virtual SfxChildAlignment
CheckAlignment(SfxChildAlignment eActual
,
201 SfxChildAlignment eWish
) override
;
203 virtual void ToggleFloatingMode() override
;
206 SmCmdBoxWindow(SfxBindings
*pBindings
,
207 SfxChildWindow
*pChildWindow
,
210 virtual ~SmCmdBoxWindow () override
;
211 virtual void dispose() override
;
214 virtual void GetFocus() override
;
215 virtual void StateChanged( StateChangedType nStateChange
) override
;
216 virtual void Command(const CommandEvent
& rCEvt
) override
;
218 Point
WidgetToWindowPos(const weld::Widget
& rWidget
, const Point
& rPos
);
220 void ShowContextMenu(const Point
& rPos
);
222 void AdjustPosition();
224 SmEditWindow
& GetEditWindow()
228 SmViewShell
* GetView();
231 class SmCmdBoxWrapper final
: public SfxChildWindow
233 SFX_DECL_CHILDWINDOW_WITHID(SmCmdBoxWrapper
);
235 SmCmdBoxWrapper(vcl::Window
* pParentWindow
, sal_uInt16 nId
, SfxBindings
* pBindings
, SfxChildWinInfo
* pInfo
);
239 SmEditWindow
& GetEditWindow()
241 return static_cast<SmCmdBoxWindow
*>(GetWindow())->GetEditWindow();
245 namespace sfx2
{ class FileDialogHelper
; }
247 class SmViewShell final
: public SfxViewShell
249 std::unique_ptr
<sfx2::DocumentInserter
> mpDocInserter
;
250 std::unique_ptr
<SfxRequest
> mpRequest
;
251 VclPtr
<SmGraphicWindow
> mxGraphicWindow
;
252 SmGraphicController maGraphicController
;
253 OUString maStatusText
;
256 DECL_LINK( DialogClosedHdl
, sfx2::FileDialogHelper
*, void );
257 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
259 virtual SfxPrinter
*GetPrinter(bool bCreate
= false) override
;
260 virtual sal_uInt16
SetPrinter(SfxPrinter
*pNewPrinter
,
261 SfxPrinterChangeFlags nDiffFlags
= SFX_PRINTER_ALL
) override
;
263 void Insert( SfxMedium
& rMedium
);
264 void InsertFrom(SfxMedium
&rMedium
);
266 virtual bool HasPrintOptionsPage() const override
;
267 virtual std::unique_ptr
<SfxTabPage
> CreatePrintOptionsPage(weld::Container
* pPage
, weld::DialogController
* pController
,
268 const SfxItemSet
&rOptions
) override
;
269 virtual void Deactivate(bool IsMDIActivate
) override
;
270 virtual void Activate(bool IsMDIActivate
) override
;
271 virtual void InnerResizePixel(const Point
&rOfs
, const Size
&rSize
, bool inplaceEditModeChange
) override
;
272 virtual void OuterResizePixel(const Point
&rOfs
, const Size
&rSize
) override
;
273 virtual void QueryObjAreaPixel( tools::Rectangle
& rRect
) const override
;
274 virtual void SetZoomFactor( const Fraction
&rX
, const Fraction
&rY
) override
;
275 virtual std::optional
<OString
> getLOKPayload(int nType
, int nViewId
) const override
;
279 SmViewShell(SfxViewFrame
& rFrame
, SfxViewShell
*pOldSh
);
280 virtual ~SmViewShell() override
;
282 SmDocShell
* GetDoc() const
284 return static_cast<SmDocShell
*>( GetViewFrame().GetObjectShell() );
287 SmEditWindow
* GetEditWindow();
289 SmGraphicWidget
& GetGraphicWidget()
291 return mxGraphicWindow
->GetGraphicWidget();
293 const SmGraphicWidget
& GetGraphicWidget() const
295 return mxGraphicWindow
->GetGraphicWidget();
298 SmGraphicWindow
& GetGraphicWindow()
300 return *mxGraphicWindow
;
303 void SetStatusText(const OUString
& rText
);
305 void ShowError( const SmErrorDesc
*pErrorDesc
);
309 SFX_DECL_INTERFACE(SFX_INTERFACE_SMA_START
+SfxInterfaceId(2))
310 SFX_DECL_VIEWFACTORY(SmViewShell
);
312 void SendCaretToLOK() const;
314 void InvalidateSlots();
317 /// SfxInterface initializer.
318 static void InitInterface_Impl();
321 void Execute( SfxRequest
& rReq
);
322 void GetState(SfxItemSet
&);
324 static bool IsInlineEditEnabled();
326 // Opens the main help page for the Math module
327 void StartMainHelp();
330 void ZoomByItemSet(const SfxItemSet
*pSet
);
333 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */