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
;
39 class SmElementsDockingWindow
;
41 namespace svtools
{ class ColorConfig
; }
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);
58 void SetGraphicMapMode(const MapMode
& rNewMapMode
);
59 MapMode
GetGraphicMapMode() const;
62 explicit SmGraphicWindow(SmViewShell
& rShell
);
63 virtual void dispose() override
;
64 virtual ~SmGraphicWindow() override
;
66 void SetTotalSize(const Size
& rNewSize
);
67 Size
GetTotalSize() const;
69 void SetZoom(sal_uInt16 Factor
);
70 sal_uInt16
GetZoom() const { return nZoom
; }
72 void ZoomToFitInWindow();
74 virtual void Resize() override
;
75 void ShowContextMenu(const CommandEvent
& rCEvt
);
77 SmGraphicWidget
& GetGraphicWidget()
82 const SmGraphicWidget
& GetGraphicWidget() const
88 class SmGraphicWidget final
: public weld::CustomWidgetController
91 bool IsCursorVisible() const
93 return bIsCursorVisible
;
95 void ShowCursor(bool bShow
);
96 bool IsLineVisible() const
98 return bIsLineVisible
;
100 void ShowLine(bool bShow
);
101 const SmNode
* SetCursorPos(sal_uInt16 nRow
, sal_uInt16 nCol
);
103 explicit SmGraphicWidget(SmViewShell
& rShell
, SmGraphicWindow
& rGraphicWindow
);
104 virtual ~SmGraphicWidget() override
;
106 // CustomWidgetController
107 virtual void SetDrawingArea(weld::DrawingArea
* pDrawingArea
) override
;
108 virtual bool MouseButtonDown(const MouseEvent
&rMEvt
) override
;
109 virtual bool MouseMove(const MouseEvent
&rMEvt
) override
;
110 virtual void GetFocus() override
;
111 virtual void LoseFocus() override
;
115 SmViewShell
& GetView()
120 const Point
& GetFormulaDrawPos() const
122 return aFormulaDrawPos
;
126 virtual css::uno::Reference
<css::accessibility::XAccessible
> CreateAccessible() override
;
128 SmGraphicAccessible
* GetAccessible_Impl()
130 return mxAccessible
.get();
134 void SetIsCursorVisible(bool bVis
)
136 bIsCursorVisible
= bVis
;
138 void SetCursor(const SmNode
*pNode
);
139 void SetCursor(const tools::Rectangle
&rRect
);
140 static bool IsInlineEditEnabled();
142 virtual void Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
&) override
;
143 virtual bool KeyInput(const KeyEvent
& rKEvt
) 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
;
164 class SmGraphicController final
: public SfxControllerItem
166 SmGraphicWidget
&rGraphic
;
168 SmGraphicController(SmGraphicWidget
&, sal_uInt16
, SfxBindings
& );
169 virtual void StateChanged(sal_uInt16 nSID
,
171 const SfxPoolItem
* pState
) override
;
174 class SmEditController final
: public SfxControllerItem
179 SmEditController(SmEditWindow
&, sal_uInt16
, SfxBindings
& );
181 virtual void StateChanged(sal_uInt16 nSID
, SfxItemState eState
, const SfxPoolItem
* pState
) override
;
184 class SmCmdBoxWindow
: public SfxDockingWindow
186 std::unique_ptr
<SmEditWindow
, o3tl::default_delete
<SmEditWindow
>> m_xEdit
;
187 SmEditController aController
;
190 Timer aInitialFocusTimer
;
192 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
: 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
;
263 static Size
GetTextLineSize(OutputDevice
const & rDevice
,
264 const OUString
& rLine
);
265 static Size
GetTextSize(OutputDevice
const & rDevice
,
266 const OUString
& rText
,
267 tools::Long MaxWidth
);
268 static void DrawTextLine(OutputDevice
& rDevice
,
269 const Point
& rPosition
,
270 const OUString
& rLine
);
271 static void DrawText(OutputDevice
& rDevice
,
272 const Point
& rPosition
,
273 const OUString
& rText
,
274 sal_uInt16 MaxWidth
);
276 virtual SfxPrinter
*GetPrinter(bool bCreate
= false) override
;
277 virtual sal_uInt16
SetPrinter(SfxPrinter
*pNewPrinter
,
278 SfxPrinterChangeFlags nDiffFlags
= SFX_PRINTER_ALL
) override
;
280 void Insert( SfxMedium
& rMedium
);
281 void InsertFrom(SfxMedium
&rMedium
);
283 virtual bool HasPrintOptionsPage() const override
;
284 virtual std::unique_ptr
<SfxTabPage
> CreatePrintOptionsPage(weld::Container
* pPage
, weld::DialogController
* pController
,
285 const SfxItemSet
&rOptions
) override
;
286 virtual void Deactivate(bool IsMDIActivate
) override
;
287 virtual void Activate(bool IsMDIActivate
) override
;
288 virtual void InnerResizePixel(const Point
&rOfs
, const Size
&rSize
, bool inplaceEditModeChange
) override
;
289 virtual void OuterResizePixel(const Point
&rOfs
, const Size
&rSize
) override
;
290 virtual void QueryObjAreaPixel( tools::Rectangle
& rRect
) const override
;
291 virtual void SetZoomFactor( const Fraction
&rX
, const Fraction
&rY
) override
;
295 SmViewShell(SfxViewFrame
*pFrame
, SfxViewShell
*pOldSh
);
296 virtual ~SmViewShell() override
;
298 SmDocShell
* GetDoc()
300 return static_cast<SmDocShell
*>( GetViewFrame()->GetObjectShell() );
303 SmEditWindow
* GetEditWindow();
305 SmGraphicWidget
& GetGraphicWidget()
307 return mxGraphicWindow
->GetGraphicWidget();
309 const SmGraphicWidget
& GetGraphicWidget() const
311 return mxGraphicWindow
->GetGraphicWidget();
314 SmGraphicWindow
& GetGraphicWindow()
316 return *mxGraphicWindow
;
319 SmElementsDockingWindow
* GetDockingWindow();
321 void SetStatusText(const OUString
& rText
);
323 void ShowError( const SmErrorDesc
*pErrorDesc
);
327 SFX_DECL_INTERFACE(SFX_INTERFACE_SMA_START
+SfxInterfaceId(2))
328 SFX_DECL_VIEWFACTORY(SmViewShell
);
331 /// SfxInterface initializer.
332 static void InitInterface_Impl();
335 void Execute( SfxRequest
& rReq
);
336 void GetState(SfxItemSet
&);
338 void Impl_Print( OutputDevice
&rOutDev
, const SmPrintUIOptions
&rPrintUIOptions
,
339 tools::Rectangle aOutRect
);
341 /** Set bInsertIntoEditWindow so we know where to insert
343 * This method is called whenever SmGraphicWidget or SmEditWindow gets focus,
344 * so that when text is inserted from catalog or elsewhere we know whether to
345 * insert for the visual editor, or the text editor.
347 void SetInsertIntoEditWindow(bool bEditWindowHadFocusLast
){
348 mbInsertIntoEditWindow
= bEditWindowHadFocusLast
;
350 static bool IsInlineEditEnabled();
353 void ZoomByItemSet(const SfxItemSet
*pSet
);
356 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */