{***************************************************************************}
{ TMS IntraWeb Component Pack Pro                                           }
{ for Delphi & C++Builder                                                   }
{                                                                           }
{ written by TMS Software                                                   }
{            copyright © 2002 - 2011                                        }
{            Email : info@tmssoftware.com                                   }
{            Web : http://www.tmssoftware.com                               }
{                                                                           }
{ The source code is given as is. The author is not responsible             }
{ for any possible damage done due to the use of this code.                 }
{ The component can be freely used in any application. The complete         }
{ source code remains property of the author and may not be distributed,    }
{ published, given or sold in any form as such. No parts of the source      }
{ code can be included in any other component or application without        }
{ written authorization of the author.                                      }
{***************************************************************************}

unit IWAdvRegion;

interface

{$I TMSDEFS.INC}

uses
  Controls, Graphics,
  {$IFDEF DELPHI6_LVL}
  Types,
  {$ENDIF}
  Classes,
  {$IFDEF TMSIW51}
  IWBaseControl, IWColor, IWRegion, IWContainerBorderOptions,
  {$ENDIF}
  IWControl, IWTypes, SysUtils,
  IWCompLabel, IWHTMLTag,
  IWTMSBase, IWFont,
  {$IFDEF TMSIW6}
  IWRenderContext
  {$ENDIF}
  ;

type

 TTIWAdvRegion = class(TIWRegion)
  private
    FCaption: string;
    FColorDirection: TTIWGradientDirection;
    FColorTo: TIWColor;

    procedure SetCaption(const Value: string);
    procedure SetColorDirection(const Value: TTIWGradientDirection);
    procedure SetColorTo(const Value: TIWColor);
  protected
    procedure Paint; override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    function RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag; override;
  published
    property Caption : string read FCaption write SetCaption;
    property ColorDirection : TTIWGradientDirection read FColorDirection write SetColorDirection default gdVertical;
    property ColorTo : TIWColor read FColorTo write SetColorTo default clNone;
  end;

implementation

uses
  IWServer;

{ TTIWAdvRegion }

constructor TTIWAdvRegion.Create(AOwner: TComponent);
begin
  FCaption := EmptyStr;
//  Color := clNone;
  FColorDirection := gdVertical;
  FColorTo := clNone;
  inherited;
end;

destructor TTIWAdvRegion.Destroy;
begin
  inherited;
end;


procedure TTIWAdvRegion.Paint;
var
 r: Trect;
begin
  inherited;
  r := GetClientRect;

  with Canvas do
  begin

    r.Left := 0;
    r.Top := 0;
    r.Right := Width;
    r.Bottom := Height;

    if ColorTo = clNone then
      DrawGradient(Canvas,Color,Color,80,r,False)
    else
      DrawGradient(Canvas,Color,ColorTo,80,r,False);

    Brush.Style := bsClear;

    if Caption <> EmptyStr then
      TextOut(0,0,Caption);
  end;
end;

function TTIWAdvRegion.RenderHTML(AContext: TIWBaseComponentContext): TIWHTMLTag;
var
 html, style: string;
begin
//  BorderOptions.NumericWidth := 0;
//  BorderOptions.Style := cbsNone;

  html := '';

  html := html + '<script>'#13
  + 'function ' + HTMLName + 'Toggle()'#13
  + '{'#13
//  + '  document.getElementById("' + HTMLName + '").style.display = "none";'#13
  + '  document.getElementById("' + HTMLName + '").style.visibility = "hidden";'#13
  + '  document.getElementById("' + HTMLName + 'Caption").style.display = "";'#13
//  + '  document.getElementById("' + HTMLName + 'Caption").style.visibility = "visible";'#13
  + '}'#13
  + '</script>'#13;

  html := html + '<div id="' + HTMLName + 'Caption" style="background-color:gold;width:100%;padding:3px;" onclick="' + HTMLName + 'Toggle();">test</div>';

  style := style + GradientStyle(Color, Color, ColorTo, clNone, ColorDirection, AContext, true);

//  Result := TIWHTMLTag.CreateTag('DIV');
  Result := inherited RenderHTML(AContext);

  Result.AddStringParam('style', Result.Params.Values['style'] + style);
  Result.Contents.AddText(html);

end;

procedure TTIWAdvRegion.SetCaption(const Value: string);
begin
  FCaption := Value;
  Invalidate;
end;

procedure TTIWAdvRegion.SetColorDirection(const Value: TTIWGradientDirection);
begin
  FColorDirection := Value;
  Invalidate;
end;

procedure TTIWAdvRegion.SetColorTo(const Value: TIWColor);
begin
  FColorTo := Value;
  Invalidate;
end;

end.
