home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 25 / nopv25.iso / 035A / COMPED2.ZIP / IMAGEWIN.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-03-05  |  5.6 KB  |  193 lines

  1. unit ImageWin;
  2.  
  3. interface
  4. {THIS UNIT WAS BORROWED FROM THE BORLAND DEMOS AND MODIFIED}
  5. uses Windows, Classes, Graphics, Forms, Controls,
  6.   FileCtrl, StdCtrls, ExtCtrls, Buttons, Spin, ComCtrls;
  7.  
  8. type
  9.   TImageForm = class(TForm)
  10.     DirectoryListBox1: TDirectoryListBox;
  11.     DriveComboBox1: TDriveComboBox;
  12.     FileEdit: TEdit;
  13.     UpDownGroup: TGroupBox;
  14.     SpeedButton1: TSpeedButton;
  15.     BitBtn1: TBitBtn;
  16.     DisabledGrp: TGroupBox;
  17.     SpeedButton2: TSpeedButton;
  18.     BitBtn2: TBitBtn;
  19.     Panel1: TPanel;
  20.     Image1: TImage;
  21.     FileListBox1: TFileListBox;
  22.     Label2: TLabel;
  23.     ViewBtn: TBitBtn;
  24.     Bevel1: TBevel;
  25.     Bevel2: TBevel;
  26.     FilterComboBox1: TFilterComboBox;
  27.     GlyphCheck: TCheckBox;
  28.     StretchCheck: TCheckBox;
  29.     UpDownEdit: TEdit;
  30.     UpDown1: TUpDown;
  31.     OkBtn: TBitBtn;
  32.     CancelBtn: TBitBtn;
  33.     procedure FileListBox1Click(Sender: TObject);
  34.     procedure ViewBtnClick(Sender: TObject);
  35.     procedure ViewAsGlyph(const FileExt: string);
  36.     procedure GlyphCheckClick(Sender: TObject);
  37.     procedure StretchCheckClick(Sender: TObject);
  38.     procedure FileEditKeyPress(Sender: TObject; var Key: Char);
  39.     procedure UpDownEditChange(Sender: TObject);
  40.     procedure FormCreate(Sender: TObject);
  41.     procedure FormHide(Sender: TObject);
  42.   private
  43.     FormCaption: string;
  44.   Public
  45.     Procedure SetMasks(Const FilterMask : String;
  46.                        Const EditMask   : String;
  47.                        Const ListMask   : String);
  48.     Procedure IconsOnly;
  49.     Procedure BmpsOnly(IsGlyph : Boolean);
  50.   end;
  51.  
  52. var
  53.   ImageForm: TImageForm;
  54.  
  55. implementation
  56.  
  57. uses SysUtils,ViewImg;
  58. {$R *.DFM}
  59. procedure TImageForm.FileListBox1Click(Sender: TObject);
  60. var
  61.   FileExt: string[4];
  62. begin
  63.   FileExt := UpperCase(ExtractFileExt(FileListBox1.Filename));
  64.   if (FileExt = '.BMP') or (FileExt = '.ICO') or (FileExt = '.WMF') or
  65.     (FileExt = '.EMF') then
  66.   begin
  67.     Image1.Picture.LoadFromFile(FileListBox1.Filename);
  68.     Caption := FormCaption + ExtractFilename(FileListBox1.Filename);
  69.     if (FileExt = '.BMP') then
  70.     begin
  71.       Caption := Caption +
  72.         Format(' (%d x %d)', [Image1.Picture.Width, Image1.Picture.Height]);
  73.       ViewImageForm.Image1.Picture := Image1.Picture;
  74.       ViewImageForm.Caption := Caption;
  75.       if GlyphCheck.Checked then ViewAsGlyph(FileExt);
  76.     end;
  77.     if FileExt = '.ICO' then Icon := Image1.Picture.Icon;
  78.     if (FileExt = '.WMF') or (FileExt = '.EMF') then
  79.       ViewImageForm.Image1.Picture.Metafile := Image1.Picture.Metafile;
  80.   end;
  81. end;
  82.  
  83. procedure TImageForm.GlyphCheckClick(Sender: TObject);
  84. begin
  85.   ViewAsGlyph(UpperCase(ExtractFileExt(FileListBox1.Filename)));
  86. end;
  87. procedure TImageForm.ViewBtnClick(Sender: TObject);
  88. begin
  89.   ViewImageForm.HorzScrollBar.Range := Image1.Picture.Width;
  90.   ViewImageForm.VertScrollBar.Range := Image1.Picture.Height;
  91.   ViewImageForm.Caption := Caption;
  92.   ViewImageForm.ShowModal;
  93.   ViewImageForm.WindowState := wsNormal;
  94. end;
  95. procedure TImageForm.ViewAsGlyph(const FileExt: string);
  96. begin
  97.   if GlyphCheck.Checked and (FileExt = '.BMP') then
  98.   begin
  99.     SpeedButton1.Glyph := Image1.Picture.Bitmap;
  100.     SpeedButton2.Glyph := Image1.Picture.Bitmap;
  101.     UpDown1.Position := SpeedButton1.NumGlyphs;
  102.     BitBtn1.Glyph := Image1.Picture.Bitmap;
  103.     BitBtn2.Glyph := Image1.Picture.Bitmap;
  104.     UpDown1.Enabled := True;
  105.     UpDownEdit.Enabled := True;
  106.     Label2.Enabled := True;
  107.   end
  108.   else begin
  109.     SpeedButton1.Glyph := nil;
  110.     SpeedButton2.Glyph := nil;
  111.     BitBtn1.Glyph := nil;
  112.     BitBtn2.Glyph := nil;
  113.     UpDown1.Enabled := False;
  114.     UpDownEdit.Enabled := False;
  115.     Label2.Enabled := False;
  116.   end;
  117. end;
  118.  
  119. procedure TImageForm.UpDownEditChange(Sender: TObject);
  120. begin
  121.   SpeedButton1.NumGlyphs := UpDown1.Position;
  122.   SpeedButton2.NumGlyphs := UpDown1.Position;
  123. end;
  124.  
  125. procedure TImageForm.StretchCheckClick(Sender: TObject);
  126. begin
  127.   Image1.Stretch := StretchCheck.Checked;
  128. end;
  129.  
  130. procedure TImageForm.FileEditKeyPress(Sender: TObject; var Key: Char);
  131. begin
  132.   if Key = #13 then
  133.   begin
  134.     FileListBox1.ApplyFilePath(FileEdit.Text);
  135.     Key := #0;
  136.   end;
  137. end;
  138.  
  139. procedure TImageForm.FormCreate(Sender: TObject);
  140. begin
  141.   FormCaption := Caption + ' - ';
  142. end;
  143.  
  144. Procedure TImageForm.SetMasks(Const FilterMask : String;
  145.                               Const EditMask   : String;
  146.                               Const ListMask   : String);
  147. begin
  148.   FilterComboBox1.Filter:=FilterMask;
  149.   FileEdit.Text:=EditMask;
  150.   FileListBox1.Mask:=ListMask;
  151. end;
  152. Procedure TImageForm.IconsOnly;
  153. begin
  154.   SetMasks('Icon Files(*.ico)*.ico','*.ico','*.ico');
  155.   FileEdit.Enabled:=False;
  156.   FilterCombobox1.Enabled:=False;
  157.   ViewBtn.Enabled:=False;
  158.   GlyphCheck.Enabled:=False;
  159.   StretchCheck.Enabled:=False;
  160.   ViewAsGlyph('.ICO');
  161. end;
  162. Procedure TImageForm.BmpsOnly(IsGlyph : Boolean);
  163. begin
  164.   SetMasks('Bitmap Files(*.bmp)*.bmp','*.bmp','*.bmp');
  165.   FileEdit.Enabled:=False;
  166.   FilterCombobox1.Enabled:=False;
  167.   If IsGlyph then
  168.   begin
  169.     GlyphCheck.Checked:=True;
  170.     ViewAsGlyph('.BMP');
  171.   end
  172.   else
  173.     ViewAsGlyph('.ICO');
  174. end;
  175. procedure TImageForm.FormHide(Sender: TObject);
  176. begin
  177.   SetMasks(
  178.   'Image Files (*.bmp, *.ico, *.wmf, *.emf)|'+
  179.   '*.bmp;*.ico;*.wmf;*.emf|Bitmap Files (*.bmp)|'+
  180.   '*.bmp|Icons (*.ico)|*.ico|Metafiles (*.wmf, *.emf)|*.wmf;*.emf|All files (*.*)|*.*',
  181.   '*.bmp;*.ico;*.wmf;*.emf','*.bmp;*.ico;*.wmf;*.emf');
  182.   ViewAsGlyph('.ICO');
  183.   FileEdit.Enabled:=True;
  184.   FilterCombobox1.Enabled:=True;
  185.   GlyphCheck.Enabled:=True;
  186.   StretchCheck.Enabled:=True;
  187.   UpDownEdit.Enabled:=True;
  188.   UpDown1.Enabled:=True;
  189.   ViewBtn.Enabled:=False;
  190. end;
  191.  
  192. end.
  193.