1 /* A Gtk Widget that inherits GtkFixed, but can be shrinked.
3 Copyright (C) 2011 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 #include "emacsgtkfixed.h"
23 struct _EmacsFixedPrivate
25 int minwidth
, minheight
;
29 static void emacs_fixed_get_preferred_width (GtkWidget
*widget
,
32 static void emacs_fixed_get_preferred_height (GtkWidget
*widget
,
35 G_DEFINE_TYPE (EmacsFixed
, emacs_fixed
, GTK_TYPE_FIXED
)
38 emacs_fixed_class_init (EmacsFixedClass
*klass
)
40 GtkWidgetClass
*widget_class
;
41 GtkFixedClass
*fixed_class
;
43 widget_class
= (GtkWidgetClass
*) klass
;
44 fixed_class
= (GtkFixedClass
*) klass
;
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
));
52 emacs_fixed_child_type (GtkFixed
*container
)
54 return GTK_TYPE_WIDGET
;
58 emacs_fixed_init (EmacsFixed
*fixed
)
60 fixed
->priv
= G_TYPE_INSTANCE_GET_PRIVATE (fixed
, EMACS_TYPE_FIXED
,
62 fixed
->priv
->minwidth
= fixed
->priv
->minheight
= 0;
68 * Creates a new #EmacsFixed.
70 * Returns: a new #EmacsFixed.
73 emacs_fixed_new (void)
75 return g_object_new (EMACS_TYPE_FIXED
, NULL
);
78 static GtkWidgetClass
*
79 get_parent_class (EmacsFixed
*fixed
)
81 EmacsFixedClass
*klass
= EMACS_FIXED_GET_CLASS (fixed
);
82 GtkFixedClass
*parent_class
= g_type_class_peek_parent (klass
);
83 return (GtkWidgetClass
*) parent_class
;
87 emacs_fixed_get_preferred_width (GtkWidget
*widget
,
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
;
99 emacs_fixed_get_preferred_height (GtkWidget
*widget
,
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
;
111 emacs_fixed_set_min_size (EmacsFixed
*widget
, int width
, int height
)
113 EmacsFixedPrivate
*priv
= widget
->priv
;
114 GtkWidgetClass
*widget_class
= get_parent_class (widget
);
117 widget_class
->get_preferred_height (GTK_WIDGET (widget
), &mh
, &nh
);
118 widget_class
->get_preferred_width (GTK_WIDGET (widget
), &mw
, &nw
);
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
;