From 10272ff6fca86792b523ba17d62e9f79985f0940 Mon Sep 17 00:00:00 2001 From: Andy Hertzfeld Date: Thu, 10 Feb 2000 09:04:55 +0000 Subject: [PATCH] finished hit-testing and made it activate the appropriate metaview when finished hit-testing and made it activate the appropriate metaview when the corresponding tab is clicked --- ChangeLog-20000414 | 16 +++++++++--- src/nautilus-index-tabs.c | 42 +++++++++++++++++++++++--------- src/nautilus-information-panel.c | 28 +++++++++++++-------- src/nautilus-sidebar-tabs.c | 42 +++++++++++++++++++++++--------- src/nautilus-sidebar.c | 28 +++++++++++++-------- src/ntl-index-panel.c | 28 +++++++++++++-------- 6 files changed, 127 insertions(+), 57 deletions(-) diff --git a/ChangeLog-20000414 b/ChangeLog-20000414 index 81be36f54..548e7f47c 100644 --- a/ChangeLog-20000414 +++ b/ChangeLog-20000414 @@ -1,13 +1,23 @@ +2000-02-09 Andy Hertzfeld + + completed hit-testing and activation for the index tabs. They're + usable now, but I'm leaving them off until they're more refined + + * src/nautilus-index-tabs.c: + completed hit-testing + * src/ntl-index-panel.c: + activate the appropriate metaview when the corresponding tab is clicked + 2000-02-09 Andy Hertzfeld more work on the index panel, still conditionally disabled; change USE_NEW_TABS to a non-zero value if you want to check it out - src/nautilus-index-tabs.c,h: + * src/nautilus-index-tabs.c,h: improved positioning and started on hit-testing - src/ntl-index-panel.c: + * src/ntl-index-panel.c: made the notebook hidden by default and added hit-testing infrastructure - src/nautilus-zoom-control.c: + * src/nautilus-zoom-control.c: fixed incorrect comment 2000-02-09 Darin Adler diff --git a/src/nautilus-index-tabs.c b/src/nautilus-index-tabs.c index 1970b3397..09fe3a82f 100644 --- a/src/nautilus-index-tabs.c +++ b/src/nautilus-index-tabs.c @@ -23,6 +23,7 @@ * */ +#include #include #include #include @@ -63,6 +64,7 @@ static void nautilus_index_tabs_class_init (NautilusIndexTabsClass *klass); static void nautilus_index_tabs_init (NautilusIndexTabs *pixmap); static gint nautilus_index_tabs_expose (GtkWidget *widget, GdkEventExpose *event); static void nautilus_index_tabs_finalize (GtkObject *object); +static gint draw_or_hit_test_all_tabs(NautilusIndexTabs *index_tabs, gboolean draw_flag, gint test_x, gint test_y); /* static variables */ @@ -195,7 +197,7 @@ nautilus_index_tabs_finalize (GtkObject *object) gint nautilus_index_tabs_hit_test(NautilusIndexTabs *index_tabs, double x, double y) { - return 0; /* for now */ + return draw_or_hit_test_all_tabs(index_tabs, FALSE, floor(x + .5), floor(y + .5)); } /* resize the widget based on the number of tabs */ @@ -264,14 +266,15 @@ draw_one_tab(NautilusIndexTabs *index_tabs, GdkGC *gc, gchar *tab_name, gint x, /* draw the right bottom line */ } -/* draw all of the currently visible tabs */ +/* draw or hit test all of the currently visible tabs */ -static void -draw_all_tabs(NautilusIndexTabs *index_tabs) +static gint +draw_or_hit_test_all_tabs(NautilusIndexTabs *index_tabs, gboolean draw_flag, gint test_x, gint test_y) { + tabItem *second_item; GList *next_tab = index_tabs->details->tab_items; GtkWidget *widget = GTK_WIDGET(index_tabs); - GdkGC* temp_gc = gdk_gc_new(widget->window); + GdkGC* temp_gc = gdk_gc_new(widget->window); gint tab_height = tab_left_edge->art_pixbuf->height + 4; gint x_pos = widget->allocation.x - 3; gint y_pos = widget->allocation.y + widget->allocation.height - tab_left_edge->art_pixbuf->height; @@ -285,12 +288,24 @@ draw_all_tabs(NautilusIndexTabs *index_tabs) /* draw the second tab first, if there is one */ if (next_tab->next) { - tabItem *second_item = next_tab->next->data; - draw_one_tab(index_tabs, temp_gc, second_item->tab_text, x_pos, y_pos - 3, TRUE); + second_item = next_tab->next->data; + if (draw_flag) + draw_one_tab(index_tabs, temp_gc, second_item->tab_text, x_pos, y_pos - 3, TRUE); } - - draw_one_tab(index_tabs, temp_gc, this_item->tab_text, x_pos, y_pos, FALSE); - + + if (draw_flag) + draw_one_tab(index_tabs, temp_gc, this_item->tab_text, x_pos, y_pos, FALSE); + else if ((test_y >= y_pos) && (test_y <= (y_pos + tab_left_edge->art_pixbuf->height))) + { + gint name_width = gdk_string_width(tab_font, this_item->tab_text) - (2 * tab_indent); + gint edge_width = tab_left_edge->art_pixbuf->width + tab_right_edge->art_pixbuf->width; + + if (test_x < (name_width + edge_width)) + return this_item->notebook_page; + else if (next_tab->next) + return second_item->notebook_page; + } + next_tab = next_tab->next; if (next_tab) next_tab = next_tab->next; @@ -298,6 +313,7 @@ draw_all_tabs(NautilusIndexTabs *index_tabs) y_pos += tab_height; } gdk_gc_unref(temp_gc); + return -1; } /* find a tab with a given name, or return NULL if we can't find one */ @@ -331,7 +347,7 @@ nautilus_index_tabs_expose (GtkWidget *widget, GdkEventExpose *event) /* draw the tabs */ if (index_tabs->details->tab_count > 0) - draw_all_tabs(index_tabs); + draw_or_hit_test_all_tabs(index_tabs, TRUE, 0, 0); return FALSE; } @@ -346,7 +362,9 @@ nautilus_index_tabs_add_view(NautilusIndexTabs *index_tabs, const gchar *name, G tabItem *new_tab_item; GList *item = find_tab(index_tabs, name); if (item) - return FALSE; + return FALSE; + + printf("adding view, name %s, pagenum %d\n", name, page_num); /* allocate a new entry, and initialize it */ new_tab_item = g_new0 (tabItem, 1); diff --git a/src/nautilus-information-panel.c b/src/nautilus-information-panel.c index fdaff583b..e6a6429e1 100644 --- a/src/nautilus-information-panel.c +++ b/src/nautilus-information-panel.c @@ -42,7 +42,7 @@ struct _NautilusIndexPanelDetails { GtkWidget *index_container; GtkWidget *per_uri_container; - GtkWidget *meta_tabs; + GtkWidget *notebook; GtkWidget *index_tabs; char *uri; gint selected_index; @@ -150,14 +150,14 @@ nautilus_index_panel_initialize (GtkObject *object) /* allocate and install the meta-tabs */ - index_panel->details->meta_tabs = gtk_notebook_new (); - gtk_widget_set_usize (index_panel->details->meta_tabs, INDEX_PANEL_WIDTH, 200); + index_panel->details->notebook = gtk_notebook_new (); + gtk_widget_set_usize (index_panel->details->notebook, INDEX_PANEL_WIDTH, 200); if (USE_NEW_TABS) - gtk_notebook_set_show_tabs(GTK_NOTEBOOK(index_panel->details->meta_tabs), FALSE); + gtk_notebook_set_show_tabs(GTK_NOTEBOOK(index_panel->details->notebook), FALSE); else { - gtk_widget_show (index_panel->details->meta_tabs); - gtk_box_pack_end (GTK_BOX (index_panel->details->index_container), index_panel->details->meta_tabs, FALSE, FALSE, 0); + gtk_widget_show (index_panel->details->notebook); + gtk_box_pack_end (GTK_BOX (index_panel->details->index_container), index_panel->details->notebook, FALSE, FALSE, 0); } /* prepare ourselves to receive dropped objects */ @@ -254,8 +254,8 @@ nautilus_index_panel_add_meta_view (NautilusIndexPanel *index_panel, NautilusVie label = gtk_label_new (description); gtk_widget_show (label); - gtk_notebook_prepend_page (GTK_NOTEBOOK (index_panel->details->meta_tabs), GTK_WIDGET (meta_view), label); - page_num = gtk_notebook_page_num (GTK_NOTEBOOK (index_panel->details->meta_tabs), GTK_WIDGET (meta_view)); + gtk_notebook_append_page (GTK_NOTEBOOK (index_panel->details->notebook), GTK_WIDGET (meta_view), label); + page_num = gtk_notebook_page_num (GTK_NOTEBOOK (index_panel->details->notebook), GTK_WIDGET (meta_view)); /* tell the index tabs about it */ nautilus_index_tabs_add_view(NAUTILUS_INDEX_TABS(index_panel->details->index_tabs), @@ -270,15 +270,23 @@ nautilus_index_panel_remove_meta_view (NautilusIndexPanel *index_panel, Nautilus { gint page_num; - page_num = gtk_notebook_page_num (GTK_NOTEBOOK (index_panel->details->meta_tabs), GTK_WIDGET (meta_view)); + page_num = gtk_notebook_page_num (GTK_NOTEBOOK (index_panel->details->notebook), GTK_WIDGET (meta_view)); g_return_if_fail (page_num >= 0); - gtk_notebook_remove_page (GTK_NOTEBOOK (index_panel->details->meta_tabs), page_num); + gtk_notebook_remove_page (GTK_NOTEBOOK (index_panel->details->notebook), page_num); } /* utility to activate the metaview corresponding to the passed in index */ static void nautilus_index_panel_activate_meta_view(NautilusIndexPanel *index_panel, gint which_view) { + GtkNotebook *notebook = GTK_NOTEBOOK(index_panel->details->notebook); + if (index_panel->details->selected_index < 0) + { + gtk_widget_show (index_panel->details->notebook); + gtk_box_pack_end (GTK_BOX (index_panel->details->index_container), index_panel->details->notebook, FALSE, FALSE, 0); + } + index_panel->details->selected_index = which_view; + gtk_notebook_set_page(notebook, which_view); } /* hit-test the index tabs and activate if necessary */ diff --git a/src/nautilus-sidebar-tabs.c b/src/nautilus-sidebar-tabs.c index 1970b3397..09fe3a82f 100644 --- a/src/nautilus-sidebar-tabs.c +++ b/src/nautilus-sidebar-tabs.c @@ -23,6 +23,7 @@ * */ +#include #include #include #include @@ -63,6 +64,7 @@ static void nautilus_index_tabs_class_init (NautilusIndexTabsClass *klass); static void nautilus_index_tabs_init (NautilusIndexTabs *pixmap); static gint nautilus_index_tabs_expose (GtkWidget *widget, GdkEventExpose *event); static void nautilus_index_tabs_finalize (GtkObject *object); +static gint draw_or_hit_test_all_tabs(NautilusIndexTabs *index_tabs, gboolean draw_flag, gint test_x, gint test_y); /* static variables */ @@ -195,7 +197,7 @@ nautilus_index_tabs_finalize (GtkObject *object) gint nautilus_index_tabs_hit_test(NautilusIndexTabs *index_tabs, double x, double y) { - return 0; /* for now */ + return draw_or_hit_test_all_tabs(index_tabs, FALSE, floor(x + .5), floor(y + .5)); } /* resize the widget based on the number of tabs */ @@ -264,14 +266,15 @@ draw_one_tab(NautilusIndexTabs *index_tabs, GdkGC *gc, gchar *tab_name, gint x, /* draw the right bottom line */ } -/* draw all of the currently visible tabs */ +/* draw or hit test all of the currently visible tabs */ -static void -draw_all_tabs(NautilusIndexTabs *index_tabs) +static gint +draw_or_hit_test_all_tabs(NautilusIndexTabs *index_tabs, gboolean draw_flag, gint test_x, gint test_y) { + tabItem *second_item; GList *next_tab = index_tabs->details->tab_items; GtkWidget *widget = GTK_WIDGET(index_tabs); - GdkGC* temp_gc = gdk_gc_new(widget->window); + GdkGC* temp_gc = gdk_gc_new(widget->window); gint tab_height = tab_left_edge->art_pixbuf->height + 4; gint x_pos = widget->allocation.x - 3; gint y_pos = widget->allocation.y + widget->allocation.height - tab_left_edge->art_pixbuf->height; @@ -285,12 +288,24 @@ draw_all_tabs(NautilusIndexTabs *index_tabs) /* draw the second tab first, if there is one */ if (next_tab->next) { - tabItem *second_item = next_tab->next->data; - draw_one_tab(index_tabs, temp_gc, second_item->tab_text, x_pos, y_pos - 3, TRUE); + second_item = next_tab->next->data; + if (draw_flag) + draw_one_tab(index_tabs, temp_gc, second_item->tab_text, x_pos, y_pos - 3, TRUE); } - - draw_one_tab(index_tabs, temp_gc, this_item->tab_text, x_pos, y_pos, FALSE); - + + if (draw_flag) + draw_one_tab(index_tabs, temp_gc, this_item->tab_text, x_pos, y_pos, FALSE); + else if ((test_y >= y_pos) && (test_y <= (y_pos + tab_left_edge->art_pixbuf->height))) + { + gint name_width = gdk_string_width(tab_font, this_item->tab_text) - (2 * tab_indent); + gint edge_width = tab_left_edge->art_pixbuf->width + tab_right_edge->art_pixbuf->width; + + if (test_x < (name_width + edge_width)) + return this_item->notebook_page; + else if (next_tab->next) + return second_item->notebook_page; + } + next_tab = next_tab->next; if (next_tab) next_tab = next_tab->next; @@ -298,6 +313,7 @@ draw_all_tabs(NautilusIndexTabs *index_tabs) y_pos += tab_height; } gdk_gc_unref(temp_gc); + return -1; } /* find a tab with a given name, or return NULL if we can't find one */ @@ -331,7 +347,7 @@ nautilus_index_tabs_expose (GtkWidget *widget, GdkEventExpose *event) /* draw the tabs */ if (index_tabs->details->tab_count > 0) - draw_all_tabs(index_tabs); + draw_or_hit_test_all_tabs(index_tabs, TRUE, 0, 0); return FALSE; } @@ -346,7 +362,9 @@ nautilus_index_tabs_add_view(NautilusIndexTabs *index_tabs, const gchar *name, G tabItem *new_tab_item; GList *item = find_tab(index_tabs, name); if (item) - return FALSE; + return FALSE; + + printf("adding view, name %s, pagenum %d\n", name, page_num); /* allocate a new entry, and initialize it */ new_tab_item = g_new0 (tabItem, 1); diff --git a/src/nautilus-sidebar.c b/src/nautilus-sidebar.c index fdaff583b..e6a6429e1 100644 --- a/src/nautilus-sidebar.c +++ b/src/nautilus-sidebar.c @@ -42,7 +42,7 @@ struct _NautilusIndexPanelDetails { GtkWidget *index_container; GtkWidget *per_uri_container; - GtkWidget *meta_tabs; + GtkWidget *notebook; GtkWidget *index_tabs; char *uri; gint selected_index; @@ -150,14 +150,14 @@ nautilus_index_panel_initialize (GtkObject *object) /* allocate and install the meta-tabs */ - index_panel->details->meta_tabs = gtk_notebook_new (); - gtk_widget_set_usize (index_panel->details->meta_tabs, INDEX_PANEL_WIDTH, 200); + index_panel->details->notebook = gtk_notebook_new (); + gtk_widget_set_usize (index_panel->details->notebook, INDEX_PANEL_WIDTH, 200); if (USE_NEW_TABS) - gtk_notebook_set_show_tabs(GTK_NOTEBOOK(index_panel->details->meta_tabs), FALSE); + gtk_notebook_set_show_tabs(GTK_NOTEBOOK(index_panel->details->notebook), FALSE); else { - gtk_widget_show (index_panel->details->meta_tabs); - gtk_box_pack_end (GTK_BOX (index_panel->details->index_container), index_panel->details->meta_tabs, FALSE, FALSE, 0); + gtk_widget_show (index_panel->details->notebook); + gtk_box_pack_end (GTK_BOX (index_panel->details->index_container), index_panel->details->notebook, FALSE, FALSE, 0); } /* prepare ourselves to receive dropped objects */ @@ -254,8 +254,8 @@ nautilus_index_panel_add_meta_view (NautilusIndexPanel *index_panel, NautilusVie label = gtk_label_new (description); gtk_widget_show (label); - gtk_notebook_prepend_page (GTK_NOTEBOOK (index_panel->details->meta_tabs), GTK_WIDGET (meta_view), label); - page_num = gtk_notebook_page_num (GTK_NOTEBOOK (index_panel->details->meta_tabs), GTK_WIDGET (meta_view)); + gtk_notebook_append_page (GTK_NOTEBOOK (index_panel->details->notebook), GTK_WIDGET (meta_view), label); + page_num = gtk_notebook_page_num (GTK_NOTEBOOK (index_panel->details->notebook), GTK_WIDGET (meta_view)); /* tell the index tabs about it */ nautilus_index_tabs_add_view(NAUTILUS_INDEX_TABS(index_panel->details->index_tabs), @@ -270,15 +270,23 @@ nautilus_index_panel_remove_meta_view (NautilusIndexPanel *index_panel, Nautilus { gint page_num; - page_num = gtk_notebook_page_num (GTK_NOTEBOOK (index_panel->details->meta_tabs), GTK_WIDGET (meta_view)); + page_num = gtk_notebook_page_num (GTK_NOTEBOOK (index_panel->details->notebook), GTK_WIDGET (meta_view)); g_return_if_fail (page_num >= 0); - gtk_notebook_remove_page (GTK_NOTEBOOK (index_panel->details->meta_tabs), page_num); + gtk_notebook_remove_page (GTK_NOTEBOOK (index_panel->details->notebook), page_num); } /* utility to activate the metaview corresponding to the passed in index */ static void nautilus_index_panel_activate_meta_view(NautilusIndexPanel *index_panel, gint which_view) { + GtkNotebook *notebook = GTK_NOTEBOOK(index_panel->details->notebook); + if (index_panel->details->selected_index < 0) + { + gtk_widget_show (index_panel->details->notebook); + gtk_box_pack_end (GTK_BOX (index_panel->details->index_container), index_panel->details->notebook, FALSE, FALSE, 0); + } + index_panel->details->selected_index = which_view; + gtk_notebook_set_page(notebook, which_view); } /* hit-test the index tabs and activate if necessary */ diff --git a/src/ntl-index-panel.c b/src/ntl-index-panel.c index fdaff583b..e6a6429e1 100644 --- a/src/ntl-index-panel.c +++ b/src/ntl-index-panel.c @@ -42,7 +42,7 @@ struct _NautilusIndexPanelDetails { GtkWidget *index_container; GtkWidget *per_uri_container; - GtkWidget *meta_tabs; + GtkWidget *notebook; GtkWidget *index_tabs; char *uri; gint selected_index; @@ -150,14 +150,14 @@ nautilus_index_panel_initialize (GtkObject *object) /* allocate and install the meta-tabs */ - index_panel->details->meta_tabs = gtk_notebook_new (); - gtk_widget_set_usize (index_panel->details->meta_tabs, INDEX_PANEL_WIDTH, 200); + index_panel->details->notebook = gtk_notebook_new (); + gtk_widget_set_usize (index_panel->details->notebook, INDEX_PANEL_WIDTH, 200); if (USE_NEW_TABS) - gtk_notebook_set_show_tabs(GTK_NOTEBOOK(index_panel->details->meta_tabs), FALSE); + gtk_notebook_set_show_tabs(GTK_NOTEBOOK(index_panel->details->notebook), FALSE); else { - gtk_widget_show (index_panel->details->meta_tabs); - gtk_box_pack_end (GTK_BOX (index_panel->details->index_container), index_panel->details->meta_tabs, FALSE, FALSE, 0); + gtk_widget_show (index_panel->details->notebook); + gtk_box_pack_end (GTK_BOX (index_panel->details->index_container), index_panel->details->notebook, FALSE, FALSE, 0); } /* prepare ourselves to receive dropped objects */ @@ -254,8 +254,8 @@ nautilus_index_panel_add_meta_view (NautilusIndexPanel *index_panel, NautilusVie label = gtk_label_new (description); gtk_widget_show (label); - gtk_notebook_prepend_page (GTK_NOTEBOOK (index_panel->details->meta_tabs), GTK_WIDGET (meta_view), label); - page_num = gtk_notebook_page_num (GTK_NOTEBOOK (index_panel->details->meta_tabs), GTK_WIDGET (meta_view)); + gtk_notebook_append_page (GTK_NOTEBOOK (index_panel->details->notebook), GTK_WIDGET (meta_view), label); + page_num = gtk_notebook_page_num (GTK_NOTEBOOK (index_panel->details->notebook), GTK_WIDGET (meta_view)); /* tell the index tabs about it */ nautilus_index_tabs_add_view(NAUTILUS_INDEX_TABS(index_panel->details->index_tabs), @@ -270,15 +270,23 @@ nautilus_index_panel_remove_meta_view (NautilusIndexPanel *index_panel, Nautilus { gint page_num; - page_num = gtk_notebook_page_num (GTK_NOTEBOOK (index_panel->details->meta_tabs), GTK_WIDGET (meta_view)); + page_num = gtk_notebook_page_num (GTK_NOTEBOOK (index_panel->details->notebook), GTK_WIDGET (meta_view)); g_return_if_fail (page_num >= 0); - gtk_notebook_remove_page (GTK_NOTEBOOK (index_panel->details->meta_tabs), page_num); + gtk_notebook_remove_page (GTK_NOTEBOOK (index_panel->details->notebook), page_num); } /* utility to activate the metaview corresponding to the passed in index */ static void nautilus_index_panel_activate_meta_view(NautilusIndexPanel *index_panel, gint which_view) { + GtkNotebook *notebook = GTK_NOTEBOOK(index_panel->details->notebook); + if (index_panel->details->selected_index < 0) + { + gtk_widget_show (index_panel->details->notebook); + gtk_box_pack_end (GTK_BOX (index_panel->details->index_container), index_panel->details->notebook, FALSE, FALSE, 0); + } + index_panel->details->selected_index = which_view; + gtk_notebook_set_page(notebook, which_view); } /* hit-test the index tabs and activate if necessary */ -- GitLab