/* vi:set ts=8 sts=4 sw=4 noet:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/
/*
* (C) 1998,1999 by Marcin Dalecki <martin@dalecki.de>
*
* Support for GTK+ 2 was added by:
*
* (C) 2002,2003 Jason Hildebrand <jason@peaceworks.ca>
* Daniel Elstner <daniel.elstner@gmx.net>
*
* This is a special purpose container widget, which manages arbitrary
* children at arbitrary positions width arbitrary sizes. This finally puts
* an end on our resize problems with which we where struggling for such a
* long time.
*
* Support for GTK+ 3 was added by:
*
* 2016 Kazunobu Kuriyama <kazunobu.kuriyama@gmail.com>
*/
#include "vim.h"
#include <gtk/gtk.h> /* without this it compiles, but gives errors at
runtime! */
#include "gui_gtk_f.h"
#if !GTK_CHECK_VERSION(3,0,0)
# include <gtk/gtksignal.h>
#endif
#ifdef WIN3264
# include <gdk/gdkwin32.h>
#else
# include <gdk/gdkx.h>
#endif
typedef struct _GtkFormChild GtkFormChild;
struct _GtkFormChild
{
GtkWidget *widget;
GdkWindow *window;
gint x; /* relative subwidget x position */
gint y; /* relative subwidget y position */
gint mapped;
};
static void gtk_form_class_init(GtkFormClass *klass);
static void gtk_form_init(GtkForm *form);
static void gtk_form_realize(GtkWidget *widget);
static void gtk_form_unrealize(GtkWidget *widget);
static void gtk_form_map(GtkWidget *widget);
static void gtk_form_size_request(GtkWidget *widget,
GtkRequisition *requisition);
#if GTK_CHECK_VERSION(3,0,0)
static void gtk_form_get_preferred_width(GtkWidget *widget,
gint *minimal_width,
gint *natural_width);
static void gtk_form_get_preferred_height(GtkWidget *widget,
gint *minimal_height,
gint *natural_height);
#endif
static void gtk_form_size_allocate(GtkWidget *widget,
GtkAllocation *allocation);
#if GTK_CHECK_VERSION(3,0,0)
static gboolean gtk_form_draw(GtkWidget *widget,
cairo_t *cr);
#else
static gint gtk_form_expose(GtkWidget *widget,
GdkEventExpose *event);
#endif
static void gtk_form_remove(GtkContainer *container,
GtkWidget *widget);
static void gtk_form_forall(GtkContainer *container,
gboolean include_internals,
GtkCallback callback,
gpointer callback_data);
static void gtk_form_attach_child_window(GtkForm *form,
GtkFormChild *child);
static void gtk_form_realize_child(GtkForm *form,
GtkFormChild *child);
static void gtk_form_position_child(GtkForm *form,
GtkFormChild *child,
gboolean force_allocate);
static void gtk_form_position_children(GtkForm *form);
static void gtk_form_send_configure(GtkForm *form);
static void gtk_form_child_map(GtkWidget *widget, gpointer user_data);
static void gtk_form_child_unmap(GtkWidget *widget, gpointer user_data);
#if !GTK_CHECK_VERSION(3,0,0)
static GtkWidgetClass *parent_class = NULL;
#endif
/* Public interface
*/
GtkWidget *
gtk_form_new(void)
{
GtkForm *form;
#if GTK_CHECK_VERSION(3,0,0)
form = g_object_new(GTK_TYPE_FORM, NULL);
#else
form = gtk_type_new(gtk_form_get_type());
#endif
return GTK_WIDGET(form);
}
void
gtk_form_put(GtkForm *form,
GtkWidget *child_widget,
gint x,
gint y)
{
GtkFormChild *child;
g_return_if_fail(GTK_IS_FORM(form));
/* LINTED: avoid warning: conversion to 'unsigned long' */
child = g_new(GtkFormChild, 1);
child->widget = child_widget;
child->window = NULL;
child->x = x;
child->y = y;
#if GTK_CHECK_VERSION(3,0,0)
gtk_widget_set_size_request(child->widget, -1, -1);
#else
child->widget->requisition.width = 0;
child->widget->requisition.height = 0;
#endif
child->mapped = FALSE;
form->children = g_list_append(form->children, child);
/* child->window must be created and attached to the widget _before_
* it has been realized, or else things will break with GTK2. Note
* that gtk_widget_set_parent() realizes the widget if it's visible
* and its parent is mapped.
*/
#if GTK_CHECK_VERSION(3,0,0)
if (gtk_widget_get_realized(GTK_WIDGET(form)))
#else
if (GTK_WIDGET_REALIZED(form))
#endif
gtk_form_attach_child_window(form, child);
gtk_widget_set_parent(child_widget, GTK_WIDGET(form));
#if GTK_CHECK_VERSION(3,0,0)
if (gtk_widget_get_realized(GTK_WIDGET(form))
&& !gtk_widget_get_realized(child_widget))
#else
if (GTK_WIDGET_REALIZED