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 CRCascade *
00061 cr_cascade_new (CRStyleSheet * a_author_sheet,
00062 CRStyleSheet * a_user_sheet, CRStyleSheet * a_ua_sheet)
00063 {
00064 CRCascade *result = NULL;
00065
00066 result = g_try_malloc (sizeof (CRCascade));
00067 if (!result) {
00068 cr_utils_trace_info ("Out of memory");
00069 return NULL;
00070 }
00071 memset (result, 0, sizeof (CRCascade));
00072
00073 PRIVATE (result) = g_try_malloc (sizeof (CRCascadePriv));
00074 if (!PRIVATE (result)) {
00075 cr_utils_trace_info ("Out of memory");
00076 return NULL;
00077 }
00078 memset (PRIVATE (result), 0, sizeof (CRCascadePriv));
00079
00080 if (a_author_sheet) {
00081 cr_cascade_set_sheet (result, a_author_sheet, ORIGIN_AUTHOR);
00082 }
00083 if (a_user_sheet) {
00084 cr_cascade_set_sheet (result, a_user_sheet, ORIGIN_USER);
00085 }
00086 if (a_ua_sheet) {
00087 cr_cascade_set_sheet (result, a_ua_sheet, ORIGIN_UA);
00088 }
00089
00090 return result;
00091 }
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 CRStyleSheet *
00107 cr_cascade_get_sheet (CRCascade * a_this, enum CRStyleOrigin a_origin)
00108 {
00109 g_return_val_if_fail (a_this
00110 && a_origin >= ORIGIN_UA
00111 && a_origin < NB_ORIGINS, NULL);
00112
00113 return PRIVATE (a_this)->sheets[a_origin];
00114 }
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 enum CRStatus
00125 cr_cascade_set_sheet (CRCascade * a_this,
00126 CRStyleSheet * a_sheet, enum CRStyleOrigin a_origin)
00127 {
00128 g_return_val_if_fail (a_this
00129 && a_sheet
00130 && a_origin >= ORIGIN_UA
00131 && a_origin < NB_ORIGINS, CR_BAD_PARAM_ERROR);
00132
00133 if (PRIVATE (a_this)->sheets[a_origin])
00134 cr_stylesheet_unref (PRIVATE (a_this)->sheets[a_origin]);
00135 PRIVATE (a_this)->sheets[a_origin] = a_sheet;
00136 cr_stylesheet_ref (a_sheet);
00137 a_sheet->origin = a_origin;
00138 return CR_OK;
00139 }
00140
00141
00142
00143
00144
00145
00146
00147 void
00148 cr_cascade_ref (CRCascade * a_this)
00149 {
00150 g_return_if_fail (a_this && PRIVATE (a_this));
00151
00152 PRIVATE (a_this)->ref_count++;
00153 }
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 void
00164 cr_cascade_unref (CRCascade * a_this)
00165 {
00166 g_return_if_fail (a_this && PRIVATE (a_this));
00167
00168 if (PRIVATE (a_this)->ref_count)
00169 PRIVATE (a_this)->ref_count--;
00170 if (!PRIVATE (a_this)->ref_count) {
00171 cr_cascade_destroy (a_this);
00172 }
00173 }
00174
00175
00176
00177
00178 void
00179 cr_cascade_destroy (CRCascade * a_this)
00180 {
00181 g_return_if_fail (a_this);
00182
00183 if (PRIVATE (a_this)) {
00184 gulong i = 0;
00185
00186 for (i = 0; PRIVATE (a_this)->sheets && i < NB_ORIGINS; i++) {
00187 if (PRIVATE (a_this)->sheets[i]) {
00188 if (cr_stylesheet_unref
00189 (PRIVATE (a_this)->sheets[i])
00190 == TRUE) {
00191 PRIVATE (a_this)->sheets[i] = NULL;
00192 }
00193 }
00194 }
00195 g_free (PRIVATE (a_this));
00196 PRIVATE (a_this) = NULL;
00197 }
00198 g_free (a_this);
00199 }