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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
|
/*
* 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 215
#define WINDOW_HEIGHT 85
HIMAGELIST himagelist;
LRESULT CALLBACK proc_ctrlwnd( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
{
XINE_UI * xine_ui = ( XINE_UI * ) GetWindowLong( hwnd, GWL_USERDATA );
switch( msg )
{
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_PLAY_BTTN )
{
xine_ui->Play( 0 );
return 0L;
}
if( cid == ID_STOP_BTTN )
{
xine_ui->Stop();
return 0L;
}
if( cid == ID_PAUSE_BTTN )
{
xine_ui->SetSpeed( XINE_SPEED_PAUSE );
return 0L;
}
if( cid == ID_NEXT_BTTN )
{
xine_ui->Stop();
xine_ui->Play( xine_ui->playindex + 1 );
return 0L;
}
if( cid == ID_PREV_BTTN )
{
xine_ui->Stop();
xine_ui->Play( xine_ui->playindex - 1 );
return 0L;
}
if( cid == ID_RWND_BTTN )
{
int current_speed = xine_ui->GetSpeed();
if( current_speed == XINE_SPEED_FAST_4 )
xine_ui->SetSpeed( XINE_SPEED_FAST_2 );
else if( current_speed == XINE_SPEED_FAST_2 )
xine_ui->SetSpeed( XINE_SPEED_NORMAL );
else if( current_speed == XINE_SPEED_NORMAL )
xine_ui->SetSpeed( XINE_SPEED_SLOW_2 );
else if( current_speed == XINE_SPEED_SLOW_2 )
xine_ui->SetSpeed( XINE_SPEED_SLOW_4 );
else if( current_speed == XINE_SPEED_SLOW_4 )
xine_ui->SetSpeed( XINE_SPEED_PAUSE );
return 0L;
}
if( cid == ID_FFWD_BTTN )
{
int current_speed = xine_ui->GetSpeed();
if( current_speed == XINE_SPEED_PAUSE )
xine_ui->SetSpeed( XINE_SPEED_SLOW_4 );
else if( current_speed == XINE_SPEED_SLOW_4 )
xine_ui->SetSpeed( XINE_SPEED_SLOW_2 );
else if( current_speed == XINE_SPEED_SLOW_2 )
xine_ui->SetSpeed( XINE_SPEED_NORMAL );
else if( current_speed == XINE_SPEED_NORMAL )
xine_ui->SetSpeed( XINE_SPEED_FAST_2 );
else if( current_speed == XINE_SPEED_FAST_2 )
xine_ui->SetSpeed( XINE_SPEED_FAST_4 );
return 0L;
}
if( cid == ID_EJECT_BTTN )
{
xine_ui->init_playlistwnd();
return 0L;
}
}
case WM_HSCROLL:
{
int code = ( int ) LOWORD( wparam );
HWND hctrl = ( HWND ) lparam;
switch( code )
{
case TB_THUMBTRACK:
xine_ui->tracking = true;
break;
case TB_LINEUP:
case TB_LINEDOWN:
case TB_PAGEUP:
case TB_PAGEDOWN:
case TB_TOP:
case TB_BOTTOM:
case TB_ENDTRACK:
{
int new_time = SendMessage( hctrl, TBM_GETPOS, (WPARAM) 0, (LPARAM) 0 );
xine_ui->SetTime( new_time );
xine_ui->tracking = false;
return 0L;
}
}
}
break;
case WM_DESTROY:
// Cleanup and close the app
PostQuitMessage( 0 );
return 0L;
}
return DefWindowProc( hwnd, msg, wparam, lparam);
}
bool ToolbarAddButton( HWND htoolbar, int dataindex, int id )
{
// define and add icon buttons
TBBUTTON button;
button.iBitmap = dataindex;
button.idCommand = id;
button.fsState = TBSTATE_ENABLED;
button.fsStyle = TBSTYLE_BUTTON;
button.iString = dataindex;
if( !SendMessage( htoolbar, TB_ADDBUTTONS, (UINT) 1, (LPARAM) &button ) )
return false;
return true;
}
bool ToolbarAddDivider( HWND htoolbar )
{
// define and add icon divider
TBBUTTON button;
button.iBitmap = 0;
button.idCommand = 0;
button.fsState = TBSTATE_ENABLED;
button.fsStyle = TBSTYLE_SEP;
button.iString = 0;
if( !SendMessage( htoolbar, TB_ADDBUTTONS, (UINT) 1, (LPARAM) &button ) )
return false;
return true;
}
bool XINE_UI::init_ctrlwnd()
{
WNDCLASSEX wc;
// register our window class
wc.cbSize = sizeof( wc );
wc.lpszClassName = TEXT( "xinectrlwindow" );
wc.lpfnWndProc = proc_ctrlwnd;
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( "Error RegisterClassEx : for xinectrlwindow" );
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 the ctrl window
hctrlwnd = CreateWindowEx( 0,
TEXT( "xinectrlwindow" ),
TEXT( "xine" ),
WS_SYSMENU,
CW_USEDEFAULT, CW_USEDEFAULT,
dwWindowWidth, dwWindowHeight,
NULL,
NULL,
hinst,
NULL );
if( !hctrlwnd )
{
error( "Error CreateWindowEx : for xinectrlwindow" );
return 0;
}
// create our panel window ( handles its own error reporting )
init_panelwnd();
if( !hpanelwnd )
return false;
SetWindowPos( hpanelwnd, HWND_TOP, 5, 5, WINDOW_WIDTH - 5, 50, SWP_SHOWWINDOW );
// create our time slider
HWND htimebar = CreateWindowEx( WS_EX_TOOLWINDOW,
TRACKBAR_CLASS,
"Trackbar Control",
WS_CHILD | WS_VISIBLE | TBS_ENABLESELRANGE | TBS_NOTICKS,
0, 0,
0, 0,
hctrlwnd,
(HMENU) ID_TIMEBAR,
hinst,
0 );
if( !htimebar )
{
error( "Error CreateWindowEx : for TRACKBAR_CLASS ( time )" );
return false;
}
SendMessage( htimebar, TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG( 0, 1000 ) );
SendMessage( htimebar, TBM_SETPAGESIZE, 0, (LPARAM) 1 );
SendMessage( htimebar, TBM_SETSEL, (WPARAM) FALSE, (LPARAM) MAKELONG( 0, 0 ) );
SendMessage( htimebar, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) 0 );
SetWindowPos( htimebar, HWND_TOP, 5, 60, WINDOW_WIDTH - 10, 17, SWP_SHOWWINDOW );
// create our button toolbar
HWND htoolbar = CreateWindowEx( WS_EX_TOOLWINDOW,
TOOLBARCLASSNAME,
0,
WS_CHILDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN |
TBSTYLE_TRANSPARENT | TBSTYLE_FLAT | CCS_NODIVIDER |
CCS_NOPARENTALIGN,
0, 0,
0, 0,
hctrlwnd,
(HMENU) ID_TOOLBAR,
hinst,
0 );
if( !htoolbar )
{
error( "Error CreateWindowEx : for TOOLBARCLASSNAME" );
return false;
}
SendMessage( htoolbar, TB_BUTTONSTRUCTSIZE, sizeof( TBBUTTON ), 0 );
// create the toolbar image list
COLORREF TransColor = RGB( 255, 0, 255 );
himagelist = ImageList_Create( 11, 11, ILC_COLOR8 | ILC_MASK, 0, 7 );
HBITMAP h_bmp_play_button = LoadBitmap( hinst, MAKEINTRESOURCE( bmp_play_button ) );
HBITMAP h_bmp_pause_button = LoadBitmap( hinst, MAKEINTRESOURCE( bmp_pause_button ) );
HBITMAP h_bmp_stop_button = LoadBitmap( hinst, MAKEINTRESOURCE( bmp_stop_button ) );
HBITMAP h_bmp_prev_button = LoadBitmap( hinst, MAKEINTRESOURCE( bmp_prev_button ) );
HBITMAP h_bmp_rwind_button = LoadBitmap( hinst, MAKEINTRESOURCE( bmp_rwind_button ) );
HBITMAP h_bmp_fforward_button = LoadBitmap( hinst, MAKEINTRESOURCE( bmp_fforward_button ) );
HBITMAP h_bmp_next_button = LoadBitmap( hinst, MAKEINTRESOURCE( bmp_next_button ) );
HBITMAP h_bmp_eject_button = LoadBitmap( hinst, MAKEINTRESOURCE( bmp_eject_button ) );
ImageList_AddMasked( himagelist, h_bmp_play_button, TransColor );
ImageList_AddMasked( himagelist, h_bmp_pause_button, TransColor );
ImageList_AddMasked( himagelist, h_bmp_stop_button, TransColor );
ImageList_AddMasked( himagelist, h_bmp_prev_button, TransColor );
ImageList_AddMasked( himagelist, h_bmp_rwind_button, TransColor );
ImageList_AddMasked( himagelist, h_bmp_fforward_button, TransColor );
ImageList_AddMasked( himagelist, h_bmp_next_button, TransColor );
ImageList_AddMasked( himagelist, h_bmp_eject_button, TransColor );
DeleteObject( h_bmp_play_button );
DeleteObject( h_bmp_pause_button );
DeleteObject( h_bmp_stop_button );
DeleteObject( h_bmp_prev_button );
DeleteObject( h_bmp_rwind_button );
DeleteObject( h_bmp_fforward_button );
DeleteObject( h_bmp_next_button );
DeleteObject( h_bmp_eject_button );
SendMessage( htoolbar, TB_SETIMAGELIST, 0, (LPARAM) himagelist );
SendMessage( htoolbar, TB_SETBITMAPSIZE, 0, (LPARAM) MAKELONG( 11, 11 ) );
SendMessage( htoolbar, TB_SETBUTTONSIZE, 0, (LPARAM) MAKELONG( 22, 18 ) );
// add our buttons to our toolbar
ToolbarAddButton( htoolbar, 0, ID_PLAY_BTTN );
ToolbarAddButton( htoolbar, 1, ID_PAUSE_BTTN );
ToolbarAddButton( htoolbar, 2, ID_STOP_BTTN );
ToolbarAddDivider( htoolbar );
ToolbarAddButton( htoolbar, 3, ID_PREV_BTTN );
ToolbarAddButton( htoolbar, 4, ID_RWND_BTTN );
ToolbarAddButton( htoolbar, 5, ID_FFWD_BTTN );
ToolbarAddButton( htoolbar, 6, ID_NEXT_BTTN );
ToolbarAddDivider( htoolbar );
ToolbarAddButton( htoolbar, 7, ID_EJECT_BTTN );
SetWindowPos( htoolbar, HWND_TOP, 10, 80, 100, 100, SWP_SHOWWINDOW );
// show the ctrl window
ShowWindow( hctrlwnd, SW_SHOW );
UpdateWindow( hctrlwnd );
SetWindowLong( hctrlwnd, GWL_USERDATA, ( long ) this );
return true;
}
void XINE_UI::end_ctrlwnd()
{
end_panelwnd();
ImageList_Destroy( himagelist );
HWND htoolbar = GetDlgItem( hctrlwnd, ID_TOOLBAR );
DestroyWindow( htoolbar );
HWND htimebar = GetDlgItem( hctrlwnd, ID_TIMEBAR );
DestroyWindow( htimebar );
DestroyWindow( hctrlwnd );
UnregisterClass( "xinectrlwindow", hinst );
}
bool _XINE_UI::UpdateCtrl()
{
if( gGui->stream )
{
if( mode == XINE_STATUS_PLAY )
{
/*mrl_time_current = xine_get_current_time( gGui->stream );*/
if (xine_get_pos_length(gGui->stream, 0, &mrl_time_current, 0))
{
mrl_time_current /= 1000;
if( !tracking )
{
HWND htimebar = GetDlgItem( hctrlwnd, ID_TIMEBAR );
SendMessage( htimebar, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) mrl_time_current );
}
}
}
}
return true;
}
DWORD __stdcall update_loop_helper( void * param )
{
XINE_UI * xine_ui = ( XINE_UI * ) param;
while( xine_ui->mode == XINE_STATUS_PLAY )
{
xine_ui->UpdateCtrl();
xine_ui->UpdatePanel();
Sleep( 500 );
}
return 0;
}
DWORD XINE_UI::UpdateLoop()
{
// start ctrl update loop
DWORD panel_loop_id;
CreateThread( 0, 0, &update_loop_helper, ( void * ) this, 0, &panel_loop_id );
return 0;
}
|