-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTitleSearch.pas
279 lines (238 loc) · 7.86 KB
/
TitleSearch.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
unit TitleSearch;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, SBFiles, Appear, ExtCtrls;
type
TFTitle = class(TForm)
ESong: TEdit;
LBSongs: TListBox;
BCancel: TButton;
BOk: TButton;
PButtons: TPanel;
procedure FormActivate(Sender: TObject);
procedure ESongChange(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure BCancelClick(Sender: TObject);
procedure ESongKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure BOkClick(Sender: TObject);
procedure LBSongsDblClick(Sender: TObject);
procedure LBSongsKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure LBSongsEnter(Sender: TObject);
procedure LBSongsClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure LBSongsDrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
procedure FormCanResize(Sender: TObject; var NewWidth,
NewHeight: Integer; var Resize: Boolean);
private
{ Private declarations }
Results : TStringList;
// Used to keep this window off the projection screen
procedure WMWindowPosChanging(var hMsg: TWMWindowPosChanging); message WM_WINDOWPOSCHANGING;
public
FileName : string;
ResultSong : integer;
ResultID : string;
PosX,PosY : integer;
Initial : string;
MoreThan : string;
FirstQuickSearch : integer;
CroppedLyrics : boolean;
{ Public declarations }
end;
var
FTitle: TFTitle;
BigSonglist : TStringlist;
MiniSonglist : TStringlist;
iSongCount : integer;
aUsed : array of boolean;
implementation
uses SBMain, EditProj, PageCache;
{$R *.DFM}
procedure TFTitle.FormActivate(Sender: TObject);
begin
Results := nil;
SetLength(aUsed,0);
ESong.Text:= Initial;
ESongChange(Sender);
ESong.SetFocus;
ESong.SelStart := Length(Initial);
FirstQuickSearch := 0;
CroppedLyrics := false;
end;
procedure TFTitle.ESongChange(Sender: TObject);
var i : integer;
SR : SongRecord;
begin
if Results <> nil then Results.free;
iSongCount := 0;
SetLength(aUsed, 0);
CroppedLyrics := false;
Results := PageCache_SearchTitles( ESong.Text );
FirstQuickSearch := Results.Count;
LBSongs.items.clear;
if Results.Count > 10 then begin
LBSongs.items.add(MoreThan);
LBSongs.enabled:=false;
end else begin
LBSongs.enabled:=true;
if( FSettings.cbSearchLyrics.Checked and
(Results.Count < FSettings.iMinSearchLyrics)) then begin
CroppedLyrics := not PageCache_TextSearch( ESong.Text, Results,
10 - FirstQuickSearch, true, false );
if CroppedLyrics then Results.Delete( Results.Count-1 );
end;
iSongCount := Results.Count;
SetLength(aUsed, iSongCount);
for i := 0 to iSongCount-1 do begin
if Copy(Results[i],1,1) = '~' then begin
Results[i] := copy( Results[i], 2, length(Results[i]) );
PageCache_GetSong( Results[i], SR );
LBSongs.Items.Add( SR.AltTitle + ' [' + SR.Title +']' );
end else begin
LBSongs.Items.Add( PageCache_GetSongName( Results[i] ) );
end;
// if FSettings.cbGrayUnusedSearch
begin
PageCache_GetSong( Results[i], SR );
aUsed[i] := (SR.OHP <> '0');
end;
end;
if 0 = LBSongs.Items.Count then LBSongs.Enabled := false;
if LBSongs.ItemIndex = -1 then LBSongs.ItemIndex := 0;
if CroppedLyrics then LBSongs.Items.Add( MoreThan );
end;
BOK.Enabled := LBSongs.Enabled;
end;
procedure TFTitle.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if Results <> nil then Results.free;
BigSonglist.free;
MiniSonglist.free;
PosX:=left;
PosY:=top;
end;
procedure TFTitle.BCancelClick(Sender: TObject);
begin
resultsong:=-1;
close;
end;
procedure TFTitle.ESongKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Key=VK_DOWN) and LBSongs.Enabled then begin
LBSongs.ItemIndex := LBSongs.ItemIndex + 1;
Key := 0;
end;
if (Key=VK_UP) and LBSongs.Enabled and (LBSongs.ItemIndex > 0) then begin
LBSongs.ItemIndex := LBSongs.ItemIndex - 1;
Key := 0;
end;
end;
procedure TFTitle.BOkClick(Sender: TObject);
begin
if LBSongs.Items.Count > 0 then begin
if LBSongs.ItemIndex=-1 then LBSongs.ItemIndex:=0;
LBSongsDblClick(Sender);
end else close;
end;
procedure TFTitle.LBSongsDblClick(Sender: TObject);
var S2 : string;
found : integer;
begin
S2 := Results[LBSongs.ItemIndex];
PageCache_EnsureID( S2, found );
ResultSong := found + 1;
close;
end;
procedure TFTitle.LBSongsKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Key=VK_RETURN) and (LBSongs.ItemIndex>=0) then LBSongsDblClick(Sender);
end;
procedure TFTitle.LBSongsEnter(Sender: TObject);
begin
if LBSongs.ItemIndex>=0 then BOk.Enabled:=true;
end;
procedure TFTitle.LBSongsClick(Sender: TObject);
begin
BOk.Enabled:=(LBSongs.ItemIndex>=0);
end;
procedure TFTitle.FormShow(Sender: TObject);
begin
if (PosX<0) then PosX:=0;
if (PosY<0) then PosY:=0;
top:=PosY;
left:=PosX;
BigSonglist:=TStringlist.create;
BigSonglist.sorted:=true;
MiniSongList:=TStringlist.create;
MiniSonglist.sorted:=true;
resultsong:=-1;
end;
procedure TFTitle.WMWindowPosChanging(var hMsg: TWMWindowPosChanging);
var rBadRect, rCurRect : TRect;
var ptBadCentre : TPoint;
begin
// Only restrict access once projection form is visible
if FSongbase.BProjectReady and FProjWin.Visible then begin
// Get the desktop rectangle that we don't want to let this screen have
// any intersections with.
rBadRect := Rect( FSongBase.ptDisplayOrigin.X,
FSongBase.ptDisplayOrigin.Y,
FSongBase.ptDisplayOrigin.X + FSongBase.szDisplaySize.cx,
FSongBase.ptDisplayOrigin.Y + FSongBase.szDisplaySize.cy );
rCurRect := Rect( hMsg.WindowPos.x, hMsg.WindowPos.y,
hMsg.WindowPos.x + Width, hMsg.WindowPos.y + Height );
// Work out centre of 'illegal' area so we can work out which side to push off
ptBadCentre.X := FSongBase.ptDisplayOrigin.X + (FSongBase.szDisplaySize.cx div 2);
ptBadCentre.Y := FSongBase.ptDisplayOrigin.Y + (FSongBase.szDisplaySize.cy div 2);
// And do the logic to prevent overlap in X
if (rCurRect.Right < ptBadCentre.X) and (rCurRect.Right > rBadRect.Left) then begin
rCurRect.Left := rBadRect.Left - (rCurRect.Right - rCurRect.Left);
rCurRect.Right := rBadRect.Left;
end;
if (rCurRect.Left > ptBadCentre.X) and (rCurRect.Left < rBadRect.Right) then begin
rCurRect.Right := rBadRect.Right + (rCurRect.Right - rCurRect.Left);
rCurRect.Left := rBadRect.Right;
end;
hMsg.WindowPos.x := rCurRect.Left;
hMsg.WindowPos.y := rCurRect.Top;
end;
inherited;
end;
procedure TFTitle.LBSongsDrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
Offset: Integer; { text offset width }
Lister: TListBox;
begin
Lister := (Control as TListBox);
Font.Style := [];
with Lister.Canvas do
begin
if (Index < iSongCount) and aUsed[Index] then begin
Font.Style := Font.Style + [fsBold];
end;
FillRect(Rect); { clear the rectangle }
Offset := 2; { provide default offset }
if not Lister.Enabled then Font.Color := clGray;
if CroppedLyrics and (Index = Lister.Count-1) then Font.Color := clGray
else
if (Index < iSongCount) and
(Index >= FirstQuickSearch) then begin
Font.Style := Font.Style + [fsItalic];
// if Font.Color = clWindowText then Font.Color := clBlue;
end;
TextOut(Rect.Left + Offset, Rect.Top, Lister.Items[Index]) { display the text }
end;
end;
procedure TFTitle.FormCanResize(Sender: TObject; var NewWidth,
NewHeight: Integer; var Resize: Boolean);
begin
NewHeight := Height;
end;
end.