1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
28 #include <sfx2/tabdlg.hxx>
29 #include <vcl/settings.hxx>
31 #include <unotools/useroptions.hxx>
33 #include <editutil.hxx>
35 #include <patattr.hxx>
37 #include <scuitphfedit.hxx>
41 ScHFEditPage::ScHFEditPage(weld::Container
* pPage
, weld::DialogController
* pController
,
42 const SfxItemSet
& rCoreAttrs
,
43 TypedWhichId
<ScPageHFItem
> nWhichId
,
45 : SfxTabPage(pPage
, pController
, u
"modules/scalc/ui/headerfootercontent.ui"_ustr
, u
"HeaderFooterContent"_ustr
, &rCoreAttrs
)
47 , m_bDropDownActive(false)
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
);
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
);
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
;
264 OUString aCenterEntry
;
265 OUString aRightEntry
;
267 pLeftObj
= m_xWndLeft
->GetEditEngine()->CreateTextObject();
268 pCenterObj
= m_xWndCenter
->GetEditEngine()->CreateTextObject();
269 pRightObj
= m_xWndRight
->GetEditEngine()->CreateTextObject();
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
))
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
;
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
;
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();
324 const SvxFieldData
* pField
= pFieldItem
->GetField();
325 if(dynamic_cast<const SvxTableField
*>( pField
))
327 eSelectEntry
= eSheetEntry
;
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
;
351 case eFileNamePageEntry
:
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
;
370 case ePageSheetEntry
:
376 case ePageFileNameEntry
:
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
;
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
;
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
;
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
)
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() + " ");
451 aSel
.end
.nIndex
= aPageEntry
.getLength();
452 if(aPageEntry
== pEngine
->GetText(aSel
))
454 aSel
.start
.nIndex
= aSel
.end
.nIndex
;
456 std::unique_ptr
< EditTextObject
> pPageObj
= pEngine
->CreateTextObject(aSel
);
457 if(pPageObj
&& pPageObj
->IsFieldObject() )
459 const SvxFieldItem
* pFieldItem
= pPageObj
->GetField();
462 const SvxFieldData
* pField
= pFieldItem
->GetField();
463 if(dynamic_cast<const SvxPageField
*>( pField
))
473 bool ScHFEditPage::IsDateEntry(const EditTextObject
* pTextObj
)
478 bool bReturn
= false;
479 if(pTextObj
->IsFieldObject())
481 const SvxFieldItem
* pFieldItem
= pTextObj
->GetField();
484 const SvxFieldData
* pField
= pFieldItem
->GetField();
485 if(dynamic_cast<const SvxDateField
*>( pField
))
492 bool ScHFEditPage::IsExtFileNameEntry(const EditTextObject
* pTextObj
)
496 bool bReturn
= false;
497 if(pTextObj
->IsFieldObject())
499 const SvxFieldItem
* pFieldItem
= pTextObj
->GetField();
502 const SvxFieldData
* pField
= pFieldItem
->GetField();
503 if(dynamic_cast<const SvxExtFileField
*>( pField
))
510 void ScHFEditPage::ProcessDefinedListSel(ScHFEntryId eSel
, bool bTravelling
)
512 SvtUserOptions aUserOpt
;
513 std::unique_ptr
< EditTextObject
> pTextObj
;
520 m_xWndLeft
->GrabFocus();
526 OUString
aPageEntry( m_xFtPage
->get_label() + " " );
527 m_xWndCenter
->GetEditEngine()->SetTextCurrentDefaults(aPageEntry
);
528 m_xWndCenter
->InsertField( SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD
) );
530 m_xWndCenter
->GrabFocus();
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
));
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
);
551 m_xWndCenter
->GrabFocus();
557 m_xWndCenter
->InsertField( SvxFieldItem(SvxTableField(), EE_FEATURE_FIELD
) );
559 m_xWndCenter
->GrabFocus();
562 case eConfidentialEntry
:
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
) );
573 m_xWndRight
->GrabFocus();
577 case eFileNamePageEntry
:
581 m_xWndCenter
->GetEditEngine()->QuickInsertField(SvxFieldItem( SvxFileField(), EE_FEATURE_FIELD
), aSel
);
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
);
591 m_xWndCenter
->GrabFocus();
595 case eExtFileNameEntry
:
597 m_xWndCenter
->InsertField( SvxFieldItem( SvxExtFileField(
598 OUString(), SvxFileType::Var
, SvxFileFormat::PathFull
), EE_FEATURE_FIELD
) );
600 m_xWndCenter
->GrabFocus();
603 case ePageSheetEntry
:
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
));
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
);
620 m_xWndCenter
->GrabFocus();
624 case ePageFileNameEntry
:
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
));
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
);
640 m_xWndCenter
->GrabFocus();
644 case ePageExtFileNameEntry
:
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
) );
653 m_xWndRight
->GrabFocus();
660 OUString
aUserNameEntry(aUserOpt
.GetFirstName() + " " + aUserOpt
.GetLastName());
661 m_xWndLeft
->GetEditEngine()->SetTextCurrentDefaults(aUserNameEntry
);
662 OUString
aPageEntry( m_xFtPage
->get_label() + " ");
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
) );
668 m_xWndRight
->GrabFocus();
672 case eCreatedByEntry
:
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
) );
682 m_xWndRight
->GrabFocus();
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();
702 IMPL_LINK_NOARG(ScHFEditPage
, ListToggleHdl_Impl
, weld::ComboBox
&, void)
704 m_bDropDownActive
= !m_bDropDownActive
;
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());
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
;
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();
731 ListToggleHdl_Impl(*m_xLbDefined
);
734 IMPL_LINK( ScHFEditPage
, ClickHdl
, weld::Button
&, rBtn
, void )
739 if (&rBtn
== m_xBtnText
.get())
741 m_pEditFocus
->SetCharAttributes();
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)
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
,
785 SID_SCATTR_PAGE_HEADERFIRST
,
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
,
798 SID_SCATTR_PAGE_HEADERRIGHT
,
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
,
811 SID_SCATTR_PAGE_HEADERLEFT
,
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
,
824 SID_SCATTR_PAGE_FOOTERFIRST
,
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
,
837 SID_SCATTR_PAGE_FOOTERRIGHT
,
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
,
850 SID_SCATTR_PAGE_FOOTERLEFT
,
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: */