LibreOffice Module svx (master) 1
TextUnderlineControl.cxx
Go to the documentation of this file.
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 */
20#include <svx/svxids.hrc>
21#include <sfx2/dispatch.hxx>
22#include <sfx2/viewfrm.hxx>
24#include <editeng/editids.hrc>
25#include <editeng/udlnitem.hxx>
26#include <helpids.h>
27
28namespace svx {
29
31 : WeldToolbarPopup(pControl->getFrameInterface(), pParent, "svx/ui/textunderlinecontrol.ui", "TextUnderlineControl")
32 , mxNone(m_xBuilder->weld_button("none"))
33 , mxSingle(m_xBuilder->weld_button("single"))
34 , mxDouble(m_xBuilder->weld_button("double"))
35 , mxBold(m_xBuilder->weld_button("bold"))
36 , mxDot(m_xBuilder->weld_button("dot"))
37 , mxDotBold(m_xBuilder->weld_button("dotbold"))
38 , mxDash(m_xBuilder->weld_button("dash"))
39 , mxDashLong(m_xBuilder->weld_button("dashlong"))
40 , mxDashDot(m_xBuilder->weld_button("dashdot"))
41 , mxDashDotDot(m_xBuilder->weld_button("dashdotdot"))
42 , mxWave(m_xBuilder->weld_button("wave"))
43 , mxMoreOptions(m_xBuilder->weld_button("moreoptions"))
44 , mxControl(pControl)
45{
46 mxMoreOptions->set_help_id(HID_UNDERLINE_BTN);
47
48 Link<weld::Button&,void> aLink = LINK(this, TextUnderlineControl, PBClickHdl);
49 mxNone->connect_clicked(aLink);
50 mxSingle->connect_clicked(aLink);
51 mxDouble->connect_clicked(aLink);
52 mxBold->connect_clicked(aLink);
53 mxDot->connect_clicked(aLink);
54 mxDotBold->connect_clicked(aLink);
55 mxDash->connect_clicked(aLink);
56 mxDashLong->connect_clicked(aLink);
57 mxDashDot->connect_clicked(aLink);
58 mxDashDotDot->connect_clicked(aLink);
59 mxWave->connect_clicked(aLink);
60 mxMoreOptions->connect_clicked(aLink);
61}
62
64{
65 mxNone->grab_focus();
66}
67
69{
70}
71
73{
74 if (&rButton == mxSingle.get())
75 return LINESTYLE_SINGLE;
76 else if (&rButton == mxDouble.get())
77 return LINESTYLE_DOUBLE;
78 else if (&rButton == mxBold.get())
79 return LINESTYLE_BOLD;
80 else if (&rButton == mxDot.get())
81 return LINESTYLE_DOTTED;
82 else if (&rButton == mxDotBold.get())
84 else if (&rButton == mxDash.get())
85 return LINESTYLE_DASH;
86 else if (&rButton == mxDashLong.get())
87 return LINESTYLE_LONGDASH;
88 else if (&rButton == mxDashDot.get())
89 return LINESTYLE_DASHDOT;
90 else if (&rButton == mxDashDotDot.get())
92 else if (&rButton == mxWave.get())
93 return LINESTYLE_WAVE;
94
95 return LINESTYLE_NONE;
96}
97
98namespace {
99
100Color GetUnderlineColor()
101{
102 if (SfxViewFrame* pViewFrm = SfxViewFrame::Current())
103 {
104 const SvxUnderlineItem* pUnderlineItem;
105 pViewFrm->GetBindings().GetDispatcher()->QueryState(SID_ATTR_CHAR_UNDERLINE, pUnderlineItem);
106
107 if (pUnderlineItem)
108 return pUnderlineItem->GetColor();
109 }
110
111 return COL_AUTO;
112}
113
114}
115
116IMPL_LINK(TextUnderlineControl, PBClickHdl, weld::Button&, rButton, void)
117{
118 if (SfxViewFrame* pViewFrm = SfxViewFrame::Current())
119 {
120 if (&rButton == mxMoreOptions.get())
121 {
122 SfxDispatcher* pDisp = pViewFrm->GetBindings().GetDispatcher();
123 pDisp->Execute(SID_CHAR_DLG_EFFECT, SfxCallMode::ASYNCHRON);
124 }
125 else
126 {
127 const FontLineStyle eUnderline = getLineStyle(rButton);
128
129 SvxUnderlineItem aLineItem(eUnderline, SID_ATTR_CHAR_UNDERLINE);
130 aLineItem.SetColor(GetUnderlineColor());
131
132 pViewFrm->GetBindings().GetDispatcher()->ExecuteList(SID_ATTR_CHAR_UNDERLINE,
133 SfxCallMode::RECORD, { &aLineItem });
134 }
135 }
136 mxControl->EndPopupMode();
137}
138
139}
140
141/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxDispatcher * GetDispatcher() const
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
SfxBindings * GetBindings() const
static SAL_WARN_UNUSED_RESULT SfxViewFrame * Current()
const Color & GetColor() const
void SetColor(const Color &rColor)
std::unique_ptr< weld::Button > mxDashDotDot
std::unique_ptr< weld::Button > mxDouble
std::unique_ptr< weld::Button > mxSingle
std::unique_ptr< weld::Button > mxDot
std::unique_ptr< weld::Button > mxBold
FontLineStyle getLineStyle(const weld::Button &rButton) const
std::unique_ptr< weld::Button > mxDash
std::unique_ptr< weld::Button > mxWave
std::unique_ptr< weld::Button > mxDashLong
virtual void GrabFocus() override
std::unique_ptr< weld::Button > mxDashDot
std::unique_ptr< weld::Button > mxDotBold
virtual ~TextUnderlineControl() override
std::unique_ptr< weld::Button > mxNone
TextUnderlineControl(TextUnderlinePopup *pControl, weld::Widget *pParent)
std::unique_ptr< weld::Button > mxMoreOptions
constexpr ::Color COL_AUTO(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
FontLineStyle
LINESTYLE_SINGLE
LINESTYLE_DASHDOTDOT
LINESTYLE_BOLDDOTTED
LINESTYLE_DOUBLE
LINESTYLE_NONE
LINESTYLE_DASH
LINESTYLE_DASHDOT
LINESTYLE_DOTTED
LINESTYLE_WAVE
LINESTYLE_LONGDASH
LINESTYLE_BOLD
constexpr OUStringLiteral HID_UNDERLINE_BTN
Definition: helpids.h:43
IMPL_LINK(HangulHanjaConversionDialog, ClickByCharacterHdl, weld::Toggleable &, rBox, void)