unit frmmain;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  Menus, StdCtrls, ComCtrls;

type

  { TMainForm }

  TMainForm = class(TForm)
    ILMenu: TImageList;
    Memo1: TMemo;
    MenuItem2: TMenuItem;
    MenuItem3: TMenuItem;
    MIMorebuttons: TMenuItem;
    MIToolBarTransparent: TMenuItem;
    MIToolbarWrapable: TMenuItem;
    MIToolbarAutoSize: TMenuItem;
    MIToolbarList: TMenuItem;
    MIToolbarShowCaptions: TMenuItem;
    MIToolbarFlat: TMenuItem;
    PMIAlignRight: TMenuItem;
    PMIAlignCenter: TMenuItem;
    PMIAlignLeft: TMenuItem;
    miReciente: TMenuItem;
    PMISelectAll: TMenuItem;
    PMICopy: TMenuItem;
    PMICut: TMenuItem;
    PMIPaste: TMenuItem;
    MenuItem1: TMenuItem;
    miSubrayado: TMenuItem;
    miACentrado: TMenuItem;
    miAInf: TMenuItem;
    miASup: TMenuItem;
    miAJustificado: TMenuItem;
    miADecha: TMenuItem;
    miAIzq: TMenuItem;
    MAlineacion: TMenuItem;
    miCursiva: TMenuItem;
    miNegrita: TMenuItem;
    MFuentes: TMenuItem;
    miSalir: TMenuItem;
    MISeparador: TMenuItem;
    miGuardar: TMenuItem;
    miAbrir: TMenuItem;
    miNuevo: TMenuItem;
    MenuPpal: TMainMenu;
    MArchivo: TMenuItem;
    pmPpal: TPopupMenu;
    pmAlin: TPopupMenu;
    tbPpal: TToolBar;
    btnNuevo: TToolButton;
    btnAbrir: TToolButton;
    btnGuardar: TToolButton;
    ToolButton1: TToolButton;
    btnAlinear: TToolButton;
    procedure DoMenuClick(Sender: TObject);
    procedure DoQuit(Sender: TObject);
    procedure MIMorebuttonsClick(Sender: TObject);
    procedure MArchivoClick(Sender: TObject);
    procedure MIManualCheckClick(Sender: TObject);
    procedure ButtonClick(Sender: TObject);
    procedure MIToolbarAutoSizeClick(Sender: TObject);
    procedure MIToolbarListClick(Sender: TObject);
    procedure MIToolbarShowCaptionsClick(Sender: TObject);
    procedure MIToolbarFlatClick(Sender: TObject);
    procedure MIToolBarTransparentClick(Sender: TObject);
    procedure MIToolbarWrapableClick(Sender: TObject);
  private
    procedure CreateExtraButtons;
    procedure FreeExtraButtons;
    { private declarations }
  public
    { public declarations }
  end;

var
  MainForm: TMainForm;

implementation

{ TMainForm }

procedure TMainForm.DoMenuClick(Sender: TObject);
begin
  With (Sender as TMenuItem) do
    begin
    ShowMessage('Se ha seleccionado el elemento del menú '+Caption);
    end;
end;

procedure TMainForm.DoQuit(Sender: TObject);
begin
  Close;
end;

procedure TMainForm.MIMorebuttonsClick(Sender: TObject);
begin
  If MIMoreButtons.Checked then
    CreateExtraButtons
  else
    FreeExtraButtons;
end;

procedure TMainForm.CreateExtraButtons;

Var
  I,P : Integer;
  C : TControl;
  B : TToolbutton;

begin
  P:=0;
  For I:=0 to tbPpal.ControlCount-1 do
    begin
    C:=tbPpal.Controls[i];
    If C.Left+C.Width>P then
      P:=C.Left+C.Width;
    end;
  For I:=1 to 4 do
    begin
    B:=TToolButton.Create(Self);
    B.Name:='TBExtra'+IntToStr(i);
    B.Parent:=tbPpal;
    B.Left:=P;
    B.Width:=tbPpal.ButtonWidth;
    B.ImageIndex:=4+I;
    B.Caption:='B'+IntToStr(i);
    B.OnClick:=@ButtonClick;
    B.Tag:=-1;
    P:=P+B.Width;
    end;
end;

procedure TMainForm.FreeExtraButtons;

Var
  I : Integer;
  C : TComponent;
begin
  For I:=ComponentCount-1 downto 0 do
    begin
    C:=Components[i];
    If (C is TToolbutton) and (C.Tag=-1) then
      Components[i].Free;
    end;
end;



procedure TMainForm.MArchivoClick(Sender: TObject);

Var
  I : integer;
  MI : TMenuItem;

begin
  With miReciente do
    begin
    Clear;
    For I:=0 to 10 do
      begin
      MI:=TMenuItem.Create(Self);
      MI.Caption:=Format('%d: archivo reciente no. %d',[I,I]);
      MI.OnClick:=@DoMenuClick;
      Add(MI);
      end;
    end;
end;

procedure TMainForm.MIManualCheckClick(Sender: TObject);
begin
  miNegrita.Checked:=Not miNegrita.Checked;
  DoMenuClick(Sender)
end;

procedure TMainForm.ButtonClick(Sender: TObject);
begin
  With (Sender as TToolButton) do
    begin
    ShowMessage('Se ha pulsado el botón de nombre '+Name);
    end;
end;

procedure TMainForm.MIToolbarAutoSizeClick(Sender: TObject);
begin
 tbPpal.AutoSize:=MIToolbarAutoSize.Checked;
end;

procedure TMainForm.MIToolbarListClick(Sender: TObject);
begin
  tbPpal.list:=MIToolbarList.Checked;
end;

procedure TMainForm.MIToolbarShowCaptionsClick(Sender: TObject);
begin
  tbPpal.ShowCaptions:=MIToolbarShowCaptions.Checked;
end;

procedure TMainForm.MIToolbarFlatClick(Sender: TObject);
begin
  tbPpal.Flat:=MIToolbarFlat.Checked;
end;

procedure TMainForm.MIToolBarTransparentClick(Sender: TObject);
begin
  tbPpal.Transparent:=MIToolBarTransparent.Checked;
end;

procedure TMainForm.MIToolbarWrapableClick(Sender: TObject);
begin
  tbPpal.Wrapable:=MIToolbarWrapable.Checked;
end;




initialization
  {$I frmmain.lrs}

end.

