Back to index

lightning-sunbird  0.9+nobinonly
nsLookAndFeel.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   John Fairhurst <john_fairhurst@iname.com>
00024  *   Michael Lowe <michael.lowe@bigfoot.com>
00025  *   Pierre Phaneuf <pp@ludusdesign.com>
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either the GNU General Public License Version 2 or later (the "GPL"), or
00029  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 
00041 #define INCL_WIN
00042 #include <os2.h>
00043 #include "nsLookAndFeel.h"
00044 #include "nsFont.h"
00045 #include "nsSize.h"
00046  
00047 nsLookAndFeel::nsLookAndFeel() : nsXPLookAndFeel()
00048 {
00049 }
00050 
00051 nsLookAndFeel::~nsLookAndFeel()
00052 {
00053 }
00054 
00055 nsresult nsLookAndFeel::NativeGetColor(const nsColorID aID, nscolor &aColor)
00056 {
00057   nsresult res = NS_OK;
00058 
00059   int idx;
00060   switch (aID) {
00061     case eColor_WindowBackground:
00062         idx = SYSCLR_WINDOW;
00063         break;
00064     case eColor_WindowForeground:
00065         idx = SYSCLR_WINDOWTEXT;
00066         break;
00067     case eColor_WidgetBackground:
00068         idx = SYSCLR_BUTTONMIDDLE;
00069         break;
00070     case eColor_WidgetForeground:
00071         idx = SYSCLR_WINDOWTEXT; 
00072         break;
00073     case eColor_WidgetSelectBackground:
00074         idx = SYSCLR_HILITEBACKGROUND;
00075         break;
00076     case eColor_WidgetSelectForeground:
00077         idx = SYSCLR_HILITEFOREGROUND;
00078         break;
00079     case eColor_Widget3DHighlight:
00080         idx = SYSCLR_BUTTONLIGHT;
00081         break;
00082     case eColor_Widget3DShadow:
00083         idx = SYSCLR_BUTTONDARK;
00084         break;
00085     case eColor_TextBackground:
00086         idx = SYSCLR_WINDOW;
00087         break;
00088     case eColor_TextForeground:
00089         idx = SYSCLR_WINDOWTEXT;
00090         break;
00091     case eColor_TextSelectBackground:
00092         idx = SYSCLR_HILITEBACKGROUND;
00093         break;
00094     case eColor_TextSelectForeground:
00095         idx = SYSCLR_HILITEFOREGROUND;
00096         break;
00097 
00098     // New CSS 2 Color definitions
00099     case eColor_activeborder:
00100       idx = SYSCLR_ACTIVEBORDER;
00101       break;
00102     case eColor_activecaption:
00103       idx = SYSCLR_ACTIVETITLETEXT;
00104       break;
00105     case eColor_appworkspace:
00106       idx = SYSCLR_APPWORKSPACE;
00107       break;
00108     case eColor_background:
00109       idx = SYSCLR_BACKGROUND;
00110       break;
00111     case eColor_buttonface:
00112     case eColor__moz_buttonhoverface:
00113       idx = SYSCLR_BUTTONMIDDLE;
00114       break;
00115     case eColor_buttonhighlight:
00116       idx = SYSCLR_BUTTONLIGHT;
00117       break;
00118     case eColor_buttonshadow:
00119       idx = SYSCLR_BUTTONDARK;
00120       break;
00121     case eColor_buttontext:
00122     case eColor__moz_buttonhovertext:
00123       idx = SYSCLR_MENUTEXT;
00124       break;
00125     case eColor_captiontext:
00126       idx = SYSCLR_WINDOWTEXT;
00127       break;
00128     case eColor_graytext:
00129       idx = SYSCLR_MENUDISABLEDTEXT;
00130       break;
00131     case eColor_highlight:
00132       idx = SYSCLR_HILITEBACKGROUND;
00133       break;
00134     case eColor_highlighttext:
00135       idx = SYSCLR_HILITEFOREGROUND;
00136       break;
00137     case eColor_inactiveborder:
00138       idx = SYSCLR_INACTIVEBORDER;
00139       break;
00140     case eColor_inactivecaption:
00141       idx = SYSCLR_INACTIVETITLE;
00142       break;
00143     case eColor_inactivecaptiontext:
00144       idx = SYSCLR_INACTIVETITLETEXT;
00145       break;
00146     case eColor_infobackground:
00147       aColor = NS_RGB( 255, 255, 228);
00148       return res;
00149     case eColor_infotext:
00150       idx = SYSCLR_WINDOWTEXT;
00151       break;
00152     case eColor_menu:
00153       idx = SYSCLR_MENU;
00154       break;
00155     case eColor_menutext:
00156       idx = SYSCLR_MENUTEXT;
00157       break;
00158     case eColor_scrollbar:
00159       idx = SYSCLR_SCROLLBAR;
00160       break;
00161     case eColor_threeddarkshadow:
00162       idx = SYSCLR_BUTTONDARK;
00163       break;
00164     case eColor_threedface:
00165       idx = SYSCLR_BUTTONMIDDLE;
00166       break;
00167     case eColor_threedhighlight:
00168       idx = SYSCLR_BUTTONLIGHT;
00169       break;
00170     case eColor_threedlightshadow:
00171       idx = SYSCLR_BUTTONMIDDLE;
00172       break;
00173     case eColor_threedshadow:
00174       idx = SYSCLR_BUTTONDARK;
00175       break;
00176     case eColor_window:
00177       idx = SYSCLR_WINDOW;
00178       break;
00179     case eColor_windowframe:
00180       idx = SYSCLR_WINDOWFRAME;
00181       break;
00182     case eColor_windowtext:
00183       idx = SYSCLR_WINDOWTEXT;
00184       break;
00185     case eColor__moz_field:
00186       idx = SYSCLR_ENTRYFIELD;
00187       break;
00188     case eColor__moz_fieldtext:
00189       idx = SYSCLR_WINDOWTEXT;
00190       break;
00191     case eColor__moz_dialog:
00192     case eColor__moz_cellhighlight:
00193       idx = SYSCLR_DIALOGBACKGROUND;
00194       break;
00195     case eColor__moz_dialogtext:
00196     case eColor__moz_cellhighlighttext:
00197       idx = SYSCLR_WINDOWTEXT;
00198       break;
00199     case eColor__moz_buttondefault:
00200       idx = SYSCLR_BUTTONDEFAULT;
00201       break;
00202     case eColor__moz_menuhover:
00203       if (WinQuerySysColor(HWND_DESKTOP, SYSCLR_MENUHILITEBGND, 0) ==
00204           WinQuerySysColor(HWND_DESKTOP, SYSCLR_MENU, 0)) {
00205         // if this happens, we would paint menu selections unreadable
00206         // (we are most likely on Warp3), so let's fake a dark grey
00207         // background for the selected menu item
00208         aColor = NS_RGB( 132, 130, 132);
00209         return res;
00210       } else {
00211         idx = SYSCLR_MENUHILITEBGND;
00212       }
00213       break;
00214     case eColor__moz_menuhovertext:
00215       if (WinQuerySysColor(HWND_DESKTOP, SYSCLR_MENUHILITEBGND, 0) ==
00216           WinQuerySysColor(HWND_DESKTOP, SYSCLR_MENU, 0)) {
00217         // white text to be readable on dark grey
00218         aColor = NS_RGB( 255, 255, 255);
00219         return res;
00220       } else {
00221         idx = SYSCLR_MENUHILITE;
00222       }
00223       break;
00224     default:
00225       idx = SYSCLR_WINDOW;
00226       break;
00227   }
00228 
00229   long lColor = WinQuerySysColor( HWND_DESKTOP, idx, 0);
00230 
00231   int iRed = (lColor & RGB_RED) >> 16;
00232   int iGreen = (lColor & RGB_GREEN) >> 8;
00233   int iBlue = (lColor & RGB_BLUE);
00234 
00235   aColor = NS_RGB( iRed, iGreen, iBlue);
00236 
00237   return res;
00238 }
00239   
00240 NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID, PRInt32 & aMetric)
00241 {
00242   nsresult res = nsXPLookAndFeel::GetMetric(aID, aMetric);
00243   if (NS_SUCCEEDED(res))
00244       return res;
00245   res = NS_OK;
00246 
00247   switch (aID) {
00248     case eMetric_WindowTitleHeight:
00249         aMetric = WinQuerySysValue( HWND_DESKTOP, SV_CYTITLEBAR);
00250         break;
00251     case eMetric_WindowBorderWidth:
00252         aMetric = WinQuerySysValue( HWND_DESKTOP, SV_CXSIZEBORDER);
00253         break;
00254     case eMetric_WindowBorderHeight:
00255         aMetric = WinQuerySysValue( HWND_DESKTOP, SV_CYSIZEBORDER);
00256         break;
00257     case eMetric_Widget3DBorder:
00258         aMetric = WinQuerySysValue( HWND_DESKTOP, SV_CXBORDER);
00259         break;
00260     case eMetric_TextFieldBorder:
00261         aMetric = 3;
00262         break;
00263     case eMetric_TextFieldHeight:
00264         aMetric = 24;
00265         break;
00266     case eMetric_ButtonHorizontalInsidePaddingNavQuirks:
00267         aMetric = 10;
00268         break;
00269     case eMetric_ButtonHorizontalInsidePaddingOffsetNavQuirks:
00270         aMetric = 8;
00271         break;
00272     case eMetric_CheckboxSize:
00273         aMetric = 12;
00274         break;
00275     case eMetric_RadioboxSize:
00276         aMetric = 12;
00277         break;
00278     case eMetric_TextHorizontalInsideMinimumPadding:
00279         aMetric = 3;
00280         break;
00281     case eMetric_TextVerticalInsidePadding:
00282         aMetric = 0;
00283         break;
00284     case eMetric_TextShouldUseVerticalInsidePadding:
00285         aMetric = 0;
00286         break;
00287     case eMetric_TextShouldUseHorizontalInsideMinimumPadding:
00288         aMetric = 1;
00289         break;
00290     case eMetric_ListShouldUseHorizontalInsideMinimumPadding:
00291         aMetric = 0;
00292         break;
00293     case eMetric_ListHorizontalInsideMinimumPadding:
00294         aMetric = 3;
00295         break;
00296     case eMetric_ListShouldUseVerticalInsidePadding:
00297         aMetric = 0;
00298         break;
00299     case eMetric_ListVerticalInsidePadding:
00300         aMetric = 0;
00301         break;
00302     case eMetric_CaretBlinkTime:
00303         aMetric = WinQuerySysValue( HWND_DESKTOP, SV_CURSORRATE);
00304         break;
00305     case eMetric_CaretWidth:
00306         aMetric = 1;
00307         break;
00308     case eMetric_ShowCaretDuringSelection:
00309         aMetric = 0;
00310         break;
00311     case eMetric_SelectTextfieldsOnKeyFocus:
00312         // Do not select textfield content when focused by kbd
00313         // used by nsEventStateManager::sTextfieldSelectModel
00314         aMetric = 0;
00315         break;
00316     case eMetric_SubmenuDelay:
00317         aMetric = 300;
00318         break;
00319     case eMetric_MenusCanOverlapOSBar:
00320         // we want XUL popups to be able to overlap the task bar.
00321         aMetric = 1;
00322         break;
00323     case eMetric_ScrollArrowStyle:
00324         aMetric = eMetric_ScrollArrowStyleSingle;
00325         break;
00326     case eMetric_ScrollSliderStyle:
00327         aMetric = eMetric_ScrollThumbStyleProportional;
00328         break;
00329     case eMetric_TreeOpenDelay:
00330         aMetric = 1000;
00331         break;
00332     case eMetric_TreeCloseDelay:
00333         aMetric = 0;
00334         break;
00335     case eMetric_TreeLazyScrollDelay:
00336         aMetric = 150;
00337         break;
00338     case eMetric_TreeScrollDelay:
00339         aMetric = 100;
00340         break;
00341     case eMetric_TreeScrollLinesMax:
00342         aMetric = 3;
00343         break;
00344 
00345     default:
00346         aMetric = 0;
00347         res = NS_ERROR_FAILURE;
00348     }
00349   return res;
00350 }
00351 
00352 NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricFloatID aID, float & aMetric)
00353 {
00354   nsresult res = nsXPLookAndFeel::GetMetric(aID, aMetric);
00355   if (NS_SUCCEEDED(res))
00356     return res;
00357   res = NS_OK;
00358 
00359   switch (aID) {
00360     case eMetricFloat_TextFieldVerticalInsidePadding:
00361         aMetric = 0.25f;
00362         break;
00363     case eMetricFloat_TextFieldHorizontalInsidePadding:
00364         aMetric = 1.025f;
00365         break;
00366     case eMetricFloat_TextAreaVerticalInsidePadding:
00367         aMetric = 0.40f;
00368         break;
00369     case eMetricFloat_TextAreaHorizontalInsidePadding:
00370         aMetric = 0.40f;
00371         break;
00372     case eMetricFloat_ListVerticalInsidePadding:
00373         aMetric = 0.10f;
00374         break;
00375     case eMetricFloat_ListHorizontalInsidePadding:
00376         aMetric = 0.40f;
00377         break;
00378     case eMetricFloat_ButtonVerticalInsidePadding:
00379         aMetric = 0.25f;
00380         break;
00381     case eMetricFloat_ButtonHorizontalInsidePadding:
00382         aMetric = 0.25f;
00383         break;
00384     default:
00385         aMetric = -1.0;
00386         res = NS_ERROR_FAILURE;
00387     }
00388   return res;
00389 }
00390 
00391 
00392 #ifdef NS_DEBUG
00393 
00394 NS_IMETHODIMP nsLookAndFeel::GetNavSize(const nsMetricNavWidgetID aWidgetID,
00395                                         const nsMetricNavFontID   aFontID, 
00396                                         const PRInt32             aFontSize, 
00397                                         nsSize &aSize)
00398 {
00399   nsresult rv = nsXPLookAndFeel::GetNavSize(aWidgetID, aFontID, aFontSize,
00400                                             aSize);
00401   if (NS_SUCCEEDED(rv))
00402       return rv;
00403 
00404   aSize.width  = 0;
00405   aSize.height = 0;
00406 
00407   if (aFontSize < 1 || aFontSize > 7) {
00408     return NS_ERROR_FAILURE;
00409   }
00410 
00411   PRInt32 kTextFieldWidths[2][7] = {
00412     {106,147,169,211,253,338,506}, // Courier
00413     {152,214,237,281,366,495,732}  // sans-serif
00414   };
00415 
00416   PRInt32 kTextFieldHeights[2][7] = {
00417     {18,21,24,27,33,45,63}, // Courier
00418     {18,21,24,27,34,48,67}  // sans-serif
00419   };
00420 
00421   PRInt32 kTextAreaWidths[2][7] = {
00422     {121,163,184,226,268,352,520}, // Courier
00423     {163,226,247,289,373,499,730}  // sans-serif
00424   };
00425 
00426   PRInt32 kTextAreaHeights[2][7] = {
00427     {40,44,48,52,60,76,100}, // Courier
00428     {40,44,48,52,62,80,106}  // sans-serif
00429   };
00430 
00431   switch (aWidgetID) {
00432     case eMetricSize_TextField:
00433       aSize.width  = kTextFieldWidths[aFontID][aFontSize-1];
00434       aSize.height = kTextFieldHeights[aFontID][aFontSize-1];
00435       break;
00436     case eMetricSize_TextArea:
00437       aSize.width  = kTextAreaWidths[aFontID][aFontSize-1];
00438       aSize.height = kTextAreaHeights[aFontID][aFontSize-1];
00439       break;
00440    /* Added to avoid warning errors - these are not used right now */
00441    case eMetricSize_ListBox:
00442    case eMetricSize_ComboBox:
00443    case eMetricSize_Radio:
00444    case eMetricSize_CheckBox:
00445    case eMetricSize_Button:
00446       break;
00447   } //switch
00448 
00449   return NS_OK;
00450 
00451 }
00452 #endif