1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
---|
2 | /* This file is part of the KDE libraries |
---|
3 | |
---|
4 | Copyright (C) 1997 Martin Jones (mjones@kde.org) |
---|
5 | Copyright (C) 1997 Torben Weis (weis@kde.org) |
---|
6 | Copyright (C) 2000 Helix Code, Inc. |
---|
7 | |
---|
8 | This library is free software; you can redistribute it and/or |
---|
9 | modify it under the terms of the GNU Library General Public |
---|
10 | License as published by the Free Software Foundation; either |
---|
11 | version 2 of the License, or (at your option) any later version. |
---|
12 | |
---|
13 | This library is distributed in the hope that it will be useful, |
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | Library General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU Library General Public License |
---|
19 | along with this library; see the file COPYING.LIB. If not, write to |
---|
20 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
21 | Boston, MA 02111-1307, USA. |
---|
22 | */ |
---|
23 | |
---|
24 | #include <config.h> |
---|
25 | #include "htmlvspace.h" |
---|
26 | #include "htmlclueflow.h" |
---|
27 | #include "htmlpainter.h" |
---|
28 | |
---|
29 | |
---|
30 | HTMLVSpaceClass html_vspace_class; |
---|
31 | static HTMLObjectClass *parent_class = NULL; |
---|
32 | |
---|
33 | |
---|
34 | static void |
---|
35 | copy (HTMLObject *self, |
---|
36 | HTMLObject *dest) |
---|
37 | { |
---|
38 | (* HTML_OBJECT_CLASS (parent_class)->copy) (self, dest); |
---|
39 | |
---|
40 | HTML_VSPACE (dest)->clear = HTML_VSPACE (self)->clear; |
---|
41 | } |
---|
42 | |
---|
43 | static gboolean |
---|
44 | calc_size (HTMLObject *self, HTMLPainter *painter, GList **changed_objs) |
---|
45 | { |
---|
46 | GtkHTMLFontStyle font_style; |
---|
47 | gint new_ascent, new_descent, new_width; |
---|
48 | gboolean changed; |
---|
49 | |
---|
50 | if (self->parent != NULL |
---|
51 | && HTML_OBJECT_TYPE (self->parent) == HTML_TYPE_CLUEFLOW) |
---|
52 | font_style = html_clueflow_get_default_font_style |
---|
53 | (HTML_CLUEFLOW (self->parent)); |
---|
54 | else |
---|
55 | font_style = GTK_HTML_FONT_STYLE_SIZE_3; |
---|
56 | |
---|
57 | new_ascent = html_painter_calc_ascent (painter, font_style, NULL); |
---|
58 | new_descent = html_painter_calc_descent (painter, font_style, NULL); |
---|
59 | new_width = 2 * html_painter_get_pixel_size (painter); |
---|
60 | |
---|
61 | changed = FALSE; |
---|
62 | |
---|
63 | if (new_ascent != self->ascent) { |
---|
64 | self->ascent = new_ascent; |
---|
65 | changed = TRUE; |
---|
66 | } |
---|
67 | |
---|
68 | if (new_descent != self->descent) { |
---|
69 | self->descent = new_descent; |
---|
70 | changed = TRUE; |
---|
71 | } |
---|
72 | |
---|
73 | if (new_width != self->width) { |
---|
74 | self->width = new_width; |
---|
75 | changed = TRUE; |
---|
76 | } |
---|
77 | |
---|
78 | return changed; |
---|
79 | } |
---|
80 | |
---|
81 | |
---|
82 | void |
---|
83 | html_vspace_type_init (void) |
---|
84 | { |
---|
85 | html_vspace_class_init (&html_vspace_class, HTML_TYPE_VSPACE, sizeof (HTMLVSpace)); |
---|
86 | } |
---|
87 | |
---|
88 | void |
---|
89 | html_vspace_class_init (HTMLVSpaceClass *klass, |
---|
90 | HTMLType type, |
---|
91 | guint object_size) |
---|
92 | { |
---|
93 | HTMLObjectClass *object_class; |
---|
94 | |
---|
95 | object_class = HTML_OBJECT_CLASS (klass); |
---|
96 | |
---|
97 | html_object_class_init (object_class, type, object_size); |
---|
98 | |
---|
99 | object_class->copy = copy; |
---|
100 | object_class->calc_size = calc_size; |
---|
101 | |
---|
102 | parent_class = &html_object_class; |
---|
103 | } |
---|
104 | |
---|
105 | void |
---|
106 | html_vspace_init (HTMLVSpace *vspace, |
---|
107 | HTMLVSpaceClass *klass, |
---|
108 | HTMLClearType clear) |
---|
109 | { |
---|
110 | HTMLObject *object; |
---|
111 | |
---|
112 | object = HTML_OBJECT (vspace); |
---|
113 | |
---|
114 | html_object_init (object, HTML_OBJECT_CLASS (klass)); |
---|
115 | |
---|
116 | object->width = 1; |
---|
117 | object->flags |= HTML_OBJECT_FLAG_NEWLINE; |
---|
118 | |
---|
119 | vspace->clear = clear; |
---|
120 | } |
---|
121 | |
---|
122 | HTMLObject * |
---|
123 | html_vspace_new (HTMLClearType clear) |
---|
124 | { |
---|
125 | HTMLVSpace *vspace; |
---|
126 | |
---|
127 | vspace = g_new (HTMLVSpace, 1); |
---|
128 | html_vspace_init (vspace, &html_vspace_class, clear); |
---|
129 | |
---|
130 | return HTML_OBJECT (vspace); |
---|
131 | } |
---|