]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/progdlgg.cpp
dfd8873c600b22a3ca2dd99468692c4e8ba1e083
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
, wxDefaultPosition
,
66 wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
);
67 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
69 wxLayoutConstraints
*c
;
72 dc
.SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
74 dc
.GetTextExtent(message
, &widthText
, NULL
);
76 m_msg
= new wxStaticText(this, -1, message
);
77 c
= new wxLayoutConstraints
;
78 c
->left
.SameAs(this, wxLeft
, 10);
79 c
->top
.SameAs(this, wxTop
, 10);
82 m_msg
->SetConstraints(c
);
86 m_gauge
= new wxGauge(this, -1, maximum
,
87 wxDefaultPosition
, wxDefaultSize
,
88 wxGA_HORIZONTAL
| wxRAISED_BORDER
);
89 c
= new wxLayoutConstraints
;
90 c
->left
.SameAs(this, wxLeft
, 2*LAYOUT_X_MARGIN
);
91 c
->top
.Below(m_msg
, 2*LAYOUT_Y_MARGIN
);
92 c
->right
.SameAs(this, wxRight
, 2*LAYOUT_X_MARGIN
);
94 m_gauge
->SetConstraints(c
);
98 m_gauge
= (wxGauge
*)NULL
;
100 if ( hasAbortButton
)
102 m_btnAbort
= new wxButton(this, -1, _("Cancel"));
103 c
= new wxLayoutConstraints
;
104 c
->centreX
.SameAs(this, wxCentreX
);
106 c
->top
.Below(m_gauge
, 2*LAYOUT_Y_MARGIN
);
108 c
->top
.Below(m_btnAbort
, 2*LAYOUT_Y_MARGIN
);
111 m_btnAbort
->SetConstraints(c
);
114 m_btnAbort
= (wxButton
*)NULL
;
119 // calc the height of the dialog
121 // and set the width from it - unfortunately, Fit() makes the dialog way too
122 // wide under Windows, so try to find a reasonable value for the width, not
123 // too big and not too small
124 wxSize size
= GetClientSize();
125 size
.x
= 2*widthText
;
126 if ( size
.x
< 2*size
.y
)
127 SetClientSize(2*size
.y
, size
.y
);
130 Centre(wxCENTER_FRAME
| wxBOTH
);
132 if(m_disableParentOnly
)
133 m_parent
->Enable(FALSE
);
135 wxEnableTopLevelWindows(FALSE
);
137 Enable(TRUE
); // enable this window
143 wxProgressDialog::Update(int value
, const wxString
& newmsg
)
145 wxASSERT_MSG( value
== -1 || m_gauge
, _T("can't update non existent dialog") );
146 wxASSERT_MSG( value
< m_maximum
, _T("invalid progress value") );
150 m_gauge
->SetValue(value
+ 1);
152 if( !newmsg
.IsEmpty() )
153 m_msg
->SetLabel(newmsg
);
155 if ( (value
== m_maximum
- 1) && !(GetWindowStyleFlag() & wxPD_AUTO_HIDE
) )
159 // tell the user what he should do...
160 m_btnAbort
->SetLabel(_("Close"));
165 // also provide the finishing message if the application didn't
166 m_msg
->SetLabel(_("Done."));
171 // so that we return TRUE below
175 return m_state
!= Canceled
;
178 void wxProgressDialog::OnClose(wxCloseEvent
& event
)
180 if ( m_state
== Uncancelable
)
187 wxProgressDialog::~wxProgressDialog()
189 if ( m_disableParentOnly
)
190 m_parent
->Enable(TRUE
);
192 wxEnableTopLevelWindows(TRUE
);