Displaying xpm images in textview



Hi
I want to display xpm images in a textview along with some text. The problem
is when inserting an xpm image along with few letters and a newline
character ,it forms a small gap in between two rows which detaches the xpm
images. I want it to be continious.

I think textview buffer is allocating some space in bottom for letters such
as g,j,p,y,q...  And if we don't insert letters then images were continious
in all rows. Is there anyway to solve this problem. Please give your
suggestions.

Here is the code,

#include <gtk/gtk.h>
/*
gcc -g -o base gtk_xpm.c `pkg-config --cflags --libs gtk+-2.0 gthread-2.0`
displaying .xpm images in textview using gdkpixbuf
*/

FILE *fp;
GtkTextBuffer *buffer;
GError *error = NULL;
GdkPixbuf *pixbuf;

/* another callback */
static gboolean delete_event( GtkWidget *widget,GdkEvent  *event, gpointer
data )
{
  gtk_main_quit ();
  return FALSE;
}

/* Another callback */
static void destroy( GtkWidget *widget,gpointer   data )
{
  g_print ("Inside destroy function\n");
  gtk_main_quit ();
}

static gint refresh( GtkWidget *widget, gpointer   data )
{
static int cnt=0;
GtkTextIter start, end, ins;
GtkTextMark *ins_mark;
gchar *a="a\n";

ins_mark=gtk_text_buffer_get_insert(GTK_TEXT_BUFFER(buffer));

if(cnt==25)
{
 gtk_text_buffer_get_bounds(buffer,&start,&end);
 gtk_text_buffer_delete(buffer,&start,&end);
 cnt=0;
}
else
{
 gtk_text_buffer_get_iter_at_mark(buffer,&ins,ins_mark);
 gtk_text_buffer_insert_pixbuf(buffer, &ins, GDK_PIXBUF(pixbuf));
 gtk_text_buffer_get_iter_at_mark(buffer,&ins,ins_mark);
 gtk_text_buffer_insert(buffer,&ins,a,-1);
 cnt++;
}
g_print ("Inside refresh function:\n");
usleep(12000);
return TRUE;
}

int main( int   argc,char *argv[] )
{
  GtkWidget *window;
   GtkWidget *box1;
      GtkWidget *view;
      PangoFontDescription *font_desc;

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window), "Display Window");
  gtk_window_set_default_size (GTK_WINDOW (window),750,500);
  g_signal_connect (G_OBJECT (window), "delete_event",
                    G_CALLBACK (delete_event), NULL);
  g_signal_connect (G_OBJECT (window), "destroy",
                    G_CALLBACK (destroy), NULL);


  box1 = gtk_vbox_new (FALSE, 0);
  gtk_container_add (GTK_CONTAINER (window), box1);

  view = gtk_text_view_new ();
  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
  /* Change default font throughout the widget */
  font_desc = pango_font_description_from_string ("Freetype 10");

  pango_font_description_set_size(font_desc,PANGO_SCALE*10);
  gtk_widget_modify_font (view, font_desc);
  pango_font_description_free (font_desc);
  gtk_text_buffer_set_text (buffer,"", -1);
  gtk_box_pack_start (GTK_BOX (box1), view, FALSE, FALSE, 0);

 pixbuf = gdk_pixbuf_new_from_file ("/root/Desktop/gtk/xpm1.xpm",&error);
 if (error)
  {
    g_print("Error on xpm file");
    g_error_free (error);
    return;
  }
 gtk_idle_add((GtkFunction)refresh,NULL );
 gtk_widget_show(view);
 gtk_widget_show (box1);
 gtk_widget_show  (window);

 gtk_main ();
 return 0;
}




And Here is the xpm file content,
/* XPM */
static const char * xpm_data[] = {
"16 20 3 1",
"       c None",
".      c #000000000000",
"X      c #FFFFFFFFFFFF",
"......X.........",
"......X.........",
"......X.........",
"................",
"................",
"................",
"................",
"................",
"................",
"................",
"................",
"................",
"................",
"................",
"................",
"................",
"................",
"................",
"................",
"................"};

/**************************************************************************/

Thanks,
prabahar



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]