Coverage Report

Created: 2026-10-14 09:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/sidebar/text/TextUnderlineControl.cxx
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
#include "TextUnderlineControl.hxx"
20
#include <svx/svxids.hrc>
21
#include <sfx2/dispatch.hxx>
22
#include <sfx2/viewfrm.hxx>
23
#include <TextUnderlinePopup.hxx>
24
#include <editeng/editids.hrc>
25
#include <editeng/udlnitem.hxx>
26
#include <svl/itemset.hxx>
27
#include <helpids.h>
28
#include <sfx2/tbxctrl.hxx>
29
#include <vcl/weld/Builder.hxx>
30
#include <vcl/weld/Button.hxx>
31
32
#include <com/sun/star/frame/XDispatchProvider.hpp>
33
#include <com/sun/star/frame/XModel3.hpp>
34
35
namespace svx {
36
37
TextUnderlineControl::TextUnderlineControl(TextUnderlinePopup* pControl, weld::Widget* pParent)
38
0
    : WeldToolbarPopup(pControl->getFrameInterface(), pParent, u"svx/ui/textunderlinecontrol.ui"_ustr, u"TextUnderlineControl"_ustr)
39
0
    , mxNone(m_xBuilder->weld_button(u"none"_ustr))
40
0
    , mxSingle(m_xBuilder->weld_button(u"single"_ustr))
41
0
    , mxDouble(m_xBuilder->weld_button(u"double"_ustr))
42
0
    , mxBold(m_xBuilder->weld_button(u"bold"_ustr))
43
0
    , mxDot(m_xBuilder->weld_button(u"dot"_ustr))
44
0
    , mxDotBold(m_xBuilder->weld_button(u"dotbold"_ustr))
45
0
    , mxDash(m_xBuilder->weld_button(u"dash"_ustr))
46
0
    , mxDashLong(m_xBuilder->weld_button(u"dashlong"_ustr))
47
0
    , mxDashDot(m_xBuilder->weld_button(u"dashdot"_ustr))
48
0
    , mxDashDotDot(m_xBuilder->weld_button(u"dashdotdot"_ustr))
49
0
    , mxWave(m_xBuilder->weld_button(u"wave"_ustr))
50
0
    , mxMoreOptions(m_xBuilder->weld_button(u"moreoptions"_ustr))
51
0
    , mxControl(pControl)
52
0
{
53
0
    mxMoreOptions->set_help_id(HID_UNDERLINE_BTN);
54
55
0
    Link<weld::Button&,void> aLink = LINK(this, TextUnderlineControl, PBClickHdl);
56
0
    mxNone->connect_clicked(aLink);
57
0
    mxSingle->connect_clicked(aLink);
58
0
    mxDouble->connect_clicked(aLink);
59
0
    mxBold->connect_clicked(aLink);
60
0
    mxDot->connect_clicked(aLink);
61
0
    mxDotBold->connect_clicked(aLink);
62
0
    mxDash->connect_clicked(aLink);
63
0
    mxDashLong->connect_clicked(aLink);
64
0
    mxDashDot->connect_clicked(aLink);
65
0
    mxDashDotDot->connect_clicked(aLink);
66
0
    mxWave->connect_clicked(aLink);
67
0
    mxMoreOptions->connect_clicked(aLink);
68
0
}
69
70
void TextUnderlineControl::GrabFocus()
71
0
{
72
0
    mxNone->grab_focus();
73
0
}
74
75
TextUnderlineControl::~TextUnderlineControl()
76
0
{
77
0
}
78
79
FontLineStyle TextUnderlineControl::getLineStyle(const weld::Button& rButton) const
80
0
{
81
0
    if (&rButton == mxSingle.get())
82
0
        return LINESTYLE_SINGLE;
83
0
    else if (&rButton == mxDouble.get())
84
0
        return LINESTYLE_DOUBLE;
85
0
    else if (&rButton == mxBold.get())
86
0
        return LINESTYLE_BOLD;
87
0
    else if (&rButton == mxDot.get())
88
0
        return LINESTYLE_DOTTED;
89
0
    else if (&rButton == mxDotBold.get())
90
0
        return LINESTYLE_BOLDDOTTED;
91
0
    else if (&rButton == mxDash.get())
92
0
        return LINESTYLE_DASH;
93
0
    else if (&rButton == mxDashLong.get())
94
0
        return LINESTYLE_LONGDASH;
95
0
    else if (&rButton == mxDashDot.get())
96
0
        return LINESTYLE_DASHDOT;
97
0
    else if (&rButton == mxDashDotDot.get())
98
0
        return LINESTYLE_DASHDOTDOT;
99
0
    else if (&rButton == mxWave.get())
100
0
        return LINESTYLE_WAVE;
101
102
0
    return LINESTYLE_NONE;
103
0
}
104
105
namespace {
106
107
Color GetUnderlineColor()
108
0
{
109
0
    if (SfxViewFrame* pViewFrm = SfxViewFrame::Current())
110
0
    {
111
0
        SfxPoolItemHolder aResult;
112
0
        pViewFrm->GetBindings().GetDispatcher()->QueryState(SID_ATTR_CHAR_UNDERLINE, aResult);
113
0
        const SvxUnderlineItem* pUnderlineItem(static_cast<const SvxUnderlineItem*>(aResult.getItem()));
114
115
0
        if (pUnderlineItem)
116
0
            return pUnderlineItem->GetColor();
117
0
    }
118
119
0
    return COL_AUTO;
120
0
}
121
122
}
123
124
IMPL_LINK(TextUnderlineControl, PBClickHdl, weld::Button&, rButton, void)
125
0
{
126
0
    if (SfxViewFrame* pViewFrm = SfxViewFrame::Current())
127
0
    {
128
0
        if (&rButton == mxMoreOptions.get())
129
0
        {
130
0
            SfxDispatcher* pDisp = pViewFrm->GetBindings().GetDispatcher();
131
0
            pDisp->Execute(SID_CHAR_DLG_EFFECT, SfxCallMode::ASYNCHRON);
132
0
        }
133
0
        else
134
0
        {
135
0
            const FontLineStyle eUnderline = getLineStyle(rButton);
136
137
0
            css::uno::Sequence<css::beans::PropertyValue> aArgs(3);
138
0
            css::beans::PropertyValue* pArgs = aArgs.getArray();
139
0
            pArgs[0].Name = "Underline.LineStyle";
140
0
            pArgs[0].Value <<= sal_Int32(eUnderline);
141
142
0
            Color aColor(GetUnderlineColor());
143
0
            pArgs[1].Name = "Underline.HasColor";
144
0
            pArgs[1].Value <<= (aColor.GetAlpha() == 255);
145
146
0
            pArgs[2].Name = "Underline.Color";
147
0
            pArgs[2].Value <<= aColor;
148
0
            const css::uno::Reference<com::sun::star::frame::XDispatchProvider> xProvider(
149
0
                m_xFrame, css::uno::UNO_QUERY);
150
0
            SfxToolBoxControl::Dispatch(xProvider, u".uno:Underline"_ustr, aArgs);
151
0
        }
152
0
    }
153
0
    mxControl->EndPopupMode();
154
0
}
155
156
}
157
158
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */