| 1 |
unit Preview; |
| 2 |
|
| 3 |
interface |
| 4 |
uses |
| 5 |
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, |
| 6 |
ActiveX, OleCtrls, HTMLDocumentEvent, |
| 7 |
{$IF Defined(DELPRO) } |
| 8 |
SHDocVw, |
| 9 |
MSHTML |
| 10 |
{$ELSE} |
| 11 |
SHDocVw_TLB, |
| 12 |
MSHTML_TLB |
| 13 |
{$IFEND} |
| 14 |
; |
| 15 |
type |
| 16 |
TPreviewBrowser = class(TWebBrowser) |
| 17 |
private |
| 18 |
FEvent: THTMLDocumentEventSink;//???????吟?????ャ?<?潟???ゃ???潟?? |
| 19 |
function makeHTML(const URL, Host, Document : String): String; |
| 20 |
procedure BrowserDocumentComplete(Sender: TObject; |
| 21 |
const pDisp: IDispatch; var URL: OleVariant); |
| 22 |
function PreviewDbClick(Sender: TObject): WordBool; |
| 23 |
protected |
| 24 |
procedure CreateParams(var Params: TCreateParams); override; |
| 25 |
public |
| 26 |
constructor Create(AOwner: TComponent); override; |
| 27 |
destructor Destroy; override; |
| 28 |
procedure PreviewImage(URL : String); |
| 29 |
function GetWindowRect(Point: TPoint) : TRect; |
| 30 |
end; |
| 31 |
|
| 32 |
implementation |
| 33 |
uses MojuUtils, GikoSystem, Setting, Giko; |
| 34 |
|
| 35 |
const |
| 36 |
//???????ャ?若???<?ゃ???? |
| 37 |
HTML_FILE_NAME = 'temp_preview.html'; |
| 38 |
// ?????鴻???若?純??????????????篏?臀?/span> |
| 39 |
DIV_X = 15; |
| 40 |
DIV_Y = 15; |
| 41 |
NICO = 'www.nicovideo.jp'; |
| 42 |
|
| 43 |
constructor TPreviewBrowser.Create(AOwner: TComponent); |
| 44 |
begin |
| 45 |
inherited Create(AOwner); |
| 46 |
FEvent := nil; |
| 47 |
OnDocumentComplete := BrowserDocumentComplete; |
| 48 |
end; |
| 49 |
|
| 50 |
destructor TPreviewBrowser.Destroy; |
| 51 |
begin |
| 52 |
if (FEvent <> nil) then begin |
| 53 |
FreeAndNil(FEvent); |
| 54 |
end; |
| 55 |
inherited Destroy; |
| 56 |
end; |
| 57 |
|
| 58 |
procedure TPreviewBrowser.CreateParams(var Params: TCreateParams); |
| 59 |
begin |
| 60 |
inherited; |
| 61 |
end; |
| 62 |
{ |
| 63 |
\brief ??絎???????URL?????????ャ??/span> |
| 64 |
\param URL ???????ャ?若?????ゃ?<?若?吾??RL |
| 65 |
} |
| 66 |
procedure TPreviewBrowser.PreviewImage(URL : String); |
| 67 |
var |
| 68 |
HtmlFileName : string; |
| 69 |
sl : TStringList; |
| 70 |
Protocol, Host, Path, Document, Port, Bookmark : string; |
| 71 |
Referer : string; |
| 72 |
Flags: OleVariant; |
| 73 |
TargetFrameName: OleVariant; |
| 74 |
PostData: OleVariant; |
| 75 |
Headers: OleVariant; |
| 76 |
begin |
| 77 |
GikoSys.ParseURI(URL, Protocol, Host, Path, Document, Port, Bookmark); |
| 78 |
Referer := Protocol + '://' + Host; |
| 79 |
if Port <> '' then |
| 80 |
Referer := Referer + ':' + Port; |
| 81 |
Referer := Referer + Path; |
| 82 |
Headers := 'Referer: ' + Referer; |
| 83 |
Flags := 0; |
| 84 |
TargetFrameName := ''; |
| 85 |
PostData := ''; |
| 86 |
|
| 87 |
HtmlFileName := GikoSys.GetAppDir + HTML_FILE_NAME; |
| 88 |
sl := TStringList.Create; |
| 89 |
try |
| 90 |
try |
| 91 |
sl.Text := makeHTML(URL, Host, Document); |
| 92 |
sl.SaveToFile(HtmlFileName); |
| 93 |
finally |
| 94 |
sl.Free; |
| 95 |
end; |
| 96 |
except |
| 97 |
end; |
| 98 |
|
| 99 |
|
| 100 |
Navigate(HtmlFileName,Flags, TargetFrameName, PostData, Headers); |
| 101 |
|
| 102 |
end; |
| 103 |
{ |
| 104 |
\breif 茵?ず???????c?潟?????泣?ゃ?冴????緇????? |
| 105 |
\param Point ?????鴻???若?純????婚罔? |
| 106 |
} |
| 107 |
function TPreviewBrowser.GetWindowRect(Point: TPoint) : TRect; |
| 108 |
var |
| 109 |
WindowWidth, WindowHeight : Integer; |
| 110 |
begin |
| 111 |
// 荐?????????翫????? |
| 112 |
case GikoSys.Setting.PreviewSize of |
| 113 |
gpsXSmall: begin |
| 114 |
WindowWidth := 128; |
| 115 |
WindowHeight := 96; |
| 116 |
end; |
| 117 |
gpsSmall: begin |
| 118 |
WindowWidth := 256; |
| 119 |
WindowHeight := 192; |
| 120 |
end; |
| 121 |
gpsLarge: begin |
| 122 |
WindowWidth := 512; |
| 123 |
WindowHeight := 384; |
| 124 |
end; |
| 125 |
gpsXLarge: begin |
| 126 |
WindowWidth := 640; |
| 127 |
WindowHeight := 480; |
| 128 |
end; |
| 129 |
else begin //gpsMedium |
| 130 |
WindowWidth := 384; |
| 131 |
WindowHeight := 288; |
| 132 |
end; |
| 133 |
end; |
| 134 |
|
| 135 |
Result := Rect(0, 0, WindowWidth, WindowHeight); |
| 136 |
// bata55篁ュ????窪?潟???????c???? |
| 137 |
// ?冴??篏?臀???????茖?罩?/span> |
| 138 |
case GikoSys.Setting.PopupPosition of |
| 139 |
gppLeftTop: OffsetRect(Result, |
| 140 |
Point.x - WindowWidth - DIV_X, Point.y - WindowHeight - DIV_Y); |
| 141 |
gppLeft: OffsetRect(Result, |
| 142 |
Point.x - WindowWidth - DIV_X, Point.y - (WindowHeight div 2)); |
| 143 |
gppLeftBottom: OffsetRect(Result, |
| 144 |
Point.x - WindowWidth - DIV_X, Point.y + DIV_Y); |
| 145 |
gppTop: OffsetRect(Result, |
| 146 |
Point.x - (WindowWidth div 2), Point.y - WindowHeight - DIV_Y); |
| 147 |
gppCenter: OffsetRect(Result, |
| 148 |
Point.x - (WindowWidth div 2), Point.y - (WindowHeight div 2)); |
| 149 |
gppBottom: OffsetRect(Result, |
| 150 |
Point.x - (WindowWidth div 2), Point.y + DIV_Y); |
| 151 |
gppRightTop: OffsetRect(Result, |
| 152 |
Point.x + DIV_X, Point.y - WindowHeight - DIV_Y); |
| 153 |
gppRight: OffsetRect(Result, |
| 154 |
Point.x + DIV_X, Point.y - (WindowHeight div 2)); |
| 155 |
gppRightBottom: OffsetRect(Result, Point.x + DIV_X, Point.y + DIV_Y); //???潟?????鴻? ???若??鐚???53羂????茗? |
| 156 |
end; |
| 157 |
|
| 158 |
end; |
| 159 |
|
| 160 |
{ |
| 161 |
\breif ???????ャ?主????TML??篏??????? |
| 162 |
\param URL ???????ャ?若?????ゃ?<?若?吾???<?ゃ??/span> |
| 163 |
} |
| 164 |
function TPreviewBrowser.makeHTML(const URL, Host, Document : String): String; |
| 165 |
var |
| 166 |
point :TPoint; |
| 167 |
rect :TRect; |
| 168 |
begin |
| 169 |
if (Pos('http://www.nicovideo.jp/watch/', URL) <> 1) then begin |
| 170 |
Result := '<html><head>'#13#10 |
| 171 |
+ '<SCRIPT>'#13#10 |
| 172 |
+ 'function init() {'#13#10 |
| 173 |
+ ' if ((document.body.clientHeight >= Image1.height) && (document.body.clientWidth >= Image1.width)) {'#13#10 |
| 174 |
+ ' } else {'#13#10 |
| 175 |
+ ' var dh, ih;'#13#10 |
| 176 |
+ ' dh = document.body.clientWidth / document.body.clientHeight;'#13#10 |
| 177 |
+ ' ih = Image1.width / Image1.height;'#13#10 |
| 178 |
+ ' if (document.body.clientWidth < document.body.clientHeight) {'#13#10 |
| 179 |
+ ' if (ih > dh)'#13#10 |
| 180 |
+ ' Image1.width = document.body.clientWidth;'#13#10 |
| 181 |
+ ' else'#13#10 |
| 182 |
+ ' Image1.height = document.body.clientHeight;'#13#10 |
| 183 |
+ ' } else {'#13#10 |
| 184 |
+ ' if (ih < dh)'#13#10 |
| 185 |
+ ' Image1.height = document.body.clientHeight;'#13#10 |
| 186 |
+ ' else'#13#10 |
| 187 |
+ ' Image1.width = document.body.clientWidth;'#13#10 |
| 188 |
+ ' }'#13#10 |
| 189 |
+ ' }'#13#10 |
| 190 |
+ ' Message.style.display = "none";'#13#10 |
| 191 |
+ '}'#13#10 |
| 192 |
+ '</SCRIPT>'#13#10 |
| 193 |
+ '</head>'#13#10 |
| 194 |
+ '<body topmargin="0" leftmargin="0" style="border-width: 1px; overflow:hidden; border-style: solid;" onLoad="init()">'#13#10 |
| 195 |
+ '<div align="center" id="Message">???????ャ?寂???筝?lt;/div>'#13#10 |
| 196 |
+ '<div align="center"><img name="Image1" border="0" src="' + URL + '"></div>'#13#10 |
| 197 |
+ '</body></html>'; |
| 198 |
end else begin |
| 199 |
// <div><iframe width="340" height="185" src="http://www.nicovideo.jp/thumb/sm2494604" scrolling="no" style="border:solid 1px #CCC;" frameborder="0"></iframe></div><div class=link_nicovideo_title><a href="" title="" target="_blank"></a></div> |
| 200 |
rect := GetWindowRect(point); |
| 201 |
|
| 202 |
Result := '<html><head>'#13#10 |
| 203 |
+ '<SCRIPT>'#13#10 |
| 204 |
+ 'function init() {'#13#10 |
| 205 |
+ ' Message.style.display = "none";'#13#10 |
| 206 |
+ '}'#13#10 |
| 207 |
+ '</SCRIPT>'#13#10 |
| 208 |
+ '</head>'#13#10 |
| 209 |
+ '<body topmargin="0" leftmargin="0" style="border-width: 1px; overflow:hidden; border-style: solid;" onLoad="init()">'#13#10 |
| 210 |
+ '<div align="center" id="Message">???????ャ?寂???筝?lt;/div>'#13#10 |
| 211 |
+ '<div><iframe width="' + IntToStr(rect.Right - rect.Left) +'" height="' + IntToStr(rect.Bottom - rect.Top) + '" src="http://' + Host + '/thumb/' + Document + '" scrolling="no" style="border:solid 1px #CCC;" frameborder="0"></iframe></div>' |
| 212 |
+ '</body></html>'; |
| 213 |
end; |
| 214 |
end; |
| 215 |
//! ?????ャ?<?潟??絎?篋??ゃ???潟?? |
| 216 |
procedure TPreviewBrowser.BrowserDocumentComplete(Sender: TObject; |
| 217 |
const pDisp: IDispatch; var URL: OleVariant); |
| 218 |
begin |
| 219 |
if (URL <> 'about:blank') then begin |
| 220 |
FEvent := THTMLDocumentEventSink.Create(Self, Self.OleObject.Document, |
| 221 |
HTMLDocumentEvents2); |
| 222 |
FEvent.OnDoubleClick := PreviewDbClick; |
| 223 |
end else begin |
| 224 |
if (FEvent <> nil) then begin |
| 225 |
FreeAndNil(FEvent); |
| 226 |
end; |
| 227 |
end; |
| 228 |
end; |
| 229 |
function TPreviewBrowser.PreviewDbClick(Sender: TObject): WordBool; |
| 230 |
begin |
| 231 |
// ?????ц????????????????с???<???祉?若?悟??宴?ф??????????? |
| 232 |
PostMessage( GikoForm.Handle , USER_POPUPCLEAR, Integer( Self ), 0 ); |
| 233 |
Result := True; |
| 234 |
end; |
| 235 |
|
| 236 |
end. |