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.10 - (show annotations) (download) (as text)
Tue May 5 11:32:22 2009 UTC (14 years, 10 months ago) by h677
Branch: MAIN
CVS Tags: v1_63_1_819, v1_62_0_812, v1_61_0_796, v1_61_0_797, v1_61_0_795, v1_61_0_798, v1_61_0_799, v1_63_0_818, v1_63_0_817, v1_63_0_816, v1_63_0_815, v1_62_0_805, v1_62_0_804, v1_62_0_807, v1_62_0_806, v1_62_0_803, v1_62_0_802, v1_62_0_809, v1_62_0_810, v1_62_0_811, v1_60_1_793, v1_62_1_813, v1_61_0_800, v1_60_0_793, v1_60_0_792, v1_60_0_791, v1_60_0_790, v1_60_2_794, v1_61_1_801, HEAD
Branch point for: Bb62, Bb63, Bb60, Bb61
Changes since 1.9: +36 -4 lines
File MIME type: text/x-pascal
close #16508
画像プレビューをダブルクリックで消せるように対応。
プレビューウィンドウを消すメッセージをレスポップアップと共通化した。

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.

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