~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/xpfe/components/prefwindow/resources/content/pref-fonts.js

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 
2
/* ***** BEGIN LICENSE BLOCK *****
 
3
 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
 
4
 *
 
5
 * The contents of this file are subject to the Netscape Public License
 
6
 * Version 1.1 (the "License"); you may not use this file except in
 
7
 * compliance with the License. You may obtain a copy of the License at
 
8
 * http://www.mozilla.org/NPL/
 
9
 *
 
10
 * Software distributed under the License is distributed on an "AS IS" basis,
 
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
12
 * for the specific language governing rights and limitations under the
 
13
 * License.
 
14
 *
 
15
 * The Original Code is mozilla.org code.
 
16
 *
 
17
 * The Initial Developer of the Original Code is 
 
18
 * Netscape Communications Corporation.
 
19
 * Portions created by the Initial Developer are Copyright (C) 1998
 
20
 * the Initial Developer. All Rights Reserved.
 
21
 *
 
22
 * Contributor(s):
 
23
 *    Gervase Markham <gerv@gerv.net>
 
24
 *    Tuukka Tolvanen <tt@lament.cjb.net>
 
25
 *
 
26
 * Alternatively, the contents of this file may be used under the terms of
 
27
 * either the GNU General Public License Version 2 or later (the "GPL"), or 
 
28
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
29
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
30
 * of those above. If you wish to allow use of your version of this file only
 
31
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
32
 * use your version of this file under the terms of the NPL, indicate your
 
33
 * decision by deleting the provisions above and replace them with the notice
 
34
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
35
 * the provisions above, a recipient may use your version of this file under
 
36
 * the terms of any one of the NPL, the GPL or the LGPL.
 
37
 *
 
38
 * ***** END LICENSE BLOCK ***** */
 
39
 
 
40
var fontEnumerator = null;
 
41
var globalFonts = null;
 
42
var fontTypes   = ["serif", "sans-serif", "cursive", "fantasy", "monospace"];
 
43
var variableSize, fixedSize, minSize, languageList;
 
44
var languageData = [];
 
45
var currentLanguage;
 
46
var gPrefutilitiesBundle;
 
47
 
 
48
// manual data retrieval function for PrefWindow
 
49
function GetFields()
 
50
  {
 
51
    var dataObject = parent.hPrefWindow.wsm.dataManager.pageData["chrome://communicator/content/pref/pref-fonts.xul"];
 
52
 
 
53
    // store data for language independent widgets
 
54
    var lists = ["selectLangs", "proportionalFont"];
 
55
    for( var i = 0; i < lists.length; i++ )
 
56
      {
 
57
        if( !( "dataEls" in dataObject ) )
 
58
          dataObject.dataEls = [];
 
59
        dataObject.dataEls[ lists[i] ] = [];
 
60
        dataObject.dataEls[ lists[i] ].value = document.getElementById( lists[i] ).value;
 
61
      }
 
62
 
 
63
   dataObject.defaultFont = document.getElementById( "proportionalFont" ).value;
 
64
   dataObject.fontDPI = document.getElementById( "screenResolution" ).value;
 
65
   dataObject.useDocFonts = document.getElementById( "browserUseDocumentFonts" ).checked ? 1 : 0;
 
66
 
 
67
    // save current state for language dependent fields and store
 
68
    saveState();
 
69
    dataObject.languageData = languageData;
 
70
 
 
71
    return dataObject;
 
72
  }
 
73
 
 
74
// manual data setting function for PrefWindow
 
75
function SetFields( aDataObject )
 
