]> git.saurik.com Git - wxWidgets.git/blob - src/generic/progdlgg.cpp
new makefiles (part I)
[wxWidgets.git] / src / generic / progdlgg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: progdlgg.h
3 // Purpose: wxProgressDialog class
4 // Author: Karsten Ballüder
5 // Modified by:
6 // Created: 09.05.1999
7 // RCS-ID: $Id$
8 // Copyright: (c) Karsten Ballüder
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "progdlgg.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/utils.h"
25 #include "wx/frame.h"
26 #include "wx/button.h"
27 #include "wx/stattext.h"
28 #include "wx/layout.h"
29 #include "wx/event.h"
30 #include "wx/gauge.h"
31 #include "wx/intl.h"
32 #endif
33
34 #include "wx/generic/progdlgg.h"
35
36 #define LAYOUT_X_MARGIN 8
37 #define LAYOUT_Y_MARGIN 8
38
39 // wxTextEntryDialog
40
41 #if !USE_SHARED_LIBRARY
42 BEGIN_EVENT_TABLE(wxProgressDialog, wxFrame)
43 EVT_BUTTON(-1, wxProgressDialog::OnCancel)
44 EVT_CLOSE(wxProgressDialog::OnClose)
45 END_EVENT_TABLE()
46
47 IMPLEMENT_CLASS(wxProgressDialog, wxFrame)
48 #endif
49
50 wxProgressDialog::wxProgressDialog(wxString const &title,
51 wxString const &message,
52 int maximum,
53 wxWindow *parent,
54 int style)
55 {
56 bool hasAbortButton = (style & wxPD_CAN_ABORT) != 0;
57 m_state = hasAbortButton ? Continue : Uncancelable;
58 m_disableParentOnly = (style & wxPD_APP_MODAL) == 0;
59 m_parent = parent;
60 m_maximum = maximum;
61
62 int height = 70; // FIXME arbitrary numbers
63 if ( hasAbortButton )
64 height += 35;
65 wxFrame::Create(m_parent, -1, title,
66 wxPoint(0, 0), wxSize(220, height),
67 wxDEFAULT_DIALOG_STYLE);
68
69 wxLayoutConstraints *c;
70
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);
75 c->width.AsIs();
76 c->height.AsIs();
77 m_msg->SetConstraints(c);
78
79 if ( maximum > 0 )
80 {
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);
86 c->height.AsIs();
87 m_gauge->SetConstraints(c);
88 m_gauge->SetValue(0);
89 }
90 else
91 m_gauge = (wxGauge *)NULL;
92
93 if ( hasAbortButton )
94 {
95 m_btnAbort = new wxButton(this, -1, _("Cancel"));
96 c = new wxLayoutConstraints;
97 c->centreX.SameAs(this, wxCentreX);
98 if(m_gauge)
99 c->top.Below(m_gauge, 2*LAYOUT_Y_MARGIN);
100 else
101 c->top.Below(m_btnAbort, 2*LAYOUT_Y_MARGIN);
102 c->width.AsIs();
103 c->height.AsIs();
104 m_btnAbort->SetConstraints(c);
105 }
106 else
107 m_btnAbort = (wxButton *)NULL;
108
109 SetAutoLayout(TRUE);
110 Show(TRUE);
111 Centre(wxCENTER_FRAME | wxBOTH);
112
113 if(m_disableParentOnly)
114 m_parent->Enable(FALSE);
115 else
116 wxEnableTopLevelWindows(FALSE);
117 Enable(TRUE); // enable this window
118 wxYield();
119 }
120
121
122 bool
123 wxProgressDialog::Update(int value, const wxString& newmsg)
124 {
125 wxASSERT_MSG( value == -1 || m_gauge, _T("can't update non existent dialog") );
126 wxASSERT_MSG( value < m_maximum, _T("invalid progress value") );
127
128 if( m_gauge )
129 m_gauge->SetValue(value + 1);
130 if( !newmsg.IsEmpty() )
131 m_msg->SetLabel(newmsg);
132 wxYield();
133
134 if ( (value == m_maximum - 1) && !(GetWindowStyleFlag() & wxPD_AUTO_HIDE) )
135 {
136 if ( m_btnAbort )
137 {
138 // tell the user what he should do...
139 m_btnAbort->SetLabel(_("Close"));
140 }
141
142 if ( !newmsg )
143 {
144 // also provide the finishing message if the application didn't
145 m_msg->SetLabel(_("Done."));
146 }
147
148 m_state = Finished;
149 while ( m_state != Canceled ) // set from OnClose()
150 wxYield();
151
152 // so that we return TRUE below
153 m_state = Finished;
154 }
155
156 return m_state != Canceled;
157 }
158
159 void wxProgressDialog::OnClose(wxCloseEvent& event)
160 {
161 if ( m_state == Uncancelable )
162 event.Veto(TRUE);
163 else
164 m_state = Canceled;
165 }
166
167
168 wxProgressDialog::~wxProgressDialog()
169 {
170 if ( m_disableParentOnly )
171 m_parent->Enable(TRUE);
172 else
173 wxEnableTopLevelWindows(TRUE);
174 }