00001 #include "../../Library/SDK_Manila_Sense.h"
00002
00003 DIRECTDRAW_GDI *Section::bkgSurface=NULL;
00004 GDI_OVERLAY *Section::scrollBar=NULL;
00005 int Section::TITLE_SECTION_HEIGHT=0;
00006 int Section::TITLE_SECTION_WIDTH=0;
00007 bool Section::scrollVisible=false;
00008 LPCRITICAL_SECTION Section::criticAdd;
00009
00010 void Section::loadSurf(){
00011 if(criticAdd==NULL){
00012 criticAdd=new CRITICAL_SECTION;
00013 InitializeCriticalSection(criticAdd);
00014 }
00015 DWORD dwWidth = GetSystemMetrics(SM_CXSCREEN);
00016 DWORD dwHeight = GetSystemMetrics(SM_CYSCREEN);
00017 if(gi->backBuffer==NULL){
00018 DDSURFACEDESC DDSurfDesc;
00019 memset(&DDSurfDesc, 0, sizeof(DDSurfDesc));
00020 DDSurfDesc.dwSize = sizeof(DDSurfDesc);
00021 DDSurfDesc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
00022 DDSurfDesc.dwWidth = dwWidth;
00023 DDSurfDesc.dwHeight = dwHeight;
00024
00025 gi->backBuffer=new DIRECTDRAW_GDI;
00026
00027 HRESULT hret=DirectDrawWarp::createSurf(&DDSurfDesc, gi->backBuffer);
00028 if (hret != DD_OK)
00029 LocalisedString::explainFailDirectDraw(hret,L"Section::loadSurf 0");
00030 }
00031
00032 if(bkgSurface==NULL&&!title.empty()){
00033 const WCHAR * tmp=gi->bg_common_titlebar->c_str();
00034 bkgSurface=loadImage(gi->bg_common_titlebar);
00035 TITLE_SECTION_HEIGHT=bkgSurface->height;
00036 TITLE_SECTION_WIDTH=bkgSurface->width;
00037 }
00038
00039 if(scrollBar==NULL){
00040 DDSURFACEDESC ddsd;
00041 memset(&ddsd, 0, sizeof(ddsd));
00042 ddsd.dwSize = sizeof(ddsd);
00043 ddsd.dwFlags = DDSD_CAPS |DDSD_HEIGHT |DDSD_WIDTH;
00044 ddsd.dwWidth = SCROLL_WIDTH+1;
00045 ddsd.dwHeight = dwHeight;
00046 ddsd.ddsCaps.dwCaps = DDSCAPS_OVERLAY;
00047
00048 scrollBar = DirectDrawWarp::createOverlay(&ddsd);
00049
00050 if (scrollBar != NULL){
00051 DDBLTFX ddbltfx;
00052 memset(&ddbltfx, 0, sizeof(ddbltfx));
00053 ddbltfx.dwSize = sizeof(ddbltfx);
00054 ddbltfx.dwFillColor = 0xA514;
00055 HRESULT hRet = Section::scrollBar->directDrawSurf->Blt(NULL,NULL,NULL, DDBLT_WAITNOTBUSY|DDBLT_COLORFILL, &ddbltfx);
00056 if (hRet != DD_OK)
00057 LocalisedString::explainFailDirectDraw(hRet,L"Fill scrollBar");
00058
00059 scrollBar->visible=true;
00060 scrollVisible=true;
00061 }else{
00062 delete scrollBar;
00063 scrollBar=NULL;
00064 }
00065 }
00066
00067 if(this->getRight()==dwHeight){
00068 this->setRight(dwWidth);
00069 rcTitle.right=dwWidth;
00070 }
00071 gi->rs.top=gi->rcVisibleDesktopTOP.top+TITLE_SECTION_HEIGHT;
00072 }
00073
00074 Section::Section(int idElement, int x,int y,int width,wstring title):Element(idElement,x,y,TYPE_SECTION)
00075 {
00076 canScroll=true;
00077 posOverlay=0;
00078 selectedElement=NULL;
00079 mouseAnalysePrev=NULL;
00080
00081 this->title=title;
00082 if(bkgSurface==NULL){
00083 loadSurf();
00084 }
00085 this->components.clear();
00086
00087 this->setWidth(width);
00088 if(title.empty())
00089 this->setHeight(0);
00090 else
00091 this->setHeight(TITLE_SECTION_HEIGHT);
00092 positionAbsolute.left=0;
00093 positionAbsolute.top=0;
00094 positionAbsolute.right=0;
00095 positionAbsolute.bottom=0;
00096 recopiePosition(rcTitle);
00097
00098
00099
00100 if(gi->hFontTitle==NULL&&!title.empty()){
00101
00102
00103 HDC hdc=gi->backBuffer->deviceInterface;
00104
00105 gi->hFontTitle = (HFONT) GetCurrentObject(hdc, OBJ_FONT);
00106
00107
00108 LOGFONT LogFont;
00109 if (GetObject(gi->hFontTitle, sizeof(LOGFONT), &LogFont) == 0)
00110 return;
00111
00112
00113 LogFont.lfHeight = -((12 * GetDeviceCaps(hdc, LOGPIXELSY))/ 72);
00114 LogFont.lfWeight = 300;
00115
00116 LogFont.lfQuality=ANTIALIASED_QUALITY;
00117 LogFont.lfCharSet=DEFAULT_CHARSET;
00118 wcsncpy(LogFont.lfFaceName,L"HelveticaNeue LT 35 Thin\0",32);
00119
00120
00121
00122 gi->hFontTitle = CreateFontIndirect(&LogFont);
00123 }
00124 mouseEvent->setMouseAnalyse(this);
00125 if(title.empty())
00126 gi->rs.top=gi->rcVisibleDesktopTOP.top;
00127 else
00128 gi->rs.top=gi->rcVisibleDesktopTOP.top+TITLE_SECTION_HEIGHT;
00129 prevPos=0;
00130 prevOverlay=100;
00131
00132 gi->mustRedraw=true;
00133 drawingHook=NULL;
00134 }
00135
00136 Section::~Section(void)
00137 {
00138 int taille=this->components.size();
00139 for(int i=0;i<taille;i++){
00140 if(this->components[i]!=NULL){
00141 delete this->components[i];
00142 this->components[i]=NULL;
00143 }
00144 }
00145 if(scrollBar!=NULL){
00146 DestroyWindow(scrollBar->windowOverlay);
00147 }
00148 }
00149
00150 void Section::computeBkgSurface(){
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207 }
00208
00209 Element* Section::isClicked(int x,int y){
00210
00211 Element* out=NULL;
00212
00213 int taille=this->components.size();
00214 for(int i=0;i<taille;i++){
00215 if(this->components[i]!=NULL){
00216 out=this->components[i]->isClicked(x,y);
00217 if(out!=NULL)
00218 return out;
00219 }
00220 }
00221 return out;
00222 };
00223
00224
00225
00226 void Section::printScrollBar(DIRECTDRAW_GDI* lpDDraw){
00227 HRESULT hres;
00228 if(prevOverlay==posOverlay){
00229 return;
00230 }
00231 prevOverlay=posOverlay;
00232 int heightTitle=0;
00233 if(!title.empty())
00234 heightTitle=TITLE_SECTION_HEIGHT;
00235 double percent=((double)(gi->rs.bottom-gi->rs.top)/(double)(this->getHeight()-heightTitle));
00236 if(percent<0.8){
00237 overlayVisibility(true);
00238 canScroll=true;
00239 DWORD dwWidth = GetSystemMetrics(SM_CXSCREEN);
00240 DWORD dwHeight = GetSystemMetrics(SM_CYSCREEN);
00241 double paddingtop=dwHeight-gi->rs.bottom;
00242 if(gi->hasMenuBar){
00243 paddingtop=paddingtop-(gi->window->hMenuArea.bottom-gi->window->hMenuArea.top);
00244 dwHeight=dwHeight-(gi->window->hMenuArea.bottom-gi->window->hMenuArea.top);
00245 }
00246
00247 int heightScroll=(int)((gi->rs.bottom-gi->rs.top)*percent);
00248 double position=-((double)posOverlay*1000.0)/((double)(this->getHeight()-heightTitle)-(gi->rs.bottom-gi->rs.top));
00249 int realPos=gi->rs.top+(int)(position*(gi->rs.bottom-heightScroll-gi->rs.top)/1000.0);
00250
00251
00252 if(prevPos==0){
00253 prevOverlay=posOverlay;
00254 prevPos=realPos;
00255 }else{
00256
00257 int posRealPrev=prevPos-(prevOverlay-posOverlay);
00258 if(posRealPrev+heightScroll>gi->rs.bottom)
00259 posRealPrev=gi->rs.bottom-heightScroll;
00260 if(posRealPrev<gi->rs.top)
00261 posRealPrev=gi->rs.top;
00262 }
00263
00264 RECT pos={dwWidth-SCROLL_WIDTH-1,paddingtop+realPos,dwWidth-1,paddingtop+realPos+heightScroll};
00265 RECT overSrc={0,0,SCROLL_WIDTH,heightScroll};
00266 if(pos.top-paddingtop<gi->rs.top)
00267 pos.top=gi->rs.top+paddingtop;
00268 if(pos.bottom>dwHeight)
00269 pos.bottom=dwHeight-1;
00270
00271 if(pos.bottom-pos.top>0){
00272 hres = scrollBar->directDrawSurf->UpdateOverlay(&overSrc,
00273 gi->primaryBuffer->directDrawSurf, &pos, DDOVER_SHOW, NULL);
00274
00275 if (hres != DD_OK){
00276 LocalisedString::explainFailDirectDraw(hres,L"show scrollBar");
00277 }
00278 }
00279 pos.top=gi->rs.top;
00280 }else{
00281 overlayVisibility(false);
00282 }
00283 };
00284 void Section::overlayVisibility(bool visib){
00285 if(scrollBar==NULL)
00286 return;
00287 scrollBar->visible=visib;
00288
00289 if (visib)
00290 {
00291 if(!scrollVisible){
00292
00293
00294 scrollBar->directDrawSurf->UpdateOverlay(NULL, gi->primaryBuffer->directDrawSurf, NULL, DDOVER_SHOW, NULL);
00295 }
00296 }else{
00297 if(scrollVisible){
00298
00299
00300 scrollBar->directDrawSurf->UpdateOverlay(NULL, gi->primaryBuffer->directDrawSurf, NULL, DDOVER_HIDE, NULL);
00301 }
00302 }
00303 scrollVisible=visib;
00304 }
00305
00306 void Section::paint(DIRECTDRAW_GDI* lpDDraw,int x,int y){
00307 if(drawingHook!=NULL){
00308 int heightTitle=0;
00309 if(!title.empty())
00310 heightTitle=TITLE_SECTION_HEIGHT;
00311 drawingHook->paint(lpDDraw,x+this->getLeft(),rcTitle.bottom+posOverlay+heightTitle);
00312 return;
00313 }
00314 HRESULT hres;
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330 y=posOverlay+gi->rs.top;
00331 x+=this->getLeft();
00332 if(this->components.size()>0&&this->components[0]!=NULL){
00333 this->components[0]->paint(lpDDraw,x,y);
00334 int taille=this->components.size();
00335 for(int i=1;i<taille;i++){
00336 y+=this->components[i-1]->getBottom();
00337 if(this->components[i]!=NULL){
00338 this->components[i]->paint(lpDDraw,x,y);
00339 }
00340 }
00341 }
00342 gi->mustRedraw=false;
00343
00344
00345
00346 if(scrollBar!=NULL)
00347 printScrollBar(lpDDraw);
00348
00349
00350
00351
00352
00353 int heightTitle=0;
00354 if(!title.empty())
00355 heightTitle=TITLE_SECTION_HEIGHT;
00356 if(gi->rcVisibleDesktopTOP.top+heightTitle<=gi->rcUpdateRegion.top||
00357 gi->rcUpdateRegion.bottom<gi->rcUpdateRegion.top)
00358 return;
00359
00360 HDC hdc;
00361 positionAbsolute=gi->rs;
00362 positionAbsolute.top-=heightTitle;
00363 positionAbsolute.bottom=rcTitle.bottom+positionAbsolute.top;
00364
00365 clipping.top=0;
00366 clipping.bottom=rcTitle.bottom-rcTitle.top;
00367 clipping.left=0;
00368 clipping.right=TITLE_SECTION_WIDTH;
00369
00370
00371
00372
00373
00374
00375
00376 hres= gi->window->BltFast(lpDDraw,&positionAbsolute, bkgSurface,&clipping,NULL,NULL);
00377
00378 if (hres != DD_OK)
00379 LocalisedString::explainFailDirectDraw(hres,L"lpDDraw->Blt(&bkgSurface)");
00380
00381 hdc=lpDDraw->deviceInterface;
00382
00383
00384 HFONT hOldFont = (HFONT) SelectObject(hdc, gi->hFontTitle);
00385 SetTextColor(hdc,RGB(32,32,32));
00386 SetBkMode(hdc,TRANSPARENT);
00387
00388
00389 DrawText(hdc,title.c_str(),title.length(),&positionAbsolute,DT_CENTER|DT_SINGLELINE|DT_VCENTER);
00390 SelectObject(hdc, hOldFont);
00391
00392
00393
00394
00395
00396
00397 };
00398
00399 void Section::updateScreen(){
00400 if(this->owner==NULL){
00401 gi->rcUpdateRegion=gi->rs;
00402 this->paint(gi->primaryBuffer,0,0);
00403 }
00404 }
00405
00406 void Section::add(Element* e,int minHeight,int pos,bool mixWithOther){
00407 ASSERT(mixWithOther==false);
00408
00409 EnterCriticalSection(criticAdd);
00410 this->setBottom(this->getBottom()+e->getBottom());
00411
00412 e->owner=this;
00413 int cSize=components.size();
00414 int heightElem=e->getBottom();
00415 if(heightElem<minHeight){
00416 heightElem=minHeight;
00417 }
00418 if(pos<0||pos>=cSize){
00419 this->components.push_back(e);
00420 }else{
00421 if(pos>=0){
00422 components.push_back(NULL);
00423
00424 for(int i=cSize;i>pos;i--){
00425 components[i]=components[i-1];
00426 }
00427 components[pos]=e;
00428 }
00429 }
00430 LeaveCriticalSection(criticAdd);
00431 };
00432
00433 void Section::remove(unsigned int pos){
00434 if(pos>=this->components.size())
00435 return;
00436 EnterCriticalSection(criticAdd);
00437 int height=this->components[pos]->getHeight();
00438 delete this->components[pos];
00439 int taille=this->components.size();
00440 for(int i=pos;i<taille-1;i++){
00441 this->components[i]=this->components[i+1];
00442 }
00443 this->components[taille-1]=NULL;
00444 this->components.pop_back();
00445
00446 this->setBottom(this->getBottom()-height);
00447 LeaveCriticalSection(criticAdd);
00448 };
00449
00450
00451 int Section::mouseGesture(){
00452
00453
00454
00455
00456 if (mouseEvent->isRightClicked())
00457 {
00458 int posX,posY;
00459 this->mouseEvent->getMousePosition(posX,posY);
00460 this->selectedElement=isClicked(posX,posY);
00461 if(this->selectedElement!=NULL){
00462 this->selectedElement->run(true);
00463 this->selectedElement=NULL;
00464 }
00465 }
00466 if(mouseEvent->isDblClicked()){
00467 if(this->selectedElement!=NULL){
00468 this->selectedElement->unClick();
00469 this->selectedElement=NULL;
00470 }
00471 return 0;
00472 }
00473
00474 bool isDragged=mouseEvent->isMouseDown();
00475 if(mouseEvent->isClicked()){
00476 if(this->selectedElement!=NULL){
00477 if(this->selectedElement->run()){
00478 this->selectedElement=NULL;
00479 return 0;
00480 }
00481 }
00482 this->selectedElement=NULL;
00483 }
00484
00485 if(mouseEvent->isSelected()){
00486 if(this->selectedElement==NULL){
00487 int posX,posY;
00488 this->mouseEvent->getMousePosition(posX,posY);
00489 this->selectedElement=isClicked(posX,posY);
00490 }
00491 }else{
00492 if(this->selectedElement!=NULL){
00493 this->selectedElement->unClick();
00494 this->selectedElement=NULL;
00495 }
00496 }
00497
00498 if(gi->mustRedraw)
00499 return 0;
00500
00501 int heightTitle=0;
00502 if(!title.empty())
00503 heightTitle=TITLE_SECTION_HEIGHT;
00504 double percent=((double)(gi->rs.bottom-gi->rs.top)/(double)(this->getHeight()-heightTitle));
00505
00506 if (percent>1){
00507 if(!canScroll){
00508 mouseEvent->stopScroll();
00509 return 0;
00510 }
00511 }
00512
00513
00514 if(this->mouseEvent->isSlidingLeft()){
00515
00516 if(this->owner!=NULL){
00517
00518
00519 this->owner->run();
00520 return 0;
00521 }
00522 }
00523
00524 return verifScrollingRange(this->mouseEvent->getMouseDY(),isDragged);
00525
00526 };
00527
00528 int Section::verifScrollingRange(int dY,bool isDragged)
00529 {
00530 int out=0;
00531 bool isOut=false;
00532
00533 int maxSize=(gi->rs.bottom-gi->rcVisibleDesktopTOP.top);
00534 if(maxSize>getHeight())
00535 maxSize=getHeight();
00536 if(getHeight()+posOverlay+dY<maxSize&&!isDragged){
00537 out= maxSize-getHeight()-posOverlay;
00538 posOverlay = maxSize-getHeight();
00539 isOut=true;
00540 }else{
00541 if(posOverlay+dY>0&&!isDragged){
00542 out= -posOverlay;
00543 posOverlay = 0;
00544 isOut=true;
00545 }
00546 }
00547
00548 if(!isOut){
00549 this->posOverlay+=dY;
00550 out= dY;
00551 }else{
00552 mouseEvent->stopScroll();
00553 }
00554 return out;
00555 }
00556
00557 void Section::setDrawingHook(Element* e){
00558 this->drawingHook=e;
00559 };
00560
00561 void Section::sizeChanged(Element* src,int w,int h){
00562 int prevHeight=src->getHeight();
00563 if(prevHeight<h){
00564 setHeight(getHeight()+(h-prevHeight));
00565 }
00566 }
00567
00568 void Section::goToTop()
00569 {
00570 posOverlay=0;
00571 }