2015-04-08 22:28:47 -05:00
|
|
|
// 8 april 2015
|
|
|
|
#include "uipriv_unix.h"
|
|
|
|
|
|
|
|
struct entry {
|
2015-04-15 21:17:02 -05:00
|
|
|
uiEntry e;
|
2015-04-16 21:21:02 -05:00
|
|
|
GtkWidget *widget;
|
|
|
|
GtkEntry *entry;
|
2015-05-06 22:18:34 -05:00
|
|
|
GtkEditable *editable;
|
2015-05-06 19:37:42 -05:00
|
|
|
void (*onChanged)(uiEntry *, void *);
|
|
|
|
void *onChangedData;
|
2015-04-08 22:28:47 -05:00
|
|
|
};
|
|
|
|
|
2015-05-06 19:37:42 -05:00
|
|
|
static void onChanged(GtkEditable *editable, gpointer data)
|
|
|
|
{
|
|
|
|
struct entry *e = (struct entry *) data;
|
|
|
|
|
|
|
|
(*(e->onChanged))(uiEntry(e), e->onChangedData);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void defaultOnChanged(uiEntry *e, void *data)
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2015-04-18 16:14:19 -05:00
|
|
|
static void onDestroy(void *data)
|
2015-04-08 22:28:47 -05:00
|
|
|
{
|
2015-04-18 16:14:19 -05:00
|
|
|
struct entry *e = (struct entry *) data;
|
2015-04-08 22:28:47 -05:00
|
|
|
|
|
|
|
uiFree(e);
|
|
|
|
}
|
|
|
|
|
2015-04-16 21:21:02 -05:00
|
|
|
static char *entryText(uiEntry *ee)
|
2015-04-15 21:17:02 -05:00
|
|
|
{
|
2015-04-16 21:21:02 -05:00
|
|
|
struct entry *e = (struct entry *) ee;
|
|
|
|
|
2015-04-30 21:55:06 -05:00
|
|
|
return uiUnixStrdupText(gtk_entry_get_text(e->entry));
|
2015-04-15 21:17:02 -05:00
|
|
|
}
|
|
|
|
|
2015-04-16 21:21:02 -05:00
|
|
|
static void entrySetText(uiEntry *ee, const char *text)
|
2015-04-15 21:17:02 -05:00
|
|
|
{
|
2015-04-16 21:21:02 -05:00
|
|
|
struct entry *e = (struct entry *) ee;
|
|
|
|
|
|
|
|
gtk_entry_set_text(e->entry, text);
|
2015-04-15 21:17:02 -05:00
|
|
|
}
|
|
|
|
|
2015-05-06 19:37:42 -05:00
|
|
|
static void entryOnChanged(uiEntry *ee, void (*f)(uiEntry *, void *), void *data)
|
|
|
|
{
|
|
|
|
struct entry *e = (struct entry *) ee;
|
|
|
|
|
|
|
|
e->onChanged = f;
|
|
|
|
e->onChangedData = data;
|
|
|
|
}
|
|
|
|
|
2015-05-06 22:18:34 -05:00
|
|
|
static int entryReadOnly(uiEntry *ee)
|
|
|
|
{
|
|
|
|
struct entry *e = (struct entry *) ee;
|
|
|
|
|
|
|
|
return gtk_editable_get_editable(e->editable) == FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void entrySetReadOnly(uiEntry *ee, int readonly)
|
|
|
|
{
|
|
|
|
struct entry *e = (struct entry *) ee;
|
|
|
|
gboolean editable;
|
|
|
|
|
|
|
|
editable = TRUE;
|
|
|
|
if (readonly)
|
|
|
|
editable = FALSE;
|
|
|
|
gtk_editable_set_editable(e->editable, editable);
|
|
|
|
}
|
|
|
|
|
2015-04-15 22:07:43 -05:00
|
|
|
uiEntry *uiNewEntry(void)
|
2015-04-08 22:28:47 -05:00
|
|
|
{
|
|
|
|
struct entry *e;
|
|
|
|
|
2015-04-15 21:17:02 -05:00
|
|
|
e = uiNew(struct entry);
|
|
|
|
|
2015-05-02 19:51:00 -05:00
|
|
|
uiUnixMakeControl(uiControl(e), GTK_TYPE_ENTRY,
|
2015-04-18 16:14:19 -05:00
|
|
|
FALSE, FALSE, onDestroy, e,
|
2015-04-08 22:28:47 -05:00
|
|
|
NULL);
|
|
|
|
|
2015-04-29 09:36:31 -05:00
|
|
|
e->widget = GTK_WIDGET(uiControlHandle(uiControl(e)));
|
2015-04-16 21:21:02 -05:00
|
|
|
e->entry = GTK_ENTRY(e->widget);
|
2015-05-06 22:18:34 -05:00
|
|
|
e->editable = GTK_EDITABLE(e->widget);
|
2015-04-16 21:21:02 -05:00
|
|
|
|
2015-05-06 19:37:42 -05:00
|
|
|
g_signal_connect(e->widget, "changed", G_CALLBACK(onChanged), e);
|
|
|
|
e->onChanged = defaultOnChanged;
|
|
|
|
|
2015-04-16 21:21:02 -05:00
|
|
|
uiEntry(e)->Text = entryText;
|
|
|
|
uiEntry(e)->SetText = entrySetText;
|
2015-05-06 19:37:42 -05:00
|
|
|
uiEntry(e)->OnChanged = entryOnChanged;
|
2015-05-06 22:18:34 -05:00
|
|
|
uiEntry(e)->ReadOnly = entryReadOnly;
|
|
|
|
uiEntry(e)->SetReadOnly = entrySetReadOnly;
|
2015-04-09 01:56:51 -05:00
|
|
|
|
2015-04-15 21:17:02 -05:00
|
|
|
return uiEntry(e);
|
2015-04-09 01:56:51 -05:00
|
|
|
}
|