Esempio n. 1
0
static void
table_set_bg_color (HTMLEngine *e,
                    HTMLTable *t,
                    GdkColor *c,
                    HTMLUndoDirection dir)
{
	HTMLTableSetAttrUndo *undo;

	undo = attr_undo_new (HTML_TABLE_BGCOLOR);
	if (t->bgColor) {
		undo->attr.color.color        = *t->bgColor;
		undo->attr.color.has_bg_color = TRUE;
	} else
		undo->attr.color.has_bg_color = FALSE;
	html_undo_add_action (e->undo, e,
			      html_undo_action_new ("Set table background color", table_set_bg_color_undo_action,
						    HTML_UNDO_DATA (undo),
						    html_cursor_get_position (e->cursor),
						    html_cursor_get_position (e->cursor)), dir);
	if (c) {
		if (!t->bgColor)
			t->bgColor = gdk_color_copy (c);
		*t->bgColor = *c;
	} else {
		if (t->bgColor)
			gdk_color_free (t->bgColor);
		t->bgColor = NULL;
	}
	html_engine_queue_draw (e, HTML_OBJECT (t));
}
Esempio n. 2
0
void
html_table_insert_column (HTMLTable *t,
                          HTMLEngine *e,
                          gint col,
                          HTMLTableCell **column,
                          HTMLUndoDirection dir)
{
	HTMLTableCell *cell;
	HTMLPoint pos;
	gint c, r;
	guint position_before;

	html_engine_freeze (e);

	position_before = e->cursor->position;
	pos.object = e->cursor->object;
	pos.offset = e->cursor->offset;

	html_engine_goto_table_0 (e, t);

	html_table_alloc_cell (t, 0, t->totalCols);
	for (c = t->totalCols - 1; c > col; c--) {
		for (r = 0; r < t->totalRows; r++) {
			HTMLTableCell *cell = t->cells[r][c - 1];

			if (cell) {
				if (cell->col == c - 1) {
					html_table_cell_set_position (cell, cell->row, c);
					t->cells[r][c - 1] = NULL;
				} else if (c == col + 1 && cell->row == r)
					cell->cspan++;
				if (cell->col > c - 1)
					t->cells[r][c - 1] = NULL;
				t->cells[r][c] = cell;
			}
		}
	}
	for (r = 0; r < t->totalRows; r++) {
		if (!t->cells[r][col]) {
			guint len;

			cell = column
				? HTML_TABLE_CELL (html_object_op_copy (HTML_OBJECT (column[r]), HTML_OBJECT (t),
									e, NULL, NULL, &len))
				: html_engine_new_cell (e, t);
			html_table_set_cell (t, r, col, cell);
			html_table_cell_set_position (t->cells[r][col], r, col);
		}
	}

	html_cursor_jump_to (e->cursor, e, pos.object, pos.offset);
	insert_column_setup_undo (e, col, position_before, dir);
	html_object_change_set (HTML_OBJECT (t), HTML_CHANGE_ALL_CALC);
	html_engine_queue_draw (e, HTML_OBJECT (t));
	html_engine_thaw (e);
}
Esempio n. 3
0
void
html_table_delete_column (HTMLTable *t,
                          HTMLEngine *e,
                          gint col,
                          HTMLUndoDirection dir)
{
	HTMLTableCell **column;
	HTMLTableCell *cell;
	HTMLPoint pos;
	gint r, c;
	guint position_after;

	/* this command is valid only in table and when this table has > 1 column */
	if (!t || t->totalCols < 2)
		return;

	html_engine_freeze (e);

	column = g_new0 (HTMLTableCell *, t->totalRows);

	backward_before_col (e, t, col);
	pos.object = e->cursor->object;
	pos.offset = e->cursor->offset;

	html_engine_goto_table_0 (e, t);
	for (r = 0; r < t->totalRows; r++) {
		cell = t->cells[r][col];

		/* remove & keep old one */
		if (cell && cell->col == col) {
			HTML_OBJECT (cell)->parent = NULL;
			column[r] = cell;
			t->cells[r][col] = NULL;
		}

		for (c = col + 1; c < t->totalCols; c++) {
			cell = t->cells[r][c];
			if (cell && cell->col != col) {
				if (cell->row == r && cell->col == c)
					html_table_cell_set_position (cell, r, c - 1);
				t->cells[r][c - 1] = cell;
				t->cells[r][c]     = NULL;
			}
		}
	}

	html_cursor_jump_to (e->cursor, e, pos.object, pos.offset);
	position_after = e->cursor->position;
	delete_column_setup_undo (e, column, t->totalRows, position_after, col, dir);
	t->totalCols--;

	html_object_change_set (HTML_OBJECT (t), HTML_CHANGE_ALL_CALC);
	html_engine_queue_draw (e, HTML_OBJECT (t));
	html_engine_thaw (e);
}
Esempio n. 4
0
void
html_table_insert_row (HTMLTable *t,
                       HTMLEngine *e,
                       gint row,
                       HTMLTableCell **row_cells,
                       HTMLUndoDirection dir)
{
	HTMLTableCell *cell;
	HTMLPoint pos;
	gint r, c;
	guint position_before;

	html_engine_freeze (e);
	position_before = e->cursor->position;
	pos.object = e->cursor->object;
	pos.offset = e->cursor->offset;
	html_engine_goto_table_0 (e, t);

	html_table_alloc_cell (t, t->totalRows, 0);
	for (r = t->totalRows; r > row; r--) {
		for (c = 0; c < t->totalCols; c++) {
			HTMLTableCell *cell = t->cells[r - 1][c];

			if (cell) {
				if (cell->row == r - 1) {
					html_table_cell_set_position (cell, r, cell->col);
					t->cells[r - 1][c] = NULL;
				} else if (r == row + 1 && cell->col == c)
					cell->rspan++;
				if (cell->row > r - 1)
					t->cells[r - 1][c] = NULL;
				t->cells[r][c] = cell;
			}
		}
	}
	for (c = 0; c < t->totalCols; c++) {
		if (!t->cells[row][c]) {
			guint len;

			cell = row_cells
				? HTML_TABLE_CELL (html_object_op_copy (HTML_OBJECT (row_cells[c]), HTML_OBJECT (t),
									e, NULL, NULL, &len))
				:  html_engine_new_cell (e, t);
			html_table_set_cell (t, row, c, cell);
			html_table_cell_set_position (t->cells[row][c], row, c);
		}
	}

	html_cursor_jump_to (e->cursor, e, pos.object, pos.offset);
	insert_row_setup_undo (e, row, position_before, dir);
	html_object_change_set (HTML_OBJECT (t), HTML_CHANGE_ALL_CALC);
	html_engine_queue_draw (e, HTML_OBJECT (t));
	html_engine_thaw (e);
}
Esempio n. 5
0
static void
table_set_bg_pixmap (HTMLEngine *e,
                     HTMLTable *t,
                     gchar *url,
                     HTMLUndoDirection dir)
{
	HTMLImagePointer *iptr;
	HTMLTableSetAttrUndo *undo;

	undo = attr_undo_new (HTML_TABLE_BGPIXMAP);
	undo->attr.pixmap = t->bgPixmap ? g_strdup (t->bgPixmap->url) : NULL;
	html_undo_add_action (e->undo, e,
			      html_undo_action_new ("Set table background pixmap", table_set_bg_pixmap_undo_action,
						    HTML_UNDO_DATA (undo),
						    html_cursor_get_position (e->cursor),
						    html_cursor_get_position (e->cursor)), dir);

	iptr = t->bgPixmap;
	t->bgPixmap = url ? html_image_factory_register (e->image_factory, NULL, url, TRUE) : NULL;
	if (iptr)
		html_image_factory_unregister (e->image_factory, iptr, NULL);
	html_engine_queue_draw (e, HTML_OBJECT (t));
}
Esempio n. 6
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;
}