2006-05-17 02:30:56 +00:00
|
|
|
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
2006-05-17 02:30:08 +00:00
|
|
|
*
|
2006-05-17 02:30:56 +00:00
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.1 (the "License"); you may not use this file except in
|
|
|
|
* compliance with the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/NPL/
|
2006-05-17 02:30:08 +00:00
|
|
|
*
|
2006-05-17 02:30:56 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
2006-05-17 02:30:08 +00:00
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2006-05-17 02:30:56 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2006-05-17 02:30:08 +00:00
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Gervase Markham <gerv@gerv.net>
|
2006-05-17 02:30:59 +00:00
|
|
|
* Tuukka Tolvanen <tt@lament.cjb.net>
|
2006-05-17 02:30:56 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2006-05-17 02:30:08 +00:00
|
|
|
|
2006-05-17 02:28:51 +00:00
|
|
|
try
|
2006-05-17 02:24:52 +00:00
|
|
|
{
|
2006-05-17 02:28:57 +00:00
|
|
|
var fontList = Components.classes["@mozilla.org/gfx/fontlist;1"].createInstance();
|
|
|
|
if (fontList)
|
|
|
|
fontList = fontList.QueryInterface(Components.interfaces.nsIFontList);
|
2006-05-17 02:24:52 +00:00
|
|
|
|
2006-05-17 02:27:37 +00:00
|
|
|
var pref = Components.classes["@mozilla.org/preferences;1"].getService( Components.interfaces.nsIPref );
|
2006-05-17 02:24:52 +00:00
|
|
|
}
|
2006-05-17 02:28:51 +00:00
|
|
|
catch(e)
|
2006-05-17 02:24:52 +00:00
|
|
|
{
|
2006-05-17 02:30:08 +00:00
|
|
|
dump("failed to get font list or pref object: "+e+" in pref-fonts.js\n");
|
2006-05-17 02:23:53 +00:00
|
|
|
}
|
|
|
|
|
2006-05-17 02:30:08 +00:00
|
|
|
var fontTypes = ["serif", "sans-serif", "cursive", "fantasy", "monospace"];
|
2006-05-17 02:32:12 +00:00
|
|
|
var variableSize, fixedSize, minSize, languageList;
|
2006-05-17 02:24:52 +00:00
|
|
|
var languageData = [];
|
|
|
|
var currentLanguage;
|
2006-05-17 02:28:44 +00:00
|
|
|
var gPrefutilitiesBundle;
|
2006-05-17 02:22:17 +00:00
|
|
|
|
2006-05-17 02:24:52 +00:00
|
|
|
// manual data retrieval function for PrefWindow
|
|
|
|
function GetFields()
|
|
|
|
{
|
2006-05-17 02:30:44 +00:00
|
|
|
var dataObject = parent.hPrefWindow.wsm.dataManager.pageData["chrome://communicator/content/pref/pref-fonts.xul"];
|
2006-05-17 02:28:51 +00:00
|
|
|
|
2006-05-17 02:24:52 +00:00
|
|
|
// store data for language independent widgets
|
2006-05-17 02:30:08 +00:00
|
|
|
var lists = ["selectLangs", "proportionalFont"];
|
2006-05-17 02:24:52 +00:00
|
|
|
for( var i = 0; i < lists.length; i++ )
|
|
|
|
{
|
2006-05-17 02:32:14 +00:00
|
|
|
if( !( "dataEls" in dataObject ) )
|
2006-05-17 02:24:52 +00:00
|
|
|
dataObject.dataEls = [];
|
|
|
|
dataObject.dataEls[ lists[i] ] = [];
|
2006-05-17 02:28:51 +00:00
|
|
|
dataObject.dataEls[ lists[i] ].value = document.getElementById( lists[i] ).value;
|
2006-05-17 02:24:52 +00:00
|
|
|
}
|
2006-05-17 02:28:51 +00:00
|
|
|
|
2006-05-17 02:30:08 +00:00
|
|
|
dataObject.defaultFont = document.getElementById( "proportionalFont" ).value;
|
|
|
|
dataObject.fontDPI = document.getElementById( "screenResolution" ).value;
|
|
|
|
dataObject.useDocFonts = document.getElementById( "browserUseDocumentFonts" ).checked ? 1 : 0;
|
2006-05-17 02:24:52 +00:00
|
|
|
|
|
|
|
// save current state for language dependent fields and store
|
|
|
|
saveState();
|
|
|
|
dataObject.languageData = languageData;
|
2006-05-17 02:28:51 +00:00
|
|
|
|
|
|
|
return dataObject;
|
2006-05-17 02:24:52 +00:00
|
|
|
}
|
2006-05-17 02:24:16 +00:00
|
|
|
|
2006-05-17 02:28:51 +00:00
|
|
|
// manual data setting function for PrefWindow
|
2006-05-17 02:24:52 +00:00
|
|
|
function SetFields( aDataObject )
|
|
|
|
{
|
2006-05-17 02:32:14 +00:00
|
|
|
languageData = "languageData" in aDataObject ? aDataObject.languageData : languageData ;
|
|
|
|
currentLanguage = "currentLanguage" in aDataObject ? aDataObject.currentLanguage : null ;
|
2006-05-17 02:24:52 +00:00
|
|
|
|
2006-05-17 02:30:08 +00:00
|
|
|
var lists = ["selectLangs", "proportionalFont"];
|
|
|
|
var prefvalue;
|
|
|
|
|
2006-05-17 02:24:52 +00:00
|
|
|
for( var i = 0; i < lists.length; i++ )
|
|
|
|
{
|
|
|
|
var element = document.getElementById( lists[i] );
|
2006-05-17 02:32:14 +00:00
|
|
|
if( "dataEls" in aDataObject )
|
2006-05-17 02:24:52 +00:00
|
|
|
{
|
2006-05-17 02:28:51 +00:00
|
|
|
element.selectedItem = element.getElementsByAttribute( "value", aDataObject.dataEls[ lists[i] ].value )[0];
|
2006-05-17 02:24:52 +00:00
|
|
|
}
|
2006-05-17 02:28:51 +00:00
|
|
|
else
|
2006-05-17 02:24:52 +00:00
|
|
|
{
|
|
|
|
var prefstring = element.getAttribute( "prefstring" );
|
|
|
|
var preftype = element.getAttribute( "preftype" );
|
|
|
|
if( prefstring && preftype )
|
|
|
|
{
|
2006-05-17 02:32:14 +00:00
|
|
|
prefvalue = parent.hPrefWindow.getPref( preftype, prefstring );
|
2006-05-17 02:28:51 +00:00
|
|
|
element.selectedItem = element.getElementsByAttribute( "value", prefvalue )[0];
|
2006-05-17 02:24:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-17 02:30:08 +00:00
|
|
|
var screenResolution = document.getElementById( "screenResolution" );
|
|
|
|
var resolution;
|
|
|
|
|
2006-05-17 02:32:14 +00:00
|
|
|
if( "fontDPI" in aDataObject )
|
2006-05-17 02:30:08 +00:00
|
|
|
{
|
|
|
|
resolution = aDataObject.fontDPI;
|
|
|
|
}
|
2006-05-17 02:24:52 +00:00
|
|
|
else
|
|
|
|
{
|
2006-05-17 02:30:08 +00:00
|
|
|
prefvalue = parent.hPrefWindow.getPref( "int", "browser.display.screen_resolution" );
|
2006-05-17 02:24:52 +00:00
|
|
|
if( prefvalue != "!/!ERROR_UNDEFINED_PREF!/!" )
|
2006-05-17 02:30:08 +00:00
|
|
|
resolution = prefvalue;
|
|
|
|
else
|
|
|
|
resolution = 96; // If it all goes horribly wrong, fall back on 96.
|
2006-05-17 02:24:52 +00:00
|
|
|
}
|
2006-05-17 02:30:08 +00:00
|
|
|
|
2006-05-17 02:30:55 +00:00
|
|
|
setResolution( resolution );
|
|
|
|
|
2006-05-17 02:30:12 +00:00
|
|
|
if ( parent.hPrefWindow.getPrefIsLocked( "browser.display.screen_resolution" ) ) {
|
|
|
|
screenResolution.disabled = true;
|
|
|
|
}
|
|
|
|
|
2006-05-17 02:24:52 +00:00
|
|
|
var useDocFontsCheckbox = document.getElementById( "browserUseDocumentFonts" );
|
2006-05-17 02:32:14 +00:00
|
|
|
if( "useDocFonts" in aDataObject && aDataObject.useDocFonts != undefined )
|
2006-05-17 02:30:08 +00:00
|
|
|
useDocFontsCheckbox.checked = aDataObject.useDocFonts ? true : false;
|
2006-05-17 02:24:52 +00:00
|
|
|
else
|
|
|
|
{
|
2006-05-17 02:30:08 +00:00
|
|
|
prefvalue = parent.hPrefWindow.getPref( "int", "browser.display.use_document_fonts" );
|
2006-05-17 02:24:52 +00:00
|
|
|
if( prefvalue != "!/!ERROR_UNDEFINED_PREF!/!" )
|
2006-05-17 02:30:08 +00:00
|
|
|
useDocFontsCheckbox.checked = prefvalue ? true : false ;
|
2006-05-17 02:24:52 +00:00
|
|
|
}
|
2006-05-17 02:30:12 +00:00
|
|
|
if ( parent.hPrefWindow.getPrefIsLocked( "browser.display.use_document_fonts" ) ) {
|
|
|
|
useDocFontsCheckbox.disabled = true;
|
|
|
|
}
|
2006-05-17 02:28:51 +00:00
|
|
|
}
|
|
|
|
|
2006-05-17 02:24:52 +00:00
|
|
|
function Startup()
|
|
|
|
{
|
|
|
|
variableSize = document.getElementById( "sizeVar" );
|
|
|
|
fixedSize = document.getElementById( "sizeMono" );
|
2006-05-17 02:32:12 +00:00
|
|
|
minSize = document.getElementById( "minSize" );
|
2006-05-17 02:24:52 +00:00
|
|
|
languageList = document.getElementById( "selectLangs" );
|
2006-05-17 02:24:57 +00:00
|
|
|
|
2006-05-17 02:28:44 +00:00
|
|
|
gPrefutilitiesBundle = document.getElementById("bundle_prefutilities");
|
2006-05-17 02:28:51 +00:00
|
|
|
|
2006-05-17 02:24:52 +00:00
|
|
|
// register our ok callback function
|
|
|
|
parent.hPrefWindow.registerOKCallbackFunc( saveFontPrefs );
|
2006-05-17 02:28:51 +00:00
|
|
|
|
2006-05-17 02:24:52 +00:00
|
|
|
// eventually we should detect the default language and select it by default
|
2006-05-17 02:28:44 +00:00
|
|
|
selectLanguage();
|
2006-05-17 02:30:09 +00:00
|
|
|
|
2006-05-17 02:32:15 +00:00
|
|
|
// Allow user to ask the OS for a DPI if we are under X or OS/2
|
|
|
|
if ((navigator.appVersion.indexOf("X11") != -1) || (navigator.appVersion.indexOf("OS/2") != -1))
|
2006-05-17 02:30:09 +00:00
|
|
|
{
|
|
|
|
document.getElementById( "systemResolution" ).removeAttribute( "hidden" );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set up the labels for the standard issue resolutions
|
|
|
|
var resolution;
|
|
|
|
resolution = document.getElementById( "screenResolution" );
|
2006-05-17 02:30:59 +00:00
|
|
|
|
|
|
|
// Set an attribute on the selected resolution item so we can fall back on
|
|
|
|
// it if an invalid selection is made (select "Other...", hit Cancel)
|
|
|
|
resolution.selectedItem.setAttribute("current", "true");
|
|
|
|
|
2006-05-17 02:32:15 +00:00
|
|
|
var defaultResolution;
|
|
|
|
var otherResolution;
|
|
|
|
|
|
|
|
// On OS/2, 120 is the default system resolution.
|
|
|
|
// 96 is valid, but used only for for 640x480.
|
|
|
|
if (navigator.appVersion.indexOf("OS/2") != -1)
|
|
|
|
{
|
|
|
|
defaultResolution = "120";
|
|
|
|
otherResolution = "96";
|
2006-05-17 02:35:19 +00:00
|
|
|
document.getElementById( "arbitraryResolution" ).setAttribute( "hidden", "true" );
|
|
|
|
document.getElementById( "resolutionSeparator" ).setAttribute( "hidden", "true" );
|
2006-05-17 02:32:15 +00:00
|
|
|
} else {
|
|
|
|
defaultResolution = "96";
|
|
|
|
otherResolution = "72";
|
|
|
|
}
|
|
|
|
|
2006-05-17 02:30:09 +00:00
|
|
|
var dpi = resolution.getAttribute( "dpi" );
|
|
|
|
resolution = document.getElementById( "defaultResolution" );
|
2006-05-17 02:32:15 +00:00
|
|
|
resolution.setAttribute( "value", defaultResolution );
|
|
|
|
resolution.setAttribute( "label", dpi.replace(/\$val/, defaultResolution ) );
|
|
|
|
resolution = document.getElementById( "otherResolution" );
|
|
|
|
resolution.setAttribute( "value", otherResolution );
|
|
|
|
resolution.setAttribute( "label", dpi.replace(/\$val/, otherResolution ) );
|
2006-05-17 02:30:12 +00:00
|
|
|
|
2006-05-17 02:30:57 +00:00
|
|
|
// Get the pref and set up the dialog appropriately. Startup is called
|
|
|
|
// after SetFields so we can't rely on that call to do the business.
|
2006-05-17 02:32:14 +00:00
|
|
|
var prefvalue = parent.hPrefWindow.getPref( "int", "browser.display.screen_resolution" );
|
2006-05-17 02:30:57 +00:00
|
|
|
if( prefvalue != "!/!ERROR_UNDEFINED_PREF!/!" )
|
|
|
|
resolution = prefvalue;
|
|
|
|
else
|
|
|
|
resolution = 96; // If it all goes horribly wrong, fall back on 96.
|
|
|
|
|
|
|
|
setResolution( resolution );
|
|
|
|
|
2006-05-17 02:30:12 +00:00
|
|
|
// This prefstring is a contrived pref whose sole purpose is to lock some
|
|
|
|
// elements in this panel. The value of the pref is not used and does not matter.
|
|
|
|
if ( parent.hPrefWindow.getPrefIsLocked( "browser.display.languageList" ) ) {
|
|
|
|
disableAllFontElements();
|
|
|
|
}
|
2006-05-17 02:24:52 +00:00
|
|
|
}
|
2006-05-17 02:28:51 +00:00
|
|
|
|
2006-05-17 02:24:52 +00:00
|
|
|
function listElement( aListID )
|
|
|
|
{
|
|
|
|
this.listElement = document.getElementById( aListID );
|
|
|
|
}
|
2006-05-17 02:28:51 +00:00
|
|
|
|
|
|
|
listElement.prototype =
|
2006-05-17 02:24:52 +00:00
|
|
|
{
|
2006-05-17 02:28:51 +00:00
|
|
|
clearList:
|
2006-05-17 02:24:52 +00:00
|
|
|
function ()
|
|
|
|
{
|
2006-05-17 02:28:51 +00:00
|
|
|
// remove the menupopup node child of the menulist.
|
2006-05-17 02:24:52 +00:00
|
|
|
this.listElement.removeChild( this.listElement.firstChild );
|
|
|
|
},
|
|
|
|
|
|
|
|
appendString:
|
|
|
|
function ( aString )
|
|
|
|
{
|
|
|
|
var menuItemNode = document.createElement( "menuitem" );
|
|
|
|
if( menuItemNode )
|
|
|
|
{
|
2006-05-17 02:28:51 +00:00
|
|
|
menuItemNode.setAttribute( "label", aString );
|
2006-05-17 02:24:52 +00:00
|
|
|
this.listElement.firstChild.appendChild( menuItemNode );
|
|
|
|
}
|
|
|
|
},
|
2006-05-17 02:28:51 +00:00
|
|
|
|
2006-05-17 02:28:57 +00:00
|
|
|
appendFontNames:
|
|
|
|
function ( aDataObject )
|
|
|
|
{
|
|
|
|
var popupNode = document.createElement( "menupopup" );
|
|
|
|
var strDefaultFontFace = "";
|
|
|
|
var fontName;
|
|
|
|
while (aDataObject.hasMoreElements()) {
|
|
|
|
fontName = aDataObject.getNext();
|
2006-05-17 02:34:48 +00:00
|
|
|
fontName = fontName.QueryInterface(Components.interfaces.nsISupportsString);
|
2006-05-17 02:28:57 +00:00
|
|
|
var fontNameStr = fontName.toString();
|
|
|
|
if (strDefaultFontFace == "")
|
|
|
|
strDefaultFontFace = fontNameStr;
|
|
|
|
var itemNode = document.createElement( "menuitem" );
|
|
|
|
itemNode.setAttribute( "value", fontNameStr );
|
|
|
|
itemNode.setAttribute( "label", fontNameStr );
|
|
|
|
popupNode.appendChild( itemNode );
|
|
|
|
}
|
|
|
|
if (strDefaultFontFace != "") {
|
|
|
|
this.listElement.removeAttribute( "disabled" );
|
|
|
|
} else {
|
|
|
|
this.listElement.setAttribute( "value", strDefaultFontFace );
|
|
|
|
this.listElement.setAttribute( "label",
|
|
|
|
gPrefutilitiesBundle.getString("nofontsforlang") );
|
|
|
|
this.listElement.setAttribute( "disabled", "true" );
|
|
|
|
}
|
|
|
|
this.listElement.appendChild( popupNode );
|
|
|
|
return strDefaultFontFace;
|
|
|
|
}
|
2006-05-17 02:24:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function saveFontPrefs()
|
|
|
|
{
|
|
|
|
// if saveState function is available, assume can call it.
|
|
|
|
// why is this extra qualification required?!!!!
|
|
|
|
if( top.hPrefWindow.wsm.contentArea.saveState )
|
|
|
|
{
|
|
|
|
saveState();
|
2006-05-17 02:25:26 +00:00
|
|
|
parent.hPrefWindow.wsm.dataManager.pageData["chrome://communicator/content/pref/pref-fonts.xul"] = GetFields();
|
2006-05-17 02:24:52 +00:00
|
|
|
}
|
2006-05-17 02:28:51 +00:00
|
|
|
|
2006-05-17 02:24:52 +00:00
|
|
|
// saving font prefs
|
2006-05-17 02:25:26 +00:00
|
|
|
var dataObject = parent.hPrefWindow.wsm.dataManager.pageData["chrome://communicator/content/pref/pref-fonts.xul"];
|
2006-05-17 02:24:52 +00:00
|
|
|
var pref = parent.hPrefWindow.pref;
|
|
|
|
for( var language in dataObject.languageData )
|
|
|
|
{
|
|
|
|
for( var type in dataObject.languageData[language].types )
|
|
|
|
{
|
|
|
|
var fontPrefString = "font.name." + type + "." + language;
|
|
|
|
var currValue = "";
|
2006-05-17 02:28:51 +00:00
|
|
|
try
|
2006-05-17 02:24:52 +00:00
|
|
|
{
|
|
|
|
currValue = pref.CopyUnicharPref( fontPrefString );
|
|
|
|
}
|
|
|
|
catch(e)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
if( currValue != dataObject.languageData[language].types[type] )
|
2006-05-17 02:25:25 +00:00
|
|
|
pref.SetUnicharPref( fontPrefString, dataObject.languageData[language].types[type] );
|
2006-05-17 02:24:52 +00:00
|
|
|
}
|
|
|
|
var variableSizePref = "font.size.variable." + language;
|
|
|
|
var fixedSizePref = "font.size.fixed." + language;
|
2006-05-17 02:32:12 +00:00
|
|
|
var minSizePref = "font.minimum-size." + language;
|
|
|
|
var currVariableSize = 12, currFixedSize = 12, minSizeVal = 0;
|
2006-05-17 02:28:51 +00:00
|
|
|
try
|
2006-05-17 02:24:52 +00:00
|
|
|
{
|
|
|
|
currVariableSize = pref.GetIntPref( variableSizePref );
|
|
|
|
currFixedSize = pref.GetIntPref( fixedSizePref );
|
2006-05-17 02:32:12 +00:00
|
|
|
minSizeVal = pref.GetIntPref( minSizePref );
|
2006-05-17 02:24:52 +00:00
|
|
|
}
|
|
|
|
catch(e)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
if( currVariableSize != dataObject.languageData[language].variableSize )
|
|
|
|
pref.SetIntPref( variableSizePref, dataObject.languageData[language].variableSize );
|
|
|
|
if( currFixedSize != dataObject.languageData[language].fixedSize )
|
2006-05-17 02:28:51 +00:00
|
|
|
pref.SetIntPref( fixedSizePref, dataObject.languageData[language].fixedSize );
|
2006-05-17 02:32:12 +00:00
|
|
|
if ( minSizeVal != dataObject.languageData[language].minSize ) {
|
|
|
|
pref.SetIntPref ( minSizePref, dataObject.languageData[language].minSize );
|
|
|
|
}
|
2006-05-17 02:24:52 +00:00
|
|
|
}
|
|
|
|
|
2006-05-17 02:28:51 +00:00
|
|
|
// font scaling
|
2006-05-17 02:24:52 +00:00
|
|
|
var fontDPI = parseInt( dataObject.fontDPI );
|
|
|
|
var documentFonts = dataObject.useDocFonts;
|
|
|
|
var defaultFont = dataObject.defaultFont;
|
2006-05-17 02:28:51 +00:00
|
|
|
|
2006-05-17 02:24:52 +00:00
|
|
|
try
|
|
|
|
{
|
2006-05-17 02:25:22 +00:00
|
|
|
var currDPI = pref.GetIntPref( "browser.display.screen_resolution" );
|
|
|
|
var currFonts = pref.GetIntPref( "browser.display.use_document_fonts" );
|
2006-05-17 02:28:20 +00:00
|
|
|
var currDefault = pref.CopyUnicharPref( "font.default" );
|
2006-05-17 02:24:52 +00:00
|
|
|
}
|
|
|
|
catch(e)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
if( currDPI != fontDPI )
|
2006-05-17 02:25:22 +00:00
|
|
|
pref.SetIntPref( "browser.display.screen_resolution", fontDPI );
|
2006-05-17 02:24:52 +00:00
|
|
|
if( currFonts != documentFonts )
|
2006-05-17 02:25:22 +00:00
|
|
|
pref.SetIntPref( "browser.display.use_document_fonts", documentFonts );
|
2006-05-17 02:24:52 +00:00
|
|
|
if( currDefault != defaultFont )
|
|
|
|
{
|
2006-05-17 02:28:20 +00:00
|
|
|
pref.SetUnicharPref( "font.default", defaultFont );
|
2006-05-17 02:24:52 +00:00
|
|
|
}
|
|
|
|
}
|
2006-05-17 02:28:51 +00:00
|
|
|
|
2006-05-17 02:24:52 +00:00
|
|
|
function saveState()
|
|
|
|
{
|
|
|
|
for( var i = 0; i < fontTypes.length; i++ )
|
|
|
|
{
|
|
|
|
// preliminary initialisation
|
2006-05-17 02:32:14 +00:00
|
|
|
if( currentLanguage && !( currentLanguage in languageData ) )
|
2006-05-17 02:24:52 +00:00
|
|
|
languageData[currentLanguage] = [];
|
2006-05-17 02:32:14 +00:00
|
|
|
if( currentLanguage && !( "types" in languageData[currentLanguage] ) )
|
2006-05-17 02:24:52 +00:00
|
|
|
languageData[currentLanguage].types = [];
|
|
|
|
// save data for the previous language
|
2006-05-17 02:32:14 +00:00
|
|
|
if( currentLanguage && currentLanguage in languageData &&
|
|
|
|
"types" in languageData[currentLanguage] )
|
2006-05-17 02:28:51 +00:00
|
|
|
languageData[currentLanguage].types[fontTypes[i]] = document.getElementById( fontTypes[i] ).value;
|
2006-05-17 02:24:52 +00:00
|
|
|
}
|
|
|
|
|
2006-05-17 02:32:14 +00:00
|
|
|
if( currentLanguage && currentLanguage in languageData &&
|
|
|
|
"types" in languageData[currentLanguage] )
|
2006-05-17 02:24:52 +00:00
|
|
|
{
|
2006-05-17 02:28:51 +00:00
|
|
|
languageData[currentLanguage].variableSize = parseInt( variableSize.value );
|
|
|
|
languageData[currentLanguage].fixedSize = parseInt( fixedSize.value );
|
2006-05-17 02:32:12 +00:00
|
|
|
languageData[currentLanguage].minSize = parseInt( minSize.value );
|
2006-05-17 02:24:52 +00:00
|
|
|
}
|
2006-05-17 02:28:51 +00:00
|
|
|
}
|
|
|
|
|
2006-05-17 02:32:12 +00:00
|
|
|
// Selects size (or the nearest entry that exists in the list)
|
|
|
|
// in the menulist minSize
|
|
|
|
function minSizeSelect(size)
|
|
|
|
{
|
|
|
|
var items = minSize.getElementsByAttribute( "value", size );
|
|
|
|
if (items.length > 0)
|
|
|
|
minSize.selectedItem = items[0];
|
|
|
|
else if (size < 6)
|
|
|
|
minSizeSelect(6);
|
2006-05-17 02:32:13 +00:00
|
|
|
else if (size > 24)
|
|
|
|
minSizeSelect(24);
|
2006-05-17 02:32:12 +00:00
|
|
|
else
|
|
|
|
minSizeSelect(size - 1);
|
|
|
|
}
|
|
|
|
|
2006-05-17 02:24:52 +00:00
|
|
|
function selectLanguage()
|
2006-05-17 02:28:44 +00:00
|
|
|
{
|
2006-05-17 02:24:52 +00:00
|
|
|
// save current state
|
|
|
|
saveState();
|
2006-05-17 02:28:51 +00:00
|
|
|
|
2006-05-17 02:24:52 +00:00
|
|
|
if( !currentLanguage )
|
2006-05-17 02:28:51 +00:00
|
|
|
currentLanguage = languageList.value;
|
|
|
|
|
2006-05-17 02:24:52 +00:00
|
|
|
for( var i = 0; i < fontTypes.length; i++ )
|
|
|
|
{
|
|
|
|
// build and populate the font list for the newly chosen font type
|
2006-05-17 02:28:57 +00:00
|
|
|
var fontEnumerator = fontList.availableFonts(languageList.value, fontTypes[i]);
|
2006-05-17 02:24:52 +00:00
|
|
|
var selectElement = new listElement( fontTypes[i] );
|
|
|
|
selectElement.clearList();
|
2006-05-17 02:28:57 +00:00
|
|
|
var strDefaultFontFace = selectElement.appendFontNames(fontEnumerator);
|
|
|
|
//the first font face name returned by the enumerator is our last resort
|
|
|
|
var defaultListSelection = selectElement.listElement.getElementsByAttribute( "value", strDefaultFontFace)[0];
|
2006-05-17 02:32:14 +00:00
|
|
|
var selectedItem;
|
2006-05-17 02:28:55 +00:00
|
|
|
|
|
|
|
//fall-back initialization values (first font face list entry)
|
2006-05-17 02:32:14 +00:00
|
|
|
defaultListSelection = strDefaultFontFace ? selectElement.listElement.getElementsByAttribute( "value", strDefaultFontFace)[0] : null;
|
2006-05-17 02:28:51 +00:00
|
|
|
|
2006-05-17 02:32:14 +00:00
|
|
|
if( languageList.value in languageData )
|
2006-05-17 02:24:52 +00:00
|
|
|
{
|
|
|
|
// data exists for this language, pre-select items based on this information
|
2006-05-17 02:28:51 +00:00
|
|
|
var dataElements = selectElement.listElement.getElementsByAttribute( "value", languageData[languageList.value].types[fontTypes[i]] );
|
2006-05-17 02:32:14 +00:00
|
|
|
selectedItem = dataElements.length ? dataElements[0] : defaultListSelection;
|
2006-05-17 02:28:55 +00:00
|
|
|
|
2006-05-17 02:32:12 +00:00
|
|
|
minSizeSelect(languageData[languageList.value].minSize);
|
2006-05-17 02:28:55 +00:00
|
|
|
if (strDefaultFontFace)
|
2006-05-17 02:25:24 +00:00
|
|
|
{
|
|
|
|
selectElement.listElement.selectedItem = selectedItem;
|
|
|
|
variableSize.removeAttribute("disabled");
|
|
|
|
fixedSize.removeAttribute("disabled");
|
2006-05-17 02:32:12 +00:00
|
|
|
minSize.removeAttribute("disabled");
|
2006-05-17 02:28:51 +00:00
|
|
|
variableSize.selectedItem = variableSize.getElementsByAttribute( "value", languageData[languageList.value].variableSize )[0];
|
|
|
|
fixedSize.selectedItem = fixedSize.getElementsByAttribute( "value", languageData[languageList.value].fixedSize )[0];
|
2006-05-17 02:25:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
variableSize.setAttribute("disabled","true");
|
|
|
|
fixedSize.setAttribute("disabled","true");
|
2006-05-17 02:32:12 +00:00
|
|
|
minSize.setAttribute("disabled","true");
|
2006-05-17 02:25:24 +00:00
|
|
|
}
|
2006-05-17 02:24:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-05-17 02:28:55 +00:00
|
|
|
|
|
|
|
if (strDefaultFontFace) {
|
|
|
|
//initialze pref panel only if font faces are available for this language family
|
|
|
|
|
|
|
|
var selectVal;
|
2006-05-17 02:32:12 +00:00
|
|
|
|
2006-05-17 02:28:55 +00:00
|
|
|
try {
|
|
|
|
var fontPrefString = "font.name." + fontTypes[i] + "." + languageList.value;
|
|
|
|
selectVal = parent.hPrefWindow.pref.CopyUnicharPref( fontPrefString );
|
|
|
|
var dataEls = selectElement.listElement.getElementsByAttribute( "value", selectVal );
|
2006-05-17 02:30:58 +00:00
|
|
|
|
|
|
|
// we need to honor name-list in case name is unavailable
|
|
|
|
if (!dataEls.length) {
|
|
|
|
var fontListPrefString = "font.name-list." + fontTypes[i] + "." + languageList.value;
|
|
|
|
var nameList = parent.hPrefWindow.pref.CopyUnicharPref( fontListPrefString );
|
|
|
|
var fontNames = nameList.split(",");
|
|
|
|
var stripWhitespace = /^\s*(.*)\s*$/;
|
|
|
|
|
|
|
|
for (j = 0; j < fontNames.length; j++) {
|
|
|
|
selectVal = fontNames[j].replace(stripWhitespace, "$1");
|
|
|
|
dataEls = selectElement.listElement.getElementsByAttribute("value", selectVal);
|
|
|
|
if (dataEls.length)
|
|
|
|
break; // exit loop if we find one
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-17 02:28:55 +00:00
|
|
|
selectedItem = dataEls.length ? dataEls[0] : defaultListSelection;
|
2006-05-17 02:30:58 +00:00
|
|
|
if (!dataEls.length)
|
|
|
|
selectedVal = strDefaultFontFace;
|
2006-05-17 02:28:55 +00:00
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
//always initialize: fall-back to default values
|
|
|
|
selectVal = strDefaultFontFace;
|
|
|
|
selectedItem = defaultListSelection;
|
|
|
|
}
|
|
|
|
|
|
|
|
selectElement.listElement.selectedItem = selectedItem;
|
|
|
|
|
|
|
|
variableSize.removeAttribute("disabled");
|
|
|
|
fixedSize.removeAttribute("disabled");
|
2006-05-17 02:32:12 +00:00
|
|
|
minSize.removeAttribute("disabled");
|
2006-05-17 02:28:55 +00:00
|
|
|
|
2006-05-17 02:30:12 +00:00
|
|
|
|
2006-05-17 02:28:55 +00:00
|
|
|
try {
|
2006-05-17 02:28:51 +00:00
|
|
|
var variableSizePref = "font.size.variable." + languageList.value;
|
|
|
|
var fixedSizePref = "font.size.fixed." + languageList.value;
|
2006-05-17 02:28:55 +00:00
|
|
|
|
2006-05-17 02:25:24 +00:00
|
|
|
var sizeVarVal = parent.hPrefWindow.pref.GetIntPref( variableSizePref );
|
|
|
|
var sizeFixedVal = parent.hPrefWindow.pref.GetIntPref( fixedSizePref );
|
2006-05-17 02:28:55 +00:00
|
|
|
|
2006-05-17 02:28:51 +00:00
|
|
|
variableSize.selectedItem = variableSize.getElementsByAttribute( "value", sizeVarVal )[0];
|
2006-05-17 02:28:55 +00:00
|
|
|
|
2006-05-17 02:28:51 +00:00
|
|
|
fixedSize.selectedItem = fixedSize.getElementsByAttribute( "value", sizeFixedVal )[0];
|
2006-05-17 02:28:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
catch(e) {
|
|
|
|
//font size lists can simply deafult to the first entry
|
|
|
|
}
|
2006-05-17 02:32:12 +00:00
|
|
|
var minSizeVal = 0;
|
|
|
|
try {
|
|
|
|
var minSizePref = "font.minimum-size." + languageList.value;
|
|
|
|
minSizeVal = pref.GetIntPref( minSizePref );
|
|
|
|
}
|
|
|
|
catch(e) {}
|
|
|
|
minSizeSelect( minSizeVal );
|
2006-05-17 02:28:55 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//disable otherwise
|
|
|
|
variableSize.setAttribute("disabled","true");
|
|
|
|
fixedSize.setAttribute("disabled","true");
|
2006-05-17 02:32:12 +00:00
|
|
|
minSize.setAttribute("disabled","true");
|
|
|
|
minSizeSelect(0);
|
2006-05-17 02:28:55 +00:00
|
|
|
}
|
2006-05-17 02:24:52 +00:00
|
|
|
}
|
|
|
|
}
|
2006-05-17 02:28:51 +00:00
|
|
|
currentLanguage = languageList.value;
|
2006-05-17 02:24:52 +00:00
|
|
|
}
|
2006-05-17 02:24:16 +00:00
|
|
|
|
2006-05-17 02:30:08 +00:00
|
|
|
function changeScreenResolution()
|
|
|
|
{
|
|
|
|
var screenResolution = document.getElementById("screenResolution");
|
|
|
|
var userResolution = document.getElementById("userResolution");
|
2006-05-17 02:30:59 +00:00
|
|
|
|
|
|
|
var previousSelection = screenResolution.getElementsByAttribute("current", "true")[0];
|
|
|
|
|
2006-05-17 02:30:08 +00:00
|
|
|
if (screenResolution.value == "other")
|
|
|
|
{
|
|
|
|
// If the user selects "Other..." we bring up the calibrate screen dialog
|
|
|
|
var rv = { newdpi : 0 };
|
2006-05-17 02:32:14 +00:00
|
|
|
var calscreen = window.openDialog("chrome://communicator/content/pref/pref-calibrate-screen.xul",
|
2006-05-17 02:30:11 +00:00
|
|
|
"_blank",
|
|
|
|
"modal,chrome,centerscreen,resizable=no,titlebar",
|
2006-05-17 02:30:08 +00:00
|
|
|
rv);
|
|
|
|
if (rv.newdpi != -1)
|
|
|
|
{
|
|
|
|
// They have entered values, and we have a DPI value back
|
2006-05-17 02:30:09 +00:00
|
|
|
var dpi = screenResolution.getAttribute( "dpi" );
|
2006-05-17 02:30:55 +00:00
|
|
|
setResolution ( rv.newdpi );
|
2006-05-17 02:30:59 +00:00
|
|
|
|
|
|
|
previousSelection.removeAttribute("current");
|
|
|
|
screenResolution.selectedItem.setAttribute("current", "true");
|
2006-05-17 02:30:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// They've cancelled. We can't leave "Other..." selected, so...
|
2006-05-17 02:30:59 +00:00
|
|
|
// we re-select the previously selected item.
|
|
|
|
screenResolution.selectedItem = previousSelection;
|
2006-05-17 02:30:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!(screenResolution.value == userResolution.value))
|
|
|
|
{
|
|
|
|
// User has selected one of the hard-coded resolutions
|
|
|
|
userResolution.setAttribute("hidden", "true");
|
2006-05-17 02:30:59 +00:00
|
|
|
|
|
|
|
previousSelection.removeAttribute("current");
|
|
|
|
screenResolution.selectedItem.setAttribute("current", "true");
|
2006-05-17 02:30:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-17 02:30:55 +00:00
|
|
|
function setResolution( resolution )
|
|
|
|
{
|
|
|
|
// Given a number, if it's equal to a hard-coded resolution we use that,
|
|
|
|
// otherwise we set the userResolution field.
|
|
|
|
var screenResolution = document.getElementById( "screenResolution" );
|
|
|
|
var userResolution = document.getElementById( "userResolution" );
|
|
|
|
|
2006-05-17 02:32:14 +00:00
|
|
|
var items = screenResolution.getElementsByAttribute( "value", resolution );
|
|
|
|
if (items.length)
|
2006-05-17 02:30:55 +00:00
|
|
|
{
|
|
|
|
// If it's one of the hard-coded values, we'll select it directly
|
2006-05-17 02:32:14 +00:00
|
|
|
screenResolution.selectedItem = items[0];
|
2006-05-17 02:30:55 +00:00
|
|
|
userResolution.setAttribute( "hidden", "true" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Otherwise we need to set up the userResolution field
|
|
|
|
var dpi = screenResolution.getAttribute( "dpi" );
|
|
|
|
userResolution.setAttribute( "value", resolution );
|
|
|
|
userResolution.setAttribute( "label", dpi.replace(/\$val/, resolution) );
|
|
|
|
userResolution.removeAttribute( "hidden" );
|
|
|
|
screenResolution.selectedItem = userResolution;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-17 02:30:08 +00:00
|
|
|
// "Calibrate screen" dialog code
|
|
|
|
|
|
|
|
function Init()
|
|
|
|
{
|
|
|
|
sizeToContent();
|
|
|
|
doSetOKCancel(onOK, onCancel);
|
|
|
|
document.getElementById("horizSize").focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
function onOK()
|
|
|
|
{
|
|
|
|
// Get value from the dialog to work out dpi
|
|
|
|
var horizSize = parseFloat(document.getElementById("horizSize").value);
|
|
|
|
var units = document.getElementById("units").value;
|
|
|
|
|
|
|
|
if (!horizSize || horizSize < 0)
|
|
|
|
{
|
|
|
|
// We can't calculate anything without a proper value
|
|
|
|
window.arguments[0].newdpi = -1;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert centimetres to inches.
|
|
|
|
// The magic number is allowed because it's a fundamental constant :-)
|
|
|
|
if (units === "centimetres")
|
|
|
|
{
|
|
|
|
horizSize /= 2.54;
|
|
|
|
}
|
|
|
|
|
|
|
|
// These shouldn't change, but you can't be too careful.
|
|
|
|
var horizBarLengthPx = document.getElementById("horizRuler").boxObject.width;
|
|
|
|
|
|
|
|
var horizDPI = parseInt(horizBarLengthPx) / horizSize;
|
|
|
|
|
|
|
|
// Average the two <shrug>.
|
|
|
|
window.arguments[0].newdpi = Math.round(horizDPI);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onCancel()
|
|
|
|
{
|
2006-05-17 02:30:59 +00:00
|
|
|
// We return -1 to show that no value has been given.
|
2006-05-17 02:30:08 +00:00
|
|
|
window.arguments[0].newdpi = -1;
|
|
|
|
return true;
|
|
|
|
}
|
2006-05-17 02:30:12 +00:00
|
|
|
|
|
|
|
// disable font items, but not the browserUseDocumentFonts checkbox nor the resolution
|
|
|
|
// menulist
|
|
|
|
function disableAllFontElements()
|
|
|
|
{
|
|
|
|
var doc_ids = [ "selectLangs", "proportionalFont",
|
|
|
|
"sizeVar", "serif", "sans-serif",
|
|
|
|
"cursive", "fantasy", "monospace",
|
2006-05-17 02:32:12 +00:00
|
|
|
"sizeMono", "minSize" ];
|
2006-05-17 02:30:12 +00:00
|
|
|
for (i=0; i<doc_ids.length; i++) {
|
|
|
|
element = document.getElementById( doc_ids[i] );
|
|
|
|
element.disabled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|