|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtGui module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
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 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #ifndef QWINDOWSXPSTYLE_P_H |
|
43 #define QWINDOWSXPSTYLE_P_H |
|
44 |
|
45 // |
|
46 // W A R N I N G |
|
47 // ------------- |
|
48 // |
|
49 // This file is not part of the Qt API. It exists for the convenience |
|
50 // of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header |
|
51 // file may change from version to version without notice, or even be removed. |
|
52 // |
|
53 // We mean it. |
|
54 // |
|
55 |
|
56 #include "qwindowsxpstyle.h" |
|
57 #include "qwindowsstyle_p.h" |
|
58 #include <qmap.h> |
|
59 #include <qt_windows.h> |
|
60 |
|
61 // Note, these tests are duplicated in qwizard_win.cpp. |
|
62 #ifdef Q_CC_GNU |
|
63 # include <w32api.h> |
|
64 # if (__W32API_MAJOR_VERSION >= 3 || (__W32API_MAJOR_VERSION == 2 && __W32API_MINOR_VERSION >= 5)) |
|
65 # ifdef _WIN32_WINNT |
|
66 # undef _WIN32_WINNT |
|
67 # endif |
|
68 # define _WIN32_WINNT 0x0501 |
|
69 # include <commctrl.h> |
|
70 # endif |
|
71 #endif |
|
72 |
|
73 #include <uxtheme.h> |
|
74 |
|
75 #if WINVER >= 0x0600 |
|
76 #include <vssym32.h> |
|
77 #else |
|
78 #include <tmschema.h> |
|
79 #endif |
|
80 |
|
81 #include <limits.h> |
|
82 |
|
83 QT_BEGIN_NAMESPACE |
|
84 |
|
85 // Older Platform SDKs do not have the extended DrawThemeBackgroundEx |
|
86 // function. We add the needed parts here, and use the extended |
|
87 // function dynamically, if available in uxtheme.dll. Else, we revert |
|
88 // back to using the DrawThemeBackground function. |
|
89 #ifndef DTBG_OMITBORDER |
|
90 # ifndef DTBG_CLIPRECT |
|
91 # define DTBG_CLIPRECT 0x00000001 |
|
92 # endif |
|
93 # ifndef DTBG_DRAWSOLID |
|
94 # define DTBG_DRAWSOLID 0x00000002 |
|
95 # endif |
|
96 # ifndef DTBG_OMITBORDER |
|
97 # define DTBG_OMITBORDER 0x00000004 |
|
98 # endif |
|
99 # ifndef DTBG_OMITCONTENT |
|
100 # define DTBG_OMITCONTENT 0x00000008 |
|
101 # endif |
|
102 # ifndef DTBG_COMPUTINGREGION |
|
103 # define DTBG_COMPUTINGREGION 0x00000010 |
|
104 # endif |
|
105 # ifndef DTBG_MIRRORDC |
|
106 # define DTBG_MIRRORDC 0x00000020 |
|
107 # endif |
|
108 typedef struct _DTBGOPTS |
|
109 { |
|
110 DWORD dwSize; |
|
111 DWORD dwFlags; |
|
112 RECT rcClip; |
|
113 } DTBGOPTS, *PDTBGOPTS; |
|
114 #endif // _DTBGOPTS |
|
115 |
|
116 // Undefined for some compile environments |
|
117 #ifndef TMT_TEXTCOLOR |
|
118 # define TMT_TEXTCOLOR 3803 |
|
119 #endif |
|
120 #ifndef TMT_BORDERCOLORHINT |
|
121 # define TMT_BORDERCOLORHINT 3822 |
|
122 #endif |
|
123 #ifndef TMT_BORDERSIZE |
|
124 # define TMT_BORDERSIZE 2403 |
|
125 #endif |
|
126 #ifndef TMT_BORDERONLY |
|
127 # define TMT_BORDERONLY 2203 |
|
128 #endif |
|
129 #ifndef TMT_TRANSPARENTCOLOR |
|
130 # define TMT_TRANSPARENTCOLOR 3809 |
|
131 #endif |
|
132 #ifndef TMT_CAPTIONMARGINS |
|
133 # define TMT_CAPTIONMARGINS 3603 |
|
134 #endif |
|
135 #ifndef TMT_CONTENTMARGINS |
|
136 # define TMT_CONTENTMARGINS 3602 |
|
137 #endif |
|
138 #ifndef TMT_SIZINGMARGINS |
|
139 # define TMT_SIZINGMARGINS 3601 |
|
140 #endif |
|
141 #ifndef TMT_GLYPHTYPE |
|
142 # define TMT_GLYPHTYPE 4012 |
|
143 #endif |
|
144 #ifndef TMT_BGTYPE |
|
145 # define TMT_BGTYPE 4001 |
|
146 #endif |
|
147 #ifndef TMT_TEXTSHADOWTYPE |
|
148 # define TMT_TEXTSHADOWTYPE 4010 |
|
149 #endif |
|
150 #ifndef TMT_BORDERCOLOR |
|
151 # define TMT_BORDERCOLOR 3801 |
|
152 #endif |
|
153 #ifndef BT_IMAGEFILE |
|
154 # define BT_IMAGEFILE 0 |
|
155 #endif |
|
156 #ifndef BT_BORDERFILL |
|
157 # define BT_BORDERFILL 1 |
|
158 #endif |
|
159 #ifndef BT_NONE |
|
160 # define BT_NONE 2 |
|
161 #endif |
|
162 #ifndef TMT_FILLCOLOR |
|
163 # define TMT_FILLCOLOR 3802 |
|
164 #endif |
|
165 #ifndef TMT_PROGRESSCHUNKSIZE |
|
166 # define TMT_PROGRESSCHUNKSIZE 2411 |
|
167 #endif |
|
168 |
|
169 // TMT_TEXTSHADOWCOLOR is wrongly defined in mingw |
|
170 #if TMT_TEXTSHADOWCOLOR != 3818 |
|
171 #undef TMT_TEXTSHADOWCOLOR |
|
172 #define TMT_TEXTSHADOWCOLOR 3818 |
|
173 #endif |
|
174 #ifndef TST_NONE |
|
175 # define TST_NONE 0 |
|
176 #endif |
|
177 |
|
178 #ifndef GT_NONE |
|
179 # define GT_NONE 0 |
|
180 #endif |
|
181 #ifndef GT_IMAGEGLYPH |
|
182 # define GT_IMAGEGLYPH 1 |
|
183 #endif |
|
184 |
|
185 // These defines are missing from the tmschema, but still exist as |
|
186 // states for their parts |
|
187 #ifndef MINBS_INACTIVE |
|
188 #define MINBS_INACTIVE 5 |
|
189 #endif |
|
190 #ifndef MAXBS_INACTIVE |
|
191 #define MAXBS_INACTIVE 5 |
|
192 #endif |
|
193 #ifndef RBS_INACTIVE |
|
194 #define RBS_INACTIVE 5 |
|
195 #endif |
|
196 #ifndef HBS_INACTIVE |
|
197 #define HBS_INACTIVE 5 |
|
198 #endif |
|
199 #ifndef CBS_INACTIVE |
|
200 #define CBS_INACTIVE 5 |
|
201 #endif |
|
202 |
|
203 // Uncomment define below to build debug assisting code, and output |
|
204 // #define DEBUG_XP_STYLE |
|
205 |
|
206 #if !defined(QT_NO_STYLE_WINDOWSXP) |
|
207 |
|
208 // Declarations ----------------------------------------------------------------------------------- |
|
209 class XPThemeData |
|
210 { |
|
211 public: |
|
212 XPThemeData(const QWidget *w = 0, QPainter *p = 0, const QString &theme = QString(), |
|
213 int part = 0, int state = 0, const QRect &r = QRect()) |
|
214 : widget(w), painter(p), name(theme), htheme(0), partId(part), stateId(state), |
|
215 mirrorHorizontally(false), mirrorVertically(false), noBorder(false), |
|
216 noContent(false), rotate(0), rect(r) |
|
217 {} |
|
218 |
|
219 HRGN mask(); |
|
220 HTHEME handle(); |
|
221 |
|
222 RECT toRECT(const QRect &qr); |
|
223 bool isValid(); |
|
224 |
|
225 const QWidget *widget; |
|
226 QPainter *painter; |
|
227 QString name; |
|
228 HTHEME htheme; |
|
229 int partId; |
|
230 int stateId; |
|
231 |
|
232 uint mirrorHorizontally : 1; |
|
233 uint mirrorVertically : 1; |
|
234 uint noBorder : 1; |
|
235 uint noContent : 1; |
|
236 uint rotate; |
|
237 QRect rect; |
|
238 }; |
|
239 |
|
240 struct ThemeMapKey { |
|
241 QString name; |
|
242 int partId; |
|
243 int stateId; |
|
244 bool noBorder; |
|
245 bool noContent; |
|
246 |
|
247 ThemeMapKey() : partId(-1), stateId(-1) {} |
|
248 ThemeMapKey(const XPThemeData &data) |
|
249 : name(data.name), partId(data.partId), stateId(data.stateId), |
|
250 noBorder(data.noBorder), noContent(data.noContent) {} |
|
251 |
|
252 }; |
|
253 |
|
254 inline uint qHash(const ThemeMapKey &key) |
|
255 { return qHash(key.name) ^ key.partId ^ key.stateId; } |
|
256 |
|
257 inline bool operator==(const ThemeMapKey &k1, const ThemeMapKey &k2) |
|
258 { |
|
259 return k1.name == k2.name |
|
260 && k1.partId == k2.partId |
|
261 && k1.stateId == k2.stateId; |
|
262 } |
|
263 |
|
264 enum AlphaChannelType { |
|
265 UnknownAlpha = -1, // Alpha of part & state not yet known |
|
266 NoAlpha, // Totally opaque, no need to touch alpha (RGB) |
|
267 MaskAlpha, // Alpha channel must be fixed (ARGB) |
|
268 RealAlpha // Proper alpha values from Windows (ARGB_Premultiplied) |
|
269 }; |
|
270 |
|
271 struct ThemeMapData { |
|
272 AlphaChannelType alphaType; // Which type of alpha on part & state |
|
273 |
|
274 bool dataValid : 1; // Only used to detect if hash value is ok |
|
275 bool partIsTransparent : 1; |
|
276 bool hasAnyData : 1; // False = part & state has not data, NOP |
|
277 bool hasAlphaChannel : 1; // True = part & state has real Alpha |
|
278 bool wasAlphaSwapped : 1; // True = alpha channel needs to be swapped |
|
279 bool hadInvalidAlpha : 1; // True = alpha channel contained invalid alpha values |
|
280 |
|
281 ThemeMapData() : dataValid(false), partIsTransparent(false), hasAnyData(false), |
|
282 hasAlphaChannel(false), wasAlphaSwapped(false), hadInvalidAlpha(false) {} |
|
283 }; |
|
284 |
|
285 class QWindowsXPStylePrivate : public QWindowsStylePrivate |
|
286 { |
|
287 Q_DECLARE_PUBLIC(QWindowsXPStyle) |
|
288 public: |
|
289 QWindowsXPStylePrivate() |
|
290 : QWindowsStylePrivate(), hasInitColors(false), bufferDC(0), bufferBitmap(0), nullBitmap(0), |
|
291 bufferPixels(0), bufferW(0), bufferH(0) |
|
292 { init(); } |
|
293 |
|
294 ~QWindowsXPStylePrivate() |
|
295 { cleanup(); } |
|
296 |
|
297 static HWND winId(const QWidget *widget); |
|
298 |
|
299 void init(bool force = false); |
|
300 void cleanup(bool force = false); |
|
301 void cleanupHandleMap(); |
|
302 const QPixmap *tabBody(QWidget *widget); |
|
303 |
|
304 HBITMAP buffer(int w = 0, int h = 0); |
|
305 HDC bufferHDC() |
|
306 { return bufferDC;} |
|
307 |
|
308 static bool resolveSymbols(); |
|
309 static bool useXP(bool update = false); |
|
310 |
|
311 bool isTransparent(XPThemeData &themeData); |
|
312 QRegion region(XPThemeData &themeData); |
|
313 |
|
314 void setTransparency(QWidget *widget, XPThemeData &themeData); |
|
315 void drawBackground(XPThemeData &themeData); |
|
316 void drawBackgroundThruNativeBuffer(XPThemeData &themeData); |
|
317 void drawBackgroundDirectly(XPThemeData &themeData); |
|
318 |
|
319 bool hasAnyData(const QRect &rect); |
|
320 bool hasAlphaChannel(const QRect &rect); |
|
321 bool fixAlphaChannel(const QRect &rect); |
|
322 bool swapAlphaChannel(const QRect &rect, bool allPixels = false); |
|
323 |
|
324 QRgb groupBoxTextColor; |
|
325 QRgb groupBoxTextColorDisabled; |
|
326 QRgb sliderTickColor; |
|
327 bool hasInitColors; |
|
328 |
|
329 static QMap<QString,HTHEME> *handleMap; |
|
330 |
|
331 QIcon dockFloat, dockClose; |
|
332 |
|
333 private: |
|
334 #ifdef DEBUG_XP_STYLE |
|
335 void dumpNativeDIB(int w, int h); |
|
336 void showProperties(XPThemeData &themeData); |
|
337 #endif |
|
338 |
|
339 static QBasicAtomicInt ref; |
|
340 static bool use_xp; |
|
341 static QWidget *limboWidget; |
|
342 static QPixmap *tabbody; |
|
343 |
|
344 QHash<ThemeMapKey, ThemeMapData> alphaCache; |
|
345 HDC bufferDC; |
|
346 HBITMAP bufferBitmap; |
|
347 HBITMAP nullBitmap; |
|
348 uchar *bufferPixels; |
|
349 int bufferW, bufferH; |
|
350 }; |
|
351 |
|
352 #endif // QT_NO_STYLE_WINDOWS |
|
353 |
|
354 QT_END_NAMESPACE |
|
355 |
|
356 #endif //QWINDOWSXPSTYLE_P_H |