1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
#include <stdlib.h>
#include <gtk/gtk.h>
#include <pthread.h>
#include "ui_gtk.h"
#define MAIN_WINDOW_WIDTH 600
#define MAIN_WINDOW_HEIGHT 90
void * create_window(void * data)
{
GtkWidget * MainWindow = NULL;
GtkWidget * Main_Vertical_Box = NULL;
GtkWidget * first_Horizontal_Box = NULL;
GtkWidget * second_Horizontal_Box = NULL;
GtkWidget * OK_Button = NULL;
GdkScreen * MainScreen= NULL;
gchar * user_information = NULL;
gint MainWindow_width = MAIN_WINDOW_WIDTH;
gint MainWindow_height = MAIN_WINDOW_HEIGHT;
gint Screen_width, Screen_height;
gint adjusted_main_window_x_position, adjusted_main_window_y_position;
printf("******* GTK Window thread created ***********\n");
//Main window creation
MainWindow = gtk_window_new(GTK_WINDOW_POPUP);
g_signal_connect(G_OBJECT(MainWindow), "delete-event", G_CALLBACK(gtk_main_quit), NULL);
//Main box containers creation & initialization
Main_Vertical_Box = gtk_vbox_new(FALSE, 0);
first_Horizontal_Box = gtk_hbox_new(FALSE, 0);
second_Horizontal_Box = gtk_hbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(MainWindow), Main_Vertical_Box);
gtk_box_pack_start(GTK_BOX(Main_Vertical_Box), first_Horizontal_Box, FALSE, FALSE, 5);
gtk_box_pack_start(GTK_BOX(Main_Vertical_Box), second_Horizontal_Box, TRUE, FALSE, 5);
//OK Button creation
OK_Button = gtk_button_new_with_label("OK");
//Window personalization
gtk_window_set_default_size(GTK_WINDOW(MainWindow), MainWindow_width, MainWindow_height);
gtk_window_set_position(GTK_WINDOW(MainWindow), GTK_WIN_POS_CENTER);
//Retrieve screen resolution and adjust popup position (NOTE : Gravity center is upper left corner of windows by default)
MainScreen = gtk_window_get_screen(GTK_WINDOW(MainWindow));
Screen_width = gdk_screen_get_width(MainScreen);
Screen_height = gdk_screen_get_height(MainScreen);
printf("Main screen resolution is %d*%d \n", Screen_width, Screen_height);
adjusted_main_window_x_position = (Screen_width/2) - (MainWindow_width/2);
adjusted_main_window_y_position = Screen_height - MainWindow_height - 10;
gtk_window_move(GTK_WINDOW(MainWindow), adjusted_main_window_x_position, adjusted_main_window_y_position);
//Add widget
...
///
//Add Button & connect "clicked" signal to quit UI interface
gtk_box_pack_start(GTK_BOX(second_Horizontal_Box), OK_Button, TRUE, FALSE, 5);
gtk_widget_set_size_request(OK_Button, 70, 30);
g_signal_connect(G_OBJECT(OK_Button), "clicked", G_CALLBACK(OnDestroy), MainWindow);
//Show main window and loop
gtk_widget_show_all(MainWindow);
gtk_main();
printf("Test \n");
return NULL;
}
void OnDestroy(GtkWidget * pWidget, gpointer pData)
{
gtk_widget_destroy(pData);
gtk_main_quit();
} |
Partager