source: trunk/third/gtkhtml/src/htmlcolor.c @ 16767

Revision 16767, 2.5 KB checked in by ghudson, 23 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r16766, 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    Authors:           Radek Doulik (rodo@helixcode.com)
6
7    This library is free software; you can redistribute it and/or
8    modify it under the terms of the GNU Library General Public
9    License as published by the Free Software Foundation; either
10    version 2 of the License, or (at your option) any later version.
11
12    This library is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    Library General Public License for more details.
16
17    You should have received a copy of the GNU Library General Public License
18    along with this library; see the file COPYING.LIB.  If not, write to
19    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20    Boston, MA 02111-1307, USA.
21
22*/
23
24#include <config.h>
25#include <gdk/gdk.h>
26
27#include "htmlcolor.h"
28#include "htmlpainter.h"
29
30HTMLColor *
31html_color_new (void)
32{
33        HTMLColor *nc = g_new0 (HTMLColor, 1);
34
35        nc->refcount = 1;
36
37        return nc;
38}
39
40HTMLColor *
41html_color_new_from_gdk_color (const GdkColor *color)
42{
43        HTMLColor *nc = html_color_new ();
44
45        nc->color = *color;
46
47        return nc;
48}
49
50HTMLColor *
51html_color_new_from_rgb (gushort red, gushort green, gushort blue)
52{
53        HTMLColor *nc = html_color_new ();
54
55        nc->color.red   = red;
56        nc->color.green = green;
57        nc->color.blue  = blue;
58
59        return nc;
60}
61
62void
63html_color_ref (HTMLColor *color)
64{
65        g_assert (color);
66
67        color->refcount ++;
68}
69
70void
71html_color_unref (HTMLColor *color)
72{
73        g_assert (color);
74        g_assert (color->refcount > 0);
75
76        color->refcount --;
77
78        if (!color->refcount) {
79                /* if (color->allocated)
80                   g_warning ("FIXME, color free\n"); */
81                /* FIXME commented out to catch g_asserts on refcount so we could hunt "too much unrefs" bugs */
82                g_free (color);
83        }
84}
85
86void
87html_color_alloc (HTMLColor *color, HTMLPainter *painter)
88{
89        g_assert (color);
90
91        if (!color->allocated) {
92                html_painter_alloc_color (painter, &color->color);
93                color->allocated = TRUE;
94        }
95}
96
97gboolean
98html_color_equal (HTMLColor *color1, HTMLColor *color2)
99{
100        g_assert (color1);
101        g_assert (color2);
102
103        return gdk_color_equal (&color1->color, &color2->color);
104}
105
106void
107html_color_set (HTMLColor *color, GdkColor *c)
108{
109        /* if (color->allocated)
110           g_warning ("FIXME, color free\n"); */
111        color->allocated = FALSE;
112        color->color = *c;
113}
Note: See TracBrowser for help on using the repository browser.