LibreOffice Module svx (master)  1
ClassificationEditView.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  */
10 
12 
13 #include <svl/itemset.hxx>
14 #include <editeng/wghtitem.hxx>
15 #include <editeng/eeitem.hxx>
16 
18 
19 namespace svx {
20 
22  : EditEngine(pItemPool)
23 {}
24 
25 OUString ClassificationEditEngine::CalcFieldValue(const SvxFieldItem& rField, sal_Int32 /*nPara*/,
26  sal_Int32 /*nPos*/, std::optional<Color>& /*rTxtColor*/, std::optional<Color>& /*rFldColor*/)
27 {
28  OUString aString;
29  const ClassificationField* pClassificationField = dynamic_cast<const ClassificationField*>(rField.GetField());
30  if (pClassificationField)
31  aString = pClassificationField->msDescription;
32  else
33  aString = "Unknown";
34  return aString;
35 }
36 
38 {
39 }
40 
42 {
44 }
45 
47 {
48 }
49 
51 {
52  m_xEditView->InsertField(rFieldItem);
53  m_xEditView->Invalidate();
54 }
55 
57 {
58  ESelection aSelection = m_xEditView->GetSelection();
59 
60  for (sal_Int32 nParagraph = aSelection.nStartPara; nParagraph <= aSelection.nEndPara; ++nParagraph)
61  {
62  FontWeight eFontWeight = WEIGHT_BOLD;
63 
64  std::unique_ptr<SfxItemSet> pSet(new SfxItemSet(m_xEditEngine->GetParaAttribs(nParagraph)));
65  if (const SfxPoolItem* pItem = pSet->GetItem(EE_CHAR_WEIGHT, false))
66  {
67  const SvxWeightItem* pWeightItem = dynamic_cast<const SvxWeightItem*>(pItem);
68  if (pWeightItem && pWeightItem->GetWeight() == WEIGHT_BOLD)
69  eFontWeight = WEIGHT_NORMAL;
70  }
71  SvxWeightItem aWeight(eFontWeight, EE_CHAR_WEIGHT);
72  pSet->Put(aWeight);
73  m_xEditEngine->SetParaAttribs(nParagraph, *pSet);
74  }
75 
76  m_xEditView->Invalidate();
77 }
78 
79 } // end sfx2
80 
81 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 nStartPara
virtual OUString CalcFieldValue(const SvxFieldItem &rField, sal_Int32 nPara, sal_Int32 nPos, std::optional< Color > &rTxtColor, std::optional< Color > &rFldColor) override
WEIGHT_BOLD
virtual void makeEditEngine() override
ClassificationEditEngine(SfxItemPool *pItemPool)
constexpr TypedWhichId< SvxWeightItem > EE_CHAR_WEIGHT(EE_CHAR_START+4)
void InsertField(const SvxFieldItem &rField)
sal_Int32 nEndPara
FontWeight GetWeight() const
WEIGHT_NORMAL
std::unique_ptr< EditView > m_xEditView
virtual ~ClassificationEditView() override
static SfxItemPool * CreatePool()
FontWeight
std::unique_ptr< EditEngine > m_xEditEngine
const SvxFieldData * GetField() const