The Winamp Remote Control suite
a remote control client and plugin for Winamp 2.x, 5.x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
PlaylistF.cpp
Go to the documentation of this file.
1 /*
2 winamp remote control suite ŠPatrick Michael Martin 2000, 2001, 2002
3 
4 Copyright (C) 2000,2001,2002 Patrick M. Martin
5 
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 
20 Patrick M. Martin may be reached by email at patrickmmartin@gmail.com.
21 */
22 
23 
24 #include <vcl.h>
25 #pragma hdrstop
26 
27 #include "PlaylistF.h"
28 #include "waint.h"
29 #include "MainF.h"
30 #include "shellapi.h"
31 #include "remotestrs.h"
32 #include "remoteDM.h"
33 
34 
35 #pragma package(smart_init)
36 #pragma resource "*.dfm"
37 
38 #include "winampinterface.h" // header file generated by MIDL compiler
39 
40 const int Offset = 4;
41 
43 
44 __fastcall TfrmPlaylist::TfrmPlaylist(TComponent* Owner)
45  : TForm(Owner), _currentpos(0), _lastindex(0), _lastlength(0)
46 {
47 }
48 
49 
50 void __fastcall TfrmPlaylist::lstSongsDblClick(TObject *)
51 {
52 
53  // this action will use the playlist itemindex, and do the pre and post actions
54  dmRemote->NewSong->Execute();
55 
56 }
57 
58 void __fastcall TfrmPlaylist::FormCreate(TObject *)
59 {
60 
61  lstSongs->ItemHeight = Canvas->TextHeight('W');
62 
63  dmRemote->registerForm(this);
64  dmRemote->PlaylistRefresh->Execute();
65 
66 }
67 
68 
69 
70 void __fastcall TfrmPlaylist::DeleteSelected(void)
71 {
73 
74 }
75 
76 // debug stuffs
77 /*
78 
79 odSelected, odGrayed, odDisabled, odChecked, odFocused, odDefault, odHotLight, odInactive,
80  odNoAccel, odNoFocusRect, odReserved1, odReserved2, odComboBoxEdit
81 
82 */
83 
84 const char* States[odComboBoxEdit + 1] =
85 {"odSelected", "odGrayed", "odDisabled", "odChecked", "odFocused", "odDefault", "odHotLight", "odInactive",
86  "odNoAccel", "odNoFocusRect", "odReserved1", "odReserved2", "odComboBoxEdit"
87 };
88 
89 void itemState(TOwnerDrawState State)
90 {
91  AnsiString setstr;
92 
93  for (Windows__1 i = odSelected ; i < odComboBoxEdit ; i++)
94  {
95  if (State.Contains(i))
96  setstr += AnsiString(States[i]) + " ";
97  }
98 }
99 
100  void __fastcall TfrmPlaylist::lstSongsDrawItem(TWinControl *Control, int Index, const TRect &Rect, TOwnerDrawState State)
101 {
102  TListBox * ListBox = (TListBox *) Control;
103  AnsiString ItemText = ListBox->Items->Strings[Index];
104  TCanvas * Canvas = ListBox->Canvas;
105 
106  if (State.Contains(odFocused))
107  return;
108 
109  itemState(State);
110 
111  if (Index == frmMain->CurrentIndex)
112  Canvas->Font->Color = clRed;
113 
114  itemState(State);
115 
116  Canvas->TextOut(Rect.Left + Offset, Rect.Top, ItemText);
117 
118  if (Index == frmMain->CurrentIndex)
119  Canvas->Font->Color = clWindowText;
120 
121 }
122 
123  void __fastcall TfrmPlaylist::lstSongsDrawItemGlass(TWinControl *Control,
124  int Index, const TRect &Rect,
125  TOwnerDrawState State)
126 {
127  TListBox * ListBox = (TListBox *) Control;
128  AnsiString ItemText = ListBox->Items->Strings[Index];
129  TCanvas * Canvas = ListBox->Canvas;
130 
131  if (State.Contains(odFocused))
132  return;
133 
134  itemState(State);
135 
136  // paints now accumulate, so this is needed
137  Canvas->FillRect(Rect);
138  ge->drawGlowText(Canvas->Handle, ItemText, Rect, (Index == frmMain->CurrentIndex) );
139 }
140 
141 
142 void __fastcall TfrmPlaylist::DropFiles(TMessage& Msg)
143 {
144  int len, i;
145  char CFileName[MAX_PATH];
146  std::auto_ptr<TStringList> Files(new TStringList);
147  void * hDrop = (void *) Msg.WParam;
148  TPoint DropPoint;
149 
150  int DropIndex;
151  DragQueryPoint(hDrop, &DropPoint);
152 
153  // this returns -1 if there was no hit item
154  DropIndex = lstSongs->ItemAtPos(DropPoint, true);
155 
156  // this gets the dragged files list and passes them onto the form
157  len = DragQueryFile((void *) hDrop, 0xFFFFFFFF, NULL, 0);
158  for (i = 0 ; i < len ; i++){
159  if (DragQueryFile((void *) hDrop, i, CFileName, MAX_PATH) > 0){
160  Files->Add(CFileName);
161  }
162  }
163  dmRemote->DropFiles(Files.get(), DropIndex);
164  DragFinish((void *) Msg.WParam);
165 
166 }
167 
168 void __fastcall TfrmPlaylist::lstSongsDragOver(TObject *, TObject *, int , int , TDragState , bool &Accept)
169 {
170  Accept = true;
171 }
172 
173 
174 void __fastcall TfrmPlaylist::lstSongsDragDrop(TObject *, TObject *, int X, int Y)
175 {
176  int DropIndex = lstSongs->ItemAtPos(TPoint(X, Y), false);
177 
178  dmRemote->PlaylistDragDrop(DropIndex, _currentpos);
179 
180 
181 }
182 
183 
184 
185 void __fastcall TfrmPlaylist::FormShow(TObject *)
186 {
187  ge = new GlassExtender(this);
188  if (ge->isCompositionActive())
189  {
190  lstSongs->Color = clNone;
191  lstSongs->BorderStyle = bsNone;
192 
193  pnlBottom->Color = clNone;
194  pnlBottom->BorderStyle = bsNone;
195 
196  sbPlaylist->Color = clNone;
197  lstSongs->OnDrawItem = lstSongsDrawItemGlass;
198  }
199  // need to re-assert this
200  DragAcceptFiles(lstSongs->Handle, true);
201 }
202 
203 
204 
205 void __fastcall TfrmPlaylist::lstSongsMouseMove(TObject *, TShiftState , int X, int Y)
206 {
207 
208  int Index = lstSongs->ItemAtPos(TPoint(X, Y), true);
209 
210  if (Index > -1)
211  {
212  if (lstSongs->Canvas->TextWidth(lstSongs->Items->Strings[Index]) > lstSongs->ClientWidth - Offset)
213  {
214  lstSongs->Hint = lstSongs->Items->Strings[Index];
215  }
216  else
217  lstSongs->Hint = "";
218 
219  }
220  else
221  {
222  lstSongs->Hint = sPlaylistHint;
223  }
224 
225 }
226 
227 
228 
229 
230 void __fastcall TfrmPlaylist::mnuPlayClick(TObject *)
231 {
232 
233  if (BelowIndex > -1)
234  {
235  lstSongs->ItemIndex = BelowIndex;
236  lstSongsDblClick(this);
237  }
238 
239 }
240 
241 
242 
243 
244 void __fastcall TfrmPlaylist::pmnuSongsPopup(TObject *)
245 {
246 
247  BelowIndex = lstSongs->ItemAtPos(lstSongs->ScreenToClient(Mouse->CursorPos), true);
248  mnuPlay->Enabled = (BelowIndex > -1);
249  if (BelowIndex > -1)
250  mnuPlay->Caption = lstSongs->Items->Strings[BelowIndex];
251  else
252  mnuPlay->Caption = sPlay;
253 
254 
255 }
256 
257 
258 
259 
260 void __fastcall TfrmPlaylist::lstSongsKeyDown(TObject *, WORD &Key, TShiftState )
261 {
262 
263  switch (Key)
264  {
265  case VK_DELETE:
266  DeleteSelected(); break;
267  case VK_RETURN :
268  lstSongsDblClick(this); break;
269  case VK_F5 :
270  mnuRefreshClick(this); break;
271 
272  }
273 
274 }
275 
276 
277 
278 
279 void __fastcall TfrmPlaylist::pbSongPosMouseUp(TObject *, TMouseButton , TShiftState , int , int )
280 {
281 
282  fDragging = false;
283 
284 }
285 
286 
287 
288 
289 void __fastcall TfrmPlaylist::pbSongPosMouseMove(TObject *, TShiftState , int X, int Y)
290 {
291 
292  if (fDragging)
293  {
294  if (PtInRect(&(pbSongPos->ClientRect), TPoint(X,Y)))
295  {
296  pbSongPos->Position = (pbSongPos->Max * X) / pbSongPos->ClientWidth;
297  dmRemote->SetSongPosition(X, pbSongPos->ClientWidth);
298 
299  }
300  }
301 
302 
303 }
304 
305 
306 
307 
308 void __fastcall TfrmPlaylist::pbSongPosMouseDown(TObject *, TMouseButton , TShiftState , int , int )
309 {
310  fDragging = true;
311 }
312 
313 
314 void __fastcall TfrmPlaylist::mnuRefreshClick(TObject *)
315 {
316  dmRemote->PlaylistRefresh->Execute();
317 }
318 
319 
320 void __fastcall TfrmPlaylist::lstSongsMeasureItem(TWinControl *, int , int &Height)
321 {
322  Height = 17;
323 }
324 
325 
326 void __fastcall TfrmPlaylist::FormDestroy(TObject *Sender)
327 {
328  dmRemote->unRegisterForm(this);
329 }
330 //---------------------------------------------------------------------------
331