/
Xbrowse.102.prg
10963 lines (8572 loc) · 309 KB
/
Xbrowse.102.prg
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
#include "FiveWin.ch"
#include "InKey.ch"
#include "constant.ch"
#include "xbrowse.ch"
#include "Report.ch"
#include "dtpicker.ch"
#xtranslate MinMax( <xValue>, <nMin>, <nMax> ) => ;
Min( Max( <xValue>, <nMin> ), <nMax> )
#define SRCCOPY 0x00CC0020
#define GWL_STYLE -16
#define GW_HWNDFIRST 0
#define GW_HWNDNEXT 2
#define SM_CYVSCROLL 20
#define SM_CYHSCROLL 3
#define CS_DBLCLKS 8
#define COLOR_SCROLLBAR 0
#define COLOR_BACKGROUND 1
#define COLOR_ACTIVECAPTION 2
#define COLOR_INACTIVECAPTION 3
#define COLOR_MENU 4
#define COLOR_WINDOW 5
#define COLOR_WINDOWFRAME 6
#define COLOR_MENUTEXT 7
#define COLOR_WINDOWTEXT 8
#define COLOR_CAPTIONTEXT 9
#define COLOR_ACTIVEBORDER 10
#define COLOR_INACTIVEBORDER 11
#define COLOR_APPWORKSPACE 12
#define COLOR_HIGHLIGHT 13
#define COLOR_HIGHLIGHTTEXT 14
#define COLOR_BTNFACE 15
#define COLOR_BTNSHADOW 16
#define COLOR_GRAYTEXT 17
#define COLOR_BTNTEXT 18
#define COLOR_INACTIVECAPTIONTEXT 19
#define COLOR_BTNHIGHLIGHT 20
#define DT_TOP 0x00000000
#define DT_LEFT 0x00000000
#define DT_CENTER 0x00000001
#define DT_RIGHT 0x00000002
#define DT_VCENTER 0x00000004
#define DT_BOTTOM 0x00000008
#define DT_WORDBREAK 0x00000010
#define DT_SINGLELINE 0x00000020
#define DT_EXPANDTABS 0x00000040
#define DT_TABSTOP 0x00000080
#define DT_NOCLIP 0x00000100
#define DT_EXTERNALLEADING 0x00000200
#define DT_CALCRECT 0x00000400
#define DT_NOPREFIX 0x00000800
#define DT_INTERNAL 0x00001000
#define DT_EDITCONTROL 0x00002000
#define DT_PATH_ELLIPSIS 0x00004000
#define DT_END_ELLIPSIS 0x00008000
#define DT_MODIFYSTRING 0x00010000
#define DT_RTLREADING 0x00020000
#define DT_WORD_ELLIPSIS 0x00040000
#define DT_NOFULLWIDTHCHARBREAK 0x00080000
#define DT_HIDEPREFIX 0x00100000
#define MK_MBUTTON 0x0010
#define COL_EXTRAWIDTH 6
#define ROW_EXTRAHEIGHT 4
#define COL_SEPARATOR 2
#define BMP_EXTRAWIDTH 5
#define RECORDSELECTOR_WIDTH 25
#define BITMAP_HANDLE 1
#define BITMAP_PALETTE 2
#define BITMAP_WIDTH 3
#define BITMAP_HEIGHT 4
#define BITMAP_ZEROCLR 5
#define BITMAP_ALPHA 6
#define VSCROLL_MAXVALUE 10000 // never set values above 32767
#define TME_LEAVE 2
#define WM_MOUSELEAVE 675
#define PM_REMOVE 0x0001
#ifdef __XHARBOUR__
#xtranslate hb_hKeyAt( <h>, <n> ) => hGetKeyAt( <h>, <n> )
#xtranslate hb_hValueAt( <h>, <n> ) => hGetValueAt( <h>, <n> )
#xtranslate hb_hCaseMatch( <h>, <n> ) => hSetCaseMatch( <h>, <n> )
#endif
//------------------------------------------------------------------------------
static lThouSep := .f.
static cNumFormat := 'A'
static lExcelInstl, lCalcInstl
static nxlLangID, cxlTrue := "=(1=1)", cxlFalse := "=(1=0)", cxlSum, cxlSubTotal, lxlEnglish := .f., hLib
static bXBrowse
//----------------------------------------------------------------------------//
CLASS TXBrowse FROM TControl
DATA oVScroll,; // Vertical scrollbar (used internally)
oHScroll,; // Horizontal scrollbar (used internally)
oCapCol,; // Actual mouse captured column (used internally)
oSeek,; // Optional TSay control to display the value of current ::cSeek value
oDbf // Just a container for a DBF object for your own use (it is not used by the class)
DATA aCols,; // Array of TXBrwCols (used internally)
aDisplay,; // Array of current diplayed ordinal columns (used internally)
aSelected,; // Currently records selected (only use with marquee style MARQSTYLE_HIGHLROWMS
aArrayData // Array data (filled on SetArray())
DATA aSortBmp
// Code-blocks for navitation
DATA bGoTop,; // codeblock for going to first row
bGoBottom,; // codeblock for going to last row
bSkip,; // codeblock for skiping rows, it receives the number of rows
; // to skip. IT SHOULD RETURN THE NUMBER OF ROWS SKIPPED
bBof,; // codeblock to check if we are at the first row
bEof,; // codeblock to check if we are at the bottom row
bKeyNo,; // SETGET codeblock to be used for positioning the vertical scrollbar
; // When no parameter is passed it should return the actual position
; // When a parameter is passed should perform a jump to that position
; // For example: {|n| iif( n == nil, OrdKeyNo(), OrdKeyGoto(n) }
bKeyCount,; // codeblock that returns the total number of rows
bBookMark,; // SETGET codeblock to be used for bookmarking a specific row
; // When no parameter is passed it should return a bookamark value
; // When a parameter is passed should return to that bookmark position
; // For example: {|n| iif( n == nil, Recno(), DbGoto(n) }
bSeek,; // block expresion for autoincremental search. It should return .T. when found
; // Receives the string to search
bPastEof // block to evaluate if trying to go down after the last row
DATA bPopUp // PopUp menu on right click on any column
// This code-blocks should return an two dimension array with {nFore, nBack} colors
DATA bClrHeader,; // default color pair for header
bClrFooter,; // default color pair for footer
bClrGrad, ; // default colour gradient spec
bClrStd,; // default color pair for normal rows
bClrSel,; // default color pair for selected row
bClrSelFocus,; // default color pair for selected row when control has focus
bClrRowFocus
DATA bColClass INIT { || TxBrwColumn() }
DATA cAlias,; // Alias when accesing via RDD
cSeek; // string that hold the current string searched (for autoincremental seek)
AS CHARACTER
DATA nRowSel,; // Current row selected based on current display
nColSel,; // Current columns based on current display
nFreeze,; // Number of columns to freeze
nColOffset; // Actual first column to be shown after freeze
AS NUMERIC
DATA nHeaderLines,; // Number of lines of the header
nFooterLines,; // Number of lines of the footer
nDataLines; // Number of lines of the data rows
AS NUMERIC
DATA nDataType; // Data type to be used: 0->rdd, 1->array, ... (more to come)
AS NUMERIC // If navigation codeblocks are not specified then get automatically
// initialiated when adjusting the browse depending on this DATA value
DATA nHeaderHeight,; // Header height. If this value is NIL, the is calculated on the Adjust method
nFooterHeight,; // Footer height. If this value is NIL, the is calculated on the Adjust method
nRowHeight,; // Data row height. If this value is NIL, the is calculated on the Adjust method
nRecSelColor // Background color for the record selector column, by default uses the backgrounf footer
DATA nRowDividerStyle,; // Row divider style
nColDividerStyle; // Col divider style
AS NUMERIC // O LINESTYLE_NOLINES
// 1 LINESTYLE_BLACK
// 2 LINESTYLE_DARKGRAY
// 3 LINESTYLE_FORECOLOR
// 4 LINESTYLE_LIGHTGRAY
// 5 LINESTYLE_INSET
// 6 LINESTYLE_RAISED
DATA nMarqueeStyle; // Marquee style (row selected)
AS NUMERIC // 0 No Marquee
// 1 Dotted cell
// 2 Solid cell
// 3 Highlight cell
// 4 Highlight row & Raise Cell
// 5 Highlight row
// 6 Highlight row & multiselect
DATA nMoveType; // 1 Move Right
AS NUMERIC // 2 Move Left
// 3 Move Up
// 4 Move down
// 5 No Move
// 6 Move Right with lFastedit features, only work with lFastEdit := .t.
// 7 Move left with lFastedit features, only work with lFastEdit := .t.
DATA nLen,; // Actual data len. This data is updated with Eval( bKeyCount ) (used internally)
nDataRows,; // Actual number of data rows, used internally
nCaptured,; // Mouse captured: 0-> No, 1->In header, 2-> In footer, 3->ResizeCol, 4->ResizeLine (used internally)
nArrayAt,; // When SetArray() method is used return the actual array element (used internally)
nLastEditCol; // Last edited col (display based)
AS NUMERIC
DATA nVScrollPos; // Actual absolute vertical scroll pos (used internally)
AS NUMERIC
DATA hBtnShadowPen,; // Pen handle for shadow buttons color (used internally)
hWhitePen,; // Pen handle for white color (used internally)
hColPen,; // Pen for column lines (used internally)
hRowPen,; // Pen for row lines (used internally)
hBmpRecSel,; // Bitmap Handle for the record selector triangle (used internally)
hBrushRecSel // Brush Handle for the record selector (used internally)
DATA lCreated,; // True when control is completaly created (used internally)
lRecordSelector,; // if true a record selector column is displayed
lHScroll,; // Horizontal Scrollbar, it should be assigned before the createfrom..() method
lVScroll,; // Vertical Scrollbar, it should be assigned before the createfrom..() method
lAllowRowSizing,; // If true horizontal row sizing is allowed
lAllowColSwapping,; // If true col swapping is allowed
lAllowColHiding,; // If true col hiding is allowed
lColDividerComplete,; // If true the vertical lines are displayed to the bottom of the browse even
; // there are not enough data rows
lFastEdit, ; // Go to edit mode just pushing a alpha or digit char on a editable column
; // (incompatible with incremental seek and highlite row)
lEditMode,; // Some column is in edit mode (used internally)
lEdit,;
lRefreshOnlyData,; // True when only the data should be painted (used internally)
l2007 ; // 2007 look
AS LOGICAL
DATA lSeekWild AS LOGICAL INIT .f.
DATA lColChangeNotify AS LOGICAL INIT .f. // if true bChange is evaluated when col is changed
DATA lAutoSort AS LOGICAL INIT .f. // used internally. do not use in applications
DATA lAllowCopy AS LOGICAL INIT .t.
DATA lCanPaste AS LOGICAL INIT .f.
DATA lExcelCellWise AS LOGICAL INIT .t.
DATA lMergeVert AS LOGICAL INIT .f. // used internally
DATA lAutoAppend AS LOGICAL INIT .t. // AutoAppend
DATA lHeader,; // Browse has header, if this value is nil then is initialized automatically on the Adjust method
lFooter // Browse has footer, if this value is nil then is initialized automatically on the Adjust method
DATA nSaveMarq // used internally
DATA oRS // ADO recordset if Method SetAdo() is used
DATA oTree, oTreeItem // Do not set them directly, instead use SetTree method. Can be accessed
DATA oColToolTip // Used internally
DATA bOnRowLeave
DATA bOnSkip INIT { || nil }
DATA lEdited INIT .f.
DATA bLock INIT { || .t. }
DATA bUnLock
DATA uStretchInfo // Internal use only
DATA nStretchCol
DATA aHeaderTop,; // Array of header string Top
nHeader
DATA nBckMode INIT 0
DATA lContrastClr INIT .t.
// Movement DATAS
DATA nStartMRow,;
nEndMRow,;
nRowAdvance,;
nColAdvance,;
nStartTime,;
nEllapsed,;
lDown,;
lPressed,;
lMoved PROTECTED
DATA lKineticBrw AS LOGICAL INIT .T.
CLASSDATA lKinetic AS LOGICAL INIT SetKinetic()
// Datas used for Kinetic Scrolling ( used Internally )
DATA nStopRatio AS NUMERIC INIT 4
DATA nMaxRowToAdvance AS NUMERIC INIT 40
DATA nMinVelocity AS NUMERIC INIT 50
DATA lDrawSelected AS LOGICAL INIT .T.
DATA hCursorHand
CLASSDATA lRegistered AS LOGICAL // used internally
METHOD New( oWnd )
METHOD Destroy()
METHOD nAt() INLINE ::colpos( ::SelectedCol() )
METHOD EraseBkGnd( hDC ) INLINE 1
METHOD SetRDD( lAddColumns, lAutoSort, aFldNames, aRows )
METHOD SetArray( aData, lAutoSort, nColOrder, aCols, bOnSkip )
METHOD SetoDbf( oDbf, aCols, lAutoSort, lAutoCols, aRows )
METHOD SetAdo( oRs, lAddCols, lAutoOrder, aFldNames ) // ADO object
METHOD SetTree( oTree, aResource, bOnSkip )
METHOD ClearBlocks()
METHOD SetColFromADO( cnCol, lAutoOrder ) // Used internally
METHOD ArrCell( nRow, nCol, cFmt )
METHOD ArrCellSet( nRow, nCol, uNewVal )
METHOD aJustify( aJust ) SETGET // only for compatibility with TWBrowse
METHOD AddCol()
METHOD InsCol( nPos )
METHOD DelCol( nPos )
METHOD AddColumn() // See the method for parameters
METHOD SwapCols( xCol1, xCol2, lRefresh )
METHOD MoveCol( xFrom, xTo, lRefresh )
METHOD ReArrangeCols( aSeq, lRetainRest )
METHOD CreateFromCode()
METHOD CreateFromResource( nId )
METHOD SelectCol( nCol )
METHOD GoLeft( lOffset, lRefresh )
METHOD GoRight( lOffset, lRefresh )
METHOD GoLeftMost()
METHOD GoRightMost()
METHOD GoUp( nLines )
METHOD GoDown( nLines )
METHOD PageUp( nLines )
METHOD PageDown( nLines )
METHOD GoTop()
METHOD GoBottom()
METHOD HandleEvent( nMsg, nWParam, nLParam )
METHOD KeyCount() INLINE ( ::nLen := iif( !Empty( ::bKeyCount ), Eval( ::bKeyCount ), 0 ),;
iif(::oVScroll != nil , ( ::VSetRange( 1, ::nLen ), ::VUpdatePos() ), ),;
::nLen )
METHOD KeyNo( n ) SETGET
METHOD BookMark( uBm ) SETGET
METHOD Skip( n ) INLINE Eval( ::bSkip, n )
METHOD Bof() INLINE Eval( ::bBof )
METHOD Eof() INLINE Eval( ::bEof )
METHOD SaveState()
METHOD RestoreState( cInfo )
METHOD Seek( cSeek )
METHOD Select( nOperation ) // 0 -> Delete all
// 1 -> Add current key
// 2 -> Swap current key (Ctrl+lClick)
// 3 -> Tipical Shift with mouse
// 4 -> Select all
METHOD SelectAll() INLINE ::Select( 4 )
METHOD SelectNone() INLINE ::Select( 0 )
METHOD SelectOne() INLINE ( ::Select( 0 ), ::Select( 1 ) )
METHOD Adjust()
METHOD Resize( nSizeType, nWidth, nHeight ) INLINE ( ::MakeBrush(), ::ColStretch(), Super:ReSize( nSizeType, nWidth, nHeight ) )
METHOD Change( lRow ) PROTECTED
METHOD MakeTotals()
METHOD Eval( bBlock, bFor, bWhile, nNext, nRec, lRest )
METHOD Report( cTitle, lPreview, lModal, bSetUp, aGroupBy )
METHOD ToExcel( bProgress, nGroupBy, aCols )
METHOD ToCalc( bProgress, nGroupBy, nPasteMode, aSaveAs )
METHOD CurrentRow()
// The rest of the methods are used internally
METHOD Initiate( hDlg )
METHOD Display()
METHOD Paint()
METHOD Refresh( lComplete )
METHOD DelRePos()
METHOD DrawLine( lSelected, nRowLine )
METHOD FullPaint() INLINE ( ::lTransparent .or. ::lMergeVert )
METHOD GotFocus( hCtlFocus ) INLINE ( Super:GotFocus( hCtlFocus ),;
If( GetParent( hCtlFocus ) != ::hWnd, ::Super:Refresh( .f. ),) )
METHOD LostFocus( hCtlFocus ) INLINE ( Super:LostFocus( hCtlFocus ),;
If( GetParent( hCtlFocus ) != ::hWnd, ::Super:Refresh( .f. ), ) )
METHOD GetDlgCode( nLastKey )
METHOD LButtonDown( nRow, nCol, nKeyFlags )
METHOD LButtonUp( nRow, nCol, nKeyFlags )
METHOD MouseMove( nRow, nCol, nKeyFlags )
METHOD LDblClick( nRow, nCol, nKeyFlags )
METHOD RButtonDown( nRow, nCol, nKeyFlags )
METHOD MouseWheel( nKeys, nDelta, nXPos, nYPos )
METHOD HorzLine( nRow, nOperation ) // nOperation (1 Down, 2 Up, 3 Move )
METHOD MouseAtHeader( nRow, nCol )
METHOD MouseAtFooter( nRow, nCol )
METHOD MouseColPos( nCol )
METHOD MouseRowPos( nRow )
METHOD EraseData( nRow )
METHOD KeyDown( nKey, nFlags )
METHOD KeyChar( nKey, nFlags )
METHOD HScroll( nWParam, nLParam )
METHOD VScroll( nWParam, nLParam )
METHOD VUpdatePos() INLINE ::VSetPos( ::KeyNo() )
METHOD VUpdateAll() INLINE ::KeyCount()
METHOD VSetPos( nPos ) INLINE ::nVScrollPos := nPos,;
::oVScroll:SetPos( iif( ::nLen <= VSCROLL_MAXVALUE,;
nPos,;
Int( nPos * VSCROLL_MAXVALUE / ::nLen ) ) )
METHOD VThumbPos( nPos ) INLINE ::nVScrollPos := ::VGetThumbPos( nPos ),;
::oVScroll:SetPos( nPos )
METHOD VGetPos() INLINE ::nVScrollPos
METHOD VSetRange( nMin, nMax ) INLINE ::oVScroll:SetRange( Min( 1, nMin ),;
Max( Min( VSCROLL_MAXVALUE, nMax ), 2 ) )
METHOD VGetMax() INLINE ::oVScroll:nMax * iif( ::nLen <= VSCROLL_MAXVALUE,;
1,;
::nLen / VSCROLL_MAXVALUE )
METHOD VGoDown() INLINE ::VSetPos( ::nVScrollPos + 1 )
METHOD VGoUp() INLINE ::VSetPos( ::nVScrollPos - 1 )
METHOD VGetThumbPos( nPos ) INLINE iif( ::nLen <= VSCROLL_MAXVALUE,;
nPos,;
Int( nPos * ::nLen / VSCROLL_MAXVALUE ) )
METHOD VGoBottom() INLINE ::VSetPos( ::nLen )
METHOD VGoTop() INLINE ::VSetPos( 1 )
METHOD GetDisplayCols()
METHOD GetVisibleCols() // returns an array of visible (Not hided) column objects
METHOD GetDisplayColsWidth( aOptionalReturnedSizes )
METHOD ColAtPos( nPos ) INLINE ::aCols[ ::aDisplay[ MinMax( If( nPos == nil, 1, nPos ), 1, Len( ::aDisplay ) ) ] ]
METHOD ColPos( oCol )
METHOD SelectedCol() INLINE ::ColAtPos( ::nColSel )
METHOD IsDisplayPosVisible( nPos, lComplete )
METHOD LastDisplayPos()
METHOD BrwWidth() INLINE ( ::nWidth - iif( ::lVScroll , GetSysMetrics( SM_CYVSCROLL ), 0 ) )
METHOD BrwHeight() INLINE ( ::nHeight - 2 - iif( ::lHScroll, GetSysMetrics( SM_CYHSCROLL ), 0 ) )
METHOD HeaderHeight() INLINE If( ::nHeaderHeight == nil, 0, ::nHeaderHeight )
METHOD FooterHeight() INLINE If( ::nFooterHeight == nil, 0, ::nFooterHeight )
METHOD RowCount() INLINE ( If( ::nRowHeight == nil, ::Adjust(),), Int( ( ::BrwHeight() - ::HeaderHeight() - ::FooterHeight() ) / ::nRowHeight ) )
METHOD FirstRow() INLINE ::HeaderHeight()
METHOD LastRow() INLINE ::BrwHeight() - ::FooterHeight() - ::nRowHeight + 1
METHOD FooterRow() INLINE ::BrwHeight() - ::FooterHeight() + 1
METHOD DataHeight() INLINE ::nRowHeight - iif(::nRowDividerStyle > LINESTYLE_NOLINES, 1, 0) - ;
If(::nRowDividerStyle >= LINESTYLE_INSET, 1, 0)
METHOD CancelEdit()
METHOD SetColumns()
METHOD GoNextCtrl()
METHOD GoPrevCtrl() VIRTUAL
METHOD SelFont()
// new methods
METHOD FontSize( nPlus )
METHOD DrawSelect() INLINE ::DrawLine( .t. )
METHOD RefreshCurrent() INLINE ::DrawLine( .t. )
METHOD aRow INLINE ( ::aArrayData[ ::nArrayAt ] ) // to make the coding easy
METHOD oCol( cHeader )
METHOD RefreshFooters() INLINE If( Empty( ::nFooterHeight ),,AEval( ::aCols, { | oCol | oCol:RefreshFooter() } ) )
METHOD ClpRow()
METHOD Copy()
METHOD Paste( cText )
METHOD aCellCoor( nRow, nCol ) // --> { nTop, nLeft, nBottom, nRight } in pixels for cell at nVisibleRow, nVisibleCol
METHOD SetPos( nRow, nCol, lPixel )
METHOD SetBackGround( uBack, nBckMode ) // call with no paratmer to clear background
METHOD MakeBrush()
METHOD DataRect()
METHOD cBmpAdjBrush( cImage ) SETGET // Obsolete SETGET method created for compatibility
METHOD ColStretch( nStretchCol ) // used internally
// tooltip support
METHOD DestroyToolTip()
METHOD NcMouseMove( nHitTestCode, nRow, nCol )
METHOD MouseLeave()
ERROR HANDLER OnError
ENDCLASS
//----------------------------------------------------------------------------//
METHOD New( oWnd ) CLASS TXBrowse
local hBmp
DEFAULT oWnd := GetWndDefault()
::oWnd := oWnd
if oWnd != nil
/*
if oWnd:oFont == nil
? "getFont"
oWnd:GetFont()
endif
*/
::oFont := oWnd:oFont
endif
::aCols := {}
::aSelected := {}
// ::bClrHeader := {|| { GetSysColor( COLOR_BTNTEXT ), GetSysColor( COLOR_BTNFACE ) } }
::bClrHeader := {|| { GetSysColor( COLOR_BTNTEXT ), GetSysColor( COLOR_BTNFACE ), nRGB( 125, 165, 224 ), nRGB( 203, 225, 252 ) } }
::bClrFooter := ::bClrHeader
::bClrStd := {|| { CLR_BLACK, GetSysColor( COLOR_WINDOW )} }
::bClrSel := {|| { CLR_BLACK, GetSysColor( COLOR_INACTIVECAPTIONTEXT )} }
::bClrSelFocus := {|| { CLR_WHITE, GetSysColor( COLOR_HIGHLIGHT )} }
// ::bKeyCount := { || 1 }
// ::bKeyNo := { || 1 }
// ::bSkip := { || 0 }
// ::bBookMark := { || 0 }
::cCaption := ""
::cAlias := ""
::cSeek := ""
::nDataType := 0 // not set
::nTop := 0
::nLeft := 0
::nBottom := 100
::nRight := 100
::nStyle := nOr( WS_CHILD, WS_BORDER, WS_VISIBLE, WS_TABSTOP )
::SetColor( CLR_BLACK, GetSysColor( COLOR_WINDOW ) )
::lDrag := .f.
::lFocused := .f.
::lHScroll := .t.
::lVScroll := .t.
::lRecordSelector := .t.
::lAllowRowSizing := .t.
::lColDividerComplete := .f.
::lAllowColSwapping := .t.
::lAllowColHiding := .t.
::lFastEdit := .f.
::lTransparent := .f.
::nRowSel := 1
::nColSel := 1
::nColOffset := 1
::nFreeze := 0
::nCaptured := 0
::nLastEditCol := 0
::nRowDividerStyle := LINESTYLE_NOLINES
::nColDividerStyle := LINESTYLE_NOLINES
::nMarqueeStyle := MARQSTYLE_SOLIDCELL
::nMoveType := MOVE_FAST_RIGHT
::nHeaderLines := 1
::nFooterLines := 1
::nDataLines := 1
::hBmpRecSel := FwRArrow()
::lHeader := .t.
::lFooter := .f.
::lRefreshOnlyData := .f.
::l2007 := ( ColorsQty() > 256 )
::aSortBmp := {}
hBmp := FWBmpAsc()
AAdd( ::aSortBmp, { hBmp, 0, nBmpWidth( hBmp ), nBmpHeight( hBmp ), nil, .F. } )
hBmp := FWBmpDes()
AAdd( ::aSortBmp, { hBmp, 0, nBmpWidth( hBmp ), nBmpHeight( hBmp ), nil, .F. } )
::bClrGrad := { | lInvert | If( lInvert, ;
{ { 1/3, nRGB( 255, 253, 222 ), nRGB( 255, 231, 151 ) }, ;
{ 2/3, nRGB( 255, 215, 84 ), nRGB( 255, 233, 162 ) } ;
}, ;
{ { 1/3, nRGB( 219, 230, 244 ), nRGB( 207, 221, 239 ) }, ;
{ 2/3, nRGB( 201, 217, 237 ), nRGB( 231, 242, 255 ) } ;
} ) }
::nHeader := 0
::aHeaderTop := {}
return Self
//----------------------------------------------------------------------------//
METHOD Destroy() CLASS TXBrowse
local nFor
::lMoved = .F.
if ::oBrush:hBitmap != 0 .and. ValType( ::oBrush:Cargo ) == 'N' .and. ;
::oBrush:hBrush != ::oBrush:Cargo
// resized brush
DeleteObject( ::oBrush:Cargo )
endif
for nFor := 1 to Len( ::aCols )
::aCols[ nFor ]:End()
next
DeleteObject( ::hBmpRecSel )
DeleteObject( ::hBrushRecSel )
DeleteObject( ::aSortBmp[ 1 ][ 1 ] )
DeleteObject( ::aSortBmp[ 2 ][ 1 ] )
if ::hBtnShadowPen != nil
DeleteObject( ::hBtnShadowPen )
::hBtnShadowPen := nil
endif
if ::hWhitePen != nil
DeleteObject( ::hWhitePen )
::hWhitePen := nil
endif
if ::hColPen != nil
DeleteObject( ::hColPen )
::hColPen := nil
endif
if ::hRowPen != nil
DeleteObject( ::hRowPen )
::hRowPen := nil
endif
return Super:Destroy()
//----------------------------------------------------------------------------//
METHOD CreateFromCode() CLASS TXBrowse
if ::lCreated
return Self
endif
// Movement Datas
::hCursorHand = CursorOpenHand()
::lDown = .T.
::lMoved = .F.
::lPressed = .F.
::nId := ::GetNewId()
::Register( nOr( CS_VREDRAW, CS_HREDRAW, CS_DBLCLKS ) )
if ::lDesign
::nStyle := nOr( ::nStyle, WS_CLIPSIBLINGS )
endif
if ::lVScroll
::nStyle := nOr( ::nStyle, WS_VSCROLL )
endif
if ::lHScroll
::nStyle := nOr( ::nStyle, WS_HSCROLL )
endif
if ! Empty( ::oWnd:hWnd )
::Create()
if ::oFont != nil
::SetFont( ::oFont )
endif
::Initiate()
::lVisible := .t.
::oWnd:AddControl( Self )
else
::lVisible := .f.
::oWnd:DefControl( Self )
endif
return Self
//----------------------------------------------------------------------------//
METHOD CreateFromResource( nId ) CLASS TXBrowse
if ::lCreated
return Self
endif
#ifdef __XPP__
DEFAULT ::lRegistered := .f.
#endif
::nId := nId
::lDown := .t.
::lMoved := .f.
::lPressed := .f.
::Register( nOr( CS_VREDRAW, CS_HREDRAW, CS_DBLCLKS ) )
::oWnd:DefControl( Self )
return Self
//----------------------------------------------------------------------------//
METHOD Initiate( hDlg ) CLASS TXBrowse
local oBrush
if ::oBrush != nil
oBrush := ::oBrush
::oBrush := nil
endif
if hDlg != nil
Super:Initiate( hDlg )
::SetColor( CLR_BLACK, GetSysColor( COLOR_WINDOW ) )
endif
if ::lVScroll .or. lAnd( GetWindowLong( ::hWnd, GWL_STYLE ), WS_VSCROLL )
DEFINE SCROLLBAR ::oVScroll VERTICAL OF Self
endif
if ::lHScroll .or. lAnd( GetWindowLong( ::hWnd, GWL_STYLE ), WS_HSCROLL )
DEFINE SCROLLBAR ::oHScroll HORIZONTAL OF Self
endif
if Empty( ::nDataType ) .or. Empty( ::aCols )
if ! Empty( ::aArrayData )
if lAnd( ::nDataType, DATATYPE_RDD )
::SetRDD( .t., nil, nil, ::aArrayData )
elseif lAnd( ::nDataType, DATATYPE_ODBF ) .and. !Empty( ::oDbf )
::SetODbf( ::oDbf, nil, nil, .t., ::aArrayData )
else
::SetArray( ::aArrayData )
endif
elseif ! Empty( ::oRs )
::SetADO( ::oRs )
elseif ! Empty ( ::oDbf )
::SetoDbf( ::oDbf,,, Empty( ::aCols ) )
elseif !Empty( ::cAlias ) .and. ( ::cAlias )->( Used() ) // .or. !Empty( Alias() )
::SetRDD()
endif
if Empty( ::nDataType ) // Empty( ::cAlias )
// no rdd open and no datasource
::bBof := ::bEof := { || .t. }
::bKeyCount := ::bKeyNo := ::bBookMark := { || 0 }
endif
endif
if ( !Empty( ::cAlias ) .and. ( ::cAlias )->( Used() ) ) .and. ( Empty( ::bKeyCount ) .or. Empty( ::bKeyNo ) )
::SetRdd()
endif
if Empty( ::aCols )
::AddCol():bStrData := { || "" }
::aCols[ 1 ]:cHeader := "A"
::nStretchCol := 1
endif
::lCreated := .t.
if ::oFont != nil
::SetFont( ::oFont )
else
::GetFont()
endif
if oBrush != nil
if ::oBrush != nil
::oBrush:End()
endif
::oBrush = oBrush
endif
::Adjust()
::MakeBrush()
return Self
//----------------------------------------------------------------------------//
METHOD Adjust() CLASS TXBrowse
local oCol, nFor, nLen, nHeight, nStyle
nLen := Len( ::aCols )
nHeight := 0
::GetDC()
for each oCol in ::aCols // nFor := 1 to nLen
oCol:Adjust() // ::aCols[ nFor ]:Adjust()
next
::ReleaseDC()
if ::lHeader .and. ::nHeaderHeight == nil
for nFor := 1 to nLen
nHeight := Max( nHeight, ::aCols[ nFor ]:HeaderHeight() )
next
::nHeaderHeight := ( nHeight * ::nHeaderLines ) + ROW_EXTRAHEIGHT + 3 // lines to give 3d look
endif
if ::lFooter .and. ::nFooterHeight == nil
nHeight := 0
for nFor := 1 to nLen
nHeight := Max( nHeight, ::aCols[ nFor ]:FooterHeight() )
next
::nFooterHeight := ( nHeight * ::nFooterLines ) + ROW_EXTRAHEIGHT + 3 // lines to give 3d look
endif
if ::nRowHeight == nil
nHeight := 0
for nFor := 1 to nLen
nHeight := Max( nHeight, ::aCols[ nFor ]:DataHeight() )
next
::nRowHeight := ( nHeight * ::nDataLines ) + ROW_EXTRAHEIGHT //+ 2 // lines to give 3d look
if ::nRowDividerStyle != LINESTYLE_NOLINES
::nRowHeight++
endif
if ::nRowDividerStyle >= LINESTYLE_INSET
::nRowHeight++
endif
endif
DEFAULT ::hBtnShadowPen := CreatePen( PS_SOLID, 1, GetSysColor( COLOR_BTNSHADOW ) ),;
::hWhitePen := CreatePen( PS_SOLID, 1, GetSysColor( COLOR_BTNHIGHLIGHT ) )
if ::hColPen != nil
DeleteObject( ::hColPen )
::hColPen := nil
endif
nStyle := ::nColDividerStyle
do case
case nStyle == LINESTYLE_BLACK .or. nStyle == LINESTYLE_RAISED .or. nStyle == LINESTYLE_INSET
::hColPen := CreatePen( PS_SOLID, 1, CLR_BLACK )
case nStyle == LINESTYLE_DARKGRAY
::hColPen := CreatePen( PS_SOLID, 1, CLR_GRAY )
case nStyle == LINESTYLE_FORECOLOR
::hColPen := CreatePen( PS_SOLID, 1, ::nClrText )
case nStyle == LINESTYLE_LIGHTGRAY
::hColPen := CreatePen( PS_SOLID, 1, CLR_LIGHTGRAY )
end case
nStyle := ::nRowDividerStyle
do case
case nStyle == LINESTYLE_BLACK .or. nStyle == LINESTYLE_RAISED .or. nStyle == LINESTYLE_INSET
::hRowPen := CreatePen( PS_SOLID, 1, CLR_BLACK )
case nStyle == LINESTYLE_DARKGRAY
::hRowPen := CreatePen( PS_SOLID, 1, CLR_GRAY )
case nStyle == LINESTYLE_FORECOLOR
::hRowPen := CreatePen( PS_SOLID, 1, ::nClrText )
case nStyle == LINESTYLE_LIGHTGRAY
::hRowPen := CreatePen( PS_SOLID, 1, CLR_LIGHTGRAY )
end case
if ::nRecSelColor == nil
::nRecSelColor := If( ::l2007, nRGB( 231, 242, 255 ), Eval( ::bClrHeader )[ 2 ] )
endif
::hBrushRecSel := CreateSolidBrush( ::nRecSelColor )
::GetDisplayCols()
::KeyCount()
if ::nMarqueeStyle == MARQSTYLE_HIGHLROWMS
::Select(1)
endif
if ::oVScroll != nil
::VSetRange( 1, ::nLen )
::VSetPos( ::KeyNo() )
endif
::ColStretch()
return nil
//----------------------------------------------------------------------------//
METHOD Change( lRow ) CLASS TXBrowse
if ::bChange != nil
DEFAULT lRow := .t.
if lRow .or. ::lColChangeNotify
Eval( ::bChange, Self, lRow )
endif
endif
return nil
//----------------------------------------------------------------------------//
METHOD Refresh( lComplete ) CLASS TXBrowse
local nKeyNo
DEFAULT lComplete := .F.
::KeyCount()
if lComplete
::nRowSel = 1
::nArrayAt = Min( 1, ::nLen )
else
nKeyNo = ::KeyNo()
::nArrayAt = Min( ::nArrayAt, ::nLen )
::nRowSel = Max( 1, Min( ::nRowSel, ::nLen ) )
::nRowSel = Max( 1, Min( ::nRowSel, nKeyNo ) ) // bKeyNo for ADS is approx. can be zero also
::DelRepos() // if the row is deleted for RDD
if nKeyNo >= ::nLen .and. ::nLen > 1
::nRowSel := Min( nKeyNo, ::RowCount() )
endif
/*
if nKeyNo <= ::RowCount()
::nRowSel := nKeyNo
endif
*/
if ::nArrayAt == 0 .and. ::nLen > 0
// when one or more rows are added to a blank array
::nArrayAt := 1
endif
endif
::GetDisplayCols()
return Super:Refresh( .T. )
//----------------------------------------------------------------------------//
METHOD DelRepos() CLASS TXBrowse
local lRepos := .f.
local cFilter, bFilter
// if lAnd( ::nDataType, DATATYPE_RDD ) .and. ::nLen > 0
if ( ::nDataType == DATATYPE_RDD ) .and. ::nLen > 0
if ( Set( _SET_DELETED ) .and. ( ::cAlias )->( Deleted() ) ) ;
.or. ;
( ! Empty( cFilter := ( ::cAlias )->( dbFilter() ) ) .and. ;
Type( cFilter ) == 'L' .and. ;
! &cFilter )
( ::cAlias )->( dbSkip( 1 ) )
if ( ::cAlias )->( eof() )
( ::cAlias )->( DbGoBottom() )
endif
lRepos := .t.
endif
endif
return lRepos
//----------------------------------------------------------------------------//
METHOD Display() CLASS TXBrowse
if !::lCreated
return nil
endif
::BeginPaint()
::Paint()