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