]> git.sesse.net Git - vlc/blob - modules/gui/qt4/main_interface_win32.cpp
Qt: put Win32 Main Interface function in its own file.
[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 #ifdef WIN32
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_DICTATE_OR_COMMAND_CONTROL_TOGGLE    43
53 #define APPCOMMAND_MIC_ON_OFF_TOGGLE      44
54 #define APPCOMMAND_MEDIA_PLAY             46
55 #define APPCOMMAND_MEDIA_PAUSE            47
56 #define APPCOMMAND_MEDIA_RECORD           48
57 #define APPCOMMAND_MEDIA_FAST_FORWARD     49
58 #define APPCOMMAND_MEDIA_REWIND           50
59 #define APPCOMMAND_MEDIA_CHANNEL_UP       51
60 #define APPCOMMAND_MEDIA_CHANNEL_DOWN     52
61
62 #define FAPPCOMMAND_MOUSE 0x8000
63 #define FAPPCOMMAND_KEY   0
64 #define FAPPCOMMAND_OEM   0x1000
65 #define FAPPCOMMAND_MASK  0xF000
66
67 #define GET_APPCOMMAND_LPARAM(lParam) ((short)(HIWORD(lParam) & ~FAPPCOMMAND_MASK))
68 #define GET_DEVICE_LPARAM(lParam)     ((WORD)(HIWORD(lParam) & FAPPCOMMAND_MASK))
69 #define GET_MOUSEORKEY_LPARAM         GET_DEVICE_LPARAM
70 #define GET_FLAGS_LPARAM(lParam)      (LOWORD(lParam))
71 #define GET_KEYSTATE_LPARAM(lParam)   GET_FLAGS_LPARAM(lParam)
72
73 void MainInterface::createTaskBarButtons()
74 {
75     taskbar_wmsg = WM_NULL;
76     /*Here is the code for the taskbar thumb buttons
77     FIXME:We need pretty buttons in 16x16 px that are handled correctly by masks in Qt
78     FIXME:the play button's picture doesn't changed to pause when clicked
79     */
80
81     CoInitialize( 0 );
82
83     if( S_OK == CoCreateInstance( &clsid_ITaskbarList,
84                 NULL, CLSCTX_INPROC_SERVER,
85                 &IID_ITaskbarList3,
86                 (void **)&p_taskbl) )
87     {
88         p_taskbl->vt->HrInit(p_taskbl);
89
90         if(himl = ImageList_Create( 15, //cx
91                         18, //cy
92                         ILC_COLOR,//flags
93                         4,//initial nb of images
94                         0//nb of images that can be added
95                         ))
96         {
97             QPixmap img   = QPixmap(":/toolbar/previous_b");
98             QPixmap img2  = QPixmap(":/toolbar/pause_b");
99             QPixmap img3  = QPixmap(":/toolbar/play_b");
100             QPixmap img4  = QPixmap(":/toolbar/next_b");
101             QBitmap mask  = img.createMaskFromColor(Qt::transparent);
102             QBitmap mask2 = img2.createMaskFromColor(Qt::transparent);
103             QBitmap mask3 = img3.createMaskFromColor(Qt::transparent);
104             QBitmap mask4 = img4.createMaskFromColor(Qt::transparent);
105
106             if(-1 == ImageList_Add(himl, img.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask.toWinHBITMAP()))
107                 msg_Err( p_intf, "ImageList_Add failed" );
108             if(-1 == ImageList_Add(himl, img2.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask2.toWinHBITMAP()))
109                 msg_Err( p_intf, "ImageList_Add failed" );
110             if(-1 == ImageList_Add(himl, img3.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask3.toWinHBITMAP()))
111                 msg_Err( p_intf, "ImageList_Add failed" );
112             if(-1 == ImageList_Add(himl, img4.toWinHBITMAP(QPixmap::PremultipliedAlpha),mask4.toWinHBITMAP()))
113                 msg_Err( p_intf, "ImageList_Add failed" );
114         }
115
116         // Define an array of two buttons. These buttons provide images through an
117         // image list and also provide tooltips.
118         DWORD dwMask = THB_BITMAP | THB_FLAGS;
119
120         THUMBBUTTON thbButtons[3];
121         thbButtons[0].dwMask = dwMask;
122         thbButtons[0].iId = 0;
123         thbButtons[0].iBitmap = 0;
124         thbButtons[0].dwFlags = THBF_HIDDEN;
125
126         thbButtons[1].dwMask = dwMask;
127         thbButtons[1].iId = 1;
128         thbButtons[1].iBitmap = 2;
129         thbButtons[1].dwFlags = THBF_HIDDEN;
130
131         thbButtons[2].dwMask = dwMask;
132         thbButtons[2].iId = 2;
133         thbButtons[2].iBitmap = 3;
134         thbButtons[2].dwFlags = THBF_HIDDEN;
135
136         HRESULT hr = p_taskbl->vt->ThumbBarSetImageList(p_taskbl, winId(), himl );
137         if(S_OK != hr)
138             msg_Err( p_intf, "ThumbBarSetImageList failed with error %08x", hr );
139         else
140         {
141             hr = p_taskbl->vt->ThumbBarAddButtons(p_taskbl, winId(), 3, thbButtons);
142             if(S_OK != hr)
143                 msg_Err( p_intf, "ThumbBarAddButtons failed with error %08x", hr );
144         }
145         CONNECT( THEMIM->getIM(), statusChanged( int ), this, changeThumbbarButtons( int ) );
146     }
147     else
148     {
149         himl = NULL;
150         p_taskbl = NULL;
151     }
152
153 }
154
155 bool MainInterface::winEvent ( MSG * msg, long * result )
156 {
157     if (msg->message == taskbar_wmsg)
158     {
159         //We received the taskbarbuttoncreated, now we can really create th buttons
160         createTaskBarButtons();
161     }
162
163     short cmd;
164     switch( msg->message )
165     {
166         case WM_COMMAND:
167             if (HIWORD(msg->wParam) == THBN_CLICKED)
168             {
169                 switch(LOWORD(msg->wParam))
170                 {
171                     case 0:
172                         THEMIM->prev();
173                         break;
174                     case 1:
175                         THEMIM->togglePlayPause();
176                         break;
177                     case 2:
178                         THEMIM->next();
179                         break;
180                 }
181             }
182             break;
183         case WM_APPCOMMAND:
184             cmd = GET_APPCOMMAND_LPARAM(msg->lParam);
185             switch(cmd)
186             {
187                 case APPCOMMAND_MEDIA_PLAY_PAUSE:
188                     THEMIM->togglePlayPause();
189                     break;
190                 case APPCOMMAND_MEDIA_PLAY:
191                     THEMIM->play();
192                     break;
193                 case APPCOMMAND_MEDIA_PAUSE:
194                     THEMIM->pause();
195                     break;
196                 case APPCOMMAND_MEDIA_PREVIOUSTRACK:
197                     THEMIM->prev();
198                     break;
199                 case APPCOMMAND_MEDIA_NEXTTRACK:
200                     THEMIM->next();
201                     break;
202                 case APPCOMMAND_MEDIA_STOP:
203                     THEMIM->stop();
204                     break;
205                 case APPCOMMAND_VOLUME_DOWN:
206                     THEAM->AudioDown();
207                     break;
208                 case APPCOMMAND_VOLUME_UP:
209                     THEAM->AudioUp();
210                     break;
211                 case APPCOMMAND_VOLUME_MUTE:
212                     THEAM->toggleMuteAudio();
213                     break;
214                 default:
215                      msg_Dbg( p_intf, "unknown APPCOMMAND = %d", cmd);
216                      break;
217             }
218             break;
219     }
220     return false;
221 }
222 #endif
223
224 //moc doesn't know about #ifdef, so we have to build this method for every platform
225 void MainInterface::changeThumbbarButtons( int i_status)
226 {
227 #ifdef WIN32
228     // Define an array of three buttons. These buttons provide images through an
229     // image list and also provide tooltips.
230     DWORD dwMask = THB_BITMAP | THB_FLAGS;
231
232     THUMBBUTTON thbButtons[3];
233     //prev
234     thbButtons[0].dwMask = dwMask;
235     thbButtons[0].iId = 0;
236     thbButtons[0].iBitmap = 0;
237
238     //play/pause
239     thbButtons[1].dwMask = dwMask;
240     thbButtons[1].iId = 1;
241
242     //next
243     thbButtons[2].dwMask = dwMask;
244     thbButtons[2].iId = 2;
245     thbButtons[2].iBitmap = 3;
246
247     switch( i_status )
248     {
249         case PLAYING_S:
250             {
251                 thbButtons[0].dwFlags = THBF_ENABLED;
252                 thbButtons[1].dwFlags = THBF_ENABLED;
253                 thbButtons[2].dwFlags = THBF_ENABLED;
254                 thbButtons[1].iBitmap = 1;
255                 break;
256             }
257         case PAUSE_S:
258             {
259                 thbButtons[0].dwFlags = THBF_ENABLED;
260                 thbButtons[1].dwFlags = THBF_ENABLED;
261                 thbButtons[2].dwFlags = THBF_ENABLED;
262                 thbButtons[1].iBitmap = 2;
263                 break;
264             }
265         default:
266             return;
267     }
268     HRESULT hr =  p_taskbl->vt->ThumbBarUpdateButtons(p_taskbl, this->winId(), 3, thbButtons);
269     if(S_OK != hr)
270         msg_Err( p_intf, "ThumbBarUpdateButtons failed with error %08x", hr );
271 #endif
272 }
273
274