OSDN Git Service

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