Back to index

lightning-sunbird  0.9+nobinonly
nsXPLookAndFeel.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; 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  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef __nsXPLookAndFeel
00039 #define __nsXPLookAndFeel
00040 
00041 #include "nsILookAndFeel.h"
00042 #include "nsCOMPtr.h"
00043 
00044 class nsIPref;
00045 
00046 #ifdef NS_DEBUG
00047 struct nsSize;
00048 #endif
00049 
00050 typedef enum {
00051   nsLookAndFeelTypeInt,
00052   nsLookAndFeelTypeFloat,
00053   nsLookAndFeelTypeColor
00054 } nsLookAndFeelType;
00055 
00056 struct nsLookAndFeelIntPref
00057 {
00058   const char* name;
00059   nsILookAndFeel::nsMetricID id;
00060   PRPackedBool isSet;
00061   nsLookAndFeelType type;
00062   PRInt32 intVar;
00063 };
00064 
00065 struct nsLookAndFeelFloatPref
00066 {
00067   const char* name;
00068   nsILookAndFeel::nsMetricFloatID id;
00069   PRPackedBool isSet;
00070   nsLookAndFeelType type;
00071   float floatVar;
00072 };
00073 
00074 #define CACHE_BLOCK(x)     ((x) >> 5)
00075 #define CACHE_BIT(x)       (1 << ((x) & 31))
00076 
00077 #define COLOR_CACHE_SIZE   (CACHE_BLOCK(nsILookAndFeel::eColor_LAST_COLOR) + 1)
00078 #define IS_COLOR_CACHED(x) (CACHE_BIT(x) & nsXPLookAndFeel::sCachedColorBits[CACHE_BLOCK(x)])
00079 #define CACHE_COLOR(x, y)  nsXPLookAndFeel::sCachedColors[(x)] = y; \
00080               nsXPLookAndFeel::sCachedColorBits[CACHE_BLOCK(x)] |= CACHE_BIT(x);
00081 
00082 class nsXPLookAndFeel: public nsILookAndFeel
00083 {
00084 public:
00085   nsXPLookAndFeel();
00086   virtual ~nsXPLookAndFeel();
00087 
00088   NS_DECL_ISUPPORTS
00089 
00090   void Init();
00091 
00092   //
00093   // All these routines will return NS_OK if they have a value,
00094   // in which case the nsLookAndFeel should use that value;
00095   // otherwise we'll return NS_ERROR_NOT_AVAILABLE, in which case, the
00096   // platform-specific nsLookAndFeel should use its own values instead.
00097   //
00098   NS_IMETHOD GetColor(const nsColorID aID, nscolor &aColor);
00099   NS_IMETHOD GetMetric(const nsMetricID aID, PRInt32 & aMetric);
00100   NS_IMETHOD GetMetric(const nsMetricFloatID aID, float & aMetric);
00101 
00102   NS_IMETHOD LookAndFeelChanged();
00103 
00104 #ifdef NS_DEBUG
00105   NS_IMETHOD GetNavSize(const nsMetricNavWidgetID aWidgetID,
00106                         const nsMetricNavFontID   aFontID, 
00107                         const PRInt32             aFontSize, 
00108                         nsSize &aSize);
00109 #endif
00110 
00111 protected:
00112   nsresult InitFromPref(nsLookAndFeelIntPref* aPref, nsIPref* aPrefService);
00113   nsresult InitFromPref(nsLookAndFeelFloatPref* aPref, nsIPref* aPrefService);
00114   nsresult InitColorFromPref(PRInt32 aIndex, nsIPref* aPrefService);
00115   virtual nsresult NativeGetColor(const nsColorID aID, nscolor& aColor) = 0;
00116 
00117   static PRBool sInitialized;
00118   static nsLookAndFeelIntPref sIntPrefs[];
00119   static nsLookAndFeelFloatPref sFloatPrefs[];
00120   /* this length must not be shorter than the length of the longest string in the array
00121    * see nsXPLookAndFeel.cpp
00122    */
00123   static const char sColorPrefs[][36];
00124   static PRInt32 sCachedColors[nsILookAndFeel::eColor_LAST_COLOR];
00125   static PRInt32 sCachedColorBits[COLOR_CACHE_SIZE];
00126 
00127   friend int colorPrefChanged(const char* aPref, void* aData);
00128 };
00129 
00130 extern nsresult NS_NewXPLookAndFeel(nsILookAndFeel**);
00131 
00132 #endif