GTK 3 NoteBook closing tabs - c

what I am trying to do is close tabs in a GTK notebook by a button added to the tab but the function to get the page number does not seem to work and it looks as though the pages close from the last created backwards.
void close_tab(GtkWidget *button, gpointer data){
gint pg_num = gtk_notebook_page_num(GTK_NOTEBOOK(notebook), button);
gtk_notebook_remove_page(GTK_NOTEBOOK(notebook) , pg_num);
}
void add_tab (char *name){
GtkWidget *textview = gtk_text_view_new();
GtkWidget *text = gtk_label_new(name);
GtkWidget *label = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
GtkWidget *icon = gtk_image_new_from_file ("close.png");
GtkWidget *button = gtk_button_new();
gtk_button_set_image(GTK_BUTTON(button), icon);
gtk_widget_set_tooltip_text(button , "Close Tab");
gtk_box_pack_start(GTK_BOX(label), text, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(label), button, FALSE, FALSE, 0);
g_signal_connect(GTK_WIDGET(button), "clicked",
G_CALLBACK(close_tab),
NULL);
GtkWidget *scrollwindow = gtk_scrolled_window_new(NULL, NULL);
gtk_container_add(GTK_CONTAINER(scrollwindow), textview);
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), scrollwindow, label);
gtk_widget_show_all(label);
gtk_widget_show_all(scrollwindow);
}
void button_click(GtkWidget *button, gpointer data){
char *btn = (char *) data;
if (strcmp(btn, "New") == 0);
add_tab("new tab");
}
my experiment is with two tabs the first is made automatically with the 'text' label as "untitled", and the second as "new tab" and tried giving the button the name passed to the add tab function but the result was the same so I don't know how to make the button know what page it belongs to.

I figured out the solution was to pass a direct child of the page as the gpointer data, the only one that seems to work is the scrollwindow.
the remove tab function change
void close_tab(GtkWidget *button, gpointer data){
int pg_num = gtk_notebook_page_num(GTK_NOTEBOOK(notebook), data);
gtk_notebook_remove_page(GTK_NOTEBOOK(notebook) , pg_num);
}
and a change inside the add tab function
GtkWidget *scrollwindow = gtk_scrolled_window_new(NULL, NULL);
gtk_container_add(GTK_CONTAINER(scrollwindow), textview);
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), scrollwindow, label);
g_signal_connect(GTK_WIDGET(button), "clicked",
G_CALLBACK(close_tab),
scrollwindow);

Related

How to remove an image from a widget gtk c?

