📄 dw_table.c
字号:
col2 < col + table->children[n]->data.cell.colspan; col2++) set_width += table->col_width[col2]; a_Dw_widget_set_width (child, set_width); a_Dw_widget_set_ascent (child, table->avail_ascent); a_Dw_widget_set_descent (child, table->avail_descent); a_Dw_widget_size_request (child, &child_requisition); /* Cells with valign=baseline have a height which may * be greater than the height returned by size_request. */ if (child->style->valign == DW_STYLE_VALIGN_BASELINE) child_height = table->baseline[row] + child_requisition.descent; else child_height = child_requisition.ascent + child_requisition.descent; row2 = row + table->children[n]->data.cell.rowspan; /* row2 is the row directly forced downward by the child */ if (table->cum_height[row2] < table->cum_height[row] + child_height + widget->style->border_spacing ) { table->cum_height[row2] = table->cum_height[row] + child_height + widget->style->border_spacing; DEBUG_MSG (1, "Row %d starts at %d.\n", row2, table->cum_height[row + table->children[n] ->data.cell.rowspan]); /* todo: column widths should be adjusted a bit. */ } } } /* if we've hit a row that contains no defined children, we need to force cumulative heights to trickle down to lower rows */ if (table->cum_height[row + 1] < table->cum_height[row]) table->cum_height[row + 1] = table->cum_height[row]; } requisition->ascent = table->cum_height[table->num_rows] + p_Dw_style_box_diff_height (widget->style); requisition->descent = 0; DEBUG_MSG (2, "Dw_table_size_request: %d x %d x %d\n", requisition->width, requisition->ascent, requisition->descent);}/* * Standard Dw function. */static void Dw_table_get_extremes (DwWidget *widget, DwExtremes *extremes){ DwTable *table = DW_TABLE (widget); gint32 diff; if (table->num_cols > 0) { if (table->sub == NULL) Dw_table_sub_create (table); DEBUG_MSG (DEBUG_EXTR_LEVEL + 3, "--> [%p] Dw_table_get_extremes for (%d x %d) table.\n", table, table->num_cols, table->num_rows); Dw_table_sub_get_extremes (table->sub); diff = 2 * widget->style->border_spacing + p_Dw_style_box_diff_width (widget->style); extremes->min_width = table->sub->total_extremes.min_width + diff; extremes->max_width = table->sub->total_extremes.max_width + diff; DEBUG_MSG (DEBUG_EXTR_LEVEL + 2, "<-- [%p] END\n", table); } else { extremes->min_width = widget->style->border_spacing + p_Dw_style_box_diff_width (widget->style); extremes->max_width = widget->style->border_spacing + p_Dw_style_box_diff_width (widget->style); }}/* * Standard Dw function. */static void Dw_table_size_allocate (DwWidget *widget, DwAllocation *allocation){ DwTable *table = DW_TABLE (widget); gint row, col, col2, n; gint32 col_offset, cell_width, cell_height, height_diff, vdiff; DwWidget *child; DwAllocation child_allocation; DwRequisition child_requisition; /* * todo: This implementation depends on that size_request has been * called before. Can this be assumed? */ DEBUG_MSG (2, "Dw_table_size_allocate: %d x %d x %d\n", allocation->width, allocation->ascent, allocation->descent); vdiff = allocation->y + p_Dw_style_box_offset_y (widget->style); for (row = 0; row < table->num_rows; row++) { col_offset = allocation->x + widget->style->border_spacing + p_Dw_style_box_offset_x (widget->style); for (col = 0; col < table->num_cols; col++) { n = col + row * table->num_cols; if (CHILD_DEFINED (table, n)) { cell_width = (table->children[n]->data.cell.colspan - 1) * widget->style->border_spacing; for (col2 = col; col2 < col + table->children[n]->data.cell.colspan; col2++) cell_width += table->col_width[col2]; child = table->children[n]->data.cell.widget; cell_height = table->cum_height[row + table->children[n]->data.cell.rowspan] - table->cum_height[row] - widget->style->border_spacing; child_allocation.x = col_offset; child_allocation.y = vdiff + table->cum_height[row]; child_allocation.width = cell_width; /* Vertical alignment is done via allocation. */ a_Dw_widget_size_request (child, &child_requisition); switch (child->style->valign) { case DW_STYLE_VALIGN_TOP: child_allocation.ascent = child_requisition.ascent; child_allocation.descent = cell_height - child_requisition.ascent; break; case DW_STYLE_VALIGN_BOTTOM: child_allocation.ascent = cell_height - child_requisition.descent; child_allocation.descent = child_requisition.descent; break; case DW_STYLE_VALIGN_MIDDLE: height_diff = cell_height - (child_requisition.ascent + child_requisition.descent); child_allocation.ascent = child_requisition.ascent + height_diff / 2; child_allocation.descent = child_requisition.descent + (height_diff + 1) / 2; /* The "+ 1" is to avoid rounding errors. */ break; case DW_STYLE_VALIGN_BASELINE: child_allocation.ascent = table->baseline[row]; child_allocation.descent = cell_height - table->baseline[row]; break; default: g_assert_not_reached(); break; } a_Dw_widget_size_allocate (child, &child_allocation); } col_offset += table->col_width[col] + widget->style->border_spacing; } }}/* * Standard Dw function. */static void Dw_table_set_width (DwWidget *widget, gint32 width){ DwTable *table; table = DW_TABLE (widget); /* If limit_text_width is set to YES, a queue_resize may also be necessary. */ if (table->avail_width != width || prefs.limit_text_width) { table->avail_width = width; p_Dw_widget_queue_resize (widget, 0, FALSE); }}/* * Standard Dw function. */static void Dw_table_set_ascent (DwWidget *widget, gint32 ascent){ DwTable *table; table = DW_TABLE (widget); if (table->avail_ascent != ascent) { table->avail_ascent = ascent; p_Dw_widget_queue_resize (widget, 0, FALSE); }}/* * Standard Dw function. */static void Dw_table_set_descent (DwWidget *widget, gint32 descent){ DwTable *table; table = DW_TABLE (widget); if (table->avail_descent != descent) { table->avail_descent = descent; p_Dw_widget_queue_resize (widget, 0, FALSE); }}/* * Standard Dw function. */static void Dw_table_draw (DwWidget *widget, HDC hdc, DwRectangle *area){ /* can be optimized, by iterating on the lines in area */ DwTable *table = DW_TABLE (widget); DwRectangle child_area; DwWidget *child; gint i; gint32 offx, offy, width; p_Dw_widget_draw_widget_box (widget, hdc, area, FALSE); offx = p_Dw_style_box_offset_x (widget->style); offy = p_Dw_style_box_offset_y (widget->style); width = DW_WIDGET_CONTENT_WIDTH(widget); for (i = 0; i < table->num_rows; i++) if (table->row_style[i]) p_Dw_widget_draw_box (widget, hdc, table->row_style[i], area, offx, offy + table->cum_height[i], width, table->cum_height[i + 1] - table->cum_height[i] - widget->style->border_spacing, FALSE); for (i = 0; i < table->num_children; i++) if (CHILD_DEFINED (table, i)) { child = table->children[i]->data.cell.widget; if (p_Dw_widget_intersect (child, area, &child_area)) {#if 0 Rectangle (hdc, p_Dw_widget_x_world_to_viewport (child, child->allocation.x) - 1, p_Dw_widget_y_world_to_viewport (child, child->allocation.y) - 1, p_Dw_widget_x_world_to_viewport (child, child->allocation.x) + child->allocation.width + 1, p_Dw_widget_y_world_to_viewport (child, child->allocation.y) + DW_WIDGET_HEIGHT(child) + 1);#endif a_Dw_widget_draw (child, hdc, &child_area); } }#if 0 Rectangle (hdc, p_Dw_widget_x_world_to_viewport (widget, widget->allocation.x), p_Dw_widget_y_world_to_viewport (widget, widget->allocation.y), p_Dw_widget_x_world_to_viewport (widget, widget->allocation.x) + widget->allocation.width, p_Dw_widget_y_world_to_viewport (widget, widget->allocation.y) + DW_WIDGET_HEIGHT(widget));#endif}/* * Construct an iterator for a cell. */static DwIterator *Dw_table_construct_iterator (DwTable *table, gint cell_index){ DwIterator *it; it = Dw_table_iterator (DW_WIDGET (table), DW_CONTENT_ALL, FALSE); ((DwIteratorInt*)it)->pos = cell_index; it->content.type = DW_CONTENT_WIDGET; it->content.data.widget = table->children[cell_index]->data.cell.widget; return it;}/* * Construct an iterator pointing to the end of the table. */static DwIterator *Dw_table_construct_last_iterator (DwTable *table, int *char_pos){ int n; DwIterator *it = NULL; DwTableChild *child = NULL; *char_pos = 0; n = table->num_children -1; while (n >= 0 && ((child = table->children[n]) == NULL || child->type != DW_TABLE_CELL)) n--; if (n >= 0) { /* Try to construct an iterator for the last child of the table. */ it = a_Dw_widget_iterator (child->data.cell.widget, DW_CONTENT_ALL, TRUE); if (it != NULL && a_Dw_iterator_prev (it)) { if (it->content.type == DW_CONTENT_TEXT) *char_pos = strlen (it->content.data.text); } else { a_Dw_iterator_free (it); it = NULL; } if (it == NULL) /* This widget has no content, construct an iterator for the table. */ it = Dw_table_construct_iterator (table, n); } return it;}#if 0/* * Send event to selection. */static gboolean Dw_table_send_selection_event (DwTable *table, gint (*fn) (Selection*, DwIterator *, gint, gint, GdkEventButton*, gboolean within_content), gint32 x, gint32 y, GdkEventButton *event){ int row, col, n, char_pos; DwIterator *it; DwTableChild *child; gint32 offy, cellspacing, cum_width; it = NULL; char_pos = 0; cellspacing = DW_WIDGET(table)->style->border_spacing; /* Search row. * Just a note: Improving the speed of this does not give very much, * since events (in dw_widget.c) are always much slower. */ offy = p_Dw_style_box_offset_y (DW_WIDGET(table)->style); row = 0; while (row < table->num_rows && y > table->cum_height[row + 1] + offy - cellspacing) row++; if (row == table->num_rows)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -