{*****************************************************************************
 *
 *  FMSelectMail.pas - Select mails before download  (30-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
 *  ----------- --- ----------------------------------------------------------
 *
 *****************************************************************************}

unit FMSelectMail;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  GradForm,
  ExtCtrls, StdCtrls, ComCtrls, ImgList, EnhListView, ExtListView, PXStuff,
  Menus;

type
  TSelectMailForm = class(TdfsGradientForm)
    Button3: TButton;
    Button5: TButton;
    Button6: TButton;
    ImageList1: TImageList;
    Button1: TButton;
    Notebook1: TNotebook;
    Label4: TLabel;
    Label7: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Image1: TImage;
    Image2: TImage;
    Image3: TImage;
    Image4: TImage;
    Label2: TLabel;
    Bevel2: TBevel;
    Label1: TLabel;
    Label8: TLabel;
    Label10: TLabel;
    Label9: TLabel;
    Image5: TImage;
    Label11: TLabel;
    Bevel3: TBevel;
    Label3: TLabel;
    ListView1: TdfsExtListView;
    PopupMenu1: TPopupMenu;
    DownloadandDelete1: TMenuItem;
    Delete1: TMenuItem;
    KeeponServer1: TMenuItem;
    DownloadandKeeponServer1: TMenuItem;
    procedure ListView1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure ListView1DrawHeader(Control: TWinControl;
      var ACanvas: TCanvas; Index: Integer; var ARect: TRect;
      Selected: Boolean; var DefaultDrawing: Boolean);
    procedure Button1Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure DownloadandDelete1Click(Sender: TObject);
    procedure ListView1SortBegin(Sender: TObject; SortColumn: Integer;
      Ascending: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  SelectMailForm: TSelectMailForm;

implementation


{$R *.DFM}

procedure TSelectMailForm.ListView1MouseDown(Sender: TObject; Button:
  TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  Item: TListItem;
  I: Integer;
begin
  if (X > 0) and (X < 18) then begin
    Item := ListView1.GetItemAt(X, Y);
    if Assigned(Item) then begin
      I := Item.StateIndex;
      Inc(I);
      if I > 3 then
        I := 0;
      Item.StateIndex := I;
    end;
  end;
end;

procedure TSelectMailForm.FormCreate(Sender: TObject);
begin
  Button1.Caption := Label9.Caption;
  //Resources
  ImageList1.ResourceLoad(rtBitmap, 'PX501', clFuchsia);
  ListView1.ReadSettings;
end;

procedure TSelectMailForm.FormDestroy(Sender: TObject);
begin
  ListView1.WriteSettings;
end;

procedure TSelectMailForm.ListView1DrawHeader(Control: TWinControl;
  var ACanvas: TCanvas; Index: Integer; var ARect: TRect;
  Selected: Boolean; var DefaultDrawing: Boolean);
begin
  if Index = 0 then begin
    DefaultDrawing := False;
    ACanvas.BrushCopy(Rect(ARect.Left + 2, ARect.Top, ARect.Left + 18, ARect.Top
      + 16), Image5.Picture.Bitmap, Rect(0, 0, 16, 16), clFuchsia);
  end
  else
    DefaultDrawing := True;
end;

procedure TSelectMailForm.Button1Click(Sender: TObject);
begin
  if NoteBook1.ActivePage = 'Legend' then begin
    NoteBook1.ActivePage := 'Mails';
    Button1.Caption := Label9.Caption;
  end
  else begin
    NoteBook1.ActivePage := 'Legend';
    Button1.Caption := Label10.Caption;
  end;
end;

procedure TSelectMailForm.Button6Click(Sender: TObject);
begin
  Application.HelpContext(5);
end;

// AH08 --
procedure TSelectMailForm.DownloadandDelete1Click(Sender: TObject);
var il : integer;
    p : TListItem;
begin
  if Sender is TMenuItem then
  begin
    il := (Sender as TMenuItem).ImageIndex;
    p := ListView1.Selected;
    while p <> nil do
    begin
      p.StateIndex := il;
      p := ListView1.GetNextItem(p, sdAll, [isSelected]);
    end;
  end;
end;

procedure TSelectMailForm.ListView1SortBegin(Sender: TObject;
  SortColumn: Integer; Ascending: Boolean);
begin
  // sorting dates
  if SortColumn >= 4 then
    ListView1.AutoSortStyle := assSmart
  else
    ListView1.AutoSortStyle := assDefault;
end;

initialization
   PMRegistry.AddCustomClass(TSelectMailForm, 'TSelectMailForm');

end.
