Develop and Download Open Source Software

Browse CVS Repository

Contents of /gikonavigoeson/gikonavi/ResPopupBrowser.pas

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


Revision 1.5 - (show annotations) (download) (as text)
Sun Aug 26 13:00:41 2007 UTC (16 years, 7 months ago) by h677
Branch: MAIN
CVS Tags: v1_57_0_730, v1_57_0_728, v1_57_0_729
Changes since 1.4: +10 -2 lines
File MIME type: text/x-pascal
レスポップアップウィンドウ上でのダブルクリックで、
レスポップアップウィンドウを閉じるようにした。

1 unit ResPopupBrowser;
2 interface
3 uses
4 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
5 ActiveX, OleCtrls, {HintWindow,} HTMLDocumentEvent, BoardGroup,
6 {$IF Defined(DELPRO) }
7 SHDocVw,
8 MSHTML
9 {$ELSE}
10 SHDocVw_TLB,
11 MSHTML_TLB
12 {$IFEND}
13 ;
14
15 type
16 TGikoPopupType = (gptRaw, gptThread);
17
18 TResPopupBrowser = class(TWebBrowser)
19 private
20 FChild :TResPopupBrowser;
21 FParentBrowser :TResPopupBrowser;
22 FTitle :String;
23 FRawDocument: String;
24 FPopupType: TGikoPopupType;
25 FEvent: THTMLDocumentEventSink;//???????吟?????ャ?<?潟???ゃ???潟??
26 FThread: TThreadItem;
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 ResPopupBrowserDbClick(Sender: TObject): WordBool;
33 function GetThread: TThreadItem;
34 protected
35 procedure CreateParams(var Params: TCreateParams); override;
36 public
37 constructor Create(AOwner: TComponent); override;
38 destructor Destroy; override;
39 property Child: TResPopupBrowser read FChild;
40 property ParentBrowser:TResPopupBrowser read FParentBrowser write FParentBrowser;
41 property Title: String read FTitle write FTitle;
42 property RawDocument: String read FRawDocument write FRawDocument;
43 property Thread: TThreadItem read GetThread write FThread;
44 function CreateNewBrowser: TResPopupBrowser;
45 function CurrentBrowser: TResPopupBrowser;
46 procedure Write(ADocument: String; OnlyTitle: Boolean = False);
47 procedure Clear;
48 procedure ChildClear;
49 procedure NavigateBlank(Forced: Boolean);
50 property PopupType: TGikoPopupType read FPopupType write FPopupType;
51 procedure TitlePopup;
52 procedure Popup;
53 procedure Blur;
54 end;
55
56 implementation
57 uses MojuUtils, GikoSystem, Setting, Giko, GikoDataModule, Preview;
58
59 constructor TResPopupBrowser.Create(AOwner: TComponent);
60 begin
61 inherited Create(AOwner);
62 TOleControl(Self).Parent := nil;
63 Visible := False;
64 FChild := nil;
65 Title := '';
66 RawDocument := '';
67 FEvent := nil;
68 ShowWindow(Self.Handle, SW_HIDE);
69 end;
70
71 destructor TResPopupBrowser.Destroy;
72 begin
73 Self.Blur;
74 Self.OnEnter := nil;
75 Self.OnBeforeNavigate2 := nil;
76 Self.OnStatusTextChange := nil;
77 Self.OnNewWindow2 := nil;
78 if (FChild <> nil) then begin
79 FChild.Free;
80 FChild := nil;
81 end;
82 if (FEvent <> nil) then begin
83 FEvent.Free;
84 FEvent := nil;
85 end;
86 FThread := nil;
87 inherited Destroy;
88 end;
89
90 procedure TResPopupBrowser.CreateParams(var Params: TCreateParams);
91 begin
92 inherited;
93 Params.Style := Params.Style or WS_EX_TOOLWINDOW;
94
95 end;
96 function TResPopupBrowser.CreateNewBrowser: TResPopupBrowser;
97 begin
98 if (Self.Visible) then begin
99 if (FChild <> nil) then begin
100 if (FChild.Visible) then begin
101 Result := FChild.CreateNewBrowser;
102 end else begin
103 Result := FChild;
104 end;
105 end else begin
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,
114 0, 0, 0 , 0,
115 SWP_NOSIZE or SWP_NOMOVE or SWP_NOACTIVATE or SWP_HIDEWINDOW);
116 Result := FChild;
117 end;
118 end else begin
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,
126 0, 0, 0 , 0,
127 SWP_NOSIZE or SWP_NOMOVE or SWP_NOACTIVATE or SWP_HIDEWINDOW);
128 Result := Self;
129 end;
130 end;
131 function TResPopupBrowser.CurrentBrowser: TResPopupBrowser;
132 begin
133 Result := Self.CreateNewBrowser;
134 if (Result.ParentBrowser <> nil) then
135 Result := Result.ParentBrowser;
136 end;
137 procedure TResPopupBrowser.NavigateBlank(Forced: Boolean);
138 begin
139 if (not Assigned(Self.Document)) or (Forced) then begin
140 Self.Navigate('about:blank');
141 end;
142 while (Self.ReadyState <> READYSTATE_COMPLETE) and
143 (Self.ReadyState <> READYSTATE_INTERACTIVE) do begin
144 Sleep(1);
145 Forms.Application.ProcessMessages;
146 end;
147 end;
148 procedure TResPopupBrowser.TitlePopup;
149 begin
150 Write('', True);
151 end;
152 procedure TResPopupBrowser.Popup;
153 begin
154 Write(Self.RawDocument, false);
155 end;
156 procedure TResPopupBrowser.Write(ADocument: String; OnlyTitle: Boolean = False);
157 var
158 p: TPoint;
159 doc: Variant;
160 ARect: TRect;
161 FDispHtmlDocument: DispHTMLDocument;
162 begin
163 try
164 // ?帥?鴻?????若????羔???
165 SetWindowLongA(Self.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
166 GetCursorpos(p);
167 // ???c????膰??
168 SetWindowPos(Self.Handle, HWND_BOTTOM,
169 p.X, p.Y, 50 , 50,
170 SWP_NOACTIVATE or SWP_HIDEWINDOW);
171 doc := Idispatch( olevariant(Self.ControlInterface).Document) as IHTMLDocument2;
172 doc.open;
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>');
181
182 doc.Close;
183
184 ARect := CalcRect(Screen.WorkAreaRect, not OnlyTitle);
185
186 FDispHtmlDocument := Idispatch(OleVariant(Self.ControlInterface).Document) as DispHTMLDocument;
187 FEvent := THTMLDocumentEventSink.Create(Self, FDispHtmlDocument, HTMLDocumentEvents2);
188 FEvent.OnClick := ResPopupBrowserClick;
189 FEvent.OnDoubleClick := ResPopupBrowserDbClick;
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);
197 except
198 end;
199 end;
200 function TResPopupBrowser.GetTitle(OnlyTitle: Boolean): string;
201 begin
202 Result := '<span id="hTitle">' + Title +'</span>';
203 if OnlyTitle then Result := Result + '<BR>';
204 end;
205 function TResPopupBrowser.GetBodyStyle(OnlyTitle: Boolean = False): string;
206 var
207 i : Integer;
208 begin
209
210 Result := '<style type="text/css">' +
211 'dl { margin :0px; padding :0px}'#13#10 +
212 'body { ' +
213 'border-width: 1px; border-style: solid;white-space: nowrap; ' +
214 'margin: 2px 4px 0px 0px; padding: 0px 4px 0px 0px; ';
215
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 ) + ';';
226 end;
227 if OnlyTitle then
228 Result := Result + 'overflow: hidden; ';
229
230 Result := Result + '}';
231 if GikoSys.Setting.ResPopupHeaderBold then begin
232 Result := Result + #13#10'span#hTitle{font-weight: bold; }';
233 end;
234 Result := Result + '</style>';
235 end;
236
237 procedure TResPopupBrowser.Clear;
238 begin
239 ChildClear;
240 if (Self.Visible) then begin
241 Self.Title := '';
242 Self.RawDocument := '';
243 Self.FThread := nil;
244 Self.FEvent.Free;
245 Self.FEvent := nil;
246 Self.Blur;
247 ShowWindow(Self.Handle, SW_HIDE);
248 Self.Visible := False;
249 end;
250 end;
251 procedure TResPopupBrowser.ChildClear;
252 begin
253 if (FChild <> nil) then begin
254 FChild.Clear;
255 end;
256 end;
257
258 function TResPopupBrowser.CalcRect(WorkArea: TRect; Scroll: Boolean): TRect;
259 var
260 p: TPoint;
261 ele: IHTMLElement2;
262 h, w, dx1, dx2, dy1, dy2: Integer;
263 MaxWidth, MaxHeight: Integer;
264 DIV_X, DIV_Y: Integer;
265 begin
266 GetCursorpos(p);
267 ele := ((Self.Document as IHTMLDocument2).body as IHTMLElement2);
268 if Scroll then begin
269 h := GetWindowHeight + 10;
270 w := ele.scrollWidth + 25
271 end else begin
272 h := GetWindowHeight + 5;
273 w := ele.scrollWidth + 10;
274 end;
275
276 DIV_X := GikoSys.Setting.RespopupDeltaX;
277 DIV_Y := GikoSys.Setting.RespopupDeltaY;
278
279 dx1 := 0; dx2 := 0;
280 dy1 := 0; dy2 := 0;
281
282 Result := Rect(0, 0, w, h);
283 case GikoSys.Setting.PopupPosition of
284 gppRightTop:
285 begin
286 dx1 := 0; dx2 := + DIV_X;
287 dy1 := -h; dy2 := - DIV_Y;
288 end;
289 gppRight:
290 begin
291 dx1 := 0; dx2 := + DIV_X;
292 dy1 := - (h div 2); dy2 := 0;
293 end;
294 gppRightBottom:
295 begin
296 dx1 := 0; dx2 := + DIV_X;
297 dy1 := 0; dy2 := + DIV_Y;
298 end;
299 gppTop:
300 begin
301 dx1 := - (w div 2); dx2 := 0;
302 dy1 := -h; dy2 := - DIV_Y;
303 end;
304 // 綮?罩 gppCenter: OffsetRect(Result, p.x - (w div 2), p.y - (h div 2));
305 gppBottom:
306 begin
307 dx1 := - (w div 2); dx2 := 0;
308 dy1 := 0; dy2 := + DIV_Y;
309 end;
310 gppLeftTop:
311 begin
312 dx1 := -w; dx2 := - DIV_X ;
313 dy1 := -h; dy2 := - DIV_Y;
314 end;
315 gppLeft:
316 begin
317 dx1 := -w; dx2 := - DIV_X;
318 dy1 := - (h div 2); dy2 := 0;
319 end;
320 gppLeftBottom:
321 begin
322 dx1 := -w; dx2 := - DIV_X;
323 dy1 := 0; dy2 := + DIV_Y;
324 end;
325 end;
326 // ????篏?臀???Щ??
327 OffsetRect(Result, p.x + dx1 + dx2, p.y + dy1 + dy2);
328
329 MaxWidth := WorkArea.Right - WorkArea.Left;
330 MaxHeight := WorkArea.Bottom - WorkArea.Top;
331 // 篁ヤ???????篏?臀????馹?????????????Щ??
332 if (Result.Left < WorkArea.Left) then begin
333 // ???泣?ゃ?????茖????????違???阪??篏?臀???窪?活拶??
334 if (p.X * 2 < MaxWidth) then begin
335 if ( (GikoSys.Setting.PopupPosition = gppTop) or
336 (GikoSys.Setting.PopupPosition = gppBottom)) then begin
337 OffsetRect(Result, -Result.Left, WorkArea.Left);
338 end else begin
339 OffsetRect(Result, - (dx1 + 2 * dx2), 0);
340 end;
341 end else begin
342 // ?脂?∝??障?х?脂?√???絨???????
343 Result := Rect(0, Result.Top,
344 Result.Right, Result.Bottom);
345 end;
346 end;
347 if (Result.Top < WorkArea.Top) then begin
348 // 綺??眼???茖????????違???阪??篏?臀????筝?荵∽?/span>
349 if (p.Y * 2 < MaxHeight) then begin
350 OffsetRect(Result, 0, - (dy1 + 2 * dy2));
351 end else begin
352 // ?脂?∝??障?х?脂?∫???絨???????
353 Result := Rect(Result.Left, WorkArea.Top,
354 Result.Right, Result.Bottom);
355 end;
356 end;
357 if (Result.Right > WorkArea.Right) then begin
358 // ???泣?ゃ?????茖????????違???阪??篏?臀???窪?活拶??
359 if (p.X * 2 > WorkArea.Right) then begin
360 if( (GikoSys.Setting.PopupPosition = gppTop) or
361 (GikoSys.Setting.PopupPosition = gppBottom)) then begin
362 OffsetRect(Result, -(Result.Right - WorkArea.Right), 0);
363 end else begin
364 OffsetRect(Result, -w - (dx1 + 2 * dx2), 0);
365 end;
366 // ???泣?ゃ???????若???若?????翫?????脂?∝??障?у???絨???????
367 if (Result.Left < WorkArea.Left) then begin
368 Result := Rect(WorkArea.Left, Result.Top,
369 Result.Right, Result.Bottom);
370 end;
371 end else begin
372 // ?脂?∝??障?х?脂?√???絨???????
373 Result := Rect(Result.Left, Result.Top,
374 WorkArea.Right, Result.Bottom);
375 end;
376 end;
377 if (Result.Bottom > WorkArea.Bottom) then begin
378 // 筝??眼???茖????????違???阪??篏?臀????筝?荵∽?/span>
379 if (p.Y * 2 > WorkArea.Bottom) then begin
380 OffsetRect(Result, 0, -h - (dy1 + 2 * dy2));
381 // 筝???黄?????翫??????
382 if (Result.Top < WorkArea.Top) then begin
383 Result := Rect(Result.Left, WorkArea.Top,
384 Result.Right, Result.Bottom);
385 end;
386 end else begin
387 // ?脂?∝??障?х?脂?∫???絨???????
388 Result := Rect(Result.Left, Result.Top,
389 Result.Right, WorkArea.Bottom);
390 end;
391 end;
392 end;
393 function TResPopupBrowser.GetWindowHeight : Integer;
394 var
395 top: Integer;
396 item: OleVariant;
397 begin
398 Result := 0;
399 //???????吟?????若?帥????粋昭?推賢????????粋昭?帥??緇???/span>
400 while (Self.ReadyState <> READYSTATE_COMPLETE) and
401 (Self.ReadyState <> READYSTATE_INTERACTIVE) do begin
402 Sleep(1);
403 Forms.Application.ProcessMessages;
404 end;
405
406 try
407 top := 0;
408 item := OleVariant( Self.Document as IHTMLDocument2)
409 .anchors.item(OleVariant('bottom'));
410 item.focus();
411 repeat
412 top := top + item.offsetTop;
413 item := item.offsetParent;
414 until AnsiCompareText(item.tagName, 'body' ) = 0;
415 Result := top;
416 except
417 end;
418 end;
419 function TResPopupBrowser.ResPopupBrowserClick(Sender: TObject): WordBool;
420 begin
421 // ???潟???????????若???鴻??絅??c???????с?????若?????∞??????菴???
422 Blur;
423 Result := True;
424 end;
425 function TResPopupBrowser.GetThread: TThreadItem;
426 begin
427 Result := nil;
428 if (FThread <> nil) then begin
429 try
430 // ?≦?鴻?????ゃ?潟?炊???/span>
431 if (FThread.ParentBoard <> nil) then begin
432 Result := FThread
433 end;
434 except
435 //?≦?鴻?????ゃ?潟?帥???c??
436 Result := nil;
437 end;
438 end;
439 end;
440 procedure TResPopupBrowser.Blur;
441 var
442 FOleInPlaceActiveObject: IOleInPlaceActiveObject;
443 begin
444 FOleInPlaceActiveObject := Self.ControlInterface as IOleInPlaceActiveObject;
445 FOleInPlaceActiveObject.OnFrameWindowActivate(False);
446 end;
447 function TResPopupBrowser.ResPopupBrowserDbClick(Sender: TObject): WordBool;
448 begin
449 // ???潟???????????若???鴻??絅??c???????с?????若?????∞??????菴???
450 Blur;
451 // ?????ц????????????????с???<???祉?若?悟??宴?ф???????????
452 PostMessage( GikoForm.Handle , USER_RESPOPUPCLEAR, Integer( Self ), 0 );
453 Result := True;
454 end;
455 initialization
456 OleInitialize(nil);
457
458 finalization
459 OleUninitialize;
460
461 end.

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