IEListView.pas 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  1. unit IEListView;
  2. {==================================================================
  3. Component TCustomIEListView / Version 1.0, September 1999
  4. ==================================================================
  5. Description:
  6. ============
  7. Basic component for TDirView.
  8. Author:
  9. =======
  10. (c) Ingo Eckel 1999
  11. Sodener Weg 38
  12. 65812 Bad Soden
  13. Germany
  14. (c) Martin Prikryl 2001 - 2003
  15. For detailed documentation see the documentation of TDirView.
  16. ==================================================================}
  17. {Required compiler options for TCustomIEListView:}
  18. {$A+,B-,X+,H+,P+}
  19. interface
  20. uses
  21. Windows, Messages, SysUtils, Classes, Graphics, Controls,
  22. Forms, ActiveX, CommCtrl, Extctrls, ImgList,
  23. ComCtrls, NortonLikeListView, ListViewColProperties;
  24. type
  25. TIEListViewColProperties = class(TCustomListViewColProperties)
  26. protected
  27. function GetSortAscending: Boolean;
  28. procedure SetSortColumn(Value: Integer);
  29. function GetSortColumn: Integer;
  30. function GetSortStr: string; virtual;
  31. procedure SetSortAscending(Value: Boolean);
  32. procedure SetSortStr(Value: string); virtual;
  33. function GetParamsStr: string; override;
  34. procedure SetParamsStr(Value: string); override;
  35. public
  36. constructor Create(ListView: TCustomListView; ColCount: Integer);
  37. property SortAscending: Boolean read GetSortAscending write SetSortAscending default True;
  38. property SortColumn: Integer read GetSortColumn write SetSortColumn;
  39. property SortStr: string read GetSortStr write SetSortStr stored False;
  40. end;
  41. type
  42. TDateTimeDisplay = (dtdDateTimeSec, dtdDateTime, dtdDate);
  43. type
  44. TCustomIEListView = class;
  45. TListViewSecondaryColumnHeaderEvent =
  46. procedure(Sender: TCustomIEListView; Index: Integer; var SecondaryColumn: Integer) of object;
  47. TCustomIEListView = class(TCustomNortonLikeListView)
  48. private
  49. FSortColumn: Integer;
  50. FSortAscending: Boolean;
  51. FColumnIconPainted: Boolean;
  52. FShowColumnIcon: Boolean;
  53. FHeaderHandle: HWND;
  54. FParentForm: TCustomForm;
  55. FHeaderCanvas: TCanvas;
  56. FOnHeaderEndDrag: TNotifyEvent;
  57. FOnHeaderEndTrack: TNotifyEvent;
  58. FOnSecondaryColumnHeader: TListViewSecondaryColumnHeaderEvent;
  59. FDateTimeFormatStr: string;
  60. FDateFormatStr: string;
  61. FDateTimeDisplay: TDateTimeDisplay;
  62. FDragImageList: TDragImageList;
  63. FHeaderImages: TImageList;
  64. function SecondaryColumnHeaderOffset(Canvas: TCanvas; Index: Integer): Integer;
  65. function ColumnHeaderIconWidth: Integer;
  66. protected
  67. procedure ColPropertiesChange(Sender: TObject); virtual;
  68. procedure SetShowColumnIcon(Value: Boolean); virtual;
  69. procedure SetSortColumn(Value: Integer); virtual;
  70. procedure SetSortAscending(Value: Boolean); virtual;
  71. procedure SortItems; virtual;
  72. procedure SetViewStyle(Value: TViewStyle); override; // CLEAN virtual
  73. procedure SetDateTimeDisplay(Value: TDateTimeDisplay); virtual;
  74. procedure SetDateTimeFormatString; virtual;
  75. procedure HeaderEndDrag(Sender: TObject); virtual;
  76. procedure SetHeaderImages(Value: TImageList); virtual;
  77. function SecondaryColumnHeader(Index: Integer; var AliasOnly: Boolean): Integer; virtual;
  78. function NewColProperties: TCustomListViewColProperties; override;
  79. function SortAscendingByDefault(Index: Integer): Boolean; virtual;
  80. procedure CreateWnd; override;
  81. procedure ColClick(Column: TListColumn); override;
  82. procedure Loaded; override;
  83. procedure WMPaint(var Msg: TWMPaint); message WM_PAINT;
  84. procedure WMNotify(var Msg: TWMNotify); message WM_NOTIFY;
  85. public
  86. constructor Create(AOwner: TComponent); override;
  87. destructor Destroy; override;
  88. procedure SetColumnImages; virtual;
  89. property HeaderImages: TImageList read FHeaderImages write SetHeaderImages;
  90. property DragImageList: TDragImageList read FDragImageList;
  91. property ColumnIconPainted: Boolean
  92. read FColumnIconPainted write FColumnIconPainted stored False;
  93. property HeaderHandle: HWND read FHeaderHandle;
  94. property ParentForm: TCustomForm read FParentForm;
  95. property DateTimeFormatStr: string
  96. read FDateTimeFormatStr write FDateTimeFormatStr stored False;
  97. property DateFormatStr: string read FDateFormatStr;
  98. {Set the sort column of the listview}
  99. property SortColumn: Integer read FSortColumn write SetSortColumn;
  100. {Show the sorting symbol in the listview's header:}
  101. property ShowColumnIcon: Boolean
  102. read FShowColumnIcon write SetShowColumnIcon default True;
  103. {Sortorder of actual sort column}
  104. property SortAscending: Boolean
  105. read FSortAscending write SetSortAscending default True;
  106. property OnSecondaryColumnHeader: TListViewSecondaryColumnHeaderEvent
  107. read FOnSecondaryColumnHeader write FOnSecondaryColumnHeader;
  108. published
  109. {Display format of the date/time of the files:}
  110. property DateTimeDisplay: TDateTimeDisplay
  111. read FDateTimeDisplay write SetDateTimeDisplay default dtdDateTimeSec;
  112. property OnHeaderEndDrag: TNotifyEvent
  113. read FOnHeaderEndDrag write FOnHeaderEndDrag;
  114. property OnHeaderEndTrack: TNotifyEvent
  115. read FOnHeaderEndTrack write FOnHeaderEndTrack;
  116. property Align;
  117. property AllocBy;
  118. property Anchors;
  119. property BiDiMode;
  120. property BorderStyle;
  121. property BorderWidth;
  122. property Checkboxes;
  123. property Color;
  124. property ColumnClick default True;
  125. property Constraints;
  126. property Ctl3D;
  127. property Enabled;
  128. property Font;
  129. property FlatScrollBars;
  130. property FullDrag;
  131. property GridLines;
  132. property HideSelection;
  133. property HotTrack;
  134. property HotTrackStyles;
  135. property IconOptions;
  136. property ReadOnly default False;
  137. property RowSelect;
  138. property ParentBiDiMode;
  139. property ParentColor default False;
  140. property ParentFont;
  141. property ParentShowHint;
  142. property PopupMenu;
  143. property ShowColumnHeaders;
  144. property ShowHint;
  145. property TabOrder;
  146. property TabStop default True;
  147. property ViewStyle;
  148. property Visible;
  149. property OnChange;
  150. property OnChanging;
  151. property OnClick;
  152. property OnColumnClick;
  153. property OnColumnRightClick;
  154. property OnCustomDraw;
  155. property OwnerDraw;
  156. {Used for internal purposes:}
  157. property OnCustomDrawItem;
  158. property OnCustomDrawSubItem;
  159. property OnDblClick;
  160. property OnDeletion;
  161. property OnDrawItem;
  162. property OnEdited;
  163. property OnEditing;
  164. property OnEndDock;
  165. property OnEnter;
  166. property OnExit;
  167. property OnInsert;
  168. property OnKeyDown;
  169. property OnKeyPress;
  170. property OnKeyUp;
  171. property OnMouseDown;
  172. property OnMouseMove;
  173. property OnMouseUp;
  174. property OnResize;
  175. property OnStartDock;
  176. property NortonLike;
  177. property OnSelectByMask;
  178. end; {Type TCustomIEListView}
  179. type
  180. TIEListView = class(TCustomIEListView)
  181. published
  182. // copy from TListView, except for marked items
  183. property Action;
  184. property Align;
  185. property AllocBy;
  186. property Anchors;
  187. property BevelEdges;
  188. property BevelInner;
  189. property BevelOuter;
  190. property BevelKind default bkNone;
  191. property BevelWidth;
  192. property BiDiMode;
  193. property BorderStyle;
  194. property BorderWidth;
  195. property Checkboxes;
  196. property Color;
  197. property Columns;
  198. property ColumnClick;
  199. property Constraints;
  200. property Ctl3D;
  201. property DragCursor;
  202. property DragKind;
  203. property DragMode;
  204. property Enabled;
  205. property Font;
  206. property FlatScrollBars;
  207. property FullDrag;
  208. property GridLines;
  209. property HeaderImages; // TCustomIEListView
  210. property HideSelection;
  211. property HotTrack;
  212. property HotTrackStyles;
  213. property HoverTime;
  214. property IconOptions;
  215. property Items;
  216. property LargeImages;
  217. property MultiSelect;
  218. property OwnerData;
  219. property OwnerDraw;
  220. property ReadOnly default False;
  221. property RowSelect;
  222. property ParentBiDiMode;
  223. property ParentColor default False;
  224. property ParentFont;
  225. property ParentShowHint;
  226. property PopupMenu;
  227. property ShowColumnHeaders;
  228. property ShowWorkAreas;
  229. property ShowHint;
  230. property SmallImages;
  231. property SortType;
  232. property StateImages;
  233. property TabOrder;
  234. property TabStop default True;
  235. property ViewStyle;
  236. property Visible;
  237. property OnAdvancedCustomDraw;
  238. property OnAdvancedCustomDrawItem;
  239. property OnAdvancedCustomDrawSubItem;
  240. property OnChange;
  241. property OnChanging;
  242. property OnClick;
  243. property OnColumnClick;
  244. property OnColumnDragged;
  245. property OnColumnRightClick;
  246. property OnCompare;
  247. property OnContextPopup;
  248. property OnCustomDraw;
  249. property OnCustomDrawItem;
  250. property OnCustomDrawSubItem;
  251. property OnData;
  252. property OnDataFind;
  253. property OnDataHint;
  254. property OnDataStateChange;
  255. property OnDblClick;
  256. property OnDeletion;
  257. property OnDrawItem;
  258. property OnEdited;
  259. property OnEditing;
  260. property OnEndDock;
  261. property OnEndDrag;
  262. property OnEnter;
  263. property OnExit;
  264. property OnGetImageIndex;
  265. property OnGetSubItemImage;
  266. property OnDragDrop;
  267. property OnDragOver;
  268. property OnInfoTip;
  269. property OnInsert;
  270. property OnKeyDown;
  271. property OnKeyPress;
  272. property OnKeyUp;
  273. property OnMouseDown;
  274. property OnMouseMove;
  275. property OnMouseUp;
  276. property OnResize;
  277. property OnSelectItem;
  278. property OnStartDock;
  279. property OnStartDrag;
  280. property OnSecondaryColumnHeader; // TCustomIEListView
  281. end;
  282. var
  283. GlobalDragImageList: TDragImageList;
  284. procedure Register;
  285. implementation
  286. const HDM_SETBITMAPMARGIN = (HDM_FIRST + 20);
  287. const HDM_GETBITMAPMARGIN = (HDM_FIRST + 21);
  288. const HDF_SORTUP = $400;
  289. const HDF_SORTDOWN = $200;
  290. procedure Register;
  291. begin
  292. RegisterComponents('Martin', [TIEListView]);
  293. end;
  294. procedure Header_SetBitmapMargin(Header: HWnd; Margin: Integer);
  295. begin
  296. SendMessage(Header, HDM_SETBITMAPMARGIN, Margin, 0);
  297. end;
  298. function Header_GetBitmapMargin(Header: HWnd): Integer;
  299. begin
  300. Result := SendMessage(Header, HDM_GETBITMAPMARGIN, 0, 0);
  301. end;
  302. { TIEListViewColProperties }
  303. constructor TIEListViewColProperties.Create(ListView: TCustomListView; ColCount: Integer);
  304. begin
  305. inherited;
  306. end;
  307. procedure TIEListViewColProperties.SetParamsStr(Value: string);
  308. begin
  309. SortStr := CutToChar(Value, '|', True);
  310. inherited SetParamsStr(Value);
  311. end;
  312. procedure TIEListViewColProperties.SetSortAscending(Value: Boolean);
  313. begin
  314. TCustomIEListView(FListView).SortAscending := Value;
  315. end;
  316. procedure TIEListViewColProperties.SetSortColumn(Value: Integer);
  317. begin
  318. if SortColumn <> Value then
  319. begin
  320. TCustomIEListView(FListView).SortColumn := Value;
  321. Changed;
  322. end;
  323. end;
  324. function TIEListViewColProperties.GetParamsStr: string;
  325. begin
  326. Result := Format('%s|%s', [SortStr, inherited GetParamsStr]);
  327. end;
  328. function TIEListViewColProperties.GetSortAscending: Boolean;
  329. begin
  330. Result := TCustomIEListView(FListView).SortAscending;
  331. end;
  332. function TIEListViewColProperties.GetSortColumn: Integer;
  333. begin
  334. Result := TCustomIEListView(FListView).SortColumn;
  335. end;
  336. procedure TIEListViewColProperties.SetSortStr(Value: string);
  337. var
  338. ASortColumn: Integer;
  339. begin
  340. ASortColumn := StrToIntDef(CutToChar(Value, ';', True), SortColumn);
  341. if ASortColumn < Count then SortColumn := ASortColumn;
  342. SortAscending := Boolean(StrToIntDef(CutToChar(Value, ';', True), Integer(SortAscending)));
  343. end;
  344. function TIEListViewColProperties.GetSortStr: string;
  345. begin
  346. Result := Format('%d;%d', [SortColumn, Integer(SortAscending)]);
  347. end;
  348. { TCustomIEListView }
  349. constructor TCustomIEListView.Create(AOwner: TComponent);
  350. begin
  351. inherited;
  352. ColProperties.OnChange := ColPropertiesChange;
  353. FHeaderImages := nil;
  354. FShowColumnIcon := True;
  355. FSortColumn := 0;
  356. FSortAscending := True;
  357. FHeaderCanvas := TCanvas.Create;
  358. SetDateTimeFormatString;
  359. end; {Create}
  360. procedure TCustomIEListView.SetSortColumn(Value: Integer);
  361. begin
  362. if Value <> SortColumn then
  363. begin
  364. FSortColumn := Value;
  365. FSortAscending := True;
  366. if Items.Count > 0 then
  367. SortItems;
  368. SetColumnImages;
  369. end;
  370. end; {SetSortColumn}
  371. procedure TCustomIEListView.SetViewStyle(Value: TViewStyle);
  372. begin
  373. if Value <> ViewStyle then
  374. begin
  375. inherited SetViewStyle(Value);
  376. if ViewStyle = vsReport then
  377. SetColumnImages;
  378. end;
  379. end; {SetViewStyle}
  380. procedure TCustomIEListView.SetSortAscending(Value: Boolean);
  381. begin
  382. if SortAscending <> Value then
  383. begin
  384. FSortAscending := Value;
  385. if Items.Count > 0 then
  386. SortItems;
  387. SetColumnImages;
  388. end;
  389. end; {SetSortAscending}
  390. procedure TCustomIEListView.SetHeaderImages(Value: TImageList);
  391. begin
  392. if FHeaderImages <> Value then
  393. begin
  394. FHeaderImages := Value;
  395. if FHeaderHandle <> 0 then
  396. Header_SetImageList(FHeaderHandle, FHeaderImages.Handle);
  397. end;
  398. end;
  399. procedure TCustomIEListView.SetColumnImages;
  400. var
  401. HdItem: THdItem;
  402. Index: Integer;
  403. SecondaryColumn: Integer;
  404. Margin, MaxMargin: Integer;
  405. Caption: string;
  406. ShowImage: Boolean;
  407. AliasOnly: Boolean;
  408. begin
  409. if ShowColumnHeaders and HandleAllocated then
  410. begin
  411. for Index := 0 to Columns.Count-1 do
  412. begin
  413. HdItem.Mask := HDI_FORMAT;
  414. Header_GetItem(GetDlgItem(Self.Handle,0), Index, HdItem);
  415. Caption := TrimRight(Columns[Index].Caption);
  416. SecondaryColumn := SecondaryColumnHeader(Index, AliasOnly);
  417. ShowImage := False;
  418. if (HeaderImages <> nil) and FShowColumnIcon then
  419. begin
  420. if Index = SortColumn then ShowImage := True
  421. else
  422. if (SecondaryColumn >= 0) and (SecondaryColumn = SortColumn) then
  423. begin
  424. if AliasOnly then ShowImage := True
  425. else
  426. begin
  427. Margin := ColumnHeaderIconWidth +
  428. Canvas.TextWidth(Columns[SecondaryColumn].Caption);
  429. MaxMargin := Columns[Index].Width -
  430. SecondaryColumnHeaderOffset(Canvas, Index);
  431. if Margin <= MaxMargin then
  432. begin
  433. Caption := Caption +
  434. StringOfChar(' ', Margin div Canvas.TextWidth(' '));
  435. ShowImage := True;
  436. end;
  437. end;
  438. end;
  439. end;
  440. // for hidden columns, do not show the icon
  441. // as on some systems it is still drawn, but on neighboring columns
  442. if ShowImage and (Columns[Index].Width > 0) then
  443. begin
  444. HdItem.Mask := HDI_FORMAT or HDI_IMAGE;
  445. HdItem.fmt := Hditem.fmt or HDF_IMAGE;
  446. if SortAscending then
  447. begin
  448. HdItem.iImage := 0;
  449. HdItem.fmt := (Hditem.fmt or HDF_SORTUP) and (not HDF_SORTDOWN);
  450. end
  451. else
  452. begin
  453. HdItem.iImage := 1;
  454. HdItem.fmt := (Hditem.fmt or HDF_SORTDOWN) and (not HDF_SORTUP);
  455. end;
  456. if Columns[Index].Alignment = taLeftJustify then
  457. HdItem.fmt := HdItem.fmt or HDF_BITMAP_ON_RIGHT;
  458. end
  459. else
  460. begin
  461. HdItem.fmt := HdItem.fmt and
  462. (not (HDF_IMAGE or HDF_SORTUP or HDF_SORTDOWN));
  463. end;
  464. Columns[Index].Caption := Caption;
  465. Header_SetItem(GetDlgItem(Self.Handle, 0), Index, HDItem);
  466. end;
  467. FColumnIconPainted := True;
  468. end;
  469. end; {SetColumnImage}
  470. procedure TCustomIEListView.SetShowColumnIcon(Value: Boolean);
  471. begin
  472. if Value <> ShowColumnIcon then
  473. begin
  474. FShowColumnIcon := Value;
  475. SetColumnImages;
  476. end;
  477. end; {SetShowColumnIcon}
  478. function TCustomIEListView.SecondaryColumnHeaderOffset(Canvas: TCanvas; Index: Integer): Integer;
  479. begin
  480. Result :=
  481. 11 +
  482. Canvas.TextWidth(TrimRight(Columns[Index].Caption)) +
  483. ColumnHeaderIconWidth;
  484. end;
  485. function TCustomIEListView.ColumnHeaderIconWidth: Integer;
  486. begin
  487. Result := 12;
  488. if Assigned(HeaderImages) then
  489. Inc(Result, HeaderImages.Width);
  490. end;
  491. function TCustomIEListView.SecondaryColumnHeader(Index: Integer;
  492. var AliasOnly: Boolean): Integer;
  493. begin
  494. if Assigned(OnSecondaryColumnHeader) then
  495. begin
  496. OnSecondaryColumnHeader(Self, Index, Result);
  497. AliasOnly := True;
  498. end
  499. else
  500. begin
  501. Result := -1;
  502. AliasOnly := False;
  503. end;
  504. end;
  505. function TCustomIEListView.NewColProperties: TCustomListViewColProperties;
  506. begin
  507. Result := TIEListViewColProperties.Create(Self, 0);
  508. end;
  509. function TCustomIEListView.SortAscendingByDefault(Index: Integer): Boolean;
  510. begin
  511. Result := True;
  512. end;
  513. procedure TCustomIEListView.ColClick(Column: TListColumn);
  514. var
  515. Index: Integer;
  516. SecondaryColumn: Integer;
  517. SecondaryOffset: Integer;
  518. R: TRect;
  519. AliasOnly: Boolean;
  520. begin
  521. Index := Column.Index;
  522. SecondaryColumn := SecondaryColumnHeader(Index, AliasOnly);
  523. if SecondaryColumn >= 0 then
  524. begin
  525. if AliasOnly then Index := SecondaryColumn
  526. else
  527. begin
  528. Header_GetItemRect(FHeaderHandle, Index, @R);
  529. // this doesn't take possible vertical scroll into account!
  530. SecondaryOffset := Mouse.CursorPos.x - ClientToScreen(R.TopLeft).x;
  531. if SecondaryOffset >= SecondaryColumnHeaderOffset(Canvas, Index) then
  532. Index := SecondaryColumn;
  533. end;
  534. end;
  535. if Index = SortColumn then FSortAscending := not FSortAscending
  536. else
  537. begin
  538. FSortColumn := Index;
  539. FSortAscending := SortAscendingByDefault(Index);
  540. end;
  541. if Items.Count > 0 then SortItems;
  542. SetColumnImages;
  543. inherited;
  544. end; {ColClick}
  545. procedure TCustomIEListView.WMPaint(var Msg: TWMPaint);
  546. begin
  547. inherited;
  548. if (ViewStyle = vsReport) and not ColumnIconPainted and
  549. ShowColumnHeaders then SetColumnImages;
  550. end; {WMPaint}
  551. procedure TCustomIEListView.WMNotify(var Msg: TWMNotify);
  552. var
  553. SecondaryColumn: Integer;
  554. AliasOnly: Boolean;
  555. begin
  556. if (FHeaderHandle <> 0) and (Msg.NMHdr^.hWndFrom = FHeaderHandle) then
  557. case Msg.NMHdr.code of
  558. HDN_BEGINDRAG:
  559. {Due to a bug in D4 (until Update Pack 3) we should eat this message!};
  560. HDN_ENDDRAG:
  561. begin
  562. {Due to a bug in D4 (until Update Pack 3) we should eat this message!}
  563. HeaderEndDrag(Self);
  564. Invalidate;
  565. Exit;
  566. end;
  567. HDN_ENDTRACK, HDN_ENDTRACKW:
  568. begin
  569. SetColumnImages;
  570. FColumnIconPainted := False;
  571. Invalidate;
  572. inherited;
  573. if Assigned(FOnHeaderEndTrack) then
  574. FOnHeaderEndTrack(Self);
  575. Exit;
  576. end;
  577. HDN_DIVIDERDBLCLICK, HDN_DIVIDERDBLCLICKW:
  578. {Due to a bug in D4 (until Update Pack 3) the column property is
  579. not updated by this message:}
  580. begin
  581. inherited;
  582. with PHDNotify(Pointer(Msg.NMHdr))^ do
  583. if Columns.Count > Item then
  584. Columns[Item].Width := ListView_GetColumnWidth(Self.Handle, Item);
  585. if Assigned(FOnHeaderEndTrack) then
  586. FOnHeaderEndTrack(Self);
  587. SetColumnImages;
  588. FColumnIconPainted := False;
  589. Exit;
  590. end;
  591. NM_CUSTOMDRAW:
  592. with PNMCustomDraw(Msg.NMHdr)^ do
  593. begin
  594. inherited;
  595. if dwDrawStage = CDDS_PREPAINT then
  596. begin
  597. Msg.Result := Msg.Result or CDRF_NOTIFYITEMDRAW;
  598. end
  599. else
  600. if dwDrawStage = CDDS_ITEMPREPAINT then
  601. begin
  602. if (SecondaryColumnHeader(dwItemSpec, AliasOnly) >= 0) and (not AliasOnly) then
  603. Msg.Result := Msg.Result or CDRF_NOTIFYPOSTPAINT;
  604. end
  605. else
  606. if dwDrawStage = CDDS_ITEMPOSTPAINT then
  607. begin
  608. SecondaryColumn := SecondaryColumnHeader(dwItemSpec, AliasOnly);
  609. if (SecondaryColumn >= 0) and (not AliasOnly) then
  610. begin
  611. FHeaderCanvas.Handle := hdc;
  612. FHeaderCanvas.Font := Font;
  613. FHeaderCanvas.Brush := Brush;
  614. FHeaderCanvas.Brush.Style := bsClear;
  615. if (uItemState and CDIS_SELECTED) <> 0 then
  616. begin
  617. Inc(rc.top);
  618. Inc(rc.left);
  619. end;
  620. Inc(rc.left, SecondaryColumnHeaderOffset(FHeaderCanvas, dwItemSpec));
  621. Inc(rc.top,
  622. ((rc.bottom - rc.top) -
  623. FHeaderCanvas.TextHeight(Columns[SecondaryColumn].Caption)) div 2);
  624. DrawText(FHeaderCanvas.Handle, PChar(Columns[SecondaryColumn].Caption),
  625. Length(Columns[SecondaryColumn].Caption), rc, 0);
  626. end;
  627. end;
  628. Exit;
  629. end;
  630. end; {Case}
  631. inherited;
  632. end; { TCustomIEListView.WMNotify }
  633. procedure TCustomIEListView.HeaderEndDrag(Sender : TObject);
  634. begin
  635. if Assigned(FOnHeaderEndDrag) then
  636. FOnHeaderEndDrag(Self);
  637. end; {HeaderEndDrag}
  638. procedure TCustomIEListView.Loaded;
  639. begin
  640. inherited;
  641. FHeaderHandle := ListView_GetHeader(Self.Handle);
  642. if (FHeaderImages <> nil) and (FHeaderHandle <> 0) then
  643. Header_SetImageList(FHeaderHandle, FHeaderImages.Handle);
  644. end; {Loaded}
  645. procedure TCustomIEListView.ColPropertiesChange(Sender: TObject);
  646. begin
  647. SetColumnImages;
  648. end;
  649. procedure TCustomIEListView.CreateWnd;
  650. begin
  651. inherited;
  652. FParentForm := GetParentForm(Self);
  653. if not (csDesigning in ComponentState) then
  654. FDragImageList := TDragImageList.Create(Self);
  655. if not Assigned(GlobalDragImageList) then
  656. GlobalDragImageList := DragImageList;
  657. end; {CreateWnd}
  658. destructor TCustomIEListView.Destroy;
  659. begin
  660. if Assigned(FDragImageList) then
  661. begin
  662. if GlobalDragImageList = FDragImageList then
  663. GlobalDragImageList := nil;
  664. FDragImageList.Free;
  665. end;
  666. FHeaderCanvas.Free;
  667. inherited;
  668. end; {Destroy}
  669. procedure TCustomIEListView.SetDateTimeDisplay(Value: TDateTimeDisplay);
  670. begin
  671. if Value <> FDateTimeDisplay then
  672. begin
  673. FDateTimeDisplay := Value;
  674. SetDateTimeFormatString;
  675. Invalidate;
  676. end;
  677. end; {SetDateTimeDisplay}
  678. procedure TCustomIEListView.SetDateTimeFormatString;
  679. var
  680. ShortDate: string;
  681. begin
  682. ShortDate := UpperCase(ShortDateFormat);
  683. {Create DateTime format string:}
  684. if Pos('YYYY', UpperCase(ShortDate)) = 0 then
  685. begin
  686. if Copy(UpperCase(ShortDate), Length(ShortDate) - 1, 2) = 'YY' then
  687. FDateTimeFormatStr := ShortDateFormat + 'yy'
  688. else
  689. if Copy(UpperCase(ShortDate), 1, 2) = 'YY' then
  690. FDateTimeFormatStr := 'yy' + ShortDateFormat;
  691. end
  692. else FDateTimeFormatStr := ShortDateFormat;
  693. FDateFormatStr := FDateTimeFormatStr;
  694. if FDateTimeDisplay = dtdDateTimeSec then
  695. FDateTimeFormatStr := FDateTimeFormatStr + ' ' + LongTimeFormat
  696. else
  697. if fDateTimeDisplay = dtdDateTime then
  698. FDateTimeFormatStr := FDateTimeFormatStr + ' ' + ShortTimeFormat;
  699. end; {SetDateTimeFormatString}
  700. procedure TCustomIEListView.SortItems;
  701. begin
  702. AlphaSort;
  703. end;
  704. end.