/* 为样式类添加样式属性 */ LCUI_API int StyleClass_SetStyleAttr( LCUI_StyleClass *style_class, const char *pseudo_class_name, const char *attr_name, const char *attr_value ) { LCUI_StyleAttr *style_attr; if( !style_class ) { return -1; } style_attr = StyleLib_GetStyleAttr( style_class, pseudo_class_name, attr_name ); /* 如果已存在该属性,则覆盖属性值 */ if( style_attr ) { _LCUIString_Copy( &style_attr->attr_value, attr_value ); return 0; } /* 否则,就需要新增属性项了 */ style_attr = malloc( sizeof(LCUI_StyleAttr) ); if( !style_attr ) { return -2; } StyleAttr_Init( style_attr ); /* 保存属性名和属性值 */ _LCUIString_Copy( &style_attr->attr_name, attr_name ); _LCUIString_Copy( &style_attr->attr_value, attr_value ); Queue_AddPointer( &style_class->style_attr, style_attr ); return 0; }
/* 注册一个输入法 */ LCUI_API int LCUIIME_Register( const char *ime_name, LCUIIME_Func *ime_func ) { static int ime_id = 0; // 输入法的ID LCUIIME_Info *ptr_data; if( !imelist_init ) { return -1; } if( LCUIIME_FindByName( ime_name ) != NULL ) { return -2; } ptr_data = (LCUIIME_Info*)malloc( sizeof(LCUIIME_Info) ); if( !ptr_data ) { return -3; } LCUIString_Init( &ptr_data->name ); _LCUIString_Copy( &ptr_data->name, ime_name ); ime_id = ime_id + 1; ptr_data->id = ime_id; memcpy( &ptr_data->func, ime_func, sizeof(LCUIIME_Func) ); Queue_AddPointer( &imelist, ptr_data ); return ime_id; }
/* 添加指定名称的样式类到样式库中 */ LCUI_API LCUI_StyleClass* StyleLib_AddStyleClass( LCUI_StyleLibrary *lib, const char *class_name ) { LCUI_StyleClass *style_class; /* 如果已存在同名类 */ if( StyleLib_GetStyleClass( lib, class_name ) ) { return NULL; } style_class = (LCUI_StyleClass*)malloc( sizeof(LCUI_StyleClass) ); if( !style_class ) { return NULL; } StyleClass_Init( style_class ); /* 保存类名 */ _LCUIString_Copy( &style_class->class_name, class_name ); Queue_AddPointer( &lib->style_classes, style_class ); return style_class; }
/* 更新复选框的图形数据 */ static void CheckBox_ExecDraw(LCUI_Widget *widget) { LCUI_Graph *p; LCUI_CheckBox *check_box; check_box = Widget_GetPrivData(widget); if(_LCUIString_Cmp(&widget->style_name, "custom") == 0) { /* 如果为自定义风格,那就使用用户指定的图形,具体可参考按钮部件的处理方法 */ if( !widget->enabled ) { widget->state = WIDGET_STATE_DISABLE; } switch(widget->state){ case WIDGET_STATE_NORMAL: if( check_box->on ) { p = &check_box->img_on_normal; } else { p = &check_box->img_off_normal; } PictureBox_SetImage(check_box->imgbox, p); break; case WIDGET_STATE_OVERLAY : if( check_box->on ) { p = &check_box->img_on_over; } else { p = &check_box->img_off_over; } PictureBox_SetImage(check_box->imgbox, p); break; case WIDGET_STATE_ACTIVE : if( check_box->on ) { p = &check_box->img_on_down; } else { p = &check_box->img_off_down; } PictureBox_SetImage(check_box->imgbox, p); break; case WIDGET_STATE_DISABLE : if( check_box->on ) { p = &check_box->img_on_disable; } else { p = &check_box->img_off_disable; } PictureBox_SetImage(check_box->imgbox, p); break; default : break; } } else {/* 如果按钮的风格为缺省 */ _LCUIString_Copy(&widget->style_name, "default"); if( !widget->enabled ) { widget->state = WIDGET_STATE_DISABLE; } /* 先释放PictureBox部件中保存的图形数据的指针 */ p = PictureBox_GetImage(check_box->imgbox); Graph_Free(p); /* 由于本函数在退出后,使用局部变量保存的图形数据会无效,因此,申请内存空间来储存 */ p = (LCUI_Graph*)calloc(1,sizeof(LCUI_Graph)); switch(widget->state) { case WIDGET_STATE_NORMAL: if( check_box->on ) { Load_Graph_Default_CheckBox_On_Normal(p); } else { Load_Graph_Default_CheckBox_Off_Normal(p); } PictureBox_SetImage(check_box->imgbox, p); break; case WIDGET_STATE_OVERLAY : if( check_box->on ) { Load_Graph_Default_CheckBox_On_Selected(p); } else { Load_Graph_Default_CheckBox_Off_Selected(p); } PictureBox_SetImage(check_box->imgbox, p); break; case WIDGET_STATE_ACTIVE : if( check_box->on ) { Load_Graph_Default_CheckBox_On_Selected(p); } else { Load_Graph_Default_CheckBox_Off_Selected(p); } PictureBox_SetImage(check_box->imgbox, p); break; case WIDGET_STATE_DISABLE : if( check_box->on ) { Load_Graph_Default_CheckBox_On_Disabled(p); } else { Load_Graph_Default_CheckBox_Off_Disabled(p); } PictureBox_SetImage(check_box->imgbox, p); break; default : break; } } }
/* 更新单选框的图形数据 */ static void RadioButton_ExecUpdate( LCUI_Widget widget ) { int img_id; LCUI_Graph *img_ptr; LCUI_RadioButton *radio_button; radio_button = (LCUI_RadioButton*)Widget_GetPrivData(widget); /* 如果为自定义风格,那就使用用户指定的图形 */ if( _LCUIString_Cmp(&widget->style_name, "custom") == 0 ) { if(widget->enabled == FALSE) { widget->state = WIDGET_STATE_DISABLE; } switch(widget->state) { case WIDGET_STATE_NORMAL: if(radio_button->on) { img_ptr = &radio_button->img_on_normal; } else { img_ptr = &radio_button->img_off_normal; } break; case WIDGET_STATE_OVERLAY : if(radio_button->on) { img_ptr = &radio_button->img_on_over; } else { img_ptr = &radio_button->img_off_over; } break; case WIDGET_STATE_ACTIVE : if(radio_button->on) { img_ptr = &radio_button->img_on_down; } else { img_ptr = &radio_button->img_off_down; } break; case WIDGET_STATE_DISABLE : if(radio_button->on) { img_ptr = &radio_button->img_on_disable; } else { img_ptr = &radio_button->img_off_disable; } break; default:return; } PictureBox_SetImage(radio_button->imgbox, img_ptr); } _LCUIString_Copy( &widget->style_name, "default" ); if( !widget->enabled ) { widget->state = WIDGET_STATE_DISABLE; } switch(widget->state) { case WIDGET_STATE_NORMAL: if(radio_button->on) { img_id = IMG_ON_NORMAL; } else { img_id = IMG_OFF_NORMAL; } break; case WIDGET_STATE_OVERLAY : if(radio_button->on) { img_id = IMG_ON_SELECTED; } else { img_id = IMG_OFF_SELECTED; } break; case WIDGET_STATE_ACTIVE : case WIDGET_STATE_DISABLE : default: return; } img_ptr = PictureBox_GetImage( radio_button->imgbox ); Graph_Free( img_ptr ); img_ptr = (LCUI_Graph*)calloc( 1, sizeof(LCUI_Graph) ); RadioButton_LoadDefaultGraph( img_ptr, img_id ); PictureBox_SetImage( radio_button->imgbox, img_ptr ); }