📄 gtknotebook.c
字号:
GTK_NOTEBOOK (widget)->child_has_focus = FALSE; GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS); gtk_widget_draw_focus (widget); return FALSE;}static gintgtk_notebook_focus_out (GtkWidget *widget, GdkEventFocus *event){ g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (GTK_IS_NOTEBOOK (widget), FALSE); g_return_val_if_fail (event != NULL, FALSE); GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS); gtk_widget_draw_focus (widget); return FALSE;}static voidgtk_notebook_draw_focus (GtkWidget *widget){ GtkNotebook *notebook; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_NOTEBOOK (widget)); notebook = GTK_NOTEBOOK (widget); if (GTK_WIDGET_DRAWABLE (widget) && notebook->show_tabs && notebook->focus_tab) { GtkNotebookPage *page; GdkRectangle area; page = notebook->focus_tab->data; area.x = page->tab_label->allocation.x - 1; area.y = page->tab_label->allocation.y - 1; area.width = page->tab_label->allocation.width + 2; area.height = page->tab_label->allocation.height + 2; gtk_notebook_draw_tab (GTK_NOTEBOOK (widget), page, &area); }}static voidgtk_notebook_style_set (GtkWidget *widget, GtkStyle *previous_style){ if (GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_NO_WINDOW (widget)) { gtk_style_set_background (widget->style, widget->window, widget->state); if (GTK_WIDGET_DRAWABLE (widget)) gdk_window_clear (widget->window); } gtk_notebook_set_shape (GTK_NOTEBOOK(widget));}/* Private GtkContainer Methods : * * gtk_notebook_set_child_arg * gtk_notebook_get_child_arg * gtk_notebook_add * gtk_notebook_remove * gtk_notebook_focus * gtk_notebook_set_focus_child * gtk_notebook_child_type * gtk_notebook_forall */static voidgtk_notebook_set_child_arg (GtkContainer *container, GtkWidget *child, GtkArg *arg, guint arg_id){ gboolean expand; gboolean fill; GtkPackType pack_type; switch (arg_id) { case CHILD_ARG_TAB_LABEL: /* a NULL pointer indicates a default_tab setting, otherwise * we need to set the associated label */ gtk_notebook_set_tab_label_text (GTK_NOTEBOOK (container), child, GTK_VALUE_STRING(*arg)); break; case CHILD_ARG_MENU_LABEL: gtk_notebook_set_menu_label_text (GTK_NOTEBOOK (container), child, GTK_VALUE_STRING (*arg)); break; case CHILD_ARG_POSITION: gtk_notebook_reorder_child (GTK_NOTEBOOK (container), child, GTK_VALUE_INT (*arg)); break; case CHILD_ARG_TAB_EXPAND: gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child, &expand, &fill, &pack_type); gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (container), child, GTK_VALUE_BOOL (*arg), fill, pack_type); break; case CHILD_ARG_TAB_FILL: gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child, &expand, &fill, &pack_type); gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (container), child, expand, GTK_VALUE_BOOL (*arg), pack_type); break; case CHILD_ARG_TAB_PACK: gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child, &expand, &fill, &pack_type); gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (container), child, expand, fill, GTK_VALUE_BOOL (*arg)); break; default: break; }}static voidgtk_notebook_get_child_arg (GtkContainer *container, GtkWidget *child, GtkArg *arg, guint arg_id){ GList *list; GtkNotebook *notebook; GtkWidget *label; gboolean expand; gboolean fill; GtkPackType pack_type; notebook = GTK_NOTEBOOK (container); if (!(list = g_list_find_custom (notebook->children, child, gtk_notebook_page_compare))) { arg->type = GTK_TYPE_INVALID; return; } switch (arg_id) { case CHILD_ARG_TAB_LABEL: label = gtk_notebook_get_tab_label (notebook, child); if (label && GTK_IS_LABEL (label)) GTK_VALUE_STRING (*arg) = g_strdup (GTK_LABEL (label)->label); else GTK_VALUE_STRING (*arg) = NULL; break; case CHILD_ARG_MENU_LABEL: label = gtk_notebook_get_menu_label (notebook, child); if (label && GTK_IS_LABEL (label)) GTK_VALUE_STRING (*arg) = g_strdup (GTK_LABEL (label)->label); else GTK_VALUE_STRING (*arg) = NULL; break; case CHILD_ARG_POSITION: GTK_VALUE_INT (*arg) = g_list_position (notebook->children, list); break; case CHILD_ARG_TAB_EXPAND: gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child, &expand, NULL, NULL); GTK_VALUE_BOOL (*arg) = expand; break; case CHILD_ARG_TAB_FILL: gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child, NULL, &fill, NULL); GTK_VALUE_BOOL (*arg) = fill; break; case CHILD_ARG_TAB_PACK: gtk_notebook_query_tab_label_packing (GTK_NOTEBOOK (container), child, NULL, NULL, &pack_type); GTK_VALUE_BOOL (*arg) = pack_type; break; default: arg->type = GTK_TYPE_INVALID; break; }}static voidgtk_notebook_add (GtkContainer *container, GtkWidget *widget){ g_return_if_fail (container != NULL); g_return_if_fail (GTK_IS_NOTEBOOK (container)); gtk_notebook_insert_page_menu (GTK_NOTEBOOK (container), widget, NULL, NULL, -1);}static voidgtk_notebook_remove (GtkContainer *container, GtkWidget *widget){ GtkNotebook *notebook; GtkNotebookPage *page; GList *children; guint page_num; g_return_if_fail (container != NULL); g_return_if_fail (GTK_IS_NOTEBOOK (container)); g_return_if_fail (widget != NULL); notebook = GTK_NOTEBOOK (container); children = notebook->children; page_num = 0; while (children) { page = children->data; if (page->child == widget) { gtk_notebook_real_remove (notebook, children); break; } page_num++; children = children->next; }}static gintgtk_notebook_focus (GtkContainer *container, GtkDirectionType direction){ GtkNotebook *notebook; GtkNotebookPage *page = NULL; GtkNotebookPage *old_page = NULL; g_return_val_if_fail (container != NULL, FALSE); g_return_val_if_fail (GTK_IS_NOTEBOOK (container), FALSE); notebook = GTK_NOTEBOOK (container); if (!GTK_WIDGET_DRAWABLE (notebook) || !GTK_WIDGET_IS_SENSITIVE (container) || !notebook->children || !notebook->cur_page) return FALSE; if (!notebook->show_tabs) { if (GTK_WIDGET_DRAWABLE (notebook->cur_page->child) && GTK_WIDGET_IS_SENSITIVE (notebook->cur_page->child)) { if (GTK_IS_CONTAINER (notebook->cur_page->child)) { if (gtk_container_focus (GTK_CONTAINER (notebook->cur_page->child), direction)) return TRUE; } else if (GTK_WIDGET_CAN_FOCUS (notebook->cur_page->child)) { if (!container->focus_child) { gtk_widget_grab_focus (notebook->cur_page->child); return TRUE; } } } return FALSE; } if (notebook->focus_tab) old_page = notebook->focus_tab->data; if (container->focus_child && old_page && container->focus_child == old_page->child && notebook->child_has_focus) { if (GTK_WIDGET_DRAWABLE (container->focus_child)) { if (GTK_IS_CONTAINER (container->focus_child) && !GTK_WIDGET_HAS_FOCUS (container->focus_child)) { if (gtk_container_focus (GTK_CONTAINER (container->focus_child), direction)) return TRUE; } gtk_widget_grab_focus (GTK_WIDGET(notebook)); return TRUE; } notebook->focus_tab = NULL; return FALSE; } if (!GTK_WIDGET_HAS_FOCUS (container)) notebook->focus_tab = NULL; switch (direction) { case GTK_DIR_TAB_FORWARD: case GTK_DIR_RIGHT: case GTK_DIR_DOWN: gtk_notebook_switch_focus_tab (notebook, gtk_notebook_search_page (notebook, notebook->focus_tab, STEP_NEXT, TRUE)); break; case GTK_DIR_TAB_BACKWARD: case GTK_DIR_LEFT: case GTK_DIR_UP: gtk_notebook_switch_focus_tab (notebook, gtk_notebook_search_page (notebook, notebook->focus_tab, STEP_PREV, TRUE)); break; } if (notebook->focus_tab) { if (!GTK_WIDGET_HAS_FOCUS (container)) gtk_widget_grab_focus (GTK_WIDGET (container)); page = notebook->focus_tab->data; if (GTK_WIDGET_MAPPED (page->tab_label)) gtk_notebook_focus_changed (notebook, old_page); else { gtk_notebook_pages_allocate (notebook, &(GTK_WIDGET (notebook)->allocation)); gtk_notebook_expose_tabs (notebook); } return TRUE; } gtk_notebook_focus_changed (notebook, old_page); return FALSE;}static voidgtk_notebook_set_focus_child (GtkContainer *container, GtkWidget *child){ GtkNotebook *notebook; g_return_if_fail (container != NULL); g_return_if_fail (GTK_IS_NOTEBOOK (container)); if (child) { g_return_if_fail (GTK_IS_WIDGET (child)); notebook = GTK_NOTEBOOK (container); notebook->child_has_focus = TRUE; if (!notebook->focus_tab) { GList *children; GtkNotebookPage *page; children = notebook->children; while (children) { page = children->data; if (page->child == child || page->tab_label == child) gtk_notebook_switch_focus_tab (notebook, children); children = children->next; } } } parent_class->set_focus_child (container, child);}static voidgtk_notebook_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data){ GtkNotebook *notebook; GList *children; g_return_if_fail (container != NULL); g_return_if_fail (GTK_IS_NOTEBOOK (container)); g_return_if_fail (callback != NULL); notebook = GTK_NOTEBOOK (container); children = notebook->children; while (children) { GtkNotebookPage *page; page = children->data; children = children->next; (* callback) (page->child, callback_data); if (include_internals) { if (page->tab_label) (* callback) (page->tab_label, callback_data); if (page->menu_label) (* callback) (page->menu_label, callback_data); } }}static GtkTypegtk_notebook_child_type (GtkContainer *container){ return GTK_TYPE_WIDGET;}/* Private GtkNotebook Functions: * * gtk_notebook_panel_realize * gtk_notebook_expose_tabs * gtk_notebook_focus_changed * gtk_notebook_real_remove * gtk_notebook_update_labels * gtk_notebook_timer * gtk_notebook_page_compare * gtk_notebook_real_page_position * gtk_notebook_search_page */static voidgtk_notebook_panel_realize (GtkNotebook *notebook){ GtkWidget *widget; GdkWindowAttr attributes; gint attributes_mask; g_return_if_fail (notebook != NULL); g_return_if_fail (GTK_IS_NOTEBOOK (notebook)); widget = GTK_WIDGET (notebook); attributes.window_type = GDK_WINDOW_CHILD; attributes.wclass = GDK_INPUT_OUTPUT; attributes.visual = gtk_widget_get_visual (widget); attributes.colormap = gtk_widget_get_colormap (widget); attributes.event_mask = gtk_widget_get_events (widget); attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_ENTER_NOTIFY_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK; attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; attributes.width = 2 * ARROW_SIZE + ARROW_SPACING; attributes.height = ARROW_SIZE; attributes.x = (widget->allocation.width - attributes.width - GTK_CONTAINER (notebook)->border_width); attributes.y = (widget->allocation.height - ARROW_SIZE - GTK_CONTAINER (notebook)->border_width); if (notebook->tab_pos == GTK_POS_TOP) attributes.y = GTK_CONTAINER (notebook)->border_width; else if (notebook->tab_pos == GTK_POS_LEFT) attributes.x = (widget->allocation.x + GTK_CONTAINER (notebook)->border_width);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -