Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / pagedlg / scuitphfedit.cxx
blobe94555d9c414d2ebdf23127cb8b75b814c5ce918
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #undef SC_DLLIMPLEMENTATION
25 //------------------------------------------------------------------
27 #define _TPHFEDIT_CXX
28 #include "scitems.hxx"
29 #include <editeng/eeitem.hxx>
31 #include <editeng/editobj.hxx>
32 #include <editeng/editstat.hxx>
33 #include <editeng/editview.hxx>
34 #include <editeng/flditem.hxx>
35 #include <sfx2/basedlgs.hxx>
36 #include <sfx2/objsh.hxx>
37 #include <vcl/msgbox.hxx>
38 #include <vcl/svapp.hxx>
39 #include <unotools/useroptions.hxx>
41 #include "editutil.hxx"
42 #include "global.hxx"
43 #include "attrib.hxx"
44 #include "patattr.hxx"
45 #include "scresid.hxx"
46 #include "sc.hrc"
47 #include "globstr.hrc"
48 #include "tabvwsh.hxx"
49 #include "prevwsh.hxx"
50 #include "textdlgs.hxx"
51 #include "AccessibleEditObject.hxx"
53 #include "scuitphfedit.hxx"
54 #include <memory>
56 // STATIC DATA -----------------------------------------------------------
58 static ScEditWindow* pActiveEdWnd = NULL;
60 //========================================================================
61 // class ScHFEditPage
64 ScHFEditPage::ScHFEditPage( Window* pParent,
65 const SfxItemSet& rCoreAttrs,
66 sal_uInt16 nWhichId,
67 bool bHeader )
68 : SfxTabPage( pParent, "HeaderFooterContent", "modules/scalc/ui/headerfootercontent.ui", rCoreAttrs )
69 , nWhich( nWhichId )
71 get(m_pWndLeft,"textviewWND_LEFT");
72 m_pWndLeft->SetLocation(Left);
73 get(m_pWndCenter,"textviewWND_CENTER");
74 m_pWndCenter->SetLocation(Center);
75 get(m_pWndRight,"textviewWND_RIGHT");
76 m_pWndRight->SetLocation(Right);
78 get(m_pLbDefined,"comboLB_DEFINED");
80 get(m_pBtnText,"buttonBTN_TEXT");
81 get(m_pBtnTable,"buttonBTN_TABLE");
82 get(m_pBtnPage,"buttonBTN_PAGE");
83 get(m_pBtnLastPage,"buttonBTN_PAGES");
84 get(m_pBtnDate,"buttonBTN_DATE");
85 get(m_pBtnTime,"buttonBTN_TIME");
87 get(m_pBtnFile,"buttonBTN_FILE");
89 get(m_pFtConfidential,"labelSTR_HF_CONFIDENTIAL");
90 get(m_pFtPage,"labelSTR_PAGE");
91 get(m_pFtOfQuestion,"labelSTR_HF_OF_QUESTION");
92 get(m_pFtOf,"labelSTR_HF_OF");
93 get(m_pFtNone,"labelSTR_HF_NONE_IN_BRACKETS");
94 get(m_pFtCreatedBy,"labelSTR_HF_CREATED_BY");
95 get(m_pFtCustomized,"labelSTR_HF_CUSTOMIZED");
98 //! use default style from current document?
99 //! if font color is used, header/footer background color must be set
101 ScPatternAttr aPatAttr( rCoreAttrs.GetPool() );
103 m_pBtnFile->SetPopupMenu(get_menu("popup"));
105 m_pLbDefined->SetSelectHdl( LINK( this, ScHFEditPage, ListHdl_Impl ) );
106 m_pBtnFile->SetMenuHdl( LINK( this, ScHFEditPage, MenuHdl ) );
107 m_pBtnText->SetClickHdl( LINK( this, ScHFEditPage, ClickHdl ) );
108 m_pBtnPage->SetClickHdl( LINK( this, ScHFEditPage, ClickHdl ) );
109 m_pBtnLastPage->SetClickHdl( LINK( this, ScHFEditPage, ClickHdl ) );
110 m_pBtnDate->SetClickHdl( LINK( this, ScHFEditPage, ClickHdl ) );
111 m_pBtnTime->SetClickHdl( LINK( this, ScHFEditPage, ClickHdl ) );
112 m_pBtnFile->SetClickHdl( LINK( this, ScHFEditPage, ClickHdl ) );
113 m_pBtnTable->SetClickHdl( LINK( this, ScHFEditPage, ClickHdl ) );
115 get(m_pFtDefinedHF,!bHeader ? "labelFT_F_DEFINED" : "labelFT_H_DEFINED");
116 get(m_pFtCustomHF, !bHeader ? "labelFT_F_CUSTOM" : "labelFT_H_CUSTOM");
118 m_pFtDefinedHF->Show();
119 m_pFtCustomHF->Show();
121 //swap left/right areas and their lables in RTL mode
122 if( Application::GetSettings().GetLayoutRTL() )
124 Window *pLeft = get<Window>("labelFT_LEFT");
125 Window *pRight = get<Window>("labelFT_RIGHT");
126 sal_Int32 nOldLeftAttach = pLeft->get_grid_left_attach();
127 sal_Int32 nOldRightAttach = pRight->get_grid_left_attach();
128 pLeft->set_grid_left_attach(nOldRightAttach);
129 pRight->set_grid_left_attach(nOldLeftAttach);
131 pLeft = m_pWndLeft;
132 pRight = m_pWndRight;
133 nOldLeftAttach = pLeft->get_grid_left_attach();
134 nOldRightAttach = pRight->get_grid_left_attach();
135 pLeft->set_grid_left_attach(nOldRightAttach);
136 pRight->set_grid_left_attach(nOldLeftAttach);
138 m_pWndLeft->SetFont( aPatAttr );
139 m_pWndCenter->SetFont( aPatAttr );
140 m_pWndRight->SetFont( aPatAttr );
142 FillCmdArr();
144 m_pWndLeft->GrabFocus();
146 InitPreDefinedList();
150 // -----------------------------------------------------------------------
152 ScHFEditPage::~ScHFEditPage()
156 void ScHFEditPage::SetNumType(SvxNumType eNumType)
158 m_pWndLeft->SetNumType(eNumType);
159 m_pWndCenter->SetNumType(eNumType);
160 m_pWndRight->SetNumType(eNumType);
163 void ScHFEditPage::Reset( const SfxItemSet& rCoreSet )
165 const SfxPoolItem* pItem = NULL;
166 if ( rCoreSet.HasItem(nWhich, &pItem) )
168 const ScPageHFItem& rItem = static_cast<const ScPageHFItem&>(*pItem);
170 if( const EditTextObject* pLeft = rItem.GetLeftArea() )
171 m_pWndLeft->SetText( *pLeft );
172 if( const EditTextObject* pCenter = rItem.GetCenterArea() )
173 m_pWndCenter->SetText( *pCenter );
174 if( const EditTextObject* pRight = rItem.GetRightArea() )
175 m_pWndRight->SetText( *pRight );
177 SetSelectDefinedList();
181 sal_Bool ScHFEditPage::FillItemSet( SfxItemSet& rCoreSet )
183 ScPageHFItem aItem( nWhich );
184 EditTextObject* pLeft = m_pWndLeft->CreateTextObject();
185 EditTextObject* pCenter = m_pWndCenter->CreateTextObject();
186 EditTextObject* pRight = m_pWndRight->CreateTextObject();
188 aItem.SetLeftArea ( *pLeft );
189 aItem.SetCenterArea( *pCenter );
190 aItem.SetRightArea ( *pRight );
191 delete pLeft;
192 delete pCenter;
193 delete pRight;
195 rCoreSet.Put( aItem );
197 return sal_True;
200 // -----------------------------------------------------------------------
202 #define SET_CMD(i,id) \
203 aCmd = aDel; \
204 aCmd += ScGlobal::GetRscString( id ); \
205 aCmd += aDel; \
206 aCmdArr[i] = aCmd;
208 // -----------------------------------------------------------------------
210 void ScHFEditPage::FillCmdArr()
212 OUString aDel( ScGlobal::GetRscString( STR_HFCMD_DELIMITER ) );
213 OUString aCmd;
215 SET_CMD( 0, STR_HFCMD_PAGE )
216 SET_CMD( 1, STR_HFCMD_PAGES )
217 SET_CMD( 2, STR_HFCMD_DATE )
218 SET_CMD( 3, STR_HFCMD_TIME )
219 SET_CMD( 4, STR_HFCMD_FILE )
220 SET_CMD( 5, STR_HFCMD_TABLE )
223 #undef SET_CMD
225 void ScHFEditPage::InitPreDefinedList()
227 SvtUserOptions aUserOpt;
229 Color* pTxtColour = NULL;
230 Color* pFldColour = NULL;
232 // Get the all field values at the outset.
233 OUString aPageFieldValue(m_pWndLeft->GetEditEngine()->CalcFieldValue(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), 0,0, pTxtColour, pFldColour));
234 OUString aSheetFieldValue(m_pWndLeft->GetEditEngine()->CalcFieldValue(SvxFieldItem(SvxTableField(), EE_FEATURE_FIELD), 0,0, pTxtColour, pFldColour));
235 OUString aFileFieldValue(m_pWndLeft->GetEditEngine()->CalcFieldValue(SvxFieldItem(SvxFileField(), EE_FEATURE_FIELD), 0,0, pTxtColour, pFldColour));
236 OUString aExtFileFieldValue(m_pWndLeft->GetEditEngine()->CalcFieldValue(SvxFieldItem(SvxExtFileField(), EE_FEATURE_FIELD), 0,0, pTxtColour, pFldColour));
237 OUString aDateFieldValue(m_pWndLeft->GetEditEngine()->CalcFieldValue(SvxFieldItem(SvxDateField(), EE_FEATURE_FIELD), 0,0, pTxtColour, pFldColour));
239 m_pLbDefined->Clear();
241 m_pLbDefined->InsertEntry(m_pFtNone->GetText());
243 OUString aPageEntry(m_pFtPage->GetText() + " " + aPageFieldValue);
244 m_pLbDefined->InsertEntry(aPageEntry);
246 OUString aPageOfEntry(aPageEntry + " " + m_pFtOfQuestion->GetText());
247 m_pLbDefined->InsertEntry( aPageOfEntry);
249 m_pLbDefined->InsertEntry(aSheetFieldValue);
251 OUString aConfidentialEntry(aUserOpt.GetCompany() + " " + m_pFtConfidential->GetText() + ", " + aDateFieldValue + ", " + aPageEntry);
252 m_pLbDefined->InsertEntry( aConfidentialEntry);
254 OUString aFileNamePageEntry(aFileFieldValue + ", " + aPageEntry);
255 m_pLbDefined->InsertEntry( aFileNamePageEntry);
257 m_pLbDefined->InsertEntry( aExtFileFieldValue);
259 OUString aPageSheetNameEntry(aPageEntry + ", " + aSheetFieldValue);
260 m_pLbDefined->InsertEntry( aPageSheetNameEntry);
262 OUString aPageFileNameEntry(aPageEntry + ", " + aFileFieldValue);
263 m_pLbDefined->InsertEntry( aPageFileNameEntry);
265 OUString aPagePathNameEntry(aPageEntry + ", " + aExtFileFieldValue);
266 m_pLbDefined->InsertEntry( aPagePathNameEntry);
268 OUString aUserNameEntry(aUserOpt.GetFirstName() + " " + aUserOpt.GetLastName() + ", " + aPageEntry + ", " + aDateFieldValue);
269 m_pLbDefined->InsertEntry( aUserNameEntry);
271 OUString aCreatedByEntry( m_pFtCreatedBy->GetText() + " " + aUserOpt.GetFirstName() + " " + aUserOpt.GetLastName() + ", ");
272 aCreatedByEntry += aDateFieldValue + ", " + aPageEntry;
273 m_pLbDefined->InsertEntry( aCreatedByEntry);
276 void ScHFEditPage::InsertToDefinedList()
278 sal_uInt16 nCount = m_pLbDefined->GetEntryCount();
279 if(nCount == eEntryCount)
281 m_pLbDefined->InsertEntry( m_pFtCustomized->GetText() );
282 m_pLbDefined->SelectEntryPos(eEntryCount);
286 void ScHFEditPage::RemoveFromDefinedList()
288 sal_uInt16 nCount = m_pLbDefined->GetEntryCount();
289 if(nCount > eEntryCount )
290 m_pLbDefined->RemoveEntry( nCount-1);
293 // determine if the header/footer exists in our predefined list and set select to it.
294 void ScHFEditPage::SetSelectDefinedList()
296 SvtUserOptions aUserOpt;
298 // default to customized
299 ScHFEntryId eSelectEntry = eEntryCount;
301 SAL_WNODEPRECATED_DECLARATIONS_PUSH
302 ::std::auto_ptr< EditTextObject > pLeftObj;
303 ::std::auto_ptr< EditTextObject > pCenterObj;
304 ::std::auto_ptr< EditTextObject > pRightObj;
305 SAL_WNODEPRECATED_DECLARATIONS_POP
307 OUString aLeftEntry;
308 OUString aCenterEntry;
309 OUString aRightEntry;
311 pLeftObj.reset(m_pWndLeft->GetEditEngine()->CreateTextObject());
312 pCenterObj.reset(m_pWndCenter->GetEditEngine()->CreateTextObject());
313 pRightObj.reset(m_pWndRight->GetEditEngine()->CreateTextObject());
315 bool bFound = false;
317 sal_uInt16 i;
318 sal_uInt16 nCount = m_pLbDefined->GetEntryCount();
319 for(i = 0; i < nCount && !bFound; i++)
321 switch(static_cast<ScHFEntryId>(i))
323 case eNoneEntry:
325 aLeftEntry = pLeftObj->GetText(0);
326 aCenterEntry = pCenterObj->GetText(0);
327 aRightEntry = pRightObj->GetText(0);
328 if(aLeftEntry == EMPTY_OUSTRING && aCenterEntry == EMPTY_OUSTRING
329 && aRightEntry == EMPTY_OUSTRING)
331 eSelectEntry = eNoneEntry;
332 bFound = true;
335 break;
337 case ePageEntry:
339 aLeftEntry = pLeftObj->GetText(0);
340 aRightEntry = pRightObj->GetText(0);
341 if(aLeftEntry == EMPTY_OUSTRING && aRightEntry == EMPTY_OUSTRING)
343 if(IsPageEntry(m_pWndCenter->GetEditEngine(), pCenterObj.get()))
345 eSelectEntry = ePageEntry;
346 bFound = true;
350 break;
353 //TODO
354 case ePagesEntry:
357 break;
359 case eSheetEntry:
361 aLeftEntry = pLeftObj->GetText(0);
362 aRightEntry = pRightObj->GetText(0);
363 if(aLeftEntry == EMPTY_OUSTRING && aRightEntry == EMPTY_OUSTRING)
365 if(pCenterObj->IsFieldObject())
367 const SvxFieldItem* pFieldItem = pCenterObj->GetField();
368 if(pFieldItem)
370 const SvxFieldData* pField = pFieldItem->GetField();
371 if(pField && pField->ISA(SvxTableField))
373 eSelectEntry = eSheetEntry;
374 bFound = true;
380 break;
382 case eConfidentialEntry:
384 if(IsDateEntry(pCenterObj.get()) && IsPageEntry(m_pWndRight->GetEditEngine(), pRightObj.get()))
386 OUString aConfidentialEntry(aUserOpt.GetCompany() + " " + m_pFtConfidential->GetText());
387 if(aConfidentialEntry == m_pWndLeft->GetEditEngine()->GetText(0))
389 eSelectEntry = eConfidentialEntry;
390 bFound = true;
394 break;
396 //TODO
397 case eFileNamePageEntry:
400 break;
402 case eExtFileNameEntry:
404 aLeftEntry = pLeftObj->GetText(0);
405 aRightEntry = pRightObj->GetText(0);
406 if(IsExtFileNameEntry(pCenterObj.get()) && aLeftEntry == EMPTY_OUSTRING
407 && aRightEntry == EMPTY_OUSTRING)
409 eSelectEntry = eExtFileNameEntry;
410 bFound = true;
413 break;
415 //TODO
416 case ePageSheetEntry:
419 break;
421 //TODO
422 case ePageFileNameEntry:
425 break;
427 case ePageExtFileNameEntry:
429 aLeftEntry = pLeftObj->GetText(0);
430 if(IsPageEntry(m_pWndCenter->GetEditEngine(), pCenterObj.get()) &&
431 IsExtFileNameEntry(pRightObj.get()) && aLeftEntry == EMPTY_OUSTRING)
433 eSelectEntry = ePageExtFileNameEntry;
434 bFound = true;
437 break;
439 case eUserNameEntry:
441 if(IsDateEntry(pRightObj.get()) && IsPageEntry(m_pWndCenter->GetEditEngine(), pCenterObj.get()))
443 OUString aUserNameEntry(aUserOpt.GetFirstName() + " " + aUserOpt.GetLastName());
445 if(aUserNameEntry == m_pWndLeft->GetEditEngine()->GetText(0))
447 eSelectEntry = eUserNameEntry;
448 bFound = true;
452 break;
454 case eCreatedByEntry:
456 if(IsDateEntry(pCenterObj.get()) && IsPageEntry(m_pWndRight->GetEditEngine(), pRightObj.get()))
458 OUString aCreatedByEntry(m_pFtCreatedBy->GetText() + " " + aUserOpt.GetFirstName() + " " + aUserOpt.GetLastName());
460 if(aCreatedByEntry == m_pWndLeft->GetEditEngine()->GetText(0))
462 eSelectEntry = eCreatedByEntry;
463 bFound = true;
467 break;
469 default:
471 // added to avoid warnings
476 if(eSelectEntry == eEntryCount)
477 InsertToDefinedList();
479 m_pLbDefined->SelectEntryPos( sal::static_int_cast<sal_uInt16>( eSelectEntry ) );
482 bool ScHFEditPage::IsPageEntry(EditEngine*pEngine, EditTextObject* pTextObj)
484 if(!pEngine || !pTextObj)
485 return false;
487 bool bReturn = false;
489 if(!pTextObj->IsFieldObject())
491 std::vector<sal_uInt16> aPosList;
492 pEngine->GetPortions(0,aPosList);
493 if(aPosList.size() == 2)
495 OUString aPageEntry(m_pFtPage->GetText() + " ");
496 ESelection aSel(0,0,0,0);
497 aSel.nEndPos = aPageEntry.getLength();
498 if(aPageEntry == pEngine->GetText(aSel))
500 aSel.nStartPos = aSel.nEndPos;
501 aSel.nEndPos++;
502 SAL_WNODEPRECATED_DECLARATIONS_PUSH
503 ::std::auto_ptr< EditTextObject > pPageObj;
504 SAL_WNODEPRECATED_DECLARATIONS_POP
505 pPageObj.reset(pEngine->CreateTextObject(aSel));
506 if(pPageObj.get() && pPageObj->IsFieldObject() )
508 const SvxFieldItem* pFieldItem = pPageObj->GetField();
509 if(pFieldItem)
511 const SvxFieldData* pField = pFieldItem->GetField();
512 if(pField && pField->ISA(SvxPageField))
513 bReturn = true;
519 return bReturn;
522 bool ScHFEditPage::IsDateEntry(EditTextObject* pTextObj)
524 if(!pTextObj)
525 return false;
527 bool bReturn = false;
528 if(pTextObj->IsFieldObject())
530 const SvxFieldItem* pFieldItem = pTextObj->GetField();
531 if(pFieldItem)
533 const SvxFieldData* pField = pFieldItem->GetField();
534 if(pField && pField->ISA(SvxDateField))
535 bReturn = true;
538 return bReturn;
541 bool ScHFEditPage::IsExtFileNameEntry(EditTextObject* pTextObj)
543 if(!pTextObj)
544 return false;
545 bool bReturn = false;
546 if(pTextObj->IsFieldObject())
548 const SvxFieldItem* pFieldItem = pTextObj->GetField();
549 if(pFieldItem)
551 const SvxFieldData* pField = pFieldItem->GetField();
552 if(pField && pField->ISA(SvxExtFileField))
553 bReturn = true;
556 return bReturn;
559 void ScHFEditPage::ProcessDefinedListSel(ScHFEntryId eSel, bool bTravelling)
561 SvtUserOptions aUserOpt;
562 SAL_WNODEPRECATED_DECLARATIONS_PUSH
563 ::std::auto_ptr< EditTextObject > pTextObj;
564 SAL_WNODEPRECATED_DECLARATIONS_POP
566 switch(eSel)
568 case eNoneEntry:
569 ClearTextAreas();
570 if(!bTravelling)
571 m_pWndLeft->GrabFocus();
572 break;
574 case ePageEntry:
576 ClearTextAreas();
577 OUString aPageEntry( m_pFtPage->GetText() + " " );
578 m_pWndCenter->GetEditEngine()->SetText(aPageEntry);
579 m_pWndCenter->InsertField( SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD) );
580 if(!bTravelling)
581 m_pWndCenter->GrabFocus();
583 break;
585 case ePagesEntry:
587 ClearTextAreas();
588 ESelection aSel(0,0,0,0);
589 OUString aPageEntry( m_pFtPage->GetText() + " ");
590 m_pWndCenter->GetEditEngine()->SetText(aPageEntry);
591 aSel.nEndPos = aPageEntry.getLength();
592 m_pWndCenter->GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
593 ++aSel.nEndPos;
595 OUString aPageOfEntry(" " + m_pFtOf->GetText() + " ");
596 m_pWndCenter->GetEditEngine()->QuickInsertText(aPageOfEntry,ESelection(aSel.nEndPara,aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
597 aSel.nEndPos = sal::static_int_cast<xub_StrLen>( aSel.nEndPos + aPageOfEntry.getLength() );
598 m_pWndCenter->GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPagesField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara,aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
599 pTextObj.reset(m_pWndCenter->GetEditEngine()->CreateTextObject());
600 m_pWndCenter->SetText(*pTextObj);
601 if(!bTravelling)
602 m_pWndCenter->GrabFocus();
604 break;
606 case eSheetEntry:
607 ClearTextAreas();
608 m_pWndCenter->InsertField( SvxFieldItem(SvxTableField(), EE_FEATURE_FIELD) );
609 if(!bTravelling)
610 m_pWndCenter->GrabFocus();
611 break;
613 case eConfidentialEntry:
615 ClearTextAreas();
616 OUString aConfidentialEntry(aUserOpt.GetCompany() + " " + m_pFtConfidential->GetText());
617 m_pWndLeft->GetEditEngine()->SetText(aConfidentialEntry);
618 m_pWndCenter->InsertField( SvxFieldItem(SvxDateField(Date( Date::SYSTEM ),SVXDATETYPE_VAR), EE_FEATURE_FIELD) );
620 OUString aPageEntry( m_pFtPage->GetText() + " ");
621 m_pWndRight->GetEditEngine()->SetText(aPageEntry);
622 m_pWndRight->InsertField( SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD) );
623 if(!bTravelling)
624 m_pWndRight->GrabFocus();
626 break;
628 case eFileNamePageEntry:
630 ClearTextAreas();
631 ESelection aSel(0,0,0,0);
632 m_pWndCenter->GetEditEngine()->QuickInsertField(SvxFieldItem( SvxFileField(), EE_FEATURE_FIELD ), aSel );
633 ++aSel.nEndPos;
634 OUString aPageEntry(", " + m_pFtPage->GetText() + " ");
635 m_pWndCenter->GetEditEngine()->QuickInsertText(aPageEntry, ESelection(aSel.nEndPara,aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
636 aSel.nStartPos = aSel.nEndPos;
637 aSel.nEndPos = sal::static_int_cast<xub_StrLen>( aSel.nEndPos + aPageEntry.getLength() );
638 m_pWndCenter->GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara,aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
639 pTextObj.reset(m_pWndCenter->GetEditEngine()->CreateTextObject());
640 m_pWndCenter->SetText(*pTextObj);
641 if(!bTravelling)
642 m_pWndCenter->GrabFocus();
644 break;
646 case eExtFileNameEntry:
647 ClearTextAreas();
648 m_pWndCenter->InsertField( SvxFieldItem( SvxExtFileField(
649 EMPTY_OUSTRING, SVXFILETYPE_VAR, SVXFILEFORMAT_FULLPATH ), EE_FEATURE_FIELD ) );
650 if(!bTravelling)
651 m_pWndCenter->GrabFocus();
652 break;
654 case ePageSheetEntry:
656 ClearTextAreas();
657 ESelection aSel(0,0,0,0);
658 OUString aPageEntry( m_pFtPage->GetText() + " " );
659 m_pWndCenter->GetEditEngine()->SetText(aPageEntry);
660 aSel.nEndPos = aPageEntry.getLength();
661 m_pWndCenter->GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
662 ++aSel.nEndPos;
664 OUString aCommaSpace(", ");
665 m_pWndCenter->GetEditEngine()->QuickInsertText(aCommaSpace,ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
666 aSel.nEndPos = sal::static_int_cast<xub_StrLen>( aSel.nEndPos + aCommaSpace.getLength() );
667 m_pWndCenter->GetEditEngine()->QuickInsertField( SvxFieldItem(SvxTableField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
668 pTextObj.reset(m_pWndCenter->GetEditEngine()->CreateTextObject());
669 m_pWndCenter->SetText(*pTextObj);
670 if(!bTravelling)
671 m_pWndCenter->GrabFocus();
673 break;
675 case ePageFileNameEntry:
677 ClearTextAreas();
678 ESelection aSel(0,0,0,0);
679 OUString aPageEntry( m_pFtPage->GetText() + " " );
680 m_pWndCenter->GetEditEngine()->SetText(aPageEntry);
681 aSel.nEndPos = aPageEntry.getLength();
682 m_pWndCenter->GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
683 ++aSel.nEndPos;
684 OUString aCommaSpace(", ");
685 m_pWndCenter->GetEditEngine()->QuickInsertText(aCommaSpace,ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
686 aSel.nEndPos = sal::static_int_cast<xub_StrLen>( aSel.nEndPos + aCommaSpace.getLength() );
687 m_pWndCenter->GetEditEngine()->QuickInsertField( SvxFieldItem(SvxFileField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
688 pTextObj.reset(m_pWndCenter->GetEditEngine()->CreateTextObject());
689 m_pWndCenter->SetText(*pTextObj);
690 if(!bTravelling)
691 m_pWndCenter->GrabFocus();
693 break;
695 case ePageExtFileNameEntry:
697 ClearTextAreas();
698 OUString aPageEntry( m_pFtPage->GetText() + " " );
699 m_pWndCenter->GetEditEngine()->SetText(aPageEntry);
700 m_pWndCenter->InsertField( SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD) );
701 m_pWndRight->InsertField( SvxFieldItem( SvxExtFileField(
702 EMPTY_OUSTRING, SVXFILETYPE_VAR, SVXFILEFORMAT_FULLPATH ), EE_FEATURE_FIELD ) );
703 if(!bTravelling)
704 m_pWndRight->GrabFocus();
706 break;
708 case eUserNameEntry:
710 ClearTextAreas();
711 OUString aUserNameEntry(aUserOpt.GetFirstName() + " " + aUserOpt.GetLastName());
712 m_pWndLeft->GetEditEngine()->SetText(aUserNameEntry);
713 OUString aPageEntry( m_pFtPage->GetText() + " ");
714 //aPageEntry += " ";
715 m_pWndCenter->GetEditEngine()->SetText(aPageEntry);
716 m_pWndCenter->InsertField( SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD) );
717 m_pWndRight->InsertField( SvxFieldItem(SvxDateField(Date( Date::SYSTEM ),SVXDATETYPE_VAR), EE_FEATURE_FIELD) );
718 if(!bTravelling)
719 m_pWndRight->GrabFocus();
721 break;
723 case eCreatedByEntry:
725 ClearTextAreas();
726 OUString aCreatedByEntry( m_pFtCreatedBy->GetText() + " " + aUserOpt.GetFirstName() + " " + aUserOpt.GetLastName());
727 m_pWndLeft->GetEditEngine()->SetText(aCreatedByEntry);
728 m_pWndCenter->InsertField( SvxFieldItem(SvxDateField(Date( Date::SYSTEM ),SVXDATETYPE_VAR), EE_FEATURE_FIELD) );
729 OUString aPageEntry( m_pFtPage->GetText() );
730 aPageEntry += " ";
731 m_pWndRight->GetEditEngine()->SetText(aPageEntry);
732 m_pWndRight->InsertField( SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD) );
733 if(!bTravelling)
734 m_pWndRight->GrabFocus();
736 break;
738 default :
739 break;
743 void ScHFEditPage::ClearTextAreas()
745 m_pWndLeft->GetEditEngine()->SetText(EMPTY_OUSTRING);
746 m_pWndLeft->Invalidate();
747 m_pWndCenter->GetEditEngine()->SetText(EMPTY_OUSTRING);
748 m_pWndCenter->Invalidate();
749 m_pWndRight->GetEditEngine()->SetText(EMPTY_OUSTRING);
750 m_pWndRight->Invalidate();
753 //-----------------------------------------------------------------------
754 // Handler:
755 //-----------------------------------------------------------------------
757 IMPL_LINK( ScHFEditPage, ListHdl_Impl, ListBox*, pList )
759 if ( pList && pList == m_pLbDefined )
761 ScHFEntryId eSel = static_cast<ScHFEntryId>(m_pLbDefined->GetSelectEntryPos());
762 if(!m_pLbDefined->IsTravelSelect())
764 ProcessDefinedListSel(eSel);
766 // check if we need to remove the customized entry.
767 if(eSel < eEntryCount)
768 RemoveFromDefinedList();
770 else
772 ProcessDefinedListSel(eSel, true);
775 return 0;
778 IMPL_LINK( ScHFEditPage, ClickHdl, PushButton*, pBtn )
780 pActiveEdWnd = ::GetScEditWindow();
781 if ( !pActiveEdWnd )
782 return 0;
784 if ( pBtn == m_pBtnText )
786 pActiveEdWnd->SetCharAttriutes();
788 else
790 if ( pBtn == m_pBtnPage )
791 pActiveEdWnd->InsertField( SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD) );
792 else if ( pBtn == m_pBtnLastPage )
793 pActiveEdWnd->InsertField( SvxFieldItem(SvxPagesField(), EE_FEATURE_FIELD) );
794 else if ( pBtn == m_pBtnDate )
795 pActiveEdWnd->InsertField( SvxFieldItem(SvxDateField(Date( Date::SYSTEM ),SVXDATETYPE_VAR), EE_FEATURE_FIELD) );
796 else if ( pBtn == m_pBtnTime )
797 pActiveEdWnd->InsertField( SvxFieldItem(SvxTimeField(), EE_FEATURE_FIELD) );
798 else if ( pBtn == m_pBtnFile )
800 pActiveEdWnd->InsertField( SvxFieldItem( SvxFileField(), EE_FEATURE_FIELD ) );
802 else if ( pBtn == m_pBtnTable )
803 pActiveEdWnd->InsertField( SvxFieldItem(SvxTableField(), EE_FEATURE_FIELD) );
805 InsertToDefinedList();
806 pActiveEdWnd->GrabFocus();
808 return 0;
811 IMPL_LINK( ScHFEditPage, MenuHdl, ScExtIButton*, pBtn )
813 pActiveEdWnd = ::GetScEditWindow();
814 if ( !pActiveEdWnd )
815 return 0;
817 if(pBtn!=NULL)
819 OSL_ENSURE( true, pBtn->GetSelected());
820 OString sSelectedId = pBtn->GetSelectedIdent();
822 if (sSelectedId == "title")
824 pActiveEdWnd->InsertField( SvxFieldItem( SvxFileField(), EE_FEATURE_FIELD ) );
826 else if (sSelectedId == "filename")
828 pActiveEdWnd->InsertField( SvxFieldItem( SvxExtFileField(
829 OUString(), SVXFILETYPE_VAR, SVXFILEFORMAT_NAME_EXT ), EE_FEATURE_FIELD ) );
831 else if (sSelectedId == "pathname")
833 pActiveEdWnd->InsertField( SvxFieldItem( SvxExtFileField(
834 OUString(), SVXFILETYPE_VAR, SVXFILEFORMAT_FULLPATH ), EE_FEATURE_FIELD ) );
837 return 0;
840 //========================================================================
841 // class ScRightHeaderEditPage
842 //========================================================================
844 ScRightHeaderEditPage::ScRightHeaderEditPage( Window* pParent, const SfxItemSet& rCoreSet )
845 : ScHFEditPage( pParent,
846 rCoreSet,
847 rCoreSet.GetPool()->GetWhich(SID_SCATTR_PAGE_HEADERRIGHT ),
848 true )
851 // -----------------------------------------------------------------------
853 SfxTabPage* ScRightHeaderEditPage::Create( Window* pParent, const SfxItemSet& rCoreSet )
854 { return ( new ScRightHeaderEditPage( pParent, rCoreSet ) ); };
856 //========================================================================
857 // class ScLeftHeaderEditPage
858 //========================================================================
860 ScLeftHeaderEditPage::ScLeftHeaderEditPage( Window* pParent, const SfxItemSet& rCoreSet )
861 : ScHFEditPage( pParent,
862 rCoreSet,
863 rCoreSet.GetPool()->GetWhich(SID_SCATTR_PAGE_HEADERLEFT ),
864 true )
867 // -----------------------------------------------------------------------
869 SfxTabPage* ScLeftHeaderEditPage::Create( Window* pParent, const SfxItemSet& rCoreSet )
870 { return ( new ScLeftHeaderEditPage( pParent, rCoreSet ) ); };
872 //========================================================================
873 // class ScRightFooterEditPage
874 //========================================================================
876 ScRightFooterEditPage::ScRightFooterEditPage( Window* pParent, const SfxItemSet& rCoreSet )
877 : ScHFEditPage( pParent,
878 rCoreSet,
879 rCoreSet.GetPool()->GetWhich(SID_SCATTR_PAGE_FOOTERRIGHT ),
880 false )
883 // -----------------------------------------------------------------------
885 SfxTabPage* ScRightFooterEditPage::Create( Window* pParent, const SfxItemSet& rCoreSet )
886 { return ( new ScRightFooterEditPage( pParent, rCoreSet ) ); };
888 //========================================================================
889 // class ScLeftFooterEditPage
890 //========================================================================
892 ScLeftFooterEditPage::ScLeftFooterEditPage( Window* pParent, const SfxItemSet& rCoreSet )
893 : ScHFEditPage( pParent,
894 rCoreSet,
895 rCoreSet.GetPool()->GetWhich(SID_SCATTR_PAGE_FOOTERLEFT ),
896 false )
899 // -----------------------------------------------------------------------
901 SfxTabPage* ScLeftFooterEditPage::Create( Window* pParent, const SfxItemSet& rCoreSet )
902 { return ( new ScLeftFooterEditPage( pParent, rCoreSet ) ); };
904 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */