static gboolean _adg_cell_set_title(AdgTableCell *table_cell, AdgEntity *title) { AdgEntity *alignment; if (table_cell->title == title) return FALSE; if (table_cell->title) { alignment = adg_entity_get_parent(table_cell->title); g_object_unref(alignment); } table_cell->title = title; if (title) { AdgEntity *table = (AdgEntity *) adg_table_cell_get_table(table_cell); alignment = (AdgEntity *) adg_alignment_new_explicit(0, -1); g_object_ref_sink(alignment); adg_entity_set_parent(alignment, table); adg_container_add((AdgContainer *) alignment, title); } return TRUE; }
static gboolean _adg_cell_set_value(AdgTableCell *table_cell, AdgEntity *value) { AdgEntity *alignment; if (table_cell->value == value) return FALSE; if (value) { AdgEntity *table = (AdgEntity *) adg_table_cell_get_table(table_cell); alignment = (AdgEntity *) adg_alignment_new_explicit(0.5, 0); g_object_ref_sink(alignment); adg_entity_set_parent(alignment, table); adg_container_add((AdgContainer *) alignment, value); } if (table_cell->value) { alignment = adg_entity_get_parent(table_cell->value); adg_container_remove((AdgContainer *) alignment, table_cell->value); g_object_unref(alignment); } table_cell->value = value; return TRUE; }
int main(int argc, char *argv[]) { AdgAlignment *alignment; adg_test_init(&argc, &argv); adg_test_add_object_checks("/adg/alignment/type/object", ADG_TYPE_ALIGNMENT); adg_test_add_entity_checks("/adg/alignment/type/entity", ADG_TYPE_ALIGNMENT); adg_test_add_container_checks("/adg/alignment/type/container", ADG_TYPE_ALIGNMENT); alignment = adg_alignment_new_explicit(0.5, 0.5); adg_container_add(ADG_CONTAINER(alignment), ADG_ENTITY(adg_logo_new())); adg_test_add_global_space_checks("/adg/alignment/behavior/global-space", alignment); alignment = adg_alignment_new_explicit(0.5, 0.5); adg_container_add(ADG_CONTAINER(alignment), ADG_ENTITY(adg_logo_new())); adg_test_add_local_space_checks("/adg/alignment/behavior/local-space", alignment); g_test_add_func("/adg/alignment/property/factor", _adg_property_factor); return g_test_run(); }
static void _adg_behavior_misc(void) { AdgContainer *container; AdgEntity *entity1, *entity2; GSList *children; container = adg_container_new(); entity1 = ADG_ENTITY(adg_toy_text_new("Testing...")); entity2 = ADG_ENTITY(adg_title_block_new()); children = adg_container_children(container); g_assert_null(children); adg_container_add(container, entity1); children = adg_container_children(container); g_assert_nonnull(children); g_assert_cmpint(g_slist_length(children), ==, 1); g_slist_free(children); adg_container_add(container, entity2); children = adg_container_children(container); g_assert_nonnull(children); g_assert_cmpint(g_slist_length(children), ==, 2); g_slist_free(children); adg_entity_destroy(entity1); children = adg_container_children(container); g_assert_nonnull(children); g_assert_cmpint(g_slist_length(children), ==, 1); g_slist_free(children); adg_entity_destroy(entity2); children = adg_container_children(container); g_assert_null(children); adg_entity_destroy(ADG_ENTITY(container)); }
int main(int argc, char *argv[]) { AdgContainer *container; adg_test_init(&argc, &argv); g_test_add_func("/adg/container/behavior/misc", _adg_behavior_misc); adg_test_add_object_checks("/adg/container/type/object", ADG_TYPE_CONTAINER); adg_test_add_entity_checks("/adg/container/type/entity", ADG_TYPE_CONTAINER); adg_test_add_container_checks("/adg/container/type/container", ADG_TYPE_CONTAINER); container = adg_container_new(); adg_container_add(container, ADG_ENTITY(adg_logo_new())); adg_test_add_global_space_checks("/adg/container/behavior/global-space", container); container = adg_container_new(); adg_container_add(container, ADG_ENTITY(adg_logo_new())); adg_test_add_local_space_checks("/adg/container/behavior/local-space", container); g_test_add_func("/adg/container/property/child", _adg_property_child); return g_test_run(); }
static void _adg_arrange(AdgEntity *entity) { AdgDim *dim; AdgDimPrivate *data; AdgEntity *quote_entity; AdgContainer *quote_container; AdgEntity *value_entity; AdgEntity *min_entity; AdgEntity *max_entity; const CpmlPair *shift; cairo_matrix_t map; dim = (AdgDim *) entity; data = dim->data; /* Resolve the dim style */ if (data->dim_style == NULL) data->dim_style = (AdgDimStyle *) adg_entity_style(entity, data->dim_dress); if (data->quote.entity == NULL) data->quote.entity = g_object_new(ADG_TYPE_ALIGNMENT, "local-mix", ADG_MIX_NONE, "parent", dim, NULL); quote_entity = (AdgEntity *) data->quote.entity; quote_container = (AdgContainer *) data->quote.entity; if (data->quote.value == NULL) { AdgDimClass *klass; AdgDress dress; const gchar *tag; gchar *value; gchar *text; klass = ADG_DIM_GET_CLASS(dim); dress = adg_dim_style_get_value_dress(data->dim_style); tag = adg_dim_style_get_number_tag(data->dim_style); value = klass->default_value ? klass->default_value(dim) : NULL; data->quote.value = g_object_new(ADG_TYPE_BEST_TEXT, "local-mix", ADG_MIX_PARENT, "font-dress", dress, NULL); adg_container_add(quote_container, (AdgEntity *) data->quote.value); if (data->value) text = adg_string_replace(data->value, tag, value); else text = g_strdup(value); g_free(value); adg_textual_set_text(data->quote.value, text); g_free(text); } if (data->quote.min == NULL && data->min != NULL) { AdgDress dress = adg_dim_style_get_min_dress(data->dim_style); data->quote.min = g_object_new(ADG_TYPE_BEST_TEXT, "local-mix", ADG_MIX_PARENT, "font-dress", dress, NULL); adg_container_add(quote_container, (AdgEntity *) data->quote.min); adg_textual_set_text(data->quote.min, data->min); } if (data->quote.max == NULL && data->max != NULL) { AdgDress dress = adg_dim_style_get_max_dress(data->dim_style); data->quote.max = g_object_new(ADG_TYPE_BEST_TEXT, "local-mix", ADG_MIX_PARENT, "font-dress", dress, NULL); adg_container_add(quote_container, (AdgEntity *) data->quote.max); adg_textual_set_text(data->quote.max, data->max); } value_entity = (AdgEntity *) data->quote.value; min_entity = (AdgEntity *) data->quote.min; max_entity = (AdgEntity *) data->quote.max; shift = adg_dim_style_get_quote_shift(data->dim_style); adg_entity_set_global_map(quote_entity, adg_matrix_identity()); adg_entity_global_changed(quote_entity); cairo_matrix_init_translate(&map, 0, shift->y); adg_entity_set_global_map(value_entity, &map); adg_entity_arrange(value_entity); /* Limit values (min and max) */ if (min_entity != NULL || max_entity != NULL) { const CpmlPair *limits_shift; gdouble spacing; CpmlPair size; CpmlPair org_min, org_max; limits_shift = adg_dim_style_get_limits_shift(data->dim_style); spacing = adg_dim_style_get_limits_spacing(data->dim_style); size = adg_entity_get_extents(value_entity)->size; org_min.x = size.x + limits_shift->x; org_min.y = -size.y / 2 + limits_shift->y; org_max = org_min; if (min_entity && max_entity) { /* Prearrange the min entity to get its extents */ adg_entity_arrange(min_entity); size = adg_entity_get_extents(min_entity)->size; org_min.y += spacing / 2; org_max.y = org_min.y - size.y - spacing / 2; } if (min_entity != NULL) { cairo_matrix_init_translate(&map, org_min.x, org_min.y); adg_entity_set_global_map(min_entity, &map); adg_entity_arrange(min_entity); } if (max_entity != NULL) { cairo_matrix_init_translate(&map, org_max.x, org_max.y); adg_entity_set_global_map(max_entity, &map); adg_entity_arrange(max_entity); } } }
static void _adg_property_child(void) { AdgContainer *container; AdgEntity *valid_entity, *invalid_entity; GSList *children; container = adg_container_new(); valid_entity = ADG_ENTITY(adg_logo_new()); invalid_entity = adg_test_invalid_pointer(); /* Keep alive the entity between all the tests */ g_object_ref(valid_entity); /* Using the public APIs */ adg_container_add(container, NULL); children = adg_container_children(container); g_assert_null(children); adg_container_add(container, invalid_entity); children = adg_container_children(container); g_assert_null(children); adg_container_add(container, valid_entity); children = adg_container_children(container); g_assert_nonnull(children); g_assert_true(children->data == valid_entity); g_slist_free(children); adg_container_remove(container, invalid_entity); children = adg_container_children(container); g_assert_nonnull(children); g_assert_true(children->data == valid_entity); g_slist_free(children); adg_container_remove(container, valid_entity); children = adg_container_children(container); g_assert_null(children); /* Using GObject property methods */ g_object_set(container, "child", NULL, NULL); children = adg_container_children(container); g_assert_null(children); g_object_set(container, "child", invalid_entity, NULL); children = adg_container_children(container); g_assert_null(children); g_object_set(container, "child", valid_entity, NULL); children = adg_container_children(container); g_assert_nonnull(children); g_assert_true(children->data == valid_entity); g_slist_free(children); adg_container_remove(container, valid_entity); children = adg_container_children(container); g_assert_null(children); adg_entity_destroy(ADG_ENTITY(container)); adg_entity_destroy(valid_entity); }