update credits
[LibreOffice.git] / cui / source / dialogs / iconcdlg.cxx
blob1f853ff62483de036e16a8887df1f3472a56ece9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sfx2/app.hxx>
21 #include <tools/rc.h>
22 #include <tools/shl.hxx>
24 #include <dialmgr.hxx>
26 #include "iconcdlg.hxx"
28 #include "helpid.hrc"
29 #include <cuires.hrc>
30 #include <unotools/viewoptions.hxx>
31 #include <svtools/apearcfg.hxx>
32 #include <vcl/mnemonic.hxx>
33 #include <vcl/i18nhelp.hxx>
35 using ::std::vector;
37 // some stuff for easier changes for SvtViewOptions
38 static const sal_Char* pViewOptDataName = "dialog data";
39 #define VIEWOPT_DATANAME OUString::createFromAscii( pViewOptDataName )
41 static inline void SetViewOptUserItem( SvtViewOptions& rOpt, const String& rData )
43 rOpt.SetUserItem( VIEWOPT_DATANAME, ::com::sun::star::uno::makeAny( OUString( rData ) ) );
46 static inline String GetViewOptUserItem( const SvtViewOptions& rOpt )
48 ::com::sun::star::uno::Any aAny( rOpt.GetUserItem( VIEWOPT_DATANAME ) );
49 OUString aUserData;
50 aAny >>= aUserData;
52 return String( aUserData );
56 //#####################################################################
58 // Class IconChoicePage
60 //#####################################################################
62 /**********************************************************************
64 | Ctor / Dtor
66 \**********************************************************************/
68 IconChoicePage::IconChoicePage( Window *pParent, const ResId &rResId,
69 const SfxItemSet &rAttrSet )
70 : TabPage ( pParent, rResId ),
71 pSet ( &rAttrSet ),
72 bHasExchangeSupport ( sal_False ),
73 pDialog ( NULL )
75 SetStyle ( GetStyle() | WB_DIALOGCONTROL | WB_HIDE );
78 // -----------------------------------------------------------------------
80 IconChoicePage::~IconChoicePage()
84 /**********************************************************************
86 | Activate / Deaktivate
88 \**********************************************************************/
90 void IconChoicePage::ActivatePage( const SfxItemSet& )
94 // -----------------------------------------------------------------------
96 int IconChoicePage::DeactivatePage( SfxItemSet* )
98 return LEAVE_PAGE;
101 /**********************************************************************
103 | ...
105 \**********************************************************************/
107 void IconChoicePage::FillUserData()
111 // -----------------------------------------------------------------------
113 sal_Bool IconChoicePage::IsReadOnly() const
115 return sal_False;
118 // -----------------------------------------------------------------------
120 sal_Bool IconChoicePage::QueryClose()
122 return sal_True;
125 /**********************************************************************
127 | window-methods
129 \**********************************************************************/
131 void IconChoicePage::ImplInitSettings()
133 Window* pParent = GetParent();
134 if ( pParent->IsChildTransparentModeEnabled() && !IsControlBackground() )
136 EnableChildTransparentMode( sal_True );
137 SetParentClipMode( PARENTCLIPMODE_NOCLIP );
138 SetPaintTransparent( sal_True );
139 SetBackground();
141 else
143 EnableChildTransparentMode( sal_False );
144 SetParentClipMode( 0 );
145 SetPaintTransparent( sal_False );
147 if ( IsControlBackground() )
148 SetBackground( GetControlBackground() );
149 else
150 SetBackground( pParent->GetBackground() );
154 // -----------------------------------------------------------------------
156 void IconChoicePage::StateChanged( StateChangedType nType )
158 Window::StateChanged( nType );
160 if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
162 ImplInitSettings();
163 Invalidate();
167 // -----------------------------------------------------------------------
169 void IconChoicePage::DataChanged( const DataChangedEvent& rDCEvt )
171 Window::DataChanged( rDCEvt );
173 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
174 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
176 ImplInitSettings();
177 Invalidate();
181 //#####################################################################
183 // Class IconChoiceDialog
185 //#####################################################################
187 /**********************************************************************
189 | Ctor / Dtor
191 \**********************************************************************/
193 IconChoiceDialog::IconChoiceDialog ( Window* pParent, const ResId &rResId,
194 const EIconChoicePos ePos,
195 const SfxItemSet *pItemSet )
196 : ModalDialog ( pParent, rResId ),
197 meChoicePos ( ePos ),
198 maIconCtrl ( this, WB_3DLOOK | WB_ICON | WB_BORDER |
199 WB_NOCOLUMNHEADER | WB_HIGHLIGHTFRAME |
200 WB_NODRAGSELECTION | WB_TABSTOP ),
201 mnCurrentPageId ( USHRT_MAX ),
203 aOKBtn ( this, WB_DEFBUTTON ),
204 aCancelBtn ( this, WB_DEFBUTTON ),
205 aHelpBtn ( this ),
206 aResetBtn ( this ),
207 pSet ( pItemSet ),
208 pOutSet ( NULL ),
209 pExampleSet ( NULL ),
210 pRanges ( NULL ),
211 nResId ( rResId.GetId() ),
213 bHideResetBtn ( sal_False ),
214 bModal ( sal_False ),
215 bInOK ( sal_False ),
216 bModified ( sal_False ),
217 bItemsReset ( sal_False )
220 maIconCtrl.SetStyle (WB_3DLOOK | WB_ICON | WB_BORDER | WB_NOCOLUMNHEADER | WB_HIGHLIGHTFRAME | WB_NODRAGSELECTION | WB_TABSTOP | WB_CLIPCHILDREN );
221 SetCtrlPos ( meChoicePos );
222 maIconCtrl.SetClickHdl ( LINK ( this, IconChoiceDialog , ChosePageHdl_Impl ) );
223 maIconCtrl.Show();
224 maIconCtrl.SetChoiceWithCursor ( sal_True );
225 maIconCtrl.SetSelectionMode( SINGLE_SELECTION );
226 maIconCtrl.SetHelpId( HID_ICCDIALOG_CHOICECTRL );
228 // ItemSet
229 if ( pSet )
231 pExampleSet = new SfxItemSet( *pSet );
232 pOutSet = new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() );
235 // Buttons
236 aOKBtn.SetClickHdl ( LINK( this, IconChoiceDialog, OkHdl ) );
237 aOKBtn.SetHelpId( HID_ICCDIALOG_OK_BTN );
238 aCancelBtn.SetHelpId( HID_ICCDIALOG_CANCEL_BTN );
239 aResetBtn.SetClickHdl( LINK( this, IconChoiceDialog, ResetHdl ) );
240 aResetBtn.SetText( CUI_RESSTR(RID_SVXSTR_ICONCHOICEDLG_RESETBUT) );
241 aResetBtn.SetHelpId( HID_ICCDIALOG_RESET_BTN );
242 aOKBtn.Show();
243 aCancelBtn.Show();
244 aHelpBtn.Show();
245 aResetBtn.Show();
247 SetPosSizeCtrls ( sal_True );
250 // -----------------------------------------------------------------------
252 IconChoiceDialog ::~IconChoiceDialog ()
254 // save configuration at INI-Manager
255 // and remove pages
256 SvtViewOptions aTabDlgOpt( E_TABDIALOG, OUString::number(nResId) );
257 aTabDlgOpt.SetWindowState(OStringToOUString(GetWindowState((WINDOWSTATE_MASK_X | WINDOWSTATE_MASK_Y | WINDOWSTATE_MASK_STATE | WINDOWSTATE_MASK_MINIMIZED)), RTL_TEXTENCODING_ASCII_US));
258 aTabDlgOpt.SetPageID( mnCurrentPageId );
260 for ( size_t i = 0, nCount = maPageList.size(); i < nCount; ++i )
262 IconChoicePageData* pData = maPageList[ i ];
264 if ( pData->pPage )
266 pData->pPage->FillUserData();
267 String aPageData(pData->pPage->GetUserData());
268 if ( aPageData.Len() )
270 SvtViewOptions aTabPageOpt( E_TABPAGE, OUString::number(pData->nId) );
272 SetViewOptUserItem( aTabPageOpt, aPageData );
275 if ( pData->bOnDemand )
276 delete (SfxItemSet*)&pData->pPage->GetItemSet();
277 delete pData->pPage;
279 delete pData;
282 // remove Userdata from Icons
283 for ( sal_uLong i=0; i < maIconCtrl.GetEntryCount(); i++)
285 SvxIconChoiceCtrlEntry* pEntry = maIconCtrl.GetEntry ( i );
286 sal_uInt16* pUserData = (sal_uInt16*) pEntry->GetUserData();
287 delete pUserData;
291 if ( pRanges )
292 delete pRanges;
293 if ( pOutSet )
294 delete pOutSet;
297 /**********************************************************************
299 | add new page
301 \**********************************************************************/
303 SvxIconChoiceCtrlEntry* IconChoiceDialog::AddTabPage(
304 sal_uInt16 nId,
305 const String& rIconText,
306 const Image& rChoiceIcon,
307 CreatePage pCreateFunc /* != 0 */,
308 GetPageRanges pRangesFunc /* darf 0 sein */,
309 sal_Bool bItemsOnDemand,
310 sal_uLong /*nPos*/
313 IconChoicePageData* pData = new IconChoicePageData ( nId, pCreateFunc,
314 pRangesFunc,
315 bItemsOnDemand );
316 maPageList.push_back( pData );
318 pData->fnGetRanges = pRangesFunc;
319 pData->bOnDemand = bItemsOnDemand;
321 sal_uInt16 *pId = new sal_uInt16 ( nId );
322 SvxIconChoiceCtrlEntry* pEntry = maIconCtrl.InsertEntry( rIconText, rChoiceIcon );
323 pEntry->SetUserData ( (void*) pId );
324 return pEntry;
327 /**********************************************************************
329 | Paint-method
331 \**********************************************************************/
333 void IconChoiceDialog::Paint( const Rectangle& rRect )
335 Dialog::Paint ( rRect );
337 for ( size_t i = 0; i < maPageList.size(); i++ )
339 IconChoicePageData* pData = maPageList[ i ];
341 if ( pData->nId == mnCurrentPageId )
343 ShowPageImpl ( pData );
345 else
347 HidePageImpl ( pData );
352 EIconChoicePos IconChoiceDialog::SetCtrlPos( const EIconChoicePos& rPos )
354 WinBits aWinBits = maIconCtrl.GetStyle ();
356 switch ( meChoicePos )
358 case PosLeft :
359 aWinBits &= ~WB_ALIGN_TOP & ~WB_NOVSCROLL;
360 aWinBits |= WB_ALIGN_LEFT | WB_NOHSCROLL;
361 break;
362 case PosRight :
363 aWinBits &= ~WB_ALIGN_TOP & ~WB_NOVSCROLL;
364 aWinBits |= WB_ALIGN_LEFT | WB_NOHSCROLL;
365 break;
366 case PosTop :
367 aWinBits &= ~WB_ALIGN_LEFT & ~WB_NOHSCROLL;
368 aWinBits |= WB_ALIGN_TOP | WB_NOVSCROLL;
369 break;
370 case PosBottom :
371 aWinBits &= ~WB_ALIGN_LEFT & ~WB_NOHSCROLL;
372 aWinBits |= WB_ALIGN_TOP | WB_NOVSCROLL;
373 break;
375 maIconCtrl.SetStyle ( aWinBits );
377 SetPosSizeCtrls();
380 EIconChoicePos eOldPos = meChoicePos;
381 meChoicePos = rPos;
383 return eOldPos;
386 /**********************************************************************
388 | Show / Hide page or button
390 \**********************************************************************/
392 void IconChoiceDialog::ShowPageImpl ( IconChoicePageData* pData )
394 if ( pData->pPage )
395 pData->pPage->Show();
398 // -----------------------------------------------------------------------
400 void IconChoiceDialog::HidePageImpl ( IconChoicePageData* pData )
402 if ( pData->pPage )
403 pData->pPage->Hide();
406 // -----------------------------------------------------------------------
408 void IconChoiceDialog::ShowPage( sal_uInt16 nId )
410 bool bInvalidate = GetCurPageId() != nId;
411 SetCurPageId( nId );
412 ActivatePageImpl( );
413 if(bInvalidate)
414 Invalidate();
417 /**********************************************************************
419 | Resize Dialog
421 \**********************************************************************/
423 #define ICONCTRL_WIDTH_PIXEL 110
424 #define ICONCTRL_HEIGHT_PIXEL 75
426 void IconChoiceDialog::Resize()
428 Dialog::Resize ();
430 if ( IsReallyVisible() )
432 SetPosSizeCtrls ();
436 void IconChoiceDialog::SetPosSizeCtrls ( sal_Bool bInit )
438 const Point aCtrlOffset ( LogicToPixel( Point( CTRLS_OFFSET, CTRLS_OFFSET ), MAP_APPFONT ) );
439 Size aOutSize ( GetOutputSizePixel() );
441 ////////////////////////////////////////
442 // Button-Defaults
444 Size aDefaultButtonSize = LogicToPixel( Size( 50, 14 ), MAP_APPFONT );
446 // Reset-Button
447 Size aResetButtonSize ( bInit ? aDefaultButtonSize :
448 aResetBtn.GetSizePixel () );
450 ////////////////////////////////////////
451 // IconChoiceCtrl resizen & positionieren
453 SvtTabAppearanceCfg aCfg;
454 const long nDefaultWidth = (aCfg.GetScaleFactor() * ICONCTRL_WIDTH_PIXEL) / 100;
455 const long nDefaultHeight = (aCfg.GetScaleFactor() * ICONCTRL_HEIGHT_PIXEL) / 100;
457 Size aNewIconCtrlSize ( nDefaultWidth,
458 aOutSize.Height()-(2*aCtrlOffset.X()) );
459 Point aIconCtrlPos;
460 switch ( meChoicePos )
462 case PosLeft :
463 aIconCtrlPos = aCtrlOffset;
464 aNewIconCtrlSize = Size ( nDefaultWidth,
465 aOutSize.Height()-(2*aCtrlOffset.X()) );
466 break;
467 case PosRight :
468 aIconCtrlPos = Point ( aOutSize.Width() - nDefaultWidth -
469 aCtrlOffset.X(), aCtrlOffset.X() );
470 aNewIconCtrlSize = Size ( nDefaultWidth,
471 aOutSize.Height()-(2*aCtrlOffset.X()) );
472 break;
473 case PosTop :
474 aIconCtrlPos = aCtrlOffset;
475 aNewIconCtrlSize = Size ( aOutSize.Width()-(2*aCtrlOffset.X()),
476 nDefaultHeight );
477 break;
478 case PosBottom :
479 aIconCtrlPos = Point ( aCtrlOffset.X(), aOutSize.Height() -
480 aResetButtonSize.Height() - (2*aCtrlOffset.X()) -
481 nDefaultHeight );
482 aNewIconCtrlSize = Size ( aOutSize.Width()-(2*aCtrlOffset.X()),
483 nDefaultHeight );
484 break;
486 maIconCtrl.SetPosSizePixel ( aIconCtrlPos, aNewIconCtrlSize );
487 maIconCtrl.ArrangeIcons();
489 ////////////////////////////////////////
490 // resize & position the pages
492 for ( size_t i = 0; i < maPageList.size(); i++ )
494 IconChoicePageData* pData = maPageList[ i ];
496 Point aNewPagePos;
497 Size aNewPageSize;
498 switch ( meChoicePos )
500 case PosLeft :
501 aNewPagePos = Point ( aNewIconCtrlSize.Width() + (2*CTRLS_OFFSET),
502 CTRLS_OFFSET );
503 aNewPageSize = Size ( aOutSize.Width() - aNewIconCtrlSize.Width() -
504 (3*CTRLS_OFFSET),
505 aOutSize.Height() - aOKBtn.GetSizePixel().Height() -
506 (3*CTRLS_OFFSET) );
507 break;
508 case PosRight :
509 aNewPagePos = aCtrlOffset;
510 aNewPageSize = Size ( aOutSize.Width() - aNewIconCtrlSize.Width() -
511 (3*aCtrlOffset.X()),
512 aOutSize.Height() - aOKBtn.GetSizePixel().Height() -
513 (3*aCtrlOffset.X()) );
514 break;
515 case PosTop :
516 aNewPagePos = Point ( aCtrlOffset.X(), aNewIconCtrlSize.Height() +
517 (2*aCtrlOffset.X()) );
518 aNewPageSize = Size ( aOutSize.Width() - (2*aCtrlOffset.X()),
519 aOutSize.Height() - aOKBtn.GetSizePixel().Height() -
520 aNewIconCtrlSize.Height() - (4*aCtrlOffset.X()) );
521 break;
522 case PosBottom :
523 aNewPagePos = aCtrlOffset;
524 aNewPageSize = Size ( aOutSize.Width() - (2*aCtrlOffset.X()),
525 aOutSize.Height() - aOKBtn.GetSizePixel().Height() -
526 aNewIconCtrlSize.Height() - (4*aCtrlOffset.X()) );
527 break;
530 if ( pData->pPage )
531 pData->pPage->SetPosSizePixel ( aNewPagePos, aNewPageSize );
534 ////////////////////////////////////////
535 // position the buttons
537 sal_uLong nXOffset=0;
538 if ( meChoicePos == PosRight )
539 nXOffset = aNewIconCtrlSize.Width()+(2*aCtrlOffset.X());
541 aResetBtn.SetPosSizePixel ( Point( aOutSize.Width() - nXOffset -
542 aResetButtonSize.Width()-aCtrlOffset.X(),
543 aOutSize.Height()-aResetButtonSize.Height()-
544 aCtrlOffset.X() ),
545 aResetButtonSize );
546 // Help-Button
547 Size aHelpButtonSize ( bInit ? aDefaultButtonSize :
548 aHelpBtn.GetSizePixel () );
549 aHelpBtn.SetPosSizePixel ( Point( aOutSize.Width()-aResetButtonSize.Width()-
550 aHelpButtonSize.Width()- nXOffset -
551 (2*aCtrlOffset.X()),
552 aOutSize.Height()-aHelpButtonSize.Height()-
553 aCtrlOffset.X() ),
554 aHelpButtonSize );
555 // Cancel-Button
556 Size aCancelButtonSize ( bInit ? aDefaultButtonSize :
557 aCancelBtn.GetSizePixel () );
558 aCancelBtn.SetPosSizePixel ( Point( aOutSize.Width()-aCancelButtonSize.Width()-
559 aResetButtonSize.Width()-aHelpButtonSize.Width()-
560 (3*aCtrlOffset.X()) - nXOffset,
561 aOutSize.Height()-aCancelButtonSize.Height()-
562 aCtrlOffset.X() ),
563 aCancelButtonSize );
564 // OK-Button
565 Size aOKButtonSize ( bInit ? aDefaultButtonSize : aOKBtn.GetSizePixel () );
566 aOKBtn.SetPosSizePixel ( Point( aOutSize.Width()-aOKButtonSize.Width()-
567 aCancelButtonSize.Width()-aResetButtonSize.Width()-
568 aHelpButtonSize.Width()-(4*aCtrlOffset.X())- nXOffset,
569 aOutSize.Height()-aOKButtonSize.Height()-aCtrlOffset.X() ),
570 aOKButtonSize );
572 Invalidate();
575 void IconChoiceDialog::SetPosSizePages ( sal_uInt16 nId )
577 const Point aCtrlOffset ( LogicToPixel( Point( CTRLS_OFFSET, CTRLS_OFFSET ), MAP_APPFONT ) );
578 IconChoicePageData* pData = GetPageData ( nId );
580 if ( pData->pPage )
582 Size aOutSize ( GetOutputSizePixel() );
583 Size aIconCtrlSize ( maIconCtrl.GetSizePixel() );
585 Point aNewPagePos;
586 Size aNewPageSize;
587 switch ( meChoicePos )
589 case PosLeft :
590 aNewPagePos = Point ( aIconCtrlSize.Width() + (2*aCtrlOffset.X()),
591 aCtrlOffset.X() );
592 aNewPageSize = Size ( aOutSize.Width() - maIconCtrl.GetSizePixel().Width() -
593 (3*aCtrlOffset.X()),
594 aOutSize.Height() - aOKBtn.GetSizePixel().Height() -
595 (3*aCtrlOffset.X()) );
596 break;
597 case PosRight :
598 aNewPagePos = aCtrlOffset;
599 aNewPageSize = Size ( aOutSize.Width() - maIconCtrl.GetSizePixel().Width() -
600 (3*aCtrlOffset.X()),
601 aOutSize.Height() - aOKBtn.GetSizePixel().Height() -
602 (3*aCtrlOffset.X()) );
603 break;
604 case PosTop :
605 aNewPagePos = Point ( aCtrlOffset.X(), aIconCtrlSize.Height() +
606 (2*aCtrlOffset.X()) );
607 aNewPageSize = Size ( aOutSize.Width() - (2*aCtrlOffset.X()),
608 aOutSize.Height() - aOKBtn.GetSizePixel().Height() -
609 maIconCtrl.GetSizePixel().Height() - (4*aCtrlOffset.X()) );
610 break;
611 case PosBottom :
612 aNewPagePos = aCtrlOffset;
613 aNewPageSize = Size ( aOutSize.Width() - (2*aCtrlOffset.X()),
614 aOutSize.Height() - aOKBtn.GetSizePixel().Height() -
615 maIconCtrl.GetSizePixel().Height() - (4*aCtrlOffset.X()) );
616 break;
619 pData->pPage->SetPosSizePixel ( aNewPagePos, aNewPageSize );
623 /**********************************************************************
625 | select a page
627 \**********************************************************************/
629 IMPL_LINK_NOARG(IconChoiceDialog , ChosePageHdl_Impl)
631 sal_uLong nPos;
633 SvxIconChoiceCtrlEntry *pEntry = maIconCtrl.GetSelectedEntry ( nPos );
634 if ( !pEntry )
635 pEntry = maIconCtrl.GetCursor( );
637 sal_uInt16 *pId = (sal_uInt16*)pEntry->GetUserData ();
639 if( *pId != mnCurrentPageId )
641 IconChoicePageData* pData = GetPageData ( mnCurrentPageId );
642 if ( pData->pPage )
643 DeActivatePageImpl();
645 SetCurPageId ( *pId );
647 ActivatePageImpl();
648 Invalidate();
651 return 0L;
654 /**********************************************************************
656 | Button-handler
658 \**********************************************************************/
660 IMPL_LINK_NOARG(IconChoiceDialog, OkHdl)
662 bInOK = sal_True;
664 if ( OK_Impl() )
666 if ( bModal )
667 EndDialog( Ok() );
668 else
670 Ok();
671 Close();
674 return 0;
677 // -----------------------------------------------------------------------
679 IMPL_LINK_NOARG(IconChoiceDialog, ResetHdl)
681 ResetPageImpl ();
683 IconChoicePageData* pData = GetPageData ( mnCurrentPageId );
684 DBG_ASSERT( pData, "Id nicht bekannt" );
686 if ( pData->bOnDemand )
688 // CSet on AIS has problems here, therefore separated
689 const SfxItemSet* _pSet = &( pData->pPage->GetItemSet() );
690 pData->pPage->Reset( *(SfxItemSet*)_pSet );
692 else
693 pData->pPage->Reset( *pSet );
696 return 0;
699 // -----------------------------------------------------------------------
701 IMPL_LINK_NOARG(IconChoiceDialog, CancelHdl)
703 Close();
705 return 0;
708 /**********************************************************************
710 | call page
712 \**********************************************************************/
714 void IconChoiceDialog::ActivatePageImpl ()
716 DBG_ASSERT( !maPageList.empty(), "keine Pages angemeldet" );
717 IconChoicePageData* pData = GetPageData ( mnCurrentPageId );
718 DBG_ASSERT( pData, "Id nicht bekannt" );
719 bool bReadOnly = false;
720 if ( pData )
722 if ( !pData->pPage )
724 const SfxItemSet* pTmpSet = 0;
726 if ( pSet )
728 if ( bItemsReset && pSet->GetParent() )
729 pTmpSet = pSet->GetParent();
730 else
731 pTmpSet = pSet;
734 if ( pTmpSet && !pData->bOnDemand )
735 pData->pPage = (pData->fnCreatePage)( this, *pTmpSet );
736 else
737 pData->pPage = (pData->fnCreatePage)( this, *CreateInputItemSet( mnCurrentPageId ) );
739 SvtViewOptions aTabPageOpt( E_TABPAGE, OUString::number(pData->nId) );
740 pData->pPage->SetUserData( GetViewOptUserItem( aTabPageOpt ) );
741 SetPosSizePages ( pData->nId );
743 if ( pData->bOnDemand )
744 pData->pPage->Reset( (SfxItemSet &)pData->pPage->GetItemSet() );
745 else
746 pData->pPage->Reset( *pSet );
748 PageCreated( mnCurrentPageId, *pData->pPage );
750 else if ( pData->bRefresh )
752 pData->pPage->Reset( *pSet );
755 pData->bRefresh = sal_False;
757 if ( pExampleSet )
758 pData->pPage->ActivatePage( *pExampleSet );
759 SetHelpId( pData->pPage->GetHelpId() );
760 bReadOnly = pData->pPage->IsReadOnly();
764 if ( bReadOnly || bHideResetBtn )
765 aResetBtn.Hide();
766 else
767 aResetBtn.Show();
771 // -----------------------------------------------------------------------
773 sal_Bool IconChoiceDialog::DeActivatePageImpl ()
775 IconChoicePageData *pData = GetPageData ( mnCurrentPageId );
777 int nRet = IconChoicePage::LEAVE_PAGE;
779 if ( pData )
781 IconChoicePage * pPage = pData->pPage;
783 if ( !pExampleSet && pPage->HasExchangeSupport() && pSet )
784 pExampleSet = new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() );
786 if ( pSet )
788 SfxItemSet aTmp( *pSet->GetPool(), pSet->GetRanges() );
790 if ( pPage->HasExchangeSupport() )
791 nRet = pPage->DeactivatePage( &aTmp );
793 if ( ( IconChoicePage::LEAVE_PAGE & nRet ) == IconChoicePage::LEAVE_PAGE &&
794 aTmp.Count() )
796 pExampleSet->Put( aTmp );
797 pOutSet->Put( aTmp );
800 else
802 if ( pPage->HasExchangeSupport() ) //!!!
804 if ( !pExampleSet )
806 SfxItemPool* pPool = pPage->GetItemSet().GetPool();
807 pExampleSet =
808 new SfxItemSet( *pPool, GetInputRanges( *pPool ) );
810 nRet = pPage->DeactivatePage( pExampleSet );
812 else
813 nRet = pPage->DeactivatePage( NULL );
816 if ( nRet & IconChoicePage::REFRESH_SET )
818 pSet = GetRefreshedSet();
819 DBG_ASSERT( pSet, "GetRefreshedSet() liefert NULL" );
820 // flag all pages to be newly initialized
821 for ( size_t i = 0, nCount = maPageList.size(); i < nCount; ++i )
823 IconChoicePageData* pObj = maPageList[ i ];
824 if ( pObj->pPage != pPage )
825 pObj->bRefresh = sal_True;
826 else
827 pObj->bRefresh = sal_False;
832 if ( nRet & IconChoicePage::LEAVE_PAGE )
833 return sal_True;
834 else
835 return sal_False;
838 // -----------------------------------------------------------------------
840 void IconChoiceDialog::ResetPageImpl ()
842 IconChoicePageData *pData = GetPageData ( mnCurrentPageId );
844 DBG_ASSERT( pData, "Id nicht bekannt" );
846 if ( pData->bOnDemand )
848 // CSet on AIS has problems here, therefore separated
849 const SfxItemSet* _pSet = &pData->pPage->GetItemSet();
850 pData->pPage->Reset( *(SfxItemSet*)_pSet );
852 else
853 pData->pPage->Reset( *pSet );
856 /**********************************************************************
858 | handling itemsets
860 \**********************************************************************/
862 const sal_uInt16* IconChoiceDialog::GetInputRanges( const SfxItemPool& rPool )
864 if ( pSet )
866 SAL_WARN( "cui.dialogs", "Set does already exist!" );
867 return pSet->GetRanges();
870 if ( pRanges )
871 return pRanges;
872 std::vector<sal_uInt16> aUS;
874 size_t nCount = maPageList.size();
875 for ( size_t i = 0; i < nCount; ++i )
877 IconChoicePageData* pData = maPageList[ i ];
878 if ( pData->fnGetRanges )
880 const sal_uInt16* pTmpRanges = (pData->fnGetRanges)();
881 const sal_uInt16* pIter = pTmpRanges;
883 sal_uInt16 nLen;
884 for( nLen = 0; *pIter; ++nLen, ++pIter )
886 aUS.insert( aUS.end(), pTmpRanges, pTmpRanges + nLen );
890 // remove double Id's
892 nCount = aUS.size();
893 for ( size_t i = 0; i < nCount; ++i )
894 aUS[i] = rPool.GetWhich( aUS[i] );
897 if ( aUS.size() > 1 )
899 std::sort( aUS.begin(), aUS.end() );
902 pRanges = new sal_uInt16[aUS.size() + 1];
903 std::copy( aUS.begin(), aUS.end(), pRanges );
904 pRanges[aUS.size()] = 0;
906 return pRanges;
909 // -----------------------------------------------------------------------
911 void IconChoiceDialog::SetInputSet( const SfxItemSet* pInSet )
913 bool bSet = ( pSet != NULL );
915 pSet = pInSet;
917 if ( !bSet && !pExampleSet && !pOutSet )
919 pExampleSet = new SfxItemSet( *pSet );
920 pOutSet = new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() );
924 // -----------------------------------------------------------------------
926 void IconChoiceDialog::PageCreated( sal_uInt16 /*nId*/, IconChoicePage& /*rPage*/ )
928 // not interested in
931 // -----------------------------------------------------------------------
933 SfxItemSet* IconChoiceDialog::CreateInputItemSet( sal_uInt16 )
935 SAL_INFO( "cui.dialogs", "CreateInputItemSet not implemented" );
937 return 0;
940 /**********************************************************************
942 | start dialog
944 \**********************************************************************/
946 short IconChoiceDialog::Execute()
948 if ( maPageList.empty() )
949 return RET_CANCEL;
951 Start_Impl();
953 return Dialog::Execute();
956 // -----------------------------------------------------------------------
958 void IconChoiceDialog::Start( sal_Bool bShow )
961 aCancelBtn.SetClickHdl( LINK( this, IconChoiceDialog, CancelHdl ) );
962 bModal = sal_False;
964 Start_Impl();
966 if ( bShow )
967 Window::Show();
971 // -----------------------------------------------------------------------
973 sal_Bool IconChoiceDialog::QueryClose()
975 sal_Bool bRet = sal_True;
976 for ( size_t i = 0, nCount = maPageList.size(); i < nCount; ++i )
978 IconChoicePageData* pData = maPageList[i ];
979 if ( pData->pPage && !pData->pPage->QueryClose() )
981 bRet = sal_False;
982 break;
985 return bRet;
988 // -----------------------------------------------------------------------
990 void IconChoiceDialog::Start_Impl()
992 sal_uInt16 nActPage;
994 if ( mnCurrentPageId == 0 || mnCurrentPageId == USHRT_MAX )
995 nActPage = maPageList.front()->nId;
996 else
997 nActPage = mnCurrentPageId;
999 // configuration existing?
1000 SvtViewOptions aTabDlgOpt( E_TABDIALOG, OUString::number(nResId) );
1002 if ( aTabDlgOpt.Exists() )
1004 // possibly position from config
1005 SetWindowState(OUStringToOString(aTabDlgOpt.GetWindowState().getStr(), RTL_TEXTENCODING_ASCII_US));
1007 // initial TabPage from program/help/config
1008 nActPage = (sal_uInt16)aTabDlgOpt.GetPageID();
1010 if ( USHRT_MAX != mnCurrentPageId )
1011 nActPage = mnCurrentPageId;
1013 if ( GetPageData ( nActPage ) == NULL )
1014 nActPage = maPageList.front()->nId;
1016 else if ( USHRT_MAX != mnCurrentPageId && GetPageData ( mnCurrentPageId ) != NULL )
1017 nActPage = mnCurrentPageId;
1019 mnCurrentPageId = nActPage;
1021 FocusOnIcon( mnCurrentPageId );
1023 ActivatePageImpl();
1026 // -----------------------------------------------------------------------
1028 const SfxItemSet* IconChoiceDialog::GetRefreshedSet()
1030 SAL_WARN( "cui.dialogs", "GetRefreshedSet not implemented" );
1031 return 0;
1034 /**********************************************************************
1036 | tool-methods
1038 \**********************************************************************/
1040 IconChoicePageData* IconChoiceDialog::GetPageData ( sal_uInt16 nId )
1042 IconChoicePageData *pRet = NULL;
1043 for ( size_t i=0; i < maPageList.size(); i++ )
1045 IconChoicePageData* pData = maPageList[ i ];
1046 if ( pData->nId == nId )
1048 pRet = pData;
1049 break;
1052 return pRet;
1055 /**********************************************************************
1057 | OK-Status
1059 \**********************************************************************/
1061 sal_Bool IconChoiceDialog::OK_Impl()
1063 IconChoicePage* pPage = GetPageData ( mnCurrentPageId )->pPage;
1065 bool bEnd = !pPage;
1066 if ( pPage )
1068 int nRet = IconChoicePage::LEAVE_PAGE;
1069 if ( pSet )
1071 SfxItemSet aTmp( *pSet->GetPool(), pSet->GetRanges() );
1072 sal_Bool bRet = sal_False;
1074 if ( pPage->HasExchangeSupport() )
1075 nRet = pPage->DeactivatePage( &aTmp );
1077 if ( ( IconChoicePage::LEAVE_PAGE & nRet ) == IconChoicePage::LEAVE_PAGE
1078 && aTmp.Count() )
1080 pExampleSet->Put( aTmp );
1081 pOutSet->Put( aTmp );
1083 else if ( bRet )
1084 bModified |= sal_True;
1086 else
1087 nRet = pPage->DeactivatePage( NULL );
1088 bEnd = nRet;
1091 return bEnd;
1094 // -----------------------------------------------------------------------
1096 short IconChoiceDialog::Ok()
1098 bInOK = sal_True;
1100 if ( !pOutSet )
1102 if ( !pExampleSet && pSet )
1103 pOutSet = pSet->Clone( sal_False ); // without items
1104 else if ( pExampleSet )
1105 pOutSet = new SfxItemSet( *pExampleSet );
1107 sal_Bool _bModified = sal_False;
1109 for ( size_t i = 0, nCount = maPageList.size(); i < nCount; ++i )
1111 IconChoicePageData* pData = GetPageData ( i );
1113 IconChoicePage* pPage = pData->pPage;
1115 if ( pPage )
1117 if ( pData->bOnDemand )
1119 SfxItemSet& rSet = (SfxItemSet&)pPage->GetItemSet();
1120 rSet.ClearItem();
1121 _bModified |= pPage->FillItemSet( rSet );
1123 else if ( pSet && !pPage->HasExchangeSupport() )
1125 SfxItemSet aTmp( *pSet->GetPool(), pSet->GetRanges() );
1127 if ( pPage->FillItemSet( aTmp ) )
1129 _bModified |= sal_True;
1130 pExampleSet->Put( aTmp );
1131 pOutSet->Put( aTmp );
1137 if ( _bModified || ( pOutSet && pOutSet->Count() > 0 ) )
1138 _bModified |= sal_True;
1140 return _bModified ? RET_OK : RET_CANCEL;
1143 // -----------------------------------------------------------------------
1145 void IconChoiceDialog::FocusOnIcon( sal_uInt16 nId )
1147 // set focus to icon for the current visible page
1148 for ( sal_uInt16 i=0; i<maIconCtrl.GetEntryCount(); i++)
1150 SvxIconChoiceCtrlEntry* pEntry = maIconCtrl.GetEntry ( i );
1151 sal_uInt16* pUserData = (sal_uInt16*) pEntry->GetUserData();
1153 if ( pUserData && *pUserData == nId )
1155 maIconCtrl.SetCursor( pEntry );
1156 break;
1162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */