Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : :
21 : : #include <limits.h>
22 : : #include <stdlib.h>
23 : : #include <algorithm>
24 : : #include <vcl/msgbox.hxx>
25 : : #include <unotools/viewoptions.hxx>
26 : :
27 : : #include "appdata.hxx"
28 : : #include "sfxtypes.hxx"
29 : : #include <sfx2/minarray.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>
39 : :
40 : : #include "dialog.hrc"
41 : : #include "helpid.hrc"
42 : :
43 : : using namespace ::com::sun::star::uno;
44 : : using namespace ::rtl;
45 : :
46 : : #define USERITEM_NAME OUString("UserItem")
47 : :
48 [ # # ][ # # ]: 0 : TYPEINIT1(SfxTabDialogItem,SfxSetItem);
49 : :
50 : 0 : struct TabPageImpl
51 : : {
52 : : sal_Bool mbStandard;
53 : : sfx::ItemConnectionArray maItemConn;
54 : : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > mxFrame;
55 : :
56 : 0 : TabPageImpl() : mbStandard( sal_False ) {}
57 : : };
58 : :
59 : : struct Data_Impl
60 : : {
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
67 : :
68 : : // Constructor
69 : 0 : Data_Impl( sal_uInt16 Id, CreateTabPage fnPage,
70 : : GetTabPageRanges fnRanges, sal_Bool bDemand ) :
71 : :
72 : : nId ( Id ),
73 : : fnCreatePage( fnPage ),
74 : : fnGetRanges ( fnRanges ),
75 : : pTabPage ( 0 ),
76 : : bOnDemand ( bDemand ),
77 : 0 : bRefresh ( sal_False )
78 : : {
79 [ # # ]: 0 : if ( !fnCreatePage )
80 : : {
81 : 0 : SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
82 [ # # ]: 0 : if ( pFact )
83 : : {
84 : 0 : fnCreatePage = pFact->GetTabPageCreatorFunc( nId );
85 : 0 : fnGetRanges = pFact->GetTabPageRangesFunc( nId );
86 : : }
87 : : }
88 : 0 : }
89 : : };
90 : :
91 : 0 : SfxTabDialogItem::SfxTabDialogItem( const SfxTabDialogItem& rAttr, SfxItemPool* pItemPool )
92 : 0 : : SfxSetItem( rAttr, pItemPool )
93 : : {
94 : 0 : }
95 : :
96 : 0 : SfxTabDialogItem::SfxTabDialogItem( sal_uInt16 nId, const SfxItemSet& rItemSet )
97 : 0 : : SfxSetItem( nId, rItemSet )
98 : : {
99 : 0 : }
100 : :
101 : 0 : SfxPoolItem* SfxTabDialogItem::Clone(SfxItemPool* pToPool) const
102 : : {
103 [ # # ]: 0 : return new SfxTabDialogItem( *this, pToPool );
104 : : }
105 : :
106 : 0 : SfxPoolItem* SfxTabDialogItem::Create(SvStream& /*rStream*/, sal_uInt16 /*nVersion*/) const
107 : : {
108 : : OSL_FAIL( "Use it only in UI!" );
109 : 0 : return NULL;
110 : : }
111 : :
112 : : class SfxTabDialogController : public SfxControllerItem
113 : : {
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 )
121 : : {}
122 : :
123 : : ~SfxTabDialogController();
124 : :
125 : : virtual void StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState );
126 : : };
127 : :
128 : 0 : SfxTabDialogController::~SfxTabDialogController()
129 : : {
130 [ # # ][ # # ]: 0 : delete pSet;
131 [ # # ]: 0 : }
132 : :
133 : 0 : void SfxTabDialogController::StateChanged( sal_uInt16 /*nSID*/, SfxItemState /*eState*/, const SfxPoolItem* pState )
134 : : {
135 [ # # ][ # # ]: 0 : const SfxSetItem* pSetItem = PTR_CAST( SfxSetItem, pState );
136 [ # # ]: 0 : if ( pSetItem )
137 : : {
138 : 0 : pSet = pDialog->pSet = pSetItem->GetItemSet().Clone();
139 : 0 : sal_Bool bDialogStarted = sal_False;
140 [ # # ]: 0 : for ( sal_uInt16 n=0; n<pDialog->aTabCtrl.GetPageCount(); n++ )
141 : : {
142 : 0 : sal_uInt16 nPageId = pDialog->aTabCtrl.GetPageId( n );
143 [ # # ]: 0 : SfxTabPage* pTabPage = dynamic_cast<SfxTabPage*> (pDialog->aTabCtrl.GetTabPage( nPageId ));
144 [ # # ]: 0 : if ( pTabPage )
145 : : {
146 : 0 : pTabPage->Reset( pSetItem->GetItemSet() );
147 : 0 : bDialogStarted = sal_True;
148 : : }
149 : : }
150 : :
151 [ # # ]: 0 : if ( bDialogStarted )
152 : 0 : pDialog->Show();
153 : : }
154 : : else
155 : 0 : pDialog->Hide();
156 : 0 : }
157 : :
158 : 0 : DECL_PTRARRAY(SfxTabDlgData_Impl, Data_Impl *, 4,4)
159 : :
160 : : struct TabDlg_Impl
161 : : {
162 : : sal_Bool bModified : 1,
163 : : bModal : 1,
164 : : bInOK : 1,
165 : : bHideResetBtn : 1;
166 : : SfxTabDlgData_Impl* pData;
167 : :
168 : : PushButton* pApplyButton;
169 : : SfxTabDialogController* pController;
170 : :
171 : 0 : TabDlg_Impl( sal_uInt8 nCnt ) :
172 : :
173 : : bModified ( sal_False ),
174 : : bModal ( sal_True ),
175 : : bInOK ( sal_False ),
176 : : bHideResetBtn ( sal_False ),
177 [ # # ]: 0 : pData ( new SfxTabDlgData_Impl( nCnt ) ),
178 : : pApplyButton ( NULL ),
179 : 0 : pController ( NULL )
180 : 0 : {}
181 : : };
182 : :
183 : : Data_Impl* Find( SfxTabDlgData_Impl& rArr, sal_uInt16 nId, sal_uInt16* pPos = 0 );
184 : :
185 : 0 : Data_Impl* Find( SfxTabDlgData_Impl& rArr, sal_uInt16 nId, sal_uInt16* pPos )
186 : : {
187 : 0 : const sal_uInt16 nCount = rArr.Count();
188 : :
189 [ # # ]: 0 : for ( sal_uInt16 i = 0; i < nCount; ++i )
190 : : {
191 : 0 : Data_Impl* pObj = rArr[i];
192 : :
193 [ # # ]: 0 : if ( pObj->nId == nId )
194 : : {
195 [ # # ]: 0 : if ( pPos )
196 : 0 : *pPos = i;
197 : 0 : return pObj;
198 : : }
199 : : }
200 : 0 : return 0;
201 : : }
202 : :
203 : 0 : void SfxTabPage::SetFrame(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame)
204 : : {
205 [ # # ]: 0 : if (pImpl)
206 : 0 : pImpl->mxFrame = xFrame;
207 : 0 : }
208 : :
209 : 0 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > SfxTabPage::GetFrame()
210 : : {
211 [ # # ]: 0 : if (pImpl)
212 : 0 : return pImpl->mxFrame;
213 : 0 : return ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >();
214 : : }
215 : :
216 : 0 : SfxTabPage::SfxTabPage( Window *pParent,
217 : : const ResId &rResId, const SfxItemSet &rAttrSet ) :
218 : :
219 : : /* [Description]
220 : :
221 : : Constructor
222 : : */
223 : :
224 : : TabPage( pParent, rResId ),
225 : :
226 : : pSet ( &rAttrSet ),
227 : : bHasExchangeSupport ( sal_False ),
228 : : pTabDlg ( NULL ),
229 [ # # ][ # # ]: 0 : pImpl ( new TabPageImpl )
[ # # ]
230 : :
231 : : {
232 : 0 : }
233 : : // -----------------------------------------------------------------------
234 : 0 : SfxTabPage:: SfxTabPage( Window *pParent, WinBits nStyle, const SfxItemSet &rAttrSet ) :
235 : : TabPage(pParent, nStyle),
236 : : pSet ( &rAttrSet ),
237 : : bHasExchangeSupport ( sal_False ),
238 : : pTabDlg ( NULL ),
239 [ # # ][ # # ]: 0 : pImpl ( new TabPageImpl )
[ # # ]
240 : : {
241 : 0 : }
242 : : // -----------------------------------------------------------------------
243 : :
244 [ # # ]: 0 : SfxTabPage::~SfxTabPage()
245 : :
246 : : /* [Description]
247 : :
248 : : Destructor
249 : : */
250 : :
251 : : {
252 [ # # ][ # # ]: 0 : delete pImpl;
253 [ # # ]: 0 : }
254 : :
255 : : // -----------------------------------------------------------------------
256 : :
257 : 0 : sal_Bool SfxTabPage::FillItemSet( SfxItemSet& rSet )
258 : : {
259 : 0 : return pImpl->maItemConn.DoFillItemSet( rSet, GetItemSet() );
260 : : }
261 : :
262 : : // -----------------------------------------------------------------------
263 : :
264 : 0 : void SfxTabPage::Reset( const SfxItemSet& rSet )
265 : : {
266 : 0 : pImpl->maItemConn.DoApplyFlags( rSet );
267 : 0 : pImpl->maItemConn.DoReset( rSet );
268 : 0 : }
269 : :
270 : : // -----------------------------------------------------------------------
271 : :
272 : 0 : void SfxTabPage::ActivatePage( const SfxItemSet& )
273 : :
274 : : /* [Description]
275 : :
276 : : Default implementation of the virtual ActivatePage method. This method is
277 : : called when a page of dialogue supports the exchange of data between pages.
278 : : <SfxTabPage::DeactivatePage(SfxItemSet *)>
279 : : */
280 : :
281 : : {
282 : 0 : }
283 : :
284 : : // -----------------------------------------------------------------------
285 : :
286 : 0 : int SfxTabPage::DeactivatePage( SfxItemSet* )
287 : :
288 : : /* [Description]
289 : :
290 : : Default implementation of the virtual DeactivatePage method. This method is
291 : : called by Sfx when leaving a page; the application can, through the return
292 : : value, control whether to leave the page. If the page is displayed through
293 : : bHasExchangeSupport which supports data exchange between pages, then a
294 : : pointer to the exchange set is passed as parameter. This takes on data for
295 : : the exchange, then the set is available as a parameter in
296 : : <SfxTabPage::ActivatePage(const SfxItemSet &)>.
297 : :
298 : : [Return value]
299 : :
300 : : LEAVE_PAGE; Allow leaving the page
301 : : */
302 : :
303 : : {
304 : 0 : return LEAVE_PAGE;
305 : : }
306 : :
307 : : // -----------------------------------------------------------------------
308 : :
309 : 0 : void SfxTabPage::FillUserData()
310 : :
311 : : /* [Description]
312 : :
313 : : Virtual method is called by the base class in the destructor to save
314 : : specific information of the TabPage in the ini-file. When overloading a
315 : : string must be compiled, which is then flushed with the <SetUserData()>.
316 : : */
317 : :
318 : : {
319 : 0 : }
320 : :
321 : : // -----------------------------------------------------------------------
322 : :
323 : 0 : sal_Bool SfxTabPage::IsReadOnly() const
324 : : {
325 : 0 : return sal_False;
326 : : }
327 : :
328 : : // -----------------------------------------------------------------------
329 : :
330 : 0 : const SfxPoolItem* SfxTabPage::GetItem( const SfxItemSet& rSet, sal_uInt16 nSlot, sal_Bool bDeep )
331 : :
332 : : /* [Description]
333 : :
334 : : static Method: hereby are the implementations of the TabPage code
335 : : beeing simplified.
336 : : */
337 : :
338 : : {
339 : 0 : const SfxItemPool* pPool = rSet.GetPool();
340 [ # # ]: 0 : sal_uInt16 nWh = pPool->GetWhich( nSlot, bDeep );
341 : 0 : const SfxPoolItem* pItem = 0;
342 [ # # ]: 0 : rSet.GetItemState( nWh, sal_True, &pItem );
343 : :
344 [ # # ][ # # ]: 0 : if ( !pItem && nWh != nSlot )
345 [ # # ]: 0 : pItem = &pPool->GetDefaultItem( nWh );
346 : 0 : return pItem;
347 : : }
348 : :
349 : : // -----------------------------------------------------------------------
350 : :
351 : 0 : const SfxPoolItem* SfxTabPage::GetOldItem( const SfxItemSet& rSet,
352 : : sal_uInt16 nSlot, sal_Bool bDeep )
353 : :
354 : : /* [Description]
355 : :
356 : : This method returns an attribute for comparison of the old value.
357 : : */
358 : :
359 : : {
360 : 0 : const SfxItemSet& rOldSet = GetItemSet();
361 : 0 : sal_uInt16 nWh = GetWhich( nSlot, bDeep );
362 : 0 : const SfxPoolItem* pItem = 0;
363 : :
364 [ # # ][ # # ]: 0 : if ( pImpl->mbStandard && rOldSet.GetParent() )
[ # # ]
365 : 0 : pItem = GetItem( *rOldSet.GetParent(), nSlot );
366 [ # # # # ]: 0 : else if ( rSet.GetParent() &&
[ # # ]
367 : 0 : SFX_ITEM_DONTCARE == rSet.GetItemState( nWh ) )
368 : 0 : pItem = GetItem( *rSet.GetParent(), nSlot );
369 : : else
370 : 0 : pItem = GetItem( rOldSet, nSlot );
371 : 0 : return pItem;
372 : : }
373 : :
374 : 0 : void SfxTabPage::PageCreated( SfxAllItemSet /*aSet*/ )
375 : : {
376 : : DBG_ASSERT(0, "SfxTabPage::PageCreated should not be called");
377 : 0 : }
378 : :
379 : : // -----------------------------------------------------------------------
380 : :
381 : 0 : void SfxTabPage::AddItemConnection( sfx::ItemConnectionBase* pConnection )
382 : : {
383 : 0 : pImpl->maItemConn.AddConnection( pConnection );
384 : 0 : }
385 : :
386 : : #define INI_LIST(ItemSetPtr) \
387 : : aTabCtrl ( this, ResId(ID_TABCONTROL,*rResId.GetResMgr() ) ),\
388 : : aOKBtn ( this ),\
389 : : pUserBtn ( pUserButtonText? new PushButton(this): 0 ),\
390 : : aCancelBtn ( this ),\
391 : : aHelpBtn ( this ),\
392 : : aResetBtn ( this ),\
393 : : aBaseFmtBtn ( this ),\
394 : : pSet ( ItemSetPtr ),\
395 : : pOutSet ( 0 ),\
396 : : pImpl ( new TabDlg_Impl( (sal_uInt8)aTabCtrl.GetPageCount() ) ), \
397 : : pRanges ( 0 ), \
398 : : nResId ( rResId.GetId() ), \
399 : : nAppPageId ( USHRT_MAX ), \
400 : : bItemsReset ( sal_False ),\
401 : : bFmt ( bEditFmt ),\
402 : : pExampleSet ( 0 )
403 : :
404 : : // -----------------------------------------------------------------------
405 : :
406 : 0 : SfxTabDialog::SfxTabDialog
407 : :
408 : : /* [Description]
409 : :
410 : : Constructor
411 : : */
412 : :
413 : : (
414 : : SfxViewFrame* pViewFrame, // Frame, to which the Dialog belongs
415 : : Window* pParent, // Parent Window
416 : : const ResId& rResId, // ResourceId
417 : : const SfxItemSet* pItemSet, // Itemset with the data;
418 : : // can be NULL, when Pages are onDemand
419 : : sal_Bool bEditFmt, // Flag: templates are processed
420 : : // when yes -> additional Button for standard
421 : : const String* pUserButtonText // Text for UserButton;
422 : : // if != 0, the UserButton is created
423 : : ) :
424 : : TabDialog( pParent, rResId ),
425 : : pFrame( pViewFrame ),
426 [ # # ][ # # ]: 0 : INI_LIST(pItemSet)
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
427 : : {
428 [ # # ]: 0 : Init_Impl( bFmt, pUserButtonText );
429 : 0 : }
430 : :
431 : : // -----------------------------------------------------------------------
432 : :
433 : 0 : SfxTabDialog::SfxTabDialog
434 : :
435 : : /* [Description]
436 : :
437 : : Constructor, temporary without Frame
438 : : */
439 : :
440 : : (
441 : : Window* pParent, // Parent Window
442 : : const ResId& rResId, // ResourceId
443 : : const SfxItemSet* pItemSet, // Itemset with the data;
444 : : // can be NULL, when Pages are onDemand
445 : : sal_Bool bEditFmt, // Flag: templates are processed
446 : : // when yes -> additional Button for standard
447 : : const String* pUserButtonText // Text for UserButton;
448 : : // if != 0, the UserButton is created
449 : : ) :
450 : : TabDialog( pParent, rResId ),
451 : : pFrame( 0 ),
452 [ # # ][ # # ]: 0 : INI_LIST(pItemSet)
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
453 : : {
454 [ # # ]: 0 : Init_Impl( bFmt, pUserButtonText );
455 : : DBG_WARNING( "Please use the Construtor with the ViewFrame" );
456 : 0 : }
457 : :
458 : : // -----------------------------------------------------------------------
459 : :
460 [ # # ][ # # ]: 0 : SfxTabDialog::~SfxTabDialog()
[ # # ][ # # ]
[ # # ][ # # ]
461 : : {
462 [ # # ]: 0 : SavePosAndId();
463 : :
464 : 0 : const sal_uInt16 nCount = pImpl->pData->Count();
465 [ # # ]: 0 : for ( sal_uInt16 i = 0; i < nCount; ++i )
466 : : {
467 [ # # ]: 0 : Data_Impl* pDataObject = pImpl->pData->GetObject(i);
468 : :
469 [ # # ]: 0 : if ( pDataObject->pTabPage )
470 : : {
471 : : // save settings of all pages (user data)
472 [ # # ]: 0 : pDataObject->pTabPage->FillUserData();
473 [ # # ]: 0 : String aPageData( pDataObject->pTabPage->GetUserData() );
474 [ # # ]: 0 : if ( aPageData.Len() )
475 : : {
476 : : // save settings of all pages (user data)
477 [ # # ][ # # ]: 0 : SvtViewOptions aPageOpt( E_TABPAGE, String::CreateFromInt32( pDataObject->nId ) );
[ # # ][ # # ]
478 [ # # ][ # # ]: 0 : aPageOpt.SetUserItem( USERITEM_NAME, makeAny( OUString( aPageData ) ) );
[ # # ][ # # ]
479 : : }
480 : :
481 [ # # ]: 0 : if ( pDataObject->bOnDemand )
482 [ # # ][ # # ]: 0 : delete (SfxItemSet*)&pDataObject->pTabPage->GetItemSet();
483 [ # # ][ # # ]: 0 : delete pDataObject->pTabPage;
[ # # ]
484 : : }
485 : 0 : delete pDataObject;
486 : : }
487 : :
488 [ # # ][ # # ]: 0 : delete pImpl->pController;
489 [ # # ][ # # ]: 0 : delete pImpl->pApplyButton;
490 [ # # ][ # # ]: 0 : delete pImpl->pData;
491 : 0 : delete pImpl;
492 [ # # ][ # # ]: 0 : delete pUserBtn;
493 [ # # ][ # # ]: 0 : delete pOutSet;
494 [ # # ][ # # ]: 0 : delete pExampleSet;
495 [ # # ]: 0 : delete [] pRanges;
496 [ # # ]: 0 : }
497 : :
498 : : // -----------------------------------------------------------------------
499 : :
500 : 0 : void SfxTabDialog::Init_Impl( sal_Bool bFmtFlag, const String* pUserButtonText )
501 : :
502 : : /* [Description]
503 : :
504 : : internal initialization of the dialogue
505 : : */
506 : :
507 : : {
508 : 0 : aOKBtn.SetClickHdl( LINK( this, SfxTabDialog, OkHdl ) );
509 : 0 : aCancelBtn.SetClickHdl( LINK( this, SfxTabDialog, CancelHdl ) );
510 : 0 : aResetBtn.SetClickHdl( LINK( this, SfxTabDialog, ResetHdl ) );
511 [ # # ][ # # ]: 0 : aResetBtn.SetText( SfxResId( STR_RESET ).toString() );
[ # # ][ # # ]
512 : : aTabCtrl.SetActivatePageHdl(
513 : 0 : LINK( this, SfxTabDialog, ActivatePageHdl ) );
514 : : aTabCtrl.SetDeactivatePageHdl(
515 : 0 : LINK( this, SfxTabDialog, DeactivatePageHdl ) );
516 : 0 : aTabCtrl.Show();
517 : 0 : aOKBtn.Show();
518 : 0 : aCancelBtn.Show();
519 : 0 : aHelpBtn.Show();
520 : 0 : aResetBtn.Show();
521 [ # # ]: 0 : aResetBtn.SetHelpId( HID_TABDLG_RESET_BTN );
522 : :
523 [ # # ]: 0 : if ( pUserBtn )
524 : : {
525 : 0 : pUserBtn->SetText( *pUserButtonText );
526 : 0 : pUserBtn->SetClickHdl( LINK( this, SfxTabDialog, UserHdl ) );
527 : 0 : pUserBtn->Show();
528 : : }
529 : :
530 : : /* TODO: Check what is up with bFmt/bFmtFlag. Comment below suggests a
531 : : different behavior than implemented!! */
532 [ # # ]: 0 : if ( bFmtFlag )
533 : : {
534 [ # # ][ # # ]: 0 : aBaseFmtBtn.SetText( SfxResId( STR_STANDARD_SHORTCUT ).toString() );
[ # # ][ # # ]
535 : 0 : aBaseFmtBtn.SetClickHdl( LINK( this, SfxTabDialog, BaseFmtHdl ) );
536 [ # # ]: 0 : aBaseFmtBtn.SetHelpId( HID_TABDLG_STANDARD_BTN );
537 : :
538 : : // bFmt = temporary Flag passed on in the Constructor(),
539 : : // if bFmt == 2, then also sal_True,
540 : : // additional suppression of the standard button,
541 : : // after the Initializing set to sal_True again
542 [ # # ]: 0 : if ( bFmtFlag != 2 )
543 : 0 : aBaseFmtBtn.Show();
544 : : else
545 : 0 : bFmtFlag = sal_True;
546 : : }
547 : :
548 [ # # ]: 0 : if ( pSet )
549 : : {
550 [ # # ]: 0 : pExampleSet = new SfxItemSet( *pSet );
551 [ # # ]: 0 : pOutSet = new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() );
552 : : }
553 : :
554 : 0 : aOKBtn.SetAccessibleRelationMemberOf( &aOKBtn );
555 : 0 : aCancelBtn.SetAccessibleRelationMemberOf( &aCancelBtn );
556 : 0 : aHelpBtn.SetAccessibleRelationMemberOf( &aHelpBtn );
557 : 0 : aResetBtn.SetAccessibleRelationMemberOf( &aResetBtn );
558 : 0 : }
559 : :
560 : : // -----------------------------------------------------------------------
561 : :
562 : 0 : void SfxTabDialog::RemoveResetButton()
563 : : {
564 : 0 : aResetBtn.Hide();
565 : 0 : pImpl->bHideResetBtn = sal_True;
566 : 0 : }
567 : :
568 : : // -----------------------------------------------------------------------
569 : :
570 : 0 : short SfxTabDialog::Execute()
571 : : {
572 [ # # ]: 0 : if ( !aTabCtrl.GetPageCount() )
573 : 0 : return RET_CANCEL;
574 : 0 : Start_Impl();
575 : 0 : return TabDialog::Execute();
576 : : }
577 : :
578 : : // -----------------------------------------------------------------------
579 : :
580 : 0 : void SfxTabDialog::StartExecuteModal( const Link& rEndDialogHdl )
581 : : {
582 [ # # ]: 0 : if ( !aTabCtrl.GetPageCount() )
583 : 0 : return;
584 : 0 : Start_Impl();
585 : 0 : TabDialog::StartExecuteModal( rEndDialogHdl );
586 : : }
587 : :
588 : : // -----------------------------------------------------------------------
589 : :
590 : 0 : void SfxTabDialog::Start( sal_Bool bShow )
591 : : {
592 : 0 : pImpl->bModal = sal_False;
593 : 0 : Start_Impl();
594 : :
595 [ # # ]: 0 : if ( bShow )
596 : 0 : Show();
597 : 0 : }
598 : :
599 : : // -----------------------------------------------------------------------
600 : :
601 : 0 : void SfxTabDialog::SetApplyHandler(const Link& _rHdl)
602 : : {
603 : : DBG_ASSERT( pImpl->pApplyButton, "SfxTabDialog::GetApplyHandler: no apply button enabled!" );
604 [ # # ]: 0 : if ( pImpl->pApplyButton )
605 : 0 : pImpl->pApplyButton->SetClickHdl( _rHdl );
606 : 0 : }
607 : :
608 : : // -----------------------------------------------------------------------
609 : :
610 : 0 : void SfxTabDialog::EnableApplyButton(sal_Bool bEnable)
611 : : {
612 [ # # ]: 0 : if ( IsApplyButtonEnabled() == bEnable )
613 : : // nothing to do
614 : 0 : return;
615 : :
616 : : // create or remove the apply button
617 [ # # ]: 0 : if ( bEnable )
618 : : {
619 [ # # ]: 0 : pImpl->pApplyButton = new PushButton( this );
620 : : // in the z-order, the apply button should be behind the ok button, thus appearing at the right side of it
621 : 0 : pImpl->pApplyButton->SetZOrder(&aOKBtn, WINDOW_ZORDER_BEHIND);
622 [ # # ][ # # ]: 0 : pImpl->pApplyButton->SetText( SfxResId( STR_APPLY ).toString() );
[ # # ][ # # ]
623 : 0 : pImpl->pApplyButton->Show();
624 : :
625 [ # # ]: 0 : pImpl->pApplyButton->SetHelpId( HID_TABDLG_APPLY_BTN );
626 : : }
627 : : else
628 : : {
629 [ # # ]: 0 : delete pImpl->pApplyButton;
630 : 0 : pImpl->pApplyButton = NULL;
631 : : }
632 : :
633 : : // adjust the layout
634 [ # # ]: 0 : if (IsReallyShown())
635 : 0 : AdjustLayout();
636 : : }
637 : :
638 : : // -----------------------------------------------------------------------
639 : :
640 : 0 : sal_Bool SfxTabDialog::IsApplyButtonEnabled() const
641 : : {
642 : 0 : return ( NULL != pImpl->pApplyButton );
643 : : }
644 : :
645 : : // -----------------------------------------------------------------------
646 : :
647 : 0 : void SfxTabDialog::Start_Impl()
648 : : {
649 : : DBG_ASSERT( pImpl->pData->Count() == aTabCtrl.GetPageCount(), "not all pages registered" );
650 [ # # ]: 0 : sal_uInt16 nActPage = aTabCtrl.GetPageId( 0 );
651 : :
652 : : // load old settings, when exists
653 [ # # ][ # # ]: 0 : SvtViewOptions aDlgOpt( E_TABDIALOG, String::CreateFromInt32( nResId ) );
[ # # ][ # # ]
654 [ # # ][ # # ]: 0 : if ( aDlgOpt.Exists() )
655 : : {
656 [ # # ][ # # ]: 0 : SetWindowState(rtl::OUStringToOString(aDlgOpt.GetWindowState().getStr(), RTL_TEXTENCODING_ASCII_US));
[ # # ]
657 : :
658 : : // initial TabPage from Program/Help/config
659 [ # # ]: 0 : nActPage = (sal_uInt16)aDlgOpt.GetPageID();
660 : :
661 [ # # ]: 0 : if ( USHRT_MAX != nAppPageId )
662 : 0 : nActPage = nAppPageId;
663 : : else
664 : : {
665 [ # # ]: 0 : sal_uInt16 nAutoTabPageId = SFX_APP()->Get_Impl()->nAutoTabPageId;
666 [ # # ]: 0 : if ( nAutoTabPageId )
667 : 0 : nActPage = nAutoTabPageId;
668 : : }
669 : :
670 [ # # ][ # # ]: 0 : if ( TAB_PAGE_NOTFOUND == aTabCtrl.GetPagePos( nActPage ) )
671 [ # # ]: 0 : nActPage = aTabCtrl.GetPageId( 0 );
672 : : }
673 [ # # ][ # # ]: 0 : else if ( USHRT_MAX != nAppPageId && TAB_PAGE_NOTFOUND != aTabCtrl.GetPagePos( nAppPageId ) )
[ # # ][ # # ]
674 : 0 : nActPage = nAppPageId;
675 : :
676 [ # # ]: 0 : aTabCtrl.SetCurPageId( nActPage );
677 [ # # ][ # # ]: 0 : ActivatePageHdl( &aTabCtrl );
678 : 0 : }
679 : :
680 : 0 : void SfxTabDialog::AddTabPage( sal_uInt16 nId, sal_Bool bItemsOnDemand )
681 : : {
682 : 0 : AddTabPage( nId, 0, 0, bItemsOnDemand );
683 : 0 : }
684 : :
685 : 0 : void SfxTabDialog::AddTabPage( sal_uInt16 nId, const String &rRiderText, sal_Bool bItemsOnDemand, sal_uInt16 nPos )
686 : : {
687 : 0 : AddTabPage( nId, rRiderText, 0, 0, bItemsOnDemand, nPos );
688 : 0 : }
689 : :
690 : : #ifdef SV_HAS_RIDERBITMAPS
691 : :
692 : : void SfxTabDialog::AddTabPage( sal_uInt16 nId, const Bitmap &rRiderBitmap, sal_Bool bItemsOnDemand, sal_uInt16 nPos )
693 : : {
694 : : AddTabPage( nId, rRiderBitmap, 0, 0, bItemsOnDemand, nPos );
695 : : }
696 : :
697 : : #endif
698 : :
699 : : // -----------------------------------------------------------------------
700 : :
701 : 0 : void SfxTabDialog::AddTabPage
702 : :
703 : : /* [Description]
704 : :
705 : : Adding a page to the dialogue. Must correspond to a entry in the
706 : : TabControl in the resource of the dialogue.
707 : : */
708 : :
709 : : (
710 : : sal_uInt16 nId, // Page ID
711 : : CreateTabPage pCreateFunc, // Pointer to the Factory Method
712 : : GetTabPageRanges pRangesFunc, // Pointer to the Method for quering
713 : : // Ranges onDemand
714 : : sal_Bool bItemsOnDemand // indicates whether the set of this page is
715 : : // requested when created
716 : : )
717 : : {
718 : : pImpl->pData->Append(
719 [ # # ]: 0 : new Data_Impl( nId, pCreateFunc, pRangesFunc, bItemsOnDemand ) );
720 : 0 : }
721 : :
722 : : // -----------------------------------------------------------------------
723 : :
724 : 0 : void SfxTabDialog::AddTabPage
725 : :
726 : : /* [Description]
727 : :
728 : : Add a page to the dialog. The Rider text is passed on, the page has no
729 : : counterpart in the TabControl in the resource of the dialogue.
730 : : */
731 : :
732 : : (
733 : : sal_uInt16 nId,
734 : : const String& rRiderText,
735 : : CreateTabPage pCreateFunc,
736 : : GetTabPageRanges pRangesFunc,
737 : : sal_Bool bItemsOnDemand,
738 : : sal_uInt16 nPos
739 : : )
740 : : {
741 : : DBG_ASSERT( TAB_PAGE_NOTFOUND == aTabCtrl.GetPagePos( nId ),
742 : : "Double Page-Ids in the Tabpage" );
743 : 0 : aTabCtrl.InsertPage( nId, rRiderText, nPos );
744 : : pImpl->pData->Append(
745 [ # # ]: 0 : new Data_Impl( nId, pCreateFunc, pRangesFunc, bItemsOnDemand ) );
746 : 0 : }
747 : :
748 : : // -----------------------------------------------------------------------
749 : : #ifdef SV_HAS_RIDERBITMAPS
750 : :
751 : : void SfxTabDialog::AddTabPage
752 : :
753 : : /* [Description]
754 : :
755 : : Add a page to the dialog. The riders bitmap is passed on, the page has no
756 : : counterpart in the TabControl in the resource of the dialogue.
757 : : */
758 : :
759 : : (
760 : : sal_uInt16 nId,
761 : : const Bitmap &rRiderBitmap,
762 : : CreateTabPage pCreateFunc,
763 : : GetTabPageRanges pRangesFunc,
764 : : sal_Bool bItemsOnDemand,
765 : : sal_uInt16 nPos
766 : : )
767 : : {
768 : : DBG_ASSERT( TAB_PAGE_NOTFOUND == aTabCtrl.GetPagePos( nId ),
769 : : "Duplicate Page-Ids in the Tabpage" );
770 : : aTabCtrl.InsertPage( nId, rRiderBitmap, nPos );
771 : : pImpl->pData->Append(
772 : : new Data_Impl( nId, pCreateFunc, pRangesFunc, bItemsOnDemand ) );
773 : : }
774 : : #endif
775 : :
776 : : // -----------------------------------------------------------------------
777 : :
778 : 0 : void SfxTabDialog::RemoveTabPage( sal_uInt16 nId )
779 : :
780 : : /* [Description]
781 : :
782 : : Delete the TabPage with ID nId
783 : : */
784 : :
785 : : {
786 : 0 : sal_uInt16 nPos = 0;
787 [ # # ]: 0 : aTabCtrl.RemovePage( nId );
788 : 0 : Data_Impl* pDataObject = Find( *pImpl->pData, nId, &nPos );
789 : :
790 [ # # ]: 0 : if ( pDataObject )
791 : : {
792 [ # # ]: 0 : if ( pDataObject->pTabPage )
793 : : {
794 [ # # ]: 0 : pDataObject->pTabPage->FillUserData();
795 [ # # ]: 0 : String aPageData( pDataObject->pTabPage->GetUserData() );
796 [ # # ]: 0 : if ( aPageData.Len() )
797 : : {
798 : : // save settings of this page (user data)
799 [ # # ][ # # ]: 0 : SvtViewOptions aPageOpt( E_TABPAGE, String::CreateFromInt32( pDataObject->nId ) );
[ # # ][ # # ]
800 [ # # ][ # # ]: 0 : aPageOpt.SetUserItem( USERITEM_NAME, makeAny( OUString( aPageData ) ) );
[ # # ][ # # ]
801 : : }
802 : :
803 [ # # ]: 0 : if ( pDataObject->bOnDemand )
804 [ # # ][ # # ]: 0 : delete (SfxItemSet*)&pDataObject->pTabPage->GetItemSet();
805 [ # # ][ # # ]: 0 : delete pDataObject->pTabPage;
[ # # ]
806 : : }
807 : :
808 : 0 : delete pDataObject;
809 [ # # ]: 0 : pImpl->pData->Remove( nPos );
810 : : }
811 : : else
812 : : {
813 : : SAL_INFO( "sfx2.dialog", "TabPage-Id not known" );
814 : : }
815 : 0 : }
816 : :
817 : : // -----------------------------------------------------------------------
818 : :
819 : 0 : void SfxTabDialog::PageCreated
820 : :
821 : : /* [Description]
822 : :
823 : : Default implemetation of the virtual method. This is called immediately
824 : : after creating a page. Here the dialogue can call the TabPage Method
825 : : directly.
826 : : */
827 : :
828 : : (
829 : : sal_uInt16, // Id of the created page
830 : : SfxTabPage& // Reference to the created page
831 : : )
832 : : {
833 : 0 : }
834 : :
835 : : // -----------------------------------------------------------------------
836 : :
837 : 0 : SfxItemSet* SfxTabDialog::GetInputSetImpl()
838 : :
839 : : /* [Description]
840 : :
841 : : Derived classes may create new storage for the InputSet. This has to be
842 : : released in the Destructor. To do this, this method must be called.
843 : : */
844 : :
845 : : {
846 : 0 : return (SfxItemSet*)pSet;
847 : : }
848 : :
849 : : // -----------------------------------------------------------------------
850 : :
851 : 0 : SfxTabPage* SfxTabDialog::GetTabPage( sal_uInt16 nPageId ) const
852 : :
853 : : /* [Description]
854 : :
855 : : Return TabPage with the specified Id.
856 : : */
857 : :
858 : : {
859 : 0 : sal_uInt16 nPos = 0;
860 : 0 : Data_Impl* pDataObject = Find( *pImpl->pData, nPageId, &nPos );
861 : :
862 [ # # ]: 0 : if ( pDataObject )
863 : 0 : return pDataObject->pTabPage;
864 : 0 : return NULL;
865 : : }
866 : :
867 : 0 : void SfxTabDialog::SavePosAndId()
868 : : {
869 : : // save settings (screen position and current page)
870 [ # # ][ # # ]: 0 : SvtViewOptions aDlgOpt( E_TABDIALOG, String::CreateFromInt32( nResId ) );
[ # # ][ # # ]
871 [ # # ][ # # ]: 0 : aDlgOpt.SetWindowState(OStringToOUString(GetWindowState(WINDOWSTATE_MASK_POS),RTL_TEXTENCODING_ASCII_US));
[ # # ]
872 [ # # ][ # # ]: 0 : aDlgOpt.SetPageID( aTabCtrl.GetCurPageId() );
[ # # ]
873 : 0 : }
874 : :
875 : : // -----------------------------------------------------------------------
876 : :
877 : 0 : short SfxTabDialog::Ok()
878 : :
879 : : /* [Description]
880 : :
881 : : Ok handler for the Dialogue.
882 : :
883 : : Dialog's current location and current page are saved for the next time
884 : : the dialog is shown.
885 : :
886 : : The OutputSet is created and for each page this or the special OutputSet
887 : : is set by calling the method <SfxTabPage::FillItemSet(SfxItemSet &)>, to
888 : : insert the entered data by the user into the set.
889 : :
890 : : [Return value]
891 : :
892 : : RET_OK: if at least one page has returned from FillItemSet,
893 : : otherwise RET_CANCEL.
894 : : */
895 : :
896 : : {
897 : 0 : SavePosAndId(); //See fdo#38828 "Apply" resetting window position
898 : :
899 : 0 : pImpl->bInOK = sal_True;
900 : :
901 [ # # ]: 0 : if ( !pOutSet )
902 : : {
903 [ # # ][ # # ]: 0 : if ( !pExampleSet && pSet )
904 : 0 : pOutSet = pSet->Clone( sal_False ); // without Items
905 [ # # ]: 0 : else if ( pExampleSet )
906 [ # # ]: 0 : pOutSet = new SfxItemSet( *pExampleSet );
907 : : }
908 : 0 : sal_Bool bModified = sal_False;
909 : :
910 : 0 : const sal_uInt16 nCount = pImpl->pData->Count();
911 : :
912 [ # # ]: 0 : for ( sal_uInt16 i = 0; i < nCount; ++i )
913 : : {
914 : 0 : Data_Impl* pDataObject = pImpl->pData->GetObject(i);
915 : 0 : SfxTabPage* pTabPage = pDataObject->pTabPage;
916 : :
917 [ # # ]: 0 : if ( pTabPage )
918 : : {
919 [ # # ]: 0 : if ( pDataObject->bOnDemand )
920 : : {
921 : 0 : SfxItemSet& rSet = (SfxItemSet&)pTabPage->GetItemSet();
922 : 0 : rSet.ClearItem();
923 : 0 : bModified |= pTabPage->FillItemSet( rSet );
924 : : }
925 [ # # ][ # # ]: 0 : else if ( pSet && !pTabPage->HasExchangeSupport() )
[ # # ]
926 : : {
927 [ # # ]: 0 : SfxItemSet aTmp( *pSet->GetPool(), pSet->GetRanges() );
928 : :
929 [ # # ][ # # ]: 0 : if ( pTabPage->FillItemSet( aTmp ) )
930 : : {
931 : 0 : bModified |= sal_True;
932 [ # # ]: 0 : pExampleSet->Put( aTmp );
933 [ # # ]: 0 : pOutSet->Put( aTmp );
934 [ # # ]: 0 : }
935 : : }
936 : : }
937 : : }
938 : :
939 [ # # ][ # # ]: 0 : if ( pImpl->bModified || ( pOutSet && pOutSet->Count() > 0 ) )
[ # # ][ # # ]
940 : 0 : bModified |= sal_True;
941 : :
942 [ # # ]: 0 : if ( bFmt == 2 )
943 : 0 : bModified |= sal_True;
944 [ # # ]: 0 : return bModified ? RET_OK : RET_CANCEL;
945 : : }
946 : :
947 : : // -----------------------------------------------------------------------
948 : :
949 : 0 : IMPL_LINK_NOARG(SfxTabDialog, CancelHdl)
950 : : {
951 : 0 : EndDialog( RET_USER_CANCEL );
952 : 0 : return 0;
953 : : }
954 : :
955 : : // -----------------------------------------------------------------------
956 : :
957 : 0 : SfxItemSet* SfxTabDialog::CreateInputItemSet( sal_uInt16 )
958 : :
959 : : /* [Description]
960 : :
961 : : Default implemetation of the virtual Method.
962 : : This is called when pages create their sets onDenamd.
963 : : */
964 : :
965 : : {
966 : : SAL_WARN( "sfx2.dialog", "CreateInputItemSet not implemented" );
967 [ # # ]: 0 : return new SfxAllItemSet( SFX_APP()->GetPool() );
968 : : }
969 : :
970 : : // -----------------------------------------------------------------------
971 : :
972 : 0 : const SfxItemSet* SfxTabDialog::GetRefreshedSet()
973 : :
974 : : /* [Description]
975 : :
976 : : Default implemetation of the virtual Method.
977 : : This is called, when <SfxTabPage::DeactivatePage(SfxItemSet *)>
978 : : returns <SfxTabPage::REFRESH_SET>.
979 : : */
980 : :
981 : : {
982 : : SAL_INFO ( "sfx2.dialog", "GetRefreshedSet not implemented" );
983 : 0 : return 0;
984 : : }
985 : :
986 : : // -----------------------------------------------------------------------
987 : :
988 : 0 : IMPL_LINK_NOARG(SfxTabDialog, OkHdl)
989 : :
990 : : /* [Description]
991 : :
992 : : Handler of the Ok-Buttons
993 : : This calls the current page <SfxTabPage::DeactivatePage(SfxItemSet *)>.
994 : : Returns <SfxTabPage::LEAVE_PAGE>, <SfxTabDialog::Ok()> is called
995 : : anf the Dialog is ended.
996 : : */
997 : :
998 : : {
999 : 0 : pImpl->bInOK = sal_True;
1000 : :
1001 [ # # ]: 0 : if ( OK_Impl() )
1002 : : {
1003 [ # # ]: 0 : if ( pImpl->bModal )
1004 : 0 : EndDialog( Ok() );
1005 : : else
1006 : : {
1007 : 0 : Ok();
1008 : 0 : Close();
1009 : : }
1010 : : }
1011 : 0 : return 0;
1012 : : }
1013 : :
1014 : : // -----------------------------------------------------------------------
1015 : :
1016 : 0 : bool SfxTabDialog::PrepareLeaveCurrentPage()
1017 : : {
1018 : 0 : sal_uInt16 const nId = aTabCtrl.GetCurPageId();
1019 [ # # ]: 0 : SfxTabPage* pPage = dynamic_cast<SfxTabPage*> (aTabCtrl.GetTabPage( nId ));
1020 : 0 : bool bEnd = !pPage;
1021 : :
1022 [ # # ]: 0 : if ( pPage )
1023 : : {
1024 : 0 : int nRet = SfxTabPage::LEAVE_PAGE;
1025 [ # # ]: 0 : if ( pSet )
1026 : : {
1027 [ # # ]: 0 : SfxItemSet aTmp( *pSet->GetPool(), pSet->GetRanges() );
1028 : :
1029 [ # # ]: 0 : if ( pPage->HasExchangeSupport() )
1030 [ # # ]: 0 : nRet = pPage->DeactivatePage( &aTmp );
1031 : : else
1032 [ # # ]: 0 : nRet = pPage->DeactivatePage( NULL );
1033 : :
1034 [ # # # # ]: 0 : if ( ( SfxTabPage::LEAVE_PAGE & nRet ) == SfxTabPage::LEAVE_PAGE
[ # # ]
1035 : 0 : && aTmp.Count() )
1036 : : {
1037 [ # # ]: 0 : pExampleSet->Put( aTmp );
1038 [ # # ]: 0 : pOutSet->Put( aTmp );
1039 [ # # ]: 0 : }
1040 : : }
1041 : : else
1042 : 0 : nRet = pPage->DeactivatePage( NULL );
1043 : 0 : bEnd = nRet;
1044 : : }
1045 : :
1046 : 0 : return bEnd;
1047 : : }
1048 : :
1049 : :
1050 : : // -----------------------------------------------------------------------
1051 : :
1052 : 0 : IMPL_LINK_NOARG(SfxTabDialog, UserHdl)
1053 : :
1054 : : /* [Description]
1055 : :
1056 : : Handler of the User-Buttons
1057 : : This calls the current page <SfxTabPage::DeactivatePage(SfxItemSet *)>.
1058 : : returns this <SfxTabPage::LEAVE_PAGE> and <SfxTabDialog::Ok()> is called.
1059 : : Then the Dialog is ended with the Return value <SfxTabDialog::Ok()>
1060 : : */
1061 : :
1062 : : {
1063 [ # # ]: 0 : if ( PrepareLeaveCurrentPage () )
1064 : : {
1065 : 0 : short nRet = Ok();
1066 : :
1067 [ # # ]: 0 : if ( RET_OK == nRet )
1068 : 0 : nRet = RET_USER;
1069 : : else
1070 : 0 : nRet = RET_USER_CANCEL;
1071 : 0 : EndDialog( nRet );
1072 : : }
1073 : 0 : return 0;
1074 : : }
1075 : :
1076 : : // -----------------------------------------------------------------------
1077 : :
1078 : 0 : IMPL_LINK_NOARG(SfxTabDialog, ResetHdl)
1079 : :
1080 : : /* [Description]
1081 : :
1082 : : Handler behind the reset button.
1083 : : The Current Page is new initialized with their initial data, all the
1084 : : settings that the user has made on this page are repealed.
1085 : : */
1086 : :
1087 : : {
1088 : 0 : const sal_uInt16 nId = aTabCtrl.GetCurPageId();
1089 : 0 : Data_Impl* pDataObject = Find( *pImpl->pData, nId );
1090 : : DBG_ASSERT( pDataObject, "Id not known" );
1091 : :
1092 [ # # ]: 0 : if ( pDataObject->bOnDemand )
1093 : : {
1094 : : // CSet on AIS has problems here, thus separated
1095 : 0 : const SfxItemSet* pItemSet = &pDataObject->pTabPage->GetItemSet();
1096 : 0 : pDataObject->pTabPage->Reset( *(SfxItemSet*)pItemSet );
1097 : : }
1098 : : else
1099 : 0 : pDataObject->pTabPage->Reset( *pSet );
1100 : 0 : return 0;
1101 : : }
1102 : :
1103 : : // -----------------------------------------------------------------------
1104 : :
1105 : 0 : IMPL_LINK_NOARG(SfxTabDialog, BaseFmtHdl)
1106 : :
1107 : : /* [Description]
1108 : :
1109 : : Handler behind the Standard-Button.
1110 : : This button is available when editing style sheets. All the set attributes
1111 : : in the edited stylesheet are deleted.
1112 : : */
1113 : :
1114 : : {
1115 : 0 : const sal_uInt16 nId = aTabCtrl.GetCurPageId();
1116 : 0 : Data_Impl* pDataObject = Find( *pImpl->pData, nId );
1117 : : DBG_ASSERT( pDataObject, "Id not known" );
1118 : 0 : bFmt = 2;
1119 : :
1120 [ # # ]: 0 : if ( pDataObject->fnGetRanges )
1121 : : {
1122 [ # # ]: 0 : if ( !pExampleSet )
1123 [ # # ][ # # ]: 0 : pExampleSet = new SfxItemSet( *pSet );
1124 : :
1125 : 0 : const SfxItemPool* pPool = pSet->GetPool();
1126 [ # # ]: 0 : const sal_uInt16* pTmpRanges = (pDataObject->fnGetRanges)();
1127 [ # # ]: 0 : SfxItemSet aTmpSet( *pExampleSet );
1128 : :
1129 [ # # ]: 0 : while ( *pTmpRanges )
1130 : : {
1131 : 0 : const sal_uInt16* pU = pTmpRanges + 1;
1132 : :
1133 [ # # ]: 0 : if ( *pTmpRanges == *pU )
1134 : : {
1135 : : // Range which two identical values -> only set one Item
1136 [ # # ]: 0 : sal_uInt16 nWh = pPool->GetWhich( *pTmpRanges );
1137 [ # # ]: 0 : pExampleSet->ClearItem( nWh );
1138 [ # # ]: 0 : aTmpSet.ClearItem( nWh );
1139 : : // At the Outset of InvalidateItem,
1140 : : // so that the change takes effect
1141 [ # # ]: 0 : pOutSet->InvalidateItem( nWh );
1142 : : }
1143 : : else
1144 : : {
1145 : : // Correct Range with multiple values
1146 : 0 : sal_uInt16 nTmp = *pTmpRanges, nTmpEnd = *pU;
1147 : : DBG_ASSERT( nTmp <= nTmpEnd, "Range is sorted the wrong way" );
1148 : :
1149 [ # # ]: 0 : if ( nTmp > nTmpEnd )
1150 : : {
1151 : : // If really sorted wrongly, then set new
1152 : 0 : sal_uInt16 nTmp1 = nTmp;
1153 : 0 : nTmp = nTmpEnd;
1154 : 0 : nTmpEnd = nTmp1;
1155 : : }
1156 : :
1157 [ # # ]: 0 : while ( nTmp <= nTmpEnd )
1158 : : {
1159 : : // Iterate over the Range and set the Items
1160 [ # # ]: 0 : sal_uInt16 nWh = pPool->GetWhich( nTmp );
1161 [ # # ]: 0 : pExampleSet->ClearItem( nWh );
1162 [ # # ]: 0 : aTmpSet.ClearItem( nWh );
1163 : : // At the Outset of InvalidateItem,
1164 : : // so that the change takes effect
1165 [ # # ]: 0 : pOutSet->InvalidateItem( nWh );
1166 : 0 : nTmp++;
1167 : : }
1168 : : }
1169 : : // Go to the next pair
1170 : 0 : pTmpRanges += 2;
1171 : : }
1172 : : // Set all Items as new -> the call the current Page Reset()
1173 : : DBG_ASSERT( pDataObject->pTabPage, "the Page is gone" );
1174 [ # # ]: 0 : pDataObject->pTabPage->Reset( aTmpSet );
1175 [ # # ]: 0 : pDataObject->pTabPage->pImpl->mbStandard = sal_True;
1176 : : }
1177 : 0 : return 1;
1178 : : }
1179 : :
1180 : : // -----------------------------------------------------------------------
1181 : :
1182 : 0 : IMPL_LINK( SfxTabDialog, ActivatePageHdl, TabControl *, pTabCtrl )
1183 : :
1184 : : /* [Description]
1185 : :
1186 : : Handler that is called by StarView for switching to a different page.
1187 : : If the page not exist yet then it is created and the virtual Method
1188 : : <SfxTabDialog::PageCreated( sal_uInt16, SfxTabPage &)> is called. If the page
1189 : : exist, then the if possible the <SfxTabPage::Reset(const SfxItemSet &)> or
1190 : : <SfxTabPage::ActivatePage(const SfxItemSet &)> is called.
1191 : : */
1192 : :
1193 : : {
1194 : 0 : sal_uInt16 const nId = pTabCtrl->GetCurPageId();
1195 : :
1196 : : DBG_ASSERT( pImpl->pData->Count(), "no Pages registered" );
1197 : 0 : SFX_APP();
1198 : :
1199 : : // Tab Page schon da?
1200 [ # # ]: 0 : SfxTabPage* pTabPage = dynamic_cast<SfxTabPage*> (pTabCtrl->GetTabPage( nId ));
1201 : 0 : Data_Impl* pDataObject = Find( *pImpl->pData, nId );
1202 : : DBG_ASSERT( pDataObject, "Id not known" );
1203 : :
1204 : : // Create TabPage if possible:
1205 [ # # ]: 0 : if ( !pTabPage )
1206 : : {
1207 : 0 : const SfxItemSet* pTmpSet = 0;
1208 : :
1209 [ # # ]: 0 : if ( pSet )
1210 : : {
1211 [ # # ][ # # ]: 0 : if ( bItemsReset && pSet->GetParent() )
[ # # ]
1212 : 0 : pTmpSet = pSet->GetParent();
1213 : : else
1214 : 0 : pTmpSet = pSet;
1215 : : }
1216 : :
1217 [ # # ][ # # ]: 0 : if ( pTmpSet && !pDataObject->bOnDemand )
1218 [ # # ]: 0 : pTabPage = (pDataObject->fnCreatePage)( pTabCtrl, *pTmpSet );
1219 : : else
1220 : : pTabPage = (pDataObject->fnCreatePage)
1221 [ # # ][ # # ]: 0 : ( pTabCtrl, *CreateInputItemSet( nId ) );
1222 : : DBG_ASSERT( NULL == pDataObject->pTabPage, "create TabPage more than once" );
1223 : 0 : pDataObject->pTabPage = pTabPage;
1224 : :
1225 : 0 : pDataObject->pTabPage->SetTabDialog( this );
1226 [ # # ][ # # ]: 0 : SvtViewOptions aPageOpt( E_TABPAGE, String::CreateFromInt32( pDataObject->nId ) );
[ # # ][ # # ]
1227 [ # # ]: 0 : String sUserData;
1228 [ # # ]: 0 : Any aUserItem = aPageOpt.GetUserItem( USERITEM_NAME );
1229 : 0 : OUString aTemp;
1230 [ # # ]: 0 : if ( aUserItem >>= aTemp )
1231 [ # # ][ # # ]: 0 : sUserData = String( aTemp );
[ # # ]
1232 [ # # ]: 0 : pTabPage->SetUserData( sUserData );
1233 [ # # ]: 0 : Size aSiz = pTabPage->GetSizePixel();
1234 : :
1235 [ # # ]: 0 : Size aCtrlSiz = pTabCtrl->GetTabPageSizePixel();
1236 : : // Only set Size on TabControl when < as TabPage
1237 [ # # # # ]: 0 : if ( aCtrlSiz.Width() < aSiz.Width() ||
[ # # ]
1238 : 0 : aCtrlSiz.Height() < aSiz.Height() )
1239 : : {
1240 [ # # ]: 0 : pTabCtrl->SetTabPageSizePixel( aSiz );
1241 : : }
1242 : :
1243 [ # # ]: 0 : PageCreated( nId, *pTabPage );
1244 : :
1245 [ # # ]: 0 : if ( pDataObject->bOnDemand )
1246 [ # # ]: 0 : pTabPage->Reset( (SfxItemSet &)pTabPage->GetItemSet() );
1247 : : else
1248 [ # # ]: 0 : pTabPage->Reset( *pSet );
1249 : :
1250 [ # # ][ # # ]: 0 : pTabCtrl->SetTabPage( nId, pTabPage );
[ # # ]
1251 : : }
1252 [ # # ]: 0 : else if ( pDataObject->bRefresh )
1253 : 0 : pTabPage->Reset( *pSet );
1254 : 0 : pDataObject->bRefresh = sal_False;
1255 : :
1256 [ # # ]: 0 : if ( pExampleSet )
1257 : 0 : pTabPage->ActivatePage( *pExampleSet );
1258 : 0 : sal_Bool bReadOnly = pTabPage->IsReadOnly();
1259 [ # # ][ # # ]: 0 : ( bReadOnly || pImpl->bHideResetBtn ) ? aResetBtn.Hide() : aResetBtn.Show();
1260 : 0 : return 0;
1261 : : }
1262 : :
1263 : : // -----------------------------------------------------------------------
1264 : :
1265 : 0 : IMPL_LINK( SfxTabDialog, DeactivatePageHdl, TabControl *, pTabCtrl )
1266 : :
1267 : : /* [Description]
1268 : :
1269 : : Handler that is called by StarView before leaving a page.
1270 : :
1271 : : [Cross-reference]
1272 : :
1273 : : <SfxTabPage::DeactivatePage(SfxItemSet *)>
1274 : : */
1275 : :
1276 : : {
1277 : 0 : sal_uInt16 nId = pTabCtrl->GetCurPageId();
1278 : 0 : SFX_APP();
1279 [ # # ]: 0 : SfxTabPage *pPage = dynamic_cast<SfxTabPage*> (pTabCtrl->GetTabPage( nId ));
1280 : : DBG_ASSERT( pPage, "no active Page" );
1281 : : #ifdef DBG_UTIL
1282 : : Data_Impl* pDataObject = Find( *pImpl->pData, pTabCtrl->GetCurPageId() );
1283 : : DBG_ASSERT( pDataObject, "no Data structur for current page" );
1284 : : if ( pPage->HasExchangeSupport() && pDataObject->bOnDemand )
1285 : : {
1286 : : DBG_WARNING( "Data exchange in ItemsOnDemand is not desired!" );
1287 : : }
1288 : : #endif
1289 : :
1290 : 0 : int nRet = SfxTabPage::LEAVE_PAGE;
1291 : :
1292 [ # # ][ # # ]: 0 : if ( !pExampleSet && pPage->HasExchangeSupport() && pSet )
[ # # ][ # # ]
1293 [ # # ]: 0 : pExampleSet = new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() );
1294 : :
1295 [ # # ]: 0 : if ( pSet )
1296 : : {
1297 [ # # ]: 0 : SfxItemSet aTmp( *pSet->GetPool(), pSet->GetRanges() );
1298 : :
1299 [ # # ]: 0 : if ( pPage->HasExchangeSupport() )
1300 [ # # ]: 0 : nRet = pPage->DeactivatePage( &aTmp );
1301 : : else
1302 [ # # ]: 0 : nRet = pPage->DeactivatePage( NULL );
1303 [ # # # # ]: 0 : if ( ( SfxTabPage::LEAVE_PAGE & nRet ) == SfxTabPage::LEAVE_PAGE &&
[ # # ]
1304 : 0 : aTmp.Count() )
1305 : : {
1306 [ # # ]: 0 : pExampleSet->Put( aTmp );
1307 [ # # ]: 0 : pOutSet->Put( aTmp );
1308 [ # # ]: 0 : }
1309 : : }
1310 : : else
1311 : : {
1312 [ # # ]: 0 : if ( pPage->HasExchangeSupport() ) //!!!
1313 : : {
1314 [ # # ]: 0 : if ( !pExampleSet )
1315 : : {
1316 : 0 : SfxItemPool* pPool = pPage->GetItemSet().GetPool();
1317 : : pExampleSet =
1318 [ # # ]: 0 : new SfxItemSet( *pPool, GetInputRanges( *pPool ) );
1319 : : }
1320 : 0 : nRet = pPage->DeactivatePage( pExampleSet );
1321 : : }
1322 : : else
1323 : 0 : nRet = pPage->DeactivatePage( NULL );
1324 : : }
1325 : :
1326 [ # # ]: 0 : if ( nRet & SfxTabPage::REFRESH_SET )
1327 : : {
1328 : 0 : pSet = GetRefreshedSet();
1329 : : DBG_ASSERT( pSet, "GetRefreshedSet() returns NULL" );
1330 : : // Flag all Pages as to be initialized as new
1331 : 0 : const sal_uInt16 nCount = pImpl->pData->Count();
1332 : :
1333 [ # # ]: 0 : for ( sal_uInt16 i = 0; i < nCount; ++i )
1334 : : {
1335 : 0 : Data_Impl* pObj = (*pImpl->pData)[i];
1336 : :
1337 [ # # ]: 0 : if ( pObj->pTabPage != pPage ) // Do not refresh own Page anymore
1338 : 0 : pObj->bRefresh = sal_True;
1339 : : else
1340 : 0 : pObj->bRefresh = sal_False;
1341 : : }
1342 : : }
1343 [ # # ]: 0 : if ( nRet & SfxTabPage::LEAVE_PAGE )
1344 : 0 : return sal_True;
1345 : : else
1346 : 0 : return sal_False;
1347 : : }
1348 : :
1349 : : // -----------------------------------------------------------------------
1350 : :
1351 : 0 : void SfxTabDialog::ShowPage( sal_uInt16 nId )
1352 : :
1353 : : /* [Description]
1354 : :
1355 : : The TabPage is activated with the specified Id.
1356 : : */
1357 : :
1358 : : {
1359 : 0 : aTabCtrl.SetCurPageId( nId );
1360 : 0 : ActivatePageHdl( &aTabCtrl );
1361 : 0 : }
1362 : :
1363 : : // -----------------------------------------------------------------------
1364 : :
1365 : 0 : const sal_uInt16* SfxTabDialog::GetInputRanges( const SfxItemPool& rPool )
1366 : :
1367 : : /* [Description]
1368 : :
1369 : : Makes the set over the range of all pages of the dialogue. Pages have the
1370 : : static method for querying their range in AddTabPage, ie deliver their
1371 : : sets onDemand.
1372 : :
1373 : : [Return value]
1374 : :
1375 : : Pointer to a null-terminated array of sal_uInt16. This array belongs to the
1376 : : dialog and is deleted when the dialogue is destroy.
1377 : :
1378 : : [Cross-reference]
1379 : :
1380 : : <SfxTabDialog::AddTabPage(sal_uInt16, CreateTabPage, GetTabPageRanges, sal_Bool)>
1381 : : <SfxTabDialog::AddTabPage(sal_uInt16, const String &, CreateTabPage, GetTabPageRanges, sal_Bool, sal_uInt16)>
1382 : : <SfxTabDialog::AddTabPage(sal_uInt16, const Bitmap &, CreateTabPage, GetTabPageRanges, sal_Bool, sal_uInt16)>
1383 : : */
1384 : :
1385 : : {
1386 [ # # ]: 0 : if ( pSet )
1387 : : {
1388 : : SAL_WARN( "sfx2.dialog", "Set already exists!" );
1389 : 0 : return pSet->GetRanges();
1390 : : }
1391 : :
1392 [ # # ]: 0 : if ( pRanges )
1393 : 0 : return pRanges;
1394 [ # # ]: 0 : std::vector<sal_uInt16> aUS;
1395 : 0 : sal_uInt16 nCount = pImpl->pData->Count();
1396 : :
1397 : : sal_uInt16 i;
1398 [ # # ]: 0 : for ( i = 0; i < nCount; ++i )
1399 : : {
1400 [ # # ]: 0 : Data_Impl* pDataObject = pImpl->pData->GetObject(i);
1401 : :
1402 [ # # ]: 0 : if ( pDataObject->fnGetRanges )
1403 : : {
1404 [ # # ]: 0 : const sal_uInt16* pTmpRanges = (pDataObject->fnGetRanges)();
1405 : 0 : const sal_uInt16* pIter = pTmpRanges;
1406 : :
1407 : : sal_uInt16 nLen;
1408 [ # # ]: 0 : for( nLen = 0; *pIter; ++nLen, ++pIter )
1409 : : ;
1410 [ # # ]: 0 : aUS.insert( aUS.end(), pTmpRanges, pTmpRanges + nLen );
1411 : : }
1412 : : }
1413 : :
1414 : : //! Remove duplicated Ids?
1415 : : {
1416 : 0 : nCount = aUS.size();
1417 : :
1418 [ # # ]: 0 : for ( i = 0; i < nCount; ++i )
1419 [ # # ][ # # ]: 0 : aUS[i] = rPool.GetWhich( aUS[i] );
[ # # ]
1420 : : }
1421 : :
1422 : : // sort
1423 [ # # ]: 0 : if ( aUS.size() > 1 )
1424 : : {
1425 [ # # ]: 0 : std::sort( aUS.begin(), aUS.end() );
1426 : : }
1427 : :
1428 [ # # ]: 0 : pRanges = new sal_uInt16[aUS.size() + 1];
1429 [ # # ]: 0 : std::copy( aUS.begin(), aUS.end(), pRanges );
1430 : 0 : pRanges[aUS.size()] = 0;
1431 : 0 : return pRanges;
1432 : : }
1433 : :
1434 : : // -----------------------------------------------------------------------
1435 : :
1436 : 0 : void SfxTabDialog::SetInputSet( const SfxItemSet* pInSet )
1437 : :
1438 : : /* [Description]
1439 : :
1440 : : With this method the Input-Set can subsequently be set initally or re-set.
1441 : : */
1442 : :
1443 : : {
1444 : 0 : bool bSet = ( pSet != NULL );
1445 : :
1446 : 0 : pSet = pInSet;
1447 : :
1448 [ # # ][ # # ]: 0 : if ( !bSet && !pExampleSet && !pOutSet )
[ # # ]
1449 : : {
1450 [ # # ]: 0 : pExampleSet = new SfxItemSet( *pSet );
1451 [ # # ]: 0 : pOutSet = new SfxItemSet( *pSet->GetPool(), pSet->GetRanges() );
1452 : : }
1453 : 0 : }
1454 : :
1455 : 0 : long SfxTabDialog::Notify( NotifyEvent& rNEvt )
1456 : : {
1457 [ # # ]: 0 : if ( rNEvt.GetType() == EVENT_GETFOCUS )
1458 : : {
1459 [ # # ]: 0 : SfxViewFrame* pViewFrame = GetViewFrame() ? GetViewFrame() : SfxViewFrame::Current();
1460 [ # # ]: 0 : if ( pViewFrame )
1461 : : {
1462 : 0 : Window* pWindow = rNEvt.GetWindow();
1463 : 0 : rtl::OString sHelpId;
1464 [ # # ][ # # ]: 0 : while ( sHelpId.isEmpty() && pWindow )
[ # # ]
1465 : : {
1466 [ # # ]: 0 : sHelpId = pWindow->GetHelpId();
1467 [ # # ]: 0 : pWindow = pWindow->GetParent();
1468 : : }
1469 : :
1470 [ # # ]: 0 : if ( !sHelpId.isEmpty() )
1471 [ # # ][ # # ]: 0 : SfxHelp::OpenHelpAgent( &pViewFrame->GetFrame(), sHelpId );
1472 : : }
1473 : : }
1474 : :
1475 : 0 : return TabDialog::Notify( rNEvt );
1476 : : }
1477 : :
1478 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|