GtkWidget * create_dialog (void) { GtkWidget *dlg; GtkWidget *hbox, *vbox, *hbox2, *bbox; GtkWidget *image; GtkWidget *text; GtkWidget *main_widget = NULL; GtkWidget *topb = NULL; /* create dialog window */ dlg = gtk_dialog_new (); if (options.data.splash) gtk_window_set_type_hint (GTK_WINDOW (dlg), GDK_WINDOW_TYPE_HINT_SPLASHSCREEN); else gtk_window_set_type_hint (GTK_WINDOW (dlg), GDK_WINDOW_TYPE_HINT_NORMAL); gtk_window_set_title (GTK_WINDOW (dlg), options.data.dialog_title); gtk_widget_set_name (dlg, "yad-dialog-window"); #ifndef G_OS_WIN32 if (options.parent) { gdk_window_set_transient_for (gtk_widget_get_window (dlg), gdk_x11_window_foreign_new_for_display (gdk_display_get_default (), options.parent)); } #endif if (options.data.no_escape) g_signal_connect (G_OBJECT (dlg), "close", G_CALLBACK (ignore_close_cb) , NULL); /* get buttons container */ bbox = gtk_dialog_get_action_area (GTK_DIALOG (dlg)); /* set window icon */ if (options.data.window_icon) { if (g_file_test (options.data.window_icon, G_FILE_TEST_EXISTS)) gtk_window_set_icon_from_file (GTK_WINDOW (dlg), options.data.window_icon, NULL); else gtk_window_set_icon_name (GTK_WINDOW (dlg), options.data.window_icon); } /* set window borders */ if (options.data.borders == -1) options.data.borders = (gint) gtk_container_get_border_width (GTK_CONTAINER (dlg)); gtk_container_set_border_width (GTK_CONTAINER (dlg), (guint) options.data.borders); /* set window size and position */ if (!options.data.geometry && !options.data.maximized && !options.data.fullscreen) { gtk_window_set_default_size (GTK_WINDOW (dlg), options.data.width, options.data.height); if (options.data.center) gtk_window_set_position (GTK_WINDOW (dlg), GTK_WIN_POS_CENTER); else if (options.data.mouse) gtk_window_set_position (GTK_WINDOW (dlg), GTK_WIN_POS_MOUSE); } /* set window behavior */ if (options.data.sticky) gtk_window_stick (GTK_WINDOW (dlg)); gtk_window_set_keep_above (GTK_WINDOW (dlg), options.data.ontop); gtk_window_set_decorated (GTK_WINDOW (dlg), !options.data.undecorated); gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dlg), options.data.skip_taskbar); gtk_window_set_skip_pager_hint (GTK_WINDOW (dlg), options.data.skip_taskbar); /* create timeout indicator widget */ if (options.data.timeout) { if (G_LIKELY (options.data.to_indicator) && g_ascii_strcasecmp (options.data.to_indicator, "none")) { topb = gtk_progress_bar_new (); gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (topb), 1.0); gtk_widget_set_name (topb, "yad-timeout-indicator"); } } /* add top label widgets */ #if !GTK_CHECK_VERSION(3,0,0) hbox = hbox2 = gtk_hbox_new (FALSE, 0); #else hbox = hbox2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); #endif gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), hbox, TRUE, TRUE, 5); #if !GTK_CHECK_VERSION(3,0,0) vbox = gtk_vbox_new (FALSE, 0); #else vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); #endif /* add timeout indicator */ if (topb) { if (g_ascii_strcasecmp (options.data.to_indicator, "top") == 0) { #if !GTK_CHECK_VERSION(3,0,0) gtk_progress_bar_set_orientation (GTK_PROGRESS_BAR (topb), GTK_PROGRESS_LEFT_TO_RIGHT); #endif gtk_box_pack_start (GTK_BOX (vbox), topb, FALSE, FALSE, 2); } else if (g_ascii_strcasecmp (options.data.to_indicator, "bottom") == 0) { #if !GTK_CHECK_VERSION(3,0,0) gtk_progress_bar_set_orientation (GTK_PROGRESS_BAR (topb), GTK_PROGRESS_LEFT_TO_RIGHT); #endif gtk_box_pack_end (GTK_BOX (vbox), topb, FALSE, FALSE, 2); } else if (g_ascii_strcasecmp (options.data.to_indicator, "left") == 0) { #if !GTK_CHECK_VERSION(3,0,0) gtk_progress_bar_set_orientation (GTK_PROGRESS_BAR (topb), GTK_PROGRESS_BOTTOM_TO_TOP); #endif gtk_box_pack_start (GTK_BOX (hbox), topb, FALSE, FALSE, 2); } else if (g_ascii_strcasecmp (options.data.to_indicator, "right") == 0) { #if !GTK_CHECK_VERSION(3,0,0) gtk_progress_bar_set_orientation (GTK_PROGRESS_BAR (topb), GTK_PROGRESS_BOTTOM_TO_TOP); #endif gtk_box_pack_end (GTK_BOX (hbox), topb, FALSE, FALSE, 2); } if (settings.show_remain) { gchar *lbl = g_strdup_printf (_("%d sec"), options.data.timeout); #if GTK_CHECK_VERSION(3,0,0) gtk_progress_bar_set_show_text (GTK_PROGRESS_BAR (topb), TRUE); #endif gtk_progress_bar_set_text (GTK_PROGRESS_BAR (topb), lbl); g_free (lbl); } } /* must be after indicator! */ gtk_box_pack_end (GTK_BOX (hbox), vbox, TRUE, TRUE, 0); if (options.data.image_on_top) { #if !GTK_CHECK_VERSION(3,0,0) hbox2 = gtk_hbox_new (FALSE, 0); #else hbox2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); #endif gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 0); } if (options.data.dialog_image) { GdkPixbuf *pb = NULL; pb = get_pixbuf (options.data.dialog_image, YAD_BIG_ICON); image = gtk_image_new_from_pixbuf (pb); if (pb) g_object_unref (pb); gtk_widget_set_name (image, "yad-dialog-image"); gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0); gtk_box_pack_start (GTK_BOX (hbox2), image, FALSE, FALSE, 2); } if (options.data.dialog_text) { /* for dnd's tooltip we don't need text label */ if (options.mode != YAD_MODE_DND || !options.dnd_data.tooltip) { gchar *buf = g_strcompress (options.data.dialog_text); text = gtk_label_new (NULL); if (!options.data.no_markup) gtk_label_set_markup (GTK_LABEL (text), buf); else gtk_label_set_text (GTK_LABEL (text), buf); g_free (buf); gtk_widget_set_name (text, "yad-dialog-label"); gtk_label_set_line_wrap (GTK_LABEL (text), TRUE); gtk_label_set_selectable (GTK_LABEL (text), options.data.selectable_labels); gtk_label_set_justify (GTK_LABEL (text), options.data.text_align); switch (options.data.text_align) { case GTK_JUSTIFY_LEFT: case GTK_JUSTIFY_FILL: gtk_misc_set_alignment (GTK_MISC (text), 0.0, 0.5); break; case GTK_JUSTIFY_CENTER: gtk_misc_set_alignment (GTK_MISC (text), 0.5, 0.5); break; case GTK_JUSTIFY_RIGHT: gtk_misc_set_alignment (GTK_MISC (text), 1.0, 0.5); break; } if (options.data.image_on_top) gtk_box_pack_start (GTK_BOX (hbox2), text, TRUE, TRUE, 2); else gtk_box_pack_start (GTK_BOX (vbox), text, FALSE, FALSE, 2); #if !GTK_CHECK_VERSION(3,0,0) if (!options.data.fixed) g_signal_connect (G_OBJECT (text), "size-allocate", G_CALLBACK (text_size_allocate_cb), NULL); #endif } } /* add main widget */ switch (options.mode) { case YAD_MODE_CALENDAR: main_widget = calendar_create_widget (dlg); break; case YAD_MODE_COLOR: main_widget = color_create_widget (dlg); break; case YAD_MODE_DND: dnd_init (dlg); break; case YAD_MODE_ENTRY: main_widget = entry_create_widget (dlg); break; case YAD_MODE_FILE: main_widget = file_create_widget (dlg); break; case YAD_MODE_FONT: main_widget = font_create_widget (dlg); break; case YAD_MODE_FORM: main_widget = form_create_widget (dlg); break; #ifdef HAVE_HTML case YAD_MODE_HTML: main_widget = html_create_widget (dlg); break; #endif case YAD_MODE_ICONS: main_widget = icons_create_widget (dlg); break; case YAD_MODE_LIST: main_widget = list_create_widget (dlg); break; case YAD_MODE_MULTI_PROGRESS: main_widget = multi_progress_create_widget (dlg); break; case YAD_MODE_NOTEBOOK: main_widget = notebook_create_widget (dlg); break; case YAD_MODE_PANED: main_widget = paned_create_widget (dlg); break; case YAD_MODE_PROGRESS: main_widget = progress_create_widget (dlg); break; case YAD_MODE_SCALE: main_widget = scale_create_widget (dlg); break; case YAD_MODE_TEXTINFO: main_widget = text_create_widget (dlg); break; default: ; } if (main_widget) { if (options.data.expander) { GtkWidget *exp; exp = gtk_expander_new_with_mnemonic (options.data.expander); gtk_expander_set_expanded (GTK_EXPANDER (exp), FALSE); gtk_container_add (GTK_CONTAINER (exp), main_widget); gtk_box_pack_start (GTK_BOX (vbox), exp, TRUE, TRUE, 2); } else gtk_box_pack_start (GTK_BOX (vbox), main_widget, TRUE, TRUE, 2); } /* add buttons */ if (!options.data.no_buttons) { if (options.data.buttons) { GSList *tmp = options.data.buttons; do { GtkWidget *btn; YadButton *b = (YadButton *) tmp->data; btn = gtk_button_new (); gtk_container_add (GTK_CONTAINER (btn), get_label (b->name, 2)); gtk_button_set_alignment (GTK_BUTTON (btn), 0.5, 0.5); g_object_set_data (G_OBJECT (btn), "resp", GINT_TO_POINTER (b->response)); g_signal_connect (G_OBJECT (btn), "clicked", G_CALLBACK (btn_cb), b->cmd); gtk_box_pack_start (GTK_BOX (bbox), btn, FALSE, FALSE, 0); tmp = tmp->next; } while (tmp != NULL); } else { if (options.mode == YAD_MODE_PROGRESS || options.mode == YAD_MODE_MULTI_PROGRESS) gtk_dialog_add_buttons (GTK_DIALOG (dlg), GTK_STOCK_CLOSE, YAD_RESPONSE_OK, NULL); else { if (gtk_alternative_dialog_button_order (NULL)) gtk_dialog_add_buttons (GTK_DIALOG (dlg), GTK_STOCK_OK, YAD_RESPONSE_OK, GTK_STOCK_CANCEL, YAD_RESPONSE_CANCEL, NULL); else gtk_dialog_add_buttons (GTK_DIALOG (dlg), GTK_STOCK_CANCEL, YAD_RESPONSE_CANCEL, GTK_STOCK_OK, YAD_RESPONSE_OK, NULL); } gtk_dialog_set_default_response (GTK_DIALOG (dlg), YAD_RESPONSE_OK); } gtk_button_box_set_layout (GTK_BUTTON_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dlg))), options.data.buttons_layout); } /* show widgets */ gtk_widget_show_all (gtk_dialog_get_content_area (GTK_DIALOG (dlg))); if (options.data.no_buttons) gtk_widget_hide (bbox); /* parse geometry, if given. must be after showing widget */ if (options.data.geometry && !options.data.maximized && !options.data.fullscreen) { gtk_widget_realize (dlg); gtk_window_parse_geometry (GTK_WINDOW (dlg), options.data.geometry); } gtk_widget_show (dlg); /* set maximized or fixed size after showing widget */ if (options.data.maximized) gtk_window_maximize (GTK_WINDOW (dlg)); else if (options.data.fullscreen) gtk_window_fullscreen (GTK_WINDOW (dlg)); else { gtk_window_set_resizable (GTK_WINDOW (dlg), !options.data.fixed); if (options.data.fixed) gtk_widget_set_size_request (dlg, options.data.width, options.data.height); } /* set timeout */ if (options.data.timeout) { g_timeout_add_seconds (options.data.timeout, timeout_cb, dlg); g_timeout_add_seconds (1, timeout_indicator_cb, topb); } #ifndef G_OS_WIN32 /* print xid */ if (options.print_xid) { fprintf (stderr, "0x%lX", GDK_WINDOW_XID (gtk_widget_get_window (dlg))); fflush (stderr); } #endif return dlg; }
gint main(gint argc, gchar **argv) { Conf *conf; GtkItemFactory *ifactory; gchar *stdin_data = NULL; bindtextdomain(PACKAGE, LOCALEDIR); //bindtextdomain ?? bind_textdomain_codeset(PACKAGE, "UTF-8"); // ?? textdomain(PACKAGE); // ?? pub = g_malloc(sizeof(PublicData)); pub->fi = g_malloc(sizeof(FileInfo)); pub->fi->filename = NULL; pub->fi->charset = NULL; pub->fi->charset_flag = FALSE; pub->fi->lineend = LF; parse_args(argc, argv, pub->fi); gtk_init(&argc, &argv); //call before using any gtk fuction g_set_application_name(PACKAGE_NAME); g_print("%s\n", PACKAGE_NAME); #if !GTK_CHECK_VERSION(2, 6, 0) add_about_stock(); #endif pub->mw = create_main_window(); //Find create_main_window conf = g_malloc(sizeof(Conf)); //sends default vlues to load and overwrites in the function conf->width = 600; conf->height = 400; conf->fontname = g_strdup("Monospace 12"); conf->wordwrap = FALSE; conf->linenumbers = FALSE; conf->autoindent = FALSE; load_config_file(conf); //gtk options for GUI gtk_window_set_default_size( GTK_WINDOW(pub->mw->window), conf->width, conf->height); set_text_font_by_name(pub->mw->view, conf->fontname); ifactory = gtk_item_factory_from_widget(pub->mw->menubar); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM( gtk_item_factory_get_widget(ifactory, "/Options/Word Wrap")), conf->wordwrap); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM( gtk_item_factory_get_widget(ifactory, "/Options/Line Numbers")), conf->linenumbers); indent_refresh_tab_width(pub->mw->view); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM( gtk_item_factory_get_widget(ifactory, "/Options/Auto Indent")), conf->autoindent); gtk_widget_show_all(pub->mw->window); g_free(conf->fontname); g_free(conf); #ifdef ENABLE_EMACS check_emacs_key_theme(GTK_WINDOW(pub->mw->window), ifactory); #endif hlight_init(pub->mw->buffer); undo_init(pub->mw->view, gtk_item_factory_get_widget(ifactory, "/Edit/Undo"), gtk_item_factory_get_widget(ifactory, "/Edit/Redo")); // hlight_init(pub->mw->buffer); dnd_init(pub->mw->view); if (pub->fi->filename) file_open_real(pub->mw->view, pub->fi); #ifdef G_OS_UNIX else stdin_data = gedit_utils_get_stdin(); #endif if (stdin_data) { gchar *str; GtkTextIter iter; str = g_convert(stdin_data, -1, "UTF-8", get_default_charset(), NULL, NULL, NULL); g_free(stdin_data); // gtk_text_buffer_set_text(buffer, "", 0); gtk_text_buffer_get_start_iter(pub->mw->buffer, &iter); gtk_text_buffer_insert(pub->mw->buffer, &iter, str, strlen(str)); gtk_text_buffer_get_start_iter(pub->mw->buffer, &iter); gtk_text_buffer_place_cursor(pub->mw->buffer, &iter); gtk_text_buffer_set_modified(pub->mw->buffer, FALSE); gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(pub->mw->view), &iter, 0, FALSE, 0, 0); g_free(str); } if (jump_linenum) { GtkTextIter iter; gtk_text_buffer_get_iter_at_line(pub->mw->buffer, &iter, jump_linenum - 1); gtk_text_buffer_place_cursor(pub->mw->buffer, &iter); // gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(textview), &iter, 0.1, FALSE, 0.5, 0.5); scroll_to_cursor(pub->mw->buffer, 0.25); } set_main_window_title(); // hlight_apply_all(pub->mw->buffer); gtk_main(); return 0; }
GtkWidget *display_tilp_dbox(void) { GtkWidget *dbox; GtkWidget *paned; GError* error = NULL; builder = gtk_builder_new(); if (!gtk_builder_add_from_file (builder, tilp_paths_build_builder("tilp.ui"), &error)) { g_warning (_("Couldn't load builder file: %s\n"), error->message); g_error_free (error); return NULL; // THIS RETURNS ! } gtk_builder_connect_signals(builder, NULL); dbox = GTK_WIDGET (gtk_builder_get_object (builder, "tilp_dbox")); if(options.full_gui) gtk_window_resize(GTK_WINDOW(dbox), options.wnd_x_size1, options.wnd_y_size1); else gtk_window_resize(GTK_WINDOW(dbox), options.wnd_x_size2, options.wnd_y_size2); ctree_wnd = GTK_WIDGET (gtk_builder_get_object (builder, "treeview1")); clist_wnd = GTK_WIDGET (gtk_builder_get_object (builder, "treeview2")); label_wnd.label11 = GTK_WIDGET (gtk_builder_get_object (builder, "label11")); label_wnd.label12 = GTK_WIDGET (gtk_builder_get_object (builder, "label12")); label_wnd.label13 = GTK_WIDGET (gtk_builder_get_object (builder, "label13")); label_wnd.label14 = GTK_WIDGET (gtk_builder_get_object (builder, "label14")); label_wnd.label21 = GTK_WIDGET (gtk_builder_get_object (builder, "label21")); toolbar_wnd.toolbar = GTK_WIDGET (gtk_builder_get_object (builder, "toolbar2")); toolbar_wnd.button10 = GTK_WIDGET (gtk_builder_get_object (builder, "button1")); toolbar_wnd.button11 = GTK_WIDGET (gtk_builder_get_object (builder, "button2")); toolbar_wnd.button12 = GTK_WIDGET (gtk_builder_get_object (builder, "button3")); toolbar_wnd.button13 = GTK_WIDGET (gtk_builder_get_object (builder, "button4")); toolbar_wnd.button14 = GTK_WIDGET (gtk_builder_get_object (builder, "button5")); toolbar_wnd.button15 = GTK_WIDGET (gtk_builder_get_object (builder, "button6")); toolbar_wnd.button20 = GTK_WIDGET (gtk_builder_get_object (builder, "button10")); toolbar_wnd.button21 = GTK_WIDGET (gtk_builder_get_object (builder, "button11")); toolbar_wnd.button22 = GTK_WIDGET (gtk_builder_get_object (builder, "button12")); menubar_wnd.menubar = GTK_WIDGET (gtk_builder_get_object (builder, "menubar1")); menubar_wnd.viewlocal = GTK_WIDGET (gtk_builder_get_object (builder, "menuitem13")); menubar_wnd.showall = GTK_WIDGET (gtk_builder_get_object (builder, "show_all_files1")); menubar_wnd.restore = GTK_WIDGET (gtk_builder_get_object (builder, "imagemenuitem4")); menubar_wnd.backup = GTK_WIDGET (gtk_builder_get_object (builder, "imagemenuitem3")); menubar_wnd.idlist = GTK_WIDGET (gtk_builder_get_object (builder, "menuitem10")); menubar_wnd.setclock = GTK_WIDGET (gtk_builder_get_object (builder, "menuitem9")); menubar_wnd.dumprom = GTK_WIDGET (gtk_builder_get_object (builder, "menuitem8")); paned = GTK_WIDGET (gtk_builder_get_object (builder, "hpaned1")); gtk_paned_set_position(GTK_PANED(paned), options.pane_x_size); show_right_view(options.full_gui); clist_init(); ctree_init(); dnd_init(); return dbox; }
gint main(gint argc, gchar **argv) { Conf *conf; gchar *stdin_data = NULL; bindtextdomain(PACKAGE, LOCALEDIR); bind_textdomain_codeset(PACKAGE, "UTF-8"); textdomain(PACKAGE); pub = g_malloc(sizeof(PublicData)); pub->fi = g_malloc(sizeof(FileInfo)); pub->fi->filename = NULL; pub->fi->charset = NULL; pub->fi->charset_flag = FALSE; pub->fi->lineend = LF; parse_args(argc, argv, pub->fi); #if !ENABLE_XINPUT2 gdk_disable_multidevice(); #endif gtk_init(&argc, &argv); g_set_application_name(PACKAGE_NAME); selection_primary = gtk_clipboard_get(GDK_SELECTION_PRIMARY); pub->mw = create_main_window(); conf = g_malloc(sizeof(Conf)); conf->width = 600; conf->height = 400; conf->fontname = g_strdup("Monospace 12"); conf->wordwrap = FALSE; conf->linenumbers = FALSE; conf->autoindent = FALSE; load_config_file(conf); gtk_window_set_default_size( GTK_WINDOW(pub->mw->window), conf->width, conf->height); set_text_font_by_name(pub->mw->view, conf->fontname); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM( gtk_item_factory_get_widget(pub->mw->menubar, "/M/Options/WordWrap")), conf->wordwrap); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM( gtk_item_factory_get_widget(pub->mw->menubar, "/M/Options/LineNumbers")), conf->linenumbers); indent_refresh_tab_width(pub->mw->view); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM( gtk_item_factory_get_widget(pub->mw->menubar, "/M/Options/AutoIndent")), conf->autoindent); gtk_widget_show_all(pub->mw->window); g_free(conf->fontname); g_free(conf); #if ENABLE_EMACS check_emacs_key_theme(GTK_WINDOW(pub->mw->window), pub->mw->menubar); #endif hlight_init(pub->mw->buffer); undo_init(pub->mw->view, gtk_item_factory_get_widget(pub->mw->menubar, "/M/Edit/Undo"), gtk_item_factory_get_widget(pub->mw->menubar, "/M/Edit/Redo")); // hlight_init(pub->mw->buffer); dnd_init(pub->mw->view); if (pub->fi->filename) file_open_real(pub->mw->view, pub->fi); #ifdef G_OS_UNIX else stdin_data = gedit_utils_get_stdin(); #endif if (stdin_data) { gchar *str; GtkTextIter iter; str = g_convert(stdin_data, -1, "UTF-8", get_default_charset(), NULL, NULL, NULL); g_free(stdin_data); // gtk_text_buffer_set_text(buffer, "", 0); gtk_text_buffer_get_start_iter(pub->mw->buffer, &iter); gtk_text_buffer_insert(pub->mw->buffer, &iter, str, strlen(str)); gtk_text_buffer_get_start_iter(pub->mw->buffer, &iter); gtk_text_buffer_place_cursor(pub->mw->buffer, &iter); gtk_text_buffer_set_modified(pub->mw->buffer, FALSE); gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(pub->mw->view), &iter, 0, FALSE, 0, 0); g_free(str); } if (jump_linenum) { GtkTextIter iter; gtk_text_buffer_get_iter_at_line(pub->mw->buffer, &iter, jump_linenum - 1); gtk_text_buffer_place_cursor(pub->mw->buffer, &iter); // gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(textview), &iter, 0.1, FALSE, 0.5, 0.5); scroll_to_cursor(pub->mw->buffer, 0.25); } set_main_window_title(); indent_refresh_tab_width(pub->mw->view); // hlight_apply_all(pub->mw->buffer); gtk_main(); return 0; }