summaryrefslogtreecommitdiff
path: root/packages/amunits/src/utilunits/easyasl.pas
blob: 466e76399d5ccbd25c362bb2ce0542cc78693a3d (plain)
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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
{
    This file is part of the Free Pascal run time library.

    A file in Amiga system run time library.
    Copyright (c) 1998-2003 by Nils Sjoholm
    member of the Amiga RTL development team.

    See the file COPYING.FPC, 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.

 **********************************************************************}

{
    An easy way to use asl.library, no need to open asl.library,
    unit asl will open it for you.
    A lot of overlay functions here.:)

    One remark, be aware of that GetMultiFiles use linklist for the
    linked list of files, you can't use your own list with ordinary
    nodes.
    26 Oct 1998

    Removed amigaoverlays, use smartlink instead.
    05 Nov 2002.

    Added the define use_amiga_smartlink.
    13 Jan 2003.

    nils.sjoholm@mailbox.swipnet.se
}

unit easyasl;


interface

uses exec, asl, utility, amigautils,strings, workbench, linklist;


TYPE

    pFPCFontInfo = ^tFPCFontInfo;

    tFPCFontInfo = RECORD
    nfi_Name       : String[40];
    nfi_Size       : Word;
    nfi_Style      : Byte;
    nfi_Flags      : Byte;
    nfi_FrontPen   : Byte;
    nfi_BackPen    : Byte;
    nfi_DrawMode   : Byte;
    END;


FUNCTION GetFileAsl(title : PChar; VAR path, fname : PChar; thepatt : PChar;win : Pointer): Boolean;
FUNCTION GetFontAsl(title : PChar;VAR finfo : tFPCFontInfo; win : Pointer): Boolean;
FUNCTION GetMultiAsl(title : PChar; VAR path : PChar;  VAR Thelist : pList; thepatt : PChar;win : Pointer): Boolean;
FUNCTION GetPathAsl(title : PChar; VAR path : PChar; win : Pointer): Boolean;
FUNCTION SaveFileAsl(title : PChar; VAR path, fname : PChar; win : Pointer): Boolean;


FUNCTION GetFileAsl(title : PChar; VAR path, fname : PChar; thepatt : String;win : Pointer): Boolean;
FUNCTION GetFileAsl(title : String; VAR path, fname : PChar; thepatt : PChar;win : Pointer): Boolean;
FUNCTION GetFileAsl(title : String; VAR path, fname : PChar; thepatt : String;win : Pointer): Boolean;
FUNCTION GetFontAsl(title : String;VAR finfo : tFPCFontInfo; win : Pointer): Boolean;
FUNCTION GetMultiAsl(title : PChar; VAR path : PChar;  VAR Thelist : pList; thepatt : String;win : Pointer): Boolean;
FUNCTION GetMultiAsl(title : String; VAR path : PChar;  VAR Thelist : pList; thepatt : PChar;win : Pointer): Boolean;
FUNCTION GetMultiAsl(title : String; VAR path : PChar;  VAR Thelist : pList; thepatt : String;win : Pointer): Boolean;
FUNCTION GetPathAsl(title : String; VAR path : PChar; win : Pointer): Boolean;
FUNCTION SaveFileAsl(title : String; VAR path, fname : PChar; win : Pointer): Boolean;


implementation


 uses pastoc;



FUNCTION GetFileAsl(title : PChar; VAR path, fname : PChar; thepatt : PChar;win : Pointer): Boolean;

VAR
    fr : pFileRequester;
    result : Boolean;
    mytags : ARRAY[0..7] OF tTagItem;

BEGIN
    result := false;
    IF strlen(fname) >0 THEN begin
        mytags[0].ti_Tag  := ASLFR_InitialFile;
        mytags[0].ti_Data := Longint(fname);
    END ELSE begin
        mytags[0].ti_Tag := TAG_IGNORE;
    END;
    IF (strlen(path) > 0) and (FileType(path) = 2) THEN begin
        mytags[1].ti_Tag  := ASLFR_InitialDrawer;
        mytags[1].ti_Data := Longint(path);
    END ELSE begin
        mytags[1].ti_Tag  := ASLFR_InitialDrawer;
        mytags[1].ti_Data := Longint(pas2c('Sys:'));
    END;
    IF win <> nil THEN begin
        mytags[2].ti_Tag  := ASLFR_Window;
        mytags[2].ti_Data := Longint(win);
    END ELSE begin
        mytags[2].ti_Tag  := TAG_IGNORE;
    END;
    IF win <> nil THEN begin
        mytags[3].ti_Tag  := ASLFR_SleepWindow;
        mytags[3].ti_Data := Longint(Byte(true));
    END ELSE begin
        mytags[3].ti_Tag  := TAG_IGNORE;
    END;
    IF title <> nil THEN begin
        mytags[4].ti_Tag  := ASLFR_TitleText;
        mytags[4].ti_Data := Longint(title);
    END ELSE begin
        mytags[4].ti_Tag  := TAG_IGNORE;
    END;
    IF thepatt <> nil THEN begin
        mytags[5].ti_Tag  := ASLFR_InitialPattern;
        mytags[5].ti_Data := Longint(thepatt);
    END ELSE begin
        mytags[5].ti_Tag  := TAG_IGNORE;
    END;
    IF thepatt <> nil THEN begin
        mytags[6].ti_Tag  := ASLFR_DoPatterns;
        mytags[6].ti_Data := Longint(Byte(true));
    END ELSE begin
        mytags[6].ti_Tag  := TAG_IGNORE;
    END;
    mytags[7].ti_Tag  := TAG_DONE;

    fr := AllocAslRequest(ASL_FileRequest,@mytags);
    IF fr <> NIL THEN BEGIN
       IF AslRequest(fr,NIL) THEN BEGIN
          IF (strlen(fr^.rf_Dir) >0) and (strlen(fr^.rf_File) > 0) THEN begin
             strcopy(path,fr^.rf_Dir);
             strcopy(fname,fr^.rf_File);
             result := true;
          END ELSE begin
             result := false;
          end;
       END ELSE BEGIN
          result := false;
       END;
       FreeAslRequest(fr);
    END ELSE BEGIN
       result := false;
    END;
    GetFileAsl := result;
END;

FUNCTION GetFontAsl(title : PChar;VAR finfo : tFPCFontInfo; win : Pointer): Boolean;

VAR
    fr : pFontRequester;
    result : boolean;
    mytags : ARRAY[0..14] OF tTagItem;

BEGIN

    result := false;
    IF win <> nil THEN begin
        mytags[0].ti_Tag  := ASLFR_Window;
        mytags[0].ti_Data := Longint(win);
    END ELSE begin
        mytags[0].ti_Tag  := TAG_IGNORE;
    END;
    IF win <> nil THEN begin
        mytags[1].ti_Tag  := ASLFR_SleepWindow;
        mytags[1].ti_Data := Longint(Byte(true));
    END ELSE begin
        mytags[1].ti_Tag  := TAG_IGNORE;
    END;
    IF title <> nil THEN begin
        mytags[2].ti_Tag  := ASLFR_TitleText;
        mytags[2].ti_Data := Longint(title);
    END ELSE begin
        mytags[2].ti_Tag  := TAG_IGNORE;
    END;
    IF length(finfo.nfi_Name) > 0 THEN BEGIN
        mytags[3].ti_Tag  := ASLFO_InitialName;
        mytags[3].ti_Data := Longint(pas2c(finfo.nfi_Name));
    END ELSE BEGIN
        finfo.nfi_Name := 'topaz.font';
        mytags[3].ti_Tag  := ASLFO_InitialName;
        mytags[3].ti_Data := Longint(pas2c('topaz.font'));
    END;
    IF finfo.nfi_Size <= 4 THEN BEGIN
        mytags[4].ti_Tag  := ASLFO_InitialSize;
        mytags[4].ti_Data := 9;
    END ELSE BEGIN
        mytags[4].ti_Tag  := ASLFO_InitialSize;
        mytags[4].ti_Data := Longint(finfo.nfi_Size);
    END;
    IF finfo.nfi_Style >= 0 THEN BEGIN
        mytags[5].ti_Tag  := ASLFO_InitialStyle;
        mytags[5].ti_Data := Longint(finfo.nfi_Style);
    END ELSE BEGIN
        mytags[5].ti_Tag  := TAG_IGNORE;
    END;
    IF finfo.nfi_Flags >= 0 THEN BEGIN
        mytags[6].ti_Tag  := ASLFO_InitialFlags;
        mytags[6].ti_Data := Longint(finfo.nfi_Flags);
    END ELSE BEGIN
        mytags[6].ti_Tag := TAG_IGNORE;
    END;
    IF finfo.nfi_BackPen >=0 THEN BEGIN
        mytags[7].ti_Tag := ASLFO_InitialBackPen;
        mytags[7].ti_Data := Longint(finfo.nfi_BackPen);
    END ELSE BEGIN
        mytags[7].ti_Tag := ASLFO_InitialBackPen;
        mytags[7].ti_Data := 0;
    END;
    IF (finfo.nfi_FrontPen = 0) and (finfo.nfi_BackPen = 0) THEN BEGIN
        mytags[8].ti_Tag := ASLFO_InitialFrontPen;
        mytags[8].ti_Data := 1;
    END ELSE BEGIN
        mytags[8].ti_Tag := ASLFO_InitialFrontPen;
        mytags[8].ti_Data := Longint(finfo.nfi_FrontPen);
    END;
    IF finfo.nfi_DrawMode >= 0 THEN BEGIN
        mytags[9].ti_Tag := ASLFO_InitialDrawMode;
        mytags[9].ti_Data := Longint(finfo.nfi_DrawMode);
    END ELSE BEGIN
        mytags[9].ti_Tag := ASLFO_InitialDrawMode;
        mytags[9].ti_Data := 0;
    END;
    mytags[10].ti_Tag := ASLFO_DoFrontPen;
    mytags[10].ti_Data := Longint(Byte(true));
    mytags[11].ti_Tag := ASLFO_DoBackPen;
    mytags[11].ti_Data := Longint(Byte(true));
    mytags[12].ti_Tag := ASLFO_DoStyle;
    mytags[12].ti_Data := Longint(Byte(true));
    mytags[13].ti_Tag := ASLFO_DoDrawMode;
    mytags[13].ti_Data := Longint(Byte(true));
    mytags[14].ti_Tag := TAG_DONE;

    fr := AllocAslRequest(ASL_FontRequest,@mytags);
    IF fr <> NIL THEN BEGIN
         IF AslRequest(fr,NIL) THEN BEGIN
              WITH finfo DO BEGIN
                  nfi_Name := strpas(fr^.fo_Attr.ta_Name);
                  nfi_Size       := fr^.fo_Attr.ta_YSize;
                  nfi_Style      := fr^.fo_Attr.ta_Style;
                  nfi_Flags      := fr^.fo_Attr.ta_Flags;
                  nfi_FrontPen   := fr^.fo_FrontPen;
                  nfi_BackPen    := fr^.fo_BackPen;
                  nfi_DrawMode   := fr^.fo_DrawMode;
             END;
             result := true;
         END ELSE BEGIN
             result := false;
         END;
         FreeAslRequest(fr);
    END ELSE BEGIN
        result := false;
    END;
    GetFontAsl := result;
END;

FUNCTION GetMultiAsl(title : PChar; VAR path : PChar;  VAR Thelist : pList; thepatt : PChar;win : Pointer): Boolean;

VAR
    fr : pFileRequester;
    result : Boolean;
    mytags : ARRAY[0..7] OF tTagItem;
    index : Longint;
    tempnode : pFPCNode;

BEGIN
        IF (strlen(path) > 0) and (FileType(path) = 2) THEN begin
            mytags[0].ti_Tag  := ASLFR_InitialDrawer;
            mytags[0].ti_Data := Longint(path);
        END ELSE begin
            mytags[0].ti_Tag  := ASLFR_InitialDrawer;
            mytags[0].ti_Data := Longint(pas2c('Sys:'));
        END;
        IF win <> nil THEN begin
            mytags[1].ti_Tag  := ASLFR_Window;
            mytags[1].ti_Data := Longint(win);
        END ELSE begin
            mytags[1].ti_Tag  := TAG_IGNORE;
        END;
        IF win <> nil THEN begin
            mytags[2].ti_Tag  := ASLFR_SleepWindow;
            mytags[2].ti_Data := Longint(Byte(true));
        END ELSE begin
            mytags[2].ti_Tag  := TAG_IGNORE;
        END;
        IF title <> nil THEN begin
            mytags[3].ti_Tag  := ASLFR_TitleText;
            mytags[3].ti_Data := Longint(title);
        END ELSE begin
            mytags[3].ti_Tag  := TAG_IGNORE;
        END;
        IF thepatt <> nil THEN begin
            mytags[4].ti_Tag  := ASLFR_InitialPattern;
            mytags[4].ti_Data := Longint(thepatt);
        END ELSE begin
            mytags[4].ti_Tag  := TAG_IGNORE;
        END;
        IF thepatt <> nil THEN begin
            mytags[5].ti_Tag  := ASLFR_DoPatterns;
            mytags[5].ti_Data := Longint(Byte(true));
        END ELSE begin
            mytags[5].ti_Tag  := TAG_IGNORE;
        END;
        mytags[6].ti_Tag := ASLFR_DoMultiSelect;
        mytags[6].ti_Data := Longint(Byte(true));
        mytags[7].ti_Tag  := TAG_DONE;

        fr := AllocAslRequest(ASL_FileRequest,@mytags);
        IF fr <> NIL THEN BEGIN
             IF AslRequest(fr,NIL) THEN BEGIN
                 IF (strlen(fr^.rf_Dir) >0) THEN begin
                    strcopy(path,fr^.rf_Dir);
                    result := true;
                    FOR index := 1 to (fr^.rf_NumArgs) do begin
                        tempnode := AddNewnode(TheList,fr^.rf_ArgList^[index].wa_Name);
                    end;
                 END ELSE begin
                    result := false;
                 end;
             END ELSE BEGIN
                 result := false;
             END;
             FreeAslRequest(fr);
        END ELSE BEGIN
            result := false;
        END;
        GetMultiAsl := result;
END;

FUNCTION GetPathAsl(title : PChar; VAR path : PChar; win : Pointer): Boolean;

VAR
    fr : pFileRequester;
    result : Boolean;
    mytags : ARRAY[0..5] OF tTagItem;

BEGIN
    result := false;
    IF (strlen(path) > 0) and (FileType(path) = 2) THEN begin
        mytags[0].ti_Tag  := ASLFR_InitialDrawer;
        mytags[0].ti_Data := Longint(path);
    END ELSE begin
        mytags[0].ti_Tag  := ASLFR_InitialDrawer;
        mytags[0].ti_Data := Longint(pas2c('Sys:'));
    END;
    IF win <> nil THEN begin
        mytags[1].ti_Tag  := ASLFR_Window;
        mytags[1].ti_Data := Longint(win);
    END ELSE begin
        mytags[1].ti_Tag  := TAG_IGNORE;
    END;
    IF win <> nil THEN begin
        mytags[2].ti_Tag  := ASLFR_SleepWindow;
        mytags[2].ti_Data := Longint(Byte(true));
    END ELSE begin
        mytags[2].ti_Tag  := TAG_IGNORE;
    END;
    IF title <> nil THEN begin
        mytags[3].ti_Tag  := ASLFR_TitleText;
        mytags[3].ti_Data := Longint(title);
    END ELSE begin
        mytags[3].ti_Tag  := TAG_IGNORE;
    END;
    mytags[4].ti_Tag  := ASLFR_DrawersOnly;
    mytags[4].ti_Data := Longint(Byte(true));
    mytags[5].ti_Tag  := TAG_DONE;

    fr := AllocAslRequest(ASL_FileRequest,@mytags);
    IF fr <> NIL THEN BEGIN
         IF AslRequest(fr,NIL) THEN BEGIN
             IF (strlen(fr^.rf_Dir) >0) THEN begin
                strcopy(path,fr^.rf_Dir);
                result := true;
             END ELSE begin
                result := false;
             end;
         END ELSE BEGIN
             result := false;
         END;
         FreeAslRequest(fr);
    END ELSE BEGIN
        result := false;
    END;
    GetPathAsl := result;
END;

FUNCTION SaveFileAsl(title : PChar; VAR path, fname : PChar; win : Pointer): Boolean;

VAR
    fr : pFileRequester;
    result : Boolean;
    mytags : ARRAY[0..6] OF tTagItem;

BEGIN
    result := false;
    IF strlen(fname) >0 THEN begin
        mytags[0].ti_Tag  := ASLFR_InitialFile;
        mytags[0].ti_Data := Longint(fname);
    END ELSE begin
        mytags[0].ti_Tag := TAG_IGNORE;
    END;
    IF (strlen(path) > 0) and (FileType(path) = 2) THEN begin
        mytags[1].ti_Tag  := ASLFR_InitialDrawer;
        mytags[1].ti_Data := Longint(path);
    END ELSE begin
        mytags[1].ti_Tag  := ASLFR_InitialDrawer;
        mytags[1].ti_Data := Longint(pas2c('Sys:'));
    END;
    IF win <> nil THEN begin
        mytags[2].ti_Tag  := ASLFR_Window;
        mytags[2].ti_Data := Longint(win);
    END ELSE begin
        mytags[2].ti_Tag  := TAG_IGNORE;
    END;
    IF win <> nil THEN begin
        mytags[3].ti_Tag  := ASLFR_SleepWindow;
        mytags[3].ti_Data := Longint(Byte(true));
    END ELSE begin
        mytags[3].ti_Tag  := TAG_IGNORE;
    END;
    IF title <> nil THEN begin
        mytags[4].ti_Tag  := ASLFR_TitleText;
        mytags[4].ti_Data := Longint(title);
    END ELSE begin
        mytags[4].ti_Tag  := TAG_IGNORE;
    END;
    mytags[5].ti_Tag := ASLFR_DoSaveMode;
    mytags[5].ti_Data := Longint(Byte(true));
    mytags[6].ti_Tag  := TAG_DONE;

    fr := AllocAslRequest(ASL_FileRequest,@mytags);
    IF fr <> NIL THEN BEGIN
         IF AslRequest(fr,NIL) THEN BEGIN
             IF (strlen(fr^.rf_Dir) >0) and (strlen(fr^.rf_File) > 0) THEN begin
                strcopy(path,fr^.rf_Dir);
                strcopy(fname,fr^.rf_File);
                result := true;
             END ELSE begin
                result := false;
             end;
         END ELSE BEGIN
             result := false;
         END;
         FreeAslRequest(fr);
    END ELSE BEGIN
        result := false;
    END;
    SaveFileAsl := result;
END;


FUNCTION GetFileAsl(title : String; VAR path, fname : PChar; thepatt : PChar;win : Pointer): Boolean;
begin
    GetFileAsl := GetFileAsl(pas2c(title),path,fname,thepatt,win);
end;

FUNCTION GetFileAsl(title : String; VAR path, fname : PChar; thepatt : String;win : Pointer): Boolean;
begin
    GetFileAsl := GetFileAsl(pas2c(title),path,fname,pas2c(thepatt),win);
end;

FUNCTION GetFileAsl(title : PChar; VAR path, fname : PChar; thepatt : String;win : Pointer): Boolean;
begin
    GetFileAsl := GetFileAsl(title,path,fname,pas2c(thepatt),win);
end;

FUNCTION GetFontAsl(title : String;VAR finfo : tFPCFontInfo; win : Pointer): Boolean;
begin
    GetFontAsl := GetFontAsl(pas2c(title),finfo,win);
end;

FUNCTION GetMultiAsl(title : String; VAR path : PChar;  VAR Thelist : pList; thepatt : PChar;win : Pointer): Boolean;
begin
    GetMultiAsl := GetMultiAsl(pas2c(title),path,TheList,thepatt,win);
end;

FUNCTION GetMultiAsl(title : String; VAR path : PChar;  VAR Thelist : pList; thepatt : String;win : Pointer): Boolean;
begin
    GetMultiAsl := GetMultiAsl(pas2c(title),path,TheList,pas2c(thepatt),win);
end;

FUNCTION GetMultiAsl(title : PChar; VAR path : PChar;  VAR Thelist : pList; thepatt : String;win : Pointer): Boolean;
begin
    GetMultiAsl := GetMultiAsl(title,path,TheList,pas2c(thepatt),win);
end;

FUNCTION GetPathAsl(title : String; VAR path : PChar; win : Pointer): Boolean;
begin
    GetPathAsl := GetPathAsl(pas2c(title),path,win);
end;

FUNCTION SaveFileAsl(title : String; VAR path, fname : PChar; win : Pointer): Boolean;
begin
    SaveFileAsl := SaveFileAsl(pas2c(title),path,fname,win);
end;


end.