use wxFlexGridSizer for layout of the labels in the progress dialog (patch 1829312); minor cleanup

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51038 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2008-01-06 15:05:57 +00:00
parent 8084f8b7c6
commit 695f550bfa
2 changed files with 108 additions and 118 deletions

View File

@ -30,29 +30,29 @@ class WXDLLEXPORT wxProgressDialog : public wxDialog
{
DECLARE_DYNAMIC_CLASS(wxProgressDialog)
public:
/* Creates and displays dialog, disables event handling for other
/* Creates and displays dialog, disables event handling for other
frames or parent frame to avoid recursion problems.
@param title title for window
@param message message to display in window
@param maximum value for status bar, if <= 0, no bar is shown
@param parent window or NULL
@param style is the bit mask of wxPD_XXX constants from wx/defs.h
*/
wxProgressDialog(const wxString &title, wxString const &message,
int maximum = 100,
wxWindow *parent = NULL,
int style = wxPD_APP_MODAL | wxPD_AUTO_HIDE);
/* Destructor.
Re-enables event handling for other windows.
*/
virtual ~wxProgressDialog();
*/
wxProgressDialog(const wxString& title, const wxString& message,
int maximum = 100,
wxWindow *parent = NULL,
int style = wxPD_APP_MODAL | wxPD_AUTO_HIDE);
/* Destructor.
Re-enables event handling for other windows.
*/
virtual ~wxProgressDialog();
/* Update the status bar to the new value.
/* Update the status bar to the new value.
@param value new value
@param newmsg if used, new message to display
@returns true if ABORT button has not been pressed
*/
virtual bool Update(int value, const wxString& newmsg = wxEmptyString, bool *skip = NULL);
*/
virtual bool Update(int value, const wxString& newmsg = wxEmptyString, bool *skip = NULL);
/* Switches the dialog to use a gauge in indeterminate mode and calls
wxGauge::Pulse() to show to the user a bit of progress */
@ -61,63 +61,63 @@ public:
// Must provide overload to avoid hiding it (and warnings about it)
virtual void Update() { wxDialog::Update(); }
/* Can be called to continue after the cancel button has been pressed, but
/* Can be called to continue after the cancel button has been pressed, but
the program decided to continue the operation (e.g., user didn't
confirm it)
*/
void Resume();
*/
void Resume();
virtual bool Show( bool show = true );
virtual bool Show( bool show = true );
protected:
// callback for optional abort button
void OnCancel(wxCommandEvent& event);
// callback for optional abort button
void OnCancel(wxCommandEvent&);
// callback for optional skip button
void OnSkip(wxCommandEvent& event);
// callback for optional skip button
void OnSkip(wxCommandEvent&);
// callback to disable "hard" window closing
void OnClose(wxCloseEvent& event);
// callback to disable "hard" window closing
void OnClose(wxCloseEvent&);
// must be called to reenable the other windows temporarily disabled while
// the dialog was shown
void ReenableOtherWindows();
// must be called to reenable the other windows temporarily disabled while
// the dialog was shown
void ReenableOtherWindows();
private:
// create the label with given text and another one to show the time nearby
// as the next windows in the sizer, returns the created control
wxStaticText *CreateLabel(const wxString& text, wxSizer *sizer);
// create the label with given text and another one to show the time nearby
// as the next windows in the sizer, returns the created control
wxStaticText *CreateLabel(const wxString& text, wxSizer *sizer);
// updates the label message
void UpdateMessage(const wxString &newmsg);
void UpdateMessage(const wxString &newmsg);
// common part of Update() and Pulse(), returns true if not cancelled
bool DoAfterUpdate(bool *skip);
// common part of Update() and Pulse(), returns true if not cancelled
bool DoAfterUpdate(bool *skip);
// shortcuts for enabling buttons
void EnableClose();
void EnableSkip(bool enable=true);
void EnableAbort(bool enable=true);
inline void DisableSkip() { EnableSkip(false); }
inline void DisableAbort() { EnableAbort(false); }
// shortcuts for enabling buttons
void EnableClose();
void EnableSkip(bool enable = true);
void EnableAbort(bool enable = true);
void DisableSkip() { EnableSkip(false); }
void DisableAbort() { EnableAbort(false); }
// the status bar
wxGauge *m_gauge;
// the message displayed
wxStaticText *m_msg;
// displayed elapsed, estimated, remaining time
class wxStaticText *m_elapsed,
*m_estimated,
*m_remaining;
// time when the dialog was created
unsigned long m_timeStart;
// time when the dialog was closed or cancelled
unsigned long m_timeStop;
// time between the moment the dialog was closed/cancelled and resume
unsigned long m_break;
// the status bar
wxGauge *m_gauge;
// the message displayed
wxStaticText *m_msg;
// displayed elapsed, estimated, remaining time
wxStaticText *m_elapsed,
*m_estimated,
*m_remaining;
// time when the dialog was created
unsigned long m_timeStart;
// time when the dialog was closed or cancelled
unsigned long m_timeStop;
// time between the moment the dialog was closed/cancelled and resume
unsigned long m_break;
// parent top level window (may be NULL)
wxWindow *m_parentTop;
// parent top level window (may be NULL)
wxWindow *m_parentTop;
// continue processing or not (return value for Update())
enum

View File

@ -92,8 +92,8 @@ IMPLEMENT_CLASS(wxProgressDialog, wxDialog)
// wxProgressDialog creation
// ----------------------------------------------------------------------------
wxProgressDialog::wxProgressDialog(wxString const &title,
wxString const &message,
wxProgressDialog::wxProgressDialog(const wxString& title,
const wxString& message,
int maximum,
wxWindow *parent,
int style)
@ -110,8 +110,6 @@ wxProgressDialog::wxProgressDialog(wxString const &title,
m_hasAbortButton = (style & wxPD_CAN_ABORT) != 0;
m_hasSkipButton = (style & wxPD_CAN_SKIP) != 0;
bool isPda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
// we have to remove the "Close" button from the title bar then as it is
// confusing to have it - it doesn't work anyhow
@ -144,36 +142,44 @@ wxProgressDialog::wxProgressDialog(wxString const &title,
wxCoord widthText = 0;
dc.GetTextExtent(message, &widthText, NULL, NULL, NULL, NULL);
wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
// top-level sizerTop
wxSizer * const sizerTop = new wxBoxSizer(wxVERTICAL);
m_msg = new wxStaticText(this, wxID_ANY, message);
sizer->Add(m_msg, 0, wxLEFT | wxTOP, 2*LAYOUT_MARGIN);
wxSize sizeDlg,
sizeLabel = m_msg->GetSize();
sizeDlg.y = 2*LAYOUT_MARGIN + sizeLabel.y;
sizerTop->Add(m_msg, 0, wxLEFT | wxTOP, 2*LAYOUT_MARGIN);
wxSize sizeLabel = m_msg->GetSize();
if ( maximum > 0 )
{
int gauge_style = wxGA_HORIZONTAL;
if ( ( style & wxPD_SMOOTH ) == wxPD_SMOOTH )
if ( style & wxPD_SMOOTH )
gauge_style |= wxGA_SMOOTH;
m_gauge = new wxGauge(this, wxID_ANY, m_maximum,
wxDefaultPosition, wxDefaultSize,
gauge_style );
m_gauge = new wxGauge
(
this,
wxID_ANY,
m_maximum,
wxDefaultPosition,
// make the progress bar sufficiently long
wxSize(wxMin(wxGetClientDisplayRect().width/3, 300), -1),
gauge_style
);
sizer->Add(m_gauge, 0, wxLEFT | wxRIGHT | wxTOP | wxEXPAND, 2*LAYOUT_MARGIN);
sizerTop->Add(m_gauge, 0, wxLEFT | wxRIGHT | wxTOP | wxEXPAND, 2*LAYOUT_MARGIN);
m_gauge->SetValue(0);
wxSize sizeGauge = m_gauge->GetSize();
sizeDlg.y += 2*LAYOUT_MARGIN + sizeGauge.y;
}
else
m_gauge = (wxGauge *)NULL;
{
m_gauge = NULL;
}
// create the estimated/remaining/total time zones if requested
m_elapsed = m_estimated = m_remaining = (wxStaticText*)NULL;
m_display_estimated = m_last_timeupdate = m_break = 0;
m_elapsed =
m_estimated =
m_remaining = NULL;
m_display_estimated =
m_last_timeupdate =
m_break = 0;
m_ctdelay = 0;
// if we are going to have at least one label, remember it in this var
@ -182,12 +188,14 @@ wxProgressDialog::wxProgressDialog(wxString const &title,
// also count how many labels we really have
size_t nTimeLabels = 0;
wxSizer * const sizerLabels = new wxFlexGridSizer(2);
if ( style & wxPD_ELAPSED_TIME )
{
nTimeLabels++;
label =
m_elapsed = CreateLabel(_("Elapsed time : "), sizer);
m_elapsed = CreateLabel(_("Elapsed time:"), sizerLabels);
}
if ( style & wxPD_ESTIMATED_TIME )
@ -195,7 +203,7 @@ wxProgressDialog::wxProgressDialog(wxString const &title,
nTimeLabels++;
label =
m_estimated = CreateLabel(_("Estimated time : "), sizer);
m_estimated = CreateLabel(_("Estimated time:"), sizerLabels);
}
if ( style & wxPD_REMAINING_TIME )
@ -203,14 +211,14 @@ wxProgressDialog::wxProgressDialog(wxString const &title,
nTimeLabels++;
label =
m_remaining = CreateLabel(_("Remaining time : "), sizer);
m_remaining = CreateLabel(_("Remaining time:"), sizerLabels);
}
sizerTop->Add(sizerLabels, 0, wxALIGN_CENTER_HORIZONTAL | wxTOP, LAYOUT_MARGIN);
if ( nTimeLabels > 0 )
{
// set it to the current time
m_timeStart = wxGetCurrentTime();
sizeDlg.y += nTimeLabels * (label->GetSize().y + LAYOUT_MARGIN);
}
#if defined(__SMARTPHONE__)
@ -219,10 +227,12 @@ wxProgressDialog::wxProgressDialog(wxString const &title,
if ( m_hasAbortButton )
SetLeftMenu(wxID_CANCEL);
#else
m_btnAbort = m_btnSkip = (wxButton *)NULL;
bool sizeDlgModified = false;
m_btnAbort =
m_btnSkip = NULL;
wxBoxSizer *buttonSizer = new wxBoxSizer(wxHORIZONTAL);
// Windows dialogs usually have buttons in the lower right corner
const int sizerFlags =
#if defined(__WXMSW__) || defined(__WXPM__)
wxALIGN_RIGHT | wxALL
@ -233,37 +243,22 @@ wxProgressDialog::wxProgressDialog(wxString const &title,
if ( m_hasSkipButton )
{
m_btnSkip = new wxButton(this, wxID_SKIP, _("Skip"));
m_btnSkip = new wxButton(this, wxID_SKIP, _("&Skip"));
// Windows dialogs usually have buttons in the lower right corner
buttonSizer->Add(m_btnSkip, 0, sizerFlags, LAYOUT_MARGIN);
sizeDlg.y += 2*LAYOUT_MARGIN + wxButton::GetDefaultSize().y;
sizeDlgModified = true;
}
if ( m_hasAbortButton )
{
m_btnAbort = new wxButton(this, wxID_CANCEL);
// Windows dialogs usually have buttons in the lower right corner
buttonSizer->Add(m_btnAbort, 0, sizerFlags, LAYOUT_MARGIN);
if(!sizeDlgModified)
sizeDlg.y += 2*LAYOUT_MARGIN + wxButton::GetDefaultSize().y;
}
sizer->Add(buttonSizer, 0, sizerFlags, LAYOUT_MARGIN );
sizerTop->Add(buttonSizer, 0, sizerFlags, LAYOUT_MARGIN );
#endif // __SMARTPHONE__/!__SMARTPHONE__
SetSizerAndFit(sizer);
if (!isPda)
{
sizeDlg.y += 2*LAYOUT_MARGIN;
// try to make the dialog not square but rectangular of reasonable width
sizeDlg.x = (wxCoord)wxMax(3*widthText/2, 4*sizeDlg.y/3);
SetClientSize(sizeDlg);
}
SetSizerAndFit(sizerTop);
Centre(wxCENTER_FRAME | wxBOTH);
@ -292,33 +287,28 @@ wxProgressDialog::wxProgressDialog(wxString const &title,
Update();
}
wxStaticText *wxProgressDialog::CreateLabel(const wxString& text,
wxSizer *sizer)
wxStaticText *
wxProgressDialog::CreateLabel(const wxString& text, wxSizer *sizer)
{
wxBoxSizer *locsizer = new wxBoxSizer(wxLARGESMALL(wxHORIZONTAL,wxVERTICAL));
wxStaticText *dummy = new wxStaticText(this, wxID_ANY, text);
wxStaticText *label = new wxStaticText(this, wxID_ANY, _("unknown"));
wxStaticText *label = new wxStaticText(this, wxID_ANY, text);
wxStaticText *value = new wxStaticText(this, wxID_ANY, _("unknown"));
// select placement most native or nice on target GUI
#if defined(__SMARTPHONE__)
// label and time to the left in two rows
locsizer->Add(dummy, 1, wxALIGN_LEFT);
locsizer->Add(label, 1, wxALIGN_LEFT);
sizer->Add(locsizer, 0, wxALIGN_LEFT | wxTOP | wxLEFT, LAYOUT_MARGIN);
// value and time to the left in two rows
sizer->Add(label, 1, wxALIGN_LEFT);
sizer->Add(value, 1, wxALIGN_LEFT);
#elif defined(__WXMSW__) || defined(__WXPM__) || defined(__WXMAC__) || defined(__WXGTK20__)
// label and time centered in one row
locsizer->Add(dummy, 1, wxLARGESMALL(wxALIGN_RIGHT,wxALIGN_LEFT));
locsizer->Add(label, 1, wxALIGN_LEFT | wxLEFT, LAYOUT_MARGIN);
sizer->Add(locsizer, 0, wxALIGN_CENTER_HORIZONTAL | wxTOP, LAYOUT_MARGIN);
// value and time centered in one row
sizer->Add(label, 1, wxLARGESMALL(wxALIGN_RIGHT,wxALIGN_LEFT) | wxTOP | wxRIGHT, LAYOUT_MARGIN);
sizer->Add(value, 1, wxALIGN_LEFT | wxTOP, LAYOUT_MARGIN);
#else
// label and time to the right in one row
sizer->Add(locsizer, 0, wxALIGN_RIGHT | wxRIGHT | wxTOP, LAYOUT_MARGIN);
locsizer->Add(dummy);
locsizer->Add(label, 0, wxLEFT, LAYOUT_MARGIN);
// value and time to the right in one row
sizer->Add(label);
sizer->Add(value, 0, wxLEFT, LAYOUT_MARGIN);
#endif
return label;
return value;
}
// ----------------------------------------------------------------------------