OSDN Git Service

XRCのロード部分をProcessDialog内に移動。
[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         ::wxXmlResource::Get()->Load(FE_DIR_S_XRC wxT("dlg_process.xrc"));
34         ::wxXmlResource::Get()->LoadDialog(this, this->GetParent(), wxT("dlg_process"));        
35 }\r
36 \r
37 ProcessDialog::~ProcessDialog()\r
38 {\r
39         g_procDlg = NULL;\r
40 }\r
41 \r
42 //******************************************************************************\r
43 // Event table.\r
44 //******************************************************************************\r
45 \r
46 BEGIN_EVENT_TABLE(ProcessDialog, wxDialog)\r
47         EVT_INIT_DIALOG(ProcessDialog::OnInit)\r
48         EVT_CLOSE(      ProcessDialog::OnClose)\r
49 END_EVENT_TABLE()\r
50 \r
51 //******************************************************************************\r
52 // Event handler.\r
53 //******************************************************************************\r
54 \r
55 void ProcessDialog::OnInit(wxInitDialogEvent &)\r
56 {\r
57         // XRC\82Æ\8c\8b\82Ñ\82Â\82¯\81B\r
58         this->ebSource          = XRCCTRL(* this, "ebSource",     wxTextCtrl);\r
59         this->ebTarget          = XRCCTRL(* this, "ebTarget",     wxTextCtrl);\r
60         this->gauge             = XRCCTRL(* this, "gauge",        wxGauge);\r
61         this->fCancel           = false;\r
62         g_procDlg = this;\r
63 \r
64         ::wxXmlResource::Get()->Unload(FE_DIR_S_XRC wxT("dlg_process.xrc"));\r
65 }\r
66 \r
67 void ProcessDialog::OnClose(wxCloseEvent & e)\r
68 {\r
69         if (e.CanVeto() && ::AskDlg(wxT("Really do you want to cancel this operation?"), this) == wxYES)\r
70         {\r
71                 this->fCancel = true;\r
72         }\r
73         e.Veto();\r
74 }\r
75 \r
76 //******************************************************************************\r
77 //    \83_\83C\83A\83\8d\83O\83v\83\8d\83V\81[\83W\83\83\r
78 //******************************************************************************\r
79 \r
80 int __stdcall TPICallbackProc(unsigned int _uMsg, void * _pStructure)\r
81 {\r
82         if (_uMsg != TPI_NOTIFY_COMMON)\r
83         {\r
84                 return TPI_CALLBACK_UNSUPPORTED;\r
85         }\r
86 \r
87         TPI_PROCESSINFO * piInfo = (TPI_PROCESSINFO *) _pStructure;\r
88         if (g_procDlg == NULL || piInfo == NULL || piInfo->uMessage != TPI_MESSAGE_STATUS || ! g_procDlg->IsShown())\r
89         {\r
90                 return TPI_CALLBACK_CONTINUE;\r
91         }\r
92 \r
93         static int s_nGaugeCounter = 0;\r
94         switch (piInfo->uStatus)\r
95         {\r
96         case TPI_STATUS_OPENARCHIVE:\r
97                 g_procDlg->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());\r
98                 break;\r
99         case TPI_STATUS_BEGINPROCESS:\r
100                 g_procDlg->ebTarget->ChangeValue((piInfo->fnDestination.IsOk() ? piInfo->fnDestination : piInfo->fiInfo.fnFileName).GetFullPath());\r
101                 if (piInfo->fiInfo.llUnpackedSize > 10000)\r
102                 {\r
103                         g_procDlg->gauge->SetRange(piInfo->fiInfo.llUnpackedSize.ToULong());\r
104                         g_procDlg->gauge->SetValue(0);\r
105                 }\r
106                 ::wxSafeYield(g_procDlg, true);\r
107                 break;\r
108         case TPI_STATUS_INPROCESS:\r
109                 if (s_nGaugeCounter++ > 100)\r
110                 {\r
111                         if (piInfo->fiInfo.llUnpackedSize > 10000)\r
112                         {\r
113                                 g_procDlg->gauge->SetValue(piInfo->llProcessedSize.ToULong());\r
114                         }\r
115                         ::wxSafeYield(g_procDlg, true);\r
116                         s_nGaugeCounter = 0;\r
117                 }\r
118                 break;\r
119         case TPI_STATUS_ENDPROCESS:\r
120 //              g_procDlg->gauge->SetValue(piInfo->fiInfo.llUnpackedSize.ToULong());\r
121                 break;\r
122         // \8f\91\8cÉ\83\8d\81[\83h\8e\9e\97p\82Ì\93Æ\8e©\8ed\97l\81B\r
123         case 0x1000:\r
124                 g_procDlg->ebSource->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());\r
125                 g_procDlg->gauge->SetRange(piInfo->fiInfo.llUnpackedSize.ToULong());\r
126                 g_procDlg->gauge->SetValue(0);\r
127                 break;\r
128         case 0x1001:\r
129                 // \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
130                 if (piInfo->llProcessedSize > g_procDlg->gauge->GetValue() + 100)\r
131                 {\r
132                         g_procDlg->ebTarget->ChangeValue(piInfo->fiInfo.fnFileName.GetFullPath());\r
133                         g_procDlg->gauge->SetValue(piInfo->llProcessedSize.ToULong());\r
134                         ::wxSafeYield(g_procDlg, true);\r
135                 }\r
136                 break;\r
137         }\r
138 \r
139         return g_procDlg->fCancel ? TPI_CALLBACK_CANCEL : TPI_CALLBACK_CONTINUE;\r
140 }\r