File: htmlstylesurround.c

package info (click to toggle)
claws-mail-extra-plugins 3.5.0-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 35,040 kB
  • ctags: 10,917
  • sloc: ansic: 86,223; sh: 15,775; makefile: 4,400; perl: 983; yacc: 219; lex: 168
file content (199 lines) | stat: -rw-r--r-- 6,093 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
   Copyright (C) 2000 CodeFactory AB
   Copyright (C) 2000 Jonas Borgstr\366m <jonas@codefactory.se>
   Copyright (C) 2000 Anders Carlsson <andersca@codefactory.se>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.
*/

#include <string.h>

#include "htmlstyle.h"

void
html_style_surround_ref (HtmlStyleSurround *surround)
{
	surround->refcount++;
}

void
html_style_surround_unref (HtmlStyleSurround *surround)
{
	if (!surround)
		return;

	surround->refcount--;

	if (surround->refcount <= 0)
		g_free (surround);
}

void
html_style_set_style_surround (HtmlStyle *style, HtmlStyleSurround *surround)
{
	if (style->surround == surround)
		return;

	if (style->surround)
		html_style_surround_unref (style->surround);

	if (surround) {
		style->surround = surround;
		html_style_surround_ref (style->surround);
	}
}

HtmlStyleSurround *
html_style_surround_new (void)
{
	HtmlStyleSurround *result = g_new0 (HtmlStyleSurround, 1);
	return result;
}

HtmlStyleSurround *
html_style_surround_dup (HtmlStyleSurround *surround)
{
	HtmlStyleSurround *result = html_style_surround_new ();

	if (surround)
		memcpy (result, surround, sizeof (HtmlStyleSurround));

	result->refcount = 0;

	return result;
}

void
html_style_set_position_top (HtmlStyle *style, const HtmlLength *length)
{
	if (!html_length_equals (&style->surround->position.top, length)) {
		if (style->surround->refcount > 1)
			html_style_set_style_surround (style, html_style_surround_dup (style->surround));
		html_length_set (&style->surround->position.top, length);
	}
}

void
html_style_set_position_right (HtmlStyle *style, const HtmlLength *length)
{
	if (!html_length_equals (&style->surround->position.right, length)) {
		if (style->surround->refcount > 1)
			html_style_set_style_surround (style, html_style_surround_dup (style->surround));
		html_length_set (&style->surround->position.right, length);
	}
}

void
html_style_set_position_bottom (HtmlStyle *style, const HtmlLength *length)
{
	if (!html_length_equals (&style->surround->position.bottom, length)) {
		if (style->surround->refcount > 1)
			html_style_set_style_surround (style, html_style_surround_dup (style->surround));
		html_length_set (&style->surround->position.bottom, length);
	}
}

void
html_style_set_position_left (HtmlStyle *style, const HtmlLength *length)
{
	if (!html_length_equals (&style->surround->position.left, length)) {
		if (style->surround->refcount > 1)
			html_style_set_style_surround (style, html_style_surround_dup (style->surround));
		html_length_set (&style->surround->position.left, length);
	}
}

void
html_style_set_margin_top (HtmlStyle *style, const HtmlLength *margin)
{
	if (!html_length_equals (&style->surround->margin.top, margin)) {
		if (style->surround->refcount > 1)
			html_style_set_style_surround (style, html_style_surround_dup (style->surround));
		html_length_set (&style->surround->margin.top, margin);
	}
}

void
html_style_set_margin_bottom (HtmlStyle *style, const HtmlLength *margin)
{
	if (!html_length_equals (&style->surround->margin.bottom, margin)) {
		if (style->surround->refcount > 1)
			html_style_set_style_surround (style, html_style_surround_dup (style->surround));
		html_length_set (&style->surround->margin.bottom, margin);
	}
}

void
html_style_set_margin_left (HtmlStyle *style, const HtmlLength *margin)
{
	if (!html_length_equals (&style->surround->margin.left, margin)) {
		if (style->surround->refcount > 1)
			html_style_set_style_surround (style, html_style_surround_dup (style->surround));
		if (margin->value >= 0)
			html_length_set (&style->surround->margin.left, margin);
	}
}

void
html_style_set_margin_right (HtmlStyle *style, const HtmlLength *margin)
{
	if (!html_length_equals (&style->surround->margin.right, margin)) {
		if (style->surround->refcount > 1)
			html_style_set_style_surround (style, html_style_surround_dup (style->surround));
		html_length_set (&style->surround->margin.right, margin);
	}
}

void
html_style_set_padding_left (HtmlStyle *style, const HtmlLength *padding)
{
	if (!html_length_equals (&style->surround->padding.left, padding)) {
		if (style->surround->refcount > 1)
			html_style_set_style_surround (style, html_style_surround_dup (style->surround));
		html_length_set (&style->surround->padding.left, padding);
	}
}

void
html_style_set_padding_right (HtmlStyle *style, const HtmlLength *padding)
{
	if (!html_length_equals (&style->surround->padding.right, padding)) {
		if (style->surround->refcount > 1)
			html_style_set_style_surround (style, html_style_surround_dup (style->surround));
		html_length_set (&style->surround->padding.right, padding);
	}
}

void
html_style_set_padding_top (HtmlStyle *style, const HtmlLength *padding)
{
	if (!html_length_equals (&style->surround->padding.top, padding)) {
		if (style->surround->refcount > 1)
			html_style_set_style_surround (style, html_style_surround_dup (style->surround));
		html_length_set (&style->surround->padding.top, padding);
	}
}

void
html_style_set_padding_bottom (HtmlStyle *style, const HtmlLength *padding)
{
	if (!html_length_equals (&style->surround->padding.bottom, padding)) {
		if (style->surround->refcount > 1)
			html_style_set_style_surround (style, html_style_surround_dup (style->surround));
		html_length_set (&style->surround->padding.bottom, padding);
	}
}