76
  {
 
77
    languageData = "languageData" in aDataObject ? aDataObject.languageData : languageData ;
 
78
    currentLanguage = "currentLanguage" in aDataObject ? aDataObject.currentLanguage : null ;
 
79
 
 
80
    var lists = ["selectLangs", "proportionalFont"];
 
81
    var prefvalue;
 
82
    
 
83
    for( var i = 0; i < lists.length; i++ )
 
84
      {
 
85
        var element = document.getElementById( lists[i] );
 
86
        if( "dataEls" in aDataObject )
 
87
          {
 
88
            element.selectedItem = element.getElementsByAttribute( "value", aDataObject.dataEls[ lists[i] ].value )[0];
 
89
          }
 
90
        else
 
91
          {
 
92
            var prefstring = element.getAttribute( "prefstring" );
 
93
            var preftype = element.getAttribute( "preftype" );
 
94
            if( prefstring && preftype )
 
95
              {
 
96
                prefvalue = parent.hPrefWindow.getPref( preftype, prefstring );
 
97
                element.selectedItem = element.getElementsByAttribute( "value", prefvalue )[0];
 
98
              }
 
99
          }
 
100
      }
 
101
 
 
102
    var screenResolution = document.getElementById( "screenResolution" );
 
103
    var resolution;
 
104
    
 
105
    if( "fontDPI" in aDataObject )
 
106
      {
 
107
        resolution = aDataObject.fontDPI;
 
108
      }
 
109
    else
 
110
      {
 
111
        prefvalue = parent.hPrefWindow.getPref( "int", "browser.display.screen_resolution" );
 
112
        if( prefvalue != "!/!ERROR_UNDEFINED_PREF!/!" )
 
113
            resolution = prefvalue;
 
114
        else
 
115
            resolution = 96; // If it all goes horribly wrong, fall back on 96.
 
116
      }
 
117
    
 
118
    setResolution( resolution );
 
119
    
 
120
    if ( parent.hPrefWindow.getPrefIsLocked( "browser.display.screen_resolution" ) ) {
 
121
        screenResolution.disabled = true;
 
122
    }
 
123
 
 
124
    var useDocFontsCheckbox = document.getElementById( "browserUseDocumentFonts" );
 
125
    if( "useDocFonts" in aDataObject && aDataObject.useDocFonts != undefined )
 
126
      useDocFontsCheckbox.checked = aDataObject.useDocFonts ? true : false;
 
127
    else
 
128
      {
 
129
        prefvalue = parent.hPrefWindow.getPref( "int", "browser.display.use_document_fonts" );
 
130
        if( prefvalue != "!/!ERROR_UNDEFINED_PREF!/!" )
 
131
          useDocFontsCheckbox.checked = prefvalue ? true : false ;
 
132
      }
 
133
    if ( parent.hPrefWindow.getPrefIsLocked( "browser.display.use_document_fonts" ) ) {
 
134
        useDocFontsCheckbox.disabled = true;
 
135
    }
 
136
  }
 
137
 
 
138
function Startup()
 
139
  {
 
140
    variableSize = document.getElementById( "sizeVar" );
 
141
    fixedSize    = document.getElementById( "sizeMono" );
 
142
    minSize      = document.getElementById( "minSize" );
 
143
    languageList = document.getElementById( "selectLangs" );
 
144
 
 
145
    gPrefutilitiesBundle = document.getElementById("bundle_prefutilities");
 
146
 
 
147
    // register our ok callback function
 
148
    parent.hPrefWindow.registerOKCallbackFunc( saveFontPrefs );
 
149
 
 
150
    // eventually we should detect the default language and select it by default
 
151
    selectLanguage();
 
152
    
 
153
    // Allow user to ask the OS for a DPI if we are under X or OS/2
 
154
    if ((navigator.appVersion.indexOf("X11") != -1) || (navigator.appVersion.indexOf("OS/2") != -1))
 
155
      {
 
156
         document.getElementById( "systemResolution" ).removeAttribute( "hidden" ); 
 
157
      }
 
158
    
 
159
    // Set up the labels for the standard issue resolutions
 
160
    var resolution;
 
161
    resolution = document.getElementById( "screenResolution" );
 
162
 
 
163
    // Set an attribute on the selected resolution item so we can fall back on
 
164
    // it if an invalid selection is made (select "Other...", hit Cancel)
 
165
    resolution.selectedItem.setAttribute("current", "true");
 
166
 
 
167
    var defaultResolution;
 
168
    var otherResolution;
 
169
 
 
170
    // On OS/2, 120 is the default system resolution.
 
171
    // 96 is valid, but used only for for 640x480.
 
172
    if (navigator.appVersion.indexOf("OS/2") != -1)
 
173
      {
 
174
        defaultResolution = "120";
 
175
        otherResolution = "96";
 
176
        document.getElementById( "arbitraryResolution" ).setAttribute( "hidden", "true" ); 
 
177
        document.getElementById( "resolutionSeparator" ).setAttribute( "hidden", "true" ); 
 
178
      } else {
 
179
        defaultResolution = "96";
 
180
        otherResolution = "72";
 
181
      }
 
182
 
 
183
    var dpi = resolution.getAttribute( "dpi" );
 
184
    resolution = document.getElementById( "defaultResolution" );
 
185
    resolution.setAttribute( "value", defaultResolution );
 
186
    resolution.setAttribute( "label", dpi.replace(/\$val/, defaultResolution ) );
 
187
    resolution = document.getElementById( "otherResolution" );
 
188
    resolution.setAttribute( "value", otherResolution );
 
189
    resolution.setAttribute( "label", dpi.replace(/\$val/, otherResolution ) );
 
190
 
 
191
    // Get the pref and set up the dialog appropriately. Startup is called
 
192
    // after SetFields so we can't rely on that call to do the business.
 
193
    var prefvalue = parent.hPrefWindow.getPref( "int", "browser.display.screen_resolution" );
 
194
    if( prefvalue != "!/!ERROR_UNDEFINED_PREF!/!" )
 
195
        resolution = prefvalue;
 
196
    else
 
197
        resolution = 96; // If it all goes horribly wrong, fall back on 96.
 
198
    
 
199
    setResolution( resolution );
 
200
 
 
201
    // This prefstring is a contrived pref whose sole purpose is to lock some
 
202
    // elements in this panel.  The value of the pref is not used and does not matter.
 
203
    if ( parent.hPrefWindow.getPrefIsLocked( "browser.display.languageList" ) ) {
 
204
      disableAllFontElements();
 
205
    }
 
206
  }
 
207
 
 
208
function getFontEnumerator()
 
209
  {
 
210
    if (!fontEnumerator)
 
211
      {
 
212
        fontEnumerator = Components.classes["@mozilla.org/gfx/fontenumerator;1"]
 
213
                        .createInstance()
 
214
                        .QueryInterface(Components.interfaces.nsIFontEnumerator);
 
215
      }
 
216
    return fontEnumerator;
 
217
  }
 
218
 
 
219
function listElement( aListID )
 
220
  {
 
221
    this.listElement = document.getElementById( aListID );
 
222
  }
 
223
 
 
224
listElement.prototype =
 
