OSDN Git Service

bata63
[gikonavigoeson/gikonavi.git] / ResPopupBrowser.pas
index b250532..1be0fea 100644 (file)
@@ -29,6 +29,7 @@ type
         function GetTitle(OnlyTitle: Boolean): string;
                function CalcRect(WorkArea: TRect; Scroll: Boolean): TRect;
         function ResPopupBrowserClick(Sender: TObject): WordBool;
+        function ResPopupBrowserDbClick(Sender: TObject): WordBool;
         function GetThread: TThreadItem;
        protected
                procedure CreateParams(var Params: TCreateParams); override;
@@ -53,8 +54,7 @@ type
        end;
 
 implementation
-uses MojuUtils, GikoSystem, Setting, Giko, GikoDataModule;
-
+uses MojuUtils, GikoSystem, Setting, Giko, GikoDataModule, Preview;
 
 constructor TResPopupBrowser.Create(AOwner: TComponent);
 begin
@@ -66,6 +66,8 @@ begin
     RawDocument := '';
     FEvent := nil;
     ShowWindow(Self.Handle, SW_HIDE);
+    GikoSys.ShowRefCount('ResPop Create', Self.ControlInterface);
+    GikoSys.ShowRefCount('ResPop.Document Create', Self.ControlInterface.Document);
 end;
 
 destructor TResPopupBrowser.Destroy;
@@ -84,6 +86,10 @@ begin
         FEvent := nil;
     end;
     FThread := nil;
+
+    GikoSys.ShowRefCount('ResPop Desctroy', Self.ControlInterface);
+    GikoSys.ShowRefCount('ResPop.Document Create', Self.ControlInterface.Document);
+
        inherited Destroy;
 end;
 
@@ -136,7 +142,7 @@ begin
 end;
 procedure TResPopupBrowser.NavigateBlank(Forced: Boolean);
 begin
-    if (not Assigned(Self.Document)) or (Forced) then begin
+    if (not Assigned(Self.ControlInterface.Document)) or (Forced) then begin
         Self.Navigate('about:blank');
     end;
     while (Self.ReadyState <> READYSTATE_COMPLETE) and
@@ -151,14 +157,22 @@ begin
 end;
 procedure TResPopupBrowser.Popup;
 begin
-    Write(Self.RawDocument, false);
+    if (GetAsyncKeyState(VK_SHIFT) = Smallint($8001)) then begin
+        // \83V\83t\83g\89\9f\82µ\82Ä\82é\8fê\8d\87\82Í\82»\82Ì\82Ü\82Ü\8fo\82·
+        Write(Self.RawDocument, false);
+    end else begin
+        // éx\82µ\8aG\82ª\8c©\82¦\82é\82æ\82¤\82É\94¼\8ap\83X\83y\81[\83X*2\82ð&nbsp;*2\82É\92u\8a·\82·\82é
+        Write(
+            MojuUtils.CustomStringReplace(
+                Self.RawDocument, '  ', '&nbsp;&nbsp;'),
+            false);
+    end;
 end;
 procedure TResPopupBrowser.Write(ADocument: String; OnlyTitle: Boolean = False);
 var
        p: TPoint;
-    doc: Variant;
-       ARect, rect: TRect;
-    FDispHtmlDocument: DispHTMLDocument;
+    doc: OleVariant;
+       ARect: TRect;
 begin
     try
         // \83^\83X\83N\83o\81[\82©\82ç\8fÁ\82·
@@ -168,7 +182,7 @@ begin
         SetWindowPos(Self.Handle, HWND_BOTTOM,
             p.X, p.Y, 50 , 50,
             SWP_NOACTIVATE or SWP_HIDEWINDOW);
-        doc := Idispatch( olevariant(Self.ControlInterface).Document) as IHTMLDocument2;
+        doc := Self.OleObject.Document;
         doc.open;
         doc.charset := 'Shift_JIS';
         doc.Write('<html><head>'#13#10 +
@@ -180,13 +194,13 @@ begin
                 + ADocument + '<a name="bottom"></a></body></html>');
 
         doc.Close;
+        // \83}\83\8b\83`\83\82\83j\83^\91Î\89\9e
+        ARect := CalcRect(Screen.MonitorFromPoint(p).WorkareaRect,
+                        not OnlyTitle);
 
