LibreOffice Module svx (master) 1
TextCharacterSpacingControl.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 <sfx2/bindings.hxx>
22#include <editeng/editids.hrc>
23#include <editeng/kernitem.hxx>
24#include <sfx2/app.hxx>
25#include <sfx2/dispatch.hxx>
26#include <sfx2/viewfrm.hxx>
28#include <svl/itempool.hxx>
29#include <helpids.h>
30
31#include <com/sun/star/beans/NamedValue.hpp>
32
33#define SPACING_VERY_TIGHT -30
34#define SPACING_TIGHT -15
35#define SPACING_NORMAL 0
36#define SPACING_LOOSE 30
37#define SPACING_VERY_LOOSE 60
38
39namespace svx {
40
42 : WeldToolbarPopup(pControl->getFrameInterface(), pParent, "svx/ui/textcharacterspacingcontrol.ui", "TextCharacterSpacingControl")
43 , mnCustomKern(0)
44 , mnLastCus(SPACING_NOCUSTOM)
45 , mxEditKerning(m_xBuilder->weld_metric_spin_button("kerning", FieldUnit::POINT))
46 , mxTight(m_xBuilder->weld_button("tight"))
47 , mxVeryTight(m_xBuilder->weld_button("very_tight"))
48 , mxNormal(m_xBuilder->weld_button("normal"))
49 , mxLoose(m_xBuilder->weld_button("loose"))
50 , mxVeryLoose(m_xBuilder->weld_button("very_loose"))
51 , mxLastCustom(m_xBuilder->weld_button("last_custom"))
52 , mxControl(pControl)
53{
54 mxEditKerning->connect_value_changed(LINK(this, TextCharacterSpacingControl, KerningModifyHdl));
56
57 Link<weld::Button&,void> aLink = LINK(this, TextCharacterSpacingControl, PredefinedValuesHdl);
58 mxNormal->connect_clicked(aLink);
59 mxVeryTight->connect_clicked(aLink);
60 mxTight->connect_clicked(aLink);
61 mxVeryLoose->connect_clicked(aLink);
62 mxLoose->connect_clicked(aLink);
63 mxLastCustom->connect_clicked(aLink);
64
65 Initialize();
66}
67
69{
70 tools::Long nKerning = mxEditKerning->get_value(FieldUnit::NONE);
71 switch (nKerning)
72 {
74 mxVeryTight->grab_focus();
75 break;
76 case SPACING_TIGHT:
77 mxTight->grab_focus();
78 break;
79 case SPACING_NORMAL:
80 mxNormal->grab_focus();
81 break;
82 case SPACING_LOOSE:
83 mxLoose->grab_focus();
84 break;
86 mxVeryLoose->grab_focus();
87 break;
88 default:
89 if (nKerning == mnCustomKern)
90 mxLastCustom->grab_focus();
91 else
92 mxEditKerning->grab_focus();
93 }
94}
95
97{
99 {
100 SvtViewOptions aWinOpt(EViewType::Window, SIDEBAR_SPACING_GLOBAL_VALUE);
101 css::uno::Sequence<css::beans::NamedValue> aSeq
102 { { "Spacing", css::uno::Any(OUString::number(mnCustomKern)) } };
103 aWinOpt.SetUserData(aSeq);
104 }
105}
106
108{
109 const SvxKerningItem* pKerningItem;
110 SfxItemState eState = SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState(SID_ATTR_CHAR_KERNING, pKerningItem);
111
112 tools::Long nKerning = 0;
113
114 if(pKerningItem)
115 nKerning = pKerningItem->GetValue();
116
117 SvtViewOptions aWinOpt(EViewType::Window, SIDEBAR_SPACING_GLOBAL_VALUE);
118 if(aWinOpt.Exists())
119 {
120 css::uno::Sequence<css::beans::NamedValue> aSeq = aWinOpt.GetUserData();
121 OUString aTmp;
122 if(aSeq.hasElements())
123 aSeq[0].Value >>= aTmp;
124
125 OUString aWinData(aTmp);
126 mnCustomKern = aWinData.toInt32();
128 }
129 else
130 {
132 }
133
134 if(eState >= SfxItemState::DEFAULT)
135 {
136 MapUnit eUnit = GetCoreMetric();
137 MapUnit eOrgUnit = eUnit;
138 tools::Long nBig = mxEditKerning->normalize(nKerning);
139 nKerning = OutputDevice::LogicToLogic(nBig, eOrgUnit, MapUnit::MapPoint);
140 mxEditKerning->set_value(nKerning, FieldUnit::NONE);
141 }
142 else if(SfxItemState::DISABLED == eState)
143 {
144 mxEditKerning->set_text(OUString());
145 mxEditKerning->set_sensitive(false);
146 }
147 else
148 {
149 mxEditKerning->set_text(OUString());
150 mxEditKerning->set_sensitive(false);
151 }
152}
153
155{
156 MapUnit eUnit = GetCoreMetric();
157
158 tools::Long nSign = (nValue < 0) ? -1 : 1;
159 nValue = nValue * nSign;
160
161 tools::Long nVal = OutputDevice::LogicToLogic(nValue, MapUnit::MapPoint, eUnit);
162 short nKern = (nValue == 0) ? 0 : static_cast<short>(mxEditKerning->denormalize(nVal));
163
164 SvxKerningItem aKernItem(nSign * nKern, SID_ATTR_CHAR_KERNING);
165
166 SfxViewFrame::Current()->GetBindings().GetDispatcher()->ExecuteList(SID_ATTR_CHAR_KERNING,
167 SfxCallMode::RECORD, { &aKernItem });
168
169 if (bClose)
170 mxControl->EndPopupMode();
171}
172
173IMPL_LINK(TextCharacterSpacingControl, PredefinedValuesHdl, weld::Button&, rControl, void)
174{
175 mnLastCus = SPACING_CLOSE_BY_CLICK_ICON;
176
177 if (&rControl == mxNormal.get())
178 {
179 ExecuteCharacterSpacing(SPACING_NORMAL);
180 }
181 else if (&rControl == mxVeryTight.get())
182 {
183 ExecuteCharacterSpacing(SPACING_VERY_TIGHT);
184 }
185 else if (&rControl == mxTight.get())
186 {
187 ExecuteCharacterSpacing(SPACING_TIGHT);
188 }
189 else if (&rControl == mxVeryLoose.get())
190 {
191 ExecuteCharacterSpacing(SPACING_VERY_LOOSE);
192 }
193 else if (&rControl == mxLoose.get())
194 {
195 ExecuteCharacterSpacing(SPACING_LOOSE);
196 }
197 else if (&rControl == mxLastCustom.get())
198 {
199 ExecuteCharacterSpacing(mnCustomKern);
200 }
201}
202
204{
205 mnLastCus = SPACING_CLOSE_BY_CUS_EDIT;
206 mnCustomKern = mxEditKerning->get_value(FieldUnit::NONE);
207
208 ExecuteCharacterSpacing(mnCustomKern, false);
209}
210
212{
213 SfxItemPool &rPool = SfxGetpApp()->GetPool();
214 sal_uInt16 nWhich = rPool.GetWhich(SID_ATTR_CHAR_KERNING);
215 return rPool.GetMetric(nWhich);
216}
217
218} // end of namespace svx
219
220/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define SPACING_LOOSE
#define SPACING_VERY_TIGHT
#define SPACING_NORMAL
#define SPACING_VERY_LOOSE
#define SPACING_TIGHT
#define SPACING_CLOSE_BY_CLICK_ICON
#define SPACING_NOCUSTOM
#define SPACING_CLOSE_BY_CUS_EDIT
SfxApplication * SfxGetpApp()
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
SfxDispatcher * GetDispatcher() const
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 * >())
SfxItemState QueryState(sal_uInt16 nSID, const SfxPoolItem *&rpState)
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
virtual MapUnit GetMetric(sal_uInt16 nWhich) const
SfxItemPool & GetPool() const
static SfxViewFrame * Current()
SfxBindings & GetBindings()
void SetUserData(const css::uno::Sequence< css::beans::NamedValue > &lData)
css::uno::Sequence< css::beans::NamedValue > GetUserData() const
bool Exists() const
std::unique_ptr< weld::Button > mxVeryLoose
std::unique_ptr< weld::MetricSpinButton > mxEditKerning
void ExecuteCharacterSpacing(tools::Long nValue, bool bClose=true)
TextCharacterSpacingControl(TextCharacterSpacingPopup *pControl, weld::Widget *pParent)
std::unique_ptr< weld::Button > mxTight
rtl::Reference< TextCharacterSpacingPopup > mxControl
std::unique_ptr< weld::Button > mxLastCustom
std::unique_ptr< weld::Button > mxNormal
std::unique_ptr< weld::Button > mxVeryTight
std::unique_ptr< weld::Button > mxLoose
FieldUnit
sal_Int16 nValue
Definition: fmsrccfg.cxx:81
constexpr OStringLiteral HID_SPACING_MB_KERN
Definition: helpids.h:44
Sequence< sal_Int8 > aSeq
MapUnit
IMPL_LINK(HangulHanjaConversionDialog, ClickByCharacterHdl, weld::Toggleable &, rBox, void)
constexpr OUStringLiteral SIDEBAR_SPACING_GLOBAL_VALUE
IMPL_LINK_NOARG(SuggestionDisplay, SelectSuggestionValueSetHdl, ValueSet *, void)
long Long
SfxItemState