Ejemplo n.º 1
0
static void
workrave_timebar_init_ui(WorkraveTimebar *self)
{
  WorkraveTimebarPrivate *priv = WORKRAVE_TIMEBAR_GET_PRIVATE(self);

  priv->style_context = gtk_style_context_new();

  GtkWidgetPath *path = gtk_widget_path_new();
  gtk_widget_path_append_type(path, GTK_TYPE_BUTTON);
  gtk_style_context_set_path(priv->style_context, path);
  gtk_style_context_add_class(priv->style_context, GTK_STYLE_CLASS_TROUGH);
  
  GdkScreen *screen = gdk_screen_get_default();
  priv->pango_context = gdk_pango_context_get_for_screen(screen);

  const PangoFontDescription *font_desc = gtk_style_context_get_font(priv->style_context, GTK_STATE_FLAG_ACTIVE);

  pango_context_set_language(priv->pango_context, gtk_get_default_language());
  pango_context_set_font_description(priv->pango_context, font_desc);

  priv->pango_layout = pango_layout_new(priv->pango_context);
  pango_layout_set_text(priv->pango_layout, "-9:59:59", -1);

  pango_layout_get_pixel_size(priv->pango_layout, &priv->width, &priv->height);

  priv->width = MAX(priv->width + 2 * MARGINX, MIN_HORIZONTAL_BAR_WIDTH);
  priv->height = MAX(priv->height + 2 * MARGINY, MIN_HORIZONTAL_BAR_HEIGHT);

  gtk_widget_path_free(path);
}
Ejemplo n.º 2
0
static void get_color (gint i, gfloat * r, gfloat * g, gfloat * b)
{
    static GdkRGBA c;
    static bool_t valid = FALSE;
    gfloat h, s, v, n;

    if (! valid)
    {
        /* we want a color that matches the current theme
         * selected color of a GtkEntry should be reasonable */
        GtkStyleContext * style = gtk_style_context_new ();
        GtkWidgetPath * path = gtk_widget_path_new ();
        gtk_widget_path_append_type (path, GTK_TYPE_ENTRY);
        gtk_style_context_set_path (style, path);
        gtk_widget_path_free (path);
        gtk_style_context_get_background_color (style, GTK_STATE_FLAG_SELECTED, & c);
        g_object_unref (style);
        valid = TRUE;
    }

    rgb_to_hsv (c.red, c.green, c.blue, & h, & s, & v);

    if (s < 0.1) /* monochrome theme? use blue instead */
    {
        h = 5;
        s = 0.75;
    }

    n = i / (gfloat) (bands - 1);
    s = 1 - 0.9 * n;
    v = 0.75 + 0.25 * n;

    hsv_to_rgb (h, s, v, r, g, b);
}
Ejemplo n.º 3
0
/* FIXME: this doesn't work */
static gboolean
draw_cb_activity (GtkWidget *widget, cairo_t *cr)
{
  GtkStyleContext *context;
  GtkWidgetPath *path;

  context = gtk_widget_get_style_context (widget);
  gtk_style_context_notify_state_change (context,
                                         gtk_widget_get_window (widget),
                                         NULL,
                                         GTK_STATE_FLAG_ACTIVE,
                                         TRUE);

  gtk_style_context_save (context);

  path = gtk_widget_path_new ();
  gtk_widget_path_append_type (path, GTK_TYPE_SPINNER);
  gtk_widget_path_iter_add_class (path, 0, "spinner");
  gtk_style_context_set_path (context, path);
  gtk_widget_path_free (path);

  gtk_style_context_set_state (context, GTK_STATE_FLAG_ACTIVE);
  gtk_render_activity (context, cr, 12, 12, 12, 12);

  gtk_style_context_restore (context);

  return TRUE;
}
Ejemplo n.º 4
0
 ScrollbarStyleContext()
     : m_context(adoptGRef(gtk_style_context_new()))
 {
     GtkWidgetPath* path = gtk_widget_path_new();
     gtk_widget_path_append_type(path, GTK_TYPE_SCROLLBAR);
     gtk_widget_path_iter_add_class(path, 0, GTK_STYLE_CLASS_SCROLLBAR);
     gtk_style_context_set_path(m_context.get(), path);
     gtk_widget_path_free(path);
 }
