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