LibreOffice Module sw (master) 1
contentcontrolaliasbutton.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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
11
19#include <vcl/metric.hxx>
20
21#include <HeaderFooterWin.hxx>
22#include <edtwin.hxx>
24#include <swabstdlg.hxx>
25#include <view.hxx>
26#include <viewopt.hxx>
27#include <wrtsh.hxx>
28
29#define TEXT_PADDING 3
30#define BOX_DISTANCE 3
31#define BUTTON_WIDTH 12
32
34 SwContentControl* pContentControl)
35 : SwFrameMenuButtonBase(pEditWin, nullptr, "modules/swriter/ui/contentcontrolaliasbutton.ui",
36 "ContentControlAliasButton")
37 , m_xPushButton(m_xBuilder->weld_button("button"))
38 , m_sLabel(pContentControl->GetAlias())
39{
40 m_xPushButton->set_accessible_name(m_sLabel);
41 m_xPushButton->connect_clicked(LINK(this, SwContentControlAliasButton, ClickHdl));
42 m_xVirDev = m_xPushButton->create_virtual_device();
44}
45
47
49{
50 m_xPushButton.reset();
53}
54
56{
57 // Compute the text size and get the box position & size from it.
58 tools::Rectangle aTextRect;
59 m_xVirDev->GetTextBoundRect(aTextRect, m_sLabel);
60 tools::Rectangle aTextPxRect = m_xVirDev->LogicToPixel(aTextRect);
61 FontMetric aFontMetric = m_xVirDev->GetFontMetric(m_xVirDev->GetFont());
62 Size aBoxSize(aTextPxRect.GetWidth() + BUTTON_WIDTH + TEXT_PADDING * 2,
63 aFontMetric.GetLineHeight() + TEXT_PADDING * 2);
64 Point aBoxPos(aTopLeftPixel.X() + BOX_DISTANCE, aTopLeftPixel.Y() - aBoxSize.Height());
65
66 // Set the position & size of the window.
67 SetPosSizePixel(aBoxPos, aBoxSize);
68 m_xVirDev->SetOutputSizePixel(aBoxSize);
69
71}
72
74{
75 if (m_bReadOnly)
76 {
77 return;
78 }
79
80 SwView& rView = GetEditWin()->GetView();
81 SwWrtShell& rWrtSh = rView.GetWrtShell();
84 pFact->CreateSwContentControlDlg(GetEditWin()->GetFrameWeld(), rWrtSh));
86 aContext.maEndDialogFn = [](sal_Int32) {};
87 pDlg->StartExecuteAsync(aContext);
88}
89
91{
92 if (!m_xVirDev)
93 {
94 return;
95 }
96
97 m_xVirDev->SetMapMode(MapMode(MapUnit::MapPixel));
99 tools::Rectangle aRect(Point(0, 0), m_xVirDev->PixelToLogic(GetSizePixel()));
100
101 // Create button
102 SwFrameButtonPainter::PaintButton(aSeq, aRect, /*bOnTop=*/false);
103
104 // Create the text primitive
106 basegfx::BColor aLineColor = pVOpt->GetHeaderFooterMarkColor().getBColor();
107 basegfx::B2DVector aFontSize;
110 false, false);
111
112 FontMetric aFontMetric = m_xVirDev->GetFontMetric(m_xVirDev->GetFont());
113 double nTextOffsetY = aFontMetric.GetAscent() + TEXT_PADDING;
114 double nTextOffsetX = std::abs(aRect.GetWidth() - m_xVirDev->GetTextWidth(m_sLabel)) / 2.0;
115 Point aTextPos(nTextOffsetX, nTextOffsetY);
116
118 aFontSize.getX(), aFontSize.getY(), static_cast<double>(aTextPos.X()),
119 static_cast<double>(aTextPos.Y()));
120
123 aTextMatrix, m_sLabel, 0, m_sLabel.getLength(), std::vector<double>(), {},
124 std::move(aFontAttr), css::lang::Locale(), aLineColor)));
125
126 // Create the processor and process the primitives
128 std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor
130
131 pProcessor->process(aSeq);
132
133 m_xPushButton->set_custom_button(m_xVirDev.get());
134}
135
136void SwContentControlAliasButton::ShowAll(bool bShow) { Show(bShow); }
137
139{
141 return aRect.Contains(rDocPt);
142}
143
144void SwContentControlAliasButton::SetReadonly(bool bReadonly) { m_bReadOnly = bReadonly; }
145
147{
148 m_sLabel = pContentControl->GetAlias();
149}
150
151/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
basegfx::BColor getBColor() const
tools::Long GetLineHeight() const
tools::Long GetAscent() const
constexpr tools::Long Y() const
constexpr tools::Long X() const
constexpr tools::Long Height() const
virtual VclPtr< VclAbstractDialog > CreateSwContentControlDlg(weld::Window *pParent, SwWrtShell &rSh)=0
static SwAbstractDialogFactory * Create()
Definition: swabstdlg.cxx:36
In case the content control has an alias/title, this widget shows it above the top left corner of the...
std::unique_ptr< weld::Button > m_xPushButton
void SetOffset(Point aTopLeftPixel)
SwContentControlAliasButton(SwEditWin *pEditWin, SwContentControl *pContentControl)
void SetReadonly(bool bReadonly) override
void SetContentControl(SwContentControl *pContentControl)
bool Contains(const Point &rDocPt) const override
Stores the properties of a content control.
const OUString & GetAlias() const
Window class for the Writer edit area, this is the one handling mouse and keyboard events and doing t...
Definition: edtwin.hxx:61
const SwView & GetView() const
Definition: edtwin.hxx:246
static void PaintButton(drawinglayer::primitive2d::Primitive2DContainer &rSeq, const tools::Rectangle &rRect, bool bOnTop)
Class sharing some MenuButton code.
VclPtr< VirtualDevice > m_xVirDev
virtual SwEditWin * GetEditWin() override
virtual void dispose() override
const Color & GetHeaderFooterMarkColor() const
Definition: viewopt.cxx:537
const SwViewOption * GetViewOptions() const
Definition: viewsh.hxx:452
Definition: view.hxx:146
SwWrtShell & GetWrtShell() const
Definition: view.hxx:423
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
void disposeAndClear()
reference_type * get() const
TYPE getX() const
TYPE getY() const
constexpr tools::Long GetWidth() const
bool Contains(const Point &rPOINT) const
virtual Point GetPosPixel() const
void Show(bool bVisible=true, ShowFlags nFlags=ShowFlags::NONE)
virtual Size GetSizePixel() const
virtual void SetPosSizePixel(const Point &rNewPos, const Size &rNewSize)
#define BOX_DISTANCE
IMPL_LINK_NOARG(SwContentControlAliasButton, ClickHdl, weld::Button &, void)
#define TEXT_PADDING
#define BUTTON_WIDTH
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
Definition: dialoghelp.cxx:19
bool m_bReadOnly
Sequence< sal_Int8 > aSeq
B2DHomMatrix createScaleTranslateB2DHomMatrix(double fScaleX, double fScaleY, double fTranslateX, double fTranslateY)
attribute::FontAttribute getFontAttributeFromVclFont(basegfx::B2DVector &o_rSize, const vcl::Font &rFont, bool bRTL, bool bBiDiStrong)
std::unique_ptr< BaseProcessor2D > createProcessor2DFromOutputDevice(OutputDevice &rTargetOutDev, const drawinglayer::geometry::ViewInformation2D &rViewInformation2D)
SwNodeOffset abs(const SwNodeOffset &a)
Definition: nodeoffset.hxx:34
std::function< void(sal_Int32)> maEndDialogFn