]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/progdlgg.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxProgressDialog class
4 // Author: Karsten Ballüder
8 // Copyright: (c) Karsten Ballüder
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "progdlgg.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/button.h"
27 #include "wx/stattext.h"
28 #include "wx/layout.h"
32 #include "wx/settings.h"
33 #include "wx/dcclient.h"
38 #include "wx/generic/progdlgg.h"
40 #define LAYOUT_X_MARGIN 8
41 #define LAYOUT_Y_MARGIN 8
45 #if !USE_SHARED_LIBRARY
46 BEGIN_EVENT_TABLE(wxProgressDialog
, wxFrame
)
47 EVT_BUTTON(-1, wxProgressDialog::OnCancel
)
48 EVT_CLOSE(wxProgressDialog::OnClose
)
51 IMPLEMENT_CLASS(wxProgressDialog
, wxFrame
)
54 wxProgressDialog::wxProgressDialog(wxString
const &title
,
55 wxString
const &message
,
60 wxWindow
*lastWindow
= NULL
;
61 bool hasAbortButton
= (style
& wxPD_CAN_ABORT
) != 0;
62 m_state
= hasAbortButton
? Continue
: Uncancelable
;
63 m_disableParentOnly
= (style
& wxPD_APP_MODAL
) == 0;
67 m_elapsed
= m_estimated
= m_remaining
= NULL
;
68 if ((style
& (wxPD_ELAPSED_TIME
| wxPD_ESTIMATED_TIME
| wxPD_REMAINING_TIME
)) != 0) m_time
= new wxTime
;
71 wxFrame::Create(m_parent
, -1, title
, wxDefaultPosition
,
72 wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
);
73 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
75 wxLayoutConstraints
*c
;
78 dc
.SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
80 dc
.GetTextExtent(message
, &widthText
, NULL
);
82 m_msg
= new wxStaticText(this, -1, message
);
83 c
= new wxLayoutConstraints
;
84 c
->left
.SameAs(this, wxLeft
, 2*LAYOUT_X_MARGIN
);
85 c
->top
.SameAs(this, wxTop
, 2*LAYOUT_Y_MARGIN
);
88 m_msg
->SetConstraints(c
);
93 m_gauge
= new wxGauge(this, -1, maximum
,
94 wxDefaultPosition
, wxDefaultSize
,
95 wxGA_HORIZONTAL
| wxRAISED_BORDER
);
96 c
= new wxLayoutConstraints
;
97 c
->left
.SameAs(this, wxLeft
, 2*LAYOUT_X_MARGIN
);
98 c
->top
.Below(m_msg
, 2*LAYOUT_Y_MARGIN
);
99 c
->right
.SameAs(this, wxRight
, 2*LAYOUT_X_MARGIN
);
101 m_gauge
->SetConstraints(c
);
102 m_gauge
->SetValue(0);
103 lastWindow
= m_gauge
;
106 m_gauge
= (wxGauge
*)NULL
;
109 if ( style
& wxPD_ELAPSED_TIME
)
111 m_elapsed
= new wxStaticText(this, -1, "");
112 c
= new wxLayoutConstraints
;
113 c
->right
.SameAs(this, wxRight
, 2*LAYOUT_X_MARGIN
);
114 c
->top
.Below(lastWindow
, LAYOUT_Y_MARGIN
);
115 c
->width
.Absolute(60);
117 m_elapsed
->SetConstraints(c
);
119 wxStaticText
*dummy
= new wxStaticText(this, -1, _T("Elapsed time : "));
120 c
= new wxLayoutConstraints
;
121 c
->right
.LeftOf(m_elapsed
);
122 c
->top
.SameAs(m_elapsed
, wxTop
, 0);
125 dummy
->SetConstraints(c
);
127 lastWindow
= m_elapsed
;
130 if ( style
& wxPD_ESTIMATED_TIME
)
132 m_estimated
= new wxStaticText(this, -1, "");
133 c
= new wxLayoutConstraints
;
134 c
->right
.SameAs(this, wxRight
, 2*LAYOUT_X_MARGIN
);
135 c
->top
.Below(lastWindow
, 0);
136 c
->width
.Absolute(60);
138 m_estimated
->SetConstraints(c
);
140 wxStaticText
*dummy
= new wxStaticText(this, -1, _T("Estimated time : "));
141 c
= new wxLayoutConstraints
;
142 c
->right
.LeftOf(m_estimated
);
143 c
->top
.SameAs(m_estimated
, wxTop
, 0);
146 dummy
->SetConstraints(c
);
148 lastWindow
= m_estimated
;
151 if ( style
& wxPD_REMAINING_TIME
)
153 m_remaining
= new wxStaticText(this, -1, "");
154 c
= new wxLayoutConstraints
;
155 c
->right
.SameAs(this, wxRight
, 2*LAYOUT_X_MARGIN
);
156 c
->top
.Below(lastWindow
, 0);
157 c
->width
.Absolute(60);
159 m_remaining
->SetConstraints(c
);
161 wxStaticText
*dummy
= new wxStaticText(this, -1, _T("Remaining time : "));
162 c
= new wxLayoutConstraints
;
163 c
->right
.LeftOf(m_remaining
);
164 c
->top
.SameAs(m_remaining
, wxTop
, 0);
167 dummy
->SetConstraints(c
);
169 lastWindow
= m_remaining
;
172 if ( hasAbortButton
)
174 m_btnAbort
= new wxButton(this, -1, _("Cancel"));
175 c
= new wxLayoutConstraints
;
176 c
->centreX
.SameAs(this, wxCentreX
);
177 c
->top
.Below(lastWindow
, 2*LAYOUT_Y_MARGIN
);
180 m_btnAbort
->SetConstraints(c
);
183 m_btnAbort
= (wxButton
*)NULL
;
188 // calc the height of the dialog
190 // and set the width from it - unfortunately, Fit() makes the dialog way too
191 // wide under Windows, so try to find a reasonable value for the width, not
192 // too big and not too small
193 wxSize size
= GetClientSize();
194 size
.x
= wxMax(3*widthText
/2, 2*size
.y
);
198 Centre(wxCENTER_FRAME
| wxBOTH
);
200 if(m_disableParentOnly
)
202 if(m_parent
) m_parent
->Enable(FALSE
);
205 wxEnableTopLevelWindows(FALSE
);
207 Enable(TRUE
); // enable this window
213 wxProgressDialog::Update(int value
, const wxString
& newmsg
)
215 wxASSERT_MSG( value
== -1 || m_gauge
, _T("cannot update non existent dialog") );
216 wxASSERT_MSG( value
<= m_maximum
, _T("invalid progress value") );
220 m_gauge
->SetValue(value
+ 1);
222 if( !newmsg
.IsEmpty() )
223 m_msg
->SetLabel(newmsg
);
225 if ( (m_elapsed
|| m_remaining
|| m_estimated
) && (value
!= 0) )
228 wxTime diff
= timenow
- *m_time
;
229 unsigned long secs
= diff
.GetSecond() + 60 * diff
.GetMinute() + 60 * 60 * diff
.GetHour();
230 unsigned long estim
= secs
* m_maximum
/ value
;
231 unsigned long remai
= estim
- secs
;
236 s
.Printf(_T("%i:%02i:%02i"), diff
.GetHour(), diff
.GetMinute(), diff
.GetSecond());
237 if (s
!= m_elapsed
->GetLabel()) m_elapsed
->SetLabel(s
);
241 s
.Printf(_T("%i:%02i:%02i"), estim
/ (60 * 60), (estim
/ 60) % 60, estim
% 60);
242 if (s
!= m_estimated
->GetLabel()) m_estimated
->SetLabel(s
);
246 s
.Printf(_T("%i:%02i:%02i"), remai
/ (60 * 60), (remai
/ 60) % 60, remai
% 60);
247 if (s
!= m_remaining
->GetLabel()) m_remaining
->SetLabel(s
);
251 if ( (value
== m_maximum
- 1) && !(GetWindowStyleFlag() & wxPD_AUTO_HIDE
) )
255 // tell the user what he should do...
256 m_btnAbort
->SetLabel(_("Close"));
259 /*I think the default should be the other way round. If the
260 application wants to set a "Done." message at the end, it should
261 supply it. Any serious objections to this change? Makes the
262 application programmers' work a little easier.
265 // also provide the finishing message if the application didn't
266 m_msg->SetLabel(_("Done."));
271 // so that we return TRUE below
275 return m_state
!= Canceled
;
278 void wxProgressDialog::OnClose(wxCloseEvent
& event
)
280 if ( m_state
== Uncancelable
)
287 wxProgressDialog::~wxProgressDialog()
289 if ( m_disableParentOnly
)
291 if(m_parent
) m_parent
->Enable(TRUE
);
294 wxEnableTopLevelWindows(TRUE
);
295 if (m_time
) delete m_time
;