1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <scitems.hxx>
#include <editeng/eeitem.hxx>
#include <editeng/editobj.hxx>
#include <editeng/editstat.hxx>
#include <editeng/editview.hxx>
#include <editeng/adjustitem.hxx>
#include <editeng/fhgtitem.hxx>
#include <sfx2/objsh.hxx>
#include <sfx2/sfxdlg.hxx>
#include <vcl/cursor.hxx>
#include <vcl/svapp.hxx>
#include <vcl/settings.hxx>
#include <tphfedit.hxx>
#include <editutil.hxx>
#include <global.hxx>
#include <patattr.hxx>
#include <scresid.hxx>
#include <globstr.hrc>
#include <strings.hrc>
#include <tabvwsh.hxx>
#include <prevwsh.hxx>
#include <AccessibleEditObject.hxx>
#include <scabstdlg.hxx>
#include <memory>
static void lcl_GetFieldData( ScHeaderFieldData& rData )
{
SfxViewShell* pShell = SfxViewShell::Current();
if (pShell)
{
if (dynamic_cast<const ScTabViewShell*>( pShell) != nullptr)
static_cast<ScTabViewShell*>(pShell)->FillFieldData(rData);
else if (dynamic_cast<const ScPreviewShell*>( pShell) != nullptr)
static_cast<ScPreviewShell*>(pShell)->FillFieldData(rData);
}
}
ScEditWindow::ScEditWindow(ScEditWindowLocation eLoc, weld::Window* pDialog)
: eLocation(eLoc)
, mbRTL(ScGlobal::IsSystemRTL())
, mpDialog(pDialog)
, pAcc(nullptr)
{
}
void ScEditWindow::makeEditEngine()
{
m_xEditEngine.reset(new ScHeaderEditEngine(EditEngine::CreatePool()));
}
ScHeaderEditEngine* ScEditWindow::GetEditEngine() const
{
return static_cast<ScHeaderEditEngine*>(m_xEditEngine.get());
}
void ScEditWindow::SetDrawingArea(weld::DrawingArea* pDrawingArea)
{
OutputDevice& rDevice = pDrawingArea->get_ref_device();
Size aSize = rDevice.LogicToPixel(Size(80, 120), MapMode(MapUnit::MapAppFont));
pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
WeldEditView::SetDrawingArea(pDrawingArea);
ScHeaderFieldData aData;
lcl_GetFieldData(aData);
// fields
GetEditEngine()->SetData(aData);
if (mbRTL)
m_xEditEngine->SetDefaultHorizontalTextDirection(EEHorizontalTextDirection::R2L);
if (pAcc)
{
OUString sName;
switch (eLocation)
{
case Left:
sName = ScResId(STR_ACC_LEFTAREA_NAME);
break;
case Center:
sName = ScResId(STR_ACC_CENTERAREA_NAME);
break;
case Right:
sName = ScResId(STR_ACC_RIGHTAREA_NAME);
break;
}
pAcc->InitAcc(nullptr, m_xEditView.get(), nullptr,
sName, pDrawingArea->get_tooltip_text());
}
}
ScEditWindow::~ScEditWindow()
{
// delete Accessible object before deleting EditEngine and EditView
if (pAcc)
{
css::uno::Reference< css::accessibility::XAccessible > xTemp = xAcc;
if (xTemp.is())
pAcc->dispose();
}
}
void ScEditWindow::SetNumType(SvxNumType eNumType)
{
ScHeaderEditEngine* pEditEngine = GetEditEngine();
pEditEngine->SetNumType(eNumType);
pEditEngine->UpdateFields();
}
std::unique_ptr<EditTextObject> ScEditWindow::CreateTextObject()
{
// reset paragraph attributes
// (GetAttribs at creation of format dialog always returns the set items)
const SfxItemSet& rEmpty = m_xEditEngine->GetEmptyItemSet();
sal_Int32 nParCnt = m_xEditEngine->GetParagraphCount();
for (sal_Int32 i=0; i<nParCnt; i++)
m_xEditEngine->SetParaAttribs( i, rEmpty );
return m_xEditEngine->CreateTextObject();
}
void ScEditWindow::SetFont( const ScPatternAttr& rPattern )
{
auto pSet = std::make_unique<SfxItemSet>( m_xEditEngine->GetEmptyItemSet() );
rPattern.FillEditItemSet( pSet.get() );
// FillEditItemSet adjusts font height to 1/100th mm,
// but for header/footer twips is needed, as in the PatternAttr:
pSet->Put( rPattern.GetItem(ATTR_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT) );
pSet->Put( rPattern.GetItem(ATTR_CJK_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CJK) );
pSet->Put( rPattern.GetItem(ATTR_CTL_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CTL) );
if (mbRTL)
pSet->Put( SvxAdjustItem( SvxAdjust::Right, EE_PARA_JUST ) );
GetEditEngine()->SetDefaults( std::move(pSet) );
}
void ScEditWindow::SetText( const EditTextObject& rTextObject )
{
GetEditEngine()->SetTextCurrentDefaults(rTextObject);
}
void ScEditWindow::InsertField( const SvxFieldItem& rFld )
{
m_xEditView->InsertField( rFld );
}
void ScEditWindow::SetCharAttributes()
{
SfxObjectShell* pDocSh = SfxObjectShell::Current();
SfxViewShell* pViewSh = SfxViewShell::Current();
ScTabViewShell* pTabViewSh = dynamic_cast<ScTabViewShell*>( SfxViewShell::Current() );
OSL_ENSURE( pDocSh, "Current DocShell not found" );
OSL_ENSURE( pViewSh, "Current ViewShell not found" );
if ( pDocSh && pViewSh )
{
if(pTabViewSh!=nullptr) pTabViewSh->SetInFormatDialog(true);
SfxItemSet aSet( m_xEditView->GetAttribs() );
ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateScCharDlg(
mpDialog, &aSet, pDocSh, false));
pDlg->SetText( ScResId( STR_TEXTATTRS ) );
if ( pDlg->Execute() == RET_OK )
{
aSet.ClearItem();
aSet.Put( *pDlg->GetOutputItemSet() );
m_xEditView->SetAttribs( aSet );
}
if(pTabViewSh!=nullptr) pTabViewSh->SetInFormatDialog(false);
}
}
bool ScEditWindow::KeyInput( const KeyEvent& rKEvt )
{
sal_uInt16 nKey = rKEvt.GetKeyCode().GetModifier()
+ rKEvt.GetKeyCode().GetCode();
if ( nKey == KEY_TAB || nKey == KEY_TAB + KEY_SHIFT )
{
return false;
}
else if ( !m_xEditView->PostKeyEvent( rKEvt ) )
{
return false;
}
else if ( !rKEvt.GetKeyCode().IsMod1() && !rKEvt.GetKeyCode().IsShift() &&
rKEvt.GetKeyCode().IsMod2() && rKEvt.GetKeyCode().GetCode() == KEY_DOWN )
{
aObjectSelectLink.Call(*this);
return true;
}
return true;
}
void ScEditWindow::GetFocus()
{
assert(m_GetFocusLink);
m_GetFocusLink(*this);
css::uno::Reference< css::accessibility::XAccessible > xTemp = xAcc;
if (xTemp.is() && pAcc)
{
pAcc->GotFocus();
}
else
pAcc = nullptr;
WeldEditView::GetFocus();
}
void ScEditWindow::LoseFocus()
{
css::uno::Reference< css::accessibility::XAccessible > xTemp = xAcc;
if (xTemp.is() && pAcc)
{
pAcc->LostFocus();
}
else
pAcc = nullptr;
WeldEditView::LoseFocus();
}
bool ScEditWindow::MouseButtonDown(const MouseEvent& rMEvt)
{
bool bHadFocus = HasFocus();
bool bRet = WeldEditView::MouseButtonDown(rMEvt);
if (!bHadFocus)
{
assert(HasFocus());
GetFocus();
}
return bRet;
}
css::uno::Reference< css::accessibility::XAccessible > ScEditWindow::CreateAccessible()
{
pAcc = new ScAccessibleEditControlObject(this);
css::uno::Reference< css::accessibility::XAccessible > xAccessible = pAcc;
xAcc = xAccessible;
return pAcc;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|