OSDN Git Service

Cookie確認でIPアドレス(ホスト名)が変わっているときに、
[gikonavigoeson/gikonavi.git] / Preview.pas
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         protected
17                 procedure CreateParams(var Params: TCreateParams); override;
18         public
19                 constructor Create(AOwner: TComponent); override;
20                 destructor Destroy; override;
21         procedure PreviewImage(URL : String);
22         function GetWindowRect(Point: TPoint) : TRect;
23         end;
24
25 implementation
26 uses MojuUtils, GikoSystem, Setting;
27
28 const
29         //\83v\83\8c\83r\83\85\81[\83t\83@\83C\83\8b\96¼
30         HTML_FILE_NAME  = 'temp_preview.html';
31     // \83}\83E\83X\83J\81[\83\\83\8b\82©\82ç\82Ì\82¸\82ç\82µ\88Ê\92u
32     DIV_X = 15;
33     DIV_Y = 15;
34
35 constructor TPreviewBrowser.Create(AOwner: TComponent);
36 begin
37         inherited Create(AOwner);
38 end;
39
40 destructor TPreviewBrowser.Destroy;
41 begin
42         inherited Destroy;
43 end;
44
45 procedure TPreviewBrowser.CreateParams(var Params: TCreateParams);
46 begin
47         inherited;
48 end;
49 {
50 \brief  \8ew\92è\82³\82ê\82½URL\82Ì\83v\83\8c\83r\83\85\81[
51 \param  URL \83v\83\8c\83r\83\85\81[\82·\82é\83C\83\81\81[\83W\82ÌURL
52 }
53 procedure TPreviewBrowser.PreviewImage(URL : String);
54 var
55     html : string;
56     HtmlFileName : string;
57     sl : TStringList;
58     Protocol, Host, Path, Document, Port, Bookmark : string;
59     Referer : string;
60         Flags: OleVariant;
61         TargetFrameName: OleVariant;
62         PostData: OleVariant;
63         Headers: OleVariant;
64 begin
65         html := '<html><head>'#13#10
66                                 + '<SCRIPT>'#13#10
67                                 + 'function init() {'#13#10
68                                 + '     if ((document.body.clientHeight >= Image1.height) && (document.body.clientWidth >= Image1.width)) {'#13#10
69                                 + '     } else {'#13#10
70                                 + '             var dh, ih;'#13#10
71                                 + '             dh = document.body.clientWidth / document.body.clientHeight;'#13#10
72                                 + '             ih = Image1.width / Image1.height;'#13#10
73                                 + '             if (document.body.clientWidth < document.body.clientHeight) {'#13#10
74                                 + '                     if (ih > dh)'#13#10
75                                 + '                             Image1.width = document.body.clientWidth;'#13#10
76                                 + '                     else'#13#10
77                                 + '                             Image1.height = document.body.clientHeight;'#13#10
78                                 + '             } else {'#13#10
79                                 + '                     if (ih < dh)'#13#10
80                                 + '                             Image1.height = document.body.clientHeight;'#13#10
81                                 + '                     else'#13#10
82                                 + '                             Image1.width = document.body.clientWidth;'#13#10
83                                 + '             }'#13#10
84                                 + '     }'#13#10
85                                 + '     Message.style.display = "none";'#13#10
86                                 + '}'#13#10
87                                 + '</SCRIPT>'#13#10
88                                 + '</head>'#13#10
89                                 + '<body topmargin="0" leftmargin="0" style="border-width: 1px; overflow:hidden; border-style: solid;" onLoad="init()">'#13#10
90                                 + '<div align="center" id="Message">\83v\83\8c\83r\83\85\81[\8dì\90¬\92\86</div>'#13#10
91                                 + '<div align="center"><img name="Image1" border="0" src="%ImageURL%"></div>'#13#10
92                                 + '</body></html>';
93     
94     HtmlFileName := GikoSys.GetAppDir + HTML_FILE_NAME;
95         sl := TStringList.Create;
96         try
97                 try
98             sl.Text := MojuUtils.
99                 CustomStringReplace(html, '%ImageURL%', URL, False);
100                         sl.SaveToFile(HtmlFileName);
101                 finally
102                         sl.Free;
103                 end;
104         except
105         end;
106
107         GikoSys.ParseURI(URL, Protocol, Host, Path, Document, Port, Bookmark);
108         Referer := Protocol + '://' + Host;
109         if Port <> '' then
110                 Referer := Referer + ':' + Port;
111         Referer := Referer + Path;
112         Headers := 'Referer: ' + Referer;
113     Flags := 0;
114     TargetFrameName := '';
115     PostData := '';
116
117         Navigate(HtmlFileName,Flags, TargetFrameName, PostData, Headers);
118
119 end;
120 {
121 \breif \95\\8e¦\82·\82é\83E\83B\83\93\83h\83E\83T\83C\83Y\82ð\8eæ\93¾\82·\82é
122 \param Point \83}\83E\83X\83J\81[\83\\83\8b\82Ì\8dÀ\95W
123 }
124 function TPreviewBrowser.GetWindowRect(Point: TPoint) : TRect;
125 var
126     WindowWidth, WindowHeight : Integer;
127 begin
128     // \90Ý\92è\82É\82æ\82é\8fê\8d\87\82í\82¯
129         case GikoSys.Setting.PreviewSize of
130                 gpsXSmall: begin
131                         WindowWidth := 128;
132                         WindowHeight := 96;
133                 end;
134                 gpsSmall: begin
135                         WindowWidth := 256;
136                         WindowHeight := 192;
137                 end;
138                 gpsLarge: begin
139                         WindowWidth := 512;
140                         WindowHeight := 384;
141                 end;
142                 gpsXLarge: begin
143                         WindowWidth := 640;
144                         WindowHeight := 480;
145                 end;
146                 else begin      //gpsMedium
147                         WindowWidth := 384;
148                         WindowHeight := 288;
149                 end;
150         end;
151
152         Result := Rect(0, 0, WindowWidth, WindowHeight);
153     // bata55\88È\91O\82Í\8d\89E\82ª\8aÔ\88á\82Á\82Ä\82½
154     // \8fo\82µ\88Ê\92u\82É\82æ\82é\95â\90³
155         case GikoSys.Setting.PopupPosition of
156                 gppLeftTop:             OffsetRect(Result,
157             Point.x - WindowWidth - DIV_X, Point.y - WindowHeight -     DIV_Y);
158                 gppLeft:                        OffsetRect(Result,
159             Point.x - WindowWidth - DIV_X, Point.y - (WindowHeight div 2));
160                 gppLeftBottom: OffsetRect(Result,
161             Point.x - WindowWidth - DIV_X, Point.y + DIV_Y);
162                 gppTop:                         OffsetRect(Result,
163             Point.x - (WindowWidth div 2), Point.y - WindowHeight - DIV_Y);
164                 gppCenter:                      OffsetRect(Result,
165             Point.x - (WindowWidth div 2), Point.y - (WindowHeight div 2));
166                 gppBottom:                      OffsetRect(Result,
167             Point.x - (WindowWidth div 2), Point.y + DIV_Y);
168                 gppRightTop:                    OffsetRect(Result,
169             Point.x + DIV_X, Point.y - WindowHeight - DIV_Y);
170                 gppRight:                       OffsetRect(Result,
171             Point.x + DIV_X, Point.y - (WindowHeight div 2));
172                 gppRightBottom:         OffsetRect(Result, Point.x + DIV_X, Point.y + DIV_Y);           //\83M\83R\83i\83r\83X\83\8c \83p\81[\83g\82P\82Ì453\8e\81\82É\8a´\8eÓ
173         end;
174
175 end;
176 end.