Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / sidebar / text / TextUnderlineControl.cxx
blobac65b827198d22ced00115179846ef9b4b16a6fb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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 <helpids.h>
28 namespace svx {
30 TextUnderlineControl::TextUnderlineControl(TextUnderlinePopup* pControl, weld::Widget* pParent)
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)
46 mxMoreOptions->set_help_id(HID_UNDERLINE_BTN);
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);
63 void TextUnderlineControl::GrabFocus()
65 mxNone->grab_focus();
68 TextUnderlineControl::~TextUnderlineControl()
72 FontLineStyle TextUnderlineControl::getLineStyle(const weld::Button& rButton) const
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())
83 return LINESTYLE_BOLDDOTTED;
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())
91 return LINESTYLE_DASHDOTDOT;
92 else if (&rButton == mxWave.get())
93 return LINESTYLE_WAVE;
95 return LINESTYLE_NONE;
98 namespace {
100 Color GetUnderlineColor()
102 if (SfxViewFrame* pViewFrm = SfxViewFrame::Current())
104 const SvxUnderlineItem* pUnderlineItem;
105 pViewFrm->GetBindings().GetDispatcher()->QueryState(SID_ATTR_CHAR_UNDERLINE, pUnderlineItem);
107 if (pUnderlineItem)
108 return pUnderlineItem->GetColor();
111 return COL_AUTO;
116 IMPL_LINK(TextUnderlineControl, PBClickHdl, weld::Button&, rButton, void)
118 if (SfxViewFrame* pViewFrm = SfxViewFrame::Current())
120 if (&rButton == mxMoreOptions.get())
122 SfxDispatcher* pDisp = pViewFrm->GetBindings().GetDispatcher();
123 pDisp->Execute(SID_CHAR_DLG_EFFECT, SfxCallMode::ASYNCHRON);
125 else
127 const FontLineStyle eUnderline = getLineStyle(rButton);
129 SvxUnderlineItem aLineItem(eUnderline, SID_ATTR_CHAR_UNDERLINE);
130 aLineItem.SetColor(GetUnderlineColor());
132 pViewFrm->GetBindings().GetDispatcher()->ExecuteList(SID_ATTR_CHAR_UNDERLINE,
133 SfxCallMode::RECORD, { &aLineItem });
136 mxControl->EndPopupMode();
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */