LibreOffice Module sc (master)  1
scuitphfedit.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #undef SC_DLLIMPLEMENTATION
21 
22 #include <scitems.hxx>
23 #include <editeng/eeitem.hxx>
24 
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>
30 
31 #include <unotools/useroptions.hxx>
32 
33 #include <editutil.hxx>
34 #include <global.hxx>
35 #include <attrib.hxx>
36 #include <patattr.hxx>
37 
38 #include <scuitphfedit.hxx>
39 #include <memory>
40 
41 
43  const SfxItemSet& rCoreAttrs,
44  sal_uInt16 nWhichId,
45  bool bHeader)
46  : SfxTabPage(pPage, pController, "modules/scalc/ui/headerfootercontent.ui", "HeaderFooterContent", &rCoreAttrs)
47  , nWhich( nWhichId )
48  , m_bDropDownActive(false)
49  , m_nTimeToggled(-1)
50  , m_xFtDefinedHF(m_xBuilder->weld_label(!bHeader ? "labelFT_F_DEFINED" : "labelFT_H_DEFINED"))
51  , m_xLbDefined(m_xBuilder->weld_combo_box("comboLB_DEFINED"))
52  , m_xFtCustomHF(m_xBuilder->weld_label(!bHeader ? "labelFT_F_CUSTOM" : "labelFT_H_CUSTOM"))
53  , m_xBtnText(m_xBuilder->weld_button("buttonBTN_TEXT"))
54  , m_xBtnFile(m_xBuilder->weld_menu_button("buttonBTN_FILE"))
55  , m_xBtnTable(m_xBuilder->weld_button("buttonBTN_TABLE"))
56  , m_xBtnPage(m_xBuilder->weld_button("buttonBTN_PAGE"))
57  , m_xBtnLastPage(m_xBuilder->weld_button("buttonBTN_PAGES"))
58  , m_xBtnDate(m_xBuilder->weld_button("buttonBTN_DATE"))
59  , m_xBtnTime(m_xBuilder->weld_button("buttonBTN_TIME"))
60  , m_xFtConfidential(m_xBuilder->weld_label("labelSTR_HF_CONFIDENTIAL"))
61  , m_xFtPage(m_xBuilder->weld_label("labelSTR_PAGE"))
62  , m_xFtOfQuestion(m_xBuilder->weld_label("labelSTR_HF_OF_QUESTION"))
63  , m_xFtOf(m_xBuilder->weld_label("labelSTR_HF_OF"))
64  , m_xFtNone(m_xBuilder->weld_label("labelSTR_HF_NONE_IN_BRACKETS"))
65  , m_xFtCreatedBy(m_xBuilder->weld_label("labelSTR_HF_CREATED_BY"))
66  , m_xFtCustomized(m_xBuilder->weld_label("labelSTR_HF_CUSTOMIZED"))
67  , m_xLeft(m_xBuilder->weld_widget("labelFT_LEFT"))
68  , m_xRight(m_xBuilder->weld_widget("labelFT_RIGHT"))
69  , m_xWndLeft(new ScEditWindow(Left, pController->getDialog()))
70  , m_xWndCenter(new ScEditWindow(Center, pController->getDialog()))
71  , m_xWndRight(new ScEditWindow(Right, pController->getDialog()))
72  , m_xWndLeftWnd(new weld::CustomWeld(*m_xBuilder, "textviewWND_LEFT", *m_xWndLeft))
73  , m_xWndCenterWnd(new weld::CustomWeld(*m_xBuilder, "textviewWND_CENTER", *m_xWndCenter))
74  , m_xWndRightWnd(new weld::CustomWeld(*m_xBuilder, "textviewWND_RIGHT", *m_xWndRight))
75  , m_pEditFocus(nullptr)
76 {
77  // tdf#114695 override natural size with a small value
78  // we expect this to get stretched to some larger but
79  // limited size based on surrounding widgets
80  m_xLbDefined->set_size_request(m_xLbDefined->get_approximate_digit_width() * 20, -1);
81 
84 
85  ScPatternAttr aPatAttr( rCoreAttrs.GetPool() );
86 
87  m_xLbDefined->connect_popup_toggled( LINK( this, ScHFEditPage, ListToggleHdl_Impl) );
88  m_xLbDefined->connect_changed( LINK( this, ScHFEditPage, ListHdl_Impl ) );
89  m_xBtnFile->connect_selected( LINK( this, ScHFEditPage, MenuHdl ) );
90  m_xBtnText->connect_clicked( LINK( this, ScHFEditPage, ClickHdl ) );
91  m_xBtnPage->connect_clicked( LINK( this, ScHFEditPage, ClickHdl ) );
92  m_xBtnLastPage->connect_clicked( LINK( this, ScHFEditPage, ClickHdl ) );
93  m_xBtnDate->connect_clicked( LINK( this, ScHFEditPage, ClickHdl ) );
94  m_xBtnTime->connect_clicked( LINK( this, ScHFEditPage, ClickHdl ) );
95  m_xBtnTable->connect_clicked( LINK( this, ScHFEditPage, ClickHdl ) );
96 
97  m_xFtDefinedHF->show();
98  m_xFtCustomHF->show();
99 
100  //swap left/right areas and their labels in RTL mode
102  {
103  sal_Int32 nOldLeftAttach = m_xLeft->get_grid_left_attach();
104  sal_Int32 nOldRightAttach = m_xRight->get_grid_left_attach();
105  m_xLeft->set_grid_left_attach(nOldRightAttach);
106  m_xRight->set_grid_left_attach(nOldLeftAttach);
107 
108  nOldLeftAttach = m_xWndLeftWnd->get_grid_left_attach();
109  nOldRightAttach = m_xWndRightWnd->get_grid_left_attach();
110  m_xWndLeftWnd->set_grid_left_attach(nOldRightAttach);
111  m_xWndRightWnd->set_grid_left_attach(nOldLeftAttach);
112  }
113  m_xWndLeft->SetFont( aPatAttr );
114  m_xWndCenter->SetFont( aPatAttr );
115  m_xWndRight->SetFont( aPatAttr );
116 
117  m_xWndLeft->SetObjectSelectHdl( LINK(this,ScHFEditPage,ObjectSelectHdl) );
118  m_xWndCenter->SetObjectSelectHdl( LINK(this,ScHFEditPage,ObjectSelectHdl) );
119  m_xWndRight->SetObjectSelectHdl( LINK(this,ScHFEditPage,ObjectSelectHdl) );
120  auto setEditFocus = [this](ScEditWindow & rEdit) { this->m_pEditFocus = &rEdit; };
121  m_xWndLeft->SetGetFocusHdl(setEditFocus);
122  m_xWndCenter->SetGetFocusHdl(setEditFocus);
123  m_xWndRight->SetGetFocusHdl(setEditFocus);
124 
125  m_xWndLeft->GrabFocus();
126  m_pEditFocus = m_xWndLeft.get(); // there's no event from grab_focus()
127 
129 
130 }
131 
132 IMPL_LINK_NOARG( ScHFEditPage, ObjectSelectHdl, ScEditWindow&, void )
133 {
134  m_xBtnText->grab_focus();
135 }
136 
138 {
139 }
140 
142 {
143  m_xWndLeft->SetNumType(eNumType);
144  m_xWndCenter->SetNumType(eNumType);
145  m_xWndRight->SetNumType(eNumType);
146 }
147 
148 void ScHFEditPage::Reset( const SfxItemSet* rCoreSet )
149 {
150  const SfxPoolItem* pItem = nullptr;
151  if ( rCoreSet->HasItem(nWhich, &pItem) )
152  {
153  const ScPageHFItem& rItem = static_cast<const ScPageHFItem&>(*pItem);
154 
155  if( const EditTextObject* pLeft = rItem.GetLeftArea() )
156  m_xWndLeft->SetText( *pLeft );
157  if( const EditTextObject* pCenter = rItem.GetCenterArea() )
158  m_xWndCenter->SetText( *pCenter );
159  if( const EditTextObject* pRight = rItem.GetRightArea() )
160  m_xWndRight->SetText( *pRight );
161 
163  }
164 }
165 
167 {
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();
172 
173  aItem.SetLeftArea ( *pLeft );
174  aItem.SetCenterArea( *pCenter );
175  aItem.SetRightArea ( *pRight );
176 
177  rCoreSet->Put( aItem );
178 
179  return true;
180 }
181 
183 {
184  SvtUserOptions aUserOpt;
185 
186  std::optional<Color> pTxtColour;
187  std::optional<Color> pFldColour;
188 
189  // Get the all field values at the outset.
190  OUString aPageFieldValue(m_xWndLeft->GetEditEngine()->CalcFieldValue(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), 0,0, pTxtColour, pFldColour));
191  OUString aSheetFieldValue(m_xWndLeft->GetEditEngine()->CalcFieldValue(SvxFieldItem(SvxTableField(), EE_FEATURE_FIELD), 0,0, pTxtColour, pFldColour));
192  OUString aFileFieldValue(m_xWndLeft->GetEditEngine()->CalcFieldValue(SvxFieldItem(SvxFileField(), EE_FEATURE_FIELD), 0,0, pTxtColour, pFldColour));
193  OUString aExtFileFieldValue(m_xWndLeft->GetEditEngine()->CalcFieldValue(SvxFieldItem(SvxExtFileField(), EE_FEATURE_FIELD), 0,0, pTxtColour, pFldColour));
194  OUString aDateFieldValue(m_xWndLeft->GetEditEngine()->CalcFieldValue(SvxFieldItem(SvxDateField(), EE_FEATURE_FIELD), 0,0, pTxtColour, pFldColour));
195 
196  m_xLbDefined->clear();
197 
198  m_xLbDefined->append_text(m_xFtNone->get_label());
199 
200  OUString aPageEntry(m_xFtPage->get_label() + " " + aPageFieldValue);
201  m_xLbDefined->append_text(aPageEntry);
202 
203  OUString aPageOfEntry(aPageEntry + " " + m_xFtOfQuestion->get_label());
204  m_xLbDefined->append_text( aPageOfEntry);
205 
206  m_xLbDefined->append_text(aSheetFieldValue);
207 
208  OUString aConfidentialEntry(aUserOpt.GetCompany() + " " + m_xFtConfidential->get_label() + ", " + aDateFieldValue + ", " + aPageEntry);
209  m_xLbDefined->append_text( aConfidentialEntry);
210 
211  OUString aFileNamePageEntry(aFileFieldValue + ", " + aPageEntry);
212  m_xLbDefined->append_text( aFileNamePageEntry);
213 
214  m_xLbDefined->append_text( aExtFileFieldValue);
215 
216  OUString aPageSheetNameEntry(aPageEntry + ", " + aSheetFieldValue);
217  m_xLbDefined->append_text( aPageSheetNameEntry);
218 
219  OUString aPageFileNameEntry(aPageEntry + ", " + aFileFieldValue);
220  m_xLbDefined->append_text( aPageFileNameEntry);
221 
222  OUString aPagePathNameEntry(aPageEntry + ", " + aExtFileFieldValue);
223  m_xLbDefined->append_text( aPagePathNameEntry);
224 
225  OUString aUserNameEntry(aUserOpt.GetFirstName() + " " + aUserOpt.GetLastName() + ", " + aPageEntry + ", " + aDateFieldValue);
226  m_xLbDefined->append_text( aUserNameEntry);
227 
228  OUString aCreatedByEntry = m_xFtCreatedBy->get_label() + " " + aUserOpt.GetFirstName() + " " + aUserOpt.GetLastName() + ", " +
229  aDateFieldValue + ", " + aPageEntry;
230  m_xLbDefined->append_text( aCreatedByEntry);
231 }
232 
234 {
235  const sal_Int32 nCount = m_xLbDefined->get_count();
236  if(nCount == eEntryCount)
237  {
238  m_xLbDefined->append_text( m_xFtCustomized->get_label() );
239  m_xLbDefined->set_active(eEntryCount);
240  }
241 }
242 
244 {
245  const sal_Int32 nCount = m_xLbDefined->get_count();
246  if(nCount > eEntryCount )
247  m_xLbDefined->remove( nCount-1);
248 }
249 
250 // determine if the header/footer exists in our predefined list and set select to it.
252 {
253  SvtUserOptions aUserOpt;
254 
255  // default to customized
256  ScHFEntryId eSelectEntry = eEntryCount;
257 
258  std::unique_ptr< EditTextObject > pLeftObj;
259  std::unique_ptr< EditTextObject > pCenterObj;
260  std::unique_ptr< EditTextObject > pRightObj;
261 
262  OUString aLeftEntry;
263  OUString aCenterEntry;
264  OUString aRightEntry;
265 
266  pLeftObj = m_xWndLeft->GetEditEngine()->CreateTextObject();
267  pCenterObj = m_xWndCenter->GetEditEngine()->CreateTextObject();
268  pRightObj = m_xWndRight->GetEditEngine()->CreateTextObject();
269 
270  bool bFound = false;
271 
272  const sal_Int32 nCount = m_xLbDefined->get_count();
273  for(sal_Int32 i = 0; i < nCount && !bFound; ++i)
274  {
275  switch(static_cast<ScHFEntryId>(i))
276  {
277  case eNoneEntry:
278  {
279  aLeftEntry = pLeftObj->GetText(0);
280  aCenterEntry = pCenterObj->GetText(0);
281  aRightEntry = pRightObj->GetText(0);
282  if(aLeftEntry == EMPTY_OUSTRING && aCenterEntry == EMPTY_OUSTRING
283  && aRightEntry == EMPTY_OUSTRING)
284  {
285  eSelectEntry = eNoneEntry;
286  bFound = true;
287  }
288  }
289  break;
290 
291  case ePageEntry:
292  {
293  aLeftEntry = pLeftObj->GetText(0);
294  aRightEntry = pRightObj->GetText(0);
295  if(aLeftEntry == EMPTY_OUSTRING && aRightEntry == EMPTY_OUSTRING)
296  {
297  if(IsPageEntry(m_xWndCenter->GetEditEngine(), pCenterObj.get()))
298  {
299  eSelectEntry = ePageEntry;
300  bFound = true;
301  }
302  }
303  }
304  break;
305 
306  //TODO
307  case ePagesEntry:
308  {
309  }
310  break;
311 
312  case eSheetEntry:
313  {
314  aLeftEntry = pLeftObj->GetText(0);
315  aRightEntry = pRightObj->GetText(0);
316  if(aLeftEntry == EMPTY_OUSTRING && aRightEntry == EMPTY_OUSTRING)
317  {
318  if(pCenterObj->IsFieldObject())
319  {
320  const SvxFieldItem* pFieldItem = pCenterObj->GetField();
321  if(pFieldItem)
322  {
323  const SvxFieldData* pField = pFieldItem->GetField();
324  if(dynamic_cast<const SvxTableField*>( pField))
325  {
326  eSelectEntry = eSheetEntry;
327  bFound = true;
328  }
329  }
330  }
331  }
332  }
333  break;
334 
335  case eConfidentialEntry:
336  {
337  if(IsDateEntry(pCenterObj.get()) && IsPageEntry(m_xWndRight->GetEditEngine(), pRightObj.get()))
338  {
339  OUString aConfidentialEntry(aUserOpt.GetCompany() + " " + m_xFtConfidential->get_label());
340  if(aConfidentialEntry == m_xWndLeft->GetEditEngine()->GetText(0))
341  {
342  eSelectEntry = eConfidentialEntry;
343  bFound = true;
344  }
345  }
346  }
347  break;
348 
349  //TODO
350  case eFileNamePageEntry:
351  {
352  }
353  break;
354 
355  case eExtFileNameEntry:
356  {
357  aLeftEntry = pLeftObj->GetText(0);
358  aRightEntry = pRightObj->GetText(0);
359  if(IsExtFileNameEntry(pCenterObj.get()) && aLeftEntry == EMPTY_OUSTRING
360  && aRightEntry == EMPTY_OUSTRING)
361  {
362  eSelectEntry = eExtFileNameEntry;
363  bFound = true;
364  }
365  }
366  break;
367 
368  //TODO
369  case ePageSheetEntry:
370  {
371  }
372  break;
373 
374  //TODO
375  case ePageFileNameEntry:
376  {
377  }
378  break;
379 
381  {
382  aLeftEntry = pLeftObj->GetText(0);
383  if(IsPageEntry(m_xWndCenter->GetEditEngine(), pCenterObj.get()) &&
384  IsExtFileNameEntry(pRightObj.get()) && aLeftEntry == EMPTY_OUSTRING)
385  {
386  eSelectEntry = ePageExtFileNameEntry;
387  bFound = true;
388  }
389  }
390  break;
391 
392  case eUserNameEntry:
393  {
394  if(IsDateEntry(pRightObj.get()) && IsPageEntry(m_xWndCenter->GetEditEngine(), pCenterObj.get()))
395  {
396  OUString aUserNameEntry(aUserOpt.GetFirstName() + " " + aUserOpt.GetLastName());
397 
398  if(aUserNameEntry == m_xWndLeft->GetEditEngine()->GetText(0))
399  {
400  eSelectEntry = eUserNameEntry;
401  bFound = true;
402  }
403  }
404  }
405  break;
406 
407  case eCreatedByEntry:
408  {
409  if(IsDateEntry(pCenterObj.get()) && IsPageEntry(m_xWndRight->GetEditEngine(), pRightObj.get()))
410  {
411  OUString aCreatedByEntry(m_xFtCreatedBy->get_label() + " " + aUserOpt.GetFirstName() + " " + aUserOpt.GetLastName());
412 
413  if(aCreatedByEntry == m_xWndLeft->GetEditEngine()->GetText(0))
414  {
415  eSelectEntry = eCreatedByEntry;
416  bFound = true;
417  }
418  }
419  }
420  break;
421 
422  default:
423  {
424  // added to avoid warnings
425  }
426  }
427  }
428 
429  if(eSelectEntry == eEntryCount)
431 
432  m_xLbDefined->set_active( sal::static_int_cast<sal_uInt16>( eSelectEntry ) );
433 }
434 
436 {
437  if(!pEngine || !pTextObj)
438  return false;
439 
440  bool bReturn = false;
441 
442  if(!pTextObj->IsFieldObject())
443  {
444  std::vector<sal_Int32> aPosList;
445  pEngine->GetPortions(0,aPosList);
446  if(aPosList.size() == 2)
447  {
448  OUString aPageEntry(m_xFtPage->get_label() + " ");
449  ESelection aSel(0,0,0,0);
450  aSel.nEndPos = aPageEntry.getLength();
451  if(aPageEntry == pEngine->GetText(aSel))
452  {
453  aSel.nStartPos = aSel.nEndPos;
454  aSel.nEndPos++;
455  std::unique_ptr< EditTextObject > pPageObj = pEngine->CreateTextObject(aSel);
456  if(pPageObj && pPageObj->IsFieldObject() )
457  {
458  const SvxFieldItem* pFieldItem = pPageObj->GetField();
459  if(pFieldItem)
460  {
461  const SvxFieldData* pField = pFieldItem->GetField();
462  if(dynamic_cast<const SvxPageField*>( pField))
463  bReturn = true;
464  }
465  }
466  }
467  }
468  }
469  return bReturn;
470 }
471 
473 {
474  if(!pTextObj)
475  return false;
476 
477  bool bReturn = false;
478  if(pTextObj->IsFieldObject())
479  {
480  const SvxFieldItem* pFieldItem = pTextObj->GetField();
481  if(pFieldItem)
482  {
483  const SvxFieldData* pField = pFieldItem->GetField();
484  if(dynamic_cast<const SvxDateField*>( pField))
485  bReturn = true;
486  }
487  }
488  return bReturn;
489 }
490 
492 {
493  if(!pTextObj)
494  return false;
495  bool bReturn = false;
496  if(pTextObj->IsFieldObject())
497  {
498  const SvxFieldItem* pFieldItem = pTextObj->GetField();
499  if(pFieldItem)
500  {
501  const SvxFieldData* pField = pFieldItem->GetField();
502  if(dynamic_cast<const SvxExtFileField*>( pField))
503  bReturn = true;
504  }
505  }
506  return bReturn;
507 }
508 
510 {
511  SvtUserOptions aUserOpt;
512  std::unique_ptr< EditTextObject > pTextObj;
513 
514  switch(eSel)
515  {
516  case eNoneEntry:
517  ClearTextAreas();
518  if(!bTravelling)
519  m_xWndLeft->GrabFocus();
520  break;
521 
522  case ePageEntry:
523  {
524  ClearTextAreas();
525  OUString aPageEntry( m_xFtPage->get_label() + " " );
526  m_xWndCenter->GetEditEngine()->SetTextCurrentDefaults(aPageEntry);
528  if(!bTravelling)
529  m_xWndCenter->GrabFocus();
530  }
531  break;
532 
533  case ePagesEntry:
534  {
535  ClearTextAreas();
536  ESelection aSel(0,0,0,0);
537  OUString aPageEntry( m_xFtPage->get_label() + " ");
538  m_xWndCenter->GetEditEngine()->SetTextCurrentDefaults(aPageEntry);
539  aSel.nEndPos = aPageEntry.getLength();
540  m_xWndCenter->GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
541  ++aSel.nEndPos;
542 
543  OUString aPageOfEntry(" " + m_xFtOf->get_label() + " ");
544  m_xWndCenter->GetEditEngine()->QuickInsertText(aPageOfEntry,ESelection(aSel.nEndPara,aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
545  aSel.nEndPos = aSel.nEndPos + aPageOfEntry.getLength();
546  m_xWndCenter->GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPagesField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara,aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
547  pTextObj = m_xWndCenter->GetEditEngine()->CreateTextObject();
548  m_xWndCenter->SetText(*pTextObj);
549  if(!bTravelling)
550  m_xWndCenter->GrabFocus();
551  }
552  break;
553 
554  case eSheetEntry:
555  ClearTextAreas();
557  if(!bTravelling)
558  m_xWndCenter->GrabFocus();
559  break;
560 
561  case eConfidentialEntry:
562  {
563  ClearTextAreas();
564  OUString aConfidentialEntry(aUserOpt.GetCompany() + " " + m_xFtConfidential->get_label());
565  m_xWndLeft->GetEditEngine()->SetTextCurrentDefaults(aConfidentialEntry);
566  m_xWndCenter->InsertField( SvxFieldItem(SvxDateField(Date( Date::SYSTEM ),SvxDateType::Var), EE_FEATURE_FIELD) );
567 
568  OUString aPageEntry( m_xFtPage->get_label() + " ");
569  m_xWndRight->GetEditEngine()->SetTextCurrentDefaults(aPageEntry);
571  if(!bTravelling)
572  m_xWndRight->GrabFocus();
573  }
574  break;
575 
576  case eFileNamePageEntry:
577  {
578  ClearTextAreas();
579  ESelection aSel(0,0,0,0);
580  m_xWndCenter->GetEditEngine()->QuickInsertField(SvxFieldItem( SvxFileField(), EE_FEATURE_FIELD ), aSel );
581  ++aSel.nEndPos;
582  OUString aPageEntry(", " + m_xFtPage->get_label() + " ");
583  m_xWndCenter->GetEditEngine()->QuickInsertText(aPageEntry, ESelection(aSel.nEndPara,aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
584  aSel.nStartPos = aSel.nEndPos;
585  aSel.nEndPos = aSel.nEndPos + aPageEntry.getLength();
586  m_xWndCenter->GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara,aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
587  pTextObj = m_xWndCenter->GetEditEngine()->CreateTextObject();
588  m_xWndCenter->SetText(*pTextObj);
589  if(!bTravelling)
590  m_xWndCenter->GrabFocus();
591  }
592  break;
593 
594  case eExtFileNameEntry:
595  ClearTextAreas();
597  EMPTY_OUSTRING, SvxFileType::Var, SvxFileFormat::PathFull ), EE_FEATURE_FIELD ) );
598  if(!bTravelling)
599  m_xWndCenter->GrabFocus();
600  break;
601 
602  case ePageSheetEntry:
603  {
604  ClearTextAreas();
605  ESelection aSel(0,0,0,0);
606  OUString aPageEntry( m_xFtPage->get_label() + " " );
607  m_xWndCenter->GetEditEngine()->SetTextCurrentDefaults(aPageEntry);
608  aSel.nEndPos = aPageEntry.getLength();
609  m_xWndCenter->GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
610  ++aSel.nEndPos;
611 
612  OUString aCommaSpace(", ");
613  m_xWndCenter->GetEditEngine()->QuickInsertText(aCommaSpace,ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
614  aSel.nEndPos = aSel.nEndPos + aCommaSpace.getLength();
615  m_xWndCenter->GetEditEngine()->QuickInsertField( SvxFieldItem(SvxTableField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
616  pTextObj = m_xWndCenter->GetEditEngine()->CreateTextObject();
617  m_xWndCenter->SetText(*pTextObj);
618  if(!bTravelling)
619  m_xWndCenter->GrabFocus();
620  }
621  break;
622 
623  case ePageFileNameEntry:
624  {
625  ClearTextAreas();
626  ESelection aSel(0,0,0,0);
627  OUString aPageEntry( m_xFtPage->get_label() + " " );
628  m_xWndCenter->GetEditEngine()->SetTextCurrentDefaults(aPageEntry);
629  aSel.nEndPos = aPageEntry.getLength();
630  m_xWndCenter->GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
631  ++aSel.nEndPos;
632  OUString aCommaSpace(", ");
633  m_xWndCenter->GetEditEngine()->QuickInsertText(aCommaSpace,ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
634  aSel.nEndPos = aSel.nEndPos + aCommaSpace.getLength();
635  m_xWndCenter->GetEditEngine()->QuickInsertField( SvxFieldItem(SvxFileField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
636  pTextObj = m_xWndCenter->GetEditEngine()->CreateTextObject();
637  m_xWndCenter->SetText(*pTextObj);
638  if(!bTravelling)
639  m_xWndCenter->GrabFocus();
640  }
641  break;
642 
644  {
645  ClearTextAreas();
646  OUString aPageEntry( m_xFtPage->get_label() + " " );
647  m_xWndCenter->GetEditEngine()->SetTextCurrentDefaults(aPageEntry);
650  EMPTY_OUSTRING, SvxFileType::Var, SvxFileFormat::PathFull ), EE_FEATURE_FIELD ) );
651  if(!bTravelling)
652  m_xWndRight->GrabFocus();
653  }
654  break;
655 
656  case eUserNameEntry:
657  {
658  ClearTextAreas();
659  OUString aUserNameEntry(aUserOpt.GetFirstName() + " " + aUserOpt.GetLastName());
660  m_xWndLeft->GetEditEngine()->SetTextCurrentDefaults(aUserNameEntry);
661  OUString aPageEntry( m_xFtPage->get_label() + " ");
662  //aPageEntry += " ";
663  m_xWndCenter->GetEditEngine()->SetTextCurrentDefaults(aPageEntry);
665  m_xWndRight->InsertField( SvxFieldItem(SvxDateField(Date( Date::SYSTEM ),SvxDateType::Var), EE_FEATURE_FIELD) );
666  if(!bTravelling)
667  m_xWndRight->GrabFocus();
668  }
669  break;
670 
671  case eCreatedByEntry:
672  {
673  ClearTextAreas();
674  OUString aCreatedByEntry( m_xFtCreatedBy->get_label() + " " + aUserOpt.GetFirstName() + " " + aUserOpt.GetLastName());
675  m_xWndLeft->GetEditEngine()->SetTextCurrentDefaults(aCreatedByEntry);
676  m_xWndCenter->InsertField( SvxFieldItem(SvxDateField(Date( Date::SYSTEM ),SvxDateType::Var), EE_FEATURE_FIELD) );
677  OUString aPageEntry( m_xFtPage->get_label() + " " );
678  m_xWndRight->GetEditEngine()->SetTextCurrentDefaults(aPageEntry);
680  if(!bTravelling)
681  m_xWndRight->GrabFocus();
682  }
683  break;
684 
685  default :
686  break;
687  }
688 }
689 
691 {
692  m_xWndLeft->GetEditEngine()->SetTextCurrentDefaults(EMPTY_OUSTRING);
693  m_xWndLeft->Invalidate();
694  m_xWndCenter->GetEditEngine()->SetTextCurrentDefaults(EMPTY_OUSTRING);
695  m_xWndCenter->Invalidate();
696  m_xWndRight->GetEditEngine()->SetTextCurrentDefaults(EMPTY_OUSTRING);
697  m_xWndRight->Invalidate();
698 }
699 
700 // Handler:
701 IMPL_LINK_NOARG(ScHFEditPage, ListToggleHdl_Impl, weld::ComboBox&, void)
702 {
703  m_bDropDownActive = !m_bDropDownActive;
704  TimeValue aNow;
705  osl_getSystemTime(&aNow);
706  m_nTimeToggled = sal_Int64(aNow.Seconds) * 1000000000L + aNow.Nanosec;
707 }
708 
710 {
711  ScHFEntryId eSel = static_cast<ScHFEntryId>(m_xLbDefined->get_active());
712 
713  TimeValue aNow;
714  osl_getSystemTime(&aNow);
715  sal_Int64 nNow = sal_Int64(aNow.Seconds) * 1000000000L + aNow.Nanosec;
716 
717  // order of dropdown vs select not guaranteed
718  bool bDiscrepency = m_xLbDefined->get_popup_shown() != m_bDropDownActive;
719  if (bDiscrepency)
720  ListToggleHdl_Impl(*m_xLbDefined);
721 
722  bool bFocusToTarget = !m_xLbDefined->get_popup_shown() && m_nTimeToggled != -1 && (nNow - m_nTimeToggled < 800000000L);
723  ProcessDefinedListSel(eSel, !bFocusToTarget);
724  // check if we need to remove the customized entry.
725  if (!m_bDropDownActive && eSel < eEntryCount)
726  RemoveFromDefinedList();
727 
728  // keep balanced
729  if (bDiscrepency)
730  ListToggleHdl_Impl(*m_xLbDefined);
731 }
732 
733 IMPL_LINK( ScHFEditPage, ClickHdl, weld::Button&, rBtn, void )
734 {
735  if (!m_pEditFocus)
736  return;
737 
738  if (&rBtn == m_xBtnText.get())
739  {
740  m_pEditFocus->SetCharAttributes();
741  }
742  else
743  {
744  if ( &rBtn == m_xBtnPage.get() )
745  m_pEditFocus->InsertField(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD));
746  else if ( &rBtn == m_xBtnLastPage.get() )
747  m_pEditFocus->InsertField(SvxFieldItem(SvxPagesField(), EE_FEATURE_FIELD));
748  else if ( &rBtn == m_xBtnDate.get() )
749  m_pEditFocus->InsertField(SvxFieldItem(SvxDateField(Date(Date::SYSTEM),SvxDateType::Var), EE_FEATURE_FIELD));
750  else if ( &rBtn == m_xBtnTime.get() )
751  m_pEditFocus->InsertField(SvxFieldItem(SvxTimeField(), EE_FEATURE_FIELD));
752  else if ( &rBtn == m_xBtnTable.get() )
753  m_pEditFocus->InsertField(SvxFieldItem(SvxTableField(), EE_FEATURE_FIELD));
754  }
755  InsertToDefinedList();
756  m_pEditFocus->GrabFocus();
757 }
758 
759 IMPL_LINK(ScHFEditPage, MenuHdl, const OString&, rSelectedId, void)
760 {
761  if (!m_pEditFocus)
762  return;
763 
764  if (rSelectedId == "title")
765  {
766  m_pEditFocus->InsertField(SvxFieldItem(SvxFileField(), EE_FEATURE_FIELD));
767  }
768  else if (rSelectedId == "filename")
769  {
770  m_pEditFocus->InsertField( SvxFieldItem( SvxExtFileField(
771  OUString(), SvxFileType::Var, SvxFileFormat::NameAndExt ), EE_FEATURE_FIELD ) );
772  }
773  else if (rSelectedId == "pathname")
774  {
775  m_pEditFocus->InsertField( SvxFieldItem( SvxExtFileField(
776  OUString(), SvxFileType::Var, SvxFileFormat::PathFull ), EE_FEATURE_FIELD ) );
777  }
778 }
779 
780 
782  : ScHFEditPage( pPage, pController,
783  rCoreSet,
784  rCoreSet.GetPool()->GetWhich(SID_SCATTR_PAGE_HEADERRIGHT ),
785  true )
786  {}
787 
788 std::unique_ptr<SfxTabPage> ScRightHeaderEditPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rCoreSet )
789 {
790  return std::make_unique<ScRightHeaderEditPage>( pPage, pController, *rCoreSet );
791 }
792 
793 
795  : ScHFEditPage( pPage, pController,
796  rCoreSet,
797  rCoreSet.GetPool()->GetWhich(SID_SCATTR_PAGE_HEADERLEFT ),
798  true )
799  {}
800 
801 std::unique_ptr<SfxTabPage> ScLeftHeaderEditPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rCoreSet )
802 {
803  return std::make_unique<ScLeftHeaderEditPage>( pPage, pController, *rCoreSet );
804 }
805 
806 
808  : ScHFEditPage( pPage, pController,
809  rCoreSet,
810  rCoreSet.GetPool()->GetWhich(SID_SCATTR_PAGE_FOOTERRIGHT ),
811  false )
812  {}
813 
814 std::unique_ptr<SfxTabPage> ScRightFooterEditPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rCoreSet )
815 {
816  return std::make_unique<ScRightFooterEditPage>( pPage, pController, *rCoreSet );
817 }
818 
819 
821  : ScHFEditPage( pPage, pController,
822  rCoreSet,
823  rCoreSet.GetPool()->GetWhich(SID_SCATTR_PAGE_FOOTERLEFT ),
824  false )
825  {}
826 
827 std::unique_ptr<SfxTabPage> ScLeftFooterEditPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rCoreSet )
828 {
829  return std::make_unique<ScLeftFooterEditPage>( pPage, pController, *rCoreSet );
830 };
831 
832 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::CustomWeld > m_xWndRightWnd
OUString GetText(LineEnd eEnd=LINEEND_LF) const
std::unique_ptr< weld::Label > m_xFtPage
std::unique_ptr< weld::Widget > m_xRight
bool IsPageEntry(EditEngine *pEngine, const EditTextObject *pTextObj)
const SvxFieldItem * GetField() const
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rCoreSet)
#define EMPTY_OUSTRING
Definition: global.hxx:214
#define SID_SCATTR_PAGE_FOOTERRIGHT
Definition: scitems.hxx:222
std::unique_ptr< weld::MenuButton > m_xBtnFile
const EditTextObject * GetCenterArea() const
Definition: attrib.hxx:186
std::unique_ptr< weld::ComboBox > m_xLbDefined
void ProcessDefinedListSel(ScHFEntryId eSel, bool bTravelling)
#define SID_SCATTR_PAGE_HEADERRIGHT
Definition: scitems.hxx:221
std::unique_ptr< weld::Label > m_xFtConfidential
std::unique_ptr< weld::Button > m_xBtnText
#define SID_SCATTR_PAGE_FOOTERLEFT
Definition: scitems.hxx:220
SvxNumType
void SetLeftArea(const EditTextObject &rNew)
Definition: attrib.cxx:472
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rCoreSet)
IMPL_LINK_NOARG(ScHFEditPage, ObjectSelectHdl, ScEditWindow &, void)
void SetSelectDefinedList()
void SetCenterArea(const EditTextObject &rNew)
Definition: attrib.cxx:477
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rCoreSet)
int nCount
std::unique_ptr< weld::Label > m_xFtNone
std::unique_ptr< weld::Label > m_xFtOfQuestion
sal_Int32 nEndPos
virtual void Reset(const SfxItemSet *rCoreSet) override
virtual bool FillItemSet(SfxItemSet *rCoreSet) override
std::unique_ptr< weld::CustomWeld > m_xWndLeftWnd
sal_Int32 nEndPara
ScHFEditPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rCoreSet, sal_uInt16 nWhich, bool bHeader)
void InitPreDefinedList()
int i
std::unique_ptr< ScEditWindow > m_xWndCenter
sal_uInt16 nWhich
std::unique_ptr< weld::Button > m_xBtnTime
IMPL_LINK(ScHFEditPage, ClickHdl, weld::Button &, rBtn, void)
std::unique_ptr< EditTextObject > CreateTextObject()
ScEditWindow * m_pEditFocus
static bool GetLayoutRTL()
void SetRightArea(const EditTextObject &rNew)
Definition: attrib.cxx:482
std::unique_ptr< weld::Button > m_xBtnPage
bool IsFieldObject() const
SfxItemPool * GetPool() const
void InsertToDefinedList()
std::unique_ptr< weld::Label > m_xFtOf
std::unique_ptr< weld::Widget > m_xLeft
OUString GetFirstName() const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
#define SID_SCATTR_PAGE_HEADERLEFT
Definition: scitems.hxx:219
std::unique_ptr< weld::Button > m_xBtnTable
weld::Entry & rEdit
OUString GetLastName() const
#define GetWhich(nSlot)
const EditTextObject * GetRightArea() const
Definition: attrib.hxx:187
const EditTextObject * GetLeftArea() const
Definition: attrib.hxx:185
void GetPortions(sal_Int32 nPara, std::vector< sal_Int32 > &rList)
std::unique_ptr< weld::Label > m_xFtCreatedBy
bool HasItem(sal_uInt16 nWhich, const SfxPoolItem **ppItem=nullptr) const
virtual ~ScHFEditPage() override
ScLeftFooterEditPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
OUString GetCompany() const
std::unique_ptr< weld::Label > m_xFtCustomized
std::unique_ptr< weld::Button > m_xBtnLastPage
ScRightFooterEditPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
void SetNumType(SvxNumType eNumType)
constexpr sal_uInt16 EE_FEATURE_FIELD(EE_FEATURE_NOTCONV+1)
ScHFEntryId
std::unique_ptr< ScEditWindow > m_xWndLeft
std::unique_ptr< weld::Label > m_xFtCustomHF
ScRightHeaderEditPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rCoreSet)
void ClearTextAreas()
static bool IsDateEntry(const EditTextObject *pTextObj)
std::unique_ptr< weld::Button > m_xBtnDate
std::unique_ptr< weld::Label > m_xFtDefinedHF
void RemoveFromDefinedList()
ScLeftHeaderEditPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
static bool IsExtFileNameEntry(const EditTextObject *pTextObj)
const SvxFieldData * GetField() const
std::unique_ptr< ScEditWindow > m_xWndRight
sal_Int32 nStartPos