1 /*****************************************************************************
2 * main_interface_win32.cpp : Main interface
3 ****************************************************************************
4 * Copyright (C) 2006-2010 VideoLAN and AUTHORS
7 * Authors: Jean-Baptiste Kempf <jb@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
25 #include "main_interface.hpp"
27 #include "input_manager.hpp"
28 #include "actions_manager.hpp"
29 #include "dialogs_provider.hpp"
32 #include <vlc_windows_interfaces.h>
34 #define WM_APPCOMMAND 0x0319
36 #define APPCOMMAND_VOLUME_MUTE 8
37 #define APPCOMMAND_VOLUME_DOWN 9
38 #define APPCOMMAND_VOLUME_UP 10
39 #define APPCOMMAND_MEDIA_NEXTTRACK 11
40 #define APPCOMMAND_MEDIA_PREVIOUSTRACK 12
41 #define APPCOMMAND_MEDIA_STOP 13
42 #define APPCOMMAND_MEDIA_PLAY_PAUSE 14
43 #define APPCOMMAND_LAUNCH_MEDIA_SELECT 16
44 #define APPCOMMAND_BASS_DOWN 19
45 #define APPCOMMAND_BASS_BOOST 20
46 #define APPCOMMAND_BASS_UP 21
47 #define APPCOMMAND_TREBLE_DOWN 22
48 #define APPCOMMAND_TREBLE_UP 23
49 #define APPCOMMAND_MICROPHONE_VOLUME_MUTE 24
50 #define APPCOMMAND_MICROPHONE_VOLUME_DOWN 25
51 #define APPCOMMAND_MICROPHONE_VOLUME_UP 26
52 #define APPCOMMAND_HELP 27
53 #define APPCOMMAND_OPEN 30
54 #define APPCOMMAND_DICTATE_OR_COMMAND_CONTROL_TOGGLE 43
55 #define APPCOMMAND_MIC_ON_OFF_TOGGLE 44
56 #define APPCOMMAND_MEDIA_PLAY 46
57 #define APPCOMMAND_MEDIA_PAUSE 47
58 #define APPCOMMAND_MEDIA_RECORD 48
59 #define APPCOMMAND_MEDIA_FAST_FORWARD 49
60 #define APPCOMMAND_MEDIA_REWIND 50
61 #define APPCOMMAND_MEDIA_CHANNEL_UP 51
62 #define APPCOMMAND_MEDIA_CHANNEL_DOWN 52
64 #define FAPPCOMMAND_MOUSE 0x8000
65 #define FAPPCOMMAND_KEY 0
66 #define FAPPCOMMAND_OEM 0x1000
67 #define FAPPCOMMAND_MASK 0xF000
69 #define GET_APPCOMMAND_LPARAM(lParam) ((short)(HIWORD(lParam) & ~FAPPCOMMAND_MASK))
70 #define GET_DEVICE_LPARAM(lParam) ((WORD)(HIWORD(lParam) & FAPPCOMMAND_MASK))
71 #define GET_MOUSEORKEY_LPARAM GET_DEVICE_LPARAM
72 #define GET_FLAGS_LPARAM(lParam) (LOWORD(lParam))
73 #define GET_KEYSTATE_LPARAM(lParam) GET_FLAGS_LPARAM(lParam)
75 void MainInterface::createTaskBarButtons()
77 /*Here is the code for the taskbar thumb buttons
78 FIXME:We need pretty buttons in 16x16 px that are handled correctly by masks in Qt
79 FIXME:the play button's picture doesn't changed to pause when clicked
84 if( S_OK == CoCreateInstance( CLSID_TaskbarList,
85 NULL, CLSCTX_INPROC_SERVER,
91 if( (himl = ImageList_Create( 20, //cx
94 4,//initial nb of images
95 0//nb of images that can be added
98 QPixmap img = QPixmap(":/win7/prev");
99 QPixmap img2 = QPixmap(":/win7/pause");
100 QPixmap img3 = QPixmap(":/win7/play");
101 QPixmap img4 = QPixmap(":/win7/next");
102 QBitmap mask = img.createMaskFromColor(Qt::transparent);
103 QBitmap mask2 = img2.createMaskFromColor(Qt::transparent);
104 QBitmap mask3 = img3.createMaskFromColor(Qt::transparent);
105 QBitmap mask4 = img4.createMaskFromColor(Qt::transparent);
107 if(-1 == ImageList_Add(himl, img.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask.toWinHBITMAP()))
108 msg_Err( p_intf, "First ImageList_Add failed" );
109 if(-1 == ImageList_Add(himl, img2.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask2.toWinHBITMAP()))
110 msg_Err( p_intf, "Second ImageList_Add failed" );
111 if(-1 == ImageList_Add(himl, img3.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask3.toWinHBITMAP()))
112 msg_Err( p_intf, "Third ImageList_Add failed" );
113 if(-1 == ImageList_Add(himl, img4.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask4.toWinHBITMAP()))
114 msg_Err( p_intf, "Fourth ImageList_Add failed" );
117 // Define an array of two buttons. These buttons provide images through an
118 // image list and also provide tooltips.
119 THUMBBUTTONMASK dwMask = THUMBBUTTONMASK(THB_BITMAP | THB_FLAGS);
121 THUMBBUTTON thbButtons[3];
122 thbButtons[0].dwMask = dwMask;
123 thbButtons[0].iId = 0;
124 thbButtons[0].iBitmap = 0;
125 thbButtons[0].dwFlags = THBF_HIDDEN;
127 thbButtons[1].dwMask = dwMask;
128 thbButtons[1].iId = 1;
129 thbButtons[1].iBitmap = 2;
130 thbButtons[1].dwFlags = THBF_HIDDEN;
132 thbButtons[2].dwMask = dwMask;
133 thbButtons[2].iId = 2;
134 thbButtons[2].iBitmap = 3;
135 thbButtons[2].dwFlags = THBF_HIDDEN;
137 HRESULT hr = p_taskbl->ThumbBarSetImageList(winId(), himl );
139 msg_Err( p_intf, "ThumbBarSetImageList failed with error %08lx", hr );
142 hr = p_taskbl->ThumbBarAddButtons(winId(), 3, thbButtons);
144 msg_Err( p_intf, "ThumbBarAddButtons failed with error %08lx", hr );
146 CONNECT( THEMIM->getIM(), playingStatusChanged( int ), this, changeThumbbarButtons( int ) );
156 bool MainInterface::winEvent ( MSG * msg, long * result )
158 if (msg->message == taskbar_wmsg)
160 //We received the taskbarbuttoncreated, now we can really create the buttons
161 createTaskBarButtons();
165 switch( msg->message )
168 if (HIWORD(msg->wParam) == THBN_CLICKED)
170 switch(LOWORD(msg->wParam))
176 THEMIM->togglePlayPause();
185 cmd = GET_APPCOMMAND_LPARAM(msg->lParam);
187 if( p_intf->p_sys->disable_volume_keys &&
188 ( cmd == APPCOMMAND_VOLUME_DOWN ||
189 cmd == APPCOMMAND_VOLUME_UP ||
190 cmd == APPCOMMAND_VOLUME_MUTE ) )
199 case APPCOMMAND_MEDIA_PLAY_PAUSE:
200 THEMIM->togglePlayPause();
202 case APPCOMMAND_MEDIA_PLAY:
205 case APPCOMMAND_MEDIA_PAUSE:
208 case APPCOMMAND_MEDIA_CHANNEL_DOWN:
209 case APPCOMMAND_MEDIA_PREVIOUSTRACK:
212 case APPCOMMAND_MEDIA_CHANNEL_UP:
213 case APPCOMMAND_MEDIA_NEXTTRACK:
216 case APPCOMMAND_MEDIA_STOP:
219 case APPCOMMAND_MEDIA_RECORD:
222 case APPCOMMAND_VOLUME_DOWN:
225 case APPCOMMAND_VOLUME_UP:
228 case APPCOMMAND_VOLUME_MUTE:
229 THEAM->toggleMuteAudio();
231 case APPCOMMAND_MEDIA_FAST_FORWARD:
232 THEMIM->getIM()->faster();
234 case APPCOMMAND_MEDIA_REWIND:
235 THEMIM->getIM()->slower();
237 case APPCOMMAND_HELP:
238 THEDP->mediaInfoDialog();
240 case APPCOMMAND_OPEN:
241 THEDP->simpleOpenDialog();
244 msg_Dbg( p_intf, "unknown APPCOMMAND = %d", cmd);
248 if (*result) return true;
254 void MainInterface::changeThumbbarButtons( int i_status )
256 if( p_taskbl == NULL )
259 // Define an array of three buttons. These buttons provide images through an
260 // image list and also provide tooltips.
261 THUMBBUTTONMASK dwMask = THUMBBUTTONMASK(THB_BITMAP | THB_FLAGS);
263 THUMBBUTTON thbButtons[3];
265 thbButtons[0].dwMask = dwMask;
266 thbButtons[0].iId = 0;
267 thbButtons[0].iBitmap = 0;
270 thbButtons[1].dwMask = dwMask;
271 thbButtons[1].iId = 1;
274 thbButtons[2].dwMask = dwMask;
275 thbButtons[2].iId = 2;
276 thbButtons[2].iBitmap = 3;
283 thbButtons[0].dwFlags = THBF_ENABLED;
284 thbButtons[1].dwFlags = THBF_ENABLED;
285 thbButtons[2].dwFlags = THBF_ENABLED;
286 thbButtons[1].iBitmap = 1;
293 thbButtons[0].dwFlags = THBF_ENABLED;
294 thbButtons[1].dwFlags = THBF_ENABLED;
295 thbButtons[2].dwFlags = THBF_ENABLED;
296 thbButtons[1].iBitmap = 2;
302 HRESULT hr = p_taskbl->ThumbBarUpdateButtons(this->winId(), 3, thbButtons);
304 msg_Err( p_intf, "ThumbBarUpdateButtons failed with error %08lx", hr );