Compare commits

...

6 Commits

Author SHA1 Message Date
Timm Bäder
0694b9b204 Inspector: add & use GtkWidgetView
Use it to show a visual representation of the focus widget in a toplevel
2019-01-23 17:14:32 +01:00
Timm Bäder
4047fa34bb csstransformvalue: Convert skew values to radians 2019-01-22 06:25:22 +01:00
Timm Bäder
880006bb46 label: Use pango_layout_get_log_attrs_readonly
No need to memdup the log attrs in this case.
2019-01-22 06:25:22 +01:00
Timm Bäder
cd4712380b cssparser: Make _gtk_css_parser_try a macro
We almost always pass a constant string to it, so use a macro and try to
trick the compiler into evaluating the 2(!) strlen() calls at compile
time.
2019-01-22 06:25:22 +01:00
Timm Bäder
5b3e0e11a2 cssanimatedstyle: Avoid some type checks and unnecessary work 2019-01-22 06:25:22 +01:00
Timm Bäder
51a0f98900 scrolledwindow: Don't NULL the indicator widget in unmap
We still have the widget, so just keep the pointer to it.
2019-01-22 06:25:22 +01:00
14 changed files with 168 additions and 51 deletions

View File

@@ -186,14 +186,13 @@ transition_info_add (TransitionInfo infos[GTK_CSS_PROPERTY_N_PROPERTIES],
GtkStyleProperty *property, GtkStyleProperty *property,
guint index) guint index)
{ {
gtk_internal_return_if_fail (GTK_IS_STYLE_PROPERTY (property));
if (GTK_IS_CSS_SHORTHAND_PROPERTY (property)) if (GTK_IS_CSS_SHORTHAND_PROPERTY (property))
{ {
GtkCssShorthandProperty *shorthand = GTK_CSS_SHORTHAND_PROPERTY (property); GtkCssShorthandProperty *shorthand = (GtkCssShorthandProperty *) property;
guint len = _gtk_css_shorthand_property_get_n_subproperties (shorthand);
guint i; guint i;
for (i = 0; i < _gtk_css_shorthand_property_get_n_subproperties (shorthand); i++) for (i = 0; i < len; i++)
{ {
GtkCssStyleProperty *prop = _gtk_css_shorthand_property_get_subproperty (shorthand, i); GtkCssStyleProperty *prop = _gtk_css_shorthand_property_get_subproperty (shorthand, i);
@@ -228,9 +227,10 @@ transition_infos_set (TransitionInfo infos[GTK_CSS_PROPERTY_N_PROPERTIES],
prop_value = _gtk_css_array_value_get_nth (transitions, i); prop_value = _gtk_css_array_value_get_nth (transitions, i);
if (g_ascii_strcasecmp (_gtk_css_ident_value_get (prop_value), "all") == 0) if (g_ascii_strcasecmp (_gtk_css_ident_value_get (prop_value), "all") == 0)
{ {
const guint len = _gtk_css_style_property_get_n_properties ();
guint j; guint j;
for (j = 0; j < _gtk_css_style_property_get_n_properties (); j++) for (j = 0; j < len; j++)
{ {
property = GTK_STYLE_PROPERTY (_gtk_css_style_property_lookup_by_id (j)); property = GTK_STYLE_PROPERTY (_gtk_css_style_property_lookup_by_id (j));
transition_info_add (infos, property, i); transition_info_add (infos, property, i);

View File

@@ -151,7 +151,6 @@ _gtk_css_color_value_resolve (GtkCssValue *color,
GtkCssValue *value; GtkCssValue *value;
gtk_internal_return_val_if_fail (color != NULL, NULL); gtk_internal_return_val_if_fail (color != NULL, NULL);
gtk_internal_return_val_if_fail (provider == NULL || GTK_IS_STYLE_PROVIDER (provider), NULL);
switch (color->type) switch (color->type)
{ {

View File

@@ -298,17 +298,18 @@ _gtk_css_parser_skip_whitespace (GtkCssParser *parser)
} }
gboolean gboolean
_gtk_css_parser_try (GtkCssParser *parser, gtk_css_parser_try_len (GtkCssParser *parser,
const char *string, const char *string,
gboolean skip_whitespace) gsize string_len,
gboolean skip_whitespace)
{ {
g_return_val_if_fail (GTK_IS_CSS_PARSER (parser), FALSE); g_return_val_if_fail (GTK_IS_CSS_PARSER (parser), FALSE);
g_return_val_if_fail (string != NULL, FALSE); g_return_val_if_fail (string != NULL, FALSE);
if (g_ascii_strncasecmp (parser->data, string, strlen (string)) != 0) if (g_ascii_strncasecmp (parser->data, string, string_len) != 0)
return FALSE; return FALSE;
parser->data += strlen (string); parser->data += string_len;
if (skip_whitespace) if (skip_whitespace)
_gtk_css_parser_skip_whitespace (parser); _gtk_css_parser_skip_whitespace (parser);

View File

@@ -66,8 +66,10 @@ gboolean _gtk_css_parser_is_string (GtkCssParser *parser
* however is fine to call if you dont know yet if the token is a foo or a bar, * however is fine to call if you dont know yet if the token is a foo or a bar,
* you can _try_bar() if try_foo() failed. * you can _try_bar() if try_foo() failed.
*/ */
gboolean _gtk_css_parser_try (GtkCssParser *parser, #define _gtk_css_parser_try(p, s, skip) (gtk_css_parser_try_len (p, s, strlen(s), skip))
gboolean gtk_css_parser_try_len (GtkCssParser *parser,
const char *string, const char *string,
gsize string_len,
gboolean skip_whitespace); gboolean skip_whitespace);
char * _gtk_css_parser_try_ident (GtkCssParser *parser, char * _gtk_css_parser_try_ident (GtkCssParser *parser,
gboolean skip_whitespace); gboolean skip_whitespace);

View File

@@ -207,9 +207,6 @@ gtk_css_static_style_compute_value (GtkCssStaticStyle *style,
{ {
GtkCssValue *value; GtkCssValue *value;
gtk_internal_return_if_fail (GTK_IS_CSS_STATIC_STYLE (style));
gtk_internal_return_if_fail (GTK_IS_STYLE_PROVIDER (provider));
gtk_internal_return_if_fail (parent_style == NULL || GTK_IS_CSS_STYLE (parent_style));
gtk_internal_return_if_fail (id < GTK_CSS_PROPERTY_N_PROPERTIES); gtk_internal_return_if_fail (id < GTK_CSS_PROPERTY_N_PROPERTIES);
/* http://www.w3.org/TR/css3-cascade/#cascade /* http://www.w3.org/TR/css3-cascade/#cascade

View File

@@ -200,14 +200,14 @@ gtk_css_transform_apply (const GtkCssTransform *transform,
break; break;
case GTK_CSS_TRANSFORM_SKEW: case GTK_CSS_TRANSFORM_SKEW:
graphene_matrix_init_skew (&skew, graphene_matrix_init_skew (&skew,
_gtk_css_number_value_get (transform->skew.x, 100), _gtk_css_number_value_get (transform->skew.x, 100) / 180.0f * G_PI,
_gtk_css_number_value_get (transform->skew.y, 100)); _gtk_css_number_value_get (transform->skew.y, 100) /180.0f * G_PI);
graphene_matrix_multiply (matrix, &skew, &tmp); graphene_matrix_multiply (matrix, &skew, &tmp);
graphene_matrix_init_from_matrix (matrix, &tmp); graphene_matrix_init_from_matrix (matrix, &tmp);
break; break;
case GTK_CSS_TRANSFORM_SKEW_X: case GTK_CSS_TRANSFORM_SKEW_X:
graphene_matrix_init_skew (&skew, graphene_matrix_init_skew (&skew,
_gtk_css_number_value_get (transform->skew_x.skew, 100), _gtk_css_number_value_get (transform->skew_x.skew, 100) / 180.0f * G_PI,
0); 0);
graphene_matrix_multiply (matrix, &skew, &tmp); graphene_matrix_multiply (matrix, &skew, &tmp);
graphene_matrix_init_from_matrix (matrix, &tmp); graphene_matrix_init_from_matrix (matrix, &tmp);
@@ -215,7 +215,7 @@ gtk_css_transform_apply (const GtkCssTransform *transform,
case GTK_CSS_TRANSFORM_SKEW_Y: case GTK_CSS_TRANSFORM_SKEW_Y:
graphene_matrix_init_skew (&skew, graphene_matrix_init_skew (&skew,
0, 0,
_gtk_css_number_value_get (transform->skew_y.skew, 100)); _gtk_css_number_value_get (transform->skew_y.skew, 100) / 180.0f * G_PI);
graphene_matrix_multiply (matrix, &skew, &tmp); graphene_matrix_multiply (matrix, &skew, &tmp);
graphene_matrix_init_from_matrix (matrix, &tmp); graphene_matrix_init_from_matrix (matrix, &tmp);
break; break;

View File

@@ -5638,15 +5638,15 @@ gtk_label_move_logically (GtkLabel *label,
if (priv->text) if (priv->text)
{ {
PangoLogAttr *log_attrs; const PangoLogAttr *log_attrs;
gint n_attrs; gint n_attrs;
gint length; gint length;
gtk_label_ensure_layout (label); gtk_label_ensure_layout (label);
length = g_utf8_strlen (priv->text, -1); length = g_utf8_strlen (priv->text, -1);
pango_layout_get_log_attrs (priv->layout, &log_attrs, &n_attrs); log_attrs = pango_layout_get_log_attrs_readonly (priv->layout, &n_attrs);
while (count > 0 && offset < length) while (count > 0 && offset < length)
{ {
@@ -5664,8 +5664,6 @@ gtk_label_move_logically (GtkLabel *label,
count++; count++;
} }
g_free (log_attrs);
} }
return g_utf8_offset_to_pointer (priv->text, offset) - priv->text; return g_utf8_offset_to_pointer (priv->text, offset) - priv->text;
@@ -5738,19 +5736,17 @@ gtk_label_move_forward_word (GtkLabel *label,
length = g_utf8_strlen (priv->text, -1); length = g_utf8_strlen (priv->text, -1);
if (new_pos < length) if (new_pos < length)
{ {
PangoLogAttr *log_attrs; const PangoLogAttr *log_attrs;
gint n_attrs; gint n_attrs;
gtk_label_ensure_layout (label); gtk_label_ensure_layout (label);
pango_layout_get_log_attrs (priv->layout, &log_attrs, &n_attrs); log_attrs = pango_layout_get_log_attrs_readonly (priv->layout, &n_attrs);
/* Find the next word end */ /* Find the next word end */
new_pos++; new_pos++;
while (new_pos < n_attrs && !log_attrs[new_pos].is_word_end) while (new_pos < n_attrs && !log_attrs[new_pos].is_word_end)
new_pos++; new_pos++;
g_free (log_attrs);
} }
return g_utf8_offset_to_pointer (priv->text, new_pos) - priv->text; return g_utf8_offset_to_pointer (priv->text, new_pos) - priv->text;
@@ -5767,20 +5763,18 @@ gtk_label_move_backward_word (GtkLabel *label,
if (new_pos > 0) if (new_pos > 0)
{ {
PangoLogAttr *log_attrs; const PangoLogAttr *log_attrs;
gint n_attrs; gint n_attrs;
gtk_label_ensure_layout (label); gtk_label_ensure_layout (label);
pango_layout_get_log_attrs (priv->layout, &log_attrs, &n_attrs); log_attrs = pango_layout_get_log_attrs_readonly (priv->layout, &n_attrs);
new_pos -= 1; new_pos -= 1;
/* Find the previous word beginning */ /* Find the previous word beginning */
while (new_pos > 0 && !log_attrs[new_pos].is_word_start) while (new_pos > 0 && !log_attrs[new_pos].is_word_start)
new_pos--; new_pos--;
g_free (log_attrs);
} }
return g_utf8_offset_to_pointer (priv->text, new_pos) - priv->text; return g_utf8_offset_to_pointer (priv->text, new_pos) - priv->text;

View File

@@ -3606,7 +3606,6 @@ indicator_reset (Indicator *indicator)
indicator->tick_id = 0; indicator->tick_id = 0;
} }
indicator->scrollbar = NULL;
indicator->over = FALSE; indicator->over = FALSE;
gtk_progress_tracker_finish (&indicator->tracker); gtk_progress_tracker_finish (&indicator->tracker);
indicator->current_pos = indicator->source_pos = indicator->target_pos = 0; indicator->current_pos = indicator->source_pos = indicator->target_pos = 0;

View File

@@ -48,6 +48,7 @@
#include "visual.h" #include "visual.h"
#include "window.h" #include "window.h"
#include "gtkstackcombo.h" #include "gtkstackcombo.h"
#include "widgetview.h"
#include "gtkmagnifierprivate.h" #include "gtkmagnifierprivate.h"
@@ -85,6 +86,7 @@ gtk_inspector_init (void)
g_type_ensure (GTK_TYPE_INSPECTOR_VISUAL); g_type_ensure (GTK_TYPE_INSPECTOR_VISUAL);
g_type_ensure (GTK_TYPE_INSPECTOR_WINDOW); g_type_ensure (GTK_TYPE_INSPECTOR_WINDOW);
g_type_ensure (GTK_TYPE_STACK_COMBO); g_type_ensure (GTK_TYPE_STACK_COMBO);
g_type_ensure (GTK_TYPE_WIDGET_VIEW);
if (extension_point == NULL) if (extension_point == NULL)
{ {

View File

@@ -37,5 +37,6 @@ inspector_sources = files(
'treewalk.c', 'treewalk.c',
'updatesoverlay.c', 'updatesoverlay.c',
'visual.c', 'visual.c',
'widgetview.c',
'window.c', 'window.c',
) )

View File

@@ -29,6 +29,7 @@
#include "gtkframe.h" #include "gtkframe.h"
#include "gtkbutton.h" #include "gtkbutton.h"
#include "gtkwidgetprivate.h" #include "gtkwidgetprivate.h"
#include "widgetview.h"
struct _GtkInspectorMiscInfoPrivate { struct _GtkInspectorMiscInfoPrivate {
@@ -223,19 +224,10 @@ update_focus_widget (GtkInspectorMiscInfo *sl)
GtkWidget *widget; GtkWidget *widget;
widget = gtk_window_get_focus (GTK_WINDOW (sl->priv->object)); widget = gtk_window_get_focus (GTK_WINDOW (sl->priv->object));
if (widget)
{ gtk_widget_view_set_inspected_widget (GTK_WIDGET_VIEW (sl->priv->focus_widget),
gchar *tmp; widget);
tmp = g_strdup_printf ("%p", widget); gtk_widget_set_sensitive (sl->priv->focus_widget_button, widget != NULL);
gtk_label_set_label (GTK_LABEL (sl->priv->focus_widget), tmp);
g_free (tmp);
gtk_widget_set_sensitive (sl->priv->focus_widget_button, TRUE);
}
else
{
gtk_label_set_label (GTK_LABEL (sl->priv->focus_widget), "NULL");
gtk_widget_set_sensitive (sl->priv->focus_widget_button, FALSE);
}
} }
static void static void

View File

@@ -176,11 +176,9 @@
</object> </object>
</child> </child>
<child> <child>
<object class="GtkLabel" id="focus_widget"> <object class="GtkWidgetView" id="focus_widget">
<property name="selectable">1</property>
<property name="halign">end</property> <property name="halign">end</property>
<property name="valign">baseline</property> <property name="valign">baseline</property>
<property name="ellipsize">end</property>
</object> </object>
</child> </child>
<child> <child>

View File

@@ -0,0 +1,93 @@
#include "widgetview.h"
#include "gtklabel.h"
#include "gtkpicture.h"
#include "gtkbox.h"
G_DEFINE_TYPE (GtkWidgetView, gtk_widget_view, GTK_TYPE_WIDGET);
static void
gtk_widget_view_measure (GtkWidget *widget,
GtkOrientation orientation,
int for_size,
int *minimum,
int *natural,
int *minimum_baseline,
int *natural_baseline)
{
GtkWidgetView *self = GTK_WIDGET_VIEW (widget);
gtk_widget_measure (self->box, orientation, for_size,
minimum, natural, minimum_baseline, natural_baseline);
}
static void
gtk_widget_view_size_allocate (GtkWidget *widget,
int width,
int height,
int baseline)
{
GtkWidgetView *self = GTK_WIDGET_VIEW (widget);
gtk_widget_size_allocate (self->box,
&(GtkAllocation) {
0, 0,
width, height
}, -1);
}
static void
gtk_widget_view_class_init (GtkWidgetViewClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
widget_class->measure = gtk_widget_view_measure;
widget_class->size_allocate = gtk_widget_view_size_allocate;
}
static void
gtk_widget_view_init (GtkWidgetView *self)
{
gtk_widget_set_has_surface (GTK_WIDGET (self), FALSE);
self->typename_label = gtk_label_new ("");
self->paintable_picture = gtk_picture_new ();
self->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
gtk_container_add (GTK_CONTAINER (self->box), self->typename_label);
gtk_container_add (GTK_CONTAINER (self->box), self->paintable_picture);
gtk_widget_set_parent (self->box, GTK_WIDGET (self));
}
GtkWidget *
gtk_widget_view_new (void)
{
return (GtkWidget *) g_object_new (GTK_TYPE_WIDGET_VIEW, NULL);
}
void
gtk_widget_view_set_inspected_widget (GtkWidgetView *self,
GtkWidget *inspected)
{
char typename_buffer[512];
GdkPaintable *paintable;
g_set_object (&self->inspected, inspected);
if (!self->inspected)
{
gtk_label_set_label (GTK_LABEL (self->typename_label), "NULL");
return;
}
g_snprintf (typename_buffer, sizeof (typename_buffer),
"%s", G_OBJECT_TYPE_NAME (inspected));
gtk_label_set_label (GTK_LABEL (self->typename_label), typename_buffer);
paintable = gtk_widget_paintable_new (inspected);
gtk_picture_set_paintable (GTK_PICTURE (self->paintable_picture), paintable);
g_object_unref (paintable);
}

View File

@@ -0,0 +1,39 @@
#ifndef __GTK_WIDGET_VIEW_H__
#define __GTK_WIDGET_VIEW_H__
#include "gtkwidget.h"
#include "gtkwidgetpaintable.h"
#define GTK_TYPE_WIDGET_VIEW (gtk_widget_view_get_type ())
#define GTK_WIDGET_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WIDGET_VIEW, GtkWidgetView))
#define GTK_WIDGET_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_WIDGET_VIEW, GtkWidgetViewClass))
#define GTK_IS_WIDGET_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_WIDGET_VIEW))
#define GTK_IS_WIDGET_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_WIDGET_VIEW))
#define GTK_WIDGET_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_WIDGET_VIEW, GtkWidgetViewClass))
typedef struct _GtkWidgetView GtkWidgetView;
typedef struct _GtkWidgetViewClass GtkWidgetViewClass;
struct _GtkWidgetView
{
GtkWidget parent_instance;
GtkWidget *box;
GtkWidget *typename_label;
GtkWidget *paintable_picture;
GtkWidget *inspected;
};
struct _GtkWidgetViewClass
{
GtkWidgetClass parent_class;
};
GType gtk_widget_view_get_type (void) G_GNUC_CONST;
GtkWidget * gtk_widget_view_new (void);
void gtk_widget_view_set_inspected_widget (GtkWidgetView *self,
GtkWidget *inspected);
#endif