home *** CD-ROM | disk | FTP | other *** search
- {$A+,B-,F-,G+,I+,P+,Q-,R-,S-,T-,V+,W-,X+,O+}
- {$ifdef Win32} {$J+} {$endif}
-
- {*********************************************************}
- {* HTMLVIEW.PAS *}
- {* Copyright (c) 1995-6 by *}
- {* L. David Baldwin *}
- {* All rights reserved. *}
- {*********************************************************}
-
- unit Htmlview;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls, StdCtrls,
- {$ifdef Win32}
- vwPrint,
- {$endif}
- HTMLUn2, Forms, Dialogs, ExtCtrls, ReadHTML, HTMLSubs, Printers, Menus;
-
- const
- wm_FormSubmit = wm_User+100;
- wm_DrawBorder = wm_User+101;
- wm_MouseScroll = wm_User+102;
-
- type
- THTMLBorderStyle = (htFocused, htNone, htSingle);
- THotSpotEvent = procedure(Sender: TObject; const SRC: string) of Object;
- THotSpotClickEvent = procedure(Sender: TObject; const SRC: string;
- var Handled: boolean) of Object;
- TProcessingEvent = procedure(Sender: TObject; ProcessingOn: boolean) of Object;
-
- TPaintPanel = class(TCustomPanel)
- private
- FOnPaint: TNotifyEvent;
- FViewer: TComponent;
- Canvas2: TCanvas;
- Sizing: boolean;
- procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_EraseBkgnd;
- procedure Paint; override;
- procedure DoBackground(ACanvas: TCanvas);
- constructor Create(AOwner: TComponent; Viewer: TComponent);
- property OnPaint: TNotifyEvent read FOnPaint write FOnPaint;
- end;
-
- {$ifdef Win32}
- T32ScrollBar = Class(TScrollBar) {a 32 bit scrollbar}
- private
- FPosition: integer;
- FMin, FMax, FPage: integer;
- procedure SetPosition(Value: integer);
- procedure SetMin(Value: Integer);
- procedure SetMax(Value: Integer);
- procedure CNVScroll(var Message: TWMVScroll); message CN_VSCROLL;
- public
- property Position: integer read FPosition write SetPosition;
- property Min: integer read FMin write SetMin;
- property Max: integer read FMax write SetMax;
- procedure SetParams(APosition, APage, AMin, AMax: Integer);
- end;
- {$endif}
-
- THTMLViewer = class(TWinControl)
- private
- { Private declarations }
- DontDraw: boolean;
- FTitle: PString;
- FURL: PString;
- FBase: PString;
- FCurrentFile: PString;
- FNameList: TStringList;
- FOnHotSpotCovered: THotSpotEvent;
- FOnHotSpotClick: THotSpotClickEvent;
- FOnBitmapRequest: TGetBitmapEvent;
- FOnFormSubmit: TFormSubmitEvent;
- FOnHistoryChange: TNotifyEvent;
- FOnProcessing: TProcessingEvent;
- FHistory, FTitleHistory: TStrings;
- FHistoryIndex: integer;
- FHistoryMaxCount: integer;
- FFontName: PString;
- FPreFontName: PString;
- FFontColor: TColor;
- FHotSpotColor: TColor;
- FBackGround: TColor;
- FFontSize: integer;
- FProcessing: boolean;
- FAction, FMethod: PString;
- FStringList: TStringList;
- FOldWidth: integer;
- FImageCacheCount: integer;
- FNoSelect: boolean;
- FScrollBars: TScrollStyle;
- FBorderStyle: THTMLBorderStyle;
- sbWidth: integer;
- ScrollWidth: integer;
- MaxVertical: LongInt;
- MouseScrolling: boolean;
- procedure WMSize(var Message: TWMSize); message WM_SIZE;
- procedure ScrollTo(Y: LongInt);
- procedure Scroll(Sender: TObject; ScrollCode: TScrollCode;
- var ScrollPos: Integer);
- procedure Layout;
- procedure SetViewImages(Value: boolean);
- function GetViewImages: boolean;
- procedure SetColor(Value: TColor);
- function GetBase: string;
- function GetFURL: string;
- function GetTitle: string;
- function GetCurrentFile: string;
- procedure SetBorderStyle(Value: THTMLBorderStyle);
- function GetPosition: LongInt;
- procedure SetPosition(Value: LongInt);
- function GetScrollPos: integer;
- procedure SetScrollPos(Value: integer);
- function GetScrollBarRange: integer;
- procedure SetHistoryIndex(Value: integer);
- function GetFontName: TFontName;
- procedure SetFontName(Value: TFontName);
- function GetPreFontName: TFontName;
- procedure SetPreFontName(Value: TFontName);
- procedure SetFontSize(Value: integer);
- procedure SetFontColor(Value: TColor);
- procedure SetHotSpotColor(Value: TColor);
- procedure SetOnBitmapRequest(Handler: TGetBitmapEvent);
- procedure SetOnFormSubmit(Handler: TFormSubmitEvent);
- procedure WMGetDlgCode(var Message: TMessage); message WM_GETDLGCODE;
- procedure BackgroundChange(Sender: TObject);
- procedure SubmitForm(Sender: TObject; Action, Method: string;
- Results: TStringList);
- procedure SetImageCacheCount(Value: integer);
- procedure WMFormSubmit(var Message: TMessage); message WM_FormSubmit;
- procedure WMDrawBorder(var Message: TMessage); message WM_DrawBorder;
- procedure WMMouseScroll(var Message: TMessage); message WM_MouseScroll;
- procedure SetSelLength(Value: LongInt);
- function GetSelLength: LongInt;
- procedure SetNoSelect(Value: boolean);
- procedure SetHistoryMaxCount(Value: integer);
- procedure DoEnter; override;
- procedure DoExit; override;
- procedure DrawBorder;
- procedure DoHilite(X, Y: integer);
- procedure SetScrollBars(Value: TScrollStyle);
-
- protected
- { Protected declarations }
- SectionList: TSectionList;
- PaintPanel: TPaintPanel;
- PaintBox: TPaintBox;
- {$ifdef Win32}
- VScrollBar: T32ScrollBar;
- {$else}
- VScrollBar: TScrollBar;
- {$endif}
- HScrollBar: TScrollBar;
- CaretPos, Sel1: LongInt;
- procedure DoLogic;
- procedure DoScrollBars;
- procedure SetupAndLogic;
- {$ifdef Windows}
- function GetURL(X, Y: integer; var URL: OpenString): boolean;
- {$else}
- function GetURL(X, Y: integer; var URL: String): boolean;
- {$endif}
- procedure KeyDown(var Key: Word; Shift: TShiftState); override;
- function GetPalette: HPALETTE; override;
- procedure HTMLPaint(Sender: TObject); virtual;
- procedure HTMLMouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer); virtual;
- procedure HTMLMouseMove(Sender: TObject; Shift: TShiftState; X,
- Y: Integer); virtual;
- procedure HTMLMouseUp(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer); virtual;
- procedure URLAction; virtual;
- function HotSpotClickHandled: boolean; dynamic;
- procedure BumpHistory(const FileName, Title: string; OldPos: LongInt);
- procedure LoadFile(const FileName: string);
- procedure PaintWindow(DC: HDC); override;
- procedure UpdateImageCache;
-
- public
- { Public declarations }
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- function HTMLExpandFilename(const Filename: string): string; virtual;
- procedure LoadFromFile(const FileName: string);
- procedure LoadStrings(Strings: TStrings);
- procedure LoadFromBuffer(Buffer: PChar; BufSize: LongInt);
- procedure Print(FromPage, ToPage: integer);
- function PositionTo(Dest: string): boolean;
- function Find(const S: String; MatchCase: boolean): boolean;
- procedure Clear; virtual;
- procedure CopyToClipboard;
- procedure SelectAll;
- procedure ClearHistory;
-
- property DocumentTitle: string read GetTitle;
- property URL: string read GetFURL;
- property Base: string read GetBase;
- property Position: LongInt read GetPosition write SetPosition;
- property VScrollBarPosition: integer read GetScrollPos write SetScrollPos;
- property VScrollBarRange: integer read GetScrollBarRange;
- property CurrentFile: string read GetCurrentFile;
- property History: TStrings read FHistory;
- property TitleHistory: TStrings read FTitleHistory;
- property HistoryIndex: integer read FHistoryIndex write SetHistoryIndex;
- property Processing: boolean read FProcessing;
- property SelLength: LongInt read GetSelLength write SetSelLength;
-
- published
- { Published declarations }
- property OnHotSpotCovered: THotSpotEvent read FOnHotSpotCovered
- write FOnHotSpotCovered;
- property OnHotSpotClick: THotSpotClickEvent read FOnHotSpotClick
- write FOnHotSpotClick;
- property OnBitmapRequest: TGetBitmapEvent read FOnBitmapRequest
- write SetOnBitmapRequest;
- property OnFormSubmit: TFormSubmitEvent read FOnFormSubmit
- write SetOnFormSubmit;
- property OnHistoryChange: TNotifyEvent read FOnHistoryChange
- write FOnHistoryChange;
- property ViewImages: boolean read GetViewImages write SetViewImages;
- property Enabled;
- property TabStop;
- property TabOrder;
- property Align;
- property Name;
- property Tag;
- property PopupMenu;
- property ShowHint;
- property Height default 150;
- property Width default 150;
- property DefBackground: TColor read FBackground write SetColor default clBtnFace;
- property BorderStyle: THTMLBorderStyle read FBorderStyle write SetBorderStyle;
- property Visible;
- property HistoryMaxCount: integer read FHistoryMaxCount write SetHistoryMaxCount;
- property DefFontName: TFontName read GetFontName write SetFontName;
- property DefPreFontName: TFontName read GetPreFontName write SetPreFontName;
- property DefFontSize: integer read FFontSize write SetFontSize default 12;
- property DefFontColor: TColor read FFontColor write SetFontColor
- default clBtnText;
- property DefHotSpotColor: TColor read FHotSpotColor write SetHotSpotColor
- default clBlue;
- property OnProcessing: TProcessingEvent read FOnProcessing write FOnProcessing;
- property ImageCacheCount: integer read FImageCacheCount
- write SetImageCacheCount default 5;
- property NoSelect: boolean read FNoSelect write SetNoSelect;
- property ScrollBars: TScrollStyle read FScrollBars write SetScrollBars default ssBoth;
- end;
-
- procedure Register;
-
- implementation
-
-