📄 atviewer.pas
字号:
procedure FocusActiveControl;
procedure TextScroll(const APos: Int64; AIndentVert, AIndentHorz: Integer);
procedure TextPopupMenu(AX, AY: Integer);
procedure TextEncodingsMenu(AX, AY: Integer);
function ImageEffect(AEffect: TATViewerImageEffect): Boolean;
procedure WebGoBack;
procedure WebGoForward;
{$ifdef WLX}
function OpenFolder(const AFolderName: WideString): Boolean;
procedure InitPluginsParams(AParent: TWinControl; const AIniFilename: string);
procedure ResizeActivePlugin(const Rect: TRect);
procedure RemovePlugins;
function AddPlugin(const AFileName: TWlxFilename; const ADetectStr: string): Boolean;
function GetPlugin(AIndex: Word; var AFileName: TWlxFilename; var ADetectStr: string): Boolean;
property ActivePluginSupportsSearch: Boolean read GetActivePluginSupportsSearch;
property ActivePluginSupportsPrint: Boolean read GetActivePluginSupportsPrint;
property ActivePluginSupportsCommands: Boolean read GetActivePluginSupportsCommands;
property ActivePluginWindowHandle: THandle read GetActivePluginWindowHandle;
property PluginsHighPriority: Boolean read FPluginsHighPriority write FPluginsHighPriority;
procedure PluginsSendMessage(const AMessage: TMessage);
{$endif}
property ActivePluginName: string read GetActivePluginName;
procedure IncreaseScale(AIncrement: Boolean);
property FileName: WideString read FFileName;
property FileSize: Int64 read FFileSize;
property FileTime: TFileTime read FFileTime;
property IsImage: Boolean read FIsImage;
property IsIcon: Boolean read FIsIcon;
property IsMetafile: Boolean read FIsMetafile;
property IsMedia: Boolean read FIsMedia;
property BinHex: TATBinHex read FBinHex;
property ImageBox: TATImageBox read FImageBox;
property ImageWidth: Integer read GetImageWidth;
property ImageHeight: Integer read GetImageHeight;
property ImageScale: Integer read GetImageScale write SetImageScale;
property ImageError: Boolean read FImageError;
property ImageErrorMessage: string read FImageErrorMessage;
procedure ImageScaleInc;
procedure ImageScaleDec;
procedure MediaDoPlayPause;
property MediaVolume: Integer read GetMediaVolume write SetMediaVolume;
property MediaMute: Boolean read GetMediaMute write SetMediaMute;
property PosPercent: Integer read GetPosPercent write SetPosPercent;
property PosOffset: Int64 read GetPosOffset write SetPosOffset;
property WebBusy: Boolean read GetWebBusy;
{$ifdef SEARCH}
property SearchStarted: Boolean read GetSearchStarted;
property SearchFinished: Boolean read FFindFinished;
{$endif}
{$ifdef PRINT}
property MarginLeft: Extended read GetMarginLeft write SetMarginLeft;
property MarginTop: Extended read GetMarginTop write SetMarginTop;
property MarginRight: Extended read GetMarginRight write SetMarginRight;
property MarginBottom: Extended read GetMarginBottom write SetMarginBottom;
{$endif}
property TextPopupCaption[AIndex: TATPopupCommand]: string write SetTextPopupCaption;
property TextMaxLengths[AIndex: TATBinHexMode]: Integer read GetTextMaxLengths write SetTextMaxLengths;
property TextMaxClipboardDataSizeMb: Integer read GetTextMaxClipboardDataSizeMb write SetTextMaxClipboardDataSizeMb;
property TextSelStart: Int64 read GetSelStart write SetSelStart;
property TextSelLength: Int64 read GetSelLength write SetSelLength;
property TextSelText: string read GetSelText;
property TextSelTextShort: string read GetSelTextShort;
property TextSelTextW: WideString read GetSelTextW;
property TextSelTextShortW: WideString read GetSelTextShortW;
property TextEncodingName: string read GetTextEncodingName;
protected
procedure Click; override;
procedure Resize; override;
published
property Mode: TATViewerMode read FMode write SetMode default vmodeText;
property ModeUndetected: TATViewerMode read FModeUndetected write FModeUndetected default vmodeText;
property ModeDetect: Boolean read FModeDetect write FModeDetect default True;
property ModesDisabledForDetect: TATViewerModes read FModesDisabledForDetect write FModesDisabledForDetect default [];
property TextDetect: Boolean read FTextDetect write FTextDetect default True;
property TextDetectOEM: Boolean read FTextDetectOEM write FTextDetectOEM default True;
property TextDetectSize: DWORD read FTextDetectSize write FTextDetectSize default 2;
property TextDetectLimit: DWORD read FTextDetectLimit write FTextDetectLimit default 0;
property TextEncoding: TATEncoding read GetTextEncoding write SetTextEncoding default vencANSI;
property TextWrap: Boolean read FTextWrap write SetTextWrap default False;
property TextWidth: Integer read GetTextWidth write SetTextWidth default 80;
property TextWidthHex: Integer read GetTextWidthHex write SetTextWidthHex default 16;
property TextWidthFit: Boolean read GetTextWidthFit write SetTextWidthFit default False;
property TextWidthFitHex: Boolean read GetTextWidthFitHex write SetTextWidthFitHex default False;
property TextWidthFitUHex: Boolean read GetTextWidthFitUHex write SetTextWidthFitUHex default False;
property TextOemSpecial: Boolean read GetTextOemSpecial write SetTextOemSpecial default False;
property TextGutter: Boolean read GetTextGutter write SetTextGutter default cATBinHexGutterEnabled;
property TextGutterWidth: Integer read GetTextGutterWidth write SetTextGutterWidth default cATBinHexGutterWidth;
property TextNonPrintable: Boolean read GetTextNonPrintable write SetTextNonPrintable default False;
property TextSearchIndentVert: Integer read FSearchIndentVert write SetSearchIndentVert default 5;
property TextSearchIndentHorz: Integer read FSearchIndentHorz write SetSearchIndentHorz default 5;
property TextTabSize: Integer read GetTextTabSize write SetTextTabSize default 8;
property TextColor: TColor read FTextColor write SetTextColor default clWindow;
property TextColorHex: TColor read GetTextColorHex write SetTextColorHex default clNavy;
property TextColorHex2: TColor read GetTextColorHex2 write SetTextColorHex2 default clBlue;
property TextColorHexBack: TColor read GetTextColorHexBack write SetTextColorHexBack default cATBinHexBkColor;
property TextColorLines: TColor read GetTextColorLines write SetTextColorLines default clGray;
property TextColorError: TColor read GetTextColorError write SetTextColorError default clRed;
property TextColorGutter: TColor read GetTextColorGutter write SetTextColorGutter default cATBinHexGutterColor;
property TextFont: TFont read GetTextFont write SetTextFont;
property TextFontOEM: TFont read GetTextFontOEM write SetTextFontOEM;
property TextFontFooter: TFont read GetTextFontFooter write SetTextFontFooter;
property TextAutoCopy: Boolean read FTextAutoCopy write FTextAutoCopy default False;
property TextPopupCommands: TATPopupCommands read GetTextPopupCommands write SetTextPopupCommands default cATBinHexCommandSet;
property MediaMode: TATViewerMediaMode read FMediaMode write SetMediaMode default vmmodeDefault;
property MediaAutoPlay: Boolean read FMediaAutoPlay write FMediaAutoPlay default True;
property MediaPlayCount: Integer read FMediaPlayCount write FMediaPlayCount default 1;
property MediaPlaylistPause: Integer read FMediaPlaylistPause write FMediaPlaylistPause default 500;
property MediaFit: Boolean read GetMediaFit write SetMediaFit default True;
property MediaFitOnlyBig: Boolean read GetMediaFitOnlyBig write SetMediaFitOnlyBig default True;
property MediaCenter: Boolean read GetMediaCenter write SetMediaCenter default True;
property ImageColor: TColor read FImageColor write FImageColor default clDkGray;
property ImageDrag: Boolean read GetImageDrag write SetImageDrag default True;
property ImageCursor: TCursor read GetImageCursor write SetImageCursor default crDefault;
property ImageDragCursor: TCursor read GetImageDragCursor write SetImageDragCursor default crSizeAll;
property ImageTransparent: Boolean read FImageTransparent write FImageTransparent default False;
property ImageResample: Boolean read FImageResample write FImageResample default False;
property ImageKeepPosition: Boolean read FImageKeepPosition write FImageKeepPosition default True;
property ImageErrorMessageBox: Boolean read FImageErrorMessageBox write FImageErrorMessageBox default True;
{$ifdef NOTIF}
property TextAutoReload: Boolean read GetTextAutoReload write SetTextAutoReload default False;
property TextAutoReloadBeep: Boolean read GetTextAutoReloadBeep write SetTextAutoReloadBeep default False;
property TextAutoReloadFollowTail: Boolean read GetTextAutoReloadFollowTail write SetTextAutoReloadFollowTail default True;
property OnTextFileReload: TNotifyEvent read GetOnTextFileReload write SetOnTextFileReload;
{$endif}
{$ifdef IVIEW}
property IViewIntegration: TATIViewIntegration read FIViewIntegration write FIViewIntegration;
{$endif}
{$ifdef OFFLINE}
property WebOffline: Boolean read FWebOffline write SetWebOffline default False;
{$endif}
property WebAcceptAllFiles: Boolean read FWebAcceptAllFiles write FWebAcceptAllFiles default False;
property WebWaitForNavigate: Boolean read FWebWaitForNavigate write FWebWaitForNavigate default False;
property IsFocused: Boolean read FFocused write FFocused default False;
property BorderStyleInner: TBorderStyle read FBorderStyleInner write FBorderStyleInner default bsSingle;
property OnMediaPlaybackEnd: TNotifyEvent read FOnMediaPlaybackEnd write FOnMediaPlaybackEnd;
property OnWebDocumentComplete: TNotifyEvent read FOnWebDocumentComplete write FOnWebDocumentComplete;
property OnWebNavigateComplete: TNotifyEvent read FOnWebNavigateComplete write FOnWebNavigateComplete;
property OnFileUnload: TNotifyEvent read FOnFileUnload write FOnFileUnload;
property OnFileLoad: TNotifyEvent read FOnFileLoad write FOnFileLoad;
property OnOptionsChange: TNotifyEvent read FOnOptionsChange write SetOnOptionsChange;
{$ifdef SEARCH}
property OnTextSearchProgress: TATStreamSearchProgress read GetOnTextSearchProgress write SetOnTextSearchProgress;
{$endif}
{$ifdef WLX}
property OnPluginsBeforeLoading: TWlxNameEvent read GetPluginsBeforeLoading write SetPluginsBeforeLoading;
property OnPluginsAfterLoading: TWlxNameEvent read GetPluginsAfterLoading write SetPluginsAfterLoading;
{$endif}
end;
type
TATViewerGlobalOptions = record
ExtText: string;
ExtRTF: string;
ExtImages: string;
ExtMedia: string;
ExtWeb: string;
end;
var
ATViewerOptions: TATViewerGlobalOptions;
procedure ATViewerOptionsReset;
procedure Register;
implementation
uses
Clipbrd,
{$ifdef WLX} WLXPlugin, {$endif}
{$ifdef IVIEW} nmzIrfanXnView, {$endif}
ATxSProc, ATxFProc, ATxWBProc, ATxREUrl,
ATxImageProc, ATViewerMsg;
{ Helper functions }
{$I ATViewerExt.inc}
procedure DoCursorHours;
begin
Screen.Cursor := crHourGlass;
end;
procedure DoCursorDefault;
begin
Screen.Cursor := crDefault;
end;
{$ifdef SEARCH}
function ATSSOptionsToREOptions(AOptions: TATStreamSearchOptions): TSearchTypes;
begin
Result := [];
if asoWholeWords in AOptions then
Include(Result, stWholeWord);
if asoCaseSens in AOptions then
Include(Result, stMatchCase);
end;
{$endif}
{
Volume property:
WMP 6.4:
http://msdn.microsoft.com/msdnmag/issues/01/02/web/
As it turns out, the Windows Media Player object exposes a volume property.
It's a little strange and awkward to use (in version 6.4 of the Media Player).
Max volume is 0, min volume is -10000, and the perceived volume ramp is not
a linear progression between those two values.
Note that if you display the default Windows Media Player controls and the
user modifies the volume with the displayed slider, this value does not appear
to get reported back via that volume property (in version 6.4).
WMP 7+:
Zero specifies no volume and 100 specifies full volume. If no value
is specified for this property, it defaults to the last volume setting
established for the player.
ATViewer:
Let's always use the volume range from 0 to 10. WMP 6.4 visual control also
has this range. And, for example, Media Player Classic has the range 0 to 13.
}
const
cVolMin = 0;
cVolMax = 10;
var
//Approximate volume values that form the linear scale:
cVolW6: array[cVolMin .. cVolMax] of Integer =
//(-10000, -1500, -1200, -980, -760, -570, -420, -300, -200, -100, 0);
(-9640, -2000, -1440, -1070, -810, -610, -450, -320, -200, -100, 0);
function Vol_W6toA(AValue: Integer): Integer;
var
i: Integer;
begin
Result:= cVolMin;
for i := cVolMin to cVolMax do
if cVolW6[i] >= AValue then
begin
Result:= i;
Break
end;
end;
function Vol_AtoW6(AValue: Integer): Integer;
begin
ILimitMin(AValue, cVolMin);
ILimitMax(AValue, cVolMax);
Result:= cVolW6[AValue];
end;
function Vol_W9toA(AValue: Integer): Integer;
begin
Result:= AValue div 10;
end;
function Vol_AtoW9(AValue: Integer): Integer;
begin
ILimitMin(AValue, cVolMin);
ILimitMax(AValue, cVolMax);
Result:= AValue * 10;
end;
{ TATViewer }
function TATViewer.CanSetFocus: Boolean;
begin
Result :=
CanFocus and
(FFocused or Focused) and
([csLoading, csDesigning] * ComponentState = [])
end;
constructor TATViewer.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
//Init inherited properties
Caption := '';
BevelOuter := bvNone;
Width := 200;
Height := 150;
//Init variables
FFileName := '';
FFileSize := 0;
FillChar(FFileTime, SizeOf(TFileTime), 0);
FMode := vmodeText;
FModeUndetected := vmodeText;
FModeDetect := True;
FModesDisabledForDetect := [];
FMediaMode := vmmodeDefault;
FTextColor := clWindow;
FTextEncoding := vencANSI;
FTextWrap := False;
FTextDetect := True;
FTextDetectOEM := True;
FTextDetectSize := 2;
FTextDetectLimit := 0;
FMediaAutoPlay := True;
FMediaPlayCount := 1;
FMediaPlaylistPause := 500;
FMediaFit := True;
FMediaFitOnlyBig := True;
FMediaCenter := True;
FMediaVolume := Pred(Pred(cVolMax));
FMediaMute := False;
{$ifdef OFFLINE}
FWebOffline := False;
{$endif}
FWebAcceptAllFiles := False;
FWebWaitForNavigate := False;
FSearchIndentVert := 5;
FSearchIndentHorz := 5;
FFocused := False;
FBorderStyleInner := bsSingle;
FIsImage := False;
FIsImageBefore := False;
FIsImageIView := False;
FIsIcon := False;
FIsMetafile := False;
FIsMedia := False;
FImageColor := clDkGray;
FImageTransparent := False;
FImageResample:= False;
FImageKeepPosition := True;
FImageDrag := True;
FImageCursor := crDefault;
FImageDragCursor := crSizeAll;
FImageError := False;
FImageErrorMessage := '';
FImageErrorMessageBox := True;
//Init event handlers
OnEnter := Enter;
//Init objects
FBinHex := TATBinHex.Create(Self);
with FBinHex do
begin
Width := 1; //To "hide" control initially during text loading
Height := 1;
Parent := Self;
Align := alClient;
Color := FTextColor;
OnSelectionChange := TextSelectionChange;
end;
FImageBox := nil;
FEdit := nil;
FEditMenuItemCopy := nil;
FEditMenuItemSelectAll := nil;
FEditMenuItemSep := nil;
FEditMenu := nil;
{$ifdef MEDIA_PLAYER}
FMedia := nil;
FMediaPanel := nil;
FMediaPanel1 := nil;
FMediaPanel2 := nil;
FMediaBar := nil;
FMediaTimer := nil;
FMediaTimerBusy := False;
{$endif}
{$ifdef MEDIA_WMP64}
FWMP6 := nil;
{$endif}
{$ifdef MEDIA_WMP9}
FWMP9 := nil;
{$endif}
FMediaEndTimer := nil;
FBrowser := nil;
{$ifdef WLX}
FPlugins := TWlxPlugins.Create;
FPluginsHighPriority := True;
{$endif}
{$ifdef PRINT}
FPrintDialog := nil;
FPageSetupDialog := nil;
{$endif}
{$ifdef IVIEW}
with FIViewIntegration do
begin
Enabled := False;
ExeName := '';
ExtList := cIViewDefaultExtensions;
HighPriority := False;
end;
FIViewObject := nil;
{$endif}
//Init events
FOnMediaPlaybackEnd := nil;
FOnWebDocumentComplete := nil;
FOnWebNavigateComplete := nil;
FOnFileUnload := nil;
FOnFileLoad := nil;
FOnOptionsChange := nil;
//Hide all
HideAll;
end;
destructor TATViewer.Destroy;
begin
FreeData;
{$ifdef IVIEW}
if Assigned(FIViewObject) then
FIViewObject.Free;
{$endif}
{$ifdef WLX}
FPlugins.Free;
{$endif}
FreeMedia;
inherited Destroy;
end;
{$ifdef PRINT}
procedure TATViewer.InitDialogs;
begin
if not Assigned(FPrintDialog) then
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -