]>
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"
36 #include "wx/generic/progdlgg.h"
38 #define LAYOUT_X_MARGIN 8
39 #define LAYOUT_Y_MARGIN 8
43 #if !USE_SHARED_LIBRARY
44 BEGIN_EVENT_TABLE(wxProgressDialog
, wxFrame
)
45 EVT_BUTTON(-1, wxProgressDialog::OnCancel
)
46 EVT_CLOSE(wxProgressDialog::OnClose
)
49 IMPLEMENT_CLASS(wxProgressDialog
, wxFrame
)
52 wxProgressDialog::wxProgressDialog(wxString
const &title
,
53 wxString
const &message
,
58 bool hasAbortButton
= (style
& wxPD_CAN_ABORT
) != 0;
59 m_state
= hasAbortButton
? Continue
: Uncancelable
;
60 m_disableParentOnly
= (style
& wxPD_APP_MODAL
) == 0;
64 int height
= 70; // FIXME arbitrary numbers
67 wxFrame::Create(m_parent
, -1, title
,
68 wxPoint(0, 0), wxSize(220, height
),
69 wxDEFAULT_DIALOG_STYLE
);
71 wxLayoutConstraints
*c
;
73 m_msg
= new wxStaticText(this, -1, message
);
74 c
= new wxLayoutConstraints
;
75 c
->left
.SameAs(this, wxLeft
, 10);
76 c
->top
.SameAs(this, wxTop
, 10);
79 m_msg
->SetConstraints(c
);
83 m_gauge
= new wxGauge(this, -1, maximum
);
84 c
= new wxLayoutConstraints
;
85 c
->left
.SameAs(this, wxLeft
, 2*LAYOUT_X_MARGIN
);
86 c
->top
.Below(m_msg
, 2*LAYOUT_Y_MARGIN
);
87 c
->right
.SameAs(this, wxRight
, 2*LAYOUT_X_MARGIN
);
89 m_gauge
->SetConstraints(c
);
93 m_gauge
= (wxGauge
*)NULL
;
97 m_btnAbort
= new wxButton(this, -1, _("Cancel"));
98 c
= new wxLayoutConstraints
;
99 c
->centreX
.SameAs(this, wxCentreX
);
101 c
->top
.Below(m_gauge
, 2*LAYOUT_Y_MARGIN
);
103 c
->top
.Below(m_btnAbort
, 2*LAYOUT_Y_MARGIN
);
106 m_btnAbort
->SetConstraints(c
);
109 m_btnAbort
= (wxButton
*)NULL
;
113 Centre(wxCENTER_FRAME
| wxBOTH
);
115 if(m_disableParentOnly
)
116 m_parent
->Enable(FALSE
);
118 wxEnableTopLevelWindows(FALSE
);
119 Enable(TRUE
); // enable this window
125 wxProgressDialog::Update(int value
, const wxString
& newmsg
)
127 wxASSERT_MSG( value
== -1 || m_gauge
, _T("can't update non existent dialog") );
128 wxASSERT_MSG( value
< m_maximum
, _T("invalid progress value") );
131 m_gauge
->SetValue(value
+ 1);
132 if( !newmsg
.IsEmpty() )
133 m_msg
->SetLabel(newmsg
);
135 if ( (value
== m_maximum
- 1) && !(GetWindowStyleFlag() & wxPD_AUTO_HIDE
) )
139 // tell the user what he should do...
140 m_btnAbort
->SetLabel(_("Close"));
145 // also provide the finishing message if the application didn't
146 m_msg
->SetLabel(_("Done."));
151 // so that we return TRUE below
155 return m_state
!= Canceled
;
158 void wxProgressDialog::OnClose(wxCloseEvent
& event
)
160 if ( m_state
== Uncancelable
)
167 wxProgressDialog::~wxProgressDialog()
169 if ( m_disableParentOnly
)
170 m_parent
->Enable(TRUE
);
172 wxEnableTopLevelWindows(TRUE
);