1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: iconcdlg.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
37 #include <sfx2/app.hxx>
39 #include <tools/shl.hxx>
41 #define _SVSTDARR_USHORTS
42 #include <svtools/svstdarr.hxx>
43 #include <svx/dialmgr.hxx>
45 #include "iconcdlg.hxx"
47 #ifndef _SVX_HELPID_HRC
50 #ifndef _SVX_DIALOGS_HRC
51 #include <svx/dialogs.hrc>
53 #include <svtools/viewoptions.hxx>
54 #include <svtools/apearcfg.hxx>
55 #include <vcl/mnemonic.hxx>
56 #include <vcl/i18nhelp.hxx>
59 int __cdecl
IconcDlgCmpUS_Impl( const void* p1
, const void* p2
)
61 #if defined(OS2) && defined(ICC)
62 int _Optlink
IconcDlgCmpUS_Impl( const void* p1
, const void* p2
)
64 int IconcDlgCmpUS_Impl( const void* p1
, const void* p2
)
68 return *(USHORT
*)p1
- *(USHORT
*)p2
;
71 // some stuff for easier changes for SvtViewOptions
72 static const sal_Char
* pViewOptDataName
= "dialog data";
73 #define VIEWOPT_DATANAME ::rtl::OUString::createFromAscii( pViewOptDataName )
75 static inline void SetViewOptUserItem( SvtViewOptions
& rOpt
, const String
& rData
)
77 rOpt
.SetUserItem( VIEWOPT_DATANAME
, ::com::sun::star::uno::makeAny( ::rtl::OUString( rData
) ) );
80 static inline String
GetViewOptUserItem( const SvtViewOptions
& rOpt
)
82 ::com::sun::star::uno::Any
aAny( rOpt
.GetUserItem( VIEWOPT_DATANAME
) );
83 ::rtl::OUString aUserData
;
86 return String( aUserData
);
90 //#####################################################################
92 // Class IconChoicePage
94 //#####################################################################
96 /**********************************************************************
100 \**********************************************************************/
102 IconChoicePage::IconChoicePage( Window
*pParent
, const ResId
&rResId
,
103 const SfxItemSet
&rAttrSet
)
104 : TabPage ( pParent
, rResId
),
106 bHasExchangeSupport ( FALSE
),
110 SetStyle ( GetStyle() | WB_DIALOGCONTROL
| WB_HIDE
);
113 // -----------------------------------------------------------------------
115 IconChoicePage::~IconChoicePage()
119 /**********************************************************************
121 | Activate / Deaktivate
123 \**********************************************************************/
125 void IconChoicePage::ActivatePage( const SfxItemSet
& )
129 // -----------------------------------------------------------------------
131 int IconChoicePage::DeactivatePage( SfxItemSet
* )
136 /**********************************************************************
140 \**********************************************************************/
142 void IconChoicePage::FillUserData()
146 // -----------------------------------------------------------------------
148 BOOL
IconChoicePage::IsReadOnly() const
153 // -----------------------------------------------------------------------
155 sal_Bool
IconChoicePage::QueryClose()
160 /**********************************************************************
164 \**********************************************************************/
166 const SfxPoolItem
* IconChoicePage::GetItem( const SfxItemSet
& rSet
,
169 const SfxItemPool
* pPool
= rSet
.GetPool();
170 USHORT nWh
= pPool
->GetWhich( nSlot
);
171 const SfxPoolItem
* pItem
= 0;
172 rSet
.GetItemState( nWh
, TRUE
, &pItem
);
174 if ( !pItem
&& nWh
!= nSlot
)
175 pItem
= &pPool
->GetDefaultItem( nWh
);
180 // -----------------------------------------------------------------------
182 const SfxPoolItem
* IconChoicePage::GetOldItem( const SfxItemSet
& rSet
,
185 const SfxItemSet
& rOldSet
= GetItemSet();
186 USHORT nWh
= GetWhich( nSlot
);
187 const SfxPoolItem
* pItem
= 0;
189 if ( bStandard
&& rOldSet
.GetParent() )
190 pItem
= GetItem( *rOldSet
.GetParent(), nSlot
);
191 else if ( rSet
.GetParent() && SFX_ITEM_DONTCARE
== rSet
.GetItemState( nWh
) )
192 pItem
= GetItem( *rSet
.GetParent(), nSlot
);
194 pItem
= GetItem( rOldSet
, nSlot
);
199 // -----------------------------------------------------------------------
201 const SfxPoolItem
* IconChoicePage::GetExchangeItem( const SfxItemSet
& rSet
,
204 if ( pDialog
&& !pDialog
->IsInOK() && pDialog
->GetExampleSet() )
205 return GetItem( *pDialog
->GetExampleSet(), nSlot
);
207 return GetOldItem( rSet
, nSlot
);
210 /**********************************************************************
214 \**********************************************************************/
216 void IconChoicePage::ImplInitSettings()
218 Window
* pParent
= GetParent();
219 if ( pParent
->IsChildTransparentModeEnabled() && !IsControlBackground() )
221 EnableChildTransparentMode( TRUE
);
222 SetParentClipMode( PARENTCLIPMODE_NOCLIP
);
223 SetPaintTransparent( TRUE
);
228 EnableChildTransparentMode( FALSE
);
229 SetParentClipMode( 0 );
230 SetPaintTransparent( FALSE
);
232 if ( IsControlBackground() )
233 SetBackground( GetControlBackground() );
235 SetBackground( pParent
->GetBackground() );
239 // -----------------------------------------------------------------------
241 void IconChoicePage::StateChanged( StateChangedType nType
)
243 Window::StateChanged( nType
);
245 if ( nType
== STATE_CHANGE_CONTROLBACKGROUND
)
252 // -----------------------------------------------------------------------
254 void IconChoicePage::DataChanged( const DataChangedEvent
& rDCEvt
)
256 Window::DataChanged( rDCEvt
);
258 if ( (rDCEvt
.GetType() == DATACHANGED_SETTINGS
) &&
259 (rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
266 //#####################################################################
268 // Class IconChoiceDialog
270 //#####################################################################
272 /**********************************************************************
276 \**********************************************************************/
278 IconChoiceDialog::IconChoiceDialog ( Window
* pParent
, const ResId
&rResId
,
279 const EIconChoicePos ePos
,
280 const SfxItemSet
*pItemSet
)//, BOOL bEditFmt, const String *pUserButtonText = 0 )
281 : ModalDialog ( pParent
, rResId
),
282 meChoicePos ( ePos
),
283 maIconCtrl ( this, WB_3DLOOK
| WB_ICON
| WB_BORDER
|
284 WB_NOCOLUMNHEADER
| WB_HIGHLIGHTFRAME
|
285 /* WB_NOSELECTION | */ WB_NODRAGSELECTION
| WB_TABSTOP
),
286 mnCurrentPageId ( USHRT_MAX
),
288 aOKBtn ( this, WB_DEFBUTTON
),
289 aCancelBtn ( this, WB_DEFBUTTON
),
294 pExampleSet ( NULL
),
296 nResId ( rResId
.GetId() ),
298 bHideResetBtn ( FALSE
),
302 bItemsReset ( FALSE
)
304 // IconChoiceCtrl-Settings
305 //maIconCtrl.SetBackground ( Wallpaper( Color (146, 146, 186) ) );
307 maIconCtrl
.SetStyle (WB_3DLOOK
| WB_ICON
| WB_BORDER
| WB_NOCOLUMNHEADER
| WB_HIGHLIGHTFRAME
| /* WB_NOSELECTION | */ WB_NODRAGSELECTION
| WB_TABSTOP
| WB_CLIPCHILDREN
);
308 SetCtrlPos ( meChoicePos
);
309 maIconCtrl
.SetClickHdl ( LINK ( this, IconChoiceDialog
, ChosePageHdl_Impl
) );
311 maIconCtrl
.SetChoiceWithCursor ( TRUE
);
312 maIconCtrl
.SetSelectionMode( SINGLE_SELECTION
);
313 maIconCtrl
.SetHelpId( HID_ICCDIALOG_CHOICECTRL
);
318 pExampleSet
= new SfxItemSet( *pSet
);
319 pOutSet
= new SfxItemSet( *pSet
->GetPool(), pSet
->GetRanges() );
323 aOKBtn
.SetClickHdl ( LINK( this, IconChoiceDialog
, OkHdl
) );
324 aOKBtn
.SetHelpId( HID_ICCDIALOG_OK_BTN
);
325 aCancelBtn
.SetHelpId( HID_ICCDIALOG_CANCEL_BTN
);
326 aResetBtn
.SetClickHdl( LINK( this, IconChoiceDialog
, ResetHdl
) );
327 aResetBtn
.SetText( SVX_RESSTR(RID_SVXSTR_ICONCHOICEDLG_RESETBUT
) );
328 aResetBtn
.SetHelpId( HID_ICCDIALOG_RESET_BTN
);
334 SetPosSizeCtrls ( TRUE
);
337 // -----------------------------------------------------------------------
340 IconChoiceDialog ::IconChoiceDialog ( SfxViewFrame *pViewFrame, Window* pParent, const ResId &rResId,
341 const SfxItemSet * = 0, BOOL bEditFmt = FALSE,
342 const String *pUserButtonText = 0 )
343 : meChoicePos ( PosLeft ), // Default erst ma Links
344 maIconCtrl ( this, Die_Winbits ),
346 pUserBtn ( pUserButtonText? new PushButton(this): 0 ),
350 aBaseFmtBtn ( this ),
351 mnCurrentPageId ( 0 )
357 // -----------------------------------------------------------------------
359 IconChoiceDialog ::~IconChoiceDialog ()
363 // save configuration at INI-Manager
365 SvtViewOptions
aTabDlgOpt( E_TABDIALOG
, String::CreateFromInt32( nResId
) );
366 aTabDlgOpt
.SetWindowState( ::rtl::OUString::createFromAscii( GetWindowState((WINDOWSTATE_MASK_X
| WINDOWSTATE_MASK_Y
| WINDOWSTATE_MASK_STATE
| WINDOWSTATE_MASK_MINIMIZED
)).GetBuffer() ) );
367 aTabDlgOpt
.SetPageID( mnCurrentPageId
);
369 const ULONG nCount
= maPageList
.Count();
371 for ( i
= 0; i
< nCount
; ++i
)
373 IconChoicePageData
* pData
= maPageList
.GetObject(i
);
377 pData
->pPage
->FillUserData();
378 String
aPageData(pData
->pPage
->GetUserData());
379 if ( aPageData
.Len() )
381 SvtViewOptions
aTabPageOpt( E_TABPAGE
, String::CreateFromInt32( pData
->nId
) );
383 SetViewOptUserItem( aTabPageOpt
, aPageData
);
386 if ( pData
->bOnDemand
)
387 delete (SfxItemSet
*)&pData
->pPage
->GetItemSet();
394 /* for ( i=0; i<maPageList.Count(); i++ )
396 IconChoicePageData* pData = (IconChoicePageData*)maPageList.GetObject ( i );
398 if ( pData->bOnDemand )
399 delete ( SfxItemSet * )&( pData->pPage->GetItemSet() );
405 // remove Userdata from Icons
406 for ( i
=0; i
<maIconCtrl
.GetEntryCount(); i
++)
408 SvxIconChoiceCtrlEntry
* pEntry
= maIconCtrl
.GetEntry ( i
);
409 USHORT
* pUserData
= (USHORT
*) pEntry
->GetUserData();
420 /**********************************************************************
424 \**********************************************************************/
426 SvxIconChoiceCtrlEntry
* IconChoiceDialog::AddTabPage( USHORT nId
, const String
& rIconText
,
427 const Image
& rChoiceIcon
,
428 CreatePage pCreateFunc
/* != 0 */,
429 GetPageRanges pRangesFunc
/* darf 0 sein */,
430 BOOL bItemsOnDemand
, ULONG
/*nPos*/ )
432 IconChoicePageData
* pData
= new IconChoicePageData ( nId
, pCreateFunc
,
435 maPageList
.Insert ( pData
, LIST_APPEND
);
437 pData
->fnGetRanges
= pRangesFunc
;
438 pData
->bOnDemand
= bItemsOnDemand
;
440 USHORT
*pId
= new USHORT ( nId
);
441 SvxIconChoiceCtrlEntry
* pEntry
= maIconCtrl
.InsertEntry( rIconText
, rChoiceIcon
);
442 pEntry
->SetUserData ( (void*) pId
);
446 SvxIconChoiceCtrlEntry
* IconChoiceDialog::AddTabPage( USHORT nId
, const String
& rIconText
,
447 const Image
& rChoiceIcon
,
448 const Image
& rChoiceIconHC
,
449 CreatePage pCreateFunc
/* != 0 */,
450 GetPageRanges pRangesFunc
/* darf 0 sein */,
451 BOOL bItemsOnDemand
, ULONG
/*nPos*/ )
453 IconChoicePageData
* pData
= new IconChoicePageData ( nId
, pCreateFunc
,
456 maPageList
.Insert ( pData
, LIST_APPEND
);
458 pData
->fnGetRanges
= pRangesFunc
;
459 pData
->bOnDemand
= bItemsOnDemand
;
461 USHORT
*pId
= new USHORT ( nId
);
462 SvxIconChoiceCtrlEntry
* pEntry
= maIconCtrl
.InsertEntry( rIconText
, rChoiceIcon
, rChoiceIconHC
);
463 pEntry
->SetUserData ( (void*) pId
);
467 /**********************************************************************
471 \**********************************************************************/
473 void IconChoiceDialog::RemoveTabPage( USHORT nId
)
475 IconChoicePageData
* pData
= GetPageData ( nId
);
477 // remove page from list
480 maPageList
.Remove ( pData
);
485 pData
->pPage
->FillUserData();
486 String
aPageData(pData
->pPage
->GetUserData());
487 if ( aPageData
.Len() )
489 SvtViewOptions
aTabPageOpt( E_TABPAGE
, String::CreateFromInt32( pData
->nId
) );
491 SetViewOptUserItem( aTabPageOpt
, aPageData
);
495 if ( pData
->bOnDemand
)
496 delete ( SfxItemSet
* )&( pData
->pPage
->GetItemSet() );
504 for ( ULONG i
=0; i
<maIconCtrl
.GetEntryCount() && !bFound
; i
++)
506 SvxIconChoiceCtrlEntry
* pEntry
= maIconCtrl
.GetEntry ( i
);
507 USHORT
* pUserData
= (USHORT
*) pEntry
->GetUserData();
509 if ( *pUserData
== nId
)
512 maIconCtrl
.RemoveEntry ( pEntry
);
517 // was it the current page ?
518 if ( nId
== mnCurrentPageId
)
520 mnCurrentPageId
= maPageList
.First()->nId
;
526 /**********************************************************************
530 \**********************************************************************/
532 void IconChoiceDialog::Paint( const Rectangle
& rRect
)
534 Dialog::Paint ( rRect
);
536 for ( ULONG i
=0; i
<maPageList
.Count(); i
++ )
538 IconChoicePageData
* pData
= (IconChoicePageData
*)maPageList
.GetObject ( i
);
540 if ( pData
->nId
== mnCurrentPageId
)
542 ShowPageImpl ( pData
);
546 HidePageImpl ( pData
);
551 EIconChoicePos
IconChoiceDialog::SetCtrlPos( const EIconChoicePos
& rPos
)
553 WinBits aWinBits
= maIconCtrl
.GetStyle ();
555 switch ( meChoicePos
)
558 aWinBits
&= ~WB_ALIGN_TOP
& ~WB_NOVSCROLL
;
559 aWinBits
|= WB_ALIGN_LEFT
| WB_NOHSCROLL
;
562 aWinBits
&= ~WB_ALIGN_TOP
& ~WB_NOVSCROLL
;
563 aWinBits
|= WB_ALIGN_LEFT
| WB_NOHSCROLL
;
566 aWinBits
&= ~WB_ALIGN_LEFT
& ~WB_NOHSCROLL
;
567 aWinBits
|= WB_ALIGN_TOP
| WB_NOVSCROLL
;
570 aWinBits
&= ~WB_ALIGN_LEFT
& ~WB_NOHSCROLL
;
571 aWinBits
|= WB_ALIGN_TOP
| WB_NOVSCROLL
;
574 maIconCtrl
.SetStyle ( aWinBits
);
579 EIconChoicePos eOldPos
= meChoicePos
;
585 void IconChoiceDialog::SetCtrlColor ( const Color
& rColor
)
587 Wallpaper
aWallpaper ( rColor
);
588 maIconCtrl
.SetBackground( aWallpaper
);
589 maIconCtrl
.SetFontColorToBackground ();
592 /**********************************************************************
594 | Show / Hide page or button
596 \**********************************************************************/
598 void IconChoiceDialog::ShowPageImpl ( IconChoicePageData
* pData
)
601 pData
->pPage
->Show();
604 // -----------------------------------------------------------------------
606 void IconChoiceDialog::HidePageImpl ( IconChoicePageData
* pData
)
609 pData
->pPage
->Hide();
612 // -----------------------------------------------------------------------
614 void IconChoiceDialog::RemoveResetButton()
617 bHideResetBtn
= TRUE
;
620 // -----------------------------------------------------------------------
622 void IconChoiceDialog::ShowPage( USHORT nId
)
624 bool bInvalidate
= GetCurPageId() != nId
;
631 /**********************************************************************
635 \**********************************************************************/
637 #define ICONCTRL_WIDTH_PIXEL 110
638 #define ICONCTRL_HEIGHT_PIXEL 75
639 #define MINSIZE_BUTTON_WIDTH 70
640 #define MINSIZE_BUTTON_HEIGHT 22
642 void IconChoiceDialog::Resize()
646 if ( IsReallyVisible() )
652 void IconChoiceDialog::SetPosSizeCtrls ( BOOL bInit
)
654 const Point
aCtrlOffset ( LogicToPixel( Point( CTRLS_OFFSET
, CTRLS_OFFSET
), MAP_APPFONT
) );
655 Size
aOutSize ( GetOutputSizePixel() );
657 ////////////////////////////////////////
660 Size aDefaultButtonSize
= LogicToPixel( Size( 50, 14 ), MAP_APPFONT
);
663 Size
aResetButtonSize ( bInit
? aDefaultButtonSize
:
664 aResetBtn
.GetSizePixel () );
666 ////////////////////////////////////////
667 // IconChoiceCtrl resizen & positionieren
669 SvtTabAppearanceCfg aCfg
;
670 const long nDefaultWidth
= (aCfg
.GetScaleFactor() * ICONCTRL_WIDTH_PIXEL
) / 100;
671 const long nDefaultHeight
= (aCfg
.GetScaleFactor() * ICONCTRL_HEIGHT_PIXEL
) / 100;
673 Size
aNewIconCtrlSize ( nDefaultWidth
,
674 aOutSize
.Height()-(2*aCtrlOffset
.X()) );
676 switch ( meChoicePos
)
679 aIconCtrlPos
= aCtrlOffset
;
680 aNewIconCtrlSize
= Size ( nDefaultWidth
,
681 aOutSize
.Height()-(2*aCtrlOffset
.X()) );
684 aIconCtrlPos
= Point ( aOutSize
.Width() - nDefaultWidth
-
685 aCtrlOffset
.X(), aCtrlOffset
.X() );
686 aNewIconCtrlSize
= Size ( nDefaultWidth
,
687 aOutSize
.Height()-(2*aCtrlOffset
.X()) );
690 aIconCtrlPos
= aCtrlOffset
;
691 aNewIconCtrlSize
= Size ( aOutSize
.Width()-(2*aCtrlOffset
.X()),
695 aIconCtrlPos
= Point ( aCtrlOffset
.X(), aOutSize
.Height() -
696 aResetButtonSize
.Height() - (2*aCtrlOffset
.X()) -
698 aNewIconCtrlSize
= Size ( aOutSize
.Width()-(2*aCtrlOffset
.X()),
702 maIconCtrl
.SetPosSizePixel ( aIconCtrlPos
, aNewIconCtrlSize
);
703 maIconCtrl
.ArrangeIcons();
705 ////////////////////////////////////////
706 // Pages resizen & positionieren
708 for ( ULONG i
=0; i
<maPageList
.Count(); i
++ )
710 IconChoicePageData
* pData
= (IconChoicePageData
*)maPageList
.GetObject ( i
);
714 switch ( meChoicePos
)
717 aNewPagePos
= Point ( aNewIconCtrlSize
.Width() + (2*CTRLS_OFFSET
),
719 aNewPageSize
= Size ( aOutSize
.Width() - aNewIconCtrlSize
.Width() -
721 aOutSize
.Height() - aOKBtn
.GetSizePixel().Height() -
725 aNewPagePos
= aCtrlOffset
;
726 aNewPageSize
= Size ( aOutSize
.Width() - aNewIconCtrlSize
.Width() -
728 aOutSize
.Height() - aOKBtn
.GetSizePixel().Height() -
729 (3*aCtrlOffset
.X()) );
732 aNewPagePos
= Point ( aCtrlOffset
.X(), aNewIconCtrlSize
.Height() +
733 (2*aCtrlOffset
.X()) );
734 aNewPageSize
= Size ( aOutSize
.Width() - (2*aCtrlOffset
.X()),
735 aOutSize
.Height() - aOKBtn
.GetSizePixel().Height() -
736 aNewIconCtrlSize
.Height() - (4*aCtrlOffset
.X()) );
739 aNewPagePos
= aCtrlOffset
;
740 aNewPageSize
= Size ( aOutSize
.Width() - (2*aCtrlOffset
.X()),
741 aOutSize
.Height() - aOKBtn
.GetSizePixel().Height() -
742 aNewIconCtrlSize
.Height() - (4*aCtrlOffset
.X()) );
747 pData
->pPage
->SetPosSizePixel ( aNewPagePos
, aNewPageSize
);
750 ////////////////////////////////////////
751 // Buttons positionieren
754 if ( meChoicePos
== PosRight
)
755 nXOffset
= aNewIconCtrlSize
.Width()+(2*aCtrlOffset
.X());
757 aResetBtn
.SetPosSizePixel ( Point( aOutSize
.Width() - nXOffset
-
758 aResetButtonSize
.Width()-aCtrlOffset
.X(),
759 aOutSize
.Height()-aResetButtonSize
.Height()-
763 Size
aHelpButtonSize ( bInit
? aDefaultButtonSize
:
764 aHelpBtn
.GetSizePixel () );
765 aHelpBtn
.SetPosSizePixel ( Point( aOutSize
.Width()-aResetButtonSize
.Width()-
766 aHelpButtonSize
.Width()- nXOffset
-
768 aOutSize
.Height()-aHelpButtonSize
.Height()-
772 Size
aCancelButtonSize ( bInit
? aDefaultButtonSize
:
773 aCancelBtn
.GetSizePixel () );
774 aCancelBtn
.SetPosSizePixel ( Point( aOutSize
.Width()-aCancelButtonSize
.Width()-
775 aResetButtonSize
.Width()-aHelpButtonSize
.Width()-
776 (3*aCtrlOffset
.X()) - nXOffset
,
777 aOutSize
.Height()-aCancelButtonSize
.Height()-
781 Size
aOKButtonSize ( bInit
? aDefaultButtonSize
: aOKBtn
.GetSizePixel () );
782 aOKBtn
.SetPosSizePixel ( Point( aOutSize
.Width()-aOKButtonSize
.Width()-
783 aCancelButtonSize
.Width()-aResetButtonSize
.Width()-
784 aHelpButtonSize
.Width()-(4*aCtrlOffset
.X())- nXOffset
,
785 aOutSize
.Height()-aOKButtonSize
.Height()-aCtrlOffset
.X() ),
791 void IconChoiceDialog::SetPosSizePages ( USHORT nId
)
793 const Point
aCtrlOffset ( LogicToPixel( Point( CTRLS_OFFSET
, CTRLS_OFFSET
), MAP_APPFONT
) );
794 IconChoicePageData
* pData
= GetPageData ( nId
);
798 Size
aOutSize ( GetOutputSizePixel() );
799 Size
aIconCtrlSize ( maIconCtrl
.GetSizePixel() );
803 switch ( meChoicePos
)
806 aNewPagePos
= Point ( aIconCtrlSize
.Width() + (2*aCtrlOffset
.X()),
808 aNewPageSize
= Size ( aOutSize
.Width() - maIconCtrl
.GetSizePixel().Width() -
810 aOutSize
.Height() - aOKBtn
.GetSizePixel().Height() -
811 (3*aCtrlOffset
.X()) );
814 aNewPagePos
= aCtrlOffset
;
815 aNewPageSize
= Size ( aOutSize
.Width() - maIconCtrl
.GetSizePixel().Width() -
817 aOutSize
.Height() - aOKBtn
.GetSizePixel().Height() -
818 (3*aCtrlOffset
.X()) );
821 aNewPagePos
= Point ( aCtrlOffset
.X(), aIconCtrlSize
.Height() +
822 (2*aCtrlOffset
.X()) );
823 aNewPageSize
= Size ( aOutSize
.Width() - (2*aCtrlOffset
.X()),
824 aOutSize
.Height() - aOKBtn
.GetSizePixel().Height() -
825 maIconCtrl
.GetSizePixel().Height() - (4*aCtrlOffset
.X()) );
828 aNewPagePos
= aCtrlOffset
;
829 aNewPageSize
= Size ( aOutSize
.Width() - (2*aCtrlOffset
.X()),
830 aOutSize
.Height() - aOKBtn
.GetSizePixel().Height() -
831 maIconCtrl
.GetSizePixel().Height() - (4*aCtrlOffset
.X()) );
835 pData
->pPage
->SetPosSizePixel ( aNewPagePos
, aNewPageSize
);
839 /**********************************************************************
843 \**********************************************************************/
845 IMPL_LINK ( IconChoiceDialog
, ChosePageHdl_Impl
, void *, EMPTYARG
)
849 SvxIconChoiceCtrlEntry
*pEntry
= maIconCtrl
.GetSelectedEntry ( nPos
);
851 pEntry
= maIconCtrl
.GetCursor( );
853 USHORT
*pId
= (USHORT
*)pEntry
->GetUserData ();
855 if( *pId
!= mnCurrentPageId
)
857 IconChoicePageData
* pData
= GetPageData ( mnCurrentPageId
);
859 DeActivatePageImpl();
861 SetCurPageId ( *pId
);
870 /**********************************************************************
874 \**********************************************************************/
876 IMPL_LINK( IconChoiceDialog
, OkHdl
, Button
*, EMPTYARG
)
893 // -----------------------------------------------------------------------
895 IMPL_LINK( IconChoiceDialog
, ResetHdl
, Button
*, EMPTYARG
)
899 IconChoicePageData
* pData
= GetPageData ( mnCurrentPageId
);
900 DBG_ASSERT( pData
, "Id nicht bekannt" );
902 if ( pData
->bOnDemand
)
904 // CSet auf AIS hat hier Probleme, daher getrennt
905 const SfxItemSet
* _pSet
= &( pData
->pPage
->GetItemSet() );
906 pData
->pPage
->Reset( *(SfxItemSet
*)_pSet
);
909 pData
->pPage
->Reset( *pSet
);
915 // -----------------------------------------------------------------------
917 IMPL_LINK( IconChoiceDialog
, CancelHdl
, Button
*, EMPTYARG
)
924 /**********************************************************************
928 \**********************************************************************/
930 void IconChoiceDialog::ActivatePageImpl ()
932 DBG_ASSERT( maPageList
.Count(), "keine Pages angemeldet" );
933 IconChoicePageData
* pData
= GetPageData ( mnCurrentPageId
);
934 DBG_ASSERT( pData
, "Id nicht bekannt" );
939 const SfxItemSet
* pTmpSet
= 0;
943 if ( bItemsReset
&& pSet
->GetParent() )
944 pTmpSet
= pSet
->GetParent();
949 if ( pTmpSet
&& !pData
->bOnDemand
)
950 pData
->pPage
= (pData
->fnCreatePage
)( this, *pTmpSet
);
952 pData
->pPage
= (pData
->fnCreatePage
)( this, *CreateInputItemSet( mnCurrentPageId
) );
954 SvtViewOptions
aTabPageOpt( E_TABPAGE
, String::CreateFromInt32( pData
->nId
) );
955 pData
->pPage
->SetUserData( GetViewOptUserItem( aTabPageOpt
) );
956 SetPosSizePages ( pData
->nId
);
958 if ( pData
->bOnDemand
)
959 pData
->pPage
->Reset( (SfxItemSet
&)pData
->pPage
->GetItemSet() );
961 pData
->pPage
->Reset( *pSet
);
963 PageCreated( mnCurrentPageId
, *pData
->pPage
);
965 else if ( pData
->bRefresh
)
967 pData
->pPage
->Reset( *pSet
);
970 pData
->bRefresh
= FALSE
;
973 pData
->pPage
->ActivatePage( *pExampleSet
);
976 SetHelpId( pData
->pPage
->GetHelpId() );
978 BOOL bReadOnly
= pData
->pPage
->IsReadOnly();
979 if ( bReadOnly
|| bHideResetBtn
)
986 // -----------------------------------------------------------------------
988 BOOL
IconChoiceDialog::DeActivatePageImpl ()
990 IconChoicePageData
*pData
= GetPageData ( mnCurrentPageId
);
992 int nRet
= IconChoicePage::LEAVE_PAGE
;
996 IconChoicePage
* pPage
= pData
->pPage
;
998 if ( !pExampleSet
&& pPage
->HasExchangeSupport() && pSet
)
999 pExampleSet
= new SfxItemSet( *pSet
->GetPool(), pSet
->GetRanges() );
1003 SfxItemSet
aTmp( *pSet
->GetPool(), pSet
->GetRanges() );
1005 if ( pPage
->HasExchangeSupport() )
1006 nRet
= pPage
->DeactivatePage( &aTmp
);
1008 if ( ( IconChoicePage::LEAVE_PAGE
& nRet
) == IconChoicePage::LEAVE_PAGE
&&
1011 pExampleSet
->Put( aTmp
);
1012 pOutSet
->Put( aTmp
);
1017 if ( pPage
->HasExchangeSupport() ) //!!!
1021 SfxItemPool
* pPool
= pPage
->GetItemSet().GetPool();
1023 new SfxItemSet( *pPool
, GetInputRanges( *pPool
) );
1025 nRet
= pPage
->DeactivatePage( pExampleSet
);
1028 nRet
= pPage
->DeactivatePage( NULL
);
1031 if ( nRet
& IconChoicePage::REFRESH_SET
)
1033 pSet
= GetRefreshedSet();
1034 DBG_ASSERT( pSet
, "GetRefreshedSet() liefert NULL" );
1035 // alle Pages als neu zu initialsieren flaggen
1036 const ULONG nCount
= maPageList
.Count();
1038 for ( USHORT i
= 0; i
< nCount
; ++i
)
1040 IconChoicePageData
* pObj
= (IconChoicePageData
*)maPageList
.GetObject(i
);
1042 if ( pObj
->pPage
!= pPage
) // eigene Page nicht mehr refreshen
1043 pObj
->bRefresh
= TRUE
;
1045 pObj
->bRefresh
= FALSE
;
1050 if ( nRet
& IconChoicePage::LEAVE_PAGE
)
1056 // -----------------------------------------------------------------------
1058 void IconChoiceDialog::ResetPageImpl ()
1060 IconChoicePageData
*pData
= GetPageData ( mnCurrentPageId
);
1062 DBG_ASSERT( pData
, "Id nicht bekannt" );
1064 if ( pData
->bOnDemand
)
1066 // CSet auf AIS hat hier Probleme, daher getrennt
1067 const SfxItemSet
* _pSet
= &pData
->pPage
->GetItemSet();
1068 pData
->pPage
->Reset( *(SfxItemSet
*)_pSet
);
1071 pData
->pPage
->Reset( *pSet
);
1074 /**********************************************************************
1078 \**********************************************************************/
1080 const USHORT
* IconChoiceDialog::GetInputRanges( const SfxItemPool
& rPool
)
1084 DBG_ERRORFILE( "Set bereits vorhanden!" );
1085 return pSet
->GetRanges();
1090 SvUShorts
aUS( 16, 16 );
1091 ULONG nCount
= maPageList
.Count();
1094 for ( i
= 0; i
< nCount
; ++i
)
1096 IconChoicePageData
* pData
= maPageList
.GetObject (i
);
1098 if ( pData
->fnGetRanges
)
1100 const USHORT
* pTmpRanges
= (pData
->fnGetRanges
)();
1101 const USHORT
* pIter
= pTmpRanges
;
1104 for( nLen
= 0; *pIter
; ++nLen
, ++pIter
)
1106 aUS
.Insert( pTmpRanges
, nLen
, aUS
.Count() );
1110 // remove double Id's
1112 if ( rPool
.HasMap() )
1115 nCount
= aUS
.Count();
1117 for ( i
= 0; i
< nCount
; ++i
)
1118 aUS
[i
] = rPool
.GetWhich( aUS
[i
] );
1122 if ( aUS
.Count() > 1 )
1124 #if defined __SUNPRO_CC
1125 #pragma disable_warn
1127 qsort( (void*)aUS
.GetData(), aUS
.Count(), sizeof(USHORT
), IconcDlgCmpUS_Impl
);
1128 #if defined __SUNPRO_CC
1133 pRanges
= new USHORT
[aUS
.Count() + 1];
1134 memcpy(pRanges
, aUS
.GetData(), sizeof(USHORT
) * aUS
.Count());
1135 pRanges
[aUS
.Count()] = 0;
1140 // -----------------------------------------------------------------------
1142 void IconChoiceDialog::SetInputSet( const SfxItemSet
* pInSet
)
1144 FASTBOOL bSet
= ( pSet
!= NULL
);
1148 if ( !bSet
&& !pExampleSet
&& !pOutSet
)
1150 pExampleSet
= new SfxItemSet( *pSet
);
1151 pOutSet
= new SfxItemSet( *pSet
->GetPool(), pSet
->GetRanges() );
1155 // -----------------------------------------------------------------------
1157 // Liefert die Pages, die ihre Sets onDemand liefern, das OutputItemSet.
1158 const SfxItemSet
* IconChoiceDialog::GetOutputItemSet ( USHORT nId
)
1160 IconChoicePageData
* pData
= GetPageData ( nId
);
1161 DBG_ASSERT( pData
, "TabPage nicht gefunden" );
1165 if ( !pData
->pPage
)
1168 if ( pData
->bOnDemand
)
1169 return &pData
->pPage
->GetItemSet();
1177 // -----------------------------------------------------------------------
1179 int IconChoiceDialog::FillOutputItemSet()
1181 int nRet
= IconChoicePage::LEAVE_PAGE
;
1185 nRet
= IconChoicePage::KEEP_PAGE
;
1189 // -----------------------------------------------------------------------
1191 void IconChoiceDialog::PageCreated( USHORT
/*nId*/, IconChoicePage
& /*rPage*/ )
1193 // not interested in
1196 // -----------------------------------------------------------------------
1198 SfxItemSet
* IconChoiceDialog::CreateInputItemSet( USHORT
)
1200 DBG_WARNINGFILE( "CreateInputItemSet nicht implementiert" );
1205 /**********************************************************************
1209 \**********************************************************************/
1211 short IconChoiceDialog::Execute()
1213 if ( !maPageList
.Count() )
1218 return Dialog::Execute();
1221 // -----------------------------------------------------------------------
1223 void IconChoiceDialog::Start( BOOL bShow
)
1226 aCancelBtn
.SetClickHdl( LINK( this, IconChoiceDialog
, CancelHdl
) );
1236 // -----------------------------------------------------------------------
1238 sal_Bool
IconChoiceDialog::QueryClose()
1240 sal_Bool bRet
= sal_True
;
1241 const ULONG nCount
= maPageList
.Count();
1242 for ( ULONG i
= 0; i
< nCount
; ++i
)
1244 IconChoicePageData
* pData
= maPageList
.GetObject(i
);
1245 if ( pData
->pPage
&& !pData
->pPage
->QueryClose() )
1254 // -----------------------------------------------------------------------
1256 void IconChoiceDialog::Start_Impl()
1261 if ( mnCurrentPageId
== 0 || mnCurrentPageId
== USHRT_MAX
)
1262 nActPage
= maPageList
.GetObject(0)->nId
;//First()->nId;
1264 nActPage
= mnCurrentPageId
;
1266 // Konfiguration vorhanden?
1267 SvtViewOptions
aTabDlgOpt( E_TABDIALOG
, String::CreateFromInt32( nResId
) );
1269 if ( aTabDlgOpt
.Exists() )
1271 // ggf. Position aus Konfig
1272 SetWindowState( ByteString( aTabDlgOpt
.GetWindowState().getStr(), RTL_TEXTENCODING_ASCII_US
) );
1274 // initiale TabPage aus Programm/Hilfe/Konfig
1275 nActPage
= (USHORT
)aTabDlgOpt
.GetPageID();
1277 if ( USHRT_MAX
!= mnCurrentPageId
)
1278 nActPage
= mnCurrentPageId
;
1280 if ( GetPageData ( nActPage
) == NULL
)
1281 nActPage
= ( (IconChoicePageData
*)maPageList
.GetObject(0) )->nId
;
1283 else if ( USHRT_MAX
!= mnCurrentPageId
&& GetPageData ( mnCurrentPageId
) != NULL
)
1284 nActPage
= mnCurrentPageId
;
1286 mnCurrentPageId
= nActPage
;
1288 FocusOnIcon( mnCurrentPageId
);
1293 // -----------------------------------------------------------------------
1295 const SfxItemSet
* IconChoiceDialog::GetRefreshedSet()
1297 DBG_ERRORFILE( "GetRefreshedSet nicht implementiert" );
1301 /**********************************************************************
1305 \**********************************************************************/
1307 IconChoicePageData
* IconChoiceDialog::GetPageData ( USHORT nId
)
1309 IconChoicePageData
*pRet
= NULL
;
1310 BOOL bFound
= FALSE
;
1312 for ( ULONG i
=0; i
<maPageList
.Count() && !bFound
; i
++ )
1314 IconChoicePageData
* pData
= (IconChoicePageData
*)maPageList
.GetObject ( i
);
1316 if ( pData
->nId
== nId
)
1325 /**********************************************************************
1329 \**********************************************************************/
1331 BOOL
IconChoiceDialog::OK_Impl()
1333 IconChoicePage
* pPage
= GetPageData ( mnCurrentPageId
)->pPage
;
1338 int nRet
= IconChoicePage::LEAVE_PAGE
;
1341 SfxItemSet
aTmp( *pSet
->GetPool(), pSet
->GetRanges() );
1344 if ( pPage
->HasExchangeSupport() )
1345 nRet
= pPage
->DeactivatePage( &aTmp
);
1347 if ( ( IconChoicePage::LEAVE_PAGE
& nRet
) == IconChoicePage::LEAVE_PAGE
1350 pExampleSet
->Put( aTmp
);
1351 pOutSet
->Put( aTmp
);
1357 nRet
= pPage
->DeactivatePage( NULL
);
1364 // -----------------------------------------------------------------------
1366 short IconChoiceDialog::Ok()
1372 if ( !pExampleSet
&& pSet
)
1373 pOutSet
= pSet
->Clone( FALSE
); // ohne Items
1374 else if ( pExampleSet
)
1375 pOutSet
= new SfxItemSet( *pExampleSet
);
1377 BOOL _bModified
= FALSE
;
1379 const ULONG nCount
= maPageList
.Count();
1381 for ( USHORT i
= 0; i
< nCount
; ++i
)
1383 IconChoicePageData
* pData
= GetPageData ( i
);
1385 IconChoicePage
* pPage
= pData
->pPage
;
1389 if ( pData
->bOnDemand
)
1391 SfxItemSet
& rSet
= (SfxItemSet
&)pPage
->GetItemSet();
1393 _bModified
|= pPage
->FillItemSet( rSet
);
1395 else if ( pSet
&& !pPage
->HasExchangeSupport() )
1397 SfxItemSet
aTmp( *pSet
->GetPool(), pSet
->GetRanges() );
1399 if ( pPage
->FillItemSet( aTmp
) )
1402 pExampleSet
->Put( aTmp
);
1403 pOutSet
->Put( aTmp
);
1409 if ( _bModified
|| ( pOutSet
&& pOutSet
->Count() > 0 ) )
1412 return _bModified
? RET_OK
: RET_CANCEL
;
1415 // -----------------------------------------------------------------------
1417 BOOL
IconChoiceDialog::IsInOK() const
1422 // -----------------------------------------------------------------------
1424 void IconChoiceDialog::FocusOnIcon( USHORT nId
)
1426 // set focus to icon for the current visible page
1427 for ( USHORT i
=0; i
<maIconCtrl
.GetEntryCount(); i
++)
1429 SvxIconChoiceCtrlEntry
* pEntry
= maIconCtrl
.GetEntry ( i
);
1430 USHORT
* pUserData
= (USHORT
*) pEntry
->GetUserData();
1432 if ( pUserData
&& *pUserData
== nId
)
1434 maIconCtrl
.SetCursor( pEntry
);
1440 // -----------------------------------------------------------------------
1442 void IconChoiceDialog::CreateIconTextAutoMnemonics( void )
1444 maIconCtrl
.CreateAutoMnemonics();