unit UMenu;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ImgList, Menus, StdActns, ActnList, ComCtrls, ToolWin, ExtCtrls, StdCtrls,
  Inifiles, AppEvnts, Buttons;

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    MFile1: TMenuItem;
    MNew1: TMenuItem;
    MOpen1: TMenuItem;
    N1: TMenuItem;
    MSave1: TMenuItem;
    MSaveAs1: TMenuItem;
    N2: TMenuItem;
    MPreview1: TMenuItem;
    MPrint1: TMenuItem;
    MPrintSetup1: TMenuItem;
    N3: TMenuItem;
    MExit1: TMenuItem;
    MEdit1: TMenuItem;
    MUndo1: TMenuItem;
    N5: TMenuItem;
    MCut1: TMenuItem;
    MCopy1: TMenuItem;
    MPaste1: TMenuItem;
    N6: TMenuItem;
    MFind1: TMenuItem;
    MReplace1: TMenuItem;
    MFormat1: TMenuItem;
    MFont1: TMenuItem;
    MParagr1: TMenuItem;
    MWindow1: TMenuItem;
    MCascad1: TMenuItem;
    MHorizont1: TMenuItem;
    MVert1: TMenuItem;
    MArrIcon1: TMenuItem;
    MParams: TMenuItem;
    MMenu: TMenuItem;
    MPanels: TMenuItem;
    MHelp1: TMenuItem;
    MCallHelp1: TMenuItem;
    N8: TMenuItem;
    MAbout1: TMenuItem;
    ImageList1: TImageList;
    ActionList1: TActionList;
    ACopy: TEditCopy;
    ACut: TEditCut;
    APaste: TEditPaste;
    AArrangeIcons: TWindowArrange;
    ATileHorizontally: TWindowTileHorizontal;
    ATileVertically: TWindowTileVertical;
    AExit: TAction;
    ANew: TAction;
    AOpen: TAction;
    ASave: TAction;
    ASaveAs: TAction;
    APrint: TAction;
    AFind: TAction;
    AReplace: TAction;
    AFont: TAction;
    ABold: TAction;
    AItalic: TAction;
    A_: TAction;
    ALeft: TAction;
    ARight: TAction;
    ACenter: TAction;
    ABul: TAction;
    AMenu: TAction;
    N9: TMenuItem;
    N10: TMenuItem;
    N11: TMenuItem;
    N12: TMenuItem;
    N13: TMenuItem;
    N17: TMenuItem;
    AOptions: TAction;
    APrinterSetup: TAction;
    ACallHelp: TAction;
    AAbout: TAction;
    APreview: TAction;
    ControlBar1: TControlBar;
    StatusBar1: TStatusBar;
    RichEdit1: TRichEdit;
    ACascade: TWindowCascade;
    AUndo: TEditUndo;
    N4: TMenuItem;
    OpenDialog1: TOpenDialog;
    SaveDialog1: TSaveDialog;
    FontDialog1: TFontDialog;
    APanels: TAction;
    TBHide: TToolBar;
    ToolButton23: TToolButton;
    ToolButton24: TToolButton;
    ToolButton25: TToolButton;
    ToolButton26: TToolButton;
    ToolButton27: TToolButton;
    ToolButton28: TToolButton;
    TBEdit: TToolBar;
    ToolButton8: TToolButton;
    ToolButton9: TToolButton;
    ToolButton6: TToolButton;
    ToolButton5: TToolButton;
    ToolButton7: TToolButton;
    ToolButton10: TToolButton;
    ToolButton11: TToolButton;
    ToolButton12: TToolButton;
    TBFile: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    TBHelp: TToolBar;
    ToolButton22: TToolButton;
    TBFont: TToolBar;
    ComboBox1: TComboBox;
    ToolButton13: TToolButton;
    ToolButton14: TToolButton;
    ToolButton15: TToolButton;
    ToolButton17: TToolButton;
    ToolButton16: TToolButton;
    ToolButton18: TToolButton;
    ToolButton19: TToolButton;
    ToolButton20: TToolButton;
    ToolButton21: TToolButton;
    procedure AMenuExecute(Sender: TObject);
    procedure ACallHelpExecute(Sender: TObject);
    procedure AAboutExecute(Sender: TObject);
    procedure AFindExecute(Sender: TObject);
    procedure AReplaceExecute(Sender: TObject);
    procedure AOptionsExecute(Sender: TObject);
    procedure APalettExecute(Sender: TObject);
    procedure ActionList1Change(Sender: TObject);
    procedure ANewExecute(Sender: TObject);
    procedure AOpenExecute(Sender: TObject);
    procedure ASaveExecute(Sender: TObject);
    procedure ASaveAsExecute(Sender: TObject);
    procedure APrintExecute(Sender: TObject);
    procedure APrinterSetupExecute(Sender: TObject);
    procedure APreviewExecute(Sender: TObject);
    procedure AFontExecute(Sender: TObject);
    procedure ABoldExecute(Sender: TObject);
    procedure AItalicExecute(Sender: TObject);
    procedure A_Execute(Sender: TObject);
    procedure ALeftExecute(Sender: TObject);
    procedure ACenterExecute(Sender: TObject);
    procedure ARightExecute(Sender: TObject);
    procedure ABulExecute(Sender: TObject);
    procedure AExitExecute(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FontDialog1Apply(Sender: TObject; Wnd: HWND);
    procedure ComboBox1Change(Sender: TObject);
    procedure APanelsExecute(Sender: TObject);
    procedure TBFileDragOver(Sender, Source: TObject; X, Y: Integer;
      State: TDragState; var Accept: Boolean);
    procedure TBFileDragDrop(Sender, Source: TObject; X, Y: Integer);
    procedure TBFileDockOver(Sender: TObject; Source: TDragDockObject; X,
      Y: Integer; State: TDragState; var Accept: Boolean);
    procedure ToolButtonDragDrop(Sender, Source: TObject; X, Y: Integer);
    procedure ControlBar1DockOver(Sender: TObject; Source: TDragDockObject;
      X, Y: Integer; State: TDragState; var Accept: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  TFileOld = class(TMenuItem)
   Procedure Click(); override;
  end;

function StrAmp(S: string): string;

var  Ini:TIniFile;

var
  Form1: TForm1;
  NFiles: integer = 5;
  NFileMen: integer = 12;
implementation

uses UMSetup, UPSetup, Grids, UOptions;

{$R *.DFM}

procedure TFileOld.Click();
begin
 Form1.RichEdit1.Lines.LoadFromFile(Caption);
end;

function StrAmp(S: string): string;
var i: integer;
begin
 Result := S;
 i := Pos('&', S);
 if i > 0
 then Delete(Result, i, 1);
end;

procedure TForm1.AMenuExecute(Sender: TObject);
begin
  FMSetup.ShowModal;
end;

procedure TForm1.ACallHelpExecute(Sender: TObject);
begin
 Application.HelpContext(1);
end;

procedure TForm1.AAboutExecute(Sender: TObject);
begin
 ShowMessage('О программе...');
end;

procedure TForm1.AFindExecute(Sender: TObject);
begin
 ShowMessage('Найти');
end;

procedure TForm1.AReplaceExecute(Sender: TObject);
begin
 ShowMessage('Заменить');
end;

procedure TForm1.AOptionsExecute(Sender: TObject);
begin
 FOptions.ShowModal;
end;

procedure TForm1.APalettExecute(Sender: TObject);
begin
 ShowMessage('Настройка панели');
end;

procedure TForm1.ActionList1Change(Sender: TObject);
begin
 ShowMessage('О программе');
end;

procedure TForm1.ANewExecute(Sender: TObject);
begin
 ShowMessage('Создать');
end;

procedure TForm1.AOpenExecute(Sender: TObject);
var TmpItem: TFileOld;
begin
 if(OpenDialog1.Execute)
  then begin
   TmpItem := TFileOld.Create(MainMenu1);
   TmpItem.Caption := OpenDialog1.FileName;
   MainMenu1.Items[0].Insert(NFileMen,TmpItem);
   if(MainMenu1.Items[0].Count > NFileMen+NFiles)
    then MainMenu1.Items[0].Items[NFileMen+NFiles].Free;
   RichEdit1.Lines.LoadFromFile(OpenDialog1.FileName);
  end;
end;

procedure TForm1.ASaveExecute(Sender: TObject);
begin
 ShowMessage('Сохранить...');
end;

procedure TForm1.ASaveAsExecute(Sender: TObject);
begin
 ShowMessage('Сохранить как...');
end;

procedure TForm1.APrintExecute(Sender: TObject);
begin
 ShowMessage('Печать');
end;

procedure TForm1.APrinterSetupExecute(Sender: TObject);
begin
 ShowMessage('Установка принтера');
end;

procedure TForm1.APreviewExecute(Sender: TObject);
begin
 ShowMessage('Предварительный просмотр');
end;

procedure TForm1.AFontExecute(Sender: TObject);
begin
 if FontDialog1.Execute then begin
  RichEdit1.SelAttributes.Assign(FontDialog1.Font);
  ComboBox1.ItemIndex := ComboBox1.Items.IndexOf(
                        RichEdit1.SelAttributes.Name);
  if (fsBold in RichEdit1.SelAttributes.Style)
   then ABold.Checked := true
   else ABold.Checked := false;
  if (fsItalic in RichEdit1.SelAttributes.Style)
   then AItalic.Checked := true
   else AItalic.Checked := false;
  if (fsUnderline in RichEdit1.SelAttributes.Style)
   then A_.Checked := true
   else A_.Checked := false;
 end
end;

procedure TForm1.ABoldExecute(Sender: TObject);
begin
 ABold.Checked := not ABold.Checked;
 if ABold.Checked
 then
  RichEdit1.SelAttributes.Style := RichEdit1.SelAttributes.Style + [fsBold]
 else
  RichEdit1.SelAttributes.Style := RichEdit1.SelAttributes.Style - [fsBold];
end;

procedure TForm1.AItalicExecute(Sender: TObject);
begin
 AItalic.Checked := not AItalic.Checked;
 if AItalic.Checked
 then
  RichEdit1.SelAttributes.Style := RichEdit1.SelAttributes.Style + [fsItalic]
 else
  RichEdit1.SelAttributes.Style := RichEdit1.SelAttributes.Style - [fsItalic];
end;

procedure TForm1.A_Execute(Sender: TObject);
begin
 A_.Checked := not A_.Checked;
 if A_.Checked
 then
  RichEdit1.SelAttributes.Style := RichEdit1.SelAttributes.Style + [fsUnderline]
 else
  RichEdit1.SelAttributes.Style := RichEdit1.SelAttributes.Style - [fsUnderline];
end;

procedure TForm1.ALeftExecute(Sender: TObject);
begin
 if ALeft.Checked then exit;
 ALeft.Checked := true;
 ACenter.Checked := false;
 ARight.Checked := false;
 RichEdit1.Paragraph.Alignment := taLeftJustify;
end;

procedure TForm1.ACenterExecute(Sender: TObject);
begin
 if ACenter.Checked then exit;
 ALeft.Checked := false;
 ACenter.Checked := true;
 ARight.Checked := false;
 RichEdit1.Paragraph.Alignment := taCenter;
end;

procedure TForm1.ARightExecute(Sender: TObject);
begin
 if ARight.Checked then exit;
 ALeft.Checked := false;
 ACenter.Checked := false;
 ARight.Checked := true;
 RichEdit1.Paragraph.Alignment := taRightJustify;
end;

procedure TForm1.ABulExecute(Sender: TObject);
begin
 if(ABul.Checked)
  then RichEdit1.Paragraph.Numbering:=nsNone
  else RichEdit1.Paragraph.Numbering:=nsBullet;
 ABul.Checked:=not ABul.Checked;
end;

procedure TForm1.AExitExecute(Sender: TObject);
begin
 Close;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
 ToIni(false);
 {Освобождение памяти}
 Ini.Free;
end;

procedure TForm1.FontDialog1Apply(Sender: TObject; Wnd: HWND);
begin
 RichEdit1.SelAttributes.Assign(FontDialog1.Font);
end;

procedure TForm1.ComboBox1Change(Sender: TObject);
begin
 RichEdit1.SelAttributes.Name := ComboBox1.Text;
 RichEdit1.SetFocus;
end;

procedure TForm1.APanelsExecute(Sender: TObject);
begin
 FPSetup.Show;
end;

procedure TForm1.TBFileDragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
 Accept := (Source = FPSetup.DrawGrid1);
end;
procedure TForm1.TBFileDragDrop(Sender, Source: TObject; X, Y: Integer);
var ind: integer;
begin
 with FPSetup.DrawGrid1 do begin
  ind := Row * ColCount + Col;
  TToolButton(LButton.Items[ind]).Parent := Sender as TToolBar;
 end;
end;

procedure TForm1.TBFileDockOver(Sender: TObject; Source: TDragDockObject;
  X, Y: Integer; State: TDragState; var Accept: Boolean);
begin
 Accept := Source.Control.ClassName = 'TToolButton';
end;

procedure TForm1.ToolButtonDragDrop(Sender, Source: TObject; X,
  Y: Integer);
var ind: integer;
begin
  with FPSetup.DrawGrid1 do begin
  ind := Row * ColCount + Col;
  TToolButton(LButton.Items[ind]).Parent :=
   (Sender as TToolButton).Parent as TToolBar;
 end;
end;

procedure TForm1.ControlBar1DockOver(Sender: TObject;
  Source: TDragDockObject; X, Y: Integer; State: TDragState;
  var Accept: Boolean);
begin
 Accept := (Source.Control.ClassName = 'TToolBar');
end;

end.
