merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / pagedlg / tphfedit.cxx
blobd42932a373240a8b05a2e114d468bced970e77f0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tphfedit.cxx,v $
10 * $Revision: 1.20 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 //------------------------------------------------------------------
38 #define _TPHFEDIT_CXX
39 #include "scitems.hxx"
40 #include <svx/eeitem.hxx>
43 //CHINA001 #include <svx/chardlg.hxx>
44 #include <svx/editobj.hxx>
45 #include <svx/editstat.hxx>
46 #include <svx/editview.hxx>
47 #include <svx/flditem.hxx>
48 #include <svx/adjitem.hxx>
49 #include <sfx2/basedlgs.hxx>
50 #include <sfx2/objsh.hxx>
51 #include <vcl/msgbox.hxx>
52 #include <vcl/svapp.hxx>
54 #include "tphfedit.hxx"
55 #include "editutil.hxx"
56 #include "global.hxx"
57 #include "attrib.hxx"
58 #include "patattr.hxx"
59 #include "scresid.hxx"
60 #include "sc.hrc"
61 #include "globstr.hrc"
62 #include "tabvwsh.hxx"
63 #include "prevwsh.hxx"
64 #include "hfedtdlg.hrc"
65 //CHINA001 #include "textdlgs.hxx"
66 #include "AccessibleEditObject.hxx"
68 #include "scabstdlg.hxx" //CHINA001
71 // STATIC DATA -----------------------------------------------------------
72 static ScEditWindow* pActiveEdWnd = NULL;
74 ScEditWindow* GetScEditWindow ()
76 return pActiveEdWnd;
79 //CHINA001
80 //CHINA001 static USHORT pPageRightHeaderRanges[] = { SID_SCATTR_PAGE_HEADERRIGHT,
81 //CHINA001 SID_SCATTR_PAGE_HEADERRIGHT,
82 //CHINA001 0 };
83 //CHINA001
84 //CHINA001 static USHORT pPageRightFooterRanges[] = { SID_SCATTR_PAGE_FOOTERRIGHT,
85 //CHINA001 SID_SCATTR_PAGE_FOOTERRIGHT,
86 //CHINA001 0 };
87 //CHINA001
88 //CHINA001 static USHORT pPageLeftHeaderRanges[] = { SID_SCATTR_PAGE_HEADERLEFT,
89 //CHINA001 SID_SCATTR_PAGE_HEADERLEFT,
90 //CHINA001 0 };
91 //CHINA001
92 //CHINA001 static USHORT pPageLeftFooterRanges[] = { SID_SCATTR_PAGE_FOOTERLEFT,
93 //CHINA001 SID_SCATTR_PAGE_FOOTERLEFT,
94 //CHINA001 0 };
95 //CHINA001
96 //CHINA001 static ScEditWindow* pActiveEdWnd = NULL;
97 //CHINA001
98 //CHINA001
99 //CHINA001
100 //CHINA001 //========================================================================
101 //CHINA001 // class ScHFEditPage
102 //CHINA001 //
103 //CHINA001
104 //CHINA001 ScHFEditPage::ScHFEditPage( Window* pParent,
105 //CHINA001 USHORT nResId,
106 //CHINA001 const SfxItemSet& rCoreAttrs,
107 //CHINA001 USHORT nWhichId )
108 //CHINA001
109 //CHINA001 : SfxTabPage ( pParent, ScResId( nResId ), rCoreAttrs ),
110 //CHINA001
111 //CHINA001 aWndLeft ( this, ScResId( WND_LEFT ), Left ),
112 //CHINA001 aWndCenter ( this, ScResId( WND_CENTER ), Center ),
113 //CHINA001 aWndRight ( this, ScResId( WND_RIGHT ), Right ),
114 //CHINA001 aFtLeft ( this, ScResId( FT_LEFT ) ),
115 //CHINA001 aFtCenter ( this, ScResId( FT_CENTER ) ),
116 //CHINA001 aFtRight ( this, ScResId( FT_RIGHT ) ),
117 //CHINA001 aFlInfo ( this, ScResId( FL_INFO ) ),
118 //CHINA001 aFtInfo ( this, ScResId( FT_INFO ) ),
119 //CHINA001 aBtnText ( this, ScResId( BTN_TEXT ) ),
120 //CHINA001 aBtnPage ( this, ScResId( BTN_PAGE ) ),
121 //CHINA001 aBtnLastPage ( this, ScResId( BTN_PAGES ) ),
122 //CHINA001 aBtnDate ( this, ScResId( BTN_DATE ) ),
123 //CHINA001 aBtnTime ( this, ScResId( BTN_TIME ) ),
124 //CHINA001 aBtnFile ( this, ScResId( BTN_FILE ) ),
125 //CHINA001 aBtnTable ( this, ScResId( BTN_TABLE ) ),
126 //CHINA001 aPopUpFile ( ScResId( RID_POPUP_FCOMMAND) ),
127 //CHINA001 nWhich ( nWhichId )
128 //CHINA001 {
129 //CHINA001 //! use default style from current document?
130 //CHINA001 //! if font color is used, header/footer background color must be set
131 //CHINA001
132 //CHINA001 ScPatternAttr aPatAttr( rCoreAttrs.GetPool() );
133 //CHINA001
134 //CHINA001 aBtnFile.SetPopupMenu(&aPopUpFile);
135 //CHINA001
136 //CHINA001 aBtnFile.SetMenuHdl( LINK( this, ScHFEditPage, MenuHdl ) );
137 //CHINA001 aBtnText .SetClickHdl( LINK( this, ScHFEditPage, ClickHdl ) );
138 //CHINA001 aBtnPage .SetClickHdl( LINK( this, ScHFEditPage, ClickHdl ) );
139 //CHINA001 aBtnLastPage.SetClickHdl( LINK( this, ScHFEditPage, ClickHdl ) );
140 //CHINA001 aBtnDate .SetClickHdl( LINK( this, ScHFEditPage, ClickHdl ) );
141 //CHINA001 aBtnTime .SetClickHdl( LINK( this, ScHFEditPage, ClickHdl ) );
142 //CHINA001 aBtnFile .SetClickHdl( LINK( this, ScHFEditPage, ClickHdl ) );
143 //CHINA001 aBtnTable .SetClickHdl( LINK( this, ScHFEditPage, ClickHdl ) );
144 //CHINA001
145 //CHINA001 aBtnText .SetModeImage( Image( ScResId( IMG_TEXT_H ) ), BMP_COLOR_HIGHCONTRAST );
146 //CHINA001 aBtnFile .SetModeImage( Image( ScResId( IMG_FILE_H ) ), BMP_COLOR_HIGHCONTRAST );
147 //CHINA001 aBtnTable .SetModeImage( Image( ScResId( IMG_TABLE_H ) ), BMP_COLOR_HIGHCONTRAST );
148 //CHINA001 aBtnPage .SetModeImage( Image( ScResId( IMG_PAGE_H ) ), BMP_COLOR_HIGHCONTRAST );
149 //CHINA001 aBtnLastPage.SetModeImage( Image( ScResId( IMG_PAGES_H ) ), BMP_COLOR_HIGHCONTRAST );
150 //CHINA001 aBtnDate .SetModeImage( Image( ScResId( IMG_DATE_H ) ), BMP_COLOR_HIGHCONTRAST );
151 //CHINA001 aBtnTime .SetModeImage( Image( ScResId( IMG_TIME_H ) ), BMP_COLOR_HIGHCONTRAST );
152 //CHINA001
153 //CHINA001 aWndLeft. SetFont( aPatAttr );
154 //CHINA001 aWndCenter. SetFont( aPatAttr );
155 //CHINA001 aWndRight. SetFont( aPatAttr );
156 //CHINA001
157 //CHINA001 FillCmdArr();
158 //CHINA001
159 //CHINA001 aWndLeft.GrabFocus();
160 //CHINA001
161 //CHINA001 FreeResource();
162 //CHINA001 }
163 //CHINA001
164 //CHINA001 // -----------------------------------------------------------------------
165 //CHINA001
166 //CHINA001 __EXPORT ScHFEditPage::~ScHFEditPage()
167 //CHINA001 {
168 //CHINA001 }
169 //CHINA001
170 //CHINA001 void ScHFEditPage::SetNumType(SvxNumType eNumType)
171 //CHINA001 {
172 //CHINA001 aWndLeft.SetNumType(eNumType);
173 //CHINA001 aWndCenter.SetNumType(eNumType);
174 //CHINA001 aWndRight.SetNumType(eNumType);
175 //CHINA001 }
176 //CHINA001
177 //CHINA001 // -----------------------------------------------------------------------
178 //CHINA001
179 //CHINA001 #define IS_AVAILABLE(w)(rCoreSet.GetItemState( (w) ) >= SFX_ITEM_AVAILABLE)
180 //CHINA001
181 //CHINA001 void __EXPORT ScHFEditPage::Reset( const SfxItemSet& rCoreSet )
182 //CHINA001 {
183 //CHINA001 if ( IS_AVAILABLE( nWhich ) )
184 //CHINA001 {
185 //CHINA001 const ScPageHFItem& rItem = (const ScPageHFItem&)(rCoreSet.Get( nWhich ));
186 //CHINA001
187 //CHINA001 const EditTextObject* pLeft = rItem.GetLeftArea();
188 //CHINA001 const EditTextObject* pCenter = rItem.GetCenterArea();
189 //CHINA001 const EditTextObject* pRight = rItem.GetRightArea();
190 //CHINA001
191 //CHINA001 if ( pLeft && pCenter && pRight )
192 //CHINA001 {
193 //CHINA001 aWndLeft .SetText( *pLeft );
194 //CHINA001 aWndCenter .SetText( *pCenter );
195 //CHINA001 aWndRight .SetText( *pRight );
196 //CHINA001 }
197 //CHINA001 }
198 //CHINA001 }
199 //CHINA001
200 //CHINA001 #undef IS_AVAILABLE
201 //CHINA001
202 //CHINA001 // -----------------------------------------------------------------------
203 //CHINA001
204 //CHINA001 BOOL __EXPORT ScHFEditPage::FillItemSet( SfxItemSet& rCoreSet )
205 //CHINA001 {
206 //CHINA001 ScPageHFItem aItem( nWhich );
207 //CHINA001 EditTextObject* pLeft = aWndLeft .CreateTextObject();
208 //CHINA001 EditTextObject* pCenter = aWndCenter.CreateTextObject();
209 //CHINA001 EditTextObject* pRight = aWndRight .CreateTextObject();
210 //CHINA001
211 //CHINA001 aItem.SetLeftArea ( *pLeft );
212 //CHINA001 aItem.SetCenterArea( *pCenter );
213 //CHINA001 aItem.SetRightArea ( *pRight );
214 //CHINA001 delete pLeft;
215 //CHINA001 delete pCenter;
216 //CHINA001 delete pRight;
217 //CHINA001
218 //CHINA001 rCoreSet.Put( aItem );
219 //CHINA001
220 //CHINA001 return TRUE;
221 //CHINA001 }
222 //CHINA001
223 //CHINA001 // -----------------------------------------------------------------------
224 //CHINA001
225 //CHINA001 #define SET_CMD(i,id) x
226 //CHINA001 aCmd = aDel; x
227 //CHINA001 aCmd += ScGlobal::GetRscString( id ); x
228 //CHINA001 aCmd += aDel; x
229 //CHINA001 aCmdArr[i] = aCmd;
230 //CHINA001
231 //CHINA001 // -----------------------------------------------------------------------
232 //CHINA001
233 //CHINA001 void ScHFEditPage::FillCmdArr()
234 //CHINA001 {
235 //CHINA001 String aDel( ScGlobal::GetRscString( STR_HFCMD_DELIMITER ) );
236 //CHINA001 String aCmd;
237 //CHINA001
238 //CHINA001 SET_CMD( 0, STR_HFCMD_PAGE )
239 //CHINA001 SET_CMD( 1, STR_HFCMD_PAGES )
240 //CHINA001 SET_CMD( 2, STR_HFCMD_DATE )
241 //CHINA001 SET_CMD( 3, STR_HFCMD_TIME )
242 //CHINA001 SET_CMD( 4, STR_HFCMD_FILE )
243 //CHINA001 SET_CMD( 5, STR_HFCMD_TABLE )
244 //CHINA001 }
245 //CHINA001
246 //CHINA001 #undef SET_CMD
247 //CHINA001
248 //CHINA001 //-----------------------------------------------------------------------
249 //CHINA001 // Handler:
250 //CHINA001 //-----------------------------------------------------------------------
251 //CHINA001
252 //CHINA001 IMPL_LINK( ScHFEditPage, ClickHdl, ImageButton*, pBtn )
253 //CHINA001 {
254 //CHINA001 if ( !pActiveEdWnd )
255 //CHINA001 return 0;
256 //CHINA001
257 //CHINA001 if ( pBtn == &aBtnText )
258 //CHINA001 {
259 //CHINA001 pActiveEdWnd->SetCharAttriutes();
260 //CHINA001 }
261 //CHINA001 else
262 //CHINA001 {
263 //CHINA001 if ( pBtn == &aBtnPage )
264 //CHINA001 pActiveEdWnd->InsertField( SvxFieldItem(SvxPageField()) );
265 //CHINA001 else if ( pBtn == &aBtnLastPage )
266 //CHINA001 pActiveEdWnd->InsertField( SvxFieldItem(SvxPagesField()) );
267 //CHINA001 else if ( pBtn == &aBtnDate )
268 //CHINA001 pActiveEdWnd->InsertField( SvxFieldItem(SvxDateField(Date(),SVXDATETYPE_VAR)) );
269 //CHINA001 else if ( pBtn == &aBtnTime )
270 //CHINA001 pActiveEdWnd->InsertField( SvxFieldItem(SvxTimeField()) );
271 //CHINA001 else if ( pBtn == &aBtnFile )
272 //CHINA001 {
273 //CHINA001 pActiveEdWnd->InsertField( SvxFieldItem( SvxFileField() ) );
274 //CHINA001 }
275 //CHINA001 else if ( pBtn == &aBtnTable )
276 //CHINA001 pActiveEdWnd->InsertField( SvxFieldItem(SvxTableField()) );
277 //CHINA001 }
278 //CHINA001 pActiveEdWnd->GrabFocus();
279 //CHINA001
280 //CHINA001 return 0;
281 //CHINA001 }
282 //CHINA001
283 //CHINA001 IMPL_LINK( ScHFEditPage, MenuHdl, ScExtIButton*, pBtn )
284 //CHINA001 {
285 //CHINA001 if ( !pActiveEdWnd )
286 //CHINA001 return 0;
287 //CHINA001
288 //CHINA001 if(pBtn!=NULL)
289 //CHINA001 {
290 //CHINA001 switch(pBtn->GetSelected())
291 //CHINA001 {
292 //CHINA001 case FILE_COMMAND_TITEL:
293 //CHINA001 pActiveEdWnd->InsertField( SvxFieldItem( SvxFileField() ) );
294 //CHINA001 break;
295 //CHINA001 case FILE_COMMAND_FILENAME:
296 //CHINA001 pActiveEdWnd->InsertField( SvxFieldItem( SvxExtFileField(
297 //CHINA001 EMPTY_STRING, SVXFILETYPE_VAR, SVXFILEFORMAT_NAME_EXT ) ) );
298 //CHINA001 break;
299 //CHINA001 case FILE_COMMAND_PATH:
300 //CHINA001 pActiveEdWnd->InsertField( SvxFieldItem( SvxExtFileField(
301 //CHINA001 EMPTY_STRING, SVXFILETYPE_VAR, SVXFILEFORMAT_FULLPATH ) ) );
302 //CHINA001 break;
303 //CHINA001 }
304 //CHINA001 }
305 //CHINA001 return 0;
306 //CHINA001 }
307 //CHINA001
308 //CHINA001 //========================================================================
309 //CHINA001 // class ScRightHeaderEditPage
310 //CHINA001 //========================================================================
311 //CHINA001
312 //CHINA001 ScRightHeaderEditPage::ScRightHeaderEditPage( Window* pParent, const SfxItemSet& rCoreSet )
313 //CHINA001 : ScHFEditPage( pParent, RID_SCPAGE_HFED_HR, rCoreSet,
314 //CHINA001 rCoreSet.GetPool()->GetWhich(SID_SCATTR_PAGE_HEADERRIGHT) )
315 //CHINA001 {}
316 //CHINA001
317 //CHINA001 // -----------------------------------------------------------------------
318 //CHINA001
319 //CHINA001 USHORT* __EXPORT ScRightHeaderEditPage::GetRanges()
320 //CHINA001 { return pPageRightHeaderRanges; }
321 //CHINA001
322 //CHINA001 // -----------------------------------------------------------------------
323 //CHINA001
324 //CHINA001 SfxTabPage* __EXPORT ScRightHeaderEditPage::Create( Window* pParent, const SfxItemSet& rCoreSet )
325 //CHINA001 { return ( new ScRightHeaderEditPage( pParent, rCoreSet ) ); };
326 //CHINA001
327 //CHINA001
328 //CHINA001 //========================================================================
329 //CHINA001 // class ScLeftHeaderEditPage
330 //CHINA001 //========================================================================
331 //CHINA001
332 //CHINA001 ScLeftHeaderEditPage::ScLeftHeaderEditPage( Window* pParent, const SfxItemSet& rCoreSet )
333 //CHINA001 : ScHFEditPage( pParent, RID_SCPAGE_HFED_HL, rCoreSet,
334 //CHINA001 rCoreSet.GetPool()->GetWhich(SID_SCATTR_PAGE_HEADERLEFT) )
335 //CHINA001 {}
336 //CHINA001
337 //CHINA001 // -----------------------------------------------------------------------
338 //CHINA001
339 //CHINA001 USHORT* __EXPORT ScLeftHeaderEditPage::GetRanges()
340 //CHINA001 { return pPageLeftHeaderRanges; }
341 //CHINA001
342 //CHINA001 // -----------------------------------------------------------------------
343 //CHINA001
344 //CHINA001 SfxTabPage* __EXPORT ScLeftHeaderEditPage::Create( Window* pParent, const SfxItemSet& rCoreSet )
345 //CHINA001 { return ( new ScLeftHeaderEditPage( pParent, rCoreSet ) ); };
346 //CHINA001
347 //CHINA001 //========================================================================
348 //CHINA001 // class ScRightFooterEditPage
349 //CHINA001 //========================================================================
350 //CHINA001
351 //CHINA001 ScRightFooterEditPage::ScRightFooterEditPage( Window* pParent, const SfxItemSet& rCoreSet )
352 //CHINA001 : ScHFEditPage( pParent, RID_SCPAGE_HFED_FR, rCoreSet,
353 //CHINA001 rCoreSet.GetPool()->GetWhich(SID_SCATTR_PAGE_FOOTERRIGHT) )
354 //CHINA001 {}
355 //CHINA001
356 //CHINA001 // -----------------------------------------------------------------------
357 //CHINA001
358 //CHINA001 USHORT* __EXPORT ScRightFooterEditPage::GetRanges()
359 //CHINA001 { return pPageRightFooterRanges; }
360 //CHINA001
361 //CHINA001 // -----------------------------------------------------------------------
362 //CHINA001
363 //CHINA001 SfxTabPage* __EXPORT ScRightFooterEditPage::Create( Window* pParent, const SfxItemSet& rCoreSet )
364 //CHINA001 { return ( new ScRightFooterEditPage( pParent, rCoreSet ) ); };
365 //CHINA001
366 //CHINA001 //========================================================================
367 //CHINA001 // class ScLeftFooterEditPage
368 //CHINA001 //========================================================================
369 //CHINA001
370 //CHINA001 ScLeftFooterEditPage::ScLeftFooterEditPage( Window* pParent, const SfxItemSet& rCoreSet )
371 //CHINA001 : ScHFEditPage( pParent, RID_SCPAGE_HFED_FL, rCoreSet,
372 //CHINA001 rCoreSet.GetPool()->GetWhich(SID_SCATTR_PAGE_FOOTERLEFT) )
373 //CHINA001 {}
374 //CHINA001
375 //CHINA001 // -----------------------------------------------------------------------
376 //CHINA001
377 //CHINA001 USHORT* __EXPORT ScLeftFooterEditPage::GetRanges()
378 //CHINA001 { return pPageLeftFooterRanges; }
379 //CHINA001
380 //CHINA001 // -----------------------------------------------------------------------
381 //CHINA001
382 //CHINA001 SfxTabPage* __EXPORT ScLeftFooterEditPage::Create( Window* pParent, const SfxItemSet& rCoreSet )
383 //CHINA001 { return ( new ScLeftFooterEditPage( pParent, rCoreSet ) ); };
385 //========================================================================
387 void lcl_GetFieldData( ScHeaderFieldData& rData )
389 SfxViewShell* pShell = SfxViewShell::Current();
390 if (pShell)
392 if (pShell->ISA(ScTabViewShell))
393 ((ScTabViewShell*)pShell)->FillFieldData(rData);
394 else if (pShell->ISA(ScPreviewShell))
395 ((ScPreviewShell*)pShell)->FillFieldData(rData);
399 //========================================================================
400 // class ScEditWindow
401 //========================================================================
403 ScEditWindow::ScEditWindow( Window* pParent, const ResId& rResId, ScEditWindowLocation eLoc )
404 : Control( pParent, rResId ),
405 eLocation(eLoc),
406 pAcc(NULL)
408 EnableRTL(FALSE);
410 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
411 Color aBgColor = rStyleSettings.GetWindowColor();
413 SetMapMode( MAP_TWIP );
414 SetPointer( POINTER_TEXT );
415 SetBackground( aBgColor );
417 Size aSize( GetOutputSize() );
418 aSize.Height() *= 4;
420 pEdEngine = new ScHeaderEditEngine( EditEngine::CreatePool(), TRUE );
421 pEdEngine->SetPaperSize( aSize );
422 pEdEngine->SetRefDevice( this );
424 ScHeaderFieldData aData;
425 lcl_GetFieldData( aData );
427 // Feldbefehle:
428 pEdEngine->SetData( aData );
429 pEdEngine->SetControlWord( pEdEngine->GetControlWord() | EE_CNTRL_MARKFIELDS );
430 mbRTL = ScGlobal::IsSystemRTL();
431 if (mbRTL)
432 pEdEngine->SetDefaultHorizontalTextDirection(EE_HTEXTDIR_R2L);
434 pEdView = new EditView( pEdEngine, this );
435 pEdView->SetOutputArea( Rectangle( Point(0,0), GetOutputSize() ) );
437 pEdView->SetBackgroundColor( aBgColor );
438 pEdEngine->InsertView( pEdView );
441 // -----------------------------------------------------------------------
443 __EXPORT ScEditWindow::~ScEditWindow()
445 // delete Accessible object before deleting EditEngine and EditView
446 if (pAcc)
448 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > xTemp = xAcc;
449 if (xTemp.is())
450 pAcc->dispose();
452 delete pEdEngine;
453 delete pEdView;
456 // -----------------------------------------------------------------------
458 void ScEditWindow::SetNumType(SvxNumType eNumType)
460 pEdEngine->SetNumType(eNumType);
461 pEdEngine->UpdateFields();
464 // -----------------------------------------------------------------------
466 EditTextObject* __EXPORT ScEditWindow::CreateTextObject()
468 // wegen #38841# die Absatzattribute zuruecksetzen
469 // (GetAttribs beim Format-Dialog-Aufruf gibt immer gesetzte Items zurueck)
471 const SfxItemSet& rEmpty = pEdEngine->GetEmptyItemSet();
472 USHORT nParCnt = pEdEngine->GetParagraphCount();
473 for (USHORT i=0; i<nParCnt; i++)
474 pEdEngine->SetParaAttribs( i, rEmpty );
476 return pEdEngine->CreateTextObject();
479 // -----------------------------------------------------------------------
481 void ScEditWindow::SetFont( const ScPatternAttr& rPattern )
483 SfxItemSet* pSet = new SfxItemSet( pEdEngine->GetEmptyItemSet() );
484 rPattern.FillEditItemSet( pSet );
485 // FillEditItemSet adjusts font height to 1/100th mm,
486 // but for header/footer twips is needed, as in the PatternAttr:
487 pSet->Put( rPattern.GetItem(ATTR_FONT_HEIGHT), EE_CHAR_FONTHEIGHT );
488 pSet->Put( rPattern.GetItem(ATTR_CJK_FONT_HEIGHT), EE_CHAR_FONTHEIGHT_CJK );
489 pSet->Put( rPattern.GetItem(ATTR_CTL_FONT_HEIGHT), EE_CHAR_FONTHEIGHT_CTL );
490 if (mbRTL)
491 pSet->Put( SvxAdjustItem( SVX_ADJUST_RIGHT, EE_PARA_JUST ) );
492 pEdEngine->SetDefaults( pSet );
495 // -----------------------------------------------------------------------
497 void ScEditWindow::SetText( const EditTextObject& rTextObject )
499 pEdEngine->SetText( rTextObject );
502 // -----------------------------------------------------------------------
504 void ScEditWindow::InsertField( const SvxFieldItem& rFld )
506 pEdView->InsertField( rFld );
509 // -----------------------------------------------------------------------
511 void ScEditWindow::SetCharAttriutes()
513 SfxObjectShell* pDocSh = SfxObjectShell::Current();
515 SfxViewShell* pViewSh = SfxViewShell::Current();
517 ScTabViewShell* pTabViewSh = PTR_CAST(ScTabViewShell, SfxViewShell::Current());
520 DBG_ASSERT( pDocSh, "Current DocShell not found" );
521 DBG_ASSERT( pViewSh, "Current ViewShell not found" );
523 if ( pDocSh && pViewSh )
525 if(pTabViewSh!=NULL) pTabViewSh->SetInFormatDialog(TRUE);
527 SfxItemSet aSet( pEdView->GetAttribs() );
529 //CHINA001 ScCharDlg* pDlg = new ScCharDlg( GetParent(), &aSet, pDocSh );
530 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
531 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
533 SfxAbstractTabDialog* pDlg = pFact->CreateScCharDlg( GetParent(), &aSet,
534 pDocSh,RID_SCDLG_CHAR );
535 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
536 pDlg->SetText( ScGlobal::GetRscString( STR_TEXTATTRS ) );
537 if ( pDlg->Execute() == RET_OK )
539 aSet.ClearItem();
540 aSet.Put( *pDlg->GetOutputItemSet() );
541 pEdView->SetAttribs( aSet );
544 if(pTabViewSh!=NULL) pTabViewSh->SetInFormatDialog(FALSE);
545 delete pDlg;
549 // -----------------------------------------------------------------------
551 void __EXPORT ScEditWindow::Paint( const Rectangle& rRec )
553 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
554 Color aBgColor = rStyleSettings.GetWindowColor();
556 pEdView->SetBackgroundColor( aBgColor );
558 SetBackground( aBgColor );
560 Control::Paint( rRec );
562 pEdView->Paint( rRec );
565 // -----------------------------------------------------------------------
567 void __EXPORT ScEditWindow::MouseMove( const MouseEvent& rMEvt )
569 pEdView->MouseMove( rMEvt );
572 // -----------------------------------------------------------------------
574 void __EXPORT ScEditWindow::MouseButtonDown( const MouseEvent& rMEvt )
576 if ( !HasFocus() )
577 GrabFocus();
579 pEdView->MouseButtonDown( rMEvt );
582 // -----------------------------------------------------------------------
584 void __EXPORT ScEditWindow::MouseButtonUp( const MouseEvent& rMEvt )
586 pEdView->MouseButtonUp( rMEvt );
589 // -----------------------------------------------------------------------
591 void __EXPORT ScEditWindow::KeyInput( const KeyEvent& rKEvt )
593 USHORT nKey = rKEvt.GetKeyCode().GetModifier()
594 + rKEvt.GetKeyCode().GetCode();
596 if ( nKey == KEY_TAB || nKey == KEY_TAB + KEY_SHIFT )
598 Control::KeyInput( rKEvt );
600 else if ( !pEdView->PostKeyEvent( rKEvt ) )
602 Control::KeyInput( rKEvt );
606 // -----------------------------------------------------------------------
608 void ScEditWindow::Command( const CommandEvent& rCEvt )
610 pEdView->Command( rCEvt );
613 // -----------------------------------------------------------------------
615 void __EXPORT ScEditWindow::GetFocus()
617 pActiveEdWnd = this;
619 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > xTemp = xAcc;
620 if (xTemp.is() && pAcc)
622 pAcc->GotFocus();
624 else
625 pAcc = NULL;
628 void __EXPORT ScEditWindow::LoseFocus()
630 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > xTemp = xAcc;
631 if (xTemp.is() && pAcc)
633 pAcc->LostFocus();
635 else
636 pAcc = NULL;
639 // -----------------------------------------------------------------------
641 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > ScEditWindow::CreateAccessible()
643 String sName;
644 String sDescription(GetHelpText());
645 switch (eLocation)
647 case Left:
649 sName = String(ScResId(STR_ACC_LEFTAREA_NAME));
650 // sDescription = String(ScResId(STR_ACC_LEFTAREA_DESCR));
652 break;
653 case Center:
655 sName = String(ScResId(STR_ACC_CENTERAREA_NAME));
656 // sDescription = String(ScResId(STR_ACC_CENTERAREA_DESCR));
658 break;
659 case Right:
661 sName = String(ScResId(STR_ACC_RIGHTAREA_NAME));
662 // sDescription = String(ScResId(STR_ACC_RIGHTAREA_DESCR));
664 break;
666 pAcc = new ScAccessibleEditObject(GetAccessibleParentWindow()->GetAccessible(), pEdView, this,
667 rtl::OUString(sName), rtl::OUString(sDescription), EditControl);
668 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > xAccessible = pAcc;
669 xAcc = xAccessible;
670 return pAcc;
674 class ScExtIButton : public ImageButton
676 private:
678 Timer aTimer;
679 ScPopupMenu* pPopupMenu;
681 DECL_LINK( TimerHdl, Timer*);
683 void DrawArrow();
685 protected:
687 virtual void MouseButtonDown( const MouseEvent& rMEvt );
688 virtual void MouseButtonUp( const MouseEvent& rMEvt);
690 virtual void StartPopup();
692 public:
694 ScExtIButton(Window* pParent, const ResId& rResId );
696 void SetPopupMenu(ScPopupMenu* pPopUp);
698 USHORT GetSelected();
700 void SetMenuHdl( const Link& rLink ) { aFxLink = rLink; }
701 const Link& GetMenuHdl() const { return aFxLink; }
705 ScExtIButton::ScExtIButton(Window* pParent, const ResId& rResId )
706 : ImageButton(pParent,rResId),
707 pPopupMenu(NULL)
709 nSelected=0;
710 aTimer.SetTimeout(600);
711 SetDropDown( TRUE);
713 // DrawArrow();
716 void ScExtIButton::SetPopupMenu(ScPopupMenu* pPopUp)
718 pPopupMenu=pPopUp;
721 USHORT ScExtIButton::GetSelected()
723 return nSelected;
726 void ScExtIButton::MouseButtonDown( const MouseEvent& rMEvt )
728 if(!aTimer.IsActive())
730 aTimer.Start();
731 aTimer.SetTimeoutHdl(LINK( this, ScExtIButton, TimerHdl));
734 ImageButton::MouseButtonDown(rMEvt );
736 void ScExtIButton::MouseButtonUp( const MouseEvent& rMEvt)
738 aTimer.Stop();
739 aTimer.SetTimeoutHdl(Link());
740 ImageButton::MouseButtonUp(rMEvt );
743 void ScExtIButton::Click()
745 aTimer.Stop();
746 aTimer.SetTimeoutHdl(Link());
747 ImageButton::Click();
750 void ScExtIButton::StartPopup()
752 nSelected=0;
754 if(pPopupMenu!=NULL)
756 SetPressed( TRUE );
757 EndSelection();
758 Point aPoint(0,0);
759 aPoint.Y()=GetOutputSizePixel().Height();
761 nSelected=pPopupMenu->Execute( this, aPoint );
763 if(nSelected)
765 aMLink.Call(this);
767 SetPressed( FALSE);
771 long ScExtIButton::PreNotify( NotifyEvent& rNEvt )
773 USHORT nSwitch=rNEvt.GetType();
774 if(nSwitch==EVENT_MOUSEBUTTONUP)
776 MouseButtonUp(*rNEvt.GetMouseEvent());
779 return ImageButton::PreNotify(rNEvt );
782 IMPL_LINK( ScExtIButton, TimerHdl, Timer*, EMPTYARG )
784 StartPopup();
785 return 0;
789 static void ImplDrawToolArrow( ToolBox* pBox, long nX, long nY, BOOL bBlack,
790 BOOL bLeft = FALSE, BOOL bTop = FALSE )
792 Color aOldFillColor = pBox->GetFillColor();
793 WindowAlign eAlign = pBox->meAlign;
794 if ( bLeft )
795 eAlign = WINDOWALIGN_RIGHT;
796 else if ( bTop )
797 eAlign = WINDOWALIGN_BOTTOM;
799 switch ( eAlign )
801 case WINDOWALIGN_LEFT:
802 if ( bBlack )
803 pBox->SetFillColor( Color( COL_BLACK ) );
804 pBox->DrawRect( Rectangle( nX+0, nY+0, nX+0, nY+6 ) );
805 pBox->DrawRect( Rectangle( nX+1, nY+1, nX+1, nY+5 ) );
806 pBox->DrawRect( Rectangle( nX+2, nY+2, nX+2, nY+4 ) );
807 pBox->DrawRect( Rectangle( nX+3, nY+3, nX+3, nY+3 ) );
808 if ( bBlack )
810 pBox->SetFillColor( aOldFillColor );
811 pBox->DrawRect( Rectangle( nX+1, nY+2, nX+1, nY+4 ) );
812 pBox->DrawRect( Rectangle( nX+2, nY+3, nX+2, nY+3 ) );
814 break;
815 case WINDOWALIGN_TOP:
816 if ( bBlack )
817 pBox->SetFillColor( Color( COL_BLACK ) );
818 pBox->DrawRect( Rectangle( nX+0, nY+0, nX+6, nY+0 ) );
819 pBox->DrawRect( Rectangle( nX+1, nY+1, nX+5, nY+1 ) );
820 pBox->DrawRect( Rectangle( nX+2, nY+2, nX+4, nY+2 ) );
821 pBox->DrawRect( Rectangle( nX+3, nY+3, nX+3, nY+3 ) );
822 if ( bBlack )
824 pBox->SetFillColor( aOldFillColor );
825 pBox->DrawRect( Rectangle( nX+2, nY+1, nX+4, nY+1 ) );
826 pBox->DrawRect( Rectangle( nX+3, nY+2, nX+3, nY+2 ) );
828 break;
829 case WINDOWALIGN_RIGHT:
830 if ( bBlack )
831 pBox->SetFillColor( Color( COL_BLACK ) );
832 pBox->DrawRect( Rectangle( nX+3, nY+0, nX+3, nY+6 ) );
833 pBox->DrawRect( Rectangle( nX+2, nY+1, nX+2, nY+5 ) );
834 pBox->DrawRect( Rectangle( nX+1, nY+2, nX+1, nY+4 ) );
835 pBox->DrawRect( Rectangle( nX+0, nY+3, nX+0, nY+3 ) );
836 if ( bBlack )
838 pBox->SetFillColor( aOldFillColor );
839 pBox->DrawRect( Rectangle( nX+2, nY+2, nX+2, nY+4 ) );
840 pBox->DrawRect( Rectangle( nX+1, nY+3, nX+1, nY+3 ) );
842 break;
843 case WINDOWALIGN_BOTTOM:
844 if ( bBlack )
845 pBox->SetFillColor( Color( COL_BLACK ) );
846 pBox->DrawRect( Rectangle( nX+0, nY+3, nX+6, nY+3 ) );
847 pBox->DrawRect( Rectangle( nX+1, nY+2, nX+5, nY+2 ) );
848 pBox->DrawRect( Rectangle( nX+2, nY+1, nX+4, nY+1 ) );
849 pBox->DrawRect( Rectangle( nX+3, nY+0, nX+3, nY+0 ) );
850 if ( bBlack )
852 pBox->SetFillColor( aOldFillColor );
853 pBox->DrawRect( Rectangle( nX+2, nY+2, nX+4, nY+2 ) );
854 pBox->DrawRect( Rectangle( nX+3, nY+1, nX+3, nY+1 ) );
856 break;
859 Down
860 - Timer starten
862 Click
863 - Timer abbrechen
865 Timer
866 if ( ??? )
868 - SetPressed( TRUE );
869 - EndSelection();
870 - Menu anzeigen
871 - SetPressed( FALSE );