Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #define _TPHFEDIT_CXX
30 : : #include "scitems.hxx"
31 : : #include <editeng/eeitem.hxx>
32 : :
33 : :
34 : : #include <editeng/editobj.hxx>
35 : : #include <editeng/editstat.hxx>
36 : : #include <editeng/editview.hxx>
37 : : #include <editeng/flditem.hxx>
38 : : #include <editeng/adjitem.hxx>
39 : : #include <sfx2/basedlgs.hxx>
40 : : #include <sfx2/objsh.hxx>
41 : : #include <vcl/msgbox.hxx>
42 : : #include <vcl/svapp.hxx>
43 : :
44 : : #include "tphfedit.hxx"
45 : : #include "editutil.hxx"
46 : : #include "global.hxx"
47 : : #include "attrib.hxx"
48 : : #include "patattr.hxx"
49 : : #include "scresid.hxx"
50 : : #include "sc.hrc"
51 : : #include "globstr.hrc"
52 : : #include "tabvwsh.hxx"
53 : : #include "prevwsh.hxx"
54 : : #include "hfedtdlg.hrc"
55 : : #include "AccessibleEditObject.hxx"
56 : :
57 : : #include "scabstdlg.hxx"
58 : :
59 : :
60 : : // STATIC DATA -----------------------------------------------------------
61 : : static ScEditWindow* pActiveEdWnd = NULL;
62 : :
63 : 0 : ScEditWindow* GetScEditWindow ()
64 : : {
65 : 0 : return pActiveEdWnd;
66 : : }
67 : :
68 : : //========================================================================
69 : :
70 : 0 : void lcl_GetFieldData( ScHeaderFieldData& rData )
71 : : {
72 : 0 : SfxViewShell* pShell = SfxViewShell::Current();
73 [ # # ]: 0 : if (pShell)
74 : : {
75 [ # # ]: 0 : if (pShell->ISA(ScTabViewShell))
76 : 0 : ((ScTabViewShell*)pShell)->FillFieldData(rData);
77 [ # # ]: 0 : else if (pShell->ISA(ScPreviewShell))
78 : 0 : ((ScPreviewShell*)pShell)->FillFieldData(rData);
79 : : }
80 : 0 : }
81 : :
82 : : //========================================================================
83 : : // class ScEditWindow
84 : : //========================================================================
85 : :
86 : 0 : ScEditWindow::ScEditWindow( Window* pParent, const ResId& rResId, ScEditWindowLocation eLoc )
87 : : : Control( pParent, rResId ),
88 : : eLocation(eLoc),
89 [ # # ]: 0 : pAcc(NULL)
90 : : {
91 [ # # ]: 0 : EnableRTL(false);
92 : :
93 [ # # ]: 0 : const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
94 : 0 : Color aBgColor = rStyleSettings.GetWindowColor();
95 : :
96 [ # # ][ # # ]: 0 : SetMapMode( MAP_TWIP );
[ # # ]
97 [ # # ]: 0 : SetPointer( POINTER_TEXT );
98 [ # # ][ # # ]: 0 : SetBackground( aBgColor );
[ # # ]
99 : :
100 [ # # ]: 0 : Size aSize( GetOutputSize() );
101 : 0 : aSize.Height() *= 4;
102 : :
103 [ # # ][ # # ]: 0 : pEdEngine = new ScHeaderEditEngine( EditEngine::CreatePool(), sal_True );
[ # # ]
104 [ # # ]: 0 : pEdEngine->SetPaperSize( aSize );
105 [ # # ]: 0 : pEdEngine->SetRefDevice( this );
106 : :
107 [ # # ]: 0 : ScHeaderFieldData aData;
108 [ # # ]: 0 : lcl_GetFieldData( aData );
109 : :
110 : : // Feldbefehle:
111 [ # # ]: 0 : pEdEngine->SetData( aData );
112 [ # # ][ # # ]: 0 : pEdEngine->SetControlWord( pEdEngine->GetControlWord() | EE_CNTRL_MARKFIELDS );
113 [ # # ]: 0 : mbRTL = ScGlobal::IsSystemRTL();
114 [ # # ]: 0 : if (mbRTL)
115 [ # # ]: 0 : pEdEngine->SetDefaultHorizontalTextDirection(EE_HTEXTDIR_R2L);
116 : :
117 [ # # ][ # # ]: 0 : pEdView = new EditView( pEdEngine, this );
[ # # ]
118 [ # # ][ # # ]: 0 : pEdView->SetOutputArea( Rectangle( Point(0,0), GetOutputSize() ) );
[ # # ]
119 : :
120 [ # # ]: 0 : pEdView->SetBackgroundColor( aBgColor );
121 [ # # ][ # # ]: 0 : pEdEngine->InsertView( pEdView );
122 : 0 : }
123 : :
124 : : // -----------------------------------------------------------------------
125 : :
126 [ # # ]: 0 : ScEditWindow::~ScEditWindow()
127 : : {
128 : : // delete Accessible object before deleting EditEngine and EditView
129 [ # # ]: 0 : if (pAcc)
130 : : {
131 [ # # ]: 0 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > xTemp = xAcc;
132 [ # # ]: 0 : if (xTemp.is())
133 [ # # ]: 0 : pAcc->dispose();
134 : : }
135 [ # # ][ # # ]: 0 : delete pEdEngine;
136 [ # # ][ # # ]: 0 : delete pEdView;
137 [ # # ]: 0 : }
138 : :
139 : : // -----------------------------------------------------------------------
140 : :
141 : 0 : void ScEditWindow::SetNumType(SvxNumType eNumType)
142 : : {
143 : 0 : pEdEngine->SetNumType(eNumType);
144 : 0 : pEdEngine->UpdateFields();
145 : 0 : }
146 : :
147 : : // -----------------------------------------------------------------------
148 : :
149 : 0 : EditTextObject* ScEditWindow::CreateTextObject()
150 : : {
151 : : // Absatzattribute zuruecksetzen
152 : : // (GetAttribs beim Format-Dialog-Aufruf gibt immer gesetzte Items zurueck)
153 : :
154 : 0 : const SfxItemSet& rEmpty = pEdEngine->GetEmptyItemSet();
155 : 0 : sal_uInt16 nParCnt = pEdEngine->GetParagraphCount();
156 [ # # ]: 0 : for (sal_uInt16 i=0; i<nParCnt; i++)
157 : 0 : pEdEngine->SetParaAttribs( i, rEmpty );
158 : :
159 : 0 : return pEdEngine->CreateTextObject();
160 : : }
161 : :
162 : : // -----------------------------------------------------------------------
163 : :
164 : 0 : void ScEditWindow::SetFont( const ScPatternAttr& rPattern )
165 : : {
166 [ # # ]: 0 : SfxItemSet* pSet = new SfxItemSet( pEdEngine->GetEmptyItemSet() );
167 : 0 : rPattern.FillEditItemSet( pSet );
168 : : // FillEditItemSet adjusts font height to 1/100th mm,
169 : : // but for header/footer twips is needed, as in the PatternAttr:
170 : 0 : pSet->Put( rPattern.GetItem(ATTR_FONT_HEIGHT), EE_CHAR_FONTHEIGHT );
171 : 0 : pSet->Put( rPattern.GetItem(ATTR_CJK_FONT_HEIGHT), EE_CHAR_FONTHEIGHT_CJK );
172 : 0 : pSet->Put( rPattern.GetItem(ATTR_CTL_FONT_HEIGHT), EE_CHAR_FONTHEIGHT_CTL );
173 [ # # ]: 0 : if (mbRTL)
174 [ # # ]: 0 : pSet->Put( SvxAdjustItem( SVX_ADJUST_RIGHT, EE_PARA_JUST ) );
175 : 0 : pEdEngine->SetDefaults( pSet );
176 : 0 : }
177 : :
178 : : // -----------------------------------------------------------------------
179 : :
180 : 0 : void ScEditWindow::SetText( const EditTextObject& rTextObject )
181 : : {
182 : 0 : pEdEngine->SetText( rTextObject );
183 : 0 : }
184 : :
185 : : // -----------------------------------------------------------------------
186 : :
187 : 0 : void ScEditWindow::InsertField( const SvxFieldItem& rFld )
188 : : {
189 : 0 : pEdView->InsertField( rFld );
190 : 0 : }
191 : :
192 : : // -----------------------------------------------------------------------
193 : :
194 : 0 : void ScEditWindow::SetCharAttriutes()
195 : : {
196 : 0 : SfxObjectShell* pDocSh = SfxObjectShell::Current();
197 : :
198 : 0 : SfxViewShell* pViewSh = SfxViewShell::Current();
199 : :
200 [ # # ][ # # ]: 0 : ScTabViewShell* pTabViewSh = PTR_CAST(ScTabViewShell, SfxViewShell::Current());
201 : :
202 : :
203 : : OSL_ENSURE( pDocSh, "Current DocShell not found" );
204 : : OSL_ENSURE( pViewSh, "Current ViewShell not found" );
205 : :
206 [ # # ][ # # ]: 0 : if ( pDocSh && pViewSh )
207 : : {
208 [ # # ]: 0 : if(pTabViewSh!=NULL) pTabViewSh->SetInFormatDialog(sal_True);
209 : :
210 [ # # ]: 0 : SfxItemSet aSet( pEdView->GetAttribs() );
211 : :
212 [ # # ]: 0 : ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
213 : : OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
214 : :
215 : : SfxAbstractTabDialog* pDlg = pFact->CreateScCharDlg( GetParent(), &aSet,
216 [ # # ][ # # ]: 0 : pDocSh,RID_SCDLG_CHAR );
217 : : OSL_ENSURE(pDlg, "Dialog create fail!");
218 [ # # ][ # # ]: 0 : pDlg->SetText( ScGlobal::GetRscString( STR_TEXTATTRS ) );
219 [ # # ][ # # ]: 0 : if ( pDlg->Execute() == RET_OK )
220 : : {
221 [ # # ]: 0 : aSet.ClearItem();
222 [ # # ][ # # ]: 0 : aSet.Put( *pDlg->GetOutputItemSet() );
223 [ # # ]: 0 : pEdView->SetAttribs( aSet );
224 : : }
225 : :
226 [ # # ]: 0 : if(pTabViewSh!=NULL) pTabViewSh->SetInFormatDialog(false);
227 [ # # ][ # # ]: 0 : delete pDlg;
[ # # ]
228 : : }
229 : 0 : }
230 : :
231 : : // -----------------------------------------------------------------------
232 : :
233 : 0 : void ScEditWindow::Paint( const Rectangle& rRec )
234 : : {
235 [ # # ]: 0 : const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
236 : 0 : Color aBgColor = rStyleSettings.GetWindowColor();
237 : :
238 [ # # ]: 0 : pEdView->SetBackgroundColor( aBgColor );
239 : :
240 [ # # ][ # # ]: 0 : SetBackground( aBgColor );
[ # # ]
241 : :
242 [ # # ]: 0 : Control::Paint( rRec );
243 : :
244 [ # # ]: 0 : pEdView->Paint( rRec );
245 : 0 : }
246 : :
247 : : // -----------------------------------------------------------------------
248 : :
249 : 0 : void ScEditWindow::MouseMove( const MouseEvent& rMEvt )
250 : : {
251 : 0 : pEdView->MouseMove( rMEvt );
252 : 0 : }
253 : :
254 : : // -----------------------------------------------------------------------
255 : :
256 : 0 : void ScEditWindow::MouseButtonDown( const MouseEvent& rMEvt )
257 : : {
258 [ # # ]: 0 : if ( !HasFocus() )
259 : 0 : GrabFocus();
260 : :
261 : 0 : pEdView->MouseButtonDown( rMEvt );
262 : 0 : }
263 : :
264 : : // -----------------------------------------------------------------------
265 : :
266 : 0 : void ScEditWindow::MouseButtonUp( const MouseEvent& rMEvt )
267 : : {
268 : 0 : pEdView->MouseButtonUp( rMEvt );
269 : 0 : }
270 : :
271 : : // -----------------------------------------------------------------------
272 : :
273 : 0 : void ScEditWindow::KeyInput( const KeyEvent& rKEvt )
274 : : {
275 : 0 : sal_uInt16 nKey = rKEvt.GetKeyCode().GetModifier()
276 : 0 : + rKEvt.GetKeyCode().GetCode();
277 : :
278 [ # # ][ # # ]: 0 : if ( nKey == KEY_TAB || nKey == KEY_TAB + KEY_SHIFT )
279 : : {
280 : 0 : Control::KeyInput( rKEvt );
281 : : }
282 [ # # ]: 0 : else if ( !pEdView->PostKeyEvent( rKEvt ) )
283 : : {
284 : 0 : Control::KeyInput( rKEvt );
285 : : }
286 : 0 : }
287 : :
288 : : // -----------------------------------------------------------------------
289 : :
290 : 0 : void ScEditWindow::Command( const CommandEvent& rCEvt )
291 : : {
292 : 0 : pEdView->Command( rCEvt );
293 : 0 : }
294 : :
295 : : // -----------------------------------------------------------------------
296 : :
297 : 0 : void ScEditWindow::GetFocus()
298 : : {
299 : 0 : pActiveEdWnd = this;
300 : :
301 [ # # ]: 0 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > xTemp = xAcc;
302 [ # # ][ # # ]: 0 : if (xTemp.is() && pAcc)
[ # # ]
303 : : {
304 [ # # ]: 0 : pAcc->GotFocus();
305 : : }
306 : : else
307 : 0 : pAcc = NULL;
308 : 0 : }
309 : :
310 : 0 : void ScEditWindow::LoseFocus()
311 : : {
312 [ # # ]: 0 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > xTemp = xAcc;
313 [ # # ][ # # ]: 0 : if (xTemp.is() && pAcc)
[ # # ]
314 : : {
315 [ # # ]: 0 : pAcc->LostFocus();
316 : : }
317 : : else
318 : 0 : pAcc = NULL;
319 : 0 : }
320 : :
321 : : // -----------------------------------------------------------------------
322 : :
323 : 0 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > ScEditWindow::CreateAccessible()
324 : : {
325 [ # # ]: 0 : String sName;
326 [ # # ][ # # ]: 0 : String sDescription(GetHelpText());
327 [ # # # # ]: 0 : switch (eLocation)
328 : : {
329 : : case Left:
330 : : {
331 [ # # ][ # # ]: 0 : sName = String(ScResId(STR_ACC_LEFTAREA_NAME));
[ # # ][ # # ]
332 : : }
333 : 0 : break;
334 : : case Center:
335 : : {
336 [ # # ][ # # ]: 0 : sName = String(ScResId(STR_ACC_CENTERAREA_NAME));
[ # # ][ # # ]
337 : : }
338 : 0 : break;
339 : : case Right:
340 : : {
341 [ # # ][ # # ]: 0 : sName = String(ScResId(STR_ACC_RIGHTAREA_NAME));
[ # # ][ # # ]
342 : : }
343 : 0 : break;
344 : : }
345 : : pAcc = new ScAccessibleEditObject(GetAccessibleParentWindow()->GetAccessible(), pEdView, this,
346 [ # # ][ # # ]: 0 : rtl::OUString(sName), rtl::OUString(sDescription), ScAccessibleEditObject::EditControl);
[ # # ][ # # ]
[ # # ]
347 [ # # ][ # # ]: 0 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > xAccessible = pAcc;
348 [ # # ]: 0 : xAcc = xAccessible;
349 [ # # ][ # # ]: 0 : return pAcc;
[ # # ][ # # ]
350 : : }
351 : :
352 : 0 : ScExtIButton::ScExtIButton(Window* pParent, const ResId& rResId )
353 : : : ImageButton(pParent,rResId),
354 [ # # ][ # # ]: 0 : pPopupMenu(NULL)
355 : : {
356 : 0 : nSelected=0;
357 [ # # ]: 0 : aTimer.SetTimeout(600);
358 [ # # ]: 0 : SetDropDown( true);
359 : 0 : }
360 : :
361 : 0 : void ScExtIButton::SetPopupMenu(ScPopupMenu* pPopUp)
362 : : {
363 : 0 : pPopupMenu=pPopUp;
364 : 0 : }
365 : :
366 : 0 : sal_uInt16 ScExtIButton::GetSelected()
367 : : {
368 : 0 : return nSelected;
369 : : }
370 : :
371 : 0 : void ScExtIButton::MouseButtonDown( const MouseEvent& rMEvt )
372 : : {
373 [ # # ]: 0 : if(!aTimer.IsActive())
374 : : {
375 : 0 : aTimer.Start();
376 : 0 : aTimer.SetTimeoutHdl(LINK( this, ScExtIButton, TimerHdl));
377 : : }
378 : :
379 : 0 : ImageButton::MouseButtonDown(rMEvt );
380 : 0 : }
381 : 0 : void ScExtIButton::MouseButtonUp( const MouseEvent& rMEvt)
382 : : {
383 : 0 : aTimer.Stop();
384 : 0 : aTimer.SetTimeoutHdl(Link());
385 : 0 : ImageButton::MouseButtonUp(rMEvt );
386 : 0 : }
387 : :
388 : 0 : void ScExtIButton::Click()
389 : : {
390 : 0 : aTimer.Stop();
391 : 0 : aTimer.SetTimeoutHdl(Link());
392 : 0 : ImageButton::Click();
393 : 0 : }
394 : :
395 : 0 : void ScExtIButton::StartPopup()
396 : : {
397 : 0 : nSelected=0;
398 : :
399 [ # # ]: 0 : if(pPopupMenu!=NULL)
400 : : {
401 [ # # ]: 0 : SetPressed( sal_True );
402 [ # # ]: 0 : EndSelection();
403 : 0 : Point aPoint(0,0);
404 : 0 : aPoint.Y()=GetOutputSizePixel().Height();
405 : :
406 [ # # ]: 0 : nSelected=pPopupMenu->Execute( this, aPoint );
407 : :
408 [ # # ]: 0 : if(nSelected)
409 : : {
410 [ # # ]: 0 : aMLink.Call(this);
411 : : }
412 [ # # ]: 0 : SetPressed( false);
413 : : }
414 : 0 : }
415 : :
416 : 0 : long ScExtIButton::PreNotify( NotifyEvent& rNEvt )
417 : : {
418 : 0 : sal_uInt16 nSwitch=rNEvt.GetType();
419 [ # # ]: 0 : if(nSwitch==EVENT_MOUSEBUTTONUP)
420 : : {
421 : 0 : MouseButtonUp(*rNEvt.GetMouseEvent());
422 : : }
423 : :
424 : 0 : return ImageButton::PreNotify(rNEvt );
425 : : }
426 : :
427 : 0 : IMPL_LINK_NOARG(ScExtIButton, TimerHdl)
428 : : {
429 : 0 : StartPopup();
430 : 0 : return 0;
431 : : }
432 : :
433 : :
434 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|