225
  {
 
226
    clearList:
 
227
      function ()
 
228
        {
 
229
          // remove the menupopup node child of the menulist.
 
230
          this.listElement.removeChild( this.listElement.firstChild );
 
231
        },
 
232
 
 
233
    appendFontNames: 
 
234
      function ( aLanguage, aFontType )
 
235
        {
 
236
          var i;
 
237
          var defaultFont = null;
 
238
          var count = { value: 0 };
 
239
          var fonts = getFontEnumerator().EnumerateFonts( aLanguage, aFontType, count );
 
240
          if (fonts.length > 0)
 
241
            {
 
242
              defaultFont = getFontEnumerator().getDefaultFont( aLanguage, aFontType );
 
243
            }
 
244
          else
 
245
            {
 
246
              // if no specific fonts, relax 'aFontType' and try to get other
 
247
              // fonts for this language so that we can group them on top
 
248
              fonts = getFontEnumerator().EnumerateFonts( aLanguage, "", count );
 
249
              if (fonts.length > 0)
 
250
                {
 
251
                  defaultFont = getFontEnumerator().getDefaultFont( aLanguage, "" );
 
252
                }
 
253
            }
 
254
 
 
255
          var itemNode = null;
 
256
          var separatorNode = null;
 
257
          var popupNode = document.createElement( "menupopup" ); 
 
258
 
 
259
          if (fonts.length > 0)
 
260
            {
 
261
              // always put the default font at the front of the list
 
262
              if (defaultFont)
 
263
                {
 
264
                  var label = gPrefutilitiesBundle
 
265
                    .getString("labelDefaultFont")
 
266
                    .replace(/%font_family%/, defaultFont);
 
267
                  itemNode = document.createElement( "menuitem" );
 
268
                  itemNode.setAttribute( "label", label );
 
269
                  itemNode.setAttribute( "value", "" ); // special blank value
 
270
                  popupNode.appendChild( itemNode );
 
271
 
 
272
                  separatorNode = document.createElement( "menuseparator" );
 
273
                  popupNode.appendChild( separatorNode );
 
274
                }
 
275
 
 
276
              for (i = 0; i < fonts.length; i++)
 
277
                {
 
278
                  itemNode = document.createElement( "menuitem" );
 
279
                  itemNode.setAttribute( "value", fonts[i] );
 
280
                  itemNode.setAttribute( "label", fonts[i] );
 
281
                  popupNode.appendChild( itemNode );
 
282
                }
 
283
            }
 
284
 
 
285
            // get all the fonts to complete the font lists
 
286
            if (!globalFonts)
 
287
              {
 
288
                globalFonts = getFontEnumerator().EnumerateAllFonts( count );
 
289
              }
 
290
 
 
291
          // since the lists are sorted, we can get unique entries by just walking
 
292
          // both lists linearly side-by-side, skipping those values already in
 
293
          // the popup list
 
294
          if (globalFonts.length > fonts.length)
 
295
            {
 
296
              var menuItem = separatorNode ? separatorNode.nextSibling : popupNode.firstChild; 
 
297
              var menuValue = menuItem ? menuItem.getAttribute( "value" ) : null;
 
298
 
 
299
              separatorNode = document.createElement( "menuseparator" );
 
300
              popupNode.appendChild( separatorNode );
 
301
 
 
302
              for (i = 0; i < globalFonts.length; i++)
 
303
                {
 
304
                  if (globalFonts[i] != menuValue)
 
305
                    {
 
306
                      itemNode = document.createElement( "menuitem" );
 
307
                      itemNode.setAttribute( "value", globalFonts[i] );
 
308
                      itemNode.setAttribute( "label", globalFonts[i] );
 
309
                      popupNode.appendChild( itemNode );
 
310
                    }
 
311
                  else
 
312
                    {
 
313
                      menuItem = menuItem.nextSibling;
 
314
                      menuValue = menuItem ? menuItem.getAttribute( "value" ) : null;
 
315
                    }
 
316
                }
 
317
            }
 
318
 
 
319
          this.listElement.appendChild( popupNode ); 
 
320
 
 
321
          return popupNode.firstChild;
 
322
        } 
 
323
  };
 
324
 
 
325
function lazyAppendFontNames( i )
 
