home *** CD-ROM | disk | FTP | other *** search
/ PC World 2006 December / PCWorld_2006-12_cd.bin / komunikace / netscape / nsb-install-8-1-2.exe / chrome / browser.jar / content / browser / setWallpaper.xul < prev    next >
Extensible Markup Language  |  2006-01-06  |  7KB  |  191 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.     <script type="application/x-javascript" src="chrome://browser/content/contentAreaUtils.js"/>
  22.  
  23.     <script type="application/x-javascript">
  24.       <![CDATA[
  25.         const xulNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
  26.         const ISS = Components.interfaces.nsIShellService;
  27.  
  28.         var gPosition = ISS.BACKGROUND_STRETCH;
  29.         var gMonitor;
  30.         var gWidth, gHeight, gBackgroundColor = 0;
  31.  
  32.         function HexToR(h) { return parseInt((cutHex(h)).substring(0,2),16) }
  33.         function HexToG(h) { return parseInt((cutHex(h)).substring(2,4),16) }
  34.         function HexToB(h) { return parseInt((cutHex(h)).substring(4,6),16) }
  35.         function cutHex(h) { return (h.charAt(0)=="#") ? h.substring(1,7) : h}
  36.  
  37.         function RGBToHex(r, g, b)
  38.         {
  39.           var rHex = r.toString(16).toUpperCase();
  40.           var gHex = g.toString(16).toUpperCase();
  41.           var bHex = b.toString(16).toUpperCase();
  42.  
  43.           if (rHex.length == 1) rHex ='0' + rHex;
  44.           if (gHex.length == 1) gHex ='0' + gHex;
  45.           if (bHex.length == 1) bHex ='0' + bHex;
  46.  
  47.           return '#' + rHex + gHex + bHex;
  48.         }       
  49.         
  50.        function onLoad()
  51.        {
  52.          gMonitor = document.getElementById("monitor");
  53.          gWidth = window.arguments[0].width;
  54.          gHeight = window.arguments[0].height;
  55.          
  56.          initColor();                  
  57.          updatePosition(parseInt(document.getElementById("menuPosition").value));
  58.         }
  59.         
  60.         function initColor()
  61.         {
  62.           var color = 0;
  63.           var shell = getShellService();
  64.           if (shell)
  65.             color = shell.desktopBackgroundColor;
  66.  
  67.           const rMask = 4294901760;
  68.           const gMask = 65280;
  69.           const bMask = 255;
  70.           var r = (color & rMask) >> 16;
  71.           var g = (color & gMask) >> 8;
  72.           var b = (color & bMask);
  73.           gBackgroundColor = RGBToHex(r, g, b);
  74.           
  75.           var colorpicker = document.getElementById("desktopColor");
  76.           colorpicker.color = RGBToHex(r, g, b);
  77.         }
  78.         
  79.         function createImage()
  80.         {
  81.           var img = document.createElementNS(xulNS, "image");
  82.           const nsIImageLoadingContent = Components.interfaces.nsIImageLoadingContent;
  83.           if (window.arguments[0] instanceof nsIImageLoadingContent) {
  84.             var request = window.arguments[0].QueryInterface(nsIImageLoadingContent)
  85.                                 .getRequest(nsIImageLoadingContent.CURRENT_REQUEST);
  86.             if (!request)
  87.               return false;
  88.           }
  89.           
  90.           if (makeURL(window.arguments[0].src).scheme == "javascript")
  91.             return false;
  92.           
  93.           img.setAttribute("src", window.arguments[0].src);
  94.           return img;
  95.         }
  96.         
  97.         function stretchImage()
  98.         {  
  99.           updateColor(gBackgroundColor);
  100.           
  101.           var img = createImage();
  102.           img.width = parseInt(gMonitor.style.width);
  103.           img.height = parseInt(gMonitor.style.height);
  104.           gMonitor.appendChild(img);
  105.         }
  106.         
  107.         function tileImage()
  108.         {
  109.           gMonitor.style.backgroundColor = 'white';
  110.           var bundle = document.getElementById("bundle_wallpaper");
  111.           var previewStr = bundle.getString("WallpaperNoPreview");
  112.           
  113.           var text = document.createElementNS(xulNS, "label");
  114.           text.setAttribute("id", "noPreviewAvailable");
  115.           text.setAttribute("value", previewStr);
  116.           gMonitor.appendChild(text);
  117.         }
  118.         
  119.         function centerImage()
  120.         {
  121.           updateColor(gBackgroundColor);
  122.                    
  123.           var img = createImage();
  124.           var width = gWidth*gMonitor.boxObject.width/screen.width;
  125.           var height = gHeight*gMonitor.boxObject.height/screen.height;
  126.           img.width = Math.floor(width);
  127.           img.height = Math.floor(height);
  128.           gMonitor.appendChild(img);
  129.         }
  130.           
  131.         function onAccept() 
  132.         {
  133.           var r = HexToR(gBackgroundColor);
  134.           var g = HexToG(gBackgroundColor);
  135.           var b = HexToB(gBackgroundColor);
  136.  
  137.           var shell = getShellService();
  138.           if (shell) {
  139.             shell.setDesktopBackground(window.arguments[0], gPosition);
  140.             shell.desktopBackgroundColor = (r << 16) | (g << 8) | b;
  141.             document.persist("menuPosition", "value");
  142.           }
  143.         }
  144.         
  145.         function updateColor(color)
  146.         {
  147.           gBackgroundColor = color;
  148.           
  149.           if (gPosition != ISS.BACKGROUND_TILE)
  150.             gMonitor.style.backgroundColor = color;
  151.         }
  152.         
  153.         function updatePosition(position)
  154.         {
  155.           if (gMonitor.childNodes.length)
  156.             gMonitor.removeChild(gMonitor.firstChild);
  157.             
  158.           gPosition = position;
  159.           if (gPosition == ISS.BACKGROUND_TILE)
  160.             tileImage();
  161.           else if (gPosition == ISS.BACKGROUND_STRETCH)
  162.             stretchImage();
  163.           else
  164.             centerImage();
  165.         }
  166.       ]]>
  167.     </script>
  168.  
  169.     <hbox align="center" id="foo">
  170.       <label value="&position.label;"/>
  171.       <menulist id="menuPosition" label="&position.label;" oncommand="updatePosition(parseInt(this.value));">
  172.         <menupopup>
  173.           <menuitem label="¢er.label;"  value="2"/>
  174.           <menuitem label="&tile.label;"    value="0"/>
  175.           <menuitem label="&stretch.label;" value="1"/>
  176.         </menupopup>
  177.       </menulist>
  178.       <spacer flex="1"/>
  179.       <label value="&color.label;"/>
  180.       <colorpicker type="button" id="desktopColor" onchange="updateColor(this.color);"/> 
  181.     </hbox>
  182.     <groupbox align="center">
  183.       <caption label="&preview.label;"/>
  184.       <stack>
  185.         <vbox id="monitor" align="center" pack="center"
  186.               style="width: 153px !important; height: 114px !important; overflow: hidden;"
  187.               left="13" top="18"/>
  188.         <image src="chrome://browser/content/monitor.png"/>
  189.       </stack>
  190.     </groupbox>
  191. </dialog>