4 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
5 ActiveX, OleCtrls, {HintWindow,} HTMLDocumentEvent, BoardGroup,
16 TGikoPopupType = (gptRaw, gptThread);
18 TResPopupBrowser = class(TWebBrowser)
20 FChild :TResPopupBrowser;
21 FParentBrowser :TResPopupBrowser;
24 FPopupType: TGikoPopupType;
25 FEvent: THTMLDocumentEventSink;//
\83u
\83\89\83E
\83U
\83h
\83L
\83\85\83\81\83\93\83g
\83C
\83x
\83\93\83g
27 function GetBodyStyle(OnlyTitle: Boolean = False): string;
28 function GetWindowHeight : Integer;
29 function GetTitle(OnlyTitle: Boolean): string;
30 function CalcRect(WorkArea: TRect; Scroll: Boolean): TRect;
31 function ResPopupBrowserClick(Sender: TObject): WordBool;
32 function GetThread: TThreadItem;
34 procedure CreateParams(var Params: TCreateParams); override;
36 constructor Create(AOwner: TComponent); override;
37 destructor Destroy; override;
38 property Child: TResPopupBrowser read FChild;
39 property ParentBrowser:TResPopupBrowser read FParentBrowser write FParentBrowser;
40 property Title: String read FTitle write FTitle;
41 property RawDocument: String read FRawDocument write FRawDocument;
42 property Thread: TThreadItem read GetThread write FThread;
43 function CreateNewBrowser: TResPopupBrowser;
44 function CurrentBrowser: TResPopupBrowser;
45 procedure Write(ADocument: String; OnlyTitle: Boolean = False);
48 procedure NavigateBlank(Forced: Boolean);
49 property PopupType: TGikoPopupType read FPopupType write FPopupType;
56 uses MojuUtils, GikoSystem, Setting, Giko, GikoDataModule;
59 constructor TResPopupBrowser.Create(AOwner: TComponent);
61 inherited Create(AOwner);
62 TOleControl(Self).Parent := nil;
68 ShowWindow(Self.Handle, SW_HIDE);
71 destructor TResPopupBrowser.Destroy;
75 Self.OnBeforeNavigate2 := nil;
76 Self.OnStatusTextChange := nil;
77 Self.OnNewWindow2 := nil;
78 if (FChild <> nil) then begin
82 if (FEvent <> nil) then begin
90 procedure TResPopupBrowser.CreateParams(var Params: TCreateParams);
93 Params.Style := Params.Style or WS_EX_TOOLWINDOW;
96 function TResPopupBrowser.CreateNewBrowser: TResPopupBrowser;
98 if (Self.Visible) then begin
99 if (FChild <> nil) then begin
100 if (FChild.Visible) then begin
101 Result := FChild.CreateNewBrowser;
106 FChild := TResPopupBrowser.Create(Self.Owner);
107 FChild.ParentBrowser := Self;
108 FChild.NavigateBlank(False);
109 FChild.OnEnter := GikoForm.BrowserEnter;
110 FChild.OnBeforeNavigate2 := GikoForm.BrowserBeforeNavigate2;
111 FChild.OnStatusTextChange := GikoForm.BrowserStatusTextChange;
112 FChild.OnNewWindow2 := GikoForm.BrowserNewWindow2;
113 SetWindowPos(FChild.Handle, HWND_BOTTOM,
115 SWP_NOSIZE or SWP_NOMOVE or SWP_NOACTIVATE or SWP_HIDEWINDOW);
119 FParentBrowser := nil;
120 Self.NavigateBlank(False);
121 Self.OnEnter := GikoForm.BrowserEnter;
122 Self.OnBeforeNavigate2 := GikoForm.BrowserBeforeNavigate2;
123 Self.OnStatusTextChange := GikoForm.BrowserStatusTextChange;
124 Self.OnNewWindow2 := GikoForm.BrowserNewWindow2;
125 SetWindowPos(Self.Handle, HWND_BOTTOM,
127 SWP_NOSIZE or SWP_NOMOVE or SWP_NOACTIVATE or SWP_HIDEWINDOW);
131 function TResPopupBrowser.CurrentBrowser: TResPopupBrowser;
133 Result := Self.CreateNewBrowser;
134 if (Result.ParentBrowser <> nil) then
135 Result := Result.ParentBrowser;
137 procedure TResPopupBrowser.NavigateBlank(Forced: Boolean);
139 if (not Assigned(Self.Document)) or (Forced) then begin
140 Self.Navigate('about:blank');
142 while (Self.ReadyState <> READYSTATE_COMPLETE) and
143 (Self.ReadyState <> READYSTATE_INTERACTIVE) do begin
145 Forms.Application.ProcessMessages;
148 procedure TResPopupBrowser.TitlePopup;
152 procedure TResPopupBrowser.Popup;
154 Write(Self.RawDocument, false);
156 procedure TResPopupBrowser.Write(ADocument: String; OnlyTitle: Boolean = False);
161 FDispHtmlDocument: DispHTMLDocument;
164 //
\83^
\83X
\83N
\83o
\81[
\82©
\82ç
\8fÁ
\82·
165 SetWindowLongA(Self.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
167 //
\82¢
\82Á
\82½
\82ñ
\8fk
\8f¬
168 SetWindowPos(Self.Handle, HWND_BOTTOM,
170 SWP_NOACTIVATE or SWP_HIDEWINDOW);
171 doc := Idispatch( olevariant(Self.ControlInterface).Document) as IHTMLDocument2;
173 doc.charset := 'Shift_JIS';
174 doc.Write('<html><head>'#13#10 +
175 '<meta http-equiv="Content-type" content="text/html; charset=Shift_JIS">'#13#10 +
176 '<meta http-equiv="Pragma" content="no-cache">'#13#10 +
177 '<meta http-equiv="Cache-Control" content="no-cache">'#13#10 +
178 GetBodyStyle(OnlyTitle) + '</head><body>'
179 + GetTitle(OnlyTitle)
180 + ADocument + '<a name="bottom"></a></body></html>');
184 ARect := CalcRect(Screen.WorkAreaRect, not OnlyTitle);
186 FDispHtmlDocument := Idispatch(OleVariant(Self.ControlInterface).Document) as DispHTMLDocument;
187 FEvent := THTMLDocumentEventSink.Create(Self, FDispHtmlDocument, HTMLDocumentEvents2);
188 FEvent.OnClick := ResPopupBrowserClick;
190 Self.Visible := True;
191 SetWindowPos(Self.Handle, HWND_TOPMOST,
192 ARect.Left, ARect.Top,
193 (ARect.Right - ARect.Left) ,
194 (ARect.Bottom - ARect.Top),
195 SWP_NOACTIVATE or SWP_HIDEWINDOW);
196 ShowWindow(Self.Handle, SW_SHOWNOACTIVATE);
200 function TResPopupBrowser.GetTitle(OnlyTitle: Boolean): string;
202 Result := '<span id="hTitle">' + Title +'</span>';
203 if OnlyTitle then Result := Result + '<BR>';
205 function TResPopupBrowser.GetBodyStyle(OnlyTitle: Boolean = False): string;
210 Result := '<style type="text/css">' +
211 'dl { margin :0px; padding :0px}'#13#10 +
213 'border-width: 1px; border-style: solid;white-space: nowrap; ' +
214 'margin: 2px 4px 0px 0px; padding: 0px 4px 0px 0px; ';
216 if Length( GikoSys.Setting.HintFontName ) > 0 then
217 Result := Result + 'font-family:"' + GikoSys.Setting.HintFontName + '";';
218 if GikoSys.Setting.HintFontSize <> 0 then
219 Result := Result + 'font-size:' + IntToStr( GikoSys.Setting.HintFontSize ) + 'pt;';
220 if GikoSys.Setting.HintFontColor <> -1 then
221 Result := Result + 'color:#' + IntToHex( GikoSys.Setting.HintFontColor, 6 ) + ';';
222 if GikoSys.Setting.HintBackColor <> -1 then begin
223 i := ColorToRGB( GikoSys.Setting.HintBackColor );
224 Result := Result + 'background-color:#' +
225 IntToHex( (i shr 16) or (i and $ff00) or ((i and $ff) shl 16), 6 ) + ';';
228 Result := Result + 'overflow: hidden; ';
230 Result := Result + '}';
231 if GikoSys.Setting.ResPopupHeaderBold then begin
232 Result := Result + #13#10'span#hTitle{font-weight: bold; }';
234 Result := Result + '</style>';
237 procedure TResPopupBrowser.Clear;
240 if (Self.Visible) then begin
242 Self.RawDocument := '';
247 ShowWindow(Self.Handle, SW_HIDE);
248 Self.Visible := False;
251 procedure TResPopupBrowser.ChildClear;
253 if (FChild <> nil) then begin
258 function TResPopupBrowser.CalcRect(WorkArea: TRect; Scroll: Boolean): TRect;
262 h, w, dx1, dx2, dy1, dy2: Integer;
263 MaxWidth, MaxHeight: Integer;
266 ele := ((Self.Document as IHTMLDocument2).body as IHTMLElement2);
268 h := GetWindowHeight + 10;
269 w := ele.scrollWidth + 25
271 h := GetWindowHeight + 5;
272 w := ele.scrollWidth + 10;
278 Result := Rect(0, 0, w, h);
279 case GikoSys.Setting.PopupPosition of
283 dy1 := -h; dy2 := -2;
288 dy1 := - (h div 2); dy2 := 0;
297 dx1 := - (w div 2); dx2 := 0;
298 dy1 := -h; dy2 := -2;
300 //
\94p
\8e~ gppCenter: OffsetRect(Result, p.x - (w div 2), p.y - (h div 2));
303 dx1 := - (w div 2); dx2 := 0;
308 dx1 := -w; dx2 := +2;
309 dy1 := -h; dy2 := -2;
313 dx1 := -w; dx2 := +2;
314 dy1 := - (h div 2); dy2 := 0;
318 dx1 := -w; dx2 := +2;
322 //
\8f\89\8aú
\88Ê
\92u
\82É
\88Ú
\93®
323 OffsetRect(Result, p.x + dx1 + dx2, p.y + dy1 + dy2);
325 MaxWidth := WorkArea.Right - WorkArea.Left;
326 MaxHeight := WorkArea.Bottom - WorkArea.Top;
327 //
\88È
\89º
\81A
\8f\89\8aú
\88Ê
\92u
\82É
\96â
\91è
\82ª
\82 \82é
\82Æ
\82«
\82Ì
\88Ú
\93®
328 if (Result.Left < WorkArea.Left) then begin
329 //
\8bt
\83T
\83C
\83h
\82É
\97]
\97T
\82ª
\82 \82ê
\82Î
\81A
\8fo
\97Í
\88Ê
\92u
\82Ì
\8d¶
\89E
\93]
\8a·
330 if (p.X * 2 < MaxWidth) then begin
331 if ( (GikoSys.Setting.PopupPosition = gppTop) or
332 (GikoSys.Setting.PopupPosition = gppBottom)) then begin
333 OffsetRect(Result, -Result.Left, WorkArea.Left);
335 OffsetRect(Result, - (dx1 + 2 * dx2), 0);
338 //
\89æ
\96Ê
\92[
\82Ü
\82Å
\89æ
\96Ê
\95\9d\82ð
\8f¬
\82³
\82
\82·
\82é
339 Result := Rect(0, Result.Top,
340 Result.Right, Result.Bottom);
343 if (Result.Top < WorkArea.Top) then begin
344 //
\92ê
\91¤
\82É
\97]
\97T
\82ª
\82 \82ê
\82Î
\81A
\8fo
\97Í
\88Ê
\92u
\82Ì
\8fã
\89º
\93]
\8a·
345 if (p.Y * 2 < MaxHeight) then begin
346 OffsetRect(Result, 0, - (dy1 + 2 * dy2));
348 //
\89æ
\96Ê
\92[
\82Ü
\82Å
\89æ
\96Ê
\8d\82\82ð
\8f¬
\82³
\82
\82·
\82é
349 Result := Rect(Result.Left, WorkArea.Top,
350 Result.Right, Result.Bottom);
353 if (Result.Right > WorkArea.Right) then begin
354 //
\8bt
\83T
\83C
\83h
\82É
\97]
\97T
\82ª
\82 \82ê
\82Î
\81A
\8fo
\97Í
\88Ê
\92u
\82Ì
\8d¶
\89E
\93]
\8a·
355 if (p.X * 2 > WorkArea.Right) then begin
356 if( (GikoSys.Setting.PopupPosition = gppTop) or
357 (GikoSys.Setting.PopupPosition = gppBottom)) then begin
358 OffsetRect(Result, -(Result.Right - WorkArea.Right), 0);
360 OffsetRect(Result, -w - (dx1 + 2 * dx2), 0);
362 //
\8bt
\83T
\83C
\83h
\82É
\83I
\81[
\83o
\81[
\82µ
\82½
\8fê
\8d\87\82Í
\89æ
\96Ê
\92[
\82Ü
\82Å
\95\9d\82ð
\8f¬
\82³
\82
\82·
\82é
363 if (Result.Left < WorkArea.Left) then begin
364 Result := Rect(WorkArea.Left, Result.Top,
365 Result.Right, Result.Bottom);
368 //
\89æ
\96Ê
\92[
\82Ü
\82Å
\89æ
\96Ê
\95\9d\82ð
\8f¬
\82³
\82
\82·
\82é
369 Result := Rect(Result.Left, Result.Top,
370 WorkArea.Right, Result.Bottom);
373 if (Result.Bottom > WorkArea.Bottom) then begin
374 //
\8fã
\91¤
\82É
\97]
\97T
\82ª
\82 \82ê
\82Î
\81A
\8fo
\97Í
\88Ê
\92u
\82Ì
\8fã
\89º
\93]
\8a·
375 if (p.Y * 2 > WorkArea.Bottom) then begin
376 OffsetRect(Result, 0, -h - (dy1 + 2 * dy2));
377 //
\8fã
\82É
\8aÑ
\82¢
\82½
\8fê
\8d\87\82Í
\81A
378 if (Result.Top < WorkArea.Top) then begin
379 Result := Rect(Result.Left, WorkArea.Top,
380 Result.Right, Result.Bottom);
383 //
\89æ
\96Ê
\92[
\82Ü
\82Å
\89æ
\96Ê
\8d\82\82ð
\8f¬
\82³
\82
\82·
\82é
384 Result := Rect(Result.Left, Result.Top,
385 Result.Right, WorkArea.Bottom);
389 function TResPopupBrowser.GetWindowHeight : Integer;
395 //
\83u
\83\89\83E
\83U
\82ª
\83f
\81[
\83^
\82Ì
\93Ç
\82Ý
\8d\9e\82Ý
\92\86\82Ì
\8e\9e\82Í
\93Ç
\82Ý
\8d\9e\82Ý
\82ð
\91Ò
\82Â
396 while (Self.ReadyState <> READYSTATE_COMPLETE) and
397 (Self.ReadyState <> READYSTATE_INTERACTIVE) do begin
399 Forms.Application.ProcessMessages;
404 item := OleVariant( Self.Document as IHTMLDocument2)
405 .anchors.item(OleVariant('bottom'));
408 top := top + item.offsetTop;
409 item := item.offsetParent;
410 until AnsiCompareText(item.tagName, 'body' ) = 0;
415 function TResPopupBrowser.ResPopupBrowserClick(Sender: TObject): WordBool;
417 //
\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·
421 function TResPopupBrowser.GetThread: TThreadItem;
424 if (FThread <> nil) then begin
426 //
\96³
\8cø
\82È
\83|
\83C
\83\93\83^
\8c\9f\8d¸
427 if (FThread.ParentBoard <> nil) then begin
431 //
\96³
\8cø
\82È
\83|
\83C
\83\93\83^
\82¾
\82Á
\82½
436 procedure TResPopupBrowser.Blur;
438 FOleInPlaceActiveObject: IOleInPlaceActiveObject;
440 FOleInPlaceActiveObject := Self.ControlInterface as IOleInPlaceActiveObject;
441 FOleInPlaceActiveObject.OnFrameWindowActivate(False);