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

View File

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