File: vlazyfixed.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 (203 lines) | stat: -rw-r--r-- 5,153 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/* $Header: /home/jcb/newmj/RCS/vlazyfixed.c,v 11.0 2002/01/05 23:31:09 jcb Rel $
 * vlazyfixed.c
 * Another slight variation on the GTK+ fixed widget.
 * It doesn't call queue_resize when children are removed, added,
 * or move, EXCEPT when the first child is added.
 * This has the consequence that move DOESN'T work, unles you
 * explicitly call resize. But that's OK, since we only use this
 * in a situation where we can physically move the child window.
 */
/****************** 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 "vlazyfixed.h"


static void vlazy_fixed_class_init    (GtkFixedClass    *klass);
static void vlazy_fixed_init          (VlazyFixed *widget);
static void vlazy_fixed_remove        (GtkContainer     *container,
				     GtkWidget        *widget);
static void vlazy_fixed_add (GtkContainer *container,
  GtkWidget    *widget);

static GtkFixedClass *parent_class = NULL;


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

  if (!fixed_type)
    {
      static const GtkTypeInfo fixed_info =
      {
	"VlazyFixed",
	sizeof (VlazyFixed),
	sizeof (VlazyFixedClass),
	(GtkClassInitFunc) vlazy_fixed_class_init,
	(GtkObjectInitFunc) vlazy_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
vlazy_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, put and move method */
  container_class->remove = vlazy_fixed_remove;
  container_class->add = vlazy_fixed_add;
}


static void vlazy_fixed_init(VlazyFixed *w UNUSED) { }

GtkWidget*
vlazy_fixed_new (void)
{
  GtkFixed *fixed;

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


static void
vlazy_fixed_add (GtkContainer *container,
	       GtkWidget    *widget)
{
  g_return_if_fail (container != NULL);
  g_return_if_fail (IS_VLAZY_FIXED (container));
  g_return_if_fail (widget != NULL);

  vlazy_fixed_put (VLAZY_FIXED (container), widget, 0, 0);
}

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

  g_return_if_fail (container != NULL);
  g_return_if_fail (IS_VLAZY_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;
    }
}

void
vlazy_fixed_put (VlazyFixed       *vlfixed,
               GtkWidget      *widget,
               gint16         x,
               gint16         y)
{
  GtkFixed *fixed;
  GtkFixedChild *child_info;

  g_return_if_fail (vlfixed != NULL);
  g_return_if_fail (IS_VLAZY_FIXED (vlfixed));
  g_return_if_fail (widget != NULL);

  fixed = GTK_FIXED(vlfixed);
  child_info = g_new (GtkFixedChild, 1);
  child_info->widget = widget;
  child_info->x = x;
  child_info->y = y;

  gtk_widget_set_parent (widget, GTK_WIDGET (fixed));

  fixed->children = g_list_append (fixed->children, child_info); 

  if (GTK_WIDGET_REALIZED (fixed))
    gtk_widget_realize (widget);

  if (GTK_WIDGET_VISIBLE (fixed) && GTK_WIDGET_VISIBLE (widget))
    {
      if (GTK_WIDGET_MAPPED (fixed))
	gtk_widget_map (widget);
      
      if ( ! fixed->children->prev )
	gtk_widget_queue_resize (GTK_WIDGET (fixed));
    }
}

void
vlazy_fixed_move (VlazyFixed       *vlfixed,
                GtkWidget      *widget,
                gint16         x,
                gint16         y)
{
  GtkFixedChild *child;
  GtkFixed *fixed;
  GList *children;

  g_return_if_fail (vlfixed != NULL);
  g_return_if_fail (IS_VLAZY_FIXED (vlfixed));
  g_return_if_fail (widget != NULL);

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

      if (child->widget == widget)
        {
          child->x = x;
          child->y = y;

          break;
        }
    }
}