forked from fkhannouf/BGUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistclass.c
More file actions
4728 lines (4230 loc) · 108 KB
/
listclass.c
File metadata and controls
4728 lines (4230 loc) · 108 KB
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
/*
* @(#) $Header$
*
* BGUI library
* listclass.c
*
* (C) Copyright 1998 Manuel Lemos.
* (C) Copyright 1996-1997 Ian J. Einman.
* (C) Copyright 1993-1996 Jaba Development.
* (C) Copyright 1993-1996 Jan van den Baard.
* All Rights Reserved.
*
* $Log$
* Revision 42.4 2004/06/16 20:16:48 verhaegs
* Use METHODPROTO, METHOD_END and REGFUNCPROTOn where needed.
*
* Revision 42.3 2000/08/17 15:09:18 chodorowski
* Fixed compiler warnings.
*
* Revision 42.2 2000/05/15 19:27:01 stegerg
* another hundreds of REG() macro replacements in func headers/protos.
*
* Revision 42.1 2000/05/14 23:32:47 stegerg
* changed over 200 function headers which all use register
* parameters (oh boy ...), because the simple REG() macro
* doesn't work with AROS. And there are still hundreds
* of headers left to be fixed :(
*
* Many of these functions would also work with stack
* params, but since i have fixed every single one
* I encountered up to now, I guess will have to do
* the same for the rest.
*
* Revision 42.0 2000/05/09 22:09:28 mlemos
* Bumped to revision 42.0 before handing BGUI to AROS team
*
* Revision 41.11 2000/05/09 19:54:37 mlemos
* Merged with the branch Manuel_Lemos_fixes.
*
* Revision 41.10.2.17 1999/08/08 23:05:11 mlemos
* Assured that the list is redrawn when the list font or the default font
* changes.
* Made the entry height be always recomputed every time the list is rendered.
*
* Revision 41.10.2.16 1999/07/28 06:34:32 mlemos
* Added rendering damage list after the ScrollRaster() call.
*
* Revision 41.10.2.15 1999/07/18 06:15:42 mlemos
* Fixed the problem of very quick drop without dragging.
*
* Revision 41.10.2.14 1999/07/03 15:17:40 mlemos
* Replaced the calls to CallHookPkt to BGUI_CallHookPkt.
*
* Revision 41.10.2.13 1999/05/24 20:20:43 mlemos
* Added fix for attempt to free BaseInfo handle twice when dragging 10 or
* more entries.
*
* Revision 41.10.2.12 1998/12/20 01:37:42 mlemos
* Ensured that the list is fully redrawn when a change like adding a new
* entry that makes the list partially invisible, makes the list overhead
* increase.
* Fixed computation of the top overhead area of a list view with title to
* include the height of the separator line (2 pixels).
*
* Revision 41.10.2.11 1998/12/07 03:07:03 mlemos
* Replaced OpenFont and CloseFont calls by the respective BGUI debug macros.
*
* Revision 41.10.2.10 1998/12/07 00:49:52 mlemos
* Fixed range checking bug of new list top entry when the number of visible
* entries is larger than the total entries.
*
* Revision 41.10.2.9 1998/12/06 21:38:21 mlemos
* Ensured that when the parent view and window are passed to the listview
* scroller gadget on its creation or when are set by OM_SET OM_UPDATE.
*
* Revision 41.10.2.8 1998/12/06 21:20:41 mlemos
* Ensured that the key activation selects the previous or the next selected
* entries in Multi Selection lists.
* Ensured that selecting the previous or the next selected entries in Multi
* Selection lists always deselects any previously selected entries.
*
* Revision 41.10.2.7 1998/11/28 13:45:17 mlemos
* Made the default flag of the list to pre clear the entries.
*
* Revision 41.10.2.6 1998/11/12 16:23:33 mlemos
* Passed NULL rastport pointer to AllocBaseInfo in the methods
* BASE_DRAGACTIVE, BASE_DRAGINACTIVE and BASE_DRAGUPDATE to ensure that it
* legally obtains the Rastport.
*
* Revision 41.10.2.5 1998/10/11 15:28:58 mlemos
* Enforced the columns minimum width value.
*
* Revision 41.10.2.4 1998/10/11 14:50:21 mlemos
* Fixed the computation of the initial offset of the column bars when the
* user starts to drag them.
*
* Revision 41.10.2.3 1998/06/16 01:22:10 mlemos
* Passed NULL rastport pointer to AllocBaseInfo in DrawDragLine to ensure
* that it legally obtains the Rastport.
*
* Revision 41.10.2.2 1998/06/15 21:48:43 mlemos
* Passed NULL rastport pointer to AllocBaseInfo in NewTop to ensure that it
* legally obtains the Rastport.
*
* Revision 41.10.2.1 1998/03/01 15:38:05 mlemos
* Added support to track BaseInfo memory leaks.
*
* Revision 41.10 1998/02/25 21:12:31 mlemos
* Bumping to 41.10
*
* Revision 1.1 1998/02/25 17:09:00 mlemos
* Ian sources
*
*
*/
/*
* Incorporates MultiColumnListview by Nick Christie.
* New code, but the interface is the same.
*/
#include "include/classdefs.h"
/*
* Internal entry storage.
*/
typedef struct lvEntry {
struct lvEntry *lve_Next; /* Next entry. */
struct lvEntry *lve_Prev; /* Previous entry. */
ULONG lve_Flags; /* See below. */
APTR lve_Entry; /* Entry data. */
} LVE;
#define LVEF_SELECTED (1<<0) /* Entry is selected. */
#define LVEF_DISABLED (1<<1) /* Entry is disabled. */
#define LVEF_HIDDEN (1<<2) /* Entry is hidden. */
#define LVEF_REFRESH (1<<31) /* Entry must be redrawn. */
typedef struct {
LVE *lvl_First; /* First entry. */
LVE *lvl_EndMarker; /* End marker. */
LVE *lvl_Last; /* Last entry. */
} LVL;
typedef struct cd_ {
UWORD cd_Offset; /* Left offset of column. */
UWORD cd_Width; /* Width of column. */
UWORD cd_MinWidth; /* Minimum column width. */
UWORD cd_MaxWidth; /* Maximum column width. */
UWORD cd_Weight; /* Relative Weight of column. */
ULONG cd_Flags; /* Column Flags. */
} CD;
#define LVCF_NOSEPARATOR (1<<0) /* No column separator. */
#define LVCF_HIDDEN (1<<1) /* Column is not visible. */
#define LVCF_DRAGGABLE (1<<2) /* Column is draggable. */
#define LVCF_PRECLEAR (1<<3) /* Column is pre-cleared. */
/*
* Object instance data.
*/
typedef struct ld_ {
ULONG ld_Flags; /* See below. */
Object *ld_Prop; /* Scroller. */
BC *ld_BC; /* Bounding boxes. */
struct IBox ld_ListArea; /* Area bounds. */
LVL ld_Entries; /* List of entries. */
// LVL ld_Hidden; /* Entries filtered out. */
LVE *ld_TopEntry; /* Top entry. */
ULONG ld_ActiveEntry; /* Active entry number. */
LVE *ld_LastActive; /* Last active entry. */
ULONG ld_LastNum; /* Last active entry number. */
UWORD ld_LastCol; /* Last active column. */
LVE *ld_LastAdded; /* Last added entry. */
UWORD ld_EntryHeight; /* Height of a single entry. */
UWORD ld_Overhead; /* View area overhead. */
ULONG ld_Top; /* Top entry visible. */
ULONG ld_Total; /* Number of entries. */
LONG ld_Visible; /* Number of visible entries. */
struct Hook *ld_Resource; /* Resource hook. */
struct Hook *ld_Display; /* Display hook. */
struct Hook *ld_Compare; /* Comparisson hook. */
struct Hook *ld_TitleHook; /* Title hook. */
UBYTE *ld_Title; /* Title. */
// struct Hook *ld_Filter; /* Filter hook. */
struct TextAttr *ld_ListFont; /* List font. */
struct TextFont *ld_Font; /* List font. */
APTR ld_MemoryPool; /* OS 3.0 memory pool. */
ULONG ld_MultiStart; /* Start of multi-(de)select. */
UWORD ld_MultiMode; /* Mode of multi-(de)select. */
UWORD ld_MinShown; /* Min # lines shown. */
ULONG ld_Secs[2]; /* Double-clicks. */
ULONG ld_Mics[2];
ULONG ld_NewPos; /* New entry position. */
APTR ld_ScanEntry; /* Last scanned entry. */
LVE *ld_ScanNode; /* And it's node. */
ULONG ld_DropSpot; /* Place where dropped. */
ULONG ld_DrawSpot; /* Place where line drawn. */
struct RastPort *ld_DragRP; /* Draggable bitmap+rport. */
struct RastPort *ld_LineBuffer; /* Place for drop line. */
UWORD ld_Columns; /* number of columns, > 0 */
UWORD ld_OneColumn; /* Render only one column. */
UWORD ld_DragColumn; /* column # being dragged, 0...n */
WORD ld_DragXLine; /* current x position of drag line */
CD *ld_CD; /* Column Descriptors. */
} LD;
#define ld_InnerBox ld_BC->bc_InnerBox
#define ld_OuterBox ld_BC->bc_OuterBox
#define ld_HitBox ld_BC->bc_HitBox
#define ld_Frame ld_BC->bc_Frame
#define LDF_READ_ONLY (1 << 0 ) /* Read-only list. */
#define LDF_MULTI_SELECT (1 << 1 ) /* Multi-select list. */
#define LDF_REFRESH_ALL (1 << 2 ) /* Refresh whole list. */
#define LDF_PROPACTIVE (1 << 4 ) /* Prop gadget is active. */
#define LDF_LIST_BUSY (1 << 5 ) /* We are busy with the list. */
#define LDF_NOSHIFT (1 << 6 ) /* Multi-select without shift */
#define LDF_CUSTOMDISABLE (1 << 7 ) /* Display hook renders disabled state. */
#define LDF_SHOWDROPSPOT (1 << 8 ) /* Show where we they drop. */
#define LDF_DRAGGABLE (1 << 9 ) /* We are in draggable mode. */
#define LDF_ALLOW_DRAG (1 << 10) /* Allow column dragging by user */
#define LDF_OFFSETS_VALID (1 << 11) /* Column offsets are valid */
#define LDF_DRAGGING_COLUMN (1 << 12) /* Currently dragging a column */
#define LDF_NEW_COLUMN_POS (1 << 13) /* Set when user releases column */
#define LDF_PRE_CLEAR (1 << 14) /* Pre-clear entry rectangle. */
#define LDF_THIN_FRAMES (1 << 15) /* 1:1 Aspect ratio frames. */
#define LDF_MOVE_DROPBOX (1 << 16) /* Move the dragbox around? */
#define LDF_ONE_COLUMN (1 << 17) /* Redraw only one column. */
#define LD_ENTRY(tag, offset, flags) PACK_ENTRY(LISTV_TAGSTART, tag, ld_, offset, flags)
#define LD_FLAG(tag, flag) PACK_LONGBIT(LISTV_TAGSTART, tag, ld_, ld_Flags, PKCTRL_BIT, flag)
static ULONG ListPackTable[] =
{
PACK_STARTTABLE(LISTV_TAGSTART),
LD_ENTRY(LISTV_MinEntriesShown, ld_MinShown, PKCTRL_UWORD),
LD_ENTRY(LISTV_Top, ld_Top, PKCTRL_ULONG),
LD_ENTRY(LISTV_Columns, ld_Columns, PKCTRL_UWORD),
LD_FLAG(LISTV_ReadOnly, LDF_READ_ONLY),
LD_FLAG(LISTV_MultiSelect, LDF_MULTI_SELECT),
LD_FLAG(LISTV_ThinFrames, LDF_THIN_FRAMES),
LD_FLAG(LISTV_MultiSelectNoShift, LDF_NOSHIFT),
LD_FLAG(LISTV_ShowDropSpot, LDF_SHOWDROPSPOT),
LD_FLAG(LISTV_CustomDisable, LDF_CUSTOMDISABLE),
LD_FLAG(LISTV_DragColumns, LDF_ALLOW_DRAG),
LD_FLAG(LISTV_PreClear, LDF_PRE_CLEAR),
PACK_ENDTABLE
};
#define LC_ENTRY(tag, offset, flags) PACK_ENTRY(LISTC_TAGSTART, tag, cd_, offset, flags)
#define LC_FLAG(tag, flag) PACK_LONGBIT(LISTC_TAGSTART, tag, cd_, cd_Flags, PKCTRL_BIT, flag)
static ULONG ColumnPackTable[] =
{
PACK_STARTTABLE(LISTV_TAGSTART),
LC_ENTRY(LISTC_MinWidth, cd_MinWidth, PKCTRL_UWORD),
LC_ENTRY(LISTC_MaxWidth, cd_MaxWidth, PKCTRL_UWORD),
LC_ENTRY(LISTC_Weight, cd_Weight, PKCTRL_UWORD),
LC_FLAG(LISTC_Draggable, LVCF_DRAGGABLE),
LC_FLAG(LISTC_Hidden, LVCF_HIDDEN),
LC_FLAG(LISTC_NoSeparator, LVCF_NOSEPARATOR),
LC_FLAG(LISTC_PreClear, LVCF_PRECLEAR),
PACK_ENDTABLE
};
/*
* Prop map-list.
*/
STATIC struct TagItem PGA2LISTV[] = {
{ PGA_Top, LISTV_Top, },
{ TAG_END },
};
STATIC VOID RenderEntry(Object *obj, LD *ld, struct BaseInfo *bi, LVE *lve, ULONG top);
#define REL_ZERO (0x80000000)
STATIC VOID ASM ColumnSeparators(REG(a0) LD *ld, REG(a1) struct BaseInfo *bi, REG(d0) ULONG x, REG(d1) ULONG y, REG(d2) ULONG h)
{
int col, pena, penb, x2, y2;
struct RastPort *rp = bi->bi_RPort;
x2 = x + ld->ld_InnerBox.Width - 4;
y2 = y + h - 1;
if (ld->ld_Flags & LDF_READ_ONLY)
{
pena = SHINEPEN;
penb = SHADOWPEN;
}
else
{
pena = SHADOWPEN;
penb = SHINEPEN;
};
for (col = 0; col < ld->ld_Columns; col++)
{
if (!(ld->ld_CD[col].cd_Flags & LVCF_HIDDEN))
{
x += ld->ld_CD[col].cd_Width - 2;
if (!(ld->ld_CD[col].cd_Flags & LVCF_NOSEPARATOR) && (x < x2))
{
BSetDPenA(bi, pena);
Move(rp, x, y);
Draw(rp, x++, y2);
BSetDPenA(bi, penb);
Move(rp, x, y);
Draw(rp, x++, y2);
};
};
};
}
/*
* Find a node by it's number (slow!).
*/
STATIC ASM LVE *FindNode( REG(a0) LD *ld, REG(d0) ULONG num )
{
LVE *lve;
ULONG lnum = 0L;
/*
* List empty?
*/
if ( ! ld->ld_Entries.lvl_First->lve_Next )
return( NULL );
/*
* Scan the list top-down to find
* the correct entry.
*/
for ( lve = ld->ld_Entries.lvl_First; lve->lve_Next; lve = lve->lve_Next, lnum++ ) {
if ( lnum == num )
break;
}
return( lve );
}
/*
* Find a node by it's number (quickly).
*/
STATIC ASM LVE *FindNodeQuick( REG(a0) LD *ld, REG(d0) ULONG num )
{
LVE *lve = ld->ld_TopEntry;
ULONG top = ld->ld_Top;
/*
* List empty?
*/
if ( ! ld->ld_Entries.lvl_First->lve_Next )
return( NULL );
/*
* Scan the list from the current node
* to find the correct entry.
*/
if ( num > top ) {
for ( ; lve->lve_Next; lve = lve->lve_Next, top++ ) {
if ( top == num )
break;
}
} else if ( num < top ) {
for ( ; lve->lve_Prev != ( LVE * )&ld->ld_Entries; lve = lve->lve_Prev, top-- ) {
if ( top == num )
break;
}
}
return( lve );
}
/*
* Add an entry in the list. Ugly code with
* lotsa goto's :)
*/
STATIC ASM VOID AddEntryInList( REG(a0) LD *ld, REG(a1) Object *obj, REG(a2) LVE *lve, REG(d0) ULONG how )
{
LVE *tmp;
struct lvCompare lvc;
/*
* Save it.
*/
ld->ld_LastAdded = lve;
/*
* Set top entry if not
* defined yet.
*/
if (!ld->ld_TopEntry)
ld->ld_TopEntry = lve;
switch (how)
{
case LVAP_SORTED:
/*
* Entries available?
*/
if (!ld->ld_Entries.lvl_First->lve_Next)
/*
* No. Simply AddTail the entry.
*/
goto tailIt;
/*
* Scan through the entries.
*/
for (tmp = ld->ld_Entries.lvl_Last; ; tmp = tmp->lve_Prev)
{
/*
* Comparrison hook?
*/
if (!ld->ld_Compare)
{
/*
* No. Simple string comparrison.
*/
if (Stricmp((STRPTR)lve->lve_Entry, (STRPTR)tmp->lve_Entry) >= 0)
break;
}
else
{
lvc.lvc_EntryA = lve->lve_Entry;
lvc.lvc_EntryB = tmp->lve_Entry;
if ((LONG)BGUI_CallHookPkt(ld->ld_Compare, (VOID *)obj, (VOID *)&lvc) >= 0)
break;
};
/*
* Done?
*/
if (tmp == ld->ld_Entries.lvl_First)
{
ld->ld_TopEntry = lve;
/*
* First entry is AddHead'ed.
*/
goto headIt;
};
};
ld->ld_Flags |= LDF_REFRESH_ALL;
Insert((struct List *)&ld->ld_Entries, (struct Node *)lve, (struct Node *)tmp);
break;
case LVAP_HEAD:
headIt:
ld->ld_Flags |= LDF_REFRESH_ALL;
AddHead((struct List *)&ld->ld_Entries, (struct Node *)lve);
ld->ld_TopEntry = lve;
break;
case LVAP_TAIL:
default:
tailIt:
AddTail((struct List *)&ld->ld_Entries, (struct Node *)lve);
break;
}
}
/*
* Add entries to the list.
*/
STATIC ASM BOOL AddEntries(REG(a0) LD *ld, REG(a1) APTR *entries, REG(a2) Object *obj, REG(d0) ULONG how, REG(a3) LVE *pred)
{
LVE *lve;
struct lvResource lvr;
BOOL success = TRUE;
/*
* Entries valid?
*/
if (!entries) return FALSE;
/*
* Initialize lvResource structure to make entries.
*/
lvr.lvr_Command = LVRC_MAKE;
ld->ld_Flags |= LDF_LIST_BUSY;
/*
* Loop through the entries.
*/
while ((lvr.lvr_Entry = *entries++))
{
/*
* Create a node.
*/
if ((lve = (LVE *)BGUI_AllocPoolMem(sizeof(LVE))))
{
/*
* Do we have a resource hook?
*/
if (ld->ld_Resource)
{
/*
* Let the hook make the entry.
*/
lve->lve_Entry = (APTR)BGUI_CallHookPkt(ld->ld_Resource, (void *)obj, (void *)&lvr);
}
else
{
/*
* Simple string copy.
*/
if ((lve->lve_Entry = (APTR)BGUI_AllocPoolMem(strlen((STRPTR)lvr.lvr_Entry) + 1)))
strcpy((STRPTR)lve->lve_Entry, (STRPTR)lvr.lvr_Entry);
}
/*
* All ok?
*/
if (lve->lve_Entry)
{
if (!pred)
{
AddEntryInList(ld, obj, lve, how);
if (how == LVAP_HEAD)
pred = lve;
}
else
{
Insert((struct List *)&ld->ld_Entries, (struct Node *)lve, (struct Node *)pred);
pred = lve;
};
ld->ld_LastAdded = lve;
ld->ld_Total++;
}
else
{
success = FALSE;
BGUI_FreePoolMem(lve);
}
}
}
ld->ld_Flags &= ~LDF_LIST_BUSY;
return success;
}
/*
* Make an entry visible.
*/
STATIC ASM ULONG MakeVisible(REG(a0) LD *ld, REG(d0) ULONG entry)
{
ULONG new_top;
/*
* # of visible items known?
*/
if (!ld->ld_Visible)
ld->ld_Visible = 1;
/*
* Otherwise adjust the top to
* make it visible.
*/
if (entry < ld->ld_Top) new_top = entry;
else if (entry >= (ld->ld_Top + ld->ld_Visible)) new_top = max((LONG)(entry - (ld->ld_Visible - 1)), 0);
else if (entry >= ld->ld_Total) new_top = max((LONG)ld->ld_Total - (LONG)(ld->ld_Visible - 1), 0);
else new_top = ld->ld_Top;
return new_top;
}
/*
* De-select node list (slow!).
*/
STATIC ASM VOID DeSelect(REG(a0) LD *ld)
{
LVE *lve;
for (lve = ld->ld_Entries.lvl_First; lve->lve_Next; lve = lve->lve_Next)
{
if (lve->lve_Flags & LVEF_SELECTED)
{
lve->lve_Flags &= ~LVEF_SELECTED;
lve->lve_Flags |= LVEF_REFRESH;
};
};
}
/*
* Select node list (slow!).
*/
STATIC ASM VOID Select(REG(a0) LD *ld)
{
LVE *lve;
for ( lve = ld->ld_Entries.lvl_First; lve->lve_Next; lve = lve->lve_Next ) {
if ( ! ( lve->lve_Flags & LVEF_SELECTED ))
lve->lve_Flags |= LVEF_SELECTED | LVEF_REFRESH;
}
}
/*
* Setup a new top-value.
*/
STATIC ASM VOID NewTop(REG(a0) LD *ld, REG(a1) struct GadgetInfo *gi, REG(a2) Object *obj, REG(d0) ULONG new_top)
{
struct BaseInfo *bi;
int i;
BC *bc = BASE_DATA(obj);
/*
* How much do we need to go up?
*/
int diff = new_top - ld->ld_Top;
/*
* Gadget info present?
* New position different than old one?
*/
if (gi && diff)
{
/*
* Create rastport.
*/
#ifdef DEBUG_BGUI
if ((bi = AllocBaseInfoDebug(__FILE__,__LINE__,BI_GadgetInfo, gi, BI_RastPort, NULL, TAG_DONE)))
#else
if ((bi = AllocBaseInfo(BI_GadgetInfo, gi, BI_RastPort, NULL, TAG_DONE)))
#endif
{
BOOL needs_refresh=FALSE;
/*
* Setup font.
*/
BSetFont(bi, ld->ld_Font);
/*
* Set top position.
*/
ld->ld_TopEntry = FindNodeQuick(ld, new_top);
ld->ld_Top = new_top;
if (diff <= -ld->ld_Visible)
{
/*
* More than a single view?
*/
diff = -ld->ld_Visible;
}
else if (diff >= +ld->ld_Visible)
{
/*
* More than a single view?
*/
diff = +ld->ld_Visible;
}
else
{
/*
* Scroll view 'diff' lines.
*/
ScrollRaster(bi->bi_RPort, 0, diff * ld->ld_EntryHeight,
ld->ld_ListArea.Left, ld->ld_ListArea.Top,
ld->ld_ListArea.Left + ld->ld_ListArea.Width - 1,
ld->ld_ListArea.Top + ld->ld_ListArea.Height - 1);
needs_refresh=(bi->bi_RPort->Layer->Flags & LAYERREFRESH);
};
ColumnSeparators(ld, bi, bc->bc_InnerBox.Left, bc->bc_InnerBox.Top, bc->bc_InnerBox.Height);
/*
* Re-render first 'diff' lines.
*/
if (diff < 0)
{
i = -diff;
}
else
{
i = diff;
new_top += ld->ld_Visible - diff;
};
while (i--)
{
RenderEntry(obj, ld, bi, FindNodeQuick(ld, new_top), new_top - ld->ld_Top);
new_top++;
};
/*
* Dump BaseInfo.
*/
FreeBaseInfo(bi);
if(needs_refresh)
{
BOOL update;
if(!(update=BeginUpdate(gi->gi_Layer)))
EndUpdate(gi->gi_Layer,FALSE);
DoRenderMethod( obj, gi, GREDRAW_REDRAW );
if(update)
EndUpdate(gi->gi_Layer,TRUE);
}
/*
* Needed by RenderEntry().
*/
ld->ld_Flags &= ~LDF_REFRESH_ALL;
}
}
else
{
ld->ld_TopEntry = FindNodeQuick(ld, new_top);
ld->ld_Top = new_top;
}
}
/************************************************************************
********************** MCLV_GETCOLUMNPOSITIONS() **********************
*************************************************************************
* Work out the left offset (relative to listview view area) of each
* column separator. Put the results in ld_Offsets array, starting
* with the first separator (ie. the left offset of the *second* column
* from the left). Returns TRUE or FALSE to indicate success. Currently
* this can only fail if the object is not displayed when this function
* is called. If all goes well, LDF_OFFSETS_VALID is set to TRUE.
*
*************************************************************************/
STATIC BOOL GetColumnPositions(Object *obj, LD *ld)
{
int w, dw, x;
int totalwidth, columnwidth, totalweight, lastwidth;
int listwidth = ld->ld_ListArea.Width;
CD *cd, *fcd = ld->ld_CD, *lcd = fcd + ld->ld_Columns - 1;
/*
* Start widths at minimum and compute width of all columns.
*/
columnwidth = 0;
for (cd = fcd; cd <= lcd; ++cd)
{
cd->cd_Width = cd->cd_MinWidth;
columnwidth += cd->cd_Width;
};
/*
* Cycle through until all extra space is used.
*/
while (columnwidth < listwidth)
{
lastwidth = columnwidth;
totalwidth = listwidth;
totalweight = 0;
for (cd = fcd; cd <= lcd; ++cd)
{
if (!(cd->cd_Flags & LVCF_HIDDEN))
{
if (cd->cd_Width < cd->cd_MaxWidth)
{
totalweight += cd->cd_Weight;
}
else
{
cd->cd_Width = cd->cd_MaxWidth;
totalwidth -= cd->cd_Width;
};
};
};
if (totalweight == 0) break;
for (cd = fcd; cd <= lcd; ++cd)
{
if (!(cd->cd_Flags & LVCF_HIDDEN))
{
if (cd->cd_Width < cd->cd_MaxWidth)
{
w = (cd->cd_Weight * totalwidth) / totalweight;
if (w > cd->cd_MaxWidth) w = cd->cd_MaxWidth;
if (w < cd->cd_MinWidth) w = cd->cd_MinWidth;
dw = w - cd->cd_Width;
if (dw > listwidth - columnwidth)
{
dw = listwidth - columnwidth;
cd->cd_Width += dw;
columnwidth += dw;
break;
};
cd->cd_Width += dw;
columnwidth += dw;
};
};
};
if (columnwidth == lastwidth) break;
};
x = 0;
for (cd = fcd; cd <= lcd; ++cd)
{
if (!(cd->cd_Flags & LVCF_HIDDEN))
{
cd->cd_Offset = x;
x += cd->cd_Width;
};
};
cd->cd_Offset = x; // Last "dummy" column needs right offset of list.
ld->ld_Flags |= LDF_OFFSETS_VALID|LDF_REFRESH_ALL;
return TRUE;
}
/************************************************************************
************************* MCLV_DRAWDRAGLINE() *************************
*************************************************************************
* Draw, using complement mode, the line that shows the user the position
* s/he has dragged the column separator to within the mclv.
*
*************************************************************************/
STATIC ASM VOID DrawDragLine(REG(a0) LD *ld, REG(a1) struct GadgetInfo *gi)
{
WORD x1 = ld->ld_InnerBox.Left + ld->ld_DragXLine - 2;
WORD x2 = x1 + 1;
WORD y1 = ld->ld_InnerBox.Top;
WORD y2 = ld->ld_InnerBox.Top + ld->ld_InnerBox.Height - 1;
struct BaseInfo *bi;
#ifdef DEBUG_BGUI
if ((bi = AllocBaseInfoDebug(__FILE__,__LINE__,BI_GadgetInfo, gi, BI_RastPort, NULL, TAG_DONE)))
#else
if ((bi = AllocBaseInfo(BI_GadgetInfo, gi, BI_RastPort, NULL, TAG_DONE)))
#endif
{
BSetDrMd(bi, COMPLEMENT);
BRectFill(bi, x1, y1, x2, y2);
FreeBaseInfo(bi);
};
}
/// OM_NEW
/*
* Create a new object.
*/
METHOD(ListClassNew, struct opSet *, ops)
{
LD *ld;
IPTR rc, data;
ULONG sort = LVAP_TAIL;
struct TagItem *tags, *tag;
struct TagItem *tstate;
ULONG *new_weights = NULL;
APTR *new_entries = NULL;
int i;
tags = DefTagList(BGUI_LISTVIEW_GADGET, ops->ops_AttrList);
/*
* Let the superclass make the object.
*/
if ((rc = NewSuperObject(cl, obj, tags)))
{
/*
* Get the instance data.
*/
ld = INST_DATA(cl, rc);
ld->ld_BC = BASE_DATA(rc);
ld->ld_Flags = LDF_REFRESH_ALL|LDF_PRE_CLEAR;
ld->ld_MinShown = 3;
ld->ld_Columns = 1;
ld->ld_Prop = (Object *)~0;
/*
* Initialize the list of entries.
*/
NewList((struct List *)&ld->ld_Entries);
// NewList((struct List *)&ld->ld_Hidden);
BGUI_PackStructureTags((APTR)ld, ListPackTable, tags);
tstate = tags;
while ((tag = NextTagItem(&tstate)))
{
data = tag->ti_Data;
switch (tag->ti_Tag)
{
case LISTV_EntryArray:
new_entries = (APTR *)data;
break;
case LISTV_SortEntryArray:
sort = LVAP_SORTED;
break;
case LISTV_ColumnWeights:
new_weights = (ULONG *)data;
break;
case LISTV_PropObject:
ld->ld_Prop = (Object *)data;
break;
case LISTV_ListFont:
ld->ld_ListFont = (struct TextAttr *)data;
break;
case LISTV_Title:
ld->ld_Title = (UBYTE *)data;
break;
case LISTV_TitleHook:
ld->ld_TitleHook = (struct Hook *)data;
break;
case LISTV_CompareHook:
ld->ld_Compare = (struct Hook *)data;
break;
case LISTV_DisplayHook:
ld->ld_Display = (struct Hook *)data;
break;
case LISTV_ResourceHook:
ld->ld_Resource = (struct Hook *)data;
break;
};
};
if (ld->ld_Columns < 1) ld->ld_Columns = 1;
ld->ld_CD = BGUI_AllocPoolMem((ld->ld_Columns + 1) * sizeof(CD));
/*
* Verify array allocated.
*/
if (ld->ld_CD)
{
for (i = 0; i <= ld->ld_Columns; i++)
{
ld->ld_CD[i].cd_MinWidth = 24;
ld->ld_CD[i].cd_MaxWidth = 0xFFFF;
ld->ld_CD[i].cd_Weight = new_weights ? (new_weights[i] ? new_weights[i] : 1) : DEFAULT_WEIGHT;
};
if (ld->ld_Prop == (Object *)~0)
{
/*
* Filter out frame and label attributes.
*/
tstate = tags;
while ((tag = NextTagItem(&tstate)))
{
switch (tag->ti_Tag)
{
/*
* Don't disable prop!
*/
case GA_Disabled:
/*
* No drag'n'drop on the prop.
*/
case BT_DragObject:
case BT_DropObject:
tag->ti_Tag = TAG_IGNORE;
break;
default:
if (FRM_TAG(tag->ti_Tag) || LAB_TAG(tag->ti_Tag))
tag->ti_Tag = TAG_IGNORE;
break;
};
};
/*
* Create a scroller.
*/
ld->ld_Prop = BGUI_NewObject(BGUI_PROP_GADGET, GA_ID, GADGET(rc)->GadgetID,
PGA_DontTarget, TRUE, BT_ParentView, ld->ld_BC->bc_View, BT_ParentWindow, ld->ld_BC->bc_Window,TAG_MORE, tags);
};
if (ld->ld_Prop)
{
/*