void getTooltipColors_GtkWidgetPath()
{
#if GTK_CHECK_VERSION(3,20,0)
	if (0 != gtk_check_version(3, 20, 0))
	{
		// 'gtk_widget_path_iter_set_object_name' was introduced in 3.20.0
		printf("With GtkWidgetPath:    Requires 3.20.0\n");
		return;
	}

	// Foreground color is taken from 'tooltip label' css node
	GtkStyleContext* styleContextLabel = gtk_style_context_new();
	{
		GtkWidgetPath* widgetPath = gtk_widget_path_new();
		gtk_widget_path_append_type(widgetPath, 0);
		gtk_widget_path_iter_set_object_name(widgetPath, -1, "tooltip");
		gtk_widget_path_iter_add_class(widgetPath, -1, GTK_STYLE_CLASS_BACKGROUND);
		gtk_widget_path_append_type(widgetPath, GTK_TYPE_LABEL);
		gtk_style_context_set_path(styleContextLabel, widgetPath);
		gtk_widget_path_free(widgetPath);
	}

	// Background color is taken from 'tooltip.background' css node
	GtkStyleContext* styleContextTooltip = gtk_style_context_new();
	{
		GtkWidgetPath* widgetPath = gtk_widget_path_new();
		gtk_widget_path_append_type(widgetPath, 0);
		gtk_widget_path_iter_set_object_name(widgetPath, -1, "tooltip");
		gtk_widget_path_iter_add_class(widgetPath, -1, GTK_STYLE_CLASS_BACKGROUND);
		gtk_style_context_set_path(styleContextTooltip, widgetPath);
		gtk_widget_path_free(widgetPath);
	}

	// Print
	printTooltipColors(styleContextLabel, styleContextTooltip, "GtkWidgetPath");

	// Destroy temporary style contexts
	g_object_unref(styleContextLabel);
	g_object_unref(styleContextTooltip);
#endif // GTK_CHECK_VERSION(3,20,0)
}
Ejemplo n.º 6
0
Archivo: ui.c Proyecto: darkxst/mtest
void
meta_ui_theme_get_frame_borders (MetaUI *ui,
                                 MetaFrameType      type,
                                 MetaFrameFlags     flags,
                                 MetaFrameBorders  *borders)
{
  int text_height;
  GtkStyleContext *style = NULL;
  PangoContext *context;
  const PangoFontDescription *font_desc;
  PangoFontDescription *free_font_desc = NULL;

  if (meta_ui_have_a_theme ())
    {
      context = gtk_widget_get_pango_context (GTK_WIDGET (ui->frames));
      font_desc = meta_prefs_get_titlebar_font ();

      if (!font_desc)
        {
          GdkDisplay *display = gdk_x11_lookup_xdisplay (ui->xdisplay);
          GdkScreen *screen = gdk_display_get_screen (display, XScreenNumberOfScreen (ui->xscreen));
          GtkWidgetPath *widget_path;

          style = gtk_style_context_new ();
          gtk_style_context_set_screen (style, screen);
          widget_path = gtk_widget_path_new ();
          gtk_widget_path_append_type (widget_path, GTK_TYPE_WINDOW);
          gtk_style_context_set_path (style, widget_path);
          gtk_widget_path_free (widget_path);

          gtk_style_context_get (style, GTK_STATE_FLAG_NORMAL, "font", &free_font_desc, NULL);
          font_desc = (const PangoFontDescription *) free_font_desc;
        }

      text_height = meta_pango_font_desc_get_text_height (font_desc, context);

      meta_theme_get_frame_borders (meta_theme_get_current (),
                                    type, text_height, flags,
                                    borders);

      if (free_font_desc)
        pango_font_description_free (free_font_desc);
    }
  else
    {
      meta_frame_borders_clear (borders);
    }

  if (style != NULL)
    g_object_unref (style);
}
Ejemplo n.º 7
0
static GtkStyleContext *
get_style_with_siblings (GtkStyleContext *parent,
                         const char      *selector,
                         const char     **siblings,
                         gint             position)
{
  GtkWidgetPath *path, *siblings_path;
  guint i;

  if (parent)
    path = gtk_widget_path_copy (gtk_style_context_get_path (parent));
  else
    path = gtk_widget_path_new ();

  siblings_path = gtk_widget_path_new ();
  for (i = 0; siblings[i]; i++)
    append_element (siblings_path, siblings[i]);

  gtk_widget_path_append_with_siblings (path, siblings_path, position);
  gtk_widget_path_unref (siblings_path);

  return create_context_for_path (path, parent);
}
static void
test_init_of_theme (void)
{
  GtkStyleContext *context;
  GtkCssProvider *provider;
  GtkWidgetPath *path;
  GdkRGBA before, after;
  char *css;

  /* Test that a style context actually uses the theme loaded for the 
   * screen it is using. If no screen is set, it's the default one.
   */
  context = gtk_style_context_new ();
  path = gtk_widget_path_new ();

  /* Set a path that will have a color set.
   * (This could actually fail if style classes change, so if this test
   *  fails, make sure to have this path represent something sane.)
   */
  gtk_widget_path_append_type (path, GTK_TYPE_WINDOW);
  gtk_widget_path_iter_add_class (path, -1, GTK_STYLE_CLASS_BACKGROUND);
  gtk_style_context_set_path (context, path);
  gtk_widget_path_free (path);

  /* Get the color. This should be initialized by the theme and not be
   * the default. */
  gtk_style_context_get_color (context, gtk_style_context_get_state (context), &before);

  /* Add a style that sets a different color for this widget.
   * This style has a higher priority than fallback, but a lower 
   * priority than the theme. */
  css = g_strdup_printf (".background { color: %s; }",
                         before.alpha < 0.5 ? "black" : "transparent");
  provider = gtk_css_provider_new ();
  gtk_css_provider_load_from_data (provider, css, -1, NULL);
  gtk_style_context_add_provider (context,
                                  GTK_STYLE_PROVIDER (provider),
                                  GTK_STYLE_PROVIDER_PRIORITY_FALLBACK + 1);
  g_object_unref (provider);

  /* Get the color again. */
  gtk_style_context_get_color (context, gtk_style_context_get_state (context), &after);

  /* Because the style we added does not influence the color,
   * the before and after colors should be identical. */
  g_assert (gdk_rgba_equal (&before, &after));

  g_object_unref (context);
}
Ejemplo n.º 9
0
static GtkStyleContext *
get_style (GtkStyleContext *parent,
           const char      *selector)
{
  GtkWidgetPath *path;

  if (parent)
    path = gtk_widget_path_copy (gtk_style_context_get_path (parent));
  else
    path = gtk_widget_path_new ();

  append_element (path, selector);

  return create_context_for_path (path, parent);
}
Ejemplo n.º 10
0
/*
 * frame_update_titlebar_font
 *
 * Returns: void
 * Description: updates the titlebar font from the pango context, should
 * be called whenever the gtk style or font has changed
 */
void
frame_update_titlebar_font (decor_frame_t *frame)
{
    const PangoFontDescription *font_desc;
    PangoFontDescription *free_font_desc;
    PangoFontMetrics *metrics;
    PangoLanguage *lang;

    free_font_desc = NULL;
    frame = gwd_decor_frame_ref (frame);

    font_desc = get_titlebar_font (frame);
    if (!font_desc)
    {
        GtkCssProvider *provider = gtk_css_provider_get_default ();
        GtkStyleContext *context = gtk_style_context_new ();
        GtkWidgetPath *path = gtk_widget_path_new ();

        gtk_widget_path_prepend_type (path, GTK_TYPE_WIDGET);
        gtk_style_context_set_path (context, path);
        gtk_widget_path_free (path);

        gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_FALLBACK);

        gtk_style_context_get (context, GTK_STATE_FLAG_NORMAL, "font", &free_font_desc, NULL);
        font_desc = (const PangoFontDescription *) free_font_desc;
    }

    pango_context_set_font_description (frame->pango_context, font_desc);

    lang    = pango_context_get_language (frame->pango_context);
    metrics = pango_context_get_metrics (frame->pango_context, font_desc, lang);

    frame->text_height = PANGO_PIXELS (pango_font_metrics_get_ascent (metrics) +
				pango_font_metrics_get_descent (metrics));

    gwd_decor_frame_unref (frame);

    pango_font_metrics_unref (metrics);

    if (free_font_desc)
        pango_font_description_free (free_font_desc);
}
Ejemplo n.º 11
0
GR_Font * GR_UnixCairoGraphics::getGUIFont(void)
{
	if (!m_pPFontGUI)
	{
		// get the font resource
#if GTK_CHECK_VERSION(3,0,0)
		GtkStyleContext *tempCtxt = gtk_style_context_new();
		GtkWidgetPath *path = gtk_widget_path_new();
		gtk_widget_path_append_type (path, GTK_TYPE_WINDOW);
		gtk_style_context_set_path(tempCtxt, path);
		gtk_widget_path_free(path);
		const char *guiFontName = pango_font_description_get_family(gtk_style_context_get_font(tempCtxt, GTK_STATE_FLAG_NORMAL));
#else
		GtkStyle *tempStyle = gtk_style_new();
		const char *guiFontName = pango_font_description_get_family(tempStyle->font_desc);
#endif
		if (!guiFontName)
			guiFontName = "'Times New Roman'";

		UT_UTF8String s = XAP_EncodingManager::get_instance()->getLanguageISOName();

		const char * pCountry
			= XAP_EncodingManager::get_instance()->getLanguageISOTerritory();
		
		if(pCountry)
		{
			s += "-";
			s += pCountry;
		}
		
		m_pPFontGUI = new GR_PangoFont(guiFontName, 11.0, this, s.utf8_str(), true);

#if GTK_CHECK_VERSION(3,0,0)
		g_object_unref(G_OBJECT(tempCtxt));
#else
		g_object_unref(G_OBJECT(tempStyle));
#endif
		
		UT_ASSERT(m_pPFontGUI);
	}

	return m_pPFontGUI;
}
static void
test_window (void)
{
  GsdOsdDrawContext ctx;
  ClutterActor *stage, *actor;
  ClutterContent *canvas;
  GtkWidgetPath *widget_path;

  /* create a resizable stage */
  stage = clutter_stage_new ();
  clutter_stage_set_title (CLUTTER_STAGE (stage), "OSD Test");
  clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE);
  clutter_actor_set_background_color (stage, CLUTTER_COLOR_Red);
  clutter_actor_set_size (stage, 300, 300);
  clutter_actor_show (stage);

  /* box canvas */
  canvas = clutter_canvas_new ();
  clutter_canvas_set_size (CLUTTER_CANVAS (canvas), 300, 300);

  actor = clutter_actor_new ();
  clutter_actor_add_constraint (actor, clutter_bind_constraint_new (stage, CLUTTER_BIND_SIZE, 0));
  clutter_actor_set_content (actor, canvas);
  g_object_unref (canvas);

  clutter_actor_add_child (stage, actor);

  memset (&ctx, 0, sizeof(ctx));

  widget_path = gtk_widget_path_new ();
  gtk_widget_path_append_type (widget_path, GTK_TYPE_WINDOW);
  ctx.style = gtk_style_context_new ();
  gtk_style_context_set_path (ctx.style, widget_path);

  ctx.direction = clutter_get_default_text_direction ();
  ctx.theme = gtk_icon_theme_get_default ();

  g_signal_connect (canvas, "draw", G_CALLBACK (draw_box), &ctx);
  clutter_content_invalidate (canvas);

  g_signal_connect (stage, "destroy", G_CALLBACK (gtk_main_quit), NULL);
}
Ejemplo n.º 13
0
PanelStyle::PanelStyle()
: d(new PanelStylePrivate)
{
    d->q = this;
    d->m_styleContext.reset(gtk_style_context_new());

    GtkWidgetPath* widgetPath = gtk_widget_path_new ();
    gtk_widget_path_append_type(widgetPath, GTK_TYPE_WINDOW);
    gtk_widget_path_iter_set_name(widgetPath, -1 , "UnityPanelWidget");

    gtk_style_context_set_path(d->m_styleContext.data(), widgetPath);
    gtk_style_context_add_class(d->m_styleContext.data(), "gnome-panel-menu-bar");
    gtk_style_context_add_class(d->m_styleContext.data(), "unity-panel");

    gtk_widget_path_free (widgetPath);

    d->m_gConnector.connect(gtk_settings_get_default(), "notify::gtk-theme-name",
        G_CALLBACK(PanelStylePrivate::onThemeChanged), d);

    d->updateTheme();
}
Ejemplo n.º 14
0
static GtkStyleContext *
get_style (GtkStyleContext *parent,
           const char      *selector)
{
  GtkWidgetPath *path;
  GtkStyleContext *context;

  if (parent)
    path = gtk_widget_path_copy (gtk_style_context_get_path (parent));
  else
    path = gtk_widget_path_new ();

  append_element (path, selector);

  context = gtk_style_context_new ();
  gtk_style_context_set_path (context, path);
  gtk_style_context_set_parent (context, parent);
  gtk_widget_path_unref (path);

  return context;
}
Ejemplo n.º 15
0
static GtkWidgetPath *
gtk_css_path_node_real_create_widget_path (GtkCssNode *node)
{
  GtkCssPathNode *path_node = GTK_CSS_PATH_NODE (node);
  GtkWidgetPath *path;
  guint length;

  if (path_node->path == NULL)
    path = gtk_widget_path_new ();
  else
    path = gtk_widget_path_copy (path_node->path);

  length = gtk_widget_path_length (path);
  if (length > 0)
    {
      gtk_css_node_declaration_add_to_widget_path (gtk_css_node_get_declaration (node),
                                                   path,
                                                   length - 1);
    }

  return path;
}
static void
matekbd_indicator_config_load_colors (MatekbdIndicatorConfig * ind_config)
{
	ind_config->foreground_color =
	    g_settings_get_string (ind_config->settings,
	                           MATEKBD_INDICATOR_CONFIG_KEY_FOREGROUND_COLOR);

	if (ind_config->foreground_color == NULL ||
	    ind_config->foreground_color[0] == '\0') {
		GtkWidgetPath *widget_path = gtk_widget_path_new ();
		GtkStyleContext *context = gtk_style_context_new ();
		GdkRGBA fg_color;

		gtk_widget_path_append_type (widget_path, GTK_TYPE_WINDOW);
		gtk_widget_path_iter_set_name (widget_path, -1 , "PanelWidget");

		gtk_style_context_set_path (context, widget_path);
		gtk_style_context_set_screen (context, gdk_screen_get_default ());
		gtk_style_context_set_state (context, GTK_STATE_FLAG_NORMAL);
		gtk_style_context_add_class (context, GTK_STYLE_CLASS_DEFAULT);
		gtk_style_context_add_class (context, "gnome-panel-menu-bar");
		gtk_style_context_add_class (context, "mate-panel-menu-bar");

		gtk_style_context_get_color (context,
		                             GTK_STATE_FLAG_NORMAL, &fg_color);
		ind_config->foreground_color =
		    g_strdup_printf ("%g %g %g",
		                     fg_color.red,
		                     fg_color.green,
		                     fg_color.blue);

		g_object_unref (G_OBJECT (context));
		gtk_widget_path_unref (widget_path);
	}

	ind_config->background_color =
	    g_settings_get_string (ind_config->settings,
				     MATEKBD_INDICATOR_CONFIG_KEY_BACKGROUND_COLOR);
}
Ejemplo n.º 17
0
static GtkWidgetPath *
gtk_css_widget_node_create_widget_path (GtkCssNode *node)
{
  GtkCssWidgetNode *widget_node = GTK_CSS_WIDGET_NODE (node);
  GtkWidgetPath *path;
  guint length;

  if (widget_node->widget == NULL)
    path = gtk_widget_path_new ();
  else
    path = _gtk_widget_create_path (widget_node->widget);
  
  length = gtk_widget_path_length (path);
  if (length > 0)
    {
      gtk_css_node_declaration_add_to_widget_path (gtk_css_node_get_declaration (node),
                                                   path,
                                                   length - 1);
    }

  return path;
}
Ejemplo n.º 18
0
static gboolean
draw_cb_slider (GtkWidget *widget, cairo_t *cr)
{
  GtkStyleContext *context;
  GtkWidgetPath *path;

  context = gtk_widget_get_style_context (widget);
  gtk_style_context_save (context);

  path = gtk_widget_path_new ();
  gtk_widget_path_append_type (path, GTK_TYPE_SCALE);
  gtk_widget_path_iter_add_class (path, 0, "slider");
  gtk_widget_path_iter_add_class (path, 0, "scale");
  gtk_style_context_set_path (context, path);
  gtk_widget_path_free (path);

  gtk_render_slider (context, cr, 12, 22, 30, 10, GTK_ORIENTATION_HORIZONTAL);
  gtk_render_slider (context, cr, 54, 12, 10, 30, GTK_ORIENTATION_VERTICAL);

  gtk_style_context_restore (context);

  return TRUE;
}
/*
 * static applet config functions
 */
