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

Revision 21116, 9.8 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/* This file is part of the GtkHTML library.
3   
4   Copyright (C) 2000 Helix Code, Inc.
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 "gtkhtmldebug.h"
24#include "htmlcolor.h"
25#include "htmlcolorset.h"
26#include "htmlengine.h"
27#include "htmlengine-edit.h"
28#include "htmlengine-save.h"
29#include "htmlimage.h"
30#include "htmlpainter.h"
31#include "htmlsearch.h"
32#include "htmltable.h"
33#include "htmltablepriv.h"
34#include "htmltablecell.h"
35
36#include "htmlshape.h"
37#include "htmlstyle.h"
38#include "htmlframe.h"
39#include "htmlframeset.h"
40
41
42HTMLFramesetClass html_frameset_class;
43static HTMLObjectClass *parent_class = NULL;
44
45static gint
46html_frameset_get_view_height (HTMLFrameset *set)
47{
48        HTMLObject *o = HTML_OBJECT (set);
49
50        while (o->parent != NULL) {
51                if (HTML_OBJECT_TYPE (o->parent) == HTML_TYPE_FRAMESET) {
52                        return (o->ascent + o->descent);
53                }
54                o = o->parent;
55        }
56        return html_engine_get_view_height (set->parent->engine);
57}
58
59static gint
60html_frameset_get_view_width (HTMLFrameset *set)
61{
62        HTMLObject *o = HTML_OBJECT (set);
63
64        while (o->parent != NULL) {
65                if (HTML_OBJECT_TYPE (o->parent) == HTML_TYPE_FRAMESET) {
66                        return html_engine_get_view_width (HTML_FRAMESET (o->parent)->parent->engine);
67                }
68
69                o = o->parent;
70        }
71        return html_engine_get_view_width (set->parent->engine);
72}
73
74gboolean
75html_frameset_append (HTMLFrameset *set, HTMLObject *frame)
76{
77        g_return_val_if_fail (frame != NULL, FALSE);
78        g_return_val_if_fail (set != NULL, FALSE);
79
80        if (set->frames->len >= set->cols->len * set->rows->len)
81                return FALSE;
82
83               
84        g_ptr_array_add (set->frames, frame);
85        html_object_set_parent (frame, HTML_OBJECT (set));
86        return TRUE;
87}
88
89static void           
90calc_dimension (GPtrArray *dim, gint *span, gint total)
91{
92        HTMLLength *len;
93        int i;
94        int adj;
95        int remain;
96        int num_frac = 0;
97
98        remain = total;
99        for (i = 0; i < dim->len; i++) {
100                len = g_ptr_array_index (dim, i);
101                span[i] = 0;
102
103                if (len->type == HTML_LENGTH_TYPE_PIXELS)
104                        span[i] = len->val;
105                else if (len->type == HTML_LENGTH_TYPE_FRACTION)
106                        num_frac += len->val;
107                else if (len->type == HTML_LENGTH_TYPE_PERCENT)
108                        span[i] = (total * len->val) / 100; 
109
110                remain -= span[i];
111        }
112
113       
114        if (remain > 0 && num_frac) {
115                adj = remain / num_frac;
116                for (i = 0; i < dim->len; i++) {
117                        len = g_ptr_array_index (dim, i);
118                        if (len->type == HTML_LENGTH_TYPE_FRACTION) {
119                                span[i] = adj * len->val;
120                                remain -= span[i];
121                        }
122                }
123        }
124
125        adj = 1;
126        if (remain < 0)
127                adj = -1;
128
129        i = 0; 
130        while (remain != 0) {         
131                if (span[i] > 0) {
132                        span[i] += adj;
133                        remain -= adj;
134                }
135               
136                i++;
137                if (i >= dim->len)
138                        i = 0;
139        }
140}
141
142static gboolean
143html_frameset_real_calc_size (HTMLObject *o, HTMLPainter *painter, GList **changed_objs)
144{
145        HTMLFrameset *set = HTML_FRAMESET (o);
146        HTMLObject *frame = NULL;
147
148        gint view_width;
149        gint view_height;
150
151        gint remain_x;
152        gint remain_y;
153        gint r, c, i;
154
155        gint *widths;
156        gint *heights;
157
158        view_width = html_frameset_get_view_width (set);
159        view_height = html_frameset_get_view_height (set);
160       
161        o->ascent = view_height;
162        o->width = view_width;
163        o->descent = 0;
164
165        heights = g_malloc (set->rows->len * sizeof (gint));
166        widths = g_malloc (set->cols->len * sizeof (gint));
167
168        calc_dimension (set->cols, widths, view_width);
169        calc_dimension (set->rows, heights, view_height);
170
171        remain_y = view_height;
172        for (r = 0; r < set->rows->len; r++) {
173
174                remain_x = view_width;
175                for (c = 0; c < set->cols->len; c++) {
176                        i = (r * set->cols->len) + c;
177
178                        if (i < set->frames->len) {
179                                frame = g_ptr_array_index (set->frames, i);
180                               
181                                if (HTML_OBJECT_TYPE (frame) == HTML_TYPE_FRAME)
182                                        html_frame_set_size (HTML_FRAME (frame), widths[c], heights[r]);
183                                else {
184                                        HTML_OBJECT (frame)->width = widths[c];
185                                        HTML_OBJECT (frame)->ascent = heights[r];
186                                        HTML_OBJECT (frame)->descent = 0;
187                                }
188                                html_object_calc_size (HTML_OBJECT (frame), painter, changed_objs);
189                               
190                                HTML_OBJECT (frame)->x = view_width - remain_x;
191                                HTML_OBJECT (frame)->y = view_height + heights[r] - remain_y;
192
193                        }       
194                       
195                        remain_x -= widths[c];
196                }
197               
198                remain_y -= heights[r];
199        }               
200
201        g_free (widths);
202        g_free (heights);
203        return TRUE;
204}
205
206void
207html_frameset_init (HTMLFrameset *set, GtkHTML *parent, char *rows, char *cols)
208{
209        html_object_init (HTML_OBJECT (set), HTML_OBJECT_CLASS (&html_frameset_class));
210        set->parent = parent;
211       
212        set->cols = NULL;
213        set->rows = NULL;
214
215        set->cols = g_ptr_array_new ();
216        set->rows = g_ptr_array_new ();
217
218        if (cols == NULL)
219                cols = "100%";
220
221        html_length_array_parse (set->cols, cols);
222
223        if (rows == NULL)
224                rows = "100%";
225       
226        html_length_array_parse (set->rows, rows);
227
228        set->frames = g_ptr_array_new ();
229}
230
231
232static void
233draw (HTMLObject *o,
234      HTMLPainter *p,
235      gint x, gint y,
236      gint width, gint height,
237      gint tx, gint ty)
238{
239        HTMLFrameset *set;
240        int i;
241        set = HTML_FRAMESET (o);
242
243        tx += o->x;
244        ty += o->y - o->ascent;
245
246       
247        /* Do nothing by default.  We don't know how to paint ourselves.  */
248        for (i = 0; i < set->frames->len; i++) {
249                html_object_draw (HTML_OBJECT (g_ptr_array_index (set->frames, i)),
250                                  p, x - o->x, y - o->y + o->ascent,
251                                  width, height,
252                                  tx, ty);
253        }
254}
255
256static void
257destroy (HTMLObject *self)
258{
259        HTMLFrameset *set;
260        gint i;
261
262        set = HTML_FRAMESET (self);
263        for (i = 0; i < set->frames->len; i++)
264                html_object_destroy (g_ptr_array_index (set->frames, i));
265
266        html_length_array_destroy (set->cols);
267        html_length_array_destroy (set->rows);
268
269        (* parent_class->destroy) (self);
270}
271
272static void
273set_max_width (HTMLObject *o, HTMLPainter *painter, gint w)
274{
275        HTMLFrameset *set = HTML_FRAMESET (o);
276        gint remain_x;
277        gint c, i;
278        gint *widths;
279
280        (* HTML_OBJECT_CLASS (parent_class)->set_max_width) (o, painter, w);
281        widths     = g_malloc (set->cols->len * sizeof (gint));
282
283        calc_dimension (set->cols, widths, w);
284
285        remain_x = w;
286        for (i = 0; i < set->frames->len; i++) {
287                c = i % set->cols->len;
288                if (i < set->frames->len)
289                        html_object_set_max_width (HTML_OBJECT (g_ptr_array_index (set->frames, i)), painter, widths [c]);
290                remain_x -= widths[c];
291        }
292        g_free (widths);
293}
294
295static HTMLObject*
296check_point (HTMLObject *self,
297             HTMLPainter *painter,
298             gint x, gint y,
299             guint *offset_return,
300             gboolean for_cursor)
301{
302        HTMLFrameset *set = HTML_FRAMESET (self);
303        HTMLObject   *obj;
304        int i;
305
306
307        x -= self->x;
308        y -= self->y - self->ascent;
309
310        for (i = 0; i < set->frames->len; i++) {
311                obj = html_object_check_point (g_ptr_array_index (set->frames, i), painter,
312                                               x, y, offset_return, for_cursor);
313
314                if (obj != NULL)
315                        return obj;
316
317        }
318   
319        return NULL;
320}
321
322static gboolean
323is_container (HTMLObject *self)
324{
325        return TRUE;
326}
327
328/* static void
329reset (HTMLObject *self)
330{
331        HTMLFrameset *set;
332        gint i;
333
334        (* HTML_OBJECT_CLASS (parent_class)->reset) (self);
335        set = HTML_FRAMESET (self);
336        for (i = 0; i < set->frames->len; i++)
337                html_object_reset (g_ptr_array_index (set->frames, i));
338
339} */
340
341static void
342forall (HTMLObject *self,
343        HTMLEngine *e,
344        HTMLObjectForallFunc func,
345        gpointer data)
346{
347        HTMLFrameset *set;
348        gint i;
349
350        set = HTML_FRAMESET (self);
351        for (i = 0; i < set->frames->len; i++)
352                     html_object_forall (g_ptr_array_index (set->frames, i), e, func, data);
353        (* func) (self, e, data);
354}
355 
356
357HTMLObject *
358html_frameset_new (GtkHTML *parent, gchar *rows, gchar *cols)
359{
360        HTMLFrameset *set;
361
362        set = g_new (HTMLFrameset, 1);
363
364        html_frameset_init (set, parent, rows, cols);
365
366        return HTML_OBJECT (set);
367}
368
369static gint
370calc_min_width (HTMLObject *o, HTMLPainter *p)
371{
372        return -1;
373}
374
375void
376html_frameset_type_init (void)
377{
378        html_frameset_class_init (&html_frameset_class, HTML_TYPE_FRAMESET, sizeof (HTMLFrameset));
379}
380
381void
382html_frameset_class_init (HTMLFramesetClass *klass,
383                          HTMLType type,
384                          guint object_size)
385{
386        HTMLObjectClass *object_class = HTML_OBJECT_CLASS (klass);
387
388        html_object_class_init (object_class, type, object_size);
389
390        object_class->calc_size =   html_frameset_real_calc_size;
391        object_class->draw =        draw;
392        object_class->destroy =     destroy;
393        object_class->check_point = check_point;
394        object_class->set_max_width = set_max_width;
395
396        /* object_class->draw_background = draw_background; */
397        object_class->forall = forall;
398        /* object_class->reset = reset; */
399        object_class->is_container = is_container;
400
401        object_class->calc_min_width = calc_min_width;
402        /*
403        object_class->copy = copy;     
404        object_class->op_copy = op_copy;
405        object_class->op_cut = op_cut;
406        object_class->split = split;
407        object_class->merge = merge;
408        object_class->accepts_cursor = accepts_cursor;
409        object_class->destroy = destroy;
410        object_class->calc_preferred_width = calc_preferred_width;
411        object_class->find_anchor = find_anchor;
412        object_class->is_container = is_container;
413        object_class->search = search;
414        object_class->fit_line = fit_line;
415        object_class->append_selection_string = append_selection_string;
416        object_class->head = head;
417        object_class->tail = tail;
418        object_class->next = next;
419        object_class->prev = prev;
420        object_class->save = save;
421        object_class->save_plain = save_plain;
422        object_class->check_page_split = check_page_split;
423        object_class->get_bg_color = get_bg_color;
424        object_class->get_recursive_length = get_recursive_length;
425        object_class->remove_child = remove_child;
426        */
427
428        parent_class = &html_object_class;
429}
430
431
432
433
Note: See TracBrowser for help on using the repository browser.