-
Notifications
You must be signed in to change notification settings - Fork 0
/
addtopaletteui.pas
132 lines (106 loc) · 4.26 KB
/
addtopaletteui.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
UNIT addToPaletteUi;
{$mode objfpc}{$H+}
INTERFACE
USES
Classes, sysutils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
paletteHandling,visualGates,visuals, types;
TYPE
{ TAddToPaletteDialog }
TAddToPaletteDialog = class(TForm)
paletteComboBox: TComboBox;
CaptionEdit: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
DescriptionMemo: TMemo;
propCancelLabel: TLabel;
propCancelShape: TShape;
propOkLabel: TLabel;
propOkLabel1: TLabel;
propOkShape: TShape;
propOkShape1: TShape;
PROCEDURE CaptionEditEditingDone(Sender: TObject);
PROCEDURE DescriptionMemoEditingDone(Sender: TObject);
PROCEDURE FormShow(Sender: TObject);
PROCEDURE PaletteComboboxDrawItem(control: TWinControl; index: integer;
ARect: TRect; state: TOwnerDrawState);
PROCEDURE propCancelShapeMouseDown(Sender: TObject; button: TMouseButton;
Shift: TShiftState; X, Y: integer);
PROCEDURE propOkShape1MouseDown(Sender: TObject; button: TMouseButton;
Shift: TShiftState; X, Y: integer);
PROCEDURE propOkShapeMouseDown(Sender: TObject; button: TMouseButton;
Shift: TShiftState; X, Y: integer);
private
currentBoard:P_visualBoard;
currentPalette:P_workspacePalette;
subPaletteIndex:longint;
public
FUNCTION showFor(CONST palette:P_workspacePalette; CONST board:P_visualBoard):boolean;
end;
FUNCTION addToPaletteDialog: TAddToPaletteDialog;
IMPLEMENTATION
USES workspaces;
VAR
myAddToPaletteForm: TAddToPaletteDialog=nil;
FUNCTION addToPaletteDialog: TAddToPaletteDialog;
begin
if myAddToPaletteForm=nil then
myAddToPaletteForm:=TAddToPaletteDialog.create(nil);
result:=myAddToPaletteForm;
end;
{$R *.lfm}
{ TAddToPaletteDialog }
PROCEDURE TAddToPaletteDialog.CaptionEditEditingDone(Sender: TObject);
begin
currentBoard^.setCaption(StringReplace(CaptionEdit.text,'\n',LineEnding,[rfReplaceAll]));
end;
PROCEDURE TAddToPaletteDialog.DescriptionMemoEditingDone(Sender: TObject);
begin
currentBoard^.setDescription(DescriptionMemo.text);
end;
PROCEDURE TAddToPaletteDialog.FormShow(Sender: TObject);
begin
applyColorScheme(self);
setEnableButton(propOkShape1,propOkLabel1,currentBoard^.getIndexInPalette>=0);
end;
PROCEDURE TAddToPaletteDialog.PaletteComboboxDrawItem(control: TWinControl; index: integer; ARect: TRect; state: TOwnerDrawState);
begin
if not(control is TComboBox) then exit;
paletteComboBox.Canvas.FillRect(ARect); //first paint normal background
paletteComboBox.Canvas.TextRect(ARect, 5, ARect.top, paletteComboBox.items[index]); //paint item text
end;
PROCEDURE TAddToPaletteDialog.propCancelShapeMouseDown(Sender: TObject; button: TMouseButton; Shift: TShiftState; X, Y: integer);
begin
ModalResult:=mrCancel;
end;
PROCEDURE TAddToPaletteDialog.propOkShape1MouseDown(Sender: TObject; button: TMouseButton; Shift: TShiftState; X, Y: integer);
begin
ModalResult:=mrOk;
currentBoard^.underlyingPrototype:=currentPalette^.updateEntry(currentBoard,paletteComboBox.ItemIndex,paletteComboBox.text);
currentBoard^.modified:=false;
end;
PROCEDURE TAddToPaletteDialog.propOkShapeMouseDown(Sender: TObject; button: TMouseButton; Shift: TShiftState; X, Y: integer);
begin
ModalResult:=mrOk;
currentBoard^.underlyingPrototype:=currentPalette^.addBoard(currentBoard,paletteComboBox.ItemIndex,paletteComboBox.text);
currentPalette^.setFilter(currentBoard^.underlyingPrototype^.getIndexInPalette);
currentBoard^.modified:=false;
end;
FUNCTION TAddToPaletteDialog.showFor(CONST palette: P_workspacePalette; CONST board: P_visualBoard): boolean;
VAR s:string;
begin
currentBoard :=board;
currentPalette:=palette;
CaptionEdit .text:=StringReplace(board^.getCaption,LineEnding,'\n',[rfReplaceAll]);
DescriptionMemo.text:=board^.getDescription;
paletteComboBox.items.clear;
setEnableButton(propOkShape1,propOkLabel1,board^.getIndexInPalette>=0);
for s in palette^.subPaletteNames do paletteComboBox.items.add(s);
paletteComboBox.ItemIndex:=workspace.currentPaletteAssociation;
if ShowModal=mrOk
then result:=true
else result:=false;
end;
FINALIZATION
if myAddToPaletteForm<>nil then FreeAndNil(myAddToPaletteForm);
end.