]> git.sesse.net Git - vlc/blob - modules/gui/qt4/main_interface_win32.cpp
macosx: removed wrong check, which could make the video output disappear when leaving...
[vlc] / modules / gui / qt4 / main_interface_win32.cpp
1 /*****************************************************************************
2  * main_interface_win32.cpp : Main interface
3  ****************************************************************************
4  * Copyright (C) 2006-2010 VideoLAN and AUTHORS
5  * $Id$
6  *
7  * Authors: Jean-Baptiste Kempf <jb@videolan.org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24
25 #include "main_interface.hpp"
26
27 #include "input_manager.hpp"
28 #include "actions_manager.hpp"
29
30 #include <QBitmap>
31 #include <vlc_windows_interfaces.h>
32
33 #define WM_APPCOMMAND 0x0319
34
35 #define APPCOMMAND_VOLUME_MUTE            8
36 #define APPCOMMAND_VOLUME_DOWN            9
37 #define APPCOMMAND_VOLUME_UP              10
38 #define APPCOMMAND_MEDIA_NEXTTRACK        11
39 #define APPCOMMAND_MEDIA_PREVIOUSTRACK    12
40 #define APPCOMMAND_MEDIA_STOP             13
41 #define APPCOMMAND_MEDIA_PLAY_PAUSE       14
42 #define APPCOMMAND_LAUNCH_MEDIA_SELECT    16
43 #define APPCOMMAND_BASS_DOWN              19
44 #define APPCOMMAND_BASS_BOOST             20
45 #define APPCOMMAND_BASS_UP                21
46 #define APPCOMMAND_TREBLE_DOWN            22
47 #define APPCOMMAND_TREBLE_UP              23
48 #define APPCOMMAND_MICROPHONE_VOLUME_MUTE 24
49 #define APPCOMMAND_MICROPHONE_VOLUME_DOWN 25
50 #define APPCOMMAND_MICROPHONE_VOLUME_UP   26
51 #define APPCOMMAND_DICTATE_OR_COMMAND_CONTROL_TOGGLE    43
52 #define APPCOMMAND_MIC_ON_OFF_TOGGLE      44
53 #define APPCOMMAND_MEDIA_PLAY             46
54 #define APPCOMMAND_MEDIA_PAUSE            47
55 #define APPCOMMAND_MEDIA_RECORD           48
56 #define APPCOMMAND_MEDIA_FAST_FORWARD     49
57 #define APPCOMMAND_MEDIA_REWIND           50
58 #define APPCOMMAND_MEDIA_CHANNEL_UP       51
59 #define APPCOMMAND_MEDIA_CHANNEL_DOWN     52
60
61 #define FAPPCOMMAND_MOUSE 0x8000
62 #define FAPPCOMMAND_KEY   0
63 #define FAPPCOMMAND_OEM   0x1000
64 #define FAPPCOMMAND_MASK  0xF000
65
66 #define GET_APPCOMMAND_LPARAM(lParam) ((short)(HIWORD(lParam) & ~FAPPCOMMAND_MASK))
67 #define GET_DEVICE_LPARAM(lParam)     ((WORD)(HIWORD(lParam) & FAPPCOMMAND_MASK))
68 #define GET_MOUSEORKEY_LPARAM         GET_DEVICE_LPARAM
69 #define GET_FLAGS_LPARAM(lParam)      (LOWORD(lParam))
70 #define GET_KEYSTATE_LPARAM(lParam)   GET_FLAGS_LPARAM(lParam)
71
72 void MainInterface::createTaskBarButtons()
73 {
74     /*Here is the code for the taskbar thumb buttons
75     FIXME:We need pretty buttons in 16x16 px that are handled correctly by masks in Qt
76     FIXME:the play button's picture doesn't changed to pause when clicked
77     */
78
79     CoInitialize( 0 );
80
81     if( S_OK == CoCreateInstance( CLSID_TaskbarList,
82                 NULL, CLSCTX_INPROC_SERVER,
83                 IID_ITaskbarList3,
84                 (void **)&p_taskbl) )
85     {
86         p_taskbl->HrInit();
87
88         if( (himl = ImageList_Create( 20, //cx
89                         20, //cy
90                         ILC_COLOR32,//flags
91                         4,//initial nb of images
92                         0//nb of images that can be added
93                         ) ) != NULL )
94         {
95             QPixmap img   = QPixmap(":/win7/prev");
96             QPixmap img2  = QPixmap(":/win7/pause");
97             QPixmap img3  = QPixmap(":/win7/play");
98             QPixmap img4  = QPixmap(":/win7/next");
99             QBitmap mask  = img.createMaskFromColor(Qt::transparent);
100             QBitmap mask2 = img2.createMaskFromColor(Qt::transparent);
101             QBitmap mask3 = img3.createMaskFromColor(Qt::transparent);
102             QBitmap mask4 = img4.createMaskFromColor(Qt::transparent);
103
104             if(-1 == ImageList_Add(himl, img.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask.toWinHBITMAP()))
105                 msg_Err( p_intf, "First ImageList_Add failed" );
106             if(-1 == ImageList_Add(himl, img2.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask2.toWinHBITMAP()))
107                 msg_Err( p_intf, "Second ImageList_Add failed" );
108             if(-1 == ImageList_Add(himl, img3.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask3.toWinHBITMAP()))
109                 msg_Err( p_intf, "Third ImageList_Add failed" );
110             if(-1 == ImageList_Add(himl, img4.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask4.toWinHBITMAP()))
111                 msg_Err( p_intf, "Fourth ImageList_Add failed" );
112         }
113
114         // Define an array of two buttons. These buttons provide images through an
115         // image list and also provide tooltips.
116         THUMBBUTTONMASK dwMask = THUMBBUTTONMASK(THB_BITMAP | THB_FLAGS);
117
118         THUMBBUTTON thbButtons[3];
119         thbButtons[0].dwMask = dwMask;
120         thbButtons[0].iId = 0;
121         thbButtons[0].iBitmap = 0;
122         thbButtons[0].dwFlags = THBF_HIDDEN;
123
124         thbButtons[1].dwMask = dwMask;
125         thbButtons[1].iId = 1;
126         thbButtons[1].iBitmap = 2;
127         thbButtons[1].dwFlags = THBF_HIDDEN;
128
129         thbButtons[2].dwMask = dwMask;
130         thbButtons[2].iId = 2;
131         thbButtons[2].iBitmap = 3;
132         thbButtons[2].dwFlags = THBF_HIDDEN;
133
134         HRESULT hr = p_taskbl->ThumbBarSetImageList(winId(), himl );
135         if(S_OK != hr)
136             msg_Err( p_intf, "ThumbBarSetImageList failed with error %08lx", hr );
137         else
138         {
139             hr = p_taskbl->ThumbBarAddButtons(winId(), 3, thbButtons);
140             if(S_OK != hr)
141                 msg_Err( p_intf, "ThumbBarAddButtons failed with error %08lx", hr );
142         }
143         CONNECT( THEMIM->getIM(), playingStatusChanged( int ), this, changeThumbbarButtons( int ) );
144     }
145     else
146     {
147         himl = NULL;
148         p_taskbl = NULL;
149     }
150
151 }
152
153 bool MainInterface::winEvent ( MSG * msg, long * result )
154 {
155     if (msg->message == taskbar_wmsg)
156     {
157         //We received the taskbarbuttoncreated, now we can really create the buttons
158         createTaskBarButtons();
159     }
160
161     short cmd;
162     switch( msg->message )
163     {
164         case WM_COMMAND:
165             if (HIWORD(msg->wParam) == THBN_CLICKED)
166             {
167                 switch(LOWORD(msg->wParam))
168                 {
169                     case 0:
170                         THEMIM->prev();
171                         break;
172                     case 1:
173                         THEMIM->togglePlayPause();
174                         break;
175                     case 2:
176                         THEMIM->next();
177                         break;
178                 }
179             }
180             break;
181         case WM_APPCOMMAND:
182             cmd = GET_APPCOMMAND_LPARAM(msg->lParam);
183
184             if( p_intf->p_sys->disable_volume_keys &&
185                     (   cmd == APPCOMMAND_VOLUME_DOWN   ||
186                         cmd == APPCOMMAND_VOLUME_UP     ||
187                         cmd == APPCOMMAND_VOLUME_MUTE ) )
188             {
189                 break;
190             }
191
192             *result = TRUE;
193
194             switch(cmd)
195             {
196                 case APPCOMMAND_MEDIA_PLAY_PAUSE:
197                     THEMIM->togglePlayPause();
198                     break;
199                 case APPCOMMAND_MEDIA_PLAY:
200                     THEMIM->play();
201                     break;
202                 case APPCOMMAND_MEDIA_PAUSE:
203                     THEMIM->pause();
204                     break;
205                 case APPCOMMAND_MEDIA_CHANNEL_DOWN:
206                 case APPCOMMAND_MEDIA_PREVIOUSTRACK:
207                     THEMIM->prev();
208                     break;
209                 case APPCOMMAND_MEDIA_CHANNEL_UP:
210                 case APPCOMMAND_MEDIA_NEXTTRACK:
211                     THEMIM->next();
212                     break;
213                 case APPCOMMAND_MEDIA_STOP:
214                     THEMIM->stop();
215                     break;
216                 case APPCOMMAND_MEDIA_RECORD:
217                     THEAM->record();
218                     break;
219                 case APPCOMMAND_VOLUME_DOWN:
220                     THEAM->AudioDown();
221                     break;
222                 case APPCOMMAND_VOLUME_UP:
223                     THEAM->AudioUp();
224                     break;
225                 case APPCOMMAND_VOLUME_MUTE:
226                     THEAM->toggleMuteAudio();
227                     break;
228                 default:
229                      msg_Dbg( p_intf, "unknown APPCOMMAND = %d", cmd);
230                      *result = FALSE;
231                      break;
232             }
233             if (*result) return true;
234             break;
235     }
236     return false;
237 }
238
239 void MainInterface::changeThumbbarButtons( int i_status )
240 {
241     if( p_taskbl == NULL )
242         return;
243
244     // Define an array of three buttons. These buttons provide images through an
245     // image list and also provide tooltips.
246     THUMBBUTTONMASK dwMask = THUMBBUTTONMASK(THB_BITMAP | THB_FLAGS);
247
248     THUMBBUTTON thbButtons[3];
249     //prev
250     thbButtons[0].dwMask = dwMask;
251     thbButtons[0].iId = 0;
252     thbButtons[0].iBitmap = 0;
253
254     //play/pause
255     thbButtons[1].dwMask = dwMask;
256     thbButtons[1].iId = 1;
257
258     //next
259     thbButtons[2].dwMask = dwMask;
260     thbButtons[2].iId = 2;
261     thbButtons[2].iBitmap = 3;
262
263     switch( i_status )
264     {
265         case OPENING_S:
266         case PLAYING_S:
267             {
268                 thbButtons[0].dwFlags = THBF_ENABLED;
269                 thbButtons[1].dwFlags = THBF_ENABLED;
270                 thbButtons[2].dwFlags = THBF_ENABLED;
271                 thbButtons[1].iBitmap = 1;
272                 break;
273             }
274         case END_S:
275         case PAUSE_S:
276         case ERROR_S:
277             {
278                 thbButtons[0].dwFlags = THBF_ENABLED;
279                 thbButtons[1].dwFlags = THBF_ENABLED;
280                 thbButtons[2].dwFlags = THBF_ENABLED;
281                 thbButtons[1].iBitmap = 2;
282                 break;
283             }
284         default:
285             return;
286     }
287     HRESULT hr =  p_taskbl->ThumbBarUpdateButtons(this->winId(), 3, thbButtons);
288     if(S_OK != hr)
289         msg_Err( p_intf, "ThumbBarUpdateButtons failed with error %08lx", hr );
290 }