File: lazyfixed.c

package info (click to toggle)
mah-jong 1.8-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 2,384 kB
  • ctags: 2,186
  • sloc: ansic: 26,312; perl: 393; makefile: 272; sh: 122
file content (122 lines) | stat: -rw-r--r-- 3,267 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* $Header: /home/jcb/newmj/RCS/lazyfixed.c,v 11.0 2001/05/17 18:23:11 jcb Rel $
 * lazyfixed.c
 * A slight variation on the GTK+ fixed widget.
 * It doesn't call queue_resize when children removed;
 * this can reduce flickering in widgets with many children.
 * Of course, it means that you must call gtk_widget_queue_resize manually
 * if you *do* want to remove something and have the size change.
 * Also, of course, if you remove a non-window widget, nothing will
 * happen until the next time something causes redisplay.
 */
/****************** COPYRIGHT STATEMENT **********************
 * This file is Copyright (c) 2001 by J. C. Bradfield.       *
 * This file may be used under the terms of the              *
 * GNU Lesser General Public License (any version).           *
 * The moral rights of the author are asserted.              *
 *                                                           *
 ***************** DISCLAIMER OF WARRANTY ********************
 * This code is not warranted fit for any purpose. See the   *
 * LICENCE file for further information.                     *
 *                                                           *
 *************************************************************/

#include "lazyfixed.h"


static void lazy_fixed_class_init    (GtkFixedClass    *klass);
static void lazy_fixed_init          (LazyFixed *widget);
static void lazy_fixed_remove        (GtkContainer     *container,
				     GtkWidget        *widget);

static GtkFixedClass *parent_class = NULL;


GtkType
lazy_fixed_get_type (void)
{
  static GtkType fixed_type = 0;

  if (!fixed_type)
    {
      static const GtkTypeInfo fixed_info =
      {
	"LazyFixed",
	sizeof (LazyFixed),
	sizeof (LazyFixedClass),
	(GtkClassInitFunc) lazy_fixed_class_init,
	(GtkObjectInitFunc) lazy_fixed_init,
	/* reserved_1 */ NULL,
        /* reserved_2 */ NULL,
        (GtkClassInitFunc) NULL,
      };

      fixed_type = gtk_type_unique (GTK_TYPE_FIXED, &fixed_info);
    }

  return fixed_type;
}

static void
lazy_fixed_class_init (GtkFixedClass *class)
{
  GtkObjectClass *object_class;
  GtkWidgetClass *widget_class;
  GtkContainerClass *container_class;

  object_class = (GtkObjectClass*) class;
  widget_class = (GtkWidgetClass*) class;
  container_class = (GtkContainerClass*) class;

  parent_class = gtk_type_class (GTK_TYPE_FIXED);

  /* override the remove method */
  container_class->remove = lazy_fixed_remove;
}


static void lazy_fixed_init(LazyFixed *w UNUSED) { }

GtkWidget*
lazy_fixed_new (void)
{
  GtkFixed *fixed;

  fixed = gtk_type_new (lazy_fixed_get_type());
  return GTK_WIDGET (fixed);
}


static void
lazy_fixed_remove (GtkContainer *container,
		  GtkWidget    *widget)
{
  GtkFixed *fixed;
  GtkFixedChild *child;
  GList *children;

  g_return_if_fail (container != NULL);
  g_return_if_fail (IS_LAZY_FIXED (container));
  g_return_if_fail (widget != NULL);

  fixed = GTK_FIXED (container);

  children = fixed->children;
  while (children)
    {
      child = children->data;

      if (child->widget == widget)
	{
	  gtk_widget_unparent (widget);

	  fixed->children = g_list_remove_link (fixed->children, children);
	  g_list_free (children);
	  g_free (child);

	  break;
	}

      children = children->next;
    }
}