summaryrefslogtreecommitdiffstats
path: root/sw/source/uibase/inc/PageBreakWin.hxx
blob: ee494f78ba04a22d7d5aba9f3c8e5d2d6050eb39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
#ifndef INCLUDED_SW_SOURCE_UIBASE_INC_PAGEBREAKWIN_HXX
#define INCLUDED_SW_SOURCE_UIBASE_INC_PAGEBREAKWIN_HXX

#include "edtwin.hxx"
#include "DashedLine.hxx"
#include "FrameControl.hxx"
#include <vcl/timer.hxx>
#include <optional>

class Menu;
class SwPageFrame;

class SwPageBreakWin;

/** Class for the page break control window.

    This control shows a line indicating a manual page break and a
    button providing a few actions on that page break.
  */
class SwBreakDashedLine final : public SwDashedLine, public ISwFrameControl
{
private:
    VclPtr<SwPageBreakWin> m_pWin;
    VclPtr<SwEditWin> m_pEditWin;
    std::optional<Point> m_xMousePt;
    ::tools::Rectangle m_aBtnRect;
    const SwFrame* m_pFrame;

    SwPageBreakWin& GetOrCreateWin();

public:
    SwBreakDashedLine(SwEditWin* pEditWin, const SwFrame *pFrame);

    virtual ~SwBreakDashedLine() override { disposeOnce(); }
    virtual void dispose() override { m_pWin.disposeAndClear(); m_pEditWin.clear(); SwDashedLine::dispose(); }

    virtual void MouseMove(const MouseEvent& rMEvt) override;

    virtual const SwFrame* GetFrame() override { return m_pFrame; }
    virtual SwEditWin* GetEditWin() override { return m_pEditWin; }
    virtual void ShowAll(bool bShow) override;
    virtual bool Contains(const Point &rDocPt) const override;
    virtual void SetReadonly(bool bReadonly) override;

    void execute(std::u16string_view rIdent);

    virtual FactoryFunction GetUITestFactory() const override;

    void UpdatePosition(const std::optional<Point>& xEvtPt = std::optional<Point>());
    void DestroyWin();
};

class SwPageBreakWin final : public InterimItemWindow
{
    std::unique_ptr<weld::MenuButton> m_xMenuButton;
    VclPtr<SwBreakDashedLine> m_pLine;
    VclPtr<SwEditWin>     m_pEditWin;
    VclPtr<VirtualDevice> m_xVirDev;
    const SwFrame*        m_pFrame;
    bool                  m_bIsAppearing;
    int                   m_nFadeRate;
    int                   m_nDelayAppearing; ///< Before we show the control, let it transparent for a few timer ticks to avoid appearing with every mouse over.
    Timer                 m_aFadeTimer;
    bool                  m_bDestroyed;

public:
    SwPageBreakWin(SwBreakDashedLine* pLine, SwEditWin* pEditWin, const SwFrame *pFrame);
    virtual ~SwPageBreakWin() override;
    virtual void dispose() override;

    void Fade( bool bFadeIn );

    void SetRectanglePixel(const ::tools::Rectangle& rRect);

private:
    DECL_LINK( FadeHandler, Timer *, void );
    /// Hide the button when the menu is toggled closed, e.g by clicking outside
    DECL_LINK(ToggleHdl, weld::Toggleable&, void);
    DECL_LINK(SelectHdl, const OUString&, void);
    void PaintButton();
};

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */