diff options
author | StapleButter <thetotalworm@gmail.com> | 2017-10-03 00:28:41 +0200 |
---|---|---|
committer | StapleButter <thetotalworm@gmail.com> | 2017-10-03 00:28:41 +0200 |
commit | 7f05bf24ada9442bfcd4c9b10e44790d2319d629 (patch) | |
tree | aed1095b2ce6ca2065af790177caf421706b7baf /src | |
parent | 04e8bbaca3113c6975e371b81da5f389066ec8b3 (diff) |
libui/GTK: start catching up. atleast now it runs without exploding (mostly).
Diffstat (limited to 'src')
-rw-r--r-- | src/libui_sdl/libui/ui_unix.h | 7 | ||||
-rw-r--r-- | src/libui_sdl/libui/unix/area.c | 5 | ||||
-rw-r--r-- | src/libui_sdl/libui/unix/stddialogs.c | 2 | ||||
-rw-r--r-- | src/libui_sdl/libui/unix/window.c | 56 |
4 files changed, 68 insertions, 2 deletions
diff --git a/src/libui_sdl/libui/ui_unix.h b/src/libui_sdl/libui/ui_unix.h index 5a91257..23bd538 100644 --- a/src/libui_sdl/libui/ui_unix.h +++ b/src/libui_sdl/libui/ui_unix.h @@ -80,6 +80,11 @@ _UI_EXTERN void uiUnixControlSetContainer(uiUnixControl *, GtkContainer *, gbool { \ gtk_widget_set_sensitive(type(c)->widget, FALSE); \ } +#define uiUnixControlDefaultSetFocus(type) \ + static void type ## SetFocus(uiControl *c) \ + { \ + gtk_widget_grab_focus(type(c)->widget); \ + } // TODO this whole addedBefore stuff is a MASSIVE HACK. #define uiUnixControlDefaultSetContainer(type) \ static void type ## SetContainer(uiUnixControl *c, GtkContainer *container, gboolean remove) \ @@ -106,6 +111,7 @@ _UI_EXTERN void uiUnixControlSetContainer(uiUnixControl *, GtkContainer *, gbool uiUnixControlDefaultEnabled(type) \ uiUnixControlDefaultEnable(type) \ uiUnixControlDefaultDisable(type) \ + uiUnixControlDefaultSetFocus(type) \ uiUnixControlDefaultSetContainer(type) #define uiUnixControlAllDefaults(type) \ @@ -126,6 +132,7 @@ _UI_EXTERN void uiUnixControlSetContainer(uiUnixControl *, GtkContainer *, gbool uiControl(var)->Enabled = type ## Enabled; \ uiControl(var)->Enable = type ## Enable; \ uiControl(var)->Disable = type ## Disable; \ + uiControl(var)->SetFocus = type ## SetFocus; \ uiUnixControl(var)->SetContainer = type ## SetContainer; // TODO document _UI_EXTERN uiUnixControl *uiUnixAllocControl(size_t n, uint32_t typesig, const char *typenamestr); diff --git a/src/libui_sdl/libui/unix/area.c b/src/libui_sdl/libui/unix/area.c index d0042e6..bde907a 100644 --- a/src/libui_sdl/libui/unix/area.c +++ b/src/libui_sdl/libui/unix/area.c @@ -439,6 +439,11 @@ static gboolean areaWidget_key_release_event(GtkWidget *w, GdkEventKey *e) return GDK_EVENT_PROPAGATE; } +char* uiKeyName(int scancode) +{ + return "TODO"; +} + enum { pArea = 1, nProps, diff --git a/src/libui_sdl/libui/unix/stddialogs.c b/src/libui_sdl/libui/unix/stddialogs.c index 9d7b62a..64a8b40 100644 --- a/src/libui_sdl/libui/unix/stddialogs.c +++ b/src/libui_sdl/libui/unix/stddialogs.c @@ -4,7 +4,7 @@ // LONGTERM figure out why, and describe, that this is the desired behavior // LONGTERM also point out that font and color buttons also work like this -#define windowWindow(w) (GTK_WINDOW(uiControlHandle(uiControl(w)))) +#define windowWindow(w) ((w)?(GTK_WINDOW(uiControlHandle(uiControl(w)))):NULL) static char *filedialog(GtkWindow *parent, GtkFileChooserAction mode, const gchar *confirm, char* filter, char* initpath) { diff --git a/src/libui_sdl/libui/unix/window.c b/src/libui_sdl/libui/unix/window.c index 3507de9..a908f88 100644 --- a/src/libui_sdl/libui/unix/window.c +++ b/src/libui_sdl/libui/unix/window.c @@ -24,6 +24,13 @@ struct uiWindow { void *onClosingData; void (*onContentSizeChanged)(uiWindow *, void *); void *onContentSizeChangedData; + void (*onDropFile)(uiWindow *, char *, void *); + void *onDropFileData; + void (*onGetFocus)(uiWindow *, void *); + void *onGetFocusData; + void (*onLoseFocus)(uiWindow *, void *); + void *onLoseFocusData; + gboolean fullscreen; }; @@ -46,6 +53,20 @@ static void onSizeAllocate(GtkWidget *widget, GdkRectangle *allocation, gpointer (*(w->onContentSizeChanged))(w, w->onContentSizeChangedData); } +static gboolean onGetFocus(GtkWidget *win, GdkEvent *e, gpointer data) +{ + uiWindow *w = uiWindow(data); + if (w->onGetFocus) + w->onGetFocus(w, w->onGetFocusData); +} + +static gboolean onLoseFocus(GtkWidget *win, GdkEvent *e, gpointer data) +{ + uiWindow *w = uiWindow(data); + if (w->onLoseFocus) + w->onLoseFocus(w, w->onLoseFocusData); +} + static int defaultOnClosing(uiWindow *w, void *data) { return 0; @@ -112,6 +133,7 @@ uiUnixControlDefaultHide(uiWindow) uiUnixControlDefaultEnabled(uiWindow) uiUnixControlDefaultEnable(uiWindow) uiUnixControlDefaultDisable(uiWindow) +uiUnixControlDefaultSetFocus(uiWindow) // TODO? uiUnixControlDefaultSetContainer(uiWindow) @@ -194,6 +216,24 @@ void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *, void *), void *data) w->onClosingData = data; } +void uiWindowOnDropFile(uiWindow *w, void (*f)(uiWindow *, char *, void *), void *data) +{ + w->onDropFile = f; + w->onDropFileData = data; +} + +void uiWindowOnGetFocus(uiWindow *w, void (*f)(uiWindow *, void *), void *data) +{ + w->onGetFocus = f; + w->onGetFocusData = data; +} + +void uiWindowOnLoseFocus(uiWindow *w, void (*f)(uiWindow *, void *), void *data) +{ + w->onLoseFocus = f; + w->onLoseFocusData = data; +} + int uiWindowBorderless(uiWindow *w) { return gtk_window_get_decorated(w->window) == FALSE; @@ -229,7 +269,12 @@ void uiWindowSetMargined(uiWindow *w, int margined) setMargined(w->childHolderContainer, w->margined); } -uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar) +void uiWindowSetDropTarget(uiWindow* w, int drop) +{ + printf("DRAG DROP TODO!!!!!\n"); +} + +uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar, int resizable) { uiWindow *w; @@ -272,12 +317,21 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar) // and connect our events g_signal_connect(w->widget, "delete-event", G_CALLBACK(onClosing), w); g_signal_connect(w->childHolderWidget, "size-allocate", G_CALLBACK(onSizeAllocate), w); + g_signal_connect(w->widget, "focus-in-event", G_CALLBACK(onGetFocus), w); + g_signal_connect(w->widget, "focus-out-event", G_CALLBACK(onLoseFocus), w); + uiWindowOnClosing(w, defaultOnClosing, NULL); uiWindowOnContentSizeChanged(w, defaultOnPositionContentSizeChanged, NULL); + + uiWindowOnDropFile(w, NULL, NULL); + uiWindowOnGetFocus(w, NULL, NULL); + uiWindowOnLoseFocus(w, NULL, NULL); // normally it's SetParent() that does this, but we can't call SetParent() on a uiWindow // TODO we really need to clean this up, especially since see uiWindowDestroy() above g_object_ref(w->widget); + + gtk_window_set_resizable(w->window, resizable?TRUE:FALSE); return w; } |