toplevel fixes

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11746 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2001-09-30 17:34:51 +00:00
parent 752b40b1da
commit a15eb0a5c8
8 changed files with 365 additions and 219 deletions

View File

@@ -64,7 +64,7 @@ public:
~wxDialog();
virtual bool Destroy();
// virtual bool Destroy();
bool Show(bool show);
void SetModal(bool flag);
@@ -87,7 +87,7 @@ public:
// --------------
// event handlers
bool OnClose();
// bool OnClose();
void OnCharHook(wxKeyEvent& event);
void OnCloseWindow(wxCloseEvent& event);
@@ -99,10 +99,6 @@ public:
// Responds to colour changes
void OnSysColourChanged(wxSysColourChangedEvent& event);
// override more base class virtuals
virtual void DoGetPosition(int *x, int *y) const;
virtual void DoSetClientSize(int width, int height);
// show modal dialog and enter modal loop
void DoShowModal();

View File

@@ -28,15 +28,17 @@ wxList wxModalDialogs;
extern wxList wxPendingDelete;
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxPanel)
IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow)
BEGIN_EVENT_TABLE(wxDialog, wxPanel)
EVT_SIZE(wxDialog::OnSize)
BEGIN_EVENT_TABLE(wxDialog, wxTopLevelWindow)
EVT_BUTTON(wxID_OK, wxDialog::OnOK)
EVT_BUTTON(wxID_APPLY, wxDialog::OnApply)
EVT_BUTTON(wxID_CANCEL, wxDialog::OnCancel)
EVT_CHAR_HOOK(wxDialog::OnCharHook)
EVT_SYS_COLOUR_CHANGED(wxDialog::OnSysColourChanged)
EVT_CLOSE(wxDialog::OnCloseWindow)
END_EVENT_TABLE()
@@ -58,15 +60,9 @@ bool wxDialog::Create(wxWindow *parent, wxWindowID id,
SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
if (!parent)
wxTopLevelWindows.Append(this);
if (parent) parent->AddChild(this);
if ( id == -1 )
m_windowId = (int)NewControlId();
else
m_windowId = id;
if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
return FALSE;
MacCreateRealWindow( title , pos , size , MacRemoveBordersFromStyle(style) , name ) ;
@@ -93,29 +89,16 @@ void wxDialog::SetModal(bool flag)
wxDialog::~wxDialog()
{
m_isBeingDeleted = TRUE ;
wxTopLevelWindows.DeleteObject(this);
Show(FALSE);
if ( !IsModal() )
wxModelessWindows.DeleteObject(this);
// If this is the last top-level window, exit.
if (wxTheApp && (wxTopLevelWindows.Number() == 0))
{
wxTheApp->SetTopWindow(NULL);
if (wxTheApp->GetExitOnFrameDelete())
{
wxTheApp->ExitMainLoop() ;
}
}
}
// By default, pressing escape cancels the dialog
// By default, pressing escape cancels the dialog , on mac command-stop does the same thing
void wxDialog::OnCharHook(wxKeyEvent& event)
{
if (event.m_keyCode == WXK_ESCAPE)
if (
( event.m_keyCode == WXK_ESCAPE ||
( event.m_keyCode == '.' && event.MetaDown() ) )
&& FindWindow(wxID_CANCEL) )
{
// Behaviour changed in 2.0: we'll send a Cancel message
// to the dialog instead of Close.
@@ -129,17 +112,6 @@ void wxDialog::OnCharHook(wxKeyEvent& event)
event.Skip();
}
void wxDialog::DoSetClientSize(int width, int height)
{
wxWindow::DoSetClientSize( width , height ) ;
}
void wxDialog::DoGetPosition(int *x, int *y) const
{
wxWindow::DoGetPosition( x , y ) ;
}
bool wxDialog::IsModal() const
{
return (GetWindowStyleFlag() & wxDIALOG_MODAL) != 0;
@@ -151,7 +123,6 @@ bool wxDialog::IsModalShowing() const
return wxModalDialogs.Find((wxDialog *)this) != NULL; // const_cast
}
extern bool s_macIsInModalLoop ;
bool wxDialog::Show(bool show)
@@ -295,16 +266,6 @@ void wxDialog::OnCloseWindow(wxCloseEvent& event)
closing.DeleteObject(this);
}
// Destroy the window (delayed, if a managed window)
bool wxDialog::Destroy()
{
wxCHECK_MSG( !wxPendingDelete.Member(this), FALSE,
_T("wxDialog destroyed twice") );
wxPendingDelete.Append(this);
return TRUE;
}
void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& event)
{
SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));

