1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <svl/itemset.hxx>
31 TextUnderlineControl::TextUnderlineControl(TextUnderlinePopup
* pControl
, weld::Widget
* pParent
)
32 : WeldToolbarPopup(pControl
->getFrameInterface(), pParent
, "svx/ui/textunderlinecontrol.ui", "TextUnderlineControl")
33 , mxNone(m_xBuilder
->weld_button("none"))
34 , mxSingle(m_xBuilder
->weld_button("single"))
35 , mxDouble(m_xBuilder
->weld_button("double"))
36 , mxBold(m_xBuilder
->weld_button("bold"))
37 , mxDot(m_xBuilder
->weld_button("dot"))
38 , mxDotBold(m_xBuilder
->weld_button("dotbold"))
39 , mxDash(m_xBuilder
->weld_button("dash"))
40 , mxDashLong(m_xBuilder
->weld_button("dashlong"))
41 , mxDashDot(m_xBuilder
->weld_button("dashdot"))
42 , mxDashDotDot(m_xBuilder
->weld_button("dashdotdot"))
43 , mxWave(m_xBuilder
->weld_button("wave"))
44 , mxMoreOptions(m_xBuilder
->weld_button("moreoptions"))
47 mxMoreOptions
->set_help_id(HID_UNDERLINE_BTN
);
49 Link
<weld::Button
&,void> aLink
= LINK(this, TextUnderlineControl
, PBClickHdl
);
50 mxNone
->connect_clicked(aLink
);
51 mxSingle
->connect_clicked(aLink
);
52 mxDouble
->connect_clicked(aLink
);
53 mxBold
->connect_clicked(aLink
);
54 mxDot
->connect_clicked(aLink
);
55 mxDotBold
->connect_clicked(aLink
);
56 mxDash
->connect_clicked(aLink
);
57 mxDashLong
->connect_clicked(aLink
);
58 mxDashDot
->connect_clicked(aLink
);
59 mxDashDotDot
->connect_clicked(aLink
);
60 mxWave
->connect_clicked(aLink
);
61 mxMoreOptions
->connect_clicked(aLink
);
64 void TextUnderlineControl::GrabFocus()
69 TextUnderlineControl::~TextUnderlineControl()
73 FontLineStyle
TextUnderlineControl::getLineStyle(const weld::Button
& rButton
) const
75 if (&rButton
== mxSingle
.get())
76 return LINESTYLE_SINGLE
;
77 else if (&rButton
== mxDouble
.get())
78 return LINESTYLE_DOUBLE
;
79 else if (&rButton
== mxBold
.get())
80 return LINESTYLE_BOLD
;
81 else if (&rButton
== mxDot
.get())
82 return LINESTYLE_DOTTED
;
83 else if (&rButton
== mxDotBold
.get())
84 return LINESTYLE_BOLDDOTTED
;
85 else if (&rButton
== mxDash
.get())
86 return LINESTYLE_DASH
;
87 else if (&rButton
== mxDashLong
.get())
88 return LINESTYLE_LONGDASH
;
89 else if (&rButton
== mxDashDot
.get())
90 return LINESTYLE_DASHDOT
;
91 else if (&rButton
== mxDashDotDot
.get())
92 return LINESTYLE_DASHDOTDOT
;
93 else if (&rButton
== mxWave
.get())
94 return LINESTYLE_WAVE
;
96 return LINESTYLE_NONE
;
101 Color
GetUnderlineColor()
103 if (SfxViewFrame
* pViewFrm
= SfxViewFrame::Current())
105 SfxPoolItemHolder aResult
;
106 pViewFrm
->GetBindings().GetDispatcher()->QueryState(SID_ATTR_CHAR_UNDERLINE
, aResult
);
107 const SvxUnderlineItem
* pUnderlineItem(static_cast<const SvxUnderlineItem
*>(aResult
.getItem()));
110 return pUnderlineItem
->GetColor();
118 IMPL_LINK(TextUnderlineControl
, PBClickHdl
, weld::Button
&, rButton
, void)
120 if (SfxViewFrame
* pViewFrm
= SfxViewFrame::Current())
122 if (&rButton
== mxMoreOptions
.get())
124 SfxDispatcher
* pDisp
= pViewFrm
->GetBindings().GetDispatcher();
125 pDisp
->Execute(SID_CHAR_DLG_EFFECT
, SfxCallMode::ASYNCHRON
);
129 const FontLineStyle eUnderline
= getLineStyle(rButton
);
131 SvxUnderlineItem
aLineItem(eUnderline
, SID_ATTR_CHAR_UNDERLINE
);
132 aLineItem
.SetColor(GetUnderlineColor());
134 pViewFrm
->GetBindings().GetDispatcher()->ExecuteList(SID_ATTR_CHAR_UNDERLINE
,
135 SfxCallMode::RECORD
, { &aLineItem
});
138 mxControl
->EndPopupMode();
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */