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