-
Notifications
You must be signed in to change notification settings - Fork 1
/
CutlistSearchResults.pas
180 lines (145 loc) · 4.67 KB
/
CutlistSearchResults.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
unit CutlistSearchResults;
{$I Information.inc}
// basic review and reformatting: done
interface
uses
// Delphi
Winapi.Windows, System.Classes, System.SysUtils, Vcl.Forms, Vcl.Controls, Vcl.ComCtrls, Vcl.StdCtrls, Vcl.ExtCtrls;
type
TFCutlistSearchResults = class(TForm)
pnlButtons: TPanel;
lvLinklist: TListView;
cmdCancel: TButton;
cmdOk: TButton;
procedure lvLinklistClick(Sender: TObject);
procedure cmdOkClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure lvLinklistCustomDrawSubItem(Sender: TCustomListView; Item: TListItem; SubItem: Integer; State: TCustomDrawState; var DefaultDraw: Boolean);
procedure lvLinklistColumnClick(Sender: TObject; Column: TListColumn);
procedure lvLinklistCompare(Sender: TObject; Item1, Item2: TListItem; Data: Integer; var Compare: Integer);
private
{ private declarations }
SortColNr: Integer; // first col = 1, neg values = desc
procedure SortByColumn(Number: Integer);
public
{ public declarations }
MovieTypeName: string;
end;
var
FCutlistSearchResults: TFCutlistSearchResults;
implementation
{$R *.dfm}
uses
// Delphi
Winapi.CommCtrl, System.Math, Vcl.Graphics,
// CA
Main, Utils;
{ TFCutlistSearchResults }
procedure TFCutlistSearchResults.FormClose(Sender: TObject; var Action: TCloseAction);
var
S: string;
I: Integer;
begin
// Save window size and column widths
S := Format('%d,%d', [Width, Height]);
for I := 0 to Pred(lvLinklist.Columns.Count) do
S := S + Format(',%d', [lvLinklist.Columns[I].Width]);
S := S + Format(',%d', [SortColNr]);
Settings.Additional[ClassName] := S;
end;
procedure TFCutlistSearchResults.FormCreate(Sender: TObject);
var
S: string;
function GetOneInt: Integer;
begin
Result := StrToIntDef(StringToken(S, ','), 0);
end;
var
W,H,I: Integer;
begin
// Restore window size and column widths
S := Settings.Additional[ClassName];
if S <> '' then
begin
W := GetOneInt;
H := GetOneInt;
if (W > 0) and (H > 0) then
begin
Width := W;
Height := H;
// Columns
for I := 0 to Pred(lvLinklist.Columns.Count) do
lvLinklist.Columns[I].Width := GetOneInt;
// Sort
I := GetOneInt;
if I <> 0 then
SortByColumn(I);
end;
end;
end;
procedure TFCutlistSearchResults.lvLinklistClick(Sender: TObject);
begin
if lvLinklist.ItemIndex >= 0 then
ModalResult := mrOK;
end;
procedure TFCutlistSearchResults.lvLinklistColumnClick(Sender: TObject; Column: TListColumn);
begin
SortByColumn(Succ(Column.Index));
end;
procedure TFCutlistSearchResults.lvLinklistCompare(Sender: TObject; Item1, Item2: TListItem; Data: Integer; var Compare: Integer);
var
I:Integer;
begin
if Abs(SortColNr) > 1 then // 1 = first col
begin
I := Abs(SortColNr) - 2;
Compare := Sign(SortColNr) * CompareText(Item1.SubItems[I], Item2.SubItems[I]);
end else
Compare := Sign(SortColNr) * CompareText(Item1.Caption, Item2.Caption)
end;
procedure TFCutlistSearchResults.lvLinklistCustomDrawSubItem(Sender: TCustomListView; Item: TListItem; SubItem: Integer; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
if SubItem = 2 then
begin
if MovieTypeName = Item.SubItems[1] then
lvLinklist.Canvas.Brush.Color := clMoneyGreen
else
lvLinklist.Canvas.Brush.Color := clWebLightYellow;
end else
lvLinklist.Canvas.Brush.Color := ColorToRGB(lvLinklist.Color);
end;
procedure TFCutlistSearchResults.SortByColumn(Number: Integer);
var
Header: HWND;
Item: THDItem;
begin
Header := ListView_GetHeader(lvLinklist.Handle);
ZeroMemory(@Item, SizeOf(Item));
Item.Mask := HDI_FORMAT;
if Abs(SortColNr) <> Abs(Number) then // other col
begin
if SortColNr <> 0 then
begin
Header_GetItem(Header, Pred(Abs(SortColNr)), Item);
Item.fmt := Item.fmt and not (HDF_SORTUP or HDF_SORTDOWN);
Header_SetItem(Header, Pred(Abs(SortColNr)), Item);
end;
SortColNr := Number;
end else
SortColNr := - SortColNr; // switch asc/desc
lvLinklist.AlphaSort;
Header_GetItem(Header, Pred(Abs(SortColNr)), Item);
Item.fmt := Item.fmt and not (HDF_SORTUP or HDF_SORTDOWN);
if SortColNr < 0 then
Item.fmt := Item.fmt or HDF_SORTDOWN
else
Item.fmt := Item.fmt or HDF_SORTUP;
Header_SetItem(Header, Pred(Abs(SortColNr)), Item);
end;
procedure TFCutlistSearchResults.cmdOkClick(Sender: TObject);
begin
if lvLinklist.ItemIndex >= 0 then
ModalResult := mrOk;
end;
end.