Bump version to 4.1-6
[LibreOffice.git] / sfx2 / source / dialog / tabdlg.cxx
blob75fcdef6bdb3a7179359f4d39733fccb695bf7ef
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <limits.h>
22 #include <stdlib.h>
23 #include <algorithm>
24 #include <vcl/builder.hxx>
25 #include <vcl/msgbox.hxx>
26 #include <unotools/viewoptions.hxx>
28 #include "appdata.hxx"
29 #include "sfxtypes.hxx"
30 #include <sfx2/tabdlg.hxx>
31 #include <sfx2/viewfrm.hxx>
32 #include <sfx2/app.hxx>
33 #include "sfx2/sfxresid.hxx"
34 #include "sfx2/sfxhelp.hxx"
35 #include <sfx2/ctrlitem.hxx>
36 #include <sfx2/bindings.hxx>
37 #include <sfx2/sfxdlg.hxx>
38 #include <sfx2/itemconnect.hxx>
40 #include "dialog.hrc"
41 #include "helpid.hrc"
43 using namespace ::com::sun::star::uno;
44 using namespace ::rtl;
46 #define USERITEM_NAME OUString("UserItem")
48 TYPEINIT1(SfxTabDialogItem,SfxSetItem);
50 struct TabPageImpl
52 sal_Bool mbStandard;
53 sfx::ItemConnectionArray maItemConn;
54 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > mxFrame;
56 TabPageImpl() : mbStandard( sal_False ) {}
59 struct Data_Impl
61 sal_uInt16 nId; // The ID
62 CreateTabPage fnCreatePage; // Pointer to Factory
63 GetTabPageRanges fnGetRanges; // Pointer to Ranges-Function
64 SfxTabPage* pTabPage; // The TabPage itself
65 sal_Bool bOnDemand; // Flag: ItemSet onDemand
66 sal_Bool bRefresh; // Flag: Page must be re-initialized
68 // Constructor
69 Data_Impl( sal_uInt16 Id, CreateTabPage fnPage,
70 GetTabPageRanges fnRanges, sal_Bool bDemand ) :
72 nId ( Id ),
73 fnCreatePage( fnPage ),
74 fnGetRanges ( fnRanges ),
75 pTabPage ( 0 ),
76 bOnDemand ( bDemand ),
77 bRefresh ( sal_False )
79 if ( !fnCreatePage )
81 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
82 if ( pFact )
84 fnCreatePage = pFact->GetTabPageCreatorFunc( nId );
85 fnGetRanges = pFact->GetTabPageRangesFunc( nId );
91 SfxTabDialogItem::SfxTabDialogItem( const SfxTabDialogItem& rAttr, SfxItemPool* pItemPool )
92 : SfxSetItem( rAttr, pItemPool )
96 SfxTabDialogItem::SfxTabDialogItem( sal_uInt16 nId, const SfxItemSet& rItemSet )
97 : SfxSetItem( nId, rItemSet )
101 SfxPoolItem* SfxTabDialogItem::Clone(SfxItemPool* pToPool) const
103 return new SfxTabDialogItem( *this, pToPool );
106 SfxPoolItem* SfxTabDialogItem::Create(SvStream& /*rStream*/, sal_uInt16 /*nVersion*/) const
108 OSL_FAIL( "Use it only in UI!" );
109 return NULL;
112 class SfxTabDialogController : public SfxControllerItem
114 SfxTabDialog* pDialog;
115 const SfxItemSet* pSet;
116 public:
117 SfxTabDialogController( sal_uInt16 nSlotId, SfxBindings& rBindings, SfxTabDialog* pDlg )
118 : SfxControllerItem( nSlotId, rBindings )
119 , pDialog( pDlg )
120 , pSet( NULL )
123 ~SfxTabDialogController();
125 virtual void StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState );
128 SfxTabDialogController::~SfxTabDialogController()
130 delete pSet;
133 void SfxTabDialogController::StateChanged( sal_uInt16 /*nSID*/, SfxItemState /*eState*/, const SfxPoolItem* pState )
135 const SfxSetItem* pSetItem = PTR_CAST( SfxSetItem, pState );
136 if ( pSetItem )
138 pSet = pDialog->pSet = pSetItem->GetItemSet().Clone();
139 sal_Bool bDialogStarted = sal_False;
140 for ( sal_uInt16 n=0; n<pDialog->m_pTabCtrl->GetPageCount(); n++ )
142 sal_uInt16 nPageId = pDialog->m_pTabCtrl->GetPageId( n );
143 SfxTabPage* pTabPage = dynamic_cast<SfxTabPage*> (pDialog->m_pTabCtrl->GetTabPage( nPageId ));
144 if ( pTabPage )
146 pTabPage->Reset( pSetItem->GetItemSet() );
147 bDialogStarted = sal_True;
151 if ( bDialogStarted )
152 pDialog->Show();
154 else
155 pDialog->Hide();
158 typedef std::vector<Data_Impl*> SfxTabDlgData_Impl;
160 struct TabDlg_Impl
162 sal_Bool bModified : 1,
163 bModal : 1,
164 bHideResetBtn : 1;
165 SfxTabDlgData_Impl aData;
167 SfxTabDialogController* pController;
169 TabDlg_Impl( sal_uInt8 nCnt ) :
171 bModified ( sal_False ),
172 bModal ( sal_True ),
173 bHideResetBtn ( sal_False ),
174 pController ( NULL )
176 aData.reserve( nCnt );
178 ~TabDlg_Impl()
180 delete pController;
185 static Data_Impl* Find( const SfxTabDlgData_Impl& rArr, sal_uInt16 nId, sal_uInt16* pPos = 0)
187 const sal_uInt16 nCount = rArr.size();
189 for ( sal_uInt16 i = 0; i < nCount; ++i )
191 Data_Impl* pObj = rArr[i];
193 if ( pObj->nId == nId )
195 if ( pPos )
196 *pPos = i;
197 return pObj;
200 return 0;
203 void SfxTabPage::SetFrame(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame)
205 if (pImpl)
206 pImpl->mxFrame = xFrame;
209 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > SfxTabPage::GetFrame()
211 if (pImpl)
212 return pImpl->mxFrame;
213 return ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >();
216 SfxTabPage::SfxTabPage( Window *pParent,
217 const ResId &rResId, const SfxItemSet &rAttrSet ) :
219 /* [Description]
221 Constructor
224 TabPage( pParent, rResId ),
226 pSet ( &rAttrSet ),
227 bHasExchangeSupport ( sal_False ),
228 pTabDlg ( NULL ),
229 pImpl ( new TabPageImpl )
235 SfxTabPage::SfxTabPage(Window *pParent, const OString& rID, const OUString& rUIXMLDescription, const SfxItemSet &rAttrSet)
236 : TabPage(pParent, rID, rUIXMLDescription)
237 , pSet ( &rAttrSet )
238 , bHasExchangeSupport ( sal_False )
239 , pTabDlg ( NULL )
240 , pImpl ( new TabPageImpl )
244 // -----------------------------------------------------------------------
246 SfxTabPage::~SfxTabPage()
248 /* [Description]
250 Destructor
254 delete pImpl;
257 // -----------------------------------------------------------------------
259 sal_Bool SfxTabPage::FillItemSet( SfxItemSet& rSet )
261 return pImpl->maItemConn.DoFillItemSet( rSet, GetItemSet() );
264 // -----------------------------------------------------------------------
266 void SfxTabPage::Reset( const SfxItemSet& rSet )
268 pImpl->maItemConn.DoApplyFlags( rSet );
269 pImpl->maItemConn.DoReset( rSet );
272 // -----------------------------------------------------------------------
274 void SfxTabPage::ActivatePage( const SfxItemSet& )
276 /* [Description]
278 Default implementation of the virtual ActivatePage method. This method is
279 called when a page of dialogue supports the exchange of data between pages.
280 <SfxTabPage::DeactivatePage(SfxItemSet *)>
286 // -----------------------------------------------------------------------
288 int SfxTabPage::DeactivatePage( SfxItemSet* )
290 /* [Description]
292 Default implementation of the virtual DeactivatePage method. This method is
293 called by Sfx when leaving a page; the application can, through the return
294 value, control whether to leave the page. If the page is displayed through
295 bHasExchangeSupport which supports data exchange between pages, then a
296 pointer to the exchange set is passed as parameter. This takes on data for
297 the exchange, then the set is available as a parameter in
298 <SfxTabPage::ActivatePage(const SfxItemSet &)>.
300 [Return value]
302 LEAVE_PAGE; Allow leaving the page
306 return LEAVE_PAGE;
309 // -----------------------------------------------------------------------
311 void SfxTabPage::FillUserData()
313 /* [Description]
315 Virtual method is called by the base class in the destructor to save
316 specific information of the TabPage in the ini-file. When overloading a
317 string must be compiled, which is then flushed with the <SetUserData()>.
323 // -----------------------------------------------------------------------
325 sal_Bool SfxTabPage::IsReadOnly() const
327 return sal_False;
330 // -----------------------------------------------------------------------
332 const SfxPoolItem* SfxTabPage::GetItem( const SfxItemSet& rSet, sal_uInt16 nSlot, sal_Bool bDeep )
334 /* [Description]
336 static Method: hereby are the implementations of the TabPage code
337 beeing simplified.
341 const SfxItemPool* pPool = rSet.GetPool();
342 sal_uInt16 nWh = pPool->GetWhich( nSlot, bDeep );
343 const SfxPoolItem* pItem = 0;
344 rSet.GetItemState( nWh, sal_True, &pItem );
346 if ( !pItem && nWh != nSlot )
347 pItem = &pPool->GetDefaultItem( nWh );
348 return pItem;
351 // -----------------------------------------------------------------------
353 const SfxPoolItem* SfxTabPage::GetOldItem( const SfxItemSet& rSet,
354 sal_uInt16 nSlot, sal_Bool bDeep )
356 /* [Description]
358 This method returns an attribute for comparison of the old value.
362 const SfxItemSet& rOldSet = GetItemSet();
363 sal_uInt16 nWh = GetWhich( nSlot, bDeep );
364 const SfxPoolItem* pItem = 0;
366 if ( pImpl->mbStandard && rOldSet.GetParent() )
367 pItem = GetItem( *rOldSet.GetParent(), nSlot );
368 else if ( rSet.GetParent() &&
369 SFX_ITEM_DONTCARE == rSet.GetItemState( nWh ) )
370 pItem = GetItem( *rSet.GetParent(), nSlot );
371 else
372 pItem = GetItem( rOldSet, nSlot );
373 return pItem;
376 void SfxTabPage::PageCreated( SfxAllItemSet /*aSet*/ )
378 DBG_ASSERT(0, "SfxTabPage::PageCreated should not be called");
381 // -----------------------------------------------------------------------
383 void SfxTabPage::AddItemConnection( sfx::ItemConnectionBase* pConnection )
385 pImpl->maItemConn.AddConnection( pConnection );
388 #define INI_LIST(ItemSetPtr) \
389 pSet(ItemSetPtr) \
390 , pOutSet(0) \
391 , pRanges(0) \
392 , nResId(rResId.GetId()) \
393 , nAppPageId(USHRT_MAX) \
394 , bItemsReset(sal_False) \
395 , bFmt(bEditFmt)\
396 , pExampleSet(0)
398 // -----------------------------------------------------------------------
400 SfxTabDialog::SfxTabDialog
402 /* [Description]
404 Constructor
408 SfxViewFrame* pViewFrame, // Frame, to which the Dialog belongs
409 Window* pParent, // Parent Window
410 const ResId& rResId, // ResourceId
411 const SfxItemSet* pItemSet, // Itemset with the data;
412 // can be NULL, when Pages are onDemand
413 sal_Bool bEditFmt, // Flag: templates are processed
414 // when yes -> additional Button for standard
415 const String* pUserButtonText // Text for UserButton;
416 // if != 0, the UserButton is created
418 : TabDialog(pParent, rResId)
419 , pFrame(pViewFrame)
420 , INI_LIST(pItemSet)
422 Init_Impl( bFmt, pUserButtonText, &rResId );
425 SfxTabDialog::SfxTabDialog
427 SfxViewFrame* pViewFrame, // Frame, to which the Dialog belongs
428 Window* pParent, // Parent Window
429 const OString& rID, const OUString& rUIXMLDescription, //Dialog Name, Dialog .ui path
430 const SfxItemSet* pItemSet, // Itemset with the data;
431 // can be NULL, when Pages are onDemand
432 sal_Bool bEditFmt // Flag: templates are processed
433 // when yes -> additional Button for standard
435 : TabDialog(pParent, rID, rUIXMLDescription)
436 , pFrame(pViewFrame)
437 , pSet(pItemSet)
438 , pOutSet(0)
439 , pRanges(0)
440 , nResId(0)
441 , nAppPageId(USHRT_MAX)
442 , bItemsReset(sal_False)
443 , bFmt(bEditFmt)
444 , pExampleSet(0)
446 Init_Impl( bFmt, NULL, NULL );
449 // -----------------------------------------------------------------------
451 SfxTabDialog::SfxTabDialog
453 /* [Description]
455 Constructor, temporary without Frame
459 Window* pParent, // Parent Window
460 const ResId& rResId, // ResourceId
461 const SfxItemSet* pItemSet, // Itemset with the data;
462 // can be NULL, when Pages are onDemand
463 sal_Bool bEditFmt, // Flag: templates are processed
464 // when yes -> additional Button for standard
465 const String* pUserButtonText // Text for UserButton;
466 // if != 0, the UserButton is created
468 : TabDialog(pParent, rResId)
469 , pFrame(0)
470 , INI_LIST(pItemSet)
472 Init_Impl( bFmt, pUserButtonText, &rResId );
473 DBG_WARNING( "Please use the Construtor with the ViewFrame" );
476 SfxTabDialog::SfxTabDialog
478 /* [Description]
480 Constructor, temporary without Frame
484 Window* pParent, // Parent Window
485 const OString& rID, const OUString& rUIXMLDescription, //Dialog Name, Dialog .ui path
486 const SfxItemSet* pItemSet, // Itemset with the data;
487 // can be NULL, when Pages are onDemand
488 sal_Bool bEditFmt // Flag: templates are processed
489 // when yes -> additional Button for standard
491 : TabDialog(pParent, rID, rUIXMLDescription)
492 , pFrame(0)
493 , pSet(pItemSet)
494 , pOutSet(0)
495 , pRanges(0)
496 , nResId(0)
497 , nAppPageId(USHRT_MAX)
498 , bItemsReset(sal_False)
499 , bFmt(bEditFmt)
500 , pExampleSet(0)
502 Init_Impl(bFmt, NULL, NULL);
503 DBG_WARNING( "Please use the Construtor with the ViewFrame" );
506 // -----------------------------------------------------------------------
508 SfxTabDialog::~SfxTabDialog()
510 SavePosAndId();
512 for ( SfxTabDlgData_Impl::const_iterator it = pImpl->aData.begin(); it != pImpl->aData.end(); ++it )
514 Data_Impl* pDataObject = *it;
516 if ( pDataObject->pTabPage )
518 // save settings of all pages (user data)
519 pDataObject->pTabPage->FillUserData();
520 String aPageData( pDataObject->pTabPage->GetUserData() );
521 if ( aPageData.Len() )
523 // save settings of all pages (user data)
524 SvtViewOptions aPageOpt( E_TABPAGE, OUString::number( pDataObject->nId ) );
525 aPageOpt.SetUserItem( USERITEM_NAME, makeAny( OUString( aPageData ) ) );
528 if ( pDataObject->bOnDemand )
529 delete (SfxItemSet*)&pDataObject->pTabPage->GetItemSet();
530 delete pDataObject->pTabPage;
532 delete pDataObject;
535 delete pImpl;
536 delete pOutSet;
537 delete pExampleSet;
538 delete [] pRanges;
540 if (m_bOwnsBaseFmtBtn)
541 delete m_pBaseFmtBtn;
542 if (m_bOwnsResetBtn)
543 delete m_pResetBtn;
544 if (m_bOwnsHelpBtn)
545 delete m_pHelpBtn;
546 if (m_bOwnsCancelBtn)
547 delete m_pCancelBtn;
548 if (m_bOwnsUserBtn)
549 delete m_pUserBtn;
550 if (m_bOwnsApplyBtn)
551 delete m_pApplyBtn;
552 if (m_bOwnsOKBtn)
553 delete m_pOKBtn;
554 if (m_bOwnsActionArea)
555 delete m_pActionArea;
556 if (m_bOwnsTabCtrl)
557 delete m_pTabCtrl;
558 if (m_bOwnsVBox)
559 delete m_pBox;
562 // -----------------------------------------------------------------------
564 void SfxTabDialog::Init_Impl( sal_Bool bFmtFlag, const String* pUserButtonText, const ResId *pResId )
566 /* [Description]
568 internal initialization of the dialogue
572 m_pBox = get_content_area();
573 m_bOwnsVBox = m_pBox == NULL;
574 if (m_bOwnsVBox)
576 m_pBox = new VclVBox(this, false, 7);
577 m_pBox->set_expand(true);
578 set_content_area(m_pBox);
581 m_pTabCtrl = m_pUIBuilder ? m_pUIBuilder->get<TabControl>("tabcontrol") : NULL;
582 m_bOwnsTabCtrl = m_pTabCtrl == NULL;
583 if (m_bOwnsTabCtrl)
585 m_pTabCtrl = new TabControl(m_pBox, ResId(ID_TABCONTROL, *pResId->GetResMgr()));
586 m_pTabCtrl->set_expand(true);
589 m_pActionArea = get_action_area();
590 m_bOwnsActionArea = m_pActionArea == NULL;
591 if (m_bOwnsActionArea)
593 m_pActionArea = new VclHButtonBox(m_pBox);
594 set_action_area(m_pActionArea);
597 m_pOKBtn = m_pUIBuilder ? m_pUIBuilder->get<OKButton>("ok") : NULL;
598 m_bOwnsOKBtn = m_pOKBtn == NULL;
599 if (m_bOwnsOKBtn)
600 m_pOKBtn = new OKButton(m_pActionArea);
602 m_pApplyBtn = m_pUIBuilder ? m_pUIBuilder->get<PushButton>("apply") : NULL;
603 m_bOwnsApplyBtn = m_pApplyBtn == NULL;
604 if (m_bOwnsApplyBtn)
605 m_pApplyBtn = NULL;
607 m_pUserBtn = m_pUIBuilder ? m_pUIBuilder->get<PushButton>("user") : NULL;
608 m_bOwnsUserBtn = m_pUserBtn == NULL;
609 if (m_bOwnsUserBtn)
610 m_pUserBtn = pUserButtonText ? new PushButton(m_pActionArea) : NULL;
612 m_pCancelBtn = m_pUIBuilder ? m_pUIBuilder->get<CancelButton>("cancel") : NULL;
613 m_bOwnsCancelBtn = m_pCancelBtn == NULL;
614 if (m_bOwnsCancelBtn)
615 m_pCancelBtn = new CancelButton(m_pActionArea);
617 m_pHelpBtn = m_pUIBuilder ? m_pUIBuilder->get<HelpButton>("help") : NULL;
618 m_bOwnsHelpBtn = m_pHelpBtn == NULL;
619 if (m_bOwnsHelpBtn)
620 m_pHelpBtn = new HelpButton(m_pActionArea);
622 m_pResetBtn = m_pUIBuilder ? m_pUIBuilder->get<PushButton>("reset") : NULL;
623 m_bOwnsResetBtn = m_pResetBtn == NULL;
624 if (m_bOwnsResetBtn)
625 m_pResetBtn = new PushButton(m_pActionArea);
627 m_pBaseFmtBtn = m_pUIBuilder ? m_pUIBuilder->get<PushButton>("standard") : NULL;
628 m_bOwnsBaseFmtBtn = m_pBaseFmtBtn == NULL;
629 if (m_bOwnsBaseFmtBtn)
630 m_pBaseFmtBtn = new PushButton(m_pActionArea);
632 pImpl = new TabDlg_Impl(m_pTabCtrl->GetPageCount());
634 m_pOKBtn->SetClickHdl( LINK( this, SfxTabDialog, OkHdl ) );
635 m_pCancelBtn->SetClickHdl( LINK( this, SfxTabDialog, CancelHdl ) );
636 m_pResetBtn->SetClickHdl( LINK( this, SfxTabDialog, ResetHdl ) );
637 m_pResetBtn->SetText( SfxResId( STR_RESET ).toString() );
638 m_pTabCtrl->SetActivatePageHdl(
639 LINK( this, SfxTabDialog, ActivatePageHdl ) );
640 m_pTabCtrl->SetDeactivatePageHdl(
641 LINK( this, SfxTabDialog, DeactivatePageHdl ) );
642 m_pActionArea->Show();
643 m_pBox->Show();
644 m_pTabCtrl->Show();
645 m_pOKBtn->Show();
646 m_pCancelBtn->Show();
647 m_pHelpBtn->Show();
648 m_pResetBtn->Show();
649 m_pResetBtn->SetHelpId( HID_TABDLG_RESET_BTN );
651 if ( m_pUserBtn )
653 if (pUserButtonText)
654 m_pUserBtn->SetText(*pUserButtonText);
655 m_pUserBtn->SetClickHdl( LINK( this, SfxTabDialog, UserHdl ) );
656 m_pUserBtn->Show();
659 /* TODO: Check what is up with bFmt/bFmtFlag. Comment below suggests a
660 different behavior than implemented!! */
661 if ( bFmtFlag )
663 m_pBaseFmtBtn->SetText( SfxResId( STR_STANDARD_SHORTCUT ).toString() );
664 m_pBaseFmtBtn->SetClickHdl( LINK( this, SfxTabDialog, BaseFmtHdl ) );
665 m_pBaseFmtBtn->SetHelpId( HID_TABDLG_STANDARD_BTN );
667 // bFmt = temporary Flag passed on in the Constructor(),
668 // if bFmt == 2, then also sal_True,
669 // additional suppression of the standard button,
670 // after the Initializing set to sal_True again
671 if ( bFmtFlag != 2 )
672 m_pBaseFmtBtn->Show();
673 else
674 bFmtFlag = sal_True;
677 if ( pSet )
679 pExampleSet = new SfxItemSet( *pSet );
680 pOutSet = new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() );
683 m_pOKBtn->SetAccessibleRelationMemberOf( m_pOKBtn );
684 m_pCancelBtn->SetAccessibleRelationMemberOf( m_pCancelBtn );
685 m_pHelpBtn->SetAccessibleRelationMemberOf( m_pHelpBtn );
686 m_pResetBtn->SetAccessibleRelationMemberOf( m_pResetBtn );
689 // -----------------------------------------------------------------------
691 void SfxTabDialog::RemoveResetButton()
693 m_pResetBtn->Hide();
694 pImpl->bHideResetBtn = sal_True;
697 // -----------------------------------------------------------------------
699 short SfxTabDialog::Execute()
701 if ( !m_pTabCtrl->GetPageCount() )
702 return RET_CANCEL;
703 Start_Impl();
704 return TabDialog::Execute();
707 // -----------------------------------------------------------------------
709 void SfxTabDialog::StartExecuteModal( const Link& rEndDialogHdl )
711 if ( !m_pTabCtrl->GetPageCount() )
712 return;
713 Start_Impl();
714 TabDialog::StartExecuteModal( rEndDialogHdl );
717 // -----------------------------------------------------------------------
719 void SfxTabDialog::Start( sal_Bool bShow )
721 pImpl->bModal = sal_False;
722 Start_Impl();
724 if ( bShow )
725 Show();
728 // -----------------------------------------------------------------------
730 void SfxTabDialog::SetApplyHandler(const Link& _rHdl)
732 DBG_ASSERT( m_pApplyBtn, "SfxTabDialog::GetApplyHandler: no apply button enabled!" );
733 if ( m_pApplyBtn )
734 m_pApplyBtn->SetClickHdl( _rHdl );
737 // -----------------------------------------------------------------------
739 void SfxTabDialog::EnableApplyButton(sal_Bool bEnable)
741 if ( IsApplyButtonEnabled() == bEnable )
742 // nothing to do
743 return;
745 // create or remove the apply button
746 if ( bEnable )
748 m_pApplyBtn = new PushButton(m_pActionArea);
749 // in the z-order, the apply button should be behind the ok button, thus appearing at the right side of it
750 m_pApplyBtn->SetZOrder(m_pOKBtn, WINDOW_ZORDER_BEHIND);
751 m_pApplyBtn->SetText(SfxResId( STR_APPLY ).toString());
752 m_pApplyBtn->Show();
754 m_pApplyBtn->SetHelpId( HID_TABDLG_APPLY_BTN );
756 else
758 delete m_pApplyBtn;
759 m_pApplyBtn = NULL;
762 // adjust the layout
763 if (IsReallyShown())
764 AdjustLayout();
767 // -----------------------------------------------------------------------
769 sal_Bool SfxTabDialog::IsApplyButtonEnabled() const
771 return ( NULL != m_pApplyBtn );
774 // -----------------------------------------------------------------------
776 void SfxTabDialog::Start_Impl()
778 DBG_ASSERT( pImpl->aData.size() == m_pTabCtrl->GetPageCount(), "not all pages registered" );
779 sal_uInt16 nActPage = m_pTabCtrl->GetPageId( 0 );
781 // load old settings, when exists
782 SvtViewOptions aDlgOpt( E_TABDIALOG, OUString::number( nResId ) );
783 if ( aDlgOpt.Exists() )
785 SetWindowState(OUStringToOString(aDlgOpt.GetWindowState().getStr(), RTL_TEXTENCODING_ASCII_US));
787 // initial TabPage from Program/Help/config
788 nActPage = (sal_uInt16)aDlgOpt.GetPageID();
790 if ( USHRT_MAX != nAppPageId )
791 nActPage = nAppPageId;
792 else
794 sal_uInt16 nAutoTabPageId = SFX_APP()->Get_Impl()->nAutoTabPageId;
795 if ( nAutoTabPageId )
796 nActPage = nAutoTabPageId;
799 if ( TAB_PAGE_NOTFOUND == m_pTabCtrl->GetPagePos( nActPage ) )
800 nActPage = m_pTabCtrl->GetPageId( 0 );
802 else if ( USHRT_MAX != nAppPageId && TAB_PAGE_NOTFOUND != m_pTabCtrl->GetPagePos( nAppPageId ) )
803 nActPage = nAppPageId;
805 m_pTabCtrl->SetCurPageId( nActPage );
806 ActivatePageHdl( m_pTabCtrl );
809 void SfxTabDialog::AddTabPage( sal_uInt16 nId, sal_Bool bItemsOnDemand )
811 AddTabPage( nId, 0, 0, bItemsOnDemand );
814 void SfxTabDialog::AddTabPage( sal_uInt16 nId, const String &rRiderText, sal_Bool bItemsOnDemand, sal_uInt16 nPos )
816 AddTabPage( nId, rRiderText, 0, 0, bItemsOnDemand, nPos );
819 #ifdef SV_HAS_RIDERBITMAPS
821 void SfxTabDialog::AddTabPage( sal_uInt16 nId, const Bitmap &rRiderBitmap, sal_Bool bItemsOnDemand, sal_uInt16 nPos )
823 AddTabPage( nId, rRiderBitmap, 0, 0, bItemsOnDemand, nPos );
826 #endif
828 // -----------------------------------------------------------------------
830 void SfxTabDialog::AddTabPage
832 /* [Description]
834 Adding a page to the dialogue. Must correspond to a entry in the
835 TabControl in the resource of the dialogue.
839 sal_uInt16 nId, // Page ID
840 CreateTabPage pCreateFunc, // Pointer to the Factory Method
841 GetTabPageRanges pRangesFunc, // Pointer to the Method for quering
842 // Ranges onDemand
843 sal_Bool bItemsOnDemand // indicates whether the set of this page is
844 // requested when created
847 pImpl->aData.push_back(
848 new Data_Impl( nId, pCreateFunc, pRangesFunc, bItemsOnDemand ) );
853 Adds a page to the dialog. The Name must correspond to a entry in the
854 TabControl in the dialog .ui
856 sal_uInt16 SfxTabDialog::AddTabPage
858 const OString &rName, // Page ID
859 CreateTabPage pCreateFunc, // Pointer to the Factory Method
860 GetTabPageRanges pRangesFunc, // Pointer to the Method for quering
861 // Ranges onDemand
862 sal_Bool bItemsOnDemand // indicates whether the set of this page is
863 // requested when created
866 sal_uInt16 nId = m_pTabCtrl->GetPageId(rName);
867 pImpl->aData.push_back(
868 new Data_Impl( nId, pCreateFunc, pRangesFunc, bItemsOnDemand ) );
869 return nId;
873 Adds a page to the dialog. The Name must correspond to a entry in the
874 TabControl in the dialog .ui
876 sal_uInt16 SfxTabDialog::AddTabPage
878 const OString &rName, // Page ID
879 sal_uInt16 nPageCreateId // Identifier of the Factory Method to create the page
882 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
883 assert(pFact);
884 CreateTabPage pCreateFunc = pFact->GetTabPageCreatorFunc(nPageCreateId);
885 assert(pCreateFunc);
886 GetTabPageRanges pRangesFunc = pFact->GetTabPageRangesFunc(nPageCreateId);
887 sal_uInt16 nPageId = m_pTabCtrl->GetPageId(rName);
888 pImpl->aData.push_back(new Data_Impl(nPageId, pCreateFunc, pRangesFunc, false));
889 return nPageId;
892 // -----------------------------------------------------------------------
894 void SfxTabDialog::AddTabPage
896 /* [Description]
898 Add a page to the dialog. The Rider text is passed on, the page has no
899 counterpart in the TabControl in the resource of the dialogue.
903 sal_uInt16 nId,
904 const String& rRiderText,
905 CreateTabPage pCreateFunc,
906 GetTabPageRanges pRangesFunc,
907 sal_Bool bItemsOnDemand,
908 sal_uInt16 nPos
911 DBG_ASSERT( TAB_PAGE_NOTFOUND == m_pTabCtrl->GetPagePos( nId ),
912 "Double Page-Ids in the Tabpage" );
913 m_pTabCtrl->InsertPage( nId, rRiderText, nPos );
914 pImpl->aData.push_back(
915 new Data_Impl( nId, pCreateFunc, pRangesFunc, bItemsOnDemand ) );
918 // -----------------------------------------------------------------------
919 #ifdef SV_HAS_RIDERBITMAPS
921 void SfxTabDialog::AddTabPage
923 /* [Description]
925 Add a page to the dialog. The riders bitmap is passed on, the page has no
926 counterpart in the TabControl in the resource of the dialogue.
930 sal_uInt16 nId,
931 const Bitmap &rRiderBitmap,
932 CreateTabPage pCreateFunc,
933 GetTabPageRanges pRangesFunc,
934 sal_Bool bItemsOnDemand,
935 sal_uInt16 nPos
938 DBG_ASSERT( TAB_PAGE_NOTFOUND == m_pTabCtrl->GetPagePos( nId ),
939 "Duplicate Page-Ids in the Tabpage" );
940 m_pTabCtrl->InsertPage( nId, rRiderBitmap, nPos );
941 pImpl->aData.push_back(
942 new Data_Impl( nId, pCreateFunc, pRangesFunc, bItemsOnDemand ) );
944 #endif
946 // -----------------------------------------------------------------------
948 void SfxTabDialog::RemoveTabPage( sal_uInt16 nId )
950 /* [Description]
952 Delete the TabPage with ID nId
956 sal_uInt16 nPos = 0;
957 m_pTabCtrl->RemovePage( nId );
958 Data_Impl* pDataObject = Find( pImpl->aData, nId, &nPos );
960 if ( pDataObject )
962 if ( pDataObject->pTabPage )
964 pDataObject->pTabPage->FillUserData();
965 String aPageData( pDataObject->pTabPage->GetUserData() );
966 if ( aPageData.Len() )
968 // save settings of this page (user data)
969 SvtViewOptions aPageOpt( E_TABPAGE, OUString::number( pDataObject->nId ) );
970 aPageOpt.SetUserItem( USERITEM_NAME, makeAny( OUString( aPageData ) ) );
973 if ( pDataObject->bOnDemand )
974 delete (SfxItemSet*)&pDataObject->pTabPage->GetItemSet();
975 delete pDataObject->pTabPage;
978 delete pDataObject;
979 pImpl->aData.erase( pImpl->aData.begin() + nPos );
981 else
983 SAL_INFO( "sfx2.dialog", "TabPage-Id not known" );
987 void SfxTabDialog::RemoveTabPage(const OString &rName)
989 RemoveTabPage(m_pTabCtrl->GetPageId(rName));
992 // -----------------------------------------------------------------------
994 void SfxTabDialog::PageCreated
996 /* [Description]
998 Default implemetation of the virtual method. This is called immediately
999 after creating a page. Here the dialogue can call the TabPage Method
1000 directly.
1004 sal_uInt16, // Id of the created page
1005 SfxTabPage& // Reference to the created page
1010 // -----------------------------------------------------------------------
1012 SfxItemSet* SfxTabDialog::GetInputSetImpl()
1014 /* [Description]
1016 Derived classes may create new storage for the InputSet. This has to be
1017 released in the Destructor. To do this, this method must be called.
1021 return (SfxItemSet*)pSet;
1024 // -----------------------------------------------------------------------
1026 SfxTabPage* SfxTabDialog::GetTabPage( sal_uInt16 nPageId ) const
1028 /* [Description]
1030 Return TabPage with the specified Id.
1034 sal_uInt16 nPos = 0;
1035 Data_Impl* pDataObject = Find( pImpl->aData, nPageId, &nPos );
1037 if ( pDataObject )
1038 return pDataObject->pTabPage;
1039 return NULL;
1042 void SfxTabDialog::SavePosAndId()
1044 // save settings (screen position and current page)
1045 SvtViewOptions aDlgOpt( E_TABDIALOG, OUString::number( nResId ) );
1046 aDlgOpt.SetWindowState(OStringToOUString(GetWindowState(WINDOWSTATE_MASK_POS),RTL_TEXTENCODING_ASCII_US));
1047 aDlgOpt.SetPageID( m_pTabCtrl->GetCurPageId() );
1050 // -----------------------------------------------------------------------
1052 short SfxTabDialog::Ok()
1054 /* [Description]
1056 Ok handler for the Dialogue.
1058 Dialog's current location and current page are saved for the next time
1059 the dialog is shown.
1061 The OutputSet is created and for each page this or the special OutputSet
1062 is set by calling the method <SfxTabPage::FillItemSet(SfxItemSet &)>, to
1063 insert the entered data by the user into the set.
1065 [Return value]
1067 RET_OK: if at least one page has returned from FillItemSet,
1068 otherwise RET_CANCEL.
1072 SavePosAndId(); //See fdo#38828 "Apply" resetting window position
1074 if ( !pOutSet )
1076 if ( !pExampleSet && pSet )
1077 pOutSet = pSet->Clone( sal_False ); // without Items
1078 else if ( pExampleSet )
1079 pOutSet = new SfxItemSet( *pExampleSet );
1081 sal_Bool bModified = sal_False;
1083 for ( SfxTabDlgData_Impl::const_iterator it = pImpl->aData.begin(); it != pImpl->aData.end(); ++it )
1085 Data_Impl* pDataObject = *it;
1086 SfxTabPage* pTabPage = pDataObject->pTabPage;
1088 if ( pTabPage )
1090 if ( pDataObject->bOnDemand )
1092 SfxItemSet& rSet = (SfxItemSet&)pTabPage->GetItemSet();
1093 rSet.ClearItem();
1094 bModified |= pTabPage->FillItemSet( rSet );
1096 else if ( pSet && !pTabPage->HasExchangeSupport() )
1098 SfxItemSet aTmp( *pSet->GetPool(), pSet->GetRanges() );
1100 if ( pTabPage->FillItemSet( aTmp ) )
1102 bModified |= sal_True;
1103 pExampleSet->Put( aTmp );
1104 pOutSet->Put( aTmp );
1110 if ( pImpl->bModified || ( pOutSet && pOutSet->Count() > 0 ) )
1111 bModified |= sal_True;
1113 if ( bFmt == 2 )
1114 bModified |= sal_True;
1115 return bModified ? RET_OK : RET_CANCEL;
1118 // -----------------------------------------------------------------------
1120 IMPL_LINK_NOARG(SfxTabDialog, CancelHdl)
1122 EndDialog( RET_USER_CANCEL );
1123 return 0;
1126 // -----------------------------------------------------------------------
1128 SfxItemSet* SfxTabDialog::CreateInputItemSet( sal_uInt16 )
1130 /* [Description]
1132 Default implemetation of the virtual Method.
1133 This is called when pages create their sets onDenamd.
1137 SAL_WARN( "sfx2.dialog", "CreateInputItemSet not implemented" );
1138 return new SfxAllItemSet( SFX_APP()->GetPool() );
1141 // -----------------------------------------------------------------------
1143 const SfxItemSet* SfxTabDialog::GetRefreshedSet()
1145 /* [Description]
1147 Default implemetation of the virtual Method.
1148 This is called, when <SfxTabPage::DeactivatePage(SfxItemSet *)>
1149 returns <SfxTabPage::REFRESH_SET>.
1153 SAL_INFO ( "sfx2.dialog", "GetRefreshedSet not implemented" );
1154 return 0;
1157 // -----------------------------------------------------------------------
1159 IMPL_LINK_NOARG(SfxTabDialog, OkHdl)
1161 /* [Description]
1163 Handler of the Ok-Buttons
1164 This calls the current page <SfxTabPage::DeactivatePage(SfxItemSet *)>.
1165 Returns <SfxTabPage::LEAVE_PAGE>, <SfxTabDialog::Ok()> is called
1166 and the Dialog is ended.
1170 if (PrepareLeaveCurrentPage())
1172 if ( pImpl->bModal )
1173 EndDialog( Ok() );
1174 else
1176 Ok();
1177 Close();
1180 return 0;
1183 bool SfxTabDialog::Apply()
1185 bool bApplied = false;
1186 if (PrepareLeaveCurrentPage())
1187 bApplied = (Ok() == RET_OK);
1188 return bApplied;
1191 // -----------------------------------------------------------------------
1193 bool SfxTabDialog::PrepareLeaveCurrentPage()
1195 sal_uInt16 const nId = m_pTabCtrl->GetCurPageId();
1196 SfxTabPage* pPage = dynamic_cast<SfxTabPage*> (m_pTabCtrl->GetTabPage( nId ));
1197 bool bEnd = !pPage;
1199 if ( pPage )
1201 int nRet = SfxTabPage::LEAVE_PAGE;
1202 if ( pSet )
1204 SfxItemSet aTmp( *pSet->GetPool(), pSet->GetRanges() );
1206 if ( pPage->HasExchangeSupport() )
1207 nRet = pPage->DeactivatePage( &aTmp );
1208 else
1209 nRet = pPage->DeactivatePage( NULL );
1211 if ( ( SfxTabPage::LEAVE_PAGE & nRet ) == SfxTabPage::LEAVE_PAGE
1212 && aTmp.Count() )
1214 pExampleSet->Put( aTmp );
1215 pOutSet->Put( aTmp );
1218 else
1219 nRet = pPage->DeactivatePage( NULL );
1220 bEnd = nRet;
1223 return bEnd;
1227 // -----------------------------------------------------------------------
1229 IMPL_LINK_NOARG(SfxTabDialog, UserHdl)
1231 /* [Description]
1233 Handler of the User-Buttons
1234 This calls the current page <SfxTabPage::DeactivatePage(SfxItemSet *)>.
1235 returns this <SfxTabPage::LEAVE_PAGE> and <SfxTabDialog::Ok()> is called.
1236 Then the Dialog is ended with the Return value <SfxTabDialog::Ok()>
1240 if ( PrepareLeaveCurrentPage () )
1242 short nRet = Ok();
1244 if ( RET_OK == nRet )
1245 nRet = RET_USER;
1246 else
1247 nRet = RET_USER_CANCEL;
1248 EndDialog( nRet );
1250 return 0;
1253 // -----------------------------------------------------------------------
1255 IMPL_LINK_NOARG(SfxTabDialog, ResetHdl)
1257 /* [Description]
1259 Handler behind the reset button.
1260 The Current Page is new initialized with their initial data, all the
1261 settings that the user has made on this page are repealed.
1265 const sal_uInt16 nId = m_pTabCtrl->GetCurPageId();
1266 Data_Impl* pDataObject = Find( pImpl->aData, nId );
1267 DBG_ASSERT( pDataObject, "Id not known" );
1269 if ( pDataObject->bOnDemand )
1271 // CSet on AIS has problems here, thus separated
1272 const SfxItemSet* pItemSet = &pDataObject->pTabPage->GetItemSet();
1273 pDataObject->pTabPage->Reset( *(SfxItemSet*)pItemSet );
1275 else
1276 pDataObject->pTabPage->Reset( *pSet );
1277 return 0;
1280 // -----------------------------------------------------------------------
1282 IMPL_LINK_NOARG(SfxTabDialog, BaseFmtHdl)
1284 /* [Description]
1286 Handler behind the Standard-Button.
1287 This button is available when editing style sheets. All the set attributes
1288 in the edited stylesheet are deleted.
1292 const sal_uInt16 nId = m_pTabCtrl->GetCurPageId();
1293 Data_Impl* pDataObject = Find( pImpl->aData, nId );
1294 DBG_ASSERT( pDataObject, "Id not known" );
1295 bFmt = 2;
1297 if ( pDataObject->fnGetRanges )
1299 if ( !pExampleSet )
1300 pExampleSet = new SfxItemSet( *pSet );
1302 const SfxItemPool* pPool = pSet->GetPool();
1303 const sal_uInt16* pTmpRanges = (pDataObject->fnGetRanges)();
1304 SfxItemSet aTmpSet( *pExampleSet );
1306 while ( *pTmpRanges )
1308 const sal_uInt16* pU = pTmpRanges + 1;
1310 if ( *pTmpRanges == *pU )
1312 // Range which two identical values -> only set one Item
1313 sal_uInt16 nWh = pPool->GetWhich( *pTmpRanges );
1314 pExampleSet->ClearItem( nWh );
1315 aTmpSet.ClearItem( nWh );
1316 // At the Outset of InvalidateItem,
1317 // so that the change takes effect
1318 pOutSet->InvalidateItem( nWh );
1320 else
1322 // Correct Range with multiple values
1323 sal_uInt16 nTmp = *pTmpRanges, nTmpEnd = *pU;
1324 DBG_ASSERT( nTmp <= nTmpEnd, "Range is sorted the wrong way" );
1326 if ( nTmp > nTmpEnd )
1328 // If really sorted wrongly, then set new
1329 sal_uInt16 nTmp1 = nTmp;
1330 nTmp = nTmpEnd;
1331 nTmpEnd = nTmp1;
1334 while ( nTmp <= nTmpEnd )
1336 // Iterate over the Range and set the Items
1337 sal_uInt16 nWh = pPool->GetWhich( nTmp );
1338 pExampleSet->ClearItem( nWh );
1339 aTmpSet.ClearItem( nWh );
1340 // At the Outset of InvalidateItem,
1341 // so that the change takes effect
1342 pOutSet->InvalidateItem( nWh );
1343 nTmp++;
1346 // Go to the next pair
1347 pTmpRanges += 2;
1349 // Set all Items as new -> the call the current Page Reset()
1350 DBG_ASSERT( pDataObject->pTabPage, "the Page is gone" );
1351 pDataObject->pTabPage->Reset( aTmpSet );
1352 pDataObject->pTabPage->pImpl->mbStandard = sal_True;
1354 return 1;
1357 // -----------------------------------------------------------------------
1359 IMPL_LINK( SfxTabDialog, ActivatePageHdl, TabControl *, pTabCtrl )
1361 /* [Description]
1363 Handler that is called by StarView for switching to a different page.
1364 If the page not exist yet then it is created and the virtual Method
1365 <SfxTabDialog::PageCreated( sal_uInt16, SfxTabPage &)> is called. If the page
1366 exist, then the if possible the <SfxTabPage::Reset(const SfxItemSet &)> or
1367 <SfxTabPage::ActivatePage(const SfxItemSet &)> is called.
1371 sal_uInt16 const nId = pTabCtrl->GetCurPageId();
1373 DBG_ASSERT( pImpl->aData.size(), "no Pages registered" );
1374 SFX_APP();
1376 // Tab Page schon da?
1377 SfxTabPage* pTabPage = dynamic_cast<SfxTabPage*> (pTabCtrl->GetTabPage( nId ));
1378 Data_Impl* pDataObject = Find( pImpl->aData, nId );
1379 DBG_ASSERT( pDataObject, "Id not known" );
1381 // Create TabPage if possible:
1382 if ( !pTabPage )
1384 const SfxItemSet* pTmpSet = 0;
1386 if ( pSet )
1388 if ( bItemsReset && pSet->GetParent() )
1389 pTmpSet = pSet->GetParent();
1390 else
1391 pTmpSet = pSet;
1394 if ( pTmpSet && !pDataObject->bOnDemand )
1395 pTabPage = (pDataObject->fnCreatePage)( pTabCtrl, *pTmpSet );
1396 else
1397 pTabPage = (pDataObject->fnCreatePage)
1398 ( pTabCtrl, *CreateInputItemSet( nId ) );
1399 DBG_ASSERT( NULL == pDataObject->pTabPage, "create TabPage more than once" );
1400 pDataObject->pTabPage = pTabPage;
1402 pDataObject->pTabPage->SetTabDialog( this );
1403 SvtViewOptions aPageOpt( E_TABPAGE, OUString::number( pDataObject->nId ) );
1404 String sUserData;
1405 Any aUserItem = aPageOpt.GetUserItem( USERITEM_NAME );
1406 OUString aTemp;
1407 if ( aUserItem >>= aTemp )
1408 sUserData = String( aTemp );
1409 pTabPage->SetUserData( sUserData );
1410 Size aSiz = pTabPage->GetSizePixel();
1412 Size aCtrlSiz = pTabCtrl->GetTabPageSizePixel();
1413 // Only set Size on TabControl when < as TabPage
1414 if ( aCtrlSiz.Width() < aSiz.Width() ||
1415 aCtrlSiz.Height() < aSiz.Height() )
1417 pTabCtrl->SetTabPageSizePixel( aSiz );
1420 PageCreated( nId, *pTabPage );
1422 if ( pDataObject->bOnDemand )
1423 pTabPage->Reset( (SfxItemSet &)pTabPage->GetItemSet() );
1424 else
1425 pTabPage->Reset( *pSet );
1427 pTabCtrl->SetTabPage( nId, pTabPage );
1429 else if ( pDataObject->bRefresh )
1430 pTabPage->Reset( *pSet );
1431 pDataObject->bRefresh = sal_False;
1433 if ( pExampleSet )
1434 pTabPage->ActivatePage( *pExampleSet );
1435 sal_Bool bReadOnly = pTabPage->IsReadOnly();
1436 ( bReadOnly || pImpl->bHideResetBtn ) ? m_pResetBtn->Hide() : m_pResetBtn->Show();
1437 return 0;
1440 // -----------------------------------------------------------------------
1442 IMPL_LINK( SfxTabDialog, DeactivatePageHdl, TabControl *, pTabCtrl )
1444 /* [Description]
1446 Handler that is called by StarView before leaving a page.
1448 [Cross-reference]
1450 <SfxTabPage::DeactivatePage(SfxItemSet *)>
1454 sal_uInt16 nId = pTabCtrl->GetCurPageId();
1455 SFX_APP();
1456 SfxTabPage *pPage = dynamic_cast<SfxTabPage*> (pTabCtrl->GetTabPage( nId ));
1457 DBG_ASSERT( pPage, "no active Page" );
1458 #ifdef DBG_UTIL
1459 Data_Impl* pDataObject = Find( pImpl->aData, pTabCtrl->GetCurPageId() );
1460 DBG_ASSERT( pDataObject, "no Data structur for current page" );
1461 if ( pPage->HasExchangeSupport() && pDataObject->bOnDemand )
1463 DBG_WARNING( "Data exchange in ItemsOnDemand is not desired!" );
1465 #endif
1467 int nRet = SfxTabPage::LEAVE_PAGE;
1469 if ( !pExampleSet && pPage->HasExchangeSupport() && pSet )
1470 pExampleSet = new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() );
1472 if ( pSet )
1474 SfxItemSet aTmp( *pSet->GetPool(), pSet->GetRanges() );
1476 if ( pPage->HasExchangeSupport() )
1477 nRet = pPage->DeactivatePage( &aTmp );
1478 else
1479 nRet = pPage->DeactivatePage( NULL );
1480 if ( ( SfxTabPage::LEAVE_PAGE & nRet ) == SfxTabPage::LEAVE_PAGE &&
1481 aTmp.Count() )
1483 pExampleSet->Put( aTmp );
1484 pOutSet->Put( aTmp );
1487 else
1489 if ( pPage->HasExchangeSupport() ) //!!!
1491 if ( !pExampleSet )
1493 SfxItemPool* pPool = pPage->GetItemSet().GetPool();
1494 pExampleSet =
1495 new SfxItemSet( *pPool, GetInputRanges( *pPool ) );
1497 nRet = pPage->DeactivatePage( pExampleSet );
1499 else
1500 nRet = pPage->DeactivatePage( NULL );
1503 if ( nRet & SfxTabPage::REFRESH_SET )
1505 pSet = GetRefreshedSet();
1506 DBG_ASSERT( pSet, "GetRefreshedSet() returns NULL" );
1507 // Flag all Pages as to be initialized as new
1509 for ( SfxTabDlgData_Impl::const_iterator it = pImpl->aData.begin(); it != pImpl->aData.end(); ++it )
1511 Data_Impl* pObj = *it;
1513 if ( pObj->pTabPage != pPage ) // Do not refresh own Page anymore
1514 pObj->bRefresh = sal_True;
1515 else
1516 pObj->bRefresh = sal_False;
1519 if ( nRet & SfxTabPage::LEAVE_PAGE )
1520 return sal_True;
1521 else
1522 return sal_False;
1525 // -----------------------------------------------------------------------
1527 void SfxTabDialog::ShowPage( sal_uInt16 nId )
1529 /* [Description]
1531 The TabPage is activated with the specified Id.
1535 m_pTabCtrl->SetCurPageId( nId );
1536 ActivatePageHdl( m_pTabCtrl );
1539 // -----------------------------------------------------------------------
1541 const sal_uInt16* SfxTabDialog::GetInputRanges( const SfxItemPool& rPool )
1543 /* [Description]
1545 Makes the set over the range of all pages of the dialogue. Pages have the
1546 static method for querying their range in AddTabPage, ie deliver their
1547 sets onDemand.
1549 [Return value]
1551 Pointer to a null-terminated array of sal_uInt16. This array belongs to the
1552 dialog and is deleted when the dialogue is destroy.
1554 [Cross-reference]
1556 <SfxTabDialog::AddTabPage(sal_uInt16, CreateTabPage, GetTabPageRanges, sal_Bool)>
1557 <SfxTabDialog::AddTabPage(sal_uInt16, const String &, CreateTabPage, GetTabPageRanges, sal_Bool, sal_uInt16)>
1558 <SfxTabDialog::AddTabPage(sal_uInt16, const Bitmap &, CreateTabPage, GetTabPageRanges, sal_Bool, sal_uInt16)>
1562 if ( pSet )
1564 SAL_WARN( "sfx2.dialog", "Set already exists!" );
1565 return pSet->GetRanges();
1568 if ( pRanges )
1569 return pRanges;
1570 std::vector<sal_uInt16> aUS;
1572 for ( SfxTabDlgData_Impl::const_iterator it = pImpl->aData.begin(); it != pImpl->aData.end(); ++it )
1574 Data_Impl* pDataObject = *it;
1576 if ( pDataObject->fnGetRanges )
1578 const sal_uInt16* pTmpRanges = (pDataObject->fnGetRanges)();
1579 const sal_uInt16* pIter = pTmpRanges;
1581 sal_uInt16 nLen;
1582 for( nLen = 0; *pIter; ++nLen, ++pIter )
1584 aUS.insert( aUS.end(), pTmpRanges, pTmpRanges + nLen );
1588 //! Remove duplicated Ids?
1590 sal_uInt16 nCount = aUS.size();
1591 for ( sal_uInt16 i = 0; i < nCount; ++i )
1592 aUS[i] = rPool.GetWhich( aUS[i] );
1595 // sort
1596 if ( aUS.size() > 1 )
1598 std::sort( aUS.begin(), aUS.end() );
1601 pRanges = new sal_uInt16[aUS.size() + 1];
1602 std::copy( aUS.begin(), aUS.end(), pRanges );
1603 pRanges[aUS.size()] = 0;
1604 return pRanges;
1607 // -----------------------------------------------------------------------
1609 void SfxTabDialog::SetInputSet( const SfxItemSet* pInSet )
1611 /* [Description]
1613 With this method the Input-Set can subsequently be set initally or re-set.
1617 bool bSet = ( pSet != NULL );
1619 pSet = pInSet;
1621 if ( !bSet && !pExampleSet && !pOutSet )
1623 pExampleSet = new SfxItemSet( *pSet );
1624 pOutSet = new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() );
1628 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */