예제 #1
0
void
tViewer::init ()
{
	layout_w=NULL;
	layout_m=NULL;
	gc = gdk_gc_new (g_pReciteWord->window->window);
	cmap = gdk_rgb_get_colormap();
}
예제 #2
0
GtkWidget*
gtk_xtbin_new (GdkWindow *parent_window, String * f)
{
  GtkXtBin *xtbin;
  gpointer user_data;

  assert(parent_window != NULL);
  xtbin = g_object_new (GTK_TYPE_XTBIN, NULL);

  if (!xtbin)
    return (GtkWidget*)NULL;

  if (f)
    fallback = f;

  /* Initialize the Xt toolkit */
  xtbin->parent_window = parent_window;

  xt_client_init(&(xtbin->xtclient), 
      GDK_VISUAL_XVISUAL(gdk_rgb_get_visual()),
      GDK_COLORMAP_XCOLORMAP(gdk_rgb_get_colormap()),
      gdk_rgb_get_visual()->depth);

  if (!xtbin->xtclient.xtdisplay) {
    /* If XtOpenDisplay failed, we can't go any further.
     *  Bail out.
     */
#ifdef DEBUG_XTBIN
    printf("gtk_xtbin_init: XtOpenDisplay() returned NULL.\n");
#endif
    g_free (xtbin);
    return (GtkWidget *)NULL;
  }

  /* Launch X event loop */
  xt_client_xloop_create();

  /* Build the hierachy */
  xtbin->xtdisplay = xtbin->xtclient.xtdisplay;
  gtk_widget_set_parent_window(GTK_WIDGET(xtbin), parent_window);
  gdk_window_get_user_data(xtbin->parent_window, &user_data);
  if (user_data)
    gtk_container_add(GTK_CONTAINER(user_data), GTK_WIDGET(xtbin));

  /* This GtkSocket has a visible window, but the Xt plug will cover this
   * window.  Normally GtkSockets let the X server paint their background and
   * this would happen immediately (before the plug is mapped).  Setting the
   * background to None prevents the server from painting this window,
   * avoiding flicker.
   */
  gtk_widget_realize(GTK_WIDGET(xtbin));
  gdk_window_set_back_pixmap(GTK_WIDGET(xtbin)->window, NULL, FALSE);

  return GTK_WIDGET (xtbin);
}
예제 #3
0
/**
 * gdk_pixbuf_render_pixmap_and_mask:
 * @pixbuf: A pixbuf.
 * @pixmap_return: Location to store a pointer to the created pixmap,
 *   or %NULL if the pixmap is not needed.
 * @mask_return: Location to store a pointer to the created mask,
 *   or %NULL if the mask is not needed.
 * @alpha_threshold: Threshold value for opacity values.
 *
 * Creates a pixmap and a mask bitmap which are returned in the @pixmap_return
 * and @mask_return arguments, respectively, and renders a pixbuf and its
 * corresponding thresholded alpha mask to them.  This is merely a convenience
 * function; applications that need to render pixbufs with dither offsets or to
 * given drawables should use gdk_draw_pixbuf() and gdk_pixbuf_render_threshold_alpha().
 *
 * The pixmap that is created is created for the colormap returned
 * by gdk_rgb_get_colormap(). You normally will want to instead use
 * the actual colormap for a widget, and use
 * gdk_pixbuf_render_pixmap_and_mask_for_colormap().
 *
 * If the pixbuf does not have an alpha channel, then *@mask_return will be set
 * to %NULL.
 **/
void
gdk_pixbuf_render_pixmap_and_mask (GdkPixbuf  *pixbuf,
				   GdkPixmap **pixmap_return,
				   GdkBitmap **mask_return,
				   int         alpha_threshold)
{
  gdk_pixbuf_render_pixmap_and_mask_for_colormap (pixbuf,
						  gdk_rgb_get_colormap (),
						  pixmap_return, mask_return,
						  alpha_threshold);
}
예제 #4
0
static void do_gtkdisplay(void)
{
    GIOChannel *chan;
    struct imgrect *ir;

    /* have our main loop poll the pipe file descriptor */
    chan = g_io_channel_unix_new(imgpipe_readfd);
    g_io_add_watch(chan, G_IO_IN | G_IO_ERR | G_IO_HUP, (GIOFunc)pipe_event, NULL);
    fcntl(imgpipe_readfd, F_SETFL, O_NONBLOCK);

    /* set up list of image rectangles. */
    imgrects = xcalloc(nimgrects = 16, sizeof *imgrects);

    /* do some init thing */
    gtk_init(0, NULL);

    gtk_widget_push_colormap(gdk_rgb_get_colormap());

    /* Make our own window. */
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_widget_set_size_request(window, DEFAULT_WIDTH + 2 * BORDER, DEFAULT_HEIGHT + 2 * BORDER);

    darea = gtk_drawing_area_new();
    gtk_container_add(GTK_CONTAINER(window), darea);
    gtk_widget_set_events(darea, GDK_EXPOSURE_MASK|GDK_BUTTON_PRESS_MASK|GDK_BUTTON_RELEASE_MASK);

    g_signal_connect(G_OBJECT(window), "delete_event", GTK_SIGNAL_FUNC(delete_event), NULL);
    g_signal_connect(G_OBJECT(window), "destroy", GTK_SIGNAL_FUNC(destroy), NULL);

    g_signal_connect(G_OBJECT(darea), "expose-event", GTK_SIGNAL_FUNC(expose_event), NULL);
    g_signal_connect(G_OBJECT(darea), "configure_event", GTK_SIGNAL_FUNC(expose_event), NULL);

    /* mouse button press/release for saving images */
    g_signal_connect(G_OBJECT(darea), "button_press_event", GTK_SIGNAL_FUNC(button_press_event), NULL);
    g_signal_connect(G_OBJECT(darea), "button_release_event", GTK_SIGNAL_FUNC(button_release_event), NULL);

    gtk_widget_show_all(window);

    gtk_main();

    /* Get rid of all remaining images. */
    for (ir = imgrects; ir < imgrects + nimgrects; ++ir)
        if (ir->filename)
            unlink(ir->filename);

    img_delete(backing_image);

    gtk_exit(0);

    return; /* NOTREACHED */
}
예제 #5
0
파일: tab_nav.c 프로젝트: dss91/omgps
static inline void update_skymap()
{
	int i;
	U1 color;
	svinfo_channel_t *sv;

	memset(hash, 0, sizeof(hash));

	for (i=0; i<g_gpsdata.sv_channel_count; i++) {
		sv = &g_gpsdata.sv_channels[i];
		color = (sv->flags & 0x01)? 0x2 : ((sv->cno > 0)? 0x1 : 0x0);
		hash[i] = color | (sv->elevation << 8) | (sv->azimuth << 24);
	}

	if (memcmp(hash, last_hash, sizeof(hash)) == 0)
		return;

	memcpy(last_hash, hash, sizeof(last_hash));

	int center_x = da_width >> 1;
	int center_y = da_height >> 1;

	int off_x = center_x - bg_image_r;
	int off_y = center_y - bg_image_r;

	if (g_view.sky_pixbuf) {
		gdk_draw_pixbuf (g_view.pixmap, g_context.drawingarea_bggc, g_view.sky_pixbuf,
			0, 0, off_x, off_y, bg_image_d, bg_image_d, GDK_RGB_DITHER_NONE, -1, -1);
		draw_skymap_fg(g_view.pixmap);
		gdk_draw_drawable (skymap_da->window, g_context.drawingarea_bggc, g_view.pixmap,
			off_x, off_y, off_x, off_y, bg_image_d, bg_image_d);
	} else {
		gdk_draw_rectangle (skymap_da->window, skymap_da->style->bg_gc[GTK_STATE_NORMAL], TRUE, 0, 0, da_width, da_height);
		gdk_draw_line(skymap_da->window, g_context.grid_line_gc, off_x, center_y, da_width - off_x, center_y);
		gdk_draw_line(skymap_da->window, g_context.grid_line_gc, center_x, off_y, center_x, da_height - off_y);

		int d;
		int R = bg_image_r - (EDGE >> 1);
		for (i=1; i<=9; i++) {
			d = R * i / 9.0;
			gdk_draw_arc(skymap_da->window, g_context.grid_line_gc, FALSE,
				center_x - d, center_y - d, d << 1, d << 1, 0, CIRCLE_ARC);
		}
		g_view.sky_pixbuf = gdk_pixbuf_get_from_drawable (NULL, g_view.pixmap,
			gdk_rgb_get_colormap(), 0, 0, 0, 0, bg_image_d, bg_image_d);

		draw_skymap_fg(skymap_da->window);
	}
}
예제 #6
0
void pixmaps_init(void)
{
	if(pixmap_cache) return;

	gtk_widget_push_colormap(gdk_rgb_get_colormap());

	pixmap_cache = g_fscache_new((GFSLoadFunc) image_from_file, NULL, NULL);

	g_timeout_add(10000, purge, NULL);

	/*
	GtkIconFactory *factory;
	int i;
	
	factory = gtk_icon_factory_new();
	for (i = 0; i < G_N_ELEMENTS(stocks); i++)
	{
		GdkPixbuf *pixbuf;
		GError *error = NULL;
		gchar *path;
		GtkIconSet *iset;
		const gchar *name = stocks[i];

		path = g_strconcat(app_dir, "/images/", name, ".png", NULL);
		pixbuf = gdk_pixbuf_new_from_file(path, &error);
		if (!pixbuf)
		{
			g_warning("%s", error->message);
			g_error_free(error);
			pixbuf = gdk_pixbuf_new_from_xpm_data(bad_xpm);
		}
		g_free(path);

		iset = gtk_icon_set_new_from_pixbuf(pixbuf);
		g_object_unref(G_OBJECT(pixbuf));
		gtk_icon_factory_add(factory, name, iset);
		gtk_icon_set_unref(iset);
	}
	gtk_icon_factory_add_default(factory);
	*/

	mount_icon_size = gtk_icon_size_register("rox-mount-size", 14, 14);

	load_default_pixmaps();

	//option_register_widget("thumbs-purge-cache", thumbs_purge_cache);
}
예제 #7
0
int
main (int argc, char **argv)
{   
   GdkWindow     *root;
   GtkWidget     *window;
   GtkWidget     *vbox;
   GtkWidget     *drawing_area;
   GdkPixbuf     *pixbuf;    
   
   pixbuf_init ();

   gtk_init (&argc, &argv);   
   gdk_rgb_set_verbose (TRUE);

   gtk_widget_set_default_colormap (gdk_rgb_get_colormap ());

   root = gdk_get_default_root_window ();
   pixbuf = gdk_pixbuf_get_from_drawable (NULL, root, NULL,
					  0, 0, 0, 0, 150, 160);
   
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   g_signal_connect (window, "delete_event",
		     G_CALLBACK (close_app), NULL);
   g_signal_connect (window, "destroy",   
		     G_CALLBACK (close_app), NULL);
   
   vbox = gtk_vbox_new (FALSE, 0);
   gtk_container_add (GTK_CONTAINER (window), vbox);  
   
   drawing_area = gtk_drawing_area_new ();
   gtk_widget_set_size_request (GTK_WIDGET (drawing_area),
                                gdk_pixbuf_get_width (pixbuf),
                                gdk_pixbuf_get_height (pixbuf));
   g_signal_connect (drawing_area, "expose_event",
		     G_CALLBACK (expose_cb), NULL);

   g_signal_connect (drawing_area, "configure_event",
		     G_CALLBACK (configure_cb), NULL);
   g_object_set_data (G_OBJECT (drawing_area), "pixbuf", pixbuf);
   gtk_box_pack_start (GTK_BOX (vbox), drawing_area, TRUE, TRUE, 0);
   
   gtk_widget_show_all (window);
   gtk_main ();
   return 0;
}
static void
read_color (GConfClient *client, const char *key, GdkColor *color)
{
        gchar *tmp;
        
        tmp = gconf_client_get_string (client, key, NULL);

        if (tmp != NULL) {
                if (!gdk_color_parse (tmp, color))
                        gdk_color_parse ("black", color);
		g_free (tmp);
        }
        else {
                gdk_color_parse ("black", color);
        }

        gdk_rgb_find_color (gdk_rgb_get_colormap (), color);
}
static void
mate_icon_text_item_render (MateCanvasItem *item, MateCanvasBuf *buffer)
{
    GdkVisual *visual;
    GdkPixmap *pixmap;
    GdkPixbuf *text_pixbuf;
    double affine[6];
    int width, height;

    visual = gdk_rgb_get_visual ();
    art_affine_identity(affine);
    width  = ROUND (item->x2 - item->x1);
    height = ROUND (item->y2 - item->y1);

    pixmap = gdk_pixmap_new (NULL, width, height, visual->depth);

    gdk_draw_rectangle (pixmap, GTK_WIDGET (item->canvas)->style->white_gc,
                        TRUE,
                        0, 0,
                        width,
                        height);

    /* use a common routine to draw the label into the pixmap */
    mate_icon_text_item_draw (item, pixmap,
                              ROUND (item->x1), ROUND (item->y1),
                              width, height);

    /* turn it into a pixbuf */
    text_pixbuf = gdk_pixbuf_get_from_drawable
                  (NULL, pixmap, gdk_rgb_get_colormap (),
                   0, 0,
                   0, 0,
                   width,
                   height);

    /* draw the pixbuf containing the label */
    draw_pixbuf_aa (text_pixbuf, buffer, affine, ROUND (item->x1), ROUND (item->y1));
    g_object_unref (text_pixbuf);

    buffer->is_bg = FALSE;
    buffer->is_buf = TRUE;
}
예제 #10
0
/* Realize handler for the image view */
static void
image_view_realize (GtkWidget *widget)
{
	GdkWindowAttr attr;
	int attr_mask;
	GdkCursor *cursor;

	g_return_if_fail (widget != NULL);
	g_return_if_fail (IS_IMAGE_VIEW (widget));

	GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);

	attr.window_type = GDK_WINDOW_CHILD;
	attr.x = widget->allocation.x;
	attr.y = widget->allocation.y;
	attr.width = widget->allocation.width;
	attr.height = widget->allocation.height;
	attr.wclass = GDK_INPUT_OUTPUT;
	attr.visual = gdk_rgb_get_visual ();
	attr.colormap = gdk_rgb_get_colormap ();
	attr.event_mask = (gtk_widget_get_events (widget)
			   | GDK_EXPOSURE_MASK
			   | GDK_BUTTON_PRESS_MASK
			   | GDK_BUTTON_RELEASE_MASK
			   | GDK_POINTER_MOTION_MASK
			   | GDK_POINTER_MOTION_HINT_MASK
			   | GDK_SCROLL_MASK
			   | GDK_KEY_PRESS_MASK);

	attr_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;

	widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attr, attr_mask);
	gdk_window_set_user_data (widget->window, widget);

	cursor = cursor_get (widget, CURSOR_HAND_OPEN);
	gdk_window_set_cursor (widget->window, cursor);
	gdk_cursor_unref (cursor);

	widget->style = gtk_style_attach (widget->style, widget->window);

	gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
}
예제 #11
0
파일: tab_nav.c 프로젝트: dss91/omgps
static gboolean skymap_da_configure_event (GtkWidget *widget, GdkEventConfigure *evt, gpointer data)
{
	da_width = evt->width;
	da_height = evt->height;

	#ifndef ICONDIR
	#define ICONDIR "/usr/share/pixmaps/omgps/"
	#endif

	if (g_view.sky_pixbuf) {
		g_object_unref(g_view.sky_pixbuf);
		g_view.sky_pixbuf = NULL;
	}

	GError *error = NULL;
	char *file = ICONDIR"/sky.png";

	/* slightly enlarge the bg image, because fg SV's can be drawn out of biggest circle. */

	if (g_view.sky_pixbuf)
		g_object_unref(g_view.sky_pixbuf);

	int d;
	g_view.sky_pixbuf = gdk_pixbuf_new_from_file_at_scale(file, da_width - EDGE, da_height - EDGE, TRUE, &error);

	bg_image_d = MIN(da_width, da_height);
	bg_image_r = bg_image_d >> 1;

	if (g_view.sky_pixbuf) {
		d = gdk_pixbuf_get_width(g_view.sky_pixbuf);

		int off_x = (da_width - d) >> 1;
		int off_y = (da_height - d) >> 1;
		gdk_draw_rectangle (g_view.pixmap, skymap_da->style->bg_gc[GTK_STATE_NORMAL], TRUE, 0, 0, da_width, da_height);
		gdk_draw_pixbuf (g_view.pixmap, g_context.drawingarea_bggc, g_view.sky_pixbuf,
			0, 0, off_x, off_y, d, d, GDK_RGB_DITHER_NONE, -1, -1);
		g_object_unref(g_view.sky_pixbuf);
		off_x = (da_width - bg_image_d) >> 1;
		off_y = (da_height - bg_image_d) >> 1;
		g_view.sky_pixbuf = gdk_pixbuf_get_from_drawable (NULL, g_view.pixmap,
			gdk_rgb_get_colormap(), off_x, off_y, 0, 0, bg_image_d, bg_image_d);
	}
예제 #12
0
void
gnc_gnome_init (int argc, char **argv, const char * version)
{
    GError *error = NULL;
    gchar *prefix = gnc_path_get_prefix ();
    gchar *pkgsysconfdir = gnc_path_get_pkgsysconfdir ();
    gchar *pkgdatadir = gnc_path_get_pkgdatadir ();
    gchar *pkglibdir = gnc_path_get_pkglibdir ();
    gboolean installation_ok = TRUE;

    /* Verify all the various directory before proceeding */
    if (!g_file_test(pkgdatadir, G_FILE_TEST_IS_DIR))
    {
        g_critical("The installation data directory \"%s\" was not found. Your installation is incomplete and cannot be run.", pkgdatadir);
        installation_ok = FALSE;
    }
    if (!g_file_test(pkglibdir, G_FILE_TEST_IS_DIR))
    {
        g_critical("The installation lib directory \"%s\" was not found. Your installation is incomplete and cannot be run.", pkglibdir);
        installation_ok = FALSE;
    }

    if (!g_file_test(pkgsysconfdir, G_FILE_TEST_IS_DIR))
    {
        g_critical("The installation sysconf directory \"%s\" was not found. Your installation is incomplete and cannot be run.", pkgsysconfdir);
        installation_ok = FALSE;
    }

    gnc_gtk_add_rc_file();
    gnucash_program = gnome_program_init(
                          "gnucash", version, LIBGNOMEUI_MODULE,
                          argc, argv,
                          GNOME_PARAM_APP_PREFIX, prefix,
                          GNOME_PARAM_APP_SYSCONFDIR, pkgsysconfdir,
                          GNOME_PARAM_APP_DATADIR, pkgdatadir,
                          GNOME_PARAM_APP_LIBDIR, pkglibdir,
                          GNOME_PARAM_NONE);
    if (!installation_ok)
    {
        /* The following string does not need translation because if
         * it shows up, the program is unusable anyway. */
        gnc_error_dialog(NULL, "The installation directories were not found.\n\ndatadir=%s\nlibdir=%s\nsysconfdir=%s\n\nYour installation is incomplete and cannot be run.",
                         pkgdatadir, pkglibdir, pkgsysconfdir);
        /* gnc_error_dialog must not be called before gnome_program_init. */
    }

    g_free (prefix);
    g_free (pkgsysconfdir);
    g_free (pkgdatadir);
    g_free (pkglibdir);

    /* Did the installation directory check fail? Terminate
     * immediately because it will inevitably fail in the glade file
     * lookup. */
    if (!installation_ok)
    {
        /* No correct installation? Shut down immediately. */
        exit(-1);
    }

#ifdef G_OS_WIN32
    /* workaround for bug #421792 */
    xmlCleanupInputCallbacks();
#endif

    /* initialization required for gtkhtml (is it also needed for webkit?) */
    gtk_widget_set_default_colormap (gdk_rgb_get_colormap ());

    /* use custom icon */
    {
        int idx;
        char *icon_filenames[] = {"gnucash-icon-16x16.png",
                                  "gnucash-icon-32x32.png",
                                  "gnucash-icon-48x48.png",
                                  NULL
                                 };
        GList *icons = NULL;
        char *fullname, *name_iter;

        for (idx = 0; icon_filenames[idx] != NULL; idx++)
        {
            GdkPixbuf *buf = NULL;

            fullname = gnc_gnome_locate_pixmap(icon_filenames[idx]);
            if (fullname == NULL)
            {
                g_warning("couldn't find icon file [%s]", icon_filenames[idx]);
                continue;
            }

            buf = gnc_gnome_get_gdkpixbuf(fullname);
            if (buf == NULL)
            {
                g_warning("error loading image from [%s]", fullname);
                g_free(fullname);
                continue;
            }
            g_free(fullname);
            icons = g_list_append(icons, buf);
        }

        gtk_window_set_default_icon_list(icons);
        g_list_foreach(icons, (GFunc)g_object_unref, NULL);
        g_list_free(icons);
    }

    assistant_gconf_install_check_schemas();

    return;
}
예제 #13
0
GtkWidget*
gtk_xtbin_new (GdkWindow *parent_window, String * f)
{
  GtkXtBin *xtbin;
  gpointer user_data;

  assert(parent_window != NULL);
  xtbin = g_object_new (GTK_TYPE_XTBIN, NULL);

  if (!xtbin)
    return (GtkWidget*)NULL;

  if (f)
    fallback = f;

  /* Initialize the Xt toolkit */
  xtbin->parent_window = parent_window;

  xt_client_init(&(xtbin->xtclient), 
      GDK_VISUAL_XVISUAL(gdk_rgb_get_visual()),
      GDK_COLORMAP_XCOLORMAP(gdk_rgb_get_colormap()),
      gdk_rgb_get_visual()->depth);

  if (!xtbin->xtclient.xtdisplay) {
    /* If XtOpenDisplay failed, we can't go any further.
     *  Bail out.
     */
#ifdef DEBUG_XTBIN
    printf("gtk_xtbin_init: XtOpenDisplay() returned NULL.\n");
#endif
    g_free (xtbin);
    return (GtkWidget *)NULL;
  }

  /* If this is the first running widget, hook this display into the
     mainloop */
  if (0 == num_widgets) {
    int           cnumber;
    /*
     * hook Xt event loop into the glib event loop.
     */

    /* the assumption is that gtk_init has already been called */
    GSource* gs = g_source_new(&xt_event_funcs, sizeof(GSource));
      if (!gs) {
       return NULL;
      }
    
    g_source_set_priority(gs, GDK_PRIORITY_EVENTS);
    g_source_set_can_recurse(gs, TRUE);
    tag = g_source_attach(gs, (GMainContext*)NULL);
#ifdef VMS
    cnumber = XConnectionNumber(xtdisplay);
#else
    cnumber = ConnectionNumber(xtdisplay);
#endif
    xt_event_poll_fd.fd = cnumber;
    xt_event_poll_fd.events = G_IO_IN; 
    xt_event_poll_fd.revents = 0;    /* hmm... is this correct? */

    g_main_context_add_poll ((GMainContext*)NULL, 
                             &xt_event_poll_fd, 
                             G_PRIORITY_LOW);
    /* add a timer so that we can poll and process Xt timers */
    xt_polling_timer_id =
      g_timeout_add(25,
                    (GtkFunction)xt_event_polling_timer_callback,
                    xtdisplay);
  }

  /* Bump up our usage count */
  num_widgets++;

  /* Build the hierachy */
  xtbin->xtdisplay = xtbin->xtclient.xtdisplay;
  gtk_widget_set_parent_window(GTK_WIDGET(xtbin), parent_window);
  gdk_window_get_user_data(xtbin->parent_window, &user_data);
  if (user_data)
    gtk_container_add(GTK_CONTAINER(user_data), GTK_WIDGET(xtbin));

  /* This GtkSocket has a visible window, but the Xt plug will cover this
   * window.  Normally GtkSockets let the X server paint their background and
   * this would happen immediately (before the plug is mapped).  Setting the
   * background to None prevents the server from painting this window,
   * avoiding flicker.
   */
  gtk_widget_realize(GTK_WIDGET(xtbin));
  gdk_window_set_back_pixmap(GTK_WIDGET(xtbin)->window, NULL, FALSE);

  return GTK_WIDGET (xtbin);
}
예제 #14
0
파일: testpixbuf.c 프로젝트: Aridna/gtk2
int
main (int argc, char **argv)
{
	int i;
	int found_valid = FALSE;

	GdkPixbuf *pixbuf;
	GdkPixbufLoader *pixbuf_loader;

	pixbuf_init ();

	gtk_init (&argc, &argv);

	/*	gdk_rgb_set_verbose (TRUE);*/

	gtk_widget_set_default_colormap (gdk_rgb_get_colormap ());

	{
		char *tbf_readlen = getenv ("TBF_READLEN");
		if (tbf_readlen) readlen = atoi (tbf_readlen);
	}

	{
		char *tbf_bps = getenv ("TBF_KBPS");
		guint bps;

		if (tbf_bps) {
			bps = atoi (tbf_bps);
			g_print ("Simulating %d kBytes/sec\n", bps);
			readlen = (bps*1024)/10;
		}
	}

	i = 1;
	if (argc == 1) {
                const gchar*** xpmp;
                GError *error = NULL;
		
		pixbuf = gdk_pixbuf_new_from_data (default_image, GDK_COLORSPACE_RGB, FALSE, 8,
						   DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_WIDTH * 3,
						   NULL, NULL);
		new_testrgb_window (pixbuf, NULL);

                xpmp = xpms;
                while (*xpmp) {
                        pixbuf = gdk_pixbuf_new_from_xpm_data (*xpmp);
                        new_testrgb_window (pixbuf, NULL);
                        ++xpmp;
                }

                /* Test loading from inline data. */
                pixbuf = gdk_pixbuf_new_from_inline (-1, apple_red, FALSE, &error);
		if (!pixbuf)
		  {
		    fprintf (stderr, "failed to construct \"red apple\" pixbuf: %s\n",
			     error->message);
		    g_error_free (error);
		  }
		else
		  new_testrgb_window (pixbuf, "Red apple from inlined RLE data");

                pixbuf = gdk_pixbuf_new_from_inline (sizeof (gnome_foot), gnome_foot, TRUE, NULL);
                new_testrgb_window (pixbuf, "GNOME Foot from inlined RLE data");
                
		found_valid = TRUE;
	} else {
		for (i = 1; i < argc; i++) {
                        GError *error;

                        error = NULL;
			pixbuf = gdk_pixbuf_new_from_file (argv[i], &error);

                        if (pixbuf == NULL) {
                                g_warning ("Error loading image: %s",
                                           error->message);
                                g_error_free (error);
                        }
                        
#if 0
			pixbuf = gdk_pixbuf_rotate (pixbuf, 10.0);
#endif

			if (pixbuf) {
				new_testrgb_window (pixbuf, "File");
				found_valid = TRUE;
			}
		}
#if 1	
                {
                        GtkWidget* rgb_window = NULL;
			ProgressFileStatus   status;

                        pixbuf_loader = gdk_pixbuf_loader_new ();
			status.loader = pixbuf_loader;

			status.rgbwin = &rgb_window;

			status.buf = g_malloc (readlen);

#if 0
			g_signal_connect (pixbuf_loader, "size_prepared", 
					  G_CALLBACK (size_func), NULL);
#endif

                        g_signal_connect (pixbuf_loader, "area_prepared",
					  G_CALLBACK (progressive_prepared_callback),
					  &rgb_window);
                        g_signal_connect (pixbuf_loader, "area_updated",
					  G_CALLBACK (progressive_updated_callback),
					  &rgb_window);
			
                        status.imagefile = fopen (argv[1], "r");
                        g_assert (status.imagefile != NULL);

			status.readlen = readlen;

                        status.timeout = gdk_threads_add_timeout (100, update_timeout, &status);
                }
#endif
	}

	if (found_valid)
		gtk_main ();

	return 0;
}
예제 #15
0
void
gnc_gnome_init (int argc, char **argv, const char * version)
{
    GError *error = NULL;
    gchar *prefix = gnc_path_get_prefix ();
    gchar *pkgsysconfdir = gnc_path_get_pkgsysconfdir ();
    gchar *pkgdatadir = gnc_path_get_pkgdatadir ();
    gchar *pkglibdir = gnc_path_get_pkglibdir ();

    gnc_gtk_add_rc_file();
    gnucash_program = gnome_program_init(
                          "gnucash", version, LIBGNOMEUI_MODULE,
                          argc, argv,
                          GNOME_PARAM_APP_PREFIX, prefix,
                          GNOME_PARAM_APP_SYSCONFDIR, pkgsysconfdir,
                          GNOME_PARAM_APP_DATADIR, pkgdatadir,
                          GNOME_PARAM_APP_LIBDIR, pkglibdir,
                          GNOME_PARAM_NONE);
    g_free (prefix);
    g_free (pkgsysconfdir);
    g_free (pkgdatadir);
    g_free (pkglibdir);

#ifdef G_OS_WIN32
    /* workaround for bug #421792 */
    xmlCleanupInputCallbacks();
#endif

    /* initialization required for gtkhtml */
    gtk_widget_set_default_colormap (gdk_rgb_get_colormap ());

    /* use custom icon */
    {
        int idx;
        char *icon_filenames[] = {"gnucash-icon-16x16.png",
                                  "gnucash-icon-32x32.png",
                                  "gnucash-icon-48x48.png",
                                  NULL
                                 };
        GList *icons = NULL;
        char *fullname, *name_iter;

        for (idx = 0; icon_filenames[idx] != NULL; idx++)
        {
            GdkPixbuf *buf = NULL;

            fullname = gnc_gnome_locate_pixmap(icon_filenames[idx]);
            if (fullname == NULL)
            {
                g_warning("couldn't find icon file [%s]", icon_filenames[idx]);
                continue;
            }

            buf = gnc_gnome_get_gdkpixbuf(fullname);
            if (buf == NULL)
            {
                g_warning("error loading image from [%s]", fullname);
                g_free(fullname);
                continue;
            }
            g_free(fullname);
            icons = g_list_append(icons, buf);
        }

        gtk_window_set_default_icon_list(icons);
        g_list_foreach(icons, (GFunc)g_object_unref, NULL);
        g_list_free(icons);
    }

    druid_gconf_install_check_schemas();

    return;
}
JNIEXPORT void JNICALL 
Java_gnu_java_awt_peer_gtk_GtkToolkit_gtkInit (JNIEnv *env, 
					       jclass clazz __attribute__((unused)),
					       jint portableNativeSync)
{
  int argc = 1;
  char **argv;
  char *homedir, *rcpath = NULL;

  gtkgenericpeer = (*env)->FindClass(env, "gnu/java/awt/peer/gtk/GtkGenericPeer");

  gtkgenericpeer = (*env)->NewGlobalRef(env, gtkgenericpeer);

  printCurrentThreadID = (*env)->GetStaticMethodID (env, gtkgenericpeer,
                                                    "printCurrentThread", "()V");
 
  NSA_INIT (env, gtkgenericpeer);

  g_assert((*env)->GetJavaVM(env, &java_vm) == 0);

  /* GTK requires a program's argc and argv variables, and requires that they
     be valid.  Set it up. */
  argv = (char **) g_malloc (sizeof (char *) * 2);
  argv[0] = (char *) g_malloc(1);
  argv[0][0] = '\0';
  argv[1] = NULL;

  init_glib_threads(env, portableNativeSync);

  /* From GDK 2.0 onwards we have to explicitly call gdk_threads_init */
  gdk_threads_init();

  gtk_init (&argc, &argv);

#if SYNCHRONIZE_GDK
  XSynchronize (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), True);
#endif

  gtk_widget_set_default_colormap (gdk_rgb_get_colormap ());

  /* Make sure queued calls don't get sent to GTK/GDK while 
     we're shutting down. */
  atexit (gdk_threads_enter);

  if ((homedir = getenv ("HOME")))
    {
      rcpath = (char *) g_malloc (strlen (homedir) + strlen (RC_FILE) + 2);
      sprintf (rcpath, "%s/%s", homedir, RC_FILE);
    }
  
  gtk_rc_parse ((rcpath) ? rcpath : RC_FILE);

  g_free (rcpath);
  g_free (argv[0]);
  g_free (argv);

  /* On errors or warning print a whole stacktrace. */
#if GTK_MINOR_VERSION > 4
  old_glog_func = g_log_set_default_handler (&glog_func, NULL);
#endif

  cp_gtk_button_init_jni ();
  cp_gtk_checkbox_init_jni ();
  cp_gtk_choice_init_jni ();
  cp_gtk_component_init_jni ();
  cp_gtk_filedialog_init_jni ();
  cp_gtk_list_init_jni ();
  cp_gtk_menuitem_init_jni ();
  cp_gtk_scrollbar_init_jni ();
  cp_gtk_textcomponent_init_jni ();
  cp_gtk_window_init_jni ();

  cp_gtk_global_window_group = gtk_window_group_new ();

  init_dpi_conversion_factor ();
}
static void setup_font_sample(GtkWidget* darea, Antialiasing antialiasing, Hinting hinting)
{
	const char* string1 = "abcfgop AO ";
	const char* string2 = "abcfgop";

	XftColor black, white;
	XRenderColor rendcolor;

	Display* xdisplay = gdk_x11_get_default_xdisplay();

#if GTK_CHECK_VERSION (3, 0, 0)
	Colormap xcolormap = DefaultColormap(xdisplay, 0);
#else
	GdkColormap* colormap = gdk_rgb_get_colormap();
	Colormap xcolormap = GDK_COLORMAP_XCOLORMAP(colormap);
#endif

#if GTK_CHECK_VERSION (3, 0, 0)
	GdkVisual* visual = gdk_visual_get_system ();
#else
	GdkVisual* visual = gdk_colormap_get_visual(colormap);
#endif
	Visual* xvisual = GDK_VISUAL_XVISUAL(visual);

	FcPattern* pattern;
	XftFont* font1;
	XftFont* font2;
	XGlyphInfo extents1 = { 0 };
	XGlyphInfo extents2 = { 0 };
#if !GTK_CHECK_VERSION (3, 0, 0)
	GdkPixmap* pixmap;
#endif
	XftDraw* draw;
	GdkPixbuf* tmp_pixbuf;
	GdkPixbuf* pixbuf;

	int width, height;
	int ascent, descent;

	pattern = FcPatternBuild (NULL,
		FC_FAMILY, FcTypeString, "Serif",
		FC_SLANT, FcTypeInteger, FC_SLANT_ROMAN,
		FC_SIZE, FcTypeDouble, 18.,
		NULL);
	font1 = open_pattern (pattern, antialiasing, hinting);
	FcPatternDestroy (pattern);

	pattern = FcPatternBuild (NULL,
		FC_FAMILY, FcTypeString, "Serif",
		FC_SLANT, FcTypeInteger, FC_SLANT_ITALIC,
		FC_SIZE, FcTypeDouble, 20.,
		NULL);
	font2 = open_pattern (pattern, antialiasing, hinting);
	FcPatternDestroy (pattern);

	ascent = 0;
	descent = 0;
	
	if (font1)
	{
		XftTextExtentsUtf8 (xdisplay, font1, (unsigned char*) string1,
		strlen (string1), &extents1);
		ascent = MAX (ascent, font1->ascent);
		descent = MAX (descent, font1->descent);
	}

	if (font2)
	{
		XftTextExtentsUtf8 (xdisplay, font2, (unsigned char*) string2, strlen (string2), &extents2);
		ascent = MAX (ascent, font2->ascent);
		descent = MAX (descent, font2->descent);
	}

	width = extents1.xOff + extents2.xOff + 4;
	height = ascent + descent + 2;

#if !GTK_CHECK_VERSION (3, 0, 0)
	pixmap = gdk_pixmap_new (NULL, width, height, visual->depth);
#endif

#if GTK_CHECK_VERSION (3, 0, 0)
	draw = XftDrawCreate (xdisplay, GDK_WINDOW_XID (gdk_screen_get_root_window (gdk_screen_get_default ())), xvisual, xcolormap);
#else
	draw = XftDrawCreate (xdisplay, GDK_DRAWABLE_XID (pixmap), xvisual, xcolormap);
#endif

	rendcolor.red = 0;
	rendcolor.green = 0;
	rendcolor.blue = 0;
	rendcolor.alpha = 0xffff;
	
	XftColorAllocValue(xdisplay, xvisual, xcolormap, &rendcolor, &black);

	rendcolor.red = 0xffff;
	rendcolor.green = 0xffff;
	rendcolor.blue = 0xffff;
	rendcolor.alpha = 0xffff;
	
	XftColorAllocValue(xdisplay, xvisual, xcolormap, &rendcolor, &white);
	XftDrawRect(draw, &white, 0, 0, width, height);
	
	if (font1)
	{
		XftDrawStringUtf8(draw, &black, font1, 2, 2 + ascent, (unsigned char*) string1, strlen(string1));
	}
	
	if (font2)
	{
		XftDrawStringUtf8(draw, &black, font2, 2 + extents1.xOff, 2 + ascent, (unsigned char*) string2, strlen(string2));
	}

	XftDrawDestroy(draw);

	if (font1)
	{
		XftFontClose(xdisplay, font1);
	}
	
	if (font2)
	{
		XftFontClose(xdisplay, font2);
	}

#if GTK_CHECK_VERSION (3, 0, 0)
	tmp_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE,8, width, height);
#else
	tmp_pixbuf = gdk_pixbuf_get_from_drawable(NULL, pixmap, colormap, 0, 0, 0, 0, width, height);
#endif
	pixbuf = gdk_pixbuf_scale_simple(tmp_pixbuf, 1 * width, 1 * height, GDK_INTERP_TILES);

#if !GTK_CHECK_VERSION (3, 0, 0)
	g_object_unref(pixmap);
#endif
	g_object_unref(tmp_pixbuf);

	g_object_set_data_full(G_OBJECT(darea), "sample-pixbuf", pixbuf, (GDestroyNotify) g_object_unref);

#if GTK_CHECK_VERSION (3, 0, 0)
	gtk_widget_set_size_request  (GTK_WIDGET(darea), width + 2, height + 2);
	g_signal_connect(darea, "draw", G_CALLBACK(sample_draw), NULL);
#else
	g_signal_connect(darea, "size_request", G_CALLBACK(sample_size_request), NULL);
	g_signal_connect(darea, "expose_event", G_CALLBACK(sample_expose), NULL);
#endif
}
예제 #18
0
void
testcase_exercise (Testcase* self)
{
	guchar   * gdkdata;
	guchar   * cairodata;
	gsize      index;
	GdkPixbuf* gdk_pixbuf;
	GdkPixbuf* cairo_pixbuf;
	cairo_t* cr;

	g_return_if_fail (IS_TESTCASE (self));

	g_signal_emit (self,
		       testcase_signals[EXERCISE_GDK],
		       0,
		       PRIV(self)->gdk_pixmap,
		       PRIV(self)->gdk_gc);

	cr = gdk_cairo_create (PRIV(self)->cairo_pixmap);
	g_signal_emit (self,
		       testcase_signals[EXERCISE_CAIRO],
		       0,
		       cr,
		       PRIV(self)->cairo_gc);
	cairo_destroy (cr);

	gdk_pixbuf   = gdk_pixbuf_get_from_drawable (NULL,
						     PRIV(self)->gdk_pixmap,
								 gdk_rgb_get_colormap (),
								 0, 0,
								 0, 0,
								 100, 80);
	cairo_pixbuf = gdk_pixbuf_get_from_drawable (NULL,
						     PRIV(self)->cairo_pixmap,
								 gdk_rgb_get_colormap (),
								 0, 0,
								 0, 0,
								 100, 80);

	gdkdata   = gdk_pixbuf_get_pixels (gdk_pixbuf);
	cairodata = gdk_pixbuf_get_pixels (cairo_pixbuf);

	g_return_if_fail (gdk_pixbuf_get_rowstride (gdk_pixbuf) == gdk_pixbuf_get_rowstride (cairo_pixbuf));
	g_return_if_fail (gdk_pixbuf_get_n_channels (gdk_pixbuf) == gdk_pixbuf_get_n_channels (cairo_pixbuf));
	g_return_if_fail (gdk_pixbuf_get_height (gdk_pixbuf) == gdk_pixbuf_get_height (cairo_pixbuf));
	g_return_if_fail (gdk_pixbuf_get_width (gdk_pixbuf) == gdk_pixbuf_get_width (cairo_pixbuf));

	PRIV(self)->passed = TRUE;

	for (index = 0; index < gdk_pixbuf_get_height (gdk_pixbuf) * gdk_pixbuf_get_rowstride (gdk_pixbuf); index++) {
		if (gdkdata[index] != cairodata[index]) {
			gchar* filepath;
			g_warning ("Eeek! Differences at byte %d: %c vs. %c",
				   index,
				   gdkdata[index],
				   cairodata[index]);
			PRIV(self)->passed = FALSE;

			filepath = g_strdup_printf ("%s-gdk.png",
						    g_get_prgname ());
			gdk_pixbuf_save (gdk_pixbuf,
					 filepath,
					 "png",
					 NULL, /* FIXME: handle errors */
					 NULL);
			g_message ("=> wrote gdk image to \"%s\"",
				   filepath);
			g_free (filepath);

			filepath = g_strdup_printf ("%s-cairo.png",
						    g_get_prgname ());
			gdk_pixbuf_save (cairo_pixbuf,
					 filepath,
					 "png",
					 NULL, /* FIXME: handle errors */
					 NULL);
			g_message ("=> wrote cairo image to \"%s\"",
				   filepath);
			g_free (filepath);
			break;
		}
	}

	g_object_unref (gdk_pixbuf);
	g_object_unref (cairo_pixbuf);
}