source: trunk/third/gtkhtml3/src/htmlcluealigned.c @ 21116

Revision 21116, 4.1 KB checked in by ghudson, 20 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r21115, which included commits to RCS files with non-trunk default branches.
Line 
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2/*
3   Copyright (C) 1997 Martin Jones (mjones@kde.org)
4   (C) 1997 Torben Weis (weis@kde.org)
5
6   This library is free software; you can redistribute it and/or
7   modify it under the terms of the GNU Library General Public
8   License as published by the Free Software Foundation; either
9   version 2 of the License, or (at your option) any later version.
10
11   This library is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   Library General Public License for more details.
15
16   You should have received a copy of the GNU Library General Public License
17   along with this library; see the file COPYING.LIB.  If not, write to
18   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19   Boston, MA 02111-1307, USA.
20*/
21
22#include <config.h>
23#include "htmlcluealigned.h"
24
25
26#define ALIGN_BORDER 0
27
28
29static HTMLClueAlignedClass html_cluealigned_class;
30static HTMLClueClass *parent_class = NULL;
31
32
33/* HTMLObject methods.  */
34
35static void
36copy (HTMLObject *self,
37      HTMLObject *dest)
38{
39        (* HTML_OBJECT_CLASS (parent_class)->copy) (self, dest);
40
41        HTML_CLUEALIGNED (dest)->next_aligned = NULL;
42}
43
44static gboolean
45html_clue_aligned_real_calc_size (HTMLObject *o, HTMLPainter *painter, GList **changed_objs)
46{
47        HTMLObject *obj;
48        gboolean changed;
49        gint old_width, old_ascent;
50
51        changed = HTML_OBJECT_CLASS (&html_clue_class)->calc_size (o, painter, changed_objs);
52
53        old_width = o->width;
54        old_ascent = o->ascent;
55
56        o->width = 0;
57        o->ascent = ALIGN_BORDER;
58        o->descent = 0;
59
60        /* FIXME: Shouldn't it call `calc_size()' on the children first!?!  */
61
62        for (obj = HTML_CLUE (o)->head; obj != 0; obj = obj->next) {
63                if (obj->width > o->width)
64                        o->width = obj->width;
65
66                o->ascent += obj->ascent + obj->descent;
67
68                if (obj->x != ALIGN_BORDER) {
69                        obj->x = ALIGN_BORDER;
70                        changed = TRUE;
71                }
72
73                if (obj->y != o->ascent - obj->descent) {
74                        obj->y = o->ascent - obj->descent;
75                        changed = TRUE;
76                }
77        }
78       
79        o->ascent += ALIGN_BORDER;
80        o->width += ALIGN_BORDER * 2;
81
82        if (old_width != o->width || old_ascent != o->ascent)
83                changed = TRUE;
84
85        return changed;
86}
87
88static void
89set_max_width (HTMLObject *o, HTMLPainter *painter, gint max_width)
90{
91        HTMLObject *obj;
92
93        o->max_width = max_width;
94
95        for (obj = HTML_CLUE (o)->head; obj != 0; obj = obj->next)
96                html_object_set_max_width (obj, painter, max_width);
97}
98
99
100void
101html_cluealigned_type_init (void)
102{
103        html_cluealigned_class_init (&html_cluealigned_class, HTML_TYPE_CLUEALIGNED, sizeof (HTMLClueAligned));
104}
105
106void
107html_cluealigned_class_init (HTMLClueAlignedClass *klass,
108                             HTMLType type,
109                             guint size)
110{
111        HTMLObjectClass *object_class;
112        HTMLClueClass *clue_class;
113
114        clue_class = HTML_CLUE_CLASS (klass);
115        object_class = HTML_OBJECT_CLASS (klass);
116
117        html_clue_class_init (clue_class, type, size);
118
119        /* HTMLObject functions FIXME destroy? */
120
121        object_class->copy = copy;
122        object_class->calc_size = html_clue_aligned_real_calc_size;
123        object_class->set_max_width = set_max_width;
124
125        parent_class = &html_clue_class;
126}
127
128void
129html_cluealigned_init (HTMLClueAligned *aligned,
130                       HTMLClueAlignedClass *klass,
131                       HTMLObject *parent,
132                       gint x, gint y,
133                       gint max_width, gint percent)
134{
135        HTMLClue *clue;
136        HTMLObject *object;
137
138        clue = HTML_CLUE (aligned);
139        object = HTML_OBJECT (aligned);
140
141        html_clue_init (clue, HTML_CLUE_CLASS (klass));
142
143        object->x = x;
144        object->y = y;
145        object->max_width = max_width;
146        object->percent = percent;
147
148        if (percent > 0)
149                object->flags &= ~HTML_OBJECT_FLAG_FIXEDWIDTH;
150
151        clue->valign = HTML_VALIGN_BOTTOM;
152        clue->halign = HTML_HALIGN_LEFT;
153
154        aligned->next_aligned = NULL;
155
156        object->parent = parent;
157        object->flags |= HTML_OBJECT_FLAG_ALIGNED;
158}
159
160HTMLObject *
161html_cluealigned_new (HTMLObject *parent,
162                      gint x, gint y,
163                      gint max_width, gint percent)
164{
165        HTMLClueAligned *aclue;
166
167        aclue = g_new (HTMLClueAligned, 1);
168        html_cluealigned_init (aclue, &html_cluealigned_class,
169                               parent, x, y, max_width, percent);
170
171        return HTML_OBJECT (aclue);
172}
173
Note: See TracBrowser for help on using the repository browser.