326
  {
 
327
     // schedule the build of the next font list
 
328
     if (i+1 < fontTypes.length)
 
329
       {
 
330
         window.setTimeout(lazyAppendFontNames, 100, i+1);
 
331
       }
 
332
 
 
333
     // now build and populate the fonts for the requested font type
 
334
     var defaultItem = null;
 
335
     var selectElement = new listElement( fontTypes[i] );
 
336
     selectElement.clearList();
 
337
     try
 
338
       {
 
339
         defaultItem = selectElement.appendFontNames( languageList.value, fontTypes[i] );
 
340
       }
 
341
     catch(e) {
 
342
         dump("pref-fonts.js: " + e + "\nFailed to build the font list for " + fontTypes[i] + "\n");
 
343
         return;
 
344
       }
 
345
 
 
346
     // now set the selected font item for the drop down list
 
347
 
 
348
     if (!defaultItem)
 
349
       return; // nothing to select, so no need to bother
 
350
 
 
351
     // the item returned by default is our last resort fall-back
 
352
     var selectedItem = defaultItem;
 
353
     if( languageList.value in languageData )
 
354
       {
 
355
         // data exists for this language, pre-select items based on this information
 
356
         var dataVal = languageData[languageList.value].types[fontTypes[i]];
 
357
         if (!dataVal.length) // special blank means the default
 
358
           {
 
359
             selectedItem = defaultItem;
 
360
           }
 
361
         else
 
362
           {
 
363
             var dataEls = selectElement.listElement.getElementsByAttribute( "value", dataVal );
 
364
             selectedItem = dataEls.length ? dataEls[0] : defaultItem;
 
365
           }
 
366
       }
 
367
     else
 
368
       {
 
369
         try
 
370
           {
 
371
             var fontPrefString = "font.name." + fontTypes[i] + "." + languageList.value;
 
372
             var selectVal = parent.hPrefWindow.pref.getComplexValue( fontPrefString, Components.interfaces.nsISupportsString ).data;
 
373
             var dataEls = selectElement.listElement.getElementsByAttribute( "value", selectVal );
 
374
 
 
375
             // we need to honor name-list in case name is unavailable 
 
376
             if (!dataEls.length) {
 
377
                 var fontListPrefString = "font.name-list." + fontTypes[i] + "." + languageList.value;
 
378
                 var nameList = parent.hPrefWindow.pref.getComplexValue( fontListPrefString, Components.interfaces.nsISupportsString ).data;
 
379
                 var fontNames = nameList.split(",");
 
380
                 var stripWhitespace = /^\s*(.*)\s*$/;
 
381
 
 
382
                 for (j = 0; j < fontNames.length; j++) {
 
383
                   selectVal = fontNames[j].replace(stripWhitespace, "$1");
 
384
                   dataEls = selectElement.listElement.getElementsByAttribute("value", selectVal);
 
385
                   if (dataEls.length)  
 
386
                     break;  // exit loop if we find one
 
387
                 }
 
388
             }
 
389
             selectedItem = dataEls.length ? dataEls[0] : defaultItem;
 
390
           }
 
391
         catch(e) {
 
392
             selectedItem = defaultItem;
 
393
           }
 
394
       }
 
395
 
 
396
     selectElement.listElement.selectedItem = selectedItem;
 
397
     selectElement.listElement.removeAttribute( "disabled" );
 
398
  }
 
399
 
 
400
function saveFontPrefs()
 
