Started implementing menus in general and on the Unix backend.
This commit is contained in:
parent
fbe806a348
commit
9f82838632
10
test.c
10
test.c
|
@ -5,6 +5,13 @@
|
||||||
|
|
||||||
// TODO convert to using the new conversion macros
|
// TODO convert to using the new conversion macros
|
||||||
|
|
||||||
|
static const uiMenu menu[] = {
|
||||||
|
{ "File", NULL },
|
||||||
|
{ "Edit", NULL },
|
||||||
|
{ "Help", NULL },
|
||||||
|
{ NULL, NULL },
|
||||||
|
};
|
||||||
|
|
||||||
int onClosing(uiWindow *w, void *data)
|
int onClosing(uiWindow *w, void *data)
|
||||||
{
|
{
|
||||||
printf("in closing!\n");
|
printf("in closing!\n");
|
||||||
|
@ -201,6 +208,7 @@ int main(int argc, char *argv[])
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
o.Menu = menu;
|
||||||
err = uiInit(&o);
|
err = uiInit(&o);
|
||||||
if (err != NULL) {
|
if (err != NULL) {
|
||||||
fprintf(stderr, "error initializing ui: %s\n", err);
|
fprintf(stderr, "error initializing ui: %s\n", err);
|
||||||
|
@ -208,7 +216,7 @@ int main(int argc, char *argv[])
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
w = uiNewWindow("Hello", 320, 240);
|
w = uiNewWindow("Hello", 320, 240, 1);
|
||||||
uiWindowOnClosing(w, onClosing, NULL);
|
uiWindowOnClosing(w, onClosing, NULL);
|
||||||
|
|
||||||
boxes[0] = uiNewVerticalBox();
|
boxes[0] = uiNewVerticalBox();
|
||||||
|
|
4
ui.idl
4
ui.idl
|
@ -22,7 +22,7 @@ struct InitOptions {
|
||||||
field debugLogAllocations int;
|
field debugLogAllocations int;
|
||||||
|
|
||||||
// This is the menu that the application will use.
|
// This is the menu that the application will use.
|
||||||
// To give this menu to a uiWindow, specify nonzero for the hasMenu parameter to uiNewWindow().
|
// To give this menu to a uiWindow, specify nonzero for the hasMenubar parameter to uiNewWindow().
|
||||||
// This value, nor any element of the array it points to, should never change during execution of the program.
|
// This value, nor any element of the array it points to, should never change during execution of the program.
|
||||||
// TODO make it a proper const *const
|
// TODO make it a proper const *const
|
||||||
// TODO idl2h doesn't support making this even const * yet...
|
// TODO idl2h doesn't support making this even const * yet...
|
||||||
|
@ -89,7 +89,7 @@ interface Window {
|
||||||
func Margined(void) int;
|
func Margined(void) int;
|
||||||
func SetMargined(margined int);
|
func SetMargined(margined int);
|
||||||
};
|
};
|
||||||
func NewWindow(title *const char, width int, height int) *Window;
|
func NewWindow(title *const char, width int, height int, hasMenubar int) *Window;
|
||||||
|
|
||||||
interface Button from Control {
|
interface Button from Control {
|
||||||
func Text(void) *char;
|
func Text(void) *char;
|
||||||
|
|
|
@ -7,6 +7,7 @@ OSCFILES = \
|
||||||
label.c \
|
label.c \
|
||||||
lifetimes.c \
|
lifetimes.c \
|
||||||
main.c \
|
main.c \
|
||||||
|
menu.c \
|
||||||
newcontrol.c \
|
newcontrol.c \
|
||||||
parent.c \
|
parent.c \
|
||||||
tab.c \
|
tab.c \
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
// 20 april 2015
|
||||||
|
#include "uipriv_unix.h"
|
||||||
|
|
||||||
|
static GtkWidget *makeMenuItem(const char *name, uiMenuItem *items)
|
||||||
|
{
|
||||||
|
return gtk_menu_item_new_with_label(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
GtkWidget *makeMenubar(void)
|
||||||
|
{
|
||||||
|
GtkWidget *menubar;
|
||||||
|
const uiMenu *m;
|
||||||
|
|
||||||
|
if (options.Menu == NULL)
|
||||||
|
complain("asked to give uiWindow a menubar but didn't specify a menu in uiInitOptions");
|
||||||
|
|
||||||
|
menubar = gtk_menu_bar_new();
|
||||||
|
|
||||||
|
for (m = options.Menu; m->Name != NULL; m++)
|
||||||
|
gtk_menu_shell_append(GTK_MENU_SHELL(menubar), makeMenuItem(m->Name, m->Items));
|
||||||
|
|
||||||
|
gtk_widget_set_hexpand(menubar, TRUE);
|
||||||
|
gtk_widget_set_halign(menubar, GTK_ALIGN_FILL);
|
||||||
|
gtk_widget_show_all(menubar);
|
||||||
|
return menubar;
|
||||||
|
}
|
|
@ -16,3 +16,6 @@
|
||||||
// lifetimes.c
|
// lifetimes.c
|
||||||
extern gulong blockDestruction(GtkWidget *, void *);
|
extern gulong blockDestruction(GtkWidget *, void *);
|
||||||
extern void readyToDestroy(GtkWidget *, gulong);
|
extern void readyToDestroy(GtkWidget *, gulong);
|
||||||
|
|
||||||
|
// menu.c
|
||||||
|
extern GtkWidget *makeMenubar(void);
|
||||||
|
|
|
@ -120,9 +120,11 @@ static void windowSetMargined(uiWindow *ww, int margined)
|
||||||
uiParentUpdate(w->content);
|
uiParentUpdate(w->content);
|
||||||
}
|
}
|
||||||
|
|
||||||
uiWindow *uiNewWindow(const char *title, int width, int height)
|
uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
|
||||||
{
|
{
|
||||||
struct window *w;
|
struct window *w;
|
||||||
|
GtkWidget *vbox;
|
||||||
|
GtkWidget *contentWidget;
|
||||||
|
|
||||||
w = uiNew(struct window);
|
w = uiNew(struct window);
|
||||||
|
|
||||||
|
@ -131,12 +133,28 @@ uiWindow *uiNewWindow(const char *title, int width, int height)
|
||||||
w->window = GTK_WINDOW(w->widget);
|
w->window = GTK_WINDOW(w->widget);
|
||||||
|
|
||||||
gtk_window_set_title(w->window, title);
|
gtk_window_set_title(w->window, title);
|
||||||
|
// TODO this does not take menus or CSD into account
|
||||||
gtk_window_resize(w->window, width, height);
|
gtk_window_resize(w->window, width, height);
|
||||||
|
|
||||||
g_signal_connect(w->widget, "delete-event", G_CALLBACK(onClosing), w);
|
g_signal_connect(w->widget, "delete-event", G_CALLBACK(onClosing), w);
|
||||||
w->destroyBlocker = g_signal_connect(w->widget, "destroy", G_CALLBACK(destroyBlocker), w);
|
w->destroyBlocker = g_signal_connect(w->widget, "destroy", G_CALLBACK(destroyBlocker), w);
|
||||||
|
|
||||||
|
if (hasMenubar) {
|
||||||
|
vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
|
||||||
|
gtk_widget_show_all(vbox);
|
||||||
|
gtk_container_add(w->container, vbox);
|
||||||
|
|
||||||
|
gtk_container_add(GTK_CONTAINER(vbox), makeMenubar());
|
||||||
|
|
||||||
|
w->content = uiNewParent((uintptr_t) GTK_CONTAINER(vbox));
|
||||||
|
contentWidget = GTK_WIDGET(uiParentHandle(w->content));
|
||||||
|
gtk_widget_set_hexpand(contentWidget, TRUE);
|
||||||
|
gtk_widget_set_halign(contentWidget, GTK_ALIGN_FILL);
|
||||||
|
gtk_widget_set_vexpand(contentWidget, TRUE);
|
||||||
|
gtk_widget_set_valign(contentWidget, GTK_ALIGN_FILL);
|
||||||
|
} else
|
||||||
w->content = uiNewParent((uintptr_t) (w->container));
|
w->content = uiNewParent((uintptr_t) (w->container));
|
||||||
|
|
||||||
w->onClosing = defaultOnClosing;
|
w->onClosing = defaultOnClosing;
|
||||||
|
|
||||||
uiWindow(w)->Destroy = windowDestroy;
|
uiWindow(w)->Destroy = windowDestroy;
|
||||||
|
|
Loading…
Reference in New Issue