Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/starmath/inc/view.hxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
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/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
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 .
18
 */
19
20
#pragma once
21
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"
33
#include "edit.hxx"
34
35
class SmViewShell;
36
class SmGraphicAccessible;
37
class SmGraphicWidget;
38
39
constexpr sal_uInt16 MINZOOM = 25;
40
constexpr sal_uInt16 MAXZOOM = 800;
41
42
class SmGraphicWindow final : public InterimItemWindow
43
{
44
private:
45
    Point aPixOffset; // offset to virtual window (pixel)
46
    Size aTotPixSz; // total size of virtual window (pixel)
47
    tools::Long nLinePixH; // size of a line/column (pixel)
48
    tools::Long nColumnPixW;
49
    sal_uInt16 nZoom;
50
51
    std::unique_ptr<weld::ScrolledWindow> mxScrolledWindow;
52
    std::unique_ptr<SmGraphicWidget> mxGraphic;
53
    std::unique_ptr<weld::CustomWeld> mxGraphicWin;
54
55
    DECL_LINK(ScrollHdl, weld::ScrolledWindow&, void);
56
57
public:
58
    explicit SmGraphicWindow(SmViewShell& rShell);
59
    virtual void dispose() override;
60
    virtual ~SmGraphicWindow() override;
61
62
0
    virtual bool IsStarMath() const override { return true; }
63
64
    void SetTotalSize(const Size& rNewSize);
65
    Size GetTotalSize() const;
66
67
    void SetZoom(sal_uInt16 Factor);
68
0
    sal_uInt16 GetZoom() const { return nZoom; }
69
70
    void ZoomToFitInWindow();
71
72
    virtual void Resize() override;
73
    void ShowContextMenu(const CommandEvent& rCEvt);
74
75
    void SetGraphicMapMode(const MapMode& rNewMapMode);
76
    MapMode GetGraphicMapMode() const;
77
78
    SmGraphicWidget& GetGraphicWidget()
79
0
    {
80
0
        return *mxGraphic;
81
0
    }
82
83
    const SmGraphicWidget& GetGraphicWidget() const
84
0
    {
85
0
        return *mxGraphic;
86
0
    }
87
};
88
89
class SmGraphicWidget final : public weld::CustomWidgetController
90
{
91
public:
92
    bool IsCursorVisible() const
93
0
    {
94
0
        return bIsCursorVisible;
95
0
    }
96
    void ShowCursor(bool bShow);
97
    bool IsLineVisible() const
98
0
    {
99
0
        return bIsLineVisible;
100
0
    }
101
    void ShowLine(bool bShow);
102
    const SmNode * SetCursorPos(sal_uInt16 nRow, sal_uInt16 nCol);
103
104
    explicit SmGraphicWidget(SmViewShell& rShell, SmGraphicWindow& rGraphicWindow);
105
    virtual ~SmGraphicWidget() override;
106
107
    // CustomWidgetController
108
    virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override;
109
    virtual bool MouseButtonDown(const MouseEvent &rMEvt) override;
110
    virtual bool MouseMove(const MouseEvent &rMEvt) override;
111
    virtual void GetFocus() override;
112
    virtual void LoseFocus() override;
113
    virtual bool KeyInput(const KeyEvent& rKEvt) override;
114
115
    void SetTotalSize();
116
117
0
    SmViewShell& GetView() { return mrViewShell; }
118
    SmDocShell* GetDoc();
119
    SmCursor& GetCursor();
120
121
    const Point& GetFormulaDrawPos() const
122
0
    {
123
0
        return aFormulaDrawPos;
124
0
    }
125
126
    // for Accessibility
127
    virtual rtl::Reference<comphelper::OAccessible> CreateAccessible() override;
128
129
    SmGraphicAccessible* GetAccessible_Impl()
130
0
    {
131
0
        return mxAccessible.get();
132
0
    }
133
134
    OutputDevice& GetOutputDevice()
135
0
    {
136
0
        assert(GetDrawingArea());
137
0
        return GetDrawingArea()->get_ref_device();
138
0
    }
139
140
private:
141
    void SetIsCursorVisible(bool bVis);
142
    void SetCursor(const SmNode *pNode);
143
    void SetCursor(const tools::Rectangle &rRect);
144
145
    virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&) override;
146
    virtual bool Command(const CommandEvent& rCEvt) override;
147
148
    void RepaintViewShellDoc();
149
    DECL_LINK(CaretBlinkTimerHdl, Timer *, void);
150
    void CaretBlinkInit();
151
    void CaretBlinkStart();
152
    void CaretBlinkStop();
153
154
    SmGraphicWindow& mrGraphicWindow;
155
156
    Point aFormulaDrawPos;
157
    // old style editing pieces
158
    tools::Rectangle aCursorRect;
159
    bool bIsCursorVisible;
160
    bool bIsLineVisible;
161
    AutoTimer aCaretBlinkTimer;
162
    rtl::Reference<SmGraphicAccessible> mxAccessible;
163
    SmViewShell& mrViewShell;
164
    double mfLastZoomScale = 0;
165
    double mfAccumulatedZoom = 0;
166
};
167
168
class SmGraphicController final : public SfxControllerItem
169
{
170
    SmGraphicWidget &rGraphic;
171
public:
172
    SmGraphicController(SmGraphicWidget &, sal_uInt16, SfxBindings & );
173
    virtual void StateChangedAtToolBoxControl(sal_uInt16             nSID,
174
                              SfxItemState       eState,
175
                              const SfxPoolItem* pState) override;
176
};
177
178
class SmEditController final : public SfxControllerItem
179
{
180
    SmEditWindow &rEdit;
181
182
public:
183
    SmEditController(SmEditWindow &, sal_uInt16, SfxBindings  & );
184
185
    virtual void StateChangedAtToolBoxControl(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState) override;
186
};
187
188
class SmCmdBoxWindow final : public SfxDockingWindow
189
{
190
    std::unique_ptr<SmEditWindow, o3tl::default_delete<SmEditWindow>> m_xEdit;
191
    SmEditController    aController;
192
    bool                bExiting;
193
194
    Timer               aInitialFocusTimer;
195
196
    DECL_LINK(InitialFocusTimerHdl, Timer *, void);
197
198
    virtual Size CalcDockingSize(SfxChildAlignment eAlign) override;
199
    virtual SfxChildAlignment CheckAlignment(SfxChildAlignment eActual,
200
                                             SfxChildAlignment eWish) override;
201
202
    virtual void    ToggleFloatingMode() override;
203
204
public:
205
    SmCmdBoxWindow(SfxBindings    *pBindings,
206
                   SfxChildWindow *pChildWindow,
207
                   Window         *pParent);
208
209
    virtual ~SmCmdBoxWindow () override;
210
    virtual void dispose() override;
211
212
    // Window
213
    virtual void GetFocus() override;
214
    virtual void StateChanged( StateChangedType nStateChange ) override;
215
    virtual void Command(const CommandEvent& rCEvt) override;
216
217
    Point WidgetToWindowPos(const weld::Widget& rWidget, const Point& rPos);
218
219
    void ShowContextMenu(const Point& rPos);
220
221
    void AdjustPosition();
222
223
    SmEditWindow& GetEditWindow()
224
0
    {
225
0
        return *m_xEdit;
226
0
    }
227
    SmViewShell* GetView();
228
};
229
230
class SmCmdBoxWrapper final : public SfxChildWindow
231
{
232
    SFX_DECL_CHILDWINDOW_WITHID(SmCmdBoxWrapper);
233
234
    SmCmdBoxWrapper(vcl::Window* pParentWindow, sal_uInt16 nId, SfxBindings* pBindings, SfxChildWinInfo* pInfo);
235
236
public:
237
238
    SmEditWindow& GetEditWindow()
239
0
    {
240
0
        return static_cast<SmCmdBoxWindow *>(GetWindow())->GetEditWindow();
241
0
    }
242
};
243
244
namespace sfx2 { class FileDialogHelper; }
245
246
class SmViewShell final : public SfxViewShell
247
{
248
    std::unique_ptr<sfx2::DocumentInserter> mpDocInserter;
249
    std::unique_ptr<SfxRequest> mpRequest;
250
    VclPtr<SmGraphicWindow> mxGraphicWindow;
251
    SmGraphicController maGraphicController;
252
    OUString maStatusText;
253
    bool mbPasteState;
254
255
    DECL_LINK( DialogClosedHdl, sfx2::FileDialogHelper*, void );
256
    virtual void            Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
257
258
    virtual SfxPrinter *GetPrinter(bool bCreate = false) override;
259
    virtual sal_uInt16 SetPrinter(SfxPrinter *pNewPrinter,
260
                              SfxPrinterChangeFlags nDiffFlags = SFX_PRINTER_ALL) override;
261
262
    void Insert( SfxMedium& rMedium );
263
    void InsertFrom(SfxMedium &rMedium);
264
265
    virtual bool HasPrintOptionsPage() const override;
266
    virtual std::unique_ptr<SfxTabPage> CreatePrintOptionsPage(weld::Container* pPage, weld::DialogController* pController,
267
                                                               const SfxItemSet &rOptions) override;
268
    virtual void Deactivate(bool IsMDIActivate) override;
269
    virtual void Activate(bool IsMDIActivate) override;
270
    virtual void InnerResizePixel(const Point &rOfs, const Size  &rSize, bool inplaceEditModeChange) override;
271
    virtual void OuterResizePixel(const Point &rOfs, const Size  &rSize) override;
272
    virtual void QueryObjAreaPixel( tools::Rectangle& rRect ) const override;
273
    virtual void SetZoomFactor( const Fraction &rX, const Fraction &rY ) override;
274
    virtual std::optional<OString> getLOKPayload(int nType, int nViewId) const override;
275
276
public:
277
278
    SmViewShell(SfxViewFrame& rFrame, SfxViewShell *pOldSh);
279
    virtual ~SmViewShell() override;
280
281
    SmDocShell * GetDoc() const
282
0
    {
283
0
        return static_cast<SmDocShell *>( GetViewFrame().GetObjectShell() );
284
0
    }
285
286
    SAL_RET_MAYBENULL SmEditWindow * GetEditWindow();
287
288
    SmGraphicWidget& GetGraphicWidget()
289
0
    {
290
0
        return mxGraphicWindow->GetGraphicWidget();
291
0
    }
292
    const SmGraphicWidget& GetGraphicWidget() const
293
0
    {
294
0
        return mxGraphicWindow->GetGraphicWidget();
295
0
    }
296
297
    SmGraphicWindow& GetGraphicWindow()
298
0
    {
299
0
        return *mxGraphicWindow;
300
0
    }
301
302
    void        SetStatusText(const OUString& rText);
303
304
    void        ShowError( const SmErrorDesc *pErrorDesc );
305
    void        NextError();
306
    void        PrevError();
307
308
    SFX_DECL_INTERFACE(SFX_INTERFACE_SMA_START+SfxInterfaceId(2))
309
    SFX_DECL_VIEWFACTORY(SmViewShell);
310
311
    void SendCaretToLOK() const;
312
313
    void InvalidateSlots();
314
315
private:
316
    /// SfxInterface initializer.
317
    static void InitInterface_Impl();
318
319
public:
320
    void Execute( SfxRequest& rReq );
321
    void GetState(SfxItemSet &);
322
323
    static bool IsInlineEditEnabled();
324
325
    // Opens the main help page for the Math module
326
    void StartMainHelp();
327
328
private:
329
    void ZoomByItemSet(const SfxItemSet *pSet);
330
};
331
332
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */