OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / coreplugin / progressmanager / progressmanager_win.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #include <QtCore/QVariant>
34 #include <QtGui/QMainWindow>
35 #include <QtGui/QFont>
36 #include <QtGui/QFontMetrics>
37 #include <QtGui/QPixmap>
38 #include <QtGui/QPainter>
39 #include <QtGui/QLabel>
40
41 #include <coreplugin/icore.h>
42
43 #include "progressmanager_p.h"
44
45 // for windows progress bar
46 #ifndef __GNUC__
47 #    include <shobjidl.h>
48 #endif
49
50 // Windows 7 SDK required
51 #ifdef __ITaskbarList3_INTERFACE_DEFINED__
52
53 namespace {
54     int total = 0;
55     ITaskbarList3* pITask = 0;
56 }
57
58 void Core::Internal::ProgressManagerPrivate::init()
59 {
60     CoInitialize(NULL);
61     HRESULT hRes = CoCreateInstance(CLSID_TaskbarList,
62                                     NULL,CLSCTX_INPROC_SERVER,
63                                     IID_ITaskbarList3,(LPVOID*) &pITask);
64      if (FAILED(hRes))
65      {
66          pITask = 0;
67          CoUninitialize();
68          return;
69      }
70
71      pITask->HrInit();
72      return;
73 }
74
75 void Core::Internal::ProgressManagerPrivate::cleanup()
76 {
77     if (pITask) {
78     pITask->Release();
79     pITask = NULL;
80     CoUninitialize();
81     }
82 }
83
84
85 void Core::Internal::ProgressManagerPrivate::setApplicationLabel(const QString &text)
86 {
87     if (!pITask)
88         return;
89
90     WId winId = Core::ICore::instance()->mainWindow()->winId();
91     if (text.isEmpty()) {
92         pITask->SetOverlayIcon(winId, NULL, NULL);
93     } else {
94         QPixmap pix = QPixmap(":/projectexplorer/images/compile_error.png");
95         QPainter p(&pix);
96         p.setPen(Qt::white);
97         QFont font = p.font();
98         font.setPointSize(font.pointSize()-2);
99         p.setFont(font);
100         p.drawText(QRect(QPoint(0,0), pix.size()), Qt::AlignHCenter|Qt::AlignCenter, text);
101         pITask->SetOverlayIcon(winId, pix.toWinHICON(), (wchar_t*)text.utf16());
102     }
103 }
104
105 void Core::Internal::ProgressManagerPrivate::setApplicationProgressRange(int min, int max)
106 {
107     total = max-min;
108 }
109
110 void Core::Internal::ProgressManagerPrivate::setApplicationProgressValue(int value)
111 {
112     if (pITask) {
113         WId winId = Core::ICore::instance()->mainWindow()->winId();
114         pITask->SetProgressValue(winId, value, total);
115     }
116 }
117
118 void Core::Internal::ProgressManagerPrivate::setApplicationProgressVisible(bool visible)
119 {
120     if (!pITask)
121         return;
122
123     WId winId = Core::ICore::instance()->mainWindow()->winId();
124     if (visible)
125         pITask->SetProgressState(winId, TBPF_NORMAL);
126     else
127         pITask->SetProgressState(winId, TBPF_NOPROGRESS);
128 }
129
130 #else
131
132 void Core::Internal::ProgressManagerPrivate::init()
133 {
134 }
135
136 void Core::Internal::ProgressManagerPrivate::cleanup()
137 {
138 }
139
140 void Core::Internal::ProgressManagerPrivate::setApplicationLabel(const QString &text)
141 {
142     Q_UNUSED(text)
143 }
144
145 void Core::Internal::ProgressManagerPrivate::setApplicationProgressRange(int min, int max)
146 {
147     Q_UNUSED(min)
148     Q_UNUSED(max)
149 }
150
151 void Core::Internal::ProgressManagerPrivate::setApplicationProgressValue(int value)
152 {
153     Q_UNUSED(value)
154 }
155
156 void Core::Internal::ProgressManagerPrivate::setApplicationProgressVisible(bool visible)
157 {
158     Q_UNUSED(visible)
159 }
160
161
162 #endif // __ITaskbarList2_INTERFACE_DEFINED__