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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
|
/*
* Copyright (C) 2000-2001 the xine project
*
* This file is part of xine for win32 video player.
*
* xine is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* xine is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
* Xine win32 UI
* by Matthew Grooms <elon@altavista.com>
*/
#include "xineui.h"
#define WINDOW_WIDTH 200
#define WINDOW_HEIGHT 200
HFONT hfont;
bool AddPlaylistColumn( HWND hlistwnd, int width, int index )
{
LV_COLUMN lvCol;
lvCol.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_WIDTH;
lvCol.fmt = LVCFMT_LEFT;
lvCol.cx = width;
lvCol.iSubItem = index;
int columnindex = SendMessage( hlistwnd, LVM_INSERTCOLUMN, ( WPARAM ) index, ( LPARAM ) &lvCol );
if( columnindex == -1 )
return false;
return true;
}
bool AddPlaylistItem( HWND hlistwnd, void * lparam )
{
int itemcount = ListView_GetItemCount( hlistwnd );
LV_ITEM newItem;
newItem.mask = LVIF_PARAM | LVIF_TEXT;
newItem.iItem = itemcount;
newItem.iSubItem = 0;
newItem.pszText = LPSTR_TEXTCALLBACK;
newItem.lParam = ( long ) lparam;
if( SendMessage( hlistwnd, LVM_INSERTITEM, 0, ( LPARAM ) &newItem ) == -1 )
return false;
return true;
}
void ResizeChildren( HWND hplaylistwnd )
{
RECT rect;
GetClientRect( hplaylistwnd, &rect );
HWND hstauswnd = GetDlgItem( hplaylistwnd, ID_STATUS );
SetWindowPos( hstauswnd, HWND_TOP,
rect.left + 5, rect.bottom - 25,
rect.right - rect.left - 10, 20,
SWP_SHOWWINDOW );
HWND hlistwnd = GetDlgItem( hplaylistwnd, ID_LIST );
SetWindowPos( hlistwnd, HWND_TOP,
rect.left + 5, rect.top + 5,
rect.right - rect.left - 55, rect.bottom - rect.top - 30,
SWP_SHOWWINDOW );
HWND haddwnd = GetDlgItem( hplaylistwnd, ID_ADD );
SetWindowPos( haddwnd, HWND_TOP,
rect.right - 40, rect.top + 5,
35, 20,
SWP_SHOWWINDOW );
HWND hdelwnd = GetDlgItem( hplaylistwnd, ID_DEL );
SetWindowPos( hdelwnd, HWND_TOP,
rect.right - 40, rect.top + 30,
35, 20,
SWP_SHOWWINDOW );
GetClientRect( hlistwnd, &rect );
SendMessage( hlistwnd, LVM_SETCOLUMNWIDTH, 1, rect.right - rect.left - 22 );
}
LRESULT CALLBACK proc_playlistwnd( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
{
XINE_UI * xine_ui = ( XINE_UI * ) GetWindowLong( hwnd, GWL_USERDATA );
switch( msg )
{
case WM_NOTIFY:
{
int controlid = ( int ) wparam;
NMHDR * lpnm = ( NMHDR * ) lparam;
NMLVDISPINFO * nmlvdi = ( NMLVDISPINFO * ) lparam;
if( lpnm->code == LVN_GETDISPINFO )
{
PLAYITEM * playitem = ( PLAYITEM * ) ( nmlvdi->item.lParam );
// first column
if( nmlvdi->item.iSubItem == 0 )
nmlvdi->item.iImage = playitem->mrl_type;
// second column
if( nmlvdi->item.iSubItem == 1 )
nmlvdi->item.pszText = playitem->mrl_short_name;
}
return 0L;
}
break;
case WM_COMMAND:
{
WORD ncode = HIWORD( wparam ); // notification code
WORD cid = LOWORD( wparam ); // item, control, or accelerator identifier
HWND chwnd = ( HWND ) lparam; // handle of control
if( cid == ID_ADD )
{
OPENFILENAME ofn; // common dialog box structure
char tmpbuff[ 2048 ]; // buffer for filename
memset( &tmpbuff, 0, sizeof( tmpbuff ) );
memset( &ofn, 0, sizeof( OPENFILENAME ) );
ofn.lStructSize = sizeof( OPENFILENAME );
ofn.hwndOwner = hwnd;
ofn.lpstrFile = tmpbuff;
ofn.nMaxFile = sizeof( tmpbuff );
ofn.lpstrFilter = "All\0*.*\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = 0;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = 0;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT | OFN_EXPLORER;
// Display the Open dialog box.
if( GetOpenFileName( &ofn ) )
{
HWND hlistwnd = GetDlgItem( hwnd, ID_LIST );
char * szItem = tmpbuff;
char szLength = strlen( szItem );
// did we get multiple files
if( !szItem[ szLength + 1 ] )
{
// single file
// add to playlist and to listview
PLAYITEM * playitem = xine_ui->PlaylistAdd( szItem + ofn.nFileOffset, szItem, 0 );
AddPlaylistItem( hlistwnd, playitem );
}
else
{
// multiple files
szItem = szItem + szLength + 1;
szLength = strlen( szItem );
while( szLength )
{
char tmpfname[ 1024 ];
sprintf( tmpfname, "%s\\%s", tmpbuff, szItem );
// add to playlist and to listview
PLAYITEM * playitem = xine_ui->PlaylistAdd( szItem, tmpfname, 0 );
AddPlaylistItem( hlistwnd, playitem );
szItem = szItem + szLength + 1;
szLength = strlen( szItem );
}
}
xine_ui->Play( xine_ui->playindex );
}
return 0L;
}
if( cid == ID_DEL )
{
HWND hlistwnd = GetDlgItem( hwnd, ID_LIST );
int lvindex;
while( ( lvindex = ListView_GetNextItem( hlistwnd, -1, LVNI_SELECTED ) ) != -1 )
{
LVITEM lvitem;
lvitem.mask = LVIF_PARAM;
lvitem.iItem = lvindex;
ListView_GetItem( hlistwnd, &lvitem );
PLAYITEM * playitem = ( PLAYITEM * ) lvitem.lParam;
if( xine_ui->PlaylistDel( lvindex ) )
ListView_DeleteItem( hlistwnd, lvindex );
}
xine_ui->Play( xine_ui->playindex );
return 0L;
}
}
break;
case WM_SIZE:
{
ResizeChildren( hwnd );
return 0L;
}
case WM_DESTROY:
{
xine_ui->end_playlistwnd();
return 0L;
}
}
return DefWindowProc( hwnd, msg, wparam, lparam);
}
bool XINE_UI::init_playlistwnd()
{
// if our playlist is already open, return
if( hplaylistwnd )
return true;
WNDCLASSEX wc;
// register our window class
wc.cbSize = sizeof( wc );
wc.lpszClassName = TEXT( "xineplaylistwindow" );
wc.lpfnWndProc = proc_playlistwnd;
wc.style = CS_VREDRAW | CS_HREDRAW;
wc.hInstance = hinst;
wc.hIcon = LoadIcon( hinst, MAKEINTRESOURCE( ico_xine_logo ) );
wc.hIconSm = LoadIcon( hinst, MAKEINTRESOURCE( ico_xine_logo ) );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = ( HBRUSH ) ( 1 + COLOR_BTNFACE );
wc.lpszMenuName = 0;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
if( !RegisterClassEx( &wc ) )
{
error( "init_videownd : cannot register window class" );
return false;
}
// calculate the proper size for the windows given client size
DWORD dwFrameWidth = GetSystemMetrics( SM_CXSIZEFRAME );
DWORD dwFrameHeight = GetSystemMetrics( SM_CYSIZEFRAME );
DWORD dwMenuHeight = GetSystemMetrics( SM_CYMENU );
DWORD dwCaptionHeight = GetSystemMetrics( SM_CYCAPTION );
DWORD dwWindowWidth = WINDOW_WIDTH + dwFrameWidth * 2;
DWORD dwWindowHeight = WINDOW_HEIGHT + dwFrameHeight * 2 +
dwMenuHeight + dwCaptionHeight;
// create and show the main window
hplaylistwnd = CreateWindowEx( 0,
TEXT( "xineplaylistwindow" ),
TEXT( "xine Playlist" ),
WS_POPUP | WS_CAPTION | WS_CHILD | WS_SIZEBOX | WS_SYSMENU,
CW_USEDEFAULT, CW_USEDEFAULT,
dwWindowWidth, dwWindowHeight,
hctrlwnd,
NULL,
hinst,
NULL );
if( !hplaylistwnd )
{
error( "init_playlistwnd : cannot create video window" );
return false;
}
ShowWindow( hplaylistwnd, SW_SHOW );
UpdateWindow( hplaylistwnd );
SetWindowLong( hplaylistwnd, GWL_USERDATA, ( long ) this );
if( !CreateStatusWindow( WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP,
"Add or Delete files from the playlist",
hplaylistwnd,
ID_STATUS ) )
{
error( "CreateStatusWindow : cannot create status window" );
return false;
}
hfont = CreateFont( 13, // logical height of font
5, // logical average character width
0, // angle of escapement
0, // base-line orientation angle
0, // font weight
0, // italic attribute flag
0, // underline attribute flag
0, // strikeout attribute flag
0, // character set identifier
0, // output precision
0, // clipping precision
PROOF_QUALITY, // output quality
FF_MODERN | VARIABLE_PITCH , // pitch and family
"Areal" ); // pointer to typeface name string
if( !hfont )
{
error( "CreateFont : cannot create font" );
return false;
}
HWND hlistwnd = CreateWindowEx( WS_EX_STATICEDGE,
WC_LISTVIEW,
0,
WS_CHILD | WS_VISIBLE | LVS_REPORT | LVS_NOCOLUMNHEADER,
0, 0,
0, 0,
hplaylistwnd,
( HMENU ) ID_LIST,
hinst,
NULL );
if( !hlistwnd )
{
error( "CreateWindow : cannot create list view" );
return false;
}
AddPlaylistColumn( hlistwnd, 20, 0 );
AddPlaylistColumn( hlistwnd, 100, 1 );
SendMessage( hlistwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, ( LPARAM ) LVS_EX_FULLROWSELECT );
SendMessage( hlistwnd, WM_SETFONT, ( WPARAM ) hfont, MAKELPARAM( TRUE, 0 ) );
ListView_SetBkColor( hlistwnd, RGB( 0, 0, 0 ) );
ListView_SetTextBkColor( hlistwnd, RGB( 0, 0, 0 ) );
ListView_SetTextColor( hlistwnd, RGB( 255, 255, 255 ) );
HWND haddwnd = CreateWindow( "BUTTON",
TEXT( "Add" ),
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
0, 0,
0, 0,
hplaylistwnd,
( HMENU ) ID_ADD,
hinst,
NULL );
if( !haddwnd )
{
error( "CreateWindow : cannot create add button" );
return false;
}
SendMessage( haddwnd, WM_SETFONT, ( WPARAM ) hfont, MAKELPARAM( TRUE, 0 ) );
HWND hdelwnd = CreateWindow( "BUTTON",
TEXT( "Del" ),
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
0, 0,
0, 0,
hplaylistwnd,
( HMENU ) ID_DEL,
hinst,
NULL );
if( !hdelwnd )
{
error( "CreateWindow : cannot create del button" );
return false;
}
SendMessage( hdelwnd, WM_SETFONT, ( WPARAM ) hfont, MAKELPARAM( TRUE, 0 ) );
// resize all playlist window children
ResizeChildren( hplaylistwnd );
// add all playlist items to view
for( int x = 0; x < playcount; x++ )
AddPlaylistItem( hlistwnd, playlist[ x ] );
return true;
}
void XINE_UI::end_playlistwnd()
{
DestroyWindow( hplaylistwnd );
UnregisterClass( "xineplaylistwindow", hinst );
hplaylistwnd = 0;
}
|