]> git.saurik.com Git - wxWidgets.git/blob - src/generic/progdlgg.cpp
Fixed core dump for when there is no image list on the TreeCtrl
[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
135 if ( (value == m_maximum - 1) && !(GetWindowStyleFlag() & wxPD_AUTO_HIDE) )
136 {
137 if ( m_btnAbort )
138 {
139 // tell the user what he should do...
140 m_btnAbort->SetLabel(_("Close"));
141 }
142
143 if ( !newmsg )
144 {
145 // also provide the finishing message if the application didn't
146 m_msg->SetLabel(_("Done."));
147 }
148
149 m_state = Finished;
150
151 // so that we return TRUE below
152 m_state = Finished;
153 }
154
155 return m_state != Canceled;
156 }
157
158 void wxProgressDialog::OnClose(wxCloseEvent& event)
159 {
160 if ( m_state == Uncancelable )
161 event.Veto(TRUE);
162 else
163 m_state = Canceled;
164 }
165
166
167 wxProgressDialog::~wxProgressDialog()
168 {
169 if ( m_disableParentOnly )
170 m_parent->Enable(TRUE);
171 else
172 wxEnableTopLevelWindows(TRUE);
173 }
174
175 #endif