ChangeLog fix.
[bpt/emacs.git] / src / emacsgtkfixed.c
CommitLineData
c195f2de
JD
1/* A Gtk Widget that inherits GtkFixed, but can be shrinked.
2
3Copyright (C) 2011 Free Software Foundation, Inc.
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 3 of the License, or
10(at your option) any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19
20#include "emacsgtkfixed.h"
21
22
23struct _EmacsFixedPrivate
24{
25 int minwidth, minheight;
26};
27
28
29static void emacs_fixed_get_preferred_width (GtkWidget *widget,
30 gint *minimum,
31 gint *natural);
32static void emacs_fixed_get_preferred_height (GtkWidget *widget,
33 gint *minimum,
34 gint *natural);
35G_DEFINE_TYPE (EmacsFixed, emacs_fixed, GTK_TYPE_FIXED)
36
37static void
38emacs_fixed_class_init (EmacsFixedClass *klass)
39{
40 GtkWidgetClass *widget_class;
41 GtkFixedClass *fixed_class;
42
43 widget_class = (GtkWidgetClass*) klass;
44 fixed_class = (GtkFixedClass*) klass;
45
46 widget_class->get_preferred_width = emacs_fixed_get_preferred_width;
47 widget_class->get_preferred_height = emacs_fixed_get_preferred_height;
48 g_type_class_add_private (klass, sizeof (EmacsFixedPrivate));
49}
50
51static GType
52emacs_fixed_child_type (GtkFixed *container)
53{
54 return GTK_TYPE_WIDGET;
55}
56
57static void
58emacs_fixed_init (EmacsFixed *fixed)
59{
60 fixed->priv = G_TYPE_INSTANCE_GET_PRIVATE (fixed, EMACS_TYPE_FIXED,
61 EmacsFixedPrivate);
62 fixed->priv->minwidth = fixed->priv->minheight = 0;
63}
64
65/**
66 * emacs_fixed_new:
67 *
68 * Creates a new #EmacsFixed.
69 *
70 * Returns: a new #EmacsFixed.
71 */
72GtkWidget*
73emacs_fixed_new (void)
74{
75 return g_object_new (EMACS_TYPE_FIXED, NULL);
76}
77
78static GtkWidgetClass *
79get_parent_class (EmacsFixed *fixed)
80{
81 EmacsFixedClass *klass = EMACS_FIXED_GET_CLASS (fixed);
82 GtkFixedClass *parent_class = g_type_class_peek_parent (klass);
83 return (GtkWidgetClass*) parent_class;
84}
85
86static void
87emacs_fixed_get_preferred_width (GtkWidget *widget,
88 gint *minimum,
89 gint *natural)
90{
91 EmacsFixed *fixed = EMACS_FIXED (widget);
92 EmacsFixedPrivate *priv = fixed->priv;
93 GtkWidgetClass *widget_class = get_parent_class (fixed);
94 widget_class->get_preferred_width (widget, minimum, natural);
95 if (minimum) *minimum = priv->minwidth;
96}
97
98static void
99emacs_fixed_get_preferred_height (GtkWidget *widget,
100 gint *minimum,
101 gint *natural)
102{
103 EmacsFixed *fixed = EMACS_FIXED (widget);
104 EmacsFixedPrivate *priv = fixed->priv;
105 GtkWidgetClass *widget_class = get_parent_class (fixed);
106 widget_class->get_preferred_height (widget, minimum, natural);
107 if (minimum) *minimum = priv->minheight;
108}
109
110void
111emacs_fixed_set_min_size (EmacsFixed *widget, int width, int height)
112{
113 EmacsFixedPrivate *priv = widget->priv;
114 GtkWidgetClass *widget_class = get_parent_class (widget);
115 int mw, nw, mh, nh;
116
117 widget_class->get_preferred_height (GTK_WIDGET (widget), &mh, &nh);
118 widget_class->get_preferred_width (GTK_WIDGET (widget), &mw, &nw);
119
120 /* Gtk complains if min size is less than natural size. */
121 if (width <= nw) priv->minwidth = width;
122 if (height <= nh) priv->minheight = height;
123}