OSDN Git Service

インストーラの変更を追記
[gikonavigoeson/gikonavi.git] / Preview.pas
index 1863a96..b3b4553 100644 (file)
@@ -3,7 +3,13 @@ unit Preview;
 interface
 uses
        Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
-       ActiveX, ShDocVw_TLB;
+       ActiveX, 
+{$IF Defined(DELPRO) }
+       SHDocVw
+{$ELSE}
+       SHDocVw_TLB
+{$IFEND}
+;
 
 type
        TPreviewBrowser = class(TWebBrowser)
@@ -13,17 +19,20 @@ type
        public
                constructor Create(AOwner: TComponent); override;
                destructor Destroy; override;
+        procedure PreviewImage(URL : String);
+        function GetWindowRect(Point: TPoint) : TRect;
        end;
 
 implementation
+uses MojuUtils, GikoSystem, Setting;
+
+const
+       //\83v\83\8c\83r\83\85\81[\83t\83@\83C\83\8b\96¼
+       HTML_FILE_NAME  = 'temp_preview.html';
 
 constructor TPreviewBrowser.Create(AOwner: TComponent);
-var
-       Style: Longint;
 begin
        inherited Create(AOwner);
-//     Style := GetWindowLong(Self.Handle, GWL_EXSTYLE);
-//     SetWindowLong(Self.Handle, GWL_EXSTYLE, Style or WS_EX_APPWINDOW);
 end;
 
 destructor TPreviewBrowser.Destroy;
@@ -34,10 +43,132 @@ end;
 procedure TPreviewBrowser.CreateParams(var Params: TCreateParams);
 begin
        inherited;
-//     Params.Style := WS_POPUP or  {or WS_BORDER};
-//     Params.WindowClass.Style := Params.WindowClass.Style or CS_SAVEBITS;
-//     Params.ExStyle := WS_EX_TOOLWINDOW;
-//     AddBiDiModeExStyle(Params.ExStyle);
 end;
