forked from jedbarlow/links
-
Notifications
You must be signed in to change notification settings - Fork 0
/
listedit.c
1945 lines (1660 loc) · 56.8 KB
/
listedit.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
/* listedit.c
* (c) 2002 Petr 'Brain' Kulhavy
* This file is a part of the Links program, released under GPL.
*/
#include "links.h"
/*
(#####)
(#########)
)))) (######)
,C--O (###) _________________
|`:, \ ~~ |. , v , .|
`-__o ~~ ; | ZAKAZ KOURENI |
/ _ \ ` |. .|
| ( \__`_=k== `~~~~~~~~~~~~~~~~~'
| `-/__---'
|=====C/
`. ),'
\ /
||_|
|| |__
||____)
v v v , ,v
KONECNE NEJAKE KOMENTARE...
*/
/* Klikani myssi (nebo mysijou, jak rika Mikulas) v list-okne:
* (hrozne dulezity komentar ;-P )
*
* Klikani je vyreseno nasledovne, pokud ma nekdo lepsi napad, nebo nejake
* vyhrady, tak at mi je posle.
*
* Prostredni tlacitko+pohyb je scroll nahoru/dolu. Levym tlacitkem se nastavi
* kurzor (cerna lista) na konkretni polozku. Kdyz se levym klikne na adresar
* (na ty graficke nesmysly, ne na ten text), tak se adresar toggle
* otevre/zavre. Prave tlacitko oznaci/odznaci polozku/adresar.
*/
/* Premistovani polozek:
*
* Pravym tlacitkem se oznaci/odznaci polozka. Cudlikem "Odznacit vse" se
* vsechny polozky odznaci. Cudlik "Prestehovat" presune vsechny oznacene
* polozky za aktualni pozici, v tom poradi, jak jsou v seznamu. Pri zavreni
* adresare se vsechny polozky v adresari odznaci.
*/
/* Prekreslovani grafickych nesmyslu v okenku je samozrejme bez jedineho
* v
* bliknuti. Ne jako nejmenovane browsery... Proste obraz jako BIC (TM)
*/
/* Ovladani klavesnici:
* sipky, page up, page down, home end pohyb
* + otevri adresar
* - zavri adresar
* mezera toggle adresar
* ins, *, 8, i toggle oznacit
* ?, /, N, n hledani nahoru, dolu, znova, znova na druhou stranu
*/
/*
* Struktura struct list_decription obsahuje popis seznamu. Tenhle file
* obsahuje obecne funkce k obsluze seznamu. Pomoci struct list_description se
* seznam customizuje. Obecne funkce volaji funkce z list_description.
*
* Jedina funkce z tohoto filu, ktera se vola zvenku, je create_list_window. Ta
* vyrobi a obstarava okno pro obsluhu seznamu.
*
* Obecny list neresi veci jako nahravani seznamu z filu, ukladani na disk
* atd.(tyhle funkce si uzivatel musi napsat sam). Resi vlastne jenom to velke
* okno na manipulaci se seznamem.
*/
/*
* Aby bylo konzistentni pridavani a editovani polozek, tak se musi pytlacit.
*
* To znamena, ze pri pridavani polozky do listu se vyrobi nova polozka
* (NEPRIDA se do seznamu), pusti se edit a po zmacknuti OK se polozka prida do
* seznamu. Pri zmacknuti cancel, se polozka smaze.
*
* Pri editovani polozky se vyrobi nova polozka, zkopiruje se do ni obsah te
* puvodni (od toho tam je funkce copy_item), pak se zavola edit a podobne jako
* v predchozim pripade: pri cancel se polozka smaze, pri OK se zkopiruje do
* puvodni polozky a smaze se taky.
*
* O smazani polozky pri cancelu se bude starat uzivatelska funkce edit_item
* sama. Funkce edit_item po zmacknuti OK zavola funkci, kterou dostane. Jako
* 1. argument ji da data, ktera dostane, jako 2. argument ji preda pointer na
* item.
*/
/*
* Seznam je definovan ve struct list. Muze byt bud placaty nebo stromovy.
*
* K placatemu asi neni co dodat. U placateho se ignoruje hloubka a neexistuji
* adresare - vsechny polozky jsou si rovny (typ polozky se ignoruje).
*
* Stromovy seznam:
* Kazdy clen seznamu ma flag sbaleno/rozbaleno. U itemy se to ignoruje, u
* adresare to znamena, zda se zobrazuje obsah nebo ne. Aby rozbaleno/sbaleno
* bylo u vsech prvku adresare, to by neslo: kdybych mel adresar a v nem dalsi
* adresar, tak bych u toho vnoreneho adresare nevedel, jestli to
* sbaleno/rozbaleno je od toho vnoreneho adresare, nebo od toho nad nim.
*
* Clenove seznamu maji hloubku - cislo od 0 vyse. Cim je prvek hloubeji ve
* strukture, tim je hloubka vyssi. Obsah adresare s hloubkou x je souvisly blok
* nasledujicich prvku s hloubkou >x.
*
* Hlava ma hloubku -1 a zobrazuje se taky jako clen seznamu (aby se dal
* zobrazit prazdny seznam a dalo se do nej pridavat), takze se da vlastne cely
* seznam zabalit/rozbalit. Hlava sice nema data, ale funkce type_item ji musi
* umet zobrazit. Jako popis bude psat fixni text, napriklad "Bookmarks".
*
* Pro urychleni vykreslovani kazdy prvek v seznamu s adresarema obsahuje
* pointer na otce (polozka fotr). U plocheho seznamu se tento pointer
* ignoruje.
*
* Strukturu stromu bude vykreslovat obecna funkce (v tomto filu), protoze v
* obecnem listu je struktura uz zachycena.
*/
/*
* V hlavnim okne se da nadefinovat 1 uzivatelske tlacitko. Polozka button ve
* struct list_description obsahuje popisku tlacitka (kod stringu v
* prekodovavacich tabulkach). Funkce button_fn je zavolana pri stisku
* tlacitka, jako argument (void *) dostane aktualni polozku. Pokud je
* button_fn NULL, tlacitko se nekona.
*
* Toto tlacitko se da vyuzit napriklad u bookmarku, kde je potreba [ Goto ].
*
* Kdyz bude potreba predavat obsluzne funkci tlacitka nejake dalsi argumenty,
* tak se pripadne definice obsluzne funkce prepise.
*
* Tlacitko funguje jen na polozky. Nefunguje na adresare (pokud se jedna o
* stromovy list) ani na hlavu.
*/
/* Jak funguje default_value:
* kdyz se zmackne tlacitko add, zavola se funkce default_value, ktera si
* naalokuje nejaky data pro new_item. Do funkce default_value se treba u
* bookmarku umisti okopirovani altualniho nazvu a url stranky. Pak se zavola
* new_item, ktera si prislusne hodnoty dekoduje a pomoci nich vyplni novou
* polozku. Funkce new_item pak MUSI data dealokovat. Pokud funkce new_item
* dostane misto pointeru s daty NULL, vyrobi prazdnou polozku.
*
* Default value musi vratit hodnoty v kodovani uvedenem v list_description
*/
/* Pristupovani z vice linksu:
*
* ... se neresi - je zakazano. K tomu slouzi polozka open ve struct
* list_description, ktera rika, jestli je okno uz otevrene, nebo ne.
*/
/* Prekodovavani znakovych sad:
*
* type_item vraci text prekodovany do kodovani terminalu, ktery dostane.
*/
/* struct list *current_pos; current cursor position in the list */
/* struct list *win_offset; item at the top of the window */
/* int win_pos; current y position in the window */
#define BOHNICE "+420-2-84016111"
#define BFU_ELEMENT_EMPTY 0
#define BFU_ELEMENT_PIPE 1
#define BFU_ELEMENT_L 2
#define BFU_ELEMENT_TEE 3
#define BFU_ELEMENT_CLOSED 4
#define BFU_ELEMENT_CLOSED_DOWN 5
#define BFU_ELEMENT_OPEN 6
#define BFU_ELEMENT_OPEN_DOWN 7
/* for mouse scrolling */
static long last_mouse_y;
#ifdef G
#define sirka_scrollovadla (G_SCROLL_BAR_WIDTH<<1)
#else
#define sirka_scrollovadla 0
#endif
/* This function uses these defines from setup.h:
*
* BFU_GRX_WIDTH
* BFU_GRX_HEIGHT
* BFU_ELEMENT_WIDTH
*/
/* draws one of BFU elements: | |- [-] [+] */
/* BFU elements are used in the list window */
/* this function also defines shape and size of the elements */
/* returns width of the BFU element (all elements have the same size, but sizes differ if we're in text mode or in graphics mode) */
static int draw_bfu_element(struct terminal * term, int x, int y, unsigned char c, long b, long f, unsigned char type, unsigned char selected)
{
#ifdef G
if (!F){
#endif
unsigned char vertical=179;
unsigned char horizontal=196;
unsigned char tee=195;
unsigned char l=192;
switch (type)
{
case BFU_ELEMENT_EMPTY:
c|=ATTR_FRAME;
set_char(term,x,y,' ',c);
set_char(term,x+1,y,' ',c);
set_char(term,x+2,y,' ',c);
set_char(term,x+3,y,' ',c);
set_char(term,x+4,y,' ',c);
break;
case BFU_ELEMENT_PIPE:
c|=ATTR_FRAME;
set_char(term,x,y,' ',c);
set_char(term,x+1,y,vertical,c);
set_char(term,x+2,y,' ',c);
set_char(term,x+3,y,' ',c);
set_char(term,x+4,y,' ',c);
break;
case BFU_ELEMENT_L:
c|=ATTR_FRAME;
set_char(term,x,y,' ',c);
set_char(term,x+1,y,l,c);
set_char(term,x+2,y,horizontal,c);
set_char(term,x+3,y,horizontal,c);
set_char(term,x+4,y,' ',c);
break;
case BFU_ELEMENT_TEE:
c|=ATTR_FRAME;
set_char(term,x,y,' ',c);
set_char(term,x+1,y,tee,c);
set_char(term,x+2,y,horizontal,c);
set_char(term,x+3,y,horizontal,c);
set_char(term,x+4,y,' ',c);
break;
case BFU_ELEMENT_CLOSED:
case BFU_ELEMENT_CLOSED_DOWN:
set_char(term,x,y,'[',c);
set_char(term,x+1,y,'+',c);
set_char(term,x+2,y,']',c);
c|=ATTR_FRAME;
set_char(term,x+3,y,horizontal,c);
set_char(term,x+4,y,' ',c);
break;
case BFU_ELEMENT_OPEN:
case BFU_ELEMENT_OPEN_DOWN:
set_char(term,x,y,'[',c);
set_char(term,x+1,y,'-',c);
set_char(term,x+2,y,']',c);
c|=ATTR_FRAME;
set_char(term,x+3,y,horizontal,c);
set_char(term,x+4,y,' ',c);
break;
default:
internal("draw_bfu_element: unknown BFU element type %d.\n",type);
}
if (selected)set_char(term,x+4,y,'*',c);
return BFU_ELEMENT_WIDTH; /* BFU element size in text mode */
#ifdef G
}else{
struct graphics_device *dev=term->dev;
struct rect r;
restrict_clip_area(dev,&r,x,y,x+5*BFU_GRX_WIDTH,y+BFU_GRX_HEIGHT);
switch (type)
{
case BFU_ELEMENT_EMPTY:
drv->fill_area(dev,x,y,x+4*BFU_GRX_WIDTH,y+BFU_GRX_HEIGHT,b);
break;
case BFU_ELEMENT_PIPE:
/* pipe */
drv->draw_vline(dev,x+1*BFU_GRX_WIDTH,y,y+BFU_GRX_HEIGHT,f);
drv->draw_vline(dev,x+1+1*BFU_GRX_WIDTH,y,y+BFU_GRX_HEIGHT,f);
/* clear the rest */
drv->fill_area(dev,x,y,x+1*BFU_GRX_WIDTH,y+BFU_GRX_HEIGHT,b);
drv->fill_area(dev,x+2+1*BFU_GRX_WIDTH,y,x+4*BFU_GRX_WIDTH,y+BFU_GRX_HEIGHT,b);
break;
case BFU_ELEMENT_L:
/* l */
drv->draw_vline(dev,x+1*BFU_GRX_WIDTH,y,y+(int)(.5*BFU_GRX_HEIGHT),f);
drv->draw_vline(dev,x+1+1*BFU_GRX_WIDTH,y,y+(int)(.5*BFU_GRX_HEIGHT),f);
drv->draw_hline(dev,x+1*BFU_GRX_WIDTH,y+(int)(.5*BFU_GRX_HEIGHT),x+1+(int)(3.5*BFU_GRX_WIDTH),f);
drv->draw_hline(dev,x+1*BFU_GRX_WIDTH,y-1+(int)(.5*BFU_GRX_HEIGHT),x+1+(int)(3.5*BFU_GRX_WIDTH),f);
/* clear the rest */
drv->fill_area(dev,x,y,x+1*BFU_GRX_WIDTH,y+BFU_GRX_HEIGHT,b);
drv->fill_area(dev,x+BFU_GRX_WIDTH,y+(int)(.5*BFU_GRX_HEIGHT)+1,x+1+(int)(3.5*BFU_GRX_WIDTH),y+BFU_GRX_HEIGHT,b);
drv->fill_area(dev,x+2+BFU_GRX_WIDTH,y,x+1+(int)(3.5*BFU_GRX_WIDTH),y-1+(int)(.5*BFU_GRX_HEIGHT),b);
drv->fill_area(dev,x+1+(int)(3.5*BFU_GRX_WIDTH),y,x+4*BFU_GRX_WIDTH,y+BFU_GRX_HEIGHT,b);
break;
case BFU_ELEMENT_TEE:
/* tee */
drv->draw_vline(dev,x+1*BFU_GRX_WIDTH,y,y+BFU_GRX_HEIGHT,f);
drv->draw_vline(dev,x+1+1*BFU_GRX_WIDTH,y,y+BFU_GRX_HEIGHT,f);
drv->draw_hline(dev,x+1*BFU_GRX_WIDTH,y+(int)(.5*BFU_GRX_HEIGHT),x+1+(int)(3.5*BFU_GRX_WIDTH),f);
drv->draw_hline(dev,x+1*BFU_GRX_WIDTH,y-1+(int)(.5*BFU_GRX_HEIGHT),x+1+(int)(3.5*BFU_GRX_WIDTH),f);
/* clear the rest */
drv->fill_area(dev,x,y,x+1*BFU_GRX_WIDTH,y+BFU_GRX_HEIGHT,b);
drv->fill_area(dev,x+2+BFU_GRX_WIDTH,y+(int)(.5*BFU_GRX_HEIGHT)+1,x+1+(int)(3.5*BFU_GRX_WIDTH),y+BFU_GRX_HEIGHT,b);
drv->fill_area(dev,x+2+BFU_GRX_WIDTH,y,x+1+(int)(3.5*BFU_GRX_WIDTH),y-1+(int)(.5*BFU_GRX_HEIGHT),b);
drv->fill_area(dev,x+1+(int)(3.5*BFU_GRX_WIDTH),y,x+4*BFU_GRX_WIDTH,y+BFU_GRX_HEIGHT,b);
break;
case BFU_ELEMENT_CLOSED:
case BFU_ELEMENT_CLOSED_DOWN:
/* vertical line of the + */
drv->draw_vline(dev,x+1*BFU_GRX_WIDTH,y+1+(int)(.25*BFU_GRX_HEIGHT),y-1+(int)(.75*BFU_GRX_HEIGHT),f);
drv->draw_vline(dev,x+1+1*BFU_GRX_WIDTH,y+1+(int)(.25*BFU_GRX_HEIGHT),y-1+(int)(.75*BFU_GRX_HEIGHT),f);
/* clear around the + */
drv->fill_area(dev,x+2+(int)(.5*BFU_GRX_WIDTH),y+3,x+(int)(1.5*BFU_GRX_WIDTH),y+1+(int)(.25*BFU_GRX_HEIGHT),b);
drv->fill_area(dev,x+2+(int)(.5*BFU_GRX_WIDTH),y-1+(int)(.75*BFU_GRX_HEIGHT),x+(int)(1.5*BFU_GRX_WIDTH),y-3+BFU_GRX_HEIGHT,b);
drv->fill_area(dev,x+2+(int)(.5*BFU_GRX_WIDTH),y+1+(int)(.25*BFU_GRX_HEIGHT),x+BFU_GRX_WIDTH,y-1+(int)(.5*BFU_GRX_HEIGHT),b);
drv->fill_area(dev,x+2+BFU_GRX_WIDTH,y+1+(int)(.25*BFU_GRX_HEIGHT),x+(int)(1.5*BFU_GRX_WIDTH),y-1+(int)(.5*BFU_GRX_HEIGHT),b);
drv->fill_area(dev,x+2+(int)(.5*BFU_GRX_WIDTH),y+1+(int)(.5*BFU_GRX_HEIGHT),x+BFU_GRX_WIDTH,y-3+BFU_GRX_HEIGHT,b);
drv->fill_area(dev,x+2+BFU_GRX_WIDTH,y+1+(int)(.5*BFU_GRX_HEIGHT),x+(int)(1.5*BFU_GRX_WIDTH),y-3+BFU_GRX_HEIGHT,b);
case BFU_ELEMENT_OPEN:
case BFU_ELEMENT_OPEN_DOWN:
/* box */
drv->draw_vline(dev,x+2,y+1,y-1+BFU_GRX_HEIGHT,f);
drv->draw_vline(dev,x+3,y+1,y-1+BFU_GRX_HEIGHT,f);
drv->draw_vline(dev,x-1+2*BFU_GRX_WIDTH,y+1,y-1+BFU_GRX_HEIGHT,f);
drv->draw_vline(dev,x-2+2*BFU_GRX_WIDTH,y+1,y-1+BFU_GRX_HEIGHT,f);
drv->draw_hline(dev,x+4,y+1,x-2+2*BFU_GRX_WIDTH,f);
drv->draw_hline(dev,x+4,y+2,x-2+2*BFU_GRX_WIDTH,f);
drv->draw_hline(dev,x+4,y-2+BFU_GRX_HEIGHT,x-2+2*BFU_GRX_WIDTH,f);
drv->draw_hline(dev,x+4,y-3+BFU_GRX_HEIGHT,x-2+2*BFU_GRX_WIDTH,f);
/* horizontal line of the - */
drv->draw_hline(dev,x+2+(int)(.5*BFU_GRX_WIDTH),y+(int)(.5*BFU_GRX_HEIGHT),x+(int)(1.5*BFU_GRX_WIDTH),f);
drv->draw_hline(dev,x+2+(int)(.5*BFU_GRX_WIDTH),y-1+(int)(.5*BFU_GRX_HEIGHT),x+(int)(1.5*BFU_GRX_WIDTH),f);
/* line to title */
drv->draw_hline(dev,x+2*BFU_GRX_WIDTH,y+(BFU_GRX_HEIGHT>>1),x+1+(int)(3.5*BFU_GRX_WIDTH),f);
drv->draw_hline(dev,x+2*BFU_GRX_WIDTH,y-1+(BFU_GRX_HEIGHT>>1),x+1+(int)(3.5*BFU_GRX_WIDTH),f);
/* top and bottom short vertical line */
drv->draw_hline(dev,x+1*BFU_GRX_WIDTH,y,x+2+1*BFU_GRX_WIDTH,f);
drv->draw_hline(dev,x+1*BFU_GRX_WIDTH,y-1+BFU_GRX_HEIGHT,x+2+1*BFU_GRX_WIDTH,type == BFU_ELEMENT_OPEN || type == BFU_ELEMENT_CLOSED ? b : f);
/* clear the rest */
drv->draw_vline(dev,x,y,y+BFU_GRX_HEIGHT,b);
drv->draw_vline(dev,x+1,y,y+BFU_GRX_HEIGHT,b);
drv->draw_hline(dev,x+2,y,x+BFU_GRX_WIDTH,b);
drv->draw_hline(dev,x+2,y-1+BFU_GRX_HEIGHT,x+BFU_GRX_WIDTH,b);
drv->draw_hline(dev,x+2+BFU_GRX_WIDTH,y,x+2*BFU_GRX_WIDTH,b);
drv->draw_hline(dev,x+2+BFU_GRX_WIDTH,y-1+BFU_GRX_HEIGHT,x+2*BFU_GRX_WIDTH,b);
drv->fill_area(dev,x+2*BFU_GRX_WIDTH,y,x+1+(int)(3.5*BFU_GRX_WIDTH),y+(int)(.5*BFU_GRX_HEIGHT)-1,b);
drv->fill_area(dev,x+2*BFU_GRX_WIDTH,y+1+(int)(.5*BFU_GRX_HEIGHT),x+1+(int)(3.5*BFU_GRX_WIDTH),y+BFU_GRX_HEIGHT,b);
drv->fill_area(dev,x+4,y+3,x+2+(int)(.5*BFU_GRX_WIDTH),y-3+BFU_GRX_HEIGHT,b);
drv->fill_area(dev,x+(int)(1.5*BFU_GRX_WIDTH),y+3,x-2+2*BFU_GRX_WIDTH,y-3+BFU_GRX_HEIGHT,b);
drv->fill_area(dev,x+2+(int)(.5*BFU_GRX_WIDTH),y+3,x+(int)(1.5*BFU_GRX_WIDTH),y+1+(int)(.25*BFU_GRX_HEIGHT),b);
drv->fill_area(dev,x+2+(int)(.5*BFU_GRX_WIDTH),y-1+(int)(.75*BFU_GRX_HEIGHT),x+(int)(1.5*BFU_GRX_WIDTH),y-3+BFU_GRX_HEIGHT,b);
if (type==BFU_ELEMENT_OPEN || type == BFU_ELEMENT_OPEN_DOWN)
{
drv->fill_area(dev,x+2+(int)(.5*BFU_GRX_WIDTH),y+3,x+(int)(1.5*BFU_GRX_WIDTH),y-1+(int)(.5*BFU_GRX_HEIGHT),b);
drv->fill_area(dev,x+2+(int)(.5*BFU_GRX_WIDTH),y+1+(int)(.5*BFU_GRX_HEIGHT),x+(int)(1.5*BFU_GRX_WIDTH),y-3+BFU_GRX_HEIGHT,b);
}
drv->fill_area(dev,x+1+(int)(3.5*BFU_GRX_WIDTH),y,x+4*BFU_GRX_WIDTH,y+BFU_GRX_HEIGHT,b);
break;
default:
internal("draw_bfu_element: unknown BFU element type %d.\n",type);
}
if (!selected)
drv->fill_area(dev,x+4*BFU_GRX_WIDTH,y,x+5*BFU_GRX_WIDTH,y+BFU_GRX_HEIGHT,b);
else
{
drv->fill_area(dev,x+4*BFU_GRX_WIDTH,y,x+(int)(4.25*BFU_GRX_WIDTH),y+BFU_GRX_HEIGHT,b);
drv->fill_area(dev,x+(int)(4.25*BFU_GRX_WIDTH),y,x+(int)(4.75*BFU_GRX_WIDTH),y+(int)(2.5*BFU_GRX_HEIGHT),b);
drv->fill_area(dev,x+(int)(4.25*BFU_GRX_WIDTH),y+(int)(.25*BFU_GRX_HEIGHT),x+(int)(4.75*BFU_GRX_WIDTH),y+(int)(.75*BFU_GRX_HEIGHT),f);
drv->fill_area(dev,x+(int)(4.25*BFU_GRX_WIDTH),y+(int)(.75*BFU_GRX_HEIGHT),x+(int)(4.75*BFU_GRX_WIDTH),y+BFU_GRX_HEIGHT,b);
drv->fill_area(dev,x+(int)(4.75*BFU_GRX_WIDTH),y,x+5*BFU_GRX_WIDTH,y+BFU_GRX_HEIGHT,b);
}
drv->set_clip_area(dev, &r);
return BFU_ELEMENT_WIDTH;
}
#endif
}
/* aux structure for parameter exchange for redrawing list window */
struct redraw_data
{
struct list_description *ld;
struct dialog_data *dlg;
int n;
};
static void redraw_list(struct terminal *term, void *bla);
/* returns next visible item in tree list */
/* works only with visible items (head or any item returned by this function) */
/* when list is flat returns next item */
static struct list *next_in_tree(struct list_description *ld, struct list *item)
{
int depth=item->depth;
/* flat list */
if (!(ld->type))return item->next;
if (!((item->type)&1)||((item->type)&2)) /* item or opened folder */
return item->next;
/* skip content of this folder */
do item=item->next; while (item->depth>depth); /* must stop on head 'cause it's depth is -1 */
return item;
}
/* returns previous visible item in tree list */
/* works only with visible items (head or any item returned by this function) */
/* when list is flat returns previous item */
static struct list *prev_in_tree(struct list_description *ld, struct list *item)
{
struct list *last_closed;
int depth=item->depth;
/* flat list */
if (!(ld->type))return item->prev;
if (item==ld->list)depth=0;
/* items with same or lower depth must be visible, because current item is visible */
if ((((struct list*)(item->prev))->depth)<=(item->depth))return item->prev;
/* find item followed with opened fotr's only */
/* searched item is last closed folder (going up from item) or item->prev */
last_closed=item->prev;
item=item->prev;
while (1)
{
if (((item->type)&3)==1)/* closed folder */
last_closed=item;
if ((item->depth)<=depth)break;
item=item->fotr;
}
return last_closed;
}
#ifdef G
static int get_total_items(struct list_description *ld)
{
struct list*l=ld->list;
int count=0;
do{
l=next_in_tree(ld,l);
count++;
}while(l!=ld->list);
return count;
}
static int get_scroll_pos(struct list_description *ld)
{
struct list*l;
int count;
for (l=ld->list,count=0;l!=ld->win_offset;l=next_in_tree(ld,l),count++)
;
return count;
}
static int get_visible_items(struct list_description *ld)
{
struct list*l=ld->win_offset;
int count=0;
do{
l=next_in_tree(ld,l);
count++;
}while(count<ld->n_items&&l!=ld->list);
return count;
}
static struct list *find_last_in_window(struct list_description *ld)
{
struct list*l=ld->win_offset;
struct list *x=l;
int count=0;
do{
l=next_in_tree(ld,l);
count++;
if (l!=ld->list&&count!=ld->n_items)x=l;
}while(count<ld->n_items&&l!=ld->list);
return x;
}
#endif
static int get_win_pos(struct list_description *ld)
{
struct list*l;
int count;
for (l=ld->win_offset,count=0;l!=ld->current_pos;l=next_in_tree(ld,l),count++)
;
return count;
}
static void unselect_in_folder(struct list_description *ld, struct list *l)
{
int depth;
depth=l->depth;
for(l=l->next;l!=ld->list&&l->depth>depth;l=l->next)
l->type&=~4;
}
/* aux function for list_item_add */
static void list_insert_behind_item(struct dialog_data *dlg, void *p, void *i, struct list_description *ld)
{
struct list *item=(struct list *)i;
struct list *pos=(struct list *)p;
struct list *a;
struct redraw_data rd;
/* BEFORE: ... <----> pos <--(possible invisible items)--> a <----> ... */
/* AFTER: ... <----> pos <--(possible invisible items)--> item <----> a <----> ... */
a=next_in_tree(ld,pos);
((struct list*)(a->prev))->next=item;
item->prev=a->prev;
item->next=a;
a->prev=item;
/* if list is flat a->fotr will contain nosenses, but it won't crash ;-) */
if (((pos->type)&3)==3||(pos->depth)==-1){item->fotr=pos;item->depth=pos->depth+1;} /* open directory or head */
else {item->fotr=pos->fotr;item->depth=pos->depth;}
ld->current_pos=next_in_tree(ld,ld->current_pos); /* ld->current_pos->next==item */
ld->win_pos++;
if (ld->win_pos>ld->n_items-1) /* scroll down */
{
ld->win_pos=ld->n_items-1;
ld->win_offset=next_in_tree(ld,ld->win_offset);
}
ld->modified=1;
rd.ld=ld;
rd.dlg=dlg;
rd.n=0;
draw_to_window(dlg->win,redraw_list,&rd);
}
/* aux function for list_item_edit */
/* copies data of src to dest and calls free on the src */
/* first argument is argument passed to user function */
static void list_copy_item(struct dialog_data *dlg, void *d, void *s, struct list_description *ld)
{
struct list *src=(struct list *)s;
struct list *dest=(struct list *)d;
struct redraw_data rd;
ld->copy_item(src,dest);
ld->delete_item(src);
ld->modified=1; /* called after an successful edit */
rd.ld=ld;
rd.dlg=dlg;
rd.n=0;
draw_to_window(dlg->win,redraw_list,&rd);
}
/* creates new item (calling new_item function) and calls edit_item function */
static int list_item_add(struct dialog_data *dlg,struct dialog_item_data *useless)
{
struct list_description *ld=(struct list_description*)(dlg->dlg->udata2);
struct list *item=ld->current_pos;
struct list *new_item;
if (!(new_item=ld->new_item(ld->default_value ? ld->default_value((struct session*)(dlg->dlg->udata),0) : NULL)))return 1;
new_item->prev=0;
new_item->next=0;
new_item->type=0;
new_item->depth=0;
ld->edit_item(dlg,new_item,list_insert_behind_item,item,TITLE_ADD);
return 0;
}
/* like list_item_add but creates folder */
static int list_folder_add(struct dialog_data *dlg,struct dialog_item_data *useless)
{
struct list_description *ld=(struct list_description*)(dlg->dlg->udata2);
struct list *item=ld->current_pos;
struct list *new_item;
if (!(new_item=ld->new_item(NULL)))return 1;
new_item->prev=0;
new_item->next=0;
new_item->type=1;
new_item->depth=0;
ld->edit_item(dlg,new_item,list_insert_behind_item,item,TITLE_ADD);
return 0;
}
static int list_item_edit(struct dialog_data *dlg,struct dialog_item_data *useless)
{
struct list_description *ld=(struct list_description*)(dlg->dlg->udata2);
struct list *item=ld->current_pos;
struct list *new_item;
if (item==ld->list)return 0; /* head */
if (!(new_item=ld->new_item(NULL)))return 1;
new_item->prev=0;
new_item->next=0;
ld->copy_item(item,new_item);
ld->edit_item(dlg,new_item,list_copy_item,item,TITLE_EDIT);
return 0;
}
static inline int is_parent(struct list_description *ld, struct list *item, struct list *parent)
{
struct list *l;
if (ld->type)
for (l=item;l->depth>=0;l=l->fotr)
if (l==parent) return 1;
return 0;
}
static int list_item_move(struct dialog_data *dlg,struct dialog_item_data *useless)
{
struct list_description *ld=(struct list_description*)(dlg->dlg->udata2);
struct list *i;
struct list *behind=ld->current_pos;
struct redraw_data rd;
int window_moved=0;
int count=0;
if (ld->current_pos->type&4) /* odznacime current_pos, kdyby nahodou byla oznacena */
{
count++;
ld->current_pos->type&=~4;
}
for (i=ld->list->next;i!=ld->list;)
{
struct list *next=next_in_tree(ld,i);
struct list *prev=i->prev;
struct list *behind_next=next_in_tree(ld,behind); /* to se musi pocitat pokazdy, protoze by se nam mohlo stat, ze to je taky oznaceny */
struct list *item_last=next->prev; /* last item of moved block */
if (is_parent(ld, ld->current_pos, i)) /* we're moving directory into itself - let's behave like item was not selected */
{
i->type&=~4;
i=next;
count++;
continue;
}
if (!(i->type&4)){i=next;continue;}
if ((i->type&3)==3) /* dirty trick */
{
i->type&=~2;
next=next_in_tree(ld,i);
prev=i->prev;
item_last=next->prev;
i->type|=2;
}
if (i==ld->win_offset)
{
window_moved=1;
if (next!=ld->list)ld->win_offset=next;
}
/* upravime fotrisko a hloubku */
if (ld->type)
{
int a=i->depth;
struct list *l=i;
if (((behind->type)&3)==3||behind==ld->list)/* open folder or head */
{i->fotr=behind;i->depth=behind->depth+1;}
else {i->fotr=behind->fotr;i->depth=behind->depth;}
a=i->depth-a;
/* poopravime hloubku v adresari */
if (l!=item_last)
{
do{
l=l->next;
l->depth+=a;
} while(l!=item_last);
}
}
if (behind_next==i)goto predratovano; /* to uz je vsechno, akorat menime hloubku */
/* predratujeme ukazatele kolem bloku na stare pozici */
prev->next=next;
next->prev=prev;
/* posuneme na novou pozici (tesne pred behind_next) */
i->prev=behind_next->prev;
((struct list*)(behind_next->prev))->next=i;
item_last->next=behind_next;
behind_next->prev=item_last;
predratovano:
/* odznacime */
i->type&=~4;
unselect_in_folder(ld,i);
/* upravime pointery pro dalsi krok */
behind=i;
i=next;
count++;
}
if (window_moved)
{
ld->current_pos=ld->win_offset;
ld->win_pos=0;
}
else
ld->win_pos=get_win_pos(ld);
if (!count)
msg_box(
dlg->win->term, /* terminal */
NULL, /* blocks to free */
TEXT_(T_MOVE), /* title */
AL_CENTER, /* alignment */
TEXT_(T_NO_ITEMS_SELECTED), /* text */
NULL, /* data */
1, /* # of buttons */
TEXT_(T_CANCEL),NULL,B_ESC|B_ENTER /* button1 */
);
else
{
ld->modified=1;
rd.ld=ld;
rd.dlg=dlg;
rd.n=0;
draw_to_window(dlg->win,redraw_list,&rd);
}
return 0;
}
/* unselect all items */
static int list_item_unselect(struct dialog_data *dlg,struct dialog_item_data *useless)
{
struct list_description *ld=(struct list_description*)(dlg->dlg->udata2);
struct list *item=ld->current_pos;
struct redraw_data rd;
item=ld->list;
do{
item->type&=~4;
item=item->next;
}while(item!=ld->list);
rd.ld=ld;
rd.dlg=dlg;
rd.n=0;
draw_to_window(dlg->win,redraw_list,&rd);
return 0;
}
/* user button function - calls button_fn with current item */
static int list_item_button(struct dialog_data *dlg, struct dialog_item_data *useless)
{
struct list_description *ld=(struct list_description*)(dlg->dlg->udata2);
struct list *item=ld->current_pos;
struct session *ses=(struct session *)(dlg->dlg->udata);
if (!(ld->button_fn))internal("Links got schizophrenia! Call "BOHNICE".\n");
if (item==(ld->list)||list_empty(*item))return 0; /* head or empty list */
if (ld->type&&((item->type)&1))return 0; /* this is tree list and item is directory */
ld->button_fn(ses,item);
cancel_dialog(dlg, useless);
return 0;
}
struct ve_skodarne_je_jeste_vetsi_narez
{
struct list_description* ld;
struct dialog_data *dlg;
struct list* item;
};
/* when delete is confirmed adjusts current_pos and calls delete function */
static void delete_ok(void * data)
{
struct list_description* ld=((struct ve_skodarne_je_jeste_vetsi_narez*)data)->ld;
struct list* item=((struct ve_skodarne_je_jeste_vetsi_narez*)data)->item;
struct dialog_data* dlg=((struct ve_skodarne_je_jeste_vetsi_narez*)data)->dlg;
struct redraw_data rd;
/* strong premise: we can't delete head of the list */
if (ld->current_pos->next!=ld->list) {
if (ld->current_pos == ld->win_offset) ld->win_offset = ld->current_pos->next;
ld->current_pos=ld->current_pos->next;
}
else /* last item */
{
if (!(ld->win_pos)) /* only one line on the screen */
ld->win_offset=prev_in_tree(ld,ld->win_offset);
else ld->win_pos--;
ld->current_pos=prev_in_tree(ld,ld->current_pos);
}
ld->delete_item(item);
rd.ld=ld;
rd.dlg=dlg;
rd.n=0;
ld->modified=1;
draw_to_window(dlg->win,redraw_list,&rd);
}
/* when delete folder is confirmed adjusts current_pos and calls delete function */
static void delete_folder_recursively(void * data)
{
struct list_description* ld=((struct ve_skodarne_je_jeste_vetsi_narez*)data)->ld;
struct list* item=((struct ve_skodarne_je_jeste_vetsi_narez*)data)->item;
struct dialog_data* dlg=((struct ve_skodarne_je_jeste_vetsi_narez*)data)->dlg;
struct redraw_data rd;
struct list *i,*j;
int depth;
for (i=item->next,depth=item->depth;i!=ld->list&&i->depth>depth;)
{
j=i;
i=i->next;
ld->delete_item(j);
}
/* strong premise: we can't delete head of the list */
if (ld->current_pos->next!=ld->list) {
if (ld->current_pos == ld->win_offset) ld->win_offset = ld->current_pos->next;
ld->current_pos=ld->current_pos->next;
}
else /* last item */
{
if (!(ld->win_pos)) /* only one line on the screen */
ld->win_offset=prev_in_tree(ld,ld->win_offset);
else ld->win_pos--;
ld->current_pos=prev_in_tree(ld,ld->current_pos);
}
ld->delete_item(item);
rd.ld=ld;
rd.dlg=dlg;
rd.n=0;
ld->modified=1;
draw_to_window(dlg->win,redraw_list,&rd);
}
/* tests if directory is emty */
static int is_empty_dir(struct list_description *ld, struct list *dir)
{
if (!(ld->type))return 1; /* flat list */
if (!((dir->type)&1))return 1; /* not a directory */
return (((struct list *)(dir->next))->depth<=dir->depth); /* head depth is -1 */
}
/* delete dialog */
static int list_item_delete(struct dialog_data *dlg,struct dialog_item_data *useless)
{
struct terminal *term=dlg->win->term;
struct list_description *ld=(struct list_description*)(dlg->dlg->udata2);
struct list *item=ld->current_pos;
/*struct session *ses=(struct session *)(dlg->dlg->udata);*/
unsigned char *txt;
struct ve_skodarne_je_jeste_vetsi_narez *narez;
if (item==(ld->list)||list_empty(*item))return 0; /* head or empty list */
narez=mem_alloc(sizeof(struct ve_skodarne_je_jeste_vetsi_narez));
narez->ld=ld;narez->item=item;narez->dlg=dlg;
txt=ld->type_item(term, item,0);
if (!txt)
{
txt=mem_alloc(sizeof(unsigned char));
*txt=0;
}
if ((item->type)&1) /* folder */
{
if (!is_empty_dir(ld,item))
msg_box(
term, /* terminal */
getml(txt,narez,NULL), /* blocks to free */
TEXT_(T_DELETE_FOLDER), /* title */
AL_CENTER|AL_EXTD_TEXT, /* alignment */
TEXT_(T_FOLDER),cast_uchar " \"",txt,cast_uchar "\" ",TEXT_(T_NOT_EMPTY_SURE_DELETE),NULL, /* text */
narez, /* data for ld->delete_item */
2, /* # of buttons */
TEXT_(T_NO),NULL,B_ESC, /* button1 */
TEXT_(T_YES),delete_folder_recursively,B_ENTER /* button2 */
);
else
msg_box(
term, /* terminal */
getml(txt,narez,NULL), /* blocks to free */
TEXT_(T_DELETE_FOLDER), /* title */
AL_CENTER|AL_EXTD_TEXT, /* alignment */
TEXT_(T_SURE_DELETE),cast_uchar " ",TEXT_(T_fOLDER),cast_uchar " \"",txt,cast_uchar "\"?",NULL, /* null-terminated text */
narez, /* data for ld->delete_item */
2, /* # of buttons */
TEXT_(T_YES),delete_ok,B_ENTER, /* button1 */
TEXT_(T_NO),NULL,B_ESC /* button2 */
);
}
else /* item */
msg_box(
term, /* terminal */
getml(txt,narez,NULL), /* blocks to free */
TEXT_(ld->delete_dialog_title), /* title */
AL_CENTER|AL_EXTD_TEXT, /* alignment */
TEXT_(T_SURE_DELETE),cast_uchar " ",TEXT_(ld->item_description),cast_uchar " \"",txt,cast_uchar "\"?",NULL, /* null-terminated text */
narez, /* data for ld->delete_item */
2, /* # of buttons */
TEXT_(T_YES),delete_ok,B_ENTER, /* button1 */
TEXT_(T_NO),NULL,B_ESC /* button2 */
);
return 0;
}
static int redraw_list_element(struct terminal *term, struct dialog_data *dlg, int y, int w, struct list_description *ld, struct list *l)
{
struct list *lx;
unsigned char *xp;
int xd;
unsigned char *txt;
int x=0;
int text_position;
unsigned char color = 0;
long bgcolor = 0, fgcolor = 0;
int b;
unsigned char element;
if (!F) {
color=(l==ld->current_pos)?COLOR_MENU_SELECTED:COLOR_MENU_TEXT;