{-# LANGUAGE ForeignFunctionInterface, TypeFamilies, MultiParamTypeClasses, 
             FlexibleInstances, TypeSynonymInstances, EmptyDataDecls, 
             OverlappingInstances, IncoherentInstances #-}

module HROOT.Class.TText.Implementation where


import HROOT.TypeCast

import HROOT.Class.TText.RawType
import HROOT.Class.TText.FFI
import HROOT.Class.TText.Interface
import HROOT.Class.TText.Cast
import HROOT.Class.TClass.RawType
import HROOT.Class.TClass.Cast
import HROOT.Class.TClass.Interface
import HROOT.Class.TNamed.RawType
import HROOT.Class.TNamed.Cast
import HROOT.Class.TNamed.Interface
import HROOT.Class.TAttText.RawType
import HROOT.Class.TAttText.Cast
import HROOT.Class.TAttText.Interface
import HROOT.Class.TObject.RawType
import HROOT.Class.TObject.Cast
import HROOT.Class.TObject.Interface
import HROOT.Class.Deletable.RawType
import HROOT.Class.Deletable.Cast
import HROOT.Class.Deletable.Interface

import Data.Word
-- import Foreign.C            
-- import Foreign.Ptr
import Foreign.ForeignPtr

import System.IO.Unsafe


instance ITText TText where
  drawText = xform3 c_ttext_drawtext
  drawTextNDC = xform3 c_ttext_drawtextndc
  getControlBox = xform5 c_ttext_getcontrolbox
  setText = xform3 c_ttext_settext
instance ITNamed TText where
  setName = xform1 c_ttext_setname
  setNameTitle = xform2 c_ttext_setnametitle
  setTitle = xform1 c_ttext_settitle
instance ITAttText TText where
  getTextAlign = xform0 c_ttext_gettextalign
  getTextAngle = xform0 c_ttext_gettextangle
  getTextColor = xform0 c_ttext_gettextcolor
  getTextFont = xform0 c_ttext_gettextfont
  getTextSize = xform0 c_ttext_gettextsize
  resetAttText = xform1 c_ttext_resetatttext
  setTextAttributes = xform0 c_ttext_settextattributes
  setTextAlign = xform1 c_ttext_settextalign
  setTextAngle = xform1 c_ttext_settextangle
  setTextColor = xform1 c_ttext_settextcolor
  setTextFont = xform1 c_ttext_settextfont
  setTextSize = xform1 c_ttext_settextsize
  setTextSizePixels = xform1 c_ttext_settextsizepixels
instance ITObject TText where
  draw = xform1 c_ttext_draw
  findObject = xform1 c_ttext_findobject
  getName = xform0 c_ttext_getname
  isA = xform0 c_ttext_isa
  isFolder = xform0 c_ttext_isfolder
  isEqual = xform1 c_ttext_isequal
  isSortable = xform0 c_ttext_issortable
  paint = xform1 c_ttext_paint
  printObj = xform1 c_ttext_printobj
  recursiveRemove = xform1 c_ttext_recursiveremove
  saveAs = xform2 c_ttext_saveas
  useCurrentStyle = xform0 c_ttext_usecurrentstyle
  write = xform3 c_ttext_write
instance IDeletable TText where
  delete = xform0 c_ttext_delete

instance ITText (Exist TText) where
  drawText (ETText x) = drawText x
  drawTextNDC (ETText x) = drawTextNDC x
  getControlBox (ETText x) = getControlBox x
  setText (ETText x) = setText x
instance ITNamed (Exist TText) where
  setName (ETText x) = setName x
  setNameTitle (ETText x) = setNameTitle x
  setTitle (ETText x) = setTitle x
instance ITAttText (Exist TText) where
  getTextAlign (ETText x) = getTextAlign x
  getTextAngle (ETText x) = getTextAngle x
  getTextColor (ETText x) = getTextColor x
  getTextFont (ETText x) = getTextFont x
  getTextSize (ETText x) = getTextSize x
  resetAttText (ETText x) = resetAttText x
  setTextAttributes (ETText x) = setTextAttributes x
  setTextAlign (ETText x) = setTextAlign x
  setTextAngle (ETText x) = setTextAngle x
  setTextColor (ETText x) = setTextColor x
  setTextFont (ETText x) = setTextFont x
  setTextSize (ETText x) = setTextSize x
  setTextSizePixels (ETText x) = setTextSizePixels x
instance ITObject (Exist TText) where
  draw (ETText x) = draw x
  findObject (ETText x) = findObject x
  getName (ETText x) = getName x
  isA (ETText x) = isA x
  isFolder (ETText x) = isFolder x
  isEqual (ETText x) = isEqual x
  isSortable (ETText x) = isSortable x
  paint (ETText x) = paint x
  printObj (ETText x) = printObj x
  recursiveRemove (ETText x) = recursiveRemove x
  saveAs (ETText x) = saveAs x
  useCurrentStyle (ETText x) = useCurrentStyle x
  write (ETText x) = write x
instance IDeletable (Exist TText) where
  delete (ETText x) = delete x


newTText :: Double -> Double -> String -> IO TText
newTText = xform2 c_ttext_newttext



instance FPtr (Exist TText) where
  type Raw (Exist TText) = RawTText
  get_fptr (ETText obj) = castForeignPtr (get_fptr obj)
  cast_fptr_to_obj fptr = ETText (cast_fptr_to_obj (fptr :: ForeignPtr RawTText) :: TText)