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;
}
Пример #2
0
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);
}
Пример #3
0
/* Main Window Initialization */
void init_main_window(const gchar * glade_file)
{
	GladeXML *xml;
	GtkWidget *widget;
	GtkTextBuffer *txtbuf;
	GtkStyle *style;

	xml = glade_xml_new(glade_file, "window1", NULL);
	if (!xml)
		g_error(_("GUI loading failed !\n"));
	glade_xml_signal_autoconnect(xml);

	main_wnd = glade_xml_get_widget(xml, "window1");
	hpaned = glade_xml_get_widget(xml, "hpaned1");
	vpaned = glade_xml_get_widget(xml, "vpaned1");
	tree1_w = glade_xml_get_widget(xml, "treeview1");
	tree2_w = glade_xml_get_widget(xml, "treeview2");
	text_w = glade_xml_get_widget(xml, "textview3");

	back_btn = glade_xml_get_widget(xml, "button1");
	gtk_widget_set_sensitive(back_btn, FALSE);

	widget = glade_xml_get_widget(xml, "show_name1");
	gtk_check_menu_item_set_active((GtkCheckMenuItem *) widget,
				       show_name);

	widget = glade_xml_get_widget(xml, "show_range1");
	gtk_check_menu_item_set_active((GtkCheckMenuItem *) widget,
				       show_range);

	widget = glade_xml_get_widget(xml, "show_data1");
	gtk_check_menu_item_set_active((GtkCheckMenuItem *) widget,
				       show_value);

	save_btn = glade_xml_get_widget(xml, "button3");
	save_menu_item = glade_xml_get_widget(xml, "save1");
	conf_set_changed_callback(conf_changed);

	style = gtk_widget_get_style(main_wnd);
	widget = glade_xml_get_widget(xml, "toolbar1");

#if 0	/* Use stock Gtk icons instead */
	replace_button_icon(xml, main_wnd->window, style,
			    "button1", (gchar **) xpm_back);
	replace_button_icon(xml, main_wnd->window, style,
			    "button2", (gchar **) xpm_load);
	replace_button_icon(xml, main_wnd->window, style,
			    "button3", (gchar **) xpm_save);
#endif
	replace_button_icon(xml, main_wnd->window, style,
			    "button4", (gchar **) xpm_single_view);
	replace_button_icon(xml, main_wnd->window, style,
			    "button5", (gchar **) xpm_split_view);
	replace_button_icon(xml, main_wnd->window, style,
			    "button6", (gchar **) xpm_tree_view);

#if 0
	switch (view_mode) {
	case SINGLE_VIEW:
		widget = glade_xml_get_widget(xml, "button4");
		g_signal_emit_by_name(widget, "clicked");
		break;
	case SPLIT_VIEW:
		widget = glade_xml_get_widget(xml, "button5");
		g_signal_emit_by_name(widget, "clicked");
		break;
	case FULL_VIEW:
		widget = glade_xml_get_widget(xml, "button6");
		g_signal_emit_by_name(widget, "clicked");
		break;
	}
#endif
	txtbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_w));
	tag1 = gtk_text_buffer_create_tag(txtbuf, "mytag1",
					  "foreground", "red",
					  "weight", PANGO_WEIGHT_BOLD,
					  NULL);
	tag2 = gtk_text_buffer_create_tag(txtbuf, "mytag2",
					  /*"style", PANGO_STYLE_OBLIQUE, */
					  NULL);

	gtk_window_set_title(GTK_WINDOW(main_wnd), rootmenu.prompt->text);

	gtk_widget_show(main_wnd);
}
Пример #4
0
/**
 * 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);
}
Пример #5
0
static GtkWidget *
normal_contents (void)
{
  GtkWidget *table;
  GtkWidget *toolbar;
  GtkWidget *handlebox;
  GtkWidget *statusbar;
  GtkWidget *contents;
  GtkWidget *sw;
  GtkItemFactory *item_factory;

  table = gtk_table_new (1, 4, FALSE);

  /* Create the menubar
   */

  item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>", NULL);

  gtk_item_factory_set_translate_func(item_factory,
				      (GtkTranslateFunc)gettext, NULL, NULL);

  /* Set up item factory to go away */
  g_object_ref (item_factory);
  g_object_ref_sink (item_factory);
  g_object_unref (item_factory);
  g_object_set_data_full (G_OBJECT (table),
                          "<main>",
                          item_factory,
                          (GDestroyNotify) g_object_unref);

  /* create menu items */
  gtk_item_factory_create_items (item_factory, G_N_ELEMENTS (menu_items),
                                 menu_items, NULL);

  gtk_table_attach (GTK_TABLE (table),
                    gtk_item_factory_get_widget (item_factory, "<main>"),
                    /* X direction */          /* Y direction */
                    0, 1,                      0, 1,
                    GTK_EXPAND | GTK_FILL,     0,
                    0,                         0);

  /* Create the toolbar
   */
  toolbar = gtk_toolbar_new ();

  GtkToolItem *newButton = gtk_tool_button_new_from_stock(GTK_STOCK_NEW);
  gtk_tool_item_set_tooltip_text(newButton,
				 "Open another one of these windows");
  gtk_toolbar_insert(GTK_TOOLBAR(toolbar),
		     newButton,
		     -1); /*-1 means append to end of toolbar*/

  GtkToolItem *openButton = gtk_tool_button_new_from_stock(GTK_STOCK_OPEN);
  gtk_tool_item_set_tooltip_text(openButton,
				 "This is a demo button with an \'open\' icon");
  gtk_toolbar_insert(GTK_TOOLBAR(toolbar),
		     openButton,
		     -1); /*-1 means append to end of toolbar*/

  GtkToolItem *quitButton = gtk_tool_button_new_from_stock(GTK_STOCK_QUIT);
  gtk_tool_item_set_tooltip_text(quitButton,
				 "This is a demo button with a \'quit\' icon");
  gtk_toolbar_insert(GTK_TOOLBAR(toolbar),
		     quitButton,
		     -1); /*-1 means append to end of toolbar*/


  handlebox = gtk_handle_box_new ();

  gtk_container_add (GTK_CONTAINER (handlebox), toolbar);

  gtk_table_attach (GTK_TABLE (table),
                    handlebox,
                    /* X direction */       /* Y direction */
                    0, 1,                   1, 2,
                    GTK_EXPAND | GTK_FILL,  0,
                    0,                      0);

  /* Create document
   */

  sw = gtk_scrolled_window_new (NULL, NULL);

  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
                                  GTK_POLICY_AUTOMATIC,
                                  GTK_POLICY_AUTOMATIC);

  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
                                       GTK_SHADOW_IN);

  gtk_table_attach (GTK_TABLE (table),
                    sw,
                    /* X direction */       /* Y direction */
                    0, 1,                   2, 3,
                    GTK_EXPAND | GTK_FILL,  GTK_EXPAND | GTK_FILL,
                    0,                      0);

  contents = gtk_text_view_new ();
  gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (contents),
                               PANGO_WRAP_WORD);

  gtk_container_add (GTK_CONTAINER (sw),
                     contents);

  /* Create statusbar */

  statusbar = gtk_statusbar_new ();
  gtk_table_attach (GTK_TABLE (table),
                    statusbar,
                    /* X direction */       /* Y direction */
                    0, 1,                   3, 4,
                    GTK_EXPAND | GTK_FILL,  0,
                    0,                      0);

  gtk_widget_show_all (table);

  return table;
}
Пример #6
0
G_MODULE_EXPORT void
on_options_generate_go_clicked         (GtkButton       *button,
                                        gpointer         user_data)
{
#ifndef _WIN32
	GtkWidget *number = get_widget ("options_generate_number");
	int n = gtk_spin_button_get_value (GTK_SPIN_BUTTON (number));
	char nn[10];
	snprintf (nn, sizeof(nn), "%d", n);
	GtkWidget *view = get_widget ("options_generate_entry");
	GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
	GtkTextIter start, end;
	gtk_text_buffer_get_iter_at_offset (buffer, &start, 0);
	gtk_text_buffer_get_iter_at_offset (buffer, &end, -1);
	char *text = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);

	int wfd[2], rfd[2];
	pid_t cpid;

	if (pipe(wfd) == -1 || pipe(rfd) == -1) {
		perror("pipe");
		exit(EXIT_FAILURE);
	}

	cpid = fork();
	if (cpid == -1) {
		perror("fork");
		exit(EXIT_FAILURE);
	}

	if (cpid == 0) {    /* Child reads from pipe */
		close (wfd[1]);          /* Close unused write end */
		close (rfd[0]);
		dup2 (0, wfd[0]);
		dup2 (1, rfd[1]);
		execlp ("dealer", "dealer", "-v", "-p", nn, NULL);
		perror ("execlp");
		_exit(EXIT_FAILURE);

	} else {
		close (wfd[0]);          /* Close unused read end */
		close (rfd[1]);
		if (write (wfd[1], text, strlen (text)) == -1) {
			perror ("write");
			return;
		}
		close (wfd[1]);          /* Reader will see EOF */
	}

	int i;
	do {
		char buf[100];
		i = read (rfd[0], buf, sizeof (buf));
		buf[i == sizeof (buf) ? sizeof (buf) - 1 : i] = '\0';
		puts (buf);
	} while (i > 0);
	close (rfd[0]);

	g_free (text);
#endif
}
Пример #7
0
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));
}
Пример #8
0
int
main(int argc, char *argv[])
{
    signal_user_data_t *ud;
    GValue *preset;
    GError *error = NULL;
    GOptionContext *context;

#ifdef ENABLE_NLS
    bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
    bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
    textdomain(GETTEXT_PACKAGE);
#endif

    context = g_option_context_new("- Transcode media formats");
    g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE);
    g_option_context_add_group(context, gtk_get_option_group(TRUE));
#if defined(_ENABLE_GST)
    g_option_context_add_group(context, gst_init_get_option_group());
#endif
    g_option_context_parse(context, &argc, &argv, &error);
    if (error != NULL)
    {
        g_warning("%s: %s", G_STRFUNC, error->message);
        g_clear_error(&error);
    }
    g_option_context_free(context);

    if (argc > 1 && dvd_device == NULL && argv[1][0] != '-')
    {
        dvd_device = argv[1];
    }
    
    gtk_init(&argc, &argv);

#if GTK_CHECK_VERSION(3, 0, 0)
    GtkCssProvider *css = gtk_css_provider_new();
    error = NULL;
    gtk_css_provider_load_from_data(css, MyCSS, -1, &error);
    if (error == NULL)
    {
        GdkScreen *ss = gdk_screen_get_default();
        gtk_style_context_add_provider_for_screen(ss, GTK_STYLE_PROVIDER(css),
                                    GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
    }
    else
    {
        g_warning("%s: %s", G_STRFUNC, error->message);
        g_clear_error(&error);
    }
#else
    gtk_rc_parse_string(hud_rcstyle);
#endif

    g_type_class_unref(g_type_class_ref(GTK_TYPE_BUTTON));
    g_object_set(gtk_settings_get_default(), "gtk-button-images", TRUE, NULL);
#if !defined(_WIN32)
    notify_init("HandBrake");
#endif
    ghb_register_transforms();
    ghb_resource_init();
    ghb_load_icons();

#if !defined(_WIN32)
    dbus_g_thread_init();
#endif
    ghb_udev_init();

    ghb_write_pid_file();
    ud = g_malloc0(sizeof(signal_user_data_t));
    ud->debug = ghb_debug;
    g_log_set_handler(NULL, G_LOG_LEVEL_DEBUG, debug_log_handler, ud);
    g_log_set_handler("Gtk", G_LOG_LEVEL_WARNING, warn_log_handler, ud);
    //g_log_set_handler("Gtk", G_LOG_LEVEL_CRITICAL, warn_log_handler, ud);
    ud->settings = ghb_settings_new();
    ud->builder = create_builder_or_die(BUILDER_NAME);
    // Enable events that alert us to media change events
    watch_volumes(ud);

    //GtkWidget *widget = GHB_WIDGET(ud->builder, "PictureDetelecineCustom");
    //gtk_entry_set_inner_border(widget, 2);

    // Since GtkBuilder no longer assigns object ids to widget names
    // Assign a few that are necessary for style overrides to work
    GtkWidget *widget;
#if defined(_NO_UPDATE_CHECK)
    widget = GHB_WIDGET(ud->builder, "check_updates_box");
    gtk_widget_hide(widget);
#endif

    // Must set the names of the widgets that I want to modify
    // style for.
    gtk_widget_set_name(GHB_WIDGET(ud->builder, "preview_event_box"), "preview_event_box");
    gtk_widget_set_name(GHB_WIDGET(ud->builder, "preview_frame"), "preview_frame");
    gtk_widget_set_name(GHB_WIDGET(ud->builder, "live_preview_play"), "live_preview_play");
    gtk_widget_set_name(GHB_WIDGET(ud->builder, "live_preview_progress"), "live_preview_progress");
    gtk_widget_set_name(GHB_WIDGET(ud->builder, "live_encode_progress"), "live_encode_progress");
    gtk_widget_set_name(GHB_WIDGET(ud->builder, "live_duration"), "live_duration");
    gtk_widget_set_name(GHB_WIDGET(ud->builder, "preview_show_crop"), "preview_show_crop");
    gtk_widget_set_name(GHB_WIDGET(ud->builder, "preview_fullscreen"), "preview_fullscreen");
    gtk_widget_set_name(GHB_WIDGET(ud->builder, "hide_settings"), "hide_settings");
    widget = GHB_WIDGET(ud->builder, "preview_hud");
    gtk_widget_set_name(widget, "preview_hud");
    widget = GHB_WIDGET(ud->builder, "preview_window");
    gtk_widget_set_name(widget, "preview_window");

    // Set up the "hud" control overlay for the preview window
    GtkWidget *align, *draw, *hud, *blender;

    align = GHB_WIDGET(ud->builder, "preview_window_alignment");
    draw = GHB_WIDGET(ud->builder, "preview_image_align");
    hud = GHB_WIDGET(ud->builder, "preview_hud");

#if 0 // wGTK_CHECK_VERSION(3, 0, 0)
    // This uses the new GtkOverlay widget.
    //
    // Unfortunately, GtkOverlay is broken in a couple of ways.
    //
    // First, it doesn't respect gtk_widget_shape_combine_region()
    // on it's child overlays.  It appears to just ignore the clip
    // mask of the child.
    //
    // Second, it doesn't respect window opacity.
    //
    // So for now, I'll just continue using my home-grown overlay
    // widget (GhbCompositor).
    blender = gtk_overlay_new();
    gtk_container_add(GTK_CONTAINER(align), blender);
    gtk_container_add(GTK_CONTAINER(blender), draw);
    gtk_widget_set_valign (hud, GTK_ALIGN_END);
    gtk_widget_set_halign (hud, GTK_ALIGN_CENTER);
    gtk_overlay_add_overlay(GTK_OVERLAY(blender), hud);

    g_signal_connect(G_OBJECT(blender), "get-child-position",
                    G_CALLBACK(position_overlay_cb), ud);

    gtk_widget_show(blender);
#else
    // Set up compositing for hud
    blender = ghb_compositor_new();

    gtk_container_add(GTK_CONTAINER(align), blender);
    ghb_compositor_zlist_insert(GHB_COMPOSITOR(blender), draw, 1, 1);
    ghb_compositor_zlist_insert(GHB_COMPOSITOR(blender), hud, 2, .85);
    gtk_widget_show(blender);
#endif

    // Redirect stderr to the activity window
    ghb_preview_init(ud);
    IoRedirect(ud);
    ghb_log( "%s - %s - %s",
        HB_PROJECT_TITLE, HB_PROJECT_BUILD_TITLE, HB_PROJECT_URL_WEBSITE );
    ghb_init_dep_map();

    // Need to connect x264_options textview buffer to the changed signal
    // since it can't be done automatically
    GtkTextView *textview;
    GtkTextBuffer *buffer;
    textview = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "x264Option"));
    buffer = gtk_text_view_get_buffer(textview);
    g_signal_connect(buffer, "changed", (GCallback)x264_entry_changed_cb, ud);

    textview = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "x264OptionExtra"));
    buffer = gtk_text_view_get_buffer(textview);
    g_signal_connect(buffer, "changed", (GCallback)x264_option_changed_cb, ud);

    ghb_combo_init(ud);

    g_debug("ud %p\n", ud);
    g_debug("ud->builder %p\n", ud->builder);

    bind_audio_tree_model(ud);
    bind_subtitle_tree_model(ud);
    bind_presets_tree_model(ud);
    bind_queue_tree_model(ud);
    bind_chapter_tree_model(ud);
    // Connect up the signals to their callbacks
    // I wrote my own connector so that I could pass user data
    // to the callbacks.  Builder's standard autoconnect doesn't all this.
    gtk_builder_connect_signals_full(ud->builder, MyConnect, ud);

    GtkWidget *presetSlider = GHB_WIDGET(ud->builder, "x264PresetSlider");
    const char * const *x264_presets;
    int count = 0;
    x264_presets = hb_x264_presets();
    while (x264_presets && x264_presets[count]) count++;
    gtk_range_set_range(GTK_RANGE(presetSlider), 0, count-1);

    // Load all internal settings
    ghb_settings_init(ud);
    // Load the presets files
    ghb_presets_load(ud);
    ghb_prefs_load(ud);

    ghb_prefs_to_ui(ud);

    gint logLevel;
    logLevel = ghb_settings_get_int(ud->settings, "LoggingLevel");
    ghb_backend_init(logLevel);

    if (ghb_settings_get_boolean(ud->settings, "hbfd"))
    {
        ghb_hbfd(ud, TRUE);
    }
    gchar *source = ghb_settings_get_string(ud->settings, "default_source");
    ghb_dvd_set_current(source, ud);
    g_free(source);

    // Parsing x264 options "" initializes x264 widgets to proper defaults
    ghb_x264_parse_options(ud, "");

    // Populate the presets tree view
    ghb_presets_list_init(ud, NULL, 0);
    // Get the first preset name
    if (arg_preset != NULL)
    {
        preset = ghb_parse_preset_path(arg_preset);
        if (preset)
        {
            ghb_select_preset(ud->builder, preset);
            ghb_value_free(preset);
        }
    }
    else
    {
        ghb_select_default_preset(ud->builder);
    }

    // Grey out widgets that are dependent on a disabled feature
    ghb_check_all_depencencies(ud);

    if (dvd_device != NULL)
    {
        // Source overridden from command line option
        ghb_settings_set_string(ud->settings, "scan_source", dvd_device);
        g_idle_add((GSourceFunc)ghb_idle_scan, ud);
    }
    // Reload and check status of the last saved queue
    g_idle_add((GSourceFunc)ghb_reload_queue, ud);

    // Start timer for monitoring libhb status, 500ms
    g_timeout_add(500, ghb_timer_cb, (gpointer)ud);

    // Add dvd devices to File menu
    ghb_volname_cache_init();
    GHB_THREAD_NEW("Cache Volume Names", (GThreadFunc)ghb_cache_volnames, ud);

#if defined(_USE_APP_IND)
    GtkUIManager * uim = GTK_UI_MANAGER(GHB_OBJECT(ud->builder, "uimanager1"));

    GtkMenu *ai_menu = GTK_MENU(gtk_ui_manager_get_widget(uim, "/ui/tray_menu"));
    ud->ai = app_indicator_new("HandBrake", "hb-icon", APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
    app_indicator_set_menu( ud->ai, ai_menu );
    app_indicator_set_label( ud->ai, "", "99.99%");
    if (ghb_settings_get_boolean(ud->settings, "show_status"))
    {
        app_indicator_set_status( ud->ai, APP_INDICATOR_STATUS_ACTIVE );
    }
    else
    {
        app_indicator_set_status( ud->ai, APP_INDICATOR_STATUS_PASSIVE );
    }
    GtkStatusIcon *si;
    si = GTK_STATUS_ICON(GHB_OBJECT(ud->builder, "hb_status"));

    gtk_status_icon_set_visible(si, FALSE );
#else
    GtkStatusIcon *si;
    si = GTK_STATUS_ICON(GHB_OBJECT(ud->builder, "hb_status"));

    gtk_status_icon_set_visible(si,
            ghb_settings_get_boolean(ud->settings, "show_status"));

#if GTK_CHECK_VERSION(2, 16, 0)
    gtk_status_icon_set_has_tooltip(si, TRUE);
    g_signal_connect(si, "query-tooltip", 
                    status_icon_query_tooltip_cb, ud);
#else
    gtk_status_icon_set_tooltip(si, "HandBrake");
#endif
#endif

    // Ugly hack to keep subtitle table from bouncing around as I change
    // which set of controls are visible
    gint width, height;
#if GTK_CHECK_VERSION(3, 0, 0)
    GtkRequisition min_size, size;
    
    widget = GHB_WIDGET(ud->builder, "SrtCodeset");
    gtk_widget_get_preferred_size( widget, &min_size, &size );
    height = MAX(min_size.height, size.height);
    widget = GHB_WIDGET(ud->builder, "srt_code_label");
    gtk_widget_get_preferred_size( widget, &min_size, &size );
    height += MAX(min_size.height, size.height);
    widget = GHB_WIDGET(ud->builder, "subtitle_table");
    gtk_widget_set_size_request(widget, -1, height);
#else
    GtkRequisition size;
    
    widget = GHB_WIDGET(ud->builder, "SrtCodeset");
    gtk_widget_size_request( widget, &size );
    height = size.height;
    widget = GHB_WIDGET(ud->builder, "srt_code_label");
    gtk_widget_size_request( widget, &size );
    height += size.height;
    widget = GHB_WIDGET(ud->builder, "subtitle_table");
    gtk_widget_set_size_request(widget, -1, height);
#endif
    
    widget = GHB_WIDGET(ud->builder, "hb_window");

    GdkGeometry geo = { 
        -1, -1, 1024, 768, -1, -1, 10, 10, 0, 0, GDK_GRAVITY_NORTH_WEST
    };
    GdkWindowHints geo_mask;
    geo_mask = GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE | GDK_HINT_BASE_SIZE;
    gtk_window_set_geometry_hints( GTK_WINDOW(widget), widget, &geo, geo_mask);
    width = ghb_settings_get_int(ud->settings, "window_width");
    height = ghb_settings_get_int(ud->settings, "window_height");
    gtk_window_resize(GTK_WINDOW(widget), width, height);
    gtk_widget_show(widget);

    /*
     * Filter objects in GtkBuilder xml
     * Unfortunately, GtkFilter is poorly supported by GtkBuilder,
     * so a lot of the setup must happen in code.
        SourceFilterAll
        SourceFilterVideo
        SourceFilterTS
        SourceFilterMPG
        SourceFilterEVO
        SourceFilterVOB
        SourceFilterMKV
        SourceFilterMP4
        SourceFilterAVI
        SourceFilterMOV
        SourceFilterOGG
        SourceFilterFLV
        SourceFilterWMV
    */
    // Add filters to source chooser
    GtkFileFilter *filter;
    GtkFileChooser *chooser;
    chooser = GTK_FILE_CHOOSER(GHB_WIDGET(ud->builder, "source_dialog"));
    filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterAll"));
    gtk_file_filter_set_name(filter, "All");
    gtk_file_filter_add_pattern(filter, "*");
    gtk_file_chooser_add_filter(chooser, filter);
    filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterVideo"));
    gtk_file_filter_set_name(filter, "Video");
    gtk_file_filter_add_mime_type(filter, "video/*");
    gtk_file_chooser_add_filter(chooser, filter);
    filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterTS"));
    gtk_file_filter_set_name(filter, "TS");
    gtk_file_filter_add_pattern(filter, "*.ts");
    gtk_file_filter_add_pattern(filter, "*.TS");
    gtk_file_filter_add_pattern(filter, "*.m2ts");
    gtk_file_filter_add_pattern(filter, "*.M2TS");
    gtk_file_chooser_add_filter(chooser, filter);
    filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterMPG"));
    gtk_file_filter_set_name(filter, "MPG");
    gtk_file_filter_add_pattern(filter, "*.mpg");
    gtk_file_filter_add_pattern(filter, "*.MPG");
    gtk_file_filter_add_pattern(filter, "*.mepg");
    gtk_file_filter_add_pattern(filter, "*.MEPG");
    gtk_file_chooser_add_filter(chooser, filter);
    filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterEVO"));
    gtk_file_filter_set_name(filter, "EVO");
    gtk_file_filter_add_pattern(filter, "*.evo");
    gtk_file_filter_add_pattern(filter, "*.EVO");
    gtk_file_chooser_add_filter(chooser, filter);
    filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterVOB"));
    gtk_file_filter_set_name(filter, "VOB");
    gtk_file_filter_add_pattern(filter, "*.vob");
    gtk_file_filter_add_pattern(filter, "*.VOB");
    gtk_file_chooser_add_filter(chooser, filter);
    filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterMKV"));
    gtk_file_filter_set_name(filter, "MKV");
    gtk_file_filter_add_pattern(filter, "*.mkv");
    gtk_file_filter_add_pattern(filter, "*.MKV");
    gtk_file_chooser_add_filter(chooser, filter);
    filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterMP4"));
    gtk_file_filter_set_name(filter, "MP4");
    gtk_file_filter_add_pattern(filter, "*.mp4");
    gtk_file_filter_add_pattern(filter, "*.MP4");
    gtk_file_filter_add_pattern(filter, "*.m4v");
    gtk_file_filter_add_pattern(filter, "*.M4V");
    gtk_file_chooser_add_filter(chooser, filter);
    filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterMOV"));
    gtk_file_filter_set_name(filter, "MOV");
    gtk_file_filter_add_pattern(filter, "*.mov");
    gtk_file_filter_add_pattern(filter, "*.MOV");
    gtk_file_chooser_add_filter(chooser, filter);
    filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterAVI"));
    gtk_file_filter_set_name(filter, "AVI");
    gtk_file_filter_add_pattern(filter, "*.avi");
    gtk_file_filter_add_pattern(filter, "*.AVI");
    gtk_file_chooser_add_filter(chooser, filter);
    filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterOGG"));
    gtk_file_filter_set_name(filter, "OGG");
    gtk_file_filter_add_pattern(filter, "*.ogg");
    gtk_file_filter_add_pattern(filter, "*.OGG");
    gtk_file_filter_add_pattern(filter, "*.ogv");
    gtk_file_filter_add_pattern(filter, "*.OGV");
    gtk_file_filter_add_pattern(filter, "*.ogm");
    gtk_file_filter_add_pattern(filter, "*.OGM");
    gtk_file_chooser_add_filter(chooser, filter);
    filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterFLV"));
    gtk_file_filter_set_name(filter, "FLV");
    gtk_file_filter_add_pattern(filter, "*.flv");
    gtk_file_filter_add_pattern(filter, "*.FLV");
    gtk_file_chooser_add_filter(chooser, filter);
    filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterWMV"));
    gtk_file_filter_set_name(filter, "WMV");
    gtk_file_filter_add_pattern(filter, "*.wmv");
    gtk_file_filter_add_pattern(filter, "*.WMV");
    gtk_file_chooser_add_filter(chooser, filter);

    // Gtk has a really stupid bug.  If the file chooser is showing
    // hidden files AND there is no filter set, it will not select
    // the filename when gtk_file_chooser_set_filename is called.
    // So add a completely unnessary filter to prevent this behavior.
    filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterAll"));
    gtk_file_chooser_set_filter(chooser, filter);

    PangoFontDescription *font_desc;
    font_desc = pango_font_description_from_string("monospace 10");
    textview = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "activity_view"));
    gtk_widget_modify_font(GTK_WIDGET(textview), font_desc);      
    pango_font_description_free(font_desc);      

    // Everything should be go-to-go.  Lets rock!

    gtk_main();
    gtk_status_icon_set_visible(si, FALSE);
    ghb_backend_close();
    if (ud->queue)
        ghb_value_free(ud->queue);
    ghb_value_free(ud->settings);
    g_io_channel_unref(ud->activity_log);
    ghb_settings_close();
#if !defined(_WIN32)
    notify_uninit();
#endif
    g_free(ud);

    return 0;
}
Пример #9
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;
}
Пример #10
0
static void
edit_properties (SheetItem *object)
{
	GSList *properties;
	PartItem *item;
	Part *part;
	char *internal, *msg;
	GtkBuilder *gui;
	GError *error = NULL;
	GtkGrid *prop_grid;
	GtkNotebook *notebook;
	gint response, y = 0;
	gboolean has_model;
	gchar *model_name = NULL;

	g_return_if_fail (object != NULL);
	g_return_if_fail (IS_PART_ITEM (object));

	item = PART_ITEM (object);
	part = PART (sheet_item_get_data (SHEET_ITEM (item)));

	internal = part_get_property (part, "internal");
	if (internal) {
		if (g_ascii_strcasecmp (internal, "ground") == 0) {
			g_free (internal);
			return;
		}
		if (g_ascii_strcasecmp (internal, "point") == 0) {
			edit_properties_point (item);
			return;
		}
	}

	g_free (internal);

	if ((gui = gtk_builder_new ()) == NULL) {
		oregano_error (_("Could not create part properties dialog."));
		return;
	} 
	else
		 gtk_builder_set_translation_domain (gui, NULL);


	if (gtk_builder_add_from_file (gui, OREGANO_UIDIR "/part-properties-dialog.ui", 
	    &error) <= 0) {
		msg = error->message;
		oregano_error_with_title (_("Could not create part properties dialog."), 
		                          msg);
		g_error_free (error);
		return;
	}

	prop_dialog = g_new0 (PartPropDialog, 1);

	prop_dialog->part_item = item;

	prop_dialog->dialog = GTK_DIALOG (gtk_builder_get_object (gui, 
	                      "part-properties-dialog"));

	prop_grid = GTK_GRID (gtk_builder_get_object (gui, "prop_grid"));
	notebook  = GTK_NOTEBOOK (gtk_builder_get_object (gui, "notebook"));

	g_signal_connect (prop_dialog->dialog, "destroy",
		G_CALLBACK (prop_dialog_destroy),  prop_dialog);

	prop_dialog->widgets = NULL;
	has_model = FALSE;

	for (properties = part_get_properties (part); properties;
		properties = properties->next) {
		Property *prop;
		
		prop = properties->data;

		if (prop->name) {
			GtkWidget *entry;
			GtkWidget *label;
			gchar *temp=NULL;
			
			if (!g_ascii_strcasecmp (prop->name, "internal"))
				continue;

			if (!g_ascii_strcasecmp (prop->name,  "model")) {
				has_model = TRUE;
				model_name = g_strdup (prop->value);
			}
			
			// Find the Refdes and replace by their real value
			temp = prop->name;
			if (!g_ascii_strcasecmp (temp,  "Refdes")) temp = _("Designation");
			if (!g_ascii_strcasecmp (temp,  "Template")) temp  = _("Template");
			if (!g_ascii_strcasecmp (temp,  "Res")) temp  = _("Resistor");
			if (!g_ascii_strcasecmp (temp,  "Cap")) temp  = _("Capacitor");
			if (!g_ascii_strcasecmp (temp,  "Ind")) temp  = _("Inductor");
			label = gtk_label_new (temp);

			entry = gtk_entry_new ();
			gtk_entry_set_text (GTK_ENTRY (entry),  prop->value);
			g_object_set_data (G_OBJECT (entry),  "user",  g_strdup (prop->name));

			gtk_grid_attach (prop_grid, label, 0,y, 1,1);
			
			gtk_grid_attach (prop_grid, entry, 1,y, 1,1);
			
			y++;
			gtk_widget_show (label);
			gtk_widget_show (entry);

			prop_dialog->widgets = g_list_prepend (prop_dialog->widgets, entry);
		}
	}

	if (!has_model) {
		gtk_notebook_remove_page (notebook, 1); 
	} 
	else {
		GtkTextBuffer *txtbuffer;
		GtkTextView *txtmodel;
		gchar *filename, *str;
		GError *read_error = NULL;

		txtmodel = GTK_TEXT_VIEW (gtk_builder_get_object (gui, "txtmodel"));
		txtbuffer = gtk_text_buffer_new (NULL);

		filename = g_strdup_printf ("%s/%s.model", OREGANO_MODELDIR, model_name);
		if (g_file_get_contents (filename, &str, NULL, &read_error)) {
			gtk_text_buffer_set_text (txtbuffer, str, -1);
			g_free (str);
		} 
		else {
			gtk_text_buffer_set_text (txtbuffer, read_error->message, -1);
			g_error_free (read_error);
		}

		g_free (filename);
		g_free (model_name);

		gtk_text_view_set_buffer (txtmodel, txtbuffer);
	}

	gtk_dialog_set_default_response (prop_dialog->dialog, 1);

	response = gtk_dialog_run (prop_dialog->dialog);

	prop_dialog_response (GTK_WIDGET (prop_dialog->dialog), response, prop_dialog);

	g_slist_free_full (properties, g_object_unref);
	gtk_widget_destroy (GTK_WIDGET (prop_dialog->dialog));
}
Пример #11
0
void program_init(void)
{
	GtkWidget *widget;
	StashGroup *group = stash_group_new("program");
	extern gboolean thread_select_on_running;
	extern gboolean thread_select_on_stopped;
	extern gboolean thread_select_on_exited;
	extern gboolean thread_select_follow;

	program_dialog = dialog_connect("program_dialog");
	program_page_vbox = get_widget("program_page_vbox");

	program_exec_entry = GTK_ENTRY(get_widget("program_executable_entry"));
	gtk_entry_set_max_length(program_exec_entry, PATH_MAX);
	stash_group_add_entry(group, &program_executable, "executable", "", program_exec_entry);
	ui_setup_open_button_callback(get_widget("program_executable_button"), NULL,
		GTK_FILE_CHOOSER_ACTION_OPEN, program_exec_entry);

	stash_group_add_entry(group, &program_arguments, "arguments", "",
		get_widget("program_arguments_entry"));
	widget = get_widget("program_environment");
	environment = gtk_text_view_get_buffer(GTK_TEXT_VIEW(widget));
	stash_group_add_string(group, &program_environment, "environment", "");

	working_dir_entry = GTK_ENTRY(get_widget("program_working_dir_entry"));
	gtk_entry_set_max_length(working_dir_entry, PATH_MAX);
	stash_group_add_entry(group, &program_working_dir, "working_dir", "", working_dir_entry);
	ui_setup_open_button_callback(get_widget("program_working_dir_button"), NULL,
		GTK_FILE_CHOOSER_ACTION_OPEN, working_dir_entry);

	load_script_entry = GTK_ENTRY(get_widget("program_load_script_entry"));
	gtk_entry_set_max_length(load_script_entry, PATH_MAX);
	stash_group_add_entry(group, &program_load_script, "load_script", "", load_script_entry);
	ui_setup_open_button_callback(get_widget("program_load_script_button"), NULL,
		GTK_FILE_CHOOSER_ACTION_OPEN, load_script_entry);

	auto_run_exit = get_widget("program_auto_run_exit");
	stash_group_add_toggle_button(group, &program_auto_run_exit, "auto_run_exit", TRUE,
		auto_run_exit);
	stash_group_add_toggle_button(group, &program_non_stop_mode, "non_stop_mode", FALSE,
		get_widget("program_non_stop_mode"));

	temp_breakpoint = get_widget("program_temp_breakpoint");
	stash_group_add_toggle_button(group, &program_temp_breakpoint, "temp_breakpoint", FALSE,
		temp_breakpoint);
	widget = get_widget("program_temp_break_location");
	gtk_entry_set_max_length(GTK_ENTRY(widget), PATH_MAX + 0xFF);
	stash_group_add_entry(group, &program_temp_break_location, "temp_break_location", "",
		widget);
	program_group = group;
	delete_all_items = GTK_TOGGLE_BUTTON(get_widget("program_delete_all_items"));

	g_signal_connect(program_exec_entry, "changed",
		G_CALLBACK(on_program_name_entry_changed), NULL);
	g_signal_connect(load_script_entry, "changed",
		G_CALLBACK(on_program_name_entry_changed), NULL);
	g_signal_connect(temp_breakpoint, "toggled", G_CALLBACK(on_temp_breakpoint_toggled),
		widget);

	import_button = get_widget("program_import");
	g_signal_connect(import_button, "clicked", G_CALLBACK(on_program_import_button_clicked),
		NULL);

	widget = get_widget("program_ok");
	g_signal_connect(widget, "clicked", G_CALLBACK(on_program_ok_button_clicked), NULL);
	gtk_widget_grab_default(widget);

	group = stash_group_new("options");

	stash_group_add_toggle_button(group, &option_open_panel_on_load, "open_panel_on_load",
		TRUE, get_widget("option_open_panel_on_load"));
	stash_group_add_toggle_button(group, &option_open_panel_on_start, "open_panel_on_start",
		TRUE, get_widget("option_open_panel_on_start"));
	stash_group_add_toggle_button(group, &option_update_all_views, "update_all_views", FALSE,
		get_widget("option_update_all_views"));

	stash_group_add_radio_buttons(group, &option_high_bit_mode, "high_bit_mode", HB_7BIT,
		get_widget("option_high_bit_mode_7bit"), HB_7BIT,
		get_widget("option_high_bit_mode_locale"), HB_LOCALE,
		get_widget("option_high_bit_mode_utf8"), HB_UTF8, NULL);

	stash_group_add_toggle_button(group, &option_member_names, "member_names", TRUE,
		get_widget("option_member_names"));
	stash_group_add_toggle_button(group, &option_argument_names, "argument_names", TRUE,
		get_widget("option_argument_names"));
	long_mr_format = GTK_BUTTON(get_widget("option_mr_long_mr_format"));
	stash_group_add_boolean(group, &option_long_mr_format, "long_mr_format", TRUE);
	LONG_MR_FORMAT[FALSE] = _("as _Name=value");
	LONG_MR_FORMAT[TRUE] = _("as _Name = value");
	g_signal_connect(long_mr_format, "clicked", G_CALLBACK(on_long_mr_format_clicked), NULL);

	stash_group_add_toggle_button(group, &option_inspect_expand, "inspect_expand", TRUE,
		get_widget("option_inspect_expand"));
	stash_group_add_spin_button_integer(group, &option_inspect_count, "inspect_count", 100,
		get_widget("option_inspect_count"));

	stash_group_add_toggle_button(group, &option_library_messages, "library_messages", FALSE,
		get_widget("option_library_messages"));
	stash_group_add_toggle_button(group, &option_editor_tooltips, "editor_tooltips", TRUE,
		get_widget("option_editor_tooltips"));
	stash_group_add_boolean(group, &stack_show_address, "stack_show_address", TRUE);
	options_group = group;

	group = stash_group_new("terminal");
#ifdef G_OS_UNIX
	stash_group_add_boolean(group, &terminal_auto_show, "auto_show", FALSE);
	stash_group_add_boolean(group, &terminal_auto_hide, "auto_hide", FALSE);
	stash_group_add_boolean(group, &terminal_show_on_error, "show_on_error", FALSE);
#endif
	terminal_group = group;

	group = stash_group_new("thread");
	stash_group_add_boolean(group, &thread_select_on_running, "select_on_running", FALSE);
	stash_group_add_boolean(group, &thread_select_on_stopped, "select_on_stopped", TRUE);
	stash_group_add_boolean(group, &thread_select_on_exited, "select_on_exited", TRUE);
	stash_group_add_boolean(group, &thread_select_follow, "select_follow", TRUE);
	stash_group_add_boolean(group, &thread_show_group, "show_group", TRUE);
	stash_group_add_boolean(group, &thread_show_core, "show_core", TRUE);
	thread_group = group;

	recent_programs = SCP_TREE_STORE(get_object("recent_program_store"));
	recent_bitmap = 0;
	recent_menu = get_widget("program_recent_menu");
}
Пример #12
0
/**
 * gail_text_util_get_text:
 * @textutil: A #GailTextUtil
 * @layout: A gpointer which is a PangoLayout, a GtkTreeView of NULL
 * @function: An enumeration specifying whether to return the text before, at, or
 *   after the offset.
 * @boundary_type: The boundary type.
 * @offset: The offset of the text in the GailTextUtil 
 * @start_offset: Address of location in which the start offset is returned
 * @end_offset: Address of location in which the end offset is returned
 *
 * This function gets the requested substring from the text in the GtkTextUtil.
 * The layout is used only for getting the text on a line. The value is NULL 
 * for a GtkTextView which is not wrapped, is a GtkTextView for a GtkTextView 
 * which is wrapped and is a PangoLayout otherwise.
 *
 * Returns: the substring requested
 **/
