Пример #1
0
/* called when some state in an embedded html object has changed ... do a redraw */
static void
html_embedded_object_changed (GtkHTMLEmbedded *eb,
                              HTMLEngine *e)
{
	HTMLObject *object;

	object = HTML_OBJECT (g_object_get_data (G_OBJECT (eb), "embeddedelement"));
	if (object)
		html_object_calc_size (object, e->painter, NULL);

	html_engine_schedule_update (e);
}
Пример #2
0
static gboolean
relayout (HTMLObject *self,
	  HTMLEngine *engine,
	  HTMLObject *child)
{
	gint prev_width, prev_ascent, prev_descent;
	gboolean changed;

	if (html_engine_frozen (engine))
		return FALSE;

	if (child == NULL)
		child = HTML_CLUE (self)->head;
	html_object_calc_size (child, engine->painter, NULL);

	HTML_CLUE (self)->curr = NULL;

	prev_width = self->width;
	prev_ascent = self->ascent;
	prev_descent = self->descent;

	changed = html_cluev_do_layout (self, engine->painter, FALSE, NULL);
	if (changed)
		html_engine_queue_draw (engine, self);

	if (prev_width == self->width
	    && prev_ascent == self->ascent
	    && prev_descent == self->descent)
		return FALSE;

	if (self->parent == NULL) {
		/* FIXME resize the widget, e.g. scrollbars and such.  */
		html_engine_queue_draw (engine, self);

		/* FIXME extreme ugliness.  */
		self->x = 0;
		self->y = self->ascent;
	} else {
		/* Relayout our parent starting from us.  */
		if (!html_object_relayout (self->parent, engine, self))
			html_engine_queue_draw (engine, self);
	}

	/* If the object has shrunk, we have to clean the areas around
	   it so that we don't leave garbage on the screen.  FIXME:
	   this wastes some time if there is an object on the right of
	   or under this one.  */

	if (prev_ascent + prev_descent > self->ascent + self->descent)
		html_engine_queue_clear (engine,
					 self->x,
					 self->y + self->descent,
					 self->width,
					 (prev_ascent + prev_descent
					  - (self->ascent + self->descent)));

	if (prev_width > self->width)
		html_engine_queue_clear (engine,
					 self->x + self->width,
					 self->y - self->ascent,
					 prev_width - self->width,
					 self->ascent + self->descent);

	return TRUE;
}
Пример #3
0
static gboolean
html_cluev_do_layout (HTMLObject *o, HTMLPainter *painter, gboolean calc_size, GList **changed_objs)
{
	HTMLClueV *cluev;
	HTMLClue *clue;
	HTMLObject *obj;
	HTMLObject *aclue;
	GList *local_changed_objs;
	gint lmargin;
	gboolean changed;
	gint old_width, old_ascent, old_descent;
	gint new_x;
	gint pixel_size;
	gint padding;
	gint padding2;
	gboolean first_change;
	gint first_y_off = 0;

	/* printf ("HTMLClueV::do_layout\n"); */

	cluev = HTML_CLUEV (o);
	clue = HTML_CLUE (o);

	pixel_size = html_painter_get_pixel_size (painter);
	padding    = pixel_size * (cluev->padding + cluev->border_width);
	padding2   = 2 * padding;

	old_width = o->width;
	old_ascent = o->ascent;
	old_descent = o->descent;

	changed = FALSE;
	first_change = TRUE;
	local_changed_objs = NULL;

	lmargin = get_lmargin (o, painter);

	/* If we have already called calc_size for the children, then just
	   continue from the last object done in previous call. */

	if (clue->curr != NULL) {
		if (clue->curr->prev)
			o->ascent = clue->curr->prev->y + clue->curr->prev->descent;
		else
			o->ascent = padding;
		remove_aligned_by_parent (cluev, clue->curr);
	} else {
		o->width = 0;
		o->ascent = padding;
		o->descent = 0;
		clue->curr = clue->head;
	}

	while (clue->curr != NULL) {
		gint old_y, old_y_off, new_y_off;
		/* Set an initial ypos so that the alignment stuff knows where
		   the top of this object is */
		old_y = clue->curr->y;
		old_y_off = clue->curr->y - clue->curr->ascent;
		clue->curr->y = o->ascent;

		switch (html_object_get_clear (clue->curr)) {
		case HTML_CLEAR_ALL: {
			gint y;

			do {
				y = clue->curr->y;
				clue->curr->y = html_clue_get_left_clear (clue, clue->curr->y);
				clue->curr->y = html_clue_get_right_clear (clue, clue->curr->y);
			} while (clue->curr->y != y);
			break;
		}
		case HTML_CLEAR_LEFT:
			clue->curr->y = html_clue_get_left_clear (clue, clue->curr->y);
			break;
		case HTML_CLEAR_RIGHT:
			clue->curr->y = html_clue_get_right_clear (clue, clue->curr->y);
			break;
		case HTML_CLEAR_NONE:
			break;
		case HTML_CLEAR_INHERIT:
			/* TODO */
			break;
		}

		o->ascent = clue->curr->y;
		lmargin = get_lmargin (o, painter);

		if (calc_size)
			changed |= html_object_calc_size (clue->curr, painter, changed_objs);

		if (o->width < clue->curr->width + padding2)
			o->width = clue->curr->width + padding2;
		o->ascent += clue->curr->ascent + clue->curr->descent;

		new_y_off = o->ascent - clue->curr->descent - clue->curr->ascent;
		if (clue->curr->x != lmargin || old_y_off != new_y_off) {
			if (changed_objs) {
				/* printf ("y: %d ", o->ascent - clue->curr->descent); */
				if (first_change) {
					first_change = FALSE;
					/* if it's new one (y == 0) clear from new y_off, else from old one or new one,
					   which one is higher */
					first_y_off = old_y && old_y_off < new_y_off ? old_y_off : new_y_off;
					/* printf ("\nfirst_y_off: %d x %d --> %d\n", old_y_off, new_y_off, first_y_off); */
				}
				html_object_add_to_changed (&local_changed_objs, clue->curr);
			}
		}
		clue->curr->x = lmargin;
		clue->curr->y = o->ascent - clue->curr->descent;

		clue->curr = clue->curr->next;
	}

	o->ascent += padding;

	/* Remember the last object so that we can start from here next time
	   we are called. */
	clue->curr = clue->tail;

	if (o->max_width != 0 && o->width < o->max_width)
		o->width = o->max_width;

	if (clue->halign == HTML_HALIGN_CENTER) {
		for (obj = clue->head; obj != 0; obj = obj->next) {
			new_x = lmargin + (o->width - obj->width - padding2) / 2;
			if (obj->x != new_x) {
				obj->x = new_x;
				changed = TRUE;
			}
		}
	} else if (clue->halign == HTML_HALIGN_RIGHT) {
		for (obj = clue->head; obj != 0; obj = obj->next) {
			new_x = lmargin + (o->width - obj->width - padding2);
			if (obj->x != new_x) {
				obj->x = new_x;
				changed = TRUE;
			}
		}
	}

	for (aclue = cluev->align_left_list; aclue != NULL; aclue = cluev_next_aligned (aclue)) {
		if (aclue->y + aclue->parent->y - aclue->parent->ascent > o->ascent)
			o->ascent = aclue->y + aclue->parent->y - aclue->parent->ascent;
	}

	for (aclue = cluev->align_right_list; aclue != NULL; aclue = cluev_next_aligned (aclue)) {
		if (aclue->y + aclue->parent->y - aclue->parent->ascent > o->ascent)
			o->ascent = aclue->y + aclue->parent->y - aclue->parent->ascent;
	}

	if (!changed
	    && (o->ascent != old_ascent || o->descent != old_descent || o->width != old_width))
		changed = TRUE;

	if (changed_objs && local_changed_objs) {
		if (!first_change && o->width > o->max_width) {
			add_clear_area_behind (changed_objs, o, o->max_width, first_y_off,
					       o->width - o->max_width, o->ascent + o->descent - first_y_off);
		}
		*changed_objs = g_list_concat (local_changed_objs, *changed_objs);
	}

	return changed;
}