| 1 | /////////////////////////////////////////////////////////////////////////////// |
| 2 | // Name: src/palmos/progdlg.cpp |
| 3 | // Purpose: wxProgressDialog implementation |
| 4 | // Author: Wlodzimierz ABX Skiba |
| 5 | // Modified by: |
| 6 | // Created: 29.12.2004 |
| 7 | // RCS-ID: $Id$ |
| 8 | // Copyright: (c) Wlodzimierz Skiba |
| 9 | // License: wxWindows licence |
| 10 | /////////////////////////////////////////////////////////////////////////////// |
| 11 | |
| 12 | // For compilers that support precompilation, includes "wx.h". |
| 13 | #include "wx/wxprec.h" |
| 14 | |
| 15 | #ifdef __BORLANDC__ |
| 16 | #pragma hdrstop |
| 17 | #endif |
| 18 | |
| 19 | #if wxUSE_PROGRESSDLG |
| 20 | |
| 21 | #include "wx/progdlg.h" |
| 22 | |
| 23 | #ifndef WX_PRECOMP |
| 24 | #include "wx/string.h" |
| 25 | #include "wx/msgdlg.h" |
| 26 | #endif //WX_PRECOMP |
| 27 | |
| 28 | #include <Progress.h> |
| 29 | #include <SysEvtMgr.h> |
| 30 | |
| 31 | IMPLEMENT_CLASS(wxProgressDialog, wxDialog) |
| 32 | |
| 33 | static Boolean wxProgressCallback(PrgCallbackData *data) |
| 34 | { |
| 35 | if(!data) |
| 36 | return false; |
| 37 | |
| 38 | wxProgressDialog *dialog = (wxProgressDialog *)data->userDataP; |
| 39 | |
| 40 | if(!dialog) |
| 41 | return false; |
| 42 | |
| 43 | return dialog->Callback(data); |
| 44 | } |
| 45 | |
| 46 | wxProgressDialog::wxProgressDialog(const wxString &title, |
| 47 | wxString const &message, |
| 48 | int maximum, |
| 49 | wxWindow *parent, |
| 50 | int style) |
| 51 | :wxDialog(parent, wxID_ANY, title), |
| 52 | m_prgFrame(NULL), |
| 53 | m_msg(message), |
| 54 | m_cur(0), |
| 55 | m_max(maximum), |
| 56 | m_canSkip((style & wxPD_CAN_SKIP )==wxPD_CAN_SKIP) |
| 57 | { |
| 58 | wxString prgTitle = title.Mid(0, progressMaxTitle); |
| 59 | |
| 60 | m_prgFrame = PrgStartDialog(prgTitle.ToAscii(), wxProgressCallback, this); |
| 61 | } |
| 62 | |
| 63 | wxProgressDialog::~wxProgressDialog() |
| 64 | { |
| 65 | if(m_prgFrame) |
| 66 | { |
| 67 | PrgStopDialog((ProgressType *)m_prgFrame, false); |
| 68 | m_prgFrame = NULL; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | bool wxProgressDialog::Update(int value, const wxString& newmsg, bool *skip) |
| 73 | { |
| 74 | if(!m_prgFrame) |
| 75 | return false; |
| 76 | if(!newmsg.empty()) |
| 77 | m_msg = newmsg; |
| 78 | m_cur = value; |
| 79 | |
| 80 | EventType event; |
| 81 | |
| 82 | ProgressType *prg = (ProgressType *)m_prgFrame; |
| 83 | do |
| 84 | { |
| 85 | EvtGetEvent(&event, 0); |
| 86 | Boolean handled = PrgHandleEvent(prg, &event); |
| 87 | if (!PrgHandleEvent(prg, &event)) |
| 88 | if( PrgUserCancel(prg) ) |
| 89 | return false; |
| 90 | } |
| 91 | while(event.eType != sysEventNilEvent); |
| 92 | |
| 93 | PrgUpdateDialog(prg, 0, 0, "", true); |
| 94 | |
| 95 | m_activeSkip = m_canSkip && true; |
| 96 | |
| 97 | return true; |
| 98 | } |
| 99 | |
| 100 | void wxProgressDialog::Resume() |
| 101 | { |
| 102 | } |
| 103 | |
| 104 | bool wxProgressDialog::Show(bool show) |
| 105 | { |
| 106 | return false; |
| 107 | } |
| 108 | |
| 109 | Boolean wxProgressDialog::Callback(void *data) |
| 110 | { |
| 111 | PrgCallbackData *palmData = (PrgCallbackData *)data; |
| 112 | strncpy( palmData->textP, m_msg.ToAscii() , palmData->textLen - 1 ); |
| 113 | palmData->textChanged = true; |
| 114 | palmData->displaySkipBtn = m_canSkip; |
| 115 | palmData->barMaxValue = (uint32_t)m_max; |
| 116 | palmData->barCurValue = (uint32_t)m_cur; |
| 117 | palmData->delay = (m_max == m_cur); |
| 118 | |
| 119 | return true; |
| 120 | } |
| 121 | |
| 122 | #endif // wxUSE_PROGRESSDLG |