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

View File

@ -3,6 +3,8 @@
struct label {
uiLabel l;
GtkWidget *widget;
GtkLabel *label;
};
static void onDestroy(GtkWidget *widget, gpointer data)
@ -12,23 +14,24 @@ static void onDestroy(GtkWidget *widget, gpointer data)
uiFree(l);
}
#define LABEL(l) GTK_LABEL(uiControlHandle(uiControl(l)))
static char *getText(uiLabel *l)
static char *labelText(uiLabel *ll)
{
struct label *l = (struct label *) ll;
// 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)
{
struct label *l;
GtkWidget *widget;
l = uiNew(struct label);
@ -39,11 +42,13 @@ uiLabel *uiNewLabel(const char *text)
// TODO yalign 0?
NULL);
widget = GTK_WIDGET(LABEL(l));
g_signal_connect(widget, "destroy", G_CALLBACK(onDestroy), l);
l->widget = WIDGET(l);
l->label = GTK_LABEL(l->widget);
uiLabel(l)->Text = getText;
uiLabel(l)->SetText = setText;
g_signal_connect(l->widget, "destroy", G_CALLBACK(onDestroy), l);
uiLabel(l)->Text = labelText;
uiLabel(l)->SetText = labelSetText;
return uiLabel(l);
}