]> git.sesse.net Git - vlc/blob - modules/gui/qt4/main_interface_win32.cpp
Qt: Menu: change icon quit(cross) -> exit
[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 #include "dialogs_provider.hpp"
30
31 #include <QBitmap>
32 #include <vlc_windows_interfaces.h>
33
34 #define WM_APPCOMMAND 0x0319
35
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
63
64 #define FAPPCOMMAND_MOUSE 0x8000
65 #define FAPPCOMMAND_KEY   0
66 #define FAPPCOMMAND_OEM   0x1000
67 #define FAPPCOMMAND_MASK  0xF000
68
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)
74
75 void MainInterface::createTaskBarButtons()
76 {
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
80     */
81
82     CoInitializeEx( NULL, COINIT_MULTITHREADED );
83
84     if( S_OK == CoCreateInstance( CLSID_TaskbarList,
85                 NULL, CLSCTX_INPROC_SERVER,
86                 IID_ITaskbarList3,
87                 (void **)&p_taskbl) )
88     {
89         p_taskbl->HrInit();
90
91         if( (himl = ImageList_Create( 20, //cx
92                         20, //cy
93                         ILC_COLOR32,//flags
94                         4,//initial nb of images
95                         0//nb of images that can be added
96                         ) ) != NULL )
97         {
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);
106
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" );
115         }
116
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);
120
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;
126
127         thbButtons[1].dwMask = dwMask;
128         thbButtons[1].iId = 1;
129         thbButtons[1].iBitmap = 2;
130         thbButtons[1].dwFlags = THBF_HIDDEN;
131
132         thbButtons[2].dwMask = dwMask;
133         thbButtons[2].iId = 2;
134         thbButtons[2].iBitmap = 3;
135         thbButtons[2].dwFlags = THBF_HIDDEN;
136
137         HRESULT hr = p_taskbl->ThumbBarSetImageList(winId(), himl );
138         if(S_OK != hr)
139             msg_Err( p_intf, "ThumbBarSetImageList failed with error %08lx", hr );
140         else
141         {
142             hr = p_taskbl->ThumbBarAddButtons(winId(), 3, thbButtons);
143             if(S_OK != hr)
144                 msg_Err( p_intf, "ThumbBarAddButtons failed with error %08lx", hr );
145         }
146         CONNECT( THEMIM->getIM(), playingStatusChanged( int ), this, changeThumbbarButtons( int ) );
147     }
148     else
149     {
150         himl = NULL;
151         p_taskbl = NULL;
152     }
153
154 }
155
156 bool MainInterface::winEvent ( MSG * msg, long * result )
157 {
158     if (msg->message == taskbar_wmsg)
159     {
160         //We received the taskbarbuttoncreated, now we can really create the buttons
161         createTaskBarButtons();
162     }
163
164     short cmd;
165     switch( msg->message )
166     {
167         case WM_COMMAND:
168             if (HIWORD(msg->wParam) == THBN_CLICKED)
169             {
170                 switch(LOWORD(msg->wParam))
171                 {
172                     case 0:
173                         THEMIM->prev();
174                         break;
175                     case 1:
176                         THEMIM->togglePlayPause();
177                         break;
178                     case 2:
179                         THEMIM->next();
180                         break;
181                 }
182             }
183             break;
184         case WM_APPCOMMAND:
185             cmd = GET_APPCOMMAND_LPARAM(msg->lParam);
186
187             if( p_intf->p_sys->disable_volume_keys &&
188                     (   cmd == APPCOMMAND_VOLUME_DOWN   ||
189                         cmd == APPCOMMAND_VOLUME_UP     ||
190                         cmd == APPCOMMAND_VOLUME_MUTE ) )
191             {
192                 break;
193             }
194
195             *result = TRUE;
196
197             switch(cmd)
198             {
199                 case APPCOMMAND_MEDIA_PLAY_PAUSE:
200                     THEMIM->togglePlayPause();
201                     break;
202                 case APPCOMMAND_MEDIA_PLAY:
203                     THEMIM->play();
204                     break;
205                 case APPCOMMAND_MEDIA_PAUSE:
206                     THEMIM->pause();
207                     break;
208                 case APPCOMMAND_MEDIA_CHANNEL_DOWN:
209                 case APPCOMMAND_MEDIA_PREVIOUSTRACK:
210                     THEMIM->prev();
211                     break;
212                 case APPCOMMAND_MEDIA_CHANNEL_UP:
213                 case APPCOMMAND_MEDIA_NEXTTRACK:
214                     THEMIM->next();
215                     break;
216                 case APPCOMMAND_MEDIA_STOP:
217                     THEMIM->stop();
218                     break;
219                 case APPCOMMAND_MEDIA_RECORD:
220                     THEAM->record();
221                     break;
222                 case APPCOMMAND_VOLUME_DOWN:
223                     THEAM->AudioDown();
224                     break;
225                 case APPCOMMAND_VOLUME_UP:
226                     THEAM->AudioUp();
227                     break;
228                 case APPCOMMAND_VOLUME_MUTE:
229                     THEAM->toggleMuteAudio();
230                     break;
231                 case APPCOMMAND_MEDIA_FAST_FORWARD:
232                     THEMIM->getIM()->faster();
233                     break;
234                 case APPCOMMAND_MEDIA_REWIND:
235                     THEMIM->getIM()->slower();
236                     break;
237                 case APPCOMMAND_HELP:
238                     THEDP->mediaInfoDialog();
239                     break;
240                 case APPCOMMAND_OPEN:
241                     THEDP->simpleOpenDialog();
242                     break;
243                 default:
244                      msg_Dbg( p_intf, "unknown APPCOMMAND = %d", cmd);
245                      *result = FALSE;
246                      break;
247             }
248             if (*result) return true;
249             break;
250     }
251     return false;
252 }
253
254 void MainInterface::changeThumbbarButtons( int i_status )
255 {
256     if( p_taskbl == NULL )
257         return;
258
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);
262
263     THUMBBUTTON thbButtons[3];
264     //prev
265     thbButtons[0].dwMask = dwMask;
266     thbButtons[0].iId = 0;
267     thbButtons[0].iBitmap = 0;
268
269     //play/pause
270     thbButtons[1].dwMask = dwMask;
271     thbButtons[1].iId = 1;
272
273     //next
274     thbButtons[2].dwMask = dwMask;
275     thbButtons[2].iId = 2;
276     thbButtons[2].iBitmap = 3;
277
278     switch( i_status )
279     {
280         case OPENING_S:
281         case PLAYING_S:
282             {
283                 thbButtons[0].dwFlags = THBF_ENABLED;
284                 thbButtons[1].dwFlags = THBF_ENABLED;
285                 thbButtons[2].dwFlags = THBF_ENABLED;
286                 thbButtons[1].iBitmap = 1;
287                 break;
288             }
289         case END_S:
290         case PAUSE_S:
291         case ERROR_S:
292             {
293                 thbButtons[0].dwFlags = THBF_ENABLED;
294                 thbButtons[1].dwFlags = THBF_ENABLED;
295                 thbButtons[2].dwFlags = THBF_ENABLED;
296                 thbButtons[1].iBitmap = 2;
297                 break;
298             }
299         default:
300             return;
301     }
302     HRESULT hr =  p_taskbl->ThumbBarUpdateButtons(this->winId(), 3, thbButtons);
303     if(S_OK != hr)
304         msg_Err( p_intf, "ThumbBarUpdateButtons failed with error %08lx", hr );
305 }