Qt 4.8
Public Functions | Static Public Functions | Public Variables | Static Public Variables | Properties | Static Private Attributes | List of all members
QWindowsXPStylePrivate Class Reference

#include <qwindowsxpstyle_p.h>

Inheritance diagram for QWindowsXPStylePrivate:
QWindowsStylePrivate QCommonStylePrivate QStylePrivate QObjectPrivate QObjectData QWindowsVistaStylePrivate

Public Functions

HBITMAP buffer (int w=0, int h=0)
 Returns a native buffer (DIB section) of at least the size of ( x , y ). More...
 
HDC bufferHDC ()
 
void cleanup (bool force=false)
 
void cleanupHandleMap ()
 
void drawBackground (XPThemeData &themeData)
 Main theme drawing function. More...
 
void drawBackgroundDirectly (XPThemeData &themeData)
 This function draws the theme parts directly to the paintengines HDC. More...
 
void drawBackgroundThruNativeBuffer (XPThemeData &themeData)
 This function uses a secondary Native doublebuffer for painting parts. More...
 
bool fixAlphaChannel (const QRect &rect)
 When the theme engine paints both a true alpha pixmap and a glyph into our buffer, the glyph might not contain a proper alpha value. More...
 
bool hasAlphaChannel (const QRect &rect)
 Returns true if the native doublebuffer contains pixels with varying alpha value. More...
 
bool hasAnyData (const QRect &rect)
 Returns true if the native doublebuffer contains a pixel which has a non-0xFF alpha value. More...
 
void init (bool force=false)
 
bool isTransparent (XPThemeData &themeData)
 Returns true if the part contains any transparency at all. More...
 
 QWindowsXPStylePrivate ()
 
QRegion region (XPThemeData &themeData)
 
void setTransparency (QWidget *widget, XPThemeData &themeData)
 Sets the parts region on a window. More...
 
bool swapAlphaChannel (const QRect &rect, bool allPixels=false)
 Swaps the alpha values on certain pixels: 0xFF?????? -> 0x00?????? 0x00?????? -> 0xFF?????? Used to determin the mask of a non-alpha transparent pixmap in the native doublebuffer, and swap the alphas so we may paint the image as a Premultiplied QImage with drawImage(), and obtain the mask transparency. More...
 
const QPixmaptabBody (QWidget *widget)
 Returns the pointer to a tab widgets body pixmap, scaled to the height of the screen. More...
 
 ~QWindowsXPStylePrivate ()
 
- Public Functions inherited from QWindowsStylePrivate
bool altDown () const
 
bool hasSeenAlt (const QWidget *widget) const
 
 QWindowsStylePrivate ()
 
void startAnimation (QObject *o, QProgressBar *bar)
 
void stopAnimation (QObject *o, QProgressBar *bar)
 
- Public Functions inherited from QCommonStylePrivate
bool isViewItemCached (const QStyleOptionViewItemV4 &option) const
 
 QCommonStylePrivate ()
 
void tabLayout (const QStyleOptionTabV3 *opt, const QWidget *widget, QRect *textRect, QRect *pixmapRect) const
 
void viewItemDrawText (QPainter *p, const QStyleOptionViewItemV4 *option, const QRect &rect) const
 
void viewItemLayout (const QStyleOptionViewItemV4 *opt, QRect *checkRect, QRect *pixmapRect, QRect *textRect, bool sizehint) const
 Set sizehint to false to layout the elements inside opt->rect. More...
 
QSize viewItemSize (const QStyleOptionViewItemV4 *option, int role) const
 
 ~QCommonStylePrivate ()
 
- Public Functions inherited from QStylePrivate
 QStylePrivate ()
 
- Public Functions inherited from QObjectPrivate
void _q_reregisterTimers (void *pointer)
 
void addConnection (int signal, Connection *c)
 
void cleanConnectionLists ()
 
void connectNotify (const char *signal)
 
void deleteChildren ()
 
void disconnectNotify (const char *signal)
 
bool isSender (const QObject *receiver, const char *signal) const
 
bool isSignalConnected (uint signalIdx) const
 Returns true if the signal with index signal_index from object sender is connected. More...
 
void moveToThread_helper ()
 
 QObjectPrivate (int version=QObjectPrivateVersion)
 
QObjectList receiverList (const char *signal) const
 
QObjectList senderList () const
 
void setParent_helper (QObject *)
 
void setThreadData_helper (QThreadData *currentData, QThreadData *targetData)
 
int signalIndex (const char *signalName) const
 Returns the signal index used in the internal connectionLists vector. More...
 
virtual ~QObjectPrivate ()
 
- Public Functions inherited from QObjectData
virtual ~QObjectData ()=0
 

Static Public Functions

static bool isItemViewDelegateLineEdit (const QWidget *widget)
 
static bool resolveSymbols ()
 Returns true if all the necessary theme engine symbols were resolved. More...
 
static bool useXP (bool update=false)
 
static HWND winId (const QWidget *widget)
 This function will always return a valid window handle, and might create a limbo widget to do so. More...
 
- Static Public Functions inherited from QObjectPrivate
static void clearGuards (QObject *)
 
static QObjectPrivateget (QObject *o)
 
static void resetCurrentSender (QObject *receiver, Sender *currentSender, Sender *previousSender)
 
static SendersetCurrentSender (QObject *receiver, Sender *sender)
 
static void signalSignature (const QMetaMethod &signal, QVarLengthArray< char > *result)
 

Public Variables

QIcon dockClose
 
QIcon dockFloat
 
QRgb groupBoxTextColor
 
QRgb groupBoxTextColorDisabled
 
bool hasInitColors
 
QRgb sliderTickColor
 
- Public Variables inherited from QWindowsStylePrivate
QColor activeCaptionColor
 
QColor activeGradientCaptionColor
 
bool alt_down
 
QList< QProgressBar * > animatedProgressBars
 
int animateStep
 
int animateTimer
 
int animationFps
 
QColor inactiveCaptionColor
 
QColor inactiveCaptionText
 
QColor inactiveGradientCaptionColor
 
int menuBarTimer
 
QList< const QWidget * > seenAlt
 
QElapsedTimer startTime
 
- Public Variables inherited from QCommonStylePrivate
QStyleOptionViewItemV4cachedOption
 
QRect checkRect
 
QRect decorationRect
 
QRect displayRect
 
QIcon tabBarcloseButtonIcon
 
- Public Variables inherited from QStylePrivate
int layoutSpacingIndex
 
QStyleproxyStyle
 
- Public Variables inherited from QObjectPrivate
union {
   QObject *   currentChildBeingDeleted
 
   QAbstractDeclarativeData *   declarativeData
 
}; 
 
quint32 connectedSignals [2]
 
QObjectConnectionListVectorconnectionLists
 
SendercurrentSender
 
QList< QPointer< QObject > > eventFilters
 
ExtraDataextraData
 
QString objectName
 
Connectionsenders
 
QAtomicPointer< QtSharedPointer::ExternalRefCountData > sharedRefcount
 
QThreadDatathreadData
 
void * unused
 
- Public Variables inherited from QObjectData
uint blockSig: 1
 
QObjectList children
 
uint hasGuards: 1
 
uint inEventHandler: 1
 
uint inThreadChangeEvent: 1
 
uint isWidget: 1
 
QMetaObjectmetaObject
 
uint ownObjectName: 1
 
QObjectparent
 
uint pendTimer: 1
 
int postedEvents
 
QObjectq_ptr
 
uint receiveChildEvents: 1
 
uint sendChildEvents: 1
 
uint unused: 22
 
uint wasDeleted: 1
 

Static Public Variables

static QMap< QString, HTHEME > * handleMap = 0
 

Properties

QHash< ThemeMapKey, ThemeMapDataalphaCache
 
HBITMAP bufferBitmap
 
HDC bufferDC
 
int bufferH
 
ucharbufferPixels
 
int bufferW
 
HBITMAP nullBitmap
 

Static Private Attributes

static QWidgetlimboWidget = 0
 
static QBasicAtomicInt ref = Q_BASIC_ATOMIC_INITIALIZER(-1)
 
static QPixmaptabbody = 0
 
static bool use_xp = false
 

Additional Inherited Members

- Public Types inherited from QWindowsStylePrivate
enum  {
  windowsItemFrame = 2, windowsSepHeight = 9, windowsItemHMargin = 3, windowsItemVMargin = 2,
  windowsArrowHMargin = 6, windowsRightBorder = 15, windowsCheckMarkWidth = 12
}
 
- Public Types inherited from QObjectPrivate
typedef void(* StaticMetaCallFunction) (QObject *, QMetaObject::Call, int, void **)
 

Detailed Description

Definition at line 285 of file qwindowsxpstyle_p.h.

Constructors and Destructors

◆ QWindowsXPStylePrivate()

QWindowsXPStylePrivate::QWindowsXPStylePrivate ( )
inline

◆ ~QWindowsXPStylePrivate()

QWindowsXPStylePrivate::~QWindowsXPStylePrivate ( )
inline

Definition at line 294 of file qwindowsxpstyle_p.h.

295  { cleanup(); }
void cleanup(bool force=false)

Functions

◆ buffer()

HBITMAP QWindowsXPStylePrivate::buffer ( int  w = 0,
int  h = 0 
)

Returns a native buffer (DIB section) of at least the size of ( x , y ).

Warning
This function is not part of the public interface. The buffer has a 32 bit depth, to not lose the alpha values on proper alpha-pixmaps.

Definition at line 410 of file qwindowsxpstyle.cpp.

411 {
412  // If we already have a HBITMAP which is of adequate size, just return that
413  if (bufferBitmap) {
414  if (bufferW >= w && bufferH >= h)
415  return bufferBitmap;
416  // Not big enough, discard the old one
417  if (bufferDC && nullBitmap)
418  SelectObject(bufferDC, nullBitmap);
419  DeleteObject(bufferBitmap);
420  bufferBitmap = 0;
421  }
422 
423  w = qMax(bufferW, w);
424  h = qMax(bufferH, h);
425 
426  if (!bufferDC)
427  bufferDC = CreateCompatibleDC(qt_win_display_dc());
428 
429  // Define the header
430  BITMAPINFO bmi;
431  memset(&bmi, 0, sizeof(bmi));
432  bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
433  bmi.bmiHeader.biWidth = w;
434  bmi.bmiHeader.biHeight = -h;
435  bmi.bmiHeader.biPlanes = 1;
436  bmi.bmiHeader.biBitCount = 32;
437  bmi.bmiHeader.biCompression = BI_RGB;
438 
439  // Create the pixmap
440  bufferPixels = 0;
441  bufferBitmap = CreateDIBSection(bufferDC, &bmi, DIB_RGB_COLORS, (void **) &bufferPixels, 0, 0);
442  GdiFlush();
443  nullBitmap = (HBITMAP)SelectObject(bufferDC, bufferBitmap);
444 
445  if (!bufferBitmap) {
446  qErrnoWarning("QWindowsXPStylePrivate::buffer(w,h), failed to create dibsection");
447  bufferW = 0;
448  bufferH = 0;
449  return 0;
450  }
451  if (!bufferPixels) {
452  qErrnoWarning("QWindowsXPStylePrivate::buffer(w,h), did not allocate pixel data");
453  bufferW = 0;
454  bufferH = 0;
455  return 0;
456  }
457  bufferW = w;
458  bufferH = h;
459 #ifdef DEBUG_XP_STYLE
460  qDebug("Creating new dib section (%d, %d)", w, h);
461 #endif
462  return bufferBitmap;
463 }
Q_GUI_EXPORT HDC qt_win_display_dc()
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
Q_CORE_EXPORT void qDebug(const char *,...)
void qErrnoWarning(const char *msg,...)
Definition: qglobal.cpp:2954

◆ bufferHDC()

HDC QWindowsXPStylePrivate::bufferHDC ( )
inline

Definition at line 305 of file qwindowsxpstyle_p.h.

306  { return bufferDC;}

◆ cleanup()

void QWindowsXPStylePrivate::cleanup ( bool  force = false)

Definition at line 242 of file qwindowsxpstyle.cpp.

243 {
244  if(bufferBitmap) {
245  if (bufferDC && nullBitmap)
246  SelectObject(bufferDC, nullBitmap);
247  DeleteObject(bufferBitmap);
248  bufferBitmap = 0;
249  }
250 
251  if(bufferDC)
252  DeleteDC(bufferDC);
253  bufferDC = 0;
254 
255  if (ref.deref() && !force)
256  return;
257  if (!force) // -1 based atomic refcounting
258  ref.deref();
259 
260  use_xp = false;
262  if (limboWidget) {
264  delete limboWidget;
265  else
267  }
268  delete tabbody;
269  limboWidget = 0;
270  tabbody = 0;
271 }
static QPixmap * tabbody
static QBasicAtomicInt ref
static bool closingDown()
Returns true if the application objects are being destroyed; otherwise returns false.
static QWidget * limboWidget
void deleteLater()
Schedules this object for deletion.
Definition: qobject.cpp:2145

◆ cleanupHandleMap()

void QWindowsXPStylePrivate::cleanupHandleMap ( )

Definition at line 278 of file qwindowsxpstyle.cpp.

279 {
280  if (!handleMap)
281  return;
282 
284  for (it = handleMap->begin(); it != handleMap->end(); ++it)
285  pCloseThemeData(it.value());
286  delete handleMap;
287  handleMap = 0;
288 }
#define it(className, varName)
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
iterator begin()
Returns an STL-style iterator pointing to the first item in the map.
Definition: qmap.h:372
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:375
static PtrCloseThemeData pCloseThemeData
static QMap< QString, HTHEME > * handleMap
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67

◆ drawBackground()

void QWindowsXPStylePrivate::drawBackground ( XPThemeData themeData)

Main theme drawing function.

Warning
This function is not part of the public interface.

Determines the correct lowlevel drawing method depending on several factors. Use drawBackgroundThruNativeBuffer() if:

Definition at line 660 of file qwindowsxpstyle.cpp.

Referenced by QWindowsVistaStyle::drawComplexControl(), QWindowsXPStyle::drawComplexControl(), QWindowsVistaStyle::drawControl(), QWindowsXPStyle::drawControl(), QWindowsVistaStyle::drawPrimitive(), QWindowsXPStyle::drawPrimitive(), QWindowsXPStyle::standardIconImplementation(), and QWindowsVistaStyle::standardIconImplementation().

661 {
662  if (themeData.rect.isEmpty())
663  return;
664 
665  QPainter *painter = themeData.painter;
666  Q_ASSERT_X(painter != 0, "QWindowsXPStylePrivate::drawBackground()", "Trying to draw a theme part without a painter");
667  if (!painter || !painter->isActive())
668  return;
669 
670  painter->save();
671 
672  bool complexXForm = painter->deviceTransform().type() > QTransform::TxTranslate;
673 
674  bool translucentToplevel = false;
675  QPaintDevice *pdev = painter->device();
676  if (pdev->devType() == QInternal::Widget) {
677  QWidget *win = ((QWidget *) pdev)->window();
678  translucentToplevel = win->testAttribute(Qt::WA_TranslucentBackground);
679  }
680 
681  bool useFallback = painter->paintEngine()->getDC() == 0
682  || painter->opacity() != 1.0
683  || themeData.rotate
684  || complexXForm
685  || themeData.mirrorVertically
686  || (themeData.mirrorHorizontally && pDrawThemeBackgroundEx == 0)
687  || translucentToplevel;
688 
689  if (!useFallback)
690  drawBackgroundDirectly(themeData);
691  else
693 
694  painter->restore();
695 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
QPaintDevice * device() const
Returns the paint device on which this painter is currently painting, or 0 if the painter is not acti...
Definition: qpainter.cpp:1530
QPainter * painter
void drawBackgroundThruNativeBuffer(XPThemeData &themeData)
This function uses a secondary Native doublebuffer for painting parts.
qreal opacity() const
Returns the opacity of the painter.
Definition: qpainter.cpp:2115
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
TransformationType type() const
Returns the transformation type of this matrix.
virtual int devType() const
Definition: qpaintdevice.h:167
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
void drawBackgroundDirectly(XPThemeData &themeData)
This function draws the theme parts directly to the paintengines HDC.
virtual HDC getDC() const
Empty default implementation.
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
bool isActive() const
Returns true if begin() has been called and end() has not yet been called; otherwise returns false...
Definition: qpainter.cpp:1545
const QTransform & deviceTransform() const
Returns the matrix that transforms from logical coordinates to device coordinates of the platform dep...
Definition: qpainter.cpp:9579
QPaintEngine * paintEngine() const
Returns the paint engine that the painter is currently operating on if the painter is active; otherwi...
Definition: qpainter.cpp:1991
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:234
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
QWidget * window() const
Returns the window for this widget, i.e.
Definition: qwidget.cpp:4492
static PtrDrawThemeBackgroundEx pDrawThemeBackgroundEx

◆ drawBackgroundDirectly()

void QWindowsXPStylePrivate::drawBackgroundDirectly ( XPThemeData themeData)

This function draws the theme parts directly to the paintengines HDC.

Warning
This function is not part of the public interface.

Do not use this if you need to perform other transformations on the resulting data.

Definition at line 705 of file qwindowsxpstyle.cpp.

706 {
707  QPainter *painter = themeData.painter;
708  HDC dc = painter->paintEngine()->getDC();
709 
710  QPoint redirectionDelta(int(painter->deviceMatrix().dx()),
711  int(painter->deviceMatrix().dy()));
712  QRect area = themeData.rect.translated(redirectionDelta);
713 
714  QRegion sysRgn = painter->paintEngine()->systemClip();
715  if (sysRgn.isEmpty())
716  sysRgn = area;
717  else
718  sysRgn &= area;
719  if (painter->hasClipping())
720  sysRgn &= painter->clipRegion().translated(redirectionDelta);
721  SelectClipRgn(dc, sysRgn.handle());
722 
723 #ifdef DEBUG_XP_STYLE
724  printf("---[ DIRECT PAINTING ]------------------> Name(%-10s) Part(%d) State(%d)\n",
725  qPrintable(themeData.name), themeData.partId, themeData.stateId);
726  showProperties(themeData);
727 #endif
728 
729  RECT drawRECT = themeData.toRECT(area);
730  DTBGOPTS drawOptions;
731  drawOptions.dwSize = sizeof(drawOptions);
732  drawOptions.rcClip = themeData.toRECT(sysRgn.boundingRect());
733  drawOptions.dwFlags = DTBG_CLIPRECT
734  | (themeData.noBorder ? DTBG_OMITBORDER : 0)
735  | (themeData.noContent ? DTBG_OMITCONTENT : 0)
736  | (themeData.mirrorHorizontally ? DTBG_MIRRORDC : 0);
737 
738  if (pDrawThemeBackgroundEx != 0) {
739  pDrawThemeBackgroundEx(themeData.handle(), dc, themeData.partId, themeData.stateId, &(drawRECT), &drawOptions);
740  } else {
741  // We are running on a system where the uxtheme.dll does not have
742  // the DrawThemeBackgroundEx function, so we need to clip away
743  // borders or contents manually. All flips and mirrors uses the
744  // fallback implementation
745 
746  int borderSize = 0;
747  PROPERTYORIGIN origin = PO_NOTFOUND;
748  pGetThemePropertyOrigin(themeData.handle(), themeData.partId, themeData.stateId, TMT_BORDERSIZE, &origin);
749  pGetThemeInt(themeData.handle(), themeData.partId, themeData.stateId, TMT_BORDERSIZE, &borderSize);
750 
751  // Clip away border region
752  QRegion extraClip = sysRgn;
753  if ((origin == PO_CLASS || origin == PO_PART || origin == PO_STATE) && borderSize > 0) {
754  if (themeData.noBorder) {
755  // extraClip &= area is already done
756  drawRECT = themeData.toRECT(area.adjusted(-borderSize, -borderSize, borderSize, borderSize));
757  }
758 
759  // Clip away content region
760  if (themeData.noContent) {
761  QRegion content = area.adjusted(borderSize, borderSize, -borderSize, -borderSize);
762  extraClip ^= content;
763  }
764 
765  // Set the clip region, if used..
766  if (themeData.noBorder || themeData.noContent)
767  SelectClipRgn(dc, extraClip.handle());
768  }
769 
770  pDrawThemeBackground(themeData.handle(), dc, themeData.partId, themeData.stateId, &(drawRECT), &(drawOptions.rcClip));
771  }
772  SelectClipRgn(dc, 0);
773 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
QPainter * painter
QRect adjusted(int x1, int y1, int x2, int y2) const
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition: qrect.h:431
qreal dx() const
Returns the horizontal translation factor.
Definition: qmatrix.h:77
#define DTBG_OMITCONTENT
static PtrGetThemeInt pGetThemeInt
QRect translated(int dx, int dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:328
QRect boundingRect() const
Returns the bounding rectangle of this region.
Definition: qregion.cpp:4363
#define DTBG_MIRRORDC
const QMatrix & deviceMatrix() const
Returns the matrix that transforms from logical coordinates to device coordinates of the platform dep...
Definition: qpainter.cpp:3110
virtual HDC getDC() const
Empty default implementation.
QRegion clipRegion() const
Returns the currently set clip region.
Definition: qpainter.cpp:2562
bool hasClipping() const
Returns true if clipping has been set; otherwise returns false.
Definition: qpainter.cpp:2499
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
Definition: qregion.cpp:4098
QPaintEngine * paintEngine() const
Returns the paint engine that the painter is currently operating on if the painter is active; otherwi...
Definition: qpainter.cpp:1991
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
RECT toRECT(const QRect &qr)
#define DTBG_OMITBORDER
qreal dy() const
Returns the vertical translation factor.
Definition: qmatrix.h:78
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
static PtrDrawThemeBackgroundEx pDrawThemeBackgroundEx
QRegion translated(int dx, int dy) const
Returns a copy of the region that is translated dx along the x axis and dy along the y axis...
Definition: qregion.cpp:743
#define TMT_BORDERSIZE
#define qPrintable(string)
Definition: qglobal.h:1750
QRegion systemClip() const
Returns the system clip.
static PtrGetThemePropertyOrigin pGetThemePropertyOrigin
static PtrDrawThemeBackground pDrawThemeBackground
Handle handle() const
Returns a platform-specific region handle.
#define DTBG_CLIPRECT
static int area(const QSize &s)
Definition: qicon.cpp:155

◆ drawBackgroundThruNativeBuffer()

void QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer ( XPThemeData themeData)

This function uses a secondary Native doublebuffer for painting parts.

Warning
This function is not part of the public interface.

It should only be used when the painteengine doesn't provide a proper HDC for direct painting (e.g. when doing a grabWidget(), painting to other pixmaps etc), or when special transformations are needed (e.g. flips (horizonal mirroring only, vertical are handled by the theme engine).

Definition at line 786 of file qwindowsxpstyle.cpp.

787 {
788  QPainter *painter = themeData.painter;
789  QRect rect = themeData.rect;
790 
791  if ((themeData.rotate + 90) % 180 == 0) { // Catch 90,270,etc.. degree flips.
792  rect = QRect(0, 0, rect.height(), rect.width());
793  }
794  rect.moveTo(0,0);
795  int partId = themeData.partId;
796  int stateId = themeData.stateId;
797  int w = rect.width();
798  int h = rect.height();
799 
800  // Values initialized later, either from cached values, or from function calls
801  AlphaChannelType alphaType = UnknownAlpha;
802  bool stateHasData = true; // We assume so;
803  bool hasAlpha = false;
804  bool partIsTransparent;
805  bool inspectData;
806  bool potentialInvalidAlpha;
807 
808  QString pixmapCacheKey = QString::fromLatin1("$qt_xp_%1p%2s%3s%4b%5c%6w%7h").arg(themeData.name)
809  .arg(partId).arg(stateId).arg(!themeData.noBorder).arg(!themeData.noContent)
810  .arg(w).arg(h);
811  QPixmap cachedPixmap;
812  ThemeMapKey key(themeData);
814 
815  bool haveCachedPixmap = false;
816  bool isCached = data.dataValid;
817  if (isCached) {
818  if (!(stateHasData = data.hasAnyData))
819  return; // Cached NOOP
820  inspectData = data.wasAlphaSwapped;
821  partIsTransparent = data.partIsTransparent;
822  hasAlpha = data.hasAlphaChannel;
823  alphaType = data.alphaType;
824  potentialInvalidAlpha = data.hadInvalidAlpha;
825 
826  haveCachedPixmap = QPixmapCache::find(pixmapCacheKey, cachedPixmap);
827 
828 #ifdef DEBUG_XP_STYLE
829  char buf[25];
830  ::sprintf(buf, "+ Pixmap(%3d, %3d) ]", w, h);
831  printf("---[ CACHED %s--------> Name(%-10s) Part(%d) State(%d)\n",
832  haveCachedPixmap ? buf : "]-------------------",
833  qPrintable(themeData.name), themeData.partId, themeData.stateId);
834 #endif
835  } else {
836  // Not cached, so get values from Theme Engine
837  BOOL tmt_borderonly = false;
838  COLORREF tmt_transparentcolor = 0x0;
839  PROPERTYORIGIN proporigin = PO_NOTFOUND;
840  pGetThemeBool(themeData.handle(), themeData.partId, themeData.stateId, TMT_BORDERONLY, &tmt_borderonly);
841  pGetThemeColor(themeData.handle(), themeData.partId, themeData.stateId, TMT_TRANSPARENTCOLOR, &tmt_transparentcolor);
842  pGetThemePropertyOrigin(themeData.handle(), themeData.partId, themeData.stateId, TMT_CAPTIONMARGINS, &proporigin);
843  inspectData = (tmt_transparentcolor != 0 || tmt_borderonly || proporigin == PO_PART || proporigin == PO_STATE);
844 
845  // ### This is a vista-specific workaround for broken alpha in titlebar pixmaps
847  if (themeData.partId == WP_CAPTION || themeData.partId == WP_SMALLCAPTION)
848  inspectData = false;
849  }
850 
851  partIsTransparent = isTransparent(themeData);
852 
853  potentialInvalidAlpha = false;
854  pGetThemePropertyOrigin(themeData.handle(), themeData.partId, themeData.stateId, TMT_GLYPHTYPE, &proporigin);
855  if (proporigin == PO_PART || proporigin == PO_STATE) {
856  int tmt_glyphtype = GT_NONE;
857  pGetThemeEnumValue(themeData.handle(), themeData.partId, themeData.stateId, TMT_GLYPHTYPE, &tmt_glyphtype);
858  potentialInvalidAlpha = partIsTransparent && !inspectData && tmt_glyphtype == GT_IMAGEGLYPH;
859  }
860 
861 #ifdef DEBUG_XP_STYLE
862  printf("---[ NOT CACHED ]-----------------------> Name(%-10s) Part(%d) State(%d)\n",
863  qPrintable(themeData.name), themeData.partId, themeData.stateId);
864  printf("-->partIsTransparen = %d\n", partIsTransparent);
865  printf("-->inspectData = %d\n", inspectData);
866  printf("-->potentialInvalidAlpha = %d\n", potentialInvalidAlpha);
867  showProperties(themeData);
868 #endif
869  }
870  bool wasAlphaSwapped = false;
871  bool wasAlphaFixed = false;
872 
873  // OLD PSDK Workaround ------------------------------------------------------------------------
874  // See if we need extra clipping for the older PSDK, which does
875  // not have a DrawThemeBackgroundEx function for DTGB_OMITBORDER
876  // and DTGB_OMITCONTENT
877  bool addBorderContentClipping = false;
878  QRegion extraClip;
879  QRect area = rect;
880  if (themeData.noBorder || themeData.noContent) {
881  extraClip = area;
882  // We are running on a system where the uxtheme.dll does not have
883  // the DrawThemeBackgroundEx function, so we need to clip away
884  // borders or contents manually.
885 
886  int borderSize = 0;
887  PROPERTYORIGIN origin = PO_NOTFOUND;
888  pGetThemePropertyOrigin(themeData.handle(), themeData.partId, themeData.stateId, TMT_BORDERSIZE, &origin);
889  pGetThemeInt(themeData.handle(), themeData.partId, themeData.stateId, TMT_BORDERSIZE, &borderSize);
890 
891  // Clip away border region
892  if ((origin == PO_CLASS || origin == PO_PART || origin == PO_STATE) && borderSize > 0) {
893  if (themeData.noBorder) {
894  extraClip &= area;
895  area = area.adjusted(-borderSize, -borderSize, borderSize, borderSize);
896  }
897 
898  // Clip away content region
899  if (themeData.noContent) {
900  QRegion content = area.adjusted(borderSize, borderSize, -borderSize, -borderSize);
901  extraClip ^= content;
902  }
903  }
904  addBorderContentClipping = (themeData.noBorder | themeData.noContent);
905  }
906 
907  QImage img;
908  if (!haveCachedPixmap) { // If the pixmap is not cached, generate it! -------------------------
909  buffer(w, h); // Ensure a buffer of at least (w, h) in size
910  HDC dc = bufferHDC();
911 
912  // Clear the buffer
913  if (alphaType != NoAlpha) {
914  // Consider have separate "memset" function for small chunks for more speedup
915  memset(bufferPixels, inspectData ? 0xFF : 0x00, bufferW * h * 4);
916  }
917 
918  // Difference between area and rect
919  int dx = area.x() - rect.x();
920  int dy = area.y() - rect.y();
921  int dr = area.right() - rect.right();
922  int db = area.bottom() - rect.bottom();
923 
924  // Adjust so painting rect starts from Origo
925  rect.moveTo(0,0);
926  area.moveTo(dx,dy);
927  DTBGOPTS drawOptions;
928  drawOptions.dwSize = sizeof(drawOptions);
929  drawOptions.rcClip = themeData.toRECT(rect);
930  drawOptions.dwFlags = DTBG_CLIPRECT
931  | (themeData.noBorder ? DTBG_OMITBORDER : 0)
932  | (themeData.noContent ? DTBG_OMITCONTENT : 0);
933 
934  // Drawing the part into the backing store
935  if (pDrawThemeBackgroundEx != 0) {
936  RECT rect(themeData.toRECT(area));
937  pDrawThemeBackgroundEx(themeData.handle(), dc, themeData.partId, themeData.stateId, &rect, &drawOptions);
938  } else {
939  // Set the clip region, if used..
940  if (addBorderContentClipping) {
941  SelectClipRgn(dc, extraClip.handle());
942  // Compensate for the noBorder area difference (noContent has the same area)
943  drawOptions.rcClip = themeData.toRECT(rect.adjusted(dx, dy, dr, db));
944  }
945 
946  pDrawThemeBackground(themeData.handle(), dc, themeData.partId, themeData.stateId, &(drawOptions.rcClip), 0);
947 
948  if (addBorderContentClipping)
949  SelectClipRgn(dc, 0);
950  }
951 
952  // If not cached, analyze the buffer data to figure
953  // out alpha type, and if it contains data
954  if (!isCached) {
955  if (inspectData)
956  stateHasData = hasAnyData(rect);
957  // SHORTCUT: If the part's state has no data, cache it for NOOP later
958  if (!stateHasData) {
959  memset(&data, 0, sizeof(data));
960  data.dataValid = true;
961  alphaCache.insert(key, data);
962  return;
963  }
964  hasAlpha = hasAlphaChannel(rect);
965  if (!hasAlpha && partIsTransparent)
966  potentialInvalidAlpha = true;
967 #if defined(DEBUG_XP_STYLE) && 1
968  dumpNativeDIB(w, h);
969 #endif
970  }
971 
972  // Swap alpha values, if needed
973  if (inspectData)
974  wasAlphaSwapped = swapAlphaChannel(rect);
975 
976  // Fix alpha values, if needed
977  if (potentialInvalidAlpha)
978  wasAlphaFixed = fixAlphaChannel(rect);
979 
981  if ((partIsTransparent && !wasAlphaSwapped) || (!partIsTransparent && hasAlpha)) {
983  alphaType = RealAlpha;
984  } else if (wasAlphaSwapped) {
986  alphaType = MaskAlpha;
987  } else {
988  format = QImage::Format_RGB32;
989  // The image data we got from the theme engine does not have any transparency,
990  // thus the alpha channel is set to 0.
991  // However, Format_RGB32 requires the alpha part to be set to 0xff, thus
992  // we must flip it from 0x00 to 0xff
993  swapAlphaChannel(rect, true);
994  alphaType = NoAlpha;
995  }
996 #if defined(DEBUG_XP_STYLE) && 1
997  printf("Image format is: %s\n", alphaType == RealAlpha ? "Real Alpha" : alphaType == MaskAlpha ? "Masked Alpha" : "No Alpha");
998 #endif
999  img = QImage(bufferPixels, bufferW, bufferH, format);
1000  }
1001 
1002  // Blitting backing store
1003  bool useRegion = partIsTransparent && !hasAlpha && !wasAlphaSwapped;
1004 
1005  QRegion newRegion;
1006  QRegion oldRegion;
1007  if (useRegion) {
1008  newRegion = region(themeData);
1009  oldRegion = painter->clipRegion();
1010  painter->setClipRegion(newRegion);
1011 #if defined(DEBUG_XP_STYLE) && 0
1012  printf("Using region:\n");
1013  QVector<QRect> rects = newRegion.rects();
1014  for (int i = 0; i < rects.count(); ++i) {
1015  const QRect &r = rects.at(i);
1016  printf(" (%d, %d, %d, %d)\n", r.x(), r.y(), r.right(), r.bottom());
1017  }
1018 #endif
1019  }
1020 
1021  if (addBorderContentClipping)
1022  painter->setClipRegion(extraClip, Qt::IntersectClip);
1023 
1024  if (!themeData.mirrorHorizontally && !themeData.mirrorVertically && !themeData.rotate) {
1025  if (!haveCachedPixmap)
1026  painter->drawImage(themeData.rect, img, rect);
1027  else
1028  painter->drawPixmap(themeData.rect, cachedPixmap);
1029  } else {
1030  // This is _slow_!
1031  // Make a copy containing only the necessary data, and mirror
1032  // on all wanted axes. Then draw the copy.
1033  // If cached, the normal pixmap is cached, instead of caching
1034  // all possible orientations for each part and state.
1035  QImage imgCopy;
1036  if (!haveCachedPixmap)
1037  imgCopy = img.copy(rect);
1038  else
1039  imgCopy = cachedPixmap.toImage();
1040 
1041  if (themeData.rotate) {
1042  QMatrix rotMatrix;
1043  rotMatrix.rotate(themeData.rotate);
1044  imgCopy = imgCopy.transformed(rotMatrix);
1045  }
1046  if (themeData.mirrorHorizontally || themeData.mirrorVertically) {
1047  imgCopy = imgCopy.mirrored(themeData.mirrorHorizontally, themeData.mirrorVertically);
1048  }
1049  painter->drawImage(themeData.rect,
1050  imgCopy);
1051  }
1052 
1053  if (useRegion || addBorderContentClipping) {
1054  if (oldRegion.isEmpty())
1055  painter->setClipping(false);
1056  else
1057  painter->setClipRegion(oldRegion);
1058  }
1059 
1060  // Cache the pixmap to avoid expensive swapAlphaChannel() calls
1061  if (!haveCachedPixmap && w && h) {
1062  QPixmap pix = QPixmap::fromImage(img).copy(rect);
1063  QPixmapCache::insert(pixmapCacheKey, pix);
1064 #ifdef DEBUG_XP_STYLE
1065  printf("+++Adding pixmap to cache, size(%d, %d), wasAlphaSwapped(%d), wasAlphaFixed(%d), name(%s)\n",
1066  w, h, wasAlphaSwapped, wasAlphaFixed, qPrintable(pixmapCacheKey));
1067 #endif
1068  }
1069 
1070  // Add to theme part cache
1071  if (!isCached) {
1072  memset(&data, 0, sizeof(data));
1073  data.dataValid = true;
1074  data.partIsTransparent = partIsTransparent;
1075  data.alphaType = alphaType;
1076  data.hasAlphaChannel = hasAlpha;
1077  data.hasAnyData = stateHasData;
1078  data.wasAlphaSwapped = wasAlphaSwapped;
1079  data.hadInvalidAlpha = wasAlphaFixed;
1080  alphaCache.insert(key, data);
1081  }
1082 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
static PtrGetThemeEnumValue pGetThemeEnumValue
HBITMAP buffer(int w=0, int h=0)
Returns a native buffer (DIB section) of at least the size of ( x , y ).
QImage toImage() const
Converts the pixmap to a QImage.
Definition: qpixmap.cpp:542
QPainter * painter
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
Definition: qpixmap.cpp:2197
Format
The following image formats are available in Qt.
Definition: qimage.h:91
QImage copy(const QRect &rect=QRect()) const
Returns a sub-area of the image as a new image.
Definition: qimage.cpp:1410
QRect adjusted(int x1, int y1, int x2, int y2) const
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition: qrect.h:431
#define TMT_BORDERONLY
The QMatrix class specifies 2D transformations of a coordinate system.
Definition: qmatrix.h:61
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
#define DTBG_OMITCONTENT
#define GT_NONE
static PtrGetThemeInt pGetThemeInt
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
bool fixAlphaChannel(const QRect &rect)
When the theme engine paints both a true alpha pixmap and a glyph into our buffer, the glyph might not contain a proper alpha value.
void moveTo(int x, int t)
Moves the rectangle, leaving the top-left corner at the given position (x, y).
Definition: qrect.h:334
static PtrGetThemeColor pGetThemeColor
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
static const WinVersion WindowsVersion
the version of the Windows operating system on which the application is run (Windows only) ...
Definition: qglobal.h:1613
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define TMT_GLYPHTYPE
#define TMT_CAPTIONMARGINS
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
static QPixmap * find(const QString &key)
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
QHash< ThemeMapKey, ThemeMapData > alphaCache
QRegion clipRegion() const
Returns the currently set clip region.
Definition: qpainter.cpp:2562
bool hasAnyData(const QRect &rect)
Returns true if the native doublebuffer contains a pixel which has a non-0xFF alpha value...
QMatrix & rotate(qreal a)
Rotates the coordinate system the given degrees counterclockwise.
Definition: qmatrix.cpp:990
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
Definition: qregion.cpp:4098
bool hasAlphaChannel(const QRect &rect)
Returns true if the native doublebuffer contains pixels with varying alpha value. ...
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
static const char * data(const QByteArray &arr)
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
bool isTransparent(XPThemeData &themeData)
Returns true if the part contains any transparency at all.
QImage transformed(const QMatrix &matrix, Qt::TransformationMode mode=Qt::FastTransformation) const
Returns a copy of the image that is transformed using the given transformation matrix and transformat...
Definition: qimage.cpp:4698
QImage mirrored(bool horizontally=false, bool vertically=true) const
Returns a mirror of the image, mirrored in the horizontal and/or the vertical direction depending on ...
Definition: qimage.cpp:4922
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
#define GT_IMAGEGLYPH
RECT toRECT(const QRect &qr)
#define DTBG_OMITBORDER
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
void setClipRegion(const QRegion &, Qt::ClipOperation op=Qt::ReplaceClip)
Sets the clip region to the given region using the specified clip operation.
Definition: qpainter.cpp:2917
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
AlphaChannelType
QRegion region(XPThemeData &themeData)
void setClipping(bool enable)
Enables clipping if enable is true, or disables clipping if enable is false.
Definition: qpainter.cpp:2517
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
static bool insert(const QString &key, const QPixmap &pixmap)
Inserts a copy of the pixmap pixmap associated with the key into the cache.
int key
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
Definition: qregion.cpp:4412
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
void drawImage(const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)
Definition: qpainter.cpp:5936
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device...
Definition: qpainter.cpp:5619
static PtrDrawThemeBackgroundEx pDrawThemeBackgroundEx
#define TMT_BORDERSIZE
static PtrGetThemeBool pGetThemeBool
#define TMT_TRANSPARENTCOLOR
QPixmap copy(int x, int y, int width, int height) const
Returns a deep copy of the subset of the pixmap that is specified by the rectangle QRect( x...
Definition: qpixmap.h:302
AlphaChannelType alphaType
#define qPrintable(string)
Definition: qglobal.h:1750
static PtrGetThemePropertyOrigin pGetThemePropertyOrigin
bool swapAlphaChannel(const QRect &rect, bool allPixels=false)
Swaps the alpha values on certain pixels: 0xFF?????? -> 0x00?????? 0x00?????? -> 0xFF?????? Used to determin the mask of a non-alpha transparent pixmap in the native doublebuffer, and swap the alphas so we may paint the image as a Premultiplied QImage with drawImage(), and obtain the mask transparency.
static PtrDrawThemeBackground pDrawThemeBackground
Handle handle() const
Returns a platform-specific region handle.
#define DTBG_CLIPRECT
static int area(const QSize &s)
Definition: qicon.cpp:155

◆ fixAlphaChannel()

bool QWindowsXPStylePrivate::fixAlphaChannel ( const QRect rect)

When the theme engine paints both a true alpha pixmap and a glyph into our buffer, the glyph might not contain a proper alpha value.

Warning
This function is not part of the public interface.

The rule of thumb for premultiplied pixmaps is that the color values of a pixel can never be higher than the alpha values, so we use this to our advantage here, and fix all instances where this occures.

Definition at line 585 of file qwindowsxpstyle.cpp.

586 {
587  const int startX = rect.left();
588  const int startY = rect.top();
589  const int w = rect.width();
590  const int h = rect.height();
591  bool hasFixedAlphaValue = false;
592 
593  for (int y = startY; y < h; ++y) {
594  register DWORD *buffer = (DWORD*)bufferPixels + (y * bufferW);
595  for (register int x = startX; x < w; ++x, ++buffer) {
596  uint pixel = *buffer;
597  int alpha = qAlpha(pixel);
598  if (qRed(pixel) > alpha || qGreen(pixel) > alpha || qBlue(pixel) > alpha) {
599  *buffer |= 0xff000000;
600  hasFixedAlphaValue = true;
601  }
602  }
603  }
604  return hasFixedAlphaValue;
605 }
HBITMAP buffer(int w=0, int h=0)
Returns a native buffer (DIB section) of at least the size of ( x , y ).
Q_GUI_EXPORT_INLINE int qAlpha(QRgb rgb)
Definition: qrgb.h:66
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
Q_GUI_EXPORT_INLINE int qRed(QRgb rgb)
Definition: qrgb.h:57
unsigned int uint
Definition: qglobal.h:996
Q_GUI_EXPORT_INLINE int qBlue(QRgb rgb)
Definition: qrgb.h:63
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
Q_GUI_EXPORT_INLINE int qGreen(QRgb rgb)
Definition: qrgb.h:60

◆ hasAlphaChannel()

bool QWindowsXPStylePrivate::hasAlphaChannel ( const QRect rect)

Returns true if the native doublebuffer contains pixels with varying alpha value.

Warning
This function is not part of the public interface.

Definition at line 553 of file qwindowsxpstyle.cpp.

554 {
555  const int startX = rect.left();
556  const int startY = rect.top();
557  const int w = rect.width();
558  const int h = rect.height();
559 
560  int firstAlpha = -1;
561  for (int y = startY; y < h/2; ++y) {
562  register DWORD *buffer = (DWORD*)bufferPixels + (y * bufferW);
563  for (int x = startX; x < w; ++x, ++buffer) {
564  int alpha = (*buffer) >> 24;
565  if (firstAlpha == -1)
566  firstAlpha = alpha;
567  else if (alpha != firstAlpha)
568  return true;
569  }
570  }
571  return false;
572 }
HBITMAP buffer(int w=0, int h=0)
Returns a native buffer (DIB section) of at least the size of ( x , y ).
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243

◆ hasAnyData()

bool QWindowsXPStylePrivate::hasAnyData ( const QRect rect)

Returns true if the native doublebuffer contains a pixel which has a non-0xFF alpha value.

Warning
This function is not part of the public interface. Should only be use when its guaranteed that data painted into the buffer wasn't a proper alpha pixmap.

Definition at line 528 of file qwindowsxpstyle.cpp.

529 {
530  const int startX = rect.left();
531  const int startY = rect.top();
532  const int w = rect.width();
533  const int h = rect.height();
534 
535  for (int y = startY; y < h; ++y) {
536  register DWORD *buffer = (DWORD*)bufferPixels + (y * bufferW);
537  for (int x = startX; x < w; ++x, ++buffer) {
538  int alpha = (*buffer) >> 24;
539  if (alpha != 0xFF) // buffer has been touched
540  return true;
541  }
542  }
543  return false;
544 }
HBITMAP buffer(int w=0, int h=0)
Returns a native buffer (DIB section) of at least the size of ( x , y ).
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243

◆ init()

void QWindowsXPStylePrivate::init ( bool  force = false)

Definition at line 229 of file qwindowsxpstyle.cpp.

230 {
231  if (ref.ref() && !force)
232  return;
233  if (!force) // -1 based atomic refcounting
234  ref.ref();
235 
236  useXP(true);
237 }
static QBasicAtomicInt ref
static bool useXP(bool update=false)

◆ isItemViewDelegateLineEdit()

bool QWindowsXPStylePrivate::isItemViewDelegateLineEdit ( const QWidget widget)
static

Definition at line 290 of file qwindowsxpstyle.cpp.

Referenced by QWindowsVistaStyle::drawPrimitive(), and QWindowsXPStyle::drawPrimitive().

291 {
292  if (!widget)
293  return false;
294  const QWidget *parent1 = widget->parentWidget();
295  // Exlude dialogs or other toplevels parented on item views.
296  if (!parent1 || parent1->isWindow())
297  return false;
298  const QWidget *parent2 = parent1->parentWidget();
299  return parent2 && widget->inherits("QLineEdit")
300  && parent2->inherits("QAbstractItemView");
301 }
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition: qwidget.h:945
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
bool inherits(const char *classname) const
Returns true if this object is an instance of a class that inherits className or a QObject subclass t...
Definition: qobject.h:275

◆ isTransparent()

bool QWindowsXPStylePrivate::isTransparent ( XPThemeData themeData)

Returns true if the part contains any transparency at all.

Warning
This function is not part of the public interface. This does not indicate what kind of transparency we're dealing with. It can be
  • Alpha transparency
  • Masked transparency

Definition at line 474 of file qwindowsxpstyle.cpp.

475 {
476  return pIsThemeBackgroundPartiallyTransparent(themeData.handle(), themeData.partId,
477  themeData.stateId);
478 }
static PtrIsThemeBackgroundPartiallyTransparent pIsThemeBackgroundPartiallyTransparent

◆ region()

QRegion QWindowsXPStylePrivate::region ( XPThemeData themeData)
Warning
This function is not part of the public interface. Returns a QRegion of the region of the part

Definition at line 484 of file qwindowsxpstyle.cpp.

Referenced by QWindowsVistaStyle::drawComplexControl(), QWindowsXPStyle::drawComplexControl(), QWindowsVistaStyle::styleHint(), and QWindowsXPStyle::styleHint().

485 {
486  HRGN hRgn = 0;
487  RECT rect = themeData.toRECT(themeData.rect);
488  if (!SUCCEEDED(pGetThemeBackgroundRegion(themeData.handle(), bufferHDC(), themeData.partId,
489  themeData.stateId, &rect, &hRgn)))
490  return QRegion();
491 
492  HRGN dest = CreateRectRgn(0, 0, 0, 0);
493  const bool success = CombineRgn(dest, hRgn, 0, RGN_COPY) != ERROR;
494 
495  QRegion region;
496 
497  if (success)
498  region = qt_region_from_HRGN(dest);
499 
500  DeleteObject(hRgn);
501  DeleteObject(dest);
502 
503  return region;
504 }
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
RECT toRECT(const QRect &qr)
QRegion region(XPThemeData &themeData)
static PtrGetThemeBackgroundRegion pGetThemeBackgroundRegion
QRegion qt_region_from_HRGN(HRGN rgn)
Definition: qregion_win.cpp:80

◆ resolveSymbols()

bool QWindowsXPStylePrivate::resolveSymbols ( )
static

Returns true if all the necessary theme engine symbols were resolved.

Warning
This function is not part of the public interface.

Definition at line 364 of file qwindowsxpstyle.cpp.

365 {
366  static bool tried = false;
367  if (!tried) {
368  QSystemLibrary themeLib(QLatin1String("uxtheme"));
369  pIsAppThemed = (PtrIsAppThemed)themeLib.resolve("IsAppThemed");
370  if (pIsAppThemed) {
371  pIsThemeActive = (PtrIsThemeActive )themeLib.resolve("IsThemeActive");
372  pGetThemePartSize = (PtrGetThemePartSize )themeLib.resolve("GetThemePartSize");
373  pOpenThemeData = (PtrOpenThemeData )themeLib.resolve("OpenThemeData");
374  pCloseThemeData = (PtrCloseThemeData )themeLib.resolve("CloseThemeData");
375  pDrawThemeBackground = (PtrDrawThemeBackground )themeLib.resolve("DrawThemeBackground");
376  pDrawThemeBackgroundEx = (PtrDrawThemeBackgroundEx )themeLib.resolve("DrawThemeBackgroundEx");
377  pGetCurrentThemeName = (PtrGetCurrentThemeName )themeLib.resolve("GetCurrentThemeName");
378  pGetThemeBool = (PtrGetThemeBool )themeLib.resolve("GetThemeBool");
379  pGetThemeColor = (PtrGetThemeColor )themeLib.resolve("GetThemeColor");
380  pGetThemeEnumValue = (PtrGetThemeEnumValue )themeLib.resolve("GetThemeEnumValue");
381  pGetThemeFilename = (PtrGetThemeFilename )themeLib.resolve("GetThemeFilename");
382  pGetThemeFont = (PtrGetThemeFont )themeLib.resolve("GetThemeFont");
383  pGetThemeInt = (PtrGetThemeInt )themeLib.resolve("GetThemeInt");
384  pGetThemeIntList = (PtrGetThemeIntList )themeLib.resolve("GetThemeIntList");
385  pGetThemeMargins = (PtrGetThemeMargins )themeLib.resolve("GetThemeMargins");
386  pGetThemeMetric = (PtrGetThemeMetric )themeLib.resolve("GetThemeMetric");
387  pGetThemePartSize = (PtrGetThemePartSize )themeLib.resolve("GetThemePartSize");
388  pGetThemePosition = (PtrGetThemePosition )themeLib.resolve("GetThemePosition");
389  pGetThemePropertyOrigin = (PtrGetThemePropertyOrigin)themeLib.resolve("GetThemePropertyOrigin");
390  pGetThemeRect = (PtrGetThemeRect )themeLib.resolve("GetThemeRect");
391  pGetThemeString = (PtrGetThemeString )themeLib.resolve("GetThemeString");
392  pGetThemeBackgroundRegion = (PtrGetThemeBackgroundRegion )themeLib.resolve("GetThemeBackgroundRegion");
393  pGetThemeDocumentationProperty = (PtrGetThemeDocumentationProperty )themeLib.resolve("GetThemeDocumentationProperty");
394  pIsThemeBackgroundPartiallyTransparent = (PtrIsThemeBackgroundPartiallyTransparent)themeLib.resolve("IsThemeBackgroundPartiallyTransparent");
395  }
396  tried = true;
397  }
398 
399  return pIsAppThemed != 0;
400 }
HRESULT(WINAPI * PtrGetThemePosition)(HTHEME hTheme, int iPartId, int iStateId, int iPropId, OUT POINT *pPoint)
static PtrGetThemeEnumValue pGetThemeEnumValue
HRESULT(WINAPI * PtrGetThemeRect)(HTHEME hTheme, int iPartId, int iStateId, int iPropId, OUT RECT *pRect)
HRESULT(WINAPI * PtrGetThemeColor)(HTHEME hTheme, int iPartId, int iStateId, int iPropId, OUT COLORREF *pColor)
static PtrGetThemeRect pGetThemeRect
HTHEME(WINAPI * PtrOpenThemeData)(HWND hwnd, LPCWSTR pszClassList)
HRESULT(WINAPI * PtrGetThemePropertyOrigin)(HTHEME hTheme, int iPartId, int iStateId, int iPropId, OUT enum PROPERTYORIGIN *pOrigin)
static PtrIsAppThemed pIsAppThemed
HRESULT(WINAPI * PtrGetThemeIntList)(HTHEME hTheme, int iPartId, int iStateId, int iPropId, OUT INTLIST *pIntList)
static PtrGetThemeInt pGetThemeInt
HRESULT(WINAPI * PtrGetThemeMargins)(HTHEME hTheme, OPTIONAL HDC hdc, int iPartId, int iStateId, int iPropId, OPTIONAL RECT *prc, OUT MARGINS *pMargins)
HRESULT(WINAPI * PtrDrawThemeBackgroundEx)(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pRect, OPTIONAL const DTBGOPTS *pOptions)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static PtrGetThemeColor pGetThemeColor
HRESULT(WINAPI * PtrGetThemeMetric)(HTHEME hTheme, OPTIONAL HDC hdc, int iPartId, int iStateId, int iPropId, OUT int *piVal)
static PtrGetCurrentThemeName pGetCurrentThemeName
HRESULT(WINAPI * PtrGetThemeBool)(HTHEME hTheme, int iPartId, int iStateId, int iPropId, OUT BOOL *pfVal)
HRESULT(WINAPI * PtrGetThemeDocumentationProperty)(LPCWSTR pszThemeName, LPCWSTR pszPropertyName, OUT LPWSTR pszValueBuff, int cchMaxValChars)
HRESULT(WINAPI * PtrGetThemeInt)(HTHEME hTheme, int iPartId, int iStateId, int iPropId, OUT int *piVal)
HRESULT(WINAPI * PtrDrawThemeBackground)(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pRect, OPTIONAL const RECT *pClipRect)
HRESULT(WINAPI * PtrGetThemeString)(HTHEME hTheme, int iPartId, int iStateId, int iPropId, OUT LPWSTR pszBuff, int cchMaxBuffChars)
HRESULT(WINAPI * PtrGetThemeBackgroundRegion)(HTHEME hTheme, OPTIONAL HDC hdc, int iPartId, int iStateId, const RECT *pRect, OUT HRGN *pRegion)
static PtrGetThemePartSize pGetThemePartSize
static PtrGetThemeString pGetThemeString
HRESULT(WINAPI * PtrCloseThemeData)(HTHEME hTheme)
static PtrGetThemeIntList pGetThemeIntList
static PtrGetThemePosition pGetThemePosition
static PtrOpenThemeData pOpenThemeData
static PtrGetThemeMargins pGetThemeMargins
bool(WINAPI * PtrIsAppThemed)()
static PtrIsThemeActive pIsThemeActive
HRESULT(WINAPI * PtrGetThemePartSize)(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, OPTIONAL RECT *prc, enum THEMESIZE eSize, OUT SIZE *psz)
static PtrGetThemeDocumentationProperty pGetThemeDocumentationProperty
HRESULT(WINAPI * PtrGetCurrentThemeName)(OUT LPWSTR pszThemeFileName, int cchMaxNameChars, OUT OPTIONAL LPWSTR pszColorBuff, int cchMaxColorChars, OUT OPTIONAL LPWSTR pszSizeBuff, int cchMaxSizeChars)
HRESULT(WINAPI * PtrGetThemeEnumValue)(HTHEME hTheme, int iPartId, int iStateId, int iPropId, OUT int *piVal)
static PtrIsThemeBackgroundPartiallyTransparent pIsThemeBackgroundPartiallyTransparent
static PtrGetThemeFilename pGetThemeFilename
static PtrGetThemeMetric pGetThemeMetric
BOOL(WINAPI * PtrIsThemeBackgroundPartiallyTransparent)(HTHEME hTheme, int iPartId, int iStateId)
HRESULT(WINAPI * PtrGetThemeFont)(HTHEME hTheme, OPTIONAL HDC hdc, int iPartId, int iStateId, int iPropId, OUT LOGFONT *pFont)
static PtrCloseThemeData pCloseThemeData
static PtrGetThemeFont pGetThemeFont
HRESULT(WINAPI * PtrGetThemeFilename)(HTHEME hTheme, int iPartId, int iStateId, int iPropId, OUT LPWSTR pszThemeFileName, int cchMaxBuffChars)
static PtrDrawThemeBackgroundEx pDrawThemeBackgroundEx
static PtrGetThemeBackgroundRegion pGetThemeBackgroundRegion
static PtrGetThemeBool pGetThemeBool
bool(WINAPI * PtrIsThemeActive)()
static PtrGetThemePropertyOrigin pGetThemePropertyOrigin
static PtrDrawThemeBackground pDrawThemeBackground

◆ setTransparency()

void QWindowsXPStylePrivate::setTransparency ( QWidget widget,
XPThemeData themeData 
)

Sets the parts region on a window.

Warning
This function is not part of the public interface.

Definition at line 512 of file qwindowsxpstyle.cpp.

513 {
514  HRGN hrgn = themeData.mask();
515  if (hrgn && widget)
516  SetWindowRgn(winId(widget), hrgn, true);
517 }
static HWND winId(const QWidget *widget)
This function will always return a valid window handle, and might create a limbo widget to do so...

◆ swapAlphaChannel()

bool QWindowsXPStylePrivate::swapAlphaChannel ( const QRect rect,
bool  allPixels = false 
)

Swaps the alpha values on certain pixels: 0xFF?????? -> 0x00?????? 0x00?????? -> 0xFF?????? Used to determin the mask of a non-alpha transparent pixmap in the native doublebuffer, and swap the alphas so we may paint the image as a Premultiplied QImage with drawImage(), and obtain the mask transparency.

Warning
This function is not part of the public interface.

Definition at line 619 of file qwindowsxpstyle.cpp.

620 {
621  const int startX = rect.left();
622  const int startY = rect.top();
623  const int w = rect.width();
624  const int h = rect.height();
625  bool valueChange = false;
626 
627  // Flip the alphas, so that 255-alpha pixels are 0, and 0-alpha are 255.
628  for (int y = startY; y < h; ++y) {
629  register DWORD *buffer = (DWORD*)bufferPixels + (y * bufferW);
630  for (register int x = startX; x < w; ++x, ++buffer) {
631  if (allPixels) {
632  *buffer |= 0xFF000000;
633  continue;
634  }
635  register unsigned int alphaValue = (*buffer) & 0xFF000000;
636  if (alphaValue == 0xFF000000) {
637  *buffer = 0;
638  valueChange = true;
639  } else if (alphaValue == 0) {
640  *buffer |= 0xFF000000;
641  valueChange = true;
642  }
643  }
644  }
645  return valueChange;
646 }
HBITMAP buffer(int w=0, int h=0)
Returns a native buffer (DIB section) of at least the size of ( x , y ).
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243

◆ tabBody()

const QPixmap * QWindowsXPStylePrivate::tabBody ( QWidget widget)

Returns the pointer to a tab widgets body pixmap, scaled to the height of the screen.

Warning
This function is not part of the public interface. This way the theme engine doesn't need to scale the body for every time we ask for it. (Speed optimization)

Definition at line 337 of file qwindowsxpstyle.cpp.

338 {
339  if (!tabbody) {
340  SIZE sz;
341  XPThemeData theme(0, 0, QLatin1String("TAB"), TABP_BODY);
342  pGetThemePartSize(theme.handle(), qt_win_display_dc(), TABP_BODY, 0, 0, TS_TRUE, &sz);
343 
345  QPainter painter(tabbody);
346  theme.rect = QRect(0, 0, sz.cx, sz.cy);
347  drawBackground(theme);
348  // We fill with the last line of the themedata, that
349  // way we don't get a tiled pixmap inside big tabs
350  QPixmap temp(sz.cx, 1);
351  painter.drawPixmap(0, 0, temp, 0, sz.cy-1, -1, -1);
352  painter.drawTiledPixmap(0, sz.cy, sz.cx, tabbody->height()-sz.cy, temp);
353  }
354  return tabbody;
355 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
static QPixmap * tabbody
Q_GUI_EXPORT HDC qt_win_display_dc()
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void drawBackground(XPThemeData &themeData)
Main theme drawing function.
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
#define SIZE(large, small, mini)
static PtrGetThemePartSize pGetThemePartSize
static QDesktopWidget * desktop()
Returns the desktop widget (also called the root window).
const QRect screenGeometry(int screen=-1) const
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71

◆ useXP()

bool QWindowsXPStylePrivate::useXP ( bool  update = false)
static

◆ winId()

HWND QWindowsXPStylePrivate::winId ( const QWidget widget)
static

This function will always return a valid window handle, and might create a limbo widget to do so.

Warning
This function is not part of the public interface.

We often need a window handle to for example open theme data, so this function ensures that we get one.

Definition at line 312 of file qwindowsxpstyle.cpp.

Referenced by XPThemeData::handle(), QWindowsVistaStyle::polish(), and QWindowsVistaStyle::subElementRect().

313 {
314  if (widget && widget->internalWinId())
315  return widget->internalWinId();
316 
317  if (!limboWidget) {
318  limboWidget = new QWidget(0);
320  limboWidget->setObjectName(QLatin1String("xp_limbo_widget"));
321  // We don't need this internal widget to appear in QApplication::topLevelWidgets()
324  }
325 
326  return limboWidget->winId();
327 }
bool remove(const T &value)
Definition: qset.h:89
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setObjectName(const QString &name)
Definition: qobject.cpp:1112
static QWidgetSet * allWidgets
Definition: qwidget_p.h:715
static QWidget * limboWidget
WId internalWinId() const
Returns the window system identifier of the widget, or 0 if the widget is not created yet...
Definition: qwidget.h:244
void createWinId()
Definition: qwidget.cpp:2626
WId winId() const
Returns the window system identifier of the widget.
Definition: qwidget.cpp:2557

Properties

◆ alphaCache

QHash<ThemeMapKey, ThemeMapData> QWindowsXPStylePrivate::alphaCache
private

Definition at line 346 of file qwindowsxpstyle_p.h.

◆ bufferBitmap

HBITMAP QWindowsXPStylePrivate::bufferBitmap
private

Definition at line 348 of file qwindowsxpstyle_p.h.

◆ bufferDC

HDC QWindowsXPStylePrivate::bufferDC
private

Definition at line 347 of file qwindowsxpstyle_p.h.

◆ bufferH

int QWindowsXPStylePrivate::bufferH
private

Definition at line 351 of file qwindowsxpstyle_p.h.

◆ bufferPixels

uchar* QWindowsXPStylePrivate::bufferPixels
private

Definition at line 350 of file qwindowsxpstyle_p.h.

◆ bufferW

int QWindowsXPStylePrivate::bufferW
private

Definition at line 351 of file qwindowsxpstyle_p.h.

◆ dockClose

QIcon QWindowsXPStylePrivate::dockClose

Definition at line 333 of file qwindowsxpstyle_p.h.

Referenced by QWindowsXPStyle::standardIconImplementation().

◆ dockFloat

QIcon QWindowsXPStylePrivate::dockFloat

Definition at line 333 of file qwindowsxpstyle_p.h.

Referenced by QWindowsXPStyle::standardIconImplementation().

◆ groupBoxTextColor

QRgb QWindowsXPStylePrivate::groupBoxTextColor

Definition at line 326 of file qwindowsxpstyle_p.h.

Referenced by QWindowsXPStyle::styleHint().

◆ groupBoxTextColorDisabled

QRgb QWindowsXPStylePrivate::groupBoxTextColorDisabled

Definition at line 327 of file qwindowsxpstyle_p.h.

Referenced by QWindowsXPStyle::styleHint().

◆ handleMap

QMap< QString, HTHEME > * QWindowsXPStylePrivate::handleMap = 0
static

Definition at line 331 of file qwindowsxpstyle_p.h.

Referenced by XPThemeData::handle(), and XPThemeData::mask().

◆ hasInitColors

bool QWindowsXPStylePrivate::hasInitColors

Definition at line 329 of file qwindowsxpstyle_p.h.

◆ limboWidget

QWidget * QWindowsXPStylePrivate::limboWidget = 0
staticprivate

Definition at line 343 of file qwindowsxpstyle_p.h.

Referenced by XPThemeData::mask().

◆ nullBitmap

HBITMAP QWindowsXPStylePrivate::nullBitmap
private

Definition at line 349 of file qwindowsxpstyle_p.h.

◆ ref

QBasicAtomicInt QWindowsXPStylePrivate::ref = Q_BASIC_ATOMIC_INITIALIZER(-1)
staticprivate

Definition at line 341 of file qwindowsxpstyle_p.h.

Referenced by XPThemeData::mask().

◆ sliderTickColor

QRgb QWindowsXPStylePrivate::sliderTickColor

Definition at line 328 of file qwindowsxpstyle_p.h.

Referenced by QWindowsXPStyle::drawComplexControl().

◆ tabbody

QPixmap * QWindowsXPStylePrivate::tabbody = 0
staticprivate

Definition at line 344 of file qwindowsxpstyle_p.h.

Referenced by XPThemeData::mask().

◆ use_xp

bool QWindowsXPStylePrivate::use_xp = false
staticprivate

Definition at line 342 of file qwindowsxpstyle_p.h.

Referenced by XPThemeData::mask().


The documentation for this class was generated from the following files: