1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtGui module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include <private/qt_mac_p.h>
43 #include <private/qpixmap_mac_p.h>
44 #include <private/qnativeimage_p.h>
48 static CTFontRef CopyCTThemeFont(ThemeFontID themeID)
50 CTFontUIFontType ctID = HIThemeGetUIFontType(themeID);
51 return CTFontCreateUIFontForLanguage(ctID, 0, 0);
54 QFont qfontForThemeFont(ThemeFontID themeID)
56 QCFType<CTFontRef> ctfont = CopyCTThemeFont(themeID);
57 QString familyName = QCFString(CTFontCopyFamilyName(ctfont));
58 QCFType<CFDictionaryRef> dict = CTFontCopyTraits(ctfont);
59 CFNumberRef num = static_cast<CFNumberRef>(CFDictionaryGetValue(dict, kCTFontWeightTrait));
61 CFNumberGetValue(num, kCFNumberFloat32Type, &fW);
62 QFont::Weight wght = fW > 0. ? QFont::Bold : QFont::Normal;
63 num = static_cast<CFNumberRef>(CFDictionaryGetValue(dict, kCTFontSlantTrait));
64 CFNumberGetValue(num, kCFNumberFloatType, &fW);
65 bool italic = (fW != 0.0);
66 return QFont(familyName, CTFontGetSize(ctfont), wght, italic);
69 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
71 static inline QColor leopardBrush(ThemeBrush brush)
73 QCFType<CGColorRef> cgClr = 0;
74 HIThemeBrushCreateCGColor(brush, &cgClr);
75 return qcolorFromCGColor(cgClr);
79 QColor qcolorForTheme(ThemeBrush brush)
81 return leopardBrush(brush);
84 QColor qcolorForThemeTextColor(ThemeTextColor themeColor)
88 GetThemeTextColor(themeColor, 32, true, &c);
89 QColor color = QColor(c.red / 256, c.green / 256, c.blue / 256);
92 // There is no equivalent to GetThemeTextColor in 64-bit and it was rather bad that
93 // I didn't file a request to implement this for Snow Leopard. So, in the meantime
94 // I've encoded the values from the GetThemeTextColor. This is not exactly ideal
95 // as if someone really wants to mess with themeing, these colors will be wrong.
96 // It also means that we need to make sure the values for differences between
97 // OS releases (and it will be likely that we are a step behind.)
99 case kThemeTextColorAlertActive:
100 case kThemeTextColorTabFrontActive:
101 case kThemeTextColorBevelButtonActive:
102 case kThemeTextColorListView:
103 case kThemeTextColorPlacardActive:
104 case kThemeTextColorPopupButtonActive:
105 case kThemeTextColorPopupLabelActive:
106 case kThemeTextColorPushButtonActive:
108 case kThemeTextColorAlertInactive:
109 case kThemeTextColorDialogInactive:
110 case kThemeTextColorPlacardInactive:
111 return QColor(69, 69, 69, 255);
112 case kThemeTextColorPopupButtonInactive:
113 case kThemeTextColorPopupLabelInactive:
114 case kThemeTextColorPushButtonInactive:
115 case kThemeTextColorTabFrontInactive:
116 case kThemeTextColorBevelButtonInactive:
117 return QColor(127, 127, 127, 255);
119 QNativeImage nativeImage(16,16, QNativeImage::systemFormat());
120 CGRect cgrect = CGRectMake(0, 0, 16, 16);
121 HIThemeSetTextFill(themeColor, 0, nativeImage.cg, kHIThemeOrientationNormal);
122 CGContextFillRect(nativeImage.cg, cgrect);
123 QColor color = nativeImage.image.pixel(0,0);
124 return QColor(nativeImage.image.pixel(0 , 0));