OSDN Git Service

レスエディタのコンストラクタの中から処理をメソッド化。
[gikonavigoeson/gikonavi.git] / Editor.pas
1 unit Editor;
2
3 interface
4
5 uses
6         Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
7         Dialogs, StdCtrls, ComCtrls, ExtCtrls, ToolWin, Menus, OleCtrls, Registry,
8 {$IF Defined(DELPRO) }
9         SHDocVw,
10         MSHTML,
11 {$ELSE}
12         SHDocVw_TLB,
13         MSHTML_TLB,
14 {$IFEND}
15         ActiveX, {HTTPApp,} YofUtils, 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,  bmRegExp,
20         Gesture, AppEvnts, SambaTimer;
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                 NameBasePanel: TPanel;
48                 NameLabel: TLabel;
49                 MailLabel: TLabel;
50                 NameComboBox: TComboBox;
51                 MailComboBox: TComboBox;
52                 ToolBar: TToolBar;
53                 SendToolButton: TToolButton;
54                 OutBoxToolButton: TToolButton;
55                 ToolButton5: TToolButton;
56                 UndoToolButton: TToolButton;
57                 CutToolButton: TToolButton;
58                 CopyToolButton: TToolButton;
59                 PasteToolButton: TToolButton;
60                 ToolButton3: TToolButton;
61                 TransToolButton: TToolButton;
62                 TopToolButton: TToolButton;
63                 Indy: TIdHTTP;
64                 IdAntiFreeze: TIdAntiFreeze;
65                 ToolButton1: TToolButton;
66                 ToolButton2: TToolButton;
67                 ActionList: TActionList;
68                 SendAction: TAction;
69                 SaveAction: TAction;
70                 CloseAction: TAction;
71                 UndoAction: TAction;
72                 CutAction: TAction;
73                 CopyAction: TAction;
74                 PasteAction: TAction;
75                 AbortAction: TAction;
76                 TopAction: TAction;
77                 Show1: TMenuItem;
78                 T1: TMenuItem;
79                 N1: TMenuItem;
80                 S1: TMenuItem;
81                 SageCheckBox: TCheckBox;
82                 IdLogDebug: TIdLogDebug;
83                 TransAction: TAction;
84                 A1: TMenuItem;
85                 KotehanCheckBox: TCheckBox;
86                 TitlePanel: TPanel;
87                 Label1: TLabel;
88                 TitleEdit: TEdit;
89                 SelectAllAction: TAction;
90                 N2: TMenuItem;
91                 SelectAll1: TMenuItem;
92         QuotePasteAction: TAction;
93         QuotePasteMenuItem: TMenuItem;
94         C1: TMenuItem;
95         SpaceToNBSPAction: TAction;
96         AmpToCharRefAction: TAction;
97         SpaceTabnbsp1: TMenuItem;
98         amp1: TMenuItem;
99         BoardInformationTab: TTabSheet;
100                                 BoardtopTab: TTabSheet;
101         TitlePictureBrowser: TWebBrowser;
102         BoardTop: TMenuItem;
103         BoardInformationMemo: TMemo;
104         GetSETTINGTXTAction: TAction;
105         N3: TMenuItem;
106         SETTINGTXT2: TMenuItem;
107         GetTitlePictureAction: TAction;
108         OP1: TMenuItem;
109     GetHeadTXTAction: TAction;
110     HeadTXT1: TMenuItem;
111     RocalRuleTab: TTabSheet;
112     WebBrowser1: TWebBrowser;
113     CalcCapacityAction: TAction;
114     N4: TMenuItem;
115     N5: TMenuItem;
116     LocalRule: TMenuItem;
117     LocalEdit: TMemo;
118     N6: TMenuItem;
119     LocalRuleBrowse: TMenuItem;
120         ToolButton4: TToolButton;
121     ToolButton6: TToolButton;
122     SaveNameMailAction: TAction;
123     ToolButton7: TToolButton;
124     BeLogInOutEAction: TAction;
125     UpdateSambaAction: TAction;
126     Samba241: TMenuItem;
127     N7: TMenuItem;
128     InputAssistAction: TAction;
129     InputAssistPopupMenu: TPopupMenu;
130     BodyEdit: TMemo;
131     ApplicationEvents1: TApplicationEvents;
132     ToolButton8: TToolButton;
133     ToolButton9: TToolButton;
134     ShowInputAssistForm: TAction;
135     ReleaseCookieAction: TAction;
136     Cookie1: TMenuItem;
137
138                 procedure EditorPageChange(Sender: TObject);
139                 procedure FormCreate(Sender: TObject);
140                 procedure BrowserStatusTextChange(Sender: TObject;
141                         const Text: WideString);
142                 procedure FormClose(Sender: TObject; var Action: TCloseAction);
143                 procedure FormDestroy(Sender: TObject);
144                 procedure SendActionExecute(Sender: TObject);
145                 procedure SaveActionExecute(Sender: TObject);
146                 procedure AbortActionExecute(Sender: TObject);
147                 procedure CloseActionExecute(Sender: TObject);
148                 procedure UndoActionExecute(Sender: TObject);
149                 procedure CutActionExecute(Sender: TObject);
150                 procedure CopyActionExecute(Sender: TObject);
151                 procedure PasteActionExecute(Sender: TObject);
152                 procedure SendActionUpdate(Sender: TObject);
153                 procedure SaveActionUpdate(Sender: TObject);
154                 procedure CloseActionUpdate(Sender: TObject);
155                 procedure UndoActionUpdate(Sender: TObject);
156                 procedure CutActionUpdate(Sender: TObject);
157                 procedure CopyActionUpdate(Sender: TObject);
158                 procedure PasteActionUpdate(Sender: TObject);
159                 procedure TopActionExecute(Sender: TObject);
160                 procedure TopActionUpdate(Sender: TObject);
161                 procedure SageCheckBoxClick(Sender: TObject);
162                 procedure MailComboBoxChange(Sender: TObject);
163                 procedure TransActionExecute(Sender: TObject);
164                 procedure TransActionUpdate(Sender: TObject);
165                 procedure IdLogDebugReceive(ASender: TIdConnectionIntercept;
166                         AStream: TStream);
167                 procedure IdLogDebugSend(ASender: TIdConnectionIntercept;
168                         AStream: TStream);
169                 procedure SelectAllActionExecute(Sender: TObject);
170         procedure StatusBarResize(Sender: TObject);
171         procedure FormActivate(Sender: TObject);
172         procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
173                 procedure QuotePasteActionExecute(Sender: TObject);
174         procedure SpaceToNBSPActionExecute(Sender: TObject);
175         procedure AmpToCharRefActionExecute(Sender: TObject);
176         procedure BoardTopClick(Sender: TObject);
177         procedure GetSETTINGTXTActionExecute(Sender: TObject);
178         procedure GetTitlePictureActionUpdate(Sender: TObject);
179         procedure GetTitlePictureActionExecute(Sender: TObject);
180     procedure GetHeadTXTActionExecute(Sender: TObject);
181         procedure CalcCapacityActionExecute(Sender: TObject);
182     procedure LocalRuleClick(Sender: TObject);
183     procedure FormDeactivate(Sender: TObject);
184     procedure LocalRuleBrowseClick(Sender: TObject);
185     procedure SaveNameMailActionExecute(Sender: TObject);
186     procedure BeLogInOutEActionExecute(Sender: TObject);
187     procedure BeLogInOutEActionUpdate(Sender: TObject);
188     procedure UpdateSambaActionUpdate(Sender: TObject);
189     procedure UpdateSambaActionExecute(Sender: TObject);
190     procedure InputAssistActionExecute(Sender: TObject);
191     procedure ApplicationEvents1Message(var Msg: tagMSG;
192       var Handled: Boolean);
193     procedure ShowInputAssistFormExecute(Sender: TObject);
194     procedure ReleaseCookieActionExecute(Sender: TObject);
195     procedure GetSETTINGTXTActionUpdate(Sender: TObject);
196     procedure GetHeadTXTActionUpdate(Sender: TObject);
197         private
198                 FThreadItem: TThreadItem;
199                 FBoard: TBoard;
200                 FNameComboEdit: THandle;
201                 FMailComboEdit: THandle;
202                 FAbort: Boolean;
203                 FWork: Boolean;
204                 FStatusCode: Integer;
205                 FDebugStrReceive: string;
206                 FDebugStrSend: string;
207                 FNow: TDateTime;
208                 FGestures       : TMouseGesture;
209                 FInputAssistKey: String;        ///< \93ü\97Í\83A\83V\83X\83g\82Ì\83L\81[
210                 FResistWords: TStringList;      ///< \93ü\97Í\83A\83V\83X\83g\82Ì\8e«\8f\91\82©\82ç\82Ì\8c\9f\8dõ\8c\8b\89Ê
211         FSambaTimer: TSambaTimer;   ///< Samba\91Î\8dô\82Ì\83^\83C\83}\81[
212                 procedure Preview;
213                 function Check: Boolean;
214                 procedure SetNameList(sName, sMail: string);
215                 procedure Send(ACOOKIE: string; SPID: string; PON: string; FirstWriting: Boolean);
216                 function GetActiveControlHandle: THandle;
217                 procedure GetSendData(Source: TStringStream);
218                 procedure SaveSendFile;
219                 procedure SetContent(Content: string; ABrowser: TWebBrowser);
220                 function GetResultType(ResponseText: string): TGikoResultType;
221                 /// \96{\95\82Ì\8eæ\93¾
222                 function GetBody : string;
223                 //IdHttp\82Ì\8f\89\8aú\89»
224                 procedure InitIdHTTP(http: TIdHTTP);
225                 procedure ShowBoardInformation(ABoard: TBoard; AMemo: TMemo);
226                 function GetTitlePictureURL(body: TStringList; ABoard: TBoard): string;
227                 procedure ShowTitlePicture();
228                                 function GetFusianaName(body: TStringList; ABoard: TBoard): String;
229                 //! \83}\83E\83X\83W\83F\83X\83`\83\83\81[\8aJ\8en
230                 procedure OnGestureStart(Sender: TObject);
231                 //! \83}\83E\83X\83W\83F\83X\83`\83\83\81[\92\86
232                 procedure OnGestureMove(Sender: TObject);
233                 //! \83}\83E\83X\83W\83F\83X\83`\83\83\81[\8fI\97¹
234                 procedure OnGestureEnd(Sender: TObject);
235                                 //HEAD.TXT\8e©\93®\95\\8e¦
236                                 procedure ShowBoardHead(ABoard: TBoard; AMemo: TMemo);
237                                 //LocalFusianaTrapAlart
238                                 function LFusianaGet(s: String): Boolean;
239                 // Cookie\82Ì\8eæ\93¾
240                 procedure GetCookie(Rawtext: String; ABoard: TBoard);
241                 //! \93ü\97Í\83A\83V\83X\83g\82Ì\83|\83b\83v\83A\83b\83v\83\81\83j\83\85\81[\82Ì\83N\83\8a\83b\83N\83C\83x\83\93\83g
242                 procedure InputAssistMenuClick(Sender: TObject);
243                 //! TMemo\82Ì\83J\81[\83\\83\8b\88Ê\92u\82É\95\8e\9a\97ñ\91}\93ü
244                 procedure InsertText(Memo: TMemo; Text: String);
245                 //! \91\97\90M\92\86\8e~
246                 procedure CancelSend(ABoard: TBoard; ASysMenu: HMENU);
247         //! Samba\83^\83C\83}\81[\83C\83x\83\93\83g
248         procedure SambaTimer(Sender: TObject);
249         //! \83E\83B\83\93\83h\83E\82Ì\88Ê\92u\82Æ\83T\83C\83Y\82Ì\90Ý\92è
250         procedure SetWindowRect;
251         //! \8ag\92£\83^\83u\90Ý\92è
252         procedure SetExtraTab;
253         protected
254                 procedure CreateParams(var Params: TCreateParams); override;
255         public
256                 FBBSID: String;
257                 procedure SetFont;
258                 procedure SetThreadItem(Item: TThreadItem);
259                 procedure SetBoard(Item: TBoard);
260         procedure UpdateSambaStatus;
261                 property BBSID: string read FBBSID write FBBSID;
262         end;
263
264 implementation
265
266 uses
267         Giko, ItemDownload, MojuUtils, IdGlobal, GikoMessage,  Imm,
268   InputAssistDataModule, InputAssist, HTMLCreate;
269 const
270         CAPTION_NAME_NEW: string = '\83M\83R\83i\83\83X\83\8c\97§\82Ä\83G\83f\83B\83^';
271         CAPTION_NAME_RES: string = '\83M\83R\83i\83\83\8c\83X\83G\83f\83B\83^';
272
273         // \83G\83f\83B\83b\83g\83E\83B\83\93\83h\83E\82ð\89E\89º\82É\82¸\82ç\82µ\82Ä\8aJ\82­\88Ú\93®\97Ê
274         WINDOWMOVE_H = 30;
275         WINDOWMOVE_V = 30;
276
277         //DAX\82³\82ñ±Ø¶ÞÄ!(\81L\81¤\81M)
278         READCGI_ERR                     = '-ERR';
279         READCGI_INCR            = '-INCR';
280         READCGI_OK                      = '+OK';
281         READCGI_PARTIAL = '+PARTIAL';
282         READCGI_ERR_FOUND_KAKO  = '-ERR \89ß\8b\8e\83\8d\83O\91q\8cÉ\82Å\94­\8c©';
283         READCGI_ERR_NOT_HTML            = '-ERR html\89»\91Ò\82¿';
284         READCGI_ERR_NOT_FOUND           = '-ERR \82»\82ñ\82È\94Âor\83X\83\8c\83b\83h\82È\82¢\82Å\82·\81B';
285         READCGI_ERR_ABONE                               = '-ERR \82Ç\82±\82©\82Å\82 \82Ú\81[\82ñ\82ª\82 \82Á\82½\82Ý\82½\82¢\82Å\82·\81B';
286         READCGI_ERR_TIMEOUT                     = '-ERR \8ew\92è\8e\9e\8aÔ\82ª\89ß\82¬\82Ü\82µ\82½\81B';
287         READCGI_ERR_CANTUSE                     = '-ERR \82à\82¤\81@\82Â\82©\82¦\82Ü\82¹\82ñ';
288         RES2CH_TRUE                             = '<!-- 2ch_X:true -->';
289         RES2CH_FALSE                    = '<!-- 2ch_X:false -->';
290         RES2CH_ERROR                    = '<!-- 2ch_X:error -->';
291         RES2CH_CHECK                    = '<!-- 2ch_X:check -->';
292         RES2CH_COOKIE                   = '<!-- 2ch_X:cookie -->';
293
294 type
295         TSelection = record
296                 StartPos, EndPos: Integer;
297         end;
298
299 {$R *.DFM}
300
301 {constructor TEditorForm.Create(AOwner: TComponent; Item: TBoard);
302 begin
303         inherited Create(AOwner);
304 end;}
305
306 procedure TEditorForm.CreateParams(var Params: TCreateParams);
307 begin
308         inherited;
309         if FormStyle in [fsNormal, fsStayOnTop] then
310                 if BorderStyle in [bsSingle, bsSizeable] then begin
311                         Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
312                         Params.WndParent := 0;
313                 end;
314 end;
315
316 {procedure TEditorForm.CreateParams(var Params: TCreateParams);
317 begin
318         inherited CreateParams(Params);
319         Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
320 end;}
321
322 procedure TEditorForm.FormCreate(Sender: TObject);
323 begin
324         FWork := False;
325     FSambaTimer := TSambaTimer.Create(Self);
326     FSambaTimer.Interval := 0;
327         Browser.Navigate('about:blank');
328         TitlePictureBrowser.Navigate('about:blank');
329         FBoard := nil;
330         FThreadItem := nil;
331
332         //\83E\83B\83\93\83h\83E\82Ì\88Ê\92u\90Ý\92è
333     SetWindowRect;
334
335         EditorPage.ActivePage := EditorTab;
336         FNameComboEdit := GetWindow(NameComboBox.Handle, GW_CHILD);
337         FMailComboEdit := GetWindow(MailComboBox.Handle, GW_CHILD);
338         NameComboBox.Items.Assign(GikoSys.Setting.NameList);
339         MailComboBox.Items.Assign(GikoSys.Setting.MailList);
340         SetFont;
341     // \94¼\93§\96¾\97\98\97p\89Â\94\\90Ý\92è
342     TransAction.Enabled := GikoSys.CanUser32DLL;
343
344     // \83E\83B\83\93\83h\83E\82Ì\83X\83e\83C\8fó\91Ô
345         if GikoSys.Setting.EditWindowStay then begin    // \83X\83e\83C\8fó\91Ô
346                 SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE);
347                 TopAction.Checked := true;
348                 TopToolButton.Down := true;
349         end else begin                                  // \83X\83e\83C\82µ\82È\82¢
350                 SetWindowPos(Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE);
351                 TopAction.Checked := false;
352                 TopToolButton.Down := false;
353         end;
354
355     // \83E\83B\83\93\83h\83E\82Ì\94¼\93§\96¾\8fó\91Ô
356         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Ô
357         AlphaBlend := true;
358         TransAction.Checked := true;
359         TransToolButton.Down := true;
360     end else begin                                      // \95s\93§\96¾
361         AlphaBlend := false;
362         TransAction.Checked := false;
363         TransToolButton.Down := false;
364     end;
365         // \94¼\93§\96¾\8fó\91Ô\82Ì\95Û\91
366         GikoSys.Setting.EditWindowTranslucent := TransAction.Checked;
367
368         SpaceToNBSPAction.Checked               := GikoSys.Setting.SpaceToNBSP;
369         AmpToCharRefAction.Checked      := GikoSys.Setting.AmpToCharRef;
370     // \83\8d\81[\83J\83\8b\83\8b\81[\83\8b\81{\94Â\83g\83b\83v\89æ\91\9c\82Ì\83^\83u\82Ì\90Ý\92è
371     SetExtraTab;
372
373         // \83L\81[\90Ý\92è\82Ì\93Ç\82Ý\8d\9e\82Ý
374         GikoSys.LoadKeySetting(ActionList, GikoSys.GetEditorKeyFileName);
375         // \83}\83E\83X\83W\83F\83X\83`\83\83\81[\82Ì\83C\83\93\83X\83g\81[\83\8b
376         if GikoSys.Setting.GestureEnabled then begin
377                 MouseGesture.UnHook;
378                 FGestures := TMouseGesture.Create;
379                 GikoSys.Setting.Gestures.ClearGesture;
380
381                 GikoSys.Setting.Gestures.LoadGesture(
382                         GikoSys.Setting.GetGestureFileName, ActionList );
383                 MouseGesture.OnGestureStart := OnGestureStart;
384                 MouseGesture.OnGestureMove := OnGestureMove;
385                 MouseGesture.OnGestureEnd := OnGestureEnd;
386                 MouseGesture.SetHook( Handle );
387         end;
388         SaveNameMailAction.Checked := True;
389 end;
390 procedure TEditorForm.SetBoard(Item: TBoard);
391 begin
392         FBoard := Item;
393         Caption := CAPTION_NAME_NEW + ' - [' + Item.Title + ']';
394         NameComboBox.Text := FBoard.KotehanName;
395         MailComboBox.Text := FBoard.KotehanMail;
396         SageCheckBox.Checked := AnsiPos('sage', MailComboBox.Text) <> 0;
397         TitlePanel.Visible := True;
398
399     if (FSambaTimer.SetBoard(FBoard) >= 0) then begin
400         UpdateSambaStatus;
401         FNow := Now();
402         FSambaTimer.OnTimer := SambaTimer;
403     end;
404
405         ShowBoardInformation(FBoard, BoardInformationMemo);
406         ShowTitlePicture();
407 end;
408
409 procedure TEditorForm.SetThreadItem(Item: TThreadItem);
410 begin
411         FThreadItem := Item;
412         Caption := CAPTION_NAME_RES + ' - [' + FThreadItem.Title + ']';
413         NameComboBox.Text := FThreadItem.ParentBoard.KotehanName;
414         MailComboBox.Text := FThreadItem.ParentBoard.KotehanMail;
415         SageCheckBox.Checked := AnsiPos('sage', MailComboBox.Text) <> 0;
416         TitlePanel.Visible := False;
417
418     if (FSambaTimer.SetBoard(FThreadItem.ParentBoard) >= 0) then begin
419         UpdateSambaStatus;
420         FNow := Now();
421         FSambaTimer.OnTimer := SambaTimer;
422     end;
423
424         ShowBoardInformation(FThreadItem.ParentBoard, BoardInformationMemo);
425         ShowTitlePicture();
426 end;
427
428 function TEditorForm.GetBody : string;
429 var
430         body, tmp               : string;
431         p, tail                 : PChar;
432         len                                     : Integer;
433 const
434         TAB_LENGTH      = 4;
435 begin
436
437         body := BodyEdit.Text;
438         if AmpToCharRefAction.Checked then
439                 // & \82Ì\92u\8a·\82Í\88ê\94Ô\8dÅ\8f\89\82É\82â\82é\82±\82Æ
440                 body := CustomStringReplace( body, '&', '&amp;' );
441         if SpaceToNBSPAction.Checked then begin
442                 p                       := PChar( body );
443                 tail    := p + Length( body );
444                 len             := 0;
445                 while p < tail do begin
446                         case p^ of
447                         #09:
448                                 begin
449                                         Inc( p );
450                                         repeat
451                                                 Inc( len );
452                                                 tmp := tmp + '&nbsp;';
453                                         until (len mod TAB_LENGTH) = 0;
454                                 end;
455
456                         #10, #13:
457                                 begin
458                                         tmp := tmp + p^;        Inc( p );
459                                         len     := 0;
460                                 end;
461
462                         ' ':
463                                 begin
464                                         tmp     := tmp + '&nbsp;';
465                                         Inc( p );
466                                         Inc( len );
467                                 end;
468                                 
469                         '&':
470                                 // \8eÀ\91Ì\8eQ\8fÆ\82Í 1 \95\8e\9a\95ª
471                                 begin
472                                         tmp := tmp + '&';
473                                         Inc( p );
474                                         Inc( len );
475                                         while p < tail do begin
476                                                 if p^ in ['a'..'z', 'A'..'Z', '0'..'9', '#'] then begin
477                                                         tmp := tmp + p^;
478                                                 end else if p^ = ';' then begin
479                                                         tmp := tmp + p^;
480                                                         Inc( p );
481                                                         Break;
482                                                 end else begin
483                                                         Break;
484                                                 end;
485                                                 Inc( p );
486                                         end;
487                                 end;
488
489                         else
490                                 if p^ in kYofKanji then begin
491                                         tmp := tmp + p^;        Inc( p );
492                                         tmp     := tmp + p^;    Inc( p );
493                                         len     := len + 2;
494                                 end else begin
495                                         tmp := tmp + p^;        Inc( p );
496                                         Inc( len );
497                                 end;
498                         end;
499                 end;
500                 body := tmp;
501         end;
502
503         Result  := body;
504
505 end;
506
507 procedure TEditorForm.SetFont;
508 begin
509         BodyEdit.Font.Name := GikoSys.Setting.EditorFontName;
510         BodyEdit.Font.Size := GikoSys.Setting.EditorFontSize;
511         BodyEdit.Font.Color := GikoSys.Setting.EditorFontColor;
512         BodyEdit.Color := GikoSys.Setting.EditorBackColor;
513 end;
514
515 procedure TEditorForm.Preview;
516 var
517         Title: string;
518         No: string;
519         Mail: string;
520         Namae: string;
521         Body: string;
522         s: string;
523 begin
524         if FThreadItem = nil then begin
525                 No := '1';
526                 Title := THTMLCreate.RepHtml(TitleEdit.Text);
527         end else begin
528                 No := IntToStr(FThreadItem.Count + 1);
529                 Title := THTMLCreate.RepHtml(FThreadItem.Title);
530         end;
531
532         Body := GetBody;
533         Namae := THTMLCreate.RepHtml(NameComboBox.Text);
534         Mail := THTMLCreate.RepHtml(MailComboBox.Text);
535         Body := THTMLCreate.RepHtml(Body);
536         Body := CustomStringReplace(Body, #13#10, '<br>', False);
537
538
539         if Trim(Namae) = '' then
540                 Namae := '\96¼\96³\82µ\82³\82ñ';
541
542     s := THTMLCreate.CreatePreviewHTML(Title, No, Mail, Namae, Body);
543     
544         SetContent(s, Browser);
545 end;
546
547 procedure TEditorForm.EditorPageChange(Sender: TObject);
548 var
549         tmpBoard: TBoard;
550 begin
551         if FThreadItem = nil then
552                 tmpBoard := FBoard
553         else
554                 tmpBoard := FThreadItem.ParentBoard;
555
556         if tmpBoard = nil then Exit;
557
558         if EditorPage.ActivePage = PreviewTab then begin
559                 Preview;
560         end else if EditorPage.ActivePage = RocalRuleTab then begin
561                 if not FileExists(tmpBoard.GETHEADTXTFileName) then begin
562                         LocalEdit.Text := '\83\8d\81[\83J\83\8b\83\8b\81[\83\8b\96¢\8eæ\93¾';
563                         Exit;
564                 end;
565                 ShowBoardHead(tmpBoard, LocalEdit);
566         end else begin
567                 Browser.Navigate('about:blank');
568         end;
569 end;
570
571 procedure TEditorForm.BrowserStatusTextChange(Sender: TObject;
572         const Text: WideString);
573 begin
574         if EditorPage.ActivePage = PreviewTab then begin
575                 StatusBar.Panels[0].Text := Text;
576         end else begin
577                 StatusBar.Panels[0].Text := '';
578         end;
579 end;
580
581 function TEditorForm.Check: Boolean;
582 const
583         REQUIRED: string = '\82ª\93ü\97Í\82³\82ê\82Ä\82¢\82Ü\82¹\82ñ\81B';
584         ERROR: string = '\83G\83\89\81[';
585 var
586         Msg: string;
587         rc: Integer;
588         Board: TBoard;
589 begin
590         Result := True;
591         if FThreadItem = nil then
592                 Board := FBoard
593         else
594                 Board := FThreadItem.ParentBoard;
595
596         if (not GikoSys.Setting.UseMachineTime) and
597                  ((Board.LastGetTime = 0) or
598                         (Board.LastGetTime = ZERO_DATE)) then begin
599                 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
600                                  + '\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¢';
601                 MsgBox(Handle, Msg, ERROR, MB_OK or MB_ICONSTOP);
602                 Result := False;
603         end else if BodyEdit.Text = '' then begin
604                 Msg := '\96{\95¶' + REQUIRED;
605                 MsgBox(Handle, Msg, ERROR, MB_OK or MB_ICONSTOP);
606                 Result := False;
607         end else if (FBoard <> nil) and (Trim(TitleEdit.Text) = '') then begin
608                 Msg := '\83^\83C\83g\83\8b' + REQUIRED;
609                 MsgBox(Handle, Msg, ERROR, MB_OK or MB_ICONSTOP);
610                 Result := False;
611         end else begin
612                 if (not GikoSys.Dolib.Connected) and (AnsiPos('\81\9c', NameComboBox.Text) <> 0) then begin
613                         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
614                                          + '\82±\82Ì\82Ü\82Ü\91\97\90M\82µ\82Ä\82à\82æ\82ë\82µ\82¢\82Å\82·\82©\81H';
615                         rc := MsgBox(Handle, Msg, '\8am\94F', MB_YESNO or MB_ICONQUESTION);
616                         Result := (rc = IDYES);
617                 end;
618         end;
619 end;
620
621 procedure TEditorForm.FormClose(Sender: TObject; var Action: TCloseAction);
622 begin
623         Action := caFree;
624     FSambaTimer.Free;
625 end;
626
627 procedure TEditorForm.FormDestroy(Sender: TObject);
628 var
629         wp: TWindowPlacement;
630 begin
631         //\8dÅ\91å\89»\81E\83E\83B\83\93\83h\83E\88Ê\92u\95Û\91
632         wp.length := sizeof(wp);
633         GetWindowPlacement(Handle, @wp);
634
635         GikoSys.Setting.EditWindowTop := wp.rcNormalPosition.Top;
636         GikoSys.Setting.EditWindowLeft := wp.rcNormalPosition.Left;
637         GikoSys.Setting.EditWindowHeight := wp.rcNormalPosition.Bottom - wp.rcNormalPosition.Top;
638         GikoSys.Setting.EditWindowWidth := wp.rcNormalPosition.Right - wp.rcNormalPosition.Left;
639         GikoSys.Setting.EditWindowMax := WindowState = wsMaximized;
640         //GikoSys.Setting.EditWindowStay := FormStyle = fsStayOnTop;      // \83X\83e\83C\8fó\91Ô\82Ì\95Û\91
641         GikoSys.Setting.EditWindowTranslucent := TransAction.Checked;   // \94¼\93§\96¾\8fó\91Ô\82Ì\95Û\91
642
643         FGestures.Free;
644
645 end;
646
647 procedure TEditorForm.SetNameList(sName, sMail: string);
648 begin
649         if SaveNameMailAction.Checked then begin
650                 if Trim(sName) <> '' then begin
651                         if GikoSys.Setting.NameList.IndexOf(sName) = -1 then
652                                 GikoSys.Setting.NameList.Insert(0, sName);
653                 end;
654                 if Trim(sMail) <> '' then begin
655                         if GikoSys.Setting.MailList.IndexOf(sMail) = -1 then
656                                 GikoSys.Setting.MailList.Insert(0, sMail);
657                 end;
658         end;
659 end;
660
661 function TEditorForm.GetActiveControlHandle: THandle;
662 begin
663         if EditorPage.ActivePage = EditorTab then begin
664                 if ActiveControl = NameComboBox then
665                         Result := FNameComboEdit
666                 else if ActiveControl = MailComboBox then
667                         Result := FMailComboEdit
668                 else if ActiveControl = BodyEdit then
669                         Result := BodyEdit.Handle
670                 else if ActiveControl = TitleEdit then
671                         Result := TitleEdit.Handle
672                 else
673                         Result := 0;
674         end else if Editorpage.ActivePage = BoardInformationTab then begin
675                 if ActiveControl = BoardInformationMemo then
676                         Result := BoardInformationMemo.Handle
677                 else
678                         Result := 0;
679         end else if Editorpage.ActivePage = RocalRuleTab then begin
680                 if ActiveCOntrol = LocalEdit then
681                         Result := LocalEdit.Handle
682                 else
683                         Result := 0;
684         end else
685                 Result := 0;
686 end;
687
688 procedure TEditorForm.SetContent(Content: string; ABrowser: TWebBrowser);
689 var
690         doc: Variant;
691 begin
692         if ABrowser.Document <> nil then begin
693                 doc := Idispatch( olevariant(ABrowser.ControlInterface).Document) as IHTMLDocument2;
694                 doc.Clear;
695                 doc.open;
696                 doc.charset := 'Shift_JIS';
697                 doc.Write(Content);
698                 doc.Close;
699         end;
700 end;
701 procedure TEditorForm.InitIdHTTP(http: TIdHTTP);
702 begin
703         http.Request.Clear;
704         http.ProxyParams.BasicAuthentication := False;
705         if GikoSys.Setting.WriteProxy then begin
706                 http.ProxyParams.ProxyServer := GikoSys.Setting.WriteProxyAddress;
707                 http.ProxyParams.ProxyPort := GikoSys.Setting.WriteProxyPort;
708                 http.ProxyParams.ProxyUsername := GikoSys.Setting.WriteProxyUserID;
709                 http.ProxyParams.ProxyPassword := GikoSys.Setting.WriteProxyPassword;
710                 if GikoSys.Setting.ReadProxyUserID <> '' then
711                         http.ProxyParams.BasicAuthentication := True;
712         end else begin
713                 http.ProxyParams.ProxyServer := '';
714                 http.ProxyParams.ProxyPort := 80;
715                 http.ProxyParams.ProxyUsername := '';
716                 http.ProxyParams.ProxyPassword := '';
717         end;
718         Indy.Request.UserAgent := GikoSys.GetUserAgent;
719         Indy.Request.AcceptEncoding := '';
720 end;
721 //! \91\97\90M\92\86\8e~\82Ì\82½\82ß\82Ì\83\81\83j\83\85\81[\82Ì\8dÄ\90
722 procedure TEditorForm.CancelSend(ABoard: TBoard; ASysMenu: HMENU);
723 begin
724         ABoard.SPID := '';
725         ABoard.PON := '';
726         FWork := false;
727         EnableMenuItem(ASysMenu, SC_CLOSE, MF_BYCOMMAND or MF_ENABLED);
728         DrawMenuBar(Handle);
729 end;
730
731 procedure TEditorForm.Send(ACOOKIE: string; SPID: string; PON: string; FirstWriting: Boolean);
732 const
733         MSG_FUSIANA : string =  '\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 +
734                 '\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' +
735                 #13#10#13#10'\90Ó\94C\82ð\95\89\82¤\82±\82Æ\82ð\8f³\91ø\82µ\82Ä\8f\91\82«\8d\9e\82Ý\82Ü\82·\82©\81H';
736 var
737         TextStream: TStringStream;
738         Source: TStringStream;
739         ResponseText: string;
740         URL: string;
741         RefURL: string;
742         State: TGikoDownloadState;
743         ResultType: TGikoResultType;
744         MsgResult: Integer;
745         Cookie: string;
746         Board: TBoard;
747         sysMenu : HMENU;
748         //fusianasan\83g\83\89\83b\83v by\92è\8aú\95Ö
749         Namae : String;
750         body : TStringList;
751         Remote : String;
752         ABoard : TBoard;
753     {Protocol,Host, Path, Document, Port, Bookmark : String;}
754 begin
755         FAbort := False;
756         State := gdsError;
757         Namae := THTMLCreate.RepHtml(NameComboBox.Text);
758         if FThreadItem = nil then
759                 Board := FBoard
760         else
761                 Board := FThreadItem.ParentBoard;
762
763
764 //    tmpRawheader := '';
765         InitIdHTTP(Indy);
766         if FThreadItem = nil then begin
767                 URL := FBoard.GetSendURL;
768                 RefURL := GikoSys.UrlToServer(FBoard.URL) + 'test/bbs.cgi';
769         end else begin
770                 URL := FThreadItem.GetSendURL;
771                 RefURL := FThreadItem.URL;
772         end;
773 //      Indy.Request.UserAgent := GikoSys.GetUserAgent;
774         Indy.Request.Referer := RefURL;
775 //      Indy.Request.AcceptEncoding := '';
776
777         Cookie := '';
778         if ACOOKIE <> '' then
779            Cookie := ACOOKIE;
780         if SPID <> '' then
781                 Cookie := Cookie + 'SPID=' + SPID + '; ';
782         if PON <> '' then
783                 Cookie := Cookie + 'PON=' + PON + '; ';
784
785         //\83z\83X\83g\82ª2ch\82Å\81ABe\82ÉLogin\82µ\82Ä\82¢\82ê\82ÎBE\82Ì\83f\81[\83^\82ð\91\97\82é
786         //GikoSys.ParseURI( URL, Protocol,Host, Path, Document, Port, Bookmark );
787         //if GikoSys.Is2chHost(Host) and GikoSys.Setting.BeLogin then
788         if (Board.Is2ch) then begin
789                 // \8cÅ\92è\82Ì\83N\83b\83L\81[\82ª\82 \82ê\82Î\90H\82í\82¹\82é
790                 if Length(GikoSys.Setting.FixedCookie) > 0 then begin
791                         // \83z\83X\83g\82ª2ch\82Ì\8fê\8d\87\81C\8cÅ\92è\82Ì\83N\83b\83L\81[\82ð\90H\82í\82¹\82é
792                         Cookie := Cookie + GikoSys.Setting.FixedCookie + '; ';
793                 end;
794                 if (GikoSys.Setting.BeLogin) then begin
795                         Cookie := Cookie + 'MDMD=' + GikoSys.Setting.BeCode + '; '
796                                         + 'DMDM=' + GikoSys.Setting.BeUserID + '; ';
797                 end;
798
799         end;
800
801         Cookie := 'Cookie: ' + Cookie + 'NAME=' + NameComboBox.Text + '; MAIL=' + MailComboBox.Text;
802
803         sysMenu := GetSystemMenu( Handle, false );
804         EnableMenuItem( sysMenu, SC_CLOSE, MF_GRAYED );
805 {
806   EnableMenuItem(SysMenu, SC_CLOSE, MF_BYCOMMAND or MF_ENABLED);
807   DrawMenuBar(Handle);
808 }
809         Indy.Request.CustomHeaders.Clear;
810 //      Indy.Request.CacheControl := 'no-cache';
811         Indy.Request.CustomHeaders.Add('Pragma: no-cache');
812         Indy.Request.AcceptLanguage := 'ja';
813         Indy.Request.Accept := 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*';
814         Indy.Request.ContentType := 'application/x-www-form-urlencoded';
815         Indy.Request.CustomHeaders.Add(Cookie);
816         TextStream := TStringStream.Create('');
817         Source := TStringStream.Create('');
818         try
819                 try
820                         FDebugStrReceive := '';
821                         FDebugStrSend := '';
822
823                         if (FirstWriting) then begin
824                                 //\83t\83V\83A\83i\83g\83\89\83b\83v\8cx\8d\90(LocalMode) by \92è\8aú\95Ö
825                                 if GikoSys.Setting.LocalTrapAtt then begin
826                                         if LFusianaGet(Namae) then begin
827                                                 MsgResult := MsgBox( Handle, MSG_FUSIANA, '\8fî\95ñ',
828                                                         MB_YESNO or MB_ICONQUESTION);
829                                                 if MsgResult = IDNO  then begin
830                                                         CancelSend( Board, SysMenu );
831                                                         Exit;
832                                                 end;
833                                         end;
834                                         if ((Namae = '\8eR\8dè\8fÂ') or (Namae = 'fusianasan')) then begin
835                                                 MsgResult := MsgBox(Handle, MSG_FUSIANA, '\8fî\95ñ',
836                                                 MB_YESNO or MB_ICONQUESTION);
837                                                 if MsgResult = IDNO  then begin
838                                                         CancelSend( Board, SysMenu );
839                                                         Exit;
840                                                 end;
841                                         end;
842                                 end;
843
844                                 if GikoSys.Setting.RemoteTrapAtt then begin
845                                         if FThreadItem = nil then
846                                                 ABoard := FBoard
847                                         else
848                                                 ABoard := FThreadItem.ParentBoard;
849
850                                         if ABoard = nil then Exit;
851
852                                         if FileExists(ABoard.GetSETTINGTXTFileName)  then begin
853                                                 body := TStringList.Create;
854                                                 try
855                                                         body.LoadFromFile(ABoard.GetSETTINGTXTFileName);
856                                                         Remote := GetFusianaName(body, ABoard);
857                                                 finally
858                                                         body.Free;
859                                                 end;
860                                         end else begin
861                                         //Setting.txt\82ª\82È\82©\82Á\82½\82ç\8eæ\93¾
862                                         //\8eI\82É\95\89\89×\82ª\82©\82©\82è\82»\82¤...
863                                         //if not FileExists(ABoard.GetSETTINGTXTFileName) then begin
864                                                 GetSETTINGTXTAction.Execute;
865                                                 body := TStringList.Create;
866                                                 try
867                                                         if FileExists(ABoard.GetSETTINGTXTFileName) then begin
868                                                                 body.LoadFromFile(ABoard.GetSETTINGTXTFileName);
869                                                                 Remote := GetFusianaName(body, ABoard);
870                                                         end;
871                                                 finally
872                                                         body.Free;
873                                                 end;
874                                         end;
875
876                                         if Remote = 'fusianasan' then begin
877                                                 MsgResult := MsgBox(
878                                                         Handle, MSG_FUSIANA, '\8fî\95ñ',
879                                                         MB_YESNO or MB_ICONQUESTION);
880                                                 if MsgResult = IDNO  then begin
881                                                         CancelSend( Board, SysMenu );
882                                                         Exit;
883                                                 end;
884                                         end;
885                                 end;
886                         end;
887
888                         GetSendData(Source);
889                         IdAntiFreeze.Active := True;
890                         try
891                                 Indy.Post(URL, Source, TextStream);
892                         finally
893                                 IdAntiFreeze.Active := False;
894                         end;
895                         ResponseText := TextStream.DataString;
896
897                         ResultType := GetResultType(ResponseText);
898
899
900                         if ResultType = grtOK then begin
901                                 if (GikoSys.Setting.UseSamba) and  (FSambaTimer.Enabled) then
902                 begin
903                     FSambaTimer.WriteSambaTime(Now());
904                 end;
905                                 State := gdsComplete;
906                         end else if ResultType = grtCookie then begin
907                                 //\83\8b\81[\83v\96h\8e~
908                                 if not FirstWriting then
909                                         raise Exception.Create('');
910
911                                 MsgResult := MsgBox( Handle,
912                                                                 '\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 +
913                                                                 '\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 +
914                                                                 '\91S\90Ó\94C\82ð\95\89\82¤\82±\82Æ\82ð\8f³\91ø\82µ\82Ä\8f\91\82«\8d\9e\82Ý\82Ü\82·\82©\81H',
915                                                                 '\8fî\95ñ',
916                                                                 MB_YESNO or MB_ICONQUESTION);
917
918                                 if MsgResult = IDYES then begin
919                                         GetCookie(Indy.Response.RawHeaders.Text, Board);
920
921                                         if (Board.SPID = '') and (Board.PON = '') and (Board.Cookie = '') then
922                                                 raise Exception.Create('');
923
924                                         //\82à\82¤\88ê\89ñ\82±\82Ì\83\81\83\\83b\83h
925                                         Send(Board.Cookie, Board.SPID, Board.PON, False);
926                                         Exit;
927                                 end else begin
928                                         CancelSend( Board, SysMenu );
929                                         Exit;
930                                 end;
931                         end else if ResultType = grtCheck then begin
932                                 //\83\8b\81[\83v\96h\8e~
933                                 if not FirstWriting then
934                                         raise Exception.Create('');
935
936                                 MsgResult := MsgBox( Handle,
937                                                 '\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 +
938                                                 '\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 +
939                                                 '\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 +
940                                                 '\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 +
941                                                 #13#10 +
942                                                 '\91S\90Ó\94C\82ð\95\89\82¤\82±\82Æ\82ð\8f³\91ø\82µ\82Ä\8f\91\82«\8d\9e\82Ý\82Ü\82·\82©\81H',
943                                                 '\8am\94F',
944                                                 MB_YESNO or MB_ICONQUESTION);
945
946                                 if MsgResult = IDYES then begin
947                                         GetCookie(Indy.Response.RawHeaders.Text, Board);
948
949                                         if (Board.SPID = '') and (Board.PON = '') and (Board.Cookie = '') then
950                                                 raise Exception.Create('');
951
952                                         Send(Board.Cookie, Board.SPID, Board.PON, False);
953                                         Exit;
954                                 end else begin
955                                         CancelSend( Board, SysMenu );
956                                         Exit;
957                                 end;
958                         end else begin
959                                 if (GikoSys.Setting.UseSamba)  and  (FSambaTimer.Enabled) then
960                 begin
961                                         FSambaTimer.WriteSambaTime(Now());
962                 end;
963
964                                 State := gdsError;
965                                 raise Exception.Create('');
966                         end;
967                 except
968                         on E: EIdConnectException do begin
969                                 State := gdsError;
970                                 ResponseText := '<html><body>'
971                                                                                         + '<div>\90Ú\91±\82ª\8e¸\94s\82µ\82Ü\82µ\82½<br>'
972                                                                                         + '\89ñ\90ü\82â\83v\83\8d\83L\83V\82Ì\8fó\91Ô\82ð\92²\82×\82Ä\82­\82¾\82³\82¢<br></div>'
973                                                                                         + '<br><br><div>' + E.Message + '</div>'
974                                                                                         + '</body></html>';
975                         end;
976                         on E: Exception do begin
977                                 State := gdsError;
978
979                                 FDebugStrReceive := AnsiReplaceText(FDebugStrReceive, '<', '&lt;');
980                                 FDebugStrReceive := AnsiReplaceText(FDebugStrReceive, '>', '&gt;');
981                                 FDebugStrSend := AnsiReplaceText(FDebugStrSend, '<', '&lt;');
982                                 FDebugStrSend := AnsiReplaceText(FDebugStrSend, '>', '&gt;');
983
984                                 ResponseText := '<html><body>' + TextStream.DataString;
985                                 ResponseText := AnsiReplaceText(ResponseText, '</body>', '');
986                                 ResponseText := AnsiReplaceText(ResponseText, '</html>', '');
987                                 ResponseText := ResponseText + '<hr><div align="left"><pre>';
988                                 ResponseText := ResponseText + '<b>\82±\82±\82©\82ç\83M\83R\83i\83r\82Ì\8fî\95ñ</b>'#13#10;
989                                 ResponseText := ResponseText + #13#10'\81\9c\91\97\90M'#13#10;
990                                 ResponseText := ResponseText + FDebugStrSend;
991                                 ResponseText := ResponseText + #13#10'\81\9c\8eó\90M'#13#10;
992                                 ResponseText := ResponseText + FDebugStrReceive;
993                                 ResponseText := ResponseText + '</pre></div></body></html>';
994                         end;
995                 end;
996                 FStatusCode := Indy.ResponseCode;
997                 if FAbort then
998                         State := gdsAbort;
999         finally
1000                 Source.Free;
1001                 TextStream.Free;
1002                 //sysMenu := GetSystemMenu( Handle, true );
1003                 EnableMenuItem(SysMenu, SC_CLOSE, MF_BYCOMMAND or MF_ENABLED);
1004                 DrawMenuBar(Handle);
1005         end;
1006         FWork := false;
1007     //\94ñ\8cö\8e®\83M\83R\83i\83r\94Â\82È\82Ç\82Ì2ch\8cÝ\8a·\83X\83N\83\8a\83v\83g\97p
1008     //2ch\88È\8aO\82Å\82©\82ÂResponceCode\82ª302Found\82Å\8f\91\82«\8d\9e\82Ý\8a®\97¹
1009     //if (not Board.Is2ch) and (FStatusCode = 302) then begin
1010     if FStatusCode = 302 then begin
1011         GikoForm.PlaySound('ResEnd');
1012         SaveSendFile;
1013                 if FThreadItem = nil then
1014                         GikoForm.AddMessageList(FBoard.Title + ' ' + GikoSys.GetGikoMessage(gmNewSure), nil, gmiOK)
1015                 else
1016                         GikoForm.AddMessageList(FThreadItem.Title + ' ' + GikoSys.GetGikoMessage(gmNewRes), nil, gmiOK);
1017         Close;
1018         Exit;
1019     end;
1020         if State = gdsComplete then begin
1021                 GikoForm.PlaySound('ResEnd');
1022                 SaveSendFile;
1023                 if FThreadItem = nil then
1024                         GikoForm.AddMessageList(FBoard.Title + ' ' + GikoSys.GetGikoMessage(gmNewSure), nil, gmiOK)
1025                 else
1026                         GikoForm.AddMessageList(FThreadItem.Title + ' ' + GikoSys.GetGikoMessage(gmNewRes), nil, gmiOK);
1027                 Close;
1028         end else if State = gdsError then begin
1029                 if FThreadItem = nil then
1030                         GikoForm.AddMessageList(FBoard.Title + ' ' + GikoSys.GetGikoMessage(gmNewSure), nil, gmiOK)
1031                 else
1032                         GikoForm.AddMessageList(FThreadItem.Title + ' ' + GikoSys.GetGikoMessage(gmNewRes), nil, gmiOK);
1033
1034                 EditorPage.ActivePage := PreviewTab;
1035                 SetContent(ResponseText, Browser);
1036         end else if State = gdsAbort then begin
1037                 GikoForm.AddMessageList(FThreadItem.Title + ' ' + GikoSys.GetGikoMessage(gmAbort), nil, gmiSAD);
1038         end;
1039 end;
1040
1041 function TEditorForm.GetResultType(ResponseText: string): TGikoResultType;
1042 begin
1043         if AnsiPos('\8f\91\82«\82±\82Ý\82ª\8fI\82í\82è\82Ü\82µ\82½', ResponseText) <> 0 then
1044                 Result := grtOK
1045         else if (AnsiPos('\83N\83b\83L\81[\82ª\82È\82¢\82©\8aú\8cÀ\90Ø\82ê\82Å\82·', ResponseText) > 0) or
1046                                         (AnsiPos('<title>\83N\83b\83L\81[\8am\94F\81I</title>', ResponseText) > 0)    or
1047                                         (AnsiPos('<title>\81¡\83N\83b\83L\81[\8am\94F\81I\81¡</title>', ResponseText) > 0)        or
1048                                         //(AnsiPos('\83N\83b\83L\81[\8am\94F', ResponseText) > 0) or
1049                                         (AnsiPos(RES2CH_COOKIE, ResponseText) > 0)      then
1050                 Result := grtCookie
1051         else if (AnsiPos('<font size=+2 color=#FF0000>\8f\91\82«\8d\9e\82Ý\83`\83F\83b\83N\81I </font>', ResponseText) > 0)   or
1052                                         (AnsiPos('<title>\81¡ \8f\91\82«\8d\9e\82Ý\8am\94F\82µ\82Ü\82· \81¡</title>', ResponseText) > 0)  or
1053                                         (AnsiPos('<title>\93\8a\8de\8am\94F</title>', ResponseText) > 0)  or
1054                                         (AnsiPos('<b>\8f\91\82«\82±\82Ý\8am\94F</b>', ResponseText) > 0)      or
1055                                         (AnsiPos('="../test/subbbs.cgi">', ResponseText) > 0)   or
1056                                         (AnsiPos(RES2CH_FALSE, ResponseText) > 0)       then
1057                 Result := grtCheck
1058         else if (AnsiPos('\81E\93\8a\8de\8eÒ\82Í\81A\8cf\8e¦\94Â\89^\89c\8eÒ\82É\91Î\82µ\82Ä\81A\92\98\8dì\8eÒ\90l\8ai\8c \82ð\88ê\90Ø\8ds\8eg\82µ\82È\82¢\82±\82Æ\82ð\8f³\91ø\82µ\82Ü\82·\81B<br>', ResponseText) > 0) or
1059                                         (AnsiPos('\81i\92\98\8dì\8c \96@\91æ21\8fð\82È\82¢\82µ\91æ28\8fð\82É\8bK\92è\82³\82ê\82é\8c \97\98\82à\8aÜ\82Þ\81j\82»\82Ì\91¼\82Ì\8c \97\98\82É\82Â\82«\81A', ResponseText) > 0) then
1060                 Result := grtCookie
1061         else
1062                 Result := grtError;
1063 end;
1064
1065
1066 procedure TEditorForm.GetSendData(Source: TStringStream);
1067 var
1068         SessionID: string;
1069         s: string;
1070         SendTime: Integer;
1071         Adjust: Integer;
1072         Board: TBoard;
1073         body            : string;
1074 begin
1075         if FThreadItem = nil then
1076                 Board := FBoard
1077         else
1078                 Board := FThreadItem.ParentBoard;
1079
1080         if GikoSys.Setting.UseMachineTime then begin
1081                 if GikoSys.Setting.TimeAdjust then
1082                         Adjust := Gikosys.Setting.TimeAdjustSec
1083                 else
1084                         Adjust := GikoSys.Setting.TimeAdjustSec * -1;
1085                 SendTime := GikoSys.DateTimeToInt(Now) - (9 * 60 * 60) + Adjust
1086         end else begin
1087                 if (Board.LastGetTime = 0) or (Board.LastGetTime = ZERO_DATE) then
1088                         SendTime := GikoSys.DateTimeToInt(Now)
1089                 else
1090                         SendTime := GikoSys.DateTimeToInt(Board.LastGetTime);
1091         end;
1092
1093         body := GetBody;
1094
1095         SessionID := GikoSys.Dolib.SessionID;
1096         if SessionID <> '' then
1097                 s := 'sid=' + HttpEncode(SessionID) + '&'
1098         else
1099                 s := '';
1100         s := s + 'subject=&'
1101                + 'FROM=' + HttpEncode(NameComboBox.Text) + '&'
1102                + 'mail=' + HttpEncode(MailComboBox.Text) + '&'
1103                + 'MESSAGE=' + HttpEncode(body) + '&'
1104                + 'bbs=' + Board.BBSID + '&'
1105                            + 'time=' + IntToStr(SendTime) + '&';
1106                            
1107         if FThreadItem = nil then begin
1108                 s := s + 'subject=' + HttpEncode(TitleEdit.Text) + '&';
1109                 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;
1110         end else begin
1111                 s := s + 'key=' + ChangeFileExt(FThreadItem.FileName, '') + '&';
1112                 s := s + 'submit=' + HttpEncode('\8f\91\82«\8d\9e\82Þ') + #13#10;
1113         end;
1114         Source.WriteString(s);
1115 end;
1116
1117 procedure TEditorForm.SaveSendFile;
1118 var
1119         sDate: string;
1120         ini: TMemIniFile;
1121 begin
1122         ini := TMemIniFile.Create(GikoSys.GetSentFileName);
1123         try
1124                 sDate := IntToStr(GikoSys.DateTimeToInt(Now));
1125
1126                 ini.WriteString(sDate, 'Name', NameComboBox.Text);
1127                 ini.WriteString(sDate, 'EMail', MailComboBox.Text);
1128                 ini.WriteString(sDate, 'Body', HttpEncode(BodyEdit.Text));
1129                 ini.WriteInteger(sDate, 'Status', FStatusCode);
1130                 ini.WriteDateTime(sDate, 'Date', Now);
1131                 if FThreadItem = nil then begin
1132                         ini.WriteString(sDate, 'Title', MojuUtils.Sanitize(TitleEdit.Text));
1133                         ini.WriteString(sDate, 'BBS', FBoard.BBSID);
1134                         ini.WriteInteger(sDate, 'NewThread', 1);
1135                 end else begin
1136                         ini.WriteString(sDate, 'Title', FThreadItem.Title);
1137                         ini.WriteString(sDate, 'BBS', FThreadItem.ParentBoard.BBSID);
1138                         ini.WriteString(sDate, 'Key', ChangeFileExt(FThreadItem.FileName, ''));
1139                 end;
1140
1141                 ini.UpdateFile;
1142         finally
1143                 ini.Free;
1144         end;
1145 end;
1146
1147 procedure TEditorForm.SendActionExecute(Sender: TObject);
1148 const
1149         TITLE_SAMBA : string = 'Samba24\8cx\8d\90';
1150 var
1151         Board: TBoard;
1152         rc: Integer;
1153         rc2: Integer;
1154         state : TGikoDownloadState;
1155         body            : string;
1156 begin
1157         if FWork then
1158                 Exit;
1159         try
1160                 FWork := True;
1161                 SendAction.Enabled := False;
1162                 Application.ProcessMessages;
1163                 if not Check then Exit;
1164
1165                 if FThreadItem = nil then
1166                         Board := FBoard
1167                 else
1168                         Board := FThreadItem.ParentBoard;
1169
1170                 if FThreadItem = nil then begin
1171                         rc := GikoUtil.MsgBox(Handle,
1172                                                                                                         '\81u' + Board.Title + '\81v\94Â\82É\90V\82µ\82¢\83X\83\8c\83b\83h\97§\82Ä\82Ü\82·'#13#10#13#10
1173                                                                                                         + '\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
1174                                                                                                         + '\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
1175                                                                                                         + '\81u\82Í\82¢\81v\82ð\89\9f\82·\82Æ\91\97\90M\82µ\82Ü\82·',
1176                                                                                                         '\8am\94F',
1177                                                                                                         MB_ICONQUESTION or MB_YESNO);
1178                         if rc <> ID_YES then
1179                                 Exit;
1180                 end;
1181
1182                 SetNameList(NameComboBox.Text, MailComboBox.Text);
1183                 if (KotehanCheckBox.Enabled) and (KotehanCheckBox.Checked) then begin
1184                         Board.KotehanName := NameComboBox.Text;
1185                         Board.KotehanMail := MailComboBox.Text;
1186                 end;
1187
1188                 if Board.IsBoardPlugInAvailable then begin
1189                         body := GetBody;
1190
1191                         if FThreadItem = nil then begin
1192                                 // \83X\83\8c\97§\82Ä
1193                                 state := TGikoDownloadState( Board.BoardPlugIn.CreateThread(
1194                                         DWORD( Board ), TitleEdit.Text, NameComboBox.Text, MailComboBox.Text, body ) );
1195
1196                                 if state = gdsComplete then begin
1197                                         GikoForm.PlaySound('ResEnd');
1198                                         SaveSendFile;
1199                                         GikoForm.AddMessageList(FBoard.Title + ' ' + GikoSys.GetGikoMessage(gmNewSure), nil, gmiOK);
1200                                         FWork := False;
1201                                         Close;
1202                                 end else if State = gdsError then begin
1203                                         GikoForm.AddMessageList(FBoard.Title + ' ' + GikoSys.GetGikoMessage(gmSureError), nil, gmiNG);
1204                                 end else if State = gdsAbort then begin
1205                                         GikoForm.AddMessageList(FBoard.Title + ' ' + GikoSys.GetGikoMessage(gmAbort), nil, gmiNG);
1206                                 end;
1207                         end else begin
1208                                 // \83\8c\83X
1209                                 state := TGikoDownloadState( FThreadItem.ParentBoard.BoardPlugIn.WriteThread(
1210                                         DWORD( FThreadItem ), NameComboBox.Text, MailComboBox.Text, body ) );
1211
1212                                 if state = gdsComplete then begin
1213                                         GikoForm.PlaySound('ResEnd');
1214                                         SaveSendFile;
1215                                         GikoForm.AddMessageList(FThreadItem.Title + ' ' + GikoSys.GetGikoMessage(gmNewRes), nil, gmiOK);
1216                                         FWork := False;
1217                                         Close;
1218                                 end else if State = gdsError then begin
1219                                         GikoForm.AddMessageList(FThreadItem.Title + ' ' + GikoSys.GetGikoMessage(gmResError), nil, gmiOK);
1220                                 end else if State = gdsAbort then begin
1221                     GikoForm.AddMessageList(FThreadItem.Title + ' ' + GikoSys.GetGikoMessage(gmAbort), nil, gmiOK);
1222                                 end;
1223                         end;
1224                 end else begin
1225                         if not FSambaTimer.Enabled then begin
1226                                 if CompareDateTime(Board.Expires ,Now) <= 0 then begin
1227                                         Board.Cookie    := '';
1228                                         Board.SPID      := '';
1229                                         Board.PON               := '';
1230                                 end;
1231                                 Send(Board.Cookie, Board.SPID, Board.PON, True);
1232                         end else begin
1233                                 if not FSambaTimer.CheckSambaTime(Now()) then begin
1234                                         rc := GikoUtil.MsgBox(Handle,
1235                                                                 '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
1236                                                                 + '\91\97\90M\82ð\92\86\8e~\82µ\82Ü\82·\82©\81H' + #13#10
1237                                                                 + '(\81u\82¢\82¢\82¦\81v\82¾\82Æ\91\97\90M\82µ\82Ü\82·)', TITLE_SAMBA,
1238                                                                 MB_YESNO or MB_ICONQUESTION);
1239                                         if rc = IDYES then begin
1240                                                 FWork := false;
1241                                                 Exit;
1242                                         end;
1243                                         if rc = IDNO then begin
1244                                                 rc2 := GikoUtil.MsgBox(Handle,
1245                                                                        '\96{\93\96\82É\91\97\90M\82µ\82Ü\82·\82©\81H',
1246                                                                        TITLE_SAMBA,
1247                                                                        MB_YESNO or MB_ICONQUESTION);
1248                                                 if rc2 = IDNO then begin
1249                                                         FWork := False;
1250                                                         Exit;
1251                                                 end;
1252                                         end;
1253                                 end;
1254                                 if CompareDateTime(Board.Expires ,Now) <= 0 then begin
1255                                         Board.Cookie    := '';
1256                                         Board.SPID      := '';
1257                                         Board.PON               := '';
1258                                 end;
1259                                 Send(Board.Cookie, Board.SPID, Board.PON, True);
1260                         end;
1261                 end;
1262         finally
1263                 FWork := False;
1264                 if FSambaTimer.Enabled then begin
1265                         FNow := FSambaTimer.Update;
1266         end;
1267         end;
1268 end;
1269
1270 procedure TEditorForm.SaveActionExecute(Sender: TObject);
1271 begin
1272 //
1273 end;
1274
1275 procedure TEditorForm.CloseActionExecute(Sender: TObject);
1276 begin
1277         Close;
1278 end;
1279
1280 procedure TEditorForm.UndoActionExecute(Sender: TObject);
1281 begin
1282         SendMessage(GetActiveControlHandle, WM_UNDO, 0, 0);
1283 end;
1284
1285 procedure TEditorForm.CutActionExecute(Sender: TObject);
1286 begin
1287         SendMessage(GetActiveControlHandle, WM_CUT, 0, 0);
1288 end;
1289
1290 procedure TEditorForm.CopyActionExecute(Sender: TObject);
1291 begin
1292         SendMessage(GetActiveControlHandle, WM_COPY, 0, 0);
1293 end;
1294
1295 procedure TEditorForm.PasteActionExecute(Sender: TObject);
1296 begin
1297         SendMessage(GetActiveControlHandle, WM_PASTE, 0, 0);
1298 end;
1299
1300 procedure TEditorForm.SelectAllActionExecute(Sender: TObject);
1301 begin
1302         SendMessage(GetActiveControlHandle, EM_SETSEL, 0, GetWindowTextLength(GetActiveControlHandle));
1303 end;
1304
1305 procedure TEditorForm.TopActionExecute(Sender: TObject);     // \83E\83B\83\93\83h\83E\8dÅ\91O\96Ê(Stay)\83{\83^\83\93\82Ì\8f\88\97\9d
1306 begin
1307         if not (fsShowing in Self.FormState) then begin
1308                 if TopAction.Checked then begin // \83X\83e\83C\8fó\91Ô\82É\90Ý\92è
1309                         SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE);
1310                         GikoSys.Setting.EditWindowStay := true;
1311                 end     else begin   // \83X\83e\83C\8fó\91Ô\89ð\8f\9c
1312                         SetWindowPos(Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE);
1313                         GikoSys.Setting.EditWindowStay := false;
1314                 end;
1315                 // \83X\83e\83C\8fó\91Ô\82Ì\95Û\91
1316                 //GikoSys.Setting.EditWindowStay := FormStyle = fsStayOnTop;
1317         end;
1318 end;
1319
1320 procedure TEditorForm.AbortActionExecute(Sender: TObject);
1321 begin
1322         FAbort := True;
1323 end;
1324
1325 procedure TEditorForm.SendActionUpdate(Sender: TObject);
1326 begin
1327         SendAction.Enabled := not FWork;
1328 end;
1329
1330 procedure TEditorForm.SaveActionUpdate(Sender: TObject);
1331 begin
1332         SaveAction.Enabled := False;
1333 end;
1334
1335 procedure TEditorForm.CloseActionUpdate(Sender: TObject);
1336 begin
1337         CloseAction.Enabled := not FWork;
1338 end;
1339
1340 procedure TEditorForm.UndoActionUpdate(Sender: TObject);
1341 begin
1342         UndoAction.Enabled := (GetActiveControlHandle <> 0)
1343                                                                                                 and (SendMessage(GetActiveControlHandle, EM_CANUNDO, 0, 0) <> 0)
1344                                                                                                 and (not FWork);
1345 end;
1346
1347 procedure TEditorForm.CutActionUpdate(Sender: TObject);
1348 var
1349         Selection: TSelection;
1350         AHandle: THandle;
1351 begin
1352         AHandle := GetActiveControlHandle;
1353         SendMessage(AHandle, EM_GETSEL, Longint(@Selection.StartPos), Longint(@Selection.EndPos));
1354         CutAction.Enabled := (AHandle <> 0)
1355                                                                                 and ((Selection.EndPos - Selection.StartPos) <> 0)
1356                                                                                 and (not FWork);
1357 end;
1358
1359 procedure TEditorForm.CopyActionUpdate(Sender: TObject);
1360 var
1361         Selection: TSelection;
1362         AHandle: THandle;
1363 begin
1364         AHandle := GetActiveControlHandle;
1365         SendMessage(AHandle, EM_GETSEL, Longint(@Selection.StartPos), Longint(@Selection.EndPos));
1366         CopyAction.Enabled := (AHandle <> 0)
1367                                                                                 and ((Selection.EndPos - Selection.StartPos) <> 0)
1368                                                                                 and (not FWork);
1369 end;
1370
1371 procedure TEditorForm.PasteActionUpdate(Sender: TObject);
1372 begin
1373         PasteAction.Enabled := (GetActiveControlHandle <> 0)
1374                                                                                         and (Clipboard.HasFormat(CF_TEXT))
1375                                                                                         and (not FWork);
1376 end;
1377
1378 procedure TEditorForm.TopActionUpdate(Sender: TObject);
1379 begin
1380         TopAction.Enabled := not FWork;
1381 end;
1382
1383 procedure TEditorForm.SageCheckBoxClick(Sender: TObject);
1384 begin
1385         if SageCheckBox.Checked then begin
1386                 if AnsiPos('sage', MailComboBox.Text) = 0 then
1387                         MailComboBox.Text := 'sage' + MailComboBox.Text;
1388         end else begin
1389                 if AnsiPos('sage', MailComboBox.Text) <> 0 then
1390                         MailComboBox.Text := StringReplace(MailComboBox.Text, 'sage', '', [rfReplaceAll]);
1391         end;
1392 end;
1393
1394 procedure TEditorForm.MailComboBoxChange(Sender: TObject);
1395 begin
1396         if AnsiPos('sage', MailComboBox.Text) = 0 then
1397                 SageCheckBox.Checked := False
1398         else
1399                 SageCheckBox.Checked := True;
1400 end;
1401
1402 procedure TEditorForm.IdLogDebugReceive(ASender: TIdConnectionIntercept;
1403         AStream: TStream);
1404 var
1405         StringStream: TStringStream;
1406 begin
1407         StringStream := TStringStream.Create('');
1408         try
1409                 StringStream.CopyFrom(AStream, AStream.Size);
1410                 FDebugStrReceive := FDebugStrReceive + StringStream.DataString;
1411         finally
1412                 StringStream.Free;
1413         end;
1414 end;
1415
1416 procedure TEditorForm.IdLogDebugSend(ASender: TIdConnectionIntercept;
1417         AStream: TStream);
1418 var
1419         StringStream: TStringStream;
1420 begin
1421         StringStream := TStringStream.Create('');
1422         try
1423                 StringStream.CopyFrom(AStream, AStream.Size);
1424                 FDebugStrSend := FDebugStrSend + StringStream.DataString;
1425         finally
1426                 StringStream.Free;
1427         end;
1428 end;
1429
1430 procedure TEditorForm.TransActionExecute(Sender: TObject);
1431 begin
1432         AlphaBlend := TransAction.Checked;
1433         // \94¼\93§\96¾\8fó\91Ô\82Ì\95Û\91
1434         GikoSys.Setting.EditWindowTranslucent := TransAction.Checked;
1435 end;
1436
1437 procedure TEditorForm.TransActionUpdate(Sender: TObject);
1438 begin
1439         TransAction.Enabled := not FWork;
1440 end;
1441 //StatusBar\82ÌPanels[0]\82Ì\95\9d\82ð\89Â\95Ï\81B\8ec\82è\82ð\8cÅ\92è\82É\82·\82é
1442 procedure TEditorForm.StatusBarResize(Sender: TObject);
1443 begin
1444         StatusBar.Panels[0].Width := StatusBar.Width
1445                                                                         - StatusBar.Panels[1].Width - StatusBar.Panels[2].Width;
1446
1447 end;
1448
1449 //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Þ
1450 procedure TEditorForm.FormActivate(Sender: TObject);
1451 begin
1452         if ( FSambaTimer.Enabled ) and ( FThreadItem <> nil ) then
1453     begin
1454                 FNow := FSambaTimer.Update;
1455     end;
1456         if GikoSys.Setting.GestureEnabled then begin
1457                 GikoSys.Setting.Gestures.ClearGesture;
1458                 GikoSys.Setting.Gestures.LoadGesture(
1459                         GikoSys.Setting.GetGestureFileName, ActionList );
1460                 MouseGesture.UnHook;
1461                 MouseGesture.OnGestureStart := OnGestureStart;
1462                 MouseGesture.OnGestureMove := OnGestureMove;
1463                 MouseGesture.OnGestureEnd := OnGestureEnd;
1464                 MouseGesture.SetHook( Handle );
1465         end;
1466 end;
1467 procedure TEditorForm.FormCloseQuery(Sender: TObject;
1468   var CanClose: Boolean);
1469 begin
1470         CanClose := not FWork;
1471 end;
1472
1473 procedure TEditorForm.QuotePasteActionExecute(Sender: TObject);
1474 var
1475         s                       : TStringList;
1476         i                       : Integer;
1477         quote   : string;
1478 begin
1479
1480         quote   := GikoSys.GetOEIndentChar;
1481         s                       := TStringList.Create;
1482         try
1483                 s.Text  := Clipboard.AsText;
1484
1485                 for i := s.Count - 1 downto 0 do
1486                         s[ i ]  := quote + s[ i ];
1487
1488                 BodyEdit.SelText        := s.Text;
1489         finally
1490                 s.Free;
1491         end;
1492
1493 end;
1494
1495 procedure TEditorForm.SpaceToNBSPActionExecute(Sender: TObject);
1496 begin
1497         GikoSys.Setting.SpaceToNBSP := SpaceToNBSPAction.Checked;
1498         if EditorPage.ActivePage = PreviewTab then
1499                 Preview;
1500 end;
1501
1502 procedure TEditorForm.AmpToCharRefActionExecute(Sender: TObject);
1503 begin
1504         GikoSys.Setting.AmpToCharRef := AmpToCharRefAction.Checked;
1505         if EditorPage.ActivePage = PreviewTab then
1506                 Preview;
1507 end;
1508
1509 procedure TEditorForm.BoardTopClick(Sender: TObject);
1510 var
1511         ini: TIniFile;
1512 begin
1513         ini := TIniFile.Create(GikoSys.Setting.GetFileName);
1514         try
1515                 BoardtopTab.TabVisible := BoardTop.Checked;
1516                 ini.WriteBool('EditorForm', 'BoardTopTab', BoardtopTab.TabVisible);
1517         finally
1518                 ini.Free;
1519         end;
1520 end;
1521
1522
1523 procedure TEditorForm.GetSETTINGTXTActionExecute(Sender: TObject);
1524 var
1525         URL, RefURL: string;
1526         settingBody: TStringList;
1527         tmpBoard: TBoard;
1528 begin
1529
1530         if FWork then begin
1531                 Exit;
1532         end;
1533
1534         FWork := True;
1535
1536         InitIdHTTP(Indy);
1537         if FThreadItem = nil then
1538                 tmpBoard := FBoard
1539         else
1540                 tmpBoard := FThreadItem.ParentBoard;
1541
1542         if tmpBoard = nil then Exit;
1543
1544         RefURL  := tmpBoard.URL;
1545         if RefURL[Length(RefURL)] <> '/' then
1546                 URL     := RefURL + '/' + 'SETTING.TXT'
1547         else
1548                 URL     := RefURL + 'SETTING.TXT';
1549
1550         Indy.Request.LastModified := tmpBoard.SETTINGTXTTime;
1551         Indy.Request.Referer := RefURL;
1552         Screen.Cursor := crHourGlass;
1553         settingBody := TStringList.Create;
1554         try
1555                 StatusBar.Panels[0].Text := 'SETTING.TXT\83_\83E\83\93\83\8d\81[\83h\92\86';
1556                 try
1557                         IdAntiFreeze.Active := True;
1558                         try
1559                                 settingBody.Text := Indy.Get(URL);
1560                         finally
1561                                 IdAntiFreeze.Active := False;
1562                         end;
1563                         if( Indy.ResponseCode = 200 ) then begin
1564                                 settingBody.SaveToFile(tmpBoard.GetSETTINGTXTFileName);
1565                                 tmpBoard.SETTINGTXTTime := Indy.Response.LastModified;
1566                                 tmpBoard.IsSETTINGTXT := true;
1567                                 tmpBoard.TitlePictureURL := GetTitlePictureURL(settingBody, tmpBoard);
1568                                 tmpBoard.Modified := true;
1569                                 StatusBar.Panels[0].Text := 'SETTING.TXT\8eæ\93¾\8a®\97¹(' + IntToStr(Indy.ResponseCode) + ')';
1570                         end;
1571                 except
1572                         on E: EIdException do begin
1573                                 if( AnsiPos('304', E.Message) > 0 ) then
1574                                         StatusBar.Panels[0].Text := 'SETTING.TXT\8dX\90V\96³\82µ(' + IntToStr(Indy.ResponseCode) + ')'
1575                                 else
1576                                         StatusBar.Panels[0].Text := 'SETTING.TXT\8eæ\93¾\83G\83\89\81[(' + IntToStr(Indy.ResponseCode) + ')';
1577                         end;
1578                 end;
1579         finally
1580                 settingBody.Free;
1581                 Screen.Cursor := crDefault;
1582                 FWork := False;
1583         end;
1584         ShowBoardInformation(tmpBoard, BoardInformationMemo);
1585
1586
1587 end;
1588
1589 procedure TEditorForm.ShowBoardInformation(ABoard: TBoard; AMemo: TMemo);
1590 var
1591         body: TStringList;
1592 begin
1593         AMemo.Clear;
1594         AMemo.Lines.Add('[SETTING.TXT]');
1595         if ABoard.IsSETTINGTXT then begin
1596                 if FileExists(ABoard.GetSETTINGTXTFileName)  then begin
1597                         AMemo.Lines.Add(DateTimeToStr(ABoard.SETTINGTXTTime) + ' \8dX\90V');
1598                         body := TStringList.Create;
1599                         try
1600                                 body.LoadFromFile(ABoard.GetSETTINGTXTFileName);
1601                                 AMemo.Lines.AddStrings(body);
1602                         finally
1603                                 body.Free;
1604                         end;
1605                 end else begin
1606                         ABoard.IsSETTINGTXT := false;
1607                         ABoard.SETTINGTXTTime := ZERO_DATE;
1608                         AMemo.Lines.Add('Local\82É\95Û\91\82³\82ê\82½SETTING.TXT\82ª\8c©\82Â\82©\82è\82Ü\82¹\82ñ');
1609                         AMemo.Lines.Add('\83\81\83j\83\85\81[\82æ\82è\8dÄ\8eæ\93¾\82µ\82Ä\82­\82¾\82³\82¢\81B');
1610                 end;
1611         end else begin
1612                 AMemo.Lines.Add('SETTING.TXT\82ð\8eæ\93¾\82µ\82Ä\82¢\82Ü\82¹\82ñ\81B');
1613                 AMemo.Lines.Add('\83\81\83j\83\85\81[\82æ\82è\8eæ\93¾\82µ\82Ä\82­\82¾\82³\82¢\81B');
1614         end;
1615 end;
1616 function TEditorForm.GetTitlePictureURL(body: TStringList; ABoard: TBoard): string;
1617 //BBS_TITLE_PICTURE=
1618 //BBS_FIGUREHEAD=
1619 var
1620         i: Integer;
1621         tmp: string;
1622 begin
1623         Result := '';
1624         for i := 0 to body.Count - 1 do begin
1625                 if (AnsiPos('BBS_TITLE_PICTURE=', body[i]) > 0) or
1626                    (AnsiPos('BBS_FIGUREHEAD=', body[i]) > 0) then begin
1627                         tmp := body[i];
1628                         Delete(tmp, 1, AnsiPos('=', tmp));
1629                         if AnsiPos('../', tmp) > 0 then begin
1630                                 tmp := CustomStringReplace(tmp, '../', GikoSys.UrlToServer(ABoard.URL));
1631                         end;
1632                         Result := tmp;
1633                         Exit;
1634                 end;
1635         end;
1636 end;
1637
1638 procedure TEditorForm.GetTitlePictureActionUpdate(Sender: TObject);
1639 begin
1640         if FThreadItem = nil then
1641                 GetTitlePictureAction.Enabled :=  FBoard.IsSETTINGTXT
1642         else
1643                 GetTitlePictureAction.Enabled :=  FThreadItem.ParentBoard.IsSETTINGTXT;
1644
1645         if GetTitlePictureAction.Enabled Then begin
1646                 // \8eÀ\8ds\92\86\82Í\8eÀ\8ds\95s\89Â
1647                 GetTitlePictureAction.Enabled := not FWork;
1648         end;
1649 end;
1650
1651 procedure TEditorForm.GetTitlePictureActionExecute(Sender: TObject);
1652 var
1653         memStream: TMemoryStream;
1654         tmpBoard: TBoard;
1655 begin
1656         if FWork then
1657                 Exit;
1658
1659         FWork := True;
1660
1661         InitIdHTTP(Indy);
1662         memStream := TMemoryStream.Create;
1663         try
1664                 if FThreadItem = nil then
1665                         tmpBoard := FBoard
1666                 else
1667                         tmpBoard := FThreadItem.ParentBoard;
1668
1669                 Indy.Request.Referer := tmpBoard.URL;
1670                 if      tmpBoard.TitlePictureURL <> '' then begin
1671                         StatusBar.Panels[0].Text := '\94Â\83g\83b\83v\89æ\91\9c\83_\83E\83\93\83\8d\81[\83h\92\86';
1672                         Screen.Cursor := crHourGlass;
1673                         try
1674                                 IdAntiFreeze.Active := True;
1675                                 try
1676                                         Indy.Get(tmpBoard.TitlePictureURL, memStream);
1677                                 finally
1678                                         IdAntiFreeze.Active := False;
1679                                 end;
1680                                 if Indy.ResponseCode = 200 then begin
1681                                         memStream.SaveToFile(tmpBoard.GetTitlePictureFileName);
1682                                         ShowTitlePicture();
1683                                         tmpBoard.Modified := true;
1684                                 end;
1685                         except
1686                         end;
1687                 end;
1688         finally
1689                 Screen.Cursor := crDefault;
1690                 StatusBar.Panels[0].Text := '\94Â\83g\83b\83v\89æ\91\9c (' + IntToStr(Indy.ResponseCode) + ')';
1691                 memStream.Free;
1692         end;
1693
1694         FWork := False;
1695 end;
1696 procedure TEditorForm.ShowTitlePicture();
1697 var
1698         tmpBoard: TBoard;
1699         s: String;
1700 begin
1701         if FThreadItem = nil then
1702                 tmpBoard := FBoard
1703         else
1704                 tmpBoard := FThreadItem.ParentBoard;
1705
1706         if FileExists(tmpBoard.GetTitlePictureFileName) then begin
1707                 TitlePictureBrowser.Navigate(tmpBoard.GetTitlePictureFileName);
1708         end else begin
1709                 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';
1710                 SetContent(s, TitlePictureBrowser);
1711         end;
1712 end;
1713
1714 function TEditorForm.GetFusianaName(body: TStringList; ABoard: TBoard): String;
1715 var
1716         i: Integer;
1717         tmp: string;
1718 begin
1719         for i := 0 to body.Count - 1 do begin
1720                 if (AnsiPos('BBS_NONAME_NAME=', body[i]) > 0) then begin
1721                         tmp := body[i];
1722                         Delete(tmp, 1, AnsiPos('=', tmp));
1723                         Result := tmp;
1724                         Exit;
1725                 end;
1726         end;
1727 end;
1728
1729 procedure TEditorForm.GetHeadTXTActionExecute(Sender: TObject);
1730 var
1731         URL, RefURL: string;
1732         settingBody: TStringList;
1733         tmpBoard: TBoard;
1734 begin
1735         if FWork then
1736                 Exit;
1737         FWork := True;
1738
1739         InitIdHTTP(Indy);
1740         if FThreadItem = nil then
1741                 tmpBoard := FBoard
1742         else
1743                 tmpBoard := FThreadItem.ParentBoard;
1744
1745         if tmpBoard = nil then Exit;
1746
1747         RefURL  := tmpBoard.URL;
1748         if RefURL[Length(RefURL)] <> '/' then
1749                 URL     := RefURL + '/' + 'head.txt'
1750         else
1751                 URL     := RefURL + 'head.txt';
1752
1753         if FileExists(tmpBoard.GETHEADTXTFileName) then
1754                 Indy.Request.LastModified := tmpBoard.HEADTXTTime
1755         else
1756                 Indy.Request.LastModified := ZERO_DATE;
1757
1758         Indy.Request.Referer := RefURL;
1759         Screen.Cursor := crHourGlass;
1760         settingBody := TStringList.Create;
1761         try
1762                 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';
1763                 try
1764                         IdAntiFreeze.Active := True;
1765                         try
1766                                 settingBody.Text := Indy.Get(URL);
1767                         finally
1768                                 IdAntiFreeze.Active := False;
1769                         end;
1770                         if( Indy.ResponseCode = 200 ) then begin
1771                                 settingBody.Insert(0, '<HTML lang="ja"><HEAD>');
1772                                 settingBody.Insert(1, '<META http-equiv="Content-Type" content="text/html; charset=Shift_JIS">');
1773                                 settingBody.Insert(2, '<TITLE>' + tmpBoard.Title + '</TITLE>');
1774                                 settingBody.Insert(3, '<base href="' + RefURL + '"></HEAD><BODY>');
1775                                 settingBody.Add('</BODY></HTML>');
1776                                 settingBody.SaveToFile(tmpBoard.GETHEADTXTFileName);
1777                                 tmpBoard.HEADTXTTime := Indy.Response.LastModified;
1778                                 tmpBoard.IsHEADTXT := true;
1779                                 tmpBoard.Modified := true;
1780                                 StatusBar.Panels[0].Text := '\83\8d\81[\83J\83\8b\83\8b\81[\83\8b\8eæ\93¾\8a®\97¹(' + IntToStr(Indy.ResponseCode) + ')';
1781                         end;
1782                 except
1783                         on E: EIdException do begin
1784                                 if( AnsiPos('304', E.Message) > 0 ) then
1785                                         StatusBar.Panels[0].Text := '\83\8d\81[\83J\83\8b\83\8b\81[\83\8b\8dX\90V\96³\82µ(' + IntToStr(Indy.ResponseCode) + ')'
1786                                 else
1787                                         StatusBar.Panels[0].Text := '\83\8d\81[\83J\83\8b\83\8b\81[\83\8b\8eæ\93¾\83G\83\89\81[(' + IntToStr(Indy.ResponseCode) + ')';
1788                         end;
1789                 end;
1790         finally
1791                 settingBody.Free;
1792                 Screen.Cursor := crDefault;
1793         FWork := False;
1794         end;
1795         if tmpBoard.IsHEADTXT then begin
1796                                 ShowBoardHead(tmpboard, LocalEdit);
1797         end;
1798
1799
1800 end;
1801
1802 procedure TEditorForm.CalcCapacityActionExecute(Sender: TObject);
1803 var
1804         Board: TBoard;
1805         body: String;
1806 begin
1807         body := GetBody;
1808     //\82Ç\82¤\82à\81A\89ü\8ds\95ª\82¸\82ê\82Ä\82½\82Á\82Û\82¢\82¯\82Ç\81A\96{\93\96\82©\82æ\82­\95ª\82©\82ç\82È\82¢\81B
1809         if FThreadItem = nil then
1810                 Board := FBoard
1811         else
1812                 Board := FThreadItem.ParentBoard;
1813
1814         if Board.BoardPlugIn <> nil then
1815                 body := CustomStringReplace(body, #13#10, '<br>')
1816         else
1817                 body := CustomStringReplace(body, #13#10, ' <br> ');
1818         StatusBar.Panels[0].Text := '\97e\97Ê:' + IntToStr(Length(body)) + ' byte';
1819 end;
1820
1821 procedure TEditorForm.LocalRuleClick(Sender: TObject);
1822 var
1823   ini: TIniFile;
1824 begin
1825         ini := TIniFile.Create(GikoSys.Setting.GetFileName);
1826         try
1827                 RocalRuleTab.TabVisible := LocalRule.Checked;
1828                 ini.WriteBool('EditorForm', 'LocalRuleTab', RocalRuleTab.TabVisible);
1829         finally
1830                 ini.Free;
1831         end;
1832 end;
1833
1834 procedure TEditorForm.FormDeactivate(Sender: TObject);
1835 begin
1836         if GikoSys.Setting.GestureEnabled then begin
1837                 MouseGesture.UnHook;
1838                 //MouseGesture.SetHook( GikoForm.Handle );
1839         end;
1840
1841 end;
1842
1843 procedure TEditorForm.OnGestureStart(Sender: TObject);
1844 begin
1845 //
1846 end;
1847
1848 procedure TEditorForm.OnGestureMove(Sender: TObject);
1849 var
1850         s: string;
1851         Action: TAction;
1852         ActStr: string;
1853 begin
1854         s := MouseGesture.GetGestureStr;
1855         ActStr := '';
1856         Action := GikoSys.Setting.Gestures.GetGestureAction(s);
1857         if Action <> nil then
1858                 ActStr := '\81i' + Action.Caption + '\81j';
1859         s := '\83W\83F\83X\83`\83\83\81[: ' + s + ActStr;
1860         StatusBar.Panels[0].Text := s;
1861 end;
1862
1863 procedure TEditorForm.OnGestureEnd(Sender: TObject);
1864 var
1865         s: string;
1866         Action: TAction;
1867 begin
1868         s := MouseGesture.GetGestureStr;
1869         Action := GikoSys.Setting.Gestures.GetGestureAction(s);
1870         if Action <> nil then
1871                 Action.Execute;
1872         StatusBar.Panels[0].Text := '';
1873 end;
1874
1875 procedure TEditorForm.ShowBoardHead(ABoard: TBoard; AMemo: TMemo);
1876 var
1877         wDoc, WTex, le: OLEVariant;
1878 begin
1879                 //\8eQ\8dl\8c³
1880                 //http://www.campus.ne.jp/~ishigami/CREATION/TECHNIC/WEBAP-2.htm
1881                 WebBrowser1.Navigate(ABoard.GETHEADTXTFileName,le,le,le,le);
1882                 //\83\8c\83^\83\8a\83\93\83O\82ª\92x\82·\82¬\82ÄTXT\82É\88Ú\82¹\82È\82¢\81B\82Ê\82é\82Ûorz
1883                 //\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
1884                 //\82±\82ê\82Å\82¢\82¯\82Ü\82µ\82½\81B\82 \82è\82ª\82Æ\82¤\82²\82´\82¢\82Ü\82µ\82½\81B
1885                 while (WebBrowser1.ReadyState <> READYSTATE_COMPLETE) and
1886                                 (WebBrowser1.ReadyState <> READYSTATE_INTERACTIVE) do begin
1887                         Application.ProcessMessages;
1888                 end;
1889                 wDoc := WebBrowser1.Document;
1890                 wTex := wDoc.body.createTextRange;
1891                 LocalEdit.Text := wTex.text;
1892 end;
1893
1894 procedure TEditorForm.LocalRuleBrowseClick(Sender: TObject);
1895 var
1896         URL: String;
1897         ABoard: TBoard;
1898 begin
1899         if FThreadItem = nil then
1900                 ABoard := FBoard
1901         else
1902                 ABoard := FThreadItem.ParentBoard;
1903
1904         if ABoard = nil then Exit;
1905
1906                 URL := ABoard.GETHEADTXTFileName;
1907                 GikoSys.OpenBrowser(URL, gbtAuto);
1908 end;
1909
1910 procedure TEditorForm.SaveNameMailActionExecute(Sender: TObject);
1911 begin
1912         SaveNameMailAction.Checked := not SaveNameMailAction.Checked;
1913         KotehanCheckBox.Enabled := SaveNameMailAction.Checked;
1914 end;
1915
1916 function TEditorForm.LFusianaGet(s: String): Boolean;
1917 var
1918         i: Integer;
1919 begin
1920                 i := AnsiPos('fusianasan', s);
1921                 if (i > 0) then Result := True else Result := False;
1922 end;
1923
1924 procedure TEditorForm.BeLogInOutEActionExecute(Sender: TObject);
1925 begin
1926         GikoSys.Setting.BeLogin := not GikoSys.Setting.BeLogin;
1927 end;
1928
1929 procedure TEditorForm.BeLogInOutEActionUpdate(Sender: TObject);
1930 begin
1931         if (GikoSys.Setting.BeUserID <> '') and (GikoSys.Setting.BeCode <> '') then begin
1932                 if (GikoSys.Setting.BeLogin) then BeLogInOutEAction.Checked := true
1933                 else BeLogInOutEAction.Checked := false;
1934                 BeLogInOutEAction.Enabled := true
1935         end else
1936                 BeLogInOutEAction.Enabled := false;
1937
1938 end;
1939 // Cookie\82Ì\8eæ\93¾
1940 procedure TEditorForm.GetCookie(Rawtext: String; ABoard: TBoard);
1941 const
1942         COOKIE_MARK = 'Set-Cookie:';
1943         VAL_SPID        = 'SPID=';
1944         VAL_PON         = 'PON=';
1945         EXPIRES_MARK = 'expires=';
1946 var
1947 //      i: Integer;
1948         tmp : string;
1949         val : string;
1950 begin
1951         ABoard.Cookie := '';
1952         while  (AnsiPos(COOKIE_MARK, Rawtext) > 0 ) do begin
1953                 //i := 0;
1954                 tmp := Copy(Rawtext, AnsiPos(COOKIE_MARK, Rawtext) + Length(COOKIE_MARK), Length(Rawtext));
1955                 Delete(Rawtext, 1, AnsiPos('Set-Cookie', Rawtext)+ Length(COOKIE_MARK));
1956                 //Cookie\82ð\90Ø\82è\8fo\82·
1957                 val := Trim(GikoSys.GetTokenIndex(tmp, ';', 0));
1958                 if( AnsiPos(VAL_SPID, val) > 0 ) then begin
1959                         ABoard.SPID := Copy(val, AnsiPos(VAL_SPID, val) + Length(VAL_SPID), Length(val));
1960                 end else if( AnsiPos(VAL_PON, val) > 0 ) then begin
1961                         ABoard.PON := Copy(val, AnsiPos(VAL_PON, val) + Length(VAL_PON), Length(val));
1962                 end else begin
1963                         ABoard.Cookie := ABoard.Cookie + val + '; ';
1964                 end;
1965                 //expires\82ð\90Ø\82è\8fo\82·
1966                 val := Trim(GikoSys.GetTokenIndex(tmp, ';', 1));
1967                 if( AnsiPos(EXPIRES_MARK, val) > 0) then begin
1968                         Delete(val, 1, AnsiPos(EXPIRES_MARK, val) + Length(EXPIRES_MARK) - 1);
1969                         ABoard.Expires := GMTToLocalDateTime(val);
1970                 end;
1971         end;
1972 end;
1973
1974
1975 //! \83T\83\93\83o\8dX\90V\82Ì\83A\83N\83V\83\87\83\93\82ÌUpdate\83C\83x\83\93\83g\81@\8aÈ\92P\82Ì\82½\82ß\83^\83C\83}\81[\82Æ\93¯\82\82É\82µ\82Ä\82¨\82­
1976 procedure TEditorForm.UpdateSambaActionUpdate(Sender: TObject);
1977 begin
1978         UpdateSambaAction.Enabled := FSambaTimer.Enabled;
1979 end;
1980
1981 //! \83T\83\93\83o\8dX\90V\83A\83N\83V\83\87\83\93
1982 procedure TEditorForm.UpdateSambaActionExecute(Sender: TObject);
1983 var
1984         input : String;
1985         i : Integer;
1986 begin
1987         if InputQuery('Samba24\90Ý\92è\92l\8dX\90V', '\90V\82µ\82¢\90Ý\92è\92l\82ð\93ü\97Í\82µ\82Ä\82­\82¾\82³\82¢', input) then begin
1988         input := ZenToHan(input);
1989                 if GikoSys.IsNumeric(input) then begin
1990             FSambaTimer.UpdateSambaSetting(StrToInt(input));
1991             UpdateSambaStatus;
1992                         //\91S\82Ä\82Ì\83t\83H\81[\83\80\82©\82ç\81ASamba\83^\83C\83}\81[\82ð\8dX\90V\82·\82é
1993                         for i := 0 to Screen.FormCount - 1 do begin
1994                                 if Screen.Forms[i] is TEditorForm then begin
1995                     TEditorForm(Screen.Forms[i]).FSambaTimer.Update;
1996                     TEditorForm(Screen.Forms[i]).UpdateSambaStatus;
1997                 end;
1998                         end;
1999                 end else begin
2000                         ShowMessage('\90\94\92l\82ð\93ü\97Í\82µ\82Ä\82­\82¾\82³\82¢');
2001                         UpdateSambaActionExecute(Sender);
2002                 end;
2003         end;
2004 end;
2005
2006 procedure TEditorForm.UpdateSambaStatus;
2007 begin
2008     if (FSambaTimer.Enabled) then begin
2009         StatusBar.Panels[2].Text
2010             := 'Samba24\8bK\92è\92l' + IntToStr(FSambaTimer.SambaInterval);
2011     end;
2012 end;
2013
2014 procedure TEditorForm.InputAssistActionExecute(Sender: TObject);
2015 var
2016         count, i : Integer;
2017         item : TMenuItem;
2018         point: TPoint;
2019         Bitmap : TBitmap;
2020         TextWidth, ItemWidth, tmpWidth: Integer;
2021 begin
2022         if FInputAssistKey = '' then Exit;
2023
2024         InputAssistPopupMenu.Items.Clear;
2025
2026         if (FResistWords = nil) then begin
2027                 FResistWords := TStringList.Create;
2028         end else begin
2029                 FResistWords.Clear;
2030         end;
2031
2032         if (GetKeyState( VK_SHIFT ) < 0) then begin
2033                 // \83V\83t\83g\82ª\89\9f\82³\82ê\82Ä\82¢\82ê\82Î\81A\83L\81[\82Å\8en\82Ü\82é\83J\83e\83S\83\8a
2034                 count :=
2035                         InputAssistDM.GetStartWithCategoryResistWords(
2036                                                                         FInputAssistKey, FResistWords);
2037         end else begin
2038                 // \83V\83t\83g\82ª\96³\82¢\82Ì\82Å\81A\83L\81[\82Å\8en\82Ü\82é\83L\81[
2039                 count :=
2040                         InputAssistDM.GetStartWithKeyResistWords(
2041                                                                         FInputAssistKey, FResistWords);
2042         end;
2043         Bitmap := TBitmap.Create;
2044         try
2045                 Bitmap.Canvas.Font.Assign(BodyEdit.Font);
2046                 // \83}\81[\83W\83\935px
2047                 TextWidth := Bitmap.Canvas.TextWidth(FInputAssistKey) + 5;
2048                 ItemWidth := 0;
2049                 for i := 0 to count - 1 do begin
2050                         item := TMenuItem.Create(nil);
2051                         item.Break := mbNone;
2052                         item.Caption := FResistWords[i];
2053                         item.Tag := i;
2054                         item.OnClick := InputAssistMenuClick;
2055                         InputAssistPopupMenu.Items.Add(item);
2056
2057                         tmpWidth := Bitmap.Canvas.TextWidth(Item.Caption);
2058                         if (tmpWidth > ItemWidth) then begin
2059                                 ItemWidth := tmpWidth;
2060                         end;
2061                 end;
2062         finally
2063                 Bitmap.Free;
2064         end;
2065
2066         if (count > 0) then begin
2067                 GetCaretpos(point);
2068                 point.X := point.X + Self.Left + (Self.Width - BodyEdit.Width) div 2;
2069                 point.Y := point.Y + Self.Top + (Self.Height - Self.ClientHeight);
2070
2071                 if Screen.DesktopWidth >
2072                         (point.X + TextWidth + ItemWidth) then begin
2073                         InputAssistPopupMenu.Popup(
2074                                 point.X + TextWidth,
2075                                 point.Y + EditorPage.Top + EditorPage.TabHeight + BodyEdit.Top);
2076                 end else begin
2077                         InputAssistPopupMenu.Popup(
2078                                 point.X - TextWidth - ItemWidth,
2079                                 point.Y + EditorPage.Top + EditorPage.TabHeight + BodyEdit.Top);
2080                 end;
2081         end;
2082 end;
2083
2084 procedure TEditorForm.InputAssistMenuClick(Sender: TObject);
2085 var
2086         text : String;
2087         IMC: HIMC;
2088 begin
2089         if not (Sender is TMenuItem) then Exit;
2090
2091         if (FResistWords <> nil) then begin
2092                 try
2093                         text :=
2094                                 TResistWord(FResistWords.Objects[TMenuItem(Sender).Tag]).GetText;
2095                 except
2096                         text := '';
2097                 end;
2098                 IMC := ImmGetContext(BodyEdit.Handle); //\83R\83\93\83e\83L\83X\83g\8eæ\93¾
2099                 try
2100                         ImmNotifyIME(IMC, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
2101                 finally
2102                         ImmReleaseContext(BodyEdit.Handle, IMC);  //\83R\83\93\83e\83L\83X\83g\89ð\95ú
2103                 end;
2104
2105                 FResistWords.Clear;
2106                 FInputAssistKey := '';
2107         end;
2108         InsertText(BodyEdit, text);
2109 end;
2110
2111 //! TMemo\82Ì\83J\81[\83\\83\8b\88Ê\92u\82É\95\8e\9a\97ñ\91}\93ü
2112 procedure TEditorForm.InsertText(Memo: TMemo; Text: String);
2113 var
2114         line, sel, pos: Integer;
2115         left, right : String;
2116 begin
2117         Memo.Lines.BeginUpdate;
2118         line := SendMessage(Memo.Handle,EM_LINEFROMCHAR,-1,0);  //\8ds
2119         sel := Memo.SelStart;
2120         pos     := sel - SendMessage(Memo.Handle, EM_LINEINDEX, -1, 0); //\8c\85
2121         if (pos > 0) then begin
2122                 left := Copy(Memo.Lines[line], 0, pos);
2123         end else begin
2124                 left := '';
2125         end;
2126         right := Copy(Memo.Lines[line], pos + 1, Length(Memo.Lines[line]));
2127         Memo.Lines.Strings[line] := left + Text + right;
2128         Memo.Lines.EndUpdate;
2129         //\81@\83L\83\83\83\8c\83b\83g\82Ì\88Ê\92u\82ð\8dX\90V\82·\82é
2130         Memo.SelStart := sel + Length(text);
2131         // \83L\83\83\83\8c\83b\83g\82Ì\88Ê\92u\82Ü\82Å\83X\83N\83\8d\81[\83\8b
2132         Memo.Perform(EM_SCROLLCARET, 0, 0);
2133
2134 end;
2135
2136 procedure TEditorForm.ApplicationEvents1Message(var Msg: tagMSG;
2137   var Handled: Boolean);
2138 var
2139         wmMsg: TWMKey;
2140         IMC: HIMC;
2141         Len: integer;
2142         Str: string;
2143 begin
2144         if (Self.Active) then begin
2145                 case Msg.message of
2146                         //\83L\81[\89\9f\89º\82Ì\82Ý\8eó\82¯\8eæ\82é
2147                         WM_KEYDOWN:
2148                         begin
2149                                 // \83^\83u\82ª\81h\95Ò\8fW\81h\82ÅCtrl\83L\81[\82ª\89\9f\82³\82ê\82Ä\82¢\82é\82Ì\82ð\8am\94F\82·\82é
2150                                 if (EditorPage.ActivePageIndex = 0)
2151                                                 and (GetKeyState( VK_CONTROL ) < 0) then begin
2152                                         wmMsg.Msg := Msg.message;
2153                                         wmMsg.CharCode := Word(Msg.wParam);
2154                                         wmMsg.KeyData := Msg.lParam;
2155                                         if (wmMsg.CharCode = 229) and (wmMsg.KeyData = 3735553) then begin
2156                                                 IMC := ImmGetContext(BodyEdit.Handle); //\83R\83\93\83e\83L\83X\83g\8eæ\93¾
2157                                                 Len := ImmGetCompositionString(IMC, GCS_COMPSTR, nil, 0); //\82Ü\82¸\92·\82³\82ð\8eæ\93¾
2158                                                 if (Len > 0) then begin
2159                                                         SetLength(Str, Len + 1); //Buffer\82Ì\83\81\83\82\83\8a\82ð\90Ý\92è
2160                                                         ImmGetCompositionString(IMC, GCS_COMPSTR, PChar(Str), Len + 1); //\82Ü\82¸\92·\82³\82ð\8eæ\93¾
2161                                                         SetLength(Str, Len);
2162                                                         FInputAssistKey := Str;
2163                                                         InputAssistActionExecute(nil);
2164                                                         Handled := True;
2165                                                 end;
2166                                                 ImmReleaseContext(BodyEdit.Handle, IMC);  //\83R\83\93\83e\83L\83X\83g\89ð\95ú
2167                                         end;
2168                                 end;
2169                         end;
2170                 end;
2171
2172         end;
2173 end;
2174
2175 procedure TEditorForm.ShowInputAssistFormExecute(Sender: TObject);
2176 var
2177         form : TInputAssistForm;
2178 begin
2179         form := TInputAssistForm.Create(nil);
2180         try
2181                 if TopAction.Checked then begin // \83X\83e\83C\8fó\91Ô\82É\90Ý\92è
2182                         SetWindowPos(form.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE);
2183         end;
2184                 form.SetUpFromEditor;
2185                 if (form.ShowModal = mrOk) then begin
2186                         InsertText(BodyEdit, form.GetInsertText);
2187                 end;
2188         finally
2189                 form.Release;
2190         end;
2191 end;
2192 //! Cookie\8fî\95ñ\8dí\8f\9c
2193 procedure TEditorForm.ReleaseCookieActionExecute(Sender: TObject);
2194 var
2195         Board : TBoard;
2196 begin
2197         // \83X\83\8c\83b\83h\82ª\96³\82¢\81@\83X\83\8c\97§\82Ä\82Ì\82Æ\82«\82ÍFBoard\82ð\92¼\90Ú\8eg\82¤
2198         if FThreadItem = nil then begin
2199                 Board := FBoard
2200         end else begin
2201                 Board := FThreadItem.ParentBoard;
2202         end;
2203
2204         // \83N\83b\83L\81[\82Ì\8fî\95ñ\82ð\8eÌ\82Ä\82é
2205         Board.Cookie := '';
2206         Board.SPID := '';
2207         Board.PON  := '';
2208         // 0\82É\8aª\82«\96ß\82·
2209         Board.Expires := 0;
2210 end;
2211 //! \94Â\8fî\95ñ\8eæ\93¾Update\83C\83x\83\93\83g
2212 procedure TEditorForm.GetSETTINGTXTActionUpdate(Sender: TObject);
2213 begin
2214         // \8eÀ\8ds\92\86\82Í\8eÀ\8ds\95s\89Â
2215         GetSETTINGTXTAction.Enabled := not FWork;
2216 end;
2217 //! \83\8d\81[\83J\83\8b\83\8b\81[\83\8b\8eæ\93¾Update\83C\83x\83\93\83g
2218 procedure TEditorForm.GetHeadTXTActionUpdate(Sender: TObject);
2219 begin
2220         // \8eÀ\8ds\92\86\82Í\8eÀ\8ds\95s\89Â
2221         GetSETTINGTXTAction.Enabled := not FWork;
2222 end;
2223
2224 //! Samba\83^\83C\83}\81[\83C\83x\83\93\83g
2225 procedure TEditorForm.SambaTimer(Sender: TObject);
2226 begin
2227
2228         if FSambaTimer.WriteDeta = ZERO_DATE then
2229                 StatusBar.Panels[1].Text := '\8f\89\8f\91'
2230         else begin
2231                 FNow := IncMilliSecond(FNow, 500);
2232                 StatusBar.Panels[1].Text :=
2233             Format('%8.0f\95b\8co\89ß', [SecondSpan(FNow, FSambaTimer.WriteDeta)]);
2234         end;
2235 end;
2236 {
2237 \brief \83E\83B\83\93\83h\83E\82Ì\88Ê\92u\82Æ\83T\83C\83Y\82Ì\90Ý\92è
2238 }
2239 procedure TEditorForm.SetWindowRect;
2240 var
2241     wp: TWindowPlacement;
2242 begin
2243         //\83E\83B\83\93\83h\83E\82Ì\88Ê\92u\90Ý\92è
2244         wp.length := sizeof(wp);
2245         wp.rcNormalPosition.Top := GikoSys.Setting.EditWindowTop;
2246         wp.rcNormalPosition.Left := GikoSys.Setting.EditWindowLeft;
2247
2248         wp.rcNormalPosition.Bottom := GikoSys.Setting.EditWindowTop + GikoSys.Setting.EditWindowHeight;
2249         wp.rcNormalPosition.Right := GikoSys.Setting.EditWindowLeft + GikoSys.Setting.EditWindowWidth;
2250         wp.showCmd := SW_HIDE;
2251         SetWindowPlacement(Handle, @wp);
2252
2253         if GikoSys.Setting.EditWindowMax then begin
2254                 WindowState := wsMaximized;
2255     end;
2256
2257         //\83E\83B\83\93\83h\83E\82ª\89æ\96Ê\8aO\82È\82ç\89æ\96Ê\93à\82É\88Ú\93®\82·\82é
2258         if (Left + Width) > Screen.Width then begin
2259                 Left := 0;
2260     end;
2261         if (Top + Height) > Screen.Height then begin
2262                 Top := 0;
2263     end;
2264         if Left < 0 then begin
2265                 Left := 0;
2266     end;
2267         if Top < 0 then begin
2268                 Top := 0;
2269     end;
2270
2271     //\8c»\8dÝ\82Ì\83E\83B\83\93\83h\83E\82Ì\88Ê\92u\82ð\95Û\91
2272     GikoSys.Setting.EditWindowTop := Top  + WINDOWMOVE_V;   // \8e\9f\82É\8aJ\82­\83E\83B\83\93\83h\83E\82Í
2273     GikoSys.Setting.EditWindowLeft := Left + WINDOWMOVE_H;  // \81@\81@\81@\89E\8eÎ\82ß\89º\82É\82¸\82ç\82·
2274     //\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·
2275         if GikoSys.Setting.EditWindowHeight < 144 then begin
2276                 Height := 400;
2277     end;
2278         if GikoSys.Setting.EditWindowWidth < 144 then begin
2279                 Width := 640;
2280     end;
2281 end;
2282 {
2283 \brief \8ag\92£\83^\83u\90Ý\92è
2284 }
2285 procedure TEditorForm.SetExtraTab;
2286 const
2287     SECTION = 'EditorForm';
2288 var
2289     ini: TMemIniFile;
2290 begin
2291     ini := TMemIniFile.Create(GikoSys.Setting.GetFileName);
2292     try
2293         BoardtopTab.TabVisible := ini.Readbool(SECTION, 'BoardTopTab', False);
2294         BoardTop.Checked := BoardtopTab.TabVisible;
2295         RocalRuleTab.TabVisible := ini.ReadBool(SECTION, 'LocalRuleTab', False);
2296         LocalRule.Checked := RocalRuleTab.TabVisible;
2297     finally
2298         ini.Free;
2299     end;
2300 end;
2301
2302 end.