2018-03-23 00:10:05 +00:00
|
|
|
{-----------------------------------------------------------------------------
|
|
|
|
The contents of this file are subject to the Mozilla Public License
|
|
|
|
Version 1.1 (the "License"); you may not use this file except in compliance
|
|
|
|
with the License. You may obtain a copy of the License at
|
|
|
|
http://www.mozilla.org/MPL/MPL-1.1.html
|
|
|
|
|
|
|
|
Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
|
|
|
|
the specific language governing rights and limitations under the License.
|
|
|
|
|
|
|
|
The Original Code is: JvThumbNail.PAS, released on 2002-07-03.
|
|
|
|
|
|
|
|
The Initial Developer of the Original Code is John Kozikopulos [Stdreamer att Excite dott com]
|
|
|
|
Portions created by John Kozikopulos are Copyright (C) 2002 John Kozikopulos.
|
|
|
|
All Rights Reserved.
|
|
|
|
|
|
|
|
Contributor(s):
|
|
|
|
|
|
|
|
You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
|
|
|
|
located at http://jvcl.delphi-jedi.org
|
|
|
|
|
|
|
|
Description:
|
|
|
|
Thumbimage, ThumbNail components
|
|
|
|
Thumbimage is a TImage descentant wich passes the control of the mouse events
|
|
|
|
to the ThumbNail and have the ability to change an images look by changing
|
|
|
|
the rgb values with the changergb,changergbcurve procedures.
|
|
|
|
You can have precise control over the images look.
|
|
|
|
The changergb procedure just adds the values you pass to its rgb variables to
|
|
|
|
the actual values of the image.
|
|
|
|
The Changergbcurves procedure just replaces the value of the rgb values
|
|
|
|
accordingly with the values that passed in the the arrays.
|
|
|
|
e.g.
|
|
|
|
the r array in the position 15 has a value of 35 this meens that wherever in
|
|
|
|
the Picture there is a pixels which has a red value equall to 15 it will be ]
|
|
|
|
replaced with the value 35.
|
|
|
|
|
|
|
|
ThumbNail is what the name says a component to simply shrink an image
|
|
|
|
proportionally to fit in a portion of the screen with some extra mouse handling
|
|
|
|
to Create a Button like effect. Just give it a FileName and it will do the work
|
|
|
|
for you.
|
|
|
|
|
|
|
|
Known Issues:
|
|
|
|
-----------------------------------------------------------------------------}
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
unit JvThumbnails;
|
|
|
|
|
|
|
|
{$MODE objfpc}{$H+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2018-04-21 14:46:46 +00:00
|
|
|
{$IFDEF WINDOWS}
|
|
|
|
Windows,
|
|
|
|
{$ENDIF}
|
|
|
|
{$IFDEF UNIX}
|
|
|
|
baseunix,
|
|
|
|
{$ENDIF}
|
2020-01-17 23:29:41 +00:00
|
|
|
LCLIntf, LCLType, LCLVersion, LMessages, Types,
|
2018-03-23 00:10:05 +00:00
|
|
|
Classes, Controls, ExtCtrls, SysUtils, Graphics, Forms,
|
|
|
|
JvThumbImage, JvBaseThumbnail, Dialogs;
|
|
|
|
|
|
|
|
const
|
|
|
|
TH_IMAGESIZECHANGED = WM_USER + 1;
|
|
|
|
|
|
|
|
type
|
|
|
|
// (rom) elements renamed
|
|
|
|
TTitlePos = (tpUp, tpDown, tpNone);
|
|
|
|
|
|
|
|
TTitleNotify = procedure(Sender: TObject; FileName: string;
|
|
|
|
var ThumbnailTitle: string) of object;
|
|
|
|
|
|
|
|
TJvThumbnail = class(TJvBaseThumbnail)
|
|
|
|
private
|
|
|
|
FTitle: string;
|
|
|
|
FTitlePanel: TJvThumbTitle;
|
|
|
|
FTitleColor: TColor;
|
|
|
|
FTitleFont: TFont;
|
|
|
|
FStreamFileKind: TGRFKind;
|
2018-04-21 14:46:46 +00:00
|
|
|
FDFileCreated: TDateTime;
|
|
|
|
FDFileChanged: TDateTime;
|
|
|
|
FDFileAccessed: TDateTime;
|
2018-03-23 00:10:05 +00:00
|
|
|
FShowTitle: Boolean;
|
|
|
|
FDFileSize: Longint;
|
|
|
|
FStream: TStream;
|
|
|
|
FImageWidth: Longint;
|
|
|
|
FImageHeight: Longint;
|
2018-03-23 23:59:33 +00:00
|
|
|
FThumbHeight: Word;
|
|
|
|
FThumbWidth: Word;
|
2018-03-23 00:10:05 +00:00
|
|
|
FShadowObj: TShape;
|
|
|
|
FUpdated: Boolean;
|
|
|
|
FImageReady: Boolean;
|
|
|
|
FTitlePlacement: TTitlePos;
|
|
|
|
FPhotoName: TJvFileName;
|
|
|
|
FPhoto: TJvThumbImage;
|
|
|
|
FOnGetTitle: TTitleNotify;
|
|
|
|
FMousePressed: Boolean;
|
|
|
|
FDestroying: Boolean;
|
|
|
|
FAsButton: Boolean;
|
|
|
|
FMinimizeMemory: Boolean;
|
|
|
|
FAutoLoad: Boolean; // if True then load the image either from a thumb file or Create it from the FileName
|
|
|
|
FShadowColor: TColor;
|
|
|
|
FShowShadow: Boolean;
|
|
|
|
FHShadowOffset: Word;
|
|
|
|
FVShadowOffset: Word;
|
2018-03-23 23:59:33 +00:00
|
|
|
FMargin: Integer;
|
2018-03-23 00:10:05 +00:00
|
|
|
(************** NOT CONVERTED ***
|
|
|
|
procedure PhotoOnProgress(Sender: TObject; Stage: TProgressStage;
|
|
|
|
PercentDone: Byte; RedrawNow: Boolean;
|
|
|
|
const R: TRect; const Msg: string);
|
|
|
|
*******************************)
|
2018-03-26 08:03:23 +00:00
|
|
|
procedure GetFileInfo(AName: string);
|
|
|
|
function GetFileName: string;
|
2018-03-25 00:04:05 +00:00
|
|
|
function GetTitleBevelInner: TPanelBevel;
|
|
|
|
function GetTitleBevelOuter: TPanelBevel;
|
|
|
|
function GetTitleBorderStyle: TBorderStyle;
|
2018-03-26 08:03:23 +00:00
|
|
|
function IsTitleFontStored: Boolean;
|
2018-03-23 00:10:05 +00:00
|
|
|
procedure RefreshFont(Sender: TObject);
|
2018-08-26 14:25:44 +00:00
|
|
|
procedure SetDummyCard({%H-}AInt: Longint);
|
|
|
|
procedure SetDummyStr({%H-}AStr: string);
|
2018-03-26 08:03:23 +00:00
|
|
|
procedure SetFileName(const AFile: string);
|
|
|
|
procedure SetMargin(AValue: Integer);
|
2018-03-23 00:10:05 +00:00
|
|
|
procedure SetMinimizeMemory(Min: Boolean);
|
2018-03-26 08:03:23 +00:00
|
|
|
//procedure SetShadowColor(aColor: TColor);
|
|
|
|
procedure SetShowShadow(AShow: Boolean);
|
|
|
|
procedure SetStream(const AStream: TStream);
|
2018-03-23 00:10:05 +00:00
|
|
|
procedure SetShowTitle(const AState: Boolean);
|
|
|
|
procedure SetTitle(const Value: string);
|
2018-03-25 00:04:05 +00:00
|
|
|
procedure SetTitleBevelInner(const Value: TPanelBevel);
|
|
|
|
procedure SetTitleBevelOuter(const Value: TPanelBevel);
|
|
|
|
procedure SetTitleBorderStyle(const Value: TBorderStyle);
|
2018-03-23 00:10:05 +00:00
|
|
|
procedure SetTitleColor(const Value: TColor);
|
|
|
|
procedure SetTitleFont(const Value: TFont);
|
2018-03-26 08:03:23 +00:00
|
|
|
procedure SetTitlePlacement(const AState: TTitlePos);
|
2018-03-25 00:04:05 +00:00
|
|
|
|
2018-03-23 00:10:05 +00:00
|
|
|
protected
|
2018-03-26 08:03:23 +00:00
|
|
|
procedure BoundsChanged; override;
|
|
|
|
procedure CalculateImageSize; virtual;
|
2018-03-23 23:59:33 +00:00
|
|
|
procedure CreateHandle; override;
|
2018-08-26 14:25:44 +00:00
|
|
|
procedure THSizeChanged(var {%H-}Msg: TLMessage); message TH_IMAGESIZECHANGED;
|
2018-03-23 00:10:05 +00:00
|
|
|
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
|
|
|
|
X, Y: Integer); override;
|
|
|
|
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
|
|
|
|
procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
|
|
|
|
X, Y: Integer); override;
|
2018-03-26 08:03:23 +00:00
|
|
|
function LoadFile(AFile: string): string;
|
|
|
|
procedure UpdateThumbHeight;
|
|
|
|
procedure UpdateThumbWidth;
|
|
|
|
procedure UpdateTitlePanelHeight;
|
|
|
|
procedure WMPaint(var Msg: TLMPaint); message LM_PAINT;
|
|
|
|
|
2020-01-17 23:29:41 +00:00
|
|
|
{ LCL Scaling }
|
|
|
|
protected
|
|
|
|
procedure DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy;
|
|
|
|
const AXProportion, AYProportion: Double); override;
|
|
|
|
public
|
|
|
|
procedure ScaleFontsPPI({$IF LCL_FullVersion >= 1080100}const AToPPI: Integer;{$IFEND}
|
|
|
|
const AProportion: Double); override;
|
|
|
|
{$IF LCL_FullVersion >= 2010000}
|
|
|
|
procedure FixDesignFontsPPI(const ADesignTimePPI: Integer); override;
|
|
|
|
{$IFEND}
|
|
|
|
|
2018-03-23 00:10:05 +00:00
|
|
|
public
|
|
|
|
constructor Create(AOwner: TComponent); override;
|
|
|
|
destructor Destroy; override;
|
|
|
|
procedure SetTitlePanel(ATitle: string; AFont: TFont; AColor: TColor);
|
|
|
|
procedure Refresh;
|
2018-03-26 08:03:23 +00:00
|
|
|
property ImageHeight: Longint read FImageHeight default 0;
|
|
|
|
property ImageReady: Boolean read FImageReady;
|
|
|
|
property ImageWidth: Longint read FImageWidth default 0;
|
2018-03-23 00:10:05 +00:00
|
|
|
property Stream: TStream read FStream write SetStream;
|
|
|
|
property Photo: TJvThumbImage read FPhoto write FPhoto;
|
|
|
|
published
|
2018-03-26 08:03:23 +00:00
|
|
|
property AutoLoad: Boolean read FAutoLoad write FAutoLoad default true;
|
|
|
|
property AsButton: Boolean read FAsButton write FAsButton default false;
|
2018-03-23 00:10:05 +00:00
|
|
|
property FileName: string read GetFileName write SetFileName;
|
2018-03-26 08:03:23 +00:00
|
|
|
property Margin: Integer read FMargin write SetMargin default 8;
|
|
|
|
property MinimizeMemory: Boolean read FMinimizeMemory write SetMinimizeMemory default true;
|
|
|
|
property ShadowColor: TColor read FShadowColor write FShadowColor;
|
|
|
|
property ShowShadow: Boolean read FShowShadow write SetShowShadow default false;
|
|
|
|
property ShowTitle: Boolean read FShowTitle write SetShowTitle default true;
|
|
|
|
property StreamFileType: TGRFKind read FStreamFileKind write FStreamFileKind default grBMP;
|
2018-03-23 00:10:05 +00:00
|
|
|
property Title: string read FTitle write SetTitle;
|
2018-03-25 00:04:05 +00:00
|
|
|
property TitleBevelInner: TPanelBevel read GetTitleBevelInner write SetTitleBevelInner default bvNone;
|
|
|
|
property TitleBevelOuter: TPanelBevel read GetTitleBevelOuter write SetTitleBevelOuter default bvLowered;
|
|
|
|
property TitleBorderStyle: TBorderStyle read GetTitleBorderStyle write SetTitleBorderStyle default bsNone;
|
2018-03-23 23:59:33 +00:00
|
|
|
property TitleColor: TColor read FTitleColor write SetTitleColor default clDefault;
|
|
|
|
property TitleFont: TFont read FTitleFont write SetTitleFont stored IsTitleFontStored;
|
2018-03-26 08:03:23 +00:00
|
|
|
property TitlePlacement: TTitlePos read FTitlePlacement write SetTitlePlacement default tpUp;
|
2018-03-23 00:10:05 +00:00
|
|
|
property OnGetTitle: TTitleNotify read FOnGetTitle write FOnGetTitle;
|
|
|
|
{ Do not store dummies }
|
2018-04-21 14:46:46 +00:00
|
|
|
property FileSize: Longint read FDFileSize stored false; // write SetDummyCard stored False;
|
|
|
|
property FileAccessed: TDateTime read FDFileAccessed stored false; // write SetDummyStr stored False;
|
|
|
|
property FileCreated: TDateTime read FDFileCreated stored false; // write SetDummyStr stored False;
|
|
|
|
property FileChanged: TDateTime read FDFileChanged stored false; // write SetDummyStr stored False;
|
2018-03-23 00:10:05 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
2018-04-21 14:46:46 +00:00
|
|
|
FileUtil, DateUtils,
|
2018-08-26 14:25:44 +00:00
|
|
|
JvThumbViews; //, JvResources;
|
2018-03-23 00:10:05 +00:00
|
|
|
|
|
|
|
constructor TJvThumbnail.Create(AOwner: TComponent);
|
|
|
|
begin
|
|
|
|
inherited Create(AOwner);
|
2018-03-23 23:59:33 +00:00
|
|
|
FShowTitle := True;
|
|
|
|
FMargin := 8;
|
2018-03-23 00:10:05 +00:00
|
|
|
FHShadowOffset := 3;
|
|
|
|
FVShadowOffset := 3;
|
|
|
|
FShowShadow := False;
|
|
|
|
FShadowColor := clSilver;
|
2018-03-23 23:59:33 +00:00
|
|
|
FTitleColor := clDefault; //clBtnFace;
|
|
|
|
FTitlePlacement := tpUp;
|
|
|
|
FTitle := '';
|
|
|
|
FUpdated := False;
|
|
|
|
|
|
|
|
FPhotoName := TJvFileName.Create;
|
|
|
|
|
2018-03-23 00:10:05 +00:00
|
|
|
Photo := TJvThumbImage.Create(Self);
|
|
|
|
Photo.AutoSize := False;
|
|
|
|
Photo.Align := alNone;
|
|
|
|
Photo.Stretch := True;
|
|
|
|
(************** NOT CONVERTED)
|
|
|
|
Photo.OnProgress := PhotoOnProgress;
|
|
|
|
**************)
|
|
|
|
|
2018-03-23 23:59:33 +00:00
|
|
|
FShadowObj := TShape.Create(Self);
|
|
|
|
FShadowObj.Visible := FShowShadow;
|
|
|
|
FShadowObj.Brush.Color := FShadowColor;
|
|
|
|
FShadowObj.Parent := Self;
|
|
|
|
FShadowObj.Pen.Style := psClear;
|
2018-03-23 00:10:05 +00:00
|
|
|
FShadowObj.Width := Photo.Width;
|
|
|
|
FShadowObj.Height := Photo.Height;
|
|
|
|
FShadowObj.Left := Photo.Left + FHShadowOffset;
|
|
|
|
FShadowObj.Top := Photo.Top + FVShadowOffset;
|
2018-03-23 23:59:33 +00:00
|
|
|
|
|
|
|
FTitleFont := TFont.Create;
|
|
|
|
FTitleFont.Name := 'default';
|
|
|
|
FTitleFont.Size := 0;
|
|
|
|
FTitleFont.OnChange := @RefreshFont;
|
|
|
|
|
2018-03-23 00:10:05 +00:00
|
|
|
FTitlePanel := TJvThumbTitle.Create(Self);
|
|
|
|
FTitlePanel.Align := alTop;
|
|
|
|
FTitlePanel.Height := 15;
|
|
|
|
FTitlePanel.Alignment := taCenter;
|
|
|
|
FTitlePanel.Color := FTitleColor;
|
|
|
|
FTitlePanel.BevelOuter := bvLowered;
|
|
|
|
FTitlePanel.ParentColor := True;
|
2018-03-23 23:59:33 +00:00
|
|
|
// FTitlePanel.Color := Self.Color;
|
|
|
|
FTitlePanel.Visible := (FTitlePlacement <> tpNone) and FShowTitle;
|
|
|
|
|
2018-03-23 00:10:05 +00:00
|
|
|
InsertControl(Photo);
|
|
|
|
InsertControl(FTitlePanel);
|
|
|
|
Align := alNone;
|
|
|
|
if AOwner is TJvThumbView then
|
|
|
|
begin
|
|
|
|
Width := TJvThumbView(Owner).MaxWidth;
|
|
|
|
Height := TJvThumbView(Owner).MaxHeight;
|
2018-03-25 00:04:05 +00:00
|
|
|
end else
|
2018-03-23 00:10:05 +00:00
|
|
|
begin
|
|
|
|
Width := 120;
|
|
|
|
Height := 120;
|
|
|
|
end;
|
|
|
|
FMinimizeMemory := True;
|
|
|
|
AsButton := False;
|
|
|
|
Left := 10;
|
|
|
|
Top := 10;
|
|
|
|
Visible := True;
|
|
|
|
BevelOuter := bvRaised;
|
|
|
|
StreamFileType := grBMP;
|
|
|
|
FAutoLoad := True;
|
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TJvThumbnail.Destroy;
|
|
|
|
begin
|
|
|
|
FDestroying := True;
|
|
|
|
(************* NOT CONVERTED ***
|
|
|
|
Photo.OnProgress := nil;
|
|
|
|
**********)
|
|
|
|
FPhotoName.Free;
|
|
|
|
FTitleFont.OnChange := nil;
|
|
|
|
FTitleFont.Free;
|
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
2018-03-26 08:03:23 +00:00
|
|
|
procedure TJvThumbnail.BoundsChanged;
|
2018-03-25 00:04:05 +00:00
|
|
|
begin
|
2018-03-26 08:03:23 +00:00
|
|
|
CalculateImageSize;
|
|
|
|
inherited BoundsChanged;
|
2018-03-25 00:04:05 +00:00
|
|
|
end;
|
|
|
|
|
2018-03-26 08:03:23 +00:00
|
|
|
procedure TJvThumbnail.CalculateImageSize;
|
|
|
|
var
|
|
|
|
Percent: Byte;
|
|
|
|
TempX, TempY: Single;
|
2018-03-25 00:04:05 +00:00
|
|
|
begin
|
2018-03-26 08:03:23 +00:00
|
|
|
if (Photo = nil) or (Photo.Picture = nil) then
|
|
|
|
exit;
|
|
|
|
UpdateThumbHeight;
|
|
|
|
UpdateThumbWidth;
|
|
|
|
if (Photo.Picture.Width > FThumbWidth) or (Photo.Picture.Height > FThumbHeight) then
|
|
|
|
begin
|
|
|
|
TempX := (FThumbWidth / Photo.Picture.Width) * 100;
|
|
|
|
TempY := (FThumbHeight / Photo.Picture.Height) * 100;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
TempX := 100;
|
|
|
|
TempY := 100;
|
|
|
|
end;
|
|
|
|
if TempX <= TempY then
|
|
|
|
Percent := Trunc(TempX)
|
|
|
|
else
|
|
|
|
Percent := Trunc(TempY);
|
|
|
|
Photo.Width := Trunc((Photo.Picture.Width / 100) * Percent);
|
|
|
|
Photo.Height := Trunc((Photo.Picture.Height / 100) * Percent);
|
|
|
|
Photo.Left := Trunc(Width / 2 - Photo.Width / 2);
|
|
|
|
Photo.Top := (Height div 2) - (Photo.Height div 2);
|
|
|
|
case FTitlePlacement of
|
|
|
|
tpUp:
|
|
|
|
Photo.Top := Photo.Top + (FTitlePanel.Height div 2);
|
|
|
|
tpDown:
|
|
|
|
Photo.Top := Photo.Top - (FTitlePanel.Height div 2);
|
|
|
|
end;
|
|
|
|
FShadowObj.SetBounds(Photo.Left + FHShadowOffset, Photo.Top + FVShadowOffset,
|
|
|
|
Photo.Width, Photo.Height);
|
2018-03-25 00:04:05 +00:00
|
|
|
end;
|
|
|
|
|
2018-03-26 08:03:23 +00:00
|
|
|
procedure TJvThumbnail.CreateHandle;
|
2018-03-25 00:04:05 +00:00
|
|
|
begin
|
2018-03-26 08:03:23 +00:00
|
|
|
inherited;
|
|
|
|
if not (csDesigning in ComponentState) and (FTitleColor = clDefault) then
|
|
|
|
FTitleColor := Color;
|
|
|
|
UpdateTitlePanelHeight;
|
2018-03-25 00:04:05 +00:00
|
|
|
end;
|
|
|
|
|
2018-03-26 08:03:23 +00:00
|
|
|
procedure TJvThumbnail.GetFileInfo(AName: String);
|
|
|
|
var
|
2018-04-21 14:46:46 +00:00
|
|
|
{$IFDEF WINDOWS}
|
|
|
|
info: TWin32FindDataW;
|
2018-08-26 14:25:44 +00:00
|
|
|
dft: DWORD = 0;
|
2018-04-21 14:46:46 +00:00
|
|
|
lft: TFileTime;
|
2018-03-26 08:03:23 +00:00
|
|
|
H: THandle;
|
2018-04-21 14:46:46 +00:00
|
|
|
ws: WideString;
|
|
|
|
{$ENDIF}
|
|
|
|
{$IFDEF UNIX}
|
|
|
|
info: stat;
|
|
|
|
{$ENDIF}
|
|
|
|
begin
|
|
|
|
{$IFDEF WINDOWS}
|
|
|
|
ws := UTF8Decode(AName);
|
2018-08-26 14:25:44 +00:00
|
|
|
H := Windows.FindFirstFileW(PWideChar(ws), info{%H-});
|
2018-03-26 08:03:23 +00:00
|
|
|
if H <> INVALID_HANDLE_VALUE then
|
|
|
|
begin
|
|
|
|
Windows.FindClose(H);
|
2018-04-21 14:46:46 +00:00
|
|
|
//fdFileAccessed
|
2018-08-26 14:25:44 +00:00
|
|
|
FileTimeToLocalFileTime(info.ftLastAccessTime, lft{%H-});
|
2018-04-21 14:46:46 +00:00
|
|
|
FileTimeToDosDateTime(lft, LongRec(dft).Hi, LongRec(dft).Lo);
|
2018-03-26 08:03:23 +00:00
|
|
|
try
|
2018-04-21 14:46:46 +00:00
|
|
|
FDFileAccessed := FileDateToDateTime(dft);
|
2018-03-26 08:03:23 +00:00
|
|
|
except
|
2018-04-21 14:46:46 +00:00
|
|
|
FDFileAccessed := 0;
|
2018-03-26 08:03:23 +00:00
|
|
|
end;
|
2018-04-21 14:46:46 +00:00
|
|
|
//fdFilechanged
|
|
|
|
FileTimeToLocalFileTime(info.ftLastwriteTime, lft);
|
|
|
|
FileTimeToDosDateTime(lft, LongRec(dft).Hi, LongRec(dft).Lo);
|
2018-03-26 08:03:23 +00:00
|
|
|
try
|
2018-04-21 14:46:46 +00:00
|
|
|
FDFileChanged := FileDateToDateTime(dft);
|
2018-03-26 08:03:23 +00:00
|
|
|
except
|
2018-04-21 14:46:46 +00:00
|
|
|
FDFileChanged := 0;
|
2018-03-26 08:03:23 +00:00
|
|
|
end;
|
2018-04-21 14:46:46 +00:00
|
|
|
//fdFileCreated
|
|
|
|
FileTimeToLocalFileTime(info.ftCreationTime, lft);
|
|
|
|
FileTimeToDosDateTime(lft, LongRec(dft).Hi, LongRec(dft).Lo);
|
2018-03-26 08:03:23 +00:00
|
|
|
try
|
2018-04-21 14:46:46 +00:00
|
|
|
FDFileCreated := FileDateToDateTime(dft);
|
2018-03-26 08:03:23 +00:00
|
|
|
except
|
2018-04-21 14:46:46 +00:00
|
|
|
FDFileCreated := 0;
|
2018-03-26 08:03:23 +00:00
|
|
|
end;
|
2018-04-21 14:46:46 +00:00
|
|
|
FDFileSize := info.nFileSizeHigh * MAXDWORD + info.nFileSizeLow;
|
|
|
|
end;
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
{$IFDEF UNIX}
|
|
|
|
if fpstat(AName, info) = 0 then begin
|
|
|
|
FDFileAccessed := UnixToDateTime(info.st_atime);
|
|
|
|
FDFileChanged := UnixToDateTime(info.st_mtime);
|
|
|
|
FDFileCreated := UnixToDateTime(info.st_ctime);
|
2020-05-06 10:40:05 +00:00
|
|
|
{$IFDEF DARWIN}
|
|
|
|
FDFileSize := info.st_size;
|
|
|
|
{$ELSE}
|
2018-04-21 14:46:46 +00:00
|
|
|
FDFileSize := info.Size;
|
2020-05-06 10:40:05 +00:00
|
|
|
{$ENDIF}
|
2018-03-26 08:03:23 +00:00
|
|
|
end;
|
2018-04-21 14:46:46 +00:00
|
|
|
{$ENDIF}
|
2018-03-25 00:04:05 +00:00
|
|
|
end;
|
|
|
|
|
2018-03-26 08:03:23 +00:00
|
|
|
function TJvThumbnail.GetFileName: string;
|
2018-03-25 00:04:05 +00:00
|
|
|
begin
|
2018-03-26 08:03:23 +00:00
|
|
|
Result := FPhotoName.FileName;
|
2018-03-25 00:04:05 +00:00
|
|
|
end;
|
|
|
|
|
2018-03-26 08:03:23 +00:00
|
|
|
function TJvThumbnail.GetTitleBevelInner: TPanelBevel;
|
2018-03-25 00:04:05 +00:00
|
|
|
begin
|
2018-03-26 08:03:23 +00:00
|
|
|
Result := FTitlePanel.BevelInner;
|
2018-03-25 00:04:05 +00:00
|
|
|
end;
|
|
|
|
|
2018-03-26 08:03:23 +00:00
|
|
|
function TJvThumbnail.GetTitleBevelOuter: TPanelBevel;
|
2018-03-23 00:10:05 +00:00
|
|
|
begin
|
2018-03-26 08:03:23 +00:00
|
|
|
Result := FTitlePanel.BevelOuter;
|
2018-03-23 00:10:05 +00:00
|
|
|
end;
|
|
|
|
|
2018-03-26 08:03:23 +00:00
|
|
|
function TJvThumbnail.GetTitleBorderStyle: TBorderStyle;
|
2018-03-23 23:59:33 +00:00
|
|
|
begin
|
2018-03-26 08:03:23 +00:00
|
|
|
Result := FTitlePanel.BorderStyle;
|
2018-03-23 23:59:33 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TJvThumbnail.IsTitleFontStored: Boolean;
|
|
|
|
begin
|
|
|
|
Result := not FTitleFont.IsDefault;
|
|
|
|
end;
|
|
|
|
|
2018-03-26 08:03:23 +00:00
|
|
|
function TJvThumbnail.LoadFile(AFile: string): string;
|
2018-03-23 00:10:05 +00:00
|
|
|
var
|
2018-03-26 08:03:23 +00:00
|
|
|
FName: string;
|
2018-03-23 00:10:05 +00:00
|
|
|
begin
|
2018-03-26 08:03:23 +00:00
|
|
|
try
|
|
|
|
FName := AFile;
|
|
|
|
Photo.LoadFromFile(AFile);
|
|
|
|
FImageWidth := Photo.Picture.Width;
|
|
|
|
FImageHeight := Photo.Picture.Height;
|
|
|
|
FUpdated := False;
|
|
|
|
CalculateImageSize;
|
|
|
|
Photo.Visible := True;
|
|
|
|
except
|
|
|
|
// (rom) ShowMessage removed
|
|
|
|
FName := '';
|
2018-03-23 00:10:05 +00:00
|
|
|
end;
|
2018-03-26 08:03:23 +00:00
|
|
|
if MinimizeMemory and (FPhotoName.FileName <> '') then
|
2018-03-23 00:10:05 +00:00
|
|
|
begin
|
2018-03-26 08:03:23 +00:00
|
|
|
if Owner is TJvThumbView then
|
|
|
|
Photo.ScaleDown(TJvThumbView(Owner).MaxWidth, TJvThumbView(Owner).MaxHeight)
|
2018-03-23 00:10:05 +00:00
|
|
|
else
|
2018-03-26 08:03:23 +00:00
|
|
|
Photo.ScaleDown(FThumbWidth, FThumbHeight);
|
2018-03-23 00:10:05 +00:00
|
|
|
end;
|
2018-03-26 08:03:23 +00:00
|
|
|
Result := FName;
|
2018-03-23 00:10:05 +00:00
|
|
|
end;
|
|
|
|
|
2018-03-26 08:03:23 +00:00
|
|
|
procedure TJvThumbnail.MouseDown(Button: TMouseButton; Shift: TShiftState;
|
|
|
|
X, Y: Integer);
|
2018-03-23 00:10:05 +00:00
|
|
|
begin
|
2018-03-26 08:03:23 +00:00
|
|
|
if AsButton then
|
|
|
|
if Button = mbLeft then
|
|
|
|
begin
|
|
|
|
FMousePressed := True;
|
|
|
|
BevelOuter := bvLowered;
|
|
|
|
FTitlePanel.BevelOuter := bvRaised;
|
|
|
|
end;
|
|
|
|
inherited MouseDown(Button, Shift, X, Y);
|
2018-03-23 00:10:05 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TJvThumbnail.MouseMove(Shift: TShiftState; X, Y: Integer);
|
|
|
|
begin
|
|
|
|
if AsButton then
|
|
|
|
if FMousePressed then
|
|
|
|
begin
|
|
|
|
if (X < 0) or (X > Width) or (Y < 0) or (Y > Height) then
|
|
|
|
begin
|
|
|
|
BevelOuter := bvRaised;
|
|
|
|
FTitlePanel.BevelOuter := bvLowered
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
BevelOuter := bvLowered;
|
|
|
|
FTitlePanel.BevelOuter := bvRaised;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
inherited MouseMove(Shift, X, Y);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TJvThumbnail.MouseUp(Button: TMouseButton; Shift: TShiftState;
|
|
|
|
X, Y: Integer);
|
|
|
|
begin
|
|
|
|
if AsButton then
|
|
|
|
if Button = mbLeft then
|
|
|
|
begin
|
|
|
|
FMousePressed := False;
|
|
|
|
BevelOuter := bvRaised;
|
|
|
|
FTitlePanel.BevelOuter := bvLowered;
|
|
|
|
end;
|
|
|
|
inherited MouseUp(Button, Shift, X, Y);
|
|
|
|
end;
|
|
|
|
|
2018-03-26 08:03:23 +00:00
|
|
|
(********** NOT CONVERTED ***
|
|
|
|
procedure TJvThumbnail.PhotoOnProgress(Sender: TObject; Stage: TProgressStage;
|
|
|
|
PercentDone: Byte; RedrawNow: Boolean; const R: TRect; const Msg: string);
|
2018-03-23 00:10:05 +00:00
|
|
|
begin
|
2018-03-26 08:03:23 +00:00
|
|
|
FImageReady := (Stage = psEnding);
|
2018-03-23 00:10:05 +00:00
|
|
|
end;
|
2018-03-26 08:03:23 +00:00
|
|
|
***************************)
|
|
|
|
|
|
|
|
procedure TJvThumbnail.Refresh;
|
2018-03-23 00:10:05 +00:00
|
|
|
begin
|
2018-03-26 08:03:23 +00:00
|
|
|
CalculateImageSize;
|
|
|
|
inherited Refresh;
|
2018-03-23 00:10:05 +00:00
|
|
|
end;
|
|
|
|
|
2018-03-26 08:03:23 +00:00
|
|
|
procedure TJvThumbnail.RefreshFont(Sender: TObject);
|
2018-03-23 00:10:05 +00:00
|
|
|
begin
|
2018-03-26 08:03:23 +00:00
|
|
|
FTitlePanel.Font.Assign(FTitleFont);
|
|
|
|
UpdateTitlePanelHeight;
|
2018-03-23 00:10:05 +00:00
|
|
|
end;
|
|
|
|
|
2018-03-26 08:03:23 +00:00
|
|
|
// dummy property functions to allow the object inspector to
|
|
|
|
// show the properties and their values
|
|
|
|
procedure TJvThumbnail.SetDummyStr(AStr: string);
|
|
|
|
begin
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TJvThumbnail.SetDummyCard(AInt: Longint);
|
2018-03-23 00:10:05 +00:00
|
|
|
begin
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TJvThumbnail.SetFileName(const AFile: string);
|
|
|
|
var
|
|
|
|
FName: string;
|
|
|
|
// Pos: Longint;
|
|
|
|
// tmp: TJvThumbImage;
|
|
|
|
// D1, D2: TdateTime;
|
|
|
|
begin
|
|
|
|
if AFile <> '' then
|
|
|
|
begin
|
|
|
|
GetFileInfo(AFile);
|
|
|
|
if FAutoLoad then
|
|
|
|
FName := LoadFile(AFile);
|
|
|
|
end
|
|
|
|
else
|
|
|
|
FName := ''; {}
|
|
|
|
if FName = AFile then
|
|
|
|
if (Title = ExtractFileName(FPhotoName.FileName)) or (Title = '') then
|
|
|
|
Title := ExtractFileName(FName);
|
|
|
|
FPhotoName.FileName := FName;
|
|
|
|
end;
|
|
|
|
|
2018-03-26 08:03:23 +00:00
|
|
|
procedure TJvThumbnail.SetMargin(AValue: Integer);
|
2018-03-23 00:10:05 +00:00
|
|
|
begin
|
2018-03-26 08:03:23 +00:00
|
|
|
if AValue <> FMargin then begin
|
|
|
|
FMargin := AValue;
|
|
|
|
CalculateImageSize;
|
|
|
|
// UpdateThumbWidth;
|
|
|
|
// UpdateThumbHeight;
|
|
|
|
Invalidate;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TJvThumbnail.SetMinimizeMemory(Min: Boolean);
|
|
|
|
begin
|
|
|
|
if Assigned(Photo.Picture.Graphic) then
|
2018-03-23 00:10:05 +00:00
|
|
|
begin
|
2018-03-26 08:03:23 +00:00
|
|
|
if FMinimizeMemory <> Min then
|
|
|
|
begin
|
|
|
|
if Min then
|
|
|
|
begin
|
|
|
|
if Owner is TJvThumbView then
|
|
|
|
Photo.ScaleDown(TJvThumbView(Owner).MaxWidth, TJvThumbView(Owner).MaxHeight)
|
|
|
|
else
|
|
|
|
Photo.ScaleDown(Width, Height);
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if FMinimizeMemory then
|
|
|
|
Photo.Picture.LoadFromFile(FileName);
|
|
|
|
FMinimizeMemory := Min;
|
|
|
|
end;
|
2018-03-23 00:10:05 +00:00
|
|
|
end
|
|
|
|
else
|
2018-03-26 08:03:23 +00:00
|
|
|
FMinimizeMemory := Min;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{procedure TJvThumbnail.SetShadowColor(aColor: TColor);
|
|
|
|
begin
|
|
|
|
FShadowObj.Brush.Color := aColor;
|
|
|
|
FShadowColor := aColor;
|
|
|
|
end;}
|
|
|
|
|
|
|
|
procedure TJvThumbnail.SetShowShadow(AShow: Boolean);
|
|
|
|
begin
|
|
|
|
FShadowObj.Visible := AShow;
|
|
|
|
FShowShadow := AShow;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TJvThumbnail.SetShowTitle(const AState: Boolean);
|
|
|
|
begin
|
|
|
|
if AState <> FShowTitle then
|
2018-03-23 00:10:05 +00:00
|
|
|
begin
|
2018-03-26 08:03:23 +00:00
|
|
|
FShowTitle := AState;
|
|
|
|
FTitlePanel.Visible := AState;
|
|
|
|
end
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TJvThumbnail.SetStream(const AStream: TStream);
|
|
|
|
var
|
|
|
|
Bmp: Graphics.TBitmap;
|
|
|
|
Size: TPoint;
|
|
|
|
Img2: TJPEGImage;
|
|
|
|
begin
|
|
|
|
case StreamFileType of
|
|
|
|
grBMP:
|
|
|
|
Photo.Picture.Bitmap.LoadFromStream(AStream);
|
|
|
|
(********* NOT CONVERTED ***
|
|
|
|
grEMF, grWMF:
|
|
|
|
Photo.Picture.Metafile.LoadFromStream(AStream);
|
|
|
|
*************************)
|
|
|
|
grJPG:
|
|
|
|
begin
|
|
|
|
Img2 := TJPEGImage.Create;
|
|
|
|
Img2.LoadFromStream(AStream);
|
|
|
|
Photo.Picture.Assign(Img2);
|
|
|
|
FreeAndNil(Img2);
|
|
|
|
end;
|
2018-03-23 00:10:05 +00:00
|
|
|
end;
|
2018-03-26 08:03:23 +00:00
|
|
|
|
|
|
|
if FMinimizeMemory then
|
|
|
|
begin
|
|
|
|
Bmp := Graphics.TBitmap.Create;
|
|
|
|
if Parent is TJvThumbView then
|
|
|
|
Size := ProportionalSize(Point(Photo.Picture.Width, Photo.Picture.Height),
|
|
|
|
Point(TJvThumbView(Parent).MaxWidth, TJvThumbView(Parent).MaxHeight))
|
|
|
|
else
|
|
|
|
Size := ProportionalSize(Point(Photo.Picture.Width, Photo.Picture.Height),
|
|
|
|
Point(Width, Height));
|
|
|
|
Bmp.Width := Size.X;
|
|
|
|
Bmp.Height := Size.Y;
|
|
|
|
Bmp.handletype := bmDIB;
|
|
|
|
Bmp.pixelformat := pf24bit;
|
|
|
|
Bmp.Canvas.StretchDraw(rect(0, 0, Bmp.Width, Bmp.Height),
|
|
|
|
Photo.Picture.Graphic);
|
|
|
|
//Photo.Picture.Graphic.Free; // (rom) not needed
|
|
|
|
//Photo.Picture.Graphic := nil;
|
|
|
|
Photo.Picture.Assign(Bmp);
|
|
|
|
Bmp.Free;
|
2018-03-23 00:10:05 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TJvThumbnail.THSizeChanged(var Msg: TLMessage);
|
|
|
|
begin
|
|
|
|
CalculateImageSize;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TJvThumbnail.SetTitle(const Value: string);
|
|
|
|
begin
|
|
|
|
if Value <> FTitle then
|
|
|
|
begin
|
|
|
|
FTitle := Value;
|
|
|
|
FTitlePanel.Caption := Value;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2018-03-26 08:03:23 +00:00
|
|
|
procedure TJvThumbnail.SetTitleBevelInner(const Value: TPanelBevel);
|
2018-03-23 00:10:05 +00:00
|
|
|
begin
|
2018-03-26 08:03:23 +00:00
|
|
|
FTitlePanel.BevelInner := Value;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TJvThumbnail.SetTitleBevelOuter(const Value: TPanelBevel);
|
|
|
|
begin
|
|
|
|
FTitlePanel.BevelOuter := Value;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TJvThumbnail.SetTitleBorderStyle(const Value: TBorderStyle);
|
|
|
|
begin
|
|
|
|
FTitlePanel.BorderStyle := Value;
|
2018-03-23 00:10:05 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TJvThumbnail.SetTitleColor(const Value: TColor);
|
|
|
|
begin
|
|
|
|
if Value <> FTitleColor then
|
|
|
|
begin
|
|
|
|
FTitleColor := Value;
|
|
|
|
FTitlePanel.Color := Value;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TJvThumbnail.SetTitleFont(const Value: TFont);
|
|
|
|
begin
|
|
|
|
FTitleFont.Assign(Value);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TJvThumbnail.SetTitlePanel(ATitle: string; AFont: TFont;
|
|
|
|
AColor: TColor);
|
|
|
|
begin
|
|
|
|
SetTitleFont(AFont);
|
|
|
|
SetTitleColor(AColor);
|
|
|
|
SetTitle(ATitle);
|
|
|
|
FUpdated := True;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TJvThumbnail.SetTitlePlacement(const AState: TTitlePos);
|
|
|
|
begin
|
|
|
|
if AState <> FTitlePlacement then
|
|
|
|
case AState of
|
|
|
|
tpUp:
|
|
|
|
FTitlePanel.Align := alTop;
|
|
|
|
tpDown:
|
|
|
|
FTitlePanel.Align := alBottom;
|
|
|
|
tpNone:
|
|
|
|
FTitlePanel.Visible := False;
|
|
|
|
end;
|
2018-03-23 23:59:33 +00:00
|
|
|
if FTitlePlacement <> tpNone then
|
2018-03-23 00:10:05 +00:00
|
|
|
FTitlePanel.Visible := True;
|
|
|
|
FTitlePlacement := AState;
|
|
|
|
CalculateImageSize;
|
|
|
|
end;
|
|
|
|
|
2018-03-26 08:03:23 +00:00
|
|
|
procedure TJvThumbnail.UpdateThumbHeight;
|
2018-03-23 00:10:05 +00:00
|
|
|
begin
|
2018-03-26 08:03:23 +00:00
|
|
|
if Assigned(FTitlePanel) and FTitlePanel.Visible then
|
|
|
|
FThumbHeight := ClientHeight - FTitlePanel.Height - FMargin
|
2018-03-23 00:10:05 +00:00
|
|
|
else
|
2018-03-26 08:03:23 +00:00
|
|
|
FThumbHeight := ClientHeight - FMargin;
|
2018-03-23 00:10:05 +00:00
|
|
|
end;
|
|
|
|
|
2018-03-26 08:03:23 +00:00
|
|
|
procedure TJvThumbnail.UpdateThumbWidth;
|
2018-03-23 00:10:05 +00:00
|
|
|
begin
|
2018-03-26 08:03:23 +00:00
|
|
|
FThumbWidth := ClientWidth - 2 * FMargin;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TJvThumbnail.UpdateTitlePanelHeight;
|
|
|
|
var
|
|
|
|
fd: TFontData;
|
|
|
|
begin
|
|
|
|
fd := GetFontData(FTitleFont.Handle);
|
|
|
|
Canvas.Font.Name := fd.Name;
|
|
|
|
Canvas.Font.Style := fd.Style;
|
|
|
|
Canvas.Font.Height := fd.Height;
|
|
|
|
FTitlePanel.Height := Canvas.TextHeight('Tg') + 4;
|
2018-03-23 00:10:05 +00:00
|
|
|
CalculateImageSize;
|
2018-03-26 08:03:23 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TJvThumbnail.WMPaint(var Msg: TLMPaint);
|
|
|
|
var
|
|
|
|
ThumbnailTitle: string;
|
|
|
|
begin
|
|
|
|
if not FUpdated then
|
|
|
|
begin
|
|
|
|
ThumbnailTitle := Title;
|
|
|
|
if Assigned(FOnGetTitle) then
|
|
|
|
begin
|
|
|
|
FOnGetTitle(Self, FileName, ThumbnailTitle);
|
|
|
|
SetTitle(ThumbnailTitle);
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
if ThumbnailTitle = '' then
|
|
|
|
SetTitle(ExtractFileName(FileName))
|
|
|
|
else
|
|
|
|
SetTitle(ThumbnailTitle);
|
|
|
|
end;
|
|
|
|
FUpdated := True;
|
|
|
|
end;
|
|
|
|
inherited;
|
2018-03-23 00:10:05 +00:00
|
|
|
end;
|
|
|
|
|
2020-01-17 23:29:41 +00:00
|
|
|
|
|
|
|
{ LCL scaling routines }
|
|
|
|
|
|
|
|
procedure TJvThumbnail.DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy;
|
|
|
|
const AXProportion, AYProportion: Double);
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
if AMode in [lapAutoAdjustWithoutHorizontalScrolling, lapAutoAdjustForDPI] then
|
|
|
|
begin
|
|
|
|
FMargin := round(FMargin * AXProportion);
|
|
|
|
FHShadowOffset := round(FHShadowOffset * AXProportion);
|
|
|
|
FVShadowOffset := round(FVShadowOffset * AYProportion);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{$IF LCL_FullVersion >= 2010000}
|
|
|
|
procedure TJvThumbnail.FixDesignFontsPPI(const ADesignTimePPI: Integer);
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
DoFixDesignFontPPI(FTitleFont, ADesignTimePPI);
|
|
|
|
end;
|
|
|
|
{$IFEND}
|
|
|
|
|
|
|
|
procedure TJvThumbnail.ScaleFontsPPI(
|
|
|
|
{$IF LCL_FullVersion >= 1080100}const AToPPI: Integer;{$IFEND}
|
|
|
|
const AProportion: Double);
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
DoScaleFontPPI(FTitleFont, AToPPI, AProportion);
|
|
|
|
end;
|
|
|
|
|
2018-03-23 00:10:05 +00:00
|
|
|
end.
|
2018-04-21 14:46:46 +00:00
|
|
|
|