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