gchar*
gail_text_util_get_text (GailTextUtil    *textutil,
                         gpointer        layout,
                         GailOffsetType  function,
                         AtkTextBoundary boundary_type,
                         gint            offset,
                         gint            *start_offset,
                         gint            *end_offset)
{
  GtkTextIter start, end;
  gint line_number;
  GtkTextBuffer *buffer;

  g_return_val_if_fail (GAIL_IS_TEXT_UTIL (textutil), NULL);

  buffer = textutil->buffer;
  if (buffer == NULL)
    {
      *start_offset = 0;
      *end_offset = 0;
      return NULL;
    }

  if (!gtk_text_buffer_get_char_count (buffer))
    {
      *start_offset = 0;
      *end_offset = 0;
      return g_strdup ("");
    }
  gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);

    
  end = start;

  switch (function)
    {
    case GAIL_BEFORE_OFFSET:
      switch (boundary_type)
        {
        case ATK_TEXT_BOUNDARY_CHAR:
          gtk_text_iter_backward_char(&start);
          break;
        case ATK_TEXT_BOUNDARY_WORD_START:
          if (!gtk_text_iter_starts_word (&start))
            gtk_text_iter_backward_word_start (&start);
          end = start;
          gtk_text_iter_backward_word_start(&start);
          break;
        case ATK_TEXT_BOUNDARY_WORD_END:
          if (gtk_text_iter_inside_word (&start) &&
              !gtk_text_iter_starts_word (&start))
            gtk_text_iter_backward_word_start (&start);
          while (!gtk_text_iter_ends_word (&start))
            {
              if (!gtk_text_iter_backward_char (&start))
                break;
            }
          end = start;
          gtk_text_iter_backward_word_start(&start);
          while (!gtk_text_iter_ends_word (&start))
            {
              if (!gtk_text_iter_backward_char (&start))
                break;
            }
          break;
        case ATK_TEXT_BOUNDARY_SENTENCE_START:
          if (!gtk_text_iter_starts_sentence (&start))
            gtk_text_iter_backward_sentence_start (&start);
          end = start;
          gtk_text_iter_backward_sentence_start (&start);
          break;
        case ATK_TEXT_BOUNDARY_SENTENCE_END:
          if (gtk_text_iter_inside_sentence (&start) &&
              !gtk_text_iter_starts_sentence (&start))
            gtk_text_iter_backward_sentence_start (&start);
          while (!gtk_text_iter_ends_sentence (&start))
            {
              if (!gtk_text_iter_backward_char (&start))
                break;
            }
          end = start;
          gtk_text_iter_backward_sentence_start (&start);
          while (!gtk_text_iter_ends_sentence (&start))
            {
              if (!gtk_text_iter_backward_char (&start))
                break;
            }
          break;
        case ATK_TEXT_BOUNDARY_LINE_START:
          if (layout == NULL)
            {
              line_number = gtk_text_iter_get_line (&start);
              if (line_number == 0)
                {
                  gtk_text_buffer_get_iter_at_offset (buffer,
                    &start, 0);
                }
              else
                {
                  gtk_text_iter_backward_line (&start);
                  gtk_text_iter_forward_line (&start);
                }
              end = start;
              gtk_text_iter_backward_line (&start);
            }
          else if GTK_IS_TEXT_VIEW (layout)
            {
              GtkTextView *view = GTK_TEXT_VIEW (layout);

              gtk_text_view_backward_display_line_start (view, &start);
              end = start;
              gtk_text_view_backward_display_line (view, &start);
            }
          else if (PANGO_IS_LAYOUT (layout))
            get_pango_text_offsets (PANGO_LAYOUT (layout),
                                    buffer,
                                    function,
                                    boundary_type,
                                    offset,
                                    start_offset,
                                    end_offset,
                                    &start,
                                    &end);
          break;
        case ATK_TEXT_BOUNDARY_LINE_END:
          if (layout == NULL)
            {
              line_number = gtk_text_iter_get_line (&start);
              if (line_number == 0)
                {
                  gtk_text_buffer_get_iter_at_offset (buffer,
                    &start, 0);
                  end = start;
                }
              else
                {
                  gtk_text_iter_backward_line (&start);
                  end = start;
                  while (!gtk_text_iter_ends_line (&start))
                    {
                      if (!gtk_text_iter_backward_char (&start))
                        break;
                    }
                  gtk_text_iter_forward_to_line_end (&end);
                }
            }
          else if GTK_IS_TEXT_VIEW (layout)
            {
              GtkTextView *view = GTK_TEXT_VIEW (layout);

              gtk_text_view_backward_display_line_start (view, &start);
              if (!gtk_text_iter_is_start (&start))
                {
                  gtk_text_view_backward_display_line (view, &start);
                  end = start;
                  if (!gtk_text_iter_is_start (&start))
                    {
                      gtk_text_view_backward_display_line (view, &start);
                      gtk_text_view_forward_display_line_end (view, &start);
                    }
                  gtk_text_view_forward_display_line_end (view, &end);
                } 
              else
                {
                  end = start;
                }
            }
          else if (PANGO_IS_LAYOUT (layout))
            get_pango_text_offsets (PANGO_LAYOUT (layout),
                                    buffer,
                                    function,
                                    boundary_type,
                                    offset,
                                    start_offset,
                                    end_offset,
                                    &start,
                                    &end);
          break;
        }
Пример #13
0
void
hybrid_chat_textview_append(GtkWidget *textview, HybridAccount *account,
							HybridBuddy *buddy,	const gchar *message, time_t msg_time)
{
	GtkTextBuffer *recv_tb;
	GtkTextIter end_iter;
	GtkTextIter stop_iter;
	GtkTextIter start_iter;
	GtkTextMark *mark;
	gchar *names;
	const gchar *color;
	const gchar *name;
	struct tm *tm_time;
	gchar time[128];

	g_return_if_fail(textview != NULL);
	g_return_if_fail(message != NULL);

	tm_time = localtime(&msg_time);
	strftime(time, sizeof(time) - 1, _("%H:%M:%S"), tm_time);

	recv_tb  = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
	gtk_text_buffer_get_end_iter(recv_tb, &end_iter);

	gtk_text_view_backward_display_line(GTK_TEXT_VIEW(textview), &end_iter);

	gtk_text_buffer_get_end_iter(recv_tb, &stop_iter);
	gtk_text_buffer_get_start_iter(recv_tb, &start_iter);

	/* first line */
	if (gtk_text_iter_equal(&end_iter, &stop_iter)) {
		gtk_text_buffer_delete(recv_tb, &start_iter, &stop_iter);

	} else {
		gtk_text_buffer_delete(recv_tb, &end_iter, &stop_iter);

		if (!gtk_text_iter_equal(&start_iter, &end_iter)) {
			gtk_text_buffer_insert(recv_tb, &end_iter, "\n", -1);
		}
	}

	gtk_text_buffer_get_end_iter(recv_tb, &end_iter);

	if (!buddy) {
		color = "blue";
		name = account->nickname && *account->nickname ?
				account->nickname : account->username;

	} else {
		color = "green";
		name = buddy->name && *buddy->name ? buddy->name : buddy->id;
	}

	names = g_strdup_printf(" (%s) ", time);

	gtk_text_buffer_insert_with_tags_by_name(recv_tb, &end_iter, 
					names, strlen(names), color, "wrap", NULL);
	g_free(names);

	gtk_text_buffer_insert_with_tags_by_name(recv_tb, &end_iter, 
					name, strlen(name), color, "bold", "wrap", NULL);

	names = _(" said:");

	gtk_text_buffer_insert_with_tags_by_name(recv_tb, &end_iter, 
					names, strlen(names), color, "wrap", NULL);

	gtk_text_buffer_insert(recv_tb, &end_iter, "\n", -1);
	
	gtk_text_buffer_insert_with_tags_by_name(recv_tb, &end_iter, 
					message, strlen(message), "lm10", "wrap", NULL);

	gtk_text_buffer_insert(recv_tb, &end_iter, "\n", -1);
	gtk_text_iter_set_line_offset(&end_iter, 0);

	mark = gtk_text_buffer_get_mark(recv_tb, "scroll");
	gtk_text_buffer_move_mark(recv_tb, mark, &end_iter);
	gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(textview), mark);
}
Пример #14
0
int main(int argc, char **argv)
{
  init_TableDir();
  set_is_chs();
  b_pinyin = is_pinyin_kbm();

  gtk_init (&argc, &argv);
  load_setttings();
  load_gtab_list(TRUE);


#if HIME_i18n_message
  bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
  textdomain(GETTEXT_PACKAGE);
#endif

  pinmd = &inmd[default_input_method];

  if (pinmd->method_type == method_type_TSIN) {
    dbg("is tsin\n");
    pho_load();
    load_tsin_db();
    ph_key_sz = 2;
  } else
  if (pinmd->filename) {
    dbg("gtab filename %s\n", pinmd->filename);
    init_gtab(default_input_method);
    is_gtab = TRUE;
    init_tsin_table_fname(pinmd, gtab_tsin_fname);
    load_tsin_db0(gtab_tsin_fname, TRUE);
  } else
    p_err("Your default input method %s doesn't use phrase database",
      pinmd->cname);

  dbg("ph_key_sz: %d\n", ph_key_sz);

  dpy = GDK_DISPLAY();

  mainwin = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_has_resize_grip(GTK_WINDOW(mainwin), FALSE);
  gtk_window_set_default_size(GTK_WINDOW (mainwin), 640, 520);
  set_window_hime_icon(mainwin);

  GtkWidget *sw = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
                                  GTK_POLICY_AUTOMATIC,
                                  GTK_POLICY_AUTOMATIC);

  GtkWidget *vbox_top = gtk_vbox_new (FALSE, 0);
  gtk_orientable_set_orientation(GTK_ORIENTABLE(vbox_top), GTK_ORIENTATION_VERTICAL);
  gtk_container_add (GTK_CONTAINER(mainwin), vbox_top);

  GtkWidget *view = gtk_text_view_new ();
  gtk_widget_set_hexpand (view, TRUE);
  gtk_widget_set_vexpand (view, TRUE);
  gtk_container_add (GTK_CONTAINER(sw), view);

  gtk_box_pack_start (GTK_BOX (vbox_top), sw, TRUE, TRUE, 0);

  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));

  char *text = _("按滑鼠中鍵, 貼上你要 hime-tslearn 學習的文章。");

  gtk_text_buffer_set_text (buffer, text, -1);

  gtk_text_buffer_create_tag (buffer,
     "blue_background", "background", "blue", "foreground", "white", NULL);

  gtk_text_buffer_create_tag (buffer, "char_wrap",
			      "wrap_mode", GTK_WRAP_CHAR, NULL);

  hbox_buttons = gtk_hbox_new (FALSE, 0);
  gtk_box_pack_start (GTK_BOX (vbox_top), hbox_buttons, FALSE, FALSE, 0);

  GtkWidget *button_parse = gtk_button_new_with_label(_("標示已知詞"));
  gtk_box_pack_start (GTK_BOX (hbox_buttons), button_parse, FALSE, FALSE, 0);
  g_signal_connect (G_OBJECT (button_parse), "clicked",
     G_CALLBACK (cb_button_parse), NULL);

  GtkWidget *button_add = gtk_button_new_with_label(_("新增詞"));
  gtk_box_pack_start (GTK_BOX (hbox_buttons), button_add, TRUE, TRUE, 0);
  g_signal_connect (G_OBJECT (button_add), "clicked",
     G_CALLBACK (cb_button_add), NULL);


  GtkWidget *button_quit = gtk_button_new_from_stock (GTK_STOCK_QUIT);
  gtk_box_pack_start (GTK_BOX (hbox_buttons), button_quit, FALSE, FALSE, 0);
  g_signal_connect (G_OBJECT (button_quit), "clicked",
     G_CALLBACK (do_exit), NULL);


  g_signal_connect (G_OBJECT (mainwin), "delete_event",
                    G_CALLBACK (do_exit), NULL);

  all_wrap();

  gtk_widget_show_all(mainwin);

  gtk_main();
  return 0;
}
Пример #15
0
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);
}
Пример #16
0
void
apply_changed_option (char *option_name)
{
    if (!g_strcmp0 (option_name, "font_name"))
    {
        PangoFontDescription *font_desc;
        font_desc = pango_font_description_from_string (options.font_name);
        int i;
        for (i = 0; i < code_widget_array_size; i++)
            gtk_widget_modify_font (code_widget_array[i]->sourceview, font_desc);

        pango_font_description_free (font_desc);
    }
    else if (!g_strcmp0 (option_name, "font_size"))
    {
    }
    else if(!g_strcmp0 (option_name, "word_wrap"))
    {
        int i;
        GtkWrapMode wrap_mode;
        if (options.word_wrap)
            wrap_mode = GTK_WRAP_WORD;
        else
            wrap_mode = GTK_WRAP_NONE;
        for (i = 0; i < code_widget_array_size; i++)
            gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (code_widget_array[i]->sourceview), wrap_mode);
    }
    else if(!g_strcmp0 (option_name, "highlight_curr_line"))
    {
        int i;
        for (i = 0; i < code_widget_array_size; i++)
            gtk_source_view_set_highlight_current_line (GTK_SOURCE_VIEW (code_widget_array [i]->sourceview), options.highlight_curr_line);
    }
    else if(!g_strcmp0 (option_name, "matching_brace"))
    {
    }
    else if(!g_strcmp0 (option_name, "indentation"))
    {
    }
    else if(!g_strcmp0 (option_name, "indent_width"))
    {
    }
    else if(!g_strcmp0 (option_name, "inc_indent_syms"))
    {
    }
    else if(!g_strcmp0 (option_name, "dec_indent_syms"))
    {
    }
    else if(!g_strcmp0 (option_name, "tab_width"))
    {
    }
    else if(!g_strcmp0 (option_name, "code_folding"))
    {
    }
    else if(!g_strcmp0 (option_name, "fold_comments"))
    {
    }
    else if(!g_strcmp0 (option_name, "fold_classes"))
    {
    }
    else if(!g_strcmp0 (option_name, "fold_functions"))
    {
    }
    else if(!g_strcmp0 (option_name, "code_completion"))
    {
    }
    else if(!g_strcmp0 (option_name, "variable_scoping"))
    {
    }
    else if(!g_strcmp0 (option_name, "line_numbers"))
    {
    }
    else if(!g_strcmp0 (option_name, "line_numbers_font_size"))
    {
    }
    else if(!g_strcmp0 (option_name, "syntax_highlighting"))
    {
    }
}
Пример #17
0
static gboolean dmm_update(void)
{

	GtkTreeIter tree_iter;
	char *name, *device, *channel, *scale, tmp[128];
	gboolean loop, enabled;
	double value;

	GtkTextBuffer *buf;
	GtkTextIter text_iter;

	/* start at the top every time */
	buf = gtk_text_buffer_new(NULL);
	gtk_text_buffer_get_iter_at_offset(buf, &text_iter, 0);

	if (this_page == gtk_notebook_get_current_page(nbook) || plugin_detached) {
		loop = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(channel_list_store), &tree_iter);
		while (loop) {
			gtk_tree_model_get(GTK_TREE_MODEL(channel_list_store), &tree_iter,
					0, &name,
					1, &enabled,
					2, &device,
					3, &channel,
					4, &scale,
					-1);
			if (enabled) {
				struct iio_device *dev =
					get_device(device);
				struct iio_channel *chn =
					get_channel(dev, channel);

				if (iio_channel_find_attr(chn, "raw"))
					value = read_double_attr(chn, "raw");
				else if (iio_channel_find_attr(chn, "processed"))
					value = read_double_attr(chn, "processed");
				else if (iio_channel_find_attr(chn, "input"))
					value = read_double_attr(chn, "input");
				else {
					sprintf(tmp, "skipping %s", name);
					goto dmm_update_next;
				}

				if (iio_channel_find_attr(chn, "offset"))
					value += read_double_attr(chn,
							"offset");
				if (iio_channel_find_attr(chn, "scale"))
					value *= read_double_attr(chn,
							"scale");
				value /= 1000.0;

				if (!strncmp(channel, "voltage", 7))
					sprintf(tmp, "%s = %f Volts\n", name, value);
				else if (!strncmp(channel, "temp", 4))
					sprintf(tmp, "%s = %3.2f °C\n", name, value);
				else
					sprintf(tmp, "%s = %f\n", name, value);

				gtk_text_buffer_insert(buf, &text_iter, tmp, -1);
			}
dmm_update_next:
			loop = gtk_tree_model_iter_next(GTK_TREE_MODEL(channel_list_store), &tree_iter);
		}

		gtk_text_view_set_buffer(GTK_TEXT_VIEW(dmm_results), buf);
		g_object_unref(buf);
	}

	return dmm_update_loop_running;
}
Пример #18
0
void create_note(Note *old_note, ColorScheme *scheme)
{
	GtkWidget *window;
	GtkWidget *vbox;
	GtkWidget *top_hbox;
	GtkWidget *mid_hbox;
	GtkWidget *bottom_bar;
	GtkWidget *bottom_hbox;
	GtkWidget *top_bar;
	GtkWidget *delete_button;
	GdkPixmap *delete_button_pixmap;
	GdkBitmap *delete_button_mask;
	GtkWidget *resize_button;
	GdkPixmap *resize_button_pixmap;
	GdkBitmap *resize_button_mask;
	GtkTextBuffer *text_buffer;

	Note *note;

	note = old_note ? old_note : malloc(sizeof(Note));

	if(!old_note) {
		highest_note_id++;
		note->id = highest_note_id;
		note->scheme = scheme;
	}

	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
	gtk_window_set_default_size(GTK_WINDOW(window), 150, 150);

	if(!old_note) {
		note->text_widget = gtk_text_view_new_with_buffer(NULL);
	}
	text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(note->text_widget));

	note->window = window;

	vbox = gtk_vbox_new(FALSE, 0);
	top_hbox = gtk_hbox_new(FALSE, 0);
	mid_hbox = gtk_hbox_new(FALSE, 0);
	bottom_hbox = gtk_hbox_new(FALSE, 0);
	top_bar = gtk_label_new("");
	note->top_bar_box = gtk_event_box_new();
	gtk_widget_set_size_request(top_bar, -1, 10);
	bottom_bar = gtk_label_new("");
	gtk_widget_set_size_request(bottom_bar, -1, 8);

	delete_button_pixmap = gdk_pixmap_colormap_create_from_xpm_d(NULL, colormap, &delete_button_mask, NULL, delete_button_xpm);
	delete_button = gtk_image_new_from_pixmap(delete_button_pixmap, delete_button_mask);
	note->delete_button_box = gtk_event_box_new();
	gtk_widget_set_size_request(note->delete_button_box, 10, 10);

	resize_button_pixmap = gdk_pixmap_colormap_create_from_xpm_d(NULL, colormap, &resize_button_mask, NULL, resize_button_xpm);
	resize_button = gtk_image_new_from_pixmap(resize_button_pixmap, resize_button_mask);
	note->resize_button_box = gtk_event_box_new();

	set_note_color(note, note->scheme);

	gtk_container_add(GTK_CONTAINER(window), vbox);
	gtk_container_add(GTK_CONTAINER(note->top_bar_box), top_bar);
	gtk_container_add(GTK_CONTAINER(note->delete_button_box), delete_button);
	gtk_container_add(GTK_CONTAINER(note->resize_button_box), resize_button);
	gtk_box_pack_start(GTK_BOX(top_hbox), note->top_bar_box, TRUE, TRUE, 0);
	gtk_box_pack_start(GTK_BOX(top_hbox), note->delete_button_box, FALSE, FALSE, 0);
	gtk_box_pack_start(GTK_BOX(mid_hbox), note->text_widget, TRUE, TRUE, 2);
	gtk_box_pack_start(GTK_BOX(bottom_hbox), bottom_bar, TRUE, TRUE, 0);
	gtk_box_pack_start(GTK_BOX(bottom_hbox), note->resize_button_box, FALSE, FALSE, 0);
	gtk_box_pack_start(GTK_BOX(vbox), top_hbox, FALSE, FALSE, 0);
	gtk_box_pack_start(GTK_BOX(vbox), mid_hbox, TRUE, TRUE, 0);
	gtk_box_pack_start(GTK_BOX(vbox), bottom_hbox, FALSE, FALSE, 0);

	gtk_widget_show_all(window);

	if(old_note) {
		gtk_window_resize(GTK_WINDOW(window), old_note->width, old_note->height);
		gtk_window_move(GTK_WINDOW(window), old_note->x, old_note->y);
	} else {
		gtk_window_get_position(GTK_WINDOW(window), &(note->x), &(note->y));
		gtk_window_get_size(GTK_WINDOW(window), &(note->width), &(note->height));
	}

	g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(delete_note), note);
	g_signal_connect(G_OBJECT(window), "configure-event", G_CALLBACK(note_configure_event), note);
	g_signal_connect(G_OBJECT(note->delete_button_box), "button-press-event", G_CALLBACK(delete_button_pressed), window);
	g_signal_connect(G_OBJECT(note->resize_button_box), "button-press-event", G_CALLBACK(resize_button_pressed), note);
	g_signal_connect(G_OBJECT(text_buffer), "changed", G_CALLBACK(save_note), note);
	g_signal_connect(G_OBJECT(note->top_bar_box), "button-press-event", G_CALLBACK(bar_pressed), note);
	g_signal_connect(G_OBJECT(note->text_widget), "populate-popup", G_CALLBACK(populate_note_popup), note);
}
Пример #19
0
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;
}
Пример #20
0
/* Internal function: write a Latin-1 buffer with length to a stream. */
static void
write_buffer_to_stream(strid_t str, gchar *buf, glui32 len)
{
	switch(str->type)
	{
		case STREAM_TYPE_WINDOW:
			/* Each window type has a different way of printing to it */
			switch(str->window->type)
			{
				/* Printing to these windows' streams does nothing */
				case wintype_Blank:
				case wintype_Pair:
				case wintype_Graphics:
					str->write_count += len;
					break;
					
			    /* Text grid/buffer windows */
			    case wintype_TextGrid:
				{
			        gchar *utf8 = convert_latin1_to_utf8(buf, len);
			        if(utf8 != NULL) {
						/* Deal with newlines */
						int i;
						gchar *line = utf8;
						for(i=0; i<len; i++) {
							if(utf8[i] == '\n') {
								utf8[i] = '\0';
								write_utf8_to_window_buffer(str->window, line);
								flush_window_buffer(str->window);

								/* Move cursor position forward to the next line */
								gdk_threads_enter();
								GtkTextIter cursor_pos;
								GtkTextView *textview = GTK_TEXT_VIEW(str->window->widget);
								GtkTextBuffer *buffer = gtk_text_view_get_buffer(textview);
								GtkTextMark *cursor_mark = gtk_text_buffer_get_mark(buffer, "cursor_position");

							    gtk_text_buffer_get_iter_at_mark( buffer, &cursor_pos, cursor_mark);
								gtk_text_view_forward_display_line(textview, &cursor_pos);
								gtk_text_view_backward_display_line_start(textview, &cursor_pos);
								gtk_text_buffer_move_mark(buffer, cursor_mark, &cursor_pos);
								gdk_threads_leave();

								line = utf8 + (i < len-1 ? (i+1):(len-1));
							}
						}
								
						/* No more newlines left. */
						write_utf8_to_window_buffer(str->window, line);
						g_free(utf8);
					}

					str->write_count += len;
				}
					break;

				case wintype_TextBuffer:
			    {
			        gchar *utf8 = convert_latin1_to_utf8(buf, len);
			        if(utf8 != NULL) {
						write_utf8_to_window_buffer(str->window, utf8);
						g_free(utf8);
					}
				}	
					str->write_count += len;
					break;
				default:
					ILLEGAL_PARAM("Unknown window type: %u", str->window->type);
			}
			
			/* Now write the same buffer to the window's echo stream */
			if(str->window->echo_stream != NULL)
				write_buffer_to_stream(str->window->echo_stream, buf, len);
			
			break;
			
		case STREAM_TYPE_MEMORY:
			if(str->unicode && str->ubuffer)
			{
				int foo = 0;
				while(str->mark < str->buflen && foo < len)
					str->ubuffer[str->mark++] = (unsigned char)buf[foo++];
			}
			if(!str->unicode && str->buffer)
			{
				int copycount = MIN(len, str->buflen - str->mark);
				memmove(str->buffer + str->mark, buf, copycount);
				str->mark += copycount;
			}

			/* Move the EOF marker if we wrote past it */
			if(str->mark > str->endmark)
				str->endmark = str->mark;

			str->write_count += len;
			break;
			
		case STREAM_TYPE_FILE:
			if(str->binary) 
			{
				if(str->unicode) 
				{
					gchar *writebuffer = convert_latin1_to_ucs4be_string(buf, len);
					ensure_file_operation(str, filemode_Write);
					fwrite(writebuffer, sizeof(gchar), len * 4, str->file_pointer);
					g_free(writebuffer);
				} 
				else /* Regular file */
				{
					ensure_file_operation(str, filemode_Write);
					fwrite(buf, sizeof(gchar), len, str->file_pointer);
				}
			}
			else /* Text mode is the same for Unicode and regular files */
			{
				gchar *utf8 = convert_latin1_to_utf8(buf, len);
				if(utf8 != NULL)
				{
					ensure_file_operation(str, filemode_Write);
					g_fprintf(str->file_pointer, "%s", utf8);
					g_free(utf8);
				}
			}
			
			str->write_count += len;
			break;
		case STREAM_TYPE_RESOURCE:
			ILLEGAL(_("Writing to a resource stream is illegal."));
			break;
		default:
			ILLEGAL_PARAM("Unknown stream type: %u", str->type);
	}
}
static GdkWindow *
get_window (GtkSourceGutter *gutter)
{
    return gtk_text_view_get_window (GTK_TEXT_VIEW (gutter->priv->view),
                                     gutter->priv->window_type);
}
Пример #22
0
/* Internal function: flush a window's text buffer to the screen. */
void
flush_window_buffer(winid_t win)
{
#ifdef DEBUG_STYLES
	g_printf("%s\n", win->buffer->str);
#endif
	if(win->type != wintype_TextBuffer && win->type != wintype_TextGrid)
		return;

	if(win->buffer->len == 0)
		return;

	gdk_threads_enter();

	GtkTextBuffer *buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(win->widget) );

	switch(win->type) {
	case wintype_TextBuffer:
	{
		GtkTextIter start, end;
		gtk_text_buffer_get_end_iter(buffer, &end);
		gint start_offset;

		start_offset = gtk_text_iter_get_offset(&end);
		gtk_text_buffer_insert(buffer, &end, win->buffer->str, -1);
		gtk_text_buffer_get_iter_at_offset(buffer, &start, start_offset);
		style_apply(win, &start, &end);

		ChimaraGlk *glk = CHIMARA_GLK(gtk_widget_get_ancestor(win->widget, CHIMARA_TYPE_GLK));
		g_assert(glk);
		g_signal_emit_by_name(glk, "text-buffer-output", win->rock, win->librock, win->buffer->str);
	}
		break;

	case wintype_TextGrid:
	{
		/* Number of characters to insert */
		glong length = win->buffer->len;
		glong chars_left = length;
		
		GtkTextMark *cursor = gtk_text_buffer_get_mark(buffer, "cursor_position");
		
		/* Get cursor position */
		GtkTextIter start, insert;
		gint start_offset;

		gtk_text_buffer_get_iter_at_mark(buffer, &insert, cursor);

		while(chars_left > 0 && !gtk_text_iter_is_end(&insert))
		{
			/* Spaces available on this line */
			gint available_space = win->width - gtk_text_iter_get_line_offset(&insert);
		
			GtkTextIter end = insert;
			if(chars_left <= available_space)
				gtk_text_iter_forward_chars(&end, chars_left);
			else
				gtk_text_iter_forward_to_line_end(&end);

			gtk_text_buffer_delete(buffer, &insert, &end);

			start_offset = gtk_text_iter_get_offset(&insert);
			gtk_text_buffer_insert(buffer, &insert, win->buffer->str + (length - chars_left), MIN(chars_left, available_space));
			gtk_text_buffer_get_iter_at_offset(buffer, &start, start_offset);
			style_apply(win, &start, &insert);
			
			chars_left -= available_space;

			if(gtk_text_iter_get_line_offset(&insert) >= win->width)
				gtk_text_iter_forward_line(&insert);
		}

		gtk_text_buffer_move_mark(buffer, cursor, &insert);
	}
		break;
	}

	gdk_threads_leave();

	g_string_truncate(win->buffer, 0);
}
Пример #23
0
/*
 * Pops up a dialog containing a list of warnings.
 *
 * This is because their can be many warnings (eg while you are away) and popping up 
 * hundreds of windows is ugly.
 */
static void
balsa_information_list(GtkWindow *parent, LibBalsaInformationType type,
                       const char *msg)
{
    static GtkWidget *information_list = NULL;
    GtkTextBuffer *buffer;
    GtkTextIter iter;

    if (information_list == NULL) {
	GtkWidget *information_dialog;
	GtkWidget *scrolled_window;

	information_dialog =
	    gtk_dialog_new_with_buttons(_("Information — Balsa"), 
                                        parent,
                                        GTK_DIALOG_DESTROY_WITH_PARENT |
                                        libbalsa_dialog_flags(),
                                        _("_Clear"), GTK_RESPONSE_APPLY,
                                        _("Cl_ose"), GTK_RESPONSE_CANCEL,
                                        NULL);
#if HAVE_MACOSX_DESKTOP
	libbalsa_macosx_menu_for_parent(information_dialog, parent);
#endif
	/* Default is to close */
	gtk_dialog_set_default_response(GTK_DIALOG(information_dialog), 
                                        GTK_RESPONSE_CANCEL);

	/* Reset the policy gtk_dialog_new makes itself non-resizable */
	gtk_window_set_resizable(GTK_WINDOW(information_dialog), TRUE);
	gtk_window_set_default_size(GTK_WINDOW(information_dialog), 350, 200);
	gtk_window_set_role(GTK_WINDOW(information_dialog), "Information");

        g_object_add_weak_pointer(G_OBJECT(information_dialog),
                                  (gpointer *) &information_list);

	/* A scrolled window for the list. */
	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_box_pack_start(GTK_BOX
                           (gtk_dialog_get_content_area
                            (GTK_DIALOG(information_dialog))),
                           scrolled_window, TRUE, TRUE, 1);
	gtk_container_set_border_width(GTK_CONTAINER(scrolled_window), 6);
	gtk_widget_show(scrolled_window);

	/* The list itself */
	information_list = balsa_information_list_new();
	gtk_container_add(GTK_CONTAINER(scrolled_window),
			  information_list);
        g_signal_connect(G_OBJECT(information_dialog), "response",
                         G_CALLBACK(balsa_information_list_response_cb),
                         information_list);

	gtk_widget_show_all(information_dialog);
    }

    buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(information_list));
    gtk_text_buffer_get_end_iter(buffer, &iter);
    gtk_text_buffer_place_cursor(buffer, &iter);
    if (gtk_text_buffer_get_char_count(buffer))
        gtk_text_buffer_insert_at_cursor(buffer, "\n", 1);
    gtk_text_buffer_insert_at_cursor(buffer, msg, -1);
    gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(information_list),
                                 gtk_text_buffer_get_insert(buffer),
                                 0, FALSE, 0, 0);

    if (balsa_app.main_window) {
        gchar *line;
        GtkStatusbar *statusbar;
        guint context_id;

        statusbar = GTK_STATUSBAR(balsa_app.main_window->statusbar);
        context_id = gtk_statusbar_get_context_id(statusbar, "Information list");
        gtk_statusbar_pop(statusbar, context_id);

        line = g_strdup(msg);
        g_strdelimit(line, "\r\n", ' ');
        gtk_statusbar_push(statusbar, context_id, line);
        g_free(line);
    }
}
Пример #24
0
/**
 * Clear the text from the text page.
 */
static void text_page_clear(GtkWidget *page)
{
  GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(g_object_get_data(G_OBJECT(page), TEXT_KEY)));

  gtk_text_buffer_set_text(buf, "", 0);
}
Пример #25
0
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;
}
Пример #26
0
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;
}
Пример #27
0
// append a string to the WarlockView
// string needs to be valid UTF-8, and gets mangled, sorry.
static void
view_append (WarlockView *view, WString *string)
{
        GtkTextIter iter;
        GtkTextBuffer *buffer;
        GtkTextIter start, end;
        GList *list_current;
        GdkRectangle rect;
        int y, height;
        gboolean scroll;

        g_assert (view != NULL);

        buffer = view->text_buffer;
        list_current = NULL;

        // Get the end of the buffer
        gtk_text_buffer_get_end_iter (buffer, &iter);

        // test if we should scroll
        gtk_text_view_get_visible_rect (GTK_TEXT_VIEW (view->text_view), &rect);
        gtk_text_view_get_line_yrange (GTK_TEXT_VIEW(view->text_view), &iter,
                        &y, &height);
        if(((y + height) - (rect.y + rect.height)) > height){
                scroll = FALSE;
	} else {
                scroll = TRUE;
        }

        // highlighting stuff
        highlight_match (string);

        // FIXME the following lines should be done through hooks

        // script stuff
        script_match_string (string->string->str);

	// log it
	warlock_log (string->string->str);

        // Put the mark there that will stay in the same place when we insert
        // text as a reference for highlighting
        gtk_text_buffer_move_mark (buffer, view->mark, &iter);

        gtk_text_buffer_insert (buffer, &iter, string->string->str, -1);

        // markup the buffer with the tags from our string
        for (list_current = string->highlights; list_current != NULL;
                        list_current = list_current->next) {
                WHighlight *tmp = list_current->data;
                debug ("tag: %s offset: %d length: %d\n", tmp->tag_name,
                                tmp->offset, tmp->length);
                gtk_text_buffer_get_iter_at_mark (buffer, &start, view->mark);
                gtk_text_iter_forward_chars (&start, tmp->offset);
                end = start;
                gtk_text_iter_forward_chars (&end, tmp->length);
                gtk_text_buffer_apply_tag_by_name (buffer, tmp->tag_name,
                                &start, &end);
        }

        if (scroll) {
                // scroll the end mark on the screen.
                gtk_text_iter_set_line_offset (&iter, 0);
                gtk_text_buffer_move_mark (buffer, view->mark, &iter);
                gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (view->text_view),
                                view->mark, 0, TRUE, 1.0, 0.0);
        }

        // Cut off beginning lines that don't fit in the buffer.
        warlock_view_trim (view);

	if (view == main_view)
		prompting = FALSE;
}
Пример #28
0
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);

}
Пример #29
0
void
modeline_parser_apply_modeline (GtkSourceView *view)
{
	ModelineOptions options;
	GtkTextBuffer *buffer;
	GtkTextIter iter, liter;
	gint line_count;
	
	options.language_id = NULL;
	options.set = MODELINE_SET_NONE;

	buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
	gtk_text_buffer_get_start_iter (buffer, &iter);

	line_count = gtk_text_buffer_get_line_count (buffer);

	/* Parse the modelines on the 10 first lines... */
	while ((gtk_text_iter_get_line (&iter) < 10) &&
	       !gtk_text_iter_is_end (&iter))
	{
		gchar *line;

		liter = iter;
		gtk_text_iter_forward_to_line_end (&iter);
		line = gtk_text_buffer_get_text (buffer, &liter, &iter, TRUE);

		parse_modeline (line,
				1 + gtk_text_iter_get_line (&iter),
				line_count,
				&options);

		gtk_text_iter_forward_line (&iter);

		g_free (line);
	}

	/* ...and on the 10 last ones (modelines are not allowed in between) */
	if (!gtk_text_iter_is_end (&iter))
	{
		gint cur_line;
		guint remaining_lines;

		/* we are on the 11th line (count from 0) */
		cur_line = gtk_text_iter_get_line (&iter);
		/* g_assert (10 == cur_line); */

		remaining_lines = line_count - cur_line - 1;

		if (remaining_lines > 10)
		{
			gtk_text_buffer_get_end_iter (buffer, &iter);
			gtk_text_iter_backward_lines (&iter, 9);
		}
	}

	while (!gtk_text_iter_is_end (&iter))
	{
		gchar *line;

		liter = iter;
		gtk_text_iter_forward_to_line_end (&iter);
		line = gtk_text_buffer_get_text (buffer, &liter, &iter, TRUE);

		parse_modeline (line,
				1 + gtk_text_iter_get_line (&iter),
				line_count,
				&options);

		gtk_text_iter_forward_line (&iter);

		g_free (line);
	}

	/* Try to set language */
	if (has_option (&options, MODELINE_SET_LANGUAGE) && options.language_id)
	{
		GtkSourceLanguageManager *manager;
		GtkSourceLanguage *language;

		manager = pluma_get_language_manager ();
		language = gtk_source_language_manager_get_language
				(manager, options.language_id);

		if (language != NULL)
		{
			gtk_source_buffer_set_language (GTK_SOURCE_BUFFER (buffer),
							language);
		}
	}

	ModelineOptions *previous = g_object_get_data (G_OBJECT (buffer), 
	                                               MODELINE_OPTIONS_DATA_KEY);

	/* Apply the options we got from modelines and restore defaults if
	   we set them before */
	if (has_option (&options, MODELINE_SET_INSERT_SPACES))
	{
		gtk_source_view_set_insert_spaces_instead_of_tabs
							(view, options.insert_spaces);
	}
	else if (check_previous (view, previous, MODELINE_SET_INSERT_SPACES))
	{
		gtk_source_view_set_insert_spaces_instead_of_tabs
							(view,
							 pluma_prefs_manager_get_insert_spaces ());
	}
	
	if (has_option (&options, MODELINE_SET_TAB_WIDTH))
	{
		gtk_source_view_set_tab_width (view, options.tab_width);
	}
	else if (check_previous (view, previous, MODELINE_SET_TAB_WIDTH))
	{
		gtk_source_view_set_tab_width (view, 
		                               pluma_prefs_manager_get_tabs_size ());
	}
	
	if (has_option (&options, MODELINE_SET_INDENT_WIDTH))
	{
		gtk_source_view_set_indent_width (view, options.indent_width);
	}
	else if (check_previous (view, previous, MODELINE_SET_INDENT_WIDTH))
	{
		gtk_source_view_set_indent_width (view, -1);
	}
	
	if (has_option (&options, MODELINE_SET_WRAP_MODE))
	{
		gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), options.wrap_mode);
	}
	else if (check_previous (view, previous, MODELINE_SET_WRAP_MODE))
	{
		gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), 
		                             pluma_prefs_manager_get_wrap_mode ());
	}
	
	if (has_option (&options, MODELINE_SET_RIGHT_MARGIN_POSITION))
	{
		gtk_source_view_set_right_margin_position (view, options.right_margin_position);
	}
	else if (check_previous (view, previous, MODELINE_SET_RIGHT_MARGIN_POSITION))
	{
		gtk_source_view_set_right_margin_position (view, 
		                                           pluma_prefs_manager_get_right_margin_position ());
	}
	
	if (has_option (&options, MODELINE_SET_SHOW_RIGHT_MARGIN))
	{
		gtk_source_view_set_show_right_margin (view, options.display_right_margin);
	}
	else if (check_previous (view, previous, MODELINE_SET_SHOW_RIGHT_MARGIN))
	{
		gtk_source_view_set_show_right_margin (view, 
		                                       pluma_prefs_manager_get_display_right_margin ());
	}
	
	if (previous)
	{
		*previous = options;
		previous->language_id = g_strdup (options.language_id);
	}
	else
	{
		previous = g_slice_new (ModelineOptions);
		*previous = options;
		previous->language_id = g_strdup (options.language_id);
		
		g_object_set_data_full (G_OBJECT (buffer), 
		                        MODELINE_OPTIONS_DATA_KEY, 
		                        previous,
		                        (GDestroyNotify)free_modeline_options);
	}
	
	g_free (options.language_id);
}
Пример #30
0
gint
main (gint argc, gchar **argv)
{
  GtkWidget *window, *main_box, *container, *child;
  GtkWidget *box, *toolbar;
  GtkStyleProvider *provider;
  GtkTextBuffer *css;
  
  gtk_init (&argc, &argv);

  css = gtk_text_buffer_new (NULL);
  gtk_text_buffer_create_tag (css,
                              "warning",
                              "background", "rgba(255,255,0,0.3)",
                              NULL);
  gtk_text_buffer_create_tag (css,
                              "error",
                              "background", "rgba(255,0,0,0.3)",
                              NULL);

  provider = GTK_STYLE_PROVIDER (gtk_css_provider_new ());
  gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
                                             provider,
                                             GTK_STYLE_PROVIDER_PRIORITY_FORCE);
  
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

  g_signal_connect (window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
  g_signal_connect (window, "delete_event", G_CALLBACK (gtk_main_quit), NULL);

  main_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
  gtk_container_add (GTK_CONTAINER (window), main_box);

  toolbar = gtk_toolbar_new ();
  gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_TEXT);
  gtk_box_pack_start (GTK_BOX (main_box), toolbar, FALSE, TRUE, 0);

  box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
  gtk_box_pack_start (GTK_BOX (main_box), box, FALSE, TRUE, 0);

  container = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_min_content_width (GTK_SCROLLED_WINDOW (container), 200);
  gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (container), 200);
  gtk_box_pack_start (GTK_BOX (main_box), container, TRUE, TRUE, 0);
  child = gtk_text_view_new_with_buffer (css);
  gtk_container_add (GTK_CONTAINER (container), child);
  g_signal_connect (css,
                    "changed",
                    G_CALLBACK (css_text_changed),
                    provider);
  gtk_text_buffer_set_text (css,
                            DEFAULT_CSS,
                            -1);
  g_signal_connect (provider,
                    "parsing-error",
                    G_CALLBACK (show_parsing_error),
                    gtk_text_view_get_buffer (GTK_TEXT_VIEW (child)));

  container = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
  gtk_box_pack_start (GTK_BOX (main_box), container, FALSE, TRUE, 0);
  child = gtk_switch_new ();
  gtk_switch_set_active (GTK_SWITCH (child), gtk_widget_get_default_direction () == GTK_TEXT_DIR_LTR);
  g_signal_connect (child,
                    "notify::active",
                    G_CALLBACK (set_orientation),
                    NULL);
  gtk_box_pack_start (GTK_BOX (container), child, FALSE, FALSE, 0);
  child = gtk_label_new ("left-to-right");
  gtk_box_pack_start (GTK_BOX (container), child, FALSE, FALSE, 0);
  child = gtk_button_new_with_label ("Add button");
  g_signal_connect_swapped (child,
                            "clicked",
                            G_CALLBACK (add_button),
                            box);
  gtk_box_pack_end (GTK_BOX (container), child, FALSE, FALSE, 0);
  child = gtk_button_new_with_label ("Add toolbutton");
  g_signal_connect_swapped (child,
                            "clicked",
                            G_CALLBACK (add_toolbutton),
                            toolbar);
  gtk_box_pack_end (GTK_BOX (container), child, FALSE, FALSE, 0);

  add_toolbutton (GTK_TOOLBAR (toolbar));
  add_toolbutton (GTK_TOOLBAR (toolbar));
  add_toolbutton (GTK_TOOLBAR (toolbar));
  add_toolbutton (GTK_TOOLBAR (toolbar));

  add_button (GTK_BOX (box));
  add_button (GTK_BOX (box));
  add_button (GTK_BOX (box));
  add_button (GTK_BOX (box));

  gtk_widget_show_all (window);

  gtk_main ();
  
  return 0;
}