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