with GNATCOM.IInterface;

with GNATCOM.Errors;

package body MSHTML.IHTMLCanvasElement_Interface is

   procedure Initialize (This : in out IHTMLCanvasElement_Type) is
   begin
      Set_IID (This, IID_IHTMLCanvasElement);
   end Initialize;

   function Pointer (This : IHTMLCanvasElement_Type)
     return Pointer_To_IHTMLCanvasElement
   is
   begin
      return To_Pointer_To_IHTMLCanvasElement (Address (This));
   end Pointer;

   procedure Attach (This    : in out IHTMLCanvasElement_Type;
                     Pointer : in     Pointer_To_IHTMLCanvasElement)
   is
   begin
      Attach (This, GNATCOM.IInterface.To_Pointer_To_IUnknown
              (Pointer.all'Address));
   end Attach;

   procedure Put_width
     (This : IHTMLCanvasElement_Type;
      p    : Interfaces.C.long)
   is
   begin
      GNATCOM.Errors.Error_Check
        (Pointer (This).Vtbl.Put_width
         (Pointer (This),
          p));

   end Put_width;

   function Get_width
     (This : IHTMLCanvasElement_Type)
     return Interfaces.C.long
   is
       RetVal : aliased Interfaces.C.long;
   begin
      GNATCOM.Errors.Error_Check
        (Pointer (This).Vtbl.Get_width
         (Pointer (This),
          RetVal'Unchecked_Access));

      return RetVal;
   end Get_width;

   procedure Put_height
     (This : IHTMLCanvasElement_Type;
      p    : Interfaces.C.long)
   is
   begin
      GNATCOM.Errors.Error_Check
        (Pointer (This).Vtbl.Put_height
         (Pointer (This),
          p));

   end Put_height;

   function Get_height
     (This : IHTMLCanvasElement_Type)
     return Interfaces.C.long
   is
       RetVal : aliased Interfaces.C.long;
   begin
      GNATCOM.Errors.Error_Check
        (Pointer (This).Vtbl.Get_height
         (Pointer (This),
          RetVal'Unchecked_Access));

      return RetVal;
   end Get_height;

   function getContext
     (This      : IHTMLCanvasElement_Type;
      contextId : GNATCOM.Types.BSTR;
      Free      : Boolean := True)
     return Pointer_To_ICanvasRenderingContext2D
   is
       RetVal : aliased Pointer_To_ICanvasRenderingContext2D;
   begin
      GNATCOM.Errors.Error_Check
        (Pointer (This).Vtbl.getContext
         (Pointer (This),
          contextId,
          RetVal'Unchecked_Access));

      if Free then
               GNATCOM.IInterface.Free (contextId);
      
      end if;

      return RetVal;
   end getContext;

   function toDataURL
     (This        : IHTMLCanvasElement_Type;
      utype       : GNATCOM.Types.BSTR;
      jpegquality : GNATCOM.Types.VARIANT;
      Free        : Boolean := True)
     return GNATCOM.Types.BSTR
   is
       RetVal : aliased GNATCOM.Types.BSTR;
   begin
      GNATCOM.Errors.Error_Check
        (Pointer (This).Vtbl.toDataURL
         (Pointer (This),
          utype,
          jpegquality,
          RetVal'Unchecked_Access));

      if Free then
               GNATCOM.IInterface.Free (utype);
               GNATCOM.IInterface.Free (jpegquality);
      
      end if;

      return RetVal;
   end toDataURL;

end MSHTML.IHTMLCanvasElement_Interface;

