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 {
63 }
64 
66 {
68 }
69 
71 {
72  return static_cast<ScHeaderEditEngine*>(m_xEditEngine.get());
73 }
74 
76 {
77  OutputDevice& rDevice = pDrawingArea->get_ref_device();
78  Size aSize = rDevice.LogicToPixel(Size(80, 120), MapMode(MapUnit::MapAppFont));
79  pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
80 
81  WeldEditView::SetDrawingArea(pDrawingArea);
82 
84  lcl_GetFieldData(aData);
85  // fields
86  GetEditEngine()->SetData(aData);
87  if (mbRTL)
88  m_xEditEngine->SetDefaultHorizontalTextDirection(EEHorizontalTextDirection::R2L);
89 
90  auto tmpAcc = mxAcc.get();
91  if (!tmpAcc)
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  tmpAcc->InitAcc(nullptr, m_xEditView.get(),
109  sName, pDrawingArea->get_tooltip_text());
110 }
111 
113 {
114  // delete Accessible object before deleting EditEngine and EditView
115  if (auto tmp = mxAcc.get())
116  tmp->dispose();
117 }
118 
120 {
121  ScHeaderEditEngine* pEditEngine = GetEditEngine();
122  pEditEngine->SetNumType(eNumType);
123  pEditEngine->UpdateFields();
124 }
125 
126 std::unique_ptr<EditTextObject> ScEditWindow::CreateTextObject()
127 {
128  // reset paragraph attributes
129  // (GetAttribs at creation of format dialog always returns the set items)
130 
131  const SfxItemSet& rEmpty = m_xEditEngine->GetEmptyItemSet();
132  sal_Int32 nParCnt = m_xEditEngine->GetParagraphCount();
133  for (sal_Int32 i=0; i<nParCnt; i++)
134  m_xEditEngine->SetParaAttribs( i, rEmpty );
135 
136  return m_xEditEngine->CreateTextObject();
137 }
138 
139 void ScEditWindow::SetFont( const ScPatternAttr& rPattern )
140 {
141  auto pSet = std::make_unique<SfxItemSet>( m_xEditEngine->GetEmptyItemSet() );
142  rPattern.FillEditItemSet( pSet.get() );
143  // FillEditItemSet adjusts font height to 1/100th mm,
144  // but for header/footer twips is needed, as in the PatternAttr:
148  if (mbRTL)
149  pSet->Put( SvxAdjustItem( SvxAdjust::Right, EE_PARA_JUST ) );
150  GetEditEngine()->SetDefaults( std::move(pSet) );
151 }
152 
153 void ScEditWindow::SetText( const EditTextObject& rTextObject )
154 {
155  GetEditEngine()->SetTextCurrentDefaults(rTextObject);
156 }
157 
159 {
160  m_xEditView->InsertField( rFld );
161 }
162 
164 {
166 
167  SfxViewShell* pViewSh = SfxViewShell::Current();
168 
169  ScTabViewShell* pTabViewSh = dynamic_cast<ScTabViewShell*>( SfxViewShell::Current() );
170 
171  OSL_ENSURE( pDocSh, "Current DocShell not found" );
172  OSL_ENSURE( pViewSh, "Current ViewShell not found" );
173 
174  if ( !(pDocSh && pViewSh) )
175  return;
176 
177  if(pTabViewSh!=nullptr) pTabViewSh->SetInFormatDialog(true);
178 
179  SfxItemSet aSet( m_xEditView->GetAttribs() );
180 
182 
183  ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateScCharDlg(
184  mpDialog, &aSet, pDocSh, false));
185  pDlg->SetText( ScResId( STR_TEXTATTRS ) );
186  if ( pDlg->Execute() == RET_OK )
187  {
188  aSet.ClearItem();
189  aSet.Put( *pDlg->GetOutputItemSet() );
190  m_xEditView->SetAttribs( aSet );
191  }
192 
193  if(pTabViewSh!=nullptr) pTabViewSh->SetInFormatDialog(false);
194 }
195 
196 bool ScEditWindow::KeyInput( const KeyEvent& rKEvt )
197 {
198  if ( !rKEvt.GetKeyCode().IsMod1() && !rKEvt.GetKeyCode().IsShift() &&
199  rKEvt.GetKeyCode().IsMod2() && rKEvt.GetKeyCode().GetCode() == KEY_DOWN )
200  {
201  aObjectSelectLink.Call(*this);
202  return true;
203  }
204  return WeldEditView::KeyInput(rKEvt);
205 }
206 
208 {
209  assert(m_GetFocusLink);
210  m_GetFocusLink(*this);
211 
212  if (auto tmp = mxAcc.get())
213  tmp->GotFocus();
214 
216 }
217 
219 {
220  if (auto xTemp = mxAcc.get())
221  xTemp->LostFocus();
222  else
223  mxAcc = nullptr;
225 }
226 
228 {
229  bool bHadFocus = HasFocus();
230  bool bRet = WeldEditView::MouseButtonDown(rMEvt);
231  if (!bHadFocus)
232  {
233  assert(HasFocus());
234  GetFocus();
235  }
236  return bRet;
237 }
238 
239 css::uno::Reference< css::accessibility::XAccessible > ScEditWindow::CreateAccessible()
240 {
242  mxAcc = tmp.get();
243  return css::uno::Reference<css::accessibility::XAccessible>(static_cast<cppu::OWeakObject*>(tmp.get()), css::uno::UNO_QUERY_THROW);
244 }
245 
246 /* 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:541
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:89
virtual void GetFocus() override
Definition: tphfedit.cxx:207
std::function< void(ScEditWindow &)> m_GetFocusLink
Definition: tphfedit.hxx:83
void SetFont(const ScPatternAttr &rPattern)
Definition: tphfedit.cxx:139
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
Definition: tphfedit.cxx:227
sal_uInt16 GetCode() const
void SetNumType(SvxNumType eNumType)
Definition: tphfedit.cxx:119
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:70
constexpr TypedWhichId< SvxFontHeightItem > EE_CHAR_FONTHEIGHT(EE_CHAR_START+2)
static void lcl_GetFieldData(ScHeaderFieldData &rData)
Definition: tphfedit.cxx:45
SvxNumType
constexpr tools::Long Width() const
static rtl::Reference< SfxItemPool > CreatePool()
static SfxViewShell * Current()
Link< ScEditWindow &, void > aObjectSelectLink
Definition: tphfedit.hxx:82
virtual bool KeyInput(const KeyEvent &rKEvt) override
Definition: tphfedit.cxx:196
virtual OutputDevice & get_ref_device()=0
virtual ~ScEditWindow() override
Definition: tphfedit.cxx:112
ScEditWindowLocation
Definition: tphfedit.hxx:39
const char * sName
void InsertField(const SvxFieldItem &rFld)
Definition: tphfedit.cxx:158
const SfxPoolItem & GetItem(sal_uInt16 nWhichP) const
Definition: patattr.hxx:70
constexpr OUStringLiteral aData
std::unique_ptr< EditTextObject > CreateTextObject()
Definition: tphfedit.cxx:126
constexpr sal_uInt16 KEY_DOWN
weld::Window * mpDialog
Definition: tphfedit.hxx:78
void SetTextCurrentDefaults(const EditTextObject &rTextObject)
SetText and apply defaults already set.
Definition: editutil.cxx:596
constexpr TypedWhichId< SvxFontHeightItem > ATTR_CJK_FONT_HEIGHT(112)
int i
void SetText(const EditTextObject &rTextObject)
Definition: tphfedit.cxx:153
void SetNumType(SvxNumType eNew)
Definition: editutil.hxx:229
std::unique_ptr< EditView > m_xEditView
virtual void GetFocus() override
rtl::Reference< interface_type > SAL_CALL get() const
void SetCharAttributes()
Definition: tphfedit.cxx:163
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
SAL_WARN_UNUSED_RESULT Point LogicToPixel(const Point &rLogicPt) const
virtual void makeEditEngine() override
Definition: tphfedit.cxx:65
void SetData(const ScHeaderFieldData &rNew)
Definition: editutil.hxx:230
virtual void LoseFocus() override
Definition: tphfedit.cxx:218
virtual bool KeyInput(const KeyEvent &rKEvt) override
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()
constexpr tools::Long Height() const
static SC_DLLPUBLIC ScAbstractDialogFactory * Create()
Definition: scabstdlg.cxx:37
RET_OK
bool IsMod1() const
std::unique_ptr< EditEngine > m_xEditEngine
virtual void LoseFocus() override
constexpr TypedWhichId< SvxFontHeightItem > EE_CHAR_FONTHEIGHT_CJK(EE_CHAR_START+19)
virtual void set_size_request(int nWidth, int nHeight)=0
constexpr TypedWhichId< SvxFontHeightItem > ATTR_FONT_HEIGHT(101)
ScEditWindowLocation eLocation
Definition: tphfedit.hxx:76
virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible() override
Definition: tphfedit.cxx:239
virtual void SetDrawingArea(weld::DrawingArea *pArea) override
Definition: tphfedit.cxx:75
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:775
bool IsMod2() const
unotools::WeakReference< ScAccessibleEditObject > mxAcc
Definition: tphfedit.hxx:80
void SetInFormatDialog(bool bFlag)
Definition: tabvwsh.hxx:345