2011-06-24 08:34:19 +00:00
|
|
|
unit mainform;
|
2011-09-08 14:12:42 +00:00
|
|
|
|
2011-06-24 08:34:19 +00:00
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2011-09-08 14:12:42 +00:00
|
|
|
LclIntf, LMessages, LclType, LResources, FPimage,
|
2011-06-24 08:34:19 +00:00
|
|
|
SysUtils, Classes, Graphics, Controls,
|
2011-09-08 14:12:42 +00:00
|
|
|
Forms, Dialogs, ExtCtrls, Menus, StdCtrls, Clipbrd,
|
|
|
|
PrintersDlgs,
|
|
|
|
ComCtrls,
|
|
|
|
{$IFDEF MSWINDOWS} ShellAPI, {$ELSE} Unix, {$ENDIF}
|
|
|
|
HTMLabt,
|
2011-09-11 06:19:45 +00:00
|
|
|
pageloader,
|
|
|
|
browserviewer;
|
2011-06-24 08:34:19 +00:00
|
|
|
|
|
|
|
type
|
2011-09-08 14:12:42 +00:00
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
{ TformBrowser }
|
2011-06-24 08:34:19 +00:00
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
TformBrowser = class(TForm)
|
2011-09-08 14:56:20 +00:00
|
|
|
labelProgress: TLabel;
|
2011-07-04 13:07:40 +00:00
|
|
|
menuViewDebug: TMenuItem;
|
|
|
|
N1: TMenuItem;
|
2011-06-24 08:34:19 +00:00
|
|
|
OpenDialog: TOpenDialog;
|
|
|
|
MainMenu: TMainMenu;
|
2011-07-04 13:07:40 +00:00
|
|
|
pageBrowser: TPageControl;
|
2011-09-08 14:41:21 +00:00
|
|
|
panelBottom: TPanel;
|
|
|
|
panelTop: TPanel;
|
2011-06-24 08:34:19 +00:00
|
|
|
File1: TMenuItem;
|
|
|
|
Open: TMenuItem;
|
|
|
|
options1: TMenuItem;
|
|
|
|
ShowImages: TMenuItem;
|
|
|
|
Fonts: TMenuItem;
|
|
|
|
editURL: TEdit;
|
2011-09-09 09:30:37 +00:00
|
|
|
buttonReload: TButton;
|
|
|
|
buttonBack: TButton;
|
|
|
|
buttonForward: TButton;
|
2011-06-24 08:34:19 +00:00
|
|
|
HistoryMenuItem: TMenuItem;
|
|
|
|
Exit1: TMenuItem;
|
|
|
|
PrintDialog: TPrintDialog;
|
|
|
|
About1: TMenuItem;
|
|
|
|
Edit2: TMenuItem;
|
|
|
|
Find1: TMenuItem;
|
|
|
|
FindDialog: TFindDialog;
|
|
|
|
CopyItem: TMenuItem;
|
|
|
|
N2: TMenuItem;
|
|
|
|
SelectAllItem: TMenuItem;
|
|
|
|
OpenTextFile: TMenuItem;
|
|
|
|
OpenImageFile: TMenuItem;
|
|
|
|
PopupMenu: TPopupMenu;
|
|
|
|
CopyImageToClipboard: TMenuItem;
|
|
|
|
Viewimage: TMenuItem;
|
|
|
|
N3: TMenuItem;
|
|
|
|
OpenInNewWindow: TMenuItem;
|
|
|
|
MetaTimer: TTimer;
|
|
|
|
Print1: TMenuItem;
|
|
|
|
Printpreview: TMenuItem;
|
|
|
|
Timer1: TTimer;
|
|
|
|
ProgressBar: TProgressBar;
|
|
|
|
PrinterSetupDialog: TPrinterSetupDialog;
|
|
|
|
PrinterSetup1: TMenuItem;
|
|
|
|
procedure editURLKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
2011-07-04 13:07:40 +00:00
|
|
|
procedure menuViewDebugClick(Sender: TObject);
|
2011-06-24 08:34:19 +00:00
|
|
|
procedure OpenFileClick(Sender: TObject);
|
|
|
|
procedure ShowImagesClick(Sender: TObject);
|
2011-09-09 09:30:37 +00:00
|
|
|
procedure buttonReloadClick(Sender: TObject);
|
2011-06-24 08:34:19 +00:00
|
|
|
procedure FormCreate(Sender: TObject);
|
|
|
|
procedure FwdBackClick(Sender: TObject);
|
|
|
|
procedure HistoryClick(Sender: TObject);
|
|
|
|
procedure HistoryChange(Sender: TObject);
|
|
|
|
procedure Exit1Click(Sender: TObject);
|
|
|
|
procedure FontColorsClick(Sender: TObject);
|
|
|
|
procedure Print1Click(Sender: TObject);
|
|
|
|
procedure About1Click(Sender: TObject);
|
|
|
|
procedure FormShow(Sender: TObject);
|
|
|
|
procedure SubmitEvent(Sender: TObject; Const AnAction, Target, EncType, Method: String;
|
|
|
|
Results: TStringList);
|
|
|
|
procedure Find1Click(Sender: TObject);
|
|
|
|
procedure FindDialogFind(Sender: TObject);
|
|
|
|
procedure ProcessingHandler(Sender: TObject; ProcessingOn: Boolean);
|
|
|
|
procedure CopyItemClick(Sender: TObject);
|
|
|
|
procedure Edit2Click(Sender: TObject);
|
|
|
|
procedure SelectAllItemClick(Sender: TObject);
|
|
|
|
procedure OpenTextFileClick(Sender: TObject);
|
|
|
|
procedure OpenImageFileClick(Sender: TObject);
|
|
|
|
procedure CopyImageToClipboardClick(Sender: TObject);
|
|
|
|
procedure ObjectClick(Sender, Obj: TObject; const OnClick: String);
|
|
|
|
procedure ViewimageClick(Sender: TObject);
|
|
|
|
procedure FormDestroy(Sender: TObject);
|
|
|
|
procedure ViewerInclude(Sender: TObject; const Command: String;
|
|
|
|
Params: TStrings; var S: string);
|
|
|
|
procedure OpenInNewWindowClick(Sender: TObject);
|
|
|
|
procedure MetaTimerTimer(Sender: TObject);
|
|
|
|
procedure MetaRefreshEvent(Sender: TObject; Delay: Integer;
|
|
|
|
const URL: String);
|
|
|
|
procedure PrintpreviewClick(Sender: TObject);
|
|
|
|
procedure Timer1Timer(Sender: TObject);
|
|
|
|
procedure PrinterSetup1Click(Sender: TObject);
|
|
|
|
private
|
|
|
|
{ Private declarations }
|
|
|
|
{$IFDEF LCLCarbon}
|
|
|
|
AppMenu : TMenuItem;
|
|
|
|
{$ENDIF}
|
2011-09-09 09:30:37 +00:00
|
|
|
History: TStringList;
|
|
|
|
HistoryIndex: Integer;
|
2011-06-24 08:34:19 +00:00
|
|
|
MediaCount: integer;
|
|
|
|
NewWindowFile: string;
|
|
|
|
NextFile, PresentFile: string;
|
|
|
|
TimerCount: integer;
|
|
|
|
OldTitle: string;
|
|
|
|
HintWindow: THintWindow;
|
2011-09-08 07:05:53 +00:00
|
|
|
HintVisible: boolean;
|
|
|
|
//
|
2011-06-24 08:34:19 +00:00
|
|
|
procedure DropFiles( Sender : TObject;
|
|
|
|
const FileNames: array of string);
|
|
|
|
procedure CloseAll;
|
|
|
|
public
|
|
|
|
{ Public declarations }
|
2011-09-11 06:19:45 +00:00
|
|
|
CurrentTab: Integer;
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure LoadURL(AURL: string);
|
2011-09-11 06:19:45 +00:00
|
|
|
procedure AddBrowserTab(AURL: string; AGoToTab: Boolean);
|
2011-09-09 09:30:37 +00:00
|
|
|
procedure AddURLToHistory(AURL: string);
|
2011-09-08 07:05:53 +00:00
|
|
|
procedure HandlePageLoaderProgress(APercent: Integer);
|
2011-09-08 07:42:24 +00:00
|
|
|
procedure HandlePageLoaderTerminated(Sender: TObject);
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
2011-07-01 07:04:46 +00:00
|
|
|
formBrowser: TformBrowser;
|
2011-06-24 08:34:19 +00:00
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
2011-09-08 14:12:42 +00:00
|
|
|
Submit, ImgForm;//, FontDlg;
|
2011-06-24 08:34:19 +00:00
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.FormCreate(Sender: TObject);
|
2011-06-24 08:34:19 +00:00
|
|
|
var
|
|
|
|
I: integer;
|
|
|
|
begin
|
2011-09-09 09:30:37 +00:00
|
|
|
History := TStringList.Create;
|
2011-09-08 07:05:53 +00:00
|
|
|
|
2011-09-11 06:19:45 +00:00
|
|
|
AddBrowserTab('', True);
|
2011-06-24 08:34:19 +00:00
|
|
|
|
2011-09-08 14:12:42 +00:00
|
|
|
Position := poScreenCenter;
|
2011-06-24 08:34:19 +00:00
|
|
|
|
2011-09-08 14:12:42 +00:00
|
|
|
{$IFDEF DARWIN} //Don't default to within app bundle.
|
|
|
|
OpenDialog.InitialDir := ExtractFilePath(ParamStr(0)) + '../../../';
|
|
|
|
{$ELSE}
|
|
|
|
OpenDialog.InitialDir := ExtractFilePath(ParamStr(0));
|
|
|
|
{$ENDIF}
|
2011-06-24 08:34:19 +00:00
|
|
|
|
2011-09-08 14:12:42 +00:00
|
|
|
Caption := 'HTML Demo, Version '+HTMLAbt.Version;
|
2011-06-24 08:34:19 +00:00
|
|
|
|
2011-09-09 09:30:37 +00:00
|
|
|
(*for I := 0 to MaxHistories-1 do
|
2011-06-24 08:34:19 +00:00
|
|
|
begin {create the MenuItems for the history list}
|
2011-09-08 14:12:42 +00:00
|
|
|
Histories[I] := TMenuItem.Create(HistoryMenuItem);
|
|
|
|
HistoryMenuItem.Insert(I, Histories[I]);
|
|
|
|
with Histories[I] do
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
|
|
|
Visible := False;
|
|
|
|
OnClick := HistoryClick;
|
|
|
|
Tag := I;
|
|
|
|
end;
|
2011-09-09 09:30:37 +00:00
|
|
|
end;*)
|
2011-06-24 08:34:19 +00:00
|
|
|
|
2011-09-08 14:12:42 +00:00
|
|
|
{$IFDEF LCLCarbon}
|
2011-06-24 08:34:19 +00:00
|
|
|
AppMenu := TMenuItem.Create(Self); //Application menu
|
|
|
|
AppMenu.Caption := #$EF#$A3#$BF; //Unicode Apple logo char
|
|
|
|
MainMenu.Items.Insert(0, AppMenu);
|
|
|
|
MainMenu.Items.Remove(About1); //Remove About as separate menu
|
|
|
|
AppMenu.Add(About1); //Add About as item in application menu
|
|
|
|
|
|
|
|
File1.Remove(File1.Items[File1.Count-2]);
|
|
|
|
File1.Remove(Exit1); //Remove Exit since have Quit
|
|
|
|
|
|
|
|
Find1.ShortCut := ShortCut(VK_F, [ssMeta]);
|
|
|
|
CopyItem.ShortCut := ShortCut(VK_C, [ssMeta]);
|
|
|
|
SelectAllItem.ShortCut := ShortCut(VK_A, [ssMeta]);
|
2011-09-08 14:12:42 +00:00
|
|
|
{$ENDIF}
|
2011-06-24 08:34:19 +00:00
|
|
|
|
2011-09-08 14:12:42 +00:00
|
|
|
AllowDropFiles := True;
|
|
|
|
OnDropFiles := DropFiles;
|
|
|
|
|
|
|
|
HintWindow := THintWindow.Create(Self);
|
|
|
|
HintWindow.Color := $C0FFFF;
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.FormShow(Sender: TObject);
|
2011-06-24 08:34:19 +00:00
|
|
|
var
|
|
|
|
S: string;
|
|
|
|
I: integer;
|
|
|
|
begin
|
2011-07-01 07:04:46 +00:00
|
|
|
// With OS X app, ParamStr not meaningful unless launched with --args switch.
|
|
|
|
if (ParamCount >= 1) {$IFDEF DARWIN} and (Copy(ParamStr(1), 1, 4) <> '-psn') {$ENDIF} then
|
2011-06-24 08:34:19 +00:00
|
|
|
begin {Parameter is file to load}
|
2011-09-08 14:12:42 +00:00
|
|
|
S := ParamStr(1);
|
2011-09-11 06:19:45 +00:00
|
|
|
GetCurrentBrowserViewer.LoadFromFile(S);
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.OpenFileClick(Sender: TObject);
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
2011-09-11 06:19:45 +00:00
|
|
|
// if Viewer.CurrentFile <> '' then
|
|
|
|
// OpenDialog.InitialDir := ExtractFilePath(Viewer.CurrentFile);
|
2011-06-24 08:34:19 +00:00
|
|
|
OpenDialog.Filter := 'HTML Files (*.htm,*.html)|*.htm;*.html'; //might have changed
|
|
|
|
if OpenDialog.Execute then
|
|
|
|
begin
|
|
|
|
Update;
|
2011-09-11 06:19:45 +00:00
|
|
|
GetCurrentBrowserViewer().LoadFromFile(OpenDialog.Filename);
|
|
|
|
Caption := GetCurrentBrowserViewer().GetDocumentTitle();
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.editURLKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
|
|
|
if Key = VK_RETURN then
|
|
|
|
begin
|
2011-07-01 07:04:46 +00:00
|
|
|
LoadURL(editURL.Text);
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2011-07-04 13:07:40 +00:00
|
|
|
procedure TformBrowser.menuViewDebugClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
pageBrowser.ShowTabs := True;
|
|
|
|
pageBrowser.ActivePageIndex := 2;
|
|
|
|
end;
|
|
|
|
|
2011-06-24 08:34:19 +00:00
|
|
|
{The Show Images menu item was clicked}
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.ShowImagesClick(Sender: TObject);
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
2011-09-11 06:19:45 +00:00
|
|
|
GetCurrentBrowserViewer().SetShowImages((Sender as TMenuItem).Checked);
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
|
2011-09-09 09:30:37 +00:00
|
|
|
procedure TformBrowser.buttonReloadClick(Sender: TObject);
|
2011-06-24 08:34:19 +00:00
|
|
|
{the Reload button was clicked}
|
|
|
|
begin
|
2011-09-08 14:12:42 +00:00
|
|
|
{$ifdef FPBROWSER_THTMLCOMP}
|
2011-09-09 09:30:37 +00:00
|
|
|
buttonReload.Enabled := False;
|
2011-09-08 14:12:42 +00:00
|
|
|
Viewer.ReLoad;
|
2011-09-09 09:30:37 +00:00
|
|
|
buttonReload.Enabled := Viewer.CurrentFile <> '';
|
2011-06-24 08:34:19 +00:00
|
|
|
Viewer.SetFocus;
|
2011-09-08 14:12:42 +00:00
|
|
|
{$endif}
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.FwdBackClick(Sender: TObject);
|
2011-06-24 08:34:19 +00:00
|
|
|
{Either the Forward or Back button was clicked}
|
|
|
|
begin
|
2011-09-08 14:12:42 +00:00
|
|
|
{$ifdef FPBROWSER_THTMLCOMP}
|
2011-09-09 09:30:37 +00:00
|
|
|
{ if Sender = buttonBack then
|
|
|
|
Viewer.HistoryIndex := Viewer.HistoryIndex +1
|
|
|
|
else
|
|
|
|
Viewer.HistoryIndex := Viewer.HistoryIndex -1;
|
|
|
|
Self.Caption := Viewer.DocumentTitle;}
|
|
|
|
{$endif}
|
|
|
|
LoadURL(History.Strings[HistoryIndex]);
|
|
|
|
if Sender = buttonBack then
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
2011-09-09 09:30:37 +00:00
|
|
|
HistoryIndex := HistoryIndex-1;
|
|
|
|
if HistoryIndex < 0 then buttonBack.Enabled := False;
|
|
|
|
buttonForward.Enabled := True;
|
|
|
|
end
|
2011-06-24 08:34:19 +00:00
|
|
|
else
|
2011-09-09 09:30:37 +00:00
|
|
|
begin
|
|
|
|
HistoryIndex := HistoryIndex+1;
|
|
|
|
if HistoryIndex >= History.Count then buttonForward.Enabled := False;
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.HistoryChange(Sender: TObject);
|
2011-06-24 08:34:19 +00:00
|
|
|
{This event occurs when something changes history list}
|
|
|
|
var
|
|
|
|
I: integer;
|
|
|
|
Cap: string[80];
|
|
|
|
begin
|
2011-09-09 09:30:37 +00:00
|
|
|
{$ifdef FPBROWSER_THTMLCOMP}
|
|
|
|
with Sender as ThtmlViewer do
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
|
|
|
{check to see which buttons are to be enabled}
|
2011-09-09 09:30:37 +00:00
|
|
|
buttonForward.Enabled := HistoryIndex > 0;
|
|
|
|
buttonBack.Enabled := HistoryIndex < History.Count-1;
|
2011-06-24 08:34:19 +00:00
|
|
|
|
|
|
|
{Enable and caption the appropriate history menuitems}
|
|
|
|
HistoryMenuItem.Visible := History.Count > 0;
|
|
|
|
for I := 0 to MaxHistories-1 do
|
|
|
|
with Histories[I] do
|
|
|
|
if I < History.Count then
|
|
|
|
Begin
|
|
|
|
Cap := History.Strings[I];
|
|
|
|
if TitleHistory[I] <> '' then
|
|
|
|
Cap := Cap + '--' + TitleHistory[I];
|
|
|
|
Caption := Cap; {Cap limits string to 80 char}
|
|
|
|
Visible := True;
|
|
|
|
Checked := I = HistoryIndex;
|
|
|
|
end
|
|
|
|
else Histories[I].Visible := False;
|
|
|
|
Caption := DocumentTitle; {keep the caption updated}
|
|
|
|
Viewer.SetFocus;
|
|
|
|
end;
|
2011-09-09 09:30:37 +00:00
|
|
|
{$endif}
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
{A history list menuitem got clicked on}
|
2011-09-08 14:12:42 +00:00
|
|
|
procedure TformBrowser.HistoryClick(Sender: TObject);
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
2011-09-09 09:30:37 +00:00
|
|
|
{$ifdef FPBROWSER_THTMLCOMP}
|
2011-06-24 08:34:19 +00:00
|
|
|
{Changing the HistoryIndex loads and positions the appropriate document}
|
|
|
|
Viewer.HistoryIndex := (Sender as TMenuItem).Tag;
|
2011-09-09 09:30:37 +00:00
|
|
|
{$endif}
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.Exit1Click(Sender: TObject);
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
2011-09-09 09:30:37 +00:00
|
|
|
Close;
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.FontColorsClick(Sender: TObject);
|
2011-09-08 14:12:42 +00:00
|
|
|
{var
|
|
|
|
FontForm: TFontForm;}
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
2011-09-08 14:12:42 +00:00
|
|
|
(*FontForm := TFontForm.Create(Self);
|
2011-06-24 08:34:19 +00:00
|
|
|
try
|
|
|
|
with FontForm do
|
|
|
|
begin
|
|
|
|
FontName := Viewer.DefFontName;
|
|
|
|
FontColor := Viewer.DefFontColor;
|
|
|
|
FontSize := Viewer.DefFontSize;
|
|
|
|
HotSpotColor := Viewer.DefHotSpotColor;
|
|
|
|
Background := Viewer.DefBackground;
|
|
|
|
if ShowModal = mrOK then
|
|
|
|
begin
|
|
|
|
Viewer.DefFontName := FontName;
|
|
|
|
Viewer.DefFontColor := FontColor;
|
|
|
|
Viewer.DefFontSize := FontSize;
|
|
|
|
Viewer.DefHotSpotColor := HotSpotColor;
|
|
|
|
Viewer.DefBackground := Background;
|
|
|
|
ReloadButtonClick(Self); {reload to see how it looks}
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
FontForm.Free;
|
2011-09-08 14:12:42 +00:00
|
|
|
end;*)
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.Print1Click(Sender: TObject);
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
2011-09-09 09:30:37 +00:00
|
|
|
{$ifdef FPBROWSER_THTMLCOMP}
|
|
|
|
with PrintDialog do
|
2011-06-24 08:34:19 +00:00
|
|
|
if Execute then
|
|
|
|
if PrintRange = prAllPages then
|
|
|
|
viewer.Print(1, 9999)
|
|
|
|
else
|
|
|
|
Viewer.Print(FromPage, ToPage);
|
2011-09-09 09:30:37 +00:00
|
|
|
{$endif}
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.PrinterSetup1Click(Sender: TObject);
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
2011-09-08 14:12:42 +00:00
|
|
|
{$IFNDEF LCLCarbon}
|
|
|
|
PrinterSetupDialog.Execute;
|
|
|
|
{$ELSE}
|
2011-06-24 08:34:19 +00:00
|
|
|
MessageDlg('Not yet supported with Carbon widgetset.',
|
|
|
|
mtError, [mbOK], 0);
|
2011-09-08 14:12:42 +00:00
|
|
|
{$ENDIF}
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.About1Click(Sender: TObject);
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
2011-09-09 09:30:37 +00:00
|
|
|
AboutBox := TAboutBox.CreateIt(Self, 'HTMLDemo', 'ThtmlViewer');
|
|
|
|
try
|
|
|
|
AboutBox.ShowModal;
|
|
|
|
finally
|
|
|
|
AboutBox.Free;
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2011-09-09 09:30:37 +00:00
|
|
|
procedure TformBrowser.SubmitEvent(Sender: TObject; const AnAction, Target,
|
|
|
|
EncType, Method: String; Results: TStringList);
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
2011-09-09 09:30:37 +00:00
|
|
|
SubmitForm.ActionText.Text := AnAction;
|
|
|
|
SubmitForm.MethodText.Text := Method;
|
|
|
|
SubmitForm.ResultBox.Items := Results;
|
2011-06-24 08:34:19 +00:00
|
|
|
Results.Free;
|
2011-09-09 09:30:37 +00:00
|
|
|
SubmitForm.Show;
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.Find1Click(Sender: TObject);
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
2011-09-09 09:30:37 +00:00
|
|
|
FindDialog.Execute;
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.FindDialogFind(Sender: TObject);
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
2011-09-09 09:30:37 +00:00
|
|
|
{$ifdef FPBROWSER_THTMLCOMP}
|
|
|
|
with FindDialog do
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
|
|
|
if not Viewer.FindEx(FindText, frMatchCase in Options, not (frDown in Options)) then
|
|
|
|
MessageDlg('No further occurances of "'+FindText+'"', mtInformation, [mbOK], 0);
|
|
|
|
end;
|
2011-09-09 09:30:37 +00:00
|
|
|
{$endif}
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.ProcessingHandler(Sender: TObject; ProcessingOn: Boolean);
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
2011-09-09 09:30:37 +00:00
|
|
|
{$ifdef FPBROWSER_THTMLCOMP}
|
|
|
|
if ProcessingOn then
|
2011-06-24 08:34:19 +00:00
|
|
|
begin {disable various buttons and menuitems during processing}
|
2011-09-09 09:30:37 +00:00
|
|
|
buttonForward.Enabled := False;
|
|
|
|
buttonBack.Enabled := False;
|
|
|
|
buttonReload.Enabled := False;
|
2011-06-24 08:34:19 +00:00
|
|
|
Print1.Enabled := False;
|
|
|
|
PrintPreview.Enabled := False;
|
|
|
|
Find1.Enabled := False;
|
|
|
|
SelectAllItem.Enabled := False;
|
|
|
|
Open.Enabled := False;
|
|
|
|
CloseAll; {in case hint window is open}
|
|
|
|
end
|
2011-09-09 09:30:37 +00:00
|
|
|
else
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
2011-09-09 09:30:37 +00:00
|
|
|
buttonForward.Enabled := Viewer.HistoryIndex > 0;
|
|
|
|
buttonBack.Enabled := Viewer.HistoryIndex < Viewer.History.Count-1;
|
|
|
|
buttonReload.Enabled := Viewer.CurrentFile <> '';
|
2011-06-24 08:34:19 +00:00
|
|
|
Print1.Enabled := Viewer.CurrentFile <> '';
|
|
|
|
PrintPreview.Enabled := Viewer.CurrentFile <> '';
|
|
|
|
Find1.Enabled := Viewer.CurrentFile <> '';
|
|
|
|
SelectAllItem.Enabled := Viewer.CurrentFile <> '';
|
|
|
|
Open.Enabled := True;
|
|
|
|
end;
|
2011-09-08 14:12:42 +00:00
|
|
|
{$endif}
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.CopyItemClick(Sender: TObject);
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
2011-09-08 14:12:42 +00:00
|
|
|
{$ifdef FPBROWSER_THTMLCOMP}
|
|
|
|
Viewer.CopyToClipboard;
|
|
|
|
{$endif}
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.Edit2Click(Sender: TObject);
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
2011-09-08 14:12:42 +00:00
|
|
|
{$ifdef FPBROWSER_THTMLCOMP}
|
|
|
|
CopyItem.Enabled := Viewer.SelLength <> 0;
|
|
|
|
{$endif}
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.SelectAllItemClick(Sender: TObject);
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
2011-09-08 14:12:42 +00:00
|
|
|
{$ifdef FPBROWSER_THTMLCOMP}
|
|
|
|
Viewer.SelectAll;
|
|
|
|
{$endif}
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.OpenTextFileClick(Sender: TObject);
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
2011-09-08 14:12:42 +00:00
|
|
|
{$ifdef FPBROWSER_THTMLCOMP}
|
2011-09-09 09:30:37 +00:00
|
|
|
if Viewer.CurrentFile <> '' then
|
|
|
|
OpenDialog.InitialDir := ExtractFilePath(Viewer.CurrentFile);
|
|
|
|
OpenDialog.Filter := 'HTML Files (*.htm,*.html)|*.htm;*.html'+
|
2011-06-24 08:34:19 +00:00
|
|
|
'|Text Files (*.txt)|*.txt'+
|
|
|
|
'|All Files (*.*)|*.*';
|
2011-09-09 09:30:37 +00:00
|
|
|
if OpenDialog.Execute then
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
2011-09-09 09:30:37 +00:00
|
|
|
buttonReload.Enabled := False;
|
|
|
|
Update;
|
|
|
|
Viewer.LoadTextFile(OpenDialog.Filename);
|
|
|
|
if Viewer.CurrentFile <> '' then
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
2011-09-09 09:30:37 +00:00
|
|
|
Caption := Viewer.DocumentTitle;
|
|
|
|
buttonReload.Enabled := True;
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
end;
|
2011-09-08 14:12:42 +00:00
|
|
|
{$endif}
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.OpenImageFileClick(Sender: TObject);
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
2011-09-09 09:30:37 +00:00
|
|
|
{$ifdef FPBROWSER_THTMLCOMP}
|
|
|
|
if Viewer.CurrentFile <> '' then
|
|
|
|
OpenDialog.InitialDir := ExtractFilePath(Viewer.CurrentFile);
|
|
|
|
OpenDialog.Filter := 'Graphics Files (*.bmp,*.gif,*.jpg,*.jpeg,*.png)|'+
|
2011-06-24 08:34:19 +00:00
|
|
|
'*.bmp;*.jpg;*.jpeg;*.gif;*.png|'+
|
|
|
|
'All Files (*.*)|*.*';
|
2011-09-09 09:30:37 +00:00
|
|
|
if OpenDialog.Execute then
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
2011-09-09 09:30:37 +00:00
|
|
|
buttonReload.Enabled := False;
|
|
|
|
Viewer.LoadImageFile(OpenDialog.Filename);
|
|
|
|
if Viewer.CurrentFile <> '' then
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
2011-09-09 09:30:37 +00:00
|
|
|
Caption := Viewer.DocumentTitle;
|
|
|
|
buttonReload.Enabled := True;
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
end;
|
2011-09-09 09:30:37 +00:00
|
|
|
{$endif}
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.DropFiles( Sender : TObject;
|
2011-06-24 08:34:19 +00:00
|
|
|
const FileNames : array of string);
|
|
|
|
var
|
|
|
|
S : string;
|
|
|
|
Ext: string;
|
|
|
|
begin
|
2011-09-09 09:30:37 +00:00
|
|
|
{$ifdef FPBROWSER_THTMLCOMP}
|
2011-06-24 08:34:19 +00:00
|
|
|
S := FileNames[0];
|
|
|
|
Ext := LowerCase(ExtractFileExt(S));
|
|
|
|
if (Ext = '.htm') or (Ext = '.html') then
|
|
|
|
Viewer.LoadFromFile(S)
|
|
|
|
else if (Ext = '.txt') then
|
|
|
|
Viewer.LoadTextFile(S)
|
|
|
|
else if (Ext = '.bmp') or (Ext = '.gif') or (Ext = '.jpg')
|
|
|
|
or (Ext = '.jpeg') or (Ext = '.png') then
|
|
|
|
Viewer.LoadImageFile(S);
|
2011-09-08 14:12:42 +00:00
|
|
|
{$endif}
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.ViewimageClick(Sender: TObject);
|
2011-06-24 08:34:19 +00:00
|
|
|
var
|
|
|
|
AForm: TImageForm;
|
|
|
|
begin
|
2011-09-08 14:12:42 +00:00
|
|
|
{$ifdef FPBROWSER_THTMLCOMP}
|
2011-07-04 13:07:40 +00:00
|
|
|
AForm := TImageForm.Create(Self);
|
|
|
|
AForm.ImageFormBitmap := FoundObject.Bitmap;
|
|
|
|
AForm.Caption := '';
|
|
|
|
AForm.Show;
|
2011-09-08 14:12:42 +00:00
|
|
|
{$endif}
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.CopyImageToClipboardClick(Sender: TObject);
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
2011-09-08 14:12:42 +00:00
|
|
|
{$ifdef FPBROWSER_THTMLCOMP}
|
2011-07-04 13:07:40 +00:00
|
|
|
Clipboard.Assign(FoundObject.Bitmap);
|
2011-09-08 14:12:42 +00:00
|
|
|
{$endif}
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.ObjectClick(Sender, Obj: TObject; const OnClick: String);
|
2011-06-24 08:34:19 +00:00
|
|
|
var
|
|
|
|
S: string;
|
|
|
|
begin
|
2011-09-08 14:12:42 +00:00
|
|
|
{$ifdef FPBROWSER_THTMLCOMP}
|
2011-09-09 09:30:37 +00:00
|
|
|
if OnClick = 'display' then
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
|
|
|
if Obj is TFormControlObj then
|
|
|
|
with TFormControlObj(Obj) do
|
|
|
|
begin
|
|
|
|
if TheControl is TCheckBox then
|
|
|
|
with TCheckBox(TheControl) do
|
|
|
|
begin
|
|
|
|
S := Value + ' is ';
|
|
|
|
if Checked then S := S + 'checked'
|
|
|
|
else S := S + 'unchecked';
|
|
|
|
MessageDlg(S, mtCustom, [mbOK], 0);
|
|
|
|
end
|
|
|
|
else if TheControl is TRadioButton then
|
|
|
|
with TRadioButton(TheControl) do
|
|
|
|
begin
|
|
|
|
S := Value + ' is checked';
|
|
|
|
MessageDlg(S, mtCustom, [mbOK], 0);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end
|
2011-09-09 09:30:37 +00:00
|
|
|
else if OnClick <> '' then
|
2011-06-24 08:34:19 +00:00
|
|
|
MessageDlg(OnClick, mtCustom, [mbOK], 0);
|
2011-09-08 14:12:42 +00:00
|
|
|
{$endif}
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.ViewerInclude(Sender: TObject; const Command: String;
|
2011-06-24 08:34:19 +00:00
|
|
|
Params: TStrings; var S: string);
|
|
|
|
{OnInclude handler}
|
|
|
|
var
|
|
|
|
Filename: string;
|
|
|
|
I: integer;
|
|
|
|
MS: TMemoryStream;
|
|
|
|
begin
|
2011-09-09 09:30:37 +00:00
|
|
|
if CompareText(Command, 'Date') = 0 then
|
|
|
|
S := DateToStr(Date) { <!--#date --> }
|
|
|
|
else if CompareText(Command, 'Time') = 0 then
|
|
|
|
S := TimeToStr(Time) { <!--#time --> }
|
|
|
|
else if CompareText(Command, 'Include') = 0 then
|
2011-06-24 08:34:19 +00:00
|
|
|
begin {an include file <!--#include FILE="filename" --> }
|
2011-09-09 09:30:37 +00:00
|
|
|
if (Params.count >= 1) then
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
|
|
|
I := Pos('file=', Lowercase(Params[0]));
|
|
|
|
if I > 0 then
|
|
|
|
begin
|
|
|
|
Filename := copy(Params[0], 6, Length(Params[0])-5);
|
|
|
|
MS := TMemoryStream.Create;
|
|
|
|
try
|
|
|
|
try
|
|
|
|
MS.LoadFromFile(Filename);
|
|
|
|
SetString(S, PChar(MS.Memory), MS.Size);
|
|
|
|
finally
|
|
|
|
MS.Free;
|
|
|
|
end;
|
|
|
|
except
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
2011-09-09 09:30:37 +00:00
|
|
|
Params.Free;
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.FormDestroy(Sender: TObject);
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
2011-07-04 13:07:40 +00:00
|
|
|
HintWindow.Free;
|
2011-09-09 09:30:37 +00:00
|
|
|
History.Free;
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
|
2011-09-08 14:12:42 +00:00
|
|
|
{$ifdef FPBROWSER_THTMLCOMP}
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.RightClick(Sender: TObject; Parameters: TRightClickParameters);
|
2011-06-24 08:34:19 +00:00
|
|
|
var
|
|
|
|
Pt: TPoint;
|
|
|
|
S, Dest: string;
|
|
|
|
I: integer;
|
|
|
|
HintWindow: THintWindow;
|
|
|
|
ARect: TRect;
|
|
|
|
begin
|
2011-07-04 13:07:40 +00:00
|
|
|
with Parameters do
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
|
|
|
FoundObject := Image;
|
|
|
|
ViewImage.Enabled := (FoundObject <> Nil) and (FoundObject.Bitmap <> Nil);
|
|
|
|
CopyImageToClipboard.Enabled := (FoundObject <> Nil) and (FoundObject.Bitmap <> Nil);
|
|
|
|
if URL <> '' then
|
|
|
|
begin
|
|
|
|
S := URL;
|
|
|
|
I := Pos('#', S);
|
|
|
|
if I >= 1 then
|
|
|
|
begin
|
|
|
|
Dest := System.Copy(S, I, 255); {local destination}
|
|
|
|
S := System.Copy(S, 1, I-1); {the file name}
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Dest := ''; {no local destination}
|
|
|
|
if S = '' then S := Viewer.CurrentFile
|
|
|
|
else S := Viewer.HTMLExpandFileName(S);
|
|
|
|
NewWindowFile := S+Dest;
|
|
|
|
OpenInNewWindow.Enabled := FileExists(S);
|
|
|
|
end
|
|
|
|
else OpenInNewWindow.Enabled := False;
|
|
|
|
|
|
|
|
GetCursorPos(Pt);
|
|
|
|
if Length(CLickWord) > 0 then
|
|
|
|
begin
|
|
|
|
HintWindow := THintWindow.Create(Self);
|
|
|
|
try
|
|
|
|
ARect := Rect(0,0,0,0);
|
|
|
|
DrawTextW(HintWindow.Canvas.Handle, @ClickWord[1], Length(ClickWord), ARect, DT_CALCRECT);
|
|
|
|
with ARect do
|
|
|
|
HintWindow.ActivateHint(Rect(Pt.X+20, Pt.Y-(Bottom-Top)-15, Pt.x+30+Right, Pt.Y-15), ClickWord);
|
|
|
|
PopupMenu.Popup(Pt.X, Pt.Y);
|
|
|
|
finally
|
|
|
|
HintWindow.Free;
|
|
|
|
end;
|
|
|
|
end
|
|
|
|
else PopupMenu.Popup(Pt.X, Pt.Y);
|
|
|
|
end;
|
|
|
|
end;
|
2011-09-08 14:12:42 +00:00
|
|
|
{$endif}
|
2011-06-24 08:34:19 +00:00
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.OpenInNewWindowClick(Sender: TObject);
|
2011-06-24 08:34:19 +00:00
|
|
|
var
|
|
|
|
PC: array[0..255] of char;
|
|
|
|
{$IFDEF LCL}
|
|
|
|
PC2: array[0..255] of char;
|
|
|
|
{$ENDIF}
|
|
|
|
begin
|
|
|
|
{$IFNDEF LCL}
|
|
|
|
WinExec(StrPCopy(PC, ParamStr(0)+' "'+NewWindowFile+'"'), sw_Show);
|
|
|
|
{$ELSE}
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
ShellExecute(Handle, nil, StrPCopy(PC, ParamStr(0)),
|
|
|
|
StrPCopy(PC2, NewWindowFile), nil, SW_SHOWNORMAL);
|
|
|
|
{$ELSE}
|
2011-07-01 05:41:36 +00:00
|
|
|
{$IFDEF DARWIN}
|
2011-06-24 08:34:19 +00:00
|
|
|
Shell('open -n "' +
|
|
|
|
ExtractFileDir(ExtractFileDir(ExtractFileDir(ParamStr(0)))) +
|
|
|
|
'" --args "' + NewWindowFile + '"');
|
|
|
|
{$ELSE}
|
|
|
|
Shell('"' + ParamStr(0) + '" "' + NewWindowFile + '"');
|
|
|
|
{$ENDIF}
|
|
|
|
{$ENDIF}
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.MetaTimerTimer(Sender: TObject);
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
2011-09-08 14:12:42 +00:00
|
|
|
{$ifdef FPBROWSER_THTMLCOMP}
|
2011-07-04 13:07:40 +00:00
|
|
|
MetaTimer.Enabled := False;
|
|
|
|
if Viewer.CurrentFile = PresentFile then {don't load if current file has changed}
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
2011-07-04 13:07:40 +00:00
|
|
|
Viewer.LoadFromFile(NextFile);
|
|
|
|
Caption := Viewer.DocumentTitle;
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
2011-09-08 14:12:42 +00:00
|
|
|
{$ENDIF}
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.MetaRefreshEvent(Sender: TObject; Delay: Integer;
|
2011-06-24 08:34:19 +00:00
|
|
|
const URL: String);
|
|
|
|
begin
|
2011-09-08 14:12:42 +00:00
|
|
|
{$ifdef FPBROWSER_THTMLCOMP}
|
2011-07-04 13:07:40 +00:00
|
|
|
NextFile := Viewer.HTMLExpandFilename(URL);
|
|
|
|
if FileExists(NextFile) then
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
2011-07-04 13:07:40 +00:00
|
|
|
PresentFile := Viewer.CurrentFile;
|
|
|
|
MetaTimer.Interval := Delay*1000;
|
|
|
|
MetaTimer.Enabled := True;
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
2011-09-08 14:12:42 +00:00
|
|
|
{$ENDIF}
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.PrintpreviewClick(Sender: TObject);
|
2011-06-24 08:34:19 +00:00
|
|
|
{$IFNDEF LCL}
|
|
|
|
var
|
|
|
|
pf: TPreviewForm;
|
|
|
|
Abort: boolean;
|
|
|
|
begin
|
2011-07-04 13:07:40 +00:00
|
|
|
pf := TPreviewForm.CreateIt(Self, Viewer, Abort);
|
|
|
|
try
|
|
|
|
if not Abort then
|
|
|
|
pf.ShowModal;
|
|
|
|
finally
|
|
|
|
pf.Free;
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
{$ELSE}
|
|
|
|
begin
|
|
|
|
MessageDlg('Not yet supported with LCL.',
|
|
|
|
mtError, [mbOK], 0);
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
|
2011-09-08 14:12:42 +00:00
|
|
|
{$ifdef FPBROWSER_THTMLCOMP}
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.ViewerMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
|
2011-06-24 08:34:19 +00:00
|
|
|
var
|
|
|
|
TitleStr: string;
|
|
|
|
begin
|
2011-07-04 13:07:40 +00:00
|
|
|
if not Timer1.Enabled and Assigned(ActiveControl) and ActiveControl.Focused then {9.25}
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
2011-07-04 13:07:40 +00:00
|
|
|
TitleStr := Viewer.TitleAttr;
|
|
|
|
if TitleStr = '' then
|
|
|
|
OldTitle := ''
|
|
|
|
else if TitleStr <> OldTitle then
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
2011-07-04 13:07:40 +00:00
|
|
|
TimerCount := 0;
|
|
|
|
Timer1.Enabled := True;
|
|
|
|
OldTitle := TitleStr;
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
2011-09-08 14:12:42 +00:00
|
|
|
{$ENDIF}
|
2011-06-24 08:34:19 +00:00
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.CloseAll;
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
2011-07-04 13:07:40 +00:00
|
|
|
Timer1.Enabled := False;
|
|
|
|
HintWindow.ReleaseHandle;
|
|
|
|
HintVisible := False;
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.LoadURL(AURL: string);
|
|
|
|
begin
|
2011-09-11 06:19:45 +00:00
|
|
|
GetCurrentBrowserViewer.LoadFromURL(AURL);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TformBrowser.AddBrowserTab(AURL: string; AGoToTab: Boolean);
|
|
|
|
var
|
|
|
|
lViewer: TBrowserViewer;
|
|
|
|
lTabSheet: TTabSheet;
|
|
|
|
begin
|
|
|
|
lTabSheet := pageBrowser.AddTabSheet(); // This call requires Lazarus 0.9.31+
|
|
|
|
|
|
|
|
lViewer := AddBrowserViewer();
|
|
|
|
lViewer.CreateViewer(lTabSheet, Self);
|
|
|
|
|
|
|
|
if AGoToTab then
|
|
|
|
begin
|
|
|
|
CurrentTab := GetBrowerViewerCount() - 1;
|
|
|
|
SetCurrentBrowserViewer(CurrentTab);
|
|
|
|
end;
|
2011-09-08 07:05:53 +00:00
|
|
|
end;
|
|
|
|
|
2011-09-09 09:30:37 +00:00
|
|
|
procedure TformBrowser.AddURLToHistory(AURL: string);
|
|
|
|
begin
|
|
|
|
History.Add(AURL);
|
|
|
|
HistoryIndex := History.Count-1;
|
|
|
|
buttonBack.Enabled := True;
|
|
|
|
end;
|
|
|
|
|
2011-09-08 07:05:53 +00:00
|
|
|
procedure TformBrowser.HandlePageLoaderProgress(APercent: Integer);
|
|
|
|
begin
|
2011-09-08 14:56:20 +00:00
|
|
|
labelProgress.Caption := 'Loading a Page';
|
|
|
|
progressBar.Position := APercent;
|
2011-09-08 07:05:53 +00:00
|
|
|
end;
|
|
|
|
|
2011-09-08 07:42:24 +00:00
|
|
|
procedure TformBrowser.HandlePageLoaderTerminated(Sender: TObject);
|
2011-09-08 07:05:53 +00:00
|
|
|
begin
|
2011-09-11 06:19:45 +00:00
|
|
|
{ labelProgress.Caption := 'Finished Loading';
|
2011-09-08 14:56:20 +00:00
|
|
|
progressBar.Position := 100;
|
|
|
|
|
2011-07-04 13:07:40 +00:00
|
|
|
// Load source and debug info
|
|
|
|
memoSource.Lines.Clear();
|
2011-09-08 07:42:24 +00:00
|
|
|
memoSource.Lines.AddStrings(MyPageLoader.ContentsList);
|
2011-07-04 13:07:40 +00:00
|
|
|
memoDebug.Lines.Clear();
|
2011-09-08 07:42:24 +00:00
|
|
|
memoDebug.Lines.AddStrings(MyPageLoader.DebugInfo);
|
2011-09-11 06:19:45 +00:00
|
|
|
AddURLToHistory(MyPageLoader.LastPageURL);}
|
2011-07-01 07:04:46 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TformBrowser.Timer1Timer(Sender: TObject);
|
2011-06-24 08:34:19 +00:00
|
|
|
const
|
|
|
|
StartCount = 2; {timer counts before hint window opens}
|
|
|
|
EndCount = 20; {after this many timer counts, hint window closes}
|
|
|
|
var
|
|
|
|
Pt, Pt1: TPoint;
|
|
|
|
ARect: TRect;
|
|
|
|
TitleStr: string;
|
|
|
|
|
|
|
|
begin
|
2011-09-08 14:12:42 +00:00
|
|
|
{$ifdef FPBROWSER_THTMLCOMP}
|
|
|
|
Inc(TimerCount);
|
|
|
|
GetCursorPos(Pt);
|
|
|
|
Pt1 := Viewer.ScreenToClient(Pt);
|
|
|
|
TitleStr := Viewer.TitleAttr;
|
|
|
|
if (TitleStr = '') or not PtInRect(Viewer.ClientRect, Pt1)then
|
|
|
|
begin
|
|
|
|
OldTitle := '';
|
|
|
|
CloseAll;
|
|
|
|
Exit;
|
|
|
|
end;
|
|
|
|
if TitleStr <> OldTitle then
|
|
|
|
begin
|
|
|
|
TimerCount := 0;
|
|
|
|
OldTitle := TitleStr;
|
|
|
|
HintWindow.ReleaseHandle;
|
|
|
|
HintVisible := False;
|
|
|
|
Exit;
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
|
2011-09-08 14:12:42 +00:00
|
|
|
if TimerCount > EndCount then
|
|
|
|
CloseAll
|
|
|
|
else if (TimerCount >= StartCount) and not HintVisible then
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
2011-09-08 14:12:42 +00:00
|
|
|
ARect := HintWindow.CalcHintRect(300, TitleStr, Nil);
|
|
|
|
with ARect do
|
|
|
|
HintWindow.ActivateHint(Rect(Pt.X, Pt.Y+18, Pt.X+Right, Pt.Y+18+Bottom), TitleStr);
|
|
|
|
HintVisible := True;
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
2011-09-08 14:12:42 +00:00
|
|
|
{$endif}
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
|
2011-09-08 14:12:42 +00:00
|
|
|
{$ifdef FPBROWSER_THTMLCOMP}
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.ViewerProgress(Sender: TObject; Stage: TProgressStage;
|
2011-06-24 08:34:19 +00:00
|
|
|
PercentDone: Integer);
|
|
|
|
begin
|
2011-09-09 09:30:37 +00:00
|
|
|
ProgressBar.Position := PercentDone;
|
|
|
|
case Stage of
|
2011-06-24 08:34:19 +00:00
|
|
|
psStarting:
|
|
|
|
ProgressBar.Visible := True;
|
|
|
|
psRunning:;
|
|
|
|
psEnding:
|
|
|
|
ProgressBar.Visible := False;
|
|
|
|
end;
|
2011-09-09 09:30:37 +00:00
|
|
|
ProgressBar.Update;
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
2011-09-08 14:12:42 +00:00
|
|
|
{$endif}
|
2011-06-24 08:34:19 +00:00
|
|
|
|
|
|
|
{HTML for print header and footer}
|
|
|
|
const
|
|
|
|
HFText: string = '<html><head><style>'+
|
|
|
|
'body {font: Arial 8pt;}'+
|
|
|
|
'</style></head>'+
|
|
|
|
'<body marginwidth="0">'+
|
|
|
|
'<table border="0" cellspacing="2" cellpadding="1" width="100%">'+
|
|
|
|
'<tr>'+
|
|
|
|
'<td>#left</td><td align="right">#right</td>'+
|
|
|
|
'</tr>'+
|
|
|
|
'</table></body></html>';
|
|
|
|
|
|
|
|
function ReplaceStr(Const S, FromStr, ToStr: string): string;
|
|
|
|
{replace FromStr with ToStr in string S.
|
|
|
|
for Delphi 6, 7, AnsiReplaceStr may be used instead.}
|
|
|
|
var
|
|
|
|
I: integer;
|
|
|
|
begin
|
2011-09-09 09:30:37 +00:00
|
|
|
I := Pos(FromStr, S);
|
|
|
|
if I > 0 then
|
2011-06-24 08:34:19 +00:00
|
|
|
begin
|
2011-09-09 09:30:37 +00:00
|
|
|
Result := S;
|
|
|
|
Delete(Result, I, Length(FromStr));
|
|
|
|
Insert(ToStr, Result, I);
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2011-09-08 14:12:42 +00:00
|
|
|
{$ifdef FPBROWSER_THTMLCOMP}
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.ViewerPrintHTMLHeader(Sender: TObject;
|
2011-06-24 08:34:19 +00:00
|
|
|
HFViewer: THTMLViewer; NumPage: Integer; LastPage: boolean; var XL, XR: integer; var StopPrinting: Boolean);
|
|
|
|
var
|
|
|
|
S: string;
|
|
|
|
begin
|
2011-09-09 09:30:37 +00:00
|
|
|
S := ReplaceStr(HFText, '#left', Viewer.DocumentTitle);
|
|
|
|
S := ReplaceStr(S, '#right', Viewer.CurrentFile);
|
|
|
|
HFViewer.LoadFromString(S);
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
|
|
|
|
2011-07-01 07:04:46 +00:00
|
|
|
procedure TformBrowser.ViewerPrintHTMLFooter(Sender: TObject;
|
2011-06-24 08:34:19 +00:00
|
|
|
HFViewer: THTMLViewer; NumPage: Integer; LastPage: boolean; var XL, XR: integer; var StopPrinting: Boolean);
|
|
|
|
var
|
|
|
|
S: string;
|
|
|
|
begin
|
2011-09-09 09:30:37 +00:00
|
|
|
S := ReplaceStr(HFText, '#left', DateToStr(Date));
|
|
|
|
S := ReplaceStr(S, '#right', 'Page '+IntToStr(NumPage));
|
|
|
|
HFViewer.LoadFromString(S);
|
2011-06-24 08:34:19 +00:00
|
|
|
end;
|
2011-09-08 14:12:42 +00:00
|
|
|
{$endif}
|
2011-06-24 08:34:19 +00:00
|
|
|
|
|
|
|
initialization
|
|
|
|
{$IFDEF LCL}
|
|
|
|
{$I mainform.lrs} {Include form's resource file}
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
end.
|