/* ----------------------------------------------------------------------------- This source file is part of OpenSpace3D For the latest info, see http://www.openspace3d.com Copyright (c) 2012 I-maginer This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, or go to http://www.gnu.org/copyleft/lesser.txt ----------------------------------------------------------------------------- */ var iWidgetZIndex = 0;; struct PlugWebNavigatorWidget = [ WNW_instance : PInstance, WNW_bOnMaterial : I, WNW_bBackground : I, WNW_Object : SO3_OBJECT, WNW_Material : SO3_MATERIAL, WNW_iTechnique : I, WNW_iPass : I, WNW_iTexture : I, WNW_win : SO3_WIDGET, WNW_iScaleMode : I, WNW_iPosX : I, WNW_iPosY : I, WNW_iWidth : I, WNW_iHeight : I, WNW_tPercent : [I I I I I I I I], WNW_tAlign : [I I], WNW_bUrl : I, WNW_sPath : S, WNW_iZorder : I, WNW_bTransparency : I, WNW_iOpacity : I, WNW_iTextureQuality : I, WNW_bDraggable : I, WNW_bUpdateOnFocus : I, WNW_bFocusOnInit : I, WNW_bTopOnFocus : I, WNW_bAllwaysOnTop : I, WNW_bEnableKeyboard : I, WNW_bEnableMouse : I, WNW_bHide : I ]mkPlugWebNavigatorWidget;; fun cbSendMessage(inst, from, action, param, reply, constr)= let substr action ((strlen (getPluginInstanceName inst)) + 1) (strlen action) -> action in // send the full path if this is a file let _checkpack param -> pfile in let if pfile != nil then (strreplace (strreplace (_PtoS pfile) "\\" "/") " " "%20") else param -> param in let listQuote (strToList strtoutf8 param) "'" -> paraml in ( SO3WidgetCallFunction constr.WNW_win action paraml; ); 0;; fun cbGetMessage(widget, constr, message, args)= SendPluginEvent constr.WNW_instance message utf8tostr (listToString args) nil; 0;; fun cbGetMessageStr(navigator, constr, message, args)= "return SCOL";; fun cbShow(inst, from, action, param, reply, constr)= if (constr.WNW_win == nil) then nil else ( SO3WidgetSetVisibility constr.WNW_win 1; set constr.WNW_bHide = 0; SendPluginEvent constr.WNW_instance "Shown" nil nil; ); 0;; fun cbHide(inst, from, action, param, reply, constr)= if (constr.WNW_win == nil) then nil else ( SO3WidgetSetVisibility constr.WNW_win 0; set constr.WNW_bHide = 1; // force the last invisible cursor if (V3DgetCursorVisible (V3DgetSessionView c3dXsession)) then nil else V3DshowCursor (V3DgetSessionView c3dXsession) 0; SendPluginEvent constr.WNW_instance "Hidden" nil nil; ); 0;; fun cbChangeUrl(inst, from, action, param, reply, constr)= let strIsUrl param -> isurl in if param == nil then nil else ( set constr.WNW_bUrl = isurl; set constr.WNW_sPath = param; if constr.WNW_win == nil then nil else ( if !isurl then SO3WidgetLoadFile constr.WNW_win _checkpack param else ( let getHtmlCookie param -> cookie in ( if (cookie == nil) then nil else let decompHtmlCookie cookie -> [cval cpath cdomain secure httponly] in ( //addLogMessage strcatn "COOKIE : "::param::" > "::cval::nil; SO3WebNavigatorSetCookie param nil cval cdomain cpath secure httponly; ); ); SO3WidgetLoadUrl constr.WNW_win param; ); ); ); 0;; fun cbInjectHtml(inst, from, action, param, reply, constr)= SO3WebNavigatorWidgetLoadHTML constr.WNW_win (strtoutf8 param); 0;; fun computePosSize(constr, vw, vh)= let constr.WNW_tPercent -> [px py pw ph xo yo wo ho] in let constr.WNW_tAlign -> [ax ay] in let if pw then (ftoi (((itof constr.WNW_iWidth) /. 100.0) *. (itof vw))) + wo else constr.WNW_iWidth -> pw in let if ph then (ftoi (((itof constr.WNW_iHeight) /. 100.0) *. (itof vh))) + ho else constr.WNW_iHeight -> ph in let if px then (ftoi (((itof constr.WNW_iPosX) /. 100.0) *. (itof vw))) + xo else constr.WNW_iPosX -> px in let if (ax == 1) then ((vw / 2) - (pw / 2)) + px else if (ax == 2) then (vw - pw) - px else px -> px in let if py then (ftoi (((itof constr.WNW_iPosY) /. 100.0) *. (itof vh))) + yo else constr.WNW_iPosY -> py in let if (ay == 1) then ((vh / 2) - (ph / 2)) + py else if (ay == 2) then (vh - ph) - py else py -> py in [px py pw ph];; fun cbSetPosition(inst, from, action, param, reply, constr)= if param == nil then nil else let strextr param -> lp in let (nth_list (hd lp) 0) -> sx in let (nth_list (hd lp) 1) -> sy in let V3DgetSessionView c3dXsession -> viewstr in let V3DgetDefaultViewport viewstr -> viewportstr in let V3DgetViewportSize viewstr viewportstr -> [_ _ vw vh] in ( let 0 -> xpercent in let if (!strcmp "%" (substr sx ((strlen sx) - 1) 1)) then ( set xpercent = 1; atoi sx; ) else atoi sx -> px in let 0 -> ypercent in let if (!strcmp "%" (substr sy ((strlen sy) - 1) 1)) then ( set ypercent = 1; atoi sy; ) else atoi sy -> py in let [(if px == nil then 0 else px) (if py == nil then 0 else py)] -> [px py] in ( mutate constr.WNW_tPercent <- [xpercent ypercent _ _ _ _ _ _]; set constr.WNW_iPosX = px; set constr.WNW_iPosY = py; let computePosSize constr vw vh -> [px py pw ph] in ( SO3WidgetSetPosition constr.WNW_win px py; SO3WidgetSetSize constr.WNW_win pw ph; ); ); ); 0;; fun cbSetSize(inst, from, action, param, reply, constr)= if param == nil then nil else let strextr param -> lp in let (nth_list (hd lp) 0) -> sx in let (nth_list (hd lp) 1) -> sy in let V3DgetSessionView c3dXsession -> viewstr in let V3DgetDefaultViewport viewstr -> viewportstr in let V3DgetViewportSize viewstr viewportstr -> [_ _ vw vh] in ( let 0 -> wpercent in let if (!strcmp "%" (substr sx ((strlen sx) - 1) 1)) then ( set wpercent = 1; atoi sx; ) else atoi sx -> px in let 0 -> hpercent in let if (!strcmp "%" (substr sy ((strlen sy) - 1) 1)) then ( set hpercent = 1; atoi sy; ) else atoi sy -> py in let [(if px == nil then 0 else px) (if py == nil then 0 else py)] -> [px py] in ( mutate constr.WNW_tPercent <- [_ _ wpercent hpercent _ _ _ _]; set constr.WNW_iWidth = px; set constr.WNW_iHeight = py; let computePosSize constr vw vh -> [px py pw ph] in ( SO3WidgetSetPosition constr.WNW_win px py; SO3WidgetSetSize constr.WNW_win pw ph; ); ); ); 0;; fun cbResizeCtrl(inst, viewstr, vw, vh, constr)= if constr.WNW_win == nil || constr.WNW_bOnMaterial then nil else let V3DgetSessionView c3dXsession -> viewstr in let V3DgetDefaultViewport viewstr -> viewportstr in let V3DgetViewportSize viewstr viewportstr -> [_ _ vw vh] in let computePosSize constr vw vh -> [px py pw ph] in ( SO3WidgetSetPosition constr.WNW_win px py; SO3WidgetSetSize constr.WNW_win pw ph; ); 0;; fun cbOnPopup(navig, constr, x, y, w , h, url)= SO3WidgetLoadUrl constr.WNW_win url; 0;; fun cbOnLoadStart(navig, constr)= SendPluginEvent constr.WNW_instance "Page loading" nil nil; 0;; fun cbOnLoadEnd(navig, constr)= SendPluginEvent constr.WNW_instance "Page loaded" nil nil; 0;; fun cbOnLoadError(navig, constr, url)= SendPluginEvent constr.WNW_instance "Page load error: " url nil; 0;; fun cbOnAddressChange(navig, constr, frame, url)= SendPluginEvent constr.WNW_instance "Address changed" url nil; 0;; fun cbOnFocus(widget, constr, state)= if state then SendPluginEvent constr.WNW_instance "Focused" nil nil else SendPluginEvent constr.WNW_instance "Unfocused" nil nil; 0;; fun cbCreate(inst, from, action, param, reply, constr)= let V3DgetSessionView c3dXsession -> viewstr in let (V3DgetDefaultViewport viewstr) -> viewportstr in if constr.WNW_win != nil then nil else ( V3DremoveWidgetControl viewportstr constr.WNW_win; SO3WidgetDestroy constr.WNW_win; if constr.WNW_bOnMaterial then ( set constr.WNW_win = SO3WebNavigatorWidgetCreateOnMaterial (V3DgetSession c3dXsession) constr.WNW_Material strcat (getPluginInstanceName inst) "_webNavigatorWidget" constr.WNW_iWidth constr.WNW_iHeight constr.WNW_iTechnique constr.WNW_iPass constr.WNW_iTexture; 0; ) else if constr.WNW_bBackground then ( let V3DgetViewportSize viewstr viewportstr -> [_ _ vw vh] in let computePosSize constr vw vh -> [px py pw ph] in ( set constr.WNW_win = SO3WebNavigatorWidgetCreateBackground (V3DgetSession c3dXsession) viewportstr.V3D_viewport (strcat (getPluginInstanceName inst) "_webNavigatorWidget") px py pw ph; ); 0; ) else ( let constr.WNW_tAlign -> [ax ay] in let V3DgetViewportSize viewstr viewportstr -> [_ _ vw vh] in let computePosSize constr vw vh -> [px py pw ph] in ( set constr.WNW_win = SO3WebNavigatorWidgetCreate (V3DgetSession c3dXsession) viewportstr.V3D_viewport strcat (getPluginInstanceName inst) "_webNavigatorWidget" px py pw ph constr.WNW_iZorder; ); SO3WidgetSetTopOnFocus constr.WNW_win constr.WNW_bTopOnFocus; SO3WidgetSetForeground constr.WNW_win constr.WNW_bAllwaysOnTop; //SO3WidgetSetDraggable constr.WNW_win constr.WNW_bDraggable; ); V3DaddWidgetControl viewportstr constr.WNW_win; SO3WidgetSetTransparency constr.WNW_win constr.WNW_bTransparency; SO3WidgetSetKeyboardEnable constr.WNW_win constr.WNW_bEnableKeyboard; SO3WidgetSetMouseEnable constr.WNW_win constr.WNW_bEnableMouse; if !constr.WNW_bFocusOnInit then nil else SO3WidgetSetFocus constr.WNW_win; SO3WidgetSetOpacity constr.WNW_win (itof constr.WNW_iOpacity) *. 0.01; SO3WidgetSetTextureRatio constr.WNW_win (itof constr.WNW_iTextureQuality) *. 0.01; SO3WidgetSetUpdateOnFocusOnly constr.WNW_win constr.WNW_bUpdateOnFocus; SO3WidgetOnScriptEventCb constr.WNW_win @cbGetMessage constr; //SO3WidgetOnScriptEventCb constr.WNW_win @cbGetMessageStr constr; //SO3WidgetCbOnPopup constr.WNW_win @cbOnPopup constr; SO3WidgetOnLoadStartEventCb constr.WNW_win @cbOnLoadStart constr; SO3WidgetOnLoadEndEventCb constr.WNW_win @cbOnLoadEnd constr; SO3WidgetOnLoadErrorEventCb constr.WNW_win @cbOnLoadError constr; //SO3WidgetCbOnAddressChange constr.WNW_win @cbOnAddressChange constr; SO3WidgetFocusEventCb constr.WNW_win @cbOnFocus constr; SO3WidgetOnScriptEventCb constr.WNW_win @cbGetMessage constr; if (!constr.WNW_bUrl) then nil else let getHtmlCookie constr.WNW_sPath -> cookie in ( if (cookie == nil) then nil else let decompHtmlCookie cookie -> [cval cpath cdomain secure httponly] in ( //addLogMessage strcatn "COOKIE : "::param::" > "::cval::nil; SO3WebNavigatorSetCookie constr.WNW_sPath nil cval cdomain cpath secure httponly; ); ); if (constr.WNW_bUrl) then SO3WidgetLoadUrl constr.WNW_win constr.WNW_sPath else SO3WidgetLoadFile constr.WNW_win (_checkpack constr.WNW_sPath); if constr.WNW_bOnMaterial then nil else setPluginInstanceCbResizeView inst mkfun5 @cbResizeCtrl constr; if (constr.WNW_bHide) then cbHide inst from action param reply constr else cbShow inst from action param reply constr; ); 0;; fun cbDestroy(inst, from, action, param, reply, constr)= setPluginInstanceCbResizeView inst nil; V3DremoveWidgetControl (V3DgetDefaultViewport (V3DgetSessionView c3dXsession)) constr.WNW_win; SO3WidgetDestroy constr.WNW_win; set constr.WNW_win = nil; // force the last invisible cursor if (V3DgetCursorVisible (V3DgetSessionView c3dXsession)) then nil else V3DshowCursor (V3DgetSessionView c3dXsession) 0; 0;; fun cbSetOpacity(inst, from, action, param, reply, constr)= if param == nil then nil else ( SO3WidgetSetOpacity constr.WNW_win (atof param) *. 0.01; set constr.WNW_iOpacity = atoi param; ); 0;; fun cbSetTextureQuality(inst, from, action, param, reply, constr)= if param == nil then nil else ( SO3WidgetSetTextureRatio constr.WNW_win (atof param) *. 0.01; set constr.WNW_iTextureQuality = atoi param; ); 0;; fun cbReload(inst, from, action, param, reply, constr)= SO3WebNavigatorWidgetReload constr.WNW_win; 0;; fun cbZoomIn(inst, from, action, param, reply, constr)= //addLogMessage ftoa ((SO3WebNavigatorWidgetGetZoomLevel constr.WNW_win) -. 0.1); SO3WebNavigatorWidgetSetZoomLevel constr.WNW_win (SO3WebNavigatorWidgetGetZoomLevel constr.WNW_win) -. 0.1; 0;; fun cbZoomOut(inst, from, action, param, reply, constr)= //addLogMessage ftoa ((SO3WebNavigatorWidgetGetZoomLevel constr.WNW_win) +. 0.1); SO3WebNavigatorWidgetSetZoomLevel constr.WNW_win (SO3WebNavigatorWidgetGetZoomLevel constr.WNW_win) +. 0.1; 0;; fun cbSetZoom(inst, from, action, param, reply, constr)= if ((atof param) == nil) then nil else SO3WebNavigatorWidgetSetZoomLevel constr.WNW_win (atof param); 0;; fun cbGoBack(inst, from, action, param, reply, constr)= SO3WebNavigatorWidgetGoBack constr.WNW_win; 0;; fun cbGoForward(inst, from, action, param, reply, constr)= SO3WebNavigatorWidgetGoForward constr.WNW_win; 0;; fun cbOpenDevTools(inst, from, action, param, reply, constr)= SO3WebNavigatorWidgetShowDevTools constr.WNW_win; 0;; fun cbCloseDevTools(inst, from, action, param, reply, constr)= SO3WebNavigatorWidgetCloseDevTools constr.WNW_win; 0;; fun deleteOb(inst, constr)= cbDestroy inst nil nil nil nil constr; 0;; fun cbUnFocus(inst, from, action, param, reply, constr)= SO3WidgetUnFocus constr.WNW_win; // force the last invisible cursor if (V3DgetCursorVisible (V3DgetSessionView c3dXsession)) then nil else V3DshowCursor (V3DgetSessionView c3dXsession) 0; 0;; fun cbSetFocus(inst, from, action, param, reply, constr)= SO3WidgetSetFocus constr.WNW_win; 0;; fun newOb(inst)= let atoi (getPluginInstanceParam inst "istexture") -> istexture in let if istexture == nil then 0 else istexture -> istexture in let (getPluginInstanceParam inst "object") -> objname in let (getPluginInstanceParam inst "material") -> matname in let atoi (getPluginInstanceParam inst "technique") -> technique in let if technique == nil then 0 else technique -> technique in let atoi (getPluginInstanceParam inst "pass") -> pass in let if pass == nil then 0 else pass -> pass in let atoi (getPluginInstanceParam inst "texture") -> texture in let if texture == nil then 0 else texture -> texture in let (getPluginInstanceParam inst "path") -> path in let (getPluginInstanceParam inst "url") -> url in let atoi (getPluginInstanceParam inst "isurl") -> isurl in let atoi (getPluginInstanceParam inst "background") -> isbackground in let if (isbackground == nil) then 0 else isbackground -> isbackground in let atoi (getPluginInstanceParam inst "scalemode") -> scalemode in let if scalemode == nil then 0 else scalemode -> scalemode in let atoi (getPluginInstanceParam inst "posx") -> posx in let atoi (getPluginInstanceParam inst "posy") -> posy in let atoi (getPluginInstanceParam inst "width") -> width in let atoi (getPluginInstanceParam inst "height") -> height in let atoi (getPluginInstanceParam inst "xpercent") -> xpercent in let atoi (getPluginInstanceParam inst "ypercent") -> ypercent in let atoi (getPluginInstanceParam inst "wpercent") -> wpercent in let atoi (getPluginInstanceParam inst "hpercent") -> hpercent in let atoi (getPluginInstanceParam inst "xoffset") -> xoffset in let if xoffset == nil then 0 else xoffset -> xoffset in let atoi (getPluginInstanceParam inst "yoffset") -> yoffset in let if yoffset == nil then 0 else yoffset -> yoffset in let atoi (getPluginInstanceParam inst "woffset") -> woffset in let if woffset == nil then 0 else woffset -> woffset in let atoi (getPluginInstanceParam inst "hoffset") -> hoffset in let if hoffset == nil then 0 else hoffset -> hoffset in let atoi (getPluginInstanceParam inst "xalign") -> xalign in let atoi (getPluginInstanceParam inst "yalign") -> yalign in let atoi (getPluginInstanceParam inst "transparency") -> transparency in let atoi (getPluginInstanceParam inst "draggable") -> draggable in let atoi (getPluginInstanceParam inst "updateonfocus") -> updateonfocus in let if updateonfocus == nil then 0 else updateonfocus -> updateonfocus in let atoi (getPluginInstanceParam inst "focus") -> focus in let atoi (getPluginInstanceParam inst "toponfocus") -> toponfocus in let if toponfocus == nil then 1 else toponfocus -> toponfocus in let atoi (getPluginInstanceParam inst "allwaysontop") -> allwaysontop in let if allwaysontop == nil then 0 else allwaysontop -> allwaysontop in let atoi (getPluginInstanceParam inst "enablekeyboard") -> enablekeyboard in let if enablekeyboard == nil then 1 else enablekeyboard -> enablekeyboard in let atoi (getPluginInstanceParam inst "enablemouse") -> enablemouse in let if enablemouse == nil then 1 else enablemouse -> enablemouse in let atoi (getPluginInstanceParam inst "opacity") -> opacity in let atoi (getPluginInstanceParam inst "texturequality") -> texturequality in let atoi (getPluginInstanceParam inst "zorder") -> zorder in let if ((zorder == nil) || (zorder == 0)) then set iWidgetZIndex = iWidgetZIndex + 1 else (if zorder > iWidgetZIndex then set iWidgetZIndex = zorder else zorder) -> zorder in let atoi (getPluginInstanceParam inst "hide") -> hide in let if hide == nil then 0 else hide -> hide in let atoi (getPluginInstanceParam inst "init") -> oninit in let if !isurl then path else url -> file in let SO3SceneGetObject (V3DgetSession c3dXsession) objname -> obj in let if !istexture then nil else SO3SceneGetMaterial (V3DgetSession c3dXsession) (SO3EntityGetResourceGroup obj) matname -> mat in let mkPlugWebNavigatorWidget [inst istexture isbackground obj mat technique pass texture nil scalemode posx posy width height [xpercent ypercent wpercent hpercent xoffset yoffset woffset hoffset] [xalign yalign] isurl file zorder transparency opacity texturequality draggable updateonfocus focus toponfocus allwaysontop enablekeyboard enablemouse hide] -> constr in ( if !oninit then nil else cbCreate inst nil nil nil nil constr; let getPluginInstanceUserActions inst -> laction in let sizelist laction -> size in let 0 -> i in while i < size do ( let nth_list laction i -> act in PluginRegisterAction inst act mkfun6 @cbSendMessage constr; set i = i + 1; ); PluginRegisterAction inst "Show" mkfun6 @cbShow constr; PluginRegisterAction inst "Hide" mkfun6 @cbHide constr; PluginRegisterAction inst "Create" mkfun6 @cbCreate constr; PluginRegisterAction inst "Destroy" mkfun6 @cbDestroy constr; PluginRegisterAction inst "Set opacity" mkfun6 @cbSetOpacity constr; PluginRegisterAction inst "Set texture quality" mkfun6 @cbSetTextureQuality constr; PluginRegisterAction inst "Change url" mkfun6 @cbChangeUrl constr; PluginRegisterAction inst "Inject html" mkfun6 @cbInjectHtml constr; PluginRegisterAction inst "Set position" mkfun6 @cbSetPosition constr; PluginRegisterAction inst "Set size" mkfun6 @cbSetSize constr; PluginRegisterAction inst "Reload" mkfun6 @cbReload constr; PluginRegisterAction inst "Zoom In" mkfun6 @cbZoomIn constr; PluginRegisterAction inst "Zoom Out" mkfun6 @cbZoomOut constr; PluginRegisterAction inst "Set zoom" mkfun6 @cbSetZoom constr; PluginRegisterAction inst "Go back" mkfun6 @cbGoBack constr; PluginRegisterAction inst "Go forward" mkfun6 @cbGoForward constr; PluginRegisterAction inst "Open dev tools" mkfun6 @cbOpenDevTools constr; PluginRegisterAction inst "Close dev tools" mkfun6 @cbCloseDevTools constr; PluginRegisterAction inst "Release focus" mkfun6 @cbUnFocus constr; PluginRegisterAction inst "Set focus" mkfun6 @cbSetFocus constr; setPluginInstanceCbDel inst mkfun2 @deleteOb constr; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;