diff --git a/include/wx/generic/progdlgg.h b/include/wx/generic/progdlgg.h index ba03308d49..20ee5a17be 100644 --- a/include/wx/generic/progdlgg.h +++ b/include/wx/generic/progdlgg.h @@ -82,6 +82,14 @@ protected: static wxString GetRemainingLabel() { return _("Remaining time:"); } + // Similar to wxWindow::HasFlag() but tests for a presence of a wxPD_XXX + // flag in our (separate) flags instead of using m_windowStyle. + bool HasPDFlag(int flag) const { return (m_pdStyle & flag) != 0; } + + // Return the progress dialog style. Prefer to use HasPDFlag() if possible. + int GetPDStyle() const { return m_pdStyle; } + + // Updates estimated times from a given progress bar value and stores the // results in provided arguments. void UpdateTimeEstimates(int value, @@ -170,6 +178,12 @@ private: // parent top level window (may be NULL) wxWindow *m_parentTop; + // Progress dialog styles: this is not the same as m_windowStyle because + // wxPD_XXX constants clash with the existing TLW styles so to be sure we + // don't have any conflicts we just use a separate variable for storing + // them. + int m_pdStyle; + // skip some portion bool m_skip; @@ -192,9 +206,6 @@ private: int m_ctdelay; unsigned long m_display_estimated; - bool m_hasAbortButton, - m_hasSkipButton; - // for wxPD_APP_MODAL case wxWindowDisabler *m_winDisabler; diff --git a/src/generic/progdlgg.cpp b/src/generic/progdlgg.cpp index a3f0df2b4b..391942015c 100644 --- a/src/generic/progdlgg.cpp +++ b/src/generic/progdlgg.cpp @@ -94,7 +94,7 @@ void wxGenericProgressDialog::Init(wxWindow *parent, int maximum, int style) // we may disappear at any moment, let the others know about it SetExtraStyle(GetExtraStyle() | wxWS_EX_TRANSIENT); - m_windowStyle |= style; + m_pdStyle = style; m_parentTop = wxGetTopLevelParent(parent); @@ -123,9 +123,6 @@ void wxGenericProgressDialog::Init(wxWindow *parent, int maximum, int style) m_delay = 3; - m_hasAbortButton = - m_hasSkipButton = false; - m_winDisabler = NULL; m_tempEventLoop = NULL; } @@ -172,15 +169,12 @@ void wxGenericProgressDialog::Create( const wxString& title, wxEventLoop::SetActive(m_tempEventLoop); } - m_hasAbortButton = (style & wxPD_CAN_ABORT) != 0; - m_hasSkipButton = (style & wxPD_CAN_SKIP) != 0; - #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 // // FIXME: should probably have a (extended?) window style for this - if ( !m_hasAbortButton ) + if ( !HasPDFlag(wxPD_CAN_ABORT) ) { EnableCloseButton(false); } @@ -190,7 +184,7 @@ void wxGenericProgressDialog::Create( const wxString& title, SetLeftMenu(); #endif - m_state = m_hasAbortButton ? Continue : Uncancelable; + m_state = HasPDFlag(wxPD_CAN_ABORT) ? Continue : Uncancelable; // top-level sizerTop wxSizer * const sizerTop = new wxBoxSizer(wxVERTICAL); @@ -255,9 +249,9 @@ void wxGenericProgressDialog::Create( const wxString& title, sizerTop->Add(sizerLabels, 0, wxALIGN_CENTER_HORIZONTAL | wxTOP, LAYOUT_MARGIN); #if defined(__SMARTPHONE__) - if ( m_hasSkipButton ) + if ( HasPDFlag(wxPD_CAN_SKIP) ) SetRightMenu(wxID_SKIP, _("Skip")); - if ( m_hasAbortButton ) + if ( HasPDFlag(wxPD_CAN_ABORT) ) SetLeftMenu(wxID_CANCEL); #else m_btnAbort = @@ -274,21 +268,21 @@ void wxGenericProgressDialog::Create( const wxString& title, #endif // MSW/!MSW ; - if ( m_hasSkipButton ) + if ( HasPDFlag(wxPD_CAN_SKIP) ) { m_btnSkip = new wxButton(this, wxID_SKIP, _("&Skip")); buttonSizer->Add(m_btnSkip, 0, sizerFlags, LAYOUT_MARGIN); } - if ( m_hasAbortButton ) + if ( HasPDFlag(wxPD_CAN_ABORT) ) { m_btnAbort = new wxButton(this, wxID_CANCEL); buttonSizer->Add(m_btnAbort, 0, sizerFlags, LAYOUT_MARGIN); } - if (!m_hasSkipButton && !m_hasAbortButton) + if ( !HasPDFlag(wxPD_CAN_SKIP | wxPD_CAN_ABORT) ) buttonSizer->AddSpacer(LAYOUT_MARGIN); sizerTop->Add(buttonSizer, 0, sizerFlags, LAYOUT_MARGIN ); @@ -464,7 +458,7 @@ wxGenericProgressDialog::Update(int value, const wxString& newmsg, bool *skip) // so that we return true below and that out [Cancel] handler knew what // to do m_state = Finished; - if( !HasFlag(wxPD_AUTO_HIDE) ) + if( !HasPDFlag(wxPD_AUTO_HIDE) ) { EnableClose(); DisableSkip(); @@ -623,12 +617,12 @@ void wxGenericProgressDialog::SetRange(int maximum) bool wxGenericProgressDialog::WasCancelled() const { - return m_hasAbortButton && m_state == Canceled; + return HasPDFlag(wxPD_CAN_ABORT) && m_state == Canceled; } bool wxGenericProgressDialog::WasSkipped() const { - return m_hasSkipButton && m_skip; + return HasPDFlag(wxPD_CAN_SKIP) && m_skip; } // static @@ -728,7 +722,7 @@ wxGenericProgressDialog::~wxGenericProgressDialog() void wxGenericProgressDialog::DisableOtherWindows() { - if ( HasFlag(wxPD_APP_MODAL) ) + if ( HasPDFlag(wxPD_APP_MODAL) ) { m_winDisabler = new wxWindowDisabler(this); } @@ -742,7 +736,7 @@ void wxGenericProgressDialog::DisableOtherWindows() void wxGenericProgressDialog::ReenableOtherWindows() { - if ( HasFlag(wxPD_APP_MODAL) ) + if ( HasPDFlag(wxPD_APP_MODAL) ) { wxDELETE(m_winDisabler); } @@ -759,7 +753,7 @@ void wxGenericProgressDialog::ReenableOtherWindows() void wxGenericProgressDialog::EnableSkip(bool enable) { - if(m_hasSkipButton) + if ( HasPDFlag(wxPD_CAN_SKIP) ) { #ifdef __SMARTPHONE__ if(enable) @@ -775,7 +769,7 @@ void wxGenericProgressDialog::EnableSkip(bool enable) void wxGenericProgressDialog::EnableAbort(bool enable) { - if(m_hasAbortButton) + if( HasPDFlag(wxPD_CAN_ABORT) ) { #ifdef __SMARTPHONE__ if(enable) @@ -791,7 +785,7 @@ void wxGenericProgressDialog::EnableAbort(bool enable) void wxGenericProgressDialog::EnableClose() { - if(m_hasAbortButton) + if(HasPDFlag(wxPD_CAN_ABORT)) { #ifdef __SMARTPHONE__ SetLeftMenu(wxID_CANCEL, _("Close")); diff --git a/src/msw/progdlg.cpp b/src/msw/progdlg.cpp index 0a016d382f..0167b40762 100644 --- a/src/msw/progdlg.cpp +++ b/src/msw/progdlg.cpp @@ -126,9 +126,12 @@ private: namespace { +// This function returns true if the progress dialog with the given style +// (combination of wxPD_XXX constants) needs the "Close" button and this button +// only, i.e. not a "Cancel" one. bool UsesCloseButtonOnly(long style) { - return !((style & wxPD_CAN_ABORT) || (style & wxPD_AUTO_HIDE)); + return !(style & (wxPD_CAN_ABORT | wxPD_AUTO_HIDE)); } BOOL CALLBACK DisplayCloseButton(HWND hwnd, LPARAM lParam) @@ -356,7 +359,7 @@ bool wxProgressDialog::Update(int value, const wxString& newmsg, bool *skip) m_state = Finished; m_sharedData->m_state = Finished; m_sharedData->m_notifications |= wxSPDD_FINISHED; - if( !HasFlag(wxPD_AUTO_HIDE) && newmsg.empty() ) + if( !HasPDFlag(wxPD_AUTO_HIDE) && newmsg.empty() ) { // Provide the finishing message if the application didn't. m_message = _("Done."); @@ -452,7 +455,7 @@ void wxProgressDialog::Resume() // it now. m_sharedData->m_notifications |= wxSPDD_ENABLE_SKIP; - if ( !UsesCloseButtonOnly(m_windowStyle) ) + if ( !UsesCloseButtonOnly(GetPDStyle()) ) m_sharedData->m_notifications |= wxSPDD_ENABLE_ABORT; hwnd = m_sharedData->m_hwnd; @@ -592,21 +595,21 @@ bool wxProgressDialog::Show(bool show) m_sharedData->m_message = m_message; m_sharedData->m_range = m_maximum; m_sharedData->m_state = Uncancelable; - m_sharedData->m_style = m_windowStyle; + m_sharedData->m_style = GetPDStyle(); - if ( HasFlag(wxPD_CAN_ABORT) ) + if ( HasPDFlag(wxPD_CAN_ABORT) ) { m_sharedData->m_state = Continue; m_sharedData->m_labelCancel = _("Cancel"); } - else if ( !HasFlag(wxPD_AUTO_HIDE) ) + else if ( !HasPDFlag(wxPD_AUTO_HIDE) ) { m_sharedData->m_labelCancel = _("Close"); } - if ( m_windowStyle & (wxPD_ELAPSED_TIME - | wxPD_ESTIMATED_TIME - | wxPD_REMAINING_TIME) ) + if ( HasPDFlag(wxPD_ELAPSED_TIME | + wxPD_ESTIMATED_TIME | + wxPD_REMAINING_TIME) ) { // Use a non-empty string just to have the collapsible pane shown. m_sharedData->m_expandedInformation = " "; @@ -625,21 +628,6 @@ bool wxProgressDialog::Show(bool show) return false; } - if ( !HasFlag(wxPD_APP_MODAL) ) - { - wxWindow * const parent = GetTopParent(); - if ( parent ) - { - parent->Disable(); - } - else - { - wxFAIL_MSG( "Progress dialog must have a valid parent if " - "wxPD_APP_MODAL is not used." ); - } - } - //else: otherwise all windows will be disabled by m_taskDialogRunner - // Do not show the underlying dialog. return false; } @@ -651,12 +639,12 @@ bool wxProgressDialog::Show(bool show) bool wxProgressDialog::HasNativeProgressDialog() const { #ifdef wxHAS_MSW_TASKDIALOG - // For a native implementation task dialogs are required, which - // also require at least one button to be present so the flags needs - // to be checked as well to see if this is the case. + // Native task dialog, if available, can't be used without any buttons so + // we fall back to the generic one if none of "Skip", "Cancel" and "Close" + // buttons is used. return HasNativeTaskDialog() - && ((m_windowStyle & (wxPD_CAN_SKIP | wxPD_CAN_ABORT)) - || !(m_windowStyle & wxPD_AUTO_HIDE)); + && (HasPDFlag(wxPD_CAN_SKIP | wxPD_CAN_ABORT) || + !HasPDFlag(wxPD_AUTO_HIDE)); #else // !wxHAS_MSW_TASKDIALOG // This shouldn't be even called in !wxHAS_MSW_TASKDIALOG case but as we // still must define the function as returning something, return false. @@ -685,14 +673,14 @@ void wxProgressDialog::UpdateExpandedInformation(int value) wxString expandedInformation; // Calculate the three different timing values. - if ( m_windowStyle & wxPD_ELAPSED_TIME ) + if ( HasPDFlag(wxPD_ELAPSED_TIME) ) { expandedInformation << GetElapsedLabel() << " " << GetFormattedTime(elapsedTime); } - if ( m_windowStyle & wxPD_ESTIMATED_TIME ) + if ( HasPDFlag(wxPD_ESTIMATED_TIME) ) { if ( !expandedInformation.empty() ) expandedInformation += "\n"; @@ -702,7 +690,7 @@ void wxProgressDialog::UpdateExpandedInformation(int value) << GetFormattedTime(realEstimatedTime); } - if ( m_windowStyle & wxPD_REMAINING_TIME ) + if ( HasPDFlag(wxPD_REMAINING_TIME) ) { if ( !expandedInformation.empty() ) expandedInformation += "\n";