From 21977bac1ae09f726d1437b1b7092ae5b3f99119 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 29 Oct 2001 14:32:42 +0000 Subject: [PATCH] improved sizing of wxBusyInfo window and updated the docs a bit git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12197 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/busyinfo.tex | 45 ++++++++++++++++++++++++++++++++----- docs/latex/wx/wnddisbl.tex | 2 ++ include/wx/busyinfo.h | 15 +++++++------ samples/dialogs/dialogs.cpp | 4 +++- src/generic/busyinfo.cpp | 27 ++++++++++++++++------ 5 files changed, 73 insertions(+), 20 deletions(-) diff --git a/docs/latex/wx/busyinfo.tex b/docs/latex/wx/busyinfo.tex index da43b7e4e1..caf6bf1ba6 100644 --- a/docs/latex/wx/busyinfo.tex +++ b/docs/latex/wx/busyinfo.tex @@ -7,15 +7,40 @@ a message window will be shown. For example: \begin{verbatim} - wxBusyInfo wait("Please wait, working..."); + wxBusyInfo wait("Please wait, working..."); - for (int i = 0; i < 100000; i++) - DoACalculation(); + for (int i = 0; i < 100000; i++) + { + DoACalculation(); + } \end{verbatim} It works by creating a window in the constructor, and deleting it in the destructor. +You may also want to call wxTheApp->Yield() to refresh the window +periodically (in case it had been obscured by other windows, for +example) like this: + +\begin{verbatim} + wxWindowDisabler disableAll; + + wxBusyInfo wait("Please wait, working..."); + + for (int i = 0; i < 100000; i++) + { + DoACalculation(); + + if ( !(i % 1000) ) + wxTheApp->Yield(); + } +\end{verbatim} + +but take care to not cause undesirable reentrancies when doing it (see +\helpref{wxApp::Yield()}{wxappyield} for more details). The simplest way to do +it is to use \helpref{wxWindowDisabler}{wxwindowdisabler} class as illustrated +in the above example. + \wxheading{Derived from} None @@ -28,7 +53,17 @@ None \membersection{wxBusyInfo::wxBusyInfo} -\func{}{wxBusyInfo}{\param{const wxString\&}{ msg}} +\func{}{wxBusyInfo}{\param{const wxString\&}{ msg}, \param{wxParent }{*parent = NULL}} + +Constructs a busy info window as child of {\it parent} and displays {\it msg} +in it. + +{\bf NB:} If {\it parent} is not {\tt NULL} you must ensure that it is not +closed while the busy info is shown. + +\membersection{wxBusyInfo::\destruct{wxBusyInfo}} + +\func{}{\destruct{wxBusyInfo}}{\void} -Constructs a busy info object, displays {\it msg}. +Hides and closes the window containing the information text. diff --git a/docs/latex/wx/wnddisbl.tex b/docs/latex/wx/wnddisbl.tex index 798dae3dd7..75965bf910 100644 --- a/docs/latex/wx/wnddisbl.tex +++ b/docs/latex/wx/wnddisbl.tex @@ -39,5 +39,7 @@ Disables all top level windows of the applications with the exception of \membersection{wxWindowDisabler::\destruct{wxWindowDisabler}} +\func{}{\destruct{wxWindowDisabler}}{\void} + Reenables back the windows disabled by the constructor. diff --git a/include/wx/busyinfo.h b/include/wx/busyinfo.h index 37e7238cb6..0050bfa08a 100644 --- a/include/wx/busyinfo.h +++ b/include/wx/busyinfo.h @@ -26,8 +26,8 @@ class WXDLLEXPORT wxInfoFrame : public wxFrame { - public: - wxInfoFrame(wxWindow *parent, const wxString& message); +public: + wxInfoFrame(wxWindow *parent, const wxString& message); }; @@ -39,12 +39,13 @@ class WXDLLEXPORT wxInfoFrame : public wxFrame class WXDLLEXPORT wxBusyInfo : public wxObject { - public: - wxBusyInfo(const wxString& message); - ~wxBusyInfo(); +public: + wxBusyInfo(const wxString& message, wxWindow *parent = NULL); - private: - wxInfoFrame *m_InfoFrame; + virtual ~wxBusyInfo(); + +private: + wxInfoFrame *m_InfoFrame; }; diff --git a/samples/dialogs/dialogs.cpp b/samples/dialogs/dialogs.cpp index 2fe34c932b..1e087c45e7 100644 --- a/samples/dialogs/dialogs.cpp +++ b/samples/dialogs/dialogs.cpp @@ -641,7 +641,9 @@ void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) ) void MyFrame::ShowBusyInfo(wxCommandEvent& WXUNUSED(event)) { - wxBusyInfo info("Sleep^H^H^H^H^HWorkiing, please wait...\n... a bit more"); + wxWindowDisabler disableAll; + + wxBusyInfo info("Sleep^H^H^H^H^HWorkiing, please wait...", this); for ( int i = 0; i < 30; i++ ) { diff --git a/src/generic/busyinfo.cpp b/src/generic/busyinfo.cpp index be101dcf52..ce2e3a45d0 100644 --- a/src/generic/busyinfo.cpp +++ b/src/generic/busyinfo.cpp @@ -25,18 +25,31 @@ wxInfoFrame::wxInfoFrame(wxWindow *parent, const wxString& message) - : wxFrame(parent, -1, wxT(""), wxPoint(0, 0), wxSize(400, 80), wxTHICK_FRAME | wxSIMPLE_BORDER | wxFRAME_TOOL_WINDOW) + : wxFrame(parent, -1, wxT(""), + wxDefaultPosition, wxDefaultSize, + wxSIMPLE_BORDER | wxFRAME_TOOL_WINDOW) { - wxPanel *p = new wxPanel( this ); - wxStaticText *s = new wxStaticText( p, -1, message, wxPoint(20, 20), wxSize(360, 40), wxALIGN_CENTER ); + wxPanel *panel = new wxPanel( this ); + wxStaticText *text = new wxStaticText(panel, -1, message); + + panel->SetCursor(*wxHOURGLASS_CURSOR); + text->SetCursor(*wxHOURGLASS_CURSOR); + + // make the frame of at least the standard size (400*80) but big enough + // for the text we show + wxSize sizeText = text->GetBestSize(); + SetClientSize(wxMax(sizeText.x, 340) + 60, wxMax(sizeText.y, 40) + 40); + + // need to size the panel correctly first so that text->Centre() works + panel->SetSize(GetClientSize()); + + text->Centre(wxBOTH); Centre(wxBOTH); - p->SetCursor(*wxHOURGLASS_CURSOR); - s->SetCursor(*wxHOURGLASS_CURSOR); } -wxBusyInfo::wxBusyInfo(const wxString& message) : wxObject() +wxBusyInfo::wxBusyInfo(const wxString& message, wxWindow *parent) { - m_InfoFrame = new wxInfoFrame( (wxWindow*) NULL, message); + m_InfoFrame = new wxInfoFrame( parent, message); m_InfoFrame->Show(TRUE); wxYield(); m_InfoFrame->Refresh(); -- 2.45.2