Move setting of LD_LIBRARY_PATH closer to invocation of cppunittester
[LibreOffice.git] / sc / source / ui / pagedlg / scuitphfedit.cxx
blobee9f21cbd9f6fc6d01ffbefe9fdd9beb6db231d1
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 .
20 #undef SC_DLLIMPLEMENTATION
22 #include <scitems.hxx>
23 #include <editeng/eeitem.hxx>
25 #include <editeng/editobj.hxx>
26 #include <editeng/flditem.hxx>
27 #include <osl/time.h>
28 #include <sfx2/tabdlg.hxx>
29 #include <vcl/settings.hxx>
31 #include <unotools/useroptions.hxx>
33 #include <editutil.hxx>
34 #include <attrib.hxx>
35 #include <patattr.hxx>
37 #include <scuitphfedit.hxx>
38 #include <memory>
41 ScHFEditPage::ScHFEditPage(weld::Container* pPage, weld::DialogController* pController,
42 const SfxItemSet& rCoreAttrs,
43 TypedWhichId<ScPageHFItem> nWhichId,
44 bool bHeader)
45 : SfxTabPage(pPage, pController, u"modules/scalc/ui/headerfootercontent.ui"_ustr, u"HeaderFooterContent"_ustr, &rCoreAttrs)
46 , nWhich( nWhichId )
47 , m_bDropDownActive(false)
48 , m_nTimeToggled(-1)
49 , m_xFtDefinedHF(m_xBuilder->weld_label(!bHeader ? "labelFT_F_DEFINED" : "labelFT_H_DEFINED"))
50 , m_xLbDefined(m_xBuilder->weld_combo_box(u"comboLB_DEFINED"_ustr))
51 , m_xFtCustomHF(m_xBuilder->weld_label(!bHeader ? "labelFT_F_CUSTOM" : "labelFT_H_CUSTOM"))
52 , m_xBtnText(m_xBuilder->weld_button(u"buttonBTN_TEXT"_ustr))
53 , m_xBtnFile(m_xBuilder->weld_menu_button(u"buttonBTN_FILE"_ustr))
54 , m_xBtnTable(m_xBuilder->weld_button(u"buttonBTN_TABLE"_ustr))
55 , m_xBtnPage(m_xBuilder->weld_button(u"buttonBTN_PAGE"_ustr))
56 , m_xBtnLastPage(m_xBuilder->weld_button(u"buttonBTN_PAGES"_ustr))
57 , m_xBtnDate(m_xBuilder->weld_button(u"buttonBTN_DATE"_ustr))
58 , m_xBtnTime(m_xBuilder->weld_button(u"buttonBTN_TIME"_ustr))
59 , m_xFtConfidential(m_xBuilder->weld_label(u"labelSTR_HF_CONFIDENTIAL"_ustr))
60 , m_xFtPage(m_xBuilder->weld_label(u"labelSTR_PAGE"_ustr))
61 , m_xFtOfQuestion(m_xBuilder->weld_label(u"labelSTR_HF_OF_QUESTION"_ustr))
62 , m_xFtOf(m_xBuilder->weld_label(u"labelSTR_HF_OF"_ustr))
63 , m_xFtNone(m_xBuilder->weld_label(u"labelSTR_HF_NONE_IN_BRACKETS"_ustr))
64 , m_xFtCreatedBy(m_xBuilder->weld_label(u"labelSTR_HF_CREATED_BY"_ustr))
65 , m_xFtCustomized(m_xBuilder->weld_label(u"labelSTR_HF_CUSTOMIZED"_ustr))
66 , m_xAreaGrid(m_xBuilder->weld_grid(u"areagrid"_ustr))
67 , m_xLeftScrolledWindow(m_xBuilder->weld_widget(u"scrolledwindow_LEFT"_ustr))
68 , m_xLeft(m_xBuilder->weld_widget(u"labelFT_LEFT"_ustr))
69 , m_xRightScrolledWindow(m_xBuilder->weld_widget(u"scrolledwindow_RIGHT"_ustr))
70 , m_xRight(m_xBuilder->weld_widget(u"labelFT_RIGHT"_ustr))
71 , m_xWndLeft(new ScEditWindow(Left, pController->getDialog()))
72 , m_xWndCenter(new ScEditWindow(Center, pController->getDialog()))
73 , m_xWndRight(new ScEditWindow(Right, pController->getDialog()))
74 , m_xWndLeftWnd(new weld::CustomWeld(*m_xBuilder, u"textviewWND_LEFT"_ustr, *m_xWndLeft))
75 , m_xWndCenterWnd(new weld::CustomWeld(*m_xBuilder, u"textviewWND_CENTER"_ustr, *m_xWndCenter))
76 , m_xWndRightWnd(new weld::CustomWeld(*m_xBuilder, u"textviewWND_RIGHT"_ustr, *m_xWndRight))
77 , m_pEditFocus(nullptr)
79 // tdf#114695 override natural size with a small value
80 // we expect this to get stretched to some larger but
81 // limited size based on surrounding widgets
82 m_xLbDefined->set_size_request(m_xLbDefined->get_approximate_digit_width() * 20, -1);
84 //! use default style from current document?
85 //! if font color is used, header/footer background color must be set
86 const CellAttributeHelper aTempHelper(*rCoreAttrs.GetPool());
87 const ScPatternAttr& rDefaultCellAttribute(aTempHelper.getDefaultCellAttribute());
89 m_xLbDefined->connect_popup_toggled( LINK( this, ScHFEditPage, ListToggleHdl_Impl) );
90 m_xLbDefined->connect_changed( LINK( this, ScHFEditPage, ListHdl_Impl ) );
91 m_xBtnFile->connect_selected( LINK( this, ScHFEditPage, MenuHdl ) );
92 m_xBtnText->connect_clicked( LINK( this, ScHFEditPage, ClickHdl ) );
93 m_xBtnPage->connect_clicked( LINK( this, ScHFEditPage, ClickHdl ) );
94 m_xBtnLastPage->connect_clicked( LINK( this, ScHFEditPage, ClickHdl ) );
95 m_xBtnDate->connect_clicked( LINK( this, ScHFEditPage, ClickHdl ) );
96 m_xBtnTime->connect_clicked( LINK( this, ScHFEditPage, ClickHdl ) );
97 m_xBtnTable->connect_clicked( LINK( this, ScHFEditPage, ClickHdl ) );
99 m_xFtDefinedHF->show();
100 m_xFtCustomHF->show();
102 //swap left/right areas and their labels in RTL mode
103 if( AllSettings::GetLayoutRTL() )
105 sal_Int32 nOldLeftAttach = m_xAreaGrid->get_child_left_attach(*m_xLeft);
106 sal_Int32 nOldRightAttach = m_xAreaGrid->get_child_left_attach(*m_xRight);
107 m_xAreaGrid->set_child_left_attach(*m_xLeft, nOldRightAttach);
108 m_xAreaGrid->set_child_left_attach(*m_xRight, nOldLeftAttach);
110 nOldLeftAttach = m_xAreaGrid->get_child_left_attach(*m_xLeftScrolledWindow);
111 nOldRightAttach = m_xAreaGrid->get_child_left_attach(*m_xRightScrolledWindow);
112 m_xAreaGrid->set_child_left_attach(*m_xLeftScrolledWindow, nOldRightAttach);
113 m_xAreaGrid->set_child_left_attach(*m_xRightScrolledWindow, nOldLeftAttach);
115 m_xWndLeft->SetFont( rDefaultCellAttribute );
116 m_xWndCenter->SetFont( rDefaultCellAttribute );
117 m_xWndRight->SetFont( rDefaultCellAttribute );
119 m_xWndLeft->SetObjectSelectHdl( LINK(this,ScHFEditPage,ObjectSelectHdl) );
120 m_xWndCenter->SetObjectSelectHdl( LINK(this,ScHFEditPage,ObjectSelectHdl) );
121 m_xWndRight->SetObjectSelectHdl( LINK(this,ScHFEditPage,ObjectSelectHdl) );
122 auto setEditFocus = [this](ScEditWindow & rEdit) { this->m_pEditFocus = &rEdit; };
123 m_xWndLeft->SetGetFocusHdl(setEditFocus);
124 m_xWndCenter->SetGetFocusHdl(setEditFocus);
125 m_xWndRight->SetGetFocusHdl(setEditFocus);
127 m_xWndLeft->GrabFocus();
128 m_pEditFocus = m_xWndLeft.get(); // there's no event from grab_focus()
130 InitPreDefinedList();
134 IMPL_LINK_NOARG( ScHFEditPage, ObjectSelectHdl, ScEditWindow&, void )
136 m_xBtnText->grab_focus();
139 ScHFEditPage::~ScHFEditPage()
143 void ScHFEditPage::SetNumType(SvxNumType eNumType)
145 m_xWndLeft->SetNumType(eNumType);
146 m_xWndCenter->SetNumType(eNumType);
147 m_xWndRight->SetNumType(eNumType);
150 void ScHFEditPage::Reset( const SfxItemSet* rCoreSet )
152 const ScPageHFItem* pItem = rCoreSet->GetItemIfSet(nWhich);
153 if ( !pItem )
154 return;
156 if( const EditTextObject* pLeft = pItem->GetLeftArea() )
157 m_xWndLeft->SetText( *pLeft );
158 if( const EditTextObject* pCenter = pItem->GetCenterArea() )
159 m_xWndCenter->SetText( *pCenter );
160 if( const EditTextObject* pRight = pItem->GetRightArea() )
161 m_xWndRight->SetText( *pRight );
163 SetSelectDefinedList();
166 bool ScHFEditPage::FillItemSet( SfxItemSet* rCoreSet )
168 ScPageHFItem aItem( nWhich );
169 std::unique_ptr<EditTextObject> pLeft = m_xWndLeft->CreateTextObject();
170 std::unique_ptr<EditTextObject> pCenter = m_xWndCenter->CreateTextObject();
171 std::unique_ptr<EditTextObject> pRight = m_xWndRight->CreateTextObject();
173 aItem.SetLeftArea ( *pLeft );
174 aItem.SetCenterArea( *pCenter );
175 aItem.SetRightArea ( *pRight );
177 rCoreSet->Put( aItem );
179 return true;
182 void ScHFEditPage::InitPreDefinedList()
184 SvtUserOptions aUserOpt;
186 std::optional<Color> pTxtColour;
187 std::optional<Color> pFldColour;
188 std::optional<FontLineStyle> pFldLineStyle;
190 // Get the all field values at the outset.
191 OUString aPageFieldValue(m_xWndLeft->GetEditEngine()->CalcFieldValue(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), 0,0, pTxtColour, pFldColour, pFldLineStyle));
192 OUString aSheetFieldValue(m_xWndLeft->GetEditEngine()->CalcFieldValue(SvxFieldItem(SvxTableField(), EE_FEATURE_FIELD), 0,0, pTxtColour, pFldColour, pFldLineStyle));
193 OUString aFileFieldValue(m_xWndLeft->GetEditEngine()->CalcFieldValue(SvxFieldItem(SvxFileField(), EE_FEATURE_FIELD), 0,0, pTxtColour, pFldColour, pFldLineStyle));
194 OUString aExtFileFieldValue(m_xWndLeft->GetEditEngine()->CalcFieldValue(SvxFieldItem(SvxExtFileField(), EE_FEATURE_FIELD), 0,0, pTxtColour, pFldColour, pFldLineStyle));
195 OUString aDateFieldValue(m_xWndLeft->GetEditEngine()->CalcFieldValue(SvxFieldItem(SvxDateField(), EE_FEATURE_FIELD), 0,0, pTxtColour, pFldColour, pFldLineStyle));
197 m_xLbDefined->clear();
199 m_xLbDefined->append_text(m_xFtNone->get_label());
201 OUString aPageEntry(m_xFtPage->get_label() + " " + aPageFieldValue);
202 m_xLbDefined->append_text(aPageEntry);
204 OUString aPageOfEntry(aPageEntry + " " + m_xFtOfQuestion->get_label());
205 m_xLbDefined->append_text( aPageOfEntry);
207 m_xLbDefined->append_text(aSheetFieldValue);
209 OUString aConfidentialEntry(aUserOpt.GetCompany() + " " + m_xFtConfidential->get_label() + ", " + aDateFieldValue + ", " + aPageEntry);
210 m_xLbDefined->append_text( aConfidentialEntry);
212 OUString aFileNamePageEntry(aFileFieldValue + ", " + aPageEntry);
213 m_xLbDefined->append_text( aFileNamePageEntry);
215 m_xLbDefined->append_text( aExtFileFieldValue);
217 OUString aPageSheetNameEntry(aPageEntry + ", " + aSheetFieldValue);
218 m_xLbDefined->append_text( aPageSheetNameEntry);
220 OUString aPageFileNameEntry(aPageEntry + ", " + aFileFieldValue);
221 m_xLbDefined->append_text( aPageFileNameEntry);
223 OUString aPagePathNameEntry(aPageEntry + ", " + aExtFileFieldValue);
224 m_xLbDefined->append_text( aPagePathNameEntry);
226 OUString aUserNameEntry(aUserOpt.GetFirstName() + " " + aUserOpt.GetLastName() + ", " + aPageEntry + ", " + aDateFieldValue);
227 m_xLbDefined->append_text( aUserNameEntry);
229 OUString aCreatedByEntry = m_xFtCreatedBy->get_label() + " " + aUserOpt.GetFirstName() + " " + aUserOpt.GetLastName() + ", " +
230 aDateFieldValue + ", " + aPageEntry;
231 m_xLbDefined->append_text( aCreatedByEntry);
234 void ScHFEditPage::InsertToDefinedList()
236 const sal_Int32 nCount = m_xLbDefined->get_count();
237 if(nCount == eEntryCount)
239 m_xLbDefined->append_text( m_xFtCustomized->get_label() );
240 m_xLbDefined->set_active(eEntryCount);
244 void ScHFEditPage::RemoveFromDefinedList()
246 const sal_Int32 nCount = m_xLbDefined->get_count();
247 if(nCount > eEntryCount )
248 m_xLbDefined->remove( nCount-1);
251 // determine if the header/footer exists in our predefined list and set select to it.
252 void ScHFEditPage::SetSelectDefinedList()
254 SvtUserOptions aUserOpt;
256 // default to customized
257 ScHFEntryId eSelectEntry = eEntryCount;
259 std::unique_ptr< EditTextObject > pLeftObj;
260 std::unique_ptr< EditTextObject > pCenterObj;
261 std::unique_ptr< EditTextObject > pRightObj;
263 OUString aLeftEntry;
264 OUString aCenterEntry;
265 OUString aRightEntry;
267 pLeftObj = m_xWndLeft->GetEditEngine()->CreateTextObject();
268 pCenterObj = m_xWndCenter->GetEditEngine()->CreateTextObject();
269 pRightObj = m_xWndRight->GetEditEngine()->CreateTextObject();
271 bool bFound = false;
273 const sal_Int32 nCount = m_xLbDefined->get_count();
274 for(sal_Int32 i = 0; i < nCount && !bFound; ++i)
276 switch(static_cast<ScHFEntryId>(i))
278 case eNoneEntry:
280 aLeftEntry = pLeftObj->GetText(0);
281 aCenterEntry = pCenterObj->GetText(0);
282 aRightEntry = pRightObj->GetText(0);
283 if(aLeftEntry.isEmpty() && aCenterEntry.isEmpty()
284 && aRightEntry.isEmpty())
286 eSelectEntry = eNoneEntry;
287 bFound = true;
290 break;
292 case ePageEntry:
294 aLeftEntry = pLeftObj->GetText(0);
295 aRightEntry = pRightObj->GetText(0);
296 if(aLeftEntry.isEmpty() && aRightEntry.isEmpty())
298 if(IsPageEntry(m_xWndCenter->GetEditEngine(), pCenterObj.get()))
300 eSelectEntry = ePageEntry;
301 bFound = true;
305 break;
307 //TODO
308 case ePagesEntry:
311 break;
313 case eSheetEntry:
315 aLeftEntry = pLeftObj->GetText(0);
316 aRightEntry = pRightObj->GetText(0);
317 if(aLeftEntry.isEmpty() && aRightEntry.isEmpty())
319 if(pCenterObj->IsFieldObject())
321 const SvxFieldItem* pFieldItem = pCenterObj->GetField();
322 if(pFieldItem)
324 const SvxFieldData* pField = pFieldItem->GetField();
325 if(dynamic_cast<const SvxTableField*>( pField))
327 eSelectEntry = eSheetEntry;
328 bFound = true;
334 break;
336 case eConfidentialEntry:
338 if(IsDateEntry(pCenterObj.get()) && IsPageEntry(m_xWndRight->GetEditEngine(), pRightObj.get()))
340 OUString aConfidentialEntry(aUserOpt.GetCompany() + " " + m_xFtConfidential->get_label());
341 if(aConfidentialEntry == m_xWndLeft->GetEditEngine()->GetText(0))
343 eSelectEntry = eConfidentialEntry;
344 bFound = true;
348 break;
350 //TODO
351 case eFileNamePageEntry:
354 break;
356 case eExtFileNameEntry:
358 aLeftEntry = pLeftObj->GetText(0);
359 aRightEntry = pRightObj->GetText(0);
360 if(IsExtFileNameEntry(pCenterObj.get()) && aLeftEntry.isEmpty()
361 && aRightEntry.isEmpty())
363 eSelectEntry = eExtFileNameEntry;
364 bFound = true;
367 break;
369 //TODO
370 case ePageSheetEntry:
373 break;
375 //TODO
376 case ePageFileNameEntry:
379 break;
381 case ePageExtFileNameEntry:
383 aLeftEntry = pLeftObj->GetText(0);
384 if(IsPageEntry(m_xWndCenter->GetEditEngine(), pCenterObj.get()) &&
385 IsExtFileNameEntry(pRightObj.get()) && aLeftEntry.isEmpty())
387 eSelectEntry = ePageExtFileNameEntry;
388 bFound = true;
391 break;
393 case eUserNameEntry:
395 if(IsDateEntry(pRightObj.get()) && IsPageEntry(m_xWndCenter->GetEditEngine(), pCenterObj.get()))
397 OUString aUserNameEntry(aUserOpt.GetFirstName() + " " + aUserOpt.GetLastName());
399 if(aUserNameEntry == m_xWndLeft->GetEditEngine()->GetText(0))
401 eSelectEntry = eUserNameEntry;
402 bFound = true;
406 break;
408 case eCreatedByEntry:
410 if(IsDateEntry(pCenterObj.get()) && IsPageEntry(m_xWndRight->GetEditEngine(), pRightObj.get()))
412 OUString aCreatedByEntry(m_xFtCreatedBy->get_label() + " " + aUserOpt.GetFirstName() + " " + aUserOpt.GetLastName());
414 if(aCreatedByEntry == m_xWndLeft->GetEditEngine()->GetText(0))
416 eSelectEntry = eCreatedByEntry;
417 bFound = true;
421 break;
423 default:
425 // added to avoid warnings
430 if(eSelectEntry == eEntryCount)
431 InsertToDefinedList();
433 m_xLbDefined->set_active( sal::static_int_cast<sal_uInt16>( eSelectEntry ) );
436 bool ScHFEditPage::IsPageEntry(EditEngine*pEngine, const EditTextObject* pTextObj)
438 if(!pEngine || !pTextObj)
439 return false;
441 bool bReturn = false;
443 if(!pTextObj->IsFieldObject())
445 std::vector<sal_Int32> aPosList;
446 pEngine->GetPortions(0,aPosList);
447 if(aPosList.size() == 2)
449 OUString aPageEntry(m_xFtPage->get_label() + " ");
450 ESelection aSel;
451 aSel.end.nIndex = aPageEntry.getLength();
452 if(aPageEntry == pEngine->GetText(aSel))
454 aSel.start.nIndex = aSel.end.nIndex;
455 aSel.end.nIndex++;
456 std::unique_ptr< EditTextObject > pPageObj = pEngine->CreateTextObject(aSel);
457 if(pPageObj && pPageObj->IsFieldObject() )
459 const SvxFieldItem* pFieldItem = pPageObj->GetField();
460 if(pFieldItem)
462 const SvxFieldData* pField = pFieldItem->GetField();
463 if(dynamic_cast<const SvxPageField*>( pField))
464 bReturn = true;
470 return bReturn;
473 bool ScHFEditPage::IsDateEntry(const EditTextObject* pTextObj)
475 if(!pTextObj)
476 return false;
478 bool bReturn = false;
479 if(pTextObj->IsFieldObject())
481 const SvxFieldItem* pFieldItem = pTextObj->GetField();
482 if(pFieldItem)
484 const SvxFieldData* pField = pFieldItem->GetField();
485 if(dynamic_cast<const SvxDateField*>( pField))
486 bReturn = true;
489 return bReturn;
492 bool ScHFEditPage::IsExtFileNameEntry(const EditTextObject* pTextObj)
494 if(!pTextObj)
495 return false;
496 bool bReturn = false;
497 if(pTextObj->IsFieldObject())
499 const SvxFieldItem* pFieldItem = pTextObj->GetField();
500 if(pFieldItem)
502 const SvxFieldData* pField = pFieldItem->GetField();
503 if(dynamic_cast<const SvxExtFileField*>( pField))
504 bReturn = true;
507 return bReturn;
510 void ScHFEditPage::ProcessDefinedListSel(ScHFEntryId eSel, bool bTravelling)
512 SvtUserOptions aUserOpt;
513 std::unique_ptr< EditTextObject > pTextObj;
515 switch(eSel)
517 case eNoneEntry:
518 ClearTextAreas();
519 if(!bTravelling)
520 m_xWndLeft->GrabFocus();
521 break;
523 case ePageEntry:
525 ClearTextAreas();
526 OUString aPageEntry( m_xFtPage->get_label() + " " );
527 m_xWndCenter->GetEditEngine()->SetTextCurrentDefaults(aPageEntry);
528 m_xWndCenter->InsertField( SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD) );
529 if(!bTravelling)
530 m_xWndCenter->GrabFocus();
532 break;
534 case ePagesEntry:
536 ClearTextAreas();
537 ESelection aSel;
538 OUString aPageEntry( m_xFtPage->get_label() + " ");
539 m_xWndCenter->GetEditEngine()->SetTextCurrentDefaults(aPageEntry);
540 aSel.end.nIndex = aPageEntry.getLength();
541 m_xWndCenter->GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), ESelection(aSel.end));
542 ++aSel.end.nIndex;
544 OUString aPageOfEntry(" " + m_xFtOf->get_label() + " ");
545 m_xWndCenter->GetEditEngine()->QuickInsertText(aPageOfEntry,ESelection(aSel.end));
546 aSel.end.nIndex += aPageOfEntry.getLength();
547 m_xWndCenter->GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPagesField(), EE_FEATURE_FIELD), ESelection(aSel.end));
548 pTextObj = m_xWndCenter->GetEditEngine()->CreateTextObject();
549 m_xWndCenter->SetText(*pTextObj);
550 if(!bTravelling)
551 m_xWndCenter->GrabFocus();
553 break;
555 case eSheetEntry:
556 ClearTextAreas();
557 m_xWndCenter->InsertField( SvxFieldItem(SvxTableField(), EE_FEATURE_FIELD) );
558 if(!bTravelling)
559 m_xWndCenter->GrabFocus();
560 break;
562 case eConfidentialEntry:
564 ClearTextAreas();
565 OUString aConfidentialEntry(aUserOpt.GetCompany() + " " + m_xFtConfidential->get_label());
566 m_xWndLeft->GetEditEngine()->SetTextCurrentDefaults(aConfidentialEntry);
567 m_xWndCenter->InsertField( SvxFieldItem(SvxDateField(Date( Date::SYSTEM ),SvxDateType::Var), EE_FEATURE_FIELD) );
569 OUString aPageEntry( m_xFtPage->get_label() + " ");
570 m_xWndRight->GetEditEngine()->SetTextCurrentDefaults(aPageEntry);
571 m_xWndRight->InsertField( SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD) );
572 if(!bTravelling)
573 m_xWndRight->GrabFocus();
575 break;
577 case eFileNamePageEntry:
579 ClearTextAreas();
580 ESelection aSel;
581 m_xWndCenter->GetEditEngine()->QuickInsertField(SvxFieldItem( SvxFileField(), EE_FEATURE_FIELD ), aSel );
582 ++aSel.end.nIndex;
583 OUString aPageEntry(", " + m_xFtPage->get_label() + " ");
584 m_xWndCenter->GetEditEngine()->QuickInsertText(aPageEntry, ESelection(aSel.end));
585 aSel.start.nIndex = aSel.end.nIndex;
586 aSel.end.nIndex += aPageEntry.getLength();
587 m_xWndCenter->GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), ESelection(aSel.end));
588 pTextObj = m_xWndCenter->GetEditEngine()->CreateTextObject();
589 m_xWndCenter->SetText(*pTextObj);
590 if(!bTravelling)
591 m_xWndCenter->GrabFocus();
593 break;
595 case eExtFileNameEntry:
596 ClearTextAreas();
597 m_xWndCenter->InsertField( SvxFieldItem( SvxExtFileField(
598 OUString(), SvxFileType::Var, SvxFileFormat::PathFull ), EE_FEATURE_FIELD ) );
599 if(!bTravelling)
600 m_xWndCenter->GrabFocus();
601 break;
603 case ePageSheetEntry:
605 ClearTextAreas();
606 ESelection aSel;
607 OUString aPageEntry( m_xFtPage->get_label() + " " );
608 m_xWndCenter->GetEditEngine()->SetTextCurrentDefaults(aPageEntry);
609 aSel.end.nIndex = aPageEntry.getLength();
610 m_xWndCenter->GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), ESelection(aSel.end));
611 ++aSel.end.nIndex;
613 OUString aCommaSpace(u", "_ustr);
614 m_xWndCenter->GetEditEngine()->QuickInsertText(aCommaSpace,ESelection(aSel.end));
615 aSel.end.nIndex += aCommaSpace.getLength();
616 m_xWndCenter->GetEditEngine()->QuickInsertField( SvxFieldItem(SvxTableField(), EE_FEATURE_FIELD), ESelection(aSel.end));
617 pTextObj = m_xWndCenter->GetEditEngine()->CreateTextObject();
618 m_xWndCenter->SetText(*pTextObj);
619 if(!bTravelling)
620 m_xWndCenter->GrabFocus();
622 break;
624 case ePageFileNameEntry:
626 ClearTextAreas();
627 ESelection aSel;
628 OUString aPageEntry( m_xFtPage->get_label() + " " );
629 m_xWndCenter->GetEditEngine()->SetTextCurrentDefaults(aPageEntry);
630 aSel.end.nIndex = aPageEntry.getLength();
631 m_xWndCenter->GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), ESelection(aSel.end));
632 ++aSel.end.nIndex;
633 OUString aCommaSpace(u", "_ustr);
634 m_xWndCenter->GetEditEngine()->QuickInsertText(aCommaSpace,ESelection(aSel.end));
635 aSel.end.nIndex += aCommaSpace.getLength();
636 m_xWndCenter->GetEditEngine()->QuickInsertField( SvxFieldItem(SvxFileField(), EE_FEATURE_FIELD), ESelection(aSel.end));
637 pTextObj = m_xWndCenter->GetEditEngine()->CreateTextObject();
638 m_xWndCenter->SetText(*pTextObj);
639 if(!bTravelling)
640 m_xWndCenter->GrabFocus();
642 break;
644 case ePageExtFileNameEntry:
646 ClearTextAreas();
647 OUString aPageEntry( m_xFtPage->get_label() + " " );
648 m_xWndCenter->GetEditEngine()->SetTextCurrentDefaults(aPageEntry);
649 m_xWndCenter->InsertField( SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD) );
650 m_xWndRight->InsertField( SvxFieldItem( SvxExtFileField(
651 OUString(), SvxFileType::Var, SvxFileFormat::PathFull ), EE_FEATURE_FIELD ) );
652 if(!bTravelling)
653 m_xWndRight->GrabFocus();
655 break;
657 case eUserNameEntry:
659 ClearTextAreas();
660 OUString aUserNameEntry(aUserOpt.GetFirstName() + " " + aUserOpt.GetLastName());
661 m_xWndLeft->GetEditEngine()->SetTextCurrentDefaults(aUserNameEntry);
662 OUString aPageEntry( m_xFtPage->get_label() + " ");
663 //aPageEntry += " ";
664 m_xWndCenter->GetEditEngine()->SetTextCurrentDefaults(aPageEntry);
665 m_xWndCenter->InsertField( SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD) );
666 m_xWndRight->InsertField( SvxFieldItem(SvxDateField(Date( Date::SYSTEM ),SvxDateType::Var), EE_FEATURE_FIELD) );
667 if(!bTravelling)
668 m_xWndRight->GrabFocus();
670 break;
672 case eCreatedByEntry:
674 ClearTextAreas();
675 OUString aCreatedByEntry( m_xFtCreatedBy->get_label() + " " + aUserOpt.GetFirstName() + " " + aUserOpt.GetLastName());
676 m_xWndLeft->GetEditEngine()->SetTextCurrentDefaults(aCreatedByEntry);
677 m_xWndCenter->InsertField( SvxFieldItem(SvxDateField(Date( Date::SYSTEM ),SvxDateType::Var), EE_FEATURE_FIELD) );
678 OUString aPageEntry( m_xFtPage->get_label() + " " );
679 m_xWndRight->GetEditEngine()->SetTextCurrentDefaults(aPageEntry);
680 m_xWndRight->InsertField( SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD) );
681 if(!bTravelling)
682 m_xWndRight->GrabFocus();
684 break;
686 default :
687 break;
691 void ScHFEditPage::ClearTextAreas()
693 m_xWndLeft->GetEditEngine()->SetTextCurrentDefaults(OUString());
694 m_xWndLeft->Invalidate();
695 m_xWndCenter->GetEditEngine()->SetTextCurrentDefaults(OUString());
696 m_xWndCenter->Invalidate();
697 m_xWndRight->GetEditEngine()->SetTextCurrentDefaults(OUString());
698 m_xWndRight->Invalidate();
701 // Handler:
702 IMPL_LINK_NOARG(ScHFEditPage, ListToggleHdl_Impl, weld::ComboBox&, void)
704 m_bDropDownActive = !m_bDropDownActive;
705 TimeValue aNow;
706 osl_getSystemTime(&aNow);
707 m_nTimeToggled = sal_Int64(aNow.Seconds) * 1000000000 + aNow.Nanosec;
710 IMPL_LINK_NOARG(ScHFEditPage, ListHdl_Impl, weld::ComboBox&, void)
712 ScHFEntryId eSel = static_cast<ScHFEntryId>(m_xLbDefined->get_active());
714 TimeValue aNow;
715 osl_getSystemTime(&aNow);
716 sal_Int64 nNow = sal_Int64(aNow.Seconds) * 1000000000 + aNow.Nanosec;
718 // order of dropdown vs select not guaranteed
719 bool bDiscrepancy = m_xLbDefined->get_popup_shown() != m_bDropDownActive;
720 if (bDiscrepancy)
721 ListToggleHdl_Impl(*m_xLbDefined);
723 bool bFocusToTarget = !m_xLbDefined->get_popup_shown() && m_nTimeToggled != -1 && (nNow - m_nTimeToggled < 800000000);
724 ProcessDefinedListSel(eSel, !bFocusToTarget);
725 // check if we need to remove the customized entry.
726 if (!m_bDropDownActive && eSel < eEntryCount)
727 RemoveFromDefinedList();
729 // keep balanced
730 if (bDiscrepancy)
731 ListToggleHdl_Impl(*m_xLbDefined);
734 IMPL_LINK( ScHFEditPage, ClickHdl, weld::Button&, rBtn, void )
736 if (!m_pEditFocus)
737 return;
739 if (&rBtn == m_xBtnText.get())
741 m_pEditFocus->SetCharAttributes();
743 else
745 if ( &rBtn == m_xBtnPage.get() )
746 m_pEditFocus->InsertField(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD));
747 else if ( &rBtn == m_xBtnLastPage.get() )
748 m_pEditFocus->InsertField(SvxFieldItem(SvxPagesField(), EE_FEATURE_FIELD));
749 else if ( &rBtn == m_xBtnDate.get() )
750 m_pEditFocus->InsertField(SvxFieldItem(SvxDateField(Date(Date::SYSTEM),SvxDateType::Var), EE_FEATURE_FIELD));
751 else if ( &rBtn == m_xBtnTime.get() )
752 m_pEditFocus->InsertField(SvxFieldItem(SvxTimeField(), EE_FEATURE_FIELD));
753 else if ( &rBtn == m_xBtnTable.get() )
754 m_pEditFocus->InsertField(SvxFieldItem(SvxTableField(), EE_FEATURE_FIELD));
756 InsertToDefinedList();
757 m_pEditFocus->GrabFocus();
760 IMPL_LINK(ScHFEditPage, MenuHdl, const OUString&, rSelectedId, void)
762 if (!m_pEditFocus)
763 return;
765 if (rSelectedId == "title")
767 m_pEditFocus->InsertField(SvxFieldItem(SvxFileField(), EE_FEATURE_FIELD));
769 else if (rSelectedId == "filename")
771 m_pEditFocus->InsertField( SvxFieldItem( SvxExtFileField(
772 OUString(), SvxFileType::Var, SvxFileFormat::NameAndExt ), EE_FEATURE_FIELD ) );
774 else if (rSelectedId == "pathname")
776 m_pEditFocus->InsertField( SvxFieldItem( SvxExtFileField(
777 OUString(), SvxFileType::Var, SvxFileFormat::PathFull ), EE_FEATURE_FIELD ) );
782 ScFirstHeaderEditPage::ScFirstHeaderEditPage( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rCoreSet )
783 : ScHFEditPage( pPage, pController,
784 rCoreSet,
785 SID_SCATTR_PAGE_HEADERFIRST,
786 true )
789 std::unique_ptr<SfxTabPage> ScFirstHeaderEditPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rCoreSet )
791 return std::make_unique<ScFirstHeaderEditPage>( pPage, pController, *rCoreSet );
795 ScRightHeaderEditPage::ScRightHeaderEditPage( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rCoreSet )
796 : ScHFEditPage( pPage, pController,
797 rCoreSet,
798 SID_SCATTR_PAGE_HEADERRIGHT,
799 true )
802 std::unique_ptr<SfxTabPage> ScRightHeaderEditPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rCoreSet )
804 return std::make_unique<ScRightHeaderEditPage>( pPage, pController, *rCoreSet );
808 ScLeftHeaderEditPage::ScLeftHeaderEditPage( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rCoreSet )
809 : ScHFEditPage( pPage, pController,
810 rCoreSet,
811 SID_SCATTR_PAGE_HEADERLEFT,
812 true )
815 std::unique_ptr<SfxTabPage> ScLeftHeaderEditPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rCoreSet )
817 return std::make_unique<ScLeftHeaderEditPage>( pPage, pController, *rCoreSet );
821 ScFirstFooterEditPage::ScFirstFooterEditPage( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rCoreSet )
822 : ScHFEditPage( pPage, pController,
823 rCoreSet,
824 SID_SCATTR_PAGE_FOOTERFIRST,
825 false )
828 std::unique_ptr<SfxTabPage> ScFirstFooterEditPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rCoreSet )
830 return std::make_unique<ScFirstFooterEditPage>( pPage, pController, *rCoreSet );
834 ScRightFooterEditPage::ScRightFooterEditPage( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rCoreSet )
835 : ScHFEditPage( pPage, pController,
836 rCoreSet,
837 SID_SCATTR_PAGE_FOOTERRIGHT,
838 false )
841 std::unique_ptr<SfxTabPage> ScRightFooterEditPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rCoreSet )
843 return std::make_unique<ScRightFooterEditPage>( pPage, pController, *rCoreSet );
847 ScLeftFooterEditPage::ScLeftFooterEditPage( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rCoreSet )
848 : ScHFEditPage( pPage, pController,
849 rCoreSet,
850 SID_SCATTR_PAGE_FOOTERLEFT,
851 false )
854 std::unique_ptr<SfxTabPage> ScLeftFooterEditPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rCoreSet )
856 return std::make_unique<ScLeftFooterEditPage>( pPage, pController, *rCoreSet );
859 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */