GtkWidget* _gtk_error_dialog_new (GtkWindow *parent, GtkDialogFlags flags, GList *row_output, const char *primary_text, const char *secondary_text, ...) { GtkWidget *dialog; GtkWidget *label; GtkWidget *image; GtkWidget *hbox; GtkWidget *vbox; GtkWidget *text_view; GtkWidget *scrolled = NULL; GtkWidget *expander; GtkWidget *content_area; GtkWidget *action_area; GtkTextBuffer *text_buf; GtkTextIter iter; char *stock_id; GList *scan; char *escaped_message, *markup_text; va_list args; gboolean view_output = (row_output != NULL); stock_id = GTK_STOCK_DIALOG_ERROR; dialog = gtk_dialog_new_with_buttons ("", parent, flags, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog)); /* Add label and image */ image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_DIALOG); #if GTK_CHECK_VERSION (3, 0, 0) gtk_widget_set_halign (image, GTK_ALIGN_CENTER); gtk_widget_set_valign (image, GTK_ALIGN_START); #else gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0); #endif label = gtk_label_new (""); gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); gtk_label_set_selectable (GTK_LABEL (label), TRUE); #if GTK_CHECK_VERSION (3, 0, 0) gtk_widget_set_halign (label, GTK_ALIGN_START); gtk_widget_set_valign (label, GTK_ALIGN_START); #else gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0); #endif escaped_message = g_markup_escape_text (primary_text, -1); if (secondary_text != NULL) { char *secondary_message; char *escaped_secondary_message; va_start (args, secondary_text); secondary_message = g_strdup_vprintf (secondary_text, args); va_end (args); escaped_secondary_message = g_markup_escape_text (secondary_message, -1); markup_text = g_strdup_printf ("<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s", escaped_message, escaped_secondary_message); g_free (escaped_secondary_message); g_free (secondary_message); } else markup_text = g_strdup (escaped_message); gtk_label_set_markup (GTK_LABEL (label), markup_text); g_free (markup_text); g_free (escaped_message); if (view_output) { gtk_widget_set_size_request (dialog, 500, -1); /* Expander */ expander = gtk_expander_new_with_mnemonic (_("Command _Line Output")); gtk_expander_set_expanded (GTK_EXPANDER (expander), secondary_text == NULL); /* Add text */ scrolled = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled), GTK_SHADOW_ETCHED_IN); gtk_widget_set_size_request (scrolled, -1, 200); text_buf = gtk_text_buffer_new (NULL); gtk_text_buffer_create_tag (text_buf, "monospace", "family", "monospace", NULL); gtk_text_buffer_get_iter_at_offset (text_buf, &iter, 0); for (scan = row_output; scan; scan = scan->next) { char *line = scan->data; char *utf8_line; gsize bytes_written; utf8_line = g_locale_to_utf8 (line, -1, NULL, &bytes_written, NULL); gtk_text_buffer_insert_with_tags_by_name (text_buf, &iter, utf8_line, bytes_written, "monospace", NULL); g_free (utf8_line); gtk_text_buffer_insert (text_buf, &iter, "\n", 1); } text_view = gtk_text_view_new_with_buffer (text_buf); g_object_unref (text_buf); gtk_text_view_set_editable (GTK_TEXT_VIEW (text_view), FALSE); gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (text_view), FALSE); } vbox = gtk_vbox_new (FALSE, 6); hbox = gtk_hbox_new (FALSE, 12); gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0); if (view_output) { gtk_container_add (GTK_CONTAINER (scrolled), text_view); gtk_container_add (GTK_CONTAINER (expander), scrolled); gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0); } gtk_box_pack_start (GTK_BOX (content_area), vbox, FALSE, FALSE, 0); gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); gtk_container_set_border_width (GTK_CONTAINER (hbox), 5); gtk_box_set_spacing (GTK_BOX (content_area), 14); /* 14 + 2 * 5 = 24 */ gtk_container_set_border_width (GTK_CONTAINER (action_area), 5); gtk_box_set_spacing (GTK_BOX (action_area), 6); gtk_widget_show_all (vbox); return dialog; }
void MultilineOptionView::_setActive(bool active) { gtk_text_view_set_editable(myTextView, active); }
GtkWidget * progress_create_widget (GtkWidget * dlg) { GtkWidget *w; GIOChannel *channel; // fix it when vertical specified #if GTK_CHECK_VERSION(3,0,0) w = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); #else w = gtk_vbox_new (FALSE, 0); #endif progress_bar = gtk_progress_bar_new (); gtk_widget_set_name (progress_bar, "yad-progress-widget"); if (options.progress_data.log_on_top) gtk_box_pack_end (GTK_BOX (w), progress_bar, FALSE, FALSE, 0); else gtk_box_pack_start (GTK_BOX (w), progress_bar, FALSE, FALSE, 0); if (options.progress_data.percentage > 100) options.progress_data.percentage = 100; gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), options.progress_data.percentage / 100.0); if (options.progress_data.progress_text) gtk_progress_bar_set_text (GTK_PROGRESS_BAR (progress_bar), options.progress_data.progress_text); #if GTK_CHECK_VERSION(3,0,0) gtk_progress_bar_set_inverted (GTK_PROGRESS_BAR (progress_bar), options.progress_data.rtl); #else if (options.progress_data.rtl) gtk_progress_bar_set_orientation (GTK_PROGRESS_BAR (progress_bar), GTK_PROGRESS_RIGHT_TO_LEFT); #endif if (options.progress_data.log) { GtkWidget *ex, *sw; ex = gtk_expander_new (options.progress_data.log); gtk_expander_set_spacing (GTK_EXPANDER (ex), 2); gtk_expander_set_expanded (GTK_EXPANDER (ex), options.progress_data.log_expanded); gtk_box_pack_start (GTK_BOX (w), ex, TRUE, TRUE, 2); sw = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_ETCHED_IN); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), options.hscroll_policy, options.vscroll_policy); gtk_container_add (GTK_CONTAINER (ex), sw); progress_log = gtk_text_view_new (); gtk_widget_set_name (progress_log, "yad-text-widget"); gtk_widget_set_size_request (progress_log, -1, options.progress_data.log_height); gtk_container_add (GTK_CONTAINER (sw), progress_log); log_buffer = gtk_text_buffer_new (NULL); gtk_text_view_set_buffer (GTK_TEXT_VIEW (progress_log), log_buffer); gtk_text_view_set_left_margin (GTK_TEXT_VIEW (progress_log), 5); gtk_text_view_set_right_margin (GTK_TEXT_VIEW (progress_log), 5); gtk_text_view_set_editable (GTK_TEXT_VIEW (progress_log), FALSE); gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (progress_log), FALSE); } #if GTK_CHECK_VERSION(3,0,0) else gtk_progress_bar_set_show_text (GTK_PROGRESS_BAR (progress_bar), TRUE); #endif channel = g_io_channel_unix_new (0); g_io_channel_set_encoding (channel, NULL, NULL); g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL); g_io_add_watch (channel, G_IO_IN | G_IO_HUP, handle_stdin, dlg); return w; }
static void warlock_view_create_text_view (WarlockView *warlock_view) { PangoFontDescription *font; GdkRGBA *color; GtkTextIter iter; GtkWidget *text_view; text_view = gtk_text_view_new (); gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text_view), GTK_WRAP_WORD_CHAR); gtk_text_view_set_editable (GTK_TEXT_VIEW (text_view), FALSE); warlock_view->text_buffer = gtk_text_buffer_new (highlight_tag_table); warlock_view->text_view = text_view; gtk_text_view_set_buffer (GTK_TEXT_VIEW (text_view), warlock_view->text_buffer); gtk_text_buffer_get_end_iter (warlock_view->text_buffer, &iter); warlock_view->mark = gtk_text_buffer_create_mark (warlock_view->text_buffer, NULL, &iter, TRUE); /* set the text color */ color = preferences_get_color (preferences_get_key (PREF_DEFAULT_TEXT_COLOR)); if (color == NULL) { color = g_new (GdkRGBA, 1); gdk_rgba_parse (color, "white"); } gtk_widget_override_color (text_view, GTK_STATE_NORMAL, color); g_free (color); /* set the background color*/ color = preferences_get_color (preferences_get_key (PREF_DEFAULT_BASE_COLOR)); if (color == NULL) { color = g_new (GdkRGBA, 1); gdk_rgba_parse (color, "black"); } gtk_widget_override_background_color (text_view, GTK_STATE_NORMAL, color); g_free (color); /* set the font */ font = preferences_get_font (preferences_get_key (PREF_DEFAULT_FONT)); if (font == NULL) { font = pango_font_description_from_string ("sans"); } gtk_widget_override_font (text_view, font); /* listen to gconf and change the text color when the gconf * value changes */ preferences_notify_add (preferences_get_key (PREF_DEFAULT_TEXT_COLOR), change_text_color, text_view); /* listen for background change */ preferences_notify_add (preferences_get_key (PREF_DEFAULT_BASE_COLOR), change_base_color, text_view); /* listen for font change */ preferences_notify_add (preferences_get_key (PREF_DEFAULT_FONT), change_font, text_view); }
static GtkWidget *create_dialog(void) { GtkWidget *dialog; GtkWidget *header_image; GtkWidget *header_label; GtkWidget *label_info; GtkWidget *codename_label; GtkWidget *builddate_label; GtkWidget *url_button; GtkWidget *cop_label; GtkWidget *label; GtkWidget *license_textview; GtkWidget *notebook; GtkWidget *box; GtkWidget *credits_scrollwin; GtkWidget *table; GtkWidget *license_scrollwin; GtkWidget *info_box; GtkWidget *header_hbox; GtkWidget *header_eventbox; GtkTextBuffer* tb; gchar *license_text = NULL; gchar buffer[512]; gchar buffer2[128]; guint i, row = 0; gchar *build_date; dialog = gtk_dialog_new(); /* configure dialog */ gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(main_widgets.window)); gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER_ON_PARENT); gtk_window_set_title(GTK_WINDOW(dialog), _("About Geany")); gtk_window_set_icon_name(GTK_WINDOW(dialog), "geany"); gtk_widget_set_name(dialog, "GeanyDialog"); gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE); gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_CLOSE); gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); g_signal_connect(dialog, "key-press-event", G_CALLBACK(gb_on_key_pressed), NULL); /* create header */ header_eventbox = gtk_event_box_new(); gtk_widget_show(header_eventbox); header_hbox = gtk_hbox_new(FALSE, 12); gtk_container_set_border_width(GTK_CONTAINER(header_hbox), 4); gtk_widget_show(header_hbox); gtk_container_add(GTK_CONTAINER(header_eventbox), header_hbox); header_image = gtk_image_new_from_icon_name("geany", GTK_ICON_SIZE_DIALOG); gtk_box_pack_start(GTK_BOX(header_hbox), header_image, FALSE, FALSE, 0); header_label = gtk_label_new(NULL); gtk_label_set_use_markup(GTK_LABEL(header_label), TRUE); /* print the subversion revision generated by ./configure if it is available */ g_snprintf(buffer, sizeof(buffer), HEADER, main_get_version_string()); gtk_label_set_markup(GTK_LABEL(header_label), buffer); gtk_widget_show(header_label); gtk_box_pack_start(GTK_BOX(header_hbox), header_label, FALSE, FALSE, 0); header_eventbox_style_set(header_eventbox); header_label_style_set(header_label); g_signal_connect_after(header_eventbox, "style-set", G_CALLBACK(header_eventbox_style_set), NULL); g_signal_connect_after(header_label, "style-set", G_CALLBACK(header_label_style_set), NULL); gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), header_eventbox, FALSE, FALSE, 0); /* create notebook */ notebook = gtk_notebook_new(); gtk_widget_show(notebook); gtk_container_set_border_width(GTK_CONTAINER(notebook), 2); gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), notebook, TRUE, TRUE, 0); /* create "Info" tab */ info_box = gtk_vbox_new(FALSE, 0); gtk_container_set_border_width(GTK_CONTAINER(info_box), 6); gtk_widget_show(info_box); label_info = gtk_label_new(NULL); gtk_label_set_justify(GTK_LABEL(label_info), GTK_JUSTIFY_CENTER); gtk_label_set_selectable(GTK_LABEL(label_info), TRUE); gtk_label_set_use_markup(GTK_LABEL(label_info), TRUE); g_snprintf(buffer, sizeof(buffer), INFO, _("A fast and lightweight IDE")); gtk_label_set_markup(GTK_LABEL(label_info), buffer); gtk_misc_set_padding(GTK_MISC(label_info), 2, 11); gtk_widget_show(label_info); gtk_box_pack_start(GTK_BOX(info_box), label_info, FALSE, FALSE, 0); /* Codename label */ codename_label = gtk_label_new(NULL); gtk_label_set_justify(GTK_LABEL(codename_label), GTK_JUSTIFY_CENTER); gtk_label_set_selectable(GTK_LABEL(codename_label), TRUE); gtk_label_set_use_markup(GTK_LABEL(codename_label), TRUE); gtk_label_set_markup(GTK_LABEL(codename_label), CODENAME); gtk_misc_set_padding(GTK_MISC(codename_label), 2, 8); gtk_widget_show(codename_label); gtk_box_pack_start(GTK_BOX(info_box), codename_label, FALSE, FALSE, 0); /* build date label */ builddate_label = gtk_label_new(NULL); gtk_label_set_justify(GTK_LABEL(builddate_label), GTK_JUSTIFY_CENTER); gtk_label_set_selectable(GTK_LABEL(builddate_label), TRUE); gtk_label_set_use_markup(GTK_LABEL(builddate_label), TRUE); build_date = utils_parse_and_format_build_date(__DATE__); g_snprintf(buffer2, sizeof(buffer2), _("(built on or after %s)"), build_date); g_free(build_date); g_snprintf(buffer, sizeof(buffer), BUILDDATE, buffer2); gtk_label_set_markup(GTK_LABEL(builddate_label), buffer); gtk_misc_set_padding(GTK_MISC(builddate_label), 2, 2); gtk_widget_show(builddate_label); gtk_box_pack_start(GTK_BOX(info_box), builddate_label, FALSE, FALSE, 0); box = gtk_hbutton_box_new(); url_button = gtk_button_new(); gtk_button_set_relief(GTK_BUTTON(url_button), GTK_RELIEF_NONE); g_signal_connect(url_button, "clicked", G_CALLBACK(homepage_clicked), (gpointer)GEANY_HOMEPAGE); label = gtk_label_new(NULL); gtk_label_set_text(GTK_LABEL(label), GEANY_HOMEPAGE); gtk_widget_show(label); gtk_container_add(GTK_CONTAINER(url_button), label); gtk_widget_show(url_button); gtk_box_pack_start(GTK_BOX(box), url_button, FALSE, FALSE, 0); gtk_widget_show(box); gtk_box_pack_start(GTK_BOX(info_box), box, FALSE, FALSE, 10); /* copyright label */ cop_label = gtk_label_new(NULL); gtk_label_set_justify(GTK_LABEL(cop_label), GTK_JUSTIFY_CENTER); gtk_label_set_selectable(GTK_LABEL(cop_label), FALSE); gtk_label_set_use_markup(GTK_LABEL(cop_label), TRUE); gtk_label_set_markup(GTK_LABEL(cop_label), COPYRIGHT); gtk_misc_set_padding(GTK_MISC(cop_label), 2, 10); gtk_widget_show(cop_label); gtk_box_pack_start(GTK_BOX(info_box), cop_label, FALSE, FALSE, 0); /*gtk_container_add(GTK_CONTAINER(info_box), cop_label); */ label = gtk_label_new(_("Info")); gtk_widget_show(label); gtk_widget_show_all(info_box); gtk_notebook_append_page(GTK_NOTEBOOK(notebook), info_box, label); /* create "Credits" tab */ credits_scrollwin = gtk_scrolled_window_new(NULL, NULL); gtk_container_set_border_width(GTK_CONTAINER(credits_scrollwin), 6); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(credits_scrollwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); table = gtk_table_new(23 + translators_len + prev_translators_len, 3, FALSE); gtk_table_set_col_spacings(GTK_TABLE(table), 10); row = 0; g_snprintf(buffer, sizeof(buffer), "<span size=\"larger\" weight=\"bold\">%s</span>", _("Developers")); label = gtk_label_new(buffer); gtk_table_attach(GTK_TABLE(table), label, 0, 2, row, row + 1, GTK_FILL, 0, 0, 5); gtk_label_set_use_markup(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); row++; g_snprintf(buffer, sizeof(buffer), "Colomban Wendling - %s", _("maintainer")); ROW(buffer, row, 0, 0, 0, 1); row++; ROW("<[email protected]>", row, 0, 0, 0, 1); row++; ROW("", row, 0, 0, 0, 0); row++; g_snprintf(buffer, sizeof(buffer), "Nick Treleaven - %s", _("developer")); ROW(buffer, row, 0, 0, 0, 1); row++; ROW("<[email protected]>", row, 0, 0, 0, 1); row++; ROW("", row, 0, 0, 0, 0); row++; g_snprintf(buffer, sizeof(buffer), "Enrico Tröger - %s", _("developer")); ROW(buffer, row, 0, 0, 0, 1); row++; ROW("<[email protected]>", row, 0, 0, 0, 1); row++; ROW("", row, 0, 0, 0, 0); row++; g_snprintf(buffer, sizeof(buffer), "Matthew Brush - %s", _("developer")); ROW(buffer, row, 0, 0, 0, 1); row++; ROW("<[email protected]>", row, 0, 0, 0, 1); row++; ROW("", row, 0, 0, 0, 0); row++; g_snprintf(buffer, sizeof(buffer), "Frank Lanitz - %s", _("translation maintainer")); ROW(buffer, row, 0, 0, 0, 1); row++; ROW("<[email protected]>", row, 0, 0, 0, 1); row++; ROW("", row, 0, 0, 0, 0); row++; g_snprintf(buffer, sizeof(buffer), "<span size=\"larger\" weight=\"bold\">%s</span>", _("Translators")); label = gtk_label_new(buffer); gtk_table_attach(GTK_TABLE(table), label, 0, 2, row, row + 1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 5); gtk_label_set_use_markup(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); row++; for (i = 0; i < translators_len; i++) { ROW(translators[i][0], row, 0, 1, 4, 0); ROW(translators[i][1], row, 1, 0, 4, 0); row++; } ROW("", row, 0, 0, 0, 0); row++; g_snprintf(buffer, sizeof(buffer), "<span size=\"larger\" weight=\"bold\">%s</span>", _("Previous Translators")); label = gtk_label_new(buffer); gtk_table_attach(GTK_TABLE(table), label, 0, 2, row, row + 1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 5); gtk_label_set_use_markup(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); row++; for (i = 0; i < prev_translators_len; i++) { ROW(prev_translators[i][0], row, 0, 1, 4, 0); ROW(prev_translators[i][1], row, 1, 0, 4, 0); row++; } ROW("", row, 0, 0, 0, 0); row++; g_snprintf(buffer, sizeof(buffer), "<span size=\"larger\" weight=\"bold\">%s</span>", _("Contributors")); label = gtk_label_new(buffer); gtk_table_attach(GTK_TABLE(table), label, 0, 2, row, row + 1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 5); gtk_label_set_use_markup(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); row++; g_snprintf(buffer, sizeof(buffer), _("Some of the many contributors (for a more detailed list, see the file %s):"), #ifdef G_OS_WIN32 "Thanks.txt" #else "THANKS" #endif ); label = geany_wrap_label_new(buffer); gtk_table_attach(GTK_TABLE(table), label, 0, 2, row, row + 1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 5); gtk_label_set_use_markup(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); row++; label = geany_wrap_label_new(contributors); gtk_table_attach(GTK_TABLE(table), label, 0, 2, row, row + 1, (GtkAttachOptions) (GTK_FILL | GTK_EXPAND), (GtkAttachOptions) (0), 0, 5); gtk_label_set_use_markup(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); row++; gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(credits_scrollwin), table); gtk_viewport_set_shadow_type(GTK_VIEWPORT(gtk_widget_get_parent(table)), GTK_SHADOW_NONE); gtk_widget_show_all(table); label = gtk_label_new(_("Credits")); gtk_widget_show(label); gtk_notebook_append_page(GTK_NOTEBOOK(notebook), credits_scrollwin, label); /* create "License" tab */ license_scrollwin = gtk_scrolled_window_new(NULL, NULL); gtk_container_set_border_width(GTK_CONTAINER(license_scrollwin), 6); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(license_scrollwin), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(license_scrollwin), GTK_SHADOW_IN); license_textview = gtk_text_view_new(); gtk_text_view_set_left_margin(GTK_TEXT_VIEW(license_textview), 2); gtk_text_view_set_right_margin(GTK_TEXT_VIEW(license_textview), 2); gtk_text_view_set_editable(GTK_TEXT_VIEW(license_textview), FALSE); gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(license_textview), FALSE); gtk_widget_show(license_textview); gtk_container_add(GTK_CONTAINER(license_scrollwin), license_textview); label = gtk_label_new(_("License")); gtk_widget_show(label); g_snprintf(buffer, sizeof(buffer), "%s" G_DIR_SEPARATOR_S "GPL-2", app->datadir); g_file_get_contents(buffer, &license_text, NULL, NULL); if (license_text == NULL) { license_text = g_strdup( _("License text could not be found, please visit http://www.gnu.org/licenses/gpl-2.0.txt to view it online.")); } tb = gtk_text_view_get_buffer(GTK_TEXT_VIEW(license_textview)); gtk_text_buffer_set_text(tb, license_text, -1); g_free(license_text); gtk_notebook_append_page(GTK_NOTEBOOK(notebook), license_scrollwin, label); gtk_widget_show_all(dialog); return dialog; }
GtkWidget * font_color_prefs_show(void) { GtkWidget *main_vb, *main_grid, *label, *combo_box; GtkWidget *font_sample, *color_sample, *colorsel; static const gchar *mt[] = { "Marked packet foreground", /* MFG_IDX 0*/ "Marked packet background", /* MBG_IDX 1*/ "Ignored packet foreground", /* IFG_IDX 2*/ "Ignored packet background", /* IBG_IDX 3*/ "'Follow Stream' client foreground", /* CFG_IDX 4*/ "'Follow Stream' client background", /* CBG_IDX 5*/ "'Follow Stream' server foreground", /* SFG_IDX 6*/ "'Follow Stream' server background", /* SBG_IDX 7*/ "Valid filter text entry", /* FTV_IDX 8*/ "Invalid filter text entry", /* FTI_IDX 9*/ "Deprecated filter text entry" /* FTD_IDX 10*/ }; int mcount = sizeof(mt) / sizeof (gchar *); GtkTextBuffer *buf; GtkTextIter iter; GRand *rand_state = g_rand_new(); GString *preview_string = g_string_new(""); int i; #define GRID_FONT_ROW 0 #define GRID_COLOR_ROW 1 #define GRID_COLOR_SEL_ROW 3 /* The font hasn't been changed yet. */ font_changed = FALSE; color_t_to_gdkxxx(&tcolors[MFG_IDX], &prefs.gui_marked_fg); color_t_to_gdkxxx(&tcolors[MBG_IDX], &prefs.gui_marked_bg); color_t_to_gdkxxx(&tcolors[IFG_IDX], &prefs.gui_ignored_fg); color_t_to_gdkxxx(&tcolors[IBG_IDX], &prefs.gui_ignored_bg); color_t_to_gdkxxx(&tcolors[CFG_IDX], &prefs.st_client_fg); color_t_to_gdkxxx(&tcolors[CBG_IDX], &prefs.st_client_bg); color_t_to_gdkxxx(&tcolors[SFG_IDX], &prefs.st_server_fg); color_t_to_gdkxxx(&tcolors[SBG_IDX], &prefs.st_server_bg); color_t_to_gdkxxx(&tcolors[FTV_IDX], &prefs.gui_text_valid); color_t_to_gdkxxx(&tcolors[FTI_IDX], &prefs.gui_text_invalid); color_t_to_gdkxxx(&tcolors[FTD_IDX], &prefs.gui_text_deprecated); color_t_to_gdkxxx(&filter_text_fg, &filter_text_fg_color); #if ! GTK_CHECK_VERSION(3,4,0) for (i=0; i<MAX_IDX; i++) { tcolors_orig[i] = tcolors[i]; } #endif curcolor = &tcolors[CFG_IDX]; /* Enclosing containers for each row of widgets */ main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 5, FALSE); gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5); main_grid = ws_gtk_grid_new(); gtk_box_pack_start(GTK_BOX(main_vb), main_grid, FALSE, FALSE, 0); ws_gtk_grid_set_row_spacing(GTK_GRID(main_grid), 40); ws_gtk_grid_set_column_spacing(GTK_GRID(main_grid), 15); gtk_widget_show(main_grid); label = gtk_label_new("Main window font:"); gtk_misc_set_alignment(GTK_MISC(label), 1.0f, 0.5f); ws_gtk_grid_attach_extended(GTK_GRID(main_grid), label, 0, GRID_FONT_ROW, 1, 1, (GtkAttachOptions)(GTK_EXPAND|GTK_FILL), (GtkAttachOptions)0, 0, 0); gtk_widget_show(label); font_button = gtk_font_button_new_with_font(prefs.gui_gtk2_font_name); gtk_font_button_set_title(GTK_FONT_BUTTON(font_button), "Wireshark: Font"); ws_gtk_grid_attach(GTK_GRID(main_grid), font_button, 1, GRID_FONT_ROW, 1, 1); gtk_widget_show(font_button); g_string_printf(preview_string, " %s 0123456789", font_pangrams[g_rand_int_range(rand_state, 0, NUM_FONT_PANGRAMS)]); font_sample = gtk_text_view_new(); gtk_text_view_set_editable(GTK_TEXT_VIEW(font_sample), FALSE); buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(font_sample)); gtk_text_buffer_get_start_iter(buf, &iter); srand((unsigned int) time(NULL)); gtk_text_buffer_insert(buf, &iter, preview_string->str, -1); ws_gtk_grid_attach_extended(GTK_GRID(main_grid), font_sample, 2, GRID_FONT_ROW, 1, 1, (GtkAttachOptions)(GTK_EXPAND|GTK_FILL), (GtkAttachOptions)0, 0, 0); g_signal_connect(font_button, "font-set", G_CALLBACK(select_font), NULL); gtk_widget_show(font_sample); g_string_free(preview_string, TRUE); g_object_set_data(G_OBJECT(font_button), FONT_SAMPLE_KEY, font_sample); label = gtk_label_new("Colors:"); gtk_misc_set_alignment(GTK_MISC(label), 1.0f, 0.5f); ws_gtk_grid_attach_extended(GTK_GRID(main_grid), label, 0, GRID_COLOR_ROW, 1, 1, (GtkAttachOptions)(GTK_EXPAND|GTK_FILL), (GtkAttachOptions)0, 0,0); gtk_widget_show(label); /* We have to create this now, and configure it below. */ #if GTK_CHECK_VERSION(3,4,0) /* XXX: There appears to be a bug in the GTK3 GtkColorChooserWidget such that * when in the GtkColorChooserWidget "customize" mode (aka "color-edit" mode) * selecting a color doesn't trigger a "motify::rgba" callback. * The effect is that the sample text FG/BG colors don't update for the GTK3 * GtkColorChooserWidget in "custon color edit node"). * I expect use of the "customize mode" will be minimal and that the bug will * not be very noticeable. * (A GTK3 bug report has beem submitted. */ #endif colorsel = gtk_color_xxx_new(); combo_box = gtk_combo_box_text_new(); for (i = 0; i < mcount; i++){ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo_box), mt[i]); } gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box), CFG_IDX); g_signal_connect(combo_box, "changed", G_CALLBACK(update_current_color), colorsel); ws_gtk_grid_attach(GTK_GRID(main_grid), combo_box, 1, GRID_COLOR_ROW, 1, 1); gtk_widget_show(combo_box); color_sample = gtk_text_view_new(); update_font(user_font_get_regular(), font_sample, color_sample); gtk_text_view_set_editable(GTK_TEXT_VIEW(color_sample), FALSE); buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(color_sample)); gtk_text_buffer_get_start_iter(buf, &iter); gtk_text_buffer_create_tag(buf, "marked", TAG_PROP_FG_COLOR, &tcolors[MFG_IDX], TAG_PROP_BG_COLOR, &tcolors[MBG_IDX], NULL); gtk_text_buffer_create_tag(buf, "ignored", TAG_PROP_FG_COLOR, &tcolors[IFG_IDX], TAG_PROP_BG_COLOR, &tcolors[IBG_IDX], NULL); gtk_text_buffer_create_tag(buf, "client", TAG_PROP_FG_COLOR, &tcolors[CFG_IDX], TAG_PROP_BG_COLOR, &tcolors[CBG_IDX], NULL); gtk_text_buffer_create_tag(buf, "server", TAG_PROP_FG_COLOR, &tcolors[SFG_IDX], TAG_PROP_BG_COLOR, &tcolors[SBG_IDX], NULL); gtk_text_buffer_create_tag(buf, "text_valid", TAG_PROP_FG_COLOR, &filter_text_fg, TAG_PROP_BG_COLOR, &tcolors[FTV_IDX], NULL); gtk_text_buffer_create_tag(buf, "text_invalid", TAG_PROP_FG_COLOR, &filter_text_fg, TAG_PROP_BG_COLOR, &tcolors[FTI_IDX], NULL); gtk_text_buffer_create_tag(buf, "text_deprecated", TAG_PROP_FG_COLOR, &filter_text_fg, TAG_PROP_BG_COLOR, &tcolors[FTD_IDX], NULL); gtk_text_buffer_insert_with_tags_by_name(buf, &iter, SAMPLE_MARKED_TEXT, -1, "marked", NULL); gtk_text_buffer_insert_with_tags_by_name(buf, &iter, SAMPLE_IGNORED_TEXT, -1, "ignored", NULL); gtk_text_buffer_insert_with_tags_by_name(buf, &iter, SAMPLE_CLIENT_TEXT, -1, "client", NULL); gtk_text_buffer_insert_with_tags_by_name(buf, &iter, SAMPLE_SERVER_TEXT, -1, "server", NULL); gtk_text_buffer_insert_with_tags_by_name(buf, &iter, SAMPLE_TEXT_VALID_TEXT, -1, "text_valid", NULL); gtk_text_buffer_insert_with_tags_by_name(buf, &iter, SAMPLE_TEXT_INVALID_TEXT, -1, "text_invalid", NULL); gtk_text_buffer_insert_with_tags_by_name(buf, &iter, SAMPLE_TEXT_DEPRECATED_TEXT, -1, "text_deprecated", NULL); ws_gtk_grid_attach_extended(GTK_GRID(main_grid), color_sample, 2, GRID_COLOR_ROW, 1, 2, (GtkAttachOptions)(GTK_EXPAND|GTK_FILL), (GtkAttachOptions)0, 0, 0); gtk_widget_show(color_sample); gtk_color_xxx_set_yyy(GTK_COLOR_XXX(colorsel), curcolor); ws_gtk_grid_attach_extended(GTK_GRID(main_grid), colorsel, 1, GRID_COLOR_SEL_ROW, 2, 1, (GtkAttachOptions)(GTK_FILL|GTK_EXPAND), (GtkAttachOptions)0, 0, 0); g_object_set_data(G_OBJECT(combo_box), COLOR_SAMPLE_KEY, color_sample); g_object_set_data(G_OBJECT(colorsel), COLOR_SAMPLE_KEY, color_sample); g_signal_connect(colorsel, COLOR_CHANGED_SIGNAL, G_CALLBACK(update_text_color), NULL); gtk_widget_show(colorsel); g_rand_free(rand_state); gtk_widget_show(main_vb); return main_vb; }
/** * mdu_shell_raise_error: * @shell: An object implementing the #MduShell interface * @presentable: The #MduPresentable for which the error was raised or %NULL. * @error: The #GError obtained from the operation * @primary_markup_format: Format string for the primary markup text of the dialog * @...: Arguments for markup string * * Show the user (through a dialog or other means (e.g. cluebar)) that an error occured. **/ void mdu_shell_raise_error (MduShell *shell, MduPresentable *presentable, GError *error, const char *primary_markup_format, ...) { GtkWidget *dialog; char *error_text; char *window_title; GIcon *window_icon; va_list args; char *error_msg; GtkWidget *box, *hbox, *expander, *sw, *tv; GList *children; GtkTextBuffer *buffer; g_return_if_fail (shell != NULL); g_return_if_fail (error != NULL); window_icon = NULL; if (presentable != NULL) { window_title = mdu_presentable_get_name (presentable); window_icon = mdu_presentable_get_icon (presentable); } else { window_title = g_strdup (_("An error occured")); } va_start (args, primary_markup_format); error_text = g_strdup_vprintf (primary_markup_format, args); va_end (args); switch (error->code) { case MDU_ERROR_FAILED: error_msg = _("The operation failed."); break; case MDU_ERROR_BUSY: error_msg = _("The device is busy."); break; case MDU_ERROR_CANCELLED: error_msg = _("The operation was canceled."); break; case MDU_ERROR_INHIBITED: error_msg = _("The daemon is being inhibited."); break; case MDU_ERROR_INVALID_OPTION: error_msg = _("An invalid option was passed."); break; case MDU_ERROR_NOT_SUPPORTED: error_msg = _("The operation is not supported."); break; case MDU_ERROR_ATA_SMART_WOULD_WAKEUP: error_msg = _("Getting ATA SMART data would wake up the device."); break; case MDU_ERROR_PERMISSION_DENIED: error_msg = _("Permission denied."); break; default: error_msg = _("Unknown error"); break; } dialog = gtk_message_dialog_new_with_markup ( GTK_WINDOW (shell->priv->app_window), GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "<big><b>%s</b></big>", error_text); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error_msg); /* Here we cheat a little by poking in the messagedialog internals * to add the details expander to the inner vbox and arrange things * so that resizing the dialog works as expected. */ box = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); children = gtk_container_get_children (GTK_CONTAINER (box)); hbox = GTK_WIDGET (children->data); gtk_container_child_set (GTK_CONTAINER (box), hbox, "expand", TRUE, "fill", TRUE, NULL); g_list_free (children); children = gtk_container_get_children (GTK_CONTAINER (hbox)); box = GTK_WIDGET (children->next->data); g_list_free (children); children = gtk_container_get_children (GTK_CONTAINER (box)); gtk_container_child_set (GTK_CONTAINER (box), GTK_WIDGET (children->next->data), "expand", FALSE, "fill", FALSE, NULL); g_list_free (children); expander = g_object_new (GTK_TYPE_EXPANDER, "label", _("_Details:"), "use-underline", TRUE, "use-markup", TRUE, NULL); sw = g_object_new (GTK_TYPE_SCROLLED_WINDOW, "hscrollbar-policy", GTK_POLICY_AUTOMATIC, "vscrollbar-policy", GTK_POLICY_AUTOMATIC, "shadow-type", GTK_SHADOW_IN, NULL); buffer = gtk_text_buffer_new (NULL); gtk_text_buffer_set_text (buffer, error->message, -1); tv = gtk_text_view_new_with_buffer (buffer); gtk_text_view_set_editable (GTK_TEXT_VIEW (tv), FALSE); gtk_container_add (GTK_CONTAINER (sw), tv); gtk_container_add (GTK_CONTAINER (expander), sw); gtk_box_pack_end (GTK_BOX (box), expander, TRUE, TRUE, 0); gtk_widget_show_all (expander); /* Make the window resizable when the details are visible */ g_signal_connect (expander, "notify::expanded", G_CALLBACK (expander_cb), dialog); /* We don't want the initial focus to end up on the expander, * so grab it to the close button on map. */ gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE); g_signal_connect (dialog, "map", G_CALLBACK (fix_focus_cb), NULL); // TODO: no support for GIcon in GtkWindow //gtk_window_set_icon_name (GTK_WINDOW (dialog), window_icon_name); g_signal_connect_swapped (dialog, "response", G_CALLBACK (gtk_widget_destroy), dialog); gtk_window_present (GTK_WINDOW (dialog)); g_free (window_title); if (window_icon != NULL) g_object_unref (window_icon); g_free (error_text); }
int main(int argc, char* argv[]) { // VMime initialization vmime::platform::setHandler<vmime::platforms::posix::posixHandler>(); // GTK+ initialization gtk_init(&argc, &argv); // Create a new window window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size(GTK_WINDOW(window), 800, 550); gtk_window_set_title(GTK_WINDOW(window), "VMime Viewer Example"); g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(destroy), NULL); GtkWidget* vbox = gtk_vbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(window), vbox); // Menubar GtkActionGroup* actionGroup = gtk_action_group_new ("Actions"); gtk_action_group_add_actions(actionGroup, uiActions, G_N_ELEMENTS(uiActions), NULL); GtkUIManager* uiManager = gtk_ui_manager_new(); gtk_ui_manager_insert_action_group(uiManager, actionGroup, 1); gtk_ui_manager_add_ui_from_string(uiManager, uiDefinition, -1, NULL); GtkWidget* menuBar = gtk_ui_manager_get_widget(uiManager, "/MainMenuBar"); gtk_box_pack_start(GTK_BOX(vbox), menuBar, FALSE, FALSE, 0); // Horizontal Pane GtkWidget* hpane = gtk_hpaned_new(); gtk_box_pack_start(GTK_BOX(vbox), hpane, TRUE, TRUE, 0); // Tree View treeModel = gtk_tree_store_new(2, G_TYPE_STRING, G_TYPE_POINTER); treeView = gtk_tree_view_new(); g_signal_connect(G_OBJECT(treeView), "cursor-changed", G_CALLBACK(treeViewSelChanged), NULL); GtkWidget* scroll = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll), GTK_SHADOW_IN); gtk_container_add(GTK_CONTAINER(scroll), treeView); gtk_paned_add1(GTK_PANED(hpane), scroll); GtkTreeViewColumn* col = gtk_tree_view_column_new(); gtk_tree_view_column_set_title(col, "Component Name"); gtk_tree_view_append_column(GTK_TREE_VIEW(treeView), col); GtkCellRenderer* renderer = gtk_cell_renderer_text_new(); gtk_tree_view_column_pack_start(col, renderer, TRUE); gtk_tree_view_column_add_attribute(col, renderer, "text", 0); gtk_tree_view_set_model(GTK_TREE_VIEW(treeView), GTK_TREE_MODEL(treeModel)); g_object_unref(treeModel); gtk_widget_set_size_request(treeView, 200, 100); // Text Area textArea = gtk_text_view_new(); gtk_text_view_set_editable(GTK_TEXT_VIEW(textArea), FALSE); scroll = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll), GTK_SHADOW_IN); gtk_container_add(GTK_CONTAINER(scroll), textArea); gtk_paned_add2(GTK_PANED(hpane), scroll); // Show main window gtk_widget_show_all(window); // GTK main loop gtk_main(); return 0; }
/** * Statistic Viewer's constructor * * This constructor is used to create StatisticViewerData data structure. * @return The Statistic viewer data created. */ StatisticViewerData * gui_statistic(LttvPluginTab *ptab) { GtkCellRenderer *renderer; GtkTreeViewColumn *column; StatisticViewerData* statistic_viewer_data = g_new(StatisticViewerData,1); statistic_viewer_data->live_trace_count = 0; Tab *tab = ptab->tab; statistic_viewer_data->tab = tab; statistic_viewer_data->ptab = ptab; // statistic_viewer_data->stats = // lttvwindow_get_traceset_stats(statistic_viewer_data->tab); // statistic_viewer_data->calculate_stats = // statistic_insert_traceset_stats((void *)statistic_viewer_data->stats); lttvwindow_register_traceset_notify(statistic_viewer_data->tab, statistic_traceset_changed, statistic_viewer_data); statistic_viewer_data->statistic_hash = g_hash_table_new_full(g_str_hash, g_str_equal, statistic_destroy_hash_key, NULL); statistic_viewer_data->hpaned_v = gtk_hpaned_new(); statistic_viewer_data->store_m = gtk_tree_store_new (N_COLUMNS, G_TYPE_STRING); statistic_viewer_data->tree_v = gtk_tree_view_new_with_model ( GTK_TREE_MODEL (statistic_viewer_data->store_m)); g_object_unref (G_OBJECT (statistic_viewer_data->store_m)); // Setup the selection handler statistic_viewer_data->select_c = gtk_tree_view_get_selection (GTK_TREE_VIEW (statistic_viewer_data->tree_v)); gtk_tree_selection_set_mode (statistic_viewer_data->select_c, GTK_SELECTION_SINGLE); g_signal_connect (G_OBJECT (statistic_viewer_data->select_c), "changed", G_CALLBACK (tree_selection_changed_cb), statistic_viewer_data); renderer = gtk_cell_renderer_text_new (); column = gtk_tree_view_column_new_with_attributes ("Statistic Name", renderer, "text", NAME_COLUMN, NULL); gtk_tree_view_column_set_alignment (column, 0.0); // gtk_tree_view_column_set_fixed_width (column, 45); gtk_tree_view_append_column (GTK_TREE_VIEW (statistic_viewer_data->tree_v), column); gtk_tree_view_set_headers_visible(GTK_TREE_VIEW (statistic_viewer_data->tree_v), FALSE); statistic_viewer_data->scroll_win_tree = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(statistic_viewer_data->scroll_win_tree), GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC); gtk_container_add (GTK_CONTAINER (statistic_viewer_data->scroll_win_tree), statistic_viewer_data->tree_v); gtk_paned_pack1(GTK_PANED(statistic_viewer_data->hpaned_v),statistic_viewer_data->scroll_win_tree, TRUE, FALSE); gtk_paned_set_position(GTK_PANED(statistic_viewer_data->hpaned_v), 160); statistic_viewer_data->scroll_win_text = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(statistic_viewer_data->scroll_win_text), GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC); statistic_viewer_data->text_v = gtk_text_view_new (); gtk_text_view_set_editable(GTK_TEXT_VIEW(statistic_viewer_data->text_v),FALSE); gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(statistic_viewer_data->text_v),FALSE); gtk_container_add (GTK_CONTAINER (statistic_viewer_data->scroll_win_text), statistic_viewer_data->text_v); gtk_paned_pack2(GTK_PANED(statistic_viewer_data->hpaned_v), statistic_viewer_data->scroll_win_text, TRUE, FALSE); gtk_container_set_border_width( GTK_CONTAINER(statistic_viewer_data->hpaned_v), 1); gtk_widget_show(statistic_viewer_data->scroll_win_tree); gtk_widget_show(statistic_viewer_data->scroll_win_text); gtk_widget_show(statistic_viewer_data->tree_v); gtk_widget_show(statistic_viewer_data->text_v); gtk_widget_show(statistic_viewer_data->hpaned_v); g_object_set_data_full( G_OBJECT(guistatistic_get_widget(statistic_viewer_data)), "statistic_viewer_data", statistic_viewer_data, (GDestroyNotify)gui_statistic_destructor); /* Add the object's information to the module's array */ g_statistic_viewer_data_list = g_slist_append( g_statistic_viewer_data_list, statistic_viewer_data); request_background_data(statistic_viewer_data); return statistic_viewer_data; }
/** * entry_properties_new: * * Returns: a new #GtkWidget */ GtkWidget * entry_properties_new (TConnection *tcnc) { EntryProperties *eprop; g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL); eprop = ENTRY_PROPERTIES (g_object_new (ENTRY_PROPERTIES_TYPE, NULL)); eprop->priv->tcnc = g_object_ref (tcnc); GtkWidget *sw; sw = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_NONE); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_box_pack_start (GTK_BOX (eprop), sw, TRUE, TRUE, 0); GtkWidget *textview; textview = gtk_text_view_new (); gtk_container_add (GTK_CONTAINER (sw), textview); gtk_text_view_set_left_margin (GTK_TEXT_VIEW (textview), 5); gtk_text_view_set_right_margin (GTK_TEXT_VIEW (textview), 5); gtk_text_view_set_editable (GTK_TEXT_VIEW (textview), FALSE); gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (textview), FALSE); eprop->priv->text = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview)); eprop->priv->view = GTK_TEXT_VIEW (textview); gtk_widget_show_all (sw); gtk_text_buffer_create_tag (eprop->priv->text, "section", "weight", PANGO_WEIGHT_BOLD, "foreground", "blue", NULL); gtk_text_buffer_create_tag (eprop->priv->text, "error", "foreground", "red", NULL); gtk_text_buffer_create_tag (eprop->priv->text, "data", "left-margin", 20, NULL); gtk_text_buffer_create_tag (eprop->priv->text, "convdata", "style", PANGO_STYLE_ITALIC, "background", "lightgray", "left-margin", 20, NULL); gtk_text_buffer_create_tag (eprop->priv->text, "starter", "indent", -10, "left-margin", 20, NULL); g_signal_connect (textview, "key-press-event", G_CALLBACK (key_press_event), eprop); g_signal_connect (textview, "event-after", G_CALLBACK (event_after), eprop); g_signal_connect (textview, "motion-notify-event", G_CALLBACK (motion_notify_event), eprop); g_signal_connect (textview, "visibility-notify-event", G_CALLBACK (visibility_notify_event), eprop); g_signal_connect (textview, "populate-popup", G_CALLBACK (populate_popup_cb), eprop); entry_properties_set_dn (eprop, NULL); return (GtkWidget*) eprop; }
/*主界面进入点*/ int main(int argc,char **argv) { GtkWidget *win; GtkWidget *menu; GtkWidget *menu_bar; GtkWidget *vbox; GtkWidget *hbox; GtkWidget *text; GtkWidget *scrolled; GtkWidget *open; GtkWidget *close; GtkWidget *clean; GtkTextBuffer *buffer; GtkAccelGroup *accel_group; PangoFontDescription *font_name; DATA data; CONFDATA conf; ABOUT about_data; //HELP help_data; struct sigaction act,old; setpgrp(); init_with_conf(&conf); init_about_data(&about_data); //init_help_data(&help_data); data.buf=g_string_new(NULL); data.python_path=conf.python_path; data.proxy_py_path=conf.proxy_py_path; setlocale(LC_ALL,""); /*设置语言环境*/ if(conf.language_env == NULL) { setlocale(LC_CTYPE,"zh_CN.UTF-8"); setenv("LANG","zh_CN.UTF-8",1); } else { setlocale(LC_CTYPE,conf.language_env); setenv("LANG",conf.language_env,1); } if(conf.gtk_goagent_path!=NULL) chdir(conf.gtk_goagent_path); /*是否自动更新 * 如果是则在后台运行版更新进程 */ if(strcmp(conf.goagent_auto_upgrade,"true")==0) auto_upgrade_goagent(GOAGENT_URL,&conf); /*国际化*/ bindtextdomain("gtk_goagent","./locale/"); textdomain("gtk_goagent"); act.sa_flags=0; act.sa_handler=clean_data; /*设置自定义信号处理 * 用于在启动GoAgent失败时清理数据 */ sigaction(SIGUSR1,&act,&old); gtk_init(&argc,&argv); win=gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_position(GTK_WINDOW(win),GTK_WIN_POS_CENTER); gtk_window_set_title(GTK_WINDOW(win),"Gtk GoAgent"); gtk_window_set_icon_from_file(GTK_WINDOW(win),"img/64x64/gtk_goagent.png",NULL); create_tray(win); //create_pre_ui(&pre,&conf); vbox=gtk_vbox_new(FALSE,0); accel_group=gtk_accel_group_new(); gtk_window_add_accel_group(GTK_WINDOW(win),accel_group); gtk_container_add(GTK_CONTAINER(win),vbox); text=gtk_text_view_new(); /*设置日志显示框字体*/ if(conf.font!=NULL) { font_name=pango_font_description_from_string(conf.font); gtk_widget_modify_font(text,font_name); } buffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(text)); /*创建红色黑色和黄色标记 * 正常日志黑色输出 * 绿色用于警告 * 红色用于错误 * 黄色用于调试 */ gtk_text_buffer_create_tag(buffer,"green_fg", "foreground","green",NULL); gtk_text_buffer_create_tag(buffer,"red_fg","foreground", "red",NULL); gtk_text_buffer_create_tag(buffer,"black_fg","foreground", "black",NULL); gtk_text_buffer_create_tag(buffer,"yellow_fg", "foreground","yellow",NULL); data.text=text; data.off=0; menu_bar=gtk_menu_bar_new(); gtk_box_pack_start(GTK_BOX(vbox),menu_bar,FALSE,FALSE,0); /*创建菜单*/ menu=create_menu(menu_bar,_("_File")); create_menu_with_image(menu,GTK_STOCK_OPEN,accel_group,connect_goagent,&data); create_menu_with_image(menu,GTK_STOCK_CLOSE,accel_group,disconnect_goagent,&data); gtk_menu_shell_append(GTK_MENU_SHELL(menu),gtk_separator_menu_item_new()); create_menu_with_image(menu,GTK_STOCK_QUIT,accel_group,really_quit,&data); menu=create_menu(menu_bar,_("_Edit")); create_menu_with_image(menu,GTK_STOCK_PREFERENCES,accel_group,preferences,NULL); create_menu_with_image(menu,_("Up_load"),accel_group,upload,&conf); menu=create_menu(menu_bar,_("_Help")); create_menu_with_image(menu,GTK_STOCK_HELP,accel_group,help,NULL); create_menu_with_image(menu,GTK_STOCK_ABOUT,accel_group,about,&about_data); gtk_menu_shell_append(GTK_MENU_SHELL(menu),gtk_separator_menu_item_new()); create_menu_with_image(menu,_("Upgrade GoAg_ent"),accel_group,upgrade_goagent,conf.proxy_py_path); //create_menu_with_image(menu,_("Upgrade _Gtk GoAGent"),accel_group,upgrade_gtk_goagent,NULL); gtk_widget_set_size_request(text,0x300,0x180); /*设置显示构件不可编辑和自动换行*/ gtk_text_view_set_editable(GTK_TEXT_VIEW(text),FALSE); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text),GTK_WRAP_CHAR); /*创建滚动条并设置自动更新*/ scrolled=gtk_scrolled_window_new(NULL,NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC); gtk_container_add(GTK_CONTAINER(scrolled),text); gtk_box_pack_start(GTK_BOX(vbox),scrolled,FALSE,FALSE,0); gtk_box_pack_start(GTK_BOX(vbox),gtk_separator_menu_item_new(),FALSE,FALSE,5); show_time(vbox); gtk_box_pack_start(GTK_BOX(vbox),gtk_separator_menu_item_new(),FALSE,FALSE,5); hbox=gtk_hbox_new(FALSE,0); gtk_box_pack_start(GTK_BOX(vbox),hbox,FALSE,FALSE,5); open=gtk_button_new_with_label(_("Connect")); gtk_box_pack_start(GTK_BOX(hbox),open,FALSE,FALSE,30); g_signal_connect(G_OBJECT(open),"clicked",G_CALLBACK(connect_goagent),&data); clean=gtk_button_new_with_label(_("Clean")); gtk_box_pack_start(GTK_BOX(hbox),clean,TRUE,TRUE,100); g_signal_connect(G_OBJECT(clean),"clicked",G_CALLBACK(clean_buffer),&data); close=gtk_button_new_with_label(_("Disconnect")); gtk_box_pack_end(GTK_BOX(hbox),close,FALSE,FALSE,30); g_signal_connect(G_OBJECT(close),"clicked",G_CALLBACK(disconnect_goagent),&data); g_signal_connect(G_OBJECT(win),"delete_event",G_CALLBACK(really_quit),NULL); gtk_widget_show_all(win); gtk_main(); //setpgrp(); g_idle_remove_by_data(&data); g_string_free(data.buf,TRUE); kill(0,SIGKILL); //killpg(getpgrp(),SIGKILL); while(waitpid(-1,NULL,WNOHANG)!=-1); //g_idle_remove_by_data(&data); return 0; }
void gui_create_tasks(GUI *appGUI) { GtkWidget *vbox1; GtkWidget *vbox2; GtkWidget *table; GtkWidget *label; GtkWidget *top_scrolledwindow; GtkWidget *hseparator; GtkWidget *close_button; GtkCellRenderer *renderer; GtkWidget *top_viewport; GtkWidget *bottom_viewport; GtkTextBuffer *text_buffer; GError *error = NULL; GtkActionGroup *action_group = NULL; gchar tmpbuf[BUFFER_SIZE]; const gchar *ui_info = " <toolbar name=\"toolbar\">\n" " <toolitem name=\"add\" action=\"add\" />\n" " <toolitem name=\"delete\" action=\"delete\" />\n" " <separator name=\"sep1\" />\n" " <toolitem name=\"edit\" action=\"edit\" />\n" " </toolbar>\n"; GtkActionEntry entries[] = { { "add", OSMO_STOCK_TASKS_ADD, _("New task"), NULL, _("New task"), NULL }, { "edit", OSMO_STOCK_TASKS_EDIT, _("Edit task"), NULL, _("Edit task"), NULL }, { "delete", OSMO_STOCK_TASKS_REMOVE, _("Remove task"), NULL, _("Remove task"), NULL }, }; guint n_entries = G_N_ELEMENTS (entries); appGUI->tsk->filter_index = 0; vbox1 = gtk_vbox_new (FALSE, 1); gtk_widget_show (vbox1); gtk_container_set_border_width (GTK_CONTAINER (vbox1), 8); sprintf(tmpbuf, "<b>%s</b>", _("Tasks")); gui_add_to_notebook (vbox1, tmpbuf, appGUI); appGUI->tsk->vbox = GTK_BOX(vbox1); /*-------------------------------------------------------------------------------------*/ action_group = gtk_action_group_new ("_actions"); gtk_action_group_add_actions (action_group, entries, n_entries, NULL); gtk_action_group_set_sensitive(action_group, TRUE); appGUI->tsk->tasks_uim_widget = gtk_ui_manager_new (); gtk_ui_manager_insert_action_group (appGUI->tsk->tasks_uim_widget, action_group, 0); g_signal_connect (appGUI->tsk->tasks_uim_widget, "add_widget", G_CALLBACK (add_tasks_toolbar_widget), appGUI); if (!gtk_ui_manager_add_ui_from_string (appGUI->tsk->tasks_uim_widget, ui_info, -1, &error)) { g_message ("building toolbar failed: %s", error->message); g_error_free (error); } gtk_ui_manager_ensure_update (appGUI->tsk->tasks_uim_widget); gtk_toolbar_set_style (appGUI->tsk->tasks_toolbar, GTK_TOOLBAR_ICONS); gtk_toolbar_set_tooltips (appGUI->tsk->tasks_toolbar, config.enable_tooltips); /*-------------------------------------------------------------------------------------*/ /* assign callbacks */ g_signal_connect (G_OBJECT(gtk_ui_manager_get_widget (appGUI->tsk->tasks_uim_widget, "/toolbar/add")), "clicked", G_CALLBACK(tasks_add_item_cb), appGUI); g_signal_connect (G_OBJECT(gtk_ui_manager_get_widget (appGUI->tsk->tasks_uim_widget, "/toolbar/edit")), "clicked", G_CALLBACK(tasks_edit_item_cb), appGUI); g_signal_connect (G_OBJECT(gtk_ui_manager_get_widget (appGUI->tsk->tasks_uim_widget, "/toolbar/delete")), "clicked", G_CALLBACK(tasks_remove_item_cb), appGUI); /*-------------------------------------------------------------------------------------*/ gtk_widget_set_sensitive(gtk_ui_manager_get_widget (appGUI->tsk->tasks_uim_widget, "/toolbar/edit"), FALSE); gtk_widget_set_sensitive(gtk_ui_manager_get_widget (appGUI->tsk->tasks_uim_widget, "/toolbar/delete"), FALSE); hseparator = gtk_hseparator_new (); gtk_widget_show (hseparator); gtk_box_pack_start (GTK_BOX (vbox1), hseparator, FALSE, TRUE, 6); table = gtk_table_new (1, 4, FALSE); gtk_widget_show (table); gtk_box_pack_start (GTK_BOX (vbox1), table, FALSE, TRUE, 0); gtk_table_set_col_spacings (GTK_TABLE (table), 8); sprintf(tmpbuf, "<b>%s:</b>", _("Category filter")); label = gtk_label_new (tmpbuf); gtk_widget_show (label); gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); gtk_label_set_use_markup (GTK_LABEL (label), TRUE); appGUI->tsk->cf_combobox = gtk_combo_box_new_text (); gtk_widget_show (appGUI->tsk->cf_combobox); gtk_combo_box_set_focus_on_click (GTK_COMBO_BOX (appGUI->tsk->cf_combobox), FALSE); GTK_WIDGET_UNSET_FLAGS(appGUI->tsk->cf_combobox, GTK_CAN_FOCUS); gtk_table_attach (GTK_TABLE (table), appGUI->tsk->cf_combobox, 1, 2, 0, 1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (GTK_FILL), 0, 0); g_signal_connect(appGUI->tsk->cf_combobox, "changed", G_CALLBACK(category_filter_cb), appGUI); g_signal_connect(G_OBJECT(appGUI->tsk->cf_combobox), "focus", G_CALLBACK(category_combo_box_focus_cb), NULL); appGUI->tsk->n_items_label = gtk_label_new (""); gtk_widget_show (appGUI->tsk->n_items_label); gtk_widget_set_size_request (appGUI->tsk->n_items_label, 100, -1); gtk_table_attach (GTK_TABLE (table), appGUI->tsk->n_items_label, 3, 4, 0, 1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); gtk_label_set_use_markup (GTK_LABEL (appGUI->tsk->n_items_label), TRUE); hseparator = gtk_hseparator_new (); gtk_widget_show (hseparator); gtk_box_pack_start (GTK_BOX (vbox1), hseparator, FALSE, TRUE, 6); /*-------------------------------------------------------------------------------------*/ appGUI->tsk->tasks_paned = gtk_vpaned_new(); gtk_widget_show (appGUI->tsk->tasks_paned); gtk_paned_set_position(GTK_PANED(appGUI->tsk->tasks_paned), 99999); gtk_box_pack_start(GTK_BOX(vbox1), appGUI->tsk->tasks_paned, TRUE, TRUE, 0); top_viewport = gtk_viewport_new (NULL, NULL); gtk_widget_show (top_viewport); gtk_viewport_set_shadow_type (GTK_VIEWPORT (top_viewport), GTK_SHADOW_NONE); gtk_paned_pack1 (GTK_PANED (appGUI->tsk->tasks_paned), top_viewport, FALSE, TRUE); top_scrolledwindow = gtk_scrolled_window_new (NULL, NULL); gtk_widget_show (top_scrolledwindow); gtk_container_add (GTK_CONTAINER (top_viewport), top_scrolledwindow); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (top_scrolledwindow), GTK_SHADOW_IN); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (top_scrolledwindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); appGUI->tsk->tasks_list_store = gtk_list_store_new(TASKS_NUM_COLUMNS, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); appGUI->tsk->tasks_filter = gtk_tree_model_filter_new(GTK_TREE_MODEL(appGUI->tsk->tasks_list_store), NULL); gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER(appGUI->tsk->tasks_filter), (GtkTreeModelFilterVisibleFunc)tasks_list_filter_cb, appGUI, NULL); appGUI->tsk->tasks_sort = gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(appGUI->tsk->tasks_filter)); appGUI->tsk->tasks_list = gtk_tree_view_new_with_model(GTK_TREE_MODEL(appGUI->tsk->tasks_sort)); gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(appGUI->tsk->tasks_list), config.tasks_rules_hint); gtk_widget_show (appGUI->tsk->tasks_list); GTK_WIDGET_SET_FLAGS (appGUI->tsk->tasks_list, GTK_CAN_DEFAULT); gtk_widget_modify_fg(GTK_WIDGET(appGUI->tsk->tasks_list), GTK_STATE_SELECTED, (& GTK_WIDGET(appGUI->tsk->tasks_list)->style->base[GTK_STATE_SELECTED])); gtk_widget_modify_fg(GTK_WIDGET(appGUI->tsk->tasks_list), GTK_STATE_NORMAL, (& GTK_WIDGET(appGUI->tsk->tasks_list)->style->bg[GTK_STATE_NORMAL])); g_signal_connect(G_OBJECT(appGUI->tsk->tasks_list), "button_press_event", G_CALLBACK(list_dbclick_cb), appGUI); appGUI->tsk->tasks_list_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (appGUI->tsk->tasks_list)); g_signal_connect(G_OBJECT(appGUI->tsk->tasks_list_selection), "changed", G_CALLBACK(tasks_item_selected), appGUI); /* create columns */ renderer = gtk_cell_renderer_toggle_new(); appGUI->tsk->tasks_columns[COLUMN_DONE] = gtk_tree_view_column_new_with_attributes (_("Done"), renderer, "active", COLUMN_DONE, NULL); gtk_tree_view_append_column (GTK_TREE_VIEW(appGUI->tsk->tasks_list), appGUI->tsk->tasks_columns[COLUMN_DONE]); g_signal_connect (renderer, "toggled", G_CALLBACK (done_toggled), appGUI); renderer = gtk_cell_renderer_text_new(); appGUI->tsk->tasks_columns[COLUMN_DUE_DATE] = gtk_tree_view_column_new_with_attributes(_("Due date"), renderer, "text", COLUMN_DUE_DATE, "strikethrough", COLUMN_DONE, "foreground", COLUMN_COLOR, NULL); gtk_tree_view_column_set_visible (appGUI->tsk->tasks_columns[COLUMN_DUE_DATE], config.visible_due_date_column); gtk_tree_view_append_column(GTK_TREE_VIEW(appGUI->tsk->tasks_list), appGUI->tsk->tasks_columns[COLUMN_DUE_DATE]); renderer = gtk_cell_renderer_text_new(); appGUI->tsk->tasks_columns[COLUMN_DUE_DATE_JULIAN] = gtk_tree_view_column_new_with_attributes(NULL, renderer, "text", COLUMN_DUE_DATE_JULIAN, "strikethrough", COLUMN_DONE, "foreground", COLUMN_COLOR, NULL); gtk_tree_view_column_set_visible (appGUI->tsk->tasks_columns[COLUMN_DUE_DATE_JULIAN], FALSE); gtk_tree_view_append_column(GTK_TREE_VIEW(appGUI->tsk->tasks_list), appGUI->tsk->tasks_columns[COLUMN_DUE_DATE_JULIAN]); renderer = gtk_cell_renderer_text_new(); appGUI->tsk->tasks_columns[COLUMN_START_DATE_JULIAN] = gtk_tree_view_column_new_with_attributes(NULL, renderer, "text", COLUMN_START_DATE_JULIAN, "strikethrough", COLUMN_DONE, "foreground", COLUMN_COLOR, NULL); gtk_tree_view_column_set_visible (appGUI->tsk->tasks_columns[COLUMN_START_DATE_JULIAN], FALSE); gtk_tree_view_append_column(GTK_TREE_VIEW(appGUI->tsk->tasks_list), appGUI->tsk->tasks_columns[COLUMN_START_DATE_JULIAN]); renderer = gtk_cell_renderer_text_new(); appGUI->tsk->tasks_columns[COLUMN_PRIORITY] = gtk_tree_view_column_new_with_attributes(_("Priority"), renderer, "text", COLUMN_PRIORITY, "strikethrough", COLUMN_DONE, "foreground", COLUMN_COLOR, NULL); gtk_tree_view_column_set_visible (appGUI->tsk->tasks_columns[COLUMN_PRIORITY], config.visible_priority_column); gtk_tree_view_append_column(GTK_TREE_VIEW(appGUI->tsk->tasks_list), appGUI->tsk->tasks_columns[COLUMN_PRIORITY]); renderer = gtk_cell_renderer_text_new(); appGUI->tsk->tasks_columns[COLUMN_CATEGORY] = gtk_tree_view_column_new_with_attributes(_("Category"), renderer, "text", COLUMN_CATEGORY, "strikethrough", COLUMN_DONE, "foreground", COLUMN_COLOR, NULL); gtk_tree_view_column_set_visible (appGUI->tsk->tasks_columns[COLUMN_CATEGORY], config.visible_category_column); gtk_tree_view_append_column(GTK_TREE_VIEW(appGUI->tsk->tasks_list), appGUI->tsk->tasks_columns[COLUMN_CATEGORY]); renderer = gtk_cell_renderer_text_new(); g_object_set(G_OBJECT(renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL); gtk_cell_renderer_set_fixed_size(renderer, 0, -1); appGUI->tsk->tasks_columns[COLUMN_SUMMARY] = gtk_tree_view_column_new_with_attributes(_("Summary"), renderer, "text", COLUMN_SUMMARY, "strikethrough", COLUMN_DONE, "foreground", COLUMN_COLOR, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(appGUI->tsk->tasks_list), appGUI->tsk->tasks_columns[COLUMN_SUMMARY]); renderer = gtk_cell_renderer_text_new(); appGUI->tsk->tasks_columns[COLUMN_DESCRIPTION] = gtk_tree_view_column_new_with_attributes(_("Description"), renderer, "text", COLUMN_DESCRIPTION, NULL); gtk_tree_view_column_set_visible (appGUI->tsk->tasks_columns[COLUMN_DESCRIPTION], FALSE); gtk_tree_view_append_column(GTK_TREE_VIEW(appGUI->tsk->tasks_list), appGUI->tsk->tasks_columns[COLUMN_DESCRIPTION]); renderer = gtk_cell_renderer_text_new(); appGUI->tsk->tasks_columns[COLUMN_COLOR] = gtk_tree_view_column_new_with_attributes(NULL, renderer, "text", COLUMN_COLOR, NULL); gtk_tree_view_column_set_visible (appGUI->tsk->tasks_columns[COLUMN_COLOR], FALSE); gtk_tree_view_append_column(GTK_TREE_VIEW(appGUI->tsk->tasks_list), appGUI->tsk->tasks_columns[COLUMN_COLOR]); /* configure list options */ gtk_container_add (GTK_CONTAINER (top_scrolledwindow), appGUI->tsk->tasks_list); gtk_tree_view_set_enable_search (GTK_TREE_VIEW(appGUI->tsk->tasks_list), FALSE); /* configure sorting */ gtk_tree_sortable_set_sort_func((GtkTreeSortable *)appGUI->tsk->tasks_sort, 0, (GtkTreeIterCompareFunc)custom_tasks_sort_function, NULL, NULL); gtk_tree_sortable_set_sort_column_id((GtkTreeSortable *)appGUI->tsk->tasks_sort, COLUMN_DUE_DATE, config.tasks_sorting_order); gtk_tree_sortable_set_sort_column_id((GtkTreeSortable *)appGUI->tsk->tasks_sort, COLUMN_PRIORITY, config.tasks_sorting_order); gtk_tree_sortable_set_sort_column_id((GtkTreeSortable *)appGUI->tsk->tasks_sort, COLUMN_DONE, config.tasks_sorting_order); /*----------------------------------------------------------------------------*/ bottom_viewport = gtk_viewport_new (NULL, NULL); gtk_widget_show (bottom_viewport); gtk_viewport_set_shadow_type (GTK_VIEWPORT (bottom_viewport), GTK_SHADOW_NONE); gtk_paned_pack2 (GTK_PANED (appGUI->tsk->tasks_paned), bottom_viewport, TRUE, TRUE); vbox2 = gtk_vbox_new (FALSE, 0); gtk_widget_show (vbox2); gtk_container_set_border_width (GTK_CONTAINER (vbox2), 0); gtk_container_add (GTK_CONTAINER (bottom_viewport), vbox2); appGUI->tsk->panel_hbox = gtk_hbox_new (FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox2), appGUI->tsk->panel_hbox, FALSE, FALSE, 0); gtk_widget_show(appGUI->tsk->panel_hbox); sprintf(tmpbuf, "%s:", _("Task details")); label = gtk_label_new (tmpbuf); gtk_widget_show (label); gtk_box_pack_start (GTK_BOX (appGUI->tsk->panel_hbox), label, FALSE, FALSE, 0); if (config.default_stock_icons) { close_button = gui_stock_button(GTK_STOCK_CLOSE, FALSE); } else { close_button = gui_stock_button(OSMO_STOCK_BUTTON_CLOSE, FALSE); } GTK_WIDGET_UNSET_FLAGS(close_button, GTK_CAN_FOCUS); gtk_button_set_relief (GTK_BUTTON(close_button), GTK_RELIEF_NONE); gtk_tooltips_set_tip (appGUI->osmo_tooltips, close_button, _("Close description panel"), NULL); gtk_box_pack_end (GTK_BOX (appGUI->tsk->panel_hbox), close_button, FALSE, FALSE, 0); g_signal_connect (G_OBJECT (close_button), "clicked", G_CALLBACK (panel_close_desc_cb), appGUI); appGUI->tsk->panel_scrolledwindow = gtk_scrolled_window_new (NULL, NULL); gtk_widget_show (appGUI->tsk->panel_scrolledwindow); gtk_box_pack_start (GTK_BOX (vbox2), appGUI->tsk->panel_scrolledwindow, TRUE, TRUE, 0); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (appGUI->tsk->panel_scrolledwindow), GTK_SHADOW_IN); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (appGUI->tsk->panel_scrolledwindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); appGUI->tsk->tasks_desc_textview = gtk_text_view_new (); gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (appGUI->tsk->tasks_desc_textview), GTK_WRAP_WORD); gtk_text_view_set_pixels_above_lines(GTK_TEXT_VIEW(appGUI->tsk->tasks_desc_textview), 4); gtk_text_view_set_left_margin(GTK_TEXT_VIEW(appGUI->tsk->tasks_desc_textview), 4); gtk_text_view_set_right_margin(GTK_TEXT_VIEW(appGUI->tsk->tasks_desc_textview), 4); gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(appGUI->tsk->tasks_desc_textview), FALSE); gtk_text_view_set_editable(GTK_TEXT_VIEW(appGUI->tsk->tasks_desc_textview), FALSE); gtk_widget_show (appGUI->tsk->tasks_desc_textview); gtk_container_add (GTK_CONTAINER (appGUI->tsk->panel_scrolledwindow), appGUI->tsk->tasks_desc_textview); text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(appGUI->tsk->tasks_desc_textview)); gtk_text_buffer_create_tag (text_buffer, "italic", "style", PANGO_STYLE_ITALIC, NULL); appGUI->tsk->font_tag_object = gtk_text_buffer_create_tag (text_buffer, "info_font", "font", (gchar *) config.task_info_font, NULL); }
int buhkomw_r(class buhkomw_rr *datark,GtkWidget *wpredok) { char strsql[512]; iceb_u_str repl; class buhkomw_r_data data; data.rk=datark; data.window=gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_modal(GTK_WINDOW(data.window),TRUE); gtk_window_set_position( GTK_WINDOW(data.window),ICEB_POS_CENTER); gtk_window_set_default_size (GTK_WINDOW (data.window),400,-1); sprintf(strsql,"%s %s",name_system,gettext("Распечатать отчёт по комментариям")); gtk_window_set_title(GTK_WINDOW(data.window),strsql); gtk_signal_connect(GTK_OBJECT(data.window),"delete_event",GTK_SIGNAL_FUNC(gtk_widget_destroy),NULL); gtk_signal_connect(GTK_OBJECT(data.window),"destroy",GTK_SIGNAL_FUNC(gtk_main_quit),NULL); gtk_signal_connect_after(GTK_OBJECT(data.window),"key_press_event",GTK_SIGNAL_FUNC(buhkomw_r_key_press),&data); if(wpredok != NULL) { gdk_window_set_cursor(wpredok->window,gdk_cursor_new(ICEB_CURSOR_GDITE)); //Удерживать окно над породившем его окном всегда gtk_window_set_transient_for(GTK_WINDOW(data.window),GTK_WINDOW(wpredok)); //Закрыть окно если окно предок удалено gtk_window_set_destroy_with_parent(GTK_WINDOW(data.window),TRUE); } GtkWidget *vbox=gtk_vbox_new(FALSE, 2); gtk_container_add(GTK_CONTAINER(data.window), vbox); data.label=gtk_label_new(gettext("Ждите !!!")); gtk_box_pack_start(GTK_BOX(vbox),data.label,FALSE,FALSE,0); repl.plus(gettext("Распечатать отчёт по комментариям")); sprintf(strsql,"%s:%s %s\n",gettext("База данных"),imabaz,organ); repl.ps_plus(strsql); GtkWidget *label=gtk_label_new(repl.ravno_toutf()); gtk_box_pack_start(GTK_BOX(vbox),label,FALSE,FALSE,0); data.view=gtk_text_view_new(); gtk_widget_set_usize(GTK_WIDGET(data.view),450,300); gtk_text_view_set_editable(GTK_TEXT_VIEW(data.view),FALSE); //Запрет на редактирование текста //PangoFontDescription *font_pango=pango_font_description_from_string("Nimbus Mono L, Bold 12"); PangoFontDescription *font_pango=pango_font_description_from_string(shrift_ravnohir.ravno()); gtk_widget_modify_font(GTK_WIDGET(data.view),font_pango); pango_font_description_free(font_pango); data.buffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(data.view)); GtkWidget *sw=gtk_scrolled_window_new(NULL,NULL); //gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),GTK_SHADOW_ETCHED_IN); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC); //gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),GTK_POLICY_ALWAYS,GTK_POLICY_ALWAYS); gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0); gtk_container_add(GTK_CONTAINER(sw),data.view); data.bar=gtk_progress_bar_new(); gtk_progress_bar_set_bar_style(GTK_PROGRESS_BAR(data.bar),GTK_PROGRESS_CONTINUOUS); gtk_progress_bar_set_orientation(GTK_PROGRESS_BAR(data.bar),GTK_PROGRESS_LEFT_TO_RIGHT); gtk_box_pack_start (GTK_BOX (vbox), data.bar, FALSE, FALSE, 2); sprintf(strsql,"F10 %s",gettext("Выход")); data.knopka=gtk_button_new_with_label(strsql); GtkTooltips *tooltops=gtk_tooltips_new(); gtk_tooltips_set_tip(tooltops,data.knopka,gettext("Завершение работы в этом окне"),NULL); gtk_signal_connect(GTK_OBJECT(data.knopka),"clicked",GTK_SIGNAL_FUNC(buhkomw_r_v_knopka),&data); gtk_object_set_user_data(GTK_OBJECT(data.knopka),(gpointer)0); gtk_box_pack_start (GTK_BOX (vbox), data.knopka, FALSE, FALSE, 2); gtk_widget_set_sensitive(GTK_WIDGET(data.knopka),FALSE);//Недоступна gtk_widget_show_all(data.window); //gtk_window_set_decorated(GTK_WINDOW(data.window),FALSE); //Убирает рамку вокруг окна //gtk_widget_set_sensitive(GTK_WIDGET(data.knopka),FALSE);//Недоступна gtk_idle_add((GtkFunction)buhkomw_r1,&data); gtk_main(); if(wpredok != NULL) gdk_window_set_cursor(wpredok->window,gdk_cursor_new(ICEB_CURSOR)); return(data.voz); }
static void mucharmap_charmap_init (MucharmapCharmap *charmap) { MucharmapCharmapPrivate *priv; GtkWidget *scrolled_window, *view, *chartable, *textview; GtkTreeSelection *selection; GtkTextBuffer *buffer; int page; priv = charmap->priv = G_TYPE_INSTANCE_GET_PRIVATE (charmap, MUCHARMAP_TYPE_CHARMAP, MucharmapCharmapPrivate); /* FIXME: move this to realize */ priv->hand_cursor = gdk_cursor_new (GDK_HAND2); priv->regular_cursor = gdk_cursor_new (GDK_XTERM); priv->hovering_over_link = FALSE; /* Left pane */ scrolled_window = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_ETCHED_IN); #if GTK_CHECK_VERSION (3, 15, 9) gtk_scrolled_window_set_overlay_scrolling (GTK_SCROLLED_WINDOW (scrolled_window), FALSE); #endif view = mucharmap_chapters_view_new (); priv->chapters_view = MUCHARMAP_CHAPTERS_VIEW (view); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view)); g_signal_connect (selection, "changed", G_CALLBACK (chapters_view_selection_changed_cb), charmap); gtk_container_add (GTK_CONTAINER (scrolled_window), view); gtk_widget_show (view); gtk_paned_pack1 (GTK_PANED (charmap), scrolled_window, FALSE, TRUE); gtk_widget_show (scrolled_window); /* Right pane */ priv->notebook = gtk_notebook_new (); /* Chartable page */ scrolled_window = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_NONE); chartable = mucharmap_chartable_new (); priv->chartable = MUCHARMAP_CHARTABLE (chartable); g_signal_connect_swapped (chartable, "status-message", G_CALLBACK (chartable_status_message), charmap); g_signal_connect (chartable, "notify::active-character", G_CALLBACK (chartable_sync_active_char), charmap); g_signal_connect (chartable, "notify::font-desc", G_CALLBACK (chartable_sync_font_desc), charmap); g_signal_connect (chartable, "notify::codepoint-list", G_CALLBACK (chartable_notify_cb), charmap); g_signal_connect (chartable, "notify::snap-pow2", G_CALLBACK (chartable_notify_cb), charmap); gtk_container_add (GTK_CONTAINER (scrolled_window), chartable); gtk_widget_show (chartable); page = gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), scrolled_window, gtk_label_new_with_mnemonic (_("Characte_r Table"))); g_assert (page == MUCHARMAP_CHARMAP_PAGE_CHARTABLE); gtk_widget_show (scrolled_window); /* Details page */ scrolled_window = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_ETCHED_IN); textview = gtk_text_view_new (); priv->details_view = GTK_TEXT_VIEW (textview); gtk_text_view_set_editable (GTK_TEXT_VIEW (textview), FALSE); gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (textview), FALSE); gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (textview), GTK_WRAP_WORD); g_signal_connect (textview, "style-set", G_CALLBACK (details_style_set), charmap); g_signal_connect (textview, "key-press-event", G_CALLBACK (details_key_press_event), charmap); g_signal_connect (textview, "event-after", G_CALLBACK (details_event_after), charmap); g_signal_connect (textview, "motion-notify-event", G_CALLBACK (details_motion_notify_event), charmap); g_signal_connect (textview, "visibility-notify-event", G_CALLBACK (details_visibility_notify_event), charmap); buffer = gtk_text_view_get_buffer (priv->details_view); priv->text_tag_gimongous = gtk_text_buffer_create_tag (buffer, "gimongous", NULL); priv->text_tag_big = gtk_text_buffer_create_tag (buffer, "big", NULL); gtk_text_buffer_create_tag (buffer, "bold", "weight", PANGO_WEIGHT_BOLD, NULL); gtk_text_buffer_create_tag (buffer, "detail-value", NULL); gtk_container_add (GTK_CONTAINER (scrolled_window), textview); gtk_widget_show (textview); page = gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), scrolled_window, gtk_label_new_with_mnemonic (_("Character _Details"))); g_assert (page == MUCHARMAP_CHARMAP_PAGE_DETAILS); gtk_widget_show (scrolled_window); priv->active_page = 0; gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), 0); g_signal_connect (priv->notebook, "switch-page", G_CALLBACK (notebook_switch_page), charmap); gtk_paned_pack2 (GTK_PANED (charmap), priv->notebook, TRUE, TRUE); gtk_widget_show (priv->notebook); }
static void qq_chatwidget_init(QQChatWidget *widget) { QQChatWidgetPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE(widget , qq_chatwidget_get_type() , QQChatWidgetPriv); GtkWidget *scrolled_win; gchar buf[100]; // message text view priv -> message_textview = qq_chat_textview_new(); scrolled_win= gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_win), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled_win) , GTK_SHADOW_ETCHED_IN); gtk_container_add(GTK_CONTAINER(scrolled_win), priv -> message_textview); gtk_box_pack_start(GTK_BOX(widget), scrolled_win, TRUE, TRUE, 0); gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(priv -> message_textview) , FALSE); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(priv -> message_textview) , GTK_WRAP_CHAR); gtk_text_view_set_editable(GTK_TEXT_VIEW(priv -> message_textview) , FALSE); // font tools priv -> font_tool_box = gtk_hbox_new(FALSE, 5); g_object_ref(priv -> font_tool_box); priv -> font_cb = gtk_combo_box_text_new(); gint i; for(i = 0; font_names[i] != NULL; ++i){ gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(priv -> font_cb) , font_names[i]); } gtk_box_pack_start(GTK_BOX(priv -> font_tool_box), priv -> font_cb , FALSE, FALSE, 0); priv -> size_cb = gtk_combo_box_text_new(); for(i = 8; i < 23; ++i){ g_snprintf(buf, 10, "%d", i); gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(priv -> size_cb) , buf); } gtk_box_pack_start(GTK_BOX(priv -> font_tool_box), priv -> size_cb , FALSE, FALSE, 0); priv -> bold_btn = qq_toggle_button_new_with_stock(GTK_STOCK_BOLD); priv -> italic_btn = qq_toggle_button_new_with_stock(GTK_STOCK_ITALIC); priv -> underline_btn = qq_toggle_button_new_with_stock( GTK_STOCK_UNDERLINE); gtk_box_pack_start(GTK_BOX(priv -> font_tool_box), priv -> bold_btn , FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(priv -> font_tool_box), priv -> italic_btn , FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(priv -> font_tool_box), priv -> underline_btn , FALSE, FALSE, 0); priv -> color_btn = gtk_color_button_new(); gtk_box_pack_start(GTK_BOX(priv -> font_tool_box), priv -> color_btn , FALSE, FALSE, 0); gtk_widget_show_all(priv -> font_tool_box); g_signal_connect(G_OBJECT(priv -> font_cb), "changed" , G_CALLBACK(qq_chat_widget_font_changed), widget); g_signal_connect(G_OBJECT(priv -> size_cb), "changed" , G_CALLBACK(qq_chat_widget_font_changed), widget); g_signal_connect(G_OBJECT(priv -> bold_btn), "toggled" , G_CALLBACK(qq_chat_widget_font_changed), widget); g_signal_connect(G_OBJECT(priv -> italic_btn), "toggled" , G_CALLBACK(qq_chat_widget_font_changed), widget); g_signal_connect(G_OBJECT(priv -> underline_btn), "toggled" , G_CALLBACK(qq_chat_widget_font_changed), widget); g_signal_connect(G_OBJECT(priv -> color_btn), "color-set" , G_CALLBACK(qq_chat_widget_font_changed), widget); // tool bar priv -> tool_bar = gtk_toolbar_new(); GtkWidget *img = NULL; img = gtk_image_new_from_file(IMGDIR"/selectfont.png"); priv -> font_item = gtk_toggle_tool_button_new(); g_signal_connect(G_OBJECT(priv -> font_item), "toggled" , G_CALLBACK(qq_chat_view_font_button_clicked) , widget); gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(priv -> font_item), img); gtk_toolbar_insert(GTK_TOOLBAR(priv -> tool_bar), priv -> font_item, -1); img = gtk_image_new_from_file(IMGDIR"/selectface.png"); priv -> face_item = gtk_tool_button_new(img, NULL); gtk_toolbar_insert(GTK_TOOLBAR(priv -> tool_bar), priv -> face_item, -1); gtk_toolbar_insert(GTK_TOOLBAR(priv -> tool_bar) , gtk_separator_tool_item_new() , -1); g_signal_connect(G_OBJECT(priv -> face_item), "clicked", G_CALLBACK(face_tool_button_clicked), widget); img = gtk_image_new_from_file(IMGDIR"/sendfile.png"); priv -> sendfile_item = gtk_tool_button_new(img, NULL); gtk_toolbar_insert(GTK_TOOLBAR(priv -> tool_bar), priv -> sendfile_item, -1); img = gtk_image_new_from_file(IMGDIR"/sendpic.png"); priv -> sendpic_item = gtk_tool_button_new(img, NULL); gtk_toolbar_insert(GTK_TOOLBAR(priv -> tool_bar), priv -> sendpic_item, -1); gtk_toolbar_insert(GTK_TOOLBAR(priv -> tool_bar) , gtk_separator_tool_item_new() , -1); img = gtk_image_new_from_file(IMGDIR"/clearscreen.png"); priv -> clear_item = gtk_tool_button_new(img, NULL); gtk_toolbar_insert(GTK_TOOLBAR(priv -> tool_bar), priv -> clear_item, -1); gtk_toolbar_insert(GTK_TOOLBAR(priv -> tool_bar) , gtk_separator_tool_item_new() , -1); g_signal_connect(G_OBJECT(priv -> clear_item), "clicked", G_CALLBACK(clear_button_clicked), widget); img = gtk_image_new_from_file(IMGDIR"/showhistory.png"); priv -> history_item = gtk_tool_button_new(img, NULL); gtk_toolbar_insert(GTK_TOOLBAR(priv -> tool_bar), priv -> history_item, -1); gtk_box_pack_start(GTK_BOX(widget), priv -> tool_bar , FALSE, FALSE, 0); // input text view priv -> input_textview = qq_chat_textview_new(); gtk_text_view_set_indent(GTK_TEXT_VIEW(priv -> input_textview), 1); scrolled_win= gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(scrolled_win), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled_win) , GTK_SHADOW_ETCHED_IN); gtk_container_add(GTK_CONTAINER(scrolled_win), priv -> input_textview); gtk_box_pack_start(GTK_BOX(widget), scrolled_win, FALSE, FALSE, 0); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(priv -> input_textview) , GTK_WRAP_CHAR); gtk_combo_box_set_active(GTK_COMBO_BOX(priv -> font_cb), 1); gtk_combo_box_set_active(GTK_COMBO_BOX(priv -> size_cb), 3); gtk_widget_grab_focus(priv -> input_textview); priv -> facepopupwindow = qq_face_popup_window_new(); g_signal_connect(G_OBJECT(priv -> facepopupwindow), "face-clicked" , G_CALLBACK(qq_chatwidget_face_clicked) , priv); }
void console_dialog_run(GtkWindow *parent, JamAccountLJ *acc) { ConsoleUI *cui; GtkWidget *vbox, *hbox, *button; GtkTextBuffer *buffer; GtkTextIter end; cui = g_new0(ConsoleUI, 1); cui->account = acc; cui->win = gtk_dialog_new_with_buttons(_("LiveJournal Console"), parent, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL); jam_win_set_size(GTK_WINDOW(cui->win), 500, 400); g_signal_connect_swapped(G_OBJECT(cui->win), "response", G_CALLBACK(gtk_widget_destroy), cui->win); g_signal_connect_swapped(G_OBJECT(cui->win), "destroy", G_CALLBACK(g_free), cui); geometry_tie(cui->win, GEOM_CONSOLE); vbox = gtk_vbox_new(FALSE, 5); hbox = gtk_hbox_new(FALSE, 5); cui->entry = gtk_entry_new(); gtk_box_pack_start(GTK_BOX(hbox), cui->entry, TRUE, TRUE, 0); button = gtk_button_new_with_mnemonic(_(" _Submit ")); gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); g_signal_connect(G_OBJECT(cui->entry), "activate", G_CALLBACK(submit_cb), cui); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(submit_cb), cui); button = gtk_button_new_from_stock(GTK_STOCK_HELP); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(console_help), cui); gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); cui->display = gtk_text_view_new(); gtk_text_view_set_editable(GTK_TEXT_VIEW(cui->display), FALSE); gtk_box_pack_start(GTK_BOX(vbox), scroll_wrap(cui->display), TRUE, TRUE, 0); buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(cui->display)); gtk_text_buffer_get_end_iter(buffer, &end); cui->mark_end = gtk_text_buffer_create_mark(buffer, NULL, &end, FALSE); gtk_text_buffer_create_tag(buffer, "command", "family", "monospace", NULL); gtk_text_buffer_create_tag(buffer, "info", "family", "monospace", "foreground", "darkgreen", NULL); gtk_text_buffer_create_tag(buffer, "error", "family", "monospace", "weight", PANGO_WEIGHT_BOLD, "foreground", "red", NULL); jam_dialog_set_contents(GTK_DIALOG(cui->win), vbox); console_print(cui, NULL, _("LiveJournal console ready.\n")); gtk_widget_show(cui->win); }
void sndstretch_about(void) { GtkWidget * vbox, * scrolltext, * button; GtkWidget * titlelabel, * copylabel; GtkWidget * text; GtkTextBuffer * textbuffer; GtkTextIter iter; GtkWidget * copyhbox, * copy_rbox, * copy_lbox; if (sndstretch_about_dialog != NULL) return; sndstretch_about_dialog = gtk_dialog_new(); gtk_widget_show(sndstretch_about_dialog); GtkWidget * logo = gtk_image_new_from_pixbuf (gdk_pixbuf_new_from_xpm_data ((const gchar * *) sndstretch_xmms_logo_xpm)); GtkWidget * FBlogo = gtk_image_new_from_pixbuf (gdk_pixbuf_new_from_xpm_data ((const gchar * *) FB_logo_xpm)); g_signal_connect (sndstretch_about_dialog, "destroy", (GCallback) sndstretch_about_destroy_cb, NULL); gtk_window_set_title(GTK_WINDOW(sndstretch_about_dialog), _("About SndStretch")); /* labels */ titlelabel = gtk_label_new(sndstretch_title_text); copylabel = gtk_label_new(sndstretch_about_text); gtk_label_set_justify(GTK_LABEL(copylabel), GTK_JUSTIFY_LEFT); copy_lbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,0); copy_rbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,0); gtk_box_pack_end (GTK_BOX(copy_lbox), FBlogo, FALSE, TRUE, 0); gtk_box_pack_start(GTK_BOX(copy_rbox), copylabel, FALSE, TRUE, 0); copyhbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,0); gtk_box_pack_start(GTK_BOX(copyhbox), copy_lbox, TRUE, TRUE, 5); gtk_box_pack_start(GTK_BOX(copyhbox), copy_rbox, TRUE, TRUE, 5); vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); gtk_box_pack_start ((GtkBox *) gtk_dialog_get_content_area ((GtkDialog *) sndstretch_about_dialog), vbox, TRUE, TRUE, 5); scrolltext = gtk_scrolled_window_new(NULL,NULL); text = gtk_text_view_new(); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD); gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE); textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text)); gtk_text_buffer_get_iter_at_offset(textbuffer, &iter, 0); gtk_text_buffer_insert(textbuffer, &iter, sndstretch_GPL_text, strlen(sndstretch_GPL_text)); scrolltext = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolltext), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_container_add(GTK_CONTAINER(scrolltext), text); gtk_box_pack_start(GTK_BOX(vbox), logo, FALSE, TRUE, 5); gtk_box_pack_start(GTK_BOX(vbox), titlelabel, FALSE, TRUE, 5); gtk_box_pack_start(GTK_BOX(vbox), copyhbox, FALSE, TRUE, 5); gtk_box_pack_start(GTK_BOX(vbox), scrolltext, TRUE, TRUE, 5); gtk_container_set_border_width(GTK_CONTAINER(vbox), 8); button = gtk_button_new_from_stock(GTK_STOCK_CLOSE); gtk_box_pack_start ((GtkBox *) gtk_dialog_get_action_area ((GtkDialog *) sndstretch_about_dialog), button, FALSE, FALSE, 0); g_signal_connect (button, "clicked", (GCallback) sndstretch_about_ok_cb, NULL); gtk_widget_set_can_default (button, TRUE); gtk_widget_grab_default(button); gtk_widget_show(button); gtk_widget_show_all(sndstretch_about_dialog); }
static GtkWidget *create_window(void) { // Basic window stwidgets.startwin = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(stwidgets.startwin), apptitle); // NOTE: use global app title gtk_window_set_position(GTK_WINDOW(stwidgets.startwin), GTK_WIN_POS_CENTER); gtk_window_set_resizable(GTK_WINDOW(stwidgets.startwin), FALSE); gtk_window_set_type_hint(GTK_WINDOW(stwidgets.startwin), GDK_WINDOW_TYPE_HINT_DIALOG); // Horizontal layout of banner and controls stwidgets.hlayout = gtk_hbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(stwidgets.startwin), stwidgets.hlayout); // banner { GdkPixbuf *pixbuf = load_banner(); stwidgets.banner = gtk_image_new_from_pixbuf(pixbuf); g_object_unref((gpointer)pixbuf); } gtk_box_pack_start(GTK_BOX(stwidgets.hlayout), stwidgets.banner, FALSE, FALSE, 0); gtk_misc_set_alignment(GTK_MISC(stwidgets.banner), 0.5, 0); // Vertical layout of tab control and start+cancel buttons stwidgets.vlayout = gtk_vbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(stwidgets.hlayout), stwidgets.vlayout, TRUE, TRUE, 0); // Tab control stwidgets.tabs = gtk_notebook_new(); gtk_box_pack_start(GTK_BOX(stwidgets.vlayout), stwidgets.tabs, TRUE, TRUE, 0); gtk_container_set_border_width(GTK_CONTAINER(stwidgets.tabs), 4); // layout table of config page stwidgets.configtlayout = gtk_table_new(6, 3, FALSE); gtk_container_add(GTK_CONTAINER(stwidgets.tabs), stwidgets.configtlayout); // 3D video mode LabelText stwidgets.vmode3dlabel = gtk_label_new_with_mnemonic("_Video mode:"); gtk_misc_set_alignment(GTK_MISC(stwidgets.vmode3dlabel), 0.3, 0); gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.vmode3dlabel, 0,1, 0,1, GTK_FILL, 0, 4, 0); // 3D video mode combo { GtkListStore *list = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT); GtkCellRenderer *cell; stwidgets.vmode3dcombo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(list)); g_object_unref(G_OBJECT(list)); cell = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(stwidgets.vmode3dcombo), cell, FALSE); gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(stwidgets.vmode3dcombo), cell, "text", 0, NULL); } gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.vmode3dcombo, 1,2, 0,1, GTK_EXPAND | GTK_FILL, 0, 4, 0); // Fullscreen checkbox stwidgets.displayvlayout = gtk_vbox_new(TRUE, 0); gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.displayvlayout, 2,3, 0,1, GTK_FILL, 0, 4, 0); stwidgets.fullscreencheck = gtk_check_button_new_with_mnemonic("_Fullscreen"); gtk_box_pack_start(GTK_BOX(stwidgets.displayvlayout), stwidgets.fullscreencheck, FALSE, FALSE, 0); #ifdef POLYMER // Polymer checkbox stwidgets.polymercheck = gtk_check_button_new_with_mnemonic("_Polymer"); gtk_box_pack_start(GTK_BOX(stwidgets.displayvlayout), stwidgets.polymercheck, FALSE, FALSE, 0); #endif // Input devices LabelText stwidgets.inputdevlabel = gtk_label_new_with_mnemonic("_Input devices:"); gtk_misc_set_alignment(GTK_MISC(stwidgets.inputdevlabel), 0.3, 0); gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.inputdevlabel, 0,1, 1,2, GTK_FILL, 0, 4, 0); // Input devices combo { GtkListStore *list = gtk_list_store_new(1, G_TYPE_STRING); GtkCellRenderer *cell; stwidgets.inputdevcombo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(list)); g_object_unref(G_OBJECT(list)); cell = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(stwidgets.inputdevcombo), cell, FALSE); gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(stwidgets.inputdevcombo), cell, "text", 0, NULL); } gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.inputdevcombo, 1,2, 1,2, GTK_EXPAND | GTK_FILL, 0, 4, 0); // Custom mod LabelText stwidgets.custommodlabel = gtk_label_new_with_mnemonic("Custom _game:"); gtk_misc_set_alignment(GTK_MISC(stwidgets.custommodlabel), 0.3, 0); gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.custommodlabel, 0,1, 2,3, GTK_FILL, 0, 4, 7); // Custom mod combo { GtkListStore *list = gtk_list_store_new(1, G_TYPE_STRING); GtkCellRenderer *cell; stwidgets.custommodcombo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(list)); g_object_unref(G_OBJECT(list)); cell = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(stwidgets.custommodcombo), cell, FALSE); gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(stwidgets.custommodcombo), cell, "text", 0, NULL); } gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.custommodcombo, 1,2, 2,3, GTK_EXPAND | GTK_FILL, 0, 4, 7); // Empty horizontal layout stwidgets.emptyhlayout = gtk_hbox_new(TRUE, 0); gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.emptyhlayout, 0,3, 3,4, 0, GTK_EXPAND | GTK_FILL, 4, 0); // Autoload checkbox stwidgets.autoloadcheck = gtk_check_button_new_with_mnemonic("_Enable \"autoload\" folder"); gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.autoloadcheck, 0,3, 4,5, GTK_FILL, 0, 2, 2); // Always show config checkbox stwidgets.alwaysshowcheck = gtk_check_button_new_with_mnemonic("_Always show this window at startup"); gtk_table_attach(GTK_TABLE(stwidgets.configtlayout), stwidgets.alwaysshowcheck, 0,3, 5,6, GTK_FILL, 0, 2, 2); // Configuration tab stwidgets.configtab = gtk_label_new("Configuration"); gtk_notebook_set_tab_label(GTK_NOTEBOOK(stwidgets.tabs), gtk_notebook_get_nth_page(GTK_NOTEBOOK(stwidgets.tabs), 0), stwidgets.configtab); // Game data layout stwidgets.gamevlayout = gtk_vbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(stwidgets.tabs), stwidgets.gamevlayout); gtk_container_set_border_width(GTK_CONTAINER(stwidgets.gamevlayout), 4); // Game data field LabelText stwidgets.gamelabel = gtk_label_new_with_mnemonic("_Game:"); gtk_box_pack_start(GTK_BOX(stwidgets.gamevlayout), stwidgets.gamelabel, FALSE, FALSE, 0); gtk_misc_set_alignment(GTK_MISC(stwidgets.gamelabel), 0, 0.5); // Game data scrollable area stwidgets.gamescroll = gtk_scrolled_window_new(NULL, NULL); gtk_box_pack_start(GTK_BOX(stwidgets.gamevlayout), stwidgets.gamescroll, TRUE, TRUE, 0); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(stwidgets.gamescroll), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(stwidgets.gamescroll), GTK_SHADOW_IN); // Game data list { GtkListStore *list = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER); GtkCellRenderer *cell; GtkTreeViewColumn *col; gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(list), 0, name_sorter, NULL, NULL); gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(list), 0, GTK_SORT_ASCENDING); stwidgets.gamelist = gtk_tree_view_new_with_model(GTK_TREE_MODEL(list)); g_object_unref(G_OBJECT(list)); cell = gtk_cell_renderer_text_new(); col = gtk_tree_view_column_new_with_attributes("Game", cell, "text", 0, NULL); gtk_tree_view_column_set_expand(col, TRUE); gtk_tree_view_append_column(GTK_TREE_VIEW(stwidgets.gamelist), col); col = gtk_tree_view_column_new_with_attributes("GRP file", cell, "text", 1, NULL); gtk_tree_view_column_set_min_width(col, 64); gtk_tree_view_append_column(GTK_TREE_VIEW(stwidgets.gamelist), col); } gtk_container_add(GTK_CONTAINER(stwidgets.gamescroll), stwidgets.gamelist); gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(stwidgets.gamelist), FALSE); gtk_tree_view_set_enable_search(GTK_TREE_VIEW(stwidgets.gamelist), FALSE); // Game tab stwidgets.gametab = gtk_label_new("Game"); gtk_notebook_set_tab_label(GTK_NOTEBOOK(stwidgets.tabs), gtk_notebook_get_nth_page(GTK_NOTEBOOK(stwidgets.tabs), 1), stwidgets.gametab); // Messages scrollable area stwidgets.messagesscroll = gtk_scrolled_window_new(NULL, NULL); gtk_container_add(GTK_CONTAINER(stwidgets.tabs), stwidgets.messagesscroll); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(stwidgets.messagesscroll), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); // Messages text area stwidgets.messagestext = gtk_text_view_new(); gtk_container_add(GTK_CONTAINER(stwidgets.messagesscroll), stwidgets.messagestext); gtk_text_view_set_editable(GTK_TEXT_VIEW(stwidgets.messagestext), FALSE); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(stwidgets.messagestext), GTK_WRAP_WORD); gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(stwidgets.messagestext), FALSE); gtk_text_view_set_left_margin(GTK_TEXT_VIEW(stwidgets.messagestext), 2); gtk_text_view_set_right_margin(GTK_TEXT_VIEW(stwidgets.messagestext), 2); // Messages tab stwidgets.messagestab = gtk_label_new("Messages"); gtk_notebook_set_tab_label(GTK_NOTEBOOK(stwidgets.tabs), gtk_notebook_get_nth_page(GTK_NOTEBOOK(stwidgets.tabs), 2), stwidgets.messagestab); // Dialogue box buttons layout stwidgets.buttons = gtk_hbutton_box_new(); gtk_box_pack_start(GTK_BOX(stwidgets.vlayout), stwidgets.buttons, FALSE, TRUE, 0); gtk_container_set_border_width(GTK_CONTAINER(stwidgets.buttons), 3); gtk_button_box_set_layout(GTK_BUTTON_BOX(stwidgets.buttons), GTK_BUTTONBOX_END); // Cancel button stwidgets.cancelbutton = gtk_button_new(); gtk_container_add(GTK_CONTAINER(stwidgets.buttons), stwidgets.cancelbutton); GTK_WIDGET_SET_FLAGS(stwidgets.cancelbutton, GTK_CAN_DEFAULT); stwidgets.cancelbuttonalign = gtk_alignment_new(0.5, 0.5, 0, 0); gtk_container_add(GTK_CONTAINER(stwidgets.cancelbutton), stwidgets.cancelbuttonalign); stwidgets.cancelbuttonlayout = gtk_hbox_new(FALSE, 2); gtk_container_add(GTK_CONTAINER(stwidgets.cancelbuttonalign), stwidgets.cancelbuttonlayout); stwidgets.cancelbuttonicon = gtk_image_new_from_stock("gtk-cancel", GTK_ICON_SIZE_BUTTON); gtk_box_pack_start(GTK_BOX(stwidgets.cancelbuttonlayout), stwidgets.cancelbuttonicon, FALSE, FALSE, 0); stwidgets.cancelbuttonlabel = gtk_label_new_with_mnemonic("_Cancel"); gtk_box_pack_start(GTK_BOX(stwidgets.cancelbuttonlayout), stwidgets.cancelbuttonlabel, FALSE, FALSE, 0); // Start button stwidgets.startbutton = gtk_button_new(); gtk_container_add(GTK_CONTAINER(stwidgets.buttons), stwidgets.startbutton); GTK_WIDGET_SET_FLAGS(stwidgets.startbutton, GTK_CAN_DEFAULT); gtk_window_set_default(GTK_WINDOW(stwidgets.startwin), stwidgets.startbutton); stwidgets.startbuttonalign = gtk_alignment_new(0.5, 0.5, 0, 0); gtk_container_add(GTK_CONTAINER(stwidgets.startbutton), stwidgets.startbuttonalign); stwidgets.startbuttonlayout = gtk_hbox_new(FALSE, 2); gtk_container_add(GTK_CONTAINER(stwidgets.startbuttonalign), stwidgets.startbuttonlayout); stwidgets.startbuttonicon = gtk_image_new_from_stock("gtk-execute", GTK_ICON_SIZE_BUTTON); gtk_box_pack_start(GTK_BOX(stwidgets.startbuttonlayout), stwidgets.startbuttonicon, FALSE, FALSE, 0); stwidgets.startbuttonlabel = gtk_label_new_with_mnemonic("_Start"); gtk_box_pack_start(GTK_BOX(stwidgets.startbuttonlayout), stwidgets.startbuttonlabel, FALSE, FALSE, 0); // Wire up the signals g_signal_connect((gpointer) stwidgets.startwin, "delete_event", G_CALLBACK(on_startwin_delete_event), NULL); g_signal_connect((gpointer) stwidgets.vmode3dcombo, "changed", G_CALLBACK(on_vmode3dcombo_changed), NULL); g_signal_connect((gpointer) stwidgets.fullscreencheck, "toggled", G_CALLBACK(on_fullscreencheck_toggled), NULL); #ifdef POLYMER g_signal_connect((gpointer) stwidgets.polymercheck, "toggled", G_CALLBACK(on_polymercheck_toggled), NULL); #endif g_signal_connect((gpointer) stwidgets.inputdevcombo, "changed", G_CALLBACK(on_inputdevcombo_changed), NULL); g_signal_connect((gpointer) stwidgets.custommodcombo, "changed", G_CALLBACK(on_custommodcombo_changed), NULL); g_signal_connect((gpointer) stwidgets.autoloadcheck, "toggled", G_CALLBACK(on_autoloadcheck_toggled), NULL); g_signal_connect((gpointer) stwidgets.alwaysshowcheck, "toggled", G_CALLBACK(on_alwaysshowcheck_toggled), NULL); g_signal_connect((gpointer) stwidgets.cancelbutton, "clicked", G_CALLBACK(on_cancelbutton_clicked), NULL); g_signal_connect((gpointer) stwidgets.startbutton, "clicked", G_CALLBACK(on_startbutton_clicked), NULL); { GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(stwidgets.gamelist)); gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE); g_signal_connect((gpointer) sel, "changed", G_CALLBACK(on_gamelist_selection_changed), NULL); } // Associate labels with their controls gtk_label_set_mnemonic_widget(GTK_LABEL(stwidgets.vmode3dlabel), stwidgets.vmode3dcombo); gtk_label_set_mnemonic_widget(GTK_LABEL(stwidgets.inputdevlabel), stwidgets.inputdevcombo); gtk_label_set_mnemonic_widget(GTK_LABEL(stwidgets.custommodlabel), stwidgets.custommodcombo); gtk_label_set_mnemonic_widget(GTK_LABEL(stwidgets.gamelabel), stwidgets.gamelist); return stwidgets.startwin; }
void quotefmt_create_forward_fmt_widgets(GtkWindow *parent_window, GtkWidget *parent_box, GtkWidget **checkbtn_forward_with_format, GtkWidget **override_from_format, GtkWidget **edit_fw_quotemark, GtkWidget **edit_fw_format, gboolean add_info_button, void(*set_defaults_func)(void)) { GtkWidget *checkbtn_use_format = NULL; GtkWidget *vbox_quote; GtkWidget *hbox1; GtkWidget *hbox2; GtkWidget *hbox3; GtkWidget *label_quotemark; GtkWidget *entry_fw_quotemark; GtkWidget *label_from = NULL; GtkWidget *entry_from = NULL; GtkWidget *scrolledwin_quotefmt; GtkWidget *text_fw_quotefmt; GtkSizeGroup *size_group; if (add_info_button) cm_return_if_fail(parent_window != NULL); cm_return_if_fail(parent_box != NULL); if (checkbtn_forward_with_format) { cm_return_if_fail(checkbtn_forward_with_format != NULL); } cm_return_if_fail(edit_fw_quotemark != NULL); cm_return_if_fail(edit_fw_format != NULL); size_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); if (checkbtn_forward_with_format) PACK_CHECK_BUTTON (parent_box, checkbtn_use_format, _("Use template when forwarding messages")); vbox_quote = gtk_vbox_new (FALSE, 4); gtk_widget_show(vbox_quote); gtk_container_add(GTK_CONTAINER (parent_box), vbox_quote); gtk_container_set_border_width (GTK_CONTAINER (vbox_quote), 8); if (override_from_format) { hbox3 = gtk_hbox_new (FALSE, 8); gtk_widget_show (hbox3); gtk_box_pack_start (GTK_BOX (vbox_quote), hbox3, FALSE, FALSE, 0); label_from = gtk_label_new (prefs_common_translated_header_name("From")); gtk_misc_set_alignment(GTK_MISC(label_from), 1, 0.5); gtk_widget_show (label_from); gtk_box_pack_start (GTK_BOX (hbox3), label_from, FALSE, FALSE, 0); gtk_size_group_add_widget(size_group, label_from); entry_from = gtk_entry_new (); gtk_widget_show (entry_from); gtk_box_pack_start (GTK_BOX (hbox3), entry_from, TRUE, TRUE, 0); gtk_widget_set_size_request (entry_from, 100, -1); CLAWS_SET_TIP(entry_from, _("Override From header. This doesn't change the account used to forward.")); } hbox1 = gtk_hbox_new (FALSE, 32); gtk_widget_show (hbox1); gtk_box_pack_start (GTK_BOX (vbox_quote), hbox1, FALSE, FALSE, 0); hbox2 = gtk_hbox_new (FALSE, 8); gtk_widget_show (hbox2); gtk_box_pack_start (GTK_BOX (hbox1), hbox2, FALSE, FALSE, 0); label_quotemark = gtk_label_new (_("Quotation mark")); gtk_misc_set_alignment(GTK_MISC(label_quotemark), 1, 0.5); gtk_widget_show (label_quotemark); gtk_box_pack_start (GTK_BOX (hbox2), label_quotemark, FALSE, FALSE, 0); gtk_size_group_add_widget(size_group, label_quotemark); entry_fw_quotemark = gtk_entry_new (); gtk_widget_show (entry_fw_quotemark); gtk_box_pack_start (GTK_BOX (hbox2), entry_fw_quotemark, FALSE, FALSE, 0); gtk_widget_set_size_request (entry_fw_quotemark, 64, -1); scrolledwin_quotefmt = gtk_scrolled_window_new (NULL, NULL); gtk_widget_show (scrolledwin_quotefmt); gtk_box_pack_start (GTK_BOX (vbox_quote), scrolledwin_quotefmt, TRUE, TRUE, 0); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwin_quotefmt), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwin_quotefmt), GTK_SHADOW_IN); text_fw_quotefmt = gtk_text_view_new (); if (prefs_common.textfont) { PangoFontDescription *font_desc; font_desc = pango_font_description_from_string (prefs_common.textfont); if (font_desc) { gtk_widget_modify_font(text_fw_quotefmt, font_desc); pango_font_description_free(font_desc); } } gtk_widget_show(text_fw_quotefmt); gtk_container_add(GTK_CONTAINER(scrolledwin_quotefmt), text_fw_quotefmt); gtk_text_view_set_editable (GTK_TEXT_VIEW (text_fw_quotefmt), TRUE); gtk_widget_set_size_request (text_fw_quotefmt, -1, 100); if (checkbtn_forward_with_format) { SET_TOGGLE_SENSITIVITY(checkbtn_use_format, label_quotemark); SET_TOGGLE_SENSITIVITY(checkbtn_use_format, entry_fw_quotemark); if (override_from_format) { SET_TOGGLE_SENSITIVITY(checkbtn_use_format, entry_from); SET_TOGGLE_SENSITIVITY(checkbtn_use_format, label_from); } SET_TOGGLE_SENSITIVITY(checkbtn_use_format, text_fw_quotefmt); } quote_fmt_add_buttons(parent_window, vbox_quote, add_info_button, set_defaults_func); if (checkbtn_forward_with_format) *checkbtn_forward_with_format = checkbtn_use_format; *edit_fw_quotemark = entry_fw_quotemark; if (override_from_format) *override_from_format = entry_from; *edit_fw_format = text_fw_quotefmt; g_object_unref(G_OBJECT(size_group)); }
void gtkui_help(void) { GtkWidget *dialog, *scrolled, *treeview, *hbox, *textview; GtkCellRenderer *renderer; GtkTreeViewColumn *column; GtkTreeIter iter; help_pair *section; DEBUG_MSG("gtkui_help"); dialog = gtk_dialog_new_with_buttons(EC_PROGRAM" Help", GTK_WINDOW (window), GTK_DIALOG_MODAL, GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL); gtk_window_set_default_size(GTK_WINDOW (dialog), 780, 580); gtk_dialog_set_has_separator(GTK_DIALOG (dialog), TRUE); gtk_container_set_border_width(GTK_CONTAINER (dialog), 5); hbox = gtk_hbox_new (FALSE, 6); gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, TRUE, TRUE, 0); scrolled = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scrolled), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW (scrolled), GTK_SHADOW_IN); gtk_box_pack_start(GTK_BOX(hbox), scrolled, FALSE, FALSE, 0); gtk_widget_show(scrolled); treeview = gtk_tree_view_new(); gtk_tree_view_set_headers_visible(GTK_TREE_VIEW (treeview), FALSE); gtk_container_add(GTK_CONTAINER (scrolled), treeview); gtk_widget_show(treeview); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE); g_signal_connect(selection, "changed", G_CALLBACK (gtkui_help_selected), liststore); renderer = gtk_cell_renderer_text_new (); column = gtk_tree_view_column_new_with_attributes ("Contents", renderer, "text", 0, NULL); gtk_tree_view_column_set_sort_column_id (column, 0); gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column); liststore = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_POINTER); for(section = help_list; section->title; section++) { gtk_list_store_append (liststore, &iter); gtk_list_store_set (liststore, &iter, 0, section->title, 1, section->file, -1); } gtk_tree_view_set_model(GTK_TREE_VIEW (treeview), GTK_TREE_MODEL (liststore)); /* text area */ scrolled = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW (scrolled), GTK_SHADOW_IN); gtk_box_pack_start(GTK_BOX(hbox), scrolled, TRUE, TRUE, 0); gtk_widget_show(scrolled); textview = gtk_text_view_new(); gtk_text_view_set_editable(GTK_TEXT_VIEW (textview), FALSE); gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW (textview), FALSE); gtk_container_add(GTK_CONTAINER (scrolled), textview); gtk_widget_show(textview); textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW (textview)); gtk_widget_show_all(hbox); gtk_dialog_run(GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); }
int main(int argc, char **argv) { BrailleMusicEditor *editor; // allocate the memory needed by our BrailleMusicEditor struct editor = g_slice_new (BrailleMusicEditor); //initialize GTK+ libraries gtk_init(&argc, &argv); ev_init(); // Creation of the main window create_window("BMC",600,400, editor); editor->vbox = gtk_vbox_new(FALSE, 2); gtk_container_add(GTK_CONTAINER(editor->window), editor->vbox); //Creation of the menubar create_menubar(editor); gtk_box_pack_start(GTK_BOX(editor->vbox), editor->menubar, FALSE, FALSE, 0); // Creation of the toolbar create_toolbar(editor); gtk_box_pack_start(GTK_BOX(editor->vbox), editor->toolbar, FALSE, FALSE, 2); //Creation of the two text views with scrollbars editor->hbox = gtk_hbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(editor->vbox), editor->hbox); editor->edit_scrollbar = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(editor->edit_scrollbar), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_box_pack_start(GTK_BOX(editor->hbox),editor->edit_scrollbar, TRUE, TRUE, 5); editor->textview=gtk_source_view_new(); //show line number gtk_source_view_set_show_line_numbers(GTK_SOURCE_VIEW(editor->textview), TRUE); g_signal_connect(gtk_text_view_get_buffer(GTK_TEXT_VIEW(editor->textview)), "changed", G_CALLBACK(on_text_changed), editor); gtk_container_add(GTK_CONTAINER(editor->edit_scrollbar), editor->textview); //lexical coloration auto update g_signal_connect(gtk_text_view_get_buffer(GTK_TEXT_VIEW(editor->textview)), "changed", G_CALLBACK(coloration_update), editor); //score view editor->score_scrollbar = gtk_scrolled_window_new(NULL, NULL); gtk_box_pack_start(GTK_BOX(editor->hbox),editor->score_scrollbar, TRUE, TRUE, 5); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(editor->score_scrollbar), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); editor->score_view = ev_view_new(); gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(editor->score_scrollbar), editor->score_view); show_score(editor); gtk_widget_grab_focus(editor->textview); //Creation of the message error views with scrollbar editor->error_scrollbar = gtk_scrolled_window_new(NULL, NULL); gtk_box_pack_start(GTK_BOX(editor->vbox),editor->error_scrollbar, FALSE, TRUE, 0); gtk_widget_set_size_request (editor->error_scrollbar, -1, 100); gtk_container_set_border_width(GTK_CONTAINER(editor->error_scrollbar), 5); editor->error_view = gtk_text_view_new(); gtk_text_view_set_editable(GTK_TEXT_VIEW(editor->error_view), FALSE); gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(editor->error_scrollbar), editor->error_view); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(editor->error_scrollbar), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); // show the window gtk_widget_show_all(editor->window); // enter GTK+ main loop gtk_main(); // free memory we allocated for BrailleMusicEditor struct g_slice_free (BrailleMusicEditor, editor); return EXIT_SUCCESS; }
GtkWidget * text_create_widget (GtkWidget * dlg) { GtkWidget *w; w = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (w), GTK_SHADOW_ETCHED_IN); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (w), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); text_view = gtk_text_view_new (); gtk_widget_set_name (text_view, "yad-text-widget"); text_buffer = gtk_text_buffer_new (NULL); gtk_text_view_set_buffer (GTK_TEXT_VIEW (text_view), text_buffer); gtk_text_view_set_justification (GTK_TEXT_VIEW (text_view), options.text_data.justify); gtk_text_view_set_left_margin (GTK_TEXT_VIEW (text_view), options.text_data.margins); gtk_text_view_set_right_margin (GTK_TEXT_VIEW (text_view), options.text_data.margins); gtk_text_view_set_editable (GTK_TEXT_VIEW (text_view), options.common_data.editable); if (!options.common_data.editable) gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (text_view), FALSE); if (options.text_data.wrap) gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text_view), GTK_WRAP_WORD_CHAR); if (options.text_data.fore) { #if GTK_CHECK_VERSION(3,0,0) GdkRGBA clr; if (gdk_rgba_parse (&clr, options.text_data.fore)) gtk_widget_override_color (text_view, GTK_STATE_FLAG_NORMAL, &clr); #else GdkColor clr; if (gdk_color_parse (options.text_data.fore, &clr)) gtk_widget_modify_text (text_view, GTK_STATE_NORMAL, &clr); #endif } if (options.text_data.back) { #if GTK_CHECK_VERSION(3,0,0) GdkRGBA clr; if (gdk_rgba_parse (&clr, options.text_data.fore)) gtk_widget_override_background_color (text_view, GTK_STATE_FLAG_NORMAL, &clr); #else GdkColor clr; if (gdk_color_parse (options.text_data.back, &clr)) gtk_widget_modify_base (text_view, GTK_STATE_NORMAL, &clr); #endif } if (options.common_data.font) { PangoFontDescription *fd = pango_font_description_from_string (options.common_data.font); #if GTK_CHECK_VERSION(3,0,0) gtk_widget_override_font (text_view, fd); #else gtk_widget_modify_font (text_view, fd); #endif pango_font_description_free (fd); } /* Add submit on ctrl+enter */ g_signal_connect (text_view, "key-press-event", G_CALLBACK (key_press_cb), dlg); /* Initialize linkifying */ if (options.text_data.uri) { GRegex *regex; regex = g_regex_new (YAD_URL_REGEX, G_REGEX_CASELESS | G_REGEX_OPTIMIZE | G_REGEX_EXTENDED, G_REGEX_MATCH_NOTEMPTY, NULL); /* Create text tag for URI */ tag = gtk_text_buffer_create_tag (text_buffer, NULL, "foreground", "blue", "underline", PANGO_UNDERLINE_SINGLE, NULL); g_object_set_data (G_OBJECT (tag), "is_link", GINT_TO_POINTER (1)); g_signal_connect (G_OBJECT (tag), "event", G_CALLBACK (tag_event_cb), NULL); /* Create cursors */ hand = gdk_cursor_new (GDK_HAND2); normal= gdk_cursor_new (GDK_XTERM); g_signal_connect (G_OBJECT (text_view), "motion-notify-event", G_CALLBACK (motion_cb), NULL); g_signal_connect_after (G_OBJECT (text_buffer), "changed", G_CALLBACK (linkify_cb), regex); } gtk_container_add (GTK_CONTAINER (w), text_view); if (options.common_data.uri) fill_buffer_from_file (); else fill_buffer_from_stdin (); return w; }
static void message_dialog (GtkMessageType message_type, const gchar *message, Git *plugin) { const gchar *dialog_title; GtkWidget *image; GtkWidget *dialog; GtkWidget *close_button; GtkWidget *content_area; GtkWidget *hbox; GtkWidget *scrolled_window; GtkWidget *text_view; GtkTextBuffer *text_buffer; dialog_title = NULL; image = gtk_image_new (); switch (message_type) { case GTK_MESSAGE_ERROR: gtk_image_set_from_icon_name (GTK_IMAGE (image), GTK_STOCK_DIALOG_ERROR, GTK_ICON_SIZE_DIALOG); dialog_title = _("Git Error"); break; case GTK_MESSAGE_WARNING: gtk_image_set_from_icon_name (GTK_IMAGE (image), GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_DIALOG); dialog_title = _("Git Warning"); break; default: break; } dialog = gtk_dialog_new_with_buttons (dialog_title, GTK_WINDOW (ANJUTA_PLUGIN (plugin)->shell), GTK_DIALOG_DESTROY_WITH_PARENT, NULL); close_button = gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE); content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); hbox = gtk_hbox_new (FALSE, 2); scrolled_window = gtk_scrolled_window_new (NULL, NULL); text_view = gtk_text_view_new (); text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view)); gtk_window_set_default_size (GTK_WINDOW (dialog), 550, 200); gtk_container_add (GTK_CONTAINER (scrolled_window), text_view); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_IN); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_text_view_set_editable (GTK_TEXT_VIEW (text_view), FALSE); gtk_text_buffer_set_text (text_buffer, message, strlen (message)); gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox), scrolled_window, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (content_area), hbox, TRUE, TRUE, 0); gtk_widget_grab_default (close_button); gtk_widget_grab_focus (close_button); g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (gtk_widget_destroy), NULL); gtk_widget_show_all (dialog); }
int main( int argc, char *argv[] ) { /* GtkWidget is the storage type for widgets */ GtkWidget *window, *text_view, *vbox, *vbox1, vbox2, *show, *prefs, *win; GtkTextTag *tag; GtkTextBuffer *buffer; GtkTextIter start, end; WplPidginSettings *settings = NULL; settings = WplPidginSettings_construct(); WplPidginSettings_loadFromFile(settings); settings->wpl->opensearchCallback = G_CALLBACK(opensearchMenuCallback); g_print("---\nsettings: %s, %s,\n---", settings->wpl->url, settings->wpl->language); //g_print(_("Here is a translation test.")); /* This is called in all GTK applications. Arguments are parsed * from the command line and are returned to the application. */ gtk_init (&argc, &argv); /* create a new window */ window = gtk_window_new (GTK_WINDOW_TOPLEVEL); /* When the window is given the "delete-event" signal (this is given * by the window manager, usually by the "close" option, or on the * titlebar), we ask it to call the delete_event () function * as defined above. The data passed to the callback * function is NULL and is ignored in the callback function. */ g_signal_connect (window, "delete-event", G_CALLBACK (destroy), NULL); /* Here we connect the "destroy" event to a signal handler. * This event occurs when we call gtk_widget_destroy() on the window, * or if we return FALSE in the "delete-event" callback. */ g_signal_connect (window, "destroy", G_CALLBACK (destroy), NULL); /* Sets the border width of the window. */ gtk_container_set_border_width (GTK_CONTAINER (window), 10); gtk_window_set_default_size(GTK_WINDOW(window), 500, 500); vbox = gtk_vbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(window), vbox); gtk_container_set_border_width(GTK_CONTAINER(vbox), 4); gtk_widget_show(vbox); text_view = gtk_text_view_new(); //win = gtk_scrolled_window_new(0, 0); gtk_box_pack_start(GTK_BOX(vbox), text_view, TRUE, TRUE, 0); /*gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(win), GTK_SHADOW_IN); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(win), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); gtk_widget_show(win); prefs = WplPidginSettings_createViewAndModel(settings);*/ gtk_container_add(GTK_CONTAINER(window), text_view); //gtk_box_pack_start(GTK_BOX(vbox), text_view, TRUE, TRUE, 0); //gtk_widget_set_has_tooltip ( text_view , true ) ; buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view)); /*g_signal_connect( G_OBJECT (text_view) , "query-tooltip" , G_CALLBACK (querytooltipcb) , (gpointer)settings->wpl) ;*/ gtk_text_buffer_set_text(buffer, "Hallo Tooltip! Rory Gallagher.", -1); //mark = gtk_text_buffer_create_mark(buffer,"tooltip",,TRUE); //gtk_widget_set_tooltip_text(GTK_WIDGET(tag), "Word Tooltip"); gtk_text_view_set_editable (GTK_TEXT_VIEW(text_view), TRUE); //show = gtk_window_new(GTK_WINDOW_TOPLEVEL); //vbox1 = gtk_vbox_new(FALSE, 0); //gtk_container_add(GTK_CONTAINER(vbox), vbox1); //gtk_container_set_border_width(GTK_CONTAINER(vbox1), 4); //gtk_widget_show(vbox1); gtk_widget_show_all(window); //gtk_widget_show_all(show); g_signal_connect(G_OBJECT(text_view), "populate-popup", G_CALLBACK(WikipediaLookup_rightClickPopup), (gpointer)settings->wpl); /* All GTK applications must have a gtk_main(). Control ends here * and waits for an event to occur (like a key press or * mouse event). */ gtk_main (); //g_signal_handlers_disconnect_matched(G_OBJECT(text_view),G_SIGNAL_MATCH_FUNC, 0, 0, NULL, G_CALLBACK(WikipediaLookup_rightClickPopup), NULL); WplPidginSettings_saveToFile(settings); WplPidginSettings_destruct(settings); return 0; }
static int _console(void) { /* FIXME allocate dynamically */ static Console console; PangoFontDescription * desc; GtkWidget * vbox; GtkWidget * menuitem; GtkWidget * menu; GtkToolItem * toolitem; GtkWidget * paned; GtkWidget * widget; desc = pango_font_description_new(); pango_font_description_set_family(desc, "Monospace"); console.window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size(GTK_WINDOW(console.window), 400, 300); gtk_window_set_title(GTK_WINDOW(console.window), "PHP Console"); g_signal_connect_swapped(console.window, "delete-event", G_CALLBACK(_console_on_closex), NULL); vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); /* menu bar */ widget = gtk_menu_bar_new(); /* menu bar: file */ menuitem = gtk_menu_item_new_with_mnemonic("_File"); gtk_menu_shell_append(GTK_MENU_SHELL(widget), menuitem); menu = gtk_menu_new(); gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), menu); menuitem = gtk_menu_item_new_with_mnemonic("_Run"); g_signal_connect_swapped(menuitem, "activate", G_CALLBACK(_console_on_execute), &console); gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); menuitem = gtk_separator_menu_item_new(); gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); menuitem = gtk_menu_item_new_with_mnemonic("C_lear"); g_signal_connect_swapped(menuitem, "activate", G_CALLBACK(_console_on_clear), &console); gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); menuitem = gtk_separator_menu_item_new(); gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); menuitem = gtk_menu_item_new_with_mnemonic("_Close"); g_signal_connect_swapped(menuitem, "activate", G_CALLBACK(_console_on_close), NULL); gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); /* menu bar: help */ menuitem = gtk_menu_item_new_with_mnemonic("_Help"); gtk_menu_shell_append(GTK_MENU_SHELL(widget), menuitem); menu = gtk_menu_new(); gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), menu); menuitem = gtk_menu_item_new_with_mnemonic("_About"); g_signal_connect_swapped(menuitem, "activate", G_CALLBACK(_console_on_about), &console); gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); gtk_box_pack_start(GTK_BOX(vbox), widget, FALSE, TRUE, 0); /* toolbar */ widget = gtk_toolbar_new(); toolitem = gtk_tool_button_new_from_stock(GTK_STOCK_EXECUTE); g_signal_connect_swapped(toolitem, "clicked", G_CALLBACK(_console_on_execute), &console); gtk_toolbar_insert(GTK_TOOLBAR(widget), toolitem, -1); toolitem = gtk_tool_button_new_from_stock(GTK_STOCK_CLEAR); g_signal_connect_swapped(toolitem, "clicked", G_CALLBACK(_console_on_clear), &console); gtk_toolbar_insert(GTK_TOOLBAR(widget), toolitem, -1); gtk_box_pack_start(GTK_BOX(vbox), widget, FALSE, TRUE, 0); /* paned */ paned = gtk_paned_new(GTK_ORIENTATION_VERTICAL); widget = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(widget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); console.code = gtk_text_view_new(); gtk_widget_override_font(console.code, desc); gtk_container_add(GTK_CONTAINER(widget), console.code); gtk_paned_add1(GTK_PANED(paned), widget); widget = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(widget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); console.console = gtk_text_view_new(); gtk_widget_override_font(console.console, desc); gtk_text_view_set_editable(GTK_TEXT_VIEW(console.console), FALSE); gtk_container_add(GTK_CONTAINER(widget), console.console); gtk_paned_add2(GTK_PANED(paned), widget); gtk_paned_set_position(GTK_PANED(paned), 150); gtk_box_pack_start(GTK_BOX(vbox), paned, TRUE, TRUE, 0); /* statusbar */ widget = gtk_statusbar_new(); gtk_box_pack_start(GTK_BOX(vbox), widget, FALSE, TRUE, 0); gtk_container_add(GTK_CONTAINER(console.window), vbox); gtk_widget_show_all(console.window); return 0; }
static GtkWidget *create_window(void) { GtkWidget *startwin; GtkWidget *hlayout; GtkWidget *banner; GtkWidget *vlayout; GtkWidget *tabs; GtkWidget *configvlayout; GtkWidget *configlayout; GtkWidget *vmode3dlabel; GtkWidget *vmode3dcombo; GtkWidget *fullscreencheck; GtkWidget *alwaysshowcheck; GtkWidget *configtab; GtkWidget *messagesscroll; GtkWidget *messagestext; GtkWidget *messagestab; GtkWidget *buttons; GtkWidget *cancelbutton; GtkWidget *cancelbuttonalign; GtkWidget *cancelbuttonlayout; GtkWidget *cancelbuttonicon; GtkWidget *cancelbuttonlabel; GtkWidget *startbutton; GtkWidget *startbuttonalign; GtkWidget *startbuttonlayout; GtkWidget *startbuttonicon; GtkWidget *startbuttonlabel; GtkAccelGroup *accel_group; accel_group = gtk_accel_group_new (); // Basic window startwin = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (startwin), apptitle); // NOTE: use global app title gtk_window_set_position (GTK_WINDOW (startwin), GTK_WIN_POS_CENTER); gtk_window_set_resizable (GTK_WINDOW (startwin), FALSE); gtk_window_set_type_hint (GTK_WINDOW (startwin), GDK_WINDOW_TYPE_HINT_DIALOG); // Horizontal layout of banner and controls hlayout = gtk_hbox_new (FALSE, 0); gtk_widget_show (hlayout); gtk_container_add (GTK_CONTAINER (startwin), hlayout); // Banner { GdkPixbuf *pixbuf = load_banner(); banner = gtk_image_new_from_pixbuf(pixbuf); g_object_unref((gpointer)pixbuf); } gtk_widget_show (banner); gtk_box_pack_start (GTK_BOX (hlayout), banner, FALSE, FALSE, 0); gtk_misc_set_alignment (GTK_MISC (banner), 0.5, 0); // Vertical layout of tab control and start+cancel buttons vlayout = gtk_vbox_new (FALSE, 0); gtk_widget_show (vlayout); gtk_box_pack_start (GTK_BOX (hlayout), vlayout, TRUE, TRUE, 0); // Tab control tabs = gtk_notebook_new (); gtk_widget_show (tabs); gtk_box_pack_start (GTK_BOX (vlayout), tabs, TRUE, TRUE, 0); gtk_container_set_border_width (GTK_CONTAINER (tabs), 4); // Vertical layout of config page main body configvlayout = gtk_vbox_new (FALSE, 0); gtk_widget_show (configvlayout); gtk_container_add (GTK_CONTAINER (tabs), configvlayout); // Fixed-position layout of config page controls configlayout = gtk_fixed_new (); gtk_widget_show (configlayout); gtk_box_pack_start (GTK_BOX (configvlayout), configlayout, TRUE, TRUE, 0); gtk_container_set_border_width (GTK_CONTAINER (configlayout), 6); // 3D video mode label vmode3dlabel = gtk_label_new_with_mnemonic ("_Video mode:"); gtk_widget_show (vmode3dlabel); gtk_fixed_put (GTK_FIXED (configlayout), vmode3dlabel, 0, 0); gtk_widget_set_size_request (vmode3dlabel, 88, 29); gtk_misc_set_alignment (GTK_MISC (vmode3dlabel), 0, 0.5); // 3D video mode combo { GtkListStore *list = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT); GtkCellRenderer *cell; vmode3dcombo = gtk_combo_box_new_with_model (GTK_TREE_MODEL(list)); g_object_unref(G_OBJECT(list)); cell = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(vmode3dcombo), cell, FALSE); gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(vmode3dcombo), cell, "text", 0, NULL); } gtk_widget_show (vmode3dcombo); gtk_fixed_put (GTK_FIXED (configlayout), vmode3dcombo, 88, 0); gtk_widget_set_size_request (vmode3dcombo, 150, 29); gtk_widget_add_accelerator (vmode3dcombo, "grab_focus", accel_group, GDK_V, GDK_MOD1_MASK, GTK_ACCEL_VISIBLE); // Fullscreen checkbox fullscreencheck = gtk_check_button_new_with_mnemonic ("_Fullscreen"); gtk_widget_show (fullscreencheck); gtk_fixed_put (GTK_FIXED (configlayout), fullscreencheck, 248, 0); gtk_widget_set_size_request (fullscreencheck, 85, 29); gtk_widget_add_accelerator (fullscreencheck, "grab_focus", accel_group, GDK_F, GDK_MOD1_MASK, GTK_ACCEL_VISIBLE); // Always show config checkbox alwaysshowcheck = gtk_check_button_new_with_mnemonic ("_Always show configuration on start"); gtk_widget_show (alwaysshowcheck); gtk_box_pack_start (GTK_BOX (configvlayout), alwaysshowcheck, FALSE, FALSE, 0); gtk_widget_add_accelerator (alwaysshowcheck, "grab_focus", accel_group, GDK_A, GDK_MOD1_MASK, GTK_ACCEL_VISIBLE); // Configuration tab configtab = gtk_label_new ("Configuration"); gtk_widget_show (configtab); gtk_notebook_set_tab_label (GTK_NOTEBOOK (tabs), gtk_notebook_get_nth_page (GTK_NOTEBOOK (tabs), 0), configtab); // Messages scrollable area messagesscroll = gtk_scrolled_window_new (NULL, NULL); gtk_widget_show (messagesscroll); gtk_container_add (GTK_CONTAINER (tabs), messagesscroll); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (messagesscroll), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); // Messages text area messagestext = gtk_text_view_new (); gtk_widget_show (messagestext); gtk_container_add (GTK_CONTAINER (messagesscroll), messagestext); gtk_text_view_set_editable (GTK_TEXT_VIEW (messagestext), FALSE); gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (messagestext), GTK_WRAP_WORD); gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (messagestext), FALSE); gtk_text_view_set_left_margin (GTK_TEXT_VIEW (messagestext), 2); gtk_text_view_set_right_margin (GTK_TEXT_VIEW (messagestext), 2); // Messages tab messagestab = gtk_label_new ("Messages"); gtk_widget_show (messagestab); gtk_notebook_set_tab_label (GTK_NOTEBOOK (tabs), gtk_notebook_get_nth_page (GTK_NOTEBOOK (tabs), 1), messagestab); // Dialogue box buttons layout buttons = gtk_hbutton_box_new (); gtk_widget_show (buttons); gtk_box_pack_start (GTK_BOX (vlayout), buttons, FALSE, TRUE, 0); gtk_container_set_border_width (GTK_CONTAINER (buttons), 3); gtk_button_box_set_layout (GTK_BUTTON_BOX (buttons), GTK_BUTTONBOX_END); // Cancel button cancelbutton = gtk_button_new (); gtk_widget_show (cancelbutton); gtk_container_add (GTK_CONTAINER (buttons), cancelbutton); GTK_WIDGET_SET_FLAGS (cancelbutton, GTK_CAN_DEFAULT); gtk_widget_add_accelerator (cancelbutton, "grab_focus", accel_group, GDK_C, GDK_MOD1_MASK, GTK_ACCEL_VISIBLE); gtk_widget_add_accelerator (cancelbutton, "clicked", accel_group, GDK_Escape, 0, GTK_ACCEL_VISIBLE); cancelbuttonalign = gtk_alignment_new (0.5, 0.5, 0, 0); gtk_widget_show (cancelbuttonalign); gtk_container_add (GTK_CONTAINER (cancelbutton), cancelbuttonalign); cancelbuttonlayout = gtk_hbox_new (FALSE, 2); gtk_widget_show (cancelbuttonlayout); gtk_container_add (GTK_CONTAINER (cancelbuttonalign), cancelbuttonlayout); cancelbuttonicon = gtk_image_new_from_stock ("gtk-cancel", GTK_ICON_SIZE_BUTTON); gtk_widget_show (cancelbuttonicon); gtk_box_pack_start (GTK_BOX (cancelbuttonlayout), cancelbuttonicon, FALSE, FALSE, 0); cancelbuttonlabel = gtk_label_new_with_mnemonic ("_Cancel"); gtk_widget_show (cancelbuttonlabel); gtk_box_pack_start (GTK_BOX (cancelbuttonlayout), cancelbuttonlabel, FALSE, FALSE, 0); // Start button startbutton = gtk_button_new (); gtk_widget_show (startbutton); gtk_container_add (GTK_CONTAINER (buttons), startbutton); GTK_WIDGET_SET_FLAGS (startbutton, GTK_CAN_DEFAULT); gtk_widget_add_accelerator (startbutton, "grab_focus", accel_group, GDK_S, GDK_MOD1_MASK, GTK_ACCEL_VISIBLE); gtk_widget_add_accelerator (startbutton, "clicked", accel_group, GDK_Return, 0, GTK_ACCEL_VISIBLE); startbuttonalign = gtk_alignment_new (0.5, 0.5, 0, 0); gtk_widget_show (startbuttonalign); gtk_container_add (GTK_CONTAINER (startbutton), startbuttonalign); startbuttonlayout = gtk_hbox_new (FALSE, 2); gtk_widget_show (startbuttonlayout); gtk_container_add (GTK_CONTAINER (startbuttonalign), startbuttonlayout); startbuttonicon = gtk_image_new_from_stock ("gtk-execute", GTK_ICON_SIZE_BUTTON); gtk_widget_show (startbuttonicon); gtk_box_pack_start (GTK_BOX (startbuttonlayout), startbuttonicon, FALSE, FALSE, 0); startbuttonlabel = gtk_label_new_with_mnemonic ("_Start"); gtk_widget_show (startbuttonlabel); gtk_box_pack_start (GTK_BOX (startbuttonlayout), startbuttonlabel, FALSE, FALSE, 0); // Wire up the signals g_signal_connect ((gpointer) startwin, "delete_event", G_CALLBACK (on_startwin_delete_event), NULL); g_signal_connect ((gpointer) vmode3dcombo, "changed", G_CALLBACK (on_vmode3dcombo_changed), NULL); g_signal_connect ((gpointer) fullscreencheck, "toggled", G_CALLBACK (on_fullscreencheck_toggled), NULL); g_signal_connect ((gpointer) alwaysshowcheck, "toggled", G_CALLBACK (on_alwaysshowcheck_toggled), NULL); g_signal_connect ((gpointer) cancelbutton, "clicked", G_CALLBACK (on_cancelbutton_clicked), NULL); g_signal_connect ((gpointer) startbutton, "clicked", G_CALLBACK (on_startbutton_clicked), NULL); // Associate labels with their controls gtk_label_set_mnemonic_widget (GTK_LABEL (vmode3dlabel), vmode3dcombo); /* Store pointers to all widgets, for use by lookup_widget(). */ GLADE_HOOKUP_OBJECT_NO_REF (startwin, startwin, "startwin"); GLADE_HOOKUP_OBJECT (startwin, hlayout, "hlayout"); GLADE_HOOKUP_OBJECT (startwin, banner, "banner"); GLADE_HOOKUP_OBJECT (startwin, vlayout, "vlayout"); GLADE_HOOKUP_OBJECT (startwin, tabs, "tabs"); GLADE_HOOKUP_OBJECT (startwin, configvlayout, "configvlayout"); GLADE_HOOKUP_OBJECT (startwin, configlayout, "configlayout"); GLADE_HOOKUP_OBJECT (startwin, vmode3dlabel, "vmode3dlabel"); GLADE_HOOKUP_OBJECT (startwin, vmode3dcombo, "vmode3dcombo"); GLADE_HOOKUP_OBJECT (startwin, fullscreencheck, "fullscreencheck"); GLADE_HOOKUP_OBJECT (startwin, alwaysshowcheck, "alwaysshowcheck"); GLADE_HOOKUP_OBJECT (startwin, configtab, "configtab"); GLADE_HOOKUP_OBJECT (startwin, messagesscroll, "messagesscroll"); GLADE_HOOKUP_OBJECT (startwin, messagestext, "messagestext"); GLADE_HOOKUP_OBJECT (startwin, messagestab, "messagestab"); GLADE_HOOKUP_OBJECT (startwin, buttons, "buttons"); GLADE_HOOKUP_OBJECT (startwin, cancelbutton, "cancelbutton"); GLADE_HOOKUP_OBJECT (startwin, cancelbuttonalign, "cancelbuttonalign"); GLADE_HOOKUP_OBJECT (startwin, cancelbuttonlayout, "cancelbuttonlayout"); GLADE_HOOKUP_OBJECT (startwin, cancelbuttonicon, "cancelbuttonicon"); GLADE_HOOKUP_OBJECT (startwin, cancelbuttonlabel, "cancelbuttonlabel"); GLADE_HOOKUP_OBJECT (startwin, startbutton, "startbutton"); GLADE_HOOKUP_OBJECT (startwin, startbuttonalign, "startbuttonalign"); GLADE_HOOKUP_OBJECT (startwin, startbuttonlayout, "startbuttonlayout"); GLADE_HOOKUP_OBJECT (startwin, startbuttonicon, "startbuttonicon"); GLADE_HOOKUP_OBJECT (startwin, startbuttonlabel, "startbuttonlabel"); gtk_window_add_accel_group (GTK_WINDOW (startwin), accel_group); return startwin; }
void dump_text(){ GtkWidget *button; GtkWidget *hbox; GtkWidget *label; GtkWidget *text_scroll; gchar buff[16]; LOG(LOG_DEBUG, "IN : dump_text()"); if(text_dlg == NULL){ text_dlg = gtk_dialog_new(); gtk_window_set_title (GTK_WINDOW (text_dlg), "Text dump"); g_signal_connect(G_OBJECT (text_dlg), "delete_event", G_CALLBACK(text_close), NULL); button = gtk_button_new_with_label(_("Close")); GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); gtk_box_pack_start(GTK_BOX (GTK_DIALOG (text_dlg)->action_area), button, TRUE, TRUE, 0); g_signal_connect(G_OBJECT (button), "clicked", G_CALLBACK(text_close), (gpointer)text_dlg); hbox = gtk_hbox_new(FALSE,5); gtk_box_pack_start (GTK_BOX(GTK_DIALOG(text_dlg)->vbox) , hbox, FALSE, FALSE, 0); label = gtk_label_new(_("page")); gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0); entry_text_page = gtk_entry_new(); gtk_widget_set_size_request(entry_text_page,100,20); gtk_box_pack_start (GTK_BOX(hbox), entry_text_page, FALSE, FALSE, 0); g_signal_connect(G_OBJECT(entry_text_page), "activate", G_CALLBACK(text_dump_page), (gpointer)NULL); label = gtk_label_new(_("offset")); gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0); entry_text_offset = gtk_entry_new(); gtk_widget_set_size_request(entry_text_offset,100,20); gtk_box_pack_start (GTK_BOX(hbox), entry_text_offset, FALSE, FALSE, 0); g_signal_connect(G_OBJECT(entry_text_offset), "activate", G_CALLBACK(text_dump_page), (gpointer)NULL); hbox = gtk_hbox_new(FALSE,5); gtk_box_pack_start (GTK_BOX(GTK_DIALOG(text_dlg)->vbox) , hbox, FALSE, FALSE, 0); text_scroll = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (text_scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_widget_set_size_request(text_scroll, 600, 400); gtk_box_pack_start(GTK_BOX(hbox), text_scroll,FALSE, FALSE, 0); text_buffer = gtk_text_buffer_new (NULL); text_view = gtk_text_view_new_with_buffer(text_buffer); gtk_text_view_set_editable(GTK_TEXT_VIEW(text_view), FALSE); gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text_view), 10); gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text_view), 10); gtk_text_view_set_pixels_above_lines(GTK_TEXT_VIEW(text_view), 3); gtk_text_view_set_pixels_inside_wrap(GTK_TEXT_VIEW(text_view), 3); gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(text_view), FALSE); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text_view), GTK_WRAP_WORD); gtk_widget_set_size_request(text_view, 500, 400); gtk_container_add (GTK_CONTAINER (text_scroll), text_view); gtk_widget_show_all(text_dlg); } if((current_result != NULL) && (current_result->type == RESULT_TYPE_EB)){ sprintf(buff, "%08x",current_result->data.eb.pos_text.page); gtk_entry_set_text(GTK_ENTRY(entry_text_page), buff); sprintf(buff, "%08x",current_result->data.eb.pos_text.offset); gtk_entry_set_text(GTK_ENTRY(entry_text_offset), buff); text_dump_page(NULL, NULL); } LOG(LOG_DEBUG, "OUT : dump_text()"); }
int main(int argc,char **argv) { GtkWidget *win; GtkWidget *vbox; GtkWidget *hbox; GtkWidget *scrolled; GtkWidget *reader; GtkWidget *displayer; GtkWidget *button; GtkWidget *frame; GtkWidget *from; GtkWidget *to; PangoFontDescription *font_name; SelectionData select_data; DuoYiData duoyi_data; TranData tran_data; /*默认使用UTF-8编码*/ setlocale(LC_ALL,""); #ifdef _WIN32 putenv("LANG=zh_CN.UTF-8"); #else setenv("LANG","zh_CN.UTF-8",1); #endif /*读取配置文件,配置文件以json格式存储*/ duoyi_read_config(&duoyi_data); /*if(!g_thread_supported()) g_thread_init(NULL); gdk_threads_init();*/ gtk_init(&argc,&argv); win=gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(win),"多译"); gtk_window_set_position(GTK_WINDOW(win),GTK_WIN_POS_CENTER); gtk_window_set_icon_from_file(GTK_WINDOW(win),"img/64x64/yi.png",NULL); /*设置窗口大小固定*/ gtk_window_set_resizable(GTK_WINDOW(win),FALSE); g_signal_connect(G_OBJECT(win),"delete-event", G_CALLBACK(duoyi_quit),NULL); /*创建两个GtkBox构件用来存放各界面构件*/ vbox=gtk_box_new(GTK_ORIENTATION_VERTICAL,0); hbox=gtk_box_new(GTK_ORIENTATION_HORIZONTAL,0); gtk_container_add(GTK_CONTAINER(win),vbox); /*在状态栏中显示图标*/ tray_create(win); /*reader为读取翻译内容构件,displayer为显示翻译结果构件*/ reader=gtk_text_view_new(); displayer=gtk_text_view_new(); /*创建主菜单*/ create_menu(win,vbox,reader); /*设置显示构件的字体*/ if(duoyi_data.font) { font_name=pango_font_description_from_string(duoyi_data.font); gtk_widget_override_font(reader,font_name); gtk_widget_override_font(displayer,font_name); } gtk_box_pack_start(GTK_BOX(vbox),hbox,FALSE,FALSE,0); /*初始化默认词典*/ select_data.select=duoyi_data.dic; //init_select_data(&select_data,from,to,&duoyi_data); /*创建词典选择界面*/ add_dic_selection(win,hbox,&select_data); //from=create_combox(hbox,"从:"); //to=create_combox(hbox,"翻译到:"); vbox=gtk_box_new(GTK_ORIENTATION_VERTICAL,0); gtk_box_pack_start(GTK_BOX(hbox),vbox,FALSE,FALSE,0); hbox=gtk_box_new(GTK_ORIENTATION_HORIZONTAL,0); gtk_box_pack_start(GTK_BOX(vbox),hbox,FALSE,FALSE,0); /*创建选择语言的下拉框界面*/ from=create_combox(hbox,"从:"); to=create_combox(hbox,"翻译到:"); /*设置SelectionData数据结构其它值*/ init_select_data(&select_data,from,to,&duoyi_data); /*添加一个横向条*/ gtk_box_pack_start(GTK_BOX(vbox), gtk_separator_new(GTK_ORIENTATION_HORIZONTAL), FALSE,FALSE,5); /*给显示构件添加滚动条*/ scrolled=gtk_scrolled_window_new(NULL,NULL); /*设置滚动条自动滚动*/ gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC); //displayer=gtk_text_view_new(); gtk_widget_set_size_request(scrolled,0x260,0x95); /*显示结果构件不可编辑*/ gtk_text_view_set_editable(GTK_TEXT_VIEW(displayer),FALSE); /*设置显示构件自动换行*/ gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(displayer),GTK_WRAP_CHAR); gtk_container_add(GTK_CONTAINER(scrolled),displayer); /*添加边框*/ frame=gtk_frame_new("翻译结果"); gtk_container_add(GTK_CONTAINER(frame),scrolled); gtk_box_pack_start(GTK_BOX(vbox),frame,FALSE,FALSE,0); gtk_container_set_border_width(GTK_CONTAINER(scrolled),0x5); gtk_box_pack_start(GTK_BOX(vbox), gtk_separator_new(GTK_ORIENTATION_HORIZONTAL), FALSE,FALSE,10); /*为读取翻译内容构件设置滚动条并设置自动滚到*/ scrolled=gtk_scrolled_window_new(NULL,NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC); gtk_widget_set_size_request(scrolled,0x260,0x60); //reader=gtk_text_view_new(); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(reader),GTK_WRAP_CHAR); gtk_container_add(GTK_CONTAINER(scrolled),reader); /*添加一个边框*/ frame=gtk_frame_new("输入"); gtk_container_add(GTK_CONTAINER(frame),scrolled); gtk_box_pack_start(GTK_BOX(vbox),frame,FALSE,FALSE,0); gtk_container_set_border_width(GTK_CONTAINER(scrolled),0x5); gtk_container_set_border_width(GTK_CONTAINER(vbox),0x10); gtk_box_pack_start(GTK_BOX(vbox), gtk_separator_new(GTK_ORIENTATION_HORIZONTAL), FALSE,FALSE,10); hbox=gtk_box_new(GTK_ORIENTATION_HORIZONTAL,0); gtk_box_pack_start(GTK_BOX(vbox),hbox,TRUE,TRUE,0); /*清除读取内容按钮*/ button=gtk_button_new_with_label("清空"); gtk_box_pack_end(GTK_BOX(hbox),button,FALSE,FALSE,10); g_signal_connect(G_OBJECT(button),"clicked", G_CALLBACK(duoyi_reader_cleanup),reader); /*从文件加载内容到读取构件按钮*/ button=gtk_button_new_with_label("从文件加载"); gtk_box_pack_end(GTK_BOX(hbox),button,FALSE,FALSE,10); g_signal_connect(G_OBJECT(button),"clicked", G_CALLBACK(duoyi_read_from_file),reader); /*翻译按钮*/ button=gtk_button_new_with_label("翻译"); gtk_box_pack_end(GTK_BOX(hbox),button,TRUE,TRUE,80); tran_data.data=&select_data; tran_data.reader=reader; tran_data.displayer=displayer; g_signal_connect(G_OBJECT(button),"clicked", G_CALLBACK(duoyi_translate),&tran_data); gtk_widget_show_all(win); /*运行程序选择默认词典*/ switch(select_data.select) { case 0: duoyi_baidu_select(NULL,&select_data); break; case 1: duoyi_bing_select(NULL,&select_data); break; case 2: duoyi_king_select(NULL,&select_data); break; case 3: duoyi_youdao_select(NULL,&select_data); break; } //gdk_threads_enter(); gtk_main(); //gdk_threads_leave(); return 0; }
SourceWindow *source_window_create(void) { SourceWindow *sourcewin; GtkWidget *window; GtkWidget *scrolledwin; GtkWidget *text; static PangoFontDescription *font_desc = NULL; static GdkGeometry geometry; debug_print("Creating source window...\n"); sourcewin = g_new0(SourceWindow, 1); window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "sourcewindow"); gtk_window_set_title(GTK_WINDOW(window), _("Source of the message")); gtk_window_set_resizable(GTK_WINDOW(window), TRUE); gtk_widget_set_size_request(window, prefs_common.sourcewin_width, prefs_common.sourcewin_height); if (!geometry.min_height) { geometry.min_width = 400; geometry.min_height = 320; } gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry, GDK_HINT_MIN_SIZE); g_signal_connect(G_OBJECT(window), "size_allocate", G_CALLBACK(source_window_size_alloc_cb), sourcewin); g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(source_window_delete_cb), sourcewin); g_signal_connect(G_OBJECT(window), "key_press_event", G_CALLBACK(key_pressed), sourcewin); gtk_widget_realize(window); scrolledwin = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin), GTK_SHADOW_IN); gtk_container_add(GTK_CONTAINER(window), scrolledwin); gtk_widget_show(scrolledwin); text = gtk_text_view_new(); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR); gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE); if (!font_desc && prefs_common.textfont) font_desc = pango_font_description_from_string (prefs_common.textfont); if (font_desc) gtk_widget_modify_font(text, font_desc); gtk_container_add(GTK_CONTAINER(scrolledwin), text); gtk_widget_show(text); sourcewin->window = window; sourcewin->scrolledwin = scrolledwin; sourcewin->text = text; source_window_init(); return sourcewin; }
/* * show the data in a joined window */ static void gtkui_connection_data_join(void) { GtkWidget *hbox, *vbox, *label, *scrolled, *button, *child; GtkTextIter iter; #define TITLE_LEN (MAX_ASCII_ADDR_LEN * 2) + 6 char src[MAX_ASCII_ADDR_LEN]; char dst[MAX_ASCII_ADDR_LEN]; char title[TITLE_LEN]; DEBUG_MSG("gtk_connection_data_join"); /* if we're switching views, make sure old hook is gone */ conntrack_hook_conn_del(curr_conn, split_print_po); if(data_window) { child = gtk_bin_get_child(GTK_BIN (data_window)); gtk_container_remove(GTK_CONTAINER (data_window), child); textview1 = NULL; textview2 = NULL; splitbuf1 = NULL; splitbuf2 = NULL; endmark1 = NULL; endmark2 = NULL; } else { data_window = gtkui_page_new("Connection data", >kui_destroy_conndata, >kui_connection_data_detach); } /* don't timeout this connection */ curr_conn->flags |= CONN_VIEWING; vbox = gtk_vbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(data_window), vbox); gtk_widget_show(vbox); /* title */ snprintf(title, TITLE_LEN, "%s:%d - %s:%d", ip_addr_ntoa(&curr_conn->L3_addr1, src), ntohs(curr_conn->L4_addr1), ip_addr_ntoa(&curr_conn->L3_addr2, dst), ntohs(curr_conn->L4_addr2)); label = gtk_label_new(title); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); gtk_widget_show(label); /* data */ scrolled = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW (scrolled), GTK_SHADOW_IN); gtk_box_pack_start(GTK_BOX(vbox), scrolled, TRUE, TRUE, 0); gtk_widget_show(scrolled); textview3 = gtk_text_view_new(); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW (textview3), GTK_WRAP_CHAR); gtk_text_view_set_editable(GTK_TEXT_VIEW (textview3), FALSE); gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW (textview3), FALSE); gtk_text_view_set_right_margin(GTK_TEXT_VIEW (textview3), 5); gtk_text_view_set_right_margin(GTK_TEXT_VIEW (textview3), 5); gtk_container_add(GTK_CONTAINER (scrolled), textview3); gtk_widget_show(textview3); joinedbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW (textview3)); gtk_text_buffer_create_tag (joinedbuf, "blue_fg", "foreground", "blue", NULL); gtk_text_buffer_create_tag (joinedbuf, "monospace", "family", "monospace", NULL); gtk_text_buffer_get_end_iter(joinedbuf, &iter); endmark3 = gtk_text_buffer_create_mark(joinedbuf, "end", &iter, FALSE); hbox = gtk_hbox_new(TRUE, 5); gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); gtk_widget_show(hbox); button = gtk_button_new_with_mnemonic("_Split View"); g_signal_connect(G_OBJECT (button), "clicked", G_CALLBACK (gtkui_connection_data_split), NULL); gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); gtk_widget_show(button); button = gtk_button_new_with_mnemonic("_Kill Connection"); g_signal_connect(G_OBJECT (button), "clicked", G_CALLBACK (gtkui_connection_kill_curr_conn), NULL); gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); gtk_widget_show(button); gtk_widget_show(data_window); if(GTK_IS_WINDOW (data_window)) gtk_window_present(GTK_WINDOW (data_window)); else gtkui_page_present(data_window); /* after widgets are drawn, scroll to bottom */ g_timeout_add(500, gtkui_connections_scroll, (gpointer)2); /* print the old data */ connbuf_print(&curr_conn->data, join_print); /* add the hook on the connection to receive data only from it */ conntrack_hook_conn_add(curr_conn, join_print_po); }