-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCALCTOOL.PAS
277 lines (265 loc) · 6.99 KB
/
CALCTOOL.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
Unit CalcTool;
INTERFACE
Uses Isatex;
Function SCGotoPhysicalCellule(Var Q:SuperCalcApp;X,Y:Byte):Byte;
Procedure SCProprieteCellule(Var Q:SuperCalcApp);
Procedure SCTriAscendant(Var Q:SuperCalcApp);
Procedure SCTriDescendant(Var Q:SuperCalcApp);
IMPLEMENTATION
Uses Systems,Dialex,Dials,DialPlus,Numerix,MalCalc;
Function SCGotoPhysicalCellule(Var Q:SuperCalcApp;X,Y:Byte):Byte;
Var
XC,YC:Integer;
PX,PY:LongInt;
I:Byte;
Begin
SCGotoPhysicalCellule:=0;
If WEInWindow(Q.W,X,Y)Then Begin
XC:=X-WEGetRX1(Q.W);
YC:=Y-WEGetRY1(Q.W)-(Q.HomeLine+1+Byte(Q.Mode=3));
If(XC>=10)and(YC>=0)Then Begin
PX:=Q.PX-Q.XL;
PY:=Q.PY;
I:=0;
Repeat
If(Q.ColumnX[I]<=XC)and(Q.ColumnX[I+1]>XC)Then Break;
Inc(I);
Until Q.ColumnX[I+1]>Q.W.MaxX;
Inc(PX,I);
Dec(PY,Q.YS);
Inc(PY,YC);
If(Q.PX<>PX)or(Q.PY<>PY)Then Begin
SCPutUnSelect(Q);
Q.PX:=PX;
Q.PY:=PY;
Q.XL:=I;
Q.YS:=YC;
SCPutSelect(Q);
SCGotoPhysicalCellule:=1;
End
Else
SCGotoPhysicalCellule:=2;
End;
End;
End;
Procedure SCProprieteCellule(Var Q:SuperCalcApp);
Var
FormProprieteCellule:Record
TypeCellule:MRadioButton;
Justify:MRadioButton;
TabbedNumber:Boolean;
NumDec:Byte;
Transparent:MCheckBox;
Inverse:MCheckBox;
Background:MColorGrid16;
Foreground:MColorGrid16;
Key:Byte;
End;
PC:PCellule;
Begin
FillClr(FormProprieteCellule,SizeOf(FormProprieteCellule));
PC:=SCGetCurrCellule(Q);
If(PC<>NIL)Then Begin
FormProprieteCellule.TabbedNumber:=PC^.Header.Format in[cfValue,cfFormula];
If(FormProprieteCellule.TabbedNumber)Then Begin
If(PC^.Header.Format=cfValue)Then FormProprieteCellule.NumDec:=PC^.Data.v.Dec
Else FormProprieteCellule.NumDec:=PC^.Data.f.Dec;
End;
FormProprieteCellule.TypeCellule.Alignment:=PC^.Header.Format;
FormProprieteCellule.Justify.Alignment:=Byte(PC^.Header.Justify);
FormProprieteCellule.Background.Color:=PC^.Header.Attribut shr 4;
FormProprieteCellule.Foreground.Color:=PC^.Header.Attribut and$F;
End;
FormProprieteCellule.Transparent.Checked:=True;
If ExecuteAppDPU(104,FormProprieteCellule)Then Begin
If(PC^.Header.Format<>FormProprieteCellule.TypeCellule.Alignment)Then Begin
Case(FormProprieteCellule.TypeCellule.Alignment)of
cfEmpty:CEAddEmpty(Q.Cellule,Q.PX,Q.PY);
cfValue:Case(PC^.Header.Format)of
cfText:CEAddRealValue(Q.Cellule,Q.PX,Q.PY,StrToReal(PC^.Data.t.Text));
Else CEAddRealValue(Q.Cellule,Q.PX,Q.PY,0.0);
End;
cfText:Case(PC^.Header.Format)of
cfValue:CEAddText(Q.Cellule,Q.PX,Q.PY,RealStr(PC^.Data.v.Value));
cfFormula:CEAddText(Q.Cellule,Q.PX,Q.PY,PC^.Data.f.Formula);
Else CEAddText(Q.Cellule,Q.PX,Q.PY,'');
End;
cfFormula:Case(PC^.Header.Format)of
cfText:CEAddFormula(Q.Cellule,Q.PX,Q.PY,PC^.Data.t.Text);
cfValue:CEAddFormula(Q.Cellule,Q.PX,Q.PY,RealStr(PC^.Data.v.Value));
Else CEAddFormula(Q.Cellule,Q.PX,Q.PY,'');
End;
End;
SCPutData(Q,Q.XL,Q.YS,Q.PX,Q.PY,False);
PC:=SCGetCurrCellule(Q);
End;
If(PC=NIL)Then Begin
SCPushData(Q,'');
PC:=SCGetCurrCellule(Q);
If(PC=NIL)Then Begin
__OutOfMemory;
Exit;
End;
End;
If(PC^.Header.Format=cfValue)Then Begin
If(PC^.Data.v.Dec<>FormProprieteCellule.NumDec)Then Begin
PC^.Data.v.Dec:=FormProprieteCellule.NumDec;
SCPutData(Q,Q.XL,Q.YS,Q.PX,Q.PY,False);
End;
End;
If(PC^.Header.Format=cfFormula)Then Begin
If(PC^.Data.f.Dec<>FormProprieteCellule.NumDec)Then Begin
PC^.Data.f.Dec:=FormProprieteCellule.NumDec;
SCPutData(Q,Q.XL,Q.YS,Q.PX,Q.PY,False);
End;
End;
Byte(PC^.Header.Justify):=FormProprieteCellule.Justify.Alignment;
If(FormProprieteCellule.Inverse.Checked)Then Begin
PC^.Header.Attribut:=FormProprieteCellule.Background.Color and$F;
PC^.Header.Attribut:=PC^.Header.Attribut or(FormProprieteCellule.Foreground.Color shl 4);
End
Else
Begin
PC^.Header.Attribut:=FormProprieteCellule.Background.Color shl 4;
PC^.Header.Attribut:=PC^.Header.Attribut or(FormProprieteCellule.Foreground.Color and$F);
End;
End;
End;
Function SCCompSup(Var Q:SuperCalcApp;X1,Y1,X2,Y2:LongInt):Boolean;Near;
Var
PC1,PC2:PCellule; { Pointeur sur une cellule }
V1,V2:Real;
V1Set,V2Set:Boolean;
S1,S2:String;
Begin
PC1:=SCGetCellule(Q,X1,Y1);
PC2:=SCGetCellule(Q,X2,Y2);
S1:='';
V1Set:=False;
V2Set:=False;
If(PC1<>NIL)Then Begin
Case(PC1^.Header.Format)of
cfFormula:Begin
S1:=RealStr2(PC1^.Data.f.Value,4,PC1^.Data.v.Dec);
V1:=PC1^.Data.v.Value;
V1Set:=True;
End;
cfValue:Begin
S1:=RealStr2(PC1^.Data.v.Value,4,PC1^.Data.v.Dec);
V1:=PC1^.Data.v.Value;
V1Set:=True;
End;
cfText:S1:=PC1^.Data.t.Text;
End;
End;
S2:='';
If(PC2<>NIL)Then Begin
Case(PC2^.Header.Format)of
cfFormula:Begin
S2:=RealStr2(PC2^.Data.f.Value,4,PC2^.Data.v.Dec);
V2:=PC2^.Data.v.Value;
V2Set:=True;
End;
cfValue:Begin
S2:=RealStr2(PC2^.Data.v.Value,4,PC2^.Data.v.Dec);
V2:=PC2^.Data.v.Value;
V2Set:=True;
End;
cfText:S2:=PC1^.Data.t.Text;
End;
End;
If(V1Set and V2Set)Then SCCompSup:=V1>V2
Else SCCompSup:=S1>S2;
End;
Procedure SCSwapCellule(Var Q:SuperCalcApp;X1,Y1,X2,Y2:LongInt);Near;
Var
PC1,PC2:PCellule; { Pointeur sur une cellule }
TCell:Array[0..1]of CelluleRec;
Begin
PC1:=SCGetCellule(Q,X1,Y1);
PC2:=SCGetCellule(Q,X2,Y2);
FillClr(TCell,SizeOf(TCell));
If(PC1<>NIL)and(PC2<>NIL)Then Begin
MoveLeft(PC1^,TCell[0],SizeOf(TCell[0]));
MoveLeft(PC2^,TCell[1],SizeOf(TCell[1]));
SwapLong(TCell[0].Column,TCell[1].Column);
SwapLong(TCell[0].Row,TCell[1].Row);
End
Else
If(PC1<>NIL)Then Begin
MoveLeft(PC1^,TCell[0],SizeOf(TCell[0]));
TCell[0].Column:=X2;
TCell[0].Row:=Y2;
End
Else
Begin
MoveLeft(PC2^,TCell[1],SizeOf(TCell[1]));
TCell[1].Column:=X1;
TCell[1].Row:=Y1;
End;
CEDelete(Q.Cellule,X1,Y1);
CEDelete(Q.Cellule,X2,Y2);
Q.Cellule.Curr:=TCell[0];
If(PC1<>NIL)Then CEAdd(Q.Cellule);
Q.Cellule.Curr:=TCell[1];
If(PC2<>NIL)Then CEAdd(Q.Cellule);
End;
Procedure SCTriAscendant(Var Q:SuperCalcApp);
Var
Ecart,M,I,J,K:LongInt;
NumLine:LongInt;
IL:LongInt;
Inversion:Boolean;
Begin
NumLine:=Q.BY2-Q.BY1;
Ecart:=NumLine;
Repeat
Ecart:=Ecart shr 1;
J:=0;K:=NumLine-Ecart;
Repeat
I:=J;
Repeat
If SCCompSup(Q,Q.BX1,Q.BY1+I,Q.BX1,Q.BY1+I+Ecart)Then Begin
For IL:=Q.BX1 to(Q.BX2)do Begin
SCSwapCellule(Q,IL,Q.BY1+I,IL,Q.BY1+I+Ecart);
End;
Dec(I,Ecart);
End
Else
Break;
Until I<1;
Inc(J);
Until J>K;
Until Ecart=1;
SCRefreshSpreadSheet(Q);
End;
Procedure SCTriDescendant(Var Q:SuperCalcApp);
Var
Ecart,M,I,J,K:LongInt;
NumLine:LongInt;
IL:LongInt;
Inversion:Boolean;
Begin
NumLine:=Q.BY2-Q.BY1;
Ecart:=NumLine;
Repeat
Ecart:=Ecart shr 1;
J:=0;K:=NumLine-Ecart;
Repeat
I:=J;
Repeat
If Not SCCompSup(Q,Q.BX1,Q.BY1+I,Q.BX1,Q.BY1+I+Ecart)Then Begin
For IL:=Q.BX1 to(Q.BX2)do Begin
SCSwapCellule(Q,IL,Q.BY1+I,IL,Q.BY1+I+Ecart);
End;
Dec(I,Ecart);
End
Else
Break;
Until I<1;
Inc(J);
Until J>K;
Until Ecart=1;
SCRefreshSpreadSheet(Q);
End;
END.