static void ensure_pixbuf_for_gicon (GtkIconHelper *self, GtkStyleContext *context) { GtkIconTheme *icon_theme; gint width, height; GtkIconInfo *info; GtkIconLookupFlags flags; if (!check_invalidate_pixbuf (self, context)) return; icon_theme = gtk_icon_theme_get_for_screen (gtk_style_context_get_screen (context)); flags = get_icon_lookup_flags (self, context); ensure_icon_size (self, context, &width, &height); if (self->priv->gicon != NULL) { info = gtk_icon_theme_lookup_by_gicon (icon_theme, self->priv->gicon, MIN (width, height), flags); } else { g_assert_not_reached (); return; } self->priv->rendered_pixbuf = ensure_stated_icon_from_info (self, context, info); if (info) g_object_unref (info); }
static PangoLayout * get_pango_layout (GtkNumerableIcon *self) { PangoContext *context; GdkScreen *screen; PangoLayout *layout; if (self->priv->style != NULL) { screen = gtk_style_context_get_screen (self->priv->style); context = gdk_pango_context_get_for_screen (screen); layout = pango_layout_new (context); if (self->priv->font != NULL) pango_layout_set_font_description (layout, self->priv->font); pango_layout_set_text (layout, self->priv->rendered_string, -1); g_object_unref (context); } else { GtkWidget *fake; /* steal gtk text settings from the window */ fake = gtk_window_new (GTK_WINDOW_TOPLEVEL); layout = gtk_widget_create_pango_layout (fake, self->priv->rendered_string); gtk_widget_destroy (fake); } return layout; }
JNIEXPORT jlong JNICALL Java_org_gnome_gtk_GtkStyleContext_gtk_1style_1context_1get_1screen ( JNIEnv* env, jclass cls, jlong _self ) { GdkScreen* result; jlong _result; GtkStyleContext* self; // convert parameter self self = (GtkStyleContext*) _self; // call function result = gtk_style_context_get_screen(self); // cleanup parameter self // translate return value to JNI type _result = (jlong) result; // cleanup return value if (result != NULL) { bindings_java_memory_cleanup((GObject*)result, FALSE); } // and finally return _result; }
static void ensure_icon_size (GtkIconHelper *self, GtkStyleContext *context, gint *width_out, gint *height_out) { gint width, height; GtkSettings *settings; GdkScreen *screen; screen = gtk_style_context_get_screen (context); settings = gtk_settings_get_for_screen (screen); if (self->priv->pixel_size != -1) { width = height = self->priv->pixel_size; } else if (!gtk_icon_size_lookup_for_settings (settings, self->priv->icon_size, &width, &height)) { if (self->priv->icon_size == GTK_ICON_SIZE_INVALID) { width = height = 0; } else { g_warning ("Invalid icon size %d\n", self->priv->icon_size); width = height = 24; } } *width_out = width; *height_out = height; }
static void gstyle_color_widget_init (GstyleColorWidget *self) { GtkStyleContext *context; GtkWidget *widget = GTK_WIDGET (self); gtk_widget_set_has_window (GTK_WIDGET (self), TRUE); self->label = GTK_LABEL (g_object_new (GTK_TYPE_LABEL, "ellipsize", PANGO_ELLIPSIZE_END, "visible", TRUE, "halign", GTK_ALIGN_CENTER, "valign", GTK_ALIGN_CENTER, NULL)); gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (self->label)); self->is_name_visible = TRUE; self->is_fallback_name_visible = TRUE; self->fallback_name_kind = GSTYLE_COLOR_KIND_RGB_HEX6; self->checkered_pattern = gstyle_utils_get_checkered_pattern (); gtk_widget_set_valign (widget, GTK_ALIGN_FILL); gtk_widget_set_halign (widget, GTK_ALIGN_FILL); gtk_widget_set_hexpand (widget, TRUE); gtk_widget_set_vexpand (widget, TRUE); context = gtk_widget_get_style_context (GTK_WIDGET (self)); self->default_provider = gstyle_css_provider_init_default (gtk_style_context_get_screen (context)); self->target_list = gtk_target_list_new (dnd_targets, G_N_ELEMENTS (dnd_targets)); gtk_target_list_add_text_targets (self->target_list, 0); gtk_drag_dest_set (widget, 0, NULL, 0, GDK_ACTION_MOVE); gtk_drag_dest_set_target_list (widget, self->target_list); gtk_drag_dest_set_track_motion (GTK_WIDGET (self), TRUE); update_container_parent_informations (self); self->multipress_gesture = gtk_gesture_multi_press_new (widget); gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (self->multipress_gesture), 0); gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (self->multipress_gesture), GTK_PHASE_BUBBLE); g_signal_connect (self->multipress_gesture, "pressed", G_CALLBACK (gstyle_color_widget_multipress_gesture_pressed), widget); self->drag_gesture = gtk_gesture_drag_new (GTK_WIDGET (self)); g_signal_connect (self->drag_gesture, "drag-update", G_CALLBACK (gstyle_color_widget_drag_gesture_update), self); g_signal_connect_swapped (self, "key-press-event", G_CALLBACK (gstyle_color_widget_key_pressed_cb), self); gstyle_color_widget_actions_init (self); gtk_widget_set_can_focus (GTK_WIDGET (self), TRUE); }
static gint get_scale_factor (GtkIconHelper *self, GtkStyleContext *context) { GdkScreen *screen; if (self->priv->window) return gdk_window_get_scale_factor (self->priv->window); screen = gtk_style_context_get_screen (context); /* else fall back to something that is more likely to be right than * just returning 1: */ return gdk_screen_get_monitor_scale_factor (screen, 0); }
static cairo_surface_t * draw_from_gicon (GtkNumerableIcon *self) { GtkIconTheme *theme; GdkScreen *screen; GtkIconInfo *info; GdkPixbuf *pixbuf; cairo_surface_t *surface; cairo_t *cr; if (self->priv->style != NULL) { screen = gtk_style_context_get_screen (self->priv->style); theme = gtk_icon_theme_get_for_screen (screen); } else { theme = gtk_icon_theme_get_default (); } info = gtk_icon_theme_lookup_by_gicon (theme, self->priv->background_icon, self->priv->icon_size, GTK_ICON_LOOKUP_GENERIC_FALLBACK); if (info == NULL) return NULL; pixbuf = gtk_icon_info_load_icon (info, NULL); g_object_unref (info); if (pixbuf == NULL) return NULL; surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf)); cr = cairo_create (surface); gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0); cairo_paint (cr); cairo_destroy (cr); g_object_unref (pixbuf); return surface; }
static GdkPixbuf * ensure_stated_icon_from_info (GtkIconHelper *self, GtkStyleContext *context, GtkIconInfo *info) { GdkPixbuf *destination = NULL; gboolean symbolic; symbolic = FALSE; if (info) destination = gtk_icon_info_load_symbolic_for_context (info, context, &symbolic, NULL); if (destination == NULL) { GtkIconTheme *icon_theme; int width; icon_theme = gtk_icon_theme_get_for_screen (gtk_style_context_get_screen (context)); gtk_icon_size_lookup (self->priv->icon_size, &width, NULL); destination = gtk_icon_theme_load_icon (icon_theme, "image-missing", width, GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL); } else if (!symbolic) { GdkPixbuf *rendered; rendered = ensure_stated_pixbuf_from_pixbuf (self, context, destination); g_object_unref (destination); destination = rendered; } return destination; }
static void gstyle_slidein_init (GstyleSlidein *self) { GtkStyleContext *context; g_signal_connect_swapped (self, "key-press-event", G_CALLBACK (gstyle_slidein_event_box_key_pressed_cb), self); gtk_widget_set_has_window (GTK_WIDGET (self), FALSE); gtk_event_box_set_visible_window (GTK_EVENT_BOX (self), FALSE); gtk_event_box_set_above_child (GTK_EVENT_BOX (self), FALSE); context = gtk_widget_get_style_context (GTK_WIDGET (self)); self->default_provider = gstyle_css_provider_init_default (gtk_style_context_get_screen (context)); self->direction_type = GSTYLE_SLIDEIN_DIRECTION_TYPE_RIGHT; self->direction_type_reverse = GSTYLE_SLIDEIN_DIRECTION_TYPE_LEFT; self->duration = 0.0; self->duration_set = TRUE; }
void gstyle_eyedropper_set_source_event (GstyleEyedropper *self, GdkEvent *event) { GtkWidget *source; GtkStyleContext *context; GtkWidget *box; GtkWidget *swatch; GdkGrabStatus status; gint x_root, y_root; gint x, y; g_return_if_fail (GSTYLE_IS_EYEDROPPER (self)); g_return_if_fail (event != NULL); self->seat = g_object_ref (gdk_event_get_seat (event)); source = gtk_get_event_widget (event); self->screen = gdk_event_get_screen (event); g_signal_connect_swapped (self->screen, "size-changed", G_CALLBACK (gstyle_eyedropper_screen_size_changed_cb), self); self->window = g_object_ref_sink (gtk_window_new (GTK_WINDOW_POPUP)); gtk_window_set_screen (GTK_WINDOW (self->window),self->screen); gtk_widget_set_name (self->window, "gstyleeyedropper"); context = gtk_widget_get_style_context (self->window); self->default_provider = gstyle_css_provider_init_default (gtk_style_context_get_screen (context)); box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); gtk_container_add (GTK_CONTAINER (self->window), box); self->zoom_area = gtk_drawing_area_new (); gtk_widget_set_size_request (self->zoom_area, ZOOM_AREA_WIDTH, ZOOM_AREA_HEIGHT); gtk_container_add (GTK_CONTAINER (box), self->zoom_area); swatch = g_object_new (GSTYLE_TYPE_COLOR_WIDGET, "fallback-name-kind", GSTYLE_COLOR_KIND_RGB_HEX6, "fallback-name-visible", TRUE, "color", self->color, NULL); gtk_container_add (GTK_CONTAINER (box), swatch); g_signal_connect_object (self->zoom_area, "draw", G_CALLBACK (gstyle_eyedropper_zoom_area_draw_cb), self, G_CONNECT_SWAPPED); self->screen_width = gdk_screen_get_width (self->screen); self->screen_height = gdk_screen_get_height (self->screen); gstyle_eyedropper_event_get_root_coords (self, event, &x_root, &y_root); gstyle_eyedropper_calculate_window_position (self, GTK_WINDOW (self->window), x_root, y_root, &x, &y); gtk_window_move (GTK_WINDOW (self->window), x, y); gtk_widget_show_all (self->window); gtk_widget_add_events (self->window, GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK); self->cursor = gdk_cursor_new_from_name (gdk_screen_get_display (self->screen), "cell"); gtk_grab_add (self->window); status = gdk_seat_grab (self->seat, gtk_widget_get_window (source), GDK_SEAT_CAPABILITY_ALL, FALSE, self->cursor, event, NULL, NULL); if (status != GDK_GRAB_SUCCESS) { g_warning ("grab failed status:%i\n", status); return; } self->motion_notify_handler_id = g_signal_connect_swapped (self->window, "motion-notify-event", G_CALLBACK (gstyle_eyedropper_pointer_motion_notify_cb), self); self->pointer_pressed_handler_id = g_signal_connect_swapped (self->window, "button-press-event", G_CALLBACK (gstyle_eyedropper_pointer_pressed_cb), self); self->pointer_wheel_handler_id = g_signal_connect_swapped (self->window, "scroll-event", G_CALLBACK (gstyle_eyedropper_pointer_wheel_cb), self); self->key_handler_id = g_signal_connect_swapped (self->window, "key-press-event", G_CALLBACK (gstyle_eyedropper_key_pressed_cb), self); self->grab_broken_handler_id = g_signal_connect_swapped (self->window, "grab-broken-event", G_CALLBACK (gstyle_eyedropper_grab_broken_cb), self); }