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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
|
/* -*- 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/flditem.hxx>
#include <editeng/adjustitem.hxx>
#include <sfx2/basedlgs.hxx>
#include <sfx2/objsh.hxx>
#include <vcl/msgbox.hxx>
#include <vcl/svapp.hxx>
#include <vcl/settings.hxx>
#include "tphfedit.hxx"
#include "editutil.hxx"
#include "global.hxx"
#include "attrib.hxx"
#include "patattr.hxx"
#include "scresid.hxx"
#include "sc.hrc"
#include "globstr.hrc"
#include "tabvwsh.hxx"
#include "prevwsh.hxx"
#include "AccessibleEditObject.hxx"
#include "scabstdlg.hxx"
#include <boost/scoped_ptr.hpp>
// STATIC DATA -----------------------------------------------------------
static ScEditWindow* pActiveEdWnd = NULL;
ScEditWindow* GetScEditWindow ()
{
return pActiveEdWnd;
}
static void lcl_GetFieldData( ScHeaderFieldData& rData )
{
SfxViewShell* pShell = SfxViewShell::Current();
if (pShell)
{
if (pShell->ISA(ScTabViewShell))
((ScTabViewShell*)pShell)->FillFieldData(rData);
else if (pShell->ISA(ScPreviewShell))
((ScPreviewShell*)pShell)->FillFieldData(rData);
}
}
// class ScEditWindow
ScEditWindow::ScEditWindow( Window* pParent, WinBits nBits, ScEditWindowLocation eLoc )
: Control( pParent, nBits ),
eLocation(eLoc),
pAcc(NULL)
{
EnableRTL(false);
const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
Color aBgColor = rStyleSettings.GetWindowColor();
SetMapMode( MAP_TWIP );
SetPointer( POINTER_TEXT );
SetBackground( aBgColor );
Size aSize( GetOutputSize() );
aSize.Height() *= 4;
pEdEngine = new ScHeaderEditEngine( EditEngine::CreatePool(), true );
pEdEngine->SetPaperSize( aSize );
pEdEngine->SetRefDevice( this );
ScHeaderFieldData aData;
lcl_GetFieldData( aData );
// Feldbefehle:
pEdEngine->SetData( aData );
pEdEngine->SetControlWord( pEdEngine->GetControlWord() | EE_CNTRL_MARKFIELDS );
mbRTL = ScGlobal::IsSystemRTL();
if (mbRTL)
pEdEngine->SetDefaultHorizontalTextDirection(EE_HTEXTDIR_R2L);
pEdView = new EditView( pEdEngine, this );
pEdView->SetOutputArea( Rectangle( Point(0,0), GetOutputSize() ) );
pEdView->SetBackgroundColor( aBgColor );
pEdEngine->InsertView( pEdView );
}
void ScEditWindow::Resize()
{
Size aOutputSize(GetOutputSize());
Size aSize(aOutputSize);
aSize.Height() *= 4;
pEdEngine->SetPaperSize(aSize);
pEdView->SetOutputArea(Rectangle(Point(0,0), aOutputSize));
Control::Resize();
}
ScEditWindow::~ScEditWindow()
{
// delete Accessible object before deleting EditEngine and EditView
if (pAcc)
{
::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > xTemp = xAcc;
if (xTemp.is())
pAcc->dispose();
}
delete pEdEngine;
delete pEdView;
}
extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeScEditWindow(Window *pParent, VclBuilder::stringmap &)
{
return new ScEditWindow (pParent, WB_BORDER|WB_TABSTOP, Left);
}
void ScEditWindow::SetNumType(SvxNumType eNumType)
{
pEdEngine->SetNumType(eNumType);
pEdEngine->UpdateFields();
}
EditTextObject* ScEditWindow::CreateTextObject()
{
// Absatzattribute zuruecksetzen
// (GetAttribs beim Format-Dialog-Aufruf gibt immer gesetzte Items zurueck)
const SfxItemSet& rEmpty = pEdEngine->GetEmptyItemSet();
sal_Int32 nParCnt = pEdEngine->GetParagraphCount();
for (sal_Int32 i=0; i<nParCnt; i++)
pEdEngine->SetParaAttribs( i, rEmpty );
return pEdEngine->CreateTextObject();
}
void ScEditWindow::SetFont( const ScPatternAttr& rPattern )
{
SfxItemSet* pSet = new SfxItemSet( pEdEngine->GetEmptyItemSet() );
rPattern.FillEditItemSet( pSet );
// 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), EE_CHAR_FONTHEIGHT );
pSet->Put( rPattern.GetItem(ATTR_CJK_FONT_HEIGHT), EE_CHAR_FONTHEIGHT_CJK );
pSet->Put( rPattern.GetItem(ATTR_CTL_FONT_HEIGHT), EE_CHAR_FONTHEIGHT_CTL );
if (mbRTL)
pSet->Put( SvxAdjustItem( SVX_ADJUST_RIGHT, EE_PARA_JUST ) );
pEdEngine->SetDefaults( pSet );
}
void ScEditWindow::SetText( const EditTextObject& rTextObject )
{
pEdEngine->SetText( rTextObject );
}
void ScEditWindow::InsertField( const SvxFieldItem& rFld )
{
pEdView->InsertField( rFld );
}
void ScEditWindow::SetCharAttriutes()
{
SfxObjectShell* pDocSh = SfxObjectShell::Current();
SfxViewShell* pViewSh = SfxViewShell::Current();
ScTabViewShell* pTabViewSh = PTR_CAST(ScTabViewShell, SfxViewShell::Current());
OSL_ENSURE( pDocSh, "Current DocShell not found" );
OSL_ENSURE( pViewSh, "Current ViewShell not found" );
if ( pDocSh && pViewSh )
{
if(pTabViewSh!=NULL) pTabViewSh->SetInFormatDialog(true);
SfxItemSet aSet( pEdView->GetAttribs() );
ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
boost::scoped_ptr<SfxAbstractTabDialog> pDlg(pFact->CreateScCharDlg(
GetParent(), &aSet, pDocSh));
OSL_ENSURE(pDlg, "Dialog create fail!");
pDlg->SetText( ScGlobal::GetRscString( STR_TEXTATTRS ) );
if ( pDlg->Execute() == RET_OK )
{
aSet.ClearItem();
aSet.Put( *pDlg->GetOutputItemSet() );
pEdView->SetAttribs( aSet );
}
if(pTabViewSh!=NULL) pTabViewSh->SetInFormatDialog(false);
}
}
void ScEditWindow::Paint( const Rectangle& rRect )
{
const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
Color aBgColor = rStyleSettings.GetWindowColor();
pEdView->SetBackgroundColor( aBgColor );
SetBackground( aBgColor );
Control::Paint( rRect );
pEdView->Paint( rRect );
if( HasFocus() )
pEdView->ShowCursor(true,true);
}
void ScEditWindow::MouseMove( const MouseEvent& rMEvt )
{
pEdView->MouseMove( rMEvt );
}
void ScEditWindow::MouseButtonDown( const MouseEvent& rMEvt )
{
if ( !HasFocus() )
GrabFocus();
pEdView->MouseButtonDown( rMEvt );
}
void ScEditWindow::MouseButtonUp( const MouseEvent& rMEvt )
{
pEdView->MouseButtonUp( rMEvt );
}
void ScEditWindow::KeyInput( const KeyEvent& rKEvt )
{
sal_uInt16 nKey = rKEvt.GetKeyCode().GetModifier()
+ rKEvt.GetKeyCode().GetCode();
if ( nKey == KEY_TAB || nKey == KEY_TAB + KEY_SHIFT )
{
Control::KeyInput( rKEvt );
}
else if ( !pEdView->PostKeyEvent( rKEvt ) )
{
Control::KeyInput( rKEvt );
}
else if ( !rKEvt.GetKeyCode().IsMod1() && !rKEvt.GetKeyCode().IsShift() &&
rKEvt.GetKeyCode().IsMod2() && rKEvt.GetKeyCode().GetCode() == KEY_DOWN )
{
if (aObjectSelectLink.IsSet() )
aObjectSelectLink.Call(this);
}
}
void ScEditWindow::Command( const CommandEvent& rCEvt )
{
pEdView->Command( rCEvt );
}
void ScEditWindow::GetFocus()
{
pEdView->ShowCursor(true,true);
pActiveEdWnd = this;
::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > xTemp = xAcc;
if (xTemp.is() && pAcc)
{
pAcc->GotFocus();
}
else
pAcc = NULL;
}
void ScEditWindow::LoseFocus()
{
::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > xTemp = xAcc;
if (xTemp.is() && pAcc)
{
pAcc->LostFocus();
}
else
pAcc = NULL;
}
::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > ScEditWindow::CreateAccessible()
{
OUString sName;
OUString sDescription(GetHelpText());
switch (eLocation)
{
case Left:
{
sName = OUString(ScResId(STR_ACC_LEFTAREA_NAME));
}
break;
case Center:
{
sName = OUString(ScResId(STR_ACC_CENTERAREA_NAME));
}
break;
case Right:
{
sName = OUString(ScResId(STR_ACC_RIGHTAREA_NAME));
}
break;
}
pAcc = new ScAccessibleEditObject(GetAccessibleParentWindow()->GetAccessible(), pEdView, this,
OUString(sName), OUString(sDescription), ScAccessibleEditObject::EditControl);
::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > xAccessible = pAcc;
xAcc = xAccessible;
return pAcc;
}
ScExtIButton::ScExtIButton(Window* pParent, WinBits nBits )
: ImageButton(pParent,nBits), pPopupMenu(NULL)
{
nSelected=0;
aTimer.SetTimeout(600);
SetDropDown(PUSHBUTTON_DROPDOWN_TOOLBOX);
}
extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeScExtIButton(Window *pParent, VclBuilder::stringmap &)
{
return new ScExtIButton (pParent, 0);// WB_BORDER|WB_TABSTOP);
}
void ScExtIButton::SetPopupMenu(PopupMenu* pPopUp)
{
pPopupMenu=pPopUp;
}
void ScExtIButton::MouseButtonDown( const MouseEvent& rMEvt )
{
if(!aTimer.IsActive())
{
aTimer.Start();
aTimer.SetTimeoutHdl(LINK( this, ScExtIButton, TimerHdl));
}
ImageButton::MouseButtonDown(rMEvt );
}
void ScExtIButton::MouseButtonUp( const MouseEvent& rMEvt)
{
aTimer.Stop();
aTimer.SetTimeoutHdl(Link());
ImageButton::MouseButtonUp(rMEvt );
}
void ScExtIButton::Click()
{
aTimer.Stop();
aTimer.SetTimeoutHdl(Link());
ImageButton::Click();
}
void ScExtIButton::StartPopup()
{
nSelected=0;
aSelectedIdent = OString();
if(pPopupMenu!=NULL)
{
SetPressed( true );
EndSelection();
Point aPoint(0,0);
aPoint.Y()=GetOutputSizePixel().Height();
nSelected = pPopupMenu->Execute( this, aPoint );
if(nSelected)
{
aSelectedIdent = pPopupMenu->GetItemIdent(nSelected);
aMLink.Call(this);
}
SetPressed( false);
}
}
bool ScExtIButton::PreNotify( NotifyEvent& rNEvt )
{
sal_uInt16 nSwitch=rNEvt.GetType();
if(nSwitch==EVENT_MOUSEBUTTONUP)
{
MouseButtonUp(*rNEvt.GetMouseEvent());
}
return ImageButton::PreNotify(rNEvt );
}
IMPL_LINK_NOARG(ScExtIButton, TimerHdl)
{
StartPopup();
return 0;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|