{*****************************************************************************
 *
 *  FMEnviro.pas - Environment Options Form  (16-August-1998)
 *
 *  Copyright (c) 1998-99 Michael Haller
 *
 *  Author:     Michael Haller
 *  E-mail:     michael@discountdrive.com
 *  Homepage:   http://www.discountdrive.com/sunrise            
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation;
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
 *
 *----------------------------------------------------------------------------
 *
 *  Revision history:
 *
 *     DATE     REV                 DESCRIPTION
 *  ----------- --- ----------------------------------------------------------
 *
 *  2000-2001       Stefan Ascher + Roland Ruder
 *  2001-2002       Roland Ruder + Arthur Hoogervorst
 *****************************************************************************}

unit FMEnviro;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
//  Roland,
  GradForm, inifiles, StdCtrls, PXStuff, ExtCtrls, ComCtrls, Buttons, NumEdit,
  FileCtrl, ComboBoxEx, Mask, ParserSup, ImgList, ToolWin,FMAccount,
  PMLanguage, CheckLst;

type
  THitBox = array[0..5] of TColor; // AH16
  TLabelBox = array[0..2] of TColor; // AH16

  TEnviroForm = class(TForm)
    Panel1: TPanel;
    PageControl1: TPageControl;
    TabSheetNormal: TTabSheet;
    OpenDialog1: TOpenDialog;
    TabSheetRead: TTabSheet;
    FontDialog1: TFontDialog;
    LblNormal: TLabel;
    Bevel4: TBevel;
    CheckBox5: TCheckBox;
    CheckBox7: TCheckBox;
    TabSheet4: TTabSheet;
    Bevel6: TBevel;
    CheckBox8: TCheckBox;
    Label10: TLabel;
    CheckBox10: TCheckBox;
    ChkBoxDefaultMail: TCheckBox;
    TabSheetView: TTabSheet;
    Label1Text: TLabel;
    txtTextViewer: TEdit;
    btnBrowseTextViewer: TSpeedButton;
    NumEdit1: TNumEdit;
    UpDown2: TUpDown;
    TabSheet2: TTabSheet;
    Label5: TLabel;
    Bevel3: TBevel;
    Label21: TLabel;
    Edit5: TEdit;
    Label6: TLabel;
    Edit6: TEdit;
    Label22: TLabel;
    CheckBox17: TCheckBox;
    ComboBoxEx1: TPMComboBoxEx;
    NumEdit2: TNumEdit;
    UpDown3: TUpDown;
    Label26: TLabel;
    CheckBox2: TCheckBox;
    TabSheetSound: TTabSheet;
    LblSound: TLabel;
    Bevel10: TBevel;
    LblNewMail: TLabel;
    Edit7: TEdit;
    SpeedButton3: TSpeedButton;
    LblError: TLabel;
    Edit8: TEdit;
    SpeedButton4: TSpeedButton;
    CheckBox19: TCheckBox;
    LblDescribe: TLabel;
    Label31: TLabel;
    Edit9: TEdit;
    Label32: TLabel;
    Edit10: TEdit;
    Label33: TLabel;
    Edit11: TEdit;
    LblInfo: TLabel;
    Edit12: TEdit;
    SpeedButton6: TSpeedButton;
    TabSheet8: TTabSheet;
    Bevel14: TBevel;
    CheckBox23: TCheckBox;
    CheckBox24: TCheckBox;
    chkEmptyTrash: TCheckBox;
    TabSheet7: TTabSheet;
    chkAutodetectURL: TCheckBox;
    chkSelectionMargin: TCheckBox;
    Label36: TLabel;
    NumEdit4: TNumEdit;
    UpDown5: TUpDown;
    Label40: TLabel;
    Bevel17: TBevel;
    Label41: TLabel;
    chkEmptyReposit: TCheckBox;
    LabelQuick: TLabel;
    txtQuickView: TEdit;
    Bevel1: TBevel;
    SpeedButton2: TSpeedButton;
    TabSheet9: TTabSheet;
    Bevel19: TBevel;
    Label43: TLabel;
    Label15: TLabel;
    txtQuoteChar: TEdit;
    chkScrollDown: TCheckBox;
    chkClearSearchHis: TCheckBox;
    TabSheet10: TTabSheet;
    LabelGra: TLabel;
    txtPicView: TEdit;
    SpeedButton7: TSpeedButton;
    Label17: TLabel;
    NumEdit3: TNumEdit;
    UpDown4: TUpDown;
    Label44: TLabel;
    Label45: TLabel;
    Bevel23: TBevel;
    chkScrollUp: TCheckBox;
    chkFlatStyle: TCheckBox;
    chkUseBook: TCheckBox;
    chkShowDefaultAccount: TCheckBox;
    dlgColours: TColorDialog;
    Panel4: TPanel;
    SpeedButton8: TSpeedButton;
    Label37: TLabel;
    chkHighlightQuoted: TCheckBox;
    TabSheet11: TTabSheet;
    Bevel25: TBevel;
    Label42: TLabel;
    LabelEdit1: TEdit;
    LabelEdit2: TEdit;
    LabelEdit3: TEdit;
    LabelEdit4: TEdit;
    LabelEdit5: TEdit;
    LabelEdit6: TEdit;
    LabelEdit7: TEdit;
    chkAutoMarkReplied: TCheckBox;
    LabelEdit8: TEdit;
    LabelEdit9: TEdit;
    LblSendRec: TLabel;
    chkUseColouredLabels: TCheckBox;
    RadioGroup1: TRadioGroup;
    TabSheet12: TTabSheet;
    Bevel11: TBevel;
    Label13: TLabel;
    PaintBox1: TPaintBox;
    Label51: TLabel;
    PaintBox2: TPaintBox;
    Label52: TLabel;
    Label53: TLabel;
    PaintBox3: TPaintBox;
    GroupBox2: TGroupBox;
    cboColours: TComboBox;
    Button1: TButton;
    Bevel18: TBevel;
    CheckBox9: TCheckBox;
    Label54: TLabel;
    CheckBox20: TCheckBox;
    TabSheet13: TTabSheet;
    chkUseDrafts: TCheckBox;
    Bevel9: TBevel;
    LblReadControl: TLabel;
    chkIgnoreDiposit: TCheckBox;
    chkAddABReply: TCheckBox;
    btnClearSearch: TButton;
    GroupBox1: TGroupBox;
    Image0: TImage;
    Image4: TImage;
    Image5: TImage;
    Image6: TImage;
    Label38: TLabel;
    Label47: TLabel;
    Roman1: TRadioButton;
    Classic0: TRadioButton;
    Classic1: TRadioButton;
    Roman0: TRadioButton;
    TabSheet14: TTabSheet;
    CheckBox4: TCheckBox;
    CheckBox6: TCheckBox;
    CheckBox1: TCheckBox;
    CheckBox18: TCheckBox;
    Bevel5: TBevel;
    PaintBox4: TPaintBox;
    Label16: TLabel;
    Bevel20: TBevel;
    ComboBox2: TComboBox;
    ComboBox1: TComboBox;
    SpeedButton9: TSpeedButton;
    Panel2: TPanel;
    CheckBox21: TCheckBox;
    Bevel21: TBevel;
    Label7: TLabel;
    Button4: TButton;
    ComboBox3: TComboBox;
    Bevel22: TBevel;
    Label50: TLabel;
    Label55: TLabel;
    NumEdit5: TNumEdit;
    UpDown6: TUpDown;
    Button2: TButton;
    TabSheet15: TTabSheet;
    CreateCustomINIButton: TButton;
    SelectLanguage: TLabel;
    LanguageFiles: TCheckListBox;
    Bevel27: TBevel;
    Button3: TButton;
    Button6: TButton;
    lblAuthor: TLabel;
    Bevel28: TBevel;
    Label57: TLabel;
    lblAgent: TLabel;
    lblComment: TLabel;
    Label29: TLabel;
    Image1: TImage;
    Label1: TLabel;
    Label3: TLabel;
    Edit1: TEdit;
    SpeedButton5: TSpeedButton;
    Edit2: TEdit;
    CheckBox3: TCheckBox;
    chkAutoScan: TCheckBox;
    Label4: TLabel;
    rgAtt: TRadioGroup;
    Label11: TLabel;
    Bevel2: TBevel;
    LabelOpenMethord: TLabel;
    Image2: TImage;
    Image3: TImage;
    LblAlert: TLabel;
    Bevel15: TBevel;
    chkWarnDelToTrash: TCheckBox;
    chkWarnDelPermanent: TCheckBox;
    Label48: TLabel;
    Bevel24: TBevel;
    chkWarnOpen: TCheckBox;
    Image7: TImage;
    Image8: TImage;
    Bevel8: TBevel;
    Image9: TImage;
    Image10: TImage;
    Bevel7: TBevel;
    Image11: TImage;
    Image12: TImage;
    TabShe: TTabSheet;
    SpeedButton1: TSpeedButton;
    SpeedButton10: TSpeedButton;
    SpeedButton11: TSpeedButton;
    Memo1: TMemo;
    ListView1: TListView;
    LblSignatrue: TLabel;
    Bevel12: TBevel;
    Label56: TLabel;
    Bevel13: TBevel;
    LblDisplay: TLabel;
    LblSecond: TLabel;
    CheckBox12: TCheckBox;
    CheckBoxEvery: TCheckBox;
    Edit3: TNumEdit;
    UpDown1: TUpDown;
    LblChkMail: TLabel;
    CheckBox13: TCheckBox;
    MaskEdit1: TMaskEdit;
    CheckBox14: TCheckBox;
    MaskEdit2: TMaskEdit;
    Image13: TImage;
    TbShtReceipt: TTabSheet;
    Label2: TLabel;
    Bevel16: TBevel;
    Label8: TLabel;
    ChkNeedReceipt: TCheckBox;
    Label9: TLabel;
    Bevel26: TBevel;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    RadioButton3: TRadioButton;
    CheckBox15: TCheckBox;
    Label12: TLabel;
    btnOk: TButton;
    btnCancel: TButton;
    btnApply: TButton;
    procedure FormShow(Sender: TObject);
    procedure SpeedButton5Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure CheckBoxEveryClick(Sender: TObject);
    procedure CheckBox17Click(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
    procedure SpeedButton4Click(Sender: TObject);
    procedure SpeedButton6Click(Sender: TObject);
    procedure btnBrowseTextViewerClick(Sender: TObject);
    procedure chkHighlightQuotedClick(Sender: TObject);
    procedure btnClearSearchClick(Sender: TObject);
    procedure SpeedButton7Click(Sender: TObject);
    procedure chkScrollDownClick(Sender: TObject);
    procedure chkScrollUpClick(Sender: TObject);
    procedure SpeedButton8Click(Sender: TObject);
    procedure Panel4DblClick(Sender: TObject);
    procedure LabelEdit8DblClick(Sender: TObject);
    procedure CheckBox24Click(Sender: TObject);
    procedure PaintBox1Paint(Sender: TObject);
    procedure cboColoursDrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Button1Click(Sender: TObject);
    procedure cboColoursClick(Sender: TObject);
    procedure Label51Click(Sender: TObject);
    procedure CheckBox9Click(Sender: TObject);
    procedure Roman0Click(Sender: TObject);
    procedure PaintBox4Paint(Sender: TObject);
    procedure PaintBox4Click(Sender: TObject);
    procedure SpeedButton9Click(Sender: TObject);
    procedure dfsGradientFormDestroy(Sender: TObject);
    procedure ComboBox1Click(Sender: TObject);
    procedure btnOkClick(Sender: TObject);
    procedure ComboBox3Change(Sender: TObject);
    procedure ComboBox3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure CreateCustomINIButtonClick(Sender: TObject);
    procedure LanguageFilesClickCheck(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure LanguageFilesClick(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure ListView1Click(Sender: TObject);
    procedure ListView1Edited(Sender: TObject; Item: TListItem;
      var S: String);
    procedure SpeedButton11Click(Sender: TObject);
    procedure Memo1Change(Sender: TObject);
    procedure Memo1Exit(Sender: TObject);
    procedure Memo1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
    WindowHitBox : THitBox;
    LabelHitBox : TLabelBox;
    OtherColour : TColor;
    lRect, rRect : TRect;
    Filename,fInputCaption,fFolderName:string;
     Save: Boolean;
    function PointInWhichHitBox(Apoint : TPoint; var anum : integer) : Boolean;
    function GetColour(Acolor : TColor) : integer;
    function GetSchemes : string;
    procedure LoadScheme(astring : string);
    procedure SaveScheme(astring : string);
    procedure DoStatus(Sender : TObject; Current, Total : LongInt);
    procedure GetLanguages;
    procedure CreateAutoPanel;
  public
    { Public declarations }
    AppearanceList : TList;
    MyProgress : TProgressBar;
    MyPanel : TPanel;
    MyLabel : TLabel;
    Node:TtreeNode;
    procedure GetOptions;
    procedure SetOptions;
    procedure Actualize;
    procedure DoSave;
  end;

const
    ColourValues : array[0..40] of TColor =
     (clAqua, clBlack, clBlue, clFuchsia, clGray,
     clGreen, clLime, clMaroon,clNavy,clOlive,
     clPurple, clRed, clSilver, clTeal, clWhite,
     clYellow, cl3DDkShadow, cl3DLight, clActiveBorder, clActiveCaption,
     clAppWorkSpace, clBackground, clBtnFace, clBtnHighlight, clBtnShadow,
     clBtnText, clCaptionText, clGrayText, clHighlight, clHighlightText,
     clInactiveBorder, clInactiveCaption, clInactiveCaptionText, clInfoBk,
     clInfoText,
     clMenu, clMenuText, clScrollBar, clWindow, clWindowFrame, clWindowText);

var
  EnviroForm: TEnviroForm;

implementation

{$R *.DFM}

uses
  Main, pmclasses, RichEdit2;


procedure TEnviroForm.GetLanguages;
var
  SearchRec: TSearchRec;
  Found, i : Integer;
begin
  // Loop through all the lng files.
  LanguageFiles.Clear;
  LanguageFiles.Items.Add('(default)');
  Found := FindFirst(GetAppPath + '*.lng', faAnyFile, SearchRec);
  while Found = 0 do
  begin
    i:= LanguageFiles.Items.Add(SearchRec.Name);
    if DefaultLanguage + '.lng' = SearchRec.Name then
      LanguageFiles.Checked[i] := True;
    Found := FindNext(SearchRec);
  end;
  FindClose(SearchRec);
end;

procedure TEnviroForm.CreateAutoPanel;
begin
  MyPanel := TPanel.Create(Self);
  MyPanel.Parent := TabSheet15;
  MyPanel.Width := TabSheet15.Width;
  MyPanel.Height := 30;
  MyPanel.Left := 0;
  MyPanel.Top := (TabSheet15.ClientHeight div 2) - (MyPanel.Height div 2);
  MyPanel.Visible := True;
  MyPanel.Caption := '';
  MyProgress := TProgressBar.Create(MyPanel);
  MyProgress.Parent := MyPanel;
  MyProgress.Align := alBottom;
  MyProgress.Height := 10;
  MyProgress.Min := 0; MyProgress.Max := LangHolder.FormCount -1;
  MyProgress.Position := 0;
  MyProgress.Smooth := True;
  MyProgress.Visible := True;
  MyLabel := TLabel.Create(MyPanel);
  MyLabel.Parent := MyPanel;
  MyLabel.Align := alTop;
  MyLabel.AutoSize := False;
  MyLabel.Visible := True;
  MyLabel.Name := 'out_label';
end;

function TEnviroForm.GetSchemes : string;
var
  SearchRec: TSearchRec;
  Found : Integer;
  s : string;
begin
//  result := '(Roman)';
  result := '칵훰';
  Found := FindFirst(getapppath + '*.pcs', faAnyFile, SearchRec);
  while Found = 0 do
  begin
    s := SearchRec.Name;
    Delete(s, Length(s) - 3, 4);
    Result := result + #13#10 + s;
    Found := FindNext(SearchRec);
  end;
  FindClose(SearchRec);
end;

procedure TEnviroForm.SaveScheme(astring : string);
var t : TIniFile;
begin
  t := TIniFile.Create(astring);
  try
    t.WriteInteger('Settings', 'ActStartColor', WindowHitBox[0]);
    t.WriteInteger('Settings', 'ActEndColor',  WindowHitBox[1]);
    t.WriteInteger('Settings', 'ActFontColor', LabelHitBox[0]);
    t.WriteInteger('Settings', 'inActStartColor',WindowHitBox[2]);
    t.WriteInteger('Settings', 'inActEndColor', WindowHitBox[3]);
    t.WriteInteger('Settings', 'InActFontColor', LabelHitBox[1]);
    t.WriteInteger('Settings', 'LabelStartColor', WindowHitBox[4]);
    t.WriteInteger('Settings', 'LabelEndColor', WindowHitBox[5]);
    t.WriteInteger('Settings', 'LabelFontColor', LabelHitBox[2]);
    t.WriteBool('Settings', 'PlainColours', CheckBox9.Checked);
    t.WriteBool('Settings', 'DitheredCaption', CheckBox20.checked);
    TPanelAppearance(AppearanceList.Items[0]).SaveToIni('ListView1', t);
    TPanelAppearance(AppearanceList.Items[1]).SaveToIni('TreeView1', t);
    TPanelAppearance(AppearanceList.Items[2]).SaveToIni('RichEdit1', t);
    t.WriteBool('Style', 'HighlightQuoted', chkHighlightQuoted.Checked);
    if ChkHighLightQuoted.checked then
    begin
      t.WriteInteger('Style', 'QuotedSize', Panel4.Font.Size);
      t.WriteInteger('Style', 'QuotedColor', Panel4.Font.Color);
      t.WriteString('Style', 'QuoteStyles',  StyleToString(Panel4.Font.Style));
      t.WriteInteger('Style', 'QuotedColorBack', Panel4.Color);
    end;
  finally
    t.Free;
  end;
end;



//TODO -oMjg:config color of main form
procedure TEnviroForm.LoadScheme(astring : string);
var t : TIniFile;
begin
  if (Trim(astring) = '') then exit;
  if astring = '칵훰' then
  begin

    WindowHitBox[0] := clBlue;
    WindowHitBox[1] := clBlue;
    WindowHitBox[2] := clBlue;
    WindowHitBox[3] := clBlue;
    WindowHitBox[4] := clBtnFace;
    WindowHitBox[5] := clBtnFace;

    LabelHitBox[0] := clWhite;
    LabelHitBox[1] := clWhite;
    LabelHitBox[2] := clBlack;

    CheckBox9.Checked := False;
    CheckBox20.checked := True;
    TPanelAppearance(AppearanceList.Items[0]).UseDefault;
    TPanelAppearance(AppearanceList.Items[1]).UseDefault;
    TPanelAppearance(AppearanceList.Items[2]).UseDefault;
    chkHighLightQuoted.OnClick := nil;
    chkHighlightQuoted.Checked := False;
    chkHighLightQuoted.OnClick := ChkHighLightQuotedClick;
    Panel4.Font.Assign(TPanelAppearance(AppearanceList.Items[2]).Font);
    Panel4.Enabled := False;
    SpeedButton8.Enabled := False;
    Panel4.Caption := ' ' + Panel4.Font.Name + '   ' + IntToStr(iSizeQuoted);
  end
  else
  begin
    if FileExists(astring) then
    begin
      t := TIniFile.Create(astring);
      try
        WindowHitBox[0] :=
           TColor(t.ReadInteger('Settings', 'ActStartColor', clBlack));
        WindowHitBox[1] :=
          TColor(t.ReadInteger('Settings', 'ActEndColor', clInfoBK));
        LabelHitBox[0] :=
          TColor(t.ReadInteger('Settings', 'ActFontColor', clWhite));
        WindowHitBox[2] := TColor(t.ReadInteger('Settings', 'inActStartColor',
          clBlack));
        WindowHitBox[3] := TColor(t.ReadInteger('Settings', 'inActEndColor',
          clInActivecaption));
        LabelHitBox[1] := TColor(t.ReadInteger('Settings', 'InActFontColor',
          clWhite));
        WindowHitBox[4] := TColor(t.ReadInteger('Settings', 'LabelStartColor',
          clBtnShadow));
        WindowHitBox[5] :=
          TColor(t.ReadInteger('Settings', 'LabelEndColor', clInfoBk));
        LabelHitBox[2] :=
          TColor(t.ReadInteger('Settings', 'LabelFontColor', clWhite));
        CheckBox9.Checked := t.ReadBool('Settings', 'PlainColours', False);
        CheckBox20.checked := t.ReadBool('Settings', 'DitheredCaption', True);
        TPanelAppearance(AppearanceList.Items[0]).LoadFromIni('ListView1', t);
        TPanelAppearance(AppearanceList.Items[1]).LoadFromIni('TreeView1', t);
        TPanelAppearance(AppearanceList.Items[2]).LoadFromIni('RichEdit1', t);
        chkHighLightQuoted.OnClick := nil;
        chkHighlightQuoted.Checked :=
          t.ReadBool('Style', 'HighlightQuoted', False);
        chkHighLightQuoted.OnClick := ChkHighLightQuotedClick;
        if ChkHighLightQuoted.Checked then
        begin
          Panel4.Font.Name :=
            TPanelAppearance(AppearanceList.Items[2]).Font.Name;
          Panel4.Font.Size := t.ReadInteger('Style', 'QuotedSize', 8);
          Panel4.Font.Color :=
            TColor(t.ReadInteger('Style', 'QuotedColor', clWindowText));
          Panel4.Font.Style :=
            StringToStyle(t.ReadString('Style', 'QuoteStyles', '[]'));
          Panel4.Color := TColor(t.ReadInteger('Style', 'QuotedColorBack',
            clInfoBk));
          Panel4.Enabled := True;
          SpeedButton8.Enabled := True;
        end
        else
        begin
          Panel4.Font.Assign(TPanelAppearance(AppearanceList.Items[2]).Font);
          Panel4.Enabled := False;
          SpeedButton8.Enabled := False;
        end;
        Panel4.Caption := ' '
          + Panel4.Font.Name + '   ' + IntToStr(Panel4.Font.Size);
      finally
        t.Free;
      end;
    end;
  end;
  ComboBox1Click(Self);
end;

function TEnviroForm.GetColour(Acolor : TColor) : integer;
var x : integer;
begin
  Result := -1;
  for x := 0 to high(ColourValues) do
  begin
    if AColor = ColourValues[x] then
    begin
      Result := x;
      break
    end;
  end;
end;

procedure TEnviroForm.GetOptions;
begin
  CheckBox1.Checked := bMakeProtocol;
  CheckBox3.Checked := bVirusMin;
  CheckBox8.Checked := bFriendlyPrinter;
  Edit1.Text := sVirusProg;
  Edit2.Text := sVirusParams;
  chkAutoScan.Checked := bVirusAutoScan;
  txtTextViewer.Text := sTextViewer;
  txtQuickView.Text := sQuickViewer;
  txtPicView.Text := sPicViewer;
  CheckBox4.Checked := bAskToGoOffline;
  CheckBox6.Checked := bAskForDelFromServer;
  chkEmptyTrash.Checked := bEmptyTrashWhenExit;
  chkEmptyReposit.Checked := bEmptyRepositWhenExit;
  chkClearSearchHis.Checked := bClearSearchHisWhenExit;


  ChkNeedReceipt.Checked:=bNeedReceipt;
  if bReceipt=0 then RadioButton1.Checked:=true  ;  //never send receipt
  if bReceipt=1 then RadioButton2.Checked:=true  ;  //Notify me when need receipt
  if bReceipt=2 then RadioButton3.Checked:=true  ;  //always send receipt


  LabelEdit1.text := sLabel1;
  LabelEdit1.Color := MainForm.ListView1.Color;
  LabelEdit2.text := sLabel2;
  LabelEdit2.Color := MainForm.ListView1.Color;
  LabelEdit3.text := sLabel3;
  LabelEdit3.Color := MainForm.ListView1.Color;
  LabelEdit4.text := sLabel4;
  LabelEdit4.Color := MainForm.ListView1.Color;
  LabelEdit5.text := sLabel5;
  LabelEdit5.Color := MainForm.ListView1.Color;
  LabelEdit6.text := sLabel6;
  LabelEdit6.Color := MainForm.ListView1.Color;
  LabelEdit7.text := sLabel7;
  LabelEdit7.Color := MainForm.ListView1.Color;
  LabelEdit8.text := sLabel8;
  LabelEdit8.Color := MainForm.ListView1.Color;
  LabelEdit9.text := sLabel9;
  LabelEdit9.Color := MainForm.ListView1.Color;

  chkHighlightQuoted.Checked := bHighlightQuoted;

  CheckBox7.Checked := bGoOnlineAtStart;
  CheckBox5.Checked := bStartAtWindowsStart;
  CheckBoxEvery.Checked := bScheduleC1;
  CheckBox12.Checked := bScheduleC2;
  CheckBox13.Checked := bScheduleC3;
  CheckBox14.Checked := bScheduleC4;
  CheckBox10.Checked := bScheduleC5;
  MaskEdit1.Text := sScheduleS2;
  MaskEdit2.Text := sScheduleS3;
  ChkBoxDefaultMail.Checked := bCheckForStdEMail;
  CheckBoxEveryClick(Self);
  // AHRK19 CheckBox16.Checked := bListMailsAtDownload;
  ComboBoxEx1.ItemIndex := ComboBoxEx1.Values.IndexOf(sDUNConnection);
  Edit5.Text := sDUNUsername;
  Edit6.Text := sDUNPassword;
  Checkbox17.Checked := bDUNAskForPassword;
  UpDown1.Position := sScheduleS1;
  UpDown2.Position := iMarkAsReadSec;
  UpDown3.Position := iDUNAutoQuitTime;
  UpDown4.Position := iLineBreakAt;
  CheckBox2.Checked := bDUNAutoQuit;
  CheckBox18.Checked := bViewStatusAtEnd;
  Edit7.Text := sSoundFile1;
  Edit8.Text := sSoundFile2;
  Edit12.Text := sSoundFile3;
  CheckBox19.Checked := bDUNNormalQuit;
  Edit9.Text := sAccountsCaption;
  Edit10.Text := sTrashBagCaption;
  Edit11.Text := sRepositoryCaption;
  CheckBox23.Checked := bShowCntInBrackets;
  CheckBox24.Checked := bHideAnimations;
  chkIgnoreDiposit.Checked := bIgnoreDipositRequest;

  chkUseColouredLabels.Checked := bUseColouredLabels;

  chkAddABReply.Checked := bAddToAddressBookWhenReply;
  with MainForm do begin
    chkAutodetectURL.Checked := (RichEdit1.AutoURLDetect = adDefault);
    UpDown5.Position := RichEdit1.UndoLimit;
    chkSelectionMargin.Checked := RichEdit1.ShowSelectionBar;
  end;

  txtQuoteChar.Text := GetMessageString(92);
  chkWarnDelToTrash.Checked := bWarnBeforeDelToTrash;
  chkWarnDelPermanent.Checked := bWarnBeforeDelPermanent;
  chkScrollUp.Checked := bSelectFirstItem;
  chkScrollDown.Checked := bSelectLastItem;
  chkFlatStyle.Checked := bFlatStyle;
  chkUseDrafts.Checked := bUseDrafts;
  chkUseBook.Checked := bUsePMBook;
  chkWarnOpen.Checked := bWarnOpen;
  chkShowDefaultAccount.Checked := bShowDefaultAccount;
  chkAutoMarkReplied.Checked := bAutoMarkReplied;
  rgAtt.ItemIndex := iDoubleClickAction;

   // AH16 TabSheet2.TabVisible := MainForm.DialUp1.RasInstalled;
  if not MainForm.DialUp1.RasInstalled then begin
    CheckBox19.Checked := False;
    CheckBox2.Checked := False;
    CheckBox10.Checked := False;
    CheckBox4.Checked := False;
    CheckBox19.Visible := False;
    CheckBox2.Visible := False;
    CheckBox10.Visible := False;
    CheckBox4.Visible := False;
    Label29.Visible := False;
    Label26.Visible := False;
    NumEdit2.Visible := False;
    UpDown3.Visible := False;
  end;
  CheckBox17Click(Self);
  RadioGroup1.ItemIndex := iAnimation;

  case iPanelsStyle of
    0: ROman0.checked := true;
    1: Roman1.checked := true;
    2: Classic0.checked := true;
    3: Classic1.checked := true;
  end;

  WindowHitBox[0] := actStartColor;
  WindowHitBox[1] := actEndColor;
  WindowHitBox[2] := inActStartColor;
  WindowHitBox[3] := inActEndColor;
  WindowHitBox[4] := lblStartColor;
  WindowHitBox[5] := lblEndColor;

  LabelHitBox[0] := actFontColor;
  LabelHitBox[1] := inActFontColor;
  LabelHitBox[2] := lblFontColor;

  OtherColour := clBtnFace;

  CheckBox9.Checked := bPlainColours;
  CheckBox20.checked := bDitheredCaption;
  CheckBox21.Checked := Boolean(iLV2Icons);
  Updown6.Position := iAutoCompleteItems;
  GetLanguages;
end;

procedure TEnviroForm.SetOptions;
var
  i: integer;
  s : string;
begin
  bMakeProtocol := CheckBox1.Checked;
  bVirusMin := CheckBox3.Checked;
  bFriendlyPrinter := CheckBox8.Checked;
  sVirusProg := Edit1.Text;
  sVirusParams := Edit2.Text;
  bVirusAutoScan := chkAutoScan.Checked;
  sTextViewer := txtTextViewer.Text;
  sQuickViewer := txtQuickView.Text;
  sPicViewer := txtPicView.Text;
  bAskToGoOffline := CheckBox4.Checked;
  bAskForDelFromServer := CheckBox6.Checked;
  bEmptyTrashWhenExit := chkEmptyTrash.Checked;
  bEmptyRepositWhenExit := chkEmptyReposit.Checked;
  bClearSearchHisWhenExit := chkClearSearchHis.Checked;

  if RadioButton1.Checked then bReceipt:=0;  //never send receipt
  if RadioButton2.Checked then bReceipt:=1;  //Notify me when need receipt
  if RadioButton3.Checked then bReceipt:=2;  //always send receipt
  bNeedReceipt:=ChkNeedReceipt.Checked;


  sLabel1 := LabelEdit1.text;
  sLabel2 := LabelEdit2.Text;
  sLabel3 := LabelEdit3.Text;
  sLabel4 := LabelEdit4.Text;
  sLabel5 := LabelEdit5.Text;
  sLabel6 := LabelEdit6.Text;
  sLabel7 := LabelEdit7.Text;
  sLabel8 := LabelEdit8.Text;
  sLabel9 := LabelEdit9.Text;


  bGoOnlineAtStart := CheckBox7.Checked;
  bStartAtWindowsStart := CheckBox5.Checked;
  bScheduleC1 := CheckBoxEvery.Checked;
  bScheduleC2 := CheckBox12.Checked;
  bScheduleC3 := CheckBox13.Checked;
  bScheduleC4 := CheckBox14.Checked;
  bScheduleC5 := CheckBox10.Checked;
  sScheduleS2 := MaskEdit1.Text;
  sScheduleS3 := MaskEdit2.Text;
  bCheckForStdEMail := ChkBoxDefaultMail.Checked;

  sDUNConnection := ComboBoxEx1.Values[ComboBoxEx1.ItemIndex];
  sDUNUsername := Edit5.Text;
  sDUNPassword := Edit6.Text;
  bDUNAskForPassword := Checkbox17.Checked;
  bDUNAutoQuit := CheckBox2.Checked;
  bViewStatusAtEnd := CheckBox18.Checked;
  sScheduleS1 := UpDown1.Position;
  iMarkAsReadSec := UpDown2.Position;
  iDUNAutoQuitTime := UpDown3.Position;
  iLineBreakAt := UpDown4.Position;
  iAutoCompleteItems := Byte(Updown6.Position);

  if iLineBreakAt >= 255 then iLineBreakAt := 255;

  sSoundFile1 := Edit7.Text;
  sSoundFile2 := Edit8.Text;
  sSoundFile3 := Edit12.Text;
  bDUNNormalQuit := Checkbox19.Checked;
  sAccountsCaption := Edit9.Text;
  sTrashBagCaption := Edit10.Text;
  sRepositoryCaption := Edit11.Text;
  bHideAnimations := CheckBox24.Checked;
  bUseColouredLabels := chkUseColouredLabels.Checked;

  bAddToAddressBookWhenReply := chkAddABReply.Checked;
  bIgnoreDipositRequest := chkIgnoreDiposit.Checked;

  bWarnBeforeDelToTrash := chkWarnDelToTrash.Checked;
  bWarnBeforeDelPermanent := chkWarnDelPermanent.Checked;
  bSelectFirstItem := chkScrollUp.Checked;
  bSelectLastItem := chkScrollDown.Checked;
  bFlatStyle := chkFlatStyle.Checked;
  bUseDrafts := chkUseDrafts.Checked;
  bUsePMBook := chkUseBook.Checked;
  bWarnOpen := chkWarnOpen.Checked;
  bShowDefaultAccount := chkShowDefaultAccount.Checked;
  bAutoMarkReplied := chkAutoMarkReplied.Checked; //RR26

  with MainForm, MainForm.RichEdit1, MainForm.TreeView1 do begin
    AccountsNode.Text := sAccountsCaption;

    bShowCntInBrackets := CheckBox23.Checked;
    for I := 0 to Items.Count - 1 do
      SetPXTreeNodeName(Items[I]);

    DefaultFont.Assign(TPanelAppearance(AppearanceList.Items[2]).Font);

    DefAttributes.Assign(DefaultFont);
    SelAttributes.Assign(DefaultFont);
    if chkAutodetectURL.Checked then
      AutoURLDetect := adDefault
    else
      AutoURLDetect := adNone;
    UndoLimit := UpDown5.Position;
    ShowSelectionBar := chkSelectionMargin.Checked;
  end;

  SetMessageString(92, txtQuoteChar.Text);
  bHighlightQuoted := chkHighlightQuoted.Checked;

  iSizeQuoted := Panel4.Font.Size;
  cColorQuoted := Panel4.Font.Color;
  cBackColorQuoted := Panel4.Color;
  sQuoteStyles := StyleToString(Panel4.Font.Style);

  iDoubleClickAction := rgAtt.ItemIndex;
  with MainForm.PopupMenu2 do begin
    for i := 0 to Items.Count - 1 do
      Items[i].Default := false;
    Items[iDoubleClickAction].Default := true;
  end;
  iAnimation := RadioGroup1.ItemIndex;

  bPlainColours := CheckBox9.Checked;
  bDitheredCaption := CheckBox20.Checked;

  //TODO -oMjg:write config file about head of main form in color
  actStartColor := WindowHitBox[0];
  actEndColor := WindowHitBox[1] ;
  inActStartColor := WindowHitBox[2];
  inActEndColor := WindowHitBox[3];
  lblStartColor := WindowHitBox[4] ;
  lblEndColor := WindowHitBox[5];

  actFontColor := LabelHitBox[0];
  inActFontColor := LabelHitBox[1];
  lblFontColor :=LabelHitBox[2];
  iLV2Icons := Ord(CheckBox21.Checked);
  s := '';
  for i := 1 to LanguageFiles.Items.Count -1 do
  begin
    if LanguageFiles.Checked[i] = True then
    begin
      s := LanguageFiles.Items[i];
      break;
    end
  end;
  DefaultLanguage := Copy(s, 1, Pos('.lng', s) - 1);
end;


procedure TEnviroForm.FormShow(Sender: TObject);
begin
  GetOptions;
  ComboBox2.ItemIndex := 0;
  ComboBox1.ItemIndex := 0;
  ComboBox1Click(Self);
end;

procedure TEnviroForm.SpeedButton5Click(Sender: TObject);
begin

  OpenDialog1.FileName := Edit1.Text;
  OpenDialog1.Title := GetMessageString(160);
  OpenDialog1.Filter := GetMessageString(161);
  if OpenDialog1.Execute then
    Edit1.Text := OpenDialog1.Filename;
end;

function EnumFontsProc(var LogFont: TLogFont; var TextMetric: TTextMetric;
  FontType: Integer; Data: Pointer): Integer; stdcall;
begin
  TStrings(Data).Add(LogFont.lfFaceName);
  Result := 1;
end;

procedure TEnviroForm.FormCreate(Sender: TObject);
var
  I,Found: Integer;
  SearchRec: TSearchRec;
  fFolderName:string;
  Item: TListItem;
begin
  PageControl1.ActivePage := TabSheetNormal;
  UpDown1.Min := Edit3.Min;
  UpDown1.Max := Edit3.Max;
  UpDown2.Min := NumEdit1.Min;
  UpDown2.Max := NumEdit1.Max;
  UpDown3.Min := NumEdit2.Min;
  UpDown3.Max := NumEdit2.Max;



  with ComboBoxEx1 do begin
    if MainForm.DialUp1.RasInstalled then begin
      Items.Assign(MainForm.DialUp1.PossibleConnections);
      Values.Assign(MainForm.DialUp1.PossibleConnections);
    end;
    Items.Insert(0, GetMessageString(79));
    Values.Insert(0, '');
    ItemIndex := 0;
    ImgIndexes.Add('13');
    for I := 0 to Items.Count - 1 do
      ImgIndexes.Add('12');
  end;

  if iColorDepth <= 8 then begin
    Edit3.Enabled := False;
  end;

  Edit6.PasswordChar := '*';

  Combobox1.ItemIndex := 0;
  Combobox2.Itemindex := 0;

  AppearanceList := TList.Create;
  // Add these manually...
  AppearanceList.Add(TPanelAppearance.Create);
  TPanelAppearance(AppearanceList.Items[0]).Font.Name := sLVFontName;
  TPanelAppearance(AppearanceList.Items[0]).Font.Size := iLVFontSize;
  TPanelAppearance(AppearanceList.Items[0]).Font.Style := fsLVFontStyle;
  TPanelAppearance(AppearanceList.Items[0]).Font.Color := iLVFontColour;
  TPanelAppearance(AppearanceList.Items[0]).BackGround := iLVBackGround;
  AppearanceList.Add(TPanelAppearance.Create(MainForm.TreeView1));
  AppearanceList.Add(TPanelAppearance.Create(MainForm.RichEdit1));
  ComboBox3.Items.Text := GetSchemes;



  ListView1.Column[0].Caption := GetMessageString(166);
//  fFolderName := sTemplateFolder;
  fFolderName := sSignatureFolder;

  Found := FindFirst(fFolderName + '*.txt', faAnyFile, SearchRec);
  while Found = 0 do begin
    SetFileAttr(fFolderName + SearchRec.Name, False, True, False, False);
    Item := ListView1.Items.Add;
    Item.SubItems.Add(fFolderName + SearchRec.Name);
    Delete(SearchRec.Name, Length(SearchRec.Name) - 3, 4);
    Item.Caption := SearchRec.Name;
    Found := FindNext(SearchRec);
  end;
  FindClose(SearchRec);
  Save:=false;

end;

procedure TEnviroForm.CheckBoxEveryClick(Sender: TObject);
begin
  LblChkMail.Enabled := CheckBoxEvery.Checked;
  Edit3.Enabled := CheckBoxEvery.Checked;
  UpDown1.Enabled := CheckBoxEvery.Checked;
  CheckBox13.Enabled := CheckBox12.Checked;
  CheckBox14.Enabled := CheckBox12.Checked;
  if not CheckBox13.Enabled then
    CheckBox13.Checked := False;
  if not CheckBox14.Enabled then
    CheckBox14.Checked := False;
  MaskEdit1.Enabled := CheckBox13.Checked;
  MaskEdit2.Enabled := CheckBox14.Checked;
  Label29.Enabled := CheckBox2.Checked;
  Label26.Enabled := CheckBox2.Checked;
  NumEdit2.Enabled := CheckBox2.Checked;
  UpDown3.Enabled := CheckBox2.Checked;
end;

procedure TEnviroForm.CheckBox17Click(Sender: TObject);
var
  B: Boolean;
begin
  B := (ComboBoxEx1.Values[ComboBoxEx1.ItemIndex] <> '');
  Label6.Enabled := B;
  Label22.Enabled := B;
  Edit5.Enabled := B;
  Edit6.Enabled := B;
  Checkbox17.Enabled := B;
  if B then
    Edit6.Enabled := not CheckBox17.Checked;
end;

procedure TEnviroForm.SpeedButton3Click(Sender: TObject);
begin
  OpenDialog1.FileName := Edit7.Text;
  OpenDialog1.Title := GetMessageString(162);
  OpenDialog1.Filter := GetMessageString(163);
  if OpenDialog1.Execute then
    Edit7.Text := OpenDialog1.Filename;
end;

procedure TEnviroForm.SpeedButton4Click(Sender: TObject);
begin
  OpenDialog1.FileName := Edit8.Text;
  OpenDialog1.Title := GetMessageString(162);
  OpenDialog1.Filter := GetMessageString(163);
  if OpenDialog1.Execute then
    Edit8.Text := OpenDialog1.Filename;
end;

procedure TEnviroForm.SpeedButton6Click(Sender: TObject);
begin
  OpenDialog1.FileName := Edit12.Text;
  OpenDialog1.Title := GetMessageString(162);
  OpenDialog1.Filter := GetMessageString(163);
  if OpenDialog1.Execute then
    Edit12.Text := OpenDialog1.Filename;
end;

procedure TEnviroForm.btnBrowseTextViewerClick(Sender: TObject);
begin
  OpenDialog1.FileName := txtTextViewer.Text;
  OpenDialog1.Title := GetMessageString(160);
  OpenDialog1.Filter := GetMessageString(161);
  if OpenDialog1.Execute then
    txtTextViewer.Text := OpenDialog1.Filename;
end;

procedure TEnviroForm.SpeedButton2Click(Sender: TObject);
begin
  OpenDialog1.FileName := txtQuickView.Text;
  OpenDialog1.Title := GetMessageString(160);
  OpenDialog1.Filter := GetMessageString(161);
  if OpenDialog1.Execute then
    txtQuickView.Text := OpenDialog1.Filename;
end;

procedure TEnviroForm.chkHighlightQuotedClick(Sender: TObject);
begin
  if not chkHighLightQuoted.checked then
  begin
    Panel4.Font.Assign(TPanelAppearance(AppearanceList.Items[2]).Font);
    Panel4.Enabled := False;
    SpeedButton8.Enabled := False;
  end
  else
  begin
    Panel4.Font.Name := TPanelAppearance(AppearanceList.Items[2]).Font.Name;
    Panel4.Font.Size := iSizeQuoted; // AH15
    Panel4.Font.Color := cColorQuoted;
    Panel4.Font.Style := StringToStyle(sQuoteStyles);
    Panel4.Color := cBackColorQuoted;
    Panel4.Enabled := True;
    SpeedButton8.Enabled := True;
  end;
  Panel4.Caption := ' ' + Panel4.Font.Name + '   ' + IntToStr(iSizeQuoted);
end;

procedure TEnviroForm.btnClearSearchClick(Sender: TObject);
begin
  if FileExists(GetAppPath + 'mfhis.txt') then
    DeleteFile(GetAppPath + 'mfhis.txt');
  if FileExists(GetAppPath + 'afhis.txt') then
    DeleteFile(GetAppPath + 'afhis.txt');
end;

procedure TEnviroForm.SpeedButton7Click(Sender: TObject);
begin
  OpenDialog1.FileName := txtPicView.Text;
  OpenDialog1.Title := GetMessageString(160);
  OpenDialog1.Filter := GetMessageString(161);
  if OpenDialog1.Execute then
    txtPicView.Text := OpenDialog1.Filename;
end;

procedure TEnviroForm.chkScrollUpClick(Sender: TObject);
begin
  if chkScrollUp.Checked then chkScrollDown.Checked := false;
end;

procedure TEnviroForm.chkScrollDownClick(Sender: TObject);
begin
  if chkScrollDown.Checked then chkScrollUp.Checked := false;
end;


procedure TEnviroForm.SpeedButton8Click(Sender: TObject);
begin
  FontDialog1.Font:=Panel4.Font; //RR04h
  FontDialog1.Font.Color:=Panel4.Font.Color; //RR04h
  FontDialog1.Font.Style := StringToStyle(sQuoteStyles);
  if FontDialog1.Execute then
  begin
    // AHRJ01
    Panel4.Font.Name := TPanelAppearance(AppearanceList.Items[2]).Font.Name;
    Panel4.Font.Size := FontDialog1.Font.Size; // AH15
    Panel4.Font.Style := FontDialog1.Font.Style;
    Panel4.Font.Color := FontDialog1.Font.Color;
    Panel4.Caption := ' ' + Panel4.Font.Name + '   ' +
      IntToStr(FontDialog1.Font.Size); // AH15
  end;
end;

procedure TEnviroForm.Panel4DblClick(Sender: TObject);
begin
  if dlgColours.Execute then
  begin
    Panel4.Color := dlgColours.Color;
    cBackColorQuoted := Panel4.Color;
  end;
end;

procedure TEnviroForm.LabelEdit8DblClick(Sender: TObject);
begin
  LabelEdit8.Text:='ギ';
end;

procedure TEnviroForm.CheckBox24Click(Sender: TObject);
begin
  RadioGroup1.Enabled := not CheckBox24.checked;
end;

procedure TEnviroForm.PaintBox1Paint(Sender: TObject);
var dy : integer;
    startCol, EndCol : TColor;
begin

  StartCol := clBtnShadow;
  EndCol := clInfoBk;

  if Sender = PaintBox1 then
  begin
    StartCol := WindowHitBox[0];
    EndCol := WindowHitBox[1];
  end;

  if Sender = PaintBox2 then
  begin
    StartCol := WindowHitBox[2];
    EndCol := WindowHitBox[3];
  end;

  if Sender = PaintBox3 then
  begin
    StartCol := WindowHitBox[4];
    EndCol := WindowHitBox[5];
  end;

  CreateGradientBitmap(1, startCol, EndCol, (Sender as TPaintBox).Canvas,
   (Sender as TPaintBox).ClientRect, 1);

  dy := (Sender as TPaintBox).Height div 2;

  lRect.Left := 4;
  lRect.Top :=  dy - (dy div 2);
  lRect.Right := lrect.left + dy;
  lRect.Bottom := lrect.top + dy;
  (Sender as TPaintBox).Canvas.Pen.Color := EndCol;
  (Sender as TPaintBox).Canvas.Brush.Color := StartCol;
  (Sender as TPaintBox).Canvas.Rectangle(lrect);

  rRect.Top := dy - (dy div 2);
  rRect.Left := lRect.left + lrect.right + 4;
  rRect.Right := rRect.Left + dy;
  rRect.Bottom := Rrect.top + dy;

  (Sender as TPaintBox).Canvas.Pen.Color := StartCol;
  (Sender as TPaintBox).Canvas.Brush.Color := EndCol;
  (Sender as TPaintBox).Canvas.Rectangle(rrect);

  Label51.Font.Color := LabelHitBox[0];
  Label52.Font.Color := LabelHitBox[1];
  Label53.Font.Color := LabelHitBox[2];
end;

procedure TEnviroForm.PaintBox4Paint(Sender: TObject);
begin
  PaintBox4.Canvas.Pen.Color := clBlack;
  PaintBox4.Canvas.Brush.Color := OtherColour;
  PaintBox4.Canvas.Rectangle(PaintBox4.ClientRect);
end;

procedure TEnviroForm.cboColoursDrawItem(Control: TWinControl;
  Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
   fillcolor, textcolor : TColor;
   BoxRect : TRect;
begin
  if (odSelected in state) then
  begin
    fillcolor := clHighLight;
    TextColor := clHighLightText;
  end
  else
  begin
    fillcolor := clWindow;
    TextColor := clWindowText;
  end;

  BoxRect.left := Rect.Left + 2;
  BoxRect.Top := Rect.Top + 2;
  BoxRect.Right := Rect.Left + 15;
  BoxRect.Bottom := Rect.Bottom - 2;

  with cboColours.canvas do
  begin
    Brush.Color := FillColor;
    FillRect(Rect);
    Brush.Color := ColourValues[index];
    Fillrect(BoxRect);
    Brush.Color := clActiveBorder;
    FrameRect(Boxrect);
    Brush.Color := fillColor;
    Pen.Color := TextColor;
    Rect.left := Rect.left + 17;
    TextRect(Rect, rect.Left, Rect.Top, cboColours.Items[index]);
  end;
end;

function TEnviroForm.PointInWhichHitBox(Apoint : TPoint; var anum : integer) : Boolean;
  function CheckThisOne (Arect : TRect) : boolean;
  begin
    result := False;
    if (Apoint.x >= ARect.Left) and (APoint.x <= ARect.Right)
       and (Apoint.y <= ARect.Bottom) and (APoint.y >= ARect.Top) then
    begin
      Result := True;
    end;
  end;
begin
  anum := -1;
  Result := False;
  if CheckThisOne(lRect) then
  begin
    anum := 0;
    Result := True;
  end;
  if CheckThisOne(rRect) then
  begin
    anum := 1;
    Result := True;
  end;
end;

procedure TEnviroForm.PaintBox1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var HitBox : integer;
begin
  OtherColour := clBtnFace;
  if PointInWhichHitBox(Point(x, y), Hitbox) then
  begin
    if Sender = PaintBox1 then
    begin
      GroupBox2.Caption := label51.Caption;
      GroupBox2.Left := PaintBox1.Left;
      GroupBox2.Top := PaintBox1.Top;
      cboColours.ItemIndex := GetColour(WindowHitBox[HitBox]);
      if cboColours.ItemIndex = -1 then
      begin
        OtherColour := WindowHitBox[HitBox];
      end;
      cboColours.Tag := 0 + HitBox;
    end;

    if Sender = PaintBox2 then
    begin
      GroupBox2.Caption := label52.Caption;
      GroupBox2.Left := PaintBox2.Left;
      GroupBox2.Top := PaintBox2.Top;
      cboColours.ItemIndex := GetColour(WindowHitBox[2 + HitBox]);
      if cboColours.ItemIndex = -1 then
      begin
        OtherColour := WindowHitBox[2 + HitBox];
      end;
      cboColours.Tag := 2 + Hitbox;
    end;

    if Sender = PaintBox3 then
    begin
      GroupBox2.Caption := label53.Caption;
      GroupBox2.Left := PaintBox3.Left;
      GroupBox2.Top := PaintBox3.Top;
      cboColours.ItemIndex := GetColour(WindowHitBox[4 + HitBox]);
      if cboColours.ItemIndex = -1 then
      begin
        OtherColour := WindowHitBox[4 + HitBox];
      end;
      cboColours.Tag := 4 + Hitbox;
    end;
    PaintBox4.Refresh;
    GroupBox2.Visible := True;
  end;
end;

procedure TEnviroForm.Button1Click(Sender: TObject);
var
  Item: TListItem;
  S: string;
begin
  if InputQuery(fInputCaption, GetMessageString(43), S) then
  begin
//    ListView1.SortType := stNone;
    Item := ListView1.Items.Add;
    Item.Caption := S;
    Item.SubItems.Add(fFolderName + S + '.txt');
    AssignFile(F, Item.SubItems[0]);
    Rewrite(F);
    CloseFile(F);
    ListView1.Items[ListView1.Items.Count - 1].Selected := true;
    Actualize;
    Memo1.SetFocus;
  end;
end;

procedure TEnviroForm.cboColoursClick(Sender: TObject);
var MyColour : TColor;
begin
  MyColour := ColourValues[cboColours.ItemIndex];
  if cboColours.Tag < 6 then
    WindowHitBox[cboColours.Tag] := MyColour
  else
    LabelHitBox[cboColours.Tag - 6] := MyColour;

  // Make sure that OtherColour stays the same...
  OtherColour := clBtnFace;
  PaintBox4.Refresh;
  GroupBox2.Visible := False;
end;

procedure TEnviroForm.Label51Click(Sender: TObject);
begin
  OtherColour := clBtnFace;
  if Sender = Label51 then
  begin
    GroupBox2.Caption := Label51.Caption; //RR06a
    GroupBox2.Left := PaintBox1.Left;
    GroupBox2.Top := PaintBox1.Top;
    cboColours.ItemIndex := GetColour(Label51.Font.Color);
    if cboColours.ItemIndex = -1 then
    begin
      OtherColour := Label51.Font.Color;
    end;
    cboColours.Tag := 6;
  end;

  if Sender = Label52 then
  begin
    GroupBox2.Caption := Label52.Caption; //RR06a
    GroupBox2.Left := PaintBox2.Left;
    GroupBox2.Top := PaintBox2.Top;
    cboColours.ItemIndex := GetColour(Label52.Font.Color);
    if cboColours.ItemIndex = -1 then
    begin
      OtherColour := Label52.Font.Color;
    end;
    cboColours.Tag := 7;
  end;

  if Sender = Label53 then
  begin
    GroupBox2.Caption := Label53.Caption; //RR06a
    GroupBox2.Left := PaintBox3.Left;
    GroupBox2.Top := PaintBox3.Top;
    cboColours.ItemIndex := GetColour(Label53.Font.Color);
    if cboColours.ItemIndex = -1 then
    begin
      OtherColour := Label53.Font.Color; // AH16
    end;
    cboColours.Tag := 8;
  end;
  PaintBox4.Refresh; // AH16
  GroupBox2.Visible := True;
end;

procedure TEnviroForm.CheckBox9Click(Sender: TObject);
begin
  PaintBox1.Enabled := not CheckBox9.Checked;
  PaintBox2.Enabled := not CheckBox9.Checked;
  Label51.Enabled := not CheckBox9.Checked;
  Label52.Enabled := not Checkbox9.Checked;
end;

procedure TEnviroForm.Roman0Click(Sender: TObject);
begin
  if Sender = Roman0 then iPanelsStyle := 0;
  if Sender = Roman1 then iPanelsStyle := 1;
  if Sender = Classic0 then iPanelsStyle := 2;
  if Sender = Classic1 then iPanelsStyle := 3;
end;



procedure TEnviroForm.PaintBox4Click(Sender: TObject);
begin
  dlgColours.Options := [cdAnyColor, cdSolidColor, cdFullOpen];
  dlgColours.Color := OtherColour;
  if dlgColours.Execute then
  begin
    OtherColour := dlgColours.Color;
    // Deselect...
    cboColours.ItemIndex := -1;
    PaintBox4.Refresh;
  end;
end;

procedure TEnviroForm.SpeedButton9Click(Sender: TObject);
begin
  if ComboBox2.ItemIndex = 1 then
  begin
    dlgColours.Color := TPanelAppearance(
      AppearanceList.Items[ComboBox1.ItemIndex]).BackGround;
    if dlgColours.Execute then
    begin
      TPanelAppearance(AppearanceList.Items[ComboBox1.ItemIndex]).BackGround
        := dlgColours.Color;
      Panel2.Caption := ComboBox1.Items.Strings[ComboBox1.ItemIndex];
      Panel2.Color := dlgColours.Color;
    end;
  end
  else
  begin
    FontDialog1.Font.Assign(
      TPanelAppearance(AppearanceList.Items[ComboBox1.ItemIndex]).Font);
    if FontDialog1.Execute then
    begin
      TPanelAppearance(AppearanceList.Items[ComboBox1.ItemIndex]).Font.Assign(
        FontDialog1.Font);
      Panel2.Font.Assign(FontDialog1.Font);
    end;
  end;
  ComboBox1Click(Self);
end;

procedure TEnviroForm.dfsGradientFormDestroy(Sender: TObject);
var i : integer;
begin
  // Get rid of those things
  for i := 0 to AppearanceList.Count -1 do
  begin
    TPanelAppearance(AppearanceList.Items[i]).Free;
  end;
  AppearanceList.Free;
end;

procedure TEnviroForm.ComboBox1Click(Sender: TObject);
var i : integer;
begin
  i := ComboBox1.ItemIndex;
  Panel2.Caption := TPanelAppearance(AppearanceList.Items[i]).Font.Name + '-' +
    IntToStr(TPanelAppearance(AppearanceList.Items[i]).Font.Size);
  Panel2.Color :=
    TPanelAppearance(AppearanceList.Items[ComboBox1.ItemIndex]).BackGround;
  Panel2.Font.Assign(
    TPanelAppearance(AppearanceList.Items[ComboBox1.ItemIndex]).Font);
end;

procedure TEnviroForm.btnOkClick(Sender: TObject);
begin
  SetOptions;
//  WriteProfileString('www.rr4u.de', 'SMAIL', PChar(paramstr(0)));
end;

procedure TEnviroForm.ComboBox3Change(Sender: TObject);
begin
  Button4.Enabled := (ComboBox3.Text <> '') and
    not (ComboBox3.Text = ('칵훰'));
end;

procedure TEnviroForm.ComboBox3Click(Sender: TObject);
var s : string;
begin
  s := Trim(ComboBox3.Items.Strings[ComboBox3.ItemIndex]);
  if s = '칵훰' then
  begin
    LoadScheme(s);
  end
  else
  begin
    s := GetAppPath + s + '.pcs';
    if FileExists(s) then
    begin
      LoadScheme(s);
    end;
  end;
end;

procedure TEnviroForm.Button4Click(Sender: TObject);
begin
  ModalResult := mrOK;
end;


procedure TEnviroForm.Button2Click(Sender: TObject);
begin
  if ListView1.Selected = nil then
    Exit;
  DeleteFile(ListView1.Selected.SubItems[0]);
  ListView1.Selected.Delete;
  Actualize;
end;

procedure TEnviroForm.CreateCustomINIButtonClick(Sender: TObject);
var s : string;
begin
  // PMCreateCustomIni;
  if InputQuery('Language', 'Please enter the name of the language', s) then
  begin
    if s <> '' then
    begin
      if Pos('.', s) > 0 then
      begin
        Delete(s, pos('.', s), Length(s));
      end;
      CreateAutoPanel;
      LangHolder.OnStatusUpdate := DoStatus;
      LangHolder.CreateLanguageFile(S);
      LangHolder.OnStatusUpdate := nil;
      MyPanel.Free;
      GetLanguages;
    end;
  end;
end;

procedure TEnviroForm.DoStatus(Sender : TObject; Current, Total : LongInt);
begin
  MyProgress.Position := Current;
  MyLabel.Caption := LangHolder.FormNames[Current]; // AHRK
  Application.ProcessMessages;
end;

procedure TEnviroForm.LanguageFilesClickCheck(Sender: TObject);
var p, x : integer;
begin
  // Reset all other..
  p := LanguageFiles.ItemIndex;
  for x := 0 to LanguageFiles.Items.Count - 1 do
  begin
    if p <> x then
       LanguageFiles.Checked[x] := False;
  end;
end;

procedure TEnviroForm.Button6Click(Sender: TObject);
var s : string;
begin
  s := LanguageFiles.Items[LanguageFiles.ItemIndex];
  s := Copy(s, 1, Pos('.lng', s) - 1);
  if s <> '' then
  begin
    CreateAutoPanel;
    LangHolder.OnStatusUpdate := DoStatus;
    LangHolder.CreateLanguageFile(s, nil, True);
    LangHolder.OnStatusUpdate := nil;
    MyPanel.Free;
  end;
end;

procedure TEnviroForm.LanguageFilesClick(Sender: TObject);
var s : string;
    f : TIniFile;
begin
  if LanguageFiles.ItemIndex > 0 then
  begin
    s := LanguageFiles.Items[LanguageFiles.ItemIndex];
    if FileExists(GetAppPath + s) then
    begin
      f := TIniFile.Create(GetAppPath + s);
      lblAuthor.Caption := 'Author: ' + f.ReadString('General', 'Author', '');
      lblAgent.Caption := 'Agent: ' + f.ReadString('General', 'Agent', '');
      lblComment.Caption := 'Comment: ' + f.ReadString('General', 'Comments', '');
      f.Free;
    end;
  end;
end;

procedure TEnviroForm.Button3Click(Sender: TObject);
var s, t : string;
begin
  // Remove selected...
  if LanguageFiles.ItemIndex > 0 then
  begin
    // Remove this language, careful not to delete the language that
    // has been set as defaultLanguage
    s  := LanguageFiles.Items.Strings[LanguageFiles.ItemIndex];
    t  := Copy(s, 1, Pos('.', s) - 1);
    if DefaultLanguage <> '' then
    begin
      if AnsiPos(DefaultLanguage, s) <> 1 then
      begin
        if FileExists(GetAppPath + s) then
          DeleteFile(GetAppPath + s);
        if FileExists(GetAppPath + 'messages_'+ s + '.txt') then
          DeleteFile(GetAppPath + 'messages_'+ s+ '.txt');
      end;
    end;
  end;
end;

procedure TEnviroForm.ListView1Click(Sender: TObject);
begin
  Actualize;
  Memo1.enabled := ListView1.selected <> nil;

end;

procedure TEnviroForm.ListView1Edited(Sender: TObject; Item: TListItem;
  var S: String);
var t : string;
begin
  t := MakeValidDirName(ExtractFilePath(Item.SubItems[0]));
  if RenameFile(Item.SubItems[0], t + S + '.txt') then
  begin
    Item.SubItems[0] := t + S + '.txt'
  end;
end;

procedure TEnviroForm.Actualize;
var
  S: string;
begin
if   Save= True then
  dosave;
  Memo1.Lines.Clear;
  if ListView1.Selected <> nil then
  begin
    AssignFile(F, ListView1.Selected.SubItems[0]);
    Reset(F);
    while not EoF(F) do begin
      ReadLn(F, S);
      Memo1.Lines.Add(S);
    end;
    CloseFile(F);
    Memo1.Enabled := True;
    Button2.Enabled := True;
    SpeedButton1.Enabled := True;
    Filename := ListView1.Selected.SubItems[0];
  end
  else
  begin
    Button2.Enabled := False;
    Button4.Enabled := False;
    SpeedButton1.Enabled := False;
    Filename := '';
  end;
end;

procedure TEnviroForm.SpeedButton11Click(Sender: TObject);
begin
  if ListView1.Selected = nil then
    Exit;
  ListView1.Selected.EditCaption;
end;

procedure TEnviroForm.DoSave;
var
  I: Integer;
begin
  if Filename = '' then
    Exit;
  if ListView1.Selected <> nil then begin
    AssignFile(F, Filename);
    Rewrite(F);
    for I := 0 to Memo1.Lines.Count - 1 do
      WriteLn(F, Memo1.Lines[I]);
    CloseFile(F);
  end;
end;

procedure TEnviroForm.Memo1Change(Sender: TObject);
begin
Save:=true;
end;

procedure TEnviroForm.Memo1Exit(Sender: TObject);
begin
  if Save then
    DoSave;
end;

procedure TEnviroForm.Memo1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  Save := True;
end;

initialization
   PMRegistry.AddCustomClass(TEnviroForm, 'TEnviroForm');
//  NilVariant  := null;
end.

