00001
00002 #include "../../Library/SDK_Manila_Sense.h"
00003 GlobalInformations* MessageBoxSense::gi=NULL;
00004
00005
00006 DIRECTDRAW_GDI *MessageBoxSense::msgBox=NULL;
00007 RECT MessageBoxSense::rectBox;
00008 int MessageBoxSense::answer;
00009 HANDLE MessageBoxSense::threadMSG;
00010 bool MessageBoxSense::standAlone=false;
00011
00012 void MessageBoxSense::loadSurf(){
00013 if(msgBox==NULL){
00014 msgBox=Element::loadImage(gi->bg_msg_box);
00015
00016 rectBox.top=0;rectBox.left=0;
00017 rectBox.right=msgBox->width;
00018 rectBox.bottom=msgBox->height;
00019 }
00020 isInit=false;
00021 posAbsolute.top=gi->rcVisibleDesktopTOP.top+((gi->rs.bottom-gi->rs.top)-(2*rectBox.bottom/3+heightMsg+button[0]->getHeight()+10))/2;
00022 posAbsolute.left=((gi->rs.right-gi->rs.left)-rectBox.right)/2;
00023 posAbsolute.bottom=posAbsolute.top+(2*rectBox.bottom/3+heightMsg+button[0]->getHeight()+10);
00024 posAbsolute.right=posAbsolute.left+rectBox.right;
00025 }
00026
00027 MessageBoxSense::MessageBoxSense(wstring ti,wstring text,int t){
00028
00029 gi->window->changeControl(this);
00030 repaintButton=false;
00031 title=ti;
00032 message=text;
00033 type=t;
00034 selectedButton=NULL;
00035 isActive=true;
00036 isAlreadyComputed=false;
00037 button=NULL;
00038
00039
00040
00041 WNDCLASS wc;
00042 DWORD dwUpdateFlags = 0;
00043
00044
00045
00046 wc.style = CS_HREDRAW | CS_VREDRAW;
00047 wc.lpfnWndProc = MessageBoxSense::messageDispatch;
00048 wc.cbClsExtra = 0;
00049 wc.cbWndExtra = 0;
00050 wc.hInstance = gi->m_hInstance;
00051 wc.hIcon = LoadIcon(gi->m_hInstance, NULL);
00052 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
00053 wc.hbrBackground = (HBRUSH )GetStockObject(WHITE_BRUSH);
00054 wc.lpszMenuName = NULL;
00055 wc.lpszClassName = L"MessageBoxSense";
00056 RegisterClass(&wc);
00057
00058
00059
00060 this->hWnd = CreateWindow(
00061 L"MessageBoxSense",
00062 title.c_str(),
00063 WS_SYSMENU,
00064 CW_USEDEFAULT,
00065 CW_USEDEFAULT,
00066 CW_USEDEFAULT,
00067 CW_USEDEFAULT,
00068 gi->m_hWnd,
00069 NULL,
00070 NULL,
00071 this);
00072 if (!this->hWnd)
00073 return;
00074 if(standAlone){
00075 gi->m_hWnd=this->hWnd;
00076 GetClientRect(gi->m_hWnd, &gi->rs);
00077 gi->primaryBuffer=new DIRECTDRAW_GDI;
00078 gi->primaryBuffer->bitmap=0;
00079 gi->primaryBuffer->directDrawSurf=NULL;
00080 gi->primaryBuffer->deviceInterface=0;
00081 gi->primaryBuffer->height=GetSystemMetrics(SM_CYSCREEN)-gi->rcVisibleDesktopTOP.top;
00082 gi->primaryBuffer->width=GetSystemMetrics(SM_CXSCREEN);
00083 gi->primaryBuffer->nbBPP=16;
00084
00085 DDSURFACEDESC DDSurfDesc;
00086 memset(&DDSurfDesc, 0, sizeof(DDSurfDesc));
00087 DDSurfDesc.dwSize = sizeof(DDSurfDesc);
00088 DDSurfDesc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
00089 DDSurfDesc.dwWidth = gi->rs.right;
00090 DDSurfDesc.dwHeight = gi->rs.bottom;
00091 gi->backBuffer=new DIRECTDRAW_GDI;
00092
00093 HRESULT hret=DirectDrawWarp::createSurf(&DDSurfDesc, gi->backBuffer);
00094 if (hret != DD_OK)
00095 LocalisedString::explainFailDirectDraw(hret,L"Can't create surface");
00096 }
00097
00099
00101
00102
00103
00104
00105 SetForegroundWindow((HWND)(((ULONG) this->hWnd) | 0x01));
00106 ShowWindow(this->hWnd, true);
00107 UpdateWindow(this->hWnd);
00108 SetFocus(this->hWnd);
00109 SHFullScreen(this->hWnd,SHFS_HIDETASKBAR|SHFS_HIDESIPBUTTON);
00110
00111
00112
00113 switch (type)
00114 {
00115 case MESSAGE_ALERT:
00116 button=new MyItem*[1];
00117 button[0]=new MyItem(1,0,0,ITEM_IS_BUTTON_SHORT,ITEM_STATE_EBL_EMPTY,L"OK");
00118 break;
00119 case MESSAGE_YESNO:
00120 button=new MyItem*[2];
00121 button[0]=new MyItem(1,0,0,ITEM_IS_BUTTON_SHORT,ITEM_STATE_EBL_EMPTY,L"Yes");
00122 button[1]=new MyItem(2,0,0,ITEM_IS_BUTTON_SHORT,ITEM_STATE_EBL_EMPTY,L"No");
00123 break;
00124 case MESSAGE_OKCANCEL:
00125 button=new MyItem*[2];
00126 button[0]=new MyItem(1,0,0,ITEM_IS_BUTTON_SHORT,ITEM_STATE_EBL_EMPTY,L"OK");
00127 button[1]=new MyItem(2,0,0,ITEM_IS_BUTTON_SHORT,ITEM_STATE_EBL_EMPTY,L"Cancel");
00128 break;
00129 case MESSAGE_ABORTRETRY:
00130 button=new MyItem*[2];
00131 button[0]=new MyItem(1,0,0,ITEM_IS_BUTTON_SHORT,ITEM_STATE_EBL_EMPTY,L"Retry");
00132 button[1]=new MyItem(2,0,0,ITEM_IS_BUTTON_SHORT,ITEM_STATE_EBL_EMPTY,L"Abort");
00133 break;
00134 default:
00135 button=NULL;
00136 }
00137 if(msgBox==NULL){
00138 loadSurf();
00139 }
00140
00141
00142 HDC hdc;
00143 RECT sizeTxt={0,0,rectBox.right,0};
00144
00145 hdc=gi->backBuffer->deviceInterface;
00146
00147 SelectObject(hdc, MyLabel::fontNormal);
00148 DrawText(hdc,message.c_str(),message.length(),&sizeTxt,DT_CALCRECT|DT_WORDBREAK);
00149 heightMsg=sizeTxt.bottom;
00150 sizeTxt.bottom=0;
00151
00152 SelectObject(hdc, MyLabel::fontTitle);
00153 DrawText(hdc,title.c_str(),title.length(),&sizeTxt,DT_CALCRECT);
00154 widthTitle=sizeTxt.right;
00155
00156 isInit=false;
00157 posAbsolute.top=gi->rcVisibleDesktopTOP.top+((gi->rs.bottom-gi->rs.top)-(2*rectBox.bottom/3+heightMsg+button[0]->getHeight()+10))/2;
00158 posAbsolute.left=((gi->rs.right-gi->rs.left)-rectBox.right)/2;
00159 posAbsolute.bottom=posAbsolute.top+(2*rectBox.bottom/3+heightMsg+button[0]->getHeight()+10);
00160 posAbsolute.right=posAbsolute.left+rectBox.right;
00161 }
00162
00163 MessageBoxSense::~MessageBoxSense(){
00164
00165 DestroyWindow(this->hWnd);
00166
00167
00168 switch (type)
00169 {
00170 case MESSAGE_ALERT:
00171 delete *button;
00172 break;
00173 case MESSAGE_YESNO:
00174 case MESSAGE_OKCANCEL:
00175 case MESSAGE_ABORTRETRY:
00176 delete button[0];
00177 delete button[1];
00178 break;
00179 default:
00180 button=NULL;
00181 }
00182 }
00183
00184
00185
00186 long FAR PASCAL MessageBoxSense::messageDispatch(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){
00187 MessageBoxSense* pParent;
00188
00189
00190 if(message == WM_CREATE)
00191 {
00192 pParent = (MessageBoxSense*)((LPCREATESTRUCT)lParam)->lpCreateParams;
00193 SetWindowLong(hWnd,GWL_USERDATA,(LONG_PTR)pParent);
00194 return 1;
00195 }
00196 else
00197 {
00198 pParent = (MessageBoxSense*)GetWindowLong(hWnd,GWL_USERDATA);
00199 if(!pParent)
00200 return DefWindowProc(hWnd,message,wParam,lParam);
00201 }
00202
00203 return pParent->messageAnalysis(message,wParam,lParam);
00204 }
00205 long MessageBoxSense::messageAnalysis(UINT message, WPARAM wParam, LPARAM lParam){
00206 switch (message)
00207 {
00208 #ifdef UNDER_CE
00209 case WM_ACTIVATE:
00210 #else
00211 case WM_ACTIVATEAPP:
00212 #endif
00213
00214 return 0;
00215
00216 case WM_SETFOCUS:
00217 if(isActive){
00218 isInit=false;
00219 gi->window->UpdateFrame();
00220 }
00221 return 0L;
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231 case WM_CTLCOLOREDIT:
00232 break;
00233
00234
00235 case WM_ERASEBKGND:
00236 return 1;
00237
00238 case MSG_USER_PAINT:
00239 gi->window->doRepaintBuffered(0);
00240 return 1;
00241 case WM_PAINT:{
00242 PAINTSTRUCT ps;
00243 BeginPaint( this->hWnd, &ps );
00244 EndPaint( this->hWnd, &ps );
00245 gi->window->UpdateFrame();
00246 }
00247 break;
00248
00249 case WM_LBUTTONDOWN:{
00250 MouseCtrl::getInstance()->leftBtnDown(LOWORD(lParam),HIWORD(lParam));
00251 gi->window->UpdateFrame();
00252 break;
00253 }
00254 case WM_LBUTTONUP:{
00255 MouseCtrl::getInstance()->leftBtnUp(LOWORD(lParam),HIWORD(lParam));
00256 gi->window->UpdateFrame();
00257 break;
00258 }
00259 case WM_MOUSEMOVE:{
00260 MouseCtrl::getInstance()->leftBtnMove(LOWORD(lParam),HIWORD(lParam));
00261 gi->window->UpdateFrame();
00262 break;
00263 }
00264
00265 }
00266 return DefWindowProc(gi->m_hWnd, message, wParam, lParam);
00267 }
00268 int MessageBoxSense::show(wstring ti,wstring message,int type){
00269
00270 if(!GlobalInformations::alreadyInitialized()){
00271 standAlone=true;
00272 gi=GlobalInformations::getInstance();
00273
00274 gi->window=new DirectDrawWarp();
00275 }else{
00276 standAlone=false;
00277 gi=GlobalInformations::getInstance();
00278 }
00279
00280 ResetEvent(gi->waitForMSG);
00281 MessageBoxSense* box=new MessageBoxSense(ti,message,type);
00282
00283 gi->window->UpdateFrame();
00284
00285
00286
00287
00288
00289
00290
00291 DWORD processWindow=NULL;
00292 GetWindowThreadProcessId(gi->m_hWnd,&processWindow);
00293 if(GetCurrentProcessId()==processWindow){
00294 bool waitMSG=true;
00295 MSG msg;
00296 while( waitMSG )
00297 {
00298
00299 if(GetMessage( &msg, NULL, 0, 0)==-1){
00300 LocalisedString::explainFail( L"Main MsgBox function failed...",L"GetMessage");
00301 waitMSG=false;
00302 }
00303 if(msg.hwnd==box->hWnd){
00304 switch(msg.message)
00305 {
00306 case WM_QUIT:
00307 waitMSG=false;
00308 break;
00309 case WM_USER:
00310 if(msg.wParam==MESSAGE_REP){
00311 waitMSG=false;
00312 break;
00313 }
00314 default:
00315 TranslateMessage(&msg);
00316 DispatchMessage(&msg);
00317
00318 }
00319 }else{
00320 if(msg.hwnd==NULL){
00321 EventHandler::msgExecute(msg);
00322 }else{
00323 TranslateMessage(&msg);
00324 DispatchMessage(&msg);
00325 }
00326 }
00327 }
00328 }else{
00329 WaitForSingleObject(gi->waitForMSG,INFINITE);
00330 }
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342 box->isActive=false;
00343 delete box;
00344
00345
00346 if(!standAlone)
00347 gi->window->changeControl(NULL);
00348 else{
00349 delete gi->window;
00350 gi->window=NULL;
00351 gi=NULL;
00352 }
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364 InvalidateRect(gi->m_hWnd,NULL,false);
00365
00366 return MessageBoxSense::answer;
00367 }
00368
00369
00370 void MessageBoxSense::updateFrame(DIRECTDRAW_GDI* screen){
00371 if(!isActive||button==NULL)
00372 return;
00373
00374 if(!isInit){
00375 isInit=true;
00376 isAlreadyComputed=true;
00377 DIRECTDRAW_GDI* backBuf=gi->backBuffer;
00378
00379 gi->rcUpdateRegion=gi->rs;
00380 gi->rcUpdateRegion.top=gi->rcVisibleDesktopTOP.top;
00381
00382 DDBLTFX fillColor;
00383 fillColor.dwFillColor=0;
00384 gi->window->BltFast(backBuf,NULL,
00385 NULL, NULL,DDBLT_COLORFILL,&fillColor);
00386 gi->window->BltMix(backBuf,&gi->rcUpdateRegion,
00387 screen,&gi->rcUpdateRegion,128.0);
00388
00389
00390
00391 RECT srcBox={rectBox.left,rectBox.top,rectBox.right,rectBox.bottom};
00392 RECT posBox=posAbsolute;
00393
00394 posBox.bottom=posAbsolute.top+rectBox.bottom/2;
00395 srcBox.bottom-=(int)((rectBox.bottom/2.0));
00396 gi->window->BltFast(backBuf,&posBox,msgBox, &srcBox,NULL,NULL);
00397
00398
00399
00400 posBox.top=posAbsolute.top+rectBox.bottom/2;
00401 posBox.bottom=posAbsolute.bottom-rectBox.bottom/10;
00402 srcBox.top=(int)((rectBox.bottom/2.0));
00403 srcBox.bottom=(LONG)((rectBox.bottom/2.0))+(LONG)2;
00404
00405 gi->window->BltFast(backBuf,&posBox,msgBox, &srcBox,NULL,NULL);
00406
00407
00408 posBox=posAbsolute;
00409 posBox.top=posAbsolute.bottom-rectBox.bottom/4;
00410 srcBox.top=(LONG)((3.0*rectBox.bottom/4.0));
00411 srcBox.bottom=(LONG)(rectBox.bottom);
00412
00413 gi->window->BltFast(backBuf,&posBox,msgBox, &srcBox,NULL,NULL);
00414
00415
00416
00417
00418 COLORREF color=RGB(0xFF,0xFF,0xFF);
00419
00420
00421 posBox=posAbsolute;
00422 posBox.bottom=posBox.top+(posBox.bottom-posBox.top)/5;
00423 SelectObject(backBuf->deviceInterface, MyLabel::fontTitle);
00424 SetTextColor(backBuf->deviceInterface,color);
00425 SetBkMode(backBuf->deviceInterface,TRANSPARENT);
00426 DrawText(backBuf->deviceInterface,title.c_str(),title.length(),&posBox,DT_CENTER|DT_SINGLELINE|DT_VCENTER);
00427
00428 color=RGB(0,0,0);
00429 posBox=posAbsolute;
00430 posBox.left+=(posBox.right-posBox.left)/50;
00431 posBox.right-=(posBox.right-posBox.left)/50;
00432 posBox.top+=rectBox.bottom/2;
00433 posBox.bottom-=(posBox.bottom-posBox.top)/4;
00434 SelectObject(backBuf->deviceInterface, MyLabel::fontNormal);
00435 SetTextColor(backBuf->deviceInterface,color);
00436 SetBkMode(backBuf->deviceInterface,TRANSPARENT);
00437 DrawText(backBuf->deviceInterface,message.c_str(),message.length(),&posBox,DT_WORDBREAK);
00438 repaintButton=false;
00439
00440 switch (type)
00441 {
00442 case MESSAGE_ALERT:
00443 button[0]->paint(backBuf,posAbsolute.left+((posAbsolute.right-posAbsolute.left)-(button[0]->getWidth()))/2,
00444 posAbsolute.top+rectBox.bottom/2+heightMsg+10);
00445 break;
00446 case MESSAGE_YESNO:
00447 case MESSAGE_OKCANCEL:
00448 case MESSAGE_ABORTRETRY:
00449 button[0]->paint(backBuf,posAbsolute.left+10,
00450 posAbsolute.top+rectBox.bottom/2+heightMsg+10);
00451 button[1]->paint(backBuf,posAbsolute.right-10-button[1]->getWidth(),
00452 posAbsolute.top+rectBox.bottom/2+heightMsg+10);
00453 break;
00454 }
00455 gi->window->BltFast(screen,&gi->rcUpdateRegion,
00456 gi->backBuffer,&gi->rcUpdateRegion,NULL,NULL);
00457 }
00458 KillTimer(gi->m_hWnd,1);
00459
00460 if(repaintButton){
00461 repaintButton=false;
00462 gi->window->BltFast(screen,&gi->rcUpdateRegion,
00463 gi->backBuffer,&gi->rcUpdateRegion,NULL,NULL);
00464
00465 switch (type)
00466 {
00467 case MESSAGE_ALERT:
00468 button[0]->paint(screen,posAbsolute.left+((posAbsolute.right-posAbsolute.left)-(button[0]->getWidth()))/2,
00469 posAbsolute.top+rectBox.bottom/2+heightMsg+10);
00470 break;
00471 case MESSAGE_YESNO:
00472 case MESSAGE_OKCANCEL:
00473 case MESSAGE_ABORTRETRY:
00474 button[0]->paint(screen,posAbsolute.left+10,
00475 posAbsolute.top+rectBox.bottom/2+heightMsg+10);
00476 button[1]->paint(screen,posAbsolute.right-10-button[1]->getWidth(),
00477 posAbsolute.top+rectBox.bottom/2+heightMsg+10);
00478 break;
00479 }
00480 }
00481
00482 MouseCtrl* mCtrl=MouseCtrl::getInstance();
00483 mCtrl->stopScroll();
00484
00485 if(mCtrl->isClicked())
00486 if(this->selectedButton!=NULL){
00487 MessageBoxSense::answer=MSG_REP_YES;
00488 if(selectedButton->getId()!=1)
00489 MessageBoxSense::answer=MSG_REP_NO;
00490
00491 PostMessage(this->hWnd,WM_USER,MESSAGE_REP,NULL);
00492 this->selectedButton=NULL;
00493 repaintButton=true;
00494 return;
00495 }
00496 if(mCtrl->isSelected()){
00497 if(this->selectedButton==NULL){
00498 int posX,posY;
00499 mCtrl->getMousePosition(posX,posY);
00500 selectedButton=button[0]->isClicked(posX,posY);
00501 if(selectedButton==NULL&&(type!=MESSAGE_ALERT))
00502 selectedButton=button[1]->isClicked(posX,posY);
00503 repaintButton=true;
00504 }
00505 }else{
00506 if(this->selectedButton!=NULL){
00507 this->selectedButton->unClick();
00508 this->selectedButton=NULL;
00509 repaintButton=true;
00510 }
00511 }
00512 };