Cleaned up unix/entry.c and unix/label.c.

This commit is contained in:
Pietro Gagliardi 2015-04-16 22:21:02 -04:00
parent ab0470f7e5
commit 90be2feb7f
2 changed files with 32 additions and 22 deletions

View File

@ -3,6 +3,8 @@
struct entry { struct entry {
uiEntry e; uiEntry e;
GtkWidget *widget;
GtkEntry *entry;
}; };
static void onDestroy(GtkWidget *widget, gpointer data) static void onDestroy(GtkWidget *widget, gpointer data)
@ -12,22 +14,23 @@ static void onDestroy(GtkWidget *widget, gpointer data)
uiFree(e); uiFree(e);
} }
#define ENTRY(e) GTK_ENTRY(uiControlHandle(uiControl(e))) static char *entryText(uiEntry *ee)
static char *getText(uiEntry *e)
{ {
return g_strdup(gtk_entry_get_text(ENTRY(e))); struct entry *e = (struct entry *) ee;
return g_strdup(gtk_entry_get_text(e->entry));
} }
static void setText(uiEntry *e, const char *text) static void entrySetText(uiEntry *ee, const char *text)
{ {
gtk_entry_set_text(ENTRY(e), text); struct entry *e = (struct entry *) ee;
gtk_entry_set_text(e->entry, text);
} }
uiEntry *uiNewEntry(void) uiEntry *uiNewEntry(void)
{ {
struct entry *e; struct entry *e;
GtkWidget *widget;
e = uiNew(struct entry); e = uiNew(struct entry);
@ -35,11 +38,13 @@ uiEntry *uiNewEntry(void)
FALSE, FALSE, FALSE, FALSE,
NULL); NULL);
widget = GTK_WIDGET(ENTRY(e)); e->widget = WIDGET(e);
g_signal_connect(widget, "destroy", G_CALLBACK(onDestroy), e); e->entry = GTK_ENTRY(e->widget);
uiEntry(e)->Text = getText; g_signal_connect(e->widget, "destroy", G_CALLBACK(onDestroy), e);
uiEntry(e)->SetText = setText;
uiEntry(e)->Text = entryText;
uiEntry(e)->SetText = entrySetText;
return uiEntry(e); return uiEntry(e);
} }

View File

@ -3,6 +3,8 @@
struct label { struct label {
uiLabel l; uiLabel l;
GtkWidget *widget;
GtkLabel *label;
}; };
static void onDestroy(GtkWidget *widget, gpointer data) static void onDestroy(GtkWidget *widget, gpointer data)
@ -12,23 +14,24 @@ static void onDestroy(GtkWidget *widget, gpointer data)
uiFree(l); uiFree(l);
} }
#define LABEL(l) GTK_LABEL(uiControlHandle(uiControl(l))) static char *labelText(uiLabel *ll)
static char *getText(uiLabel *l)
{ {
struct label *l = (struct label *) ll;
// TODO change g_strdup() to a wrapper function for export in ui_unix.h // TODO change g_strdup() to a wrapper function for export in ui_unix.h
return g_strdup(gtk_label_get_text(LABEL(l))); return g_strdup(gtk_label_get_text(l->label));
} }
static void setText(uiLabel *l, const char *text) static void labelSetText(uiLabel *ll, const char *text)
{ {
gtk_label_set_text(LABEL(l), text); struct label *l = (struct label *) ll;
gtk_label_set_text(l->label, text);
} }
uiLabel *uiNewLabel(const char *text) uiLabel *uiNewLabel(const char *text)
{ {
struct label *l; struct label *l;
GtkWidget *widget;
l = uiNew(struct label); l = uiNew(struct label);
@ -39,11 +42,13 @@ uiLabel *uiNewLabel(const char *text)
// TODO yalign 0? // TODO yalign 0?
NULL); NULL);
widget = GTK_WIDGET(LABEL(l)); l->widget = WIDGET(l);
g_signal_connect(widget, "destroy", G_CALLBACK(onDestroy), l); l->label = GTK_LABEL(l->widget);
uiLabel(l)->Text = getText; g_signal_connect(l->widget, "destroy", G_CALLBACK(onDestroy), l);
uiLabel(l)->SetText = setText;
uiLabel(l)->Text = labelText;
uiLabel(l)->SetText = labelSetText;
return uiLabel(l); return uiLabel(l);
} }