Develop and Download Open Source Software

Browse CVS Repository

Contents of /gikonavigoeson/gikonavi/Preview.pas

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.9 - (show annotations) (download) (as text)
Sun Feb 22 15:30:05 2009 UTC (15 years, 1 month ago) by h677
Branch: MAIN
CVS Tags: v1_60_0_788, v1_60_0_789, v1_60_0_782, v1_60_0_784, v1_60_0_786, v1_60_0_787, v1_60_0_783
Changes since 1.8: +69 -41 lines
File MIME type: text/x-pascal
ニコニコ動画へのリンクのサムネイルをプレビューで表示できるように拡張

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

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26