-- Experimental widget showing a square shape with controlled background color. module Main where import DOMHelper import Language.JSMW import BrownPLT.JavaScript import Foreign.WebIDL.Dom.Text import Foreign.WebIDL.Dom.Node import Foreign.WebIDL.Dom.Document import Foreign.WebIDL.Dom.Element import Foreign.WebIDL.Html2.HTMLDivElement import Foreign.WebIDL.Dom.Document instance JContainer THTMLDivElement instance CNode This main = writeFiles "." itf impl = IFaceImpl "ColorSquare" parent = argument "parent" TNode "a parent node for the DIV element" color = argument "color" "String" "a background color to set" size = argument "size" "String" "size of the square in CSS units" doc = argument "doc" TDocument "a document where the DIV element is created" setc = method "setColor" setColor "set background color" `withArg` color `withArg` this `returning` "this object updated" initdiv = method "initDiv" initd "create a DIV element to control the color of" `withArg` doc `withArg` this `returning` "this object updated" setsize = method "setSize" setSize "set horizontal and vertical size of the DIV element" `withArg` size `withArg` this `returning` "this object updated" `jdoctopic` ("see", "Cascading Style Sheets") insert = method "insert" insrt "insert the DIV element into a parent node" `withArg` parent `withArg` this `returning` "no value" coldiv = attribute "colorDiv" THTMLDivElement ro "the DIV element to control" itf = defInterface impl `withMethod` setc `withMethod` initdiv `withMethod` setsize `withMethod` insert `withPrivate` coldiv setColor :: Expression String -> Expression This -> MRet This setColor str this = do mydiv <- attrGet coldiv this inside mydiv $ do setStyle ["background-color" := str] return this initd :: Expression TDocument -> Expression This -> MRet This initd doc this = do dv <- mkDiv doc attrSet coldiv dv this setSize :: Expression String -> Expression This -> MRet This setSize str this = do mydiv <- attrGet coldiv this inside mydiv $ do setStyle ["height" := str ,"width" := str] return this insrt :: Expression TNode -> Expression This -> MRet Void insrt parent this = addChild this parent >>=once >> return unit