1. wxProgressDialog uses wxWindowDisabler, not (dumb) wxEnableTopLevelWindows

2. some more wxWindowDisabler bugs fixed (updated dialogs sample to test them)
3. Esc won't close the dialogs without cancel button under MSW
4. status bar can be child of windows of clases other than wxFrame
   (updated statbar sample to show it)


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6630 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2000-03-12 00:26:21 +00:00
parent 5028104652
commit cbc66a2704
10 changed files with 128 additions and 90 deletions

View File

@@ -97,11 +97,16 @@ private:
Continue, // can be cancelled but wasn't Continue, // can be cancelled but wasn't
Finished // finished, waiting to be removed from screen Finished // finished, waiting to be removed from screen
} m_state; } m_state;
// the abort button (or NULL if none) // the abort button (or NULL if none)
wxButton *m_btnAbort; wxButton *m_btnAbort;
// the maximum value // the maximum value
int m_maximum; int m_maximum;
// for wxPD_APP_MODAL case
class WXDLLEXPORT wxWindowDisabler *m_winDisabler;
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
#endif #endif

View File

@@ -58,14 +58,14 @@ public:
virtual int GetBorderX() const; virtual int GetBorderX() const;
virtual int GetBorderY() const; virtual int GetBorderY() const;
void OnSize(wxSizeEvent& event);
protected: protected:
void CopyFieldsWidth(const int widths[]); void CopyFieldsWidth(const int widths[]);
void SetFieldsWidth(); void SetFieldsWidth();
// override base class virtual
void DoMoveWindow(int x, int y, int width, int height);
private: private:
DECLARE_EVENT_TABLE()
DECLARE_DYNAMIC_CLASS(wxStatusBar95); DECLARE_DYNAMIC_CLASS(wxStatusBar95);
}; };

View File

@@ -537,9 +537,20 @@ void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) )
MyModelessDialog::MyModelessDialog(wxWindow *parent) MyModelessDialog::MyModelessDialog(wxWindow *parent)
: wxDialog(parent, -1, wxString("Modeless dialog")) : wxDialog(parent, -1, wxString("Modeless dialog"))
{ {
(void)new wxButton(this, DIALOGS_MODELESS_BTN, "Press me"); wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
Fit();
Centre(); wxButton *btn = new wxButton(this, DIALOGS_MODELESS_BTN, "Press me");
wxCheckBox *check = new wxCheckBox(this, -1, "Should be disabled");
check->Disable();
sizerTop->Add(btn, 1, wxEXPAND | wxALL, 5);
sizerTop->Add(check, 1, wxEXPAND | wxALL, 5);
SetAutoLayout(TRUE);
SetSizer(sizerTop);
sizerTop->SetSizeHints(this);
sizerTop->Fit(this);
} }
void MyModelessDialog::OnClose(wxCloseEvent& event) void MyModelessDialog::OnClose(wxCloseEvent& event)

View File

