2 // gtkutils.h - Common defines and inline functions for the gtk AWT peers.
4 /* Copyright (C) 2000 Free Software Foundation
6 This file is part of libgcj.
8 This software is copyrighted work licensed under the terms of the
9 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
12 #ifndef __GTKCOMMON_H__
13 #define __GTKCOMMON_H__
18 #include <java/awt/Color.h>
20 // Convert AWT Color to gdk color value.
22 _Jv_ConvertAwtColor(java::awt::Color* awtcolor, GdkColor* gdkcolor)
24 jint rgb = awtcolor->getRGB();
25 gushort r = (rgb >> 16) & 0xFF;
26 gushort g = (rgb >> 8) & 0xFF;
27 gushort b = rgb & 0xFF;
29 gdkcolor->red = (r << 8) + r;
30 gdkcolor->green = (g << 8) + g;
31 gdkcolor->blue = (b << 8) + b;
33 // FIXME: Deal with colormap? gdk_color_alloc()?
36 // Convert gdk color value to AWT Color.
37 static inline java::awt::Color*
38 _Jv_ConvertGtkColor (GdkColor* gdkcolor)
40 jint r = gdkcolor->red >> 8;
41 jint g = gdkcolor->green >> 8;
42 jint b = gdkcolor->blue >> 8;
44 java::awt::Color *c = new java::awt::Color(r,g,b);
50 _Jv_GdkScaleColor (GdkColor* oldc, GdkColor* newc, gfloat scale)
52 // FIXME: Need to deal with overflows or find a better way
54 newc->red += (gushort) (newc->red * scale);
55 newc->green += (gushort) (newc->green * scale);
56 newc->blue += (gushort) (newc->blue * scale);
59 // Normally the X queue gets flushed automatically when gtk's event loop goes
60 // idle. However, some calls do not cause any activitity on the event loop,
61 // so we need to occasionally flush pending requests manually because we arn't
62 // running from the gtk_main thread. Note that gdk_flush calls XSync(), which
63 // is more than what is needed here.
67 // FIXME: What about platforms that arn't X?
68 XFlush (GDK_DISPLAY ());
71 #endif /* __GTKUTILS_H__ */