/usr/lib/lazarus/0.9.30.4/ideintf/maskpropedit.pas is in lazarus-src-0.9.30.4 0.9.30.4-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | { Copyright (C) 2005
*****************************************************************************
* *
* See the file COPYING.modifiedLGPL.txt, included in this distribution, *
* for details about the copyright. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
*****************************************************************************
Author: Lagunov Aleksey
Abstract:
Property Editors for TMaskEdit.EditMask of FCL and LCL.
}
unit MaskPropEdit;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, MaskUtils, Forms, Controls, Graphics, Dialogs,
StrUtils, StdCtrls, Buttons, ExtCtrls, FileUtil, MaskEdit, LazIDEIntf,
PropEdits, ComponentEditors, ObjInspStrConsts, ButtonPanel;
type
{ TMaskEditorForm }
TMaskEditorForm = class(TForm)
ButtonPanel1: TButtonPanel;
LoadSampleMasksButton: TButton;
SaveLiteralCheckBox: TCheckBox;
InputMaskEdit: TEdit;
CharactersForBlanksEdit: TEdit;
InputMaskLabel: TLabel;
SampleMasksLabel: TLabel;
CharactersForBlanksLabel: TLabel;
TestInputLabel: TLabel;
SampleMasksListBox: TListBox;
TestMaskEdit: TMaskEdit;
OpenDialog1: TOpenDialog;
TestInputPanel: TPanel;
procedure LoadSampleMasksButtonClick(Sender: TObject);
procedure SampleMasksListBoxDrawItem(Control: TWinControl; Index: Integer;
ARect: TRect; State: TOwnerDrawState);
procedure SaveLiteralCheckBoxClick(Sender: TObject);
procedure InputMaskEditChange(Sender: TObject);
procedure CharactersForBlankEditChange(Sender: TObject);
procedure SampleMasksListBoxClick(Sender: TObject);
procedure MaskEditorFormCreate(Sender: TObject);
private
function ConstructEditmask: String;
function GetEditMask: string;
procedure LoadDEMFile(AFileName: string);
procedure ReConstructEditmask;
procedure SetEditMask(AValue: string);
function SplitMask(AMask: String; out MaskText: String; out
SaveLiterals: Boolean; out BlankChar: Char): Boolean;
procedure UpdateTestEditor;
public
property EditMask: string read GetEditMask write SetEditMask;
end;
{ TEditMaskProperty }
TEditMaskProperty = class(TStringPropertyEditor)
public
function GetAttributes: TPropertyAttributes; override;
procedure Edit; override;
end;
{ TMaskEditEditor }
TMaskEditEditor = class(TDefaultComponentEditor)
public
procedure ExecuteVerb(Index: Integer); override;
function GetVerb(Index: Integer): string; override;
function GetVerbCount: Integer; override;
function MaskEdit: TCustomMaskEdit; virtual;
end;
implementation
{$R *.lfm}
procedure ParseMaskLine(Line: String; out Caption, Example, Mask: String);
begin
// in delphi .dem files every mask line contains:
// mask name|mask example|mask
// 1. Extract caption from Line
Caption := Copy(Line, 1, Pos(' | ', Line) - 1);
Delete(Line, 1, Length(Caption) + 3);
// 2. Extract example from Line
Example := Copy(Line, 1, Pos(' | ', Line) - 1);
Delete(Line, 1, Length(Example) + 3);
// 3. Copy what we have to Mask
Mask := Line;
end;
function MaskDoFormatText(const EditMask: string; const Value: string; Blank: Char): String;
var
P: Integer;
S: String;
begin
// cheat maskutils while it has no its own MaskDoFormatText
S := EditMask;
P := LastDelimiter(';', S);
if P <> 0 then
begin
S[P + 1] := Blank;
dec(P);
while (P > 0) and (S[P] <> ';') do
dec(P);
if P <> 0 then
S[P + 1] := '0';
end;
try
Result := FormatMaskText(S, Value);
except
Result := Value;
end;
end;
{ TMaskEditorForm }
procedure TMaskEditorForm.LoadSampleMasksButtonClick(Sender: TObject);
begin
OpenDialog1.InitialDir:=ExtractFileDir(ParamStrUTF8(0));
if OpenDialog1.Execute then
LoadDEMFile(OpenDialog1.FileName);
end;
procedure TMaskEditorForm.SampleMasksListBoxDrawItem(Control: TWinControl;
Index: Integer; ARect: TRect; State: TOwnerDrawState);
var
OldBrushStyle: TBrushStyle;
OldTextStyle: TTextStyle;
NewTextStyle: TTextStyle;
ListBox: TListBox absolute Control;
AMaskCaption, AMaskExample, AEditMask: String;
R1, R2: TRect;
begin
ListBox.Canvas.FillRect(ARect);
if (Index >= 0) and (Index < ListBox.Items.Count) then
begin
OldBrushStyle := ListBox.Canvas.Brush.Style;
ListBox.Canvas.Brush.Style := bsClear;
OldTextStyle := ListBox.Canvas.TextStyle;
NewTextStyle := OldTextStyle;
NewTextStyle.Layout := tlCenter;
ListBox.Canvas.TextStyle := NewTextStyle;
ParseMaskLine(ListBox.Items[Index], AMaskCaption, AMaskExample, AEditMask);
AMaskExample := MaskDoFormatText(AEditMask, AMaskExample, ' ');
R1 := ARect;
R2 := ARect;
R1.Right := (R1.Left + R1.Right) div 2;
R2.Left := R1.Right + 1;
ListBox.Canvas.TextRect(R1, R1.Left + 2, R1.Top, AMaskCaption);
ListBox.Canvas.TextRect(R2, R2.Left + 2, R2.Top, AMaskExample);
ListBox.Canvas.MoveTo(R2.Left - 1, R2.Top);
ListBox.Canvas.LineTo(R2.Left - 1, R2.Bottom);
ListBox.Canvas.Brush.Style := OldBrushStyle;
ListBox.Canvas.TextStyle := OldTextStyle;
end;
end;
procedure TMaskEditorForm.SaveLiteralCheckBoxClick(Sender: TObject);
begin
ReconstructEditMask;
end;
procedure TMaskEditorForm.InputMaskEditChange(Sender: TObject);
begin
UpdateTestEditor;
end;
procedure TMaskEditorForm.CharactersForBlankEditChange(Sender: TObject);
var
S:string;
SL: Boolean;
BC: Char;
begin
SplitMask(InputMaskEdit.Text, S, SL, BC);
if (CharactersForBlanksEdit.Text<>'') and (Length(S) > 0) then
begin
BC := CharactersForBlanksEdit.Text[1];
if SL then InputMaskEdit.Text:=S + MaskFieldSeparator + '1' + MaskFieldSeparator + BC
else InputMaskEdit.Text:=S + MaskFieldSeparator + MaskNoSave + MaskFieldSeparator + BC;
end
else
ReConstructEditMask
end;
Function TMaskEditorForm.SplitMask(AMask : String; Out MaskText : String; Out SaveLiterals : Boolean; Out BlankChar : Char) : Boolean;
begin
Result:=False;
//Code modified to use same logic as in TCustomMaskEdit
BlankChar := DefaultBlank;
SaveLiterals := True;
if (Length(AMask) >= 4) and (AMask[Length(AMask)-1] = MaskFieldSeparator) and
(AMask[Length(AMask)-3] = MaskFieldSeparator) and
(AMask[Length(AMask)-2] <> cMask_SpecialChar) and
//Length = 4 is OK (AMask = ";1;_" for example), but if Length > 4 there must be no escape charater in front
((Length(AMask) = 4) or ((Length(AMask) > 4) and (AMask[Length(AMask)-4] <> cMask_SpecialChar))) then
begin
BlankChar := AMask[Length(AMask)];
SaveLiterals := (AMask[Length(AMask)-2] <> MaskNosave);
Result := True;
System.Delete(AMask,Length(AMask)-3,4);
end
//If not both SaveLiterals and BlankChar are specified, then see if only SaveLiterals is specified
else if (Length(AMask) >= 2) and (AMask[Length(AMask)-1] = MaskFieldSeparator) and
//Length = 2 is OK, but if Length > 2 there must be no escape charater in front
((Length(AMask) = 2) or ((Length(AMask) > 2) and (AMask[Length(AMask)-2] <> cMask_SpecialChar))) then
begin
SaveLiterals := (AMask[Length(AMask)] <> MaskNoSave);
Result := True;
//Remove this bit from Mask
System.Delete(AMask,Length(AMask)-1,2);
end;
MaskText := AMask;
end;
Function TMaskEditorForm.ConstructEditmask : String;
Var
S : String;
B : Char;
L : Boolean;
begin
SplitMask(InputMaskEdit.Text,S,L,B);
If (CharactersForBlanksEdit.Text<>'') then
B:=CharactersForBlanksEdit.Text[1];
if (Length(S) = 0) then
Result := ''
else
Result:=Format('%s'+MaskFieldSeparator+'%d'+MaskFieldSeparator+'%s',[S,ord(SaveLiteralCheckBox.checked),B]);
end;
procedure TMaskEditorForm.ReConstructEditmask;
begin
InputMaskEdit.Text:=ConstructEditMask;
UpdateTestEditor;
end;
procedure TMaskEditorForm.SampleMasksListBoxClick(Sender: TObject);
var
AMaskCaption, AMaskExample, AEditMask: String;
begin
if (SampleMasksListBox.Items.Count > 0) then
begin
TestMaskEdit.Text := '';
ParseMaskLine(SampleMasksListBox.Items[SampleMasksListBox.ItemIndex],
AMaskCaption, AMaskExample, AEditMask);
EditMask := AEditMask;
end;
end;
procedure TMaskEditorForm.MaskEditorFormCreate(Sender: TObject);
var
aDemFile: string;
begin
LoadSampleMasksButton.Caption := oisMasks;
SaveLiteralCheckBox.Caption := oisSaveLiteralCharacters;
InputMaskLabel.Caption := oisInputMask;
SampleMasksLabel.Caption := oisSampleMasks;
CharactersForBlanksLabel.Caption := oisCharactersForBlanks;
TestInputLabel.Caption := oisTestInput;
if LazarusIDE<>nil then
aDemFile:=LazarusIDE.GetPrimaryConfigPath
else
aDemFile:=ExtractFileDir(ParamStrUTF8(0));
aDemFile:=CleanAndExpandDirectory(aDemFile)+'maskeditmasks.txt';
if FileExistsUTF8(aDemFile) then
LoadDEMFile(aDemFile);
end;
function TMaskEditorForm.GetEditMask: string;
begin
Result:=ConstructEditMask;
end;
procedure TMaskEditorForm.LoadDEMFile(AFileName: string);
begin
SampleMasksListBox.Items.Clear;
SampleMasksListBox.Items.LoadFromFile(UTF8ToSys(AFileName));
end;
procedure TMaskEditorForm.SetEditMask(AValue: string);
Var
M : String;
B : Char;
S : Boolean;
begin
SplitMask(AValue,M,S,B);
InputMaskEdit.Text := AValue;
SaveLiteralCheckBox.Checked := S;
CharactersForBlanksEdit.Text := B;
UpdateTestEditor;
end;
procedure TMaskEditorForm.UpdateTestEditor;
begin
TestMaskEdit.EditMask:=InputMaskEdit.Text;
end;
{ TEditMaskProperty }
function TEditMaskProperty.GetAttributes: TPropertyAttributes;
begin
Result:= [paDialog, paMultiSelect, paRevertable];
end;
procedure TEditMaskProperty.Edit;
var
MaskEditorForm: TMaskEditorForm;
begin
MaskEditorForm:=TMaskEditorForm.Create(Application);
try
MaskEditorForm.EditMask:=GetValue;
if MaskEditorForm.ShowModal = mrOk then
SetValue(MaskEditorForm.EditMask);
finally
MaskEditorForm.Free;
end;
end;
{ TMaskEditEditor }
procedure TMaskEditEditor.ExecuteVerb(Index: Integer);
var
MaskEditorForm: TMaskEditorForm;
begin
if Index = 0 then
begin
MaskEditorForm := TMaskEditorForm.Create(Application);
try
MaskEditorForm.EditMask := MaskEdit.EditMask;
if MaskEditorForm.ShowModal = mrOk then
MaskEdit.EditMask := MaskEditorForm.EditMask;
finally
MaskEditorForm.Free;
end;
end;
end;
function TMaskEditEditor.GetVerb(Index: Integer): string;
begin
case Index of
0: Result := sccsMaskEditor;
else
Result := '';
end;
end;
function TMaskEditEditor.GetVerbCount: Integer;
begin
Result := 1;
end;
function TMaskEditEditor.MaskEdit: TCustomMaskEdit;
begin
Result := TCustomMaskEdit(GetComponent)
end;
initialization
RegisterPropertyEditor(TypeInfo(string), TCustomMaskEdit, 'EditMask',
TEditMaskProperty);
RegisterComponentEditor(TCustomMaskEdit, TMaskEditEditor);
end.
|