00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <string.h>
00030 #include "cr-cascade.h"
00031
00032 #define PRIVATE(a_this) ((a_this)->priv)
00033
00034 struct _CRCascadePriv {
00035
00036
00037
00038
00039
00040
00041
00042 CRStyleSheet *sheets[3];
00043 guint ref_count;
00044 };
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 CRCascade *
00064 cr_cascade_new (CRStyleSheet * a_author_sheet,
00065 CRStyleSheet * a_user_sheet, CRStyleSheet * a_ua_sheet)
00066 {
00067 CRCascade *result = NULL;
00068
00069 result = g_try_malloc (sizeof (CRCascade));
00070 if (!result) {
00071 cr_utils_trace_info ("Out of memory");
00072 return NULL;
00073 }
00074 memset (result, 0, sizeof (CRCascade));
00075
00076 PRIVATE (result) = g_try_malloc (sizeof (CRCascadePriv));
00077 if (!PRIVATE (result)) {
00078 cr_utils_trace_info ("Out of memory");
00079 return NULL;
00080 }
00081 memset (PRIVATE (result), 0, sizeof (CRCascadePriv));
00082
00083 if (a_author_sheet) {
00084 cr_cascade_set_sheet (result, a_author_sheet, ORIGIN_AUTHOR);
00085 }
00086 if (a_user_sheet) {
00087 cr_cascade_set_sheet (result, a_user_sheet, ORIGIN_USER);
00088 }
00089 if (a_ua_sheet) {
00090 cr_cascade_set_sheet (result, a_ua_sheet, ORIGIN_UA);
00091 }
00092
00093 return result;
00094 }
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 CRStyleSheet *
00113 cr_cascade_get_sheet (CRCascade * a_this, enum CRStyleOrigin a_origin)
00114 {
00115 g_return_val_if_fail (a_this
00116 && a_origin >= ORIGIN_UA
00117 && a_origin < NB_ORIGINS, NULL);
00118
00119 return PRIVATE (a_this)->sheets[a_origin];
00120 }
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133 enum CRStatus
00134 cr_cascade_set_sheet (CRCascade * a_this,
00135 CRStyleSheet * a_sheet, enum CRStyleOrigin a_origin)
00136 {
00137 g_return_val_if_fail (a_this
00138 && a_sheet
00139 && a_origin >= ORIGIN_UA
00140 && a_origin < NB_ORIGINS, CR_BAD_PARAM_ERROR);
00141
00142 if (PRIVATE (a_this)->sheets[a_origin])
00143 cr_stylesheet_unref (PRIVATE (a_this)->sheets[a_origin]);
00144 PRIVATE (a_this)->sheets[a_origin] = a_sheet;
00145 cr_stylesheet_ref (a_sheet);
00146 a_sheet->origin = a_origin;
00147 return CR_OK;
00148 }
00149
00150
00151
00152
00153
00154
00155
00156
00157 void
00158 cr_cascade_ref (CRCascade * a_this)
00159 {
00160 g_return_if_fail (a_this && PRIVATE (a_this));
00161
00162 PRIVATE (a_this)->ref_count++;
00163 }
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175 void
00176 cr_cascade_unref (CRCascade * a_this)
00177 {
00178 g_return_if_fail (a_this && PRIVATE (a_this));
00179
00180 if (PRIVATE (a_this)->ref_count)
00181 PRIVATE (a_this)->ref_count--;
00182 if (!PRIVATE (a_this)->ref_count) {
00183 cr_cascade_destroy (a_this);
00184 }
00185 }
00186
00187
00188
00189
00190
00191
00192
00193 void
00194 cr_cascade_destroy (CRCascade * a_this)
00195 {
00196 g_return_if_fail (a_this);
00197
00198 if (PRIVATE (a_this)) {
00199 gulong i = 0;
00200
00201 for (i = 0; PRIVATE (a_this)->sheets && i < NB_ORIGINS; i++) {
00202 if (PRIVATE (a_this)->sheets[i]) {
00203 if (cr_stylesheet_unref
00204 (PRIVATE (a_this)->sheets[i])
00205 == TRUE) {
00206 PRIVATE (a_this)->sheets[i] = NULL;
00207 }
00208 }
00209 }
00210 g_free (PRIVATE (a_this));
00211 PRIVATE (a_this) = NULL;
00212 }
00213 g_free (a_this);
00214 }