]> git.sesse.net Git - vlc/blob - modules/gui/qt4/main_interface_win32.cpp
be786ccb6f9e6eeec8f52a4d36eb253f4d15e793
[vlc] / modules / gui / qt4 / main_interface_win32.cpp
1 /*****************************************************************************
2  * main_interface.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     taskbar_wmsg = WM_NULL;
75     /*Here is the code for the taskbar thumb buttons
76     FIXME:We need pretty buttons in 16x16 px that are handled correctly by masks in Qt
77     FIXME:the play button's picture doesn't changed to pause when clicked
78     */
79
80     CoInitialize( 0 );
81
82     if( S_OK == CoCreateInstance( &clsid_ITaskbarList,
83                 NULL, CLSCTX_INPROC_SERVER,
84                 &IID_ITaskbarList3,
85                 (void **)&p_taskbl) )
86     {
87         p_taskbl->vt->HrInit(p_taskbl);
88
89         if( (himl = ImageList_Create( 20, //cx
90                         20, //cy
91                         ILC_COLOR32,//flags
92                         4,//initial nb of images
93                         0//nb of images that can be added
94                         ) ) != NULL )
95         {
96             QPixmap img   = QPixmap(":/win7/prev");
97             QPixmap img2  = QPixmap(":/win7/pause");
98             QPixmap img3  = QPixmap(":/win7/play");
99             QPixmap img4  = QPixmap(":/win7/next");
100             QBitmap mask  = img.createMaskFromColor(Qt::transparent);
101             QBitmap mask2 = img2.createMaskFromColor(Qt::transparent);
102             QBitmap mask3 = img3.createMaskFromColor(Qt::transparent);
103             QBitmap mask4 = img4.createMaskFromColor(Qt::transparent);
104
105             if(-1 == ImageList_Add(himl, img.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask.toWinHBITMAP()))
106                 msg_Err( p_intf, "ImageList_Add failed" );
107             if(-1 == ImageList_Add(himl, img2.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask2.toWinHBITMAP()))
108                 msg_Err( p_intf, "ImageList_Add failed" );
109             if(-1 == ImageList_Add(himl, img3.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask3.toWinHBITMAP()))
110                 msg_Err( p_intf, "ImageList_Add failed" );
111             if(-1 == ImageList_Add(himl, img4.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask4.toWinHBITMAP()))
112                 msg_Err( p_intf, "ImageList_Add failed" );
113         }
114
115         // Define an array of two buttons. These buttons provide images through an
116         // image list and also provide tooltips.
117         DWORD dwMask = THB_BITMAP | THB_FLAGS;
118
119         THUMBBUTTON thbButtons[3];
120         thbButtons[0].dwMask = dwMask;
121         thbButtons[0].iId = 0;
122         thbButtons[0].iBitmap = 0;
123         thbButtons[0].dwFlags = THBF_HIDDEN;
124
125         thbButtons[1].dwMask = dwMask;
126         thbButtons[1].iId = 1;
127         thbButtons[1].iBitmap = 2;
128         thbButtons[1].dwFlags = THBF_HIDDEN;
129
130         thbButtons[2].dwMask = dwMask;
131         thbButtons[2].iId = 2;
132         thbButtons[2].iBitmap = 3;
133         thbButtons[2].dwFlags = THBF_HIDDEN;
134
135         HRESULT hr = p_taskbl->vt->ThumbBarSetImageList(p_taskbl, winId(), himl );
136         if(S_OK != hr)
137             msg_Err( p_intf, "ThumbBarSetImageList failed with error %08lx", hr );
138         else
139         {
140             hr = p_taskbl->vt->ThumbBarAddButtons(p_taskbl, winId(), 3, thbButtons);
141             if(S_OK != hr)
142                 msg_Err( p_intf, "ThumbBarAddButtons failed with error %08lx", hr );
143         }
144         CONNECT( THEMIM->getIM(), playingStatusChanged( int ), this, changeThumbbarButtons( int ) );
145     }
146     else
147     {
148         himl = NULL;
149         p_taskbl = NULL;
150     }
151
152 }
153
154 bool MainInterface::winEvent ( MSG * msg, long * result )
155 {
156     if (msg->message == taskbar_wmsg)
157     {
158         //We received the taskbarbuttoncreated, now we can really create the buttons
159         createTaskBarButtons();
160     }
161
162     short cmd;
163     switch( msg->message )
164     {
165         case WM_COMMAND:
166             if (HIWORD(msg->wParam) == THBN_CLICKED)
167             {
168                 switch(LOWORD(msg->wParam))
169                 {
170                     case 0:
171                         THEMIM->prev();
172                         break;
173                     case 1:
174                         THEMIM->togglePlayPause();
175                         break;
176                     case 2:
177                         THEMIM->next();
178                         break;
179                 }
180             }
181             break;
182         case WM_APPCOMMAND:
183             cmd = GET_APPCOMMAND_LPARAM(msg->lParam);
184
185             if( p_intf->p_sys->disable_volume_keys &&
186                     (   cmd == APPCOMMAND_VOLUME_DOWN   ||
187                         cmd == APPCOMMAND_VOLUME_UP     ||
188                         cmd == APPCOMMAND_VOLUME_MUTE ) )
189             {
190                 break;
191             }
192
193             *result = TRUE;
194
195             switch(cmd)
196             {
197                 case APPCOMMAND_MEDIA_PLAY_PAUSE:
198                     THEMIM->togglePlayPause();
199                     break;
200                 case APPCOMMAND_MEDIA_PLAY:
201                     THEMIM->play();
202                     break;
203                 case APPCOMMAND_MEDIA_PAUSE:
204                     THEMIM->pause();
205                     break;
206                 case APPCOMMAND_MEDIA_CHANNEL_DOWN:
207                 case APPCOMMAND_MEDIA_PREVIOUSTRACK:
208                     THEMIM->prev();
209                     break;
210                 case APPCOMMAND_MEDIA_CHANNEL_UP:
211                 case APPCOMMAND_MEDIA_NEXTTRACK:
212                     THEMIM->next();
213                     break;
214                 case APPCOMMAND_MEDIA_STOP:
215                     THEMIM->stop();
216                     break;
217                 case APPCOMMAND_MEDIA_RECORD:
218                     THEAM->record();
219                     break;
220                 case APPCOMMAND_VOLUME_DOWN:
221                     THEAM->AudioDown();
222                     break;
223                 case APPCOMMAND_VOLUME_UP:
224                     THEAM->AudioUp();
225                     break;
226                 case APPCOMMAND_VOLUME_MUTE:
227                     THEAM->toggleMuteAudio();
228                     break;
229                 default:
230                      msg_Dbg( p_intf, "unknown APPCOMMAND = %d", cmd);
231                      *result = FALSE;
232                      break;
233             }
234             if (*result) return true;
235             break;
236     }
237     return false;
238 }
239
240 void MainInterface::changeThumbbarButtons( int i_status )
241 {
242     // Define an array of three buttons. These buttons provide images through an
243     // image list and also provide tooltips.
244     DWORD dwMask = THB_BITMAP | THB_FLAGS;
245
246     THUMBBUTTON thbButtons[3];
247     //prev
248     thbButtons[0].dwMask = dwMask;
249     thbButtons[0].iId = 0;
250     thbButtons[0].iBitmap = 0;
251
252     //play/pause
253     thbButtons[1].dwMask = dwMask;
254     thbButtons[1].iId = 1;
255
256     //next
257     thbButtons[2].dwMask = dwMask;
258     thbButtons[2].iId = 2;
259     thbButtons[2].iBitmap = 3;
260
261     switch( i_status )
262     {
263         case OPENING_S:
264         case PLAYING_S:
265             {
266                 thbButtons[0].dwFlags = THBF_ENABLED;
267                 thbButtons[1].dwFlags = THBF_ENABLED;
268                 thbButtons[2].dwFlags = THBF_ENABLED;
269                 thbButtons[1].iBitmap = 1;
270                 break;
271             }
272         case END_S:
273         case PAUSE_S:
274         case ERROR_S:
275             {
276                 thbButtons[0].dwFlags = THBF_ENABLED;
277                 thbButtons[1].dwFlags = THBF_ENABLED;
278                 thbButtons[2].dwFlags = THBF_ENABLED;
279                 thbButtons[1].iBitmap = 2;
280                 break;
281             }
282         default:
283             return;
284     }
285     HRESULT hr =  p_taskbl->vt->ThumbBarUpdateButtons(p_taskbl, this->winId(), 3, thbButtons);
286     if(S_OK != hr)
287         msg_Err( p_intf, "ThumbBarUpdateButtons failed with error %08lx", hr );
288 }