Beispiel #1
0
/**
 * 插入图片到输入缓冲区.
 * @param dlgpr 对话框类
 */
void DialogPeer::InsertPicture(DialogPeer *dlgpr)
{
        GtkWidget *widget, *window;
        GtkTextBuffer *buffer;
        GtkTextIter iter;
        GdkPixbuf *pixbuf;
        gchar *filename;
        gint position;

        window = GTK_WIDGET(g_datalist_get_data(&dlgpr->widset, "window-widget"));
        if (!(filename = choose_file_with_preview(
                 _("Please select a picture to insert the buffer"), window)))
                return;

        if (!(pixbuf = gdk_pixbuf_new_from_file(filename, NULL))) {
                g_free(filename);
                return;
        }
        g_free(filename);

        widget = GTK_WIDGET(g_datalist_get_data(&dlgpr->widset,
                                         "input-textview-widget"));
        buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(widget));
        g_object_get(buffer, "cursor-position", &position, NULL);
        gtk_text_buffer_get_iter_at_offset(buffer, &iter, position);
        gtk_text_buffer_insert_pixbuf(buffer, &iter, pixbuf);
        g_object_unref(pixbuf);
}
Beispiel #2
0
void interface_image_add(GtkWidget * tab, GtkTextIter * iter,
       GdkPixbuf * pixbuf)
{
  if (pixbuf == NULL)
    return;
  GtkTextView *out1 = GTK_TEXT_VIEW(interface_get_widget(tab, "output1"));
  GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(out1));

  GtkTextIter it;
  if (iter != NULL)
    it = *iter;
  else
    gtk_text_buffer_get_end_iter(buffer, &it);

  gtk_text_buffer_insert_pixbuf(buffer, &it, pixbuf);
  
  // append tag name, if needed
  SESSION_STATE *session = g_object_get_data(G_OBJECT(tab), "session");
  if (!session->imagemapName) return;
  
  GtkTextTag *t = gtk_text_tag_new (session->imagemapName);
  g_object_set_data(G_OBJECT(t), "imagemap",
                    g_strdup(session->imagemapName));

  GtkTextTagTable *table =
      gtk_text_buffer_get_tag_table(buffer);
  gtk_text_tag_table_add(table, t);
  gtk_text_buffer_apply_tag(buffer, t, &it, &it);
  g_signal_connect(G_OBJECT(t), "event",
                   G_CALLBACK(on_tag_click), session);
}
static void
chat_text_view_insert_text_with_emoticons (EmpathyChatTextView *view,
					   GtkTextIter         *iter,
					   const gchar         *str)
{
	EmpathyChatTextViewPriv *priv = GET_PRIV (view);
	gboolean                 use_smileys = FALSE;
	GSList                  *smileys, *l;

	empathy_conf_get_bool (empathy_conf_get (),
			       EMPATHY_PREFS_CHAT_SHOW_SMILEYS,
			       &use_smileys);

	if (!use_smileys) {
		gtk_text_buffer_insert (priv->buffer, iter, str, -1);
		return;
	}

	smileys = empathy_smiley_manager_parse (priv->smiley_manager, str);
	for (l = smileys; l; l = l->next) {
		EmpathySmiley *smiley;

		smiley = l->data;
		if (smiley->pixbuf) {
			gtk_text_buffer_insert_pixbuf (priv->buffer, iter, smiley->pixbuf);
		} else {
			gtk_text_buffer_insert (priv->buffer, iter, smiley->str, -1);
		}
		empathy_smiley_free (smiley);
	}
	g_slist_free (smileys);
}
static void
load_images(MarkdownTextView * self)
{
    GtkTextBuffer *buffer;
    GtkTextIter iter;
    GSList *tags, *tagp;
    gchar *image_path;
    
    buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(self));
    gtk_text_buffer_get_start_iter(buffer, &iter);
    
    do {
       tags = gtk_text_iter_get_tags(&iter);
       for (tagp = tags; tagp != NULL; tagp = tagp->next) {
           GtkTextTag *tag = tagp->data;
           gint is_underline = 0;
           gchar *lang = NULL;

           g_object_get(G_OBJECT(tag),
                        "underline", &is_underline,
                        "language", &lang,
                        NULL);

           if (is_underline == 2 && lang) {
               GdkPixbuf *pixbuf;
               gchar *path;
               
               image_path = egg_markdown_get_link_uri(self->markdown, atoi(lang));
               path = g_build_filename(self->image_directory, image_path, NULL);
               pixbuf = gdk_pixbuf_new_from_file(path, NULL);
               if (pixbuf) {
                   GtkTextMark *mark;
                   GtkTextIter start;

                   mark = gtk_text_buffer_create_mark(buffer, NULL, &iter, FALSE);
                   
                   gtk_text_buffer_get_iter_at_mark(buffer, &start, mark);
                   gtk_text_iter_forward_to_tag_toggle(&iter, tag);
                   gtk_text_buffer_delete(buffer, &start, &iter);

                   gtk_text_buffer_insert_pixbuf(buffer, &iter, pixbuf);
  
                   g_object_unref(pixbuf);
                   gtk_text_buffer_delete_mark(buffer, mark);
               }
               
               g_free(image_path);
               g_free(lang);
               g_free(path);
               break;
           }

           g_free(lang);
       }
       
       if (tags)
           g_slist_free(tags);
   } while (gtk_text_iter_forward_to_tag_toggle(&iter, NULL));
}
Beispiel #5
0
void gglk_textbuffer_put_image(GglkTextBuffer *tb,
			       GdkPixbuf *pic, glui32 align)
{
    int line_height = tb->base.yunits;
    int height = gdk_pixbuf_get_height(pic);

    if(align == imagealign_MarginLeft || align == imagealign_MarginRight) {
	/* FIXME */
	gglk_textbuffer_put_image(tb, pic, imagealign_InlineUp);
	
#if 0
	GdkRectangle rect;
	GtkWidget *child, *event_box;

	event_box = gtk_event_box_new();
	child = gtk_image_new_from_pixbuf(pic);
	gtk_container_add(GTK_CONTAINER(event_box), child);

	gtk_widget_show_all(event_box);

	gtk_text_view_get_iter_location(GTK_TEXT_VIEW(tb),
					&tb->base.iter, &rect);
	gtk_text_view_add_child_in_window(GTK_TEXT_VIEW(tb),
					  event_box, GTK_TEXT_WINDOW_TEXT,
					  rect.x, rect.y);
#endif

    } else {
	GtkTextIter start, end;

	switch(align) {
	case imagealign_InlineUp:
	    height = 0;
	    break;
	case imagealign_InlineDown:
	    height -= line_height;
	    break;
	case imagealign_InlineCenter:
	    height = (height - line_height) / 2;
	    break;
	default:
	    height = 0;
	}

	gtk_text_buffer_insert_pixbuf(tb->base.buffer, &tb->base.iter, pic);

	start = end = tb->base.iter;
	gtk_text_iter_backward_char(&start);
	if(height != 0) {
	    GtkTextTag *tag = gtk_text_buffer_create_tag(tb->base.buffer, NULL,
							 "rise", PANGO_SCALE * (-height),
							 NULL);
	    gtk_text_buffer_apply_tag(tb->base.buffer, tag, &start, &end);
	}
	gtk_text_buffer_get_end_iter(tb->base.buffer, &tb->base.iter);
    }
}
static void insert_icon_at_mark(GtkTextMark * requested_mark, gpointer user_data)
{
    GList          *win_list;
    GtkIMHtml      *target_imhtml = NULL;
    GtkTextBuffer  *target_buffer = NULL;
    GtkTextIter     insertion_point;
    TwitterConvIcon *conv_icon = user_data;

    /* find the conversation that contains the mark  */
    for (win_list = pidgin_conv_windows_get_list(); win_list; win_list = win_list->next) {
        PidginWindow   *win = win_list->data;
        GList          *conv_list;

        for (conv_list = pidgin_conv_window_get_gtkconvs(win); conv_list; conv_list = conv_list->next) {
            PidginConversation *conv = conv_list->data;

            GtkIMHtml      *current_imhtml = GTK_IMHTML(conv->imhtml);
            GtkTextBuffer  *current_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(current_imhtml));

            if (current_buffer == gtk_text_mark_get_buffer(requested_mark)) {
                target_imhtml = current_imhtml;
                target_buffer = current_buffer;
                break;
            }
        }
    }

    if (!(target_imhtml && target_buffer)) {
        purple_debug_warning(PLUGIN_ID, "No target imhtml/target buffer\n");
        return;
    }

    /* insert icon to the mark */
    gtk_text_buffer_get_iter_at_mark(target_buffer, &insertion_point, requested_mark);

    /* in this function, we put an icon for pending marks. we should
     * not invalidate the icon here, otherwise it may result in
     * thrashing. --yaz */

    if (!conv_icon || !conv_icon->pixbuf) {
        purple_debug_warning(PLUGIN_ID, "No pixbuf\n");
        return;
    }

/* We only want to add the icon if the mark is still on screen. If the user cleared the screen with a ctrl-L, this won't be true. TODO -- can we get a callback at the clear and just delete the mark there? */
    if (TRUE == gtk_text_iter_is_end(&insertion_point)) {
        purple_debug_warning(PLUGIN_ID, "Not adding the icon, since the insertion point is no longer in the buffer\n");
    } else {
        /* insert icon actually */
        gtk_text_buffer_insert_pixbuf(target_buffer, &insertion_point, conv_icon->pixbuf);
    }

    gtk_text_buffer_delete_mark(target_buffer, requested_mark);
    requested_mark = NULL;
    purple_debug_info(PLUGIN_ID, "inserted icon into conv\n");
}
Beispiel #7
0
static void add_line(module_t *Module, const char *Line) {
// 	printf("Adding line to %s: %s\n", Module->Name, Line);
	gdk_threads_enter();
	GtkTextIter Iter;
	gtk_text_buffer_get_end_iter(Module->Source, &Iter);
	gtk_text_buffer_insert_pixbuf(Module->Source, &Iter, NoBreakpointPixbuf);
	gtk_text_buffer_insert_with_tags(Module->Source, &Iter, Line, strlen(Line), SourceTag, 0);
	Module->NoOfLines++;
	gdk_threads_leave();
};
static void twitter_conv_icon_displayed_chat_cb(PurpleAccount * account, const char *who, char *message, PurpleConversation * conv, PurpleMessageFlags flags, void *account_signal)
{
    GtkIMHtml      *imhtml;
    GtkTextBuffer  *text_buffer;
    GtkTextIter     insertion_point;
    gint            linenumber;
    TwitterConvIcon *conv_icon;
    PurpleConnection *gc;
    TwitterConnectionData *twitter;

    if (account != account_signal)
        return;

    gc = purple_account_get_connection(account);
    if (!gc) {
        return;
    }

    twitter = gc->proto_data;

    purple_debug_info(PLUGIN_ID, "%s\n", G_STRFUNC);

    /* insert icon */
    imhtml = GTK_IMHTML(PIDGIN_CONVERSATION(conv)->imhtml);
    text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(imhtml));

    /* get GtkTextIter in the target line */
    linenumber = GPOINTER_TO_INT(purple_conversation_get_data(conv, PLUGIN_ID "-icon-ln"));
    gtk_text_buffer_get_iter_at_line(text_buffer, &insertion_point, linenumber);

    conv_icon = twitter_conv_icon_find(account, who);

    /* if we don't have the icon for this user, put a mark instead and
     * request the icon */
    if (!conv_icon) {
        conv_icon = twitter_conv_icon_new(account, who);
        twitter_conv_icon_add_conv(conv_icon, conv);
        g_hash_table_insert(twitter->icons, g_strdup(purple_normalize(account, who)), conv_icon);
        mark_icon_for_user(gtk_text_buffer_create_mark(text_buffer, NULL, &insertion_point, FALSE), conv_icon);
        return;
    }
    twitter_conv_icon_add_conv(conv_icon, conv);

    /* if we have the icon for this user, insert the icon immediately */
    if (TRUE) {
        if (conv_icon->pixbuf) {
            gtk_text_buffer_insert_pixbuf(text_buffer, &insertion_point, conv_icon->pixbuf);
        } else {
            mark_icon_for_user(gtk_text_buffer_create_mark(text_buffer, NULL, &insertion_point, FALSE), conv_icon);
        }
    }

    purple_debug_info(PLUGIN_ID, "end %s\n", G_STRFUNC);
}
Beispiel #9
0
/**
 * 将好友信息数据写入指定的缓冲区.
 * @param buffer text-buffer
 * @param pal class PalInfo
 */
void DialogPeer::FillPalInfoToBuffer(GtkTextBuffer *buffer, PalInfo *pal)
{
        char buf[MAX_BUFLEN], ipstr[INET_ADDRSTRLEN];
        GdkPixbuf *pixbuf;
        GtkTextIter iter;

        gtk_text_buffer_get_end_iter(buffer, &iter);

        snprintf(buf, MAX_BUFLEN, _("Version: %s\n"), pal->version);
        gtk_text_buffer_insert(buffer, &iter, buf, -1);

        if (pal->group && *pal->group != '\0')
                snprintf(buf, MAX_BUFLEN, _("Nickname: %s@%s\n"), pal->name, pal->group);
        else
                snprintf(buf, MAX_BUFLEN, _("Nickname: %s\n"), pal->name);
        gtk_text_buffer_insert(buffer, &iter, buf, -1);

        snprintf(buf, MAX_BUFLEN, _("User: %s\n"), pal->user);
        gtk_text_buffer_insert(buffer, &iter, buf, -1);

        snprintf(buf, MAX_BUFLEN, _("Host: %s\n"), pal->host);
        gtk_text_buffer_insert(buffer, &iter, buf, -1);

        inet_ntop(AF_INET, &pal->ipv4, ipstr, INET_ADDRSTRLEN);
        if (pal->segdes && *pal->segdes != '\0')
                snprintf(buf, MAX_BUFLEN, _("Address: %s(%s)\n"), pal->segdes, ipstr);
        else
                snprintf(buf, MAX_BUFLEN, _("Address: %s\n"), ipstr);
        gtk_text_buffer_insert(buffer, &iter, buf, -1);

        if (!FLAG_ISSET(pal->flags, 0))
                snprintf(buf, MAX_BUFLEN, _("Compatibility: Microsoft\n"));
        else
                snprintf(buf, MAX_BUFLEN, _("Compatibility: GNU/Linux\n"));
        gtk_text_buffer_insert(buffer, &iter, buf, -1);

        snprintf(buf, MAX_BUFLEN, _("System coding: %s\n"), pal->encode);
        gtk_text_buffer_insert(buffer, &iter, buf, -1);

        if (pal->sign && *pal->sign != '\0') {
                gtk_text_buffer_insert(buffer, &iter, _("Signature:\n"), -1);
                gtk_text_buffer_insert_with_tags_by_name(buffer, &iter,
                                 pal->sign, -1, "sign-words", NULL);
        }

        if (pal->photo && *pal->photo != '\0'
                 && (pixbuf = gdk_pixbuf_new_from_file(pal->photo, NULL))) {
                gtk_text_buffer_insert(buffer, &iter, _("\nPhoto:\n"), -1);
                //TODO 缩放多少才合适
                pixbuf_shrink_scale_1(&pixbuf, 200, -1);
                gtk_text_buffer_insert_pixbuf(buffer, &iter, pixbuf);
                g_object_unref(pixbuf);
        }
}
Beispiel #10
0
int main (int argc,
          char *argv[])
{
  GtkWidget *window, *scrolled_win, *textview;
  GdkPixbuf *undo, *redo;
  GtkTextIter line;
  GtkTextBuffer *buffer;
  
  gtk_init (&argc, &argv);
  
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window), "Pixbufs");
  gtk_container_set_border_width (GTK_CONTAINER (window), 10);
  gtk_widget_set_size_request (window, 200, 150);
  
  g_signal_connect (G_OBJECT (window), "destroy",
                    G_CALLBACK (gtk_main_quit), NULL);
  
  textview = gtk_text_view_new ();
  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview));
  gtk_text_buffer_set_text (buffer, " Undo\n Redo", -1);

  /* Create two images and insert them into the text buffer. */
  undo = gdk_pixbuf_new_from_file (IMAGE_UNDO, NULL);
  gtk_text_buffer_get_iter_at_line (buffer, &line, 0);
  gtk_text_buffer_insert_pixbuf (buffer, &line, undo);

  redo = gdk_pixbuf_new_from_file (IMAGE_REDO, NULL);
  gtk_text_buffer_get_iter_at_line (buffer, &line, 1);
  gtk_text_buffer_insert_pixbuf (buffer, &line, redo);
  
  scrolled_win = gtk_scrolled_window_new (NULL, NULL);
  gtk_container_add (GTK_CONTAINER (scrolled_win), textview);
  gtk_container_add (GTK_CONTAINER (window), scrolled_win);
  gtk_widget_show_all (window);
  
  gtk_main();
  return 0;
}
Beispiel #11
0
static void
chat_text_view_replace_smiley (const gchar *text,
			       gssize len,
			       gpointer match_data,
			       gpointer user_data)
{
	EmpathySmileyHit *hit = match_data;
	GtkTextBuffer *buffer = GTK_TEXT_BUFFER (user_data);
	GtkTextIter iter;

	gtk_text_buffer_get_end_iter (buffer, &iter);
	gtk_text_buffer_insert_pixbuf (buffer, &iter, hit->pixbuf);
}
Beispiel #12
0
void
gimp_error_console_add (GimpErrorConsole    *console,
                        GimpMessageSeverity  severity,
                        const gchar         *domain,
                        const gchar         *message)
{
  const gchar *desc;
  GtkTextIter  end;
  GtkTextMark *end_mark;
  GdkPixbuf   *pixbuf;
  gchar       *str;

  g_return_if_fail (GIMP_IS_ERROR_CONSOLE (console));
  g_return_if_fail (domain != NULL);
  g_return_if_fail (message != NULL);

  gimp_enum_get_value (GIMP_TYPE_MESSAGE_SEVERITY, severity,
                       NULL, NULL, &desc, NULL);

  gtk_text_buffer_get_end_iter (console->text_buffer, &end);

  pixbuf = gtk_widget_render_icon (console->text_view,
                                   gimp_get_message_stock_id (severity),
                                   GTK_ICON_SIZE_BUTTON, NULL);
  gtk_text_buffer_insert_pixbuf (console->text_buffer, &end, pixbuf);
  g_object_unref (pixbuf);

  gtk_text_buffer_insert (console->text_buffer, &end, "  ", -1);

  str = g_strdup_printf ("%s %s", domain, desc);
  gtk_text_buffer_insert_with_tags_by_name (console->text_buffer, &end,
                                            str, -1,
                                            "title",
                                            NULL);
  g_free (str);

  gtk_text_buffer_insert (console->text_buffer, &end, "\n", -1);

  gtk_text_buffer_insert_with_tags_by_name (console->text_buffer, &end,
                                            message, -1,
                                            "message",
                                            NULL);

  gtk_text_buffer_insert (console->text_buffer, &end, "\n\n", -1);

  end_mark = gtk_text_buffer_create_mark (console->text_buffer,
                                          NULL, &end, TRUE);
  gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (console->text_view), end_mark,
                                FALSE, TRUE, 1.0, 0.0);
  gtk_text_buffer_delete_mark (console->text_buffer, end_mark);
}
Beispiel #13
0
/**
 * 图片拖拽事件响应函数.
 * @param dlgpr 对话框类
 * @param context the drag context
 * @param x where the drop happened
 * @param y where the drop happened
 * @param data the received data
 * @param info the info that has been registered with the target in the GtkTargetList
 * @param time the timestamp at which the data was received
 */
void DialogPeer::DragPicReceived(DialogPeer *dlgpr, GdkDragContext *context,
                                 gint x, gint y, GtkSelectionData *data,
                                 guint info, guint time)
{
        GtkWidget *widget;
        GtkTextBuffer *buffer;
        GtkTextIter iter;
        GdkPixbuf *pixbuf;
        GSList *list, *flist, *tlist;
        gint position;

        if (data->length <= 0 || data->format != 8) {
                gtk_drag_finish(context, FALSE, FALSE, time);
                return;
        }

        /* 获取(text-buffer)的当前插入点 */
        widget = GTK_WIDGET(g_datalist_get_data(&dlgpr->widset, "input-textview-widget"));
        buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(widget));
        g_object_get(buffer, "cursor-position", &position, NULL);
        gtk_text_buffer_get_iter_at_offset(buffer, &iter, position);
        /* 分离图片文件和常规文件,图片立即处理,常规文件稍候再处理 */
        flist = NULL;   //预置常规文件链表为空
        tlist = list = selection_data_get_path(data);   //获取所有文件
        while (tlist) {
                if ( (pixbuf = gdk_pixbuf_new_from_file((char *)tlist->data, NULL))) {
                        /* 既然是图片,那就立即处理吧 */
                        gtk_text_buffer_insert_pixbuf(buffer, &iter, pixbuf);
                        g_object_unref(pixbuf);
                } else {
                        /* 将文件路径转移至文件链表(flist) */
                        flist = g_slist_append(flist, tlist->data);
                        tlist->data = NULL;
                }
                tlist = g_slist_next(tlist);
        }
        /*/* 释放链表数据 */
        g_slist_foreach(list, GFunc(g_free), NULL);
        g_slist_free(list);
        /* 如果文件链表有文件,那就添加为附件吧 */
        if (flist) {
                dlgpr->AttachEnclosure(flist);
                g_slist_foreach(flist, GFunc(g_free), NULL);
                g_slist_free(flist);
                widget = GTK_WIDGET(g_datalist_get_data(&dlgpr->widset,
                                         "enclosure-frame-widget"));
                gtk_widget_show(widget);
        }

        gtk_drag_finish(context, TRUE, FALSE, time);
}
Beispiel #14
0
static void
insert_message_with_emotes(GtkTextBuffer* buf, GtkTextIter* iter, GList* emotes, const gchar* msg, gint offset)
{
    gint deleted = 0;

    gtk_text_buffer_insert(buf, iter, msg, -1);

    if (!emotes)
        return;

    for (GList* l = emotes; l != NULL; l = l->next)
    {
        TwitchEmote* em = (TwitchEmote*) l->data;
        GtkTextIter iter2 = *iter;

        gtk_text_iter_set_line_offset(iter, em->start + offset - deleted);
        gtk_text_iter_set_line_offset(&iter2, em->end + offset - deleted + 1);
        gtk_text_buffer_delete(buf, iter, &iter2);
        gtk_text_buffer_insert_pixbuf(buf, iter, em->pixbuf);
        deleted += em->end - em->start;
    }
}
Beispiel #15
0
static void
enhancer_helper_enhance (G_GNUC_UNUSED GmTextBufferEnhancerHelperIFace* self,
			 GtkTextBuffer* buffer,
			 GtkTextIter* iter,
			 G_GNUC_UNUSED GSList** tags,
			 G_GNUC_UNUSED const gchar* full_text,
			 gint* start,
			 gint length)
{
  const gchar **smileys = gm_get_smileys ();
  gchar* smiley = NULL;
  gint ii = 0;
  const gchar* pixbuf_name = NULL;
  GdkPixbuf* pixbuf = NULL;

  smiley = g_malloc0 (length + 1);

  strncpy (smiley, full_text + *start, length);

  for (ii = 0;
       smileys[ii] != NULL;
       ii = ii + 2) {

    if (strcmp (smiley, smileys[ii]) == 0)
      pixbuf_name = smileys[ii + 1];
  }

  if (pixbuf_name != NULL) {

    pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
				       pixbuf_name, 16, 0, NULL);
    gtk_text_buffer_insert_pixbuf (buffer, iter, pixbuf);
    g_object_unref (pixbuf);
    *start = *start + length;
  }

  g_free (smiley);
}
Beispiel #16
0
static void
entry_info_fetched_done (EntryProperties *eprop, GdaLdapEntry *entry)
{
	GtkTextBuffer *tbuffer;
	GtkTextIter start, end;
	TConnection *tcnc = eprop->priv->tcnc;
	
	tbuffer = eprop->priv->text;
	gtk_text_buffer_get_start_iter (tbuffer, &start);
	gtk_text_buffer_get_end_iter (tbuffer, &end);
	gtk_text_buffer_delete (tbuffer, &start, &end);

	guint i;
	GtkTextIter current;

	gtk_text_buffer_get_start_iter (tbuffer, &current);

	/* DN */
	gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, _("Distinguished Name:"), -1,
						  "section", NULL);
	gtk_text_buffer_insert (tbuffer, &current, "\n", -1);
	gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, " ", -1, "starter", NULL);
	gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, entry->dn, -1,
						  "data", NULL);
	gtk_text_buffer_insert (tbuffer, &current, "\n", -1);

	/* other attributes */
	const gchar *basedn;
	GdaDataHandler *ts_dh = NULL;
	basedn = t_connection_ldap_get_base_dn (tcnc);

	for (i = 0; i < entry->nb_attributes; i++) {
		GdaLdapAttribute *attr;
		gchar *tmp;
		attr = entry->attributes [i];
		tmp = g_strdup_printf ("%s:", attr->attr_name);
		gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, tmp, -1, "section", NULL);
		g_free (tmp);
		gtk_text_buffer_insert (tbuffer, &current, "\n", -1);

		guint j;
		for (j = 0; j < attr->nb_values; j++) {
			const GValue *cvalue;
			cvalue = attr->values [j];

			gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, " ", -1,
								  "starter", NULL);

			if (G_VALUE_TYPE (cvalue) == GDA_TYPE_BINARY) {
				GValue *copyvalue;
				GtkTextTagTable *table;
				GtkTextTag *tag;
				GtkTextMark *mark;

				copyvalue = gda_value_copy (cvalue);
				table = gtk_text_buffer_get_tag_table (tbuffer);
				tag = gtk_text_tag_new (NULL);
				gtk_text_tag_table_add (table, tag);
				g_object_set_data_full ((GObject*) tag, "binvalue",
							copyvalue, (GDestroyNotify) gda_value_free);
				g_object_unref ((GObject*) tag);

				mark = gtk_text_buffer_create_mark (tbuffer, NULL, &current, TRUE);

				GdkPixbuf *pixbuf;
				pixbuf = data_to_pixbuf (cvalue);
				if (pixbuf) {
					gtk_text_buffer_insert_pixbuf (tbuffer, &current, pixbuf); 
					g_object_unref (pixbuf);
				}
				else {
					GdaDataHandler *dh;
					dh = gda_data_handler_get_default (G_VALUE_TYPE (cvalue));
					if (dh)
						tmp = gda_data_handler_get_str_from_value (dh, cvalue);
					else
						tmp = gda_value_stringify (cvalue);
					gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
										  tmp, -1,
										  "data", NULL);
					g_free (tmp);
				}
				GtkTextIter before;
				gtk_text_buffer_get_iter_at_mark (tbuffer, &before, mark);
				gtk_text_buffer_apply_tag (tbuffer, tag, &before, &current);
				gtk_text_buffer_delete_mark (tbuffer, mark);
					
				gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
									  "\n", 1,
									  "data", NULL);
			}
			else {
				GdaDataHandler *dh;
				dh = gda_data_handler_get_default (G_VALUE_TYPE (cvalue));
				if (dh)
					tmp = gda_data_handler_get_str_from_value (dh, cvalue);
				else
					tmp = gda_value_stringify (cvalue);
				if (tmp) {
					if (*tmp &&
					    ((basedn && g_str_has_suffix (tmp, basedn)) || !basedn) &&
					    gda_ldap_is_dn (tmp)) {
						/* we have a DN */
						GtkTextTag *tag;
						tag = gtk_text_buffer_create_tag (tbuffer, NULL,
										  "foreground", "blue",
										  "weight", PANGO_WEIGHT_NORMAL,
										  "underline", PANGO_UNDERLINE_SINGLE,
										  NULL);
						g_object_set_data_full (G_OBJECT (tag), "dn",
									g_strdup (tmp), g_free);
						gtk_text_buffer_insert_with_tags (tbuffer, &current,
										  tmp, -1,
										  tag, NULL);
					}
					else if (attr->attr_name &&
						 !g_ascii_strcasecmp (attr->attr_name, "objectClass")) {
						GtkTextTag *tag;
						tag = gtk_text_buffer_create_tag (tbuffer, NULL,
										  "foreground", "blue",
										  "weight", PANGO_WEIGHT_NORMAL,
										  "underline", PANGO_UNDERLINE_SINGLE,
										  NULL);
						g_object_set_data_full (G_OBJECT (tag), "class",
									g_strdup (tmp), g_free);
						gtk_text_buffer_insert_with_tags (tbuffer, &current,
										  tmp, -1,
										  tag, NULL);
					}
					else
						gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, tmp, -1,
											  "data", NULL);

					gchar *extrainfo = NULL;
					if (!strncmp (attr->attr_name, "shadow", 6) &&
					    (!strcmp (attr->attr_name, "shadowLastChange") ||
					     !strcmp (attr->attr_name, "shadowMax") ||
					     !strcmp (attr->attr_name, "shadowMin") ||
					     !strcmp (attr->attr_name, "shadowInactive") ||
					     !strcmp (attr->attr_name, "shadowExpire")))
						extrainfo = unix_shadow_to_string (tmp, attr->attr_name);
					else if (!strcmp (attr->attr_name, "badPasswordTime") ||
						 !strcmp (attr->attr_name, "lastLogon") ||
						 !strcmp (attr->attr_name, "pwdLastSet") ||
						 !strcmp (attr->attr_name, "accountExpires") ||
						 !strcmp (attr->attr_name, "lockoutTime") ||
						 !strcmp (attr->attr_name, "lastLogonTimestamp"))
						extrainfo = ad_1601_timestamp_to_string (tmp, attr->attr_name);
					else if (!strcmp (attr->attr_name, "userAccountControl"))
						extrainfo = ad_1601_uac_to_string (tmp);
					else if (!strcmp (attr->attr_name, "sAMAccountType"))
						extrainfo = ad_sam_account_type_to_string (tmp);

					if (extrainfo) {
						gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
											  " ", 1,
											  "data", NULL);
						gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
											  extrainfo, -1,
											  "convdata", NULL);
						g_free (extrainfo);
					}
					g_free (tmp);
				}
				else {
					gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, _("Can't display attribute value"), -1,
										  "error", NULL);
				}
				gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
									  "\n", 1,
									  "data", NULL);
			}
		}
	}
	if (ts_dh)
		g_object_unref (ts_dh);
	gda_ldap_entry_free (entry);


	if (eprop->priv->text_search && gtk_widget_get_visible (eprop->priv->text_search))
		text_search_rerun (TEXT_SEARCH (eprop->priv->text_search));
}
Beispiel #17
0
static void
displayed_im_cb(PurpleAccount *account, const char *who, char *message,
                PurpleConversation *conv, PurpleMessageFlags flags)
{
    GMatchInfo *match_info = NULL;
    gchar *user_name = NULL;
    GtkIMHtml *imhtml;
    GtkTextBuffer *text_buffer;
    GtkTextIter insertion_point;
    gint service = get_service_type(conv);
    icon_data *data = NULL;
    gint linenumber;
    GHashTable *hash = NULL;
    gboolean renew = FALSE;

    twitter_debug("called\n");

    if(service == unknown_service) {
        twitter_debug("unknown service\n");
        return;
    }

    /* get user's name */
    g_regex_match(regp[USER], message, 0, &match_info);
    if(!g_match_info_matches(match_info)) {
        twitter_debug("message was not matched : %s\n", message);
        g_match_info_free(match_info);
        return;
    }

    user_name = g_match_info_fetch(match_info, 1);
    g_match_info_free(match_info);

    /* insert icon */
    imhtml = GTK_IMHTML(PIDGIN_CONVERSATION(conv)->imhtml);
    text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(imhtml));

    /* get GtkTextIter in the target line */
    linenumber = GPOINTER_TO_INT(g_hash_table_lookup(conv_hash, conv));
    gtk_text_buffer_get_iter_at_line(text_buffer,
                                     &insertion_point,
                                     linenumber);

    switch(service) {
    case twitter_service:
    case wassr_service:
    case identica_service:
    case jisko_service:
    case ffeed_service:
        hash = icon_hash[service];
        break;
    default:
        twitter_debug("unknown service\n");
        break;
    }

    if(hash)
        data = g_hash_table_lookup(hash, user_name);

    if(data) {
        /* check validity of icon */
        int count_thres = purple_prefs_get_int(OPT_ICON_MAX_COUNT);
        int days_thres =
            DAYS_TO_SECONDS(purple_prefs_get_int(OPT_ICON_MAX_DAYS));

        if(data->use_count > count_thres ||
           (data->mtime && ((time(NULL) - data->mtime)) > days_thres)) {
            twitter_debug("count=%d mtime=%d\n",
                          data->use_count, (int)(data->mtime));
            renew = TRUE;
            request_icon(user_name, service, renew);
        }
    }

    /* if we don't have the icon for this user, put a mark instead and
     * request the icon */
    if(!data || !data->pixbuf) {
        twitter_debug("%s's icon is not in memory.\n", user_name);
        mark_icon_for_user(gtk_text_buffer_create_mark(
                               text_buffer, NULL, &insertion_point, FALSE),
                           user_name, service);
        /* request to attach icon to the buffer */
        request_icon(user_name, service, renew);
        g_free(user_name); user_name = NULL;
        return;
    }

    /* if we have the icon for this user, insert the icon immediately */
    if(purple_prefs_get_bool(OPT_SHOW_ICON)) {
        gtk_text_buffer_insert_pixbuf(text_buffer,
                                      &insertion_point,
                                      data->pixbuf);
        data->use_count++;
    }
    g_free(user_name); user_name = NULL;

    twitter_debug("reach end of function\n");
}
Beispiel #18
0
/**
 * class_properties_set_class:
 * @cprop: a #ClassProperties widget
 * @classname: a DN to display information for
 *
 * Adjusts the display to show @classname's properties
 */
