OSDN Git Service

Cancelボタンを削除し、処理の中断を右上の閉じるボタンで行うよう変更。
[tpi/lychee.git] / src / frontend / dlg_process.cpp
1 /*******************************************************************************\r
2   TPI - flexible but useless plug-in framework.\r
3   Copyright (C) 2002-2009 Silky\r
4 \r
5   This library is free software; you can redistribute it and/or modify it under\r
6   the terms of the GNU Lesser General Public License as published by the Free\r
7   Software Foundation; either version 2.1 of the License, or (at your option)\r
8   any later version.\r
9 \r
10   This library is distributed in the hope that it will be useful, but WITHOUT\r
11   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or \r
12   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License\r
13   for more details.\r
14 \r
15   You should have received a copy of the GNU Lesser General Public License along\r
16   with this library; if not, write to the Free Software Foundation, Inc.,\r
17   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
18 \r
19   $Id: dlg_process.cpp,v 1.6 2009/09/01 12:20:49 sirakaba Exp $\r
20 *******************************************************************************/\r
21 \r
22 #include "frontend.h"\r
23 #include "dlg_process.h"\r
24 \r
25 ProcessDialog * g_procDlg = NULL;\r
26 \r
27 //******************************************************************************\r
28 // ProcessDialog\r
29 //******************************************************************************\r
30 \r
31 ProcessDialog::ProcessDialog(): wxDialog()\r
32 {\r
33 }\r
34 \r
35 ProcessDialog::~ProcessDialog()\r
36 {\r
37         g_procDlg = NULL;\r
38 }\r
39 \r
40 //******************************************************************************\r
41 // Event table.\r
42 //******************************************************************************\r
43 \r
44 BEGIN_EVENT_TABLE(ProcessDialog, wxDialog)\r
45         EVT_INIT_DIALOG(ProcessDialog::OnInit)\r
46         EVT_CLOSE(      ProcessDialog::OnClose)\r
47 END_EVENT_TABLE()\r
48 \r
49 //******************************************************************************\r
50 // Event handler.\r
51 //******************************************************************************\r
52 \r
53 void ProcessDialog::OnInit(wxInitDialogEvent &)\r
54 {\r
55         // XRC\82Æ\8c\8b\82Ñ\82Â\82¯\81B\r
56         this->ebSource          = XRCCTRL(* this, "ebSource",     wxTextCtrl);\r
57         this->ebTarget          = XRCCTRL(* this, "ebTarget",     wxTextCtrl);\r
58         this->gauge             = XRCCTRL(* this, "gauge",        wxGauge);\r
59         this->fCancel           = false;\r
60         g_procDlg = this;\r
61 \r
62         ::wxXmlResource::Get()->Unload(FE_DIR_S_XRC wxT("dlg_process.xrc"));\r
63 }\r
64 \r
65 void ProcessDialog::OnClose(wxCloseEvent & e)\r
66 {\r
67         if (e.CanVeto() && ::wxMessageBox(wxT("Really do you want to cancel this operation?"), wxMessageBoxCaptionStr, wxYES_NO | wxICON_EXCLAMATION, g_procDlg) == wxYES)\r
68         {\r
69                 this->fCancel = true;\r
70         }\r
71         e.Veto();\r
72 }\r
73 \r
74 //******************************************************************************\r
75 //    \83_\83C\83A\83\8d\83O\83v\83\8d\83V\81[\83W\83\83\r
76 //******************************************************************************\r
77 \r
78 int __stdcall TPICallbackProc(unsigned int _uMsg, void * _pStructure)\r
79 {\r
80         if (_uMsg != TPI_NOTIFY_COMMON)\r
81         {\r
82                 return TPI_CALLBACK_UNSUPPORTED;\r
83         }\r
84 \r
85         TPI_PROCESSINFO * piInfo = (TPI_PROCESSINFO *) _pStructure;\r
86         if (g_procDlg == NULL || piInfo == NULL || piInfo->uMessage != TPI_MESSAGE_STATUS || ! g_procDlg->IsShown())\r
87         {\r
88                 return TPI_CALLBACK_CONTINUE;\r
89         }\r
90 \r
91         static int s_nGaugeCounter = 0;\r
92         switch (piInfo->uStatus)\r
93         {\r
94         case TPI_STATUS_OPENARCHIVE:\r
95                 g_procDlg->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());\r
96                 break;\r
97         case TPI_STATUS_BEGINPROCESS:\r
98                 g_procDlg->ebTarget->ChangeValue((piInfo->fnDestination.IsOk() ? piInfo->fnDestination : piInfo->fiInfo.fnFileName).GetFullPath());\r
99                 if (piInfo->fiInfo.llUnpackedSize > 10000)\r
100                 {\r
101                         g_procDlg->gauge->SetRange(piInfo->fiInfo.llUnpackedSize.ToULong());\r
102                         g_procDlg->gauge->SetValue(0);\r
103                 }\r
104                 ::wxSafeYield(g_procDlg, true);\r
105                 break;\r
106         case TPI_STATUS_INPROCESS:\r
107                 if (s_nGaugeCounter++ > 100)\r
108                 {\r
109                         if (piInfo->fiInfo.llUnpackedSize > 10000)\r
110                         {\r
111                                 g_procDlg->gauge->SetValue(piInfo->llProcessedSize.ToULong());\r
112                         }\r
113                         ::wxSafeYield(g_procDlg, true);\r
114                         s_nGaugeCounter = 0;\r
115                 }\r
116                 break;\r
117         case TPI_STATUS_ENDPROCESS:\r
118 //              g_procDlg->gauge->SetValue(piInfo->fiInfo.llUnpackedSize.ToULong());\r
119                 break;\r
120         // \8f\91\8cÉ\83\8d\81[\83h\8e\9e\97p\82Ì\93Æ\8e©\8ed\97l\81B\r
121         case 0x1000:\r
122                 g_procDlg->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());\r
123                 g_procDlg->gauge->SetRange(piInfo->fiInfo.llUnpackedSize.ToULong());\r
124                 g_procDlg->gauge->SetValue(0);\r
125                 break;\r
126         case 0x1001:\r
127                 // \8dX\90V\82µ\82·\82¬\82é\82Æ\92á\91¬\82È\82Ì\82Å100\83t\83@\83C\83\8b\96\88\82É\8dX\90V\82·\82é\81B\r
128                 if (piInfo->llProcessedSize > g_procDlg->gauge->GetValue() + 100)\r
129                 {\r
130                         g_procDlg->ebTarget->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());\r
131                         ::wxSafeYield(g_procDlg, true);\r
132                 }\r
133                 break;\r
134         case 0x1002:\r
135                 if (piInfo->llProcessedSize > g_procDlg->gauge->GetValue() + 100)\r
136                 {\r
137                         g_procDlg->gauge->SetValue(piInfo->llProcessedSize.ToULong());\r
138                 }\r
139                 break;\r
140         }\r
141 \r
142         return g_procDlg->fCancel ? TPI_CALLBACK_CANCEL : TPI_CALLBACK_CONTINUE;\r
143 }\r