📄 gtknotebook.c
字号:
notebook->panel = gdk_window_new (widget->window, &attributes, attributes_mask); gtk_style_set_background (widget->style, notebook->panel, GTK_STATE_NORMAL); gdk_window_set_back_pixmap (widget->window, NULL, TRUE); gdk_window_set_user_data (notebook->panel, widget);}static voidgtk_notebook_expose_tabs (GtkNotebook *notebook){ GtkWidget *widget; GtkNotebookPage *page; GdkEventExpose event; gint border; widget = GTK_WIDGET (notebook); border = GTK_CONTAINER (notebook)->border_width; if (!GTK_WIDGET_MAPPED (notebook) || !notebook->first_tab) return; page = notebook->first_tab->data; event.type = GDK_EXPOSE; event.window = widget->window; event.count = 0; event.area.x = border; event.area.y = border; switch (notebook->tab_pos) { case GTK_POS_BOTTOM: event.area.y = (widget->allocation.height - border - page->allocation.height - widget->style->klass->ythickness); if (page != notebook->cur_page) event.area.y -= widget->style->klass->ythickness; case GTK_POS_TOP: event.area.width = widget->allocation.width - 2 * border; event.area.height = (page->allocation.height + widget->style->klass->ythickness); if (page != notebook->cur_page) event.area.height += widget->style->klass->ythickness; break; case GTK_POS_RIGHT: event.area.x = (widget->allocation.width - border - page->allocation.width - widget->style->klass->xthickness); if (page != notebook->cur_page) event.area.x -= widget->style->klass->xthickness; case GTK_POS_LEFT: event.area.width = (page->allocation.width + widget->style->klass->xthickness); event.area.height = widget->allocation.height - 2 * border; if (page != notebook->cur_page) event.area.width += widget->style->klass->xthickness; break; } gtk_widget_event (widget, (GdkEvent *) &event);}static voidgtk_notebook_focus_changed (GtkNotebook *notebook, GtkNotebookPage *old_page){ g_return_if_fail (notebook != NULL); g_return_if_fail (GTK_IS_NOTEBOOK (notebook)); if (GTK_WIDGET_DRAWABLE (notebook) && notebook->show_tabs) { GdkRectangle area; if (notebook->focus_tab) { GtkNotebookPage *page; 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 (notebook, page, &area); } if (old_page) { area.x = old_page->tab_label->allocation.x - 1; area.y = old_page->tab_label->allocation.y - 1; area.width = old_page->tab_label->allocation.width + 2; area.height = old_page->tab_label->allocation.height + 2; gtk_notebook_draw_tab (notebook, old_page, &area); } }}static gintgtk_notebook_timer (GtkNotebook *notebook){ gboolean retval = FALSE; GDK_THREADS_ENTER (); if (notebook->timer) { if (notebook->click_child == GTK_ARROW_LEFT) { if (!notebook->focus_tab || gtk_notebook_search_page (notebook, notebook->focus_tab, STEP_PREV, TRUE)) gtk_container_focus (GTK_CONTAINER (notebook), GTK_DIR_LEFT); } else if (notebook->click_child == GTK_ARROW_RIGHT) { if (!notebook->focus_tab || gtk_notebook_search_page (notebook, notebook->focus_tab, STEP_NEXT, TRUE)) gtk_container_focus (GTK_CONTAINER (notebook), GTK_DIR_RIGHT); } if (notebook->need_timer) { notebook->need_timer = FALSE; notebook->timer = gtk_timeout_add (NOTEBOOK_SCROLL_DELAY, (GtkFunction) gtk_notebook_timer, (gpointer) notebook); } else retval = TRUE; } GDK_THREADS_LEAVE (); return retval;}static gintgtk_notebook_page_compare (gconstpointer a, gconstpointer b){ return (((GtkNotebookPage *) a)->child != b);}static voidgtk_notebook_real_remove (GtkNotebook *notebook, GList *list){ GtkNotebookPage *page; GList * next_list; gint need_resize = FALSE; next_list = gtk_notebook_search_page (notebook, list, STEP_PREV, TRUE); if (!next_list) next_list = gtk_notebook_search_page (notebook, list, STEP_NEXT, TRUE); if (notebook->cur_page == list->data) { notebook->cur_page = NULL; if (next_list) gtk_notebook_switch_page (notebook, GTK_NOTEBOOK_PAGE (next_list), -1); } if (list == notebook->first_tab) notebook->first_tab = next_list; if (list == notebook->focus_tab) gtk_notebook_switch_focus_tab (notebook, next_list); page = list->data; if (GTK_WIDGET_VISIBLE (page->child) && GTK_WIDGET_VISIBLE (notebook)) need_resize = TRUE; gtk_widget_unparent (page->child); if (page->tab_label) gtk_widget_unparent (page->tab_label); if (notebook->menu) { gtk_container_remove (GTK_CONTAINER (notebook->menu), page->menu_label->parent); gtk_widget_queue_resize (notebook->menu); } if (!page->default_menu) gtk_widget_unref (page->menu_label); notebook->children = g_list_remove_link (notebook->children, list); g_list_free (list); g_free (page); gtk_notebook_update_labels (notebook); if (need_resize) gtk_widget_queue_resize (GTK_WIDGET (notebook));}static voidgtk_notebook_update_labels (GtkNotebook *notebook){ GtkNotebookPage *page; GList *list; gchar string[32]; gint page_num = 1; for (list = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, FALSE); list; list = gtk_notebook_search_page (notebook, list, STEP_NEXT, FALSE)) { page = list->data; g_snprintf (string, sizeof(string), _("Page %u"), page_num++); if (notebook->show_tabs) { if (page->default_tab) { if (!page->tab_label) { page->tab_label = gtk_label_new (string); gtk_widget_set_parent (page->tab_label, GTK_WIDGET (notebook)); } else gtk_label_set_text (GTK_LABEL (page->tab_label), string); } if (GTK_WIDGET_VISIBLE (page->child) && !GTK_WIDGET_VISIBLE (page->tab_label)) gtk_widget_show (page->tab_label); else if (!GTK_WIDGET_VISIBLE (page->child) && GTK_WIDGET_VISIBLE (page->tab_label)) gtk_widget_hide (page->tab_label); } if (notebook->menu && page->default_menu) { if (page->tab_label && GTK_IS_LABEL (page->tab_label)) gtk_label_set_text (GTK_LABEL (page->menu_label), GTK_LABEL (page->tab_label)->label); else gtk_label_set_text (GTK_LABEL (page->menu_label), string); } } }static gintgtk_notebook_real_page_position (GtkNotebook *notebook, GList *list){ GList *work; gint count_start; g_return_val_if_fail (notebook != NULL, -1); g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), -1); g_return_val_if_fail (list != NULL, -1); for (work = notebook->children, count_start = 0; work && work != list; work = work->next) if (GTK_NOTEBOOK_PAGE (work)->pack == GTK_PACK_START) count_start++; if (!work) return -1; if (GTK_NOTEBOOK_PAGE (list)->pack == GTK_PACK_START) return count_start; return (count_start + g_list_length (list) - 1);}static GList *gtk_notebook_search_page (GtkNotebook *notebook, GList *list, gint direction, gboolean find_visible){ GtkNotebookPage *page = NULL; GList *old_list = NULL; gint flag = 0; g_return_val_if_fail (notebook != NULL, NULL); g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL); switch (direction) { case STEP_PREV: flag = GTK_PACK_END; break; case STEP_NEXT: flag = GTK_PACK_START; break; } if (list) page = list->data; if (!page || page->pack == flag) { if (list) { old_list = list; list = list->next; } else list = notebook->children; while (list) { page = list->data; if (page->pack == flag && (!find_visible || GTK_WIDGET_VISIBLE (page->child))) return list; old_list = list; list = list->next; } list = old_list; } else { old_list = list; list = list->prev; } while (list) { page = list->data; if (page->pack != flag && (!find_visible || GTK_WIDGET_VISIBLE (page->child))) return list; old_list = list; list = list->prev; } return NULL;}/* Private GtkNotebook Drawing Functions: * * gtk_notebook_paint * gtk_notebook_draw_tab * gtk_notebook_draw_arrow * gtk_notebook_set_shape */static voidgtk_notebook_paint (GtkWidget *widget, GdkRectangle *area){ GtkNotebook *notebook; GtkNotebookPage *page; GList *children; gboolean showarrow; gint width, height; gint x, y; gint gap_x = 0, gap_width = 0; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_NOTEBOOK (widget)); g_return_if_fail (area != NULL); if (!GTK_WIDGET_DRAWABLE (widget)) return; notebook = GTK_NOTEBOOK (widget); if ((!notebook->show_tabs && !notebook->show_border) || !notebook->cur_page || !GTK_WIDGET_VISIBLE (notebook->cur_page->child)) { gdk_window_clear_area (widget->window, area->x, area->y, area->width, area->height); return; } x = GTK_CONTAINER (widget)->border_width; y = GTK_CONTAINER (widget)->border_width; width = widget->allocation.width - x * 2; height = widget->allocation.height - y * 2; if (notebook->show_border && (!notebook->show_tabs || !notebook->children)) { gtk_paint_box (widget->style, widget->window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, area, widget, "notebook", x, y, width, height); return; } if (!GTK_WIDGET_MAPPED (notebook->cur_page->tab_label)) { page = notebook->first_tab->data; switch (notebook->tab_pos) { case GTK_POS_TOP: y += page->allocation.height + widget->style->klass->ythickness; case GTK_POS_BOTTOM: height -= page->allocation.height + widget->style->klass->ythickness; break; case GTK_POS_LEFT: x += page->allocation.width + widget->style->klass->xthickness; case GTK_POS_RIGHT: width -= page->allocation.width + widget->style->klass->xthickness; break; } gtk_paint_box (widget->style, widget->window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, area, widget, "notebook", x, y, width, height); } else { switch (notebook->tab_pos) { case GTK_POS_TOP: y += notebook->cur_page->allocation.height; case GTK_POS_BOTTOM: height -= notebook->cur_page->allocation.height; break; case GTK_POS_LEFT: x += notebook->cur_page->allocation.width; case GTK_POS_RIGHT: width -= notebook->cur_page->allocation.width; break; } switch (notebook->tab_pos) { case GTK_POS_TOP: gap_x = (notebook->cur_page->allocation.x - GTK_CONTAINER(notebook)->border_width); gap_width = notebook->cur_page->allocation.width; break; case GTK_POS_BOTTOM: gap_x = (notebook->cur_page->allocation.x - GTK_CONTAINER(notebook)->border_width); gap_width = notebook->cur_page->allocation.width; break; case GTK_POS_LEFT: gap_x = (notebook->cur_page->allocation.y - GTK_CONTAINER(notebook)->border_width); gap_width = notebook->cur_page->allocation.height; break; case GTK_POS_RIGHT: gap_x = (notebook->cur_page->allocation.y - GTK_CONTAINER(notebook)->border_width); gap_width = notebook->cur_page->allocation.height; break; } gtk_paint_box_gap(widget->style, widget->window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, area, widget, "notebook", x, y, width, height, notebook->tab_pos, gap_x, gap_width); } showarrow = FALSE; children = gtk_notebook_search_page (notebook, NULL, STEP_PREV, TRUE); while (childr
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -