+function callBookmark(evtarget) {
+}
+
+function saveBookmark() {
+ // retrieve wanted bookmark name with a prompt
+ var mbrotBundle = document.getElementById("mbrotBundle");
+ var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
+ .getService(Components.interfaces.nsIPromptService);
+ var input = {value: ""}; // empty default value
+ var ok = prompts.prompt(null, "XXX Title", "XXX Please enter a name for the bookmark", input, null, {});
+ // ok is true if OK is pressed, false if Cancel. input.value holds the value of the edit field if "OK" was pressed.
+ if (!ok || !input.value)
+ return
+
+ var bmName = input.value;
+
+ // Open or create the bookmarks database.
+ var file = Components.classes["@mozilla.org/file/directory_service;1"]
+ .getService(Components.interfaces.nsIProperties)
+ .get("ProfD", Components.interfaces.nsIFile);
+ file.append("mandelbookmarks.sqlite");
+ var connection = Components.classes["@mozilla.org/storage/service;1"]
+ .getService(Components.interfaces.mozIStorageService)
+ .openDatabase(file);
+ connection.beginTransaction();
+ if (!connection.tableExists("bookmarks"))
+ connection.createTable("bookmarks", "name TEXT, iteration_max INTEGER, Cr_min REAL, Cr_max REAL, Ci_min REAL, Ci_max REAL");
+ // NULL. The value is a NULL value.
+ // INTEGER. The value is a signed integer, stored in 1, 2, 3, 4, 6, or 8 bytes depending on the magnitude of the value.
+ // REAL. The value is a floating point value, stored as an 8-byte IEEE floating point number.
+ // TEXT. The value is a text string, stored using the database encoding (UTF-8, UTF-16BE or UTF-16-LE).
+
+ // Put value of the current image into the bookmarks table
+ var statement = connection.createStatement(
+ "INSERT INTO bookmarks (name,iteration_max,Cr_min,Cr_max,Ci_min,Ci_max) VALUES (?1,?2,?3,?4,?5,?6)");
+ statement.bindStringParameter(0, bmName);
+ statement.bindStringParameter(1, gPref.getIntPref("mandelbrot.iteration_max"));
+ statement.bindStringParameter(2, parseFloat(gPref.getCharPref("mandelbrot.last_image.Cr_min")));
+ statement.bindStringParameter(3, parseFloat(gPref.getCharPref("mandelbrot.last_image.Cr_max")));
+ statement.bindStringParameter(4, parseFloat(gPref.getCharPref("mandelbrot.last_image.Ci_min")));
+ statement.bindStringParameter(5, parseFloat(gPref.getCharPref("mandelbrot.last_image.Ci_max")));
+ statement.execute();
+ statement.finalize();
+ connection.commitTransaction();
+ connection.close();
+}
+
+function updateIterMenu() {
+ try {
+ var currentIter = gPref.getIntPref("mandelbrot.iteration_max");
+ }
+ catch(e) {
+ var currentIter = 0;
+ }
+ if (currentIter < 10) {
+ currentIter = 500;
+ setIter(currentIter);
+ }
+
+ var popup = document.getElementById("menu_iterPopup");
+ var item = popup.firstChild;
+ while (item) {
+ if (item.getAttribute("name") == "iter") {
+ if (item.getAttribute("value") == currentIter)
+ item.setAttribute("checked","true");
+ else
+ item.removeAttribute("checked");
+ }
+ item = item.nextSibling;
+ }
+}
+
+function setIter(aIter) {
+ gPref.setIntPref("mandelbrot.iteration_max", aIter);
+}
+
+function updatePaletteMenu() {
+ try {
+ var currentPalette = gPref.getCharPref("mandelbrot.color_palette");
+ }
+ catch(e) {
+ var currentPalette = '';
+ }
+ if (!currentPalette.length) {
+ currentPalette = 'kairo';
+ setPalette(currentPalette);
+ }
+ if (!gColorPalette || !gColorPalette.length)
+ gColorPalette = getColorPalette(currentPalette);
+
+ var popup = document.getElementById("menu_palettePopup");
+ var item = popup.firstChild;
+ while (item) {
+ if (item.getAttribute("name") == "palette") {
+ if (item.getAttribute("value") == currentPalette)
+ item.setAttribute("checked", "true");
+ else
+ item.removeAttribute("checked");
+ }
+ item = item.nextSibling;
+ }
+}
+
+function setPalette(aPaletteID) {
+ gPref.setCharPref("mandelbrot.color_palette", aPaletteID);
+ gColorPalette = getColorPalette(aPaletteID);
+}
+
+function imgSettings() {
+ window.openDialog("chrome://mandelbrot/content/image-settings.xul");
+}
+
+function updateDebugMenu() {
+ var jitMenuItem = document.getElementById("jitEnabled");
+ jitMenuItem.setAttribute("checked", gPref.getBoolPref("javascript.options.jit.chrome"));
+}
+
+function toggleJITState(jitMenuItem) {
+ var jitEnabled = !gPref.getBoolPref("javascript.options.jit.chrome");
+ gPref.setBoolPref("javascript.options.jit.chrome", jitEnabled)
+ jitMenuItem.setAttribute("checked", jitEnabled? "true" : "false");
+}
+
+function updateAlgoMenu() {
+ try {
+ var currentAlgo = gPref.getCharPref("mandelbrot.use_algorithm");
+ }
+ catch(e) {
+ var currentAlgo = '';
+ }
+ if (!currentAlgo.length) {
+ currentAlgo = 'numeric';
+ setAlgorithm(currentAlgo);
+ }
+
+ var popup = document.getElementById("menu_algoPopup");
+ var item = popup.firstChild;
+ while (item) {
+ if (item.getAttribute("name") == "algorithm") {
+ if (item.getAttribute("value") == currentAlgo)
+ item.setAttribute("checked", "true");
+ else
+ item.removeAttribute("checked");
+ }
+ item = item.nextSibling;
+ }
+}
+
+function setAlgorithm(algoID) {
+ gPref.setCharPref("mandelbrot.use_algorithm", algoID);
+}
+
+function addonsManager(aPane) {
+ var theEM = Components.classes["@mozilla.org/appshell/window-mediator;1"]
+ .getService(Components.interfaces.nsIWindowMediator)
+ .getMostRecentWindow("Extension:Manager");
+ if (theEM) {
+ theEM.focus();
+ if (aPane)
+ theEM.showView(aPane);
+ return;
+ }
+
+ const EMURL = "chrome://mozapps/content/extensions/extensions.xul";
+ const EMFEATURES = "all,dialog=no";
+ if (aPane)
+ window.openDialog(EMURL, "", EMFEATURES, aPane);
+ else
+ window.openDialog(EMURL, "", EMFEATURES);
+}
+
+function errorConsole() {
+ toOpenWindowByType("global:console", "chrome://global/content/console.xul");
+}
+
+/***** helper functions from external sources *****/
+
+// function below is based on http://developer.mozilla.org/en/docs/Code_snippets:Canvas
+// custom modifications:
+// - use "a"-prefix on function arguments
+// - take an nsILocalFile as aDestFile argument
+// - always do silent download
+function saveCanvas(aCanvas, aDestFile) {