]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/progdlgg.cpp
8bb26d9041ad5272e78fe8e32fd73b5c1707756c
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxProgressDialog class
4 // Author: Karsten Ballüder
8 // Copyright: (c) Karsten Ballüder
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "progdlgg.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/button.h"
27 #include "wx/stattext.h"
28 #include "wx/layout.h"
32 #include "wx/settings.h"
37 #include "wx/generic/progdlgg.h"
39 #define LAYOUT_X_MARGIN 8
40 #define LAYOUT_Y_MARGIN 8
44 #if !USE_SHARED_LIBRARY
45 BEGIN_EVENT_TABLE(wxProgressDialog
, wxFrame
)
46 EVT_BUTTON(-1, wxProgressDialog::OnCancel
)
47 EVT_CLOSE(wxProgressDialog::OnClose
)
50 IMPLEMENT_CLASS(wxProgressDialog
, wxFrame
)
53 wxProgressDialog::wxProgressDialog(wxString
const &title
,
54 wxString
const &message
,
59 bool hasAbortButton
= (style
& wxPD_CAN_ABORT
) != 0;
60 m_state
= hasAbortButton
? Continue
: Uncancelable
;
61 m_disableParentOnly
= (style
& wxPD_APP_MODAL
) == 0;
65 wxFrame::Create(m_parent
, -1, title
);
66 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
68 wxLayoutConstraints
*c
;
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);
76 m_msg
->SetConstraints(c
);
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
);
88 m_gauge
->SetConstraints(c
);
92 m_gauge
= (wxGauge
*)NULL
;
96 m_btnAbort
= new wxButton(this, -1, _("Cancel"));
97 c
= new wxLayoutConstraints
;
98 c
->centreX
.SameAs(this, wxCentreX
);
100 c
->top
.Below(m_gauge
, 2*LAYOUT_Y_MARGIN
);
102 c
->top
.Below(m_btnAbort
, 2*LAYOUT_Y_MARGIN
);
105 m_btnAbort
->SetConstraints(c
);
108 m_btnAbort
= (wxButton
*)NULL
;
113 // calc the height of the dialog
115 // and set the width from it
116 wxSize size
= GetClientSize();
117 if(size
.x
< 2*size
.y
)
118 SetClientSize(2*size
.y
, size
.y
);
121 Centre(wxCENTER_FRAME
| wxBOTH
);
123 if(m_disableParentOnly
)
124 m_parent
->Enable(FALSE
);
126 wxEnableTopLevelWindows(FALSE
);
128 Enable(TRUE
); // enable this window
134 wxProgressDialog::Update(int value
, const wxString
& newmsg
)
136 wxASSERT_MSG( value
== -1 || m_gauge
, _T("can't update non existent dialog") );
137 wxASSERT_MSG( value
< m_maximum
, _T("invalid progress value") );
141 m_gauge
->SetValue(value
+ 1);
143 if( !newmsg
.IsEmpty() )
144 m_msg
->SetLabel(newmsg
);
146 if ( (value
== m_maximum
- 1) && !(GetWindowStyleFlag() & wxPD_AUTO_HIDE
) )
150 // tell the user what he should do...
151 m_btnAbort
->SetLabel(_("Close"));
156 // also provide the finishing message if the application didn't
157 m_msg
->SetLabel(_("Done."));
162 // so that we return TRUE below
166 return m_state
!= Canceled
;
169 void wxProgressDialog::OnClose(wxCloseEvent
& event
)
171 if ( m_state
== Uncancelable
)
178 wxProgressDialog::~wxProgressDialog()
180 if ( m_disableParentOnly
)
181 m_parent
->Enable(TRUE
);
183 wxEnableTopLevelWindows(TRUE
);