Back to index

lightning-sunbird  0.9+nobinonly
nsLookAndFeel.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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  *   Lars Knoll <knoll@kde.org>
00024  *   Zack Rusin <zack@kde.org>
00025  *   John C. Griggs <johng@corel.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 #include "nsLookAndFeel.h"
00041 
00042 #include <qpalette.h>
00043 #include <qapplication.h>
00044 
00045 #define QCOLOR_TO_NS_RGB(c) \
00046     ((nscolor)NS_RGB(c.red(),c.green(),c.blue()))
00047 
00048 //-------------------------------------------------------------------------
00049 //
00050 // Query interface implementation
00051 //
00052 //-------------------------------------------------------------------------
00053 nsLookAndFeel::nsLookAndFeel() : nsXPLookAndFeel()
00054 {
00055 }
00056 
00057 nsLookAndFeel::~nsLookAndFeel()
00058 {
00059 }
00060 
00061 nsresult nsLookAndFeel::NativeGetColor(const nsColorID aID,nscolor &aColor)
00062 {
00063   nsresult res = NS_OK;
00064 
00065   if (!qApp)
00066     return NS_ERROR_FAILURE;
00067 
00068   QPalette palette = qApp->palette();
00069   QColorGroup normalGroup = palette.inactive();
00070   QColorGroup activeGroup = palette.active();
00071   QColorGroup disabledGroup = palette.disabled();
00072 
00073   switch (aID) {
00074     case eColor_WindowBackground:
00075       aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
00076       break;
00077 
00078     case eColor_WindowForeground:
00079       aColor = QCOLOR_TO_NS_RGB(normalGroup.foreground());
00080       break;
00081 
00082     case eColor_WidgetBackground:
00083       aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
00084       break;
00085 
00086     case eColor_WidgetForeground:
00087       aColor = QCOLOR_TO_NS_RGB(normalGroup.foreground());
00088       break;
00089 
00090     case eColor_WidgetSelectBackground:
00091       aColor = QCOLOR_TO_NS_RGB(activeGroup.background());
00092       break;
00093 
00094     case eColor_WidgetSelectForeground:
00095       aColor = QCOLOR_TO_NS_RGB(activeGroup.foreground());
00096       break;
00097 
00098     case eColor_Widget3DHighlight:
00099       aColor = NS_RGB(0xa0,0xa0,0xa0);
00100       break;
00101 
00102     case eColor_Widget3DShadow:
00103       aColor = NS_RGB(0x40,0x40,0x40);
00104       break;
00105 
00106     case eColor_TextBackground:
00107       aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
00108       break;
00109 
00110     case eColor_TextForeground:
00111       aColor = QCOLOR_TO_NS_RGB(normalGroup.text());
00112       break;
00113 
00114     case eColor_TextSelectBackground:
00115       aColor = QCOLOR_TO_NS_RGB(activeGroup.highlight());
00116       break;
00117 
00118     case eColor_TextSelectForeground:
00119       aColor = QCOLOR_TO_NS_RGB(activeGroup.highlightedText());
00120       break;
00121 
00122     case eColor_activeborder:
00123       aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
00124       break;
00125 
00126     case eColor_activecaption:
00127       aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
00128       break;
00129 
00130     case eColor_appworkspace:
00131       aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
00132       break;
00133 
00134     case eColor_background:
00135       aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
00136       break;
00137 
00138     case eColor_captiontext:
00139       aColor = QCOLOR_TO_NS_RGB(normalGroup.text());
00140       break;
00141 
00142     case eColor_graytext:
00143       aColor = QCOLOR_TO_NS_RGB(disabledGroup.text());
00144       break;
00145 
00146     case eColor_highlight:
00147       aColor = QCOLOR_TO_NS_RGB(activeGroup.highlight());
00148       break;
00149 
00150     case eColor_highlighttext:
00151       aColor = QCOLOR_TO_NS_RGB(activeGroup.highlightedText());
00152       break;
00153 
00154     case eColor_inactiveborder:
00155       aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
00156       break;
00157 
00158     case eColor_inactivecaption:
00159       aColor = QCOLOR_TO_NS_RGB(disabledGroup.background());
00160       break;
00161 
00162     case eColor_inactivecaptiontext:
00163       aColor = QCOLOR_TO_NS_RGB(disabledGroup.text());
00164       break;
00165 
00166     case eColor_infobackground:
00167       aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
00168       break;
00169 
00170     case eColor_infotext:
00171       aColor = QCOLOR_TO_NS_RGB(normalGroup.text());
00172       break;
00173 
00174     case eColor_menu:
00175       aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
00176       break;
00177 
00178     case eColor_menutext:
00179       aColor = QCOLOR_TO_NS_RGB(normalGroup.text());
00180       break;
00181 
00182     case eColor_scrollbar:
00183       aColor = QCOLOR_TO_NS_RGB(activeGroup.background());
00184       break;
00185 
00186     case eColor_threedface:
00187     case eColor_buttonface:
00188       aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
00189       break;
00190 
00191     case eColor_buttonhighlight:
00192     case eColor_threedhighlight:
00193       aColor = QCOLOR_TO_NS_RGB(normalGroup.light());
00194       break;
00195 
00196     case eColor_buttontext:
00197       aColor = QCOLOR_TO_NS_RGB(normalGroup.text());
00198       break;
00199 
00200     case eColor_buttonshadow:
00201     case eColor_threedshadow:
00202       aColor = QCOLOR_TO_NS_RGB(normalGroup.shadow());
00203       break;
00204 
00205     case eColor_threeddarkshadow:
00206       aColor = QCOLOR_TO_NS_RGB(normalGroup.dark());
00207       break;
00208 
00209     case eColor_threedlightshadow:
00210       aColor = QCOLOR_TO_NS_RGB(normalGroup.light());
00211       break;
00212 
00213     case eColor_window:
00214     case eColor_windowframe:
00215       aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
00216       break;
00217 
00218     case eColor_windowtext:
00219       aColor = QCOLOR_TO_NS_RGB(normalGroup.text());
00220       break;
00221 
00222      // from the CSS3 working draft (not yet finalized)
00223      // http://www.w3.org/tr/2000/wd-css3-userint-20000216.html#color
00224      case eColor__moz_field:
00225        aColor = QCOLOR_TO_NS_RGB(normalGroup.base());
00226        break;
00227 
00228      case eColor__moz_fieldtext:
00229        aColor = QCOLOR_TO_NS_RGB(normalGroup.text());
00230        break;
00231 
00232      case eColor__moz_dialog:
00233        aColor = QCOLOR_TO_NS_RGB(normalGroup.background());
00234        break;
00235 
00236      case eColor__moz_dialogtext:
00237        aColor = QCOLOR_TO_NS_RGB(normalGroup.text());
00238        break;
00239 
00240      case eColor__moz_dragtargetzone:
00241        aColor = QCOLOR_TO_NS_RGB(activeGroup.background());
00242        break;
00243 
00244     default:
00245       aColor = 0;
00246       res    = NS_ERROR_FAILURE;
00247       break;
00248   }
00249   return res;
00250 }
00251 
00252 static const char *metricToString[] = {
00253     "eMetric_WindowTitleHeight",
00254     "eMetric_WindowBorderWidth",
00255     "eMetric_WindowBorderHeight",
00256     "eMetric_Widget3DBorder",
00257     "eMetric_TextFieldBorder"
00258     "eMetric_TextFieldHeight",
00259     "eMetric_TextVerticalInsidePadding",
00260     "eMetric_TextShouldUseVerticalInsidePadding",
00261     "eMetric_TextHorizontalInsideMinimumPadding",
00262     "eMetric_TextShouldUseHorizontalInsideMinimumPadding",
00263     "eMetric_ButtonHorizontalInsidePaddingNavQuirks",
00264     "eMetric_ButtonHorizontalInsidePaddingOffsetNavQuirks",
00265     "eMetric_CheckboxSize",
00266     "eMetric_RadioboxSize",
00267 
00268     "eMetric_ListShouldUseHorizontalInsideMinimumPadding",
00269     "eMetric_ListHorizontalInsideMinimumPadding",
00270 
00271     "eMetric_ListShouldUseVerticalInsidePadding",
00272     "eMetric_ListVerticalInsidePadding",
00273 
00274     "eMetric_CaretBlinkTime",
00275     "eMetric_CaretWidth",
00276     "eMetric_ShowCaretDuringSelection",
00277     "eMetric_SelectTextfieldsOnKeyFocus",
00278     "eMetric_SubmenuDelay",
00279     "eMetric_MenusCanOverlapOSBar",
00280     "eMetric_DragFullWindow",
00281     "eMetric_DragThresholdX",
00282     "eMetric_DragThresholdY",
00283     "eMetric_UseAccessibilityTheme",
00284     "eMetric_IsScreenReaderActive",
00285 
00286     "eMetric_ScrollArrowStyle",
00287     "eMetric_ScrollSliderStyle",
00288 
00289     "eMetric_TreeOpenDelay",
00290     "eMetric_TreeCloseDelay",
00291     "eMetric_TreeLazyScrollDelay",
00292     "eMetric_TreeScrollDelay",
00293     "eMetric_TreeScrollLinesMax"
00294     };
00295 
00296 
00297 NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID,PRInt32 &aMetric)
00298 {
00299 //     qDebug("nsLookAndFeel::GetMetric aID = %s", metricToString[aID]);
00300   nsresult res = nsXPLookAndFeel::GetMetric(aID, aMetric);
00301   if (NS_SUCCEEDED(res))
00302       return res;
00303 //   qDebug("    checking ourselves");
00304   res = NS_OK;
00305 
00306   switch (aID) {
00307     case eMetric_WindowTitleHeight:
00308       aMetric = 0;
00309       break;
00310 
00311     case eMetric_WindowBorderWidth:
00312       // There was once code in nsDeviceContextQt::GetSystemAttribute to
00313       // use the border width obtained from a widget in its Init method.
00314       break;
00315 
00316     case eMetric_WindowBorderHeight:
00317       // There was once code in nsDeviceContextQt::GetSystemAttribute to
00318       // use the border width obtained from a widget in its Init method.
00319       break;
00320 
00321     case eMetric_Widget3DBorder:
00322       aMetric = 4;
00323       break;
00324 
00325     case eMetric_TextFieldHeight:
00326       aMetric = 15;
00327       break;
00328 
00329     case eMetric_TextFieldBorder:
00330       aMetric = 2;
00331       break;
00332 
00333     case eMetric_TextVerticalInsidePadding:
00334       aMetric = 0;
00335       break;
00336 
00337     case eMetric_TextShouldUseVerticalInsidePadding:
00338       aMetric = 0;
00339       break;
00340 
00341     case eMetric_TextHorizontalInsideMinimumPadding:
00342       aMetric = 15;
00343       break;
00344 
00345     case eMetric_TextShouldUseHorizontalInsideMinimumPadding:
00346       aMetric = 1;
00347       break;
00348 
00349     case eMetric_ButtonHorizontalInsidePaddingNavQuirks:
00350       aMetric = 10;
00351       break;
00352 
00353     case eMetric_ButtonHorizontalInsidePaddingOffsetNavQuirks:
00354       aMetric = 8;
00355       break;
00356 
00357     case eMetric_CheckboxSize:
00358       aMetric = 15;
00359       break;
00360 
00361     case eMetric_RadioboxSize:
00362       aMetric = 15;
00363       break;
00364 
00365     case eMetric_ListShouldUseHorizontalInsideMinimumPadding:
00366       aMetric = 15;
00367       break;
00368 
00369     case eMetric_ListHorizontalInsideMinimumPadding:
00370       aMetric = 15;
00371       break;
00372 
00373     case eMetric_ListShouldUseVerticalInsidePadding:
00374       aMetric = 1;
00375       break;
00376 
00377     case eMetric_ListVerticalInsidePadding:
00378       aMetric = 1;
00379       break;
00380 
00381     case eMetric_CaretBlinkTime:
00382       aMetric = 500;
00383       break;
00384 
00385     case eMetric_CaretWidth:
00386       aMetric = 1;
00387       break;
00388 
00389     case eMetric_ShowCaretDuringSelection:
00390       aMetric = 0;
00391       break;
00392 
00393     case eMetric_SelectTextfieldsOnKeyFocus:
00394       // Select textfield content when focused by kbd
00395       // used by nsEventStateManager::sTextfieldSelectModel
00396       aMetric = 1;
00397       break;
00398 
00399     case eMetric_SubmenuDelay:
00400       aMetric = 200;
00401       break;
00402 
00403     case eMetric_MenusCanOverlapOSBar:
00404       // we want XUL popups to be able to overlap the task bar.
00405       aMetric = 1;
00406       break;
00407 
00408     case eMetric_DragFullWindow:
00409       aMetric = 1;
00410       break;
00411 
00412     case eMetric_ScrollArrowStyle:
00413       aMetric = eMetric_ScrollArrowStyleSingle;
00414       break;
00415 
00416     case eMetric_ScrollSliderStyle:
00417       aMetric = eMetric_ScrollThumbStyleProportional;
00418       break;
00419 
00420     default:
00421       aMetric = 0;
00422       res = NS_ERROR_FAILURE;
00423   }
00424   return res;
00425 }
00426 
00427 NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricFloatID aID,
00428                                        float &aMetric)
00429 {
00430   nsresult res = nsXPLookAndFeel::GetMetric(aID, aMetric);
00431   if (NS_SUCCEEDED(res))
00432       return res;
00433   res = NS_OK;
00434 
00435   switch (aID) {
00436     case eMetricFloat_TextFieldVerticalInsidePadding:
00437       aMetric = 0.25f;
00438       break;
00439 
00440     case eMetricFloat_TextFieldHorizontalInsidePadding:
00441       aMetric = 0.95f; // large number on purpose so minimum padding is used
00442       break;
00443 
00444     case eMetricFloat_TextAreaVerticalInsidePadding:
00445       aMetric = 0.40f;
00446       break;
00447 
00448     case eMetricFloat_TextAreaHorizontalInsidePadding:
00449       aMetric = 0.40f; // large number on purpose so minimum padding is used
00450       break;
00451 
00452     case eMetricFloat_ListVerticalInsidePadding:
00453       aMetric = 0.10f;
00454       break;
00455 
00456     case eMetricFloat_ListHorizontalInsidePadding:
00457       aMetric = 0.40f;
00458       break;
00459 
00460     case eMetricFloat_ButtonVerticalInsidePadding:
00461       aMetric = 0.25f;
00462       break;
00463 
00464     case eMetricFloat_ButtonHorizontalInsidePadding:
00465       aMetric = 0.25f;
00466       break;
00467 
00468     default:
00469       aMetric = -1.0;
00470       res = NS_ERROR_FAILURE;
00471   }
00472   return res;
00473 }