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