forked from trevordevore/levurehelper-dataview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataview_behavior.livecodescript
6138 lines (4783 loc) · 198 KB
/
dataview_behavior.livecodescript
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
script "DataView Behavior"
constant kLockUpdatesSetting = "true" # use for testing whether or not lockupdates makes a difference.
constant kFieldEditorName = "dvFieldEditor"
constant kAlternatingRowModValue = 0 -- 0 to have first color be first, 1 to have first color be alternating color
constant kDefaultDimmedHiliteColor = "212,212,212"
constant kRowColor = "255,255,255"
constant kAlternateRowColor = "230,237,247"
constant kKeyNumsThatScroll = "65308,65309,65310,65311"
constant kSBWidthWin = 17
constant kSBWidthMac = 15
constant kSBWidthLinux = 16
constant kDefaultForNonCachedVariableHeightRows = 50
local sInit
local sWorkingGroupRect
local sViewPropsA
local sSystemA -- stores system specific settings
local sLastTargetedRow
local sScrollerID
local sPendingMsgsA
local sFieldEditor ## place holder until I decide what to do with editing.
local sNumRowsTempCache ## Caches row count during single event
local sTouchA # for swiping
local sMouseDownA # dvMouseDownBefore handler stores data in this variable that dvMouseDownAfter handler uses.
local sDropStructure
local sUseEventsForScroll
/**
Summary: Print out diagnostic information about the internal data structures.
Returns: Diagnostic text
*/
command __InspectInternally
local tText
put "control height cache:" && _getTotalCachedHeight() & cr & \
"content height:" && the viewProp["content height"] of me & cr & \
"sViewProps:" & cr & printArray(sViewPropsA,,true) into tText
return tText
end __InspectInternally
/**
Summary: Possible entry point for initializing internal data structures.
Description:
Note that this message will not be called if a DataView is created
by script.
*/
before preopenControl
if the target is not me then exit preopenControl
_init
end preopenControl
/**
Summary: Possible entry point for initializing internal data structures.
*/
before newGroup
if the target is not me then exit newGroup
_init
end newGroup
/**
Summary: Cleans up the mobile scrollbar.
*/
after closeControl
if the environment is "mobile" then
if sScrollerID is among the lines of mobileControls() then
mobileControlDelete sScrollerID
put empty into sScrollerID
end if
end if
end closeControl
/**
Summary: Resizes the DataView to fit the new rect.
*/
on resizeControl
if the target is not me then pass resizeControl
ResizeToFit
pass resizeControl
end resizeControl
/**
Summary: Implements changing selection when arrow keys are pressed.
*/
on arrowKey pDirection
if word 1 of the target is "field" and not the locktext of the target then pass arrowkey
dvArrowKey pDirection
pass arrowkey
end arrowKey
/**
Summary: Implements scroll wheel scrolling for the control.
Parameters:
pKeyNum: See LiveCode docs.
Returns: empty
*/
on rawKeyDown pKeyNum
local tCanScroll
/*
Immediate exit:
1. No scrollbar (content isn't tall enough to scroll)
2. Editable field is target and either:
A. pKeyNum isn't interesting for scrolling purposes
B. The field is the focusedObject and it has a scrollbar
*/
put the visible of scrollbar "dvVScrollbar" of me \
or the viewProp["scroll when vScrollbar is hidden"] of me into tCanScroll
if not tCanScroll then
pass rawKeyDown
else if word 1 of the target is "field" AND not the locktext of the target then
set the wholeMatches to true
if pKeyNum is not among the items of kKeyNumsThatScroll then
pass rawkeyDown
else if the long id of the target is the focusedObject AND the vscrollbar of the target then
# If field has focus then scroll actions should be handled by field
pass rawKeyDown
end if
end if
-- 65308 - Mouse wheel down
-- 65309 - Mouse wheel up
-- 65310 - Mouse wheel right
-- 65311 - Mouse wheel left
-- 65365 - page up
-- 65366 - page down
-- 65360 - home
-- 65367 - end
## Note: Messages are locked when setting thumbpostion and we call scrolling code directly.
## This is done so that scrolling works when scrollbars are hidden.
local tAvailHeight, tScroll, tRowHeight
switch pKeyNum
case "65360"
## home
set the viewProp["vscroll"] of me to 0
break
case "65367"
## end
set the viewProp["vscroll"] of me to the endValue of scrollbar "dvVScrollbar" of me
break
case "65365"
## scroll page up
set the viewProp["vscroll"] of me to the thumbPosition of scrollbar "dvVScrollbar" of me - \
the pageIncrement of scrollbar "dvVScrollbar" of me
break
case "65366"
## scroll page down
set the viewProp["vscroll"] of me to the thumbPosition of scrollbar "dvVScrollbar" of me + \
the pageIncrement of scrollbar "dvVScrollbar" of me
break
case "65309" # scroll up
## mouse wheel up
## If a field editor is open then it must be closed first
if the viewProp["cache"] of me is "none" and the viewProp["field editor is open"] of me then
DeleteFieldEditor true, "close control"
else
if sUseEventsForScroll then
put the viewProp["row height"] of me into tRowHeight
if tRowHeight <= 0 then
# This calculation provides an acceptable scroll speed for variabl row height in testing
put the viewProp["content window height"] of me into tAvailHeight
put round(tAvailHeight * .03) into tRowHeight
end if
set the viewProp["vscroll"] of me to \
round(the thumbPosition of scrollbar "dvVScrollbar" of me) - item 2 of macCurrentEventScrollValues(tRowHeight)
else
put the viewProp["content window height"] of me into tAvailHeight
put round(tAvailHeight * .1) into tScroll
set the viewProp["vscroll"] of me to round(the thumbPosition of scrollbar "dvVScrollbar" of me) - tScroll
end if
end if
break
case "65308" # scroll down
## mouse wheel down
## If a field editor is open then it must be closed first
if the viewProp["cache"] of me is "none" and the viewProp["field editor is open"] of me then
DeleteFieldEditor true, "close control"
else
if sUseEventsForScroll then
put the viewProp["row height"] of me into tRowHeight
if tRowHeight <= 0 then
# This calculation provides an acceptable scroll speed for variabl row height in testing
put the viewProp["content window height"] of me into tAvailHeight
put round(tAvailHeight * .03) into tRowHeight
end if
set the viewProp["vscroll"] of me to \
round(the thumbPosition of scrollbar "dvVScrollbar" of me) - item 2 of macCurrentEventScrollValues(tRowHeight)
else
put the viewProp["content window height"] of me into tAvailHeight
put round(tAvailHeight * .1) into tScroll
set the viewProp["vscroll"] of me to round(the thumbPosition of scrollbar "dvVScrollbar" of me) + tScroll
end if
end if
break
case "65310"
## mouse wheel right
-- nothing
case "65311"
## mouse wheel left
-- nothing
default
pass rawKeyDown
end SWITCH
end rawKeyDown
/**
Summary: Prcoesses the message for the scrollbars.
*/
on scrollbarDrag pValue
if the short name of the target is "dvVScrollbar" then
if pValue is not the viewProp["vscroll"] of me then
lock messages
_setVScroll pValue ## in case messages are locked
unlock messages
end if
end if
end scrollbarDrag
/**
Summary: Called by mobile scrollbars.
*/
on scrollerDidScroll pOffsetX, pOffsetY
-- Set the scroll values of the group based on feedback from the scroller
-- notice that we can just use the values directly and because out-of-bounds
-- scrolling is enabled for the group, the bounce effect needs no extra
-- code.
_setVScroll pOffsetY
end scrollerDidScroll
on mouseDown pMouseBtnNum
if the environment is not "mobile" then
# For more complicated dataview behavior the developer may
# want to call dvMouseDownBefore manually.
if the viewProp["process mousedown"] of me is not false then
dvMouseDown pMouseBtnNum
end if
end if
pass mousedown
end mouseDown
on mouseUp pMouseBtnNum
if the environment is not "mobile" then
dvMouseUp pMouseBtnNum
end if
pass mouseUp
end mouseUp
on mouseRelease pMouseBtnNum
if the environment is not "mobile" then
dvMouseRelease pMouseBtnNum
end if
pass mouseRelease
end mouseRelease
/**
Summary: Implementation of `MouseEnterControl`/`MouseLeaveControl` and `MouseEnterDataView/MouseLeaveControl` messages.
Description:
As of LiveCode 9.5 there is no support for `mouseEnter`/`mouseLeave` messages that
are sent to a group. The DataView synthesizes the `MouseEnterControl`/`MouseLeaveControl`
messages to overcome this shortcoming.
`mouseEnter` handles both `MouseEnterControl` and `MouseLeaveControl` messages while the mouse
moves around inside of the DataView. `mouseLeave` sends the `MouseLeaveControl` when the mouse
leaves the DataView.
*/
local sCurrentMouseRowControlId
local sMouseWithinDataView
before mouseEnter
local tControlId
/*
Observed behavior:
Take a row control that has an icon which is shown on MouseEnterRowControl and
hidden on MouseLeaveRowControl. While visible, the user can click on it to show a
popup menu. If the user moves the mouse around to other controls in the row control
while the popup menu is visible, and then dismisses the menu while the mouse is outside
of the DataView (by click or using escape key), an endless loop of mouseLeave/mouseEnter
messages will be generated while the icon is being shown/hidden repeatedly.
I understand why mouseLeave is sent to the control. It is unclear why mouseEnter would
be sent again as the mouse isn't over the control. That appears to be a bug.
This check ensures that this endless loop doesn't occur.
*/
if the mouseLoc is not within the rect of me then
exit mouseEnter
end if
if not sMouseWithinDataView then
put true into sMouseWithinDataView
dispatch "MouseEnterDataView" to me
end if
put the dvRowControl of the target into tControlId
if tControlId is empty then
put the dvPaddingControl of the target into tControlId
end if
if tControlId is not empty then
put the short id of tControlId into tControlId
if tControlId is not sCurrentMouseRowControlId then
if sCurrentMouseRowControlId is not empty and there is a control id sCurrentMouseRowControlId then
dispatch "MouseLeaveControl" to control id sCurrentMouseRowControlId
end if
put tControlId into sCurrentMouseRowControlId
dispatch "MouseEnterControl" to control id sCurrentMouseRowControlId
end if
else
if there is a control id sCurrentMouseRowControlId then
put sCurrentMouseRowControlId into tControlId
put empty into sCurrentMouseRowControlId
dispatch "MouseLeaveControl" to control id tControlId
end if
end if
end mouseEnter
/**
Summary: Ensures that `the mouseLoc` does not return a negative y value.
Description:
During testing it was observed that `the mouseLoc` in `after mouseUp` would
return a negative value for the y coordinate unless the DataView also defined
the `on mouseUp` handler. The root cause has not been found but this fixes
the problem.
Returns: nothing
*/
on mouseEnter
pass mouseEnter
end mouseEnter
/**
Summary: mouseLeave is only necessary for sending messages when the mouse leaves the DataView as a whole.
Returns: nothing
*/
after mouseLeave
# During this message the mouseLoc will be outside of the rect in most cases.
# It is possible that a control slightly overlaps the DataView, however, which
# is why there is a check for a matching dvControl as well.
if the mouseLoc is not within the rect of me or \
the mousecontrol is empty or the dvControl of the mousecontrol is not the dvControl of me then
if sCurrentMouseRowControlId is not empty then
local tControlId
put sCurrentMouseRowControlId into tControlId
put empty into sCurrentMouseRowControlId
if there is a control id tControlId then
dispatch "MouseLeaveControl" to control id tControlId
end if
end if
put false into sMouseWithinDataView
dispatch "MouseLeaveDataView" to me
end if
end mouseLeave
/**
Summary: Ensures that `the mouseLoc` does not return a negative y value.
Description:
During testing it was observed that `the mouseLoc` in `after mouseLeave` would
return a negative value for the y coordinate unless the DataView also defined
the `on mouseLeave` handler. The root cause has not been found but this fixes
the problem.
Returns: nothing
*/
on mouseLeave
pass mouseLeave
end mouseLeave
on touchStart pID
local theIndex, theControl, theRow
put the mouseLoc into sTouchA[pId]["start loc"]
## figure out the index clicked on
put empty into theIndex
if the mouseControl is not empty then
put the dvRowControl of the mouseControl into theControl
end if
if theControl is not empty then
put the dvRow of theControl into theRow
end if
## Bring focus into control. Do this before any possible exit points.
if theRow is not empty then
## Clicked on a control. Bring focus into control but away from scrollbar.
if the long ID of me is not in the long ID of the focusedObject or word 1 of the target is "scrollbar" or \
(sViewPropsA["fld_editor"]["control"] is not empty and the long id of control id sViewPropsA["fld_editor"]["control"] is the long ID of the focusedObject) then
focus on graphic "dvBackground" of me
end if
else
## clicked in space but no on list control
focus on graphic "dvBackground" of me
end if
if the viewProp["autohilite"] of me is false then return empty
## Now do what we need to do
if theRow is not empty then
put sViewPropsA["hilited rows"] into sViewPropsA["previously hilited rows"]
put theRow into sViewPropsA["hilited rows"]
_hiliteRowsInVisibleControls
end if
## If the selection hasn't changed then at least update the hilites as they
## may be grayed out. If one day we can get a true focusIn message for the group
## as a whle then the 'else' condition can be removed.
-- if theSelectionChanged then _selectionChanged thePreviouslyHilitedRows
-- else _hiliteRowsInVisibleControls
pass touchStart
end touchStart
on touchEnd pID
local thePreviouslyHilitedRows
# When the touch end remove the ID from the array tracking all our touches
if sTouchA[pID] is an array then
## no swipe
delete variable sTouchA[pId]
end if
put sViewPropsA["previously hilited rows"] into thePreviouslyHilitedRows
put empty into sViewPropsA["previously hilited rows"]
if sViewPropsA["hilited rows"] is not empty then
_selectionChanged thePreviouslyHilitedRows
end if
pass touchEnd
end touchEnd
/**
Summary: Sent in cases where user touches row, holds but then starts scrolling.
*/
on touchRelease
set the dvHilitedRows of me to empty
pass touchRelease
end touchRelease
/**
Summary: Determines whether a left or right swipe has occurred on the data view.
*/
on touchMove pId, pX, pY
## Swipe is with one finger
if sTouchA[pID] is an array and the number of lines of the keys of sTouchA is 1 then
local theDeltaX, theDeltaY
put item 1 of sTouchA[pID]["start loc"] - pX into theDeltaX
put abs(item 2 of sTouchA[pID]["start loc"] - pY) into theDeltaY
if theDeltaY < 50 then
if abs(theDeltaX) > 30 then
if theDeltaX < 0 then
dispatch "swipeRight"
else
dispatch "swipeLeft"
end if
delete variable sTouchA[pID]
end if
end if
end if
pass touchMove
end touchMove
/**
Summary: Deletes all controls, resets the vscroll and clears internal storage.
Returns: empty
*/
command ResetView
local i, msgsAreLocked
put the lockMessages into msgsAreLocked
lock screen
lock messages
_init
# Cleanup rows, sending messages
repeat for each key theKey in sViewPropsA["controls"]["cache"]
if there is not a control id sViewPropsA["controls"]["cache"][theKey]["control"] then next repeat
dispatch "CleanupAfterControl" to control id sViewPropsA["controls"]["cache"][theKey]["control"]
delete control id sViewPropsA["controls"]["cache"][theKey]["control"]
end repeat
# This will clean up any stragglers
repeat with i = the number of groups of group "dvList" of me down to 1
delete group i of group "dvList" of me
end repeat
repeat with i = 1 to the number of controls of group "dvList" of me
delete control 1 of group "dvList" of me
end repeat
if there is a group "dvTopPaddingContent" of me then
delete group "dvTopPaddingContent" of me
end if
set the viewProp["vscroll"] of me to 0
set the viewProp["first working row"] of me to 0
set the viewProp["last working row"] of me to 0
set the thumbposition of scrollbar "dvVScrollbar" of me to 0
put empty into sViewPropsA
set the viewProp["content height"] of me to 0
_autoHideScrollbars
_configureScrollbars
unlock screen
set the lockMessages to msgsAreLocked
return empty
end ResetView
/**
Summary: Renders the data in the view using the current vscroll. The 'hilited rows' property will be reset.
Description:
All controls will be updated with latest data. If caching is on this means all controls get new data.
Any controls which have not yet been cached will be cached during this call. No controls will be recreated.
Returns: empty
*/
command RenderView
put empty into sViewPropsA["hilited rows"]
put empty into sViewPropsA["running actions"]
_renderView
return the result
end RenderView
/**
Summary: Refresh the view by making sure the proper data is mapped to the proper row.
Description:
The purpose of this handler is to ensure that the proper data is mapped to the proper row
in the view. It can be called after reordering rows, deleting rows, adding rows, etc.
If caching is on then the cache keys for each row will be updated, clearing controls as
necessary, and any new controls will be initialized/displayed.
If caching is off then the normal draw routines are called.
Returns: empty
*/
command RefreshViewRows
_renderView false
return the result
end RefreshViewRows
/**
Summary: Refreshes the data in the specified rows and renders them.
Parameters:
pRows: A comma-delimited list of rows to render.
Description:
If a row does not have a control associated with it then nothing will happen.
Returns: empty
*/
command RenderRows pRows
local tRowCount, theRow, theIndex
local theDataA, theControlId, theStyle, theTopLeft
local updateTheScrollbars = "false"
local msgsAreLocked, theRowWidth, theCacheKey
put the viewProp["content width"] of me into theRowWidth
put the lockMessages into msgsAreLocked
unlock messages
lock screen
set the lockUpdates of group "dvList" of me to kLockUpdatesSetting
put the viewProp["number of rows"] of me into tRowCount
## Update existing rows
repeat for each item theRow in pRows
if theRow < 1 or theRow > tRowCount then next repeat
# Reset data array each time through loop
put empty into theDataA
dispatch "DataForRow" to me with theRow, theDataA, theStyle ## style is ignored for a refresh (dispatch forces target)
put _dispatchCacheKeyForRow(theRow) into theCacheKey # don't use cached key
put sViewPropsA["controls"]["cache"][theCacheKey]["control"] into theControlId
if theControlId is not empty then
if the dvTemplateStyle of control id theControlId is not theStyle then
# Control isn't valid for row type. Move back into cache and get a new control
put the topleft of control id theControlId into theTopLeft
_cleanupControl theCacheKey, theRow, theControlId, true
_setupRowControl theRow, empty, true
put the result into theControlId
set the topleft of control id theControlId to theTopLeft
else
# Reset data array each time through loop
put empty into theStyle
## Since we are rendering from scratch dvControlHasBeenRendered should return false during the next two messages
lock messages
set the dvDataCache of control id theControlId to empty
set the dvHiliteState of control id theControlId to empty
unlock messages
## Implemented by instance of behavior
dispatch "FillInData" to control id theControlId with theDataA, theRow
lock messages
set the dvDataCache of control id theControlId to NULL
unlock messages
end if
_dispatchLayoutControl theControlId, theRow, theRowWidth, true
put true into updateTheScrollbars
else if the viewProp["cache"] of me is "none" and not the viewProp["fixed row height"] of me then
## Control isn't visible on screen. NULL the height so it's new height is taken into account next time it is rendered.
if sViewPropsA["controls"]["control height cache"][theRow] is not NULL then
put true into updateTheScrollbars
put NULL into sViewPropsA["controls"]["control height cache"][theRow]
end if
end if
end repeat
set the lockUpdates of group "dvList" of me to false
if updateTheScrollbars then
## Update everything
_calculateContentHeight
lock messages
_configureScrollbars ## note that messages are locked so no scrollbar drag is sent
unlock messages
RenderVisibleRows
# Allow developer to move objects along with the DataView.
dispatch "DataViewDidUpdateView" to me
end if
unlock screen
set the lockMessages to msgsAreLocked
return empty
end RenderRows
/**
Summary: Renders all visible controls based on current properties.
Returns: `true` if the `content height` changed while drawing.
*/
command RenderVisibleRows
local theDataA, theStyle
local theStartRow, theEndRow, theStartRowYOffset
local theRowWidth, theOrigContentHeight
local msgsAreLocked
## Throttle
if sViewPropsA["running actions"]["vscroll"] then
put true into sViewPropsA["running actions"]["resend vscroll"]
return empty
end if
put true into sViewPropsA["running actions"]["vscroll"]
put the lockMessages into msgsAreLocked
unlock messages
_getRangeOfRowsToDisplay theStartRow, theEndRow, theStartRowYOffset ## can alter content height
put the viewProp["content height"] of me into theOrigContentHeight
put the viewProp["content width"] of me into theRowWidth
## Update the pool of available controls
## and reset list of rows in use
_updateControlCacheForActiveRange theStartRow, theEndRow
set the viewProp["first working row"] of me to theStartRow # in case developer wants to access
set the viewProp["last working row"] of me to theEndRow
lock screen
local forceFillInData = "true"
if theStartRow > 0 then
local theTopLeft, tControlId
put the topleft of group "dvListMask" of me into theTopLeft
subtract theStartRowYOffset from item 2 of theTopLeft
set the lockUpdates of group "dvList" of me to kLockUpdatesSetting
repeat with theRow = theStartRow to theEndRow
## Controls
## "available"
## "cache"
## "rows in use"
## Is there a cached control for this row?
put sViewPropsA["controls"]["cache"][_getCacheKeyForRow(theRow)]["control"] into tControlId
## No control? Get data and get one.
if tControlId is empty then
_setupRowControl theRow, empty, forceFillInData
put the result into tControlId
if tControlId is empty then exit repeat
set the topleft of control id tControlId to theTopLeft
# Don't update height. We only get here if caching is off. Heights have already been determined previously.
_dispatchLayoutControl tControlId, theRow, theRowWidth, false
else
_prepareRowForDisplay theRow, tControlId, theRowWidth, theTopLeft
end if
if not the visible of control id tControlId then
# Send message to control telling it that it is being displayed
dispatch "ShowControl" to control id tControlId
set the visible of control id tControlId to true
end if
if theRow is among the items of sViewPropsA["hilited rows"] then
_hiliteControl tControlId, true
else
_hiliteControl tControlId, false
end if
put the bottom of control id tControlId into item 2 of theTopLeft
# relayer row control so that tabbing through controls works as expected.
lock messages
relayer control id tControlId to front of group "dvList" of me
unlock messages
end repeat
end if ## startrow > 0
# Scroll top padding content
if there is a group "dvTopPaddingContent" of me then
put the short id of group "dvTopPaddingContent" of me into tControlId
if theStartRow is 0 then
if not the visible of control id tControlId then
set the visible of control id tControlId to true
end if
set topleft of control id tControlId to the topleft of group "dvList" of me
else if theStartRow is 1 and theStartRowYOffset < 0 then
if not the visible of control id tControlId then
set the visible of control id tControlId to true
end if
set the bottomleft of control id tControlId to \
the topleft of control id sViewPropsA["controls"]["cache"][_getCacheKeyForRow(1)]["control"]
else if the visible of control id tControlId then
set the visible of control id tControlId to false
end if
end if
set the lockUpdates of group "dvList" of me to false
if the viewProp["content height"] of me is not theOrigContentHeight then
_configureScrollbars
end if
unlock screen
set the lockMessages to msgsAreLocked
put false into sViewPropsA["running actions"]["vscroll"]
if sViewPropsA["running actions"]["resend vscroll"] then
if the keys of the dragData is empty then
send "RenderVisibleRows" to me in 0 milliseconds
end if
put false into sViewPropsA["running actions"]["resend vscroll"]
end if
return the viewProp["content height"] of me is not theOrigContentHeight
end RenderVisibleRows
/**
Summary: Resizes the specified row controls. Useful for cached controls that can be resized by the user.
Parameters:
pRows: The rows to resize.
Returns: empty
*/
command ResizeRows pRows
local theRow
repeat for each item theRow in pRows
FlagRowForResize theRow
end repeat
lock screen
RenderVisibleRows
# 2015-12-21: Added so we could move objects along with the DataView.
dispatch "DataViewDidUpdateView" to me
unlock screen
return empty
end ResizeRows
/**
Summary: Removes the specified row from the view. Use when data is removed from the model.
Parameters:
pRows: The rows to delete.
pRefreshView: Pass in false to prevent the view being refreshed.
Description:
This handler is most useful when caching is turned on.
Returns: empty
*/
command DeleteRows pRows, pRefreshView
local theRow, theCacheKey, theItemNo
local msgsAreLocked
put pRefreshView is not false into pRefreshView
put the lockMessages into msgsAreLocked
lock screen
set the wholeMatches to true
## Go backwards so as not to mess up index offsets 11-08-2012: Not sure if this is still relevant
sort items of pRows descending numeric
## Move control back into cache of available controls
repeat for each item theRow in pRows
_deleteRowControlFromCache theRow
end repeat
_ensureIntegrityOfSelectedRows
## Redraw everything. Note that RefreshViewRows won't reload data in cached controls, just refresh the view.
if pRefreshView then
RefreshViewRows
end if
set the lockMessages to msgsAreLocked
unlock screen
return empty
end DeleteRows
/**
Summary: Removes a row control from the cache. The view is not refreshed afterwards.
Parameters:
pRow: The row to remove.
Description:
Use this handler to remove controls from the cache as part of a larger handler that
will also handle refreshing the view.
Returns: nothing
*/
command DeleteRowControlFromCache pRow
_deleteRowControlFromCache pRow
return empty
end DeleteRowControlFromCache
private command _deleteRowControlFromCache pRow
local tCacheKey, tItemNo
put _getCacheKeyForRow(pRow) into tCacheKey
if sViewPropsA["controls"]["cache"][tCacheKey] is an array then
_cleanupControl tCacheKey, pRow, sViewPropsA["controls"]["cache"][tCacheKey]["control"], true
end if
# Remove from rows in use
put itemOffset(pRow, sViewPropsA["controls"]["rows in use"]) into tItemNo
if tItemNo > 0 then
delete item tItemNo of sViewPropsA["controls"]["rows in use"]
end if
return empty
end _deleteRowControlFromCache
/**
Summary: Resizes the DataView rows to fit the current rect.
Returns: empty
*/
command ResizeToFit
put _workingGroupRect(the long id of me) into sWorkingGroupRect
## Throttle just in case developer tries to call this from different timers
if sViewPropsA["running actions"]["resize to fit"] then
put true into sViewPropsA["running actions"]["resend resize to fit"]
return empty
end if
put true into sViewPropsA["running actions"]["resize to fit"]
local screenIsLocked
put the lockScreen into screenIsLocked
if not screenIsLocked then lock screen
local theVScrollPercent, theLockLoc, msgsAreLocked, theMasterRect
local theErrorToRethrow
put sWorkingGroupRect into theMasterRect
put the viewProp["vscroll percent"] of me into theVScrollPercent
put the lockLoc of me into theLockLoc
set the lockLoc of me to true
put the lockMessages into msgsAreLocked
lock messages
set the rect of graphic "dvBackground" of me to theMasterRect
if there is a button "dvEventCatcher" of me then
set the rect of button "dvEventCatcher" of me to theMasterRect
end if
add the borderWidth of me to item 1 of theMasterRect
add the borderWidth of me to item 2 of theMasterRect
subtract the borderWidth of me from item 3 of theMasterRect
subtract the borderWidth of me from item 4 of theMasterRect
set the rect of scrollbar "dvVScrollbar" of me to \
item 3 of theMasterRect - the width of scrollbar "dvVScrollbar" of me, \
item 2 of theMasterRect, item 3 of theMasterRect, item 4 of theMasterRect - max(0, the viewProp["scrollbar corner offset"] of me)
set the topleft of group "dvListMask" of me to item 1 of theMasterRect + max(0, the viewProp["content left padding"] of me), \
item 2 of theMasterRect
set the topleft of group "dvList" of me to the topleft of group "dvListMask" of me
set the visible of scrollbar "dvVScrollbar" of me to the environment is not "mobile" \
AND the viewProp["content height"] of me > _getContentWindowHeight()
_resizeSupportingControls
set the lockLoc of me to theLockLoc
unlock messages
try
_resetHiliteStateInCachedControls
_resizeRowControlsAsNeeded
lock messages
_configureScrollbars
unlock messages