Qt 4.8
qwindowsxpstyle_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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 
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 -----------------------------------------------------------------------------------
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;
228  HTHEME htheme;
229  int partId;
230  int stateId;
231 
238 };
239 
240 struct ThemeMapKey {
242  int partId;
243  int stateId;
244  bool noBorder;
245  bool noContent;
246 
247  ThemeMapKey() : partId(-1), stateId(-1) {}
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 
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
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 
286 {
288 public:
290  : QWindowsStylePrivate(), hasInitColors(false), bufferDC(0), bufferBitmap(0), nullBitmap(0),
291  bufferPixels(0), bufferW(0), bufferH(0)
292  { init(); }
293 
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  static bool isItemViewDelegateLineEdit(const QWidget *widget);
325 
330 
332 
333  QIcon dockFloat, dockClose;
334 
335 private:
336 #ifdef DEBUG_XP_STYLE
337  void dumpNativeDIB(int w, int h);
338  void showProperties(XPThemeData &themeData);
339 #endif
340 
342  static bool use_xp;
344  static QPixmap *tabbody;
345 
347  HDC bufferDC;
348  HBITMAP bufferBitmap;
349  HBITMAP nullBitmap;
351  int bufferW, bufferH;
352 };
353 
354 #endif // QT_NO_STYLE_WINDOWS
355 
357 
358 #endif //QWINDOWSXPSTYLE_P_H
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
const QWidget * widget
QPainter * painter
unsigned int QRgb
Definition: qrgb.h:53
struct _DTBGOPTS * PDTBGOPTS
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QPointer< QWidget > widget
static QPixmap * tabbody
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
static QBasicAtomicInt ref
The QString class provides a Unicode character string.
Definition: qstring.h:83
struct _DTBGOPTS DTBGOPTS
uint qHash(const ThemeMapKey &key)
XPThemeData(const QWidget *w=0, QPainter *p=0, const QString &theme=QString(), int part=0, int state=0, const QRect &r=QRect())
QHash< ThemeMapKey, ThemeMapData > alphaCache
unsigned char uchar
Definition: qglobal.h:994
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static bool init
const char * name
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
The QWindowsXPStyle class provides a Microsoft Windows XP-like look and feel.
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
ThemeMapKey(const XPThemeData &data)
AlphaChannelType
int key
static void cleanup()
Definition: qpicture.cpp:1508
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
static QWidget * limboWidget
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
static QMap< QString, HTHEME > * handleMap
bool operator==(const ThemeMapKey &k1, const ThemeMapKey &k2)
AlphaChannelType alphaType
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60