summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@src.gnome.org>1998-03-24 01:43:21 +0000
committerOwen Taylor <otaylor@src.gnome.org>1998-03-24 01:43:21 +0000
commit34e324ca708cd83b03e3d526f9defbe2e0f1d90c (patch)
tree47291ccec103012539f7e2a145d553d0f1e9723a /gtk
parent7bd32a06cf0e5ad85445f5d7dfbe6db88caa9331 (diff)
downloadgtk+-34e324ca708cd83b03e3d526f9defbe2e0f1d90c.tar.gz
/home/otaylor/commit
Diffstat (limited to 'gtk')
-rw-r--r--gtk/gtkbutton.c20
-rw-r--r--gtk/gtkclist.c16
-rw-r--r--gtk/gtkeventbox.c20
-rw-r--r--gtk/gtkfilesel.c2
-rw-r--r--gtk/gtklist.c8
-rw-r--r--gtk/gtkmenu.c42
-rw-r--r--gtk/gtkmenushell.c49
-rw-r--r--gtk/gtktext.c1
-rw-r--r--gtk/gtktree.c5
-rw-r--r--gtk/gtkviewport.c29
10 files changed, 140 insertions, 52 deletions
diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c
index ea303e0962..5de521d733 100644
--- a/gtk/gtkbutton.c
+++ b/gtk/gtkbutton.c
@@ -324,6 +324,7 @@ gtk_button_realize (GtkWidget *widget)
GtkButton *button;
GdkWindowAttr attributes;
gint attributes_mask;
+ gint border_width;
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_BUTTON (widget));
@@ -331,11 +332,13 @@ gtk_button_realize (GtkWidget *widget)
button = GTK_BUTTON (widget);
GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
+ border_width = GTK_CONTAINER (widget)->border_width;
+
attributes.window_type = GDK_WINDOW_CHILD;
- attributes.x = widget->allocation.x;
- attributes.y = widget->allocation.y;
- attributes.width = widget->allocation.width;
- attributes.height = widget->allocation.height;
+ attributes.x = widget->allocation.x + border_width;
+ attributes.y = widget->allocation.y + border_width;
+ attributes.width = widget->allocation.width - border_width * 2;
+ attributes.height = widget->allocation.height - border_width * 2;
attributes.wclass = GDK_INPUT_OUTPUT;
attributes.visual = gtk_widget_get_visual (widget);
attributes.colormap = gtk_widget_get_colormap (widget);
@@ -482,6 +485,7 @@ gtk_button_draw (GtkWidget *widget,
{
GtkButton *button;
GdkRectangle child_area;
+ GdkRectangle tmp_area;
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_BUTTON (widget));
@@ -491,9 +495,13 @@ gtk_button_draw (GtkWidget *widget,
{
button = GTK_BUTTON (widget);
- gtk_button_paint (widget, area);
+ tmp_area = *area;
+ tmp_area.x -= GTK_CONTAINER (button)->border_width;
+ tmp_area.y -= GTK_CONTAINER (button)->border_width;
+
+ gtk_button_paint (widget, &tmp_area);
- if (button->child && gtk_widget_intersect (button->child, area, &child_area))
+ if (button->child && gtk_widget_intersect (button->child, &tmp_area, &child_area))
gtk_widget_draw (button->child, &child_area);
gtk_widget_draw_default (widget);
diff --git a/gtk/gtkclist.c b/gtk/gtkclist.c
index 64f8f8322b..bfef6fc743 100644
--- a/gtk/gtkclist.c
+++ b/gtk/gtkclist.c
@@ -1729,6 +1729,7 @@ gtk_clist_realize (GtkWidget * widget)
GdkWindowAttr attributes;
gint attributes_mask;
GdkGCValues values;
+ gint border_width;
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_CLIST (widget));
@@ -1737,11 +1738,13 @@ gtk_clist_realize (GtkWidget * widget)
GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
+ border_width = GTK_CONTAINER (widget)->border_width;
+
attributes.window_type = GDK_WINDOW_CHILD;
- attributes.x = widget->allocation.x;
- attributes.y = widget->allocation.y;
- attributes.width = widget->allocation.width;
- attributes.height = widget->allocation.height;
+ attributes.x = widget->allocation.x + border_width;
+ attributes.y = widget->allocation.y + border_width;
+ attributes.width = widget->allocation.width - border_width * 2;
+ attributes.height = widget->allocation.height - border_width * 2;
attributes.wclass = GDK_INPUT_OUTPUT;
attributes.visual = gtk_widget_get_visual (widget);
attributes.colormap = gtk_widget_get_colormap (widget);
@@ -1951,6 +1954,7 @@ gtk_clist_draw (GtkWidget * widget,
GdkRectangle * area)
{
GtkCList *clist;
+ gint border_width;
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_CLIST (widget));
@@ -1959,9 +1963,11 @@ gtk_clist_draw (GtkWidget * widget,
if (GTK_WIDGET_DRAWABLE (widget))
{
clist = GTK_CLIST (widget);
+ border_width = GTK_CONTAINER (widget)->border_width;
gdk_window_clear_area (widget->window,
- area->x, area->y,
+ area->x - border_width,
+ area->y - border_width,
area->width, area->height);
/* draw list shadow/border */
diff --git a/gtk/gtkeventbox.c b/gtk/gtkeventbox.c
index ac9d8746da..b18e1646ae 100644
--- a/gtk/gtkeventbox.c
+++ b/gtk/gtkeventbox.c
@@ -88,16 +88,19 @@ gtk_event_box_realize (GtkWidget *widget)
{
GdkWindowAttr attributes;
gint attributes_mask;
+ gint border_width;
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_EVENT_BOX (widget));
GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
- attributes.x = widget->allocation.x;
- attributes.y = widget->allocation.y;
- attributes.width = widget->allocation.width;
- attributes.height = widget->allocation.height;
+ border_width = GTK_CONTAINER (widget)->border_width;
+
+ attributes.x = widget->allocation.x + border_width;
+ attributes.y = widget->allocation.y + border_width;
+ attributes.width = widget->allocation.width - 2*border_width;
+ attributes.height = widget->allocation.height - 2*border_width;
attributes.window_type = GDK_WINDOW_CHILD;
attributes.wclass = GDK_INPUT_OUTPUT;
attributes.visual = gtk_widget_get_visual (widget);
@@ -182,19 +185,22 @@ gtk_event_box_draw (GtkWidget *widget,
GdkRectangle *area)
{
GtkBin *bin;
+ GdkRectangle tmp_area;
GdkRectangle child_area;
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_EVENT_BOX (widget));
- g_return_if_fail (area != NULL);
if (GTK_WIDGET_DRAWABLE (widget))
{
bin = GTK_BIN (widget);
-
+ tmp_area = *area;
+ tmp_area.x -= GTK_CONTAINER (widget)->border_width;
+ tmp_area.y -= GTK_CONTAINER (widget)->border_width;
+
if (bin->child)
{
- if (gtk_widget_intersect (bin->child, area, &child_area))
+ if (gtk_widget_intersect (bin->child, &tmp_area, &child_area))
gtk_widget_draw (bin->child, &child_area);
}
}
diff --git a/gtk/gtkfilesel.c b/gtk/gtkfilesel.c
index 871f988d01..1328f7e980 100644
--- a/gtk/gtkfilesel.c
+++ b/gtk/gtkfilesel.c
@@ -1278,7 +1278,7 @@ gtk_file_selection_populate (GtkFileSelection *fs,
{
possible_count += 1;
- filename = g_strdup (cmpl_this_completion (poss));
+ filename = cmpl_this_completion (poss);
text[0] = filename;
diff --git a/gtk/gtklist.c b/gtk/gtklist.c
index 063041c60d..ead9f98a97 100644
--- a/gtk/gtklist.c
+++ b/gtk/gtklist.c
@@ -698,12 +698,12 @@ gtk_list_button_press (GtkWidget *widget,
list = GTK_LIST (widget);
item = gtk_get_event_widget ((GdkEvent*) event);
- if (!item)
- return FALSE;
-
- while (!gtk_type_is_a (GTK_WIDGET_TYPE (item), gtk_list_item_get_type ()))
+ while (item && !GTK_IS_LIST_ITEM (item))
item = item->parent;
+ if (!item || (item->parent != widget))
+ return FALSE;
+
gtk_list_select_child (list, item);
return FALSE;
diff --git a/gtk/gtkmenu.c b/gtk/gtkmenu.c
index 2e2e098223..12a804ec8b 100644
--- a/gtk/gtkmenu.c
+++ b/gtk/gtkmenu.c
@@ -279,6 +279,9 @@ gtk_menu_popup (GtkMenu *menu,
guint button,
guint32 activate_time)
{
+ GtkWidget *xgrab_shell;
+ GtkWidget *parent;
+
g_return_if_fail (menu != NULL);
g_return_if_fail (GTK_IS_MENU (menu));
@@ -292,6 +295,41 @@ gtk_menu_popup (GtkMenu *menu,
GTK_MENU_SHELL (menu)->activate_time = activate_time;
gtk_widget_show (GTK_WIDGET (menu));
+
+ /* Find the last viewable ancestor, and make an X grab on it
+ */
+ parent = GTK_WIDGET (menu);
+ xgrab_shell = NULL;
+ while (parent)
+ {
+ gboolean viewable = TRUE;
+ GtkWidget *tmp = parent;
+
+ while (tmp)
+ {
+ if (!GTK_WIDGET_MAPPED (tmp))
+ {
+ viewable = FALSE;
+ break;
+ }
+ tmp = tmp->parent;
+ }
+
+ if (viewable)
+ xgrab_shell = parent;
+
+ parent = GTK_MENU_SHELL (parent)->parent_menu_shell;
+ }
+
+ if (xgrab_shell && (!GTK_MENU_SHELL (xgrab_shell)->have_xgrab))
+ {
+ GTK_MENU_SHELL (xgrab_shell)->have_xgrab =
+ (gdk_pointer_grab (xgrab_shell->window, TRUE,
+ GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
+ GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK,
+ NULL, NULL, activate_time) == 0);
+ }
+
gtk_grab_add (GTK_WIDGET (menu));
}
@@ -315,7 +353,11 @@ gtk_menu_popdown (GtkMenu *menu)
menu_shell->active_menu_item = NULL;
}
+ /* The X Grab, if present, will automatically be removed when we hide
+ * the window */
gtk_widget_hide (GTK_WIDGET (menu));
+ menu_shell->have_xgrab = FALSE;
+
gtk_grab_remove (GTK_WIDGET (menu));
}
diff --git a/gtk/gtkmenushell.c b/gtk/gtkmenushell.c
index eb9d731d90..7fd467ff95 100644
--- a/gtk/gtkmenushell.c
+++ b/gtk/gtkmenushell.c
@@ -53,6 +53,8 @@ static void gtk_menu_shell_foreach (GtkContainer *container,
static void gtk_real_menu_shell_deactivate (GtkMenuShell *menu_shell);
static gint gtk_menu_shell_is_item (GtkMenuShell *menu_shell,
GtkWidget *child);
+static GtkWidget *gtk_menu_shell_get_item (GtkMenuShell *menu_shell,
+ GdkEvent *event);
static GtkContainerClass *parent_class = NULL;
@@ -302,14 +304,11 @@ gtk_menu_shell_button_press (GtkWidget *widget,
menu_shell->active = TRUE;
}
menu_shell->button = event->button;
-
- menu_item = gtk_get_event_widget ((GdkEvent*) event);
- if (!GTK_WIDGET_IS_SENSITIVE (menu_item))
- return TRUE;
+ menu_item = gtk_menu_shell_get_item (menu_shell, (GdkEvent *)event);
- if (menu_item && GTK_IS_MENU_ITEM (menu_item) &&
- gtk_menu_shell_is_item (menu_shell, menu_item))
+ if (menu_item &&
+ GTK_WIDGET_IS_SENSITIVE (menu_item))
{
if ((menu_item->parent == widget) &&
(menu_item != menu_shell->active_menu_item))
@@ -358,16 +357,13 @@ gtk_menu_shell_button_release (GtkWidget *widget,
}
menu_shell->button = 0;
- menu_item = gtk_get_event_widget ((GdkEvent*) event);
-
- if (!GTK_WIDGET_IS_SENSITIVE (menu_item))
- return TRUE;
+ menu_item = gtk_menu_shell_get_item (menu_shell, (GdkEvent*) event);
deactivate = TRUE;
if ((event->time - menu_shell->activate_time) > MENU_SHELL_TIMEOUT)
{
- if (menu_shell->active_menu_item == menu_item)
+ if (menu_item && (menu_shell->active_menu_item == menu_item))
{
if (GTK_MENU_ITEM (menu_item)->submenu == NULL)
{
@@ -385,15 +381,14 @@ gtk_menu_shell_button_release (GtkWidget *widget,
}
else
deactivate = FALSE;
-
- if ((!deactivate || (menu_shell->active_menu_item == menu_item)) &&
- (gdk_pointer_grab (widget->window, TRUE,
- GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
- GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK,
- NULL, NULL, event->time) == 0))
+
+ /* If the button click was very fast, or we ended up on a submenu,
+ * leave the menu up
+ */
+ if (!deactivate ||
+ (menu_item && (menu_shell->active_menu_item == menu_item)))
{
deactivate = FALSE;
- menu_shell->have_xgrab = TRUE;
menu_shell->ignore_leave = TRUE;
}
else
@@ -607,3 +602,21 @@ gtk_menu_shell_is_item (GtkMenuShell *menu_shell,
return FALSE;
}
+
+static GtkWidget *
+gtk_menu_shell_get_item (GtkMenuShell *menu_shell,
+ GdkEvent *event)
+{
+ GtkWidget *menu_item;
+
+ menu_item = gtk_get_event_widget ((GdkEvent*) event);
+
+ while (menu_item && !GTK_IS_MENU_ITEM (menu_item))
+ menu_item = menu_item->parent;
+
+ if (menu_item && gtk_menu_shell_is_item (menu_shell, menu_item))
+ return menu_item;
+ else
+ return NULL;
+}
+
diff --git a/gtk/gtktext.c b/gtk/gtktext.c
index e7ff57e129..5b77794e0a 100644
--- a/gtk/gtktext.c
+++ b/gtk/gtktext.c
@@ -497,6 +497,7 @@ gtk_text_init (GtkText *text)
text->tab_stops = g_list_prepend (text->tab_stops, (void*)8);
text->line_wrap = TRUE;
+ text->word_wrap = FALSE;
text->timer = 0;
text->button = 0;
diff --git a/gtk/gtktree.c b/gtk/gtktree.c
index b501486ad0..f4c9e78608 100644
--- a/gtk/gtktree.c
+++ b/gtk/gtktree.c
@@ -299,9 +299,12 @@ gtk_tree_button_press (GtkWidget *widget,
tree = GTK_TREE (widget);
item = gtk_get_event_widget ((GdkEvent*) event);
- while (!gtk_type_is_a (GTK_WIDGET_TYPE (item), gtk_tree_item_get_type ()))
+ while (item && !GTK_IS_TREE_ITEM (item))
item = item->parent;
+ if (!item || (item->parent != widget))
+ return FALSE;
+
switch(event->button)
{
case 1:
diff --git a/gtk/gtkviewport.c b/gtk/gtkviewport.c
index 08e5d27a28..ed8c202b2f 100644
--- a/gtk/gtkviewport.c
+++ b/gtk/gtkviewport.c
@@ -391,6 +391,7 @@ gtk_viewport_draw (GtkWidget *widget,
GtkBin *bin;
GdkRectangle tmp_area;
GdkRectangle child_area;
+ gint border_width;
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_VIEWPORT (widget));
@@ -401,13 +402,18 @@ gtk_viewport_draw (GtkWidget *widget,
viewport = GTK_VIEWPORT (widget);
bin = GTK_BIN (widget);
- gtk_viewport_paint (widget, area);
+ border_width = GTK_CONTAINER (widget)->border_width;
+
+ tmp_area = *area;
+ tmp_area.x -= border_width;
+ tmp_area.y -= border_width;
+
+ gtk_viewport_paint (widget, &tmp_area);
if (bin->child)
{
- tmp_area = *area;
- tmp_area.x += viewport->hadjustment->value;
- tmp_area.y += viewport->vadjustment->value;
+ tmp_area.x += viewport->hadjustment->value - widget->style->klass->xthickness;
+ tmp_area.y += viewport->vadjustment->value - widget->style->klass->ythickness;
if (gtk_widget_intersect (bin->child, &tmp_area, &child_area))
gtk_widget_draw (bin->child, &child_area);
@@ -508,6 +514,7 @@ gtk_viewport_size_allocate (GtkWidget *widget,
GtkBin *bin;
GtkAllocation child_allocation;
gint hval, vval;
+ gint border_width;
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_VIEWPORT (widget));
@@ -517,6 +524,8 @@ gtk_viewport_size_allocate (GtkWidget *widget,
viewport = GTK_VIEWPORT (widget);
bin = GTK_BIN (widget);
+ border_width = GTK_CONTAINER (widget)->border_width;
+
child_allocation.x = 0;
child_allocation.y = 0;
@@ -526,16 +535,16 @@ gtk_viewport_size_allocate (GtkWidget *widget,
child_allocation.y = GTK_WIDGET (viewport)->style->klass->ythickness;
}
- child_allocation.width = allocation->width - child_allocation.x * 2;
- child_allocation.height = allocation->height - child_allocation.y * 2;
+ child_allocation.width = allocation->width - child_allocation.x * 2 - border_width * 2;
+ child_allocation.height = allocation->height - child_allocation.y * 2 - border_width * 2;
if (GTK_WIDGET_REALIZED (widget))
{
gdk_window_move_resize (widget->window,
- allocation->x + GTK_CONTAINER (viewport)->border_width,
- allocation->y + GTK_CONTAINER (viewport)->border_width,
- allocation->width - GTK_CONTAINER (viewport)->border_width * 2,
- allocation->height - GTK_CONTAINER (viewport)->border_width * 2);
+ allocation->x + border_width,
+ allocation->y + border_width,
+ allocation->width - border_width * 2,
+ allocation->height - border_width * 2);
gdk_window_move_resize (viewport->view_window,
child_allocation.x,