Converted unix/window.c. Now to test!

This commit is contained in:
Pietro Gagliardi 2015-04-15 22:26:27 -04:00
parent 95cda3c562
commit b659198f16
1 changed files with 59 additions and 27 deletions

View File

@ -1,7 +1,8 @@
// 6 april 2015
#include "uipriv_unix.h"
struct uiWindow {
struct window {
uiWindow w;
GtkWidget *widget;
uiParent *content;
int (*onClosing)(uiWindow *, void *);
@ -11,7 +12,7 @@ struct uiWindow {
static gboolean onClosing(GtkWidget *win, GdkEvent *e, gpointer data)
{
uiWindow *w = (uiWindow *) data;
struct window *w = (struct window *) data;
// return exact values just in case
if ((*(w->onClosing))(w, w->onClosingData))
@ -26,76 +27,80 @@ static int defaultOnClosing(uiWindow *w, void *data)
static void onDestroy(GtkWidget *widget, gpointer data)
{
uiWindow *w = (uiWindow *) data;
struct window *w = (struct window *) data;
uiFree(w);
}
uiWindow *uiNewWindow(char *title, int width, int height)
static void windowDestroy(uiWindow *ww)
{
uiWindow *w;
struct window *w = (struct window *) ww;
w = uiNew(uiWindow);
w->widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(w->widget), title);
gtk_window_resize(GTK_WINDOW(w->widget), width, height);
g_signal_connect(w->widget, "delete-event", G_CALLBACK(onClosing), w);
g_signal_connect(w->widget, "destroy", G_CALLBACK(onDestroy), w);
w->content = uiNewParent((uintptr_t) (w->widget));
w->onClosing = defaultOnClosing;
return w;
}
void uiWindowDestroy(uiWindow *w)
{
gtk_widget_destroy(w->widget);
}
uintptr_t uiWindowHandle(uiWindow *w)
static uintptr_t handle(uiWindow *ww)
{
struct window *w = (struct window *) ww;
return (uintptr_t) (w->widget);
}
char *uiWindowTitle(uiWindow *w)
static char *title(uiWindow *ww)
{
struct window *w = (struct window *) ww;
return g_strdup(gtk_window_get_title(GTK_WINDOW(w->widget)));
}
void uiWindowSetTitle(uiWindow *w, const char *title)
static void setTitle(uiWindow *ww, const char *title)
{
struct window *w = (struct window *) ww;
gtk_window_set_title(GTK_WINDOW(w->widget), title);
}
void uiWindowShow(uiWindow *w)
static void show(uiWindow *ww)
{
struct window *w = (struct window *) ww;
// don't use gtk_widget_show_all(); that will override user hidden settings
gtk_widget_show(w->widget);
}
void uiWindowHide(uiWindow *w)
static void hide(uiWindow *ww)
{
struct window *w = (struct window *) ww;
gtk_widget_hide(w->widget);
}
void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *, void *), void *data)
static void setOnClosing(uiWindow *ww, int (*f)(uiWindow *, void *), void *data)
{
struct window *w = (struct window *) ww;
w->onClosing = f;
w->onClosingData = data;
}
void uiWindowSetChild(uiWindow *w, uiControl *c)
static void setChild(uiWindow *ww, uiControl *c)
{
struct window *w = (struct window *) ww;
uiParentSetChild(w->content, c);
uiParentUpdate(w->content);
}
int uiWindowMargined(uiWindow *w)
static int margined(uiWindow *ww)
{
struct window *w = (struct window *) ww;
return w->margined;
}
void uiWindowSetMargined(uiWindow *w, int margined)
static void setMargined(uiWindow *ww, int margined)
{
struct window *w = (struct window *) ww;
w->margined = margined;
if (w->margined)
uiParentSetMargins(w->content, gtkXMargin, gtkYMargin, gtkXMargin, gtkYMargin);
@ -103,3 +108,30 @@ void uiWindowSetMargined(uiWindow *w, int margined)
uiParentSetMargins(w->content, 0, 0, 0, 0);
uiParentUpdate(w->content);
}
uiWindow *uiNewWindow(char *title, int width, int height)
{
struct window *w;
w = uiNew(struct window);
w->widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(w->widget), title);
gtk_window_resize(GTK_WINDOW(w->widget), width, height);
g_signal_connect(w->widget, "delete-event", G_CALLBACK(onClosing), w);
g_signal_connect(w->widget, "destroy", G_CALLBACK(onDestroy), w);
w->content = uiNewParent((uintptr_t) (w->widget));
w->onClosing = defaultOnClosing;
uiWindow(w)->Destroy = windowDestroy;
uiWindow(w)->Handle = handle;
uiWindow(w)->Title = title;
uiWindow(w)->SetTitle = setTitle;
uiWindow(w)->Show = show;
uiWindow(w)->Hide = hide;
uiWindow(w)->OnClosing = setOnClosing;
uiWindow(w)->SetChild = setChild;
uiWindow(w)->Margined = margined;
uiWindow(w)->SetMargined = setMargined;
return uiWindow(w);
}