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  */
19 #include "TextUnderlineControl.hxx"
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 
28 namespace 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())
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;
94 
95  return LINESTYLE_NONE;
96 }
97 
98 namespace {
99 
100 Color GetUnderlineColor()
101 {
102  const SfxPoolItem* pItem;
103  SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState(SID_ATTR_CHAR_UNDERLINE, pItem);
104 
105  const SvxUnderlineItem* pUnderlineItem = static_cast<const SvxUnderlineItem*>(pItem);
106 
107  if(pUnderlineItem)
108  return pUnderlineItem->GetColor();
109 
110  return COL_AUTO;
111 }
112 
113 }
114 
115 IMPL_LINK(TextUnderlineControl, PBClickHdl, weld::Button&, rButton, void)
116 {
117  if (&rButton == mxMoreOptions.get())
118  {
120  pDisp->Execute(SID_CHAR_DLG_EFFECT, SfxCallMode::ASYNCHRON);
121  }
122  else
123  {
124  const FontLineStyle eUnderline = getLineStyle(rButton);
125 
126  SvxUnderlineItem aLineItem(eUnderline, SID_ATTR_CHAR_UNDERLINE);
127  aLineItem.SetColor(GetUnderlineColor());
128 
129  SfxViewFrame::Current()->GetBindings().GetDispatcher()->ExecuteList(SID_ATTR_CHAR_UNDERLINE,
130  SfxCallMode::RECORD, { &aLineItem });
131  }
132  mxControl->EndPopupMode();
133 }
134 
135 }
136 
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
std::unique_ptr< weld::Button > mxDashDot
void SetColor(const Color &rCol)
LINESTYLE_BOLD
std::unique_ptr< weld::Button > mxWave
constexpr::Color COL_AUTO(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
TextUnderlineControl(TextUnderlinePopup *pControl, weld::Widget *pParent)
std::unique_ptr< weld::Button > mxSingle
std::unique_ptr< weld::Button > mxDotBold
virtual ~TextUnderlineControl() override
LINESTYLE_DASH
LINESTYLE_DASHDOT
const Color & GetColor() const
std::unique_ptr< weld::Button > mxMoreOptions
LINESTYLE_NONE
std::unique_ptr< weld::Button > mxDot
#define HID_UNDERLINE_BTN
Definition: helpids.h:41
LINESTYLE_WAVE
SfxBindings & GetBindings()
LINESTYLE_SINGLE
std::unique_ptr< weld::Button > mxDash
FontLineStyle getLineStyle(const weld::Button &rButton)
IMPL_LINK(HangulHanjaConversionDialog, ClickByCharacterHdl, weld::ToggleButton &, rBox, void)
SfxItemState QueryState(sal_uInt16 nSID, const SfxPoolItem *&rpState)
std::unique_ptr< weld::Button > mxNone
LINESTYLE_LONGDASH
std::unique_ptr< weld::Button > mxDouble
static SfxViewFrame * Current()
LINESTYLE_DASHDOTDOT
LINESTYLE_DOTTED
std::unique_ptr< weld::Button > mxBold
LINESTYLE_BOLDDOTTED
SfxDispatcher * GetDispatcher() const
virtual void GrabFocus() override
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
LINESTYLE_DOUBLE
FontLineStyle
std::unique_ptr< weld::Button > mxDashDotDot
std::unique_ptr< weld::Button > mxDashLong