source: trunk/third/gtkhtml/src/htmlframeset.c @ 16784

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