2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: busyinfo.h
|
2008-03-10 11:24:38 -04:00
|
|
|
// Purpose: interface of wxBusyInfo
|
2008-03-08 08:52:38 -05:00
|
|
|
// Author: wxWidgets team
|
2010-07-13 09:29:13 -04:00
|
|
|
// Licence: wxWindows licence
|
2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxBusyInfo
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
This class makes it easy to tell your user that the program is temporarily busy.
|
2014-10-24 17:54:38 -04:00
|
|
|
|
|
|
|
Normally the main thread should always return to the main loop to continue
|
|
|
|
dispatching events as quickly as possible, hence this class shouldn't be
|
|
|
|
needed. However if the main thread does need to block, this class provides
|
|
|
|
a simple way to at least show this to the user: just create a wxBusyInfo
|
|
|
|
object on the stack, and within the current scope, a message window will be
|
|
|
|
shown.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
For example:
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@code
|
2008-03-16 20:47:38 -04:00
|
|
|
wxBusyInfo wait("Please wait, working...");
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-16 20:47:38 -04:00
|
|
|
for (int i = 0; i < 100000; i++)
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
DoACalculation();
|
|
|
|
}
|
|
|
|
@endcode
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-16 20:47:38 -04:00
|
|
|
It works by creating a window in the constructor, and deleting it
|
|
|
|
in the destructor.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2014-10-24 17:54:38 -04:00
|
|
|
This window is rather plain by default but can be customized by passing
|
|
|
|
wxBusyInfo constructor an object of wxBusyInfoFlags class instead of a
|
2015-10-31 16:35:30 -04:00
|
|
|
simple message. Here is an example from the dialogs sample:
|
|
|
|
|
2014-10-24 17:54:38 -04:00
|
|
|
@code
|
|
|
|
wxBusyInfo info
|
|
|
|
(
|
|
|
|
wxBusyInfoFlags()
|
|
|
|
.Parent(this)
|
|
|
|
.Icon(wxArtProvider::GetIcon(wxART_PRINT,
|
|
|
|
wxART_OTHER, wxSize(128, 128)))
|
|
|
|
.Title("<b>Printing your document</b>")
|
|
|
|
.Text("Please wait...")
|
|
|
|
.Foreground(*wxWHITE)
|
|
|
|
.Background(*wxBLACK)
|
|
|
|
.Transparency(4*wxALPHA_OPAQUE/5)
|
|
|
|
);
|
|
|
|
@endcode
|
2015-10-31 16:35:30 -04:00
|
|
|
|
|
|
|
This shows that separate title and text can be set, and that simple markup
|
2014-10-24 17:54:38 -04:00
|
|
|
(@ref wxControl::SetLabelMarkup()) can be used in them, and that it's also
|
|
|
|
possible to add an icon and customize the colours and transparency of the
|
|
|
|
window.
|
|
|
|
|
2009-01-29 18:52:47 -05:00
|
|
|
You may also want to call wxTheApp->Yield() to refresh the window
|
2008-03-08 08:52:38 -05:00
|
|
|
periodically (in case it had been obscured by other windows, for
|
|
|
|
example) like this:
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@code
|
2008-03-16 20:47:38 -04:00
|
|
|
wxWindowDisabler disableAll;
|
2008-03-08 08:52:38 -05:00
|
|
|
wxBusyInfo wait("Please wait, working...");
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-16 20:47:38 -04:00
|
|
|
for (int i = 0; i < 100000; i++)
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
DoACalculation();
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
if ( !(i % 1000) )
|
2008-12-12 10:41:22 -05:00
|
|
|
wxTheApp->Yield();
|
2008-03-08 08:52:38 -05:00
|
|
|
}
|
|
|
|
@endcode
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
|
|
but take care to not cause undesirable reentrancies when doing it (see
|
2008-03-16 20:47:38 -04:00
|
|
|
wxApp::Yield for more details). The simplest way to do it is to use
|
|
|
|
wxWindowDisabler class as illustrated in the above example.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2009-02-05 12:46:00 -05:00
|
|
|
Note that a wxBusyInfo is always built with the @c wxSTAY_ON_TOP window style
|
|
|
|
(see wxFrame window styles for more info).
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxcore}
|
2008-03-16 20:47:38 -04:00
|
|
|
@category{cmndlg}
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
class wxBusyInfo
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2014-10-24 17:54:38 -04:00
|
|
|
General constructor.
|
|
|
|
|
2019-01-25 21:14:20 -05:00
|
|
|
This constructor allows specifying all supported attributes by calling
|
2014-10-24 17:54:38 -04:00
|
|
|
the appropriate methods on wxBusyInfoFlags object passed to it as
|
|
|
|
parameter. All of them are optional but usually at least the message
|
|
|
|
should be specified.
|
|
|
|
|
|
|
|
@since 3.1.0
|
|
|
|
*/
|
|
|
|
wxBusyInfo(const wxBusyInfoFlags& flags);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Simple constructor specifying only the message and the parent.
|
|
|
|
|
|
|
|
This constructs a busy info window as child of @a parent and displays
|
|
|
|
@a msg in it. It is exactly equivalent to using
|
|
|
|
@code
|
|
|
|
wxBusyInfo(wxBusyInfoFlags().Parent(parent).Label(message))
|
|
|
|
@endcode
|
2008-03-16 20:47:38 -04:00
|
|
|
|
|
|
|
@note If @a parent is not @NULL you must ensure that it is not
|
|
|
|
closed while the busy info is shown.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 08:33:59 -04:00
|
|
|
wxBusyInfo(const wxString& msg, wxWindow* parent = NULL);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2019-09-07 09:31:28 -04:00
|
|
|
/**
|
|
|
|
Update the information text.
|
|
|
|
|
|
|
|
The @a text string may contain markup as described in
|
|
|
|
wxControl::SetLabelMarkup().
|
|
|
|
|
|
|
|
@since 3.1.3
|
|
|
|
*/
|
|
|
|
void UpdateText(const wxString& str);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Same as UpdateText() but doesn't interpret the string as containing markup.
|
|
|
|
|
|
|
|
@since 3.1.3
|
|
|
|
*/
|
|
|
|
void UpdateLabel(const wxString& str);
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
Hides and closes the window containing the information text.
|
|
|
|
*/
|
2008-03-24 18:17:25 -04:00
|
|
|
virtual ~wxBusyInfo();
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2014-10-24 17:54:38 -04:00
|
|
|
/**
|
|
|
|
Parameters for wxBusyInfo.
|
|
|
|
|
|
|
|
This class exists only in order to make passing attributes to wxBusyInfo
|
|
|
|
constructor easier and the code doing it more readable.
|
|
|
|
|
|
|
|
All methods of this class return the reference to the object on which they
|
|
|
|
are called, making it possible to chain them together, e.g. typically you
|
|
|
|
would just create a temporary wxBusyInfoFlags object and then call the
|
|
|
|
methods corresponding to the attributes you want to set, before finally
|
|
|
|
passing the result to wxBusyInfo constructor, e.g.:
|
|
|
|
@code
|
|
|
|
wxBusyInfo info
|
|
|
|
(
|
|
|
|
wxBusyInfoFlags()
|
|
|
|
.Parent(window)
|
|
|
|
.Icon(icon)
|
|
|
|
.Title("Some text")
|
|
|
|
.Text("Some more text")
|
|
|
|
.Foreground(wxColour(...))
|
|
|
|
.Background(wxColour(...))
|
|
|
|
);
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
@since 3.1.0
|
|
|
|
*/
|
|
|
|
class wxBusyInfoFlags
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Default constructor initializes all attributes to default values.
|
|
|
|
|
|
|
|
Call the other methods to really fill in the object.
|
|
|
|
*/
|
|
|
|
wxBusyInfoFlags();
|
|
|
|
|
|
|
|
/// Sets the parent for wxBusyInfo.
|
|
|
|
wxBusyInfoFlags& Parent(wxWindow* parent);
|
|
|
|
|
|
|
|
/// Sets the icon to show in wxBusyInfo.
|
|
|
|
wxBusyInfoFlags& Icon(const wxIcon& icon);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the title, shown prominently in wxBusyInfo window.
|
|
|
|
|
|
|
|
The @a title string may contain markup as described in
|
|
|
|
wxControl::SetLabelMarkup().
|
|
|
|
*/
|
|
|
|
wxBusyInfoFlags& Title(const wxString& title);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the more detailed text, shown under the title, if any.
|
|
|
|
|
|
|
|
The @a text string may contain markup as described in
|
|
|
|
wxControl::SetLabelMarkup().
|
|
|
|
*/
|
|
|
|
wxBusyInfoFlags& Text(const wxString& text);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Same as Text() but doesn't interpret the string as containing markup.
|
|
|
|
|
|
|
|
This method should be used if the text shown in wxBusyInfo comes from
|
|
|
|
external source and so may contain characters having special meaning in
|
|
|
|
simple markup, e.g. '<'.
|
|
|
|
*/
|
|
|
|
wxBusyInfoFlags& Label(const wxString& label);
|
|
|
|
|
|
|
|
/// Sets the foreground colour of the title and text strings.
|
|
|
|
wxBusyInfoFlags& Foreground(const wxColour& foreground);
|
|
|
|
|
|
|
|
/// Sets the background colour of wxBusyInfo window.
|
|
|
|
wxBusyInfoFlags& Background(const wxColour& background);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the transparency of wxBusyInfo window.
|
|
|
|
|
|
|
|
@param alpha Value in wxALPHA_TRANSPARENT (0) to wxALPHA_OPAQUE (255)
|
|
|
|
range.
|
|
|
|
|
|
|
|
@see wxTopLevelWindow::SetTransparent()
|
|
|
|
*/
|
|
|
|
wxBusyInfoFlags& Transparency(wxByte alpha);
|
|
|
|
};
|