1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
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 The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 
43 #ifndef QMACSTYLE_MAC_P_H
44 #define QMACSTYLE_MAC_P_H
45 
46 #include <qmacstyle_mac.h>
47 #include <private/qapplication_p.h>
48 #include <private/qcombobox_p.h>
49 #include <private/qmacstylepixmaps_mac_p.h>
50 #include <private/qpaintengine_mac_p.h>
51 #include <private/qpainter_p.h>
52 #include <private/qprintengine_mac_p.h>
53 #include <private/qstylehelper_p.h>
54 #include <qapplication.h>
55 #include <qbitmap.h>
56 #include <qcheckbox.h>
57 #include <qcombobox.h>
58 #include <qdialogbuttonbox.h>
59 #include <qdockwidget.h>
60 #include <qevent.h>
61 #include <qfocusframe.h>
62 #include <qformlayout.h>
63 #include <qgroupbox.h>
64 #include <qhash.h>
65 #include <qheaderview.h>
66 #include <qlayout.h>
67 #include <qlineedit.h>
68 #include <qlistview.h>
69 #include <qmainwindow.h>
70 #include <qmap.h>
71 #include <qmenubar.h>
72 #include <qpaintdevice.h>
73 #include <qpainter.h>
74 #include <qpixmapcache.h>
75 #include <qpointer.h>
76 #include <qprogressbar.h>
77 #include <qpushbutton.h>
78 #include <qradiobutton.h>
79 #include <qrubberband.h>
80 #include <qsizegrip.h>
81 #include <qspinbox.h>
82 #include <qsplitter.h>
83 #include <qstyleoption.h>
84 #include <qtextedit.h>
85 #include <qtextstream.h>
86 #include <qtoolbar.h>
87 #include <qtoolbutton.h>
88 #include <qtreeview.h>
89 #include <qtableview.h>
90 #include <qwizard.h>
91 #include <qdebug.h>
92 #include <qlibrary.h>
93 #include <qdatetimeedit.h>
94 #include <qmath.h>
95 #include <QtGui/qgraphicsproxywidget.h>
96 #include <QtGui/qgraphicsview.h>
97 #include <private/qt_cocoa_helpers_mac_p.h>
98 
99 //
100 //  W A R N I N G
101 //  -------------
102 //
103 // This file is not part of the Qt API.  It exists purely as an
104 // implementation detail.  This header file may change from version to
105 // version without notice, or even be removed.
106 //
107 // We mean it.
108 //
109 
110 QT_BEGIN_NAMESPACE
111 
112 #if (MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5)
113 enum {
114     kThemePushButtonTextured = 31,
115     kThemePushButtonTexturedSmall = 32,
116     kThemePushButtonTexturedMini = 33
117 };
118 
119 /* Search fields */
120 enum {
121     kHIThemeFrameTextFieldRound = 1000,
122     kHIThemeFrameTextFieldRoundSmall = 1001,
123     kHIThemeFrameTextFieldRoundMini = 1002
124 };
125 #endif
126 
127 /*
128     AHIG:
129         Apple Human Interface Guidelines
130         http://developer.apple.com/documentation/UserExperience/Conceptual/OSXHIGuidelines/
131 
132     Builder:
133         Apple Interface Builder v. 3.1.1
134 */
135 
136 // this works as long as we have at most 16 different control types
137 #define CT1(c) CT2(c, c)
138 #define CT2(c1, c2) ((uint(c1) << 16) | uint(c2))
139 
140 enum QAquaWidgetSize { QAquaSizeLarge = 0, QAquaSizeSmall = 1, QAquaSizeMini = 2,
141                        QAquaSizeUnknown = -1 };
142 
143 #define SIZE(large, small, mini) \
144     (controlSize == QAquaSizeLarge ? (large) : controlSize == QAquaSizeSmall ? (small) : (mini))
145 
146 // same as return SIZE(...) but optimized
147 #define return_SIZE(large, small, mini) \
148     do { \
149         static const int sizes[] = { (large), (small), (mini) }; \
150         return sizes[controlSize]; \
151     } while (0)
152 
153 bool qt_mac_buttonIsRenderedFlat(const QPushButton *pushButton, const QStyleOptionButton *option);
154 
155 class QMacStylePrivate : public QObject
156 {
157     Q_OBJECT
158 
159 public:
160     QMacStylePrivate(QMacStyle *style);
161 
162     // Ideally these wouldn't exist, but since they already exist we need some accessors.
163     static const int PushButtonLeftOffset;
164     static const int PushButtonTopOffset;
165     static const int PushButtonRightOffset;
166     static const int PushButtonBottomOffset;
167     static const int MiniButtonH;
168     static const int SmallButtonH;
169     static const int BevelButtonW;
170     static const int BevelButtonH;
171     static const int PushButtonContentPadding;
172 
173 
174     // Stuff from QAquaAnimate:
175     bool addWidget(QWidget *);
176     void removeWidget(QWidget *);
177 
178     enum Animates { AquaPushButton, AquaProgressBar, AquaListViewItemOpen };
179     bool animatable(Animates, const QWidget *) const;
180     void stopAnimate(Animates, QWidget *);
181     void startAnimate(Animates, QWidget *);
182     static ThemeDrawState getDrawState(QStyle::State flags);
183     QAquaWidgetSize aquaSizeConstrain(const QStyleOption *option, const QWidget *widg,
184                              QStyle::ContentsType ct = QStyle::CT_CustomBase,
185                              QSize szHint=QSize(-1, -1), QSize *insz = 0) const;
186     void getSliderInfo(QStyle::ComplexControl cc, const QStyleOptionSlider *slider,
187                           HIThemeTrackDrawInfo *tdi, const QWidget *needToRemoveMe);
188     bool doAnimate(Animates);
animateSpeed(Animates)189     inline int animateSpeed(Animates) const { return 33; }
190 
191     // Utility functions
192     void drawColorlessButton(const HIRect &macRect, HIThemeButtonDrawInfo *bdi,
193                              QPainter *p, const QStyleOption *opt) const;
194 
195     QSize pushButtonSizeFromContents(const QStyleOptionButton *btn) const;
196 
197     HIRect pushButtonContentBounds(const QStyleOptionButton *btn,
198                                    const HIThemeButtonDrawInfo *bdi) const;
199 
200     void initComboboxBdi(const QStyleOptionComboBox *combo, HIThemeButtonDrawInfo *bdi,
201                         const QWidget *widget, const ThemeDrawState &tds);
202 
203     static HIRect comboboxInnerBounds(const HIRect &outerBounds, int buttonKind);
204 
205     static QRect comboboxEditBounds(const QRect &outerBounds, const HIThemeButtonDrawInfo &bdi);
206 
207     static void drawCombobox(const HIRect &outerBounds, const HIThemeButtonDrawInfo &bdi, QPainter *p);
208     static void drawTableHeader(const HIRect &outerBounds, bool drawTopBorder, bool drawLeftBorder,
209                                      const HIThemeButtonDrawInfo &bdi, QPainter *p);
210     bool contentFitsInPushButton(const QStyleOptionButton *btn, HIThemeButtonDrawInfo *bdi,
211                                  ThemeButtonKind buttonKindToCheck) const;
212     void initHIThemePushButton(const QStyleOptionButton *btn, const QWidget *widget,
213                                const ThemeDrawState tds,
214                                HIThemeButtonDrawInfo *bdi) const;
215     QPixmap generateBackgroundPattern() const;
216 protected:
217     bool eventFilter(QObject *, QEvent *);
218     void timerEvent(QTimerEvent *);
219 
220 private slots:
221     void startAnimationTimer();
222 
223 public:
224     QPointer<QPushButton> defaultButton; //default push buttons
225     int timerID;
226     QList<QPointer<QWidget> > progressBars; //existing progress bars that need animation
227 
228     struct ButtonState {
229         int frame;
230         enum { ButtonDark, ButtonLight } dir;
231     } buttonState;
232     UInt8 progressFrame;
233     QPointer<QFocusFrame> focusWidget;
234     CFAbsoluteTime defaultButtonStart;
235     QMacStyle *q;
236     bool mouseDown;
237 };
238 
239 QT_END_NAMESPACE
240 
241 #endif // QMACSTYLE_MAC_P_H
242