LibreOffice Module sc (master)  1
tphfedit.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 
20 #include <scitems.hxx>
21 #include <editeng/eeitem.hxx>
22 
23 #include <editeng/editobj.hxx>
24 #include <editeng/editview.hxx>
25 #include <editeng/adjustitem.hxx>
26 #include <editeng/fhgtitem.hxx>
27 #include <sfx2/objsh.hxx>
28 #include <sfx2/sfxdlg.hxx>
29 
30 #include <tphfedit.hxx>
31 #include <editutil.hxx>
32 #include <global.hxx>
33 #include <patattr.hxx>
34 #include <scresid.hxx>
35 #include <globstr.hrc>
36 #include <strings.hrc>
37 #include <tabvwsh.hxx>
38 #include <prevwsh.hxx>
39 #include <AccessibleEditObject.hxx>
40 
41 #include <scabstdlg.hxx>
42 #include <memory>
43 
44 
45 static void lcl_GetFieldData( ScHeaderFieldData& rData )
46 {
48  if (pShell)
49  {
50  if (auto pTabViewShell = dynamic_cast<ScTabViewShell*>( pShell))
51  pTabViewShell->FillFieldData(rData);
52  else if (auto pPreviewShell = dynamic_cast<ScPreviewShell*>( pShell))
53  pPreviewShell->FillFieldData(rData);
54  }
55 }
56 
57 
59  : eLocation(eLoc)
60  , mbRTL(ScGlobal::IsSystemRTL())
61  , mpDialog(pDialog)
62  , pAcc(nullptr)
63 {
64 }
65 
67 {
69 }
70 
72 {
73  return static_cast<ScHeaderEditEngine*>(m_xEditEngine.get());
74 }
75 
77 {
78  OutputDevice& rDevice = pDrawingArea->get_ref_device();
79  Size aSize = rDevice.LogicToPixel(Size(80, 120), MapMode(MapUnit::MapAppFont));
80  pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
81 
82  WeldEditView::SetDrawingArea(pDrawingArea);
83 
85  lcl_GetFieldData(aData);
86  // fields
87  GetEditEngine()->SetData(aData);
88  if (mbRTL)
89  m_xEditEngine->SetDefaultHorizontalTextDirection(EEHorizontalTextDirection::R2L);
90 
91  if (!pAcc)
92  return;
93 
94  OUString sName;
95  switch (eLocation)
96  {
97  case Left:
98  sName = ScResId(STR_ACC_LEFTAREA_NAME);
99  break;
100  case Center:
101  sName = ScResId(STR_ACC_CENTERAREA_NAME);
102  break;
103  case Right:
104  sName = ScResId(STR_ACC_RIGHTAREA_NAME);
105  break;
106  }
107 
108  pAcc->InitAcc(nullptr, m_xEditView.get(), nullptr, nullptr,
109  sName, pDrawingArea->get_tooltip_text());
110 }
111 
113 {
114  // delete Accessible object before deleting EditEngine and EditView
115  if (pAcc)
116  {
117  css::uno::Reference< css::accessibility::XAccessible > xTemp = xAcc;
118  if (xTemp.is())
119  pAcc->dispose();
120  }
121 }
122 
124 {
125  ScHeaderEditEngine* pEditEngine = GetEditEngine();
126  pEditEngine->SetNumType(eNumType);
127  pEditEngine->UpdateFields();
128 }
129 
130 std::unique_ptr<EditTextObject> ScEditWindow::CreateTextObject()
131 {
132  // reset paragraph attributes
133  // (GetAttribs at creation of format dialog always returns the set items)
134 
135  const SfxItemSet& rEmpty = m_xEditEngine->GetEmptyItemSet();
136  sal_Int32 nParCnt = m_xEditEngine->GetParagraphCount();
137  for (sal_Int32 i=0; i<nParCnt; i++)
138  m_xEditEngine->SetParaAttribs( i, rEmpty );
139 
140  return m_xEditEngine->CreateTextObject();
141 }
142 
143 void ScEditWindow::SetFont( const ScPatternAttr& rPattern )
144 {
145  auto pSet = std::make_unique<SfxItemSet>( m_xEditEngine->GetEmptyItemSet() );
146  rPattern.FillEditItemSet( pSet.get() );
147  // FillEditItemSet adjusts font height to 1/100th mm,
148  // but for header/footer twips is needed, as in the PatternAttr:
152  if (mbRTL)
153  pSet->Put( SvxAdjustItem( SvxAdjust::Right, EE_PARA_JUST ) );
154  GetEditEngine()->SetDefaults( std::move(pSet) );
155 }
156 
157 void ScEditWindow::SetText( const EditTextObject& rTextObject )
158 {
159  GetEditEngine()->SetTextCurrentDefaults(rTextObject);
160 }
161 
163 {
164  m_xEditView->InsertField( rFld );
165 }
166 
168 {
170 
171  SfxViewShell* pViewSh = SfxViewShell::Current();
172 
173  ScTabViewShell* pTabViewSh = dynamic_cast<ScTabViewShell*>( SfxViewShell::Current() );
174 
175  OSL_ENSURE( pDocSh, "Current DocShell not found" );
176  OSL_ENSURE( pViewSh, "Current ViewShell not found" );
177 
178  if ( !(pDocSh && pViewSh) )
179  return;
180 
181  if(pTabViewSh!=nullptr) pTabViewSh->SetInFormatDialog(true);
182 
183  SfxItemSet aSet( m_xEditView->GetAttribs() );
184 
186 
187  ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateScCharDlg(
188  mpDialog, &aSet, pDocSh, false));
189  pDlg->SetText( ScResId( STR_TEXTATTRS ) );
190  if ( pDlg->Execute() == RET_OK )
191  {
192  aSet.ClearItem();
193  aSet.Put( *pDlg->GetOutputItemSet() );
194  m_xEditView->SetAttribs( aSet );
195  }
196 
197  if(pTabViewSh!=nullptr) pTabViewSh->SetInFormatDialog(false);
198 }
199 
200 bool ScEditWindow::KeyInput( const KeyEvent& rKEvt )
201 {
202  sal_uInt16 nKey = rKEvt.GetKeyCode().GetModifier()
203  + rKEvt.GetKeyCode().GetCode();
204 
205  if ( nKey == KEY_TAB || nKey == KEY_TAB + KEY_SHIFT )
206  {
207  return false;
208  }
209  else if ( !m_xEditView->PostKeyEvent( rKEvt ) )
210  {
211  return false;
212  }
213  else if ( !rKEvt.GetKeyCode().IsMod1() && !rKEvt.GetKeyCode().IsShift() &&
214  rKEvt.GetKeyCode().IsMod2() && rKEvt.GetKeyCode().GetCode() == KEY_DOWN )
215  {
216  aObjectSelectLink.Call(*this);
217  return true;
218  }
219  return true;
220 }
221 
223 {
225  m_GetFocusLink(*this);
226 
227  css::uno::Reference< css::accessibility::XAccessible > xTemp = xAcc;
228  if (xTemp.is() && pAcc)
229  {
230  pAcc->GotFocus();
231  }
232  else
233  pAcc = nullptr;
234 
236 }
237 
239 {
240  css::uno::Reference< css::accessibility::XAccessible > xTemp = xAcc;
241  if (xTemp.is() && pAcc)
242  {
243  pAcc->LostFocus();
244  }
245  else
246  pAcc = nullptr;
248 }
249 
251 {
252  bool bHadFocus = HasFocus();
253  bool bRet = WeldEditView::MouseButtonDown(rMEvt);
254  if (!bHadFocus)
255  {
256  assert(HasFocus());
257  GetFocus();
258  }
259  return bRet;
260 }
261 
262 css::uno::Reference< css::accessibility::XAccessible > ScEditWindow::CreateAccessible()
263 {
265  css::uno::Reference< css::accessibility::XAccessible > xAccessible = pAcc;
266  xAcc = xAccessible;
267  return pAcc;
268 }
269 
270 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetDefaults(const SfxItemSet &rDefaults, bool bRememberCopy=true)
Creates a copy of SfxItemSet if bRememberCopy set.
Definition: editutil.cxx:498
virtual void GetFocus() override
Definition: tphfedit.cxx:222
std::function< void(ScEditWindow &)> m_GetFocusLink
Definition: tphfedit.hxx:85
void SetFont(const ScPatternAttr &rPattern)
Definition: tphfedit.cxx:143
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
Definition: tphfedit.cxx:250
sal_uInt16 GetCode() const
void SetNumType(SvxNumType eNumType)
Definition: tphfedit.cxx:123
constexpr TypedWhichId< SvxAdjustItem > EE_PARA_JUST(EE_PARA_START+15)
static SfxObjectShell * Current()
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
ScHeaderEditEngine * GetEditEngine() const override
Definition: tphfedit.cxx:71
constexpr TypedWhichId< SvxFontHeightItem > EE_CHAR_FONTHEIGHT(EE_CHAR_START+2)
static void lcl_GetFieldData(ScHeaderFieldData &rData)
Definition: tphfedit.cxx:45
ScAccessibleEditObject * pAcc
Definition: tphfedit.hxx:82
SvxNumType
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
static SfxViewShell * Current()
Link< ScEditWindow &, void > aObjectSelectLink
Definition: tphfedit.hxx:84
sal_uInt16 GetModifier() const
virtual bool KeyInput(const KeyEvent &rKEvt) override
Definition: tphfedit.cxx:200
virtual OutputDevice & get_ref_device()=0
virtual ~ScEditWindow() override
Definition: tphfedit.cxx:112
ScEditWindowLocation
Definition: tphfedit.hxx:40
const char * sName
void InsertField(const SvxFieldItem &rFld)
Definition: tphfedit.cxx:162
const SfxPoolItem & GetItem(sal_uInt16 nWhichP) const
Definition: patattr.hxx:71
constexpr OUStringLiteral aData
std::unique_ptr< EditTextObject > CreateTextObject()
Definition: tphfedit.cxx:130
constexpr sal_uInt16 KEY_DOWN
weld::Window * mpDialog
Definition: tphfedit.hxx:79
void SetTextCurrentDefaults(const EditTextObject &rTextObject)
SetText and apply defaults already set.
Definition: editutil.cxx:555
constexpr TypedWhichId< SvxFontHeightItem > ATTR_CJK_FONT_HEIGHT(112)
int i
void SetText(const EditTextObject &rTextObject)
Definition: tphfedit.cxx:157
void SetNumType(SvxNumType eNew)
Definition: editutil.hxx:226
css::uno::WeakReference< css::accessibility::XAccessible > xAcc
Definition: tphfedit.hxx:81
tools::Long Width() const
OUString ScResId(const char *pId)
Definition: scdll.cxx:89
std::unique_ptr< EditView > m_xEditView
virtual void GetFocus() override
void SetCharAttributes()
Definition: tphfedit.cxx:167
constexpr TypedWhichId< SvxFontHeightItem > ATTR_CTL_FONT_HEIGHT(117)
ScEditWindow(ScEditWindowLocation eLoc, weld::Window *pParent)
Definition: tphfedit.cxx:58
std::unique_ptr< SfxPoolItem > CloneSetWhich(sal_uInt16 nNewWhich) const
void InitAcc(const css::uno::Reference< css::accessibility::XAccessible > &rxParent, EditView *pEditView, vcl::Window *pWin, ScTextWnd *pTextWnd, const OUString &rName, const OUString &rDescription)
static SfxItemPool * CreatePool()
Point LogicToPixel(const Point &rLogicPt) const
virtual void makeEditEngine() override
Definition: tphfedit.cxx:66
void SetData(const ScHeaderFieldData &rNew)
Definition: editutil.hxx:227
virtual void LoseFocus() override
Definition: tphfedit.cxx:238
const vcl::KeyCode & GetKeyCode() const
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
virtual OUString get_tooltip_text() const =0
bool IsShift() const
constexpr TypedWhichId< SvxFontHeightItem > EE_CHAR_FONTHEIGHT_CTL(EE_CHAR_START+20)
bool UpdateFields()
static SC_DLLPUBLIC ScAbstractDialogFactory * Create()
Definition: scabstdlg.cxx:37
RET_OK
bool IsMod1() const
tools::Long Height() const
std::unique_ptr< EditEngine > m_xEditEngine
virtual void LoseFocus() override
constexpr TypedWhichId< SvxFontHeightItem > EE_CHAR_FONTHEIGHT_CJK(EE_CHAR_START+19)
constexpr sal_uInt16 KEY_SHIFT
virtual void set_size_request(int nWidth, int nHeight)=0
constexpr TypedWhichId< SvxFontHeightItem > ATTR_FONT_HEIGHT(101)
ScEditWindowLocation eLocation
Definition: tphfedit.hxx:77
virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible() override
Definition: tphfedit.cxx:262
constexpr sal_uInt16 KEY_TAB
virtual void SetDrawingArea(weld::DrawingArea *pArea) override
Definition: tphfedit.cxx:76
void FillEditItemSet(SfxItemSet *pEditSet, const SfxItemSet *pCondSet=nullptr) const
Converts all Calc items contained in the own item set to edit engine items and puts them into pEditSe...
Definition: patattr.cxx:776
bool IsMod2() const
void SetInFormatDialog(bool bFlag)
Definition: tabvwsh.hxx:346