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 <com/sun/star/beans/XPropertySet.hpp>
21 : #include <com/sun/star/util/PathSettings.hpp>
22 : #include <comphelper/processfactory.hxx>
23 : #include <osl/file.hxx>
24 :
25 : #include <tools/debug.hxx>
26 :
27 : #include <tools/rc.h>
28 : #include <svdata.hxx>
29 : #include <window.h>
30 : #include <brdwin.hxx>
31 :
32 : #include <rtl/strbuf.hxx>
33 : #include <sal/log.hxx>
34 :
35 : #include <vcl/builder.hxx>
36 : #include <vcl/layout.hxx>
37 : #include <vcl/svapp.hxx>
38 : #include <vcl/event.hxx>
39 : #include <vcl/wrkwin.hxx>
40 : #include <vcl/button.hxx>
41 : #include <vcl/mnemonic.hxx>
42 : #include <vcl/dialog.hxx>
43 : #include <vcl/decoview.hxx>
44 : #include <vcl/msgbox.hxx>
45 : #include <vcl/unowrap.hxx>
46 : #include <iostream>
47 :
48 : #ifdef ANDROID
49 : #include <osl/detail/android-bootstrap.h>
50 : #endif
51 :
52 : // =======================================================================
53 :
54 0 : static OString ImplGetDialogText( Dialog* pDialog )
55 : {
56 : OStringBuffer aErrorStr(OUStringToOString(
57 0 : pDialog->GetText(), RTL_TEXTENCODING_UTF8));
58 0 : if ( (pDialog->GetType() == WINDOW_MESSBOX) ||
59 0 : (pDialog->GetType() == WINDOW_INFOBOX) ||
60 0 : (pDialog->GetType() == WINDOW_WARNINGBOX) ||
61 0 : (pDialog->GetType() == WINDOW_ERRORBOX) ||
62 0 : (pDialog->GetType() == WINDOW_QUERYBOX) )
63 : {
64 0 : aErrorStr.append(", ");
65 : aErrorStr.append(OUStringToOString(
66 0 : ((MessBox*)pDialog)->GetMessText(), RTL_TEXTENCODING_UTF8));
67 : }
68 0 : return aErrorStr.makeStringAndClear();
69 : }
70 :
71 : // =======================================================================
72 :
73 7 : static bool ImplIsMnemonicCtrl( Window* pWindow )
74 : {
75 7 : if( ! pWindow->GetSettings().GetStyleSettings().GetAutoMnemonic() )
76 0 : return false;
77 :
78 21 : if ( (pWindow->GetType() == WINDOW_RADIOBUTTON) ||
79 14 : (pWindow->GetType() == WINDOW_CHECKBOX) ||
80 21 : (pWindow->GetType() == WINDOW_TRISTATEBOX) ||
81 7 : (pWindow->GetType() == WINDOW_PUSHBUTTON) )
82 0 : return true;
83 :
84 7 : if ( pWindow->GetType() == WINDOW_FIXEDTEXT )
85 : {
86 1 : if ( pWindow->GetStyle() & (WB_INFO | WB_NOLABEL) )
87 0 : return false;
88 1 : Window* pNextWindow = pWindow->GetWindow( WINDOW_NEXT );
89 1 : if ( !pNextWindow )
90 1 : return false;
91 0 : pNextWindow = pNextWindow->GetWindow( WINDOW_CLIENT );
92 0 : if ( !(pNextWindow->GetStyle() & WB_TABSTOP) ||
93 0 : (pNextWindow->GetType() == WINDOW_FIXEDTEXT) ||
94 0 : (pNextWindow->GetType() == WINDOW_GROUPBOX) ||
95 0 : (pNextWindow->GetType() == WINDOW_RADIOBUTTON) ||
96 0 : (pNextWindow->GetType() == WINDOW_CHECKBOX) ||
97 0 : (pNextWindow->GetType() == WINDOW_TRISTATEBOX) ||
98 0 : (pNextWindow->GetType() == WINDOW_PUSHBUTTON) )
99 0 : return false;
100 :
101 0 : return true;
102 : }
103 :
104 6 : return false;
105 : }
106 :
107 : // -----------------------------------------------------------------------
108 :
109 : // Called by native error dialog popup implementations
110 0 : void ImplHideSplash()
111 : {
112 0 : ImplSVData* pSVData = ImplGetSVData();
113 0 : if( pSVData->mpIntroWindow )
114 0 : pSVData->mpIntroWindow->Hide();
115 0 : }
116 :
117 : //Get next window after pChild of a pTopLevel window as
118 : //if any intermediate layout widgets didn't exist
119 58551 : Window * nextLogicalChildOfParent(Window *pTopLevel, Window *pChild)
120 : {
121 58551 : Window *pLastChild = pChild;
122 :
123 58551 : if (isContainerWindow(*pChild))
124 0 : pChild = pChild->GetWindow(WINDOW_FIRSTCHILD);
125 : else
126 58551 : pChild = pChild->GetWindow(WINDOW_NEXT);
127 :
128 117102 : while (!pChild)
129 : {
130 5774 : Window *pParent = pLastChild->GetParent();
131 5774 : if (!pParent)
132 0 : return NULL;
133 5774 : if (pParent == pTopLevel)
134 5774 : return NULL;
135 0 : pLastChild = pParent;
136 0 : pChild = pParent->GetWindow(WINDOW_NEXT);
137 : }
138 :
139 52777 : if (pChild && isContainerWindow(*pChild))
140 0 : pChild = nextLogicalChildOfParent(pTopLevel, pChild);
141 :
142 52777 : return pChild;
143 : }
144 :
145 0 : Window * prevLogicalChildOfParent(Window *pTopLevel, Window *pChild)
146 : {
147 0 : Window *pLastChild = pChild;
148 :
149 0 : if (isContainerWindow(*pChild))
150 0 : pChild = pChild->GetWindow(WINDOW_LASTCHILD);
151 : else
152 0 : pChild = pChild->GetWindow(WINDOW_PREV);
153 :
154 0 : while (!pChild)
155 : {
156 0 : Window *pParent = pLastChild->GetParent();
157 0 : if (!pParent)
158 0 : return NULL;
159 0 : if (pParent == pTopLevel)
160 0 : return NULL;
161 0 : pLastChild = pParent;
162 0 : pChild = pParent->GetWindow(WINDOW_PREV);
163 : }
164 :
165 0 : if (pChild && isContainerWindow(*pChild))
166 0 : pChild = prevLogicalChildOfParent(pTopLevel, pChild);
167 :
168 0 : return pChild;
169 : }
170 :
171 : //Get first window of a pTopLevel window as
172 : //if any intermediate layout widgets didn't exist
173 42379 : Window * firstLogicalChildOfParent(Window *pTopLevel)
174 : {
175 42379 : Window *pChild = pTopLevel->GetWindow(WINDOW_FIRSTCHILD);
176 42379 : if (pChild && isContainerWindow(*pChild))
177 0 : pChild = nextLogicalChildOfParent(pTopLevel, pChild);
178 42379 : return pChild;
179 : }
180 :
181 : // -----------------------------------------------------------------------
182 :
183 3 : void ImplWindowAutoMnemonic( Window* pWindow )
184 : {
185 3 : MnemonicGenerator aMnemonicGenerator;
186 : Window* pGetChild;
187 : Window* pChild;
188 :
189 : // Die schon vergebenen Mnemonics registieren
190 3 : pGetChild = pWindow->GetWindow( WINDOW_FIRSTCHILD );
191 13 : while ( pGetChild )
192 : {
193 7 : pChild = pGetChild->ImplGetWindow();
194 7 : aMnemonicGenerator.RegisterMnemonic( pChild->GetText() );
195 7 : pGetChild = nextLogicalChildOfParent(pWindow, pGetChild);
196 : }
197 :
198 : // Bei TabPages auch noch die Controls vom Dialog beruecksichtigen
199 3 : if ( pWindow->GetType() == WINDOW_TABPAGE )
200 : {
201 0 : Window* pParent = pWindow->GetParent();
202 0 : if ( pParent->GetType() == WINDOW_TABCONTROL )
203 0 : pParent = pParent->GetParent();
204 :
205 0 : if ( (pParent->GetStyle() & (WB_DIALOGCONTROL | WB_NODIALOGCONTROL)) == WB_DIALOGCONTROL )
206 : {
207 0 : pGetChild = pParent->GetWindow( WINDOW_FIRSTCHILD );
208 0 : while ( pGetChild )
209 : {
210 0 : pChild = pGetChild->ImplGetWindow();
211 0 : aMnemonicGenerator.RegisterMnemonic( pChild->GetText() );
212 0 : pGetChild = nextLogicalChildOfParent(pWindow, pGetChild);
213 : }
214 : }
215 : }
216 :
217 : // Die Mnemonics an die Controls vergeben, die noch keinen haben
218 3 : pGetChild = pWindow->GetWindow( WINDOW_FIRSTCHILD );
219 13 : while ( pGetChild )
220 : {
221 7 : pChild = pGetChild->ImplGetWindow();
222 7 : if ( ImplIsMnemonicCtrl( pChild ) )
223 : {
224 0 : XubString aText = pChild->GetText();
225 0 : if ( aMnemonicGenerator.CreateMnemonic( aText ) )
226 0 : pChild->SetText( aText );
227 : }
228 :
229 7 : pGetChild = nextLogicalChildOfParent(pWindow, pGetChild);
230 3 : }
231 3 : }
232 :
233 0 : static VclButtonBox* getActionArea(Dialog *pDialog)
234 : {
235 0 : VclButtonBox *pButtonBox = NULL;
236 0 : if (pDialog->isLayoutEnabled())
237 : {
238 0 : Window *pBox = pDialog->GetWindow(WINDOW_FIRSTCHILD);
239 0 : Window *pChild = pBox->GetWindow(WINDOW_LASTCHILD);
240 0 : while (pChild)
241 : {
242 0 : pButtonBox = dynamic_cast<VclButtonBox*>(pChild);
243 0 : if (pButtonBox)
244 0 : break;
245 0 : pChild = pChild->GetWindow(WINDOW_PREV);
246 : }
247 : }
248 0 : return pButtonBox;
249 : }
250 :
251 0 : static Window* getActionAreaButtonList(Dialog *pDialog)
252 : {
253 0 : VclButtonBox* pButtonBox = getActionArea(pDialog);
254 0 : if (pButtonBox)
255 0 : return pButtonBox->GetWindow(WINDOW_FIRSTCHILD);
256 0 : return pDialog->GetWindow(WINDOW_FIRSTCHILD);
257 : }
258 :
259 : // =======================================================================
260 :
261 0 : static PushButton* ImplGetDefaultButton( Dialog* pDialog )
262 : {
263 0 : Window* pChild = getActionAreaButtonList(pDialog);
264 0 : while ( pChild )
265 : {
266 0 : if ( pChild->ImplIsPushButton() )
267 : {
268 0 : PushButton* pPushButton = (PushButton*)pChild;
269 0 : if ( pPushButton->ImplIsDefButton() )
270 0 : return pPushButton;
271 : }
272 :
273 0 : pChild = pChild->GetWindow( WINDOW_NEXT );
274 : }
275 :
276 0 : return NULL;
277 : }
278 :
279 : // -----------------------------------------------------------------------
280 :
281 0 : static PushButton* ImplGetOKButton( Dialog* pDialog )
282 : {
283 0 : Window* pChild = getActionAreaButtonList(pDialog);
284 0 : while ( pChild )
285 : {
286 0 : if ( pChild->GetType() == WINDOW_OKBUTTON )
287 0 : return (PushButton*)pChild;
288 :
289 0 : pChild = pChild->GetWindow( WINDOW_NEXT );
290 : }
291 :
292 0 : return NULL;
293 : }
294 :
295 : // -----------------------------------------------------------------------
296 :
297 0 : static PushButton* ImplGetCancelButton( Dialog* pDialog )
298 : {
299 0 : Window* pChild = getActionAreaButtonList(pDialog);
300 :
301 0 : while ( pChild )
302 : {
303 0 : if ( pChild->GetType() == WINDOW_CANCELBUTTON )
304 0 : return (PushButton*)pChild;
305 :
306 0 : pChild = pChild->GetWindow( WINDOW_NEXT );
307 : }
308 :
309 0 : return NULL;
310 : }
311 :
312 : // -----------------------------------------------------------------------
313 :
314 3 : static void ImplMouseAutoPos( Dialog* pDialog )
315 : {
316 3 : sal_uLong nMouseOptions = pDialog->GetSettings().GetMouseSettings().GetOptions();
317 3 : if ( nMouseOptions & MOUSE_OPTION_AUTOCENTERPOS )
318 : {
319 0 : Size aSize = pDialog->GetOutputSizePixel();
320 0 : pDialog->SetPointerPosPixel( Point( aSize.Width()/2, aSize.Height()/2 ) );
321 : }
322 3 : else if ( nMouseOptions & MOUSE_OPTION_AUTODEFBTNPOS )
323 : {
324 0 : Window* pWindow = ImplGetDefaultButton( pDialog );
325 0 : if ( !pWindow )
326 0 : pWindow = ImplGetOKButton( pDialog );
327 0 : if ( !pWindow )
328 0 : pWindow = ImplGetCancelButton( pDialog );
329 0 : if ( !pWindow )
330 0 : pWindow = pDialog;
331 0 : Size aSize = pWindow->GetOutputSizePixel();
332 0 : pWindow->SetPointerPosPixel( Point( aSize.Width()/2, aSize.Height()/2 ) );
333 : }
334 3 : }
335 :
336 : // =======================================================================
337 :
338 : struct DialogImpl
339 : {
340 : long mnResult;
341 : bool mbStartedModal;
342 : Link maEndDialogHdl;
343 :
344 7 : DialogImpl() : mnResult( -1 ), mbStartedModal( false ) {}
345 : };
346 :
347 : // =======================================================================
348 :
349 7 : void Dialog::ImplInitDialogData()
350 : {
351 7 : mpWindowImpl->mbDialog = sal_True;
352 7 : mpDialogParent = NULL;
353 7 : mpPrevExecuteDlg = NULL;
354 7 : mbInExecute = sal_False;
355 7 : mbOldSaveBack = sal_False;
356 7 : mbInClose = sal_False;
357 7 : mbModalMode = sal_False;
358 7 : mpContentArea = NULL;
359 7 : mpActionArea = NULL;
360 7 : mbIsCalculatingInitialLayoutSize = false;
361 7 : mnMousePositioned = 0;
362 7 : mpDialogImpl = new DialogImpl;
363 :
364 : //To-Do, reuse maResizeTimer
365 7 : maLayoutTimer.SetTimeout(50);
366 7 : maLayoutTimer.SetTimeoutHdl( LINK( this, Dialog, ImplHandleLayoutTimerHdl ) );
367 7 : }
368 :
369 : // -----------------------------------------------------------------------
370 :
371 7 : void Dialog::ImplInit( Window* pParent, WinBits nStyle )
372 : {
373 7 : sal_uInt16 nSysWinMode = Application::GetSystemWindowMode();
374 :
375 7 : if ( !(nStyle & WB_NODIALOGCONTROL) )
376 7 : nStyle |= WB_DIALOGCONTROL;
377 7 : nStyle |= WB_ROLLABLE;
378 :
379 : // Now, all Dialogs are per default system windows !!!
380 7 : nStyle |= WB_SYSTEMWINDOW;
381 :
382 :
383 : // parent is NULL: get the default Dialog parent
384 7 : if ( !pParent )
385 : {
386 2 : pParent = Application::GetDefDialogParent();
387 2 : if ( !pParent && !(nStyle & WB_SYSTEMWINDOW) )
388 0 : pParent = ImplGetSVData()->maWinData.mpAppWin;
389 :
390 : // If Parent is disabled, then we search for a modal dialog
391 : // in this frame
392 2 : if ( pParent && (!pParent->IsInputEnabled() || pParent->IsInModalMode()) )
393 : {
394 0 : ImplSVData* pSVData = ImplGetSVData();
395 0 : Dialog* pExeDlg = pSVData->maWinData.mpLastExecuteDlg;
396 0 : while ( pExeDlg )
397 : {
398 : // Nur wenn er sichtbar und enabled ist
399 0 : if ( pParent->ImplGetFirstOverlapWindow()->IsWindowOrChild( pExeDlg, sal_True ) &&
400 0 : pExeDlg->IsReallyVisible() &&
401 0 : pExeDlg->IsEnabled() && pExeDlg->IsInputEnabled() && !pExeDlg->IsInModalMode() )
402 : {
403 0 : pParent = pExeDlg;
404 0 : break;
405 : }
406 :
407 0 : pExeDlg = pExeDlg->mpPrevExecuteDlg;
408 : }
409 : }
410 : }
411 : // DIALOG_NO_PARENT: explicitly don't have a parent for this Dialog
412 5 : else if( pParent == DIALOG_NO_PARENT )
413 3 : pParent = NULL;
414 :
415 :
416 7 : if ( !pParent || (nStyle & WB_SYSTEMWINDOW) ||
417 0 : (pParent->mpWindowImpl->mpFrameData->mbNeedSysWindow && !(nSysWinMode & SYSTEMWINDOW_MODE_NOAUTOMODE)) ||
418 0 : (nSysWinMode & SYSTEMWINDOW_MODE_DIALOG) )
419 : {
420 : // create window with a small border ?
421 7 : if ( (nStyle & (WB_BORDER | WB_NOBORDER | WB_MOVEABLE | WB_SIZEABLE | WB_CLOSEABLE)) == WB_BORDER )
422 : {
423 0 : ImplBorderWindow* pBorderWin = new ImplBorderWindow( pParent, nStyle, BORDERWINDOW_STYLE_FRAME );
424 0 : SystemWindow::ImplInit( pBorderWin, nStyle & ~WB_BORDER, NULL );
425 0 : pBorderWin->mpWindowImpl->mpClientWindow = this;
426 0 : pBorderWin->GetBorder( mpWindowImpl->mnLeftBorder, mpWindowImpl->mnTopBorder, mpWindowImpl->mnRightBorder, mpWindowImpl->mnBottomBorder );
427 0 : mpWindowImpl->mpBorderWindow = pBorderWin;
428 0 : mpWindowImpl->mpRealParent = pParent;
429 : }
430 : else
431 : {
432 7 : mpWindowImpl->mbFrame = sal_True;
433 7 : mpWindowImpl->mbOverlapWin = sal_True;
434 7 : SystemWindow::ImplInit( pParent, (nStyle & (WB_MOVEABLE | WB_SIZEABLE | WB_ROLLABLE | WB_CLOSEABLE | WB_STANDALONE)) | WB_CLOSEABLE, NULL );
435 : // Now set all style bits
436 7 : mpWindowImpl->mnStyle = nStyle;
437 7 : }
438 : }
439 : else
440 : {
441 0 : ImplBorderWindow* pBorderWin = new ImplBorderWindow( pParent, nStyle, BORDERWINDOW_STYLE_OVERLAP | BORDERWINDOW_STYLE_BORDER );
442 0 : SystemWindow::ImplInit( pBorderWin, nStyle & ~WB_BORDER, NULL );
443 0 : pBorderWin->mpWindowImpl->mpClientWindow = this;
444 0 : pBorderWin->GetBorder( mpWindowImpl->mnLeftBorder, mpWindowImpl->mnTopBorder, mpWindowImpl->mnRightBorder, mpWindowImpl->mnBottomBorder );
445 0 : mpWindowImpl->mpBorderWindow = pBorderWin;
446 0 : mpWindowImpl->mpRealParent = pParent;
447 : }
448 :
449 7 : SetActivateMode( ACTIVATE_MODE_GRABFOCUS );
450 :
451 7 : ImplInitSettings();
452 7 : }
453 :
454 : // -----------------------------------------------------------------------
455 :
456 11 : void Dialog::ImplInitSettings()
457 : {
458 : // user override
459 11 : if ( IsControlBackground() )
460 4 : SetBackground( GetControlBackground() );
461 : // NWF background
462 7 : else if( IsNativeControlSupported( CTRL_WINDOW_BACKGROUND, PART_BACKGROUND_DIALOG ) )
463 : {
464 0 : mpWindowImpl->mnNativeBackground = PART_BACKGROUND_DIALOG;
465 0 : EnableChildTransparentMode( sal_True );
466 : }
467 : // fallback to settings color
468 : else
469 7 : SetBackground( GetSettings().GetStyleSettings().GetDialogColor() );
470 11 : }
471 :
472 : // -----------------------------------------------------------------------
473 :
474 0 : Dialog::Dialog( WindowType nType )
475 : : SystemWindow( nType )
476 0 : , mbIsDefferedInit(false)
477 : {
478 0 : ImplInitDialogData();
479 0 : }
480 :
481 0 : OUString VclBuilderContainer::getUIRootDir()
482 : {
483 : /*to-do, check if user config has an override before using shared one, etc*/
484 : css::uno::Reference< css::util::XPathSettings > xPathSettings = css::util::PathSettings::create(
485 0 : ::comphelper::getProcessComponentContext() );
486 :
487 0 : OUString sShareLayer = xPathSettings->getBasePathShareLayer();
488 :
489 : // "UIConfig" is a "multi path" ... use first part only here!
490 0 : sal_Int32 nPos = sShareLayer.indexOf(';');
491 0 : if (nPos > 0)
492 0 : sShareLayer = sShareLayer.copy(0, nPos);
493 :
494 : // Note: May be an user uses URLs without a final slash! Check it ...
495 0 : if (!sShareLayer.endsWith("/"))
496 0 : sShareLayer += "/";
497 :
498 0 : sShareLayer += "soffice.cfg/";
499 : /*to-do, can we merge all this foo with existing soffice.cfg finding code, etc*/
500 0 : return sShareLayer;
501 : }
502 :
503 : //we can't change sizeable after the fact, so need to defer until we know and then
504 : //do the init. Find the real parent stashed in mpDialogParent.
505 0 : void Dialog::doDeferredInit(bool bResizable)
506 : {
507 0 : WinBits nBits = WB_3DLOOK|WB_CLOSEABLE|WB_MOVEABLE;
508 0 : if (bResizable)
509 0 : nBits |= WB_SIZEABLE;
510 0 : Window *pParent = mpDialogParent;
511 0 : mpDialogParent = NULL;
512 0 : ImplInit(pParent, nBits);
513 0 : mbIsDefferedInit = false;
514 0 : }
515 :
516 0 : Dialog::Dialog(Window* pParent, const OString& rID, const OUString& rUIXMLDescription)
517 : : SystemWindow( WINDOW_DIALOG )
518 0 : , mbIsDefferedInit(true)
519 : {
520 0 : ImplInitDialogData();
521 0 : mpDialogParent = pParent; //will be unset in doDeferredInit
522 0 : m_pUIBuilder = new VclBuilder(this, getUIRootDir(), rUIXMLDescription, rID);
523 0 : }
524 :
525 0 : Dialog::Dialog(Window* pParent, const OString& rID, const OUString& rUIXMLDescription, WindowType nType)
526 : : SystemWindow( nType )
527 0 : , mbIsDefferedInit(true)
528 : {
529 0 : ImplInitDialogData();
530 0 : mpDialogParent = pParent; //will be unset in doDeferredInit
531 0 : m_pUIBuilder = new VclBuilder(this, getUIRootDir(), rUIXMLDescription, rID);
532 0 : }
533 :
534 :
535 : // -----------------------------------------------------------------------
536 :
537 7 : Dialog::Dialog( Window* pParent, WinBits nStyle )
538 : : SystemWindow( WINDOW_DIALOG )
539 7 : , mbIsDefferedInit(false)
540 : {
541 7 : ImplInitDialogData();
542 7 : ImplInit( pParent, nStyle );
543 7 : }
544 :
545 0 : WinBits Dialog::init(Window *pParent, const ResId& rResId)
546 : {
547 0 : WinBits nStyle = ImplInitRes( rResId );
548 :
549 0 : ImplInit( pParent, nStyle );
550 0 : ImplLoadRes( rResId );
551 :
552 0 : return nStyle;
553 : }
554 :
555 0 : VclButtonBox* Dialog::get_action_area()
556 : {
557 0 : return mpActionArea;
558 : }
559 :
560 0 : void Dialog::set_action_area(VclButtonBox* pActionArea)
561 : {
562 0 : mpActionArea = pActionArea;
563 0 : }
564 :
565 0 : VclBox* Dialog::get_content_area()
566 : {
567 0 : return mpContentArea;
568 : }
569 :
570 0 : void Dialog::set_content_area(VclBox* pContentArea)
571 : {
572 0 : mpContentArea = pContentArea;
573 0 : }
574 :
575 : // -----------------------------------------------------------------------
576 :
577 14 : Dialog::~Dialog()
578 : {
579 7 : maLayoutTimer.Stop();
580 7 : delete mpDialogImpl;
581 7 : mpDialogImpl = NULL;
582 7 : }
583 :
584 : // -----------------------------------------------------------------------
585 :
586 0 : IMPL_LINK_NOARG(Dialog, ImplAsyncCloseHdl)
587 : {
588 0 : Close();
589 0 : return 0;
590 : }
591 :
592 : // -----------------------------------------------------------------------
593 :
594 61 : long Dialog::Notify( NotifyEvent& rNEvt )
595 : {
596 : // Zuerst Basisklasse rufen wegen TabSteuerung
597 61 : long nRet = SystemWindow::Notify( rNEvt );
598 61 : if ( !nRet )
599 : {
600 61 : if ( rNEvt.GetType() == EVENT_KEYINPUT )
601 : {
602 0 : const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
603 0 : KeyCode aKeyCode = pKEvt->GetKeyCode();
604 0 : sal_uInt16 nKeyCode = aKeyCode.GetCode();
605 :
606 0 : if ( (nKeyCode == KEY_ESCAPE) &&
607 0 : ((GetStyle() & WB_CLOSEABLE) || ImplGetCancelButton( this ) || ImplGetOKButton( this )) )
608 : {
609 : // #i89505# for the benefit of slightly mentally challenged implementations
610 : // like e.g. SfxModelessDialog which destroy themselves inside Close()
611 : // post this Close asynchronous so we can leave our key handler before
612 : // we get destroyed
613 0 : PostUserEvent( LINK( this, Dialog, ImplAsyncCloseHdl ), this );
614 0 : return sal_True;
615 : }
616 : }
617 61 : else if ( rNEvt.GetType() == EVENT_GETFOCUS )
618 : {
619 : // make sure the dialog is still modal
620 : // changing focus between application frames may
621 : // have re-enabled input for our parent
622 3 : if( mbInExecute && mbModalMode )
623 : {
624 : // do not change modal counter (pSVData->maAppData.mnModalDialog)
625 0 : SetModalInputMode( sal_False );
626 0 : SetModalInputMode( sal_True );
627 :
628 : // #93022# def-button might have changed after show
629 0 : if( !mnMousePositioned )
630 : {
631 0 : mnMousePositioned = 1;
632 0 : ImplMouseAutoPos( this );
633 : }
634 :
635 : }
636 : }
637 : }
638 :
639 61 : return nRet;
640 : }
641 :
642 : //What we really want here is something that gives the available width and
643 : //height of a users screen, taking away the space taken up the OS
644 : //taskbar, menus, etc.
645 0 : Size bestmaxFrameSizeForScreenSize(const Size &rScreenSize)
646 : {
647 0 : long w = rScreenSize.Width();
648 0 : if (w <= 800)
649 0 : w -= 15;
650 0 : else if (w <= 1024)
651 0 : w -= 65;
652 : else
653 0 : w -= 115;
654 :
655 0 : long h = rScreenSize.Height();
656 0 : if (h <= 768)
657 0 : h -= 50;
658 : else
659 0 : h -= 100;
660 :
661 0 : return Size(w, h);
662 : }
663 :
664 0 : void Dialog::setOptimalLayoutSize()
665 : {
666 0 : maLayoutTimer.Stop();
667 :
668 : //resize dialog to fit requisition on initial show
669 0 : VclBox *pBox = static_cast<VclBox*>(GetWindow(WINDOW_FIRSTCHILD));
670 :
671 : const DialogStyle& rDialogStyle =
672 0 : GetSettings().GetStyleSettings().GetDialogStyle();
673 0 : pBox->set_border_width(rDialogStyle.content_area_border);
674 0 : pBox->set_spacing(pBox->get_spacing() +
675 0 : rDialogStyle.content_area_spacing);
676 :
677 0 : VclButtonBox *pActionArea = getActionArea(this);
678 0 : if (pActionArea)
679 : {
680 0 : pActionArea->set_border_width(rDialogStyle.action_area_border);
681 0 : pActionArea->set_spacing(rDialogStyle.button_spacing);
682 : }
683 :
684 0 : Size aSize = get_preferred_size();
685 :
686 0 : Size aMax(bestmaxFrameSizeForScreenSize(GetDesktopRectPixel().GetSize()));
687 :
688 0 : aSize.Width() = std::min(aMax.Width(), aSize.Width());
689 0 : aSize.Height() = std::min(aMax.Height(), aSize.Height());
690 :
691 0 : SetMinOutputSizePixel(aSize);
692 0 : SetSizePixel(aSize);
693 0 : setPosSizeOnContainee(aSize, *pBox);
694 0 : }
695 :
696 : // -----------------------------------------------------------------------
697 :
698 13 : void Dialog::StateChanged( StateChangedType nType )
699 : {
700 13 : SystemWindow::StateChanged( nType );
701 :
702 13 : if ( nType == STATE_CHANGE_INITSHOW )
703 : {
704 3 : if ( GetSettings().GetStyleSettings().GetAutoMnemonic() )
705 3 : ImplWindowAutoMnemonic( this );
706 :
707 3 : if (isLayoutEnabled())
708 : {
709 0 : mbIsCalculatingInitialLayoutSize = true;
710 0 : setDeferredProperties();
711 0 : setOptimalLayoutSize();
712 0 : mbIsCalculatingInitialLayoutSize = false;
713 : }
714 :
715 3 : if ( !HasChildPathFocus() || HasFocus() )
716 3 : GrabFocusToFirstControl();
717 3 : if ( !(GetStyle() & WB_CLOSEABLE) )
718 : {
719 0 : if ( ImplGetCancelButton( this ) || ImplGetOKButton( this ) )
720 : {
721 0 : if ( ImplGetBorderWindow() )
722 0 : ((ImplBorderWindow*)ImplGetBorderWindow())->SetCloser();
723 : }
724 : }
725 :
726 3 : ImplMouseAutoPos( this );
727 : }
728 10 : else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
729 : {
730 4 : ImplInitSettings();
731 4 : Invalidate();
732 : }
733 13 : }
734 :
735 : // -----------------------------------------------------------------------
736 :
737 0 : void Dialog::DataChanged( const DataChangedEvent& rDCEvt )
738 : {
739 0 : SystemWindow::DataChanged( rDCEvt );
740 :
741 0 : if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
742 0 : (rDCEvt.GetFlags() & SETTINGS_STYLE) )
743 : {
744 0 : ImplInitSettings();
745 0 : Invalidate();
746 : }
747 0 : }
748 :
749 : // -----------------------------------------------------------------------
750 :
751 0 : sal_Bool Dialog::Close()
752 : {
753 0 : ImplDelData aDelData;
754 0 : ImplAddDel( &aDelData );
755 0 : ImplCallEventListeners( VCLEVENT_WINDOW_CLOSE );
756 0 : if ( aDelData.IsDead() )
757 0 : return sal_False;
758 0 : ImplRemoveDel( &aDelData );
759 :
760 0 : if ( mpWindowImpl->mxWindowPeer.is() && IsCreatedWithToolkit() && !IsInExecute() )
761 0 : return sal_False;
762 :
763 0 : mbInClose = sal_True;
764 :
765 0 : if ( !(GetStyle() & WB_CLOSEABLE) )
766 : {
767 0 : sal_Bool bRet = sal_True;
768 0 : ImplAddDel( &aDelData );
769 0 : PushButton* pButton = ImplGetCancelButton( this );
770 0 : if ( pButton )
771 0 : pButton->Click();
772 : else
773 : {
774 0 : pButton = ImplGetOKButton( this );
775 0 : if ( pButton )
776 0 : pButton->Click();
777 : else
778 0 : bRet = sal_False;
779 : }
780 0 : if ( aDelData.IsDead() )
781 0 : return sal_True;
782 0 : ImplRemoveDel( &aDelData );
783 0 : return bRet;
784 : }
785 :
786 0 : if ( IsInExecute() )
787 : {
788 0 : EndDialog( sal_False );
789 0 : mbInClose = sal_False;
790 0 : return sal_True;
791 : }
792 : else
793 : {
794 0 : mbInClose = sal_False;
795 0 : return SystemWindow::Close();
796 0 : }
797 : }
798 :
799 : // -----------------------------------------------------------------------
800 :
801 0 : sal_Bool Dialog::ImplStartExecuteModal()
802 : {
803 : #ifdef ANDROID
804 : // Not sure if the idea is that this will be called on Android or
805 : // not? But OK, let's try to have the below code reached on
806 : // Android...
807 : #endif
808 :
809 0 : if ( mbInExecute )
810 : {
811 : #ifdef DBG_UTIL
812 : OStringBuffer aErrorStr;
813 : aErrorStr.append("Dialog::StartExecuteModal() is called in Dialog::StartExecuteModal(): ");
814 : aErrorStr.append(ImplGetDialogText(this));
815 : OSL_FAIL(aErrorStr.getStr());
816 : #endif
817 0 : return sal_False;
818 : }
819 :
820 0 : switch ( Application::GetDialogCancelMode() )
821 : {
822 : case Application::DIALOG_CANCEL_OFF:
823 0 : break;
824 : case Application::DIALOG_CANCEL_SILENT:
825 : SAL_INFO(
826 : "vcl",
827 : "Dialog \"" << ImplGetDialogText(this).getStr()
828 : << "\"cancelled in silent mode");
829 0 : return sal_False;
830 : default:
831 : assert(false); // this cannot happen
832 : // fall through
833 : case Application::DIALOG_CANCEL_FATAL:
834 0 : std::abort();
835 : }
836 :
837 : #ifdef DBG_UTIL
838 : Window* pParent = GetParent();
839 : if ( pParent )
840 : {
841 : pParent = pParent->ImplGetFirstOverlapWindow();
842 : DBG_ASSERT( pParent->IsReallyVisible(),
843 : "Dialog::StartExecuteModal() - Parent not visible" );
844 : DBG_ASSERT( pParent->IsInputEnabled(),
845 : "Dialog::StartExecuteModal() - Parent input disabled, use another parent to ensure modality!" );
846 : DBG_ASSERT( ! pParent->IsInModalMode(),
847 : "Dialog::StartExecuteModal() - Parent already modally disabled, use another parent to ensure modality!" );
848 :
849 : }
850 : #endif
851 :
852 0 : ImplSVData* pSVData = ImplGetSVData();
853 :
854 : // Dialoge, die sich in Execute befinden, miteinander verketten
855 0 : mpPrevExecuteDlg = pSVData->maWinData.mpLastExecuteDlg;
856 0 : pSVData->maWinData.mpLastExecuteDlg = this;
857 :
858 : // Capture beenden, damit der Dialog bedient werden kann
859 0 : if ( pSVData->maWinData.mpTrackWin )
860 0 : pSVData->maWinData.mpTrackWin->EndTracking( ENDTRACK_CANCEL );
861 0 : if ( pSVData->maWinData.mpCaptureWin )
862 0 : pSVData->maWinData.mpCaptureWin->ReleaseMouse();
863 0 : EnableInput( sal_True, sal_True );
864 :
865 0 : if ( GetParent() )
866 : {
867 0 : NotifyEvent aNEvt( EVENT_EXECUTEDIALOG, this );
868 0 : GetParent()->Notify( aNEvt );
869 : }
870 0 : mbInExecute = sal_True;
871 0 : SetModalInputMode( sal_True );
872 0 : mbOldSaveBack = IsSaveBackgroundEnabled();
873 0 : EnableSaveBackground();
874 :
875 : // FIXME: no layouting, workaround some clipping issues
876 0 : ImplAdjustNWFSizes();
877 :
878 0 : Show();
879 :
880 0 : pSVData->maAppData.mnModalMode++;
881 0 : return sal_True;
882 : }
883 :
884 : // -----------------------------------------------------------------------
885 :
886 0 : void Dialog::ImplEndExecuteModal()
887 : {
888 0 : ImplSVData* pSVData = ImplGetSVData();
889 0 : pSVData->maAppData.mnModalMode--;
890 0 : }
891 :
892 : // -----------------------------------------------------------------------
893 :
894 0 : short Dialog::Execute()
895 : {
896 0 : setDeferredProperties();
897 :
898 0 : if ( !ImplStartExecuteModal() )
899 0 : return 0;
900 :
901 0 : ImplDelData aDelData;
902 0 : ImplAddDel( &aDelData );
903 :
904 : #ifdef DBG_UTIL
905 : ImplDelData aParentDelData;
906 : Window* pDialogParent = mpDialogParent;
907 : if( pDialogParent )
908 : pDialogParent->ImplAddDel( &aParentDelData );
909 : #endif
910 :
911 : // Yield util EndDialog is called or dialog gets destroyed
912 : // (the latter should not happen, but better safe than sorry
913 0 : while ( !aDelData.IsDead() && mbInExecute )
914 0 : Application::Yield();
915 :
916 0 : ImplEndExecuteModal();
917 :
918 : #ifdef DBG_UTIL
919 : if( pDialogParent )
920 : {
921 : if( ! aParentDelData.IsDead() )
922 : pDialogParent->ImplRemoveDel( &aParentDelData );
923 : else
924 : OSL_FAIL( "Dialog::Execute() - Parent of dialog destroyed in Execute()" );
925 : }
926 : #endif
927 0 : if ( !aDelData.IsDead() )
928 0 : ImplRemoveDel( &aDelData );
929 : #ifdef DBG_UTIL
930 : else
931 : {
932 : OSL_FAIL( "Dialog::Execute() - Dialog destroyed in Execute()" );
933 : }
934 : #endif
935 :
936 0 : long nRet = mpDialogImpl->mnResult;
937 0 : mpDialogImpl->mnResult = -1;
938 0 : return (short)nRet;
939 : }
940 :
941 : // -----------------------------------------------------------------------
942 :
943 : // virtual
944 0 : void Dialog::StartExecuteModal( const Link& rEndDialogHdl )
945 : {
946 0 : if ( !ImplStartExecuteModal() )
947 0 : return;
948 :
949 0 : mpDialogImpl->maEndDialogHdl = rEndDialogHdl;
950 0 : mpDialogImpl->mbStartedModal = true;
951 : }
952 :
953 : // -----------------------------------------------------------------------
954 :
955 0 : void Dialog::EndDialog( long nResult )
956 : {
957 0 : if ( mbInExecute )
958 : {
959 0 : SetModalInputMode( sal_False );
960 :
961 : // Dialog aus der Kette der Dialoge die in Execute stehen entfernen
962 0 : ImplSVData* pSVData = ImplGetSVData();
963 0 : Dialog* pExeDlg = pSVData->maWinData.mpLastExecuteDlg;
964 0 : while ( pExeDlg )
965 : {
966 0 : if ( pExeDlg == this )
967 : {
968 0 : pSVData->maWinData.mpLastExecuteDlg = mpPrevExecuteDlg;
969 0 : break;
970 : }
971 0 : pExeDlg = pExeDlg->mpPrevExecuteDlg;
972 : }
973 : // set focus to previous modal dialogue if it is modal for
974 : // the same frame parent (or NULL)
975 0 : if( mpPrevExecuteDlg )
976 : {
977 0 : Window* pFrameParent = ImplGetFrameWindow()->ImplGetParent();
978 0 : Window* pPrevFrameParent = mpPrevExecuteDlg->ImplGetFrameWindow()->ImplGetParent();
979 0 : if( ( !pFrameParent && !pPrevFrameParent ) ||
980 0 : ( pFrameParent && pPrevFrameParent && pFrameParent->ImplGetFrame() == pPrevFrameParent->ImplGetFrame() )
981 : )
982 : {
983 0 : mpPrevExecuteDlg->GrabFocus();
984 : }
985 : }
986 0 : mpPrevExecuteDlg = NULL;
987 :
988 0 : Hide();
989 0 : EnableSaveBackground( mbOldSaveBack );
990 0 : if ( GetParent() )
991 : {
992 0 : NotifyEvent aNEvt( EVENT_ENDEXECUTEDIALOG, this );
993 0 : GetParent()->Notify( aNEvt );
994 : }
995 :
996 0 : mpDialogImpl->mnResult = nResult;
997 :
998 0 : if ( mpDialogImpl->mbStartedModal )
999 : {
1000 0 : ImplEndExecuteModal();
1001 0 : mpDialogImpl->maEndDialogHdl.Call( this );
1002 :
1003 0 : mpDialogImpl->maEndDialogHdl = Link();
1004 0 : mpDialogImpl->mbStartedModal = false;
1005 0 : mpDialogImpl->mnResult = -1;
1006 : }
1007 0 : mbInExecute = sal_False;
1008 : }
1009 0 : }
1010 :
1011 : // -----------------------------------------------------------------------
1012 :
1013 0 : long Dialog::GetResult() const
1014 : {
1015 0 : return mpDialogImpl->mnResult;
1016 : }
1017 :
1018 : // -----------------------------------------------------------------------
1019 :
1020 0 : void Dialog::EndAllDialogs( Window* pParent )
1021 : {
1022 0 : ImplSVData* pSVData = ImplGetSVData();
1023 : Dialog* pTempModDialog;
1024 0 : Dialog* pModDialog = pSVData->maWinData.mpLastExecuteDlg;
1025 0 : while ( pModDialog )
1026 : {
1027 0 : pTempModDialog = pModDialog->mpPrevExecuteDlg;
1028 0 : if( !pParent || ( pParent && pParent->IsWindowOrChild( pModDialog, sal_True ) ) )
1029 : {
1030 0 : pModDialog->EndDialog( sal_False );
1031 0 : pModDialog->PostUserEvent( Link() );
1032 : }
1033 0 : pModDialog = pTempModDialog;
1034 : }
1035 0 : }
1036 :
1037 : // -----------------------------------------------------------------------
1038 :
1039 0 : void Dialog::SetModalInputMode( sal_Bool bModal )
1040 : {
1041 0 : if ( bModal == mbModalMode )
1042 0 : return;
1043 :
1044 0 : ImplSVData* pSVData = ImplGetSVData();
1045 0 : mbModalMode = bModal;
1046 0 : if ( bModal )
1047 : {
1048 0 : pSVData->maAppData.mnModalDialog++;
1049 :
1050 : // Diable the prev Modal Dialog, because our dialog must close at first,
1051 : // before the other dialog can be closed (because the other dialog
1052 : // is on stack since our dialog returns)
1053 0 : if ( mpPrevExecuteDlg && !mpPrevExecuteDlg->IsWindowOrChild( this, sal_True ) )
1054 0 : mpPrevExecuteDlg->EnableInput( sal_False, sal_True, sal_True, this );
1055 :
1056 : // determine next overlap dialog parent
1057 0 : Window* pParent = GetParent();
1058 0 : if ( pParent )
1059 : {
1060 : // #103716# dialogs should always be modal to the whole frame window
1061 : // #115933# disable the whole frame hierarchie, useful if our parent
1062 : // is a modeless dialog
1063 0 : mpDialogParent = pParent->mpWindowImpl->mpFrameWindow;
1064 0 : mpDialogParent->ImplIncModalCount();
1065 : }
1066 :
1067 : }
1068 : else
1069 : {
1070 0 : pSVData->maAppData.mnModalDialog--;
1071 :
1072 0 : if ( mpDialogParent )
1073 : {
1074 : // #115933# re-enable the whole frame hierarchie again (see above)
1075 : // note that code in getfocus assures that we do not accidentally enable
1076 : // windows that were disabled before
1077 0 : mpDialogParent->ImplDecModalCount();
1078 : }
1079 :
1080 : // Enable the prev Modal Dialog
1081 0 : if ( mpPrevExecuteDlg && !mpPrevExecuteDlg->IsWindowOrChild( this, sal_True ) )
1082 : {
1083 0 : mpPrevExecuteDlg->EnableInput( sal_True, sal_True, sal_True, this );
1084 : // ensure continued modality of prev dialog
1085 : // do not change modality counter
1086 :
1087 :
1088 : // #i119994# need find the last modal dialog before reactive it
1089 0 : Dialog * pPrevModalDlg = mpPrevExecuteDlg;
1090 :
1091 0 : while( pPrevModalDlg && !pPrevModalDlg->IsModalInputMode() )
1092 0 : pPrevModalDlg = pPrevModalDlg->mpPrevExecuteDlg;
1093 :
1094 0 : if( pPrevModalDlg &&
1095 0 : ( pPrevModalDlg == mpPrevExecuteDlg
1096 0 : || !pPrevModalDlg->IsWindowOrChild( this, sal_True ) ) )
1097 : {
1098 0 : mpPrevExecuteDlg->SetModalInputMode( sal_False );
1099 0 : mpPrevExecuteDlg->SetModalInputMode( sal_True );
1100 : }
1101 : }
1102 : }
1103 : }
1104 :
1105 : // -----------------------------------------------------------------------
1106 :
1107 0 : void Dialog::SetModalInputMode( sal_Bool bModal, sal_Bool bSubModalDialogs )
1108 : {
1109 0 : if ( bSubModalDialogs )
1110 : {
1111 0 : Window* pOverlap = ImplGetFirstOverlapWindow();
1112 0 : pOverlap = pOverlap->mpWindowImpl->mpFirstOverlap;
1113 0 : while ( pOverlap )
1114 : {
1115 0 : if ( pOverlap->IsDialog() )
1116 0 : ((Dialog*)pOverlap)->SetModalInputMode( bModal, sal_True );
1117 0 : pOverlap = pOverlap->mpWindowImpl->mpNext;
1118 : }
1119 : }
1120 :
1121 0 : SetModalInputMode( bModal );
1122 0 : }
1123 :
1124 : // -----------------------------------------------------------------------
1125 :
1126 3 : void Dialog::GrabFocusToFirstControl()
1127 : {
1128 : Window* pFocusControl;
1129 :
1130 : // Wenn Dialog den Focus hat, versuchen wr trotzdem
1131 : // ein Focus-Control zu finden
1132 3 : if ( HasFocus() )
1133 0 : pFocusControl = NULL;
1134 : else
1135 : {
1136 : // Wenn schon ein Child-Fenster mal den Focus hatte,
1137 : // dann dieses bevorzugen
1138 3 : pFocusControl = ImplGetFirstOverlapWindow()->mpWindowImpl->mpLastFocusWindow;
1139 : // Control aus der Dialog-Steuerung suchen
1140 3 : if ( pFocusControl )
1141 0 : pFocusControl = ImplFindDlgCtrlWindow( pFocusControl );
1142 : }
1143 : // Kein Control hatte vorher den Focus, oder das Control
1144 : // befindet sich nicht in der Tab-Steuerung, dann das erste
1145 : // Control in der TabSteuerung den Focus geben
1146 3 : if ( !pFocusControl ||
1147 0 : !(pFocusControl->GetStyle() & WB_TABSTOP) ||
1148 0 : !isVisibleInLayout(pFocusControl) ||
1149 3 : !isEnabledInLayout(pFocusControl) || !pFocusControl->IsInputEnabled() )
1150 : {
1151 3 : sal_uInt16 n = 0;
1152 3 : pFocusControl = ImplGetDlgWindow( n, DLGWINDOW_FIRST );
1153 : }
1154 3 : if ( pFocusControl )
1155 0 : pFocusControl->ImplControlFocus( GETFOCUS_INIT );
1156 3 : }
1157 :
1158 0 : void Dialog::GetDrawWindowBorder( sal_Int32& rLeftBorder, sal_Int32& rTopBorder, sal_Int32& rRightBorder, sal_Int32& rBottomBorder ) const
1159 : {
1160 0 : ImplBorderWindow aImplWin( (Window*)this, WB_BORDER|WB_STDWORK, BORDERWINDOW_STYLE_OVERLAP );
1161 : // aImplWin.SetText( GetText() );
1162 : // aImplWin.SetPosSizePixel( aPos.X(), aPos.Y(), aSize.Width(), aSize.Height() );
1163 : // aImplWin.SetDisplayActive( sal_True );
1164 : // aImplWin.InitView();
1165 0 : aImplWin.GetBorder( rLeftBorder, rTopBorder, rRightBorder, rBottomBorder );
1166 0 : }
1167 :
1168 :
1169 0 : void Dialog::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong )
1170 : {
1171 0 : Point aPos = pDev->LogicToPixel( rPos );
1172 0 : Size aSize = pDev->LogicToPixel( rSize );
1173 :
1174 0 : Wallpaper aWallpaper = GetBackground();
1175 0 : if ( !aWallpaper.IsBitmap() )
1176 0 : ImplInitSettings();
1177 :
1178 0 : pDev->Push();
1179 0 : pDev->SetMapMode();
1180 0 : pDev->SetLineColor();
1181 :
1182 0 : if ( aWallpaper.IsBitmap() )
1183 0 : pDev->DrawBitmapEx( aPos, aSize, aWallpaper.GetBitmap() );
1184 : else
1185 : {
1186 0 : pDev->SetFillColor( aWallpaper.GetColor() );
1187 0 : pDev->DrawRect( Rectangle( aPos, aSize ) );
1188 : }
1189 :
1190 0 : if (!( GetStyle() & WB_NOBORDER ))
1191 : {
1192 0 : ImplBorderWindow aImplWin( this, WB_BORDER|WB_STDWORK, BORDERWINDOW_STYLE_OVERLAP );
1193 0 : aImplWin.SetText( GetText() );
1194 0 : aImplWin.setPosSizePixel( aPos.X(), aPos.Y(), aSize.Width(), aSize.Height() );
1195 0 : aImplWin.SetDisplayActive( sal_True );
1196 0 : aImplWin.InitView();
1197 :
1198 0 : aImplWin.Draw( Rectangle( aPos, aSize ), pDev, aPos );
1199 : }
1200 :
1201 0 : pDev->Pop();
1202 0 : }
1203 :
1204 115 : bool Dialog::isLayoutEnabled() const
1205 : {
1206 : //pre dtor called, and single child is a container => we're layout enabled
1207 115 : return mpDialogImpl ? ::isLayoutEnabled(this) : false;
1208 : }
1209 :
1210 0 : Size Dialog::GetOptimalSize() const
1211 : {
1212 0 : if (!isLayoutEnabled())
1213 0 : return SystemWindow::GetOptimalSize();
1214 :
1215 0 : Size aSize = VclContainer::getLayoutRequisition(*GetWindow(WINDOW_FIRSTCHILD));
1216 :
1217 0 : sal_Int32 nBorderWidth = get_border_width();
1218 :
1219 0 : aSize.Height() += mpWindowImpl->mnLeftBorder + mpWindowImpl->mnRightBorder
1220 0 : + 2*nBorderWidth;
1221 0 : aSize.Width() += mpWindowImpl->mnTopBorder + mpWindowImpl->mnBottomBorder
1222 0 : + 2*nBorderWidth;
1223 :
1224 0 : return Window::CalcWindowSize(aSize);
1225 : }
1226 :
1227 0 : void Dialog::setPosSizeOnContainee(Size aSize, VclContainer &rBox)
1228 : {
1229 0 : sal_Int32 nBorderWidth = get_border_width();
1230 :
1231 0 : aSize.Width() -= mpWindowImpl->mnLeftBorder + mpWindowImpl->mnRightBorder
1232 0 : + 2 * nBorderWidth;
1233 0 : aSize.Height() -= mpWindowImpl->mnTopBorder + mpWindowImpl->mnBottomBorder
1234 0 : + 2 * nBorderWidth;
1235 :
1236 : Point aPos(mpWindowImpl->mnLeftBorder + nBorderWidth,
1237 0 : mpWindowImpl->mnTopBorder + nBorderWidth);
1238 :
1239 0 : VclContainer::setLayoutAllocation(rBox, aPos, aSize);
1240 0 : }
1241 :
1242 0 : IMPL_LINK( Dialog, ImplHandleLayoutTimerHdl, void*, EMPTYARG )
1243 : {
1244 0 : if (!isLayoutEnabled())
1245 : {
1246 : SAL_WARN("vcl.layout", "Dialog has become non-layout because extra children have been added directly to it.");
1247 0 : return 0;
1248 : }
1249 :
1250 0 : VclBox *pBox = static_cast<VclBox*>(GetWindow(WINDOW_FIRSTCHILD));
1251 : assert(pBox);
1252 0 : setPosSizeOnContainee(GetSizePixel(), *pBox);
1253 0 : return 0;
1254 : }
1255 :
1256 112 : void Dialog::queue_layout()
1257 : {
1258 112 : if (hasPendingLayout())
1259 0 : return;
1260 112 : if (IsInClose())
1261 0 : return;
1262 112 : if (!isLayoutEnabled())
1263 112 : return;
1264 0 : maLayoutTimer.Start();
1265 : }
1266 :
1267 0 : void Dialog::Resize()
1268 : {
1269 0 : queue_layout();
1270 0 : }
1271 :
1272 0 : bool Dialog::set_property(const OString &rKey, const OString &rValue)
1273 : {
1274 0 : if (rKey == "border-width")
1275 0 : set_border_width(rValue.toInt32());
1276 : else
1277 0 : return SystemWindow::set_property(rKey, rValue);
1278 0 : return true;
1279 : }
1280 :
1281 4 : void Dialog::SetText(const OUString& rStr)
1282 : {
1283 4 : setDeferredProperties();
1284 4 : SystemWindow::SetText(rStr);
1285 4 : }
1286 :
1287 2 : OUString Dialog::GetText() const
1288 : {
1289 2 : const_cast<Dialog*>(this)->setDeferredProperties();
1290 2 : return SystemWindow::GetText();
1291 : }
1292 :
1293 20 : VclBuilderContainer::VclBuilderContainer()
1294 20 : : m_pUIBuilder(NULL)
1295 : {
1296 20 : }
1297 :
1298 20 : VclBuilderContainer::~VclBuilderContainer()
1299 : {
1300 20 : delete m_pUIBuilder;
1301 20 : }
1302 :
1303 : // -----------------------------------------------------------------------
1304 :
1305 0 : ModelessDialog::ModelessDialog( Window* pParent, const ResId& rResId ) :
1306 0 : Dialog( WINDOW_MODELESSDIALOG )
1307 : {
1308 0 : rResId.SetRT( RSC_MODELESSDIALOG );
1309 :
1310 0 : WinBits nStyle = init( pParent, rResId );
1311 :
1312 0 : if ( !(nStyle & WB_HIDE) )
1313 0 : Show();
1314 0 : }
1315 :
1316 0 : ModelessDialog::ModelessDialog( Window* pParent, const OString& rID, const OUString& rUIXMLDescription ) :
1317 0 : Dialog(pParent, rID, rUIXMLDescription, WINDOW_MODELESSDIALOG)
1318 : {
1319 0 : }
1320 :
1321 : // =======================================================================
1322 :
1323 0 : ModalDialog::ModalDialog( Window* pParent, WinBits nStyle ) :
1324 0 : Dialog( WINDOW_MODALDIALOG )
1325 : {
1326 0 : ImplInit( pParent, nStyle );
1327 0 : }
1328 :
1329 : // -----------------------------------------------------------------------
1330 :
1331 0 : ModalDialog::ModalDialog( Window* pParent, const ResId& rResId ) :
1332 0 : Dialog( WINDOW_MODALDIALOG )
1333 : {
1334 0 : rResId.SetRT( RSC_MODALDIALOG );
1335 0 : init( pParent, rResId );
1336 0 : }
1337 :
1338 0 : ModalDialog::ModalDialog( Window* pParent, const OString& rID, const OUString& rUIXMLDescription ) :
1339 0 : Dialog(pParent, rID, rUIXMLDescription, WINDOW_MODALDIALOG)
1340 : {
1341 465 : }
1342 :
1343 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|