| 1 | /* |
|---|
| 2 | ----------------------------------------------------------------------------- |
|---|
| 3 | This source file is part of LEXIExporter |
|---|
| 4 | |
|---|
| 5 | Copyright 2006 NDS Limited |
|---|
| 6 | |
|---|
| 7 | Author(s): |
|---|
| 8 | Mark Folkenberg, |
|---|
| 9 | Bo Krohn |
|---|
| 10 | |
|---|
| 11 | This program is free software; you can redistribute it and/or modify it under |
|---|
| 12 | the terms of the GNU Lesser General Public License as published by the Free Software |
|---|
| 13 | Foundation; either version 2 of the License, or (at your option) any later |
|---|
| 14 | version. |
|---|
| 15 | |
|---|
| 16 | This program is distributed in the hope that it will be useful, but WITHOUT |
|---|
| 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|---|
| 18 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
|---|
| 19 | |
|---|
| 20 | You should have received a copy of the GNU Lesser General Public License along with |
|---|
| 21 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
|---|
| 22 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
|---|
| 23 | http://www.gnu.org/copyleft/lesser.txt. |
|---|
| 24 | ----------------------------------------------------------------------------- |
|---|
| 25 | */ |
|---|
| 26 | |
|---|
| 27 | #include "LexiStdAfx.h" |
|---|
| 28 | #include "LexiMaxExport.h" |
|---|
| 29 | #include "LexiDialogProgress.h" |
|---|
| 30 | #include "LexiExportObject.h" |
|---|
| 31 | |
|---|
| 32 | #include "..\Res\resource.h" |
|---|
| 33 | |
|---|
| 34 | // |
|---|
| 35 | CExportProgressDlg::CExportProgressDlg(Window* pParent) : Dialog(IDD_DIALOG_PROGRESS, DlgProc, pParent) |
|---|
| 36 | { |
|---|
| 37 | m_iTotalGlobal=0; |
|---|
| 38 | m_iGlobalProgress=0; |
|---|
| 39 | m_bAbortRequest=false; |
|---|
| 40 | m_bAbortFlag=false; |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | CExportProgressDlg::~CExportProgressDlg() |
|---|
| 44 | { |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | // Initialize global stepping |
|---|
| 48 | void CExportProgressDlg::InitGlobal(int iObjectCount) |
|---|
| 49 | { |
|---|
| 50 | m_pGlobalProgress->SendMessage(PBM_SETRANGE, 0, MAKELPARAM(0, iObjectCount+1)); |
|---|
| 51 | m_iGlobalProgress=0; |
|---|
| 52 | m_iTotalGlobal=iObjectCount; |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | // Do a global step (once per ExportObject) |
|---|
| 56 | void CExportProgressDlg::GlobalStep() |
|---|
| 57 | { |
|---|
| 58 | ++m_iGlobalProgress; |
|---|
| 59 | _snprintf_s(m_InfoBuffer, 1024, "Exporting %d of %d", m_iGlobalProgress, m_iTotalGlobal); |
|---|
| 60 | m_pGlobalInfo->SetWindowText(m_InfoBuffer); |
|---|
| 61 | m_pGlobalProgress->SendMessage(PBM_SETPOS, m_iGlobalProgress, 0); |
|---|
| 62 | |
|---|
| 63 | // Pump messages |
|---|
| 64 | MSG winmsg; |
|---|
| 65 | while(PeekMessage(&winmsg, NULL, 0, 0, PM_REMOVE)) |
|---|
| 66 | { |
|---|
| 67 | TranslateMessage(&winmsg); |
|---|
| 68 | DispatchMessage(&winmsg); |
|---|
| 69 | } |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | // Initialize local progress |
|---|
| 73 | void CExportProgressDlg::InitLocal(int iStepCount) |
|---|
| 74 | { |
|---|
| 75 | m_pLocalProgress->SendMessage(PBM_SETRANGE, 0, MAKELPARAM(0, iStepCount+1)); |
|---|
| 76 | m_iLocalProgress=0; |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | // Do a local step |
|---|
| 80 | void CExportProgressDlg::LocalStep(const char *pszDesc) |
|---|
| 81 | { |
|---|
| 82 | ++m_iLocalProgress; |
|---|
| 83 | if(pszDesc!=NULL) m_pLocalInfo->SetWindowText(pszDesc); |
|---|
| 84 | m_pLocalProgress->SendMessage(PBM_SETPOS, m_iLocalProgress, 0); |
|---|
| 85 | |
|---|
| 86 | // Pump messages |
|---|
| 87 | MSG winmsg; |
|---|
| 88 | while(PeekMessage(&winmsg, NULL, 0, 0, PM_REMOVE)) |
|---|
| 89 | { |
|---|
| 90 | TranslateMessage(&winmsg); |
|---|
| 91 | DispatchMessage(&winmsg); |
|---|
| 92 | } |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | // Signal export done |
|---|
| 96 | void CExportProgressDlg::ExportDone(void) |
|---|
| 97 | { |
|---|
| 98 | DestroyWindow(); |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | // Check if we want to abort current export |
|---|
| 102 | bool CExportProgressDlg::CheckAbort() |
|---|
| 103 | { |
|---|
| 104 | if(m_bAbortFlag) return true; |
|---|
| 105 | |
|---|
| 106 | if(m_bAbortRequest) |
|---|
| 107 | { |
|---|
| 108 | int rs = MessageBox("Do you want to abort current export?", NDS_EXPORTER_TITLE, MB_YESNO | MB_ICONWARNING); |
|---|
| 109 | if(rs != IDYES) |
|---|
| 110 | { |
|---|
| 111 | m_bAbortRequest=false; |
|---|
| 112 | return false; |
|---|
| 113 | } |
|---|
| 114 | m_bAbortFlag=true; |
|---|
| 115 | return true; |
|---|
| 116 | } |
|---|
| 117 | return false; |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | // |
|---|
| 121 | INT_PTR CALLBACK CExportProgressDlg::DlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) |
|---|
| 122 | { |
|---|
| 123 | CExportProgressDlg* pThis = (CExportProgressDlg*)Window::GetMapping(hWnd); |
|---|
| 124 | |
|---|
| 125 | switch(message) |
|---|
| 126 | { |
|---|
| 127 | case WM_INITDIALOG: |
|---|
| 128 | { |
|---|
| 129 | pThis = (CExportProgressDlg*)lParam; |
|---|
| 130 | Window::AddMapping(pThis, hWnd); |
|---|
| 131 | |
|---|
| 132 | pThis->OnInitDialog(); |
|---|
| 133 | |
|---|
| 134 | } return 0; |
|---|
| 135 | |
|---|
| 136 | case WM_COMMAND: |
|---|
| 137 | { |
|---|
| 138 | switch(LOWORD(wParam)) |
|---|
| 139 | { |
|---|
| 140 | case IDC_ABORT: |
|---|
| 141 | pThis->OnAbort(); |
|---|
| 142 | break; |
|---|
| 143 | } |
|---|
| 144 | } break; |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | return 0; |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | // |
|---|
| 151 | |
|---|
| 152 | void CExportProgressDlg::OnInitDialog() |
|---|
| 153 | { |
|---|
| 154 | m_pGlobalInfo=GetDlgItem(IDC_EXPORTINFO); |
|---|
| 155 | m_pGlobalProgress=GetDlgItem(IDC_GLOBALPROGRESS); |
|---|
| 156 | m_pLocalInfo=GetDlgItem(IDC_LOCALINFO); |
|---|
| 157 | m_pLocalProgress=GetDlgItem(IDC_LOCALPROGRESS); |
|---|
| 158 | m_pGlobalInfo->SetWindowText("Counting..."); |
|---|
| 159 | m_pLocalInfo->SetWindowText(""); |
|---|
| 160 | CenterWindow(); |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | void CExportProgressDlg::OnAbort() |
|---|
| 165 | { |
|---|
| 166 | m_bAbortRequest=true; |
|---|
| 167 | } |
|---|