]>
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"
34 #include "wx/generic/progdlgg.h"
36 #define LAYOUT_X_MARGIN 8
37 #define LAYOUT_Y_MARGIN 8
41 #if !USE_SHARED_LIBRARY
42 BEGIN_EVENT_TABLE(wxProgressDialog
, wxFrame
)
43 EVT_BUTTON(-1, wxProgressDialog::OnCancel
)
44 EVT_CLOSE(wxProgressDialog::OnClose
)
47 IMPLEMENT_CLASS(wxProgressDialog
, wxFrame
)
50 wxProgressDialog::wxProgressDialog(wxString
const &title
,
51 wxString
const &message
,
56 bool hasAbortButton
= (style
& wxPD_CAN_ABORT
) != 0;
57 m_state
= hasAbortButton
? Continue
: Uncancelable
;
58 m_disableParentOnly
= (style
& wxPD_APP_MODAL
) == 0;
62 int height
= 70; // FIXME arbitrary numbers
65 wxFrame::Create(m_parent
, -1, title
,
66 wxPoint(0, 0), wxSize(220, height
),
67 wxDEFAULT_DIALOG_STYLE
);
69 wxLayoutConstraints
*c
;
71 m_msg
= new wxStaticText(this, -1, message
);
72 c
= new wxLayoutConstraints
;
73 c
->left
.SameAs(this, wxLeft
, 10);
74 c
->top
.SameAs(this, wxTop
, 10);
77 m_msg
->SetConstraints(c
);
81 m_gauge
= new wxGauge(this, -1, maximum
);
82 c
= new wxLayoutConstraints
;
83 c
->left
.SameAs(this, wxLeft
, 2*LAYOUT_X_MARGIN
);
84 c
->top
.Below(m_msg
, 2*LAYOUT_Y_MARGIN
);
85 c
->right
.SameAs(this, wxRight
, 2*LAYOUT_X_MARGIN
);
87 m_gauge
->SetConstraints(c
);
91 m_gauge
= (wxGauge
*)NULL
;
95 m_btnAbort
= new wxButton(this, -1, _("Cancel"));
96 c
= new wxLayoutConstraints
;
97 c
->centreX
.SameAs(this, wxCentreX
);
99 c
->top
.Below(m_gauge
, 2*LAYOUT_Y_MARGIN
);
101 c
->top
.Below(m_btnAbort
, 2*LAYOUT_Y_MARGIN
);
104 m_btnAbort
->SetConstraints(c
);
107 m_btnAbort
= (wxButton
*)NULL
;
111 Centre(wxCENTER_FRAME
| wxBOTH
);
113 if(m_disableParentOnly
)
114 m_parent
->Enable(FALSE
);
116 wxEnableTopLevelWindows(FALSE
);
117 Enable(TRUE
); // enable this window
123 wxProgressDialog::Update(int value
, const wxString
& newmsg
)
125 wxASSERT_MSG( value
== -1 || m_gauge
, "can't update non existent dialog" );
126 wxASSERT_MSG( value
< m_maximum
, "invalid progress value" );
129 m_gauge
->SetValue(value
+ 1);
130 if( !newmsg
.IsEmpty() )
131 m_msg
->SetLabel(newmsg
);
134 if ( (value
== m_maximum
- 1) && !(GetWindowStyleFlag() & wxPD_AUTO_HIDE
) )
138 // tell the user what he should do...
139 m_btnAbort
->SetLabel(_("Close"));
144 // also provide the finishing message if the application didn't
145 m_msg
->SetLabel(_("Done."));
149 while ( m_state
!= Canceled
) // set from OnClose()
152 // so that we return TRUE below
156 return m_state
!= Canceled
;
159 void wxProgressDialog::OnClose(wxCloseEvent
& event
)
161 if ( m_state
== Uncancelable
)
168 wxProgressDialog::~wxProgressDialog()
170 if ( m_disableParentOnly
)
171 m_parent
->Enable(TRUE
);
173 wxEnableTopLevelWindows(TRUE
);