1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
22 #include <tools/shl.hxx>
24 #include <dialmgr.hxx>
26 #include "iconcdlg.hxx"
30 #include <unotools/viewoptions.hxx>
31 #include <svtools/apearcfg.hxx>
32 #include <vcl/mnemonic.hxx>
33 #include <vcl/i18nhelp.hxx>
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
) );
52 return String( aUserData
);
56 //#####################################################################
58 // Class IconChoicePage
60 //#####################################################################
62 /**********************************************************************
66 \**********************************************************************/
68 IconChoicePage::IconChoicePage( Window
*pParent
, const ResId
&rResId
,
69 const SfxItemSet
&rAttrSet
)
70 : TabPage ( pParent
, rResId
),
72 bHasExchangeSupport ( sal_False
),
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
* )
101 /**********************************************************************
105 \**********************************************************************/
107 void IconChoicePage::FillUserData()
111 // -----------------------------------------------------------------------
113 sal_Bool
IconChoicePage::IsReadOnly() const
118 // -----------------------------------------------------------------------
120 sal_Bool
IconChoicePage::QueryClose()
125 /**********************************************************************
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
);
143 EnableChildTransparentMode( sal_False
);
144 SetParentClipMode( 0 );
145 SetPaintTransparent( sal_False
);
147 if ( IsControlBackground() )
148 SetBackground( GetControlBackground() );
150 SetBackground( pParent
->GetBackground() );
154 // -----------------------------------------------------------------------
156 void IconChoicePage::StateChanged( StateChangedType nType
)
158 Window::StateChanged( nType
);
160 if ( nType
== STATE_CHANGE_CONTROLBACKGROUND
)
167 // -----------------------------------------------------------------------
169 void IconChoicePage::DataChanged( const DataChangedEvent
& rDCEvt
)
171 Window::DataChanged( rDCEvt
);
173 if ( (rDCEvt
.GetType() == DATACHANGED_SETTINGS
) &&
174 (rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
181 //#####################################################################
183 // Class IconChoiceDialog
185 //#####################################################################
187 /**********************************************************************
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
),
209 pExampleSet ( NULL
),
211 nResId ( rResId
.GetId() ),
213 bHideResetBtn ( sal_False
),
214 bModal ( 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
) );
224 maIconCtrl
.SetChoiceWithCursor ( sal_True
);
225 maIconCtrl
.SetSelectionMode( SINGLE_SELECTION
);
226 maIconCtrl
.SetHelpId( HID_ICCDIALOG_CHOICECTRL
);
231 pExampleSet
= new SfxItemSet( *pSet
);
232 pOutSet
= new SfxItemSet( *pSet
->GetPool(), pSet
->GetRanges() );
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
);
247 SetPosSizeCtrls ( sal_True
);
250 // -----------------------------------------------------------------------
252 IconChoiceDialog ::~IconChoiceDialog ()
254 // save configuration at INI-Manager
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
];
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();
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();
297 /**********************************************************************
301 \**********************************************************************/
303 SvxIconChoiceCtrlEntry
* IconChoiceDialog::AddTabPage(
305 const String
& rIconText
,
306 const Image
& rChoiceIcon
,
307 CreatePage pCreateFunc
/* != 0 */,
308 GetPageRanges pRangesFunc
/* darf 0 sein */,
309 sal_Bool bItemsOnDemand
,
313 IconChoicePageData
* pData
= new IconChoicePageData ( nId
, pCreateFunc
,
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
);
327 /**********************************************************************
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
);
347 HidePageImpl ( pData
);
352 EIconChoicePos
IconChoiceDialog::SetCtrlPos( const EIconChoicePos
& rPos
)
354 WinBits aWinBits
= maIconCtrl
.GetStyle ();
356 switch ( meChoicePos
)
359 aWinBits
&= ~WB_ALIGN_TOP
& ~WB_NOVSCROLL
;
360 aWinBits
|= WB_ALIGN_LEFT
| WB_NOHSCROLL
;
363 aWinBits
&= ~WB_ALIGN_TOP
& ~WB_NOVSCROLL
;
364 aWinBits
|= WB_ALIGN_LEFT
| WB_NOHSCROLL
;
367 aWinBits
&= ~WB_ALIGN_LEFT
& ~WB_NOHSCROLL
;
368 aWinBits
|= WB_ALIGN_TOP
| WB_NOVSCROLL
;
371 aWinBits
&= ~WB_ALIGN_LEFT
& ~WB_NOHSCROLL
;
372 aWinBits
|= WB_ALIGN_TOP
| WB_NOVSCROLL
;
375 maIconCtrl
.SetStyle ( aWinBits
);
380 EIconChoicePos eOldPos
= meChoicePos
;
386 /**********************************************************************
388 | Show / Hide page or button
390 \**********************************************************************/
392 void IconChoiceDialog::ShowPageImpl ( IconChoicePageData
* pData
)
395 pData
->pPage
->Show();
398 // -----------------------------------------------------------------------
400 void IconChoiceDialog::HidePageImpl ( IconChoicePageData
* pData
)
403 pData
->pPage
->Hide();
406 // -----------------------------------------------------------------------
408 void IconChoiceDialog::ShowPage( sal_uInt16 nId
)
410 bool bInvalidate
= GetCurPageId() != nId
;
417 /**********************************************************************
421 \**********************************************************************/
423 #define ICONCTRL_WIDTH_PIXEL 110
424 #define ICONCTRL_HEIGHT_PIXEL 75
426 void IconChoiceDialog::Resize()
430 if ( IsReallyVisible() )
436 void IconChoiceDialog::SetPosSizeCtrls ( sal_Bool bInit
)
438 const Point
aCtrlOffset ( LogicToPixel( Point( CTRLS_OFFSET
, CTRLS_OFFSET
), MAP_APPFONT
) );
439 Size
aOutSize ( GetOutputSizePixel() );
441 ////////////////////////////////////////
444 Size aDefaultButtonSize
= LogicToPixel( Size( 50, 14 ), MAP_APPFONT
);
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()) );
460 switch ( meChoicePos
)
463 aIconCtrlPos
= aCtrlOffset
;
464 aNewIconCtrlSize
= Size ( nDefaultWidth
,
465 aOutSize
.Height()-(2*aCtrlOffset
.X()) );
468 aIconCtrlPos
= Point ( aOutSize
.Width() - nDefaultWidth
-
469 aCtrlOffset
.X(), aCtrlOffset
.X() );
470 aNewIconCtrlSize
= Size ( nDefaultWidth
,
471 aOutSize
.Height()-(2*aCtrlOffset
.X()) );
474 aIconCtrlPos
= aCtrlOffset
;
475 aNewIconCtrlSize
= Size ( aOutSize
.Width()-(2*aCtrlOffset
.X()),
479 aIconCtrlPos
= Point ( aCtrlOffset
.X(), aOutSize
.Height() -
480 aResetButtonSize
.Height() - (2*aCtrlOffset
.X()) -
482 aNewIconCtrlSize
= Size ( aOutSize
.Width()-(2*aCtrlOffset
.X()),
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
];
498 switch ( meChoicePos
)
501 aNewPagePos
= Point ( aNewIconCtrlSize
.Width() + (2*CTRLS_OFFSET
),
503 aNewPageSize
= Size ( aOutSize
.Width() - aNewIconCtrlSize
.Width() -
505 aOutSize
.Height() - aOKBtn
.GetSizePixel().Height() -
509 aNewPagePos
= aCtrlOffset
;
510 aNewPageSize
= Size ( aOutSize
.Width() - aNewIconCtrlSize
.Width() -
512 aOutSize
.Height() - aOKBtn
.GetSizePixel().Height() -
513 (3*aCtrlOffset
.X()) );
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()) );
523 aNewPagePos
= aCtrlOffset
;
524 aNewPageSize
= Size ( aOutSize
.Width() - (2*aCtrlOffset
.X()),
525 aOutSize
.Height() - aOKBtn
.GetSizePixel().Height() -
526 aNewIconCtrlSize
.Height() - (4*aCtrlOffset
.X()) );
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()-
547 Size
aHelpButtonSize ( bInit
? aDefaultButtonSize
:
548 aHelpBtn
.GetSizePixel () );
549 aHelpBtn
.SetPosSizePixel ( Point( aOutSize
.Width()-aResetButtonSize
.Width()-
550 aHelpButtonSize
.Width()- nXOffset
-
552 aOutSize
.Height()-aHelpButtonSize
.Height()-
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()-
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() ),
575 void IconChoiceDialog::SetPosSizePages ( sal_uInt16 nId
)
577 const Point
aCtrlOffset ( LogicToPixel( Point( CTRLS_OFFSET
, CTRLS_OFFSET
), MAP_APPFONT
) );
578 IconChoicePageData
* pData
= GetPageData ( nId
);
582 Size
aOutSize ( GetOutputSizePixel() );
583 Size
aIconCtrlSize ( maIconCtrl
.GetSizePixel() );
587 switch ( meChoicePos
)
590 aNewPagePos
= Point ( aIconCtrlSize
.Width() + (2*aCtrlOffset
.X()),
592 aNewPageSize
= Size ( aOutSize
.Width() - maIconCtrl
.GetSizePixel().Width() -
594 aOutSize
.Height() - aOKBtn
.GetSizePixel().Height() -
595 (3*aCtrlOffset
.X()) );
598 aNewPagePos
= aCtrlOffset
;
599 aNewPageSize
= Size ( aOutSize
.Width() - maIconCtrl
.GetSizePixel().Width() -
601 aOutSize
.Height() - aOKBtn
.GetSizePixel().Height() -
602 (3*aCtrlOffset
.X()) );
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()) );
612 aNewPagePos
= aCtrlOffset
;
613 aNewPageSize
= Size ( aOutSize
.Width() - (2*aCtrlOffset
.X()),
614 aOutSize
.Height() - aOKBtn
.GetSizePixel().Height() -
615 maIconCtrl
.GetSizePixel().Height() - (4*aCtrlOffset
.X()) );
619 pData
->pPage
->SetPosSizePixel ( aNewPagePos
, aNewPageSize
);
623 /**********************************************************************
627 \**********************************************************************/
629 IMPL_LINK_NOARG(IconChoiceDialog
, ChosePageHdl_Impl
)
633 SvxIconChoiceCtrlEntry
*pEntry
= maIconCtrl
.GetSelectedEntry ( nPos
);
635 pEntry
= maIconCtrl
.GetCursor( );
637 sal_uInt16
*pId
= (sal_uInt16
*)pEntry
->GetUserData ();
639 if( *pId
!= mnCurrentPageId
)
641 IconChoicePageData
* pData
= GetPageData ( mnCurrentPageId
);
643 DeActivatePageImpl();
645 SetCurPageId ( *pId
);
654 /**********************************************************************
658 \**********************************************************************/
660 IMPL_LINK_NOARG(IconChoiceDialog
, OkHdl
)
677 // -----------------------------------------------------------------------
679 IMPL_LINK_NOARG(IconChoiceDialog
, ResetHdl
)
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
);
693 pData
->pPage
->Reset( *pSet
);
699 // -----------------------------------------------------------------------
701 IMPL_LINK_NOARG(IconChoiceDialog
, CancelHdl
)
708 /**********************************************************************
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;
724 const SfxItemSet
* pTmpSet
= 0;
728 if ( bItemsReset
&& pSet
->GetParent() )
729 pTmpSet
= pSet
->GetParent();
734 if ( pTmpSet
&& !pData
->bOnDemand
)
735 pData
->pPage
= (pData
->fnCreatePage
)( this, *pTmpSet
);
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() );
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
;
758 pData
->pPage
->ActivatePage( *pExampleSet
);
759 SetHelpId( pData
->pPage
->GetHelpId() );
760 bReadOnly
= pData
->pPage
->IsReadOnly();
764 if ( bReadOnly
|| bHideResetBtn
)
771 // -----------------------------------------------------------------------
773 sal_Bool
IconChoiceDialog::DeActivatePageImpl ()
775 IconChoicePageData
*pData
= GetPageData ( mnCurrentPageId
);
777 int nRet
= IconChoicePage::LEAVE_PAGE
;
781 IconChoicePage
* pPage
= pData
->pPage
;
783 if ( !pExampleSet
&& pPage
->HasExchangeSupport() && pSet
)
784 pExampleSet
= new SfxItemSet( *pSet
->GetPool(), pSet
->GetRanges() );
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
&&
796 pExampleSet
->Put( aTmp
);
797 pOutSet
->Put( aTmp
);
802 if ( pPage
->HasExchangeSupport() ) //!!!
806 SfxItemPool
* pPool
= pPage
->GetItemSet().GetPool();
808 new SfxItemSet( *pPool
, GetInputRanges( *pPool
) );
810 nRet
= pPage
->DeactivatePage( pExampleSet
);
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
;
827 pObj
->bRefresh
= sal_False
;
832 if ( nRet
& IconChoicePage::LEAVE_PAGE
)
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
);
853 pData
->pPage
->Reset( *pSet
);
856 /**********************************************************************
860 \**********************************************************************/
862 const sal_uInt16
* IconChoiceDialog::GetInputRanges( const SfxItemPool
& rPool
)
866 SAL_WARN( "cui.dialogs", "Set does already exist!" );
867 return pSet
->GetRanges();
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
;
884 for( nLen
= 0; *pIter
; ++nLen
, ++pIter
)
886 aUS
.insert( aUS
.end(), pTmpRanges
, pTmpRanges
+ nLen
);
890 // remove double Id's
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;
909 // -----------------------------------------------------------------------
911 void IconChoiceDialog::SetInputSet( const SfxItemSet
* pInSet
)
913 bool bSet
= ( pSet
!= NULL
);
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*/ )
931 // -----------------------------------------------------------------------
933 SfxItemSet
* IconChoiceDialog::CreateInputItemSet( sal_uInt16
)
935 SAL_INFO( "cui.dialogs", "CreateInputItemSet not implemented" );
940 /**********************************************************************
944 \**********************************************************************/
946 short IconChoiceDialog::Execute()
948 if ( maPageList
.empty() )
953 return Dialog::Execute();
956 // -----------------------------------------------------------------------
958 void IconChoiceDialog::Start( sal_Bool bShow
)
961 aCancelBtn
.SetClickHdl( LINK( this, IconChoiceDialog
, CancelHdl
) );
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() )
988 // -----------------------------------------------------------------------
990 void IconChoiceDialog::Start_Impl()
994 if ( mnCurrentPageId
== 0 || mnCurrentPageId
== USHRT_MAX
)
995 nActPage
= maPageList
.front()->nId
;
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
);
1026 // -----------------------------------------------------------------------
1028 const SfxItemSet
* IconChoiceDialog::GetRefreshedSet()
1030 SAL_WARN( "cui.dialogs", "GetRefreshedSet not implemented" );
1034 /**********************************************************************
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
)
1055 /**********************************************************************
1059 \**********************************************************************/
1061 sal_Bool
IconChoiceDialog::OK_Impl()
1063 IconChoicePage
* pPage
= GetPageData ( mnCurrentPageId
)->pPage
;
1068 int nRet
= IconChoicePage::LEAVE_PAGE
;
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
1080 pExampleSet
->Put( aTmp
);
1081 pOutSet
->Put( aTmp
);
1084 bModified
|= sal_True
;
1087 nRet
= pPage
->DeactivatePage( NULL
);
1094 // -----------------------------------------------------------------------
1096 short IconChoiceDialog::Ok()
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
;
1117 if ( pData
->bOnDemand
)
1119 SfxItemSet
& rSet
= (SfxItemSet
&)pPage
->GetItemSet();
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
);
1162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */