?? atviewer.pas
字號:
{************************************************}
{ }
{ ATViewer Component }
{ Copyright (C) 2006-2008 Alexey Torgashin }
{ http://atorg.net.ru }
{ support@uvviewsoft.com }
{ }
{************************************************}
{$OPTIMIZATION OFF} //Delphi 5 cannot compile this with optimization on.
{$BOOLEVAL OFF} //Short boolean evaluation required.
{$RANGECHECKS OFF} //For LOWORD/HIWORD functions to work.
{$I ATViewerOptions.inc} //ATViewer options.
{$ifdef MEDIA_WMP64} {$define MEDIA_WMP} {$endif}
{$ifdef MEDIA_WMP9} {$define MEDIA_WMP} {$endif}
unit ATViewer;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, Graphics,
StdCtrls, ExtCtrls, ComCtrls, Forms, Menus, Jpeg,
{$ifdef TNT} TntExtCtrls, {$endif}
{$ifdef GEX} GraphicEx, {$endif}
{$ifdef GIF} GIFImage, {$endif}
{$ifdef WLX} WLXProc, {$endif}
{$ifdef MEDIA_PLAYER} MPlayer, {$endif}
{$ifdef MEDIA_WMP64} MediaPlayer_TLB, {$endif}
{$ifdef MEDIA_WMP9} MediaPlayer9_TLB, {$endif}
{$ifdef MEDIA_WMP} ActiveX, {$endif}
{$ifdef IE4X} WebBrowser4_TLB, {$else} SHDocVw, {$endif}
{$ifdef PRINT} Dialogs, {$endif}
{$ifdef SEARCH} ATStreamSearch, {$endif}
{$ifdef PREVIEW} ATPrintPreview, ATxPrintProc, {$endif}
ATBinHex,
ATImageBox,
ATxCodepages,
ATxREProc;
type
TATViewerMode = (
vmodeText,
vmodeBinary,
vmodeHex,
vmodeUnicode,
vmodeRTF,
vmodeMedia,
vmodeWeb
{$ifdef WLX}, vmodeWLX {$endif}
);
TATViewerModes = set of TATViewerMode;
TATViewerMediaMode = (
vmmodeNone
{$ifdef MEDIA_PLAYER}, vmmodeMCI {$endif}
{$ifdef MEDIA_WMP64}, vmmodeWMP64 {$endif}
{$ifdef MEDIA_WMP9}, vmmodeWMP9 {$endif}
);
const
cATViewerMediaModeNames: array[TATViewerMediaMode] of string = (
''
{$ifdef MEDIA_PLAYER}, 'MCI' {$endif}
{$ifdef MEDIA_WMP64}, 'Windows Media Player 6.4' {$endif}
{$ifdef MEDIA_WMP9}, 'Windows Media Player 9.0' {$endif}
);
const
vmmodeDefault =
{$ifdef MEDIA_WMP64}
vmmodeWMP64
{$else}
{$ifdef MEDIA_PLAYER}
vmmodeMCI
{$else}
{$ifdef MEDIA_WMP9}
vmmodeWMP9
{$else}
vmmodeNone
{$endif}
{$endif}
{$endif}
;
type
TATViewerImageEffect = (
vieRotate90,
vieRotate270,
vieGrayscale,
vieNegative,
vieFlipVertical,
vieFlipHorizontal
);
{$ifdef IVIEW}
type
TATIViewIntegration = record
Enabled: Boolean;
ExeName: string; //WideString currently not supported
ExtList: string;
HighPriority: Boolean;
end;
{$endif}
type
TATViewer = class(TPanel)
private
FFileName: WideString;
FFileSize: Int64;
FFileTime: TFileTime;
FBinHex: TATBinHex;
FImageBox: TATImageBox;
FEdit: TRichEdit;
FEditMenu: TPopupMenu;
FEditMenuItemCopy: TMenuItem;
FEditMenuItemSelectAll: TMenuItem;
FEditMenuItemSep: TMenuItem;
{$ifdef MEDIA_PLAYER}
FMedia: TMediaPlayer;
FMediaPanel: TPanel;
FMediaPanel1: TPanel;
FMediaPanel2: TPanel;
FMediaBar: TTrackBar;
FMediaTimer: TTimer;
FMediaTimerBusy: Boolean;
{$endif}
{$ifdef MEDIA_WMP64}
FWMP6: TWMP;
{$endif}
{$ifdef MEDIA_WMP9}
FWMP9: TWMP9;
{$endif}
FBrowser: TWebBrowser;
{$ifdef WLX}
FPlugins: TWlxPlugins;
FPluginsHighPriority: Boolean;
{$endif}
FMediaEndTimer: TTimer;
{$ifdef PRINT}
FPrintDialog: TPrintDialog;
FPageSetupDialog: TPageSetupDialog;
{$endif}
{$ifdef IVIEW}
FIViewIntegration: TATIViewIntegration;
FIViewObject: TObject;
{$endif}
FMode: TATViewerMode;
FModeUndetected: TATViewerMode;
FModeDetect: Boolean;
FModesDisabledForDetect: TATViewerModes;
FMediaMode: TATViewerMediaMode;
FTextEncoding: TATEncoding;
FTextWrap: Boolean;
FTextDetect: Boolean;
FTextDetectSize: DWORD;
FTextDetectLimit: DWORD;
FTextDetectOEM: Boolean;
FMediaAutoPlay: Boolean;
FMediaPlayCount: Integer;
FMediaPlaylistPause: Integer;
FMediaFit: Boolean;
FMediaFitOnlyBig: Boolean;
FMediaCenter: Boolean;
FMediaVolume: Integer;
FMediaMute: Boolean;
{$ifdef OFFLINE}
FWebOffline: Boolean;
{$endif}
FWebAcceptAllFiles: Boolean;
FWebWaitForNavigate: Boolean;
FTextColor: TColor;
FTextAutoCopy: Boolean;
FFocused: Boolean;
FBorderStyleInner: TBorderStyle;
{$ifdef SEARCH}
FFindText: WideString;
FFindOptions: TATStreamSearchOptions;
FFindFinished: Boolean;
FRELastSearch: TRELastSearch;
{$endif}
FIsImage: Boolean; //Image is currently loaded
FIsImageBefore: Boolean; //Image was loaded before the last FreeData call
FIsImageIView: Boolean; //Image was loaded using IrfanView/XnView
FIsIcon: Boolean; //Icon is currently loaded
FIsMetafile: Boolean; //Metafile is currently loaded
FIsMedia: Boolean; //Media clip is currently loaded
FImageColor: TColor;
FImageTransparent: Boolean;
FImageResample: Boolean;
FImageKeepPosition: Boolean;
FImageDrag: Boolean;
FImageCursor: TCursor;
FImageDragCursor: TCursor;
FImageError: Boolean;
FImageErrorMessage: string;
FImageErrorMessageBox: Boolean;
FSearchIndentVert: Integer;
FSearchIndentHorz: Integer;
FOnMediaPlaybackEnd: TNotifyEvent;
FOnWebDocumentComplete: TNotifyEvent;
FOnWebNavigateComplete: TNotifyEvent;
FOnFileUnload: TNotifyEvent;
FOnFileLoad: TNotifyEvent;
FOnOptionsChange: TNotifyEvent;
{$ifdef PRINT}
procedure InitDialogs;
{$endif}
procedure InitEdit;
procedure InitImage;
procedure InitMediaEndTimer;
procedure InitMedia;
procedure InitWeb;
procedure FreeMedia;
function CanSetFocus: Boolean;
procedure SetMode(AValue: TATViewerMode);
procedure SetMediaMode(AValue: TATViewerMediaMode);
function GetTextEncoding: TATEncoding;
procedure SetTextEncoding(AValue: TATEncoding);
procedure SetTextWrap(AValue: Boolean);
function GetTextWidth: Integer;
function GetTextWidthHex: Integer;
function GetTextWidthFit: Boolean;
function GetTextWidthFitHex: Boolean;
function GetTextWidthFitUHex: Boolean;
function GetTextOemSpecial: Boolean;
function GetTextGutter: Boolean;
function GetTextGutterWidth: Integer;
function GetTextNonPrintable: Boolean;
procedure SetTextWidth(AValue: Integer);
procedure SetTextWidthHex(AValue: Integer);
procedure SetTextWidthFit(AValue: Boolean);
procedure SetTextWidthFitHex(AValue: Boolean);
procedure SetTextWidthFitUHex(AValue: Boolean);
procedure SetTextOemSpecial(AValue: Boolean);
procedure SetTextGutter(AValue: Boolean);
procedure SetTextGutterWidth(AValue: Integer);
procedure SetTextNonPrintable(AValue: Boolean);
procedure SetSearchIndentVert(AValue: Integer);
procedure SetSearchIndentHorz(AValue: Integer);
procedure SetMediaPosition;
procedure SetMediaFit(AValue: Boolean);
procedure SetMediaFitOnlyBig(AValue: Boolean);
procedure SetMediaCenter(AValue: Boolean);
{$ifdef OFFLINE}
procedure SetWebOffline(AValue: Boolean);
{$endif}
procedure SetTextColor(AValue: TColor);
procedure SetTextFont(AValue: TFont);
procedure SetTextFontOEM(AValue: TFont);
procedure SetTextFontFooter(AValue: TFont);
function GetTextFont: TFont;
function GetTextFontOEM: TFont;
function GetTextFontFooter: TFont;
function GetTextColorHex: TColor;
function GetTextColorHex2: TColor;
function GetTextColorHexBack: TColor;
function GetTextColorLines: TColor;
function GetTextColorError: TColor;
function GetTextColorGutter: TColor;
procedure SetTextColorHex(AValue: TColor);
procedure SetTextColorHex2(AValue: TColor);
procedure SetTextColorHexBack(AValue: TColor);
procedure SetTextColorLines(AValue: TColor);
procedure SetTextColorError(AValue: TColor);
procedure SetTextColorGutter(AValue: TColor);
//function GetTextVariableScrollbar: Boolean;
//procedure SetTextVariableScrollbar(AValue: Boolean);
{$ifdef SEARCH}
function GetSearchStarted: Boolean;
{$endif}
procedure DetectMode;
procedure LoadRTF;
procedure LoadBinary;
procedure LoadImage(APicture: TPicture = nil);
procedure LoadMedia(APicture: TPicture = nil);
procedure LoadWeb;
{$ifdef WLX}
function LoadWLX: Boolean;
procedure HideWLX;
procedure SendWLXCommand(ACmd, AParam: Integer);
procedure SendWLXParams;
function GetPluginsBeforeLoading: TWlxNameEvent;
function GetPluginsAfterLoading: TWlxNameEvent;
procedure SetPluginsBeforeLoading(AProc: TWlxNameEvent);
procedure SetPluginsAfterLoading(AProc: TWlxNameEvent);
function OpenByPlugins(AFileIsNew: Boolean): Boolean;
function GetActivePluginSupportsSearch: Boolean;
function GetActivePluginSupportsPrint: Boolean;
function GetActivePluginSupportsCommands: Boolean;
function GetActivePluginWindowHandle: THandle;
procedure CloseActivePlugin;
{$endif}
procedure FreeSearch;
procedure FreeData;
procedure HideAll;
procedure HideEdit;
procedure HideImage;
procedure HideMedia;
procedure HideWeb;
procedure Enter(Sender: TObject);
{$ifdef MEDIA_PLAYER}
procedure MediaBarChange(Sender: TObject);
procedure MediaTimerTimer(Sender: TObject);
procedure MediaNotify(Sender: TObject);
{$endif}
procedure WebBrowserDocumentComplete(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant);
procedure WebBrowserNavigateComplete2(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant);
function WebBrowserSafe: Boolean;
function GetWebBusy: Boolean;
{$ifdef IE4X}
procedure WebBrowserFileDownload(Sender: TObject; ActiveDocument: WordBool; var Cancel: WordBool);
{$endif}
{$ifdef PRINT}
function PrinterCaption: string;
procedure PrintEdit(ASelectionOnly: Boolean; ACopies: Integer);
{$endif}
function GetActivePluginName: string;
function GetPosPercent: Integer;
procedure SetPosPercent(APos: Integer);
function GetPosOffset: Int64;
procedure SetPosOffset(const APos: Int64);
{$ifdef SEARCH}
function GetOnTextSearchProgress: TATStreamSearchProgress;
procedure SetOnTextSearchProgress(AValue: TATStreamSearchProgress);
{$endif}
procedure EditMenuItemCopyClick(Sender: TObject);
procedure EditMenuItemSelectAllClick(Sender: TObject);
procedure EditURLClick(Sender: TObject; const URL: string);
procedure TextSelectionChange(Sender: TObject);
function DetectTextAndUnicode: Boolean;
{$ifdef MEDIA_WMP64}
procedure SetMediaFit_WMP6(WMP: TWMP);
procedure PlayStateChange_WMP6(Sender: TObject; OldState: Integer; NewState: Integer);
{$endif}
{$ifdef MEDIA_WMP9}
procedure SetMediaFit_WMP9(WMP: TWMP9);
procedure PlayStateChange_WMP9(Sender: TObject; NewState: Integer);
{$endif}
procedure MediaEndTimerTimer(Sender: TObject);
procedure PreparePlaybackEnd;
procedure DoPlaybackEnd;
procedure DoWebDocumentComplete;
procedure DoWebNavigateComplete;
procedure DoFileUnload;
procedure DoFileLoad;
{$ifdef NOTIF}
function GetTextAutoReload: Boolean;
function GetTextAutoReloadBeep: Boolean;
function GetTextAutoReloadFollowTail: Boolean;
procedure SetTextAutoReload(AValue: Boolean);
procedure SetTextAutoReloadBeep(AValue: Boolean);
procedure SetTextAutoReloadFollowTail(AValue: Boolean);
function GetOnTextFileReload: TNotifyEvent;
procedure SetOnTextFileReload(AEvent: TNotifyEvent);
{$endif}
procedure SetTextPopupCaption(AIndex: TATPopupCommand; const AValue: string);
function GetTextTabSize: Integer;
procedure SetTextTabSize(AValue: Integer);
function GetTextPopupCommands: TATPopupCommands;
procedure SetTextPopupCommands(AValue: TATPopupCommands);
function GetTextMaxLengths(AIndex: TATBinHexMode): Integer;
procedure SetTextMaxLengths(AIndex: TATBinHexMode; AValue: Integer);
function GetTextEncodingName: string;
procedure FocusWebBrowser;
function GetSelStart: Int64;
procedure SetSelStart(const AValue: Int64);
function GetSelLength: Int64;
procedure SetSelLength(const AValue: Int64);
function GetSelText: string;
function GetSelTextShort: string;
function GetSelTextW: WideString;
function GetSelTextShortW: WideString;
function GetImageDrag: Boolean;
procedure SetImageDrag(AValue: Boolean);
function GetImageCursor: TCursor;
procedure SetImageCursor(AValue: TCursor);
function GetImageDragCursor: TCursor;
procedure SetImageDragCursor(AValue: TCursor);
function GetImageWidth: Integer;
function GetImageHeight: Integer;
function GetImageScale: Integer;
procedure SetImageScale(AValue: Integer);
function GetMediaFit: Boolean;
function GetMediaFitOnlyBig: Boolean;
function GetMediaCenter: Boolean;
function GetTextMaxClipboardDataSizeMb: Integer;
procedure SetTextMaxClipboardDataSizeMb(AValue: Integer);
function GetMediaVolume: Integer;
procedure SetMediaVolume(AValue: Integer);
function GetMediaMute: Boolean;
procedure SetMediaMute(AValue: Boolean);
procedure SetOnOptionsChange(AEvent: TNotifyEvent);
procedure MediaSyncVolume;
function ActualExtImages: string;
{$ifdef PRINT}
function GetMarginLeft: Extended;
function GetMarginTop: Extended;
function GetMarginRight: Extended;
function GetMarginBottom: Extended;
procedure SetMarginLeft(const AValue: Extended);
procedure SetMarginTop(const AValue: Extended);
procedure SetMarginRight(const AValue: Extended);
procedure SetMarginBottom(const AValue: Extended);
function MarginsRectPx: TRect;
{$endif}
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function Open(const AFileName: WideString; APicture: TPicture = nil): Boolean;
procedure Reload;
procedure CopyToClipboard(AsHex: Boolean = False);
procedure SelectAll;
procedure SelectNone;
{$ifdef SEARCH}
function FindFirst(const AText: WideString; AOptions: TATStreamSearchOptions): Boolean;
function FindNext(AFindPrevious: Boolean = False): Boolean;
function FindDialog(AFindNext: Boolean): Boolean;
{$endif}
{$ifdef PRINT}
procedure PrintDialog;
procedure PrintPreview;
procedure PrintSetup;
{$endif}
{$ifdef PREVIEW}
function PrintOptions(ACopies: Integer; AFailOnErrors: Boolean): TATPrintOptions;
{$endif}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -