source: cprs/trunk/CPRS-Chart/Encounter/fPCEBaseGrid.pas@ 1560

Last change on this file since 1560 was 829, checked in by Kevin Toppenberg, 14 years ago

Upgrade to version 27

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