merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / pagedlg / scuitphfedit.cxx
blobe0448432c6dca405b9e9cc843c8510a1d1538471
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: scuitphfedit.cxx,v $
10 * $Revision: 1.10.172.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #undef SC_DLLIMPLEMENTATION
38 //------------------------------------------------------------------
40 #define _TPHFEDIT_CXX
41 #include "scitems.hxx"
42 #include <svx/eeitem.hxx>
44 //CHINA001 #include <svx/chardlg.hxx>
45 #include <svx/editobj.hxx>
46 #include <svx/editstat.hxx>
47 #include <svx/editview.hxx>
48 #include <svx/flditem.hxx>
49 #include <sfx2/basedlgs.hxx>
50 #include <sfx2/objsh.hxx>
51 #include <vcl/msgbox.hxx>
52 #include <vcl/svapp.hxx>
53 #include <svtools/useroptions.hxx>
54 #define _SVSTDARR_USHORTS
55 #include <svtools/svstdarr.hxx>
57 //CHINA001 #include "tphfedit.hxx"
58 #include "editutil.hxx"
59 #include "global.hxx"
60 #include "attrib.hxx"
61 #include "patattr.hxx"
62 #include "scresid.hxx"
63 #include "sc.hrc"
64 #include "globstr.hrc"
65 #include "tabvwsh.hxx"
66 #include "prevwsh.hxx"
67 #include "hfedtdlg.hrc"
68 #include "textdlgs.hxx"
69 #include "AccessibleEditObject.hxx"
71 #include "scuitphfedit.hxx" //CHINA001
72 #include <memory> // header file for auto_ptr
74 // STATIC DATA -----------------------------------------------------------
76 static USHORT pPageRightHeaderRanges[] = { SID_SCATTR_PAGE_HEADERRIGHT,
77 SID_SCATTR_PAGE_HEADERRIGHT,
78 0 };
80 static USHORT pPageRightFooterRanges[] = { SID_SCATTR_PAGE_FOOTERRIGHT,
81 SID_SCATTR_PAGE_FOOTERRIGHT,
82 0 };
84 static USHORT pPageLeftHeaderRanges[] = { SID_SCATTR_PAGE_HEADERLEFT,
85 SID_SCATTR_PAGE_HEADERLEFT,
86 0 };
88 static USHORT pPageLeftFooterRanges[] = { SID_SCATTR_PAGE_FOOTERLEFT,
89 SID_SCATTR_PAGE_FOOTERLEFT,
90 0 };
93 static ScEditWindow* pActiveEdWnd = NULL;
96 //========================================================================
97 // class ScHFEditPage
100 ScHFEditPage::ScHFEditPage( Window* pParent,
101 USHORT nResId,
102 const SfxItemSet& rCoreAttrs,
103 USHORT nWhichId,
104 bool bHeader )
106 : SfxTabPage ( pParent, ScResId( nResId ), rCoreAttrs ),
108 aFtLeft ( this, ScResId( FT_LEFT ) ),
109 aWndLeft ( this, ScResId( WND_LEFT ), Left ),
110 aFtCenter ( this, ScResId( FT_CENTER ) ),
111 aWndCenter ( this, ScResId( WND_CENTER ), Center ),
112 aFtRight ( this, ScResId( FT_RIGHT ) ),
113 aWndRight ( this, ScResId( WND_RIGHT ), Right ),
114 maFtDefinedHF ( this, ScResId( FT_HF_DEFINED ) ),
115 maLbDefined ( this, ScResId( LB_DEFINED ) ),
116 maFtCustomHF ( this, ScResId( FT_HF_CUSTOM ) ),
117 aBtnText ( this, ScResId( BTN_TEXT ) ),
118 aBtnFile ( this, ScResId( BTN_FILE ) ),
119 aBtnTable ( this, ScResId( BTN_TABLE ) ),
120 aBtnPage ( this, ScResId( BTN_PAGE ) ),
121 aBtnLastPage ( this, ScResId( BTN_PAGES ) ),
122 aBtnDate ( this, ScResId( BTN_DATE ) ),
123 aBtnTime ( this, ScResId( BTN_TIME ) ),
124 aFlInfo ( this, ScResId( FL_INFO ) ),
125 aFtInfo ( this, ScResId( FT_INFO ) ),
126 aPopUpFile ( ScResId( RID_POPUP_FCOMMAND) ),
127 nWhich ( nWhichId )
129 //! use default style from current document?
130 //! if font color is used, header/footer background color must be set
132 ScPatternAttr aPatAttr( rCoreAttrs.GetPool() );
135 aBtnFile.SetPopupMenu(&aPopUpFile);
137 maLbDefined.SetSelectHdl( LINK( this, ScHFEditPage, ListHdl_Impl ) );
138 aBtnFile.SetMenuHdl( LINK( this, ScHFEditPage, MenuHdl ) );
139 aBtnText .SetClickHdl( LINK( this, ScHFEditPage, ClickHdl ) );
140 aBtnPage .SetClickHdl( LINK( this, ScHFEditPage, ClickHdl ) );
141 aBtnLastPage.SetClickHdl( LINK( this, ScHFEditPage, ClickHdl ) );
142 aBtnDate .SetClickHdl( LINK( this, ScHFEditPage, ClickHdl ) );
143 aBtnTime .SetClickHdl( LINK( this, ScHFEditPage, ClickHdl ) );
144 aBtnFile .SetClickHdl( LINK( this, ScHFEditPage, ClickHdl ) );
145 aBtnTable .SetClickHdl( LINK( this, ScHFEditPage, ClickHdl ) );
147 aBtnText .SetModeImage( Image( ScResId( IMG_TEXT_H ) ), BMP_COLOR_HIGHCONTRAST );
148 aBtnFile .SetModeImage( Image( ScResId( IMG_FILE_H ) ), BMP_COLOR_HIGHCONTRAST );
149 aBtnTable .SetModeImage( Image( ScResId( IMG_TABLE_H ) ), BMP_COLOR_HIGHCONTRAST );
150 aBtnPage .SetModeImage( Image( ScResId( IMG_PAGE_H ) ), BMP_COLOR_HIGHCONTRAST );
151 aBtnLastPage.SetModeImage( Image( ScResId( IMG_PAGES_H ) ), BMP_COLOR_HIGHCONTRAST );
152 aBtnDate .SetModeImage( Image( ScResId( IMG_DATE_H ) ), BMP_COLOR_HIGHCONTRAST );
153 aBtnTime .SetModeImage( Image( ScResId( IMG_TIME_H ) ), BMP_COLOR_HIGHCONTRAST );
155 if(!bHeader)
157 maFtDefinedHF.SetText(ScGlobal::GetRscString( STR_FOOTER ));
158 maFtCustomHF.SetText(ScGlobal::GetRscString( STR_HF_CUSTOM_FOOTER ));
160 if( Application::GetSettings().GetLayoutRTL() )
162 Point pt1 = aWndLeft.GetPosPixel();
163 Point pt2 = aWndRight.GetPosPixel();
164 aWndLeft.SetPosPixel(pt2);
165 aWndRight.SetPosPixel(pt1);
167 pt1 = aFtLeft.GetPosPixel();
168 pt2 = aFtRight.GetPosPixel();
169 aFtLeft.SetPosPixel(pt2);
170 aFtRight.SetPosPixel(pt1);
172 aWndLeft. SetFont( aPatAttr );
173 aWndCenter. SetFont( aPatAttr );
174 aWndRight. SetFont( aPatAttr );
176 FillCmdArr();
178 aWndLeft.GrabFocus();
180 InitPreDefinedList();
182 FreeResource();
185 // -----------------------------------------------------------------------
187 __EXPORT ScHFEditPage::~ScHFEditPage()
191 void ScHFEditPage::SetNumType(SvxNumType eNumType)
193 aWndLeft.SetNumType(eNumType);
194 aWndCenter.SetNumType(eNumType);
195 aWndRight.SetNumType(eNumType);
198 // -----------------------------------------------------------------------
200 #define IS_AVAILABLE(w)(rCoreSet.GetItemState( (w) ) >= SFX_ITEM_AVAILABLE)
202 void __EXPORT ScHFEditPage::Reset( const SfxItemSet& rCoreSet )
204 if ( IS_AVAILABLE( nWhich ) )
206 const ScPageHFItem& rItem = (const ScPageHFItem&)(rCoreSet.Get( nWhich ));
208 if( const EditTextObject* pLeft = rItem.GetLeftArea() )
209 aWndLeft.SetText( *pLeft );
210 if( const EditTextObject* pCenter = rItem.GetCenterArea() )
211 aWndCenter.SetText( *pCenter );
212 if( const EditTextObject* pRight = rItem.GetRightArea() )
213 aWndRight.SetText( *pRight );
215 SetSelectDefinedList();
219 #undef IS_AVAILABLE
221 // -----------------------------------------------------------------------
223 BOOL __EXPORT ScHFEditPage::FillItemSet( SfxItemSet& rCoreSet )
225 ScPageHFItem aItem( nWhich );
226 EditTextObject* pLeft = aWndLeft .CreateTextObject();
227 EditTextObject* pCenter = aWndCenter.CreateTextObject();
228 EditTextObject* pRight = aWndRight .CreateTextObject();
230 aItem.SetLeftArea ( *pLeft );
231 aItem.SetCenterArea( *pCenter );
232 aItem.SetRightArea ( *pRight );
233 delete pLeft;
234 delete pCenter;
235 delete pRight;
237 rCoreSet.Put( aItem );
239 return TRUE;
242 // -----------------------------------------------------------------------
244 #define SET_CMD(i,id) \
245 aCmd = aDel; \
246 aCmd += ScGlobal::GetRscString( id ); \
247 aCmd += aDel; \
248 aCmdArr[i] = aCmd;
250 // -----------------------------------------------------------------------
252 void ScHFEditPage::FillCmdArr()
254 String aDel( ScGlobal::GetRscString( STR_HFCMD_DELIMITER ) );
255 String aCmd;
257 SET_CMD( 0, STR_HFCMD_PAGE )
258 SET_CMD( 1, STR_HFCMD_PAGES )
259 SET_CMD( 2, STR_HFCMD_DATE )
260 SET_CMD( 3, STR_HFCMD_TIME )
261 SET_CMD( 4, STR_HFCMD_FILE )
262 SET_CMD( 5, STR_HFCMD_TABLE )
265 #undef SET_CMD
267 void ScHFEditPage::InitPreDefinedList()
269 SvtUserOptions aUserOpt;
271 Color* pTxtColour = NULL;
272 Color* pFldColour = NULL;
274 // Get the all field values at the outset.
275 String aPageFieldValue(aWndLeft.GetEditEngine()->CalcFieldValue(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), 0,0, pTxtColour, pFldColour));
276 String aSheetFieldValue(aWndLeft.GetEditEngine()->CalcFieldValue(SvxFieldItem(SvxTableField(), EE_FEATURE_FIELD), 0,0, pTxtColour, pFldColour));
277 String aFileFieldValue(aWndLeft.GetEditEngine()->CalcFieldValue(SvxFieldItem(SvxFileField(), EE_FEATURE_FIELD), 0,0, pTxtColour, pFldColour));
278 String aExtFileFieldValue(aWndLeft.GetEditEngine()->CalcFieldValue(SvxFieldItem(SvxExtFileField(), EE_FEATURE_FIELD), 0,0, pTxtColour, pFldColour));
279 String aDateFieldValue(aWndLeft.GetEditEngine()->CalcFieldValue(SvxFieldItem(SvxDateField(), EE_FEATURE_FIELD), 0,0, pTxtColour, pFldColour));
281 maLbDefined.Clear();
283 maLbDefined.InsertEntry( ScGlobal::GetRscString( STR_HF_NONE_IN_BRACKETS ));
285 String aPageEntry(ScGlobal::GetRscString( STR_PAGE ) );
286 aPageEntry += ' ';
287 aPageEntry += aPageFieldValue;
288 maLbDefined.InsertEntry(aPageEntry);
290 String aPageOfEntry(aPageEntry);
291 aPageOfEntry += ' ';
292 aPageOfEntry += ScGlobal::GetRscString( STR_HF_OF_QUESTION );
293 maLbDefined.InsertEntry( aPageOfEntry);
295 maLbDefined.InsertEntry(aSheetFieldValue);
297 String aConfidentialEntry(aUserOpt.GetCompany());
298 aConfidentialEntry += ' ';
299 aConfidentialEntry += ScGlobal::GetRscString( STR_HF_CONFIDENTIAL );
300 aConfidentialEntry.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
301 aConfidentialEntry += aDateFieldValue;
302 aConfidentialEntry.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
303 aConfidentialEntry += aPageEntry;
304 maLbDefined.InsertEntry( aConfidentialEntry);
306 String aFileNamePageEntry(aFileFieldValue);
307 aFileNamePageEntry.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
308 aFileNamePageEntry += aPageEntry;
309 maLbDefined.InsertEntry( aFileNamePageEntry);
311 maLbDefined.InsertEntry( aExtFileFieldValue);
313 String aPageSheetNameEntry(aPageEntry);
314 aPageSheetNameEntry.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
315 aPageSheetNameEntry += aSheetFieldValue;
316 maLbDefined.InsertEntry( aPageSheetNameEntry);
318 String aPageFileNameEntry(aPageEntry);
319 aPageFileNameEntry.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
320 aPageFileNameEntry += aFileFieldValue;
321 maLbDefined.InsertEntry( aPageFileNameEntry);
323 String aPagePathNameEntry(aPageEntry);
324 aPagePathNameEntry.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
325 aPagePathNameEntry += aExtFileFieldValue;
326 maLbDefined.InsertEntry( aPagePathNameEntry);
328 String aUserNameEntry(aUserOpt.GetFirstName());
329 aUserNameEntry += ' ';
330 aUserNameEntry += (String)aUserOpt.GetLastName();
331 aUserNameEntry.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
332 aUserNameEntry += aPageEntry;
333 aUserNameEntry.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
334 aUserNameEntry += aDateFieldValue;
335 maLbDefined.InsertEntry( aUserNameEntry);
337 String aCreatedByEntry(ScGlobal::GetRscString( STR_HF_CREATED_BY ) );
338 aCreatedByEntry += ' ';
339 aCreatedByEntry += (String)aUserOpt.GetFirstName();
340 aCreatedByEntry += ' ';
341 aCreatedByEntry += (String)aUserOpt.GetLastName();
342 aCreatedByEntry.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
343 aCreatedByEntry += aDateFieldValue;
344 aCreatedByEntry.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
345 aCreatedByEntry += aPageEntry;
346 maLbDefined.InsertEntry( aCreatedByEntry);
349 void ScHFEditPage::InsertToDefinedList()
351 USHORT nCount = maLbDefined.GetEntryCount();
352 if(nCount == eEntryCount)
354 String aCustomizedEntry(ScGlobal::GetRscString( STR_HF_CUSTOMIZED ) );
355 maLbDefined.InsertEntry( aCustomizedEntry);
356 maLbDefined.SelectEntryPos(eEntryCount);
360 void ScHFEditPage::RemoveFromDefinedList()
362 USHORT nCount = maLbDefined.GetEntryCount();
363 if(nCount > eEntryCount )
364 maLbDefined.RemoveEntry( nCount-1);
367 // determine if the header/footer exists in our predefined list and set select to it.
368 void ScHFEditPage::SetSelectDefinedList()
370 SvtUserOptions aUserOpt;
372 // default to customized
373 ScHFEntryId eSelectEntry = eEntryCount;
375 ::std::auto_ptr< EditTextObject > pLeftObj;
376 ::std::auto_ptr< EditTextObject > pCenterObj;
377 ::std::auto_ptr< EditTextObject > pRightObj;
379 XubString aLeftEntry;
380 XubString aCenterEntry;
381 XubString aRightEntry;
383 pLeftObj.reset(aWndLeft.GetEditEngine()->CreateTextObject());
384 pCenterObj.reset(aWndCenter.GetEditEngine()->CreateTextObject());
385 pRightObj.reset(aWndRight.GetEditEngine()->CreateTextObject());
387 bool bFound = false;
389 USHORT i;
390 USHORT nCount = maLbDefined.GetEntryCount();
391 for(i = 0; i < nCount && !bFound; i++)
393 switch(static_cast<ScHFEntryId>(i))
395 case eNoneEntry:
397 aLeftEntry = pLeftObj->GetText(0);
398 aCenterEntry = pCenterObj->GetText(0);
399 aRightEntry = pRightObj->GetText(0);
400 if(aLeftEntry == EMPTY_STRING && aCenterEntry == EMPTY_STRING
401 && aRightEntry == EMPTY_STRING)
403 eSelectEntry = eNoneEntry;
404 bFound = true;
407 break;
409 case ePageEntry:
411 aLeftEntry = pLeftObj->GetText(0);
412 aRightEntry = pRightObj->GetText(0);
413 if(aLeftEntry == EMPTY_STRING && aRightEntry == EMPTY_STRING)
415 if(IsPageEntry(aWndCenter.GetEditEngine(), pCenterObj.get()))
417 eSelectEntry = ePageEntry;
418 bFound = true;
422 break;
425 //TODO
426 case ePagesEntry:
429 break;
431 case eSheetEntry:
433 aLeftEntry = pLeftObj->GetText(0);
434 aRightEntry = pRightObj->GetText(0);
435 if(aLeftEntry == EMPTY_STRING && aRightEntry == EMPTY_STRING)
437 if(pCenterObj->IsFieldObject())
439 const SvxFieldItem* pFieldItem = pCenterObj->GetField();
440 if(pFieldItem)
442 const SvxFieldData* pField = pFieldItem->GetField();
443 if(pField && pField->ISA(SvxTableField))
445 eSelectEntry = eSheetEntry;
446 bFound = true;
452 break;
454 case eConfidentialEntry:
456 if(IsDateEntry(pCenterObj.get()) && IsPageEntry(aWndRight.GetEditEngine(), pRightObj.get()))
458 String aConfidentialEntry(aUserOpt.GetCompany());
459 aConfidentialEntry += ' ';
460 aConfidentialEntry += ScGlobal::GetRscString( STR_HF_CONFIDENTIAL );
461 if(aConfidentialEntry == aWndLeft.GetEditEngine()->GetText(0))
463 eSelectEntry = eConfidentialEntry;
464 bFound = true;
468 break;
470 //TODO
471 case eFileNamePageEntry:
474 break;
476 case eExtFileNameEntry:
478 aLeftEntry = pLeftObj->GetText(0);
479 aRightEntry = pRightObj->GetText(0);
480 if(IsExtFileNameEntry(pCenterObj.get()) && aLeftEntry == EMPTY_STRING
481 && aRightEntry == EMPTY_STRING)
483 eSelectEntry = eExtFileNameEntry;
484 bFound = true;
487 break;
489 //TODO
490 case ePageSheetEntry:
493 break;
495 //TODO
496 case ePageFileNameEntry:
499 break;
501 case ePageExtFileNameEntry:
503 aLeftEntry = pLeftObj->GetText(0);
504 if(IsPageEntry(aWndCenter.GetEditEngine(), pCenterObj.get()) &&
505 IsExtFileNameEntry(pRightObj.get()) && aLeftEntry == EMPTY_STRING)
507 eSelectEntry = ePageExtFileNameEntry;
508 bFound = true;
511 break;
513 case eUserNameEntry:
515 if(IsDateEntry(pRightObj.get()) && IsPageEntry(aWndCenter.GetEditEngine(), pCenterObj.get()))
517 String aUserNameEntry(aUserOpt.GetFirstName());
518 aUserNameEntry += ' ';
519 aUserNameEntry += (String)aUserOpt.GetLastName();
520 if(aUserNameEntry == aWndLeft.GetEditEngine()->GetText(0))
522 eSelectEntry = eUserNameEntry;
523 bFound = true;
527 break;
529 case eCreatedByEntry:
531 if(IsDateEntry(pCenterObj.get()) && IsPageEntry(aWndRight.GetEditEngine(), pRightObj.get()))
533 String aCreatedByEntry(ScGlobal::GetRscString( STR_HF_CREATED_BY ) );
534 aCreatedByEntry += ' ';
535 aCreatedByEntry += (String)aUserOpt.GetFirstName();
536 aCreatedByEntry += ' ';
537 aCreatedByEntry += (String)aUserOpt.GetLastName();
538 if(aCreatedByEntry == aWndLeft.GetEditEngine()->GetText(0))
540 eSelectEntry = eCreatedByEntry;
541 bFound = true;
545 break;
547 default:
549 // added to avoid warnings
554 if(eSelectEntry == eEntryCount)
555 InsertToDefinedList();
557 maLbDefined.SelectEntryPos( sal::static_int_cast<USHORT>( eSelectEntry ) );
560 bool ScHFEditPage::IsPageEntry(EditEngine*pEngine, EditTextObject* pTextObj)
562 if(!pEngine && !pTextObj)
563 return false;
565 bool bReturn = false;
567 if(!pTextObj->IsFieldObject())
569 SvUShorts aPosList;
570 pEngine->GetPortions(0,aPosList);
571 if(aPosList.Count() == 2)
573 String aPageEntry(ScGlobal::GetRscString( STR_PAGE ) );
574 aPageEntry += ' ';
575 ESelection aSel(0,0,0,0);
576 aSel.nEndPos = aPageEntry.Len();
577 if(aPageEntry == pEngine->GetText(aSel))
579 aSel.nStartPos = aSel.nEndPos;
580 aSel.nEndPos++;
581 ::std::auto_ptr< EditTextObject > pPageObj;
582 pPageObj.reset(pEngine->CreateTextObject(aSel));
583 if(pPageObj.get() && pPageObj->IsFieldObject() )
585 const SvxFieldItem* pFieldItem = pPageObj->GetField();
586 if(pFieldItem)
588 const SvxFieldData* pField = pFieldItem->GetField();
589 if(pField && pField->ISA(SvxPageField))
590 bReturn = true;
596 return bReturn;
599 bool ScHFEditPage::IsDateEntry(EditTextObject* pTextObj)
601 if(!pTextObj)
602 return false;
604 bool bReturn = false;
605 if(pTextObj->IsFieldObject())
607 const SvxFieldItem* pFieldItem = pTextObj->GetField();
608 if(pFieldItem)
610 const SvxFieldData* pField = pFieldItem->GetField();
611 if(pField && pField->ISA(SvxDateField))
612 bReturn = true;
615 return bReturn;
618 bool ScHFEditPage::IsExtFileNameEntry(EditTextObject* pTextObj)
620 if(!pTextObj)
621 return false;
622 bool bReturn = false;
623 if(pTextObj->IsFieldObject())
625 const SvxFieldItem* pFieldItem = pTextObj->GetField();
626 if(pFieldItem)
628 const SvxFieldData* pField = pFieldItem->GetField();
629 if(pField && pField->ISA(SvxExtFileField))
630 bReturn = true;
633 return bReturn;
636 void ScHFEditPage::ProcessDefinedListSel(ScHFEntryId eSel, bool bTravelling)
638 SvtUserOptions aUserOpt;
639 ::std::auto_ptr< EditTextObject > pTextObj;
641 switch(eSel)
643 case eNoneEntry:
644 ClearTextAreas();
645 if(!bTravelling)
646 aWndLeft.GrabFocus();
647 break;
649 case ePageEntry:
651 ClearTextAreas();
652 String aPageEntry(ScGlobal::GetRscString( STR_PAGE ) );
653 aPageEntry += ' ';
654 aWndCenter.GetEditEngine()->SetText(aPageEntry);
655 aWndCenter.InsertField( SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD) );
656 if(!bTravelling)
657 aWndCenter.GrabFocus();
659 break;
661 case ePagesEntry:
663 ClearTextAreas();
664 ESelection aSel(0,0,0,0);
665 String aPageEntry(ScGlobal::GetRscString( STR_PAGE ) );
666 aPageEntry += ' ';
667 aWndCenter.GetEditEngine()->SetText(aPageEntry);
668 aSel.nEndPos = aPageEntry.Len();
669 aWndCenter.GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
670 ++aSel.nEndPos;
671 String aPageOfEntry = ' ';
672 aPageOfEntry += ScGlobal::GetRscString( STR_HF_OF );
673 aPageOfEntry += ' ';
674 aWndCenter.GetEditEngine()->QuickInsertText(aPageOfEntry,ESelection(aSel.nEndPara,aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
675 aSel.nEndPos = sal::static_int_cast<xub_StrLen>( aSel.nEndPos + aPageOfEntry.Len() );
676 aWndCenter.GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPagesField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara,aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
677 pTextObj.reset(aWndCenter.GetEditEngine()->CreateTextObject());
678 aWndCenter.SetText(*pTextObj);
679 XubString aEntry(pTextObj.get()->GetText(0));
680 if(!bTravelling)
681 aWndCenter.GrabFocus();
683 break;
685 case eSheetEntry:
686 ClearTextAreas();
687 aWndCenter.InsertField( SvxFieldItem(SvxTableField(), EE_FEATURE_FIELD) );
688 if(!bTravelling)
689 aWndCenter.GrabFocus();
690 break;
692 case eConfidentialEntry:
694 ClearTextAreas();
695 String aConfidentialEntry(aUserOpt.GetCompany());
696 aConfidentialEntry += ' ';
697 aConfidentialEntry += ScGlobal::GetRscString( STR_HF_CONFIDENTIAL );
698 aWndLeft.GetEditEngine()->SetText(aConfidentialEntry);
699 aWndCenter.InsertField( SvxFieldItem(SvxDateField(Date(),SVXDATETYPE_VAR), EE_FEATURE_FIELD) );
700 String aPageEntry(ScGlobal::GetRscString( STR_PAGE ) );
701 aPageEntry += ' ';
702 aWndRight.GetEditEngine()->SetText(aPageEntry);
703 aWndRight.InsertField( SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD) );
704 if(!bTravelling)
705 aWndRight.GrabFocus();
707 break;
709 case eFileNamePageEntry:
711 ClearTextAreas();
712 ESelection aSel(0,0,0,0);
713 aWndCenter.GetEditEngine()->QuickInsertField(SvxFieldItem( SvxFileField(), EE_FEATURE_FIELD ), aSel );
714 ++aSel.nEndPos;
715 String aPageEntry(RTL_CONSTASCII_STRINGPARAM(", "));
716 aPageEntry += ScGlobal::GetRscString( STR_PAGE ) ;
717 aPageEntry += ' ';
718 aWndCenter.GetEditEngine()->QuickInsertText(aPageEntry, ESelection(aSel.nEndPara,aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
719 aSel.nStartPos = aSel.nEndPos;
720 aSel.nEndPos = sal::static_int_cast<xub_StrLen>( aSel.nEndPos + aPageEntry.Len() );
721 aWndCenter.GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara,aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
722 pTextObj.reset(aWndCenter.GetEditEngine()->CreateTextObject());
723 aWndCenter.SetText(*pTextObj);
724 XubString aEntry2(pTextObj.get()->GetText(0));
725 if(!bTravelling)
726 aWndCenter.GrabFocus();
728 break;
730 case eExtFileNameEntry:
731 ClearTextAreas();
732 aWndCenter.InsertField( SvxFieldItem( SvxExtFileField(
733 EMPTY_STRING, SVXFILETYPE_VAR, SVXFILEFORMAT_FULLPATH ), EE_FEATURE_FIELD ) );
734 if(!bTravelling)
735 aWndCenter.GrabFocus();
736 break;
738 case ePageSheetEntry:
740 ClearTextAreas();
741 ESelection aSel(0,0,0,0);
742 String aPageEntry(ScGlobal::GetRscString( STR_PAGE ) );
743 aPageEntry += ' ';
744 aWndCenter.GetEditEngine()->SetText(aPageEntry);
745 aSel.nEndPos = aPageEntry.Len();
746 aWndCenter.GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
747 ++aSel.nEndPos;
748 String aCommaSpace(RTL_CONSTASCII_STRINGPARAM(", "));
749 aWndCenter.GetEditEngine()->QuickInsertText(aCommaSpace,ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
750 aSel.nEndPos = sal::static_int_cast<xub_StrLen>( aSel.nEndPos + aCommaSpace.Len() );
751 aWndCenter.GetEditEngine()->QuickInsertField( SvxFieldItem(SvxTableField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
752 pTextObj.reset(aWndCenter.GetEditEngine()->CreateTextObject());
753 aWndCenter.SetText(*pTextObj);
754 if(!bTravelling)
755 aWndCenter.GrabFocus();
757 break;
759 case ePageFileNameEntry:
761 ClearTextAreas();
762 ESelection aSel(0,0,0,0);
763 String aPageEntry(ScGlobal::GetRscString( STR_PAGE ) );
764 aPageEntry += ' ';
765 aWndCenter.GetEditEngine()->SetText(aPageEntry);
766 aSel.nEndPos = aPageEntry.Len();
767 aWndCenter.GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
768 ++aSel.nEndPos;
769 String aCommaSpace(RTL_CONSTASCII_STRINGPARAM(", "));
770 aWndCenter.GetEditEngine()->QuickInsertText(aCommaSpace,ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
771 aSel.nEndPos = sal::static_int_cast<xub_StrLen>( aSel.nEndPos + aCommaSpace.Len() );
772 aWndCenter.GetEditEngine()->QuickInsertField( SvxFieldItem(SvxFileField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
773 pTextObj.reset(aWndCenter.GetEditEngine()->CreateTextObject());
774 aWndCenter.SetText(*pTextObj);
775 if(!bTravelling)
776 aWndCenter.GrabFocus();
778 break;
780 case ePageExtFileNameEntry:
782 ClearTextAreas();
783 String aPageEntry(ScGlobal::GetRscString( STR_PAGE ) );
784 aPageEntry += ' ';
785 aWndCenter.GetEditEngine()->SetText(aPageEntry);
786 aWndCenter.InsertField( SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD) );
787 aWndRight.InsertField( SvxFieldItem( SvxExtFileField(
788 EMPTY_STRING, SVXFILETYPE_VAR, SVXFILEFORMAT_FULLPATH ), EE_FEATURE_FIELD ) );
789 if(!bTravelling)
790 aWndRight.GrabFocus();
792 break;
794 case eUserNameEntry:
796 ClearTextAreas();
797 String aUserNameEntry(aUserOpt.GetFirstName());
798 aUserNameEntry += ' ';
799 aUserNameEntry += (String)aUserOpt.GetLastName();
800 aWndLeft.GetEditEngine()->SetText(aUserNameEntry);
801 String aPageEntry(ScGlobal::GetRscString( STR_PAGE ) );
802 aPageEntry += ' ';
803 aWndCenter.GetEditEngine()->SetText(aPageEntry);
804 aWndCenter.InsertField( SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD) );
805 aWndRight.InsertField( SvxFieldItem(SvxDateField(Date(),SVXDATETYPE_VAR), EE_FEATURE_FIELD) );
806 if(!bTravelling)
807 aWndRight.GrabFocus();
809 break;
811 case eCreatedByEntry:
813 ClearTextAreas();
814 String aCreatedByEntry(ScGlobal::GetRscString( STR_HF_CREATED_BY ) );
815 aCreatedByEntry += ' ';
816 aCreatedByEntry += (String)aUserOpt.GetFirstName();
817 aCreatedByEntry += ' ';
818 aCreatedByEntry += (String)aUserOpt.GetLastName();
819 aWndLeft.GetEditEngine()->SetText(aCreatedByEntry);
820 aWndCenter.InsertField( SvxFieldItem(SvxDateField(Date(),SVXDATETYPE_VAR), EE_FEATURE_FIELD) );
821 String aPageEntry(ScGlobal::GetRscString( STR_PAGE ) );
822 aPageEntry += ' ';
823 aWndRight.GetEditEngine()->SetText(aPageEntry);
824 aWndRight.InsertField( SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD) );
825 if(!bTravelling)
826 aWndRight.GrabFocus();
828 break;
830 default :
831 break;
835 void ScHFEditPage::ClearTextAreas()
837 aWndLeft.GetEditEngine()->SetText(EMPTY_STRING);
838 aWndLeft.Invalidate();
839 aWndCenter.GetEditEngine()->SetText(EMPTY_STRING);
840 aWndCenter.Invalidate();
841 aWndRight.GetEditEngine()->SetText(EMPTY_STRING);
842 aWndRight.Invalidate();
845 //-----------------------------------------------------------------------
846 // Handler:
847 //-----------------------------------------------------------------------
849 IMPL_LINK( ScHFEditPage, ListHdl_Impl, ListBox*, pList )
851 if ( pList && pList == &maLbDefined )
853 ScHFEntryId eSel = static_cast<ScHFEntryId>(maLbDefined.GetSelectEntryPos());
854 if(!maLbDefined.IsTravelSelect())
856 ProcessDefinedListSel(eSel);
858 // check if we need to remove the customized entry.
859 if(eSel < eEntryCount)
860 RemoveFromDefinedList();
862 else
864 ProcessDefinedListSel(eSel, true);
867 return 0;
870 IMPL_LINK( ScHFEditPage, ClickHdl, ImageButton*, pBtn )
872 pActiveEdWnd = ::GetScEditWindow(); //CHINA001
873 if ( !pActiveEdWnd )
874 return 0;
876 if ( pBtn == &aBtnText )
878 pActiveEdWnd->SetCharAttriutes();
880 else
882 if ( pBtn == &aBtnPage )
883 pActiveEdWnd->InsertField( SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD) );
884 else if ( pBtn == &aBtnLastPage )
885 pActiveEdWnd->InsertField( SvxFieldItem(SvxPagesField(), EE_FEATURE_FIELD) );
886 else if ( pBtn == &aBtnDate )
887 pActiveEdWnd->InsertField( SvxFieldItem(SvxDateField(Date(),SVXDATETYPE_VAR), EE_FEATURE_FIELD) );
888 else if ( pBtn == &aBtnTime )
889 pActiveEdWnd->InsertField( SvxFieldItem(SvxTimeField(), EE_FEATURE_FIELD) );
890 else if ( pBtn == &aBtnFile )
892 pActiveEdWnd->InsertField( SvxFieldItem( SvxFileField(), EE_FEATURE_FIELD ) );
894 else if ( pBtn == &aBtnTable )
895 pActiveEdWnd->InsertField( SvxFieldItem(SvxTableField(), EE_FEATURE_FIELD) );
897 InsertToDefinedList();
898 pActiveEdWnd->GrabFocus();
900 return 0;
903 IMPL_LINK( ScHFEditPage, MenuHdl, ScExtIButton*, pBtn )
905 pActiveEdWnd = ::GetScEditWindow(); //CHINA001
906 if ( !pActiveEdWnd )
907 return 0;
909 if(pBtn!=NULL)
911 switch(pBtn->GetSelected())
913 case FILE_COMMAND_TITEL:
914 pActiveEdWnd->InsertField( SvxFieldItem( SvxFileField(), EE_FEATURE_FIELD ) );
915 break;
916 case FILE_COMMAND_FILENAME:
917 pActiveEdWnd->InsertField( SvxFieldItem( SvxExtFileField(
918 EMPTY_STRING, SVXFILETYPE_VAR, SVXFILEFORMAT_NAME_EXT ), EE_FEATURE_FIELD ) );
919 break;
920 case FILE_COMMAND_PATH:
921 pActiveEdWnd->InsertField( SvxFieldItem( SvxExtFileField(
922 EMPTY_STRING, SVXFILETYPE_VAR, SVXFILEFORMAT_FULLPATH ), EE_FEATURE_FIELD ) );
923 break;
926 return 0;
929 //========================================================================
930 // class ScRightHeaderEditPage
931 //========================================================================
933 ScRightHeaderEditPage::ScRightHeaderEditPage( Window* pParent, const SfxItemSet& rCoreSet )
934 : ScHFEditPage( pParent, RID_SCPAGE_HFED_HR, rCoreSet,
935 rCoreSet.GetPool()->GetWhich(SID_SCATTR_PAGE_HEADERRIGHT ), true )
938 // -----------------------------------------------------------------------
940 USHORT* __EXPORT ScRightHeaderEditPage::GetRanges()
941 { return pPageRightHeaderRanges; }
943 // -----------------------------------------------------------------------
945 SfxTabPage* __EXPORT ScRightHeaderEditPage::Create( Window* pParent, const SfxItemSet& rCoreSet )
946 { return ( new ScRightHeaderEditPage( pParent, rCoreSet ) ); };
949 //========================================================================
950 // class ScLeftHeaderEditPage
951 //========================================================================
953 ScLeftHeaderEditPage::ScLeftHeaderEditPage( Window* pParent, const SfxItemSet& rCoreSet )
954 : ScHFEditPage( pParent, RID_SCPAGE_HFED_HL, rCoreSet,
955 rCoreSet.GetPool()->GetWhich(SID_SCATTR_PAGE_HEADERLEFT ), true )
958 // -----------------------------------------------------------------------
960 USHORT* __EXPORT ScLeftHeaderEditPage::GetRanges()
961 { return pPageLeftHeaderRanges; }
963 // -----------------------------------------------------------------------
965 SfxTabPage* __EXPORT ScLeftHeaderEditPage::Create( Window* pParent, const SfxItemSet& rCoreSet )
966 { return ( new ScLeftHeaderEditPage( pParent, rCoreSet ) ); };
968 //========================================================================
969 // class ScRightFooterEditPage
970 //========================================================================
972 ScRightFooterEditPage::ScRightFooterEditPage( Window* pParent, const SfxItemSet& rCoreSet )
973 : ScHFEditPage( pParent, RID_SCPAGE_HFED_FR, rCoreSet,
974 rCoreSet.GetPool()->GetWhich(SID_SCATTR_PAGE_FOOTERRIGHT ), false )
977 // -----------------------------------------------------------------------
979 USHORT* __EXPORT ScRightFooterEditPage::GetRanges()
980 { return pPageRightFooterRanges; }
982 // -----------------------------------------------------------------------
984 SfxTabPage* __EXPORT ScRightFooterEditPage::Create( Window* pParent, const SfxItemSet& rCoreSet )
985 { return ( new ScRightFooterEditPage( pParent, rCoreSet ) ); };
987 //========================================================================
988 // class ScLeftFooterEditPage
989 //========================================================================
991 ScLeftFooterEditPage::ScLeftFooterEditPage( Window* pParent, const SfxItemSet& rCoreSet )
992 : ScHFEditPage( pParent, RID_SCPAGE_HFED_FL, rCoreSet,
993 rCoreSet.GetPool()->GetWhich(SID_SCATTR_PAGE_FOOTERLEFT ), false )
996 // -----------------------------------------------------------------------
998 USHORT* __EXPORT ScLeftFooterEditPage::GetRanges()
999 { return pPageLeftFooterRanges; }
1001 // -----------------------------------------------------------------------
1003 SfxTabPage* __EXPORT ScLeftFooterEditPage::Create( Window* pParent, const SfxItemSet& rCoreSet )
1004 { return ( new ScLeftFooterEditPage( pParent, rCoreSet ) ); };