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>
21 #include <unotools/viewoptions.hxx>
22 #include <editeng/editids.hrc>
23 #include <editeng/kernitem.hxx>
24 #include <editeng/fhgtitem.hxx>
25 #include <sfx2/app.hxx>
26 #include <sfx2/dispatch.hxx>
27 #include <sfx2/viewfrm.hxx>
28 #include <sfx2/sidebar/Theme.hxx>
29 #include <vcl/button.hxx>
30 #include <vcl/settings.hxx>
31 #include <svl/itempool.hxx>
32 #include <helpids.h>
33 
34 #include <com/sun/star/beans/NamedValue.hpp>
35 
36 #define SPACING_VERY_TIGHT -30
37 #define SPACING_TIGHT -15
38 #define SPACING_NORMAL 0
39 #define SPACING_LOOSE 30
40 #define SPACING_VERY_LOOSE 60
41 
42 namespace svx {
43 
45  : SfxPopupWindow(nId, pParent, "TextCharacterSpacingControl", "svx/ui/textcharacterspacingcontrol.ui")
46 , mnId(nId)
47 , mnCustomKern(0)
48 , mnLastCus(SPACING_NOCUSTOM)
49 {
50  get(maEditKerning, "kerning");
51 
52  get(maNormal, "normal");
53  get(maVeryTight, "very_tight");
54  get(maTight, "tight");
55  get(maVeryLoose, "very_loose");
56  get(maLoose, "loose");
57  get(maLastCustom, "last_custom");
58 
61 
62  Link<Button*,void> aLink = LINK(this, TextCharacterSpacingControl, PredefinedValuesHdl);
63  maNormal->SetClickHdl(aLink);
64  maVeryTight->SetClickHdl(aLink);
65  maTight->SetClickHdl(aLink);
66  maVeryLoose->SetClickHdl(aLink);
67  maLoose->SetClickHdl(aLink);
68  maLastCustom->SetClickHdl(aLink);
69 
70  Initialize();
71 }
72 
74 {
75  disposeOnce();
76 }
77 
79 {
81  {
82  SvtViewOptions aWinOpt(EViewType::Window, SIDEBAR_SPACING_GLOBAL_VALUE);
83  css::uno::Sequence<css::beans::NamedValue> aSeq
84  { { "Spacing", css::uno::makeAny(OUString::number(GetLastCustomValue())) } };
85  aWinOpt.SetUserData(aSeq);
86  }
87 
89 
90  maNormal.clear();
92  maTight.clear();
94  maLoose.clear();
96 
98 }
99 
101 {
102  const SfxPoolItem* pItem;
103  SfxItemState eState = SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState(SID_ATTR_CHAR_KERNING, pItem);
104 
105  const SvxKerningItem* pKerningItem = static_cast<const SvxKerningItem*>(pItem);
106  long nKerning = 0;
107 
108  if(pKerningItem)
109  nKerning = pKerningItem->GetValue();
110 
111  SvtViewOptions aWinOpt(EViewType::Window, SIDEBAR_SPACING_GLOBAL_VALUE);
112  if(aWinOpt.Exists())
113  {
114  css::uno::Sequence<css::beans::NamedValue> aSeq = aWinOpt.GetUserData();
115  OUString aTmp;
116  if(aSeq.hasElements())
117  aSeq[0].Value >>= aTmp;
118 
119  OUString aWinData(aTmp);
120  mnCustomKern = aWinData.toInt32();
122  }
123  else
124  {
126  }
127 
128  if(eState >= SfxItemState::DEFAULT)
129  {
130  MapUnit eUnit = GetCoreMetric();
131  MapUnit eOrgUnit = eUnit;
132  long nBig = maEditKerning->Normalize(nKerning);
133  nKerning = LogicToLogic(nBig, eOrgUnit, MapUnit::MapPoint);
134  maEditKerning->SetValue(nKerning);
135  }
136  else if(SfxItemState::DISABLED == eState)
137  {
138  maEditKerning->SetText(OUString());
140  }
141  else
142  {
143  maEditKerning->SetText(OUString());
145  }
146 }
147 
149 {
150  MapUnit eUnit = GetCoreMetric();
151 
152  long nSign = (nValue < 0) ? -1 : 1;
153  nValue = nValue * nSign;
154 
155  long nVal = LogicToLogic(nValue, MapUnit::MapPoint, eUnit);
156  short nKern = (nValue == 0) ? 0 : static_cast<short>(maEditKerning->Denormalize(nVal));
157 
158  SvxKerningItem aKernItem(nSign * nKern, SID_ATTR_CHAR_KERNING);
159 
160  SfxViewFrame::Current()->GetBindings().GetDispatcher()->ExecuteList(SID_ATTR_CHAR_KERNING,
161  SfxCallMode::RECORD, { &aKernItem });
162 
163  if(bClose)
164  EndPopupMode();
165 }
166 
167 IMPL_LINK(TextCharacterSpacingControl, PredefinedValuesHdl, Button*, pControl, void)
168 {
169  mnLastCus = SPACING_CLOSE_BY_CLICK_ICON;
170 
171  if(pControl == maNormal)
172  {
173  ExecuteCharacterSpacing(SPACING_NORMAL);
174  }
175  else if(pControl == maVeryTight)
176  {
177  ExecuteCharacterSpacing(SPACING_VERY_TIGHT);
178  }
179  else if(pControl == maTight)
180  {
181  ExecuteCharacterSpacing(SPACING_TIGHT);
182  }
183  else if(pControl == maVeryLoose)
184  {
185  ExecuteCharacterSpacing(SPACING_VERY_LOOSE);
186  }
187  else if(pControl == maLoose)
188  {
189  ExecuteCharacterSpacing(SPACING_LOOSE);
190  }
191  else if(pControl == maLastCustom)
192  {
193  ExecuteCharacterSpacing(mnCustomKern);
194  }
195 }
196 
198 {
199  mnLastCus = SPACING_CLOSE_BY_CUS_EDIT;
200  mnCustomKern = static_cast<long>(maEditKerning->GetValue());
201 
202  ExecuteCharacterSpacing(mnCustomKern, false);
203 }
204 
206 {
207  SfxItemPool &rPool = SfxGetpApp()->GetPool();
208  sal_uInt16 nWhich = rPool.GetWhich(mnId);
209  return rPool.GetMetric(nWhich);
210 }
211 
212 } // end of namespace svx
213 
214 /* 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 * >())
css::uno::Sequence< css::beans::NamedValue > GetUserData() const
IMPL_LINK_NOARG(SuggestionDisplay, SelectSuggestionValueSetHdl, SvtValueSet *, void)
void SetClickHdl(const Link< Button *, void > &rLink)
TextCharacterSpacingControl(sal_uInt16 nId, vcl::Window *pParent)
#define SIDEBAR_SPACING_GLOBAL_VALUE
#define SPACING_LOOSE
void SetHelpId(const OString &)
#define HID_SPACING_MB_KERN
Definition: helpids.h:42
SfxApplication * SfxGetpApp()
Value
virtual MapUnit GetMetric(sal_uInt16 nWhich) const
virtual void SetModifyHdl(const Link< Edit &, void > &rLink)
sal_Int16 const nValue
Definition: fmsrccfg.cxx:82
SfxItemPool & GetPool() const
#define SPACING_TIGHT
#define SPACING_CLOSE_BY_CLICK_ICON
void clear()
sal_Int64 Normalize(sal_Int64 nValue) const
SfxBindings & GetBindings()
void SetUserData(const css::uno::Sequence< css::beans::NamedValue > &lData)
#define SPACING_NOCUSTOM
IMPL_LINK(HangulHanjaConversionDialog, ClickByCharacterHdl, weld::ToggleButton &, rBox, void)
SfxItemState QueryState(sal_uInt16 nSID, const SfxPoolItem *&rpState)
sal_Int64 Denormalize(sal_Int64 nValue) const
void Disable(bool bChild=true)
#define SPACING_VERY_LOOSE
static SfxViewFrame * Current()
SfxItemState
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
#define SPACING_CLOSE_BY_CUS_EDIT
sal_uInt16 const mnId
bool Exists() const
Sequence< sal_Int8 > aSeq
virtual void SetValue(sal_Int64 nNewValue, FieldUnit eInUnit)
SfxDispatcher * GetDispatcher() const
MapUnit
virtual void SetText(const OUString &rStr) override
#define SPACING_NORMAL
void ExecuteCharacterSpacing(long nValue, bool bClose=true)
virtual void dispose() override
#define SPACING_VERY_TIGHT