401
  {
 
402
    // saving font prefs
 
403
    var dataObject = parent.hPrefWindow.wsm.dataManager.pageData["chrome://communicator/content/pref/pref-fonts.xul"];
 
404
    var pref = parent.hPrefWindow.pref;
 
405
    for( var language in dataObject.languageData )
 
406
      {
 
407
        for( var type in dataObject.languageData[language].types )
 
408
          {
 
409
            var fontPrefString = "font.name." + type + "." + language;
 
410
            var currValue = "";
 
411
            try
 
412
              {
 
413
                currValue = pref.getComplexValue( fontPrefString, Components.interfaces.nsISupportsString ).data;
 
414
              }
 
415
            catch(e)
 
416
              {
 
417
              }
 
418
 
 
419
            var dataValue = dataObject.languageData[language].types[type];
 
420
            if( currValue != dataValue )
 
421
              {
 
422
                if (dataValue)
 
423
                  {
 
424
                    parent.hPrefWindow.setPref( "string", fontPrefString, dataValue );
 
425
                  }
 
426
                else
 
427
                  {
 
428
                    // A font name can't be blank. The special blank means the default.
 
429
                    // Unset the pref entirely, letting Gfx to decide. GfxXft will use what
 
430
                    // Xft says, whereas GfxWin and others will use the built-in settings
 
431
                    // that are shipped for font.name and font.name-list.
 
432
                    try
 
433
                      {
 
434
                        // ClearUserPref throws an exception...
 
435
                        pref.clearUserPref( fontPrefString );
 
436
                      }
 
437
                    catch(e)
 
438
                      {
 
439
                      }
 
440
                  }
 
441
              }
 
442
          }
 
443
        var variableSizePref = "font.size.variable." + language;
 
444
        var fixedSizePref = "font.size.fixed." + language;
 
445
        var minSizePref = "font.minimum-size." + language;
 
446
        var currVariableSize = 12, currFixedSize = 12, minSizeVal = 0;
 
447
        try
 
448
          {
 
449
            currVariableSize = pref.getIntPref( variableSizePref );
 
450
            currFixedSize = pref.getIntPref( fixedSizePref );
 
451
            minSizeVal = pref.getIntPref( minSizePref );
 
452
          }
 
453
        catch(e)
 
454
          {
 
455
          }
 
456
        if( currVariableSize != dataObject.languageData[language].variableSize )
 
457
          pref.setIntPref( variableSizePref, dataObject.languageData[language].variableSize );
 
458
        if( currFixedSize != dataObject.languageData[language].fixedSize )
 
459
          pref.setIntPref( fixedSizePref, dataObject.languageData[language].fixedSize );
 
460
        if ( minSizeVal != dataObject.languageData[language].minSize ) {
 
461
          pref.setIntPref ( minSizePref, dataObject.languageData[language].minSize );
 
462
        }
 
463
      }
 
464
 
 
465
    // font scaling
 
466
    var fontDPI       = parseInt( dataObject.fontDPI );
 
467
    var documentFonts = dataObject.useDocFonts;
 
468
    var defaultFont   = dataObject.defaultFont;
 
469
 
 
470
    try
 
471
      {
 
472
        var currDPI = pref.getIntPref( "browser.display.screen_resolution" );
 
473
        var currFonts = pref.getIntPref( "browser.display.use_document_fonts" );
 
474
        var currDefault = pref.getComplexValue( "font.default", Components.interfaces.nsISupportsString ).data;
 
475
      }
 
476
    catch(e)
 
477
      {
 
478
      }
 
479
    if( currDPI != fontDPI )
 
480
      pref.setIntPref( "browser.display.screen_resolution", fontDPI );
 
481
    if( currFonts != documentFonts )
 
482
      pref.setIntPref( "browser.display.use_document_fonts", documentFonts );
 
483
    if( currDefault != defaultFont )
 
484
      {
 
485
        parent.hPrefWindow.setPref( "string", "font.default", defaultFont );
 
486
      }
 
487
  }
 
488
 
 
489
function saveState()
 
490
  {
 
491
    for( var i = 0; i < fontTypes.length; i++ )
 
492
      {
 
493
        // preliminary initialisation
 
494
        if( currentLanguage && !( currentLanguage in languageData ) )
 
495
          languageData[currentLanguage] = [];
 
496
        if( currentLanguage && !( "types" in languageData[currentLanguage] ) )
 
497
          languageData[currentLanguage].types = [];
 
498
        // save data for the previous language
 
499
        if( currentLanguage && currentLanguage in languageData &&
 
500
            "types" in languageData[currentLanguage] )
 
501
          languageData[currentLanguage].types[fontTypes[i]] = document.getElementById( fontTypes[i] ).value;
 
502
      }
 
503
 
 
504
    if( currentLanguage && currentLanguage in languageData &&
 
505
        "types" in languageData[currentLanguage] )
 
506
      {
 
507
        languageData[currentLanguage].variableSize = parseInt( variableSize.value );
 
508
        languageData[currentLanguage].fixedSize = parseInt( fixedSize.value );
 
509
        languageData[currentLanguage].minSize = parseInt( minSize.value );
 
510
      }
 
511
  }
 
512
 
 
513
// Selects size (or the nearest entry that exists in the list)
 
514
// in the menulist minSize
 
515
function minSizeSelect(size)
 
