-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtscroll.cpp
1458 lines (1262 loc) · 37.7 KB
/
tscroll.cpp
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
/*
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
* ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
* PARTICULAR PURPOSE.
*
* Copyright (c) Microsoft Corporation. All Rights Reserved.
*/
/*
* tscroll.cpp
*
* standard table class.
*
* scrolling and selection routines
*
* see table.h for interface description
*
* This implementation currently only supports TM_SINGLE, not TM_MANY
* modes of selection.
*/
#include "precomp.h"
#include "table.h"
#include "tpriv.h"
VOID
gtab_extendsel(
HWND hwnd,
lpTable ptab,
long startrow,
long startcell,
BOOL bNotify
);
/* handle a vscroll message */
void
gtab_msg_vscroll(HWND hwnd, lpTable ptab, int opcode, int pos)
{
long change;
switch(opcode) {
case SB_THUMBPOSITION:
case SB_THUMBTRACK:
change = (pos * ptab->scrollscale) - ptab->toprow;
break;
case SB_LINEUP:
change = -1;
break;
case SB_LINEDOWN:
change = 1;
break;
case SB_PAGEUP:
change = - (ptab->nlines - 3);
if (change>=0)
change = -1; // consider nlines <=3!
break;
case SB_PAGEDOWN:
change = (ptab->nlines - 3);
if (change<=0)
change = 1; // consider nlines <=3!
break;
default:
return;
}
gtab_dovscroll(hwnd, ptab, change);
}
/* handle a hscroll message */
void
gtab_msg_hscroll(HWND hwnd, lpTable ptab, int opcode, int pos)
{
int change;
switch(opcode) {
case SB_THUMBPOSITION:
case SB_THUMBTRACK:
change = pos - ptab->scroll_dx;
break;
case SB_LINEUP:
change = -(ptab->avewidth);
break;
case SB_LINEDOWN:
change = ptab->avewidth;
break;
case SB_PAGEUP:
change = - (ptab->winwidth * 2 / 3);
break;
case SB_PAGEDOWN:
change = (ptab->winwidth * 2 / 3);
break;
default:
return;
}
gtab_dohscroll(hwnd, ptab, change);
}
/*
* set new vertical scroll pos,
* adjust linedata array
* set line win-relative start posns & clip top/bottom posns
* revise display.
*/
void
gtab_dovscroll(HWND hwnd, lpTable ptab, long change)
{
int cury, i;
long ncopy;
lpCellPos cp;
LineData ldtemp;
RECT rc, rcpaint;
long range;
long newtop;
int newpos;
BOOL fWasVisible = FALSE;
if (ptab->selvisible)
{
fWasVisible = TRUE;
ptab->selvisible = FALSE;
gtab_invertsel(hwnd, ptab, NULL);
}
range = ptab->hdr.nrows - (ptab->nlines - 1);
newtop = ptab->toprow + change;
if (range < 0) {
range = 0;
}
if (newtop > range) {
change = range - ptab->toprow;
} else if (newtop < 0) {
change = -(ptab->toprow);
}
ptab->toprow += change;
newpos = (int) (newtop / ptab->scrollscale);
SetScrollPos(hwnd, SB_VERT, newpos, TRUE);
if (ptab->hdr.sendscroll) {
gtab_sendtq(hwnd, TQ_SCROLL, ptab->toprow);
}
/* adjust data ptrs rather than invalidate, to retain the
* data we know is still valid
*/
if (abs(change) >= ptab->nlines) {
gtab_invallines(hwnd, ptab, ptab->hdr.fixedrows,
ptab->nlines - ptab->hdr.fixedrows);
InvalidateRect(hwnd, NULL, FALSE);
change = 0;
} else if (change < 0) {
/* copy data down */
ncopy = (ptab->nlines - ptab->hdr.fixedrows) - abs(change);
for (i = ptab->nlines - 1;
i >= (ptab->hdr.fixedrows + abs(change)); i--) {
ldtemp = ptab->pdata[i - abs(change)];
ptab->pdata[i - abs(change)] = ptab->pdata[i];
ptab->pdata[i] = ldtemp;
}
gtab_invallines(hwnd, ptab,
ptab->hdr.fixedrows, (int) abs(change));
} else if (change > 0) {
ncopy = (ptab->nlines - ptab->hdr.fixedrows) - change;
for (i = ptab->hdr.fixedrows;
i < (ncopy + ptab->hdr.fixedrows); i++) {
ldtemp = ptab->pdata[i + change];
ptab->pdata[i + change] = ptab->pdata[i];
ptab->pdata[i] = ldtemp;
}
gtab_invallines(hwnd, ptab,
(int) ncopy + ptab->hdr.fixedrows, (int) change);
}
/* scroll window */
GetClientRect(hwnd, &rc);
rcpaint = rc;
if (change > 0) {
rc.top += (int) (change + ptab->hdr.fixedrows) * ptab->rowheight;
rcpaint.top = (ptab->hdr.fixedrows * ptab->rowheight);
rcpaint.top += rc.bottom - rc.top;
} else if (change < 0) {
rc.top += (ptab->hdr.fixedrows * ptab->rowheight);
rc.bottom += (int) (change * ptab->rowheight);
rcpaint.bottom -= rc.bottom - rc.top;
}
/* loop through each line setting relative posn and clipping */
/* set up all rows - the fixed/moveable difference for
* rows is made at fetch-time during painting, when we remember
* which absolute row nr to ask for, for a given screen line
*/
cury = 0;
for (i = 0; i < ptab->nlines; i++) {
cp = &ptab->pdata[i].linepos;
cp->start = cury;
cp->clipstart = cury;
cp->clipend = cury + cp->size;
cury += cp->size;
}
/* now move and repaint the window */
if (change != 0) {
if (rc.top < rc.bottom) {
ScrollWindow(hwnd, 0, (int) -(change * ptab->rowheight),
&rc, NULL);
}
// don't repaint the fixed rows
rc.top = 0;
rc.bottom = ptab->hdr.fixedrows * ptab->rowheight;
ValidateRect(hwnd, &rc);
/* force repaint now, not just post message for later,
* since we want to repaint that line before the next
* scroll down occurs
*/
ValidateRect(hwnd, &rcpaint);
RedrawWindow(hwnd, &rcpaint, NULL,
RDW_NOERASE | RDW_INVALIDATE | RDW_INTERNALPAINT);
}
if (fWasVisible)
{
gtab_invertsel(hwnd, ptab, NULL);
ptab->selvisible = TRUE;
}
}
/*
* set new horizontal scroll pos,
* set col win-relative start posns & clip left/right posns
* revise display.
*/
void
gtab_dohscroll(HWND hwnd, lpTable ptab, long change)
{
int curx, i;
int moveable;
lpCellPos cp;
int newdx, range;
/* check that the new scroll pos is still within the valid range */
range = ptab->rowwidth - ptab->winwidth;
newdx = ptab->scroll_dx + (int) change;
if (range < 0) {
range = 0;
}
if (newdx > range) {
change = range - ptab->scroll_dx;
} else if (newdx < 0) {
change = -(ptab->scroll_dx);
}
ptab->scroll_dx += (int) change;
SetScrollPos(hwnd, SB_HORZ, ptab->scroll_dx, TRUE);
if (ptab->hdr.fixedcols > 0) {
RECT rc;
GetClientRect(hwnd, &rc);
rc.left = ptab->pcellpos[ptab->hdr.fixedcols - 1].clipend;
InvalidateRect(hwnd, &rc, FALSE);
} else {
InvalidateRect(hwnd, NULL, FALSE);
}
/* loop through each col setting relative posn and clipping */
/* clip off 1 pixel left and right (we added 2 on to size for this) */
/* first set up fixed columns */
curx = 0;
for (i = 0; i < ptab->hdr.fixedcols; i++) {
cp = &ptab->pcellpos[i];
cp->start = curx + 1;
cp->clipstart = cp->start;
cp->clipend = cp->start + cp->size - 2;
curx += cp->size;
}
/* now moveable columns. remember start of moveable cols */
moveable = curx;
curx = - ptab->scroll_dx; /* rel. pos of col */
for (i = ptab->hdr.fixedcols; i < ptab->hdr.ncols; i++) {
cp = &ptab->pcellpos[i];
cp->start = curx + moveable + 1;
cp->clipstart = max(moveable+1, cp->start);
cp->clipend = cp->start + cp->size - 2;
curx += cp->size;
}
}
/*
* convert screen line nr to table row nr
*/
long
gtab_linetorow(HWND hwnd, lpTable ptab, int line)
{
if (line < ptab->hdr.fixedrows) {
return(line);
}
return (line + ptab->toprow);
}
/*
* convert table row nr to screen line nr or -1 if not on screen
*/
int
gtab_rowtoline(HWND hwnd, lpTable ptab, long row)
{
if (row < ptab->hdr.fixedrows) {
return( (int) row);
}
row -= ptab->toprow;
if ((row >= ptab->hdr.fixedrows) && (row < ptab->nlines)) {
return ( (int) row);
}
return(-1);
}
/*
* check if a given location is within the current selection.
* Returns true if it is inside the current selection, or false if
* either there is no selection, or the row, cell passed is outside it.
*/
BOOL
gtab_insideselection(
lpTable ptab,
long row,
long cell)
{
long startrow, endrow;
long startcell, endcell;
if (0 == ptab->select.nrows) {
// no selection
return FALSE;
}
// selection maintains anchor point as startrow,
// so the selection can extend forwards or backwards from there.
// need to convert to forward only for comparison
startrow = ptab->select.startrow;
if (ptab->select.nrows < 0) {
endrow = startrow;
startrow += ptab->select.nrows + 1;
} else {
endrow = startrow + ptab->select.nrows - 1;
}
if ((row < startrow) || (row > endrow)) {
return FALSE;
}
// if we are in row-select mode, then that's it - its inside
if (ptab->hdr.selectmode & TM_ROW) {
return TRUE;
}
// same calculation for cells
startcell = ptab->select.startcell;
if (ptab->select.ncells < 0) {
endcell = startcell;
startcell += ptab->select.ncells + 1;
} else {
endcell = startcell + ptab->select.ncells - 1;
}
if ((cell < startcell) || (cell > endcell)) {
return FALSE;
}
return TRUE;
}
/*
* replace old selection with new. Notify owner if bNotify. Change
* display to reflect new display.
*/
void
gtab_select(
HWND hwnd,
lpTable ptab,
long row,
long col,
long nrows,
long ncells,
BOOL bNotify)
{
/* if in ROW mode, force col and ncells to reflect the entire row. */
if (ptab->hdr.selectmode & TM_ROW) {
col = 0;
ncells = ptab->hdr.ncols;
}
/* clear existing sel if valid and visible */
if ((ptab->select.nrows != 0) && (ptab->selvisible == TRUE)) {
/* only clear sel if it is different from the new one */
if ((ptab->select.startrow != row) ||
(ptab->select.startcell != col) ||
(ptab->select.nrows != nrows) ||
(ptab->select.ncells != ncells)) {
gtab_invertsel(hwnd, ptab, NULL);
ptab->selvisible = FALSE;
}
}
/* set select fields and send TQ_SELECT */
if (row < ptab->hdr.nrows) {
ptab->select.startrow = row;
ptab->select.startcell = col;
ptab->select.nrows = nrows;
ptab->select.ncells = ncells;
} else {
ptab->select.nrows = 0;
ptab->select.startrow = 0;
ptab->select.startcell = 0;
ptab->select.ncells = 0;
}
if (bNotify) {
gtab_sendtq(hwnd, TQ_SELECT, (LPARAM) &ptab->select);
}
/* paint in selection */
if (nrows != 0) {
if (!ptab->selvisible) {
gtab_invertsel(hwnd, ptab, NULL);
ptab->selvisible = TRUE;
}
} else {
if (ptab->selvisible) {
gtab_invertsel(hwnd, ptab, NULL);
ptab->selvisible = FALSE;
}
ptab->selvisible = FALSE;
}
}
/*
* convert window y co-ord to a line nr
*/
int
gtab_ytoline(HWND hwnd, lpTable ptab, int y)
{
return(y / ptab->rowheight);
}
/*
* convert window x co-ord to a cell nr
*/
int
gtab_xtocol(HWND hwnd, lpTable ptab, int x)
{
int i;
lpCellPos ppos;
for (i = 0; i < ptab->hdr.ncols; i++) {
ppos = &ptab->pcellpos[i];
if (ppos->clipstart < ppos->clipend) {
if ( (x >= ppos->clipstart) && (x < ppos->clipend)) {
return(i);
}
}
}
return(-1);
}
/*
* check if x co-ord is 'near' (+- 2 pixels) the right border of given cell
*/
BOOL
gtab_isborder(HWND hwnd, lpTable ptab, long x, long col)
{
if (abs(ptab->pcellpos[col].clipend - x) < 2) {
return(TRUE);
} else {
return(FALSE);
}
}
/*
* set selection and send 'TQ_ENTER' event to owner
*/
void
gtab_enter(HWND hwnd, lpTable ptab, long row, long col, long nrows,
long ncells)
{
/* clear existing sel if valid and visible */
if ((ptab->select.nrows != 0) && (ptab->selvisible == TRUE)) {
/* only clear sel if it is different from the new one */
if ((ptab->select.startrow != row) ||
(ptab->select.startcell != col) ||
(ptab->select.nrows != nrows) ||
(ptab->select.ncells != ncells)) {
gtab_invertsel(hwnd, ptab, NULL);
ptab->selvisible = FALSE;
}
}
/* set select fields and send TQ_ENTER */
if (row < ptab->hdr.nrows) {
ptab->select.startrow = row;
ptab->select.startcell = col;
ptab->select.nrows = nrows;
ptab->select.ncells = ncells;
} else {
ptab->select.nrows = 0;
ptab->select.startrow = 0;
ptab->select.startcell = 0;
ptab->select.ncells = 0;
}
/* paint in selection */
if (nrows != 0) {
if (!ptab->selvisible) {
gtab_invertsel(hwnd, ptab, NULL);
ptab->selvisible = TRUE;
}
/* do this at end because it could cause a layout-change */
gtab_sendtq(hwnd, TQ_ENTER, (LPARAM) &ptab->select);
} else {
if (ptab->selvisible) {
gtab_invertsel(hwnd, ptab, NULL);
}
ptab->selvisible = FALSE;
}
}
/*
* start re-sizing a column
*/
void
gtab_trackcol(HWND hwnd, lpTable ptab, long col, long x)
{
/* ensure we see the mouse-up */
SetCapture(hwnd);
ptab->trackmode = TRACK_COLUMN;
#ifdef WIN32
ptab->tracknr = col;
ptab->trackline1 = x;
#else
// maximum 32767 columns is a reasonable limit!
ptab->tracknr = (int) (col & 0x7fff);
ptab->trackline1 = (int) (x & 0x7fff);
#endif
/* if line at other side of cell is visible, draw that too */
if (ptab->pcellpos[col].start >= ptab->pcellpos[col].clipstart) {
ptab->trackline2 = ptab->pcellpos[col].start;
} else {
ptab->trackline2 = -1;
}
gtab_drawvertline(hwnd, ptab);
}
/*
* called on right-click events. Select the cell clicked on, and if
* valid, send on to owner for any context-menu type operation
*/
void
gtab_rightclick(HWND hwnd, lpTable ptab, int x, int y)
{
long cell, ncells;
long row;
HWND hOwner;
/* find which col, row he selected */
cell = gtab_xtocol(hwnd, ptab, x);
if (cell == -1) {
return;
}
row = gtab_linetorow(hwnd, ptab, gtab_ytoline(hwnd, ptab, y));
/* is he selecting a disabled fixed area ? */
if ( (row < ptab->hdr.fixedrows) || (cell < ptab->hdr.fixedcols)) {
if (ptab->hdr.fixedselectable == FALSE) {
return;
}
}
// ignore if beyond data
if ((row >= ptab->hdr.nrows) ||
(cell >= ptab->hdr.ncols)) {
return;
}
/* is this within the already-selected area? */
if (!gtab_insideselection(ptab, row, cell)) {
// no selection, or clicked outside the selection - make new selection
// before sending the right-click
// if shift is down, extend selection
if (GetKeyState(VK_SHIFT) & 0x8000) {
gtab_extendsel(hwnd, ptab, row, cell, TRUE);
} else {
/* record and paint new selection */
if (ptab->hdr.selectmode & TM_ROW) {
cell = 0;
ncells = ptab->hdr.ncols;
} else {
ncells = 1;
}
gtab_select(hwnd, ptab, row, cell, 1, ncells, TRUE);
}
}
// now we have sent the selection, pass the message onto him
hOwner = (HWND) GetWindowLongPtr(hwnd, WW_OWNER);
SendMessage(hOwner, WM_RBUTTONDOWN, 0, MAKELONG( (short)x, (short)y));
}
/*
* called on mouse-down events. decide what to start tracking.
*/
void
gtab_press(HWND hwnd, lpTable ptab, int x, int y)
{
long cell, ncells;
long row;
if (ptab->trackmode != TRACK_NONE) {
return;
}
/* has he grabbed a cell-edge to resize ? */
cell = gtab_xtocol(hwnd, ptab, x);
if (cell == -1) {
return;
}
if (gtab_isborder(hwnd, ptab, x, cell)) {
gtab_trackcol(hwnd, ptab, cell, x);
return;
}
if ( (cell > 0) && gtab_isborder(hwnd, ptab, x, cell-1)) {
gtab_trackcol(hwnd, ptab, cell, x);
return;
}
/* find which line he selected */
row = gtab_linetorow(hwnd, ptab, gtab_ytoline(hwnd, ptab, y));
/* is he selecting a disabled fixed area ? */
if ( (row < ptab->hdr.fixedrows) || (cell < ptab->hdr.fixedcols)) {
if (ptab->hdr.fixedselectable == FALSE) {
return;
}
}
// ignore if beyond data
if ((row >= ptab->hdr.nrows) ||
(cell >= ptab->hdr.ncols)) {
return;
}
/* ok, start cell selection */
ptab->trackmode = TRACK_CELL;
SetCapture(hwnd);
/* record and paint new selection */
if (ptab->hdr.selectmode & TM_ROW) {
cell = 0;
ncells = ptab->hdr.ncols;
} else {
ncells = 1;
}
/*
* if the shift key is down, then extend the selection to this
* new anchor point, rather than create a new selection
*/
if (GetKeyState(VK_SHIFT) & 0x8000) {
gtab_extendsel(hwnd, ptab, row, cell, FALSE);
} else {
gtab_select(hwnd, ptab, row, cell, 1, ncells, FALSE);
}
return;
}
/*
* called on mouse-up. complete any tracking that was happening
*/
void
gtab_release(HWND hwnd, lpTable ptab, int x, int y)
{
lpCellPos ppos;
lpProps pprop;
long row, cell;
int cx;
switch(ptab->trackmode) {
case TRACK_NONE:
return;
case TRACK_COLUMN:
/* erase marker lines */
gtab_drawvertline(hwnd, ptab);
ReleaseCapture();
ptab->trackmode = TRACK_NONE;
/* adjust cell width */
ppos = &ptab->pcellpos[ptab->tracknr];
cx = ptab->trackline1 - ppos->start;
pprop = &ptab->pcolhdr[ptab->tracknr].props;
pprop->valid |= P_WIDTH;
pprop->width = cx;
gtab_calcwidths(hwnd, ptab);
gtab_setsize(hwnd, ptab);
InvalidateRect(hwnd, NULL, FALSE);
return;
case TRACK_CELL:
row = gtab_linetorow(hwnd, ptab, gtab_ytoline(hwnd, ptab, y));
cell = gtab_xtocol(hwnd, ptab, x);
ReleaseCapture();
ptab->trackmode = TRACK_NONE;
// ignore if before or beyond data
if ( (row < ptab->hdr.fixedrows) ||
(cell < ptab->hdr.fixedcols)) {
if (ptab->hdr.fixedselectable == FALSE) {
gtab_select(
hwnd,
ptab,
ptab->select.startrow,
ptab->select.startcell,
ptab->select.nrows,
ptab->select.ncells,
TRUE);
return;
}
}
if ((row >= ptab->hdr.nrows) ||
(cell >= ptab->hdr.ncols)) {
gtab_select(
hwnd,
ptab,
ptab->select.startrow,
ptab->select.startcell,
ptab->select.nrows,
ptab->select.ncells,
TRUE);
return;
}
/*
* Extend to this new selection end point
* we used to only do this if shift key pressed, but that
* is not a good UI.
*/
gtab_extendsel(hwnd, ptab, row, cell, TRUE);
return;
}
}
/* called on mouse-move. if tracking - adjust position, if not,
* set correct cursor
*/
void
gtab_move(HWND hwnd, lpTable ptab, int x, int y)
{
BOOL fOK;
int line;
long row;
int col;
lpCellPos ppos;
switch(ptab->trackmode) {
case TRACK_NONE:
col = gtab_xtocol(hwnd, ptab, x);
if (col == -1) {
SetCursor((HCURSOR)hNormCurs);
return;
}
if (gtab_isborder(hwnd, ptab, x, col)) {
SetCursor((HCURSOR)hVertCurs);
return;
}
if ( (col > 0) && gtab_isborder(hwnd, ptab, x, col-1)) {
SetCursor((HCURSOR)hVertCurs);
return;
}
SetCursor((HCURSOR)hNormCurs);
return;
case TRACK_CELL:
line = gtab_ytoline(hwnd, ptab, y);
// we used to only allow drag to extend
// the selection if the shift key was down.
// this doesn't seem to work as a UI - you expect
// to drag and extend.
/* if extending selection then
* allow scrolling by dragging off window
*/
if (line < 0) {
gtab_dovscroll(hwnd, ptab, -1);
line = gtab_ytoline(hwnd, ptab, y);
} else if (line >= ptab->nlines) {
gtab_dovscroll(hwnd, ptab, 1);
line = gtab_ytoline(hwnd, ptab, y);
}
row = gtab_linetorow(hwnd, ptab, line);
col = gtab_xtocol(hwnd, ptab, x);
// ignore if before or beyond data
if ( (row < ptab->hdr.fixedrows) || (col < ptab->hdr.fixedcols)) {
if (ptab->hdr.fixedselectable == FALSE) {
return;
}
}
if ((row >= ptab->hdr.nrows) ||
(col >= ptab->hdr.ncols)) {
return;
}
/*
* extend to this new selection end point
*/
gtab_extendsel(hwnd, ptab, row, col, FALSE);
return;
case TRACK_COLUMN:
/* check that new x is still visible/valid */
ppos = &ptab->pcellpos[ptab->tracknr];
fOK = FALSE;
if (ptab->tracknr < ptab->hdr.fixedcols) {
if ((x > ppos->start) && (x < ptab->winwidth)) {
fOK = TRUE;
}
} else {
if ((x > ppos->clipstart) && (x < ptab->winwidth)) {
fOK = TRUE;
}
}
if (fOK == TRUE) {
gtab_drawvertline(hwnd, ptab);
ptab->trackline1 = x;
gtab_drawvertline(hwnd, ptab);
}
return;
}
}
/* dbl-click - send an TQ_ENTER event to the owner (if valid) */
void
gtab_dblclick(HWND hwnd, lpTable ptab, int x, int y)
{
int cell, line;
long row;
line = gtab_ytoline(hwnd, ptab, y);
cell = gtab_xtocol(hwnd, ptab, x);
if ( (line < ptab->hdr.fixedrows) || (cell < ptab->hdr.fixedcols) ) {
if (!ptab->hdr.fixedselectable) {
return;
}
}
row = gtab_linetorow(hwnd, ptab, line);
if (ptab->hdr.selectmode & TM_ROW) {
gtab_enter(hwnd, ptab, row, 0, 1, ptab->hdr.ncols);
} else {
gtab_enter(hwnd, ptab, row, cell, 1, 1);
}
}
/*
* move selection area to visible part of window. argument bToBottom
* indicates whether to move the line onto the bottom or the top of the
* window if not visible - this affects the smoothness of scrolling
* line-by-line.
*/
void
gtab_showsel(HWND hwnd, lpTable ptab, BOOL bToBottom)
{
int line;
long change;
line = gtab_rowtoline(hwnd, ptab, ptab->select.startrow);
/* move up if last line or not at all visible */
if ( (line < 0) || line == (ptab->nlines - 1)) {
change = ptab->select.startrow - ptab->toprow;
if (bToBottom) {
/* change to bottom of window. subtract 2 not 1
* since nlines includes one line that is only
* partly visible
*/
change -= (ptab->nlines - 2);
}
change -= ptab->hdr.fixedrows;
gtab_dovscroll(hwnd, ptab, change);
}
/* add support for TM_CELL here! */
}
/*
* scroll the window so that if possible, the selected row is in the
* middle 60% of the screen so that context around it is visible.
*/
void
gtab_showsel_middle(HWND hwnd, lpTable ptab, long dyRowsFromTop)
{
int line = ptab->select.startrow;
long change = 0;
int mid_top, mid_end;
BOOL fScroll = FALSE;
if (dyRowsFromTop >= 0)
{
fScroll = TRUE;
change = (ptab->select.startrow - dyRowsFromTop) - ptab->toprow;
change -= ptab->hdr.fixedrows;
}
/* is this within the middle 60 % ? */
mid_top = ptab->toprow + (ptab->nlines * 20 / 100);
mid_end = ptab->toprow + (ptab->nlines * 80 / 100);
if ((line < mid_top + change) || (line > mid_end + change))
{
/* no - scroll so that selected line is at
* the 20% mark
*/
fScroll = TRUE;
change = (ptab->select.startrow - mid_top);
change -= ptab->hdr.fixedrows;
}
if (fScroll)
{
gtab_dovscroll(hwnd, ptab, change);
}
/* again - need code here for TM_CELL mode to ensure that
* active cell is horizontally scrolled correctly
*/
}
/*
* extend the selection to set the new anchor point as startrow, startcell.
*
* nrows and ncells will then be set to include the end row of the previous
* selection. nrows, ncells < 0 indicate left and up. -1 and +1 both indicate
* just one cell or row selected.
*/
VOID
gtab_extendsel(
HWND hwnd,
lpTable ptab,
long startrow,
long startcell,
BOOL bNotify
)
{