File indexing completed on 2024-04-28 13:42:22

0001 /*****************************************************************************
0002  *   Copyright 2003 - 2010 Craig Drummond <craig.p.drummond@gmail.com>       *
0003  *   Copyright 2013 - 2015 Yichao Yu <yyc1992@gmail.com>                     *
0004  *                                                                           *
0005  *   This program is free software; you can redistribute it and/or modify    *
0006  *   it under the terms of the GNU Lesser General Public License as          *
0007  *   published by the Free Software Foundation; either version 2.1 of the    *
0008  *   License, or (at your option) version 3, or any later version accepted   *
0009  *   by the membership of KDE e.V. (or its successor approved by the         *
0010  *   membership of KDE e.V.), which shall act as a proxy defined in          *
0011  *   Section 6 of version 3 of the license.                                  *
0012  *                                                                           *
0013  *   This program is distributed in the hope that it will be useful,         *
0014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
0015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       *
0016  *   Lesser General Public License for more details.                         *
0017  *                                                                           *
0018  *   You should have received a copy of the GNU Lesser General Public        *
0019  *   License along with this library. If not,                                *
0020  *   see <http://www.gnu.org/licenses/>.                                     *
0021  *****************************************************************************/
0022 
0023 #ifndef __QTC_HELPERS_H__
0024 #define __QTC_HELPERS_H__
0025 
0026 #include "config.h"
0027 #include "qt_settings.h"
0028 #include <common/common.h>
0029 #include <qtcurve-cairo/utils.h>
0030 
0031 namespace QtCurve {
0032 
0033 #ifndef GTK_IS_COMBO_BOX_ENTRY
0034 #define GTK_IS_COMBO_BOX_ENTRY(x) 0
0035 #endif
0036 #ifndef GTK_IS_COMBO_BOX
0037 #define GTK_IS_COMBO_BOX(x) 0
0038 #endif
0039 
0040 #if GTK_CHECK_VERSION(2, 90, 0)
0041 #  define QTC_IS_COMBO(X) GTK_IS_COMBO_BOX_TEXT(X)
0042 #  define QTC_COMBO_ENTRY(X) GTK_IS_COMBO_BOX_TEXT(X)
0043 #elif GTK_CHECK_VERSION(2, 24, 0)
0044 #  define QTC_IS_COMBO(X) (GTK_IS_COMBO(X) || GTK_IS_COMBO_BOX_TEXT(X))
0045 #  define QTC_COMBO_ENTRY(X) (GTK_IS_COMBO_BOX_ENTRY(X) ||      \
0046                               GTK_IS_COMBO_BOX_TEXT(X))
0047 #else
0048 #  define QTC_IS_COMBO(X) GTK_IS_COMBO(X)
0049 #  define QTC_COMBO_ENTRY(X) GTK_IS_COMBO_BOX_ENTRY(X)
0050 #endif
0051 
0052 #define QT_CUSTOM_COLOR_BUTTON(style)           \
0053     (style &&                                                           \
0054      !(COL_EQ(qtSettings.colors[PAL_ACTIVE][COLOR_WINDOW].red,(style->bg[GTK_STATE_SELECTED==state ? state : GTK_STATE_NORMAL].red)) && \
0055       COL_EQ(qtSettings.colors[PAL_ACTIVE][COLOR_WINDOW].green,(style->bg[GTK_STATE_SELECTED==state ? state : GTK_STATE_NORMAL].green)) && \
0056       COL_EQ(qtSettings.colors[PAL_ACTIVE][COLOR_WINDOW].blue,(style->bg[GTK_STATE_SELECTED==state ? state : GTK_STATE_NORMAL].blue))))
0057 
0058 #define SET_BTN_COLS(SCROLLBAR, SCALE, LISTVIEW, STATE) \
0059 { \
0060     if(SCROLLBAR || SCALE) \
0061         btnColors=GTK_STATE_INSENSITIVE==STATE \
0062                     ? qtcPalette.background \
0063                     : SHADE_NONE!=opts.shadeSliders && qtcPalette.slider && \
0064                       (!opts.colorSliderMouseOver || GTK_STATE_PRELIGHT==STATE) \
0065                         ? qtcPalette.slider \
0066                         : qtcPalette.button[PAL_ACTIVE]; \
0067     else if(LISTVIEW) \
0068     { \
0069         if(GTK_STATE_INSENSITIVE!=state && qtcPalette.sortedlv && isSortColumn(widget)) \
0070             btnColors=qtcPalette.sortedlv;  \
0071         else if(opts.lvButton) \
0072             btnColors=qtcPalette.button[GTK_STATE_INSENSITIVE==STATE ? PAL_DISABLED : PAL_ACTIVE]; \
0073         else \
0074             btnColors=qtcPalette.background; \
0075     } \
0076     else \
0077         btnColors=qtcPalette.button[GTK_STATE_INSENSITIVE==STATE ? PAL_DISABLED : PAL_ACTIVE]; \
0078 }
0079 
0080 #define ARROW_STATE(state) (GTK_STATE_INSENSITIVE==state ? state : GTK_STATE_NORMAL)
0081 /* (GTK_STATE_ACTIVE==state ? GTK_STATE_NORMAL : state) */
0082 
0083 void debugDisplayWidget(GtkWidget *widget, int level);
0084 bool haveAlternateListViewCol();
0085 bool isFixedWidget(GtkWidget *widget);
0086 QTC_ALWAYS_INLINE static inline bool
0087 isMozilla()
0088 {
0089     return (oneOf(qtSettings.app, GTK_APP_MOZILLA, GTK_APP_NEW_MOZILLA) &&
0090             !getenv("QTCURVE_MOZ_TEST"));
0091 }
0092 QTC_ALWAYS_INLINE static inline bool
0093 isMozillaTab(GtkWidget *widget)
0094 {
0095     return isFixedWidget(widget) && GTK_IS_NOTEBOOK(widget);
0096 }
0097 QTC_ALWAYS_INLINE static inline bool
0098 isFakeGtk()
0099 {
0100     return isMozilla() || oneOf(qtSettings.app, GTK_APP_OPEN_OFFICE,
0101                                 GTK_APP_JAVA);
0102 }
0103 GdkColor *menuColors(bool active);
0104 EBorder shadowToBorder(GtkShadowType shadow);
0105 bool useButtonColor(const char *detail);
0106 void shadeColors(const GdkColor *base, GdkColor *vals);
0107 bool isSortColumn(GtkWidget *button);
0108 GdkColor *getCellCol(GdkColor *std, const char *detail);
0109 bool reverseLayout(GtkWidget *widget);
0110 bool isOnToolbar(GtkWidget *widget, bool *horiz, int level);
0111 bool isOnHandlebox(GtkWidget *widget, bool *horiz, int level);
0112 bool isButtonOnToolbar(GtkWidget *widget, bool *horiz);
0113 bool isButtonOnHandlebox(GtkWidget *widget, bool *horiz);
0114 bool isOnStatusBar(GtkWidget *widget, int level);
0115 bool isList(GtkWidget *widget);
0116 bool isListViewHeader(GtkWidget *widget);
0117 bool isEvolutionListViewHeader(GtkWidget *widget, const char *detail);
0118 bool isOnListViewHeader(GtkWidget *w, int level);
0119 bool isPathButton(GtkWidget *widget);
0120 GtkWidget *getComboEntry(GtkWidget *widget);
0121 GtkWidget *getComboButton(GtkWidget *widget);
0122 bool isSideBarBtn(GtkWidget *widget);
0123 bool isComboBoxButton(GtkWidget *widget);
0124 bool isComboBox(GtkWidget *widget);
0125 bool isComboBoxEntry(GtkWidget *widget);
0126 bool isComboBoxEntryButton(GtkWidget *widget);
0127 bool isGimpCombo(GtkWidget *widget);
0128 bool isOnComboEntry(GtkWidget *w, int level);
0129 bool isOnComboBox(GtkWidget *w, int level);
0130 bool isOnCombo(GtkWidget *w, int level);
0131 #if !GTK_CHECK_VERSION(2, 90, 0)
0132 bool isOnOptionMenu(GtkWidget *w, int level);
0133 bool isActiveOptionMenu(GtkWidget *widget);
0134 #endif
0135 bool isOnMenuItem(GtkWidget *w, int level);
0136 bool isSpinButton(GtkWidget *widget);
0137 bool isStatusBarFrame(GtkWidget *widget);
0138 GtkMenuBar *isMenubar(GtkWidget *w, int level);
0139 bool isMenuitem(GtkWidget *w, int level=0);
0140 bool isMenuWindow(GtkWidget *w);
0141 #define IS_GROUP_BOX(W) ((W) && GTK_IS_FRAME(W) &&                    \
0142                          (gtk_frame_get_label(GTK_FRAME(W)) ||        \
0143                           gtk_frame_get_label_widget(GTK_FRAME(W))))
0144 
0145 bool isInGroupBox(GtkWidget *w, int level);
0146 bool isOnButton(GtkWidget *w, int level, bool *def);
0147 void optionMenuGetProps(GtkWidget *widget, GtkRequisition *indicator_size, GtkBorder *indicator_spacing);
0148 
0149 typedef enum {
0150     STEPPER_A,
0151     STEPPER_B,
0152     STEPPER_C,
0153     STEPPER_D,
0154     STEPPER_NONE
0155 } EStepper;
0156 
0157 #if GTK_CHECK_VERSION(2, 90, 0)
0158 #define sanitizeSize(A, B, C) sanitizeSizeReal(widget, B, C)
0159 void gdk_drawable_get_size(GdkWindow *window, int *width, int *height);
0160 void sanitizeSizeReal(GtkWidget *widget, int *width, int *height);
0161 #else
0162 void sanitizeSize(GdkWindow *window, int *width, int *height);
0163 #endif
0164 EStepper getStepper(GtkWidget *widget, int x, int y, int width, int height);
0165 
0166 int getFill(GtkStateType state, bool set, bool darker=false);
0167 bool isSbarDetail(const char *detail);
0168 bool isHorizontalProgressbar(GtkWidget *widget);
0169 bool isComboBoxPopupWindow(GtkWidget *widget, int level);
0170 bool isComboBoxList(GtkWidget *widget);
0171 bool isComboPopupWindow(GtkWidget *widget, int level);
0172 bool isComboList(GtkWidget *widget);
0173 bool isComboMenu(GtkWidget *widget);
0174 bool isComboFrame(GtkWidget *widget);
0175 bool isGimpDockable(GtkWidget *widget);
0176 #define isMozillaWidget(widget) (isMozilla() && isFixedWidget(widget))
0177 GdkColor *getParentBgCol(GtkWidget *widget);
0178 int getOpacity(GtkWidget *widget);
0179 void setLowerEtchCol(cairo_t *cr, GtkWidget *widget);
0180 GdkColor shadeColor(const GdkColor *orig, double mod);
0181 gboolean windowEvent(GtkWidget *widget, GdkEvent *event, void *user_data);
0182 void adjustToolbarButtons(GtkWidget *widget, int *x, int *y, int *width,
0183                           int *height, ECornerBits *round, bool horiz);
0184 void getEntryParentBgCol(GtkWidget *widget, GdkColor *color);
0185 bool compositingActive(GtkWidget *widget);
0186 bool isRgbaWidget(GtkWidget *widget);
0187 void enableBlurBehind(GtkWidget *w, bool enable);
0188 void getTopLevelSize(GdkWindow *window, int *w, int *h);
0189 void getTopLevelOrigin(GdkWindow *window, int *x, int *y);
0190 bool mapToTopLevel(GdkWindow *window, GtkWidget *widget, int *x, int *y, int *w, int *h); //, bool frame)
0191 ECornerBits getRound(const char *detail, GtkWidget *widget, bool rev);
0192 
0193 bool treeViewCellHasChildren(GtkTreeView *treeView, GtkTreePath *path);
0194 bool treeViewCellIsLast(GtkTreeView *treeView, GtkTreePath *path);
0195 GtkTreePath *treeViewPathParent(GtkTreeView *treeView, GtkTreePath *path);
0196 void generateColors();
0197 GdkColor *getCheckRadioCol(GtkStyle *style, GtkStateType state, bool mnu);
0198 bool objectIsA(const GObject *object, const char *type_name);
0199 
0200 }
0201 
0202 #endif