update dev300-m58
[ooovba.git] / svx / source / cui / iconcdlg.cxx
blob7bd9843fb2735c391d9a4afcbf3b292b49f49b3a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: iconcdlg.cxx,v $
10 * $Revision: 1.24 $
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
36 #endif
37 #include <sfx2/app.hxx>
38 #include <tools/rc.h>
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
48 #include "helpid.hrc"
49 #endif
50 #ifndef _SVX_DIALOGS_HRC
51 #include <svx/dialogs.hrc>
52 #endif
53 #include <svtools/viewoptions.hxx>
54 #include <svtools/apearcfg.hxx>
55 #include <vcl/mnemonic.hxx>
56 #include <vcl/i18nhelp.hxx>
58 #ifdef WNT
59 int __cdecl IconcDlgCmpUS_Impl( const void* p1, const void* p2 )
60 #else
61 #if defined(OS2) && defined(ICC)
62 int _Optlink IconcDlgCmpUS_Impl( const void* p1, const void* p2 )
63 #else
64 int IconcDlgCmpUS_Impl( const void* p1, const void* p2 )
65 #endif
66 #endif
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;
84 aAny >>= aUserData;
86 return String( aUserData );
90 //#####################################################################
92 // Class IconChoicePage
94 //#####################################################################
96 /**********************************************************************
98 | Ctor / Dtor
100 \**********************************************************************/
102 IconChoicePage::IconChoicePage( Window *pParent, const ResId &rResId,
103 const SfxItemSet &rAttrSet )
104 : TabPage ( pParent, rResId ),
105 pSet ( &rAttrSet ),
106 bHasExchangeSupport ( FALSE ),
107 pDialog ( NULL ),
108 bStandard ( 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* )
133 return LEAVE_PAGE;
136 /**********************************************************************
138 | ...
140 \**********************************************************************/
142 void IconChoicePage::FillUserData()
146 // -----------------------------------------------------------------------
148 BOOL IconChoicePage::IsReadOnly() const
150 return FALSE;
153 // -----------------------------------------------------------------------
155 sal_Bool IconChoicePage::QueryClose()
157 return sal_True;
160 /**********************************************************************
162 | handling itemsets
164 \**********************************************************************/
166 const SfxPoolItem* IconChoicePage::GetItem( const SfxItemSet& rSet,
167 USHORT nSlot )
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 );
177 return pItem;
180 // -----------------------------------------------------------------------
182 const SfxPoolItem* IconChoicePage::GetOldItem( const SfxItemSet& rSet,
183 USHORT nSlot )
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 );
193 else
194 pItem = GetItem( rOldSet, nSlot );
196 return pItem;
199 // -----------------------------------------------------------------------
201 const SfxPoolItem* IconChoicePage::GetExchangeItem( const SfxItemSet& rSet,
202 USHORT nSlot )
204 if ( pDialog && !pDialog->IsInOK() && pDialog->GetExampleSet() )
205 return GetItem( *pDialog->GetExampleSet(), nSlot );
206 else
207 return GetOldItem( rSet, nSlot );
210 /**********************************************************************
212 | window-methods
214 \**********************************************************************/
216 void IconChoicePage::ImplInitSettings()
218 Window* pParent = GetParent();
219 if ( pParent->IsChildTransparentModeEnabled() && !IsControlBackground() )
221 EnableChildTransparentMode( TRUE );
222 SetParentClipMode( PARENTCLIPMODE_NOCLIP );
223 SetPaintTransparent( TRUE );
224 SetBackground();
226 else
228 EnableChildTransparentMode( FALSE );
229 SetParentClipMode( 0 );
230 SetPaintTransparent( FALSE );
232 if ( IsControlBackground() )
233 SetBackground( GetControlBackground() );
234 else
235 SetBackground( pParent->GetBackground() );
239 // -----------------------------------------------------------------------
241 void IconChoicePage::StateChanged( StateChangedType nType )
243 Window::StateChanged( nType );
245 if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
247 ImplInitSettings();
248 Invalidate();
252 // -----------------------------------------------------------------------
254 void IconChoicePage::DataChanged( const DataChangedEvent& rDCEvt )
256 Window::DataChanged( rDCEvt );
258 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
259 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
261 ImplInitSettings();
262 Invalidate();
266 //#####################################################################
268 // Class IconChoiceDialog
270 //#####################################################################
272 /**********************************************************************
274 | Ctor / Dtor
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 ),
290 aHelpBtn ( this ),
291 aResetBtn ( this ),
292 pSet ( pItemSet ),
293 pOutSet ( NULL ),
294 pExampleSet ( NULL ),
295 pRanges ( NULL ),
296 nResId ( rResId.GetId() ),
298 bHideResetBtn ( FALSE ),
299 bModal ( FALSE ),
300 bInOK ( FALSE ),
301 bModified ( 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 ) );
310 maIconCtrl.Show();
311 maIconCtrl.SetChoiceWithCursor ( TRUE );
312 maIconCtrl.SetSelectionMode( SINGLE_SELECTION );
313 maIconCtrl.SetHelpId( HID_ICCDIALOG_CHOICECTRL );
315 // ItemSet
316 if ( pSet )
318 pExampleSet = new SfxItemSet( *pSet );
319 pOutSet = new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() );
322 // Buttons
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 );
329 aOKBtn.Show();
330 aCancelBtn.Show();
331 aHelpBtn.Show();
332 aResetBtn.Show();
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 ),
345 aOKBtn ( this ),
346 pUserBtn ( pUserButtonText? new PushButton(this): 0 ),
347 aCancelBtn ( this ),
348 aHelpBtn ( this ),
349 aResetBtn ( this ),
350 aBaseFmtBtn ( this ),
351 mnCurrentPageId ( 0 )
353 FreeResource();
357 // -----------------------------------------------------------------------
359 IconChoiceDialog ::~IconChoiceDialog ()
361 ULONG i;
363 // save configuration at INI-Manager
364 // and remove pages
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);
375 if ( pData->pPage )
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();
388 delete pData->pPage;
390 delete pData;
393 // remove Pagelist
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() );
401 delete pData->pPage;
402 delete pData;
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();
410 delete pUserData;
414 if ( pRanges )
415 delete pRanges;
416 if ( pOutSet )
417 delete pOutSet;
420 /**********************************************************************
422 | add new page
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,
433 pRangesFunc,
434 bItemsOnDemand );
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 );
443 return pEntry;
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,
454 pRangesFunc,
455 bItemsOnDemand );
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 );
464 return pEntry;
467 /**********************************************************************
469 | remove page
471 \**********************************************************************/
473 void IconChoiceDialog::RemoveTabPage( USHORT nId )
475 IconChoicePageData* pData = GetPageData ( nId );
477 // remove page from list
478 if ( pData )
480 maPageList.Remove ( pData );
482 // save settings
483 if ( pData->pPage )
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() );
498 delete pData->pPage;
499 delete pData;
502 // remove Icon
503 BOOL bFound=FALSE;
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 )
511 delete pUserData;
512 maIconCtrl.RemoveEntry ( pEntry );
513 bFound = TRUE;
517 // was it the current page ?
518 if ( nId == mnCurrentPageId )
520 mnCurrentPageId = maPageList.First()->nId;
523 Invalidate ();
526 /**********************************************************************
528 | Paint-method
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 );
544 else
546 HidePageImpl ( pData );
551 EIconChoicePos IconChoiceDialog::SetCtrlPos( const EIconChoicePos& rPos )
553 WinBits aWinBits = maIconCtrl.GetStyle ();
555 switch ( meChoicePos )
557 case PosLeft :
558 aWinBits &= ~WB_ALIGN_TOP & ~WB_NOVSCROLL;
559 aWinBits |= WB_ALIGN_LEFT | WB_NOHSCROLL;
560 break;
561 case PosRight :
562 aWinBits &= ~WB_ALIGN_TOP & ~WB_NOVSCROLL;
563 aWinBits |= WB_ALIGN_LEFT | WB_NOHSCROLL;
564 break;
565 case PosTop :
566 aWinBits &= ~WB_ALIGN_LEFT & ~WB_NOHSCROLL;
567 aWinBits |= WB_ALIGN_TOP | WB_NOVSCROLL;
568 break;
569 case PosBottom :
570 aWinBits &= ~WB_ALIGN_LEFT & ~WB_NOHSCROLL;
571 aWinBits |= WB_ALIGN_TOP | WB_NOVSCROLL;
572 break;
574 maIconCtrl.SetStyle ( aWinBits );
576 SetPosSizeCtrls();
579 EIconChoicePos eOldPos = meChoicePos;
580 meChoicePos = rPos;
582 return eOldPos;
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 )
600 if ( pData->pPage )
601 pData->pPage->Show();
604 // -----------------------------------------------------------------------
606 void IconChoiceDialog::HidePageImpl ( IconChoicePageData* pData )
608 if ( pData->pPage )
609 pData->pPage->Hide();
612 // -----------------------------------------------------------------------
614 void IconChoiceDialog::RemoveResetButton()
616 aResetBtn.Hide();
617 bHideResetBtn = TRUE;
620 // -----------------------------------------------------------------------
622 void IconChoiceDialog::ShowPage( USHORT nId )
624 bool bInvalidate = GetCurPageId() != nId;
625 SetCurPageId( nId );
626 ActivatePageImpl( );
627 if(bInvalidate)
628 Invalidate();
631 /**********************************************************************
633 | Resize Dialog
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()
644 Dialog::Resize ();
646 if ( IsReallyVisible() )
648 SetPosSizeCtrls ();
652 void IconChoiceDialog::SetPosSizeCtrls ( BOOL bInit )
654 const Point aCtrlOffset ( LogicToPixel( Point( CTRLS_OFFSET, CTRLS_OFFSET ), MAP_APPFONT ) );
655 Size aOutSize ( GetOutputSizePixel() );
657 ////////////////////////////////////////
658 // Button-Defaults
660 Size aDefaultButtonSize = LogicToPixel( Size( 50, 14 ), MAP_APPFONT );
662 // Reset-Button
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()) );
675 Point aIconCtrlPos;
676 switch ( meChoicePos )
678 case PosLeft :
679 aIconCtrlPos = aCtrlOffset;
680 aNewIconCtrlSize = Size ( nDefaultWidth,
681 aOutSize.Height()-(2*aCtrlOffset.X()) );
682 break;
683 case PosRight :
684 aIconCtrlPos = Point ( aOutSize.Width() - nDefaultWidth -
685 aCtrlOffset.X(), aCtrlOffset.X() );
686 aNewIconCtrlSize = Size ( nDefaultWidth,
687 aOutSize.Height()-(2*aCtrlOffset.X()) );
688 break;
689 case PosTop :
690 aIconCtrlPos = aCtrlOffset;
691 aNewIconCtrlSize = Size ( aOutSize.Width()-(2*aCtrlOffset.X()),
692 nDefaultHeight );
693 break;
694 case PosBottom :
695 aIconCtrlPos = Point ( aCtrlOffset.X(), aOutSize.Height() -
696 aResetButtonSize.Height() - (2*aCtrlOffset.X()) -
697 nDefaultHeight );
698 aNewIconCtrlSize = Size ( aOutSize.Width()-(2*aCtrlOffset.X()),
699 nDefaultHeight );
700 break;
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 );
712 Point aNewPagePos;
713 Size aNewPageSize;
714 switch ( meChoicePos )
716 case PosLeft :
717 aNewPagePos = Point ( aNewIconCtrlSize.Width() + (2*CTRLS_OFFSET),
718 CTRLS_OFFSET );
719 aNewPageSize = Size ( aOutSize.Width() - aNewIconCtrlSize.Width() -
720 (3*CTRLS_OFFSET),
721 aOutSize.Height() - aOKBtn.GetSizePixel().Height() -
722 (3*CTRLS_OFFSET) );
723 break;
724 case PosRight :
725 aNewPagePos = aCtrlOffset;
726 aNewPageSize = Size ( aOutSize.Width() - aNewIconCtrlSize.Width() -
727 (3*aCtrlOffset.X()),
728 aOutSize.Height() - aOKBtn.GetSizePixel().Height() -
729 (3*aCtrlOffset.X()) );
730 break;
731 case PosTop :
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()) );
737 break;
738 case PosBottom :
739 aNewPagePos = aCtrlOffset;
740 aNewPageSize = Size ( aOutSize.Width() - (2*aCtrlOffset.X()),
741 aOutSize.Height() - aOKBtn.GetSizePixel().Height() -
742 aNewIconCtrlSize.Height() - (4*aCtrlOffset.X()) );
743 break;
746 if ( pData->pPage )
747 pData->pPage->SetPosSizePixel ( aNewPagePos, aNewPageSize );
750 ////////////////////////////////////////
751 // Buttons positionieren
753 ULONG nXOffset=0;
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()-
760 aCtrlOffset.X() ),
761 aResetButtonSize );
762 // Help-Button
763 Size aHelpButtonSize ( bInit ? aDefaultButtonSize :
764 aHelpBtn.GetSizePixel () );
765 aHelpBtn.SetPosSizePixel ( Point( aOutSize.Width()-aResetButtonSize.Width()-
766 aHelpButtonSize.Width()- nXOffset -
767 (2*aCtrlOffset.X()),
768 aOutSize.Height()-aHelpButtonSize.Height()-
769 aCtrlOffset.X() ),
770 aHelpButtonSize );
771 // Cancel-Button
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()-
778 aCtrlOffset.X() ),
779 aCancelButtonSize );
780 // OK-Button
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() ),
786 aOKButtonSize );
788 Invalidate();
791 void IconChoiceDialog::SetPosSizePages ( USHORT nId )
793 const Point aCtrlOffset ( LogicToPixel( Point( CTRLS_OFFSET, CTRLS_OFFSET ), MAP_APPFONT ) );
794 IconChoicePageData* pData = GetPageData ( nId );
796 if ( pData->pPage )
798 Size aOutSize ( GetOutputSizePixel() );
799 Size aIconCtrlSize ( maIconCtrl.GetSizePixel() );
801 Point aNewPagePos;
802 Size aNewPageSize;
803 switch ( meChoicePos )
805 case PosLeft :
806 aNewPagePos = Point ( aIconCtrlSize.Width() + (2*aCtrlOffset.X()),
807 aCtrlOffset.X() );
808 aNewPageSize = Size ( aOutSize.Width() - maIconCtrl.GetSizePixel().Width() -
809 (3*aCtrlOffset.X()),
810 aOutSize.Height() - aOKBtn.GetSizePixel().Height() -
811 (3*aCtrlOffset.X()) );
812 break;
813 case PosRight :
814 aNewPagePos = aCtrlOffset;
815 aNewPageSize = Size ( aOutSize.Width() - maIconCtrl.GetSizePixel().Width() -
816 (3*aCtrlOffset.X()),
817 aOutSize.Height() - aOKBtn.GetSizePixel().Height() -
818 (3*aCtrlOffset.X()) );
819 break;
820 case PosTop :
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()) );
826 break;
827 case PosBottom :
828 aNewPagePos = aCtrlOffset;
829 aNewPageSize = Size ( aOutSize.Width() - (2*aCtrlOffset.X()),
830 aOutSize.Height() - aOKBtn.GetSizePixel().Height() -
831 maIconCtrl.GetSizePixel().Height() - (4*aCtrlOffset.X()) );
832 break;
835 pData->pPage->SetPosSizePixel ( aNewPagePos, aNewPageSize );
839 /**********************************************************************
841 | select a page
843 \**********************************************************************/
845 IMPL_LINK ( IconChoiceDialog , ChosePageHdl_Impl, void *, EMPTYARG )
847 ULONG nPos;
849 SvxIconChoiceCtrlEntry *pEntry = maIconCtrl.GetSelectedEntry ( nPos );
850 if ( !pEntry )
851 pEntry = maIconCtrl.GetCursor( );
853 USHORT *pId = (USHORT*)pEntry->GetUserData ();
855 if( *pId != mnCurrentPageId )
857 IconChoicePageData* pData = GetPageData ( mnCurrentPageId );
858 if ( pData->pPage )
859 DeActivatePageImpl();
861 SetCurPageId ( *pId );
863 ActivatePageImpl();
864 Invalidate();
867 return 0L;
870 /**********************************************************************
872 | Button-handler
874 \**********************************************************************/
876 IMPL_LINK( IconChoiceDialog, OkHdl, Button *, EMPTYARG )
878 bInOK = TRUE;
880 if ( OK_Impl() )
882 if ( bModal )
883 EndDialog( Ok() );
884 else
886 Ok();
887 Close();
890 return 0;
893 // -----------------------------------------------------------------------
895 IMPL_LINK( IconChoiceDialog, ResetHdl, Button *, EMPTYARG )
897 ResetPageImpl ();
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 );
908 else
909 pData->pPage->Reset( *pSet );
912 return 0;
915 // -----------------------------------------------------------------------
917 IMPL_LINK( IconChoiceDialog, CancelHdl, Button*, EMPTYARG )
919 Close();
921 return 0;
924 /**********************************************************************
926 | call page
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" );
935 if ( pData )
937 if ( !pData->pPage )
939 const SfxItemSet* pTmpSet = 0;
941 if ( pSet )
943 if ( bItemsReset && pSet->GetParent() )
944 pTmpSet = pSet->GetParent();
945 else
946 pTmpSet = pSet;
949 if ( pTmpSet && !pData->bOnDemand )
950 pData->pPage = (pData->fnCreatePage)( this, *pTmpSet );
951 else
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() );
960 else
961 pData->pPage->Reset( *pSet );
963 PageCreated( mnCurrentPageId, *pData->pPage );
965 else if ( pData->bRefresh )
967 pData->pPage->Reset( *pSet );
970 pData->bRefresh = FALSE;
972 if ( pExampleSet )
973 pData->pPage->ActivatePage( *pExampleSet );
976 SetHelpId( pData->pPage->GetHelpId() );
978 BOOL bReadOnly = pData->pPage->IsReadOnly();
979 if ( bReadOnly || bHideResetBtn )
980 aResetBtn.Hide();
981 else
982 aResetBtn.Show();
986 // -----------------------------------------------------------------------
988 BOOL IconChoiceDialog::DeActivatePageImpl ()
990 IconChoicePageData *pData = GetPageData ( mnCurrentPageId );
992 int nRet = IconChoicePage::LEAVE_PAGE;
994 if ( pData )
996 IconChoicePage * pPage = pData->pPage;
998 if ( !pExampleSet && pPage->HasExchangeSupport() && pSet )
999 pExampleSet = new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() );
1001 if ( pSet )
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 &&
1009 aTmp.Count() )
1011 pExampleSet->Put( aTmp );
1012 pOutSet->Put( aTmp );
1015 else
1017 if ( pPage->HasExchangeSupport() ) //!!!
1019 if ( !pExampleSet )
1021 SfxItemPool* pPool = pPage->GetItemSet().GetPool();
1022 pExampleSet =
1023 new SfxItemSet( *pPool, GetInputRanges( *pPool ) );
1025 nRet = pPage->DeactivatePage( pExampleSet );
1027 else
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;
1044 else
1045 pObj->bRefresh = FALSE;
1050 if ( nRet & IconChoicePage::LEAVE_PAGE )
1051 return TRUE;
1052 else
1053 return FALSE;
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 );
1070 else
1071 pData->pPage->Reset( *pSet );
1074 /**********************************************************************
1076 | handling itemsets
1078 \**********************************************************************/
1080 const USHORT* IconChoiceDialog::GetInputRanges( const SfxItemPool& rPool )
1082 if ( pSet )
1084 DBG_ERRORFILE( "Set bereits vorhanden!" );
1085 return pSet->GetRanges();
1088 if ( pRanges )
1089 return pRanges;
1090 SvUShorts aUS( 16, 16 );
1091 ULONG nCount = maPageList.Count();
1093 USHORT i;
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;
1103 USHORT nLen;
1104 for( nLen = 0; *pIter; ++nLen, ++pIter )
1106 aUS.Insert( pTmpRanges, nLen, aUS.Count() );
1110 // remove double Id's
1111 #ifndef TF_POOLABLE
1112 if ( rPool.HasMap() )
1113 #endif
1115 nCount = aUS.Count();
1117 for ( i = 0; i < nCount; ++i )
1118 aUS[i] = rPool.GetWhich( aUS[i] );
1121 // sortieren
1122 if ( aUS.Count() > 1 )
1124 #if defined __SUNPRO_CC
1125 #pragma disable_warn
1126 #endif
1127 qsort( (void*)aUS.GetData(), aUS.Count(), sizeof(USHORT), IconcDlgCmpUS_Impl );
1128 #if defined __SUNPRO_CC
1129 #pragma enable_warn
1130 #endif
1133 pRanges = new USHORT[aUS.Count() + 1];
1134 memcpy(pRanges, aUS.GetData(), sizeof(USHORT) * aUS.Count());
1135 pRanges[aUS.Count()] = 0;
1137 return pRanges;
1140 // -----------------------------------------------------------------------
1142 void IconChoiceDialog::SetInputSet( const SfxItemSet* pInSet )
1144 FASTBOOL bSet = ( pSet != NULL );
1146 pSet = pInSet;
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" );
1163 if ( pData )
1165 if ( !pData->pPage )
1166 return NULL;
1168 if ( pData->bOnDemand )
1169 return &pData->pPage->GetItemSet();
1171 return pOutSet;
1174 return NULL;
1177 // -----------------------------------------------------------------------
1179 int IconChoiceDialog::FillOutputItemSet()
1181 int nRet = IconChoicePage::LEAVE_PAGE;
1182 if ( OK_Impl() )
1183 Ok();
1184 else
1185 nRet = IconChoicePage::KEEP_PAGE;
1186 return nRet;
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" );
1202 return 0;
1205 /**********************************************************************
1207 | start dialog
1209 \**********************************************************************/
1211 short IconChoiceDialog::Execute()
1213 if ( !maPageList.Count() )
1214 return RET_CANCEL;
1216 Start_Impl();
1218 return Dialog::Execute();
1221 // -----------------------------------------------------------------------
1223 void IconChoiceDialog::Start( BOOL bShow )
1226 aCancelBtn.SetClickHdl( LINK( this, IconChoiceDialog, CancelHdl ) );
1227 bModal = FALSE;
1229 Start_Impl();
1231 if ( bShow )
1232 Window::Show();
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() )
1247 bRet = sal_False;
1248 break;
1251 return bRet;
1254 // -----------------------------------------------------------------------
1256 void IconChoiceDialog::Start_Impl()
1258 Point aPos;
1259 USHORT nActPage;
1261 if ( mnCurrentPageId == 0 || mnCurrentPageId == USHRT_MAX )
1262 nActPage = maPageList.GetObject(0)->nId;//First()->nId;
1263 else
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 );
1290 ActivatePageImpl();
1293 // -----------------------------------------------------------------------
1295 const SfxItemSet* IconChoiceDialog::GetRefreshedSet()
1297 DBG_ERRORFILE( "GetRefreshedSet nicht implementiert" );
1298 return 0;
1301 /**********************************************************************
1303 | tool-methods
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 )
1318 pRet = pData;
1322 return pRet;
1325 /**********************************************************************
1327 | OK-Status
1329 \**********************************************************************/
1331 BOOL IconChoiceDialog::OK_Impl()
1333 IconChoicePage* pPage = GetPageData ( mnCurrentPageId )->pPage;
1335 bool bEnd = !pPage;
1336 if ( pPage )
1338 int nRet = IconChoicePage::LEAVE_PAGE;
1339 if ( pSet )
1341 SfxItemSet aTmp( *pSet->GetPool(), pSet->GetRanges() );
1342 BOOL bRet = FALSE;
1344 if ( pPage->HasExchangeSupport() )
1345 nRet = pPage->DeactivatePage( &aTmp );
1347 if ( ( IconChoicePage::LEAVE_PAGE & nRet ) == IconChoicePage::LEAVE_PAGE
1348 && aTmp.Count() )
1350 pExampleSet->Put( aTmp );
1351 pOutSet->Put( aTmp );
1353 else if ( bRet )
1354 bModified |= TRUE;
1356 else
1357 nRet = pPage->DeactivatePage( NULL );
1358 bEnd = nRet;
1361 return bEnd;
1364 // -----------------------------------------------------------------------
1366 short IconChoiceDialog::Ok()
1368 bInOK = TRUE;
1370 if ( !pOutSet )
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;
1387 if ( pPage )
1389 if ( pData->bOnDemand )
1391 SfxItemSet& rSet = (SfxItemSet&)pPage->GetItemSet();
1392 rSet.ClearItem();
1393 _bModified |= pPage->FillItemSet( rSet );
1395 else if ( pSet && !pPage->HasExchangeSupport() )
1397 SfxItemSet aTmp( *pSet->GetPool(), pSet->GetRanges() );
1399 if ( pPage->FillItemSet( aTmp ) )
1401 _bModified |= TRUE;
1402 pExampleSet->Put( aTmp );
1403 pOutSet->Put( aTmp );
1409 if ( _bModified || ( pOutSet && pOutSet->Count() > 0 ) )
1410 _bModified |= TRUE;
1412 return _bModified ? RET_OK : RET_CANCEL;
1415 // -----------------------------------------------------------------------
1417 BOOL IconChoiceDialog::IsInOK() const
1419 return bInOK;
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 );
1435 break;
1440 // -----------------------------------------------------------------------
1442 void IconChoiceDialog::CreateIconTextAutoMnemonics( void )
1444 maIconCtrl.CreateAutoMnemonics();