]> git.saurik.com Git - wxWidgets.git/blob - src/generic/progdlgg.cpp
keyboard/focus handling improved a bit more:
[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 #if wxUSE_PROGRESSDLG
35
36 #include "wx/generic/progdlgg.h"
37
38 #define LAYOUT_X_MARGIN 8
39 #define LAYOUT_Y_MARGIN 8
40
41 // wxTextEntryDialog
42
43 #if !USE_SHARED_LIBRARY
44 BEGIN_EVENT_TABLE(wxProgressDialog, wxFrame)
45 EVT_BUTTON(-1, wxProgressDialog::OnCancel)
46 EVT_CLOSE(wxProgressDialog::OnClose)
47 END_EVENT_TABLE()
48
49 IMPLEMENT_CLASS(wxProgressDialog, wxFrame)
50 #endif
51
52 wxProgressDialog::wxProgressDialog(wxString const &title,
53 wxString const &message,
54 int maximum,
55 wxWindow *parent,
56 int style)
57 {
58 bool hasAbortButton = (style & wxPD_CAN_ABORT) != 0;
59 m_state = hasAbortButton ? Continue : Uncancelable;
60 m_disableParentOnly = (style & wxPD_APP_MODAL) == 0;
61 m_parent = parent;
62 m_maximum = maximum;
63
64 int height = 70; // FIXME arbitrary numbers
65 if ( hasAbortButton )
66 height += 35;
67 wxFrame::Create(m_parent, -1, title,
68 wxPoint(0, 0), wxSize(220, height),
69 wxDEFAULT_DIALOG_STYLE);
70
71 wxLayoutConstraints *c;
72
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);
77 c->width.AsIs();
78 c->height.AsIs();
79 m_msg->SetConstraints(c);
80
81 if ( maximum > 0 )
82 {
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);
88 c->height.AsIs();
89 m_gauge->SetConstraints(c);
90 m_gauge->SetValue(0);
91 }
92 else
93 m_gauge = (wxGauge *)NULL;
94
95 if ( hasAbortButton )
96 {
97 m_btnAbort = new wxButton(this, -1, _("Cancel"));
98 c = new wxLayoutConstraints;
99 c->centreX.SameAs(this, wxCentreX);
100 if(m_gauge)
101 c->top.Below(m_gauge, 2*LAYOUT_Y_MARGIN);
102 else
103 c->top.Below(m_btnAbort, 2*LAYOUT_Y_MARGIN);
104 c->width.AsIs();
105 c->height.AsIs();
106 m_btnAbort->SetConstraints(c);
107 }
108 else
109 m_btnAbort = (wxButton *)NULL;
110
111 SetAutoLayout(TRUE);
112 Show(TRUE);
113 Centre(wxCENTER_FRAME | wxBOTH);
114
115 if(m_disableParentOnly)
116 m_parent->Enable(FALSE);
117 else
118 wxEnableTopLevelWindows(FALSE);
119 Enable(TRUE); // enable this window
120 wxYield();
121 }
122
123
124 bool
125 wxProgressDialog::Update(int value, const wxString& newmsg)
126 {
127 wxASSERT_MSG( value == -1 || m_gauge, _T("can't update non existent dialog") );
128 wxASSERT_MSG( value < m_maximum, _T("invalid progress value") );
129
130 if( m_gauge )
131 m_gauge->SetValue(value + 1);
132 if( !newmsg.IsEmpty() )
133 m_msg->SetLabel(newmsg);
134 wxYield();
135
136 if ( (value == m_maximum - 1) && !(GetWindowStyleFlag() & wxPD_AUTO_HIDE) )
137 {
138 if ( m_btnAbort )
139 {
140 // tell the user what he should do...
141 m_btnAbort->SetLabel(_("Close"));
142 }
143
144 if ( !newmsg )
145 {
146 // also provide the finishing message if the application didn't
147 m_msg->SetLabel(_("Done."));
148 }
149
150 m_state = Finished;
151 while ( m_state != Canceled ) // set from OnClose()
152 wxYield();
153
154 // so that we return TRUE below
155 m_state = Finished;
156 }
157
158 return m_state != Canceled;
159 }
160
161 void wxProgressDialog::OnClose(wxCloseEvent& event)
162 {
163 if ( m_state == Uncancelable )
164 event.Veto(TRUE);
165 else
166 m_state = Canceled;
167 }
168
169
170 wxProgressDialog::~wxProgressDialog()
171 {
172 if ( m_disableParentOnly )
173 m_parent->Enable(TRUE);
174 else
175 wxEnableTopLevelWindows(TRUE);
176 }
177
178 #endif