{==============================================================================

  Copyright (C) 2000-2001 by Evgeny Kryukov
  All rights reserved

  All contents of this file and all other files included in this archive
  are Copyright (C) 2001 Evgeny Kryukov. Use and/or distribution of
  them requires acceptance of the License Agreement.

  See License.txt for licence information

===============================================================================}

unit EpIIMenuForm;

{$I EpIIVer.Inc}
{$T-,W-,X+,P+}

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, ExtCtrls,
  KsBitmap, KsControls, KsForms, KsItems, KsMenuForm, EpIIItems, EpIIStyles;

type

{ TEpPopupForm }

  TEpPopupForm = class(TKsPopupForm)
  private
  protected
    function GetClientRect: TRect; override;
    procedure PaintNCArea(Buffer: TKsBitmap); override;
    procedure PaintClientArea(Buffer: TKsBitmap); override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  end;

{ TEpPopupWindow class }

  TEpPopupWindow = class(TKsPopupWindow)
  private
    FBackground: TEpBackground;
    FBorder: TepBorder;
    procedure SetBackground(const Value: TEpBackground);
    procedure SetBorder(const Value: TepBorder);
  protected
    class function GetFormClass: TKsPopupFormClass; override;
  public
    constructor CreatePopupWindow(AOwner: TComponent; AItems: TKsCustomItem;
      AParentView: TKsItemView); override;
    destructor Destroy; override;

    property Background: TEpBackground read FBackground write SetBackground;
    property Border: TepBorder read FBorder write SetBorder;
  end;

implementation {===============================================================}

uses KsMenus;

{ TEpPopupForm ================================================================}

constructor TEpPopupForm.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
end;

destructor TEpPopupForm.Destroy;
begin
  inherited;
end;

function TEpPopupForm.GetClientRect: TRect;
begin
  if (PopupWindow <> nil) then
    with TEpPopupWindow(PopupWindow) do
    begin
      if Border <> nil then
        Result := Rect(Border.GetWidth, Border.GetHeight, FWidth-Border.GetWidth,
          FHeight-Border.GetHeight)
      else
        Result := inherited GetClientRect;
    end
  else
    Result := inherited GetClientRect;
end;

procedure TEpPopupForm.PaintClientArea(Buffer: TKsBitmap);
begin
  if (PopupWindow <> nil) then
    with TEpPopupWindow(PopupWindow) do
    begin
      if Background <> nil then
        Background.Draw(Buffer, Rect(0, 0, FWidth, FHeight));
        
      inherited PaintClientArea(Buffer);
    end
  else
    inherited PaintClientArea(Buffer);
end;

procedure TEpPopupForm.PaintNCArea(Buffer: TKsBitmap);
begin
  if (PopupWindow <> nil) then
    with TEpPopupWindow(PopupWindow) do
    begin
      if Border <> nil then
        Border.Draw(Buffer, Rect(0, 0, FWidth, FHeight), 0)
      else
        inherited PaintNCArea(Buffer);
    end
  else
    inherited PaintNCArea(Buffer);
end;

{ TEpPopupWindow ===============================================================}

constructor TEpPopupWindow.CreatePopupWindow(AOwner: TComponent;
  AItems: TKsCustomItem; AParentView: TKsItemView);
begin
  inherited CreatePopupWindow(AOwner, AItems, AParentView);

  if AItems <> nil then
  begin
    Background := TEpItem(AItems).PopupBackground;
    Border := TEpItem(AItems).PopupBorder;
  end;
end;

destructor TEpPopupWindow.Destroy;
begin
  inherited Destroy;
end;

class function TEpPopupWindow.GetFormClass: TKsPopupFormClass;
begin
  Result := TEpPopupForm;
end;

procedure TEpPopupWindow.SetBackground(const Value: TEpBackground);
begin
  FBackground := Value;
end;

procedure TEpPopupWindow.SetBorder(const Value: TepBorder);
begin
  FBorder := Value;
end;

end.
