Commit 10272ff6 authored by Andy Hertzfeld's avatar Andy Hertzfeld

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
parent d01ee0fa
2000-02-09 Andy Hertzfeld <andy@eazel.com>
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 <andy@eazel.com>
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 <darin@eazel.com>
......
......@@ -23,6 +23,7 @@
*
*/
#include <math.h>
#include <gdk/gdk.h>
#include <gtk/gtkwidget.h>
#include <gnome.h>
......@@ -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);
......
......@@ -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 */
......
......@@ -23,6 +23,7 @@
*
*/
#include <math.h>
#include <gdk/gdk.h>
#include <gtk/gtkwidget.h>
#include <gnome.h>
......@@ -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);
......
......@@ -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 */
......
......@@ -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 */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment