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

📄 gtktable.c

📁 gtk是linux一款强大的夸平台的图形化开发工具
💻 C
📖 第 1 页 / 共 3 页
字号:
		{		  width += table->cols[col].requisition;		  if ((col + 1) < child->right_attach)		    width += table->cols[col].spacing;		}	      	      /* If we need to request more space for this child to fill	       *  its requisition, then divide up the needed space evenly	       *  amongst the columns it spans.	       */	      if (width < child_requisition.width + child->xpadding * 2)		{		  width = child_requisition.width + child->xpadding * 2 - width;		  		  for (col = child->left_attach; col < child->right_attach; col++)		    {		      extra = width / (child->right_attach - col);		      table->cols[col].requisition += extra;		      width -= extra;		    }		}	    }	  	  /* Child spans multiple rows.	   */	  if (child->top_attach != (child->bottom_attach - 1))	    {	      GtkRequisition child_requisition;	      gtk_widget_get_child_requisition (child->widget, &child_requisition);	      /* Check and see if there is already enough space	       *  for the child.	       */	      height = 0;	      for (row = child->top_attach; row < child->bottom_attach; row++)		{		  height += table->rows[row].requisition;		  if ((row + 1) < child->bottom_attach)		    height += table->rows[row].spacing;		}	      	      /* If we need to request more space for this child to fill	       *  its requisition, then divide up the needed space evenly	       *  amongst the columns it spans.	       */	      if (height < child_requisition.height + child->ypadding * 2)		{		  height = child_requisition.height + child->ypadding * 2 - height;		  		  for (row = child->top_attach; row < child->bottom_attach; row++)		    {		      extra = height / (child->bottom_attach - row);		      table->rows[row].requisition += extra;		      height -= extra;		    }		}	    }	}    }}static voidgtk_table_size_allocate_init (GtkTable *table){  GtkTableChild *child;  GList *children;  gint row, col;  gint has_expand;  gint has_shrink;    /* Initialize the rows and cols.   *  By default, rows and cols do not expand and do shrink.   *  Those values are modified by the children that occupy   *  the rows and cols.   */  for (col = 0; col < table->ncols; col++)    {      table->cols[col].allocation = table->cols[col].requisition;      table->cols[col].need_expand = FALSE;      table->cols[col].need_shrink = TRUE;      table->cols[col].expand = FALSE;      table->cols[col].shrink = TRUE;      table->cols[col].empty = TRUE;    }  for (row = 0; row < table->nrows; row++)    {      table->rows[row].allocation = table->rows[row].requisition;      table->rows[row].need_expand = FALSE;      table->rows[row].need_shrink = TRUE;      table->rows[row].expand = FALSE;      table->rows[row].shrink = TRUE;      table->rows[row].empty = TRUE;    }    /* Loop over all the children and adjust the row and col values   *  based on whether the children want to be allowed to expand   *  or shrink. This loop handles children that occupy a single   *  row or column.   */  children = table->children;  while (children)    {      child = children->data;      children = children->next;            if (GTK_WIDGET_VISIBLE (child->widget))	{	  if (child->left_attach == (child->right_attach - 1))	    {	      if (child->xexpand)		table->cols[child->left_attach].expand = TRUE;	      	      if (!child->xshrink)		table->cols[child->left_attach].shrink = FALSE;	      	      table->cols[child->left_attach].empty = FALSE;	    }	  	  if (child->top_attach == (child->bottom_attach - 1))	    {	      if (child->yexpand)		table->rows[child->top_attach].expand = TRUE;	      	      if (!child->yshrink)		table->rows[child->top_attach].shrink = FALSE;	      table->rows[child->top_attach].empty = FALSE;	    }	}    }    /* Loop over all the children again and this time handle children   *  which span multiple rows or columns.   */  children = table->children;  while (children)    {      child = children->data;      children = children->next;            if (GTK_WIDGET_VISIBLE (child->widget))	{	  if (child->left_attach != (child->right_attach - 1))	    {	      for (col = child->left_attach; col < child->right_attach; col++)		table->cols[col].empty = FALSE;	      if (child->xexpand)		{		  has_expand = FALSE;		  for (col = child->left_attach; col < child->right_attach; col++)		    if (table->cols[col].expand)		      {			has_expand = TRUE;			break;		      }		  		  if (!has_expand)		    for (col = child->left_attach; col < child->right_attach; col++)		      table->cols[col].need_expand = TRUE;		}	      	      if (!child->xshrink)		{		  has_shrink = TRUE;		  for (col = child->left_attach; col < child->right_attach; col++)		    if (!table->cols[col].shrink)		      {			has_shrink = FALSE;			break;		      }		  		  if (has_shrink)		    for (col = child->left_attach; col < child->right_attach; col++)		      table->cols[col].need_shrink = FALSE;		}	    }	  	  if (child->top_attach != (child->bottom_attach - 1))	    {	      for (row = child->top_attach; row < child->bottom_attach; row++)		table->rows[row].empty = FALSE;	      if (child->yexpand)		{		  has_expand = FALSE;		  for (row = child->top_attach; row < child->bottom_attach; row++)		    if (table->rows[row].expand)		      {			has_expand = TRUE;			break;		      }		  		  if (!has_expand)		    for (row = child->top_attach; row < child->bottom_attach; row++)		      table->rows[row].need_expand = TRUE;		}	      	      if (!child->yshrink)		{		  has_shrink = TRUE;		  for (row = child->top_attach; row < child->bottom_attach; row++)		    if (!table->rows[row].shrink)		      {			has_shrink = FALSE;			break;		      }		  		  if (has_shrink)		    for (row = child->top_attach; row < child->bottom_attach; row++)		      table->rows[row].need_shrink = FALSE;		}	    }	}    }    /* Loop over the columns and set the expand and shrink values   *  if the column can be expanded or shrunk.   */  for (col = 0; col < table->ncols; col++)    {      if (table->cols[col].empty)	{	  table->cols[col].expand = FALSE;	  table->cols[col].shrink = FALSE;	}      else	{	  if (table->cols[col].need_expand)	    table->cols[col].expand = TRUE;	  if (!table->cols[col].need_shrink)	    table->cols[col].shrink = FALSE;	}    }    /* Loop over the rows and set the expand and shrink values   *  if the row can be expanded or shrunk.   */  for (row = 0; row < table->nrows; row++)    {      if (table->rows[row].empty)	{	  table->rows[row].expand = FALSE;	  table->rows[row].shrink = FALSE;	}      else	{	  if (table->rows[row].need_expand)	    table->rows[row].expand = TRUE;	  if (!table->rows[row].need_shrink)	    table->rows[row].shrink = FALSE;	}    }}static voidgtk_table_size_allocate_pass1 (GtkTable *table){  gint real_width;  gint real_height;  gint width, height;  gint row, col;  gint nexpand;  gint nshrink;  gint extra;    /* If we were allocated more space than we requested   *  then we have to expand any expandable rows and columns   *  to fill in the extra space.   */    real_width = GTK_WIDGET (table)->allocation.width - GTK_CONTAINER (table)->border_width * 2;  real_height = GTK_WIDGET (table)->allocation.height - GTK_CONTAINER (table)->border_width * 2;    if (table->homogeneous)    {      nexpand = 0;      for (col = 0; col < table->ncols; col++)	if (table->cols[col].expand)	  {	    nexpand += 1;	    break;	  }            if (nexpand > 0)	{	  width = real_width;	  	  for (col = 0; col + 1 < table->ncols; col++)	    width -= table->cols[col].spacing;	  	  for (col = 0; col < table->ncols; col++)	    {	      extra = width / (table->ncols - col);	      table->cols[col].allocation = MAX (1, extra);	      width -= extra;	    }	}    }  else    {      width = 0;      nexpand = 0;      nshrink = 0;            for (col = 0; col < table->ncols; col++)	{	  width += table->cols[col].requisition;	  if (table->cols[col].expand)	    nexpand += 1;	  if (table->cols[col].shrink)	    nshrink += 1;	}      for (col = 0; col + 1 < table->ncols; col++)	width += table->cols[col].spacing;            /* Check to see if we were allocated more width than we requested.       */      if ((width < real_width) && (nexpand >= 1))	{	  width = real_width - width;	  	  for (col = 0; col < table->ncols; col++)	    if (table->cols[col].expand)	      {		extra = width / nexpand;		table->cols[col].allocation += extra;				width -= extra;		nexpand -= 1;	      }	}            /* Check to see if we were allocated less width than we requested.       */      if ((width > real_width) && (nshrink >= 1))	{	  width = width - real_width;	  	  for (col = 0; col < table->ncols; col++)	    if (table->cols[col].shrink)	      {		extra = width / nshrink;		table->cols[col].allocation = MAX (1, (gint)table->cols[col].allocation - extra);				width -= extra;		nshrink -= 1;	      }	}    }    if (table->homogeneous)    {      nexpand = 0;      for (row = 0; row < table->nrows; row++)	if (table->rows[row].expand)	  {	    nexpand += 1;	    break;	  }            if (nexpand > 0)	{	  height = real_height;	  	  for (row = 0; row + 1 < table->nrows; row++)	    height -= table->rows[row].spacing;	  	  	  for (row = 0; row < table->nrows; row++)	    {	      extra = height / (table->nrows - row);	      table->rows[row].allocation = MAX (1, extra);	      height -= extra;	    }	}    }  else    {      height = 0;      nexpand = 0;      nshrink = 0;            for (row = 0; row < table->nrows; row++)	{	  height += table->rows[row].requisition;	  if (table->rows[row].expand)	    nexpand += 1;	  if (table->rows[row].shrink)	    nshrink += 1;	}      for (row = 0; row + 1 < table->nrows; row++)	height += table->rows[row].spacing;            /* Check to see if we were allocated more height than we requested.       */      if ((height < real_height) && (nexpand >= 1))	{	  height = real_height - height;	  	  for (row = 0; row < table->nrows; row++)	    if (table->rows[row].expand)	      {		extra = height / nexpand;		table->rows[row].allocation += extra;				height -= extra;		nexpand -= 1;	      }	}            /* Check to see if we were allocated less height than we requested.       */      if ((height > real_height) && (nshrink >= 1))	{	  height = height - real_height;	  	  for (row = 0; row < table->nrows; row++)	    if (table->rows[row].shrink)	      {		extra = height / nshrink;		table->rows[row].allocation = MAX (1, (gint)table->rows[row].allocation - extra);				height -= extra;		nshrink -= 1;	      }	}    }}static voidgtk_table_size_allocate_pass2 (GtkTable *table){  GtkTableChild *child;  GList *children;  gint max_width;  gint max_height;  gint x, y;  gint row, col;  GtkAllocation allocation;    children = table->children;  while (children)    {      child = children->data;      children = children->next;            if (GTK_WIDGET_VISIBLE (child->widget))	{	  GtkRequisition child_requisition;	  gtk_widget_get_child_requisition (child->widget, &child_requisition);	  x = GTK_WIDGET (table)->allocation.x + GTK_CONTAINER (table)->border_width;	  y = GTK_WIDGET (table)->allocation.y + GTK_CONTAINER (table)->border_width;	  max_width = 0;	  max_height = 0;	  	  for (col = 0; col < child->left_attach; col++)	    {	      x += table->cols[col].allocation;	      x += table->cols[col].spacing;	    }	  	  for (col = child->left_attach; col < child->right_attach; col++)	    {	      max_width += table->cols[col].allocation;	      if ((col + 1) < child->right_attach)		max_width += table->cols[col].spacing;	    }	  	  for (row = 0; row < child->top_attach; row++)	    {	      y += table->rows[row].allocation;	      y += table->rows[row].spacing;	    }	  	  for (row = child->top_attach; row < child->bottom_attach; row++)	    {	      max_height += table->rows[row].allocation;	      if ((row + 1) < child->bottom_attach)		max_height += table->rows[row].spacing;	    }	  	  if (child->xfill)	    {	      allocation.width = MAX (1, max_width - (gint)child->xpadding * 2);	      allocation.x = x + (max_width - allocation.width) / 2;	    }	  else	    {	      allocation.width = child_requisition.width;	      allocation.x = x + (max_width - allocation.width) / 2;	    }	  	  if (child->yfill)	    {	      allocation.height = MAX (1, max_height - (gint)child->ypadding * 2);	      allocation.y = y + (max_height - allocation.height) / 2;	    }	  else	    {	      allocation.height = child_requisition.height;	      allocation.y = y + (max_height - allocation.height) / 2;	    }	  	  gtk_widget_size_allocate (child->widget, &allocation);	}    }}

⌨️ 快捷键说明

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