* 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, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
/*
#include "gtkorientable.h"
#include "gtkwindow.h"
#include "gtktypebuiltins.h"
+#include "gtkorientableprivate.h"
#include "gtkprivate.h"
#include "gtkintl.h"
-
+#include "a11y/gtkpanedaccessible.h"
/**
* SECTION:gtkpaned
- * @Short_description: Base class for widgets with two adjustable panes
+ * @Short_description: A widget with two adjustable panes
* @Title: GtkPaned
*
- * #GtkPaned is the base class for widgets with two panes, arranged either
- * horizontally (#GtkHPaned) or vertically (#GtkVPaned). Child widgets are
+ * #GtkPaned has two panes, arranged either
+ * horizontally or vertically. The division between
+ * the two panes is adjustable by the user by dragging
+ * a handle.
+ *
+ * Child widgets are
* added to the panes of the widget with gtk_paned_pack1() and
* gtk_paned_pack2(). The division between the two children is set by default
* from the size requests of the children, but it can be adjusted by the
add_move_binding (binding_set, GDK_KEY_KP_End, 0, GTK_SCROLL_END);
g_type_class_add_private (object_class, sizeof (GtkPanedPrivate));
+ gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_PANED_ACCESSIBLE);
}
static GType
priv->child1 = NULL;
priv->child2 = NULL;
priv->handle = NULL;
- priv->cursor_type = GDK_CROSS;
priv->handle_pos.width = 5;
priv->handle_pos.height = 5;
{
case PROP_ORIENTATION:
priv->orientation = g_value_get_enum (value);
+ _gtk_orientable_set_style_classes (GTK_ORIENTABLE (paned));
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
priv->cursor_type = GDK_SB_H_DOUBLE_ARROW;
if (priv->child1 && gtk_widget_get_visible (priv->child1))
{
get_preferred_size_for_size (priv->child1, orientation, size, &child_min, &child_nat);
- *minimum = child_min;
+ if (priv->child1_shrink && priv->orientation == orientation)
+ *minimum = 0;
+ else
+ *minimum = child_min;
*natural = child_nat;
}
if (priv->orientation == orientation)
{
- *minimum += child_min;
+ if (!priv->child2_shrink)
+ *minimum += child_min;
*natural += child_nat;
}
else
child_pos->x = 2 * x + width - child_pos->x - child_pos->width;
}
-static gboolean
-gtk_paned_get_child_visible (GtkPaned *paned,
- guint id)
-{
- GtkPanedPrivate *priv = paned->priv;
- GtkWidget *child;
-
- child = id == CHILD1 ? priv->child1 : priv->child2;
-
- return (child != NULL && gtk_widget_get_child_visible (child));
-}
-
static void
gtk_paned_set_child_visible (GtkPaned *paned,
guint id,
{
GtkPanedPrivate *priv = paned->priv;
GtkWidget *child;
- gboolean was_visible;
-
- was_visible = gtk_paned_get_child_visible (paned, id);
child = id == CHILD1 ? priv->child1 : priv->child2;
if (child == NULL)
return;
- if (was_visible == visible)
- return;
-
gtk_widget_set_child_visible (child, visible);
if (gtk_widget_get_mapped (GTK_WIDGET (paned)))
{
GdkWindow *window = id == CHILD1 ? priv->child1_window : priv->child2_window;
- if (visible)
- gdk_window_show (window);
- else
- gdk_window_hide (window);
+ if (visible != gdk_window_is_visible (window))
+ {
+ if (visible)
+ gdk_window_show (window);
+ else
+ gdk_window_hide (window);
+ }
}
}
if (gtk_widget_get_realized (widget))
gdk_window_hide (priv->handle);
- if (priv->child1)
- gtk_paned_set_child_visible (paned, 0, TRUE);
- if (priv->child2)
- gtk_paned_set_child_visible (paned, 1, TRUE);
-
window_allocation.x = allocation->x;
window_allocation.y = allocation->y;
window_allocation.width = allocation->width;
if (priv->child1 && gtk_widget_get_visible (priv->child1))
{
+ gtk_paned_set_child_visible (paned, 0, TRUE);
+ if (priv->child2)
+ gtk_paned_set_child_visible (paned, 1, FALSE);
+
gtk_paned_child_allocate (priv->child1,
priv->child1_window,
&window_allocation,
}
else if (priv->child2 && gtk_widget_get_visible (priv->child2))
{
+ gtk_paned_set_child_visible (paned, 1, TRUE);
+ if (priv->child1)
+ gtk_paned_set_child_visible (paned, 0, FALSE);
+
gtk_paned_child_allocate (priv->child2,
priv->child2_window,
&window_allocation,
&child_allocation);
}
+ else
+ {
+ if (priv->child1)
+ gtk_paned_set_child_visible (paned, 0, FALSE);
+ if (priv->child2)
+ gtk_paned_set_child_visible (paned, 1, FALSE);
+ }
}
}
gtk_widget_get_allocation (widget, &allocation);
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
- child == priv->child2)
+ child == priv->child2 && priv->child1 &&
+ gtk_widget_get_visible (priv->child1))
attributes.x = priv->handle_pos.x + handle_size;
else
attributes.x = allocation.x;
if (priv->orientation == GTK_ORIENTATION_VERTICAL &&
- child == priv->child2)
+ child == priv->child2 && priv->child1 &&
+ gtk_widget_get_visible (priv->child1))
attributes.y = priv->handle_pos.y + handle_size;
else
attributes.y = allocation.y;
window = gdk_window_new (gtk_widget_get_window (widget),
&attributes, attributes_mask);
- gdk_window_set_user_data (window, paned);
+ gtk_widget_register_window (widget, window);
gtk_style_context_set_background (gtk_widget_get_style_context (widget), window);
if (child)
GDK_BUTTON_RELEASE_MASK |
GDK_ENTER_NOTIFY_MASK |
GDK_LEAVE_NOTIFY_MASK |
- GDK_POINTER_MOTION_MASK |
- GDK_POINTER_MOTION_HINT_MASK);
+ GDK_POINTER_MOTION_MASK);
attributes_mask = GDK_WA_X | GDK_WA_Y;
if (gtk_widget_is_sensitive (widget))
{
priv->handle = gdk_window_new (window,
&attributes, attributes_mask);
- gdk_window_set_user_data (priv->handle, paned);
+ gtk_widget_register_window (widget, priv->handle);
if (attributes_mask & GDK_WA_CURSOR)
g_object_unref (attributes.cursor);
if (priv->child2)
gtk_widget_set_parent_window (priv->child2, NULL);
- gdk_window_set_user_data (priv->child2_window, NULL);
+ gtk_widget_unregister_window (widget, priv->child2_window);
gdk_window_destroy (priv->child2_window);
priv->child2_window = NULL;
if (priv->child1)
gtk_widget_set_parent_window (priv->child1, NULL);
- gdk_window_set_user_data (priv->child1_window, NULL);
+ gtk_widget_unregister_window (widget, priv->child1_window);
gdk_window_destroy (priv->child1_window);
priv->child1_window = NULL;
if (priv->handle)
{
- gdk_window_set_user_data (priv->handle, NULL);
+ gtk_widget_unregister_window (widget, priv->handle);
gdk_window_destroy (priv->handle);
priv->handle = NULL;
}
}
static void
-update_drag (GtkPaned *paned)
+update_drag (GtkPaned *paned,
+ /* relative to priv->handle */
+ int xpos,
+ int ypos)
{
GtkPanedPrivate *priv = paned->priv;
GtkAllocation allocation;
gint pos;
gint handle_size;
gint size;
+ gint x, y;
+ gdk_window_get_position (priv->handle, &x, &y);
+ gtk_widget_get_allocation (widget, &allocation);
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
- gtk_widget_get_pointer (widget, &pos, NULL);
+ {
+ pos = xpos + x - allocation.x;
+ }
else
- gtk_widget_get_pointer (widget, NULL, &pos);
+ {
+ pos = ypos + y - allocation.y;
+ }
pos -= priv->drag_pos;
"handle-size", &handle_size,
NULL);
- gtk_widget_get_allocation (widget, &allocation);
size = allocation.width - pos - handle_size;
}
else
GtkPanedPrivate *priv = paned->priv;
if (priv->in_drag)
- update_drag (paned);
+ update_drag (paned, event->x, event->y);
else
{
priv->handle_prelit = TRUE;
GtkPanedPrivate *priv = paned->priv;
if (priv->in_drag)
- update_drag (paned);
+ update_drag (paned, event->x, event->y);
else
{
priv->handle_prelit = FALSE;
GtkPanedPrivate *priv = paned->priv;
if (!priv->in_drag &&
- (event->window == priv->handle) && (event->button == 1))
+ (event->window == priv->handle) && (event->button == GDK_BUTTON_PRIMARY))
{
/* We need a server grab here, not gtk_grab_add(), since
* we don't want to pass events on to the widget's children */
if (gdk_device_grab (event->device,
priv->handle,
GDK_OWNERSHIP_WINDOW, FALSE,
- GDK_POINTER_MOTION_HINT_MASK
- | GDK_BUTTON1_MOTION_MASK
+ GDK_BUTTON1_MOTION_MASK
| GDK_BUTTON_RELEASE_MASK
| GDK_ENTER_NOTIFY_MASK
| GDK_LEAVE_NOTIFY_MASK,
GtkPaned *paned = GTK_PANED (widget);
GtkPanedPrivate *priv = paned->priv;
- if (priv->in_drag && (event->button == 1))
+ if (priv->in_drag && (event->button == GDK_BUTTON_PRIMARY))
{
stop_drag (paned);
if (priv->in_drag)
{
- update_drag (paned);
+ update_drag (paned, event->x, event->y);
return TRUE;
}