-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxvbrowse.c
5421 lines (4147 loc) · 143 KB
/
xvbrowse.c
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
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* xvbrowse.c - visual schnauzer routines
*
* includes:
* void CreateBrowse(char *, char *, char *, char *, char *);
* void OpenBrowse();
* void HideBrowseWindows();
* void UnHideBrowseWindows();
* void SetBrowseCursor(Cursor);
* void KillBrowseWindows();
* int BrowseCheckEvent(evt, int *retval, int *done);
* int BrowseDelWin(Window);
* void SetBrowStr(char *);
* void RegenBrowseIcons();
*
*/
#include "copyright.h"
#define NEEDSDIR
#include "xv.h"
#if defined(VMS) || defined(isc)
typedef unsigned int mode_t; /* file mode bits */
#endif
/* load up built-in icons */
#include "bits/br_file"
#include "bits/br_dir"
#include "bits/br_exe"
#include "bits/br_chr"
#include "bits/br_blk"
#include "bits/br_sock"
#include "bits/br_fifo"
#include "bits/br_error"
#include "bits/br_cmpres"
#include "bits/br_gif"
#include "bits/br_pm"
#include "bits/br_pbm"
#include "bits/br_xbm"
#include "bits/br_sunras"
#include "bits/br_bmp"
#include "bits/br_utah"
#include "bits/br_iris"
#include "bits/br_pcx"
#include "bits/br_jfif"
#include "bits/br_tiff"
#include "bits/br_pds"
#include "bits/br_ps"
#include "bits/br_iff"
#include "bits/br_targa"
#include "bits/br_xpm"
#include "bits/br_xwd"
#include "bits/br_fits"
#include "bits/br_png"
#include "bits/br_trash"
#include "bits/fcurs"
#include "bits/fccurs"
#include "bits/fdcurs"
#include "bits/fcursm"
/* FileTypes */
#define BF_HAVEIMG -1 /* should use 'pimage' and 'ximage' fields */
#define BF_FILE 0
#define BF_DIR 1
#define BF_EXE 2
#define BF_CHR 3
#define BF_BLK 4
#define BF_SOCK 5
#define BF_FIFO 6
#define BF_ERROR 7
#define BF_UNKNOWN 8
#define BF_GIF 9
#define BF_PM 10
#define BF_PBM 11
#define BF_XBM 12
#define BF_SUNRAS 13
#define BF_BMP 14
#define BF_UTAHRLE 15
#define BF_IRIS 16
#define BF_PCX 17
#define BF_JFIF 18
#define BF_TIFF 19
#define BF_PDS 20
#define BF_COMPRESS 21
#define BF_PS 22
#define BF_IFF 23
#define BF_TARGA 24
#define BF_XPM 25
#define BF_XWD 26
#define BF_FITS 27
#define BF_PNG 28
#define BF_MAX 29 /* # of built-in icons */
#define ISLOADABLE(ftyp) (ftyp!=BF_DIR && ftyp!=BF_CHR && ftyp!=BF_BLK && \
ftyp!=BF_SOCK && ftyp!=BF_FIFO)
#define DEF_BROWWIDE 615 /* default size of window */
#define DEF_BROWHIGH 356
#define SCROLLVERT 8 /* height of scroll region at top/bottom of iconw */
#define PAGEVERT 40 /* during rect drag, if further than this, page */
#define ICON_ONLY 2 /* if 'lit' field ==, invert icon only, not title */
#define TEMP_LIT 3 /* temporarily selected, normally off */
#define TEMP_LIT1 4 /* temporarily selected, normally on */
#define TOPMARGIN 30 /* from top of window to top of iconwindow */
#define BOTMARGIN 58 /* room for a row of buttons and a line of text */
#define LRMARGINS 5 /* left and right margins */
#define ISIZE_WIDE 80 /* maximum size of an icon */
#define ISIZE_HIGH 60
#define ISPACE_WIDE (ISIZE_WIDE+16) /* icon spacing */
#define ISPACE_TOP 4 /* dist btwn top of ISPACE and ISIZE */
#define ISPACE_TTOP 4 /* dist btwn bot of icon and title */
#define ISPACE_HIGH (ISIZE_HIGH+ISPACE_TOP+ISPACE_TTOP+16+4)
#define DBLCLICKTIME 300 /* milliseconds */
/* button/menu indicies */
#define BR_CHDIR 0
#define BR_DELETE 1
#define BR_MKDIR 2
#define BR_RENAME 3
#define BR_RESCAN 4
#define BR_UPDATE 5
#define BR_NEWWIN 6
#define BR_GENICON 7
#define BR_SELALL 8
#define BR_TEXTVIEW 9
#define BR_RECURSUP 10
#define BR_QUIT 11
#define BR_CLOSE 12
#define BR_NBUTTS 13 /* # of command buttons */
#define BR_SEP1 13 /* separator */
#define BR_HIDDEN 14
#define BR_SELFILES 15
#define BR_NCMDS 16 /* # of menu commands */
#define BUTTW 80
#define BUTTH 24
static char *showHstr = "Show hidden files";
static char *hideHstr = "Hide 'hidden' files";
static char *cmdMList[] = { "Change directory...\t^c",
"Delete file(s)\t^d",
"New directory...\t^n",
"Rename file...\t^r",
"Rescan directory\t^s",
"Update icons\t^u",
"Open new window\t^w",
"Generate icon(s)\t^g",
"Select all files\t^a",
"Text view\t^t",
"Recursive Update\t^e",
"Quit xv\t^q",
"Close window\t^c",
MBSEP,
"Show hidden files", /* no equiv */
"Select files...\t^f"
};
#define MAXDEEP 30 /* maximum directory depth */
#define BOGUSPATH "NO SUCH PATH"
typedef struct { char *name; /* name of file */
char *imginfo; /* info on the real image */
int ftype; /* BF_EXE, BF_DIR, BF_FILE, etc... */
byte *pimage; /* normal, 8-bit-per image */
XImage *ximage; /* X version of pimage */
int w,h; /* size of icon */
int lit; /* true if 'selected' */
} BFIL;
/* data needed per schnauzer window */
typedef struct { Window win, iconW;
int vis, wasvis;
int wide, high;
int iwWide, iwHigh;
int numWide, numHigh, visHigh;
SCRL scrl;
BUTT but[BR_NBUTTS];
MBUTT dirMB, cmdMB;
char dispstr[256];
int numbutshown;
int showhidden;
int numlit;
BFIL *bfList;
int bfLen;
int lastIconClicked;
unsigned long lastClickTime;
int ndirs;
char *mblist[MAXDEEP];
char path[MAXPATHLEN+2]; /* '/' terminated */
} BROWINFO;
static Cursor movecurs, copycurs, delcurs;
static BROWINFO binfo[MAXBRWIN];
static Pixmap bfIcons[BF_MAX], trashPix;
static int hasBeenSized = 0;
static int haveWindows = 0;
static unsigned long browfg, browbg, browhi, browlo;
static void closeBrowse PARM((BROWINFO *));
static int brChkEvent PARM((BROWINFO *, XEvent *));
static void resizeBrowse PARM((BROWINFO *, int, int));
static void setBrowStr PARM((BROWINFO *, char *));
static void doCmd PARM((BROWINFO *, int));
static void drawBrow PARM((BROWINFO *));
static void drawNumfiles PARM((BROWINFO *));
static void eraseNumfiles PARM((BROWINFO *, int));
static void drawTrash PARM((BROWINFO *));
static int inTrash PARM((BROWINFO *, int, int));
static void drawBrowStr PARM((BROWINFO *));
static void changedNumLit PARM((BROWINFO *, int, int));
static void setSelInfoStr PARM((BROWINFO *, int));
static void exposeIconWin PARM((BROWINFO *, int, int, int, int));
static void drawIconWin PARM((int, SCRL *));
static void eraseIcon PARM((BROWINFO *, int));
static void eraseIconTitle PARM((BROWINFO *, int));
static void drawIcon PARM((BROWINFO *, int));
static void makeIconVisible PARM((BROWINFO *, int));
static void clickBrow PARM((BROWINFO *, int, int));
static int clickIconWin PARM((BROWINFO *, int, int, unsigned long, int));
static void doubleClick PARM((BROWINFO *, int));
static int mouseInWhichIcon PARM((BROWINFO *, int, int));
static void invertSelRect PARM((BROWINFO *, int, int, int, int));
static void keyIconWin PARM((BROWINFO *, XKeyEvent *));
static void browKey PARM((BROWINFO *, int));
static void browAlpha PARM((BROWINFO *, int));
static void changedBrDirMB PARM((BROWINFO *, int));
static int cdBrow PARM((BROWINFO *));
static void scanDir PARM((BROWINFO *));
static void copyDirInfo PARM((BROWINFO *, BROWINFO *));
static void endScan PARM((BROWINFO *, int));
static void scanFile PARM((BROWINFO *, BFIL *, char *));
static void sortBFList PARM((BROWINFO *));
static int bfnamCmp PARM((const void *, const void *));
static void rescanDir PARM((BROWINFO *));
static int namcmp PARM((const void *, const void *));
static void freeBfList PARM((BROWINFO *br));
static char **getDirEntries PARM((char *, int *, int));
static void computeScrlVals PARM((BROWINFO *, int *, int *));
static void genSelectedIcons PARM((BROWINFO *));
static void genIcon PARM((BROWINFO *, BFIL *));
static void loadThumbFile PARM((BROWINFO *, BFIL *));
static void writeThumbFile PARM((BROWINFO *, BFIL *, byte *, int,
int, char *));
static void makeThumbDir PARM((BROWINFO *));
static void updateIcons PARM((BROWINFO *));
static void drawTemp PARM((BROWINFO *, int, int));
static void clearTemp PARM((BROWINFO *));
static void doTextCmd PARM((BROWINFO *));
static void doRenameCmd PARM((BROWINFO *));
static void doMkdirCmd PARM((BROWINFO *));
static void doChdirCmd PARM((BROWINFO *));
static void doDeleteCmd PARM((BROWINFO *));
static void doSelFilesCmd PARM((BROWINFO *));
static void doRecurseCmd PARM((BROWINFO *));
static void recurseUpdate PARM((BROWINFO *, char *));
static void rm_file PARM((BROWINFO *, char *));
static void rm_dir PARM((BROWINFO *, char *));
static void rm_dir1 PARM((BROWINFO *));
static void dragFiles PARM((BROWINFO *, BROWINFO *, char *, char *,
char *, char **, int, int));
static int moveFile PARM((char *, char *));
static int copyFile PARM((char *, char *));
static void cp PARM((void));
static void cp_dir PARM((void));
static void cp_file PARM((struct stat *, int));
static void cp_special PARM((struct stat *, int));
static void cp_fifo PARM((struct stat *, int));
static int stat2bf PARM((u_int));
static int selmatch PARM((char *, char *));
static int selmatch1 PARM((char *, char *));
/***************************************************************/
void CreateBrowse(geom, fgstr, bgstr, histr, lostr)
char *geom, *fgstr, *bgstr, *histr, *lostr;
{
int i;
XSizeHints hints;
XSetWindowAttributes xswa;
BROWINFO *br;
XColor ecdef, cursfg, cursbg;
Pixmap mcpix, ccpix, dcpix, fcmpix;
int gx, gy, gw, gh, gset, gx1, gy1;
unsigned int uw, uh;
char wgeom[64];
if (!geom) geom = "";
/* map color spec strings into browCmap, if we're in browPerfect mode */
if (browPerfect && browCmap) {
browfg = 0; browbg = 255; /* black text on white bg, by default */
if (fgstr && XParseColor(theDisp, browCmap, fgstr, &ecdef)) {
browfg = browcols[((ecdef.red >> 8) & 0xe0) |
((ecdef.green >> 11) & 0x1c) |
((ecdef.blue >> 14) & 0x03)];
}
if (bgstr && XParseColor(theDisp, browCmap, bgstr, &ecdef)) {
browbg = browcols[((ecdef.red >> 8) & 0xe0) |
((ecdef.green >> 11) & 0x1c) |
((ecdef.blue >> 14) & 0x03)];
}
browhi = browbg; browlo = browfg;
if (histr && XParseColor(theDisp, browCmap, histr, &ecdef)) {
browhi = browcols[((ecdef.red >> 8) & 0xe0) |
((ecdef.green >> 11) & 0x1c) |
((ecdef.blue >> 14) & 0x03)];
}
if (lostr && XParseColor(theDisp, browCmap, lostr, &ecdef)) {
browlo = browcols[((ecdef.red >> 8) & 0xe0) |
((ecdef.green >> 11) & 0x1c) |
((ecdef.blue >> 14) & 0x03)];
}
}
else {
browfg = infofg; browbg = infobg; browhi = hicol; browlo = locol;
}
gset = XParseGeometry(geom, &gx, &gy, &uw, &uh);
gw = (int) uw; gh = (int) uh;
/* creates *all* schnauzer windows at once */
for (i=0; i<MAXBRWIN; i++) binfo[i].win = (Window) NULL;
for (i=0; i<MAXBRWIN; i++) {
char wname[64];
/* create a slightly offset geometry, so the windows stack nicely */
if ((gset & XValue) && (gset & YValue)) {
if (gset & XNegative) gx1 = gx - i * 20;
else gx1 = gx + i * 20;
if (gset & YNegative) gy1 = gy - i * 20;
else gy1 = gy + i * 20;
if ((gset & WidthValue) && (gset & HeightValue))
sprintf(wgeom, "%dx%d%s%d%s%d", gw, gh,
(gset & XNegative) ? "-" : "+", abs(gx1),
(gset & YNegative) ? "-" : "+", abs(gy1));
else
sprintf(wgeom, "%s%d%s%d",
(gset & XNegative) ? "-" : "+", abs(gx1),
(gset & YNegative) ? "-" : "+", abs(gy1));
}
else strcpy(wgeom, geom);
br = &binfo[i];
if (i) sprintf(wname, "xv visual schnauzer (%d)", i);
else sprintf(wname, "xv visual schnauzer");
br->win = CreateWindow(wname, "XVschnauze", wgeom,
DEF_BROWWIDE, DEF_BROWHIGH, browfg, browbg, 1);
if (!br->win) FatalError("can't create schnauzer window!");
haveWindows = 1;
br->vis = br->wasvis = 0;
if (browPerfect && browCmap) {
xswa.colormap = browCmap;
XChangeWindowAttributes(theDisp, br->win, CWColormap, &xswa);
}
if (ctrlColor) XSetWindowBackground(theDisp, br->win, browlo);
else XSetWindowBackgroundPixmap(theDisp, br->win, grayTile);
/* note: everything is sized and positioned in ResizeBrowse() */
br->iconW = XCreateSimpleWindow(theDisp, br->win, 1,1, 100,100,
1,browfg,browbg);
if (!br->iconW) FatalError("can't create schnauzer icon window!");
SCCreate(&(br->scrl), br->win, 0,0, 1,100, 0,0,0,0,
browfg, browbg, browhi, browlo, drawIconWin);
if (XGetNormalHints(theDisp, br->win, &hints)) {
hints.min_width = 325 + 96;
hints.min_height = 180;
hints.flags |= PMinSize;
XSetNormalHints(theDisp, br->win, &hints);
}
#ifdef BACKING_STORE
xswa.backing_store = WhenMapped;
XChangeWindowAttributes(theDisp, br->iconW, CWBackingStore, &xswa);
#endif
XSelectInput(theDisp, br->iconW, ExposureMask | ButtonPressMask);
BTCreate(&(br->but[BR_CHDIR]), br->win, 0,0,BUTTW,BUTTH,
"Change Dir",browfg,browbg,browhi,browlo);
BTCreate(&(br->but[BR_DELETE]), br->win, 0,0,BUTTW,BUTTH,
"Delete",browfg,browbg,browhi,browlo);
BTCreate(&(br->but[BR_MKDIR]), br->win, 0,0,BUTTW,BUTTH,
"New Dir",browfg,browbg,browhi,browlo);
BTCreate(&(br->but[BR_RENAME]), br->win, 0,0,BUTTW,BUTTH,
"Rename",browfg,browbg,browhi,browlo);
BTCreate(&(br->but[BR_RESCAN]), br->win, 0,0,BUTTW,BUTTH,
"ReScan",browfg,browbg,browhi,browlo);
BTCreate(&(br->but[BR_UPDATE]), br->win, 0,0,BUTTW,BUTTH,
"Update",browfg,browbg,browhi,browlo);
BTCreate(&(br->but[BR_NEWWIN]), br->win, 0,0,BUTTW,BUTTH,
"Open Win",browfg,browbg,browhi,browlo);
BTCreate(&(br->but[BR_GENICON]),br->win, 0,0,BUTTW,BUTTH,
"GenIcon",browfg,browbg,browhi,browlo);
BTCreate(&(br->but[BR_SELALL]), br->win, 0,0,BUTTW,BUTTH,
"Select All",browfg,browbg,browhi,browlo);
BTCreate(&(br->but[BR_TEXTVIEW]), br->win, 0,0,BUTTW,BUTTH,
"Text view",browfg,browbg,browhi,browlo);
BTCreate(&(br->but[BR_RECURSUP]), br->win, 0,0,BUTTW,BUTTH,
"RecursUpd",browfg,browbg,browhi,browlo);
BTCreate(&(br->but[BR_QUIT]), br->win, 0,0,BUTTW,BUTTH,
"Quit xv",browfg,browbg,browhi,browlo);
BTCreate(&(br->but[BR_CLOSE]), br->win, 0,0,BUTTW,BUTTH,
"Close",browfg,browbg,browhi,browlo);
XMapSubwindows(theDisp, br->win);
MBCreate(&(br->dirMB), br->win, 0,0,100,19, NULL,NULL,0,
browfg,browbg,browhi,browlo);
MBCreate(&(br->cmdMB), br->win, 0,0,160,19, "Misc. Commands",
cmdMList, BR_NCMDS, browfg,browbg,browhi,browlo);
br->showhidden = 0;
br->cmdMB.list[BR_HIDDEN] = showHstr;
br->numbutshown = 0;
br->numlit = 0;
br->bfList = NULL;
br->bfLen = 0;
br->dispstr[0] = '\0';
br->ndirs = 0;
sprintf(br->path, BOGUSPATH);
br->lastIconClicked = -1;
br->lastClickTime = 0;
}
/* create built-in icon pixmaps */
bfIcons[BF_FILE]=MakePix1(br->win,br_file_bits,br_file_width,br_file_height);
bfIcons[BF_DIR] =MakePix1(br->win,br_dir_bits, br_dir_width, br_dir_height);
bfIcons[BF_EXE] =MakePix1(br->win,br_exe_bits, br_exe_width, br_exe_height);
bfIcons[BF_CHR] =MakePix1(br->win,br_chr_bits, br_chr_width, br_chr_height);
bfIcons[BF_BLK] =MakePix1(br->win,br_blk_bits, br_blk_width, br_blk_height);
bfIcons[BF_SOCK]=MakePix1(br->win,br_sock_bits,br_sock_width,br_sock_height);
bfIcons[BF_FIFO]=MakePix1(br->win,br_fifo_bits,br_fifo_width,br_fifo_height);
bfIcons[BF_ERROR] = MakePix1(br->win, br_error_bits,
br_error_width, br_error_height);
/* bfIcons[BF_UNKNOWN] = MakePix1(br->win, br_unknown_bits,
br_unknown_width, br_unknown_height); */
bfIcons[BF_UNKNOWN] = bfIcons[BF_FILE];
bfIcons[BF_GIF] =MakePix1(br->win,br_gif_bits, br_gif_width, br_gif_height);
bfIcons[BF_PM] =MakePix1(br->win,br_pm_bits, br_pm_width, br_pm_height);
bfIcons[BF_PBM] =MakePix1(br->win,br_pbm_bits, br_pbm_width, br_pbm_height);
bfIcons[BF_XBM] =MakePix1(br->win,br_xbm_bits, br_xbm_width, br_xbm_height);
bfIcons[BF_SUNRAS] = MakePix1(br->win, br_sunras_bits,
br_sunras_width, br_sunras_height);
bfIcons[BF_BMP] = MakePix1(br->win,br_bmp_bits,
br_bmp_width, br_bmp_height);
bfIcons[BF_UTAHRLE] = MakePix1(br->win, br_utahrle_bits,
br_utahrle_width, br_utahrle_height);
bfIcons[BF_IRIS]=MakePix1(br->win,br_iris_bits,br_iris_width,br_iris_height);
bfIcons[BF_PCX] =MakePix1(br->win,br_pcx_bits, br_pcx_width, br_pcx_height);
bfIcons[BF_JFIF]=MakePix1(br->win,br_jfif_bits,br_jfif_width,br_jfif_height);
bfIcons[BF_TIFF]=MakePix1(br->win,br_tiff_bits,br_tiff_width,br_tiff_height);
bfIcons[BF_PDS] =MakePix1(br->win,br_pds_bits, br_pds_width, br_pds_height);
bfIcons[BF_COMPRESS]= MakePix1(br->win, br_cmpres_bits,
br_cmpres_width, br_cmpres_height);
bfIcons[BF_PS] =MakePix1(br->win,br_ps_bits, br_ps_width, br_ps_height);
bfIcons[BF_IFF] =MakePix1(br->win,br_iff_bits, br_iff_width, br_iff_height);
bfIcons[BF_TARGA] = MakePix1(br->win, br_targa_bits,
br_targa_width, br_targa_height);
bfIcons[BF_XPM] =MakePix1(br->win,br_xpm_bits, br_xpm_width, br_xpm_height);
bfIcons[BF_XWD] =MakePix1(br->win,br_xwd_bits, br_xwd_width, br_xwd_height);
bfIcons[BF_FITS]=MakePix1(br->win,br_fits_bits,br_fits_width,br_fits_height);
bfIcons[BF_PNG]=MakePix1(br->win,br_png_bits,br_png_width,br_png_height);
/* check that they all got built */
for (i=0; i<BF_MAX && bfIcons[i]; i++);
if (i<BF_MAX)
FatalError("unable to create all built-in icons for schnauzer");
for (i=0; i<MAXBRWIN; i++) {
resizeBrowse(&binfo[i], DEF_BROWWIDE, DEF_BROWHIGH);
XSelectInput(theDisp, binfo[i].win, ExposureMask | ButtonPressMask |
KeyPressMask | StructureNotifyMask);
}
trashPix = MakePix1(br->win, br_trash_bits, br_trash_width, br_trash_height);
if (!trashPix)
FatalError("unable to create all built-in icons for schnauzer");
/* create movecurs and copycurs cursors */
mcpix = MakePix1(rootW, filecurs_bits, filecurs_width, filecurs_height);
ccpix = MakePix1(rootW, fileccurs_bits, fileccurs_width, fileccurs_height);
dcpix = MakePix1(rootW, fdcurs_bits, fdcurs_width, fdcurs_height);
fcmpix= MakePix1(rootW, filecursm_bits, filecursm_width, filecursm_height);
if (mcpix && ccpix && fcmpix && dcpix) {
cursfg.red = cursfg.green = cursfg.blue = 0;
cursbg.red = cursbg.green = cursbg.blue = 0xffff;
movecurs = XCreatePixmapCursor(theDisp,mcpix,fcmpix,&cursfg,&cursbg,13,13);
copycurs = XCreatePixmapCursor(theDisp,ccpix,fcmpix,&cursfg,&cursbg,13,13);
delcurs = XCreatePixmapCursor(theDisp,dcpix,fcmpix,&cursbg,&cursfg,13,13);
if (!movecurs || !copycurs || !delcurs)
FatalError("unable to create schnauzer cursors...");
}
else FatalError("unable to create schnauzer cursors...");
XFreePixmap(theDisp, mcpix);
XFreePixmap(theDisp, ccpix);
XFreePixmap(theDisp, dcpix);
XFreePixmap(theDisp, fcmpix);
hasBeenSized = 1; /* we can now start looking at browse events */
}
/***************************************************************/
void OpenBrowse()
{
/* opens up a single browser window */
int i;
BROWINFO *br;
char path[MAXPATHLEN+1];
/* find next browser to be opened */
for (i=0; i<MAXBRWIN; i++) {
br = &binfo[i];
if (!br->vis) break;
}
if (i==MAXBRWIN) return; /* full up: shouldn't happen */
anyBrowUp = 1;
XMapRaised(theDisp, br->win);
br->vis = 1;
freeBfList(br);
/* see if some browser is pointing to the same path as CWD. If so,
copy the info, rather than reading the directory */
xv_getwd(path, sizeof(path));
if (path[strlen(path)-1] != '/') strcat(path,"/"); /* add trailing '/' */
for (i=0; i<MAXBRWIN; i++) {
if (strcmp(binfo[i].path,path)==0) break;
}
if (i<MAXBRWIN && &binfo[i] != br) copyDirInfo(&binfo[i], br);
else scanDir(br);
SCSetVal(&(br->scrl), 0);
/* see if that was the last one */
for (i=0; i<MAXBRWIN; i++) {
if (!binfo[i].vis) break;
}
if (i==MAXBRWIN) { /* can't open any more */
windowMB.dim[WMB_BROWSE] = 1;
for (i=0; i<MAXBRWIN; i++) {
BTSetActive(&(binfo[i].but[BR_NEWWIN]), 0);
binfo[i].cmdMB.dim[BR_NEWWIN] = 1;
}
}
changedNumLit(br, -1, 0);
}
/***************************************************************/
static void closeBrowse(br)
BROWINFO *br;
{
int i;
WaitCursor();
/* closes a specified browse window */
XUnmapWindow(theDisp, br->win);
br->vis = 0;
for (i=0; i<MAXBRWIN; i++) {
if (binfo[i].vis) break;
}
if (i==MAXBRWIN) anyBrowUp = 0;
/* free all info for this browse window */
freeBfList(br);
sprintf(br->path, BOGUSPATH);
/* turn on 'open new window' command doodads */
windowMB.dim[WMB_BROWSE] = 0;
for (i=0; i<MAXBRWIN; i++) {
BTSetActive(&(binfo[i].but[BR_NEWWIN]), 1);
binfo[i].cmdMB.dim[BR_NEWWIN] = 0;
}
SetCursors(-1);
}
/***************************************************************/
void HideBrowseWindows()
{
int i;
for (i=0; i<MAXBRWIN; i++) {
if (binfo[i].vis) {
XUnmapWindow(theDisp, binfo[i].win);
binfo[i].wasvis = 1;
binfo[i].vis = 0;
}
}
}
/***************************************************************/
void UnHideBrowseWindows()
{
int i;
for (i=0; i<MAXBRWIN; i++) {
if (binfo[i].wasvis) {
XMapRaised(theDisp, binfo[i].win);
binfo[i].wasvis = 0;
binfo[i].vis = 1;
}
}
}
/***************************************************************/
void SetBrowseCursor(c)
Cursor c;
{
int i;
for (i=0; i<MAXBRWIN; i++) {
if (haveWindows && binfo[i].win) XDefineCursor(theDisp, binfo[i].win, c);
}
}
/***************************************************************/
void KillBrowseWindows()
{
int i;
for (i=0; i<MAXBRWIN; i++) {
if (haveWindows && binfo[i].win) XDestroyWindow(theDisp, binfo[i].win);
}
}
static int *event_retP, *event_doneP;
/***************************************************************/
int BrowseCheckEvent(xev, retP, doneP)
XEvent *xev;
int *retP, *doneP;
{
int i;
event_retP = retP; /* so don't have to pass these all over the place */
event_doneP = doneP;
for (i=0; i<MAXBRWIN; i++) {
if (brChkEvent(&binfo[i], xev)) break;
}
if (i<MAXBRWIN) return 1;
return 0;
}
/***************************************************************/
static int brChkEvent(br, xev)
BROWINFO *br;
XEvent *xev;
{
/* checks event to see if it's a browse-window related thing. If it
is, it eats the event and returns '1', otherwise '0'. */
int rv;
rv = 1;
if (!hasBeenSized) return 0; /* ignore evrythng until we get 1st Resize */
if (xev->type == Expose) {
int x,y,w,h;
XExposeEvent *e = (XExposeEvent *) xev;
x = e->x; y = e->y; w = e->width; h = e->height;
/* throw away excess redraws for 'dumb' windows */
if (e->count > 0 && (e->window == br->scrl.win)) {}
else if (e->window == br->scrl.win) SCRedraw(&(br->scrl));
else if (e->window == br->win || e->window == br->iconW) { /* smart wins */
/* group individual expose rects into a single expose region */
int count;
Region reg;
XRectangle rect;
XEvent evt;
XSync(theDisp, False);
xvbcopy((char *) e, (char *) &evt, sizeof(XEvent));
reg = XCreateRegion();
count = 0;
do {
rect.x = evt.xexpose.x;
rect.y = evt.xexpose.y;
rect.width = evt.xexpose.width;
rect.height = evt.xexpose.height;
XUnionRectWithRegion(&rect, reg, reg);
count++;
} while (XCheckWindowEvent(theDisp, evt.xexpose.window,
ExposureMask, &evt));
XClipBox(reg, &rect); /* bounding box of region */
XSetRegion(theDisp, theGC, reg);
if (DEBUG) {
fprintf(stderr,"win = %lx, br->win = %lx, iconW = %lx\n",
e->window, br->win, br->iconW);
fprintf(stderr,"grouped %d expose events into %d,%d %dx%d rect\n",
count, rect.x, rect.y, rect.width, rect.height);
}
if (e->window == br->win) drawBrow(br);
else if (e->window == br->iconW)
exposeIconWin(br, rect.x, rect.y, rect.width, rect.height);
XSetClipMask(theDisp, theGC, None);
XDestroyRegion(reg);
}
else rv = 0;
}
else if (xev->type == ButtonPress) {
XButtonEvent *e = (XButtonEvent *) xev;
int i,x,y;
x = e->x; y = e->y;
if (e->button == Button1) {
if (e->window == br->win) clickBrow(br,x,y);
else if (e->window == br->scrl.win) SCTrack(&(br->scrl),x,y);
else if (e->window == br->iconW) {
i = clickIconWin(br, x,y,(unsigned long) e->time,
(e->state&ControlMask) || (e->state&ShiftMask));
}
else rv = 0;
}
else rv = 0;
}
else if (xev->type == KeyPress) {
XKeyEvent *e = (XKeyEvent *) xev;
if (e->window == br->win) keyIconWin(br, e);
else rv = 0;
}
else if (xev->type == ConfigureNotify) {
XConfigureEvent *e = (XConfigureEvent *) xev;
if (e->window == br->win) {
if (DEBUG) fprintf(stderr,"browW got a configure event (%dx%d)\n",
e->width, e->height);
if (br->wide != e->width || br->high != e->height) {
if (DEBUG) fprintf(stderr,"Forcing a redraw! (from configure)\n");
XClearArea(theDisp, br->win, 0, 0,
(u_int) e->width, (u_int) e->height, True);
resizeBrowse(br, e->width, e->height);
}
}
else rv = 0;
}
else rv = 0;
return rv;
}
/***************************************************************/
int BrowseDelWin(win)
Window win;
{
/* got a delete window request. see if the window is a browser window,
and close accordingly. Return 1 if event was eaten */
int i;
for (i=0; i<MAXBRWIN; i++) {
if (binfo[i].win == win) {
closeBrowse(&binfo[i]);
return 1;
}
}
return 0;
}
/***************************************************************/
static void resizeBrowse(br,w,h)
BROWINFO *br;
int w,h;
{
XSizeHints hints;
int i, maxv, page, maxh;
if (br->wide == w && br->high == h) return; /* no change in size */
if (XGetNormalHints(theDisp, br->win, &hints)) {
hints.width = w;
hints.height = h;
hints.flags |= USSize;
XSetNormalHints(theDisp, br->win, &hints);
}
br->wide = w; br->high = h;
br->iwWide = br->wide - (2*LRMARGINS) - (br->scrl.tsize+1) - 2;
maxh = br->high - (TOPMARGIN + BOTMARGIN);
br->iwHigh = (maxh / ISPACE_HIGH) * ISPACE_HIGH;
if (br->iwHigh < ISPACE_HIGH) br->iwHigh = ISPACE_HIGH;
XMoveResizeWindow(theDisp, br->iconW, LRMARGINS, TOPMARGIN,
(u_int) br->iwWide, (u_int) br->iwHigh);
/* move the buttons around */
br->numbutshown = (br->wide / (BUTTW + 5));
RANGE(br->numbutshown, 1, BR_NBUTTS);
br->numbutshown--;
for (i=0; i<BR_NBUTTS; i++) {
/* 'close' always goes on right-most edge */
if (i<br->numbutshown)
br->but[i].x = br->wide - (1+br->numbutshown-i) * (BUTTW+5);
else if (i==BR_CLOSE)
br->but[i].x = br->wide - (BUTTW+5);
else
br->but[i].x = br->wide + 10; /* offscreen */
br->but[i].y = br->high - BUTTH - 5;
}
br->dirMB.x = br->wide/2 - br->dirMB.w/2;
br->dirMB.x = br->dirMB.x - br->cmdMB.w/2 + (StringWidth("123 files") + 6)/2;
br->dirMB.y = 5;
br->cmdMB.x = br->wide - LRMARGINS - br->cmdMB.w - 2;
br->cmdMB.y = 5;
br->numWide = br->iwWide / ISPACE_WIDE;
br->visHigh = br->iwHigh / ISPACE_HIGH;
/* compute minv,maxv,curv,page values based on new current size */
computeScrlVals(br, &maxv, &page);
if (br->scrl.val>maxv) br->scrl.val = maxv;
SCChange(&br->scrl, LRMARGINS+br->iwWide+1, TOPMARGIN,
1, br->iwHigh, 0, maxv, br->scrl.val, page);
}
/***************************************************************/
void SetBrowStr(str)
char *str;
{
/* put string in *all* browse windows */
int i;
for (i=0; i<MAXBRWIN; i++)
setBrowStr(&binfo[i], str);
}
/***************************************************************/
static void setBrowStr(br, str)
BROWINFO *br;
char *str;
{
strncpy(br->dispstr, str, (size_t) 256);
br->dispstr[255] = '\0';
drawBrowStr(br);
XFlush(theDisp);
}
/***************************************************************/
void RegenBrowseIcons()
{
/* called whenever colormaps have changed, and icons need to be rebuilt */
int i, j, iconcount;
BFIL *bf;
BROWINFO *br;
for (j=0; j<MAXBRWIN; j++) {
br = &binfo[j];
iconcount = 0;
for (i=0; i<br->bfLen; i++) {
bf = &(br->bfList[i]);
drawTemp(br, i, br->bfLen);
if (bf->pimage && bf->ftype == BF_HAVEIMG) {
xvDestroyImage(bf->ximage);
bf->ximage = Pic8ToXImage(bf->pimage, (u_int) bf->w, (u_int) bf->h,
browcols, browR, browG, browB);
iconcount++;
}
if ((i && (i %100)==0) ||
(iconcount && (iconcount% 20)==0)) { /* mention progress */
char tmp[64];
sprintf(tmp, "Re-coloring icons: processed %d out of %d...",
i+1, br->bfLen);
setBrowStr(br, tmp);
}