I am currently working on an user interface with gtk.
What I've done for now is that you can select an image from your file and display it with the button "open".
The problem is that when I open a second image it add the image to the window without removing the current one.
I would like to know how to change the displayed image when the user choose to open another image.
My code:
#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "../Threshold/delete_color.h"
#define GTK_STOCK_CANCEL ((GtkStock)"gtk-cancel")
GtkWidget *image;
gchar* path;
void cb_quit(GtkWidget *p_widget, gpointer user_data)
{
gtk_main_quit();
(void)p_widget;
(void)user_data;
}
void solve(const gchar* path)
{
SDL_Surface* image;
// Binarization
image = binarization((char*) file_name);
SDL_SaveBMP(image, "binarize.bmp");
// Rotation
//rotation(image);
SDL_SaveBMP(image, "rotation.bmp");
// Grid Detection
SDL_SaveBMP(image, "grid.bmp");
// Case detection
// TODO
// Get the grid.txt
// TODO
// Get the grid solution
// TODO
// Create the solution image
// TODO
}
static void set_image(const gchar *file_name, gpointer user_data)
{
GtkWidget *pVBox;
GdkPixbuf *pixbuf;
GError *error = NULL;
pVBox = (GtkWidget*) user_data;
int width = gtk_widget_get_allocated_width(pVBox);
int height = gtk_widget_get_allocated_height(pVBox);
pixbuf = gdk_pixbuf_new_from_file("result.bmp", &error);
if (!error)
{
GdkPixbuf *pixbuf_mini = NULL;
pixbuf_mini = gdk_pixbuf_scale_simple(pixbuf,
width,
height - 200,
GDK_INTERP_NEAREST);
image = gtk_image_new_from_pixbuf(pixbuf_mini);
gtk_container_add(GTK_CONTAINER(pVBox), image);
gtk_widget_show(image);
}
}
void cb_open(GtkWidget *p_widget, gpointer user_data)
{
GtkWidget *p_dialog = NULL;
p_dialog = gtk_file_chooser_dialog_new("Open file", NULL,
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
NULL);
if(gtk_dialog_run (GTK_DIALOG (p_dialog)) == GTK_RESPONSE_ACCEPT)
{
gchar *file_name = NULL;
path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (p_dialog));
file_name = path;
g_print("%s\n", path);
set_image(file_name, user_data);
g_free (file_name), file_name = NULL;
}
gtk_widget_destroy(p_dialog);
(void)p_widget;
}
int main(int argc, char **argv)
{
GtkWidget *p_window = NULL;
GtkWidget *p_main_box = NULL;
// Initialisation
gtk_init (&argc, &argv);
// Main window
p_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(p_window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(p_window), 600, 400);
g_signal_connect (G_OBJECT (p_window), "destroy",
G_CALLBACK (cb_quit), NULL);
// Main container
p_main_box = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER (p_window), p_main_box);
// Exit button
{
GtkWidget *p_button = NULL;
p_button = gtk_button_new_with_label("Exit");
g_signal_connect(G_OBJECT (p_button), "clicked", G_CALLBACK (cb_quit), NULL);
gtk_box_pack_start(GTK_BOX (p_main_box), p_button, FALSE, FALSE, 0);
}
// Open button
{
GtkWidget *p_button = NULL;
p_button = gtk_button_new_with_label ("Open");
g_signal_connect (G_OBJECT (p_button), "clicked", G_CALLBACK (cb_open), (gpointer*) p_main_box);
gtk_box_pack_start (GTK_BOX (p_main_box), p_button, FALSE, FALSE, 0);
}
// Display
gtk_widget_show_all(p_window);
g_print("%s\n", path);
gtk_main();
return EXIT_SUCCESS;
}
You can try multiple approaches.
Remove old image and add new image
Use gtk_container_get_children to retrieve your old image if present and remove it using gtk_container_remove. Then add as you have done before.
You can replace the content of the image
Again, use gtk_container_get_children to retrieve your old image if present and replace the content using gtk_image_set_from_pixbuf.
(additionally to 1 or 2 above)
You can also create an image already when you create the container and use the pointer to that image as user_data for your callback. That would remove the need for retrieving the child from your container.

How to change the background color of the line numbers mode in GTK3+?

I'm designing a text editor in C/GTK3+, using the GtkSourceView class to be able to show the line numbers via the method gtk_source_view_set_show_line_numbers. I'm able to modify the background color of textview and text but not that of panel containing line numbers. By default it seems to be white. Can you show me how to modify it?
This is the code:
#include <gtk/gtk.h>
#include <gtksourceview/gtksource.h>
void find (GtkTextView *text_view, const gchar *text, GtkTextIter *iter)
{
GtkTextIter mstart, mend;
GtkTextBuffer *buffer;
gboolean found;
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
found = gtk_text_iter_forward_search (iter, text, 0, &mstart, &mend, NULL);
if (found)
{
gtk_text_buffer_select_range (buffer, &mstart, &mend);
gtk_text_buffer_create_mark (buffer, "last_pos", &mend, FALSE);
}
}
typedef struct App
{
GtkWidget *text_view;
GtkWidget *search_entry;
} App;
/* Called when main window is destroyed. */
void
win_destroy (void)
{
gtk_main_quit();
}
void
next_button_clicked (GtkWidget *next_button, App *app)
{
const gchar *text;
GtkTextBuffer *buffer;
GtkTextMark *last_pos;
GtkTextIter iter;
text = gtk_entry_get_text (GTK_ENTRY (app->search_entry));
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (app->text_view));
last_pos = gtk_text_buffer_get_mark (buffer, "last_pos");
if (last_pos == NULL)
return;
gtk_text_buffer_get_iter_at_mark (buffer, &iter, last_pos);
find (GTK_TEXT_VIEW (app->text_view), text, &iter);
}
/* Called when search button is clicked. */
void
search_button_clicked (GtkWidget *search_button, App *app)
{
const gchar *text;
GtkTextBuffer *buffer;
GtkTextIter iter;
text = gtk_entry_get_text (GTK_ENTRY (app->search_entry));
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (app->text_view));
gtk_text_buffer_get_start_iter (buffer, &iter);
find (GTK_TEXT_VIEW (app->text_view), text, &iter);
}
int
main (int argc, char *argv[])
{
GtkWidget *win;
GtkWidget *vbox;
GtkWidget *hbox;
GtkWidget *search_button;
GtkWidget *next_button;
GtkWidget *swindow;
GtkCssProvider *provider;
GtkStyleContext *context;
App app;
gtk_init (&argc, &argv);
/* Create a window with a search entry, search button and a text
area. */
win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (G_OBJECT (win), "destroy", win_destroy, NULL);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL,0);
gtk_container_add (GTK_CONTAINER (win), vbox);
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,0);
gtk_container_add(GTK_CONTAINER (vbox), hbox);
app.search_entry = gtk_entry_new ();
search_button = gtk_button_new_with_label ("Search");
next_button = gtk_button_new_with_label ("Next");
gtk_container_add(GTK_CONTAINER (hbox), app.search_entry);
gtk_container_add(GTK_CONTAINER (hbox), search_button);
gtk_container_add(GTK_CONTAINER (hbox), next_button);
g_signal_connect (G_OBJECT (search_button), "clicked",
G_CALLBACK (search_button_clicked), &app);
g_signal_connect (G_OBJECT (next_button), "clicked",
G_CALLBACK (next_button_clicked), &app);
/* A scrolled window which automatically displays horizontal and
vertical scrollbars when the text exceeds the text view's size. */
swindow = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_widget_set_vexpand (swindow, TRUE);
gtk_container_add(GTK_CONTAINER (vbox), swindow);
app.text_view = gtk_source_view_new ();
provider = gtk_css_provider_new ();
gtk_css_provider_load_from_data (provider,
"textview{"
"font-size: 30px;"
"font-family: serif;"
"} text{"
"color: green;"
"background: black;"
"}",
-1,
NULL);
context = gtk_widget_get_style_context (app.text_view);
gtk_style_context_add_provider (context,
GTK_STYLE_PROVIDER (provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
gtk_container_add (GTK_CONTAINER (swindow), app.text_view);
gtk_source_view_set_show_line_numbers (GTK_SOURCE_VIEW((app.text_view)), TRUE);
gtk_widget_show_all (win);
gtk_main();
}
There are generally two possibilities.
The typical way this is done is not by changing colors on the GtkSourceView, but to instead use a style scheme with gtk_source_buffer_set_style_scheme(). The style scheme has a "line-number" and "current-line-number" style which can have a color associated with it.
Another way, that is typically only used to show information about marks, is to have a GtkSourceMark with GtkSourceMarkAttributes:background set. Then you can show marks in the gutter.
Generally speaking, when you get to certain levels of complexity, it's just easier to write your own gutter renderer to optimize for the problem space.

Set the state of a menu item on shortcut press

A program has a menu bar, which has a menu, which has a menu item. The menu item is enabled or disabled depending on some circumstances. Checking of circumstances and enabling/disabling of the menu item is done when a user clicks on the menu that holds that menu item.
But, there is also a shortcut associated with that menu item. The shortcut functions only when the menu item is enabled.
How can we set the state of a menu item without clicking on the menu that holds it, when we want to use a shortcut?
Here is an example program that will hopefully make my question more clear:
#include <gtk/gtk.h>
struct check_sensitivity
{
GtkWidget *menuitem;
GtkTextBuffer *buffer;
};
void sensitivity(GtkWidget *menu, struct check_sensitivity *sens)
{
if (gtk_text_buffer_get_modified(sens->buffer))
gtk_widget_set_sensitive(sens->menuitem, TRUE);
else
gtk_widget_set_sensitive(sens->menuitem, FALSE);
}
void menuitem_click(GtkWidget *menuitem, GtkTextBuffer *buffer)
{
gtk_text_buffer_set_text(buffer, "", -1);
gtk_text_buffer_set_modified(buffer, FALSE);
}
int main(int argc, char **argv)
{
gtk_init(&argc, &argv);
struct check_sensitivity sens;
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
GtkWidget *view = gtk_text_view_new();
sens.buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view));
GtkWidget *menubar = gtk_menu_bar_new();
GtkWidget *menu = gtk_menu_new();
GtkAccelGroup *shortcuts = gtk_accel_group_new();
gtk_window_add_accel_group(GTK_WINDOW(window), shortcuts);
GtkWidget *menuitem = gtk_menu_item_new_with_label("Menu");
gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), menu);
gtk_menu_shell_append(GTK_MENU_SHELL(menubar), menuitem);
g_signal_connect(menuitem, "activate", G_CALLBACK(sensitivity), &sens);
menuitem = gtk_menu_item_new_with_label("Clear");
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
gtk_widget_add_accelerator(menuitem, "activate", shortcuts, GDK_KEY_D, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
sens.menuitem = menuitem;
g_signal_connect(sens.menuitem, "activate", G_CALLBACK(menuitem_click), sens.buffer);
GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_box_pack_start(GTK_BOX(box), menubar, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(box), view, TRUE, TRUE, 0);
gtk_container_add(GTK_CONTAINER(window), box);
gtk_widget_show_all(window);
gtk_main();
}
In this program, the state of menu item "Clear" depends on that whether the buffer is modified or not. The state is, of course, set when the user clicks on the menu "Menu".
There is also a shortcut Ctrl+D that does the same thing as clicking on "Clear". The shortcut works as it should depending on the state of the menu item, but what is wrong is the state of the menu item. Let me explain:
Since the menu item is (un)set when a user click on "Menu", to update the state of "Clear" before using a shortcut, a user must click on it. If the shortcut is used before updating of the state of the menu item, it may not be able to do its function when it should.
Here is what you can try: open the program and write something. Try clearing it with Ctrl+D. You'll see that nothing happens even though it should, because the state of the menu item is not updated. If you click on "Menu", then try using the shortcut again, the text buffer will clear.
I'm just asking for a why to update the state when the shortcut is pressed as well. I tried a few ways that base on setting the state when Ctrl is pressed (I can't check only for Ctrl+D, I may have another shortcuts in a program), but all of them failed or produced bugs. One of those ways you can see here.
If you want to update the menuitem sensitivity depending on if there is text in your textbuffer, connect to the textbuffer changed or modified-changed signal. Since I am not good at C, but normally use Python:
textbuffer.connect("changed", update_menuitem_sensitivity)
changed
modified-changed
Finally found a working method.
#include <gtk/gtk.h>
struct check_sensitivity
{
GtkWidget *menuitem;
GtkTextBuffer *buffer;
};
void sensitivity(GtkWidget *menu, struct check_sensitivity *sens);
void check_sensitivity_on_ctrl(GtkWidget *window, GdkEventKey *key, struct check_sensitivity *sens)
{
if(key->keyval == GDK_KEY_Control_L || key->keyval == GDK_KEY_Control_R)
{
sensitivity(NULL, sens);
}
}
void sensitivity(GtkWidget *menu, struct check_sensitivity *sens)
{
if (gtk_text_buffer_get_modified(sens->buffer))
gtk_widget_set_sensitive(sens->menuitem, TRUE);
else
gtk_widget_set_sensitive(sens->menuitem, FALSE);
}
void menuitem_click(GtkWidget *menuitem, GtkTextBuffer *buffer)
{
gtk_text_buffer_set_text(buffer, "", -1);
gtk_text_buffer_set_modified(buffer, FALSE);
}
int main(int argc, char **argv)
{
gtk_init(&argc, &argv);
struct check_sensitivity sens;
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(window), 400, 400);
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
GtkWidget *view = gtk_text_view_new();
sens.buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view));
gtk_text_buffer_set_modified(sens.buffer, FALSE);
GtkWidget *menubar = gtk_menu_bar_new();
GtkWidget *menu = gtk_menu_new();
GtkAccelGroup *shortcuts = gtk_accel_group_new();
gtk_window_add_accel_group(GTK_WINDOW(window), shortcuts);
GtkWidget *menuitem = gtk_menu_item_new_with_label("Menu");
gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), menu);
gtk_menu_shell_append(GTK_MENU_SHELL(menubar), menuitem);
g_signal_connect(menuitem, "activate", G_CALLBACK(sensitivity), &sens);
menuitem = gtk_menu_item_new_with_label("Clear");
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
gtk_widget_add_accelerator(menuitem, "activate", shortcuts, GDK_KEY_D, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
sens.menuitem = menuitem;
g_signal_connect(sens.menuitem, "activate", G_CALLBACK(menuitem_click), sens.buffer);
g_signal_connect_after(window, "key-press-event", G_CALLBACK(check_sensitivity_on_ctrl), &sens);
GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_box_pack_start(GTK_BOX(box), menubar, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(box), view, TRUE, TRUE, 0);
gtk_container_add(GTK_CONTAINER(window), box);
gtk_widget_show_all(window);
gtk_main();
}

GtkTextView select all text on focus

I'm trying to implement a text view that will have all the text selected when the user clicks on it. However, when I tried the following, the text isn't selected when the text view is clicked, although it is selected after dragging the window.
Consider this minimal example:
#include <gtk/gtk.h>
gboolean cb(GtkWidget *tv, GdkEvent *event, gpointer user_data) {
GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(tv));
GtkTextIter start, end;
gtk_text_buffer_get_start_iter(buf, &start);
gtk_text_buffer_get_end_iter(buf, &end);
gtk_text_buffer_select_range(buf, &start, &end);
return FALSE;
}
int main(int argc, char *argv[]) {
gtk_init(&argc, &argv);
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
GtkWidget *box1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add(GTK_CONTAINER(window), box1);
GtkWidget *tv1 = gtk_text_view_new();
GtkWidget *tv2 = gtk_text_view_new();
gtk_box_pack_start(GTK_BOX(box1), tv1, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(box1), tv2, TRUE, TRUE, 0);
GtkTextBuffer *buf1 = gtk_text_view_get_buffer(GTK_TEXT_VIEW(tv1));
GtkTextBuffer *buf2 = gtk_text_view_get_buffer(GTK_TEXT_VIEW(tv2));
gtk_text_buffer_set_text(buf1, "asdf", -1);
gtk_text_buffer_set_text(buf2, "ghjkl", -1);
g_signal_connect(tv2, "focus-in-event", G_CALLBACK(cb), NULL);
gtk_widget_show(tv1);
gtk_widget_show(tv2);
gtk_widget_show(box1);
gtk_widget_show(window);
gtk_main();
return 0;
}
What should I change to get the desired result?
Connect the callback function to the button-release-event instead.
I expect the focus-in-event isn't triggered when you click on the text view when it already has the input focus. Try using button-press-event instead.

GTK Application doesn't quit from dialog

I'm programming my first bigger GTK+-Application and i have some troubles with exiting the application.
I want to have a Quit-Button in a dialog box, because normally you should run the program in full-screen-mode.
First I tried to call "gtk_main_quit" direktly from a signal but it also didn't work. Now i tried it through an event, the console output works but "gtk_main_quit" doesn't do anything!
Can somebody explain what I'm doing wrong? If you want to give me some tips for better coding, I will really welcome that, too!
Thanks for you help in advance!
#include <stdlib.h>
#include <gtk/gtk.h>
#include <time.h>
static gboolean gtk_delete_event(GtkWidget *widget, GdkEvent *event, gpointer data)
{
g_message("delete event occured\n");
gtk_main_quit();
return TRUE;
}
static void check_toggle_fullscreen (GtkToggleButton *checkButton_fullscreen, GtkWindow *window)
{
if (gtk_toggle_button_get_active(checkButton_fullscreen))
{
gtk_window_fullscreen(GTK_WINDOW(window));
}
else
{
gtk_window_unfullscreen(GTK_WINDOW(window));
}
}
static gboolean double_clicked (GtkWidget *eventbox, GdkEventButton *event, GtkWindow *window)
{
GtkWidget *dialog, *hbox, *checkButton_fullscreen, *image, *button_preferences, *button_closeApp;
dialog = gtk_dialog_new_with_buttons("Schnelleinstellung", window, GTK_DIALOG_MODAL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
checkButton_fullscreen = gtk_check_button_new_with_label("Fullscreen");
image = gtk_image_new_from_stock(GTK_STOCK_FULLSCREEN, GTK_ICON_SIZE_BUTTON);
hbox = gtk_hbox_new(FALSE, 10);
gtk_box_pack_start_defaults (GTK_BOX(hbox), image);
gtk_box_pack_start_defaults (GTK_BOX(hbox), checkButton_fullscreen);
if (gdk_window_get_state(gtk_widget_get_window(GTK_WIDGET(window))) & GDK_WINDOW_STATE_FULLSCREEN)
{
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkButton_fullscreen), TRUE);
}
button_closeApp = gtk_button_new_from_stock(GTK_STOCK_QUIT);
button_preferences = gtk_button_new_from_stock(GTK_STOCK_PREFERENCES);
//Fill dialog with content
gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox);
gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), button_preferences);
gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), button_closeApp);
g_signal_connect(G_OBJECT(checkButton_fullscreen), "toggled", G_CALLBACK(check_toggle_fullscreen), (gpointer)window);
g_signal_connect(G_OBJECT(button_closeApp), "clicked", G_CALLBACK(gtk_delete_event), NULL);
if (event-> type == GDK_2BUTTON_PRESS)
{
gtk_widget_show_all(dialog);
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
}
return FALSE;
}
int main (int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *vbox2;
GtkWidget *label[5];
GtkWidget *frame1, *frame2;
GtkWidget *eventbox;
PangoFontDescription *font;
gtk_init(&argc, &argv);
//Window_TOPLEVEL
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window),"Abnahme");
gtk_window_maximize(GTK_WINDOW(window));
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_NONE);
gtk_window_set_decorated(GTK_WINDOW(window), TRUE);
vbox = gtk_vbox_new(FALSE, 10);
vbox2 = gtk_vbox_new(FALSE, 10);
frame1 = gtk_frame_new("Naechster Skid");
frame2 = gtk_frame_new("Warteschlange");
eventbox = gtk_event_box_new();
gtk_frame_set_shadow_type(GTK_FRAME(frame1), GTK_SHADOW_IN);
gtk_frame_set_shadow_type(GTK_FRAME(frame2), GTK_SHADOW_IN);
label[0] = gtk_label_new("1");
font = pango_font_description_from_string("Arial 40");
gtk_widget_modify_font(label[0], font);
gtk_label_set_markup(GTK_LABEL(label[0]), "<b>Erster Skid</b>");
int j = 1;
while(j<5)
{
gchar buffer[10];
label[j] = gtk_label_new("0");
g_snprintf(buffer, sizeof(buffer), "%i",j+1);
gtk_label_set_markup(GTK_LABEL(label[j]), buffer);
gtk_widget_modify_font(label[j], font);
j++;
}
//Level 0
gtk_container_add(GTK_CONTAINER(window), eventbox);
gtk_event_box_set_above_child(GTK_EVENT_BOX(eventbox), TRUE);
gtk_container_add(GTK_CONTAINER(eventbox), vbox);
//Level 1
gtk_box_pack_start(GTK_BOX(vbox),frame1, TRUE, TRUE, 0);
//Level 2
gtk_container_add(GTK_CONTAINER(frame1), label[0]);
//Level 1
gtk_box_pack_start(GTK_BOX(vbox),frame2, TRUE, TRUE, 0);
//Level 2
gtk_container_add(GTK_CONTAINER(frame2), vbox2);
//Level 3
int i = 1;
while(i<5)
{
gtk_box_pack_start(GTK_BOX(vbox2), label[i], TRUE, TRUE, 0);
i++;
}
//Signals
g_signal_connect_swapped(G_OBJECT(window), "destroy", G_CALLBACK(gtk_delete_event), NULL);
g_signal_connect(G_OBJECT(eventbox), "button_press_event", G_CALLBACK(double_clicked), (gpointer) window);
gtk_widget_set_events(eventbox, GDK_BUTTON_PRESS_MASK);
gtk_widget_realize(eventbox);
/* Enter the main loop */
gtk_widget_show_all (window);
gtk_main ();
return 0;
}
gtk_dialog_run() enters a recursive main loop. gtk_main_quit() only exits the innermost recursion of the main loop.
I don't know if GTK+ provides a clean way to do what you want; you might have to do that yourself somehow.
To delete gtk_dialog_run() and gtk_widget_destroy() like under the code is available to quit dialog button.
if (event-> type == GDK_2BUTTON_PRESS)
{
gtk_widget_show_all(dialog);
/*
* gtk_dialog_run(GTK_DIALOG(dialog));
* gtk_widget_destroy(dialog);
*/
}
It seems that the reason is running dialog is blocking to quit app.

Resources