[15] | 1 | unit MultiColumnListBox;
|
---|
| 2 |
|
---|
| 3 | interface
|
---|
| 4 |
|
---|
| 5 | uses
|
---|
| 6 | Messages, SysUtils, Classes, Graphics, Forms, Dialogs,
|
---|
| 7 | StdCtrls, ComCtrls, CustomHeaderControl; // menus for SPCC v2.5+
|
---|
| 8 |
|
---|
| 9 | const
|
---|
| 10 | mclbImageMarker = #11;
|
---|
| 11 |
|
---|
| 12 | type
|
---|
| 13 | TMultiColumnListBox = class(TControl)
|
---|
| 14 | protected
|
---|
| 15 | FHeader: TCustomHeaderControl;
|
---|
| 16 | FLIstBox: TListBox;
|
---|
| 17 | FImageList: TImageList;
|
---|
| 18 |
|
---|
| 19 | FSavedSelectedObject: TObject;
|
---|
| 20 |
|
---|
| 21 | FBorderStyle: TBorderStyle;
|
---|
| 22 | Procedure SetBorderStyle( NewValue: TBorderStyle );
|
---|
| 23 |
|
---|
| 24 | function GetHeaderPenColor: TColor;
|
---|
| 25 | procedure SetHeaderPenColor( NewValue: TColor );
|
---|
| 26 | function GetListPenColor: TColor;
|
---|
| 27 | procedure SetListPenColor( NewValue: TColor );
|
---|
| 28 |
|
---|
| 29 | function GetEnabled: boolean; //override;
|
---|
| 30 | function GetExtendedSelect: boolean;
|
---|
| 31 | function GetHeaderFont: TFont;
|
---|
| 32 | function GetHeaderHeight: integer;
|
---|
| 33 | function GetHeaderParentFont: boolean;
|
---|
| 34 | function GetItemHeight: integer;
|
---|
| 35 | function GetListFont: TFont;
|
---|
| 36 | function GetListParentFont: boolean;
|
---|
| 37 | function GetMultiSelect: boolean;
|
---|
| 38 | function GetParentColor: boolean;
|
---|
| 39 | function GetParentShowHint: boolean;
|
---|
[458] | 40 | function GetThePopupMenu: TPopupMenu;
|
---|
[15] | 41 | function GetShowHint: boolean;
|
---|
| 42 | // procedure SetEnabled(NewState:Boolean); override;
|
---|
| 43 | procedure SetExtendedSelect(const Value: boolean);
|
---|
| 44 | procedure SetHeaderFont(const Value: TFont);
|
---|
| 45 | procedure SetHeaderHeight(const Value: integer);
|
---|
| 46 | procedure SetHeaderParentFont(const Value: boolean);
|
---|
| 47 | procedure SetItemHeight(const Value: integer);
|
---|
| 48 | procedure SetListFont(const Value: TFont);
|
---|
| 49 | procedure SetListParentFont(const Value: boolean);
|
---|
| 50 | procedure SetMultiSelect(const Value: boolean);
|
---|
| 51 | procedure SetParentShowHint(const Value: boolean);
|
---|
| 52 | procedure SetPopupMenu(const Value: TPopupMenu);
|
---|
| 53 | procedure SetShowHint(const Value: boolean);
|
---|
| 54 | procedure SetSelectedObject(const Value: TObject);
|
---|
| 55 | function GetOnClick: TNotifyEvent;
|
---|
| 56 | procedure SetOnClick(const Value: TNotifyEvent);
|
---|
| 57 | function GetOnDblClick: TNotifyEvent;
|
---|
| 58 | procedure SetOnDblClick(const Value: TNotifyEvent);
|
---|
| 59 | procedure SetSelectedItem(const Value: string);
|
---|
| 60 | function GetTopObject: TObject;
|
---|
| 61 | procedure SetTopObject(const Value: TObject);
|
---|
| 62 |
|
---|
| 63 | function GetItems: TStrings;
|
---|
| 64 | procedure SetItems( Items: TStrings );
|
---|
| 65 | function GetHeaderSections: TCustomHeaderSections;
|
---|
| 66 | procedure SetHeaderSections( Sections: TCustomHeaderSections );
|
---|
| 67 | function GetSelectedItem: string;
|
---|
| 68 | function GetSelectedObject: TObject;
|
---|
| 69 | function GetItemIndex: integer;
|
---|
| 70 | procedure SetItemIndex( const Value: integer );
|
---|
| 71 | procedure SetImageList( ImageList: TImageList );
|
---|
| 72 | procedure Notification( AComponent: TComponent;
|
---|
| 73 | Operation: TOperation); override;
|
---|
| 74 |
|
---|
| 75 | procedure SetOnItemFocus( Value: TItemFocusEvent );
|
---|
| 76 | function GetOnItemFocus: TItemFocusEvent;
|
---|
| 77 | function GetOnItemSelect: TItemSelectEvent;
|
---|
| 78 | procedure SetOnItemSelect( Value: TItemSelectEvent );
|
---|
| 79 |
|
---|
| 80 | function GetOnEnter: TNotifyEvent;
|
---|
| 81 | procedure SetOnEnter( Value: TNotifyEvent );
|
---|
| 82 | function GetOnExit: TNotifyEvent;
|
---|
| 83 | procedure SetOnExit( Value: TNotifyEvent );
|
---|
| 84 |
|
---|
| 85 | procedure SetSelected( Index: longint; Value: boolean );
|
---|
| 86 | function GetSelected( Index: longint ): boolean;
|
---|
| 87 |
|
---|
| 88 | Procedure SetColor(NewColor:TColor); Override;
|
---|
| 89 |
|
---|
| 90 | procedure Layout;
|
---|
| 91 | procedure DrawListBoxItem( Sender: TObject;
|
---|
| 92 | Index: longint;
|
---|
| 93 | Rect: TRect;
|
---|
| 94 | State: TOwnerDrawState );
|
---|
| 95 | procedure ChangeHeader( HeaderControl: TCustomHeaderControl;
|
---|
| 96 | Section: TCustomHeaderSection );
|
---|
| 97 | procedure Resize; override;
|
---|
| 98 | procedure SetupShow; override;
|
---|
| 99 | procedure SetupComponent; override;
|
---|
| 100 |
|
---|
| 101 | Procedure ReadSCUResource(Const ResName:TResourceName;Var Data;DataLen:LongInt);Override;
|
---|
| 102 | Function WriteSCUResource(Stream:TResourceStream):Boolean;Override;
|
---|
| 103 |
|
---|
| 104 | function GetTabStop:boolean;
|
---|
| 105 | procedure SetTabStop(Value:boolean);
|
---|
| 106 |
|
---|
| 107 | procedure WMFocussing( Var Msg: TMessage ); message WM_FOCUSSING;
|
---|
| 108 | public
|
---|
| 109 | destructor Destroy; override;
|
---|
| 110 |
|
---|
| 111 | property ItemIndex: integer read GetItemIndex write SetItemIndex;
|
---|
| 112 | property SelectedItem: string read GetSelectedItem write SetSelectedItem;
|
---|
| 113 | property SelectedObject: TObject read GetSelectedObject write SetSelectedObject;
|
---|
| 114 | property TopObject: TObject read GetTopObject write SetTopObject;
|
---|
| 115 |
|
---|
| 116 | procedure SetSelectedItemTo( Text: string );
|
---|
| 117 | property Selected[ Index: longint ]: boolean read GetSelected write SetSelected;
|
---|
| 118 |
|
---|
[458] | 119 | procedure SetColumnWidth( const Index: Integer;
|
---|
| 120 | const NewWidth: Integer );
|
---|
| 121 |
|
---|
[15] | 122 | property Parent;
|
---|
| 123 |
|
---|
| 124 | published
|
---|
| 125 | property Items: TStrings
|
---|
| 126 | read GetItems
|
---|
| 127 | write SetItems;
|
---|
| 128 | property HeaderColumns: TCustomHeaderSections
|
---|
| 129 | read GetHeaderSections
|
---|
| 130 | write SetHeaderSections;
|
---|
| 131 | property ImageList: TImageList
|
---|
| 132 | read FImageList
|
---|
| 133 | write SetImageList;
|
---|
| 134 |
|
---|
| 135 | Property BorderStyle:TBorderStyle read FBorderStyle write SetBorderStyle;
|
---|
| 136 |
|
---|
| 137 | property ListPenColor: TColor read GetListPenColor write SetListPenColor;
|
---|
| 138 | property HeaderPenColor: TColor read GetHeaderPenColor write SetHeaderPenColor;
|
---|
| 139 |
|
---|
| 140 | property ListFont: TFont read GetListFont write SetListFont;
|
---|
| 141 | property ListParentFont: boolean read GetListParentFont write SetListParentFont;
|
---|
| 142 |
|
---|
| 143 | property HeaderFont: TFont read GetHeaderFont write SetHeaderFont;
|
---|
| 144 | property HeaderParentFont: boolean read GetHeaderParentFont write SetHeaderParentFont;
|
---|
| 145 |
|
---|
| 146 | property ShowHint: boolean read GetShowHint write SetShowHint;
|
---|
| 147 | property ParentShowHint: boolean read GetParentShowHint write SetParentShowHint;
|
---|
| 148 |
|
---|
| 149 | property PopupMenu: TPopupMenu read GetThePopupMenu write SetPopupMenu;
|
---|
| 150 |
|
---|
| 151 | property HeaderHeight: integer read GetHeaderHeight write SetHeaderHeight;
|
---|
| 152 | property ItemHeight: integer read GetItemHeight write SetItemHeight;
|
---|
| 153 |
|
---|
| 154 | property MultiSelect: boolean read GetMultiSelect write SetMultiSelect;
|
---|
| 155 | property ExtendedSelect: boolean read GetExtendedSelect write SetExtendedSelect;
|
---|
| 156 |
|
---|
| 157 | property Enabled; //: boolean read GetEnabled write SetEnabled;
|
---|
| 158 |
|
---|
| 159 | property Align;
|
---|
| 160 | property Color;
|
---|
| 161 | property ParentColor;
|
---|
| 162 | property TabStop: boolean read GetTabStop write SetTabStop;
|
---|
| 163 | property TabOrder;
|
---|
| 164 |
|
---|
| 165 | // Events
|
---|
| 166 | property OnClick: TNotifyEvent read GetOnClick write SetOnClick;
|
---|
| 167 | property OnDblClick: TNotifyEvent read GetOnDblClick write SetOnDblClick;
|
---|
| 168 | property OnItemFocus: TItemFocusEvent read GetOnItemFocus write SetOnItemFocus;
|
---|
| 169 | property OnItemSelect: TItemSelectEvent read GetOnItemSelect write SetOnItemSelect;
|
---|
| 170 | property OnEnter: TNotifyEvent read GetOnEnter write SetOnEnter;
|
---|
| 171 | property OnExit: TNotifyEvent read GetOnExit write SetOnExit;
|
---|
| 172 | end;
|
---|
| 173 |
|
---|
| 174 | exports
|
---|
| 175 | TMultiColumnListBox, 'User', 'MultiColumnListBox.bmp';
|
---|
| 176 |
|
---|
| 177 | implementation
|
---|
| 178 |
|
---|
| 179 | uses
|
---|
[396] | 180 | StringUtilsUnit;
|
---|
[458] | 181 |
|
---|
[15] | 182 | { TMultiColumnListBox }
|
---|
| 183 |
|
---|
| 184 | procedure TMultiColumnListBox.SetupComponent;
|
---|
| 185 | var
|
---|
| 186 | Section: TCustomHeaderSection;
|
---|
| 187 | begin
|
---|
| 188 | inherited SetupComponent;
|
---|
| 189 |
|
---|
| 190 | Width := 100;
|
---|
| 191 | Height := 100;
|
---|
| 192 |
|
---|
| 193 | ParentCOlor := true;
|
---|
| 194 |
|
---|
| 195 | Name := 'MultiColumnListBox';
|
---|
| 196 |
|
---|
| 197 | FTabStop := false;
|
---|
| 198 |
|
---|
| 199 | FHeader := TCustomHeaderControl.Create( Self );
|
---|
| 200 | FHeader.Parent := self;
|
---|
| 201 | FHeader.Height := 22;
|
---|
| 202 | FHeader.BevelWidth := 1;
|
---|
| 203 | FHeader.TabStop := false;
|
---|
| 204 | Include( FHeader.ComponentState, csDetail );
|
---|
| 205 |
|
---|
| 206 | // Create a couple of default header sections
|
---|
| 207 | // so it's obvious that it's there.
|
---|
| 208 | Section := FHeader.Sections.Add;
|
---|
| 209 | Section.Text := 'Column 1';
|
---|
| 210 | Section.AllowClick := false;
|
---|
| 211 | Section := FHeader.Sections.Add;
|
---|
| 212 | Section.Text := 'Column 2';
|
---|
| 213 |
|
---|
| 214 | FListBox := TListBox.Create( Self );
|
---|
| 215 | FListBox.Parent := self;
|
---|
| 216 | // FListBox.ItemHeight := 16;
|
---|
| 217 |
|
---|
| 218 | FListBox.Style := lbOwnerDrawFixed;
|
---|
| 219 |
|
---|
| 220 | FListBox.OnDrawItem := DrawListBoxItem;
|
---|
| 221 |
|
---|
| 222 | FListBox.TabStop := true;
|
---|
| 223 | Include( FListBox.ComponentState, csDetail );
|
---|
| 224 | FListBox.ParentColor := true;
|
---|
| 225 |
|
---|
| 226 | // FListBox.BorderStyle := bsNone; // we draw it ourselves
|
---|
| 227 |
|
---|
| 228 | FHeader.OnSectionResize := ChangeHeader;
|
---|
| 229 |
|
---|
| 230 | FImageList := nil;
|
---|
| 231 |
|
---|
| 232 | // FAlwaysFocusChild := FListBox;
|
---|
| 233 |
|
---|
| 234 | Layout;
|
---|
| 235 |
|
---|
| 236 | end;
|
---|
| 237 |
|
---|
| 238 | procedure TMultiColumnListBox.SetupShow;
|
---|
| 239 | begin
|
---|
| 240 | Layout;
|
---|
| 241 | end;
|
---|
| 242 |
|
---|
| 243 | destructor TMultiColumnListBox.Destroy;
|
---|
| 244 | begin
|
---|
| 245 | inherited Destroy;
|
---|
| 246 | end;
|
---|
| 247 |
|
---|
| 248 | Procedure TMultiColumnListBox.ReadSCUResource( Const ResName: TResourceName;
|
---|
| 249 | Var Data;DataLen: LongInt );
|
---|
| 250 | begin
|
---|
| 251 | if ResName = rnHeaders then
|
---|
| 252 | FHeader.ReadSCUResource( ResName, Data, DataLen )
|
---|
| 253 | else
|
---|
| 254 | inherited ReadSCUResource( ResName, Data, DataLen );
|
---|
| 255 |
|
---|
| 256 | end;
|
---|
| 257 |
|
---|
| 258 | Function TMultiColumnListBox.WriteSCUResource( Stream: TResourceStream ): Boolean;
|
---|
| 259 | begin
|
---|
| 260 | Result := Inherited WriteSCUResource(Stream);
|
---|
| 261 | If Not Result Then
|
---|
| 262 | Exit;
|
---|
| 263 | FHeader.WriteScuResource( Stream );
|
---|
| 264 | end;
|
---|
| 265 |
|
---|
| 266 | procedure TMultiColumnListBox.WMFocussing( Var Msg: TMessage );
|
---|
| 267 | begin
|
---|
| 268 | // focus listbox instead
|
---|
| 269 | Msg.Result := LONGWORD( FListBox );
|
---|
| 270 | msg.Handled := true;
|
---|
| 271 | end;
|
---|
| 272 |
|
---|
| 273 | function TMultiColumnListBox.GetTabStop:boolean;
|
---|
| 274 | begin
|
---|
| 275 | result:=FListBox.TabStop;
|
---|
| 276 | end;
|
---|
| 277 |
|
---|
| 278 | procedure TMultiColumnListBox.SetTabStop(Value:boolean);
|
---|
| 279 | begin
|
---|
| 280 | FListBox.TabStop:=Value;
|
---|
| 281 | end;
|
---|
| 282 |
|
---|
| 283 | procedure TMultiColumnListBox.DrawListBoxItem( Sender: TObject;
|
---|
| 284 | Index: longint;
|
---|
| 285 | Rect: TRect;
|
---|
| 286 | State: TOwnerDrawState );
|
---|
| 287 | var
|
---|
| 288 | ColumnIndex: integer;
|
---|
| 289 | X: integer;
|
---|
| 290 | ItemToDraw: string;
|
---|
| 291 | Line: string;
|
---|
| 292 | BitmapIndex: integer;
|
---|
| 293 | ColumnWidth: integer;
|
---|
| 294 | ItemRect: TRect;
|
---|
| 295 | Dest: TRect;
|
---|
| 296 | LineClipRect: TRect;
|
---|
[396] | 297 | tmpColumns : TStringList;
|
---|
| 298 | i : longint;
|
---|
[15] | 299 | begin
|
---|
| 300 | LineClipRect := FListBox.Canvas.ClipRect;
|
---|
| 301 |
|
---|
| 302 | ColumnIndex := 0;
|
---|
| 303 |
|
---|
| 304 | Dest := rect;
|
---|
| 305 | dec( Dest.top ); // minor adjustments since we seem to get a slightly
|
---|
| 306 | inc( Dest.left ); // incorrect area to draw on...
|
---|
| 307 |
|
---|
| 308 | X := Dest.Left;
|
---|
| 309 | Line := FListBox.Items[ Index ];
|
---|
| 310 |
|
---|
| 311 | with FListBox.Canvas do
|
---|
| 312 | begin
|
---|
| 313 | Pen.Color := FListBox.PenColor;
|
---|
| 314 | Brush.Color := FListBox.Color;
|
---|
| 315 | IF State * [odSelected] <> [] THEN
|
---|
| 316 | begin
|
---|
| 317 | Brush.Color := clHighLight;
|
---|
| 318 | Pen.Color := Color;
|
---|
| 319 | end;
|
---|
| 320 |
|
---|
| 321 | FillRect( Dest, Brush.Color );
|
---|
| 322 | end;
|
---|
| 323 |
|
---|
[396] | 324 | tmpColumns := TStringList.Create;
|
---|
| 325 | StrExtractStrings(tmpColumns, Line, [#9], #0);
|
---|
| 326 |
|
---|
| 327 | for i := 0 to tmpColumns.Count - 1 do
|
---|
[15] | 328 | begin
|
---|
[396] | 329 | ItemToDraw := tmpColumns[i];
|
---|
[15] | 330 | if ColumnIndex < FHeader.Sections.Count then
|
---|
| 331 | ColumnWidth := FHeader.Sections[ ColumnIndex ].Width
|
---|
| 332 | else
|
---|
| 333 | ColumnWidth := 50;
|
---|
| 334 |
|
---|
| 335 | ItemRect := Dest;
|
---|
| 336 | ItemRect.Left := X;
|
---|
| 337 | ItemRect.Right := X + ColumnWidth - 2;
|
---|
| 338 | FListBox.Canvas.ClipRect := IntersectRect( LineClipRect,
|
---|
| 339 | ItemRect );
|
---|
| 340 |
|
---|
| 341 | if StrLeft( ItemToDraw, 1 ) = mclbImageMarker then
|
---|
| 342 | begin
|
---|
| 343 | Delete( ItemToDraw, 1, 1 );
|
---|
| 344 | try
|
---|
| 345 | BitmapIndex := StrToInt( ItemToDraw );
|
---|
| 346 | except
|
---|
| 347 | BitmapIndex := -1;
|
---|
| 348 | end;
|
---|
| 349 | if Assigned( FImageList ) then
|
---|
| 350 | if ( BitmapIndex >= 0 )
|
---|
| 351 | and ( BitmapIndex < FImageList.Count ) then
|
---|
| 352 | begin
|
---|
| 353 | FImageList.Draw( FListBox.Canvas,
|
---|
| 354 | X, Dest.Bottom,
|
---|
| 355 | BitmapIndex );
|
---|
| 356 | end
|
---|
| 357 | else
|
---|
[396] | 358 | begin
|
---|
| 359 | tmpColumns.Destroy;
|
---|
[15] | 360 | raise Exception.Create( 'Bitmap index out of range in MultiColumnListBox' )
|
---|
[396] | 361 | end
|
---|
[15] | 362 | else
|
---|
[396] | 363 | begin
|
---|
| 364 | tmpColumns.Destroy;
|
---|
[15] | 365 | raise Exception.Create( 'No imagelist assigned in MultiColumnListBox' );
|
---|
[396] | 366 | end
|
---|
[15] | 367 | end
|
---|
| 368 | else
|
---|
| 369 | begin
|
---|
| 370 | FListBox.Canvas.TextOut( X, Dest.Bottom,
|
---|
| 371 | ItemToDraw );
|
---|
| 372 | end;
|
---|
| 373 | inc( X, ColumnWidth );
|
---|
| 374 | inc( ColumnIndex );
|
---|
| 375 | end;
|
---|
[396] | 376 | tmpColumns.Destroy;
|
---|
[15] | 377 | end;
|
---|
| 378 |
|
---|
| 379 | procedure TMultiColumnListBox.SetItems( Items: TStrings );
|
---|
| 380 | begin
|
---|
| 381 | FListBox.Items.Assign( Items );
|
---|
| 382 | end;
|
---|
| 383 |
|
---|
| 384 | function TMultiColumnListBox.GetHeaderSections: TCustomHeaderSections;
|
---|
| 385 | begin
|
---|
| 386 | Result := FHeader.Sections;
|
---|
| 387 | end;
|
---|
| 388 |
|
---|
| 389 | function TMultiColumnListBox.GetItems: TStrings;
|
---|
| 390 | begin
|
---|
| 391 | Result := FListBox.Items;
|
---|
| 392 | end;
|
---|
| 393 |
|
---|
| 394 | procedure TMultiColumnListBox.Layout;
|
---|
| 395 | var
|
---|
| 396 | LastSection: TCustomHeaderSection;
|
---|
| 397 | begin
|
---|
| 398 | FHeader.Align := alTop;
|
---|
| 399 |
|
---|
| 400 | //FListBox.Align := alClient;
|
---|
| 401 | {
|
---|
| 402 | if FBorderStyle = bsNone then
|
---|
| 403 | begin
|
---|
| 404 | }
|
---|
| 405 | FListBox.Left := 0;
|
---|
| 406 | FListBox.Width := Width;
|
---|
| 407 | FListBox.Bottom := 0;
|
---|
| 408 | FListBox.Height := Height - FHeader.Height + 2; // hide the top edge under header
|
---|
| 409 | FListBox.SendToBack;
|
---|
| 410 | {
|
---|
| 411 | end
|
---|
| 412 | else
|
---|
| 413 | begin
|
---|
| 414 | FListBox.Left := 2;
|
---|
| 415 | FListBox.Width := Width - 4;
|
---|
| 416 | FListBox.Bottom := 2;
|
---|
| 417 | FListBox.Height := Height - FHeader.Height - 4;
|
---|
| 418 | end;
|
---|
| 419 | }
|
---|
| 420 |
|
---|
| 421 | if HeaderColumns.Count > 0 then
|
---|
| 422 | begin
|
---|
| 423 | // Resize the last column to fit, if possible
|
---|
| 424 | LastSection := HeaderColumns[ HeaderColumns.Count - 1 ];
|
---|
| 425 | if LastSection.Left < Width then
|
---|
| 426 | LastSection.Width := Width - LastSection.Left;
|
---|
| 427 | end;
|
---|
| 428 |
|
---|
| 429 | end;
|
---|
| 430 |
|
---|
| 431 | procedure TMultiColumnListBox.SetBorderStyle( NewValue: TBorderStyle );
|
---|
| 432 | begin
|
---|
| 433 | if NewValue = FBorderStyle then
|
---|
| 434 | exit;
|
---|
| 435 | FBorderStyle := NewValue;
|
---|
| 436 | Layout;
|
---|
| 437 | Invalidate;
|
---|
| 438 | end;
|
---|
| 439 |
|
---|
| 440 | procedure TMultiColumnListBox.SetImageList(ImageList: TImageList);
|
---|
| 441 | begin
|
---|
| 442 | if FImageList <> nil then
|
---|
| 443 | // Tell the old imagelist not to inform us any more
|
---|
| 444 | FImageList.Notification( Self, opRemove );
|
---|
| 445 |
|
---|
| 446 | FImageList := ImageList;
|
---|
| 447 |
|
---|
| 448 | if FImageList <> nil then
|
---|
| 449 | begin
|
---|
| 450 | // request notification when other is freed
|
---|
| 451 | FImageList.FreeNotification( Self );
|
---|
| 452 | end;
|
---|
| 453 | end;
|
---|
| 454 |
|
---|
| 455 | procedure TMultiColumnListBox.SetHeaderSections(Sections: TCustomHeaderSections);
|
---|
| 456 | begin
|
---|
| 457 | FHeader.Sections.Assign( Sections );
|
---|
| 458 | end;
|
---|
| 459 |
|
---|
[458] | 460 | procedure TMultiColumnListBox.SetColumnWidth( const Index: Integer;
|
---|
| 461 | const NewWidth: Integer );
|
---|
| 462 | begin
|
---|
| 463 | FHeader.Sections[ Index ].Width := NewWidth;
|
---|
| 464 | Layout;
|
---|
| 465 | Invalidate;
|
---|
| 466 | end;
|
---|
| 467 |
|
---|
[15] | 468 | procedure TMultiColumnListBox.Notification( AComponent: TComponent;
|
---|
| 469 | Operation: TOperation);
|
---|
| 470 | begin
|
---|
| 471 | inherited Notification( AComponent, Operation );
|
---|
| 472 | if AComponent = FImageList then
|
---|
| 473 | if Operation = opRemove then
|
---|
| 474 | // Image list is being destroyed
|
---|
| 475 | FImageList := nil;
|
---|
| 476 | end;
|
---|
| 477 |
|
---|
| 478 | procedure TMultiColumnListBox.ChangeHeader(HeaderControl: TCustomHeaderControl;
|
---|
| 479 | Section: TCustomHeaderSection);
|
---|
| 480 | begin
|
---|
| 481 | Layout;
|
---|
| 482 | FListBox.Invalidate;
|
---|
| 483 | end;
|
---|
| 484 |
|
---|
| 485 | function TMultiColumnListBox.GetSelectedItem: string;
|
---|
| 486 | begin
|
---|
| 487 | Result := '';
|
---|
| 488 | if FListBox.ItemIndex <> -1 then
|
---|
| 489 | Result := FListBox.Items[ FListBox.ItemIndex ];
|
---|
| 490 | end;
|
---|
| 491 |
|
---|
| 492 | function TMultiColumnListBox.GetSelectedObject: TObject;
|
---|
| 493 | begin
|
---|
| 494 | Result := nil;
|
---|
| 495 | if FListBox.ItemIndex <> -1 then
|
---|
| 496 | Result := FListBox.Items.Objects[ FListBox.ItemIndex ];
|
---|
| 497 |
|
---|
| 498 | end;
|
---|
| 499 |
|
---|
| 500 | procedure TMultiColumnListBox.SetItemIndex(const Value: integer );
|
---|
| 501 | begin
|
---|
| 502 | FListBox.ItemIndex := Value;
|
---|
| 503 | end;
|
---|
| 504 |
|
---|
| 505 | function TMultiColumnListBox.GetItemIndex: integer;
|
---|
| 506 | begin
|
---|
| 507 | Result := FListBox.ItemIndex;
|
---|
| 508 | end;
|
---|
| 509 |
|
---|
| 510 | function TMultiColumnListBox.GetHeaderPenColor: TColor;
|
---|
| 511 | begin
|
---|
| 512 | Result := FHeader.PenColor;
|
---|
| 513 | end;
|
---|
| 514 |
|
---|
| 515 | procedure TMultiColumnListBox.SetHeaderPenColor( NewValue: TColor );
|
---|
| 516 | begin
|
---|
| 517 | FHeader.PenColor := NewValue;
|
---|
| 518 | end;
|
---|
| 519 |
|
---|
| 520 | function TMultiColumnListBox.GetListPenColor: TColor;
|
---|
| 521 | begin
|
---|
| 522 | Result := FListBox.PenColor;
|
---|
| 523 | end;
|
---|
| 524 |
|
---|
| 525 | procedure TMultiColumnListBox.SetListPenColor( NewValue: TColor );
|
---|
| 526 | begin
|
---|
| 527 | FListBox.PenColor := NewValue;
|
---|
| 528 | end;
|
---|
| 529 |
|
---|
| 530 | function TMultiColumnListBox.GetEnabled: boolean;
|
---|
| 531 | begin
|
---|
| 532 | Result := FListBox.Enabled;
|
---|
| 533 | end;
|
---|
| 534 |
|
---|
| 535 | function TMultiColumnListBox.GetExtendedSelect: boolean;
|
---|
| 536 | begin
|
---|
| 537 | Result := FListBox.ExtendedSelect;
|
---|
| 538 | end;
|
---|
| 539 |
|
---|
| 540 | function TMultiColumnListBox.GetHeaderFont: TFont;
|
---|
| 541 | begin
|
---|
| 542 | Result := FHeader.Font;
|
---|
| 543 | end;
|
---|
| 544 |
|
---|
| 545 | function TMultiColumnListBox.GetHeaderHeight: integer;
|
---|
| 546 | begin
|
---|
| 547 | Result := FHeader.Height;
|
---|
| 548 | end;
|
---|
| 549 |
|
---|
| 550 | function TMultiColumnListBox.GetHeaderParentFont: boolean;
|
---|
| 551 | begin
|
---|
| 552 | Result := FHeader.ParentFont;
|
---|
| 553 | end;
|
---|
| 554 |
|
---|
| 555 | function TMultiColumnListBox.GetItemHeight: integer;
|
---|
| 556 | begin
|
---|
| 557 | Result := FListBox.ItemHeight;
|
---|
| 558 | end;
|
---|
| 559 |
|
---|
| 560 | function TMultiColumnListBox.GetListFont: TFont;
|
---|
| 561 | begin
|
---|
| 562 | Result := FListBox.Font;
|
---|
| 563 | end;
|
---|
| 564 |
|
---|
| 565 | function TMultiColumnListBox.GetListParentFont: boolean;
|
---|
| 566 | begin
|
---|
| 567 | Result := FListBox.ParentFont;
|
---|
| 568 | end;
|
---|
| 569 |
|
---|
| 570 | function TMultiColumnListBox.GetMultiSelect: boolean;
|
---|
| 571 | begin
|
---|
| 572 | Result := FListBox.MultiSelect;
|
---|
| 573 | end;
|
---|
| 574 |
|
---|
| 575 | function TMultiColumnListBox.GetParentColor: boolean;
|
---|
| 576 | begin
|
---|
| 577 | Result := FListBox.ParentColor;
|
---|
| 578 | end;
|
---|
| 579 |
|
---|
| 580 | function TMultiColumnListBox.GetParentShowHint: boolean;
|
---|
| 581 | begin
|
---|
| 582 | Result := FListBox.ParentShowHint;
|
---|
| 583 | end;
|
---|
| 584 |
|
---|
| 585 | function TMultiColumnListBox.GetThePopupMenu: TPopupMenu;
|
---|
| 586 | begin
|
---|
| 587 | Result := FListBox.PopupMenu;
|
---|
| 588 | end;
|
---|
| 589 |
|
---|
| 590 | function TMultiColumnListBox.GetShowHint: boolean;
|
---|
| 591 | begin
|
---|
| 592 | Result := FListBox.ShowHint;
|
---|
| 593 | end;
|
---|
| 594 |
|
---|
| 595 | {
|
---|
| 596 | procedure TMultiColumnListBox.SetEnabled(NewState:Boolean);
|
---|
| 597 | begin
|
---|
| 598 | FListBox.Enabled := NewState;
|
---|
| 599 | FHeader.Enabled := NewState;
|
---|
| 600 | end;
|
---|
| 601 | }
|
---|
| 602 |
|
---|
| 603 | procedure TMultiColumnListBox.SetExtendedSelect(const Value: boolean);
|
---|
| 604 | begin
|
---|
| 605 | FListBox.ExtendedSelect := Value;
|
---|
| 606 | end;
|
---|
| 607 |
|
---|
| 608 | procedure TMultiColumnListBox.SetHeaderFont(const Value: TFont);
|
---|
| 609 | begin
|
---|
| 610 | FHeader.Font := Value;
|
---|
| 611 | end;
|
---|
| 612 |
|
---|
| 613 | procedure TMultiColumnListBox.SetHeaderHeight(const Value: integer);
|
---|
| 614 | begin
|
---|
| 615 | FHeader.Height := Value;
|
---|
[458] | 616 | Layout;
|
---|
[15] | 617 | end;
|
---|
| 618 |
|
---|
| 619 | procedure TMultiColumnListBox.SetHeaderParentFont(const Value: boolean);
|
---|
| 620 | begin
|
---|
| 621 | FHeader.ParentFont := Value;
|
---|
| 622 | end;
|
---|
| 623 |
|
---|
| 624 | procedure TMultiColumnListBox.SetItemHeight(const Value: integer);
|
---|
| 625 | begin
|
---|
| 626 | FListBox.ItemHeight := Value;
|
---|
| 627 | end;
|
---|
| 628 |
|
---|
| 629 | procedure TMultiColumnListBox.SetListFont(const Value: TFont);
|
---|
| 630 | begin
|
---|
| 631 | FListBox.Font := Value;
|
---|
| 632 | end;
|
---|
| 633 |
|
---|
| 634 | procedure TMultiColumnListBox.SetListParentFont(const Value: boolean);
|
---|
| 635 | begin
|
---|
| 636 | FListBox.ParentFont := Value;
|
---|
| 637 | end;
|
---|
| 638 |
|
---|
| 639 | procedure TMultiColumnListBox.SetMultiSelect(const Value: boolean);
|
---|
| 640 | begin
|
---|
| 641 | FListBox.MultiSelect := Value;
|
---|
| 642 | end;
|
---|
| 643 |
|
---|
| 644 | procedure TMultiColumnListBox.SetParentShowHint(const Value: boolean);
|
---|
| 645 | begin
|
---|
| 646 | FListBox.ParentShowHint := Value;
|
---|
| 647 | FHeader.ParentShowHint := Value;
|
---|
| 648 | end;
|
---|
| 649 |
|
---|
| 650 | procedure TMultiColumnListBox.SetPopupMenu(const Value: TPopupMenu);
|
---|
| 651 | begin
|
---|
| 652 | FListBox.PopupMenu := Value;
|
---|
| 653 | FHeader.PopupMenu := Value;
|
---|
| 654 | end;
|
---|
| 655 |
|
---|
| 656 | procedure TMultiColumnListBox.SetShowHint(const Value: boolean);
|
---|
| 657 | begin
|
---|
| 658 | FListBox.ShowHint := Value;
|
---|
| 659 | FHeader.ShowHint := Value;
|
---|
| 660 | end;
|
---|
| 661 |
|
---|
| 662 | procedure TMultiColumnListBox.SetSelectedObject(const Value: TObject);
|
---|
| 663 | var
|
---|
| 664 | Index: integer;
|
---|
| 665 | begin
|
---|
| 666 | Index := FListBox.Items.IndexOfObject( Value );
|
---|
| 667 | FListBox.ItemIndex := Index;
|
---|
| 668 | end;
|
---|
| 669 |
|
---|
| 670 | function TMultiColumnListBox.GetOnClick: TNotifyEvent;
|
---|
| 671 | begin
|
---|
| 672 | Result := FListBox.OnClick;
|
---|
| 673 | end;
|
---|
| 674 |
|
---|
| 675 | procedure TMultiColumnListBox.SetOnClick(const Value: TNotifyEvent);
|
---|
| 676 | begin
|
---|
| 677 | FListBox.OnClick := Value;
|
---|
| 678 | end;
|
---|
| 679 |
|
---|
| 680 | function TMultiColumnListBox.GetOnDblClick: TNotifyEvent;
|
---|
| 681 | begin
|
---|
| 682 | Result := FListBox.OnDblClick;
|
---|
| 683 | end;
|
---|
| 684 |
|
---|
| 685 | procedure TMultiColumnListBox.SetOnDblClick(const Value: TNotifyEvent);
|
---|
| 686 | begin
|
---|
| 687 | FListBox.OnDblClick := Value;
|
---|
| 688 | end;
|
---|
| 689 |
|
---|
| 690 | procedure TMultiColumnListBox.SetSelectedItem(const Value: string);
|
---|
| 691 | var
|
---|
| 692 | Index: integer;
|
---|
| 693 | begin
|
---|
| 694 | Index := FListBox.Items.IndexOf( Value );
|
---|
| 695 | FListBox.ItemIndex := Index;
|
---|
| 696 | end;
|
---|
| 697 |
|
---|
| 698 | procedure TMultiColumnListBox.SetSelectedItemTo(Text: string );
|
---|
| 699 | begin
|
---|
| 700 | if ItemIndex = -1 then
|
---|
| 701 | raise Exception.Create( 'MultiColumnListBox: no item selected to set!' );
|
---|
| 702 |
|
---|
| 703 | Items[ ItemIndex ] := Text;
|
---|
| 704 | end;
|
---|
| 705 |
|
---|
| 706 | procedure TMultiColumnListBox.Resize;
|
---|
| 707 | begin
|
---|
| 708 | Layout;
|
---|
| 709 | end;
|
---|
| 710 |
|
---|
| 711 |
|
---|
| 712 | function TMultiColumnListBox.GetTopObject: TObject;
|
---|
| 713 | begin
|
---|
| 714 | Result := nil;
|
---|
| 715 | if ( FListBox.TopIndex >0 )
|
---|
| 716 | and ( FListBox.TopIndex < FListBox.Items.Count ) then
|
---|
| 717 | Result := FListBox.Items.Objects[ FLIstBox.TopIndex ];
|
---|
| 718 |
|
---|
| 719 | end;
|
---|
| 720 |
|
---|
| 721 | procedure TMultiColumnListBox.SetTopObject(const Value: TObject);
|
---|
| 722 | var
|
---|
| 723 | Index: integer;
|
---|
| 724 | begin
|
---|
| 725 | Index := FListBox.Items.IndexOfObject( Value );
|
---|
| 726 | if Index <> -1 then
|
---|
| 727 | FListBox.TopIndex := Index;
|
---|
| 728 | end;
|
---|
| 729 |
|
---|
| 730 | procedure TMultiColumnListBox.SetOnItemFocus( Value: TItemFocusEvent );
|
---|
| 731 | begin
|
---|
| 732 | FListBox.OnItemFocus := Value;
|
---|
| 733 | end;
|
---|
| 734 |
|
---|
| 735 | function TMultiColumnListBox.GetOnItemFocus: TItemFocusEvent;
|
---|
| 736 | begin
|
---|
| 737 | Result := FListBox.OnItemFocus;
|
---|
| 738 | end;
|
---|
| 739 |
|
---|
| 740 | function TMultiColumnListBox.GetOnItemSelect: TItemSelectEvent;
|
---|
| 741 | begin
|
---|
| 742 | Result := FListBox.OnItemSelect;
|
---|
| 743 | end;
|
---|
| 744 |
|
---|
| 745 | procedure TMultiColumnListBox.SetOnItemSelect( Value: TItemSelectEvent );
|
---|
| 746 | begin
|
---|
| 747 | FListBox.OnItemSelect := Value;
|
---|
| 748 | end;
|
---|
| 749 |
|
---|
| 750 | function TMultiColumnListBox.GetOnEnter: TNotifyEvent;
|
---|
| 751 | begin
|
---|
| 752 | Result := FListBox.OnEnter;
|
---|
| 753 | end;
|
---|
| 754 |
|
---|
| 755 | procedure TMultiColumnListBox.SetOnEnter( Value: TNotifyEvent );
|
---|
| 756 | begin
|
---|
| 757 | FListBox.OnEnter := Value;
|
---|
| 758 | end;
|
---|
| 759 |
|
---|
| 760 | function TMultiColumnListBox.GetOnExit: TNotifyEvent;
|
---|
| 761 | begin
|
---|
| 762 | Result := FListBox.OnExit;
|
---|
| 763 | end;
|
---|
| 764 |
|
---|
| 765 | procedure TMultiColumnListBox.SetOnExit( Value: TNotifyEvent );
|
---|
| 766 | begin
|
---|
| 767 | FListBox.OnExit := Value;
|
---|
| 768 | end;
|
---|
| 769 |
|
---|
| 770 | procedure TMultiColumnListBox.SetSelected( Index: longint; Value: boolean );
|
---|
| 771 | begin
|
---|
| 772 | FListBox.Selected[ Index ] := Value;
|
---|
| 773 | end;
|
---|
| 774 |
|
---|
| 775 | function TMultiColumnListBox.GetSelected( Index: longint ): boolean;
|
---|
| 776 | begin
|
---|
| 777 | Result := FListBox.Selected[ Index ];
|
---|
| 778 | end;
|
---|
| 779 |
|
---|
| 780 | Procedure TMultiColumnListBox.SetColor(NewColor:TColor);
|
---|
| 781 | begin
|
---|
| 782 | inherited SetColor( NewColor );
|
---|
| 783 | end;
|
---|
| 784 |
|
---|
| 785 | Initialization
|
---|
| 786 | {Register classes}
|
---|
| 787 | RegisterClasses([TMultiColumnListBox]);
|
---|
| 788 | end.
|
---|