-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathuTmpMessage.pas
362 lines (337 loc) · 11.9 KB
/
uTmpMessage.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
unit uTmpMessage;
{******************************************************************************}
{* Template Message Unit *}
{* Revolutionary Confederation of Anarcho Syndicalists *}
{* Written by: black.rabbit 2011 *}
{******************************************************************************}
interface
{$I 'std.inc'}
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, ComCtrls, StdCtrls, RxRichEd, RichEdit,
sFrameAdapter,
sPanel, sScrollBox, sLabel, Buttons, sSpeedButton, acPNG, jpeg;
const
clQuote = $f4f4f4;
type
TMessageText = class (TRxRichEdit)
private
OwnParent : TWinControl;
protected
procedure Change; override;
public
constructor Create (anOwner: TWinControl; const aName: String); overload; virtual;
end;
CTmpMessage = class of TTmpMessage;
PTmpMessage = ^TTmpMessage;
TTmpMessage = class (TFrame)
FrameAdapter: TsFrameAdapter;
FpnlMsg: TsPanel;
FimgBottomLeft: TImage;
FimgBottomRight: TImage;
FimgTop: TImage;
FimgRight: TImage;
FimgBack: TImage;
FimgTopLeft: TImage;
FlbAuthor: TsWebLabel;
FimgAuthor: TImage;
FimgClip: TImage;
FimgBullet: TImage;
FimgBottom: TImage;
FimgTopRight: TImage;
FimgLeft: TImage;
FlbCaption: TsWebLabel;
FpnlButtons: TsPanel;
FbtEdit: TsSpeedButton;
FbtDelete: TsSpeedButton;
FbtQuote: TsSpeedButton;
procedure FrameResize (Sender: TObject);
procedure FrameMouseActivate (Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y, HitTest: Integer;
var MouseActivate: TMouseActivate);
procedure FpnlMsgPaint (Sender: TObject; Canvas: TCanvas);
procedure FbtEditClick (Sender: TObject);
procedure FbtDeleteClick (Sender: TObject);
procedure FbtQuoteClick (Sender: TObject);
public
FedMsg: TMessageText;
public
class procedure _raise (anArgs: array of const;
const anEGUID: String = ''); overload; virtual;
class procedure _raise (anArgs: array of const;
anEGUID: array of const); overload; virtual;
private
f_Index: WORD;
f_Data: Pointer;
f_Created: Boolean;
f_Loaded: Boolean;
f_Adapter: TsFrameAdapter;
f_pnlMsg: TsPanel;
f_lbCaption: TsWebLabel;
f_edMsg: TMessageText;
f_lbAuthor: TsWebLabel;
f_imgAuthor: TImage;
f_imgClip: TImage;
f_imgBullet: TImage;
f_pnlButtons: TsPanel;
f_btEdit: TsSpeedButton;
f_btDelete: TsSpeedButton;
f_btQuote: TsSpeedButton;
public
constructor Create (anOwner: TWinControl;
const anIndex: WORD); overload; virtual;
destructor Destroy; override;
public
procedure Load; virtual;
//procedure AlphaShow (const wTime: WORD);
public
property Index: WORD read f_Index;
property Data: Pointer read f_Data write f_Data;
property Created: Boolean read f_Created write f_Created;
property Loaded: Boolean read f_Loaded write f_Loaded;
property edMsg: TMessageText read f_edMsg;
end;
resourcestring
ERR_TTMPMESSAGE_CREATE = 'Îøèáêà ñîçäàíèÿ øàáëîíà ñîîáùåíèÿ!';
ERR_TTMPMESSAGE_DESTROY = 'Îøèáêà óíè÷òîæåíèÿ øàáëîíà ñîîáùåíèÿ!';
ERR_TTMPMESSAGE_LOAD = 'Îøèáêà çàãðóçêè øàáëîíà ñîîáùåíèÿ!';
ERR_TTMPMESSAGE_ON_RESIZE = 'Îøèáêà èçìåíåíèÿ ðàçìåðîâ øàáëîíà ñîîáùåíèÿ!!';
ERR_TTMPMESSAGE_ON_ACTIVATE = 'Îøèáêà àêòèâàöèè øàáëîíà ñîîáùåíèÿ!';
implementation
{$R *.dfm}
uses
{ utils }
Utils, Strings, BBCode, Versions, VarRecs,
EClasses,
{ engine }
Engine,
{ SQLite }
SQLite3, SQLite3DLL, SQLiteTable3,
{ main window }
uMain,
{ smiles }
uSmileDialog;
constructor TMessageText.Create (anOwner: TWinControl; const aName: String);
begin
inherited Create (anOwner);
Parent := anOwner;
OwnParent := Parent;
while not ( ( OwnParent is TForm ) or ( OwnParent is TFrame ) ) do
begin
if Assigned (OwnParent.Parent) then
OwnParent := OwnParent.Parent;
end;
Name := aName;
ParentColor := FALSE;
ParentFont := FALSE;
Color := clWhite;
Font.Name := 'Calibri';
Font.CharSet := RUSSIAN_CHARSET;
Font.Style := [fsBold];
Font.Size := 12;
BorderStyle := bsNone;
ScrollBars := TScrollStyle (ssNone);
WordWrap := TRUE;
ReadOnly := TRUE;
end;
procedure TMessageText.Change;
var
LineHeight : Integer;
DC : HDC;
SaveFont : HFont;
Metrics : TTextMetric;
begin
inherited Change;
DC := GetDC (Handle);
SaveFont := SelectObject (DC,Font.Handle);
GetTextMetrics (DC, Metrics);
SelectObject (DC, SaveFont);
ReleaseDC (Handle,DC);
LineHeight := Metrics.tmHeight;
OwnParent.Height := ( Lines.Count + 1 ) * LineHeight +
(OwnParent.Height - Height);
end;
class procedure TTmpMessage._raise (anArgs: array of const;
const anEGUID: String = '');
begin
raise EClass.Create ( _([self],anArgs), anEGUID );
end;
class procedure TTmpMessage._raise (anArgs: array of const;
anEGUID: array of const);
begin
raise EClass.Create ( _([self],anArgs), anEGUID );
end;
constructor TTmpMessage.Create (anOwner: TWinControl;
const anIndex: WORD);
var
I : Integer;
begin
try
Created := FALSE;
inherited Create (anOwner);
Color := $00211A18;
Parent := anOwner;
Align := alTop;
PopupMenu := MainForm.mnMessagesPopup;
OnMouseWheel := MainForm.OnMouseWheel;
f_Data := CreateMessageNode;
f_Loaded := FALSE;
{ ñîçäàåì òåêñòîâîå ïîëå }
FedMsg := TMessageText.Create (FpnlMsg,'edMsg');
FedMsg.Align := alClient;
FedMsg.AlignWithMargins := TRUE;
FedMsg.Margins.Top := 42;
FedMsg.Margins.Left := 86;
FedMsg.Margins.Right := 8;
FedMsg.Margins.Bottom := 0;
FedMsg.OnMouseWheel := MainForm.OnMouseWheel;
{ êíîïêè }
FbtEdit.OnMouseMove := MainForm.OnButtonMove;
FbtDelete.OnMouseMove := MainForm.OnButtonMove;
FbtQuote.OnMouseMove := MainForm.OnButtonMove;
{ ñîõðàíÿåì óêçàòåëè }
f_Adapter := FrameAdapter;
f_pnlMsg := FpnlMsg;
f_lbCaption := FlbCaption;
f_edMsg := FedMsg;
f_lbAuthor := FlbAuthor;
f_imgAuthor := FimgAuthor;
f_imgClip := FimgClip;
f_imgBullet := FimgBullet;
f_pnlButtons := FpnlButtons;
f_btEdit := FbtEdit;
f_btDelete := FbtDelete;
f_btQuote := FbtQuote;
{ ïåðèìåíîâûâàåì êîìïîíåíòû â ñîîòâåòñòâèè ñ èíäåêñîì øàáëîíà }
f_Index := anIndex;
for I := 0 to ComponentCount - 1 do
Components [I].Name := Format ('%s_%d',[ Components [I].Name, anIndex ]);
Name := Format ('%s_%d',[Name,anIndex]);
Created := TRUE;
except on E: Exception do
_raise (['Create',ERR_TTMPMESSAGE_CREATE,E],
['{C1CBB232-2D3D-40D4-AC5D-CFF2D3360BEC}']);
end;
end;
destructor TTmpMessage.Destroy;
begin
try
FreeMessageNode (f_Data);
inherited Destroy;
except on E: Exception do
_raise (['Destroy',ERR_TTMPMESSAGE_DESTROY,E],
['{D7969E9B-95C3-4DA9-87F4-8292B8EF921D}']);
end;
end;
procedure TTmpMessage.FrameResize (Sender: TObject);
begin
try
if Assigned (Data) and Created then
begin
f_edMsg.Change;
end;
except on E: Exception do
_raise (['FrameResize',ERR_TTMPMESSAGE_ON_RESIZE,E],
['{5F8FDF73-6840-4918-B71B-98C6F7609B81}']);
end;
end;
procedure TTmpMessage.FbtEditClick (Sender: TObject);
begin
if MainForm.actEditMessage.Enabled then
MainForm.actEditMessage.Execute;
end;
procedure TTmpMessage.FbtDeleteClick (Sender: TObject);
begin
if MainForm.actDeleteMessage.Enabled then
MainForm.actDeleteMessage.Execute;
end;
procedure TTmpMessage.FbtQuoteClick (Sender: TObject);
begin
MainForm.actQuoteMessage.Update;
if MainForm.actQuoteMessage.Enabled then
MainForm.actQuoteMessage.Execute;
end;
procedure TTmpMessage.Load;
var
Author : TUser;
BBCode : String;
begin
try
if Assigned (Data) and Created and not Loaded then
begin
{ çàãîëîâîê }
f_lbCaption.Caption := Format ('%s : %s',
[ PMessageNode (Data)^.Subject,
_DateTimeToStr (PMessageNode (Data)^.TimeStampModify) ]);
{ òåêñò }
f_edMsg.Clear;
BBCode := StrPas ( PMessageNode (Data)^.Text );
try
MarkQuotes (BBCode,clQuote);
InsertBBCode (f_edMsg,BBCode);
InsertQuotes (f_edMsg,MainForm.imgQuotes,clQuote);
InsertSmiles (f_edMsg,SMILES,MainForm.GetImgSmiles);
InsertSmiles (f_edMsg,SMILES_ADVANCED,MainForm.imgSmilesAdvanced);
finally
_FillChar ( BBCode, Length (BBCode), $00 );
end;
//f_edMsg.DefAttributes.Color := clBlack;
//f_edMsg.DefAttributes.Name := 'Arial';
f_edMsg.DefAttributes.CharSet := RUSSIAN_CHARSET;
//f_edMsg.DefAttributes.Style := [fsBold];
//f_edMsg.DefAttributes.Size := 10;
//f_edMsg.DefAttributes.Protected := TRUE;
f_edMsg.PopupMenu := MainForm.mnTextPopup;
f_edMsg.OnMouseDown := MainForm.OnRichEditMouseDown;
{ àâòîð }
f_lbAuthor.Caption := PMessageNode (Data)^.Author;
f_imgAuthor.Picture.Bitmap.FreeImage;
if ( PMessageNode (Data)^.IDAuthor > 0 ) then
begin
Author := TUser.Load ( MainForm.DB, PMessageNode (Data)^.IDAuthor ) as TUser;
try
if Assigned (Author) and
Assigned (Author.Pic) and
Assigned (Author.Pic.Picture) then
f_imgAuthor.Picture.Assign (Author.Pic.Picture);
finally
FreeAndNil (Author);
end;
end;
{ êíîïêè }
f_btEdit.Visible := ( PMessageNode (Data)^.IDAuthor = USER_ID );
f_btDelete.Visible := ( PMessageNode (Data)^.IDAuthor = USER_ID );
{ èêîíêè ñîîáùåíèÿ }
f_imgClip.Visible := ( Index mod 2 <> 0 );
f_imgBullet.Visible := ( Index mod 2 = 0 );
Loaded := TRUE;
end;
except on E: Exception do
_raise (['Load',ERR_TTMPMESSAGE_LOAD,E],
['{A0EEDDDF-501D-432A-B624-AA5D4250B9B1}']);
end;
end;
procedure TTmpMessage.FpnlMsgPaint (Sender: TObject; Canvas: TCanvas);
begin
Load;
end;
procedure TTmpMessage.FrameMouseActivate (Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y, HitTest: Integer;
var MouseActivate: TMouseActivate);
begin
try
if Assigned (Data) then
begin
MainForm.CurrMsgID := PMessageNode (Data)^.ID;
MainForm.CurrMsgKeyHash := PMessageNode (Data)^.KeyHash;
MainForm.CurrMsgTmp := Self;
MainForm.edURL.Text := Format ('crypto://categorie/%s#%s/',
[ MainForm.CurrCtgKeyHash,
MainForm.CurrMsgKeyHash]);
end;
except on E: Exception do
_raise (['FrameMouseActivate',ERR_TTMPMESSAGE_ON_ACTIVATE,E],
['{9BCD887F-F501-4004-B327-2BA07269909B}']);
end
end;
end.