2 TfmLVColumnsEditor = class(TForm)
\r
10 chkStayOnTop: TCheckBox;
\r
11 lvColumns: TListView;
\r
12 procedure FormResize(Sender: TObject);
\r
13 procedure FormShow(Sender: TObject);
\r
14 procedure chkStayOnTopClick(Sender: TObject);
\r
15 procedure btAddClick(Sender: TObject);
\r
16 procedure btDelClick(Sender: TObject);
\r
17 procedure btUpClick(Sender: TObject);
\r
18 procedure btDownClick(Sender: TObject);
\r
19 procedure FormKeyDown(Sender: TObject; var Key: Word;
\r
20 Shift: TShiftState);
\r
21 procedure lvColumnsSelectItem(Sender: TObject; Item: TListItem;
\r
23 {$IFDEF VER90} {$DEFINE OLDDELPHI} {$ENDIF}
\r
24 {$IFDEF VER100} {$DEFINE OLDDELPHI} {$ENDIF}
\r
26 procedure lvColumnsChange(Sender: TObject; Item: TListItem; Change: TItemChange);
\r
28 procedure lvColumnsEdited(Sender: TObject; Item: TListItem;
\r
30 procedure FormDestroy(Sender: TObject);
\r
31 procedure FormClose(Sender: TObject; var Action: TCloseAction);
\r
33 { Private declarations }
\r
34 FListView: TComponent;
\r
35 procedure SetListView(const Value: TComponent);
\r
36 procedure AdjustButtons;
\r
39 { Public declarations }
\r
40 property ListView: TComponent read FListView write SetListView;
\r
41 procedure MakeActive( SelectAny: Boolean );
\r
42 constructor Create( AOwner: TComponent ); override;
\r
46 fmLVColumnsEditor: TfmLVColumnsEditor;
\r
50 uses mirror, mckCtrls, mckObjs;
\r
52 procedure TfmLVColumnsEditor.AdjustButtons;
\r
55 LI := lvColumns.Selected;
\r
58 btAdd.Enabled := lvColumns.Items.Count = 0;
\r
59 btDel.Enabled := FALSE;
\r
60 btUp.Enabled := FALSE;
\r
61 btDown.Enabled := FALSE;
\r
65 btAdd.Enabled := TRUE;
\r
66 btDel.Enabled := TRUE;
\r
67 btUp.Enabled := LI.Index > 0;
\r
68 btDown.Enabled := LI.Index < lvColumns.Items.Count - 1;
\r
72 procedure TfmLVColumnsEditor.FormResize(Sender: TObject);
\r
74 lvColumns.Columns[ 0 ].Width := lvColumns.ClientWidth;
\r
77 procedure TfmLVColumnsEditor.MakeActive(SelectAny: Boolean);
\r
81 Col: TKOLListViewColumn;
\r
83 if lvColumns.Items.Count > 0 then
\r
84 if lvColumns.Selected = nil then
\r
86 lvColumns.Selected := lvColumns.Items[ 0 ];
\r
87 if lvColumns.Selected <> nil then
\r
89 Col := lvColumns.Selected.Data;
\r
90 F := (FListView as TKOLListView).Owner as TForm;
\r
93 {$IFDEF _D6orHigher}
\r
94 F.Designer.QueryInterface(IFormDesigner,D);
\r
99 if QueryFormDesigner( D, FD ) then
\r
101 RemoveSelection( FD );
\r
102 FD.SelectComponent( Col );
\r
109 procedure TfmLVColumnsEditor.SetListView(const Value: TComponent);
\r
110 var LV: TKOLListView;
\r
112 FListView := Value;
\r
113 LV := FListView as TKOLListView;
\r
114 Caption := LV.Name + ' columns';
\r
117 procedure TfmLVColumnsEditor.FormShow(Sender: TObject);
\r
120 Col: TKOLListViewColumn;
\r
123 lvColumns.Items.BeginUpdate;
\r
126 lvColumns.Items.Clear;
\r
127 if FListView <> nil then
\r
128 if FListView is TKOLListView then
\r
130 LV := FListView as TKOLListView;
\r
131 for I := 0 to LV.Cols.Count-1 do
\r
133 LI := lvColumns.Items.Add;
\r
134 Col := LV.Cols[ I ];
\r
136 LI.Caption := Col.Caption;
\r
141 lvColumns.Items.EndUpdate;
\r
145 procedure TfmLVColumnsEditor.chkStayOnTopClick(Sender: TObject);
\r
147 if chkStayOnTop.Checked then
\r
148 FormStyle := fsStayOnTop
\r
150 FormStyle := fsNormal;
\r
153 procedure TfmLVColumnsEditor.btAddClick(Sender: TObject);
\r
155 Col: TKOLListViewColumn;
\r
160 if FListView = nil then Exit;
\r
161 if not( FListView is TKOLListView ) then Exit;
\r
162 LV := FListView as TKOLListView;
\r
163 LI := lvColumns.Selected;
\r
166 Col := TKOLListViewColumn.Create( LV );
\r
167 LI := lvColumns.Items.Add;
\r
172 if LI.Index >= lvColumns.Items.Count then
\r
173 Col := TKOLListViewColumn.Create( LV )
\r
176 Col := TKOLListViewColumn.Create( LV );
\r
177 LV.Cols.Move( lvColumns.Items.Count, LI.Index + 1 );
\r
179 LI := lvColumns.Items.Insert( LI.Index + 1 );
\r
183 if LV.Owner is TForm then
\r
184 for I := 1 to MaxInt do
\r
186 S := 'Col' + IntToStr( I );
\r
187 if (LV.Owner as TForm).FindComponent( S ) = nil then
\r
188 if LV.FindComponent( S ) = nil then
\r
194 if LV.HasOrderedColumns then
\r
195 Col.LVColOrder := LI.Index;
\r
196 lvColumns.Selected := nil;
\r
197 lvColumns.Selected := LI;
\r
198 lvColumns.ItemFocused := LI;
\r
199 LI.MakeVisible( FALSE );
\r
203 procedure TfmLVColumnsEditor.btDelClick(Sender: TObject);
\r
206 Col: TKOLListViewColumn;
\r
208 LI := lvColumns.Selected;
\r
215 if J >= lvColumns.Items.Count then
\r
219 lvColumns.Selected := lvColumns.Items[ J ];
\r
220 lvColumns.ItemFocused := lvColumns.Selected;
\r
224 if lvColumns.Items.Count = 0 then
\r
228 procedure TfmLVColumnsEditor.btUpClick(Sender: TObject);
\r
229 var LI, LI1: TListItem;
\r
232 Col: TKOLListViewColumn;
\r
234 if FListView = nil then Exit;
\r
235 if not(FListView is TKOLListView) then Exit;
\r
236 LV := FListView as TKOLListView;
\r
237 LI := lvColumns.Selected;
\r
238 if LI = nil then Exit;
\r
240 LI1 := lvColumns.Items.Insert( I );
\r
241 LI1.Caption := LI.Caption;
\r
242 LI1.Data := LI.Data;
\r
243 LV.Cols.Move( I + 1, I );
\r
245 lvColumns.Selected := LI1;
\r
246 lvColumns.ItemFocused := LI1;
\r
248 if Col.LVColOrder = LI1.Index + 1 then
\r
249 Col.LVColOrder := LI1.Index;
\r
253 procedure TfmLVColumnsEditor.btDownClick(Sender: TObject);
\r
254 var LI, LI1: TListItem;
\r
256 Col: TKOLListViewColumn;
\r
258 if FListView = nil then Exit;
\r
259 if not(FListView is TKOLListView) then Exit;
\r
260 LV := FListView as TKOLListView;
\r
261 LI := lvColumns.Selected;
\r
262 if LI = nil then Exit;
\r
263 LV.Cols.Move( LI.Index, LI.Index + 1 );
\r
264 LI1 := lvColumns.Items.Insert( LI.Index + 2 );
\r
265 LI1.Caption := LI.Caption;
\r
266 LI1.Data := LI.Data;
\r
268 lvColumns.Selected := LI1;
\r
269 lvColumns.ItemFocused := LI1;
\r
271 if Col.LVColOrder = LI1.Index - 1 then
\r
272 Col.LVColOrder := LI1.Index;
\r
276 procedure TfmLVColumnsEditor.FormKeyDown(Sender: TObject; var Key: Word;
\r
277 Shift: TShiftState);
\r
280 VK_INSERT: btAdd.Click;
\r
281 VK_DELETE: if not lvColumns.IsEditing then btDel.Click;
\r
282 VK_RETURN: if (ActiveControl = lvColumns) and not lvColumns.IsEditing and
\r
283 (lvColumns.Selected <> nil) then
\r
284 lvColumns.Selected.EditCaption;
\r
285 VK_UP: if (GetKeyState( VK_CONTROL ) < 0) then
\r
288 VK_DOWN: if (GetKeyState( VK_CONTROL ) < 0) then
\r
296 procedure TfmLVColumnsEditor.lvColumnsSelectItem(Sender: TObject;
\r
297 Item: TListItem; Selected: Boolean);
\r
300 MakeActive( FALSE );
\r
304 procedure TfmLVColumnsEditor.lvColumnsChange(Sender: TObject; Item: TListItem; Change: TItemChange);
\r
306 if lvColumns.Selected <> nil then
\r
307 MakeActive( FALSE );
\r
311 procedure TfmLVColumnsEditor.lvColumnsEdited(Sender: TObject;
\r
312 Item: TListItem; var S: String);
\r
313 var Col: TKOLListViewColumn;
\r
315 if Item = nil then Exit;
\r
318 MakeActive( FALSE );
\r
321 procedure TfmLVColumnsEditor.FormDestroy(Sender: TObject);
\r
322 var LV: TKOLListView;
\r
324 if FListView = nil then Exit;
\r
325 LV := FListView as TKOLListView;
\r
326 LV.ActiveDesign := nil;
\r
329 procedure TfmLVColumnsEditor.FormClose(Sender: TObject;
\r
330 var Action: TCloseAction);
\r
332 Rpt( 'Closing Listview columns editor' );
\r
334 modalResult := mrOK;
\r
337 procedure TfmLVColumnsEditor.SelectLV;
\r
342 if FListView <> nil then
\r
344 F := (FListView as TKOLListView).Owner as TForm;
\r
347 Rpt( 'Form found: ' + F.Name );
\r
349 {$IFDEF _D6orHigher} //
\r
350 F.Designer.QueryInterface(IFormDesigner,D); //
\r
357 Rpt( 'IDesigner interface returned' );
\r
358 if QueryFormDesigner( D, FD ) then
\r
360 Rpt( 'IFormDesigner interface quered' );
\r
362 RemoveSelection( FD );
\r
363 FD.SelectComponent( FListView );
\r
365 Rpt( 'EXCEPTION *** Could not clear selection!' )
\r
374 constructor TfmLVColumnsEditor.Create(AOwner: TComponent);
\r
381 HorzScrollBar.Visible := False;
\r
382 VertScrollBar.Visible := False;
\r
383 BorderIcons := [biSystemMenu];
\r
384 Caption := 'Columns';
\r
385 //Color := clBtnFace;
\r
386 //Font.Charset := DEFAULT_CHARSET;
\r
387 //Font.Color := clWindowText;
\r
388 //Font.Height := -11;
\r
389 Font.Name := 'MS Sans Serif';
\r
390 //Font.Style := [];
\r
391 KeyPreview := True;
\r
392 //OldCreateOrder := False;
\r
394 OnClose := FormClose;
\r
395 OnDestroy := FormDestroy;
\r
396 OnKeyDown := FormKeyDown;
\r
397 OnResize := FormResize;
\r
398 OnShow := FormShow;
\r
399 PixelsPerInch := 96;
\r
400 //TextHeight := 13;
\r
401 pnButtons := TPanel.Create( Self );
\r
410 BevelOuter := bvNone;
\r
412 btAdd := TButton.Create( pnButtons );
\r
415 Parent := pnButtons;
\r
422 OnClick := btAddClick;
\r
424 btDel := TButton.Create( pnButtons );
\r
427 Parent := pnButtons;
\r
432 Caption := '&Delete';
\r
434 OnClick := btDelClick;
\r
436 btUp := TButton.Create( pnButtons );
\r
439 Parent := pnButtons;
\r
446 OnClick := btUpClick;
\r
448 btDown := TButton.Create( pnButtons );
\r
451 Parent := pnButtons;
\r
456 Caption := '&Down';
\r
458 OnClick := btDownClick;
\r
460 chkStayOnTop := TCheckBox.Create( pnButtons );
\r
461 with chkStayOnTop do
\r
463 Parent := pnButtons;
\r
468 Caption := 'Stay On &Top';
\r
470 OnClick := chkStayOnTopClick;
\r
473 pnView := TPanel.Create( Self );
\r
482 BevelOuter := bvNone;
\r
485 lvColumns := TListView.Create( pnView );
\r
495 HideSelection := False;
\r
499 ShowColumnHeaders := False;
\r
501 ViewStyle := vsReport;
\r
502 OnEdited := lvColumnsEdited;
\r
504 OnChange := lvColumnsChange;
\r
506 OnSelectItem := lvColumnsSelectItem;
\r