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_cui.hxx" 26 27 #include <sfx2/app.hxx> 28 #include <tools/rc.h> 29 #include <tools/shl.hxx> 30 31 #define _SVSTDARR_USHORTS 32 #include <svl/svstdarr.hxx> 33 #include <dialmgr.hxx> 34 35 #include "iconcdlg.hxx" 36 37 #include "helpid.hrc" 38 #include <cuires.hrc> 39 #include <unotools/viewoptions.hxx> 40 #include <svtools/apearcfg.hxx> 41 #include <vcl/mnemonic.hxx> 42 #include <vcl/i18nhelp.hxx> 43 44 #ifdef WNT 45 int __cdecl IconcDlgCmpUS_Impl( const void* p1, const void* p2 ) 46 #else 47 #if defined(OS2) && defined(ICC) 48 int _Optlink IconcDlgCmpUS_Impl( const void* p1, const void* p2 ) 49 #else 50 int IconcDlgCmpUS_Impl( const void* p1, const void* p2 ) 51 #endif 52 #endif 53 { 54 return *(sal_uInt16*)p1 - *(sal_uInt16*)p2; 55 } 56 57 // some stuff for easier changes for SvtViewOptions 58 static const sal_Char* pViewOptDataName = "dialog data"; 59 #define VIEWOPT_DATANAME ::rtl::OUString::createFromAscii( pViewOptDataName ) 60 61 static inline void SetViewOptUserItem( SvtViewOptions& rOpt, const String& rData ) 62 { 63 rOpt.SetUserItem( VIEWOPT_DATANAME, ::com::sun::star::uno::makeAny( ::rtl::OUString( rData ) ) ); 64 } 65 66 static inline String GetViewOptUserItem( const SvtViewOptions& rOpt ) 67 { 68 ::com::sun::star::uno::Any aAny( rOpt.GetUserItem( VIEWOPT_DATANAME ) ); 69 ::rtl::OUString aUserData; 70 aAny >>= aUserData; 71 72 return String( aUserData ); 73 } 74 75 76 //##################################################################### 77 // 78 // Class IconChoicePage 79 // 80 //##################################################################### 81 82 /********************************************************************** 83 | 84 | Ctor / Dtor 85 | 86 \**********************************************************************/ 87 88 IconChoicePage::IconChoicePage( Window *pParent, const ResId &rResId, 89 const SfxItemSet &rAttrSet ) 90 : TabPage ( pParent, rResId ), 91 pSet ( &rAttrSet ), 92 bHasExchangeSupport ( sal_False ), 93 pDialog ( NULL ), 94 bStandard ( sal_False ) 95 { 96 SetStyle ( GetStyle() | WB_DIALOGCONTROL | WB_HIDE ); 97 } 98 99 // ----------------------------------------------------------------------- 100 101 IconChoicePage::~IconChoicePage() 102 { 103 } 104 105 /********************************************************************** 106 | 107 | Activate / Deaktivate 108 | 109 \**********************************************************************/ 110 111 void IconChoicePage::ActivatePage( const SfxItemSet& ) 112 { 113 } 114 115 // ----------------------------------------------------------------------- 116 117 int IconChoicePage::DeactivatePage( SfxItemSet* ) 118 { 119 return LEAVE_PAGE; 120 } 121 122 /********************************************************************** 123 | 124 | ... 125 | 126 \**********************************************************************/ 127 128 void IconChoicePage::FillUserData() 129 { 130 } 131 132 // ----------------------------------------------------------------------- 133 134 sal_Bool IconChoicePage::IsReadOnly() const 135 { 136 return sal_False; 137 } 138 139 // ----------------------------------------------------------------------- 140 141 sal_Bool IconChoicePage::QueryClose() 142 { 143 return sal_True; 144 } 145 146 /********************************************************************** 147 | 148 | window-methods 149 | 150 \**********************************************************************/ 151 152 void IconChoicePage::ImplInitSettings() 153 { 154 Window* pParent = GetParent(); 155 if ( pParent->IsChildTransparentModeEnabled() && !IsControlBackground() ) 156 { 157 EnableChildTransparentMode( sal_True ); 158 SetParentClipMode( PARENTCLIPMODE_NOCLIP ); 159 SetPaintTransparent( sal_True ); 160 SetBackground(); 161 } 162 else 163 { 164 EnableChildTransparentMode( sal_False ); 165 SetParentClipMode( 0 ); 166 SetPaintTransparent( sal_False ); 167 168 if ( IsControlBackground() ) 169 SetBackground( GetControlBackground() ); 170 else 171 SetBackground( pParent->GetBackground() ); 172 } 173 } 174 175 // ----------------------------------------------------------------------- 176 177 void IconChoicePage::StateChanged( StateChangedType nType ) 178 { 179 Window::StateChanged( nType ); 180 181 if ( nType == STATE_CHANGE_CONTROLBACKGROUND ) 182 { 183 ImplInitSettings(); 184 Invalidate(); 185 } 186 } 187 188 // ----------------------------------------------------------------------- 189 190 void IconChoicePage::DataChanged( const DataChangedEvent& rDCEvt ) 191 { 192 Window::DataChanged( rDCEvt ); 193 194 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && 195 (rDCEvt.GetFlags() & SETTINGS_STYLE) ) 196 { 197 ImplInitSettings(); 198 Invalidate(); 199 } 200 } 201 202 //##################################################################### 203 // 204 // Class IconChoiceDialog 205 // 206 //##################################################################### 207 208 /********************************************************************** 209 | 210 | Ctor / Dtor 211 | 212 \**********************************************************************/ 213 214 IconChoiceDialog::IconChoiceDialog ( Window* pParent, const ResId &rResId, 215 const EIconChoicePos ePos, 216 const SfxItemSet *pItemSet )//, sal_Bool bEditFmt, const String *pUserButtonText = 0 ) 217 : ModalDialog ( pParent, rResId ), 218 meChoicePos ( ePos ), 219 maIconCtrl ( this, WB_3DLOOK | WB_ICON | WB_BORDER | 220 WB_NOCOLUMNHEADER | WB_HIGHLIGHTFRAME | 221 /* WB_NOSELECTION | */ WB_NODRAGSELECTION | WB_TABSTOP ), 222 mnCurrentPageId ( USHRT_MAX ), 223 224 aOKBtn ( this, WB_DEFBUTTON ), 225 aCancelBtn ( this, WB_DEFBUTTON ), 226 aHelpBtn ( this ), 227 aResetBtn ( this ), 228 pSet ( pItemSet ), 229 pOutSet ( NULL ), 230 pExampleSet ( NULL ), 231 pRanges ( NULL ), 232 nResId ( rResId.GetId() ), 233 234 bHideResetBtn ( sal_False ), 235 bModal ( sal_False ), 236 bInOK ( sal_False ), 237 bModified ( sal_False ), 238 bItemsReset ( sal_False ) 239 { 240 // IconChoiceCtrl-Settings 241 //maIconCtrl.SetBackground ( Wallpaper( Color (146, 146, 186) ) ); 242 243 maIconCtrl.SetStyle (WB_3DLOOK | WB_ICON | WB_BORDER | WB_NOCOLUMNHEADER | WB_HIGHLIGHTFRAME | /* WB_NOSELECTION | */ WB_NODRAGSELECTION | WB_TABSTOP | WB_CLIPCHILDREN ); 244 SetCtrlPos ( meChoicePos ); 245 maIconCtrl.SetClickHdl ( LINK ( this, IconChoiceDialog , ChosePageHdl_Impl ) ); 246 maIconCtrl.Show(); 247 maIconCtrl.SetChoiceWithCursor ( sal_True ); 248 maIconCtrl.SetSelectionMode( SINGLE_SELECTION ); 249 maIconCtrl.SetHelpId( HID_ICCDIALOG_CHOICECTRL ); 250 251 // ItemSet 252 if ( pSet ) 253 { 254 pExampleSet = new SfxItemSet( *pSet ); 255 pOutSet = new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() ); 256 } 257 258 // Buttons 259 aOKBtn.SetClickHdl ( LINK( this, IconChoiceDialog, OkHdl ) ); 260 aOKBtn.SetHelpId( HID_ICCDIALOG_OK_BTN ); 261 aCancelBtn.SetHelpId( HID_ICCDIALOG_CANCEL_BTN ); 262 aResetBtn.SetClickHdl( LINK( this, IconChoiceDialog, ResetHdl ) ); 263 aResetBtn.SetText( CUI_RESSTR(RID_SVXSTR_ICONCHOICEDLG_RESETBUT) ); 264 aResetBtn.SetHelpId( HID_ICCDIALOG_RESET_BTN ); 265 aOKBtn.Show(); 266 aCancelBtn.Show(); 267 aHelpBtn.Show(); 268 aResetBtn.Show(); 269 270 SetPosSizeCtrls ( sal_True ); 271 } 272 273 // ----------------------------------------------------------------------- 274 275 /* 276 IconChoiceDialog ::IconChoiceDialog ( SfxViewFrame *pViewFrame, Window* pParent, const ResId &rResId, 277 const SfxItemSet * = 0, sal_Bool bEditFmt = sal_False, 278 const String *pUserButtonText = 0 ) 279 : meChoicePos ( PosLeft ), // Default erst ma Links 280 maIconCtrl ( this, Die_Winbits ), 281 aOKBtn ( this ), 282 pUserBtn ( pUserButtonText? new PushButton(this): 0 ), 283 aCancelBtn ( this ), 284 aHelpBtn ( this ), 285 aResetBtn ( this ), 286 aBaseFmtBtn ( this ), 287 mnCurrentPageId ( 0 ) 288 { 289 FreeResource(); 290 } 291 */ 292 293 // ----------------------------------------------------------------------- 294 295 IconChoiceDialog ::~IconChoiceDialog () 296 { 297 sal_uLong i; 298 299 // save configuration at INI-Manager 300 // and remove pages 301 SvtViewOptions aTabDlgOpt( E_TABDIALOG, String::CreateFromInt32( nResId ) ); 302 aTabDlgOpt.SetWindowState( ::rtl::OUString::createFromAscii( GetWindowState((WINDOWSTATE_MASK_X | WINDOWSTATE_MASK_Y | WINDOWSTATE_MASK_STATE | WINDOWSTATE_MASK_MINIMIZED)).GetBuffer() ) ); 303 aTabDlgOpt.SetPageID( mnCurrentPageId ); 304 305 const sal_uLong nCount = maPageList.Count(); 306 307 for ( i = 0; i < nCount; ++i ) 308 { 309 IconChoicePageData* pData = maPageList.GetObject(i); 310 311 if ( pData->pPage ) 312 { 313 pData->pPage->FillUserData(); 314 String aPageData(pData->pPage->GetUserData()); 315 if ( aPageData.Len() ) 316 { 317 SvtViewOptions aTabPageOpt( E_TABPAGE, String::CreateFromInt32( pData->nId ) ); 318 319 SetViewOptUserItem( aTabPageOpt, aPageData ); 320 } 321 322 if ( pData->bOnDemand ) 323 delete (SfxItemSet*)&pData->pPage->GetItemSet(); 324 delete pData->pPage; 325 } 326 delete pData; 327 } 328 329 // remove Userdata from Icons 330 for ( i=0; i<maIconCtrl.GetEntryCount(); i++) 331 { 332 SvxIconChoiceCtrlEntry* pEntry = maIconCtrl.GetEntry ( i ); 333 sal_uInt16* pUserData = (sal_uInt16*) pEntry->GetUserData(); 334 delete pUserData; 335 } 336 337 // 338 if ( pRanges ) 339 delete pRanges; 340 if ( pOutSet ) 341 delete pOutSet; 342 } 343 344 /********************************************************************** 345 | 346 | add new page 347 | 348 \**********************************************************************/ 349 350 SvxIconChoiceCtrlEntry* IconChoiceDialog::AddTabPage( sal_uInt16 nId, const String& rIconText, 351 const Image& rChoiceIcon, 352 const Image& rChoiceIconHC, 353 CreatePage pCreateFunc /* != 0 */, 354 GetPageRanges pRangesFunc /* darf 0 sein */, 355 sal_Bool bItemsOnDemand, sal_uLong /*nPos*/ ) 356 { 357 IconChoicePageData* pData = new IconChoicePageData ( nId, pCreateFunc, 358 pRangesFunc, 359 bItemsOnDemand ); 360 maPageList.Insert ( pData, LIST_APPEND ); 361 362 pData->fnGetRanges = pRangesFunc; 363 pData->bOnDemand = bItemsOnDemand; 364 365 sal_uInt16 *pId = new sal_uInt16 ( nId ); 366 SvxIconChoiceCtrlEntry* pEntry = maIconCtrl.InsertEntry( rIconText, rChoiceIcon, rChoiceIconHC ); 367 pEntry->SetUserData ( (void*) pId ); 368 return pEntry; 369 } 370 371 /********************************************************************** 372 | 373 | Paint-method 374 | 375 \**********************************************************************/ 376 377 void IconChoiceDialog::Paint( const Rectangle& rRect ) 378 { 379 Dialog::Paint ( rRect ); 380 381 for ( sal_uLong i=0; i<maPageList.Count(); i++ ) 382 { 383 IconChoicePageData* pData = (IconChoicePageData*)maPageList.GetObject ( i ); 384 385 if ( pData->nId == mnCurrentPageId ) 386 { 387 ShowPageImpl ( pData ); 388 } 389 else 390 { 391 HidePageImpl ( pData ); 392 } 393 } 394 } 395 396 EIconChoicePos IconChoiceDialog::SetCtrlPos( const EIconChoicePos& rPos ) 397 { 398 WinBits aWinBits = maIconCtrl.GetStyle (); 399 400 switch ( meChoicePos ) 401 { 402 case PosLeft : 403 aWinBits &= ~WB_ALIGN_TOP & ~WB_NOVSCROLL; 404 aWinBits |= WB_ALIGN_LEFT | WB_NOHSCROLL; 405 break; 406 case PosRight : 407 aWinBits &= ~WB_ALIGN_TOP & ~WB_NOVSCROLL; 408 aWinBits |= WB_ALIGN_LEFT | WB_NOHSCROLL; 409 break; 410 case PosTop : 411 aWinBits &= ~WB_ALIGN_LEFT & ~WB_NOHSCROLL; 412 aWinBits |= WB_ALIGN_TOP | WB_NOVSCROLL; 413 break; 414 case PosBottom : 415 aWinBits &= ~WB_ALIGN_LEFT & ~WB_NOHSCROLL; 416 aWinBits |= WB_ALIGN_TOP | WB_NOVSCROLL; 417 break; 418 }; 419 maIconCtrl.SetStyle ( aWinBits ); 420 421 SetPosSizeCtrls(); 422 423 424 EIconChoicePos eOldPos = meChoicePos; 425 meChoicePos = rPos; 426 427 return eOldPos; 428 } 429 430 /********************************************************************** 431 | 432 | Show / Hide page or button 433 | 434 \**********************************************************************/ 435 436 void IconChoiceDialog::ShowPageImpl ( IconChoicePageData* pData ) 437 { 438 if ( pData->pPage ) 439 pData->pPage->Show(); 440 } 441 442 // ----------------------------------------------------------------------- 443 444 void IconChoiceDialog::HidePageImpl ( IconChoicePageData* pData ) 445 { 446 if ( pData->pPage ) 447 pData->pPage->Hide(); 448 } 449 450 // ----------------------------------------------------------------------- 451 452 void IconChoiceDialog::ShowPage( sal_uInt16 nId ) 453 { 454 bool bInvalidate = GetCurPageId() != nId; 455 SetCurPageId( nId ); 456 ActivatePageImpl( ); 457 if(bInvalidate) 458 Invalidate(); 459 } 460 461 /********************************************************************** 462 | 463 | Resize Dialog 464 | 465 \**********************************************************************/ 466 467 #define ICONCTRL_WIDTH_PIXEL 110 468 #define ICONCTRL_HEIGHT_PIXEL 75 469 #define MINSIZE_BUTTON_WIDTH 70 470 #define MINSIZE_BUTTON_HEIGHT 22 471 472 void IconChoiceDialog::Resize() 473 { 474 Dialog::Resize (); 475 476 if ( IsReallyVisible() ) 477 { 478 SetPosSizeCtrls (); 479 } 480 } 481 482 void IconChoiceDialog::SetPosSizeCtrls ( sal_Bool bInit ) 483 { 484 const Point aCtrlOffset ( LogicToPixel( Point( CTRLS_OFFSET, CTRLS_OFFSET ), MAP_APPFONT ) ); 485 Size aOutSize ( GetOutputSizePixel() ); 486 487 //////////////////////////////////////// 488 // Button-Defaults 489 // 490 Size aDefaultButtonSize = LogicToPixel( Size( 50, 14 ), MAP_APPFONT ); 491 492 // Reset-Button 493 Size aResetButtonSize ( bInit ? aDefaultButtonSize : 494 aResetBtn.GetSizePixel () ); 495 496 //////////////////////////////////////// 497 // IconChoiceCtrl resizen & positionieren 498 // 499 SvtTabAppearanceCfg aCfg; 500 const long nDefaultWidth = (aCfg.GetScaleFactor() * ICONCTRL_WIDTH_PIXEL) / 100; 501 const long nDefaultHeight = (aCfg.GetScaleFactor() * ICONCTRL_HEIGHT_PIXEL) / 100; 502 503 Size aNewIconCtrlSize ( nDefaultWidth, 504 aOutSize.Height()-(2*aCtrlOffset.X()) ); 505 Point aIconCtrlPos; 506 switch ( meChoicePos ) 507 { 508 case PosLeft : 509 aIconCtrlPos = aCtrlOffset; 510 aNewIconCtrlSize = Size ( nDefaultWidth, 511 aOutSize.Height()-(2*aCtrlOffset.X()) ); 512 break; 513 case PosRight : 514 aIconCtrlPos = Point ( aOutSize.Width() - nDefaultWidth - 515 aCtrlOffset.X(), aCtrlOffset.X() ); 516 aNewIconCtrlSize = Size ( nDefaultWidth, 517 aOutSize.Height()-(2*aCtrlOffset.X()) ); 518 break; 519 case PosTop : 520 aIconCtrlPos = aCtrlOffset; 521 aNewIconCtrlSize = Size ( aOutSize.Width()-(2*aCtrlOffset.X()), 522 nDefaultHeight ); 523 break; 524 case PosBottom : 525 aIconCtrlPos = Point ( aCtrlOffset.X(), aOutSize.Height() - 526 aResetButtonSize.Height() - (2*aCtrlOffset.X()) - 527 nDefaultHeight ); 528 aNewIconCtrlSize = Size ( aOutSize.Width()-(2*aCtrlOffset.X()), 529 nDefaultHeight ); 530 break; 531 }; 532 maIconCtrl.SetPosSizePixel ( aIconCtrlPos, aNewIconCtrlSize ); 533 maIconCtrl.ArrangeIcons(); 534 535 //////////////////////////////////////// 536 // Pages resizen & positionieren 537 // 538 for ( sal_uLong i=0; i<maPageList.Count(); i++ ) 539 { 540 IconChoicePageData* pData = (IconChoicePageData*)maPageList.GetObject ( i ); 541 542 Point aNewPagePos; 543 Size aNewPageSize; 544 switch ( meChoicePos ) 545 { 546 case PosLeft : 547 aNewPagePos = Point ( aNewIconCtrlSize.Width() + (2*CTRLS_OFFSET), 548 CTRLS_OFFSET ); 549 aNewPageSize = Size ( aOutSize.Width() - aNewIconCtrlSize.Width() - 550 (3*CTRLS_OFFSET), 551 aOutSize.Height() - aOKBtn.GetSizePixel().Height() - 552 (3*CTRLS_OFFSET) ); 553 break; 554 case PosRight : 555 aNewPagePos = aCtrlOffset; 556 aNewPageSize = Size ( aOutSize.Width() - aNewIconCtrlSize.Width() - 557 (3*aCtrlOffset.X()), 558 aOutSize.Height() - aOKBtn.GetSizePixel().Height() - 559 (3*aCtrlOffset.X()) ); 560 break; 561 case PosTop : 562 aNewPagePos = Point ( aCtrlOffset.X(), aNewIconCtrlSize.Height() + 563 (2*aCtrlOffset.X()) ); 564 aNewPageSize = Size ( aOutSize.Width() - (2*aCtrlOffset.X()), 565 aOutSize.Height() - aOKBtn.GetSizePixel().Height() - 566 aNewIconCtrlSize.Height() - (4*aCtrlOffset.X()) ); 567 break; 568 case PosBottom : 569 aNewPagePos = aCtrlOffset; 570 aNewPageSize = Size ( aOutSize.Width() - (2*aCtrlOffset.X()), 571 aOutSize.Height() - aOKBtn.GetSizePixel().Height() - 572 aNewIconCtrlSize.Height() - (4*aCtrlOffset.X()) ); 573 break; 574 }; 575 576 if ( pData->pPage ) 577 pData->pPage->SetPosSizePixel ( aNewPagePos, aNewPageSize ); 578 } 579 580 //////////////////////////////////////// 581 // Buttons positionieren 582 // 583 sal_uLong nXOffset=0; 584 if ( meChoicePos == PosRight ) 585 nXOffset = aNewIconCtrlSize.Width()+(2*aCtrlOffset.X()); 586 587 aResetBtn.SetPosSizePixel ( Point( aOutSize.Width() - nXOffset - 588 aResetButtonSize.Width()-aCtrlOffset.X(), 589 aOutSize.Height()-aResetButtonSize.Height()- 590 aCtrlOffset.X() ), 591 aResetButtonSize ); 592 // Help-Button 593 Size aHelpButtonSize ( bInit ? aDefaultButtonSize : 594 aHelpBtn.GetSizePixel () ); 595 aHelpBtn.SetPosSizePixel ( Point( aOutSize.Width()-aResetButtonSize.Width()- 596 aHelpButtonSize.Width()- nXOffset - 597 (2*aCtrlOffset.X()), 598 aOutSize.Height()-aHelpButtonSize.Height()- 599 aCtrlOffset.X() ), 600 aHelpButtonSize ); 601 // Cancel-Button 602 Size aCancelButtonSize ( bInit ? aDefaultButtonSize : 603 aCancelBtn.GetSizePixel () ); 604 aCancelBtn.SetPosSizePixel ( Point( aOutSize.Width()-aCancelButtonSize.Width()- 605 aResetButtonSize.Width()-aHelpButtonSize.Width()- 606 (3*aCtrlOffset.X()) - nXOffset, 607 aOutSize.Height()-aCancelButtonSize.Height()- 608 aCtrlOffset.X() ), 609 aCancelButtonSize ); 610 // OK-Button 611 Size aOKButtonSize ( bInit ? aDefaultButtonSize : aOKBtn.GetSizePixel () ); 612 aOKBtn.SetPosSizePixel ( Point( aOutSize.Width()-aOKButtonSize.Width()- 613 aCancelButtonSize.Width()-aResetButtonSize.Width()- 614 aHelpButtonSize.Width()-(4*aCtrlOffset.X())- nXOffset, 615 aOutSize.Height()-aOKButtonSize.Height()-aCtrlOffset.X() ), 616 aOKButtonSize ); 617 618 Invalidate(); 619 } 620 621 void IconChoiceDialog::SetPosSizePages ( sal_uInt16 nId ) 622 { 623 const Point aCtrlOffset ( LogicToPixel( Point( CTRLS_OFFSET, CTRLS_OFFSET ), MAP_APPFONT ) ); 624 IconChoicePageData* pData = GetPageData ( nId ); 625 626 if ( pData->pPage ) 627 { 628 Size aOutSize ( GetOutputSizePixel() ); 629 Size aIconCtrlSize ( maIconCtrl.GetSizePixel() ); 630 631 Point aNewPagePos; 632 Size aNewPageSize; 633 switch ( meChoicePos ) 634 { 635 case PosLeft : 636 aNewPagePos = Point ( aIconCtrlSize.Width() + (2*aCtrlOffset.X()), 637 aCtrlOffset.X() ); 638 aNewPageSize = Size ( aOutSize.Width() - maIconCtrl.GetSizePixel().Width() - 639 (3*aCtrlOffset.X()), 640 aOutSize.Height() - aOKBtn.GetSizePixel().Height() - 641 (3*aCtrlOffset.X()) ); 642 break; 643 case PosRight : 644 aNewPagePos = aCtrlOffset; 645 aNewPageSize = Size ( aOutSize.Width() - maIconCtrl.GetSizePixel().Width() - 646 (3*aCtrlOffset.X()), 647 aOutSize.Height() - aOKBtn.GetSizePixel().Height() - 648 (3*aCtrlOffset.X()) ); 649 break; 650 case PosTop : 651 aNewPagePos = Point ( aCtrlOffset.X(), aIconCtrlSize.Height() + 652 (2*aCtrlOffset.X()) ); 653 aNewPageSize = Size ( aOutSize.Width() - (2*aCtrlOffset.X()), 654 aOutSize.Height() - aOKBtn.GetSizePixel().Height() - 655 maIconCtrl.GetSizePixel().Height() - (4*aCtrlOffset.X()) ); 656 break; 657 case PosBottom : 658 aNewPagePos = aCtrlOffset; 659 aNewPageSize = Size ( aOutSize.Width() - (2*aCtrlOffset.X()), 660 aOutSize.Height() - aOKBtn.GetSizePixel().Height() - 661 maIconCtrl.GetSizePixel().Height() - (4*aCtrlOffset.X()) ); 662 break; 663 }; 664 665 pData->pPage->SetPosSizePixel ( aNewPagePos, aNewPageSize ); 666 } 667 } 668 669 /********************************************************************** 670 | 671 | select a page 672 | 673 \**********************************************************************/ 674 675 IMPL_LINK ( IconChoiceDialog , ChosePageHdl_Impl, void *, EMPTYARG ) 676 { 677 sal_uLong nPos; 678 679 SvxIconChoiceCtrlEntry *pEntry = maIconCtrl.GetSelectedEntry ( nPos ); 680 if ( !pEntry ) 681 pEntry = maIconCtrl.GetCursor( ); 682 683 sal_uInt16 *pId = (sal_uInt16*)pEntry->GetUserData (); 684 685 if( *pId != mnCurrentPageId ) 686 { 687 IconChoicePageData* pData = GetPageData ( mnCurrentPageId ); 688 if ( pData->pPage ) 689 DeActivatePageImpl(); 690 691 SetCurPageId ( *pId ); 692 693 ActivatePageImpl(); 694 Invalidate(); 695 } 696 697 return 0L; 698 } 699 700 /********************************************************************** 701 | 702 | Button-handler 703 | 704 \**********************************************************************/ 705 706 IMPL_LINK( IconChoiceDialog, OkHdl, Button *, EMPTYARG ) 707 { 708 bInOK = sal_True; 709 710 if ( OK_Impl() ) 711 { 712 if ( bModal ) 713 EndDialog( Ok() ); 714 else 715 { 716 Ok(); 717 Close(); 718 } 719 } 720 return 0; 721 } 722 723 // ----------------------------------------------------------------------- 724 725 IMPL_LINK( IconChoiceDialog, ResetHdl, Button *, EMPTYARG ) 726 { 727 ResetPageImpl (); 728 729 IconChoicePageData* pData = GetPageData ( mnCurrentPageId ); 730 DBG_ASSERT( pData, "Id nicht bekannt" ); 731 732 if ( pData->bOnDemand ) 733 { 734 // CSet auf AIS hat hier Probleme, daher getrennt 735 const SfxItemSet* _pSet = &( pData->pPage->GetItemSet() ); 736 pData->pPage->Reset( *(SfxItemSet*)_pSet ); 737 } 738 else 739 pData->pPage->Reset( *pSet ); 740 741 742 return 0; 743 } 744 745 // ----------------------------------------------------------------------- 746 747 IMPL_LINK( IconChoiceDialog, CancelHdl, Button*, EMPTYARG ) 748 { 749 Close(); 750 751 return 0; 752 } 753 754 /********************************************************************** 755 | 756 | call page 757 | 758 \**********************************************************************/ 759 760 void IconChoiceDialog::ActivatePageImpl () 761 { 762 DBG_ASSERT( maPageList.Count(), "keine Pages angemeldet" ); 763 IconChoicePageData* pData = GetPageData ( mnCurrentPageId ); 764 DBG_ASSERT( pData, "Id nicht bekannt" ); 765 if ( pData ) 766 { 767 if ( !pData->pPage ) 768 { 769 const SfxItemSet* pTmpSet = 0; 770 771 if ( pSet ) 772 { 773 if ( bItemsReset && pSet->GetParent() ) 774 pTmpSet = pSet->GetParent(); 775 else 776 pTmpSet = pSet; 777 } 778 779 if ( pTmpSet && !pData->bOnDemand ) 780 pData->pPage = (pData->fnCreatePage)( this, *pTmpSet ); 781 else 782 pData->pPage = (pData->fnCreatePage)( this, *CreateInputItemSet( mnCurrentPageId ) ); 783 784 SvtViewOptions aTabPageOpt( E_TABPAGE, String::CreateFromInt32( pData->nId ) ); 785 pData->pPage->SetUserData( GetViewOptUserItem( aTabPageOpt ) ); 786 SetPosSizePages ( pData->nId ); 787 788 if ( pData->bOnDemand ) 789 pData->pPage->Reset( (SfxItemSet &)pData->pPage->GetItemSet() ); 790 else 791 pData->pPage->Reset( *pSet ); 792 793 PageCreated( mnCurrentPageId, *pData->pPage ); 794 } 795 else if ( pData->bRefresh ) 796 { 797 pData->pPage->Reset( *pSet ); 798 } 799 800 pData->bRefresh = sal_False; 801 802 if ( pExampleSet ) 803 pData->pPage->ActivatePage( *pExampleSet ); 804 } 805 806 SetHelpId( pData->pPage->GetHelpId() ); 807 808 sal_Bool bReadOnly = pData->pPage->IsReadOnly(); 809 if ( bReadOnly || bHideResetBtn ) 810 aResetBtn.Hide(); 811 else 812 aResetBtn.Show(); 813 814 } 815 816 // ----------------------------------------------------------------------- 817 818 sal_Bool IconChoiceDialog::DeActivatePageImpl () 819 { 820 IconChoicePageData *pData = GetPageData ( mnCurrentPageId ); 821 822 int nRet = IconChoicePage::LEAVE_PAGE; 823 824 if ( pData ) 825 { 826 IconChoicePage * pPage = pData->pPage; 827 828 if ( !pExampleSet && pPage->HasExchangeSupport() && pSet ) 829 pExampleSet = new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() ); 830 831 if ( pSet ) 832 { 833 SfxItemSet aTmp( *pSet->GetPool(), pSet->GetRanges() ); 834 835 if ( pPage->HasExchangeSupport() ) 836 nRet = pPage->DeactivatePage( &aTmp ); 837 838 if ( ( IconChoicePage::LEAVE_PAGE & nRet ) == IconChoicePage::LEAVE_PAGE && 839 aTmp.Count() ) 840 { 841 pExampleSet->Put( aTmp ); 842 pOutSet->Put( aTmp ); 843 } 844 } 845 else 846 { 847 if ( pPage->HasExchangeSupport() ) //!!! 848 { 849 if ( !pExampleSet ) 850 { 851 SfxItemPool* pPool = pPage->GetItemSet().GetPool(); 852 pExampleSet = 853 new SfxItemSet( *pPool, GetInputRanges( *pPool ) ); 854 } 855 nRet = pPage->DeactivatePage( pExampleSet ); 856 } 857 else 858 nRet = pPage->DeactivatePage( NULL ); 859 } 860 861 if ( nRet & IconChoicePage::REFRESH_SET ) 862 { 863 pSet = GetRefreshedSet(); 864 DBG_ASSERT( pSet, "GetRefreshedSet() liefert NULL" ); 865 // alle Pages als neu zu initialsieren flaggen 866 const sal_uLong nCount = maPageList.Count(); 867 868 for ( sal_uInt16 i = 0; i < nCount; ++i ) 869 { 870 IconChoicePageData* pObj = (IconChoicePageData*)maPageList.GetObject(i); 871 872 if ( pObj->pPage != pPage ) // eigene Page nicht mehr refreshen 873 pObj->bRefresh = sal_True; 874 else 875 pObj->bRefresh = sal_False; 876 } 877 } 878 } 879 880 if ( nRet & IconChoicePage::LEAVE_PAGE ) 881 return sal_True; 882 else 883 return sal_False; 884 } 885 886 // ----------------------------------------------------------------------- 887 888 void IconChoiceDialog::ResetPageImpl () 889 { 890 IconChoicePageData *pData = GetPageData ( mnCurrentPageId ); 891 892 DBG_ASSERT( pData, "Id nicht bekannt" ); 893 894 if ( pData->bOnDemand ) 895 { 896 // CSet auf AIS hat hier Probleme, daher getrennt 897 const SfxItemSet* _pSet = &pData->pPage->GetItemSet(); 898 pData->pPage->Reset( *(SfxItemSet*)_pSet ); 899 } 900 else 901 pData->pPage->Reset( *pSet ); 902 } 903 904 /********************************************************************** 905 | 906 | handling itemsets 907 | 908 \**********************************************************************/ 909 910 const sal_uInt16* IconChoiceDialog::GetInputRanges( const SfxItemPool& rPool ) 911 { 912 if ( pSet ) 913 { 914 DBG_ERRORFILE( "Set bereits vorhanden!" ); 915 return pSet->GetRanges(); 916 } 917 918 if ( pRanges ) 919 return pRanges; 920 SvUShorts aUS( 16, 16 ); 921 sal_uLong nCount = maPageList.Count(); 922 923 sal_uInt16 i; 924 for ( i = 0; i < nCount; ++i ) 925 { 926 IconChoicePageData* pData = maPageList.GetObject (i); 927 928 if ( pData->fnGetRanges ) 929 { 930 const sal_uInt16* pTmpRanges = (pData->fnGetRanges)(); 931 const sal_uInt16* pIter = pTmpRanges; 932 933 sal_uInt16 nLen; 934 for( nLen = 0; *pIter; ++nLen, ++pIter ) 935 ; 936 aUS.Insert( pTmpRanges, nLen, aUS.Count() ); 937 } 938 } 939 940 // remove double Id's 941 #ifndef TF_POOLABLE 942 if ( rPool.HasMap() ) 943 #endif 944 { 945 nCount = aUS.Count(); 946 947 for ( i = 0; i < nCount; ++i ) 948 aUS[i] = rPool.GetWhich( aUS[i] ); 949 } 950 951 // sortieren 952 if ( aUS.Count() > 1 ) 953 { 954 #if defined __SUNPRO_CC 955 #pragma disable_warn 956 #endif 957 qsort( (void*)aUS.GetData(), aUS.Count(), sizeof(sal_uInt16), IconcDlgCmpUS_Impl ); 958 #if defined __SUNPRO_CC 959 #pragma enable_warn 960 #endif 961 } 962 963 pRanges = new sal_uInt16[aUS.Count() + 1]; 964 memcpy(pRanges, aUS.GetData(), sizeof(sal_uInt16) * aUS.Count()); 965 pRanges[aUS.Count()] = 0; 966 967 return pRanges; 968 } 969 970 // ----------------------------------------------------------------------- 971 972 void IconChoiceDialog::SetInputSet( const SfxItemSet* pInSet ) 973 { 974 FASTBOOL bSet = ( pSet != NULL ); 975 976 pSet = pInSet; 977 978 if ( !bSet && !pExampleSet && !pOutSet ) 979 { 980 pExampleSet = new SfxItemSet( *pSet ); 981 pOutSet = new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() ); 982 } 983 } 984 985 // ----------------------------------------------------------------------- 986 987 void IconChoiceDialog::PageCreated( sal_uInt16 /*nId*/, IconChoicePage& /*rPage*/ ) 988 { 989 // not interested in 990 } 991 992 // ----------------------------------------------------------------------- 993 994 SfxItemSet* IconChoiceDialog::CreateInputItemSet( sal_uInt16 ) 995 { 996 DBG_WARNINGFILE( "CreateInputItemSet nicht implementiert" ); 997 998 return 0; 999 } 1000 1001 /********************************************************************** 1002 | 1003 | start dialog 1004 | 1005 \**********************************************************************/ 1006 1007 short IconChoiceDialog::Execute() 1008 { 1009 if ( !maPageList.Count() ) 1010 return RET_CANCEL; 1011 1012 Start_Impl(); 1013 1014 return Dialog::Execute(); 1015 } 1016 1017 // ----------------------------------------------------------------------- 1018 1019 void IconChoiceDialog::Start( sal_Bool bShow ) 1020 { 1021 1022 aCancelBtn.SetClickHdl( LINK( this, IconChoiceDialog, CancelHdl ) ); 1023 bModal = sal_False; 1024 1025 Start_Impl(); 1026 1027 if ( bShow ) 1028 Window::Show(); 1029 1030 } 1031 1032 // ----------------------------------------------------------------------- 1033 1034 sal_Bool IconChoiceDialog::QueryClose() 1035 { 1036 sal_Bool bRet = sal_True; 1037 const sal_uLong nCount = maPageList.Count(); 1038 for ( sal_uLong i = 0; i < nCount; ++i ) 1039 { 1040 IconChoicePageData* pData = maPageList.GetObject(i); 1041 if ( pData->pPage && !pData->pPage->QueryClose() ) 1042 { 1043 bRet = sal_False; 1044 break; 1045 } 1046 } 1047 return bRet; 1048 } 1049 1050 // ----------------------------------------------------------------------- 1051 1052 void IconChoiceDialog::Start_Impl() 1053 { 1054 Point aPos; 1055 sal_uInt16 nActPage; 1056 1057 if ( mnCurrentPageId == 0 || mnCurrentPageId == USHRT_MAX ) 1058 nActPage = maPageList.GetObject(0)->nId;//First()->nId; 1059 else 1060 nActPage = mnCurrentPageId; 1061 1062 // Konfiguration vorhanden? 1063 SvtViewOptions aTabDlgOpt( E_TABDIALOG, String::CreateFromInt32( nResId ) ); 1064 1065 if ( aTabDlgOpt.Exists() ) 1066 { 1067 // ggf. Position aus Konfig 1068 SetWindowState( ByteString( aTabDlgOpt.GetWindowState().getStr(), RTL_TEXTENCODING_ASCII_US ) ); 1069 1070 // initiale TabPage aus Programm/Hilfe/Konfig 1071 nActPage = (sal_uInt16)aTabDlgOpt.GetPageID(); 1072 1073 if ( USHRT_MAX != mnCurrentPageId ) 1074 nActPage = mnCurrentPageId; 1075 1076 if ( GetPageData ( nActPage ) == NULL ) 1077 nActPage = ( (IconChoicePageData*)maPageList.GetObject(0) )->nId; 1078 } 1079 else if ( USHRT_MAX != mnCurrentPageId && GetPageData ( mnCurrentPageId ) != NULL ) 1080 nActPage = mnCurrentPageId; 1081 1082 mnCurrentPageId = nActPage; 1083 1084 FocusOnIcon( mnCurrentPageId ); 1085 1086 ActivatePageImpl(); 1087 } 1088 1089 // ----------------------------------------------------------------------- 1090 1091 const SfxItemSet* IconChoiceDialog::GetRefreshedSet() 1092 { 1093 DBG_ERRORFILE( "GetRefreshedSet nicht implementiert" ); 1094 return 0; 1095 } 1096 1097 /********************************************************************** 1098 | 1099 | tool-methods 1100 | 1101 \**********************************************************************/ 1102 1103 IconChoicePageData* IconChoiceDialog::GetPageData ( sal_uInt16 nId ) 1104 { 1105 IconChoicePageData *pRet = NULL; 1106 sal_Bool bFound = sal_False; 1107 1108 for ( sal_uLong i=0; i<maPageList.Count() && !bFound; i++ ) 1109 { 1110 IconChoicePageData* pData = (IconChoicePageData*)maPageList.GetObject ( i ); 1111 1112 if ( pData->nId == nId ) 1113 { 1114 pRet = pData; 1115 } 1116 } 1117 1118 return pRet; 1119 } 1120 1121 /********************************************************************** 1122 | 1123 | OK-Status 1124 | 1125 \**********************************************************************/ 1126 1127 sal_Bool IconChoiceDialog::OK_Impl() 1128 { 1129 IconChoicePage* pPage = GetPageData ( mnCurrentPageId )->pPage; 1130 1131 bool bEnd = !pPage; 1132 if ( pPage ) 1133 { 1134 int nRet = IconChoicePage::LEAVE_PAGE; 1135 if ( pSet ) 1136 { 1137 SfxItemSet aTmp( *pSet->GetPool(), pSet->GetRanges() ); 1138 sal_Bool bRet = sal_False; 1139 1140 if ( pPage->HasExchangeSupport() ) 1141 nRet = pPage->DeactivatePage( &aTmp ); 1142 1143 if ( ( IconChoicePage::LEAVE_PAGE & nRet ) == IconChoicePage::LEAVE_PAGE 1144 && aTmp.Count() ) 1145 { 1146 pExampleSet->Put( aTmp ); 1147 pOutSet->Put( aTmp ); 1148 } 1149 else if ( bRet ) 1150 bModified |= sal_True; 1151 } 1152 else 1153 nRet = pPage->DeactivatePage( NULL ); 1154 bEnd = nRet; 1155 } 1156 1157 return bEnd; 1158 } 1159 1160 // ----------------------------------------------------------------------- 1161 1162 short IconChoiceDialog::Ok() 1163 { 1164 bInOK = sal_True; 1165 1166 if ( !pOutSet ) 1167 { 1168 if ( !pExampleSet && pSet ) 1169 pOutSet = pSet->Clone( sal_False ); // ohne Items 1170 else if ( pExampleSet ) 1171 pOutSet = new SfxItemSet( *pExampleSet ); 1172 } 1173 sal_Bool _bModified = sal_False; 1174 1175 const sal_uLong nCount = maPageList.Count(); 1176 1177 for ( sal_uInt16 i = 0; i < nCount; ++i ) 1178 { 1179 IconChoicePageData* pData = GetPageData ( i ); 1180 1181 IconChoicePage* pPage = pData->pPage; 1182 1183 if ( pPage ) 1184 { 1185 if ( pData->bOnDemand ) 1186 { 1187 SfxItemSet& rSet = (SfxItemSet&)pPage->GetItemSet(); 1188 rSet.ClearItem(); 1189 _bModified |= pPage->FillItemSet( rSet ); 1190 } 1191 else if ( pSet && !pPage->HasExchangeSupport() ) 1192 { 1193 SfxItemSet aTmp( *pSet->GetPool(), pSet->GetRanges() ); 1194 1195 if ( pPage->FillItemSet( aTmp ) ) 1196 { 1197 _bModified |= sal_True; 1198 pExampleSet->Put( aTmp ); 1199 pOutSet->Put( aTmp ); 1200 } 1201 } 1202 } 1203 } 1204 1205 if ( _bModified || ( pOutSet && pOutSet->Count() > 0 ) ) 1206 _bModified |= sal_True; 1207 1208 return _bModified ? RET_OK : RET_CANCEL; 1209 } 1210 1211 // ----------------------------------------------------------------------- 1212 1213 void IconChoiceDialog::FocusOnIcon( sal_uInt16 nId ) 1214 { 1215 // set focus to icon for the current visible page 1216 for ( sal_uInt16 i=0; i<maIconCtrl.GetEntryCount(); i++) 1217 { 1218 SvxIconChoiceCtrlEntry* pEntry = maIconCtrl.GetEntry ( i ); 1219 sal_uInt16* pUserData = (sal_uInt16*) pEntry->GetUserData(); 1220 1221 if ( pUserData && *pUserData == nId ) 1222 { 1223 maIconCtrl.SetCursor( pEntry ); 1224 break; 1225 } 1226 } 1227 } 1228