1 | //kt -- Modified with SourceScanner on 8/8/2007
|
---|
2 | unit fPCEBaseGrid;
|
---|
3 |
|
---|
4 | interface
|
---|
5 |
|
---|
6 | uses
|
---|
7 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
|
---|
8 | fPCEBase, ComCtrls, StdCtrls, ORCtrls, ExtCtrls, Buttons, ORFn, DKLang;
|
---|
9 |
|
---|
10 | type
|
---|
11 | TfrmPCEBaseGrid = class(TfrmPCEBase)
|
---|
12 | pnlGrid: TPanel;
|
---|
13 | lbGrid: TORListBox;
|
---|
14 | hcGrid: THeaderControl;
|
---|
15 | procedure FormCreate(Sender: TObject);
|
---|
16 | procedure hcGridSectionResize(HeaderControl: THeaderControl;
|
---|
17 | Section: THeaderSection);
|
---|
18 | procedure pnlGridResize(Sender: TObject);
|
---|
19 | private
|
---|
20 | FSel: string;
|
---|
21 | FGridHeaderSyncing: boolean;
|
---|
22 | function GetGridIndex: integer;
|
---|
23 | procedure SetGridIndex(const Value: integer);
|
---|
24 | protected
|
---|
25 | FSectionGap: integer;
|
---|
26 | procedure UpdateControls; virtual;
|
---|
27 | procedure SaveGridSelected;
|
---|
28 | procedure RestoreGridSelected;
|
---|
29 | public
|
---|
30 | procedure SyncGridHeader(FromHeader: boolean);
|
---|
31 | procedure SyncGridData;
|
---|
32 | procedure ClearGrid;
|
---|
33 | property GridIndex: integer read GetGridIndex write SetGridIndex;
|
---|
34 | end;
|
---|
35 |
|
---|
36 | var
|
---|
37 | frmPCEBaseGrid: TfrmPCEBaseGrid;
|
---|
38 |
|
---|
39 | implementation
|
---|
40 |
|
---|
41 | {$R *.DFM}
|
---|
42 |
|
---|
43 | const
|
---|
44 | JustificationGap = 5;
|
---|
45 |
|
---|
46 | procedure TfrmPCEBaseGrid.FormCreate(Sender: TObject);
|
---|
47 | begin
|
---|
48 | inherited;
|
---|
49 | lbGrid.Color := ReadOnlyColor;
|
---|
50 | lbGrid.ItemTipColor := ReadOnlyColor;
|
---|
51 | FSectionGap := 15;
|
---|
52 | SyncGridHeader(TRUE);
|
---|
53 | end;
|
---|
54 |
|
---|
55 | procedure TfrmPCEBaseGrid.SyncGridHeader(FromHeader: boolean);
|
---|
56 | var
|
---|
57 | i, w, wd, wp, Gap: integer;
|
---|
58 | txt: string;
|
---|
59 |
|
---|
60 | begin
|
---|
61 | if(not FGridHeaderSyncing) then
|
---|
62 | begin
|
---|
63 | Gap := JustificationGap;
|
---|
64 | FGridHeaderSyncing := TRUE;
|
---|
65 | try
|
---|
66 | if(FromHeader) then
|
---|
67 | begin
|
---|
68 | txt := '';
|
---|
69 | w := 0;
|
---|
70 | for i := 0 to hcGrid.Sections.Count-2 do
|
---|
71 | begin
|
---|
72 | if(i > 0) then
|
---|
73 | txt := txt + ',';
|
---|
74 | inc(w,(hcGrid.Sections[i].Width div 2)*2);
|
---|
75 | txt := txt + IntToStr(w + Gap);
|
---|
76 | Gap := 0;
|
---|
77 | end;
|
---|
78 | lbGrid.TabPositions := txt;
|
---|
79 | end
|
---|
80 | else
|
---|
81 | begin
|
---|
82 | txt := lbGrid.TabPositions;
|
---|
83 | wd := 0;
|
---|
84 | for i := 0 to hcGrid.Sections.Count-2 do
|
---|
85 | begin
|
---|
86 | wp := StrToIntDef(Piece(txt,',',i+1),hcGrid.Sections[i].MinWidth);
|
---|
87 | w := wp - wd;
|
---|
88 | hcGrid.Sections[i].Width := w - Gap;
|
---|
89 | Gap := 0;
|
---|
90 | wd := wp;
|
---|
91 | end;
|
---|
92 | end;
|
---|
93 | w := 0;
|
---|
94 | for i := 0 to hcGrid.Sections.Count-2 do
|
---|
95 | inc(w,hcGrid.Sections[i].Width);
|
---|
96 | hcGrid.Sections[hcGrid.Sections.Count-1].Width := pnlGrid.Width - w;
|
---|
97 | finally
|
---|
98 | FGridHeaderSyncing := FALSE;
|
---|
99 | end;
|
---|
100 | end;
|
---|
101 | end;
|
---|
102 |
|
---|
103 | procedure TfrmPCEBaseGrid.hcGridSectionResize(
|
---|
104 | HeaderControl: THeaderControl; Section: THeaderSection);
|
---|
105 | begin
|
---|
106 | inherited;
|
---|
107 | SyncGridHeader(TRUE);
|
---|
108 | end;
|
---|
109 |
|
---|
110 | procedure TfrmPCEBaseGrid.pnlGridResize(Sender: TObject);
|
---|
111 | begin
|
---|
112 | inherited;
|
---|
113 | SyncGridHeader(TRUE);
|
---|
114 | end;
|
---|
115 |
|
---|
116 | procedure TfrmPCEBaseGrid.SyncGridData;
|
---|
117 | var
|
---|
118 | tp, ltp, i, j, tlen: integer;
|
---|
119 | max: array[0..9] of integer; // more than 10 header sections will cause this to explode
|
---|
120 | tmp: string;
|
---|
121 |
|
---|
122 | begin
|
---|
123 | if(lbGrid.Items.Count > 0) then
|
---|
124 | begin
|
---|
125 | for j := 0 to hcGrid.Sections.Count-2 do max[j] := 0;
|
---|
126 | for i := 0 to lbGrid.Items.Count-1 do
|
---|
127 | begin
|
---|
128 | tmp := lbGrid.Items[i];
|
---|
129 | for j := 0 to hcGrid.Sections.Count-2 do
|
---|
130 | begin
|
---|
131 | tlen := Canvas.TextWidth(Piece(tmp,U,j+1)) + FSectionGap;
|
---|
132 | if(max[j] < tlen) then
|
---|
133 | max[j] := tlen;
|
---|
134 | end;
|
---|
135 | end;
|
---|
136 | ltp := 0;
|
---|
137 | tmp := lbGrid.TabPositions;
|
---|
138 | for i := 0 to hcGrid.Sections.Count-2 do
|
---|
139 | begin
|
---|
140 | if(max[i] < hcGrid.Sections[i].MinWidth) then
|
---|
141 | max[i] := hcGrid.Sections[i].MinWidth;
|
---|
142 | tp := StrToIntDef(Piece(tmp,',',i+1),0);
|
---|
143 | tlen := tp - ltp;
|
---|
144 | ltp := tp;
|
---|
145 | if(max[i] < tlen) then
|
---|
146 | max[i] := tlen;
|
---|
147 | end;
|
---|
148 | for i := 1 to hcGrid.Sections.Count-2 do
|
---|
149 | inc(max[i], max[i-1]);
|
---|
150 | tmp := '';
|
---|
151 | for i := 0 to hcGrid.Sections.Count-2 do
|
---|
152 | tmp := tmp + ',' + inttostr(max[i]);
|
---|
153 | delete(tmp,1,1);
|
---|
154 | if(lbGrid.TabPositions <> tmp) then
|
---|
155 | begin
|
---|
156 | SaveGridSelected;
|
---|
157 | lbGrid.TabPositions := tmp;
|
---|
158 | RestoreGridSelected;
|
---|
159 | end;
|
---|
160 | SyncGridHeader(FALSE);
|
---|
161 | end;
|
---|
162 | end;
|
---|
163 |
|
---|
164 | function TfrmPCEBaseGrid.GetGridIndex: integer;
|
---|
165 | var
|
---|
166 | i: integer;
|
---|
167 |
|
---|
168 | begin
|
---|
169 | Result := -1;
|
---|
170 | if(lbGrid.SelCount > 0) then
|
---|
171 | begin
|
---|
172 | for i := 0 to lbGrid.Items.Count-1 do
|
---|
173 | if(lbGrid.Selected[i]) then
|
---|
174 | begin
|
---|
175 | Result := i;
|
---|
176 | exit;
|
---|
177 | end;
|
---|
178 | end;
|
---|
179 | end;
|
---|
180 |
|
---|
181 | procedure TfrmPCEBaseGrid.SetGridIndex(const Value: integer);
|
---|
182 | var
|
---|
183 | i: integer;
|
---|
184 |
|
---|
185 | begin
|
---|
186 | for i := 0 to lbGrid.Items.Count-1 do
|
---|
187 | lbGrid.Selected[i] := (i = Value);
|
---|
188 | UpdateControls;
|
---|
189 | end;
|
---|
190 |
|
---|
191 | procedure TfrmPCEBaseGrid.ClearGrid;
|
---|
192 | var
|
---|
193 | i: integer;
|
---|
194 |
|
---|
195 | begin
|
---|
196 | if lbGrid.SelCount > 0 then
|
---|
197 | begin
|
---|
198 | for i := 0 to lbGrid.Items.Count-1 do
|
---|
199 | lbGrid.Selected[i] := FALSE;
|
---|
200 | end;
|
---|
201 | UpdateControls;
|
---|
202 | end;
|
---|
203 |
|
---|
204 | procedure TfrmPCEBaseGrid.UpdateControls;
|
---|
205 | begin
|
---|
206 | end;
|
---|
207 |
|
---|
208 | procedure TfrmPCEBaseGrid.RestoreGridSelected;
|
---|
209 | var
|
---|
210 | i: integer;
|
---|
211 |
|
---|
212 | begin
|
---|
213 | for i := 0 to lbGrid.Items.Count-1 do
|
---|
214 | lbGrid.Selected[i] := (copy(FSel,i+1,1) = BOOLCHAR[TRUE]);
|
---|
215 | end;
|
---|
216 |
|
---|
217 | procedure TfrmPCEBaseGrid.SaveGridSelected;
|
---|
218 | var
|
---|
219 | i: integer;
|
---|
220 | begin
|
---|
221 | FSel := '';
|
---|
222 | for i := 0 to lbGrid.Items.Count-1 do
|
---|
223 | FSel := FSel + BOOLCHAR[lbGrid.Selected[i]];
|
---|
224 | end;
|
---|
225 |
|
---|
226 | end.
|
---|