gwenhywfar 4.0.3

theme.cpp

Go to the documentation of this file.
00001 /* These widgets have initially been created by Martin Oberzalek who gave them into
00002  * the public domain via an email to the mailing list foxgui-users on 17th of June, 2010
00003  * ("here the source. Free to use for alll.").
00004  * I (Martin Preuss) adapted them to be usable with FOX 1.6 and also added some widgets of
00005  * my own (for now: ThemeHeaderItem).
00006  */
00007 
00008 
00009 #include "theme.h"
00010 
00011 #define ICON_SPACING  4
00012 
00013 
00014 // Draw rectangle
00015 static void drawRectangle(FXDC& dc,FXColor lower,FXColor upper,FXint x,FXint y,FXint w,FXint h){
00016   register FXint rr,gg,bb,dr,dg,db,r1,g1,b1,r2,g2,b2,yl,yh,yy,dy,n,t;
00017   const FXint MAXSTEPS=128;
00018 
00019   if(0<w && 0<h){
00020     dc.setStipple(STIPPLE_NONE);
00021     dc.setFillStyle(FILL_SOLID);
00022 
00023     r1=FXREDVAL(lower);   r2=FXREDVAL(upper);   dr=r2-r1;
00024     g1=FXGREENVAL(lower); g2=FXGREENVAL(upper); dg=g2-g1;
00025     b1=FXBLUEVAL(lower);  b2=FXBLUEVAL(upper);  db=b2-b1;
00026 
00027     n=FXABS(dr);
00028     if((t=FXABS(dg))>n) n=t;
00029     if((t=FXABS(db))>n) n=t;
00030     n++;
00031     if(n>h) n=h;
00032     if(n>MAXSTEPS) n=MAXSTEPS;
00033     rr=(r1<<16)+32767;
00034     gg=(g1<<16)+32767;
00035     bb=(b1<<16)+32767;
00036     yy=32767;
00037 
00038     dr=(dr<<16)/n;
00039     dg=(dg<<16)/n;
00040     db=(db<<16)/n;
00041     dy=(h<<16)/n;
00042 
00043     do {
00044       yl=yy>>16;
00045       yy+=dy;
00046       yh=yy>>16;
00047       dc.setForeground(FXRGB(rr>>16,gg>>16,bb>>16));
00048       dc.fillRectangle(x,y+yl,w,yh-yl);
00049       rr+=dr;
00050       gg+=dg;
00051       bb+=db;
00052     } while(yh<h);
00053   }
00054 }
00055 
00056 
00057 
00058 
00059 FXDEFMAP(ThemeButton) ThemeButtonMap[]={
00060         FXMAPFUNC( SEL_PAINT, 0, ThemeButton::onPaint)
00061 };
00062 
00063 FXIMPLEMENT( ThemeButton, FXButton, ThemeButtonMap, ARRAYNUMBER(ThemeButtonMap) );
00064 
00065 
00066 ThemeButton::ThemeButton(FXComposite* p, const FXString& text, FXIcon* ic,
00067                          FXObject* tgt, FXSelector sel, FXuint opts,
00068                          FXint x, FXint y, FXint w, FXint h,
00069                          FXint pl, FXint pr, FXint pt, FXint pb)
00070   : FXButton( p, text, ic, tgt, sel, opts, x, y, w, h, pl, pr, pt, pb )
00071 {}
00072 
00073 // Handle repaint
00074 long ThemeButton::onPaint(FXObject*,FXSelector,void* ptr){
00075   FXint tw=0,th=0,iw=0,ih=0,tx,ty,ix,iy;
00076   FXEvent*ev=(FXEvent*)ptr;
00077   FXDCWindow dc(this,ev);
00078 
00079 
00080   FXColor top         = FXRGB(0xfe,0xfd,0xfd);
00081   FXColor bottom      = FXRGB(0xdd,0xd7,0xce);
00082   FXColor shade       = FXRGB(0xdc,0xd9,0xd4);
00083 
00084 //      FXColor bordercolor = FXRGB(0x78,0x70,0x63);
00085 
00086   FXColor bordercolor = FXRGB(123,158,189);
00087 
00088 /*
00089   FXPoint borderbackground[12]={FXPoint(0,0),FXPoint(0,1),FXPoint(1,0),
00090   FXPoint(width-1,0),FXPoint(width-2,0),FXPoint(width-1,1),
00091   FXPoint(0,height-1),FXPoint(0,height-2),FXPoint(1,height-1),
00092   FXPoint(width-1,height-1),FXPoint(width-1,height-2),FXPoint(width-2,height-1)};
00093 */
00094   FXPoint basebackground[4]={FXPoint(0,0),FXPoint(width-1,0),FXPoint(0,height-1),FXPoint(width-1,height-1)};
00095 
00096   FXPoint bordershade[16]={
00097     FXPoint(0,1),FXPoint(1,0),FXPoint(1,2),FXPoint(2,1),
00098     FXPoint(width-2,0),FXPoint(width-1,1),FXPoint(width-3,1),FXPoint(width-2,2),
00099     FXPoint(0,height-2),FXPoint(1,height-1),FXPoint(1,height-3),FXPoint(2,height-2),
00100     FXPoint(width-1,height-2),FXPoint(width-2,height-1),FXPoint(width-2,height-3),FXPoint(width-3,height-2)
00101   };
00102   FXPoint bordercorners[4]={
00103     FXPoint(1,1),FXPoint(1,height-2),FXPoint(width-2,1),FXPoint(width-2,height-2)
00104   };
00105 
00106 
00107   if (options&BUTTON_TOOLBAR && !underCursor()) {
00108     dc.setForeground(baseColor);
00109     dc.fillRectangle(0,0,width,height);
00110   }
00111   else if (state==STATE_UP && ((options&BUTTON_TOOLBAR)==0 || (options&BUTTON_TOOLBAR && underCursor()))) {
00113     dc.setForeground(baseColor);
00114     dc.drawPoints(basebackground,4);
00116     dc.setForeground(bordercolor);
00117     dc.drawRectangle(2,0,width-5,0);
00118     dc.drawRectangle(2,height-1,width-5,height-1);
00119     dc.drawRectangle(0,2,0,height-5);
00120     dc.drawRectangle(width-1,2,width-1,height-5);
00121     dc.drawPoints(bordercorners,4);
00122     dc.setForeground(shade);
00123     dc.drawPoints(bordershade,16);
00125     drawRectangle(dc,top,bottom,2,1,width-4,height-2);
00126     dc.setForeground(top);
00127     dc.drawRectangle(1,3,0,height-7);
00128     dc.setForeground(bottom);
00129     dc.drawRectangle(width-2,3,0,height-7);
00130   }
00131   else {
00133     dc.setForeground(baseColor);
00134     dc.drawPoints(basebackground,4);
00136     dc.setForeground(bordercolor);
00137     dc.drawRectangle(2,0,width-5,0);
00138     dc.drawRectangle(2,height-1,width-5,height-1);
00139     dc.drawRectangle(0,2,0,height-5);
00140     dc.drawRectangle(width-1,2,width-1,height-5);
00141     dc.drawPoints(bordercorners,4);
00142     dc.setForeground(shade);
00143     dc.drawPoints(bordershade,16);
00144 
00145     dc.setForeground(FXRGB(0xdc,0xd4,0xc9));
00146     dc.fillRectangle(2,1,width-4,height-2);
00147   }
00148 
00149   // Place text & icon
00150   if(!label.empty()){
00151     tw=labelWidth(label);
00152     th=labelHeight(label);
00153   }
00154   if(icon){
00155     iw=icon->getWidth();
00156     ih=icon->getHeight();
00157   }
00158 
00159   just_x(tx,ix,tw,iw);
00160   just_y(ty,iy,th,ih);
00161 
00162   // Shift a bit when pressed
00163   if (state && (options&(FRAME_RAISED|FRAME_SUNKEN))){
00164     ++tx; ++ty; ++ix; ++iy;
00165   }
00166 
00167   // Draw enabled state
00168   if(isEnabled()){
00169     if(icon){
00170       dc.drawIcon(icon,ix,iy);
00171     }
00172     if(!label.empty()){
00173       dc.setFont(font);
00174       dc.setForeground(textColor);
00175       drawLabel(dc,label,hotoff,tx,ty,tw,th);
00176     }
00177     if(hasFocus()){
00178       dc.drawFocusRectangle(border+1,border+1,width-2*border-2,height-2*border-2);
00179     }
00180   }
00181 
00182   // Draw grayed-out state
00183   else {
00184     if (icon) {
00185       dc.drawIconSunken(icon,ix,iy);
00186     }
00187     if(!label.empty()) {
00188       dc.setFont(font);
00189       dc.setForeground(hiliteColor);
00190       drawLabel(dc,label,hotoff,tx+1,ty+1,tw,th);
00191       dc.setForeground(shadowColor);
00192       drawLabel(dc,label,hotoff,tx,ty,tw,th);
00193     }
00194   }
00195   return 1;
00196 }
00197 
00198 
00199 
00200 
00201 FXDEFMAP(ThemeTextField) ThemeTextFieldMap[]={
00202   FXMAPFUNC( SEL_PAINT, 0, ThemeTextField::onPaint)
00203 };
00204 
00205 FXIMPLEMENT( ThemeTextField, FXTextField, ThemeTextFieldMap, ARRAYNUMBER(ThemeTextFieldMap) );
00206 
00207 ThemeTextField::ThemeTextField(FXComposite* p,FXint ncols,FXObject* tgt,FXSelector sel,
00208                                FXuint opts,FXint x,FXint y,FXint w,FXint h,
00209                                FXint pl,FXint pr,FXint pt,FXint pb)
00210   : FXTextField( p, ncols, tgt, sel, opts, x, y, w, h, pl, pr, pt, pb )
00211 {
00212         
00213 }
00214 
00215 static void drawFrame(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h) {
00216   if(0<w && 0<h){
00217     dc.setForeground(FXRGB(123,158,189));
00218     dc.fillRectangle(x,y,w,1);
00219     dc.fillRectangle(x,y,1,h);
00220     // dc.setForeground(hiliteColor);
00221     dc.fillRectangle(x,y+h-1,w,1);
00222     dc.fillRectangle(x+w-1,y,1,h);
00223   }
00224 }
00225 
00226 
00227 
00228 
00229 static void drawSunkenFrame(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h){
00230   if(0<w && 0<h){
00231     dc.setForeground(FXRGB(255,158,100));
00232     dc.fillRectangle(x,y,w,1);
00233     dc.fillRectangle(x,y,1,h);
00234     // dc.setForeground(hiliteColor);
00235     dc.fillRectangle(x,y+h-1,w,1);
00236     dc.fillRectangle(x+w-1,y,1,h);
00237 
00238     if(1<w && 1<h){
00239       dc.fillRectangle(x+1,y+1,w-3,1);
00240       dc.fillRectangle(x+1,y+1,1,h-3);
00241       dc.fillRectangle(x+1,y+h-2,w-2,1);
00242       dc.fillRectangle(x+w-2,y+1,1,h-2);
00243     }
00244   }
00245 }
00246 
00247 
00248 
00249 static void drawHighlightFrame(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h) {
00250   if (0<w && 0<h){
00251     dc.setForeground(FXRGB(123,158,255));
00252     dc.fillRectangle(x,y,w,1);
00253     dc.fillRectangle(x,y,1,h);
00254     // dc.setForeground(hiliteColor);
00255     dc.fillRectangle(x,y+h-1,w,1);
00256     dc.fillRectangle(x+w-1,y,1,h);
00257 
00258     if (1<w && 1<h){
00259       dc.fillRectangle(x+1,y+1,w-3,1);
00260       dc.fillRectangle(x+1,y+1,1,h-3);
00261       dc.fillRectangle(x+1,y+h-2,w-2,1);
00262       dc.fillRectangle(x+w-2,y+1,1,h-2);
00263     }
00264   }
00265 }
00266 
00267 
00268 
00269 long ThemeTextField::onPaint(FXObject*,FXSelector,void* ptr) {
00270   FXEvent *ev=(FXEvent*)ptr;
00271   FXDCWindow dc(this,ev);
00272 
00273   // Set font
00274   dc.setFont(font);
00275 
00276   // Draw frame
00277   ::drawFrame(dc,0,0,width,height);
00278 
00279   // Gray background if disabled
00280   dc.setForeground(isEnabled() ? backColor : baseColor);
00281 
00282   // Draw background
00283   dc.fillRectangle(border,border,width-(border<<1),height-(border<<1));
00284 
00285   // Draw text, clipped against frame interior
00286   dc.setClipRectangle(border,border,width-(border<<1),height-(border<<1));
00287   drawTextRange(dc,0,contents.length());
00288   
00289   // Draw caret
00290   if (flags&FLAG_CARET){
00291     int xx=coord(cursor)-1;
00292     dc.setForeground(cursorColor);
00293     dc.fillRectangle(xx,padtop+border,1,height-padbottom-padtop-(border<<1));
00294     dc.fillRectangle(xx-2,padtop+border,5,1);
00295     dc.fillRectangle(xx-2,height-border-padbottom-1,5,1);
00296   }
00297   return 1;
00298 }
00299 
00300 
00301 
00302 struct ColorTheme {
00303   const FXchar* name;
00304   FXColor base;
00305   FXColor border;
00306   FXColor back;
00307   FXColor fore;
00308   FXColor selback;
00309   FXColor selfore;
00310   FXColor tipback;
00311   FXColor tipfore;
00312   FXColor menuback;
00313   FXColor menufore;
00314   };
00315 
00316 
00317 const ColorTheme ColorThemes[]={
00318         {"Redmond XP",FXRGB(238,238,230),FXRGB(  0,  0,  0),FXRGB(255,255,255),FXRGB(  0,  0,  0),FXRGB( 74,121,205),FXRGB(255,255,255),FXRGB(255,255,225),FXRGB(  0,  0,  0),FXRGB( 74,121,205),FXRGB(255,255,255)}
00319 };
00320 
00321 
00322 
00323 void init_theme(FXApp *app) {
00324   app->setBaseColor( ColorThemes[0].base );
00325   app->setBorderColor( ColorThemes[0].border );
00326   app->setBackColor( ColorThemes[0].back );
00327   app->setForeColor( ColorThemes[0].fore );
00328   app->setSelforeColor( ColorThemes[0].selfore );
00329   app->setSelbackColor( ColorThemes[0].selback );
00330   app->setTipforeColor( ColorThemes[0].tipfore );
00331   app->setTipbackColor( ColorThemes[0].tipback );
00332   app->setSelMenuTextColor( ColorThemes[0].menufore );
00333   app->setSelMenuBackColor( ColorThemes[0].menuback );
00334   // app->setHiliteColor(FXRGB(123,158,189));
00335 }
00336 
00337 
00338 
00339 
00340 FXDEFMAP(ThemeComboBox) ThemeComboBoxMap[]={
00341   FXMAPFUNC( SEL_PAINT, 0, ThemeComboBox::onPaint)
00342 };
00343 
00344 FXIMPLEMENT( ThemeComboBox, FXComboBox, ThemeComboBoxMap, ARRAYNUMBER(ThemeComboBoxMap) );
00345 
00346 ThemeComboBox::ThemeComboBox(FXComposite *p,FXint cols,FXObject* tgt,FXSelector sel,FXuint opts,
00347                              FXint x,FXint y,FXint w,FXint h,
00348                              FXint pl,FXint pr,FXint pt,FXint pb)
00349   : FXComboBox(p,cols, tgt, sel, opts,x,y,w,h, pl,pr,pt,pb)
00350 {
00351   delete button;
00352 
00353   button=new ThemeMenuButton(this,FXString::null, NULL, pane,
00354                              FRAME_RAISED|MENUBUTTON_DOWN|MENUBUTTON_ATTACH_RIGHT,
00355                              0,0,0,0, 0,0,0,0);
00356   button->setXOffset(border);
00357   button->setYOffset(border);
00358 }
00359 
00360 
00361 
00362 long ThemeComboBox::onPaint(FXObject*,FXSelector,void* ptr){
00363   FXEvent *ev=(FXEvent*)ptr;
00364   FXDCWindow dc(this,ev);
00365 
00366   dc.setForeground(backColor);
00367   dc.fillRectangle(ev->rect.x,ev->rect.y,ev->rect.w,ev->rect.h);
00368   drawFrame(dc,0,0,width,height);
00369   return 1;
00370 }
00371 
00372 
00373 
00374 
00375 
00376 FXDEFMAP(ThemeLabel) ThemeLabelMap[]={
00377         FXMAPFUNC( SEL_PAINT, 0, ThemeLabel::onPaint )
00378 };
00379 
00380 FXIMPLEMENT( ThemeLabel, FXLabel, ThemeLabelMap, ARRAYNUMBER( ThemeLabelMap ));
00381 
00382 ThemeLabel::ThemeLabel(FXComposite* p,const FXString& text,FXIcon* ic,FXuint opts,
00383                        FXint x,FXint y,FXint w,FXint h,FXint pl,FXint pr,FXint pt,FXint pb)
00384   : FXLabel( p, text, ic, opts, x, y, w, h, pl, pr, pt, pb )
00385 {
00386         
00387 }
00388 
00389 
00390 
00391 // Handle repaint
00392 long ThemeLabel::onPaint(FXObject*,FXSelector,void* ptr) {
00393   FXEvent   *ev=(FXEvent*)ptr;
00394   FXDCWindow dc(this,ev);
00395   FXint      tw=0,th=0,iw=0,ih=0,tx,ty,ix,iy;
00396   dc.setForeground(backColor);
00397   dc.fillRectangle(0,0,width,height);
00398   if (!label.empty()){
00399     tw=labelWidth(label);
00400     th=labelHeight(label);
00401   }
00402   if (icon){
00403     iw=icon->getWidth();
00404     ih=icon->getHeight();
00405   }
00406   just_x(tx,ix,tw,iw);
00407   just_y(ty,iy,th,ih);
00408   if(icon) {
00409     if(isEnabled())
00410       dc.drawIcon(icon,ix,iy);
00411     else
00412       dc.drawIconSunken(icon,ix,iy);
00413   }
00414   if (!label.empty()){
00415     dc.setFont(font);
00416     if(isEnabled()){
00417       dc.setForeground(textColor);
00418       drawLabel(dc,label,hotoff,tx,ty,tw,th);
00419     }
00420     else {
00421       dc.setForeground(hiliteColor);
00422       drawLabel(dc,label,hotoff,tx+1,ty+1,tw,th);
00423       dc.setForeground(shadowColor);
00424       drawLabel(dc,label,hotoff,tx,ty,tw,th);
00425     }
00426   }
00427   if (options & (FRAME_THICK|FRAME_RAISED|FRAME_SUNKEN)) {
00428     if( options & (FRAME_SUNKEN) )
00429       drawSunkenFrame(dc,0,0,width,height);
00430     else if( options & (FRAME_RAISED) )
00431       drawHighlightFrame(dc,0,0,width,height);
00432     else
00433       drawFrame(dc,0,0,width,height);
00434   }
00435 
00436   return 1;
00437 }
00438 
00439 
00440 
00441 
00442 FXDEFMAP(ThemeTabItem) ThemeTabItemMap[]={
00443 //      FXMAPFUNC( SEL_PAINT, 0, ThemeTabItem::onPaint )
00444 };
00445 
00446 FXIMPLEMENT( ThemeTabItem, FXTabItem, ThemeTabItemMap, ARRAYNUMBER( ThemeTabItemMap ));
00447 
00448 ThemeTabItem::ThemeTabItem(FXTabBar* p,const FXString& text,FXIcon* ic,FXuint opts,
00449                            FXint x,FXint y,FXint w,FXint h,FXint pl,FXint pr,FXint pt,FXint pb)
00450   : FXTabItem(p,text,ic,opts,x,y,w,h,pl,pr,pt,pb)
00451 {
00452   shadowColor = FXRGB(123,158,189);
00453   borderColor = FXRGB(123,158,189);
00454   hiliteColor = FXRGB(123,158,189);
00455 }
00456 
00457 
00458 
00459 
00460 ThemeVerticalFrame::ThemeVerticalFrame(FXComposite* p,FXuint opts,FXint x,FXint y,FXint w,FXint h,
00461                                        FXint pl,FXint pr,FXint pt,FXint pb,FXint hs,FXint vs)
00462 : FXVerticalFrame( p, opts, x, y, w, h, pl, pr, pt, pb, hs, vs )
00463 {
00464   setHiliteColor( FXRGB(123,158,189) );
00465 }
00466 
00467 
00468 ThemeHorizontalFrame::ThemeHorizontalFrame(FXComposite* p,FXuint opts,FXint x,FXint y,FXint w,FXint h,
00469                                            FXint pl,FXint pr,FXint pt,FXint pb,FXint hs,FXint vs)
00470 : FXHorizontalFrame( p, opts, x, y, w, h, pl, pr, pt, pb, hs, vs )
00471 {
00472   setHiliteColor( FXRGB(123,158,189) );
00473 }
00474 
00475 
00476 
00477 
00478 #define MENUBUTTONARROW_WIDTH  13
00479 #define MENUBUTTONARROW_HEIGHT  5
00480 
00481 FXDEFMAP(ThemeMenuButton) ThemeMenuButtonMap[]={
00482   FXMAPFUNC( SEL_PAINT, 0, ThemeMenuButton::onPaint)
00483 };
00484 
00485 FXIMPLEMENT( ThemeMenuButton, FXMenuButton, ThemeMenuButtonMap, ARRAYNUMBER(ThemeMenuButtonMap) );
00486 
00487 
00488 ThemeMenuButton::ThemeMenuButton(FXComposite* p,const FXString& text,
00489                                  FXIcon* ic,FXPopup* pup,FXuint opts,
00490                                  FXint x,FXint y,FXint w,FXint h,
00491                                  FXint pl,FXint pr,FXint pt,FXint pb )
00492   : FXMenuButton( p, text, ic, pup, opts, x, y, w, h,
00493                  pl, pr, pt, pb)
00494 {
00495 }
00496 
00497 
00498 
00499 // Handle repaint
00500 long ThemeMenuButton::onPaint(FXObject*,FXSelector,void* ptr) {
00501   FXint tw=0,th=0,iw=0,ih=0,tx,ty,ix,iy;
00502   FXEvent *ev=(FXEvent*)ptr;
00503   FXPoint points[6];
00504   FXDCWindow dc(this,ev);
00505   /*
00506   FXColor top         = FXRGB(0xfe,0xfd,0xfd);
00507   FXColor bottom      = FXRGB(0xdd,0xd7,0xce);
00508   FXColor shade       = FXRGB(0xdc,0xd9,0xd4);
00509   */
00510   FXColor top         = FXRGB(0xde,0xe7,0xff);
00511   FXColor bottom      = FXRGB(0xbd,0xcf,0xff);
00512   FXColor shade       = FXRGB(0xbd,0xcb,0xf7);
00513 
00514   FXColor buttoncolor = FXRGB(0x4a,0x61,0x84);
00515 
00516   // FXColor bordercolor = FXRGB(123,158,189);
00517   FXColor bordercolor = shade;
00518 
00519   FXPoint basebackground[4]={
00520     FXPoint(0,0),FXPoint(width-1,0),FXPoint(0,height-1),FXPoint(width-1,height-1)
00521   };
00522   FXPoint bordershade[16]={
00523     FXPoint(0,1),FXPoint(1,0),FXPoint(1,2),FXPoint(2,1),
00524     FXPoint(width-2,0),FXPoint(width-1,1),FXPoint(width-3,1),FXPoint(width-2,2),
00525     FXPoint(0,height-2),FXPoint(1,height-1),FXPoint(1,height-3),FXPoint(2,height-2),
00526     FXPoint(width-1,height-2),FXPoint(width-2,height-1),FXPoint(width-2,height-3),FXPoint(width-3,height-2)
00527   };
00528   FXPoint bordercorners[4]={
00529     FXPoint(1,1),FXPoint(1,height-2),FXPoint(width-2,1),FXPoint(width-2,height-2)
00530   };
00531 
00532 
00533   // Got a border at all?
00534   if (options&(FRAME_RAISED|FRAME_SUNKEN)){
00535 
00536     // Toolbar style
00537     if (options&MENUBUTTON_TOOLBAR){
00538 
00539       // Enabled and cursor inside, and not popped up
00540       if (isEnabled() && underCursor() && !state){
00541         dc.setForeground(backColor);
00542         dc.fillRectangle(border,border,width-border*2,height-border*2);
00543         if(options&FRAME_THICK) drawDoubleRaisedRectangle(dc,0,0,width,height);
00544         else drawRaisedRectangle(dc,0,0,width,height);
00545       }
00546 
00547       // Enabled and popped up
00548       else if (isEnabled() && state){
00549         dc.setForeground(hiliteColor);
00550         dc.fillRectangle(border,border,width-border*2,height-border*2);
00551         if(options&FRAME_THICK) drawDoubleSunkenRectangle(dc,0,0,width,height);
00552         else drawSunkenRectangle(dc,0,0,width,height);
00553       }
00554 
00555       // Disabled or unchecked or not under cursor
00556       else {
00557         dc.setForeground(backColor);
00558         dc.fillRectangle(0,0,width,height);
00559       }
00560     }
00561 
00562     // Normal style
00563     else {
00564       // Draw in up state if disabled or up
00565       if (!isEnabled() || !state){
00566         /*
00567          * dc.setForeground(backColor);
00568          dc.fillRectangle(border,border,width-border*2,height-border*2);
00569          if(options&FRAME_THICK) drawDoubleRaisedRectangle(dc,0,0,width,height);
00570          else drawRaisedRectangle(dc,0,0,width,height);
00571          */
00573         dc.setForeground(baseColor);
00574         dc.drawPoints(basebackground,4);
00576         dc.setForeground(bordercolor);
00577         dc.drawRectangle(2,0,width-5,0);
00578         dc.drawRectangle(2,height-1,width-5,height-1);
00579         dc.drawRectangle(0,2,0,height-5);
00580         dc.drawRectangle(width-1,2,0,height-5);
00581         dc.drawPoints(bordercorners,4);
00582         dc.setForeground(shade);
00583         dc.drawPoints(bordershade,16);
00585         drawRectangle(dc,top,bottom,2,1,width-4,height-2);
00586         dc.setForeground(top);
00587         dc.drawRectangle(1,3,0,height-7);
00588         dc.setForeground(bottom);
00589         dc.drawRectangle(width-2,3,0,height-7);
00590       }
00591 
00592       // Draw sunken if enabled and either checked or pressed
00593       else {
00594         dc.setForeground(baseColor);
00595         dc.drawPoints(basebackground,4);
00597         dc.setForeground(bordercolor);
00598         dc.drawRectangle(2,0,width-5,0);
00599         dc.drawRectangle(2,height-1,width-5,height-1);
00600         dc.drawRectangle(0,2,0,height-5);
00601         dc.drawRectangle(width-1,2,0,height-5);
00602         dc.drawPoints(bordercorners,4);
00603         dc.setForeground(shade);
00604         dc.drawPoints(bordershade,16);
00605 
00606         dc.setForeground(FXRGB(0xdc,0xd4,0xc9));
00607         dc.fillRectangle(2,1,width-4,height-2);
00608       }
00609     }
00610   }
00611 
00612   // No borders
00613   else {
00614     if(isEnabled() && state){
00615       dc.setForeground(hiliteColor);
00616       dc.fillRectangle(0,0,width,height);
00617     }
00618     else{
00619       dc.setForeground(backColor);
00620       dc.fillRectangle(0,0,width,height);
00621     }
00622   }
00623 
00624   // Position text & icon
00625   if (!label.empty()){
00626     tw=labelWidth(label);
00627     th=labelHeight(label);
00628   }
00629 
00630   // Icon?
00631   if (icon){
00632     iw=icon->getWidth();
00633     ih=icon->getHeight();
00634   }
00635 
00636   // Arrows?
00637   else if(!(options&MENUBUTTON_NOARROWS)){
00638     if(options&MENUBUTTON_LEFT){
00639       ih=MENUBUTTONARROW_WIDTH;
00640       iw=MENUBUTTONARROW_HEIGHT;
00641     }
00642     else{
00643       iw=MENUBUTTONARROW_WIDTH;
00644       ih=MENUBUTTONARROW_HEIGHT;
00645     }
00646   }
00647 
00648   // Keep some room for the arrow!
00649   just_x(tx,ix,tw,iw);
00650   just_y(ty,iy,th,ih);
00651 
00652   // Move a bit when pressed
00653   if (state){
00654     ++tx; ++ty; ++ix; ++iy;
00655   }
00656 
00657   // Draw icon
00658   if (icon){
00659     if (isEnabled())
00660       dc.drawIcon(icon,ix,iy);
00661     else
00662       dc.drawIconSunken(icon,ix,iy);
00663   }
00664 
00665   // Draw arrows
00666   else if (!(options&MENUBUTTON_NOARROWS)){
00667 
00668     // Right arrow
00669     if ((options&MENUBUTTON_RIGHT)==MENUBUTTON_RIGHT){
00670       if (isEnabled())
00671         dc.setForeground(buttoncolor);
00672       else
00673         dc.setForeground(shadowColor);
00674       points[0].x=ix;
00675       points[0].y=iy;
00676       points[1].x=ix;
00677       points[1].y=iy+MENUBUTTONARROW_WIDTH-1;
00678       points[2].x=ix+MENUBUTTONARROW_HEIGHT;
00679       points[2].y=(FXshort)(iy+(MENUBUTTONARROW_WIDTH>>1));
00680       dc.fillPolygon(points,3);
00681     }
00682 
00683     // Left arrow
00684     else if (options&MENUBUTTON_LEFT){
00685       if (isEnabled())
00686         dc.setForeground(buttoncolor);
00687       else
00688         dc.setForeground(shadowColor);
00689       points[0].x=ix+MENUBUTTONARROW_HEIGHT;
00690       points[0].y=iy;
00691       points[1].x=ix+MENUBUTTONARROW_HEIGHT;
00692       points[1].y=iy+MENUBUTTONARROW_WIDTH-1;
00693       points[2].x=ix;
00694       points[2].y=(FXshort)(iy+(MENUBUTTONARROW_WIDTH>>1));
00695       dc.fillPolygon(points,3);
00696     }
00697 
00698     // Up arrow
00699     else if (options&MENUBUTTON_UP){
00700       if(isEnabled())
00701         dc.setForeground(buttoncolor);
00702       else
00703         dc.setForeground(shadowColor);
00704       points[0].x=(FXshort)(ix+(MENUBUTTONARROW_WIDTH>>1));
00705       points[0].y=iy-1;
00706       points[1].x=ix;
00707       points[1].y=iy+MENUBUTTONARROW_HEIGHT;
00708       points[2].x=ix+MENUBUTTONARROW_WIDTH;
00709       points[2].y=iy+MENUBUTTONARROW_HEIGHT;
00710       dc.fillPolygon(points,3);
00711     }
00712 
00713     // Down arrow
00714     else {
00715       if(isEnabled())
00716         dc.setForeground(buttoncolor);
00717       else
00718         dc.setForeground(shadowColor);
00719       points[0].x=ix+1;
00720       points[0].y=iy;
00721       points[2].x=ix+MENUBUTTONARROW_WIDTH-1;
00722       points[2].y=iy;
00723       points[1].x=(FXshort)(ix+(MENUBUTTONARROW_WIDTH>>1));
00724       points[1].y=iy+MENUBUTTONARROW_HEIGHT;
00725       points[3].x=ix+MENUBUTTONARROW_WIDTH-3;
00726       points[3].y=iy;
00727       points[4].x=(FXshort)(ix+(MENUBUTTONARROW_WIDTH>>1));
00728       points[4].y=iy+MENUBUTTONARROW_HEIGHT-3;
00729       points[5].x=ix+3;
00730       points[5].y=iy;
00731       dc.fillConcavePolygon(points,6);
00732     }
00733   }
00734 
00735   // Draw text
00736   if (!label.empty()){
00737     dc.setFont(font);
00738     if(isEnabled()){
00739       dc.setForeground(textColor);
00740       drawLabel(dc,label,hotoff,tx,ty,tw,th);
00741     }
00742     else {
00743       dc.setForeground(hiliteColor);
00744       drawLabel(dc,label,hotoff,tx+1,ty+1,tw,th);
00745       dc.setForeground(shadowColor);
00746       drawLabel(dc,label,hotoff,tx,ty,tw,th);
00747     }
00748   }
00749 
00750   // Draw focus
00751   if (hasFocus()){
00752     if (isEnabled()){
00753       dc.drawFocusRectangle(border+1,border+1,width-2*border-2,height-2*border-2);
00754     }
00755   }
00756   return 1;
00757 }
00758 
00759 
00760 
00761 // Get default width
00762 FXint ThemeMenuButton::getDefaultWidth(){
00763   FXint tw=0,iw=0,s=0,w,pw;
00764 
00765   if (!label.empty()){
00766     tw=labelWidth(label); s=4;
00767   }
00768   if (!(options&MENUBUTTON_NOARROWS)){
00769     if (options&MENUBUTTON_LEFT)
00770       iw=MENUBUTTONARROW_HEIGHT;
00771     else
00772       iw=MENUBUTTONARROW_WIDTH;
00773   }
00774   if(icon)
00775     iw=icon->getWidth();
00776   if (!(options&(ICON_AFTER_TEXT|ICON_BEFORE_TEXT)))
00777     w=FXMAX(tw,iw);
00778   else
00779     w=tw+iw+s;
00780   w=padleft+padright+(border<<1)+w;
00781   if (!(options&MENUBUTTON_LEFT) &&
00782       (options&MENUBUTTON_ATTACH_RIGHT) &&
00783       (options&MENUBUTTON_ATTACH_CENTER)) {
00784     if (pane){
00785       pw=pane->getDefaultWidth();
00786       if(pw>w)
00787         w=pw;
00788     }
00789   }
00790   return w;
00791 }
00792 
00793 
00794 
00795 
00796 #if 0
00797 FXDEFMAP(ThemeHeaderItem) ThemeHeaderItemMap[]={
00798   FXMAPFUNC(SEL_PAINT, 0, ThemeHeaderItem::onPaint)
00799 };
00800 
00801 FXIMPLEMENT(ThemeHeaderItem, FXHeaderItem, ThemeHeaderItemMap, ARRAYNUMBER(ThemeHeaderItemMap));
00802 #endif
00803 
00804 
00805 ThemeHeaderItem::ThemeHeaderItem(const FXString& text, FXIcon* ic, FXint s, void* ptr)
00806   :FXHeaderItem(text, ic, s, ptr)
00807 {
00808 }
00809 
00810 
00811 
00812 void ThemeHeaderItem::draw(const FXHeader* header,FXDC& dc,FXint x,FXint y,FXint w,FXint h) {
00813   register FXint tx,ty,tw,th,ix,iy,iw,ih,s,ml,mr,mt,mb,beg,end,t,xx,yy,bb,aa,ax,ay;
00814   register FXFont *font=header->getFont();
00815   FXColor top         = FXRGB(0xfe,0xfd,0xfd);
00816   FXColor bottom      = FXRGB(0xdd,0xd7,0xce);
00817   FXColor shade       = FXRGB(0xdc,0xd9,0xd4);
00818 
00819   // Get border width and padding
00820   bb=header->getBorderWidth();
00821   ml=header->getPadLeft()+bb;
00822   mr=header->getPadRight()+bb;
00823   mt=header->getPadTop()+bb;
00824   mb=header->getPadBottom()+bb;
00825 
00826   dc.setForeground(shade);
00828   drawRectangle(dc,top, bottom, x+2, y+1, w-4, h-2);
00829 
00830   // Shrink by margins
00831   x+=ml; w-=ml+mr;
00832   y+=mt; h-=mt+mb;
00833 
00834   // Initial clip rectangle
00835   dc.setClipRectangle(x,y,w,h);
00836 
00837   dc.setForeground(header->getTextColor());
00838   // Text width and height
00839   tw=th=iw=ih=beg=s=0;
00840   do {
00841     end=beg;
00842     while(end<label.length() && label[end]!='\n') end++;
00843     if((t=font->getTextWidth(&label[beg],end-beg))>tw) tw=t;
00844     th+=font->getFontHeight();
00845     beg=end+1;
00846   }
00847   while(end<label.length());
00848 
00849   // Icon size
00850   if(icon){
00851     iw=icon->getWidth();
00852     ih=icon->getHeight();
00853   }
00854 
00855   // Icon-text spacing
00856   if(iw && tw)
00857     s=ICON_SPACING;
00858 
00859   // Draw arrows
00860   if (state&(ARROW_UP|ARROW_DOWN)){
00861     aa=(font->getFontHeight()-5)|1;
00862     ay=y+(h-aa)/2;
00863     ax=x+w-aa-2;
00864     if(state&ARROW_UP) {
00865       dc.setForeground(header->getHiliteColor());
00866       dc.drawLine(ax+aa/2,ay,ax+aa-1,ay+aa);
00867       dc.drawLine(ax,ay+aa,ax+aa,ay+aa);
00868       dc.setForeground(header->getShadowColor());
00869       dc.drawLine(ax+aa/2,ay,ax,ay+aa);
00870     }
00871     else {
00872       dc.setForeground(header->getHiliteColor());
00873       dc.drawLine(ax+aa/2,ay+aa,ax+aa-1,ay);
00874       dc.setForeground(header->getShadowColor());
00875       dc.drawLine(ax+aa/2,ay+aa,ax,ay);
00876       dc.drawLine(ax,ay,ax+aa,ay);
00877     }
00878     w-=aa+4;
00879     dc.setClipRectangle(x,y,w,h);
00880   }
00881 
00882   // Fix x coordinate
00883   if (state&LEFT){
00884     if(state&BEFORE){
00885       ix=x; tx=ix+iw+s;
00886     }
00887     else if (state&AFTER){
00888       tx=x; ix=tx+tw+s;
00889     }
00890     else {
00891       ix=x; tx=x;
00892     }
00893   }
00894   else if(state&RIGHT){
00895     if(state&BEFORE){
00896       tx=x+w-tw;
00897       ix=tx-iw-s;
00898     }
00899     else if (state&AFTER){
00900       ix=x+w-iw;
00901       tx=ix-tw-s;
00902     }
00903     else {
00904       ix=x+w-iw; tx=x+w-tw;
00905     }
00906   }
00907   else{
00908     if (state&BEFORE){
00909       ix=x+(w-tw-iw-s)/2;
00910       tx=ix+iw+s;
00911     }
00912     else if (state&AFTER){
00913       tx=x+(w-tw-iw-s)/2;
00914       ix=tx+tw+s;
00915     }
00916     else{
00917       ix=x+(w-iw)/2;
00918       tx=x+(w-tw)/2;
00919     }
00920   }
00921 
00922   // Fix y coordinate
00923   if(state&TOP){
00924     if (state&ABOVE){
00925       iy=y;
00926       ty=iy+ih;
00927     }
00928     else if (state&BELOW){
00929       ty=y;
00930       iy=ty+th;
00931     }
00932     else {
00933       iy=y;
00934       ty=y;
00935     }
00936   }
00937   else if(state&BOTTOM){
00938     if (state&ABOVE){
00939       ty=y+h-th;
00940       iy=ty-ih;
00941     }
00942     else if (state&BELOW){
00943       iy=y+h-ih;
00944       ty=iy-th;
00945     }
00946     else{
00947       iy=y+h-ih;
00948       ty=y+h-th;
00949     }
00950   }
00951   else {
00952     if (state&ABOVE){
00953       iy=y+(h-th-ih)/2;
00954       ty=iy+ih;
00955     }
00956     else if (state&BELOW){
00957       ty=y+(h-th-ih)/2;
00958       iy=ty+th;
00959     }
00960     else {
00961       iy=y+(h-ih)/2;
00962       ty=y+(h-th)/2;
00963     }
00964   }
00965 
00966   // Offset a bit when pressed
00967   if (state&PRESSED){
00968     tx++;
00969     ty++;
00970     ix++;
00971     iy++;
00972   }
00973 
00974   // Paint icon
00975   if (icon){
00976     dc.drawIcon(icon,ix,iy);
00977   }
00978 
00979   // Text color
00980   dc.setForeground(header->getTextColor());
00981 
00982   // Draw text
00983   yy=ty+font->getFontAscent();
00984   beg=0;
00985   do {
00986     end=beg;
00987     while(end<label.length() && label[end]!='\n')
00988       end++;
00989     if (state&LEFT)
00990       xx=tx;
00991     else if(state&RIGHT)
00992       xx=tx+tw-font->getTextWidth(&label[beg],end-beg);
00993     else
00994       xx=tx+(tw-font->getTextWidth(&label[beg],end-beg))/2;
00995     dc.drawText(xx,yy,&label[beg],end-beg);
00996     yy+=font->getFontHeight();
00997     beg=end+1;
00998   }
00999   while(end<label.length());
01000 
01001   // Restore original clip path
01002   dc.clearClipRectangle();
01003 }
01004 
01005 
01006 
01007 
01008 
01009