xref: /AOO41X/main/vcl/source/window/dialog.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_vcl.hxx"
30*cdf0e10cSrcweir #include <tools/debug.hxx>
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include <tools/rc.h>
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include <svdata.hxx>
35*cdf0e10cSrcweir #include <window.h>
36*cdf0e10cSrcweir #include <brdwin.hxx>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir #include <vcl/svapp.hxx>
39*cdf0e10cSrcweir #include <vcl/event.hxx>
40*cdf0e10cSrcweir #include <vcl/wrkwin.hxx>
41*cdf0e10cSrcweir #include <vcl/button.hxx>
42*cdf0e10cSrcweir #include <vcl/mnemonic.hxx>
43*cdf0e10cSrcweir #include <vcl/dialog.hxx>
44*cdf0e10cSrcweir #include <vcl/decoview.hxx>
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir #ifdef DBG_UTIL
47*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
48*cdf0e10cSrcweir #endif
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir #include <vcl/unowrap.hxx>
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir // =======================================================================
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir #ifdef DBG_UTIL
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir static ByteString ImplGetDialogText( Dialog* pDialog )
59*cdf0e10cSrcweir {
60*cdf0e10cSrcweir     ByteString aErrorStr( pDialog->GetText(), RTL_TEXTENCODING_UTF8 );
61*cdf0e10cSrcweir     if ( (pDialog->GetType() == WINDOW_MESSBOX) ||
62*cdf0e10cSrcweir          (pDialog->GetType() == WINDOW_INFOBOX) ||
63*cdf0e10cSrcweir          (pDialog->GetType() == WINDOW_WARNINGBOX) ||
64*cdf0e10cSrcweir          (pDialog->GetType() == WINDOW_ERRORBOX) ||
65*cdf0e10cSrcweir          (pDialog->GetType() == WINDOW_QUERYBOX) )
66*cdf0e10cSrcweir     {
67*cdf0e10cSrcweir         aErrorStr += ", ";
68*cdf0e10cSrcweir         aErrorStr += ByteString( ((MessBox*)pDialog)->GetMessText(), RTL_TEXTENCODING_UTF8 );
69*cdf0e10cSrcweir     }
70*cdf0e10cSrcweir     return aErrorStr;
71*cdf0e10cSrcweir }
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir #endif
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir // =======================================================================
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir static sal_Bool ImplIsMnemonicCtrl( Window* pWindow )
78*cdf0e10cSrcweir {
79*cdf0e10cSrcweir     if( ! pWindow->GetSettings().GetStyleSettings().GetAutoMnemonic() )
80*cdf0e10cSrcweir         return sal_False;
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir     if ( (pWindow->GetType() == WINDOW_RADIOBUTTON) ||
83*cdf0e10cSrcweir          (pWindow->GetType() == WINDOW_CHECKBOX) ||
84*cdf0e10cSrcweir          (pWindow->GetType() == WINDOW_TRISTATEBOX) ||
85*cdf0e10cSrcweir          (pWindow->GetType() == WINDOW_PUSHBUTTON) )
86*cdf0e10cSrcweir         return sal_True;
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir     if ( pWindow->GetType() == WINDOW_FIXEDTEXT )
89*cdf0e10cSrcweir     {
90*cdf0e10cSrcweir         if ( pWindow->GetStyle() & (WB_INFO | WB_NOLABEL) )
91*cdf0e10cSrcweir             return sal_False;
92*cdf0e10cSrcweir         Window* pNextWindow = pWindow->GetWindow( WINDOW_NEXT );
93*cdf0e10cSrcweir         if ( !pNextWindow )
94*cdf0e10cSrcweir             return sal_False;
95*cdf0e10cSrcweir         pNextWindow = pNextWindow->GetWindow( WINDOW_CLIENT );
96*cdf0e10cSrcweir         if ( !(pNextWindow->GetStyle() & WB_TABSTOP) ||
97*cdf0e10cSrcweir              (pNextWindow->GetType() == WINDOW_FIXEDTEXT) ||
98*cdf0e10cSrcweir              (pNextWindow->GetType() == WINDOW_GROUPBOX) ||
99*cdf0e10cSrcweir              (pNextWindow->GetType() == WINDOW_RADIOBUTTON) ||
100*cdf0e10cSrcweir              (pNextWindow->GetType() == WINDOW_CHECKBOX) ||
101*cdf0e10cSrcweir              (pNextWindow->GetType() == WINDOW_TRISTATEBOX) ||
102*cdf0e10cSrcweir              (pNextWindow->GetType() == WINDOW_PUSHBUTTON) )
103*cdf0e10cSrcweir             return sal_False;
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir         return sal_True;
106*cdf0e10cSrcweir     }
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir     return sal_False;
109*cdf0e10cSrcweir }
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir // -----------------------------------------------------------------------
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir void ImplWindowAutoMnemonic( Window* pWindow )
114*cdf0e10cSrcweir {
115*cdf0e10cSrcweir     MnemonicGenerator   aMnemonicGenerator;
116*cdf0e10cSrcweir     Window*                 pGetChild;
117*cdf0e10cSrcweir     Window*                 pChild;
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir     // Die schon vergebenen Mnemonics registieren
120*cdf0e10cSrcweir     pGetChild = pWindow->GetWindow( WINDOW_FIRSTCHILD );
121*cdf0e10cSrcweir     while ( pGetChild )
122*cdf0e10cSrcweir     {
123*cdf0e10cSrcweir         pChild = pGetChild->ImplGetWindow();
124*cdf0e10cSrcweir         aMnemonicGenerator.RegisterMnemonic( pChild->GetText() );
125*cdf0e10cSrcweir         pGetChild = pGetChild->GetWindow( WINDOW_NEXT );
126*cdf0e10cSrcweir     }
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir     // Bei TabPages auch noch die Controls vom Dialog beruecksichtigen
129*cdf0e10cSrcweir     if ( pWindow->GetType() == WINDOW_TABPAGE )
130*cdf0e10cSrcweir     {
131*cdf0e10cSrcweir         Window* pParent = pWindow->GetParent();
132*cdf0e10cSrcweir         if ( pParent->GetType() == WINDOW_TABCONTROL )
133*cdf0e10cSrcweir             pParent = pParent->GetParent();
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir         if ( (pParent->GetStyle() & (WB_DIALOGCONTROL | WB_NODIALOGCONTROL)) == WB_DIALOGCONTROL )
136*cdf0e10cSrcweir         {
137*cdf0e10cSrcweir             pGetChild = pParent->GetWindow( WINDOW_FIRSTCHILD );
138*cdf0e10cSrcweir             while ( pGetChild )
139*cdf0e10cSrcweir             {
140*cdf0e10cSrcweir                 pChild = pGetChild->ImplGetWindow();
141*cdf0e10cSrcweir                 aMnemonicGenerator.RegisterMnemonic( pChild->GetText() );
142*cdf0e10cSrcweir                 pGetChild = pGetChild->GetWindow( WINDOW_NEXT );
143*cdf0e10cSrcweir             }
144*cdf0e10cSrcweir         }
145*cdf0e10cSrcweir     }
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir     // Die Mnemonics an die Controls vergeben, die noch keinen haben
148*cdf0e10cSrcweir     pGetChild = pWindow->GetWindow( WINDOW_FIRSTCHILD );
149*cdf0e10cSrcweir     while ( pGetChild )
150*cdf0e10cSrcweir     {
151*cdf0e10cSrcweir         pChild = pGetChild->ImplGetWindow();
152*cdf0e10cSrcweir         if ( ImplIsMnemonicCtrl( pChild ) )
153*cdf0e10cSrcweir         {
154*cdf0e10cSrcweir             XubString aText = pChild->GetText();
155*cdf0e10cSrcweir             if ( aMnemonicGenerator.CreateMnemonic( aText ) )
156*cdf0e10cSrcweir                 pChild->SetText( aText );
157*cdf0e10cSrcweir         }
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir         pGetChild = pGetChild->GetWindow( WINDOW_NEXT );
160*cdf0e10cSrcweir     }
161*cdf0e10cSrcweir }
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir // =======================================================================
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir static PushButton* ImplGetDefaultButton( Dialog* pDialog )
166*cdf0e10cSrcweir {
167*cdf0e10cSrcweir     Window* pChild = pDialog->GetWindow( WINDOW_FIRSTCHILD );
168*cdf0e10cSrcweir     while ( pChild )
169*cdf0e10cSrcweir     {
170*cdf0e10cSrcweir         if ( pChild->ImplIsPushButton() )
171*cdf0e10cSrcweir         {
172*cdf0e10cSrcweir             PushButton* pPushButton = (PushButton*)pChild;
173*cdf0e10cSrcweir             if ( pPushButton->ImplIsDefButton() )
174*cdf0e10cSrcweir                 return pPushButton;
175*cdf0e10cSrcweir         }
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir         pChild = pChild->GetWindow( WINDOW_NEXT );
178*cdf0e10cSrcweir     }
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir     return NULL;
181*cdf0e10cSrcweir }
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir // -----------------------------------------------------------------------
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir static PushButton* ImplGetOKButton( Dialog* pDialog )
186*cdf0e10cSrcweir {
187*cdf0e10cSrcweir     Window* pChild = pDialog->GetWindow( WINDOW_FIRSTCHILD );
188*cdf0e10cSrcweir     while ( pChild )
189*cdf0e10cSrcweir     {
190*cdf0e10cSrcweir         if ( pChild->GetType() == WINDOW_OKBUTTON )
191*cdf0e10cSrcweir             return (PushButton*)pChild;
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir         pChild = pChild->GetWindow( WINDOW_NEXT );
194*cdf0e10cSrcweir     }
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir     return NULL;
197*cdf0e10cSrcweir }
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir // -----------------------------------------------------------------------
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir static PushButton* ImplGetCancelButton( Dialog* pDialog )
202*cdf0e10cSrcweir {
203*cdf0e10cSrcweir     Window* pChild = pDialog->GetWindow( WINDOW_FIRSTCHILD );
204*cdf0e10cSrcweir     while ( pChild )
205*cdf0e10cSrcweir     {
206*cdf0e10cSrcweir         if ( pChild->GetType() == WINDOW_CANCELBUTTON )
207*cdf0e10cSrcweir             return (PushButton*)pChild;
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir         pChild = pChild->GetWindow( WINDOW_NEXT );
210*cdf0e10cSrcweir     }
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir     return NULL;
213*cdf0e10cSrcweir }
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir // -----------------------------------------------------------------------
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir static void ImplMouseAutoPos( Dialog* pDialog )
218*cdf0e10cSrcweir {
219*cdf0e10cSrcweir     sal_uLong nMouseOptions = pDialog->GetSettings().GetMouseSettings().GetOptions();
220*cdf0e10cSrcweir     if ( nMouseOptions & MOUSE_OPTION_AUTOCENTERPOS )
221*cdf0e10cSrcweir     {
222*cdf0e10cSrcweir         Size aSize = pDialog->GetOutputSizePixel();
223*cdf0e10cSrcweir         pDialog->SetPointerPosPixel( Point( aSize.Width()/2, aSize.Height()/2 ) );
224*cdf0e10cSrcweir     }
225*cdf0e10cSrcweir     else if ( nMouseOptions & MOUSE_OPTION_AUTODEFBTNPOS )
226*cdf0e10cSrcweir     {
227*cdf0e10cSrcweir         Window* pWindow = ImplGetDefaultButton( pDialog );
228*cdf0e10cSrcweir         if ( !pWindow )
229*cdf0e10cSrcweir             pWindow = ImplGetOKButton( pDialog );
230*cdf0e10cSrcweir         if ( !pWindow )
231*cdf0e10cSrcweir             pWindow = ImplGetCancelButton( pDialog );
232*cdf0e10cSrcweir         if ( !pWindow )
233*cdf0e10cSrcweir             pWindow = pDialog;
234*cdf0e10cSrcweir         Size aSize = pWindow->GetOutputSizePixel();
235*cdf0e10cSrcweir         pWindow->SetPointerPosPixel( Point( aSize.Width()/2, aSize.Height()/2 ) );
236*cdf0e10cSrcweir     }
237*cdf0e10cSrcweir }
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir // =======================================================================
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir struct DialogImpl
242*cdf0e10cSrcweir {
243*cdf0e10cSrcweir     long    mnResult;
244*cdf0e10cSrcweir     bool    mbStartedModal;
245*cdf0e10cSrcweir     Link    maEndDialogHdl;
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir     DialogImpl() : mnResult( -1 ), mbStartedModal( false ) {}
248*cdf0e10cSrcweir };
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir // =======================================================================
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir void Dialog::ImplInitDialogData()
253*cdf0e10cSrcweir {
254*cdf0e10cSrcweir     mpWindowImpl->mbDialog  = sal_True;
255*cdf0e10cSrcweir     mpDialogParent          = NULL;
256*cdf0e10cSrcweir     mpPrevExecuteDlg        = NULL;
257*cdf0e10cSrcweir     mbInExecute             = sal_False;
258*cdf0e10cSrcweir     mbOldSaveBack           = sal_False;
259*cdf0e10cSrcweir     mbInClose               = sal_False;
260*cdf0e10cSrcweir     mbModalMode             = sal_False;
261*cdf0e10cSrcweir     mnMousePositioned       = 0;
262*cdf0e10cSrcweir     mpDialogImpl            = new DialogImpl;
263*cdf0e10cSrcweir }
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir // -----------------------------------------------------------------------
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir void Dialog::ImplInit( Window* pParent, WinBits nStyle )
268*cdf0e10cSrcweir {
269*cdf0e10cSrcweir     sal_uInt16 nSysWinMode = Application::GetSystemWindowMode();
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir     if ( !(nStyle & WB_NODIALOGCONTROL) )
272*cdf0e10cSrcweir         nStyle |= WB_DIALOGCONTROL;
273*cdf0e10cSrcweir     nStyle |= WB_ROLLABLE;
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir     // Now, all Dialogs are per default system windows !!!
276*cdf0e10cSrcweir     nStyle |= WB_SYSTEMWINDOW;
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir     // parent is NULL: get the default Dialog parent
280*cdf0e10cSrcweir     if ( !pParent )
281*cdf0e10cSrcweir     {
282*cdf0e10cSrcweir         pParent = Application::GetDefDialogParent();
283*cdf0e10cSrcweir         if ( !pParent && !(nStyle & WB_SYSTEMWINDOW) )
284*cdf0e10cSrcweir             pParent = ImplGetSVData()->maWinData.mpAppWin;
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir         // If Parent is disabled, then we search for a modal dialog
287*cdf0e10cSrcweir         // in this frame
288*cdf0e10cSrcweir         if ( pParent && (!pParent->IsInputEnabled() || pParent->IsInModalMode()) )
289*cdf0e10cSrcweir         {
290*cdf0e10cSrcweir             ImplSVData* pSVData = ImplGetSVData();
291*cdf0e10cSrcweir             Dialog*     pExeDlg = pSVData->maWinData.mpLastExecuteDlg;
292*cdf0e10cSrcweir             while ( pExeDlg )
293*cdf0e10cSrcweir             {
294*cdf0e10cSrcweir                 // Nur wenn er sichtbar und enabled ist
295*cdf0e10cSrcweir                 if ( pParent->ImplGetFirstOverlapWindow()->IsWindowOrChild( pExeDlg, sal_True ) &&
296*cdf0e10cSrcweir                      pExeDlg->IsReallyVisible() &&
297*cdf0e10cSrcweir                      pExeDlg->IsEnabled() && pExeDlg->IsInputEnabled() && !pExeDlg->IsInModalMode() )
298*cdf0e10cSrcweir                 {
299*cdf0e10cSrcweir                     pParent = pExeDlg;
300*cdf0e10cSrcweir                     break;
301*cdf0e10cSrcweir                 }
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir                 pExeDlg = pExeDlg->mpPrevExecuteDlg;
304*cdf0e10cSrcweir             }
305*cdf0e10cSrcweir         }
306*cdf0e10cSrcweir     }
307*cdf0e10cSrcweir     // DIALOG_NO_PARENT: explicitly don't have a parent for this Dialog
308*cdf0e10cSrcweir     else if( pParent == DIALOG_NO_PARENT )
309*cdf0e10cSrcweir         pParent = NULL;
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir /*
312*cdf0e10cSrcweir     // Now, all Dialogs are per default system windows !!!
313*cdf0e10cSrcweir     if ( pParent && !(nSysWinMode & SYSTEMWINDOW_MODE_NOAUTOMODE) )
314*cdf0e10cSrcweir     {
315*cdf0e10cSrcweir         if ( !pParent->mpWindowImpl->mpFrameWindow->IsVisible() )
316*cdf0e10cSrcweir             pParent = NULL;
317*cdf0e10cSrcweir         else
318*cdf0e10cSrcweir         {
319*cdf0e10cSrcweir             if ( pParent->mpWindowImpl->mpFrameWindow->IsDialog() )
320*cdf0e10cSrcweir             {
321*cdf0e10cSrcweir                 Size aOutSize = pParent->mpWindowImpl->mpFrameWindow->GetOutputSizePixel();
322*cdf0e10cSrcweir                 if ( (aOutSize.Width() < 210) ||(aOutSize.Height() < 160) )
323*cdf0e10cSrcweir                     nStyle |= WB_SYSTEMWINDOW;
324*cdf0e10cSrcweir             }
325*cdf0e10cSrcweir         }
326*cdf0e10cSrcweir     }
327*cdf0e10cSrcweir */
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir     if ( !pParent || (nStyle & WB_SYSTEMWINDOW) ||
330*cdf0e10cSrcweir          (pParent->mpWindowImpl->mpFrameData->mbNeedSysWindow && !(nSysWinMode & SYSTEMWINDOW_MODE_NOAUTOMODE)) ||
331*cdf0e10cSrcweir          (nSysWinMode & SYSTEMWINDOW_MODE_DIALOG) )
332*cdf0e10cSrcweir     {
333*cdf0e10cSrcweir         // create window with a small border ?
334*cdf0e10cSrcweir         if ( (nStyle & (WB_BORDER | WB_NOBORDER | WB_MOVEABLE | WB_SIZEABLE | WB_CLOSEABLE)) == WB_BORDER )
335*cdf0e10cSrcweir         {
336*cdf0e10cSrcweir             ImplBorderWindow* pBorderWin  = new ImplBorderWindow( pParent, nStyle, BORDERWINDOW_STYLE_FRAME );
337*cdf0e10cSrcweir             SystemWindow::ImplInit( pBorderWin, nStyle & ~WB_BORDER, NULL );
338*cdf0e10cSrcweir             pBorderWin->mpWindowImpl->mpClientWindow = this;
339*cdf0e10cSrcweir             pBorderWin->GetBorder( mpWindowImpl->mnLeftBorder, mpWindowImpl->mnTopBorder, mpWindowImpl->mnRightBorder, mpWindowImpl->mnBottomBorder );
340*cdf0e10cSrcweir             mpWindowImpl->mpBorderWindow  = pBorderWin;
341*cdf0e10cSrcweir             mpWindowImpl->mpRealParent    = pParent;
342*cdf0e10cSrcweir         }
343*cdf0e10cSrcweir         else
344*cdf0e10cSrcweir         {
345*cdf0e10cSrcweir             mpWindowImpl->mbFrame         = sal_True;
346*cdf0e10cSrcweir             mpWindowImpl->mbOverlapWin    = sal_True;
347*cdf0e10cSrcweir             SystemWindow::ImplInit( pParent, (nStyle & (WB_MOVEABLE | WB_SIZEABLE | WB_ROLLABLE | WB_CLOSEABLE | WB_STANDALONE)) | WB_CLOSEABLE, NULL );
348*cdf0e10cSrcweir             // Now set all style bits
349*cdf0e10cSrcweir             mpWindowImpl->mnStyle = nStyle;
350*cdf0e10cSrcweir         }
351*cdf0e10cSrcweir     }
352*cdf0e10cSrcweir     else
353*cdf0e10cSrcweir     {
354*cdf0e10cSrcweir         ImplBorderWindow* pBorderWin  = new ImplBorderWindow( pParent, nStyle, BORDERWINDOW_STYLE_OVERLAP | BORDERWINDOW_STYLE_BORDER );
355*cdf0e10cSrcweir         SystemWindow::ImplInit( pBorderWin, nStyle & ~WB_BORDER, NULL );
356*cdf0e10cSrcweir         pBorderWin->mpWindowImpl->mpClientWindow = this;
357*cdf0e10cSrcweir         pBorderWin->GetBorder( mpWindowImpl->mnLeftBorder, mpWindowImpl->mnTopBorder, mpWindowImpl->mnRightBorder, mpWindowImpl->mnBottomBorder );
358*cdf0e10cSrcweir         mpWindowImpl->mpBorderWindow  = pBorderWin;
359*cdf0e10cSrcweir         mpWindowImpl->mpRealParent    = pParent;
360*cdf0e10cSrcweir     }
361*cdf0e10cSrcweir 
362*cdf0e10cSrcweir     SetActivateMode( ACTIVATE_MODE_GRABFOCUS );
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir     ImplInitSettings();
365*cdf0e10cSrcweir }
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir // -----------------------------------------------------------------------
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir void Dialog::ImplInitSettings()
370*cdf0e10cSrcweir {
371*cdf0e10cSrcweir     // user override
372*cdf0e10cSrcweir     if ( IsControlBackground() )
373*cdf0e10cSrcweir         SetBackground( GetControlBackground() );
374*cdf0e10cSrcweir     // NWF background
375*cdf0e10cSrcweir     else if( IsNativeControlSupported( CTRL_WINDOW_BACKGROUND, PART_BACKGROUND_DIALOG ) )
376*cdf0e10cSrcweir     {
377*cdf0e10cSrcweir         mpWindowImpl->mnNativeBackground = PART_BACKGROUND_DIALOG;
378*cdf0e10cSrcweir         EnableChildTransparentMode( sal_True );
379*cdf0e10cSrcweir     }
380*cdf0e10cSrcweir     // fallback to settings color
381*cdf0e10cSrcweir     else
382*cdf0e10cSrcweir         SetBackground( GetSettings().GetStyleSettings().GetDialogColor() );
383*cdf0e10cSrcweir 
384*cdf0e10cSrcweir }
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir // -----------------------------------------------------------------------
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir void Dialog::ImplCenterDialog()
389*cdf0e10cSrcweir {
390*cdf0e10cSrcweir     Rectangle   aDeskRect = ImplGetFrameWindow()->GetDesktopRectPixel();
391*cdf0e10cSrcweir     Point       aDeskPos = aDeskRect.TopLeft();
392*cdf0e10cSrcweir     Size        aDeskSize = aDeskRect.GetSize();
393*cdf0e10cSrcweir     Size        aWinSize = GetSizePixel();
394*cdf0e10cSrcweir     Window *pWindow = this;
395*cdf0e10cSrcweir     while ( pWindow->mpWindowImpl->mpBorderWindow )
396*cdf0e10cSrcweir         pWindow = pWindow->mpWindowImpl->mpBorderWindow;
397*cdf0e10cSrcweir     Point       aWinPos( ((aDeskSize.Width() - aWinSize.Width()) / 2) + aDeskPos.X(),
398*cdf0e10cSrcweir                          ((aDeskSize.Height() - aWinSize.Height()) / 2) + aDeskPos.Y() );
399*cdf0e10cSrcweir 
400*cdf0e10cSrcweir     // Pruefen, ob Dialogbox ausserhalb des Desks liegt
401*cdf0e10cSrcweir     if ( (aWinPos.X() + aWinSize.Width()) > (aDeskPos.X()+aDeskSize.Width()) )
402*cdf0e10cSrcweir         aWinPos.X() = aDeskPos.X()+aDeskSize.Width() - aWinSize.Width();
403*cdf0e10cSrcweir     if ( (aWinPos.Y()+aWinSize.Height()) > (aDeskPos.Y()+aDeskSize.Height()) )
404*cdf0e10cSrcweir         aWinPos.Y() = aDeskPos.Y()+aDeskSize.Height() - aWinSize.Height();
405*cdf0e10cSrcweir     // Linke Ecke bevorzugen, da Titelbar oben ist
406*cdf0e10cSrcweir     if ( aWinPos.X() < aDeskPos.X() )
407*cdf0e10cSrcweir         aWinPos.X() = aDeskPos.X();
408*cdf0e10cSrcweir     if ( aWinPos.Y() < aDeskPos.Y() )
409*cdf0e10cSrcweir         aWinPos.Y() = aDeskPos.Y();
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir     //SetPosPixel( aWinPos );
412*cdf0e10cSrcweir     SetPosPixel( pWindow->ScreenToOutputPixel( aWinPos ) );
413*cdf0e10cSrcweir }
414*cdf0e10cSrcweir 
415*cdf0e10cSrcweir // -----------------------------------------------------------------------
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir Dialog::Dialog( WindowType nType ) :
418*cdf0e10cSrcweir     SystemWindow( nType )
419*cdf0e10cSrcweir {
420*cdf0e10cSrcweir     ImplInitDialogData();
421*cdf0e10cSrcweir }
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir // -----------------------------------------------------------------------
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir Dialog::Dialog( Window* pParent, WinBits nStyle ) :
426*cdf0e10cSrcweir     SystemWindow( WINDOW_DIALOG )
427*cdf0e10cSrcweir {
428*cdf0e10cSrcweir     ImplInitDialogData();
429*cdf0e10cSrcweir     ImplInit( pParent, nStyle );
430*cdf0e10cSrcweir }
431*cdf0e10cSrcweir 
432*cdf0e10cSrcweir // -----------------------------------------------------------------------
433*cdf0e10cSrcweir 
434*cdf0e10cSrcweir Dialog::Dialog( Window* pParent, const ResId& rResId ) :
435*cdf0e10cSrcweir     SystemWindow( WINDOW_DIALOG )
436*cdf0e10cSrcweir {
437*cdf0e10cSrcweir     ImplInitDialogData();
438*cdf0e10cSrcweir     rResId.SetRT( RSC_DIALOG );
439*cdf0e10cSrcweir     ImplInit( pParent, ImplInitRes( rResId ) );
440*cdf0e10cSrcweir     ImplLoadRes( rResId );
441*cdf0e10cSrcweir }
442*cdf0e10cSrcweir 
443*cdf0e10cSrcweir // -----------------------------------------------------------------------
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir Dialog::~Dialog()
446*cdf0e10cSrcweir {
447*cdf0e10cSrcweir     delete mpDialogImpl;
448*cdf0e10cSrcweir     mpDialogImpl = NULL;
449*cdf0e10cSrcweir }
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir // -----------------------------------------------------------------------
452*cdf0e10cSrcweir 
453*cdf0e10cSrcweir IMPL_LINK( Dialog, ImplAsyncCloseHdl, void*, EMPTYARG )
454*cdf0e10cSrcweir {
455*cdf0e10cSrcweir     Close();
456*cdf0e10cSrcweir     return 0;
457*cdf0e10cSrcweir }
458*cdf0e10cSrcweir 
459*cdf0e10cSrcweir // -----------------------------------------------------------------------
460*cdf0e10cSrcweir 
461*cdf0e10cSrcweir long Dialog::Notify( NotifyEvent& rNEvt )
462*cdf0e10cSrcweir {
463*cdf0e10cSrcweir     // Zuerst Basisklasse rufen wegen TabSteuerung
464*cdf0e10cSrcweir     long nRet = SystemWindow::Notify( rNEvt );
465*cdf0e10cSrcweir     if ( !nRet )
466*cdf0e10cSrcweir     {
467*cdf0e10cSrcweir         if ( rNEvt.GetType() == EVENT_KEYINPUT )
468*cdf0e10cSrcweir         {
469*cdf0e10cSrcweir             const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
470*cdf0e10cSrcweir             KeyCode         aKeyCode = pKEvt->GetKeyCode();
471*cdf0e10cSrcweir             sal_uInt16          nKeyCode = aKeyCode.GetCode();
472*cdf0e10cSrcweir 
473*cdf0e10cSrcweir             if ( (nKeyCode == KEY_ESCAPE) &&
474*cdf0e10cSrcweir                  ((GetStyle() & WB_CLOSEABLE) || ImplGetCancelButton( this ) || ImplGetOKButton( this )) )
475*cdf0e10cSrcweir             {
476*cdf0e10cSrcweir                 // #i89505# for the benefit of slightly mentally challenged implementations
477*cdf0e10cSrcweir                 // like e.g. SfxModelessDialog which destroy themselves inside Close()
478*cdf0e10cSrcweir                 // post this Close asynchronous so we can leave our key handler before
479*cdf0e10cSrcweir                 // we get destroyed
480*cdf0e10cSrcweir                 PostUserEvent( LINK( this, Dialog, ImplAsyncCloseHdl ), this );
481*cdf0e10cSrcweir                 return sal_True;
482*cdf0e10cSrcweir             }
483*cdf0e10cSrcweir         }
484*cdf0e10cSrcweir         else if ( rNEvt.GetType() == EVENT_GETFOCUS )
485*cdf0e10cSrcweir         {
486*cdf0e10cSrcweir             // make sure the dialog is still modal
487*cdf0e10cSrcweir             // changing focus between application frames may
488*cdf0e10cSrcweir             // have re-enabled input for our parent
489*cdf0e10cSrcweir             if( mbInExecute && mbModalMode )
490*cdf0e10cSrcweir             {
491*cdf0e10cSrcweir                 // do not change modal counter (pSVData->maAppData.mnModalDialog)
492*cdf0e10cSrcweir                 SetModalInputMode( sal_False );
493*cdf0e10cSrcweir                 SetModalInputMode( sal_True );
494*cdf0e10cSrcweir 
495*cdf0e10cSrcweir                 // #93022# def-button might have changed after show
496*cdf0e10cSrcweir                 if( !mnMousePositioned )
497*cdf0e10cSrcweir                 {
498*cdf0e10cSrcweir                     mnMousePositioned = 1;
499*cdf0e10cSrcweir                     ImplMouseAutoPos( this );
500*cdf0e10cSrcweir                 }
501*cdf0e10cSrcweir 
502*cdf0e10cSrcweir             }
503*cdf0e10cSrcweir         }
504*cdf0e10cSrcweir     }
505*cdf0e10cSrcweir 
506*cdf0e10cSrcweir     return nRet;
507*cdf0e10cSrcweir }
508*cdf0e10cSrcweir 
509*cdf0e10cSrcweir // -----------------------------------------------------------------------
510*cdf0e10cSrcweir 
511*cdf0e10cSrcweir void Dialog::StateChanged( StateChangedType nType )
512*cdf0e10cSrcweir {
513*cdf0e10cSrcweir     SystemWindow::StateChanged( nType );
514*cdf0e10cSrcweir 
515*cdf0e10cSrcweir     if ( nType == STATE_CHANGE_INITSHOW )
516*cdf0e10cSrcweir     {
517*cdf0e10cSrcweir         if ( GetSettings().GetStyleSettings().GetAutoMnemonic() )
518*cdf0e10cSrcweir             ImplWindowAutoMnemonic( this );
519*cdf0e10cSrcweir 
520*cdf0e10cSrcweir         //if ( IsDefaultPos() && !mpWindowImpl->mbFrame )
521*cdf0e10cSrcweir         //    ImplCenterDialog();
522*cdf0e10cSrcweir         if ( !HasChildPathFocus() || HasFocus() )
523*cdf0e10cSrcweir             GrabFocusToFirstControl();
524*cdf0e10cSrcweir         if ( !(GetStyle() & WB_CLOSEABLE) )
525*cdf0e10cSrcweir         {
526*cdf0e10cSrcweir             if ( ImplGetCancelButton( this ) || ImplGetOKButton( this ) )
527*cdf0e10cSrcweir             {
528*cdf0e10cSrcweir                 if ( ImplGetBorderWindow() )
529*cdf0e10cSrcweir                     ((ImplBorderWindow*)ImplGetBorderWindow())->SetCloser();
530*cdf0e10cSrcweir             }
531*cdf0e10cSrcweir         }
532*cdf0e10cSrcweir 
533*cdf0e10cSrcweir         ImplMouseAutoPos( this );
534*cdf0e10cSrcweir     }
535*cdf0e10cSrcweir     else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
536*cdf0e10cSrcweir     {
537*cdf0e10cSrcweir         ImplInitSettings();
538*cdf0e10cSrcweir         Invalidate();
539*cdf0e10cSrcweir     }
540*cdf0e10cSrcweir }
541*cdf0e10cSrcweir 
542*cdf0e10cSrcweir // -----------------------------------------------------------------------
543*cdf0e10cSrcweir 
544*cdf0e10cSrcweir void Dialog::DataChanged( const DataChangedEvent& rDCEvt )
545*cdf0e10cSrcweir {
546*cdf0e10cSrcweir     SystemWindow::DataChanged( rDCEvt );
547*cdf0e10cSrcweir 
548*cdf0e10cSrcweir     if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
549*cdf0e10cSrcweir          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
550*cdf0e10cSrcweir     {
551*cdf0e10cSrcweir         ImplInitSettings();
552*cdf0e10cSrcweir         Invalidate();
553*cdf0e10cSrcweir     }
554*cdf0e10cSrcweir }
555*cdf0e10cSrcweir 
556*cdf0e10cSrcweir // -----------------------------------------------------------------------
557*cdf0e10cSrcweir 
558*cdf0e10cSrcweir sal_Bool Dialog::Close()
559*cdf0e10cSrcweir {
560*cdf0e10cSrcweir     ImplDelData aDelData;
561*cdf0e10cSrcweir     ImplAddDel( &aDelData );
562*cdf0e10cSrcweir     ImplCallEventListeners( VCLEVENT_WINDOW_CLOSE );
563*cdf0e10cSrcweir     if ( aDelData.IsDelete() )
564*cdf0e10cSrcweir         return sal_False;
565*cdf0e10cSrcweir     ImplRemoveDel( &aDelData );
566*cdf0e10cSrcweir 
567*cdf0e10cSrcweir     if ( mpWindowImpl->mxWindowPeer.is() && IsCreatedWithToolkit() && !IsInExecute() )
568*cdf0e10cSrcweir         return sal_False;
569*cdf0e10cSrcweir 
570*cdf0e10cSrcweir     mbInClose = sal_True;
571*cdf0e10cSrcweir 
572*cdf0e10cSrcweir     if ( !(GetStyle() & WB_CLOSEABLE) )
573*cdf0e10cSrcweir     {
574*cdf0e10cSrcweir         sal_Bool bRet = sal_True;
575*cdf0e10cSrcweir         ImplAddDel( &aDelData );
576*cdf0e10cSrcweir         PushButton* pButton = ImplGetCancelButton( this );
577*cdf0e10cSrcweir         if ( pButton )
578*cdf0e10cSrcweir             pButton->Click();
579*cdf0e10cSrcweir         else
580*cdf0e10cSrcweir         {
581*cdf0e10cSrcweir             pButton = ImplGetOKButton( this );
582*cdf0e10cSrcweir             if ( pButton )
583*cdf0e10cSrcweir                 pButton->Click();
584*cdf0e10cSrcweir             else
585*cdf0e10cSrcweir                 bRet = sal_False;
586*cdf0e10cSrcweir         }
587*cdf0e10cSrcweir         if ( aDelData.IsDelete() )
588*cdf0e10cSrcweir             return sal_True;
589*cdf0e10cSrcweir         ImplRemoveDel( &aDelData );
590*cdf0e10cSrcweir         return bRet;
591*cdf0e10cSrcweir     }
592*cdf0e10cSrcweir 
593*cdf0e10cSrcweir     if ( IsInExecute() )
594*cdf0e10cSrcweir     {
595*cdf0e10cSrcweir         EndDialog( sal_False );
596*cdf0e10cSrcweir         mbInClose = sal_False;
597*cdf0e10cSrcweir         return sal_True;
598*cdf0e10cSrcweir     }
599*cdf0e10cSrcweir     else
600*cdf0e10cSrcweir     {
601*cdf0e10cSrcweir         mbInClose = sal_False;
602*cdf0e10cSrcweir         return SystemWindow::Close();
603*cdf0e10cSrcweir     }
604*cdf0e10cSrcweir }
605*cdf0e10cSrcweir 
606*cdf0e10cSrcweir // -----------------------------------------------------------------------
607*cdf0e10cSrcweir 
608*cdf0e10cSrcweir sal_Bool Dialog::ImplStartExecuteModal()
609*cdf0e10cSrcweir {
610*cdf0e10cSrcweir     if ( mbInExecute )
611*cdf0e10cSrcweir     {
612*cdf0e10cSrcweir #ifdef DBG_UTIL
613*cdf0e10cSrcweir         ByteString aErrorStr( "Dialog::StartExecuteModal() is called in Dialog::StartExecuteModal(): " );
614*cdf0e10cSrcweir         aErrorStr += ImplGetDialogText( this );
615*cdf0e10cSrcweir         DBG_ERROR( aErrorStr.GetBuffer() );
616*cdf0e10cSrcweir #endif
617*cdf0e10cSrcweir         return sal_False;
618*cdf0e10cSrcweir     }
619*cdf0e10cSrcweir 
620*cdf0e10cSrcweir     if ( Application::IsDialogCancelEnabled() )
621*cdf0e10cSrcweir     {
622*cdf0e10cSrcweir #ifdef DBG_UTIL
623*cdf0e10cSrcweir         ByteString aErrorStr( "Dialog::StartExecuteModal() is called in a none UI application: " );
624*cdf0e10cSrcweir         aErrorStr += ImplGetDialogText( this );
625*cdf0e10cSrcweir         DBG_ERROR( aErrorStr.GetBuffer() );
626*cdf0e10cSrcweir #endif
627*cdf0e10cSrcweir         return sal_False;
628*cdf0e10cSrcweir     }
629*cdf0e10cSrcweir 
630*cdf0e10cSrcweir #ifdef DBG_UTIL
631*cdf0e10cSrcweir     Window* pParent = GetParent();
632*cdf0e10cSrcweir     if ( pParent )
633*cdf0e10cSrcweir     {
634*cdf0e10cSrcweir         pParent = pParent->ImplGetFirstOverlapWindow();
635*cdf0e10cSrcweir         DBG_ASSERT( pParent->IsReallyVisible(),
636*cdf0e10cSrcweir                     "Dialog::StartExecuteModal() - Parent not visible" );
637*cdf0e10cSrcweir         DBG_ASSERT( pParent->IsInputEnabled(),
638*cdf0e10cSrcweir                     "Dialog::StartExecuteModal() - Parent input disabled, use another parent to ensure modality!" );
639*cdf0e10cSrcweir         DBG_ASSERT( ! pParent->IsInModalMode(),
640*cdf0e10cSrcweir                     "Dialog::StartExecuteModal() - Parent already modally disabled, use another parent to ensure modality!" );
641*cdf0e10cSrcweir 
642*cdf0e10cSrcweir     }
643*cdf0e10cSrcweir #endif
644*cdf0e10cSrcweir 
645*cdf0e10cSrcweir     ImplSVData* pSVData = ImplGetSVData();
646*cdf0e10cSrcweir 
647*cdf0e10cSrcweir     // Dialoge, die sich in Execute befinden, miteinander verketten
648*cdf0e10cSrcweir     mpPrevExecuteDlg = pSVData->maWinData.mpLastExecuteDlg;
649*cdf0e10cSrcweir     pSVData->maWinData.mpLastExecuteDlg = this;
650*cdf0e10cSrcweir 
651*cdf0e10cSrcweir     // Capture beenden, damit der Dialog bedient werden kann
652*cdf0e10cSrcweir     if ( pSVData->maWinData.mpTrackWin )
653*cdf0e10cSrcweir         pSVData->maWinData.mpTrackWin->EndTracking( ENDTRACK_CANCEL );
654*cdf0e10cSrcweir     if ( pSVData->maWinData.mpCaptureWin )
655*cdf0e10cSrcweir         pSVData->maWinData.mpCaptureWin->ReleaseMouse();
656*cdf0e10cSrcweir     EnableInput( sal_True, sal_True );
657*cdf0e10cSrcweir 
658*cdf0e10cSrcweir     if ( GetParent() )
659*cdf0e10cSrcweir     {
660*cdf0e10cSrcweir         NotifyEvent aNEvt( EVENT_EXECUTEDIALOG, this );
661*cdf0e10cSrcweir         GetParent()->Notify( aNEvt );
662*cdf0e10cSrcweir     }
663*cdf0e10cSrcweir     mbInExecute = sal_True;
664*cdf0e10cSrcweir     SetModalInputMode( sal_True );
665*cdf0e10cSrcweir     mbOldSaveBack = IsSaveBackgroundEnabled();
666*cdf0e10cSrcweir     EnableSaveBackground();
667*cdf0e10cSrcweir 
668*cdf0e10cSrcweir     // FIXME: no layouting, workaround some clipping issues
669*cdf0e10cSrcweir     ImplAdjustNWFSizes();
670*cdf0e10cSrcweir 
671*cdf0e10cSrcweir     Show();
672*cdf0e10cSrcweir 
673*cdf0e10cSrcweir     pSVData->maAppData.mnModalMode++;
674*cdf0e10cSrcweir     return sal_True;
675*cdf0e10cSrcweir }
676*cdf0e10cSrcweir 
677*cdf0e10cSrcweir // -----------------------------------------------------------------------
678*cdf0e10cSrcweir 
679*cdf0e10cSrcweir void Dialog::ImplEndExecuteModal()
680*cdf0e10cSrcweir {
681*cdf0e10cSrcweir     ImplSVData* pSVData = ImplGetSVData();
682*cdf0e10cSrcweir     pSVData->maAppData.mnModalMode--;
683*cdf0e10cSrcweir }
684*cdf0e10cSrcweir 
685*cdf0e10cSrcweir // -----------------------------------------------------------------------
686*cdf0e10cSrcweir 
687*cdf0e10cSrcweir short Dialog::Execute()
688*cdf0e10cSrcweir {
689*cdf0e10cSrcweir     if ( !ImplStartExecuteModal() )
690*cdf0e10cSrcweir         return 0;
691*cdf0e10cSrcweir 
692*cdf0e10cSrcweir     ImplDelData aDelData;
693*cdf0e10cSrcweir     ImplAddDel( &aDelData );
694*cdf0e10cSrcweir 
695*cdf0e10cSrcweir #ifdef DBG_UTIL
696*cdf0e10cSrcweir     ImplDelData aParentDelData;
697*cdf0e10cSrcweir     Window* pDialogParent = mpDialogParent;
698*cdf0e10cSrcweir     if( pDialogParent )
699*cdf0e10cSrcweir         pDialogParent->ImplAddDel( &aParentDelData );
700*cdf0e10cSrcweir #endif
701*cdf0e10cSrcweir 
702*cdf0e10cSrcweir     // Yield util EndDialog is called or dialog gets destroyed
703*cdf0e10cSrcweir     // (the latter should not happen, but better safe than sorry
704*cdf0e10cSrcweir     while ( !aDelData.IsDelete() && mbInExecute )
705*cdf0e10cSrcweir         Application::Yield();
706*cdf0e10cSrcweir 
707*cdf0e10cSrcweir     ImplEndExecuteModal();
708*cdf0e10cSrcweir 
709*cdf0e10cSrcweir #ifdef DBG_UTIL
710*cdf0e10cSrcweir     if( pDialogParent  )
711*cdf0e10cSrcweir     {
712*cdf0e10cSrcweir         if( ! aParentDelData.IsDelete() )
713*cdf0e10cSrcweir             pDialogParent->ImplRemoveDel( &aParentDelData );
714*cdf0e10cSrcweir         else
715*cdf0e10cSrcweir             DBG_ERROR( "Dialog::Execute() - Parent of dialog destroyed in Execute()" );
716*cdf0e10cSrcweir     }
717*cdf0e10cSrcweir #endif
718*cdf0e10cSrcweir     if ( !aDelData.IsDelete() )
719*cdf0e10cSrcweir         ImplRemoveDel( &aDelData );
720*cdf0e10cSrcweir #ifdef DBG_UTIL
721*cdf0e10cSrcweir     else
722*cdf0e10cSrcweir     {
723*cdf0e10cSrcweir         DBG_ERROR( "Dialog::Execute() - Dialog destroyed in Execute()" );
724*cdf0e10cSrcweir     }
725*cdf0e10cSrcweir #endif
726*cdf0e10cSrcweir 
727*cdf0e10cSrcweir     long nRet = mpDialogImpl->mnResult;
728*cdf0e10cSrcweir     mpDialogImpl->mnResult = -1;
729*cdf0e10cSrcweir     return (short)nRet;
730*cdf0e10cSrcweir }
731*cdf0e10cSrcweir 
732*cdf0e10cSrcweir // -----------------------------------------------------------------------
733*cdf0e10cSrcweir 
734*cdf0e10cSrcweir // virtual
735*cdf0e10cSrcweir void Dialog::StartExecuteModal( const Link& rEndDialogHdl )
736*cdf0e10cSrcweir {
737*cdf0e10cSrcweir     if ( !ImplStartExecuteModal() )
738*cdf0e10cSrcweir         return;
739*cdf0e10cSrcweir 
740*cdf0e10cSrcweir     mpDialogImpl->maEndDialogHdl = rEndDialogHdl;
741*cdf0e10cSrcweir     mpDialogImpl->mbStartedModal = true;
742*cdf0e10cSrcweir }
743*cdf0e10cSrcweir 
744*cdf0e10cSrcweir // -----------------------------------------------------------------------
745*cdf0e10cSrcweir 
746*cdf0e10cSrcweir sal_Bool Dialog::IsStartedModal() const
747*cdf0e10cSrcweir {
748*cdf0e10cSrcweir     return mpDialogImpl->mbStartedModal;
749*cdf0e10cSrcweir }
750*cdf0e10cSrcweir 
751*cdf0e10cSrcweir // -----------------------------------------------------------------------
752*cdf0e10cSrcweir 
753*cdf0e10cSrcweir void Dialog::EndDialog( long nResult )
754*cdf0e10cSrcweir {
755*cdf0e10cSrcweir     if ( mbInExecute )
756*cdf0e10cSrcweir     {
757*cdf0e10cSrcweir         SetModalInputMode( sal_False );
758*cdf0e10cSrcweir 
759*cdf0e10cSrcweir         // Dialog aus der Kette der Dialoge die in Execute stehen entfernen
760*cdf0e10cSrcweir         ImplSVData* pSVData = ImplGetSVData();
761*cdf0e10cSrcweir         Dialog* pExeDlg = pSVData->maWinData.mpLastExecuteDlg;
762*cdf0e10cSrcweir         while ( pExeDlg )
763*cdf0e10cSrcweir         {
764*cdf0e10cSrcweir             if ( pExeDlg == this )
765*cdf0e10cSrcweir             {
766*cdf0e10cSrcweir                 pSVData->maWinData.mpLastExecuteDlg = mpPrevExecuteDlg;
767*cdf0e10cSrcweir                 break;
768*cdf0e10cSrcweir             }
769*cdf0e10cSrcweir             pExeDlg = pExeDlg->mpPrevExecuteDlg;
770*cdf0e10cSrcweir         }
771*cdf0e10cSrcweir         // set focus to previous modal dialogue if it is modal for
772*cdf0e10cSrcweir         // the same frame parent (or NULL)
773*cdf0e10cSrcweir         if( mpPrevExecuteDlg )
774*cdf0e10cSrcweir         {
775*cdf0e10cSrcweir             Window* pFrameParent = ImplGetFrameWindow()->ImplGetParent();
776*cdf0e10cSrcweir             Window* pPrevFrameParent = mpPrevExecuteDlg->ImplGetFrameWindow()->ImplGetParent();
777*cdf0e10cSrcweir             if( ( !pFrameParent && !pPrevFrameParent ) ||
778*cdf0e10cSrcweir                 ( pFrameParent && pPrevFrameParent && pFrameParent->ImplGetFrame() == pPrevFrameParent->ImplGetFrame() )
779*cdf0e10cSrcweir                 )
780*cdf0e10cSrcweir             {
781*cdf0e10cSrcweir                 mpPrevExecuteDlg->GrabFocus();
782*cdf0e10cSrcweir             }
783*cdf0e10cSrcweir         }
784*cdf0e10cSrcweir         mpPrevExecuteDlg = NULL;
785*cdf0e10cSrcweir 
786*cdf0e10cSrcweir         Hide();
787*cdf0e10cSrcweir         EnableSaveBackground( mbOldSaveBack );
788*cdf0e10cSrcweir         if ( GetParent() )
789*cdf0e10cSrcweir         {
790*cdf0e10cSrcweir             NotifyEvent aNEvt( EVENT_ENDEXECUTEDIALOG, this );
791*cdf0e10cSrcweir             GetParent()->Notify( aNEvt );
792*cdf0e10cSrcweir         }
793*cdf0e10cSrcweir 
794*cdf0e10cSrcweir         mpDialogImpl->mnResult = nResult;
795*cdf0e10cSrcweir 
796*cdf0e10cSrcweir         if ( mpDialogImpl->mbStartedModal )
797*cdf0e10cSrcweir         {
798*cdf0e10cSrcweir             ImplEndExecuteModal();
799*cdf0e10cSrcweir             mpDialogImpl->maEndDialogHdl.Call( this );
800*cdf0e10cSrcweir 
801*cdf0e10cSrcweir             mpDialogImpl->maEndDialogHdl = Link();
802*cdf0e10cSrcweir             mpDialogImpl->mbStartedModal = false;
803*cdf0e10cSrcweir             mpDialogImpl->mnResult = -1;
804*cdf0e10cSrcweir         }
805*cdf0e10cSrcweir         mbInExecute = sal_False;
806*cdf0e10cSrcweir     }
807*cdf0e10cSrcweir }
808*cdf0e10cSrcweir 
809*cdf0e10cSrcweir // -----------------------------------------------------------------------
810*cdf0e10cSrcweir 
811*cdf0e10cSrcweir long Dialog::GetResult() const
812*cdf0e10cSrcweir {
813*cdf0e10cSrcweir     return mpDialogImpl->mnResult;
814*cdf0e10cSrcweir }
815*cdf0e10cSrcweir 
816*cdf0e10cSrcweir // -----------------------------------------------------------------------
817*cdf0e10cSrcweir 
818*cdf0e10cSrcweir void Dialog::EndAllDialogs( Window* pParent )
819*cdf0e10cSrcweir {
820*cdf0e10cSrcweir    ImplSVData*  pSVData = ImplGetSVData();
821*cdf0e10cSrcweir    Dialog*      pTempModDialog;
822*cdf0e10cSrcweir    Dialog*      pModDialog = pSVData->maWinData.mpLastExecuteDlg;
823*cdf0e10cSrcweir    while ( pModDialog )
824*cdf0e10cSrcweir    {
825*cdf0e10cSrcweir      pTempModDialog = pModDialog->mpPrevExecuteDlg;
826*cdf0e10cSrcweir      if( !pParent || ( pParent && pParent->IsWindowOrChild( pModDialog, sal_True ) ) )
827*cdf0e10cSrcweir      {
828*cdf0e10cSrcweir         pModDialog->EndDialog( sal_False );
829*cdf0e10cSrcweir         pModDialog->PostUserEvent( Link() );
830*cdf0e10cSrcweir      }
831*cdf0e10cSrcweir      pModDialog = pTempModDialog;
832*cdf0e10cSrcweir    }
833*cdf0e10cSrcweir }
834*cdf0e10cSrcweir 
835*cdf0e10cSrcweir // -----------------------------------------------------------------------
836*cdf0e10cSrcweir 
837*cdf0e10cSrcweir void Dialog::SetModalInputMode( sal_Bool bModal )
838*cdf0e10cSrcweir {
839*cdf0e10cSrcweir     if ( bModal == mbModalMode )
840*cdf0e10cSrcweir         return;
841*cdf0e10cSrcweir 
842*cdf0e10cSrcweir     ImplSVData* pSVData = ImplGetSVData();
843*cdf0e10cSrcweir     mbModalMode = bModal;
844*cdf0e10cSrcweir     if ( bModal )
845*cdf0e10cSrcweir     {
846*cdf0e10cSrcweir         pSVData->maAppData.mnModalDialog++;
847*cdf0e10cSrcweir 
848*cdf0e10cSrcweir         // Diable the prev Modal Dialog, because our dialog must close at first,
849*cdf0e10cSrcweir         // before the other dialog can be closed (because the other dialog
850*cdf0e10cSrcweir         // is on stack since our dialog returns)
851*cdf0e10cSrcweir         if ( mpPrevExecuteDlg && !mpPrevExecuteDlg->IsWindowOrChild( this, sal_True ) )
852*cdf0e10cSrcweir             mpPrevExecuteDlg->EnableInput( sal_False, sal_True, sal_True, this );
853*cdf0e10cSrcweir 
854*cdf0e10cSrcweir         // determine next overlap dialog parent
855*cdf0e10cSrcweir         Window* pParent = GetParent();
856*cdf0e10cSrcweir         if ( pParent )
857*cdf0e10cSrcweir         {
858*cdf0e10cSrcweir             // #103716# dialogs should always be modal to the whole frame window
859*cdf0e10cSrcweir             // #115933# disable the whole frame hierarchie, useful if our parent
860*cdf0e10cSrcweir             // is a modeless dialog
861*cdf0e10cSrcweir             mpDialogParent = pParent->mpWindowImpl->mpFrameWindow;
862*cdf0e10cSrcweir             mpDialogParent->ImplIncModalCount();
863*cdf0e10cSrcweir         }
864*cdf0e10cSrcweir 
865*cdf0e10cSrcweir     }
866*cdf0e10cSrcweir     else
867*cdf0e10cSrcweir     {
868*cdf0e10cSrcweir         pSVData->maAppData.mnModalDialog--;
869*cdf0e10cSrcweir 
870*cdf0e10cSrcweir         if ( mpDialogParent )
871*cdf0e10cSrcweir         {
872*cdf0e10cSrcweir             // #115933# re-enable the whole frame hierarchie again (see above)
873*cdf0e10cSrcweir             // note that code in getfocus assures that we do not accidentally enable
874*cdf0e10cSrcweir             // windows that were disabled before
875*cdf0e10cSrcweir             mpDialogParent->ImplDecModalCount();
876*cdf0e10cSrcweir         }
877*cdf0e10cSrcweir 
878*cdf0e10cSrcweir         // Enable the prev Modal Dialog
879*cdf0e10cSrcweir         if ( mpPrevExecuteDlg && !mpPrevExecuteDlg->IsWindowOrChild( this, sal_True ) )
880*cdf0e10cSrcweir         {
881*cdf0e10cSrcweir             mpPrevExecuteDlg->EnableInput( sal_True, sal_True, sal_True, this );
882*cdf0e10cSrcweir             // ensure continued modality of prev dialog
883*cdf0e10cSrcweir             // do not change modality counter
884*cdf0e10cSrcweir             mpPrevExecuteDlg->SetModalInputMode( sal_False );
885*cdf0e10cSrcweir             mpPrevExecuteDlg->SetModalInputMode( sal_True );
886*cdf0e10cSrcweir         }
887*cdf0e10cSrcweir     }
888*cdf0e10cSrcweir }
889*cdf0e10cSrcweir 
890*cdf0e10cSrcweir // -----------------------------------------------------------------------
891*cdf0e10cSrcweir 
892*cdf0e10cSrcweir void Dialog::SetModalInputMode( sal_Bool bModal, sal_Bool bSubModalDialogs )
893*cdf0e10cSrcweir {
894*cdf0e10cSrcweir     if ( bSubModalDialogs )
895*cdf0e10cSrcweir     {
896*cdf0e10cSrcweir         Window* pOverlap = ImplGetFirstOverlapWindow();
897*cdf0e10cSrcweir         pOverlap = pOverlap->mpWindowImpl->mpFirstOverlap;
898*cdf0e10cSrcweir         while ( pOverlap )
899*cdf0e10cSrcweir         {
900*cdf0e10cSrcweir             if ( pOverlap->IsDialog() )
901*cdf0e10cSrcweir                 ((Dialog*)pOverlap)->SetModalInputMode( bModal, sal_True );
902*cdf0e10cSrcweir             pOverlap = pOverlap->mpWindowImpl->mpNext;
903*cdf0e10cSrcweir         }
904*cdf0e10cSrcweir     }
905*cdf0e10cSrcweir 
906*cdf0e10cSrcweir     SetModalInputMode( bModal );
907*cdf0e10cSrcweir }
908*cdf0e10cSrcweir 
909*cdf0e10cSrcweir // -----------------------------------------------------------------------
910*cdf0e10cSrcweir 
911*cdf0e10cSrcweir void Dialog::GrabFocusToFirstControl()
912*cdf0e10cSrcweir {
913*cdf0e10cSrcweir     Window* pFocusControl;
914*cdf0e10cSrcweir 
915*cdf0e10cSrcweir     // Wenn Dialog den Focus hat, versuchen wr trotzdem
916*cdf0e10cSrcweir     // ein Focus-Control zu finden
917*cdf0e10cSrcweir     if ( HasFocus() )
918*cdf0e10cSrcweir         pFocusControl = NULL;
919*cdf0e10cSrcweir     else
920*cdf0e10cSrcweir     {
921*cdf0e10cSrcweir         // Wenn schon ein Child-Fenster mal den Focus hatte,
922*cdf0e10cSrcweir         // dann dieses bevorzugen
923*cdf0e10cSrcweir         pFocusControl = ImplGetFirstOverlapWindow()->mpWindowImpl->mpLastFocusWindow;
924*cdf0e10cSrcweir         // Control aus der Dialog-Steuerung suchen
925*cdf0e10cSrcweir         if ( pFocusControl )
926*cdf0e10cSrcweir             pFocusControl = ImplFindDlgCtrlWindow( pFocusControl );
927*cdf0e10cSrcweir     }
928*cdf0e10cSrcweir     // Kein Control hatte vorher den Focus, oder das Control
929*cdf0e10cSrcweir     // befindet sich nicht in der Tab-Steuerung, dann das erste
930*cdf0e10cSrcweir     // Control in der TabSteuerung den Focus geben
931*cdf0e10cSrcweir     if ( !pFocusControl ||
932*cdf0e10cSrcweir          !(pFocusControl->GetStyle() & WB_TABSTOP) ||
933*cdf0e10cSrcweir          !pFocusControl->IsVisible() ||
934*cdf0e10cSrcweir          !pFocusControl->IsEnabled() || !pFocusControl->IsInputEnabled() )
935*cdf0e10cSrcweir     {
936*cdf0e10cSrcweir         sal_uInt16 n = 0;
937*cdf0e10cSrcweir         pFocusControl = ImplGetDlgWindow( n, DLGWINDOW_FIRST );
938*cdf0e10cSrcweir     }
939*cdf0e10cSrcweir     if ( pFocusControl )
940*cdf0e10cSrcweir         pFocusControl->ImplControlFocus( GETFOCUS_INIT );
941*cdf0e10cSrcweir }
942*cdf0e10cSrcweir 
943*cdf0e10cSrcweir void Dialog::GetDrawWindowBorder( sal_Int32& rLeftBorder, sal_Int32& rTopBorder, sal_Int32& rRightBorder, sal_Int32& rBottomBorder ) const
944*cdf0e10cSrcweir {
945*cdf0e10cSrcweir     ImplBorderWindow aImplWin( (Window*)this, WB_BORDER|WB_STDWORK, BORDERWINDOW_STYLE_OVERLAP );
946*cdf0e10cSrcweir //  aImplWin.SetText( GetText() );
947*cdf0e10cSrcweir //  aImplWin.SetPosSizePixel( aPos.X(), aPos.Y(), aSize.Width(), aSize.Height() );
948*cdf0e10cSrcweir //  aImplWin.SetDisplayActive( sal_True );
949*cdf0e10cSrcweir //  aImplWin.InitView();
950*cdf0e10cSrcweir     aImplWin.GetBorder( rLeftBorder, rTopBorder, rRightBorder, rBottomBorder );
951*cdf0e10cSrcweir }
952*cdf0e10cSrcweir 
953*cdf0e10cSrcweir 
954*cdf0e10cSrcweir void Dialog::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong )
955*cdf0e10cSrcweir {
956*cdf0e10cSrcweir     Point aPos = pDev->LogicToPixel( rPos );
957*cdf0e10cSrcweir     Size aSize = pDev->LogicToPixel( rSize );
958*cdf0e10cSrcweir 
959*cdf0e10cSrcweir     Wallpaper aWallpaper = GetBackground();
960*cdf0e10cSrcweir     if ( !aWallpaper.IsBitmap() )
961*cdf0e10cSrcweir         ImplInitSettings();
962*cdf0e10cSrcweir 
963*cdf0e10cSrcweir     pDev->Push();
964*cdf0e10cSrcweir     pDev->SetMapMode();
965*cdf0e10cSrcweir     pDev->SetLineColor();
966*cdf0e10cSrcweir 
967*cdf0e10cSrcweir     if ( aWallpaper.IsBitmap() )
968*cdf0e10cSrcweir         pDev->DrawBitmapEx( aPos, aSize, aWallpaper.GetBitmap() );
969*cdf0e10cSrcweir     else
970*cdf0e10cSrcweir     {
971*cdf0e10cSrcweir         pDev->SetFillColor( aWallpaper.GetColor() );
972*cdf0e10cSrcweir         pDev->DrawRect( Rectangle( aPos, aSize ) );
973*cdf0e10cSrcweir     }
974*cdf0e10cSrcweir 
975*cdf0e10cSrcweir     if (!( GetStyle() & WB_NOBORDER ))
976*cdf0e10cSrcweir 	{
977*cdf0e10cSrcweir 		ImplBorderWindow aImplWin( this, WB_BORDER|WB_STDWORK, BORDERWINDOW_STYLE_OVERLAP );
978*cdf0e10cSrcweir 		aImplWin.SetText( GetText() );
979*cdf0e10cSrcweir 		aImplWin.SetPosSizePixel( aPos.X(), aPos.Y(), aSize.Width(), aSize.Height() );
980*cdf0e10cSrcweir 		aImplWin.SetDisplayActive( sal_True );
981*cdf0e10cSrcweir 		aImplWin.InitView();
982*cdf0e10cSrcweir 
983*cdf0e10cSrcweir 		aImplWin.Draw( Rectangle( aPos, aSize ), pDev, aPos );
984*cdf0e10cSrcweir 	}
985*cdf0e10cSrcweir 
986*cdf0e10cSrcweir     pDev->Pop();
987*cdf0e10cSrcweir }
988*cdf0e10cSrcweir 
989*cdf0e10cSrcweir 
990*cdf0e10cSrcweir // =======================================================================
991*cdf0e10cSrcweir 
992*cdf0e10cSrcweir ModelessDialog::ModelessDialog( Window* pParent, WinBits nStyle ) :
993*cdf0e10cSrcweir     Dialog( WINDOW_MODELESSDIALOG )
994*cdf0e10cSrcweir {
995*cdf0e10cSrcweir     ImplInit( pParent, nStyle );
996*cdf0e10cSrcweir }
997*cdf0e10cSrcweir 
998*cdf0e10cSrcweir // -----------------------------------------------------------------------
999*cdf0e10cSrcweir 
1000*cdf0e10cSrcweir ModelessDialog::ModelessDialog( Window* pParent, const ResId& rResId ) :
1001*cdf0e10cSrcweir     Dialog( WINDOW_MODELESSDIALOG )
1002*cdf0e10cSrcweir {
1003*cdf0e10cSrcweir     rResId.SetRT( RSC_MODELESSDIALOG );
1004*cdf0e10cSrcweir     WinBits nStyle = ImplInitRes( rResId );
1005*cdf0e10cSrcweir     ImplInit( pParent, nStyle );
1006*cdf0e10cSrcweir     ImplLoadRes( rResId );
1007*cdf0e10cSrcweir 
1008*cdf0e10cSrcweir     if ( !(nStyle & WB_HIDE) )
1009*cdf0e10cSrcweir         Show();
1010*cdf0e10cSrcweir }
1011*cdf0e10cSrcweir 
1012*cdf0e10cSrcweir // =======================================================================
1013*cdf0e10cSrcweir 
1014*cdf0e10cSrcweir ModalDialog::ModalDialog( Window* pParent, WinBits nStyle ) :
1015*cdf0e10cSrcweir     Dialog( WINDOW_MODALDIALOG )
1016*cdf0e10cSrcweir {
1017*cdf0e10cSrcweir     ImplInit( pParent, nStyle );
1018*cdf0e10cSrcweir }
1019*cdf0e10cSrcweir 
1020*cdf0e10cSrcweir // -----------------------------------------------------------------------
1021*cdf0e10cSrcweir 
1022*cdf0e10cSrcweir ModalDialog::ModalDialog( Window* pParent, const ResId& rResId ) :
1023*cdf0e10cSrcweir     Dialog( WINDOW_MODALDIALOG )
1024*cdf0e10cSrcweir {
1025*cdf0e10cSrcweir     rResId.SetRT( RSC_MODALDIALOG );
1026*cdf0e10cSrcweir     ImplInit( pParent, ImplInitRes( rResId ) );
1027*cdf0e10cSrcweir     ImplLoadRes( rResId );
1028*cdf0e10cSrcweir }
1029