⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dw_table.c

📁 嵌入式浏览器Dillo源码
💻 C
📖 第 1 页 / 共 4 页
字号:
         for (col = old_num_cols; col < table->num_cols; col++)            table->children[row * table->num_cols + col] = NULL;      }   }   for (col = 0; col < colspan; col++)      for (row = 0; row < rowspan; row++)         if (!(col == 0 && row == 0)) {            child = g_new (DwTableChild, 1);            child->type = DW_TABLE_SPAN_SPACE;            child->data.span_space.start_col = table->cur_col;            child->data.span_space.start_row = table->cur_row;            table->children[(table->cur_row + row) * table->num_cols                           + (table->cur_col + col)] = child;         }   child = g_new (DwTableChild, 1);   child->type = DW_TABLE_CELL;   child->data.cell.widget = widget;   child->data.cell.colspan = colspan;   child->data.cell.rowspan = rowspan;   table->children[table->cur_row * table->num_cols + table->cur_col] = child;   table->cur_col += colspan;   p_Dw_widget_set_parent (widget, DW_WIDGET (table));   p_Dw_widget_queue_resize (widget, 0, TRUE);   /* The cell structure has changed, so the subtables have to be rebuilt. */   if (table->sub) {      Dw_table_sub_free (table->sub);      table->sub = NULL;   }}/* * Add a new row to the table, and start adding cells from the * left-most column. */void a_Dw_table_add_row (DwTable *table,                         DwStyle *style){   gint row, old_num_rows;   table->cur_row++;   if (table->cur_row >= table->num_rows) {      old_num_rows = table->num_rows;      table->num_rows = table->cur_row + 1;      Dw_table_realloc_children (table);      for (row = old_num_rows; row < table->num_rows; row++)         table->row_style[row] = NULL;   }   if (table->row_style[table->cur_row])      a_Dw_style_unref (table->row_style[table->cur_row]);   table->row_style[table->cur_row] = style;   if (style)      a_Dw_style_ref (style);   table->cur_col = 0;}/* ---------------------------------------------------------------------- * *    General Functions for Subtables * * ---------------------------------------------------------------------- */static gboolean Dw_table_sub_spans_width (DwTableSub *sub,                                         gint row){   gint n, start_col, start_row, start_n, colspan;   n = sub->start_col + sub->table->num_cols * row;   if (sub->table->children[n]) {      if (sub->table->children[n]->type == DW_TABLE_CELL) {         start_col = sub->start_col;         start_row = row;      } else {         start_col = sub->table->children[n]->data.span_space.start_col;         start_row = sub->table->children[n]->data.span_space.start_row;      }      start_n = start_col + sub->table->num_cols * start_row;      colspan = sub->table->children[start_n]->data.cell.colspan;      return (start_col <= sub->start_col &&              start_col + colspan >= sub->end_col);   } else      return FALSE;}/* * Fill the DwTableSub and create the sub DwTableSub's. Only for use * by Dw_table_get_sub. */static void Dw_table_sub_calc_subs (DwTableSub *sub){   gint col, row, n, start_n, colspan, most_right, start_col, start_row;   if (sub->start_col + 1 == sub->end_col) {      DEBUG_MSG (DEBUG_CALC_LEVEL + 2, "   single column at %d\n",                 sub->start_col);      sub->num_subs = 0;      sub->subs = NULL;      for (row = 0; row < sub->table->num_rows; row++)         if (!a_Bitvec_get_bit (sub->removed_rows, row)) {            a_Bitvec_set_bit (sub->spanning_rows, row);            DEBUG_MSG (DEBUG_CALC_LEVEL + 1,                       "      row %d spans width\n", row);         }   } else {      DEBUG_MSG (DEBUG_CALC_LEVEL + 2,                 "   --> complex subtable from %d to %d\n",                 sub->start_col, sub->end_col);      for (row = 0; row < sub->table->num_rows; row++)         if (!a_Bitvec_get_bit (sub->removed_rows, row) &&             Dw_table_sub_spans_width (sub, row)) {            a_Bitvec_set_bit (sub->spanning_rows, row);            DEBUG_MSG (DEBUG_CALC_LEVEL + 1,                       "      row %d spans width\n", row);         }      sub->num_subs = 0;      sub->subs = g_new (DwTableSub, sub->end_col - sub->start_col);      col = sub->start_col;      while (col < sub->end_col) {         DEBUG_MSG (DEBUG_CALC_LEVEL + 1, "      column %d\n", col);         sub->subs[sub->num_subs].table = sub->table;         sub->subs[sub->num_subs].start_col = col;         sub->subs[sub->num_subs].removed_rows =            a_Bitvec_new (sub->table->num_rows);         sub->subs[sub->num_subs].spanning_rows =            a_Bitvec_new (sub->table->num_rows);         /* Search for the greatest colspan value. */         most_right = col + 1;         for (row = 0; row < sub->table->num_rows; row++)            if (a_Bitvec_get_bit (sub->removed_rows, row) ||                a_Bitvec_get_bit (sub->spanning_rows, row))               a_Bitvec_set_bit (sub->subs[sub->num_subs].removed_rows, row);            else {               n = col + sub->table->num_cols * row;               if (sub->table->children[n]) {                  if (sub->table->children[n]->type == DW_TABLE_CELL) {                     start_col = col;                     start_row = row;                     start_n = n;                  } else {                     start_col =                        sub->table->children[n]->data.span_space.start_col;                     start_row =                        sub->table->children[n]->data.span_space.start_row;                     start_n = start_col + sub->table->num_cols * start_row;                  }                  if (row == start_row) {                     colspan =                        sub->table->children[start_n]->data.cell.colspan -                        (col - start_col);                     if (start_col + colspan > most_right &&                         start_col + colspan <= sub->end_col)                        most_right = start_col + colspan;                  }               }            }         sub->subs[sub->num_subs].end_col = most_right;         Dw_table_sub_calc_subs (&sub->subs[sub->num_subs]);         sub->num_subs++;         col = most_right;      }      DEBUG_MSG (DEBUG_CALC_LEVEL + 1, "   <-- END\n");   }}/* * Create a DwTableSub for a table. */static void Dw_table_sub_create (DwTable *table){   if (table->sub)      Dw_table_sub_free (table->sub);   DEBUG_MSG (DEBUG_CALC_LEVEL + 3,              "--> Dw_table_sub_create widths for (%d x %d) table.\n",              table->num_cols, table->num_rows);   table->sub = g_new (DwTableSub, 1);   table->sub->table = table;   table->sub->start_col = 0;   table->sub->end_col = table->num_cols;   table->sub->removed_rows = a_Bitvec_new (table->num_rows);   table->sub->spanning_rows = a_Bitvec_new (table->num_rows);   Dw_table_sub_calc_subs (table->sub);   DEBUG_MSG (DEBUG_CALC_LEVEL + 2, "<-- END\n");}/* * Clean up a DwTableSub. Only for use by Dw_table_free_sub. */static void Dw_table_sub_clean_up (DwTableSub *sub){   gint i;   a_Bitvec_free (sub->removed_rows);   a_Bitvec_free (sub->spanning_rows);   if (sub->subs) {      for (i = 0; i < sub->num_subs; i++)         Dw_table_sub_clean_up (&sub->subs[i]);      g_free (sub->subs);   }}/* * Free a DwTableSub. */static void Dw_table_sub_free (DwTableSub *sub){   Dw_table_sub_clean_up (sub);   g_free (sub);}/* ---------------------------------------------------------------------- * *    Specific Functions for Subtables * *    NOTE: The spaces left of the left most column and right of the *    right most column do not belong to a subtable. * * ---------------------------------------------------------------------- *//* * Calculate the extremes of a subtable. */static void Dw_table_sub_get_extremes (DwTableSub *sub){   gint i, row, n, start_col, start_row, start_n, num_cols, colspan;   DwWidget *child, *widget;   DwExtremes child_extremes, sum_extremes;   gint32 col_width;   gint32 border_spacing = DW_WIDGET(sub->table)->style->border_spacing;   gfloat percentage;   gfloat sum_percentage;   gint use_percentage_map[3][3] = {      { USE_PERCENTAGE_NO, USE_PERCENTAGE_SOME, -1 },      { USE_PERCENTAGE_SOME, USE_PERCENTAGE_SOME, USE_PERCENTAGE_SOME },      { USE_PERCENTAGE_SOME, USE_PERCENTAGE_SOME, USE_PERCENTAGE_ALL } };   num_cols = sub->end_col - sub->start_col;   sub->use_percentage = USE_PERCENTAGE_NO;   sub->fixed_width = FALSE;   sub->percentage = 0;   DEBUG_MSG (DEBUG_EXTR_LEVEL + 2, "   subtable from %d to %d\n",              sub->start_col, sub->end_col);   /* 1. cells spanning the whole width */   sub->span_extremes.min_width = 0;   sub->span_extremes.max_width = 0;   for (row = 0; row < sub->table->num_rows; row++) {      if (!a_Bitvec_get_bit (sub->removed_rows, row) &&          a_Bitvec_get_bit (sub->spanning_rows, row)) {         n = sub->start_col + row * sub->table->num_cols;         if (sub->table->children[n]) {            if (sub->table->children[n]->type == DW_TABLE_CELL) {               start_row = row;               start_n = n;            } else {               start_col = sub->table->children[n]->data.span_space.start_col;               start_row = sub->table->children[n]->data.span_space.start_row;               start_n = start_col + sub->table->num_cols * start_row;            }            if (row == start_row) {               child = sub->table->children[start_n]->data.cell.widget;               a_Dw_widget_get_extremes (child, &child_extremes);               colspan = sub->table->children[start_n]->data.cell.colspan;               /* Adjust width argument of the cell */               if (DW_STYLE_IS_LENGTH (child->style->width)) {                  col_width = DW_STYLE_GET_LENGTH (child->style->width,                                                   child->style->font);                  if (col_width < child_extremes.min_width)                     col_width = child_extremes.min_width;                  child_extremes.min_width = col_width;                  child_extremes.max_width = col_width;                  sub->fixed_width = TRUE;                  DEBUG_MSG (DEBUG_EXTR_LEVEL,                             "         following adjusted by %d pixels:\n",                             col_width);               } else if (DW_STYLE_IS_PERCENTAGE (child->style->width)) {                  percentage = DW_STYLE_GET_PERCENTAGE (child->style->width);                  sub->percentage = MAX (sub->percentage, percentage);                  sub->use_percentage = USE_PERCENTAGE_ALL;                  DEBUG_MSG (DEBUG_EXTR_LEVEL,                             "         following adjusted by %g %%\n",                             100 * sub->percentage);               }               if (num_cols != colspan) {                  child_extremes.min_width =                     child_extremes.min_width * num_cols / colspan;                  child_extremes.max_width =                     child_extremes.max_width * num_cols / colspan;               }               DEBUG_MSG (DEBUG_EXTR_LEVEL,                          "         row %d: cell extremes: %d / %d "                          "[was multiplied by %d / %d]\n",                          row, child_extremes.min_width,                          child_extremes.max_width,                          num_cols, colspan);               if (child_extremes.min_width > sub->span_extremes.min_width)                  sub->span_extremes.min_width = child_extremes.min_width;               if (child_extremes.max_width > sub->span_extremes.max_width)                  sub->span_extremes.max_width = child_extremes.max_width;            } else {               DEBUG_MSG (DEBUG_EXTR_LEVEL,                          "         row %d: omitted\n", row);            }         }      }   }   DEBUG_MSG (DEBUG_EXTR_LEVEL + 1, "      spanning subs: %d / %d\n",              sub->span_extremes.min_width, sub->span_extremes.max_width);   if (sub->table->sub == sub) {      /* Adjust width argument of the table (fixed, percentages         later in the code). */      widget = DW_WIDGET(sub->table);      if (DW_STYLE_IS_LENGTH (widget->style->width)) {         col_width = DW_STYLE_GET_LENGTH (widget->style->width,                                          widget->style->font);         if (col_width < sub->span_extremes.min_width)            col_width = sub->span_extremes.min_width;         sub->span_extremes.min_width = col_width;         sub->span_extremes.max_width = col_width;      }   }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -