From c2d6d46b9ca89cb1c0729ee599c3566d3d1e7cf7 Mon Sep 17 00:00:00 2001 From: Javier Date: Tue, 28 Jan 2014 16:50:47 +0100 Subject: initial import --- test/Makefile.am | 12 +++++++++ test/client.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/server.c | 40 ++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+) create mode 100644 test/Makefile.am create mode 100644 test/client.c create mode 100644 test/server.c (limited to 'test') diff --git a/test/Makefile.am b/test/Makefile.am new file mode 100644 index 0000000..4455221 --- /dev/null +++ b/test/Makefile.am @@ -0,0 +1,12 @@ +noinst_PROGRAMS = client server + +AM_CPPFLAGS = $(GTK_CFLAGS) +AM_LDFLAGS = $(GTK_LIBS) + +client_SOURCES = client.c +client_CPPFLAGS = $(GTK_CFLAGS) +client_LDADD = $(GTK_LIBS) ../libtopmenu-client/libtopmenu-client.la + +server_SOURCES = server.c +server_CPPFLAGS = $(GTK_CFLAGS) +server_LDADD = $(GTK_LIBS) ../libtopmenu-server/libtopmenu-server.la diff --git a/test/client.c b/test/client.c new file mode 100644 index 0000000..08312e6 --- /dev/null +++ b/test/client.c @@ -0,0 +1,79 @@ +#include + +#include +#include + +#include "../libtopmenu-client/topmenu-client.h" +#include "../libtopmenu-client/topmenu-monitor.h" + +static GtkWindow *mainwin; + +static GtkWidget * create_menu_bar(void) +{ + GtkMenuBar *bar = GTK_MENU_BAR(gtk_menu_bar_new()); + GtkMenuItem *app = GTK_MENU_ITEM(gtk_menu_item_new_with_label("Client")); + GtkMenuItem *file = GTK_MENU_ITEM(gtk_menu_item_new_with_mnemonic("_File")); + GtkMenuItem *edit = GTK_MENU_ITEM(gtk_menu_item_new_with_mnemonic("_Edit")); + GtkMenuItem *help = GTK_MENU_ITEM(gtk_menu_item_new_with_mnemonic("_Help")); + + GtkLabel *app_label = GTK_LABEL(gtk_bin_get_child(GTK_BIN(app))); + gtk_label_set_markup(app_label, "Client"); + + gtk_menu_bar_append(bar, GTK_WIDGET(app)); + gtk_menu_bar_append(bar, GTK_WIDGET(file)); + gtk_menu_bar_append(bar, GTK_WIDGET(edit)); + gtk_menu_bar_append(bar, GTK_WIDGET(help)); + + GtkMenu *app_menu = GTK_MENU(gtk_menu_new()); + GtkMenuItem *quit = GTK_MENU_ITEM(gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT, NULL)); + gtk_menu_append(app_menu, GTK_WIDGET(quit)); + gtk_menu_item_set_submenu(app, GTK_WIDGET(app_menu)); + + GtkMenu *file_menu = GTK_MENU(gtk_menu_new()); + GtkMenuItem *new = GTK_MENU_ITEM(gtk_image_menu_item_new_from_stock(GTK_STOCK_NEW, NULL)); + gtk_menu_append(file_menu, GTK_WIDGET(new)); + GtkMenuItem *open = GTK_MENU_ITEM(gtk_image_menu_item_new_from_stock(GTK_STOCK_OPEN, NULL)); + gtk_menu_append(file_menu, GTK_WIDGET(open)); + GtkMenuItem *close = GTK_MENU_ITEM(gtk_image_menu_item_new_from_stock(GTK_STOCK_CLOSE, NULL)); + gtk_menu_append(file_menu, GTK_WIDGET(close)); + gtk_menu_item_set_submenu(file, GTK_WIDGET(file_menu)); + + return GTK_WIDGET(bar); +} + +GtkWindow * create_main_window() +{ + GtkWindow *win = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); + GtkVBox *box = GTK_VBOX(gtk_vbox_new(FALSE, 0)); + GtkLabel *label = GTK_LABEL(gtk_label_new("Hello World")); + + GtkWidget *bar = create_menu_bar(); + + gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(bar), FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(label), TRUE, TRUE, 0); + gtk_container_add(GTK_CONTAINER(win), GTK_WIDGET(box)); + + return win; +} + +int main(int argc, char **argv) +{ + gtk_set_locale(); + gtk_init(&argc, &argv); + + mainwin = create_main_window(); + topmenu_monitor_get_instance(); + + g_signal_connect(mainwin, "destroy", G_CALLBACK(gtk_main_quit), NULL); + + gtk_widget_realize(GTK_WIDGET(mainwin)); + + topmenu_client_connect_window_widget(gtk_widget_get_window(GTK_WIDGET(mainwin)), + create_menu_bar()); + + gtk_widget_show_all(GTK_WIDGET(mainwin)); + + gtk_main(); + + return EXIT_SUCCESS; +} diff --git a/test/server.c b/test/server.c new file mode 100644 index 0000000..d0b9135 --- /dev/null +++ b/test/server.c @@ -0,0 +1,40 @@ +#include + +#include + +#include "../libtopmenu-server/topmenu-widget.h" + +static GtkWindow *mainwin; +static TopMenuWidget *topmenu; + +static gboolean handle_button_press(GtkWidget *widget, GdkEvent *event, gpointer user_data) +{ + g_debug("Mainwin: button press"); + return FALSE; +} + +static void construct_main_window() +{ + mainwin = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); + topmenu = TOPMENU_WIDGET(topmenu_widget_new()); + gtk_container_add(GTK_CONTAINER(mainwin), GTK_WIDGET(topmenu)); +} + +int main(int argc, char **argv) +{ + gtk_set_locale(); + gtk_init(&argc, &argv); + + construct_main_window(); + + g_signal_connect(mainwin, "destroy", G_CALLBACK(gtk_main_quit), NULL); + g_signal_connect(mainwin, "button-press-event", G_CALLBACK(handle_button_press), NULL); + + gtk_window_set_keep_above(mainwin, TRUE); + gtk_window_set_accept_focus(mainwin, FALSE); + gtk_widget_show_all(GTK_WIDGET(mainwin)); + + gtk_main(); + + return EXIT_SUCCESS; +} -- cgit v1.2.3