516
  {
 
517
    var items = minSize.getElementsByAttribute( "value", size );
 
518
    if (items.length > 0)
 
519
      minSize.selectedItem = items[0];
 
520
    else if (size < 6)
 
521
      minSizeSelect(6);
 
522
    else if (size > 24)
 
523
      minSizeSelect(24);
 
524
    else
 
525
      minSizeSelect(size - 1);
 
526
  }
 
527
 
 
528
function selectLanguage()
 
529
  {
 
530
    // save current state
 
531
    saveState();
 
532
 
 
533
    if( !currentLanguage )
 
534
      currentLanguage = languageList.value;
 
535
    else if( currentLanguage == languageList.value )
 
536
      return; // same as before, nothing changed
 
537
 
 
538
    // lazily populate the successive font lists at 100ms intervals.
 
539
    // (Note: the third parameter to setTimeout() is going to be
 
540
    // passed as argument to the callback function.)
 
541
    window.setTimeout(lazyAppendFontNames, 100, 0);
 
542
 
 
543
    // in the meantime, disable the menu lists
 
544
    for( var i = 0; i < fontTypes.length; i++ )
 
545
      {
 
546
        var listElement = document.getElementById( fontTypes[i] );
 
547
        listElement.setAttribute( "value", "" );
 
548
        listElement.setAttribute( "label", "" );
 
549
        listElement.setAttribute( "disabled", "true" );
 
550
      }
 
551
 
 
552
    // and set the font sizes
 
553
    try
 
554
      {
 
555
        var variableSizePref = "font.size.variable." + languageList.value;
 
556
        var sizeVarVal = parent.hPrefWindow.pref.getIntPref( variableSizePref );
 
557
        variableSize.selectedItem = variableSize.getElementsByAttribute( "value", sizeVarVal )[0];
 
558
 
 
559
        var fixedSizePref = "font.size.fixed." + languageList.value;
 
560
        var sizeFixedVal = parent.hPrefWindow.pref.getIntPref( fixedSizePref );
 
561
        fixedSize.selectedItem = fixedSize.getElementsByAttribute( "value", sizeFixedVal )[0];
 
562
      }
 
563
    catch(e) { } // font size lists can simply default to the first entry
 
564
 
 
565
    var minSizeVal = 0;
 
566
    try 
 
567
      {
 
568
        var minSizePref = "font.minimum-size." + languageList.value;
 
569
        minSizeVal = parent.hPrefWindow.pref.getIntPref( minSizePref );
 
570
      }
 
571
    catch(e) { }
 
572
    minSizeSelect( minSizeVal );
 
573
 
 
574
    currentLanguage = languageList.value;
 
575
  }
 
576
 
 
577
function changeScreenResolution()
 
578
  {
 
579
    var screenResolution = document.getElementById("screenResolution");
 
580
    var userResolution = document.getElementById("userResolution");
 
581
 
 
582
    var previousSelection = screenResolution.getElementsByAttribute("current", "true")[0];
 
583
 
 
584
    if (screenResolution.value == "other")
 
585
      {
 
586
        // If the user selects "Other..." we bring up the calibrate screen dialog
 
587
        var rv = { newdpi : 0 };
 
588
        var calscreen = window.openDialog("chrome://communicator/content/pref/pref-calibrate-screen.xul", 
 
589
                                      "_blank", 
 
590
                                      "modal,chrome,centerscreen,resizable=no,titlebar",
 
591
                                      rv);
 
592
        if (rv.newdpi != -1) 
 
593
          {
 
594
            // They have entered values, and we have a DPI value back
 
595
            var dpi = screenResolution.getAttribute( "dpi" );
 
596
            setResolution ( rv.newdpi );
 
597
 
 
598
            previousSelection.removeAttribute("current");
 
599
            screenResolution.selectedItem.setAttribute("current", "true");
 
600
          }
 
601
        else
 
602
          {
 
603
            // They've cancelled. We can't leave "Other..." selected, so...
 
604
            // we re-select the previously selected item.
 
605
            screenResolution.selectedItem = previousSelection;
 
606
          }
 
607
      }
 
608
    else if (!(screenResolution.value == userResolution.value))
 
609
      {
 
610
        // User has selected one of the hard-coded resolutions
 
611
        userResolution.setAttribute("hidden", "true");
 
612
 
 
613
        previousSelection.removeAttribute("current");
 
614
        screenResolution.selectedItem.setAttribute("current", "true");
 
615
      }
 
616
  }
 
