Re: [gtk-list] [patch] Broken pixmap_path in gtk's rc files.
- From: Ian Main <slow intergate bc ca>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] [patch] Broken pixmap_path in gtk's rc files.
- Date: Mon, 4 Aug 1997 04:06:26 -0700 (PDT)
On Sun, 3 Aug 1997, Ian Main wrote:
>
>
> Just wondering if anyone has time to fix this ? I'd do it myself, but I'd
Yeah, I'll do it Ian! :)
I got tired of writing documentation and figured I'd do a little real
coding.. since no one else spoke up..
The only thing I'm not sure of, is whether defining a second pixmap_path
should result in removing the old one with the new (which is what I've
done), or adding to the old one (wouldn't be hard to change).
There's probly a better way to do the string handling.. I was looking at
the g_string* functions.. they look interesting, but I didn't figure out
how to change them back to real C strings.. Can I just reach into the
structure and grab g_strdup() it out ?
The g_string_free() function:
void g_string_free (GString *string,
gint free_segment);
What's the free_segment do.. if you don't mind me asking :)
(I know, I know.. use the source Luke! :)
This is a patch against gtk970606's gtkrc.c.
Have fun!
--------------------------------- PATCH ----------------------------------
--- gtkrc.c.orig Mon Aug 4 03:55:39 1997
+++ gtkrc.c Mon Aug 4 03:54:55 1997
@@ -110,6 +110,8 @@
static gint gtk_rc_parse_state (GtkStateType *state);
static gint gtk_rc_parse_color (GdkColor *color);
static gint gtk_rc_parse_pixmap_path (void);
+static void gtk_rc_parse_pixmap_path_string (gchar *pix_path);
+static char* gtk_rc_find_pixmap_in_path (gchar *pixmap_file);
static gint gtk_rc_parse_widget_style (void);
static gint gtk_rc_parse_widget_class_style (void);
static char* gtk_rc_widget_path (GtkWidget *widget);
@@ -177,7 +179,8 @@
static GSList *widget_sets = NULL;
static GSList *widget_class_sets = NULL;
-static char *pixmap_path = NULL;
+#define GTK_RC_MAX_PIXMAP_PATHS 128
+static gchar *pixmap_path[GTK_RC_MAX_PIXMAP_PATHS];
void
@@ -192,7 +195,7 @@
{
input_fp = fopen (filename, "r");
if (!input_fp)
- return;
+ return;
buffer = g_new (char, buffer_size + tokenbuf_size);
tokenbuf = buffer + buffer_size;
@@ -457,8 +460,8 @@
int state;
int count;
int token;
- int hex_number;
- int float_number;
+ int hex_number = 0;
+ int float_number = 0;
char ch;
tokenpos = 0;
@@ -922,7 +925,8 @@
GtkStateType state;
gint token;
gint error;
-
+ gchar *pixmap_file;
+
token = gtk_rc_peek_next_token ();
if (!token)
return PARSE_ERROR;
@@ -942,13 +946,47 @@
if (!token || (token != TOKEN_STRING))
return PARSE_ERROR;
- if (rc_style->bg_pixmap_name[state])
- g_free (rc_style->bg_pixmap_name[state]);
- rc_style->bg_pixmap_name[state] = g_strdup (token_str);
-
+ if(strcmp(token_str, "<parent>"))
+ pixmap_file = gtk_rc_find_pixmap_in_path (token_str);
+ else
+ pixmap_file = strdup(token_str);
+
+ if (pixmap_file)
+ {
+ if (rc_style->bg_pixmap_name[state])
+ g_free (rc_style->bg_pixmap_name[state]);
+ rc_style->bg_pixmap_name[state] = pixmap_file;
+ }
+
return PARSE_OK;
}
+static char* gtk_rc_find_pixmap_in_path (gchar *pixmap_file)
+{
+ gint i;
+ FILE *fp;
+ gchar *buf;
+
+ for (i=0; (i < GTK_RC_MAX_PIXMAP_PATHS) && (pixmap_path[i] != NULL); i++)
+ {
+ buf = g_malloc(strlen(pixmap_path[i]) + strlen(pixmap_file) + 2);
+ sprintf(buf, "%s%c%s", pixmap_path[i], '/', pixmap_file);
+
+ if ( (fp = fopen(buf, "r")) != NULL )
+ {
+ fclose (fp);
+ return(buf);
+ }
+ g_free(buf);
+ }
+ g_warning ("Unable to locate image file in pixmap_path: \"%s\" line %d",
+ pixmap_file, linenum);
+
+ return(NULL);
+}
+
+
+
static gint
gtk_rc_parse_font (GtkRcStyle *rc_style)
{
@@ -1151,14 +1189,50 @@
token = gtk_rc_get_next_token ();
token = gtk_rc_get_next_token ();
+
if (!token || (token != TOKEN_STRING))
return PARSE_ERROR;
- if (pixmap_path)
- g_free (pixmap_path);
- pixmap_path = g_strdup (token_str);
+ gtk_rc_parse_pixmap_path_string(token_str);
return PARSE_OK;
+}
+
+static void gtk_rc_parse_pixmap_path_string(gchar *pix_path)
+{
+ gchar *buf;
+ gint end_offset;
+ gint start_offset = 0;
+ gint path_len;
+ gint path_num;
+
+ /* free the old one, or just add to the old one ? */
+ for (path_num=0; pixmap_path[path_num]; path_num++)
+ {
+ g_free(pixmap_path[path_num]);
+ pixmap_path[path_num] = NULL;
+ }
+
+ path_num = 0;
+
+ path_len = strlen(pix_path);
+
+ buf = g_strdup(pix_path);
+
+ for(end_offset = 0; end_offset <= path_len; end_offset++)
+ {
+ if ( (buf[end_offset] == ':') || (end_offset == path_len) )
+ {
+ buf[end_offset] = '\0';
+ pixmap_path[path_num] = g_strdup(buf + start_offset);
+ path_num++;
+ pixmap_path[path_num] = NULL;
+ start_offset = end_offset + 1;
+ g_free(buf);
+ buf = g_strdup(pix_path);
+ }
+ }
+ g_free(buf);
}
static gint
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]