unit intercapPrinc;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, StdCtrls, shellApi, Clipbrd, ExtCtrls, Buttons;

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    Arquivo1: TMenuItem;
    Editar1: TMenuItem;
    Visualizar1: TMenuItem;
    ajuda1: TMenuItem;
    Novo1: TMenuItem;
    Salvar1: TMenuItem;
    SalvarComo1: TMenuItem;
    Terminar: TMenuItem;
    Copiar1: TMenuItem;
    Colar1: TMenuItem;
    Inserir1: TMenuItem;
    Elo1: TMenuItem;
    Imagem1: TMenuItem;
    Abrir1: TMenuItem;
    Separador1: TMenuItem;
    HTML1: TMenuItem;
    amanho1: TMenuItem;
    Negrito1: TMenuItem;
    Itlico1: TMenuItem;
    Programa1: TMenuItem;
    Centralizado1: TMenuItem;
    H1Grande1: TMenuItem;
    H21: TMenuItem;
    H31: TMenuItem;
    H41: TMenuItem;
    H51: TMenuItem;
    H6Micro1: TMenuItem;
    Cabecalho1: TMenuItem;
    OpenDialog1: TOpenDialog;
    SaveDialog1: TSaveDialog;
    Cortar1: TMenuItem;
    Rotulo1: TMenuItem;
    Criarnovapastadepublicao1: TMenuItem;
    GerarHTML1: TMenuItem;
    Desfazer1: TMenuItem;
    FontDialog1: TFontDialog;
    GeraHTML1: TMenuItem;
    Configurar1: TMenuItem;
    Ajuda2: TMenuItem;
    Sobreesteprograma1: TMenuItem;
    N1: TMenuItem;
    N2: TMenuItem;
    Localizar1: TMenuItem;
    FindDialog1: TFindDialog;
    Panel1: TPanel;
    newButton1: TSpeedButton;
    OpenButton: TSpeedButton;
    saveButton: TSpeedButton;
    ConfigBtn: TSpeedButton;
    Regenerartudo1: TMenuItem;
    negBtn: TSpeedButton;
    CutBtn: TSpeedButton;
    CopyBtn: TSpeedButton;
    PasteBtn: TSpeedButton;
    genvisBtn: TSpeedButton;
    Titulo1: TMenuItem;
    itaBtn: TSpeedButton;
    ProgBtn: TSpeedButton;
    CentrBtn: TSpeedButton;
    TituloBtn: TSpeedButton;
    sublBtn: TSpeedButton;
    Sublinhado1: TMenuItem;
    Reabrir1: TMenuItem;
    N11: TMenuItem;
    N21: TMenuItem;
    N31: TMenuItem;
    N41: TMenuItem;
    N51: TMenuItem;
    Panel2: TPanel;
    Memo1: TMemo;
    lb_arqpag: TListBox;
    Splitter1: TSplitter;
    btnPag: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button1: TButton;
    Button6: TButton;
    Timer1: TTimer;
    l_lincol: TLabel;
    Tabela1: TMenuItem;
    Formulario1: TMenuItem;
    Botao1: TMenuItem;
    Mostrarpastaatual1: TMenuItem;
    procedure Novo1Click(Sender: TObject);
    procedure Abrir1Click(Sender: TObject);
    procedure Cabecalho1Click(Sender: TObject);
    procedure Salvar1Click(Sender: TObject);
    procedure SalvarComo1Click(Sender: TObject);
    procedure TerminarClick(Sender: TObject);
    procedure Copiar1Click(Sender: TObject);
    procedure Cortar1Click(Sender: TObject);
    procedure Colar1Click(Sender: TObject);
    procedure Elo1Click(Sender: TObject);
    procedure Separador1Click(Sender: TObject);
    procedure Imagem1Click(Sender: TObject);
    procedure Rotulo1Click(Sender: TObject);
    procedure escolherPastaBase1Click(Sender: TObject);
    procedure Visualizar1Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure GerarHTML1Click(Sender: TObject);
    procedure H1Grande1Click(Sender: TObject);
    procedure H21Click(Sender: TObject);
    procedure H31Click(Sender: TObject);
    procedure H41Click(Sender: TObject);
    procedure H51Click(Sender: TObject);
    procedure H6Micro1Click(Sender: TObject);
    procedure Negrito1Click(Sender: TObject);
    procedure Itlico1Click(Sender: TObject);
    procedure Sublinhado1Click(Sender: TObject);
    procedure Programa1Click(Sender: TObject);
    procedure Titulo1Click(Sender: TObject);
    procedure Centralizado1Click(Sender: TObject);
    procedure Desfazer1Click(Sender: TObject);
    procedure Configurar1Click(Sender: TObject);
    procedure Ajuda2Click(Sender: TObject);
    procedure Sobreesteprograma1Click(Sender: TObject);
    procedure Localizar1Click(Sender: TObject);
    procedure FindDialog1Find(Sender: TObject);
    procedure newButton1Click(Sender: TObject);
    procedure OpenButtonClick(Sender: TObject);
    procedure genvisBtnClick(Sender: TObject);
    procedure ConfigBtnClick(Sender: TObject);
    procedure Regenerartudo1Click(Sender: TObject);
    procedure lb_arqpagClick(Sender: TObject);
    procedure saveButtonClick(Sender: TObject);
    procedure negBtnClick(Sender: TObject);
    procedure itaBtnClick(Sender: TObject);
    procedure ProgBtnClick(Sender: TObject);
    procedure CentrBtnClick(Sender: TObject);
    procedure TituloBtnClick(Sender: TObject);
    procedure sublBtnClick(Sender: TObject);
    procedure N11Click(Sender: TObject);
    procedure N21Click(Sender: TObject);
    procedure N31Click(Sender: TObject);
    procedure N41Click(Sender: TObject);
    procedure N51Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure CriaMenuReabrir1Click(Sender: TObject);
    procedure btnExtensaoClick(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Memo1Change(Sender: TObject);
    procedure Memo1Click(Sender: TObject);
    procedure Memo1KeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Tabela1Click(Sender: TObject);
    procedure Botao1Click(Sender: TObject);
    procedure Formulario1Click(Sender: TObject);
    procedure Mostrarpastaatual1Click(Sender: TObject);
  private
    { Private declarations }
    procedure ajustaLinCol;
    procedure insertMemo (s: string);
    procedure trocaPastaAtual (nome: string);
    procedure lbArqRefresh (nomeFoco: string);
    procedure Reabrir(novoDir: string);

  public
    { Public declarations }
  end;

var
    Form1: TForm1;

implementation

uses uvars, ucabecalho, uelo, ufigura, ugeraHtml, uabout, uconf, ubasico, udir,
  udicasform;

const CRLF = #$0d + #$0a;

{$R *.dfm}

procedure TForm1.ajustaLinCol;
var i, tam, acum, lin, col: integer;
    posic: integer;
begin
   posic := memo1.SelStart;
   acum := 0;
   i := 0;
   if memo1.lines.count > 0 then
     for i := 0 to memo1.lines.count-1 do
         begin
             tam := length (memo1.Lines[i]) + 2;
             if acum + tam > posic then break;
             acum := acum + tam;
         end;

   lin := i+1;
   col := posic-acum+1;
   l_lincol.caption := 'L='+intToStr(lin)+' C='+intToStr(col);
end;

procedure TForm1.Novo1Click(Sender: TObject);
begin
  if not memo1.Modified then
      memo1.clear
  else
     if MessageDlg('Confirmando apagamento geral',
        mtConfirmation, [mbYes, mbNo], 0) = mrYes then
           memo1.Clear;
  nomeArq := '';
  nomeArqHTML := '';
  form1.Caption := 'InterCap';
  lb_arqpag.ItemIndex := -1;
end;

procedure TForm1.Abrir1Click(Sender: TObject);
begin
    if memo1.Modified then
       if MessageDlg('Texto foi alterado, carrega outro sem salvar?',
          mtConfirmation, [mbYes, mbNo], 0) = mrNo then
              exit;

    if not OpenDialog1.execute then
        exit;

    memo1.Clear;
    nomeArq := OpenDialog1.FileName;
    memo1.lines.loadfromfile (nomeArq);
    Caption := 'InterCAP ' + nomeArq;
    nomeArqHTML := '';
    lbArqRefresh (nomeArq);
end;

procedure TForm1.Salvar1Click(Sender: TObject);
begin
    if nomeArq = '' then
        salvarComo1Click (Sender)
    else
        memo1.Lines.SaveToFile(nomeArq);
    memo1.Modified := false;
end;

procedure TForm1.SalvarComo1Click(Sender: TObject);
begin
    if SaveDialog1.execute then
        begin
           nomeArq := SaveDialog1.FileName;
           if pos ('.', nomeArq) = 0 then
               nomeArq := nomeArq + '.pag';
           if nomeArq <> '' then
               begin
                   memo1.Lines.SaveToFile(nomeArq);
                   memo1.Modified := false;
                   Caption := 'InterCAP ' + nomeArq;
               end;
            lbArqRefresh (nomeArq);
        end;
end;

procedure TForm1.TerminarClick(Sender: TObject);
begin
  if memo1.Modified then
     if MessageDlg('Texto foi alterado, sai sem salvar?',
        mtConfirmation, [mbYes, mbNo], 0) <> mrYes then
          exit;
  close;
end;

procedure TForm1.Copiar1Click(Sender: TObject);
begin
   memo1.CopyToClipboard;
end;

procedure TForm1.Cortar1Click(Sender: TObject);
begin
   memo1.CutToClipboard;
end;

procedure TForm1.Colar1Click(Sender: TObject);
begin
   memo1.PasteFromClipboard;
end;

procedure TForm1.Cabecalho1Click(Sender: TObject);
begin
    OKCabecalhoDlg.showModal;
    if OKCabecalhoDlg.ok then
        begin
            memo1.Lines.Insert(0, 'TÍTULO: ' + OKCabecalhoDlg.e_titulo.text);
            memo1.Lines.Insert(1, 'CABEÇALHO: ' + OKCabecalhoDlg.e_cabec.text);
            memo1.Lines.Insert(2, 'AUTOR: ' + OKCabecalhoDlg.e_autor.text);
            memo1.Lines.Insert(3, 'EMAIL: ' + OKCabecalhoDlg.e_email.text);
            memo1.Lines.Insert(4, 'LOGOTIPO: ' + OKCabecalhoDlg.e_logotipo.text);
            memo1.Lines.Insert(5, 'MODELO: ' + OKCabecalhoDlg.e_modelo.text);
            memo1.Lines.Insert (6, '');

            if OKCabecalhoDlg.cb_geraphp.Checked then
                memo1.Lines.Insert(0, '<?php?>');
        end;
end;

procedure TForm1.Elo1Click(Sender: TObject);
begin
    OKEloDlg.showModal;
    if OKEloDlg.ok then
        begin
            clipboard.Clear;
            clipboard.asText := CRLF + '{' + OKEloDlg.e_referencia.text + ' ' +
                              OKEloDlg.e_texto.text + '}' + CRLF;
            memo1.PasteFromClipboard;
            clipboard.Clear;
        end;
end;

procedure TForm1.Separador1Click(Sender: TObject);
begin
    clipboard.Clear;
    clipboard.asText := CRLF + '-----------------------------------' + CRLF;
    memo1.PasteFromClipboard;
    clipboard.Clear;
end;

procedure TForm1.Imagem1Click(Sender: TObject);
begin
    OKFiguraDlg.showModal;
    if OKFiguraDlg.ok then
        begin
            clipboard.Clear;
            clipboard.asText := CRLF + '$' + OKFiguraDlg.e_nomeFig.text + ' ' +
                              OKFiguraDlg.e_comentFig.text + '$' + CRLF;
            memo1.PasteFromClipboard;
            clipboard.Clear;
        end;
end;

procedure TForm1.Rotulo1Click(Sender: TObject);
var nome: string;
begin
   nome := '';
   if inputQuery('Nome do rótulo', 'Como se chama esta posição?', nome) then
       begin
            clipboard.Clear;
            clipboard.asText := CRLF + '#'+nome + CRLF;
            memo1.PasteFromClipboard;
            clipboard.Clear;
       end;
end;

procedure copiaArquivosBasicos (dirModelo, dirDestino: string);
var nome, nome2: string;
    dosError: integer;
    f: TSearchRec;
    dirSalva: string;
begin
    getDir (0, dirSalva);

    {$I-} chdir (dirModelo);  {$I+}
    if ioresult <> 0 then
        showMessage ('Site modelo não existe, modelo padrão assumido')
    else
        begin
            dosError := findFirst ('*.*', faArchive, f);
            while dosError = 0 do
                begin
                    nome := dirModelo + '\' + f.FindData.cFileName;
                    nome2 := dirDestino + '\' + f.FindData.cFileName;
                    copyFile (@nome[1], @nome2[1], false);
                    dosError := findNext (f);
                end;
        end;

    chdir (dirSalva);
end;

procedure registraUltDir (dirAtual: string);
var i, j: integer;
begin
	for i := 1 to 5 do
        begin
            if dirAtual = ultimosDir [i] then
                begin
                    for j := i to 4 do
                        ultimosDir [j] := ultimosDir [j+1];
                    ultimosDir [5] := '';
                end;
        end;

    if (dirAtual <> '') and (dirAtual <> ultimosDir [1]) then
       begin
           for i := 5 downto 2 do
               ultimosDir [i] := ultimosDir [i-1];
           ultimosDir [1] := dirAtual;
           for i := 1 to 5 do
               writePrivateProfileString ('INTERCAP',
                 pchar('arq'+intToStr(i)), pchar(ultimosDir[i]), 'intercap.ini');
           writePrivateProfileString ('INTERCAP', 'PASTAPADRAO', pchar (dirAtual), 'intercap.ini');
       end;
end;


procedure TForm1.trocaPastaAtual (nome: string);
begin
    dirAtual := nome;
    {$i-}  chdir (dirAtual);  {$I+}    // evita situações de inacessibilidade
    if ioresult <> 0 then
        begin
            showMessage ('Pasta de trabalho ' + diratual + ' está inacessível');
            exit;
        end;

    memo1.clear;
    Caption := 'InterCAP';
    nomeArqHTML := '';

    OpenDialog1.InitialDir := nome;
    saveDialog1.InitialDir := nome;
    lbArqRefresh(nome);

    registraUltDir (dirAtual);

    carregaConfigs;
    form_conf.showModal;
end;

function DirectoryIsEmpty(Directory: string): Boolean;
var
  SR: TSearchRec;
  i: Integer;
begin
  Result := False;
  FindFirst(IncludeTrailingPathDelimiter(Directory) + '*', faAnyFile, SR);
  for i := 1 to 2 do
    if (SR.Name = '.') or (SR.Name = '..') then
      Result := FindNext(SR) <> 0;
  FindClose(SR);
end;

procedure TForm1.escolherPastaBase1Click(Sender: TObject);
var nomeDir: string;
begin
    nomeDir := escolhePastaBase (dirAtual);
    if nomeDir = '' then
        exit;

    {$I-} chdir (nomeDir);  {$I+}
    if (IOResult <> 0) then
        begin
            if MessageDlg('Confirmando criação da pasta ' + nomeDir,
               mtConfirmation, [mbYes, mbNo], 0) = mrYes then
                begin
                  {$I-} mkdir (nomeDir);  {$I+}
                  if ioresult <> 0 then
                      begin
                         showMessage ('Pasta não pode ser criada');
                         exit;
                      end;
                end;
        end;

    if DirectoryIsEmpty(nomeDir) then
        begin
            copiaArquivosBasicos (dirProg + '\homepage', nomeDir);
            carregaConfigs;                                                 
            nomeModeloDefault := 'modelo.mdl';
            logotipoPadrao := 'logotipo.gif';
            salvaConfigs;
        end;

    trocaPastaAtual (nomeDir);
end;

procedure TForm1.Mostrarpastaatual1Click(Sender: TObject);
begin
    ShellExecute(0, 'open', 'explorer', @dirAtual[1], NIL, SW_SHOW);
end;

procedure TForm1.Visualizar1Click(Sender: TObject);
begin
    if nomeArq = '' then
        begin
            showMessage ('Salve o arquivo antes de visualizar pela primeira vez');
            exit;
        end;

    if memo1.Modified then
        begin
            memo1.Lines.SaveToFile(nomeArq);
            memo1.Modified := false;
        end;

    if upperCase (copy (nomearq, length(nomearq)-3, 4)) = '.PAG' then
        begin
            GerarHTML1Click(Sender);
            ShellExecute(0, 'open', @nomeArqHTML[1], NIL, NIL, SW_SHOW);
        end
    else
        ShellExecute(0, 'open', @nomeArq[1], NIL, NIL, SW_SHOW);
end;

procedure TForm1.lbArqRefresh (nomeFoco: string);
var sr: TSearchRec;
    i: integer;
    nome: string;
begin
    if not DirectoryExists (nomeFoco) then
        begin
            i := lastDelimiter('\', nomeFoco);
            nomeFoco := copy (nomeFoco, i+1, 999);
        end;

    lb_arqpag.Clear;
    if findfirst(extMostrada, faAnyFile, sr) = 0 then
        repeat
            nome := sr.FindData.cFileName;
            if (nome = '.') or (nome = '..') then
                continue;
            lb_arqpag.Items.add (sr.FindData.cFileName);
            if sr.FindData.cFileName = nomeFoco then
                lb_arqPag.itemIndex := lb_arqPag.count-1;
        until FindNext(sr) <> 0;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
    timer1.enabled := false;
    trocaPastaAtual(dirAtual);
    carregaConfigs;
    OpenDialog1.InitialDir := dirAtual;
    lbArqRefresh ('');
    memo1.modified := false;
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
   // o timer evita que o formulário saia de foco
   timer1.enabled := true;
end;

procedure TForm1.GerarHTML1Click(Sender: TObject);
var ext: string;
begin
    if nomeArq = '' then
        begin
            showMessage ('Salve o arquivo antes de processar pela primeira vez');
            exit;
        end;

    if memo1.Modified then
        memo1.Lines.SaveToFile(nomeArq);

    if copy (memo1.Lines[0], 1, 5) = '<?php' then
        begin
            ext := '.php';
            emPHP := true;
        end
    else
        begin
            ext := '.htm';
            emPHP := false;
        end;

    if copy (AnsiUpperCase (nomeArq), length(nomeArq)-3, 4) = '.PAG' then
         nomeArqHTML := copy (nomeArq, 1, length(nomeArq)-4) + ext
    else
         nomeArqHTML := nomeArq + ext;
         
    geraHtml(nomeArq, nomeArqHTML, nomeModeloDefault);
end;

procedure TForm1.insertMemo (s: string);
var cb: string;
begin
    clipboard.clear;
    memo1.CopyToClipboard;
    cb := clipboard.asText;
    memo1.ClearSelection;
    cb := '<' + s + '>' + cb + '</' + s + '>';
    clipboard.AsText := cb;
    memo1.PasteFromClipboard;
end;

procedure TForm1.H1Grande1Click(Sender: TObject);
begin
    insertMemo ('h1');
end;

procedure TForm1.H21Click(Sender: TObject);
begin
    insertMemo ('h2');
end;

procedure TForm1.H31Click(Sender: TObject);
begin
    insertMemo ('h3');
end;

procedure TForm1.H41Click(Sender: TObject);
begin
    insertMemo ('h4');
end;

procedure TForm1.H51Click(Sender: TObject);
begin
    insertMemo ('h5');
end;

procedure TForm1.H6Micro1Click(Sender: TObject);
begin
    insertMemo ('h6');
end;

procedure TForm1.Negrito1Click(Sender: TObject);
begin
    insertMemo ('b');
end;

procedure TForm1.Itlico1Click(Sender: TObject);
begin
    insertMemo ('i');
end;

procedure TForm1.Sublinhado1Click(Sender: TObject);
begin
    insertMemo ('u');
end;

procedure TForm1.Programa1Click(Sender: TObject);
begin
    insertMemo ('pre');
end;

procedure TForm1.Centralizado1Click(Sender: TObject);
begin
    insertMemo ('center');
end;

procedure TForm1.Titulo1Click(Sender: TObject);
begin
    clipboard.clear;
    clipboard.AsText := '*';
    memo1.PasteFromClipboard;
end;

procedure TForm1.Desfazer1Click(Sender: TObject);
begin
    memo1.Undo;
end;

procedure TForm1.Configurar1Click(Sender: TObject);
begin
    form_conf.showModal;
end;

procedure TForm1.Ajuda2Click(Sender: TObject);
begin
    ShellExecute(0, 'open', @nomeArqAjuda[1], NIL, NIL, SW_SHOW);
end;

procedure TForm1.Sobreesteprograma1Click(Sender: TObject);
begin
    AboutBox.ShowModal;
end;

procedure TForm1.Localizar1Click(Sender: TObject);
begin
    FindDialog1.Execute;
    ajustaLinCol;
end;

procedure TForm1.FindDialog1Find(Sender: TObject);
var n, ini: integer;
    buscado: string;
    compIdentico: boolean;
    txt: string;

begin
   compIdentico := frMatchCase in findDialog1.Options;
   buscado := findDialog1.findText;
   ini := memo1.SelStart + memo1.SelLength;
   if ini = 0 then ini := 1;
   txt := copy (memo1.Text, ini, 65000);
   if not compIdentico then
       begin
          txt := AnsiUpperCase(txt);
          buscado := AnsiUpperCase(buscado);
       end;
   n := pos (buscado, txt);
   if n >= 1 then
      begin
         Memo1.SetFocus;
         Memo1.SelStart := n+ini-2;
         Memo1.SelLength := Length(buscado);
         txt := '';
      end
   else
      MessageDlg ('Busca terminada', mtInformation, [mbOk], 0);
end;

procedure TForm1.newButton1Click(Sender: TObject);
begin
    novo1Click (sender);
end;

procedure TForm1.OpenButtonClick(Sender: TObject);
begin
    Abrir1Click(Sender);
end;

procedure TForm1.saveButtonClick(Sender: TObject);
begin
    Salvar1Click(Sender);
end;

procedure TForm1.genvisBtnClick(Sender: TObject);
begin
    Visualizar1Click(Sender);
end;

procedure TForm1.ConfigBtnClick(Sender: TObject);
begin
    Configurar1Click(Sender);
end;

procedure TForm1.Regenerartudo1Click(Sender: TObject);
var sr: TSearchRec;
    nomeArq, nomeArqHtml: string;
    numArq: integer;
    oldCursor: TCursor;
    arqTeste: textFile;
    ext, s: string;
begin
    numArq := 0;
    oldCursor := Screen.Cursor;
    if findfirst('*.pag', faAnyFile, sr) = 0 then
        repeat
            nomeArq := sr.FindData.cFileName;

            assignFile (arqTeste, nomeArq);   // verifica se HTM ou PHP
            reset (arqTeste);
            {$i-} readln (arqTeste, s); {$I+}
            if ioresult <> 0 then;
            closeFile (arqTeste);

            if copy (s, 1, 5) = '<?php' then
                begin
                    ext := '.php';
                    emPHP := true;
                end
            else
                begin
                    ext := '.htm';
                    emPHP := false;
                end;

            nomeArqHtml := copy (nomeArq, 1, length(nomeArq)-4) + ext;
            geraHtml(nomeArq, nomeArqHTML, nomeModeloDefault);
            numArq := numArq + 1;
        until FindNext(sr) <> 0;
    Screen.Cursor := oldCursor;
    showMessage ('Arquivos gerados: ' + intToStr(numArq));
end;

procedure TForm1.lb_arqpagClick(Sender: TObject);
begin
    if memo1.Modified then
       if MessageDlg('Texto foi alterado, carrega outro sem salvar?',
          mtConfirmation, [mbYes, mbNo], 0) = mrNo then
            exit;

    chdir (dirAtual);
    memo1.Clear;
    nomeArq := lb_arqpag.Items[lb_arqpag.itemIndex];
    memo1.lines.loadfromfile (nomeArq);
    Caption := 'InterCAP ' + nomeArq;
    nomeArqHTML := '';
    lbArqRefresh (nomeArq);
end;

procedure TForm1.negBtnClick(Sender: TObject);
begin
    Negrito1Click(Sender);
end;

procedure TForm1.itaBtnClick(Sender: TObject);
begin
    Itlico1Click(Sender);
end;

procedure TForm1.ProgBtnClick(Sender: TObject);
begin
    Programa1Click(Sender);
end;

procedure TForm1.CentrBtnClick(Sender: TObject);
begin
    Centralizado1Click(Sender);
end;

procedure TForm1.TituloBtnClick(Sender: TObject);
begin
    Titulo1Click(Sender);
end;

procedure TForm1.sublBtnClick(Sender: TObject);
begin
    Sublinhado1Click(Sender);
end;

procedure TForm1.Reabrir(novoDir: string);
begin
    if memo1.Modified then
       if MessageDlg('Texto foi alterado, carrega outro sem salvar?',
          mtConfirmation, [mbYes, mbNo], 0) = mrNo then
              exit;

    if DirectoryExists(novoDir) then
        trocaPastaAtual (novoDir)
    else
        showMessage ('Diretório não existe');
end;

procedure TForm1.N11Click(Sender: TObject);
begin
   reabrir (ultimosDir[1]);
end;

procedure TForm1.N21Click(Sender: TObject);
begin
   reabrir (ultimosDir[2]);
end;

procedure TForm1.N31Click(Sender: TObject);
begin
   reabrir (ultimosDir[3]);
end;

procedure TForm1.N41Click(Sender: TObject);
begin
   reabrir (ultimosDir[4]);
end;

procedure TForm1.N51Click(Sender: TObject);
begin
   reabrir (ultimosDir[5]);
end;

procedure TForm1.FormCreate(Sender: TObject);
var
    valor, def: array [0..255] of char;
    p: array [0..255] of char;
begin
    getDir (0, dirProg);
    if dirProg [length(dirProg)] = '\' then
        delete (dirProg, length(dirProg), 1);

    nomeArqAjuda := dirProg + '\intercap.htm';
    extMostrada := '*.pag';

    strPCopy (def, dirProg + '\homepage');
    GetPrivateProfileString ('INTERCAP', 'PASTAPADRAO', def, valor, 255, 'intercap.ini');
    dirAtual := strPas (valor);

    getPrivateProfileString ('INTERCAP', 'arq1', '', p, 255, 'intercap.ini');
    ultimosDir [1] := strPas (p);
    getPrivateProfileString ('INTERCAP', 'arq2', '', p, 255, 'intercap.ini');
    ultimosDir [2] := strPas (p);
    getPrivateProfileString ('INTERCAP', 'arq3', '', p, 255, 'intercap.ini');
    ultimosDir [3] := strPas (p);
    getPrivateProfileString ('INTERCAP', 'arq4', '', p, 255, 'intercap.ini');
    ultimosDir [4] := strPas (p);
    getPrivateProfileString ('INTERCAP', 'arq5', '', p, 255, 'intercap.ini');
    ultimosDir [5] := strPas (p);
end;

procedure TForm1.CriaMenuReabrir1Click(Sender: TObject);
begin
    N11.Caption := ultimosDir [1];
    N21.Caption := ultimosDir [2];
    N31.Caption := ultimosDir [3];
    N41.Caption := ultimosDir [4];
    N51.Caption := ultimosDir [5];
end;

procedure TForm1.btnExtensaoClick(Sender: TObject);
begin
    if memo1.Modified then
       if MessageDlg('Texto foi alterado, carrega outro sem salvar?',
          mtConfirmation, [mbYes, mbNo], 0) = mrNo then
            exit;
    extMostrada := '*.'+(Sender as TButton).Caption;
    if extMostrada = '*.*.*' then
        extMostrada := '*.*';
    lbArqRefresh('');
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
    if memo1.modified then
       if MessageDlg('Termina o programa sem salvar a edição?',
            mtConfirmation, [mbYes, mbNo], 0) <> mrYes then
                   action := caNone;
end;

procedure TForm1.Memo1Change(Sender: TObject);
begin
    ajustaLinCol;
end;

procedure TForm1.Memo1Click(Sender: TObject);
begin
    ajustaLinCol;
end;

procedure TForm1.Memo1KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
    ajustaLinCol;
end;

procedure TForm1.Tabela1Click(Sender: TObject);
var s, exemplo: string;
    l, c, v, erro: integer;
begin
   if inputQuery ('Dimensão da tabela', 'Quantas colunas?', s) then
       begin
           val (s, v, erro);
           if (v <= 0) or (v > 10) then
               v := 3;

           clipboard.Clear;
           exemplo := '';
           for l := 1 to 2 do
               for c := 1 to v do
                   exemplo := exemplo + intToStr(l*10+c) + CRLF;
           clipboard.asText := '@' + intToStr(v) + CRLF + exemplo + '@' + CRLF;

           memo1.PasteFromClipboard;
           clipboard.Clear;
       end;
end;

procedure TForm1.Botao1Click(Sender: TObject);
begin
    memo1.copyToClipboard;
    OKEloDlg.e_texto.text := clipboard.asText;
    OKEloDlg.showModal;
    if OKEloDlg.ok then
        begin
            clipboard.asText := '<button>' + CRLF + '{' + OKEloDlg.e_referencia.text + ' ' +
                              OKEloDlg.e_texto.text + '}' + CRLF + '</button>' + CRLF;
            memo1.PasteFromClipboard;
            clipboard.Clear;
        end;
end;

procedure TForm1.Formulario1Click(Sender: TObject);
begin
    dicasForm.showModal;
end;

end.

