📄 gtkwindow.c
字号:
requisition->height += child_requisition.height; }}static voidgtk_window_size_allocate (GtkWidget *widget, GtkAllocation *allocation){ GtkWindow *window; GtkAllocation child_allocation; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_WINDOW (widget)); g_return_if_fail (allocation != NULL); window = GTK_WINDOW (widget); widget->allocation = *allocation; if (window->bin.child && GTK_WIDGET_VISIBLE (window->bin.child)) { child_allocation.x = GTK_CONTAINER (window)->border_width; child_allocation.y = GTK_CONTAINER (window)->border_width; child_allocation.width = MAX (1, (gint)allocation->width - child_allocation.x * 2); child_allocation.height = MAX (1, (gint)allocation->height - child_allocation.y * 2); gtk_widget_size_allocate (window->bin.child, &child_allocation); }}static gintgtk_window_configure_event (GtkWidget *widget, GdkEventConfigure *event){ GtkWindow *window; g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (GTK_IS_WINDOW (widget), FALSE); g_return_val_if_fail (event != NULL, FALSE); window = GTK_WINDOW (widget); /* we got a configure event specifying the new window size and position, * in principle we have to distinguish 4 cases here: * 1) the size didn't change and resize_count == 0 * -> the window was merely moved (sometimes not even that) * 2) the size didn't change and resize_count > 0 * -> we requested a new size, but didn't get it * 3) the size changed and resize_count > 0 * -> we asked for a new size and we got one * 4) the size changed and resize_count == 0 * -> we got resized from outside the toolkit, and have to * accept that size since we don't want to fight neither the * window manager nor the user * in the three latter cases we have to reallocate the widget tree, * which happens in gtk_window_move_resize(), so we set a flag for * that function and assign the new size. if resize_count > 1, * we simply do nothing and wait for more configure events. */ if (window->resize_count > 0 || widget->allocation.width != event->width || widget->allocation.height != event->height) { if (window->resize_count > 0) window->resize_count -= 1; if (window->resize_count == 0) { window->handling_resize = TRUE; widget->allocation.width = event->width; widget->allocation.height = event->height; gtk_widget_queue_resize (widget); } } return TRUE;}static gintgtk_window_key_press_event (GtkWidget *widget, GdkEventKey *event){ GtkWindow *window; GtkDirectionType direction = 0; gboolean handled; g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (GTK_IS_WINDOW (widget), FALSE); g_return_val_if_fail (event != NULL, FALSE); window = GTK_WINDOW (widget); handled = FALSE; if (window->focus_widget && window->focus_widget != widget && GTK_WIDGET_IS_SENSITIVE (window->focus_widget)) { handled = gtk_widget_event (window->focus_widget, (GdkEvent*) event); } if (!handled) handled = gtk_accel_groups_activate (GTK_OBJECT (window), event->keyval, event->state); if (!handled) { switch (event->keyval) { case GDK_space: if (window->focus_widget) { gtk_widget_activate (window->focus_widget); handled = TRUE; } break; case GDK_Return: case GDK_KP_Enter: if (window->default_widget && (!window->focus_widget || !GTK_WIDGET_RECEIVES_DEFAULT (window->focus_widget))) { gtk_widget_activate (window->default_widget); handled = TRUE; } else if (window->focus_widget) { gtk_widget_activate (window->focus_widget); handled = TRUE; } break; case GDK_Up: case GDK_Down: case GDK_Left: case GDK_Right: case GDK_KP_Up: case GDK_KP_Down: case GDK_KP_Left: case GDK_KP_Right: case GDK_Tab: case GDK_ISO_Left_Tab: switch (event->keyval) { case GDK_Up: case GDK_KP_Up: direction = GTK_DIR_UP; break; case GDK_Down: case GDK_KP_Down: direction = GTK_DIR_DOWN; break; case GDK_Left: case GDK_KP_Left: direction = GTK_DIR_LEFT; break; case GDK_Right: case GDK_KP_Right: direction = GTK_DIR_RIGHT; break; case GDK_Tab: case GDK_ISO_Left_Tab: if (event->state & GDK_SHIFT_MASK) direction = GTK_DIR_TAB_BACKWARD; else direction = GTK_DIR_TAB_FORWARD; break; default : direction = GTK_DIR_UP; /* never reached, but makes compiler happy */ } gtk_container_focus (GTK_CONTAINER (widget), direction); if (!GTK_CONTAINER (window)->focus_child) gtk_window_set_focus (GTK_WINDOW (widget), NULL); else handled = TRUE; break; } } if (!handled && GTK_WIDGET_CLASS (parent_class)->key_press_event) handled = GTK_WIDGET_CLASS (parent_class)->key_press_event (widget, event); return handled;}static gintgtk_window_key_release_event (GtkWidget *widget, GdkEventKey *event){ GtkWindow *window; gint handled; g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (GTK_IS_WINDOW (widget), FALSE); g_return_val_if_fail (event != NULL, FALSE); window = GTK_WINDOW (widget); handled = FALSE; if (window->focus_widget && window->focus_widget != widget && GTK_WIDGET_SENSITIVE (window->focus_widget)) { handled = gtk_widget_event (window->focus_widget, (GdkEvent*) event); } if (!handled && GTK_WIDGET_CLASS (parent_class)->key_release_event) handled = GTK_WIDGET_CLASS (parent_class)->key_release_event (widget, event); return handled;}static gintgtk_window_enter_notify_event (GtkWidget *widget, GdkEventCrossing *event){ g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (GTK_IS_WINDOW (widget), FALSE); g_return_val_if_fail (event != NULL, FALSE); return FALSE;}static gintgtk_window_leave_notify_event (GtkWidget *widget, GdkEventCrossing *event){ g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (GTK_IS_WINDOW (widget), FALSE); g_return_val_if_fail (event != NULL, FALSE); return FALSE;}static gintgtk_window_focus_in_event (GtkWidget *widget, GdkEventFocus *event){ GtkWindow *window; GdkEventFocus fevent; g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (GTK_IS_WINDOW (widget), FALSE); g_return_val_if_fail (event != NULL, FALSE); /* It appears spurious focus in events can occur when * the window is hidden. So we'll just check to see if * the window is visible before actually handling the * event */ if (GTK_WIDGET_VISIBLE (widget)) { window = GTK_WINDOW (widget); if (window->focus_widget && window->focus_widget != widget && !GTK_WIDGET_HAS_FOCUS (window->focus_widget)) { fevent.type = GDK_FOCUS_CHANGE; fevent.window = window->focus_widget->window; fevent.in = TRUE; gtk_widget_event (window->focus_widget, (GdkEvent*) &fevent); } } return FALSE;}static gintgtk_window_focus_out_event (GtkWidget *widget, GdkEventFocus *event){ GtkWindow *window; GdkEventFocus fevent; g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (GTK_IS_WINDOW (widget), FALSE); g_return_val_if_fail (event != NULL, FALSE); window = GTK_WINDOW (widget); if (window->focus_widget && window->focus_widget != widget && GTK_WIDGET_HAS_FOCUS (window->focus_widget)) { fevent.type = GDK_FOCUS_CHANGE; fevent.window = window->focus_widget->window; fevent.in = FALSE; gtk_widget_event (window->focus_widget, (GdkEvent*) &fevent); } return FALSE;}static GdkAtom atom_rcfiles = GDK_NONE;static voidgtk_window_read_rcfiles (GtkWidget *widget, GdkEventClient *event){ GList *embedded_windows; embedded_windows = gtk_object_get_data (GTK_OBJECT (widget), "gtk-embedded"); if (embedded_windows) { GdkEventClient sev; int i; for(i = 0; i < 5; i++) sev.data.l[i] = 0; sev.data_format = 32; sev.message_type = atom_rcfiles; while (embedded_windows) { guint xid = GPOINTER_TO_UINT (embedded_windows->data); gdk_event_send_client_message ((GdkEvent *) &sev, xid); embedded_windows = embedded_windows->next; } } if (gtk_rc_reparse_all ()) { /* If the above returned true, some of our RC files are out * of date, so we need to reset all our widgets. Our other * toplevel windows will also get the message, but by * then, the RC file will up to date, so we have to tell * them now. */ GList *toplevels; toplevels = gtk_container_get_toplevels(); while (toplevels) { gtk_widget_reset_rc_styles (toplevels->data); toplevels = toplevels->next; } }}static gintgtk_window_client_event (GtkWidget *widget, GdkEventClient *event){ g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (GTK_IS_WINDOW (widget), FALSE); g_return_val_if_fail (event != NULL, FALSE); if (!atom_rcfiles) atom_rcfiles = gdk_atom_intern("_GTK_READ_RCFILES", FALSE); if(event->message_type == atom_rcfiles) gtk_window_read_rcfiles (widget, event); return FALSE;}static voidgtk_window_check_resize (GtkContainer *container){ GtkWindow *window; g_return_if_fail (container != NULL); g_return_if_fail (GTK_IS_WINDOW (container)); window = GTK_WINDOW (container); if (GTK_WIDGET_VISIBLE (container)) gtk_window_move_resize (window);}static voidgtk_window_real_set_focus (GtkWindow *window, GtkWidget *focus){ GdkEventFocus event; gboolean def_flags = 0; g_return_if_fail (window != NULL); g_return_if_fail (GTK_IS_WINDOW (window)); if (window->default_widget) def_flags = GTK_WIDGET_HAS_DEFAULT (window->default_widget); if (window->focus_widget) { event.type = GDK_FOCUS_CHANGE; event.window = window->focus_widget->window; event.in = FALSE; if (GTK_WIDGET_RECEIVES_DEFAULT (window->focus_widget) && (window->focus_widget != window->default_widget)) { GTK_WIDGET_UNSET_FLAGS (window->focus_widget, GTK_HAS_DEFAULT); /* if any widget had the default set there should be a default_widget, but might not so this is a sanity check */ if (window->default_widget) GTK_WIDGET_SET_FLAGS (window->default_widget, GTK_HAS_DEFAULT); } gtk_widget_event (window->focus_widget, (GdkEvent*) &event); } window->focus_widget = focus; if (window->focus_widget) { event.type = GDK_FOCUS_CHANGE; event.window = window->focus_widget->window; event.in = TRUE; if (window->default_widget) { if (GTK_WIDGET_RECEIVES_DEFAULT (window->focus_widget) && (window->focus_widget != window->default_widget)) { if (GTK_WIDGET_CAN_DEFAULT (window->focus_widget)) GTK_WIDGET_SET_FLAGS (window->focus_widget, GTK_HAS_DEFAULT); GTK_WIDGET_UNSET_FLAGS (window->default_widget, GTK_HAS_DEFAULT); } else { GTK_WIDGET_SET_FLAGS (window->default_widget, GTK_HAS_DEFAULT); } } gtk_widget_event (window->focus_widget, (GdkEvent*) &event); } else if (window->default_widget) { GTK_WIDGET_SET_FLAGS (window->default_widget, GTK_HAS_DEFAULT); } if (window->default_widget && (def_flags != GTK_WIDGET_FLAGS (window->default_widget))) gtk_widget_queue_draw (window->default_widget);}/********************************* * Functions related to resizing * *********************************/static voidgtk_window_move_resize (GtkWindow *window){ GtkWidget *widget; GtkContainer *container; GtkWindowGeometryInfo *info; GtkWindowLastGeometryInfo saved_last_info; GdkGeometry new_geometry; guint new_flags; gint x, y; gint width, height; gint new_width, new_height; gboolean default_size_changed = FALSE; gboolean hints_changed = FALSE; g_return_if_fail (GTK_IS_WINDOW (window)); g_return_if_fail (GTK_WIDGET_REALIZED (window)); widget = GTK_WIDGET (window); container = GTK_CONTAINER (widget); info = gtk_window_get_geometry_info (window, TRUE); saved_last_info = info->last; gtk_widget_size_request (widget, NULL); gtk_window_compute_default_size (window, &new_width, &new_height); if (info->last.width < 0 || info->last.width != new_width || info->last.height != new_height) { default_size_changed = TRUE; info->last.width = new_width; info->last.height = new_height; /* We need to force a reposition in this case */ if (window->position == GTK_WIN_POS_CENTER_ALWAYS) window->use_uposition = TRUE; } /* Compute new set of hints for the window */ gtk_window_compute_hints (window, &new_geometry, &new_flags); if (!gtk_window_compare_hints (&info->last.geometry, info->last.flags, &new_geometry, new_flags)) { hints_changed = TRUE; info->last.geometry = new_geometry; info->last.flags = new_flags; } /* From the default size and the allocation, figure out the size * the window should be. */ if (!default_size_changed || (!window->auto_shrink && new_width <= widget->allocation.width && new_height <= widget->allocation.height)) { new_width = widget->allocation.width; new_height = widget->allocation.height; } /* constrain the window size to the specified geometry */ gtk_window_constrain_size (window, &new_geometry, new_flags, new_width, new_height, &new_width, &new_height); /* compute new window position if a move is required */ gtk_window_compute_reposition (window, new_width, new_height, &x, &y); if (x != 1 && y != -1 && !(new_flags & GDK_HINT_POS)) { new_flags |= GDK_HINT_POS; hints_changed = TRUE; } /* handle actual resizing: * - handle reallocations due to configure events * - figure whether we need to request a new window size * - handle simple resizes within our widget tree * - reposition window if neccessary */ width = widget->allocation.width; height = widget->allocation.height;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -