OSDN Git Service

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