gatuno-terminal/src/terminal-screen-container.c

414 lines
12 KiB
C
Raw Normal View History

2011-11-06 14:13:49 -06:00
/*
* Copyright © 2008, 2010 Christian Persch
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 3 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
2012-10-11 18:34:18 -05:00
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
2011-11-06 14:13:49 -06:00
*/
#include <config.h>
#include "terminal-screen-container.h"
#include "terminal-debug.h"
#include "terminal-intl.h"
#include <gtk/gtk.h>
struct _TerminalScreenContainerPrivate
{
2011-11-06 16:14:03 -06:00
TerminalScreen *screen;
2011-11-06 14:13:49 -06:00
#ifdef USE_SCROLLED_WINDOW
2011-11-06 16:14:03 -06:00
GtkWidget *scrolled_window;
2011-11-06 14:13:49 -06:00
#else
2011-11-06 16:14:03 -06:00
GtkWidget *hbox;
GtkWidget *vscrollbar;
2011-11-06 14:13:49 -06:00
#endif
2011-11-06 16:14:03 -06:00
GtkPolicyType hscrollbar_policy;
GtkPolicyType vscrollbar_policy;
GtkCornerType window_placement;
guint window_placement_set : 1;
2011-11-06 14:13:49 -06:00
};
enum
{
2011-11-06 16:14:03 -06:00
PROP_0,
PROP_SCREEN,
PROP_HSCROLLBAR_POLICY,
PROP_VSCROLLBAR_POLICY,
PROP_WINDOW_PLACEMENT,
PROP_WINDOW_PLACEMENT_SET
2011-11-06 14:13:49 -06:00
};
G_DEFINE_TYPE_WITH_PRIVATE (TerminalScreenContainer, terminal_screen_container, GTK_TYPE_BOX)
2011-11-06 14:13:49 -06:00
/* helper functions */
static void
terminal_screen_container_set_placement_internal (TerminalScreenContainer *container,
2011-11-06 16:14:03 -06:00
GtkCornerType corner)
2011-11-06 14:13:49 -06:00
{
2011-11-06 16:14:03 -06:00
TerminalScreenContainerPrivate *priv = container->priv;
2011-11-06 14:13:49 -06:00
#ifdef USE_SCROLLED_WINDOW
2011-11-06 16:14:03 -06:00
gtk_scrolled_window_set_placement (GTK_SCROLLED_WINDOW (priv->scrolled_window), corner);
2011-11-06 14:13:49 -06:00
#else
2011-11-06 16:14:03 -06:00
switch (corner)
{
case GTK_CORNER_TOP_LEFT:
case GTK_CORNER_BOTTOM_LEFT:
gtk_box_reorder_child (GTK_BOX (priv->hbox), priv->vscrollbar, 1);
break;
case GTK_CORNER_TOP_RIGHT:
case GTK_CORNER_BOTTOM_RIGHT:
gtk_box_reorder_child (GTK_BOX (priv->hbox), priv->vscrollbar, 0);
break;
default:
g_assert_not_reached ();
}
2011-11-06 14:13:49 -06:00
#endif
2011-11-06 16:14:03 -06:00
priv->window_placement = corner;
g_object_notify (G_OBJECT (container), "window-placement");
2011-11-06 14:13:49 -06:00
}
static void
terminal_screen_container_set_placement_set (TerminalScreenContainer *container,
2011-11-06 16:14:03 -06:00
gboolean set)
2011-11-06 14:13:49 -06:00
{
2011-11-06 16:14:03 -06:00
TerminalScreenContainerPrivate *priv = container->priv;
2011-11-06 14:13:49 -06:00
#ifdef USE_SCROLLED_WINDOW
2011-11-06 16:14:03 -06:00
g_object_set (priv->scrolled_window, "window-placement-set", set, NULL);
2011-11-06 14:13:49 -06:00
#endif
2011-11-06 16:14:03 -06:00
priv->window_placement_set = set != FALSE;
g_object_notify (G_OBJECT (container), "window-placement-set");
2011-11-06 14:13:49 -06:00
}
#if defined(USE_SCROLLED_WINDOW) && defined(MATE_ENABLE_DEBUG)
static void
size_allocate_cb (GtkWidget *widget,
GdkRectangle *rect,
TerminalScreenContainer *container)
2011-11-06 14:13:49 -06:00
{
2011-11-06 16:14:03 -06:00
_terminal_debug_print (TERMINAL_DEBUG_GEOMETRY,
"[screen %p] scrolled-window size alloc %d : %d\n",
container->priv->screen, rect->width, rect->height);
2011-11-06 14:13:49 -06:00
}
#endif
/* Class implementation */
static void
terminal_screen_container_init (TerminalScreenContainer *container)
{
2011-11-06 16:14:03 -06:00
TerminalScreenContainerPrivate *priv;
2011-11-06 14:13:49 -06:00
priv = container->priv = terminal_screen_container_get_instance_private (container);
2011-11-06 14:13:49 -06:00
2011-11-06 16:14:03 -06:00
priv->hscrollbar_policy = GTK_POLICY_AUTOMATIC;
priv->vscrollbar_policy = GTK_POLICY_AUTOMATIC;
priv->window_placement = GTK_CORNER_BOTTOM_RIGHT;
priv->window_placement_set = FALSE;
gtk_orientable_set_orientation (GTK_ORIENTABLE (container), GTK_ORIENTATION_VERTICAL);
2011-11-06 14:13:49 -06:00
}
static GObject *
terminal_screen_container_constructor (GType type,
2011-11-06 16:14:03 -06:00
guint n_construct_properties,
GObjectConstructParam *construct_params)
2011-11-06 14:13:49 -06:00
{
2011-11-06 16:14:03 -06:00
GObject *object;
TerminalScreenContainer *container;
TerminalScreenContainerPrivate *priv;
2011-11-06 14:13:49 -06:00
2011-11-06 16:14:03 -06:00
object = G_OBJECT_CLASS (terminal_screen_container_parent_class)->constructor
(type, n_construct_properties, construct_params);
2011-11-06 14:13:49 -06:00
2011-11-06 16:14:03 -06:00
container = TERMINAL_SCREEN_CONTAINER (object);
priv = container->priv;
2011-11-06 14:13:49 -06:00
2011-11-06 16:14:03 -06:00
g_assert (priv->screen != NULL);
2011-11-06 14:13:49 -06:00
#ifdef USE_SCROLLED_WINDOW
priv->scrolled_window = gtk_scrolled_window_new (NULL, gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (priv->screen)));
2011-11-06 16:14:03 -06:00
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
priv->hscrollbar_policy,
priv->vscrollbar_policy);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (priv->scrolled_window),
GTK_SHADOW_NONE);
gtk_container_add (GTK_CONTAINER (priv->scrolled_window), GTK_WIDGET (priv->screen));
gtk_widget_show (GTK_WIDGET (priv->screen));
gtk_box_pack_end (GTK_BOX (container), priv->scrolled_window, TRUE, TRUE, 0);
gtk_widget_show (priv->scrolled_window);
2011-11-06 14:13:49 -06:00
#ifdef MATE_ENABLE_DEBUG
g_signal_connect (priv->scrolled_window, "size-allocate", G_CALLBACK (size_allocate_cb), container);
2011-11-06 14:13:49 -06:00
#endif
#else
priv->hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
2011-11-06 14:13:49 -06:00
2016-06-01 10:36:40 -05:00
priv->vscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_VERTICAL, gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (priv->screen)));
2011-11-06 14:13:49 -06:00
2011-11-06 16:14:03 -06:00
gtk_box_pack_start (GTK_BOX (priv->hbox), GTK_WIDGET (priv->screen), TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (priv->hbox), priv->vscrollbar, FALSE, FALSE, 0);
2011-11-06 14:13:49 -06:00
2011-11-06 16:14:03 -06:00
gtk_box_pack_end (GTK_BOX (container), priv->hbox, TRUE, TRUE, 0);
gtk_widget_show_all (priv->hbox);
2011-11-06 14:13:49 -06:00
#endif /* USE_SCROLLED_WINDOW */
2011-11-06 16:14:03 -06:00
_terminal_screen_update_scrollbar (priv->screen);
2011-11-06 14:13:49 -06:00
2011-11-06 16:14:03 -06:00
return object;
2011-11-06 14:13:49 -06:00
}
static void
terminal_screen_container_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
2011-11-06 16:14:03 -06:00
TerminalScreenContainer *container = TERMINAL_SCREEN_CONTAINER (object);
TerminalScreenContainerPrivate *priv = container->priv;
switch (prop_id)
{
case PROP_SCREEN:
break;
case PROP_HSCROLLBAR_POLICY:
g_value_set_enum (value, priv->hscrollbar_policy);
break;
case PROP_VSCROLLBAR_POLICY:
g_value_set_enum (value, priv->vscrollbar_policy);
break;
case PROP_WINDOW_PLACEMENT:
g_value_set_enum (value, priv->window_placement);
break;
case PROP_WINDOW_PLACEMENT_SET:
g_value_set_boolean (value, priv->window_placement_set);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
2011-11-06 14:13:49 -06:00
}
static void
terminal_screen_container_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
2011-11-06 16:14:03 -06:00
TerminalScreenContainer *container = TERMINAL_SCREEN_CONTAINER (object);
TerminalScreenContainerPrivate *priv = container->priv;
switch (prop_id)
{
case PROP_SCREEN:
priv->screen = g_value_get_object (value);
break;
case PROP_HSCROLLBAR_POLICY:
terminal_screen_container_set_policy (container,
g_value_get_enum (value),
priv->vscrollbar_policy);
break;
case PROP_VSCROLLBAR_POLICY:
terminal_screen_container_set_policy (container,
priv->hscrollbar_policy,
g_value_get_enum (value));
break;
case PROP_WINDOW_PLACEMENT:
terminal_screen_container_set_placement_internal (container, g_value_get_enum (value));
break;
case PROP_WINDOW_PLACEMENT_SET:
terminal_screen_container_set_placement_set (container, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
2011-11-06 14:13:49 -06:00
}
static void
terminal_screen_container_class_init (TerminalScreenContainerClass *klass)
{
2011-11-06 16:14:03 -06:00
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->constructor = terminal_screen_container_constructor;
gobject_class->get_property = terminal_screen_container_get_property;
gobject_class->set_property = terminal_screen_container_set_property;
g_object_class_install_property
(gobject_class,
PROP_SCREEN,
g_param_spec_object ("screen", NULL, NULL,
TERMINAL_TYPE_SCREEN,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property
(gobject_class,
PROP_HSCROLLBAR_POLICY,
g_param_spec_enum ("hscrollbar-policy", NULL, NULL,
GTK_TYPE_POLICY_TYPE,
GTK_POLICY_AUTOMATIC,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property
(gobject_class,
PROP_VSCROLLBAR_POLICY,
g_param_spec_enum ("vscrollbar-policy", NULL, NULL,
GTK_TYPE_POLICY_TYPE,
GTK_POLICY_AUTOMATIC,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property
(gobject_class,
PROP_WINDOW_PLACEMENT,
g_param_spec_enum ("window-placement", NULL, NULL,
GTK_TYPE_CORNER_TYPE,
GTK_CORNER_TOP_LEFT,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property
(gobject_class,
PROP_WINDOW_PLACEMENT_SET,
g_param_spec_boolean ("window-placement-set", NULL, NULL,
FALSE,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
2011-11-06 14:13:49 -06:00
}
/* public API */
/**
* terminal_screen_container_new:
* @screen: a #TerminalScreen
*
* Returns: a new #TerminalScreenContainer for @screen
*/
GtkWidget *
terminal_screen_container_new (TerminalScreen *screen)
{
2011-11-06 16:14:03 -06:00
return g_object_new (TERMINAL_TYPE_SCREEN_CONTAINER,
"screen", screen,
NULL);
2011-11-06 14:13:49 -06:00
}
/**
* terminal_screen_container_get_screen:
* @container: a #TerminalScreenContainer
*
* Returns: @container's #TerminalScreen
*/
TerminalScreen *
terminal_screen_container_get_screen (TerminalScreenContainer *container)
{
2011-11-06 16:14:03 -06:00
g_return_val_if_fail (TERMINAL_IS_SCREEN_CONTAINER (container), NULL);
2011-11-06 14:13:49 -06:00
2011-11-06 16:14:03 -06:00
return container->priv->screen;
2011-11-06 14:13:49 -06:00
}
/**
* terminal_screen_container_get_from_screen:
* @screen: a #TerminalScreenContainerPrivate
*
* Returns the #TerminalScreenContainer containing @screen.
*/
TerminalScreenContainer *
terminal_screen_container_get_from_screen (TerminalScreen *screen)
{
2011-11-06 16:14:03 -06:00
g_return_val_if_fail (TERMINAL_IS_SCREEN (screen), NULL);
2011-11-06 14:13:49 -06:00
2011-11-06 16:14:03 -06:00
return TERMINAL_SCREEN_CONTAINER (gtk_widget_get_ancestor (GTK_WIDGET (screen), TERMINAL_TYPE_SCREEN_CONTAINER));
2011-11-06 14:13:49 -06:00
}
/**
* terminal_screen_container_set_policy:
* @container: a #TerminalScreenContainer
* @hpolicy: a #GtkPolicyType
* @vpolicy: a #GtkPolicyType
*
* Sets @container's scrollbar policy.
*/
void
terminal_screen_container_set_policy (TerminalScreenContainer *container,
GtkPolicyType hpolicy G_GNUC_UNUSED,
GtkPolicyType vpolicy)
{
2011-11-06 16:14:03 -06:00
TerminalScreenContainerPrivate *priv;
GObject *object;
2011-11-06 14:13:49 -06:00
2011-11-06 16:14:03 -06:00
g_return_if_fail (TERMINAL_IS_SCREEN_CONTAINER (container));
2011-11-06 14:13:49 -06:00
2011-11-06 16:14:03 -06:00
object = G_OBJECT (container);
priv = container->priv;
2011-11-06 14:13:49 -06:00
2011-11-06 16:14:03 -06:00
g_object_freeze_notify (object);
2011-11-06 14:13:49 -06:00
2011-11-06 16:14:03 -06:00
if (priv->hscrollbar_policy != hpolicy)
{
priv->hscrollbar_policy = hpolicy;
g_object_notify (object, "hscrollbar-policy");
}
if (priv->vscrollbar_policy != vpolicy)
{
priv->vscrollbar_policy = vpolicy;
g_object_notify (object, "vscrollbar-policy");
}
2011-11-06 14:13:49 -06:00
#ifdef USE_SCROLLED_WINDOW
2011-11-06 16:14:03 -06:00
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window), hpolicy, vpolicy);
2011-11-06 14:13:49 -06:00
#else
2011-11-06 16:14:03 -06:00
switch (vpolicy)
{
case GTK_POLICY_NEVER:
gtk_widget_hide (priv->vscrollbar);
break;
case GTK_POLICY_AUTOMATIC:
case GTK_POLICY_ALWAYS:
gtk_widget_show (priv->vscrollbar);
break;
default:
g_assert_not_reached ();
}
2011-11-06 14:13:49 -06:00
#endif
2011-11-06 16:14:03 -06:00
g_object_thaw_notify (object);
2011-11-06 14:13:49 -06:00
}
/**
* terminal_screen_container_set_placement:
* @container: a #TerminalScreenContainer
* @corner: a #GtkCornerType
*
* Sets @container's window placement.
*/
void
terminal_screen_container_set_placement (TerminalScreenContainer *container,
2011-11-06 16:14:03 -06:00
GtkCornerType corner)
2011-11-06 14:13:49 -06:00
{
2011-11-06 16:14:03 -06:00
g_return_if_fail (TERMINAL_IS_SCREEN_CONTAINER (container));
2011-11-06 14:13:49 -06:00
2011-11-06 16:14:03 -06:00
terminal_screen_container_set_placement_internal (container, corner);
terminal_screen_container_set_placement_set (container, TRUE);
2011-11-06 14:13:49 -06:00
}