popover: Add private _gtk_popover_set_apply_shape() call

Popovers no longer sets a shape, unless this function is called. This
function exists so widgets that are potentially placed on top of other
native windows can get a popover that's nicely shaped, even if it has
no border shadow around.

https://bugzilla.gnome.org/show_bug.cgi?id=723556
This commit is contained in:
Carlos Garnacho 2014-02-04 20:45:53 +01:00
parent 0493d74650
commit 2d9c09d6c0
3 changed files with 67 additions and 39 deletions

View File

@ -505,6 +505,7 @@ gtk_private_h_sources = \
gtkorientableprivate.h \ gtkorientableprivate.h \
gtkpango.h \ gtkpango.h \
gtkpathbar.h \ gtkpathbar.h \
gtkpopoverprivate.h \
gtkpressandholdprivate.h \ gtkpressandholdprivate.h \
gtkprintoperation-private.h \ gtkprintoperation-private.h \
gtkprintutils.h \ gtkprintutils.h \

View File

@ -85,6 +85,7 @@ struct _GtkPopoverPrivate
guint current_position : 2; guint current_position : 2;
guint modal : 1; guint modal : 1;
guint button_pressed : 1; guint button_pressed : 1;
guint apply_shape : 1;
}; };
static GQuark quark_widget_popovers = 0; static GQuark quark_widget_popovers = 0;
@ -524,6 +525,7 @@ gtk_popover_apply_tail_path (GtkPopover *popover,
gint tip_x, tip_y; gint tip_x, tip_y;
gint final_x, final_y; gint final_x, final_y;
cairo_set_line_width (cr, 1);
gtk_popover_get_gap_coords (popover, gtk_popover_get_gap_coords (popover,
&initial_x, &initial_y, &initial_x, &initial_y,
&tip_x, &tip_y, &tip_x, &tip_y,
@ -536,49 +538,23 @@ gtk_popover_apply_tail_path (GtkPopover *popover,
} }
static void static void
gtk_popover_apply_border_path (GtkPopover *popover, gtk_popover_fill_border_path (GtkPopover *popover,
cairo_t *cr) cairo_t *cr)
{ {
GtkPopoverPrivate *priv;
GtkAllocation allocation; GtkAllocation allocation;
GtkStyleContext *context;
gint x1, y1, x2, y2; gint x1, y1, x2, y2;
priv = popover->priv; context = gtk_widget_get_style_context (GTK_WIDGET (popover));
gtk_widget_get_allocation (GTK_WIDGET (popover), &allocation); gtk_widget_get_allocation (GTK_WIDGET (popover), &allocation);
gtk_popover_apply_tail_path (popover, cr); gtk_popover_apply_tail_path (popover, cr);
gtk_popover_get_rect_coords (popover, &x1, &y1, &x2, &y2);
if (priv->final_position == GTK_POS_TOP)
{
cairo_line_to (cr, x2, y2);
cairo_line_to (cr, x2, y1);
cairo_line_to (cr, x1, y1);
cairo_line_to (cr, x1, y2);
}
else if (priv->final_position == GTK_POS_BOTTOM)
{
cairo_line_to (cr, x2, y1);
cairo_line_to (cr, x2, y2);
cairo_line_to (cr, x1, y2);
cairo_line_to (cr, x1, y1);
}
else if (priv->final_position == GTK_POS_LEFT)
{
cairo_line_to (cr, x2, y2);
cairo_line_to (cr, x1, y2);
cairo_line_to (cr, x1, y1);
cairo_line_to (cr, x2, y1);
}
else if (priv->final_position == GTK_POS_RIGHT)
{
cairo_line_to (cr, x1, y1);
cairo_line_to (cr, x2, y1);
cairo_line_to (cr, x2, y2);
cairo_line_to (cr, x1, y2);
}
cairo_close_path (cr); cairo_close_path (cr);
cairo_fill (cr);
gtk_popover_get_rect_coords (popover, &x1, &y1, &x2, &y2);
gtk_render_frame (context, cr, x1, y1, x2 - x1, y2 - y1);
gtk_render_background (context, cr, x1, y1, x2 - x1, y2 - y1);
} }
static void static void
@ -597,8 +573,7 @@ gtk_popover_update_shape (GtkPopover *popover)
gdk_window_get_height (win)); gdk_window_get_height (win));
cr = cairo_create (surface); cr = cairo_create (surface);
gtk_popover_apply_border_path (popover, cr); gtk_popover_fill_border_path (popover, cr);
cairo_fill (cr);
cairo_destroy (cr); cairo_destroy (cr);
region = gdk_cairo_region_create_from_surface (surface); region = gdk_cairo_region_create_from_surface (surface);
@ -679,7 +654,8 @@ gtk_popover_update_position (GtkPopover *popover)
if (priv->final_position != priv->current_position) if (priv->final_position != priv->current_position)
{ {
if (gtk_widget_is_drawable (GTK_WIDGET (popover))) if (priv->apply_shape &&
gtk_widget_is_drawable (GTK_WIDGET (popover)))
gtk_popover_update_shape (popover); gtk_popover_update_shape (popover);
priv->current_position = priv->final_position; priv->current_position = priv->final_position;
@ -704,6 +680,8 @@ gtk_popover_draw (GtkWidget *widget,
GtkStateFlags state; GtkStateFlags state;
context = gtk_widget_get_style_context (widget); context = gtk_widget_get_style_context (widget);
gtk_style_context_save (context);
state = gtk_widget_get_state_flags (widget); state = gtk_widget_get_state_flags (widget);
gtk_widget_get_allocation (widget, &allocation); gtk_widget_get_allocation (widget, &allocation);
@ -772,6 +750,8 @@ gtk_popover_draw (GtkWidget *widget,
if (child) if (child)
gtk_container_propagate_draw (GTK_CONTAINER (widget), child, cr); gtk_container_propagate_draw (GTK_CONTAINER (widget), child, cr);
gtk_style_context_restore (context);
return TRUE; return TRUE;
} }
@ -1030,8 +1010,10 @@ static void
gtk_popover_size_allocate (GtkWidget *widget, gtk_popover_size_allocate (GtkWidget *widget,
GtkAllocation *allocation) GtkAllocation *allocation)
{ {
GtkPopoverPrivate *priv;
GtkWidget *child; GtkWidget *child;
priv = gtk_popover_get_instance_private (GTK_POPOVER (widget));
gtk_widget_set_allocation (widget, allocation); gtk_widget_set_allocation (widget, allocation);
child = gtk_bin_get_child (GTK_BIN (widget)); child = gtk_bin_get_child (GTK_BIN (widget));
if (child) if (child)
@ -1055,7 +1037,8 @@ gtk_popover_size_allocate (GtkWidget *widget,
{ {
gdk_window_move_resize (gtk_widget_get_window (widget), gdk_window_move_resize (gtk_widget_get_window (widget),
0, 0, allocation->width, allocation->height); 0, 0, allocation->width, allocation->height);
gtk_popover_update_shape (GTK_POPOVER (widget)); if (priv->apply_shape)
gtk_popover_update_shape (GTK_POPOVER (widget));
} }
} }
@ -1744,3 +1727,21 @@ gtk_popover_get_modal (GtkPopover *popover)
return priv->modal; return priv->modal;
} }
void
_gtk_popover_set_apply_shape (GtkPopover *popover,
gboolean apply_shape)
{
GtkPopoverPrivate *priv;
g_return_if_fail (GTK_IS_POPOVER (popover));
priv = gtk_popover_get_instance_private (popover);
if ((priv->apply_shape == TRUE) == (apply_shape == TRUE))
return;
priv->apply_shape = apply_shape;
gtk_popover_update_position (popover);
gtk_widget_queue_draw (GTK_WIDGET (popover));
}

26
gtk/gtkpopoverprivate.h Normal file
View File

@ -0,0 +1,26 @@
/* GTK - The GIMP Toolkit
* Copyright © 2014 Carlos Garnacho <carlosg@gnome.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GTK_POPOVER_PRIVATE_H__
#define __GTK_POPOVER_PRIVATE_H__
#include "gtkpopover.h"
void _gtk_popover_set_apply_shape (GtkPopover *popover,
gboolean modal);
#endif /* __GTK_POPOVER_PRIVATE_H__ */