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