xref: /trunk/main/sc/source/ui/pagedlg/tphfedit.cxx (revision b3f79822)
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 }
557 
558 // -----------------------------------------------------------------------
559 
560 void __EXPORT ScEditWindow::MouseMove( const MouseEvent& rMEvt )
561 {
562 	pEdView->MouseMove( rMEvt );
563 }
564 
565 // -----------------------------------------------------------------------
566 
567 void __EXPORT ScEditWindow::MouseButtonDown( const MouseEvent& rMEvt )
568 {
569 	if ( !HasFocus() )
570 		GrabFocus();
571 
572 	pEdView->MouseButtonDown( rMEvt );
573 }
574 
575 // -----------------------------------------------------------------------
576 
577 void __EXPORT ScEditWindow::MouseButtonUp( const MouseEvent& rMEvt )
578 {
579 	pEdView->MouseButtonUp( rMEvt );
580 }
581 
582 // -----------------------------------------------------------------------
583 
584 void __EXPORT ScEditWindow::KeyInput( const KeyEvent& rKEvt )
585 {
586 	sal_uInt16 nKey =  rKEvt.GetKeyCode().GetModifier()
587 				 + rKEvt.GetKeyCode().GetCode();
588 
589 	if ( nKey == KEY_TAB || nKey == KEY_TAB + KEY_SHIFT )
590 	{
591 		Control::KeyInput( rKEvt );
592 	}
593 	else if ( !pEdView->PostKeyEvent( rKEvt ) )
594 	{
595 		Control::KeyInput( rKEvt );
596 	}
597 }
598 
599 // -----------------------------------------------------------------------
600 
601 void ScEditWindow::Command( const CommandEvent& rCEvt )
602 {
603 	pEdView->Command( rCEvt );
604 }
605 
606 // -----------------------------------------------------------------------
607 
608 void __EXPORT ScEditWindow::GetFocus()
609 {
610 	pActiveEdWnd = this;
611 
612     ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > xTemp = xAcc;
613     if (xTemp.is() && pAcc)
614     {
615         pAcc->GotFocus();
616     }
617     else
618         pAcc = NULL;
619 }
620 
621 void __EXPORT ScEditWindow::LoseFocus()
622 {
623     ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > xTemp = xAcc;
624     if (xTemp.is() && pAcc)
625     {
626         pAcc->LostFocus();
627     }
628     else
629         pAcc = NULL;
630 }
631 
632 // -----------------------------------------------------------------------
633 
634 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > ScEditWindow::CreateAccessible()
635 {
636     String sName;
637     String sDescription(GetHelpText());
638     switch (eLocation)
639     {
640     case Left:
641         {
642             sName = String(ScResId(STR_ACC_LEFTAREA_NAME));
643 //            sDescription = String(ScResId(STR_ACC_LEFTAREA_DESCR));
644         }
645         break;
646     case Center:
647         {
648             sName = String(ScResId(STR_ACC_CENTERAREA_NAME));
649 //            sDescription = String(ScResId(STR_ACC_CENTERAREA_DESCR));
650         }
651         break;
652     case Right:
653         {
654             sName = String(ScResId(STR_ACC_RIGHTAREA_NAME));
655 //            sDescription = String(ScResId(STR_ACC_RIGHTAREA_DESCR));
656         }
657         break;
658     }
659     pAcc = new ScAccessibleEditObject(GetAccessibleParentWindow()->GetAccessible(), pEdView, this,
660         rtl::OUString(sName), rtl::OUString(sDescription), EditControl);
661     ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > xAccessible = pAcc;
662     xAcc = xAccessible;
663     return pAcc;
664 }
665 
666 /*
667 class ScExtIButton : public ImageButton
668 {
669 private:
670 
671 	Timer			aTimer;
672 	ScPopupMenu*	pPopupMenu;
673 
674 	DECL_LINK( TimerHdl, Timer*);
675 
676 	void			DrawArrow();
677 
678 protected:
679 
680 	virtual void	MouseButtonDown( const MouseEvent& rMEvt );
681 	virtual void	MouseButtonUp( const MouseEvent& rMEvt);
682 
683 	virtual void	StartPopup();
684 
685 public:
686 
687 	ScExtIButton(Window* pParent, const ResId& rResId );
688 
689 	void			SetPopupMenu(ScPopupMenu* pPopUp);
690 
691 	sal_uInt16			GetSelected();
692 
693 	void            SetMenuHdl( const Link& rLink ) { aFxLink = rLink; }
694 	const Link&     GetMenuHdl() const { return aFxLink; }
695 
696 }
697 */
698 ScExtIButton::ScExtIButton(Window* pParent, const ResId& rResId )
699 :	ImageButton(pParent,rResId),
700 	pPopupMenu(NULL)
701 {
702 	nSelected=0;
703 	aTimer.SetTimeout(600);
704 	SetDropDown( sal_True);
705 
706 //	DrawArrow();
707 }
708 
709 void ScExtIButton::SetPopupMenu(ScPopupMenu* pPopUp)
710 {
711 	pPopupMenu=pPopUp;
712 }
713 
714 sal_uInt16 ScExtIButton::GetSelected()
715 {
716 	return nSelected;
717 }
718 
719 void ScExtIButton::MouseButtonDown( const MouseEvent& rMEvt )
720 {
721 	if(!aTimer.IsActive())
722 	{
723 		aTimer.Start();
724 		aTimer.SetTimeoutHdl(LINK( this, ScExtIButton, TimerHdl));
725 	}
726 
727 	ImageButton::MouseButtonDown(rMEvt );
728 }
729 void ScExtIButton::MouseButtonUp( const MouseEvent& rMEvt)
730 {
731 	aTimer.Stop();
732 	aTimer.SetTimeoutHdl(Link());
733 	ImageButton::MouseButtonUp(rMEvt );
734 }
735 
736 void ScExtIButton::Click()
737 {
738 	aTimer.Stop();
739 	aTimer.SetTimeoutHdl(Link());
740 	ImageButton::Click();
741 }
742 
743 void ScExtIButton::StartPopup()
744 {
745 	nSelected=0;
746 
747 	if(pPopupMenu!=NULL)
748 	{
749 		SetPressed( sal_True );
750 		EndSelection();
751 		Point aPoint(0,0);
752 		aPoint.Y()=GetOutputSizePixel().Height();
753 
754 		nSelected=pPopupMenu->Execute( this, aPoint );
755 
756 		if(nSelected)
757 		{
758 			aMLink.Call(this);
759 		}
760 		SetPressed( sal_False);
761 	}
762 }
763 
764 long ScExtIButton::PreNotify( NotifyEvent& rNEvt )
765 {
766 	sal_uInt16 nSwitch=rNEvt.GetType();
767 	if(nSwitch==EVENT_MOUSEBUTTONUP)
768 	{
769 		MouseButtonUp(*rNEvt.GetMouseEvent());
770 	}
771 
772 	return ImageButton::PreNotify(rNEvt );
773 }
774 
775 IMPL_LINK( ScExtIButton, TimerHdl, Timer*, EMPTYARG )
776 {
777 	StartPopup();
778 	return 0;
779 }
780 
781 /*
782 static void ImplDrawToolArrow( ToolBox* pBox, long nX, long nY, sal_Bool bBlack,
783 							   sal_Bool bLeft = sal_False, sal_Bool bTop = sal_False )
784 {
785 	Color			aOldFillColor = pBox->GetFillColor();
786 	WindowAlign 	eAlign = pBox->meAlign;
787 	if ( bLeft )
788 		eAlign = WINDOWALIGN_RIGHT;
789 	else if ( bTop )
790 		eAlign = WINDOWALIGN_BOTTOM;
791 
792 	switch ( eAlign )
793 	{
794 		case WINDOWALIGN_LEFT:
795 			if ( bBlack )
796 				pBox->SetFillColor( Color( COL_BLACK ) );
797 			pBox->DrawRect( Rectangle( nX+0, nY+0, nX+0, nY+6 ) );
798 			pBox->DrawRect( Rectangle( nX+1, nY+1, nX+1, nY+5 ) );
799 			pBox->DrawRect( Rectangle( nX+2, nY+2, nX+2, nY+4 ) );
800 			pBox->DrawRect( Rectangle( nX+3, nY+3, nX+3, nY+3 ) );
801 			if ( bBlack )
802 			{
803 				pBox->SetFillColor( aOldFillColor );
804 				pBox->DrawRect( Rectangle( nX+1, nY+2, nX+1, nY+4 ) );
805 				pBox->DrawRect( Rectangle( nX+2, nY+3, nX+2, nY+3 ) );
806 			}
807 			break;
808 		case WINDOWALIGN_TOP:
809 			if ( bBlack )
810 				pBox->SetFillColor( Color( COL_BLACK ) );
811 			pBox->DrawRect( Rectangle( nX+0, nY+0, nX+6, nY+0 ) );
812 			pBox->DrawRect( Rectangle( nX+1, nY+1, nX+5, nY+1 ) );
813 			pBox->DrawRect( Rectangle( nX+2, nY+2, nX+4, nY+2 ) );
814 			pBox->DrawRect( Rectangle( nX+3, nY+3, nX+3, nY+3 ) );
815 			if ( bBlack )
816 			{
817 				pBox->SetFillColor( aOldFillColor );
818 				pBox->DrawRect( Rectangle( nX+2, nY+1, nX+4, nY+1 ) );
819 				pBox->DrawRect( Rectangle( nX+3, nY+2, nX+3, nY+2 ) );
820 			}
821 			break;
822 		case WINDOWALIGN_RIGHT:
823 			if ( bBlack )
824 				pBox->SetFillColor( Color( COL_BLACK ) );
825 			pBox->DrawRect( Rectangle( nX+3, nY+0, nX+3, nY+6 ) );
826 			pBox->DrawRect( Rectangle( nX+2, nY+1, nX+2, nY+5 ) );
827 			pBox->DrawRect( Rectangle( nX+1, nY+2, nX+1, nY+4 ) );
828 			pBox->DrawRect( Rectangle( nX+0, nY+3, nX+0, nY+3 ) );
829 			if ( bBlack )
830 			{
831 				pBox->SetFillColor( aOldFillColor );
832 				pBox->DrawRect( Rectangle( nX+2, nY+2, nX+2, nY+4 ) );
833 				pBox->DrawRect( Rectangle( nX+1, nY+3, nX+1, nY+3 ) );
834 			}
835 			break;
836 		case WINDOWALIGN_BOTTOM:
837 			if ( bBlack )
838 				pBox->SetFillColor( Color( COL_BLACK ) );
839 			pBox->DrawRect( Rectangle( nX+0, nY+3, nX+6, nY+3 ) );
840 			pBox->DrawRect( Rectangle( nX+1, nY+2, nX+5, nY+2 ) );
841 			pBox->DrawRect( Rectangle( nX+2, nY+1, nX+4, nY+1 ) );
842 			pBox->DrawRect( Rectangle( nX+3, nY+0, nX+3, nY+0 ) );
843 			if ( bBlack )
844 			{
845 				pBox->SetFillColor( aOldFillColor );
846 				pBox->DrawRect( Rectangle( nX+2, nY+2, nX+4, nY+2 ) );
847 				pBox->DrawRect( Rectangle( nX+3, nY+1, nX+3, nY+1 ) );
848 			}
849 			break;
850 	}
851 }
852 Down
853 	- Timer starten
854 
855 Click
856 	- Timer abbrechen
857 
858 Timer
859 	if ( ??? )
860 	{
861 	- SetPressed( sal_True );
862 	- EndSelection();
863 	- Menu anzeigen
864 	- SetPressed( sal_False );
865 	}
866 
867 
868 */
869 
870 
871