home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 July & August / PCWorld_2005-07-08_cd.bin / komunikace / netscape / nsb-install-8-0.exe / chrome / browser.jar / content / browser / setWallpaper.xul < prev    next >
Extensible Markup Language  |  2004-11-25  |  6KB  |  179 lines

  1. <?xml version="1.0"?> <!-- -*- Mode: HTML -*- --> 
  2.  
  3.  
  4. <?xml-stylesheet href="chrome://global/skin/" type="text/css"?> 
  5. <?xml-stylesheet href="chrome://browser/content/browser.css" type="text/css"?>
  6.  
  7. <!DOCTYPE dialog SYSTEM "chrome://browser/locale/setWallpaper.dtd">
  8.  
  9. <dialog xmlns:html="http://www.w3.org/1999/xhtml"
  10.         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  11.         id="aboutDialog"
  12.         buttons="accept,cancel"
  13.         buttonlabelaccept="&setWallpaper.title;"
  14.         onload="onLoad();"
  15.         ondialogaccept="onAccept();"
  16.         title="&setWallpaper.title;"
  17.         style="width: 299px"> 
  18.     
  19.     <stringbundle id="bundle_wallpaper" src="chrome://browser/locale/browser.properties"/>
  20.     <script type="application/x-javascript" src="chrome://browser/content/utilityOverlay.js"/>
  21.  
  22.     <script type="application/x-javascript">
  23.       <![CDATA[
  24.         const xulNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
  25.         const ISS = Components.interfaces.nsIShellService;
  26.  
  27.         var gPosition = ISS.BACKGROUND_STRETCH;
  28.         var gMonitor;
  29.         var gWidth, gHeight, gBackgroundColor = 0;
  30.  
  31.         function HexToR(h) { return parseInt((cutHex(h)).substring(0,2),16) }
  32.         function HexToG(h) { return parseInt((cutHex(h)).substring(2,4),16) }
  33.         function HexToB(h) { return parseInt((cutHex(h)).substring(4,6),16) }
  34.         function cutHex(h) { return (h.charAt(0)=="#") ? h.substring(1,7) : h}
  35.  
  36.         function RGBToHex(r, g, b)
  37.         {
  38.           var rHex = r.toString(16).toUpperCase();
  39.           var gHex = g.toString(16).toUpperCase();
  40.           var bHex = b.toString(16).toUpperCase();
  41.  
  42.           if (rHex.length == 1) rHex ='0' + rHex;
  43.           if (gHex.length == 1) gHex ='0' + gHex;
  44.           if (bHex.length == 1) bHex ='0' + bHex;
  45.  
  46.           return '#' + rHex + gHex + bHex;
  47.         }       
  48.         
  49.        function onLoad()
  50.        {
  51.          gMonitor = document.getElementById("monitor");
  52.          gWidth = window.arguments[0].width;
  53.          gHeight = window.arguments[0].height;
  54.          
  55.          initColor();                  
  56.          updatePosition(parseInt(document.getElementById("menuPosition").value));
  57.         }
  58.         
  59.         function initColor()
  60.         {
  61.           var color = 0;
  62.           var shell = getShellService();
  63.           if (shell)
  64.             color = shell.desktopBackgroundColor;
  65.  
  66.           const rMask = 4294901760;
  67.           const gMask = 65280;
  68.           const bMask = 255;
  69.           var r = (color & rMask) >> 16;
  70.           var g = (color & gMask) >> 8;
  71.           var b = (color & bMask);
  72.           gBackgroundColor = RGBToHex(r, g, b);
  73.           
  74.           var colorpicker = document.getElementById("desktopColor");
  75.           colorpicker.color = RGBToHex(r, g, b);
  76.         }
  77.         
  78.         function createImage()
  79.         {
  80.           var img = document.createElementNS(xulNS, "image");
  81.           img.setAttribute("src", window.arguments[0].src);
  82.           return img;
  83.         }
  84.         
  85.         function stretchImage()
  86.         {  
  87.           updateColor(gBackgroundColor);
  88.           
  89.           var img = createImage();
  90.           img.width = parseInt(gMonitor.style.width);
  91.           img.height = parseInt(gMonitor.style.height);
  92.           gMonitor.appendChild(img);
  93.         }
  94.         
  95.         function tileImage()
  96.         {
  97.           gMonitor.style.backgroundColor = 'white';
  98.           var bundle = document.getElementById("bundle_wallpaper");
  99.           var previewStr = bundle.getString("WallpaperNoPreview");
  100.           
  101.           var text = document.createElementNS(xulNS, "label");
  102.           text.setAttribute("id", "noPreviewAvailable");
  103.           text.setAttribute("value", previewStr);
  104.           gMonitor.appendChild(text);
  105.         }
  106.         
  107.         function centerImage()
  108.         {
  109.           updateColor(gBackgroundColor);
  110.                    
  111.           var img = createImage();
  112.           var width = gWidth*gMonitor.boxObject.width/screen.width;
  113.           var height = gHeight*gMonitor.boxObject.height/screen.height;
  114.           img.width = Math.floor(width);
  115.           img.height = Math.floor(height);
  116.           gMonitor.appendChild(img);
  117.         }
  118.           
  119.         function onAccept() 
  120.         {
  121.           var r = HexToR(gBackgroundColor);
  122.           var g = HexToG(gBackgroundColor);
  123.           var b = HexToB(gBackgroundColor);
  124.  
  125.           var shell = getShellService();
  126.           if (shell) {
  127.             shell.setDesktopBackground(window.arguments[0], gPosition);
  128.             shell.desktopBackgroundColor = (r << 16) | (g << 8) | b;
  129.             document.persist("menuPosition", "value");
  130.           }
  131.         }
  132.         
  133.         function updateColor(color)
  134.         {
  135.           gBackgroundColor = color;
  136.           
  137.           if (gPosition != ISS.BACKGROUND_TILE)
  138.             gMonitor.style.backgroundColor = color;
  139.         }
  140.         
  141.         function updatePosition(position)
  142.         {
  143.           if (gMonitor.childNodes.length)
  144.             gMonitor.removeChild(gMonitor.firstChild);
  145.             
  146.           gPosition = position;
  147.           if (gPosition == ISS.BACKGROUND_TILE)
  148.             tileImage();
  149.           else if (gPosition == ISS.BACKGROUND_STRETCH)
  150.             stretchImage();
  151.           else
  152.             centerImage();
  153.         }
  154.       ]]>
  155.     </script>
  156.  
  157.     <hbox align="center" id="foo">
  158.       <label value="&position.label;"/>
  159.       <menulist id="menuPosition" label="&position.label;" oncommand="updatePosition(parseInt(this.value));">
  160.         <menupopup>
  161.           <menuitem label="¢er.label;"  value="2"/>
  162.           <menuitem label="&tile.label;"    value="0"/>
  163.           <menuitem label="&stretch.label;" value="1"/>
  164.         </menupopup>
  165.       </menulist>
  166.       <spacer flex="1"/>
  167.       <label value="&color.label;"/>
  168.       <colorpicker type="button" id="desktopColor" onchange="updateColor(this.color);"/> 
  169.     </hbox>
  170.     <groupbox align="center">
  171.       <caption label="&preview.label;"/>
  172.       <stack>
  173.         <vbox id="monitor" align="center" pack="center"
  174.               style="width: 153px !important; height: 114px !important; overflow: hidden;"
  175.               left="13" top="18"/>
  176.         <image src="chrome://browser/content/monitor.png"/>
  177.       </stack>
  178.     </groupbox>
  179. </dialog>