# K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)

# ---------- Zoom Functionality ------------------------------------------------------------------------------------
#
# Dependencies	: main.kmm ($macroPrefBranch, JS)
# Resources	: -
# Preferences	: kmeleon.plugins.macros.zoom
#
# ------------------------------------------------------------------------------------------------------------------

Zoom_In{
macroinfo=_("Perform the Zoom In button action");
$__data=getpref(STRING,$_Zoom_Pref);
$__data=="text"?id(ID_FONT_INCREASE):($__data=="page"?&Zoom_Page_In:($__data=="images"?&Zoom_Images_In:0));
}
Zoom_Out{
macroinfo=_("Perform the Zoom Out button action");
$__data=getpref(STRING,$_Zoom_Pref);
$__data=="text"?id(ID_FONT_DECREASE):($__data=="page"?&Zoom_Page_Out:($__data=="images"?&Zoom_Images_Out:0));
}

Zoom_Page_In{
macroinfo=_("Zoom into the current page");
id(ID_FULLZOOM_INCREASE);
}
Zoom_Page_Out{
macroinfo=_("Zoom out of the current page");
id(ID_FULLZOOM_DECREASE);
}

Zoom_Images_In{
macroinfo=_("Increase image size");
$_Zoom_By="1"; &_Zoom_Images;
}
Zoom_Images_Out{
macroinfo=_("Decrease image size");
$_Zoom_By="-1"; &_Zoom_Images;
}

Zoom_Image_In{
macroinfo=_("Increase the size of the current image");
$_Zoom_By="2"; &_Zoom_Image;
}
Zoom_Image_Out{
macroinfo=_("Decrease the size of the current image");
$_Zoom_By="1/2"; &_Zoom_Image;
}

Zoom_Page{
macroinfo=_("Let zoom buttons effect text and images");
menuchecked=(getpref(STRING,$_Zoom_Pref)=="page");
$_default="page"; $_tip=_("Zoom buttons effect text and images."); &_Zoom_Set;
}
Zoom_Text{
macroinfo=_("Let zoom buttons effect text only");
menuchecked=(getpref(STRING,$_Zoom_Pref)=="text");
$_default="text"; $_tip=_("Zoom buttons effect text only."); &_Zoom_Set;
}
Zoom_Images{
macroinfo=_("Let zoom buttons effect images only");
menuchecked=(getpref(STRING,$_Zoom_Pref)=="images");
$_default="images"; $_tip=_("Zoom buttons effect images only."); &_Zoom_Set;
}

# ----- PRIVATE

$_Zoom_Pref=$macroPrefBranch."zoom";

_Zoom_Image{
$_Zoom_doitImg="if(getAttribute('zoom')==null){setAttribute('initW',width);setAttribute('initH',height);setAttribute('zoom',1)}var iz=".$_Zoom_By.";setAttribute('zoom',getAttribute('zoom')*iz);iz=getAttribute('zoom');width=bz*iz*getAttribute('initW');height=bz*iz*getAttribute('initH')"; &_Zoom_hndlImage;
}
_Zoom_Images{
$_Zoom_doitImg="var iz=(getAttribute('zoom')==null)?1:getAttribute('zoom');if(getAttribute('initW')==null){setAttribute('initW',width);setAttribute('initH',height)}width=bz*iz*getAttribute('initW');height=bz*iz*getAttribute('initH')"; &_Zoom_hndlImages;
}
_Zoom_Text{
$JS_doit="var b=getElementsByTagName('body')[0];if(b)zoomNode(b,(10+".$_Zoom_By.")/10);"; $JS_func="function zoomNode(n,z){for(var j=0;j<n.childNodes.length;j++)if(n.childNodes[j].nodeType==1)zoomNode(n.childNodes[j],z);var lh=getComputedStyle(n,'').getPropertyValue('line-height');if(lh!='normal')n.style.lineHeight=Math.round(parseFloat(lh.replace(/px/,''))*z)+'px';n.style.fontSize=Math.round(parseFloat(getComputedStyle(n,'').getPropertyValue('font-size').replace(/px/,''))*z)+'px'}"; &JS_hndlDocs;
}
_Zoom_hndlImage{
$JS_doit="var b=getElementsByTagName('body')[0];if(b){var bz=(b.getAttribute('zoom')==null)?1:(b.getAttribute('zoom')/10);for(var j=0,i=images;j<i.length;j++)with(i[j])if(urlencode(src)=='".urlencode($ImageURL)."'){".$_Zoom_doitImg."}}"; &JS_hndlDoc;
}
_Zoom_hndlImages{
$JS_doit="var b=getElementsByTagName('body')[0];if(b){if(b.getAttribute('zoom')==null)b.setAttribute('zoom',10);var bz=".$_Zoom_By.",o=parseFloat(b.getAttribute('zoom'));if(Math.round(bz+o)){b.setAttribute('zoom',Math.round(bz+o));bz=b.getAttribute('zoom')/10;for(var j=0,i=images;j<i.length;j++)with(i[j]){".$_Zoom_doitImg."}}}"; &JS_hndlDocs;
}

