]> git.saurik.com Git - wxWidgets.git/blob - src/generic/progdlgg.cpp
repaired recently broken framelayout
[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 bool parentOnly,
55 bool abortButton)
56 {
57 m_state = abortButton ? Continue : Uncancelable;
58 m_disableParentOnly = parentOnly;
59 m_parent = parent;
60
61 int height = 70; // FIXME arbitrary numbers
62 if ( abortButton )
63 height += 35;
64 wxFrame::Create(m_parent, -1, title,
65 wxPoint(0, 0), wxSize(220, height),
66 wxDEFAULT_DIALOG_STYLE);
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 c = new wxLayoutConstraints;
82 c->left.SameAs(this, wxLeft, 2*LAYOUT_X_MARGIN);
83 c->top.Below(m_msg, 2*LAYOUT_Y_MARGIN);
84 c->right.SameAs(this, wxRight, 2*LAYOUT_X_MARGIN);
85 c->height.AsIs();
86 m_gauge->SetConstraints(c);
87 m_gauge->SetValue(0);
88 }
89 else
90 m_gauge = NULL;
91
92 if ( abortButton )
93 {
94 wxControl *ctrl = new wxButton(this, -1, _("Cancel"));
95 c = new wxLayoutConstraints;
96 c->centreX.SameAs(this, wxCentreX);
97 if(m_gauge)
98 c->top.Below(m_gauge, 2*LAYOUT_Y_MARGIN);
99 else
100 c->top.Below(ctrl, 2*LAYOUT_Y_MARGIN);
101 c->width.AsIs();
102 c->height.AsIs();
103 ctrl->SetConstraints(c);
104 }
105
106 SetAutoLayout(TRUE);
107 Show(TRUE);
108 Centre(wxCENTER_FRAME | wxBOTH);
109
110 if(m_disableParentOnly)
111 m_parent->Enable(false);
112 else
113 wxEnableTopLevelWindows(false);
114 Enable(true); // enable this window
115 wxYield();
116 }
117
118
119 bool
120 wxProgressDialog::Update(int value, const wxString& newmsg)
121 {
122 wxASSERT(value == -1 || m_gauge);
123 if(m_gauge)
124 m_gauge->SetValue(value);
125 if(!newmsg.IsNull())
126 m_msg->SetLabel(newmsg);
127 wxYield();
128 return m_state != Canceled;
129 }
130
131 void wxProgressDialog::OnClose(wxCloseEvent& event)
132 {
133 if ( m_state == Uncancelable )
134 event.Veto(TRUE);
135 else
136 m_state = Canceled;
137 }
138
139
140 wxProgressDialog::~wxProgressDialog()
141 {
142 if(m_disableParentOnly)
143 m_parent->Enable(true);
144 else
145 wxEnableTopLevelWindows(true);
146 }