OSDN Git Service

2000-10-02 Bryce McKinlay <bryce@albatross.co.nz>
[pf3gnuchains/gcc-fork.git] / libjava / gnu / awt / gtk / gtkcommon.h
1 // -*- c++ -*-
2 // gtkutils.h - Common defines and inline functions for the gtk AWT peers.
3
4 /* Copyright (C) 2000  Free Software Foundation
5
6    This file is part of libgcj.
7
8 This software is copyrighted work licensed under the terms of the
9 Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
10 details.  */
11
12 #ifndef __GTKCOMMON_H__
13 #define __GTKCOMMON_H__
14
15 #include <gtk/gtk.h>
16 #include <gdk/gdkx.h>
17
18 #include <java/awt/Color.h>
19
20 // Convert AWT Color to gdk color value.
21 static inline void 
22 _Jv_ConvertAwtColor(java::awt::Color* awtcolor, GdkColor* gdkcolor)
23 {
24   jint rgb = awtcolor->getRGB();
25   gushort r = (rgb >> 16) & 0xFF;
26   gushort g = (rgb >> 8) & 0xFF;
27   gushort b = rgb & 0xFF;
28   
29   gdkcolor->red = (r << 8) + r;
30   gdkcolor->green = (g << 8) + g;
31   gdkcolor->blue = (b << 8) + b;
32   
33   // FIXME: Deal with colormap? gdk_color_alloc()?
34 }                                   
35
36 // Convert gdk color value to AWT Color.
37 static inline java::awt::Color* 
38 _Jv_ConvertGtkColor (GdkColor* gdkcolor)
39 {
40   jint r = gdkcolor->red >> 8;
41   jint g = gdkcolor->green >> 8;
42   jint b = gdkcolor->blue >> 8;
43
44   java::awt::Color *c = new java::awt::Color(r,g,b);
45   
46   return c;
47 }                                   
48
49 static inline void  
50 _Jv_GdkScaleColor (GdkColor* oldc, GdkColor* newc, gfloat scale)
51 {
52   // FIXME: Need to deal with overflows or find a better way
53   *newc = *oldc;
54   newc->red += (gushort) (newc->red * scale);
55   newc->green += (gushort) (newc->green * scale);
56   newc->blue += (gushort) (newc->blue * scale);
57 }
58
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.
64 static inline void
65 _Jv_FlushRequests ()
66 {
67   // FIXME: What about platforms that arn't X?
68   XFlush (GDK_DISPLAY ());
69 }
70
71 #endif /* __GTKUTILS_H__ */