unit UnitForms;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 
  sSpinEdit, StdCtrls, sEdit, sCheckbox, sRadioButton, ExtCtrls, sPanel, sGroupBox, 
  sSkinProvider, sFrameAdapter, sComboBox, sButton;

type
  TFrameForms = class(TFrame)
    sGroupBox7: TsGroupBox;
    sRadioButton12: TsRadioButton;
    sRadioButton13: TsRadioButton;
    sRadioButton14: TsRadioButton;
    sRadioButton15: TsRadioButton;
    sRadioButton16: TsRadioButton;
    sRadioButton17: TsRadioButton;
    sButton1: TsButton;
    sGroupBox8: TsGroupBox;
    sCheckBox9: TsCheckBox;
    sCheckBox15: TsCheckBox;
    sCheckBox16: TsCheckBox;
    sCheckBox17: TsCheckBox;
    sGroupBox9: TsGroupBox;
    sRadioButton18: TsRadioButton;
    sRadioButton19: TsRadioButton;
    sRadioButton20: TsRadioButton;
    sCheckBox19: TsCheckBox;
    sCheckBox20: TsCheckBox;
    sEdit2: TsEdit;
    sSpinEdit4: TsSpinEdit;
    sFrameAdapter1: TsFrameAdapter;
    sCheckBox1: TsCheckBox;
    sComboBox1: TsComboBox;
    sCheckBox2: TsCheckBox;
    procedure sRadioButton12Click(Sender: TObject);
    procedure sRadioButton18Change(Sender: TObject);
    procedure sRadioButton19Change(Sender: TObject);
    procedure sRadioButton20Change(Sender: TObject);
    procedure sCheckBox19Change(Sender: TObject);
    procedure sButton1Click(Sender: TObject);
    procedure sCheckBox1Change(Sender: TObject);
    procedure sComboBox1Change(Sender: TObject);
  private
    { Private declarations }
  public
    procedure BtnMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure CloseBtnClick(Sender: TObject);
  end;

var
  bs : TFormBorderStyle = bsSizeable;
  bi : TBorderIcons = [biSystemMenu, biMinimize, biMaximize];

implementation

uses acntUtils, MainUnit, ImgList, math;

{$R *.DFM}

procedure TFrameForms.sRadioButton12Click(Sender: TObject);
begin
  if Sender = sRadioButton12 then bs := bsDialog else
  if Sender = sRadioButton13 then bs := bsNone else
  if Sender = sRadioButton14 then bs := bsSingle else
  if Sender = sRadioButton15 then bs := bsSizeable else
  if Sender = sRadioButton16 then bs := bsSizeToolWin else
  if Sender = sRadioButton17 then bs := bsToolWindow;
end;

procedure TFrameForms.sRadioButton18Change(Sender: TObject);
begin
  MainForm.sSkinProvider1.CaptionAlignment := taLeftJustify;
end;

procedure TFrameForms.sRadioButton19Change(Sender: TObject);
begin
  MainForm.sSkinProvider1.CaptionAlignment := taCenter;
end;

procedure TFrameForms.sRadioButton20Change(Sender: TObject);
begin
  MainForm.sSkinProvider1.CaptionAlignment := taRightJustify;
end;

procedure TFrameForms.sCheckBox19Change(Sender: TObject);
begin
  MainForm.sSkinProvider1.ShowAppIcon := sCheckBox19.Checked;
end;

procedure TFrameForms.sButton1Click(Sender: TObject);
var
  tf : TForm;
  sp : TsSkinProvider;
  btn : TsButton;
  i : integer;
begin
  Application.CreateForm(TForm, tf);
  tf.BorderStyle := bs;
  tf.Position := poScreenCenter;
  tf.Height := 200;
  tf.Caption := sEdit2.Text;
  tf.Constraints.MinWidth := Width;

  bi := [];
  if sCheckBox9.Checked  then bi := bi + [biSystemMenu];
  if sCheckBox15.Checked then bi := bi + [biMaximize];
  if sCheckBox16.Checked then bi := bi + [biMinimize];
  if sCheckBox17.Checked then bi := bi + [biHelp];
  tf.BorderIcons := bi;

  sp := TsSkinProvider.Create(tf);
  if sCheckBox1.Checked then sp.ResizeMode := rmBorder else sp.ResizeMode := rmStandard;
  sp.MakeSkinMenu := sCheckBox2.Checked;

  if sRadioButton18.Checked then sp.CaptionAlignment := taLeftJustify else
  if sRadioButton19.Checked then sp.CaptionAlignment := taCenter else
  if sRadioButton20.Checked then sp.CaptionAlignment := taRightJustify;

  sp.SkinData.SkinSection := sComboBox1.Text;
  sp.ShowAppIcon := sCheckBox19.Checked;

  if sCheckBox20.Checked then sp.GripMode := gmRightBottom else sp.GripMode := gmNone;
  for i := 0 to sSpinEdit4.Value - 1 do begin
    sp.TitleButtons.Add;
    sp.TitleButtons.Items[i].Name := 'TitleButton' + IntToStr(i);
    sp.TitleButtons.Items[i].OnMouseUp := BtnMouseUp;
    sp.TitleButtons.Items[i].UseSkinData := False;
    // Assigning of glyph from MainForm Title button
    if sp.TitleButtons.Items[i].Glyph = nil
      then sp.TitleButtons.Items[i].Glyph := TBitmap.Create;
    sp.TitleButtons.Items[i].Glyph.Assign(MainForm.sSkinProvider1.TitleButtons.Items[0].Glyph);
  end;

  btn := TsButton.Create(tf);
  btn.Parent := tf;
  btn.Caption := 'Close';
  btn.Top := 120;
  btn.Left := 120;
  btn.Height := 32;
  btn.Width := 84;
  btn.Anchors := btn.Anchors + [akBottom, akRight] - [aktop];
  btn.OnClick := CloseBtnClick;
  tf.ShowModal;
  FreeAndNil(btn);
  FreeAndNil(sp);
  FreeAndNil(tf);
end;

procedure TFrameForms.BtnMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  Alert(TsTitleButton(Sender).Name + ' clicked!');
end;

procedure TFrameForms.CloseBtnClick(Sender: TObject);
begin
  TForm(TsButton(Sender).Parent).Close;
end;

procedure TFrameForms.sCheckBox1Change(Sender: TObject);
begin
  if sCheckBox1.Checked then MainForm.sSkinProvider1.ResizeMode := rmBorder else MainForm.sSkinProvider1.ResizeMode := rmStandard
end;

procedure TFrameForms.sComboBox1Change(Sender: TObject);
begin
//  MainForm.sSkinProvider1.CommonData.SkinSection := sComboBox1.Text;
//  MainForm.Repaint;
end;

end.