617
 
 
618
function setResolution( resolution )
 
619
  {
 
620
    // Given a number, if it's equal to a hard-coded resolution we use that,
 
621
    // otherwise we set the userResolution field.
 
622
    var screenResolution = document.getElementById( "screenResolution" );
 
623
    var userResolution = document.getElementById( "userResolution" );
 
624
 
 
625
    var items = screenResolution.getElementsByAttribute( "value", resolution );
 
626
    if (items.length)
 
627
      {
 
628
        // If it's one of the hard-coded values, we'll select it directly 
 
629
        screenResolution.selectedItem = items[0];
 
630
        userResolution.setAttribute( "hidden", "true" );
 
631
      }   
 
632
    else
 
633
      {
 
634
        // Otherwise we need to set up the userResolution field
 
635
        var dpi = screenResolution.getAttribute( "dpi" );
 
636
        userResolution.setAttribute( "value", resolution );
 
637
        userResolution.setAttribute( "label", dpi.replace(/\$val/, resolution) );
 
638
        userResolution.removeAttribute( "hidden" );
 
639
        screenResolution.selectedItem = userResolution;   
 
640
      }
 
641
  }
 
642
  
 
643
// "Calibrate screen" dialog code
 
644
 
 
645
function Init()
 
646
  {
 
647
      sizeToContent();
 
648
      doSetOKCancel(onOK, onCancel);
 
649
      document.getElementById("horizSize").focus();
 
650
  }
 
651
  
 
652
function onOK()
 
653
  {
 
654
    // Get value from the dialog to work out dpi
 
655
    var horizSize = parseFloat(document.getElementById("horizSize").value);
 
656
    var units = document.getElementById("units").value;
 
657
  
 
658
    if (!horizSize || horizSize < 0)
 
659
      {
 
660
        // We can't calculate anything without a proper value
 
661
        window.arguments[0].newdpi = -1;
 
662
        return true;
 
663
      }
 
664
      
 
665
    // Convert centimetres to inches.
 
666
    // The magic number is allowed because it's a fundamental constant :-)
 
667
    if (units === "centimetres")
 
668
      {
 
669
        horizSize /= 2.54;
 
670
      }
 
671
  
 
672
    // These shouldn't change, but you can't be too careful.
 
673
    var horizBarLengthPx = document.getElementById("horizRuler").boxObject.width;
 
674
  
 
675
    var horizDPI = parseInt(horizBarLengthPx) / horizSize;
 
676
  
 
677
    // Average the two <shrug>.
 
678
    window.arguments[0].newdpi = Math.round(horizDPI);
 
679
  
 
680
    return true;
 
681
  }
 
682
 
 
683
function onCancel()
 
684
  {
 
685
      // We return -1 to show that no value has been given.
 
686
      window.arguments[0].newdpi = -1;
 
687
      return true;
 
688
  }
 
689
 
 
690
// disable font items, but not the browserUseDocumentFonts checkbox nor the resolution
 
691
// menulist
 
692
function disableAllFontElements()
 
693
  {
 
694
      var doc_ids = [ "selectLangs", "proportionalFont",
 
695
                      "sizeVar", "serif", "sans-serif",
 
696
                      "cursive", "fantasy", "monospace",
 
697
                      "sizeMono", "minSize" ];
 
698
      for (i=0; i<doc_ids.length; i++) {
 
699
          element = document.getElementById( doc_ids[i] );
 
700
          element.disabled = true;
 
701
      }
 
702
  }
 
703