View File

@@ -30,7 +30,6 @@ extern wxList wxPendingDelete;
#if !USE_SHARED_LIBRARY
BEGIN_EVENT_TABLE(wxFrameMac, wxFrameBase)
// EVT_SIZE(wxFrameMac::OnSize)
EVT_ACTIVATE(wxFrameMac::OnActivate)
// EVT_MENU_HIGHLIGHT_ALL(wxFrameMac::OnMenuHighlight)
EVT_SYS_COLOUR_CHANGED(wxFrameMac::OnSysColourChanged)
@@ -107,15 +106,8 @@ bool wxFrameMac::Create(wxWindow *parent,
{
SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
if ( id > -1 )
m_windowId = id;
else
m_windowId = (int)NewControlId();
if (parent) parent->AddChild(this);
if (!parent)
wxTopLevelWindows.Append(this);
if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
return FALSE;
MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ;
@@ -129,23 +121,9 @@ bool wxFrameMac::Create(wxWindow *parent,
wxFrameMac::~wxFrameMac()
{
m_isBeingDeleted = TRUE;
wxTopLevelWindows.DeleteObject(this);
DeleteAllBars();
/* Check if it's the last top-level window */
if (wxTheApp && (wxTopLevelWindows.Number() == 0))
{
wxTheApp->SetTopWindow(NULL);
if (wxTheApp->GetExitOnFrameDelete())
{
wxTheApp->ExitMainLoop() ;
}
}
wxModelessWindows.DeleteObject(this);
}
@@ -216,46 +194,39 @@ void wxFrameMac::OnActivate(wxActivateEvent& event)
{
if ( !event.GetActive() )
{
// remember the last focused child
// remember the last focused child if it is our child
m_winLastFocused = FindFocus();
while ( m_winLastFocused )
{
if ( GetChildren().Find(m_winLastFocused) )
break;
m_winLastFocused = m_winLastFocused->GetParent();
// so we NULL it out if it's a child from some other frame
wxWindow *win = m_winLastFocused;
while ( win )
{
if ( win->IsTopLevel() )
{
if ( win != this )
{
m_winLastFocused = NULL;
}
break;
}
win = win->GetParent();
}
event.Skip();
}
else
{
/*
for ( wxWindowList::Node *node = GetChildren().GetFirst();
node;
node = node->GetNext() )
// restore focus to the child which was last focused
wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent()
: NULL;
if ( !parent )
{
// FIXME all this is totally bogus - we need to do the same as wxPanel,
// but how to do it without duplicating the code?
// restore focus
wxWindow *child = node->GetData();
if ( !child->IsTopLevel() && child->AcceptsFocus()
#if wxUSE_TOOLBAR
&& !wxDynamicCast(child, wxToolBar)
#endif // wxUSE_TOOLBAR
#if wxUSE_STATUSBAR
&& !wxDynamicCast(child, wxStatusBar)
#endif // wxUSE_STATUSBAR
)
{
child->SetFocus();
break;
parent = this;
}
}
*/
wxSetFocusToChild(this, &m_winLastFocused);
wxSetFocusToChild(parent, &m_winLastFocused);
if ( m_frameMenuBar != NULL )
{

143
src/mac/carbon/toplevel.cpp Normal file
View File

@@ -0,0 +1,143 @@
///////////////////////////////////////////////////////////////////////////////
// Name: mac/toplevel.cpp
// Purpose: implements wxTopLevelWindow for MSW
// Author: Vadim Zeitlin
// Modified by:
// Created: 24.09.01
// RCS-ID: $Id$
// Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
// License: wxWindows license
///////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#ifdef __GNUG__
#pragma implementation "toplevel.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/app.h"
#include "wx/toplevel.h"
#include "wx/string.h"
#include "wx/log.h"
#include "wx/intl.h"
#endif //WX_PRECOMP
// ----------------------------------------------------------------------------
// globals
// ----------------------------------------------------------------------------
// list of all frames and modeless dialogs
wxWindowList wxModelessWindows;
// ============================================================================
// wxTopLevelWindowMac implementation
// ============================================================================
// ----------------------------------------------------------------------------
// wxTopLevelWindowMac creation
// ----------------------------------------------------------------------------
void wxTopLevelWindowMac::Init()
{
m_iconized =
m_maximizeOnShow = FALSE;
}
bool wxTopLevelWindowMac::Create(wxWindow *parent,
wxWindowID id,
const wxString& title,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
{
// init our fields
Init();
m_windowStyle = style;
SetName(name);
m_windowId = id == -1 ? NewControlId() : id;
wxTopLevelWindows.Append(this);
if ( parent )
parent->AddChild(this);
return TRUE;
}
wxTopLevelWindowMac::~wxTopLevelWindowMac()
{
wxTopLevelWindows.DeleteObject(this);
if ( wxModelessWindows.Find(this) )
wxModelessWindows.DeleteObject(this);
// If this is the last top-level window, exit.
if ( wxTheApp && (wxTopLevelWindows.Number() == 0) )
{
wxTheApp->SetTopWindow(NULL);
if ( wxTheApp->GetExitOnFrameDelete() )
{
wxTheApp->ExitMainLoop() ;
}
}
}
// ----------------------------------------------------------------------------
// wxTopLevelWindowMac maximize/minimize
// ----------------------------------------------------------------------------
void wxTopLevelWindowMac::Maximize(bool maximize)
{
// not available on mac
}
bool wxTopLevelWindowMac::IsMaximized() const
{
return false ;
}
void wxTopLevelWindowMac::Iconize(bool iconize)
{
// not available on mac
}
bool wxTopLevelWindowMac::IsIconized() const
{
// mac dialogs cannot be iconized
return FALSE;
}
void wxTopLevelWindowMac::Restore()
{
// not available on mac
}
// ----------------------------------------------------------------------------
// wxTopLevelWindowMac misc
// ----------------------------------------------------------------------------
void wxTopLevelWindowMac::SetIcon(const wxIcon& icon)
{
// this sets m_icon
wxTopLevelWindowBase::SetIcon(icon);
}

View File

@@ -28,15 +28,17 @@ wxList wxModalDialogs;
extern wxList wxPendingDelete;
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxPanel)
IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow)
BEGIN_EVENT_TABLE(wxDialog, wxPanel)
EVT_SIZE(wxDialog::OnSize)
BEGIN_EVENT_TABLE(wxDialog, wxTopLevelWindow)
EVT_BUTTON(wxID_OK, wxDialog::OnOK)
EVT_BUTTON(wxID_APPLY, wxDialog::OnApply)
EVT_BUTTON(wxID_CANCEL, wxDialog::OnCancel)
EVT_CHAR_HOOK(wxDialog::OnCharHook)
EVT_SYS_COLOUR_CHANGED(wxDialog::OnSysColourChanged)
EVT_CLOSE(wxDialog::OnCloseWindow)
END_EVENT_TABLE()
@@ -58,15 +60,9 @@ bool wxDialog::Create(wxWindow *parent, wxWindowID id,
SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
if (!parent)
wxTopLevelWindows.Append(this);
if (parent) parent->AddChild(this);
if ( id == -1 )
m_windowId = (int)NewControlId();
else
m_windowId = id;
if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
return FALSE;
MacCreateRealWindow( title , pos , size , MacRemoveBordersFromStyle(style) , name ) ;
@@ -93,29 +89,16 @@ void wxDialog::SetModal(bool flag)
wxDialog::~wxDialog()
{
m_isBeingDeleted = TRUE ;
wxTopLevelWindows.DeleteObject(this);
Show(FALSE);
if ( !IsModal() )
wxModelessWindows.DeleteObject(this);
// If this is the last top-level window, exit.
if (wxTheApp && (wxTopLevelWindows.Number() == 0))
{
wxTheApp->SetTopWindow(NULL);
if (wxTheApp->GetExitOnFrameDelete())
{
wxTheApp->ExitMainLoop() ;
}
}
}
// By default, pressing escape cancels the dialog
// By default, pressing escape cancels the dialog , on mac command-stop does the same thing
void wxDialog::OnCharHook(wxKeyEvent& event)
{
if (event.m_keyCode == WXK_ESCAPE)
if (
( event.m_keyCode == WXK_ESCAPE ||
( event.m_keyCode == '.' && event.MetaDown() ) )
&& FindWindow(wxID_CANCEL) )
{
// Behaviour changed in 2.0: we'll send a Cancel message
// to the dialog instead of Close.
@@ -129,17 +112,6 @@ void wxDialog::OnCharHook(wxKeyEvent& event)
event.Skip();
}
void wxDialog::DoSetClientSize(int width, int height)
{
wxWindow::DoSetClientSize( width , height ) ;
}
void wxDialog::DoGetPosition(int *x, int *y) const
{
wxWindow::DoGetPosition( x , y ) ;
}
bool wxDialog::IsModal() const
{
return (GetWindowStyleFlag() & wxDIALOG_MODAL) != 0;
@@ -151,7 +123,6 @@ bool wxDialog::IsModalShowing() const
return wxModalDialogs.Find((wxDialog *)this) != NULL; // const_cast
}
extern bool s_macIsInModalLoop ;
bool wxDialog::Show(bool show)
@@ -295,16 +266,6 @@ void wxDialog::OnCloseWindow(wxCloseEvent& event)
closing.DeleteObject(this);
}
// Destroy the window (delayed, if a managed window)
bool wxDialog::Destroy()
{
wxCHECK_MSG( !wxPendingDelete.Member(this), FALSE,
_T("wxDialog destroyed twice") );
wxPendingDelete.Append(this);
return TRUE;
}
void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& event)
{
SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));

View File

@@ -30,7 +30,6 @@ extern wxList wxPendingDelete;
#if !USE_SHARED_LIBRARY
BEGIN_EVENT_TABLE(wxFrameMac, wxFrameBase)
// EVT_SIZE(wxFrameMac::OnSize)
EVT_ACTIVATE(wxFrameMac::OnActivate)
// EVT_MENU_HIGHLIGHT_ALL(wxFrameMac::OnMenuHighlight)
EVT_SYS_COLOUR_CHANGED(wxFrameMac::OnSysColourChanged)
@@ -107,15 +106,8 @@ bool wxFrameMac::Create(wxWindow *parent,
{
SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
if ( id > -1 )
m_windowId = id;
else
m_windowId = (int)NewControlId();
if (parent) parent->AddChild(this);
if (!parent)
wxTopLevelWindows.Append(this);
if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
return FALSE;
MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ;
@@ -129,23 +121,9 @@ bool wxFrameMac::Create(wxWindow *parent,
wxFrameMac::~wxFrameMac()
{
m_isBeingDeleted = TRUE;
wxTopLevelWindows.DeleteObject(this);
DeleteAllBars();
/* Check if it's the last top-level window */
if (wxTheApp && (wxTopLevelWindows.Number() == 0))
{
wxTheApp->SetTopWindow(NULL);
if (wxTheApp->GetExitOnFrameDelete())
{
wxTheApp->ExitMainLoop() ;
}
}
wxModelessWindows.DeleteObject(this);
}
@@ -216,46 +194,39 @@ void wxFrameMac::OnActivate(wxActivateEvent& event)
{
if ( !event.GetActive() )
{
// remember the last focused child
// remember the last focused child if it is our child
m_winLastFocused = FindFocus();
while ( m_winLastFocused )
{
if ( GetChildren().Find(m_winLastFocused) )
break;
m_winLastFocused = m_winLastFocused->GetParent();
// so we NULL it out if it's a child from some other frame
wxWindow *win = m_winLastFocused;
while ( win )
{
if ( win->IsTopLevel() )
{
if ( win != this )
{
m_winLastFocused = NULL;
}
break;
}
win = win->GetParent();
}
event.Skip();
}
else
{
/*
for ( wxWindowList::Node *node = GetChildren().GetFirst();
node;
node = node->GetNext() )
// restore focus to the child which was last focused
wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent()
: NULL;
if ( !parent )
{
// FIXME all this is totally bogus - we need to do the same as wxPanel,
// but how to do it without duplicating the code?
// restore focus
wxWindow *child = node->GetData();
if ( !child->IsTopLevel() && child->AcceptsFocus()
#if wxUSE_TOOLBAR
&& !wxDynamicCast(child, wxToolBar)
#endif // wxUSE_TOOLBAR
#if wxUSE_STATUSBAR
&& !wxDynamicCast(child, wxStatusBar)
#endif // wxUSE_STATUSBAR
)
{
child->SetFocus();
break;
parent = this;
}
}
*/
wxSetFocusToChild(this, &m_winLastFocused);
wxSetFocusToChild(parent, &m_winLastFocused);
if ( m_frameMenuBar != NULL )
{

View File

@@ -235,7 +235,7 @@ pascal OSErr GetVolumeInfoNoName(ConstStr255Param pathname,
** to the local tempPathname).
*/
#if !TARGET_CARBON
#if TARGET_CARBON
pascal OSErr XGetVolumeInfoNoName(ConstStr255Param pathname,
short vRefNum,

143
src/mac/toplevel.cpp Normal file
View File

@@ -0,0 +1,143 @@
///////////////////////////////////////////////////////////////////////////////
// Name: mac/toplevel.cpp
// Purpose: implements wxTopLevelWindow for MSW
// Author: Vadim Zeitlin
// Modified by:
// Created: 24.09.01
// RCS-ID: $Id$
// Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
// License: wxWindows license
///////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#ifdef __GNUG__
#pragma implementation "toplevel.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/app.h"
#include "wx/toplevel.h"
#include "wx/string.h"
#include "wx/log.h"
#include "wx/intl.h"
#endif //WX_PRECOMP
// ----------------------------------------------------------------------------
// globals
// ----------------------------------------------------------------------------
// list of all frames and modeless dialogs
wxWindowList wxModelessWindows;
// ============================================================================
// wxTopLevelWindowMac implementation
// ============================================================================
// ----------------------------------------------------------------------------
// wxTopLevelWindowMac creation
// ----------------------------------------------------------------------------
void wxTopLevelWindowMac::Init()
{
m_iconized =
m_maximizeOnShow = FALSE;
}
bool wxTopLevelWindowMac::Create(wxWindow *parent,
wxWindowID id,
const wxString& title,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
{
// init our fields
Init();
m_windowStyle = style;
SetName(name);
m_windowId = id == -1 ? NewControlId() : id;
wxTopLevelWindows.Append(this);
if ( parent )
parent->AddChild(this);
return TRUE;
}
wxTopLevelWindowMac::~wxTopLevelWindowMac()
{
wxTopLevelWindows.DeleteObject(this);
if ( wxModelessWindows.Find(this) )
wxModelessWindows.DeleteObject(this);
// If this is the last top-level window, exit.
if ( wxTheApp && (wxTopLevelWindows.Number() == 0) )
{
wxTheApp->SetTopWindow(NULL);
if ( wxTheApp->GetExitOnFrameDelete() )
{
wxTheApp->ExitMainLoop() ;
}
}
}
// ----------------------------------------------------------------------------
// wxTopLevelWindowMac maximize/minimize
// ----------------------------------------------------------------------------
void wxTopLevelWindowMac::Maximize(bool maximize)
{
// not available on mac
}
bool wxTopLevelWindowMac::IsMaximized() const
{
return false ;
}
void wxTopLevelWindowMac::Iconize(bool iconize)
{
// not available on mac
}
bool wxTopLevelWindowMac::IsIconized() const
{
// mac dialogs cannot be iconized
return FALSE;
}
void wxTopLevelWindowMac::Restore()
{
// not available on mac
}
// ----------------------------------------------------------------------------
// wxTopLevelWindowMac misc
// ----------------------------------------------------------------------------
void wxTopLevelWindowMac::SetIcon(const wxIcon& icon)
{
// this sets m_icon
wxTopLevelWindowBase::SetIcon(icon);
}