Files
libreoffice/vcl/source/window/dialog.cxx

1047 lines
32 KiB
C++
Raw Normal View History

2000-09-18 16:07:07 +00:00
/*************************************************************************
*
* OpenOffice.org - a multi-platform office productivity suite
2000-09-18 16:07:07 +00:00
*
* $RCSfile: dialog.cxx,v $
2000-09-18 16:07:07 +00:00
*
* $Revision: 1.42 $
2000-09-18 16:07:07 +00:00
*
* last change: $Author: ihi $ $Date: 2007-11-26 15:13:56 $
2000-09-18 16:07:07 +00:00
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
2000-09-18 16:07:07 +00:00
*
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2005 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
2000-09-18 16:07:07 +00:00
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
2000-09-18 16:07:07 +00:00
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
2000-09-18 16:07:07 +00:00
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
2000-09-18 16:07:07 +00:00
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_vcl.hxx"
2000-09-18 16:07:07 +00:00
#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif
#ifndef _SV_RC_H
#include <tools/rc.h>
2000-09-18 16:07:07 +00:00
#endif
#ifndef _SV_SVDATA_HXX
#include <vcl/svdata.hxx>
2000-09-18 16:07:07 +00:00
#endif
#ifndef _SV_SVAPP_HXX
#include <vcl/svapp.hxx>
2000-09-18 16:07:07 +00:00
#endif
#ifndef _SV_WINDOW_H
#include <vcl/window.h>
2000-09-18 16:07:07 +00:00
#endif
#ifndef _SV_EVENT_HXX
#include <vcl/event.hxx>
2000-09-18 16:07:07 +00:00
#endif
#ifndef _SV_BRDWIN_HXX
#include <vcl/brdwin.hxx>
2000-09-18 16:07:07 +00:00
#endif
#ifndef _SV_WRKWIN_HXX
#include <vcl/wrkwin.hxx>
2000-09-18 16:07:07 +00:00
#endif
#ifndef _SV_BUTTON_HXX
#include <vcl/button.hxx>
2000-09-18 16:07:07 +00:00
#endif
#ifndef _SV_MNEMONIC_HXX
#include <vcl/mnemonic.hxx>
2000-09-18 16:07:07 +00:00
#endif
#ifndef _SV_DIALOG_HXX
#include <vcl/dialog.hxx>
2000-09-18 16:07:07 +00:00
#endif
2001-02-14 17:11:46 +00:00
#ifndef _SV_DECOVIEW_HXX
#include <vcl/decoview.hxx>
2001-02-14 17:11:46 +00:00
#endif
2000-09-18 16:07:07 +00:00
#ifdef DBG_UTIL
#ifndef _SV_MSGBOX_HXX
#include <vcl/msgbox.hxx>
2000-09-18 16:07:07 +00:00
#endif
#endif
#include <vcl/unowrap.hxx>
2000-09-18 16:07:07 +00:00
2000-09-18 16:07:07 +00:00
// =======================================================================
#ifdef DBG_UTIL
static ByteString ImplGetDialogText( Dialog* pDialog )
{
ByteString aErrorStr( pDialog->GetText(), RTL_TEXTENCODING_UTF8 );
if ( (pDialog->GetType() == WINDOW_MESSBOX) ||
(pDialog->GetType() == WINDOW_INFOBOX) ||
(pDialog->GetType() == WINDOW_WARNINGBOX) ||
(pDialog->GetType() == WINDOW_ERRORBOX) ||
(pDialog->GetType() == WINDOW_QUERYBOX) )
{
aErrorStr += ", ";
aErrorStr += ByteString( ((MessBox*)pDialog)->GetMessText(), RTL_TEXTENCODING_UTF8 );
}
return aErrorStr;
}
#endif
// =======================================================================
static BOOL ImplIsMnemonicCtrl( Window* pWindow )
{
if( ! pWindow->GetSettings().GetStyleSettings().GetAutoMnemonic() )
return FALSE;
2000-09-18 16:07:07 +00:00
if ( (pWindow->GetType() == WINDOW_RADIOBUTTON) ||
(pWindow->GetType() == WINDOW_CHECKBOX) ||
(pWindow->GetType() == WINDOW_TRISTATEBOX) ||
(pWindow->GetType() == WINDOW_PUSHBUTTON) )
return TRUE;
if ( pWindow->GetType() == WINDOW_FIXEDTEXT )
{
if ( pWindow->GetStyle() & (WB_INFO | WB_NOLABEL) )
return FALSE;
Window* pNextWindow = pWindow->GetWindow( WINDOW_NEXT );
if ( !pNextWindow )
return FALSE;
pNextWindow = pNextWindow->GetWindow( WINDOW_CLIENT );
if ( !(pNextWindow->GetStyle() & WB_TABSTOP) ||
(pNextWindow->GetType() == WINDOW_FIXEDTEXT) ||
(pNextWindow->GetType() == WINDOW_GROUPBOX) ||
(pNextWindow->GetType() == WINDOW_RADIOBUTTON) ||
(pNextWindow->GetType() == WINDOW_CHECKBOX) ||
(pNextWindow->GetType() == WINDOW_TRISTATEBOX) ||
(pNextWindow->GetType() == WINDOW_PUSHBUTTON) )
return FALSE;
return TRUE;
}
return FALSE;
}
// -----------------------------------------------------------------------
void ImplWindowAutoMnemonic( Window* pWindow )
{
2002-05-16 10:22:20 +00:00
MnemonicGenerator aMnemonicGenerator;
2000-09-18 16:07:07 +00:00
Window* pGetChild;
Window* pChild;
// Die schon vergebenen Mnemonics registieren
pGetChild = pWindow->GetWindow( WINDOW_FIRSTCHILD );
while ( pGetChild )
{
pChild = pGetChild->ImplGetWindow();
aMnemonicGenerator.RegisterMnemonic( pChild->GetText() );
pGetChild = pGetChild->GetWindow( WINDOW_NEXT );
}
// Bei TabPages auch noch die Controls vom Dialog beruecksichtigen
if ( pWindow->GetType() == WINDOW_TABPAGE )
{
Window* pParent = pWindow->GetParent();
if ( pParent->GetType() == WINDOW_TABCONTROL )
pParent = pParent->GetParent();
if ( (pParent->GetStyle() & (WB_DIALOGCONTROL | WB_NODIALOGCONTROL)) == WB_DIALOGCONTROL )
{
pGetChild = pParent->GetWindow( WINDOW_FIRSTCHILD );
2000-09-18 16:07:07 +00:00
while ( pGetChild )
{
pChild = pGetChild->ImplGetWindow();
aMnemonicGenerator.RegisterMnemonic( pChild->GetText() );
pGetChild = pGetChild->GetWindow( WINDOW_NEXT );
}
}
}
// Die Mnemonics an die Controls vergeben, die noch keinen haben
pGetChild = pWindow->GetWindow( WINDOW_FIRSTCHILD );
while ( pGetChild )
{
pChild = pGetChild->ImplGetWindow();
if ( ImplIsMnemonicCtrl( pChild ) )
{
XubString aText = pChild->GetText();
if ( aMnemonicGenerator.CreateMnemonic( aText ) )
pChild->SetText( aText );
}
pGetChild = pGetChild->GetWindow( WINDOW_NEXT );
}
}
// =======================================================================
static PushButton* ImplGetDefaultButton( Dialog* pDialog )
{
Window* pChild = pDialog->GetWindow( WINDOW_FIRSTCHILD );
while ( pChild )
{
if ( pChild->ImplIsPushButton() )
{
PushButton* pPushButton = (PushButton*)pChild;
if ( pPushButton->ImplIsDefButton() )
return pPushButton;
}
pChild = pChild->GetWindow( WINDOW_NEXT );
}
return NULL;
}
// -----------------------------------------------------------------------
static PushButton* ImplGetOKButton( Dialog* pDialog )
{
Window* pChild = pDialog->GetWindow( WINDOW_FIRSTCHILD );
while ( pChild )
{
if ( pChild->GetType() == WINDOW_OKBUTTON )
return (PushButton*)pChild;
pChild = pChild->GetWindow( WINDOW_NEXT );
}
return NULL;
}
// -----------------------------------------------------------------------
static PushButton* ImplGetCancelButton( Dialog* pDialog )
{
Window* pChild = pDialog->GetWindow( WINDOW_FIRSTCHILD );
while ( pChild )
{
if ( pChild->GetType() == WINDOW_CANCELBUTTON )
return (PushButton*)pChild;
pChild = pChild->GetWindow( WINDOW_NEXT );
}
return NULL;
}
// -----------------------------------------------------------------------
static void ImplMouseAutoPos( Dialog* pDialog )
{
ULONG nMouseOptions = pDialog->GetSettings().GetMouseSettings().GetOptions();
if ( nMouseOptions & MOUSE_OPTION_AUTOCENTERPOS )
{
Size aSize = pDialog->GetOutputSizePixel();
pDialog->SetPointerPosPixel( Point( aSize.Width()/2, aSize.Height()/2 ) );
}
else if ( nMouseOptions & MOUSE_OPTION_AUTODEFBTNPOS )
{
Window* pWindow = ImplGetDefaultButton( pDialog );
if ( !pWindow )
pWindow = ImplGetOKButton( pDialog );
if ( !pWindow )
pWindow = ImplGetCancelButton( pDialog );
if ( !pWindow )
pWindow = pDialog;
Size aSize = pWindow->GetOutputSizePixel();
pWindow->SetPointerPosPixel( Point( aSize.Width()/2, aSize.Height()/2 ) );
}
}
// =======================================================================
struct DialogImpl
{
long mnResult;
bool mbStartedModal;
Link maEndDialogHdl;
DialogImpl() : mnResult( -1 ), mbStartedModal( false ) {}
};
// =======================================================================
void Dialog::ImplInitDialogData()
2000-09-18 16:07:07 +00:00
{
mpWindowImpl->mbDialog = TRUE;
mpDialogParent = NULL;
mpPrevExecuteDlg = NULL;
mbInExecute = FALSE;
mbOldSaveBack = FALSE;
mbInClose = FALSE;
mbModalMode = FALSE;
mnMousePositioned = 0;
mpDialogImpl = new DialogImpl;
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
void Dialog::ImplInit( Window* pParent, WinBits nStyle )
{
USHORT nSysWinMode = Application::GetSystemWindowMode();
if ( !(nStyle & WB_NODIALOGCONTROL) )
nStyle |= WB_DIALOGCONTROL;
nStyle |= WB_ROLLABLE;
// Now, all Dialogs are per default system windows !!!
nStyle |= WB_SYSTEMWINDOW;
2002-05-16 10:22:20 +00:00
// parent is NULL: get the default Dialog parent
2000-09-18 16:07:07 +00:00
if ( !pParent )
{
pParent = Application::GetDefDialogParent();
if ( !pParent && !(nStyle & WB_SYSTEMWINDOW) )
pParent = ImplGetSVData()->maWinData.mpAppWin;
2000-09-18 16:07:07 +00:00
// If Parent is disabled, then we search for a modal dialog
// in this frame
if ( pParent && (!pParent->IsInputEnabled() || pParent->IsInModalMode()) )
2000-09-18 16:07:07 +00:00
{
ImplSVData* pSVData = ImplGetSVData();
Dialog* pExeDlg = pSVData->maWinData.mpLastExecuteDlg;
while ( pExeDlg )
{
// Nur wenn er sichtbar und enabled ist
if ( pParent->ImplGetFirstOverlapWindow()->IsWindowOrChild( pExeDlg, TRUE ) &&
pExeDlg->IsReallyVisible() &&
pExeDlg->IsEnabled() && pExeDlg->IsInputEnabled() && !pExeDlg->IsInModalMode() )
2000-09-18 16:07:07 +00:00
{
pParent = pExeDlg;
break;
}
pExeDlg = pExeDlg->mpPrevExecuteDlg;
}
}
}
// DIALOG_NO_PARENT: explicitly don't have a parent for this Dialog
else if( pParent == DIALOG_NO_PARENT )
pParent = NULL;
2000-09-18 16:07:07 +00:00
/*
// Now, all Dialogs are per default system windows !!!
2000-09-18 16:07:07 +00:00
if ( pParent && !(nSysWinMode & SYSTEMWINDOW_MODE_NOAUTOMODE) )
{
if ( !pParent->mpWindowImpl->mpFrameWindow->IsVisible() )
2000-09-18 16:07:07 +00:00
pParent = NULL;
else
{
if ( pParent->mpWindowImpl->mpFrameWindow->IsDialog() )
2000-09-18 16:07:07 +00:00
{
Size aOutSize = pParent->mpWindowImpl->mpFrameWindow->GetOutputSizePixel();
2000-09-18 16:07:07 +00:00
if ( (aOutSize.Width() < 210) ||(aOutSize.Height() < 160) )
nStyle |= WB_SYSTEMWINDOW;
}
}
}
*/
2000-09-18 16:07:07 +00:00
if ( !pParent || (nStyle & WB_SYSTEMWINDOW) ||
(pParent->mpWindowImpl->mpFrameData->mbNeedSysWindow && !(nSysWinMode & SYSTEMWINDOW_MODE_NOAUTOMODE)) ||
2000-09-18 16:07:07 +00:00
(nSysWinMode & SYSTEMWINDOW_MODE_DIALOG) )
{
// create window with a small border ?
if ( (nStyle & (WB_BORDER | WB_NOBORDER | WB_MOVEABLE | WB_SIZEABLE | WB_CLOSEABLE)) == WB_BORDER )
2000-09-18 16:07:07 +00:00
{
ImplBorderWindow* pBorderWin = new ImplBorderWindow( pParent, nStyle, BORDERWINDOW_STYLE_FRAME );
SystemWindow::ImplInit( pBorderWin, nStyle & ~WB_BORDER, NULL );
pBorderWin->mpWindowImpl->mpClientWindow = this;
pBorderWin->GetBorder( mpWindowImpl->mnLeftBorder, mpWindowImpl->mnTopBorder, mpWindowImpl->mnRightBorder, mpWindowImpl->mnBottomBorder );
mpWindowImpl->mpBorderWindow = pBorderWin;
mpWindowImpl->mpRealParent = pParent;
2000-09-18 16:07:07 +00:00
}
else
{
mpWindowImpl->mbFrame = TRUE;
mpWindowImpl->mbOverlapWin = TRUE;
2001-08-07 10:54:21 +00:00
SystemWindow::ImplInit( pParent, nStyle & (WB_MOVEABLE | WB_SIZEABLE | WB_ROLLABLE | WB_CLOSEABLE | WB_STANDALONE) | WB_CLOSEABLE, NULL );
// Now set all style bits
mpWindowImpl->mnStyle = nStyle;
2000-09-18 16:07:07 +00:00
}
}
else
{
ImplBorderWindow* pBorderWin = new ImplBorderWindow( pParent, nStyle, BORDERWINDOW_STYLE_OVERLAP | BORDERWINDOW_STYLE_BORDER );
SystemWindow::ImplInit( pBorderWin, nStyle & ~WB_BORDER, NULL );
pBorderWin->mpWindowImpl->mpClientWindow = this;
pBorderWin->GetBorder( mpWindowImpl->mnLeftBorder, mpWindowImpl->mnTopBorder, mpWindowImpl->mnRightBorder, mpWindowImpl->mnBottomBorder );
mpWindowImpl->mpBorderWindow = pBorderWin;
mpWindowImpl->mpRealParent = pParent;
2000-09-18 16:07:07 +00:00
}
SetActivateMode( ACTIVATE_MODE_GRABFOCUS );
ImplInitSettings();
}
// -----------------------------------------------------------------------
void Dialog::ImplInitSettings()
{
// user override
2000-09-18 16:07:07 +00:00
if ( IsControlBackground() )
SetBackground( GetControlBackground() );
// NWF background
else if( IsNativeControlSupported( CTRL_WINDOW_BACKGROUND, PART_BACKGROUND_DIALOG ) )
{
mpWindowImpl->mnNativeBackground = PART_BACKGROUND_DIALOG;
EnableChildTransparentMode( TRUE );
}
// fallback to settings color
2000-09-18 16:07:07 +00:00
else
SetBackground( GetSettings().GetStyleSettings().GetDialogColor() );
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
void Dialog::ImplCenterDialog()
{
Rectangle aDeskRect = ImplGetFrameWindow()->GetDesktopRectPixel();
Point aDeskPos = aDeskRect.TopLeft();
Size aDeskSize = aDeskRect.GetSize();
Size aWinSize = GetSizePixel();
2001-10-24 07:57:18 +00:00
Window *pWindow = this;
while ( pWindow->mpWindowImpl->mpBorderWindow )
pWindow = pWindow->mpWindowImpl->mpBorderWindow;
2000-09-18 16:07:07 +00:00
Point aWinPos( ((aDeskSize.Width() - aWinSize.Width()) / 2) + aDeskPos.X(),
((aDeskSize.Height() - aWinSize.Height()) / 2) + aDeskPos.Y() );
// Pruefen, ob Dialogbox ausserhalb des Desks liegt
if ( (aWinPos.X() + aWinSize.Width()) > (aDeskPos.X()+aDeskSize.Width()) )
aWinPos.X() = aDeskPos.X()+aDeskSize.Width() - aWinSize.Width();
if ( (aWinPos.Y()+aWinSize.Height()) > (aDeskPos.Y()+aDeskSize.Height()) )
aWinPos.Y() = aDeskPos.Y()+aDeskSize.Height() - aWinSize.Height();
// Linke Ecke bevorzugen, da Titelbar oben ist
if ( aWinPos.X() < aDeskPos.X() )
aWinPos.X() = aDeskPos.X();
if ( aWinPos.Y() < aDeskPos.Y() )
aWinPos.Y() = aDeskPos.Y();
2001-10-24 07:57:18 +00:00
//SetPosPixel( aWinPos );
SetPosPixel( pWindow->ScreenToOutputPixel( aWinPos ) );
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
Dialog::Dialog( WindowType nType ) :
SystemWindow( nType )
{
ImplInitDialogData();
2000-09-18 16:07:07 +00:00
}
// -----------------------------------------------------------------------
Dialog::Dialog( Window* pParent, WinBits nStyle ) :
SystemWindow( WINDOW_DIALOG )
{
ImplInitDialogData();
2000-09-18 16:07:07 +00:00
ImplInit( pParent, nStyle );
}
// -----------------------------------------------------------------------
Dialog::Dialog( Window* pParent, const ResId& rResId ) :
SystemWindow( WINDOW_DIALOG )
{
ImplInitDialogData();
2000-09-18 16:07:07 +00:00
rResId.SetRT( RSC_DIALOG );
ImplInit( pParent, ImplInitRes( rResId ) );
ImplLoadRes( rResId );
}
// -----------------------------------------------------------------------
Dialog::~Dialog()
{
delete mpDialogImpl;
mpDialogImpl = NULL;
}
// -----------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
long Dialog::Notify( NotifyEvent& rNEvt )
{
// Zuerst Basisklasse rufen wegen TabSteuerung
long nRet = SystemWindow::Notify( rNEvt );
if ( !nRet )
{
if ( rNEvt.GetType() == EVENT_KEYINPUT )
{
const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
KeyCode aKeyCode = pKEvt->GetKeyCode();
USHORT nKeyCode = aKeyCode.GetCode();
if ( (nKeyCode == KEY_ESCAPE) &&
((GetStyle() & WB_CLOSEABLE) || ImplGetCancelButton( this ) || ImplGetOKButton( this )) )
{
Close();
return TRUE;
}
}
else if ( rNEvt.GetType() == EVENT_GETFOCUS )
{
// make sure the dialog is still modal
// changing focus between application frames may
// have re-enabled input for our parent
if( mbInExecute && mbModalMode )
{
// do not change modal counter (pSVData->maAppData.mnModalDialog)
SetModalInputMode( FALSE );
SetModalInputMode( TRUE );
// #93022# def-button might have changed after show
if( !mnMousePositioned )
{
mnMousePositioned = 1;
ImplMouseAutoPos( this );
}
}
}
2000-09-18 16:07:07 +00:00
}
return nRet;
}
// -----------------------------------------------------------------------
void Dialog::StateChanged( StateChangedType nType )
{
SystemWindow::StateChanged( nType );
if ( nType == STATE_CHANGE_INITSHOW )
{
if ( GetSettings().GetStyleSettings().GetAutoMnemonic() )
2000-09-18 16:07:07 +00:00
ImplWindowAutoMnemonic( this );
//if ( IsDefaultPos() && !mpWindowImpl->mbFrame )
// ImplCenterDialog();
2000-09-18 16:07:07 +00:00
if ( !HasChildPathFocus() || HasFocus() )
GrabFocusToFirstControl();
if ( !(GetStyle() & WB_CLOSEABLE) )
{
if ( ImplGetCancelButton( this ) || ImplGetOKButton( this ) )
{
if ( ImplGetBorderWindow() )
((ImplBorderWindow*)ImplGetBorderWindow())->SetCloser();
}
}
ImplMouseAutoPos( this );
}
else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
{
ImplInitSettings();
Invalidate();
}
}
// -----------------------------------------------------------------------
void Dialog::DataChanged( const DataChangedEvent& rDCEvt )
{
SystemWindow::DataChanged( rDCEvt );
if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
(rDCEvt.GetFlags() & SETTINGS_STYLE) )
{
ImplInitSettings();
Invalidate();
}
}
// -----------------------------------------------------------------------
BOOL Dialog::Close()
{
2001-11-27 08:52:58 +00:00
ImplDelData aDelData;
ImplAddDel( &aDelData );
ImplCallEventListeners( VCLEVENT_WINDOW_CLOSE );
if ( aDelData.IsDelete() )
return FALSE;
ImplRemoveDel( &aDelData );
if ( mpWindowImpl->mxWindowPeer.is() && IsCreatedWithToolkit() && !IsInExecute() )
2001-11-27 08:52:58 +00:00
return FALSE;
2000-09-18 16:07:07 +00:00
mbInClose = TRUE;
if ( !(GetStyle() & WB_CLOSEABLE) )
{
2001-08-07 10:54:21 +00:00
BOOL bRet = TRUE;
2000-09-18 16:07:07 +00:00
ImplAddDel( &aDelData );
PushButton* pButton = ImplGetCancelButton( this );
if ( pButton )
pButton->Click();
else
{
pButton = ImplGetOKButton( this );
if ( pButton )
pButton->Click();
2001-08-07 10:54:21 +00:00
else
bRet = FALSE;
2000-09-18 16:07:07 +00:00
}
if ( aDelData.IsDelete() )
return TRUE;
ImplRemoveDel( &aDelData );
2001-08-07 10:54:21 +00:00
return bRet;
2000-09-18 16:07:07 +00:00
}
if ( IsInExecute() )
{
EndDialog( FALSE );
mbInClose = FALSE;
return TRUE;
}
else
{
mbInClose = FALSE;
return SystemWindow::Close();
}
}
// -----------------------------------------------------------------------
BOOL Dialog::ImplStartExecuteModal()
2000-09-18 16:07:07 +00:00
{
if ( mbInExecute )
{
#ifdef DBG_UTIL
ByteString aErrorStr( "Dialog::StartExecuteModal() is called in Dialog::StartExecuteModal(): " );
2000-09-18 16:07:07 +00:00
aErrorStr += ImplGetDialogText( this );
DBG_ERROR( aErrorStr.GetBuffer() );
#endif
return FALSE;
2000-09-18 16:07:07 +00:00
}
if ( Application::IsDialogCancelEnabled() )
{
#ifdef DBG_UTIL
ByteString aErrorStr( "Dialog::StartExecuteModal() is called in a none UI application: " );
2000-09-18 16:07:07 +00:00
aErrorStr += ImplGetDialogText( this );
DBG_ERROR( aErrorStr.GetBuffer() );
#endif
return FALSE;
2000-09-18 16:07:07 +00:00
}
#ifdef DBG_UTIL
Window* pParent = GetParent();
if ( pParent )
{
pParent = pParent->ImplGetFirstOverlapWindow();
DBG_ASSERT( pParent->IsReallyVisible(),
"Dialog::StartExecuteModal() - Parent not visible" );
2001-12-10 12:36:20 +00:00
DBG_ASSERT( pParent->IsInputEnabled(),
"Dialog::StartExecuteModal() - Parent input disabled, use another parent to ensure modality!" );
DBG_ASSERT( ! pParent->IsInModalMode(),
"Dialog::StartExecuteModal() - Parent already modally disabled, use another parent to ensure modality!" );
2000-09-18 16:07:07 +00:00
}
#endif
ImplSVData* pSVData = ImplGetSVData();
// Dialoge, die sich in Execute befinden, miteinander verketten
mpPrevExecuteDlg = pSVData->maWinData.mpLastExecuteDlg;
pSVData->maWinData.mpLastExecuteDlg = this;
// Capture beenden, damit der Dialog bedient werden kann
if ( pSVData->maWinData.mpTrackWin )
pSVData->maWinData.mpTrackWin->EndTracking( ENDTRACK_CANCEL );
if ( pSVData->maWinData.mpCaptureWin )
pSVData->maWinData.mpCaptureWin->ReleaseMouse();
EnableInput( TRUE, TRUE );
if ( GetParent() )
{
NotifyEvent aNEvt( EVENT_EXECUTEDIALOG, this );
GetParent()->Notify( aNEvt );
}
mbInExecute = TRUE;
SetModalInputMode( TRUE );
mbOldSaveBack = IsSaveBackgroundEnabled();
EnableSaveBackground();
Show();
pSVData->maAppData.mnModalMode++;
return TRUE;
}
// -----------------------------------------------------------------------
void Dialog::ImplEndExecuteModal()
{
ImplSVData* pSVData = ImplGetSVData();
pSVData->maAppData.mnModalMode--;
}
// -----------------------------------------------------------------------
short Dialog::Execute()
{
if ( !ImplStartExecuteModal() )
return 0;
2000-09-18 16:07:07 +00:00
ImplDelData aDelData;
ImplAddDel( &aDelData );
ImplDelData aParentDelData;
//DBG_ASSERT( mpDialogParent, "Dialog::Execute() - no Parent: cannot set modal count!" );
Window* pDialogParent = mpDialogParent;
if( pDialogParent )
{
pDialogParent->ImplIncModalCount(); // #106303# support frame based modal count
pDialogParent->ImplAddDel( &aParentDelData );
}
// Solange Yielden, bis EndDialog aufgerufen wird, oder der Dialog
// zerstoert wird (sollte nicht sein und ist nur vorsichtsmassnahme)
2000-09-18 16:07:07 +00:00
while ( !aDelData.IsDelete() && mbInExecute )
Application::Yield();
ImplEndExecuteModal();
if( pDialogParent )
{
if( ! aParentDelData.IsDelete() )
{
pDialogParent->ImplDecModalCount(); // #106303# support frame based modal count
pDialogParent->ImplRemoveDel( &aParentDelData );
}
#ifdef DBG_UTIL
else
{
DBG_ERROR( "Dialog::Execute() - Parent of dialog destroyed in Execute()" );
}
#endif
}
2000-09-18 16:07:07 +00:00
if ( !aDelData.IsDelete() )
ImplRemoveDel( &aDelData );
#ifdef DBG_UTIL
else
{
DBG_ERROR( "Dialog::Execute() - Dialog destroyed in Execute()" );
}
#endif
long nRet = mpDialogImpl->mnResult;
mpDialogImpl->mnResult = -1;
2000-09-18 16:07:07 +00:00
return (short)nRet;
}
// -----------------------------------------------------------------------
// virtual
void Dialog::StartExecuteModal( const Link& rEndDialogHdl )
{
if ( !ImplStartExecuteModal() )
return;
mpDialogImpl->maEndDialogHdl = rEndDialogHdl;
mpDialogImpl->mbStartedModal = true;
}
// -----------------------------------------------------------------------
BOOL Dialog::IsStartedModal() const
{
return mpDialogImpl->mbStartedModal;
}
// -----------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
void Dialog::EndDialog( long nResult )
{
if ( mbInExecute )
{
SetModalInputMode( FALSE );
// Dialog aus der Kette der Dialoge die in Execute stehen entfernen
ImplSVData* pSVData = ImplGetSVData();
Dialog* pExeDlg = pSVData->maWinData.mpLastExecuteDlg;
while ( pExeDlg )
{
if ( pExeDlg == this )
{
pSVData->maWinData.mpLastExecuteDlg = mpPrevExecuteDlg;
2000-09-18 16:07:07 +00:00
break;
}
pExeDlg = pExeDlg->mpPrevExecuteDlg;
}
// set focus to previous modal dialogue if it is modal for
// the same frame parent (or NULL)
if( mpPrevExecuteDlg )
{
Window* pFrameParent = ImplGetFrameWindow()->ImplGetParent();
Window* pPrevFrameParent = mpPrevExecuteDlg->ImplGetFrameWindow()->ImplGetParent();
if( ( !pFrameParent && !pPrevFrameParent ) ||
( pFrameParent && pPrevFrameParent && pFrameParent->ImplGetFrame() == pPrevFrameParent->ImplGetFrame() )
)
{
mpPrevExecuteDlg->GrabFocus();
}
}
2000-09-18 16:07:07 +00:00
mpPrevExecuteDlg = NULL;
Hide();
EnableSaveBackground( mbOldSaveBack );
if ( GetParent() )
{
NotifyEvent aNEvt( EVENT_ENDEXECUTEDIALOG, this );
GetParent()->Notify( aNEvt );
}
mpDialogImpl->mnResult = nResult;
if ( mpDialogImpl->mbStartedModal )
{
ImplEndExecuteModal();
mpDialogImpl->maEndDialogHdl.Call( this );
mpDialogImpl->maEndDialogHdl = Link();
mpDialogImpl->mbStartedModal = false;
mpDialogImpl->mnResult = -1;
}
2000-09-18 16:07:07 +00:00
mbInExecute = FALSE;
}
}
// -----------------------------------------------------------------------
long Dialog::GetResult() const
{
return mpDialogImpl->mnResult;
}
// -----------------------------------------------------------------------
2001-01-29 14:48:32 +00:00
void Dialog::EndAllDialogs( Window* pParent )
{
ImplSVData* pSVData = ImplGetSVData();
Dialog* pTempModDialog;
Dialog* pModDialog = pSVData->maWinData.mpLastExecuteDlg;
while ( pModDialog )
{
pTempModDialog = pModDialog->mpPrevExecuteDlg;
2001-01-29 14:48:32 +00:00
if( !pParent || ( pParent && pParent->IsWindowOrChild( pModDialog, TRUE ) ) )
{
pModDialog->EndDialog( FALSE );
pModDialog->PostUserEvent( Link() );
}
pModDialog = pTempModDialog;
}
}
// -----------------------------------------------------------------------
2000-09-18 16:07:07 +00:00
void Dialog::SetModalInputMode( BOOL bModal )
{
if ( bModal == mbModalMode )
return;
ImplSVData* pSVData = ImplGetSVData();
mbModalMode = bModal;
if ( bModal )
{
pSVData->maAppData.mnModalDialog++;
// Diable the prev Modal Dialog, because our dialog must close at first,
// before the other dialog can be closed (because the other dialog
// is on stack since our dialog returns)
if ( mpPrevExecuteDlg && !mpPrevExecuteDlg->IsWindowOrChild( this, TRUE ) )
mpPrevExecuteDlg->EnableInput( FALSE, TRUE, TRUE, this );
// determine next overlap dialog parent
Window* pParent = GetParent();
if ( pParent )
{
// #103716# dialogs should always be modal to the whole frame window
// #115933# disable the whole frame hierarchie, useful if our parent
// is a modeless dialog
mpDialogParent = pParent->mpWindowImpl->mpFrameWindow;
mpDialogParent->ImplIncModalCount();
}
2001-12-10 12:36:20 +00:00
2000-09-18 16:07:07 +00:00
}
else
{
pSVData->maAppData.mnModalDialog--;
if ( mpDialogParent )
{
// #115933# re-enable the whole frame hierarchie again (see above)
// note that code in getfocus assures that we do not accidentally enable
// windows that were disabled before
mpDialogParent->ImplDecModalCount();
}
2000-09-18 16:07:07 +00:00
// Enable the prev Modal Dialog
if ( mpPrevExecuteDlg && !mpPrevExecuteDlg->IsWindowOrChild( this, TRUE ) )
{
2000-09-18 16:07:07 +00:00
mpPrevExecuteDlg->EnableInput( TRUE, TRUE, TRUE, this );
// ensure continued modality of prev dialog
// do not change modality counter
mpPrevExecuteDlg->SetModalInputMode( FALSE );
mpPrevExecuteDlg->SetModalInputMode( TRUE );
}
2000-09-18 16:07:07 +00:00
}
}
// -----------------------------------------------------------------------
void Dialog::SetModalInputMode( BOOL bModal, BOOL bSubModalDialogs )
{
if ( bSubModalDialogs )
{
Window* pOverlap = ImplGetFirstOverlapWindow();
pOverlap = pOverlap->mpWindowImpl->mpFirstOverlap;
2000-09-18 16:07:07 +00:00
while ( pOverlap )
{
if ( pOverlap->IsDialog() )
((Dialog*)pOverlap)->SetModalInputMode( bModal, TRUE );
pOverlap = pOverlap->mpWindowImpl->mpNext;
2000-09-18 16:07:07 +00:00
}
}
SetModalInputMode( bModal );
}
// -----------------------------------------------------------------------
void Dialog::GrabFocusToFirstControl()
{
Window* pFocusControl;
// Wenn Dialog den Focus hat, versuchen wr trotzdem
// ein Focus-Control zu finden
if ( HasFocus() )
pFocusControl = NULL;
else
{
// Wenn schon ein Child-Fenster mal den Focus hatte,
// dann dieses bevorzugen
pFocusControl = ImplGetFirstOverlapWindow()->mpWindowImpl->mpLastFocusWindow;
2000-09-18 16:07:07 +00:00
// Control aus der Dialog-Steuerung suchen
if ( pFocusControl )
pFocusControl = ImplFindDlgCtrlWindow( pFocusControl );
}
// Kein Control hatte vorher den Focus, oder das Control
// befindet sich nicht in der Tab-Steuerung, dann das erste
// Control in der TabSteuerung den Focus geben
if ( !pFocusControl ||
!(pFocusControl->GetStyle() & WB_TABSTOP) ||
!pFocusControl->IsVisible() ||
!pFocusControl->IsEnabled() || !pFocusControl->IsInputEnabled() )
{
USHORT n = 0;
pFocusControl = ImplGetDlgWindow( n, DLGWINDOW_FIRST );
}
if ( pFocusControl )
pFocusControl->ImplControlFocus( GETFOCUS_INIT );
}
void Dialog::GetDrawWindowBorder( sal_Int32& rLeftBorder, sal_Int32& rTopBorder, sal_Int32& rRightBorder, sal_Int32& rBottomBorder ) const
2001-06-05 12:52:42 +00:00
{
ImplBorderWindow aImplWin( (Window*)this, WB_BORDER|WB_STDWORK, BORDERWINDOW_STYLE_OVERLAP );
// aImplWin.SetText( GetText() );
// aImplWin.SetPosSizePixel( aPos.X(), aPos.Y(), aSize.Width(), aSize.Height() );
// aImplWin.SetDisplayActive( TRUE );
// aImplWin.InitView();
aImplWin.GetBorder( rLeftBorder, rTopBorder, rRightBorder, rBottomBorder );
}
void Dialog::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, ULONG )
2001-02-14 17:11:46 +00:00
{
Point aPos = pDev->LogicToPixel( rPos );
Size aSize = pDev->LogicToPixel( rSize );
2001-02-14 17:11:46 +00:00
ImplInitSettings();
2001-02-16 10:13:00 +00:00
pDev->Push();
pDev->SetMapMode();
pDev->SetLineColor();
pDev->SetFillColor( GetBackground().GetColor() );
pDev->DrawRect( Rectangle( aPos, aSize ) );
if (!( GetStyle() & WB_NOBORDER ))
{
ImplBorderWindow aImplWin( this, WB_BORDER|WB_STDWORK, BORDERWINDOW_STYLE_OVERLAP );
aImplWin.SetText( GetText() );
aImplWin.SetPosSizePixel( aPos.X(), aPos.Y(), aSize.Width(), aSize.Height() );
aImplWin.SetDisplayActive( TRUE );
aImplWin.InitView();
2001-02-16 10:13:00 +00:00
aImplWin.Draw( Rectangle( aPos, aSize ), pDev, aPos );
}
2001-02-14 17:11:46 +00:00
pDev->Pop();
}
2000-09-18 16:07:07 +00:00
// =======================================================================
ModelessDialog::ModelessDialog( Window* pParent, WinBits nStyle ) :
Dialog( WINDOW_MODELESSDIALOG )
{
ImplInit( pParent, nStyle );
}
// -----------------------------------------------------------------------
ModelessDialog::ModelessDialog( Window* pParent, const ResId& rResId ) :
Dialog( WINDOW_MODELESSDIALOG )
{
rResId.SetRT( RSC_MODELESSDIALOG );
WinBits nStyle = ImplInitRes( rResId );
ImplInit( pParent, nStyle );
ImplLoadRes( rResId );
if ( !(nStyle & WB_HIDE) )
Show();
}
// =======================================================================
ModalDialog::ModalDialog( Window* pParent, WinBits nStyle ) :
Dialog( WINDOW_MODALDIALOG )
{
ImplInit( pParent, nStyle );
}
// -----------------------------------------------------------------------
ModalDialog::ModalDialog( Window* pParent, const ResId& rResId ) :
Dialog( WINDOW_MODALDIALOG )
{
rResId.SetRT( RSC_MODALDIALOG );
ImplInit( pParent, ImplInitRes( rResId ) );
ImplLoadRes( rResId );
}