00001 #include "../../Library/SDK_Manila_Sense.h"
00002
00003 DIRECTDRAW_GDI *MyPanel::bkgSurfaceSrc=NULL;
00004 DIRECTDRAW_GDI *MyPanel::separator=NULL;
00005 int MyPanel::TITLE_PANEL_HEIGHT=0;
00006 int MyPanel::bkgSurfaceSrcWidth=0;
00007 int MyPanel::separatorWidth=0;
00008 LPCRITICAL_SECTION MyPanel::criticAdd=NULL;
00009
00010 void MyPanel::loadSurf(){
00011 if(criticAdd==NULL){
00012 criticAdd=new CRITICAL_SECTION;
00013 InitializeCriticalSection(criticAdd);
00014 }
00015 if(bkgSurfaceSrc==NULL&&hasTitle){
00016 bkgSurfaceSrc=loadImage(gi->bg_common_divider_section);
00017
00018 TITLE_PANEL_HEIGHT=bkgSurfaceSrc->height;
00019 bkgSurfaceSrcWidth=bkgSurfaceSrc->width;
00020 }
00021 if(separator==NULL&&hasSeparator){
00022 separator=loadImage(gi->bg_common_dotline);
00023 separatorWidth=separator->width;
00024 }
00025
00026 DWORD dwWidth = GetSystemMetrics(SM_CXSCREEN);
00027 DWORD dwHeight = GetSystemMetrics(SM_CYSCREEN);
00028
00029 if(this->getRight()==dwHeight){
00030 this->setRight(dwWidth);
00031 rcTitle.right=dwWidth;
00032 }
00033 if(bkgSurface==NULL)
00034 computeSurface();
00035
00036 }
00037
00038 MyPanel::MyPanel(int idElement, int x,int y,int width,wstring title,bool hT,bool hS):Element(idElement, x,y,TYPE_PANEL)
00039 {
00040 if(width>0)
00041 this->setWidth(width);
00042 else
00043 this->setWidth(gi->rs.right);
00044
00045 bkgSurface=NULL;
00046 this->title=title;
00047 this->components.clear();
00048 heightComp.clear();
00049 isAlone.clear();
00050 hasTitle=hT;
00051 hasSeparator=hS;
00052
00053 loadSurf();
00054
00055
00056 if(hasTitle)
00057 this->setHeight(TITLE_PANEL_HEIGHT);
00058 else
00059 this->setHeight(0);
00060
00061 rcTitle.left=getLeft();
00062 rcTitle.right=getRight();
00063 rcTitle.top=getTop();
00064 rcTitle.bottom=rcTitle.top+TITLE_PANEL_HEIGHT;
00065 }
00066
00067 MyPanel::~MyPanel(void)
00068 {
00069 int taille=this->components.size();
00070 for(int i=0;i<taille;i++){
00071 if(this->components[i]!=NULL){
00072 delete this->components[i];
00073 this->components[i]=NULL;
00074 }
00075 }
00076 }
00077
00078 void MyPanel::changeTitle(wstring t){
00079 if(title==L""){
00080 hasTitle=false;
00081 return;
00082 }
00083 hasTitle=true;
00084 title=t;
00085 computeSurface();
00086 }
00087 void MyPanel::computeSurface(){
00088 if(!hasTitle)
00089 return;
00090 DirectDrawWarp::deleteSurf(&bkgSurface);
00091
00092 bkgSurface=new DIRECTDRAW_GDI;
00093 DDSURFACEDESC ddsd;
00094 HRESULT hres;
00095
00096
00097
00098 memset(&ddsd, 0, sizeof(ddsd));
00099 ddsd.dwSize = sizeof(ddsd);
00100 ddsd.dwFlags = DDSD_HEIGHT | DDSD_WIDTH;
00101 ddsd.dwWidth=bkgSurfaceSrcWidth;
00102 ddsd.dwHeight=bkgSurfaceSrc->height;
00103
00104
00105 hres =DirectDrawWarp::createSurf(&ddsd, bkgSurface);
00106 if(hres != DD_OK)
00107 LocalisedString::explainFailDirectDraw(hres, L"computeSurface(bkgSurface);");
00108
00109 #ifdef DRAWING_DDRAW
00110 DDCOLORKEY ddck;
00111 memset(&ddck, 0, sizeof(ddck));
00112 ddck.dwColorSpaceHighValue = BACKGROUND_COLOR_MANILA;
00113 ddck.dwColorSpaceLowValue = ddck.dwColorSpaceHighValue;
00114 hres = bkgSurface->directDrawSurface->SetColorKey(DDCKEY_SRCBLT,&ddck);
00115 if (hres != DD_OK)
00116 LocalisedString::explainFailDirectDraw(hres,L"bkgSurface SetColorKey");
00117
00118 #endif
00119
00120 RECT posPatch={0,0,bkgSurfaceSrcWidth,TITLE_PANEL_HEIGHT};
00121 if ((hres = gi->window->BltFast(bkgSurface,NULL, bkgSurfaceSrc,&posPatch,DDBLT_WAITNOTBUSY, NULL)) != DD_OK)
00122 LocalisedString::explainFailDirectDraw(hres, L"computeSurface(Blt);");
00123
00124
00125
00126 HDC hdc=bkgSurface->deviceInterface;
00127
00128 RECT posText={5,0,getWidth(),TITLE_PANEL_HEIGHT};
00129 posText.top-=5;
00130 posText.left+=5;
00131
00132 SetTextColor(hdc,RGB(255,255,255));
00133 SetBkMode(hdc,TRANSPARENT);
00134 DrawText(hdc,title.c_str(),title.length(),&posText,DT_SINGLELINE|DT_VCENTER);
00135
00136 }
00137
00138 Element* MyPanel::isClicked(int x,int y){
00139
00140 Element* out=NULL;
00141
00142 int taille=this->components.size();
00143 for(int i=0;i<taille;i++){
00144 if(this->components[i]!=NULL){
00145 out=this->components[i]->isClicked(x,y);
00146 if(out!=NULL)
00147 return out;
00148 }
00149 }
00150 return out;
00151 };
00152
00153 void MyPanel::paint(DIRECTDRAW_GDI* lpDDraw,int x,int y){
00154
00155 HRESULT hres;
00156
00157 if(hasTitle){
00158
00159 if(bkgSurface==NULL){
00160 computeSurface();
00161 }
00162
00163 positionAbsolute.top=rcTitle.top+y;
00164 positionAbsolute.bottom=rcTitle.bottom+y;
00165 positionAbsolute.left=rcTitle.left+x;
00166 positionAbsolute.right=rcTitle.right+x;
00167
00168
00169
00170 if(!(positionAbsolute.top>=gi->rcUpdateRegion.bottom||positionAbsolute.bottom<=gi->rcUpdateRegion.top||
00171 positionAbsolute.left>=gi->rcUpdateRegion.right||positionAbsolute.right<=gi->rcUpdateRegion.left||
00172 gi->rcUpdateRegion.bottom-gi->rcUpdateRegion.top==0)){
00173
00174 if(positionAbsolute.top<gi->rcUpdateRegion.top){
00175 clipping.top=gi->rcUpdateRegion.top-positionAbsolute.top;
00176 positionAbsolute.top=gi->rcUpdateRegion.top;
00177 }else{
00178 clipping.top=0;
00179 }
00180 if(positionAbsolute.bottom>gi->rcUpdateRegion.bottom){
00181 clipping.bottom=(rcTitle.bottom-rcTitle.top)-(positionAbsolute.bottom-gi->rcUpdateRegion.bottom);
00182 positionAbsolute.bottom=gi->rcUpdateRegion.bottom;
00183 }else{
00184 clipping.bottom=(rcTitle.bottom-rcTitle.top);
00185 }
00186 if(positionAbsolute.left<gi->rcUpdateRegion.left){
00187 clipping.left=gi->rcUpdateRegion.left-positionAbsolute.left;
00188 positionAbsolute.left=gi->rcUpdateRegion.left;
00189 }else{
00190 clipping.left=0;
00191 }
00192 if(positionAbsolute.right>gi->rcUpdateRegion.right){
00193 positionAbsolute.right=gi->rcUpdateRegion.right;
00194 clipping.right=clipping.left+(positionAbsolute.right-positionAbsolute.left);
00195 }else{
00196 clipping.right=bkgSurfaceSrcWidth;
00197 }
00198
00199
00200 if(positionAbsolute.bottom-positionAbsolute.top>0&&
00201 clipping.right-clipping.left>0&&clipping.left>=0){
00202 if(bkgSurfaceSrcWidth<positionAbsolute.right){
00203 RECT clTmp={bkgSurfaceSrcWidth-(positionAbsolute.right-bkgSurfaceSrcWidth),clipping.top,
00204 bkgSurfaceSrcWidth,clipping.bottom};
00205 RECT posTmp={bkgSurfaceSrcWidth,positionAbsolute.top,
00206 positionAbsolute.right,positionAbsolute.bottom};
00207
00208 hres= gi->window->BltFast(lpDDraw,&posTmp, bkgSurfaceSrc,&clTmp, DDBLT_WAITNOTBUSY,NULL);
00209 if (hres != DD_OK){
00210 LocalisedString::explainFailDirectDraw(hres,L"MyPanel Blt(bkgSurface);");
00211 return;
00212 }
00213 positionAbsolute.right=posTmp.left;
00214 clipping.right=clTmp.right;
00215 }
00216
00217 hres= gi->window->BltFast(lpDDraw,&positionAbsolute, bkgSurface,&clipping, DDBLT_WAITNOTBUSY,NULL);
00218 if (hres != DD_OK){
00219 LocalisedString::explainFailDirectDraw(hres,L"MyPanel:paint Blt");
00220 }
00221 }
00222
00223
00224 positionAbsolute.top=this->getTop()+y;
00225 positionAbsolute.left=this->getLeft();
00226
00227 }
00228
00229 y+=TITLE_PANEL_HEIGHT;
00230 }
00231 y+=this->getTop();
00232 x+=this->getLeft();
00233
00234
00235
00236 positionAbsolute.left=x;
00237 positionAbsolute.right=this->getWidth()+x;
00238 if(positionAbsolute.right>gi->rs.right)
00239 positionAbsolute.right=gi->rs.right;
00240
00241 RECT srcSeparator={0,0,this->getWidth(),1};
00242 if(srcSeparator.right>separatorWidth)
00243 srcSeparator.right=separatorWidth;
00244 RECT destSeparator=positionAbsolute;
00245
00246 int maxSize=0;
00247
00248 if(y+this->getHeight()<0||y>=gi->rs.bottom){
00249 return;
00250 }
00251 if(this->components.size()>0&&this->components[0]!=NULL){
00252 this->components[0]->paint(lpDDraw,x,y);
00253
00254 int taille=this->components.size();
00255 for(int i=1;i<taille;i++){
00256 if(this->heightComp[i-1]>maxSize)
00257 maxSize=this->heightComp[i-1];
00258
00259 if(this->isAlone[i]){
00260 y+=maxSize+PADDING_PANEL_H;
00261 maxSize=0;
00262 }
00263
00264 if(hasSeparator&&this->isAlone[i]){
00265 y+=PADDING_PANEL_H;
00266 if(y-PADDING_PANEL_H+1<=gi->rcUpdateRegion.bottom&&y-PADDING_PANEL_H>=gi->rcUpdateRegion.top){
00267 positionAbsolute.top=y-PADDING_PANEL_H;
00268 positionAbsolute.bottom=y-PADDING_PANEL_H+1;
00269 destSeparator=positionAbsolute;
00270 while(separatorWidth<destSeparator.right-destSeparator.left){
00271 int leftTmp=(destSeparator.right-destSeparator.left)-separatorWidth;
00272 if (leftTmp>separatorWidth)
00273 {
00274 leftTmp=separatorWidth;
00275 }
00276 RECT clTmp={0,0,leftTmp,1};
00277 RECT posTmp={destSeparator.right-leftTmp,destSeparator.top,
00278 destSeparator.right,destSeparator.bottom};
00279
00280
00281 hres= gi->window->BltFast(lpDDraw,&posTmp, gi->background,&clTmp, DDBLT_WAITNOTBUSY,NULL);
00282 hres= gi->window->BltFast(lpDDraw,&posTmp, separator,&clTmp, DDBLT_WAITNOTBUSY,NULL);
00283 if (hres != DD_OK){
00284 LocalisedString::explainFailDirectDraw(hres,L"MyPanel Blt(bkgSurface);");
00285 return;
00286 }
00287 destSeparator.right=posTmp.left;
00288 srcSeparator.right=separatorWidth;
00289 }
00290
00291 hres= gi->window->BltFast(lpDDraw,&destSeparator, gi->background,&srcSeparator, DDBLT_WAITNOTBUSY,NULL);
00292 hres= gi->window->BltFast(lpDDraw,&destSeparator, separator,&srcSeparator, DDBLT_WAITNOTBUSY,NULL);
00293 if (hres != DD_OK)
00294 LocalisedString::explainFailDirectDraw(hres,L"MyPanel::paint Blt");
00295 }
00296
00297 y++;
00298 }
00299
00300 if(this->components[i]!=NULL){
00301 this->components[i]->paint(lpDDraw,x,y);
00302 }
00303 }
00304 }
00305 positionAbsolute.top=this->getTop()+y;
00306 positionAbsolute.left=this->getLeft()+x;
00307 };
00308
00309 void MyPanel::add(Element* e,int minHeight,int pos,bool mixWithOther){
00310
00311 EnterCriticalSection(criticAdd);
00312 int prevBottom=this->getBottom();
00313 minHeight=minHeight*gi->percentOfVGA;
00314 e->owner=this;
00315 int cSize=components.size();
00316 int heightElem=e->getBottom();
00317 if(heightElem<minHeight){
00318 heightElem=minHeight;
00319 }
00320 if(pos<0||pos>=cSize){
00321 this->components.push_back(e);
00322 heightComp.push_back(heightElem);
00323 isAlone.push_back(true);
00324 if(hasSeparator)
00325 this->setBottom(this->getBottom()+heightElem+2*PADDING_PANEL_H+1);
00326 else
00327 this->setBottom(this->getBottom()+heightElem+PADDING_PANEL_H);
00328 }else{
00329 if(pos>=0){
00330 int maxHeight=0;
00331 components.push_back(NULL);
00332 heightComp.push_back(0);
00333 isAlone.push_back(false);
00334
00335 int i;
00336 for(i=cSize;i>pos;i--){
00337 components[i]=components[i-1];
00338 isAlone[i]=isAlone[i-1];
00339 heightComp[i]=heightComp[i-1];
00340 if(maxHeight<heightComp[i])
00341 maxHeight=heightComp[i];
00342 if(isAlone[i]&&i!=pos+1)
00343 maxHeight=0;
00344 }
00345 isAlone[pos+1]=false;
00346 components[pos+1]=e;
00347 heightComp[pos+1]=heightElem;
00348 while(i>=0&&!isAlone[i]){
00349 if(maxHeight<heightComp[i])
00350 maxHeight=heightComp[i];
00351 i--;
00352 }
00353 if(i>=0){
00354 if(maxHeight<heightComp[i])
00355 maxHeight=heightComp[i];
00356 }
00357 if(maxHeight<heightElem)
00358 this->setBottom(this->getBottom()+heightElem-maxHeight);
00359 }
00360 }
00361 if(owner!=NULL){
00362 owner->setBottom(owner->getBottom()+this->getBottom()-prevBottom);
00363 }
00364 LeaveCriticalSection(criticAdd);
00365 };
00366 Element* MyPanel::remove(int pos,int nb){
00367 int taille=this->components.size();
00368 if(pos>=taille)
00369 return NULL;
00370 EnterCriticalSection(criticAdd);
00371 if(pos+nb>taille||nb<0)
00372 nb=taille-pos;
00373 Element*out=this->components[pos];
00374 int i=0;
00375 for(i=pos;i<taille-nb;i++){
00376 this->components[i]=this->components[i+nb];
00377 this->isAlone[i]=this->isAlone[i+nb];
00378 this->heightComp[i]=this->heightComp[i+nb];
00379 }
00380 for(i=0;i<nb;i++){
00381 this->components.pop_back();
00382 heightComp.pop_back();
00383 }
00384
00385 taille=this->heightComp.size();
00386 int height=0;
00387 int maxHeight=0;
00388 for(int i=0;i<taille;i++){
00389 if(maxHeight<heightComp[i])
00390 maxHeight=heightComp[i];
00391 if(isAlone[i]){
00392 height+=maxHeight;
00393 maxHeight=0;
00394 }
00395 }
00396 int prevBottom=this->getBottom();
00397 this->setBottom(height);
00398 if(owner!=NULL&&this->getBottom()-prevBottom!=0){
00399 owner->setBottom(owner->getBottom()+this->getBottom()-prevBottom);
00400 }
00401 LeaveCriticalSection(criticAdd);
00402 return out;
00403 };
00404 void MyPanel::sizeChanged(Element* src,int w,int h){
00405 int i=0,sizeTab=components.size();
00406 while(i<sizeTab&&src!=components[i])
00407 i++;
00408 if(i>=sizeTab)
00409 return;
00410 int prevHeight=heightComp[i];
00411 if(prevHeight<h){
00412 heightComp[i]=h;
00413 setHeight(getHeight()+(h-prevHeight));
00414 }
00415 }