-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathview.cpp
1800 lines (1495 loc) · 53.9 KB
/
view.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.
*/
/*
* view.cpp
*
* map rows in window to items in COMPLIST
*
*
* A view owns a COMPLIST, and talks to a table window. The table window
* shows 3 columns: line nr, tag and text. We also need to supply a state
* for each row (used to select colour scheme).
*
* The COMPLIST can give us a list of its COMPITEMs. Each of these can give
* us a tag (eg the filenames compared) and the text (usually the compare
* result), and the state. We make the line number from the
* COMPITEM's place in the list.
*
* If we are asked to switch to 'expand' mode, we ask the selected COMPITEM
* for its composite section list. We can then get the state (and thus
* the tag) from each SECTION, and the line nr and text from the LINEs within
* each section.
*
* When moving between expand and outline, and when refreshing the view
* for some option change, we have to be careful to keep the current row
* and the selected row in the table what the user would expect (!)
*
*
* WIN32: Functions in this module can be called from the UI thread (to refresh
* the display) and simultaneously from a worker thread to update the
* view mapping (view_setcomplist, view_newitem). We use a critical section
* to manage the synchronisation. We need to protect all access/modification
* to the view structure elements (particularly bExpand, rows, pLines and
* pItems), BUT we must not hold the critical section over any calls
* to SendMessage.
*
*/
#include "precomp.h"
#include "table.h"
#include "state.h"
#include "sdkdiff.h"
#include "wdiffrc.h"
#include "list.h"
#include "line.h"
#include "scandir.h"
#include "file.h"
#include "section.h"
#include "compitem.h"
#include "complist.h"
#include "findgoto.h"
#include "view.h"
/*
* data structures
*/
#ifdef WIN32
#define huge
#endif
/* in expand mode, we keep an array of one of these per screen line. */
typedef struct viewline {
LINE line; /* handle to LINE for this row */
SECTION section; /* handle to section containing this line */
int nr_left; /* line nr in left file */
int nr_right; /* line nr in right file */
} VIEWLINE, FAR * PVIEWLINE;
/*
* The users VIEW handle is in fact a pointer to this structure
*/
struct view {
HWND hwnd; /* the table window to send notifies to */
COMPLIST cl; /* the complist that we own */
BOOL bExpand; /* true if we are in expand mode */
BOOL bExpanding; /* set by view_expandstart, reset by view_expand
interrogated in sdkdiff.cpp, causes keystrokes
to be ignored. Protects against mappings being
messed up by another thread.
(I have doubts about this - Laurie).
*/
BOOL bExpandGuard; /* Protects against two threads both trying to
expand the same item.
*/
COMPITEM ciSelect; /* selected compitem (in expand mode) */
int rows; /* number of rows in this view */
char nrtext[12]; /* we use this in view_gettext for the line
* number column. overwritten on each call
*/
int maxtag, maxrest;/* column widths in characters for cols 1, 2 */
/* if we are in outline mode, we map the row number to one entry
* in this array of COMPITEM handles. this pointer will
* be NULL in expand mode
*/
COMPITEM FAR * pItems;
/* in expand mode we use this array of line and section handles */
PVIEWLINE pLines;
};
#ifdef WIN32
CRITICAL_SECTION CSView; /* also known to Sdkdiff.cpp WM_EXIT processing */
static BOOL bDoneInit = FALSE;
#define ViewEnter() EnterCriticalSection(&CSView);
#define ViewLeave() LeaveCriticalSection(&CSView);
#else //WIN32
#define ViewEnter()
#define ViewLeave()
#endif //WIN32
extern long selection;
extern long selection_nrows;
/*------- forward declaration of internal functions ----------------*/
void view_outline_opt(VIEW view, BOOL bRedraw, COMPITEM ci, int* prow);
void view_freemappings(VIEW view);
int view_findrow(VIEW view, int number, BOOL bRight);
BOOL view_expand_item(VIEW view, COMPITEM ci);
/* ----- externally-called functions---------------------------*/
/* view_new
*
* create a new view. at this point, we are told the table window handle,
* and nothing else.
*
*/
VIEW
view_new(HWND hwndTable)
{
VIEW view;
#ifdef WIN32
if (!bDoneInit) {
InitializeCriticalSection(&CSView);
bDoneInit = TRUE;
}
#endif
/* alloc the view using HeapAlloc */
view = (VIEW) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct view));
if (view == NULL)
return NULL;
/* set the default fields */
view->hwnd = hwndTable;
view->cl = NULL;
view->bExpand = FALSE;
view->bExpandGuard = FALSE;
view->ciSelect = NULL;
view->rows = 0;
view->pItems = NULL;
view->pLines = NULL;
// erase the message in the names field - the central box in the status bar
SetNames("");
return(view);
}
/*
* view_setcomplist.
*
* We have to separate view_new and view_setcomplist because we need
* to give the view handle to the complist and the complist handle to the
* view. So do a view_new to create a null view; then complist_new() to
* which you pass a view handle. The complist will then register itself
* with the view by calling this function. During the build of the complist,
* it will also update us by calling view_additem, so that we can refresh
* the display.
*
* Here we should initialise an outline view of the complist.
*
* We also talk to the status bar using SetNames to set the names of
* the two items.
*/
BOOL
view_setcomplist(VIEW view, COMPLIST cl)
{
LPSTR both;
if (view == NULL) {
return(FALSE);
}
/* there can be only one call to this per VIEW */
if (view->cl != NULL) {
return (FALSE);
}
ViewEnter();
view->cl = cl;
/* set names on status bar to root names of left and right trees */
both = complist_getdescription(cl);
ViewLeave(); // LKGHACK
SetNames(both);
ViewEnter(); // LKGHACK
complist_freedescription(cl, both);
ViewLeave();
view_outline(view);
return TRUE;
}
/*
* return a handle to the complist owned by this view
*/
COMPLIST
view_getcomplist(VIEW view)
{
if (view == NULL) {
return(NULL);
}
return(view->cl);
}
/*
* close a view. notify the table window that this view should be
* closed. When the table window has finished with it, it will send
* a TQ_CLOSE notify that should result in view_delete being called
* and the memory being freed.
*/
void
view_close(VIEW view)
{
if (view == NULL) {
return;
}
SendMessage(view->hwnd, TM_NEWID, 0, 0);
}
/*
* delete a view and all associated data.
*
* This function should only be called in response to the table window
* sending a TQ_CLOSE message. To close the view, call view_close and
* wait for the TQ_CLOSE before calling this.
*
* We delete the associated COMPLIST and all its associated structures.
*/
void
view_delete(VIEW view)
{
if (view == NULL) {
return;
}
/* we have two arrays that are used for the mapping - an array
* of compitem handles in outline mode, and an array of
* VIEWLINE structures in expand mode
*/
view_freemappings(view);
complist_delete(view->cl);
HeapFree(GetProcessHeap(), NULL, view);
}
/*
* view_outline
*
* build an outline mode mapping where one row represents one COMPITEM in
* the list. check the global option flag outline_include to see which items
* we should include.
*
* If we were in expand mode, then set as the selection the row in outline mode
* that we were expanding. Also remember to free up the expand mode mapping
* array
*
* once we have built the new mapping, notify the table window to
* redraw itself.
*/
void
view_outline(VIEW view)
{
if (view == NULL) {
return;
}
/* all work done by view_outline_opt - this function
* gives us the option of not updating the display
*/
view_outline_opt(view, TRUE, NULL, NULL);
}
/*
* switch to expand mode, expanding the given row into a view
* of the differences in that file.
*
* map the given row nr into a compitem handle, and then
* call the internal function with that.
*
* It is legal (and a no-op) if this function is called with
* row==-1.
*/
BOOL
view_expand(VIEW view, long row)
{
COMPITEM ci;
BOOL bRet;
if (row<0) return FALSE;
ViewEnter();
if ((view == NULL) || (view->bExpand)) {
/* no view, or already expanded */
ViewLeave();
return(FALSE);
}
if (row >= view->rows) {
/* no such row */
ViewLeave();
return FALSE;
}
/* remember the compitem we are expanding */
ci = view->pItems[row];
bRet = view_expand_item(view, ci);
return(bRet);
}
/*
* return the text associated with a given column of a given row.
* Return a pointer that does not need to be freed after use - ie
* a pointer into our data somewhere, not a copy
*/
LPSTR
view_gettext(VIEW view, long row, int col)
{
int line;
int state;
LPSTR pstr;
HRESULT hr;
pstr = NULL; /* kill spurious diagnostic */
if (view == NULL) {
return (NULL);
}
ViewEnter();
if (row >= view->rows) {
ViewLeave();
return(NULL);
}
if (view->bExpand) {
/* we are in expand mode */
state = section_getstate(view->pLines[row].section);
switch(col) {
case 0:
/* row nr */
/* line numbers can be from either original file
* this is a menu-selectable option
*/
line = 0;
switch(line_numbers) {
case IDM_NONRS:
pstr = NULL;
break;
case IDM_LNRS:
line = view->pLines[row].nr_left;
if (state == STATE_MOVEDRIGHT
|| state == STATE_SIMILARRIGHT) {
line = -line;
}
break;
case IDM_RNRS:
line = view->pLines[row].nr_right;
if (state == STATE_MOVEDLEFT
|| state == STATE_SIMILARLEFT) {
line = -line;
}
break;
}
if (line == 0) {
ViewLeave();
return(NULL);
}
if (line < 0) {
/* lines that are moved appear twice.
* show the correct-sequence line nr
* for the out-of-seq. copy in brackets.
*/
hr = StringCchPrintf(view->nrtext, 12, "(%d)", abs(line));
if (FAILED(hr)) {
OutputError(hr, IDS_SAFE_PRINTF);
return(NULL);
}
} else {
hr = StringCchPrintf(view->nrtext, 12, "%d", line);
if (FAILED(hr)) {
OutputError(hr, IDS_SAFE_PRINTF);
return(NULL);
}
}
pstr = view->nrtext;
break;
case 1:
/* tag text - represents the state of the line */
switch(state) {
case STATE_SAME:
pstr = " ";
break;
case STATE_LEFTONLY:
case STATE_SIMILARLEFT:
pstr = " <! ";
break;
case STATE_RIGHTONLY:
case STATE_SIMILARRIGHT:
pstr = " !> ";
break;
case STATE_MOVEDLEFT:
pstr = " <- ";
break;
case STATE_MOVEDRIGHT:
pstr = " -> ";
break;
}
break;
case 2:
/* main text - line */
pstr = line_gettext(view->pLines[row].line);
break;
}
} else {
/* outline mode */
switch(col) {
case 0:
/* row number - just the line number */
hr = StringCchPrintf(view->nrtext, 12, "%d", row+1);
if (FAILED(hr)) {
OutputError(hr, IDS_SAFE_PRINTF);
return(NULL);
}
pstr = view->nrtext;
break;
case 1:
/* tag */
pstr = compitem_gettext_tag(view->pItems[row]);
break;
case 2:
/* result text */
pstr = compitem_gettext_result(view->pItems[row]);
break;
}
}
ViewLeave();
return(pstr);
}
/*
* return the text associated with a given column of a given row.
* Return a pointer that does not need to be freed after use - ie
* a pointer into our data somewhere, not a copy
*/
LPWSTR
view_gettextW(VIEW view, long row, int col)
{
int state;
LPWSTR pwz;
pwz = NULL; /* kill spurious diagnostic */
if (view == NULL) {
return (NULL);
}
ViewEnter();
if (row >= view->rows) {
ViewLeave();
return(NULL);
}
if (view->bExpand) {
/* we are in expand mode */
state = section_getstate(view->pLines[row].section);
switch(col) {
case 2:
/* main text - line */
pwz = line_gettextW(view->pLines[row].line);
break;
}
}
ViewLeave();
return(pwz);
}
/*
* return the line number that this row had in the original left
* file. 0 if not in expand mode. 0 if this row was not in the left file.
* -(linenr) if this row is a MOVED line, and this is the right file
* copy
*/
int
view_getlinenr_left(VIEW view, long row)
{
int state, line;
if ((view == NULL) || (row >= view->rows) || !view->bExpand) {
return 0;
}
ViewEnter();
state = section_getstate(view->pLines[row].section);
line = view->pLines[row].nr_left;
if (state == STATE_MOVEDRIGHT || state == STATE_SIMILARRIGHT) {
line = -line;
}
ViewLeave();
return(line);
}
/*
* return the line number that this row had in the original right
* file. 0 if not in expand mode. 0 if this row was not in the right file.
* -(linenr) if this row is a MOVED line, and this is the left file
* copy
*/
int
view_getlinenr_right(VIEW view, long row)
{
int state, line;
if ((view == NULL) || (row > view->rows) || !view->bExpand) {
return 0;
}
ViewEnter();
state = section_getstate(view->pLines[row].section);
line = view->pLines[row].nr_right;
if (state == STATE_MOVEDLEFT || state == STATE_SIMILARLEFT) {
line = -line;
}
ViewLeave();
return(line);
}
/* find the maximum width in characters for the given column */
int
view_getwidth(VIEW view, int col)
{
if (view == NULL) {
return(0);
}
switch(col) {
case 0:
/* line nr column - always 5 characters wide */
return(5);
case 1:
/* this is a proportional font field, so add on a margin
* for error
*/
return(view->maxtag + (view->maxtag / 20));
case 2:
/* this now includes the tab expansion allowance */
return(view->maxrest);
default:
return(0);
}
}
/* how many rows are there in this view ? */
long
view_getrowcount(VIEW view)
{
if (view == NULL) {
return(0);
}
return(view->rows);
}
/* return the state for the current row. This is used
* to select the text colour for the row
*
* states for sections are obtained from section_getstate (and apply, and
* to all lines in that section. States for compitems are obtained
* from compitem_getstate.
*/
int
view_getstate(VIEW view, long row)
{
int state;
if (view == NULL) {
return(0);
}
ViewEnter();
if (row >= view->rows) {
state = 0;
} else if (view->bExpand) {
/* its a line state that's needed */
state = section_getstate(view->pLines[row].section);
} else {
/* its a compitem state */
state = compitem_getstate(view->pItems[row]);
}
ViewLeave();
return(state);
}
/*
* return the marked state for a given row. Only compitems can be marked,
* so it will be FALSE unless it is a compitem on which view_setmark or
* compitem_setmark have previously set the mark state to TRUE.
*/
BOOL
view_getmarkstate(VIEW view, long row)
{
BOOL bMark = FALSE;
if (view != NULL) {
ViewEnter();
if ( (row < view->rows) && (!view->bExpand)) {
bMark = compitem_getmark(view->pItems[row]);
}
ViewLeave();
}
return(bMark);
}
/*
* set the mark state for a given row. This is only possible for compitem rows.
* The mark set can be retrieved by view_getmarkstate or compitem_getmark.
*
* We return FALSE if the state could not be set - eg because the
* row to set is not a compitem row.
*/
BOOL
view_setmarkstate(VIEW view, long row, BOOL bMark)
{
BOOL bOK = FALSE;
if (view != NULL) {
ViewEnter();
if ( (row < view->rows) && !view->bExpand) {
compitem_setmark(view->pItems[row], bMark);
bOK = TRUE;
}
ViewLeave();
}
return (bOK);
}
/* return a handle to the current compitem. in expand mode,
* returns the handle to the compitem we are expanding. In outline
* mode, returns the handle to the compitem for the given row, if valid,
* or NULL otherwise. row is only used if not in expand mode.
*/
COMPITEM
view_getitem(VIEW view, long row)
{
COMPITEM ci;
if (view == NULL) {
return(NULL);
}
ViewEnter();
if (!view->bExpand) {
if ((row >= 0) && (row < view->rows)) {
ci = view->pItems[row];
} else {
ci = NULL;
}
} else {
ci = view->ciSelect;
}
ViewLeave();
return(ci);
}
/*
* return TRUE if the current mapping is expanded mode
*/
BOOL
view_isexpanded(VIEW view)
{
if (view == NULL) {
return(FALSE);
}
return(view->bExpand);
}
/*
* return a text string describing the view. This is NULL in outline mode,
* or the tag text for the current compitem in expanded mode
*/
LPSTR
view_getcurrenttag(VIEW view)
{
LPSTR str;
if ((view == NULL) || (!view->bExpand)) {
return(NULL);
} else {
ViewEnter();
str = compitem_gettext_tag(view->ciSelect);
ViewLeave();
return(str);
}
}
/* notify that CompItems have been added to the complist.
*
* rebuild the view (if in outline mode), and refresh the table. Use
* the table message TM_APPEND if possible (if column widths have not
* change). If we have to do TM_NEWLAYOUT, then ensure we scroll
* back to the right row afterwards.
*
* This causes a Poll() to take place. We return TRUE if an abort is
* pending - in this case, the caller should abandon the scan loop.
*
* WIN32: enter the critical section for this function since this can be
* called from the worker thread while the UI thread is using the
* view that we are about to change.
*
* We cannot ever call SendMessage from the
* worker thread within CSView. If there is conflict, it will hang.
*
*/
BOOL
view_newitem(VIEW view)
{
int maxtag, maxrest;
int rownr;
TableSelection Select;
BOOL bSelect;
COMPITEM ciTop = NULL;
BOOL bRedraw = FALSE;
BOOL bAppend = FALSE;
// get the top row before remapping in case we need it
/* find the row at the top of the window */
rownr = (long) SendMessage(view->hwnd, TM_TOPROW, FALSE, 0);
// also remember the selection
bSelect = (BOOL) SendMessage(view->hwnd, TM_GETSELECTION, 0, (LPARAM) &Select);
// *important*:no critsec over SendMessage
ViewEnter();
if ((view != NULL) &&
!(view->bExpand) &&
!(view->bExpanding)) {
/* save some state about the present mapping */
maxtag = view->maxtag;
maxrest = view->maxrest;
// remember the compitem this corresponds to
if (view->pItems && (rownr >= 0) && (rownr < view->rows)) {
ciTop = view->pItems[rownr];
}
// re-do the outline mapping, but don't tell the table class.
// ask it to check for the visible row closest to ciTop in case
// we need to refresh the display
//
// since we are holding the critsec, the redraw param
// *must* be false.
view_outline_opt(view, FALSE, ciTop, &rownr);
/* have the column widths changed ? */
if ((maxtag < view->maxtag) || (maxrest < view->maxrest)) {
/* yes - need complete redraw */
bRedraw = TRUE;
} else {
bAppend = TRUE;
}
}
ViewLeave();
if (bRedraw) {
/* switch to new mapping */
SendMessage(view->hwnd, TM_NEWLAYOUT, 0, (LPARAM) view);
// go to the visible row closest to the old top row
if ((rownr >= 0) && (rownr < view->rows)) {
SendMessage(view->hwnd, TM_TOPROW, TRUE, rownr);
}
// select the old selection too (if the table class allowed
// us to get it)
if (bSelect) {
SendMessage(view->hwnd, TM_SELECT,0, (LPARAM) &Select);
}
} else if (bAppend) {
/* we can just append */
/*
* in the WIN32 multiple threads case, the mapping may have
* changed since we released the critsec. however we are still
* safe. The table will not allow us to reduce the number of
* rows, so the worst that can happen is that the table will
* think there are too many rows, and the table message handler
* will handle this correctly (return null for the text).
* The only visible effect is therefore that the scrollbar
* position is wrong.
*/
SendMessage(view->hwnd, TM_APPEND, view->rows, (LPARAM) view);
}
return(Poll());
}
/*
* the view mapping options (eg outline_include, expand_mode) have changed -
* re-do the mapping and then scroll back to the same position in the window
* if possible.
*/
void
view_changeviewoptions(VIEW view)
{
long row;
int state, number;
BOOL bRight;
if (view == NULL) {
return;
}
/* find what row we are currently on. Do this BEFORE we enter CSView */
row = (long) SendMessage(view->hwnd, TM_TOPROW, FALSE, 0);
ViewEnter();
if (!view->bExpand) {
// view_outline_opt allows us to find the first visible row
// after a given COMPITEM. Do this to look for the old top-row
// compitem, so that even if it is no longer visible, we can
// still go to just after it.
INT newrow = -1;
if (row < view->rows) {
COMPITEM ciTop = view->pItems[row];
view_outline_opt(view, TRUE, ciTop, &newrow);
} else {
view_outline_opt(view, TRUE, NULL, NULL);
}
ViewLeave();
// row now has the visible row that corresponds to
// ciTop or where it would have been
if ((newrow >=0) && (newrow < view->rows)) {
SendMessage(view->hwnd, TM_TOPROW, TRUE, newrow);
}
return;
}
/* expanded mode */
bRight = FALSE; /* arbitrarily - avoid strange diagnostic */
/* save the line number on one side (and remember which side) */
if (row >= view->rows) {
number = -1;
} else {
state = section_getstate(view->pLines[row].section);
if ((state == STATE_MOVEDRIGHT) ||
(state == STATE_RIGHTONLY)) {
bRight = TRUE;
number = view->pLines[row].nr_right;
} else {
bRight = FALSE;
number = view->pLines[row].nr_left;
}
}
/* make the new mapping */
view_expand_item(view, view->ciSelect);
/* things may happen now due to simultaneous scrolling from
* two threads. At least we won't deadlock.
*/
/* find the nearest row in the new view */
if (number >= 0) {
ViewEnter();
row = view_findrow(view, number, bRight);
ViewLeave();
/* scroll this row to top of window */
if (row >= 0) {
/* things may happen now due to simultaneous scrolling from
* two threads. At least we won't deadlock.
*/
SendMessage(view->hwnd, TM_TOPROW, TRUE, row);
return;
}
}
}
/* the compare options have changed - re-do the compare completely
* and make the new mapping. Retain current position in the file.
*/
void
view_changediffoptions(VIEW view)
{
int state, number;
long row;
BOOL bRight = FALSE;
LIST li;
COMPITEM ci;
number = 0;
if (view == NULL) {
return;
}
/*