~canonical-dx-team/ubuntu/maverick/gtk+2.0/menuproxy

« back to all changes in this revision

Viewing changes to modules/engines/ms-windows/xp_theme.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-05-04 12:24:25 UTC
  • mfrom: (1.1.21 upstream)
  • Revision ID: james.westby@ubuntu.com-20070504122425-0m8midgzrp40y8w2
Tags: 2.10.12-1ubuntu1
* Sync with Debian
* New upstream version:
  Fixed bugs:
  - 379414 file chooser warnings when changing path in the entry
  - 418585 GtkFileChooserDefault sizing code is not DPI independent
  - 419568 Crash in search if start with special letter
  - 435062 build dies with icon cache validation
  - 379399 Segfault to call gtk_print_operation_run twice.
  - 387889 cups backend has problems when there are too many printers
  - 418531 invalid read to gtkicontheme.c gtk_icon_theme_lookup_icon...
  - 423916 crash in color scheme code
  - 424042 Segmentation fault while quickly pressing Alt+arrows
  - 415260 Protect against negative indices when setting values in G...
  - 419171 XGetVisualInfo() may not set nxvisuals
  - 128852 Gdk cursors don't look good on win32
  - 344657 Ctrl-H doesn't toggle "Show Hidden Files" setting
  - 345345 PrintOperation::paginate is not emitted for class handler
  - 347567 GtkPrintOperation::end-print is not emitted if it's cance...
  - 369112 gtk_ui_manager_add_ui should accept unnamed separator
  - 392015 Selected menu item invisible on Windows Vista
  - 399253 MS-Windows Theme Bottom Tab placement rendering glitches
  - 399425 gtk_input_dialog_fill_axes() adds child to gtkscrolledwin...
  - 403251 [patch] little memory leak in GtkPrintJob
  - 403267 [patch] memory leak in GtkPageSetupUnixDialog
  - 403470 MS-Windows Theme tab placement other than on top leaks a ...
  - 404506 Windows system fonts that have multi-byte font names cann...
  - 405089 Incorrect window placement for GtkEventBox private window
  - 405515 Minor leak in gtkfilesystemmodel.c
  - 405539 gdk_pixbuf_save() for PNG saver can return FALSE without ...
  - 415681 gdk_window_clear_area includes an extra line and column o...
  - 418219 GtkRecentChooser should apply filter before sorting and c...
  - 418403 Scroll to printer after selecting it from settings
  - 421985 _gtk_print_operation_platform_backend_launch_preview
  - 421990 gtk_print_job_get_surface
  - 421993 gtk_print_operation_init
  - 423064 Conditional jump or move depends on uninitialised value(s...
  - 423722 Fix printing header in gtk-demo
  - 424168 gtk_print_operation_run on async preview
  - 425655 Don't install gtk+-unix-print-2.0.pc on non-UNIX platforms
  - 425786 GDK segfaults if XineramaQueryScreens fails
  - 428665 Lpr Backend gets stuck in infinite loop during gtk_enumer...
  - 429902 GtkPrintOperation leaks cairo contextes
  - 431997 First delay of GdkPixbufAnimationIter is wrong
  - 433242 Inconsistent scroll arrow position calculations
  - 433972 Placing gtk.Expander inside a gtk.TextView() changes gtk....
  - 434261 _gtk_toolbar_elide_underscores incorrectly handles some s...
  - 383354 ctrl-L should make 'Location' entry disappear
  - 418673 gtk_recent_manager_add_item
  - 429732 gtk_accel_group_finalize accesses invalid memory
  - 435028 WM_CLIENT_LEADER is wrong on the leader_window
  - 431067 Background of the header window is not updated
  - 338843 add recent files support inside the ui manager
  - 148535 add drop shadow to menus, tooltips, etc. under Windows XP
* debian/control.in:
  - Conflicts on ubuntulooks (<= 0.9.11-1)
* debian/patches/15_default-fallback-icon-theme.patch:
  - patch from Debian, fallback on gnome icon theme

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* MS-Windows Engine (aka GTK-Wimp)
 
2
 *
 
3
 * Copyright (C) 2003, 2004 Raymond Penners <raymond@dotsphinx.com>
 
4
 *
 
5
 * This library is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU Library General Public
 
7
 * License as published by the Free Software Foundation; either
 
8
 * version 2 of the License, or (at your option) any later version.
 
9
 *
 
10
 * This library is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
 * Library General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU Library General Public
 
16
 * License along with this library; if not, write to the
 
17
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
18
 * Boston, MA 02111-1307, USA.
 
19
 */
 
20
 
 
21
#define _WIN32_WINNT 0x0501
 
22
 
 
23
#include "xp_theme.h"
 
24
 
 
25
#ifdef HAVE_CONFIG_H
 
26
#include <config.h>
 
27
#endif
 
28
 
 
29
#include <windows.h>
 
30
#include <math.h>
 
31
#include <string.h>
 
32
#include <stdio.h>
 
33
 
 
34
/* #include "gdk/gdkwin32.h" */
 
35
#include "gdk/win32/gdkwin32.h"
 
36
 
 
37
#include "xp_theme_defs.h"
 
38
 
 
39
#ifndef TMT_CAPTIONFONT
 
40
 
 
41
/* These aren't in mingw's "w32api" headers, nor in the Platform SDK
 
42
 * headers.
 
43
 */
 
44
#define TMT_CAPTIONFONT 801
 
45
#define TMT_MENUFONT 803
 
46
#define TMT_STATUSFONT 804
 
47
#define TMT_MSGBOXFONT 805
 
48
#endif
 
49
 
 
50
#define GP_LINEHORZ 2
 
51
#define GP_LINEVERT 3
 
52
#define TP_SEPARATOR           5
 
53
#define TP_SEPARATORVERT       6
 
54
 
 
55
/* GLOBALS LINEHORZ states */
 
56
#define LHS_FLAT   1
 
57
#define LHS_RAISED 2
 
58
#define LHS_SUNKEN 3
 
59
 
 
60
/* GLOBAL LINEVERT states */
 
61
#define LVS_FLAT   1
 
62
#define LVS_RAISED 2
 
63
#define LVS_SUNKEN 3
 
64
 
 
65
/* TRACKBAR parts */
 
66
#define TKP_TRACK       1
 
67
#define TKP_TRACKVERT   2
 
68
#define TKP_THUMB       3
 
69
#define TKP_THUMBBOTTOM 4
 
70
#define TKP_THUMBTOP    5
 
71
#define TKP_THUMBVERT   6
 
72
#define TKP_THUMBLEFT   7
 
73
#define TKP_THUMBRIGHT  8
 
74
#define TKP_TICS        9
 
75
#define TKP_TICSVERT    10
 
76
 
 
77
#define TRS_NORMAL 1
 
78
 
 
79
static const LPCWSTR class_descriptors[] = {
 
80
    L"Scrollbar",               /* XP_THEME_CLASS_SCROLLBAR */
 
81
    L"Button",                  /* XP_THEME_CLASS_BUTTON */
 
82
    L"Header",                  /* XP_THEME_CLASS_HEADER */
 
83
    L"ComboBox",                /* XP_THEME_CLASS_COMBOBOX */
 
84
    L"Tab",                         /* XP_THEME_CLASS_TAB */
 
85
    L"Edit",                    /* XP_THEME_CLASS_EDIT */
 
86
    L"TreeView",                /* XP_THEME_CLASS_TREEVIEW */
 
87
    L"Spin",                    /* XP_THEME_CLASS_SPIN */
 
88
    L"Progress",                /* XP_THEME_CLASS_PROGRESS */
 
89
    L"Tooltip",                 /* XP_THEME_CLASS_TOOLTIP */
 
90
    L"Rebar",                   /* XP_THEME_CLASS_REBAR */
 
91
    L"Toolbar",                 /* XP_THEME_CLASS_TOOLBAR */
 
92
    L"Globals",                 /* XP_THEME_CLASS_GLOBALS */
 
93
    L"Menu",                    /* XP_THEME_CLASS_MENU */
 
94
    L"Window",                  /* XP_THEME_CLASS_WINDOW */
 
95
    L"Status",                  /* XP_THEME_CLASS_STATUS */
 
96
    L"Trackbar"                 /* XP_THEME_CLASS_TRACKBAR */
 
97
};
 
98
 
 
99
static const short element_part_map[] = {
 
100
    BP_CHECKBOX,
 
101
    BP_CHECKBOX,
 
102
    BP_PUSHBUTTON,
 
103
    HP_HEADERITEM,
 
104
    CP_DROPDOWNBUTTON,
 
105
    TABP_BODY,
 
106
    TABP_TABITEM,
 
107
    TABP_TABITEMLEFTEDGE,
 
108
        TABP_TABITEMRIGHTEDGE,
 
109
    TABP_PANE,
 
110
    SBP_THUMBBTNHORZ,
 
111
    SBP_THUMBBTNVERT,
 
112
    SBP_ARROWBTN,
 
113
    SBP_ARROWBTN,
 
114
    SBP_ARROWBTN,
 
115
    SBP_ARROWBTN,
 
116
    SBP_GRIPPERHORZ,
 
117
    SBP_GRIPPERVERT,
 
118
    SBP_LOWERTRACKHORZ,
 
119
    SBP_LOWERTRACKVERT,
 
120
    EP_EDITTEXT,
 
121
    BP_PUSHBUTTON,
 
122
    SPNP_UP,
 
123
    SPNP_DOWN,
 
124
    BP_RADIOBUTTON,
 
125
    BP_RADIOBUTTON,
 
126
    TVP_GLYPH,
 
127
    TVP_GLYPH,
 
128
    PP_CHUNK,
 
129
    PP_CHUNKVERT,
 
130
    PP_BAR,
 
131
    PP_BARVERT,
 
132
    TTP_STANDARD,
 
133
    0 /* RP_BAND */ ,
 
134
    RP_GRIPPER,
 
135
    RP_GRIPPERVERT,
 
136
    RP_CHEVRON,
 
137
    TP_BUTTON,
 
138
    MP_MENUITEM,
 
139
    MP_SEPARATOR,
 
140
    SP_GRIPPER,
 
141
    SP_PANE,
 
142
    GP_LINEHORZ,
 
143
    GP_LINEVERT,
 
144
    TP_SEPARATOR,
 
145
    TP_SEPARATORVERT,
 
146
    TKP_TRACK,
 
147
    TKP_TRACKVERT,
 
148
    TKP_THUMB,
 
149
    TKP_THUMBVERT,
 
150
    TKP_TICS,
 
151
    TKP_TICSVERT
 
152
};
 
153
 
 
154
static HINSTANCE uxtheme_dll = NULL;
 
155
static HTHEME open_themes[XP_THEME_CLASS__SIZEOF];
 
156
static gboolean use_xp_theme = FALSE;
 
157
 
 
158
typedef HRESULT (FAR PASCAL * GetThemeSysFontFunc)
 
159
    (HTHEME hTheme, int iFontID, OUT LOGFONT * plf);
 
160
typedef int (FAR PASCAL * GetThemeSysSizeFunc) (HTHEME hTheme, int iSizeId);
 
161
typedef COLORREF (FAR PASCAL * GetThemeSysColorFunc) (HTHEME hTheme,
 
162
                                                      int iColorID);
 
163
typedef HTHEME (FAR PASCAL * OpenThemeDataFunc) (HWND hwnd,
 
164
                                                 LPCWSTR pszClassList);
 
165
typedef HRESULT (FAR PASCAL * CloseThemeDataFunc) (HTHEME theme);
 
166
typedef HRESULT (FAR PASCAL * DrawThemeBackgroundFunc)
 
167
    (HTHEME hTheme, HDC hdc, int iPartId, int iStateId,
 
168
     const RECT * pRect, const RECT * pClipRect);
 
169
typedef HRESULT (FAR PASCAL * EnableThemeDialogTextureFunc) (HWND hwnd,
 
170
                                                             DWORD dwFlags);
 
171
typedef BOOL (FAR PASCAL * IsThemeActiveFunc) (VOID);
 
172
typedef BOOL (FAR PASCAL * IsAppThemedFunc) (VOID);
 
173
typedef BOOL (FAR PASCAL *
 
174
              IsThemeBackgroundPartiallyTransparentFunc) (HTHEME hTheme,
 
175
                                                          int iPartId,
 
176
                                                          int iStateId);
 
177
typedef HRESULT (FAR PASCAL * DrawThemeParentBackgroundFunc) (HWND hwnd,
 
178
                                                              HDC hdc,
 
179
                                                              RECT * prc);
 
180
 
 
181
static GetThemeSysFontFunc get_theme_sys_font_func = NULL;
 
182
static GetThemeSysColorFunc get_theme_sys_color_func = NULL;
 
183
static GetThemeSysSizeFunc get_theme_sys_metric_func = NULL;
 
184
static OpenThemeDataFunc open_theme_data_func = NULL;
 
185
static CloseThemeDataFunc close_theme_data_func = NULL;
 
186
static DrawThemeBackgroundFunc draw_theme_background_func = NULL;
 
187
static EnableThemeDialogTextureFunc enable_theme_dialog_texture_func = NULL;
 
188
static IsThemeActiveFunc is_theme_active_func = NULL;
 
189
static IsAppThemedFunc is_app_themed_func = NULL;
 
190
static IsThemeBackgroundPartiallyTransparentFunc
 
191
    is_theme_partially_transparent_func = NULL;
 
192
static DrawThemeParentBackgroundFunc draw_theme_parent_background_func = NULL;
 
193
 
 
194
static void
 
195
xp_theme_close_open_handles (void)
 
196
{
 
197
    int i;
 
198
 
 
199
    for (i = 0; i < XP_THEME_CLASS__SIZEOF; i++)
 
200
        {
 
201
            if (open_themes[i])
 
202
                {
 
203
                    close_theme_data_func (open_themes[i]);
 
204
                    open_themes[i] = NULL;
 
205
                }
 
206
        }
 
207
}
 
208
 
 
209
void
 
210
xp_theme_init (void)
 
211
{
 
212
    if (uxtheme_dll)
 
213
        return;
 
214
 
 
215
    memset (open_themes, 0, sizeof (open_themes));
 
216
 
 
217
    uxtheme_dll = LoadLibrary ("uxtheme.dll");
 
218
    if (!uxtheme_dll)
 
219
        return;
 
220
 
 
221
    is_app_themed_func =
 
222
        (IsAppThemedFunc) GetProcAddress (uxtheme_dll, "IsAppThemed");
 
223
 
 
224
    if (is_app_themed_func)
 
225
        {
 
226
            is_theme_active_func =
 
227
                (IsThemeActiveFunc) GetProcAddress (uxtheme_dll,
 
228
                                                    "IsThemeActive");
 
229
            open_theme_data_func =
 
230
                (OpenThemeDataFunc) GetProcAddress (uxtheme_dll,
 
231
                                                    "OpenThemeData");
 
232
            close_theme_data_func =
 
233
                (CloseThemeDataFunc) GetProcAddress (uxtheme_dll,
 
234
                                                     "CloseThemeData");
 
235
            draw_theme_background_func =
 
236
                (DrawThemeBackgroundFunc) GetProcAddress (uxtheme_dll,
 
237
                                                          "DrawThemeBackground");
 
238
            enable_theme_dialog_texture_func =
 
239
                (EnableThemeDialogTextureFunc) GetProcAddress (uxtheme_dll,
 
240
                                                               "EnableThemeDialogTexture");
 
241
            get_theme_sys_font_func =
 
242
                (GetThemeSysFontFunc) GetProcAddress (uxtheme_dll,
 
243
                                                      "GetThemeSysFont");
 
244
            get_theme_sys_color_func =
 
245
                (GetThemeSysColorFunc) GetProcAddress (uxtheme_dll,
 
246
                                                       "GetThemeSysColor");
 
247
            get_theme_sys_metric_func =
 
248
                (GetThemeSysSizeFunc) GetProcAddress (uxtheme_dll,
 
249
                                                      "GetThemeSysSize");
 
250
            is_theme_partially_transparent_func =
 
251
                (IsThemeBackgroundPartiallyTransparentFunc)
 
252
                GetProcAddress (uxtheme_dll,
 
253
                                "IsThemeBackgroundPartiallyTransparent");
 
254
            draw_theme_parent_background_func =
 
255
                (DrawThemeParentBackgroundFunc) GetProcAddress (uxtheme_dll,
 
256
                                                                "DrawThemeParentBackground");
 
257
        }
 
258
 
 
259
    if (is_app_themed_func && is_theme_active_func) {
 
260
        use_xp_theme = (is_app_themed_func () && is_theme_active_func ());
 
261
    }
 
262
    else {
 
263
        use_xp_theme = FALSE;
 
264
    }
 
265
}
 
266
 
 
267
void
 
268
xp_theme_reset (void)
 
269
{
 
270
    xp_theme_close_open_handles ();
 
271
 
 
272
    if (is_app_themed_func && is_theme_active_func) {
 
273
        use_xp_theme = (is_app_themed_func () && is_theme_active_func ());
 
274
    }
 
275
    else {
 
276
        use_xp_theme = FALSE;
 
277
    }
 
278
}
 
279
 
 
280
void
 
281
xp_theme_exit (void)
 
282
{
 
283
    if (!uxtheme_dll)
 
284
        return;
 
285
 
 
286
    xp_theme_close_open_handles ();
 
287
 
 
288
    FreeLibrary (uxtheme_dll);
 
289
    uxtheme_dll = NULL;
 
290
        use_xp_theme = FALSE;
 
291
 
 
292
    is_app_themed_func = NULL;
 
293
    is_theme_active_func = NULL;
 
294
    open_theme_data_func = NULL;
 
295
    close_theme_data_func = NULL;
 
296
    draw_theme_background_func = NULL;
 
297
    enable_theme_dialog_texture_func = NULL;
 
298
    get_theme_sys_font_func = NULL;
 
299
    get_theme_sys_color_func = NULL;
 
300
    get_theme_sys_metric_func = NULL;
 
301
    is_theme_partially_transparent_func = NULL;
 
302
    draw_theme_parent_background_func = NULL;
 
303
}
 
304
 
 
305
static HTHEME
 
306
xp_theme_get_handle_by_class (XpThemeClass klazz)
 
307
{
 
308
    if (!open_themes[klazz] && open_theme_data_func)
 
309
        {
 
310
            open_themes[klazz] =
 
311
                open_theme_data_func (NULL, class_descriptors[klazz]);
 
312
        }
 
313
    return open_themes[klazz];
 
314
}
 
315
 
 
316
static HTHEME
 
317
xp_theme_get_handle_by_element (XpThemeElement element)
 
318
{
 
319
    HTHEME ret = NULL;
 
320
    XpThemeClass klazz = XP_THEME_CLASS__SIZEOF;
 
321
 
 
322
    switch (element)
 
323
        {
 
324
        case XP_THEME_ELEMENT_TOOLTIP:
 
325
            klazz = XP_THEME_CLASS_TOOLTIP;
 
326
            break;
 
327
 
 
328
        case XP_THEME_ELEMENT_REBAR:
 
329
        case XP_THEME_ELEMENT_REBAR_GRIPPER_H:
 
330
        case XP_THEME_ELEMENT_REBAR_GRIPPER_V:
 
331
        case XP_THEME_ELEMENT_REBAR_CHEVRON:
 
332
            klazz = XP_THEME_CLASS_REBAR;
 
333
            break;
 
334
 
 
335
        case XP_THEME_ELEMENT_SCALE_TROUGH_H:
 
336
        case XP_THEME_ELEMENT_SCALE_TROUGH_V:
 
337
        case XP_THEME_ELEMENT_SCALE_SLIDER_H:
 
338
        case XP_THEME_ELEMENT_SCALE_SLIDER_V:
 
339
        case XP_THEME_ELEMENT_SCALE_TICS_H:
 
340
        case XP_THEME_ELEMENT_SCALE_TICS_V:
 
341
            klazz = XP_THEME_CLASS_TRACKBAR;
 
342
            break;
 
343
 
 
344
        case XP_THEME_ELEMENT_STATUS_GRIPPER:
 
345
        case XP_THEME_ELEMENT_STATUS_PANE:
 
346
            klazz = XP_THEME_CLASS_STATUS;
 
347
            break;
 
348
 
 
349
        case XP_THEME_ELEMENT_TOOLBAR_BUTTON:
 
350
        case XP_THEME_ELEMENT_TOOLBAR_SEPARATOR_H:
 
351
        case XP_THEME_ELEMENT_TOOLBAR_SEPARATOR_V:
 
352
            klazz = XP_THEME_CLASS_TOOLBAR;
 
353
            break;
 
354
 
 
355
        case XP_THEME_ELEMENT_MENU_ITEM:
 
356
        case XP_THEME_ELEMENT_MENU_SEPARATOR:
 
357
            klazz = XP_THEME_CLASS_MENU;
 
358
            break;
 
359
 
 
360
        case XP_THEME_ELEMENT_PRESSED_CHECKBOX:
 
361
        case XP_THEME_ELEMENT_CHECKBOX:
 
362
        case XP_THEME_ELEMENT_BUTTON:
 
363
        case XP_THEME_ELEMENT_DEFAULT_BUTTON:
 
364
        case XP_THEME_ELEMENT_PRESSED_RADIO_BUTTON:
 
365
        case XP_THEME_ELEMENT_RADIO_BUTTON:
 
366
            klazz = XP_THEME_CLASS_BUTTON;
 
367
            break;
 
368
 
 
369
        case XP_THEME_ELEMENT_LIST_HEADER:
 
370
            klazz = XP_THEME_CLASS_HEADER;
 
371
            break;
 
372
 
 
373
        case XP_THEME_ELEMENT_COMBOBUTTON:
 
374
            klazz = XP_THEME_CLASS_COMBOBOX;
 
375
            break;
 
376
 
 
377
        case XP_THEME_ELEMENT_BODY:
 
378
        case XP_THEME_ELEMENT_TAB_ITEM:
 
379
        case XP_THEME_ELEMENT_TAB_ITEM_LEFT_EDGE:
 
380
        case XP_THEME_ELEMENT_TAB_ITEM_RIGHT_EDGE:
 
381
        case XP_THEME_ELEMENT_TAB_PANE:
 
382
            klazz = XP_THEME_CLASS_TAB;
 
383
            break;
 
384
 
 
385
        case XP_THEME_ELEMENT_SCROLLBAR_V:
 
386
        case XP_THEME_ELEMENT_SCROLLBAR_H:
 
387
        case XP_THEME_ELEMENT_ARROW_UP:
 
388
        case XP_THEME_ELEMENT_ARROW_DOWN:
 
389
        case XP_THEME_ELEMENT_ARROW_LEFT:
 
390
        case XP_THEME_ELEMENT_ARROW_RIGHT:
 
391
        case XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_V:
 
392
        case XP_THEME_ELEMENT_SCROLLBAR_GRIPPER_H:
 
393
        case XP_THEME_ELEMENT_TROUGH_V:
 
394
        case XP_THEME_ELEMENT_TROUGH_H:
 
395
            klazz = XP_THEME_CLASS_SCROLLBAR;
 
396
            break;
 
397
 
 
398
        case XP_THEME_ELEMENT_EDIT_TEXT:
 
399
            klazz = XP_THEME_CLASS_EDIT;
 
400
            break;
 
401
 
 
402
        case XP_THEME_ELEMENT_SPIN_BUTTON_UP:
 
403
        case XP_THEME_ELEMENT_SPIN_BUTTON_DOWN:
 
404
            klazz = XP_THEME_CLASS_SPIN;
 
405
            break;
 
406
 
 
407
        case XP_THEME_ELEMENT_PROGRESS_BAR_H:
 
408
        case XP_THEME_ELEMENT_PROGRESS_BAR_V:
 
409
        case XP_THEME_ELEMENT_PROGRESS_TROUGH_H:
 
410
        case XP_THEME_ELEMENT_PROGRESS_TROUGH_V:
 
411
            klazz = XP_THEME_CLASS_PROGRESS;
 
412
            break;
 
413
 
 
414
        case XP_THEME_ELEMENT_TREEVIEW_EXPANDER_OPENED:
 
415
        case XP_THEME_ELEMENT_TREEVIEW_EXPANDER_CLOSED:
 
416
            klazz = XP_THEME_CLASS_TREEVIEW;
 
417
            break;
 
418
 
 
419
        case XP_THEME_ELEMENT_LINE_H:
 
420
        case XP_THEME_ELEMENT_LINE_V:
 
421
            klazz = XP_THEME_CLASS_GLOBALS;
 
422
            break;
 
423
 
 
424
        default:
 
425
            break;
 
426
        }
 
427
 
 
428
    if (klazz != XP_THEME_CLASS__SIZEOF)
 
429
        {
 
430
            ret = xp_theme_get_handle_by_class (klazz);
 
431
        }
 
432
    return ret;
 
433
}
 
434
 
 
435
static int
 
436
xp_theme_map_gtk_state (XpThemeElement element, GtkStateType state)
 
437
{
 
438
    int ret = 0;
 
439
 
 
440
    switch (element)
 
441
        {
 
442
        case XP_THEME_ELEMENT_TOOLTIP:
 
443
            ret = TTSS_NORMAL;
 
444
            break;
 
445
 
 
446
        case XP_THEME_ELEMENT_REBAR:
 
447
            ret = 0;
 
448
            break;
 
449
 
 
450
        case XP_THEME_ELEMENT_REBAR_GRIPPER_H:
 
451
        case XP_THEME_ELEMENT_REBAR_GRIPPER_V:
 
452
            ret = 0;
 
453
            break;
 
454
 
 
455
        case XP_THEME_ELEMENT_STATUS_GRIPPER:
 
456
        case XP_THEME_ELEMENT_STATUS_PANE:
 
457
            ret = 1;
 
458
            break;
 
459
 
 
460
        case XP_THEME_ELEMENT_REBAR_CHEVRON:
 
461
            switch (state)
 
462
                {
 
463
                case GTK_STATE_PRELIGHT:
 
464
                    ret = CHEVS_HOT;
 
465
                    break;
 
466
                case GTK_STATE_SELECTED:
 
467
                case GTK_STATE_ACTIVE:
 
468
                    ret = CHEVS_PRESSED;
 
469
                    break;
 
470
                default:
 
471
                    ret = CHEVS_NORMAL;
 
472
                }
 
473
            break;
 
474
 
 
475
        case XP_THEME_ELEMENT_TOOLBAR_SEPARATOR_H:
 
476
        case XP_THEME_ELEMENT_TOOLBAR_SEPARATOR_V:
 
477
            ret = TS_NORMAL;
 
478
            break;
 
479
 
 
480
        case XP_THEME_ELEMENT_TOOLBAR_BUTTON:
 
481
            switch (state)
 
482
                {
 
483
                case GTK_STATE_ACTIVE:
 
484
                    ret = TS_PRESSED;
 
485
                    break;
 
486
                case GTK_STATE_PRELIGHT:
 
487
                    ret = TS_HOT;
 
488
                    break;
 
489
                case GTK_STATE_INSENSITIVE:
 
490
                    ret = TS_DISABLED;
 
491
                    break;
 
492
                default:
 
493
                    ret = TS_NORMAL;
 
494
                }
 
495
            break;
 
496
 
 
497
        case XP_THEME_ELEMENT_TAB_PANE:
 
498
            ret = 1;
 
499
            break;
 
500
 
 
501
        case XP_THEME_ELEMENT_TAB_ITEM_LEFT_EDGE:
 
502
        case XP_THEME_ELEMENT_TAB_ITEM_RIGHT_EDGE:
 
503
        case XP_THEME_ELEMENT_TAB_ITEM:
 
504
            switch (state)
 
505
                {
 
506
                case GTK_STATE_PRELIGHT:
 
507
                    ret = TIS_HOT;
 
508
                    break;
 
509
                case GTK_STATE_INSENSITIVE:
 
510
                    ret = TIS_DISABLED;
 
511
                    break;
 
512
                case GTK_STATE_SELECTED:
 
513
                case GTK_STATE_ACTIVE:
 
514
                    ret = TIS_NORMAL;
 
515
                    break;
 
516
                default:
 
517
                    ret = TIS_SELECTED;
 
518
                }
 
519
            break;
 
520
 
 
521
        case XP_THEME_ELEMENT_EDIT_TEXT:
 
522
            switch (state)
 
523
                {
 
524
                case GTK_STATE_PRELIGHT:
 
525
                    ret = ETS_FOCUSED;
 
526
                    break;
 
527
                case GTK_STATE_INSENSITIVE:
 
528
                    ret = ETS_READONLY;
 
529
                    break;
 
530
                case GTK_STATE_SELECTED:
 
531
                case GTK_STATE_ACTIVE:
 
532
                default:
 
533
                    ret = ETS_NORMAL;
 
534
                }
 
535
            break;
 
536
 
 
537
        case XP_THEME_ELEMENT_TROUGH_H:
 
538
        case XP_THEME_ELEMENT_TROUGH_V:
 
539
            ret = SCRBS_NORMAL;
 
540
            break;
 
541
 
 
542
        case XP_THEME_ELEMENT_SCROLLBAR_H:
 
543
        case XP_THEME_ELEMENT_SCROLLBAR_V:
 
544
            switch (state)
 
545
                {
 
546
                case GTK_STATE_SELECTED:
 
547
                case GTK_STATE_ACTIVE:
 
548
                    ret = SCRBS_PRESSED;
 
549
                    break;
 
550
                case GTK_STATE_PRELIGHT:
 
551
                    ret = SCRBS_HOT;
 
552
                    break;
 
553
                case GTK_STATE_INSENSITIVE:
 
554
                    ret = SCRBS_DISABLED;
 
555
                    break;
 
556
                default:
 
557
                    ret = SCRBS_NORMAL;
 
558
                }
 
559
            break;
 
560
 
 
561
        case XP_THEME_ELEMENT_ARROW_DOWN:
 
562
            switch (state)
 
563
                {
 
564
                case GTK_STATE_ACTIVE:
 
565
                    ret = ABS_DOWNPRESSED;
 
566
                    break;
 
567
                case GTK_STATE_PRELIGHT:
 
568
                    ret = ABS_DOWNHOT;
 
569
                    break;
 
570
                case GTK_STATE_INSENSITIVE:
 
571
                    ret = ABS_DOWNDISABLED;
 
572
                    break;
 
573
                default:
 
574
                    ret = ABS_DOWNNORMAL;
 
575
                }
 
576
            break;
 
577
 
 
578
        case XP_THEME_ELEMENT_ARROW_UP:
 
579
            switch (state)
 
580
                {
 
581
                case GTK_STATE_ACTIVE:
 
582
                    ret = ABS_UPPRESSED;
 
583
                    break;
 
584
                case GTK_STATE_PRELIGHT:
 
585
                    ret = ABS_UPHOT;
 
586
                    break;
 
587
                case GTK_STATE_INSENSITIVE:
 
588
                    ret = ABS_UPDISABLED;
 
589
                    break;
 
590
                default:
 
591
                    ret = ABS_UPNORMAL;
 
592
                }
 
593
            break;
 
594
 
 
595
        case XP_THEME_ELEMENT_ARROW_LEFT:
 
596
            switch (state)
 
597
                {
 
598
                case GTK_STATE_ACTIVE:
 
599
                    ret = ABS_LEFTPRESSED;
 
600
                    break;
 
601
                case GTK_STATE_PRELIGHT:
 
602
                    ret = ABS_LEFTHOT;
 
603
                    break;
 
604
                case GTK_STATE_INSENSITIVE:
 
605
                    ret = ABS_LEFTDISABLED;
 
606
                    break;
 
607
                default:
 
608
                    ret = ABS_LEFTNORMAL;
 
609
                }
 
610
            break;
 
611
 
 
612
        case XP_THEME_ELEMENT_ARROW_RIGHT:
 
613
            switch (state)
 
614
                {
 
615
                case GTK_STATE_ACTIVE:
 
616
                    ret = ABS_RIGHTPRESSED;
 
617
                    break;
 
618
                case GTK_STATE_PRELIGHT:
 
619
                    ret = ABS_RIGHTHOT;
 
620
                    break;
 
621
                case GTK_STATE_INSENSITIVE:
 
622
                    ret = ABS_RIGHTDISABLED;
 
623
                    break;
 
624
                default:
 
625
                    ret = ABS_RIGHTNORMAL;
 
626
                }
 
627
            break;
 
628
 
 
629
        case XP_THEME_ELEMENT_CHECKBOX:
 
630
        case XP_THEME_ELEMENT_RADIO_BUTTON:
 
631
            switch (state)
 
632
                {
 
633
                case GTK_STATE_SELECTED:
 
634
                    ret = CBS_UNCHECKEDPRESSED;
 
635
                    break;
 
636
                case GTK_STATE_PRELIGHT:
 
637
                    ret = CBS_UNCHECKEDHOT;
 
638
                    break;
 
639
                case GTK_STATE_INSENSITIVE:
 
640
                    ret = CBS_UNCHECKEDDISABLED;
 
641
                    break;
 
642
                default:
 
643
                    ret = CBS_UNCHECKEDNORMAL;
 
644
                }
 
645
            break;
 
646
 
 
647
        case XP_THEME_ELEMENT_PRESSED_CHECKBOX:
 
648
        case XP_THEME_ELEMENT_PRESSED_RADIO_BUTTON:
 
649
            switch (state)
 
650
                {
 
651
                case GTK_STATE_SELECTED:
 
652
                    ret = CBS_CHECKEDPRESSED;
 
653
                    break;
 
654
                case GTK_STATE_PRELIGHT:
 
655
                    ret = CBS_CHECKEDHOT;
 
656
                    break;
 
657
                case GTK_STATE_INSENSITIVE:
 
658
                    ret = CBS_CHECKEDDISABLED;
 
659
                    break;
 
660
                default:
 
661
                    ret = CBS_CHECKEDNORMAL;
 
662
                }
 
663
            break;
 
664
 
 
665
        case XP_THEME_ELEMENT_DEFAULT_BUTTON:
 
666
            switch (state)
 
667
                {
 
668
                case GTK_STATE_ACTIVE:
 
669
                    ret = PBS_PRESSED;
 
670
                    break;
 
671
                case GTK_STATE_PRELIGHT:
 
672
                    ret = PBS_HOT;
 
673
                    break;
 
674
                case GTK_STATE_INSENSITIVE:
 
675
                    ret = PBS_DISABLED;
 
676
                    break;
 
677
                default:
 
678
                    ret = PBS_DEFAULTED;
 
679
                }
 
680
            break;
 
681
 
 
682
        case XP_THEME_ELEMENT_SPIN_BUTTON_DOWN:
 
683
            switch (state)
 
684
                {
 
685
                case GTK_STATE_ACTIVE:
 
686
                    ret = DNS_PRESSED;
 
687
                    break;
 
688
                case GTK_STATE_PRELIGHT:
 
689
                    ret = DNS_HOT;
 
690
                    break;
 
691
                case GTK_STATE_INSENSITIVE:
 
692
                    ret = DNS_DISABLED;
 
693
                    break;
 
694
                default:
 
695
                    ret = DNS_NORMAL;
 
696
                }
 
697
            break;
 
698
 
 
699
        case XP_THEME_ELEMENT_SPIN_BUTTON_UP:
 
700
            switch (state)
 
701
                {
 
702
                case GTK_STATE_ACTIVE:
 
703
                    ret = UPS_PRESSED;
 
704
                    break;
 
705
                case GTK_STATE_PRELIGHT:
 
706
                    ret = UPS_HOT;
 
707
                    break;
 
708
                case GTK_STATE_INSENSITIVE:
 
709
                    ret = UPS_DISABLED;
 
710
                    break;
 
711
                default:
 
712
                    ret = UPS_NORMAL;
 
713
                }
 
714
            break;
 
715
 
 
716
        case XP_THEME_ELEMENT_TREEVIEW_EXPANDER_OPENED:
 
717
            ret = GLPS_OPENED;
 
718
            break;
 
719
 
 
720
        case XP_THEME_ELEMENT_TREEVIEW_EXPANDER_CLOSED:
 
721
            ret = GLPS_CLOSED;
 
722
            break;
 
723
 
 
724
        case XP_THEME_ELEMENT_PROGRESS_BAR_H:
 
725
        case XP_THEME_ELEMENT_PROGRESS_BAR_V:
 
726
        case XP_THEME_ELEMENT_PROGRESS_TROUGH_H:
 
727
        case XP_THEME_ELEMENT_PROGRESS_TROUGH_V:
 
728
            ret = 1;
 
729
            break;
 
730
 
 
731
        case XP_THEME_ELEMENT_MENU_ITEM:
 
732
        case XP_THEME_ELEMENT_MENU_SEPARATOR:
 
733
            switch (state)
 
734
                {
 
735
                case GTK_STATE_SELECTED:
 
736
                    ret = MS_SELECTED;
 
737
                    break;
 
738
                case GTK_STATE_INSENSITIVE:
 
739
                    ret = MS_DEMOTED;
 
740
                    break;
 
741
                default:
 
742
                    ret = MS_NORMAL;
 
743
                }
 
744
            break;
 
745
 
 
746
        case XP_THEME_ELEMENT_LINE_H:
 
747
            switch (state)
 
748
                {
 
749
                    /* LHS_FLAT, LHS_RAISED, LHS_SUNKEN */
 
750
                    ret = LHS_RAISED;
 
751
                    break;
 
752
                }
 
753
            break;
 
754
 
 
755
        case XP_THEME_ELEMENT_LINE_V:
 
756
            switch (state)
 
757
                {
 
758
                    /* LVS_FLAT, LVS_RAISED, LVS_SUNKEN */
 
759
                    ret = LVS_RAISED;
 
760
                    break;
 
761
                }
 
762
            break;
 
763
 
 
764
        case XP_THEME_ELEMENT_SCALE_TROUGH_H:
 
765
        case XP_THEME_ELEMENT_SCALE_TROUGH_V:
 
766
            ret = TRS_NORMAL;
 
767
            break;
 
768
 
 
769
        default:
 
770
            switch (state)
 
771
                {
 
772
                case GTK_STATE_ACTIVE:
 
773
                    ret = PBS_PRESSED;
 
774
                    break;
 
775
                case GTK_STATE_PRELIGHT:
 
776
                    ret = PBS_HOT;
 
777
                    break;
 
778
                case GTK_STATE_INSENSITIVE:
 
779
                    ret = PBS_DISABLED;
 
780
                    break;
 
781
                default:
 
782
                    ret = PBS_NORMAL;
 
783
                }
 
784
        }
 
785
    return ret;
 
786
}
 
787
 
 
788
gboolean
 
789
xp_theme_draw (GdkWindow * win, XpThemeElement element, GtkStyle * style,
 
790
               int x, int y, int width, int height,
 
791
               GtkStateType state_type, GdkRectangle * area)
 
792
{
 
793
    HTHEME theme;
 
794
    RECT rect, clip, *pClip;
 
795
    int xoff, yoff;
 
796
    HDC dc;
 
797
    GdkDrawable *drawable;
 
798
    int part_state;
 
799
 
 
800
    if (!xp_theme_is_drawable (element))
 
801
        return FALSE;
 
802
 
 
803
    theme = xp_theme_get_handle_by_element (element);
 
804
    if (!theme)
 
805
        return FALSE;
 
806
 
 
807
    /* FIXME: Recheck its function */
 
808
    enable_theme_dialog_texture_func (GDK_WINDOW_HWND (win), ETDT_ENABLETAB);
 
809
 
 
810
    if (!GDK_IS_WINDOW (win))
 
811
        {
 
812
            xoff = 0;
 
813
            yoff = 0;
 
814
            drawable = win;
 
815
        }
 
816
    else
 
817
        {
 
818
            gdk_window_get_internal_paint_info (win, &drawable, &xoff, &yoff);
 
819
        }
 
820
 
 
821
    rect.left = x - xoff;
 
822
    rect.top = y - yoff;
 
823
    rect.right = rect.left + width;
 
824
    rect.bottom = rect.top + height;
 
825
 
 
826
    if (area)
 
827
        {
 
828
            clip.left = area->x - xoff;
 
829
            clip.top = area->y - yoff;
 
830
            clip.right = clip.left + area->width;
 
831
            clip.bottom = clip.top + area->height;
 
832
 
 
833
            pClip = &clip;
 
834
        }
 
835
    else
 
836
        {
 
837
            pClip = NULL;
 
838
        }
 
839
 
 
840
    gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
 
841
    dc = gdk_win32_hdc_get (drawable, style->dark_gc[state_type], 0);
 
842
    if (!dc)
 
843
        return FALSE;
 
844
 
 
845
    part_state = xp_theme_map_gtk_state (element, state_type);
 
846
 
 
847
    draw_theme_background_func (theme, dc, element_part_map[element],
 
848
                                part_state, &rect, pClip);
 
849
    gdk_win32_hdc_release (drawable, style->dark_gc[state_type], 0);
 
850
 
 
851
    return TRUE;
 
852
}
 
853
 
 
854
gboolean
 
855
xp_theme_is_active (void)
 
856
{
 
857
        return use_xp_theme;
 
858
}
 
859
 
 
860
gboolean
 
861
xp_theme_is_drawable (XpThemeElement element)
 
862
{
 
863
    if (xp_theme_is_active ())
 
864
        return (xp_theme_get_handle_by_element (element) != NULL);
 
865
 
 
866
    return FALSE;
 
867
}
 
868
 
 
869
gboolean
 
870
xp_theme_get_system_font (XpThemeClass klazz, XpThemeFont fontId,
 
871
                          OUT LOGFONT * lf)
 
872
{
 
873
    if (xp_theme_is_active () && get_theme_sys_font_func != NULL)
 
874
        {
 
875
            HTHEME theme = xp_theme_get_handle_by_class (klazz);
 
876
            int themeFont;
 
877
 
 
878
            if (!theme)
 
879
                return FALSE;
 
880
 
 
881
            switch (fontId)
 
882
                {
 
883
                case XP_THEME_FONT_CAPTION:
 
884
                    themeFont = TMT_CAPTIONFONT;
 
885
                    break;
 
886
                case XP_THEME_FONT_MENU:
 
887
                    themeFont = TMT_MENUFONT;
 
888
                    break;
 
889
                case XP_THEME_FONT_STATUS:
 
890
                    themeFont = TMT_STATUSFONT;
 
891
                    break;
 
892
                case XP_THEME_FONT_MESSAGE:
 
893
                default:
 
894
                    themeFont = TMT_MSGBOXFONT;
 
895
                    break;
 
896
                }
 
897
            /* if theme is NULL, it will just return the GetSystemFont()
 
898
               value */
 
899
            return ((*get_theme_sys_font_func) (theme, themeFont, lf) ==
 
900
                    S_OK);
 
901
        }
 
902
 
 
903
    return FALSE;
 
904
}
 
905
 
 
906
gboolean
 
907
xp_theme_get_system_color (XpThemeClass klazz, int colorId,
 
908
                           OUT DWORD * pColor)
 
909
{
 
910
    if (xp_theme_is_active () && get_theme_sys_color_func != NULL)
 
911
        {
 
912
            HTHEME theme = xp_theme_get_handle_by_class (klazz);
 
913
 
 
914
            /* if theme is NULL, it will just return the GetSystemColor()
 
915
               value */
 
916
            *pColor = (*get_theme_sys_color_func) (theme, colorId);
 
917
            return TRUE;
 
918
        }
 
919
 
 
920
    return FALSE;
 
921
}
 
922
 
 
923
gboolean
 
924
xp_theme_get_system_metric (XpThemeClass klazz, int metricId, OUT int *pVal)
 
925
{
 
926
    if (xp_theme_is_active () && get_theme_sys_metric_func != NULL)
 
927
        {
 
928
            HTHEME theme = xp_theme_get_handle_by_class (klazz);
 
929
 
 
930
            /* if theme is NULL, it will just return the GetSystemMetrics()
 
931
               value */
 
932
            *pVal = (*get_theme_sys_metric_func) (theme, metricId);
 
933
            return TRUE;
 
934
        }
 
935
 
 
936
    return FALSE;
 
937
}