@@ -33,8 +33,7 @@
#error "You need to set wxUSE_STATUSBAR to 1 to compile this sample" #error "You need to set wxUSE_STATUSBAR to 1 to compile this sample"
#endif // wxUSE_STATUSBAR #endif // wxUSE_STATUSBAR
// for all others, include the necessary headers (this file is usually all you // for all others, include the necessary headers
// need because it includes almost all "standard" wxWindows headers
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/app.h" #include "wx/app.h"
#include "wx/frame.h" #include "wx/frame.h"
@@ -45,6 +44,7 @@
#include "wx/menu.h" #include "wx/menu.h"
#include "wx/msgdlg.h" #include "wx/msgdlg.h"
#include "wx/textdlg.h" #include "wx/textdlg.h"
#include "wx/sizer.h"
#endif #endif
#include "wx/datetime.h" #include "wx/datetime.h"
@@ -137,6 +137,13 @@ private:
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
// Our about dialog ith its status bar
class MyAboutDialog : public wxDialog
{
public:
MyAboutDialog(wxWindow *parent);
};
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// constants // constants
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -346,8 +353,39 @@ void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{ {
wxMessageBox("wxStatusBar sample\n(c) 2000 Vadim Zeitlin", MyAboutDialog dlg(this);
"About statbar", wxOK | wxICON_INFORMATION, this); dlg.ShowModal();
}
// ----------------------------------------------------------------------------
// MyAboutDialog
// ----------------------------------------------------------------------------
MyAboutDialog::MyAboutDialog(wxWindow *parent)
: wxDialog(parent, -1, wxString("About statbar"),
wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
{
wxStaticText *text = new wxStaticText(this, -1,
"wxStatusBar sample\n"
"(c) 2000 Vadim Zeitlin");
wxStatusBar *statbar = new wxStatusBar(this, -1);
statbar->SetFieldsCount(2);
statbar->SetStatusText("This is a status bar", 0);
statbar->SetStatusText("in a dialog", 1);
wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
sizerTop->Add(-1, 10, 1, wxGROW);
sizerTop->Add(text, 0, wxCENTRE);
sizerTop->Add(-1, 10, 1, wxGROW);
sizerTop->Add(statbar, 0, wxGROW);
SetAutoLayout(TRUE);
SetSizer(sizerTop);
sizerTop->Fit(this);
sizerTop->SetSizeHints(this);
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -952,7 +952,7 @@ int isascii( int c )
#endif // __MWERKS__ #endif // __MWERKS__
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// misc functions // wxSafeYield and supporting functions
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void wxEnableTopLevelWindows(bool enable) void wxEnableTopLevelWindows(bool enable)
@@ -962,13 +962,18 @@ void wxEnableTopLevelWindows(bool enable)
node->GetData()->Enable(enable); node->GetData()->Enable(enable);
} }
static void wxFindDisabledWindows(wxWindowList& winDisabled, wxWindow *win) static void wxFindDisabledWindows(wxWindowList& winDisabled,
wxWindow *win,
wxWindow *winToSkip)
{ {
wxWindowList::Node *node; wxWindowList::Node *node;
for ( node = win->GetChildren().GetFirst(); node; node = node->GetNext() ) for ( node = win->GetChildren().GetFirst(); node; node = node->GetNext() )
{ {
wxWindow *child = node->GetData(); wxWindow *child = node->GetData();
wxFindDisabledWindows(winDisabled, child); if ( child == winToSkip )
continue;
wxFindDisabledWindows(winDisabled, child, winToSkip);
if ( child->IsEnabled() ) if ( child->IsEnabled() )
{ {
@@ -998,21 +1003,14 @@ wxWindowDisabler::wxWindowDisabler(wxWindow *winToSkip)
for ( node = wxTopLevelWindows.GetFirst(); node; node = node->GetNext() ) for ( node = wxTopLevelWindows.GetFirst(); node; node = node->GetNext() )
{ {
wxWindow *winTop = node->GetData(); wxWindow *winTop = node->GetData();
if ( winTop->IsEnabled() ) if ( winTop != winToSkip && winTop->IsEnabled() )
{ {
wxFindDisabledWindows(*m_winDisabled, winTop); wxFindDisabledWindows(*m_winDisabled, winTop, winToSkip);
m_winDisabled->Append(winTop); m_winDisabled->Append(winTop);
winTop->Disable(); winTop->Disable();
} }
} }
if ( winToSkip && m_winDisabled->Find(winToSkip) )
{
// always enable ourselves
m_winDisabled->DeleteObject(winToSkip);
winToSkip->Enable();
}
} }
wxWindowDisabler::~wxWindowDisabler() wxWindowDisabler::~wxWindowDisabler()
@@ -1060,6 +1058,10 @@ bool wxSafeYield(wxWindow *win)
return rc; return rc;
} }
// ----------------------------------------------------------------------------
// misc functions
// ----------------------------------------------------------------------------
// Don't synthesize KeyUp events holding down a key and producing KeyDown // Don't synthesize KeyUp events holding down a key and producing KeyDown
// events with autorepeat. On by default and always on in wxMSW. wxGTK version // events with autorepeat. On by default and always on in wxMSW. wxGTK version
// in utilsgtk.cpp. // in utilsgtk.cpp.

View File

@@ -103,14 +103,7 @@ wxProgressDialog::wxProgressDialog(wxString const &title,
wxClientDC dc(this); wxClientDC dc(this);
dc.SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT)); dc.SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
long widthText; long widthText;
#if defined(__VISAGECPP__)
// have two versions of this in wxWindowDC tp avoid function hiding
// since there are two of these in wxDCBase, and in turn in wxDC.
// VA cannot resolve this so:
dc.GetTextExtent(message, &widthText, NULL, NULL, NULL, NULL); dc.GetTextExtent(message, &widthText, NULL, NULL, NULL, NULL);
#else
dc.GetTextExtent(message, &widthText, (long*)NULL);
#endif
m_msg = new wxStaticText(this, -1, message); m_msg = new wxStaticText(this, -1, message);
c = new wxLayoutConstraints; c = new wxLayoutConstraints;
@@ -218,14 +211,15 @@ wxProgressDialog::wxProgressDialog(wxString const &title,
Centre(wxCENTER_FRAME | wxBOTH); Centre(wxCENTER_FRAME | wxBOTH);
if ( !(style & wxPD_APP_MODAL) ) if ( style & wxPD_APP_MODAL )
{ {
if ( m_parentTop ) m_winDisabler = new wxWindowDisabler(this);
m_parentTop->Enable(FALSE);
} }
else else
{ {
wxEnableTopLevelWindows(FALSE); if ( m_parentTop )
m_parentTop->Enable(FALSE);
m_winDisabler = NULL;
} }
Show(TRUE); Show(TRUE);
@@ -389,14 +383,14 @@ void wxProgressDialog::OnClose(wxCloseEvent& event)
wxProgressDialog::~wxProgressDialog() wxProgressDialog::~wxProgressDialog()
{ {
if ( !(GetWindowStyle() & wxPD_APP_MODAL) ) if ( GetWindowStyle() & wxPD_APP_MODAL )
{ {
if ( m_parentTop ) delete m_winDisabler;
m_parentTop->Enable(TRUE);
} }
else else
{ {
wxEnableTopLevelWindows(TRUE); if ( m_parentTop )
m_parentTop->Enable(TRUE);
} }
} }

View File

@@ -237,10 +237,10 @@ void wxDialog::OnCharHook(wxKeyEvent& event)
{ {
if (GetHWND()) if (GetHWND())
{ {
if (event.m_keyCode == WXK_ESCAPE) // "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) )
{ {
// Behaviour changed in 2.0: we'll send a Cancel message
// to the dialog instead of Close.
wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
cancelEvent.SetEventObject( this ); cancelEvent.SetEventObject( this );
GetEventHandler()->ProcessEvent(cancelEvent); GetEventHandler()->ProcessEvent(cancelEvent);
@@ -248,9 +248,11 @@ void wxDialog::OnCharHook(wxKeyEvent& event)
// ensure that there is another message for this window so the // ensure that there is another message for this window so the
// ShowModal loop will exit and won't get stuck in GetMessage(). // ShowModal loop will exit and won't get stuck in GetMessage().
::PostMessage(GetHwnd(), WM_NULL, 0, 0); ::PostMessage(GetHwnd(), WM_NULL, 0, 0);
return; return;
} }
} }
// We didn't process this event. // We didn't process this event.
event.Skip(); event.Skip();
} }

View File

@@ -393,20 +393,6 @@ void wxFrame::PositionStatusBar()
if ( !m_frameStatusBar ) if ( !m_frameStatusBar )
return; return;
// native status bar positions itself, but we must forward the WM_SIZE
// messages to it
#if wxUSE_NATIVE_STATUSBAR
wxStatusBar95 *sb = wxDynamicCast(m_frameStatusBar, wxStatusBar95);
if ( sb )
{
wxSizeEvent event(GetSize(), sb->GetId());
event.SetEventObject(sb);
sb->GetEventHandler()->ProcessEvent(event);
}
else
#endif // wxUSE_NATIVE_STATUSBAR
{
int w, h; int w, h;
GetClientSize(&w, &h); GetClientSize(&w, &h);
int sw, sh; int sw, sh;
@@ -416,7 +402,6 @@ void wxFrame::PositionStatusBar()
// we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
m_frameStatusBar->SetSize(0, h, w, sh); m_frameStatusBar->SetSize(0, h, w, sh);
} }
}
#endif // wxUSE_STATUSBAR #endif // wxUSE_STATUSBAR
void wxFrame::DetachMenuBar() void wxFrame::DetachMenuBar()

View File

@@ -47,10 +47,6 @@
IMPLEMENT_DYNAMIC_CLASS(wxStatusBar95, wxWindow); IMPLEMENT_DYNAMIC_CLASS(wxStatusBar95, wxWindow);
IMPLEMENT_DYNAMIC_CLASS(wxStatusBar, wxStatusBar95) IMPLEMENT_DYNAMIC_CLASS(wxStatusBar, wxStatusBar95)
BEGIN_EVENT_TABLE(wxStatusBar95, wxWindow)
EVT_SIZE(wxStatusBar95::OnSize)
END_EVENT_TABLE()
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// macros // macros
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -102,13 +98,15 @@ bool wxStatusBar95::Create(wxWindow *parent,
long style, long style,
const wxString& name) const wxString& name)
{ {
wxCHECK_MSG( parent, FALSE, wxT("status bar must have a parent") );
SetName(name); SetName(name);
SetWindowStyleFlag(style);
SetParent(parent); SetParent(parent);
if (id == -1) parent->AddChild(this);
m_windowId = NewControlId();
else m_windowId = id == -1 ? NewControlId() : id;
m_windowId = id;
DWORD wstyle = WS_CHILD | WS_VISIBLE; DWORD wstyle = WS_CHILD | WS_VISIBLE;
if ( style & wxST_SIZEGRIP ) if ( style & wxST_SIZEGRIP )
@@ -125,12 +123,12 @@ bool wxStatusBar95::Create(wxWindow *parent,
return FALSE; return FALSE;
} }
// for some reason, subclassing in the usual way doesn't work at all - many // we can't subclass this window as usual because the status bar window
// strange things start happening (status bar is not positioned correctly, // proc processes WM_SIZE and WM_PAINT specially
// all methods fail...)
// SubclassWin(m_hWnd); // SubclassWin(m_hWnd);
// but we want to process the messages from it still, so must subclass it // but we want to process the messages from it still, so do custom
// subclassing here
gs_wndprocStatBar = (WXFARPROC)GetWindowLong(GetHwnd(), GWL_WNDPROC); gs_wndprocStatBar = (WXFARPROC)GetWindowLong(GetHwnd(), GWL_WNDPROC);
SetWindowLong(GetHwnd(), GWL_WNDPROC, (LONG)wxStatusBarProc); SetWindowLong(GetHwnd(), GWL_WNDPROC, (LONG)wxStatusBarProc);
SetWindowLong(GetHwnd(), GWL_USERDATA, (LONG)this); SetWindowLong(GetHwnd(), GWL_USERDATA, (LONG)this);
@@ -301,11 +299,9 @@ bool wxStatusBar95::GetFieldRect(int i, wxRect& rect) const
return TRUE; return TRUE;
} }
void wxStatusBar95::OnSize(wxSizeEvent& event) void wxStatusBar95::DoMoveWindow(int x, int y, int width, int height)
{ {
FORWARD_WM_SIZE(GetHwnd(), SIZE_RESTORED, FORWARD_WM_SIZE(GetHwnd(), SIZE_RESTORED, x, y, SendMessage);
event.GetSize().x, event.GetSize().y,
SendMessage);
// adjust fields widths to the new size // adjust fields widths to the new size
SetFieldsWidth(); SetFieldsWidth();

View File

@@ -365,6 +365,10 @@ bool wxWindow::Enable(bool enable)
if ( hWnd ) if ( hWnd )
::EnableWindow(hWnd, (BOOL)enable); ::EnableWindow(hWnd, (BOOL)enable);
// VZ: no, this is a bad idea: imagine that you have a dialog with some
// disabled controls and disable it - you really wouldn't like the
// disabled controls eb reenabled too when you reenable the dialog!
#if 0
wxWindowList::Node *node = GetChildren().GetFirst(); wxWindowList::Node *node = GetChildren().GetFirst();
while ( node ) while ( node )
{ {
@@ -373,6 +377,7 @@ bool wxWindow::Enable(bool enable)
node = node->GetNext(); node = node->GetNext();
} }
#endif // 0
return TRUE; return TRUE;
} }