1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "scitems.hxx"
21 #include <editeng/eeitem.hxx>
24 #include <editeng/editobj.hxx>
25 #include <editeng/editstat.hxx>
26 #include <editeng/editview.hxx>
27 #include <editeng/flditem.hxx>
28 #include <editeng/adjustitem.hxx>
29 #include <sfx2/basedlgs.hxx>
30 #include <sfx2/objsh.hxx>
31 #include <vcl/msgbox.hxx>
32 #include <vcl/svapp.hxx>
34 #include "tphfedit.hxx"
35 #include "editutil.hxx"
38 #include "patattr.hxx"
39 #include "scresid.hxx"
41 #include "globstr.hrc"
42 #include "tabvwsh.hxx"
43 #include "prevwsh.hxx"
44 #include "AccessibleEditObject.hxx"
46 #include "scabstdlg.hxx"
49 // STATIC DATA -----------------------------------------------------------
50 static ScEditWindow
* pActiveEdWnd
= NULL
;
52 ScEditWindow
* GetScEditWindow ()
57 //========================================================================
59 static void lcl_GetFieldData( ScHeaderFieldData
& rData
)
61 SfxViewShell
* pShell
= SfxViewShell::Current();
64 if (pShell
->ISA(ScTabViewShell
))
65 ((ScTabViewShell
*)pShell
)->FillFieldData(rData
);
66 else if (pShell
->ISA(ScPreviewShell
))
67 ((ScPreviewShell
*)pShell
)->FillFieldData(rData
);
71 //========================================================================
73 //========================================================================
75 ScEditWindow::ScEditWindow( Window
* pParent
, WinBits nBits
, ScEditWindowLocation eLoc
)
76 : Control( pParent
, nBits
),
82 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
83 Color aBgColor
= rStyleSettings
.GetWindowColor();
85 SetMapMode( MAP_TWIP
);
86 SetPointer( POINTER_TEXT
);
87 SetBackground( aBgColor
);
89 Size
aSize( GetOutputSize() );
92 pEdEngine
= new ScHeaderEditEngine( EditEngine::CreatePool(), sal_True
);
93 pEdEngine
->SetPaperSize( aSize
);
94 pEdEngine
->SetRefDevice( this );
96 ScHeaderFieldData aData
;
97 lcl_GetFieldData( aData
);
100 pEdEngine
->SetData( aData
);
101 pEdEngine
->SetControlWord( pEdEngine
->GetControlWord() | EE_CNTRL_MARKFIELDS
);
102 mbRTL
= ScGlobal::IsSystemRTL();
104 pEdEngine
->SetDefaultHorizontalTextDirection(EE_HTEXTDIR_R2L
);
106 pEdView
= new EditView( pEdEngine
, this );
107 pEdView
->SetOutputArea( Rectangle( Point(0,0), GetOutputSize() ) );
109 pEdView
->SetBackgroundColor( aBgColor
);
110 pEdEngine
->InsertView( pEdView
);
113 void ScEditWindow::Resize()
115 Size
aOutputSize(GetOutputSize());
116 Size
aSize(aOutputSize
);
118 pEdEngine
->SetPaperSize(aSize
);
119 pEdView
->SetOutputArea(Rectangle(Point(0,0), aOutputSize
));
123 // -----------------------------------------------------------------------
125 ScEditWindow::~ScEditWindow()
127 // delete Accessible object before deleting EditEngine and EditView
130 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
> xTemp
= xAcc
;
138 extern "C" SAL_DLLPUBLIC_EXPORT Window
* SAL_CALL
makeScEditWindow(Window
*pParent
, VclBuilder::stringmap
&)
140 return new ScEditWindow (pParent
, WB_BORDER
|WB_TABSTOP
, Left
);
143 // -----------------------------------------------------------------------
145 void ScEditWindow::SetNumType(SvxNumType eNumType
)
147 pEdEngine
->SetNumType(eNumType
);
148 pEdEngine
->UpdateFields();
151 // -----------------------------------------------------------------------
153 EditTextObject
* ScEditWindow::CreateTextObject()
155 // Absatzattribute zuruecksetzen
156 // (GetAttribs beim Format-Dialog-Aufruf gibt immer gesetzte Items zurueck)
158 const SfxItemSet
& rEmpty
= pEdEngine
->GetEmptyItemSet();
159 sal_Int32 nParCnt
= pEdEngine
->GetParagraphCount();
160 for (sal_Int32 i
=0; i
<nParCnt
; i
++)
161 pEdEngine
->SetParaAttribs( i
, rEmpty
);
163 return pEdEngine
->CreateTextObject();
166 // -----------------------------------------------------------------------
168 void ScEditWindow::SetFont( const ScPatternAttr
& rPattern
)
170 SfxItemSet
* pSet
= new SfxItemSet( pEdEngine
->GetEmptyItemSet() );
171 rPattern
.FillEditItemSet( pSet
);
172 // FillEditItemSet adjusts font height to 1/100th mm,
173 // but for header/footer twips is needed, as in the PatternAttr:
174 pSet
->Put( rPattern
.GetItem(ATTR_FONT_HEIGHT
), EE_CHAR_FONTHEIGHT
);
175 pSet
->Put( rPattern
.GetItem(ATTR_CJK_FONT_HEIGHT
), EE_CHAR_FONTHEIGHT_CJK
);
176 pSet
->Put( rPattern
.GetItem(ATTR_CTL_FONT_HEIGHT
), EE_CHAR_FONTHEIGHT_CTL
);
178 pSet
->Put( SvxAdjustItem( SVX_ADJUST_RIGHT
, EE_PARA_JUST
) );
179 pEdEngine
->SetDefaults( pSet
);
182 // -----------------------------------------------------------------------
184 void ScEditWindow::SetText( const EditTextObject
& rTextObject
)
186 pEdEngine
->SetText( rTextObject
);
189 // -----------------------------------------------------------------------
191 void ScEditWindow::InsertField( const SvxFieldItem
& rFld
)
193 pEdView
->InsertField( rFld
);
196 // -----------------------------------------------------------------------
198 void ScEditWindow::SetCharAttriutes()
200 SfxObjectShell
* pDocSh
= SfxObjectShell::Current();
202 SfxViewShell
* pViewSh
= SfxViewShell::Current();
204 ScTabViewShell
* pTabViewSh
= PTR_CAST(ScTabViewShell
, SfxViewShell::Current());
207 OSL_ENSURE( pDocSh
, "Current DocShell not found" );
208 OSL_ENSURE( pViewSh
, "Current ViewShell not found" );
210 if ( pDocSh
&& pViewSh
)
212 if(pTabViewSh
!=NULL
) pTabViewSh
->SetInFormatDialog(sal_True
);
214 SfxItemSet
aSet( pEdView
->GetAttribs() );
216 ScAbstractDialogFactory
* pFact
= ScAbstractDialogFactory::Create();
217 OSL_ENSURE(pFact
, "ScAbstractFactory create fail!");
219 SfxAbstractTabDialog
* pDlg
= pFact
->CreateScCharDlg( GetParent(), &aSet
,
220 pDocSh
,RID_SCDLG_CHAR
);
221 OSL_ENSURE(pDlg
, "Dialog create fail!");
222 pDlg
->SetText( ScGlobal::GetRscString( STR_TEXTATTRS
) );
223 if ( pDlg
->Execute() == RET_OK
)
226 aSet
.Put( *pDlg
->GetOutputItemSet() );
227 pEdView
->SetAttribs( aSet
);
230 if(pTabViewSh
!=NULL
) pTabViewSh
->SetInFormatDialog(false);
235 // -----------------------------------------------------------------------
237 void ScEditWindow::Paint( const Rectangle
& rRect
)
239 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
240 Color aBgColor
= rStyleSettings
.GetWindowColor();
242 pEdView
->SetBackgroundColor( aBgColor
);
244 SetBackground( aBgColor
);
246 Control::Paint( rRect
);
248 pEdView
->Paint( rRect
);
251 // -----------------------------------------------------------------------
253 void ScEditWindow::MouseMove( const MouseEvent
& rMEvt
)
255 pEdView
->MouseMove( rMEvt
);
258 // -----------------------------------------------------------------------
260 void ScEditWindow::MouseButtonDown( const MouseEvent
& rMEvt
)
265 pEdView
->MouseButtonDown( rMEvt
);
268 // -----------------------------------------------------------------------
270 void ScEditWindow::MouseButtonUp( const MouseEvent
& rMEvt
)
272 pEdView
->MouseButtonUp( rMEvt
);
275 // -----------------------------------------------------------------------
277 void ScEditWindow::KeyInput( const KeyEvent
& rKEvt
)
279 sal_uInt16 nKey
= rKEvt
.GetKeyCode().GetModifier()
280 + rKEvt
.GetKeyCode().GetCode();
282 if ( nKey
== KEY_TAB
|| nKey
== KEY_TAB
+ KEY_SHIFT
)
284 Control::KeyInput( rKEvt
);
286 else if ( !pEdView
->PostKeyEvent( rKEvt
) )
288 Control::KeyInput( rKEvt
);
292 // -----------------------------------------------------------------------
294 void ScEditWindow::Command( const CommandEvent
& rCEvt
)
296 pEdView
->Command( rCEvt
);
299 // -----------------------------------------------------------------------
301 void ScEditWindow::GetFocus()
305 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
> xTemp
= xAcc
;
306 if (xTemp
.is() && pAcc
)
314 void ScEditWindow::LoseFocus()
316 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
> xTemp
= xAcc
;
317 if (xTemp
.is() && pAcc
)
325 // -----------------------------------------------------------------------
327 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
> ScEditWindow::CreateAccessible()
330 OUString
sDescription(GetHelpText());
335 sName
= OUString(ScResId(STR_ACC_LEFTAREA_NAME
));
340 sName
= OUString(ScResId(STR_ACC_CENTERAREA_NAME
));
345 sName
= OUString(ScResId(STR_ACC_RIGHTAREA_NAME
));
349 pAcc
= new ScAccessibleEditObject(GetAccessibleParentWindow()->GetAccessible(), pEdView
, this,
350 OUString(sName
), OUString(sDescription
), ScAccessibleEditObject::EditControl
);
351 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
> xAccessible
= pAcc
;
356 ScExtIButton::ScExtIButton(Window
* pParent
, WinBits nBits
)
357 : ImageButton(pParent
,nBits
), pPopupMenu(NULL
)
360 aTimer
.SetTimeout(600);
364 extern "C" SAL_DLLPUBLIC_EXPORT Window
* SAL_CALL
makeScExtIButton(Window
*pParent
, VclBuilder::stringmap
&)
366 return new ScExtIButton (pParent
, 0);// WB_BORDER|WB_TABSTOP);
369 void ScExtIButton::SetPopupMenu(PopupMenu
* pPopUp
)
374 sal_uInt16
ScExtIButton::GetSelected() const
379 OString
ScExtIButton::GetSelectedIdent() const
381 return aSelectedIdent
;
384 void ScExtIButton::MouseButtonDown( const MouseEvent
& rMEvt
)
386 if(!aTimer
.IsActive())
389 aTimer
.SetTimeoutHdl(LINK( this, ScExtIButton
, TimerHdl
));
392 ImageButton::MouseButtonDown(rMEvt
);
395 void ScExtIButton::MouseButtonUp( const MouseEvent
& rMEvt
)
398 aTimer
.SetTimeoutHdl(Link());
399 ImageButton::MouseButtonUp(rMEvt
);
402 void ScExtIButton::Click()
405 aTimer
.SetTimeoutHdl(Link());
406 ImageButton::Click();
409 void ScExtIButton::StartPopup()
412 aSelectedIdent
= OString();
416 SetPressed( sal_True
);
419 aPoint
.Y()=GetOutputSizePixel().Height();
421 nSelected
= pPopupMenu
->Execute( this, aPoint
);
425 aSelectedIdent
= pPopupMenu
->GetItemIdent(nSelected
);
433 long ScExtIButton::PreNotify( NotifyEvent
& rNEvt
)
435 sal_uInt16 nSwitch
=rNEvt
.GetType();
436 if(nSwitch
==EVENT_MOUSEBUTTONUP
)
438 MouseButtonUp(*rNEvt
.GetMouseEvent());
441 return ImageButton::PreNotify(rNEvt
);
444 IMPL_LINK_NOARG(ScExtIButton
, TimerHdl
)
451 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */