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