+{
+\brief  \8ew\92è\82³\82ê\82½URL\82Ì\83v\83\8c\83r\83\85\81[
+\param  URL \83v\83\8c\83r\83\85\81[\82·\82é\83C\83\81\81[\83W\82ÌURL
+}
+procedure TPreviewBrowser.PreviewImage(URL : String);
+var
+    html : string;
+    HtmlFileName : string;
+    sl : TStringList;
+    Protocol, Host, Path, Document, Port, Bookmark : string;
+    Referer : string;
+       Flags: OleVariant;
+       TargetFrameName: OleVariant;
+       PostData: OleVariant;
+       Headers: OleVariant;
+begin
+       html := '<html><head>'#13#10
+                               + '<SCRIPT>'#13#10
+                               + 'function init() {'#13#10
+                               + '     if ((document.body.clientHeight >= Image1.height) && (document.body.clientWidth >= Image1.width)) {'#13#10
+                               + '     } else {'#13#10
+                               + '             var dh, ih;'#13#10
+                               + '             dh = document.body.clientWidth / document.body.clientHeight;'#13#10
+                               + '             ih = Image1.width / Image1.height;'#13#10
+                               + '             if (document.body.clientWidth < document.body.clientHeight) {'#13#10
+                               + '                     if (ih > dh)'#13#10
+                               + '                             Image1.width = document.body.clientWidth;'#13#10
+                               + '                     else'#13#10
+                               + '                             Image1.height = document.body.clientHeight;'#13#10
+                               + '             } else {'#13#10
+                               + '                     if (ih < dh)'#13#10
+                               + '                             Image1.height = document.body.clientHeight;'#13#10
+                               + '                     else'#13#10
+                               + '                             Image1.width = document.body.clientWidth;'#13#10
+                               + '             }'#13#10
+                               + '     }'#13#10
+                               + '     Message.style.display = "none";'#13#10
+                               + '}'#13#10
+                               + '</SCRIPT>'#13#10
+                               + '</head>'#13#10
+                               + '<body topmargin="0" leftmargin="0" style="border-width: 1px; overflow:hidden; border-style: solid;" onLoad="init()">'#13#10
+                               + '<div align="center" id="Message">\83v\83\8c\83r\83\85\81[\8dì\90¬\92\86</div>'#13#10
+                               + '<div align="center"><img name="Image1" border="0" src="%ImageURL%"></div>'#13#10
+                               + '</body></html>';
+    
+    HtmlFileName := GikoSys.GetAppDir + HTML_FILE_NAME;
+       sl := TStringList.Create;
+       try
+               try
+            sl.Text := MojuUtils.
+                CustomStringReplace(html, '%ImageURL%', URL, False);
+                       sl.SaveToFile(HtmlFileName);
+               finally
+                       sl.Free;
+               end;
+       except
+       end;
+
+       GikoSys.ParseURI(URL, Protocol, Host, Path, Document, Port, Bookmark);
+       Referer := Protocol + '://' + Host;
+       if Port <> '' then
+               Referer := Referer + ':' + Port;
+       Referer := Referer + Path;
+       Headers := 'Referer: ' + Referer;
+    Flags := 0;
+    TargetFrameName := '';
+    PostData := '';
+
+       Navigate(HtmlFileName,Flags, TargetFrameName, PostData, Headers);
+
+end;
+{
+\breif \95\\8e¦\82·\82é\83E\83B\83\93\83h\83E\83T\83C\83Y\82ð\8eæ\93¾\82·\82é
+\param Point \83}\83E\83X\83J\81[\83\\83\8b\82Ì\8dÀ\95W
+}
+function TPreviewBrowser.GetWindowRect(Point: TPoint) : TRect;
+var
+    WindowWidth, WindowHeight : Integer;
+begin
+    // \90Ý\92è\82É\82æ\82é\8fê\8d\87\82í\82¯
+       case GikoSys.Setting.PreviewSize of
+               gpsXSmall: begin
+                       WindowWidth := 128;
+                       WindowHeight := 96;
+               end;
+               gpsSmall: begin
+                       WindowWidth := 256;
+                       WindowHeight := 192;
+               end;
+               gpsLarge: begin
+                       WindowWidth := 512;
+                       WindowHeight := 384;
+               end;
+               gpsXLarge: begin
+                       WindowWidth := 640;
+                       WindowHeight := 480;
+               end;
+               else begin      //gpsMedium
+                       WindowWidth := 384;
+                       WindowHeight := 288;
+               end;
+       end;
 
+       Result := Rect(0, 0, WindowWidth, WindowHeight);
+
+    // \8fo\82µ\88Ê\92u\82É\82æ\82é\95â\90³
+       case GikoSys.Setting.PopupPosition of
+               gppRightTop:            OffsetRect(Result,
+            Point.x - WindowWidth - 15, Point.y - WindowHeight -       15);
+               gppRight:                       OffsetRect(Result,
+            Point.x - WindowWidth - 15, Point.y - (WindowHeight div 2));
+               gppRightBottom: OffsetRect(Result,
+            Point.x - WindowWidth - 15, Point.y + 15);
+               gppTop:                         OffsetRect(Result,
+            Point.x - (WindowWidth div 2), Point.y - WindowHeight - 15);
+               gppCenter:                      OffsetRect(Result,
+            Point.x - (WindowWidth div 2), Point.y - (WindowHeight div 2));
+               gppBottom:                      OffsetRect(Result,
+            Point.x - (WindowWidth div 2), Point.y + 15);
+               gppLeftTop:                     OffsetRect(Result,
+            Point.x + 15, Point.y - WindowHeight -     15);
+               gppLeft:                        OffsetRect(Result,
+            Point.x + 15, Point.y - (WindowHeight div 2));
+               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Ó
+       end;
+
+end;
 end.