-        ARect := CalcRect(Screen.WorkAreaRect, not OnlyTitle);
-
-        FDispHtmlDocument := Idispatch(OleVariant(Self.ControlInterface).Document) as DispHTMLDocument;
-        FEvent := THTMLDocumentEventSink.Create(Self, FDispHtmlDocument, HTMLDocumentEvents2);
+        FEvent := THTMLDocumentEventSink.Create(Self, Self.OleObject.Document, HTMLDocumentEvents2);
         FEvent.OnClick := ResPopupBrowserClick;
-
+        FEvent.OnDoubleClick := ResPopupBrowserDbClick;
         Self.Visible := True;
         SetWindowPos(Self.Handle, HWND_TOPMOST,
             ARect.Left, ARect.Top,
@@ -261,9 +275,10 @@ var
     ele: IHTMLElement2;
     h, w, dx1, dx2, dy1, dy2: Integer;
     MaxWidth, MaxHeight: Integer;
+    DIV_X, DIV_Y: Integer;
 begin
        GetCursorpos(p);
-    ele := ((Self.Document as IHTMLDocument2).body as IHTMLElement2);
+    ele := ((Self.ControlInterface.Document as IHTMLDocument2).body as IHTMLElement2);
     if Scroll then begin
         h := GetWindowHeight + 10;
         w := ele.scrollWidth + 25
@@ -272,6 +287,9 @@ begin
         w := ele.scrollWidth + 10;
     end;
 
+    DIV_X := GikoSys.Setting.RespopupDeltaX;
+    DIV_Y := GikoSys.Setting.RespopupDeltaY;
+    
     dx1 := 0; dx2 := 0;
     dy1 := 0; dy2 := 0;
 
@@ -279,44 +297,44 @@ begin
     case GikoSys.Setting.PopupPosition of
         gppRightTop:
         begin
-            dx1 := 0; dx2 := -2;
-            dy1 := -h; dy2 := -2;
+            dx1 := 0; dx2 := + DIV_X;
+            dy1 := -h; dy2 := - DIV_Y;
         end;
         gppRight:
         begin
-            dx1 := 0; dx2 := -2;
+            dx1 := 0; dx2 := + DIV_X;
             dy1 := - (h div 2); dy2 := 0;
         end;
         gppRightBottom:
         begin
-            dx1 := 0; dx2 := -2;
-            dy1 := 0; dy2 := +2;
+            dx1 := 0; dx2 := + DIV_X;
+            dy1 := 0; dy2 := + DIV_Y;
         end;
         gppTop:
         begin
             dx1 := - (w div 2); dx2 := 0;
-            dy1 := -h; dy2 := -2;
+            dy1 := -h; dy2 := - DIV_Y;
         end;
         // \94p\8e~ gppCenter: OffsetRect(Result, p.x - (w div 2), p.y - (h div 2));
        gppBottom:
         begin
             dx1 := - (w div 2); dx2 := 0;
-            dy1 := 0; dy2 := +2;
+            dy1 := 0; dy2 := + DIV_Y;
         end;
         gppLeftTop:
         begin
-            dx1 := -w; dx2 := +2;
-            dy1 := -h; dy2 := -2;
+            dx1 := -w; dx2 := - DIV_X ;
+            dy1 := -h; dy2 := - DIV_Y;
         end;
         gppLeft:
         begin
-            dx1 := -w; dx2 := +2;
+            dx1 := -w; dx2 := - DIV_X;
             dy1 := - (h div 2); dy2 := 0;
         end;
         gppLeftBottom:
         begin
-            dx1 := -w; dx2 := +2;
-            dy1 := 0; dy2 := +2;
+            dx1 := -w; dx2 := - DIV_X;
+            dy1 := 0; dy2 := + DIV_Y;
         end;
     end;
     // \8f\89\8aú\88Ê\92u\82É\88Ú\93®
@@ -327,22 +345,22 @@ begin
     // \88È\89º\81A\8f\89\8aú\88Ê\92u\82É\96â\91è\82ª\82 \82é\82Æ\82«\82Ì\88Ú\93®
     if (Result.Left < WorkArea.Left) then begin
         // \8bt\83T\83C\83h\82É\97]\97T\82ª\82 \82ê\82Î\81A\8fo\97Í\88Ê\92u\82Ì\8d\89E\93]\8a·
-        if (p.X * 2 < MaxWidth) then begin
+        if ((p.X - WorkArea.Left) * 2 < MaxWidth) then begin
             if ( (GikoSys.Setting.PopupPosition = gppTop) or
                 (GikoSys.Setting.PopupPosition = gppBottom)) then begin
-                OffsetRect(Result, -Result.Left, WorkArea.Left);
+                OffsetRect(Result, -Result.Left, 0);
             end else begin
                 OffsetRect(Result, - (dx1 + 2 * dx2), 0);
             end;
         end else begin
             // \89æ\96Ê\92[\82Ü\82Å\89æ\96Ê\95\9d\82ð\8f¬\82³\82­\82·\82é
-            Result := Rect(0, Result.Top,
+            Result := Rect(WorkArea.Left, Result.Top,
                 Result.Right, Result.Bottom);
         end;
     end;
     if (Result.Top < WorkArea.Top) then begin
         // \92ê\91¤\82É\97]\97T\82ª\82 \82ê\82Î\81A\8fo\97Í\88Ê\92u\82Ì\8fã\89º\93]\8a·
-        if (p.Y * 2 < MaxHeight) then begin
+        if ((p.Y - WorkArea.Top) * 2 < MaxHeight) then begin
             OffsetRect(Result, 0, - (dy1 + 2 * dy2));
         end else begin
             // \89æ\96Ê\92[\82Ü\82Å\89æ\96Ê\8d\82\82ð\8f¬\82³\82­\82·\82é
@@ -352,7 +370,7 @@ begin
     end;
     if (Result.Right > WorkArea.Right) then begin
         // \8bt\83T\83C\83h\82É\97]\97T\82ª\82 \82ê\82Î\81A\8fo\97Í\88Ê\92u\82Ì\8d\89E\93]\8a·
-        if (p.X * 2 > WorkArea.Right) then begin
+        if ((p.X - WorkArea.Left) * 2 > MaxWidth) then begin
             if( (GikoSys.Setting.PopupPosition = gppTop) or
                 (GikoSys.Setting.PopupPosition = gppBottom)) then begin
                 OffsetRect(Result, -(Result.Right - WorkArea.Right), 0);
@@ -372,7 +390,7 @@ begin
     end;
     if (Result.Bottom > WorkArea.Bottom) then begin
         // \8fã\91¤\82É\97]\97T\82ª\82 \82ê\82Î\81A\8fo\97Í\88Ê\92u\82Ì\8fã\89º\93]\8a·
-        if (p.Y * 2 > WorkArea.Bottom) then begin
+        if ((p.Y - WorkArea.Top) * 2 > WorkArea.Bottom) then begin
             OffsetRect(Result, 0, -h - (dy1 + 2 * dy2));
             // \8fã\82É\8aÑ\82¢\82½\8fê\8d\87\82Í\81A
             if (Result.Top < WorkArea.Top) then begin
@@ -401,8 +419,7 @@ begin
 
     try
         top := 0;
-        item := OleVariant( Self.Document as IHTMLDocument2)
-                .anchors.item(OleVariant('bottom'));
+        item := Self.OleObject.Document.anchors.item(OleVariant('bottom'));
         item.focus();
         repeat
             top := top + item.offsetTop;
@@ -440,7 +457,14 @@ begin
     FOleInPlaceActiveObject := Self.ControlInterface as IOleInPlaceActiveObject;
     FOleInPlaceActiveObject.OnFrameWindowActivate(False);
 end;
-
+function TResPopupBrowser.ResPopupBrowserDbClick(Sender: TObject): WordBool;
+begin
+    // \83M\83R\83i\83r\82Ì\83t\83H\81[\83J\83X\82ð\92D\82Á\82Ä\82é\82Ì\82Å\83t\83H\81[\83\80\82É\96³\97\9d\82â\82è\95Ô\82·
+    Blur;
+    // \8e©\95ª\82Å\8e©\95ª\82Í\8fÁ\82¹\82È\82¢\82Ì\82Å\81A\83\81\83b\83Z\81[\83W\8co\97R\82Å\8fÁ\82µ\82Ä\82à\82ç\82¤
+    PostMessage( GikoForm.Handle , USER_POPUPCLEAR, Integer( Self ), 0 );
+    Result := True;
+end;
 initialization
     OleInitialize(nil);