mirror of
https://github.com/lc-soft/LCUI.git
synced 2026-11-30 16:48:21 +01:00
将 CSS 数据操作代码抽离至 css_library.c,调整相关函数
This commit is contained in:
@@ -2,5 +2,5 @@ AUTOMAKE_OPTIONS=foreign
|
||||
SUBDIRS=widget
|
||||
# Headers to install
|
||||
pkginclude_HEADERS = widget_base.h widget_task.h widget_library.h \
|
||||
widget_event.h widget_paint.h widget.h css_parser.h builder.h
|
||||
widget_event.h widget_paint.h widget.h css_library.h css_parser.h builder.h
|
||||
pkgincludedir=$(prefix)/include/LCUI/gui
|
||||
|
||||
@@ -0,0 +1,236 @@
|
||||
/* ***************************************************************************
|
||||
* css_library.h -- css library operation module.
|
||||
*
|
||||
* Copyright (C) 2015-2016 by Liu Chao <lc-soft@live.cn>
|
||||
*
|
||||
* This file is part of the LCUI project, and may only be used, modified, and
|
||||
* distributed under the terms of the GPLv2.
|
||||
*
|
||||
* (GPLv2 is abbreviation of GNU General Public License Version 2)
|
||||
*
|
||||
* By continuing to use, modify, or distribute this file you indicate that you
|
||||
* have read the license and understand and accept it fully.
|
||||
*
|
||||
* The LCUI project 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 GPL v2 for more details.
|
||||
*
|
||||
* You should have received a copy of the GPLv2 along with this file. It is
|
||||
* usually in the LICENSE.TXT file, If not, see <http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
/* ****************************************************************************
|
||||
* css_library.h -- CSS 样式库操作模块
|
||||
*
|
||||
* 版权所有 (C) 2015-2016 归属于 刘超 <lc-soft@live.cn>
|
||||
*
|
||||
* 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。
|
||||
*
|
||||
* (GPLv2 是 GNU通用公共许可证第二版 的英文缩写)
|
||||
*
|
||||
* 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。
|
||||
*
|
||||
* LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特
|
||||
* 定用途的隐含担保,详情请参照GPLv2许可协议。
|
||||
*
|
||||
* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
|
||||
#ifndef LCUI_CSS_LIBRARY_H
|
||||
#define LCUI_CSS_LIBRARY_H
|
||||
|
||||
#define MAX_SELECTOR_LEN 1024
|
||||
#define MAX_SELECTOR_DEPTH 32
|
||||
|
||||
/** 样式属性名 */
|
||||
enum LCUI_StyleKeyName {
|
||||
// position start
|
||||
key_left,
|
||||
key_right,
|
||||
key_top,
|
||||
key_bottom,
|
||||
key_position,
|
||||
// position end
|
||||
|
||||
// display start
|
||||
key_visible,
|
||||
key_display,
|
||||
// display end
|
||||
|
||||
key_z_index,
|
||||
key_opacity,
|
||||
key_box_sizing,
|
||||
key_width,
|
||||
key_min_width,
|
||||
key_max_width,
|
||||
key_height,
|
||||
key_min_height,
|
||||
key_max_height,
|
||||
key_margin_top,
|
||||
key_margin_right,
|
||||
key_margin_bottom,
|
||||
key_margin_left,
|
||||
key_padding_top,
|
||||
key_padding_right,
|
||||
key_padding_bottom,
|
||||
key_padding_left,
|
||||
key_vertical_align,
|
||||
|
||||
// border start
|
||||
key_border_color,
|
||||
key_border_style,
|
||||
key_border_width,
|
||||
key_border_top_width,
|
||||
key_border_top_style,
|
||||
key_border_top_color,
|
||||
key_border_right_width,
|
||||
key_border_right_style,
|
||||
key_border_right_color,
|
||||
key_border_bottom_width,
|
||||
key_border_bottom_style,
|
||||
key_border_bottom_color,
|
||||
key_border_left_width,
|
||||
key_border_left_style,
|
||||
key_border_left_color,
|
||||
key_border_top_left_radius,
|
||||
key_border_top_right_radius,
|
||||
key_border_bottom_left_radius,
|
||||
key_border_bottom_right_radius,
|
||||
// border end
|
||||
|
||||
// background start
|
||||
key_background_color,
|
||||
key_background_image,
|
||||
key_background_size,
|
||||
key_background_size_width,
|
||||
key_background_size_height,
|
||||
key_background_repeat,
|
||||
key_background_repeat_x,
|
||||
key_background_repeat_y,
|
||||
key_background_position,
|
||||
key_background_position_x,
|
||||
key_background_position_y,
|
||||
key_background_origin,
|
||||
// background end
|
||||
|
||||
// box shadow start
|
||||
key_box_shadow_x,
|
||||
key_box_shadow_y,
|
||||
key_box_shadow_spread,
|
||||
key_box_shadow_blur,
|
||||
key_box_shadow_color,
|
||||
// box shadow end
|
||||
|
||||
key_pointer_events,
|
||||
key_focusable,
|
||||
STYLE_KEY_TOTAL
|
||||
};
|
||||
|
||||
#define key_display_start key_visible
|
||||
#define key_display_end key_display
|
||||
#define key_position_start key_left
|
||||
#define key_position_end key_position
|
||||
#define key_border_start key_border_color
|
||||
#define key_border_end key_border_bottom_right_radius
|
||||
#define key_background_start key_background_color
|
||||
#define key_background_end key_background_origin
|
||||
#define key_box_shadow_start key_box_shadow_x
|
||||
#define key_box_shadow_end key_box_shadow_color
|
||||
|
||||
typedef struct LCUI_StyleSheetRec_ {
|
||||
LCUI_Style sheet;
|
||||
int length;
|
||||
} LCUI_StyleSheetRec, *LCUI_StyleSheet;
|
||||
|
||||
/** 选择器结点结构 */
|
||||
typedef struct LCUI_SelectorNodeRec_ {
|
||||
char *id; /**< ID */
|
||||
char *type; /**< 类型名称 */
|
||||
char **classes; /**< 样式类列表 */
|
||||
char **status; /**< 状态列表 */
|
||||
char *fullname; /**< 全名,由 id、type、classes、status 组合而成 */
|
||||
int rank; /**< 权值 */
|
||||
} LCUI_SelectorNodeRec, *LCUI_SelectorNode;
|
||||
|
||||
/** 选择器结构 */
|
||||
typedef struct LCUI_SelectorRec_ {
|
||||
int rank; /**< 权值,决定优先级 */
|
||||
int batch_num; /**< 批次号 */
|
||||
int length; /**< 选择器结点长度 */
|
||||
unsigned int hash; /**< 哈希值 */
|
||||
LCUI_SelectorNode *nodes; /**< 选择器结点列表 */
|
||||
} LCUI_SelectorRec, *LCUI_Selector;
|
||||
|
||||
#define SetStyle(S, NAME, VAL, TYPE) S->sheet[NAME].is_valid = TRUE, \
|
||||
S->sheet[NAME].is_changed = TRUE, \
|
||||
S->sheet[NAME].type = SVT_##TYPE, \
|
||||
S->sheet[NAME].val_##TYPE = VAL
|
||||
|
||||
#define LCUI_FindStyleSheet(S, L) LCUI_FindStyleSheetFromGroup(0, NULL, S, L)
|
||||
|
||||
LCUI_API LCUI_StyleSheet StyleSheet( void );
|
||||
|
||||
LCUI_API void StyleSheet_Clear( LCUI_StyleSheet ss );
|
||||
|
||||
LCUI_API void StyleSheet_Delete( LCUI_StyleSheet ss );
|
||||
|
||||
LCUI_API int StyleSheet_Merge( LCUI_StyleSheet dest, LCUI_StyleSheet src );
|
||||
|
||||
LCUI_API int StyleSheet_Replace( LCUI_StyleSheet dest, LCUI_StyleSheet src );
|
||||
|
||||
LCUI_API LCUI_Selector Selector( const char *selector );
|
||||
|
||||
LCUI_API void Selector_Update( LCUI_Selector s );
|
||||
|
||||
LCUI_API void Selector_Delete( LCUI_Selector s );
|
||||
|
||||
LCUI_API int SelectorNode_GetNames( LCUI_SelectorNode sn, LinkedList *names );
|
||||
|
||||
LCUI_API int SelectorNode_Update( LCUI_SelectorNode node );
|
||||
|
||||
/**
|
||||
* 匹配选择器节点
|
||||
* 左边的选择器必须包含右边的选择器的所有属性。
|
||||
*/
|
||||
LCUI_API LCUI_BOOL SelectorNode_Match( LCUI_SelectorNode sn1,
|
||||
LCUI_SelectorNode sn2 );
|
||||
|
||||
LCUI_API int LCUI_PutStyleSheet( LCUI_Selector selector,
|
||||
LCUI_StyleSheet in_ss, const char *space );
|
||||
|
||||
/**
|
||||
* 从指定组中查找样式表
|
||||
* @param[in] group 组号
|
||||
* @param[in] name 选择器结点名称,若为 NULL,则根据选择器结点生成名称
|
||||
* @param[in] s 选择器
|
||||
* @param[out] list 找到的样式表列表
|
||||
*/
|
||||
LCUI_API int LCUI_FindStyleSheetFromGroup( int group, const char *name,
|
||||
LCUI_Selector s, LinkedList *list );
|
||||
|
||||
LCUI_API void LCUI_GetStyleSheet( LCUI_Selector s, LCUI_StyleSheet out_ss );
|
||||
|
||||
LCUI_API int LCUI_AddStyleName( int key, const char *name );
|
||||
|
||||
LCUI_API int LCUI_AddStyleValue( int key, const char *name );
|
||||
|
||||
LCUI_API int LCUI_GetStyleValue( const char *str );
|
||||
|
||||
LCUI_API const char *LCUI_GetStyleValueName( int val );
|
||||
|
||||
LCUI_API const char *LCUI_GetStyleName( int key );
|
||||
|
||||
LCUI_API int LCUI_GetStyleTotal( void );
|
||||
|
||||
LCUI_API void LCUI_PrintStyleSheet( LCUI_StyleSheet ss );
|
||||
|
||||
LCUI_API void LCUI_PrintSelector( LCUI_Selector selector );
|
||||
|
||||
LCUI_API void LCUI_PrintCSSLibrary( void );
|
||||
|
||||
LCUI_API void LCUI_InitCSSLibrary( void );
|
||||
|
||||
LCUI_API void LCUI_ExitCSSLibrary( void );
|
||||
|
||||
#endif
|
||||
@@ -49,28 +49,25 @@ typedef struct LCUI_StyleParserRec_ {
|
||||
int (*parse)(LCUI_StyleSheet, int, const char*);
|
||||
} LCUI_StyleParserRec, *LCUI_StyleParser;
|
||||
|
||||
LCUI_API int GetStyleOption( const char *str );
|
||||
LCUI_API int LCUI_GetStyleValue( const char *str );
|
||||
|
||||
LCUI_API const char *GetStyleOptionName( int val );
|
||||
LCUI_API const char *LCUI_GetStyleValueName( int val );
|
||||
|
||||
LCUI_API const char *GetStyleName( int key );
|
||||
LCUI_API const char *LCUI_GetStyleName( int key );
|
||||
|
||||
/** 初始化 LCUI 的 CSS 代码解析功能 */
|
||||
void LCUICSS_Init(void);
|
||||
LCUI_API void LCUI_InitCSSParser( void );
|
||||
|
||||
/** 从文件中载入CSS样式数据,并导入至样式库中 */
|
||||
LCUI_API int LCUICSS_LoadFile( const char *filepath );
|
||||
LCUI_API int LCUI_LoadCSSFile( const char *filepath );
|
||||
|
||||
/** 从字符串中载入CSS样式数据,并导入至样式库中 */
|
||||
LCUI_API int LCUICSS_LoadString( const char *str, const char *space );
|
||||
LCUI_API int LCUI_LoadCSSString( const char *str, const char *space );
|
||||
|
||||
void LCUICSS_Destroy(void);
|
||||
|
||||
/** 获取当前记录的样式属性的总数 */
|
||||
int LCUICSS_GetStyleTotal(void);
|
||||
LCUI_API void LCUI_ExitCSSParser(void);
|
||||
|
||||
/** 注册新的属性和对应的属性值解析器 */
|
||||
LCUI_API int LCUICSS_AddParser( LCUI_StyleParser sp );
|
||||
LCUI_API int LCUI_AddCSSParser( LCUI_StyleParser sp );
|
||||
|
||||
LCUI_END_HEADER
|
||||
|
||||
|
||||
@@ -42,10 +42,8 @@
|
||||
|
||||
LCUI_BEGIN_HEADER
|
||||
|
||||
/** 如果没有包含 widget_build.h 头文件 */
|
||||
#ifndef LCUI_WIDGET_BUILD_H
|
||||
typedef struct LCUI_WidgetBase* LCUI_Widget;
|
||||
#endif
|
||||
#include <LCUI/gui/css_library.h>
|
||||
#include <LCUI/gui/css_parser.h>
|
||||
|
||||
/** 部件样式 */
|
||||
typedef struct LCUI_WidgetStyle {
|
||||
@@ -67,113 +65,6 @@ typedef struct LCUI_WidgetStyle {
|
||||
int pointer_events; /**< 事件的处理方式 */
|
||||
} LCUI_WidgetStyle;
|
||||
|
||||
/** 样式属性名 */
|
||||
enum LCUI_StyleKeyName {
|
||||
key_position_start,
|
||||
key_left,
|
||||
key_right,
|
||||
key_top,
|
||||
key_bottom,
|
||||
key_position,
|
||||
key_position_end,
|
||||
key_display_start,
|
||||
key_visible,
|
||||
key_display,
|
||||
key_display_end,
|
||||
key_z_index,
|
||||
key_opacity,
|
||||
key_box_sizing,
|
||||
key_width,
|
||||
key_min_width,
|
||||
key_max_width,
|
||||
key_height,
|
||||
key_min_height,
|
||||
key_max_height,
|
||||
key_margin_top,
|
||||
key_margin_right,
|
||||
key_margin_bottom,
|
||||
key_margin_left,
|
||||
key_padding_top,
|
||||
key_padding_right,
|
||||
key_padding_bottom,
|
||||
key_padding_left,
|
||||
key_vertical_align,
|
||||
key_border_start,
|
||||
key_border_color,
|
||||
key_border_style,
|
||||
key_border_width,
|
||||
key_border_top_width,
|
||||
key_border_top_style,
|
||||
key_border_top_color,
|
||||
key_border_right_width,
|
||||
key_border_right_style,
|
||||
key_border_right_color,
|
||||
key_border_bottom_width,
|
||||
key_border_bottom_style,
|
||||
key_border_bottom_color,
|
||||
key_border_left_width,
|
||||
key_border_left_style,
|
||||
key_border_left_color,
|
||||
key_border_top_left_radius,
|
||||
key_border_top_right_radius,
|
||||
key_border_bottom_left_radius,
|
||||
key_border_bottom_right_radius,
|
||||
key_border_end,
|
||||
key_background_start,
|
||||
key_background_color,
|
||||
key_background_image,
|
||||
key_background_size,
|
||||
key_background_size_width,
|
||||
key_background_size_height,
|
||||
key_background_repeat,
|
||||
key_background_repeat_x,
|
||||
key_background_repeat_y,
|
||||
key_background_position,
|
||||
key_background_position_x,
|
||||
key_background_position_y,
|
||||
key_background_origin,
|
||||
key_background_end,
|
||||
key_box_shadow_start,
|
||||
key_box_shadow_x,
|
||||
key_box_shadow_y,
|
||||
key_box_shadow_spread,
|
||||
key_box_shadow_blur,
|
||||
key_box_shadow_color,
|
||||
key_box_shadow_end,
|
||||
key_pointer_events,
|
||||
key_focusable,
|
||||
STYLE_KEY_TOTAL
|
||||
};
|
||||
|
||||
typedef struct LCUI_StyleSheetRec_ {
|
||||
LCUI_Style sheet;
|
||||
int length;
|
||||
} LCUI_StyleSheetRec, *LCUI_StyleSheet;
|
||||
|
||||
/** 选择器结点结构 */
|
||||
typedef struct LCUI_SelectorNodeRec_ {
|
||||
char *id; /**< ID */
|
||||
char *type; /**< 类型名称 */
|
||||
char **classes; /**< 样式类列表 */
|
||||
char **status; /**< 状态列表 */
|
||||
char *fullname; /**< 全名,由 id、type、classes、status 组合而成 */
|
||||
int rank; /**< 权值 */
|
||||
} LCUI_SelectorNodeRec, *LCUI_SelectorNode;
|
||||
|
||||
/** 选择器结构 */
|
||||
typedef struct LCUI_SelectorRec_ {
|
||||
int rank; /**< 权值,决定优先级 */
|
||||
int batch_num; /**< 批次号 */
|
||||
int length; /**< 选择器结点长度 */
|
||||
unsigned int hash; /**< 哈希值 */
|
||||
LCUI_SelectorNode *nodes; /**< 选择器结点列表 */
|
||||
} LCUI_SelectorRec, *LCUI_Selector;
|
||||
|
||||
#define SetStyle(S, NAME, VAL, TYPE) S->sheet[NAME].is_valid = TRUE, \
|
||||
S->sheet[NAME].is_changed = TRUE, \
|
||||
S->sheet[NAME].type = SVT_##TYPE, \
|
||||
S->sheet[NAME].val_##TYPE = VAL
|
||||
|
||||
/** 部件任务类型,按照任务的依赖顺序排列 */
|
||||
enum WidgetTaskType {
|
||||
WTT_REFRESH_STYLE, /**< 刷新部件全部样式 */
|
||||
|
||||
@@ -78,7 +78,7 @@ LCUI_API LCUI_BOOL Selector_Compare( LCUI_Selector s1, LCUI_Selector s2 );
|
||||
LCUI_API LCUI_BOOL Selector_MatchPath( LCUI_Selector selector, LCUI_Widget *wlist );
|
||||
|
||||
/** 向样式库添加样式表 */
|
||||
LCUI_API int LCUI_PutStyle( LCUI_Selector selector,
|
||||
LCUI_API int LCUI_PutStyleSheet( LCUI_Selector selector,
|
||||
LCUI_StyleSheet in_ss, const char *space );
|
||||
|
||||
/** 打印样式表的内容 */
|
||||
@@ -88,7 +88,7 @@ LCUI_API void LCUI_PrintStyleSheet( LCUI_StyleSheet ss );
|
||||
LCUI_API void LCUI_PrintSelector( LCUI_Selector selector );
|
||||
|
||||
/** 打印样式库中的内容 */
|
||||
LCUI_API void LCUI_PrintStyleLibrary(void);
|
||||
LCUI_API void LCUI_PrintCSSLibrary(void);
|
||||
|
||||
/** 计算部件继承得到的样式表 */
|
||||
LCUI_API void Widget_GetInheritStyle( LCUI_Widget w, LCUI_StyleSheet out_ss );
|
||||
@@ -108,6 +108,4 @@ LCUI_API LCUI_Selector Widget_GetSelector( LCUI_Widget w );
|
||||
/** 处理子级部件样式变化 */
|
||||
LCUI_API int Widget_HandleChildrenStyleChange( LCUI_Widget w, int type, const char *name );
|
||||
|
||||
#include <LCUI/gui/css_parser.h>
|
||||
|
||||
#endif
|
||||
|
||||
@@ -227,6 +227,9 @@ LCUI_API void Dict_SetHashFunctionSeed( unsigned int initval );
|
||||
LCUI_API unsigned int Dict_GetHashFunctionSeed( void );
|
||||
|
||||
/* Hash table types */
|
||||
extern DictType DictType_StringCopyKey;
|
||||
DictType DictType_StringKey;
|
||||
DictType DictType_StringCopyKey;
|
||||
DictType DictType_IntKey;
|
||||
DictType DictType_IdentityKey;
|
||||
|
||||
#endif /* LCUI_UTIL_DICT_H */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* ***************************************************************************
|
||||
* string.h -- The string operation set.
|
||||
*
|
||||
* Copyright (C) 2015 by Liu Chao <lc-soft@live.cn>
|
||||
* Copyright (C) 2015-2016 by Liu Chao <lc-soft@live.cn>
|
||||
*
|
||||
* This file is part of the LCUI project, and may only be used, modified, and
|
||||
* distributed under the terms of the GPLv2.
|
||||
@@ -22,7 +22,7 @@
|
||||
/* ****************************************************************************
|
||||
* string.h -- 字符串相关操作函数。
|
||||
*
|
||||
* 版权所有 (C) 2015 归属于 刘超 <lc-soft@live.cn>
|
||||
* 版权所有 (C) 2015-2016 归属于 刘超 <lc-soft@live.cn>
|
||||
*
|
||||
* 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。
|
||||
*
|
||||
@@ -79,6 +79,37 @@ LCUI_API int strtrim( char *outstr, const char *instr, const char *charlist );
|
||||
*/
|
||||
LCUI_API int strsplit( const char *instr, const char *sep, char ***outstrs );
|
||||
|
||||
|
||||
/**
|
||||
* 向字符串组添加字符串
|
||||
* @param[in][out] strlist 字符串组
|
||||
* @param[in] str 字符串
|
||||
*/
|
||||
LCUI_API int strsadd( char ***strlist, const char *str );
|
||||
|
||||
/**
|
||||
* 判断字符串组中是否包含指定字符串
|
||||
* @param[in][out] strlist 字符串组
|
||||
* @param[in] str 字符串
|
||||
* @returns 如果包含则返回 1, 否则返回 0
|
||||
*/
|
||||
LCUI_API int strshas( char **strlist, const char *str );
|
||||
|
||||
/**
|
||||
* 从字符串组中删除指定字符串
|
||||
* @param[in][out] strlist 字符串组
|
||||
* @param[in] str 字符串
|
||||
* @returns 如果删除成功则返回 1, 否则返回 0
|
||||
*/
|
||||
LCUI_API int strsdel( char ***strlist, const char *str );
|
||||
|
||||
/**
|
||||
* 向已排序的字符串组添加字符串
|
||||
* @param[in][out] strlist 字符串组
|
||||
* @param[in] str 字符串
|
||||
*/
|
||||
LCUI_API int sortedstrsadd( char ***strlist, const char *str );
|
||||
|
||||
/** 释放字符串组 */
|
||||
LCUI_API void freestrs( char **strs );
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ widget_task.c \
|
||||
widget_paint.c \
|
||||
widget_background.c \
|
||||
css_parser.c \
|
||||
css_library.c \
|
||||
builder.c \
|
||||
widget/textview.c \
|
||||
widget/textedit.c \
|
||||
|
||||
+2
-2
@@ -118,13 +118,13 @@ static int ParseResource( XMLParserContext ctx, xmlNodePtr node )
|
||||
}
|
||||
else if( strstr(type, "text/css") ) {
|
||||
if( src ) {
|
||||
LCUICSS_LoadFile( src );
|
||||
LCUI_LoadCSSFile( src );
|
||||
}
|
||||
for( node = node->children; node; node = node->next ) {
|
||||
if( node->type != XML_TEXT_NODE ) {
|
||||
continue;
|
||||
}
|
||||
LCUICSS_LoadString( (char*)node->content, ctx->space );
|
||||
LCUI_LoadCSSString( (char*)node->content, ctx->space );
|
||||
}
|
||||
}
|
||||
return PB_NEXT;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+45
-193
@@ -36,13 +36,21 @@
|
||||
* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果
|
||||
* 没有,请查看:<http://www.gnu.org/licenses/>.
|
||||
* ****************************************************************************/
|
||||
//#define DEBUG
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <LCUI_Build.h>
|
||||
#include <LCUI/LCUI.h>
|
||||
#include <LCUI/gui/widget.h>
|
||||
#include <LCUI/thread.h>
|
||||
#include <LCUI/gui/css_library.h>
|
||||
#include <LCUI/gui/css_parser.h>
|
||||
|
||||
#define SPLIT_NUMBER 1
|
||||
#define SPLIT_COLOR (1<<1)
|
||||
#define SPLIT_STYLE (1<<2)
|
||||
|
||||
#define LEN(A) sizeof( A ) / sizeof( *A )
|
||||
|
||||
/** 解析器的环境参数(上下文数据) */
|
||||
typedef struct CSSParserContextRec_ {
|
||||
@@ -64,49 +72,12 @@ typedef struct CSSParserContextRec_ {
|
||||
char *space; /**< 样式记录所属的空间 */
|
||||
} CSSParserContextRec, *CSSParserContext;
|
||||
|
||||
/** 样式字符串值与标识码 */
|
||||
typedef struct KeyNameGroup {
|
||||
int key;
|
||||
char *name;
|
||||
} KeyNameGroup;
|
||||
|
||||
static struct CSSParserModule {
|
||||
LCUI_RBTree parser_tree; /**< 解析器树,以名称进行索引 */
|
||||
LCUI_RBTree option_name_tree; /**< 样式属性值名称树,以值进行索引 */
|
||||
LCUI_RBTree option_tree; /**< 样式属性值树,以值的名称进行索引 */
|
||||
LCUI_RBTree name_tree; /**< 样式属性名称树,以属性名称进行索引 */
|
||||
int count; /**< 当前记录的属性数量 */
|
||||
int count;
|
||||
DictType dicttype; /**< 解析器表的字典类型数据 */
|
||||
Dict *parsers; /**< 解析器表,以名称进行索引 */
|
||||
} self;
|
||||
|
||||
#define SPLIT_NUMBER 1
|
||||
#define SPLIT_COLOR (1<<1)
|
||||
#define SPLIT_STYLE (1<<2)
|
||||
|
||||
int GetStyleOption( const char *str )
|
||||
{
|
||||
LCUI_RBTreeNode *node;
|
||||
node = RBTree_CustomSearch( &self.option_tree, str );
|
||||
if( !node ) {
|
||||
return -1;
|
||||
}
|
||||
return ((KeyNameGroup*)(node->data))->key;
|
||||
}
|
||||
|
||||
const char *GetStyleOptionName( int val )
|
||||
{
|
||||
LCUI_RBTreeNode *node;
|
||||
node = RBTree_Search( &self.option_name_tree, val );
|
||||
if( !node ) {
|
||||
return NULL;
|
||||
}
|
||||
return ((KeyNameGroup*)(node->data))->name;
|
||||
}
|
||||
|
||||
const char *GetStyleName( int key )
|
||||
{
|
||||
return RBTree_GetData( &self.name_tree, key );
|
||||
}
|
||||
|
||||
static int SplitValues( const char *str, LCUI_Style slist,
|
||||
int max_len, int mode )
|
||||
{
|
||||
@@ -155,7 +126,7 @@ static int SplitValues( const char *str, LCUI_Style slist,
|
||||
}
|
||||
}
|
||||
if( mode & SPLIT_STYLE ) {
|
||||
val = GetStyleOption( values[vj] );
|
||||
val = LCUI_GetStyleValue( values[vj] );
|
||||
if( val > 0 ) {
|
||||
slist[vj].style = val;
|
||||
slist[vj].type = SVT_style;
|
||||
@@ -234,7 +205,10 @@ static int OnParseColor( LCUI_StyleSheet ss, int key, const char *str )
|
||||
}
|
||||
if( strcmp("transparent", str) == 0 ) {
|
||||
s->is_valid = TRUE;
|
||||
s->color = ARGB(0,255,255,255);
|
||||
s->color.alpha = 0;
|
||||
s->color.red = 255;
|
||||
s->color.green = 255;
|
||||
s->color.blue = 255;
|
||||
s->type = SVT_COLOR;
|
||||
return 0;
|
||||
}
|
||||
@@ -274,7 +248,7 @@ static int OnParseImage( LCUI_StyleSheet ss, int key, const char *str )
|
||||
static int OnParseStyleOption( LCUI_StyleSheet ss, int key, const char *str )
|
||||
{
|
||||
LCUI_Style s = &ss->sheet[key];
|
||||
int v = GetStyleOption( str );
|
||||
int v = LCUI_GetStyleValue( str );
|
||||
if( v < 0 ) {
|
||||
return -1;
|
||||
}
|
||||
@@ -542,99 +516,6 @@ static int OnParseBackgroundSize( LCUI_StyleSheet ss, int key, const char *str )
|
||||
return 0;
|
||||
}
|
||||
|
||||
static KeyNameGroup style_name_map[] = {
|
||||
{ key_visible, "visible"},
|
||||
{ key_width, "width" },
|
||||
{ key_height, "height" },
|
||||
{ key_min_width, "min-width" },
|
||||
{ key_min_height, "min-height" },
|
||||
{ key_max_width, "max-width" },
|
||||
{ key_max_height, "max-height" },
|
||||
{ key_display, "display" },
|
||||
{ key_z_index, "z-index" },
|
||||
{ key_top, "top" },
|
||||
{ key_right, "right" },
|
||||
{ key_left, "left" },
|
||||
{ key_bottom, "bottom" },
|
||||
{ key_position, "position" },
|
||||
{ key_vertical_align, "vertical-align" },
|
||||
{ key_background_color, "background-color" },
|
||||
{ key_background_position, "background-position" },
|
||||
{ key_background_size, "background-size" },
|
||||
{ key_background_image, "background-image" },
|
||||
{ key_border_color, "border-color" },
|
||||
{ key_border_width, "border-width" },
|
||||
{ key_border_style, "border-style" },
|
||||
{ key_padding_left, "padding-left" },
|
||||
{ key_padding_right, "padding-right" },
|
||||
{ key_padding_top, "padding-top" },
|
||||
{ key_padding_bottom, "padding-bottom" },
|
||||
{ key_margin_left, "margin-left" },
|
||||
{ key_margin_right, "margin-right" },
|
||||
{ key_margin_top, "margin-top" },
|
||||
{ key_margin_bottom, "margin-bottom" },
|
||||
{ key_border_top_color, "border-top-color" },
|
||||
{ key_border_right_color, "border-right-color" },
|
||||
{ key_border_bottom_color, "border-bottom-color" },
|
||||
{ key_border_left_color, "border-left-color" },
|
||||
{ key_border_top_width, "border-top-width" },
|
||||
{ key_border_right_width, "border-right-width" },
|
||||
{ key_border_bottom_width, "border-bottom-width" },
|
||||
{ key_border_left_width, "border-left-width" },
|
||||
{ key_border_top_width, "border-top-width" },
|
||||
{ key_border_right_width, "border-right-width" },
|
||||
{ key_border_bottom_width, "border-bottom-width" },
|
||||
{ key_border_left_width, "border-left-width" },
|
||||
{ key_border_top_style, "border-top-style" },
|
||||
{ key_border_right_style, "border-right-style" },
|
||||
{ key_border_bottom_style, "border-bottom-style" },
|
||||
{ key_border_left_style, "border-left-style" },
|
||||
{ key_box_shadow_x, "box-shadow-x" },
|
||||
{ key_box_shadow_y, "box-shadow-y" },
|
||||
{ key_box_shadow_blur, "box-shadow-blur" },
|
||||
{ key_box_shadow_spread, "box-shadow-spread" },
|
||||
{ key_box_shadow_color, "box-shadow-color" },
|
||||
{ key_pointer_events, "pointer-events" },
|
||||
{ key_focusable, "focusable" },
|
||||
{ key_box_sizing, "box-sizing" }
|
||||
};
|
||||
|
||||
/** 样式字符串与标识码的映射表 */
|
||||
static KeyNameGroup style_option_map[] = {
|
||||
{ SV_NONE, "none" },
|
||||
{ SV_AUTO, "auto" },
|
||||
{ SV_CONTAIN, "contain" },
|
||||
{ SV_COVER, "cover" },
|
||||
{ SV_LEFT, "left" },
|
||||
{ SV_CENTER, "center" },
|
||||
{ SV_RIGHT, "right" },
|
||||
{ SV_TOP, "top" },
|
||||
{ SV_TOP_LEFT, "top left" },
|
||||
{ SV_TOP_CENTER, "top center" },
|
||||
{ SV_TOP_RIGHT, "top right" },
|
||||
{ SV_MIDDLE, "middle" },
|
||||
{ SV_CENTER_LEFT, "center left" },
|
||||
{ SV_CENTER_CENTER, "center center" },
|
||||
{ SV_CENTER_RIGHT, "center right" },
|
||||
{ SV_BOTTOM, "bottom" },
|
||||
{ SV_BOTTOM_LEFT, "bottom left" },
|
||||
{ SV_BOTTOM_CENTER, "bottom center" },
|
||||
{ SV_BOTTOM_RIGHT, "bottom right" },
|
||||
{ SV_SOLID, "solid" },
|
||||
{ SV_DOTTED, "dotted" },
|
||||
{ SV_DOUBLE, "double" },
|
||||
{ SV_DASHED, "dashed" },
|
||||
{ SV_CONTENT_BOX, "content-box" },
|
||||
{ SV_PADDING_BOX, "padding-box" },
|
||||
{ SV_BORDER_BOX, "border-box" },
|
||||
{ SV_GRAPH_BOX, "graph-box" },
|
||||
{ SV_STATIC, "static" },
|
||||
{ SV_RELATIVE, "relative" },
|
||||
{ SV_ABSOLUTE, "absolute" },
|
||||
{ SV_BLOCK, "block" },
|
||||
{ SV_INLINE_BLOCK, "inline-block" },
|
||||
{ SV_NOWRAP, "nowrap" }
|
||||
};
|
||||
|
||||
/** 各个样式的解析器映射表 */
|
||||
static LCUI_StyleParserRec style_parser_map[] = {
|
||||
@@ -699,11 +580,6 @@ static int CompareParserName( void *data, const void *keydata )
|
||||
return strcmp(((LCUI_StyleParser)data)->name, (const char*)keydata);
|
||||
}
|
||||
|
||||
static int CompareName( void *data, const void *keydata )
|
||||
{
|
||||
return strcmp(((KeyNameGroup*)data)->name, (const char*)keydata);
|
||||
}
|
||||
|
||||
static CSSParserContext NewCSSParserContext( size_t buffer_size,
|
||||
const char *space )
|
||||
{
|
||||
@@ -727,7 +603,7 @@ static void DeleteCSSParserContext( CSSParserContext *ctx_ptr )
|
||||
}
|
||||
|
||||
/** 载入CSS代码块,用于实现CSS代码的分块载入 */
|
||||
static int LCUICSS_LoadBlock( CSSParserContext ctx, const char *str )
|
||||
static int LCUI_LoadCSSBlock( CSSParserContext ctx, const char *str )
|
||||
{
|
||||
size_t size = 0;
|
||||
LCUI_Selector s;
|
||||
@@ -844,7 +720,7 @@ put_css:
|
||||
DEBUG_MSG("put css\n");
|
||||
/* 将记录的样式表添加至匹配到的选择器中 */
|
||||
for( LinkedList_Each( node, &ctx->selectors ) ) {
|
||||
LCUI_PutStyle( node->data, ctx->css, ctx->space );
|
||||
LCUI_PutStyleSheet( node->data, ctx->css, ctx->space );
|
||||
}
|
||||
LinkedList_Clear( &ctx->selectors, (FuncPtr)Selector_Delete );
|
||||
StyleSheet_Delete( ctx->css );
|
||||
@@ -853,8 +729,7 @@ select_parser:
|
||||
ctx->target = TARGET_VALUE;
|
||||
ctx->buffer[ctx->pos] = 0;
|
||||
ctx->pos = 0;
|
||||
ctx->parser = RBTree_CustomGetData( &self.parser_tree,
|
||||
ctx->buffer );
|
||||
ctx->parser = Dict_FetchValue( self.parsers, ctx->buffer );
|
||||
DEBUG_MSG("select style: %s, parser: %p\n",
|
||||
ctx->buffer, ctx->parser);
|
||||
continue;
|
||||
@@ -878,7 +753,7 @@ parse_value:
|
||||
}
|
||||
|
||||
/** 从文件中载入CSS样式数据,并导入至样式库中 */
|
||||
int LCUICSS_LoadFile( const char *filepath )
|
||||
int LCUI_LoadCSSFile( const char *filepath )
|
||||
{
|
||||
int n;
|
||||
FILE *fp;
|
||||
@@ -893,7 +768,7 @@ int LCUICSS_LoadFile( const char *filepath )
|
||||
n = fread( buff, 1, 511, fp );
|
||||
while( n > 0 ) {
|
||||
buff[n] = 0;
|
||||
LCUICSS_LoadBlock( ctx, buff );
|
||||
LCUI_LoadCSSBlock( ctx, buff );
|
||||
n = fread( buff, 1, 511, fp );
|
||||
}
|
||||
DeleteCSSParserContext( &ctx );
|
||||
@@ -901,7 +776,7 @@ int LCUICSS_LoadFile( const char *filepath )
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LCUICSS_LoadString( const char *str, const char *space )
|
||||
int LCUI_LoadCSSString( const char *str, const char *space )
|
||||
{
|
||||
int len = 1;
|
||||
const char *cur;
|
||||
@@ -909,71 +784,55 @@ int LCUICSS_LoadString( const char *str, const char *space )
|
||||
DEBUG_MSG("parse begin\n");
|
||||
ctx = NewCSSParserContext( 512, space );
|
||||
for( cur = str; len > 0; cur += len ) {
|
||||
len = LCUICSS_LoadBlock( ctx, cur );
|
||||
len = LCUI_LoadCSSBlock( ctx, cur );
|
||||
}
|
||||
DeleteCSSParserContext( &ctx );
|
||||
DEBUG_MSG("parse end\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LCUICSS_GetStyleTotal(void)
|
||||
{
|
||||
return self.count;
|
||||
}
|
||||
|
||||
int LCUICSS_AddParser( LCUI_StyleParser sp )
|
||||
int LCUI_AddCSSParser( LCUI_StyleParser sp )
|
||||
{
|
||||
int key;
|
||||
LCUI_StyleParser new_sp;
|
||||
if( !sp->name || strlen(sp->name) < 1 ) {
|
||||
if( !sp->name || strlen( sp->name ) < 1 ) {
|
||||
return -1;
|
||||
}
|
||||
if( RBTree_CustomSearch(&self.name_tree, sp->name) ) {
|
||||
if( Dict_FetchValue( self.parsers, sp->name ) ) {
|
||||
return -2;
|
||||
}
|
||||
key = self.count++;
|
||||
new_sp = NEW(LCUI_StyleParserRec, 1);
|
||||
new_sp = NEW( LCUI_StyleParserRec, 1 );
|
||||
new_sp->key = sp->key;
|
||||
new_sp->parse = sp->parse;
|
||||
new_sp->name = strdup( sp->name );
|
||||
RBTree_Insert( &self.name_tree, key, new_sp->name );
|
||||
RBTree_CustomInsert( &self.parser_tree, new_sp->name, new_sp );
|
||||
Dict_Add( self.parsers, new_sp->name, new_sp );
|
||||
return key;
|
||||
}
|
||||
|
||||
static void OnDestroyStyleParser( void *arg )
|
||||
static void DestroyStyleParser( void *privdata, void *val )
|
||||
{
|
||||
LCUI_StyleParser sp = arg;
|
||||
LCUI_StyleParser sp = val;
|
||||
free( sp->name );
|
||||
free( sp );
|
||||
}
|
||||
|
||||
/** 初始化 LCUI 的 CSS 代码解析功能 */
|
||||
void LCUICSS_Init( void )
|
||||
void LCUI_InitCSSParser( void )
|
||||
{
|
||||
KeyNameGroup *skn, *skn_end;
|
||||
LCUI_StyleParser new_sp, sp, sp_end;
|
||||
/* 构建一个红黑树,方便按名称查找解析器 */
|
||||
RBTree_Init( &self.name_tree );
|
||||
RBTree_Init( &self.parser_tree );
|
||||
RBTree_Init( &self.option_tree );
|
||||
RBTree_Init( &self.option_name_tree );
|
||||
RBTree_OnDestroy( &self.parser_tree, OnDestroyStyleParser );
|
||||
RBTree_OnCompare( &self.parser_tree, CompareParserName );
|
||||
RBTree_OnCompare( &self.option_tree, CompareName );
|
||||
skn = style_name_map;
|
||||
skn_end = skn + sizeof( style_name_map ) / sizeof( KeyNameGroup );
|
||||
for( ; skn < skn_end; ++skn ) {
|
||||
RBTree_Insert( &self.name_tree, skn->key, skn->name );
|
||||
}
|
||||
sp_end = sp = style_parser_map;
|
||||
sp_end += sizeof( style_parser_map ) / sizeof( LCUI_StyleParserRec );
|
||||
for( ; sp < sp_end; ++sp ) {
|
||||
|
||||
self.count = 0;
|
||||
self.dicttype = DictType_StringKey;
|
||||
self.dicttype.valDestructor = DestroyStyleParser;
|
||||
self.parsers = Dict_Create( &self.dicttype, NULL );
|
||||
sp_end = style_parser_map + LEN( style_parser_map );
|
||||
for( sp = style_parser_map; sp < sp_end; ++sp ) {
|
||||
new_sp = malloc( sizeof( LCUI_StyleParserRec ) );
|
||||
new_sp->key = sp->key;
|
||||
new_sp->parse = sp->parse;
|
||||
if( !sp->name && sp->key >= 0 ) {
|
||||
const char *name = GetStyleName( sp->key );
|
||||
const char *name = LCUI_GetStyleName( sp->key );
|
||||
if( !name ) {
|
||||
free( new_sp );
|
||||
continue;
|
||||
@@ -982,18 +841,11 @@ void LCUICSS_Init( void )
|
||||
} else {
|
||||
new_sp->name = strdup( sp->name );
|
||||
}
|
||||
RBTree_CustomInsert( &self.parser_tree, new_sp->name, new_sp );
|
||||
Dict_Add( self.parsers, new_sp->name, new_sp );
|
||||
}
|
||||
skn = style_option_map;
|
||||
skn_end = skn + sizeof( style_option_map ) / sizeof( KeyNameGroup );
|
||||
for( ; skn < skn_end; ++skn ) {
|
||||
RBTree_CustomInsert( &self.option_tree, skn->name, skn );
|
||||
RBTree_Insert( &self.option_name_tree, skn->key, skn );
|
||||
}
|
||||
self.count = STYLE_KEY_TOTAL;
|
||||
}
|
||||
|
||||
void LCUICSS_Destroy( void )
|
||||
void LCUI_ExitCSSParser( void )
|
||||
{
|
||||
|
||||
Dict_Release( self.parsers );
|
||||
}
|
||||
|
||||
@@ -120,5 +120,5 @@ void LCUIWidget_AddButton( void )
|
||||
wc->methods.set_text = Button_SetText;
|
||||
wc->methods.destroy = Button_OnDestroy;
|
||||
wc->task_handler = Button_OnTask;
|
||||
LCUICSS_LoadString( button_css, NULL );
|
||||
LCUI_LoadCSSString( button_css, NULL );
|
||||
}
|
||||
|
||||
@@ -579,5 +579,5 @@ void LCUIWidget_AddTScrollBar( void )
|
||||
wc->methods.set_attr = ScrollBar_OnSetAttr;
|
||||
scroll_event_id = LCUIWidget_AllocEventId();
|
||||
LCUIWidget_SetEventName( scroll_event_id, "scroll" );
|
||||
LCUICSS_LoadString( scrollbar_css, NULL );
|
||||
LCUI_LoadCSSString( scrollbar_css, NULL );
|
||||
}
|
||||
|
||||
@@ -181,5 +181,5 @@ void LCUIWidget_AddSideBar(void)
|
||||
wc->methods.destroy = SideBarItem_OnDestroy;
|
||||
wc = LCUIWidget_AddClass("sidebar-toggle");
|
||||
wc->methods.init = SideBarToggle_OnInit;
|
||||
LCUICSS_LoadString( sidebar_css, NULL );
|
||||
LCUI_LoadCSSString( sidebar_css, NULL );
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ static void LCUIWidget_AddTextCaret( void )
|
||||
LCUI_WidgetClass *wc = LCUIWidget_AddClass( "textcaret" );
|
||||
wc->methods.init = TextCaret_OnInit;
|
||||
wc->methods.destroy = TextCaret_OnDestroy;
|
||||
LCUICSS_LoadString( textcaret_css, NULL );
|
||||
LCUI_LoadCSSString( textcaret_css, NULL );
|
||||
}
|
||||
|
||||
/*-------------------------------- End Caret --------------------------------*/
|
||||
@@ -922,7 +922,7 @@ void LCUIWidget_AddTextEdit( void )
|
||||
wc->methods.set_attr = TextEdit_SetAttr;
|
||||
wc->methods.autosize = TextEdit_AutoSize;
|
||||
wc->task_handler = TextEdit_OnTask;
|
||||
LCUICSS_LoadString( textedit_css, NULL );
|
||||
LCUI_LoadCSSString( textedit_css, NULL );
|
||||
LCUIWidget_AddTextCaret();
|
||||
textedit_event_id = LCUIWidget_AllocEventId();
|
||||
LCUIWidget_SetEventName( textedit_event_id, "change" );
|
||||
|
||||
@@ -189,7 +189,7 @@ static int OnParseFontWeight( LCUI_StyleSheet ss, int key, const char *str )
|
||||
|
||||
static int OnParseTextAlign( LCUI_StyleSheet ss, int key, const char *str )
|
||||
{
|
||||
int val = GetStyleOption( str );
|
||||
int val = LCUI_GetStyleValue( str );
|
||||
if( val < 0 ) {
|
||||
return -1;
|
||||
}
|
||||
@@ -213,7 +213,7 @@ static int OnParseLineHeight( LCUI_StyleSheet ss, int key, const char *str )
|
||||
static int OnParseStyleOption( LCUI_StyleSheet ss, int key, const char *str )
|
||||
{
|
||||
LCUI_Style s = &ss->sheet[style_key_map[key]];
|
||||
int v = GetStyleOption( str );
|
||||
int v = LCUI_GetStyleValue( str );
|
||||
if( v < 0 ) {
|
||||
return -1;
|
||||
}
|
||||
@@ -569,6 +569,6 @@ void LCUIWidget_AddTextView( void )
|
||||
wc->task_handler = TextView_OnTask;
|
||||
for( i = 0; i < TOTAL_FONT_STYLE_KEY; ++i ) {
|
||||
style_key_map[style_parsers[i].key] =
|
||||
LCUICSS_AddParser( &style_parsers[i] );
|
||||
LCUI_AddCSSParser( &style_parsers[i] );
|
||||
}
|
||||
}
|
||||
|
||||
+10
-132
@@ -54,128 +54,6 @@ static struct LCUIWidgetModule {
|
||||
|
||||
#define StrList_Destroy freestrs
|
||||
|
||||
static int StrList_AddOne( char ***strlist, const char *str )
|
||||
{
|
||||
int i = 0;
|
||||
char **newlist;
|
||||
|
||||
if( !*strlist ) {
|
||||
newlist = (char**)malloc( sizeof(char*) * 2 );
|
||||
goto check_done;
|
||||
}
|
||||
for( i = 0; (*strlist)[i]; ++i ) {
|
||||
if( strcmp((*strlist)[i], str) == 0 ) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
newlist = (char**)realloc( *strlist, (i+2)*sizeof(char*) );
|
||||
check_done:
|
||||
if( !newlist ) {
|
||||
return 0;
|
||||
}
|
||||
newlist[i] = strdup(str);
|
||||
newlist[i+1] = NULL;
|
||||
*strlist = newlist;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int StrList_Add( char ***strlist, const char *str )
|
||||
{
|
||||
char buff[256];
|
||||
int count = 0, i, head;
|
||||
for( head = 0, i = 0; str[i]; ++i ) {
|
||||
if( str[i] != ' ' ) {
|
||||
continue;
|
||||
}
|
||||
if( i - 1 > head ) {
|
||||
strncpy( buff, &str[head], i - head );
|
||||
buff[i - head] = 0;
|
||||
count += StrList_AddOne( strlist, buff );
|
||||
}
|
||||
head = i + 1;
|
||||
}
|
||||
if( i - 1 > head ) {
|
||||
strncpy( buff, &str[head], i - head );
|
||||
buff[i - head] = 0;
|
||||
count += StrList_AddOne( strlist, buff );
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static LCUI_BOOL StrList_Has( char **strlist, const char *str )
|
||||
{
|
||||
int i;
|
||||
if( !strlist ) {
|
||||
return FALSE;
|
||||
}
|
||||
for( i = 0; strlist[i]; ++i ) {
|
||||
if( strcmp(strlist[i], str) == 0 ) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static int StrList_RemoveOne( char ***strlist, const char *str )
|
||||
{
|
||||
int i, pos, len;
|
||||
char **newlist;
|
||||
|
||||
if( !*strlist ) {
|
||||
return 0;
|
||||
}
|
||||
for( pos = -1, i = 0; (*strlist)[i]; ++i ) {
|
||||
if( strcmp( (*strlist)[i], str ) == 0 ) {
|
||||
pos = i;
|
||||
}
|
||||
}
|
||||
if( pos == -1 ) {
|
||||
return 0;
|
||||
}
|
||||
if( pos == 0 && i < 2 ) {
|
||||
free( *strlist );
|
||||
*strlist = NULL;
|
||||
return 1;
|
||||
}
|
||||
len = i - 1;
|
||||
newlist = (char**)malloc( i * sizeof(char*) );
|
||||
for( i = 0; i < pos; ++i ) {
|
||||
newlist[i] = (*strlist)[i];
|
||||
}
|
||||
for( i = pos; i < len; ++i ) {
|
||||
newlist[i] = (*strlist)[i+1];
|
||||
}
|
||||
newlist[i] = NULL;
|
||||
free( (*strlist)[pos] );
|
||||
free( *strlist );
|
||||
*strlist = newlist;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int StrList_Remove( char ***strlist, const char *str )
|
||||
{
|
||||
char buff[256];
|
||||
int count = 0, i, head;
|
||||
|
||||
for( head = 0, i = 0; str[i]; ++i ) {
|
||||
if( str[i] != ' ' ) {
|
||||
continue;
|
||||
}
|
||||
if( i - 1 > head ) {
|
||||
strncpy( buff, &str[head], i - head );
|
||||
buff[i - head] = 0;
|
||||
count += StrList_RemoveOne( strlist, buff );
|
||||
}
|
||||
head = i + 1;
|
||||
}
|
||||
if( i - 1 > head ) {
|
||||
strncpy( buff, &str[head], i - head );
|
||||
buff[i - head] = 0;
|
||||
count += StrList_RemoveOne( strlist, buff );
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
LCUI_Widget LCUIWidget_GetRoot(void)
|
||||
{
|
||||
return LCUIWidget.root;
|
||||
@@ -1338,11 +1216,11 @@ void Widget_Unlock( LCUI_Widget w )
|
||||
int Widget_AddClass( LCUI_Widget w, const char *class_name )
|
||||
{
|
||||
Widget_Lock( w );
|
||||
if( StrList_Has( w->classes, class_name ) ) {
|
||||
if( strshas( w->classes, class_name ) ) {
|
||||
Widget_Unlock( w );
|
||||
return 1;
|
||||
}
|
||||
if( StrList_Add(&w->classes, class_name) <= 0 ) {
|
||||
if( strsadd(&w->classes, class_name) <= 0 ) {
|
||||
Widget_Unlock( w );
|
||||
return 0;
|
||||
}
|
||||
@@ -1356,7 +1234,7 @@ int Widget_AddClass( LCUI_Widget w, const char *class_name )
|
||||
LCUI_BOOL Widget_HasClass( LCUI_Widget w, const char *class_name )
|
||||
{
|
||||
Widget_Lock( w );
|
||||
if( StrList_Has( w->classes, class_name ) ) {
|
||||
if( strshas( w->classes, class_name ) ) {
|
||||
Widget_Unlock( w );
|
||||
return TRUE;
|
||||
}
|
||||
@@ -1368,9 +1246,9 @@ LCUI_BOOL Widget_HasClass( LCUI_Widget w, const char *class_name )
|
||||
int Widget_RemoveClass( LCUI_Widget w, const char *class_name )
|
||||
{
|
||||
Widget_Lock( w );
|
||||
if( StrList_Has( w->classes, class_name ) ) {
|
||||
if( strshas( w->classes, class_name ) ) {
|
||||
Widget_HandleChildrenStyleChange( w, 0, class_name );
|
||||
StrList_Remove( &w->classes, class_name );
|
||||
strsdel( &w->classes, class_name );
|
||||
Widget_UpdateStyle( w, TRUE );
|
||||
Widget_Unlock( w );
|
||||
return 1;
|
||||
@@ -1383,11 +1261,11 @@ int Widget_RemoveClass( LCUI_Widget w, const char *class_name )
|
||||
int Widget_AddStatus( LCUI_Widget w, const char *status_name )
|
||||
{
|
||||
Widget_Lock( w );
|
||||
if( StrList_Has( w->status, status_name ) ) {
|
||||
if( strshas( w->status, status_name ) ) {
|
||||
Widget_Unlock( w );
|
||||
return 0;
|
||||
}
|
||||
if( StrList_Add( &w->status, status_name ) <= 0 ) {
|
||||
if( strsadd( &w->status, status_name ) <= 0 ) {
|
||||
Widget_Unlock( w );
|
||||
return 0;
|
||||
}
|
||||
@@ -1401,7 +1279,7 @@ int Widget_AddStatus( LCUI_Widget w, const char *status_name )
|
||||
LCUI_BOOL Widget_HasStatus( LCUI_Widget w, const char *status_name )
|
||||
{
|
||||
Widget_Lock( w );
|
||||
if( StrList_Has( w->status, status_name ) ) {
|
||||
if( strshas( w->status, status_name ) ) {
|
||||
Widget_Unlock( w );
|
||||
return TRUE;
|
||||
}
|
||||
@@ -1413,9 +1291,9 @@ LCUI_BOOL Widget_HasStatus( LCUI_Widget w, const char *status_name )
|
||||
int Widget_RemoveStatus( LCUI_Widget w, const char *status_name )
|
||||
{
|
||||
Widget_Lock( w );
|
||||
if( StrList_Has( w->status, status_name ) ) {
|
||||
if( strshas( w->status, status_name ) ) {
|
||||
Widget_HandleChildrenStyleChange( w, 1, status_name );
|
||||
StrList_Remove( &w->status, status_name );
|
||||
strsdel( &w->status, status_name );
|
||||
Widget_UpdateStyle( w, TRUE );
|
||||
Widget_Unlock( w );
|
||||
return 1;
|
||||
|
||||
+18
-1224
File diff suppressed because it is too large
Load Diff
@@ -512,6 +512,7 @@ int LCUI_Init(void)
|
||||
LCUI_ShowCopyrightText();
|
||||
LCUIApp_Init();
|
||||
/* 初始化各个模块 */
|
||||
LCUI_InitMemDebug();
|
||||
LCUI_InitEvent();
|
||||
LCUI_InitFont();
|
||||
LCUI_InitTimer();
|
||||
@@ -538,6 +539,7 @@ static int LCUI_Destroy( void )
|
||||
LCUI_ExitFont();
|
||||
LCUI_ExitTimer();
|
||||
LCUI_ExitDisplay();
|
||||
LCUI_ExitMemDebug();
|
||||
LCUIApp_Destroy();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2,5 +2,5 @@ AUTOMAKE_OPTIONS=foreign
|
||||
AM_CFLAGS = -I$(abs_top_srcdir)/include
|
||||
noinst_LTLIBRARIES = libutil.la
|
||||
libutil_la_SOURCES = rbtree.c dict.c linkedlist.c time.c event.c rect.c string.c \
|
||||
dirent.c parse.c framectrl.c
|
||||
dirent.c parse.c framectrl.c memdebug.c
|
||||
|
||||
|
||||
@@ -690,6 +690,26 @@ static void StringCopyKeyDict_KeyDestructor( void *privdata, void *key )
|
||||
free( key );
|
||||
}
|
||||
|
||||
static unsigned int IntKeyDict_KeyHash( const void *key )
|
||||
{
|
||||
unsigned int hash = (unsigned int)key;
|
||||
return Dict_IntHashFunction( hash );
|
||||
}
|
||||
|
||||
static unsigned int IdentityKeyDict_KeyHash( const void *key )
|
||||
{
|
||||
return (unsigned int)key;
|
||||
}
|
||||
|
||||
DictType DictType_StringKey = {
|
||||
StringCopyKeyDict_KeyHash,
|
||||
NULL,
|
||||
NULL,
|
||||
StringCopyKeyDict_KeyCompare,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
DictType DictType_StringCopyKey = {
|
||||
StringCopyKeyDict_KeyHash,
|
||||
StringCopyKeyDict_KeyDup,
|
||||
@@ -698,3 +718,13 @@ DictType DictType_StringCopyKey = {
|
||||
StringCopyKeyDict_KeyDestructor,
|
||||
NULL
|
||||
};
|
||||
|
||||
DictType DictType_IntKey = {
|
||||
IntKeyDict_KeyHash,
|
||||
NULL, NULL, NULL, NULL, NULL
|
||||
};
|
||||
|
||||
DictType DictType_IdentityKey = {
|
||||
IdentityKeyDict_KeyHash,
|
||||
NULL, NULL, NULL, NULL, NULL
|
||||
};
|
||||
@@ -1,45 +0,0 @@
|
||||
#include <LCUI_Build.h>
|
||||
#include <LCUI/LCUI.h>
|
||||
#include <stdio.h>
|
||||
|
||||
//#define DEBUG
|
||||
#ifdef DEBUG
|
||||
static struct {
|
||||
int alloc_count;
|
||||
int free_count;
|
||||
int saved_count;
|
||||
int alloc_total_size;
|
||||
int free_total_size;
|
||||
int saved_total_size;
|
||||
} mem_debug = { 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
void *malloc( size_t size )
|
||||
{
|
||||
int *head;
|
||||
mem_debug.saved_total_size += size;
|
||||
if( size > 32 ) {
|
||||
_DEBUG_MSG( "malloc[%d]: %lu bytes, saved_total: %d bytes\n", mem_debug.saved_count, size, mem_debug.saved_total_size );
|
||||
}
|
||||
head = (int*)malloc(size+sizeof(int));
|
||||
*head = size;
|
||||
++mem_debug.saved_count;
|
||||
++mem_debug.alloc_count;
|
||||
mem_debug.alloc_total_size += size;
|
||||
return (void*)(head+1);
|
||||
}
|
||||
|
||||
void free( void *p )
|
||||
{
|
||||
int *head;
|
||||
head = p;
|
||||
head -= 1;
|
||||
++mem_debug.free_count;
|
||||
mem_debug.saved_count = mem_debug.alloc_count - mem_debug.free_count;
|
||||
mem_debug.free_total_size += *head;
|
||||
mem_debug.saved_total_size = mem_debug.alloc_total_size - mem_debug.free_total_size;
|
||||
if( *head > 32 ) {
|
||||
_DEBUG_MSG( "free[%d]: %d bytes, saved_total: %d bytes\n", mem_debug.saved_count, *head, mem_debug.saved_total_size );
|
||||
}
|
||||
free(head);
|
||||
}
|
||||
#endif
|
||||
@@ -39,6 +39,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <LCUI_Build.h>
|
||||
#include <LCUI/LCUI.h>
|
||||
|
||||
@@ -129,3 +130,171 @@ int strsplit( const char *instr, const char *sep, char ***outstrs )
|
||||
*outstrs = newstrs;
|
||||
return i + 1;
|
||||
}
|
||||
|
||||
static int strsaddone( char ***strlist, const char *str )
|
||||
{
|
||||
int i = 0;
|
||||
char **newlist;
|
||||
|
||||
if( !*strlist ) {
|
||||
newlist = (char**)malloc( sizeof(char*) * 2 );
|
||||
goto check_done;
|
||||
}
|
||||
for( i = 0; (*strlist)[i]; ++i ) {
|
||||
if( strcmp((*strlist)[i], str) == 0 ) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
newlist = (char**)realloc( *strlist, (i+2)*sizeof(char*) );
|
||||
check_done:
|
||||
if( !newlist ) {
|
||||
return 0;
|
||||
}
|
||||
newlist[i] = strdup(str);
|
||||
newlist[i+1] = NULL;
|
||||
*strlist = newlist;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int strsadd( char ***strlist, const char *str )
|
||||
{
|
||||
char buff[256];
|
||||
int count = 0, i, head;
|
||||
for( head = 0, i = 0; str[i]; ++i ) {
|
||||
if( str[i] != ' ' ) {
|
||||
continue;
|
||||
}
|
||||
if( i - 1 > head ) {
|
||||
strncpy( buff, &str[head], i - head );
|
||||
buff[i - head] = 0;
|
||||
count += strsaddone( strlist, buff );
|
||||
}
|
||||
head = i + 1;
|
||||
}
|
||||
if( i - 1 > head ) {
|
||||
strncpy( buff, &str[head], i - head );
|
||||
buff[i - head] = 0;
|
||||
count += strsaddone( strlist, buff );
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
int strshas( char **strlist, const char *str )
|
||||
{
|
||||
int i;
|
||||
if( !strlist ) {
|
||||
return 0;
|
||||
}
|
||||
for( i = 0; strlist[i]; ++i ) {
|
||||
if( strcmp(strlist[i], str) == 0 ) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int strsdelone( char ***strlist, const char *str )
|
||||
{
|
||||
int i, pos, len;
|
||||
char **newlist;
|
||||
|
||||
if( !*strlist ) {
|
||||
return 0;
|
||||
}
|
||||
for( pos = -1, i = 0; (*strlist)[i]; ++i ) {
|
||||
if( strcmp( (*strlist)[i], str ) == 0 ) {
|
||||
pos = i;
|
||||
}
|
||||
}
|
||||
if( pos == -1 ) {
|
||||
return 0;
|
||||
}
|
||||
if( pos == 0 && i < 2 ) {
|
||||
free( *strlist );
|
||||
*strlist = NULL;
|
||||
return 1;
|
||||
}
|
||||
len = i - 1;
|
||||
newlist = (char**)malloc( i * sizeof(char*) );
|
||||
for( i = 0; i < pos; ++i ) {
|
||||
newlist[i] = (*strlist)[i];
|
||||
}
|
||||
for( i = pos; i < len; ++i ) {
|
||||
newlist[i] = (*strlist)[i+1];
|
||||
}
|
||||
newlist[i] = NULL;
|
||||
free( (*strlist)[pos] );
|
||||
free( *strlist );
|
||||
*strlist = newlist;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int strsdel( char ***strlist, const char *str )
|
||||
{
|
||||
char buff[256];
|
||||
int count = 0, i, head;
|
||||
|
||||
for( head = 0, i = 0; str[i]; ++i ) {
|
||||
if( str[i] != ' ' ) {
|
||||
continue;
|
||||
}
|
||||
if( i - 1 > head ) {
|
||||
strncpy( buff, &str[head], i - head );
|
||||
buff[i - head] = 0;
|
||||
count += strsdelone( strlist, buff );
|
||||
}
|
||||
head = i + 1;
|
||||
}
|
||||
if( i - 1 > head ) {
|
||||
strncpy( buff, &str[head], i - head );
|
||||
buff[i - head] = 0;
|
||||
count += strsdelone( strlist, buff );
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
int sortedstrsadd( char ***strlist, const char *str )
|
||||
{
|
||||
int i, n, len, pos;
|
||||
char **newlist, *newstr;
|
||||
|
||||
if( *strlist ) {
|
||||
for( i = 0; (*strlist)[i]; ++i );
|
||||
len = i + 2;
|
||||
} else {
|
||||
len = 2;
|
||||
}
|
||||
newlist = realloc( *strlist, sizeof( char* ) * len );
|
||||
if( !newlist ) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
newlist[len - 2] = NULL;
|
||||
for( i = 0, pos = -1; newlist[i]; ++i ) {
|
||||
n = strcmp( newlist[i], str );
|
||||
if( n < 0 ) {
|
||||
continue;
|
||||
} else if( n == 0 ) {
|
||||
return 1;
|
||||
} else {
|
||||
pos = i;
|
||||
}
|
||||
}
|
||||
n = strlen( str ) + 1;
|
||||
newstr = malloc( sizeof(char) * n );
|
||||
if( !newstr ) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
strncpy( newstr, str, n );
|
||||
if( pos >= 0 ) {
|
||||
for( i = len - 2; i > pos; --i ) {
|
||||
newlist[i] = newlist[i - 1];
|
||||
}
|
||||
newlist[pos] = newstr;
|
||||
} else {
|
||||
pos = len - 2;
|
||||
}
|
||||
newlist[pos] = newstr;
|
||||
newlist[len - 1] = NULL;
|
||||
*strlist = newlist;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user