OSDN Git Service

Update MediaInfo binaries to v0.7.53 (2012-01-24), compiled with ICL 12.1.6 and MSVC...
[lamexp/LameXP.git] / src / WinSevenTaskbar.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2012 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 //
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
21
22 #include "WinSevenTaskbar.h"
23
24 #include <QWidget>
25 #include <QIcon>
26 #include <ShObjIdl.h>
27
28 UINT WinSevenTaskbar::m_winMsg = 0;
29 ITaskbarList3 *WinSevenTaskbar::m_ptbl = NULL;
30
31 WinSevenTaskbar::WinSevenTaskbar(void)
32 {
33         throw "Cannot create instance of this class!";
34 }
35
36 WinSevenTaskbar::~WinSevenTaskbar(void)
37 {
38 }
39
40 ////////////////////////////////////////////////////////////
41
42 #ifdef __ITaskbarList3_INTERFACE_DEFINED__      
43
44 void WinSevenTaskbar::init(void)
45 {
46         m_winMsg = RegisterWindowMessageW(L"TaskbarButtonCreated");
47         m_ptbl = NULL;
48 }
49         
50 void WinSevenTaskbar::uninit(void)
51 {
52         if(m_ptbl)
53         {
54                 m_ptbl->Release();
55                 m_ptbl = NULL;
56         }
57 }
58
59 bool WinSevenTaskbar::handleWinEvent(MSG *message, long *result)
60 {
61         bool stopEvent = false;
62
63         if(message->message == m_winMsg)
64         {
65                 if(!m_ptbl) createInterface();
66                 *result = (m_ptbl) ? S_OK : S_FALSE;
67                 stopEvent = true;
68         }
69
70         return stopEvent;
71 }
72
73 void WinSevenTaskbar::createInterface(void)
74 {
75         if(!m_ptbl)
76         {
77                 ITaskbarList3 *ptbl = NULL;
78                 HRESULT hr = CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&ptbl));
79
80                 if (SUCCEEDED(hr))
81                 {
82                         HRESULT hr2 = ptbl->HrInit();
83                         if(SUCCEEDED(hr2))
84                         {
85                                 m_ptbl = ptbl;
86                                 /*qDebug("ITaskbarList3::HrInit() succeeded.");*/
87                         }
88                         else
89                         {
90                                 ptbl->Release();
91                                 qWarning("ITaskbarList3::HrInit() has failed.");
92                         }
93                 }
94                 else
95                 {
96                         qWarning("ITaskbarList3 could not be created.");
97                 }
98         }
99 }
100
101 bool WinSevenTaskbar::setTaskbarState(QWidget *window, WinSevenTaskbarState state)
102 {
103         bool result = false;
104         
105         if(m_ptbl && window)
106         {
107                 HRESULT hr = HRESULT(-1);
108
109                 switch(state)
110                 {
111                 case WinSevenTaskbarNoState:
112                         hr = m_ptbl->SetProgressState(window->winId(), TBPF_NOPROGRESS);
113                         break;
114                 case WinSevenTaskbarNormalState:
115                         hr = m_ptbl->SetProgressState(window->winId(), TBPF_NORMAL);
116                         break;
117                 case WinSevenTaskbarIndeterminateState:
118                         hr = m_ptbl->SetProgressState(window->winId(), TBPF_INDETERMINATE);
119                         break;
120                 case WinSevenTaskbarErrorState:
121                         hr = m_ptbl->SetProgressState(window->winId(), TBPF_ERROR);
122                         break;
123                 case WinSevenTaskbarPausedState:
124                         hr = m_ptbl->SetProgressState(window->winId(), TBPF_PAUSED);
125                         break;
126                 }
127
128                 result = SUCCEEDED(hr);
129         }
130
131         return result;
132 }
133
134 void WinSevenTaskbar::setTaskbarProgress(QWidget *window, unsigned __int64 currentValue, unsigned __int64 maximumValue)
135 {
136         if(m_ptbl && window)
137         {
138                 m_ptbl->SetProgressValue(window->winId(), currentValue, maximumValue);
139         }
140 }
141
142 void WinSevenTaskbar::setOverlayIcon(QWidget *window, QIcon *icon)
143 {
144         if(m_ptbl && window)
145         {
146                 m_ptbl->SetOverlayIcon(window->winId(), (icon ? icon->pixmap(16,16).toWinHICON() : NULL), L"LameXP");
147         }
148 }
149
150 #else //__ITaskbarList3_INTERFACE_DEFINED__
151
152 LAMEXP_COMPILER_WARNING("ITaskbarList3 not defined. Compiling *without* support for Win7 taskbar!")
153 void WinSevenTaskbar::init(void) {}
154 void WinSevenTaskbar::uninit(void) {}
155 bool WinSevenTaskbar::handleWinEvent(MSG *message, long *result) { return false; }
156 void WinSevenTaskbar::createInterface(void) {}
157 bool WinSevenTaskbar::setTaskbarState(QWidget *window, WinSevenTaskbarState state) { return false; }
158 void WinSevenTaskbar::setTaskbarProgress(QWidget *window, unsigned __int64 currentValue, unsigned __int64 maximumValue) {}
159 void WinSevenTaskbar::setOverlayIcon(QWidget *window, QIcon *icon) {}
160
161 #endif //__ITaskbarList3_INTERFACE_DEFINED__