1. fixed toolbar deletion problem (don't leave hole any longer)

2. tried to fix modal dialog handling


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7427 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2000-05-18 23:02:49 +00:00
parent 42413911cc
commit e36ee5f7aa
3 changed files with 73 additions and 58 deletions

View File

@@ -116,8 +116,7 @@ bool wxDialog::Create(wxWindow *parent, wxWindowID id,
SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
SetName(name);
if (!parent)
wxTopLevelWindows.Append(this);
wxTopLevelWindows.Append(this);
// windowFont = wxTheFontList->FindOrCreateFont(11, wxSWISS, wxNORMAL, wxNORMAL);
@@ -324,47 +323,45 @@ bool wxDialog::IsModalShowing() const
void wxDialog::DoShowModal()
{
wxCHECK_RET( !IsModalShowing(), _T("DoShowModal() called twice") );
wxCHECK_RET( IsModal(), _T("can't DoShowModal() modeless dialog") );
wxModalDialogs.Append(this);
wxWindow *parent = GetParent();
// remember where the focus was
if ( !m_oldFocus )
// inside this block, all app windows are disabled
{
m_oldFocus = parent;
}
if ( !m_oldFocus )
{
m_oldFocus = wxTheApp->GetTopWindow();
}
wxWindowDisabler wd(this);
// disable the parent window first
HWND hwndParent = parent ? GetHwndOf(parent) : (HWND)NULL;
if ( hwndParent )
{
::EnableWindow(hwndParent, FALSE);
}
// remember where the focus was
if ( !m_oldFocus )
{
m_oldFocus = parent;
}
if ( !m_oldFocus )
{
m_oldFocus = wxTheApp->GetTopWindow();
}
// enter the modal loop
while ( IsModalShowing() )
{
// enter the modal loop
while ( IsModalShowing() )
{
#if wxUSE_THREADS
wxMutexGuiLeaveOrEnter();
wxMutexGuiLeaveOrEnter();
#endif // wxUSE_THREADS
while ( !wxTheApp->Pending() && wxTheApp->ProcessIdle() )
;
while ( !wxTheApp->Pending() && wxTheApp->ProcessIdle() )
;
// a message came or no more idle processing to do
wxTheApp->DoMessage();
// a message came or no more idle processing to do
wxTheApp->DoMessage();
}
}
// reenable the parent window if any
if ( hwndParent )
{
::EnableWindow(hwndParent, TRUE);
}
#ifdef __WIN32__
if ( parent )
::SetActiveWindow(GetHwndOf(parent));
#endif // __WIN32__
// and restore focus
if ( m_oldFocus && (m_oldFocus != this) )
@@ -405,6 +402,17 @@ bool wxDialog::Show(bool show)
{
if ( show )
{
// modal dialog needs a parent window, so try to find one
if ( !GetParent() )
{
wxWindow *parent = wxTheApp->GetTopWindow();
if ( parent && parent != this )
{
// use it
m_parent = parent;
}
}
DoShowModal();
}
else // end of modal dialog
@@ -418,32 +426,16 @@ bool wxDialog::Show(bool show)
return TRUE;
}
// Replacement for Show(TRUE) for modal dialogs - returns return code
// a special version for Show(TRUE) for modal dialogs which returns return code
int wxDialog::ShowModal()
{
// modal dialog needs a parent window, so try to find one
if ( !GetParent() )
if ( !IsModal() )
{
wxWindow *parent = wxTheApp->GetTopWindow();
if ( parent && parent != this )
{
// use it
m_parent = parent;
}
SetModal(TRUE);
}
wxWindowDisabler *wd = (wxWindowDisabler *)NULL;
if ( !GetParent() )
{
// still no parent? make the dialog app modal by disabling all windows
wd = new wxWindowDisabler(this);
}
m_windowStyle |= wxDIALOG_MODAL;
Show(TRUE);
delete wd;
return GetReturnCode();
}

View File

@@ -163,6 +163,9 @@ wxFrame::~wxFrame()
m_isBeingDeleted = TRUE;
wxTopLevelWindows.DeleteObject(this);
// the ~wxToolBar() code relies on the previous line to be executed before
// this one, i.e. the frame should remove itself from wxTopLevelWindows
// before destorying its toolbar
DeleteAllBars();
if (wxTheApp && (wxTopLevelWindows.Number() == 0))

View File

@@ -108,6 +108,10 @@
// private function prototypes
// ----------------------------------------------------------------------------
// send a dummy WM_SIZE to the given window: this is used to relayout the frame
// which contains us
static void SendResizeMessage(HWND hwnd);
static void wxMapBitmap(HBITMAP hBitmap, int width, int height);
// ----------------------------------------------------------------------------
@@ -258,7 +262,18 @@ bool wxToolBar::Create(wxWindow *parent,
wxToolBar::~wxToolBar()
{
if (m_hBitmap)
// we must refresh the frame size when the toolbar is deleted but the frame
// is not - otherwise toolbar leaves a hole in the place it used to occupy
//
// NB: a frame is being deleted only if it is not any longer in
// wxTopLevelWindows list
wxFrame *frame = wxDynamicCast(GetParent(), wxFrame);
if ( frame && wxTopLevelWindows.Find(frame) )
{
SendResizeMessage(GetHwndOf(frame));
}
if ( m_hBitmap )
{
::DeleteObject((HBITMAP) m_hBitmap);
}
@@ -880,15 +895,7 @@ void wxToolBar::UpdateSize()
wxFrame *frame = wxDynamicCast(GetParent(), wxFrame);
if ( frame )
{
// don't change the size, we just need to generate a WM_SIZE
RECT r;
if ( !GetWindowRect(GetHwndOf(frame), &r) )
{
wxLogLastError(_T("GetWindowRect"));
}
(void)::SendMessage(GetHwndOf(frame), WM_SIZE, SIZE_RESTORED,
MAKELPARAM(r.right - r.left, r.bottom - r.top));
SendResizeMessage(GetHwndOf(frame));
}
}
@@ -998,6 +1005,19 @@ long wxToolBar::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
// private functions
// ----------------------------------------------------------------------------
static void SendResizeMessage(HWND hwnd)
{
// don't change the size, we just need to generate a WM_SIZE
RECT r;
if ( !::GetWindowRect(hwnd, &r) )
{
wxLogLastError(_T("GetWindowRect"));
}
(void)::PostMessage(hwnd, WM_SIZE, SIZE_RESTORED,
MAKELPARAM(r.right - r.left, r.bottom - r.top));
}
// These are the default colors used to map the bitmap colors to the current
// system colors. Note that they are in BGR format because this is what Windows
// wants (and not RGB)