static gint calculate_arrow_rect(GtkWidget* arrow, GdkRectangle* rect, GdkRectangle* arrow_rect, GtkTextDirection direction) { /* defined in gtkarrow.c */ gfloat arrow_scaling = 0.7; gfloat xalign, xpad; gint extent; GtkMisc* misc = GTK_MISC(arrow); gfloat misc_xalign, misc_yalign; gint misc_xpad, misc_ypad; if (have_arrow_scaling) gtk_widget_style_get(arrow, "arrow_scaling", &arrow_scaling, NULL); gtk_misc_get_padding(misc, &misc_xpad, &misc_ypad); gtk_misc_get_alignment(misc, &misc_xalign, &misc_yalign); extent = MIN((rect->width - misc_xpad * 2), (rect->height - misc_ypad * 2)) * arrow_scaling; xalign = direction == GTK_TEXT_DIR_LTR ? misc_xalign : 1.0 - misc_xalign; xpad = misc_xpad + (rect->width - extent) * xalign; arrow_rect->x = direction == GTK_TEXT_DIR_LTR ? floor(rect->x + xpad) : ceil(rect->x + xpad); arrow_rect->y = floor(rect->y + misc_ypad + ((rect->height - extent) * misc_yalign)); arrow_rect->width = arrow_rect->height = extent; return MOZ_GTK_SUCCESS; }
/* Hack to make the plugin-provided editor widget fit in better with * the control center by changing * * Foo: [__________] * Bar baz: [__________] * * to * * Foo [__________] * Bar baz [__________] */ static void vpn_gnome3ify_editor (GtkWidget *widget) { if (GTK_IS_CONTAINER (widget)) { GList *children, *iter; children = gtk_container_get_children (GTK_CONTAINER (widget)); for (iter = children; iter; iter = iter->next) vpn_gnome3ify_editor (iter->data); g_list_free (children); } else if (GTK_IS_LABEL (widget)) { const char *text; gfloat xalign, yalign; char *newtext; int len; gtk_misc_get_alignment (GTK_MISC (widget), &xalign, &yalign); if (xalign != 0.0) return; text = gtk_label_get_text (GTK_LABEL (widget)); len = strlen (text); if (len < 2 || text[len - 1] != ':') return; newtext = g_strndup (text, len - 1); gtk_label_set_text (GTK_LABEL (widget), newtext); g_free (newtext); gtk_misc_set_alignment (GTK_MISC (widget), 1.0, yalign); } }
void sg_left_justify_label(GtkWidget *label) { /* the label justify function in Gtk refers to the text of the lines after the 1st! */ gfloat x, y; gtk_misc_get_alignment(GTK_MISC(GTK_LABEL(label)), &x, &y); gtk_misc_set_alignment(GTK_MISC(GTK_LABEL(label)), 0.05, y); }
static VALUE misc_get_align(VALUE self) { gfloat xalign, yalign; gtk_misc_get_alignment(_SELF(self), &xalign, &yalign); return rb_ary_new3(2, rb_float_new(xalign), rb_float_new(yalign)); }
void label_align_text(GtkLabel *label, gfloat xalign, gfloat yalign) { gtk_label_set_line_wrap(label, TRUE); gtk_label_set_justify(label, GTK_JUSTIFY_LEFT); #if (GTK_MAJOR_VERSION > 3) || (GTK_MINOR_VERSION >= 16) if(xalign >= 0) gtk_label_set_xalign(label, xalign); if(yalign >= 0) gtk_label_set_xalign(label, yalign); #else /* deprecated at 3.14, but above only implemented at 3.16 */ if(xalign < 0) gtk_misc_get_alignment(GTK_MISC(label), &xalign, NULL); if(yalign < 0) gtk_misc_get_alignment(GTK_MISC(label), NULL, &yalign); gtk_misc_set_alignment(GTK_MISC(label), xalign, yalign); #endif }
static gint luaH_label_get_alignment(lua_State *L) { widget_t *w = luaH_checkwidget(L, 1); gfloat xalign, yalign; gtk_misc_get_alignment(GTK_MISC(w->widget), &xalign, &yalign); lua_pushnumber(L, xalign); lua_pushnumber(L, yalign); return 2; }
static gboolean avatar_image_expose_event (GtkWidget *widget, GdkEventExpose *event) { GiggleAvatarImagePriv *priv = GET_PRIV (widget); GtkAllocation allocation; GtkRequisition requisition; GtkStyle *style; float xalign, yalign; double x, y; int w, h; cairo_t *cr; gtk_widget_size_request (widget, &requisition); gtk_widget_get_allocation (widget, &allocation); style = gtk_widget_get_style (widget); cr = gdk_cairo_create (event->window); gdk_cairo_region (cr, event->region); cairo_clip (cr); w = requisition.width; h = requisition.height; gtk_misc_get_alignment (GTK_MISC (widget), &xalign, &yalign); cairo_translate (cr, (int) ((allocation.width - w) * xalign), (int) ((allocation.height - h) * yalign)); rounded_rectangle (cr, 0.5, 0.5, w - 1, h - 1, MIN (w, h) * 0.2); gdk_cairo_set_source_color (cr, &style->base[GTK_STATE_NORMAL]); cairo_fill_preserve (cr); if (priv->pixbuf) { x = (w - gdk_pixbuf_get_width (priv->pixbuf)) * 0.5; y = (h - gdk_pixbuf_get_height (priv->pixbuf)) * 0.5; gdk_cairo_set_source_pixbuf (cr, priv->pixbuf, x, y); cairo_fill_preserve (cr); } gdk_cairo_set_source_color (cr, &style->text[GTK_STATE_NORMAL]); cairo_set_line_width (cr, 1); cairo_stroke (cr); cairo_destroy (cr); return TRUE; }
static void justify_element(GtkWidget *el, const xmlNode *justify) { const xmlChar *s = children_content(justify); gfloat xalign, yalign; gtk_misc_get_alignment(GTK_MISC(el), &xalign, &yalign); if (xstrcmp(s, "Right") == 0) gtk_misc_set_alignment(GTK_MISC(el), 1, yalign); if (xstrcmp(s, "Left") == 0) gtk_misc_set_alignment(GTK_MISC(el), 0, yalign); if (xstrcmp(s, "Auto") == 0) gtk_misc_set_alignment(GTK_MISC(el), 0, yalign); }
static gint luaH_label_get_align(lua_State *L, widget_t *w) { gfloat xalign, yalign; gtk_misc_get_alignment(GTK_MISC(w->widget), &xalign, &yalign); lua_createtable(L, 0, 2); /* set align.x */ lua_pushliteral(L, "x"); lua_pushnumber(L, xalign); lua_rawset(L, -3); /* set align.y */ lua_pushliteral(L, "y"); lua_pushnumber(L, yalign); lua_rawset(L, -3); return 1; }
static gboolean avatar_image_draw (GtkWidget *widget, cairo_t *cr) { GiggleAvatarImagePriv *priv = GET_PRIV (widget); GtkRequisition requisition; GtkStyleContext *context; GdkRGBA rgba; float xalign, yalign; double x, y; gint width, height; int w, h; gtk_widget_get_preferred_size (widget, &requisition, NULL); width = gtk_widget_get_allocated_width (widget); height = gtk_widget_get_allocated_height (widget); context = gtk_widget_get_style_context (widget); w = requisition.width; h = requisition.height; gtk_misc_get_alignment (GTK_MISC (widget), &xalign, &yalign); cairo_translate (cr, (int) ((width - w) * xalign), (int) ((height - h) * yalign)); rounded_rectangle (cr, 0.5, 0.5, w - 1, h - 1, MIN (w, h) * 0.2); gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &rgba); gdk_cairo_set_source_rgba (cr, &rgba); cairo_fill_preserve (cr); if (priv->pixbuf) { x = (w - gdk_pixbuf_get_width (priv->pixbuf)) * 0.5; y = (h - gdk_pixbuf_get_height (priv->pixbuf)) * 0.5; gdk_cairo_set_source_pixbuf (cr, priv->pixbuf, x, y); cairo_fill_preserve (cr); } gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &rgba); gdk_cairo_set_source_rgba (cr, &rgba); cairo_set_line_width (cr, 1); cairo_stroke (cr); return TRUE; }
static gint luaH_label_set_align(lua_State *L, widget_t *w) { luaH_checktable(L, 3); /* get old alignment values */ gfloat xalign, yalign; gtk_misc_get_alignment(GTK_MISC(w->widget), &xalign, &yalign); /* get align.x */ if (luaH_rawfield(L, 3, "x")) { xalign = (gfloat) lua_tonumber(L, -1); lua_pop(L, 1); } /* get align.y */ if (luaH_rawfield(L, 3, "y")) { yalign = (gfloat) lua_tonumber(L, -1); lua_pop(L, 1); } gtk_misc_set_alignment(GTK_MISC(w->widget), xalign, yalign); return 0; }
/* TODO - Optimize this a bit */ static void calculate_pupil_xy (EyesApplet *eyes_applet, gint x, gint y, gint *pupil_x, gint *pupil_y, GtkWidget* widget) { GtkAllocation allocation; double sina; double cosa; double h; double temp; double nx, ny; gfloat xalign, yalign; gint width, height; gtk_widget_get_allocation (GTK_WIDGET(widget), &allocation); width = allocation.width; height = allocation.height; gtk_misc_get_alignment(GTK_MISC(widget), &xalign, &yalign); nx = x - MAX(width - eyes_applet->eye_width, 0) * xalign - eyes_applet->eye_width / 2; ny = y - MAX(height- eyes_applet->eye_height, 0) * yalign - eyes_applet->eye_height / 2; h = hypot (nx, ny); if (h < 0.5 || abs (h) < (abs (hypot (eyes_applet->eye_height / 2, eyes_applet->eye_width / 2)) - eyes_applet->wall_thickness - eyes_applet->pupil_height)) { *pupil_x = nx + eyes_applet->eye_width / 2; *pupil_y = ny + eyes_applet->eye_height / 2; return; } sina = nx / h; cosa = ny / h; temp = hypot ((eyes_applet->eye_width / 2) * sina, (eyes_applet->eye_height / 2) * cosa); temp -= hypot ((eyes_applet->pupil_width / 2) * sina, (eyes_applet->pupil_height / 2) * cosa); temp -= hypot ((eyes_applet->wall_thickness / 2) * sina, (eyes_applet->wall_thickness / 2) * cosa); *pupil_x = temp * sina + (eyes_applet->eye_width / 2); *pupil_y = temp * cosa + (eyes_applet->eye_height / 2); }
void sg_left_justify_button(GtkWidget *button) { gfloat x, y; gtk_misc_get_alignment(GTK_MISC(GTK_LABEL(GTK_BIN(button)->child)), &x, &y); gtk_misc_set_alignment(GTK_MISC(GTK_LABEL(GTK_BIN(button)->child)), 0.05, y); }
static void egg_status_icon_update_image (EggStatusIcon *status_icon) { if (status_icon->priv->blink_off) { gtk_image_set_from_pixbuf (GTK_IMAGE (status_icon->priv->image), egg_status_icon_blank_icon (status_icon)); return; } switch (status_icon->priv->image_type) { case GTK_IMAGE_PIXBUF: { GdkPixbuf *pixbuf; pixbuf = status_icon->priv->image_data.pixbuf; if (pixbuf) { GdkPixbuf *scaled; gint size; gint width; gint height; size = status_icon->priv->size; width = gdk_pixbuf_get_width (pixbuf); height = gdk_pixbuf_get_height (pixbuf); if (width > size || height > size) { scaled = gdk_pixbuf_scale_simple (pixbuf, MIN (size, width), MIN (size, height), GDK_INTERP_BILINEAR); } else { scaled = g_object_ref (pixbuf); } gtk_image_set_from_pixbuf (GTK_IMAGE (status_icon->priv->image), scaled); /* Sets the icon's transparency mask as the window's shape mask. Note: This doesn't handle translucency (partial transparency). */ gint image_offset_x, image_offset_y; /* No way to know the image's real offset but by calculating ourselves. */ { GtkOrientation orientation; gfloat xalign, yalign; gint xpad, ypad; GtkWidget* image = status_icon->priv->image; gtk_misc_get_padding(GTK_MISC(image), &xpad, &ypad); gtk_misc_get_alignment(GTK_MISC(image), &xalign, &yalign); /* We're aligning either horizontally or vertically, depending on the orientation. According to this, we'll assume either width or height to be preallocated up to the panel's size. */ orientation = egg_tray_icon_get_orientation (EGG_TRAY_ICON (status_icon->priv->tray_icon)); /* We base on the code found in gtk_image_expose */ image_offset_x = floor(image->allocation.x + xpad + ((status_icon->priv->alloc_width - image->requisition.width) * xalign) + 0.5); image_offset_y = floor(image->allocation.y + ypad + ((status_icon->priv->alloc_height - image->requisition.height) * yalign) + 0.5); } GdkBitmap* scaled_mask = NULL; gdk_pixbuf_render_pixmap_and_mask(scaled, NULL, &scaled_mask, 0); if (scaled_mask) { /* It's only possible to set shape masks on real windows, so we have to set an offseted shape mask. */ gtk_widget_shape_combine_mask(GTK_WIDGET(status_icon->priv->tray_icon), scaled_mask, image_offset_x, image_offset_y); g_object_unref(scaled_mask); } g_object_unref (scaled); } else { gtk_image_set_from_pixbuf (GTK_IMAGE (status_icon->priv->image), NULL); } } break; case GTK_IMAGE_STOCK: case GTK_IMAGE_ANIMATION: case GTK_IMAGE_EMPTY: gtk_image_set_from_pixbuf (GTK_IMAGE (status_icon->priv->image), NULL); break; default: g_assert_not_reached (); break; } }
/** * filter_editor_new: * * Returns: a new #GtkWidget */ GtkWidget * filter_editor_new (BrowserConnection *bcnc) { FilterEditor *feditor; GtkWidget *grid, *label, *entry; GdaDataModel *model; GList *values; GValue *v1, *v2; gfloat ya; g_return_val_if_fail (BROWSER_IS_CONNECTION (bcnc), NULL); feditor = FILTER_EDITOR (g_object_new (FILTER_EDITOR_TYPE, NULL)); feditor->priv->bcnc = g_object_ref ((GObject*) bcnc); grid = gtk_grid_new (); gtk_grid_set_column_spacing (GTK_GRID (grid), 5); gtk_box_pack_start (GTK_BOX (feditor), grid, TRUE, TRUE, 0); label = gtk_label_new (_("Base DN:")); gtk_misc_get_alignment (GTK_MISC (label), NULL, &ya); gtk_misc_set_alignment (GTK_MISC (label), 0., ya); gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1); label = gtk_label_new (_("Filter expression:")); gtk_misc_get_alignment (GTK_MISC (label), NULL, &ya); gtk_misc_set_alignment (GTK_MISC (label), 0., ya); gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1); label = gtk_label_new (_("Attributes to fetch:")); gtk_misc_get_alignment (GTK_MISC (label), NULL, &ya); gtk_misc_set_alignment (GTK_MISC (label), 0., ya); gtk_grid_attach (GTK_GRID (grid), label, 0, 2, 1, 1); label = gtk_label_new (_("Search scope:")); gtk_misc_get_alignment (GTK_MISC (label), NULL, &ya); gtk_misc_set_alignment (GTK_MISC (label), 0., ya); gtk_grid_attach (GTK_GRID (grid), label, 0, 3, 1, 1); entry = gtk_entry_new (); gtk_grid_attach (GTK_GRID (grid), entry, 1, 0, 1, 1); feditor->priv->base_dn = entry; g_signal_connect (entry, "activate", G_CALLBACK (activated_cb), feditor); entry = gtk_entry_new (); gtk_grid_attach (GTK_GRID (grid), entry, 1, 1, 1, 1); feditor->priv->filter = entry; g_signal_connect (entry, "activate", G_CALLBACK (activated_cb), feditor); entry = gtk_entry_new (); gtk_grid_attach (GTK_GRID (grid), entry, 1, 2, 1, 1); feditor->priv->attributes = entry; g_signal_connect (entry, "activate", G_CALLBACK (activated_cb), feditor); model = gda_data_model_array_new_with_g_types (2, G_TYPE_INT, G_TYPE_STRING); g_value_set_string ((v1 = gda_value_new (G_TYPE_STRING)), "Base (search the base DN only)"); values = g_list_prepend (NULL, v1); g_value_set_int ((v2 = gda_value_new (G_TYPE_INT)), GDA_LDAP_SEARCH_BASE); values = g_list_prepend (values, v2); g_assert (gda_data_model_append_values (model, values, NULL) >= 0); gda_value_free (v1); gda_value_free (v2); g_value_set_string ((v1 = gda_value_new (G_TYPE_STRING)), "Onelevel (search immediate children of base DN only)"); values = g_list_prepend (NULL, v1); g_value_set_int ((v2 = gda_value_new (G_TYPE_INT)), GDA_LDAP_SEARCH_ONELEVEL); values = g_list_prepend (values, v2); g_assert (gda_data_model_append_values (model, values, NULL) >= 0); gda_value_free (v1); gda_value_free (v2); g_value_set_string ((v1 = gda_value_new (G_TYPE_STRING)), "Subtree (search of the base DN and the entire subtree below)"); values = g_list_prepend (NULL, v1); g_value_set_int ((v2 = gda_value_new (G_TYPE_INT)), GDA_LDAP_SEARCH_SUBTREE); values = g_list_prepend (values, v2); g_assert (gda_data_model_append_values (model, values, NULL) >= 0); gda_value_free (v1); gda_value_free (v2); gint cols[] = {1}; entry = gdaui_combo_new_with_model (model, 1, cols); g_object_unref (model); gtk_grid_attach (GTK_GRID (grid), entry, 1, 3, 1, 1); feditor->priv->scope = entry; filter_editor_clear (feditor); gtk_widget_show_all (grid); return (GtkWidget*) feditor; }
/** * gtk_ellipsis_set_label_widget: * @ellipsis: a #GtkEllipsis * @label: the new label widget * * Set the label widget for the ellipsis. This is the widget * that will appear embedded alongside the ellipsis arrow. * * Since: 2.4 **/ void gtk_ellipsis_set_label_widget (GtkEllipsis *ellipsis, GtkWidget *label) { GtkEllipsisPrivate *priv; g_return_if_fail (GTK_IS_ELLIPSIS (ellipsis)); g_return_if_fail (label == NULL || GTK_IS_WIDGET (label)); g_return_if_fail (label == NULL || label->parent == NULL); priv = ellipsis->priv; if (priv->label == label) return; if (priv->label) { gtk_widget_set_state (priv->label, GTK_STATE_NORMAL); gtk_widget_unparent (priv->label); } priv->label = label; if (label) { gfloat xalign, yalign; gtk_misc_get_alignment (>K_LABEL (label)->misc, &xalign, &yalign); gtk_misc_set_alignment (>K_LABEL (label)->misc, 0.0, yalign); gtk_widget_set_parent (label, GTK_WIDGET (ellipsis)); if (!priv->ellipsis_label) { GdkColor *link_color, active_bg_color; GtkWidget *child; PangoAttrList *attrs; PangoAttribute *uline; child = gtk_label_new ("..."); /* Change the foreground color for all states but selected. */ gtk_widget_style_get (GTK_WIDGET (child), "link-color", &link_color, NULL); if (!link_color) { GtkStyle *style = gtk_widget_get_style (child); active_bg_color = style->bg[GTK_STATE_SELECTED]; link_color = &active_bg_color; } gtk_widget_modify_fg (child, GTK_STATE_NORMAL, link_color); gtk_widget_modify_fg (child, GTK_STATE_ACTIVE, link_color); gtk_widget_modify_fg (child, GTK_STATE_PRELIGHT, link_color); if (link_color != &active_bg_color) gdk_color_free (link_color); /* Add an underline. */ attrs = gtk_label_get_attributes (GTK_LABEL (label)); attrs = attrs ? pango_attr_list_copy (attrs) : pango_attr_list_new (); uline = pango_attr_underline_new (PANGO_UNDERLINE_SINGLE); uline->start_index = 0; uline->end_index = G_MAXUINT; pango_attr_list_insert (attrs, uline); gtk_label_set_attributes (GTK_LABEL (child), attrs); pango_attr_list_unref (attrs); gtk_widget_show (child); gtk_widget_set_parent (child, GTK_WIDGET (ellipsis)); priv->ellipsis_label = child; } if (priv->prelight) { gtk_widget_set_state (label, GTK_STATE_PRELIGHT); gtk_widget_set_state (priv->ellipsis_label, GTK_STATE_PRELIGHT); } } else { if (priv->ellipsis_label) { gtk_widget_destroy (priv->ellipsis_label); priv->ellipsis_label = NULL; } } if (GTK_WIDGET_VISIBLE (ellipsis)) gtk_widget_queue_resize (GTK_WIDGET (ellipsis)); g_object_freeze_notify (G_OBJECT (ellipsis)); g_object_notify (G_OBJECT (ellipsis), "label-widget"); g_object_notify (G_OBJECT (ellipsis), "label"); g_object_thaw_notify (G_OBJECT (ellipsis)); }