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 : #include <stdlib.h>
21 : #include <comphelper/processfactory.hxx>
22 : #include <osl/file.hxx>
23 : #include <vcl/fixed.hxx>
24 : #include <vcl/help.hxx>
25 : #include <vcl/msgbox.hxx>
26 : #include <svl/eitem.hxx>
27 : #include <unotools/viewoptions.hxx>
28 : #include <svtools/controldims.hrc>
29 :
30 : #include <sfx2/basedlgs.hxx>
31 : #include <sfx2/viewfrm.hxx>
32 : #include <sfx2/tabdlg.hxx>
33 : #include <sfx2/app.hxx>
34 : #include <sfx2/bindings.hxx>
35 : #include <sfx2/dispatch.hxx>
36 : #include <sfx2/childwin.hxx>
37 : #include <sfx2/viewsh.hxx>
38 : #include <sfx2/sfxhelp.hxx>
39 : #include "workwin.hxx"
40 : #include <sfx2/sfxresid.hxx>
41 : #include "dialog.hrc"
42 :
43 : using namespace ::com::sun::star::uno;
44 :
45 : #define USERITEM_NAME OUString("UserItem")
46 :
47 0 : class SfxModelessDialog_Impl : public SfxListener
48 : {
49 : public:
50 : OString aWinState;
51 : SfxChildWindow* pMgr;
52 : bool bConstructed;
53 : void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) SAL_OVERRIDE;
54 :
55 : Timer aMoveTimer;
56 : };
57 :
58 0 : void SfxModelessDialog_Impl::Notify( SfxBroadcaster&, const SfxHint& rHint )
59 : {
60 0 : const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
61 0 : if ( pSimpleHint )
62 : {
63 0 : switch( pSimpleHint->GetId() )
64 : {
65 : case SFX_HINT_DYING:
66 0 : pMgr->Destroy();
67 0 : break;
68 : }
69 : }
70 0 : }
71 :
72 102 : class SfxFloatingWindow_Impl : public SfxListener
73 : {
74 : public:
75 : OString aWinState;
76 : SfxChildWindow* pMgr;
77 : bool bConstructed;
78 : Timer aMoveTimer;
79 :
80 : void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) SAL_OVERRIDE;
81 : };
82 :
83 4 : void SfxFloatingWindow_Impl::Notify( SfxBroadcaster&, const SfxHint& rHint )
84 : {
85 4 : const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
86 4 : if ( pSimpleHint )
87 : {
88 4 : switch( pSimpleHint->GetId() )
89 : {
90 : case SFX_HINT_DYING:
91 0 : pMgr->Destroy();
92 0 : break;
93 : }
94 : }
95 4 : }
96 :
97 :
98 :
99 0 : void SfxModalDialog::SetDialogData_Impl()
100 : {
101 : // save settings (position and user data)
102 0 : OUString sConfigId;
103 0 : if (isLayoutEnabled())
104 0 : sConfigId = OStringToOUString(GetHelpId(),RTL_TEXTENCODING_UTF8);
105 : else
106 : {
107 : SAL_WARN("sfx.config", "Dialog needs to be converted to .ui format");
108 0 : sConfigId = OUString::number(nUniqId);
109 : }
110 :
111 0 : SvtViewOptions aDlgOpt(E_DIALOG, sConfigId);
112 : aDlgOpt.SetWindowState(OStringToOUString(
113 0 : GetWindowState(WINDOWSTATE_MASK_POS), RTL_TEXTENCODING_ASCII_US));
114 0 : if ( !aExtraData.isEmpty() )
115 0 : aDlgOpt.SetUserItem( USERITEM_NAME, makeAny( aExtraData ) );
116 0 : }
117 :
118 :
119 :
120 0 : void SfxModalDialog::GetDialogData_Impl()
121 :
122 : /* [Description]
123 :
124 : Helper function, reads the dialogue position from the ini file and
125 : puts them on the transfered window.
126 : */
127 :
128 : {
129 0 : OUString sConfigId;
130 0 : if (isLayoutEnabled())
131 0 : sConfigId = OStringToOUString(GetHelpId(),RTL_TEXTENCODING_UTF8);
132 : else
133 : {
134 : SAL_WARN("sfx.config", "Dialog needs to be converted to .ui format");
135 0 : sConfigId = OUString::number(nUniqId);
136 : }
137 :
138 0 : SvtViewOptions aDlgOpt(E_DIALOG, sConfigId);
139 0 : if ( aDlgOpt.Exists() )
140 : {
141 : // load settings
142 0 : SetWindowState( OUStringToOString( aDlgOpt.GetWindowState().getStr(), RTL_TEXTENCODING_ASCII_US ) );
143 0 : Any aUserItem = aDlgOpt.GetUserItem( USERITEM_NAME );
144 0 : OUString aTemp;
145 0 : if ( aUserItem >>= aTemp )
146 0 : aExtraData = aTemp;
147 0 : }
148 0 : }
149 :
150 0 : void SfxModalDialog::init()
151 : {
152 0 : GetDialogData_Impl();
153 0 : }
154 :
155 0 : SfxModalDialog::SfxModalDialog(vcl::Window *pParent, const OString& rID, const OUString& rUIXMLDescription )
156 : : ModalDialog(pParent, rID, rUIXMLDescription),
157 : nUniqId(0), //todo: remove this member when the ResId using ctor is removed
158 : pInputSet(0),
159 0 : pOutputSet(0)
160 : {
161 0 : init();
162 0 : }
163 :
164 0 : SfxModalDialog::~SfxModalDialog()
165 :
166 : /* [Description]
167 :
168 : Destructor; writes the Dialog position in the ini-file.
169 : */
170 :
171 : {
172 0 : SetDialogData_Impl();
173 0 : delete pOutputSet;
174 0 : }
175 :
176 0 : void SfxModalDialog::CreateOutputItemSet( SfxItemPool& rPool )
177 : {
178 : DBG_ASSERT( !pOutputSet, "Double creation of OutputSet!" );
179 0 : if (!pOutputSet)
180 0 : pOutputSet = new SfxAllItemSet( rPool );
181 0 : }
182 :
183 :
184 :
185 0 : void SfxModalDialog::CreateOutputItemSet( const SfxItemSet& rSet )
186 : {
187 : DBG_ASSERT( !pOutputSet, "Double creation of OutputSet!" );
188 0 : if (!pOutputSet)
189 : {
190 0 : pOutputSet = new SfxItemSet( rSet );
191 0 : pOutputSet->ClearItem();
192 : }
193 0 : }
194 :
195 :
196 0 : void SfxModelessDialog::StateChanged( StateChangedType nStateChange )
197 : {
198 0 : if ( nStateChange == StateChangedType::INITSHOW )
199 : {
200 0 : if ( !pImp->aWinState.isEmpty() )
201 : {
202 0 : SetWindowState( pImp->aWinState );
203 : }
204 : else
205 : {
206 0 : Point aPos = GetPosPixel();
207 0 : if ( !aPos.X() )
208 : {
209 0 : aSize = GetSizePixel();
210 :
211 0 : Size aParentSize = GetParent()->GetOutputSizePixel();
212 0 : Size aDlgSize = GetSizePixel();
213 0 : aPos.X() += ( aParentSize.Width() - aDlgSize.Width() ) / 2;
214 0 : aPos.Y() += ( aParentSize.Height() - aDlgSize.Height() ) / 2;
215 :
216 0 : Point aPoint;
217 0 : Rectangle aRect = GetDesktopRectPixel();
218 0 : aPoint.X() = aRect.Right() - aDlgSize.Width();
219 0 : aPoint.Y() = aRect.Bottom() - aDlgSize.Height();
220 :
221 0 : aPoint = OutputToScreenPixel( aPoint );
222 :
223 0 : if ( aPos.X() > aPoint.X() )
224 0 : aPos.X() = aPoint.X() ;
225 0 : if ( aPos.Y() > aPoint.Y() )
226 0 : aPos.Y() = aPoint.Y();
227 :
228 0 : if ( aPos.X() < 0 ) aPos.X() = 0;
229 0 : if ( aPos.Y() < 0 ) aPos.Y() = 0;
230 :
231 0 : SetPosPixel( aPos );
232 : }
233 : }
234 :
235 0 : pImp->bConstructed = true;
236 : }
237 :
238 0 : ModelessDialog::StateChanged( nStateChange );
239 0 : }
240 :
241 0 : void SfxModelessDialog::Initialize(SfxChildWinInfo *pInfo)
242 :
243 : /* [Description]
244 :
245 : Initialization of the class SfxModelessDialog via a SfxChildWinInfo.
246 : The initialization is done only in a 2nd step after the constructor, this
247 : constructor should be called from the derived class or from the
248 : SfxChildWindows.
249 : */
250 :
251 : {
252 0 : if (pInfo)
253 0 : pImp->aWinState = pInfo->aWinState;
254 0 : }
255 :
256 0 : void SfxModelessDialog::Resize()
257 :
258 : /* [Description]
259 :
260 : This virtual method of the class FloatingWindow keeps track if a change
261 : in size has been made. When this method is overridden by a derived class,
262 : then the SfxFloatingWindow: Resize() must also be called.
263 : */
264 :
265 : {
266 0 : ModelessDialog::Resize();
267 0 : if ( pImp->bConstructed && pImp->pMgr )
268 : {
269 : // start timer for saving window status information
270 0 : pImp->aMoveTimer.Start();
271 : }
272 0 : }
273 :
274 0 : void SfxModelessDialog::Move()
275 : {
276 0 : ModelessDialog::Move();
277 0 : if ( pImp->bConstructed && pImp->pMgr && IsReallyVisible() )
278 : {
279 : // start timer for saving window status information
280 0 : pImp->aMoveTimer.Start();
281 : }
282 0 : }
283 :
284 : /*
285 : Implements a timer event that is triggered by a move or resize of the window
286 : This will save config information to Views.xcu with a small delay
287 : */
288 0 : IMPL_LINK_NOARG(SfxModelessDialog, TimerHdl)
289 : {
290 0 : pImp->aMoveTimer.Stop();
291 0 : if ( pImp->bConstructed && pImp->pMgr )
292 : {
293 0 : if ( !IsRollUp() )
294 0 : aSize = GetSizePixel();
295 0 : sal_uIntPtr nMask = WINDOWSTATE_MASK_POS | WINDOWSTATE_MASK_STATE;
296 0 : if ( GetStyle() & WB_SIZEABLE )
297 0 : nMask |= ( WINDOWSTATE_MASK_WIDTH | WINDOWSTATE_MASK_HEIGHT );
298 0 : pImp->aWinState = GetWindowState( nMask );
299 0 : GetBindings().GetWorkWindow_Impl()->ConfigChild_Impl( SFX_CHILDWIN_DOCKINGWINDOW, SFX_ALIGNDOCKINGWINDOW, pImp->pMgr->GetType() );
300 : }
301 0 : return 0;
302 : }
303 :
304 0 : SfxModelessDialog::SfxModelessDialog(SfxBindings* pBindinx,
305 : SfxChildWindow *pCW, vcl::Window *pParent, const OString& rID,
306 : const OUString& rUIXMLDescription)
307 0 : : ModelessDialog(pParent, rID, rUIXMLDescription)
308 : {
309 0 : Init(pBindinx, pCW);
310 0 : }
311 :
312 0 : void SfxModelessDialog::Init(SfxBindings *pBindinx, SfxChildWindow *pCW)
313 : {
314 0 : pBindings = pBindinx;
315 0 : pImp = new SfxModelessDialog_Impl;
316 0 : pImp->pMgr = pCW;
317 0 : pImp->bConstructed = false;
318 0 : SetUniqueId( GetHelpId() );
319 0 : if ( pBindinx )
320 0 : pImp->StartListening( *pBindinx );
321 0 : pImp->aMoveTimer.SetTimeout(50);
322 0 : pImp->aMoveTimer.SetTimeoutHdl(LINK(this,SfxModelessDialog,TimerHdl));
323 0 : }
324 :
325 : /* [Description]
326 :
327 : If a ModelessDialog is enabled its ViewFrame wil be activated.
328 : This is necessary by PluginInFrames.
329 : */
330 0 : bool SfxModelessDialog::Notify( NotifyEvent& rEvt )
331 : {
332 0 : if ( rEvt.GetType() == EVENT_GETFOCUS )
333 : {
334 0 : pBindings->SetActiveFrame( pImp->pMgr->GetFrame() );
335 0 : pImp->pMgr->Activate_Impl();
336 : }
337 0 : else if ( rEvt.GetType() == EVENT_LOSEFOCUS && !HasChildPathFocus() )
338 : {
339 0 : pBindings->SetActiveFrame( ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > () );
340 0 : pImp->pMgr->Deactivate_Impl();
341 : }
342 0 : else if( rEvt.GetType() == EVENT_KEYINPUT )
343 : {
344 : // First, allow KeyInput for Dialog functions ( TAB etc. )
345 0 : if ( !ModelessDialog::Notify( rEvt ) && SfxViewShell::Current() )
346 : // then also for valid global accelerators.
347 0 : return SfxViewShell::Current()->GlobalKeyInput_Impl( *rEvt.GetKeyEvent() );
348 0 : return true;
349 : }
350 :
351 0 : return ModelessDialog::Notify( rEvt );
352 : }
353 :
354 :
355 :
356 0 : SfxModelessDialog::~SfxModelessDialog()
357 :
358 : /* [Description]
359 :
360 : Destructor
361 : */
362 :
363 : {
364 0 : if ( pImp->pMgr->GetFrame().is() && pImp->pMgr->GetFrame() == pBindings->GetActiveFrame() )
365 0 : pBindings->SetActiveFrame( NULL );
366 0 : delete pImp;
367 0 : }
368 :
369 :
370 :
371 0 : bool SfxModelessDialog::Close()
372 :
373 : /* [Description]
374 :
375 : The window is closed when the ChildWindow is destroyed by running the
376 : ChildWindow-slots. If this is method is overridden by a derived class
377 : method, then the SfxModelessDialogWindow: Close() must be called afterwards
378 : if the Close() was not cancelled with "return sal_False".
379 : */
380 :
381 : {
382 : // Execute with Parameters, since Toggle is ignored by some ChildWindows.
383 0 : SfxBoolItem aValue( pImp->pMgr->GetType(), false);
384 : pBindings->GetDispatcher_Impl()->Execute(
385 0 : pImp->pMgr->GetType(),
386 0 : SfxCallMode::RECORD|SfxCallMode::SYNCHRON, &aValue, 0L );
387 0 : return true;
388 : }
389 :
390 :
391 :
392 0 : void SfxModelessDialog::FillInfo(SfxChildWinInfo& rInfo) const
393 :
394 : /* [Description]
395 :
396 : Fills a SfxChildWinInfo with specific data from SfxModelessDialog,
397 : so that it can be written in the INI file. It is assumed that rinfo
398 : receives all other possible relevant data in the ChildWindow class.
399 : ModelessDialogs have no specific information, so that the base
400 : implementation does nothing and therefore must not be called.
401 : */
402 :
403 : {
404 0 : rInfo.aSize = aSize;
405 0 : if ( IsRollUp() )
406 0 : rInfo.nFlags |= SFX_CHILDWIN_ZOOMIN;
407 0 : }
408 :
409 :
410 :
411 306 : bool SfxFloatingWindow::Notify( NotifyEvent& rEvt )
412 :
413 : /* [Description]
414 :
415 : If a ModelessDialog is enabled, its ViewFrame will be activated.
416 : This necessary for the PluginInFrames.
417 : */
418 :
419 : {
420 306 : if ( rEvt.GetType() == EVENT_GETFOCUS )
421 : {
422 0 : pBindings->SetActiveFrame( pImp->pMgr->GetFrame() );
423 0 : pImp->pMgr->Activate_Impl();
424 : }
425 306 : else if ( rEvt.GetType() == EVENT_LOSEFOCUS )
426 : {
427 0 : if ( !HasChildPathFocus() )
428 : {
429 0 : pBindings->SetActiveFrame( NULL );
430 0 : pImp->pMgr->Deactivate_Impl();
431 : }
432 : }
433 306 : else if( rEvt.GetType() == EVENT_KEYINPUT )
434 : {
435 : // First, allow KeyInput for Dialog functions
436 0 : if ( !FloatingWindow::Notify( rEvt ) && SfxViewShell::Current() )
437 : // then also for valid global accelerators.
438 0 : return SfxViewShell::Current()->GlobalKeyInput_Impl( *rEvt.GetKeyEvent() );
439 0 : return true;
440 : }
441 :
442 306 : return FloatingWindow::Notify( rEvt );
443 : }
444 :
445 :
446 :
447 0 : SfxFloatingWindow::SfxFloatingWindow( SfxBindings *pBindinx,
448 : SfxChildWindow *pCW,
449 : vcl::Window* pParent, WinBits nWinBits) :
450 : FloatingWindow (pParent, nWinBits),
451 : pBindings(pBindinx),
452 0 : pImp( new SfxFloatingWindow_Impl )
453 : {
454 0 : pImp->pMgr = pCW;
455 0 : pImp->bConstructed = false;
456 0 : SetUniqueId( GetHelpId() );
457 0 : SetHelpId("");
458 0 : if ( pBindinx )
459 0 : pImp->StartListening( *pBindinx );
460 0 : pImp->aMoveTimer.SetTimeout(50);
461 0 : pImp->aMoveTimer.SetTimeoutHdl(LINK(this,SfxFloatingWindow,TimerHdl));
462 0 : }
463 :
464 34 : SfxFloatingWindow::SfxFloatingWindow( SfxBindings *pBindinx,
465 : SfxChildWindow *pCW,
466 : vcl::Window* pParent,
467 : const OString& rID, const OUString& rUIXMLDescription, const css::uno::Reference<css::frame::XFrame> &rFrame) :
468 : FloatingWindow(pParent, rID, rUIXMLDescription, rFrame),
469 : pBindings(pBindinx),
470 34 : pImp( new SfxFloatingWindow_Impl )
471 : {
472 34 : pImp->pMgr = pCW;
473 34 : pImp->bConstructed = false;
474 :
475 : //do we really need this odd helpid/uniqueid dance ?
476 34 : SetUniqueId( GetHelpId() );
477 34 : SetHelpId("");
478 :
479 34 : if ( pBindinx )
480 34 : pImp->StartListening( *pBindinx );
481 34 : pImp->aMoveTimer.SetTimeout(50);
482 34 : pImp->aMoveTimer.SetTimeoutHdl(LINK(this,SfxFloatingWindow,TimerHdl));
483 34 : }
484 :
485 0 : bool SfxFloatingWindow::Close()
486 :
487 : /* [Description]
488 :
489 : The window is closed when the ChildWindow is destroyed by running the
490 : ChildWindow-slots. If this is method is overridden by a derived class
491 : method, then the SfxModelessDialogWindow: Close) must be called afterwards
492 : if the Close() was not cancelled with "return sal_False".
493 : */
494 :
495 : {
496 : // Execute with Parameters, since Toggle is ignored by some ChildWindows.
497 0 : SfxBoolItem aValue( pImp->pMgr->GetType(), false);
498 : pBindings->GetDispatcher_Impl()->Execute(
499 0 : pImp->pMgr->GetType(),
500 0 : SfxCallMode::RECORD|SfxCallMode::SYNCHRON, &aValue, 0L );
501 0 : return true;
502 : }
503 :
504 :
505 :
506 68 : SfxFloatingWindow::~SfxFloatingWindow()
507 :
508 : /* [Description]
509 :
510 : Destructor
511 : */
512 :
513 : {
514 34 : if ( pImp->pMgr->GetFrame() == pBindings->GetActiveFrame() )
515 0 : pBindings->SetActiveFrame( NULL );
516 34 : delete pImp;
517 34 : }
518 :
519 :
520 :
521 102 : void SfxFloatingWindow::Resize()
522 :
523 : /* [Description]
524 :
525 : This virtual method of the class FloatingWindow keeps track if a change
526 : in size has been made. When this method is overridden by a derived class,
527 : then the SfxFloatingWindow: Resize() must also be called.
528 : */
529 :
530 : {
531 102 : FloatingWindow::Resize();
532 102 : if ( pImp->bConstructed && pImp->pMgr )
533 : {
534 : // start timer for saving window status information
535 34 : pImp->aMoveTimer.Start();
536 : }
537 102 : }
538 :
539 34 : void SfxFloatingWindow::Move()
540 : {
541 34 : FloatingWindow::Move();
542 34 : if ( pImp->bConstructed && pImp->pMgr )
543 : {
544 : // start timer for saving window status information
545 0 : pImp->aMoveTimer.Start();
546 : }
547 34 : }
548 :
549 : /*
550 : Implements a timer event that is triggered by a move or resize of the window
551 : This will save config information to Views.xcu with a small delay
552 : */
553 18 : IMPL_LINK_NOARG(SfxFloatingWindow, TimerHdl)
554 : {
555 9 : pImp->aMoveTimer.Stop();
556 9 : if ( pImp->bConstructed && pImp->pMgr )
557 : {
558 9 : if ( !IsRollUp() )
559 9 : aSize = GetSizePixel();
560 9 : sal_uIntPtr nMask = WINDOWSTATE_MASK_POS | WINDOWSTATE_MASK_STATE;
561 9 : if ( GetStyle() & WB_SIZEABLE )
562 0 : nMask |= ( WINDOWSTATE_MASK_WIDTH | WINDOWSTATE_MASK_HEIGHT );
563 9 : pImp->aWinState = GetWindowState( nMask );
564 9 : GetBindings().GetWorkWindow_Impl()->ConfigChild_Impl( SFX_CHILDWIN_DOCKINGWINDOW, SFX_ALIGNDOCKINGWINDOW, pImp->pMgr->GetType() );
565 : }
566 9 : return 0;
567 : }
568 :
569 :
570 238 : void SfxFloatingWindow::StateChanged( StateChangedType nStateChange )
571 : {
572 238 : if ( nStateChange == StateChangedType::INITSHOW )
573 : {
574 : // FloatingWindows are not centered by default
575 68 : if ( !pImp->aWinState.isEmpty() )
576 60 : SetWindowState( pImp->aWinState );
577 68 : pImp->bConstructed = true;
578 : }
579 :
580 238 : FloatingWindow::StateChanged( nStateChange );
581 238 : }
582 :
583 :
584 34 : void SfxFloatingWindow::Initialize(SfxChildWinInfo *pInfo)
585 :
586 : /* [Description]
587 :
588 : Initialization of a class SfxFloatingWindow through a SfxChildWinInfo.
589 : The initialization is done only in a 2nd step after the constructor and
590 : should be called by the constructor of the derived class or from the
591 : SfxChildWindows.
592 : */
593 : {
594 34 : if (pInfo)
595 34 : pImp->aWinState = pInfo->aWinState;
596 34 : }
597 :
598 :
599 :
600 43 : void SfxFloatingWindow::FillInfo(SfxChildWinInfo& rInfo) const
601 :
602 : /* [Description]
603 :
604 : Fills a SfxChildWinInfo with specific data from SfxFloatingWindow,
605 : so that it can be written in the INI file. It is assumed that rinfo
606 : receives all other possible relevant data in the ChildWindow class.
607 : Insertions are marked with size and the ZoomIn flag.
608 : If this method is overridden, the base implementation must be called first.
609 : */
610 :
611 : {
612 43 : rInfo.aSize = aSize;
613 43 : if ( IsRollUp() )
614 0 : rInfo.nFlags |= SFX_CHILDWIN_ZOOMIN;
615 43 : }
616 :
617 : // SfxSingleTabDialog ----------------------------------------------------
618 :
619 0 : IMPL_LINK_NOARG(SfxSingleTabDialog, OKHdl_Impl)
620 :
621 : /* [Description]
622 :
623 : Ok_Handler; FillItemSet() is called for setting of Page.
624 : */
625 :
626 : {
627 0 : if ( !GetInputItemSet() )
628 : {
629 : // TabPage without ItemSet
630 0 : EndDialog( RET_OK );
631 0 : return 1;
632 : }
633 :
634 0 : if ( !GetOutputItemSet() )
635 : {
636 0 : CreateOutputItemSet( *GetInputItemSet() );
637 : }
638 0 : bool bModified = false;
639 :
640 0 : if ( pImpl->m_pSfxPage->HasExchangeSupport() )
641 : {
642 0 : int nRet = pImpl->m_pSfxPage->DeactivatePage( GetOutputSetImpl() );
643 0 : if ( nRet != SfxTabPage::LEAVE_PAGE )
644 0 : return 0;
645 : else
646 0 : bModified = ( GetOutputItemSet()->Count() > 0 );
647 : }
648 : else
649 0 : bModified = pImpl->m_pSfxPage->FillItemSet( GetOutputSetImpl() );
650 :
651 0 : if ( bModified )
652 : {
653 : // Save user data in IniManager.
654 0 : pImpl->m_pSfxPage->FillUserData();
655 0 : OUString sData( pImpl->m_pSfxPage->GetUserData() );
656 :
657 : OUString sConfigId = OStringToOUString(pImpl->m_pSfxPage->GetConfigId(),
658 0 : RTL_TEXTENCODING_UTF8);
659 0 : if (sConfigId.isEmpty())
660 : {
661 : SAL_WARN("sfx.config", "Tabpage needs to be converted to .ui format");
662 0 : sConfigId = OUString::number(GetUniqId());
663 : }
664 :
665 0 : SvtViewOptions aPageOpt(E_TABPAGE, sConfigId);
666 0 : aPageOpt.SetUserItem( USERITEM_NAME, makeAny( OUString( sData ) ) );
667 0 : EndDialog( RET_OK );
668 : }
669 : else
670 0 : EndDialog( RET_CANCEL );
671 0 : return 0;
672 : }
673 :
674 :
675 :
676 0 : SfxSingleTabDialog::SfxSingleTabDialog(vcl::Window *pParent, const SfxItemSet& rSet,
677 : const OString& rID, const OUString& rUIXMLDescription)
678 : : SfxModalDialog(pParent, rID, rUIXMLDescription)
679 : , fnGetRanges(NULL)
680 0 : , pImpl(new SingleTabDlgImpl)
681 : {
682 0 : get(pOKBtn, "ok");
683 0 : pOKBtn->SetClickHdl( LINK( this, SfxSingleTabDialog, OKHdl_Impl ) );
684 0 : get(pCancelBtn, "cancel");
685 0 : get(pHelpBtn, "help");
686 0 : SetInputSet( &rSet );
687 0 : }
688 :
689 0 : SfxSingleTabDialog::SfxSingleTabDialog(vcl::Window* pParent, const SfxItemSet* pInSet,
690 : const OString& rID, const OUString& rUIXMLDescription)
691 : : SfxModalDialog(pParent, rID, rUIXMLDescription)
692 : , fnGetRanges(NULL)
693 0 : , pImpl(new SingleTabDlgImpl)
694 : {
695 0 : get(pOKBtn, "ok");
696 0 : pOKBtn->SetClickHdl( LINK( this, SfxSingleTabDialog, OKHdl_Impl ) );
697 0 : get(pCancelBtn, "cancel");
698 0 : get(pHelpBtn, "help");
699 0 : SetInputSet( pInSet );
700 0 : }
701 :
702 0 : SfxSingleTabDialog::~SfxSingleTabDialog()
703 : {
704 0 : delete pImpl->m_pSfxPage;
705 0 : delete pImpl->m_pLine;
706 0 : delete pImpl;
707 0 : }
708 :
709 0 : void SfxSingleTabDialog::SetTabPage(SfxTabPage* pTabPage,
710 : GetTabPageRanges pRangesFunc, sal_uInt32 nSettingsId)
711 : /* [Description]
712 :
713 : Insert a (new) TabPage; an existing page is deleted.
714 : The passed on page is initialized with the initially given Itemset
715 : through calling Reset().
716 : */
717 :
718 : {
719 0 : SetUniqId(nSettingsId);
720 0 : delete pImpl->m_pSfxPage;
721 0 : pImpl->m_pSfxPage = pTabPage;
722 0 : fnGetRanges = pRangesFunc;
723 :
724 0 : if ( pImpl->m_pSfxPage )
725 : {
726 : // First obtain the user data, only then Reset()
727 : OUString sConfigId = OStringToOUString(pImpl->m_pSfxPage->GetConfigId(),
728 0 : RTL_TEXTENCODING_UTF8);
729 0 : if (sConfigId.isEmpty())
730 : {
731 : SAL_WARN("sfx.config", "Tabpage needs to be converted to .ui format");
732 0 : sConfigId = OUString::number(GetUniqId());
733 : }
734 :
735 0 : SvtViewOptions aPageOpt(E_TABPAGE, sConfigId);
736 0 : Any aUserItem = aPageOpt.GetUserItem( USERITEM_NAME );
737 0 : OUString sUserData;
738 0 : aUserItem >>= sUserData;
739 0 : pImpl->m_pSfxPage->SetUserData(sUserData);
740 0 : pImpl->m_pSfxPage->Reset( GetInputItemSet() );
741 0 : pImpl->m_pSfxPage->Show();
742 :
743 0 : pHelpBtn->Show(Help::IsContextHelpEnabled());
744 :
745 : // Set TabPage text in the Dialog if there is any
746 0 : OUString sTitle(pImpl->m_pSfxPage->GetText());
747 0 : if (!sTitle.isEmpty())
748 0 : SetText(sTitle);
749 :
750 : // Dialog receives the HelpId of TabPage if there is any
751 0 : OString sHelpId(pImpl->m_pSfxPage->GetHelpId());
752 0 : if (!sHelpId.isEmpty())
753 0 : SetHelpId(sHelpId);
754 0 : OString sUniqueId(pImpl->m_pSfxPage->GetUniqueId());
755 0 : if (!sUniqueId.isEmpty())
756 0 : SetUniqueId(sUniqueId);
757 : }
758 951 : }
759 :
760 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|