static void
matekbd_indicator_config_load_font (MatekbdIndicatorConfig * ind_config)
{
	ind_config->font_family =
	    g_settings_get_string (ind_config->settings,
				   MATEKBD_INDICATOR_CONFIG_KEY_FONT_FAMILY);

	if (ind_config->font_family == NULL ||
	    ind_config->font_family[0] == '\0') {
		PangoFontDescription *fd = NULL;
		GtkWidgetPath *widget_path = gtk_widget_path_new ();
		GtkStyleContext *context = gtk_style_context_new ();

		gtk_widget_path_append_type (widget_path, GTK_TYPE_WINDOW);
		gtk_widget_path_iter_set_name (widget_path, -1 , "PanelWidget");

		gtk_style_context_set_path (context, widget_path);
		gtk_style_context_set_screen (context, gdk_screen_get_default ());
		gtk_style_context_set_state (context, GTK_STATE_FLAG_NORMAL);
		gtk_style_context_add_class (context, GTK_STYLE_CLASS_DEFAULT);
		gtk_style_context_add_class (context, "gnome-panel-menu-bar");
		gtk_style_context_add_class (context, "mate-panel-menu-bar");

		gtk_style_context_get (context, GTK_STATE_FLAG_NORMAL,
		                       GTK_STYLE_PROPERTY_FONT, &fd, NULL);

		if (fd != NULL) {
			ind_config->font_family =
			    g_strdup (pango_font_description_to_string(fd));
		}

		g_object_unref (G_OBJECT (context));
		gtk_widget_path_unref (widget_path);
	}
	xkl_debug (150, "font: [%s]\n", ind_config->font_family);

}
Ejemplo n.º 20
0
static void
bacon_video_osd_actor_init (BaconVideoOsdActor *osd)
{
	ClutterActor *self;
	GtkWidgetPath *widget_path;

	self = CLUTTER_ACTOR (osd);
        osd->priv = BACON_VIDEO_OSD_ACTOR_GET_PRIVATE (osd);

	osd->priv->canvas = CLUTTER_CANVAS (clutter_canvas_new ());
	g_object_bind_property (self, "width",
				osd->priv->canvas, "width",
				G_BINDING_DEFAULT);
	g_object_bind_property (self, "height",
				osd->priv->canvas, "height",
				G_BINDING_DEFAULT);
	clutter_actor_set_content (self, CLUTTER_CONTENT (osd->priv->canvas));
	g_object_unref (osd->priv->canvas);

	osd->priv->icon_name = NULL;
	osd->priv->message = NULL;

	osd->priv->ctx = g_new0 (GsdOsdDrawContext, 1);

	widget_path = gtk_widget_path_new ();
	gtk_widget_path_append_type (widget_path, GTK_TYPE_WINDOW);
	osd->priv->style = gtk_style_context_new ();
	gtk_style_context_set_path (osd->priv->style, widget_path);
	gtk_widget_path_free (widget_path);

	osd->priv->ctx->direction = clutter_get_default_text_direction ();
	osd->priv->ctx->theme = gtk_icon_theme_get_default ();
	osd->priv->ctx->style = osd->priv->style;

	g_signal_connect (osd->priv->canvas, "draw", G_CALLBACK (bacon_video_osd_actor_draw), osd);
        osd->priv->fade_out_alpha = 1.0;
}
Ejemplo n.º 21
0
/**
 * gtk_widget_path_copy:
 * @path: a #GtkWidgetPath
 *
 * Returns a copy of @path
 *
 * Returns: (transfer full): a copy of @path
 *
 * Since: 3.0
 **/
GtkWidgetPath *
gtk_widget_path_copy (const GtkWidgetPath *path)
{
  GtkWidgetPath *new_path;
  guint i;

  gtk_internal_return_val_if_fail (path != NULL, NULL);

  new_path = gtk_widget_path_new ();

  g_array_set_size (new_path->elems, path->elems->len);

  for (i = 0; i < path->elems->len; i++)
    {
      GtkPathElement *elem, *dest;

      elem = &g_array_index (path->elems, GtkPathElement, i);
      dest = &g_array_index (new_path->elems, GtkPathElement, i);

      gtk_path_element_copy (dest, elem);
    }

  return new_path;
}
Ejemplo n.º 22
0
void
meta_ui_theme_get_frame_borders (MetaUI *ui,
                                 MetaFrameType      type,
                                 MetaFrameFlags     flags,
                                 int               *top_height,
                                 int               *bottom_height,
                                 int               *left_width,
                                 int               *right_width)
{
  int text_height;
#if GTK_CHECK_VERSION (3, 0, 0)
  GtkStyleContext *style = NULL;
  PangoFontDescription *free_font_desc = NULL;
#endif
  PangoContext *context;
  const PangoFontDescription *font_desc;

  if (meta_ui_have_a_theme ())
    {
      context = gtk_widget_get_pango_context (GTK_WIDGET (ui->frames));
      font_desc = meta_prefs_get_titlebar_font ();

      if (!font_desc)
        {
#if GTK_CHECK_VERSION (3, 0, 0)
          GdkDisplay *display = gdk_x11_lookup_xdisplay (ui->xdisplay);
          GdkScreen *screen = gdk_display_get_screen (display, XScreenNumberOfScreen (ui->xscreen));
          GtkWidgetPath *widget_path;

          style = gtk_style_context_new ();
          gtk_style_context_set_screen (style, screen);
          widget_path = gtk_widget_path_new ();
          gtk_widget_path_append_type (widget_path, GTK_TYPE_WINDOW);
          gtk_style_context_set_path (style, widget_path);
          gtk_widget_path_free (widget_path);

          gtk_style_context_get (style, GTK_STATE_FLAG_NORMAL, "font", &free_font_desc, NULL);
          font_desc = (const PangoFontDescription *) free_font_desc;
#else
          GtkStyle *default_style;

          default_style = gtk_widget_get_default_style ();
          font_desc = default_style->font_desc;
#endif
        }

      text_height = meta_pango_font_desc_get_text_height (font_desc, context);

      meta_theme_get_frame_borders (meta_theme_get_current (),
                                    type, text_height, flags,
                                    top_height, bottom_height,
                                    left_width, right_width);

#if GTK_CHECK_VERSION (3, 0, 0)
      if (free_font_desc)
        pango_font_description_free (free_font_desc);
#endif
    }
  else
    {
      *top_height = *bottom_height = *left_width = *right_width = 0;
    }

#if GTK_CHECK_VERSION (3, 0, 0)
  if (style != NULL)
    g_object_unref (style);
#endif
}
Ejemplo n.º 23
0
MetaTilePreview *
meta_tile_preview_new (int      screen_number,
                       gboolean composited)
{
  MetaTilePreview *preview;
  GdkScreen *screen;

  screen = gdk_display_get_screen (gdk_display_get_default (), screen_number);

  preview = g_new (MetaTilePreview, 1);

  preview->preview_window = gtk_window_new (GTK_WINDOW_POPUP);

  gtk_window_set_screen (GTK_WINDOW (preview->preview_window), screen);
  gtk_widget_set_app_paintable (preview->preview_window, TRUE);

  preview->preview_color = NULL;

  preview->tile_rect.x = preview->tile_rect.y = 0;
  preview->tile_rect.width = preview->tile_rect.height = 0;

  preview->has_alpha = composited &&
                       (gdk_screen_get_rgba_visual (screen) != NULL);

  if (preview->has_alpha)
    {
      GtkStyleContext *context;
      GtkWidgetPath *path;
      guchar selection_alpha = 0xFF;

      gtk_widget_set_visual (preview->preview_window,
                             gdk_screen_get_rgba_visual (screen));

      path = gtk_widget_path_new ();
      gtk_widget_path_append_type (path, GTK_TYPE_ICON_VIEW);

      context = gtk_style_context_new ();
      gtk_style_context_set_path (context, path);
      gtk_style_context_add_class (context,
                                   GTK_STYLE_CLASS_RUBBERBAND);

      gtk_widget_path_free (path);

      gtk_style_context_get (context, GTK_STATE_FLAG_SELECTED,
                             "background-color", &preview->preview_color,
                             NULL);

      /* The background-color for the .rubberband class should probably
       * contain the correct alpha value - unfortunately, at least for now
       * it doesn't. Hopefully the following workaround can be removed
       * when GtkIconView gets ported to GtkStyleContext.
       */
      gtk_style_context_get_style (context,
                                   "selection-box-alpha", &selection_alpha,
                                   NULL);
      preview->preview_color->alpha = (double)selection_alpha / 0xFF;

      g_object_unref (context);
    }

  /* We make an assumption that XCreateWindow will be the first operation
   * when calling gtk_widget_realize() (via gdk_window_new()), or that it
   * is at least "close enough".
   */
  preview->create_serial = XNextRequest (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()));
  gtk_widget_realize (preview->preview_window);
  g_signal_connect (preview->preview_window, "draw",
                    G_CALLBACK (meta_tile_preview_draw), preview);

  return preview;
}
void testColors()
{
	for (int testBits = 0; testBits < (1 << 4); testBits++)
	{
		GdkRGBA colorFore;
		{
			GtkWidgetPath* widgetPath = gtk_widget_path_new();
			gint pathPos = gtk_widget_path_append_type(widgetPath, gtk_tooltip_get_type());

			#if GTK_CHECK_VERSION(3,20,0)
			if (testBits & 1)
				gtk_widget_path_iter_set_object_name(widgetPath, pathPos, "tooltip");
			#else
			// Silence the warning
			(void)pathPos;
			#endif

			if (testBits & 2)
				gtk_widget_path_append_type(widgetPath, gtk_label_get_type());

			GtkStyleContext* styleContext = gtk_style_context_new();
			gtk_style_context_set_path(styleContext, widgetPath);
			gtk_widget_path_free(widgetPath);

			if (testBits & 4)
				gtk_style_context_add_class(styleContext, GTK_STYLE_CLASS_BACKGROUND);

			if (testBits & 8)
				gtk_style_context_add_class(styleContext, GTK_STYLE_CLASS_TOOLTIP);

			gtk_style_context_get_color(styleContext, GTK_STATE_FLAG_NORMAL, &colorFore);

			g_object_unref(styleContext);
		}

		GdkRGBA colorBack;
		{
			GtkWidgetPath* widgetPath = gtk_widget_path_new();
			gint pathPos = gtk_widget_path_append_type(widgetPath, gtk_tooltip_get_type());

			#if GTK_CHECK_VERSION(3,20,0)
			if (testBits & 1)
				gtk_widget_path_iter_set_object_name(widgetPath, pathPos, "tooltip");
			#else
			// Silence the warning
			(void)pathPos;
			#endif

			if (testBits & 2)
				gtk_widget_path_append_type(widgetPath, gtk_label_get_type());

			GtkStyleContext* styleContext = gtk_style_context_new();
			gtk_style_context_set_path(styleContext, widgetPath);
			gtk_widget_path_free(widgetPath);

			if (testBits & 4)
				gtk_style_context_add_class(styleContext, GTK_STYLE_CLASS_BACKGROUND);

			if (testBits & 8)
				gtk_style_context_add_class(styleContext, GTK_STYLE_CLASS_TOOLTIP);

			gtk_style_context_get_background_color(styleContext, GTK_STATE_FLAG_NORMAL, &colorBack);

			g_object_unref(styleContext);
		}

		printf
		(
			"%c%c%c%c fore=%s back=%s\n",
			(testBits & 1) ? '1' : '-',
			(testBits & 2) ? '2' : '-',
			(testBits & 4) ? '3' : '-',
			(testBits & 8) ? '4' : '-',
			format_GdkRGBA(colorFore).c_str(),
			format_GdkRGBA(colorBack).c_str()
		);
	}
}
Ejemplo n.º 25
0
static GtkWidgetPath *
gtk_css_node_real_create_widget_path (GtkCssNode *cssnode)
{
  return gtk_widget_path_new ();
}
Ejemplo n.º 26
0
/**
 * gd_create_collection_icon:
 * @base_size:
 * @pixbufs: (element-type GdkPixbuf):
 *
 * Returns: (transfer full):
 */
GIcon *
gd_create_collection_icon (gint base_size,
                           GList *pixbufs)
{
  cairo_surface_t *surface;
  GIcon *retval;
  cairo_t *cr;
  GtkStyleContext *context;
  GtkWidgetPath *path;
  GtkBorder tile_border;
  gint padding, tile_size;
  gint idx, cur_x, cur_y;
  GList *l;

  context = gtk_style_context_new ();
  gtk_style_context_add_class (context, "documents-collection-icon");

  path = gtk_widget_path_new ();
  gtk_widget_path_append_type (path, GTK_TYPE_ICON_VIEW);
  gtk_style_context_set_path (context, path);
  gtk_widget_path_unref (path);

  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, base_size, base_size);
  cr = cairo_create (surface);

  /* Render the thumbnail itself */
  gtk_render_background (context, cr,
                         0, 0, base_size, base_size);
  gtk_render_frame (context, cr,
                    0, 0, base_size, base_size);

  /* Now, render the tiles inside */
  gtk_style_context_remove_class (context, "documents-collection-icon");
  gtk_style_context_add_class (context, "documents-collection-icon-tile");

  /* TODO: do not hardcode 4, but scale to another layout if more
   * pixbufs are provided.
   */
  padding = MAX (floor (base_size / 10), 4);
  gtk_style_context_get_border (context, GTK_STATE_FLAG_NORMAL, &tile_border);
  tile_size = (base_size - (3 * padding)) / 2 -
    MAX (tile_border.left + tile_border.right, tile_border.top + tile_border.bottom);

  l = pixbufs;
  idx = 0;
  cur_x = padding;
  cur_y = padding;

  while (l != NULL && idx < 4)
    {
      GdkPixbuf *pix;
      gboolean is_thumbnail;
      gint pix_width, pix_height, scale_size;

      pix = l->data;
      is_thumbnail = (gdk_pixbuf_get_option (pix, "-documents-has-thumb") != NULL);

      /* Only draw a box for thumbnails */
      if (is_thumbnail)
        {
          gtk_render_background (context, cr,
                                 cur_x, cur_y,
                                 tile_size + tile_border.left + tile_border.right,
                                 tile_size + tile_border.top + tile_border.bottom);
          gtk_render_frame (context, cr,
                            cur_x, cur_y,
                            tile_size + tile_border.left + tile_border.right,
                            tile_size + tile_border.top + tile_border.bottom);
        }

      pix_width = gdk_pixbuf_get_width (pix);
      pix_height = gdk_pixbuf_get_height (pix);
      scale_size = MIN (pix_width, pix_height);

      cairo_save (cr);

      cairo_translate (cr, cur_x + tile_border.left, cur_y + tile_border.top);
      cairo_rectangle (cr, 0, 0, tile_size, tile_size);
      cairo_clip (cr);

      cairo_scale (cr, (gdouble) tile_size / (gdouble) scale_size, (gdouble) tile_size / (gdouble) scale_size);
      gdk_cairo_set_source_pixbuf (cr, pix, 0, 0);
      cairo_paint (cr);

      cairo_restore (cr);

      if ((idx % 2) == 0)
        {
          cur_x += tile_size + padding + tile_border.left + tile_border.right;
        }
      else
        {
          cur_x = padding;
          cur_y += tile_size + padding + tile_border.top + tile_border.bottom;
        }

      idx++;
      l = l->next;
    }

  retval = G_ICON (gdk_pixbuf_get_from_surface (surface, 0, 0, base_size, base_size));

  cairo_surface_destroy (surface);
  cairo_destroy (cr);
  g_object_unref (context);

  return retval;
}
Ejemplo n.º 27
0
static VALUE
rg_initialize(VALUE self)
{
    G_INITIALIZE(self, gtk_widget_path_new());
    return Qnil;
}
Ejemplo n.º 28
0
/**
 * gd_embed_image_in_frame: 
 * @source_image:
 * @frame_image_path:
 * @slice_width:
 * @border_width:
 *
 * Returns: (transfer full):
 */
GdkPixbuf *
gd_embed_image_in_frame (GdkPixbuf *source_image,
                         const gchar *frame_image_path,
                         GtkBorder *slice_width,
                         GtkBorder *border_width)
{
  cairo_surface_t *surface;
  cairo_t *cr;
  int source_width, source_height;
  int dest_width, dest_height;
  gchar *css_str;
  GtkCssProvider *provider;
  GtkStyleContext *context;
  GError *error = NULL;
  GdkPixbuf *retval;
  GtkWidgetPath *path;
 
  source_width = gdk_pixbuf_get_width (source_image);
  source_height = gdk_pixbuf_get_height (source_image);

  dest_width = source_width +  border_width->left + border_width->right;
  dest_height = source_height + border_width->top + border_width->bottom;

  css_str = g_strdup_printf (".embedded-image { border-image: url(\"%s\") %d %d %d %d / %d %d %d %d }",
                             frame_image_path, 
                             slice_width->top, slice_width->right, slice_width->bottom, slice_width->left,
                             border_width->top, border_width->right, border_width->bottom, border_width->left);
  provider = gtk_css_provider_new ();
  gtk_css_provider_load_from_data (provider, css_str, -1, &error);

  if (error != NULL) 
    {
      g_warning ("Unable to create the thumbnail frame image: %s", error->message);
      g_error_free (error);
      g_free (css_str);

      return g_object_ref (source_image);
    }

  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, dest_width, dest_height);
  cr = cairo_create (surface);

  context = gtk_style_context_new ();
  path = gtk_widget_path_new ();
  gtk_widget_path_append_type (path, GTK_TYPE_ICON_VIEW);

  gtk_style_context_set_path (context, path);
  gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (provider), 600);

  gtk_style_context_save (context);
  gtk_style_context_add_class (context, "embedded-image");

  gtk_render_frame (context, cr,
                    0, 0,
                    dest_width, dest_height);

  gtk_style_context_restore (context);

  gtk_render_icon (context, cr,
                   source_image,
                   border_width->left, border_width->top);

  retval = gdk_pixbuf_get_from_surface (surface,
                                        0, 0, dest_width, dest_height);

  cairo_surface_destroy (surface);
  cairo_destroy (cr);

  gtk_widget_path_unref (path);
  g_object_unref (provider);
  g_object_unref (context);
  g_free (css_str);

  return retval;
}
Ejemplo n.º 29
0
/**
 * gd_create_collection_icon:
 * @base_size:
 * @pixbufs: (element-type GdkPixbuf):
 *
 * Returns: (transfer full):
 */
GIcon *
gd_create_collection_icon (gint base_size,
                           GList *pixbufs)
{
  cairo_surface_t *surface;
  GIcon *retval;
  cairo_t *cr;
  GtkStyleContext *context;
  GtkWidgetPath *path;
  gint padding, tile_size, scale_size;
  gint pix_width, pix_height;
  gint idx, cur_x, cur_y;
  GList *l;
  GdkPixbuf *pix;

  /* TODO: do not hardcode 4, but scale to another layout if more
   * pixbufs are provided.
   */

  padding = MAX (floor (base_size / 10), 4);
  tile_size = (base_size - (3 * padding)) / 2;

  context = gtk_style_context_new ();
  gtk_style_context_add_class (context, "documents-collection-icon");

  path = gtk_widget_path_new ();
  gtk_widget_path_append_type (path, GTK_TYPE_ICON_VIEW);
  gtk_style_context_set_path (context, path);
  gtk_widget_path_unref (path);

  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, base_size, base_size);
  cr = cairo_create (surface);

  gtk_render_background (context, cr,
                         0, 0, base_size, base_size);

  l = pixbufs;
  idx = 0;
  cur_x = padding;
  cur_y = padding;

  while (l != NULL && idx < 4)
    {
      pix = l->data;
      pix_width = gdk_pixbuf_get_width (pix);
      pix_height = gdk_pixbuf_get_height (pix);

      scale_size = MIN (pix_width, pix_height);

      cairo_save (cr);

      cairo_translate (cr, cur_x, cur_y);

      cairo_rectangle (cr, 0, 0,
                       tile_size, tile_size);
      cairo_clip (cr);

      cairo_scale (cr, (gdouble) tile_size / (gdouble) scale_size, (gdouble) tile_size / (gdouble) scale_size);
      gdk_cairo_set_source_pixbuf (cr, pix, 0, 0);

      cairo_paint (cr);
      cairo_restore (cr);

      if ((idx % 2) == 0)
        {
          cur_x += tile_size + padding;
        }
      else
        {
          cur_x = padding;
          cur_y += tile_size + padding;
        }

      idx++;
      l = l->next;
    }

  retval = G_ICON (gdk_pixbuf_get_from_surface (surface, 0, 0, base_size, base_size));

  cairo_surface_destroy (surface);
  cairo_destroy (cr);
  g_object_unref (context);

  return retval;
}
Ejemplo n.º 30
0
/**
 * gd_create_symbolic_icon:
 * @name:
 *
 * Returns: (transfer full):
 */
GIcon *
gd_create_symbolic_icon (const gchar *name,
                         gint base_size)
{
  gchar *symbolic_name;
  GIcon *icon, *retval = NULL;
  cairo_surface_t *surface;
  cairo_t *cr;
  GtkStyleContext *style;
  GtkWidgetPath *path;
  GdkPixbuf *pixbuf;
  GtkIconTheme *theme;
  GtkIconInfo *info;
  gint bg_size;
  gint emblem_size;
  gint total_size;

  total_size = base_size / 2;
  bg_size = MAX (total_size / 2, _BG_MIN_SIZE);
  emblem_size = MAX (bg_size - 8, _EMBLEM_MIN_SIZE);

  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, total_size, total_size);
  cr = cairo_create (surface);

  style = gtk_style_context_new ();

  path = gtk_widget_path_new ();
  gtk_widget_path_append_type (path, GTK_TYPE_ICON_VIEW);
  gtk_style_context_set_path (style, path);
  gtk_widget_path_unref (path);

  gtk_style_context_add_class (style, "documents-icon-bg");

  gtk_render_background (style, cr, (total_size - bg_size) / 2, (total_size - bg_size) / 2, bg_size, bg_size);

  symbolic_name = g_strconcat (name, "-symbolic", NULL);
  icon = g_themed_icon_new_with_default_fallbacks (symbolic_name);
  g_free (symbolic_name);

  theme = gtk_icon_theme_get_default();
  info = gtk_icon_theme_lookup_by_gicon (theme, icon, emblem_size,
                                         GTK_ICON_LOOKUP_FORCE_SIZE);
  g_object_unref (icon);

  if (info == NULL)
    goto out;

  pixbuf = gtk_icon_info_load_symbolic_for_context (info, style, NULL, NULL);
  gtk_icon_info_free (info);

  if (pixbuf == NULL)
    goto out;

  gtk_render_icon (style, cr, pixbuf, (total_size - emblem_size) / 2,  (total_size - emblem_size) / 2);
  g_object_unref (pixbuf);

  retval = G_ICON (gdk_pixbuf_get_from_surface (surface, 0, 0, total_size, total_size));

 out:
  g_object_unref (style);
  cairo_surface_destroy (surface);
  cairo_destroy (cr);

  return retval;
}