OSDN Git Service

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