OSDN Git Service

メインウィンドウとエディタの両方にジェスチャーが設定されていると AV を起こしてしまうバグを修正。
[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         MSHTML,
11 {$ELSE}
12         SHDocVw_TLB,
13         MSHTML_TLB,
14 {$IFEND}
15         ActiveX, {HTTPApp,} YofUtils, Trip, IniFiles, StrUtils,
16         GikoSystem, GikoUtil, ImgList, Clipbrd, BoardGroup,
17         IdAntiFreezeBase,       IdAntiFreeze, IdBaseComponent, IdComponent,
18         IdTCPConnection, IdTCPClient, IdHTTP, ActnList, StdActns, IdIntercept,
19         IdLogBase, IdLogDebug, IdException, DateUtils, MojuUtils, bmRegExp,
20         GestureModel;
21
22 type
23 //      TSetLayeredWindowAttributes = function(wnd: HWND; crKey: DWORD; bAlpha: BYTE; dwFlag: DWORD): Boolean; stdcall;
24         //\8f\91\82«\8d\9e\82Ý\96ß\82è\92l\83^\83C\83v
25         TGikoResultType = (grtOK, grtCookie, grtCheck, grtError);
26
27         TEditorForm = class(TForm)
28                 MainMenu: TMainMenu;
29                 FileMenu: TMenuItem;
30                 PostMessage: TMenuItem;
31                 SaveMessage: TMenuItem;
32                 CloseMenu: TMenuItem;
33                 N01: TMenuItem;
34                 StatusBar: TStatusBar;
35         EditorPage: TPageControl;
36                 EditorTab: TTabSheet;
37                 PreviewTab: TTabSheet;
38                 Browser: TWebBrowser;
39                 EditMenu: TMenuItem;
40                 UndoMenu: TMenuItem;
41                 CutMenu: TMenuItem;
42                 CopyMenu: TMenuItem;
43                 PasteMenu: TMenuItem;
44                 N02: TMenuItem;
45                 ToolBarImageList: TImageList;
46                 HotToobarImageList: TImageList;
47                 BodyEdit: TMemo;
48                 NameBasePanel: TPanel;
49                 NameLabel: TLabel;
50                 MailLabel: TLabel;
51                 NameComboBox: TComboBox;
52                 MailComboBox: TComboBox;
53                 ToolBar: TToolBar;
54                 SendToolButton: TToolButton;
55                 OutBoxToolButton: TToolButton;
56                 ToolButton5: TToolButton;
57                 UndoToolButton: TToolButton;
58                 CutToolButton: TToolButton;
59                 CopyToolButton: TToolButton;
60                 PasteToolButton: TToolButton;
61                 ToolButton3: TToolButton;
62                 TransToolButton: TToolButton;
63                 TopToolButton: TToolButton;
64                 Indy: TIdHTTP;
65                 IdAntiFreeze: TIdAntiFreeze;
66                 ToolButton1: TToolButton;
67                 ToolButton2: TToolButton;
68                 ActionList: TActionList;
69                 SendAction: TAction;
70                 SaveAction: TAction;
71                 CloseAction: TAction;
72                 UndoAction: TAction;
73                 CutAction: TAction;
74                 CopyAction: TAction;
75                 PasteAction: TAction;
76                 AbortAction: TAction;
77                 TopAction: TAction;
78                 Show1: TMenuItem;
79                 T1: TMenuItem;
80                 N1: TMenuItem;
81                 S1: TMenuItem;
82                 SageCheckBox: TCheckBox;
83                 IdLogDebug: TIdLogDebug;
84                 TransAction: TAction;
85                 A1: TMenuItem;
86                 KotehanCheckBox: TCheckBox;
87                 TitlePanel: TPanel;
88                 Label1: TLabel;
89                 TitleEdit: TEdit;
90                 SelectAllAction: TAction;
91                 N2: TMenuItem;
92                 SelectAll1: TMenuItem;
93         Timer1: TTimer;
94         QuotePasteAction: TAction;
95         QuotePasteMenuItem: TMenuItem;
96         C1: TMenuItem;
97         SpaceToNBSPAction: TAction;
98         AmpToCharRefAction: TAction;
99         SpaceTabnbsp1: TMenuItem;
100         amp1: TMenuItem;
101         BoardInformationTab: TTabSheet;
102                                 BoardtopTab: TTabSheet;
103         TitlePictureBrowser: TWebBrowser;
104         BoardTop: TMenuItem;
105         BoardInformationMemo: TMemo;
106         GetSETTINGTXTAction: TAction;
107         N3: TMenuItem;
108         SETTINGTXT2: TMenuItem;
109         GetTitlePictureAction: TAction;
110         OP1: TMenuItem;
111     GetHeadTXTAction: TAction;
112     HeadTXT1: TMenuItem;
113     RocalRuleTab: TTabSheet;
114     WebBrowser1: TWebBrowser;
115     CalcCapasityAction: TAction;
116     N4: TMenuItem;
117     N5: TMenuItem;
118     LocalRule: TMenuItem;
119     LocalEdit: TMemo;
120
121                 procedure EditorPageChange(Sender: TObject);
122                 procedure FormCreate(Sender: TObject);
123                 procedure BrowserStatusTextChange(Sender: TObject;
124                         const Text: WideString);
125                 procedure FormClose(Sender: TObject; var Action: TCloseAction);
126                 procedure FormDestroy(Sender: TObject);
127                 procedure SendActionExecute(Sender: TObject);
128                 procedure SaveActionExecute(Sender: TObject);
129                 procedure AbortActionExecute(Sender: TObject);
130                 procedure CloseActionExecute(Sender: TObject);
131                 procedure UndoActionExecute(Sender: TObject);
132                 procedure CutActionExecute(Sender: TObject);
133                 procedure CopyActionExecute(Sender: TObject);
134                 procedure PasteActionExecute(Sender: TObject);
135                 procedure SendActionUpdate(Sender: TObject);
136                 procedure SaveActionUpdate(Sender: TObject);
137                 procedure CloseActionUpdate(Sender: TObject);
138                 procedure UndoActionUpdate(Sender: TObject);
139                 procedure CutActionUpdate(Sender: TObject);
140                 procedure CopyActionUpdate(Sender: TObject);
141                 procedure PasteActionUpdate(Sender: TObject);
142                 procedure TopActionExecute(Sender: TObject);
143                 procedure TopActionUpdate(Sender: TObject);
144                 procedure SageCheckBoxClick(Sender: TObject);
145                 procedure MailComboBoxChange(Sender: TObject);
146                 procedure TransActionExecute(Sender: TObject);
147                 procedure TransActionUpdate(Sender: TObject);
148                 procedure IdLogDebugReceive(ASender: TIdConnectionIntercept;
149                         AStream: TStream);
150                 procedure IdLogDebugSend(ASender: TIdConnectionIntercept;
151                         AStream: TStream);
152                 procedure SelectAllActionExecute(Sender: TObject);
153         procedure StatusBarResize(Sender: TObject);
154         procedure Timer1Timer(Sender: TObject);
155         procedure FormActivate(Sender: TObject);
156         procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
157                 procedure QuotePasteActionExecute(Sender: TObject);
158         procedure SpaceToNBSPActionExecute(Sender: TObject);
159         procedure AmpToCharRefActionExecute(Sender: TObject);
160         procedure BoardTopClick(Sender: TObject);
161         procedure GetSETTINGTXTActionExecute(Sender: TObject);
162         procedure GetTitlePictureActionUpdate(Sender: TObject);
163         procedure GetTitlePictureActionExecute(Sender: TObject);
164     procedure GetHeadTXTActionExecute(Sender: TObject);
165     procedure CalcCapasityActionExecute(Sender: TObject);
166     procedure LocalRuleClick(Sender: TObject);
167     procedure FormDeactivate(Sender: TObject);
168         private
169                 FThreadItem: TThreadItem;
170                 FBoard: TBoard;
171                 FNameComboEdit: THandle;
172                 FMailComboEdit: THandle;
173                 FAbort: Boolean;
174                 FWork: Boolean;
175                 FStatusCode: Integer;
176                 FDebugStrReceive: string;
177                 FDebugStrSend: string;
178                 FSambaTime: TDateTime;
179                 FHost: string;
180                 FNow: TDateTime;
181                 FGestures       : TGestureModel;
182                 procedure Preview;
183                 function RepHtml(s: string): string;
184                 function Check: Boolean;
185                 procedure SetNameList(sName, sMail: string);
186 //              procedure Send(SendType: TGikoSendType; SPID: string; PON: string; FirstWriting: Boolean);
187                 procedure Send(SPID: string; PON: string; FirstWriting: Boolean);
188
189                 function GetActiveControlHandle: THandle;
190 //              function GetSendData: string;
191 //              procedure GetSendData(Source: TStringStream);
192                 procedure GetSendData(Source: TStringStream);
193                 procedure SaveSendFile;
194                 procedure SetContent(Content: string; ABrowser: TWebBrowser);
195                 function GetSPID(CookieLine: string): string;
196                 function GetPON(CookieLine: string): string;
197                 function GetResultType(ResponseText: string): TGikoResultType;
198                 procedure ReadSambaTime(const AHost: string);
199                 procedure WriteSambaTime(const AHost: string; ATime: TDateTime);
200                 function ReadSettingTime(const AHost: string): Integer;
201                 function CheckSambaTime(const AHost: string; ATime: TDateTime): Boolean;
202                                 procedure SetSamba24(AURL: string);
203                 /// \88ø\97p\95\84\82Ì\8eæ\93¾
204                 function GetOEIndentChar : string;
205                 /// \96{\95\82Ì\8eæ\93¾
206                 function GetBody : string;
207                 //IdHttp\82Ì\8f\89\8aú\89»
208                 procedure InitIdHTTP(http: TIdHTTP);
209                 procedure ShowBoardInformation(ABoard: TBoard; AMemo: TMemo);
210                 function GetTitlePictureURL(body: TStringList; ABoard: TBoard): string;
211                 procedure ShowTitlePicture();
212                                 function GetFusianaName(body: TStringList; ABoard: TBoard): String;
213                 //! \83}\83E\83X\83W\83F\83X\83`\83\83\81[\8aJ\8en
214                 procedure OnGestureStart(Sender: TObject);
215                 //! \83}\83E\83X\83W\83F\83X\83`\83\83\81[\92\86
216                 procedure OnGestureMove(Sender: TObject);
217                 //! \83}\83E\83X\83W\83F\83X\83`\83\83\81[\8fI\97¹
218                 procedure OnGestureEnd(Sender: TObject);
219                 //HEAD.TXT\8e©\93®\95\\8e¦
220                 procedure ShowBoardHead(ABoard: TBoard; AMemo: TMemo);
221         protected
222                 procedure CreateParams(var Params: TCreateParams); override;
223         public
224                                 FBBSID: String;
225                 procedure SetFont;
226                 procedure SetThreadItem(Item: TThreadItem);
227                 procedure SetBoard(Item: TBoard);
228                                 property BBSID: string read FBBSID write FBBSID;
229
230         end;
231
232 implementation
233
234 uses
235         Giko, ItemDownload, Gesture;
236 const
237         CAPTION_NAME_NEW: string = '\83M\83R\83i\83\83X\83\8c\97§\82Ä\83G\83f\83B\83^';
238         CAPTION_NAME_RES: string = '\83M\83R\83i\83\83\8c\83X\83G\83f\83B\83^';
239
240     // \83G\83f\83B\83b\83g\83E\83B\83\93\83h\83E\82ð\89E\89º\82É\82¸\82ç\82µ\82Ä\8aJ\82­\88Ú\93®\97Ê
241     WINDOWMOVE_H = 30;
242     WINDOWMOVE_V = 30;
243
244         //DAX\82³\82ñ±Ø¶ÞÄ!(\81L\81¤\81M)
245         READCGI_ERR                     = '-ERR';
246         READCGI_INCR            = '-INCR';
247         READCGI_OK                      = '+OK';
248         READCGI_PARTIAL = '+PARTIAL';
249         READCGI_ERR_FOUND_KAKO  = '-ERR \89ß\8b\8e\83\8d\83O\91q\8cÉ\82Å\94­\8c©';
250         READCGI_ERR_NOT_HTML            = '-ERR html\89»\91Ò\82¿';
251         READCGI_ERR_NOT_FOUND           = '-ERR \82»\82ñ\82È\94Âor\83X\83\8c\83b\83h\82È\82¢\82Å\82·\81B';
252         READCGI_ERR_ABONE                               = '-ERR \82Ç\82±\82©\82Å\82 \82Ú\81[\82ñ\82ª\82 \82Á\82½\82Ý\82½\82¢\82Å\82·\81B';
253         READCGI_ERR_TIMEOUT                     = '-ERR \8ew\92è\8e\9e\8aÔ\82ª\89ß\82¬\82Ü\82µ\82½\81B';
254         READCGI_ERR_CANTUSE                     = '-ERR \82à\82¤\81@\82Â\82©\82¦\82Ü\82¹\82ñ';
255         RES2CH_TRUE                             = '<!-- 2ch_X:true -->';
256         RES2CH_FALSE                    = '<!-- 2ch_X:false -->';
257         RES2CH_ERROR                    = '<!-- 2ch_X:error -->';
258         RES2CH_CHECK                    = '<!-- 2ch_X:check -->';
259         RES2CH_COOKIE                   = '<!-- 2ch_X:cookie -->';
260
261
262         BBS2CH_NAME:                                     string = '\82Q\82¿\82á\82ñ\82Ë\82é';
263         BBS2CH_LOG_FOLDER:               string = '2ch';
264         EXTERNAL_LOG_FOLDER:            string  = 'exboard';
265
266         FOLDER_INI_FILENAME:     string = 'Folder.ini';
267         FOLDER_INDEX_FILENAME: string   = 'Folder.idx';
268         SUBJECT_FILENAME:                       string  = 'subject.txt';
269         PATH_DELIM:                                             string  = '\';
270
271
272 type
273         TSelection = record
274                 StartPos, EndPos: Integer;
275         end;
276
277 {$R *.DFM}
278
279 {constructor TEditorForm.Create(AOwner: TComponent; Item: TBoard);
280 begin
281         inherited Create(AOwner);
282 end;}
283
284 procedure TEditorForm.CreateParams(var Params: TCreateParams);
285 begin
286         inherited;
287         if FormStyle in [fsNormal, fsStayOnTop] then
288                 if BorderStyle in [bsSingle, bsSizeable] then begin
289                         Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
290                         Params.WndParent := 0;
291                 end;
292 end;
293
294 {procedure TEditorForm.CreateParams(var Params: TCreateParams);
295 begin
296         inherited CreateParams(Params);
297         Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
298 end;}
299
300 procedure TEditorForm.FormCreate(Sender: TObject);
301 var
302         wp: TWindowPlacement;
303                 hUser32 : HINST;
304         ini: TIniFile;
305 begin
306         FWork := False;
307         Browser.Navigate('about:blank');
308         TitlePictureBrowser.Navigate('about:blank');
309         FBoard := nil;
310         FThreadItem := nil;
311
312         //\83E\83B\83\93\83h\83E\82Ì\88Ê\92u\90Ý\92è
313         wp.length := sizeof(wp);
314         wp.rcNormalPosition.Top := GikoSys.Setting.EditWindowTop;
315         wp.rcNormalPosition.Left := GikoSys.Setting.EditWindowLeft;
316
317         wp.rcNormalPosition.Bottom := GikoSys.Setting.EditWindowTop + GikoSys.Setting.EditWindowHeight;
318         wp.rcNormalPosition.Right := GikoSys.Setting.EditWindowLeft + GikoSys.Setting.EditWindowWidth;
319         wp.showCmd := SW_HIDE;
320         SetWindowPlacement(Handle, @wp);
321
322         if GikoSys.Setting.EditWindowMax then
323                 WindowState := wsMaximized;
324
325         //\83E\83B\83\93\83h\83E\82ª\89æ\96Ê\8aO\82È\82ç\89æ\96Ê\93à\82É\88Ú\93®\82·\82é
326         if (Left + Width) > Screen.Width then
327 //              Left := Screen.Width - Width;
328                 Left := 0;
329         if (Top + Height) > Screen.Height then
330 //              Top := Screen.Height - Height;
331                 Top := 0;
332         if Left < 0 then
333                 Left := 0;
334         if Top < 0 then
335                 Top := 0;
336
337     //\8c»\8dÝ\82Ì\83E\83B\83\93\83h\83E\82Ì\88Ê\92u\82ð\95Û\91
338     GikoSys.Setting.EditWindowTop := Top  + WINDOWMOVE_V;   // \8e\9f\82É\8aJ\82­\83E\83B\83\93\83h\83E\82Í
339     GikoSys.Setting.EditWindowLeft := Left + WINDOWMOVE_H;  // \81@\81@\81@\89E\8eÎ\82ß\89º\82É\82¸\82ç\82·
340     //\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·
341         if GikoSys.Setting.EditWindowHeight < 144 then
342                 Height := 400;
343         if GikoSys.Setting.EditWindowWidth < 144 then
344                 Width := 640;
345
346         EditorPage.ActivePage := EditorTab;
347         FNameComboEdit := GetWindow(NameComboBox.Handle, GW_CHILD);
348         FMailComboEdit := GetWindow(MailComboBox.Handle, GW_CHILD);
349         NameComboBox.Items.Assign(GikoSys.Setting.NameList);
350         MailComboBox.Items.Assign(GikoSys.Setting.MailList);
351         SetFont;
352         hUser32 := 0;
353         try
354                 try
355                         hUser32 := LoadLibrary('User32.dll');
356                         if hUser32 <> 0 then
357                                 TransAction.Enabled := true
358                         else
359                                 TransAction.Enabled := false;
360                 except
361                 TransAction.Enabled := false;
362                 end;
363         finally
364                 FreeLibrary(hUser32);
365         end;
366
367     // \83E\83B\83\93\83h\83E\82Ì\83X\83e\83C\8fó\91Ô
368         if GikoSys.Setting.EditWindowStay then begin    // \83X\83e\83C\8fó\91Ô
369                 SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE);
370                 TopAction.Checked := true;
371                 TopToolButton.Down := true;
372         end else begin                                  // \83X\83e\83C\82µ\82È\82¢
373                 SetWindowPos(Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE);
374                 TopAction.Checked := false;
375                 TopToolButton.Down := false;
376         end;
377
378     // \83E\83B\83\93\83h\83E\82Ì\94¼\93§\96¾\8fó\91Ô
379         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Ô
380         AlphaBlend := true;
381         TransAction.Checked := true;
382         TransToolButton.Down := true;
383     end else begin                                      // \95s\93§\96¾
384         AlphaBlend := false;
385         TransAction.Checked := false;
386         TransToolButton.Down := false;
387     end;
388         // \94¼\93§\96¾\8fó\91Ô\82Ì\95Û\91
389         GikoSys.Setting.EditWindowTranslucent := TransAction.Checked;
390
391         SpaceToNBSPAction.Checked               := GikoSys.Setting.SpaceToNBSP;
392         AmpToCharRefAction.Checked      := GikoSys.Setting.AmpToCharRef;
393
394                 ini := TIniFile.Create(GikoSys.Setting.GetFileName);
395
396                 try
397                         BoardtopTab.TabVisible := ini.Readbool('EditorForm', 'BoardTopTab', False);
398                         BoardTop.Checked := BoardtopTab.TabVisible;
399                         RocalRuleTab.TabVisible := ini.ReadBool('EditorForm', 'LocalRuleTab', False);
400                         LocalRule.Checked := RocalRuleTab.TabVisible;
401                 finally
402                         ini.Free;
403                 end;
404
405         // \83}\83E\83X\83W\83F\83X\83`\83\83\81[\82Ì\83C\83\93\83X\83g\81[\83\8b
406         if GikoSys.Setting.GestureEnabled then begin
407                 MouseGesture.UnHook;
408                 FGestures := TGestureModel.Create;
409                 FGestures.LoadGesture(
410                         GikoSys.Setting.GetGestureFileName, ActionList );
411                 MouseGesture.OnGestureStart := OnGestureStart;
412                 MouseGesture.OnGestureMove := OnGestureMove;
413                 MouseGesture.OnGestureEnd := OnGestureEnd;
414                 MouseGesture.SetHook( Handle );
415         end;
416
417 end;
418
419 procedure TEditorForm.SetBoard(Item: TBoard);
420 begin
421         FBoard := Item;
422         Caption := CAPTION_NAME_NEW + ' - [' + Item.Title + ']';
423         NameComboBox.Text := FBoard.KotehanName;
424         MailComboBox.Text := FBoard.KotehanMail;
425         SageCheckBox.Checked := AnsiPos('sage', MailComboBox.Text) <> 0;
426         TitlePanel.Visible := True;
427         SetSamba24(FBoard.URL);
428         ShowBoardInformation(FBoard, BoardInformationMemo);
429         ShowTitlePicture();
430 end;
431
432 procedure TEditorForm.SetThreadItem(Item: TThreadItem);
433 begin
434         FThreadItem := Item;
435         Caption := CAPTION_NAME_RES + ' - [' + FThreadItem.Title + ']';
436         NameComboBox.Text := FThreadItem.ParentBoard.KotehanName;
437         MailComboBox.Text := FThreadItem.ParentBoard.KotehanMail;
438         SageCheckBox.Checked := AnsiPos('sage', MailComboBox.Text) <> 0;
439         TitlePanel.Visible := False;
440         SetSamba24(FThreadItem.ParentBoard.URL);
441         ShowBoardInformation(FThreadItem.ParentBoard, BoardInformationMemo);
442         ShowTitlePicture();
443 end;
444
445 function TEditorForm.GetBody : string;
446 var
447         body, tmp               : string;
448         p, tail                 : PChar;
449         len                                     : Integer;
450 const
451         TAB_LENGTH      = 4;
452 begin
453
454         body := BodyEdit.Text;
455         if AmpToCharRefAction.Checked then
456                 // & \82Ì\92u\8a·\82Í\88ê\94Ô\8dÅ\8f\89\82É\82â\82é\82±\82Æ
457                 body := CustomStringReplace( body, '&', '&amp;' );
458         if SpaceToNBSPAction.Checked then begin
459                 p                       := PChar( body );
460                 tail    := p + Length( body );
461                 len             := 0;
462                 while p < tail do begin
463                         case p^ of
464                         #09:
465                                 begin
466                                         Inc( p );
467                                         repeat
468                                                 Inc( len );
469                                                 tmp := tmp + '&nbsp;';
470                                         until (len mod TAB_LENGTH) = 0;
471                                 end;
472
473                         #10, #13:
474                                 begin
475                                         tmp := tmp + p^;        Inc( p );
476                                         len     := 0;
477                                 end;
478
479                         ' ':
480                                 begin
481                                         tmp     := tmp + '&nbsp;';
482                                         Inc( p );
483                                         Inc( len );
484                                 end;
485                                 
486                         '&':
487                                 // \8eÀ\91Ì\8eQ\8fÆ\82Í 1 \95\8e\9a\95ª
488                                 begin
489                                         tmp := tmp + '&';
490                                         Inc( p );
491                                         Inc( len );
492                                         while p < tail do begin
493                                                 if p^ in ['a'..'z', 'A'..'Z', '0'..'9', '#'] then begin
494                                                         tmp := tmp + p^;
495                                                 end else if p^ = ';' then begin
496                                                         tmp := tmp + p^;
497                                                         Inc( p );
498                                                         Break;
499                                                 end else begin
500                                                         Break;
501                                                 end;
502                                                 Inc( p );
503                                         end;
504                                 end;
505
506                         else
507                                 if p^ in kYofKanji then begin
508                                         tmp := tmp + p^;        Inc( p );
509                                         tmp     := tmp + p^;    Inc( p );
510                                         len     := len + 2;
511                                 end else begin
512                                         tmp := tmp + p^;        Inc( p );
513                                         Inc( len );
514                                 end;
515                         end;
516                 end;
517                 body := tmp;
518         end;
519
520         Result  := body;
521
522 end;
523
524 procedure TEditorForm.SetFont;
525 begin
526         BodyEdit.Font.Name := GikoSys.Setting.EditorFontName;
527         BodyEdit.Font.Size := GikoSys.Setting.EditorFontSize;
528         BodyEdit.Font.Color := GikoSys.Setting.EditorFontColor;
529         BodyEdit.Color := GikoSys.Setting.EditorBackColor;
530 end;
531
532 procedure TEditorForm.Preview;
533 var
534         Title: string;
535         No: string;
536         Mail: string;
537         Namae: string;
538         DateTime: string;
539         Body: string;
540         s: string;
541
542                                 posTrip : Integer;
543                                 tripOrigin : string;
544 begin
545         if FThreadItem = nil then begin
546                 No := '1';
547                 Title := RepHtml(TitleEdit.Text);
548         end else begin
549                 No := IntToStr(FThreadItem.Count + 1);
550                 Title := RepHtml(FThreadItem.Title);
551         end;
552
553         body := GetBody;
554         Namae := RepHtml(NameComboBox.Text);
555         Mail := RepHtml(MailComboBox.Text);
556         Body := RepHtml(body);
557         Body := StringReplace(Body, #13#10, '<br>', [rfReplaceAll]);
558         DateTime := FormatDateTime('yyyy/mm/dd(aaa) hh:nn', now);
559
560         if Trim(Namae) = '' then
561                 Namae := '\96¼\96³\82µ\82³\82ñ';
562
563         s := '<HTML><HEAD>' + #13#10
564                         + '<META http-equiv="Content-Type" content="text/html; charset=Shift_JIS">' + #13#10
565                         + '<TITLE>' + title + '</TITLE>' + #13#10
566 //                      + '<STYLE><!--BODY{font-size : 9pt;font-family : "\82l\82\82o\83S\83V\83b\83N";}--></STYLE>' + #13#10
567                         + '</HEAD>' + #13#10
568                         + '<BODY text="#000000" bgcolor="#EFEFEF" link="#0000FF" alink="#FF0000" vlink="#660099">' + #13#10
569                         + '<FONT COLOR="#FF0000">' + title + '</FONT>' + #13#10
570                         + '<DL>' + #13#10;
571                                 posTrip := AnsiPos( '#', Namae );
572                                 if posTrip > 0 then
573                                 begin
574                                                                 tripOrigin := Copy( Namae, posTrip + 1, Length( Namae ) );
575                                                                 Namae :=
576                                                                                                 Copy( Namae, 1, posTrip - 1 ) + '</B> \81\9f' +
577                                                                                                 get_2ch_trip( PChar( tripOrigin ) ) + '<B>';
578                                 end;
579         if Mail = '' then
580                 s := s + '<DT>' + No + ' \81F <FONT color="forestgreen"><B>' + Namae + '</B></FONT> \81F ' + DateTime+ '<BR><DD>' + Body + '<BR><BR><BR>' + #13#10
581         else
582                 s := s + '<DT>' + No + ' \81F <A href="mailto:' + Mail + '"><B>' + Namae + '</B></A> [' + Mail + ']\81F ' + DateTime+ '<BR><DD>' + Body + '<BR><BR><BR>' + #13#10;
583         s := s + '</BODY></HTML>';
584         SetContent(s, Browser);
585 end;
586
587 function TEditorForm.RepHtml(s: string): string;
588 begin
589 //      s := StringReplace(s, '&', '&amp;', [rfReplaceAll]);
590         s := StringReplace(s, '<', '&lt;', [rfReplaceAll]);
591         s := StringReplace(s, '>', '&gt;', [rfReplaceAll]);
592 //      s := StringReplace(s, ' ', '&nbsp;', [rfReplaceAll]);   //\8ed\97l\95Ï\8dX\82É\82æ\82è&nbsp;\8eg\97p\95s\89Â
593         s := StringReplace(s, '"', '&quot;', [rfReplaceAll]);
594         Result := s;
595 end;
596
597 procedure TEditorForm.EditorPageChange(Sender: TObject);
598 var
599         tmpBoard: TBoard;
600 begin
601         if FThreadItem = nil then
602                 tmpBoard := FBoard
603         else
604                 tmpBoard := FThreadItem.ParentBoard;
605
606         if tmpBoard = nil then Exit;
607
608         if EditorPage.ActivePage = PreviewTab then begin
609                 Preview;
610         end else if EditorPage.ActivePage = RocalRuleTab then begin
611                 ShowBoardHead(tmpBoard, LocalEdit);
612         end else begin
613                 Browser.Navigate('about:blank');
614         end;
615 end;
616
617 procedure TEditorForm.BrowserStatusTextChange(Sender: TObject;
618         const Text: WideString);
619 begin
620         if EditorPage.ActivePage = PreviewTab then begin
621                 StatusBar.Panels[0].Text := Text;
622         end else begin
623                 StatusBar.Panels[0].Text := '';
624         end;
625 end;
626
627 function TEditorForm.Check: Boolean;
628 var
629         Msg: string;
630         rc: Integer;
631         Board: TBoard;
632 begin
633         Result := True;
634         if FThreadItem = nil then
635                 Board := FBoard
636         else
637                 Board := FThreadItem.ParentBoard;
638
639         if (not GikoSys.Setting.UseMachineTime) and
640                  ((Board.LastGetTime = 0) or
641                         (Board.LastGetTime = ZERO_DATE)) then begin
642                 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
643                                  + '\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¢';
644                 MsgBox(Handle, Msg, '\83G\83\89\81[', MB_OK or MB_ICONSTOP);
645                 Result := False;
646         end else if BodyEdit.Text = '' then begin
647                 Msg := '\96{\95\82ª\93ü\97Í\82³\82ê\82Ä\82¢\82Ü\82¹\82ñ\81B';
648                 MsgBox(Handle, Msg, '\83G\83\89\81[', MB_OK or MB_ICONSTOP);
649                 Result := False;
650         end else if (FBoard <> nil) and (Trim(TitleEdit.Text) = '') then begin
651                 Msg := '\83^\83C\83g\83\8b\82ª\93ü\97Í\82³\82ê\82Ä\82¢\82Ü\82¹\82ñ\81B';
652                 MsgBox(Handle, Msg, '\83G\83\89\81[', MB_OK or MB_ICONSTOP);
653                 Result := False;
654         end else begin
655                 if (not GikoSys.Dolib.Connected) and (AnsiPos('\81\9c', NameComboBox.Text) <> 0) then begin
656                         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
657                                          + '\82±\82Ì\82Ü\82Ü\91\97\90M\82µ\82Ä\82à\82æ\82ë\82µ\82¢\82Å\82·\82©\81H';
658                         rc := MsgBox(Handle, Msg, '\8am\94F', MB_YESNO or MB_ICONQUESTION);
659                         Result := (rc = IDYES);
660                 end;
661         end;
662 end;
663
664 procedure TEditorForm.FormClose(Sender: TObject; var Action: TCloseAction);
665 begin
666         Action := caFree;
667 end;
668
669 procedure TEditorForm.FormDestroy(Sender: TObject);
670 var
671         wp: TWindowPlacement;
672 begin
673         //\8dÅ\91å\89»\81E\83E\83B\83\93\83h\83E\88Ê\92u\95Û\91
674         wp.length := sizeof(wp);
675         GetWindowPlacement(Handle, @wp);
676
677         GikoSys.Setting.EditWindowTop := wp.rcNormalPosition.Top;
678         GikoSys.Setting.EditWindowLeft := wp.rcNormalPosition.Left;
679         GikoSys.Setting.EditWindowHeight := wp.rcNormalPosition.Bottom - wp.rcNormalPosition.Top;
680         GikoSys.Setting.EditWindowWidth := wp.rcNormalPosition.Right - wp.rcNormalPosition.Left;
681         GikoSys.Setting.EditWindowMax := WindowState = wsMaximized;
682         //GikoSys.Setting.EditWindowStay := FormStyle = fsStayOnTop;      // \83X\83e\83C\8fó\91Ô\82Ì\95Û\91
683         GikoSys.Setting.EditWindowTranslucent := TransAction.Checked;   // \94¼\93§\96¾\8fó\91Ô\82Ì\95Û\91
684
685         FGestures.Free;
686
687 end;
688
689 procedure TEditorForm.SetNameList(sName, sMail: string);
690 begin
691         if Trim(sName) <> '' then begin
692                 if GikoSys.Setting.NameList.IndexOf(sName) = -1 then
693                         GikoSys.Setting.NameList.Insert(0, sName);
694         end;
695         if Trim(sMail) <> '' then begin
696                 if GikoSys.Setting.MailList.IndexOf(sMail) = -1 then
697                         GikoSys.Setting.MailList.Insert(0, sMail);
698         end;
699 end;
700
701 function TEditorForm.GetActiveControlHandle: THandle;
702 begin
703         if EditorPage.ActivePage = EditorTab then begin
704                 if ActiveControl = NameComboBox then
705                         Result := FNameComboEdit
706                 else if ActiveControl = MailComboBox then
707                         Result := FMailComboEdit
708                 else if ActiveControl = BodyEdit then
709                         Result := BodyEdit.Handle
710                 else if ActiveControl = TitleEdit then
711                         Result := TitleEdit.Handle
712                 else
713                         Result := 0;
714         end else if Editorpage.ActivePage = BoardInformationTab then begin
715                 if ActiveControl = BoardInformationMemo then
716                         Result := BoardInformationMemo.Handle
717                 else
718                         Result := 0;
719         end else
720                 Result := 0;
721 end;
722
723 procedure TEditorForm.SetContent(Content: string; ABrowser: TWebBrowser);
724 var
725         doc: Variant;
726 begin
727         if ABrowser.Document <> nil then begin
728                 doc := Idispatch( olevariant(ABrowser.ControlInterface).Document) as IHTMLDocument2;
729                 doc.Clear;
730                 doc.open;
731                 doc.charset := 'Shift_JIS';
732                 doc.Write(Content);
733                 doc.Close;
734         end;
735 end;
736 procedure TEditorForm.InitIdHTTP(http: TIdHTTP);
737 begin
738         http.Request.Clear;
739         http.ProxyParams.BasicAuthentication := False;
740         if GikoSys.Setting.WriteProxy then begin
741                 http.ProxyParams.ProxyServer := GikoSys.Setting.WriteProxyAddress;
742                 http.ProxyParams.ProxyPort := GikoSys.Setting.WriteProxyPort;
743                 http.ProxyParams.ProxyUsername := GikoSys.Setting.WriteProxyUserID;
744                 http.ProxyParams.ProxyPassword := GikoSys.Setting.WriteProxyPassword;
745                 if GikoSys.Setting.ReadProxyUserID <> '' then
746                         http.ProxyParams.BasicAuthentication := True;
747         end else begin
748                 http.ProxyParams.ProxyServer := '';
749                 http.ProxyParams.ProxyPort := 80;
750                 http.ProxyParams.ProxyUsername := '';
751                 http.ProxyParams.ProxyPassword := '';
752         end;
753         Indy.Request.UserAgent := GikoSys.GetUserAgent;
754         Indy.Request.AcceptEncoding := '';
755 end;
756
757 procedure TEditorForm.Send(SPID: string; PON: string; FirstWriting: Boolean);
758 var
759         TextStream: TStringStream;
760         Source: TStringStream;
761         ResponseText: string;
762         URL: string;
763         RefURL: string;
764         State: TGikoDownloadState;
765         ResultType: TGikoResultType;
766         MsgResult: Integer;
767         Cookie: string;
768         Board: TBoard;
769         sysMenu : HMENU;
770         //fusianasan\83g\83\89\83b\83v by\92è\8aú\95Ö
771         Namae: String;
772 //      SettingTxt: String;
773 //        RefeURL: string;
774 //        RuleURL: String;
775 //        RuleTxt: String;
776 //        Name: String;
777 //        SettingBody: TStringList;
778 //        tmpBoard: TBoard;
779 begin
780         FAbort := False;
781         State := gdsError;
782         Namae := RepHtml(NameComboBox.Text);
783         if FThreadItem = nil then
784                 Board := FBoard
785         else
786                 Board := FThreadItem.ParentBoard;
787
788
789         InitIdHTTP(Indy);
790         if FThreadItem = nil then begin
791                 URL := FBoard.GetSendURL;
792                 RefURL := GikoSys.UrlToServer(FBoard.URL) + 'test/bbs.cgi';
793         end else begin
794                 URL := FThreadItem.GetSendURL;
795                 RefURL := FThreadItem.URL;
796         end;
797 //      Indy.Request.UserAgent := GikoSys.GetUserAgent;
798         Indy.Request.Referer := RefURL;
799 //      Indy.Request.AcceptEncoding := '';
800
801         Cookie := '';
802         if SPID <> '' then
803                 Cookie := Cookie + 'SPID=' + SPID + '; ';
804         if PON <> '' then
805                 Cookie := Cookie + 'PON=' + PON + '; ';
806         Cookie := 'Cookie: ' + Cookie + 'NAME=' + NameComboBox.Text + '; MAIL=' + MailComboBox.Text;
807
808         sysMenu := GetSystemMenu( Handle, false );
809         EnableMenuItem( sysMenu, SC_CLOSE, MF_GRAYED );
810 {
811   EnableMenuItem(SysMenu, SC_CLOSE, MF_BYCOMMAND or MF_ENABLED);
812   DrawMenuBar(Handle);
813 }
814         Indy.Request.CustomHeaders.Clear;
815 //      Indy.Request.CacheControl := 'no-cache';
816         Indy.Request.CustomHeaders.Add('Pragma: no-cache');
817         Indy.Request.AcceptLanguage := 'ja';
818         Indy.Request.Accept := 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*';
819         Indy.Request.ContentType := 'application/x-www-form-urlencoded';
820         Indy.Request.CustomHeaders.Add(Cookie);
821         TextStream := TStringStream.Create('');
822         Source := TStringStream.Create('');
823         try
824                 try
825                         FDebugStrReceive := '';
826                         FDebugStrSend := '';
827                         GetSendData(Source);
828                         Indy.Post(URL, Source, TextStream);
829                         ResponseText := TextStream.DataString;
830
831                         ResultType := GetResultType(ResponseText);
832
833                         //MsgResult\8f\89\8aú\89»
834                         MsgResult := IDNO;
835                         //\83t\83V\83A\83i\83g\83\89\83b\83v\8cx\8d\90(LocalMode) by \92è\8aú\95Ö
836                         if ((Namae = '\8eR\8dè\8fÂ') or (Namae = 'fusianasan')) and (FirstWriting) then begin
837                                 MsgResult := MsgBox(
838                                                 Handle,
839                                         '\83\8a\83\82\81[\83g\83z\83X\83g\82ð\95\\8e¦\82·\82é\8b@\94\\82ª\8eg\82í\82ê\82Ä\82¢\82Ü\82·' + #13#10 +
840                                         '\82à\82µ\82à\8aÔ\88á\82Á\82Ä\82±\82Ì\95û\96@\82Å\83z\83X\83g\82ª\95\\8e¦\82³\82ê\82½\82Æ\82µ\82Ä\82à\81A\8e©\8cÈ\90Ó\94C\82È\82Ì\82Å\8dí\8f\9c\88Ë\97\8a\82É\82Í\89\9e\82\82Ü\82¹\82ñ\81B' + #13#10#13#10 +
841                                         '\90Ó\94C\82ð\95\89\82¤\82±\82Æ\82ð\8f³\91ø\82µ\82Ä\8f\91\82«\8d\9e\82Ý\82Ü\82·\82©\81H',
842                                         '\8fî\95ñ',
843                                         MB_YESNO or MB_ICONQUESTION);
844                                 if MsgResult = IDNO  then begin
845                                         Board.SPID := '';
846                                         Board.PON := '';
847                                         FWork := false;
848                                         EnableMenuItem(SysMenu, SC_CLOSE, MF_BYCOMMAND or MF_ENABLED);
849                                         DrawMenuBar(Handle);
850                                         Exit;
851                                 end;
852                         end;
853
854                         if ResultType = grtOK then begin
855                                 WriteSambaTime(FHost, Now());
856                                 State := gdsComplete;
857                         end else if ResultType = grtCookie then begin
858                                 //\83\8b\81[\83v\96h\8e~
859                                 if not FirstWriting then
860                                         raise Exception.Create('');
861                                 MsgResult := MsgBox(
862                                         Handle,
863                                         '\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 +
864                                         '\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 +
865                                         '\91S\90Ó\94C\82ð\95\89\82¤\82±\82Æ\82ð\8f³\91ø\82µ\82Ä\8f\91\82«\8d\9e\82Ý\82Ü\82·\82©\81H',
866                                         '\8fî\95ñ',
867                                         MB_YESNO or MB_ICONQUESTION);
868                                 if MsgResult = IDYES then begin
869                                         Board.SPID := GetSPID(Indy.Response.RawHeaders.Values['Set-Cookie']);
870                                         Board.PON := GetPON(Indy.Response.RawHeaders.Values['Set-Cookie']);
871                                         if (Board.SPID = '') and (Board.PON = '') then
872                                                 raise Exception.Create('');
873                                         //\82à\82¤\88ê\89ñ\82±\82Ì\83\81\83\\83b\83h
874                                         Send(Board.SPID, Board.PON, False);
875                                         Exit;
876                                 end else begin
877                                         Board.SPID := '';
878                                         Board.PON := '';
879                                         FWork := false;
880                                         EnableMenuItem(SysMenu, SC_CLOSE, MF_BYCOMMAND or MF_ENABLED);
881                                         DrawMenuBar(Handle);
882                                         Exit;
883                                 end;
884                         end else if ResultType = grtCheck then begin
885                                 //
886                                 //\83\8b\81[\83v\96h\8e~
887                                 if not FirstWriting then
888                                         raise Exception.Create('');
889
890                                 MsgResult := MsgBox(
891                                         Handle,
892                                         '\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 +
893                                         '\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 +
894                                         '\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 +
895                                         '\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 +
896                                         #13#10 +
897                                         '\91S\90Ó\94C\82ð\95\89\82¤\82±\82Æ\82ð\8f³\91ø\82µ\82Ä\8f\91\82«\8d\9e\82Ý\82Ü\82·\82©\81H',
898                                         '\8am\94F',
899                                         MB_YESNO or MB_ICONQUESTION);
900
901                                 if MsgResult = IDYES then begin
902                                         Board.SPID := GetSPID(Indy.Response.RawHeaders.Values['Set-Cookie']);
903                                         Board.PON := GetPON(Indy.Response.RawHeaders.Values['Set-Cookie']);
904                                         if (Board.SPID = '') and (Board.PON = '') then
905                                                 raise Exception.Create('');
906                                         Send(Board.SPID, Board.PON, False);
907                                         Exit;
908                                 end else begin
909                                         EnableMenuItem(SysMenu, SC_CLOSE, MF_BYCOMMAND or MF_ENABLED);
910                                         DrawMenuBar(Handle);
911                                         Board.SPID := '';
912                                         Board.PON := '';
913                                         FWork := false;
914                                         Exit;
915                                         end;
916                         end else begin
917                 WriteSambaTime(FHost, Now());
918                                 State := gdsError;
919                                 raise Exception.Create('');
920                         end;
921
922                 except
923                         on E: EIdConnectException do begin
924                                 State := gdsError;
925                                 ResponseText := '<html><body>'
926                                                                                         + '<div>\90Ú\91±\82ª\8e¸\94s\82µ\82Ü\82µ\82½<br>'
927                                                                                         + '\89ñ\90ü\82â\83v\83\8d\83L\83V\82Ì\8fó\91Ô\82ð\92²\82×\82Ä\82­\82¾\82³\82¢<br></div>'
928                                                                                         + '<br><br><div>' + E.Message + '</div>'
929                                                                                         + '</body></html>';
930                         end;
931                         on E: Exception do begin
932                                 State := gdsError;
933
934                                 FDebugStrReceive := AnsiReplaceText(FDebugStrReceive, '<', '&lt;');
935                                 FDebugStrReceive := AnsiReplaceText(FDebugStrReceive, '>', '&gt;');
936                                 FDebugStrSend := AnsiReplaceText(FDebugStrSend, '<', '&lt;');
937                                 FDebugStrSend := AnsiReplaceText(FDebugStrSend, '>', '&gt;');
938
939                                 ResponseText := '<html><body>' + TextStream.DataString;
940                                 ResponseText := AnsiReplaceText(ResponseText, '</body>', '');
941                                 ResponseText := AnsiReplaceText(ResponseText, '</html>', '');
942                                 ResponseText := ResponseText + '<hr><div align="left"><pre>';
943                                 ResponseText := ResponseText + '<b>\82±\82±\82©\82ç\83M\83R\83i\83r\82Ì\8fî\95ñ</b>'#13#10;
944                                 ResponseText := ResponseText + #13#10'\81\9c\91\97\90M'#13#10;
945                                 ResponseText := ResponseText + FDebugStrSend;
946                                 ResponseText := ResponseText + #13#10'\81\9c\8eó\90M'#13#10;
947                                 ResponseText := ResponseText + FDebugStrReceive;
948                                 ResponseText := ResponseText + '</pre></div></body></html>';
949                         end;
950                 end;
951                 FStatusCode := Indy.ResponseCode;
952                 if FAbort then
953                         State := gdsAbort;
954         finally
955                 Source.Free;
956                 TextStream.Free;
957                 //sysMenu := GetSystemMenu( Handle, true );
958                 EnableMenuItem(SysMenu, SC_CLOSE, MF_BYCOMMAND or MF_ENABLED);
959                 DrawMenuBar(Handle);
960         end;
961         FWork := false;
962         //\94ñ\8cö\8e®\83M\83R\83i\83r\94Â\82È\82Ç\82Ì\83X\83N\83\8a\83v\83g\97p
963         //ResponceCode\82ª302Found\82Å\8f\91\82«\8d\9e\82Ý\8a®\97¹
964         if FStatusCode = 302 then begin
965                 GikoForm.PlaySound('ResEnd');
966                 SaveSendFile;
967                 if FThreadItem = nil then
968                         GikoForm.AddMessageList(FBoard.Title + ' [\90V\83X\83\8c\91\97\90M\8fI\97¹]', nil, gmiOK)
969                 else
970                         GikoForm.AddMessageList(FThreadItem.Title + ' [\83\8c\83X\91\97\90M\8fI\97¹]', nil, gmiOK);
971                 Close;
972                 Exit;
973         end;
974         if State = gdsComplete then begin
975                 GikoForm.PlaySound('ResEnd');
976                 SaveSendFile;
977                 if FThreadItem = nil then
978                         GikoForm.AddMessageList(FBoard.Title + ' [\90V\83X\83\8c\91\97\90M\8fI\97¹]', nil, gmiOK)
979                 else
980                         GikoForm.AddMessageList(FThreadItem.Title + ' [\83\8c\83X\91\97\90M\8fI\97¹]', nil, gmiOK);
981                 Close;
982         end else if State = gdsError then begin
983                 if FThreadItem = nil then
984                         GikoForm.AddMessageList(FBoard.Title + ' [\90V\83X\83\8c\91\97\90M\8e¸\94s]', nil, gmiNG)
985                 else
986                         GikoForm.AddMessageList(FThreadItem.Title + ' [\83\8c\83X\91\97\90M\8e¸\94s]', nil, gmiNG);
987                 EditorPage.ActivePage := PreviewTab;
988                 SetContent(ResponseText, Browser);
989         end else if State = gdsAbort then begin
990                 GikoForm.AddMessageList(FThreadItem.Title + ' [\92\86\92f]', nil, gmiSAD);
991         end;
992 end;
993
994 function TEditorForm.GetResultType(ResponseText: string): TGikoResultType;
995 begin
996         if AnsiPos('\8f\91\82«\82±\82Ý\82ª\8fI\82í\82è\82Ü\82µ\82½', ResponseText) <> 0 then
997                 Result := grtOK
998         else if (AnsiPos('\83N\83b\83L\81[\82ª\82È\82¢\82©\8aú\8cÀ\90Ø\82ê\82Å\82·', ResponseText) > 0) or
999                                         (AnsiPos('<title>\83N\83b\83L\81[\8am\94F\81I</title>', ResponseText) > 0)    or
1000                                         (AnsiPos('<title>\81¡\83N\83b\83L\81[\8am\94F\81I\81¡</title>', ResponseText) > 0)        or
1001                                         //(AnsiPos('\83N\83b\83L\81[\8am\94F', ResponseText) > 0) or
1002                                         (AnsiPos(RES2CH_COOKIE, ResponseText) > 0)      then
1003                 Result := grtCookie
1004         else if (AnsiPos('<font size=+2 color=#FF0000>\8f\91\82«\8d\9e\82Ý\83`\83F\83b\83N\81I </font>', ResponseText) > 0)   or
1005                                         (AnsiPos('<title>\81¡ \8f\91\82«\8d\9e\82Ý\8am\94F\82µ\82Ü\82· \81¡</title>', ResponseText) > 0)  or
1006                                         (AnsiPos('<title>\93\8a\8de\8am\94F</title>', ResponseText) > 0)  or
1007                                         (AnsiPos('<b>\8f\91\82«\82±\82Ý\8am\94F</b>', ResponseText) > 0)      or
1008                                         (AnsiPos('="../test/subbbs.cgi">', ResponseText) > 0)   or
1009                                         (AnsiPos(RES2CH_FALSE, ResponseText) > 0)       then
1010                 Result := grtCheck
1011         else
1012                 Result := grtError;
1013 end;
1014
1015
1016 procedure TEditorForm.GetSendData(Source: TStringStream);
1017 var
1018         SessionID: string;
1019         s: string;
1020         SendTime: Integer;
1021         Adjust: Integer;
1022         Board: TBoard;
1023         body            : string;
1024 begin
1025         if FThreadItem = nil then
1026                 Board := FBoard
1027         else
1028                 Board := FThreadItem.ParentBoard;
1029
1030         if GikoSys.Setting.UseMachineTime then begin
1031                 if GikoSys.Setting.TimeAdjust then
1032                         Adjust := Gikosys.Setting.TimeAdjustSec
1033                 else
1034                         Adjust := GikoSys.Setting.TimeAdjustSec * -1;
1035                 SendTime := GikoSys.DateTimeToInt(Now) - (9 * 60 * 60) + Adjust
1036         end else begin
1037                 if (Board.LastGetTime = 0) or (Board.LastGetTime = ZERO_DATE) then
1038                         SendTime := GikoSys.DateTimeToInt(Now)
1039                 else
1040                         SendTime := GikoSys.DateTimeToInt(Board.LastGetTime);
1041         end;
1042
1043         body := GetBody;
1044
1045         SessionID := GikoSys.Dolib.SessionID;
1046         if SessionID <> '' then
1047                 s := 'sid=' + HttpEncode(SessionID) + '&'
1048         else
1049                 s := '';
1050         s := s + 'subject=&'
1051                                  + 'FROM=' + HttpEncode(NameComboBox.Text) + '&'
1052                                  + 'mail=' + HttpEncode(MailComboBox.Text) + '&'
1053                                  + 'MESSAGE=' + HttpEncode(body) + '&'
1054                                  + 'bbs=' + Board.BBSID + '&'
1055                                  + 'time=' + IntToStr(SendTime) + '&';
1056         if FThreadItem = nil then begin
1057                 s := s + 'subject=' + HttpEncode(TitleEdit.Text) + '&';
1058                 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;
1059         end else begin
1060                 s := s + 'key=' + ChangeFileExt(FThreadItem.FileName, '') + '&';
1061                 s := s + 'submit=' + HttpEncode('\8f\91\82«\8d\9e\82Þ') + #13#10;
1062         end;
1063         Source.WriteString(s);
1064 end;
1065
1066 procedure TEditorForm.SaveSendFile;
1067 var
1068         sDate: string;
1069         ini: TMemIniFile;
1070 begin
1071         ini := TMemIniFile.Create(GikoSys.GetSentFileName);
1072         try
1073                 sDate := IntToStr(GikoSys.DateTimeToInt(Now));
1074
1075                 ini.WriteString(sDate, 'Name', NameComboBox.Text);
1076                 ini.WriteString(sDate, 'EMail', MailComboBox.Text);
1077                 ini.WriteString(sDate, 'Body', HttpEncode(BodyEdit.Text));
1078                 ini.WriteInteger(sDate, 'Status', FStatusCode);
1079                 ini.WriteDateTime(sDate, 'Date', Now);
1080                 if FThreadItem = nil then begin
1081                         ini.WriteString(sDate, 'Title', TitleEdit.Text);
1082                         ini.WriteString(sDate, 'BBS', FBoard.BBSID);
1083                         ini.WriteInteger(sDate, 'NewThread', 1);
1084                 end else begin
1085                         ini.WriteString(sDate, 'Title', FThreadItem.Title);
1086                         ini.WriteString(sDate, 'BBS', FThreadItem.ParentBoard.BBSID);
1087                         ini.WriteString(sDate, 'Key', ChangeFileExt(FThreadItem.FileName, ''));
1088                 end;
1089
1090                 ini.UpdateFile;
1091         finally
1092                 ini.Free;
1093         end;
1094 end;
1095
1096 procedure TEditorForm.SendActionExecute(Sender: TObject);
1097 var
1098         Board: TBoard;
1099         rc: Integer;
1100         state : TGikoDownloadState;
1101         body            : string;
1102 begin
1103         if FWork then
1104                 Exit;
1105         try
1106                 FWork := True;
1107                 SendAction.Enabled := False;
1108                 Application.ProcessMessages;
1109                 if not Check then Exit;
1110
1111                 if FThreadItem = nil then
1112                         Board := FBoard
1113                 else
1114                         Board := FThreadItem.ParentBoard;
1115
1116                 if FThreadItem = nil then begin
1117                         rc := GikoUtil.MsgBox(Handle,
1118                                                                                                         '\81u' + Board.Title + '\81v\94Â\82É\90V\82µ\82¢\83X\83\8c\83b\83h\97§\82Ä\82Ü\82·'#13#10#13#10
1119                                                                                                         + '\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
1120                                                                                                         + '\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
1121                                                                                                         + '\81u\82Í\82¢\81v\82ð\89\9f\82·\82Æ\91\97\90M\82µ\82Ü\82·',
1122                                                                                                         '\8am\94F',
1123                                                                                                         MB_ICONQUESTION or MB_YESNO);
1124                         if rc <> ID_YES then
1125                                 Exit;
1126                 end;
1127
1128                 SetNameList(NameComboBox.Text, MailComboBox.Text);
1129                 if KotehanCheckBox.Checked then begin
1130                         Board.KotehanName := NameComboBox.Text;
1131                         Board.KotehanMail := MailComboBox.Text;
1132                 end;
1133
1134                 if Board.IsBoardPlugInAvailable then begin
1135                         body := GetBody;
1136
1137                         if FThreadItem = nil then begin
1138                                 // \83X\83\8c\97§\82Ä
1139                                 state := TGikoDownloadState( Board.BoardPlugIn.CreateThread(
1140                                         DWORD( Board ), TitleEdit.Text, NameComboBox.Text, MailComboBox.Text, body ) );
1141
1142                                 if state = gdsComplete then begin
1143                                         GikoForm.PlaySound('ResEnd');
1144                                         SaveSendFile;
1145                                         GikoForm.AddMessageList(FBoard.Title + ' [\90V\83X\83\8c\91\97\90M\8fI\97¹]', nil, gmiOK);
1146                                         FWork := False;
1147                                         Close;
1148                                 end else if State = gdsError then begin
1149                                         GikoForm.AddMessageList(FBoard.Title + ' [\90V\83X\83\8c\91\97\90M\8e¸\94s]', nil, gmiNG);
1150                                 end else if State = gdsAbort then begin
1151                                         GikoForm.AddMessageList(FThreadItem.Title + ' [\92\86\92f]', nil, gmiSAD);
1152                                 end;
1153                         end else begin
1154                                 // \83\8c\83X
1155                                 state := TGikoDownloadState( FThreadItem.BoardPlugIn.WriteThread(
1156                                         DWORD( FThreadItem ), NameComboBox.Text, MailComboBox.Text, body ) );
1157
1158                                 if state = gdsComplete then begin
1159                                         GikoForm.PlaySound('ResEnd');
1160                                         SaveSendFile;
1161                                         GikoForm.AddMessageList(FThreadItem.Title + ' [\83\8c\83X\91\97\90M\8fI\97¹]', nil, gmiOK);
1162                     FWork := False;
1163                                         Close;
1164                                 end else if State = gdsError then begin
1165                                         GikoForm.AddMessageList(FThreadItem.Title + ' [\83\8c\83X\91\97\90M\8e¸\94s]', nil, gmiNG);
1166                                 end else if State = gdsAbort then begin
1167                                         GikoForm.AddMessageList(FThreadItem.Title + ' [\92\86\92f]', nil, gmiSAD);
1168                                 end;
1169                         end;
1170                 end else begin
1171                         if not Timer1.Enabled then
1172                                 Send(Board.SPID, Board.PON, True)
1173                         else begin
1174                                 if not CheckSambaTime(FHost, Now()) then begin
1175                                         rc := GikoUtil.MsgBox(Handle,
1176                                                                 '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
1177                                                                 + '\91\97\90M\82ð\92\86\8e~\82µ\82Ü\82·\82©\81H' + #13#10
1178                                                                 + '(\81u\82¢\82¢\82¦\81v\82¾\82Æ\91\97\90M\82µ\82Ü\82·)', 'Samba24\8cx\8d\90',
1179                                                                 MB_YESNO or MB_ICONQUESTION);
1180                                         if rc = IDYES then begin
1181                                                 FWork := false;
1182                                                 Exit;
1183                                         end;
1184                                 end;
1185                                 Send(Board.SPID, Board.PON, True);
1186                         end;
1187                 end;
1188         finally
1189                 FWork := False;
1190                 if Timer1.Enabled then
1191                         ReadSambaTime(FHost);
1192         end;
1193 end;
1194
1195 procedure TEditorForm.SaveActionExecute(Sender: TObject);
1196 begin
1197 //
1198 end;
1199
1200 procedure TEditorForm.CloseActionExecute(Sender: TObject);
1201 begin
1202         Close;
1203 end;
1204
1205 procedure TEditorForm.UndoActionExecute(Sender: TObject);
1206 begin
1207         SendMessage(GetActiveControlHandle, WM_UNDO, 0, 0);
1208 end;
1209
1210 procedure TEditorForm.CutActionExecute(Sender: TObject);
1211 begin
1212         SendMessage(GetActiveControlHandle, WM_CUT, 0, 0);
1213 end;
1214
1215 procedure TEditorForm.CopyActionExecute(Sender: TObject);
1216 begin
1217         SendMessage(GetActiveControlHandle, WM_COPY, 0, 0);
1218 end;
1219
1220 procedure TEditorForm.PasteActionExecute(Sender: TObject);
1221 begin
1222         SendMessage(GetActiveControlHandle, WM_PASTE, 0, 0);
1223 end;
1224
1225 procedure TEditorForm.SelectAllActionExecute(Sender: TObject);
1226 begin
1227         SendMessage(GetActiveControlHandle, EM_SETSEL, 0, GetWindowTextLength(GetActiveControlHandle));
1228 end;
1229
1230 procedure TEditorForm.TopActionExecute(Sender: TObject);     // \83E\83B\83\93\83h\83E\8dÅ\91O\96Ê(Stay)\83{\83^\83\93\82Ì\8f\88\97\9d
1231 begin
1232         if not (fsShowing in Self.FormState) then begin
1233                 if TopAction.Checked then begin // \83X\83e\83C\8fó\91Ô\82É\90Ý\92è
1234                         SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE);
1235                         GikoSys.Setting.EditWindowStay := true;
1236                 end     else begin   // \83X\83e\83C\8fó\91Ô\89ð\8f\9c
1237                         SetWindowPos(Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE);
1238                         GikoSys.Setting.EditWindowStay := false;
1239                 end;
1240                 // \83X\83e\83C\8fó\91Ô\82Ì\95Û\91
1241                 //GikoSys.Setting.EditWindowStay := FormStyle = fsStayOnTop;
1242         end;
1243 end;
1244
1245 procedure TEditorForm.AbortActionExecute(Sender: TObject);
1246 begin
1247         FAbort := True;
1248 end;
1249
1250 procedure TEditorForm.SendActionUpdate(Sender: TObject);
1251 begin
1252         SendAction.Enabled := not FWork;
1253 end;
1254
1255 procedure TEditorForm.SaveActionUpdate(Sender: TObject);
1256 begin
1257         SaveAction.Enabled := False;
1258 end;
1259
1260 procedure TEditorForm.CloseActionUpdate(Sender: TObject);
1261 begin
1262         CloseAction.Enabled := not FWork;
1263 end;
1264
1265 procedure TEditorForm.UndoActionUpdate(Sender: TObject);
1266 begin
1267         UndoAction.Enabled := (GetActiveControlHandle <> 0)
1268                                                                                                 and (SendMessage(GetActiveControlHandle, EM_CANUNDO, 0, 0) <> 0)
1269                                                                                                 and (not FWork);
1270 end;
1271
1272 procedure TEditorForm.CutActionUpdate(Sender: TObject);
1273 var
1274         Selection: TSelection;
1275         AHandle: THandle;
1276 begin
1277         AHandle := GetActiveControlHandle;
1278         SendMessage(AHandle, EM_GETSEL, Longint(@Selection.StartPos), Longint(@Selection.EndPos));
1279         CutAction.Enabled := (AHandle <> 0)
1280                                                                                 and ((Selection.EndPos - Selection.StartPos) <> 0)
1281                                                                                 and (not FWork);
1282 end;
1283
1284 procedure TEditorForm.CopyActionUpdate(Sender: TObject);
1285 var
1286         Selection: TSelection;
1287         AHandle: THandle;
1288 begin
1289         AHandle := GetActiveControlHandle;
1290         SendMessage(AHandle, EM_GETSEL, Longint(@Selection.StartPos), Longint(@Selection.EndPos));
1291         CopyAction.Enabled := (AHandle <> 0)
1292                                                                                 and ((Selection.EndPos - Selection.StartPos) <> 0)
1293                                                                                 and (not FWork);
1294 end;
1295
1296 procedure TEditorForm.PasteActionUpdate(Sender: TObject);
1297 begin
1298         PasteAction.Enabled := (GetActiveControlHandle <> 0)
1299                                                                                         and (Clipboard.HasFormat(CF_TEXT))
1300                                                                                         and (not FWork);
1301 end;
1302
1303 procedure TEditorForm.TopActionUpdate(Sender: TObject);
1304 begin
1305         TopAction.Enabled := not FWork;
1306 end;
1307
1308 procedure TEditorForm.SageCheckBoxClick(Sender: TObject);
1309 begin
1310         if SageCheckBox.Checked then begin
1311                 if AnsiPos('sage', MailComboBox.Text) = 0 then
1312                         MailComboBox.Text := 'sage' + MailComboBox.Text;
1313         end else begin
1314                 if AnsiPos('sage', MailComboBox.Text) <> 0 then
1315                         MailComboBox.Text := StringReplace(MailComboBox.Text, 'sage', '', [rfReplaceAll]);
1316         end;
1317 end;
1318
1319 procedure TEditorForm.MailComboBoxChange(Sender: TObject);
1320 begin
1321         if AnsiPos('sage', MailComboBox.Text) = 0 then
1322                 SageCheckBox.Checked := False
1323         else
1324                 SageCheckBox.Checked := True;
1325 end;
1326
1327
1328 function TEditorForm.GetSPID(CookieLine: string): string;
1329 var
1330         s: string;
1331         i: Integer;
1332 begin
1333         Result := '';
1334         i := 0;
1335         while True do begin
1336                 s := Trim(GikoSys.GetTokenIndex(CookieLine, ';', i));
1337                 if s = '' then
1338                         Break
1339                 else begin
1340                         if Pos('SPID=', s) = 1 then begin
1341                                 Result := Trim(Copy(s, 6, Length(s)));
1342                                 Break;
1343                         end;
1344                 end;
1345                 inc(i);
1346         end;
1347 end;
1348
1349 function TEditorForm.GetPON(CookieLine: string): string;
1350 var
1351         s: string;
1352         i: Integer;
1353 begin
1354         Result := '';
1355         i := 0;
1356         while True do begin
1357                 s := Trim(GikoSys.GetTokenIndex(CookieLine, ';', i));
1358                 if s = '' then
1359                         Break
1360                 else begin
1361                         if Pos('PON=', s) = 1 then begin
1362                                 Result := Trim(Copy(s, 5, Length(s)));
1363                                 Break;
1364                         end;
1365                 end;
1366                 inc(i);
1367         end;
1368 end;
1369
1370 procedure TEditorForm.IdLogDebugReceive(ASender: TIdConnectionIntercept;
1371         AStream: TStream);
1372 var
1373         StringStream: TStringStream;
1374 begin
1375         StringStream := TStringStream.Create('');
1376         try
1377                 StringStream.CopyFrom(AStream, AStream.Size);
1378                 FDebugStrReceive := FDebugStrReceive + StringStream.DataString;
1379         finally
1380                 StringStream.Free;
1381         end;
1382 end;
1383
1384 procedure TEditorForm.IdLogDebugSend(ASender: TIdConnectionIntercept;
1385         AStream: TStream);
1386 var
1387         StringStream: TStringStream;
1388 begin
1389         StringStream := TStringStream.Create('');
1390         try
1391                 StringStream.CopyFrom(AStream, AStream.Size);
1392                 FDebugStrSend := FDebugStrSend + StringStream.DataString;
1393         finally
1394                 StringStream.Free;
1395         end;
1396 end;
1397
1398 procedure TEditorForm.TransActionExecute(Sender: TObject);
1399 begin
1400         AlphaBlend := TransAction.Checked;
1401         // \94¼\93§\96¾\8fó\91Ô\82Ì\95Û\91
1402         GikoSys.Setting.EditWindowTranslucent := TransAction.Checked;
1403 end;
1404
1405 procedure TEditorForm.TransActionUpdate(Sender: TObject);
1406 begin
1407         TransAction.Enabled := not FWork;
1408 end;
1409 //StatusBar\82ÌPanels[0]\82Ì\95\9d\82ð\89Â\95Ï\81B\8ec\82è\82ð\8cÅ\92è\82É\82·\82é
1410 procedure TEditorForm.StatusBarResize(Sender: TObject);
1411 begin
1412         StatusBar.Panels[0].Width := StatusBar.Width
1413                                                                         - StatusBar.Panels[1].Width - StatusBar.Panels[2].Width;
1414
1415 end;
1416
1417 procedure TEditorForm.Timer1Timer(Sender: TObject);
1418 begin
1419         if FSambaTime = ZERO_DATE then
1420                 StatusBar.Panels[1].Text := '\8f\89\8f\91'
1421         else begin
1422                 FNow := IncMilliSecond(FNow, 500);
1423                 StatusBar.Panels[1].Text := Format('%8.0f\95b\8co\89ß', [SecondSpan(FNow, FSambaTime)]);
1424         end;
1425
1426 end;
1427 //Samba.ini\82Ì\8f\91\82«\8d\9e\82Ý\8e\9e\8aÔ\82ð\93Ç\82Ý\8d\9e\82Þ
1428 procedure TEditorForm.ReadSambaTime(const AHost: string);
1429 var
1430         ini :TMemIniFile;
1431         tmp: string;
1432 begin
1433         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
1434         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
1435         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
1436         ini := TMemIniFile.Create(GikoSys.GetSambaFileName);
1437         try
1438                  //\95\8e\9a\97ñ\82Å\93Ç\82Ý\8eæ\82Á\82Ä\81A\95Ï\8a·\8aÖ\90\94\82ÅTDateTime\82Ö
1439                  tmp := ini.ReadString('Send', AHost, DateTimeToStr(ZERO_DATE));
1440                  FSambaTime := ConvertDateTimeString(tmp);
1441         finally
1442                 ini.Free;
1443         end;
1444 end;
1445 //Samba.ini\82É\8dÅ\8fI\8f\91\82«\8d\9e\82Ý\8e\9e\8aÔ\82ð\8f\91\82«\8d\9e\82Þ
1446 procedure TEditorForm.WriteSambaTime(const AHost: string; ATime: TDateTime);
1447 var
1448         ini :TMemIniFile;
1449 begin
1450         ini := TMemIniFile.Create(GikoSys.GetSambaFileName);
1451         try
1452                 ini.WriteDateTime('Send', AHost, ATime);
1453                 ini.UpdateFile;
1454         finally
1455                 ini.Free;
1456         end;
1457 end;
1458 //\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
1459 function TEditorForm.CheckSambaTime(const AHost: string; ATime: TDateTime): Boolean;
1460 var
1461         pastsec: double;
1462         SettingTime: Integer;
1463 begin
1464         SettingTime := ReadSettingTime(AHost);
1465         ReadSambaTime(AHost);
1466         pastsec := SecondSpan(ATime, FSambaTime);
1467         if pastsec > SettingTime then
1468                 Result := true
1469         else
1470                 Result := false;
1471 end;
1472 //AHost\81i\8eI\96¼\81j\82ÌSamba\82Ì\8bK\92è\92l\82ð\93Ç\82Ý\8d\9e\82Þ
1473 function TEditorForm.ReadSettingTime(const AHost: string): Integer;
1474 var
1475         ini :TMemIniFile;
1476 begin
1477         ini := TMemIniFile.Create(GikoSys.GetSambaFileName);
1478         try
1479                 Result := ini.ReadInteger('Setting', AHost, 0);
1480                 //\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
1481                 if Result = 0 then begin
1482                         ini.WriteInteger('Setting', AHost, 0);
1483                         ini.UpdateFile;
1484                 end;
1485         finally
1486                 ini.Free;
1487         end;
1488 end;
1489 //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Þ
1490 procedure TEditorForm.FormActivate(Sender: TObject);
1491 begin
1492         if ( Timer1.Enabled ) and ( FThreadItem <> nil )then
1493                 ReadSambaTime(FHost);
1494         if GikoSys.Setting.GestureEnabled then begin
1495                 MouseGesture.UnHook;
1496                 MouseGesture.OnGestureStart := OnGestureStart;
1497                 MouseGesture.OnGestureMove := OnGestureMove;
1498                 MouseGesture.OnGestureEnd := OnGestureEnd;
1499                 MouseGesture.SetHook( Handle );
1500         end;
1501 end;
1502 //Samba24\91Î\8dô\82ð\8eg\82¤\82©\82Ç\82¤\82©\8c\88\82ß\82é\8aÖ\90\94
1503 //ReadSambaTime \82ð\8cÄ\82Ñ\8fo\82·\82ÆTimer\82ªOn\82É\82È\82é
1504 procedure TEditorForm.SetSamba24(AURL: string);
1505 var
1506         Protocol, Host, Path, Document, Port, Bookmark : string;
1507 begin
1508         //Samba24\91Î\8dô\82ð\82µ\82È\82¢\82È\82ç\8fI\97¹
1509         if not GikoSys.Setting.UseSamba then
1510                 Exit;
1511         //Host\82ÌURL\82É'.2ch.'\82©'.bbspink.'\82ª\8aÜ\82Ü\82ê\82Ä\82¢\82½\82çSamba24\91Î\8dô\82ð\82·\82é
1512         GikoSys.ParseURI( AURL, Protocol,Host, Path, Document, Port, Bookmark );
1513         if GikoSys.Is2chHost(Host) then begin
1514                 Host := Copy(Host, 1, AnsiPos('.', Host) - 1);
1515                 FHost := Host;   //FHost=\8eI\96¼
1516                 ReadSambaTime(FHost); //\88È\91O\82Ì\8f\91\82«\8d\9e\82Ý\8e\9e\8aÔ\82ð\93Ç\82Ý\8d\9e\82Þ
1517                 //StatusBar\82É\82±\82Ì\8eI\82Ì\8bK\92è\92l\82ð\95\\8e¦\82·\82é
1518                 StatusBar.Panels[2].Text := 'Samba24\8bK\92è\92l' + IntToStr(ReadSettingTime(FHost));
1519         end;
1520 end;
1521 procedure TEditorForm.FormCloseQuery(Sender: TObject;
1522   var CanClose: Boolean);
1523 begin
1524         CanClose := not FWork;
1525 end;
1526
1527 function TEditorForm.GetOEIndentChar : string;
1528 var
1529         regKey                  : TRegistry;
1530         Identities      : string;
1531         IndentChar      : DWORD;
1532 const
1533         DEFAULT_CHAR    = '> ';
1534         OE_MAIL_PATH    = '\Software\Microsoft\Outlook Express\5.0\Mail';
1535         INDENT_CHAR             = 'Indent Char';
1536 begin
1537
1538         Result  := DEFAULT_CHAR;
1539         regKey  := TRegistry.Create;
1540         try
1541                 try
1542                         regKey.RootKey  := HKEY_CURRENT_USER;
1543                         if not regKey.OpenKey( 'Identities', False ) then
1544                                 Exit;
1545                         Identities                      := regKey.ReadString( 'Default User ID' );
1546                         if Identities = '' then
1547                                 Exit;
1548                         if not regKey.OpenKey( Identities + OE_MAIL_PATH, False ) then
1549                                 Exit;
1550                         IndentChar := regKey.ReadInteger( INDENT_CHAR );
1551                         Result := Char( IndentChar ) + ' ';
1552                 except
1553                 end;
1554         finally
1555                 regKey.Free;
1556         end;
1557
1558 end;
1559
1560 procedure TEditorForm.QuotePasteActionExecute(Sender: TObject);
1561 var
1562         s                       : TStringList;
1563         i                       : Integer;
1564         quote   : string;
1565 begin
1566
1567         quote   := GetOEIndentChar;
1568         s                       := TStringList.Create;
1569         try
1570                 s.Text  := Clipboard.AsText;
1571
1572                 for i := s.Count - 1 downto 0 do
1573                         s[ i ]  := quote + s[ i ];
1574
1575                 BodyEdit.SelText        := s.Text;
1576         finally
1577                 s.Free;
1578         end;
1579
1580 end;
1581
1582 procedure TEditorForm.SpaceToNBSPActionExecute(Sender: TObject);
1583 begin
1584         GikoSys.Setting.SpaceToNBSP := SpaceToNBSPAction.Checked;
1585         if EditorPage.ActivePage = PreviewTab then
1586                 Preview;
1587 end;
1588
1589 procedure TEditorForm.AmpToCharRefActionExecute(Sender: TObject);
1590 begin
1591         GikoSys.Setting.AmpToCharRef := AmpToCharRefAction.Checked;
1592         if EditorPage.ActivePage = PreviewTab then
1593                 Preview;
1594 end;
1595
1596 procedure TEditorForm.BoardTopClick(Sender: TObject);
1597 var
1598         ini: TIniFile;
1599 begin
1600         ini := TIniFile.Create(GikoSys.Setting.GetFileName);
1601         try
1602                 BoardtopTab.TabVisible := BoardTop.Checked;
1603                 ini.WriteBool('EditorForm', 'BoardTopTab', BoardtopTab.TabVisible);
1604         finally
1605                 ini.Free;
1606         end;
1607 end;
1608
1609
1610 procedure TEditorForm.GetSETTINGTXTActionExecute(Sender: TObject);
1611 var
1612         URL, RefURL: string;
1613         settingBody: TStringList;
1614         tmpBoard: TBoard;
1615 begin
1616         InitIdHTTP(Indy);
1617         if FThreadItem = nil then
1618                 tmpBoard := FBoard
1619         else
1620                 tmpBoard := FThreadItem.ParentBoard;
1621
1622         if tmpBoard = nil then Exit;
1623
1624         RefURL  := tmpBoard.URL;
1625         if RefURL[Length(RefURL)] <> '/' then
1626                 URL     := RefURL + '/' + 'SETTING.TXT'
1627         else
1628                 URL     := RefURL + 'SETTING.TXT';
1629
1630         Indy.Request.LastModified := tmpBoard.SETTINGTXTTime;
1631         Indy.Request.Referer := RefURL;
1632         Screen.Cursor := crHourGlass;
1633         settingBody := TStringList.Create;
1634         try
1635                 StatusBar.Panels[0].Text := 'SETTING.TXT\83_\83E\83\93\83\8d\81[\83h\92\86';
1636                 try
1637                         settingBody.Text := Indy.Get(URL);
1638                         if( Indy.ResponseCode = 200 ) then begin
1639                                 settingBody.SaveToFile(tmpBoard.GetSETTINGTXTFileName);
1640                                 tmpBoard.SETTINGTXTTime := Indy.Response.LastModified;
1641                                 tmpBoard.IsSETTINGTXT := true;
1642                                 tmpBoard.TitlePictureURL := GetTitlePictureURL(settingBody, tmpBoard);
1643                                 tmpBoard.Modified := true;
1644                                 StatusBar.Panels[0].Text := 'SETTING.TXT\8eæ\93¾\8a®\97¹(' + IntToStr(Indy.ResponseCode) + ')';
1645                         end;
1646                 except
1647                         on E: EIdException do begin
1648                                 if( AnsiPos('304', E.Message) > 0 ) then
1649                                         StatusBar.Panels[0].Text := 'SETTING.TXT\8dX\90V\96³\82µ(' + IntToStr(Indy.ResponseCode) + ')'
1650                                 else
1651                                         StatusBar.Panels[0].Text := 'SETTING.TXT\8eæ\93¾\83G\83\89\81[(' + IntToStr(Indy.ResponseCode) + ')';
1652                         end;
1653                 end;
1654         finally
1655                 settingBody.Free;
1656                 Screen.Cursor := crDefault;
1657         end;
1658         ShowBoardInformation(tmpBoard, BoardInformationMemo);
1659 end;
1660
1661 procedure TEditorForm.ShowBoardInformation(ABoard: TBoard; AMemo: TMemo);
1662 var
1663         body: TStringList;
1664 begin
1665         AMemo.Clear;
1666         AMemo.Lines.Add('[SETTING.TXT]');
1667         if ABoard.IsSETTINGTXT then begin
1668                 if FileExists(ABoard.GetSETTINGTXTFileName)  then begin
1669                         AMemo.Lines.Add(DateTimeToStr(ABoard.SETTINGTXTTime) + ' \8dX\90V');
1670                         body := TStringList.Create;
1671                         try
1672                                 body.LoadFromFile(ABoard.GetSETTINGTXTFileName);
1673                                 AMemo.Lines.AddStrings(body);
1674                         finally
1675                                 body.Free;
1676                         end;
1677                 end else begin
1678                         ABoard.IsSETTINGTXT := false;
1679                         ABoard.SETTINGTXTTime := ZERO_DATE;
1680                         AMemo.Lines.Add('Local\82É\95Û\91\82³\82ê\82½SETTING.TXT\82ª\8c©\82Â\82©\82è\82Ü\82¹\82ñ');
1681                         AMemo.Lines.Add('\83\81\83j\83\85\81[\82æ\82è\8dÄ\8eæ\93¾\82µ\82Ä\82­\82¾\82³\82¢\81B');
1682                 end;
1683         end else begin
1684                 AMemo.Lines.Add('SETTING.TXT\82ð\8eæ\93¾\82µ\82Ä\82¢\82Ü\82¹\82ñ\81B');
1685                 AMemo.Lines.Add('\83\81\83j\83\85\81[\82æ\82è\8eæ\93¾\82µ\82Ä\82­\82¾\82³\82¢\81B');
1686         end;
1687 end;
1688 function TEditorForm.GetTitlePictureURL(body: TStringList; ABoard: TBoard): string;
1689 //BBS_TITLE_PICTURE=
1690 //BBS_FIGUREHEAD=
1691 var
1692         i: Integer;
1693         tmp: string;
1694 begin
1695         Result := '';
1696         for i := 0 to body.Count - 1 do begin
1697                 if (AnsiPos('BBS_TITLE_PICTURE=', body[i]) > 0) or
1698                    (AnsiPos('BBS_FIGUREHEAD=', body[i]) > 0) then begin
1699                         tmp := body[i];
1700                         Delete(tmp, 1, AnsiPos('=', tmp));
1701                         if AnsiPos('../', tmp) > 0 then begin
1702                                 tmp := CustomStringReplace(tmp, '../', GikoSys.UrlToServer(ABoard.URL));
1703                         end;
1704                         Result := tmp;
1705                         Exit;
1706                 end;
1707         end;
1708 end;
1709
1710 procedure TEditorForm.GetTitlePictureActionUpdate(Sender: TObject);
1711 begin
1712         if FThreadItem = nil then
1713                 GetTitlePictureAction.Enabled :=  FBoard.IsSETTINGTXT
1714         else
1715                 GetTitlePictureAction.Enabled :=  FThreadItem.ParentBoard.IsSETTINGTXT;
1716
1717 end;
1718
1719 procedure TEditorForm.GetTitlePictureActionExecute(Sender: TObject);
1720 var
1721         memStream: TMemoryStream;
1722         tmpBoard: TBoard;
1723 begin
1724         InitIdHTTP(Indy);
1725         memStream := TMemoryStream.Create;
1726         try
1727                 if FThreadItem = nil then
1728                         tmpBoard := FBoard
1729                 else
1730                         tmpBoard := FThreadItem.ParentBoard;
1731
1732                 Indy.Request.Referer := tmpBoard.URL;
1733                 if      tmpBoard.TitlePictureURL <> '' then begin
1734                         StatusBar.Panels[0].Text := '\94Â\83g\83b\83v\89æ\91\9c\83_\83E\83\93\83\8d\81[\83h\92\86';
1735                         Screen.Cursor := crHourGlass;
1736                         try
1737                                 Indy.Get(tmpBoard.TitlePictureURL, memStream);
1738                                 if Indy.ResponseCode = 200 then begin
1739                                         memStream.SaveToFile(tmpBoard.GetTitlePictureFileName);
1740                                         ShowTitlePicture();
1741                                         tmpBoard.Modified := true;
1742                                 end;
1743                         except
1744                         end;
1745                 end;
1746         finally
1747                 Screen.Cursor := crDefault;
1748                 StatusBar.Panels[0].Text := '\94Â\83g\83b\83v\89æ\91\9c (' + IntToStr(Indy.ResponseCode) + ')';
1749                 memStream.Free;
1750         end;
1751
1752 end;
1753 procedure TEditorForm.ShowTitlePicture();
1754 var
1755         tmpBoard: TBoard;
1756         s: String;
1757 begin
1758         if FThreadItem = nil then
1759                 tmpBoard := FBoard
1760         else
1761                 tmpBoard := FThreadItem.ParentBoard;
1762
1763         if FileExists(tmpBoard.GetTitlePictureFileName) then begin
1764                 TitlePictureBrowser.Navigate(tmpBoard.GetTitlePictureFileName);
1765         end else begin
1766                 s := '\94Â\83g\83b\83v\89æ\91\9c\96¢\8eæ\93¾\82Å\82·\81B<br>\83\81\83j\83\85\81[\82æ\82è\8eæ\93¾\82µ\82Ä\82­\82¾\82³\82¢\81B';
1767                 SetContent(s, TitlePictureBrowser);
1768         end;
1769 end;
1770
1771 function TEditorForm.GetFusianaName(body: TStringList; ABoard: TBoard): String;
1772 var
1773         i: Integer;
1774         tmp: string;
1775 begin
1776         for i := 0 to body.Count - 1 do begin
1777                 if (AnsiPos('BBS_NONAME_NAME=', body[i]) > 0) then begin
1778                         tmp := body[i];
1779                         Delete(tmp, 1, AnsiPos('=', tmp));
1780                         Result := tmp;
1781                         Exit;
1782                 end;
1783         end;
1784 end;
1785
1786 procedure TEditorForm.GetHeadTXTActionExecute(Sender: TObject);
1787 var
1788         URL, RefURL: string;
1789         settingBody: TStringList;
1790         tmpBoard: TBoard;
1791 begin
1792         InitIdHTTP(Indy);
1793         if FThreadItem = nil then
1794                 tmpBoard := FBoard
1795         else
1796                 tmpBoard := FThreadItem.ParentBoard;
1797
1798         if tmpBoard = nil then Exit;
1799
1800         RefURL  := tmpBoard.URL;
1801         if RefURL[Length(RefURL)] <> '/' then
1802                 URL     := RefURL + '/' + 'head.txt'
1803         else
1804                 URL     := RefURL + 'head.txt';
1805
1806         if FileExists(tmpBoard.GETHEADTXTFileName) then
1807                 Indy.Request.LastModified := tmpBoard.HEADTXTTime
1808         else
1809                 Indy.Request.LastModified := ZERO_DATE;
1810
1811         Indy.Request.Referer := RefURL;
1812         Screen.Cursor := crHourGlass;
1813         settingBody := TStringList.Create;
1814         try
1815                 StatusBar.Panels[0].Text := '\83\8d\81[\83J\83\8b\83\8b\81[\83\8b(head.txt)\83_\83E\83\93\83\8d\81[\83h\92\86';
1816                 try
1817                         settingBody.Text := Indy.Get(URL);
1818                         if( Indy.ResponseCode = 200 ) then begin
1819                                 settingBody.Insert(0, '<HTML lang="ja"><HEAD>');
1820                                 settingBody.Insert(1, '<META http-equiv="Content-Type" content="text/html; charset=Shift_JIS">');
1821                                 settingBody.Insert(2, '<TITLE>' + tmpBoard.Title + '</TITLE>');
1822                                 settingBody.Insert(3, '<base href="' + RefURL + '"></HEAD><BODY>');
1823                                 settingBody.Add('</BODY></HTML>');
1824                                 settingBody.SaveToFile(tmpBoard.GETHEADTXTFileName);
1825                                 tmpBoard.HEADTXTTime := Indy.Response.LastModified;
1826                                 tmpBoard.IsHEADTXT := true;
1827                                 tmpBoard.Modified := true;
1828                                 StatusBar.Panels[0].Text := '\83\8d\81[\83J\83\8b\83\8b\81[\83\8b\8eæ\93¾\8a®\97¹(' + IntToStr(Indy.ResponseCode) + ')';
1829                         end;
1830                 except
1831                         on E: EIdException do begin
1832                                 if( AnsiPos('304', E.Message) > 0 ) then
1833                                         StatusBar.Panels[0].Text := '\83\8d\81[\83J\83\8b\83\8b\81[\83\8b\8dX\90V\96³\82µ(' + IntToStr(Indy.ResponseCode) + ')'
1834                                 else
1835                                         StatusBar.Panels[0].Text := '\83\8d\81[\83J\83\8b\83\8b\81[\83\8b\8eæ\93¾\83G\83\89\81[(' + IntToStr(Indy.ResponseCode) + ')';
1836                         end;
1837                 end;
1838         finally
1839                 settingBody.Free;
1840                 Screen.Cursor := crDefault;
1841         end;
1842         if tmpBoard.IsHEADTXT then begin
1843                 ShowBoardHead(tmpboard, LocalEdit);
1844         end;
1845
1846 end;
1847
1848 procedure TEditorForm.CalcCapasityActionExecute(Sender: TObject);
1849 var
1850         body: String;
1851 begin
1852         body := GetBody;
1853         StatusBar.Panels[0].Text := '\97e\97Ê:' + IntToStr(Length(body)) + ' byte';
1854 end;
1855
1856 procedure TEditorForm.LocalRuleClick(Sender: TObject);
1857 var
1858   ini: TIniFile;
1859 begin
1860         ini := TIniFile.Create(GikoSys.Setting.GetFileName);
1861         try
1862                 RocalRuleTab.TabVisible := LocalRule.Checked;
1863                 ini.WriteBool('EditorForm', 'LocalRuleTab', RocalRuleTab.TabVisible);
1864         finally
1865                 ini.Free;
1866         end;
1867 end;
1868
1869 procedure TEditorForm.FormDeactivate(Sender: TObject);
1870 begin
1871         if GikoSys.Setting.GestureEnabled then begin
1872                 MouseGesture.UnHook;
1873                 MouseGesture.SetHook( GikoForm.Handle );
1874         end;
1875 end;
1876
1877 procedure TEditorForm.OnGestureStart(Sender: TObject);
1878 begin
1879 //
1880 end;
1881
1882 procedure TEditorForm.OnGestureMove(Sender: TObject);
1883 var
1884         s: string;
1885         Action: TAction;
1886         ActStr: string;
1887 begin
1888         s := MouseGesture.GetGestureStr;
1889         ActStr := '';
1890         Action := FGestures.GetGestureAction(s);
1891         if Action <> nil then
1892                 ActStr := '\81i' + Action.Caption + '\81j';
1893         s := '\83W\83F\83X\83`\83\83\81[: ' + s + ActStr;
1894         StatusBar.Panels[0].Text := s;
1895 end;
1896
1897 procedure TEditorForm.OnGestureEnd(Sender: TObject);
1898 var
1899         s: string;
1900         Action: TAction;
1901 begin
1902         s := MouseGesture.GetGestureStr;
1903         Action := FGestures.GetGestureAction(s);
1904         if Action <> nil then
1905                 Action.Execute;
1906         StatusBar.Panels[0].Text := '';
1907 end;
1908
1909 procedure TEditorForm.ShowBoardHead(ABoard: TBoard; AMemo: TMemo);
1910 var
1911         wDoc, WTex, le: OLEVariant;
1912 begin
1913                 //\8eQ\8dl\8c³
1914                 //http://www.campus.ne.jp/~ishigami/CREATION/TECHNIC/WEBAP-2.htm
1915                 WebBrowser1.Navigate(ABoard.GETHEADTXTFileName,le,le,le,le);
1916                 //\83\8c\83^\83\8a\83\93\83O\82ª\92x\82·\82¬\82ÄTXT\82É\88Ú\82¹\82È\82¢\81B\82Ê\82é\82Ûorz
1917                 //\89º\82Ì\82æ\82¤\82É\82¿\82á\82ñ\82Æ\93Ç\82Ý\8d\9e\82Ý\82ª\8fI\82í\82Á\82Ä\82¢\82é\82©\81A\83`\83F\83b\83N\82·\82ê\82Î\82¢\82¢\82ñ\82¾\82æ\81B
1918                 //\82±\82ê\82Å\82¢\82¯\82Ü\82µ\82½\81B\82 \82è\82ª\82Æ\82¤\82²\82´\82¢\82Ü\82µ\82½\81B
1919                 while (WebBrowser1.ReadyState <> READYSTATE_COMPLETE) and
1920                                 (WebBrowser1.ReadyState <> READYSTATE_INTERACTIVE) do begin
1921                         Application.ProcessMessages;
1922                 end;
1923                 wDoc := WebBrowser1.Document;
1924                 wTex := wDoc.body.createTextRange;
1925                 LocalEdit.Text := wTex.text;
1926 end;
1927
1928 end.