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

📄 gtktable.c

📁 gtk是linux一款强大的夸平台的图形化开发工具
💻 C
📖 第 1 页 / 共 3 页
字号:
/* GTK - The GIMP Toolkit * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. *//* * Modified by the GTK+ Team and others 1997-1999.  See the AUTHORS * file for a list of people on the GTK+ Team.  See the ChangeLog * files for a list of changes.  These files are distributed with * GTK+ at ftp://ftp.gtk.org/pub/gtk/.  */#include "gtktable.h"enum{  ARG_0,  ARG_N_ROWS,  ARG_N_COLUMNS,  ARG_COLUMN_SPACING,  ARG_ROW_SPACING,  ARG_HOMOGENEOUS};enum{  CHILD_ARG_0,  CHILD_ARG_LEFT_ATTACH,  CHILD_ARG_RIGHT_ATTACH,  CHILD_ARG_TOP_ATTACH,  CHILD_ARG_BOTTOM_ATTACH,  CHILD_ARG_X_OPTIONS,  CHILD_ARG_Y_OPTIONS,  CHILD_ARG_X_PADDING,  CHILD_ARG_Y_PADDING};  static void gtk_table_class_init    (GtkTableClass  *klass);static void gtk_table_init	    (GtkTable	    *table);static void gtk_table_finalize	    (GtkObject	    *object);static void gtk_table_map	    (GtkWidget	    *widget);static void gtk_table_unmap	    (GtkWidget	    *widget);static void gtk_table_draw	    (GtkWidget	    *widget,				     GdkRectangle   *area);static gint gtk_table_expose	    (GtkWidget	    *widget,				     GdkEventExpose *event);static void gtk_table_size_request  (GtkWidget	    *widget,				     GtkRequisition *requisition);static void gtk_table_size_allocate (GtkWidget	    *widget,				     GtkAllocation  *allocation);static void gtk_table_add	    (GtkContainer   *container,				     GtkWidget	    *widget);static void gtk_table_remove	    (GtkContainer   *container,				     GtkWidget	    *widget);static void gtk_table_forall	    (GtkContainer   *container,				     gboolean	     include_internals,				     GtkCallback     callback,				     gpointer	     callback_data);static void gtk_table_get_arg       (GtkObject      *object,				     GtkArg         *arg,				     guint           arg_id);static void gtk_table_set_arg       (GtkObject      *object,				     GtkArg         *arg,				     guint           arg_id);static void gtk_table_set_child_arg (GtkContainer   *container,				     GtkWidget      *child,				     GtkArg         *arg,				     guint           arg_id);static void gtk_table_get_child_arg (GtkContainer   *container,				     GtkWidget      *child,				     GtkArg         *arg,				     guint           arg_id);static GtkType gtk_table_child_type (GtkContainer   *container);static void gtk_table_size_request_init	 (GtkTable *table);static void gtk_table_size_request_pass1 (GtkTable *table);static void gtk_table_size_request_pass2 (GtkTable *table);static void gtk_table_size_request_pass3 (GtkTable *table);static void gtk_table_size_allocate_init  (GtkTable *table);static void gtk_table_size_allocate_pass1 (GtkTable *table);static void gtk_table_size_allocate_pass2 (GtkTable *table);static GtkContainerClass *parent_class = NULL;GtkTypegtk_table_get_type (void){  static GtkType table_type = 0;    if (!table_type)    {      static const GtkTypeInfo table_info =      {	"GtkTable",	sizeof (GtkTable),	sizeof (GtkTableClass),	(GtkClassInitFunc) gtk_table_class_init,	(GtkObjectInitFunc) gtk_table_init,        /* reserved_1 */ NULL,	/* reserved_2 */ NULL,	(GtkClassInitFunc) NULL,      };            table_type = gtk_type_unique (gtk_container_get_type (), &table_info);    }    return table_type;}static voidgtk_table_class_init (GtkTableClass *class){  GtkObjectClass *object_class;  GtkWidgetClass *widget_class;  GtkContainerClass *container_class;    object_class = (GtkObjectClass*) class;  widget_class = (GtkWidgetClass*) class;  container_class = (GtkContainerClass*) class;    parent_class = gtk_type_class (gtk_container_get_type ());    gtk_object_add_arg_type ("GtkTable::n_rows", GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_N_ROWS);  gtk_object_add_arg_type ("GtkTable::n_columns", GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_N_COLUMNS);  gtk_object_add_arg_type ("GtkTable::row_spacing", GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_ROW_SPACING);  gtk_object_add_arg_type ("GtkTable::column_spacing", GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_COLUMN_SPACING);  gtk_object_add_arg_type ("GtkTable::homogeneous", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_HOMOGENEOUS);  gtk_container_add_child_arg_type ("GtkTable::left_attach", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_LEFT_ATTACH);  gtk_container_add_child_arg_type ("GtkTable::right_attach", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_RIGHT_ATTACH);  gtk_container_add_child_arg_type ("GtkTable::top_attach", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_TOP_ATTACH);  gtk_container_add_child_arg_type ("GtkTable::bottom_attach", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_BOTTOM_ATTACH);  gtk_container_add_child_arg_type ("GtkTable::x_options", GTK_TYPE_ATTACH_OPTIONS, GTK_ARG_READWRITE, CHILD_ARG_X_OPTIONS);  gtk_container_add_child_arg_type ("GtkTable::y_options", GTK_TYPE_ATTACH_OPTIONS, GTK_ARG_READWRITE, CHILD_ARG_Y_OPTIONS);  gtk_container_add_child_arg_type ("GtkTable::x_padding", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_X_PADDING);  gtk_container_add_child_arg_type ("GtkTable::y_padding", GTK_TYPE_UINT, GTK_ARG_READWRITE, CHILD_ARG_Y_PADDING);  object_class->get_arg = gtk_table_get_arg;  object_class->set_arg = gtk_table_set_arg;  object_class->finalize = gtk_table_finalize;    widget_class->map = gtk_table_map;  widget_class->unmap = gtk_table_unmap;  widget_class->draw = gtk_table_draw;  widget_class->expose_event = gtk_table_expose;  widget_class->size_request = gtk_table_size_request;  widget_class->size_allocate = gtk_table_size_allocate;    container_class->add = gtk_table_add;  container_class->remove = gtk_table_remove;  container_class->forall = gtk_table_forall;  container_class->child_type = gtk_table_child_type;  container_class->set_child_arg = gtk_table_set_child_arg;  container_class->get_child_arg = gtk_table_get_child_arg;}static GtkTypegtk_table_child_type (GtkContainer   *container){  return GTK_TYPE_WIDGET;}static voidgtk_table_get_arg (GtkObject      *object,		   GtkArg         *arg,		   guint           arg_id){  GtkTable *table;  table = GTK_TABLE (object);  switch (arg_id)    {    case ARG_N_ROWS:      GTK_VALUE_UINT (*arg) = table->nrows;      break;    case ARG_N_COLUMNS:      GTK_VALUE_UINT (*arg) = table->ncols;      break;    case ARG_ROW_SPACING:      GTK_VALUE_UINT (*arg) = table->row_spacing;      break;    case ARG_COLUMN_SPACING:      GTK_VALUE_UINT (*arg) = table->column_spacing;      break;    case ARG_HOMOGENEOUS:      GTK_VALUE_BOOL (*arg) = table->homogeneous;      break;    default:      arg->type = GTK_TYPE_INVALID;      break;    }}static voidgtk_table_set_arg (GtkObject      *object,		   GtkArg         *arg,		   guint           arg_id){  GtkTable *table;  table = GTK_TABLE (object);  switch (arg_id)    {    case ARG_N_ROWS:      gtk_table_resize (table, GTK_VALUE_UINT (*arg), table->ncols);      break;    case ARG_N_COLUMNS:      gtk_table_resize (table, table->nrows, GTK_VALUE_UINT (*arg));      break;    case ARG_ROW_SPACING:      gtk_table_set_row_spacings (table, GTK_VALUE_UINT (*arg));      break;    case ARG_COLUMN_SPACING:      gtk_table_set_col_spacings (table, GTK_VALUE_UINT (*arg));      break;    case ARG_HOMOGENEOUS:      gtk_table_set_homogeneous (table, GTK_VALUE_BOOL (*arg));      break;    default:      break;    }}static voidgtk_table_set_child_arg (GtkContainer   *container,			 GtkWidget      *child,			 GtkArg         *arg,			 guint           arg_id){  GtkTable *table;  GtkTableChild *table_child;  GList *list;  table = GTK_TABLE (container);  table_child = NULL;  for (list = table->children; list; list = list->next)    {      table_child = list->data;      if (table_child->widget == child)	break;    }  if (!list)    return;  switch (arg_id)    {    case CHILD_ARG_LEFT_ATTACH:      table_child->left_attach = GTK_VALUE_UINT (*arg);      if (table_child->right_attach <= table_child->left_attach)	table_child->right_attach = table_child->left_attach + 1;      if (table_child->right_attach >= table->ncols)	gtk_table_resize (table, table->ncols, table_child->right_attach);      break;    case CHILD_ARG_RIGHT_ATTACH:      if (GTK_VALUE_UINT (*arg) > 0)	{	  table_child->right_attach = GTK_VALUE_UINT (*arg);	  if (table_child->right_attach <= table_child->left_attach)	    table_child->left_attach = table_child->right_attach - 1;	  if (table_child->right_attach >= table->ncols)	    gtk_table_resize (table, table->ncols, table_child->right_attach);	}      break;    case CHILD_ARG_TOP_ATTACH:      table_child->top_attach = GTK_VALUE_UINT (*arg);      if (table_child->bottom_attach <= table_child->top_attach)	table_child->bottom_attach = table_child->top_attach + 1;      if (table_child->bottom_attach >= table->nrows)	gtk_table_resize (table, table_child->bottom_attach, table->ncols);      break;    case CHILD_ARG_BOTTOM_ATTACH:      if (GTK_VALUE_UINT (*arg) > 0)	{	  table_child->bottom_attach = GTK_VALUE_UINT (*arg);	  if (table_child->bottom_attach <= table_child->top_attach)	    table_child->top_attach = table_child->bottom_attach - 1;	  if (table_child->bottom_attach >= table->nrows)	    gtk_table_resize (table, table_child->bottom_attach, table->ncols);	}      break;    case CHILD_ARG_X_OPTIONS:      table_child->xexpand = (GTK_VALUE_FLAGS (*arg) & GTK_EXPAND) != 0;      table_child->xshrink = (GTK_VALUE_FLAGS (*arg) & GTK_SHRINK) != 0;      table_child->xfill = (GTK_VALUE_FLAGS (*arg) & GTK_FILL) != 0;      break;    case CHILD_ARG_Y_OPTIONS:      table_child->yexpand = (GTK_VALUE_FLAGS (*arg) & GTK_EXPAND) != 0;      table_child->yshrink = (GTK_VALUE_FLAGS (*arg) & GTK_SHRINK) != 0;      table_child->yfill = (GTK_VALUE_FLAGS (*arg) & GTK_FILL) != 0;      break;    case CHILD_ARG_X_PADDING:      table_child->xpadding = GTK_VALUE_UINT (*arg);      break;    case CHILD_ARG_Y_PADDING:      table_child->ypadding = GTK_VALUE_UINT (*arg);      break;    default:      break;    }  if (GTK_WIDGET_VISIBLE (child) && GTK_WIDGET_VISIBLE (table))    gtk_widget_queue_resize (child);}static voidgtk_table_get_child_arg (GtkContainer   *container,			 GtkWidget      *child,			 GtkArg         *arg,			 guint           arg_id){  GtkTable *table;  GtkTableChild *table_child;  GList *list;  table = GTK_TABLE (container);  table_child = NULL;  for (list = table->children; list; list = list->next)    {      table_child = list->data;      if (table_child->widget == child)	break;    }  if (!list)    return;  switch (arg_id)    {    case CHILD_ARG_LEFT_ATTACH:      GTK_VALUE_UINT (*arg) = table_child->left_attach;      break;    case CHILD_ARG_RIGHT_ATTACH:      GTK_VALUE_UINT (*arg) = table_child->right_attach;      break;    case CHILD_ARG_TOP_ATTACH:      GTK_VALUE_UINT (*arg) = table_child->top_attach;      break;    case CHILD_ARG_BOTTOM_ATTACH:      GTK_VALUE_UINT (*arg) = table_child->bottom_attach;      break;    case CHILD_ARG_X_OPTIONS:      GTK_VALUE_FLAGS (*arg) = (table_child->xexpand * GTK_EXPAND |				table_child->xshrink * GTK_SHRINK |				table_child->xfill * GTK_FILL);      break;    case CHILD_ARG_Y_OPTIONS:      GTK_VALUE_FLAGS (*arg) = (table_child->yexpand * GTK_EXPAND |				table_child->yshrink * GTK_SHRINK |				table_child->yfill * GTK_FILL);      break;    case CHILD_ARG_X_PADDING:      GTK_VALUE_UINT (*arg) = table_child->xpadding;      break;    case CHILD_ARG_Y_PADDING:      GTK_VALUE_UINT (*arg) = table_child->ypadding;      break;    default:      arg->type = GTK_TYPE_INVALID;      break;    }}static voidgtk_table_init (GtkTable *table){  GTK_WIDGET_SET_FLAGS (table, GTK_NO_WINDOW);    table->children = NULL;  table->rows = NULL;  table->cols = NULL;  table->nrows = 0;  table->ncols = 0;  table->column_spacing = 0;  table->row_spacing = 0;  table->homogeneous = FALSE;  gtk_table_resize (table, 1, 1);}GtkWidget*gtk_table_new (guint	rows,	       guint	columns,	       gboolean homogeneous){  GtkTable *table;  if (rows == 0)	  rows = 1;  if (columns == 0)	  columns = 1;    table = gtk_type_new (gtk_table_get_type ());    table->homogeneous = (homogeneous ? TRUE : FALSE);  gtk_table_resize (table, rows, columns);    return GTK_WIDGET (table);}voidgtk_table_resize (GtkTable *table,		  guint     n_rows,		  guint     n_cols){  g_return_if_fail (table != NULL);  g_return_if_fail (GTK_IS_TABLE (table));  n_rows = MAX (n_rows, 1);  n_cols = MAX (n_cols, 1);    if (n_rows != table->nrows ||      n_cols != table->ncols)    {      GList *list;            for (list = table->children; list; list = list->next)	{	  GtkTableChild *child;	  	  child = list->data;	  	  n_rows = MAX (n_rows, child->bottom_attach);	  n_cols = MAX (n_cols, child->right_attach);	}            if (n_rows != table->nrows)	{	  guint i;	  i = table->nrows;	  table->nrows = n_rows;	  table->rows = g_realloc (table->rows, table->nrows * sizeof (GtkTableRowCol));	  	  for (; i < table->nrows; i++)	    {	      table->rows[i].requisition = 0;	      table->rows[i].allocation = 0;	      table->rows[i].spacing = table->row_spacing;	      table->rows[i].need_expand = 0;	      table->rows[i].need_shrink = 0;	      table->rows[i].expand = 0;	      table->rows[i].shrink = 0;	    }	}      if (n_cols != table->ncols)	{	  guint i;	  i = table->ncols;	  table->ncols = n_cols;	  table->cols = g_realloc (table->cols, table->ncols * sizeof (GtkTableRowCol));	  	  for (; i < table->ncols; i++)	    {	      table->cols[i].requisition = 0;	      table->cols[i].allocation = 0;	      table->cols[i].spacing = table->column_spacing;	      table->cols[i].need_expand = 0;	      table->cols[i].need_shrink = 0;	      table->cols[i].expand = 0;	      table->cols[i].shrink = 0;	    }	}    }}voidgtk_table_attach (GtkTable	  *table,		  GtkWidget	  *child,		  guint		   left_attach,		  guint		   right_attach,		  guint		   top_attach,		  guint		   bottom_attach,		  GtkAttachOptions xoptions,		  GtkAttachOptions yoptions,		  guint		   xpadding,		  guint		   ypadding){  GtkTableChild *table_child;    g_return_if_fail (table != NULL);  g_return_if_fail (GTK_IS_TABLE (table));  g_return_if_fail (child != NULL);  g_return_if_fail (GTK_IS_WIDGET (child));  g_return_if_fail (child->parent == NULL);    /* g_return_if_fail (left_attach >= 0); */  g_return_if_fail (left_attach < right_attach);  /* g_return_if_fail (top_attach >= 0); */

⌨️ 快捷键说明

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