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

📄 gtkmenu.c

📁 gtk是linux一款强大的夸平台的图形化开发工具
💻 C
📖 第 1 页 / 共 3 页
字号:
  menu = GTK_MENU (widget);  menu_shell = GTK_MENU_SHELL (widget);    requisition->width = 0;  requisition->height = 0;    max_toggle_size = 0;  max_accel_width = 0;    children = menu_shell->children;  while (children)    {      child = children->data;      children = children->next;            if (GTK_WIDGET_VISIBLE (child))	{	  GTK_MENU_ITEM (child)->show_submenu_indicator = TRUE;	  gtk_widget_size_request (child, &child_requisition);	  	  requisition->width = MAX (requisition->width, child_requisition.width);	  requisition->height += child_requisition.height;	  	  max_toggle_size = MAX (max_toggle_size, MENU_ITEM_CLASS (child)->toggle_size);	  max_accel_width = MAX (max_accel_width, GTK_MENU_ITEM (child)->accelerator_width);	}    }    requisition->width += max_toggle_size + max_accel_width;  requisition->width += (GTK_CONTAINER (menu)->border_width +			 widget->style->klass->xthickness) * 2;  requisition->height += (GTK_CONTAINER (menu)->border_width +			  widget->style->klass->ythickness) * 2;    children = menu_shell->children;  while (children)    {      child = children->data;      children = children->next;            GTK_MENU_ITEM (child)->toggle_size = max_toggle_size;    }}static voidgtk_menu_size_allocate (GtkWidget     *widget,			GtkAllocation *allocation){  GtkMenu *menu;  GtkMenuShell *menu_shell;  GtkWidget *child;  GtkAllocation child_allocation;  GList *children;    g_return_if_fail (widget != NULL);  g_return_if_fail (GTK_IS_MENU (widget));  g_return_if_fail (allocation != NULL);    menu = GTK_MENU (widget);  menu_shell = GTK_MENU_SHELL (widget);    widget->allocation = *allocation;  if (GTK_WIDGET_REALIZED (widget))    gdk_window_move_resize (widget->window,			    allocation->x, allocation->y,			    allocation->width, allocation->height);  if (menu_shell->children)    {      child_allocation.x = (GTK_CONTAINER (menu)->border_width +			    widget->style->klass->xthickness);      child_allocation.y = (GTK_CONTAINER (menu)->border_width +			    widget->style->klass->ythickness);      child_allocation.width = MAX (1, (gint)allocation->width - child_allocation.x * 2);            children = menu_shell->children;      while (children)	{	  child = children->data;	  children = children->next;	  	  if (GTK_WIDGET_VISIBLE (child))	    {	      GtkRequisition child_requisition;	      gtk_widget_get_child_requisition (child, &child_requisition);	      	      child_allocation.height = child_requisition.height;	      	      gtk_widget_size_allocate (child, &child_allocation);	      gtk_widget_queue_draw (child);	      	      child_allocation.y += child_allocation.height;	    }	}    }}static voidgtk_menu_paint (GtkWidget *widget){  g_return_if_fail (widget != NULL);  g_return_if_fail (GTK_IS_MENU (widget));    if (GTK_WIDGET_DRAWABLE (widget))    {      gtk_paint_box (widget->style,		     widget->window,		     GTK_STATE_NORMAL,		     GTK_SHADOW_OUT,		     NULL, widget, "menu",		     0, 0, -1, -1);    }}static voidgtk_menu_draw (GtkWidget    *widget,	       GdkRectangle *area){  GtkMenuShell *menu_shell;  GtkWidget *child;  GdkRectangle child_area;  GList *children;    g_return_if_fail (widget != NULL);  g_return_if_fail (GTK_IS_MENU (widget));  g_return_if_fail (area != NULL);    if (GTK_WIDGET_DRAWABLE (widget))    {      gtk_menu_paint (widget);            menu_shell = GTK_MENU_SHELL (widget);            children = menu_shell->children;      while (children)	{	  child = children->data;	  children = children->next;	  	  if (gtk_widget_intersect (child, area, &child_area))	    gtk_widget_draw (child, &child_area);	}    }}static gintgtk_menu_expose (GtkWidget	*widget,		 GdkEventExpose *event){  GtkMenuShell *menu_shell;  GtkWidget *child;  GdkEventExpose child_event;  GList *children;  GtkMenu *menu;    g_return_val_if_fail (widget != NULL, FALSE);  g_return_val_if_fail (GTK_IS_MENU (widget), FALSE);  g_return_val_if_fail (event != NULL, FALSE);  menu_shell = GTK_MENU_SHELL (widget);  menu = GTK_MENU (widget);    if (GTK_WIDGET_DRAWABLE (widget))    {      gtk_menu_paint (widget);            child_event = *event;            children = menu_shell->children;      while (children)	{	  child = children->data;	  children = children->next;	  	  if (GTK_WIDGET_NO_WINDOW (child) &&	      gtk_widget_intersect (child, &event->area, &child_event.area))	    gtk_widget_event (child, (GdkEvent*) &child_event);	}    }    return FALSE;}static gintgtk_menu_key_press (GtkWidget	*widget,		    GdkEventKey *event){  GtkMenuShell *menu_shell;  gboolean delete = FALSE;    g_return_val_if_fail (widget != NULL, FALSE);  g_return_val_if_fail (GTK_IS_MENU (widget), FALSE);  g_return_val_if_fail (event != NULL, FALSE);        menu_shell = GTK_MENU_SHELL (widget);  if (GTK_WIDGET_CLASS (parent_class)->key_press_event (widget, event))    return TRUE;  switch (event->keyval)    {    case GDK_Delete:    case GDK_KP_Delete:    case GDK_BackSpace:      delete = TRUE;      break;    default:      break;    }  /* Modify the accelerators */  if (menu_shell->active_menu_item &&      GTK_BIN (menu_shell->active_menu_item)->child &&      GTK_MENU_ITEM (menu_shell->active_menu_item)->submenu == NULL &&      !gtk_widget_accelerators_locked (menu_shell->active_menu_item) &&      (delete ||       (gtk_accelerator_valid (event->keyval, event->state) &&	(event->state ||	 !gtk_menu_get_uline_accel_group (GTK_MENU (menu_shell)) ||	 (event->keyval >= GDK_F1 && event->keyval <= GDK_F35)))))    {      GtkMenuItem *menu_item;      GtkAccelGroup *accel_group;            menu_item = GTK_MENU_ITEM (menu_shell->active_menu_item);            if (!GTK_MENU (widget)->accel_group)	accel_group = gtk_accel_group_get_default ();      else	accel_group = GTK_MENU (widget)->accel_group;            gtk_widget_remove_accelerators (GTK_WIDGET (menu_item),				      gtk_signal_name (menu_item->accelerator_signal),				      TRUE);            if (!delete &&	  0 == gtk_widget_accelerator_signal (GTK_WIDGET (menu_item),					      accel_group,					      event->keyval,					      event->state))	{	  GSList *slist;	  	  slist = gtk_accel_group_entries_from_object (GTK_OBJECT (menu_item));	  while (slist)	    {	      GtkAccelEntry *ac_entry;	      	      ac_entry = slist->data;	      	      if (ac_entry->signal_id == menu_item->accelerator_signal)		break;	      	      slist = slist->next;	    }	  	  if (!slist)	    gtk_widget_add_accelerator (GTK_WIDGET (menu_item),					gtk_signal_name (menu_item->accelerator_signal),					accel_group,					event->keyval,					event->state,					GTK_ACCEL_VISIBLE);	}    }    return TRUE;}static gint gtk_menu_motion_notify  (GtkWidget	   *widget,			 GdkEventMotion    *event){  g_return_val_if_fail (widget != NULL, FALSE);  g_return_val_if_fail (GTK_IS_MENU (widget), FALSE);    if (GTK_MENU_SHELL (widget)->ignore_enter)    GTK_MENU_SHELL (widget)->ignore_enter = FALSE;  else     {      gint width, height;      gdk_window_get_size (event->window, &width, &height);      if (event->x >= 0 && event->x < width &&	  event->y >= 0 && event->y < height)	{	  GdkEvent send_event;	  	  send_event.crossing.type = GDK_ENTER_NOTIFY;	  send_event.crossing.window = event->window;	  send_event.crossing.time = event->time;	  send_event.crossing.send_event = TRUE;	  	  gtk_widget_event (widget, &send_event);	}    }  return FALSE;}static voidgtk_menu_deactivate (GtkMenuShell *menu_shell){  GtkWidget *parent;    g_return_if_fail (menu_shell != NULL);  g_return_if_fail (GTK_IS_MENU (menu_shell));    parent = menu_shell->parent_menu_shell;    menu_shell->activate_time = 0;  gtk_menu_popdown (GTK_MENU (menu_shell));    if (parent)    gtk_menu_shell_deactivate (GTK_MENU_SHELL (parent));}static voidgtk_menu_position (GtkMenu *menu){  GtkWidget *widget;  GtkRequisition requisition;  gint x, y;   g_return_if_fail (menu != NULL);  g_return_if_fail (GTK_IS_MENU (menu));  widget = GTK_WIDGET (menu);  gdk_window_get_pointer (NULL, &x, &y, NULL);  /* We need the requisition to figure out the right place to   * popup the menu. In fact, we always need to ask here, since   * if one a size_request was queued while we weren't popped up,   * the requisition won't have been recomputed yet.   */  gtk_widget_size_request (widget, &requisition);        if (menu->position_func)    (* menu->position_func) (menu, &x, &y, menu->position_func_data);  else    {      gint screen_width;      gint screen_height;            screen_width = gdk_screen_width ();      screen_height = gdk_screen_height ();	        x = CLAMP (x - 2, 0, MAX (0, screen_width - requisition.width));      y = CLAMP (y - 2, 0, MAX (0, screen_height - requisition.height));    }  /* FIXME: The MAX() here is because gtk_widget_set_uposition   * is broken. Once we provide an alternate interface that   * allows negative values, then we can remove them.   */  gtk_widget_set_uposition (GTK_MENU_SHELL (menu)->active ?			        menu->toplevel : menu->tearoff_window, 			    MAX (x, 0), MAX (y, 0));}/* Reparent the menu, taking care of the refcounting */static void gtk_menu_reparent (GtkMenu      *menu, 		   GtkWidget    *new_parent, 		   gboolean      unrealize){  GtkObject *object = GTK_OBJECT (menu);  GtkWidget *widget = GTK_WIDGET (menu);  gboolean was_floating = GTK_OBJECT_FLOATING (object);  gtk_object_ref (object);  gtk_object_sink (object);  if (unrealize)    {      gtk_object_ref (object);      gtk_container_remove (GTK_CONTAINER (widget->parent), widget);      gtk_container_add (GTK_CONTAINER (new_parent), widget);      gtk_object_unref (object);    }  else    gtk_widget_reparent (GTK_WIDGET (menu), new_parent);  gtk_widget_set_usize (new_parent, -1, -1);    if (was_floating)    GTK_OBJECT_SET_FLAGS (object, GTK_FLOATING);  else    gtk_object_unref (object);}static voidgtk_menu_show_all (GtkWidget *widget){  g_return_if_fail (widget != NULL);  g_return_if_fail (GTK_IS_MENU (widget));  /* Show children, but not self. */  gtk_container_foreach (GTK_CONTAINER (widget), (GtkCallback) gtk_widget_show_all, NULL);}static voidgtk_menu_hide_all (GtkWidget *widget){  g_return_if_fail (widget != NULL);  g_return_if_fail (GTK_IS_MENU (widget));  /* Hide children, but not self. */  gtk_container_foreach (GTK_CONTAINER (widget), (GtkCallback) gtk_widget_hide_all, NULL);}

⌨️ 快捷键说明

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