/* ----------------------------------------------------------------------------- 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 ----------------------------------------------------------------------------- */ struct TablePlugit = [ TBP_inst : PInstance, TBP_posstr : InterfacePos, TBP_contstr : VUIcontainer, TBP_tablestr : VUITable, TBP_lthemeelts : [S r1], TBP_bUseTheme : I, TBP_tTableSize : [I I], TBP_tMargins : [I I], TBP_iCellColor : I, TBP_iBorder : I, TBP_iBorderColor : I, TBP_font : VUIfont, TBP_iTextAlignFlag : I, TBP_values : tab tab S, TBP_cwidths : tab I, TBP_iColIndex : I, TBP_iRowIndex : I, TBP_bShow : I ]mkTablePlugit;; fun deleteOb(inst, obstr)= VUIdestroyContainer obstr.TBP_contstr; VUIdelFont obstr.TBP_font; 0;; fun setTableText(obstr, row, col, text)= let obstr.TBP_tTableSize -> [x y] in let if text == nil then "" else text -> text in if ((row < 0) ||(row >= y) || (col < 0) || (col >= x)) then nil else ( set obstr.TBP_values.(row).(col) = text; VUIsetTableCellText obstr.TBP_tablestr col row text; );; fun getTableText(obstr, row, col)= let obstr.TBP_tTableSize -> [x y] in if ((row < 0) ||(row >= y) || (col < 0) || (col >= x)) then nil else obstr.TBP_values.(row).(col);; fun getTableParam(param)= let strextr param -> lp in let hd lp -> pp in let if ((atoi (hd pp)) == nil) then 0 else (atoi (hd pp)) -> row in let if ((atoi (hd tl pp)) == nil) then 0 else (atoi (hd tl pp)) -> col in let strbuildn (tl tl pp)::(tl lp) -> p in [row col p];; fun getTableIndexParam(param)= let strextr param -> lp in let hd lp -> pp in let if ((atoi (hd pp)) == nil) then 0 else (atoi (hd pp)) -> index in let strbuildn (tl pp)::(tl lp) -> p in [index p];; fun cbHide(inst, from, action, param, reply, obstr)= VUIshowContainer obstr.TBP_contstr 0; SendPluginEvent inst "Hidden" nil nil; 0;; fun cbShow(inst, from, action, param, reply, obstr)= VUIshowContainer obstr.TBP_contstr 1; if (obstr.TBP_posstr.IP_iMode != 3) then nil else let obstr.TBP_posstr.IP_posvrstr -> posvrstr in VUIrefreshVrContainerPosition c3dXsession obstr.TBP_contstr posvrstr.IPVR_tSize posvrstr.IPVR_fScale posvrstr.IPVR_iZorder; SendPluginEvent inst "Shown" nil nil; 0;; fun cbSetCellContent(inst, from, action, param, reply, obstr)= let getTableParam param -> [row col text] in ( setTableText obstr row col text; ); 0;; fun cbGetCellContent(inst, from, action, param, reply, obstr)= let getTableParam param -> [row col _] in let getTableText obstr row col -> text in SendPluginEvent inst "Cell content" (strcatn (itoa row)::" "::(itoa col)::" "::text::nil) nil; 0;; fun cbSetNextRow(inst, from, action, param, reply, obstr)= let obstr.TBP_tTableSize -> [x y] in let if (param == nil) || (!strcmp param "") then let "" -> str in ( let 0 -> t in while (t < x) do ( set str = strcat str ";"; set t = t + 1; ); str ) else param -> param in set obstr.TBP_values = readCSVdataToTabRow param nil obstr.TBP_iRowIndex obstr.TBP_values y x; VUIsetTable obstr.TBP_tablestr obstr.TBP_values; set obstr.TBP_iRowIndex = obstr.TBP_iRowIndex + 1; 0;; fun cbSetRow(inst, from, action, param, reply, obstr)= if (param == nil) || (!strcmp param "") then nil else ( let obstr.TBP_tTableSize -> [x y] in let getTableIndexParam param -> [index param] in set obstr.TBP_values = readCSVdataToTabRow param nil index obstr.TBP_values y x; VUIsetTable obstr.TBP_tablestr obstr.TBP_values; ); 0;; fun cbSetNextColumn(inst, from, action, param, reply, obstr)= let obstr.TBP_tTableSize -> [x y] in let if (param == nil) || (!strcmp param "") then let "" -> str in ( let 0 -> t in while (t < y) do ( set str = strcat str ";\n"; set t = t + 1; ); str ) else param -> param in set obstr.TBP_values = readCSVdataToTabColumn param nil obstr.TBP_iColIndex obstr.TBP_values y x; VUIsetTable obstr.TBP_tablestr obstr.TBP_values; set obstr.TBP_iColIndex = obstr.TBP_iColIndex + 1; 0;; fun cbSetColumn(inst, from, action, param, reply, obstr)= if (param == nil) || (!strcmp param "") then nil else ( let obstr.TBP_tTableSize -> [x y] in let getTableIndexParam param -> [index param] in set obstr.TBP_values = readCSVdataToTabColumn param nil index obstr.TBP_values y x; VUIsetTable obstr.TBP_tablestr obstr.TBP_values; ); 0;; fun cbSetTable(inst, from, action, param, reply, obstr)= let obstr.TBP_tTableSize -> [x y] in let readCSVdataToTabSized param nil y x -> data in ( set obstr.TBP_values = data; VUIsetTable obstr.TBP_tablestr data; ); 0;; fun cbGetTable(inst, from, action, param, reply, obstr)= let obstr.TBP_tTableSize -> [x y] in SendPluginEvent inst "Table" (formatCSV nil nil (readCSVTabToData obstr.TBP_values y x)) nil; 0;; fun cbTableModified(tablestr, cellstr, x, y, content, obstr)= SendPluginEvent obstr.TBP_inst "Modified" (strcatnSep (itoa y)::(itoa x)::content::nil " ") nil; 0;; fun createTable(inst, obstr)= set obstr.TBP_contstr = crInterfacePosContainer inst obstr.TBP_posstr c3dXsession; let obstr.TBP_tTableSize -> [x y] in ( if (obstr.TBP_bUseTheme) then ( set obstr.TBP_tablestr = VUIcreateTableExt obstr.TBP_contstr nil [0.0 0.0] [100.0 100.0] [0 0 1 1 0 0 0 0] [0 0] obstr.TBP_tMargins obstr.TBP_tTableSize obstr.TBP_cwidths nil obstr.TBP_iTextAlignFlag (hd obstr.TBP_lthemeelts); 0; ) else ( set obstr.TBP_tablestr = VUIcreateTable obstr.TBP_contstr nil [0.0 0.0] [100.0 100.0] [0 0 1 1 0 0 0 0] [0 0] obstr.TBP_tMargins obstr.TBP_tTableSize obstr.TBP_cwidths obstr.TBP_font obstr.TBP_iTextAlignFlag; VUIsetTableResource obstr.TBP_tablestr obstr.TBP_iCellColor obstr.TBP_iBorder obstr.TBP_iBorderColor nil nil; 0; ); VUIsetTable obstr.TBP_tablestr obstr.TBP_values; VUIsetTableCbChange obstr.TBP_tablestr mkfun6 @cbTableModified obstr; ); 0;; fun getHalign(mode)= if (mode == 1) then iVUITEXT_HALIGNCENTER else if (mode == 2) then iVUITEXT_HALIGNRIGHT else iVUITEXT_HALIGNLEFT;; fun getValign(mode)= if (mode == 1) then iVUITEXT_VALIGNCENTER else if (mode == 2) then iVUITEXT_VALIGNBOTTOM else iVUITEXT_VALIGNTOP;; fun getWidthsTab(nbcol, colwidths)= let mktab nbcol 0 -> widthstab in let strToListSep colwidths ";" -> wlist in let 0 -> i in ( while (i < nbcol && wlist != nil) do ( set widthstab.(i) = atoi (nth_list wlist i); set i = i + 1; ); widthstab; );; fun newOb(inst)= let loadInterfacePos inst c3dXsession -> posstr in let atoi (getPluginInstanceParam inst "nbrow") -> nbrow in let if (nbrow == nil) then 3 else nbrow -> nbrow in let atoi (getPluginInstanceParam inst "nbcol") -> nbcol in let if (nbcol == nil) then 4 else nbcol -> nbcol in let atoi (getPluginInstanceParam inst "xmargin") -> xmargin in let if (xmargin == nil) then 5 else xmargin -> xmargin in let atoi (getPluginInstanceParam inst "ymargin") -> ymargin in let if (ymargin == nil) then 5 else ymargin -> ymargin in let atoi (getPluginInstanceParam inst "texthalign") -> texthalign in let if (texthalign == nil) then 1 else texthalign -> texthalign in let atoi (getPluginInstanceParam inst "textvalign") -> textvalign in let if (textvalign == nil) then 1 else textvalign -> textvalign in let atoi (getPluginInstanceParam inst "usetheme") -> usetheme in let if (usetheme == nil) then 0 else usetheme -> usetheme in let loadThemeEltSelectorValues inst "common/tableCell"::nil -> lthemeelts in let atoi (getPluginInstanceParam inst "ccolor") -> ccolor in let if ccolor == nil then 0xffffffff else ccolor -> ccolor in let atoi (getPluginInstanceParam inst "border") -> border in let if (border == nil) then 1 else border -> border in let atoi (getPluginInstanceParam inst "bcolor") -> bcolor in let if bcolor == nil then 0x000000ff else bcolor -> bcolor in let getPluginInstanceParam inst "fontname" -> fontname in let if fontname == nil then "Sans" else fontname -> fontname in let atoi (getPluginInstanceParam inst "fontsize") -> fontsize in let if fontsize == nil then 10 else fontsize -> fontsize in let atoi (getPluginInstanceParam inst "fontcolor") -> fontcolor in let if fontcolor == nil then 0x000000 else fontcolor -> fontcolor in let atoi (getPluginInstanceParam inst "show") -> show in let if (show == nil) then 1 else show -> show in let (getPluginInstanceParam inst "colwidths") -> colwidths in let if colwidths == nil then nil else colwidths -> colwidths in let (getPluginInstanceParam inst "value") -> value in let if value == nil then nil else value -> value in let VUIcreateFont fontname fontsize 0 fontcolor 1 -> font in let (getHalign texthalign) | (getValign textvalign) -> textalignflag in let getWidthsTab nbcol colwidths -> widthstab in let readCSVdataToTabSized value nil nbrow nbcol -> data in let mkTablePlugit [inst posstr nil nil lthemeelts usetheme [nbcol nbrow] [xmargin ymargin] ccolor border bcolor font textalignflag data widthstab 0 0 0] -> obstr in ( createTable inst obstr; if !show then nil else cbShow inst nil nil nil nil obstr; PluginRegisterAction inst "Show" mkfun6 @cbShow obstr; PluginRegisterAction inst "Hide" mkfun6 @cbHide obstr; PluginRegisterAction inst "Set cell content" mkfun6 @cbSetCellContent obstr; PluginRegisterAction inst "Get cell content" mkfun6 @cbGetCellContent obstr; PluginRegisterAction inst "Set next row" mkfun6 @cbSetNextRow obstr; PluginRegisterAction inst "Set row" mkfun6 @cbSetRow obstr; PluginRegisterAction inst "Set next column" mkfun6 @cbSetNextColumn obstr; PluginRegisterAction inst "Set column" mkfun6 @cbSetColumn obstr; PluginRegisterAction inst "Set table" mkfun6 @cbSetTable obstr; PluginRegisterAction inst "Get table" mkfun6 @cbGetTable obstr; setPluginInstanceCbDel inst mkfun2 @deleteOb obstr; ); 0;; fun IniPlug(file)= VUIsetEnable c3dXsession 1; PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;