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>
26#include <editeng/colritem.hxx>
27#include <editeng/fhgtitem.hxx>
28#include <sfx2/objsh.hxx>
29#include <sfx2/sfxdlg.hxx>
30
31#include <tphfedit.hxx>
32#include <editutil.hxx>
33#include <global.hxx>
34#include <patattr.hxx>
35#include <scresid.hxx>
36#include <globstr.hrc>
37#include <strings.hrc>
38#include <tabvwsh.hxx>
39#include <prevwsh.hxx>
41
42#include <scabstdlg.hxx>
43#include <memory>
44
45
47{
49 if (pShell)
50 {
51 if (auto pTabViewShell = dynamic_cast<ScTabViewShell*>( pShell))
52 pTabViewShell->FillFieldData(rData);
53 else if (auto pPreviewShell = dynamic_cast<ScPreviewShell*>( pShell))
54 pPreviewShell->FillFieldData(rData);
55 }
56}
57
58
60 : eLocation(eLoc)
61 , mbRTL(ScGlobal::IsSystemRTL())
62 , mpDialog(pDialog)
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
86 // fields
88 if (mbRTL)
89 m_xEditEngine->SetDefaultHorizontalTextDirection(EEHorizontalTextDirection::R2L);
90
92 rDevice.SetBackground(aBgColor);
93 m_xEditView->SetBackgroundColor(aBgColor);
94
95 if (auto tmpAcc = mxAcc.get())
96 {
97 OUString sName;
98 switch (eLocation)
99 {
100 case Left:
101 sName = ScResId(STR_ACC_LEFTAREA_NAME);
102 break;
103 case Center:
104 sName = ScResId(STR_ACC_CENTERAREA_NAME);
105 break;
106 case Right:
107 sName = ScResId(STR_ACC_RIGHTAREA_NAME);
108 break;
109 }
110
111 tmpAcc->InitAcc(nullptr, m_xEditView.get(),
112 sName, pDrawingArea->get_tooltip_text());
113 }
114
115 SetCursor(m_xEditView->GetCursor());
116}
117
119{
120 // delete Accessible object before deleting EditEngine and EditView
121 if (auto tmp = mxAcc.get())
122 tmp->dispose();
123}
124
126{
127 ScHeaderEditEngine* pEditEngine = GetEditEngine();
128 pEditEngine->SetNumType(eNumType);
129 pEditEngine->UpdateFields();
130}
131
132std::unique_ptr<EditTextObject> ScEditWindow::CreateTextObject()
133{
134 // reset paragraph attributes
135 // (GetAttribs at creation of format dialog always returns the set items)
136
137 const SfxItemSet& rEmpty = m_xEditEngine->GetEmptyItemSet();
138 sal_Int32 nParCnt = m_xEditEngine->GetParagraphCount();
139 for (sal_Int32 i=0; i<nParCnt; i++)
140 m_xEditEngine->SetParaAttribs( i, rEmpty );
141
142 return m_xEditEngine->CreateTextObject();
143}
144
146{
147 auto pSet = std::make_unique<SfxItemSet>( m_xEditEngine->GetEmptyItemSet() );
148 rPattern.FillEditItemSet( pSet.get() );
149 // FillEditItemSet adjusts font height to 1/100th mm,
150 // but for header/footer twips is needed, as in the PatternAttr:
154 // font color used, suitable header/footer background color set in ScEditWindow::SetDrawingArea
156 if (aFgColor == COL_AUTO) {
158 aFgColor = aBgColor.IsDark() ? COL_WHITE : COL_BLACK;
159 }
160 pSet->Put(SvxColorItem(aFgColor, EE_CHAR_COLOR));
161 if (mbRTL)
162 pSet->Put( SvxAdjustItem( SvxAdjust::Right, EE_PARA_JUST ) );
163 GetEditEngine()->SetDefaults( std::move(pSet) );
164}
165
166void ScEditWindow::SetText( const EditTextObject& rTextObject )
167{
169}
170
172{
173 m_xEditView->InsertField( rFld );
174}
175
177{
179
181
182 ScTabViewShell* pTabViewSh = dynamic_cast<ScTabViewShell*>( SfxViewShell::Current() );
183
184 OSL_ENSURE( pDocSh, "Current DocShell not found" );
185 OSL_ENSURE( pViewSh, "Current ViewShell not found" );
186
187 if ( !(pDocSh && pViewSh) )
188 return;
189
190 if(pTabViewSh!=nullptr) pTabViewSh->SetInFormatDialog(true);
191
192 SfxItemSet aSet( m_xEditView->GetAttribs() );
193
195
197 mpDialog, &aSet, pDocSh, false));
198 pDlg->SetText( ScResId( STR_TEXTATTRS ) );
199 if ( pDlg->Execute() == RET_OK )
200 {
201 aSet.ClearItem();
202 aSet.Put( *pDlg->GetOutputItemSet() );
203 m_xEditView->SetAttribs( aSet );
204 }
205
206 if(pTabViewSh!=nullptr) pTabViewSh->SetInFormatDialog(false);
207}
208
210{
211 if ( !rKEvt.GetKeyCode().IsMod1() && !rKEvt.GetKeyCode().IsShift() &&
212 rKEvt.GetKeyCode().IsMod2() && rKEvt.GetKeyCode().GetCode() == KEY_DOWN )
213 {
214 aObjectSelectLink.Call(*this);
215 return true;
216 }
217 return WeldEditView::KeyInput(rKEvt);
218}
219
221{
222 assert(m_GetFocusLink);
223 m_GetFocusLink(*this);
224
225 if (auto tmp = mxAcc.get())
226 tmp->GotFocus();
227
229}
230
232{
233 if (auto xTemp = mxAcc.get())
234 xTemp->LostFocus();
235 else
236 mxAcc = nullptr;
238}
239
241{
242 bool bHadFocus = HasFocus();
243 bool bRet = WeldEditView::MouseButtonDown(rMEvt);
244 if (!bHadFocus)
245 {
246 assert(comphelper::LibreOfficeKit::isActive() || HasFocus());
247 GetFocus();
248 }
249 return bRet;
250}
251
252css::uno::Reference< css::accessibility::XAccessible > ScEditWindow::CreateAccessible()
253{
255 mxAcc = tmp.get();
256 return tmp;
257}
258
259/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsDark() const
static rtl::Reference< SfxItemPool > CreatePool()
bool UpdateFields()
const vcl::KeyCode & GetKeyCode() const
SAL_WARN_UNUSED_RESULT Point LogicToPixel(const Point &rLogicPt) const
void SetBackground()
static SC_DLLPUBLIC ScAbstractDialogFactory * Create()
Definition: scabstdlg.cxx:37
virtual VclPtr< SfxAbstractTabDialog > CreateScCharDlg(weld::Window *pParent, const SfxItemSet *pAttr, const SfxObjectShell *pDocShell, bool bDrawText)=0
void SetDefaults(const SfxItemSet &rDefaults, bool bRememberCopy=true)
Creates a copy of SfxItemSet if bRememberCopy set.
Definition: editutil.cxx:564
void SetTextCurrentDefaults(const EditTextObject &rTextObject)
SetText and apply defaults already set.
Definition: editutil.cxx:619
void SetFont(const ScPatternAttr &rPattern)
Definition: tphfedit.cxx:145
virtual bool KeyInput(const KeyEvent &rKEvt) override
Definition: tphfedit.cxx:209
ScHeaderEditEngine * GetEditEngine() const override
Definition: tphfedit.cxx:71
virtual void GetFocus() override
Definition: tphfedit.cxx:220
virtual void SetDrawingArea(weld::DrawingArea *pArea) override
Definition: tphfedit.cxx:76
void SetText(const EditTextObject &rTextObject)
Definition: tphfedit.cxx:166
Link< ScEditWindow &, void > aObjectSelectLink
Definition: tphfedit.hxx:81
void SetNumType(SvxNumType eNumType)
Definition: tphfedit.cxx:125
weld::Window * mpDialog
Definition: tphfedit.hxx:77
std::function< void(ScEditWindow &)> m_GetFocusLink
Definition: tphfedit.hxx:82
unotools::WeakReference< ScAccessibleEditObject > mxAcc
Definition: tphfedit.hxx:79
virtual ~ScEditWindow() override
Definition: tphfedit.cxx:118
void InsertField(const SvxFieldItem &rFld)
Definition: tphfedit.cxx:171
void SetCharAttributes()
Definition: tphfedit.cxx:176
virtual void LoseFocus() override
Definition: tphfedit.cxx:231
virtual void makeEditEngine() override
Definition: tphfedit.cxx:66
std::unique_ptr< EditTextObject > CreateTextObject()
Definition: tphfedit.cxx:132
virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible() override
Definition: tphfedit.cxx:252
ScEditWindowLocation eLocation
Definition: tphfedit.hxx:75
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
Definition: tphfedit.cxx:240
ScEditWindow(ScEditWindowLocation eLoc, weld::Window *pParent)
Definition: tphfedit.cxx:59
void SetData(const ScHeaderFieldData &rNew)
Definition: editutil.hxx:224
void SetNumType(SvxNumType eNew)
Definition: editutil.hxx:223
const SfxPoolItem & GetItem(sal_uInt16 nWhichP) const
Definition: patattr.hxx:73
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:868
void SetInFormatDialog(bool bFlag)
Definition: tabvwsh.hxx:355
sal_uInt16 ClearItem(sal_uInt16 nWhich=0)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
static SAL_WARN_UNUSED_RESULT SfxObjectShell * Current()
std::unique_ptr< SfxPoolItem > CloneSetWhich(sal_uInt16 nNewWhich) const
static SAL_WARN_UNUSED_RESULT SfxViewShell * Current()
constexpr tools::Long Height() const
constexpr tools::Long Width() const
std::unique_ptr< EditEngine > m_xEditEngine
std::unique_ptr< EditView > m_xEditView
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
virtual void GetFocus() override
virtual bool KeyInput(const KeyEvent &rKEvt) override
virtual void LoseFocus() override
ColorConfigValue GetColorValue(ColorConfigEntry eEntry, bool bSmart=true) const
rtl::Reference< interface_type > SAL_CALL get() const
bool IsMod1() const
sal_uInt16 GetCode() const
bool IsShift() const
bool IsMod2() const
virtual OutputDevice & get_ref_device()=0
virtual void set_size_request(int nWidth, int nHeight)=0
virtual OUString get_tooltip_text() const=0
constexpr ::Color COL_WHITE(0xFF, 0xFF, 0xFF)
constexpr ::Color COL_AUTO(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
constexpr ::Color COL_BLACK(0x00, 0x00, 0x00)
constexpr TypedWhichId< SvxAdjustItem > EE_PARA_JUST(EE_PARA_START+16)
constexpr TypedWhichId< SvxFontHeightItem > EE_CHAR_FONTHEIGHT(EE_CHAR_START+2)
constexpr TypedWhichId< SvxColorItem > EE_CHAR_COLOR(EE_CHAR_START+0)
constexpr TypedWhichId< SvxFontHeightItem > EE_CHAR_FONTHEIGHT_CTL(EE_CHAR_START+20)
constexpr TypedWhichId< SvxFontHeightItem > EE_CHAR_FONTHEIGHT_CJK(EE_CHAR_START+19)
OUString sName
constexpr sal_uInt16 KEY_DOWN
constexpr OUStringLiteral aData
int i
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:90
constexpr TypedWhichId< SvxFontHeightItem > ATTR_FONT_HEIGHT(101)
constexpr TypedWhichId< SvxFontHeightItem > ATTR_CJK_FONT_HEIGHT(112)
constexpr TypedWhichId< SvxFontHeightItem > ATTR_CTL_FONT_HEIGHT(117)
SvxNumType
static void lcl_GetFieldData(ScHeaderFieldData &rData)
Definition: tphfedit.cxx:46
ScEditWindowLocation
Definition: tphfedit.hxx:39
@ Left
Definition: tphfedit.hxx:40
@ Center
Definition: tphfedit.hxx:41
@ Right
Definition: tphfedit.hxx:42
RET_OK