diff options
68 files changed, 3611 insertions, 1643 deletions
diff --git a/Makefile.am b/Makefile.am index e07238656e..b518527963 100644 --- a/Makefile.am +++ b/Makefile.am @@ -6,10 +6,12 @@ SUBDIRS = $(SRC_SUBDIRS) docs bin_SCRIPTS = gtk-config EXTRA_DIST = \ - gtk+.prj \ + gtk+.spec \ gtk.m4 \ makecopyright \ TODO \ + NEWS.pre-1-0 \ + ChangeLog.pre-1-0 \ examples/aspectframe/Makefile \ examples/aspectframe/aspectframe.c \ examples/buttons/Makefile \ diff --git a/config.h.in b/config.h.in index 8121d09d14..b105985b05 100644 --- a/config.h.in +++ b/config.h.in @@ -18,25 +18,27 @@ /* Other stuff */ #undef HAVE_IPC_H #undef HAVE_SHM_H -#undef HAVE_XPM #undef HAVE_XSHM_H +#undef HAVE_SHAPE_EXT #undef HAVE_SYS_SELECT_H +/* some systems do not allow to ipcrm pages prior to + * actual usage, namely: OSF1 V3.2, SunOS 4.1.1, 5.5, 5.5.1, 5.6, + * IRIX 5.2 and 6.2. + */ #undef IPC_RMID_DEFERRED_RELEASE #undef NO_FD_SET #undef RESOURCE_BASE +/* Define to enable POSIX threading awareness */ +#undef USE_PTHREADS + #undef XINPUT_NONE #undef XINPUT_GXI #undef XINPUT_XFREE -#undef GTK_MAJOR_VERSION -#undef GTK_MINOR_VERSION -#undef GTK_MICRO_VERSION -#undef GTK_VERSION - /* Define as the return type of signal handlers (int or void). */ #undef RETSIGTYPE diff --git a/configure.in b/configure.in index dcaf862642..74f23e4f61 100644 --- a/configure.in +++ b/configure.in @@ -4,10 +4,35 @@ AC_INIT(gdk/gdktypes.h) # Save this value here, since automake will set cflags later cflags_set=${CFLAGS+set} +# Making releases: +# GTK_MICRO_VERSION += 1; +# GTK_INTERFACE_AGE += 1; +# GTK_BINARY_AGE += 1; +# if any functions have been added, set GTK_INTERFACE_AGE to 0. +# if backwards compatibility has been broken, +# set GTK_BINARY_AGE and GTK_INTERFACE_AGE to 0. +# GTK_MAJOR_VERSION=1 -GTK_MINOR_VERSION=0 +GTK_MINOR_VERSION=1 GTK_MICRO_VERSION=0 +GTK_INTERFACE_AGE=0 +GTK_BINARY_AGE=0 GTK_VERSION=$GTK_MAJOR_VERSION.$GTK_MINOR_VERSION.$GTK_MICRO_VERSION +AC_SUBST(GTK_MAJOR_VERSION) +AC_SUBST(GTK_MINOR_VERSION) +AC_SUBST(GTK_MICRO_VERSION) +AC_SUBST(GTK_VERSION) + +# libtool versioning +LT_RELEASE=$GTK_MAJOR_VERSION.$GTK_MINOR_VERSION +LT_CURRENT=`expr $GTK_MICRO_VERSION - $GTK_INTERFACE_AGE` +LT_REVISION=$GTK_INTERFACE_AGE +LT_AGE=`expr $GTK_BINARY_AGE - $GTK_INTERFACE_AGE` +AC_SUBST(LT_RELEASE) +AC_SUBST(LT_CURRENT) +AC_SUBST(LT_REVISION) +AC_SUBST(LT_AGE) + # For automake. VERSION=$GTK_VERSION @@ -43,9 +68,10 @@ AC_ARG_ENABLE(xim, [ --enable-xim support XIM [default=yes]], AC_ARG_WITH(locale, [ --with-locale=LOCALE locale name you want to use ]) AC_ARG_WITH(xinput, [ --with-xinput=[no/gxi/xfree] support XInput ]) +AC_ARG_WITH(threads, [ --with-threads=[posix] support threading ]) if test "x$enable_debug" = "xyes"; then - test "$cflags_set" = set || CFLAGS="-g" + test "$cflags_set" = set || CFLAGS="$CFLAGS -g" CFLAGS="$CFLAGS -DG_ENABLE_DEBUG" else if test "x$enable_debug" = "xno"; then @@ -80,15 +106,29 @@ if test "x$GCC" = "xyes"; then fi fi +AC_MSG_CHECKING([For extra flags to get ANSI library prototypes]) +gtk_save_LDFLAGS=$LDFLAGS +LIBS="$LIBS -lm" +AC_TRY_RUN([#include <math.h> + int main (void) { return (log(1) != log(1.)); }], + AC_MSG_RESULT(none needed), + gtk_save_CFLAGS=$CFLAGS + CFLAGS="$CFLAGS -std1" + AC_TRY_RUN([#include <math.h> + int main (void) { return (log(1) != log(1.)); }], + AC_MSG_RESULT(-std1), + AC_MSG_RESULT() + CFLAGS=$gtk_save_CFLAGS + AC_MSG_WARN( + [No ANSI prototypes found in library. (-std1 didn't work.)]) + ) +) +LIBS=$gtk_save_LIBS + if test "x$enable_xim" = "xyes"; then CFLAGS="$CFLAGS -DUSE_XIM" fi -AC_DEFINE_UNQUOTED(GTK_MAJOR_VERSION, $GTK_MAJOR_VERSION) -AC_DEFINE_UNQUOTED(GTK_MINOR_VERSION, $GTK_MINOR_VERSION) -AC_DEFINE_UNQUOTED(GTK_MICRO_VERSION, $GTK_MICRO_VERSION) -AC_DEFINE_UNQUOTED(GTK_VERSION, "$GTK_VERSION") - # Find the X11 include and library directories AC_PATH_X AC_PATH_XTRA @@ -118,6 +158,16 @@ if test "x$enable_shm" = "xyes"; then $x_libs) fi +# Check for shaped window extension + +AC_CHECK_LIB(Xext, XShapeCombineMask, + if test -z "`echo $x_libs | grep "\-lXext" 2> /dev/null`"; then + $x_libs="-lXext $x_libs" + fi + AC_DEFINE(HAVE_SHAPE_EXT), + , + $x_libs) + x_cflags="$X_CFLAGS" x_ldflags="$X_LDFLAGS $X_LIBS" @@ -134,12 +184,20 @@ else AC_DEFINE(XINPUT_NONE) fi +# Threads + +if test "x$with_threads" = "xposix" || test "x$with_threads" = "xyes"; then + AC_CHECK_LIB(pthread, pthread_create, + AC_DEFINE(USE_PTHREADS) + x_libs="$x_libs -lpthread" + CFLAGS="$CFLAGS -D_REENTRANT") +fi + AC_SUBST(x_cflags) AC_SUBST(x_includes) AC_SUBST(x_ldflags) AC_SUBST(x_libs) AC_SUBST(xinput_progs) -AC_SUBST(GTK_VERSION) CFLAGS="$saved_cflags" LDFLAGS="$saved_ldflags" @@ -265,5 +323,11 @@ if test $gtk_ok = no; then AC_DEFINE(NO_FD_SET) fi -AC_OUTPUT([Makefile gtk-config docs/Makefile gdk/Makefile gtk/Makefile], - [chmod +x gtk-config]) +AC_OUTPUT([ +Makefile +gtk-config +docs/Makefile +gdk/Makefile +gtk/Makefile +gtk/gtkfeatures.h +], [chmod +x gtk-config]) diff --git a/gdk/Makefile.am b/gdk/Makefile.am index 1013fc2346..634e6a9160 100644 --- a/gdk/Makefile.am +++ b/gdk/Makefile.am @@ -2,9 +2,9 @@ gdkincludedir = $(includedir)/gdk -lib_LTLIBRARIES = libgdk.la +lib_LTLIBRARIES = libgdk-1.1.la -libgdk_la_SOURCES = \ +libgdk_1_1_la_SOURCES = \ gdk.c \ gdkcc.c \ gdkcolor.c \ @@ -26,6 +26,7 @@ libgdk_la_SOURCES = \ gdkrectangle.c \ gdkregion.c \ gdkselection.c \ + gdkthreads.c \ gdkvisual.c \ gdkwindow.c \ gdkxid.c \ @@ -46,7 +47,8 @@ gdkinclude_HEADERS = \ gdktypes.h \ gdkx.h -libgdk_la_LDFLAGS = -version-info 1:0:0 \ +libgdk_1_1_la_LDFLAGS = \ + -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \ @x_ldflags@ @x_libs@ INCLUDES = -I$(top_srcdir) -I../glib -I$(top_srcdir)/glib @x_cflags@ @@ -78,5 +80,3 @@ files: @files=`ls $(DISTFILES) 2> /dev/null `; for p in $$files; do \ echo $$p; \ done - -$(DEP_FILES) : $(BUILT_SOURCES) @@ -51,8 +51,8 @@ #include "gdkinput.h" #ifdef USE_XIM #include "gdkx.h" -#include "gdkkeysyms.h" #endif +#include "gdkkeysyms.h" #include "gdki18n.h" #ifndef X_GETTIMEOFDAY @@ -625,7 +625,7 @@ gdk_exit (int errorcode) */ gchar* -gdk_set_locale () +gdk_set_locale (void) { if (!setlocale (LC_ALL,"")) g_print ("locale not supported by C library\n"); @@ -663,7 +663,7 @@ gdk_set_locale () */ gint -gdk_events_pending () +gdk_events_pending (void) { gint result; GList *tmp_list; @@ -1023,13 +1023,13 @@ gdk_set_use_xshm (gint use_xshm) } gint -gdk_get_show_events () +gdk_get_show_events (void) { return gdk_debug_flags & GDK_DEBUG_EVENTS; } gint -gdk_get_use_xshm () +gdk_get_use_xshm (void) { return gdk_use_xshm; } @@ -1055,7 +1055,7 @@ gdk_get_use_xshm () */ guint32 -gdk_time_get () +gdk_time_get (void) { struct timeval end; struct timeval elapsed; @@ -1094,7 +1094,7 @@ gdk_time_get () */ guint32 -gdk_timer_get () +gdk_timer_get (void) { return timer_val; } @@ -1129,13 +1129,13 @@ gdk_timer_set (guint32 milliseconds) } void -gdk_timer_enable () +gdk_timer_enable (void) { timerp = &timer; } void -gdk_timer_disable () +gdk_timer_disable (void) { timerp = NULL; } @@ -1463,7 +1463,7 @@ gdk_keyboard_ungrab (guint32 time) */ gint -gdk_screen_width () +gdk_screen_width (void) { gint return_val; @@ -1488,7 +1488,7 @@ gdk_screen_width () */ gint -gdk_screen_height () +gdk_screen_height (void) { gint return_val; @@ -1498,13 +1498,13 @@ gdk_screen_height () } void -gdk_key_repeat_disable () +gdk_key_repeat_disable (void) { XAutoRepeatOff (gdk_display); } void -gdk_key_repeat_restore () +gdk_key_repeat_restore (void) { if (autorepeat) XAutoRepeatOn (gdk_display); @@ -1531,14 +1531,14 @@ gdk_key_repeat_restore () *-------------------------------------------------------------- */ -void gdk_flush () +void gdk_flush (void) { XSync (gdk_display, False); } void -gdk_beep () +gdk_beep (void) { XBell(gdk_display, 100); } @@ -1562,7 +1562,7 @@ gdk_beep () */ static gint -gdk_event_wait () +gdk_event_wait (void) { GList *list; GdkInput *input; @@ -1606,8 +1606,31 @@ gdk_event_wait () max_input = MAX (max_input, input->source); } +#ifdef USE_PTHREADS + if (gdk_using_threads) + { + gdk_select_waiting = TRUE; + + FD_SET (gdk_threads_pipe[0], &readfds); + max_input = MAX (max_input, gdk_threads_pipe[0]); + gdk_threads_leave (); + } +#endif + nfd = select (max_input+1, &readfds, &writefds, &exceptfds, timerp); +#ifdef USE_PTHREADS + if (gdk_using_threads) + { + gchar c; + gdk_threads_enter (); + gdk_select_waiting = FALSE; + + if (FD_ISSET (gdk_threads_pipe[0], &readfds)) + read (gdk_threads_pipe[0], &c, 1); + } +#endif + timerp = NULL; timer_val = 0; @@ -1685,7 +1708,8 @@ gdk_event_translate (GdkEvent *event, GdkWindow *window; GdkWindowPrivate *window_private; - XComposeStatus compose; + static XComposeStatus compose; + KeySym keysym; int charcount; #ifdef USE_XIM static gchar* buf = NULL; @@ -1767,16 +1791,16 @@ gdk_event_translate (GdkEvent *event, buf_len = 128; buf = g_new (gchar, buf_len); } + keysym = GDK_VoidSymbol; + if (xim_using == TRUE && xim_ic) { Status status; /* Clear keyval. Depending on status, may not be set */ - event->key.keyval = GDK_VoidSymbol; charcount = XmbLookupString(xim_ic->xic, &xevent->xkey, buf, buf_len-1, - (KeySym*) &event->key.keyval, - &status); + &keysym, &status); if (status == XBufferOverflow) { /* retry */ /* alloc adequate size of buffer */ @@ -1789,8 +1813,7 @@ gdk_event_translate (GdkEvent *event, charcount = XmbLookupString (xim_ic->xic, &xevent->xkey, buf, buf_len-1, - (KeySym*) &event->key.keyval, - &status); + &keysym, &status); } if (status == XLookupNone) { @@ -1800,13 +1823,13 @@ gdk_event_translate (GdkEvent *event, } else charcount = XLookupString (&xevent->xkey, buf, buf_len, - (KeySym*) &event->key.keyval, - &compose); + &keysym, &compose); #else charcount = XLookupString (&xevent->xkey, buf, 16, - (KeySym*) &event->key.keyval, - &compose); + &keysym, &compose); #endif + event->key.keyval = keysym; + if (charcount > 0 && buf[charcount-1] == '\0') charcount --; else @@ -1844,9 +1867,10 @@ gdk_event_translate (GdkEvent *event, case KeyRelease: /* Lookup the string corresponding to the given keysym. */ + keysym = GDK_VoidSymbol; charcount = XLookupString (&xevent->xkey, buf, 16, - (KeySym*) &event->key.keyval, - &compose); + &keysym, &compose); + event->key.keyval = keysym; /* Print debugging info. */ @@ -1964,7 +1988,7 @@ gdk_event_translate (GdkEvent *event, window_private->dnd_drag_savedeventmask = dnd_winattr.your_event_mask; dnd_setwinattr.event_mask = window_private->dnd_drag_eventmask = ButtonMotionMask | ButtonPressMask | ButtonReleaseMask | - EnterWindowMask | LeaveWindowMask; + EnterWindowMask | LeaveWindowMask | ExposureMask; XChangeWindowAttributes(gdk_display, window_private->xwindow, CWEventMask, &dnd_setwinattr); } @@ -2333,7 +2357,7 @@ gdk_event_translate (GdkEvent *event, ButtonMotionMask | PointerMotionMask | /* PointerMotionHintMask | */ /* HINTME */ ButtonPressMask | ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, gdk_root_window, + GrabModeAsync, GrabModeAsync, None, None, CurrentTime); #ifdef G_ENABLE_DEBUG GDK_NOTE(DND, g_print("xgpret = %d\n", xgpret)); @@ -3028,7 +3052,7 @@ gdk_synthesize_click (GdkEvent *event, */ static void -gdk_exit_func () +gdk_exit_func (void) { static gboolean in_gdk_exit_func = FALSE; @@ -4004,8 +4028,8 @@ gdk_dnd_check_types (GdkWindow *window, if (realfmt != (sizeof(Atom) * 8)) { - g_warning("XdeTypelist property had format of %d instead of the expected %d, on window %#lx\n", - realfmt, sizeof(Atom) * 8, xevent->xclient.data.l[0]); + g_warning("XdeTypelist property had format of %d instead of the expected %ld, on window %#lx\n", + realfmt, (glong)sizeof(Atom) * 8, xevent->xclient.data.l[0]); return 0; } @@ -299,6 +299,8 @@ void gdk_window_set_decorations (GdkWindow *window, GdkWMDecoration decorations); void gdk_window_set_functions (GdkWindow *window, GdkWMFunction functions); +GList * gdk_window_get_toplevels (void); + /* Cursors */ @@ -358,6 +360,10 @@ void gdk_gc_set_line_attributes (GdkGC *gc, GdkLineStyle line_style, GdkCapStyle cap_style, GdkJoinStyle join_style); +void gdk_gc_set_dashes (GdkGC *gc, + gint dash_offset, + gchar dash_list[], + gint n); void gdk_gc_copy (GdkGC *dst_gc, GdkGC *src_gc); @@ -795,6 +801,14 @@ GdkRegion* gdk_regions_subtract (GdkRegion *source1, GdkRegion* gdk_regions_xor (GdkRegion *source1, GdkRegion *source2); +gboolean gdk_threads_init (void); +void gdk_threads_enter (void); +void gdk_threads_leave (void); + +/* If the mainloop thread is in its select, wake it up. + * For GTK's idle handling + */ +void gdk_threads_wake (void); #ifdef __cplusplus } diff --git a/gdk/gdkdnd.c b/gdk/gdkdnd.c index 2dca54a8b7..6a74022c55 100644 --- a/gdk/gdkdnd.c +++ b/gdk/gdkdnd.c @@ -60,11 +60,11 @@ gdk_dnd_set_drag_shape(GdkWindow *default_pixmapwin, gdk_window_ref(default_pixmapwin); gdk_dnd.c->drag_pm_default = default_pixmapwin; gdk_dnd.c->default_hotspot = *default_hotspot; - gdk_dnd.c->xids = g_list_append(gdk_dnd.c->xids, (gpointer)(glong)((GdkWindowPrivate *)default_pixmapwin)->xwindow); + gdk_dnd.c->xids = g_list_append(gdk_dnd.c->xids, GUINT_TO_POINTER (((GdkWindowPrivate *)default_pixmapwin)->xwindow)); if(goahead_pixmapwin) { gdk_window_ref(goahead_pixmapwin); - gdk_dnd.c->xids = g_list_append(gdk_dnd.c->xids, (gpointer)(glong)((GdkWindowPrivate *)goahead_pixmapwin)->xwindow); + gdk_dnd.c->xids = g_list_append(gdk_dnd.c->xids, GUINT_TO_POINTER (((GdkWindowPrivate *)goahead_pixmapwin)->xwindow)); gdk_dnd.c->drag_pm_ok = goahead_pixmapwin; gdk_dnd.c->ok_hotspot = *goahead_hotspot; } diff --git a/gdk/gdkgc.c b/gdk/gdkgc.c index 8ffce9e478..932a9606c1 100644 --- a/gdk/gdkgc.c +++ b/gdk/gdkgc.c @@ -88,6 +88,18 @@ gdk_gc_new_with_values (GdkWindow *window, case GDK_XOR: xvalues.function = GXxor; break; + case GDK_OR: + xvalues.function = GXor; + break; + case GDK_AND: + xvalues.function = GXand; + break; + case GDK_NOR: + xvalues.function = GXnor; + break; + case GDK_NAND: + xvalues.function = GXnand; + break; } xvalues_mask |= GCFunction; } @@ -703,6 +715,22 @@ gdk_gc_set_line_attributes (GdkGC *gc, } void +gdk_gc_set_dashes (GdkGC *gc, + gint dash_offset, + gchar dash_list[], + gint n) +{ + GdkGCPrivate *private; + + g_return_if_fail (gc != NULL); + g_return_if_fail (dash_list != NULL); + + private = (GdkGCPrivate*) gc; + + XSetDashes (private->xdisplay, private->xgc, dash_offset, dash_list, n); +} + +void gdk_gc_copy (GdkGC *dst_gc, GdkGC *src_gc) { GdkGCPrivate *dst_private, *src_private; diff --git a/gdk/gdkglobals.c b/gdk/gdkglobals.c index 6e34bfa883..82b67a823f 100644 --- a/gdk/gdkglobals.c +++ b/gdk/gdkglobals.c @@ -20,6 +20,7 @@ #include <X11/Xlib.h> #include "gdktypes.h" #include "gdkprivate.h" +#include "../config.h" guint gdk_debug_flags = 0; gint gdk_use_xshm = TRUE; @@ -53,3 +54,13 @@ gint gdk_error_code; gint gdk_error_warnings = TRUE; gint gdk_null_window_warnings = TRUE; GList *gdk_default_filters = NULL; + +gboolean gdk_using_threads = FALSE; + +/* Used to signal the mainloop thread from its select() */ +#ifdef USE_PTHREADS +gint gdk_threads_pipe[2]; +gboolean gdk_select_waiting = FALSE; +#endif + + diff --git a/gdk/gdkimage.c b/gdk/gdkimage.c index 82c5421227..c31ab4e5be 100644 --- a/gdk/gdkimage.c +++ b/gdk/gdkimage.c @@ -64,7 +64,7 @@ static GList *image_list = NULL; void -gdk_image_exit () +gdk_image_exit (void) { GdkImage *image; @@ -131,7 +131,7 @@ gdk_image_check_xshm(Display *display) } void -gdk_image_init () +gdk_image_init (void) { if (gdk_use_xshm) { diff --git a/gdk/gdkinput.c b/gdk/gdkinput.c index e47f2205ff..491131ca27 100644 --- a/gdk/gdkinput.c +++ b/gdk/gdkinput.c @@ -70,7 +70,7 @@ static GList *gdk_input_windows; #include "gdkinputgxi.h" GList * -gdk_input_list_devices () +gdk_input_list_devices (void) { return gdk_input_devices; } diff --git a/gdk/gdkinputnone.h b/gdk/gdkinputnone.h index 44bd8d0378..aa0cc0b0bc 100644 --- a/gdk/gdkinputnone.h +++ b/gdk/gdkinputnone.h @@ -29,7 +29,7 @@ static void gdk_input_none_get_pointer (GdkWindow *window, GdkModifierType *mask); void -gdk_input_init () +gdk_input_init (void) { gdk_input_vtable.set_mode = NULL; gdk_input_vtable.set_axes = NULL; diff --git a/gdk/gdkinputxfree.h b/gdk/gdkinputxfree.h index efc728cb0b..c0411a4fea 100644 --- a/gdk/gdkinputxfree.h +++ b/gdk/gdkinputxfree.h @@ -22,7 +22,7 @@ /* forward declarations */ static gint gdk_input_xfree_set_mode (guint32 deviceid, GdkInputMode mode); -static void gdk_input_check_proximity(); +static void gdk_input_check_proximity (void); static void gdk_input_xfree_configure_event (XConfigureEvent *xevent, GdkWindow *window); static void gdk_input_xfree_enter_event (XCrossingEvent *xevent, @@ -115,7 +115,7 @@ gdk_input_xfree_set_mode (guint32 deviceid, GdkInputMode mode) } static void -gdk_input_check_proximity() +gdk_input_check_proximity (void) { gint new_proximity = 0; GList *tmp_list = gdk_input_devices; diff --git a/gdk/gdkkeysyms.h b/gdk/gdkkeysyms.h index 0ef07706f8..cc3ed517e6 100644 --- a/gdk/gdkkeysyms.h +++ b/gdk/gdkkeysyms.h @@ -1,21 +1,3 @@ -/* GDK - The GIMP Drawing Kit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ #define GDK_VoidSymbol 0xFFFFFF #define GDK_BackSpace 0xFF08 #define GDK_Tab 0xFF09 @@ -28,6 +10,9 @@ #define GDK_Escape 0xFF1B #define GDK_Delete 0xFFFF #define GDK_Multi_key 0xFF20 +#define GDK_SingleCandidate 0xFF3C +#define GDK_MultipleCandidate 0xFF3D +#define GDK_PreviousCandidate 0xFF3E #define GDK_Kanji 0xFF21 #define GDK_Muhenkan 0xFF22 #define GDK_Henkan_Mode 0xFF23 @@ -45,6 +30,8 @@ #define GDK_Kana_Shift 0xFF2E #define GDK_Eisu_Shift 0xFF2F #define GDK_Eisu_toggle 0xFF30 +#define GDK_Zen_Koho 0xFF3D +#define GDK_Mae_Koho 0xFF3E #define GDK_Home 0xFF50 #define GDK_Left 0xFF51 #define GDK_Up 0xFF52 @@ -234,11 +221,23 @@ #define GDK_dead_iota 0xFE5D #define GDK_dead_voiced_sound 0xFE5E #define GDK_dead_semivoiced_sound 0xFE5F +#define GDK_dead_belowdot 0xFE60 #define GDK_First_Virtual_Screen 0xFED0 #define GDK_Prev_Virtual_Screen 0xFED1 #define GDK_Next_Virtual_Screen 0xFED2 #define GDK_Last_Virtual_Screen 0xFED4 #define GDK_Terminate_Server 0xFED5 +#define GDK_AccessX_Enable 0xFE70 +#define GDK_AccessX_Feedback_Enable 0xFE71 +#define GDK_RepeatKeys_Enable 0xFE72 +#define GDK_SlowKeys_Enable 0xFE73 +#define GDK_BounceKeys_Enable 0xFE74 +#define GDK_StickyKeys_Enable 0xFE75 +#define GDK_MouseKeys_Enable 0xFE76 +#define GDK_MouseKeys_Accel_Enable 0xFE77 +#define GDK_Overlay1_Enable 0xFE78 +#define GDK_Overlay2_Enable 0xFE79 +#define GDK_AudibleBell_Enable 0xFE7A #define GDK_Pointer_Left 0xFEE0 #define GDK_Pointer_Right 0xFEE1 #define GDK_Pointer_Up 0xFEE2 @@ -264,6 +263,7 @@ #define GDK_Pointer_Drag2 0xFEF6 #define GDK_Pointer_Drag3 0xFEF7 #define GDK_Pointer_Drag4 0xFEF8 +#define GDK_Pointer_Drag5 0xFEFD #define GDK_Pointer_EnableKeys 0xFEF9 #define GDK_Pointer_Accelerate 0xFEFA #define GDK_Pointer_DfltBtnNext 0xFEFB diff --git a/gdk/gdkpixmap.c b/gdk/gdkpixmap.c index 5cbca00c57..7ba8727885 100644 --- a/gdk/gdkpixmap.c +++ b/gdk/gdkpixmap.c @@ -55,7 +55,7 @@ gdk_pixmap_new (GdkWindow *window, return NULL; if (depth == -1) - gdk_window_get_geometry (window, NULL, NULL, NULL, NULL, &depth); + depth = gdk_window_get_visual (window)->depth; private = g_new (GdkWindowPrivate, 1); pixmap = (GdkPixmap*) private; @@ -64,6 +64,7 @@ gdk_pixmap_new (GdkWindow *window, private->window_type = GDK_WINDOW_PIXMAP; private->xwindow = XCreatePixmap (private->xdisplay, window_private->xwindow, width, height, depth); + private->colormap = NULL; private->parent = NULL; private->x = 0; private->y = 0; @@ -148,7 +149,7 @@ gdk_pixmap_create_from_data (GdkWindow *window, return NULL; if (depth == -1) - gdk_window_get_geometry (window, NULL, NULL, NULL, NULL, &depth); + depth = gdk_window_get_visual (window)->depth; private = g_new (GdkWindowPrivate, 1); pixmap = (GdkPixmap*) private; @@ -236,12 +237,15 @@ gdk_pixmap_read_string (FILE *infile, guint *buffer_size) { gint c; - guint cnt = 0; + guint cnt = 0, bufsiz, ret = FALSE; + gchar *buf; - if ((*buffer) == NULL) + buf = *buffer; + bufsiz = *buffer_size; + if (buf == NULL) { - (*buffer_size) = 10 * sizeof (gchar); - (*buffer) = g_new(gchar, *buffer_size); + bufsiz = 10 * sizeof (gchar); + buf = g_new(gchar, bufsiz); } do @@ -249,25 +253,37 @@ gdk_pixmap_read_string (FILE *infile, while (c != EOF && c != '"'); if (c != '"') - return FALSE; + goto out; while ((c = getc(infile)) != EOF) { - if (cnt == (*buffer_size)) + if (cnt == bufsiz) { - (*buffer_size) *= 2; - (*buffer) = (gchar *) g_realloc ((*buffer), *buffer_size); } + guint new_size = bufsiz * 2; + if (new_size > bufsiz) + bufsiz = new_size; + else + goto out; + + buf = (gchar *) g_realloc (buf, bufsiz); + buf[bufsiz-1] = '\0'; + } if (c != '"') - (*buffer)[cnt++] = c; + buf[cnt++] = c; else { - (*buffer)[cnt++] = 0; - return TRUE; + buf[cnt] = 0; + ret = TRUE; + break; } } - return FALSE; + out: + buf[bufsiz-1] = '\0'; /* ensure null termination for errors */ + *buffer = buf; + *buffer_size = bufsiz; + return ret; } gchar* @@ -292,12 +308,16 @@ gdk_pixmap_skip_string (gchar *buffer) return &buffer[index]; } +/* Xlib crashed ince at a color name lengths around 125 */ +#define MAX_COLOR_LEN 120 + gchar* gdk_pixmap_extract_color (gchar *buffer) { - gint counter, finished = FALSE, numnames; + gint counter, numnames; gchar *ptr = NULL, ch, temp[128]; - gchar color[128], *retcol; + gchar color[MAX_COLOR_LEN], *retcol; + gint space; counter = 0; while (ptr == NULL) @@ -314,9 +334,6 @@ gdk_pixmap_extract_color (gchar *buffer) counter++; } - if (ptr == NULL) - return NULL; - ptr = gdk_pixmap_skip_whitespaces (ptr); if (ptr[0] == 0) @@ -330,18 +347,26 @@ gdk_pixmap_extract_color (gchar *buffer) color[0] = 0; numnames = 0; - while (finished == FALSE) + space = MAX_COLOR_LEN - 1; + while (space > 0) { sscanf (ptr, "%127s", temp); - if ((gint)ptr[0] == 0 || strcmp ("s", temp) == 0 || strcmp ("m", temp) == 0 || - strcmp ("g", temp) == 0 || strcmp ("g4", temp) == 0) - finished = TRUE; + if (((gint)ptr[0] == 0) || + (strcmp ("s", temp) == 0) || (strcmp ("m", temp) == 0) || + (strcmp ("g", temp) == 0) || (strcmp ("g4", temp) == 0)) + { + break; + } else { if (numnames > 0) - strcat (color, " "); - strcat (color, temp); + { + space -= 1; + strcat (color, " "); + } + strncat (color, temp, space); + space -= MIN (space, strlen (temp)); ptr = gdk_pixmap_skip_string (ptr); ptr = gdk_pixmap_skip_whitespaces (ptr); numnames++; @@ -352,216 +377,48 @@ gdk_pixmap_extract_color (gchar *buffer) return retcol; } - -GdkPixmap* -gdk_pixmap_colormap_create_from_xpm (GdkWindow *window, - GdkColormap *colormap, - GdkBitmap **mask, - GdkColor *transparent_color, - const gchar *filename) +static void +free_color (gpointer key, gpointer value, gpointer user_data) { - FILE *infile = NULL; - GdkPixmap *pixmap = NULL; - GdkImage *image = NULL; - GdkVisual *visual; - GdkGC *gc; - GdkColor tmp_color; - gint width, height, num_cols, cpp, cnt, n, ns, xcnt, ycnt; - gchar *buffer = NULL, pixel_str[32]; - guint buffer_size = 0; - _GdkPixmapColor *colors = NULL, *color = NULL; - gulong index; - - if ((window == NULL) && (colormap == NULL)) - g_warning ("Creating pixmap from xpm with NULL window and colormap"); - - if (window == NULL) - window = (GdkWindow *)&gdk_root_parent; - - if (colormap == NULL) - { - colormap = gdk_window_get_colormap (window); - visual = gdk_window_get_visual (window); - } - else - visual = ((GdkColormapPrivate *)colormap)->visual; - - infile = fopen (filename, "rb"); - if (infile != NULL) - { - if (gdk_pixmap_seek_string (infile, "XPM", FALSE) == TRUE) - { - if (gdk_pixmap_seek_char (infile,'{') == TRUE) - { - gdk_pixmap_seek_char (infile, '"'); - fseek (infile, -1, SEEK_CUR); - gdk_pixmap_read_string (infile, &buffer, &buffer_size); - - sscanf (buffer,"%d %d %d %d", &width, &height, &num_cols, &cpp); - - colors = g_new(_GdkPixmapColor, num_cols); - - if (transparent_color == NULL) - { - gdk_color_white (colormap, &tmp_color); - transparent_color = &tmp_color; - } - - for (cnt = 0; cnt < num_cols; cnt++) - { - gchar *color_name; - - gdk_pixmap_seek_char (infile, '"'); - fseek (infile, -1, SEEK_CUR); - gdk_pixmap_read_string (infile, &buffer, &buffer_size); - - colors[cnt].color_string = g_new(gchar, cpp + 1); - for (n = 0; n < cpp; n++) - colors[cnt].color_string[n] = buffer[n]; - colors[cnt].color_string[n] = 0; - colors[cnt].transparent = FALSE; - - color_name = gdk_pixmap_extract_color (&buffer[cpp]); - - if (color_name != NULL) - { - if (gdk_color_parse (color_name, &colors[cnt].color) == FALSE) - { - colors[cnt].color = *transparent_color; - colors[cnt].transparent = TRUE; - } - } - else - { - colors[cnt].color = *transparent_color; - colors[cnt].transparent = TRUE; - } - - g_free (color_name); - - gdk_color_alloc (colormap, &colors[cnt].color); - } - - index = 0; - image = gdk_image_new (GDK_IMAGE_FASTEST, visual, width, height); - - gc = NULL; - if (mask) - { - /* The pixmap mask is just a bits pattern. - * Color 0 is used for background and 1 for foreground. - * We don't care about the colormap, we just need 0 and 1. - */ - GdkColor mask_pattern; - - *mask = gdk_pixmap_new (window, width, height, 1); - gc = gdk_gc_new (*mask); - - mask_pattern.pixel = 0; - gdk_gc_set_foreground (gc, &mask_pattern); - gdk_draw_rectangle (*mask, gc, TRUE, 0, 0, -1, -1); - - mask_pattern.pixel = 1; - gdk_gc_set_foreground (gc, &mask_pattern); - } - - for (ycnt = 0; ycnt < height; ycnt++) - { - gdk_pixmap_read_string (infile, &buffer, &buffer_size); - - for (n = 0, cnt = 0, xcnt = 0; n < (width * cpp); n += cpp, xcnt++) - { - strncpy (pixel_str, &buffer[n], cpp); - pixel_str[cpp] = 0; - color = NULL; - ns = 0; - - while ((color == NULL) && (ns < num_cols)) - { - if (strcmp (pixel_str, colors[ns].color_string) == 0) - color = &colors[ns]; - else - ns++; - } - - if (!color) /* screwed up XPM file */ - color = &colors[0]; - - gdk_image_put_pixel (image, xcnt, ycnt, color->color.pixel); - - if (mask && color->transparent) - { - if (cnt < xcnt) - gdk_draw_line (*mask, gc, cnt, ycnt, xcnt - 1, ycnt); - cnt = xcnt + 1; - } - } - - if (mask && (cnt < xcnt)) - gdk_draw_line (*mask, gc, cnt, ycnt, xcnt - 1, ycnt); - } - - if (mask) - gdk_gc_destroy (gc); - - pixmap = gdk_pixmap_new (window, width, height, visual->depth); - - gc = gdk_gc_new (pixmap); - gdk_gc_set_foreground (gc, transparent_color); - gdk_draw_image (pixmap, gc, image, 0, 0, 0, 0, image->width, image->height); - gdk_gc_destroy (gc); - gdk_image_destroy (image); - } - } - - fclose (infile); - free (buffer); - - if (colors != NULL) - { - for (cnt = 0; cnt < num_cols; cnt++) - g_free (colors[cnt].color_string); - g_free (colors); - } - } - - return pixmap; + g_free (key); + g_free (value); } + -GdkPixmap* -gdk_pixmap_create_from_xpm (GdkWindow *window, - GdkBitmap **mask, - GdkColor *transparent_color, - const gchar *filename) +enum buffer_op { - return gdk_pixmap_colormap_create_from_xpm (window, NULL, mask, - transparent_color, filename); -} - - -GdkPixmap* -gdk_pixmap_colormap_create_from_xpm_d (GdkWindow *window, - GdkColormap *colormap, - GdkBitmap **mask, - GdkColor *transparent_color, - gchar **data) + op_header, + op_cmap, + op_body +}; + + +static GdkPixmap * +_gdk_pixmap_create_from_xpm (GdkWindow *window, + GdkColormap *colormap, + GdkBitmap **mask, + GdkColor *transparent_color, + gchar * (*get_buf) (enum buffer_op op, + gpointer handle), + gpointer handle) { GdkPixmap *pixmap = NULL; GdkImage *image = NULL; GdkVisual *visual; - GdkGC *gc; + GdkGC *gc = NULL; GdkColor tmp_color; - gint width, height, num_cols, cpp, cnt, n, ns, xcnt, ycnt, i; + gint width, height, num_cols, cpp, n, ns, cnt, xcnt, ycnt, wbytes; gchar *buffer, pixel_str[32]; - _GdkPixmapColor *colors = NULL, *color = NULL; + _GdkPixmapColor *color = NULL, *fallbackcolor = NULL; gulong index; - + GHashTable *colors = NULL; + if ((window == NULL) && (colormap == NULL)) g_warning ("Creating pixmap from xpm with NULL window and colormap"); - + if (window == NULL) window = (GdkWindow *)&gdk_root_parent; - + if (colormap == NULL) { colormap = gdk_window_get_colormap (window); @@ -569,56 +426,63 @@ gdk_pixmap_colormap_create_from_xpm_d (GdkWindow *window, } else visual = ((GdkColormapPrivate *)colormap)->visual; - - i = 0; - buffer = data[i++]; + + buffer = (*get_buf) (op_header, handle); + if (buffer == NULL) + return NULL; + sscanf (buffer,"%d %d %d %d", &width, &height, &num_cols, &cpp); - - colors = g_new(_GdkPixmapColor, num_cols); - - if (transparent_color == NULL) + if (cpp >= 32) + { + g_warning ("Pixmap has more than 31 characters per color\n"); + return NULL; + } + + colors = g_hash_table_new (g_str_hash, g_str_equal); + + if (transparent_color == NULL) { gdk_color_white (colormap, &tmp_color); transparent_color = &tmp_color; } - + for (cnt = 0; cnt < num_cols; cnt++) { gchar *color_name; - - buffer = data[i++]; - - colors[cnt].color_string = g_new(gchar, cpp + 1); - for (n = 0; n < cpp; n++) - colors[cnt].color_string[n] = buffer[n]; - colors[cnt].color_string[n] = 0; - colors[cnt].transparent = FALSE; - - color_name = gdk_pixmap_extract_color (&buffer[cpp]); - - if (color_name != NULL) - { - if (gdk_color_parse (color_name, &colors[cnt].color) == FALSE) - { - colors[cnt].color = *transparent_color; - colors[cnt].transparent = TRUE; - } - } - else + + buffer = (*get_buf) (op_cmap, handle); + if (buffer == NULL) + goto error; + + color = g_new (_GdkPixmapColor, 1); + color->color_string = g_new (gchar, cpp + 1); + strncpy (color->color_string, buffer, cpp); + color->color_string[cpp] = 0; + buffer += strlen (color->color_string); + color->transparent = FALSE; + + color_name = gdk_pixmap_extract_color (buffer); + + if (color_name == NULL || + gdk_color_parse (color_name, &color->color) == FALSE) { - colors[cnt].color = *transparent_color; - colors[cnt].transparent = TRUE; + color->color = *transparent_color; + color->transparent = TRUE; } - + g_free (color_name); - - gdk_color_alloc (colormap, &colors[cnt].color); + + /* FIXME: The remaining slowness appears to happen in this + function. */ + gdk_color_alloc (colormap, &color->color); + g_hash_table_insert (colors, color->color_string, color); + if (cnt == 0) + fallbackcolor = color; } - + index = 0; image = gdk_image_new (GDK_IMAGE_FASTEST, visual, width, height); - - gc = NULL; + if (mask) { /* The pixmap mask is just a bits pattern. @@ -626,42 +490,43 @@ gdk_pixmap_colormap_create_from_xpm_d (GdkWindow *window, * We don't care about the colormap, we just need 0 and 1. */ GdkColor mask_pattern; - + *mask = gdk_pixmap_new (window, width, height, 1); gc = gdk_gc_new (*mask); - + mask_pattern.pixel = 0; gdk_gc_set_foreground (gc, &mask_pattern); gdk_draw_rectangle (*mask, gc, TRUE, 0, 0, -1, -1); - + mask_pattern.pixel = 1; gdk_gc_set_foreground (gc, &mask_pattern); } - + + wbytes = width * cpp; for (ycnt = 0; ycnt < height; ycnt++) { - buffer = data[i++]; - - for (n = 0, cnt = 0, xcnt = 0; n < (width * cpp); n += cpp, xcnt++) + buffer = (*get_buf) (op_body, handle); + + /* FIXME: this slows things down a little - it could be + * integrated into the strncpy below, perhaps. OTOH, strlen + * is fast. + */ + if ((buffer == NULL) || strlen (buffer) < wbytes) + continue; + + for (n = 0, cnt = 0, xcnt = 0; n < wbytes; n += cpp, xcnt++) { strncpy (pixel_str, &buffer[n], cpp); pixel_str[cpp] = 0; - color = NULL; ns = 0; - - while ((color == NULL) && (ns < num_cols)) - { - if (strcmp (pixel_str, colors[ns].color_string) == 0) - color = &colors[ns]; - else - ns++; - } - + + color = g_hash_table_lookup (colors, pixel_str); + if (!color) /* screwed up XPM file */ - color = &colors[0]; - + color = fallbackcolor; + gdk_image_put_pixel (image, xcnt, ycnt, color->color.pixel); - + if (mask && color->transparent) { if (cnt < xcnt) @@ -669,33 +534,151 @@ gdk_pixmap_colormap_create_from_xpm_d (GdkWindow *window, cnt = xcnt + 1; } } - + if (mask && (cnt < xcnt)) gdk_draw_line (*mask, gc, cnt, ycnt, xcnt - 1, ycnt); } - + + error: + if (mask) gdk_gc_destroy (gc); + + if (image != NULL) + { + pixmap = gdk_pixmap_new (window, width, height, visual->depth); + + gc = gdk_gc_new (pixmap); + gdk_gc_set_foreground (gc, transparent_color); + gdk_draw_image (pixmap, gc, image, 0, 0, 0, 0, image->width, image->height); + gdk_gc_destroy (gc); + gdk_image_destroy (image); + } + + if (colors != NULL) + { + g_hash_table_foreach (colors, free_color, 0); + g_hash_table_destroy (colors); + } + + return pixmap; +} - pixmap = gdk_pixmap_new (window, width, height, visual->depth); - gc = gdk_gc_new (pixmap); - gdk_gc_set_foreground (gc, transparent_color); - gdk_draw_image (pixmap, gc, image, 0, 0, 0, 0, image->width, image->height); - gdk_gc_destroy (gc); - gdk_image_destroy (image); +struct file_handle +{ + FILE *infile; + gchar *buffer; + guint buffer_size; +}; - if (colors != NULL) + +static gchar * +file_buffer (enum buffer_op op, gpointer handle) +{ + struct file_handle *h = handle; + + switch (op) + { + case op_header: + if (gdk_pixmap_seek_string (h->infile, "XPM", FALSE) != TRUE) + break; + + if (gdk_pixmap_seek_char (h->infile,'{') != TRUE) + break; + /* Fall through to the next gdk_pixmap_seek_char. */ + + case op_cmap: + gdk_pixmap_seek_char (h->infile, '"'); + fseek (h->infile, -1, SEEK_CUR); + /* Fall through to the gdk_pixmap_read_string. */ + + case op_body: + gdk_pixmap_read_string (h->infile, &h->buffer, &h->buffer_size); + return h->buffer; + } + return 0; +} + + +GdkPixmap* +gdk_pixmap_colormap_create_from_xpm (GdkWindow *window, + GdkColormap *colormap, + GdkBitmap **mask, + GdkColor *transparent_color, + const gchar *filename) +{ + struct file_handle h; + GdkPixmap *pixmap = NULL; + + memset (&h, 0, sizeof (h)); + h.infile = fopen (filename, "rb"); + if (h.infile != NULL) { - for (cnt = 0; cnt < num_cols; cnt++) - g_free (colors[cnt].color_string); - g_free (colors); + pixmap = _gdk_pixmap_create_from_xpm (window, colormap, mask, + transparent_color, + file_buffer, &h); + fclose (h.infile); + g_free (h.buffer); } return pixmap; } GdkPixmap* +gdk_pixmap_create_from_xpm (GdkWindow *window, + GdkBitmap **mask, + GdkColor *transparent_color, + const gchar *filename) +{ + return gdk_pixmap_colormap_create_from_xpm (window, NULL, mask, + transparent_color, filename); +} + + +struct mem_handle +{ + gchar **data; + int offset; +}; + + +static gchar * +mem_buffer (enum buffer_op op, gpointer handle) +{ + struct mem_handle *h = handle; + switch (op) + { + case op_header: + case op_cmap: + case op_body: + if (h->data[h->offset]) + return h->data[h->offset ++]; + } + return 0; +} + + +GdkPixmap* +gdk_pixmap_colormap_create_from_xpm_d (GdkWindow *window, + GdkColormap *colormap, + GdkBitmap **mask, + GdkColor *transparent_color, + gchar **data) +{ + struct mem_handle h; + GdkPixmap *pixmap = NULL; + + memset (&h, 0, sizeof (h)); + h.data = data; + pixmap = _gdk_pixmap_create_from_xpm (window, colormap, mask, + transparent_color, + mem_buffer, &h); + return pixmap; +} + + +GdkPixmap* gdk_pixmap_create_from_xpm_d (GdkWindow *window, GdkBitmap **mask, GdkColor *transparent_color, diff --git a/gdk/gdkprivate.h b/gdk/gdkprivate.h index 2749d5ff49..fcfca025bf 100644 --- a/gdk/gdkprivate.h +++ b/gdk/gdkprivate.h @@ -81,6 +81,8 @@ struct _GdkWindowPrivate gint extension_events; GList *filters; + GdkColormap *colormap; + GList *children; }; struct _GdkImagePrivate @@ -266,6 +268,13 @@ extern gint gdk_error_code; extern gint gdk_error_warnings; extern gint gdk_null_window_warnings; extern GList *gdk_default_filters; +extern gboolean gdk_using_threads; + +/* Threading stuff */ +#ifdef USE_PTHREADS +extern gint gdk_threads_pipe[2]; +extern gboolean gdk_select_waiting; +#endif /* Debugging support */ diff --git a/gdk/gdkregion.c b/gdk/gdkregion.c index 6034bbae86..4b5c1c866c 100644 --- a/gdk/gdkregion.c +++ b/gdk/gdkregion.c @@ -127,7 +127,7 @@ gdk_region_polygon (GdkPoint *points, GdkRegionPrivate *private; GdkRegion *region; Region xregion; - int xfill_rule; + gint xfill_rule = EvenOddRule; g_return_val_if_fail (points != NULL, NULL); g_return_val_if_fail (npoints != 0, NULL); /* maybe we should check for at least three points */ diff --git a/gdk/gdktypes.h b/gdk/gdktypes.h index 9ff8c1312e..311f07762c 100644 --- a/gdk/gdktypes.h +++ b/gdk/gdktypes.h @@ -220,9 +220,13 @@ typedef enum */ typedef enum { - GDK_COPY, - GDK_INVERT, - GDK_XOR + GDK_COPY, + GDK_INVERT, + GDK_XOR, + GDK_OR, + GDK_AND, + GDK_NOR, + GDK_NAND } GdkFunction; /* GC fill types. diff --git a/gdk/gdkvisual.c b/gdk/gdkvisual.c index 90ca5cfe78..a6a8b2b134 100644 --- a/gdk/gdkvisual.c +++ b/gdk/gdkvisual.c @@ -58,7 +58,7 @@ static gchar* visual_names[] = static GHashTable *visual_hash = NULL; void -gdk_visual_init () +gdk_visual_init (void) { static gint possible_depths[6] = { 32, 24, 16, 15, 8, 1 }; static GdkVisualType possible_types[6] = @@ -263,25 +263,25 @@ gdk_visual_unref (GdkVisual *visual) } gint -gdk_visual_get_best_depth () +gdk_visual_get_best_depth (void) { return available_depths[0]; } GdkVisualType -gdk_visual_get_best_type () +gdk_visual_get_best_type (void) { return available_types[0]; } GdkVisual* -gdk_visual_get_system () +gdk_visual_get_system (void) { return ((GdkVisual*) system_visual); } GdkVisual* -gdk_visual_get_best () +gdk_visual_get_best (void) { return ((GdkVisual*) &(visuals[0])); } diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c index 4edb1ead66..21b10590d0 100644 --- a/gdk/gdkwindow.c +++ b/gdk/gdkwindow.c @@ -20,7 +20,6 @@ #include <X11/Xlib.h> #include <X11/Xutil.h> #include <X11/Xatom.h> -#include <X11/extensions/shape.h> #include <netinet/in.h> #include "gdk.h" #include "../config.h" @@ -30,6 +29,10 @@ #include <stdlib.h> #include <stdio.h> +#ifdef HAVE_SHAPE_EXT +#include <X11/extensions/shape.h> +#endif + int nevent_masks = 17; int event_mask_table[19] = { @@ -65,18 +68,18 @@ gdk_window_xid_at(Window base, gint bx, gint by, gint x, gint y, Display *disp; Window *list=NULL; Window child=0,parent_win=0,root_win=0; + int i; - guint num; + unsigned int ww, wh, wb, wd, num; int wx,wy; - guint ww,wh,wb,wd; - + window=(GdkWindow*)&gdk_root_parent; private=(GdkWindowPrivate*)window; disp=private->xdisplay; if (!XGetGeometry(disp,base,&root_win,&wx,&wy,&ww,&wh,&wb,&wd)) return 0; wx+=bx;wy+=by; - if (!((x>=wx)&&(y>=wy)&&(x<(wx+ww))&&(y<(wy+wh)))) + if (!((x>=wx)&&(y>=wy)&&(x<(int)(wx+ww))&&(y<(int)(wy+wh)))) return 0; if (!XQueryTree(disp,base,&root_win,&parent_win,&list,&num)) return base; @@ -172,7 +175,7 @@ gdk_window_xid_at_coords(gint x, gint y, GList *excludes, gboolean excl_child) } void -gdk_window_init () +gdk_window_init (void) { XWindowAttributes xattributes; unsigned int width; @@ -191,6 +194,8 @@ gdk_window_init () gdk_root_parent.window.user_data = NULL; gdk_root_parent.width = width; gdk_root_parent.height = height; + gdk_root_parent.children = NULL; + gdk_root_parent.colormap = NULL; } GdkWindow* @@ -202,7 +207,6 @@ gdk_window_new (GdkWindow *parent, GdkWindowPrivate *private; GdkWindowPrivate *parent_private; GdkVisual *visual; - GdkColormap *colormap; Display *parent_display; Window xparent; Visual *xvisual; @@ -232,6 +236,10 @@ gdk_window_new (GdkWindow *parent, window = (GdkWindow*) private; private->parent = parent; + + if (parent_private) + parent_private->children = g_list_prepend (parent_private->children, window); + private->xdisplay = parent_display; private->destroyed = FALSE; private->resize_count = 0; @@ -264,6 +272,7 @@ gdk_window_new (GdkWindow *parent, private->dnd_drag_eventmask = private->dnd_drag_savedeventmask = 0; private->filters = NULL; + private->children = NULL; window->user_data = NULL; @@ -296,9 +305,9 @@ gdk_window_new (GdkWindow *parent, depth = visual->depth; if (attributes_mask & GDK_WA_COLORMAP) - colormap = attributes->colormap; + private->colormap = attributes->colormap; else - colormap = gdk_colormap_get_system (); + private->colormap = gdk_colormap_get_system (); xattributes.background_pixel = BlackPixel (gdk_display, gdk_screen); xattributes.border_pixel = BlackPixel (gdk_display, gdk_screen); @@ -307,26 +316,26 @@ gdk_window_new (GdkWindow *parent, switch (private->window_type) { case GDK_WINDOW_TOPLEVEL: - xattributes.colormap = ((GdkColormapPrivate*) colormap)->xcolormap; + xattributes.colormap = ((GdkColormapPrivate*) private->colormap)->xcolormap; xattributes_mask |= CWColormap; xparent = gdk_root_window; break; case GDK_WINDOW_CHILD: - xattributes.colormap = ((GdkColormapPrivate*) colormap)->xcolormap; + xattributes.colormap = ((GdkColormapPrivate*) private->colormap)->xcolormap; xattributes_mask |= CWColormap; break; case GDK_WINDOW_DIALOG: - xattributes.colormap = ((GdkColormapPrivate*) colormap)->xcolormap; + xattributes.colormap = ((GdkColormapPrivate*) private->colormap)->xcolormap; xattributes_mask |= CWColormap; xparent = gdk_root_window; break; case GDK_WINDOW_TEMP: - xattributes.colormap = ((GdkColormapPrivate*) colormap)->xcolormap; + xattributes.colormap = ((GdkColormapPrivate*) private->colormap)->xcolormap; xattributes_mask |= CWColormap; xparent = gdk_root_window; @@ -348,7 +357,7 @@ gdk_window_new (GdkWindow *parent, { depth = 0; class = InputOnly; - colormap = NULL; + private->colormap = NULL; } private->xwindow = XCreateWindow (private->xdisplay, xparent, @@ -358,6 +367,9 @@ gdk_window_new (GdkWindow *parent, gdk_window_ref (window); gdk_xid_table_insert (&private->xwindow, window); + if (private->colormap) + gdk_colormap_ref (private->colormap); + gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ? (attributes->cursor) : NULL)); @@ -372,8 +384,8 @@ gdk_window_new (GdkWindow *parent, break; case GDK_WINDOW_CHILD: if ((attributes->wclass == GDK_INPUT_OUTPUT) && - (colormap != gdk_colormap_get_system ()) && - (colormap != gdk_window_get_colormap (gdk_window_get_toplevel (window)))) + (private->colormap != gdk_colormap_get_system ()) && + (private->colormap != gdk_window_get_colormap (gdk_window_get_toplevel (window)))) { GDK_NOTE (MISC, g_print ("adding colormap window\n")); gdk_window_add_colormap_windows (window); @@ -430,6 +442,7 @@ gdk_window_foreign_new (guint32 anid) { GdkWindow *window; GdkWindowPrivate *private; + GdkWindowPrivate *parent_private; XWindowAttributes attrs; Window root, parent; Window *children; @@ -446,6 +459,11 @@ gdk_window_foreign_new (guint32 anid) XFree (children); private->parent = gdk_xid_table_lookup (parent); + parent_private = (GdkWindowPrivate *)private->parent; + + if (parent_private) + parent_private->children = g_list_prepend (parent_private->children, window); + private->xwindow = anid; private->xdisplay = gdk_display; private->x = attrs.x; @@ -458,6 +476,7 @@ gdk_window_foreign_new (guint32 anid) private->destroyed = FALSE; private->extension_events = 0; + private->colormap = NULL; private->dnd_drag_data_type = None; private->dnd_drag_data_typesavail = @@ -469,6 +488,7 @@ gdk_window_foreign_new (guint32 anid) private->dnd_drag_eventmask = private->dnd_drag_savedeventmask = 0; private->filters = NULL; + private->children = NULL; window->user_data = NULL; @@ -507,10 +527,17 @@ gdk_window_internal_destroy (GdkWindow *window, gboolean xdestroy, case GDK_WINDOW_FOREIGN: if (!private->destroyed) { + if (private->parent) + { + GdkWindowPrivate *parent_private = (GdkWindowPrivate *)private->parent; + if (parent_private->children) + parent_private->children = g_list_remove (parent_private->children, window); + } + if (private->window_type != GDK_WINDOW_FOREIGN) { - children = gdk_window_get_children (window); - tmp = children; + children = tmp = private->children; + private->children = NULL; while (tmp) { @@ -522,7 +549,7 @@ gdk_window_internal_destroy (GdkWindow *window, gboolean xdestroy, gdk_window_internal_destroy (temp_window, FALSE, our_destroy); } - + g_list_free (children); } @@ -581,6 +608,9 @@ gdk_window_internal_destroy (GdkWindow *window, gboolean xdestroy, else if (xdestroy) XDestroyWindow (private->xdisplay, private->xwindow); + if (private->colormap) + gdk_colormap_unref (private->colormap); + private->destroyed = TRUE; } break; @@ -1059,6 +1089,11 @@ gdk_window_set_colormap (GdkWindow *window, XSetWindowColormap (window_private->xdisplay, window_private->xwindow, colormap_private->xcolormap); + + if (window_private->colormap) + gdk_colormap_unref (window_private->colormap); + window_private->colormap = colormap; + gdk_colormap_ref (window_private->colormap); if (window_private->window_type != GDK_WINDOW_TOPLEVEL) gdk_window_add_colormap_windows (window); @@ -1153,20 +1188,27 @@ gdk_window_get_visual (GdkWindow *window) { GdkWindowPrivate *window_private; XWindowAttributes window_attributes; - + g_return_val_if_fail (window != NULL, NULL); - + window_private = (GdkWindowPrivate*) window; + /* Huh? ->parent is never set for a pixmap. We should just return + * null immeditately + */ while (window_private && (window_private->window_type == GDK_WINDOW_PIXMAP)) window_private = (GdkWindowPrivate*) window_private->parent; if (window_private && !window_private->destroyed) { - XGetWindowAttributes (window_private->xdisplay, - window_private->xwindow, - &window_attributes); - - return gdk_visual_lookup (window_attributes.visual); + if (window_private->colormap == NULL) + { + XGetWindowAttributes (window_private->xdisplay, + window_private->xwindow, + &window_attributes); + return gdk_visual_lookup (window_attributes.visual); + } + else + return ((GdkColormapPrivate *)window_private->colormap)->visual; } return NULL; @@ -1179,16 +1221,20 @@ gdk_window_get_colormap (GdkWindow *window) XWindowAttributes window_attributes; g_return_val_if_fail (window != NULL, NULL); - window_private = (GdkWindowPrivate*) window; - + + g_return_val_if_fail (window_private->window_type != GDK_WINDOW_PIXMAP, NULL); if (!window_private->destroyed) { - XGetWindowAttributes (window_private->xdisplay, - window_private->xwindow, - &window_attributes); - - return gdk_colormap_lookup (window_attributes.colormap); + if (window_private->colormap == NULL) + { + XGetWindowAttributes (window_private->xdisplay, + window_private->xwindow, + &window_attributes); + return gdk_colormap_lookup (window_attributes.colormap); + } + else + return window_private->colormap; } return NULL; @@ -1436,8 +1482,7 @@ gdk_window_add_colormap_windows (GdkWindow *window) /* * This needs the X11 shape extension. - * If not available, simply remove the call to - * XShapeCombineMask. Shaped windows will look + * If not available, shaped windows will look * ugly, but programs still work. Stefan Wille */ void @@ -1445,38 +1490,53 @@ gdk_window_shape_combine_mask (GdkWindow *window, GdkBitmap *mask, gint x, gint y) { + enum { UNKNOWN, NO, YES }; + + static gint have_shape = UNKNOWN; + GdkWindowPrivate *window_private; Pixmap pixmap; g_return_if_fail (window != NULL); - /* This is needed, according to raster */ - gdk_window_set_override_redirect(window, TRUE); - - window_private = (GdkWindowPrivate*) window; - if (window_private->destroyed) - return; - - if (mask) +#ifdef HAVE_SHAPE_EXT + if (have_shape == UNKNOWN) { - GdkWindowPrivate *pixmap_private; - - pixmap_private = (GdkWindowPrivate*) mask; - pixmap = (Pixmap) pixmap_private->xwindow; + int ignore; + if (XQueryExtension(gdk_display, "SHAPE", &ignore, &ignore, &ignore)) + have_shape = YES; + else + have_shape = NO; } - else + + if (have_shape == YES) { - x = 0; - y = 0; - pixmap = None; + window_private = (GdkWindowPrivate*) window; + if (window_private->destroyed) + return; + + if (mask) + { + GdkWindowPrivate *pixmap_private; + + pixmap_private = (GdkWindowPrivate*) mask; + pixmap = (Pixmap) pixmap_private->xwindow; + } + else + { + x = 0; + y = 0; + pixmap = None; + } + + XShapeCombineMask (window_private->xdisplay, + window_private->xwindow, + ShapeBounding, + x, y, + pixmap, + ShapeSet); } - - XShapeCombineMask (window_private->xdisplay, - window_private->xwindow, - ShapeBounding, - x, y, - pixmap, - ShapeSet); +#endif /* HAVE_SHAPE_EXT */ } void @@ -1915,3 +1975,20 @@ gdk_window_set_functions (GdkWindow *window, gdk_window_set_mwm_hints (window, &hints); } + +GList * +gdk_window_get_toplevels (void) +{ + GList *new_list = NULL; + GList *tmp_list; + + tmp_list = gdk_root_parent.children; + while (tmp_list) + { + new_list = g_list_prepend (new_list, tmp_list->data); + tmp_list = tmp_list->next; + } + + return new_list; +} + diff --git a/gdk/gxid.c b/gdk/gxid.c index 219c08bfe0..40b48fa31c 100644 --- a/gdk/gxid.c +++ b/gdk/gxid.c @@ -61,7 +61,7 @@ handler(int signal) } void -init_socket() +init_socket(void) { struct sockaddr_in sin; @@ -130,7 +130,7 @@ enable_device(GxidDevice *dev) /* switch the core pointer from whatever it is now to something else, return true on success, false otherwise */ static int -switch_core_pointer() +switch_core_pointer(void) { GxidDevice *old_pointer = 0; GxidDevice *new_pointer = 0; @@ -222,7 +222,7 @@ init_device(XDeviceInfo *xdevice) } void -init_xinput() +init_xinput(void) { char **extensions; XDeviceInfo *xdevices; @@ -279,12 +279,22 @@ int handle_claim_device(GxidClaimDevice *msg) { int i,j; - XID devid = ntohl(msg->device); - XID winid = ntohl(msg->window); - int exclusive = ntohl(msg->exclusive); + XID devid; + XID winid; + int exclusive; GxidDevice *device = NULL; GxidWindow *window = NULL; + if (msg->length != sizeof(GxidClaimDevice)) + { + fprintf(stderr,"Bad length for ClaimDevice message\n"); + return GXID_RETURN_ERROR; + } + + devid = ntohl(msg->device); + winid = ntohl(msg->window); + exclusive = ntohl(msg->exclusive); + #ifdef DEBUG_CLIENTS fprintf(stderr,"device %ld claimed (window 0x%lx)\n",devid,winid); #endif @@ -397,11 +407,20 @@ int handle_release_device(GxidReleaseDevice *msg) { int i,j; - XID devid = ntohl(msg->device); - XID winid = ntohl(msg->window); + XID devid; + XID winid; GxidDevice *device = NULL; + if (msg->length != sizeof(GxidReleaseDevice)) + { + fprintf(stderr,"Bad length for ReleaseDevice message\n"); + return GXID_RETURN_ERROR; + } + + devid = ntohl(msg->device); + winid = ntohl(msg->window); + #ifdef DEBUG_CLIENTS fprintf(stderr,"device %ld released (window 0x%lx)\n",devid,winid); #endif @@ -460,11 +479,11 @@ handle_release_device(GxidReleaseDevice *msg) } void -handle_connection() +handle_connection (void) { GxidMessage msg; GxidU32 type; - int length; + GxidU32 length; GxidI32 retval; int conn_fd; @@ -496,7 +515,7 @@ handle_connection() /* read rest of message */ - if (length > sizeof(GxidMessage)) + if ((length > sizeof(GxidMessage)) || (length < 2*sizeof(GxidU32))) { fprintf(stderr,"%s: Bad message length\n", program_name); @@ -689,7 +708,7 @@ handle_destroy_notify(XDestroyWindowEvent *event) } void -handle_xevent() +handle_xevent(void) { int i; XEvent event; @@ -743,7 +762,7 @@ handle_xevent() } void -usage() +usage(void) { fprintf(stderr,"Usage: %s [-d display] [-p --gxid-port port]\n", program_name); @@ -833,7 +852,7 @@ main(int argc, char **argv) } if (FD_ISSET(socket_fd,&readfds)) - handle_connection(socket_fd); + handle_connection(); while (XPending(dpy)) handle_xevent(); diff --git a/gdk/x11/gdkdnd-x11.c b/gdk/x11/gdkdnd-x11.c index 2dca54a8b7..6a74022c55 100644 --- a/gdk/x11/gdkdnd-x11.c +++ b/gdk/x11/gdkdnd-x11.c @@ -60,11 +60,11 @@ gdk_dnd_set_drag_shape(GdkWindow *default_pixmapwin, gdk_window_ref(default_pixmapwin); gdk_dnd.c->drag_pm_default = default_pixmapwin; gdk_dnd.c->default_hotspot = *default_hotspot; - gdk_dnd.c->xids = g_list_append(gdk_dnd.c->xids, (gpointer)(glong)((GdkWindowPrivate *)default_pixmapwin)->xwindow); + gdk_dnd.c->xids = g_list_append(gdk_dnd.c->xids, GUINT_TO_POINTER (((GdkWindowPrivate *)default_pixmapwin)->xwindow)); if(goahead_pixmapwin) { gdk_window_ref(goahead_pixmapwin); - gdk_dnd.c->xids = g_list_append(gdk_dnd.c->xids, (gpointer)(glong)((GdkWindowPrivate *)goahead_pixmapwin)->xwindow); + gdk_dnd.c->xids = g_list_append(gdk_dnd.c->xids, GUINT_TO_POINTER (((GdkWindowPrivate *)goahead_pixmapwin)->xwindow)); gdk_dnd.c->drag_pm_ok = goahead_pixmapwin; gdk_dnd.c->ok_hotspot = *goahead_hotspot; } diff --git a/gdk/x11/gdkglobals-x11.c b/gdk/x11/gdkglobals-x11.c index 6e34bfa883..82b67a823f 100644 --- a/gdk/x11/gdkglobals-x11.c +++ b/gdk/x11/gdkglobals-x11.c @@ -20,6 +20,7 @@ #include <X11/Xlib.h> #include "gdktypes.h" #include "gdkprivate.h" +#include "../config.h" guint gdk_debug_flags = 0; gint gdk_use_xshm = TRUE; @@ -53,3 +54,13 @@ gint gdk_error_code; gint gdk_error_warnings = TRUE; gint gdk_null_window_warnings = TRUE; GList *gdk_default_filters = NULL; + +gboolean gdk_using_threads = FALSE; + +/* Used to signal the mainloop thread from its select() */ +#ifdef USE_PTHREADS +gint gdk_threads_pipe[2]; +gboolean gdk_select_waiting = FALSE; +#endif + + diff --git a/gdk/x11/gdkimage-x11.c b/gdk/x11/gdkimage-x11.c index 82c5421227..c31ab4e5be 100644 --- a/gdk/x11/gdkimage-x11.c +++ b/gdk/x11/gdkimage-x11.c @@ -64,7 +64,7 @@ static GList *image_list = NULL; void -gdk_image_exit () +gdk_image_exit (void) { GdkImage *image; @@ -131,7 +131,7 @@ gdk_image_check_xshm(Display *display) } void -gdk_image_init () +gdk_image_init (void) { if (gdk_use_xshm) { diff --git a/gdk/x11/gdkinput-none.c b/gdk/x11/gdkinput-none.c index 44bd8d0378..aa0cc0b0bc 100644 --- a/gdk/x11/gdkinput-none.c +++ b/gdk/x11/gdkinput-none.c @@ -29,7 +29,7 @@ static void gdk_input_none_get_pointer (GdkWindow *window, GdkModifierType *mask); void -gdk_input_init () +gdk_input_init (void) { gdk_input_vtable.set_mode = NULL; gdk_input_vtable.set_axes = NULL; diff --git a/gdk/x11/gdkinput-xfree.c b/gdk/x11/gdkinput-xfree.c index efc728cb0b..c0411a4fea 100644 --- a/gdk/x11/gdkinput-xfree.c +++ b/gdk/x11/gdkinput-xfree.c @@ -22,7 +22,7 @@ /* forward declarations */ static gint gdk_input_xfree_set_mode (guint32 deviceid, GdkInputMode mode); -static void gdk_input_check_proximity(); +static void gdk_input_check_proximity (void); static void gdk_input_xfree_configure_event (XConfigureEvent *xevent, GdkWindow *window); static void gdk_input_xfree_enter_event (XCrossingEvent *xevent, @@ -115,7 +115,7 @@ gdk_input_xfree_set_mode (guint32 deviceid, GdkInputMode mode) } static void -gdk_input_check_proximity() +gdk_input_check_proximity (void) { gint new_proximity = 0; GList *tmp_list = gdk_input_devices; diff --git a/gdk/x11/gdkinput.c b/gdk/x11/gdkinput.c index e47f2205ff..491131ca27 100644 --- a/gdk/x11/gdkinput.c +++ b/gdk/x11/gdkinput.c @@ -70,7 +70,7 @@ static GList *gdk_input_windows; #include "gdkinputgxi.h" GList * -gdk_input_list_devices () +gdk_input_list_devices (void) { return gdk_input_devices; } diff --git a/gdk/x11/gdkmain-x11.c b/gdk/x11/gdkmain-x11.c index b2cdb5d2d6..eeefa4f1be 100644 --- a/gdk/x11/gdkmain-x11.c +++ b/gdk/x11/gdkmain-x11.c @@ -51,8 +51,8 @@ #include "gdkinput.h" #ifdef USE_XIM #include "gdkx.h" -#include "gdkkeysyms.h" #endif +#include "gdkkeysyms.h" #include "gdki18n.h" #ifndef X_GETTIMEOFDAY @@ -625,7 +625,7 @@ gdk_exit (int errorcode) */ gchar* -gdk_set_locale () +gdk_set_locale (void) { if (!setlocale (LC_ALL,"")) g_print ("locale not supported by C library\n"); @@ -663,7 +663,7 @@ gdk_set_locale () */ gint -gdk_events_pending () +gdk_events_pending (void) { gint result; GList *tmp_list; @@ -1023,13 +1023,13 @@ gdk_set_use_xshm (gint use_xshm) } gint -gdk_get_show_events () +gdk_get_show_events (void) { return gdk_debug_flags & GDK_DEBUG_EVENTS; } gint -gdk_get_use_xshm () +gdk_get_use_xshm (void) { return gdk_use_xshm; } @@ -1055,7 +1055,7 @@ gdk_get_use_xshm () */ guint32 -gdk_time_get () +gdk_time_get (void) { struct timeval end; struct timeval elapsed; @@ -1094,7 +1094,7 @@ gdk_time_get () */ guint32 -gdk_timer_get () +gdk_timer_get (void) { return timer_val; } @@ -1129,13 +1129,13 @@ gdk_timer_set (guint32 milliseconds) } void -gdk_timer_enable () +gdk_timer_enable (void) { timerp = &timer; } void -gdk_timer_disable () +gdk_timer_disable (void) { timerp = NULL; } @@ -1463,7 +1463,7 @@ gdk_keyboard_ungrab (guint32 time) */ gint -gdk_screen_width () +gdk_screen_width (void) { gint return_val; @@ -1488,7 +1488,7 @@ gdk_screen_width () */ gint -gdk_screen_height () +gdk_screen_height (void) { gint return_val; @@ -1498,13 +1498,13 @@ gdk_screen_height () } void -gdk_key_repeat_disable () +gdk_key_repeat_disable (void) { XAutoRepeatOff (gdk_display); } void -gdk_key_repeat_restore () +gdk_key_repeat_restore (void) { if (autorepeat) XAutoRepeatOn (gdk_display); @@ -1531,14 +1531,14 @@ gdk_key_repeat_restore () *-------------------------------------------------------------- */ -void gdk_flush () +void gdk_flush (void) { XSync (gdk_display, False); } void -gdk_beep () +gdk_beep (void) { XBell(gdk_display, 100); } @@ -1562,7 +1562,7 @@ gdk_beep () */ static gint -gdk_event_wait () +gdk_event_wait (void) { GList *list; GdkInput *input; @@ -1606,8 +1606,31 @@ gdk_event_wait () max_input = MAX (max_input, input->source); } +#ifdef USE_PTHREADS + if (gdk_using_threads) + { + gdk_select_waiting = TRUE; + + FD_SET (gdk_threads_pipe[0], &readfds); + max_input = MAX (max_input, gdk_threads_pipe[0]); + gdk_threads_leave (); + } +#endif + nfd = select (max_input+1, &readfds, &writefds, &exceptfds, timerp); +#ifdef USE_PTHREADS + if (gdk_using_threads) + { + gchar c; + gdk_threads_enter (); + gdk_select_waiting = FALSE; + + if (FD_ISSET (gdk_threads_pipe[0], &readfds)) + read (gdk_threads_pipe[0], &c, 1); + } +#endif + timerp = NULL; timer_val = 0; @@ -1685,7 +1708,8 @@ gdk_event_translate (GdkEvent *event, GdkWindow *window; GdkWindowPrivate *window_private; - XComposeStatus compose; + static XComposeStatus compose; + KeySym keysym; int charcount; #ifdef USE_XIM static gchar* buf = NULL; @@ -1767,16 +1791,16 @@ gdk_event_translate (GdkEvent *event, buf_len = 128; buf = g_new (gchar, buf_len); } + keysym = GDK_VoidSymbol; + if (xim_using == TRUE && xim_ic) { Status status; /* Clear keyval. Depending on status, may not be set */ - event->key.keyval = GDK_VoidSymbol; charcount = XmbLookupString(xim_ic->xic, &xevent->xkey, buf, buf_len-1, - (KeySym*) &event->key.keyval, - &status); + &keysym, &status); if (status == XBufferOverflow) { /* retry */ /* alloc adequate size of buffer */ @@ -1789,8 +1813,7 @@ gdk_event_translate (GdkEvent *event, charcount = XmbLookupString (xim_ic->xic, &xevent->xkey, buf, buf_len-1, - (KeySym*) &event->key.keyval, - &status); + &keysym, &status); } if (status == XLookupNone) { @@ -1800,13 +1823,13 @@ gdk_event_translate (GdkEvent *event, } else charcount = XLookupString (&xevent->xkey, buf, buf_len, - (KeySym*) &event->key.keyval, - &compose); + &keysym, &compose); #else charcount = XLookupString (&xevent->xkey, buf, 16, - (KeySym*) &event->key.keyval, - &compose); + &keysym, &compose); #endif + event->key.keyval = keysym; + if (charcount > 0 && buf[charcount-1] == '\0') charcount --; else @@ -1844,9 +1867,10 @@ gdk_event_translate (GdkEvent *event, case KeyRelease: /* Lookup the string corresponding to the given keysym. */ + keysym = GDK_VoidSymbol; charcount = XLookupString (&xevent->xkey, buf, 16, - (KeySym*) &event->key.keyval, - &compose); + &keysym, &compose); + event->key.keyval = keysym; /* Print debugging info. */ @@ -1964,7 +1988,7 @@ gdk_event_translate (GdkEvent *event, window_private->dnd_drag_savedeventmask = dnd_winattr.your_event_mask; dnd_setwinattr.event_mask = window_private->dnd_drag_eventmask = ButtonMotionMask | ButtonPressMask | ButtonReleaseMask | - EnterWindowMask | LeaveWindowMask; + EnterWindowMask | LeaveWindowMask | ExposureMask; XChangeWindowAttributes(gdk_display, window_private->xwindow, CWEventMask, &dnd_setwinattr); } @@ -2333,7 +2357,7 @@ gdk_event_translate (GdkEvent *event, ButtonMotionMask | PointerMotionMask | /* PointerMotionHintMask | */ /* HINTME */ ButtonPressMask | ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, gdk_root_window, + GrabModeAsync, GrabModeAsync, None, None, CurrentTime); #ifdef G_ENABLE_DEBUG GDK_NOTE(DND, g_print("xgpret = %d\n", xgpret)); @@ -3028,7 +3052,7 @@ gdk_synthesize_click (GdkEvent *event, */ static void -gdk_exit_func () +gdk_exit_func (void) { static gboolean in_gdk_exit_func = FALSE; @@ -4004,8 +4028,8 @@ gdk_dnd_check_types (GdkWindow *window, if (realfmt != (sizeof(Atom) * 8)) { - g_warning("XdeTypelist property had format of %d instead of the expected %d, on window %#lx\n", - realfmt, sizeof(Atom) * 8, xevent->xclient.data.l[0]); + g_warning("XdeTypelist property had format of %d instead of the expected %ld, on window %#lx\n", + realfmt, (glong)sizeof(Atom) * 8, xevent->xclient.data.l[0]); return 0; } diff --git a/gdk/x11/gdkpixmap-x11.c b/gdk/x11/gdkpixmap-x11.c index 5cbca00c57..7ba8727885 100644 --- a/gdk/x11/gdkpixmap-x11.c +++ b/gdk/x11/gdkpixmap-x11.c @@ -55,7 +55,7 @@ gdk_pixmap_new (GdkWindow *window, return NULL; if (depth == -1) - gdk_window_get_geometry (window, NULL, NULL, NULL, NULL, &depth); + depth = gdk_window_get_visual (window)->depth; private = g_new (GdkWindowPrivate, 1); pixmap = (GdkPixmap*) private; @@ -64,6 +64,7 @@ gdk_pixmap_new (GdkWindow *window, private->window_type = GDK_WINDOW_PIXMAP; private->xwindow = XCreatePixmap (private->xdisplay, window_private->xwindow, width, height, depth); + private->colormap = NULL; private->parent = NULL; private->x = 0; private->y = 0; @@ -148,7 +149,7 @@ gdk_pixmap_create_from_data (GdkWindow *window, return NULL; if (depth == -1) - gdk_window_get_geometry (window, NULL, NULL, NULL, NULL, &depth); + depth = gdk_window_get_visual (window)->depth; private = g_new (GdkWindowPrivate, 1); pixmap = (GdkPixmap*) private; @@ -236,12 +237,15 @@ gdk_pixmap_read_string (FILE *infile, guint *buffer_size) { gint c; - guint cnt = 0; + guint cnt = 0, bufsiz, ret = FALSE; + gchar *buf; - if ((*buffer) == NULL) + buf = *buffer; + bufsiz = *buffer_size; + if (buf == NULL) { - (*buffer_size) = 10 * sizeof (gchar); - (*buffer) = g_new(gchar, *buffer_size); + bufsiz = 10 * sizeof (gchar); + buf = g_new(gchar, bufsiz); } do @@ -249,25 +253,37 @@ gdk_pixmap_read_string (FILE *infile, while (c != EOF && c != '"'); if (c != '"') - return FALSE; + goto out; while ((c = getc(infile)) != EOF) { - if (cnt == (*buffer_size)) + if (cnt == bufsiz) { - (*buffer_size) *= 2; - (*buffer) = (gchar *) g_realloc ((*buffer), *buffer_size); } + guint new_size = bufsiz * 2; + if (new_size > bufsiz) + bufsiz = new_size; + else + goto out; + + buf = (gchar *) g_realloc (buf, bufsiz); + buf[bufsiz-1] = '\0'; + } if (c != '"') - (*buffer)[cnt++] = c; + buf[cnt++] = c; else { - (*buffer)[cnt++] = 0; - return TRUE; + buf[cnt] = 0; + ret = TRUE; + break; } } - return FALSE; + out: + buf[bufsiz-1] = '\0'; /* ensure null termination for errors */ + *buffer = buf; + *buffer_size = bufsiz; + return ret; } gchar* @@ -292,12 +308,16 @@ gdk_pixmap_skip_string (gchar *buffer) return &buffer[index]; } +/* Xlib crashed ince at a color name lengths around 125 */ +#define MAX_COLOR_LEN 120 + gchar* gdk_pixmap_extract_color (gchar *buffer) { - gint counter, finished = FALSE, numnames; + gint counter, numnames; gchar *ptr = NULL, ch, temp[128]; - gchar color[128], *retcol; + gchar color[MAX_COLOR_LEN], *retcol; + gint space; counter = 0; while (ptr == NULL) @@ -314,9 +334,6 @@ gdk_pixmap_extract_color (gchar *buffer) counter++; } - if (ptr == NULL) - return NULL; - ptr = gdk_pixmap_skip_whitespaces (ptr); if (ptr[0] == 0) @@ -330,18 +347,26 @@ gdk_pixmap_extract_color (gchar *buffer) color[0] = 0; numnames = 0; - while (finished == FALSE) + space = MAX_COLOR_LEN - 1; + while (space > 0) { sscanf (ptr, "%127s", temp); - if ((gint)ptr[0] == 0 || strcmp ("s", temp) == 0 || strcmp ("m", temp) == 0 || - strcmp ("g", temp) == 0 || strcmp ("g4", temp) == 0) - finished = TRUE; + if (((gint)ptr[0] == 0) || + (strcmp ("s", temp) == 0) || (strcmp ("m", temp) == 0) || + (strcmp ("g", temp) == 0) || (strcmp ("g4", temp) == 0)) + { + break; + } else { if (numnames > 0) - strcat (color, " "); - strcat (color, temp); + { + space -= 1; + strcat (color, " "); + } + strncat (color, temp, space); + space -= MIN (space, strlen (temp)); ptr = gdk_pixmap_skip_string (ptr); ptr = gdk_pixmap_skip_whitespaces (ptr); numnames++; @@ -352,216 +377,48 @@ gdk_pixmap_extract_color (gchar *buffer) return retcol; } - -GdkPixmap* -gdk_pixmap_colormap_create_from_xpm (GdkWindow *window, - GdkColormap *colormap, - GdkBitmap **mask, - GdkColor *transparent_color, - const gchar *filename) +static void +free_color (gpointer key, gpointer value, gpointer user_data) { - FILE *infile = NULL; - GdkPixmap *pixmap = NULL; - GdkImage *image = NULL; - GdkVisual *visual; - GdkGC *gc; - GdkColor tmp_color; - gint width, height, num_cols, cpp, cnt, n, ns, xcnt, ycnt; - gchar *buffer = NULL, pixel_str[32]; - guint buffer_size = 0; - _GdkPixmapColor *colors = NULL, *color = NULL; - gulong index; - - if ((window == NULL) && (colormap == NULL)) - g_warning ("Creating pixmap from xpm with NULL window and colormap"); - - if (window == NULL) - window = (GdkWindow *)&gdk_root_parent; - - if (colormap == NULL) - { - colormap = gdk_window_get_colormap (window); - visual = gdk_window_get_visual (window); - } - else - visual = ((GdkColormapPrivate *)colormap)->visual; - - infile = fopen (filename, "rb"); - if (infile != NULL) - { - if (gdk_pixmap_seek_string (infile, "XPM", FALSE) == TRUE) - { - if (gdk_pixmap_seek_char (infile,'{') == TRUE) - { - gdk_pixmap_seek_char (infile, '"'); - fseek (infile, -1, SEEK_CUR); - gdk_pixmap_read_string (infile, &buffer, &buffer_size); - - sscanf (buffer,"%d %d %d %d", &width, &height, &num_cols, &cpp); - - colors = g_new(_GdkPixmapColor, num_cols); - - if (transparent_color == NULL) - { - gdk_color_white (colormap, &tmp_color); - transparent_color = &tmp_color; - } - - for (cnt = 0; cnt < num_cols; cnt++) - { - gchar *color_name; - - gdk_pixmap_seek_char (infile, '"'); - fseek (infile, -1, SEEK_CUR); - gdk_pixmap_read_string (infile, &buffer, &buffer_size); - - colors[cnt].color_string = g_new(gchar, cpp + 1); - for (n = 0; n < cpp; n++) - colors[cnt].color_string[n] = buffer[n]; - colors[cnt].color_string[n] = 0; - colors[cnt].transparent = FALSE; - - color_name = gdk_pixmap_extract_color (&buffer[cpp]); - - if (color_name != NULL) - { - if (gdk_color_parse (color_name, &colors[cnt].color) == FALSE) - { - colors[cnt].color = *transparent_color; - colors[cnt].transparent = TRUE; - } - } - else - { - colors[cnt].color = *transparent_color; - colors[cnt].transparent = TRUE; - } - - g_free (color_name); - - gdk_color_alloc (colormap, &colors[cnt].color); - } - - index = 0; - image = gdk_image_new (GDK_IMAGE_FASTEST, visual, width, height); - - gc = NULL; - if (mask) - { - /* The pixmap mask is just a bits pattern. - * Color 0 is used for background and 1 for foreground. - * We don't care about the colormap, we just need 0 and 1. - */ - GdkColor mask_pattern; - - *mask = gdk_pixmap_new (window, width, height, 1); - gc = gdk_gc_new (*mask); - - mask_pattern.pixel = 0; - gdk_gc_set_foreground (gc, &mask_pattern); - gdk_draw_rectangle (*mask, gc, TRUE, 0, 0, -1, -1); - - mask_pattern.pixel = 1; - gdk_gc_set_foreground (gc, &mask_pattern); - } - - for (ycnt = 0; ycnt < height; ycnt++) - { - gdk_pixmap_read_string (infile, &buffer, &buffer_size); - - for (n = 0, cnt = 0, xcnt = 0; n < (width * cpp); n += cpp, xcnt++) - { - strncpy (pixel_str, &buffer[n], cpp); - pixel_str[cpp] = 0; - color = NULL; - ns = 0; - - while ((color == NULL) && (ns < num_cols)) - { - if (strcmp (pixel_str, colors[ns].color_string) == 0) - color = &colors[ns]; - else - ns++; - } - - if (!color) /* screwed up XPM file */ - color = &colors[0]; - - gdk_image_put_pixel (image, xcnt, ycnt, color->color.pixel); - - if (mask && color->transparent) - { - if (cnt < xcnt) - gdk_draw_line (*mask, gc, cnt, ycnt, xcnt - 1, ycnt); - cnt = xcnt + 1; - } - } - - if (mask && (cnt < xcnt)) - gdk_draw_line (*mask, gc, cnt, ycnt, xcnt - 1, ycnt); - } - - if (mask) - gdk_gc_destroy (gc); - - pixmap = gdk_pixmap_new (window, width, height, visual->depth); - - gc = gdk_gc_new (pixmap); - gdk_gc_set_foreground (gc, transparent_color); - gdk_draw_image (pixmap, gc, image, 0, 0, 0, 0, image->width, image->height); - gdk_gc_destroy (gc); - gdk_image_destroy (image); - } - } - - fclose (infile); - free (buffer); - - if (colors != NULL) - { - for (cnt = 0; cnt < num_cols; cnt++) - g_free (colors[cnt].color_string); - g_free (colors); - } - } - - return pixmap; + g_free (key); + g_free (value); } + -GdkPixmap* -gdk_pixmap_create_from_xpm (GdkWindow *window, - GdkBitmap **mask, - GdkColor *transparent_color, - const gchar *filename) +enum buffer_op { - return gdk_pixmap_colormap_create_from_xpm (window, NULL, mask, - transparent_color, filename); -} - - -GdkPixmap* -gdk_pixmap_colormap_create_from_xpm_d (GdkWindow *window, - GdkColormap *colormap, - GdkBitmap **mask, - GdkColor *transparent_color, - gchar **data) + op_header, + op_cmap, + op_body +}; + + +static GdkPixmap * +_gdk_pixmap_create_from_xpm (GdkWindow *window, + GdkColormap *colormap, + GdkBitmap **mask, + GdkColor *transparent_color, + gchar * (*get_buf) (enum buffer_op op, + gpointer handle), + gpointer handle) { GdkPixmap *pixmap = NULL; GdkImage *image = NULL; GdkVisual *visual; - GdkGC *gc; + GdkGC *gc = NULL; GdkColor tmp_color; - gint width, height, num_cols, cpp, cnt, n, ns, xcnt, ycnt, i; + gint width, height, num_cols, cpp, n, ns, cnt, xcnt, ycnt, wbytes; gchar *buffer, pixel_str[32]; - _GdkPixmapColor *colors = NULL, *color = NULL; + _GdkPixmapColor *color = NULL, *fallbackcolor = NULL; gulong index; - + GHashTable *colors = NULL; + if ((window == NULL) && (colormap == NULL)) g_warning ("Creating pixmap from xpm with NULL window and colormap"); - + if (window == NULL) window = (GdkWindow *)&gdk_root_parent; - + if (colormap == NULL) { colormap = gdk_window_get_colormap (window); @@ -569,56 +426,63 @@ gdk_pixmap_colormap_create_from_xpm_d (GdkWindow *window, } else visual = ((GdkColormapPrivate *)colormap)->visual; - - i = 0; - buffer = data[i++]; + + buffer = (*get_buf) (op_header, handle); + if (buffer == NULL) + return NULL; + sscanf (buffer,"%d %d %d %d", &width, &height, &num_cols, &cpp); - - colors = g_new(_GdkPixmapColor, num_cols); - - if (transparent_color == NULL) + if (cpp >= 32) + { + g_warning ("Pixmap has more than 31 characters per color\n"); + return NULL; + } + + colors = g_hash_table_new (g_str_hash, g_str_equal); + + if (transparent_color == NULL) { gdk_color_white (colormap, &tmp_color); transparent_color = &tmp_color; } - + for (cnt = 0; cnt < num_cols; cnt++) { gchar *color_name; - - buffer = data[i++]; - - colors[cnt].color_string = g_new(gchar, cpp + 1); - for (n = 0; n < cpp; n++) - colors[cnt].color_string[n] = buffer[n]; - colors[cnt].color_string[n] = 0; - colors[cnt].transparent = FALSE; - - color_name = gdk_pixmap_extract_color (&buffer[cpp]); - - if (color_name != NULL) - { - if (gdk_color_parse (color_name, &colors[cnt].color) == FALSE) - { - colors[cnt].color = *transparent_color; - colors[cnt].transparent = TRUE; - } - } - else + + buffer = (*get_buf) (op_cmap, handle); + if (buffer == NULL) + goto error; + + color = g_new (_GdkPixmapColor, 1); + color->color_string = g_new (gchar, cpp + 1); + strncpy (color->color_string, buffer, cpp); + color->color_string[cpp] = 0; + buffer += strlen (color->color_string); + color->transparent = FALSE; + + color_name = gdk_pixmap_extract_color (buffer); + + if (color_name == NULL || + gdk_color_parse (color_name, &color->color) == FALSE) { - colors[cnt].color = *transparent_color; - colors[cnt].transparent = TRUE; + color->color = *transparent_color; + color->transparent = TRUE; } - + g_free (color_name); - - gdk_color_alloc (colormap, &colors[cnt].color); + + /* FIXME: The remaining slowness appears to happen in this + function. */ + gdk_color_alloc (colormap, &color->color); + g_hash_table_insert (colors, color->color_string, color); + if (cnt == 0) + fallbackcolor = color; } - + index = 0; image = gdk_image_new (GDK_IMAGE_FASTEST, visual, width, height); - - gc = NULL; + if (mask) { /* The pixmap mask is just a bits pattern. @@ -626,42 +490,43 @@ gdk_pixmap_colormap_create_from_xpm_d (GdkWindow *window, * We don't care about the colormap, we just need 0 and 1. */ GdkColor mask_pattern; - + *mask = gdk_pixmap_new (window, width, height, 1); gc = gdk_gc_new (*mask); - + mask_pattern.pixel = 0; gdk_gc_set_foreground (gc, &mask_pattern); gdk_draw_rectangle (*mask, gc, TRUE, 0, 0, -1, -1); - + mask_pattern.pixel = 1; gdk_gc_set_foreground (gc, &mask_pattern); } - + + wbytes = width * cpp; for (ycnt = 0; ycnt < height; ycnt++) { - buffer = data[i++]; - - for (n = 0, cnt = 0, xcnt = 0; n < (width * cpp); n += cpp, xcnt++) + buffer = (*get_buf) (op_body, handle); + + /* FIXME: this slows things down a little - it could be + * integrated into the strncpy below, perhaps. OTOH, strlen + * is fast. + */ + if ((buffer == NULL) || strlen (buffer) < wbytes) + continue; + + for (n = 0, cnt = 0, xcnt = 0; n < wbytes; n += cpp, xcnt++) { strncpy (pixel_str, &buffer[n], cpp); pixel_str[cpp] = 0; - color = NULL; ns = 0; - - while ((color == NULL) && (ns < num_cols)) - { - if (strcmp (pixel_str, colors[ns].color_string) == 0) - color = &colors[ns]; - else - ns++; - } - + + color = g_hash_table_lookup (colors, pixel_str); + if (!color) /* screwed up XPM file */ - color = &colors[0]; - + color = fallbackcolor; + gdk_image_put_pixel (image, xcnt, ycnt, color->color.pixel); - + if (mask && color->transparent) { if (cnt < xcnt) @@ -669,33 +534,151 @@ gdk_pixmap_colormap_create_from_xpm_d (GdkWindow *window, cnt = xcnt + 1; } } - + if (mask && (cnt < xcnt)) gdk_draw_line (*mask, gc, cnt, ycnt, xcnt - 1, ycnt); } - + + error: + if (mask) gdk_gc_destroy (gc); + + if (image != NULL) + { + pixmap = gdk_pixmap_new (window, width, height, visual->depth); + + gc = gdk_gc_new (pixmap); + gdk_gc_set_foreground (gc, transparent_color); + gdk_draw_image (pixmap, gc, image, 0, 0, 0, 0, image->width, image->height); + gdk_gc_destroy (gc); + gdk_image_destroy (image); + } + + if (colors != NULL) + { + g_hash_table_foreach (colors, free_color, 0); + g_hash_table_destroy (colors); + } + + return pixmap; +} - pixmap = gdk_pixmap_new (window, width, height, visual->depth); - gc = gdk_gc_new (pixmap); - gdk_gc_set_foreground (gc, transparent_color); - gdk_draw_image (pixmap, gc, image, 0, 0, 0, 0, image->width, image->height); - gdk_gc_destroy (gc); - gdk_image_destroy (image); +struct file_handle +{ + FILE *infile; + gchar *buffer; + guint buffer_size; +}; - if (colors != NULL) + +static gchar * +file_buffer (enum buffer_op op, gpointer handle) +{ + struct file_handle *h = handle; + + switch (op) + { + case op_header: + if (gdk_pixmap_seek_string (h->infile, "XPM", FALSE) != TRUE) + break; + + if (gdk_pixmap_seek_char (h->infile,'{') != TRUE) + break; + /* Fall through to the next gdk_pixmap_seek_char. */ + + case op_cmap: + gdk_pixmap_seek_char (h->infile, '"'); + fseek (h->infile, -1, SEEK_CUR); + /* Fall through to the gdk_pixmap_read_string. */ + + case op_body: + gdk_pixmap_read_string (h->infile, &h->buffer, &h->buffer_size); + return h->buffer; + } + return 0; +} + + +GdkPixmap* +gdk_pixmap_colormap_create_from_xpm (GdkWindow *window, + GdkColormap *colormap, + GdkBitmap **mask, + GdkColor *transparent_color, + const gchar *filename) +{ + struct file_handle h; + GdkPixmap *pixmap = NULL; + + memset (&h, 0, sizeof (h)); + h.infile = fopen (filename, "rb"); + if (h.infile != NULL) { - for (cnt = 0; cnt < num_cols; cnt++) - g_free (colors[cnt].color_string); - g_free (colors); + pixmap = _gdk_pixmap_create_from_xpm (window, colormap, mask, + transparent_color, + file_buffer, &h); + fclose (h.infile); + g_free (h.buffer); } return pixmap; } GdkPixmap* +gdk_pixmap_create_from_xpm (GdkWindow *window, + GdkBitmap **mask, + GdkColor *transparent_color, + const gchar *filename) +{ + return gdk_pixmap_colormap_create_from_xpm (window, NULL, mask, + transparent_color, filename); +} + + +struct mem_handle +{ + gchar **data; + int offset; +}; + + +static gchar * +mem_buffer (enum buffer_op op, gpointer handle) +{ + struct mem_handle *h = handle; + switch (op) + { + case op_header: + case op_cmap: + case op_body: + if (h->data[h->offset]) + return h->data[h->offset ++]; + } + return 0; +} + + +GdkPixmap* +gdk_pixmap_colormap_create_from_xpm_d (GdkWindow *window, + GdkColormap *colormap, + GdkBitmap **mask, + GdkColor *transparent_color, + gchar **data) +{ + struct mem_handle h; + GdkPixmap *pixmap = NULL; + + memset (&h, 0, sizeof (h)); + h.data = data; + pixmap = _gdk_pixmap_create_from_xpm (window, colormap, mask, + transparent_color, + mem_buffer, &h); + return pixmap; +} + + +GdkPixmap* gdk_pixmap_create_from_xpm_d (GdkWindow *window, GdkBitmap **mask, GdkColor *transparent_color, diff --git a/gdk/x11/gdkregion-x11.c b/gdk/x11/gdkregion-x11.c index 6034bbae86..4b5c1c866c 100644 --- a/gdk/x11/gdkregion-x11.c +++ b/gdk/x11/gdkregion-x11.c @@ -127,7 +127,7 @@ gdk_region_polygon (GdkPoint *points, GdkRegionPrivate *private; GdkRegion *region; Region xregion; - int xfill_rule; + gint xfill_rule = EvenOddRule; g_return_val_if_fail (points != NULL, NULL); g_return_val_if_fail (npoints != 0, NULL); /* maybe we should check for at least three points */ diff --git a/gdk/x11/gdkvisual-x11.c b/gdk/x11/gdkvisual-x11.c index 90ca5cfe78..a6a8b2b134 100644 --- a/gdk/x11/gdkvisual-x11.c +++ b/gdk/x11/gdkvisual-x11.c @@ -58,7 +58,7 @@ static gchar* visual_names[] = static GHashTable *visual_hash = NULL; void -gdk_visual_init () +gdk_visual_init (void) { static gint possible_depths[6] = { 32, 24, 16, 15, 8, 1 }; static GdkVisualType possible_types[6] = @@ -263,25 +263,25 @@ gdk_visual_unref (GdkVisual *visual) } gint -gdk_visual_get_best_depth () +gdk_visual_get_best_depth (void) { return available_depths[0]; } GdkVisualType -gdk_visual_get_best_type () +gdk_visual_get_best_type (void) { return available_types[0]; } GdkVisual* -gdk_visual_get_system () +gdk_visual_get_system (void) { return ((GdkVisual*) system_visual); } GdkVisual* -gdk_visual_get_best () +gdk_visual_get_best (void) { return ((GdkVisual*) &(visuals[0])); } diff --git a/gdk/x11/gdkwindow-x11.c b/gdk/x11/gdkwindow-x11.c index 4edb1ead66..21b10590d0 100644 --- a/gdk/x11/gdkwindow-x11.c +++ b/gdk/x11/gdkwindow-x11.c @@ -20,7 +20,6 @@ #include <X11/Xlib.h> #include <X11/Xutil.h> #include <X11/Xatom.h> -#include <X11/extensions/shape.h> #include <netinet/in.h> #include "gdk.h" #include "../config.h" @@ -30,6 +29,10 @@ #include <stdlib.h> #include <stdio.h> +#ifdef HAVE_SHAPE_EXT +#include <X11/extensions/shape.h> +#endif + int nevent_masks = 17; int event_mask_table[19] = { @@ -65,18 +68,18 @@ gdk_window_xid_at(Window base, gint bx, gint by, gint x, gint y, Display *disp; Window *list=NULL; Window child=0,parent_win=0,root_win=0; + int i; - guint num; + unsigned int ww, wh, wb, wd, num; int wx,wy; - guint ww,wh,wb,wd; - + window=(GdkWindow*)&gdk_root_parent; private=(GdkWindowPrivate*)window; disp=private->xdisplay; if (!XGetGeometry(disp,base,&root_win,&wx,&wy,&ww,&wh,&wb,&wd)) return 0; wx+=bx;wy+=by; - if (!((x>=wx)&&(y>=wy)&&(x<(wx+ww))&&(y<(wy+wh)))) + if (!((x>=wx)&&(y>=wy)&&(x<(int)(wx+ww))&&(y<(int)(wy+wh)))) return 0; if (!XQueryTree(disp,base,&root_win,&parent_win,&list,&num)) return base; @@ -172,7 +175,7 @@ gdk_window_xid_at_coords(gint x, gint y, GList *excludes, gboolean excl_child) } void -gdk_window_init () +gdk_window_init (void) { XWindowAttributes xattributes; unsigned int width; @@ -191,6 +194,8 @@ gdk_window_init () gdk_root_parent.window.user_data = NULL; gdk_root_parent.width = width; gdk_root_parent.height = height; + gdk_root_parent.children = NULL; + gdk_root_parent.colormap = NULL; } GdkWindow* @@ -202,7 +207,6 @@ gdk_window_new (GdkWindow *parent, GdkWindowPrivate *private; GdkWindowPrivate *parent_private; GdkVisual *visual; - GdkColormap *colormap; Display *parent_display; Window xparent; Visual *xvisual; @@ -232,6 +236,10 @@ gdk_window_new (GdkWindow *parent, window = (GdkWindow*) private; private->parent = parent; + + if (parent_private) + parent_private->children = g_list_prepend (parent_private->children, window); + private->xdisplay = parent_display; private->destroyed = FALSE; private->resize_count = 0; @@ -264,6 +272,7 @@ gdk_window_new (GdkWindow *parent, private->dnd_drag_eventmask = private->dnd_drag_savedeventmask = 0; private->filters = NULL; + private->children = NULL; window->user_data = NULL; @@ -296,9 +305,9 @@ gdk_window_new (GdkWindow *parent, depth = visual->depth; if (attributes_mask & GDK_WA_COLORMAP) - colormap = attributes->colormap; + private->colormap = attributes->colormap; else - colormap = gdk_colormap_get_system (); + private->colormap = gdk_colormap_get_system (); xattributes.background_pixel = BlackPixel (gdk_display, gdk_screen); xattributes.border_pixel = BlackPixel (gdk_display, gdk_screen); @@ -307,26 +316,26 @@ gdk_window_new (GdkWindow *parent, switch (private->window_type) { case GDK_WINDOW_TOPLEVEL: - xattributes.colormap = ((GdkColormapPrivate*) colormap)->xcolormap; + xattributes.colormap = ((GdkColormapPrivate*) private->colormap)->xcolormap; xattributes_mask |= CWColormap; xparent = gdk_root_window; break; case GDK_WINDOW_CHILD: - xattributes.colormap = ((GdkColormapPrivate*) colormap)->xcolormap; + xattributes.colormap = ((GdkColormapPrivate*) private->colormap)->xcolormap; xattributes_mask |= CWColormap; break; case GDK_WINDOW_DIALOG: - xattributes.colormap = ((GdkColormapPrivate*) colormap)->xcolormap; + xattributes.colormap = ((GdkColormapPrivate*) private->colormap)->xcolormap; xattributes_mask |= CWColormap; xparent = gdk_root_window; break; case GDK_WINDOW_TEMP: - xattributes.colormap = ((GdkColormapPrivate*) colormap)->xcolormap; + xattributes.colormap = ((GdkColormapPrivate*) private->colormap)->xcolormap; xattributes_mask |= CWColormap; xparent = gdk_root_window; @@ -348,7 +357,7 @@ gdk_window_new (GdkWindow *parent, { depth = 0; class = InputOnly; - colormap = NULL; + private->colormap = NULL; } private->xwindow = XCreateWindow (private->xdisplay, xparent, @@ -358,6 +367,9 @@ gdk_window_new (GdkWindow *parent, gdk_window_ref (window); gdk_xid_table_insert (&private->xwindow, window); + if (private->colormap) + gdk_colormap_ref (private->colormap); + gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ? (attributes->cursor) : NULL)); @@ -372,8 +384,8 @@ gdk_window_new (GdkWindow *parent, break; case GDK_WINDOW_CHILD: if ((attributes->wclass == GDK_INPUT_OUTPUT) && - (colormap != gdk_colormap_get_system ()) && - (colormap != gdk_window_get_colormap (gdk_window_get_toplevel (window)))) + (private->colormap != gdk_colormap_get_system ()) && + (private->colormap != gdk_window_get_colormap (gdk_window_get_toplevel (window)))) { GDK_NOTE (MISC, g_print ("adding colormap window\n")); gdk_window_add_colormap_windows (window); @@ -430,6 +442,7 @@ gdk_window_foreign_new (guint32 anid) { GdkWindow *window; GdkWindowPrivate *private; + GdkWindowPrivate *parent_private; XWindowAttributes attrs; Window root, parent; Window *children; @@ -446,6 +459,11 @@ gdk_window_foreign_new (guint32 anid) XFree (children); private->parent = gdk_xid_table_lookup (parent); + parent_private = (GdkWindowPrivate *)private->parent; + + if (parent_private) + parent_private->children = g_list_prepend (parent_private->children, window); + private->xwindow = anid; private->xdisplay = gdk_display; private->x = attrs.x; @@ -458,6 +476,7 @@ gdk_window_foreign_new (guint32 anid) private->destroyed = FALSE; private->extension_events = 0; + private->colormap = NULL; private->dnd_drag_data_type = None; private->dnd_drag_data_typesavail = @@ -469,6 +488,7 @@ gdk_window_foreign_new (guint32 anid) private->dnd_drag_eventmask = private->dnd_drag_savedeventmask = 0; private->filters = NULL; + private->children = NULL; window->user_data = NULL; @@ -507,10 +527,17 @@ gdk_window_internal_destroy (GdkWindow *window, gboolean xdestroy, case GDK_WINDOW_FOREIGN: if (!private->destroyed) { + if (private->parent) + { + GdkWindowPrivate *parent_private = (GdkWindowPrivate *)private->parent; + if (parent_private->children) + parent_private->children = g_list_remove (parent_private->children, window); + } + if (private->window_type != GDK_WINDOW_FOREIGN) { - children = gdk_window_get_children (window); - tmp = children; + children = tmp = private->children; + private->children = NULL; while (tmp) { @@ -522,7 +549,7 @@ gdk_window_internal_destroy (GdkWindow *window, gboolean xdestroy, gdk_window_internal_destroy (temp_window, FALSE, our_destroy); } - + g_list_free (children); } @@ -581,6 +608,9 @@ gdk_window_internal_destroy (GdkWindow *window, gboolean xdestroy, else if (xdestroy) XDestroyWindow (private->xdisplay, private->xwindow); + if (private->colormap) + gdk_colormap_unref (private->colormap); + private->destroyed = TRUE; } break; @@ -1059,6 +1089,11 @@ gdk_window_set_colormap (GdkWindow *window, XSetWindowColormap (window_private->xdisplay, window_private->xwindow, colormap_private->xcolormap); + + if (window_private->colormap) + gdk_colormap_unref (window_private->colormap); + window_private->colormap = colormap; + gdk_colormap_ref (window_private->colormap); if (window_private->window_type != GDK_WINDOW_TOPLEVEL) gdk_window_add_colormap_windows (window); @@ -1153,20 +1188,27 @@ gdk_window_get_visual (GdkWindow *window) { GdkWindowPrivate *window_private; XWindowAttributes window_attributes; - + g_return_val_if_fail (window != NULL, NULL); - + window_private = (GdkWindowPrivate*) window; + /* Huh? ->parent is never set for a pixmap. We should just return + * null immeditately + */ while (window_private && (window_private->window_type == GDK_WINDOW_PIXMAP)) window_private = (GdkWindowPrivate*) window_private->parent; if (window_private && !window_private->destroyed) { - XGetWindowAttributes (window_private->xdisplay, - window_private->xwindow, - &window_attributes); - - return gdk_visual_lookup (window_attributes.visual); + if (window_private->colormap == NULL) + { + XGetWindowAttributes (window_private->xdisplay, + window_private->xwindow, + &window_attributes); + return gdk_visual_lookup (window_attributes.visual); + } + else + return ((GdkColormapPrivate *)window_private->colormap)->visual; } return NULL; @@ -1179,16 +1221,20 @@ gdk_window_get_colormap (GdkWindow *window) XWindowAttributes window_attributes; g_return_val_if_fail (window != NULL, NULL); - window_private = (GdkWindowPrivate*) window; - + + g_return_val_if_fail (window_private->window_type != GDK_WINDOW_PIXMAP, NULL); if (!window_private->destroyed) { - XGetWindowAttributes (window_private->xdisplay, - window_private->xwindow, - &window_attributes); - - return gdk_colormap_lookup (window_attributes.colormap); + if (window_private->colormap == NULL) + { + XGetWindowAttributes (window_private->xdisplay, + window_private->xwindow, + &window_attributes); + return gdk_colormap_lookup (window_attributes.colormap); + } + else + return window_private->colormap; } return NULL; @@ -1436,8 +1482,7 @@ gdk_window_add_colormap_windows (GdkWindow *window) /* * This needs the X11 shape extension. - * If not available, simply remove the call to - * XShapeCombineMask. Shaped windows will look + * If not available, shaped windows will look * ugly, but programs still work. Stefan Wille */ void @@ -1445,38 +1490,53 @@ gdk_window_shape_combine_mask (GdkWindow *window, GdkBitmap *mask, gint x, gint y) { + enum { UNKNOWN, NO, YES }; + + static gint have_shape = UNKNOWN; + GdkWindowPrivate *window_private; Pixmap pixmap; g_return_if_fail (window != NULL); - /* This is needed, according to raster */ - gdk_window_set_override_redirect(window, TRUE); - - window_private = (GdkWindowPrivate*) window; - if (window_private->destroyed) - return; - - if (mask) +#ifdef HAVE_SHAPE_EXT + if (have_shape == UNKNOWN) { - GdkWindowPrivate *pixmap_private; - - pixmap_private = (GdkWindowPrivate*) mask; - pixmap = (Pixmap) pixmap_private->xwindow; + int ignore; + if (XQueryExtension(gdk_display, "SHAPE", &ignore, &ignore, &ignore)) + have_shape = YES; + else + have_shape = NO; } - else + + if (have_shape == YES) { - x = 0; - y = 0; - pixmap = None; + window_private = (GdkWindowPrivate*) window; + if (window_private->destroyed) + return; + + if (mask) + { + GdkWindowPrivate *pixmap_private; + + pixmap_private = (GdkWindowPrivate*) mask; + pixmap = (Pixmap) pixmap_private->xwindow; + } + else + { + x = 0; + y = 0; + pixmap = None; + } + + XShapeCombineMask (window_private->xdisplay, + window_private->xwindow, + ShapeBounding, + x, y, + pixmap, + ShapeSet); } - - XShapeCombineMask (window_private->xdisplay, - window_private->xwindow, - ShapeBounding, - x, y, - pixmap, - ShapeSet); +#endif /* HAVE_SHAPE_EXT */ } void @@ -1915,3 +1975,20 @@ gdk_window_set_functions (GdkWindow *window, gdk_window_set_mwm_hints (window, &hints); } + +GList * +gdk_window_get_toplevels (void) +{ + GList *new_list = NULL; + GList *tmp_list; + + tmp_list = gdk_root_parent.children; + while (tmp_list) + { + new_list = g_list_prepend (new_list, tmp_list->data); + tmp_list = tmp_list->next; + } + + return new_list; +} + diff --git a/gdk/x11/gxid.c b/gdk/x11/gxid.c index 219c08bfe0..40b48fa31c 100644 --- a/gdk/x11/gxid.c +++ b/gdk/x11/gxid.c @@ -61,7 +61,7 @@ handler(int signal) } void -init_socket() +init_socket(void) { struct sockaddr_in sin; @@ -130,7 +130,7 @@ enable_device(GxidDevice *dev) /* switch the core pointer from whatever it is now to something else, return true on success, false otherwise */ static int -switch_core_pointer() +switch_core_pointer(void) { GxidDevice *old_pointer = 0; GxidDevice *new_pointer = 0; @@ -222,7 +222,7 @@ init_device(XDeviceInfo *xdevice) } void -init_xinput() +init_xinput(void) { char **extensions; XDeviceInfo *xdevices; @@ -279,12 +279,22 @@ int handle_claim_device(GxidClaimDevice *msg) { int i,j; - XID devid = ntohl(msg->device); - XID winid = ntohl(msg->window); - int exclusive = ntohl(msg->exclusive); + XID devid; + XID winid; + int exclusive; GxidDevice *device = NULL; GxidWindow *window = NULL; + if (msg->length != sizeof(GxidClaimDevice)) + { + fprintf(stderr,"Bad length for ClaimDevice message\n"); + return GXID_RETURN_ERROR; + } + + devid = ntohl(msg->device); + winid = ntohl(msg->window); + exclusive = ntohl(msg->exclusive); + #ifdef DEBUG_CLIENTS fprintf(stderr,"device %ld claimed (window 0x%lx)\n",devid,winid); #endif @@ -397,11 +407,20 @@ int handle_release_device(GxidReleaseDevice *msg) { int i,j; - XID devid = ntohl(msg->device); - XID winid = ntohl(msg->window); + XID devid; + XID winid; GxidDevice *device = NULL; + if (msg->length != sizeof(GxidReleaseDevice)) + { + fprintf(stderr,"Bad length for ReleaseDevice message\n"); + return GXID_RETURN_ERROR; + } + + devid = ntohl(msg->device); + winid = ntohl(msg->window); + #ifdef DEBUG_CLIENTS fprintf(stderr,"device %ld released (window 0x%lx)\n",devid,winid); #endif @@ -460,11 +479,11 @@ handle_release_device(GxidReleaseDevice *msg) } void -handle_connection() +handle_connection (void) { GxidMessage msg; GxidU32 type; - int length; + GxidU32 length; GxidI32 retval; int conn_fd; @@ -496,7 +515,7 @@ handle_connection() /* read rest of message */ - if (length > sizeof(GxidMessage)) + if ((length > sizeof(GxidMessage)) || (length < 2*sizeof(GxidU32))) { fprintf(stderr,"%s: Bad message length\n", program_name); @@ -689,7 +708,7 @@ handle_destroy_notify(XDestroyWindowEvent *event) } void -handle_xevent() +handle_xevent(void) { int i; XEvent event; @@ -743,7 +762,7 @@ handle_xevent() } void -usage() +usage(void) { fprintf(stderr,"Usage: %s [-d display] [-p --gxid-port port]\n", program_name); @@ -833,7 +852,7 @@ main(int argc, char **argv) } if (FD_ISSET(socket_fd,&readfds)) - handle_connection(socket_fd); + handle_connection(); while (XPending(dpy)) handle_xevent(); diff --git a/glib/ChangeLog b/glib/ChangeLog index 2ab8ab1f9b..541430f3c3 100644 --- a/glib/ChangeLog +++ b/glib/ChangeLog @@ -1,3 +1,152 @@ +Sun May 17 10:48:27 1998 Tim Janik <timj@gtk.org> + + * gscanner.c (g_scanner_unexp_token): provide usefull default + specifications for identifier_spec and symbol_spec. + + * glib.h: new functions g_slist_nth_data and g_list_nth_data to return + the data of the nth element in the list. + +Fri May 15 22:31:49 1998 Tim Janik <timj@gtk.org> + + * gscanner.c (g_scanner_unexp_token): removed spurious va_end(args) + that for some reason didn't produce a compiler wrning on my machine + (is va_end undefined for i386?). + +Fri May 15 12:32:08 1998 rodo <doulik@karlin.mff.cuni.cz> + + * gscanner.c: replaced some snprintf with g_snprintf + +Fri May 15 00:56:59 1998 Tim Janik <timj@gtk.org> + + * glib.h: further support for gcc function attributes: G_GNUC_FORMAT, + G_GNUC_NORETURN and G_GNUC_CONST. + + * gscanner.c (g_scanner_stat_mode): changed stat() to lstat(). + (g_scanner_msg_handler): "\n" at end of line! + (g_scanner_foreach_symbol): new function to iterate over the symbol + table (GScanner does value-wrapping). + +Thu May 14 04:14:12 1998 Tim Janik <timj@gtk.org> + + * glib.h: typedef gint gboolean; + this is needed to provide portability with big-endian platforms (e.g. + try sizeof(bool) for c++ on big-endians - it's 4). + this is also needed to maintain some_union.d_gint==some_union.d_gboolean. + plus, gint to gboolean casts and vice versa need to be possible without + loss. + +Tue May 12 19:22:58 1998 Owen Taylor <otaylor@gtk.org> + + * glib/glib.h: Added macros G[U]INT_TO_POINTER() and + GPOINTER_TO_[U]INT for storing small integers integers + inside pointers. + + * glib/testglib.c: Print sizeof() results + as g_print("%ld", (glong)sizeof(foo)), to deal with + size_t being long on Alpha's. + +Tue May 12 16:54:15 1998 Owen Taylor <otaylor@gtk.org> + (James A <jamesa@demon.net> : gtk-jamesa-980511-4.patch) + + * glib.h gstring.c gmessages.c: Added some missing + const to arguments. + + * gutils.c (g_strsignal.c): Added missing return statements. + +Mon May 11 21:11:54 1998 Owen Taylor <otaylor@gtk.org> + + * gutils.c gmessages.c: Moved g_error, g_warning, g_message and + g_print from gutils.c to new file gmessages.c, to avoid having to + include <unistd.h> in gutils.c which was causing problems for the + g_strsignal implementation on FreeBSD boxes. + +Mon May 11 09:53:43 1998 Tim Janik <timj@gtk.org> + + * configure.in: preserve automake CFLAGS. + + * Makefile.am: fully rename the created library to libglib-1.1.la. + this means we need to change certain portions of the Makefile.am on + major/minor version bumps. + + * ltmain.sh: the -release option is not required anymore. + + * glib.h: provide G_GNUC_FUNCTION and G_GNUC_PRETTY_FUNCTION to + avoid conditionals. unconditionally define NULL, TRUE, FALSE, MAX, + MIN, ABS and CLAMP, these macros might be screwed from other headers. + +Mon May 11 01:44:10 1998 Tim Janik <timj@gtk.org> + + * gdataset.c: new file, gdatasets implement the object data + mechanism from GtkObject. a generic data pointer is associated with + a certain location and a key id. + +Sat May 9 20:08:12 1998 Owen Taylor <otaylor@gtk.org> + + * glib/gmem.c: Experimentally restore GMemChunk + to its primeval state - where mem areas are + freed incrementally instead of searching the tree + every time a mem area is completely empty. Also, + always keep one mem chunk around. (Reduced calls + to malloc() a lot, but doesn't really improve + performance significiantly) + +Thu May 7 08:17:28 1998 Tim Janik <timj@gtk.org> + + * glib.h (G_GNUC_PRINTF): + (G_GNUC_SCANF): macros to facilitate the printf/scanf format argument + checking of gcc. + + * gstring.c: const corrections, string!=NULL checks at function entry. + (g_string_down): new function for tolower(3) conversion. + (g_string_up): new function for toupper(3) conversion. + + * gutils.c: const corrections. + (g_strdown): g_string_down() counterpart. + (g_strup): g_string_up() counterpart. + + * gscanner.c (g_scanner_unexp_token): + (g_scanner_error): + (g_scanner_warn): new functions to let a scanner put out warnings + or errors, especially to react on unexpected tokens. + + * gslist.c: + (g_slist_index): find out about about the position of a + certain data pointer. + (g_slist_position): find out about about the position of a + certain node. + + * glist.c: + (g_list_index): find out about about the position of a + certain data pointer. + +Thu May 7 05:14:19 1998 Tim Janik <timj@gtk.org> + + * ltmain.sh: added a new commandline flag -postfix similar to -release, + but will immediately change the library name. + + * Makefile.am: specify -postfix and -version-info + + * configure.in: version bump to 1.1.0. added GLIB_INTERFACE_AGE and + GLIB_BINARY_AGE. calculate LT_* variables for libtool. + +Fri May 1 16:36:08 1998 Owen Taylor <otaylor@gtk.org> + + * gutils.c: (g_strcasecmp). Check for isupper before + taking tolower, and account for macroized tolower. + + * gutils.c (g_error): Check for recursion. + +1998-04-27 Elliot Lee <sopwith@cuc.ml.org> + + * glist.c (g_list_position): New function to find the position of + a link in a list - should be the inverse of g_list_nth(), but + haven't tested it so poof. + +Thu Apr 30 21:41:30 1998 Owen Taylor <otaylor@gtk.org> + + * gstring.c : Check arguments more carefully, + (gtk-draco-980423-1.patch; ramsey@rhrk.uni-kl.de) + Tue Apr 7 19:36:48 1998 Owen Taylor <owt1@cornell.edu> * gutils.c (g_direct_compare): Removed, because that's what diff --git a/glib/Makefile.am b/glib/Makefile.am index 7ee39bae91..ef28c3e2f4 100644 --- a/glib/Makefile.am +++ b/glib/Makefile.am @@ -2,15 +2,17 @@ configincludedir = $(pkglibdir)/include -lib_LTLIBRARIES = libglib.la +lib_LTLIBRARIES = libglib-1.1.la -libglib_la_SOURCES = \ +libglib_1_1_la_SOURCES = \ garray.c \ gcache.c \ + gdataset.c \ gerror.c \ ghash.c \ glist.c \ gmem.c \ + gmessages.c \ gprimes.c \ gslist.c \ gtimer.c \ @@ -25,12 +27,12 @@ include_HEADERS = \ configinclude_DATA = \ glibconfig.h -libglib_la_LDFLAGS = -version-info 1:0:0 +libglib_1_1_la_LDFLAGS = -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) INCLUDES = -I$(top_srcdir) noinst_PROGRAMS = testglib -testglib_LDADD = libglib.la +testglib_LDADD = libglib-@LT_RELEASE@.la .PHONY: files release diff --git a/glib/configure.in b/glib/configure.in index cc78947c5d..ecec5f975f 100644 --- a/glib/configure.in +++ b/glib/configure.in @@ -4,8 +4,36 @@ AC_INIT(glist.c) # Save this value here, since automake will set cflags later cflags_set=${CFLAGS+set} -dnl Initialize automake stuff -AM_INIT_AUTOMAKE(glib, 1.0.0) +# Making releases: +# GLIB_MICRO_VERSION += 1; +# GLIB_INTERFACE_AGE += 1; +# GLIB_BINARY_AGE += 1; +# if any functions have been added, set GLIB_INTERFACE_AGE to 0. +# if backwards compatibility has been broken, +# set GLIB_BINARY_AGE and GLIB_INTERFACE_AGE to 0. +# +GLIB_MAJOR_VERSION=1 +GLIB_MINOR_VERSION=1 +GLIB_MICRO_VERSION=0 +GLIB_INTERFACE_AGE=0 +GLIB_BINARY_AGE=0 +GLIB_VERSION=$GLIB_MAJOR_VERSION.$GLIB_MINOR_VERSION.$GLIB_MICRO_VERSION +AC_SUBST(GLIB_VERSION) + +# libtool versioning +LT_RELEASE=$GLIB_MAJOR_VERSION.$GLIB_MINOR_VERSION +LT_CURRENT=`expr $GLIB_MICRO_VERSION - $GLIB_INTERFACE_AGE` +LT_REVISION=$GLIB_INTERFACE_AGE +LT_AGE=`expr $GLIB_BINARY_AGE - $GLIB_INTERFACE_AGE` +AC_SUBST(LT_RELEASE) +AC_SUBST(LT_CURRENT) +AC_SUBST(LT_REVISION) +AC_SUBST(LT_AGE) + +VERSION=$GLIB_VERSION +PACKAGE=glib + +AM_INIT_AUTOMAKE($PACKAGE, $VERSION, no-define) # Specify a configuration file AM_CONFIG_HEADER(glibconfig.h) @@ -24,7 +52,7 @@ AC_ARG_ENABLE(ansi, [ --enable-ansi turn on strict ansi [default=no]] , enable_ansi=no) if test "x$enable_debug" = "xyes"; then - test "$cflags_set" = set || CFLAGS="-g" + test "$cflags_set" = set || CFLAGS="$CFLAGS -g" CFLAGS="$CFLAGS -DG_ENABLE_DEBUG" else if test "x$enable_debug" = "xno"; then diff --git a/glib/gerror.c b/glib/gerror.c index d84ea38ca6..1c4ce5c31c 100644 --- a/glib/gerror.c +++ b/glib/gerror.c @@ -55,7 +55,7 @@ static int do_query (char *prompt); -static void debug (char *progname, int method); +static void debug (const gchar *progname, int method); static void stack_trace (char **); static void stack_trace_sigchld (int); @@ -63,7 +63,7 @@ static void stack_trace_sigchld (int); static int stack_trace_done; void -g_debug (char *progname) +g_debug (const gchar *progname) { char buf[32]; @@ -82,14 +82,16 @@ g_debug (char *progname) } void -g_attach_process (char *progname, int query) +g_attach_process (const gchar *progname, + int query) { if (!query || do_query ("attach to process")) debug (progname, INTERACTIVE); } void -g_stack_trace (char *progname, int query) +g_stack_trace (const gchar *progname, + int query) { if (!query || do_query ("print stack trace")) debug (progname, STACK_TRACE); @@ -114,7 +116,7 @@ do_query (char *prompt) } static void -debug (char *progname, +debug (const char *progname, int method) { pid_t pid; @@ -124,7 +126,7 @@ debug (char *progname, sprintf (buf, "%d", (int) getpid ()); - args[1] = progname; + args[1] = (gchar*) progname; args[2] = buf; switch (method) diff --git a/glib/glib.h b/glib/glib.h index bc63541997..282288c977 100644 --- a/glib/glib.h +++ b/glib/glib.h @@ -89,38 +89,85 @@ /* Provide definitions for some commonly used macros. - * These are only provided if they haven't already - * been defined. It is assumed that if they are already - * defined then the current definition is correct. */ -#ifndef FALSE -#define FALSE 0 -#endif /* FALSE */ +#undef NULL +#define NULL ((void*) 0) -#ifndef TRUE -#define TRUE 1 -#endif /* TRUE */ +#undef FALSE +#define FALSE 0 -#ifndef NULL -#define NULL ((void*) 0) -#endif /* NULL */ +#undef TRUE +#define TRUE 1 -#ifndef MAX +#undef MAX #define MAX(a, b) (((a) > (b)) ? (a) : (b)) -#endif /* MAX */ -#ifndef MIN +#undef MIN #define MIN(a, b) (((a) < (b)) ? (a) : (b)) -#endif /* MIN */ -#ifndef ABS +#undef ABS #define ABS(a) (((a) < 0) ? -(a) : (a)) -#endif /* ABS */ -#ifndef CLAMP +#undef CLAMP #define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x))) -#endif /* CLAMP */ + +/* Provide simple macro statement wrappers (adapted from Pearl): + * G_STMT_START { statements; } G_STMT_END; + * can be used as a single statement, as in + * if (x) G_STMT_START { ... } G_STMT_END; else ... + * + * For gcc we will wrap the statements within `({' and `})' braces. + * For SunOS they will be wrapped within `if (1)' and `else (void)0', + * and otherwise within `do' and `while (0)'. + */ +#if !(defined (G_STMT_START) && defined (G_STMT_END)) +# if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus) +# define G_STMT_START (void)( +# define G_STMT_END ) +# else +# if (defined (sun) || defined (__sun__)) +# define G_STMT_START if (1) +# define G_STMT_END else (void)0 +# else +# define G_STMT_START do +# define G_STMT_END while (0) +# endif +# endif +#endif + +/* Provide macros to feature GCC function attributes. + */ +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4) +#define G_GNUC_PRINTF( format_idx, arg_idx ) \ + __attribute__((format (printf, format_idx, arg_idx))) +#define G_GNUC_SCANF( format_idx, arg_idx ) \ + __attribute__((format (scanf, format_idx, arg_idx))) +#define G_GNUC_FORMAT( arg_idx ) \ + __attribute__((format_arg (arg_idx))) +#define G_GNUC_NORETURN \ + __attribute__((noreturn)) +#define G_GNUC_CONST \ + __attribute__((const)) +#else /* !__GNUC__ */ +#define G_GNUC_PRINTF( format_idx, arg_idx ) +#define G_GNUC_SCANF( format_idx, arg_idx ) +#define G_GNUC_FORMAT( arg_idx ) +#define G_GNUC_NORETURN +#define G_GNUC_CONST +#endif /* !__GNUC__ */ + +/* Wrap the __PRETTY_FUNCTION__ and __FUNCTION__ variables with macros, + * so we can refer to them as strings unconditionally. + */ +#ifdef __GNUC__ +#define G_GNUC_FUNCTION (__FUNCTION__) +#define G_GNUC_PRETTY_FUNCTION (__PRETTY_FUNCTION__) +#else /* !__GNUC__ */ +#define G_GNUC_FUNCTION ("") +#define G_GNUC_PRETTY_FUNCTION ("") +#endif /* !__GNUC__ */ + #ifndef ATEXIT # ifdef HAVE_ATEXIT @@ -156,29 +203,6 @@ #define g_string(x) #x -/* Provide simple macro statement wrappers (adapted from Pearl): - * G_STMT_START { statements; } G_STMT_END; - * can be used as a single statement, as in - * if (x) G_STMT_START { ... } G_STMT_END; else ... - * - * For gcc we will wrap the statements within `({' and `})' braces. - * For SunOS they will be wrapped within `if (1)' and `else (void)0', - * and otherwise within `do' and `while (0)'. - */ -#if !(defined (G_STMT_START) && defined (G_STMT_END)) -# if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus) -# define G_STMT_START (void)( -# define G_STMT_END ) -# else -# if (defined (sun) || defined (__sun__)) -# define G_STMT_START if (1) -# define G_STMT_END else (void)0 -# else -# define G_STMT_START do -# define G_STMT_END while (0) -# endif -# endif -#endif /* Provide macros for error handling. The "assert" macros will @@ -285,8 +309,11 @@ #endif /* G_DISABLE_CHECKS */ + + #ifdef __cplusplus extern "C" { +#pragma } #endif /* __cplusplus */ /* Provide type definitions for commonly used types. @@ -300,7 +327,7 @@ typedef char gchar; typedef short gshort; typedef long glong; typedef int gint; -typedef char gboolean; +typedef gint gboolean; typedef unsigned char guchar; typedef unsigned short gushort; @@ -343,35 +370,69 @@ typedef signed long gint32; typedef unsigned long guint32; #endif /* SIZEOF_INT */ +/* Define macros for storing integers inside pointers */ + +#if (SIZEOF_INT == SIZEOF_VOID_P) + +#define GPOINTER_TO_INT(p) ((gint)(p)) +#define GPOINTER_TO_UINT(p) ((guint)(p)) + +#define GINT_TO_POINTER(i) ((gpointer)(i)) +#define GUINT_TO_POINTER(u) ((gpointer)(u)) + +#elif (SIZEOF_LONG == SIZEOF_VOID_P) + +#define GPOINTER_TO_INT(p) ((gint)(glong)(p)) +#define GPOINTER_TO_UINT(p) ((guint)(gulong)(p)) + +#define GINT_TO_POINTER(i) ((gpointer)(glong)(i)) +#define GUINT_TO_POINTER(u) ((gpointer)(gulong)(u)) + +#else +#error "No integer type of the same size as a pointer" +#endif + -typedef struct _GList GList; -typedef struct _GSList GSList; -typedef struct _GHashTable GHashTable; -typedef struct _GCache GCache; -typedef struct _GTree GTree; -typedef struct _GTimer GTimer; -typedef struct _GMemChunk GMemChunk; -typedef struct _GListAllocator GListAllocator; -typedef struct _GStringChunk GStringChunk; -typedef struct _GString GString; -typedef struct _GArray GArray; -typedef struct _GDebugKey GDebugKey; - -typedef void (*GFunc) (gpointer data, gpointer user_data); -typedef void (*GHFunc) (gpointer key, gpointer value, gpointer user_data); -typedef guint (*GHashFunc) (gpointer key); -typedef gint (*GCompareFunc) (gpointer a, gpointer b); -typedef gpointer (*GCacheNewFunc) (gpointer key); -typedef gpointer (*GCacheDupFunc) (gpointer value); -typedef void (*GCacheDestroyFunc) (gpointer value); -typedef gint (*GTraverseFunc) (gpointer key, - gpointer value, - gpointer data); -typedef gint (*GSearchFunc) (gpointer key, - gpointer data); -typedef void (*GErrorFunc) (gchar *str); -typedef void (*GWarningFunc) (gchar *str); -typedef void (*GPrintFunc) (gchar *str); +typedef struct _GList GList; +typedef struct _GSList GSList; +typedef struct _GHashTable GHashTable; +typedef struct _GCache GCache; +typedef struct _GTree GTree; +typedef struct _GTimer GTimer; +typedef struct _GMemChunk GMemChunk; +typedef struct _GListAllocator GListAllocator; +typedef struct _GStringChunk GStringChunk; +typedef struct _GString GString; +typedef struct _GArray GArray; +typedef struct _GDebugKey GDebugKey; +typedef struct _GScannerConfig GScannerConfig; +typedef struct _GScanner GScanner; +typedef union _GValue GValue; + + +typedef void (*GFunc) (gpointer data, + gpointer user_data); +typedef void (*GHFunc) (gpointer key, + gpointer value, + gpointer user_data); +typedef guint (*GHashFunc) (gpointer key); +typedef gint (*GCompareFunc) (gpointer a, + gpointer b); +typedef gpointer (*GCacheNewFunc) (gpointer key); +typedef gpointer (*GCacheDupFunc) (gpointer value); +typedef void (*GCacheDestroyFunc) (gpointer value); +typedef gint (*GTraverseFunc) (gpointer key, + gpointer value, + gpointer data); +typedef gint (*GSearchFunc) (gpointer key, + gpointer data); +typedef void (*GErrorFunc) (gchar *str); +typedef void (*GWarningFunc) (gchar *str); +typedef void (*GPrintFunc) (gchar *str); +typedef void (*GScannerMsgFunc) (GScanner *scanner, + gchar *message, + gint error); +typedef void (*GDestroyNotify) (gpointer data); struct _GList @@ -447,12 +508,18 @@ GList* g_list_nth (GList *list, guint n); GList* g_list_find (GList *list, gpointer data); +gint g_list_position (GList *list, + GList *link); +gint g_list_index (GList *list, + gpointer data); GList* g_list_last (GList *list); GList* g_list_first (GList *list); guint g_list_length (GList *list); void g_list_foreach (GList *list, GFunc func, gpointer user_data); +gpointer g_list_nth_data (GList *list, + guint n); #define g_list_previous(list) ((list) ? (((GList *)list)->prev) : NULL) #define g_list_next(list) ((list) ? (((GList *)list)->next) : NULL) @@ -484,11 +551,17 @@ GSList* g_slist_nth (GSList *list, guint n); GSList* g_slist_find (GSList *list, gpointer data); +gint g_slist_position (GSList *list, + GSList *link); +gint g_slist_index (GSList *list, + gpointer data); GSList* g_slist_last (GSList *list); guint g_slist_length (GSList *list); void g_slist_foreach (GSList *list, GFunc func, gpointer user_data); +gpointer g_slist_nth_data (GSList *list, + guint n); #define g_slist_next(list) ((list) ? (((GSList *)list)->next) : NULL) @@ -646,31 +719,35 @@ gdouble g_timer_elapsed (GTimer *timer, /* Output */ -#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4) -void g_error (gchar *format, ...) __attribute__ ((format (printf, 1, 2))); -void g_warning (gchar *format, ...) __attribute__ ((format (printf, 1, 2))); -void g_message (gchar *format, ...) __attribute__ ((format (printf, 1, 2))); -void g_print (gchar *format, ...) __attribute__ ((format (printf, 1, 2))); -#else -void g_error (gchar *format, ...); -void g_warning (gchar *format, ...); -void g_message (gchar *format, ...); -void g_print (gchar *format, ...); -#endif +void g_error (const gchar *format, ...) G_GNUC_PRINTF (1, 2); +void g_warning (const gchar *format, ...) G_GNUC_PRINTF (1, 2); +void g_message (const gchar *format, ...) G_GNUC_PRINTF (1, 2); +void g_print (const gchar *format, ...) G_GNUC_PRINTF (1, 2); /* Utility functions */ -gchar* g_strdup (const gchar *str); -gchar* g_strconcat (const gchar *string1, ...); /* NULL terminated */ -gdouble g_strtod (const gchar *nptr, gchar **endptr); -gchar* g_strerror (gint errnum); -gchar* g_strsignal (gint signum); -gint g_strcasecmp (const gchar *s1, const gchar *s2); -#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4) -gint g_snprintf (gchar *str, gulong n, gchar const *fmt, ...) __attribute__ ((format (printf, 3, 4))); -#else -gint g_snprintf (gchar *str, gulong n, gchar const *fmt, ...); -#endif +#define G_STR_DELIMITERS "_-|> <." +void g_strdelimit (gchar *string, + const gchar *delimiters, + gchar new_delimiter); +gchar* g_strdup (const gchar *str); +gchar* g_strconcat (const gchar *string1, + ...); /* NULL terminated */ +gdouble g_strtod (const gchar *nptr, + gchar **endptr); +gchar* g_strerror (gint errnum); +gchar* g_strsignal (gint signum); +gint g_strcasecmp (const gchar *s1, + const gchar *s2); +void g_strdown (gchar *string); +void g_strup (gchar *string); +guint g_parse_debug_string (const gchar *string, + GDebugKey *keys, + guint nkeys); +gint g_snprintf (gchar *string, + gulong n, + gchar const *format, + ...) G_GNUC_PRINTF (3, 4); /* We make the assumption that if memmove isn't available, then * bcopy will do the job. This isn't safe everywhere. (bcopy can't @@ -688,13 +765,11 @@ GWarningFunc g_set_warning_handler (GWarningFunc func); GPrintFunc g_set_message_handler (GPrintFunc func); GPrintFunc g_set_print_handler (GPrintFunc func); -guint g_parse_debug_string (const gchar *string, - GDebugKey *keys, - guint nkeys); - -void g_debug (char *progname); -void g_attach_process (char *progname, int query); -void g_stack_trace (char *progname, int query); +void g_debug (const gchar *progname); +void g_attach_process (const gchar *progname, + gint query); +void g_stack_trace (const gchar *progname, + gint query); /* String Chunks @@ -702,53 +777,44 @@ void g_stack_trace (char *progname, int query); GStringChunk* g_string_chunk_new (gint size); void g_string_chunk_free (GStringChunk *chunk); gchar* g_string_chunk_insert (GStringChunk *chunk, - gchar* string); + const gchar *string); gchar* g_string_chunk_insert_const (GStringChunk *chunk, - gchar* string); + const gchar *string); /* Strings */ -GString* g_string_new (gchar *init); -void g_string_free (GString *string, - gint free_segment); -GString* g_string_assign (GString *lval, - gchar *rval); -GString* g_string_truncate (GString *string, - gint len); -GString* g_string_append (GString *string, - gchar *val); -GString* g_string_append_c (GString *string, - gchar c); -GString* g_string_prepend (GString *string, - gchar *val); -GString* g_string_prepend_c (GString *string, - gchar c); -GString* g_string_insert (GString *fstring, - gint pos, - gchar *val); -GString* g_string_insert_c (GString *fstring, - gint pos, - gchar c); -GString* g_string_erase (GString *fstring, - gint pos, - gint len); -#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4) -void g_string_sprintf (GString *string, - gchar *fmt, - ...) __attribute__ ((format (printf, 2, 3))); - -void g_string_sprintfa (GString *string, - gchar *fmt, - ...) __attribute__ ((format (printf, 2, 3))); -#else -void g_string_sprintf (GString *string, - gchar *fmt, - ...); - -void g_string_sprintfa (GString *string, - gchar *fmt, - ...); -#endif +GString* g_string_new (const gchar *init); +void g_string_free (GString *string, + gint free_segment); +GString* g_string_assign (GString *lval, + const gchar *rval); +GString* g_string_truncate (GString *string, + gint len); +GString* g_string_append (GString *string, + const gchar *val); +GString* g_string_append_c (GString *string, + gchar c); +GString* g_string_prepend (GString *string, + const gchar *val); +GString* g_string_prepend_c (GString *string, + gchar c); +GString* g_string_insert (GString *string, + gint pos, + const gchar *val); +GString* g_string_insert_c (GString *string, + gint pos, + gchar c); +GString* g_string_erase (GString *string, + gint pos, + gint len); +GString* g_string_down (GString *string); +GString* g_string_up (GString *string); +void g_string_sprintf (GString *string, + const gchar *format, + ...) G_GNUC_PRINTF (2, 3); +void g_string_sprintfa (GString *string, + const gchar *format, + ...) G_GNUC_PRINTF (2, 3); /* Resizable arrays */ @@ -791,8 +857,31 @@ guint g_str_hash (const gpointer v); guint g_direct_hash (gpointer key); +/* Associated Data + */ +void g_dataset_destroy (const gpointer dataset_location); +guint g_dataset_try_key (const gchar *key); +guint g_dataset_force_id (const gchar *key); +gpointer g_dataset_id_get_data (const gpointer dataset_location, + guint key_id); +void g_dataset_id_set_data_full (const gpointer dataset_location, + guint key_id, + gpointer data, + GDestroyNotify destroy_func); +void g_dataset_id_set_destroy (const gpointer dataset_location, + guint key_id, + GDestroyNotify destroy_func); + +#define g_dataset_id_set_data(l,k,d) G_STMT_START{g_dataset_id_set_data_full((l),(k),(d),NULL);}G_STMT_END +#define g_dataset_id_remove_data(l,k) G_STMT_START{g_dataset_id_set_data((l),(k),NULL);}G_STMT_END +#define g_dataset_get_data(l,k) (g_dataset_id_get_data((l),g_dataset_try_key(k))) +#define g_dataset_set_data_full(l,k,d,f) G_STMT_START{g_dataset_id_set_data_full((l),g_dataset_force_id(k),(d),(f));}G_STMT_END +#define g_dataset_set_destroy(l,k,f) G_STMT_START{g_dataset_id_set_destroy((l),g_dataset_force_id(k),(f));}G_STMT_END +#define g_dataset_set_data(l,k,d) G_STMT_START{g_dataset_set_data_full((l),(k),(d),NULL);}G_STMT_END +#define g_dataset_remove_data(l,k) G_STMT_START{g_dataset_set_data((l),(k),NULL);}G_STMT_END + + /* GScanner: Flexible lexical scanner for general purpose. - * Copyright (C) 1997 Tim Janik */ /* Character sets */ @@ -807,10 +896,6 @@ guint g_direct_hash (gpointer key); "\361\362\363\364\365\366"\ "\370\371\372\373\374\375\376\377" -typedef union _GValue GValue; -typedef struct _GScannerConfig GScannerConfig; -typedef struct _GScanner GScanner; - /* Error types */ typedef enum { @@ -936,6 +1021,8 @@ struct _GScanner guint text_len; gint input_fd; gint peeked_char; + + GScannerMsgFunc msg_handler; }; GScanner* g_scanner_new (GScannerConfig *config_templ); @@ -957,8 +1044,25 @@ void g_scanner_add_symbol (GScanner *scanner, gpointer value); gpointer g_scanner_lookup_symbol (GScanner *scanner, const gchar *symbol); +void g_scanner_foreach_symbol (GScanner *scanner, + GHFunc func, + gpointer func_data); void g_scanner_remove_symbol (GScanner *scanner, const gchar *symbol); +void g_scanner_unexp_token (GScanner *scanner, + GTokenType expected_token, + const gchar *identifier_spec, + const gchar *symbol_spec, + const gchar *symbol_name, + const gchar *message, + gint is_error); +void g_scanner_error (GScanner *scanner, + const gchar *format, + ...) G_GNUC_PRINTF (2,3); +void g_scanner_warn (GScanner *scanner, + const gchar *format, + ...) G_GNUC_PRINTF (2,3); +gint g_scanner_stat_mode (const gchar *filename); diff --git a/glib/glibconfig.h.in b/glib/glibconfig.h.in index 4d4ad2dc78..8fae1ffb7c 100644 --- a/glib/glibconfig.h.in +++ b/glib/glibconfig.h.in @@ -35,9 +35,6 @@ #undef NO_SYS_ERRLIST #undef NO_SYS_SIGLIST -/* #undef PACKAGE */ -/* #undef VERSION */ - /* The number of bytes in a char. */ #undef SIZEOF_CHAR diff --git a/glib/glist.c b/glib/glist.c index 70a97ea2db..a24751cbc3 100644 --- a/glib/glist.c +++ b/glib/glist.c @@ -33,7 +33,7 @@ static GRealListAllocator *current_allocator = NULL; GListAllocator* -g_list_allocator_new () +g_list_allocator_new (void) { GRealListAllocator* allocator = g_new (GRealListAllocator, 1); @@ -80,7 +80,7 @@ g_list_set_allocator (GListAllocator* fallocator) GList* -g_list_alloc () +g_list_alloc (void) { GList *new_list; @@ -300,6 +300,16 @@ g_list_nth (GList *list, return list; } +gpointer +g_list_nth_data (GList *list, + guint n) +{ + while ((n-- > 0) && list) + list = list->next; + + return list ? list->data : NULL; +} + GList* g_list_find (GList *list, gpointer data) @@ -314,6 +324,42 @@ g_list_find (GList *list, return list; } +gint +g_list_position (GList *list, + GList *link) +{ + gint i; + + i = 0; + while (list) + { + if (list == link) + return i; + i++; + list = list->next; + } + + return -1; +} + +gint +g_list_index (GList *list, + gpointer data) +{ + gint i; + + i = 0; + while (list) + { + if (list->data == data) + return i; + i++; + list = list->next; + } + + return -1; +} + GList* g_list_last (GList *list) { diff --git a/glib/gmem.c b/glib/gmem.c index b1498f936a..101255966a 100644 --- a/glib/gmem.c +++ b/glib/gmem.c @@ -326,7 +326,7 @@ g_free (gpointer mem) void -g_mem_profile () +g_mem_profile (void) { #ifdef MEM_PROFILE gint i; @@ -498,7 +498,6 @@ g_mem_chunk_alloc (GMemChunk *mem_chunk) if (rmem_chunk->free_mem_area) { rmem_chunk->num_mem_areas -= 1; - rmem_chunk->num_marked_areas -= 1; if (temp_area->next) temp_area->next->prev = temp_area->prev; @@ -506,13 +505,15 @@ g_mem_chunk_alloc (GMemChunk *mem_chunk) temp_area->prev->next = temp_area->next; if (temp_area == rmem_chunk->mem_areas) rmem_chunk->mem_areas = rmem_chunk->mem_areas->next; - if (temp_area == rmem_chunk->mem_area) - rmem_chunk->mem_area = NULL; + if (rmem_chunk->type == G_ALLOC_AND_FREE) + g_tree_remove (rmem_chunk->mem_tree, temp_area); g_free (temp_area); } else rmem_chunk->free_mem_area = temp_area; + + rmem_chunk->num_marked_areas -= 1; } } else @@ -562,23 +563,6 @@ g_mem_chunk_alloc (GMemChunk *mem_chunk) rmem_chunk->mem_area->allocated = 0; rmem_chunk->mem_area->mark = 0; } - else if (rmem_chunk->free_mem_area) - { - rmem_chunk->num_mem_areas -= 1; - - if (rmem_chunk->free_mem_area->next) - rmem_chunk->free_mem_area->next->prev = rmem_chunk->free_mem_area->prev; - if (rmem_chunk->free_mem_area->prev) - rmem_chunk->free_mem_area->prev->next = rmem_chunk->free_mem_area->next; - if (rmem_chunk->free_mem_area == rmem_chunk->mem_areas) - rmem_chunk->mem_areas = rmem_chunk->mem_areas->next; - - if (rmem_chunk->type == G_ALLOC_AND_FREE) - g_tree_remove (rmem_chunk->mem_tree, rmem_chunk->free_mem_area); - - g_free (rmem_chunk->free_mem_area); - rmem_chunk->free_mem_area = NULL; - } /* Get the memory and modify the state variables appropriately. */ @@ -624,12 +608,11 @@ g_mem_chunk_free (GMemChunk *mem_chunk, { temp_area->mark = 1; rmem_chunk->num_marked_areas += 1; - - g_mem_chunk_clean (mem_chunk); } } } +/* This doesn't free the free_area if there is one */ void g_mem_chunk_clean (GMemChunk *mem_chunk) { @@ -749,7 +732,7 @@ g_mem_chunk_print (GMemChunk *mem_chunk) } void -g_mem_chunk_info () +g_mem_chunk_info (void) { GRealMemChunk *mem_chunk; gint count; @@ -773,7 +756,7 @@ g_mem_chunk_info () } void -g_blow_chunks () +g_blow_chunks (void) { GRealMemChunk *mem_chunk; diff --git a/glib/gscanner.c b/glib/gscanner.c index a5d359461e..d8f7f6805a 100644 --- a/glib/gscanner.c +++ b/glib/gscanner.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald * * GScanner: Flexible lexical scanner for general purpose. - * Copyright (C) 1997 Tim Janik + * Copyright (C) 1997, 1998 Tim Janik * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -22,9 +22,13 @@ #define __gscanner_c__ #include <stdlib.h> +#include <stdarg.h> #include <string.h> +#include <stdio.h> #include <unistd.h> #include <errno.h> +#include <sys/types.h> /* needed for sys/stat.h */ +#include <sys/stat.h> #include "glib.h" @@ -32,9 +36,9 @@ /* --- defines --- */ #define to_lower(c) ( \ (guchar) ( \ - ( (((guchar)(c))>='A' && ((guchar)(c))<='Z') * ('a'-'A') ) + \ - ( (((guchar)(c))>=192 && ((guchar)(c))<=214) * (224-192) ) + \ - ( (((guchar)(c))>=216 && ((guchar)(c))<=222) * (248-216) ) + \ + ( (((guchar)(c))>='A' && ((guchar)(c))<='Z') * ('a'-'A') ) | \ + ( (((guchar)(c))>=192 && ((guchar)(c))<=214) * (224-192) ) | \ + ( (((guchar)(c))>=216 && ((guchar)(c))<=222) * (248-216) ) | \ ((guchar)(c)) \ ) \ ) @@ -96,6 +100,7 @@ static GScannerConfig g_scanner_config_template = /* --- prototypes --- */ +extern char* g_vsprintf (gchar *fmt, va_list *args, va_list *args2); static GScannerHashVal* g_scanner_lookup_internal (GScanner *scanner, const gchar *symbol); static void g_scanner_get_token_ll (GScanner *scanner, @@ -118,6 +123,9 @@ static guchar g_scanner_peek_next_char(GScanner *scanner); static guchar g_scanner_get_char (GScanner *scanner, guint *line_p, guint *position_p); +static void g_scanner_msg_handler (GScanner *scanner, + gchar *message, + gint is_error); /* --- functions --- */ @@ -197,6 +205,8 @@ g_scanner_new (GScannerConfig *config_templ) scanner->text_len = 0; scanner->input_fd = -1; scanner->peeked_char = -1; + + scanner->msg_handler = g_scanner_msg_handler; return scanner; } @@ -224,6 +234,75 @@ g_scanner_destroy (GScanner *scanner) g_free (scanner); } +static void +g_scanner_msg_handler (GScanner *scanner, + gchar *message, + gint is_error) +{ + g_return_if_fail (scanner != NULL); + + fprintf (stdout, "%s:%d: ", scanner->input_name, scanner->line); + if (is_error) + fprintf (stdout, "error: "); + fprintf (stdout, "%s\n", message); +} + +void +g_scanner_error (GScanner *scanner, + const gchar *format, + ...) +{ + g_return_if_fail (scanner != NULL); + g_return_if_fail (format != NULL); + + scanner->parse_errors++; + + if (scanner->msg_handler) + { + va_list args, args2; + gchar *string; + + va_start (args, format); + va_start (args2, format); + string = g_vsprintf ((gchar*) format, &args, &args2); + va_end (args); + va_end (args2); + + string = g_strdup (string); + + scanner->msg_handler (scanner, string, TRUE); + + g_free (string); + } +} + +void +g_scanner_warn (GScanner *scanner, + const gchar *format, + ...) +{ + g_return_if_fail (scanner != NULL); + g_return_if_fail (format != NULL); + + if (scanner->msg_handler) + { + va_list args, args2; + gchar *string; + + va_start (args, format); + va_start (args2, format); + string = g_vsprintf ((gchar*) format, &args, &args2); + va_end (args); + va_end (args2); + + string = g_strdup (string); + + scanner->msg_handler (scanner, string, FALSE); + + g_free (string); + } +} + void g_scanner_input_file (GScanner *scanner, gint input_fd) @@ -245,7 +324,7 @@ g_scanner_input_file (GScanner *scanner, void g_scanner_input_text (GScanner *scanner, const gchar *text, - guint text_len) + guint text_len) { g_return_if_fail (text != NULL); @@ -311,6 +390,39 @@ g_scanner_lookup_symbol (GScanner *scanner, return NULL; } +static void +g_scanner_foreach_internal (gpointer key, + gpointer value, + gpointer user_data) +{ + register GScannerHashVal *hash_val; + register GHFunc func; + register gpointer func_data; + register gpointer *d; + + d = user_data; + func = d[0]; + func_data = d[1]; + hash_val = value; + + func (key, hash_val->value, func_data); +} + +void +g_scanner_foreach_symbol (GScanner *scanner, + GHFunc func, + gpointer func_data) +{ + gpointer d[2]; + + g_return_if_fail (scanner != NULL); + + d[0] = func; + d[1] = func_data; + + g_hash_table_foreach (scanner->symbol_table, g_scanner_foreach_internal, d); +} + void g_scanner_remove_symbol (GScanner *scanner, const gchar *symbol) @@ -530,6 +642,277 @@ g_scanner_get_char (GScanner *scanner, return fchar; } +void +g_scanner_unexp_token (GScanner *scanner, + GTokenType expected_token, + const gchar *identifier_spec, + const gchar *symbol_spec, + const gchar *symbol_name, + const gchar *message, + gint is_error) +{ + register gchar *token_string; + register guint token_string_len; + register gchar *expected_string; + register guint expected_string_len; + register gchar *message_prefix; + register gboolean print_unexp; + void (*msg_handler) (GScanner*, const gchar*, ...); + + g_return_if_fail (scanner != NULL); + + if (is_error) + msg_handler = g_scanner_error; + else + msg_handler = g_scanner_warn; + + if (!identifier_spec) + identifier_spec = "identifier"; + if (!symbol_spec) + symbol_spec = "symbol"; + + token_string_len = 56; + token_string = g_new (gchar, token_string_len + 1); + expected_string_len = 64; + expected_string = g_new (gchar, expected_string_len + 1); + print_unexp = TRUE; + + switch (scanner->token) + { + + case G_TOKEN_EOF: + g_snprintf (token_string, token_string_len, "end of file"); + break; + + default: /* 1 ... 255 */ + if (scanner->token >= 1 && scanner->token <= 255) + { + if ((scanner->token >= ' ' && scanner->token <= '~') || + strchr (scanner->config->cset_identifier_first, scanner->token) || + strchr (scanner->config->cset_identifier_nth, scanner->token)) + g_snprintf (token_string, expected_string_len, "character `%c'", scanner->token); + else + g_snprintf (token_string, expected_string_len, "character `\\%o'", scanner->token); + } + else + g_snprintf (token_string, token_string_len, "(unknown) token <%d>", scanner->token); + break; + + case G_TOKEN_ERROR: + print_unexp = FALSE; + expected_token = G_TOKEN_NONE; + switch (scanner->value.v_error) + { + case G_ERR_UNEXP_EOF: + g_snprintf (token_string, token_string_len, "scanner: unexpected end of file"); + break; + + case G_ERR_UNEXP_EOF_IN_STRING: + g_snprintf (token_string, token_string_len, "scanner: unterminated string constant"); + break; + + case G_ERR_UNEXP_EOF_IN_COMMENT: + g_snprintf (token_string, token_string_len, "scanner: unterminated comment"); + break; + + case G_ERR_NON_DIGIT_IN_CONST: + g_snprintf (token_string, token_string_len, "scanner: non digit in constant"); + break; + + case G_ERR_FLOAT_RADIX: + g_snprintf (token_string, token_string_len, "scanner: invalid radix for floating constant"); + break; + + case G_ERR_FLOAT_MALFORMED: + g_snprintf (token_string, token_string_len, "scanner: malformed floating constant"); + break; + + case G_ERR_DIGIT_RADIX: + g_snprintf (token_string, token_string_len, "scanner: digit is beyond radix"); + break; + + case G_ERR_UNKNOWN: + default: + g_snprintf (token_string, token_string_len, "scanner: unknown error"); + break; + } + break; + + case G_TOKEN_CHAR: + g_snprintf (token_string, token_string_len, "character `%c'", scanner->value.v_char); + break; + + case G_TOKEN_SYMBOL: + if (expected_token == G_TOKEN_SYMBOL) + print_unexp = FALSE; + if (symbol_name) + g_snprintf (token_string, + token_string_len, + "%s%s `%s'", + print_unexp ? "" : "invalid ", + symbol_spec, + symbol_name); + else + g_snprintf (token_string, + token_string_len, + "%s%s", + print_unexp ? "" : "invalid ", + symbol_spec); + break; + + case G_TOKEN_IDENTIFIER: + if (expected_token == G_TOKEN_IDENTIFIER) + print_unexp = FALSE; + g_snprintf (token_string, + token_string_len, + "%s%s `%s'", + print_unexp ? "" : "invalid ", + identifier_spec, + scanner->value.v_string); + break; + + case G_TOKEN_BINARY: + case G_TOKEN_OCTAL: + case G_TOKEN_INT: + case G_TOKEN_HEX: + g_snprintf (token_string, token_string_len, "number `%ld'", scanner->value.v_int); + break; + + case G_TOKEN_FLOAT: + g_snprintf (token_string, token_string_len, "number `%.3f'", scanner->value.v_float); + break; + + case G_TOKEN_STRING: + g_snprintf (token_string, + token_string_len, + "%sstring constant \"%s\"", + scanner->value.v_string[0] == 0 ? "empty " : "", + scanner->value.v_string); + token_string[token_string_len - 2] = '"'; + token_string[token_string_len - 1] = 0; + break; + + case G_TOKEN_COMMENT_SINGLE: + case G_TOKEN_COMMENT_MULTI: + g_snprintf (token_string, token_string_len, "comment"); + break; + + case G_TOKEN_NONE: + g_assert_not_reached (); + break; + } + + + switch (expected_token) + { + default: /* 1 ... 255 */ + if (expected_token >= 1 && expected_token <= 255) + { + if ((expected_token >= ' ' && expected_token <= '~') || + strchr (scanner->config->cset_identifier_first, expected_token) || + strchr (scanner->config->cset_identifier_nth, expected_token)) + g_snprintf (expected_string, expected_string_len, "character `%c'", expected_token); + else + g_snprintf (expected_string, expected_string_len, "character `\\%o'", expected_token); + } + else + g_snprintf (expected_string, expected_string_len, "(unknown) token <%d>", expected_token); + break; + + case G_TOKEN_INT: + g_snprintf (expected_string, expected_string_len, "number (integer)"); + break; + + case G_TOKEN_FLOAT: + g_snprintf (expected_string, expected_string_len, "number (float)"); + break; + + case G_TOKEN_STRING: + g_snprintf (expected_string, expected_string_len, "string constant"); + break; + + case G_TOKEN_SYMBOL: + g_snprintf (expected_string, + expected_string_len, + "%s%s", + scanner->token == G_TOKEN_SYMBOL ? "valid " : "", + symbol_spec); + break; + + case G_TOKEN_IDENTIFIER: + g_snprintf (expected_string, + expected_string_len, + "%s%s", + scanner->token == G_TOKEN_IDENTIFIER ? "valid " : "", + identifier_spec); + break; + + case G_TOKEN_NONE: + break; + } + + if (message && message[0] != 0) + message_prefix = " - "; + else + { + message_prefix = ""; + message = ""; + } + + if (expected_token != G_TOKEN_NONE) + { + if (print_unexp) + msg_handler (scanner, + "unexpected %s, expected %s%s%s", + token_string, + expected_string, + message_prefix, + message); + else + msg_handler (scanner, + "%s, expected %s%s%s", + token_string, + expected_string, + message_prefix, + message); + } + else + { + if (print_unexp) + msg_handler (scanner, + "unexpected %s%s%s", + token_string, + message_prefix, + message); + else + msg_handler (scanner, + "%s%s%s", + token_string, + message_prefix, + message); + } + + g_free (token_string); + g_free (expected_string); +} + +gint +g_scanner_stat_mode (const gchar *filename) +{ + struct stat *stat_buf; + gint st_mode; + + stat_buf = g_new0 (struct stat, 1); + + lstat (filename, stat_buf); + + st_mode = stat_buf->st_mode; + + g_free (stat_buf); + + return st_mode; +} + static void g_scanner_free_value (GTokenType *token_p, GValue *value_p) diff --git a/glib/gslist.c b/glib/gslist.c index 7045687ca2..636dd37dc4 100644 --- a/glib/gslist.c +++ b/glib/gslist.c @@ -57,7 +57,7 @@ g_slist_set_allocator (GListAllocator* fallocator) GSList* -g_slist_alloc () +g_slist_alloc (void) { GSList *new_list; @@ -289,6 +289,16 @@ g_slist_nth (GSList *list, return list; } +gpointer +g_slist_nth_data (GSList *list, + guint n) +{ + while ((n-- > 0) && list) + list = list->next; + + return list ? list->data : NULL; +} + GSList* g_slist_find (GSList *list, gpointer data) @@ -303,6 +313,42 @@ g_slist_find (GSList *list, return list; } +gint +g_slist_position (GSList *list, + GSList *link) +{ + gint i; + + i = 0; + while (list) + { + if (list == link) + return i; + i++; + list = list->next; + } + + return -1; +} + +gint +g_slist_index (GSList *list, + gpointer data) +{ + gint i; + + i = 0; + while (list) + { + if (list->data == data) + return i; + i++; + list = list->next; + } + + return -1; +} + GSList* g_slist_last (GSList *list) { diff --git a/glib/gstring.c b/glib/gstring.c index fc0780e2b4..91a5e1e2c9 100644 --- a/glib/gstring.c +++ b/glib/gstring.c @@ -21,6 +21,7 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> +#include <ctype.h> typedef struct _GRealStringChunk GRealStringChunk; @@ -101,6 +102,8 @@ g_string_chunk_free (GStringChunk *fchunk) GRealStringChunk *chunk = (GRealStringChunk*) fchunk; GSList *tmp_list; + g_return_if_fail (chunk != NULL); + if (chunk->storage_list) { GListAllocator *tmp_allocator = g_slist_set_allocator (NULL); @@ -121,12 +124,14 @@ g_string_chunk_free (GStringChunk *fchunk) gchar* g_string_chunk_insert (GStringChunk *fchunk, - gchar* string) + const gchar *string) { GRealStringChunk *chunk = (GRealStringChunk*) fchunk; gint len = strlen (string); char* pos; + g_return_val_if_fail (chunk != NULL, NULL); + if ((chunk->storage_next + len + 1) > chunk->this_size) { GListAllocator *tmp_allocator = g_slist_set_allocator (NULL); @@ -155,15 +160,17 @@ g_string_chunk_insert (GStringChunk *fchunk, gchar* g_string_chunk_insert_const (GStringChunk *fchunk, - gchar* string) + const gchar *string) { GRealStringChunk *chunk = (GRealStringChunk*) fchunk; char* lookup; + g_return_val_if_fail (chunk != NULL, NULL); + if (!chunk->const_table) chunk->const_table = g_hash_table_new (g_str_hash, g_str_equal); - lookup = (char*) g_hash_table_lookup (chunk->const_table, string); + lookup = (char*) g_hash_table_lookup (chunk->const_table, (gchar *)string); if (!lookup) { @@ -198,7 +205,7 @@ g_string_maybe_expand (GRealString* string, gint len) } GString* -g_string_new (gchar *init) +g_string_new (const gchar *init) { GRealString *string; @@ -220,8 +227,11 @@ g_string_new (gchar *init) } void -g_string_free (GString *string, gint free_segment) +g_string_free (GString *string, + gint free_segment) { + g_return_if_fail (string != NULL); + if (free_segment) g_free (string->str); @@ -230,7 +240,7 @@ g_string_free (GString *string, gint free_segment) GString* g_string_assign (GString *lval, - char *rval) + const gchar *rval) { g_string_truncate (lval, 0); g_string_append (lval, rval); @@ -239,10 +249,13 @@ g_string_assign (GString *lval, } GString* -g_string_truncate (GString* fstring, gint len) +g_string_truncate (GString* fstring, + gint len) { GRealString *string = (GRealString*)fstring; + g_return_val_if_fail (string != NULL, NULL); + string->len = len; string->str[len] = 0; @@ -251,11 +264,16 @@ g_string_truncate (GString* fstring, gint len) } GString* -g_string_append (GString *fstring, gchar *val) +g_string_append (GString *fstring, + const gchar *val) { GRealString *string = (GRealString*)fstring; - int len = strlen (val); + int len; + g_return_val_if_fail (string != NULL, NULL); + g_return_val_if_fail (val != NULL, fstring); + + len = strlen (val); g_string_maybe_expand (string, len); strcpy (string->str + string->len, val); @@ -266,10 +284,12 @@ g_string_append (GString *fstring, gchar *val) } GString* -g_string_append_c (GString *fstring, char c) +g_string_append_c (GString *fstring, + gchar c) { GRealString *string = (GRealString*)fstring; + g_return_val_if_fail (string != NULL, NULL); g_string_maybe_expand (string, 1); string->str[string->len++] = c; @@ -279,11 +299,16 @@ g_string_append_c (GString *fstring, char c) } GString* -g_string_prepend (GString *fstring, gchar *val) +g_string_prepend (GString *fstring, + const gchar *val) { GRealString *string = (GRealString*)fstring; - gint len = strlen (val); + gint len; + + g_return_val_if_fail (string != NULL, NULL); + g_return_val_if_fail (val != NULL, fstring); + len = strlen (val); g_string_maybe_expand (string, len); g_memmove (string->str + len, string->str, string->len); @@ -298,10 +323,12 @@ g_string_prepend (GString *fstring, gchar *val) } GString* -g_string_prepend_c (GString *fstring, char c) +g_string_prepend_c (GString *fstring, + gchar c) { GRealString *string = (GRealString*)fstring; + g_return_val_if_fail (string != NULL, NULL); g_string_maybe_expand (string, 1); g_memmove (string->str + 1, string->str, string->len); @@ -315,14 +342,20 @@ g_string_prepend_c (GString *fstring, char c) return fstring; } -GString * -g_string_insert (GString *fstring, gint pos, gchar *val) +GString* +g_string_insert (GString *fstring, + gint pos, + const gchar *val) { GRealString *string = (GRealString*)fstring; - gint len = strlen (val); + gint len; + g_return_val_if_fail (string != NULL, NULL); + g_return_val_if_fail (val != NULL, fstring); + g_return_val_if_fail (pos >= 0, fstring); g_return_val_if_fail (pos <= string->len, fstring); + len = strlen (val); g_string_maybe_expand (string, len); g_memmove (string->str + pos + len, string->str + pos, string->len - pos); @@ -337,10 +370,13 @@ g_string_insert (GString *fstring, gint pos, gchar *val) } GString * -g_string_insert_c (GString *fstring, gint pos, gchar c) +g_string_insert_c (GString *fstring, + gint pos, + gchar c) { GRealString *string = (GRealString*)fstring; + g_return_val_if_fail (string != NULL, NULL); g_return_val_if_fail (pos <= string->len, fstring); g_string_maybe_expand (string, 1); @@ -356,15 +392,21 @@ g_string_insert_c (GString *fstring, gint pos, gchar c) return fstring; } -GString * -g_string_erase (GString *fstring, gint pos, gint len) +GString* +g_string_erase (GString *fstring, + gint pos, + gint len) { GRealString *string = (GRealString*)fstring; + g_return_val_if_fail (string != NULL, NULL); + g_return_val_if_fail (len >= 0, fstring); + g_return_val_if_fail (pos >= 0, fstring); g_return_val_if_fail (pos <= string->len, fstring); g_return_val_if_fail (pos + len <= string->len, fstring); - g_memmove (string->str + pos, string->str + pos + len, string->len - (pos + len)); + if (pos + len < string->len) + g_memmove (string->str + pos, string->str + pos + len, string->len - (pos + len)); string->len -= len; @@ -373,6 +415,44 @@ g_string_erase (GString *fstring, gint pos, gint len) return fstring; } +GString* +g_string_down (GString *fstring) +{ + GRealString *string = (GRealString*)fstring; + gchar *s; + + g_return_val_if_fail (string != NULL, NULL); + + s = string->str; + + while (*s) + { + *s = tolower (*s); + s++; + } + + return fstring; +} + +GString* +g_string_up (GString *fstring) +{ + GRealString *string = (GRealString*)fstring; + gchar *s; + + g_return_val_if_fail (string != NULL, NULL); + + s = string->str; + + while (*s) + { + *s = toupper (*s); + s++; + } + + return fstring; +} + static int get_length_upper_bound (const gchar* fmt, va_list *args) { @@ -512,7 +592,7 @@ g_vsprintf (const gchar *fmt, static void g_string_sprintfa_int (GString *string, - gchar *fmt, + const gchar *fmt, va_list *args, va_list *args2) { @@ -520,7 +600,9 @@ g_string_sprintfa_int (GString *string, } void -g_string_sprintf (GString *string, gchar *fmt, ...) +g_string_sprintf (GString *string, + const gchar *fmt, + ...) { va_list args, args2; @@ -536,7 +618,9 @@ g_string_sprintf (GString *string, gchar *fmt, ...) } void -g_string_sprintfa (GString *string, gchar *fmt, ...) +g_string_sprintfa (GString *string, + const gchar *fmt, + ...) { va_list args, args2; diff --git a/glib/gtimer.c b/glib/gtimer.c index 860c76cffb..47946b39b5 100644 --- a/glib/gtimer.c +++ b/glib/gtimer.c @@ -32,7 +32,7 @@ struct _GRealTimer GTimer* -g_timer_new () +g_timer_new (void) { GRealTimer *timer; diff --git a/glib/gutils.c b/glib/gutils.c index e23280ff62..ef51134828 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -25,13 +25,6 @@ #include "glib.h" -static GErrorFunc glib_error_func = NULL; -static GWarningFunc glib_warning_func = NULL; -static GPrintFunc glib_message_func = NULL; -static GPrintFunc glib_print_func = NULL; - -extern char* g_vsprintf (const gchar *fmt, va_list *args, va_list *args2); - gchar* g_strdup (const gchar *str) { @@ -577,85 +570,85 @@ g_strsignal (gint signum) case SIGQUIT: return "Quit"; #endif #ifdef SIGILL - case SIGILL: "Illegal instruction"; + case SIGILL: return "Illegal instruction"; #endif #ifdef SIGTRAP - case SIGTRAP: "Trace/breakpoint trap"; + case SIGTRAP: return "Trace/breakpoint trap"; #endif #ifdef SIGABRT - case SIGABRT: "IOT trap/Abort"; + case SIGABRT: return "IOT trap/Abort"; #endif #ifdef SIGBUS - case SIGBUS: "Bus error"; + case SIGBUS: return "Bus error"; #endif #ifdef SIGFPE - case SIGFPE: "Floating point exception"; + case SIGFPE: return "Floating point exception"; #endif #ifdef SIGKILL - case SIGKILL: "Killed"; + case SIGKILL: return "Killed"; #endif #ifdef SIGUSR1 - case SIGUSR1: "User defined signal 1"; + case SIGUSR1: return "User defined signal 1"; #endif #ifdef SIGSEGV - case SIGSEGV: "Segmentation fault"; + case SIGSEGV: return "Segmentation fault"; #endif #ifdef SIGUSR2 - case SIGUSR2: "User defined signal 2"; + case SIGUSR2: return "User defined signal 2"; #endif #ifdef SIGPIPE - case SIGPIPE: "Broken pipe"; + case SIGPIPE: return "Broken pipe"; #endif #ifdef SIGALRM - case SIGALRM: "Alarm clock"; + case SIGALRM: return "Alarm clock"; #endif #ifdef SIGTERM - case SIGTERM: "Terminated"; + case SIGTERM: return "Terminated"; #endif #ifdef SIGSTKFLT - case SIGSTKFLT: "Stack fault"; + case SIGSTKFLT: return "Stack fault"; #endif #ifdef SIGCHLD - case SIGCHLD: "Child exited"; + case SIGCHLD: return "Child exited"; #endif #ifdef SIGCONT - case SIGCONT: "Continued"; + case SIGCONT: return "Continued"; #endif #ifdef SIGSTOP - case SIGSTOP: "Stopped (signal)"; + case SIGSTOP: return "Stopped (signal)"; #endif #ifdef SIGTSTP - case SIGTSTP: "Stopped"; + case SIGTSTP: return "Stopped"; #endif #ifdef SIGTTIN - case SIGTTIN: "Stopped (tty input)"; + case SIGTTIN: return "Stopped (tty input)"; #endif #ifdef SIGTTOU - case SIGTTOU: "Stopped (tty output)"; + case SIGTTOU: return "Stopped (tty output)"; #endif #ifdef SIGURG - case SIGURG: "Urgent condition"; + case SIGURG: return "Urgent condition"; #endif #ifdef SIGXCPU - case SIGXCPU: "CPU time limit exceeded"; + case SIGXCPU: return "CPU time limit exceeded"; #endif #ifdef SIGXFSZ - case SIGXFSZ: "File size limit exceeded"; + case SIGXFSZ: return "File size limit exceeded"; #endif #ifdef SIGVTALRM - case SIGVTALRM: "Virtual time alarm"; + case SIGVTALRM: return "Virtual time alarm"; #endif #ifdef SIGPROF - case SIGPROF: "Profile signal"; + case SIGPROF: return "Profile signal"; #endif #ifdef SIGWINCH - case SIGWINCH: "Window size changed"; + case SIGWINCH: return "Window size changed"; #endif #ifdef SIGIO - case SIGIO: "Possible I/O"; + case SIGIO: return "Possible I/O"; #endif #ifdef SIGPWR - case SIGPWR: "Power failure"; + case SIGPWR: return "Power failure"; #endif #ifdef SIGUNUSED case SIGUNUSED: return "Unused signal"; @@ -670,146 +663,6 @@ g_strsignal (gint signum) return msg; } -void -g_error (gchar *format, ...) -{ - va_list args, args2; - char *buf; - - va_start (args, format); - va_start (args2, format); - buf = g_vsprintf (format, &args, &args2); - va_end (args); - va_end (args2); - - if (glib_error_func) - { - (* glib_error_func) (buf); - } - else - { - fputs ("\n** ERROR **: ", stderr); - fputs (buf, stderr); - fputc ('\n', stderr); - } - - abort (); -} - -void -g_warning (gchar *format, ...) -{ - va_list args, args2; - char *buf; - - va_start (args, format); - va_start (args2, format); - buf = g_vsprintf (format, &args, &args2); - va_end (args); - va_end (args2); - - if (glib_warning_func) - { - (* glib_warning_func) (buf); - } - else - { - fputs ("\n** WARNING **: ", stderr); - fputs (buf, stderr); - fputc ('\n', stderr); - } -} - -void -g_message (gchar *format, ...) -{ - va_list args, args2; - char *buf; - - va_start (args, format); - va_start (args2, format); - buf = g_vsprintf (format, &args, &args2); - va_end (args); - va_end (args2); - - if (glib_message_func) - { - (* glib_message_func) (buf); - } - else - { - fputs ("message: ", stdout); - fputs (buf, stdout); - fputc ('\n', stdout); - } -} - -void -g_print (gchar *format, ...) -{ - va_list args, args2; - char *buf; - - va_start (args, format); - va_start (args2, format); - buf = g_vsprintf (format, &args, &args2); - va_end (args); - va_end (args2); - - if (glib_print_func) - { - (* glib_print_func) (buf); - } - else - { - fputs (buf, stdout); - } -} - -GErrorFunc -g_set_error_handler (GErrorFunc func) -{ - GErrorFunc old_error_func; - - old_error_func = glib_error_func; - glib_error_func = func; - - return old_error_func; -} - -GWarningFunc -g_set_warning_handler (GWarningFunc func) -{ - GWarningFunc old_warning_func; - - old_warning_func = glib_warning_func; - glib_warning_func = func; - - return old_warning_func; -} - -GPrintFunc -g_set_message_handler (GPrintFunc func) -{ - GPrintFunc old_message_func; - - old_message_func = glib_message_func; - glib_message_func = func; - - return old_message_func; -} - -GPrintFunc -g_set_print_handler (GPrintFunc func) -{ - GPrintFunc old_print_func; - - old_print_func = glib_print_func; - glib_print_func = func; - - return old_print_func; -} - gint g_snprintf (gchar *str, gulong n, @@ -845,25 +698,82 @@ g_snprintf (gchar *str, #endif } +void +g_strdown (gchar *string) +{ + register gchar *s; + + g_return_if_fail (string != NULL); + + s = string; + + while (*s) + { + *s = tolower (*s); + s++; + } +} + +void +g_strup (gchar *string) +{ + register gchar *s; + + g_return_if_fail (string != NULL); + + s = string; + + while (*s) + { + *s = toupper (*s); + s++; + } +} + gint -g_strcasecmp (const gchar *s1, const gchar *s2) +g_strcasecmp (const gchar *s1, + const gchar *s2) { #ifdef HAVE_STRCASECMP - return strcasecmp(s1, s2); + return strcasecmp (s1, s2); #else gint c1, c2; while (*s1 && *s2) { - c1 = tolower((guchar)(*s1++)); c2 = tolower((guchar)(*s2++)); + /* According to A. Cox, some platforms have islower's that + * don't work right on non-uppercase + */ + c1 = isupper ((guchar)*s1) ? tolower ((guchar)*s1) : *s1; + c2 = isupper ((guchar)*s2) ? tolower ((guchar)*s2) : *s2; if (c1 != c2) return (c1 - c2); + s1++; s2++; } return (((gint)(guchar) *s1) - ((gint)(guchar) *s2)); #endif } +void +g_strdelimit (gchar *string, + const gchar *delimiters, + gchar new_delim) +{ + register gchar *c; + + g_return_if_fail (string != NULL); + + if (!delimiters) + delimiters = G_STR_DELIMITERS; + + for (c = string; *c; c++) + { + if (strchr (delimiters, *c)) + *c = new_delim; + } +} + guint g_parse_debug_string (const gchar *string, GDebugKey *keys, @@ -913,6 +823,6 @@ g_parse_debug_string (const gchar *string, guint g_direct_hash(gpointer key) { - return (guint) key; + return GPOINTER_TO_UINT (key); } diff --git a/glib/ltconfig b/glib/ltconfig index 7ebb9be8c0..878a7c8122 100755 --- a/glib/ltconfig +++ b/glib/ltconfig @@ -32,23 +32,43 @@ if test "${CDPATH+set}" = set; then CDPATH=; export CDPATH; fi echo=echo if test "X`($echo '\t') 2>/dev/null`" = 'X\t'; then : else - # The Solaris and AIX default echo program unquotes backslashes. - # This makes it impossible to quote backslashes using + # The Solaris, AIX, and Digital Unix default echo programs unquote + # backslashes. This makes it impossible to quote backslashes using # echo "$something" | sed 's/\\/\\\\/g' - # So, we emulate echo with printf '%s\n' - echo="printf %s\\n" - if test "X`($echo '\t') 2>/dev/null`" = 'X\t'; then : - else - # Oops. We have no working printf. Try to find a not-so-buggy echo. - echo=echo - IFS="${IFS= }"; save_ifs="$IFS"; IFS="${IFS}:" - for dir in $PATH /usr/ucb; do - if test -f $dir/echo && test "X`$dir/echo '\t'`" = 'X\t'; then - echo="$dir/echo" - break + # + # So, first we look for a working echo in the user's PATH. + IFS="${IFS= }"; save_ifs="$IFS"; IFS="${IFS}:" + for dir in $PATH /usr/ucb; do + if test -f $dir/echo && test "X`($dir/echo '\t') 2>/dev/null`" = 'X\t'; then + echo="$dir/echo" + break + fi + done + IFS="$save_ifs" + + if test "X$echo" = Xecho; then + # We didn't find a better echo, so look for alternatives. + if test "X`(print -r '\t') 2>/dev/null`" = 'X\t'; then + # This shell has a builtin print -r that does the trick. + echo='print -r' +# +# The following is from libtool-1.2a, won't work with this patched +# libtool-1.2 +# +# elif test -f /bin/ksh && test "X$CONFIG_SHELL" != X/bin/ksh; then +# # If we have ksh, try running ltconfig again with it. +# CONFIG_SHELL=/bin/ksh +# export CONFIG_SHELL +# exec "$CONFIG_SHELL" "$0" --no-reexec ${1+"$@"} + else + # Try using printf. + echo='printf %s\n' + if test "X`($echo '\t') 2>/dev/null`" = 'X\t'; then : + else + # Oops. We lost completely, so just stick with echo. + echo=echo fi - done - IFS="$save_ifs" + fi fi fi @@ -66,7 +86,7 @@ progname=`$echo "X$0" | $Xsed -e 's%^.*/%%'` # Constants: PROGRAM=ltconfig PACKAGE=libtool -VERSION=1.1 +VERSION=1.2 ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.c 1>&5' ac_link='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest.c $LIBS 1>&5' rm="rm -f" @@ -421,7 +441,7 @@ if test "$with_gcc" != yes || test -z "$CC"; then # Now see if the compiler is really GCC. with_gcc=no echo $ac_n "checking whether we are using GNU C... $ac_c" 1>&6 - echo "$progname:424: checking whether we are using GNU C" >&5 + echo "$progname:444: checking whether we are using GNU C" >&5 $rm conftest.c cat > conftest.c <<EOF @@ -429,7 +449,7 @@ if test "$with_gcc" != yes || test -z "$CC"; then yes; #endif EOF - if { ac_try='${CC-cc} -E conftest.c'; { (eval echo $progname:432: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then + if { ac_try='${CC-cc} -E conftest.c'; { (eval echo $progname:452: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then with_gcc=yes fi $rm conftest.c @@ -544,14 +564,15 @@ if test -n "$pic_flag"; then echo > conftest.c save_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS $pic_flag -DPIC" - echo "$progname:547: checking if $compiler PIC flag $pic_flag works" >&5 - if { (eval echo $progname:548: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>conftest.err; } && test -s conftest.o; then - # Append any errors to the config.log. + echo "$progname:567: checking if $compiler PIC flag $pic_flag works" >&5 + if { (eval echo $progname:568: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>conftest.err; } && test -s conftest.o; then + # Append any warnings to the config.log. cat conftest.err 1>&5 - # On HP-UX, the stripped-down bundled CC does not accept +Z, but also - # reports no error. So, we need to grep stderr for (Bundled). - if grep '(Bundled)' conftest.err >/dev/null; then + # On HP-UX, both CC and GCC only warn that PIC is supported... then they + # create non-PIC objects. So, if there were any warnings, we assume that + # PIC is not supported. + if test -s conftest.err; then echo "$ac_t"no 1>&6 can_build_shared=no pic_flag= @@ -587,8 +608,8 @@ $rm conftest* echo 'main(){return(0);}' > conftest.c save_LDFLAGS="$LDFLAGS" LDFLAGS="$LDFLAGS $link_static_flag" -echo "$progname:590: checking if $compiler static flag $link_static_flag works" >&5 -if { (eval echo $progname:591: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +echo "$progname:611: checking if $compiler static flag $link_static_flag works" >&5 +if { (eval echo $progname:612: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then echo "$ac_t$link_static_flag" 1>&6 else echo "$ac_t"none 1>&6 @@ -620,7 +641,7 @@ if test -z "$LD"; then if test "$with_gcc" = yes; then # Check if gcc -print-prog-name=ld gives a path. echo $ac_n "checking for ld used by GCC... $ac_c" 1>&6 - echo "$progname:623: checking for ld used by GCC" >&5 + echo "$progname:644: checking for ld used by GCC" >&5 ac_prog=`($CC -print-prog-name=ld) 2>&5` case "$ac_prog" in # Accept absolute paths. @@ -638,10 +659,10 @@ if test -z "$LD"; then esac elif test "$with_gnu_ld" = yes; then echo $ac_n "checking for GNU ld... $ac_c" 1>&6 - echo "$progname:641: checking for GNU ld" >&5 + echo "$progname:662: checking for GNU ld" >&5 else echo $ac_n "checking for non-GNU ld""... $ac_c" 1>&6 - echo "$progname:644: checking for non-GNU ld" >&5 + echo "$progname:665: checking for non-GNU ld" >&5 fi if test -z "$LD"; then @@ -967,11 +988,11 @@ void nm_test_func(){} main(){nm_test_var='a';nm_test_func();return(0);} EOF -echo "$progname:970: checking if global_symbol_pipe works" >&5 -if { (eval echo $progname:971: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; } && test -s conftest.o; then +echo "$progname:991: checking if global_symbol_pipe works" >&5 +if { (eval echo $progname:992: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; } && test -s conftest.o; then # Now try to grab the symbols. nlist=conftest.nm - if { echo "$progname:974: eval \"$NM conftest.o | $global_symbol_pipe > $nlist\"" >&5; eval "$NM conftest.o | $global_symbol_pipe > $nlist 2>&5"; } && test -s "$nlist"; then + if { echo "$progname:995: eval \"$NM conftest.o | $global_symbol_pipe > $nlist\"" >&5; eval "$NM conftest.o | $global_symbol_pipe > $nlist 2>&5"; } && test -s "$nlist"; then # Try sorting and uniquifying the output. if sort "$nlist" | uniq > "$nlist"T; then @@ -1029,7 +1050,7 @@ EOF save_CFLAGS="$CFLAGS" LIBS='conftestm.o' CFLAGS="$CFLAGS$no_builtin_flag" - if { (eval echo $progname:1032: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then + if { (eval echo $progname:1053: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then pipe_works=yes else echo "$progname: failed program was:" >&5 diff --git a/glib/ltmain.sh b/glib/ltmain.sh index 9b8e94784b..0e884205b8 100644 --- a/glib/ltmain.sh +++ b/glib/ltmain.sh @@ -30,7 +30,7 @@ modename="$progname" # Constants. PROGRAM=ltmain.sh PACKAGE=libtool -VERSION=1.1 +VERSION=1.2 default_mode= help="Try \`$progname --help' for more information." @@ -386,6 +386,7 @@ if test -z "$show_help"; then prev= prevarg= release= + postfix= rpath= perm_rpath= temp_rpath= @@ -437,6 +438,11 @@ if test -z "$show_help"; then prev= continue ;; + postfix) + postfix="-$arg" + prev= + continue + ;; rpath) rpath="$rpath $arg" prev= @@ -481,7 +487,7 @@ if test -z "$show_help"; then if test "$export_dynamic" != yes; then export_dynamic=yes if test -n "$export_dynamic_flag_spec"; then - arg=`eval \\$echo "$export_dynamic_flag_spec"` + eval arg=\"$export_dynamic_flag_spec\" else arg= fi @@ -520,6 +526,11 @@ if test -z "$show_help"; then continue ;; + -postfix) + prev=postfix + continue + ;; + -rpath) prev=rpath continue @@ -682,7 +693,7 @@ if test -z "$show_help"; then fi if test -n "$libdir"; then - flag=`eval \\$echo \"$hardcode_libdir_flag_spec\"` + eval flag=\"$hardcode_libdir_flag_spec\" compile_command="$compile_command $flag" finalize_command="$finalize_command $flag" @@ -842,8 +853,8 @@ if test -z "$show_help"; then ;; esac - name=`$echo "X$output" | $Xsed -e 's/\.la$//' -e 's/^lib//'` - libname=`eval \\$echo \"$libname_spec\"` + name=`$echo "X$output" | $Xsed -e 's/\.la$//' -e 's/^lib//'`$postfix + eval libname=\"$libname_spec\" # All the library-specific variables (install_libdir is set above). library_names= @@ -1006,13 +1017,13 @@ if test -z "$show_help"; then if test "$build_libtool_libs" = yes; then # Get the real and link names of the library. - library_names=`eval \\$echo \"$library_names_spec\"` + eval library_names=\"$library_names_spec\" set dummy $library_names realname="$2" shift; shift if test -n "$soname_spec"; then - soname=`eval \\$echo \"$soname_spec\"` + eval soname=\"$soname_spec\" else soname="$realname" fi @@ -1027,7 +1038,7 @@ if test -z "$show_help"; then test -z "$pic_flag" && libobjs=`$echo "X$libobjs " | $Xsed -e 's/\.lo /.o /g' -e 's/ $//g'` # Do each of the archive commands. - cmds=`eval \\$echo \"$archive_cmds\"` + eval cmds=\"$archive_cmds\" IFS="${IFS= }"; save_ifs="$IFS"; IFS=';' for cmd in $cmds; do IFS="$save_ifs" @@ -1104,7 +1115,7 @@ if test -z "$show_help"; then reload_objs="$objs"`$echo "X$libobjs " | $Xsed -e 's/[^ ]*\.a //g' -e 's/\.lo /.o /g' -e 's/ $//g'` output="$obj" - cmds=`eval \\$echo \"$reload_cmds\"` + eval cmds=\"$reload_cmds\" IFS="${IFS= }"; save_ifs="$IFS"; IFS=';' for cmd in $cmds; do IFS="$save_ifs" @@ -1128,7 +1139,7 @@ if test -z "$show_help"; then # Only do commands if we really have different PIC objects. reload_objs="$libobjs" output="$libobj" - cmds=`eval \\$echo \"$reload_cmds\"` + eval cmds=\"$reload_cmds\" IFS="${IFS= }"; save_ifs="$IFS"; IFS=';' for cmd in $cmds; do IFS="$save_ifs" @@ -1177,7 +1188,7 @@ if test -z "$show_help"; then fi if test -n "$libdir"; then - flag=`eval \\$echo \"$hardcode_libdir_flag_spec\"` + eval flag=\"$hardcode_libdir_flag_spec\" compile_command="$compile_command $flag" finalize_command="$finalize_command $flag" @@ -1254,8 +1265,8 @@ if test -z "$show_help"; then case "$dlsyms" in "") ;; *.c) - $echo > "$objdir/$dlsyms" \ -"/* $dlsyms - symbol resolution table for \`$output' dlsym emulation. */ + $echo > "$objdir/$dlsyms" "\ +/* $dlsyms - symbol resolution table for \`$output' dlsym emulation. */ /* Generated by $PROGRAM - GNU $PACKAGE $VERSION */ #ifdef __cplusplus @@ -1266,17 +1277,17 @@ extern \"C\" { #define dld_preloaded_symbol_count some_other_symbol #define dld_preloaded_symbols some_other_symbol -/* External symbol declarations for the compiler. */" +/* External symbol declarations for the compiler. */\ +" if test -f "$nlist"; then sed -e 's/^.* \(.*\)$/extern char \1;/' < "$nlist" >> "$objdir/$dlsyms" else echo '/* NONE */' >> "$objdir/$dlsyms" -EOF fi - $echo >> "$objdir/$dlsyms" \ -" + $echo >> "$objdir/$dlsyms" "\ + #undef dld_preloaded_symbol_count #undef dld_preloaded_symbols @@ -1295,19 +1306,21 @@ struct { __ptr_t address; } dld_preloaded_symbols[] = -{" +{\ +" if test -f "$nlist"; then sed 's/^\(.*\) \(.*\)$/ {"\1", (__ptr_t) \&\2},/' < "$nlist" >> "$objdir/$dlsyms" fi - $echo >> "$objdir/$dlsyms" \ -" {0, (__ptr_t) 0} + $echo >> "$objdir/$dlsyms" "\ + {0, (__ptr_t) 0} }; #ifdef __cplusplus } -#endif" +#endif\ +" ;; *) @@ -1427,8 +1440,8 @@ dld_preloaded_symbols[] = $rm $output trap "$rm $output; exit 1" 1 2 15 - $echo > $output \ -"#! /bin/sh + $echo > $output "\ +#! /bin/sh # $output - temporary wrapper script for $objdir/$output # Generated by ltmain.sh - GNU $PACKAGE $VERSION @@ -1459,10 +1472,9 @@ else else echo=\"$qecho\" file=\"\$0\" - fi -" - $echo >> $output \ + fi\ " + $echo >> $output "\ # Find the directory that this script lives in. thisdir=\`\$echo \"X\$file\" | \$Xsed -e 's%/[^/]*$%%'\` @@ -1496,8 +1508,8 @@ else # Export our shlibpath_var if we have one. if test -n "$shlibpath_var" && test -n "$temp_rpath"; then - $echo >> $output \ -" # Add our own library path to $shlibpath_var + $echo >> $output "\ + # Add our own library path to $shlibpath_var $shlibpath_var=\"$temp_rpath\$$shlibpath_var\" # Some systems cannot cope with colon-terminated $shlibpath_var @@ -1507,24 +1519,17 @@ else " fi - echo >> $output \ -" if test \"\$libtool_execute_magic\" != \"$magic\"; then + $echo >> $output "\ + if test \"\$libtool_execute_magic\" != \"$magic\"; then # Run the actual program with our arguments. - args= - for arg - do - # Quote arguments (to preserve shell metacharacters). - arg=\`\$echo \"X\$arg\" | \$Xsed -e \"\$sed_quote_subst\"\` - args=\"\$args \\\"\$arg\\\"\" - done # Export the path to the program. PATH=\"\$progdir:\$PATH\" export PATH - eval \"exec \$program \$args\" + exec \$program \${1+\"\$@\"} - \$echo \"\$0: cannot exec \$program \$args\" + \$echo \"\$0: cannot exec \$program \${1+\"\$@\"}\" exit 1 fi else @@ -1534,7 +1539,8 @@ else echo \"See the $PACKAGE documentation for more information.\" 1>&2 exit 1 fi -fi" +fi\ +" chmod +x $output fi exit 0 @@ -1548,9 +1554,9 @@ fi" # Do each command in the archive commands. if test -n "$old_archive_from_new_cmds" && test "$build_libtool_libs" = yes; then - cmds=`eval \\$echo \"$old_archive_from_new_cmds\"` + eval cmds=\"$old_archive_from_new_cmds\" else - cmds=`eval \\$echo \"$old_archive_cmds\"` + eval cmds=\"$old_archive_cmds\" fi IFS="${IFS= }"; save_ifs="$IFS"; IFS=';' for cmd in $cmds; do @@ -1571,8 +1577,8 @@ fi" # Only create the output if not a dry run. if test -z "$run"; then - echo > $output \ -"# $output - a libtool library file + $echo > $output "\ +# $output - a libtool library file # Generated by ltmain.sh - GNU $PACKAGE $VERSION # The name that we can dlopen(3). @@ -1593,7 +1599,8 @@ age=$age revision=$revision # Directory that this library needs to be installed in: -libdir='$install_libdir'" +libdir='$install_libdir'\ +" fi # Do a symbolic link so that the libtool archive can be found in @@ -1835,7 +1842,7 @@ libdir='$install_libdir'" # Do each command in the postinstall commands. lib="$destdir/$realname" - cmds=`eval \\$echo \"$postinstall_cmds\"` + eval cmds=\"$postinstall_cmds\" IFS="${IFS= }"; save_ifs="$IFS"; IFS=';' for cmd in $cmds; do IFS="$save_ifs" @@ -1972,7 +1979,7 @@ libdir='$install_libdir'" $run eval "$install_prog \$file \$oldlib" || exit $? # Do each command in the postinstall commands. - cmds=`eval \\$echo \"$old_postinstall_cmds\"` + eval cmds=\"$old_postinstall_cmds\" IFS="${IFS= }"; save_ifs="$IFS"; IFS=';' for cmd in $cmds; do IFS="$save_ifs" @@ -2010,7 +2017,7 @@ libdir='$install_libdir'" for libdir in $libdirs; do if test -n "$finish_cmds"; then # Do each command in the finish commands. - cmds=`eval \\$echo \"$finish_cmds\"` + eval cmds=\"$finish_cmds\" IFS="${IFS= }"; save_ifs="$IFS"; IFS=';' for cmd in $cmds; do IFS="$save_ifs" @@ -2021,7 +2028,7 @@ libdir='$install_libdir'" fi if test -n "$finish_eval"; then # Do the single finish_eval. - cmds=`eval \\$echo \"$finish_eval\"` + eval cmds=\"$finish_eval\" $run eval "$cmds" fi done @@ -2047,7 +2054,7 @@ libdir='$install_libdir'" fi if test -n "$hardcode_libdir_flag_spec"; then libdir=LIBDIR - flag=`eval \\$echo \"$hardcode_libdir_flag_spec\"` + eval flag=\"$hardcode_libdir_flag_spec\" echo " - use the \`$flag' linker flag" fi @@ -2238,7 +2245,7 @@ libdir='$install_libdir'" if test -n "$library_names"; then # Do each command in the postuninstall commands. - cmds=`eval \\$echo \"$postuninstall_cmds\"` + eval cmds=\"$postuninstall_cmds\" IFS="${IFS= }"; save_ifs="$IFS"; IFS=';' for cmd in $cmds; do IFS="$save_ifs" @@ -2250,7 +2257,7 @@ libdir='$install_libdir'" if test -n "$old_library"; then # Do each command in the old_postuninstall commands. - cmds=`eval \\$echo \"$old_postuninstall_cmds\"` + eval cmds=\"$old_postuninstall_cmds\" IFS="${IFS= }"; save_ifs="$IFS"; IFS=';' for cmd in $cmds; do IFS="$save_ifs" diff --git a/glib/testglib.c b/glib/testglib.c index d4bd85a530..4c223667ac 100644 --- a/glib/testglib.c +++ b/glib/testglib.c @@ -108,9 +108,9 @@ main (int argc, GTree *tree; char chars[62]; - g_print ("checking size of gint8...%d (should be 1)\n", sizeof (gint8)); - g_print ("checking size of gint16...%d (should be 2)\n", sizeof (gint16)); - g_print ("checking size of gint32...%d (should be 4)\n", sizeof (gint32)); + g_print ("checking size of gint8...%ld (should be 1)\n", (glong)sizeof (gint8)); + g_print ("checking size of gint16...%ld (should be 2)\n", (glong)sizeof (gint16)); + g_print ("checking size of gint32...%ld (should be 4)\n", (glong)sizeof (gint32)); g_print ("checking doubly linked lists..."); @@ -126,6 +126,10 @@ main (int argc, g_error ("Regular insert failed"); } + for (i = 0; i < 10; i++) + if(g_list_position(list, g_list_nth (list, i)) != i) + g_error("g_list_position does not seem to be the inverse of g_list_nth\n"); + g_list_free (list); list = NULL; diff --git a/gtk/Makefile.am b/gtk/Makefile.am index 11cd4cbbd6..87913cfd78 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -2,9 +2,9 @@ gtkincludedir = $(includedir)/gtk -lib_LTLIBRARIES = libgtk.la +lib_LTLIBRARIES = libgtk-1.1.la -libgtk_la_SOURCES = \ +libgtk_1_1_la_SOURCES = \ gtkaccelerator.c \ gtkadjustment.c \ gtkaspectframe.c \ @@ -76,7 +76,6 @@ libgtk_la_SOURCES = \ gtkstatusbar.c \ gtktable.c \ gtktext.c \ - gtkthemes.c \ gtktipsquery.c \ gtktogglebutton.c \ gtktoolbar.c \ @@ -94,6 +93,7 @@ libgtk_la_SOURCES = \ gtkvseparator.c \ gtkwidget.c \ gtkwindow.c \ + gtkthemes.c \ fnmatch.c \ fnmatch.h @@ -123,6 +123,7 @@ gtkinclude_HEADERS = \ gtkentry.h \ gtkenums.h \ gtkeventbox.h \ + gtkfeatures.h \ gtkfilesel.h \ gtkfixed.h \ gtkframe.h \ @@ -173,7 +174,6 @@ gtkinclude_HEADERS = \ gtkstatusbar.h \ gtktable.h \ gtktext.h \ - gtkthemes.h \ gtktipsquery.h \ gtktogglebutton.h \ gtktoolbar.h \ @@ -199,13 +199,15 @@ $(srcdir)/gtktypebuiltins.h: @MAINT@ $(srcdir)/gtk.defs $(srcdir)/gentypeinfo.el $(srcdir)/gtktypebuiltins.c: @MAINT@ $(srcdir)/gtk.defs $(srcdir)/gentypeinfo.el $(SHELL) $(srcdir)/runelisp $(srcdir)/gentypeinfo.el id $< $@ -libgtk_la_LDFLAGS = -lgdk_imlib -ldl -ljpeg -ltiff -lgif -lpng -lz -lm -version-info 1:0:0 +libgtk_1_1_la_LDFLAGS = -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) EXTRA_DIST = \ line-arrow.xbm \ line-wrap.xbm \ testgtkrc \ + testgtkrc2 \ gtk.defs \ + gtkfeatures.h.in \ runelisp \ gentypeinfo.el \ gtktypebuiltins.c \ @@ -223,48 +225,32 @@ EXTRA_DIST = \ INCLUDES = -I$(top_srcdir) -I../glib -I$(top_srcdir)/glib @x_cflags@ noinst_PROGRAMS = testgtk testinput testselection simple -testgtk_LDADD = \ - libgtk.la \ - $(top_builddir)/gdk/libgdk.la \ - @x_ldflags@ \ - @x_libs@ \ - $(top_builddir)/glib/libglib.la \ - -lm -testinput_LDADD = \ - libgtk.la \ - $(top_builddir)/gdk/libgdk.la \ - @x_ldflags@ \ - @x_libs@ \ - $(top_builddir)/glib/libglib.la \ - -lm +# FIXME, we currently rely on linking against libglib-1.1 -testselection_LDADD = \ - libgtk.la \ - $(top_builddir)/gdk/libgdk.la \ - @x_ldflags@ \ - @x_libs@ \ - $(top_builddir)/glib/libglib.la \ - -lm - -simple_LDADD = \ - libgtk.la \ - $(top_builddir)/gdk/libgdk.la \ - @x_ldflags@ \ - @x_libs@ \ - $(top_builddir)/glib/libglib.la \ - -lm - -DEPS = \ - libgtk.la \ - $(top_builddir)/gdk/libgdk.la \ - $(top_builddir)/glib/libglib.la +DEPS = \ + libgtk-@LT_RELEASE@.la \ + $(top_builddir)/gdk/libgdk-@LT_RELEASE@.la \ + $(top_builddir)/glib/libglib-1.1.la +LDADDS = \ + libgtk-@LT_RELEASE@.la \ + $(top_builddir)/gdk/libgdk-@LT_RELEASE@.la \ + @x_ldflags@ \ + @x_libs@ \ + $(top_builddir)/glib/libglib-1.1.la \ + -lm -ldl -lgdk_imlib -ljpeg -ltiff -lgif -lpng -lz -lm testgtk_DEPENDENCIES = $(DEPS) testinput_DEPENDENCIES = $(DEPS) testselection_DEPENDENCIES = $(DEPS) simple_DEPENDENCIES = $(DEPS) +testgtk_LDADD = $(LDADDS) +testinput_LDADD = $(LDADDS) +testselection_LDADD = $(LDADDS) +simple_LDADD = $(LDADDS) + + .PHONY: files test test-debug files: @@ -18,6 +18,9 @@ #ifndef __GTK_H__ #define __GTK_H__ +#define GTK_MAJOR_VERSION 1 +#define GTK_MINOR_VERSION 0 +#define GTK_MICRO_VERSION 1 #include <gdk/gdk.h> #include <gtk/gtkaccelerator.h> diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c index 189b38831e..4d8f79c23f 100644 --- a/gtk/gtkbutton.c +++ b/gtk/gtkbutton.c @@ -388,6 +388,8 @@ gtk_button_size_request (GtkWidget *widget, button->border(GTK_WIDGET(widget)); else { + GTK_CONTAINER(widget)->minimum_width=0; + GTK_CONTAINER(widget)->minimum_height=0; if (GTK_WIDGET_CAN_DEFAULT (widget)) { GTK_CONTAINER(widget)->internal_border_left=10; @@ -418,6 +420,14 @@ gtk_button_size_request (GtkWidget *widget, requisition->width += button->child->requisition.width; requisition->height += button->child->requisition.height; } + if ((requisition->width-(GTK_CONTAINER (widget)->border_width * 2))< + GTK_CONTAINER(widget)->minimum_width) + requisition->width=GTK_CONTAINER(widget)->minimum_width+ + (GTK_CONTAINER (widget)->border_width * 2); + if ((requisition->height-(GTK_CONTAINER (widget)->border_width * 2))< + GTK_CONTAINER(widget)->minimum_height) + requisition->height=GTK_CONTAINER(widget)->minimum_height+ + (GTK_CONTAINER (widget)->border_width * 2); } static void diff --git a/gtk/gtkcheckbutton.c b/gtk/gtkcheckbutton.c index 834e954e4b..54998e803a 100644 --- a/gtk/gtkcheckbutton.c +++ b/gtk/gtkcheckbutton.c @@ -16,6 +16,8 @@ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "gtkcheckbutton.h" +#include "gtkthemes.h" +#include "gtkprivate.h" #include "gtklabel.h" @@ -38,8 +40,9 @@ static gint gtk_check_button_expose (GtkWidget *widget, GdkEventExpose *event); static void gtk_check_button_draw_indicator (GtkCheckButton *check_button, GdkRectangle *area); -static void gtk_real_check_button_draw_indicator (GtkCheckButton *check_button, - GdkRectangle *area); +static void gtk_check_button_realize (GtkWidget *widget); +static void gtk_check_button_unrealize (GtkWidget *widget); +static void gtk_check_button_unmap (GtkWidget *widget); static GtkToggleButtonClass *parent_class = NULL; @@ -72,7 +75,7 @@ gtk_check_button_get_type () static void gtk_check_button_class_init (GtkCheckButtonClass *class) { - GtkWidgetClass *widget_class; + GtkWidgetClass *widget_class; widget_class = (GtkWidgetClass*) class; parent_class = gtk_type_class (gtk_toggle_button_get_type ()); @@ -85,7 +88,124 @@ gtk_check_button_class_init (GtkCheckButtonClass *class) class->indicator_size = INDICATOR_SIZE; class->indicator_spacing = INDICATOR_SPACING; - class->draw_indicator = gtk_real_check_button_draw_indicator; + + widget_class->realize = gtk_check_button_realize; + widget_class->unrealize = gtk_check_button_unrealize; +} + +static void +gtk_check_button_unmap (GtkWidget *widget) +{ + g_return_if_fail (widget != NULL); + g_return_if_fail (GTK_IS_CHECK_BUTTON (widget)); + + GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED); +/* gdk_window_hide (widget->window);*/ + gdk_window_clear_area(widget->window,widget->allocation.x, + widget->allocation.y, + widget->allocation.width, + widget->allocation.height); + gtk_widget_draw (widget, NULL); +} + +static void +gtk_check_button_realize (GtkWidget *widget) +{ + GtkCheckButton *check_button; + GdkWindowAttr attributes; + gint attributes_mask; + gint border_width; + + g_return_if_fail (widget != NULL); + g_return_if_fail (GTK_IS_CHECK_BUTTON (widget)); + + check_button = GTK_CHECK_BUTTON (widget); + GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); + + border_width = GTK_CONTAINER (widget)->border_width; + + attributes.window_type = GDK_WINDOW_CHILD; + attributes.x = widget->allocation.x + border_width; + attributes.y = widget->allocation.y + border_width; + attributes.width = widget->allocation.width - border_width * 2; + attributes.height = widget->allocation.height - border_width * 2; + attributes.wclass = GDK_INPUT_OUTPUT; + attributes.visual = gtk_widget_get_visual (widget); + attributes.colormap = gtk_widget_get_colormap (widget); + attributes.event_mask = gtk_widget_get_events (widget); + attributes.event_mask |= (GDK_EXPOSURE_MASK | + GDK_BUTTON_PRESS_MASK | + GDK_BUTTON_RELEASE_MASK | + GDK_ENTER_NOTIFY_MASK | + GDK_LEAVE_NOTIFY_MASK); + + attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; + + widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask); + gdk_window_set_user_data (widget->window, check_button); + + widget->style = gtk_style_attach (widget->style, widget->window); + gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); + + if (check_button->init) + check_button->init(GTK_WIDGET(widget)); +} + +static void +gtk_check_button_unrealize (GtkWidget *widget) +{ + GtkButton *check_button; + + g_return_if_fail (widget != NULL); + g_return_if_fail (GTK_IS_WIDGET (widget)); + + check_button=GTK_CHECK_BUTTON(widget); + + if (GTK_WIDGET_NO_WINDOW (widget) && GTK_WIDGET_MAPPED (widget)) + gtk_check_button_unmap (widget); + + GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED | GTK_MAPPED); + + + gtk_style_detach (widget->style); + if (!GTK_WIDGET_NO_WINDOW (widget)) + { + gdk_window_set_user_data (widget->window, NULL); + gdk_window_destroy (widget->window); + } + else + { + gdk_window_unref (widget->window); + } + + if (GTK_IS_CONTAINER (widget)) + gtk_container_foreach (GTK_CONTAINER (widget), + (GtkCallback)gtk_widget_unrealize, + NULL); + if (check_button->exit) + check_button->exit(GTK_WIDGET(widget)); + + widget->window = NULL; +} + +void +gtk_check_button_set_theme (GtkCheckButton *check_button, + void (* init) (GtkWidget *check_button), + void (* border) (GtkWidget *check_button), + void (* draw) (GtkWidget *check_button, GdkRectangle *area), + void (* exit) (GtkWidget *check_button)) +{ + if (GTK_WIDGET_REALIZED(GTK_WIDGET(check_button))) + check_button->exit(GTK_WIDGET(check_button)); + check_button->init=init; + check_button->border=border; + check_button->draw=draw; + check_button->exit=exit; + if (GTK_WIDGET_REALIZED(GTK_WIDGET(check_button))) + { + check_button->init(GTK_WIDGET(check_button)); + check_button->draw(GTK_WIDGET(check_button),NULL); + } } static void @@ -97,7 +217,17 @@ gtk_check_button_init (GtkCheckButton *check_button) GtkWidget* gtk_check_button_new () { - return GTK_WIDGET (gtk_type_new (gtk_check_button_get_type ())); + GtkCheckButton *check_button; + + check_button = GTK_CHECK_BUTTON (gtk_type_new (gtk_check_button_get_type ())); + if (check_button) + { + check_button->init=th_dat.functions.check_button.init; + check_button->border=th_dat.functions.check_button.border; + check_button->draw=th_dat.functions.check_button.draw; + check_button->exit=th_dat.functions.check_button.exit; + } + return GTK_WIDGET(check_button); } @@ -124,70 +254,126 @@ gtk_check_button_draw (GtkWidget *widget, GtkButton *button; GtkCheckButton *check_button; GdkRectangle child_area; + GdkRectangle dummy_area; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_CHECK_BUTTON (widget)); - g_return_if_fail (area != NULL); +/* g_return_if_fail (area != NULL);*/ if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_MAPPED (widget)) { - check_button = GTK_CHECK_BUTTON (widget); - - if (check_button->toggle_button.draw_indicator) - { - button = GTK_BUTTON (widget); - - gtk_check_button_draw_indicator (check_button, area); - - if (button->child && GTK_WIDGET_NO_WINDOW (button->child) && - gtk_widget_intersect (button->child, area, &child_area)) - gtk_widget_draw (button->child, &child_area); - - gtk_widget_draw_focus (widget); - } - else - { - if (GTK_WIDGET_CLASS (parent_class)->draw) - (* GTK_WIDGET_CLASS (parent_class)->draw) (widget, area); - } + check_button = GTK_CHECK_BUTTON (widget); + button = GTK_BUTTON (widget); + + if (!area) + { +/* dummy_area.x = widget->allocation.x; + dummy_area.y = widget->allocation.y;*/ + dummy_area.x = 0; + dummy_area.y = 0; + dummy_area.width = widget->allocation.width; + dummy_area.height = widget->allocation.height; + area = & dummy_area; + } +/* if (GTK_WIDGET_CLASS (parent_class)->draw) + (* GTK_WIDGET_CLASS (parent_class)->draw) (widget, area);*/ + if (check_button->draw) + { + check_button->draw(GTK_WIDGET(widget),area); + if (button->child && GTK_WIDGET_NO_WINDOW (button->child) && + gtk_widget_intersect (button->child, area, &child_area)) + { + gtk_widget_draw (button->child, area); + } + } + else + { + GtkToggleButton *toggle_button; + GtkStateType state_type; + GtkShadowType shadow_type; + GdkRectangle restrict_area; + GdkRectangle new_area; + gint width, height; + gint x, y; + + if (GTK_WIDGET_DRAWABLE (check_button)) + { + widget = GTK_WIDGET (check_button); + toggle_button = GTK_TOGGLE_BUTTON (check_button); + + state_type = GTK_WIDGET_STATE (widget); + if ((state_type != GTK_STATE_NORMAL) && + (state_type != GTK_STATE_PRELIGHT)) + state_type = GTK_STATE_NORMAL; + + restrict_area.x = GTK_CONTAINER (widget)->border_width; + restrict_area.y = restrict_area.x; + restrict_area.width = widget->allocation.width - restrict_area.x * 2; + restrict_area.height = widget->allocation.height - restrict_area.x * 2; + + if (gdk_rectangle_intersect (area, &restrict_area, &new_area)) + { + gtk_style_set_background (widget->style, widget->window, state_type); + gdk_window_clear_area (widget->window, new_area.x, new_area.y, + new_area.width, new_area.height); + } + + x = CHECK_BUTTON_CLASS (widget)->indicator_spacing + GTK_CONTAINER (widget)->border_width; + y = (widget->allocation.height - CHECK_BUTTON_CLASS (widget)->indicator_size) / 2; + width = CHECK_BUTTON_CLASS (widget)->indicator_size; + height = CHECK_BUTTON_CLASS (widget)->indicator_size; + + if (GTK_TOGGLE_BUTTON (widget)->active) + shadow_type = GTK_SHADOW_IN; + else + shadow_type = GTK_SHADOW_OUT; + + gdk_draw_rectangle (widget->window, + widget->style->bg_gc[GTK_WIDGET_STATE (widget)], + TRUE, x + 1, y + 1, width, height); + gtk_draw_shadow (widget->style, widget->window, + GTK_WIDGET_STATE (widget), shadow_type, + x + 1, y + 1, width, height); + } + if (button->child && GTK_WIDGET_NO_WINDOW (button->child) && + gtk_widget_intersect (button->child, area, &child_area)) + gtk_widget_draw (button->child, &child_area); + + if (GTK_WIDGET_DRAWABLE (widget)) + { + check_button = GTK_CHECK_BUTTON (widget); + if (check_button->toggle_button.draw_indicator) + { + gint border_width; + + border_width = GTK_CONTAINER (widget)->border_width; + if (GTK_WIDGET_HAS_FOCUS (widget)) + gdk_draw_rectangle (widget->window, + widget->style->black_gc, FALSE, + border_width, border_width, + widget->allocation.width - 2 * border_width - 1, + widget->allocation.height - 2 * border_width - 1); + else + gdk_draw_rectangle (widget->window, + widget->style->bg_gc[GTK_STATE_NORMAL], FALSE, + border_width, border_width, + widget->allocation.width - 2 * border_width - 1, + widget->allocation.height - 2 * border_width - 1); + } + else + { + if (GTK_WIDGET_CLASS (parent_class)->draw_focus) + (* GTK_WIDGET_CLASS (parent_class)->draw_focus) (widget); + } + } + } } } -static void +void gtk_check_button_draw_focus (GtkWidget *widget) { - GtkCheckButton *check_button; - - g_return_if_fail (widget != NULL); - g_return_if_fail (GTK_IS_CHECK_BUTTON (widget)); - - if (GTK_WIDGET_DRAWABLE (widget)) - { - check_button = GTK_CHECK_BUTTON (widget); - if (check_button->toggle_button.draw_indicator) - { - gint border_width; - - border_width = GTK_CONTAINER (widget)->border_width; - if (GTK_WIDGET_HAS_FOCUS (widget)) - gdk_draw_rectangle (widget->window, - widget->style->black_gc, FALSE, - border_width, border_width, - widget->allocation.width - 2 * border_width - 1, - widget->allocation.height - 2 * border_width - 1); - else - gdk_draw_rectangle (widget->window, - widget->style->bg_gc[GTK_STATE_NORMAL], FALSE, - border_width, border_width, - widget->allocation.width - 2 * border_width - 1, - widget->allocation.height - 2 * border_width - 1); - } - else - { - if (GTK_WIDGET_CLASS (parent_class)->draw_focus) - (* GTK_WIDGET_CLASS (parent_class)->draw_focus) (widget); - } - } + gtk_check_button_draw(widget, NULL); } static void @@ -279,24 +465,18 @@ gtk_check_button_expose (GtkWidget *widget, { check_button = GTK_CHECK_BUTTON (widget); - if (check_button->toggle_button.draw_indicator) + gtk_check_button_draw(GTK_WIDGET(check_button), &event->area); +/* if (check_button->toggle_button.draw_indicator) { button = GTK_BUTTON (widget); - gtk_check_button_draw_indicator (check_button, &event->area); child_event = *event; if (button->child && GTK_WIDGET_NO_WINDOW (button->child) && gtk_widget_intersect (button->child, &event->area, &child_event.area)) gtk_widget_event (button->child, (GdkEvent*) &child_event); - - gtk_widget_draw_focus (widget); - } - else - { - if (GTK_WIDGET_CLASS (parent_class)->expose_event) - (* GTK_WIDGET_CLASS (parent_class)->expose_event) (widget, event); } + */ } return FALSE; @@ -307,71 +487,6 @@ static void gtk_check_button_draw_indicator (GtkCheckButton *check_button, GdkRectangle *area) { - GtkCheckButtonClass *class; - - g_return_if_fail (check_button != NULL); - g_return_if_fail (GTK_IS_CHECK_BUTTON (check_button)); - g_return_if_fail (CHECK_BUTTON_CLASS (check_button) != NULL); - - class = CHECK_BUTTON_CLASS (check_button); - - if (class->draw_indicator) - (* class->draw_indicator) (check_button, area); + gtk_check_button_draw (GTK_WIDGET(check_button), NULL); } -static void -gtk_real_check_button_draw_indicator (GtkCheckButton *check_button, - GdkRectangle *area) -{ - GtkWidget *widget; - GtkToggleButton *toggle_button; - GtkStateType state_type; - GtkShadowType shadow_type; - GdkRectangle restrict_area; - GdkRectangle new_area; - gint width, height; - gint x, y; - - g_return_if_fail (check_button != NULL); - g_return_if_fail (GTK_IS_CHECK_BUTTON (check_button)); - - if (GTK_WIDGET_DRAWABLE (check_button)) - { - widget = GTK_WIDGET (check_button); - toggle_button = GTK_TOGGLE_BUTTON (check_button); - - state_type = GTK_WIDGET_STATE (widget); - if ((state_type != GTK_STATE_NORMAL) && - (state_type != GTK_STATE_PRELIGHT)) - state_type = GTK_STATE_NORMAL; - - restrict_area.x = GTK_CONTAINER (widget)->border_width; - restrict_area.y = restrict_area.x; - restrict_area.width = widget->allocation.width - restrict_area.x * 2; - restrict_area.height = widget->allocation.height - restrict_area.x * 2; - - if (gdk_rectangle_intersect (area, &restrict_area, &new_area)) - { - gtk_style_set_background (widget->style, widget->window, state_type); - gdk_window_clear_area (widget->window, new_area.x, new_area.y, - new_area.width, new_area.height); - } - - x = CHECK_BUTTON_CLASS (widget)->indicator_spacing + GTK_CONTAINER (widget)->border_width; - y = (widget->allocation.height - CHECK_BUTTON_CLASS (widget)->indicator_size) / 2; - width = CHECK_BUTTON_CLASS (widget)->indicator_size; - height = CHECK_BUTTON_CLASS (widget)->indicator_size; - - if (GTK_TOGGLE_BUTTON (widget)->active) - shadow_type = GTK_SHADOW_IN; - else - shadow_type = GTK_SHADOW_OUT; - - gdk_draw_rectangle (widget->window, - widget->style->bg_gc[GTK_WIDGET_STATE (widget)], - TRUE, x + 1, y + 1, width, height); - gtk_draw_shadow (widget->style, widget->window, - GTK_WIDGET_STATE (widget), shadow_type, - x + 1, y + 1, width, height); - } -} diff --git a/gtk/gtkcheckbutton.h b/gtk/gtkcheckbutton.h index 8994db563e..45ee37b953 100644 --- a/gtk/gtkcheckbutton.h +++ b/gtk/gtkcheckbutton.h @@ -38,7 +38,12 @@ typedef struct _GtkCheckButtonClass GtkCheckButtonClass; struct _GtkCheckButton { - GtkToggleButton toggle_button; + GtkToggleButton toggle_button; + + void (* init) (GtkWidget *button); + void (* border) (GtkWidget *button); + void (* draw) (GtkWidget *button, GdkRectangle *area); + void (* exit) (GtkWidget *button); }; struct _GtkCheckButtonClass @@ -56,7 +61,13 @@ struct _GtkCheckButtonClass guint gtk_check_button_get_type (void); GtkWidget* gtk_check_button_new (void); GtkWidget* gtk_check_button_new_with_label (const gchar *label); - +void gtk_check_button_set_theme (GtkCheckButton *check_button, + void (* init) (GtkWidget *check_button), + void (* border) (GtkWidget *check_button), + void (* draw) (GtkWidget *check_button, GdkRectangle *area), + void (* exit) (GtkWidget *check_button)); + + #ifdef __cplusplus } diff --git a/gtk/gtkcontainer.h b/gtk/gtkcontainer.h index 3ab84aead7..836f127802 100644 --- a/gtk/gtkcontainer.h +++ b/gtk/gtkcontainer.h @@ -45,10 +45,6 @@ struct _GtkContainer GtkWidget *focus_child; gint16 border_width; - gint16 internal_border_left; - gint16 internal_border_right; - gint16 internal_border_top; - gint16 internal_border_bottom; guint auto_resize : 1; guint need_resize : 1; guint block_resize : 1; @@ -57,6 +53,13 @@ struct _GtkContainer /* The list of children that requested a resize */ GSList *resize_widgets; + + gint16 internal_border_left; + gint16 internal_border_right; + gint16 internal_border_top; + gint16 internal_border_bottom; + gint16 minimum_width; + gint16 minimum_height; }; struct _GtkContainerClass diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c index 685836b9f6..f17f695c6a 100644 --- a/gtk/gtkmain.c +++ b/gtk/gtkmain.c @@ -19,6 +19,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include "gtk.h" #include "gtkbutton.h" #include "gtkhscrollbar.h" #include "gtkhseparator.h" diff --git a/gtk/gtkthemes.c b/gtk/gtkthemes.c index f82aef53ec..60189e3584 100644 --- a/gtk/gtkthemes.c +++ b/gtk/gtkthemes.c @@ -109,6 +109,14 @@ gtk_themes_init (int *argc, th_dat.functions.button.init=NULL; th_dat.functions.button.draw=NULL; th_dat.functions.button.exit=NULL; + th_dat.functions.window.border=NULL; + th_dat.functions.window.init=NULL; + th_dat.functions.window.draw=NULL; + th_dat.functions.window.exit=NULL; + th_dat.functions.check_button.border=NULL; + th_dat.functions.check_button.init=NULL; + th_dat.functions.check_button.draw=NULL; + th_dat.functions.check_button.exit=NULL; return; } /* extract symbols from the lib */ @@ -118,7 +126,27 @@ gtk_themes_init (int *argc, th_dat.functions.button.init=dlsym(th_dat.theme_lib,"button_init"); th_dat.functions.button.draw=dlsym(th_dat.theme_lib,"button_draw"); th_dat.functions.button.exit=dlsym(th_dat.theme_lib,"button_exit"); + th_dat.functions.window.border=dlsym(th_dat.theme_lib,"window_border"); + th_dat.functions.window.init=dlsym(th_dat.theme_lib,"window_init"); + th_dat.functions.window.draw=dlsym(th_dat.theme_lib,"window_draw"); + th_dat.functions.window.exit=dlsym(th_dat.theme_lib,"window_exit"); + th_dat.functions.check_button.border=dlsym(th_dat.theme_lib,"check_button_border"); + th_dat.functions.check_button.init=dlsym(th_dat.theme_lib,"check_button_init"); + th_dat.functions.check_button.draw=dlsym(th_dat.theme_lib,"check_button_draw"); + th_dat.functions.check_button.exit=dlsym(th_dat.theme_lib,"check_button_exit"); + printf("Found button_border %x\n",th_dat.functions.button.border); + printf("Found button_init %x\n",th_dat.functions.button.init); + printf("Found button_draw %x\n",th_dat.functions.button.draw); + printf("Found button_exit %x\n",th_dat.functions.button.exit); + printf("Found window_border %x\n",th_dat.functions.window.border); + printf("Found window_init %x\n",th_dat.functions.window.init); + printf("Found window_draw %x\n",th_dat.functions.window.draw); + printf("Found window_exit %x\n",th_dat.functions.window.exit); + printf("Found check_button_border %x\n",th_dat.functions.check_button.border); + printf("Found check_button_init %x\n",th_dat.functions.check_button.init); + printf("Found check_button_draw %x\n",th_dat.functions.check_button.draw); + printf("Found check_button_exit %x\n",th_dat.functions.check_button.exit); /* call the theme's init (theme_init) function to let it setup anything */ th_dat.init(argc,argv); } diff --git a/gtk/gtkthemes.h b/gtk/gtkthemes.h index bba698154e..623b5c4b20 100644 --- a/gtk/gtkthemes.h +++ b/gtk/gtkthemes.h @@ -45,6 +45,8 @@ struct _GtkThemesData struct { struct _GtkWidgetThemeFunction button; + struct _GtkWidgetThemeFunction window; + struct _GtkWidgetThemeFunction check_button; } functions; void *data; }; diff --git a/gtk/gtktogglebutton.c b/gtk/gtktogglebutton.c index 8dbcba2100..12d4b7864b 100644 --- a/gtk/gtktogglebutton.c +++ b/gtk/gtktogglebutton.c @@ -15,6 +15,9 @@ * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include <string.h> +#include "gtkthemes.h" +#include "gtkprivate.h" #include "gtklabel.h" #include "gtkmain.h" #include "gtksignal.h" @@ -113,7 +116,19 @@ gtk_toggle_button_init (GtkToggleButton *toggle_button) GtkWidget* gtk_toggle_button_new () { - return GTK_WIDGET (gtk_type_new (gtk_toggle_button_get_type ())); + GtkToggleButton *toggle_button; + GtkButton *button; + + toggle_button=GTK_TOGGLE_BUTTON(gtk_type_new(gtk_toggle_button_get_type())); + if (toggle_button) + { + button=GTK_BUTTON(toggle_button); + button->init=th_dat.functions.button.init; + button->border=th_dat.functions.button.border; + button->draw=th_dat.functions.button.draw; + button->exit=th_dat.functions.button.exit; + } + return GTK_WIDGET(toggle_button); } GtkWidget* @@ -171,75 +186,7 @@ gtk_toggle_button_toggled (GtkToggleButton *toggle_button) static void gtk_toggle_button_draw_focus (GtkWidget *widget) { - GtkButton *button; - GtkToggleButton *toggle_button; - GtkShadowType shadow_type; - gint width, height; - gint x, y; - - g_return_if_fail (widget != NULL); - g_return_if_fail (GTK_IS_TOGGLE_BUTTON (widget)); - - if (GTK_WIDGET_DRAWABLE (widget)) - { - button = GTK_BUTTON (widget); - toggle_button = GTK_TOGGLE_BUTTON (widget); - - x = 0; - y = 0; - width = widget->allocation.width - GTK_CONTAINER (widget)->border_width * 2; - height = widget->allocation.height - GTK_CONTAINER (widget)->border_width * 2; - - if (GTK_WIDGET_CAN_DEFAULT (widget)) - { - x += widget->style->klass->xthickness; - y += widget->style->klass->ythickness; - width -= 2 * x + DEFAULT_SPACING; - height -= 2 * y + DEFAULT_SPACING; - x += DEFAULT_LEFT_POS; - y += DEFAULT_TOP_POS; - } - - if (GTK_WIDGET_HAS_FOCUS (widget)) - { - x += 1; - y += 1; - width -= 2; - height -= 2; - } - else - { - if (GTK_WIDGET_STATE (toggle_button) == GTK_STATE_ACTIVE) - gdk_draw_rectangle (widget->window, - widget->style->bg_gc[GTK_WIDGET_STATE (widget)], FALSE, - x + 1, y + 1, width - 4, height - 4); - else - gdk_draw_rectangle (widget->window, - widget->style->bg_gc[GTK_WIDGET_STATE (widget)], FALSE, - x + 2, y + 2, width - 5, height - 5); - } - - if (toggle_button->active) - shadow_type = GTK_SHADOW_IN; - else - shadow_type = GTK_SHADOW_OUT; - - gtk_draw_shadow (widget->style, widget->window, - GTK_WIDGET_STATE (widget), shadow_type, - x, y, width, height); - - if (GTK_WIDGET_HAS_FOCUS (widget)) - { - x -= 1; - y -= 1; - width += 2; - height += 2; - - gdk_draw_rectangle (widget->window, - widget->style->black_gc, FALSE, - x, y, width - 1, height - 1); - } - } + gtk_widget_queue_draw(widget); } static void diff --git a/gtk/gtktogglebutton.h b/gtk/gtktogglebutton.h index e48d1cf5a2..f9627ef2e4 100644 --- a/gtk/gtktogglebutton.h +++ b/gtk/gtktogglebutton.h @@ -61,7 +61,12 @@ void gtk_toggle_button_set_state (GtkToggleButton *toggle_button, gint state); void gtk_toggle_button_toggled (GtkToggleButton *toggle_button); - +void gtk_toggle_button_set_theme (GtkToggleButton *toggle_button, + void (* init) (GtkWidget *toggle_button), + void (* border) (GtkWidget *toggle_button), + void (* draw) (GtkWidget *toggle_button, GdkRectangle *area), + void (* exit) (GtkWidget *toggle_button)); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index 65699e7c6a..294007fb07 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -108,7 +108,9 @@ static void gtk_window_set_hints (GtkWidget *widget, static gint gtk_window_check_accelerator (GtkWindow *window, gint key, guint mods); - +static void gtk_window_unrealize (GtkWidget *widget); +static void gtk_window_draw (GtkWidget *widget, + GdkRectangle *area); static GtkBinClass *parent_class = NULL; static guint window_signals[LAST_SIGNAL] = { 0 }; @@ -198,6 +200,7 @@ gtk_window_class_init (GtkWindowClass *klass) widget_class->focus_in_event = gtk_window_focus_in_event; widget_class->focus_out_event = gtk_window_focus_out_event; widget_class->client_event = gtk_window_client_event; + widget_class->unrealize = gtk_window_unrealize; container_class->need_resize = gtk_window_need_resize; @@ -303,7 +306,13 @@ gtk_window_new (GtkWindowType type) window = gtk_type_new (gtk_window_get_type ()); window->type = type; - + if (window) + { + window->init=th_dat.functions.window.init; + window->border=th_dat.functions.window.border; + window->draw=th_dat.functions.window.draw; + window->exit=th_dat.functions.window.exit; + } return GTK_WIDGET (window); } @@ -638,6 +647,9 @@ gtk_window_realize (GtkWidget *widget) widget->style = gtk_style_attach (widget->style, widget->window); gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); + + if (window->init) + window->init(GTK_WIDGET(widget)); } static void @@ -652,11 +664,27 @@ gtk_window_size_request (GtkWidget *widget, window = GTK_WINDOW (widget); - if (window->bin.child) + if (window->border) + window->border(GTK_WIDGET(widget)); + else + { + GTK_CONTAINER(widget)->minimum_width=0; + GTK_CONTAINER(widget)->minimum_height=0; + GTK_CONTAINER(widget)->internal_border_left=2; + GTK_CONTAINER(widget)->internal_border_right=2; + GTK_CONTAINER(widget)->internal_border_top=2; + GTK_CONTAINER(widget)->internal_border_bottom=2; + } + + requisition->width = (GTK_CONTAINER (widget)->border_width * 2) + + GTK_CONTAINER(widget)->internal_border_left + + GTK_CONTAINER(widget)->internal_border_right; + requisition->height = (GTK_CONTAINER (widget)->border_width * 2) + + GTK_CONTAINER(widget)->internal_border_top + + GTK_CONTAINER(widget)->internal_border_bottom; + + if (window->bin.child) { - requisition->width = GTK_CONTAINER (window)->border_width * 2; - requisition->height = GTK_CONTAINER (window)->border_width * 2; - gtk_widget_size_request (window->bin.child, &window->bin.child->requisition); requisition->width += window->bin.child->requisition.width; @@ -667,33 +695,82 @@ gtk_window_size_request (GtkWidget *widget, if (!GTK_WIDGET_VISIBLE (window)) window->need_resize = TRUE; } + if ((requisition->width-(GTK_CONTAINER (widget)->border_width * 2))< + GTK_CONTAINER(widget)->minimum_width) + requisition->width=GTK_CONTAINER(widget)->minimum_width+ + (GTK_CONTAINER (widget)->border_width * 2); + if ((requisition->height-(GTK_CONTAINER (widget)->border_width * 2))< + GTK_CONTAINER(widget)->minimum_height) + requisition->height=GTK_CONTAINER(widget)->minimum_height+ + (GTK_CONTAINER (widget)->border_width * 2); } static void gtk_window_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { - GtkWindow *window; - GtkAllocation child_allocation; - - g_return_if_fail (widget != NULL); - g_return_if_fail (GTK_IS_WINDOW (widget)); - g_return_if_fail (allocation != NULL); - - window = GTK_WINDOW (widget); - widget->allocation = *allocation; - - if (window->bin.child && GTK_WIDGET_VISIBLE (window->bin.child)) + GtkWindow *window; + GtkAllocation child_allocation; + gint border_width; + + g_return_if_fail (widget != NULL); + g_return_if_fail (GTK_IS_WINDOW (widget)); + g_return_if_fail (allocation != NULL); + + window = GTK_WINDOW (widget); + widget->allocation = *allocation; + border_width = GTK_CONTAINER (widget)->border_width; + + if (window->border) + window->border(GTK_WIDGET(widget)); + else + { + GTK_CONTAINER(widget)->internal_border_left=2; + GTK_CONTAINER(widget)->internal_border_right=2; + GTK_CONTAINER(widget)->internal_border_top=2; + GTK_CONTAINER(widget)->internal_border_bottom=2; + } + if (window->bin.child && GTK_WIDGET_VISIBLE (window->bin.child)) { - child_allocation.x = GTK_CONTAINER (window)->border_width; - child_allocation.y = GTK_CONTAINER (window)->border_width; - child_allocation.width = allocation->width - child_allocation.x * 2; - child_allocation.height = allocation->height - child_allocation.y * 2; - - gtk_widget_size_allocate (window->bin.child, &child_allocation); + child_allocation.x = GTK_CONTAINER(widget)->internal_border_left; + child_allocation.y = GTK_CONTAINER(widget)->internal_border_top; + + child_allocation.width = widget->allocation.width - + child_allocation.x - GTK_CONTAINER(widget)->internal_border_right - + border_width * 2; + child_allocation.height = widget->allocation.height - + child_allocation.y - GTK_CONTAINER(widget)->internal_border_bottom - + border_width * 2; +/* + child_allocation.x = GTK_CONTAINER (window)->border_width; + child_allocation.y = GTK_CONTAINER (window)->border_width; + child_allocation.width = allocation->width - child_allocation.x * 2; + child_allocation.height = allocation->height - child_allocation.y * 2; + */ + gtk_widget_size_allocate (window->bin.child, &child_allocation); } } +static void +gtk_window_draw (GtkWidget *widget, GdkRectangle *area) +{ + GtkWindow *window; + GdkRectangle new_area; + + window = GTK_WINDOW (widget); + if (window->draw) + { + if (!area) + { + new_area.x=0;new_area.y=0; + new_area.width=widget->allocation.width; + new_area.height=widget->allocation.height; + } + if (area) window->draw(GTK_WIDGET(widget),area); + else window->draw(GTK_WIDGET(widget),&new_area); + } +} + static gint gtk_window_expose_event (GtkWidget *widget, GdkEventExpose *event) @@ -702,6 +779,7 @@ gtk_window_expose_event (GtkWidget *widget, g_return_val_if_fail (GTK_IS_WINDOW (widget), FALSE); g_return_val_if_fail (event != NULL, FALSE); + gtk_window_draw(widget,&event->area); if (GTK_WIDGET_DRAWABLE (widget)) if (GTK_WIDGET_CLASS (parent_class)->expose_event) return (* GTK_WIDGET_CLASS (parent_class)->expose_event) (widget, event); @@ -1348,3 +1426,60 @@ gtk_window_check_accelerator (GtkWindow *window, return FALSE; } + +static void +gtk_window_unrealize (GtkWidget *widget) +{ + GtkWindow *window; + + g_return_if_fail (widget != NULL); + g_return_if_fail (GTK_IS_WIDGET (widget)); + + window=GTK_WINDOW(widget); + + if (GTK_WIDGET_NO_WINDOW (widget) && GTK_WIDGET_MAPPED (widget)) + gtk_window_unmap (widget); + + GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED | GTK_MAPPED); + + + gtk_style_detach (widget->style); + if (!GTK_WIDGET_NO_WINDOW (widget)) + { + gdk_window_set_user_data (widget->window, NULL); + gdk_window_destroy (widget->window); + } + else + { + gdk_window_unref (widget->window); + } + + if (GTK_IS_CONTAINER (widget)) + gtk_container_foreach (GTK_CONTAINER (widget), + (GtkCallback)gtk_widget_unrealize, + NULL); + if (window->exit) + window->exit(GTK_WIDGET(widget)); + + widget->window = NULL; +} + +void +gtk_window_set_theme (GtkWindow *window, + void (* init) (GtkWidget *window), + void (* border) (GtkWidget *window), + void (* draw) (GtkWidget *window, GdkRectangle *area), + void (* exit) (GtkWidget *window)) +{ + if (GTK_WIDGET_REALIZED(GTK_WIDGET(window))) + window->exit(GTK_WIDGET(window)); + window->init=init; + window->border=border; + window->draw=draw; + window->exit=exit; + if (GTK_WIDGET_REALIZED(GTK_WIDGET(window))) + { + window->init(GTK_WIDGET(window)); + window->draw(GTK_WIDGET(window),NULL); + } +} diff --git a/gtk/gtkwindow.h b/gtk/gtkwindow.h index f1fc2ca1cb..831451884d 100644 --- a/gtk/gtkwindow.h +++ b/gtk/gtkwindow.h @@ -55,6 +55,11 @@ struct _GtkWindow guint handling_resize : 1; guint position : 2; guint use_uposition : 1; + + void (* init) (GtkWidget *window); + void (* border) (GtkWidget *window); + void (* draw) (GtkWidget *window, GdkRectangle *area); + void (* exit) (GtkWidget *window); }; struct _GtkWindowClass @@ -100,6 +105,11 @@ void gtk_window_position (GtkWindow *window, gint gtk_window_activate_focus (GtkWindow *window); gint gtk_window_activate_default (GtkWindow *window); +void gtk_window_set_theme (GtkWindow *window, + void (* init) (GtkWidget *window), + void (* border) (GtkWidget *window), + void (* draw) (GtkWidget *window, GdkRectangle *area), + void (* exit) (GtkWidget *window)); #ifdef __cplusplus } diff --git a/themes/COMPILE_THEME2 b/themes/COMPILE_THEME2 index 3e14abe99b..6ef09e8b34 100755 --- a/themes/COMPILE_THEME2 +++ b/themes/COMPILE_THEME2 @@ -1,5 +1,11 @@ mkdir .libs +gcc -c theme2_checkbutton.c -o theme2_checkbutton.lo \ + -I. -I.. -I../gtk -I../gdk -I../glib -I/usr/X11R6/include \ + -g -O2 -DGTK_NO_CHECK_CASTS -Wall -DUSE_XIM -c -fPIC -DPIC +gcc -c theme2_window.c -o theme2_window.lo \ + -I. -I.. -I../gtk -I../gdk -I../glib -I/usr/X11R6/include \ + -g -O2 -DGTK_NO_CHECK_CASTS -Wall -DUSE_XIM -c -fPIC -DPIC gcc -c theme2_button.c -o theme2_button.lo \ -I. -I.. -I../gtk -I../gdk -I../glib -I/usr/X11R6/include \ -g -O2 -DGTK_NO_CHECK_CASTS -Wall -DUSE_XIM -c -fPIC -DPIC @@ -11,11 +17,13 @@ gcc -c theme2_main.c -o theme2_main.lo \ -lgdk_imlib -ljpeg -lpng -ltiff -lm -lz -lgif -lgdk -lX11 -lXext \ -L/usr/X11R6/lib \ -DUSE_XIM -o libtheme2.la -rpath /usr/local/lib -version-info 1:0:0 \ +theme2_checkbutton.lo \ +theme2_window.lo \ theme2_button.lo \ theme2_main.lo # NEED to do this to install sample theme (run testgtk with --theme theme2) # for user -ln -sf `pwd`.libs ~/themes +ln -sf `pwd`/.libs ~/themes cp -r theme_data/* ~/themes/ diff --git a/themes/theme2.h b/themes/theme2.h index 88fa0076b4..48a1007576 100644 --- a/themes/theme2.h +++ b/themes/theme2.h @@ -4,6 +4,8 @@ #include "gtkthemes.h" #include "gtkprivate.h" #include "gtkbutton.h" +#include "gtkcheckbutton.h" +#include "gtkwindow.h" #include "gtklabel.h" #include "gtkmain.h" #include "gtksignal.h" @@ -39,13 +41,26 @@ typedef struct _themebuttonconfig { /* Border between outside of button and any children (eg label) */ GdkImlibBorder button_padding; + int min_w,min_h; ThemeButtonBorder border; ThemeButtonBackground background; int number_of_decorations; ThemeButtonDecoration *decoration; } ThemeButtonConfig; +typedef struct _themewindowconfig +{ + /* Border between outside of button and any children (eg label) */ + GdkImlibBorder window_padding; + int min_w,min_h; + ThemeButtonBorder border; + ThemeButtonBackground background; + int number_of_decorations; + ThemeButtonDecoration *decoration; +} ThemeWindowConfig; + typedef struct _themeconfig { ThemeButtonConfig buttonconfig[3][5][2]; + ThemeWindowConfig windowconfig; } ThemeConfig; diff --git a/themes/theme2_button.c b/themes/theme2_button.c index 38043b6c0f..4a85a307dc 100644 --- a/themes/theme2_button.c +++ b/themes/theme2_button.c @@ -47,6 +47,10 @@ button_border (GtkWidget *widget) cf->buttonconfig[def][state][foc].button_padding.top; GTK_CONTAINER(widget)->internal_border_bottom= cf->buttonconfig[def][state][foc].button_padding.bottom; + GTK_CONTAINER(widget)->minimum_width= + cf->buttonconfig[def][state][foc].min_w; + GTK_CONTAINER(widget)->minimum_height= + cf->buttonconfig[def][state][foc].min_h; } void @@ -68,7 +72,13 @@ button_draw (GtkWidget *widget, int state,def,foc; ThemeConfig *cf; int i,x,y,w,h; + GdkPixmap *pmap,*p; + GdkPixmap *mask,*m; + GdkGC *mgc,*gc; + GdkColor cl; + char refresh=0; + if (!widget->window) return; cf=(ThemeConfig *)th_dat.data; bi=gtk_object_get_data(GTK_OBJECT(widget),"gtk-widget-theme-data"); def=0; @@ -81,14 +91,24 @@ button_draw (GtkWidget *widget, else if (GTK_WIDGET_STATE(widget)==GTK_STATE_PRELIGHT) state=2; else if (GTK_WIDGET_STATE(widget)==GTK_STATE_SELECTED) state=3; else if (GTK_WIDGET_STATE(widget)==GTK_STATE_INSENSITIVE) state=4; + pmap=NULL; + mask=NULL; if ((bi->state!=state)||(bi->foc!=foc)||(bi->def!=def)|| (bi->w!=widget->allocation.width)||(bi->h!=widget->allocation.height)) + refresh=1; + if (refresh) { if (cf->buttonconfig[def][state][foc].background.image) { if (cf->buttonconfig[def][state][foc].background.scale_to_fit) - gdk_imlib_apply_image(cf->buttonconfig[def][state][foc].background.image, - widget->window); + { + + gdk_imlib_render(cf->buttonconfig[def][state][foc].background.image, + widget->allocation.width, + widget->allocation.height); + pmap=gdk_imlib_move_image(cf->buttonconfig[def][state][foc].background.image); + mask=gdk_imlib_copy_mask(cf->buttonconfig[def][state][foc].background.image); + } else { GdkPixmap *pmap; @@ -116,32 +136,81 @@ button_draw (GtkWidget *widget, bi->w=widget->allocation.width;bi->h=widget->allocation.height; bi->state=state;bi->foc=foc;bi->def=def; } - if (cf->buttonconfig[def][state][foc].border.image) + if (pmap) { - gdk_imlib_paste_image_border(cf->buttonconfig[def][state][foc].border.image, - widget->window, - 0,0,widget->allocation.width, - widget->allocation.height); + gdk_window_set_back_pixmap(widget->window,pmap,0); + gdk_window_clear(widget->window); + gdk_imlib_free_pixmap(pmap); } - for(i=0;i<cf->buttonconfig[def][state][foc].number_of_decorations;i++) + if (cf->buttonconfig[def][state][foc].border.image) + gdk_imlib_paste_image_border(cf->buttonconfig[def][state][foc].border.image, + widget->window, + 0,0,widget->allocation.width, + widget->allocation.height); + if (cf->buttonconfig[def][state][foc].number_of_decorations>0) { - if (cf->buttonconfig[def][state][foc].decoration[i].image) + mgc=NULL; + gc = gdk_gc_new(widget->window); + if (mask) { - x=cf->buttonconfig[def][state][foc].decoration[i].xabs+ - ((cf->buttonconfig[def][state][foc].decoration[i].xrel* - widget->allocation.width)>>10); - y=cf->buttonconfig[def][state][foc].decoration[i].yabs+ - ((cf->buttonconfig[def][state][foc].decoration[i].yrel* - widget->allocation.height)>>10); - w=cf->buttonconfig[def][state][foc].decoration[i].x2abs+ - ((cf->buttonconfig[def][state][foc].decoration[i].x2rel* - widget->allocation.width)>>10)-x; - h=cf->buttonconfig[def][state][foc].decoration[i].y2abs+ - ((cf->buttonconfig[def][state][foc].decoration[i].y2rel* - widget->allocation.height)>>10)-y; - gdk_imlib_paste_image(cf->buttonconfig[def][state][foc].decoration[i].image, - widget->window,x,y,w,h); + mgc = gdk_gc_new(mask); + gdk_gc_set_function(mgc, GDK_OR); + cl.pixel=1; + gdk_gc_set_foreground(mgc, &cl); } + for(i=0;i<cf->buttonconfig[def][state][foc].number_of_decorations;i++) + { + if (cf->buttonconfig[def][state][foc].decoration[i].image) + { + x=cf->buttonconfig[def][state][foc].decoration[i].xabs+ + ((cf->buttonconfig[def][state][foc].decoration[i].xrel* + widget->allocation.width)>>10); + y=cf->buttonconfig[def][state][foc].decoration[i].yabs+ + ((cf->buttonconfig[def][state][foc].decoration[i].yrel* + widget->allocation.height)>>10); + w=cf->buttonconfig[def][state][foc].decoration[i].x2abs+ + ((cf->buttonconfig[def][state][foc].decoration[i].x2rel* + widget->allocation.width)>>10)-x+1; + h=cf->buttonconfig[def][state][foc].decoration[i].y2abs+ + ((cf->buttonconfig[def][state][foc].decoration[i].y2rel* + widget->allocation.height)>>10)-y+1; + p=NULL;m=NULL; + gdk_imlib_render(cf->buttonconfig[def][state][foc].decoration[i].image,w,h); + p=gdk_imlib_move_image(cf->buttonconfig[def][state][foc].decoration[i].image); + m=gdk_imlib_move_mask(cf->buttonconfig[def][state][foc].decoration[i].image); + if (p) + { + if (m) + { + gdk_gc_set_clip_mask(gc, m); + gdk_gc_set_clip_origin(gc, x, y); + } + else + gdk_gc_set_clip_mask(gc, NULL); + gdk_draw_pixmap(widget->window, gc, p, 0, 0, x, y, w, h); + if (mask) + { + /* temporary until I work out why OR doesnt OR */ + gdk_gc_set_clip_mask(mgc, m); + gdk_gc_set_clip_origin(mgc, x, y); + /* end temp */ + if (m) + gdk_draw_pixmap(mask, mgc, m, 0, 0, x, y, w, h); + else + gdk_draw_rectangle(mask, mgc, TRUE, x, y, w, h); + } + gdk_imlib_free_pixmap(p); + } + } + } + if (mask) + gdk_gc_destroy(mgc); + gdk_gc_destroy(gc); + } + if (mask) + { + gdk_window_shape_combine_mask(widget->window,mask,0,0); + gdk_imlib_free_pixmap(mask); } } diff --git a/themes/theme2_checkbutton.c b/themes/theme2_checkbutton.c new file mode 100644 index 0000000000..73eee4e7d8 --- /dev/null +++ b/themes/theme2_checkbutton.c @@ -0,0 +1,141 @@ +#include "theme2.h" + +#define CHILD_SPACING 1 +#define DEFAULT_LEFT_POS 4 +#define DEFAULT_TOP_POS 4 +#define DEFAULT_SPACING 7 + +#define CHECK_BUTTON_CLASS(w) GTK_CHECK_BUTTON_CLASS (GTK_OBJECT (w)->klass) + +struct _butinfo +{ + int state; + int foc; + int def; + int w,h; +}; + +/* Theme functions to export */ +void check_button_border (GtkWidget *widget); +void check_button_init (GtkWidget *widget); +void check_button_draw (GtkWidget *widget, + GdkRectangle *area); +void check_button_exit (GtkWidget *widget); + +/* internals */ + +void +check_button_border (GtkWidget *widget) +{ + ThemeConfig *cf; + int state,def,foc; + + cf=(ThemeConfig *)th_dat.data; + def=0; + if (GTK_WIDGET_CAN_DEFAULT(widget)) def=1; + if (GTK_WIDGET_HAS_DEFAULT(widget)) def=2; + foc=0; + if (GTK_WIDGET_HAS_FOCUS(widget)) foc=1; + state=0; + if (GTK_WIDGET_STATE(widget)==GTK_STATE_ACTIVE) state=1; + else if (GTK_WIDGET_STATE(widget)==GTK_STATE_PRELIGHT) state=2; + else if (GTK_WIDGET_STATE(widget)==GTK_STATE_SELECTED) state=3; + else if (GTK_WIDGET_STATE(widget)==GTK_STATE_INSENSITIVE) state=4; + GTK_CONTAINER(widget)->internal_border_left= + cf->buttonconfig[def][state][foc].button_padding.left; + GTK_CONTAINER(widget)->internal_border_right= + cf->buttonconfig[def][state][foc].button_padding.right; + GTK_CONTAINER(widget)->internal_border_top= + cf->buttonconfig[def][state][foc].button_padding.top; + GTK_CONTAINER(widget)->internal_border_bottom= + cf->buttonconfig[def][state][foc].button_padding.bottom; + GTK_CONTAINER(widget)->minimum_width= + cf->buttonconfig[def][state][foc].min_w; + GTK_CONTAINER(widget)->minimum_height= + cf->buttonconfig[def][state][foc].min_h; +} + +void +check_button_init (GtkWidget *widget) +{ + struct _butinfo *bi; + + bi=malloc(sizeof(struct _butinfo)); + GTK_CONTAINER(widget)->border_width=0; + gtk_object_set_data(GTK_OBJECT(widget),"gtk-widget-theme-data",bi); + bi->w=-1;bi->h=-1;bi->state=-1;bi->foc=-1;bi->def=-1; +} + +void +check_button_draw (GtkWidget *widget, + GdkRectangle *area) +{ + struct _butinfo *bi; + int state,def,foc; + ThemeConfig *cf; + int i,x,y,w,h; + GdkPixmap *pmap,*p; + GdkPixmap *mask,*m; + GdkGC *mgc,*gc; + GdkColor cl; + char refresh=0; + + if (!widget->window) return; + cf=(ThemeConfig *)th_dat.data; + bi=gtk_object_get_data(GTK_OBJECT(widget),"gtk-widget-theme-data"); + def=0; + if (GTK_WIDGET_CAN_DEFAULT(widget)) def=1; + if (GTK_WIDGET_HAS_DEFAULT(widget)) def=2; + foc=0; + if (GTK_WIDGET_HAS_FOCUS(widget)) foc=1; + state=0; + if (GTK_WIDGET_STATE(widget)==GTK_STATE_ACTIVE) state=1; + else if (GTK_WIDGET_STATE(widget)==GTK_STATE_PRELIGHT) state=2; + else if (GTK_WIDGET_STATE(widget)==GTK_STATE_SELECTED) state=3; + else if (GTK_WIDGET_STATE(widget)==GTK_STATE_INSENSITIVE) state=4; + pmap=NULL; + mask=NULL; + if ((bi->state!=state)||(bi->foc!=foc)||(bi->def!=def)|| + (bi->w!=widget->allocation.width)||(bi->h!=widget->allocation.height)) + refresh=1; + refresh=1; + if (refresh) + { + gdk_window_clear(widget->window); + gdk_flush(); + if (cf->buttonconfig[def][state][foc].background.image) + { + x = CHECK_BUTTON_CLASS (widget)->indicator_spacing + + GTK_CONTAINER (widget)->border_width; + y = (widget->allocation.height - + CHECK_BUTTON_CLASS (widget)->indicator_size) / 2; + w = CHECK_BUTTON_CLASS (widget)->indicator_size; + h = CHECK_BUTTON_CLASS (widget)->indicator_size; + + if (cf->buttonconfig[def][state][foc].background.scale_to_fit) + { + gdk_imlib_paste_image(cf->buttonconfig[def][state][foc].background.image, + widget->window,x,y,w,h); + } + } + bi->w=widget->allocation.width;bi->h=widget->allocation.height; + bi->state=state;bi->foc=foc;bi->def=def; + } +/* if (cf->buttonconfig[def][state][foc].border.image) + gdk_imlib_paste_image_border(cf->buttonconfig[def][state][foc].border.image, + widget->window, + 0,0,widget->allocation.width, + widget->allocation.height); + */ +} + +void +check_button_exit (GtkWidget *widget) +{ + struct _butinfo *bi; + + bi=gtk_object_get_data(GTK_OBJECT(widget),"gtk-widget-theme-data"); + free(bi); + gtk_object_remove_data(GTK_OBJECT(widget),"gtk-widget-theme-data"); +} + diff --git a/themes/theme2_main.c b/themes/theme2_main.c index e9f84c7703..68c48ac5be 100644 --- a/themes/theme2_main.c +++ b/themes/theme2_main.c @@ -30,6 +30,8 @@ theme_read_config () cf->buttonconfig[i][j][k].button_padding.right=1; cf->buttonconfig[i][j][k].button_padding.top=1; cf->buttonconfig[i][j][k].button_padding.bottom=1; + cf->buttonconfig[i][j][k].min_w=0; + cf->buttonconfig[i][j][k].min_h=0; cf->buttonconfig[i][j][k].border.filename=NULL; cf->buttonconfig[i][j][k].border.image=NULL; cf->buttonconfig[i][j][k].background.filename=NULL; @@ -39,6 +41,18 @@ theme_read_config () } } } + cf->windowconfig.window_padding.left=1; + cf->windowconfig.window_padding.right=1; + cf->windowconfig.window_padding.top=1; + cf->windowconfig.window_padding.bottom=1; + cf->windowconfig.min_w=0; + cf->windowconfig.min_h=0; + cf->windowconfig.border.filename=NULL; + cf->windowconfig.border.image=NULL; + cf->windowconfig.background.filename=NULL; + cf->windowconfig.background.image=NULL; + cf->windowconfig.number_of_decorations=0; + cf->windowconfig.decoration=NULL; if (!f) { fprintf(stderr,"THEME ERROR: No config file found. Looked for %s\n",s); @@ -46,7 +60,6 @@ theme_read_config () } while(fgets(s,2048,f)) { - printf("%s",s); if (s[0]!='#') { ss[0]=0; @@ -62,6 +75,12 @@ theme_read_config () cf->buttonconfig[a][b][c].button_padding.top=k; cf->buttonconfig[a][b][c].button_padding.bottom=l; } + else if (!strcmp(ss,"minimums")) + { + sscanf(s,"%*s %*i %*i %*i %*s %i %i",&i,&j); + cf->buttonconfig[a][b][c].min_w=i; + cf->buttonconfig[a][b][c].min_h=j; + } else if (!strcmp(ss,"background")) { sscanf(s,"%*s %*i %*i %*i %*s %s",ss); @@ -128,7 +147,6 @@ theme_read_config () else if (!strcmp(ss,"border")) { sscanf(s,"%*s %*i %*i %*i %*s %*s %i %i %i %i",&i,&j,&k,&l); - printf("%i %i %i * %i %i %i %i\n",a,b,c,i,j,k,l); cf->buttonconfig[a][b][c].border.border.left=i; cf->buttonconfig[a][b][c].border.border.right=j; cf->buttonconfig[a][b][c].border.border.top=k; @@ -194,6 +212,154 @@ theme_read_config () } } } + else if (!strcmp(ss,"window")) + { + sscanf(s,"%*s %s",ss); + if (!strcmp(ss,"padding")) + { + sscanf(s,"%*s %*s %i %i %i %i",&i,&j,&k,&l); + cf->windowconfig.window_padding.left=i; + cf->windowconfig.window_padding.right=j; + cf->windowconfig.window_padding.top=k; + cf->windowconfig.window_padding.bottom=l; + } + else if (!strcmp(ss,"minimums")) + { + sscanf(s,"%*s %*s %i %i",&i,&j); + cf->windowconfig.min_w=i; + cf->windowconfig.min_h=j; + } + else if (!strcmp(ss,"background")) + { + sscanf(s,"%*s %*s %s",ss); + if (!strcmp(ss,"image")) + { + sscanf(s,"%*s %*s %*s %s",ss); + snprintf(s,2048,"%s/themes/%s",h,ss); + cf->windowconfig.background.filename=strdup(s); + cf->windowconfig.background.image= + gdk_imlib_load_image(cf->windowconfig.background.filename); + if (!cf->windowconfig.background.image) + { + fprintf(stderr,"ERROR: Cannot load %s\n",cf->windowconfig.background.filename); + exit(1); + } + } + else if (!strcmp(ss,"color")) + { + sscanf(s,"%*s %*s %*s %i %i %i",&i,&j,&k); + cf->windowconfig.background.color.r=i; + cf->windowconfig.background.color.g=j; + cf->windowconfig.background.color.b=k; + cf->windowconfig.background.color.pixel= + gdk_imlib_best_color_match(&i,&j,&k); + } + else if (!strcmp(ss,"border")) + { + sscanf(s,"%*s %*s %*s %i %i %i %i",&i,&j,&k,&l); + cf->windowconfig.background.border.left=i; + cf->windowconfig.background.border.right=j; + cf->windowconfig.background.border.top=k; + cf->windowconfig.background.border.bottom=l; + if (cf->windowconfig.background.image) + gdk_imlib_set_image_border(cf->windowconfig.background.image, + &cf->windowconfig.background.border); + } + else if (!strcmp(ss,"scale")) + { + sscanf(s,"%*s %*s %*s %i",&i); + cf->windowconfig.background.scale_to_fit=i; + } + else if (!strcmp(ss,"parent_tile")) + { + sscanf(s,"%*s %*s %*s %i",&i); + cf->windowconfig.background.tile_relative_to_parent=i; + } + } + else if (!strcmp(ss,"border")) + { + sscanf(s,"%*s %*s %s",ss); + if (!strcmp(ss,"image")) + { + sscanf(s,"%*s %*s %*s %s",ss); + snprintf(s,2048,"%s/themes/%s",h,ss); + cf->windowconfig.border.filename=strdup(s); + cf->windowconfig.border.image= + gdk_imlib_load_image(cf->windowconfig.border.filename); + if (!cf->windowconfig.border.image) + { + fprintf(stderr,"ERROR: Cannot load %s\n",cf->windowconfig.border.filename); + exit(1); + } + } + else if (!strcmp(ss,"border")) + { + sscanf(s,"%*s %*s %*s %i %i %i %i",&i,&j,&k,&l); + cf->windowconfig.border.border.left=i; + cf->windowconfig.border.border.right=j; + cf->windowconfig.border.border.top=k; + cf->windowconfig.border.border.bottom=l; + if (cf->windowconfig.border.image) + gdk_imlib_set_image_border(cf->windowconfig.border.image, + &cf->windowconfig.border.border); + } + } + else if (!strcmp(ss,"decoration")) + { + sscanf(s,"%*s %*s %s",ss); + if (!strcmp(ss,"image")) + { + sscanf(s,"%*s %*s %*s %s",ss); + snprintf(s,2048,"%s/themes/%s",h,ss); + cf->windowconfig.number_of_decorations++; + cf->windowconfig.decoration=realloc + (cf->windowconfig.decoration, + cf->windowconfig.number_of_decorations* + sizeof(ThemeButtonDecoration)); + cf->windowconfig.decoration + [cf->windowconfig.number_of_decorations-1] + .filename=strdup(s); + cf->windowconfig.decoration[cf->windowconfig.number_of_decorations-1].image= + gdk_imlib_load_image(cf->windowconfig.decoration + [cf->windowconfig.number_of_decorations-1].filename); + if (!cf->windowconfig.decoration + [cf->windowconfig.number_of_decorations-1] + .image) + { + fprintf(stderr,"ERROR: Cannot load %s\n",cf->windowconfig.decoration[cf->windowconfig.number_of_decorations-1].filename); + exit(1); + } + } + else if (!strcmp(ss,"coords")) + { + sscanf(s,"%*s %*s %*s %i %i %i %i %i %i %i %i",&i,&j,&k,&l,&m,&n,&o,&p); + cf->windowconfig.decoration + [cf->windowconfig.number_of_decorations-1] + .xrel=i; + cf->windowconfig.decoration + [cf->windowconfig.number_of_decorations-1] + .yrel=j; + cf->windowconfig.decoration + [cf->windowconfig.number_of_decorations-1] + .xabs=k; + cf->windowconfig.decoration + [cf->windowconfig.number_of_decorations-1] + .yabs=l; + cf->windowconfig.decoration + [cf->windowconfig.number_of_decorations-1] + .x2rel=m; + cf->windowconfig.decoration + [cf->windowconfig.number_of_decorations-1] + .y2rel=n; + cf->windowconfig.decoration + [cf->windowconfig.number_of_decorations-1] + .x2abs=o; + cf->windowconfig.decoration + [cf->windowconfig.number_of_decorations-1] + .y2abs=p; + } + } + } } } fclose(f); diff --git a/themes/theme2_window.c b/themes/theme2_window.c new file mode 100644 index 0000000000..eede6d7dfa --- /dev/null +++ b/themes/theme2_window.c @@ -0,0 +1,196 @@ +#include "theme2.h" + +#define CHILD_SPACING 1 +#define DEFAULT_LEFT_POS 4 +#define DEFAULT_TOP_POS 4 +#define DEFAULT_SPACING 7 + +/* Theme functions to export */ +void window_border (GtkWidget *widget); +void window_init (GtkWidget *widget); +void window_draw (GtkWidget *widget, + GdkRectangle *area); +void window_exit (GtkWidget *widget); + +/* internals */ +struct _wininfo +{ + int w,h; +}; + +void +window_border (GtkWidget *widget) +{ + ThemeConfig *cf; + + cf=(ThemeConfig *)th_dat.data; + GTK_CONTAINER(widget)->internal_border_left= + cf->windowconfig.window_padding.left; + GTK_CONTAINER(widget)->internal_border_right= + cf->windowconfig.window_padding.right; + GTK_CONTAINER(widget)->internal_border_top= + cf->windowconfig.window_padding.top; + GTK_CONTAINER(widget)->internal_border_bottom= + cf->windowconfig.window_padding.bottom; + GTK_CONTAINER(widget)->minimum_width= + cf->windowconfig.min_w; + GTK_CONTAINER(widget)->minimum_height= + cf->windowconfig.min_h; +} + +void +window_init (GtkWidget *widget) +{ + struct _wininfo *wi; + + wi=malloc(sizeof(struct _wininfo)); + GTK_CONTAINER(widget)->border_width=0; + gtk_object_set_data(GTK_OBJECT(widget),"gtk-widget-theme-data",wi); + wi->w=-1;wi->h=-1; +} + +void +window_draw (GtkWidget *widget, + GdkRectangle *area) +{ + struct _wininfo *wi; + ThemeConfig *cf; + int i,x,y,w,h; + GdkPixmap *pmap,*p; + GdkPixmap *mask,*m; + GdkGC *mgc,*gc; + GdkColor cl; + char refresh=0; + + if (!widget->window) return; + wi=gtk_object_get_data(GTK_OBJECT(widget),"gtk-widget-theme-data"); + cf=(ThemeConfig *)th_dat.data; + pmap=NULL; + mask=NULL; + if ((wi->w!=widget->allocation.width)||(wi->h!=widget->allocation.height)) + refresh=1; + if (refresh) + { + if (cf->windowconfig.background.image) + { + if (cf->windowconfig.background.scale_to_fit) + { + + gdk_imlib_render(cf->windowconfig.background.image, + widget->allocation.width, + widget->allocation.height); + pmap=gdk_imlib_move_image(cf->windowconfig.background.image); + mask=gdk_imlib_copy_mask(cf->windowconfig.background.image); + } + else + { + GdkPixmap *pmap; + + gdk_imlib_render(cf->windowconfig.background.image, + cf->windowconfig.background.image->rgb_width, + cf->windowconfig.background.image->rgb_height); + pmap=gdk_imlib_move_image(cf->windowconfig.background.image); + if (pmap) + { + gdk_window_set_back_pixmap(widget->window,pmap,0); + gdk_window_clear(widget->window); + gdk_imlib_free_pixmap(pmap); + } + } + } + else + { + GdkColor cl; + + cl.pixel=cf->windowconfig.background.color.pixel; + gdk_window_set_background(widget->window,&cl); + gdk_window_clear(widget->window); + } + wi->w=widget->allocation.width;wi->h=widget->allocation.height; + } + if (pmap) + { + gdk_window_set_back_pixmap(widget->window,pmap,0); + gdk_window_clear(widget->window); + gdk_imlib_free_pixmap(pmap); + } + if (cf->windowconfig.border.image) + gdk_imlib_paste_image_border(cf->windowconfig.border.image, + widget->window, + 0,0,widget->allocation.width, + widget->allocation.height); + if (cf->windowconfig.number_of_decorations>0) + { + mgc=NULL; + gc = gdk_gc_new(widget->window); + if (mask) + { + mgc = gdk_gc_new(mask); + gdk_gc_set_function(mgc, GDK_OR); + cl.pixel=1; + gdk_gc_set_foreground(mgc, &cl); + } + for(i=0;i<cf->windowconfig.number_of_decorations;i++) + { + if (cf->windowconfig.decoration[i].image) + { + x=cf->windowconfig.decoration[i].xabs+ + ((cf->windowconfig.decoration[i].xrel* + widget->allocation.width)>>10); + y=cf->windowconfig.decoration[i].yabs+ + ((cf->windowconfig.decoration[i].yrel* + widget->allocation.height)>>10); + w=cf->windowconfig.decoration[i].x2abs+ + ((cf->windowconfig.decoration[i].x2rel* + widget->allocation.width)>>10)-x+1; + h=cf->windowconfig.decoration[i].y2abs+ + ((cf->windowconfig.decoration[i].y2rel* + widget->allocation.height)>>10)-y+1; + p=NULL;m=NULL; + gdk_imlib_render(cf->windowconfig.decoration[i].image,w,h); + p=gdk_imlib_move_image(cf->windowconfig.decoration[i].image); + m=gdk_imlib_move_mask(cf->windowconfig.decoration[i].image); + if (p) + { + if (m) + { + gdk_gc_set_clip_mask(gc, m); + gdk_gc_set_clip_origin(gc, x, y); + } + else + gdk_gc_set_clip_mask(gc, NULL); + gdk_draw_pixmap(widget->window, gc, p, 0, 0, x, y, w, h); + if (mask) + { + gdk_gc_set_clip_mask(mgc, m); + gdk_gc_set_clip_origin(mgc, x, y); + if (m) + gdk_draw_pixmap(mask, mgc, m, 0, 0, x, y, w, h); + else + gdk_draw_rectangle(mask, mgc, TRUE, x, y, w, h); + } + gdk_imlib_free_pixmap(p); + } + } + } + if (mask) + gdk_gc_destroy(mgc); + gdk_gc_destroy(gc); + } + if (mask) + { + gdk_window_shape_combine_mask(widget->window,mask,0,0); + gdk_imlib_free_pixmap(mask); + } +} + +void +window_exit (GtkWidget *widget) +{ + struct _wininfo *wi; + + wi=gtk_object_get_data(GTK_OBJECT(widget),"gtk-widget-theme-data"); + free(wi); + gtk_object_remove_data(GTK_OBJECT(widget),"gtk-widget-theme-data"); +} + |