source: trunk/gcc/libjava/gnu/awt/gtk/gtkcommon.h

Last change on this file was 2, checked in by bird, 22 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 2.1 KB
Line 
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
8This software is copyrighted work licensed under the terms of the
9Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
10details. */
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
20class _Jv_GdkThreadLock
21{
22public:
23 _Jv_GdkThreadLock ()
24 {
25 GDK_THREADS_ENTER ();
26 }
27
28 ~_Jv_GdkThreadLock ()
29 {
30 GDK_THREADS_LEAVE ();
31 }
32};
33
34// Convert AWT Color to gdk color value.
35static inline void
36_Jv_ConvertAwtColor(java::awt::Color* awtcolor, GdkColor* gdkcolor)
37{
38 jint rgb = awtcolor->getRGB();
39 gushort r = (rgb >> 16) & 0xFF;
40 gushort g = (rgb >> 8) & 0xFF;
41 gushort b = rgb & 0xFF;
42
43 gdkcolor->red = (r << 8) + r;
44 gdkcolor->green = (g << 8) + g;
45 gdkcolor->blue = (b << 8) + b;
46
47 // FIXME: Deal with colormap? gdk_color_alloc()?
48}
49
50// Convert gdk color value to AWT Color.
51static inline java::awt::Color*
52_Jv_ConvertGtkColor (GdkColor* gdkcolor)
53{
54 jint r = gdkcolor->red >> 8;
55 jint g = gdkcolor->green >> 8;
56 jint b = gdkcolor->blue >> 8;
57
58 java::awt::Color *c = new java::awt::Color(r,g,b);
59
60 return c;
61}
62
63static inline void
64_Jv_GdkScaleColor (GdkColor* oldc, GdkColor* newc, gfloat scale)
65{
66 // FIXME: Need to deal with overflows or find a better way
67 *newc = *oldc;
68 newc->red += (gushort) (newc->red * scale);
69 newc->green += (gushort) (newc->green * scale);
70 newc->blue += (gushort) (newc->blue * scale);
71}
72
73// Normally the X queue gets flushed automatically when gtk's event loop goes
74// idle. However, some calls do not cause any activitity on the event loop,
75// so we need to occasionally flush pending requests manually because we arn't
76// running from the gtk_main thread. Note that gdk_flush calls XSync(), which
77// is more than what is needed here.
78static inline void
79_Jv_FlushRequests ()
80{
81 // FIXME: What about platforms that arn't X?
82 XFlush (GDK_DISPLAY ());
83}
84
85#endif /* __GTKUTILS_H__ */
Note: See TracBrowser for help on using the repository browser.