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 std::optional<FontLineStyle> pFldLineStyle;
186
187 // Get the all field values at the outset.
188 OUString aPageFieldValue(m_xWndLeft->GetEditEngine()->CalcFieldValue(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), 0,0, pTxtColour, pFldColour, pFldLineStyle));
189 OUString aSheetFieldValue(m_xWndLeft->GetEditEngine()->CalcFieldValue(SvxFieldItem(SvxTableField(), EE_FEATURE_FIELD), 0,0, pTxtColour, pFldColour, pFldLineStyle));
190 OUString aFileFieldValue(m_xWndLeft->GetEditEngine()->CalcFieldValue(SvxFieldItem(SvxFileField(), EE_FEATURE_FIELD), 0,0, pTxtColour, pFldColour, pFldLineStyle));
191 OUString aExtFileFieldValue(m_xWndLeft->GetEditEngine()->CalcFieldValue(SvxFieldItem(SvxExtFileField(), EE_FEATURE_FIELD), 0,0, pTxtColour, pFldColour, pFldLineStyle));
192 OUString aDateFieldValue(m_xWndLeft->GetEditEngine()->CalcFieldValue(SvxFieldItem(SvxDateField(), EE_FEATURE_FIELD), 0,0, pTxtColour, pFldColour, pFldLineStyle));
193
194 m_xLbDefined->clear();
195
196 m_xLbDefined->append_text(m_xFtNone->get_label());
197
198 OUString aPageEntry(m_xFtPage->get_label() + " " + aPageFieldValue);
199 m_xLbDefined->append_text(aPageEntry);
200
201 OUString aPageOfEntry(aPageEntry + " " + m_xFtOfQuestion->get_label());
202 m_xLbDefined->append_text( aPageOfEntry);
203
204 m_xLbDefined->append_text(aSheetFieldValue);
205
206 OUString aConfidentialEntry(aUserOpt.GetCompany() + " " + m_xFtConfidential->get_label() + ", " + aDateFieldValue + ", " + aPageEntry);
207 m_xLbDefined->append_text( aConfidentialEntry);
208
209 OUString aFileNamePageEntry(aFileFieldValue + ", " + aPageEntry);
210 m_xLbDefined->append_text( aFileNamePageEntry);
211
212 m_xLbDefined->append_text( aExtFileFieldValue);
213
214 OUString aPageSheetNameEntry(aPageEntry + ", " + aSheetFieldValue);
215 m_xLbDefined->append_text( aPageSheetNameEntry);
216
217 OUString aPageFileNameEntry(aPageEntry + ", " + aFileFieldValue);
218 m_xLbDefined->append_text( aPageFileNameEntry);
219
220 OUString aPagePathNameEntry(aPageEntry + ", " + aExtFileFieldValue);
221 m_xLbDefined->append_text( aPagePathNameEntry);
222
223 OUString aUserNameEntry(aUserOpt.GetFirstName() + " " + aUserOpt.GetLastName() + ", " + aPageEntry + ", " + aDateFieldValue);
224 m_xLbDefined->append_text( aUserNameEntry);
225
226 OUString aCreatedByEntry = m_xFtCreatedBy->get_label() + " " + aUserOpt.GetFirstName() + " " + aUserOpt.GetLastName() + ", " +
227 aDateFieldValue + ", " + aPageEntry;
228 m_xLbDefined->append_text( aCreatedByEntry);
229}
230
232{
233 const sal_Int32 nCount = m_xLbDefined->get_count();
234 if(nCount == eEntryCount)
235 {
236 m_xLbDefined->append_text( m_xFtCustomized->get_label() );
237 m_xLbDefined->set_active(eEntryCount);
238 }
239}
240
242{
243 const sal_Int32 nCount = m_xLbDefined->get_count();
244 if(nCount > eEntryCount )
245 m_xLbDefined->remove( nCount-1);
246}
247
248// determine if the header/footer exists in our predefined list and set select to it.
250{
251 SvtUserOptions aUserOpt;
252
253 // default to customized
254 ScHFEntryId eSelectEntry = eEntryCount;
255
256 std::unique_ptr< EditTextObject > pLeftObj;
257 std::unique_ptr< EditTextObject > pCenterObj;
258 std::unique_ptr< EditTextObject > pRightObj;
259
260 OUString aLeftEntry;
261 OUString aCenterEntry;
262 OUString aRightEntry;
263
264 pLeftObj = m_xWndLeft->GetEditEngine()->CreateTextObject();
265 pCenterObj = m_xWndCenter->GetEditEngine()->CreateTextObject();
266 pRightObj = m_xWndRight->GetEditEngine()->CreateTextObject();
267
268 bool bFound = false;
269
270 const sal_Int32 nCount = m_xLbDefined->get_count();
271 for(sal_Int32 i = 0; i < nCount && !bFound; ++i)
272 {
273 switch(static_cast<ScHFEntryId>(i))
274 {
275 case eNoneEntry:
276 {
277 aLeftEntry = pLeftObj->GetText(0);
278 aCenterEntry = pCenterObj->GetText(0);
279 aRightEntry = pRightObj->GetText(0);
280 if(aLeftEntry.isEmpty() && aCenterEntry.isEmpty()
281 && aRightEntry.isEmpty())
282 {
283 eSelectEntry = eNoneEntry;
284 bFound = true;
285 }
286 }
287 break;
288
289 case ePageEntry:
290 {
291 aLeftEntry = pLeftObj->GetText(0);
292 aRightEntry = pRightObj->GetText(0);
293 if(aLeftEntry.isEmpty() && aRightEntry.isEmpty())
294 {
295 if(IsPageEntry(m_xWndCenter->GetEditEngine(), pCenterObj.get()))
296 {
297 eSelectEntry = ePageEntry;
298 bFound = true;
299 }
300 }
301 }
302 break;
303
304 //TODO
305 case ePagesEntry:
306 {
307 }
308 break;
309
310 case eSheetEntry:
311 {
312 aLeftEntry = pLeftObj->GetText(0);
313 aRightEntry = pRightObj->GetText(0);
314 if(aLeftEntry.isEmpty() && aRightEntry.isEmpty())
315 {
316 if(pCenterObj->IsFieldObject())
317 {
318 const SvxFieldItem* pFieldItem = pCenterObj->GetField();
319 if(pFieldItem)
320 {
321 const SvxFieldData* pField = pFieldItem->GetField();
322 if(dynamic_cast<const SvxTableField*>( pField))
323 {
324 eSelectEntry = eSheetEntry;
325 bFound = true;
326 }
327 }
328 }
329 }
330 }
331 break;
332
334 {
335 if(IsDateEntry(pCenterObj.get()) && IsPageEntry(m_xWndRight->GetEditEngine(), pRightObj.get()))
336 {
337 OUString aConfidentialEntry(aUserOpt.GetCompany() + " " + m_xFtConfidential->get_label());
338 if(aConfidentialEntry == m_xWndLeft->GetEditEngine()->GetText(0))
339 {
340 eSelectEntry = eConfidentialEntry;
341 bFound = true;
342 }
343 }
344 }
345 break;
346
347 //TODO
349 {
350 }
351 break;
352
354 {
355 aLeftEntry = pLeftObj->GetText(0);
356 aRightEntry = pRightObj->GetText(0);
357 if(IsExtFileNameEntry(pCenterObj.get()) && aLeftEntry.isEmpty()
358 && aRightEntry.isEmpty())
359 {
360 eSelectEntry = eExtFileNameEntry;
361 bFound = true;
362 }
363 }
364 break;
365
366 //TODO
367 case ePageSheetEntry:
368 {
369 }
370 break;
371
372 //TODO
374 {
375 }
376 break;
377
379 {
380 aLeftEntry = pLeftObj->GetText(0);
381 if(IsPageEntry(m_xWndCenter->GetEditEngine(), pCenterObj.get()) &&
382 IsExtFileNameEntry(pRightObj.get()) && aLeftEntry.isEmpty())
383 {
384 eSelectEntry = ePageExtFileNameEntry;
385 bFound = true;
386 }
387 }
388 break;
389
390 case eUserNameEntry:
391 {
392 if(IsDateEntry(pRightObj.get()) && IsPageEntry(m_xWndCenter->GetEditEngine(), pCenterObj.get()))
393 {
394 OUString aUserNameEntry(aUserOpt.GetFirstName() + " " + aUserOpt.GetLastName());
395
396 if(aUserNameEntry == m_xWndLeft->GetEditEngine()->GetText(0))
397 {
398 eSelectEntry = eUserNameEntry;
399 bFound = true;
400 }
401 }
402 }
403 break;
404
405 case eCreatedByEntry:
406 {
407 if(IsDateEntry(pCenterObj.get()) && IsPageEntry(m_xWndRight->GetEditEngine(), pRightObj.get()))
408 {
409 OUString aCreatedByEntry(m_xFtCreatedBy->get_label() + " " + aUserOpt.GetFirstName() + " " + aUserOpt.GetLastName());
410
411 if(aCreatedByEntry == m_xWndLeft->GetEditEngine()->GetText(0))
412 {
413 eSelectEntry = eCreatedByEntry;
414 bFound = true;
415 }
416 }
417 }
418 break;
419
420 default:
421 {
422 // added to avoid warnings
423 }
424 }
425 }
426
427 if(eSelectEntry == eEntryCount)
429
430 m_xLbDefined->set_active( sal::static_int_cast<sal_uInt16>( eSelectEntry ) );
431}
432
434{
435 if(!pEngine || !pTextObj)
436 return false;
437
438 bool bReturn = false;
439
440 if(!pTextObj->IsFieldObject())
441 {
442 std::vector<sal_Int32> aPosList;
443 pEngine->GetPortions(0,aPosList);
444 if(aPosList.size() == 2)
445 {
446 OUString aPageEntry(m_xFtPage->get_label() + " ");
447 ESelection aSel(0,0,0,0);
448 aSel.nEndPos = aPageEntry.getLength();
449 if(aPageEntry == pEngine->GetText(aSel))
450 {
451 aSel.nStartPos = aSel.nEndPos;
452 aSel.nEndPos++;
453 std::unique_ptr< EditTextObject > pPageObj = pEngine->CreateTextObject(aSel);
454 if(pPageObj && pPageObj->IsFieldObject() )
455 {
456 const SvxFieldItem* pFieldItem = pPageObj->GetField();
457 if(pFieldItem)
458 {
459 const SvxFieldData* pField = pFieldItem->GetField();
460 if(dynamic_cast<const SvxPageField*>( pField))
461 bReturn = true;
462 }
463 }
464 }
465 }
466 }
467 return bReturn;
468}
469
471{
472 if(!pTextObj)
473 return false;
474
475 bool bReturn = false;
476 if(pTextObj->IsFieldObject())
477 {
478 const SvxFieldItem* pFieldItem = pTextObj->GetField();
479 if(pFieldItem)
480 {
481 const SvxFieldData* pField = pFieldItem->GetField();
482 if(dynamic_cast<const SvxDateField*>( pField))
483 bReturn = true;
484 }
485 }
486 return bReturn;
487}
488
490{
491 if(!pTextObj)
492 return false;
493 bool bReturn = false;
494 if(pTextObj->IsFieldObject())
495 {
496 const SvxFieldItem* pFieldItem = pTextObj->GetField();
497 if(pFieldItem)
498 {
499 const SvxFieldData* pField = pFieldItem->GetField();
500 if(dynamic_cast<const SvxExtFileField*>( pField))
501 bReturn = true;
502 }
503 }
504 return bReturn;
505}
506
508{
509 SvtUserOptions aUserOpt;
510 std::unique_ptr< EditTextObject > pTextObj;
511
512 switch(eSel)
513 {
514 case eNoneEntry:
516 if(!bTravelling)
517 m_xWndLeft->GrabFocus();
518 break;
519
520 case ePageEntry:
521 {
523 OUString aPageEntry( m_xFtPage->get_label() + " " );
524 m_xWndCenter->GetEditEngine()->SetTextCurrentDefaults(aPageEntry);
526 if(!bTravelling)
527 m_xWndCenter->GrabFocus();
528 }
529 break;
530
531 case ePagesEntry:
532 {
534 ESelection aSel(0,0,0,0);
535 OUString aPageEntry( m_xFtPage->get_label() + " ");
536 m_xWndCenter->GetEditEngine()->SetTextCurrentDefaults(aPageEntry);
537 aSel.nEndPos = aPageEntry.getLength();
538 m_xWndCenter->GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
539 ++aSel.nEndPos;
540
541 OUString aPageOfEntry(" " + m_xFtOf->get_label() + " ");
542 m_xWndCenter->GetEditEngine()->QuickInsertText(aPageOfEntry,ESelection(aSel.nEndPara,aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
543 aSel.nEndPos = aSel.nEndPos + aPageOfEntry.getLength();
544 m_xWndCenter->GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPagesField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara,aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
545 pTextObj = m_xWndCenter->GetEditEngine()->CreateTextObject();
546 m_xWndCenter->SetText(*pTextObj);
547 if(!bTravelling)
548 m_xWndCenter->GrabFocus();
549 }
550 break;
551
552 case eSheetEntry:
555 if(!bTravelling)
556 m_xWndCenter->GrabFocus();
557 break;
558
560 {
562 OUString aConfidentialEntry(aUserOpt.GetCompany() + " " + m_xFtConfidential->get_label());
563 m_xWndLeft->GetEditEngine()->SetTextCurrentDefaults(aConfidentialEntry);
564 m_xWndCenter->InsertField( SvxFieldItem(SvxDateField(Date( Date::SYSTEM ),SvxDateType::Var), EE_FEATURE_FIELD) );
565
566 OUString aPageEntry( m_xFtPage->get_label() + " ");
567 m_xWndRight->GetEditEngine()->SetTextCurrentDefaults(aPageEntry);
569 if(!bTravelling)
570 m_xWndRight->GrabFocus();
571 }
572 break;
573
575 {
577 ESelection aSel(0,0,0,0);
578 m_xWndCenter->GetEditEngine()->QuickInsertField(SvxFieldItem( SvxFileField(), EE_FEATURE_FIELD ), aSel );
579 ++aSel.nEndPos;
580 OUString aPageEntry(", " + m_xFtPage->get_label() + " ");
581 m_xWndCenter->GetEditEngine()->QuickInsertText(aPageEntry, ESelection(aSel.nEndPara,aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
582 aSel.nStartPos = aSel.nEndPos;
583 aSel.nEndPos = aSel.nEndPos + aPageEntry.getLength();
584 m_xWndCenter->GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara,aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
585 pTextObj = m_xWndCenter->GetEditEngine()->CreateTextObject();
586 m_xWndCenter->SetText(*pTextObj);
587 if(!bTravelling)
588 m_xWndCenter->GrabFocus();
589 }
590 break;
591
595 OUString(), SvxFileType::Var, SvxFileFormat::PathFull ), EE_FEATURE_FIELD ) );
596 if(!bTravelling)
597 m_xWndCenter->GrabFocus();
598 break;
599
600 case ePageSheetEntry:
601 {
603 ESelection aSel(0,0,0,0);
604 OUString aPageEntry( m_xFtPage->get_label() + " " );
605 m_xWndCenter->GetEditEngine()->SetTextCurrentDefaults(aPageEntry);
606 aSel.nEndPos = aPageEntry.getLength();
607 m_xWndCenter->GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
608 ++aSel.nEndPos;
609
610 OUString aCommaSpace(", ");
611 m_xWndCenter->GetEditEngine()->QuickInsertText(aCommaSpace,ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
612 aSel.nEndPos = aSel.nEndPos + aCommaSpace.getLength();
613 m_xWndCenter->GetEditEngine()->QuickInsertField( SvxFieldItem(SvxTableField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
614 pTextObj = m_xWndCenter->GetEditEngine()->CreateTextObject();
615 m_xWndCenter->SetText(*pTextObj);
616 if(!bTravelling)
617 m_xWndCenter->GrabFocus();
618 }
619 break;
620
622 {
624 ESelection aSel(0,0,0,0);
625 OUString aPageEntry( m_xFtPage->get_label() + " " );
626 m_xWndCenter->GetEditEngine()->SetTextCurrentDefaults(aPageEntry);
627 aSel.nEndPos = aPageEntry.getLength();
628 m_xWndCenter->GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
629 ++aSel.nEndPos;
630 OUString aCommaSpace(", ");
631 m_xWndCenter->GetEditEngine()->QuickInsertText(aCommaSpace,ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
632 aSel.nEndPos = aSel.nEndPos + aCommaSpace.getLength();
633 m_xWndCenter->GetEditEngine()->QuickInsertField( SvxFieldItem(SvxFileField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
634 pTextObj = m_xWndCenter->GetEditEngine()->CreateTextObject();
635 m_xWndCenter->SetText(*pTextObj);
636 if(!bTravelling)
637 m_xWndCenter->GrabFocus();
638 }
639 break;
640
642 {
644 OUString aPageEntry( m_xFtPage->get_label() + " " );
645 m_xWndCenter->GetEditEngine()->SetTextCurrentDefaults(aPageEntry);
648 OUString(), SvxFileType::Var, SvxFileFormat::PathFull ), EE_FEATURE_FIELD ) );
649 if(!bTravelling)
650 m_xWndRight->GrabFocus();
651 }
652 break;
653
654 case eUserNameEntry:
655 {
657 OUString aUserNameEntry(aUserOpt.GetFirstName() + " " + aUserOpt.GetLastName());
658 m_xWndLeft->GetEditEngine()->SetTextCurrentDefaults(aUserNameEntry);
659 OUString aPageEntry( m_xFtPage->get_label() + " ");
660 //aPageEntry += " ";
661 m_xWndCenter->GetEditEngine()->SetTextCurrentDefaults(aPageEntry);
663 m_xWndRight->InsertField( SvxFieldItem(SvxDateField(Date( Date::SYSTEM ),SvxDateType::Var), EE_FEATURE_FIELD) );
664 if(!bTravelling)
665 m_xWndRight->GrabFocus();
666 }
667 break;
668
669 case eCreatedByEntry:
670 {
672 OUString aCreatedByEntry( m_xFtCreatedBy->get_label() + " " + aUserOpt.GetFirstName() + " " + aUserOpt.GetLastName());
673 m_xWndLeft->GetEditEngine()->SetTextCurrentDefaults(aCreatedByEntry);
674 m_xWndCenter->InsertField( SvxFieldItem(SvxDateField(Date( Date::SYSTEM ),SvxDateType::Var), EE_FEATURE_FIELD) );
675 OUString aPageEntry( m_xFtPage->get_label() + " " );
676 m_xWndRight->GetEditEngine()->SetTextCurrentDefaults(aPageEntry);
678 if(!bTravelling)
679 m_xWndRight->GrabFocus();
680 }
681 break;
682
683 default :
684 break;
685 }
686}
687
689{
690 m_xWndLeft->GetEditEngine()->SetTextCurrentDefaults(OUString());
691 m_xWndLeft->Invalidate();
692 m_xWndCenter->GetEditEngine()->SetTextCurrentDefaults(OUString());
693 m_xWndCenter->Invalidate();
694 m_xWndRight->GetEditEngine()->SetTextCurrentDefaults(OUString());
695 m_xWndRight->Invalidate();
696}
697
698// Handler:
699IMPL_LINK_NOARG(ScHFEditPage, ListToggleHdl_Impl, weld::ComboBox&, void)
700{
701 m_bDropDownActive = !m_bDropDownActive;
702 TimeValue aNow;
703 osl_getSystemTime(&aNow);
704 m_nTimeToggled = sal_Int64(aNow.Seconds) * 1000000000 + aNow.Nanosec;
705}
706
708{
709 ScHFEntryId eSel = static_cast<ScHFEntryId>(m_xLbDefined->get_active());
710
711 TimeValue aNow;
712 osl_getSystemTime(&aNow);
713 sal_Int64 nNow = sal_Int64(aNow.Seconds) * 1000000000 + aNow.Nanosec;
714
715 // order of dropdown vs select not guaranteed
716 bool bDiscrepancy = m_xLbDefined->get_popup_shown() != m_bDropDownActive;
717 if (bDiscrepancy)
718 ListToggleHdl_Impl(*m_xLbDefined);
719
720 bool bFocusToTarget = !m_xLbDefined->get_popup_shown() && m_nTimeToggled != -1 && (nNow - m_nTimeToggled < 800000000);
721 ProcessDefinedListSel(eSel, !bFocusToTarget);
722 // check if we need to remove the customized entry.
723 if (!m_bDropDownActive && eSel < eEntryCount)
724 RemoveFromDefinedList();
725
726 // keep balanced
727 if (bDiscrepancy)
728 ListToggleHdl_Impl(*m_xLbDefined);
729}
730
731IMPL_LINK( ScHFEditPage, ClickHdl, weld::Button&, rBtn, void )
732{
733 if (!m_pEditFocus)
734 return;
735
736 if (&rBtn == m_xBtnText.get())
737 {
738 m_pEditFocus->SetCharAttributes();
739 }
740 else
741 {
742 if ( &rBtn == m_xBtnPage.get() )
743 m_pEditFocus->InsertField(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD));
744 else if ( &rBtn == m_xBtnLastPage.get() )
745 m_pEditFocus->InsertField(SvxFieldItem(SvxPagesField(), EE_FEATURE_FIELD));
746 else if ( &rBtn == m_xBtnDate.get() )
747 m_pEditFocus->InsertField(SvxFieldItem(SvxDateField(Date(Date::SYSTEM),SvxDateType::Var), EE_FEATURE_FIELD));
748 else if ( &rBtn == m_xBtnTime.get() )
749 m_pEditFocus->InsertField(SvxFieldItem(SvxTimeField(), EE_FEATURE_FIELD));
750 else if ( &rBtn == m_xBtnTable.get() )
751 m_pEditFocus->InsertField(SvxFieldItem(SvxTableField(), EE_FEATURE_FIELD));
752 }
753 InsertToDefinedList();
754 m_pEditFocus->GrabFocus();
755}
756
757IMPL_LINK(ScHFEditPage, MenuHdl, const OUString&, rSelectedId, void)
758{
759 if (!m_pEditFocus)
760 return;
761
762 if (rSelectedId == "title")
763 {
764 m_pEditFocus->InsertField(SvxFieldItem(SvxFileField(), EE_FEATURE_FIELD));
765 }
766 else if (rSelectedId == "filename")
767 {
768 m_pEditFocus->InsertField( SvxFieldItem( SvxExtFileField(
769 OUString(), SvxFileType::Var, SvxFileFormat::NameAndExt ), EE_FEATURE_FIELD ) );
770 }
771 else if (rSelectedId == "pathname")
772 {
773 m_pEditFocus->InsertField( SvxFieldItem( SvxExtFileField(
774 OUString(), SvxFileType::Var, SvxFileFormat::PathFull ), EE_FEATURE_FIELD ) );
775 }
776}
777
778
780 : ScHFEditPage( pPage, pController,
781 rCoreSet,
783 true )
784 {}
785
786std::unique_ptr<SfxTabPage> ScFirstHeaderEditPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rCoreSet )
787{
788 return std::make_unique<ScFirstHeaderEditPage>( pPage, pController, *rCoreSet );
789}
790
791
793 : ScHFEditPage( pPage, pController,
794 rCoreSet,
796 true )
797 {}
798
799std::unique_ptr<SfxTabPage> ScRightHeaderEditPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rCoreSet )
800{
801 return std::make_unique<ScRightHeaderEditPage>( pPage, pController, *rCoreSet );
802}
803
804
806 : ScHFEditPage( pPage, pController,
807 rCoreSet,
809 true )
810 {}
811
812std::unique_ptr<SfxTabPage> ScLeftHeaderEditPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rCoreSet )
813{
814 return std::make_unique<ScLeftHeaderEditPage>( pPage, pController, *rCoreSet );
815}
816
817
819 : ScHFEditPage( pPage, pController,
820 rCoreSet,
822 false )
823 {}
824
825std::unique_ptr<SfxTabPage> ScFirstFooterEditPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rCoreSet )
826{
827 return std::make_unique<ScFirstFooterEditPage>( pPage, pController, *rCoreSet );
828}
829
830
832 : ScHFEditPage( pPage, pController,
833 rCoreSet,
835 false )
836 {}
837
838std::unique_ptr<SfxTabPage> ScRightFooterEditPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rCoreSet )
839{
840 return std::make_unique<ScRightFooterEditPage>( pPage, pController, *rCoreSet );
841}
842
843
845 : ScHFEditPage( pPage, pController,
846 rCoreSet,
848 false )
849 {}
850
851std::unique_ptr<SfxTabPage> ScLeftFooterEditPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rCoreSet )
852{
853 return std::make_unique<ScLeftFooterEditPage>( pPage, pController, *rCoreSet );
854};
855
856/* 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:191
void SetLeftArea(const EditTextObject &rNew)
Definition: attrib.cxx:494
void SetCenterArea(const EditTextObject &rNew)
Definition: attrib.cxx:499
void SetRightArea(const EditTextObject &rNew)
Definition: attrib.cxx:504
const EditTextObject * GetLeftArea() const
Definition: attrib.hxx:190
const EditTextObject * GetRightArea() const
Definition: attrib.hxx:192
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