00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "CATWaitDlg.h"
00016 #include "CATLabel.h"
00017 #include "CATStreamFile.h"
00018 #include "CATEventDefs.h"
00019
00020 CATWaitDlg::CATWaitDlg( CATINSTANCE instance,
00021 CATInt32 backgroundBmpId,
00022 CATRect& textRect,
00023 CATInt32 progressBmpOnId,
00024 CATInt32 progressBmpOffId,
00025 CATInt32 progressLeft,
00026 CATInt32 progressTop)
00027 : CATWindow( "Window", "" )
00028 {
00029 fAllowClose = false;
00030 fBmpId = 0;
00031 fHandle = 0;
00032 fDepth = 0;
00033 fParent = 0;
00034 fDisableParent = false;
00035 fProgBmpOnId = 0;
00036 fProgBmpOffId = 0;
00037 fProgressBar = 0;
00038 fWaitLabel = 0;
00039
00040
00041 this->AddAttribute(L"WaitDlg", L"Name");
00042 this->AddAttribute(L"Please Wait...", L"Title");
00043 this->AddAttribute(L"False", L"CaptionBar");
00044 this->AddAttribute(L"True", L"DragAnywhere");
00045 this->AddAttribute(L"False", L"Sizeable");
00046 this->AddAttribute(L"True", L"Multiline");
00047 this->AddAttribute(L"True", L"TextCentered");
00048
00049
00050
00051 fBmpId = backgroundBmpId;
00052 HBITMAP bgBmp = (HBITMAP)::LoadImage( instance,
00053 MAKEINTRESOURCE(fBmpId),
00054 IMAGE_BITMAP,
00055 0,
00056 0,
00057 LR_CREATEDIBSECTION);
00058
00059
00060 if (bgBmp != 0)
00061 {
00062 CATResult result = CATImage::CreateImageFromDIB(fImage, bgBmp);
00063
00064 CATASSERT(CATSUCCEEDED(result), "Unable to create image from bitmap for wait dialog!");
00065 this->fRect.Set( 0,0, fImage->Width(), fImage->Height());
00066
00067 ::DeleteObject(bgBmp);
00068 }
00069
00070
00071
00072
00073
00074
00075 fWaitLabel = new CATLabel( "Label",this->fRootDir);
00076 fWaitLabel->AddAttribute(L"Name", L"WaitStatus");
00077 fWaitLabel->AddAttribute(L"XPos", (CATString)textRect.left);
00078 fWaitLabel->AddAttribute(L"Width", (CATString)textRect.Width());
00079 fWaitLabel->AddAttribute(L"YPos", (CATString)textRect.top);
00080 fWaitLabel->AddAttribute(L"Height", (CATString)textRect.Height());
00081 fWaitLabel->AddAttribute(L"ColorFore", (CATString)(CATUInt32)0);
00082 fWaitLabel->AddAttribute(L"FontName", L"Arial");
00083 fWaitLabel->AddAttribute(L"FontSize", L"10");
00084
00085 this->AddChild(fWaitLabel);
00086
00087
00088
00089 if ((progressBmpOnId != 0) && (progressBmpOffId != 0))
00090 {
00091 fProgBmpOnId = progressBmpOnId;
00092 fProgBmpOffId = progressBmpOffId;
00093
00094 HBITMAP progBmpOn = (HBITMAP)::LoadImage(instance, MAKEINTRESOURCE(fProgBmpOnId), IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION);
00095 HBITMAP progBmpOff = (HBITMAP)::LoadImage(instance, MAKEINTRESOURCE(fProgBmpOffId), IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION);
00096
00097 if (progBmpOn && progBmpOff)
00098 {
00099
00100 CATImage *progOn, *progOff;
00101
00102 CATImage::CreateImageFromDIB( progOn, progBmpOn);
00103 CATImage::CreateImageFromDIB( progOff, progBmpOff);
00104
00105 fProgressBar = new CATProgress( L"Progress", L"");
00106 fProgressBar->AddAttribute(L"XPos", (CATString)progressLeft);
00107 fProgressBar->AddAttribute(L"YPos", (CATString)progressTop);
00108 fProgressBar->AddAttribute(L"Name", L"WaitProgress");
00109 fProgressBar->AddAttribute(L"ProgressStyle", L"Horizontal");
00110
00111
00112 this->AddChild(fProgressBar);
00113
00114
00115 fProgressBar->SetImages(progOn, progOff,0);
00116 }
00117
00118 if (progBmpOn)
00119 DeleteObject(progBmpOn);
00120
00121 if (progBmpOff)
00122 DeleteObject(progBmpOff);
00123
00124 }
00125
00126
00127
00128 CATWindow::Load();
00129 }
00130
00131 CATWaitDlg::~CATWaitDlg()
00132 {
00133 if (this->IsShowing())
00134 {
00135 this->Hide(true);
00136 }
00137 }
00138
00139 void CATWaitDlg::OnDestroy()
00140 {
00141 CATWindow::OnDestroy();
00142 }
00143
00144 void CATWaitDlg::StartWait(const CATString& waitText, CATWindow* parent, bool disableParent)
00145 {
00146 this->SetWaitLabelText(waitText);
00147 this->SetProgress(0.0f);
00148
00149 if (fDepth != 0)
00150 {
00151 fDepth++;
00152 this->SetWaitLabelText(waitText);
00153 return;
00154 }
00155
00156
00157 fDisableParent = disableParent;
00158 fParent = parent;
00159
00160 if ((fDisableParent) && (fParent))
00161 {
00162 fParent->SetEnabled(false);
00163 }
00164
00165 fAllowClose = false;
00166 fParent = parent;
00167
00168 CATRect wndRect = fRect;
00169
00170 CATRect parentRect;
00171 if (fParent)
00172 {
00173 parentRect = fParent->GetRectAbs(true);
00174 }
00175 else
00176 {
00177 HMONITOR monitor = MonitorFromWindow( ::GetDesktopWindow(), MONITOR_DEFAULTTOPRIMARY);
00178 MONITORINFO monInfo;
00179 monInfo.cbSize = sizeof(monInfo);
00180 GetMonitorInfo(monitor, &monInfo);
00181 parentRect.Set(monInfo.rcWork.left, monInfo.rcWork.top, monInfo.rcWork.right, monInfo.rcWork.bottom);
00182 }
00183
00184 CATPOINT centerPos;
00185 centerPos.x = parentRect.left + (parentRect.Width() - fRect.Width())/2;
00186 centerPos.y = parentRect.top + (parentRect.Height() - fRect.Height())/2;
00187 wndRect.SetOrigin(centerPos);
00188
00189 this->AddAttribute(L"XPos",(CATString)wndRect.left);
00190 this->AddAttribute(L"YPos",(CATString)wndRect.top);
00191 this->AddAttribute(L"Width",(CATString)wndRect.Width());
00192 this->AddAttribute(L"Height",(CATString)wndRect.Height());
00193
00194 this->OnSize(wndRect);
00195
00196
00197 fDlgReady.Reset();
00198
00199 fDepth = 1;
00200
00201 unsigned int threadId;
00202 fHandle = (HANDLE)_beginthreadex(0,0,WindowThread,this,0,&threadId);
00203 fDlgReady.Wait();
00204
00205 }
00206
00207 bool CATWaitDlg::IsShowing()
00208 {
00209 return (fDepth > 0);
00210 }
00211
00212 void CATWaitDlg::EndWait(bool force)
00213 {
00214 if (fDepth > 0)
00215 {
00216 fDepth--;
00217 }
00218
00219
00220 if ((fDepth == 0) || (force))
00221 {
00222 fAllowClose = true;
00223 ::PostMessage(fWindow,CATWM_ENDWAIT,0,0);
00224
00225 WaitForSingleObject( fHandle,INFINITE);
00226 CloseHandle(fHandle);
00227 fHandle = 0;
00228 fDepth = 0;
00229 fWindow = 0;
00230 if ((fDisableParent) && (fParent))
00231 {
00232 fParent->SetEnabled(true);
00233 }
00234 }
00235 }
00236
00237 CATUInt32 CATWaitDlg::GetDepth()
00238 {
00239 return fDepth;
00240 }
00241
00242 bool CATWaitDlg::OnClose()
00243 {
00244 return fAllowClose;
00245 }
00246
00247 unsigned int _stdcall CATWaitDlg::WindowThread(void* param)
00248 {
00249 CATWaitDlg* waitWnd = (CATWaitDlg*)param;
00250
00251 waitWnd->Show( waitWnd->fParent);
00252
00253 waitWnd->fRect.ZeroOrigin();
00254 waitWnd->OnSize(waitWnd->fRect);
00255
00256 MSG msg;
00257
00258 waitWnd->fDlgReady.Fire();
00259
00260 while (::GetMessage(&msg,waitWnd->fWindow,0,0))
00261 {
00262 ::TranslateMessage(&msg);
00263 ::DispatchMessage(&msg);
00264 }
00265
00266 return 0;
00267 }
00268
00269 void CATWaitDlg::SetWaitLabelText( const CATString& waitStr )
00270 {
00271 if (fWindow != 0)
00272 {
00273 ::SendMessage(fWindow, CATWM_SETWAITLABEL,(WPARAM)&waitStr,0);
00274 }
00275 }
00276
00277
00278
00279
00280
00281 void CATWaitDlg::Draw( CATImage* background,
00282 const CATRect& dirtyRect)
00283 {
00284 CATWindow::Draw(background,dirtyRect);
00285 }
00286
00287
00288 void CATWaitDlg::SetProgress( CATFloat32 percent )
00289 {
00290 if (percent < 0.0f)
00291 percent = 0.0f;
00292 if (percent > 1.0f)
00293 percent = 1.0f;
00294
00295 if (fWindow != 0)
00296 {
00297 ::SendMessage(fWindow,CATWM_SETWAITPROGRESS, (WPARAM)&percent,0);
00298 }
00299
00300
00301 }
00302
00303 CATResult CATWaitDlg::OnEvent(const CATEvent& event, CATInt32& retVal)
00304 {
00305 CATResult result = CAT_SUCCESS;
00306
00307 switch (event.fEventCode)
00308 {
00309 case CATEVENT_WINDOWS_EVENT:
00310 switch (event.fIntParam2)
00311 {
00312 case CATWM_SETWAITPROGRESS:
00313 {
00314 CATFloat32* progPtr = (float*)event.fIntParam3;
00315 if ((progPtr != 0) && (fProgressBar != 0))
00316 {
00317 fProgressBar->SetValue(*progPtr);
00318 }
00319 }
00320 break;
00321 case CATWM_SETWAITLABEL:
00322 {
00323 CATString* strPtr = (CATString*)event.fIntParam3;
00324 if ((strPtr != 0) && (fWaitLabel != 0))
00325 {
00326 fWaitLabel->SetString(*strPtr);
00327 }
00328 }
00329 break;
00330 case CATWM_ENDWAIT:
00331 ::PostQuitMessage(0);
00332 break;
00333 }
00334 break;
00335 default:
00336 return CATWindow::OnEvent(event,retVal);
00337 }
00338
00339 return result;
00340 }