OSDN Git Service

スキンを使わなくても、レスアンカーをクリックするとそのレスに飛ぶようにした。
[gikonavigoeson/gikonavi.git] / Editor.pas
1 unit Editor;
2
3 interface
4
5 uses
6         Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
7         Dialogs, StdCtrls, ComCtrls, ExtCtrls, ToolWin, Menus, OleCtrls,
8 {$IF Defined(DELPRO) }
9         SHDocVw,
10 {$ELSE}
11         SHDocVw_TLB,
12 {$IFEND}
13         ActiveX, {HTTPApp,} YofUtils, Trip, IniFiles, StrUtils,
14         GikoSystem, GikoUtil, ImgList, Clipbrd, BoardGroup,
15         IdAntiFreezeBase,       IdAntiFreeze, IdBaseComponent, IdComponent,
16         IdTCPConnection, IdTCPClient, IdHTTP, ActnList, StdActns, IdIntercept,
17         IdLogBase, IdLogDebug, IdException, DateUtils;
18
19 type
20 //      TSetLayeredWindowAttributes = function(wnd: HWND; crKey: DWORD; bAlpha: BYTE; dwFlag: DWORD): Boolean; stdcall;
21         //\8f\91\82«\8d\9e\82Ý\96ß\82è\92l\83^\83C\83v
22         TGikoResultType = (grtOK, grtCookie, grtCheck, grtError);
23
24         TEditorForm = class(TForm)
25                 MainMenu: TMainMenu;
26                 FileMenu: TMenuItem;
27                 PostMessage: TMenuItem;
28                 SaveMessage: TMenuItem;
29                 CloseMenu: TMenuItem;
30                 N01: TMenuItem;
31                 StatusBar: TStatusBar;
32                 EditorPage: TPageControl;
33                 EditorTab: TTabSheet;
34                 PreviewTab: TTabSheet;
35                 Browser: TWebBrowser;
36                 EditMenu: TMenuItem;
37                 UndoMenu: TMenuItem;
38                 CutMenu: TMenuItem;
39                 CopyMenu: TMenuItem;
40                 PasteMenu: TMenuItem;
41                 N02: TMenuItem;
42                 ToolBarImageList: TImageList;
43                 HotToobarImageList: TImageList;
44                 BodyEdit: TMemo;
45                 NameBasePanel: TPanel;
46                 NameLabel: TLabel;
47                 MailLabel: TLabel;
48                 NameComboBox: TComboBox;
49                 MailComboBox: TComboBox;
50                 ToolBar: TToolBar;
51                 SendToolButton: TToolButton;
52                 OutBoxToolButton: TToolButton;
53                 ToolButton5: TToolButton;
54                 UndoToolButton: TToolButton;
55                 CutToolButton: TToolButton;
56                 CopyToolButton: TToolButton;
57                 PasteToolButton: TToolButton;
58                 ToolButton3: TToolButton;
59                 TransToolButton: TToolButton;
60                 TopToolButton: TToolButton;
61                 Indy: TIdHTTP;
62                 IdAntiFreeze: TIdAntiFreeze;
63                 ToolButton1: TToolButton;
64                 ToolButton2: TToolButton;
65                 ActionList: TActionList;
66                 SendAction: TAction;
67                 SaveAction: TAction;
68                 CloseAction: TAction;
69                 UndoAction: TAction;
70                 CutAction: TAction;
71                 CopyAction: TAction;
72                 PasteAction: TAction;
73                 AbortAction: TAction;
74                 TopAction: TAction;
75                 Show1: TMenuItem;
76                 T1: TMenuItem;
77                 N1: TMenuItem;
78                 S1: TMenuItem;
79                 SageCheckBox: TCheckBox;
80                 IdLogDebug: TIdLogDebug;
81                 TransAction: TAction;
82                 A1: TMenuItem;
83                 KotehanCheckBox: TCheckBox;
84                 TitlePanel: TPanel;
85                 Label1: TLabel;
86                 TitleEdit: TEdit;
87                 SelectAllAction: TAction;
88                 N2: TMenuItem;
89                 SelectAll1: TMenuItem;
90     Timer1: TTimer;
91                 procedure EditorPageChange(Sender: TObject);
92                 procedure FormCreate(Sender: TObject);
93                 procedure BrowserStatusTextChange(Sender: TObject;
94                         const Text: WideString);
95                 procedure FormClose(Sender: TObject; var Action: TCloseAction);
96                 procedure FormDestroy(Sender: TObject);
97                 procedure SendActionExecute(Sender: TObject);
98                 procedure SaveActionExecute(Sender: TObject);
99                 procedure AbortActionExecute(Sender: TObject);
100                 procedure CloseActionExecute(Sender: TObject);
101                 procedure UndoActionExecute(Sender: TObject);
102                 procedure CutActionExecute(Sender: TObject);
103                 procedure CopyActionExecute(Sender: TObject);
104                 procedure PasteActionExecute(Sender: TObject);
105                 procedure SendActionUpdate(Sender: TObject);
106                 procedure SaveActionUpdate(Sender: TObject);
107                 procedure CloseActionUpdate(Sender: TObject);
108                 procedure UndoActionUpdate(Sender: TObject);
109                 procedure CutActionUpdate(Sender: TObject);
110                 procedure CopyActionUpdate(Sender: TObject);
111                 procedure PasteActionUpdate(Sender: TObject);
112                 procedure TopActionExecute(Sender: TObject);
113                 procedure TopActionUpdate(Sender: TObject);
114                 procedure SageCheckBoxClick(Sender: TObject);
115                 procedure MailComboBoxChange(Sender: TObject);
116                 procedure TransActionExecute(Sender: TObject);
117                 procedure TransActionUpdate(Sender: TObject);
118                 procedure IdLogDebugReceive(ASender: TIdConnectionIntercept;
119                         AStream: TStream);
120                 procedure IdLogDebugSend(ASender: TIdConnectionIntercept;
121                         AStream: TStream);
122                 procedure SelectAllActionExecute(Sender: TObject);
123     procedure StatusBarResize(Sender: TObject);
124     procedure Timer1Timer(Sender: TObject);
125     procedure FormActivate(Sender: TObject);
126     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
127         private
128                 FThreadItem: TThreadItem;
129                 FBoard: TBoard;
130                 FNameComboEdit: THandle;
131                 FMailComboEdit: THandle;
132                 FAbort: Boolean;
133                 FWork: Boolean;
134                 FStatusCode: Integer;
135                 FDebugStrReceive: string;
136                 FDebugStrSend: string;
137         FSambaTime: TDateTime;
138         FHost: string;
139                 FNow: TDateTime;
140                 procedure Preview;
141                 function RepHtml(s: string): string;
142                 function Check: Boolean;
143                 procedure SetNameList(sName, sMail: string);
144 //              procedure Send(SendType: TGikoSendType; SPID: string; PON: string; FirstWriting: Boolean);
145                 procedure Send(SPID: string; PON: string; FirstWriting: Boolean);
146
147                 function GetActiveControlHandle: THandle;
148 //              function GetSendData: string;
149 //              procedure GetSendData(Source: TStringStream);
150                 procedure GetSendData(Source: TStringStream);
151                 procedure SaveSendFile;
152                 procedure SetContent(Content: string);
153                 function GetSPID(CookieLine: string): string;
154                 function GetPON(CookieLine: string): string;
155                 function GetResultType(ResponseText: string): TGikoResultType;
156         procedure ReadSambaTime(const AHost: string);
157         procedure WriteSambaTime(const AHost: string; ATime: TDateTime);
158         function ReadSettingTime(const AHost: string): Integer;
159         function CheckSambaTime(const AHost: string; ATime: TDateTime): Boolean;
160         procedure SetSamba24(AURL: string);
161         protected
162                 procedure CreateParams(var Params: TCreateParams); override;
163         public
164                 procedure SetFont;
165                 procedure SetThreadItem(Item: TThreadItem);
166                 procedure SetBoard(Item: TBoard);
167         end;
168
169 implementation
170
171 uses
172         Giko, ItemDownload;
173 const
174         CAPTION_NAME_NEW: string = '\83M\83R\83i\83\83X\83\8c\97§\82Ä\83G\83f\83B\83^';
175         CAPTION_NAME_RES: string = '\83M\83R\83i\83\83\8c\83X\83G\83f\83B\83^';
176
177     // \83G\83f\83B\83b\83g\83E\83B\83\93\83h\83E\82ð\89E\89º\82É\82¸\82ç\82µ\82Ä\8aJ\82­\88Ú\93®\97Ê
178     WINDOWMOVE_H = 30;
179     WINDOWMOVE_V = 30;
180
181         //DAX\82³\82ñ±Ø¶ÞÄ!(\81L\81¤\81M)
182         READCGI_ERR                     = '-ERR';
183         READCGI_INCR            = '-INCR';
184         READCGI_OK                      = '+OK';
185         READCGI_PARTIAL = '+PARTIAL';
186         READCGI_ERR_FOUND_KAKO  = '-ERR \89ß\8b\8e\83\8d\83O\91q\8cÉ\82Å\94­\8c©';
187         READCGI_ERR_NOT_HTML            = '-ERR html\89»\91Ò\82¿';
188         READCGI_ERR_NOT_FOUND           = '-ERR \82»\82ñ\82È\94Âor\83X\83\8c\83b\83h\82È\82¢\82Å\82·\81B';
189         READCGI_ERR_ABONE                               = '-ERR \82Ç\82±\82©\82Å\82 \82Ú\81[\82ñ\82ª\82 \82Á\82½\82Ý\82½\82¢\82Å\82·\81B';
190         READCGI_ERR_TIMEOUT                     = '-ERR \8ew\92è\8e\9e\8aÔ\82ª\89ß\82¬\82Ü\82µ\82½\81B';
191         READCGI_ERR_CANTUSE                     = '-ERR \82à\82¤\81@\82Â\82©\82¦\82Ü\82¹\82ñ';
192         RES2CH_TRUE                             = '<!-- 2ch_X:true -->';
193         RES2CH_FALSE                    = '<!-- 2ch_X:false -->';
194         RES2CH_ERROR                    = '<!-- 2ch_X:error -->';
195         RES2CH_CHECK                    = '<!-- 2ch_X:check -->';
196         RES2CH_COOKIE                   = '<!-- 2ch_X:cookie -->';
197
198
199 type
200         TSelection = record
201                 StartPos, EndPos: Integer;
202         end;
203
204 {$R *.DFM}
205
206 {constructor TEditorForm.Create(AOwner: TComponent; Item: TBoard);
207 begin
208         inherited Create(AOwner);
209 end;}
210
211 procedure TEditorForm.CreateParams(var Params: TCreateParams);
212 begin
213         inherited;
214         if FormStyle in [fsNormal, fsStayOnTop] then
215                 if BorderStyle in [bsSingle, bsSizeable] then begin
216                         Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
217                         Params.WndParent := 0;
218                 end;
219 end;
220
221 {procedure TEditorForm.CreateParams(var Params: TCreateParams);
222 begin
223         inherited CreateParams(Params);
224         Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
225 end;}
226
227 procedure TEditorForm.FormCreate(Sender: TObject);
228 var
229         wp: TWindowPlacement;
230                 hUser32 : HINST;
231 begin
232         FWork := False;
233         Browser.Navigate('about:blank');
234
235         FBoard := nil;
236         FThreadItem := nil;
237
238         //\83E\83B\83\93\83h\83E\82Ì\88Ê\92u\90Ý\92è
239 {       i := GikoSys.Setting.EditWindowLeft +
240                          GikoSys.Setting.EditWindowTop +
241                          GikoSys.Setting.EditWindowWidth +
242                          GikoSys.Setting.EditWindowHeight;
243         if i > 0 then begin
244                 SetBounds(GikoSys.Setting.EditWindowLeft, GikoSys.Setting.EditWindowTop,
245                                                         GikoSys.Setting.EditWindowWidth, GikoSys.Setting.EditWindowHeight);
246                 if GikoSys.Setting.EditWindowMax then
247                         WindowState := wsMaximized;
248         end;}
249
250         //\83E\83B\83\93\83h\83E\82Ì\88Ê\92u\90Ý\92è
251         wp.length := sizeof(wp);
252         wp.rcNormalPosition.Top := GikoSys.Setting.EditWindowTop;
253         wp.rcNormalPosition.Left := GikoSys.Setting.EditWindowLeft;
254
255         wp.rcNormalPosition.Bottom := GikoSys.Setting.EditWindowTop + GikoSys.Setting.EditWindowHeight;
256         wp.rcNormalPosition.Right := GikoSys.Setting.EditWindowLeft + GikoSys.Setting.EditWindowWidth;
257         wp.showCmd := SW_HIDE;
258         SetWindowPlacement(Handle, @wp);
259
260         if GikoSys.Setting.EditWindowMax then
261                 WindowState := wsMaximized;
262
263         //\83E\83B\83\93\83h\83E\82ª\89æ\96Ê\8aO\82È\82ç\89æ\96Ê\93à\82É\88Ú\93®\82·\82é
264         if (Left + Width) > Screen.Width then
265 //              Left := Screen.Width - Width;
266                 Left := 0;
267         if (Top + Height) > Screen.Height then
268 //              Top := Screen.Height - Height;
269                 Top := 0;
270         if Left < 0 then
271                 Left := 0;
272         if Top < 0 then
273                 Top := 0;
274
275     //\8c»\8dÝ\82Ì\83E\83B\83\93\83h\83E\82Ì\88Ê\92u\82ð\95Û\91
276     GikoSys.Setting.EditWindowTop := Top  + WINDOWMOVE_V;   // \8e\9f\82É\8aJ\82­\83E\83B\83\93\83h\83E\82Í
277     GikoSys.Setting.EditWindowLeft := Left + WINDOWMOVE_H;  // \81@\81@\81@\89E\8eÎ\82ß\89º\82É\82¸\82ç\82·
278     //\83E\83B\83\93\83h\83E\82Ì\95\9d\82Æ\8d\82\82³\82ª\8f¬\82³\82·\82¬\82¢\82ê\82Î\8c³\82É\96ß\82·
279         if GikoSys.Setting.EditWindowHeight < 144 then
280                 Height := 400;
281         if GikoSys.Setting.EditWindowWidth < 144 then
282                 Width := 640;
283
284         EditorPage.ActivePage := EditorTab;
285         FNameComboEdit := GetWindow(NameComboBox.Handle, GW_CHILD);
286         FMailComboEdit := GetWindow(MailComboBox.Handle, GW_CHILD);
287         NameComboBox.Items.Assign(GikoSys.Setting.NameList);
288         MailComboBox.Items.Assign(GikoSys.Setting.MailList);
289         SetFont;
290         hUser32 := LoadLibrary('User32.dll');
291         try
292                 if hUser32 <> 0 then
293                         TransAction.Enabled := true
294                 else
295                         TransAction.Enabled := false;
296         finally
297                 FreeLibrary(hUser32);
298         end;
299
300     // \83E\83B\83\93\83h\83E\82Ì\83X\83e\83C\8fó\91Ô
301         if GikoSys.Setting.EditWindowStay then begin    // \83X\83e\83C\8fó\91Ô
302         FormStyle := fsStayOnTop;
303         TopAction.Checked := true;
304         TopToolButton.Down := true;
305     end else begin                                  // \83X\83e\83C\82µ\82È\82¢
306         FormStyle := fsNormal;
307         TopAction.Checked := false;
308         TopToolButton.Down := false;
309     end;
310         // \83X\83e\83C\8fó\91Ô\82Ì\95Û\91
311         GikoSys.Setting.EditWindowStay := FormStyle = fsStayOnTop;
312
313     // \83E\83B\83\93\83h\83E\82Ì\94¼\93§\96¾\8fó\91Ô
314         if(GikoSys.Setting.EditWindowTranslucent) and (TransAction.Enabled) then begin // \94¼\93§\96¾\81i\83g\83\89\83\93\83X\83\8b\81[\83Z\83\93\83g\81j\8fó\91Ô
315         AlphaBlend := true;
316         TransAction.Checked := true;
317         TransToolButton.Down := true;
318     end else begin                                      // \95s\93§\96¾
319         AlphaBlend := false;
320         TransAction.Checked := false;
321         TransToolButton.Down := false;
322     end;
323         // \94¼\93§\96¾\8fó\91Ô\82Ì\95Û\91
324         GikoSys.Setting.EditWindowTranslucent := TransAction.Checked;
325 end;
326
327 procedure TEditorForm.SetBoard(Item: TBoard);
328 begin
329         FBoard := Item;
330         Caption := CAPTION_NAME_NEW + ' - [' + Item.Title + ']';
331         NameComboBox.Text := FBoard.KotehanName;
332         MailComboBox.Text := FBoard.KotehanMail;
333         SageCheckBox.Checked := AnsiPos('sage', MailComboBox.Text) <> 0;
334         TitlePanel.Visible := True;
335     SetSamba24('');
336 end;
337
338 procedure TEditorForm.SetThreadItem(Item: TThreadItem);
339 begin
340         FThreadItem := Item;
341         Caption := CAPTION_NAME_RES + ' - [' + FThreadItem.Title + ']';
342         NameComboBox.Text := FThreadItem.ParentBoard.KotehanName;
343         MailComboBox.Text := FThreadItem.ParentBoard.KotehanMail;
344         SageCheckBox.Checked := AnsiPos('sage', MailComboBox.Text) <> 0;
345         TitlePanel.Visible := False;
346     SetSamba24(FThreadItem.ParentBoard.URL);
347 end;
348
349 procedure TEditorForm.SetFont;
350 begin
351         BodyEdit.Font.Name := GikoSys.Setting.EditorFontName;
352         BodyEdit.Font.Size := GikoSys.Setting.EditorFontSize;
353         BodyEdit.Font.Color := GikoSys.Setting.EditorFontColor;
354         BodyEdit.Color := GikoSys.Setting.EditorBackColor;
355 end;
356
357 procedure TEditorForm.Preview;
358 var
359         Title: string;
360         No: string;
361         Mail: string;
362         Namae: string;
363         DateTime: string;
364         Body: string;
365         s: string;
366
367                                 posTrip : Integer;
368                                 tripOrigin : string;
369 begin
370         if FThreadItem = nil then begin
371                 No := '1';
372                 Title := RepHtml(TitleEdit.Text);
373         end else begin
374                 No := IntToStr(FThreadItem.Count + 1);
375                 Title := RepHtml(FThreadItem.Title);
376         end;
377
378         Namae := RepHtml(NameComboBox.Text);
379         Mail := RepHtml(MailComboBox.Text);
380         Body := RepHtml(BodyEdit.Text);
381         Body := StringReplace(Body, #13#10, '<br>', [rfReplaceAll]);
382         DateTime := FormatDateTime('yyyy/mm/dd(aaa) hh:nn', now);
383
384         if Trim(Namae) = '' then
385                 Namae := '\96¼\96³\82µ\82³\82ñ';
386
387         s := '<HTML><HEAD>' + #13#10
388                         + '<META http-equiv="Content-Type" content="text/html; charset=Shift_JIS">' + #13#10
389                         + '<TITLE>' + title + '</TITLE>' + #13#10
390 //                      + '<STYLE><!--BODY{font-size : 9pt;font-family : "\82l\82\82o\83S\83V\83b\83N";}--></STYLE>' + #13#10
391                         + '</HEAD>' + #13#10
392                         + '<BODY text="#000000" bgcolor="#EFEFEF" link="#0000FF" alink="#FF0000" vlink="#660099">' + #13#10
393                         + '<FONT COLOR="#FF0000">' + title + '</FONT>' + #13#10
394                         + '<DL>' + #13#10;
395                                 posTrip := AnsiPos( '#', Namae );
396                                 if posTrip > 0 then
397                                 begin
398                                                                 tripOrigin := Copy( Namae, posTrip + 1, Length( Namae ) );
399                                                                 Namae :=
400                                                                                                 Copy( Namae, 1, posTrip - 1 ) + '</B> \81\9f' +
401                                                                                                 get_2ch_trip( PChar( tripOrigin ) ) + '<B>';
402                                 end;
403         if Mail = '' then
404                 s := s + '<DT>' + No + ' \81F <FONT color="forestgreen"><B>' + Namae + '</B></FONT> \81F ' + DateTime+ '<BR><DD>' + Body + '<BR><BR><BR>' + #13#10
405         else
406                 s := s + '<DT>' + No + ' \81F <A href="mailto:' + Mail + '"><B>' + Namae + '</B></A> [' + Mail + ']\81F ' + DateTime+ '<BR><DD>' + Body + '<BR><BR><BR>' + #13#10;
407         s := s + '</BODY></HTML>';
408         SetContent(s);
409 end;
410
411 function TEditorForm.RepHtml(s: string): string;
412 begin
413 //      s := StringReplace(s, '&', '&amp;', [rfReplaceAll]);
414         s := StringReplace(s, '<', '&lt;', [rfReplaceAll]);
415         s := StringReplace(s, '>', '&gt;', [rfReplaceAll]);
416 //      s := StringReplace(s, ' ', '&nbsp;', [rfReplaceAll]);   //\8ed\97l\95Ï\8dX\82É\82æ\82è&nbsp;\8eg\97p\95s\89Â
417         s := StringReplace(s, '"', '&quot;', [rfReplaceAll]);
418         Result := s;
419 end;
420
421 procedure TEditorForm.EditorPageChange(Sender: TObject);
422 begin
423         if EditorPage.ActivePage = PreviewTab then begin
424                 Preview;
425         end else begin
426                 Browser.Navigate('about:blank');
427         end;
428 end;
429
430 procedure TEditorForm.BrowserStatusTextChange(Sender: TObject;
431         const Text: WideString);
432 begin
433         if EditorPage.ActivePage = PreviewTab then begin
434                 StatusBar.Panels[0].Text := Text;
435         end else begin
436                 StatusBar.Panels[0].Text := '';
437         end;
438 end;
439
440 function TEditorForm.Check: Boolean;
441 var
442         Msg: string;
443         rc: Integer;
444         Board: TBoard;
445 begin
446         Result := True;
447         if FThreadItem = nil then
448                 Board := FBoard
449         else
450                 Board := FThreadItem.ParentBoard;
451
452         if (not GikoSys.Setting.UseMachineTime) and
453                  ((Board.LastGetTime = 0) or
454                         (Board.LastGetTime = ZERO_DATE)) then begin
455                 Msg := '\83T\81[\83o\82Ì\8e\9e\8d\8f\82ª\95ª\82©\82ç\82È\82¢\82½\82ß\81A\91\97\90M\8fo\97\88\82Ü\82¹\82ñ'#13#10
456                                  + '\83X\83\8c\83b\83h\82ð\8dX\90V\81i\8eæ\93¾\81j\8cã\81A15\95b\91Ò\82Á\82Ä\82©\82ç\91\97\90M\82µ\82Ä\82­\82¾\82³\82¢';
457                 MsgBox(Handle, Msg, '\83G\83\89\81[', MB_OK or MB_ICONSTOP);
458                 Result := False;
459         end else if BodyEdit.Text = '' then begin
460                 Msg := '\96{\95\82ª\93ü\97Í\82³\82ê\82Ä\82¢\82Ü\82¹\82ñ\81B';
461                 MsgBox(Handle, Msg, '\83G\83\89\81[', MB_OK or MB_ICONSTOP);
462                 Result := False;
463         end else if (FBoard <> nil) and (Trim(TitleEdit.Text) = '') then begin
464                 Msg := '\83^\83C\83g\83\8b\82ª\93ü\97Í\82³\82ê\82Ä\82¢\82Ü\82¹\82ñ\81B';
465                 MsgBox(Handle, Msg, '\83G\83\89\81[', MB_OK or MB_ICONSTOP);
466                 Result := False;
467         end else begin
468                 if (not GikoSys.Dolib.Connected) and (AnsiPos('\81\9c', NameComboBox.Text) <> 0) then begin
469                         Msg := '\83\8d\83O\83C\83\93\82µ\82Ä\82¢\82È\82¢\82Ì\82Å\81\9c\82Ì\8b@\94\\82Í\97\98\97p\8fo\97\88\82Ü\82¹\82ñ\81B'#13#10
470                                          + '\82±\82Ì\82Ü\82Ü\91\97\90M\82µ\82Ä\82à\82æ\82ë\82µ\82¢\82Å\82·\82©\81H';
471                         rc := MsgBox(Handle, Msg, '\8am\94F', MB_YESNO or MB_ICONQUESTION);
472                         Result := (rc = IDYES);
473                 end;
474         end;
475 end;
476
477 procedure TEditorForm.FormClose(Sender: TObject; var Action: TCloseAction);
478 begin
479         Action := caFree;
480 end;
481
482 procedure TEditorForm.FormDestroy(Sender: TObject);
483 var
484         wp: TWindowPlacement;
485 begin
486         //\8dÅ\91å\89»\81E\83E\83B\83\93\83h\83E\88Ê\92u\95Û\91
487         wp.length := sizeof(wp);
488         GetWindowPlacement(Handle, @wp);
489
490         GikoSys.Setting.EditWindowTop := wp.rcNormalPosition.Top;
491         GikoSys.Setting.EditWindowLeft := wp.rcNormalPosition.Left;
492         GikoSys.Setting.EditWindowHeight := wp.rcNormalPosition.Bottom - wp.rcNormalPosition.Top;
493         GikoSys.Setting.EditWindowWidth := wp.rcNormalPosition.Right - wp.rcNormalPosition.Left;
494         GikoSys.Setting.EditWindowMax := WindowState = wsMaximized;
495         GikoSys.Setting.EditWindowStay := FormStyle = fsStayOnTop;      // \83X\83e\83C\8fó\91Ô\82Ì\95Û\91
496         GikoSys.Setting.EditWindowTranslucent := TransAction.Checked;   // \94¼\93§\96¾\8fó\91Ô\82Ì\95Û\91
497
498 end;
499
500 procedure TEditorForm.SetNameList(sName, sMail: string);
501 begin
502         if Trim(sName) <> '' then begin
503                 if GikoSys.Setting.NameList.IndexOf(sName) = -1 then
504                         GikoSys.Setting.NameList.Insert(0, sName);
505         end;
506         if Trim(sMail) <> '' then begin
507                 if GikoSys.Setting.MailList.IndexOf(sMail) = -1 then
508                         GikoSys.Setting.MailList.Insert(0, sMail);
509         end;
510 end;
511
512 function TEditorForm.GetActiveControlHandle: THandle;
513 begin
514         if EditorPage.ActivePage = EditorTab then begin
515                 if ActiveControl = NameComboBox then
516                         Result := FNameComboEdit
517                 else if ActiveControl = MailComboBox then
518                         Result := FMailComboEdit
519                 else if ActiveControl = BodyEdit then
520                         Result := BodyEdit.Handle
521                 else if ActiveControl = TitleEdit then
522                         Result := TitleEdit.Handle
523                 else
524                         Result := 0;
525         end else
526                 Result := 0;
527 end;
528
529 procedure TEditorForm.SetContent(Content: string);
530 var
531         doc : Variant;
532 begin
533         if Browser.Document <> nil then begin
534                 doc := Browser.Document;
535                 doc.Clear;
536                 doc.open;
537                 doc.charset := 'Shift_JIS';
538                 doc.Write(Content);
539                 doc.Close;
540         end;
541 end;
542
543 procedure TEditorForm.Send(SPID: string; PON: string; FirstWriting: Boolean);
544 var
545         TextStream: TStringStream;
546         Source: TStringStream;
547         ResponseText: string;
548         URL: string;
549         RefURL: string;
550         State: TGikoDownloadState;
551         ResultType: TGikoResultType;
552         MsgResult: Integer;
553         Cookie: string;
554         Board: TBoard;
555         sysMenu : HMENU;
556 begin
557         FAbort := False;
558         State := gdsError;
559         if FThreadItem = nil then
560                 Board := FBoard
561         else
562                 Board := FThreadItem.ParentBoard;
563
564         Indy.Request.Clear;
565         Indy.ProxyParams.BasicAuthentication := False;
566         if GikoSys.Setting.WriteProxy then begin
567                 Indy.ProxyParams.ProxyServer := GikoSys.Setting.WriteProxyAddress;
568                 Indy.ProxyParams.ProxyPort := GikoSys.Setting.WriteProxyPort;
569                 Indy.ProxyParams.ProxyUsername := GikoSys.Setting.WriteProxyUserID;
570                 Indy.ProxyParams.ProxyPassword := GikoSys.Setting.WriteProxyPassword;
571                 if GikoSys.Setting.ReadProxyUserID <> '' then
572                         Indy.ProxyParams.BasicAuthentication := True;
573         end else begin
574                 Indy.ProxyParams.ProxyServer := '';
575                 Indy.ProxyParams.ProxyPort := 80;
576                 Indy.ProxyParams.ProxyUsername := '';
577                 Indy.ProxyParams.ProxyPassword := '';
578         end;
579         if FThreadItem = nil then begin
580                 URL := FBoard.GetSendURL;
581                 RefURL := GikoSys.UrlToServer(FBoard.URL) + 'test/bbs.cgi';
582         end else begin
583                 URL := FThreadItem.GetSendURL;
584                 RefURL := FThreadItem.URL;
585         end;
586         Indy.Request.UserAgent := GikoSys.GetUserAgent;
587         Indy.Request.Referer := RefURL;
588         Indy.Request.AcceptEncoding := '';
589
590         Cookie := '';
591         if SPID <> '' then
592                 Cookie := Cookie + 'SPID=' + SPID + '; ';
593         if PON <> '' then
594                 Cookie := Cookie + 'PON=' + PON + '; ';
595         Cookie := 'Cookie: ' + Cookie + 'NAME=' + NameComboBox.Text + '; MAIL=' + MailComboBox.Text;
596
597         sysMenu := GetSystemMenu( Handle, false );
598         EnableMenuItem( sysMenu, SC_CLOSE, MF_GRAYED );
599 {
600   EnableMenuItem(SysMenu, SC_CLOSE, MF_BYCOMMAND or MF_ENABLED);
601   DrawMenuBar(Handle);
602 }
603         Indy.Request.CustomHeaders.Clear;
604 //      Indy.Request.CacheControl := 'no-cache';
605         Indy.Request.CustomHeaders.Add('Pragma: no-cache');
606         Indy.Request.AcceptLanguage := 'ja';
607         Indy.Request.Accept := 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*';
608         Indy.Request.ContentType := 'application/x-www-form-urlencoded';
609         Indy.Request.CustomHeaders.Add(Cookie);
610         TextStream := TStringStream.Create('');
611         Source := TStringStream.Create('');
612         try
613                 try
614                         FDebugStrReceive := '';
615                         FDebugStrSend := '';
616                         GetSendData(Source);
617                         Indy.Post(URL, Source, TextStream);
618                         ResponseText := TextStream.DataString;
619
620                         ResultType := GetResultType(ResponseText);
621
622                         if ResultType = grtOK then begin
623                 WriteSambaTime(FHost, Now());
624                                 State := gdsComplete;
625                         end else if ResultType = grtCookie then begin
626                                 //\83\8b\81[\83v\96h\8e~
627                                 if not FirstWriting then
628                                         raise Exception.Create('');
629                                 MsgResult := MsgBox(
630                                         Handle,
631                                         '\81E\93\8a\8de\82³\82ê\82½\93à\97e\82Í\83R\83s\81[\81A\95Û\91\81A\88ø\97p\81A\93]\8dÚ\93\99\82³\82ê\82é\8fê\8d\87\82ª\82 \82è\82Ü\82·\81B' + #13#10 +
632                                         '\81E\93\8a\8de\82É\8aÖ\82µ\82Ä\94­\90\82·\82é\90Ó\94C\82Í\91S\82Ä\93\8a\8de\8eÒ\82É\8bA\82µ\82Ü\82·\81B' + #13#10#13#10 +
633                                         '\91S\90Ó\94C\82ð\95\89\82¤\82±\82Æ\82ð\8f³\91ø\82µ\82Ä\8f\91\82«\8d\9e\82Ý\82Ü\82·\82©\81H',
634                                         '\8fî\95ñ',
635                                         MB_YESNO or MB_ICONQUESTION);
636                                 if MsgResult = IDYES then begin
637                                         Board.SPID := GetSPID(Indy.Response.RawHeaders.Values['Set-Cookie']);
638                                         Board.PON := GetPON(Indy.Response.RawHeaders.Values['Set-Cookie']);
639                                         if (Board.SPID = '') and (Board.PON = '') then
640                                                 raise Exception.Create('');
641                                         //\82à\82¤\88ê\89ñ\82±\82Ì\83\81\83\\83b\83h
642                                         Send(Board.SPID, Board.PON, False);
643                                         Exit;
644                                 end else begin
645                                         Board.SPID := '';
646                                         Board.PON := '';
647                                         FWork := false;
648                                         EnableMenuItem(SysMenu, SC_CLOSE, MF_BYCOMMAND or MF_ENABLED);
649                                         DrawMenuBar(Handle);
650                                         Exit;
651                                 end;
652                         end else if ResultType = grtCheck then begin
653                                 //
654                                 //\83\8b\81[\83v\96h\8e~
655                                 if not FirstWriting then
656                                         raise Exception.Create('');
657
658                                 MsgResult := MsgBox(
659                                         Handle,
660                                         '\8f\91\82«\8d\9e\82Ý\82É\8aÖ\82µ\82Ä\82Í\97l\81X\82È\83\8d\83O\8fî\95ñ\82ª\8bL\98^\82³\82ê\82Ä\82¢\82Ü\82·\81B' + #13#10 +
661                                         '\93\8a\8de\82É\8aÖ\82µ\82Ä\94­\90\82·\82é\90Ó\94C\82Í\91S\82Ä\93\8a\8de\8eÒ\82É\8bA\82µ\82Ü\82·\81B' + #13#10 +
662                                         '\8cö\8f\98\97Ç\91­\82É\94½\82µ\82½\82è\81A\91¼\90l\82É\96À\98f\82ð\82©\82¯\82é\8f\91\82«\8d\9e\82Ý\82Í\8dT\82¦\82Ä\89º\82³\82¢\81B' + #13#10 +
663                                         '\93\8a\8de\82³\82ê\82½\93à\97e\82Í\83R\83s\81[\81E\95Û\91\81E\88ø\97p\81E\93]\8dÚ\93\99\82³\82ê\82é\8fê\8d\87\82ª\82 \82è\82Ü\82·\81B' + #13#10 +
664                                         #13#10 +
665                                         '\91S\90Ó\94C\82ð\95\89\82¤\82±\82Æ\82ð\8f³\91ø\82µ\82Ä\8f\91\82«\8d\9e\82Ý\82Ü\82·\82©\81H',
666                                         '\8am\94F',
667                                         MB_YESNO or MB_ICONQUESTION);
668
669                                 if MsgResult = IDYES then begin
670                                         Board.SPID := GetSPID(Indy.Response.RawHeaders.Values['Set-Cookie']);
671                                         Board.PON := GetPON(Indy.Response.RawHeaders.Values['Set-Cookie']);
672                                         if (Board.SPID = '') and (Board.PON = '') then
673                                                 raise Exception.Create('');
674                                         Send(Board.SPID, Board.PON, False);
675                                         Exit;
676                                 end else begin
677                                         EnableMenuItem(SysMenu, SC_CLOSE, MF_BYCOMMAND or MF_ENABLED);
678                                         DrawMenuBar(Handle);
679                                         Board.SPID := '';
680                                         Board.PON := '';
681                                         FWork := false;
682                                         Exit;
683                                 end;
684                         end else begin
685                 WriteSambaTime(FHost, Now());
686                                 State := gdsError;
687                                 raise Exception.Create('');
688                         end;
689                 except
690                         on E: EIdConnectException do begin
691                                 State := gdsError;
692                                 ResponseText := '<html><body>'
693                                                                                         + '<div>\90Ú\91±\82ª\8e¸\94s\82µ\82Ü\82µ\82½<br>'
694                                                                                         + '\89ñ\90ü\82â\83v\83\8d\83L\83V\82Ì\8fó\91Ô\82ð\92²\82×\82Ä\82­\82¾\82³\82¢<br></div>'
695                                                                                         + '<br><br><div>' + E.Message + '</div>'
696                                                                                         + '</body></html>';
697                         end;
698                         on E: Exception do begin
699                                 State := gdsError;
700
701                                 FDebugStrReceive := AnsiReplaceText(FDebugStrReceive, '<', '&lt;');
702                                 FDebugStrReceive := AnsiReplaceText(FDebugStrReceive, '>', '&gt;');
703                                 FDebugStrSend := AnsiReplaceText(FDebugStrSend, '<', '&lt;');
704                                 FDebugStrSend := AnsiReplaceText(FDebugStrSend, '>', '&gt;');
705
706                                 ResponseText := '<html><body>' + TextStream.DataString;
707                                 ResponseText := AnsiReplaceText(ResponseText, '</body>', '');
708                                 ResponseText := AnsiReplaceText(ResponseText, '</html>', '');
709                                 ResponseText := ResponseText + '<hr><div align="left"><pre>';
710                                 ResponseText := ResponseText + '<b>\82±\82±\82©\82ç\83M\83R\83i\83r\82Ì\8fî\95ñ</b>'#13#10;
711                                 ResponseText := ResponseText + #13#10'\81\9c\91\97\90M'#13#10;
712                                 ResponseText := ResponseText + FDebugStrSend;
713                                 ResponseText := ResponseText + #13#10'\81\9c\8eó\90M'#13#10;
714                                 ResponseText := ResponseText + FDebugStrReceive;
715                                 ResponseText := ResponseText + '</pre></div></body></html>';
716                         end;
717                 end;
718                 FStatusCode := Indy.ResponseCode;
719                 if FAbort then
720                         State := gdsAbort;
721         finally
722                 Source.Free;
723                 TextStream.Free;
724                 //sysMenu := GetSystemMenu( Handle, true );
725                 EnableMenuItem(SysMenu, SC_CLOSE, MF_BYCOMMAND or MF_ENABLED);
726                 DrawMenuBar(Handle);
727         end;
728         FWork := false;
729         if State = gdsComplete then begin
730                 GikoForm.PlaySound('ResEnd');
731                 SaveSendFile;
732                 if FThreadItem = nil then
733                         GikoForm.AddMessageList(FBoard.Title + ' [\90V\83X\83\8c\91\97\90M\8fI\97¹]', nil, gmiOK)
734                 else
735                         GikoForm.AddMessageList(FThreadItem.Title + ' [\83\8c\83X\91\97\90M\8fI\97¹]', nil, gmiOK);
736                 Close;
737         end else if State = gdsError then begin
738                 if FThreadItem = nil then
739                         GikoForm.AddMessageList(FBoard.Title + ' [\90V\83X\83\8c\91\97\90M\8e¸\94s]', nil, gmiNG)
740                 else
741                         GikoForm.AddMessageList(FThreadItem.Title + ' [\83\8c\83X\91\97\90M\8e¸\94s]', nil, gmiNG);
742                 EditorPage.ActivePage := PreviewTab;
743                 SetContent(ResponseText);
744         end else if State = gdsAbort then begin
745                 GikoForm.AddMessageList(FThreadItem.Title + ' [\92\86\92f]', nil, gmiSAD);
746         end;
747 end;
748
749 function TEditorForm.GetResultType(ResponseText: string): TGikoResultType;
750 begin
751         if AnsiPos('\8f\91\82«\82±\82Ý\82ª\8fI\82í\82è\82Ü\82µ\82½', ResponseText) <> 0 then
752                 Result := grtOK
753         else if (AnsiPos('\83N\83b\83L\81[\82ª\82È\82¢\82©\8aú\8cÀ\90Ø\82ê\82Å\82·', ResponseText) > 0) or
754                                         (AnsiPos('<title>\83N\83b\83L\81[\8am\94F\81I</title>', ResponseText) > 0)    or
755                                         (AnsiPos('<title>\81¡\83N\83b\83L\81[\8am\94F\81I\81¡</title>', ResponseText) > 0)        or
756                                         //(AnsiPos('\83N\83b\83L\81[\8am\94F', ResponseText) > 0) or
757                                         (AnsiPos(RES2CH_COOKIE, ResponseText) > 0)      then
758                 Result := grtCookie
759         else if (AnsiPos('<font size=+2 color=#FF0000>\8f\91\82«\8d\9e\82Ý\83`\83F\83b\83N\81I </font>', ResponseText) > 0)   or
760                                         (AnsiPos('<title>\81¡ \8f\91\82«\8d\9e\82Ý\8am\94F\82µ\82Ü\82· \81¡</title>', ResponseText) > 0)  or
761                                         (AnsiPos('<title>\93\8a\8de\8am\94F</title>', ResponseText) > 0)  or
762                                         (AnsiPos('<b>\8f\91\82«\82±\82Ý\8am\94F</b>', ResponseText) > 0)      or
763                                         (AnsiPos('="../test/subbbs.cgi">', ResponseText) > 0)   or
764                                         (AnsiPos(RES2CH_FALSE, ResponseText) > 0)       then
765                 Result := grtCheck
766         else
767                 Result := grtError;
768 end;
769
770
771 procedure TEditorForm.GetSendData(Source: TStringStream);
772 var
773         SessionID: string;
774         s: string;
775         SendTime: Integer;
776         Adjust: Integer;
777         Board: TBoard;
778 begin
779         if FThreadItem = nil then
780                 Board := FBoard
781         else
782                 Board := FThreadItem.ParentBoard;
783
784         if GikoSys.Setting.UseMachineTime then begin
785                 if GikoSys.Setting.TimeAdjust then
786                         Adjust := Gikosys.Setting.TimeAdjustSec
787                 else
788                         Adjust := GikoSys.Setting.TimeAdjustSec * -1;
789                 SendTime := GikoSys.DateTimeToInt(Now) - (9 * 60 * 60) + Adjust
790         end else begin
791                 if (Board.LastGetTime = 0) or (Board.LastGetTime = ZERO_DATE) then
792                         SendTime := GikoSys.DateTimeToInt(Now)
793                 else
794                         SendTime := GikoSys.DateTimeToInt(Board.LastGetTime);
795         end;
796         SessionID := GikoSys.Dolib.SessionID;
797         if SessionID <> '' then
798                 s := 'sid=' + HttpEncode(SessionID) + '&'
799         else
800                 s := '';
801         s := s + 'subject=&'
802                                  + 'FROM=' + HttpEncode(NameComboBox.Text) + '&'
803                                  + 'mail=' + HttpEncode(MailComboBox.Text) + '&'
804                                  + 'MESSAGE=' + HttpEncode(BodyEdit.Text) + '&'
805                                  + 'bbs=' + Board.BBSID + '&'
806                                  + 'time=' + IntToStr(SendTime) + '&';
807         if FThreadItem = nil then begin
808                 s := s + 'subject=' + HttpEncode(TitleEdit.Text) + '&';
809                 s := s + 'submit=' + HttpEncode('\91S\90Ó\94C\82ð\95\89\82¤\82±\82Æ\82ð\8f³\91ø\82µ\82Ä\8f\91\82«\8d\9e\82Þ') + #13#10;
810         end else begin
811                 s := s + 'key=' + ChangeFileExt(FThreadItem.FileName, '') + '&';
812                 s := s + 'submit=' + HttpEncode('\8f\91\82«\8d\9e\82Þ') + #13#10;
813         end;
814         Source.WriteString(s);
815 end;
816
817 procedure TEditorForm.SaveSendFile;
818 var
819         sDate: string;
820         ini: TMemIniFile;
821 begin
822         ini := TMemIniFile.Create(GikoSys.GetSentFileName);
823         try
824                 sDate := IntToStr(GikoSys.DateTimeToInt(Now));
825
826                 ini.WriteString(sDate, 'Name', NameComboBox.Text);
827                 ini.WriteString(sDate, 'EMail', MailComboBox.Text);
828                 ini.WriteString(sDate, 'Body', HttpEncode(BodyEdit.Text));
829                 ini.WriteInteger(sDate, 'Status', FStatusCode);
830                 ini.WriteDateTime(sDate, 'Date', Now);
831                 if FThreadItem = nil then begin
832                         ini.WriteString(sDate, 'Title', TitleEdit.Text);
833                         ini.WriteString(sDate, 'BBS', FBoard.BBSID);
834                         ini.WriteInteger(sDate, 'NewThread', 1);
835                 end else begin
836                         ini.WriteString(sDate, 'Title', FThreadItem.Title);
837                         ini.WriteString(sDate, 'BBS', FThreadItem.ParentBoard.BBSID);
838                         ini.WriteString(sDate, 'Key', ChangeFileExt(FThreadItem.FileName, ''));
839                 end;
840
841                 ini.UpdateFile;
842         finally
843                 ini.Free;
844         end;
845 end;
846
847 procedure TEditorForm.SendActionExecute(Sender: TObject);
848 var
849         Board: TBoard;
850         rc: Integer;
851         state : TGikoDownloadState;
852 begin
853         if FWork then
854                 Exit;
855         try
856                 FWork := True;
857                 SendAction.Enabled := False;
858                 Application.ProcessMessages;
859                 if not Check then Exit;
860
861                 if FThreadItem = nil then
862                         Board := FBoard
863                 else
864                         Board := FThreadItem.ParentBoard;
865
866                 if FThreadItem = nil then begin
867                         rc := GikoUtil.MsgBox(Handle,
868                                                                                                         '\81u' + Board.Title + '\81v\94Â\82É\90V\82µ\82¢\83X\83\8c\83b\83h\97§\82Ä\82Ü\82·'#13#10#13#10
869                                                                                                         + '\81E\94Â\82Ì\83\8b\81[\83\8b\82ð\8eç\82Á\82½\8f\91\82«\8d\9e\82Ý\82Å\82 \82é\82±\82Æ\82ð\8am\94F\82µ\82Ü\82µ\82½\82©\81H'#13#10
870                                                                                                         + '\81E\91¼\82É\93¯\82\82æ\82¤\82È\83X\83\8c\83b\83h\82ª\96³\82©\82Á\82½\82±\82Æ\82ð\8am\94F\82µ\82Ü\82µ\82½\82©\81H'#13#10#13#10
871                                                                                                         + '\81u\82Í\82¢\81v\82ð\89\9f\82·\82Æ\91\97\90M\82µ\82Ü\82·',
872                                                                                                         '\8am\94F',
873                                                                                                         MB_ICONQUESTION or MB_YESNO);
874                         if rc <> ID_YES then
875                                 Exit;
876                 end;
877
878                 SetNameList(NameComboBox.Text, MailComboBox.Text);
879                 if KotehanCheckBox.Checked then begin
880                         Board.KotehanName := NameComboBox.Text;
881                         Board.KotehanMail := MailComboBox.Text;
882                 end;
883
884                 if Board.IsBoardPlugInAvailable then begin
885                         if FThreadItem = nil then begin
886                                 // \83X\83\8c\97§\82Ä
887                                 state := TGikoDownloadState( Board.BoardPlugIn.CreateThread(
888                                         DWORD( Board ), TitleEdit.Text, NameComboBox.Text, MailComboBox.Text, BodyEdit.Text ) );
889
890                                 if state = gdsComplete then begin
891                                         GikoForm.PlaySound('ResEnd');
892                                         SaveSendFile;
893                                         GikoForm.AddMessageList(FBoard.Title + ' [\90V\83X\83\8c\91\97\90M\8fI\97¹]', nil, gmiOK);
894                                         FWork := False;
895                                         Close;
896                                 end else if State = gdsError then begin
897                                         GikoForm.AddMessageList(FBoard.Title + ' [\90V\83X\83\8c\91\97\90M\8e¸\94s]', nil, gmiNG);
898                                 end else if State = gdsAbort then begin
899                                         GikoForm.AddMessageList(FThreadItem.Title + ' [\92\86\92f]', nil, gmiSAD);
900                                 end;
901                         end else begin
902                                 // \83\8c\83X
903                                 state := TGikoDownloadState( FThreadItem.BoardPlugIn.WriteThread(
904                                         DWORD( FThreadItem ), NameComboBox.Text, MailComboBox.Text, BodyEdit.Text ) );
905
906                                 if state = gdsComplete then begin
907                                         GikoForm.PlaySound('ResEnd');
908                                         SaveSendFile;
909                                         GikoForm.AddMessageList(FThreadItem.Title + ' [\83\8c\83X\91\97\90M\8fI\97¹]', nil, gmiOK);
910                     FWork := False;
911                                         Close;
912                                 end else if State = gdsError then begin
913                                         GikoForm.AddMessageList(FThreadItem.Title + ' [\83\8c\83X\91\97\90M\8e¸\94s]', nil, gmiNG);
914                                 end else if State = gdsAbort then begin
915                                         GikoForm.AddMessageList(FThreadItem.Title + ' [\92\86\92f]', nil, gmiSAD);
916                                 end;
917                         end;
918                 end else begin
919                         if not Timer1.Enabled then
920                                 Send(Board.SPID, Board.PON, True)
921                         else begin
922                                 if not CheckSambaTime(FHost, Now()) then begin
923                                         rc := GikoUtil.MsgBox(Handle,
924                                                                 'Samba24\82Ì\8bK\92è\92l\96¢\96\9e\82Ì\95b\90\94\82µ\82©\8co\89ß\82µ\82Ä\82¢\82Ü\82¹\82ñ\81B'#13#10
925                                                                 + '\91\97\90M\82ð\92\86\8e~\82µ\82Ü\82·\82©\81H' + #13#10
926                                                                 + '(\81u\82¢\82¢\82¦\81v\82¾\82Æ\91\97\90M\82µ\82Ü\82·)', 'Samba24\8cx\8d\90',
927                                                                 MB_YESNO or MB_ICONQUESTION);
928                                         if rc = IDYES then begin
929                                                 FWork := false;
930                                                 Exit;
931                                         end;
932                                 end;
933                                 Send(Board.SPID, Board.PON, True);
934                         end;
935                 end;
936         finally
937                 FWork := False;
938                 if Timer1.Enabled then
939                         ReadSambaTime(FHost);
940         end;
941 end;
942
943 procedure TEditorForm.SaveActionExecute(Sender: TObject);
944 begin
945 //
946 end;
947
948 procedure TEditorForm.CloseActionExecute(Sender: TObject);
949 begin
950         Close;
951 end;
952
953 procedure TEditorForm.UndoActionExecute(Sender: TObject);
954 begin
955         SendMessage(GetActiveControlHandle, WM_UNDO, 0, 0);
956 end;
957
958 procedure TEditorForm.CutActionExecute(Sender: TObject);
959 begin
960         SendMessage(GetActiveControlHandle, WM_CUT, 0, 0);
961 end;
962
963 procedure TEditorForm.CopyActionExecute(Sender: TObject);
964 begin
965         SendMessage(GetActiveControlHandle, WM_COPY, 0, 0);
966 end;
967
968 procedure TEditorForm.PasteActionExecute(Sender: TObject);
969 begin
970         SendMessage(GetActiveControlHandle, WM_PASTE, 0, 0);
971 end;
972
973 procedure TEditorForm.SelectAllActionExecute(Sender: TObject);
974 begin
975         SendMessage(GetActiveControlHandle, EM_SETSEL, 0, GetWindowTextLength(GetActiveControlHandle));
976 end;
977
978 procedure TEditorForm.TopActionExecute(Sender: TObject);     // \83E\83B\83\93\83h\83E\8dÅ\91O\96Ê(Stay)\83{\83^\83\93\82Ì\8f\88\97\9d
979 begin
980         if not (fsShowing in Self.FormState) then begin
981                 if TopAction.Checked then begin // \83X\83e\83C\8fó\91Ô\82É\90Ý\92è
982                         SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE);
983                 end     else begin   // \83X\83e\83C\8fó\91Ô\89ð\8f\9c
984                         SetWindowPos(Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE);
985                 end;
986                 // \83X\83e\83C\8fó\91Ô\82Ì\95Û\91
987                 GikoSys.Setting.EditWindowStay := FormStyle = fsStayOnTop;
988         end;
989 end;
990
991 procedure TEditorForm.AbortActionExecute(Sender: TObject);
992 begin
993         FAbort := True;
994 end;
995
996 procedure TEditorForm.SendActionUpdate(Sender: TObject);
997 begin
998         SendAction.Enabled := not FWork;
999 end;
1000
1001 procedure TEditorForm.SaveActionUpdate(Sender: TObject);
1002 begin
1003         SaveAction.Enabled := False;
1004 end;
1005
1006 procedure TEditorForm.CloseActionUpdate(Sender: TObject);
1007 begin
1008         CloseAction.Enabled := not FWork;
1009 end;
1010
1011 procedure TEditorForm.UndoActionUpdate(Sender: TObject);
1012 begin
1013         UndoAction.Enabled := (GetActiveControlHandle <> 0)
1014                                                                                                 and (SendMessage(GetActiveControlHandle, EM_CANUNDO, 0, 0) <> 0)
1015                                                                                                 and (not FWork);
1016 end;
1017
1018 procedure TEditorForm.CutActionUpdate(Sender: TObject);
1019 var
1020         Selection: TSelection;
1021         AHandle: THandle;
1022 begin
1023         AHandle := GetActiveControlHandle;
1024         SendMessage(AHandle, EM_GETSEL, Longint(@Selection.StartPos), Longint(@Selection.EndPos));
1025         CutAction.Enabled := (AHandle <> 0)
1026                                                                                 and ((Selection.EndPos - Selection.StartPos) <> 0)
1027                                                                                 and (not FWork);
1028 end;
1029
1030 procedure TEditorForm.CopyActionUpdate(Sender: TObject);
1031 var
1032         Selection: TSelection;
1033         AHandle: THandle;
1034 begin
1035         AHandle := GetActiveControlHandle;
1036         SendMessage(AHandle, EM_GETSEL, Longint(@Selection.StartPos), Longint(@Selection.EndPos));
1037         CopyAction.Enabled := (AHandle <> 0)
1038                                                                                 and ((Selection.EndPos - Selection.StartPos) <> 0)
1039                                                                                 and (not FWork);
1040 end;
1041
1042 procedure TEditorForm.PasteActionUpdate(Sender: TObject);
1043 begin
1044         PasteAction.Enabled := (GetActiveControlHandle <> 0)
1045                                                                                         and (Clipboard.HasFormat(CF_TEXT))
1046                                                                                         and (not FWork);
1047 end;
1048
1049 procedure TEditorForm.TopActionUpdate(Sender: TObject);
1050 begin
1051         TopAction.Enabled := not FWork;
1052 end;
1053
1054 procedure TEditorForm.SageCheckBoxClick(Sender: TObject);
1055 begin
1056         if SageCheckBox.Checked then begin
1057                 if AnsiPos('sage', MailComboBox.Text) = 0 then
1058                         MailComboBox.Text := 'sage' + MailComboBox.Text;
1059         end else begin
1060                 if AnsiPos('sage', MailComboBox.Text) <> 0 then
1061                         MailComboBox.Text := StringReplace(MailComboBox.Text, 'sage', '', [rfReplaceAll]);
1062         end;
1063 end;
1064
1065 procedure TEditorForm.MailComboBoxChange(Sender: TObject);
1066 begin
1067         if AnsiPos('sage', MailComboBox.Text) = 0 then
1068                 SageCheckBox.Checked := False
1069         else
1070                 SageCheckBox.Checked := True;
1071 end;
1072
1073
1074 function TEditorForm.GetSPID(CookieLine: string): string;
1075 var
1076         s: string;
1077         i: Integer;
1078 begin
1079         Result := '';
1080         i := 0;
1081         while True do begin
1082                 s := Trim(GikoSys.GetTokenIndex(CookieLine, ';', i));
1083                 if s = '' then
1084                         Break
1085                 else begin
1086                         if Pos('SPID=', s) = 1 then begin
1087                                 Result := Trim(Copy(s, 6, Length(s)));
1088                                 Break;
1089                         end;
1090                 end;
1091                 inc(i);
1092         end;
1093 end;
1094
1095 function TEditorForm.GetPON(CookieLine: string): string;
1096 var
1097         s: string;
1098         i: Integer;
1099 begin
1100         Result := '';
1101         i := 0;
1102         while True do begin
1103                 s := Trim(GikoSys.GetTokenIndex(CookieLine, ';', i));
1104                 if s = '' then
1105                         Break
1106                 else begin
1107                         if Pos('PON=', s) = 1 then begin
1108                                 Result := Trim(Copy(s, 5, Length(s)));
1109                                 Break;
1110                         end;
1111                 end;
1112                 inc(i);
1113         end;
1114 end;
1115
1116 procedure TEditorForm.IdLogDebugReceive(ASender: TIdConnectionIntercept;
1117         AStream: TStream);
1118 var
1119         StringStream: TStringStream;
1120 begin
1121         StringStream := TStringStream.Create('');
1122         try
1123                 StringStream.CopyFrom(AStream, AStream.Size);
1124                 FDebugStrReceive := FDebugStrReceive + StringStream.DataString;
1125         finally
1126                 StringStream.Free;
1127         end;
1128 end;
1129
1130 procedure TEditorForm.IdLogDebugSend(ASender: TIdConnectionIntercept;
1131         AStream: TStream);
1132 var
1133         StringStream: TStringStream;
1134 begin
1135         StringStream := TStringStream.Create('');
1136         try
1137                 StringStream.CopyFrom(AStream, AStream.Size);
1138                 FDebugStrSend := FDebugStrSend + StringStream.DataString;
1139         finally
1140                 StringStream.Free;
1141         end;
1142 end;
1143
1144 procedure TEditorForm.TransActionExecute(Sender: TObject);
1145 begin
1146         AlphaBlend := TransAction.Checked;
1147         // \94¼\93§\96¾\8fó\91Ô\82Ì\95Û\91
1148         GikoSys.Setting.EditWindowTranslucent := TransAction.Checked;
1149 end;
1150
1151 procedure TEditorForm.TransActionUpdate(Sender: TObject);
1152 begin
1153         TransAction.Enabled := not FWork;
1154 end;
1155 //StatusBar\82ÌPanels[0]\82Ì\95\9d\82ð\89Â\95Ï\81B\8ec\82è\82ð\8cÅ\92è\82É\82·\82é
1156 procedure TEditorForm.StatusBarResize(Sender: TObject);
1157 begin
1158         StatusBar.Panels[0].Width := StatusBar.Width
1159                                                                         - StatusBar.Panels[1].Width - StatusBar.Panels[2].Width;
1160
1161 end;
1162
1163 procedure TEditorForm.Timer1Timer(Sender: TObject);
1164 begin
1165         if FSambaTime = ZERO_DATE then
1166                 StatusBar.Panels[1].Text := '\8f\89\8f\91'
1167         else begin
1168                 FNow := IncMilliSecond(FNow, 500);
1169                 StatusBar.Panels[1].Text := Format('%8.0f\95b\8co\89ß', [SecondSpan(FNow, FSambaTime)]);
1170         end;
1171
1172 end;
1173 //Samba.ini\82Ì\8f\91\82«\8d\9e\82Ý\8e\9e\8aÔ\82ð\93Ç\82Ý\8d\9e\82Þ
1174 procedure TEditorForm.ReadSambaTime(const AHost: string);
1175 var
1176         ini :TMemIniFile;
1177         tmp: string;
1178 begin
1179         Timer1.Enabled := false; //\8co\89ß\95b\90\94\95\\8e¦Timer\82ðOff\82É\82·\82é\81i\82±\82ê\82ªON\82Ì\82Æ\82«Samba24\91Î\8dôOn\81j
1180         FNow := Now();   //\8c»\8dÝ\8e\9e\8aÔ\82ð\8eæ\93¾\81iTimer\95\\8e¦\97p\82Å\81ACheck\82·\82é\82Æ\82«\82Í\8dÄ\82ÑNow()\82ð\8cÄ\82Ô\81j
1181         Timer1.Enabled := true; //\8co\89ß\95b\90\94\95\\8e¦Timer\82ðOn\82É\82·\82é\81i\82±\82ê\82ªON\82Ì\82Æ\82«Samba24\91Î\8dôOn\81j
1182         ini := TMemIniFile.Create(GikoSys.GetSambaFileName);
1183         try
1184                  //\95\8e\9a\97ñ\82Å\93Ç\82Ý\8eæ\82Á\82Ä\81A\95Ï\8a·\8aÖ\90\94\82ÅTDateTime\82Ö
1185                  tmp := ini.ReadString('Send', AHost, DateTimeToStr(ZERO_DATE));
1186                  FSambaTime := ConvertDateTimeString(tmp);
1187         finally
1188                 ini.Free;
1189         end;
1190 end;
1191 //Samba.ini\82É\8dÅ\8fI\8f\91\82«\8d\9e\82Ý\8e\9e\8aÔ\82ð\8f\91\82«\8d\9e\82Þ
1192 procedure TEditorForm.WriteSambaTime(const AHost: string; ATime: TDateTime);
1193 var
1194         ini :TMemIniFile;
1195 begin
1196         ini := TMemIniFile.Create(GikoSys.GetSambaFileName);
1197         try
1198                 ini.WriteDateTime('Send', AHost, ATime);
1199                 ini.UpdateFile;
1200         finally
1201                 ini.Free;
1202         end;
1203 end;
1204 //\8dÅ\8fI\8f\91\82«\8d\9e\82Ý\8e\9e\8aÔ\82Æ\8c»\8dÝ\8e\9e\82ð\94ä\8ar\82·\82é\81i\90^\81F\8bK\92è\92l\88È\8fã\81@\8bU\81F\8bK\92è\92l\96¢\96\9e\81j
1205 function TEditorForm.CheckSambaTime(const AHost: string; ATime: TDateTime): Boolean;
1206 var
1207         pastsec: double;
1208         SettingTime: Integer;
1209 begin
1210         SettingTime := ReadSettingTime(AHost);
1211         ReadSambaTime(AHost);
1212         pastsec := SecondSpan(ATime, FSambaTime);
1213         if pastsec > SettingTime then
1214                 Result := true
1215         else
1216                 Result := false;
1217 end;
1218 //AHost\81i\8eI\96¼\81j\82ÌSamba\82Ì\8bK\92è\92l\82ð\93Ç\82Ý\8d\9e\82Þ
1219 function TEditorForm.ReadSettingTime(const AHost: string): Integer;
1220 var
1221         ini :TMemIniFile;
1222 begin
1223         ini := TMemIniFile.Create(GikoSys.GetSambaFileName);
1224         try
1225                 Result := ini.ReadInteger('Setting', AHost, 0);
1226                 //\8bK\92è\92l\82ª\82O\82Ì\82Æ\82«\81A\82à\82µ\82­\82Í\90Ý\92è\82³\82ê\82Ä\82¢\82È\82¢\82Æ\82«\82Í\81A\83t\83@\83C\83\8b\82É\8f\91\82«\82½\82·\81B
1227                 if Result = 0 then begin
1228                         ini.WriteInteger('Setting', AHost, 0);
1229                         ini.UpdateFile;
1230                 end;
1231         finally
1232                 ini.Free;
1233         end;
1234 end;
1235 //Form\82ªActive\82É\82È\82Á\82½\82ç\8dÅ\8fI\8f\91\82«\8d\9e\82Ý\8e\9e\8aÔ\82ð\93Ç\82Ý\8d\9e\82Þ
1236 procedure TEditorForm.FormActivate(Sender: TObject);
1237 begin
1238         if ( Timer1.Enabled ) and ( FThreadItem <> nil )then
1239                 ReadSambaTime(FHost);
1240 end;
1241 //Samba24\91Î\8dô\82ð\8eg\82¤\82©\82Ç\82¤\82©\8c\88\82ß\82é\8aÖ\90\94
1242 //ReadSambaTime \82ð\8cÄ\82Ñ\8fo\82·\82ÆTimer\82ªOn\82É\82È\82é
1243 procedure TEditorForm.SetSamba24(AURL: string);
1244 var
1245         Protocol, Host, Path, Document, Port, Bookmark : string;
1246 begin
1247         //Samba24\91Î\8dô\82ð\82µ\82È\82¢\82È\82ç\8fI\97¹
1248         if not GikoSys.Setting.UseSamba then
1249                 Exit;
1250         //Host\82ÌURL\82É'.2ch.'\82©'.bbspink.'\82ª\8aÜ\82Ü\82ê\82Ä\82¢\82½\82çSamba24\91Î\8dô\82ð\82·\82é
1251         GikoSys.ParseURI( AURL, Protocol,Host, Path, Document, Port, Bookmark );
1252         if GikoSys.Is2chHost(Host) then begin
1253                 Host := Copy(Host, 1, AnsiPos('.', Host) - 1);
1254                 FHost := Host;   //FHost=\8eI\96¼
1255                 ReadSambaTime(FHost); //\88È\91O\82Ì\8f\91\82«\8d\9e\82Ý\8e\9e\8aÔ\82ð\93Ç\82Ý\8d\9e\82Þ
1256                 //StatusBar\82É\82±\82Ì\8eI\82Ì\8bK\92è\92l\82ð\95\\8e¦\82·\82é
1257                 StatusBar.Panels[2].Text := 'Samba24\8bK\92è\92l' + IntToStr(ReadSettingTime(FHost));
1258         end;
1259 end;
1260 procedure TEditorForm.FormCloseQuery(Sender: TObject;
1261   var CanClose: Boolean);
1262 begin
1263         CanClose := not FWork;
1264 end;
1265
1266 end.
1267