📄 messengermainformu.pas
字号:
procedure TMessengerMainForm.HandleReadOnlyOn;
begin
FReadOnlyHandled := True;
if not JvRichEdit1.ReadOnly then
begin
{ cheap effect :-p }
JvRichEdit1.Color := clRed;
Application.ProcessMessages;
Sleep(50);
JvRichEdit1.ReadOnly := True;
JvRichEdit1.Color := clWindow;
end;
end;
procedure TMessengerMainForm.OnEmoticonClick(Sender: TObject);
begin
if Sender is TAction then
AddImageToEdit(TAction(Sender).ImageIndex);
end;
procedure TMessengerMainForm.ParseString(const S: string);
var
P, Q: PChar;
State: Integer;
procedure AddImage(const SmileIndex, SmileLength: Integer);
begin
AddTextToRichEdit(Q, P - Q - SmileLength + 1, FCurrentFont);
AddImageToRichEdit(SmileIndex);
State := 0;
Q := P + 1;
end;
begin
P := PChar(S);
Q := P;
State := 0;
// State = 1.. then looking at ":-A" with A = @x)( etc.
// 10.. "LOL"
// 20.. "O :-)"
// 30.. "(blush)"
// 40.. ":'-("
// 50.. "8-)"
// 60.. ";-)"
// 70.. "readonly"
// 80.. "read-only on" or "read-only off"
//
// State = 1 -> ":" read
// State = 2 -> ":-" read
// State = 11 -> "LO" read
// State = 22 -> "O :" read
// State = 23 -> "O :-" read
//
// etc.
while P^ <> #0 do
begin
case P^ of
'$':
if State in [2, 23] then
AddImage(9, 3) // :-$
else
State := 0;
'&':
if State in [2, 23] then
AddImage(4, 3) // :-&
else
State := 0;
'(':
case State of
1, 22: AddImage(5, 2); // :(
2, 23: AddImage(5, 3); // :-(
40: AddImage(2, 3); // :,(
41: AddImage(2, 4); // :'-(
else
State := 30;
end;
')':
case State of
1, 22: AddImage(11, 2); // :)
2: AddImage(11, 3); // :-)
23: AddImage(6, 5); // O :-)
35: AddImage(3, 7); // (blush)
51: AddImage(1, 3); // 8-)
61: AddImage(15, 3); // ;-)
else
State := 0;
end;
'*':
if State = 1 then
AddImage(7, 2) // :*
else
State := 0;
',':
if State in [1, 22] then
State := 40
else
State := 0;
'-':
case State of
1, 22, 40, 50, 60: Inc(State);
73: State := 80;
else
State := 0;
end;
'8': State := 50;
'"': State := -1; // to prevent "read.." etc will be triggered by the program
':':
if State = 21 then
State := 22
else
State := 1;
';': State := 60;
'@':
case State of
1, 22: AddImage(0, 2); // :@
2, 23: AddImage(0, 3) // :-@
else
State := 0;
end;
'D':
case State of
1, 22: AddImage(8, 2); // :D = LOL
2, 23: AddImage(8, 3) // :-D = LOL
else
State := 0;
end;
'L':
if State = 11 then
AddImage(8, 3) // LOL
else
State := 10;
'O':
if State = 10 then
State := 11
else
State := 20;
'\', '/':
if State in [2, 23] then
AddImage(14, 3) // :-\
else
State := 0;
'a':
if State = 71 then
State := 72
else
State := 0;
'b':
if State = 30 then
State := 31
else
State := 0;
'd':
if State = 72 then
State := 73
else
State := 0;
'e':
if State = 70 then
State := 71
else
State := 0;
'f':
case State of
86: State := 87;
87: HandleReadOnlyOff;
else
State := 0;
end;
'h':
if State = 34 then
State := 35
else
State := 0;
'l':
if State in [31, 75, 82] then
Inc(State)
else
State := 0;
'n':
case State of
74, 81: Inc(State);
86: HandleReadOnlyOn;
else
State := 0;
end;
'o':
case State of
2, 23: AddImage(12, 3); // :-o
73, 80, 85: Inc(State);
else
State := 0;
end;
'p':
if State in [2, 23] then
AddImage(13, 3) // :-p
else
State := 0;
'r':
if State <> -1 then
State := 70
else
State := 0;
's':
if State = 33 then
State := 34
else
State := 0;
'u':
if State = 32 then
State := 33
else
State := 0;
'x', 'X':
if State in [2, 23] then
AddImage(10, 3) // :-x
else
State := 0;
'y':
case State of
76: HandleReadOnly;
83: State := 84;
else
State := 0;
end;
' ':
case State of
20, 84: Inc(State);
11: State := 21;
else
State := 0;
end;
end;
Inc(P);
end;
if Q < P then
AddTextToRichEdit(Q, P - Q, FCurrentFont);
end;
procedure TMessengerMainForm.SendString(const S: string; const You: Boolean);
var
OldActive: TWinControl;
begin
OldActive := ActiveControl;
try
{ Ensure rich edit control is focused before moving }
FocusControl(JvRichEdit1);
{ Goto end }
JvRichEdit1.SetSelection(MaxInt, MaxInt, False);
if You then
begin
FHeaderFont.Color := clRed;
AddTextToRichEdit('You: ', 5, FHeaderFont);
Inc(FYourLines);
end
else
begin
FHeaderFont.Color := clGreen;
AddTextToRichEdit('JVCL: ', 5, FHeaderFont);
FYourLines := 0;
end;
ParseString(S + #13#10);
{ Goto end & scroll }
JvRichEdit1.SetSelection(MaxInt, MaxInt, True);
finally
FocusControl(OldActive);
end;
end;
procedure TMessengerMainForm.Timer1Timer(Sender: TObject);
const
CLameResponse: array[0..4] of string = (
'What?',
'Huh??',
':)',
'Really :-o',
'Good 8-)');
begin
if Random(10 * (1 + FYourLines)) < 9 then
Exit;
if FReadOnlySend and not FReadOnlyHandled then
begin
SendString(ReadOnlyMessages[2], False);
FReadOnlyHandled := True;
end
else
if FYourLines = 0 then
SendString('Hello :-@', False)
else
if Random(10) < 4 then
begin
if JvRichEdit1.ReadOnly then
SendString(ReadOnlyMessages[0], False)
else
begin
SendString(ReadOnlyMessages[1], False);
ReadOnlyMessages[1] := 'read-only on :-p';
end;
end
else
SendString(CLameResponse[Random(5)], False);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -