1998-05-20 14:12:05 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2000-01-30 01:31:09 +00:00
|
|
|
// Name: src/msw/dialog.cpp
|
1998-05-20 14:12:05 +00:00
|
|
|
// Purpose: wxDialog class
|
|
|
|
// Author: Julian Smart
|
|
|
|
// Modified by:
|
|
|
|
// Created: 01/02/97
|
|
|
|
// RCS-ID: $Id$
|
2003-03-17 11:23:28 +00:00
|
|
|
// Copyright: (c) Julian Smart
|
1998-08-07 22:27:33 +00:00
|
|
|
// Licence: wxWindows licence
|
1998-05-20 14:12:05 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2000-01-30 01:31:09 +00:00
|
|
|
// ============================================================================
|
|
|
|
// declarations
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2003-08-09 12:46:53 +00:00
|
|
|
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
|
2000-01-30 01:31:09 +00:00
|
|
|
#pragma implementation "dialog.h"
|
1998-05-20 14:12:05 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
2000-01-30 01:31:09 +00:00
|
|
|
#pragma hdrstop
|
1998-05-20 14:12:05 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
2000-01-30 01:31:09 +00:00
|
|
|
#include "wx/dialog.h"
|
|
|
|
#include "wx/utils.h"
|
|
|
|
#include "wx/frame.h"
|
|
|
|
#include "wx/app.h"
|
|
|
|
#include "wx/settings.h"
|
|
|
|
#include "wx/intl.h"
|
|
|
|
#include "wx/log.h"
|
1998-05-20 14:12:05 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/msw/private.h"
|
1999-02-09 16:00:23 +00:00
|
|
|
#include "wx/log.h"
|
2003-09-15 19:54:51 +00:00
|
|
|
#include "wx/evtloop.h"
|
2003-09-17 23:34:07 +00:00
|
|
|
#include "wx/ptr_scpd.h"
|
1998-05-20 14:12:05 +00:00
|
|
|
|
2001-11-28 18:22:16 +00:00
|
|
|
#if wxUSE_COMMON_DIALOGS && !defined(__WXMICROWIN__)
|
2000-01-30 01:31:09 +00:00
|
|
|
#include <commdlg.h>
|
1998-05-20 14:12:05 +00:00
|
|
|
#endif
|
|
|
|
|
2000-01-30 01:31:09 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// default dialog pos and size
|
|
|
|
|
1998-05-20 14:12:05 +00:00
|
|
|
#define wxDIALOG_DEFAULT_X 300
|
|
|
|
#define wxDIALOG_DEFAULT_Y 300
|
|
|
|
|
2000-01-30 01:31:09 +00:00
|
|
|
#define wxDIALOG_DEFAULT_WIDTH 500
|
|
|
|
#define wxDIALOG_DEFAULT_HEIGHT 500
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxWin macros
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2003-08-27 18:42:14 +00:00
|
|
|
#if wxUSE_EXTENDED_RTTI
|
|
|
|
WX_DEFINE_FLAGS( wxDialogStyle )
|
|
|
|
|
2003-09-04 01:19:40 +00:00
|
|
|
wxBEGIN_FLAGS( wxDialogStyle )
|
2003-08-27 18:42:14 +00:00
|
|
|
// new style border flags, we put them first to
|
|
|
|
// use them for streaming out
|
2003-09-04 01:19:40 +00:00
|
|
|
wxFLAGS_MEMBER(wxBORDER_SIMPLE)
|
|
|
|
wxFLAGS_MEMBER(wxBORDER_SUNKEN)
|
|
|
|
wxFLAGS_MEMBER(wxBORDER_DOUBLE)
|
|
|
|
wxFLAGS_MEMBER(wxBORDER_RAISED)
|
|
|
|
wxFLAGS_MEMBER(wxBORDER_STATIC)
|
|
|
|
wxFLAGS_MEMBER(wxBORDER_NONE)
|
2003-08-27 18:42:14 +00:00
|
|
|
|
|
|
|
// old style border flags
|
2003-09-04 01:19:40 +00:00
|
|
|
wxFLAGS_MEMBER(wxSIMPLE_BORDER)
|
|
|
|
wxFLAGS_MEMBER(wxSUNKEN_BORDER)
|
|
|
|
wxFLAGS_MEMBER(wxDOUBLE_BORDER)
|
|
|
|
wxFLAGS_MEMBER(wxRAISED_BORDER)
|
|
|
|
wxFLAGS_MEMBER(wxSTATIC_BORDER)
|
|
|
|
wxFLAGS_MEMBER(wxNO_BORDER)
|
2003-08-27 18:42:14 +00:00
|
|
|
|
|
|
|
// standard window styles
|
2003-09-04 01:19:40 +00:00
|
|
|
wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
|
|
|
|
wxFLAGS_MEMBER(wxCLIP_CHILDREN)
|
2003-08-27 18:42:14 +00:00
|
|
|
|
|
|
|
// dialog styles
|
2003-09-04 01:19:40 +00:00
|
|
|
wxFLAGS_MEMBER(wxDIALOG_MODAL)
|
|
|
|
wxFLAGS_MEMBER(wxDIALOG_MODELESS)
|
|
|
|
wxFLAGS_MEMBER(wxNO_3D)
|
|
|
|
wxFLAGS_MEMBER(wxWS_EX_VALIDATE_RECURSIVELY)
|
|
|
|
wxFLAGS_MEMBER(wxSTAY_ON_TOP)
|
|
|
|
wxFLAGS_MEMBER(wxCAPTION)
|
|
|
|
wxFLAGS_MEMBER(wxTHICK_FRAME)
|
|
|
|
wxFLAGS_MEMBER(wxSYSTEM_MENU)
|
|
|
|
wxFLAGS_MEMBER(wxRESIZE_BORDER)
|
|
|
|
wxFLAGS_MEMBER(wxRESIZE_BOX)
|
|
|
|
wxFLAGS_MEMBER(wxCLOSE_BOX)
|
|
|
|
wxFLAGS_MEMBER(wxMAXIMIZE_BOX)
|
|
|
|
wxFLAGS_MEMBER(wxMINIMIZE_BOX)
|
|
|
|
wxEND_FLAGS( wxDialogStyle )
|
2003-08-27 18:42:14 +00:00
|
|
|
|
|
|
|
IMPLEMENT_DYNAMIC_CLASS_XTI(wxDialog, wxTopLevelWindow,"wx/dialog.h")
|
|
|
|
|
2003-09-04 01:19:40 +00:00
|
|
|
wxBEGIN_PROPERTIES_TABLE(wxDialog)
|
|
|
|
wxPROPERTY( Title,wxString, SetTitle, GetTitle, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
|
|
|
|
wxPROPERTY_FLAGS( WindowStyle , wxDialogStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
|
|
|
|
wxEND_PROPERTIES_TABLE()
|
2003-08-27 18:42:14 +00:00
|
|
|
|
2003-09-04 01:19:40 +00:00
|
|
|
wxBEGIN_HANDLERS_TABLE(wxDialog)
|
|
|
|
wxEND_HANDLERS_TABLE()
|
2003-08-27 18:42:14 +00:00
|
|
|
|
2003-09-04 01:19:40 +00:00
|
|
|
wxCONSTRUCTOR_6( wxDialog , wxWindow* , Parent , wxWindowID , Id , wxString , Title , wxPoint , Position , wxSize , Size , long , WindowStyle)
|
2003-08-27 18:42:14 +00:00
|
|
|
|
|
|
|
#else
|
2001-09-24 00:34:14 +00:00
|
|
|
IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow)
|
2003-08-27 18:42:14 +00:00
|
|
|
#endif
|
2003-08-05 17:30:46 +00:00
|
|
|
|
2002-01-04 15:20:01 +00:00
|
|
|
BEGIN_EVENT_TABLE(wxDialog, wxDialogBase)
|
2000-01-29 02:38:19 +00:00
|
|
|
EVT_BUTTON(wxID_OK, wxDialog::OnOK)
|
|
|
|
EVT_BUTTON(wxID_APPLY, wxDialog::OnApply)
|
|
|
|
EVT_BUTTON(wxID_CANCEL, wxDialog::OnCancel)
|
2000-01-30 01:31:09 +00:00
|
|
|
|
2000-01-29 02:38:19 +00:00
|
|
|
EVT_CHAR_HOOK(wxDialog::OnCharHook)
|
2000-01-30 01:31:09 +00:00
|
|
|
|
2000-01-29 02:38:19 +00:00
|
|
|
EVT_SYS_COLOUR_CHANGED(wxDialog::OnSysColourChanged)
|
2000-01-30 01:31:09 +00:00
|
|
|
|
2000-01-29 02:38:19 +00:00
|
|
|
EVT_CLOSE(wxDialog::OnCloseWindow)
|
|
|
|
END_EVENT_TABLE()
|
1998-05-20 14:12:05 +00:00
|
|
|
|
2003-09-16 12:30:34 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxDialogModalData
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2003-09-17 23:34:07 +00:00
|
|
|
// this is simply a container for any data we need to implement modality which
|
|
|
|
// allows us to avoid changing wxDialog each time the implementation changes
|
2003-09-16 12:30:34 +00:00
|
|
|
class wxDialogModalData
|
|
|
|
{
|
|
|
|
public:
|
2003-09-17 23:34:07 +00:00
|
|
|
wxDialogModalData(wxDialog *dialog) : m_evtLoop(dialog) { }
|
2003-09-16 12:30:34 +00:00
|
|
|
|
2003-09-17 23:34:07 +00:00
|
|
|
void RunLoop()
|
2003-09-16 12:30:34 +00:00
|
|
|
{
|
|
|
|
m_evtLoop.Run();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExitLoop()
|
|
|
|
{
|
|
|
|
m_evtLoop.Exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2003-09-17 23:34:07 +00:00
|
|
|
wxModalEventLoop m_evtLoop;
|
2003-09-16 12:30:34 +00:00
|
|
|
};
|
|
|
|
|
2003-09-17 23:34:07 +00:00
|
|
|
wxDEFINE_TIED_SCOPED_PTR_TYPE(wxDialogModalData);
|
|
|
|
|
2000-01-30 01:31:09 +00:00
|
|
|
// ============================================================================
|
|
|
|
// implementation
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxDialog construction
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2000-10-07 20:19:10 +00:00
|
|
|
void wxDialog::Init()
|
1998-05-20 14:12:05 +00:00
|
|
|
{
|
2000-02-25 16:21:53 +00:00
|
|
|
m_oldFocus = (wxWindow *)NULL;
|
2000-10-07 20:19:10 +00:00
|
|
|
|
2000-01-30 01:31:09 +00:00
|
|
|
m_isShown = FALSE;
|
1998-05-20 14:12:05 +00:00
|
|
|
|
2003-09-16 12:30:34 +00:00
|
|
|
m_modalData = NULL;
|
2000-10-07 20:19:10 +00:00
|
|
|
|
2002-01-08 23:53:01 +00:00
|
|
|
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
|
1998-05-20 14:12:05 +00:00
|
|
|
}
|
|
|
|
|
2000-10-11 13:16:37 +00:00
|
|
|
bool wxDialog::Create(wxWindow *parent,
|
|
|
|
wxWindowID id,
|
1999-02-06 23:27:08 +00:00
|
|
|
const wxString& title,
|
|
|
|
const wxPoint& pos,
|
|
|
|
const wxSize& size,
|
|
|
|
long style,
|
|
|
|
const wxString& name)
|
1998-05-20 14:12:05 +00:00
|
|
|
{
|
2000-10-07 20:19:10 +00:00
|
|
|
Init();
|
|
|
|
|
2001-09-24 00:34:14 +00:00
|
|
|
SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG);
|
1999-04-17 20:30:28 +00:00
|
|
|
|
2001-10-07 22:17:24 +00:00
|
|
|
// save focus before doing anything which can potentially change it
|
2001-09-24 00:34:14 +00:00
|
|
|
m_oldFocus = FindFocus();
|
1999-02-06 23:27:08 +00:00
|
|
|
|
1999-03-08 11:22:31 +00:00
|
|
|
// All dialogs should really have this style
|
2001-10-07 22:17:24 +00:00
|
|
|
style |= wxTAB_TRAVERSAL;
|
1998-05-20 14:12:05 +00:00
|
|
|
|
2001-10-07 22:17:24 +00:00
|
|
|
if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
|
1999-02-06 23:27:08 +00:00
|
|
|
return FALSE;
|
1998-05-20 14:12:05 +00:00
|
|
|
|
2002-01-08 23:53:01 +00:00
|
|
|
SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
|
2001-10-15 22:17:09 +00:00
|
|
|
|
1999-02-06 23:27:08 +00:00
|
|
|
return TRUE;
|
1998-05-20 14:12:05 +00:00
|
|
|
}
|
|
|
|
|
1998-07-04 15:17:59 +00:00
|
|
|
void wxDialog::SetModal(bool flag)
|
1998-05-20 14:12:05 +00:00
|
|
|
{
|
2000-01-30 01:31:09 +00:00
|
|
|
if ( flag )
|
|
|
|
{
|
|
|
|
m_windowStyle |= wxDIALOG_MODAL;
|
|
|
|
|
|
|
|
wxModelessWindows.DeleteObject(this);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_windowStyle &= ~wxDIALOG_MODAL;
|
|
|
|
|
|
|
|
wxModelessWindows.Append(this);
|
|
|
|
}
|
1998-05-20 14:12:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxDialog::~wxDialog()
|
|
|
|
{
|
2000-01-30 01:31:09 +00:00
|
|
|
m_isBeingDeleted = TRUE;
|
1998-05-20 14:12:05 +00:00
|
|
|
|
2000-10-07 20:19:10 +00:00
|
|
|
// this will also reenable all the other windows for a modal dialog
|
2000-01-30 01:31:09 +00:00
|
|
|
Show(FALSE);
|
1998-05-20 14:12:05 +00:00
|
|
|
}
|
|
|
|
|
2000-01-30 01:31:09 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// kbd handling
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
1998-05-20 14:12:05 +00:00
|
|
|
// By default, pressing escape cancels the dialog
|
|
|
|
void wxDialog::OnCharHook(wxKeyEvent& event)
|
|
|
|
{
|
2000-03-12 00:26:21 +00:00
|
|
|
if (GetHWND())
|
1998-05-20 14:12:05 +00:00
|
|
|
{
|
2000-03-12 00:26:21 +00:00
|
|
|
// "Esc" works as an accelerator for the "Cancel" button, but it
|
|
|
|
// shouldn't close the dialog which doesn't have any cancel button
|
|
|
|
if ( (event.m_keyCode == WXK_ESCAPE) && FindWindow(wxID_CANCEL) )
|
|
|
|
{
|
|
|
|
wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
|
|
|
|
cancelEvent.SetEventObject( this );
|
|
|
|
GetEventHandler()->ProcessEvent(cancelEvent);
|
|
|
|
|
|
|
|
// ensure that there is another message for this window so the
|
|
|
|
// ShowModal loop will exit and won't get stuck in GetMessage().
|
|
|
|
::PostMessage(GetHwnd(), WM_NULL, 0, 0);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
1998-05-20 14:12:05 +00:00
|
|
|
}
|
2000-03-12 00:26:21 +00:00
|
|
|
|
|
|
|
// We didn't process this event.
|
|
|
|
event.Skip();
|
1998-05-20 14:12:05 +00:00
|
|
|
}
|
|
|
|
|
2000-01-30 01:31:09 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// showing the dialogs
|
|
|
|
// ----------------------------------------------------------------------------
|
1999-07-24 23:16:35 +00:00
|
|
|
|
|
|
|
bool wxDialog::IsModal() const
|
|
|
|
{
|
2000-01-30 01:31:09 +00:00
|
|
|
return (GetWindowStyleFlag() & wxDIALOG_MODAL) != 0;
|
1998-05-20 14:12:05 +00:00
|
|
|
}
|
|
|
|
|
2000-01-30 01:31:09 +00:00
|
|
|
bool wxDialog::IsModalShowing() const
|
1998-05-20 14:12:05 +00:00
|
|
|
{
|
2003-09-16 12:30:34 +00:00
|
|
|
return m_modalData != NULL;
|
1998-05-20 14:12:05 +00:00
|
|
|
}
|
|
|
|
|
2002-09-02 00:44:24 +00:00
|
|
|
wxWindow *wxDialog::FindSuitableParent() const
|
|
|
|
{
|
|
|
|
// first try to use the currently active window
|
|
|
|
HWND hwndFg = ::GetForegroundWindow();
|
|
|
|
wxWindow *parent = hwndFg ? wxFindWinFromHandle((WXHWND)hwndFg)
|
|
|
|
: NULL;
|
|
|
|
if ( !parent )
|
|
|
|
{
|
|
|
|
// next try the main app window
|
|
|
|
parent = wxTheApp->GetTopWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
// finally, check if the parent we found is really suitable
|
|
|
|
if ( !parent || parent == (wxWindow *)this || !parent->IsShown() )
|
|
|
|
{
|
|
|
|
// don't use this one
|
|
|
|
parent = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
2000-01-30 01:31:09 +00:00
|
|
|
void wxDialog::DoShowModal()
|
1998-05-20 14:12:05 +00:00
|
|
|
{
|
2000-01-30 01:31:09 +00:00
|
|
|
wxCHECK_RET( !IsModalShowing(), _T("DoShowModal() called twice") );
|
2000-07-15 19:51:35 +00:00
|
|
|
wxCHECK_RET( IsModal(), _T("can't DoShowModal() modeless dialog") );
|
2000-01-30 01:31:09 +00:00
|
|
|
|
|
|
|
wxWindow *parent = GetParent();
|
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
wxWindow* oldFocus = m_oldFocus;
|
2000-01-30 01:31:09 +00:00
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
// We have to remember the HWND because we need to check
|
|
|
|
// the HWND still exists (oldFocus can be garbage when the dialog
|
|
|
|
// exits, if it has been destroyed)
|
|
|
|
HWND hwndOldFocus = 0;
|
|
|
|
if (oldFocus)
|
|
|
|
hwndOldFocus = (HWND) oldFocus->GetHWND();
|
2000-01-30 01:31:09 +00:00
|
|
|
|
2000-10-07 20:19:10 +00:00
|
|
|
// remember where the focus was
|
|
|
|
if ( !oldFocus )
|
2000-01-30 01:31:09 +00:00
|
|
|
{
|
2000-10-07 20:19:10 +00:00
|
|
|
oldFocus = parent;
|
|
|
|
if ( parent )
|
|
|
|
hwndOldFocus = GetHwndOf(parent);
|
|
|
|
}
|
2000-07-15 19:51:35 +00:00
|
|
|
|
2000-10-07 20:19:10 +00:00
|
|
|
// enter the modal loop
|
2003-09-17 23:34:07 +00:00
|
|
|
{
|
|
|
|
wxDialogModalDataTiedPtr modalData(&m_modalData,
|
|
|
|
new wxDialogModalData(this));
|
|
|
|
modalData->RunLoop();
|
|
|
|
}
|
2002-12-04 14:11:26 +00:00
|
|
|
|
2000-01-30 01:31:09 +00:00
|
|
|
// and restore focus
|
2000-07-15 19:51:35 +00:00
|
|
|
// Note that this code MUST NOT access the dialog object's data
|
|
|
|
// in case the object has been deleted (which will be the case
|
|
|
|
// for a modal dialog that has been destroyed before calling EndModal).
|
|
|
|
if ( oldFocus && (oldFocus != this) && ::IsWindow(hwndOldFocus))
|
2000-01-30 01:31:09 +00:00
|
|
|
{
|
2000-07-15 19:51:35 +00:00
|
|
|
// This is likely to prove that the object still exists
|
|
|
|
if (wxFindWinFromHandle((WXHWND) hwndOldFocus) == oldFocus)
|
|
|
|
oldFocus->SetFocus();
|
2000-01-30 01:31:09 +00:00
|
|
|
}
|
1998-05-20 14:12:05 +00:00
|
|
|
}
|
|
|
|
|
2000-01-30 01:31:09 +00:00
|
|
|
bool wxDialog::Show(bool show)
|
1998-05-20 14:12:05 +00:00
|
|
|
{
|
2003-09-16 12:30:34 +00:00
|
|
|
if ( !show && m_modalData )
|
2000-02-22 08:54:05 +00:00
|
|
|
{
|
2003-09-16 12:30:34 +00:00
|
|
|
// we need to do this before calling wxDialogBase version because if we
|
|
|
|
// had disabled other app windows, they must be reenabled right now as
|
2000-10-07 20:19:10 +00:00
|
|
|
// if they stay disabled Windows will activate another window (one
|
2003-09-16 12:30:34 +00:00
|
|
|
// which is enabled, anyhow) when we're hidden in the base class Show()
|
|
|
|
// and we will lose activation
|
|
|
|
m_modalData->ExitLoop();
|
2000-02-22 08:54:05 +00:00
|
|
|
}
|
|
|
|
|
2000-02-25 02:20:44 +00:00
|
|
|
// ShowModal() may be called for already shown dialog
|
|
|
|
if ( !wxDialogBase::Show(show) && !(show && IsModal()) )
|
2000-01-30 01:31:09 +00:00
|
|
|
{
|
|
|
|
// nothing to do
|
|
|
|
return FALSE;
|
|
|
|
}
|
1998-05-20 14:12:05 +00:00
|
|
|
|
2000-01-30 01:31:09 +00:00
|
|
|
if ( show )
|
|
|
|
{
|
2002-12-04 14:11:26 +00:00
|
|
|
// dialogs don't get WM_SIZE message after creation unlike most (all?)
|
|
|
|
// other windows and so could start their life non laid out correctly
|
|
|
|
// if we didn't call Layout() from here
|
|
|
|
//
|
|
|
|
// NB: normally we should call it just the first time but doing it
|
|
|
|
// every time is simpler than keeping a flag
|
|
|
|
Layout();
|
|
|
|
|
2003-09-16 12:30:34 +00:00
|
|
|
// this usually will result in TransferDataToWindow() being called
|
2000-01-30 01:31:09 +00:00
|
|
|
InitDialog();
|
|
|
|
}
|
1998-05-20 14:12:05 +00:00
|
|
|
|
2003-09-16 12:30:34 +00:00
|
|
|
if ( show && IsModal() )
|
2000-01-30 01:31:09 +00:00
|
|
|
{
|
2003-09-16 12:30:34 +00:00
|
|
|
// modal dialog needs a parent window, so try to find one
|
|
|
|
if ( !GetParent() )
|
2000-01-30 01:31:09 +00:00
|
|
|
{
|
2003-09-16 12:30:34 +00:00
|
|
|
m_parent = FindSuitableParent();
|
2000-01-30 01:31:09 +00:00
|
|
|
}
|
2003-07-09 22:03:21 +00:00
|
|
|
|
2003-09-16 12:30:34 +00:00
|
|
|
DoShowModal();
|
2000-01-30 01:31:09 +00:00
|
|
|
}
|
1998-05-20 14:12:05 +00:00
|
|
|
|
2000-01-30 01:31:09 +00:00
|
|
|
return TRUE;
|
1998-05-20 14:12:05 +00:00
|
|
|
}
|
|
|
|
|
2003-06-01 21:01:18 +00:00
|
|
|
void wxDialog::Raise()
|
|
|
|
{
|
|
|
|
::SetForegroundWindow(GetHwnd());
|
|
|
|
}
|
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
// a special version for Show(TRUE) for modal dialogs which returns return code
|
1999-05-13 21:21:04 +00:00
|
|
|
int wxDialog::ShowModal()
|
1998-05-20 14:12:05 +00:00
|
|
|
{
|
2000-07-15 19:51:35 +00:00
|
|
|
if ( !IsModal() )
|
2000-03-05 02:12:04 +00:00
|
|
|
{
|
2000-07-15 19:51:35 +00:00
|
|
|
SetModal(TRUE);
|
2000-03-05 02:12:04 +00:00
|
|
|
}
|
|
|
|
|
2000-01-30 01:31:09 +00:00
|
|
|
Show(TRUE);
|
2000-03-05 02:12:04 +00:00
|
|
|
|
2000-01-30 01:31:09 +00:00
|
|
|
return GetReturnCode();
|
1998-05-20 14:12:05 +00:00
|
|
|
}
|
|
|
|
|
2000-01-30 01:31:09 +00:00
|
|
|
// NB: this function (surprizingly) may be called for both modal and modeless
|
|
|
|
// dialogs and should work for both of them
|
1998-05-20 14:12:05 +00:00
|
|
|
void wxDialog::EndModal(int retCode)
|
|
|
|
{
|
2000-01-30 01:31:09 +00:00
|
|
|
SetReturnCode(retCode);
|
2000-02-21 09:42:31 +00:00
|
|
|
|
2000-01-30 01:31:09 +00:00
|
|
|
Show(FALSE);
|
1998-05-20 14:12:05 +00:00
|
|
|
}
|
|
|
|
|
2000-01-30 01:31:09 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxWin event handlers
|
|
|
|
// ----------------------------------------------------------------------------
|
1998-05-20 14:12:05 +00:00
|
|
|
|
|
|
|
// Standard buttons
|
2001-05-02 19:48:15 +00:00
|
|
|
void wxDialog::OnOK(wxCommandEvent& WXUNUSED(event))
|
1998-05-20 14:12:05 +00:00
|
|
|
{
|
1998-08-07 22:27:33 +00:00
|
|
|
if ( Validate() && TransferDataFromWindow() )
|
|
|
|
{
|
2000-01-30 01:31:09 +00:00
|
|
|
EndModal(wxID_OK);
|
1998-08-07 22:27:33 +00:00
|
|
|
}
|
1998-05-20 14:12:05 +00:00
|
|
|
}
|
|
|
|
|
2001-05-02 19:48:15 +00:00
|
|
|
void wxDialog::OnApply(wxCommandEvent& WXUNUSED(event))
|
1998-05-20 14:12:05 +00:00
|
|
|
{
|
2000-01-30 01:31:09 +00:00
|
|
|
if ( Validate() )
|
|
|
|
TransferDataFromWindow();
|
|
|
|
|
|
|
|
// TODO probably need to disable the Apply button until things change again
|
1998-05-20 14:12:05 +00:00
|
|
|
}
|
|
|
|
|
2001-05-02 19:48:15 +00:00
|
|
|
void wxDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
|
1998-05-20 14:12:05 +00:00
|
|
|
{
|
2000-01-30 01:31:09 +00:00
|
|
|
EndModal(wxID_CANCEL);
|
1998-05-20 14:12:05 +00:00
|
|
|
}
|
|
|
|
|
2001-05-02 19:48:15 +00:00
|
|
|
void wxDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
|
1998-05-20 14:12:05 +00:00
|
|
|
{
|
2000-01-30 01:31:09 +00:00
|
|
|
// We'll send a Cancel message by default, which may close the dialog.
|
1999-02-05 23:55:04 +00:00
|
|
|
// Check for looping if the Cancel event handler calls Close().
|
|
|
|
|
|
|
|
// Note that if a cancel button and handler aren't present in the dialog,
|
|
|
|
// nothing will happen when you close the dialog via the window manager, or
|
2000-01-30 01:31:09 +00:00
|
|
|
// via Close(). We wouldn't want to destroy the dialog by default, since
|
|
|
|
// the dialog may have been created on the stack. However, this does mean
|
|
|
|
// that calling dialog->Close() won't delete the dialog unless the handler
|
|
|
|
// for wxID_CANCEL does so. So use Destroy() if you want to be sure to
|
|
|
|
// destroy the dialog. The default OnCancel (above) simply ends a modal
|
|
|
|
// dialog, and hides a modeless dialog.
|
|
|
|
|
|
|
|
// VZ: this is horrible and MT-unsafe. Can't we reuse some of these global
|
|
|
|
// lists here? don't dare to change it now, but should be done later!
|
1998-05-20 14:12:05 +00:00
|
|
|
static wxList closing;
|
1999-04-17 20:30:28 +00:00
|
|
|
|
1998-05-20 14:12:05 +00:00
|
|
|
if ( closing.Member(this) )
|
1999-02-05 23:55:04 +00:00
|
|
|
return;
|
1999-04-17 20:30:28 +00:00
|
|
|
|
1998-05-20 14:12:05 +00:00
|
|
|
closing.Append(this);
|
1999-04-17 20:30:28 +00:00
|
|
|
|
1998-10-12 19:45:24 +00:00
|
|
|
wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
|
|
|
|
cancelEvent.SetEventObject( this );
|
1999-02-05 23:55:04 +00:00
|
|
|
GetEventHandler()->ProcessEvent(cancelEvent); // This may close the dialog
|
1998-05-20 14:12:05 +00:00
|
|
|
|
|
|
|
closing.DeleteObject(this);
|
1999-02-05 23:55:04 +00:00
|
|
|
}
|
1998-05-20 14:12:05 +00:00
|
|
|
|
2001-05-02 19:48:15 +00:00
|
|
|
void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event))
|
1998-05-20 14:12:05 +00:00
|
|
|
{
|
1999-02-02 12:37:14 +00:00
|
|
|
#if wxUSE_CTL3D
|
2000-01-30 01:31:09 +00:00
|
|
|
Ctl3dColorChange();
|
1998-05-20 14:12:05 +00:00
|
|
|
#else
|
2002-01-08 23:53:01 +00:00
|
|
|
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
|
2000-01-30 01:31:09 +00:00
|
|
|
Refresh();
|
1998-05-20 14:12:05 +00:00
|
|
|
#endif
|
1999-03-14 22:31:35 +00:00
|
|
|
}
|
1999-05-19 00:53:27 +00:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// dialog window proc
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
long wxDialog::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
|
|
|
|
{
|
|
|
|
long rc = 0;
|
|
|
|
bool processed = FALSE;
|
|
|
|
|
|
|
|
switch ( message )
|
|
|
|
{
|
|
|
|
case WM_CLOSE:
|
|
|
|
// if we can't close, tell the system that we processed the
|
|
|
|
// message - otherwise it would close us
|
|
|
|
processed = !Close();
|
|
|
|
break;
|
2000-02-25 02:20:44 +00:00
|
|
|
|
2002-04-06 22:31:07 +00:00
|
|
|
case WM_SIZE:
|
|
|
|
// the Windows dialogs unfortunately are not meant to be resizeable
|
|
|
|
// at all and their standard class doesn't include CS_[VH]REDRAW
|
|
|
|
// styles which means that the window is not refreshed properly
|
|
|
|
// after the resize and no amount of WS_CLIPCHILDREN/SIBLINGS can
|
|
|
|
// help with it - so we have to refresh it manually which certainly
|
|
|
|
// creates flicker but at least doesn't show garbage on the screen
|
|
|
|
rc = wxWindow::MSWWindowProc(message, wParam, lParam);
|
|
|
|
processed = TRUE;
|
2003-09-24 00:26:40 +00:00
|
|
|
if ( HasFlag(wxFULL_REPAINT_ON_RESIZE) )
|
2002-04-06 22:31:07 +00:00
|
|
|
{
|
2002-04-26 20:35:11 +00:00
|
|
|
::InvalidateRect(GetHwnd(), NULL, FALSE /* erase bg */);
|
2002-04-06 22:31:07 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2001-06-29 10:58:59 +00:00
|
|
|
#ifndef __WXMICROWIN__
|
2000-02-25 02:20:44 +00:00
|
|
|
case WM_SETCURSOR:
|
|
|
|
// we want to override the busy cursor for modal dialogs:
|
|
|
|
// typically, wxBeginBusyCursor() is called and then a modal dialog
|
2000-02-25 23:49:41 +00:00
|
|
|
// is shown, but the modal dialog shouldn't have hourglass cursor
|
2000-02-25 23:57:21 +00:00
|
|
|
if ( IsModalShowing() && wxIsBusy() )
|
2000-02-25 02:20:44 +00:00
|
|
|
{
|
2000-02-25 23:49:41 +00:00
|
|
|
// set our cursor for all windows (but see below)
|
|
|
|
wxCursor cursor = m_cursor;
|
|
|
|
if ( !cursor.Ok() )
|
|
|
|
cursor = wxCURSOR_ARROW;
|
2000-02-25 02:20:44 +00:00
|
|
|
|
2000-02-25 23:49:41 +00:00
|
|
|
::SetCursor(GetHcursorOf(cursor));
|
|
|
|
|
|
|
|
// in any case, stop here and don't let wxWindow process this
|
|
|
|
// message (it would set the busy cursor)
|
2000-02-25 02:20:44 +00:00
|
|
|
processed = TRUE;
|
2000-02-25 23:49:41 +00:00
|
|
|
|
|
|
|
// but return FALSE to tell the child window (if the event
|
|
|
|
// comes from one of them and not from ourselves) that it can
|
|
|
|
// set its own cursor if it has one: thus, standard controls
|
|
|
|
// (e.g. text ctrl) still have correct cursors in a dialog
|
|
|
|
// invoked while wxIsBusy()
|
|
|
|
rc = FALSE;
|
2000-02-25 02:20:44 +00:00
|
|
|
}
|
2000-02-25 23:49:41 +00:00
|
|
|
break;
|
2001-09-24 00:34:14 +00:00
|
|
|
#endif // __WXMICROWIN__
|
1999-05-19 00:53:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( !processed )
|
|
|
|
rc = wxWindow::MSWWindowProc(message, wParam, lParam);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
2000-01-30 01:31:09 +00:00
|
|
|
|
|
|
|
#if wxUSE_CTL3D
|
|
|
|
|
|
|
|
// Define for each class of dialog and control
|
|
|
|
WXHBRUSH wxDialog::OnCtlColor(WXHDC WXUNUSED(pDC),
|
|
|
|
WXHWND WXUNUSED(pWnd),
|
|
|
|
WXUINT WXUNUSED(nCtlColor),
|
|
|
|
WXUINT message,
|
|
|
|
WXWPARAM wParam,
|
|
|
|
WXLPARAM lParam)
|
|
|
|
{
|
|
|
|
return (WXHBRUSH)Ctl3dCtlColorEx(message, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // wxUSE_CTL3D
|
|
|
|
|