зеркало из https://github.com/mozilla/gecko-dev.git
Bug 656826 part.4 xpwidgets should use new pref utilities r=roc
This commit is contained in:
Родитель
57a9ee7b21
Коммит
21bb5457d0
|
@ -41,13 +41,10 @@
|
|||
|
||||
#include "GfxInfoWebGL.h"
|
||||
#include "GfxDriverInfo.h"
|
||||
#include "nsIPrefBranch2.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsCOMArray.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsString.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "mozilla/Services.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsIObserverService.h"
|
||||
|
@ -56,6 +53,7 @@
|
|||
#include "nsIDOM3Node.h"
|
||||
#include "nsIDOMNodeList.h"
|
||||
#include "nsTArray.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
|
||||
#if defined(MOZ_CRASHREPORTER) && defined(MOZ_ENABLE_LIBXUL)
|
||||
#include "nsExceptionHandler.h"
|
||||
|
@ -122,6 +120,7 @@ CrashSpline(double tolerance, int ax, int ay, int bx, int by, int cx, int cy, in
|
|||
|
||||
|
||||
using namespace mozilla::widget;
|
||||
using namespace mozilla;
|
||||
|
||||
NS_IMPL_ISUPPORTS3(GfxInfoBase, nsIGfxInfo, nsIObserver, nsISupportsWeakReference)
|
||||
|
||||
|
@ -171,16 +170,8 @@ GetPrefValueForFeature(PRInt32 aFeature, PRInt32& aValue)
|
|||
if (!prefname)
|
||||
return false;
|
||||
|
||||
nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
if (prefs) {
|
||||
PRInt32 val;
|
||||
if (NS_SUCCEEDED(prefs->GetIntPref(prefname, &val))) {
|
||||
aValue = val;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
aValue = PR_FALSE;
|
||||
return NS_SUCCEEDED(Preferences::GetInt(prefname, &aValue));
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -190,10 +181,7 @@ SetPrefValueForFeature(PRInt32 aFeature, PRInt32 aValue)
|
|||
if (!prefname)
|
||||
return;
|
||||
|
||||
nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
if (prefs) {
|
||||
prefs->SetIntPref(prefname, aValue);
|
||||
}
|
||||
Preferences::SetInt(prefname, aValue);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -203,46 +191,25 @@ RemovePrefForFeature(PRInt32 aFeature)
|
|||
if (!prefname)
|
||||
return;
|
||||
|
||||
nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
if (prefs) {
|
||||
prefs->ClearUserPref(prefname);
|
||||
}
|
||||
Preferences::ClearUser(prefname);
|
||||
}
|
||||
|
||||
static bool
|
||||
GetPrefValueForDriverVersion(nsACString& aVersion)
|
||||
GetPrefValueForDriverVersion(nsCString& aVersion)
|
||||
{
|
||||
nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
if (prefs) {
|
||||
nsXPIDLCString version;
|
||||
if (NS_SUCCEEDED(prefs->GetCharPref(SUGGESTED_VERSION_PREF,
|
||||
getter_Copies(version)))) {
|
||||
aVersion = version;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return NS_SUCCEEDED(Preferences::GetChar(SUGGESTED_VERSION_PREF, &aVersion));
|
||||
}
|
||||
|
||||
static void
|
||||
SetPrefValueForDriverVersion(const nsAString& aVersion)
|
||||
SetPrefValueForDriverVersion(const nsString& aVersion)
|
||||
{
|
||||
nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
if (prefs) {
|
||||
nsCAutoString ver = NS_LossyConvertUTF16toASCII(aVersion);
|
||||
prefs->SetCharPref(SUGGESTED_VERSION_PREF,
|
||||
PromiseFlatCString(ver).get());
|
||||
}
|
||||
Preferences::SetChar(SUGGESTED_VERSION_PREF, aVersion);
|
||||
}
|
||||
|
||||
static void
|
||||
RemovePrefForDriverVersion()
|
||||
{
|
||||
nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
if (prefs) {
|
||||
prefs->ClearUserPref(SUGGESTED_VERSION_PREF);
|
||||
}
|
||||
Preferences::ClearUser(SUGGESTED_VERSION_PREF);
|
||||
}
|
||||
|
||||
// <foo>Hello</foo> - "Hello" is stored as a child text node of the foo node.
|
||||
|
|
|
@ -66,11 +66,13 @@
|
|||
#include "nsIViewObserver.h"
|
||||
#include "nsRegion.h"
|
||||
#include "nsGUIEvent.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
|
||||
#include "gfxContext.h"
|
||||
#include "gfxPlatform.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
#define DRAGIMAGES_PREF "nglayout.enable_drag_images"
|
||||
|
||||
nsBaseDragService::nsBaseDragService()
|
||||
|
@ -453,10 +455,7 @@ nsBaseDragService::DrawDrag(nsIDOMNode* aDOMNode,
|
|||
*aPresContext = presShell->GetPresContext();
|
||||
|
||||
// check if drag images are disabled
|
||||
PRBool enableDragImages = PR_TRUE;
|
||||
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
||||
if (prefs)
|
||||
prefs->GetBoolPref(DRAGIMAGES_PREF, &enableDragImages);
|
||||
PRBool enableDragImages = Preferences::GetBool(DRAGIMAGES_PREF, PR_TRUE);
|
||||
|
||||
// didn't want an image, so just set the screen rectangle to the frame size
|
||||
if (!enableDragImages || !mHasImage) {
|
||||
|
|
|
@ -47,8 +47,7 @@
|
|||
#include "nsISimpleEnumerator.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIPrefBranch2.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "BasicLayers.h"
|
||||
#include "LayerManagerOGL.h"
|
||||
#include "nsIXULRuntime.h"
|
||||
|
@ -68,6 +67,7 @@ static PRInt32 gNumWidgets;
|
|||
#endif
|
||||
|
||||
using namespace mozilla::layers;
|
||||
using namespace mozilla;
|
||||
|
||||
nsIContent* nsBaseWidget::mLastRollup = nsnull;
|
||||
|
||||
|
@ -778,10 +778,6 @@ nsBaseWidget::AutoUseBasicLayerManager::~AutoUseBasicLayerManager()
|
|||
PRBool
|
||||
nsBaseWidget::GetShouldAccelerate()
|
||||
{
|
||||
nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
|
||||
PRBool disableAcceleration = PR_FALSE;
|
||||
PRBool forceAcceleration = PR_FALSE;
|
||||
#if defined(XP_WIN) || defined(ANDROID) || (MOZ_PLATFORM_MAEMO > 5)
|
||||
PRBool accelerateByDefault = PR_TRUE;
|
||||
#elif defined(XP_MACOSX)
|
||||
|
@ -815,17 +811,13 @@ nsBaseWidget::GetShouldAccelerate()
|
|||
PRBool accelerateByDefault = PR_FALSE;
|
||||
#endif
|
||||
|
||||
if (prefs) {
|
||||
// we should use AddBoolPrefVarCache
|
||||
prefs->GetBoolPref("layers.acceleration.disabled",
|
||||
&disableAcceleration);
|
||||
|
||||
prefs->GetBoolPref("layers.acceleration.force-enabled",
|
||||
&forceAcceleration);
|
||||
|
||||
prefs->GetBoolPref("layers.acceleration.draw-fps",
|
||||
&mDrawFPS);
|
||||
}
|
||||
// we should use AddBoolPrefVarCache
|
||||
PRBool disableAcceleration =
|
||||
Preferences::GetBool("layers.acceleration.disabled", PR_FALSE);
|
||||
PRBool forceAcceleration =
|
||||
Preferences::GetBool("layers.acceleration.force-enabled", PR_FALSE);
|
||||
mDrawFPS =
|
||||
Preferences::GetBool("layers.acceleration.draw-fps", PR_FALSE);
|
||||
|
||||
const char *acceleratedEnv = PR_GetEnv("MOZ_ACCELERATED");
|
||||
accelerateByDefault = accelerateByDefault ||
|
||||
|
@ -1108,22 +1100,14 @@ nsBaseWidget::OverrideSystemMouseScrollSpeed(PRInt32 aOriginalDelta,
|
|||
{
|
||||
aOverriddenDelta = aOriginalDelta;
|
||||
|
||||
nsCOMPtr<nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
NS_ENSURE_TRUE(prefs, NS_ERROR_FAILURE);
|
||||
nsCOMPtr<nsIPrefBranch> prefBranch;
|
||||
nsresult rv = prefs->GetBranch(nsnull, getter_AddRefs(prefBranch));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ENSURE_TRUE(prefBranch, NS_ERROR_FAILURE);
|
||||
|
||||
PRBool isOverrideEnabled;
|
||||
const char* kPrefNameOverrideEnabled =
|
||||
"mousewheel.system_scroll_override_on_root_content.enabled";
|
||||
rv = prefBranch->GetBoolPref(kPrefNameOverrideEnabled, &isOverrideEnabled);
|
||||
if (NS_FAILED(rv) || !isOverrideEnabled) {
|
||||
PRBool isOverrideEnabled =
|
||||
Preferences::GetBool(kPrefNameOverrideEnabled, PR_FALSE);
|
||||
if (!isOverrideEnabled) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRInt32 iFactor;
|
||||
nsCAutoString factorPrefName(
|
||||
"mousewheel.system_scroll_override_on_root_content.");
|
||||
if (aIsHorizontal) {
|
||||
|
@ -1132,10 +1116,10 @@ nsBaseWidget::OverrideSystemMouseScrollSpeed(PRInt32 aOriginalDelta,
|
|||
factorPrefName.AppendLiteral("vertical.");
|
||||
}
|
||||
factorPrefName.AppendLiteral("factor");
|
||||
rv = prefBranch->GetIntPref(factorPrefName.get(), &iFactor);
|
||||
PRInt32 iFactor = Preferences::GetInt(factorPrefName.get(), 0);
|
||||
// The pref value must be larger than 100, otherwise, we don't override the
|
||||
// delta value.
|
||||
if (NS_FAILED(rv) || iFactor <= 100) {
|
||||
if (iFactor <= 100) {
|
||||
return NS_OK;
|
||||
}
|
||||
double factor = (double)iFactor / 100;
|
||||
|
@ -1347,32 +1331,13 @@ static PrefPair debug_PrefValues[] =
|
|||
{ "nglayout.debug.paint_flashing", PR_FALSE }
|
||||
};
|
||||
|
||||
static PRUint32 debug_NumPrefValues =
|
||||
(sizeof(debug_PrefValues) / sizeof(debug_PrefValues[0]));
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
static PRBool debug_GetBoolPref(nsIPrefBranch * aPrefs,const char * aPrefName)
|
||||
{
|
||||
NS_ASSERTION(nsnull != aPrefName,"cmon, pref name is null.");
|
||||
NS_ASSERTION(nsnull != aPrefs,"cmon, prefs are null.");
|
||||
|
||||
PRBool value = PR_FALSE;
|
||||
|
||||
if (aPrefs)
|
||||
{
|
||||
aPrefs->GetBoolPref(aPrefName,&value);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
//////////////////////////////////////////////////////////////
|
||||
PRBool
|
||||
nsBaseWidget::debug_GetCachedBoolPref(const char * aPrefName)
|
||||
{
|
||||
NS_ASSERTION(nsnull != aPrefName,"cmon, pref name is null.");
|
||||
|
||||
for (PRUint32 i = 0; i < debug_NumPrefValues; i++)
|
||||
for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(debug_PrefValues); i++)
|
||||
{
|
||||
if (strcmp(debug_PrefValues[i].name, aPrefName) == 0)
|
||||
{
|
||||
|
@ -1387,7 +1352,7 @@ static void debug_SetCachedBoolPref(const char * aPrefName,PRBool aValue)
|
|||
{
|
||||
NS_ASSERTION(nsnull != aPrefName,"cmon, pref name is null.");
|
||||
|
||||
for (PRUint32 i = 0; i < debug_NumPrefValues; i++)
|
||||
for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(debug_PrefValues); i++)
|
||||
{
|
||||
if (strcmp(debug_PrefValues[i].name, aPrefName) == 0)
|
||||
{
|
||||
|
@ -1413,13 +1378,9 @@ NS_IMETHODIMP
|
|||
Debug_PrefObserver::Observe(nsISupports* subject, const char* topic,
|
||||
const PRUnichar* data)
|
||||
{
|
||||
nsCOMPtr<nsIPrefBranch> branch(do_QueryInterface(subject));
|
||||
NS_ASSERTION(branch, "must implement nsIPrefBranch");
|
||||
|
||||
NS_ConvertUTF16toUTF8 prefName(data);
|
||||
|
||||
PRBool value = PR_FALSE;
|
||||
branch->GetBoolPref(prefName.get(), &value);
|
||||
PRBool value = Preferences::GetBool(prefName.get(), PR_FALSE);
|
||||
debug_SetCachedBoolPref(prefName.get(), value);
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -1430,28 +1391,21 @@ debug_RegisterPrefCallbacks()
|
|||
{
|
||||
static PRBool once = PR_TRUE;
|
||||
|
||||
if (once)
|
||||
{
|
||||
once = PR_FALSE;
|
||||
if (!once) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPrefBranch2> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
||||
|
||||
NS_ASSERTION(prefs, "Prefs services is null.");
|
||||
once = PR_FALSE;
|
||||
|
||||
if (prefs)
|
||||
{
|
||||
nsCOMPtr<nsIObserver> obs(new Debug_PrefObserver());
|
||||
for (PRUint32 i = 0; i < debug_NumPrefValues; i++)
|
||||
{
|
||||
// Initialize the pref values
|
||||
debug_PrefValues[i].value =
|
||||
debug_GetBoolPref(prefs,debug_PrefValues[i].name);
|
||||
nsCOMPtr<nsIObserver> obs(new Debug_PrefObserver());
|
||||
for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(debug_PrefValues); i++) {
|
||||
// Initialize the pref values
|
||||
debug_PrefValues[i].value =
|
||||
Preferences::GetBool(debug_PrefValues[i].name, PR_FALSE);
|
||||
|
||||
if (obs) {
|
||||
// Register callbacks for when these change
|
||||
prefs->AddObserver(debug_PrefValues[i].name, obs, PR_FALSE);
|
||||
}
|
||||
}
|
||||
if (obs) {
|
||||
// Register callbacks for when these change
|
||||
Preferences::AddStrongObserver(obs, debug_PrefValues[i].name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,13 +43,14 @@
|
|||
#include "nsIdleService.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsDebug.h"
|
||||
#include "nsCOMArray.h"
|
||||
#include "prinrval.h"
|
||||
#include "mozilla/Services.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
// observer topics used:
|
||||
#define OBSERVER_TOPIC_IDLE "idle"
|
||||
|
@ -102,11 +103,8 @@ nsIdleServiceDaily::Observe(nsISupports *,
|
|||
(void)mIdleService->RemoveIdleObserver(this, MAX_IDLE_POLL_INTERVAL);
|
||||
|
||||
// Set the last idle-daily time pref.
|
||||
nsCOMPtr<nsIPrefBranch> pref = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
if (pref) {
|
||||
PRInt32 nowSec = static_cast<PRInt32>(PR_Now() / PR_USEC_PER_SEC);
|
||||
(void)pref->SetIntPref(PREF_LAST_DAILY, nowSec);
|
||||
}
|
||||
PRInt32 nowSec = static_cast<PRInt32>(PR_Now() / PR_USEC_PER_SEC);
|
||||
Preferences::SetInt(PREF_LAST_DAILY, nowSec);
|
||||
|
||||
// Start timer for the next check in one day.
|
||||
(void)mTimer->InitWithFuncCallback(DailyCallback, this, SECONDS_PER_DAY * 1000,
|
||||
|
@ -127,15 +125,11 @@ nsIdleServiceDaily::Init()
|
|||
{
|
||||
// Check time of the last idle-daily notification. If it was more than 24
|
||||
// hours ago listen for idle, otherwise set a timer for 24 hours from now.
|
||||
PRInt32 lastDaily = 0;
|
||||
PRInt32 nowSec = static_cast<PRInt32>(PR_Now() / PR_USEC_PER_SEC);
|
||||
nsCOMPtr<nsIPrefBranch> pref = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
if (pref) {
|
||||
if (NS_FAILED(pref->GetIntPref(PREF_LAST_DAILY, &lastDaily)) ||
|
||||
lastDaily < 0 || lastDaily > nowSec) {
|
||||
// The time is bogus, use default.
|
||||
lastDaily = 0;
|
||||
}
|
||||
PRInt32 lastDaily = Preferences::GetInt(PREF_LAST_DAILY, 0);
|
||||
if (lastDaily < 0 || lastDaily > nowSec) {
|
||||
// The time is bogus, use default.
|
||||
lastDaily = 0;
|
||||
}
|
||||
|
||||
// Check if it has been a day since the last notification.
|
||||
|
|
|
@ -51,15 +51,14 @@
|
|||
#include "nsISupportsArray.h"
|
||||
#include "prprf.h"
|
||||
|
||||
// For Prefs
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
#include "nsIStringEnumerator.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
#include "stdlib.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "nsPrintfCString.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsPrintOptions, nsIPrintOptions, nsIPrintSettingsService)
|
||||
|
||||
|
@ -128,12 +127,7 @@ nsPrintOptions::~nsPrintOptions()
|
|||
nsresult
|
||||
nsPrintOptions::Init()
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPrefService> prefService =
|
||||
do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return prefService->GetBranch("print.", getter_AddRefs(mPrefBranch));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -246,7 +240,6 @@ nsresult
|
|||
nsPrintOptions::ReadPrefs(nsIPrintSettings* aPS, const nsAString& aPrinterName,
|
||||
PRUint32 aFlags)
|
||||
{
|
||||
NS_ENSURE_STATE(mPrefBranch);
|
||||
NS_ENSURE_ARG_POINTER(aPS);
|
||||
|
||||
if (aFlags & nsIPrintSettings::kInitSaveMargins) {
|
||||
|
@ -308,21 +301,21 @@ nsPrintOptions::ReadPrefs(nsIPrintSettings* aPS, const nsAString& aPrinterName,
|
|||
|
||||
#define GETBOOLPREF(_prefname, _retval) \
|
||||
NS_SUCCEEDED( \
|
||||
mPrefBranch->GetBoolPref( \
|
||||
Preferences::GetBool( \
|
||||
GetPrefName(_prefname, aPrinterName), _retval \
|
||||
) \
|
||||
)
|
||||
|
||||
#define GETSTRPREF(_prefname, _retval) \
|
||||
NS_SUCCEEDED( \
|
||||
ReadPrefString( \
|
||||
Preferences::GetChar( \
|
||||
GetPrefName(_prefname, aPrinterName), _retval \
|
||||
) \
|
||||
)
|
||||
|
||||
#define GETINTPREF(_prefname, _retval) \
|
||||
NS_SUCCEEDED( \
|
||||
mPrefBranch->GetIntPref( \
|
||||
Preferences::GetInt( \
|
||||
GetPrefName(_prefname, aPrinterName), _retval \
|
||||
) \
|
||||
)
|
||||
|
@ -343,7 +336,7 @@ nsPrintOptions::ReadPrefs(nsIPrintSettings* aPS, const nsAString& aPrinterName,
|
|||
&& GETINTPREF(kPrintPaperSizeType, &sizeType)
|
||||
&& GETDBLPREF(kPrintPaperWidth, width)
|
||||
&& GETDBLPREF(kPrintPaperHeight, height)
|
||||
&& GETSTRPREF(kPrintPaperName, str);
|
||||
&& GETSTRPREF(kPrintPaperName, &str);
|
||||
|
||||
// Bug 315687: Sanity check paper size to avoid paper size values in
|
||||
// mm when the size unit flag is inches. The value 100 is arbitrary
|
||||
|
@ -383,42 +376,42 @@ nsPrintOptions::ReadPrefs(nsIPrintSettings* aPS, const nsAString& aPrinterName,
|
|||
}
|
||||
|
||||
if (aFlags & nsIPrintSettings::kInitSaveHeaderLeft) {
|
||||
if (GETSTRPREF(kPrintHeaderStrLeft, str)) {
|
||||
if (GETSTRPREF(kPrintHeaderStrLeft, &str)) {
|
||||
aPS->SetHeaderStrLeft(str.get());
|
||||
DUMP_STR(kReadStr, kPrintHeaderStrLeft, str.get());
|
||||
}
|
||||
}
|
||||
|
||||
if (aFlags & nsIPrintSettings::kInitSaveHeaderCenter) {
|
||||
if (GETSTRPREF(kPrintHeaderStrCenter, str)) {
|
||||
if (GETSTRPREF(kPrintHeaderStrCenter, &str)) {
|
||||
aPS->SetHeaderStrCenter(str.get());
|
||||
DUMP_STR(kReadStr, kPrintHeaderStrCenter, str.get());
|
||||
}
|
||||
}
|
||||
|
||||
if (aFlags & nsIPrintSettings::kInitSaveHeaderRight) {
|
||||
if (GETSTRPREF(kPrintHeaderStrRight, str)) {
|
||||
if (GETSTRPREF(kPrintHeaderStrRight, &str)) {
|
||||
aPS->SetHeaderStrRight(str.get());
|
||||
DUMP_STR(kReadStr, kPrintHeaderStrRight, str.get());
|
||||
}
|
||||
}
|
||||
|
||||
if (aFlags & nsIPrintSettings::kInitSaveFooterLeft) {
|
||||
if (GETSTRPREF(kPrintFooterStrLeft, str)) {
|
||||
if (GETSTRPREF(kPrintFooterStrLeft, &str)) {
|
||||
aPS->SetFooterStrLeft(str.get());
|
||||
DUMP_STR(kReadStr, kPrintFooterStrLeft, str.get());
|
||||
}
|
||||
}
|
||||
|
||||
if (aFlags & nsIPrintSettings::kInitSaveFooterCenter) {
|
||||
if (GETSTRPREF(kPrintFooterStrCenter, str)) {
|
||||
if (GETSTRPREF(kPrintFooterStrCenter, &str)) {
|
||||
aPS->SetFooterStrCenter(str.get());
|
||||
DUMP_STR(kReadStr, kPrintFooterStrCenter, str.get());
|
||||
}
|
||||
}
|
||||
|
||||
if (aFlags & nsIPrintSettings::kInitSaveFooterRight) {
|
||||
if (GETSTRPREF(kPrintFooterStrRight, str)) {
|
||||
if (GETSTRPREF(kPrintFooterStrRight, &str)) {
|
||||
aPS->SetFooterStrRight(str.get());
|
||||
DUMP_STR(kReadStr, kPrintFooterStrRight, str.get());
|
||||
}
|
||||
|
@ -453,7 +446,7 @@ nsPrintOptions::ReadPrefs(nsIPrintSettings* aPS, const nsAString& aPrinterName,
|
|||
}
|
||||
|
||||
if (aFlags & nsIPrintSettings::kInitSavePlexName) {
|
||||
if (GETSTRPREF(kPrintPlexName, str)) {
|
||||
if (GETSTRPREF(kPrintPlexName, &str)) {
|
||||
aPS->SetPlexName(str.get());
|
||||
DUMP_STR(kReadStr, kPrintPlexName, str.get());
|
||||
}
|
||||
|
@ -467,14 +460,14 @@ nsPrintOptions::ReadPrefs(nsIPrintSettings* aPS, const nsAString& aPrinterName,
|
|||
}
|
||||
|
||||
if (aFlags & nsIPrintSettings::kInitSaveColorspace) {
|
||||
if (GETSTRPREF(kPrintColorspace, str)) {
|
||||
if (GETSTRPREF(kPrintColorspace, &str)) {
|
||||
aPS->SetColorspace(str.get());
|
||||
DUMP_STR(kReadStr, kPrintColorspace, str.get());
|
||||
}
|
||||
}
|
||||
|
||||
if (aFlags & nsIPrintSettings::kInitSaveResolutionName) {
|
||||
if (GETSTRPREF(kPrintResolutionName, str)) {
|
||||
if (GETSTRPREF(kPrintResolutionName, &str)) {
|
||||
aPS->SetResolutionName(str.get());
|
||||
DUMP_STR(kReadStr, kPrintResolutionName, str.get());
|
||||
}
|
||||
|
@ -495,7 +488,7 @@ nsPrintOptions::ReadPrefs(nsIPrintSettings* aPS, const nsAString& aPrinterName,
|
|||
}
|
||||
|
||||
if (aFlags & nsIPrintSettings::kInitSavePrintCommand) {
|
||||
if (GETSTRPREF(kPrintCommand, str)) {
|
||||
if (GETSTRPREF(kPrintCommand, &str)) {
|
||||
aPS->SetPrintCommand(str.get());
|
||||
DUMP_STR(kReadStr, kPrintCommand, str.get());
|
||||
}
|
||||
|
@ -509,7 +502,7 @@ nsPrintOptions::ReadPrefs(nsIPrintSettings* aPS, const nsAString& aPrinterName,
|
|||
}
|
||||
|
||||
if (aFlags & nsIPrintSettings::kInitSaveToFileName) {
|
||||
if (GETSTRPREF(kPrintToFileName, str)) {
|
||||
if (GETSTRPREF(kPrintToFileName, &str)) {
|
||||
aPS->SetToFileName(str.get());
|
||||
DUMP_STR(kReadStr, kPrintToFileName, str.get());
|
||||
}
|
||||
|
@ -551,7 +544,6 @@ nsPrintOptions::WritePrefs(nsIPrintSettings *aPS, const nsAString& aPrinterName,
|
|||
PRUint32 aFlags)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aPS);
|
||||
NS_ENSURE_STATE(mPrefBranch);
|
||||
|
||||
nsIntMargin margin;
|
||||
if (aFlags & nsIPrintSettings::kInitSaveMargins) {
|
||||
|
@ -621,17 +613,17 @@ nsPrintOptions::WritePrefs(nsIPrintSettings *aPS, const nsAString& aPrinterName,
|
|||
NS_SUCCEEDED(aPS->GetPaperName(&name))
|
||||
) {
|
||||
DUMP_INT(kWriteStr, kPrintPaperSizeUnit, sizeUnit);
|
||||
mPrefBranch->SetIntPref(GetPrefName(kPrintPaperSizeUnit, aPrinterName),
|
||||
PRInt32(sizeUnit));
|
||||
Preferences::SetInt(GetPrefName(kPrintPaperSizeUnit, aPrinterName),
|
||||
PRInt32(sizeUnit));
|
||||
DUMP_INT(kWriteStr, kPrintPaperSizeType, sizeType);
|
||||
mPrefBranch->SetIntPref(GetPrefName(kPrintPaperSizeType, aPrinterName),
|
||||
PRInt32(sizeType));
|
||||
Preferences::SetInt(GetPrefName(kPrintPaperSizeType, aPrinterName),
|
||||
PRInt32(sizeType));
|
||||
DUMP_DBL(kWriteStr, kPrintPaperWidth, width);
|
||||
WritePrefDouble(GetPrefName(kPrintPaperWidth, aPrinterName), width);
|
||||
DUMP_DBL(kWriteStr, kPrintPaperHeight, height);
|
||||
WritePrefDouble(GetPrefName(kPrintPaperHeight, aPrinterName), height);
|
||||
DUMP_STR(kWriteStr, kPrintPaperName, name);
|
||||
WritePrefString(name, GetPrefName(kPrintPaperName, aPrinterName));
|
||||
Preferences::SetChar(GetPrefName(kPrintPaperName, aPrinterName), name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -645,8 +637,7 @@ nsPrintOptions::WritePrefs(nsIPrintSettings *aPS, const nsAString& aPrinterName,
|
|||
if (NS_SUCCEEDED(aPS->GetPrintOptions(nsIPrintSettings::kPrintEvenPages,
|
||||
&b))) {
|
||||
DUMP_BOOL(kWriteStr, kPrintEvenPages, b);
|
||||
mPrefBranch->SetBoolPref(GetPrefName(kPrintEvenPages, aPrinterName),
|
||||
b);
|
||||
Preferences::SetBool(GetPrefName(kPrintEvenPages, aPrinterName), b);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -654,130 +645,134 @@ nsPrintOptions::WritePrefs(nsIPrintSettings *aPS, const nsAString& aPrinterName,
|
|||
if (NS_SUCCEEDED(aPS->GetPrintOptions(nsIPrintSettings::kPrintOddPages,
|
||||
&b))) {
|
||||
DUMP_BOOL(kWriteStr, kPrintOddPages, b);
|
||||
mPrefBranch->SetBoolPref(GetPrefName(kPrintOddPages, aPrinterName),
|
||||
b);
|
||||
Preferences::SetBool(GetPrefName(kPrintOddPages, aPrinterName), b);
|
||||
}
|
||||
}
|
||||
|
||||
if (aFlags & nsIPrintSettings::kInitSaveHeaderLeft) {
|
||||
if (NS_SUCCEEDED(aPS->GetHeaderStrLeft(&uStr))) {
|
||||
DUMP_STR(kWriteStr, kPrintHeaderStrLeft, uStr);
|
||||
WritePrefString(uStr, GetPrefName(kPrintHeaderStrLeft, aPrinterName));
|
||||
Preferences::SetChar(GetPrefName(kPrintHeaderStrLeft, aPrinterName),
|
||||
uStr);
|
||||
}
|
||||
}
|
||||
|
||||
if (aFlags & nsIPrintSettings::kInitSaveHeaderCenter) {
|
||||
if (NS_SUCCEEDED(aPS->GetHeaderStrCenter(&uStr))) {
|
||||
DUMP_STR(kWriteStr, kPrintHeaderStrCenter, uStr);
|
||||
WritePrefString(uStr, GetPrefName(kPrintHeaderStrCenter, aPrinterName));
|
||||
Preferences::SetChar(GetPrefName(kPrintHeaderStrCenter, aPrinterName),
|
||||
uStr);
|
||||
}
|
||||
}
|
||||
|
||||
if (aFlags & nsIPrintSettings::kInitSaveHeaderRight) {
|
||||
if (NS_SUCCEEDED(aPS->GetHeaderStrRight(&uStr))) {
|
||||
DUMP_STR(kWriteStr, kPrintHeaderStrRight, uStr);
|
||||
WritePrefString(uStr, GetPrefName(kPrintHeaderStrRight, aPrinterName));
|
||||
Preferences::SetChar(GetPrefName(kPrintHeaderStrRight, aPrinterName),
|
||||
uStr);
|
||||
}
|
||||
}
|
||||
|
||||
if (aFlags & nsIPrintSettings::kInitSaveFooterLeft) {
|
||||
if (NS_SUCCEEDED(aPS->GetFooterStrLeft(&uStr))) {
|
||||
DUMP_STR(kWriteStr, kPrintFooterStrLeft, uStr);
|
||||
WritePrefString(uStr, GetPrefName(kPrintFooterStrLeft, aPrinterName));
|
||||
Preferences::SetChar(GetPrefName(kPrintFooterStrLeft, aPrinterName),
|
||||
uStr);
|
||||
}
|
||||
}
|
||||
|
||||
if (aFlags & nsIPrintSettings::kInitSaveFooterCenter) {
|
||||
if (NS_SUCCEEDED(aPS->GetFooterStrCenter(&uStr))) {
|
||||
DUMP_STR(kWriteStr, kPrintFooterStrCenter, uStr);
|
||||
WritePrefString(uStr, GetPrefName(kPrintFooterStrCenter, aPrinterName));
|
||||
Preferences::SetChar(GetPrefName(kPrintFooterStrCenter, aPrinterName),
|
||||
uStr);
|
||||
}
|
||||
}
|
||||
|
||||
if (aFlags & nsIPrintSettings::kInitSaveFooterRight) {
|
||||
if (NS_SUCCEEDED(aPS->GetFooterStrRight(&uStr))) {
|
||||
DUMP_STR(kWriteStr, kPrintFooterStrRight, uStr);
|
||||
WritePrefString(uStr, GetPrefName(kPrintFooterStrRight, aPrinterName));
|
||||
Preferences::SetChar(GetPrefName(kPrintFooterStrRight, aPrinterName),
|
||||
uStr);
|
||||
}
|
||||
}
|
||||
|
||||
if (aFlags & nsIPrintSettings::kInitSaveBGColors) {
|
||||
if (NS_SUCCEEDED(aPS->GetPrintBGColors(&b))) {
|
||||
DUMP_BOOL(kWriteStr, kPrintBGColors, b);
|
||||
mPrefBranch->SetBoolPref(GetPrefName(kPrintBGColors, aPrinterName), b);
|
||||
Preferences::SetBool(GetPrefName(kPrintBGColors, aPrinterName), b);
|
||||
}
|
||||
}
|
||||
|
||||
if (aFlags & nsIPrintSettings::kInitSaveBGImages) {
|
||||
if (NS_SUCCEEDED(aPS->GetPrintBGImages(&b))) {
|
||||
DUMP_BOOL(kWriteStr, kPrintBGImages, b);
|
||||
mPrefBranch->SetBoolPref(GetPrefName(kPrintBGImages, aPrinterName), b);
|
||||
Preferences::SetBool(GetPrefName(kPrintBGImages, aPrinterName), b);
|
||||
}
|
||||
}
|
||||
|
||||
if (aFlags & nsIPrintSettings::kInitSaveReversed) {
|
||||
if (NS_SUCCEEDED(aPS->GetPrintReversed(&b))) {
|
||||
DUMP_BOOL(kWriteStr, kPrintReversed, b);
|
||||
mPrefBranch->SetBoolPref(GetPrefName(kPrintReversed, aPrinterName), b);
|
||||
Preferences::SetBool(GetPrefName(kPrintReversed, aPrinterName), b);
|
||||
}
|
||||
}
|
||||
|
||||
if (aFlags & nsIPrintSettings::kInitSaveInColor) {
|
||||
if (NS_SUCCEEDED(aPS->GetPrintInColor(&b))) {
|
||||
DUMP_BOOL(kWriteStr, kPrintInColor, b);
|
||||
mPrefBranch->SetBoolPref(GetPrefName(kPrintInColor, aPrinterName), b);
|
||||
Preferences::SetBool(GetPrefName(kPrintInColor, aPrinterName), b);
|
||||
}
|
||||
}
|
||||
|
||||
if (aFlags & nsIPrintSettings::kInitSavePlexName) {
|
||||
if (NS_SUCCEEDED(aPS->GetPlexName(&uStr))) {
|
||||
DUMP_STR(kWriteStr, kPrintPlexName, uStr);
|
||||
WritePrefString(uStr, GetPrefName(kPrintPlexName, aPrinterName));
|
||||
Preferences::SetChar(GetPrefName(kPrintPlexName, aPrinterName), uStr);
|
||||
}
|
||||
}
|
||||
|
||||
if (aFlags & nsIPrintSettings::kInitSavePaperData) {
|
||||
if (NS_SUCCEEDED(aPS->GetPaperData(&iVal16))) {
|
||||
DUMP_INT(kWriteStr, kPrintPaperData, iVal16);
|
||||
mPrefBranch->SetIntPref(GetPrefName(kPrintPaperData, aPrinterName),
|
||||
PRInt32(iVal16));
|
||||
Preferences::SetInt(GetPrefName(kPrintPaperData, aPrinterName),
|
||||
PRInt32(iVal16));
|
||||
}
|
||||
}
|
||||
|
||||
if (aFlags & nsIPrintSettings::kInitSaveColorspace) {
|
||||
if (NS_SUCCEEDED(aPS->GetColorspace(&uStr))) {
|
||||
DUMP_STR(kWriteStr, kPrintColorspace, uStr);
|
||||
WritePrefString(uStr, GetPrefName(kPrintColorspace, aPrinterName));
|
||||
Preferences::SetChar(GetPrefName(kPrintColorspace, aPrinterName), uStr);
|
||||
}
|
||||
}
|
||||
|
||||
if (aFlags & nsIPrintSettings::kInitSaveResolutionName) {
|
||||
if (NS_SUCCEEDED(aPS->GetResolutionName(&uStr))) {
|
||||
DUMP_STR(kWriteStr, kPrintResolutionName, uStr);
|
||||
WritePrefString(uStr, GetPrefName(kPrintResolutionName, aPrinterName));
|
||||
Preferences::SetChar(GetPrefName(kPrintResolutionName, aPrinterName),
|
||||
uStr);
|
||||
}
|
||||
}
|
||||
|
||||
if (aFlags & nsIPrintSettings::kInitSaveDownloadFonts) {
|
||||
if (NS_SUCCEEDED(aPS->GetDownloadFonts(&b))) {
|
||||
DUMP_BOOL(kWriteStr, kPrintDownloadFonts, b);
|
||||
mPrefBranch->SetBoolPref(GetPrefName(kPrintDownloadFonts, aPrinterName),
|
||||
b);
|
||||
Preferences::SetBool(GetPrefName(kPrintDownloadFonts, aPrinterName), b);
|
||||
}
|
||||
}
|
||||
|
||||
if (aFlags & nsIPrintSettings::kInitSaveOrientation) {
|
||||
if (NS_SUCCEEDED(aPS->GetOrientation(&iVal))) {
|
||||
DUMP_INT(kWriteStr, kPrintOrientation, iVal);
|
||||
mPrefBranch->SetIntPref(GetPrefName(kPrintOrientation, aPrinterName),
|
||||
iVal);
|
||||
Preferences::SetInt(GetPrefName(kPrintOrientation, aPrinterName), iVal);
|
||||
}
|
||||
}
|
||||
|
||||
if (aFlags & nsIPrintSettings::kInitSavePrintCommand) {
|
||||
if (NS_SUCCEEDED(aPS->GetPrintCommand(&uStr))) {
|
||||
DUMP_STR(kWriteStr, kPrintCommand, uStr);
|
||||
WritePrefString(uStr, GetPrefName(kPrintCommand, aPrinterName));
|
||||
Preferences::SetChar(GetPrefName(kPrintCommand, aPrinterName), uStr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -786,35 +781,35 @@ nsPrintOptions::WritePrefs(nsIPrintSettings *aPS, const nsAString& aPrinterName,
|
|||
&& aPrinterName.IsEmpty()) {
|
||||
if (NS_SUCCEEDED(aPS->GetPrinterName(&uStr))) {
|
||||
DUMP_STR(kWriteStr, kPrinterName, uStr);
|
||||
WritePrefString(uStr, kPrinterName);
|
||||
Preferences::SetChar(kPrinterName, uStr);
|
||||
}
|
||||
}
|
||||
|
||||
if (aFlags & nsIPrintSettings::kInitSavePrintToFile) {
|
||||
if (NS_SUCCEEDED(aPS->GetPrintToFile(&b))) {
|
||||
DUMP_BOOL(kWriteStr, kPrintToFile, b);
|
||||
mPrefBranch->SetBoolPref(GetPrefName(kPrintToFile, aPrinterName), b);
|
||||
Preferences::SetBool(GetPrefName(kPrintToFile, aPrinterName), b);
|
||||
}
|
||||
}
|
||||
|
||||
if (aFlags & nsIPrintSettings::kInitSaveToFileName) {
|
||||
if (NS_SUCCEEDED(aPS->GetToFileName(&uStr))) {
|
||||
DUMP_STR(kWriteStr, kPrintToFileName, uStr);
|
||||
WritePrefString(uStr, GetPrefName(kPrintToFileName, aPrinterName));
|
||||
Preferences::SetChar(GetPrefName(kPrintToFileName, aPrinterName), uStr);
|
||||
}
|
||||
}
|
||||
|
||||
if (aFlags & nsIPrintSettings::kInitSavePageDelay) {
|
||||
if (NS_SUCCEEDED(aPS->GetPrintPageDelay(&iVal))) {
|
||||
DUMP_INT(kWriteStr, kPrintPageDelay, iVal);
|
||||
mPrefBranch->SetIntPref(GetPrefName(kPrintPageDelay, aPrinterName), iVal);
|
||||
Preferences::SetInt(GetPrefName(kPrintPageDelay, aPrinterName), iVal);
|
||||
}
|
||||
}
|
||||
|
||||
if (aFlags & nsIPrintSettings::kInitSaveShrinkToFit) {
|
||||
if (NS_SUCCEEDED(aPS->GetShrinkToFit(&b))) {
|
||||
DUMP_BOOL(kWriteStr, kPrintShrinkToFit, b);
|
||||
mPrefBranch->SetBoolPref(GetPrefName(kPrintShrinkToFit, aPrinterName), b);
|
||||
Preferences::SetBool(GetPrefName(kPrintShrinkToFit, aPrinterName), b);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -911,7 +906,7 @@ nsPrintOptions::GetDefaultPrinterName(PRUnichar * *aDefaultPrinterName)
|
|||
|
||||
// Look up the printer from the last print job
|
||||
nsAutoString lastPrinterName;
|
||||
ReadPrefString(kPrinterName, lastPrinterName);
|
||||
Preferences::GetChar(kPrinterName, &lastPrinterName);
|
||||
if (!lastPrinterName.IsEmpty()) {
|
||||
// Verify it's still a valid printer
|
||||
nsCOMPtr<nsIStringEnumerator> printers;
|
||||
|
@ -1014,7 +1009,6 @@ NS_IMETHODIMP
|
|||
nsPrintOptions::GetPrinterPrefInt(nsIPrintSettings *aPrintSettings,
|
||||
const PRUnichar *aPrefName, PRInt32 *_retval)
|
||||
{
|
||||
NS_ENSURE_STATE(mPrefBranch);
|
||||
NS_ENSURE_ARG_POINTER(aPrintSettings);
|
||||
NS_ENSURE_ARG_POINTER(aPrefName);
|
||||
|
||||
|
@ -1029,7 +1023,7 @@ nsPrintOptions::GetPrinterPrefInt(nsIPrintSettings *aPrintSettings,
|
|||
NS_ENSURE_TRUE(prefName, NS_ERROR_FAILURE);
|
||||
|
||||
PRInt32 iVal;
|
||||
nsresult rv = mPrefBranch->GetIntPref(prefName, &iVal);
|
||||
nsresult rv = Preferences::GetInt(prefName, &iVal);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
*_retval = iVal;
|
||||
|
@ -1096,57 +1090,15 @@ nsPrintOptions::SavePrintSettingsToPrefs(nsIPrintSettings *aPS,
|
|||
//-----------------------------------------------------
|
||||
//-- Protected Methods --------------------------------
|
||||
//-----------------------------------------------------
|
||||
nsresult
|
||||
nsPrintOptions::ReadPrefString(const char * aPrefId, nsAString& aString)
|
||||
{
|
||||
NS_ENSURE_STATE(mPrefBranch);
|
||||
NS_ENSURE_ARG_POINTER(aPrefId);
|
||||
|
||||
nsXPIDLCString str;
|
||||
nsresult rv = mPrefBranch->GetCharPref(aPrefId, getter_Copies(str));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
CopyUTF8toUTF16(str.get(), aString);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsPrintOptions::WritePrefString(PRUnichar*& aStr, const char* aPrefId)
|
||||
{
|
||||
NS_ENSURE_STATE(mPrefBranch);
|
||||
NS_ENSURE_ARG_POINTER(aStr);
|
||||
NS_ENSURE_ARG_POINTER(aPrefId);
|
||||
|
||||
nsresult rv = mPrefBranch->SetCharPref(aPrefId,
|
||||
NS_ConvertUTF16toUTF8(aStr).get());
|
||||
|
||||
nsMemory::Free(aStr);
|
||||
aStr = nsnull;
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsPrintOptions::WritePrefString(const char * aPrefId, const nsAString& aString)
|
||||
{
|
||||
NS_ENSURE_STATE(mPrefBranch);
|
||||
NS_ENSURE_ARG_POINTER(aPrefId);
|
||||
|
||||
return mPrefBranch->SetCharPref(aPrefId,
|
||||
NS_ConvertUTF16toUTF8(aString).get());
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsPrintOptions::ReadPrefDouble(const char * aPrefId, double& aVal)
|
||||
{
|
||||
NS_ENSURE_STATE(mPrefBranch);
|
||||
NS_ENSURE_ARG_POINTER(aPrefId);
|
||||
|
||||
char * str;
|
||||
nsresult rv = mPrefBranch->GetCharPref(aPrefId, &str);
|
||||
if (NS_SUCCEEDED(rv) && str) {
|
||||
aVal = atof(str);
|
||||
nsMemory::Free(str);
|
||||
nsCAutoString str;
|
||||
nsresult rv = Preferences::GetChar(aPrefId, &str);
|
||||
if (NS_SUCCEEDED(rv) && !str.IsEmpty()) {
|
||||
aVal = atof(str.get());
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
@ -1154,29 +1106,24 @@ nsPrintOptions::ReadPrefDouble(const char * aPrefId, double& aVal)
|
|||
nsresult
|
||||
nsPrintOptions::WritePrefDouble(const char * aPrefId, double aVal)
|
||||
{
|
||||
NS_ENSURE_STATE(mPrefBranch);
|
||||
NS_ENSURE_ARG_POINTER(aPrefId);
|
||||
|
||||
char str[16]; // max 9 chars in below snprintf(), 16 will do nicely
|
||||
int ret = PR_snprintf(str, sizeof(str), "%6.2f", aVal);
|
||||
NS_ENSURE_TRUE(ret >= 0, NS_ERROR_FAILURE);
|
||||
nsPrintfCString str("%6.2f", aVal);
|
||||
NS_ENSURE_TRUE(!str.IsEmpty(), NS_ERROR_FAILURE);
|
||||
|
||||
return mPrefBranch->SetCharPref(aPrefId, str);
|
||||
return Preferences::SetChar(aPrefId, str);
|
||||
}
|
||||
|
||||
void
|
||||
nsPrintOptions::ReadInchesToTwipsPref(const char * aPrefId, PRInt32& aTwips,
|
||||
const char * aMarginPref)
|
||||
{
|
||||
if (!mPrefBranch) {
|
||||
return;
|
||||
nsCAutoString str;
|
||||
nsresult rv = Preferences::GetChar(aPrefId, &str);
|
||||
if (NS_FAILED(rv) || str.IsEmpty()) {
|
||||
rv = Preferences::GetChar(aMarginPref, &str);
|
||||
}
|
||||
|
||||
char * str = nsnull;
|
||||
nsresult rv = mPrefBranch->GetCharPref(aPrefId, &str);
|
||||
if (NS_FAILED(rv) || !str)
|
||||
rv = mPrefBranch->GetCharPref(aMarginPref, &str);
|
||||
if (NS_SUCCEEDED(rv) && str) {
|
||||
if (NS_SUCCEEDED(rv) && !str.IsEmpty()) {
|
||||
nsAutoString justStr;
|
||||
justStr.AssignWithConversion(str);
|
||||
PRInt32 errCode;
|
||||
|
@ -1186,36 +1133,27 @@ nsPrintOptions::ReadInchesToTwipsPref(const char * aPrefId, PRInt32& aTwips,
|
|||
} else {
|
||||
aTwips = 0;
|
||||
}
|
||||
nsMemory::Free(str);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsPrintOptions::WriteInchesFromTwipsPref(const char * aPrefId, PRInt32 aTwips)
|
||||
{
|
||||
if (!mPrefBranch) {
|
||||
return;
|
||||
}
|
||||
|
||||
double inches = NS_TWIPS_TO_INCHES(aTwips);
|
||||
nsCAutoString inchesStr;
|
||||
inchesStr.AppendFloat(inches);
|
||||
|
||||
mPrefBranch->SetCharPref(aPrefId, inchesStr.get());
|
||||
Preferences::SetChar(aPrefId, inchesStr);
|
||||
}
|
||||
|
||||
void
|
||||
nsPrintOptions::ReadInchesIntToTwipsPref(const char * aPrefId, PRInt32& aTwips,
|
||||
const char * aMarginPref)
|
||||
{
|
||||
if (!mPrefBranch) {
|
||||
return;
|
||||
}
|
||||
|
||||
PRInt32 value;
|
||||
nsresult rv = mPrefBranch->GetIntPref(aPrefId, &value);
|
||||
nsresult rv = Preferences::GetInt(aPrefId, &value);
|
||||
if (NS_FAILED(rv)) {
|
||||
rv = mPrefBranch->GetIntPref(aMarginPref, &value);
|
||||
rv = Preferences::GetInt(aMarginPref, &value);
|
||||
}
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
aTwips = NS_INCHES_TO_INT_TWIPS(float(value)/100.0f);
|
||||
|
@ -1227,11 +1165,8 @@ nsPrintOptions::ReadInchesIntToTwipsPref(const char * aPrefId, PRInt32& aTwips,
|
|||
void
|
||||
nsPrintOptions::WriteInchesIntFromTwipsPref(const char * aPrefId, PRInt32 aTwips)
|
||||
{
|
||||
if (!mPrefBranch) {
|
||||
return;
|
||||
}
|
||||
|
||||
mPrefBranch->SetIntPref(aPrefId, PRInt32(NS_TWIPS_TO_INCHES(aTwips)*100.0f + 0.5f));
|
||||
Preferences::SetInt(aPrefId,
|
||||
PRInt32(NS_TWIPS_TO_INCHES(aTwips) * 100.0f + 0.5f));
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1240,13 +1175,11 @@ nsPrintOptions::ReadJustification(const char * aPrefId, PRInt16& aJust,
|
|||
{
|
||||
aJust = aInitValue;
|
||||
nsAutoString justStr;
|
||||
if (NS_SUCCEEDED(ReadPrefString(aPrefId, justStr))) {
|
||||
if (NS_SUCCEEDED(Preferences::GetChar(aPrefId, &justStr))) {
|
||||
if (justStr.EqualsASCII(kJustRight)) {
|
||||
aJust = nsIPrintSettings::kJustRight;
|
||||
|
||||
} else if (justStr.EqualsASCII(kJustCenter)) {
|
||||
aJust = nsIPrintSettings::kJustCenter;
|
||||
|
||||
} else {
|
||||
aJust = nsIPrintSettings::kJustLeft;
|
||||
}
|
||||
|
@ -1259,15 +1192,15 @@ nsPrintOptions::WriteJustification(const char * aPrefId, PRInt16 aJust)
|
|||
{
|
||||
switch (aJust) {
|
||||
case nsIPrintSettings::kJustLeft:
|
||||
mPrefBranch->SetCharPref(aPrefId, kJustLeft);
|
||||
Preferences::SetChar(aPrefId, kJustLeft);
|
||||
break;
|
||||
|
||||
case nsIPrintSettings::kJustCenter:
|
||||
mPrefBranch->SetCharPref(aPrefId, kJustCenter);
|
||||
Preferences::SetChar(aPrefId, kJustCenter);
|
||||
break;
|
||||
|
||||
case nsIPrintSettings::kJustRight:
|
||||
mPrefBranch->SetCharPref(aPrefId, kJustRight);
|
||||
Preferences::SetChar(aPrefId, kJustRight);
|
||||
break;
|
||||
} //switch
|
||||
}
|
||||
|
|
|
@ -44,7 +44,6 @@
|
|||
#include "nsCOMPtr.h"
|
||||
#include "nsIPrintOptions.h"
|
||||
#include "nsIPrintSettingsService.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsString.h"
|
||||
#include "nsFont.h"
|
||||
|
||||
|
@ -83,13 +82,6 @@ protected:
|
|||
const char * aMarginPref);
|
||||
void WriteInchesIntFromTwipsPref(const char * aPrefId, PRInt32 aTwips);
|
||||
|
||||
nsresult ReadPrefString(const char * aPrefId, nsAString& aString);
|
||||
/**
|
||||
* method WritePrefString
|
||||
* Writes PRUnichar* to Prefs and deletes the contents of aString
|
||||
*/
|
||||
nsresult WritePrefString(const char * aPrefId, const nsAString& aString);
|
||||
nsresult WritePrefString(PRUnichar*& aStr, const char* aPrefId);
|
||||
nsresult ReadPrefDouble(const char * aPrefId, double& aVal);
|
||||
nsresult WritePrefDouble(const char * aPrefId, double aVal);
|
||||
|
||||
|
@ -125,8 +117,6 @@ protected:
|
|||
|
||||
nsCString mPrefName;
|
||||
|
||||
nsCOMPtr<nsIPrefBranch> mPrefBranch;
|
||||
|
||||
private:
|
||||
// These are not supported and are not implemented!
|
||||
nsPrintOptions(const nsPrintOptions& x);
|
||||
|
|
|
@ -38,13 +38,9 @@
|
|||
#include "nscore.h"
|
||||
|
||||
#include "nsXPLookAndFeel.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIPrefBranch2.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsFont.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
|
||||
#include "gfxPlatform.h"
|
||||
#include "qcms.h"
|
||||
|
@ -53,6 +49,8 @@
|
|||
#include "nsSize.h"
|
||||
#endif
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsXPLookAndFeel, nsILookAndFeel, nsIObserver)
|
||||
|
||||
nsLookAndFeelIntPref nsXPLookAndFeel::sIntPrefs[] =
|
||||
|
@ -222,124 +220,113 @@ nsXPLookAndFeel::nsXPLookAndFeel() : nsILookAndFeel()
|
|||
void
|
||||
nsXPLookAndFeel::IntPrefChanged (nsLookAndFeelIntPref *data)
|
||||
{
|
||||
if (data)
|
||||
{
|
||||
nsCOMPtr<nsIPrefBranch> prefService(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
||||
if (prefService)
|
||||
{
|
||||
PRInt32 intpref;
|
||||
nsresult rv = prefService->GetIntPref(data->name, &intpref);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
data->intVar = intpref;
|
||||
data->isSet = PR_TRUE;
|
||||
#ifdef DEBUG_akkana
|
||||
printf("====== Changed int pref %s to %d\n", data->name, data->intVar);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
|
||||
PRInt32 intpref;
|
||||
nsresult rv = Preferences::GetInt(data->name, &intpref);
|
||||
if (NS_FAILED(rv)) {
|
||||
return;
|
||||
}
|
||||
data->intVar = intpref;
|
||||
data->isSet = PR_TRUE;
|
||||
#ifdef DEBUG_akkana
|
||||
printf("====== Changed int pref %s to %d\n", data->name, data->intVar);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
nsXPLookAndFeel::FloatPrefChanged (nsLookAndFeelFloatPref *data)
|
||||
{
|
||||
if (data)
|
||||
{
|
||||
nsCOMPtr<nsIPrefBranch> prefService(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
||||
if (prefService)
|
||||
{
|
||||
PRInt32 intpref;
|
||||
nsresult rv = prefService->GetIntPref(data->name, &intpref);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
data->floatVar = (float)intpref / 100.;
|
||||
data->isSet = PR_TRUE;
|
||||
#ifdef DEBUG_akkana
|
||||
printf("====== Changed float pref %s to %f\n", data->name, data->floatVar);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
|
||||
PRInt32 intpref;
|
||||
nsresult rv = Preferences::GetInt(data->name, &intpref);
|
||||
if (NS_FAILED(rv)) {
|
||||
return;
|
||||
}
|
||||
data->floatVar = (float)intpref / 100.;
|
||||
data->isSet = PR_TRUE;
|
||||
#ifdef DEBUG_akkana
|
||||
printf("====== Changed float pref %s to %f\n", data->name, data->floatVar);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
nsXPLookAndFeel::ColorPrefChanged (unsigned int index, const char *prefName)
|
||||
{
|
||||
nsCOMPtr<nsIPrefBranch> prefService(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
||||
if (prefService) {
|
||||
nsXPIDLCString colorStr;
|
||||
nsresult rv = prefService->GetCharPref(prefName, getter_Copies(colorStr));
|
||||
if (NS_SUCCEEDED(rv) && !colorStr.IsEmpty()) {
|
||||
nscolor thecolor;
|
||||
if (colorStr[0] == '#') {
|
||||
if (NS_HexToRGB(NS_ConvertASCIItoUTF16(Substring(colorStr, 1, colorStr.Length() - 1)),
|
||||
&thecolor)) {
|
||||
PRInt32 id = NS_PTR_TO_INT32(index);
|
||||
CACHE_COLOR(id, thecolor);
|
||||
}
|
||||
}
|
||||
else if (NS_ColorNameToRGB(NS_ConvertASCIItoUTF16(colorStr), &thecolor)) {
|
||||
nsAutoString colorStr;
|
||||
nsresult rv = Preferences::GetChar(prefName, &colorStr);
|
||||
if (NS_FAILED(rv)) {
|
||||
return;
|
||||
}
|
||||
if (!colorStr.IsEmpty()) {
|
||||
nscolor thecolor;
|
||||
if (colorStr[0] == PRUnichar('#')) {
|
||||
if (NS_HexToRGB(nsDependentString(
|
||||
Substring(colorStr, 1, colorStr.Length() - 1)),
|
||||
&thecolor)) {
|
||||
PRInt32 id = NS_PTR_TO_INT32(index);
|
||||
CACHE_COLOR(id, thecolor);
|
||||
#ifdef DEBUG_akkana
|
||||
printf("====== Changed color pref %s to 0x%lx\n",
|
||||
prefName, thecolor);
|
||||
#endif
|
||||
}
|
||||
} else if (colorStr.IsEmpty()) {
|
||||
// Reset to the default color, by clearing the cache
|
||||
// to force lookup when the color is next used
|
||||
} else if (NS_ColorNameToRGB(colorStr, &thecolor)) {
|
||||
PRInt32 id = NS_PTR_TO_INT32(index);
|
||||
CLEAR_COLOR_CACHE(id);
|
||||
CACHE_COLOR(id, thecolor);
|
||||
#ifdef DEBUG_akkana
|
||||
printf("====== Changed color pref %s to 0x%lx\n",
|
||||
prefName, thecolor);
|
||||
#endif
|
||||
}
|
||||
} else {
|
||||
// Reset to the default color, by clearing the cache
|
||||
// to force lookup when the color is next used
|
||||
PRInt32 id = NS_PTR_TO_INT32(index);
|
||||
CLEAR_COLOR_CACHE(id);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsXPLookAndFeel::InitFromPref(nsLookAndFeelIntPref* aPref, nsIPrefBranch* aPrefBranch)
|
||||
nsXPLookAndFeel::InitFromPref(nsLookAndFeelIntPref* aPref)
|
||||
{
|
||||
PRInt32 intpref;
|
||||
nsresult rv = aPrefBranch->GetIntPref(aPref->name, &intpref);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsresult rv = Preferences::GetInt(aPref->name, &intpref);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
aPref->isSet = PR_TRUE;
|
||||
aPref->intVar = intpref;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsXPLookAndFeel::InitFromPref(nsLookAndFeelFloatPref* aPref, nsIPrefBranch* aPrefBranch)
|
||||
nsXPLookAndFeel::InitFromPref(nsLookAndFeelFloatPref* aPref)
|
||||
{
|
||||
PRInt32 intpref;
|
||||
nsresult rv = aPrefBranch->GetIntPref(aPref->name, &intpref);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsresult rv = Preferences::GetInt(aPref->name, &intpref);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
aPref->isSet = PR_TRUE;
|
||||
aPref->floatVar = (float)intpref / 100.;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsXPLookAndFeel::InitColorFromPref(PRInt32 i, nsIPrefBranch* aPrefBranch)
|
||||
nsXPLookAndFeel::InitColorFromPref(PRInt32 i)
|
||||
{
|
||||
nsXPIDLCString colorStr;
|
||||
nsresult rv = aPrefBranch->GetCharPref(sColorPrefs[i], getter_Copies(colorStr));
|
||||
if (NS_SUCCEEDED(rv) && !colorStr.IsEmpty())
|
||||
{
|
||||
nsAutoString colorNSStr; colorNSStr.AssignWithConversion(colorStr);
|
||||
nscolor thecolor;
|
||||
if (colorNSStr[0] == '#') {
|
||||
nsAutoString hexString;
|
||||
colorNSStr.Right(hexString, colorNSStr.Length() - 1);
|
||||
if (NS_HexToRGB(hexString, &thecolor)) {
|
||||
CACHE_COLOR(i, thecolor);
|
||||
}
|
||||
}
|
||||
else if (NS_ColorNameToRGB(colorNSStr, &thecolor))
|
||||
{
|
||||
nsAutoString colorStr;
|
||||
nsresult rv = Preferences::GetChar(sColorPrefs[i], &colorStr);
|
||||
if (NS_FAILED(rv) || colorStr.IsEmpty()) {
|
||||
return;
|
||||
}
|
||||
nscolor thecolor;
|
||||
if (colorStr[0] == PRUnichar('#')) {
|
||||
nsAutoString hexString;
|
||||
colorStr.Right(hexString, colorStr.Length() - 1);
|
||||
if (NS_HexToRGB(hexString, &thecolor)) {
|
||||
CACHE_COLOR(i, thecolor);
|
||||
}
|
||||
} else if (NS_ColorNameToRGB(colorStr, &thecolor)) {
|
||||
CACHE_COLOR(i, thecolor);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -389,31 +376,24 @@ nsXPLookAndFeel::Init()
|
|||
// protects against some other process writing to our static variables.
|
||||
sInitialized = PR_TRUE;
|
||||
|
||||
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
||||
if (!prefs)
|
||||
return;
|
||||
nsCOMPtr<nsIPrefBranch2> prefBranchInternal(do_QueryInterface(prefs));
|
||||
if (!prefBranchInternal)
|
||||
return;
|
||||
|
||||
unsigned int i;
|
||||
for (i = 0; i < NS_ARRAY_LENGTH(sIntPrefs); ++i) {
|
||||
InitFromPref(&sIntPrefs[i], prefs);
|
||||
prefBranchInternal->AddObserver(sIntPrefs[i].name, this, PR_FALSE);
|
||||
InitFromPref(&sIntPrefs[i]);
|
||||
Preferences::AddStrongObserver(this, sIntPrefs[i].name);
|
||||
}
|
||||
|
||||
for (i = 0; i < NS_ARRAY_LENGTH(sFloatPrefs); ++i) {
|
||||
InitFromPref(&sFloatPrefs[i], prefs);
|
||||
prefBranchInternal->AddObserver(sFloatPrefs[i].name, this, PR_FALSE);
|
||||
InitFromPref(&sFloatPrefs[i]);
|
||||
Preferences::AddStrongObserver(this, sFloatPrefs[i].name);
|
||||
}
|
||||
|
||||
for (i = 0; i < NS_ARRAY_LENGTH(sColorPrefs); ++i) {
|
||||
InitColorFromPref(i, prefs);
|
||||
prefBranchInternal->AddObserver(sColorPrefs[i], this, PR_FALSE);
|
||||
InitColorFromPref(i);
|
||||
Preferences::AddStrongObserver(this, sColorPrefs[i]);
|
||||
}
|
||||
|
||||
PRBool val;
|
||||
if (NS_SUCCEEDED(prefs->GetBoolPref("ui.use_native_colors", &val))) {
|
||||
if (NS_SUCCEEDED(Preferences::GetBool("ui.use_native_colors", &val))) {
|
||||
sUseNativeColors = val;
|
||||
}
|
||||
}
|
||||
|
@ -625,12 +605,12 @@ nsXPLookAndFeel::GetMetric(const nsMetricID aID, PRInt32& aMetric)
|
|||
break;
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < ((sizeof (sIntPrefs) / sizeof (*sIntPrefs))); ++i)
|
||||
if (sIntPrefs[i].isSet && (sIntPrefs[i].id == aID))
|
||||
{
|
||||
for (unsigned int i = 0; i < NS_ARRAY_LENGTH(sIntPrefs); ++i) {
|
||||
if (sIntPrefs[i].isSet && (sIntPrefs[i].id == aID)) {
|
||||
aMetric = sIntPrefs[i].intVar;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
@ -641,12 +621,12 @@ nsXPLookAndFeel::GetMetric(const nsMetricFloatID aID, float& aMetric)
|
|||
if (!sInitialized)
|
||||
Init();
|
||||
|
||||
for (unsigned int i = 0; i < ((sizeof (sFloatPrefs) / sizeof (*sFloatPrefs))); ++i)
|
||||
if (sFloatPrefs[i].isSet && sFloatPrefs[i].id == aID)
|
||||
{
|
||||
for (unsigned int i = 0; i < NS_ARRAY_LENGTH(sFloatPrefs); ++i) {
|
||||
if (sFloatPrefs[i].isSet && sFloatPrefs[i].id == aID) {
|
||||
aMetric = sFloatPrefs[i].floatVar;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
|
|
@ -41,7 +41,6 @@
|
|||
#include "nsILookAndFeel.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
struct nsSize;
|
||||
|
@ -116,9 +115,9 @@ protected:
|
|||
void IntPrefChanged(nsLookAndFeelIntPref *data);
|
||||
void FloatPrefChanged(nsLookAndFeelFloatPref *data);
|
||||
void ColorPrefChanged(unsigned int index, const char *prefName);
|
||||
void InitFromPref(nsLookAndFeelIntPref* aPref, nsIPrefBranch* aPrefBranch);
|
||||
void InitFromPref(nsLookAndFeelFloatPref* aPref, nsIPrefBranch* aPrefBranch);
|
||||
void InitColorFromPref(PRInt32 aIndex, nsIPrefBranch* aPrefBranch);
|
||||
void InitFromPref(nsLookAndFeelIntPref* aPref);
|
||||
void InitFromPref(nsLookAndFeelFloatPref* aPref);
|
||||
void InitColorFromPref(PRInt32 aIndex);
|
||||
virtual nsresult NativeGetColor(const nsColorID aID, nscolor& aColor) = 0;
|
||||
PRBool IsSpecialColor(const nsColorID aID, nscolor &aColor);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче