Line data Source code
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 :
21 : #undef SC_DLLIMPLEMENTATION
22 :
23 :
24 :
25 : //------------------------------------------------------------------
26 :
27 : #define _TPHFEDIT_CXX
28 : #include "scitems.hxx"
29 : #include <editeng/eeitem.hxx>
30 :
31 : #include <editeng/editobj.hxx>
32 : #include <editeng/editstat.hxx>
33 : #include <editeng/editview.hxx>
34 : #include <editeng/flditem.hxx>
35 : #include <sfx2/basedlgs.hxx>
36 : #include <sfx2/objsh.hxx>
37 : #include <vcl/msgbox.hxx>
38 : #include <vcl/svapp.hxx>
39 : #include <unotools/useroptions.hxx>
40 :
41 : #include "editutil.hxx"
42 : #include "global.hxx"
43 : #include "attrib.hxx"
44 : #include "patattr.hxx"
45 : #include "scresid.hxx"
46 : #include "sc.hrc"
47 : #include "globstr.hrc"
48 : #include "tabvwsh.hxx"
49 : #include "prevwsh.hxx"
50 : #include "hfedtdlg.hrc"
51 : #include "textdlgs.hxx"
52 : #include "AccessibleEditObject.hxx"
53 :
54 : #include "scuitphfedit.hxx"
55 : #include <memory> // header file for auto_ptr
56 :
57 : // STATIC DATA -----------------------------------------------------------
58 :
59 : static ScEditWindow* pActiveEdWnd = NULL;
60 :
61 : //========================================================================
62 : // class ScHFEditPage
63 : //
64 :
65 0 : ScHFEditPage::ScHFEditPage( Window* pParent,
66 : sal_uInt16 nResId,
67 : const SfxItemSet& rCoreAttrs,
68 : sal_uInt16 nWhichId,
69 : bool bHeader )
70 :
71 : : SfxTabPage ( pParent, ScResId( nResId ), rCoreAttrs ),
72 :
73 : aFtLeft ( this, ScResId( FT_LEFT ) ),
74 : aWndLeft ( this, ScResId( WND_LEFT ), Left ),
75 : aFtCenter ( this, ScResId( FT_CENTER ) ),
76 : aWndCenter ( this, ScResId( WND_CENTER ), Center ),
77 : aFtRight ( this, ScResId( FT_RIGHT ) ),
78 : aWndRight ( this, ScResId( WND_RIGHT ), Right ),
79 : maFtDefinedHF ( this, ScResId( FT_HF_DEFINED ) ),
80 : maLbDefined ( this, ScResId( LB_DEFINED ) ),
81 : maFtCustomHF ( this, ScResId( FT_HF_CUSTOM ) ),
82 : aBtnText ( this, ScResId( BTN_TEXT ) ),
83 : aBtnFile ( this, ScResId( BTN_FILE ) ),
84 : aBtnTable ( this, ScResId( BTN_TABLE ) ),
85 : aBtnPage ( this, ScResId( BTN_PAGE ) ),
86 : aBtnLastPage ( this, ScResId( BTN_PAGES ) ),
87 : aBtnDate ( this, ScResId( BTN_DATE ) ),
88 : aBtnTime ( this, ScResId( BTN_TIME ) ),
89 : aFlInfo ( this, ScResId( FL_INFO ) ),
90 : aFtInfo ( this, ScResId( FT_INFO ) ),
91 : aPopUpFile ( ScResId( RID_POPUP_FCOMMAND) ),
92 0 : nWhich ( nWhichId )
93 : {
94 : //! use default style from current document?
95 : //! if font color is used, header/footer background color must be set
96 :
97 0 : ScPatternAttr aPatAttr( rCoreAttrs.GetPool() );
98 :
99 :
100 0 : aBtnFile.SetPopupMenu(&aPopUpFile);
101 :
102 0 : maLbDefined.SetSelectHdl( LINK( this, ScHFEditPage, ListHdl_Impl ) );
103 0 : aBtnFile.SetMenuHdl( LINK( this, ScHFEditPage, MenuHdl ) );
104 0 : aBtnText .SetClickHdl( LINK( this, ScHFEditPage, ClickHdl ) );
105 0 : aBtnPage .SetClickHdl( LINK( this, ScHFEditPage, ClickHdl ) );
106 0 : aBtnLastPage.SetClickHdl( LINK( this, ScHFEditPage, ClickHdl ) );
107 0 : aBtnDate .SetClickHdl( LINK( this, ScHFEditPage, ClickHdl ) );
108 0 : aBtnTime .SetClickHdl( LINK( this, ScHFEditPage, ClickHdl ) );
109 0 : aBtnFile .SetClickHdl( LINK( this, ScHFEditPage, ClickHdl ) );
110 0 : aBtnTable .SetClickHdl( LINK( this, ScHFEditPage, ClickHdl ) );
111 :
112 0 : if(!bHeader)
113 : {
114 0 : maFtDefinedHF.SetText(ScGlobal::GetRscString( STR_FOOTER ));
115 0 : maFtCustomHF.SetText(ScGlobal::GetRscString( STR_HF_CUSTOM_FOOTER ));
116 : }
117 0 : if( Application::GetSettings().GetLayoutRTL() )
118 : {
119 0 : Point pt1 = aWndLeft.GetPosPixel();
120 0 : Point pt2 = aWndRight.GetPosPixel();
121 0 : aWndLeft.SetPosPixel(pt2);
122 0 : aWndRight.SetPosPixel(pt1);
123 :
124 0 : pt1 = aFtLeft.GetPosPixel();
125 0 : pt2 = aFtRight.GetPosPixel();
126 0 : aFtLeft.SetPosPixel(pt2);
127 0 : aFtRight.SetPosPixel(pt1);
128 : }
129 0 : aWndLeft. SetFont( aPatAttr );
130 0 : aWndCenter. SetFont( aPatAttr );
131 0 : aWndRight. SetFont( aPatAttr );
132 :
133 0 : FillCmdArr();
134 :
135 0 : aWndLeft.GrabFocus();
136 :
137 0 : InitPreDefinedList();
138 :
139 0 : FreeResource();
140 0 : }
141 :
142 : // -----------------------------------------------------------------------
143 :
144 0 : ScHFEditPage::~ScHFEditPage()
145 : {
146 0 : }
147 :
148 0 : void ScHFEditPage::SetNumType(SvxNumType eNumType)
149 : {
150 0 : aWndLeft.SetNumType(eNumType);
151 0 : aWndCenter.SetNumType(eNumType);
152 0 : aWndRight.SetNumType(eNumType);
153 0 : }
154 :
155 0 : void ScHFEditPage::Reset( const SfxItemSet& rCoreSet )
156 : {
157 0 : const SfxPoolItem* pItem = NULL;
158 0 : if ( rCoreSet.HasItem(nWhich, &pItem) )
159 : {
160 0 : const ScPageHFItem& rItem = static_cast<const ScPageHFItem&>(*pItem);
161 :
162 0 : if( const EditTextObject* pLeft = rItem.GetLeftArea() )
163 0 : aWndLeft.SetText( *pLeft );
164 0 : if( const EditTextObject* pCenter = rItem.GetCenterArea() )
165 0 : aWndCenter.SetText( *pCenter );
166 0 : if( const EditTextObject* pRight = rItem.GetRightArea() )
167 0 : aWndRight.SetText( *pRight );
168 :
169 0 : SetSelectDefinedList();
170 : }
171 0 : }
172 :
173 0 : sal_Bool ScHFEditPage::FillItemSet( SfxItemSet& rCoreSet )
174 : {
175 0 : ScPageHFItem aItem( nWhich );
176 0 : EditTextObject* pLeft = aWndLeft .CreateTextObject();
177 0 : EditTextObject* pCenter = aWndCenter.CreateTextObject();
178 0 : EditTextObject* pRight = aWndRight .CreateTextObject();
179 :
180 0 : aItem.SetLeftArea ( *pLeft );
181 0 : aItem.SetCenterArea( *pCenter );
182 0 : aItem.SetRightArea ( *pRight );
183 0 : delete pLeft;
184 0 : delete pCenter;
185 0 : delete pRight;
186 :
187 0 : rCoreSet.Put( aItem );
188 :
189 0 : return sal_True;
190 : }
191 :
192 : // -----------------------------------------------------------------------
193 :
194 : #define SET_CMD(i,id) \
195 : aCmd = aDel; \
196 : aCmd += ScGlobal::GetRscString( id ); \
197 : aCmd += aDel; \
198 : aCmdArr[i] = aCmd;
199 :
200 : // -----------------------------------------------------------------------
201 :
202 0 : void ScHFEditPage::FillCmdArr()
203 : {
204 0 : String aDel( ScGlobal::GetRscString( STR_HFCMD_DELIMITER ) );
205 0 : String aCmd;
206 :
207 0 : SET_CMD( 0, STR_HFCMD_PAGE )
208 0 : SET_CMD( 1, STR_HFCMD_PAGES )
209 0 : SET_CMD( 2, STR_HFCMD_DATE )
210 0 : SET_CMD( 3, STR_HFCMD_TIME )
211 0 : SET_CMD( 4, STR_HFCMD_FILE )
212 0 : SET_CMD( 5, STR_HFCMD_TABLE )
213 0 : }
214 :
215 : #undef SET_CMD
216 :
217 0 : void ScHFEditPage::InitPreDefinedList()
218 : {
219 0 : SvtUserOptions aUserOpt;
220 :
221 0 : Color* pTxtColour = NULL;
222 0 : Color* pFldColour = NULL;
223 :
224 : // Get the all field values at the outset.
225 0 : String aPageFieldValue(aWndLeft.GetEditEngine()->CalcFieldValue(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), 0,0, pTxtColour, pFldColour));
226 0 : String aSheetFieldValue(aWndLeft.GetEditEngine()->CalcFieldValue(SvxFieldItem(SvxTableField(), EE_FEATURE_FIELD), 0,0, pTxtColour, pFldColour));
227 0 : String aFileFieldValue(aWndLeft.GetEditEngine()->CalcFieldValue(SvxFieldItem(SvxFileField(), EE_FEATURE_FIELD), 0,0, pTxtColour, pFldColour));
228 0 : String aExtFileFieldValue(aWndLeft.GetEditEngine()->CalcFieldValue(SvxFieldItem(SvxExtFileField(), EE_FEATURE_FIELD), 0,0, pTxtColour, pFldColour));
229 0 : String aDateFieldValue(aWndLeft.GetEditEngine()->CalcFieldValue(SvxFieldItem(SvxDateField(), EE_FEATURE_FIELD), 0,0, pTxtColour, pFldColour));
230 :
231 0 : maLbDefined.Clear();
232 :
233 0 : maLbDefined.InsertEntry( ScGlobal::GetRscString( STR_HF_NONE_IN_BRACKETS ));
234 :
235 0 : String aPageEntry(ScGlobal::GetRscString( STR_PAGE ) );
236 0 : aPageEntry += ' ';
237 0 : aPageEntry += aPageFieldValue;
238 0 : maLbDefined.InsertEntry(aPageEntry);
239 :
240 0 : String aPageOfEntry(aPageEntry);
241 0 : aPageOfEntry += ' ';
242 0 : aPageOfEntry += ScGlobal::GetRscString( STR_HF_OF_QUESTION );
243 0 : maLbDefined.InsertEntry( aPageOfEntry);
244 :
245 0 : maLbDefined.InsertEntry(aSheetFieldValue);
246 :
247 0 : String aConfidentialEntry(aUserOpt.GetCompany());
248 0 : aConfidentialEntry += ' ';
249 0 : aConfidentialEntry += ScGlobal::GetRscString( STR_HF_CONFIDENTIAL );
250 0 : aConfidentialEntry.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
251 0 : aConfidentialEntry += aDateFieldValue;
252 0 : aConfidentialEntry.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
253 0 : aConfidentialEntry += aPageEntry;
254 0 : maLbDefined.InsertEntry( aConfidentialEntry);
255 :
256 0 : String aFileNamePageEntry(aFileFieldValue);
257 0 : aFileNamePageEntry.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
258 0 : aFileNamePageEntry += aPageEntry;
259 0 : maLbDefined.InsertEntry( aFileNamePageEntry);
260 :
261 0 : maLbDefined.InsertEntry( aExtFileFieldValue);
262 :
263 0 : String aPageSheetNameEntry(aPageEntry);
264 0 : aPageSheetNameEntry.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
265 0 : aPageSheetNameEntry += aSheetFieldValue;
266 0 : maLbDefined.InsertEntry( aPageSheetNameEntry);
267 :
268 0 : String aPageFileNameEntry(aPageEntry);
269 0 : aPageFileNameEntry.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
270 0 : aPageFileNameEntry += aFileFieldValue;
271 0 : maLbDefined.InsertEntry( aPageFileNameEntry);
272 :
273 0 : String aPagePathNameEntry(aPageEntry);
274 0 : aPagePathNameEntry.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
275 0 : aPagePathNameEntry += aExtFileFieldValue;
276 0 : maLbDefined.InsertEntry( aPagePathNameEntry);
277 :
278 0 : String aUserNameEntry(aUserOpt.GetFirstName());
279 0 : aUserNameEntry += ' ';
280 0 : aUserNameEntry += (String)aUserOpt.GetLastName();
281 0 : aUserNameEntry.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
282 0 : aUserNameEntry += aPageEntry;
283 0 : aUserNameEntry.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
284 0 : aUserNameEntry += aDateFieldValue;
285 0 : maLbDefined.InsertEntry( aUserNameEntry);
286 :
287 0 : String aCreatedByEntry(ScGlobal::GetRscString( STR_HF_CREATED_BY ) );
288 0 : aCreatedByEntry += ' ';
289 0 : aCreatedByEntry += (String)aUserOpt.GetFirstName();
290 0 : aCreatedByEntry += ' ';
291 0 : aCreatedByEntry += (String)aUserOpt.GetLastName();
292 0 : aCreatedByEntry.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
293 0 : aCreatedByEntry += aDateFieldValue;
294 0 : aCreatedByEntry.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", "));
295 0 : aCreatedByEntry += aPageEntry;
296 0 : maLbDefined.InsertEntry( aCreatedByEntry);
297 0 : }
298 :
299 0 : void ScHFEditPage::InsertToDefinedList()
300 : {
301 0 : sal_uInt16 nCount = maLbDefined.GetEntryCount();
302 0 : if(nCount == eEntryCount)
303 : {
304 0 : String aCustomizedEntry(ScGlobal::GetRscString( STR_HF_CUSTOMIZED ) );
305 0 : maLbDefined.InsertEntry( aCustomizedEntry);
306 0 : maLbDefined.SelectEntryPos(eEntryCount);
307 : }
308 0 : }
309 :
310 0 : void ScHFEditPage::RemoveFromDefinedList()
311 : {
312 0 : sal_uInt16 nCount = maLbDefined.GetEntryCount();
313 0 : if(nCount > eEntryCount )
314 0 : maLbDefined.RemoveEntry( nCount-1);
315 0 : }
316 :
317 : // determine if the header/footer exists in our predefined list and set select to it.
318 0 : void ScHFEditPage::SetSelectDefinedList()
319 : {
320 0 : SvtUserOptions aUserOpt;
321 :
322 : // default to customized
323 0 : ScHFEntryId eSelectEntry = eEntryCount;
324 :
325 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
326 0 : ::std::auto_ptr< EditTextObject > pLeftObj;
327 0 : ::std::auto_ptr< EditTextObject > pCenterObj;
328 0 : ::std::auto_ptr< EditTextObject > pRightObj;
329 : SAL_WNODEPRECATED_DECLARATIONS_POP
330 :
331 0 : XubString aLeftEntry;
332 0 : XubString aCenterEntry;
333 0 : XubString aRightEntry;
334 :
335 0 : pLeftObj.reset(aWndLeft.GetEditEngine()->CreateTextObject());
336 0 : pCenterObj.reset(aWndCenter.GetEditEngine()->CreateTextObject());
337 0 : pRightObj.reset(aWndRight.GetEditEngine()->CreateTextObject());
338 :
339 0 : bool bFound = false;
340 :
341 : sal_uInt16 i;
342 0 : sal_uInt16 nCount = maLbDefined.GetEntryCount();
343 0 : for(i = 0; i < nCount && !bFound; i++)
344 : {
345 0 : switch(static_cast<ScHFEntryId>(i))
346 : {
347 : case eNoneEntry:
348 : {
349 0 : aLeftEntry = pLeftObj->GetText(0);
350 0 : aCenterEntry = pCenterObj->GetText(0);
351 0 : aRightEntry = pRightObj->GetText(0);
352 0 : if(aLeftEntry == EMPTY_STRING && aCenterEntry == EMPTY_STRING
353 0 : && aRightEntry == EMPTY_STRING)
354 : {
355 0 : eSelectEntry = eNoneEntry;
356 0 : bFound = true;
357 : }
358 : }
359 0 : break;
360 :
361 : case ePageEntry:
362 : {
363 0 : aLeftEntry = pLeftObj->GetText(0);
364 0 : aRightEntry = pRightObj->GetText(0);
365 0 : if(aLeftEntry == EMPTY_STRING && aRightEntry == EMPTY_STRING)
366 : {
367 0 : if(IsPageEntry(aWndCenter.GetEditEngine(), pCenterObj.get()))
368 : {
369 0 : eSelectEntry = ePageEntry;
370 0 : bFound = true;
371 : }
372 : }
373 : }
374 0 : break;
375 :
376 :
377 : //TODO
378 : case ePagesEntry:
379 : {
380 : }
381 0 : break;
382 :
383 : case eSheetEntry:
384 : {
385 0 : aLeftEntry = pLeftObj->GetText(0);
386 0 : aRightEntry = pRightObj->GetText(0);
387 0 : if(aLeftEntry == EMPTY_STRING && aRightEntry == EMPTY_STRING)
388 : {
389 0 : if(pCenterObj->IsFieldObject())
390 : {
391 0 : const SvxFieldItem* pFieldItem = pCenterObj->GetField();
392 0 : if(pFieldItem)
393 : {
394 0 : const SvxFieldData* pField = pFieldItem->GetField();
395 0 : if(pField && pField->ISA(SvxTableField))
396 : {
397 0 : eSelectEntry = eSheetEntry;
398 0 : bFound = true;
399 : }
400 : }
401 : }
402 : }
403 : }
404 0 : break;
405 :
406 : case eConfidentialEntry:
407 : {
408 0 : if(IsDateEntry(pCenterObj.get()) && IsPageEntry(aWndRight.GetEditEngine(), pRightObj.get()))
409 : {
410 0 : String aConfidentialEntry(aUserOpt.GetCompany());
411 0 : aConfidentialEntry += ' ';
412 0 : aConfidentialEntry += ScGlobal::GetRscString( STR_HF_CONFIDENTIAL );
413 0 : if(aConfidentialEntry == aWndLeft.GetEditEngine()->GetText(0))
414 : {
415 0 : eSelectEntry = eConfidentialEntry;
416 0 : bFound = true;
417 0 : }
418 : }
419 : }
420 0 : break;
421 :
422 : //TODO
423 : case eFileNamePageEntry:
424 : {
425 : }
426 0 : break;
427 :
428 : case eExtFileNameEntry:
429 : {
430 0 : aLeftEntry = pLeftObj->GetText(0);
431 0 : aRightEntry = pRightObj->GetText(0);
432 0 : if(IsExtFileNameEntry(pCenterObj.get()) && aLeftEntry == EMPTY_STRING
433 0 : && aRightEntry == EMPTY_STRING)
434 : {
435 0 : eSelectEntry = eExtFileNameEntry;
436 0 : bFound = true;
437 : }
438 : }
439 0 : break;
440 :
441 : //TODO
442 : case ePageSheetEntry:
443 : {
444 : }
445 0 : break;
446 :
447 : //TODO
448 : case ePageFileNameEntry:
449 : {
450 : }
451 0 : break;
452 :
453 : case ePageExtFileNameEntry:
454 : {
455 0 : aLeftEntry = pLeftObj->GetText(0);
456 0 : if(IsPageEntry(aWndCenter.GetEditEngine(), pCenterObj.get()) &&
457 0 : IsExtFileNameEntry(pRightObj.get()) && aLeftEntry == EMPTY_STRING)
458 : {
459 0 : eSelectEntry = ePageExtFileNameEntry;
460 0 : bFound = true;
461 : }
462 : }
463 0 : break;
464 :
465 : case eUserNameEntry:
466 : {
467 0 : if(IsDateEntry(pRightObj.get()) && IsPageEntry(aWndCenter.GetEditEngine(), pCenterObj.get()))
468 : {
469 0 : String aUserNameEntry(aUserOpt.GetFirstName());
470 0 : aUserNameEntry += ' ';
471 0 : aUserNameEntry += (String)aUserOpt.GetLastName();
472 0 : if(aUserNameEntry == aWndLeft.GetEditEngine()->GetText(0))
473 : {
474 0 : eSelectEntry = eUserNameEntry;
475 0 : bFound = true;
476 0 : }
477 : }
478 : }
479 0 : break;
480 :
481 : case eCreatedByEntry:
482 : {
483 0 : if(IsDateEntry(pCenterObj.get()) && IsPageEntry(aWndRight.GetEditEngine(), pRightObj.get()))
484 : {
485 0 : String aCreatedByEntry(ScGlobal::GetRscString( STR_HF_CREATED_BY ) );
486 0 : aCreatedByEntry += ' ';
487 0 : aCreatedByEntry += (String)aUserOpt.GetFirstName();
488 0 : aCreatedByEntry += ' ';
489 0 : aCreatedByEntry += (String)aUserOpt.GetLastName();
490 0 : if(aCreatedByEntry == aWndLeft.GetEditEngine()->GetText(0))
491 : {
492 0 : eSelectEntry = eCreatedByEntry;
493 0 : bFound = true;
494 0 : }
495 : }
496 : }
497 0 : break;
498 :
499 : default:
500 : {
501 : // added to avoid warnings
502 : }
503 : }
504 : }
505 :
506 0 : if(eSelectEntry == eEntryCount)
507 0 : InsertToDefinedList();
508 :
509 0 : maLbDefined.SelectEntryPos( sal::static_int_cast<sal_uInt16>( eSelectEntry ) );
510 0 : }
511 :
512 0 : bool ScHFEditPage::IsPageEntry(EditEngine*pEngine, EditTextObject* pTextObj)
513 : {
514 0 : if(!pEngine && !pTextObj)
515 0 : return false;
516 :
517 0 : bool bReturn = false;
518 :
519 0 : if(!pTextObj->IsFieldObject())
520 : {
521 0 : std::vector<sal_uInt16> aPosList;
522 0 : pEngine->GetPortions(0,aPosList);
523 0 : if(aPosList.size() == 2)
524 : {
525 0 : String aPageEntry(ScGlobal::GetRscString( STR_PAGE ) );
526 0 : aPageEntry += ' ';
527 0 : ESelection aSel(0,0,0,0);
528 0 : aSel.nEndPos = aPageEntry.Len();
529 0 : if(aPageEntry == pEngine->GetText(aSel))
530 : {
531 0 : aSel.nStartPos = aSel.nEndPos;
532 0 : aSel.nEndPos++;
533 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
534 0 : ::std::auto_ptr< EditTextObject > pPageObj;
535 : SAL_WNODEPRECATED_DECLARATIONS_POP
536 0 : pPageObj.reset(pEngine->CreateTextObject(aSel));
537 0 : if(pPageObj.get() && pPageObj->IsFieldObject() )
538 : {
539 0 : const SvxFieldItem* pFieldItem = pPageObj->GetField();
540 0 : if(pFieldItem)
541 : {
542 0 : const SvxFieldData* pField = pFieldItem->GetField();
543 0 : if(pField && pField->ISA(SvxPageField))
544 0 : bReturn = true;
545 : }
546 0 : }
547 0 : }
548 0 : }
549 : }
550 0 : return bReturn;
551 : }
552 :
553 0 : bool ScHFEditPage::IsDateEntry(EditTextObject* pTextObj)
554 : {
555 0 : if(!pTextObj)
556 0 : return false;
557 :
558 0 : bool bReturn = false;
559 0 : if(pTextObj->IsFieldObject())
560 : {
561 0 : const SvxFieldItem* pFieldItem = pTextObj->GetField();
562 0 : if(pFieldItem)
563 : {
564 0 : const SvxFieldData* pField = pFieldItem->GetField();
565 0 : if(pField && pField->ISA(SvxDateField))
566 0 : bReturn = true;
567 : }
568 : }
569 0 : return bReturn;
570 : }
571 :
572 0 : bool ScHFEditPage::IsExtFileNameEntry(EditTextObject* pTextObj)
573 : {
574 0 : if(!pTextObj)
575 0 : return false;
576 0 : bool bReturn = false;
577 0 : if(pTextObj->IsFieldObject())
578 : {
579 0 : const SvxFieldItem* pFieldItem = pTextObj->GetField();
580 0 : if(pFieldItem)
581 : {
582 0 : const SvxFieldData* pField = pFieldItem->GetField();
583 0 : if(pField && pField->ISA(SvxExtFileField))
584 0 : bReturn = true;
585 : }
586 : }
587 0 : return bReturn;
588 : }
589 :
590 0 : void ScHFEditPage::ProcessDefinedListSel(ScHFEntryId eSel, bool bTravelling)
591 : {
592 0 : SvtUserOptions aUserOpt;
593 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
594 0 : ::std::auto_ptr< EditTextObject > pTextObj;
595 : SAL_WNODEPRECATED_DECLARATIONS_POP
596 :
597 0 : switch(eSel)
598 : {
599 : case eNoneEntry:
600 0 : ClearTextAreas();
601 0 : if(!bTravelling)
602 0 : aWndLeft.GrabFocus();
603 0 : break;
604 :
605 : case ePageEntry:
606 : {
607 0 : ClearTextAreas();
608 0 : String aPageEntry(ScGlobal::GetRscString( STR_PAGE ) );
609 0 : aPageEntry += ' ';
610 0 : aWndCenter.GetEditEngine()->SetText(aPageEntry);
611 0 : aWndCenter.InsertField( SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD) );
612 0 : if(!bTravelling)
613 0 : aWndCenter.GrabFocus();
614 : }
615 0 : break;
616 :
617 : case ePagesEntry:
618 : {
619 0 : ClearTextAreas();
620 0 : ESelection aSel(0,0,0,0);
621 0 : String aPageEntry(ScGlobal::GetRscString( STR_PAGE ) );
622 0 : aPageEntry += ' ';
623 0 : aWndCenter.GetEditEngine()->SetText(aPageEntry);
624 0 : aSel.nEndPos = aPageEntry.Len();
625 0 : aWndCenter.GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
626 0 : ++aSel.nEndPos;
627 0 : String aPageOfEntry = rtl::OUStringBuffer().append(' ').
628 0 : append(ScGlobal::GetRscString( STR_HF_OF )).append(' ').
629 0 : makeStringAndClear();
630 0 : aWndCenter.GetEditEngine()->QuickInsertText(aPageOfEntry,ESelection(aSel.nEndPara,aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
631 0 : aSel.nEndPos = sal::static_int_cast<xub_StrLen>( aSel.nEndPos + aPageOfEntry.Len() );
632 0 : aWndCenter.GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPagesField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara,aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
633 0 : pTextObj.reset(aWndCenter.GetEditEngine()->CreateTextObject());
634 0 : aWndCenter.SetText(*pTextObj);
635 0 : XubString aEntry(pTextObj.get()->GetText(0));
636 0 : if(!bTravelling)
637 0 : aWndCenter.GrabFocus();
638 : }
639 0 : break;
640 :
641 : case eSheetEntry:
642 0 : ClearTextAreas();
643 0 : aWndCenter.InsertField( SvxFieldItem(SvxTableField(), EE_FEATURE_FIELD) );
644 0 : if(!bTravelling)
645 0 : aWndCenter.GrabFocus();
646 0 : break;
647 :
648 : case eConfidentialEntry:
649 : {
650 0 : ClearTextAreas();
651 0 : String aConfidentialEntry(aUserOpt.GetCompany());
652 0 : aConfidentialEntry += ' ';
653 0 : aConfidentialEntry += ScGlobal::GetRscString( STR_HF_CONFIDENTIAL );
654 0 : aWndLeft.GetEditEngine()->SetText(aConfidentialEntry);
655 0 : aWndCenter.InsertField( SvxFieldItem(SvxDateField(Date( Date::SYSTEM ),SVXDATETYPE_VAR), EE_FEATURE_FIELD) );
656 0 : String aPageEntry(ScGlobal::GetRscString( STR_PAGE ) );
657 0 : aPageEntry += ' ';
658 0 : aWndRight.GetEditEngine()->SetText(aPageEntry);
659 0 : aWndRight.InsertField( SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD) );
660 0 : if(!bTravelling)
661 0 : aWndRight.GrabFocus();
662 : }
663 0 : break;
664 :
665 : case eFileNamePageEntry:
666 : {
667 0 : ClearTextAreas();
668 0 : ESelection aSel(0,0,0,0);
669 0 : aWndCenter.GetEditEngine()->QuickInsertField(SvxFieldItem( SvxFileField(), EE_FEATURE_FIELD ), aSel );
670 0 : ++aSel.nEndPos;
671 0 : String aPageEntry(RTL_CONSTASCII_USTRINGPARAM(", "));
672 0 : aPageEntry += ScGlobal::GetRscString( STR_PAGE ) ;
673 0 : aPageEntry += ' ';
674 0 : aWndCenter.GetEditEngine()->QuickInsertText(aPageEntry, ESelection(aSel.nEndPara,aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
675 0 : aSel.nStartPos = aSel.nEndPos;
676 0 : aSel.nEndPos = sal::static_int_cast<xub_StrLen>( aSel.nEndPos + aPageEntry.Len() );
677 0 : aWndCenter.GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara,aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
678 0 : pTextObj.reset(aWndCenter.GetEditEngine()->CreateTextObject());
679 0 : aWndCenter.SetText(*pTextObj);
680 0 : XubString aEntry2(pTextObj.get()->GetText(0));
681 0 : if(!bTravelling)
682 0 : aWndCenter.GrabFocus();
683 : }
684 0 : break;
685 :
686 : case eExtFileNameEntry:
687 0 : ClearTextAreas();
688 : aWndCenter.InsertField( SvxFieldItem( SvxExtFileField(
689 0 : EMPTY_STRING, SVXFILETYPE_VAR, SVXFILEFORMAT_FULLPATH ), EE_FEATURE_FIELD ) );
690 0 : if(!bTravelling)
691 0 : aWndCenter.GrabFocus();
692 0 : break;
693 :
694 : case ePageSheetEntry:
695 : {
696 0 : ClearTextAreas();
697 0 : ESelection aSel(0,0,0,0);
698 0 : String aPageEntry(ScGlobal::GetRscString( STR_PAGE ) );
699 0 : aPageEntry += ' ';
700 0 : aWndCenter.GetEditEngine()->SetText(aPageEntry);
701 0 : aSel.nEndPos = aPageEntry.Len();
702 0 : aWndCenter.GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
703 0 : ++aSel.nEndPos;
704 0 : String aCommaSpace(RTL_CONSTASCII_USTRINGPARAM(", "));
705 0 : aWndCenter.GetEditEngine()->QuickInsertText(aCommaSpace,ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
706 0 : aSel.nEndPos = sal::static_int_cast<xub_StrLen>( aSel.nEndPos + aCommaSpace.Len() );
707 0 : aWndCenter.GetEditEngine()->QuickInsertField( SvxFieldItem(SvxTableField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
708 0 : pTextObj.reset(aWndCenter.GetEditEngine()->CreateTextObject());
709 0 : aWndCenter.SetText(*pTextObj);
710 0 : if(!bTravelling)
711 0 : aWndCenter.GrabFocus();
712 : }
713 0 : break;
714 :
715 : case ePageFileNameEntry:
716 : {
717 0 : ClearTextAreas();
718 0 : ESelection aSel(0,0,0,0);
719 0 : String aPageEntry(ScGlobal::GetRscString( STR_PAGE ) );
720 0 : aPageEntry += ' ';
721 0 : aWndCenter.GetEditEngine()->SetText(aPageEntry);
722 0 : aSel.nEndPos = aPageEntry.Len();
723 0 : aWndCenter.GetEditEngine()->QuickInsertField(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
724 0 : ++aSel.nEndPos;
725 0 : String aCommaSpace(RTL_CONSTASCII_USTRINGPARAM(", "));
726 0 : aWndCenter.GetEditEngine()->QuickInsertText(aCommaSpace,ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
727 0 : aSel.nEndPos = sal::static_int_cast<xub_StrLen>( aSel.nEndPos + aCommaSpace.Len() );
728 0 : aWndCenter.GetEditEngine()->QuickInsertField( SvxFieldItem(SvxFileField(), EE_FEATURE_FIELD), ESelection(aSel.nEndPara, aSel.nEndPos, aSel.nEndPara, aSel.nEndPos));
729 0 : pTextObj.reset(aWndCenter.GetEditEngine()->CreateTextObject());
730 0 : aWndCenter.SetText(*pTextObj);
731 0 : if(!bTravelling)
732 0 : aWndCenter.GrabFocus();
733 : }
734 0 : break;
735 :
736 : case ePageExtFileNameEntry:
737 : {
738 0 : ClearTextAreas();
739 0 : String aPageEntry(ScGlobal::GetRscString( STR_PAGE ) );
740 0 : aPageEntry += ' ';
741 0 : aWndCenter.GetEditEngine()->SetText(aPageEntry);
742 0 : aWndCenter.InsertField( SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD) );
743 : aWndRight.InsertField( SvxFieldItem( SvxExtFileField(
744 0 : EMPTY_STRING, SVXFILETYPE_VAR, SVXFILEFORMAT_FULLPATH ), EE_FEATURE_FIELD ) );
745 0 : if(!bTravelling)
746 0 : aWndRight.GrabFocus();
747 : }
748 0 : break;
749 :
750 : case eUserNameEntry:
751 : {
752 0 : ClearTextAreas();
753 0 : String aUserNameEntry(aUserOpt.GetFirstName());
754 0 : aUserNameEntry += ' ';
755 0 : aUserNameEntry += (String)aUserOpt.GetLastName();
756 0 : aWndLeft.GetEditEngine()->SetText(aUserNameEntry);
757 0 : String aPageEntry(ScGlobal::GetRscString( STR_PAGE ) );
758 0 : aPageEntry += ' ';
759 0 : aWndCenter.GetEditEngine()->SetText(aPageEntry);
760 0 : aWndCenter.InsertField( SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD) );
761 0 : aWndRight.InsertField( SvxFieldItem(SvxDateField(Date( Date::SYSTEM ),SVXDATETYPE_VAR), EE_FEATURE_FIELD) );
762 0 : if(!bTravelling)
763 0 : aWndRight.GrabFocus();
764 : }
765 0 : break;
766 :
767 : case eCreatedByEntry:
768 : {
769 0 : ClearTextAreas();
770 0 : String aCreatedByEntry(ScGlobal::GetRscString( STR_HF_CREATED_BY ) );
771 0 : aCreatedByEntry += ' ';
772 0 : aCreatedByEntry += (String)aUserOpt.GetFirstName();
773 0 : aCreatedByEntry += ' ';
774 0 : aCreatedByEntry += (String)aUserOpt.GetLastName();
775 0 : aWndLeft.GetEditEngine()->SetText(aCreatedByEntry);
776 0 : aWndCenter.InsertField( SvxFieldItem(SvxDateField(Date( Date::SYSTEM ),SVXDATETYPE_VAR), EE_FEATURE_FIELD) );
777 0 : String aPageEntry(ScGlobal::GetRscString( STR_PAGE ) );
778 0 : aPageEntry += ' ';
779 0 : aWndRight.GetEditEngine()->SetText(aPageEntry);
780 0 : aWndRight.InsertField( SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD) );
781 0 : if(!bTravelling)
782 0 : aWndRight.GrabFocus();
783 : }
784 0 : break;
785 :
786 : default :
787 0 : break;
788 0 : }
789 0 : }
790 :
791 0 : void ScHFEditPage::ClearTextAreas()
792 : {
793 0 : aWndLeft.GetEditEngine()->SetText(EMPTY_STRING);
794 0 : aWndLeft.Invalidate();
795 0 : aWndCenter.GetEditEngine()->SetText(EMPTY_STRING);
796 0 : aWndCenter.Invalidate();
797 0 : aWndRight.GetEditEngine()->SetText(EMPTY_STRING);
798 0 : aWndRight.Invalidate();
799 0 : }
800 :
801 : //-----------------------------------------------------------------------
802 : // Handler:
803 : //-----------------------------------------------------------------------
804 :
805 0 : IMPL_LINK( ScHFEditPage, ListHdl_Impl, ListBox*, pList )
806 : {
807 0 : if ( pList && pList == &maLbDefined )
808 : {
809 0 : ScHFEntryId eSel = static_cast<ScHFEntryId>(maLbDefined.GetSelectEntryPos());
810 0 : if(!maLbDefined.IsTravelSelect())
811 : {
812 0 : ProcessDefinedListSel(eSel);
813 :
814 : // check if we need to remove the customized entry.
815 0 : if(eSel < eEntryCount)
816 0 : RemoveFromDefinedList();
817 : }
818 : else
819 : {
820 0 : ProcessDefinedListSel(eSel, true);
821 : }
822 : }
823 0 : return 0;
824 : }
825 :
826 0 : IMPL_LINK( ScHFEditPage, ClickHdl, ImageButton*, pBtn )
827 : {
828 0 : pActiveEdWnd = ::GetScEditWindow();
829 0 : if ( !pActiveEdWnd )
830 0 : return 0;
831 :
832 0 : if ( pBtn == &aBtnText )
833 : {
834 0 : pActiveEdWnd->SetCharAttriutes();
835 : }
836 : else
837 : {
838 0 : if ( pBtn == &aBtnPage )
839 0 : pActiveEdWnd->InsertField( SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD) );
840 0 : else if ( pBtn == &aBtnLastPage )
841 0 : pActiveEdWnd->InsertField( SvxFieldItem(SvxPagesField(), EE_FEATURE_FIELD) );
842 0 : else if ( pBtn == &aBtnDate )
843 0 : pActiveEdWnd->InsertField( SvxFieldItem(SvxDateField(Date( Date::SYSTEM ),SVXDATETYPE_VAR), EE_FEATURE_FIELD) );
844 0 : else if ( pBtn == &aBtnTime )
845 0 : pActiveEdWnd->InsertField( SvxFieldItem(SvxTimeField(), EE_FEATURE_FIELD) );
846 0 : else if ( pBtn == &aBtnFile )
847 : {
848 0 : pActiveEdWnd->InsertField( SvxFieldItem( SvxFileField(), EE_FEATURE_FIELD ) );
849 : }
850 0 : else if ( pBtn == &aBtnTable )
851 0 : pActiveEdWnd->InsertField( SvxFieldItem(SvxTableField(), EE_FEATURE_FIELD) );
852 : }
853 0 : InsertToDefinedList();
854 0 : pActiveEdWnd->GrabFocus();
855 :
856 0 : return 0;
857 : }
858 :
859 0 : IMPL_LINK( ScHFEditPage, MenuHdl, ScExtIButton*, pBtn )
860 : {
861 0 : pActiveEdWnd = ::GetScEditWindow();
862 0 : if ( !pActiveEdWnd )
863 0 : return 0;
864 :
865 0 : if(pBtn!=NULL)
866 : {
867 0 : switch(pBtn->GetSelected())
868 : {
869 : case FILE_COMMAND_TITEL:
870 0 : pActiveEdWnd->InsertField( SvxFieldItem( SvxFileField(), EE_FEATURE_FIELD ) );
871 0 : break;
872 : case FILE_COMMAND_FILENAME:
873 : pActiveEdWnd->InsertField( SvxFieldItem( SvxExtFileField(
874 0 : EMPTY_STRING, SVXFILETYPE_VAR, SVXFILEFORMAT_NAME_EXT ), EE_FEATURE_FIELD ) );
875 0 : break;
876 : case FILE_COMMAND_PATH:
877 : pActiveEdWnd->InsertField( SvxFieldItem( SvxExtFileField(
878 0 : EMPTY_STRING, SVXFILETYPE_VAR, SVXFILEFORMAT_FULLPATH ), EE_FEATURE_FIELD ) );
879 0 : break;
880 : }
881 : }
882 0 : return 0;
883 : }
884 :
885 : //========================================================================
886 : // class ScRightHeaderEditPage
887 : //========================================================================
888 :
889 0 : ScRightHeaderEditPage::ScRightHeaderEditPage( Window* pParent, const SfxItemSet& rCoreSet )
890 : : ScHFEditPage( pParent, RID_SCPAGE_HFED_HR, rCoreSet,
891 0 : rCoreSet.GetPool()->GetWhich(SID_SCATTR_PAGE_HEADERRIGHT ), true )
892 0 : {}
893 :
894 : // -----------------------------------------------------------------------
895 :
896 0 : SfxTabPage* ScRightHeaderEditPage::Create( Window* pParent, const SfxItemSet& rCoreSet )
897 0 : { return ( new ScRightHeaderEditPage( pParent, rCoreSet ) ); };
898 :
899 : //========================================================================
900 : // class ScLeftHeaderEditPage
901 : //========================================================================
902 :
903 0 : ScLeftHeaderEditPage::ScLeftHeaderEditPage( Window* pParent, const SfxItemSet& rCoreSet )
904 : : ScHFEditPage( pParent, RID_SCPAGE_HFED_HL, rCoreSet,
905 0 : rCoreSet.GetPool()->GetWhich(SID_SCATTR_PAGE_HEADERLEFT ), true )
906 0 : {}
907 :
908 : // -----------------------------------------------------------------------
909 :
910 0 : SfxTabPage* ScLeftHeaderEditPage::Create( Window* pParent, const SfxItemSet& rCoreSet )
911 0 : { return ( new ScLeftHeaderEditPage( pParent, rCoreSet ) ); };
912 :
913 : //========================================================================
914 : // class ScRightFooterEditPage
915 : //========================================================================
916 :
917 0 : ScRightFooterEditPage::ScRightFooterEditPage( Window* pParent, const SfxItemSet& rCoreSet )
918 : : ScHFEditPage( pParent, RID_SCPAGE_HFED_FR, rCoreSet,
919 0 : rCoreSet.GetPool()->GetWhich(SID_SCATTR_PAGE_FOOTERRIGHT ), false )
920 0 : {}
921 :
922 : // -----------------------------------------------------------------------
923 :
924 0 : SfxTabPage* ScRightFooterEditPage::Create( Window* pParent, const SfxItemSet& rCoreSet )
925 0 : { return ( new ScRightFooterEditPage( pParent, rCoreSet ) ); };
926 :
927 : //========================================================================
928 : // class ScLeftFooterEditPage
929 : //========================================================================
930 :
931 0 : ScLeftFooterEditPage::ScLeftFooterEditPage( Window* pParent, const SfxItemSet& rCoreSet )
932 : : ScHFEditPage( pParent, RID_SCPAGE_HFED_FL, rCoreSet,
933 0 : rCoreSet.GetPool()->GetWhich(SID_SCATTR_PAGE_FOOTERLEFT ), false )
934 0 : {}
935 :
936 : // -----------------------------------------------------------------------
937 :
938 0 : SfxTabPage* ScLeftFooterEditPage::Create( Window* pParent, const SfxItemSet& rCoreSet )
939 0 : { return ( new ScLeftFooterEditPage( pParent, rCoreSet ) ); };
940 :
941 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|