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