2010-12-05 23:11:03 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// LameXP - Audio Encoder Front-End
|
2013-02-08 23:50:51 +01:00
|
|
|
// Copyright (C) 2004-2013 LoRd_MuldeR <MuldeR2@GMX.de>
|
2010-12-05 23:11:03 +01:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
//
|
|
|
|
// http://www.gnu.org/licenses/gpl-2.0.txt
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "WinSevenTaskbar.h"
|
|
|
|
|
|
|
|
#include <QWidget>
|
|
|
|
#include <QIcon>
|
2013-10-06 19:28:12 +02:00
|
|
|
|
|
|
|
//Windows includes
|
|
|
|
#define NOMINMAX
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <Windows.h>
|
2011-11-07 17:13:41 +01:00
|
|
|
#include <ShObjIdl.h>
|
2010-12-05 23:11:03 +01:00
|
|
|
|
2013-10-06 19:28:12 +02:00
|
|
|
static UINT s_winMsg = 0;
|
|
|
|
static ITaskbarList3 *s_ptbl = NULL;
|
2010-12-05 23:11:03 +01:00
|
|
|
|
|
|
|
WinSevenTaskbar::WinSevenTaskbar(void)
|
|
|
|
{
|
2013-10-18 21:37:40 +02:00
|
|
|
THROW("Cannot create instance of this class!");
|
2010-12-05 23:11:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
WinSevenTaskbar::~WinSevenTaskbar(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-11-07 17:13:41 +01:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifdef __ITaskbarList3_INTERFACE_DEFINED__
|
|
|
|
|
|
|
|
void WinSevenTaskbar::init(void)
|
2010-12-05 23:11:03 +01:00
|
|
|
{
|
2013-10-06 19:28:12 +02:00
|
|
|
s_winMsg = RegisterWindowMessageW(L"TaskbarButtonCreated");
|
|
|
|
s_ptbl = NULL;
|
2011-11-07 17:13:41 +01:00
|
|
|
}
|
2010-12-05 23:11:03 +01:00
|
|
|
|
2011-11-07 17:13:41 +01:00
|
|
|
void WinSevenTaskbar::uninit(void)
|
|
|
|
{
|
2013-10-06 19:28:12 +02:00
|
|
|
if(s_ptbl)
|
2010-12-05 23:11:03 +01:00
|
|
|
{
|
2013-10-06 19:28:12 +02:00
|
|
|
s_ptbl->Release();
|
|
|
|
s_ptbl = NULL;
|
2011-11-07 17:13:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-06 19:28:12 +02:00
|
|
|
bool WinSevenTaskbar::handleWinEvent(void *message, long *result)
|
2011-11-07 17:13:41 +01:00
|
|
|
{
|
|
|
|
bool stopEvent = false;
|
|
|
|
|
2013-10-06 19:28:12 +02:00
|
|
|
if(((MSG*)message)->message == s_winMsg)
|
2011-11-07 17:13:41 +01:00
|
|
|
{
|
2013-10-06 19:28:12 +02:00
|
|
|
if(!s_ptbl) createInterface();
|
|
|
|
*result = (s_ptbl) ? S_OK : S_FALSE;
|
2011-11-07 17:13:41 +01:00
|
|
|
stopEvent = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return stopEvent;
|
|
|
|
}
|
2010-12-05 23:11:03 +01:00
|
|
|
|
2011-11-07 17:13:41 +01:00
|
|
|
void WinSevenTaskbar::createInterface(void)
|
|
|
|
{
|
2013-10-06 19:28:12 +02:00
|
|
|
if(!s_ptbl)
|
2011-11-07 17:13:41 +01:00
|
|
|
{
|
|
|
|
ITaskbarList3 *ptbl = NULL;
|
|
|
|
HRESULT hr = CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&ptbl));
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
HRESULT hr2 = ptbl->HrInit();
|
|
|
|
if(SUCCEEDED(hr2))
|
2010-12-05 23:11:03 +01:00
|
|
|
{
|
2013-10-06 19:28:12 +02:00
|
|
|
s_ptbl = ptbl;
|
2011-11-07 17:13:41 +01:00
|
|
|
/*qDebug("ITaskbarList3::HrInit() succeeded.");*/
|
2010-12-05 23:11:03 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-11-07 17:13:41 +01:00
|
|
|
ptbl->Release();
|
|
|
|
qWarning("ITaskbarList3::HrInit() has failed.");
|
2010-12-05 23:11:03 +01:00
|
|
|
}
|
|
|
|
}
|
2011-11-07 17:13:41 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning("ITaskbarList3 could not be created.");
|
|
|
|
}
|
2010-12-05 23:11:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-07 17:13:41 +01:00
|
|
|
bool WinSevenTaskbar::setTaskbarState(QWidget *window, WinSevenTaskbarState state)
|
2010-12-05 23:11:03 +01:00
|
|
|
{
|
2011-11-07 17:13:41 +01:00
|
|
|
bool result = false;
|
|
|
|
|
2013-10-06 19:28:12 +02:00
|
|
|
if(s_ptbl && window)
|
2010-12-05 23:11:03 +01:00
|
|
|
{
|
2011-11-07 17:13:41 +01:00
|
|
|
HRESULT hr = HRESULT(-1);
|
|
|
|
|
2010-12-05 23:11:03 +01:00
|
|
|
switch(state)
|
|
|
|
{
|
|
|
|
case WinSevenTaskbarNoState:
|
2013-10-06 19:28:12 +02:00
|
|
|
hr = s_ptbl->SetProgressState(reinterpret_cast<HWND>(window->winId()), TBPF_NOPROGRESS);
|
2010-12-05 23:11:03 +01:00
|
|
|
break;
|
|
|
|
case WinSevenTaskbarNormalState:
|
2013-10-06 19:28:12 +02:00
|
|
|
hr = s_ptbl->SetProgressState(reinterpret_cast<HWND>(window->winId()), TBPF_NORMAL);
|
2010-12-05 23:11:03 +01:00
|
|
|
break;
|
|
|
|
case WinSevenTaskbarIndeterminateState:
|
2013-10-06 19:28:12 +02:00
|
|
|
hr = s_ptbl->SetProgressState(reinterpret_cast<HWND>(window->winId()), TBPF_INDETERMINATE);
|
2010-12-05 23:11:03 +01:00
|
|
|
break;
|
|
|
|
case WinSevenTaskbarErrorState:
|
2013-10-06 19:28:12 +02:00
|
|
|
hr = s_ptbl->SetProgressState(reinterpret_cast<HWND>(window->winId()), TBPF_ERROR);
|
2010-12-05 23:11:03 +01:00
|
|
|
break;
|
|
|
|
case WinSevenTaskbarPausedState:
|
2013-10-06 19:28:12 +02:00
|
|
|
hr = s_ptbl->SetProgressState(reinterpret_cast<HWND>(window->winId()), TBPF_PAUSED);
|
2010-12-05 23:11:03 +01:00
|
|
|
break;
|
|
|
|
}
|
2011-11-07 17:13:41 +01:00
|
|
|
|
|
|
|
result = SUCCEEDED(hr);
|
2010-12-05 23:11:03 +01:00
|
|
|
}
|
2011-11-07 17:13:41 +01:00
|
|
|
|
|
|
|
return result;
|
2010-12-05 23:11:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WinSevenTaskbar::setTaskbarProgress(QWidget *window, unsigned __int64 currentValue, unsigned __int64 maximumValue)
|
|
|
|
{
|
2013-10-06 19:28:12 +02:00
|
|
|
if(s_ptbl && window)
|
2010-12-05 23:11:03 +01:00
|
|
|
{
|
2013-10-06 19:28:12 +02:00
|
|
|
s_ptbl->SetProgressValue(reinterpret_cast<HWND>(window->winId()), currentValue, maximumValue);
|
2010-12-05 23:11:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WinSevenTaskbar::setOverlayIcon(QWidget *window, QIcon *icon)
|
|
|
|
{
|
2012-04-11 00:44:40 +02:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
2013-10-06 19:28:12 +02:00
|
|
|
if(s_ptbl && window)
|
2010-12-05 23:11:03 +01:00
|
|
|
{
|
2013-10-06 19:28:12 +02:00
|
|
|
s_ptbl->SetOverlayIcon(window->winId(), (icon ? icon->pixmap(16,16).toWinHICON() : NULL), L"LameXP");
|
2010-12-05 23:11:03 +01:00
|
|
|
}
|
2012-04-11 00:44:40 +02:00
|
|
|
#endif
|
2010-12-05 23:11:03 +01:00
|
|
|
}
|
|
|
|
|
2011-11-07 17:13:41 +01:00
|
|
|
#else //__ITaskbarList3_INTERFACE_DEFINED__
|
|
|
|
|
|
|
|
LAMEXP_COMPILER_WARNING("ITaskbarList3 not defined. Compiling *without* support for Win7 taskbar!")
|
|
|
|
void WinSevenTaskbar::init(void) {}
|
|
|
|
void WinSevenTaskbar::uninit(void) {}
|
|
|
|
bool WinSevenTaskbar::handleWinEvent(MSG *message, long *result) { return false; }
|
|
|
|
void WinSevenTaskbar::createInterface(void) {}
|
2011-11-07 17:29:07 +01:00
|
|
|
bool WinSevenTaskbar::setTaskbarState(QWidget *window, WinSevenTaskbarState state) { return false; }
|
2011-11-07 17:13:41 +01:00
|
|
|
void WinSevenTaskbar::setTaskbarProgress(QWidget *window, unsigned __int64 currentValue, unsigned __int64 maximumValue) {}
|
|
|
|
void WinSevenTaskbar::setOverlayIcon(QWidget *window, QIcon *icon) {}
|
|
|
|
|
|
|
|
#endif //__ITaskbarList3_INTERFACE_DEFINED__
|