Mercurial > dwindows
comparison gtk/dw.c @ 1216:f87e5a44f45e
Attempt at alternating rows for GTK1/2...
probably will need fixes since I wrote this on a different platform.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 09 Oct 2011 11:57:26 +0000 |
parents | 70dca53cb071 |
children | 9512bf242b3e |
comparison
equal
deleted
inserted
replaced
1215:dc8ea09605f7 | 1216:f87e5a44f45e |
---|---|
3036 | 3036 |
3037 gtk_object_set_data(GTK_OBJECT(handle), "_dw_foregdk", (gpointer)foregdk); | 3037 gtk_object_set_data(GTK_OBJECT(handle), "_dw_foregdk", (gpointer)foregdk); |
3038 gtk_object_set_data(GTK_OBJECT(handle), "_dw_backgdk", (gpointer)backgdk); | 3038 gtk_object_set_data(GTK_OBJECT(handle), "_dw_backgdk", (gpointer)backgdk); |
3039 } | 3039 } |
3040 | 3040 |
3041 GdkColor _get_gdkcolor(unsigned long color) | |
3042 { | |
3043 GdkColor temp = _colors[0]; | |
3044 | |
3045 if(color & DW_RGB_COLOR) | |
3046 { | |
3047 temp.pixel = 0; | |
3048 temp.red = DW_RED_VALUE(color) << 8; | |
3049 temp.green = DW_GREEN_VALUE(color) << 8; | |
3050 temp.blue = DW_BLUE_VALUE(color) << 8; | |
3051 | |
3052 gdk_color_alloc(_dw_cmap, &temp); | |
3053 } | |
3054 else if(color != DW_CLR_DEFAULT) | |
3055 { | |
3056 temp = _colors[color]; | |
3057 } | |
3058 return temp; | |
3059 } | |
3060 | |
3041 static int _set_color(HWND handle, unsigned long fore, unsigned long back) | 3061 static int _set_color(HWND handle, unsigned long fore, unsigned long back) |
3042 { | 3062 { |
3043 /* Remember that each color component in X11 use 16 bit no matter | 3063 /* Remember that each color component in X11 use 16 bit no matter |
3044 * what the destination display supports. (and thus GDK) | 3064 * what the destination display supports. (and thus GDK) |
3045 */ | 3065 */ |
3046 GdkColor forecolor, backcolor; | 3066 GdkColor forecolor = _get_gdkcolor(fore); |
3067 GdkColor backcolor = _get_gdkcolor(back); | |
3047 #if GTK_MAJOR_VERSION < 2 | 3068 #if GTK_MAJOR_VERSION < 2 |
3048 GtkStyle *style = gtk_style_copy(gtk_widget_get_style(handle)); | 3069 GtkStyle *style = gtk_style_copy(gtk_widget_get_style(handle)); |
3049 #endif | 3070 #endif |
3050 | 3071 |
3051 if(fore & DW_RGB_COLOR) | 3072 if(fore != DW_CLR_DEFAULT) |
3052 { | 3073 { |
3053 forecolor.pixel = 0; | |
3054 forecolor.red = DW_RED_VALUE(fore) << 8; | |
3055 forecolor.green = DW_GREEN_VALUE(fore) << 8; | |
3056 forecolor.blue = DW_BLUE_VALUE(fore) << 8; | |
3057 | |
3058 gdk_color_alloc(_dw_cmap, &forecolor); | |
3059 | |
3060 #if GTK_MAJOR_VERSION > 1 | |
3061 gtk_widget_modify_text(handle, 0, &forecolor); | |
3062 gtk_widget_modify_text(handle, 1, &forecolor); | |
3063 gtk_widget_modify_fg(handle, 0, &forecolor); | |
3064 gtk_widget_modify_fg(handle, 1, &forecolor); | |
3065 #else | |
3066 if(style) | |
3067 style->text[0] = style->text[1] = style->fg[0] = style->fg[1] = forecolor; | |
3068 #endif | |
3069 } | |
3070 else if(fore != DW_CLR_DEFAULT) | |
3071 { | |
3072 forecolor = _colors[fore]; | |
3073 | |
3074 #if GTK_MAJOR_VERSION > 1 | 3074 #if GTK_MAJOR_VERSION > 1 |
3075 gtk_widget_modify_text(handle, 0, &_colors[fore]); | 3075 gtk_widget_modify_text(handle, 0, &_colors[fore]); |
3076 gtk_widget_modify_text(handle, 1, &_colors[fore]); | 3076 gtk_widget_modify_text(handle, 1, &_colors[fore]); |
3077 gtk_widget_modify_fg(handle, 0, &_colors[fore]); | 3077 gtk_widget_modify_fg(handle, 0, &_colors[fore]); |
3078 gtk_widget_modify_fg(handle, 1, &_colors[fore]); | 3078 gtk_widget_modify_fg(handle, 1, &_colors[fore]); |
3079 #else | 3079 #else |
3080 if(style) | 3080 if(style) |
3081 style->text[0] = style->text[1] = style->fg[0] = style->fg[1] = _colors[fore]; | 3081 style->text[0] = style->text[1] = style->fg[0] = style->fg[1] = _colors[fore]; |
3082 #endif | 3082 #endif |
3083 } | 3083 } |
3084 if(back & DW_RGB_COLOR) | 3084 if(back != DW_CLR_DEFAULT) |
3085 { | 3085 { |
3086 backcolor.pixel = 0; | |
3087 backcolor.red = DW_RED_VALUE(back) << 8; | |
3088 backcolor.green = DW_GREEN_VALUE(back) << 8; | |
3089 backcolor.blue = DW_BLUE_VALUE(back) << 8; | |
3090 | |
3091 gdk_color_alloc(_dw_cmap, &backcolor); | |
3092 | |
3093 #if GTK_MAJOR_VERSION > 1 | |
3094 gtk_widget_modify_base(handle, 0, &backcolor); | |
3095 gtk_widget_modify_base(handle, 1, &backcolor); | |
3096 gtk_widget_modify_bg(handle, 0, &backcolor); | |
3097 gtk_widget_modify_bg(handle, 1, &backcolor); | |
3098 #else | |
3099 if(style) | |
3100 style->base[0] = style->base[1] = style->bg[0] = style->bg[1] = backcolor; | |
3101 #endif | |
3102 } | |
3103 else if(back != DW_CLR_DEFAULT) | |
3104 { | |
3105 backcolor = _colors[back]; | |
3106 | |
3107 #if GTK_MAJOR_VERSION > 1 | 3086 #if GTK_MAJOR_VERSION > 1 |
3108 gtk_widget_modify_base(handle, 0, &_colors[back]); | 3087 gtk_widget_modify_base(handle, 0, &_colors[back]); |
3109 gtk_widget_modify_base(handle, 1, &_colors[back]); | 3088 gtk_widget_modify_base(handle, 1, &_colors[back]); |
3110 gtk_widget_modify_bg(handle, 0, &_colors[back]); | 3089 gtk_widget_modify_bg(handle, 0, &_colors[back]); |
3111 gtk_widget_modify_bg(handle, 1, &_colors[back]); | 3090 gtk_widget_modify_bg(handle, 1, &_colors[back]); |
3135 gtk_style_unref(style); | 3114 gtk_style_unref(style); |
3136 } | 3115 } |
3137 #endif | 3116 #endif |
3138 return TRUE; | 3117 return TRUE; |
3139 } | 3118 } |
3119 | |
3120 void _update_clist_rows(HWND handle) | |
3121 { | |
3122 if(GTK_IS_CLIST(handle)) | |
3123 { | |
3124 int z, rowcount = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(handle), "_dw_rowcount")); | |
3125 unsigned long odd = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(handle), "_dw_oddcol")); | |
3126 unsigned long even = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(handle), "_dw_evencol")); | |
3127 GdkColor *backcol = (GdkColor *)gtk_object_get_data(GTK_OBJECT(handle), "_dw_backgdk"); | |
3128 | |
3129 if(!backcol) | |
3130 backcol = &_colors[DW_CLR_WHITE]; | |
3131 | |
3132 if(odd != DW_RGB_TRANSPARENT && even != DW_RGB_TRANSPARENT) | |
3133 { | |
3134 GdkColor oddcol = _get_gdkcolor(odd); | |
3135 GdkColor evencol = _get_gdkcolor(even); | |
3136 | |
3137 for(z=0;z<rowcount;z++) | |
3138 { | |
3139 int which = z % 2; | |
3140 | |
3141 if(which) | |
3142 gtk_clist_set_background(GTK_CLIST(handle), z, odd != DW_RGB_TRANSPARENT ? &oddcol : backcol); | |
3143 else if(!which) | |
3144 gtk_clist_set_background(GTK_CLIST(handle), z, even != DW_RGB_TRANSPARENT ? &evencol : backcol); | |
3145 } | |
3146 } | |
3147 } | |
3148 } | |
3149 | |
3140 /* | 3150 /* |
3141 * Sets the colors used by a specified window (widget) handle. | 3151 * Sets the colors used by a specified window (widget) handle. |
3142 * Parameters: | 3152 * Parameters: |
3143 * handle: The window (widget) handle. | 3153 * handle: The window (widget) handle. |
3144 * fore: Foreground color in RGB format. | 3154 * fore: Foreground color in RGB format. |
6978 | 6988 |
6979 strftime(textbuffer, 100, "%X", &curtm); | 6989 strftime(textbuffer, 100, "%X", &curtm); |
6980 | 6990 |
6981 gtk_clist_set_text(GTK_CLIST(clist), row, column, textbuffer); | 6991 gtk_clist_set_text(GTK_CLIST(clist), row, column, textbuffer); |
6982 } | 6992 } |
6993 _update_clist_rows(handle); | |
6983 DW_MUTEX_UNLOCK; | 6994 DW_MUTEX_UNLOCK; |
6984 } | 6995 } |
6985 | 6996 |
6986 /* | 6997 /* |
6987 * Sets an item in specified row and column to the given data. | 6998 * Sets an item in specified row and column to the given data. |
7125 * DW_RGB_TRANSPARENT will disable coloring rows. | 7136 * DW_RGB_TRANSPARENT will disable coloring rows. |
7126 * DW_CLR_DEFAULT will use the system default alternating row colors. | 7137 * DW_CLR_DEFAULT will use the system default alternating row colors. |
7127 */ | 7138 */ |
7128 void API dw_container_set_row_bg(HWND handle, unsigned long oddcolor, unsigned long evencolor) | 7139 void API dw_container_set_row_bg(HWND handle, unsigned long oddcolor, unsigned long evencolor) |
7129 { | 7140 { |
7141 GtkWidget *clist; | |
7142 int _locked_by_me = FALSE; | |
7143 | |
7144 DW_MUTEX_LOCK; | |
7145 clist = gtk_object_get_user_data(GTK_OBJECT(handle)); | |
7146 | |
7147 if(clist && GTK_IS_CLIST(clist)) | |
7148 { | |
7149 gtk_object_set_data(GTK_OBJECT(handle), "_dw_oddcol", GINT_TO_POINTER(oddcolor)); | |
7150 gtk_object_set_data(GTK_OBJECT(handle), "_dw_evencol", GINT_TO_POINTER(evencolor)); | |
7151 _update_clist_rows(handle); | |
7152 } | |
7153 DW_MUTEX_UNLOCK; | |
7130 } | 7154 } |
7131 | 7155 |
7132 /* | 7156 /* |
7133 * Sets the width of a column in the container. | 7157 * Sets the width of a column in the container. |
7134 * Parameters: | 7158 * Parameters: |
7239 rows = 0; | 7263 rows = 0; |
7240 else | 7264 else |
7241 rows -= rowcount; | 7265 rows -= rowcount; |
7242 | 7266 |
7243 gtk_object_set_data(GTK_OBJECT(clist), "_dw_rowcount", GINT_TO_POINTER(rows)); | 7267 gtk_object_set_data(GTK_OBJECT(clist), "_dw_rowcount", GINT_TO_POINTER(rows)); |
7268 _update_clist_rows(handle); | |
7244 } | 7269 } |
7245 DW_MUTEX_UNLOCK; | 7270 DW_MUTEX_UNLOCK; |
7246 } | 7271 } |
7247 | 7272 |
7248 /* | 7273 /* |
7491 gtk_clist_remove(GTK_CLIST(clist), z); | 7516 gtk_clist_remove(GTK_CLIST(clist), z); |
7492 | 7517 |
7493 rowcount--; | 7518 rowcount--; |
7494 | 7519 |
7495 gtk_object_set_data(GTK_OBJECT(clist), "_dw_rowcount", GINT_TO_POINTER(rowcount)); | 7520 gtk_object_set_data(GTK_OBJECT(clist), "_dw_rowcount", GINT_TO_POINTER(rowcount)); |
7521 _update_clist_rows(handle); | |
7496 DW_MUTEX_UNLOCK; | 7522 DW_MUTEX_UNLOCK; |
7497 return; | 7523 return; |
7498 } | 7524 } |
7499 } | 7525 } |
7500 | 7526 |