void
class_properties_set_class (ClassProperties *cprop, const gchar *classname)
{
	g_return_if_fail (IS_CLASS_PROPERTIES (cprop));

	GtkTextBuffer *tbuffer;
	GtkTextIter start, end;
	GdaLdapClass *lcl;
	GtkTextIter current;
	guint i;

	tbuffer = cprop->priv->text;
	gtk_text_buffer_get_start_iter (tbuffer, &start);
        gtk_text_buffer_get_end_iter (tbuffer, &end);
        gtk_text_buffer_delete (tbuffer, &start, &end);

	if (!classname || !*classname)
		return;

	lcl = t_connection_get_class_info (cprop->priv->tcnc, classname);
	if (!lcl) {
		ui_show_message (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) cprop)),
				      "%s", _("Could not get information about LDAP class"));
		return;
	}

	gtk_text_buffer_get_start_iter (tbuffer, &current);

	/* Description */
	if (lcl->description) {
		gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
							  _("Description:"), -1,
							  "section", NULL);
		gtk_text_buffer_insert (tbuffer, &current, "\n", -1);
		gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, " ", -1, "starter", NULL);
		gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, lcl->description, -1,
							  "data", NULL);
		gtk_text_buffer_insert (tbuffer, &current, "\n", -1);
	}

	/* OID */
	gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
						  _("Class OID:"), -1,
						  "section", NULL);
	gtk_text_buffer_insert (tbuffer, &current, "\n", -1);
	gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, " ", -1, "starter", NULL);
	gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, lcl->oid, -1,
						  "data", NULL);
	gtk_text_buffer_insert (tbuffer, &current, "\n", -1);

	/* Kind */
	const gchar *kind;
	gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
						  _("Class kind:"), -1,
						  "section", NULL);
	gtk_text_buffer_insert (tbuffer, &current, "\n", 1);

	gtk_text_buffer_insert_pixbuf (tbuffer, &current, ui_connection_ldap_icon_for_class_kind (lcl->kind)); 

	kind = ui_connection_ldap_class_kind_to_string (lcl->kind);
	gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, " ", -1, "starter", NULL);
	gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, kind, -1,
						  "data", NULL);
	gtk_text_buffer_insert (tbuffer, &current, "\n", -1);

	/* Class name */
	gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
						  ngettext ("Class name:", "Class names:", lcl->nb_names), -1,
						  "section", NULL);
	gtk_text_buffer_insert (tbuffer, &current, "\n", -1);
	for (i = 0; i < lcl->nb_names; i++) {
		gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, " ", -1, "starter", NULL);
		gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, lcl->names[i], -1,
							  "data", NULL);
		gtk_text_buffer_insert (tbuffer, &current, "\n", -1);
	}

	/* obsolete */
	if (lcl->obsolete) {
		gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
							  _("This LDAP class is obsolete"), -1,
							  "error", NULL);
		gtk_text_buffer_insert (tbuffer, &current, "\n", -1);
	}
	
	/* req. attributes */
	if (lcl->nb_req_attributes > 0) {
		gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
							  ngettext ("Required attribute:",
								    "Required attributes:",
								    lcl->nb_req_attributes), -1,
							  "section", NULL);
		gtk_text_buffer_insert (tbuffer, &current, "\n", -1);
		for (i = 0; i < lcl->nb_req_attributes; i++) {
			gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, " ", -1, "starter", NULL);
			gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, lcl->req_attributes[i], -1,
								  "data", NULL);
			gtk_text_buffer_insert (tbuffer, &current, "\n", -1);
		}
	}

	/* opt. attributes */
	if (lcl->nb_opt_attributes > 0) {
		gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
							  ngettext ("Optional attribute:",
								    "Optional attributes:",
								    lcl->nb_opt_attributes), -1,
							  "section", NULL);
		gtk_text_buffer_insert (tbuffer, &current, "\n", -1);
		for (i = 0; i < lcl->nb_opt_attributes; i++) {
			gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, " ", -1, "starter", NULL);
			gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, lcl->opt_attributes[i], -1,
								  "data", NULL);
			gtk_text_buffer_insert (tbuffer, &current, "\n", -1);
		}
	}

	/* children */
	if (lcl->children) {
		gint nb;
		GSList *list;
		nb = g_slist_length (lcl->children);
		gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
							  ngettext ("Children class:",
								    "Children classes:",
								    nb), -1,
							  "section", NULL);
		gtk_text_buffer_insert (tbuffer, &current, "\n", -1);
		for (list = lcl->children; list; list = list->next) {
			GdaLdapClass *olcl;
			gchar *tmp;
			GtkTextTag *tag;
			olcl = (GdaLdapClass*) list->data;
			gtk_text_buffer_insert_pixbuf (tbuffer, &current,
						       ui_connection_ldap_icon_for_class_kind (olcl->kind)); 
			gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, " ", -1, "starter", NULL);
			tag = gtk_text_buffer_create_tag (tbuffer, NULL,
							  "foreground", "blue",
							  "weight", PANGO_WEIGHT_NORMAL,
							  "underline", PANGO_UNDERLINE_SINGLE,
							  NULL);
			tmp = olcl->names [0];
			g_object_set_data_full (G_OBJECT (tag), "class",
						g_strdup (tmp), g_free);
			gtk_text_buffer_insert_with_tags (tbuffer, &current,
							  tmp, -1,
							  tag, NULL);
			if (olcl->description) {
				gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
									  " (", -1,
									  "data", NULL);
				gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
									  olcl->description, -1,
									  "data", NULL);
				gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
									  ")", -1,
									  "data", NULL);
			}
			gtk_text_buffer_insert (tbuffer, &current, "\n", -1);
		}
	}

	/* parents */
	if (lcl->parents) {
		gint nb;
		GSList *list;
		nb = g_slist_length (lcl->parents);
		gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
							  ngettext ("Inherited class:",
								    "Inherited classes:",
								    nb), -1,
							  "section", NULL);
		gtk_text_buffer_insert (tbuffer, &current, "\n", -1);
		for (list = lcl->parents; list; list = list->next) {
			GdaLdapClass *olcl;
			gchar *tmp;
			GtkTextTag *tag;
			olcl = (GdaLdapClass*) list->data;

			gtk_text_buffer_insert_pixbuf (tbuffer, &current,
						       ui_connection_ldap_icon_for_class_kind (olcl->kind)); 
			gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current, " ", -1, "starter", NULL);
			tag = gtk_text_buffer_create_tag (tbuffer, NULL,
							  "foreground", "blue",
							  "weight", PANGO_WEIGHT_NORMAL,
							  "underline", PANGO_UNDERLINE_SINGLE,
							  NULL);
			tmp = olcl->names [0];
			g_object_set_data_full (G_OBJECT (tag), "class",
						g_strdup (tmp), g_free);
			gtk_text_buffer_insert_with_tags (tbuffer, &current,
							  tmp, -1,
							  tag, NULL);

			if (olcl->description) {
				gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
									  " (", -1,
									  "data", NULL);
				gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
									  olcl->description, -1,
									  "data", NULL);
				gtk_text_buffer_insert_with_tags_by_name (tbuffer, &current,
									  ")", -1,
									  "data", NULL);
			}

			gtk_text_buffer_insert (tbuffer, &current, "\n", -1);
		}
	}

	if (cprop->priv->text_search && gtk_widget_get_visible (cprop->priv->text_search))
		text_search_rerun (TEXT_SEARCH (cprop->priv->text_search));
}
Beispiel #19
0
static void
insert_text (GtkTextBuffer *buffer)
{
  GtkTextIter iter;
  GtkTextIter start, end;
  GdkPixbuf *pixbuf;
  GdkPixbuf *scaled;
  GtkTextChildAnchor *anchor;
  char *filename;

  /* demo_find_file() looks in the current directory first,
   * so you can run gtk-demo without installing GTK, then looks
   * in the location where the file is installed.
   */
  pixbuf = NULL;
  filename = demo_find_file ("gtk-logo-rgb.gif", NULL);
  if (filename)
    {
      pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
      g_free (filename);
    }

  if (pixbuf == NULL)
    {
      g_printerr ("Failed to load image file gtk-logo-rgb.gif\n");
      exit (1);
    }

  scaled = gdk_pixbuf_scale_simple (pixbuf, 32, 32, GDK_INTERP_BILINEAR);
  g_object_unref (pixbuf);
  pixbuf = scaled;
  
  /* get start of buffer; each insertion will revalidate the
   * iterator to point to just after the inserted text.
   */
  gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0);

  gtk_text_buffer_insert (buffer, &iter, "The text widget can display text with all kinds of nifty attributes. It also supports multiple views of the same buffer; this demo is showing the same buffer in two places.\n\n", -1);

  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Font styles. ", -1,
					    "heading", NULL);
  
  gtk_text_buffer_insert (buffer, &iter, "For example, you can have ", -1);
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
					    "italic", -1,
					    "italic", NULL);
  gtk_text_buffer_insert (buffer, &iter, ", ", -1);  
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
					    "bold", -1,
					    "bold", NULL);
  gtk_text_buffer_insert (buffer, &iter, ", or ", -1);
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
					    "monospace (typewriter)", -1,
					    "monospace", NULL);
  gtk_text_buffer_insert (buffer, &iter, ", or ", -1);
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
					    "big", -1,
					    "big", NULL);
  gtk_text_buffer_insert (buffer, &iter, " text. ", -1);
  gtk_text_buffer_insert (buffer, &iter, "It's best not to hardcode specific text sizes; you can use relative sizes as with CSS, such as ", -1);
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
					    "xx-small", -1,
					    "xx-small", NULL);
  gtk_text_buffer_insert (buffer, &iter, " or ", -1);
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
					    "x-large", -1,
					    "x-large", NULL);
  gtk_text_buffer_insert (buffer, &iter, " to ensure that your program properly adapts if the user changes the default font size.\n\n", -1);
  
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Colors. ", -1,
					    "heading", NULL);
  
  gtk_text_buffer_insert (buffer, &iter, "Colors such as ", -1);  
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
					    "a blue foreground", -1,
					    "blue_foreground", NULL);
  gtk_text_buffer_insert (buffer, &iter, " or ", -1);  
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
					    "a red background", -1,
					    "red_background", NULL);
  gtk_text_buffer_insert (buffer, &iter, " or even ", -1);  
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
					    "a stippled red background", -1,
					    "red_background",
					    "background_stipple",
					    NULL);

  gtk_text_buffer_insert (buffer, &iter, " or ", -1);  
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
					    "a stippled blue foreground on solid red background", -1,
					    "blue_foreground",
					    "red_background",
					    "foreground_stipple",
					    NULL);
  gtk_text_buffer_insert (buffer, &iter, " (select that to read it) can be used.\n\n", -1);  

  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Underline, strikethrough, and rise. ", -1,
					    "heading", NULL);
  
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
					    "Strikethrough", -1,
					    "strikethrough", NULL);
  gtk_text_buffer_insert (buffer, &iter, ", ", -1);
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
					    "underline", -1,
					    "underline", NULL);
  gtk_text_buffer_insert (buffer, &iter, ", ", -1);
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
					    "double underline", -1, 
					    "double_underline", NULL);
  gtk_text_buffer_insert (buffer, &iter, ", ", -1);
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
					    "superscript", -1,
					    "superscript", NULL);
  gtk_text_buffer_insert (buffer, &iter, ", and ", -1);
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
					    "subscript", -1,
					    "subscript", NULL);
  gtk_text_buffer_insert (buffer, &iter, " are all supported.\n\n", -1);

  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Images. ", -1,
					    "heading", NULL);
  
  gtk_text_buffer_insert (buffer, &iter, "The buffer can have images in it: ", -1);
  gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf);
  gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf);
  gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf);
  gtk_text_buffer_insert (buffer, &iter, " for example.\n\n", -1);

  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Spacing. ", -1,
					    "heading", NULL);

  gtk_text_buffer_insert (buffer, &iter, "You can adjust the amount of space before each line.\n", -1);
  
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
					    "This line has a whole lot of space before it.\n", -1,
					    "big_gap_before_line", "wide_margins", NULL);
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
					    "You can also adjust the amount of space after each line; this line has a whole lot of space after it.\n", -1,
					    "big_gap_after_line", "wide_margins", NULL);
  
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
					    "You can also adjust the amount of space between wrapped lines; this line has extra space between each wrapped line in the same paragraph. To show off wrapping, some filler text: the quick brown fox jumped over the lazy dog. Blah blah blah blah blah blah blah blah blah.\n", -1,
					    "double_spaced_line", "wide_margins", NULL);

  gtk_text_buffer_insert (buffer, &iter, "Also note that those lines have extra-wide margins.\n\n", -1);

  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Editability. ", -1,
					    "heading", NULL);
  
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
					    "This line is 'locked down' and can't be edited by the user - just try it! You can't delete this line.\n\n", -1,
					    "not_editable", NULL);

  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Wrapping. ", -1,
					    "heading", NULL);

  gtk_text_buffer_insert (buffer, &iter,
			  "This line (and most of the others in this buffer) is word-wrapped, using the proper Unicode algorithm. Word wrap should work in all scripts and languages that GTK+ supports. Let's make this a long paragraph to demonstrate: blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah\n\n", -1);  
  
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
					    "This line has character-based wrapping, and can wrap between any two character glyphs. Let's make this a long paragraph to demonstrate: blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah\n\n", -1,
					    "char_wrap", NULL);
  
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
					    "This line has all wrapping turned off, so it makes the horizontal scrollbar appear.\n\n\n", -1,
					    "no_wrap", NULL);

  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Justification. ", -1,
					    "heading", NULL);  
  
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
					    "\nThis line has center justification.\n", -1,
					    "center", NULL);

  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
					    "This line has right justification.\n", -1,
					    "right_justify", NULL);

  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
					    "\nThis line has big wide margins. Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.\n", -1,
					    "wide_margins", NULL);  

  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Internationalization. ", -1,
					    "heading", NULL);
	  
  gtk_text_buffer_insert (buffer, &iter,
			  "You can put all sorts of Unicode text in the buffer.\n\nGerman (Deutsch S\303\274d) Gr\303\274\303\237 Gott\nGreek (\316\225\316\273\316\273\316\267\316\275\316\271\316\272\316\254) \316\223\316\265\316\271\316\254 \317\203\316\261\317\202\nHebrew	\327\251\327\234\327\225\327\235\nJapanese (\346\227\245\346\234\254\350\252\236)\n\nThe widget properly handles bidirectional text, word wrapping, DOS/UNIX/Unicode paragraph separators, grapheme boundaries, and so on using the Pango internationalization framework.\n", -1);  

  gtk_text_buffer_insert (buffer, &iter, "Here's a word-wrapped quote in a right-to-left language:\n", -1);
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "\331\210\331\202\330\257 \330\250\330\257\330\243 \330\253\331\204\330\247\330\253 \331\205\331\206 \330\243\331\203\330\253\330\261 \330\247\331\204\331\205\330\244\330\263\330\263\330\247\330\252 \330\252\331\202\330\257\331\205\330\247 \331\201\331\212 \330\264\330\250\331\203\330\251 \330\247\331\203\330\263\331\212\331\210\331\206 \330\250\330\261\330\247\331\205\330\254\331\207\330\247 \331\203\331\205\331\206\330\270\331\205\330\247\330\252 \331\204\330\247 \330\252\330\263\330\271\331\211 \331\204\331\204\330\261\330\250\330\255\330\214 \330\253\331\205 \330\252\330\255\331\210\331\204\330\252 \331\201\331\212 \330\247\331\204\330\263\331\206\331\210\330\247\330\252 \330\247\331\204\330\256\331\205\330\263 \330\247\331\204\331\205\330\247\330\266\331\212\330\251 \330\245\331\204\331\211 \331\205\330\244\330\263\330\263\330\247\330\252 \331\205\330\247\331\204\331\212\330\251 \331\205\331\206\330\270\331\205\330\251\330\214 \331\210\330\250\330\247\330\252\330\252 \330\254\330\262\330\241\330\247 \331\205\331\206 \330\247\331\204\331\206\330\270\330\247\331\205 \330\247\331\204\331\205\330\247\331\204\331\212 \331\201\331\212 \330\250\331\204\330\257\330\247\331\206\331\207\330\247\330\214 \331\210\331\204\331\203\331\206\331\207\330\247 \330\252\330\252\330\256\330\265\330\265 \331\201\331\212 \330\256\330\257\331\205\330\251 \331\202\330\267\330\247\330\271 \330\247\331\204\331\205\330\264\330\261\331\210\330\271\330\247\330\252 \330\247\331\204\330\265\330\272\331\212\330\261\330\251. \331\210\330\243\330\255\330\257 \330\243\331\203\330\253\330\261 \331\207\330\260\331\207 \330\247\331\204\331\205\330\244\330\263\330\263\330\247\330\252 \331\206\330\254\330\247\330\255\330\247 \331\207\331\210 \302\273\330\250\330\247\331\206\331\203\331\210\330\263\331\210\331\204\302\253 \331\201\331\212 \330\250\331\210\331\204\331\212\331\201\331\212\330\247.\n\n", -1,
						"rtl_quote", NULL);
      
  gtk_text_buffer_insert (buffer, &iter, "You can put widgets in the buffer: Here's a button: ", -1);
  anchor = gtk_text_buffer_create_child_anchor (buffer, &iter);
  gtk_text_buffer_insert (buffer, &iter, " and a menu: ", -1);
  anchor = gtk_text_buffer_create_child_anchor (buffer, &iter);
  gtk_text_buffer_insert (buffer, &iter, " and a scale: ", -1);
  anchor = gtk_text_buffer_create_child_anchor (buffer, &iter);
  gtk_text_buffer_insert (buffer, &iter, " and an animation: ", -1);
  anchor = gtk_text_buffer_create_child_anchor (buffer, &iter);
  gtk_text_buffer_insert (buffer, &iter, " finally a text entry: ", -1);
  anchor = gtk_text_buffer_create_child_anchor (buffer, &iter);
  gtk_text_buffer_insert (buffer, &iter, ".\n", -1);
  
  gtk_text_buffer_insert (buffer, &iter, "\n\nThis demo doesn't demonstrate all the GtkTextBuffer features; it leaves out, for example: invisible/hidden text, tab stops, application-drawn areas on the sides of the widget for displaying breakpoints and such...", -1);

  /* Apply word_wrap tag to whole buffer */
  gtk_text_buffer_get_bounds (buffer, &start, &end);
  gtk_text_buffer_apply_tag_by_name (buffer, "word_wrap", &start, &end);

  g_object_unref (pixbuf);
}
Beispiel #20
0
void DocActionPix::Exec(bool bInteractive)
{
	DocumentIterator it(*m_pDoc);

	if(bInteractive)
	{
		FileDialog dlg(true);
		dlg.SetTitle(_("Open picture"));

		//define file filters
		dlg.AddFilter(_("All supported image formats (*.png,*.jpg,*.gif)"), "*.png|*.jpg|*.gif");
		dlg.AddFilter(_("PNG format (*.png)"), "*.png");
		dlg.AddFilter(_("JPG format (*.jpg)"), "*.jpg");
		dlg.AddFilter(_("GIF format (*.gif)"), "*.gif");
		dlg.AddFilter(_("All files (*)"), "*");

		//set initial directory from INI (store last used)
		std::string strDefaultDir;
		std::string strDir;
		g_objIni.GetValue("Cache", "LastPictureDir", strDir, "");
		if(!strDir.empty() && 0 == access(strDir.c_str(), 00))
			strDefaultDir = strDir;
		else
			strDefaultDir = GetHomeDir();

		dlg.SetDirectory(strDefaultDir.c_str());

		if(dlg.DoModal())
		{
			const gchar *filename = dlg.GetFilename();
			strDefaultDir = dlg.GetDirectory();
			dlg.Close();

			//store last open directory
			g_objIni.SetValue("Cache", "LastPictureDir", strDefaultDir.c_str());
			g_objIni.Save();

			GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(filename, NULL);

			PixPropertiesDlg dlg1;
			dlg1.m_nOrigWidth  = gdk_pixbuf_get_width(pixbuf);
			dlg1.m_nOrigHeight = gdk_pixbuf_get_height(pixbuf);
			dlg1.m_bUsePNG = false;
			dlg1.Create();
			if(GTK_RESPONSE_OK != dlg1.ShowModal()){
				g_object_unref (G_OBJECT (pixbuf));
				return;
			}

			GdkPixbuf *destpix = gdk_pixbuf_scale_simple(pixbuf, dlg1.m_nNewWidth, dlg1.m_nNewHeight, GDK_INTERP_BILINEAR);
			g_object_unref (G_OBJECT (pixbuf));
			pixbuf = destpix;

			UpdateTextFromScreen();

			//search from last result selection (or start)
			int cursor = -1;
			int selection = -1;
			g_text.GetSelectionBounds(cursor, selection);
			if(selection >= 0)
				cursor = selection;

			//get the iterator
			GtkTextBuffer* buffer1 = gtk_text_view_get_buffer((GtkTextView *)g_text.m_pWidget);
			GtkTextIter cursIter;
			gtk_text_buffer_get_iter_at_offset(buffer1, &cursIter, cursor);

			gtk_text_buffer_insert_pixbuf(buffer1, &cursIter, pixbuf);

			//store base name for the picture (with changed extension if required)
			std::string strName = GetBaseName(filename);
			EnsureExtension(strName, dlg1.m_bUsePNG ? ".png" : ".jpg");

			PixInfo info;
			info.bUsePNG = dlg1.m_bUsePNG;
			info.nOffset = cursor;
			info.pixbuf  = pixbuf;
			info.strName = strName;
			g_doc.GetNodeByIdx(m_nNodeIdx).m_lstPictures.push_back(info);
			std::sort(g_doc.GetNodeByIdx(m_nNodeIdx).m_lstPictures.begin(), g_doc.GetNodeByIdx(m_nNodeIdx).m_lstPictures.end());

			m_nOffset = cursor;
			m_pixbuf  = pixbuf;
			m_bUsePNG = dlg1.m_bUsePNG;

			//increment offsets for all formatting marks
			int nSize = g_doc.GetNodeByIdx(m_nNodeIdx).m_lstTxtFmt.size();
			int i;
			for(i=0; i<nSize; i++){
				if(g_doc.GetNodeByIdx(m_nNodeIdx).m_lstTxtFmt[i].nOffset >= m_nOffset)
					g_doc.GetNodeByIdx(m_nNodeIdx).m_lstTxtFmt[i].nOffset ++;
			}

			//increment all the pictures after this one
			nSize = g_doc.GetNodeByIdx(m_nNodeIdx).m_lstPictures.size();
			for(i=0; i<nSize; i++){
				if(g_doc.GetNodeByIdx(m_nNodeIdx).m_lstPictures[i].nOffset > m_nOffset)
					g_doc.GetNodeByIdx(m_nNodeIdx).m_lstPictures[i].nOffset ++;
			}
		}
	}
	else
	{
		PixInfo info;
		info.bUsePNG = m_bUsePNG;
		info.nOffset = m_nOffset;
		info.pixbuf  = m_pixbuf;
		g_doc.GetNodeByIdx(m_nNodeIdx).m_lstPictures.push_back(info);

		//increment offsets for all formatting marks
		int nSize = g_doc.GetNodeByIdx(m_nNodeIdx).m_lstTxtFmt.size();
		int i;
		for(i=0; i<nSize; i++){
			if(g_doc.GetNodeByIdx(m_nNodeIdx).m_lstTxtFmt[i].nOffset >= m_nOffset)
				g_doc.GetNodeByIdx(m_nNodeIdx).m_lstTxtFmt[i].nOffset ++;
		}

		//increment all the pictures after this one
		nSize = g_doc.GetNodeByIdx(m_nNodeIdx).m_lstPictures.size();
		for(i=0; i<nSize; i++){
			if(g_doc.GetNodeByIdx(m_nNodeIdx).m_lstPictures[i].nOffset > m_nOffset)
				g_doc.GetNodeByIdx(m_nNodeIdx).m_lstPictures[i].nOffset ++;
		}

		if(m_nNodeIdx == GetSelectedNodeIdx()){
			//get the iterator
			GtkTextBuffer* buffer1 = gtk_text_view_get_buffer((GtkTextView *)g_text.m_pWidget);
			GtkTextIter cursIter;
			gtk_text_buffer_get_iter_at_offset(buffer1, &cursIter, m_nOffset);
			gtk_text_buffer_insert_pixbuf(buffer1, &cursIter, m_pixbuf);
		}
	}
}
Beispiel #21
0
static void
html_output_tag(struct html_output *output, const struct array *tag)
#if GTK_CHECK_VERSION(2,0,0)
{
	static struct {
		gboolean initialized;
		short_string_t centre_line, nbsp, bullet, soft_hyphen, em_dash;
		short_string_t list_item_prefix;
	} special;
	struct html_context *ctx;
	const gchar *style, *text, *attr;
	enum html_tag id;
	gboolean closing;
	GtkTextBuffer *buffer;

	if (!special.initialized) {

		special.initialized = TRUE;
		special.bullet = utf8_char(0x2022);
		special.centre_line = utf8_char(0xFE4E);
		special.soft_hyphen = utf8_char(0x00AD);
		special.nbsp = utf8_char(0x00A0);
		special.em_dash = utf8_char(0x2014);
		concat_strings(special.list_item_prefix.str,
			sizeof special.list_item_prefix.str,
			" ", special.bullet.str, " ", (void *) 0);
	}
	
	style = NULL;
	text = NULL;
	attr = NULL;
	closing = html_tag_is_closing(tag);
	ctx = html_output_get_udata(output);
	id = html_parse_tag(tag);
	buffer = gtk_text_view_get_buffer(ctx->html_view->widget);

	switch (id) {
	case HTML_TAG_BODY:
		style = STYLE_TAG_WORD_WRAP;
		break;
	case HTML_TAG_A:
		if (closing) {
			if (ctx->start[id] && ctx->href) {
				GtkTextIter start, end;
				GtkTextTag *anchor;

				anchor = gtk_text_buffer_create_tag(buffer, NULL, (void *) 0);
				g_object_set_data(G_OBJECT(anchor), "href",
					deconstify_gchar(ctx->href));
				gtk_text_buffer_get_iter_at_mark(buffer,
					&start, ctx->start[id]);
				gtk_text_buffer_get_end_iter(buffer, &end);
				gtk_text_buffer_apply_tag(buffer, anchor, &start, &end);
				style = get_style_for_href(ctx->href);
				ctx->href = NULL;
			}
		} else {
			struct array value;

			value = html_get_attribute(tag, HTML_ATTR_HREF);
			if (value.data && value.size > 0) {
				GtkTextIter iter;

				ctx->href = g_strndup(value.data, value.size);
				ctx->html_view->to_free = g_slist_prepend(
						ctx->html_view->to_free, deconstify_gchar(ctx->href));
				gtk_text_buffer_get_end_iter(buffer, &iter);
				ctx->start[id] = gtk_text_buffer_create_mark(buffer,
										NULL, &iter, TRUE);
				g_object_set_data(G_OBJECT(ctx->start[id]), "href",
					deconstify_gchar(ctx->href));
			}
			value = html_get_attribute(tag, HTML_ATTR_NAME);
			if (value.data && value.size > 0) {
				GtkTextTagTable *table;
				gchar name[256];
				size_t n;

				n = sizeof name - 2;
				n = MIN(value.size, n);
				name[0] = '#';
				memcpy(&name[1], value.data, n);
				name[n + 1] = '\0';
				
				table = gtk_text_buffer_get_tag_table(buffer);
				if (NULL == gtk_text_tag_table_lookup(table, name)) {
					GtkTextIter iter;

					gtk_text_buffer_get_end_iter(buffer, &iter);
					gtk_text_buffer_create_mark(buffer, name, &iter, TRUE);
				}
			}
		}
		break;
	case HTML_TAG_B:
	case HTML_TAG_STRONG:
	case HTML_TAG_THEAD:
		style = STYLE_TAG_BOLD;
		break;
	case HTML_TAG_TH:
		if (closing)
			text = "\t";
		break;
	case HTML_TAG_EM:
		style = STYLE_TAG_UNDERLINE;
		break;
	case HTML_TAG_I:
	case HTML_TAG_Q:
		style = STYLE_TAG_ITALIC;
		break;
	case HTML_TAG_IMG:
		if (!closing) {
			struct array value;
			static gchar alt[1024];
			
			value = html_get_attribute(tag, HTML_ATTR_ALT);
			if (value.data) {
				gm_snprintf(alt, sizeof alt, "\n[image alt=\"%.*s\"]\n",
					(int)value.size, value.data);
				text = alt;
			}
			value = html_get_attribute(tag, HTML_ATTR_SRC);
			if (value.data) {
				GdkPixbuf *pixbuf;
				gchar *filename;
				GtkTextIter iter;

				filename = h_strndup(value.data, value.size);
				pixbuf = gdk_pixbuf_new_from_file(filename, NULL);
				if (pixbuf) {
					gtk_text_buffer_get_end_iter(buffer, &iter);
					gtk_text_buffer_insert_pixbuf(buffer, &iter, pixbuf);
				} else {
					static gchar msg[1024];
					gm_snprintf(msg, sizeof msg,
						"\n[Image not found (\"%s\")]\n", filename);
					text = msg;
				}
				HFREE_NULL(filename);
			}
			if (!text) {
				text = "\n[image]\n";
			}
		}
		attr = STYLE_TAG_BOLD;
		break;
	case HTML_TAG_TD:
		if (closing)
			text = "\t";
		break;
	case HTML_TAG_P:
	case HTML_TAG_DIV:
		text = closing ? "\n\n" : special.soft_hyphen.str;
		break;
	case HTML_TAG_DL:
	case HTML_TAG_TABLE:
	case HTML_TAG_TR:
	case HTML_TAG_UL:
	case HTML_TAG_OL:
	case HTML_TAG_BR:
		text = "\n";
		break;
	case HTML_TAG_DT:
	case HTML_TAG_LI:
		if (closing) {
			GtkTextIter start, end;
			GtkTextTag *margin;
			PangoLayout *pl;
			gint width;

			pl = pango_layout_new(gtk_widget_get_pango_context(
						GTK_WIDGET(ctx->html_view->widget)));
			pango_layout_set_text(pl, special.list_item_prefix.str, -1);
			pango_layout_get_pixel_size(pl, &width, NULL);
			g_object_unref(G_OBJECT(pl));

			margin = gtk_text_buffer_create_tag(buffer, NULL,
						"left-margin",		width * 2,
						"left-margin-set",	TRUE,
						(void *) 0);

			gtk_text_buffer_get_iter_at_mark(buffer, &start, ctx->start[id]);
			gtk_text_buffer_get_end_iter(buffer, &end);
			gtk_text_buffer_apply_tag(buffer, margin, &start, &end);
		} else {
			GtkTextIter iter;
		
			gtk_text_buffer_get_end_iter(buffer, &iter);
			gtk_text_buffer_insert(buffer, &iter, "\n", (-1));

			gtk_text_buffer_get_end_iter(buffer, &iter);
			gtk_text_buffer_insert_with_tags_by_name(buffer, &iter,
					special.list_item_prefix.str, (-1),
					STYLE_TAG_BOLD, (void *) 0);
			gtk_text_buffer_get_end_iter(buffer, &iter);
			ctx->start[id] = gtk_text_buffer_create_mark(buffer, NULL,
					&iter, TRUE);
		}
		break;
	case HTML_TAG_CODE:
	case HTML_TAG_KBD:
	case HTML_TAG_PRE:
	case HTML_TAG_TT:
		style = STYLE_TAG_MONOSPACE;
		break;
	case HTML_TAG_H1:
		style = STYLE_TAG_HEADING_1;
		text = closing ? "\n\n" : "\n";
		break;
	case HTML_TAG_H2:
		style = STYLE_TAG_HEADING_2;
		text = closing ? "\n\n" : "\n";
		break;
	case HTML_TAG_H3:
		style = STYLE_TAG_HEADING_3;
		text = closing ? "\n\n" : "\n";
		break;
	case HTML_TAG_H4:
	case HTML_TAG_H5:
	case HTML_TAG_H6:
		style = STYLE_TAG_HEADING_4;
		text = closing ? "\n\n" : "\n";
		break;
	case HTML_TAG_TITLE:
		if (closing) {
			if (ctx->title) {
				GtkWidget *window;

				window = gtk_widget_get_toplevel(
							GTK_WIDGET(ctx->html_view->widget));
				gtk_window_set_title(GTK_WINDOW(window), str_2c(ctx->title));
				str_destroy_null(&ctx->title);
			}
		} else {
			ctx->title = str_new(0);
		}
		break;
	case HTML_TAG_HR:
		{
			GtkTextIter iter;

			gtk_text_buffer_get_end_iter(buffer, &iter);
			gtk_text_buffer_insert_with_tags_by_name(buffer, &iter,
					"\n    \n", (-1),
					STYLE_TAG_CENTER, STYLE_TAG_UNDERLINE, (void *) 0);
		}
		text = "\n";
		break;
	case HTML_TAG_COMMENT:
#if 0 
		{
			GtkTextIter iter;

			/* Comments can be made visible this way */
			ctx->start[id] = gtk_text_buffer_create_mark(buffer, NULL,
					&iter, TRUE);
			gtk_text_buffer_get_end_iter(buffer, &iter);
			gtk_text_buffer_insert_with_tags_by_name(buffer, &iter,
					tag->data, tag->size, STYLE_TAG_ITALIC, (void *) 0);
		}
		closing = TRUE;
		text = "\n";
#endif
		break;
	case HTML_TAG_HTML:
		if (closing) {
		   	if (ctx->lang && ctx->start[id]) {
				GtkTextIter start, end;
				GtkTextTag *lang;

				lang = gtk_text_buffer_create_tag(buffer, NULL,
						"language",		ctx->lang,
						"language-set",	TRUE,
						(void *) 0);
				gtk_text_buffer_get_iter_at_mark(buffer,
					&start, ctx->start[id]);
				gtk_text_buffer_get_end_iter(buffer, &end);
				gtk_text_buffer_apply_tag(buffer, lang, &start, &end);
				ctx->lang = NULL;
			}
		} else {
			struct array value;

			value = html_get_attribute(tag, HTML_ATTR_LANG);
			if (value.data && value.size > 0) {
				GtkTextIter iter;

				ctx->lang = g_strndup(value.data, value.size);
				ctx->html_view->to_free = g_slist_prepend(
						ctx->html_view->to_free, deconstify_gchar(ctx->lang));
				gtk_text_buffer_get_end_iter(buffer, &iter);
				ctx->start[id] = gtk_text_buffer_create_mark(buffer,
										NULL, &iter, TRUE);
			}
		}
	case HTML_TAG_HEAD:
	case HTML_TAG_META:
	case HTML_TAG_SPAN:
	case HTML_TAG_COL:
	case HTML_TAG_DD:
	case HTML_TAG_TBODY:
	case HTML_TAG_DOCTYPE:
	case HTML_TAG_UNKNOWN:
		break;
	case NUM_HTML_TAG:
		g_assert_not_reached();
	}

	if (style) {
		if (closing) {
			if (ctx->start[id]) {
				GtkTextIter start, end;
		
				gtk_text_buffer_get_iter_at_mark(buffer,
						&start, ctx->start[id]);
				gtk_text_buffer_get_end_iter(buffer, &end);
				gtk_text_buffer_apply_tag_by_name(buffer, style, &start, &end);
				ctx->start[id] = NULL;
			}
		} else {
			GtkTextIter iter;
			gtk_text_buffer_get_end_iter(buffer, &iter);
			ctx->start[id] = gtk_text_buffer_create_mark(buffer,
										NULL, &iter, TRUE);
		}
	}
	if (text) {
		GtkTextIter iter;

		gtk_text_buffer_get_end_iter(buffer, &iter);
		gtk_text_buffer_insert_with_tags_by_name(buffer, &iter,
			text, (-1), attr, (void *) 0);
	}
}
Beispiel #22
0
void gui_help_topic_show(GtkTextBuffer *buffer, gchar *source)
{
gint i, j, n, start, stop;
gchar *text;
GdkPixbuf *pixbuf;
GtkTextIter a, b;

/* initialize help tags */
if (!help_tag_bold)
  help_tag_bold = gtk_text_buffer_create_tag(buffer,
                                            "bold",
                                            "weight", PANGO_WEIGHT_BOLD,
                                            NULL);

if (!help_tag_italic)
  help_tag_italic = gtk_text_buffer_create_tag(buffer,
                                              "italic",
                                              "style", PANGO_STYLE_ITALIC,
                                              NULL);

/* invisible tag not implemented as of GTK 2.2 */
/*
if (!help_tag_invisible)
  help_tag_invisible = gtk_text_buffer_create_tag(buffer,
                                                 "invisible",
                                                 "invisible",
                                                  TRUE,
                                                  NULL);
*/

/* FIXME - hack due to above */
if (!help_tag_invisible)
  {
  GdkColor white = {0, 65535, 65535, 65535};
  help_tag_invisible = gtk_text_buffer_create_tag(buffer,
                                                 "invisible",
                                                 "foreground-gdk",
                                                  &white,
                                                  NULL);
  }

if (!help_tag_fixed)
  {
  help_tag_fixed = gtk_text_buffer_create_tag(buffer,
                                              "fixed",
                                              "font", "Fixed 10",
                                              NULL);
  }

/*
tag_bold = gtk_text_buffer_create_tag(buffer, "bold", "style", PANGO_WEIGHT_OBLIQUE, NULL);
*/

gtk_text_buffer_set_text(buffer, source, -1);

n = strlen(source);
start = i = 0;
stop = -1;
while (i<n)
  {
/* search for special tags */
  if (source[i] == '\\')
    {
/* process the tag */
    switch (source[i+1])
      {
/* header */
      case 'h':
/* make the tag invisible */
        gtk_text_buffer_get_iter_at_offset(buffer, &a, i);
        gtk_text_buffer_get_iter_at_offset(buffer, &b, i+3);
        gtk_text_buffer_apply_tag(buffer, help_tag_invisible, &a, &b);
        a = b;
/* apply the bold tag to the rest of the line */
        stop = -1;
        for (j=i+3 ; j<n ; j++)
          {
          if (source[j] == '\n')
            {
            stop = j;
            break;
            }
          }
        if (stop < 0)
          stop = n;
        gtk_text_buffer_get_iter_at_offset(buffer, &b, stop);
        gtk_text_buffer_apply_tag(buffer, help_tag_bold, &a, &b);
        i = stop;
        break;

/* italics */
      case 'i':
/* make the tag invisible */
        gtk_text_buffer_get_iter_at_offset(buffer, &a, i);
        gtk_text_buffer_get_iter_at_offset(buffer, &b, i+3);
        gtk_text_buffer_apply_tag(buffer, help_tag_invisible, &a, &b);
        a = b;
/* apply the bold tag to the rest of the line */
        stop = -1;
        for (j=i+3 ; j<n ; j++)
          {
          if (source[j] == '\n')
            {
            stop = j;
            break;
            }
          }
        if (stop < 0)
          stop = n;
        gtk_text_buffer_get_iter_at_offset(buffer, &b, stop);
        gtk_text_buffer_apply_tag(buffer, help_tag_italic, &a, &b);
        i = stop;
        break;

/* fixed width font */
      case 'f':
/* make the tag invisible */
        gtk_text_buffer_get_iter_at_offset(buffer, &a, i);
        gtk_text_buffer_get_iter_at_offset(buffer, &b, i+3);
        gtk_text_buffer_apply_tag(buffer, help_tag_invisible, &a, &b);
        a = b;
/* apply the fixed tag to the rest of the line */
        stop = -1;
        for (j=i+3 ; j<n ; j++)
          {
          if (source[j] == '\n')
            {
            stop = j;
            break;
            }
          }
        if (stop < 0)
          stop = n;
        gtk_text_buffer_get_iter_at_offset(buffer, &b, stop);
        gtk_text_buffer_apply_tag(buffer, help_tag_fixed, &a, &b);
        i = stop;
        break;

/* picture */
      case 'p':
/* get the picture label code */
        stop = -1; 
        for (j=i+3 ; j<n ; j++)
          {
          if (source[j] == ' ' || source[j] == '\n')
            {
            stop = j;
            break;
            }
          }
        if (stop < 0)
          stop = n;

/* hide the tag */
        gtk_text_buffer_get_iter_at_offset(buffer, &a, i);
        gtk_text_buffer_get_iter_at_offset(buffer, &b, stop);
        gtk_text_buffer_apply_tag(buffer, help_tag_invisible, &a, &b);

/* CURRENT - delete one char to compensate? */
gtk_text_buffer_get_iter_at_offset(buffer, &b, i+1);
gtk_text_buffer_delete(buffer, &a, &b);

/* insert the pixbuf - counts as one character in the text buffer */
        text = g_strndup(&source[i+3], stop-i-3);
        pixbuf = image_table_lookup(text);
        gtk_text_buffer_insert_pixbuf(buffer, &a, pixbuf);

        i = stop;
        break;
      }
    }
  i++;
  }
}
Beispiel #23
0
static GtkWidget *about_create_child_page_features(void)
{
	GtkWidget *scrolledwin;
	GtkWidget *text;
	GtkTextBuffer *buffer;
	GtkTextIter iter;
	GdkPixbuf *active_pixbuf;
	GdkPixbuf *inactive_pixbuf;

	scrolledwin = gtk_scrolled_window_new(NULL, NULL);
	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
				       GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
	gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
					    GTK_SHADOW_IN);

	text = gtk_text_view_new();
	gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
	gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD);
	gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text), 6);
	gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text), 6);
	gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(text), FALSE);
	gtk_container_add(GTK_CONTAINER(scrolledwin), text);
	gtk_widget_add_events(text, GDK_LEAVE_NOTIFY_MASK);

	buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
	gtk_text_buffer_get_iter_at_offset(buffer, &iter, 0);

	gtk_text_buffer_insert(buffer, &iter, _("Compiled-in Features\n"), -1);

	gtk_text_buffer_create_tag(buffer, "bold", "weight", PANGO_WEIGHT_BOLD,
				   NULL);

	stock_pixbuf_gdk(window, STOCK_PIXMAP_CHECKBOX_ON, &active_pixbuf);
	stock_pixbuf_gdk(window, STOCK_PIXMAP_CHECKBOX_OFF, &inactive_pixbuf);

#if HAVE_LIBCOMPFACE
	gtk_text_buffer_insert_pixbuf(buffer, &iter, active_pixbuf);
#else
	gtk_text_buffer_insert_pixbuf(buffer, &iter, inactive_pixbuf);
#endif
	gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, (" compface "), -1,
						 "bold", NULL);
	gtk_text_buffer_insert(buffer, &iter, 
		(gchar *)C_("compface", "adds support for the X-Face header\n"), -1);

#if USE_ENCHANT
	gtk_text_buffer_insert_pixbuf(buffer, &iter, active_pixbuf);
#else
	gtk_text_buffer_insert_pixbuf(buffer, &iter, inactive_pixbuf);
#endif
	gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, (" Enchant "), -1,
						 "bold", NULL);
	gtk_text_buffer_insert(buffer, &iter, 
		(gchar *)C_("Enchant", "adds support for spell checking\n"), -1);

#if USE_GNUTLS
	gtk_text_buffer_insert_pixbuf(buffer, &iter, active_pixbuf);
#else
	gtk_text_buffer_insert_pixbuf(buffer, &iter, inactive_pixbuf);
#endif
	gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, (" GnuTLS "), -1,
						 "bold", NULL);
	gtk_text_buffer_insert(buffer, &iter, 
		(gchar *)C_("GnuTLS", "adds support for encrypted connections to servers\n"), -1);

#if INET6
	gtk_text_buffer_insert_pixbuf(buffer, &iter, active_pixbuf);
#else
	gtk_text_buffer_insert_pixbuf(buffer, &iter, inactive_pixbuf);
#endif
	gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, (" IPv6 "), -1,
						 "bold", NULL);
	gtk_text_buffer_insert(buffer, &iter, 
		(gchar *)C_("IPv6", "adds support for IPv6 addresses, the new Internet "
			    "addressing protocol\n"), -1);

#if HAVE_ICONV
	gtk_text_buffer_insert_pixbuf(buffer, &iter, active_pixbuf);
#else
	gtk_text_buffer_insert_pixbuf(buffer, &iter, inactive_pixbuf);
#endif
	gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, (" iconv "), -1,
						 "bold", NULL);
	gtk_text_buffer_insert(buffer, &iter, 
		(gchar *)C_("iconv", "allows converting to and from different character sets\n"), -1);

#if USE_JPILOT
	gtk_text_buffer_insert_pixbuf(buffer, &iter, active_pixbuf);
#else
	gtk_text_buffer_insert_pixbuf(buffer, &iter, inactive_pixbuf);
#endif
	gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, (" JPilot "), -1,
						 "bold", NULL);
	gtk_text_buffer_insert(buffer, &iter, 
		(gchar *)C_("JPilot", "adds support for PalmOS addressbooks\n"), -1);

#if USE_LDAP
	gtk_text_buffer_insert_pixbuf(buffer, &iter, active_pixbuf);
#else
	gtk_text_buffer_insert_pixbuf(buffer, &iter, inactive_pixbuf);
#endif
	gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, (" LDAP "), -1,
						 "bold", NULL);
	gtk_text_buffer_insert(buffer, &iter, 
		(gchar *)C_("LDAP", "adds support for LDAP shared addressbooks\n"), -1);

#if HAVE_LIBETPAN
	gtk_text_buffer_insert_pixbuf(buffer, &iter, active_pixbuf);
#else
	gtk_text_buffer_insert_pixbuf(buffer, &iter, inactive_pixbuf);
#endif
	gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, (" libetpan "), -1,
						 "bold", NULL);
	gtk_text_buffer_insert(buffer, &iter, 
		(gchar *)C_("libetpan", "adds support for IMAP and NNTP servers\n"), -1);

#if HAVE_LIBSM
	gtk_text_buffer_insert_pixbuf(buffer, &iter, active_pixbuf);
#else
	gtk_text_buffer_insert_pixbuf(buffer, &iter, inactive_pixbuf);
#endif
	gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, (" libSM "), -1,
						 "bold", NULL);
	gtk_text_buffer_insert(buffer, &iter, 
		(gchar *)C_("libSM", "adds support for session handling\n"), -1);

#if HAVE_NETWORKMANAGER_SUPPORT
	gtk_text_buffer_insert_pixbuf(buffer, &iter, active_pixbuf);
#else
	gtk_text_buffer_insert_pixbuf(buffer, &iter, inactive_pixbuf);
#endif
	gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, (" NetworkManager "), -1,
						 "bold", NULL);
	gtk_text_buffer_insert(buffer, &iter,
		(gchar *)C_("NetworkManager", "adds support for detection of network connection changes\n"), -1);

	return scrolledwin;
}
Beispiel #24
0
static void field_instruction_end(ParserContext *ctx)
{
	FieldInstructionState *state = get_state(ctx);
	gchar *field_type, *buffer;
	GSList *switches = NULL, *formatswitches = NULL, *iter;
	const FieldInfo *field_info = fields;
	GScanner *tokenizer = g_scanner_new(&field_parser);
	
	g_scanner_input_text(tokenizer, state->scanbuffer->str, strlen(state->scanbuffer->str));
	
	/* Get field type */
	if(!(field_type = get_string_token(tokenizer)))
		return;

	/* Determine if field type is supported and get switches and arguments */
	while(field_info->name != NULL)
	{
	    if(g_ascii_strcasecmp(field_type, field_info->name) == 0)
	    {
	        state->type = field_info->type;
	        switches = get_switches(tokenizer, switches, field_info->switches, field_info->argswitches, field_info->wideswitches, field_info->wideargswitches);
	        if(field_info->has_argument)
	        {
	            if(!(buffer = get_string_token(tokenizer)))
	                return;
	            state->argument = g_strdup(buffer);
	            switches = get_switches(tokenizer, switches, field_info->switches, field_info->argswitches, field_info->wideswitches, field_info->wideargswitches);
	        }
	        break;
	    }
	    field_info++;
	}
	if(field_info->name == NULL) /* Field name wasn't found in list */
	{
		g_warning(_("'%s' field not supported"), field_type);
		g_scanner_destroy(tokenizer);
		return;
	}

	formatswitches = get_switches(tokenizer, formatswitches, "", "@#*", "", "");
	for(iter = formatswitches; iter; iter = g_slist_next(iter))
	{
		SwitchInfo *info = (SwitchInfo *)iter->data;
		/* Parse a date format consisting of \@ and a string */
		if(strcmp(info->switchname, "@") == 0)
			state->date_format = g_strdup(info->switcharg);
		/* Parse a numeric format consisting of \# and a string */
		else if(strcmp(info->switchname, "#") == 0)
			state->numeric_format = g_strdup(info->switcharg);
		/* Parse a general format consisting of \* and a keyword */
		else if(strcmp(info->switchname, "*") == 0)
		{
			if(strcmp(info->switcharg, "ALPHABETIC") == 0)
				state->general_number_format = NUMBER_ALPHABETIC;
			else if(strcmp(info->switcharg, "alphabetic") == 0)
				state->general_number_format = NUMBER_alphabetic;
			else if(strcmp(info->switcharg, "Arabic") == 0)
				state->general_number_format = NUMBER_ARABIC;
			else if(strcmp(info->switcharg, "ArabicDash") == 0)
				state->general_number_format = NUMBER_ARABIC_DASH;
			else if(strcmp(info->switcharg, "CIRCLENUM") == 0)
				state->general_number_format = NUMBER_CIRCLENUM;
			else if(strcmp(info->switcharg, "GB1") == 0)
				state->general_number_format = NUMBER_DECIMAL_ENCLOSED_PERIOD;
			else if(strcmp(info->switcharg, "GB2") == 0)
				state->general_number_format = NUMBER_DECIMAL_ENCLOSED_PARENTHESES;
			else if(strcmp(info->switcharg, "Hex") == 0)
				state->general_number_format = NUMBER_HEX;
			else if(strcmp(info->switcharg, "MERGEFORMATINET") == 0)
				; /* ignore */
			else if(strcmp(info->switcharg, "Ordinal") == 0)
				state->general_number_format = NUMBER_ORDINAL;
			else if(strcmp(info->switcharg, "Roman") == 0)
				state->general_number_format = NUMBER_ROMAN;
			else if(strcmp(info->switcharg, "roman") == 0)
				state->general_number_format = NUMBER_roman;
			else
				g_warning(_("Format '%s' not supported"), info->switcharg);
				/* Just continue */
		}
	}

    Destination *fielddest = g_queue_peek_nth(ctx->destination_stack, 1);
    FieldState *fieldstate = g_queue_peek_tail(fielddest->state_stack);

	switch(state->type)
	{
		case FIELD_TYPE_HYPERLINK:
		    /* Actually inserting hyperlinks into the text buffer is a whole 
		    security can of worms I don't want to open! Just use field result */
		    fieldstate->ignore_field_result = FALSE;
			break;

		case FIELD_TYPE_INCLUDEPICTURE:
		{
			GError *error = NULL;
			gchar **pathcomponents = g_strsplit(state->argument, "\\", 0);
			gchar *realfilename = g_build_filenamev(pathcomponents);
			
			g_strfreev(pathcomponents);
			GdkPixbuf *picture = gdk_pixbuf_new_from_file(realfilename, &error);
			if(!picture)
				g_warning(_("Error loading picture from file '%s': %s"), realfilename, error->message);
			else
			{
				/* Insert picture into text buffer */
				GtkTextIter iter;
				gtk_text_buffer_get_iter_at_mark(ctx->textbuffer, &iter, ctx->endmark);
				gtk_text_buffer_insert_pixbuf(ctx->textbuffer, &iter, picture);
				g_object_unref(picture);
			}
			g_free(realfilename);
		}
		    /* Don't use calculated field result */
		    fieldstate->ignore_field_result = TRUE;
			break;

		case FIELD_TYPE_PAGE:
		{
			gchar *output = format_integer(1, state->general_number_format);
			GtkTextIter iter;
			gtk_text_buffer_get_iter_at_mark(ctx->textbuffer, &iter, ctx->endmark);
			gtk_text_buffer_insert(ctx->textbuffer, &iter, output, -1);
			g_free(output);
		}
		    /* Don't use calculated field result */
		    fieldstate->ignore_field_result = TRUE;
			break;
			
		default:
			g_assert_not_reached();
	}
	
	g_free(state->argument);
	g_free(state->date_format);
	g_free(state->numeric_format);
	g_slist_foreach(switches, (GFunc)free_switch_info, NULL);
	g_slist_foreach(formatswitches, (GFunc)free_switch_info, NULL);
	g_scanner_destroy(tokenizer);
}
Beispiel #25
0
static void
insert_text (GtkTextBuffer *buffer)
{
  GtkTextIter iter;
  GtkTextIter start, end;
  GdkPixbuf *pixbuf;
  GtkIconTheme *icon_theme;

  icon_theme = gtk_icon_theme_get_default ();
  pixbuf = gtk_icon_theme_load_icon (icon_theme,
                                     "gtk3-demo",
                                     32,
                                     GTK_ICON_LOOKUP_GENERIC_FALLBACK,
                                     NULL);
  g_assert (pixbuf);

  /* get start of buffer; each insertion will revalidate the
   * iterator to point to just after the inserted text.
   */
  gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0);

  gtk_text_buffer_insert (buffer, &iter,
      "The text widget can display text with all kinds of nifty attributes. "
      "It also supports multiple views of the same buffer; this demo is "
      "showing the same buffer in two places.\n\n", -1);

  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
                                            "Font styles. ", -1,
                                            "heading", NULL);

  gtk_text_buffer_insert (buffer, &iter, "For example, you can have ", -1);
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
                                            "italic", -1,
                                            "italic", NULL);
  gtk_text_buffer_insert (buffer, &iter, ", ", -1);
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
                                            "bold", -1,
                                            "bold", NULL);
  gtk_text_buffer_insert (buffer, &iter, ", or ", -1);
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
                                            "monospace (typewriter)", -1,
                                            "monospace", NULL);
  gtk_text_buffer_insert (buffer, &iter, ", or ", -1);
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
                                            "big", -1,
                                            "big", NULL);
  gtk_text_buffer_insert (buffer, &iter, " text. ", -1);
  gtk_text_buffer_insert (buffer, &iter,
      "It's best not to hardcode specific text sizes; you can use relative "
      "sizes as with CSS, such as ", -1);
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
                                            "xx-small", -1,
                                            "xx-small", NULL);
  gtk_text_buffer_insert (buffer, &iter, " or ", -1);
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
                                            "x-large", -1,
                                            "x-large", NULL);
  gtk_text_buffer_insert (buffer, &iter,
      " to ensure that your program properly adapts if the user changes the "
      "default font size.\n\n", -1);

  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Colors. ", -1,
                                            "heading", NULL);

  gtk_text_buffer_insert (buffer, &iter, "Colors such as ", -1);
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
                                            "a blue foreground", -1,
                                            "blue_foreground", NULL);
  gtk_text_buffer_insert (buffer, &iter, " or ", -1);
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
                                            "a red background", -1,
                                            "red_background", NULL);
  gtk_text_buffer_insert (buffer, &iter, " or even ", -1);
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
                                            "a blue foreground on red background", -1,
                                            "blue_foreground",
                                            "red_background",
                                            NULL);
  gtk_text_buffer_insert (buffer, &iter, " (select that to read it) can be used.\n\n", -1);

  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
                                            "Underline, strikethrough, and rise. ", -1,
                                            "heading", NULL);

  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
                                            "Strikethrough", -1,
                                            "strikethrough", NULL);
  gtk_text_buffer_insert (buffer, &iter, ", ", -1);
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
                                            "underline", -1,
                                            "underline", NULL);
  gtk_text_buffer_insert (buffer, &iter, ", ", -1);
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
                                            "double underline", -1,
                                            "double_underline", NULL);
  gtk_text_buffer_insert (buffer, &iter, ", ", -1);
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
                                            "superscript", -1,
                                            "superscript", NULL);
  gtk_text_buffer_insert (buffer, &iter, ", and ", -1);
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
                                            "subscript", -1,
                                            "subscript", NULL);
  gtk_text_buffer_insert (buffer, &iter, " are all supported.\n\n", -1);

  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Images. ", -1,
                                            "heading", NULL);

  gtk_text_buffer_insert (buffer, &iter, "The buffer can have images in it: ", -1);
  gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf);
  gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf);
  gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf);
  gtk_text_buffer_insert (buffer, &iter, " for example.\n\n", -1);

  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Spacing. ", -1,
                                            "heading", NULL);

  gtk_text_buffer_insert (buffer, &iter,
      "You can adjust the amount of space before each line.\n", -1);

  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
      "This line has a whole lot of space before it.\n", -1,
      "big_gap_before_line", "wide_margins", NULL);
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
      "You can also adjust the amount of space after each line; "
      "this line has a whole lot of space after it.\n", -1,
      "big_gap_after_line", "wide_margins", NULL);

  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
      "You can also adjust the amount of space between wrapped lines; "
      "this line has extra space between each wrapped line in the same "
      "paragraph. To show off wrapping, some filler text: the quick "
      "brown fox jumped over the lazy dog. Blah blah blah blah blah "
      "blah blah blah blah.\n", -1,
      "double_spaced_line", "wide_margins", NULL);

  gtk_text_buffer_insert (buffer, &iter,
      "Also note that those lines have extra-wide margins.\n\n", -1);

  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
                                            "Editability. ", -1,
                                            "heading", NULL);

  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
      "This line is 'locked down' and can't be edited by the user - just "
      "try it! You can't delete this line.\n\n", -1,
      "not_editable", NULL);

  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
                                            "Wrapping. ", -1,
                                            "heading", NULL);

  gtk_text_buffer_insert (buffer, &iter,
      "This line (and most of the others in this buffer) is word-wrapped, "
      "using the proper Unicode algorithm. Word wrap should work in all "
      "scripts and languages that GTK+ supports. Let's make this a long "
      "paragraph to demonstrate: blah blah blah blah blah blah blah blah "
      "blah blah blah blah blah blah blah blah blah blah blah\n\n", -1);

  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
      "This line has character-based wrapping, and can wrap between any two "
      "character glyphs. Let's make this a long paragraph to demonstrate: "
      "blah blah blah blah blah blah blah blah blah blah blah blah blah blah "
      "blah blah blah blah blah\n\n", -1, "char_wrap", NULL);

  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
      "This line has all wrapping turned off, so it makes the horizontal "
      "scrollbar appear.\n\n\n", -1, "no_wrap", NULL);

  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
                                            "Justification. ", -1,
                                            "heading", NULL);

  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
                                            "\nThis line has center justification.\n", -1,
                                            "center", NULL);

  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
                                            "This line has right justification.\n", -1,
                                            "right_justify", NULL);

  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
      "\nThis line has big wide margins. Text text text text text text text "
      "text text text text text text text text text text text text text text "
      "text text text text text text text text text text text text text text "
      "text.\n", -1, "wide_margins", NULL);

  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
                                            "Internationalization. ", -1,
                                            "heading", NULL);

  gtk_text_buffer_insert (buffer, &iter,
      "You can put all sorts of Unicode text in the buffer.\n\nGerman "
      "(Deutsch S\303\274d) Gr\303\274\303\237 Gott\nGreek "
      "(\316\225\316\273\316\273\316\267\316\275\316\271\316\272\316\254) "
      "\316\223\316\265\316\271\316\254 \317\203\316\261\317\202\nHebrew      "
      "\327\251\327\234\327\225\327\235\nJapanese "
      "(\346\227\245\346\234\254\350\252\236)\n\nThe widget properly handles "
      "bidirectional text, word wrapping, DOS/UNIX/Unicode paragraph separators, "
      "grapheme boundaries, and so on using the Pango internationalization "
      "framework.\n", -1);

  gtk_text_buffer_insert (buffer, &iter,
      "Here's a word-wrapped quote in a right-to-left language:\n", -1);
  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
      "\331\210\331\202\330\257 \330\250\330\257\330\243 "
      "\330\253\331\204\330\247\330\253 \331\205\331\206 "
      "\330\243\331\203\330\253\330\261 \330\247\331\204\331\205\330\244\330\263\330\263\330\247\330\252 "
      "\330\252\331\202\330\257\331\205\330\247 \331\201\331\212 "
      "\330\264\330\250\331\203\330\251 \330\247\331\203\330\263\331\212\331\210\331\206 "
      "\330\250\330\261\330\247\331\205\330\254\331\207\330\247 "
      "\331\203\331\205\331\206\330\270\331\205\330\247\330\252 "
      "\331\204\330\247 \330\252\330\263\330\271\331\211 \331\204\331\204\330\261\330\250\330\255\330\214 "
      "\330\253\331\205 \330\252\330\255\331\210\331\204\330\252 "
      "\331\201\331\212 \330\247\331\204\330\263\331\206\331\210\330\247\330\252 "
      "\330\247\331\204\330\256\331\205\330\263 \330\247\331\204\331\205\330\247\330\266\331\212\330\251 "
      "\330\245\331\204\331\211 \331\205\330\244\330\263\330\263\330\247\330\252 "
      "\331\205\330\247\331\204\331\212\330\251 \331\205\331\206\330\270\331\205\330\251\330\214 "
      "\331\210\330\250\330\247\330\252\330\252 \330\254\330\262\330\241\330\247 "
      "\331\205\331\206 \330\247\331\204\331\206\330\270\330\247\331\205 "
      "\330\247\331\204\331\205\330\247\331\204\331\212 \331\201\331\212 "
      "\330\250\331\204\330\257\330\247\331\206\331\207\330\247\330\214 "
      "\331\210\331\204\331\203\331\206\331\207\330\247 \330\252\330\252\330\256\330\265\330\265 "
      "\331\201\331\212 \330\256\330\257\331\205\330\251 \331\202\330\267\330\247\330\271 "
      "\330\247\331\204\331\205\330\264\330\261\331\210\330\271\330\247\330\252 "
      "\330\247\331\204\330\265\330\272\331\212\330\261\330\251. \331\210\330\243\330\255\330\257 "
      "\330\243\331\203\330\253\330\261 \331\207\330\260\331\207 "
      "\330\247\331\204\331\205\330\244\330\263\330\263\330\247\330\252 "
      "\331\206\330\254\330\247\330\255\330\247 \331\207\331\210 "
      "\302\273\330\250\330\247\331\206\331\203\331\210\330\263\331\210\331\204\302\253 "
      "\331\201\331\212 \330\250\331\210\331\204\331\212\331\201\331\212\330\247.\n\n", -1,
                                                "rtl_quote", NULL);

  gtk_text_buffer_insert (buffer, &iter,
                          "You can put widgets in the buffer: Here's a button: ", -1);
  gtk_text_buffer_create_child_anchor (buffer, &iter);
  gtk_text_buffer_insert (buffer, &iter, " and a menu: ", -1);
  gtk_text_buffer_create_child_anchor (buffer, &iter);
  gtk_text_buffer_insert (buffer, &iter, " and a scale: ", -1);
  gtk_text_buffer_create_child_anchor (buffer, &iter);
  gtk_text_buffer_insert (buffer, &iter, " and an animation: ", -1);
  gtk_text_buffer_create_child_anchor (buffer, &iter);
  gtk_text_buffer_insert (buffer, &iter, " finally a text entry: ", -1);
  gtk_text_buffer_create_child_anchor (buffer, &iter);
  gtk_text_buffer_insert (buffer, &iter, ".\n", -1);

  gtk_text_buffer_insert (buffer, &iter,
      "\n\nThis demo doesn't demonstrate all the GtkTextBuffer features; "
      "it leaves out, for example: invisible/hidden text, tab stops, "
      "application-drawn areas on the sides of the widget for displaying "
      "breakpoints and such...", -1);

  /* Apply word_wrap tag to whole buffer */
  gtk_text_buffer_get_bounds (buffer, &start, &end);
  gtk_text_buffer_apply_tag_by_name (buffer, "word_wrap", &start, &end);

  g_object_unref (pixbuf);
}