aboutsummaryrefslogtreecommitdiffstats
path: root/src/emacsgtkfixed.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/emacsgtkfixed.c')
-rw-r--r--src/emacsgtkfixed.c123
1 files changed, 104 insertions, 19 deletions
diff --git a/src/emacsgtkfixed.c b/src/emacsgtkfixed.c
index cdcaf803ba5..08b840389c5 100644
--- a/src/emacsgtkfixed.c
+++ b/src/emacsgtkfixed.c
@@ -23,6 +23,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
23#include "lisp.h" 23#include "lisp.h"
24#include "frame.h" 24#include "frame.h"
25#include "xterm.h" 25#include "xterm.h"
26#ifdef HAVE_XWIDGETS
27# include "xwidget.h"
28#endif
26#include "emacsgtkfixed.h" 29#include "emacsgtkfixed.h"
27 30
28/* Silence a bogus diagnostic; see GNOME bug 683906. */ 31/* Silence a bogus diagnostic; see GNOME bug 683906. */
@@ -31,27 +34,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
31# pragma GCC diagnostic ignored "-Wunused-local-typedefs" 34# pragma GCC diagnostic ignored "-Wunused-local-typedefs"
32#endif 35#endif
33 36
34#define EMACS_TYPE_FIXED emacs_fixed_get_type ()
35#define EMACS_FIXED(obj) \
36 G_TYPE_CHECK_INSTANCE_CAST (obj, EMACS_TYPE_FIXED, EmacsFixed)
37
38typedef struct _EmacsFixed EmacsFixed; 37typedef struct _EmacsFixed EmacsFixed;
39typedef struct _EmacsFixedPrivate EmacsFixedPrivate; 38typedef struct _EmacsFixedPrivate EmacsFixedPrivate;
40typedef struct _EmacsFixedClass EmacsFixedClass; 39typedef struct _EmacsFixedClass EmacsFixedClass;
41 40
42struct _EmacsFixed
43{
44 GtkFixed container;
45
46 /*< private >*/
47 EmacsFixedPrivate *priv;
48};
49
50struct _EmacsFixedClass
51{
52 GtkFixedClass parent_class;
53};
54
55struct _EmacsFixedPrivate 41struct _EmacsFixedPrivate
56{ 42{
57 struct frame *f; 43 struct frame *f;
@@ -64,9 +50,103 @@ static void emacs_fixed_get_preferred_width (GtkWidget *widget,
64static void emacs_fixed_get_preferred_height (GtkWidget *widget, 50static void emacs_fixed_get_preferred_height (GtkWidget *widget,
65 gint *minimum, 51 gint *minimum,
66 gint *natural); 52 gint *natural);
53
67static GType emacs_fixed_get_type (void); 54static GType emacs_fixed_get_type (void);
68G_DEFINE_TYPE (EmacsFixed, emacs_fixed, GTK_TYPE_FIXED) 55G_DEFINE_TYPE (EmacsFixed, emacs_fixed, GTK_TYPE_FIXED)
69 56
57static EmacsFixed *
58EMACS_FIXED (GtkWidget *widget)
59{
60 return G_TYPE_CHECK_INSTANCE_CAST (widget, emacs_fixed_get_type (),
61 EmacsFixed);
62}
63
64#ifdef HAVE_XWIDGETS
65
66static EmacsFixedClass *
67EMACS_FIXED_GET_CLASS (GtkWidget *widget)
68{
69 return G_TYPE_INSTANCE_GET_CLASS (widget, emacs_fixed_get_type (),
70 EmacsFixedClass);
71}
72
73struct GtkFixedPrivateL
74{
75 GList *children;
76};
77
78static void emacs_fixed_gtk_widget_size_allocate (GtkWidget *widget,
79 GtkAllocation *allocation)
80{
81 // For xwidgets.
82
83 // This basically re-implements the base class method and adds an
84 // additional case for an xwidget view.
85
86 // It would be nicer if the bse class method could be called first,
87 // and the the xview modification only would remain here. It wasn't
88 // possible to solve it that way yet.
89 EmacsFixedClass *klass;
90 GtkWidgetClass *parent_class;
91 struct GtkFixedPrivateL* priv;
92
93 klass = EMACS_FIXED_GET_CLASS (widget);
94 parent_class = g_type_class_peek_parent (klass);
95 parent_class->size_allocate (widget, allocation);
96
97 priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
98 GTK_TYPE_FIXED,
99 struct GtkFixedPrivateL);
100
101 gtk_widget_set_allocation (widget, allocation);
102
103 if (gtk_widget_get_has_window (widget))
104 {
105 if (gtk_widget_get_realized (widget))
106 gdk_window_move_resize (gtk_widget_get_window (widget),
107 allocation->x,
108 allocation->y,
109 allocation->width,
110 allocation->height);
111 }
112
113 for (GList *children = priv->children; children; children = children->next)
114 {
115 GtkFixedChild *child = children->data;
116
117 if (!gtk_widget_get_visible (child->widget))
118 continue;
119
120 GtkRequisition child_requisition;
121 gtk_widget_get_preferred_size (child->widget, &child_requisition, NULL);
122
123 GtkAllocation child_allocation;
124 child_allocation.x = child->x;
125 child_allocation.y = child->y;
126
127 if (!gtk_widget_get_has_window (widget))
128 {
129 child_allocation.x += allocation->x;
130 child_allocation.y += allocation->y;
131 }
132
133 child_allocation.width = child_requisition.width;
134 child_allocation.height = child_requisition.height;
135
136 struct xwidget_view *xv
137 = g_object_get_data (G_OBJECT (child->widget), XG_XWIDGET_VIEW);
138 if (xv)
139 {
140 child_allocation.width = xv->clip_right;
141 child_allocation.height = xv->clip_bottom - xv->clip_top;
142 }
143
144 gtk_widget_size_allocate (child->widget, &child_allocation);
145 }
146}
147
148#endif /* HAVE_XWIDGETS */
149
70static void 150static void
71emacs_fixed_class_init (EmacsFixedClass *klass) 151emacs_fixed_class_init (EmacsFixedClass *klass)
72{ 152{
@@ -74,15 +154,20 @@ emacs_fixed_class_init (EmacsFixedClass *klass)
74 154
75 widget_class = (GtkWidgetClass*) klass; 155 widget_class = (GtkWidgetClass*) klass;
76 156
157
77 widget_class->get_preferred_width = emacs_fixed_get_preferred_width; 158 widget_class->get_preferred_width = emacs_fixed_get_preferred_width;
78 widget_class->get_preferred_height = emacs_fixed_get_preferred_height; 159 widget_class->get_preferred_height = emacs_fixed_get_preferred_height;
160#ifdef HAVE_XWIDGETS
161 widget_class->size_allocate = emacs_fixed_gtk_widget_size_allocate;
162#endif
79 g_type_class_add_private (klass, sizeof (EmacsFixedPrivate)); 163 g_type_class_add_private (klass, sizeof (EmacsFixedPrivate));
80} 164}
81 165
166
82static void 167static void
83emacs_fixed_init (EmacsFixed *fixed) 168emacs_fixed_init (EmacsFixed *fixed)
84{ 169{
85 fixed->priv = G_TYPE_INSTANCE_GET_PRIVATE (fixed, EMACS_TYPE_FIXED, 170 fixed->priv = G_TYPE_INSTANCE_GET_PRIVATE (fixed, emacs_fixed_get_type (),
86 EmacsFixedPrivate); 171 EmacsFixedPrivate);
87 fixed->priv->f = 0; 172 fixed->priv->f = 0;
88} 173}
@@ -97,7 +182,7 @@ emacs_fixed_init (EmacsFixed *fixed)
97GtkWidget* 182GtkWidget*
98emacs_fixed_new (struct frame *f) 183emacs_fixed_new (struct frame *f)
99{ 184{
100 EmacsFixed *fixed = g_object_new (EMACS_TYPE_FIXED, NULL); 185 EmacsFixed *fixed = g_object_new (emacs_fixed_get_type (), NULL);
101 EmacsFixedPrivate *priv = fixed->priv; 186 EmacsFixedPrivate *priv = fixed->priv;
102 priv->f = f; 187 priv->f = f;
103 return GTK_WIDGET (fixed); 188 return GTK_WIDGET (fixed);