summaryrefslogtreecommitdiff
path: root/shared/taskbar.cpp
blob: 476819580864dc73d6b8b8e0820d1143f8baecd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// **************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
// * GNU General Public License: http://www.gnu.org/licenses/gpl.html       *
// * Copyright (C) 2008-2010 ZenJu (zhnmju123 AT gmx.de)                    *
// **************************************************************************
//
#include "taskbar.h"
#include "Taskbar_Seven/taskbar.h"
#include "dllLoader.h"
#include "buildInfo.h"
#include "staticAssert.h"
#include <wx/msw/wrapwin.h> //includes "windows.h"

using namespace Utility;


namespace
{
bool windows7TaskbarAvailable()
{
    OSVERSIONINFO osvi;
    ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);

    if (GetVersionEx(&osvi))
        return osvi.dwMajorVersion > 6 ||
               (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion >= 1); //task bar progress available with Windows 7
    //XP          has majorVersion == 5, minorVersion == 1
    //Server 2003 has majorVersion == 5, minorVersion == 2
    //Seven       has majorVersion == 6, minorVersion == 1
    //version overview: http://msdn.microsoft.com/en-us/library/ms724834(VS.85).aspx
    return false;
}


const wxString& getTaskBarDllName()
{
    static const wxString filename(
        Utility::is64BitBuild ?
        wxT("Taskbar7_x64.dll") :
        wxT("Taskbar7_Win32.dll"));

    assert_static(Utility::is32BitBuild || Utility::is64BitBuild);

    return filename;
}
}


struct TaskbarProgress::Pimpl
{
    Pimpl() : tbHandle(0),
        assocWindow(NULL),
        init_(NULL),
        release_(NULL),
        setStatus_(NULL),
        setProgress_(NULL) {}

    TaskbarSeven::TBHandle tbHandle;
    void* assocWindow;

    TaskbarSeven::initFct init_;
    TaskbarSeven::releaseFct release_;
    TaskbarSeven::setStatusFct setStatus_;
    TaskbarSeven::setProgressFct setProgress_;
};


TaskbarProgress::TaskbarProgress(const wxTopLevelWindow& window) : pimpl_(new Pimpl)
{
    if (!windows7TaskbarAvailable())
        throw TaskbarNotAvailable();

    pimpl_->init_         = Utility::loadDllFunction<TaskbarSeven::initFct>(       getTaskBarDllName().c_str(), TaskbarSeven::initFctName);
    pimpl_->release_      = Utility::loadDllFunction<TaskbarSeven::releaseFct>(    getTaskBarDllName().c_str(), TaskbarSeven::releaseFctName);
    pimpl_->setProgress_  = Utility::loadDllFunction<TaskbarSeven::setProgressFct>(getTaskBarDllName().c_str(), TaskbarSeven::setProgressFctName);
    pimpl_->setStatus_    = Utility::loadDllFunction<TaskbarSeven::setStatusFct>(  getTaskBarDllName().c_str(), TaskbarSeven::setStatusFctName);

    if (    !pimpl_->init_        ||
            !pimpl_->release_     ||
            !pimpl_->setProgress_ ||
            !pimpl_->setStatus_)
        throw TaskbarNotAvailable();

    pimpl_->tbHandle = pimpl_->init_();
    if (pimpl_->tbHandle == 0)
        throw TaskbarNotAvailable();

    pimpl_->assocWindow = window.GetHWND();
}


TaskbarProgress::~TaskbarProgress()
{
    setStatus(STATUS_NOPROGRESS);

    pimpl_->release_(pimpl_->tbHandle);
}


void TaskbarProgress::setStatus(Status status)
{
    TaskbarSeven::TaskBarStatus tbSevenStatus = TaskbarSeven::STATUS_NORMAL;
    switch (status)
    {
    case TaskbarProgress::STATUS_NOPROGRESS:
        tbSevenStatus = TaskbarSeven::STATUS_NOPROGRESS;
        break;
    case TaskbarProgress::STATUS_INDETERMINATE:
        tbSevenStatus = TaskbarSeven::STATUS_INDETERMINATE;
        break;
    case TaskbarProgress::STATUS_NORMAL:
        tbSevenStatus = TaskbarSeven::STATUS_NORMAL;
        break;
    case TaskbarProgress::STATUS_ERROR:
        tbSevenStatus = TaskbarSeven::STATUS_ERROR;
        break;
    case TaskbarProgress::STATUS_PAUSED:
        tbSevenStatus = TaskbarSeven::STATUS_PAUSED;
        break;
    }

    pimpl_->setStatus_(pimpl_->tbHandle, pimpl_->assocWindow, tbSevenStatus);
}


void TaskbarProgress::setProgress(size_t current, size_t total)
{
    pimpl_->setProgress_(pimpl_->tbHandle, pimpl_->assocWindow, current, total);
}
bgstack15