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