_Zoom_Set{
setpref(STRING,$_Zoom_Pref,$_default); statusbar($_tip);
}
_Zoom_SetDefaults{
getpref(STRING,$_Zoom_Pref)==""?setpref(STRING,$_Zoom_Pref,"text"):0;
}
$OnStartup=$OnStartup."_Zoom_SetDefaults;";

_Zoom_BuildMenu{
# view menu
setmenu(PageDisplay,popup,"&Zoom",ID_FONT_INCREASE);
setmenu(PageDisplay,command,"",ID_FONT_INCREASE);
setmenu(PageDisplay,command,"",ID_FONT_DECREASE);
setmenu("&Zoom",inline,__Zoom_In);
setmenu(__Zoom_In,macro,"Zoom In &Page",Zoom_Page_In);
setmenu(__Zoom_In,command,"Zoom In &Text",ID_FONT_INCREASE);
setmenu(__Zoom_In,macro,"Zoom In &Images",Zoom_Images_In);
setmenu("&Zoom",inline,__Zoom_Out);
setmenu(__Zoom_Out,macro,"Zoom Out P&age",Zoom_Page_Out);
setmenu(__Zoom_Out,command,"Zoom Out T&ext",ID_FONT_DECREASE);
setmenu(__Zoom_Out,macro,"Zoom Out I&mages",Zoom_Images_Out);
$kToolbars?&_Zoom_BuildButtonMenu:0;
# context menus
setmenu(ImageView,macro,"Zoom I&n",Zoom_Image_In);
setmenu(ImageView,macro,"Zoom Ou&t",Zoom_Image_Out);
}
_Zoom_BuildButtonMenu{
# zoom buttons
setmenu("&Zoom",inline,__Zoom_Btn);
setmenu(__Zoom_Btn,popup,"Zoom &Buttons");
setmenu("Zoom &Buttons",macro,"Zoom Full &Page",Zoom_Page);
setmenu("Zoom &Buttons",macro,"Zoom &Text Only",Zoom_Text);
setmenu("Zoom &Buttons",macro,"Zoom &Images Only",Zoom_Images);
setmenu(_Zoom_In,inline,__Zoom_In);
setmenu(_Zoom_In,inline,__Zoom_Btn);
setmenu(_Zoom_Out,inline,__Zoom_Out);
setmenu(_Zoom_Out,inline,__Zoom_Btn);
}
_Zoom_SetAccels{
setaccel("ALT VK_PLUS","macros(Zoom_Images_In)");
setaccel("ALT VK_ADD","macros(Zoom_Images_In)");
setaccel("ALT VK_MINUS","macros(Zoom_Images_Out)");
setaccel("ALT VK_SUBTRACT","macros(Zoom_Images_Out)");
setaccel("CTRL ALT VK_PLUS","ID_FONT_INCREASE");
setaccel("CTRL ALT VK_ADD","ID_FONT_INCREASE");
setaccel("CTRL ALT VK_MINUS","ID_FONT_DECREASE");
setaccel("CTRL ALT VK_SUBTRACT","ID_FONT_DECREASE");
}
$OnInit=$OnInit."_Zoom_SetAccels;_Zoom_BuildMenu;";

# ------------------------------------------------------------------------------------------------------------------
$macroModules=$macroModules."Zoom;";