Develop and Download Open Source Software

Browse CVS Repository

Annotation of /gikonavigoeson/gikonavi/ResPopupBrowser.pas

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1.2.4 - (hide annotations) (download) (as text)
Thu May 10 15:29:42 2007 UTC (16 years, 11 months ago) by h677
Branch: bRESPOPUP
Changes since 1.1.2.3: +69 -29 lines
File MIME type: text/x-pascal
背景色の設定、フォント設定、ウィンドウサイズ、ウィンドウ位置
の不具合の修正

1 h677 1.1.2.1 unit ResPopupBrowser;
2     interface
3     uses
4     Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
5 h677 1.1.2.2 ActiveX, OleCtrls, HintWindow,
6 h677 1.1.2.1 {$IF Defined(DELPRO) }
7     SHDocVw,
8     MSHTML
9     {$ELSE}
10     SHDocVw_TLB,
11     MSHTML_TLB
12     {$IFEND}
13     ;
14    
15     type
16     TResPopupBrowser = class(TWebBrowser)
17     private
18     FChild :TResPopupBrowser;
19     FTitle :String;
20     FPopupType: TGikoPopupType;
21 h677 1.1.2.2 function GetBodyStyle(): string;
22 h677 1.1.2.4 function GetWindowHeight : Integer;
23 h677 1.1.2.1 protected
24     procedure CreateParams(var Params: TCreateParams); override;
25     public
26     constructor Create(AOwner: TComponent); override;
27     destructor Destroy; override;
28     property Child: TResPopupBrowser read FChild;
29     property Title: String read FTitle write FTitle;
30     function CreateNewBrowser: TResPopupBrowser;
31     procedure Write(ADocument: String);
32     procedure Clear;
33     procedure ChildClear;
34     procedure NavigateBlank;
35 h677 1.1.2.4 function CalcRect(MaxHeight: Integer; MaxWidth: Integer): TRect;
36 h677 1.1.2.1 property PopupType: TGikoPopupType read FPopupType write FPopupType;
37     end;
38    
39     implementation
40     uses MojuUtils, GikoSystem, Setting, Giko;
41    
42    
43     constructor TResPopupBrowser.Create(AOwner: TComponent);
44     begin
45     inherited Create(AOwner);
46     FChild := nil;
47     Visible := False;
48 h677 1.1.2.2 Title := '';
49 h677 1.1.2.1 end;
50    
51     destructor TResPopupBrowser.Destroy;
52     begin
53     inherited Destroy;
54     end;
55    
56     procedure TResPopupBrowser.CreateParams(var Params: TCreateParams);
57     begin
58     inherited CreateParams(Params);
59     end;
60     function TResPopupBrowser.CreateNewBrowser: TResPopupBrowser;
61     begin
62     if (Self.Visible) then begin
63     if (FChild <> nil) then begin
64     if (FChild.Visible) then begin
65     Result := FChild.CreateNewBrowser;
66     end else begin
67     Result := FChild;
68     end;
69     end else begin
70     FChild := TResPopupBrowser.Create(Self);
71     TOleControl(FChild).Parent := nil;
72     FChild.NavigateBlank;
73     FChild.OnEnter := GikoForm.BrowserEnter;
74 h677 1.1.2.3 FChild.OnBeforeNavigate2 := GikoForm.BrowserBeforeNavigate2;
75 h677 1.1.2.1 FChild.OnStatusTextChange := GikoForm.BrowserStatusTextChange;
76 h677 1.1.2.2 FChild.OnNewWindow2 := GikoForm.BrowserNewWindow2;
77 h677 1.1.2.1 ShowWindow(FChild.Handle, SW_HIDE);
78     Result := FChild;
79     end;
80     end else begin
81     TOleControl(Self).Parent := nil;
82     Self.NavigateBlank;
83     Self.OnEnter := GikoForm.BrowserEnter;
84 h677 1.1.2.3 Self.OnBeforeNavigate2 := GikoForm.BrowserBeforeNavigate2;
85 h677 1.1.2.1 Self.OnStatusTextChange := GikoForm.BrowserStatusTextChange;
86 h677 1.1.2.2 Self.OnNewWindow2 := GikoForm.BrowserNewWindow2;
87 h677 1.1.2.1 Result := Self;
88     end;
89    
90     end;
91     procedure TResPopupBrowser.NavigateBlank;
92     begin
93     if (not Assigned(Self.Document)) then begin
94     Self.Navigate('about:blank');
95     end;
96     while (Self.ReadyState <> READYSTATE_COMPLETE) and
97     (Self.ReadyState <> READYSTATE_INTERACTIVE) do begin
98     Forms.Application.ProcessMessages;
99     end;
100     end;
101     procedure TResPopupBrowser.Write(ADocument: String);
102     var
103     doc: Variant;
104     ARect: TRect;
105     begin
106     try
107 h677 1.1.2.4 // 鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申
108     SetWindowPos(Self.Handle, HWND_TOP,
109     0, 0, 50 , 50,
110     SWP_NOMOVE or SWP_NOACTIVATE or SWP_HIDEWINDOW);
111    
112 h677 1.1.2.1 doc := Idispatch( olevariant(Self.ControlInterface).Document) as IHTMLDocument2;
113     doc.open;
114     doc.charset := 'Shift_JIS';
115 h677 1.1.2.2 doc.Write('<html><head>'#13#10 +
116     '<meta http-equiv="Content-type" content="text/html; charset=Shift_JIS">'#13#10 +
117     Title + GetBodyStyle + '</head><body>' +
118 h677 1.1.2.4 ADocument + '<a name="bottom"></a></body></html>');
119 h677 1.1.2.1 doc.Close;
120    
121 h677 1.1.2.4 ARect := CalcRect(Screen.Height, Screen.Width);
122 h677 1.1.2.3 SetWindowPos(Self.Handle, HWND_TOP,
123 h677 1.1.2.1 ARect.Left, ARect.Top,
124     (ARect.Right - ARect.Left) ,
125     (ARect.Bottom - ARect.Top),
126     SWP_NOACTIVATE or SWP_HIDEWINDOW);
127 h677 1.1.2.2 ShowWindow(Self.Handle, SW_SHOWNOACTIVATE);
128 h677 1.1.2.4 Self.Visible := True;
129 h677 1.1.2.1 except
130     end;
131 h677 1.1.2.2
132     end;
133    
134     function TResPopupBrowser.GetBodyStyle(): string;
135 h677 1.1.2.4 var
136     i : Integer;
137 h677 1.1.2.2 begin
138    
139     Result := '<style type="text/css">' +
140     'dl { margin :0px; padding :0px}'#13#10 +
141     'body { ' +
142     'border-width: 1px; border-style: solid;white-space: nowrap; ' +
143 h677 1.1.2.4 'margin: 2px 4px 0px 0px; padding: 0px 4px 0px 0px; ';
144 h677 1.1.2.2
145     if Length( GikoSys.Setting.HintFontName ) > 0 then
146     Result := Result + 'font-family:"' + GikoSys.Setting.HintFontName + '";';
147     if GikoSys.Setting.HintFontSize <> 0 then
148     Result := Result + 'font-size:' + IntToStr( GikoSys.Setting.HintFontSize ) + 'pt;';
149     if GikoSys.Setting.HintFontColor <> -1 then
150     Result := Result + 'color:#' + IntToHex( GikoSys.Setting.HintFontColor, 6 ) + ';';
151 h677 1.1.2.4 if GikoSys.Setting.HintBackColor <> -1 then begin
152     i := ColorToRGB( GikoSys.Setting.HintBackColor );
153 h677 1.1.2.2 Result := Result + 'background-color:#' +
154 h677 1.1.2.4 IntToHex( (i shr 16) or (i and $ff00) or ((i and $ff) shl 16), 6 ) + ';';
155     end;
156 h677 1.1.2.2
157     Result := Result + '}</style>';
158 h677 1.1.2.1 end;
159 h677 1.1.2.2
160 h677 1.1.2.1 procedure TResPopupBrowser.Clear;
161     begin
162     ChildClear;
163     if (Self.Visible) then begin
164 h677 1.1.2.2 Self.Title := '';
165 h677 1.1.2.1 Self.Visible := False;
166     ShowWindow(Self.Handle, SW_HIDE);
167     end;
168     end;
169     procedure TResPopupBrowser.ChildClear;
170     begin
171     if (FChild <> nil) then begin
172     FChild.Clear;
173     end;
174     end;
175    
176 h677 1.1.2.4 function TResPopupBrowser.CalcRect(MaxHeight: Integer; MaxWidth: Integer): TRect;
177 h677 1.1.2.1 var
178     p: TPoint;
179 h677 1.1.2.2 ele: IHTMLElement2;
180 h677 1.1.2.4 h, w: Integer;
181 h677 1.1.2.1 begin
182     GetCursorpos(p);
183 h677 1.1.2.2 ele := ((Self.Document as IHTMLDocument2).body as IHTMLElement2);
184 h677 1.1.2.4 h := GetWindowHeight + 25;
185     w := ele.scrollWidth + 25;
186     Result := Rect(0, 0, w, h);
187 h677 1.1.2.1 case GikoSys.Setting.PopupPosition of
188 h677 1.1.2.4 gppRightTop: OffsetRect(Result, p.x - w - 2, p.y - h - 2);
189     gppRight: OffsetRect(Result, p.x - w - 2, p.y - (h div 2));
190     gppRightBottom: OffsetRect(Result, p.x - w -2, p.y + 2);
191     gppTop: OffsetRect(Result, p.x - (w div 2), p.y - h - 2);
192     gppCenter: OffsetRect(Result, p.x - (w div 2), p.y - (h div 2));
193     gppBottom: OffsetRect(Result, p.x - (w div 2), p.y + 2);
194     gppLeftTop: OffsetRect(Result, p.x + 2, p.y - h - 2);
195     gppLeft: OffsetRect(Result, p.x + 2, p.y - (h div 2));
196 h677 1.1.2.3 gppLeftBottom: OffsetRect(Result, p.x + 2, p.y + 2);
197 h677 1.1.2.1 end;
198     if (Result.Left < 0) then begin
199     OffsetRect(Result, -Result.Left, 0);
200     end;
201     if (Result.Top < 0) then begin
202     OffsetRect(Result, 0, -Result.Top);
203     end;
204 h677 1.1.2.4 if (Result.Right > MaxWidth) then begin
205     OffsetRect(Result, - (Result.Right - MaxWidth), 0);
206     end;
207     if (Result.Bottom > MaxHeight) then begin
208     OffsetRect(Result, 0, - (Result.Bottom - MaxHeight));
209     end;
210     // 鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申
211     if (Result.Left < 0) then begin
212     Result := Rect(0, Result.Top,
213     Result.Right, Result.Bottom);
214     end;
215     if (Result.Top < 0) then begin
216     Result := Rect(Result.Left, 0,
217     Result.Right, Result.Bottom);
218     end;
219 h677 1.1.2.1 end;
220 h677 1.1.2.4 function TResPopupBrowser.GetWindowHeight : Integer;
221     var
222     top: Integer;
223     item: OleVariant;
224     begin
225     //鐃?鐃緒申鐃?鐃?鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申
226     while (Self.ReadyState <> READYSTATE_COMPLETE) and
227     (Self.ReadyState <> READYSTATE_INTERACTIVE) do begin
228     Sleep(1);
229     Forms.Application.ProcessMessages;
230     end;
231 h677 1.1.2.1
232 h677 1.1.2.4 try
233     top := 0;
234     item := OleVariant( Self.Document as IHTMLDocument2)
235     .anchors.item(OleVariant('bottom'));
236     item.focus();
237     repeat
238     top := top + item.offsetTop;
239     item := item.offsetParent;
240     until AnsiCompareText(item.tagName, 'body' ) = 0;
241     Result := top;
242     except
243     end;
244     end;
245 h677 1.1.2.1 end.

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