OSDN Git Service

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