inconsistency in naming functions...
- From: Antonio Campos <acampos ceronet com>
- To: "gtk-devel-list redhat com" <gtk-devel-list redhat com>
- Subject: inconsistency in naming functions...
- Date: Tue, 14 Mar 2000 13:15:22 +0100
Looking around gtklabel.h, I found that now gtk_label_set is deprecated
in favour of gtk_label_set_text, but at the same time gtk_label_get is
still being used when it should be gtk_label_get_text for a better
naming consistency.
So here it is the patch for having both gtk_label_set_text and
gtk_label_get_text correctly. At the same time I have moved the
compatibility defines:
#define gtk_label_set gtk_label_set_text
#define gtk_label_get gtk_label_get_text
that currently appeared in gtklabel.h inside the more logical
gtkcompat.h.
I have fixed some calls to gtk_label_get with gtk_label_get_text in
gtkcombo.c,
gtkmenu.c and gtkfontsel.c.
So here are the six little patches in order:
1. One for gtklabel.h
2. Other for gtklabel.c
3. Other for gtkcompat.h
4. " for gtkcombo.c
5. " for gtkfontsel.c
6. " for gtkmenu.c
I expect GTKers to give me your opinion about these patches, before I
submit them.
Another someway inconsistent thing:
When I issue gtk_label_set_text(GTK_LABEL(label),my_text), it's known
that my_text is duplicated inside the label structures, so I can safely
say: free(my_text) after issuing the last function call.
But when after looking at the code,
gtk_label_get_text(GTK_LABEL(label),&my_text) makes my_text point to the
label that is in the internal structures of the widget, but doesn't
first duplicate the label in the internal structures of the widget and
then returns the duplication in my_text.
I think this is annoying because is a little inconsistent. Besides that,
suppose that the label widget is destroyed. Then you have a pointer in
my_text to nowhere, and it's a possible "segmentation fault" problem in
the future. (I know nothing about threads, but maybe this is even a
better thing when using them).
My proprosal is making gtk_label_get_text first duplicate the label that
it contains and then returning this duplication to the caller.
I think it shouldn't break any code because I have tested the change and
GNOME continued to work. Although we should advertise people about
possible memory leaks if this change is someday done.
--- /home/kde/joder/gtk+-1.2.6/gtk/gtklabel.h Mon Aug 23 21:40:33 1999
+++ /home/kde/cambios_gtk/gtklabel.h Tue Mar 7 13:47:14 2000
@@ -79,8 +79,8 @@
const gchar *pattern);
void gtk_label_set_line_wrap (GtkLabel *label,
gboolean wrap);
-void gtk_label_get (GtkLabel *label,
- gchar **str);
+void gtk_label_get_text (GtkLabel *label,
+ gchar **str);
/* Convenience function to set the name and pattern by parsing
* a string with embedded underscores, and return the appropriate
@@ -88,10 +88,6 @@
*/
guint gtk_label_parse_uline (GtkLabel *label,
const gchar *string);
-
-#ifndef GTK_DISABLE_COMPAT_H
-# define gtk_label_set gtk_label_set_text
-#endif /* GTK_DISABLE_COMPAT_H */
#ifdef __cplusplus
}
--- /home/kde/joder/gtk+-1.2.6/gtk/gtklabel.c Mon Aug 23 21:40:33 1999
+++ /home/kde/cambios_gtk/gtklabel.c Tue Mar 7 13:47:25 2000
@@ -327,8 +327,8 @@
}
void
-gtk_label_get (GtkLabel *label,
- gchar **str)
+gtk_label_get_text (GtkLabel *label,
+ gchar **str)
{
g_return_if_fail (label != NULL);
g_return_if_fail (GTK_IS_LABEL (label));
--- /home/kde/joder/gtk+-1.2.6/gtk/gtkcompat.h Wed Feb 24 11:14:57 1999
+++ gtkcompat.h Tue Mar 7 13:46:23 2000
@@ -49,6 +49,8 @@
#define gtk_window_position gtk_window_set_position
#define gtk_toggle_button_set_state gtk_toggle_button_set_active
#define gtk_check_menu_item_set_state gtk_check_menu_item_set_active
+#define gtk_label_set gtk_label_set_text
+#define gtk_label_get gtk_label_get_text
/* strongly deprecated: */
#define gtk_ctree_set_reorderable(t,r) gtk_clist_set_reorderable((GtkCList*) (t),(r))
--- /home/kde/joder/gtk+-1.2.6/gtk/gtkcombo.c Wed Feb 24 11:14:57 1999
+++ gtkcombo.c Tue Mar 14 12:21:19 2000
@@ -243,7 +243,7 @@
label = GTK_BIN (li)->child;
if (!label || !GTK_IS_LABEL (label))
return NULL;
- gtk_label_get (GTK_LABEL (label), <ext);
+ gtk_label_get_text (GTK_LABEL (label), <ext);
}
return ltext;
}
--- /home/kde/joder/gtk+-1.2.6/gtk/gtkfontsel.c Fri Sep 3 20:56:57 1999
+++ gtkfontsel.c Tue Mar 14 12:23:32 2000
@@ -1770,7 +1770,7 @@
fontsel->font = font;
/* Make sure the message label is empty, but don't change it unless
it's necessary as it results in a resize of the whole window! */
- gtk_label_get(GTK_LABEL(fontsel->message_label), &label_text);
+ gtk_label_get_text(GTK_LABEL(fontsel->message_label), &label_text);
if (strcmp(label_text, ""))
gtk_label_set_text(GTK_LABEL(fontsel->message_label), "");
gtk_font_selection_update_preview (fontsel);
--- /home/kde/joder/gtk+-1.2.6/gtk/gtkmenu.c Fri Sep 3 20:56:58 1999
+++ gtkmenu.c Tue Mar 14 12:24:51 2000
@@ -724,7 +724,7 @@
{
GtkWidget *child = GTK_BIN (attach_widget)->child;
if (GTK_IS_LABEL (child))
- gtk_label_get (GTK_LABEL (child), &title);
+ gtk_label_get_text (GTK_LABEL (child), &title);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]