From 9ba414ddba5a636c6c2f2ebbf93f1964e92f04ce Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Sat, 21 May 2016 18:35:06 +0800 Subject: [PATCH 001/124] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=86=99=E7=9A=84=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E8=BE=93=E5=87=BA=E3=80=81=E5=9C=A8=E7=BB=98?= =?UTF-8?q?=E5=88=B6=E9=83=A8=E4=BB=B6=E6=97=B6=E5=8A=A0=E4=B8=8A=E4=BA=92?= =?UTF-8?q?=E6=96=A5=E9=94=81=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bmp/load_image.c | 52 ++++++++++++------------------------------ src/gui/widget_paint.c | 5 +++- 2 files changed, 18 insertions(+), 39 deletions(-) diff --git a/src/bmp/load_image.c b/src/bmp/load_image.c index 0eca5c9a..b1020938 100755 --- a/src/bmp/load_image.c +++ b/src/bmp/load_image.c @@ -26,35 +26,22 @@ int Graph_LoadImage( const char *filepath, LCUI_Graph *out ) { FILE *fp; int ret = 0; - - Graph_Init(out); + Graph_Init( out ); out->color_type = COLOR_TYPE_RGB; - fp = fopen(filepath,"rb"); - if ( fp == NULL ) { - ret = FILE_ERROR_OPEN_ERROR; - } else { - fgetc(fp); - if (!ferror (fp)) { /* 如果没出错 */ - fseek(fp,0,SEEK_END); - if (ftell(fp)>4) { - fclose(fp); - ret = Graph_DetectImage(filepath, out); - } else { - ret = FILE_ERROR_SHORT_FILE; /* 文件过小 */ - fclose(fp); - } - } + fp = fopen( filepath, "rb" ); + if( fp == NULL ) { + return FILE_ERROR_OPEN_ERROR; } - switch(ret) { - case FILE_ERROR_SHORT_FILE: - printf("error: file is too short!\n"); - break; - case FILE_ERROR_OPEN_ERROR: - perror(filepath); - break; - case FILE_ERROR_UNKNOWN_FORMAT: - printf("error: unknown format!\n"); - break; + fgetc( fp ); + if( !ferror( fp ) ) { + fseek( fp, 0, SEEK_END ); + if( ftell( fp ) > 4 ) { + fclose( fp ); + ret = Graph_DetectImage( filepath, out ); + } else { + ret = FILE_ERROR_SHORT_FILE; + fclose( fp ); + } } return ret; } @@ -68,16 +55,5 @@ int Graph_GetImageSize( const char *filepath, int *width, int *height ) if( ret == FILE_ERROR_UNKNOWN_FORMAT ) { ret = Graph_GetBMPSize( filepath, width, height ); } - switch( ret ) { - case FILE_ERROR_SHORT_FILE: - printf( "error: file is too short!\n" ); - break; - case FILE_ERROR_OPEN_ERROR: - perror( filepath ); - break; - case FILE_ERROR_UNKNOWN_FORMAT: - printf( "error: unknown format!\n" ); - break; - } return ret; } diff --git a/src/gui/widget_paint.c b/src/gui/widget_paint.c index d94221bc..08bc8d6d 100644 --- a/src/gui/widget_paint.c +++ b/src/gui/widget_paint.c @@ -135,8 +135,10 @@ static void Widget_OnPaint( LCUI_Widget w, LCUI_PaintContext paint ) LCUI_Rect box; LCUI_WidgetClass *wc; LCUI_WidgetStyle *s; - s = &w->computed_style; + + Widget_Lock( w ); box.x = box.y = 0; + s = &w->computed_style; box.width = w->box.graph.width; box.height = w->box.graph.height; /* 如果是有位图缓存的话,则先清空缓存里的阴影区域 */ @@ -150,6 +152,7 @@ static void Widget_OnPaint( LCUI_Widget w, LCUI_PaintContext paint ) box.height = w->box.border.height; Graph_DrawBackground( paint, &box, &s->background ); Graph_DrawBorder( paint, &box, &s->border ); + Widget_Unlock( w ); wc = LCUIWidget_GetClass( w->type ); if( wc && wc->methods.paint ) { wc->methods.paint( w, paint ); From 47adab494d276b3c976c9117d029444b0a489e7b Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Sun, 22 May 2016 23:15:09 +0800 Subject: [PATCH 002/124] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=97=A0=E6=95=88?= =?UTF-8?q?=E5=8C=BA=E5=9F=9F=E5=A4=84=E7=90=86=EF=BC=8C=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E6=97=A0=E6=95=88=E5=8C=BA=E5=9F=9F=E6=9C=AA=E8=A2=AB=E9=87=8D?= =?UTF-8?q?=E7=BB=98=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gui/widget_paint.c | 43 ++++++++++++++++++++++-------------------- src/gui/widget_style.c | 2 +- src/gui/widget_task.c | 2 -- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/gui/widget_paint.c b/src/gui/widget_paint.c index 08bc8d6d..8428169a 100644 --- a/src/gui/widget_paint.c +++ b/src/gui/widget_paint.c @@ -159,6 +159,14 @@ static void Widget_OnPaint( LCUI_Widget w, LCUI_PaintContext paint ) } } +/** + * 处理部件无效区域 + * @param[in] w 部件 + * @param[in] x 当前部件的绝对 X 坐标 + * @param[in] y 当前部件的绝对 Y 坐标 + * @param[in] valid_box 当前部件内的有效框 + * @param[out] rlist 收集到的无效区域列表 + */ static int _Widget_ProcInvalidArea( LCUI_Widget w, int x, int y, LCUI_Rect *valid_box, LinkedList *rlist ) @@ -168,26 +176,21 @@ static int _Widget_ProcInvalidArea( LCUI_Widget w, int x, int y, LinkedListNode *node; LCUI_Rect rect, child_box, *r; count = w->dirty_rects.length; - /* 取出当前记录的脏矩形 */ - DEBUG_MSG( "fixed xy: %d,%d\n", x, y ); + /* 取出当前记录的无效区域 */ LinkedList_ForEach( node, &w->dirty_rects ) { r = node->data; /* 若有独立位图缓存,则重绘脏矩形区域 */ - if( w->enable_graph && Graph_IsValid(&w->graph) ) { + if( w->enable_graph && Graph_IsValid( &w->graph ) ) { LCUI_PaintContextRec paint; paint.rect = *r; Graph_Quote( &paint.canvas, &w->graph, &paint.rect ); - DEBUG_MSG("[%s]: paint, rect:(%d,%d,%d,%d)\n", - w->type, r->x, r->y, r->width, r->height); Widget_OnPaint( w, &paint ); } /* 取出与容器内有效区域相交的区域 */ - if( LCUIRect_GetOverlayRect(r, valid_box, &rect) ) { - /* 转换相对于根级部件的坐标 */ + if( LCUIRect_GetOverlayRect( r, valid_box, &rect ) ) { + /* 转换成绝对坐标 */ rect.x += x; rect.y += y; - DEBUG_MSG("[%s]: merge rect:(%d,%d,%d,%d)\n", w->type, - rect.x, rect.y, rect.width, rect.height); RectList_Add( rlist, &rect ); } } @@ -196,14 +199,9 @@ static int _Widget_ProcInvalidArea( LCUI_Widget w, int x, int y, if( !w->has_dirty_child ) { return count; } - /* 缩小有效区域到当前部件内容框内,若没有重叠区域,则不向子级部件递归 */ - if( !LCUIRect_GetOverlayRect(valid_box, &w->box.padding, &child_box) ) { - return count; - } - /* 转换有效区域的坐标,相对于当前部件的内容框 */ - child_box.x -= w->box.padding.x; - child_box.y -= w->box.padding.y; - DEBUG_MSG("child valid box: %d,%d,%d,%d\n", child_box.x, child_box.y, child_box.width, child_box.height); + /* 转换为内边距框的坐标 */ + x += w->box.padding.x - w->box.graph.x; + y += w->box.padding.y - w->box.graph.y; /* 向子级部件递归 */ LinkedList_ForEach( node, &w->children ) { int child_x, child_y; @@ -211,11 +209,16 @@ static int _Widget_ProcInvalidArea( LCUI_Widget w, int x, int y, if( !child->computed_style.visible ) { continue; } - DEBUG_MSG("child graph xy: %d,%d\n", child->box.graph.x, child->box.graph.y); child_x = child->box.graph.x + x; child_y = child->box.graph.y + y; - child_x += w->box.padding.x - w->box.graph.x; - child_y += w->box.padding.y - w->box.graph.y; + /* 若有效框与子部件没有重叠区域,则不向子级部件递归 */ + if( !LCUIRect_GetOverlayRect( valid_box, &child->box.graph, + &child_box ) ) { + continue; + } + /* 转换为相对于子部件的坐标 */ + child_box.x -= child->box.graph.x; + child_box.y -= child->box.graph.y; count += _Widget_ProcInvalidArea( child, child_x, child_y, &child_box, rlist ); } diff --git a/src/gui/widget_style.c b/src/gui/widget_style.c index 12f728a4..eb7d4c32 100644 --- a/src/gui/widget_style.c +++ b/src/gui/widget_style.c @@ -1115,7 +1115,7 @@ void Widget_ExecUpdateStyle( LCUI_Widget w, LCUI_BOOL is_update_all ) s->is_changed = FALSE; if( key >= STYLE_KEY_TOTAL ) { need_update_expend_style = TRUE; - continue; + break; } for( i = 0; i < sizeof(task_map) / sizeof(TaskMap); ++i ) { if( key >= task_map[i].start && key <= task_map[i].end ) { diff --git a/src/gui/widget_task.c b/src/gui/widget_task.c index 3871f788..dbfe7cb5 100644 --- a/src/gui/widget_task.c +++ b/src/gui/widget_task.c @@ -66,14 +66,12 @@ static void HandleCacheStyle( LCUI_Widget w ) static void HandleSetTitle( LCUI_Widget w ) { - _DEBUG_MSG("widget: %s\n", w->type); Widget_PostSurfaceEvent( w, WET_TITLE ); } /** 处理主体刷新(标记主体区域为脏矩形,但不包括阴影区域) */ static void HandleBody( LCUI_Widget w ) { - DEBUG_MSG( "body\n" ); Widget_InvalidateArea( w, NULL, SV_BORDER_BOX ); } From d3de01184c4b4ebb886588e14d3eb2e7524f9bec Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Mon, 23 May 2016 21:52:01 +0800 Subject: [PATCH 003/124] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/VS2012/LCUI/LCUI.rc | Bin 5140 -> 5100 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/build/VS2012/LCUI/LCUI.rc b/build/VS2012/LCUI/LCUI.rc index 124e152868f68f0aadf28a76c309823308544795..11245c941ca77d192dc87e8fb452edca65ff2eb5 100644 GIT binary patch delta 108 zcmbQD@kV{aIWAFkhGGTU|3@!|*3}rx^!;sHVz>o`M Date: Mon, 23 May 2016 21:55:35 +0800 Subject: [PATCH 004/124] =?UTF-8?q?=E4=B8=BA=E9=83=A8=E4=BB=B6=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=20ready=20=E4=BA=8B=E4=BB=B6=EF=BC=8C=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E4=BA=8B=E4=BB=B6=E5=86=92=E6=B3=A1=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当部件在完成一次更新后会触发 ready 事件,这时可以获取到实际的坐标和尺寸。 部件在触发 ready 事件前是不可见的。 --- include/LCUI/gui/widget_base.h | 13 +++++++++++-- include/LCUI/gui/widget_event.h | 1 + src/gui/widget_base.c | 18 +++++++++++++++--- src/gui/widget_event.c | 7 ++++--- src/gui/widget_paint.c | 6 ++++-- src/gui/widget_task.c | 19 +++++++++++++------ 6 files changed, 48 insertions(+), 16 deletions(-) diff --git a/include/LCUI/gui/widget_base.h b/include/LCUI/gui/widget_base.h index ab3475ea..dd755128 100755 --- a/include/LCUI/gui/widget_base.h +++ b/include/LCUI/gui/widget_base.h @@ -215,8 +215,19 @@ typedef struct LCUI_WidgetTaskBoxRec_ { typedef struct LCUI_WidgetRec_* LCUI_Widget; +/** 部件状态 */ +enum LCUI_WidgetStatus { + WSTATUS_CREATED = 0, + WSTATUS_UPDATED, + WSTATUS_LAYOUTED, + WSTATUS_READY, + WSTATUS_NORMAL, + WSTATUS_DELETED, +}; + /** 部件结构 */ typedef struct LCUI_WidgetRec_ { + int state; /**< 状态 */ int x, y; /**< 当前坐标(由 origin 计算而来) */ int origin_x, origin_y; /**< 当前布局下计算出的坐标 */ int width, height; /**< 部件区域大小,包括边框和内边距占用区域 */ @@ -247,11 +258,9 @@ typedef struct LCUI_WidgetRec_ { LCUI_WidgetTaskBoxRec task; /**< 任务记录 */ LinkedList dirty_rects; /**< 记录无效区域(脏矩形) */ LCUI_BOOL has_dirty_child; /**< 子级部件是否有无效区域 */ - LCUI_BOOL deleted; /**< 是否已经删除 */ LCUI_BOOL layout_locked; /**< 子级部件布局是否已锁定 */ } LCUI_WidgetRec; - #define Widget_GetNode(w) (LinkedListNode*)(((char*)w) + sizeof(LCUI_WidgetRec)) #define Widget_GetShowNode(w) (LinkedListNode*)(((char*)w) + sizeof(LCUI_WidgetRec) + sizeof(LinkedListNode)) #define Widget_NewPrivateData(w, type) (type*)(w->private_data = malloc(sizeof(type))) diff --git a/include/LCUI/gui/widget_event.h b/include/LCUI/gui/widget_event.h index ad3377bf..0fa36d6c 100644 --- a/include/LCUI/gui/widget_event.h +++ b/include/LCUI/gui/widget_event.h @@ -45,6 +45,7 @@ LCUI_BEGIN_HEADER enum WidgetEventType { WET_NONE, WET_ADD, + WET_READY, WET_REMOVE, WET_DESTROY, WET_MOVE, diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index 046efb48..5340fa87 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -125,7 +125,7 @@ int Widget_Append( LCUI_Widget parent, LCUI_Widget widget ) Widget_PostSurfaceEvent( widget, WET_ADD ); Widget_AddTaskForChildren( widget, WTT_REFRESH_STYLE ); Widget_UpdateTaskStatus( widget ); - Widget_AddTask( parent, WTT_LAYOUT ); + Widget_UpdateLayout( parent ); Widget_UpdateStatusAfterAppend( widget, FALSE ); return 0; } @@ -167,7 +167,7 @@ int Widget_Unwrap( LCUI_Widget widget ) static void Widget_Init( LCUI_Widget widget ) { memset( widget, 0, sizeof(struct LCUI_WidgetRec_)); - widget->deleted = FALSE; + widget->state = WSTATUS_CREATED; widget->trigger = EventTrigger(); widget->style = StyleSheet(); widget->custom_style = StyleSheet(); @@ -249,7 +249,7 @@ void Widget_Destroy( LCUI_Widget w ) while( root->parent ) { root = root->parent; } - w->deleted = TRUE; + w->state = WSTATUS_DELETED; if( w->parent ) { LCUI_Widget child; LinkedListNode *node, *snode; @@ -1425,6 +1425,18 @@ void Widget_ExecUpdateLayout( LCUI_Widget w ) default: continue; } Widget_UpdatePosition( child ); + /* 如果部件还处于未准备完毕的状态 */ + if( child->state < WSTATUS_READY ) { + child->state |= WSTATUS_LAYOUTED; + /* 如果部件已经准备完毕则触发 ready 事件 */ + if( child->state == WSTATUS_READY ) { + LCUI_WidgetEventRec e; + e.type = WET_READY; + e.cancel_bubble = TRUE; + Widget_TriggerEvent( child, &e, NULL ); + child->state = WSTATUS_NORMAL; + } + } ctx.prev = child; ctx.prev_display = child->computed_style.display; } diff --git a/src/gui/widget_event.c b/src/gui/widget_event.c index ab951849..0d904e54 100644 --- a/src/gui/widget_event.c +++ b/src/gui/widget_event.c @@ -90,10 +90,10 @@ static void WidgetEventTranslator( LCUI_Event e, LCUI_WidgetEventPack pack ) pack->event.type = e->type; pack->event.data = handler->data; handler->func( w, &pack->event, pack->data ); - while( w && !w->deleted ) { + while( w && w->state != WSTATUS_DELETED ) { w = w->parent; } - if( w && w->deleted ) { + if( w && w->state == WSTATUS_DELETED ) { pack->event.cancel_bubble = TRUE; } w = pack->widget; @@ -268,7 +268,7 @@ static int Widget_TriggerEventEx( LCUI_Widget widget, LCUI_WidgetEvent e, default: ret = EventTrigger_Trigger( widget->trigger, e->type, &pack ); if( ret <= 0 ) { - if( !widget->parent ) { + if( !widget->parent || e->cancel_bubble ) { return -1; } /* 如果事件投递失败,则向父级部件冒泡 */ @@ -509,6 +509,7 @@ void LCUIWidget_InitEvent(void) int id; const char *name; } mappings[] = { + { WET_READY, "ready" }, { WET_DESTROY, "destroy" }, { WET_MOUSEDOWN, "mousedown" }, { WET_MOUSEUP, "mouseup" }, diff --git a/src/gui/widget_paint.c b/src/gui/widget_paint.c index 8428169a..020e0012 100644 --- a/src/gui/widget_paint.c +++ b/src/gui/widget_paint.c @@ -206,7 +206,8 @@ static int _Widget_ProcInvalidArea( LCUI_Widget w, int x, int y, LinkedList_ForEach( node, &w->children ) { int child_x, child_y; child = node->data; - if( !child->computed_style.visible ) { + if( !child->computed_style.visible || + child->state != WSTATUS_NORMAL ) { continue; } child_x = child->box.graph.x + x; @@ -370,7 +371,8 @@ void Widget_Render( LCUI_Widget w, LCUI_PaintContext paint ) LinkedList_ForEachReverse( node, &w->children_show ) { LCUI_Rect child_rect; LCUI_Widget child = node->data; - if( !child->computed_style.visible ) { + if( !child->computed_style.visible || + child->state != WSTATUS_NORMAL ) { continue; } /* 转换子部件区域,由相对于内容框转换为相对于当前脏矩形 */ diff --git a/src/gui/widget_task.c b/src/gui/widget_task.c index dbfe7cb5..1e2bb3f0 100644 --- a/src/gui/widget_task.c +++ b/src/gui/widget_task.c @@ -112,7 +112,7 @@ void Widget_AddTaskForChildren( LCUI_Widget widget, int task ) void Widget_AddTask( LCUI_Widget widget, int task ) { - if( widget->deleted ) { + if( widget->state == WSTATUS_DELETED ) { return; } widget->task.for_self = TRUE; @@ -168,9 +168,6 @@ int Widget_Update( LCUI_Widget w ) LCUI_BOOL *buffer; LCUI_Widget child; LinkedListNode *node, *next; - - DEBUG_MSG( "1,widget: %s, for_self: %d, for_children: %d\n", - w->type, w->task.for_self, w->task.for_children ); /* 如果该部件有任务需要处理 */ if( w->task.for_self ) { ret = LCUIMutex_TryLock( &w->mutex ); @@ -197,6 +194,18 @@ int Widget_Update( LCUI_Widget w ) } } LCUIMutex_Unlock( &w->mutex ); + /* 如果部件还处于未准备完毕的状态 */ + if( w->state < WSTATUS_READY ) { + w->state |= WSTATUS_UPDATED; + /* 如果部件已经准备完毕则触发 ready 事件 */ + if( w->state == WSTATUS_READY ) { + LCUI_WidgetEventRec e; + e.type = WET_READY; + e.cancel_bubble = TRUE; + Widget_TriggerEvent( w, &e, NULL ); + w->state = WSTATUS_NORMAL; + } + } } /* 删除无用部件 */ node = w->children_trash.head.next; @@ -228,8 +237,6 @@ skip_proc_self_task:; node = next; } } - DEBUG_MSG( "2,widget: %s, for_self: %d, for_children: %d\n", - w->type, w->task.for_self, w->task.for_children ); return (w->task.for_self || w->task.for_children) ? 1 : 0; } From 502b23c40504072ae6f957e3bdf67f9b55316c51 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Tue, 24 May 2016 22:31:31 +0800 Subject: [PATCH 005/124] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20Widget=5FStopEvent?= =?UTF-8?q?Propagation()=20=E5=87=BD=E6=95=B0=EF=BC=8C=E7=94=A8=E4=BA=8E?= =?UTF-8?q?=E5=81=9C=E6=AD=A2=E5=BD=93=E5=89=8D=E9=83=A8=E4=BB=B6=E6=AD=A3?= =?UTF-8?q?=E4=BC=A0=E6=92=AD=E7=9A=84=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 该函数主要在部件被销毁时调用,避免事件在部件销毁后还在传播而导致内存访问越界。 --- include/LCUI/gui/widget_event.h | 3 + src/gui/widget_event.c | 125 +++++++++++++++++++++++++++----- 2 files changed, 110 insertions(+), 18 deletions(-) diff --git a/include/LCUI/gui/widget_event.h b/include/LCUI/gui/widget_event.h index 0fa36d6c..c570d471 100644 --- a/include/LCUI/gui/widget_event.h +++ b/include/LCUI/gui/widget_event.h @@ -157,6 +157,9 @@ LCUI_API int Widget_PostSurfaceEvent( LCUI_Widget w, int event_type ); /** 清除事件对象,通常在部件销毁时调用该函数,以避免部件销毁后还有事件发送给它 */ LCUI_API void LCUIWidget_ClearEventTarget( LCUI_Widget widget ); +/** 停止部件的事件传播 */ +LCUI_API int Widget_StopEventPropagation( LCUI_Widget widget ); + /** 初始化 LCUI 部件的事件系统 */ void LCUIWidget_InitEvent(void); diff --git a/src/gui/widget_event.c b/src/gui/widget_event.c index 0d904e54..64df8779 100644 --- a/src/gui/widget_event.c +++ b/src/gui/widget_event.c @@ -65,13 +65,34 @@ enum WidgetStatusType { WST_TOTAL }; +/** 部件事件记录结点 */ +typedef struct EventRecordNodeRec_ { + LCUI_Widget widget; /**< 所属部件 */ + LinkedList records; /**< 事件记录列表 */ +} EventRecordNodeRec, *EventRecordNode; + +/** 当前功能模块的相关数据 */ static struct LCUIWidgetEvnetModule { LCUI_Widget targets[WST_TOTAL]; /**< 相关的部件 */ + LCUI_RBTree event_records; /**< 当前正执行的事件的记录 */ LCUI_RBTree event_names; /**< 事件标识号 -> 名称映射表 */ Dict *event_ids; /**< 事件名称 -> 标识号映射表 */ int base_event_id; /**< 事件标识号计数器 */ + LCUI_Mutex mutex; /**< 互斥锁 */ } self; +static int CompareEventRecord( void *data, const void *keydata ) +{ + EventRecordNode node = data; + if( node->widget == (LCUI_Widget)keydata ) { + return 0; + } else if( node->widget < (LCUI_Widget)keydata ) { + return -1; + } else { + return 1; + } +} + static void DestroyWidgetEventHandler( void *arg ) { WidgetEventHandler handler = arg; @@ -82,6 +103,44 @@ static void DestroyWidgetEventHandler( void *arg ) free( handler ); } +/** 添加事件记录 */ +static void Widget_AddEventRecord( LCUI_Widget widget, LCUI_WidgetEvent e ) +{ + EventRecordNode node; + LCUIMutex_Lock( &self.mutex ); + node = RBTree_CustomGetData( &self.event_records, widget ); + if( !node ) { + node = NEW( EventRecordNodeRec, 1 ); + LinkedList_Init( &node->records ); + node->widget = widget; + RBTree_CustomInsert( &self.event_records, widget, node ); + } + LinkedList_Append( &node->records, e ); + LCUIMutex_Unlock( &self.mutex ); +} + +/** 删除事件记录 */ +static int Widget_DeleteEventRecord( LCUI_Widget widget, LCUI_WidgetEvent e ) +{ + EventRecordNode enode; + LinkedListNode *node, *prev; + LCUIMutex_Lock( &self.mutex ); + enode = RBTree_CustomGetData( &self.event_records, widget ); + if( !enode ) { + LCUIMutex_Unlock( &self.mutex ); + return -1; + } + LinkedList_ForEach( node, &enode->records ) { + prev = node->prev; + if( node->data == e ) { + LinkedList_DeleteNode( &enode->records, node ); + node = prev; + } + } + LCUIMutex_Unlock( &self.mutex ); + return 0; +} + /** 将原始事件转换成部件事件 */ static void WidgetEventTranslator( LCUI_Event e, LCUI_WidgetEventPack pack ) { @@ -89,14 +148,9 @@ static void WidgetEventTranslator( LCUI_Event e, LCUI_WidgetEventPack pack ) LCUI_Widget w = pack->widget; pack->event.type = e->type; pack->event.data = handler->data; + Widget_AddEventRecord( w, &pack->event ); handler->func( w, &pack->event, pack->data ); - while( w && w->state != WSTATUS_DELETED ) { - w = w->parent; - } - if( w && w->state == WSTATUS_DELETED ) { - pack->event.cancel_bubble = TRUE; - } - w = pack->widget; + Widget_DeleteEventRecord( w, &pack->event ); if( pack->event.cancel_bubble || !w->parent ) { if( pack->data && pack->destroy_data ) { pack->destroy_data( pack->data ); @@ -139,16 +193,20 @@ static void OnWidgetEvent( LCUI_Event e, void *arg ) int LCUIWidget_SetEventName( int event_id, const char *event_name ) { - int *id; char *name; + int *id, ret; + LCUIMutex_Lock( &self.mutex ); if( Dict_FetchValue( self.event_ids, event_name ) ) { + LCUIMutex_Unlock( &self.mutex ); return -1; } id = malloc( sizeof( int ) ); name = strdup( event_name ); *id = event_id; RBTree_Insert( &self.event_names, event_id, name ); - return Dict_Add( self.event_ids, name, id ); + ret = Dict_Add( self.event_ids, name, id ); + LCUIMutex_Unlock( &self.mutex ); + return ret; } int LCUIWidget_AllocEventId( void ) @@ -158,15 +216,23 @@ int LCUIWidget_AllocEventId( void ) const char *LCUIWidget_GetEventName( int event_id ) { - return RBTree_GetData( &self.event_names, event_id ); + char *name; + LCUIMutex_Lock( &self.mutex ); + name = RBTree_GetData( &self.event_names, event_id ); + LCUIMutex_Unlock( &self.mutex ); + return name; } int LCUIWidget_GetEventId( const char *event_name ) { - int *val = Dict_FetchValue( self.event_ids, event_name ); + int *val; + LCUIMutex_Lock( &self.mutex ); + val = Dict_FetchValue( self.event_ids, event_name ); if( val ) { + LCUIMutex_Unlock( &self.mutex ); return *val; } + LCUIMutex_Unlock( &self.mutex ); return -1; } @@ -276,7 +342,7 @@ static int Widget_TriggerEventEx( LCUI_Widget widget, LCUI_WidgetEvent e, data, destroy_data ); } } - if( !widget->parent ) { + if( !widget->parent || e->cancel_bubble ) { return -1; } /* 转换成相对于父级部件内容框的坐标 */ @@ -289,9 +355,9 @@ static int Widget_TriggerEventEx( LCUI_Widget widget, LCUI_WidgetEvent e, return Widget_PostEvent( widget->parent, e, data, destroy_data ); } - pack.event.x -= widget->box.border.x; - pack.event.y -= widget->box.border.y; - return EventTrigger_Trigger( widget->trigger, e->type, &pack ); + pack.event.x -= w->box.border.x; + pack.event.y -= w->box.border.y; + return EventTrigger_Trigger( w->trigger, e->type, &pack ); } int Widget_PostEvent( LCUI_Widget widget, LCUI_WidgetEvent e, void *data, @@ -315,6 +381,25 @@ void LCUIWidget_ClearEventTarget( LCUI_Widget widget ) } } +int Widget_StopEventPropagation(LCUI_Widget widget ) +{ + LCUI_WidgetEvent e; + LinkedListNode *node; + EventRecordNode enode; + LCUIMutex_Lock( &self.mutex ); + enode = RBTree_CustomGetData( &self.event_records, widget ); + if( !enode ) { + LCUIMutex_Unlock( &self.mutex ); + return -1; + } + LinkedList_ForEach( node, &enode->records ) { + e = node->data; + e->cancel_bubble = TRUE; + } + LCUIMutex_Unlock( &self.mutex ); + return 0; +} + /** 更新状态 */ static void Widget_UpdateStatus( LCUI_Widget widget, int type ) { @@ -527,7 +612,9 @@ void LCUIWidget_InitEvent(void) { WET_SURFACE, "surface" }, { WET_TITLE, "title" } }; + LCUIMutex_Init( &self.mutex ); RBTree_Init( &self.event_names ); + RBTree_Init( &self.event_records ); self.targets[WST_ACTIVE] = NULL; self.targets[WST_HOVER] = NULL; self.base_event_id = WET_USER + 1000; @@ -536,18 +623,20 @@ void LCUIWidget_InitEvent(void) for( i = 0; i < n; ++i ) { LCUIWidget_SetEventName( mappings[i].id, mappings[i].name ); } + LCUI_BindEvent( LCUI_MOUSEWHEEL, OnMouseEvent, NULL, NULL ); LCUI_BindEvent( LCUI_MOUSEDOWN, OnMouseEvent, NULL, NULL ); LCUI_BindEvent( LCUI_MOUSEMOVE, OnMouseEvent, NULL, NULL ); LCUI_BindEvent( LCUI_MOUSEUP, OnMouseEvent, NULL, NULL ); - LCUI_BindEvent( LCUI_MOUSEWHEEL, OnMouseEvent, NULL, NULL ); - LCUI_BindEvent( LCUI_KEYUP, OnKeyUp, NULL, NULL ); - LCUI_BindEvent( LCUI_KEYDOWN, OnKeyDown, NULL, NULL ); LCUI_BindEvent( LCUI_KEYPRESS, OnKeyPress, NULL, NULL ); + LCUI_BindEvent( LCUI_KEYDOWN, OnKeyDown, NULL, NULL ); LCUI_BindEvent( LCUI_INPUT, OnInput, NULL, NULL ); + LCUI_BindEvent( LCUI_KEYUP, OnKeyUp, NULL, NULL ); + RBTree_OnJudge( &self.event_records, CompareEventRecord ); } void LCUIWidget_ExitEvent(void) { RBTree_Destroy( &self.event_names ); + RBTree_Destroy( &self.event_records ); Dict_Release( self.event_ids ); } From 87d0459f952fc648dccda8b2021d7f1dd6438ede Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Tue, 24 May 2016 22:32:53 +0800 Subject: [PATCH 006/124] WSTATUS_* -> WSTATE_* --- include/LCUI/gui/widget_base.h | 14 +++++++------- src/gui/widget_base.c | 13 +++++++------ src/gui/widget_paint.c | 4 ++-- src/gui/widget_task.c | 10 +++++----- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/include/LCUI/gui/widget_base.h b/include/LCUI/gui/widget_base.h index dd755128..f43b4551 100755 --- a/include/LCUI/gui/widget_base.h +++ b/include/LCUI/gui/widget_base.h @@ -216,13 +216,13 @@ typedef struct LCUI_WidgetTaskBoxRec_ { typedef struct LCUI_WidgetRec_* LCUI_Widget; /** 部件状态 */ -enum LCUI_WidgetStatus { - WSTATUS_CREATED = 0, - WSTATUS_UPDATED, - WSTATUS_LAYOUTED, - WSTATUS_READY, - WSTATUS_NORMAL, - WSTATUS_DELETED, +enum LCUI_WidgetState { + WSTATE_CREATED = 0, + WSTATE_UPDATED, + WSTATE_LAYOUTED, + WSTATE_READY, + WSTATE_NORMAL, + WSTATE_DELETED, }; /** 部件结构 */ diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index 5340fa87..2937a81c 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -167,7 +167,7 @@ int Widget_Unwrap( LCUI_Widget widget ) static void Widget_Init( LCUI_Widget widget ) { memset( widget, 0, sizeof(struct LCUI_WidgetRec_)); - widget->state = WSTATUS_CREATED; + widget->state = WSTATE_CREATED; widget->trigger = EventTrigger(); widget->style = StyleSheet(); widget->custom_style = StyleSheet(); @@ -229,6 +229,7 @@ static void Widget_OnDestroy( void *arg ) void Widget_ExecDestroy( LCUI_Widget widget ) { + Widget_StopEventPropagation( widget ); LCUIWidget_ClearEventTarget( widget ); /* 先释放显示列表,后销毁部件列表,因为部件在这两个链表中的节点是和它共用 * 一块内存空间的,销毁部件列表会把部件释放掉,所以把这个操作放在后面 */ @@ -249,7 +250,7 @@ void Widget_Destroy( LCUI_Widget w ) while( root->parent ) { root = root->parent; } - w->state = WSTATUS_DELETED; + w->state = WSTATE_DELETED; if( w->parent ) { LCUI_Widget child; LinkedListNode *node, *snode; @@ -1426,15 +1427,15 @@ void Widget_ExecUpdateLayout( LCUI_Widget w ) } Widget_UpdatePosition( child ); /* 如果部件还处于未准备完毕的状态 */ - if( child->state < WSTATUS_READY ) { - child->state |= WSTATUS_LAYOUTED; + if( child->state < WSTATE_READY ) { + child->state |= WSTATE_LAYOUTED; /* 如果部件已经准备完毕则触发 ready 事件 */ - if( child->state == WSTATUS_READY ) { + if( child->state == WSTATE_READY ) { LCUI_WidgetEventRec e; e.type = WET_READY; e.cancel_bubble = TRUE; Widget_TriggerEvent( child, &e, NULL ); - child->state = WSTATUS_NORMAL; + child->state = WSTATE_NORMAL; } } ctx.prev = child; diff --git a/src/gui/widget_paint.c b/src/gui/widget_paint.c index 020e0012..5f1af90d 100644 --- a/src/gui/widget_paint.c +++ b/src/gui/widget_paint.c @@ -207,7 +207,7 @@ static int _Widget_ProcInvalidArea( LCUI_Widget w, int x, int y, int child_x, child_y; child = node->data; if( !child->computed_style.visible || - child->state != WSTATUS_NORMAL ) { + child->state != WSTATE_NORMAL ) { continue; } child_x = child->box.graph.x + x; @@ -372,7 +372,7 @@ void Widget_Render( LCUI_Widget w, LCUI_PaintContext paint ) LCUI_Rect child_rect; LCUI_Widget child = node->data; if( !child->computed_style.visible || - child->state != WSTATUS_NORMAL ) { + child->state != WSTATE_NORMAL ) { continue; } /* 转换子部件区域,由相对于内容框转换为相对于当前脏矩形 */ diff --git a/src/gui/widget_task.c b/src/gui/widget_task.c index 1e2bb3f0..dbcfbcb9 100644 --- a/src/gui/widget_task.c +++ b/src/gui/widget_task.c @@ -112,7 +112,7 @@ void Widget_AddTaskForChildren( LCUI_Widget widget, int task ) void Widget_AddTask( LCUI_Widget widget, int task ) { - if( widget->state == WSTATUS_DELETED ) { + if( widget->state == WSTATE_DELETED ) { return; } widget->task.for_self = TRUE; @@ -195,15 +195,15 @@ int Widget_Update( LCUI_Widget w ) } LCUIMutex_Unlock( &w->mutex ); /* 如果部件还处于未准备完毕的状态 */ - if( w->state < WSTATUS_READY ) { - w->state |= WSTATUS_UPDATED; + if( w->state < WSTATE_READY ) { + w->state |= WSTATE_UPDATED; /* 如果部件已经准备完毕则触发 ready 事件 */ - if( w->state == WSTATUS_READY ) { + if( w->state == WSTATE_READY ) { LCUI_WidgetEventRec e; e.type = WET_READY; e.cancel_bubble = TRUE; Widget_TriggerEvent( w, &e, NULL ); - w->state = WSTATUS_NORMAL; + w->state = WSTATE_NORMAL; } } } From 7542c5f7071339e05bd0f87b37ea0b4a675eead3 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Tue, 24 May 2016 22:33:49 +0800 Subject: [PATCH 007/124] =?UTF-8?q?=E7=BA=A0=E6=AD=A3=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E5=99=A8=E6=A8=A1=E5=9D=97=E7=9A=84=E6=9E=90=E6=9E=84=E5=A4=84?= =?UTF-8?q?=E7=90=86=E3=80=81=E8=AE=BE=E7=BD=AE=E6=BB=9A=E5=8A=A8=E6=9D=A1?= =?UTF-8?q?=E6=9C=80=E5=B0=8F=E5=B0=BA=E5=AF=B8=E3=80=81=E5=85=B6=E5=AE=83?= =?UTF-8?q?=E5=B0=8F=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gui/widget/scrollbar.c | 2 ++ src/gui/widget_background.c | 1 + src/main.c | 2 +- src/timer.c | 2 +- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/gui/widget/scrollbar.c b/src/gui/widget/scrollbar.c index 8706aebf..15ace638 100644 --- a/src/gui/widget/scrollbar.c +++ b/src/gui/widget/scrollbar.c @@ -77,6 +77,8 @@ top: 0; left: 0; width: 14px; height: 14px; +min-width: 14px; +min-height: 14px; position: absolute; background-color: #888; } diff --git a/src/gui/widget_background.c b/src/gui/widget_background.c index 6f542ff8..62e1b22a 100644 --- a/src/gui/widget_background.c +++ b/src/gui/widget_background.c @@ -153,6 +153,7 @@ static void AsyncLoadImage( LCUI_Widget widget, const char *path ) task.func = ExecLoadImage; task.arg[0] = widget; task.arg[1] = strdup( path ); + task.destroy_arg[1] = free; LCUI_PostTask( &task ); } diff --git a/src/main.c b/src/main.c index d1c7e317..4a462208 100644 --- a/src/main.c +++ b/src/main.c @@ -237,7 +237,7 @@ int LCUI_MainLoop_Run( LCUI_MainLoop loop ) } else { LinkedList_Insert( &MainApp.loops, 0, loop ); } - _DEBUG_MSG("loop: %p, enter\n", loop); + DEBUG_MSG("loop: %p, enter\n", loop); MainApp.loop = loop; while( loop->state != STATE_EXITED ) { LCUI_WaitEvent(); diff --git a/src/timer.c b/src/timer.c index a2cf87d5..d1b15441 100644 --- a/src/timer.c +++ b/src/timer.c @@ -300,7 +300,7 @@ void LCUI_ExitTimer( void ) LCUICond_Broadcast( &self.sleep_cond ); LCUIMutex_Unlock( &self.mutex ); LCUIThread_Join( self.tid, NULL ); - LinkedList_Clear( &self.timer_list, free ); + LinkedList_ClearData( &self.timer_list, free ); LCUICond_Destroy( &self.sleep_cond ); LCUIMutex_Destroy( &self.mutex ); } From fea73815b89b86e323e88751a426ab41925047d5 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Tue, 24 May 2016 23:37:59 +0800 Subject: [PATCH 008/124] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=BD=9C=E5=9C=A8?= =?UTF-8?q?=E7=9A=84=E5=86=85=E5=AD=98=E8=AE=BF=E9=97=AE=E8=B6=8A=E7=95=8C?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gui/widget_event.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/gui/widget_event.c b/src/gui/widget_event.c index 64df8779..493df756 100644 --- a/src/gui/widget_event.c +++ b/src/gui/widget_event.c @@ -556,8 +556,9 @@ static int Dict_KeyCompare( void *privdata, const void *key1, const void *key2 ) static void *Dict_KeyDup( void *privdata, const void *key ) { - char *newkey = malloc( (wcslen( key ) + 1)*sizeof( char ) ); - strcpy( newkey, key ); + int len = strlen( key ) + 1; + char *newkey = malloc( len * sizeof( char ) ); + strncpy( newkey, key, len ); return newkey; } From 838752650a05d19144594c807f1a95c12e7b37a3 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Fri, 27 May 2016 19:03:40 +0800 Subject: [PATCH 009/124] change to use AX_PTHREAD #33 --- configure.ac | 18 +- m4/ax_pthread.m4 | 485 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 492 insertions(+), 11 deletions(-) create mode 100644 m4/ax_pthread.m4 diff --git a/configure.ac b/configure.ac index 207cd7ab..d1d30d31 100755 --- a/configure.ac +++ b/configure.ac @@ -1,9 +1,6 @@ # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. # -# 具体用法,可参考Automake的中文文档: -# http://www.linuxforum.net/books/autoconf.html -# 也可以到这看英文版的: # http://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/html_node/index.html AC_PREREQ([2.68]) @@ -65,14 +62,13 @@ want_thread=no thread_name=pthread AC_ARG_WITH(pthread, [ --with-pthread use pthread (default)]) if test "x$with_pthread" != "xno"; then - ##检测是否有pthread头文件及函数库,测试调用pthread_create函数 - AC_CHECK_HEADERS([pthread.h],[ - AC_CHECK_LIB([pthread], [pthread_create], [ - want_thread=yes - LCUI_LIBS="$LCUI_LIBS -lpthread" - AC_DEFINE_UNQUOTED(LCUI_THREAD_PTHREAD, 1, Define to 1 if you using pthread support) - ], want_thread=no) - ], want_thread=no) + m4_include([m4/ax_pthread.m4]) + AX_PTHREAD([ + want_thread=yes + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + LCUI_LIBS="$LCUI_LIBS $PTHREAD_LIBS" + AC_DEFINE_UNQUOTED(LCUI_THREAD_PTHREAD, 1, Define to 1 if you using pthread support) + ], want_thread=no) fi ##检测是否有libxml2库,必须有 libxml2 库才能启用 LCUIBuilder 功能模块 diff --git a/m4/ax_pthread.m4 b/m4/ax_pthread.m4 new file mode 100644 index 00000000..4c4051ea --- /dev/null +++ b/m4/ax_pthread.m4 @@ -0,0 +1,485 @@ +# =========================================================================== +# http://www.gnu.org/software/autoconf-archive/ax_pthread.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) +# +# DESCRIPTION +# +# This macro figures out how to build C programs using POSIX threads. It +# sets the PTHREAD_LIBS output variable to the threads library and linker +# flags, and the PTHREAD_CFLAGS output variable to any special C compiler +# flags that are needed. (The user can also force certain compiler +# flags/libs to be tested by setting these environment variables.) +# +# Also sets PTHREAD_CC to any special C compiler that is needed for +# multi-threaded programs (defaults to the value of CC otherwise). (This +# is necessary on AIX to use the special cc_r compiler alias.) +# +# NOTE: You are assumed to not only compile your program with these flags, +# but also to link with them as well. For example, you might link with +# $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS +# +# If you are only building threaded programs, you may wish to use these +# variables in your default LIBS, CFLAGS, and CC: +# +# LIBS="$PTHREAD_LIBS $LIBS" +# CFLAGS="$CFLAGS $PTHREAD_CFLAGS" +# CC="$PTHREAD_CC" +# +# In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant +# has a nonstandard name, this macro defines PTHREAD_CREATE_JOINABLE to +# that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX). +# +# Also HAVE_PTHREAD_PRIO_INHERIT is defined if pthread is found and the +# PTHREAD_PRIO_INHERIT symbol is defined when compiling with +# PTHREAD_CFLAGS. +# +# ACTION-IF-FOUND is a list of shell commands to run if a threads library +# is found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it +# is not found. If ACTION-IF-FOUND is not specified, the default action +# will define HAVE_PTHREAD. +# +# Please let the authors know if this macro fails on any platform, or if +# you have any other suggestions or comments. This macro was based on work +# by SGJ on autoconf scripts for FFTW (http://www.fftw.org/) (with help +# from M. Frigo), as well as ac_pthread and hb_pthread macros posted by +# Alejandro Forero Cuervo to the autoconf macro repository. We are also +# grateful for the helpful feedback of numerous users. +# +# Updated for Autoconf 2.68 by Daniel Richard G. +# +# LICENSE +# +# Copyright (c) 2008 Steven G. Johnson +# Copyright (c) 2011 Daniel Richard G. +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation, either version 3 of the License, or (at your +# option) any later version. +# +# This program 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 GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . +# +# As a special exception, the respective Autoconf Macro's copyright owner +# gives unlimited permission to copy, distribute and modify the configure +# scripts that are the output of Autoconf when processing the Macro. You +# need not follow the terms of the GNU General Public License when using +# or distributing such scripts, even though portions of the text of the +# Macro appear in them. The GNU General Public License (GPL) does govern +# all other use of the material that constitutes the Autoconf Macro. +# +# This special exception to the GPL applies to versions of the Autoconf +# Macro released by the Autoconf Archive. When you make and distribute a +# modified version of the Autoconf Macro, you may extend this special +# exception to the GPL to apply to your modified version as well. + +#serial 23 + +AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD]) +AC_DEFUN([AX_PTHREAD], [ +AC_REQUIRE([AC_CANONICAL_HOST]) +AC_REQUIRE([AC_PROG_CC]) +AC_REQUIRE([AC_PROG_SED]) +AC_LANG_PUSH([C]) +ax_pthread_ok=no + +# We used to check for pthread.h first, but this fails if pthread.h +# requires special compiler flags (e.g. on Tru64 or Sequent). +# It gets checked for in the link test anyway. + +# First of all, check if the user has set any of the PTHREAD_LIBS, +# etcetera environment variables, and if threads linking works using +# them: +if test "x$PTHREAD_CFLAGS$PTHREAD_LIBS" != "x"; then + ax_pthread_save_CC="$CC" + ax_pthread_save_CFLAGS="$CFLAGS" + ax_pthread_save_LIBS="$LIBS" + AS_IF([test "x$PTHREAD_CC" != "x"], [CC="$PTHREAD_CC"]) + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + LIBS="$PTHREAD_LIBS $LIBS" + AC_MSG_CHECKING([for pthread_join using $CC $PTHREAD_CFLAGS $PTHREAD_LIBS]) + AC_LINK_IFELSE([AC_LANG_CALL([], [pthread_join])], [ax_pthread_ok=yes]) + AC_MSG_RESULT([$ax_pthread_ok]) + if test "x$ax_pthread_ok" = "xno"; then + PTHREAD_LIBS="" + PTHREAD_CFLAGS="" + fi + CC="$ax_pthread_save_CC" + CFLAGS="$ax_pthread_save_CFLAGS" + LIBS="$ax_pthread_save_LIBS" +fi + +# We must check for the threads library under a number of different +# names; the ordering is very important because some systems +# (e.g. DEC) have both -lpthread and -lpthreads, where one of the +# libraries is broken (non-POSIX). + +# Create a list of thread flags to try. Items starting with a "-" are +# C compiler flags, and other items are library names, except for "none" +# which indicates that we try without any flags at all, and "pthread-config" +# which is a program returning the flags for the Pth emulation library. + +ax_pthread_flags="pthreads none -Kthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config" + +# The ordering *is* (sometimes) important. Some notes on the +# individual items follow: + +# pthreads: AIX (must check this before -lpthread) +# none: in case threads are in libc; should be tried before -Kthread and +# other compiler flags to prevent continual compiler warnings +# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h) +# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads), Tru64 +# (Note: HP C rejects this with "bad form for `-t' option") +# -pthreads: Solaris/gcc (Note: HP C also rejects) +# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it +# doesn't hurt to check since this sometimes defines pthreads and +# -D_REENTRANT too), HP C (must be checked before -lpthread, which +# is present but should not be used directly; and before -mthreads, +# because the compiler interprets this as "-mt" + "-hreads") +# -mthreads: Mingw32/gcc, Lynx/gcc +# pthread: Linux, etcetera +# --thread-safe: KAI C++ +# pthread-config: use pthread-config program (for GNU Pth library) + +case $host_os in + + freebsd*) + + # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) + # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread) + + ax_pthread_flags="-kthread lthread $ax_pthread_flags" + ;; + + hpux*) + + # From the cc(1) man page: "[-mt] Sets various -D flags to enable + # multi-threading and also sets -lpthread." + + ax_pthread_flags="-mt -pthread pthread $ax_pthread_flags" + ;; + + openedition*) + + # IBM z/OS requires a feature-test macro to be defined in order to + # enable POSIX threads at all, so give the user a hint if this is + # not set. (We don't define these ourselves, as they can affect + # other portions of the system API in unpredictable ways.) + + AC_EGREP_CPP([AX_PTHREAD_ZOS_MISSING], + [ +# if !defined(_OPEN_THREADS) && !defined(_UNIX03_THREADS) + AX_PTHREAD_ZOS_MISSING +# endif + ], + [AC_MSG_WARN([IBM z/OS requires -D_OPEN_THREADS or -D_UNIX03_THREADS to enable pthreads support.])]) + ;; + + solaris*) + + # On Solaris (at least, for some versions), libc contains stubbed + # (non-functional) versions of the pthreads routines, so link-based + # tests will erroneously succeed. (N.B.: The stubs are missing + # pthread_cleanup_push, or rather a function called by this macro, + # so we could check for that, but who knows whether they'll stub + # that too in a future libc.) So we'll check first for the + # standard Solaris way of linking pthreads (-mt -lpthread). + + ax_pthread_flags="-mt,pthread pthread $ax_pthread_flags" + ;; +esac + +# GCC generally uses -pthread, or -pthreads on some platforms (e.g. SPARC) + +AS_IF([test "x$GCC" = "xyes"], + [ax_pthread_flags="-pthread -pthreads $ax_pthread_flags"]) + +# The presence of a feature test macro requesting re-entrant function +# definitions is, on some systems, a strong hint that pthreads support is +# correctly enabled + +case $host_os in + darwin* | hpux* | linux* | osf* | solaris*) + ax_pthread_check_macro="_REENTRANT" + ;; + + aix*) + ax_pthread_check_macro="_THREAD_SAFE" + ;; + + *) + ax_pthread_check_macro="--" + ;; +esac +AS_IF([test "x$ax_pthread_check_macro" = "x--"], + [ax_pthread_check_cond=0], + [ax_pthread_check_cond="!defined($ax_pthread_check_macro)"]) + +# Are we compiling with Clang? + +AC_CACHE_CHECK([whether $CC is Clang], + [ax_cv_PTHREAD_CLANG], + [ax_cv_PTHREAD_CLANG=no + # Note that Autoconf sets GCC=yes for Clang as well as GCC + if test "x$GCC" = "xyes"; then + AC_EGREP_CPP([AX_PTHREAD_CC_IS_CLANG], + [/* Note: Clang 2.7 lacks __clang_[a-z]+__ */ +# if defined(__clang__) && defined(__llvm__) + AX_PTHREAD_CC_IS_CLANG +# endif + ], + [ax_cv_PTHREAD_CLANG=yes]) + fi + ]) +ax_pthread_clang="$ax_cv_PTHREAD_CLANG" + +ax_pthread_clang_warning=no + +# Clang needs special handling, because older versions handle the -pthread +# option in a rather... idiosyncratic way + +if test "x$ax_pthread_clang" = "xyes"; then + + # Clang takes -pthread; it has never supported any other flag + + # (Note 1: This will need to be revisited if a system that Clang + # supports has POSIX threads in a separate library. This tends not + # to be the way of modern systems, but it's conceivable.) + + # (Note 2: On some systems, notably Darwin, -pthread is not needed + # to get POSIX threads support; the API is always present and + # active. We could reasonably leave PTHREAD_CFLAGS empty. But + # -pthread does define _REENTRANT, and while the Darwin headers + # ignore this macro, third-party headers might not.) + + PTHREAD_CFLAGS="-pthread" + PTHREAD_LIBS= + + ax_pthread_ok=yes + + # However, older versions of Clang make a point of warning the user + # that, in an invocation where only linking and no compilation is + # taking place, the -pthread option has no effect ("argument unused + # during compilation"). They expect -pthread to be passed in only + # when source code is being compiled. + # + # Problem is, this is at odds with the way Automake and most other + # C build frameworks function, which is that the same flags used in + # compilation (CFLAGS) are also used in linking. Many systems + # supported by AX_PTHREAD require exactly this for POSIX threads + # support, and in fact it is often not straightforward to specify a + # flag that is used only in the compilation phase and not in + # linking. Such a scenario is extremely rare in practice. + # + # Even though use of the -pthread flag in linking would only print + # a warning, this can be a nuisance for well-run software projects + # that build with -Werror. So if the active version of Clang has + # this misfeature, we search for an option to squash it. + + AC_CACHE_CHECK([whether Clang needs flag to prevent "argument unused" warning when linking with -pthread], + [ax_cv_PTHREAD_CLANG_NO_WARN_FLAG], + [ax_cv_PTHREAD_CLANG_NO_WARN_FLAG=unknown + # Create an alternate version of $ac_link that compiles and + # links in two steps (.c -> .o, .o -> exe) instead of one + # (.c -> exe), because the warning occurs only in the second + # step + ax_pthread_save_ac_link="$ac_link" + ax_pthread_sed='s/conftest\.\$ac_ext/conftest.$ac_objext/g' + ax_pthread_link_step=`$as_echo "$ac_link" | sed "$ax_pthread_sed"` + ax_pthread_2step_ac_link="($ac_compile) && (echo ==== >&5) && ($ax_pthread_link_step)" + ax_pthread_save_CFLAGS="$CFLAGS" + for ax_pthread_try in '' -Qunused-arguments -Wno-unused-command-line-argument unknown; do + AS_IF([test "x$ax_pthread_try" = "xunknown"], [break]) + CFLAGS="-Werror -Wunknown-warning-option $ax_pthread_try -pthread $ax_pthread_save_CFLAGS" + ac_link="$ax_pthread_save_ac_link" + AC_LINK_IFELSE([AC_LANG_SOURCE([[int main(void){return 0;}]])], + [ac_link="$ax_pthread_2step_ac_link" + AC_LINK_IFELSE([AC_LANG_SOURCE([[int main(void){return 0;}]])], + [break]) + ]) + done + ac_link="$ax_pthread_save_ac_link" + CFLAGS="$ax_pthread_save_CFLAGS" + AS_IF([test "x$ax_pthread_try" = "x"], [ax_pthread_try=no]) + ax_cv_PTHREAD_CLANG_NO_WARN_FLAG="$ax_pthread_try" + ]) + + case "$ax_cv_PTHREAD_CLANG_NO_WARN_FLAG" in + no | unknown) ;; + *) PTHREAD_CFLAGS="$ax_cv_PTHREAD_CLANG_NO_WARN_FLAG $PTHREAD_CFLAGS" ;; + esac + +fi # $ax_pthread_clang = yes + +if test "x$ax_pthread_ok" = "xno"; then +for ax_pthread_try_flag in $ax_pthread_flags; do + + case $ax_pthread_try_flag in + none) + AC_MSG_CHECKING([whether pthreads work without any flags]) + ;; + + -mt,pthread) + AC_MSG_CHECKING([whether pthreads work with -mt -lpthread]) + PTHREAD_CFLAGS="-mt" + PTHREAD_LIBS="-lpthread" + ;; + + -*) + AC_MSG_CHECKING([whether pthreads work with $ax_pthread_try_flag]) + PTHREAD_CFLAGS="$ax_pthread_try_flag" + ;; + + pthread-config) + AC_CHECK_PROG([ax_pthread_config], [pthread-config], [yes], [no]) + AS_IF([test "x$ax_pthread_config" = "xno"], [continue]) + PTHREAD_CFLAGS="`pthread-config --cflags`" + PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`" + ;; + + *) + AC_MSG_CHECKING([for the pthreads library -l$ax_pthread_try_flag]) + PTHREAD_LIBS="-l$ax_pthread_try_flag" + ;; + esac + + ax_pthread_save_CFLAGS="$CFLAGS" + ax_pthread_save_LIBS="$LIBS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + LIBS="$PTHREAD_LIBS $LIBS" + + # Check for various functions. We must include pthread.h, + # since some functions may be macros. (On the Sequent, we + # need a special flag -Kthread to make this header compile.) + # We check for pthread_join because it is in -lpthread on IRIX + # while pthread_create is in libc. We check for pthread_attr_init + # due to DEC craziness with -lpthreads. We check for + # pthread_cleanup_push because it is one of the few pthread + # functions on Solaris that doesn't have a non-functional libc stub. + # We try pthread_create on general principles. + + AC_LINK_IFELSE([AC_LANG_PROGRAM([#include +# if $ax_pthread_check_cond +# error "$ax_pthread_check_macro must be defined" +# endif + static void routine(void *a) { a = 0; } + static void *start_routine(void *a) { return a; }], + [pthread_t th; pthread_attr_t attr; + pthread_create(&th, 0, start_routine, 0); + pthread_join(th, 0); + pthread_attr_init(&attr); + pthread_cleanup_push(routine, 0); + pthread_cleanup_pop(0) /* ; */])], + [ax_pthread_ok=yes], + []) + + CFLAGS="$ax_pthread_save_CFLAGS" + LIBS="$ax_pthread_save_LIBS" + + AC_MSG_RESULT([$ax_pthread_ok]) + AS_IF([test "x$ax_pthread_ok" = "xyes"], [break]) + + PTHREAD_LIBS="" + PTHREAD_CFLAGS="" +done +fi + +# Various other checks: +if test "x$ax_pthread_ok" = "xyes"; then + ax_pthread_save_CFLAGS="$CFLAGS" + ax_pthread_save_LIBS="$LIBS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + LIBS="$PTHREAD_LIBS $LIBS" + + # Detect AIX lossage: JOINABLE attribute is called UNDETACHED. + AC_CACHE_CHECK([for joinable pthread attribute], + [ax_cv_PTHREAD_JOINABLE_ATTR], + [ax_cv_PTHREAD_JOINABLE_ATTR=unknown + for ax_pthread_attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do + AC_LINK_IFELSE([AC_LANG_PROGRAM([#include ], + [int attr = $ax_pthread_attr; return attr /* ; */])], + [ax_cv_PTHREAD_JOINABLE_ATTR=$ax_pthread_attr; break], + []) + done + ]) + AS_IF([test "x$ax_cv_PTHREAD_JOINABLE_ATTR" != "xunknown" && \ + test "x$ax_cv_PTHREAD_JOINABLE_ATTR" != "xPTHREAD_CREATE_JOINABLE" && \ + test "x$ax_pthread_joinable_attr_defined" != "xyes"], + [AC_DEFINE_UNQUOTED([PTHREAD_CREATE_JOINABLE], + [$ax_cv_PTHREAD_JOINABLE_ATTR], + [Define to necessary symbol if this constant + uses a non-standard name on your system.]) + ax_pthread_joinable_attr_defined=yes + ]) + + AC_CACHE_CHECK([whether more special flags are required for pthreads], + [ax_cv_PTHREAD_SPECIAL_FLAGS], + [ax_cv_PTHREAD_SPECIAL_FLAGS=no + case $host_os in + solaris*) + ax_cv_PTHREAD_SPECIAL_FLAGS="-D_POSIX_PTHREAD_SEMANTICS" + ;; + esac + ]) + AS_IF([test "x$ax_cv_PTHREAD_SPECIAL_FLAGS" != "xno" && \ + test "x$ax_pthread_special_flags_added" != "xyes"], + [PTHREAD_CFLAGS="$ax_cv_PTHREAD_SPECIAL_FLAGS $PTHREAD_CFLAGS" + ax_pthread_special_flags_added=yes]) + + AC_CACHE_CHECK([for PTHREAD_PRIO_INHERIT], + [ax_cv_PTHREAD_PRIO_INHERIT], + [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include ]], + [[int i = PTHREAD_PRIO_INHERIT;]])], + [ax_cv_PTHREAD_PRIO_INHERIT=yes], + [ax_cv_PTHREAD_PRIO_INHERIT=no]) + ]) + AS_IF([test "x$ax_cv_PTHREAD_PRIO_INHERIT" = "xyes" && \ + test "x$ax_pthread_prio_inherit_defined" != "xyes"], + [AC_DEFINE([HAVE_PTHREAD_PRIO_INHERIT], [1], [Have PTHREAD_PRIO_INHERIT.]) + ax_pthread_prio_inherit_defined=yes + ]) + + CFLAGS="$ax_pthread_save_CFLAGS" + LIBS="$ax_pthread_save_LIBS" + + # More AIX lossage: compile with *_r variant + if test "x$GCC" != "xyes"; then + case $host_os in + aix*) + AS_CASE(["x/$CC"], + [x*/c89|x*/c89_128|x*/c99|x*/c99_128|x*/cc|x*/cc128|x*/xlc|x*/xlc_v6|x*/xlc128|x*/xlc128_v6], + [#handle absolute path differently from PATH based program lookup + AS_CASE(["x$CC"], + [x/*], + [AS_IF([AS_EXECUTABLE_P([${CC}_r])],[PTHREAD_CC="${CC}_r"])], + [AC_CHECK_PROGS([PTHREAD_CC],[${CC}_r],[$CC])])]) + ;; + esac + fi +fi + +test -n "$PTHREAD_CC" || PTHREAD_CC="$CC" + +AC_SUBST([PTHREAD_LIBS]) +AC_SUBST([PTHREAD_CFLAGS]) +AC_SUBST([PTHREAD_CC]) + +# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: +if test "x$ax_pthread_ok" = "xyes"; then + ifelse([$1],,[AC_DEFINE([HAVE_PTHREAD],[1],[Define if you have POSIX threads libraries and header files.])],[$1]) + : +else + ax_pthread_ok=no + $2 +fi +AC_LANG_POP +])dnl AX_PTHREAD From b69ff4cb9f3c5fdf98f92915ea724073d1544598 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Mon, 30 May 2016 22:58:42 +0800 Subject: [PATCH 010/124] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E7=A0=81=E5=AE=9A=E4=B9=89=EF=BC=8C=E6=94=B9?= =?UTF-8?q?=E7=94=A8=20errno.h=20=E4=B8=AD=E9=A2=84=E8=AE=BE=E7=9A=84?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/draw.h | 7 ------- src/bmp/bmp.c | 11 ++++++----- src/bmp/jpeg.c | 9 +++++---- src/bmp/load_image.c | 22 +++++++++++----------- src/bmp/png.c | 19 ++++++++++--------- 5 files changed, 32 insertions(+), 36 deletions(-) diff --git a/include/LCUI/draw.h b/include/LCUI/draw.h index 84fdd855..addaa9d9 100644 --- a/include/LCUI/draw.h +++ b/include/LCUI/draw.h @@ -43,13 +43,6 @@ #define __LCUI_DRAW_H__ LCUI_BEGIN_HEADER - -/* 打开文件时的错误 */ -#define FILE_ERROR_OPEN_ERROR -1 -#define FILE_ERROR_SHORT_FILE -2 -#define FILE_ERROR_BIG_FILE -3 -#define FILE_ERROR_UNKNOWN_FORMAT -4 -#define FILE_ERROR_MALLOC_ERROR -5 #include #include diff --git a/src/bmp/bmp.c b/src/bmp/bmp.c index 3334d5cb..f0ea2ed9 100755 --- a/src/bmp/bmp.c +++ b/src/bmp/bmp.c @@ -38,6 +38,7 @@ * ***************************************************************************/ #include +#include #include #include #include @@ -62,17 +63,17 @@ int Graph_LoadBMP( const char *filepath, LCUI_Graph *out ) int x, y, tempi, pocz, omin; FILE *fp = fopen( filepath, "rb" ); if( !fp ) { - return FILE_ERROR_OPEN_ERROR; + return ENOENT; } /* 检测是否为bmp图片 */ tempi = fread( &bmp, 1, sizeof( bmp_head ), fp ); if( tempi < sizeof( bmp_head ) || bmp.BMPsyg != 19778 ) { - return FILE_ERROR_UNKNOWN_FORMAT; + return -1; } pocz = bmp.nic[4]; if( (bmp.depth != 32) && (bmp.depth != 24) ) { _DEBUG_MSG( "can not support %i bit-depth !\n", bmp.depth ); - return FILE_ERROR_UNKNOWN_FORMAT; + return -1; } out->color_type = COLOR_TYPE_RGB; tempi = Graph_Create( out, bmp.ix, bmp.iy ); @@ -131,12 +132,12 @@ int Graph_GetBMPSize( const char *filepath, int *width, int *height ) bmp_head bmp; FILE *fp = fopen( filepath, "rb" ); if( !fp ) { - return FILE_ERROR_OPEN_ERROR; + return ENOENT; } /* 检测是否为bmp图片 */ n = fread( &bmp, 1, sizeof( bmp_head ), fp ); if( n < sizeof( bmp_head ) || bmp.BMPsyg != 19778 ) { - return FILE_ERROR_UNKNOWN_FORMAT; + return -1; } *width = bmp.ix; *height = bmp.iy; diff --git a/src/bmp/jpeg.c b/src/bmp/jpeg.c index ec57420e..db01d8bf 100755 --- a/src/bmp/jpeg.c +++ b/src/bmp/jpeg.c @@ -39,6 +39,7 @@ #include #include +#include #include #include #include @@ -85,11 +86,11 @@ int Graph_LoadJPEG( const char *filepath, LCUI_Graph *buf ) fp = fopen( filepath, "rb" ); if( !fp ) { - return FILE_ERROR_OPEN_ERROR; + return ENOENT; } if( fread( &JPsyg, sizeof( short int ), 1, fp ) ) { if( JPsyg != -9985 ) { /* 如果不是jpg图片 */ - return FILE_ERROR_UNKNOWN_FORMAT; + return -1; } } rewind( fp ); @@ -148,11 +149,11 @@ int Graph_GetJPEGSize( const char *filepath, int *width, int *height ) struct jpeg_decompress_struct cinfo; FILE *fp = fopen( filepath, "rb" ); if( !fp ) { - return FILE_ERROR_OPEN_ERROR; + return ENOENT; } if( fread( &JPsyg, sizeof( short int ), 1, fp ) ) { if( JPsyg != -9985 ) { - return FILE_ERROR_UNKNOWN_FORMAT; + return -1; } } rewind( fp ); diff --git a/src/bmp/load_image.c b/src/bmp/load_image.c index b1020938..efacef9f 100755 --- a/src/bmp/load_image.c +++ b/src/bmp/load_image.c @@ -1,22 +1,22 @@ +#include +#include +#include #include #include #include -#include -#include - /** 检测图片格式,并解码图片 */ static int Graph_DetectImage(const char *filepath, LCUI_Graph *out) { - int ret = FILE_ERROR_UNKNOWN_FORMAT; - if (ret == FILE_ERROR_UNKNOWN_FORMAT) { + int ret = -1; + if (ret == -1) { ret = Graph_LoadPNG(filepath, out); } - if (ret == FILE_ERROR_UNKNOWN_FORMAT) { + if (ret == -1) { ret = Graph_LoadJPEG(filepath, out); } - if (ret == FILE_ERROR_UNKNOWN_FORMAT) { + if (ret == -1) { ret = Graph_LoadBMP(filepath, out); } return ret; @@ -30,7 +30,7 @@ int Graph_LoadImage( const char *filepath, LCUI_Graph *out ) out->color_type = COLOR_TYPE_RGB; fp = fopen( filepath, "rb" ); if( fp == NULL ) { - return FILE_ERROR_OPEN_ERROR; + return ENOENT; } fgetc( fp ); if( !ferror( fp ) ) { @@ -39,7 +39,7 @@ int Graph_LoadImage( const char *filepath, LCUI_Graph *out ) fclose( fp ); ret = Graph_DetectImage( filepath, out ); } else { - ret = FILE_ERROR_SHORT_FILE; + ret = -1; fclose( fp ); } } @@ -49,10 +49,10 @@ int Graph_LoadImage( const char *filepath, LCUI_Graph *out ) int Graph_GetImageSize( const char *filepath, int *width, int *height ) { int ret = Graph_GetPNGSize( filepath, width, height ); - if( ret == FILE_ERROR_UNKNOWN_FORMAT ) { + if( ret != 0 ) { ret = Graph_GetJPEGSize( filepath, width, height ); } - if( ret == FILE_ERROR_UNKNOWN_FORMAT ) { + if( ret != 0 ) { ret = Graph_GetBMPSize( filepath, width, height ); } return ret; diff --git a/src/bmp/png.c b/src/bmp/png.c index c30c33d7..8a5a8532 100644 --- a/src/bmp/png.c +++ b/src/bmp/png.c @@ -39,6 +39,7 @@ #include #include +#include #include #include #include @@ -62,7 +63,7 @@ int Graph_LoadPNG( const char *filepath, LCUI_Graph *graph ) fp = fopen( filepath, "rb" ); if( fp == NULL ) { - return FILE_ERROR_OPEN_ERROR; + return ENOENT; } png_ptr = png_create_read_struct( PNG_LIBPNG_VER_STRING, 0, 0, 0 ); @@ -75,7 +76,7 @@ int Graph_LoadPNG( const char *filepath, LCUI_Graph *graph ) if( temp < PNG_BYTES_TO_CHECK ) { fclose( fp ); png_destroy_read_struct( &png_ptr, &info_ptr, 0 ); - return FILE_ERROR_UNKNOWN_FORMAT; + return -1; } /* 检测数据是否为PNG的签名 */ temp = png_sig_cmp( (png_bytep)buf, (png_size_t)0, PNG_BYTES_TO_CHECK ); @@ -83,7 +84,7 @@ int Graph_LoadPNG( const char *filepath, LCUI_Graph *graph ) if( temp != 0 ) { fclose( fp ); png_destroy_read_struct( &png_ptr, &info_ptr, 0 ); - return FILE_ERROR_UNKNOWN_FORMAT; + return -1; } /* 复位文件指针 */ rewind( fp ); @@ -104,7 +105,7 @@ int Graph_LoadPNG( const char *filepath, LCUI_Graph *graph ) graph->color_type = COLOR_TYPE_ARGB; temp = Graph_Create( graph, w, h ); if( temp != 0 ) { - ret = FILE_ERROR_MALLOC_ERROR; + ret = ENOMEM; break; } pixel_ptr = graph->bytes; @@ -126,7 +127,7 @@ int Graph_LoadPNG( const char *filepath, LCUI_Graph *graph ) graph->color_type = COLOR_TYPE_RGB; temp = Graph_Create( graph, w, h ); if( temp != 0 ) { - ret = FILE_ERROR_MALLOC_ERROR; + ret = ENOMEM; break; } pixel_ptr = graph->bytes; @@ -139,7 +140,7 @@ int Graph_LoadPNG( const char *filepath, LCUI_Graph *graph ) } break; /* 其它色彩类型的图像就读了 */ - default: ret = FILE_ERROR_UNKNOWN_FORMAT; break; + default: ret = -1; break; } fclose( fp ); png_destroy_read_struct( &png_ptr, &info_ptr, 0 ); @@ -158,7 +159,7 @@ int Graph_GetPNGSize( const char *filepath, int *width, int *height ) char buf[PNG_BYTES_TO_CHECK]; FILE *fp = fopen( filepath, "rb" ); if( !fp ) { - return FILE_ERROR_OPEN_ERROR; + return ENOENT; } png_ptr = png_create_read_struct( PNG_LIBPNG_VER_STRING, 0, 0, 0 ); info_ptr = png_create_info_struct( png_ptr ); @@ -167,13 +168,13 @@ int Graph_GetPNGSize( const char *filepath, int *width, int *height ) if( ret < PNG_BYTES_TO_CHECK ) { fclose( fp ); png_destroy_read_struct( &png_ptr, &info_ptr, 0 ); - return FILE_ERROR_UNKNOWN_FORMAT; + return -1; } ret = png_sig_cmp( (png_bytep)buf, (png_size_t)0, PNG_BYTES_TO_CHECK ); if( ret != 0 ) { fclose( fp ); png_destroy_read_struct( &png_ptr, &info_ptr, 0 ); - return FILE_ERROR_UNKNOWN_FORMAT; + return -1; } rewind( fp ); png_init_io( png_ptr, fp ); From 7315edb43464d2ca936755fd003fd82724780f57 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Mon, 30 May 2016 23:01:18 +0800 Subject: [PATCH 011/124] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E7=9A=84=E6=95=B0=E6=8D=AE=E7=BB=93=E6=9E=84?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0=E8=A7=A6=E5=B1=8F=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/main.h | 52 +++++++++++++++-- src/cursor.c | 4 +- src/gui/widget_event.c | 2 +- src/main.c | 12 ++++ src/platform/windows/windows_display.c | 1 + src/platform/windows/windows_events.c | 3 +- src/platform/windows/windows_keyboard.c | 4 +- src/platform/windows/windows_mouse.c | 74 ++++++++++++++++++++++--- 8 files changed, 134 insertions(+), 18 deletions(-) diff --git a/include/LCUI/main.h b/include/LCUI/main.h index dae68257..d39c7feb 100644 --- a/include/LCUI/main.h +++ b/include/LCUI/main.h @@ -60,17 +60,57 @@ enum LCUI_SysEventType { LCUI_MOUSEUP, /**< 鼠标触发的按钮释放事件 */ LCUI_MOUSEWHEEL, /**< 鼠标触发的滚轮滚动事件 */ LCUI_INPUT, /**< 输入法触发的文本输入事件 */ + LCUI_TOUCH, + LCUI_TOUCHMOVE, + LCUI_TOUCHDOWN, + LCUI_TOUCHUP, LCUI_WIDGET, LCUI_QUIT, /**< 在 LCUI 退出前触发的事件 */ LCUI_USER = 100 /**< 用户事件,可以把这个当成系统事件与用户事件的分界 */ }; +typedef struct LCUI_TouchPointRec_ { + int x; + int y; + int id; + int state; + LCUI_BOOL is_primary; +} LCUI_TouchPointRec, *LCUI_TouchPoint; + +typedef struct LCUI_KeyboardEvent_ { + int code; +} LCUI_KeyboardEvent; + +typedef struct LCUI_MouseMotionEvent_ { + int x, y; + int xrel, yrel; +} LCUI_MouseMotionEvent; + +typedef struct LCUI_MouseButtonEvent_ { + int x, y; + int button; +} LCUI_MouseButtonEvent; + +typedef struct LCUI_MouseWheelEvent_ { + int x, y; + int delta; +} LCUI_MouseWheelEvent; + +typedef struct LCUI_TouchEvent_ { + int n_points; + LCUI_TouchPoint points; +} LCUI_TouchEvent; + typedef struct LCUI_SysEventRec_ { - int type; /**< 事件类型标识号 */ - int key_code; /**< 按键的键值 */ - int rel_x, rel_y; /**< 鼠标的坐标与上次坐标的差值 */ - int z_delta; /**< 鼠标滚轮滚动速度 */ - void *data; /**< 附加数据 */ + uint32_t type; + void *data; + union { + LCUI_MouseMotionEvent motion; + LCUI_MouseButtonEvent button; + LCUI_MouseWheelEvent wheel; + LCUI_KeyboardEvent key; + LCUI_TouchEvent touch; + }; } LCUI_SysEventRec, *LCUI_SysEvent; typedef void(*LCUI_SysEventFunc)(LCUI_SysEvent, void*); @@ -99,6 +139,8 @@ LCUI_API int LCUI_UnbindEvent( int handler_id ); LCUI_API int LCUI_TriggerEvent( LCUI_SysEvent e, void *arg ); +LCUI_API void LCUI_DestroyEvent( LCUI_SysEvent e ); + LCUI_API LCUI_BOOL LCUI_WaitEvent( void ); LCUI_API int LCUI_BindSysEvent( int event_id, LCUI_EventFunc func, diff --git a/src/cursor.c b/src/cursor.c index d2f0dc2f..fbeef445 100644 --- a/src/cursor.c +++ b/src/cursor.c @@ -106,8 +106,8 @@ static int LCUICursor_LoadDefualtGraph(LCUI_Graph *buff ) static void OnMouseMoveEvent( LCUI_SysEvent e, void *arg ) { - global_cursor.pos.x += e->rel_x; - global_cursor.pos.y += e->rel_y; + global_cursor.pos.x += e->motion.xrel; + global_cursor.pos.y += e->motion.yrel; global_cursor.new_pos = global_cursor.pos; DEBUG_MSG("x: %d, y: %d\n", global_cursor.pos.x, global_cursor.pos.y); } diff --git a/src/gui/widget_event.c b/src/gui/widget_event.c index 493df756..eb113493 100644 --- a/src/gui/widget_event.c +++ b/src/gui/widget_event.c @@ -490,7 +490,7 @@ static void OnMouseEvent( LCUI_SysEvent e, void *arg ) break; case LCUI_MOUSEWHEEL: ebuff.type = WET_MOUSEWHEEL; - ebuff.z_delta = e->z_delta; + ebuff.z_delta = e->wheel.delta; Widget_PostEvent( target, &ebuff, NULL, NULL ); default:return; } diff --git a/src/main.c b/src/main.c index 4a462208..ecf780b2 100644 --- a/src/main.c +++ b/src/main.c @@ -177,6 +177,18 @@ int LCUI_TriggerEvent( LCUI_SysEvent e, void *arg ) return ret; } +void LCUI_DestroyEvent( LCUI_SysEvent e ) +{ + if( e->type == LCUI_TOUCH ) { + if( e->touch.n_points > 0 && e->touch.points ) { + free( e->touch.points ); + e->touch.points = NULL; + e->touch.n_points = 0; + } + } + e->type = LCUI_NONE; +} + /*--------------------------- system event ----------------------------*/ LCUI_BOOL LCUI_PostTask( LCUI_AppTask task ) diff --git a/src/platform/windows/windows_display.c b/src/platform/windows/windows_display.c index 47f5e3cb..55831d7a 100644 --- a/src/platform/windows/windows_display.c +++ b/src/platform/windows/windows_display.c @@ -158,6 +158,7 @@ static void OnCreateSurface( void *arg1, void *arg2 ) instance, NULL ); hdc_client = GetDC( surface->hwnd ); + RegisterTouchWindow( surface->hwnd, 0 ); surface->fb_hdc = CreateCompatibleDC( hdc_client ); surface->is_ready = TRUE; DEBUG_MSG("surface: %p, surface->hwnd: %p\n", surface, surface->hwnd); diff --git a/src/platform/windows/windows_events.c b/src/platform/windows/windows_events.c index 8b4326e4..db31f634 100644 --- a/src/platform/windows/windows_events.c +++ b/src/platform/windows/windows_events.c @@ -139,13 +139,14 @@ int LCUI_InitWinApp( LCUI_AppDriver app ) /** * 创建一个隐藏的主窗体,用于接收 LCUI 的任务 * 之前用 PostThreadMessage() 无法发送自定义消息到主线程的消息循环,因此 - * 改成创建隐藏窗体兵用 PostMessage() 发送任务。 + * 改成创建隐藏窗体并用 PostMessage() 发送任务。 */ win.main_hwnd = CreateWindow( TEXT("LCUI"), TEXT("LCUI Task Receiver"), 0, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL, win.main_instance, NULL ); + RegisterTouchWindow( win.main_hwnd, 0 ); return 0; } diff --git a/src/platform/windows/windows_keyboard.c b/src/platform/windows/windows_keyboard.c index 4c25ffbc..2783425c 100644 --- a/src/platform/windows/windows_keyboard.c +++ b/src/platform/windows/windows_keyboard.c @@ -14,11 +14,11 @@ static void OnKeyboardMessage( LCUI_Event ev, void *arg ) switch( win_ev->msg ) { case WM_KEYDOWN: sys_ev.type = LCUI_KEYDOWN; - sys_ev.key_code = win_ev->wparam; + sys_ev.key.code = win_ev->wparam; break; case WM_KEYUP: sys_ev.type = LCUI_KEYUP; - sys_ev.key_code = win_ev->wparam; + sys_ev.key.code = win_ev->wparam; break; default: return; } diff --git a/src/platform/windows/windows_mouse.c b/src/platform/windows/windows_mouse.c index b8432ffd..056866cc 100644 --- a/src/platform/windows/windows_mouse.c +++ b/src/platform/windows/windows_mouse.c @@ -17,8 +17,10 @@ static void OnMouseMessage( LCUI_Event ev, void *arg ) POINT new_pos; GetCursorPos( &new_pos ); ScreenToClient( win_ev->hwnd, &new_pos ); - sys_ev.rel_x = new_pos.x - mouse_pos.x; - sys_ev.rel_y = new_pos.y - mouse_pos.y; + sys_ev.motion.x = new_pos.x; + sys_ev.motion.y = new_pos.y; + sys_ev.motion.xrel = new_pos.x - mouse_pos.x; + sys_ev.motion.yrel = new_pos.y - mouse_pos.y; mouse_pos.x = new_pos.x; mouse_pos.y = new_pos.y; sys_ev.type = LCUI_MOUSEMOVE; @@ -26,28 +28,84 @@ static void OnMouseMessage( LCUI_Event ev, void *arg ) } case WM_LBUTTONDOWN: sys_ev.type = LCUI_MOUSEDOWN; - sys_ev.key_code = 1; + sys_ev.button.button = 1; + sys_ev.button.x = mouse_pos.x; + sys_ev.button.y = mouse_pos.y; break; case WM_LBUTTONUP: sys_ev.type = LCUI_MOUSEUP; - sys_ev.key_code = 1; + sys_ev.button.button = 1; + sys_ev.button.x = mouse_pos.x; + sys_ev.button.y = mouse_pos.y; break; case WM_RBUTTONDOWN: sys_ev.type = LCUI_MOUSEDOWN; - sys_ev.key_code = 2; + sys_ev.button.button = 2; + sys_ev.button.x = mouse_pos.x; + sys_ev.button.y = mouse_pos.y; break; case WM_RBUTTONUP: sys_ev.type = LCUI_MOUSEUP; - sys_ev.key_code = 2; + sys_ev.button.button = 2; + sys_ev.button.x = mouse_pos.x; + sys_ev.button.y = mouse_pos.y; break; case WM_MOUSEWHEEL: sys_ev.type = LCUI_MOUSEWHEEL; - sys_ev.z_delta = GET_WHEEL_DELTA_WPARAM( win_ev->wparam ); + sys_ev.wheel.x = mouse_pos.x; + sys_ev.wheel.y = mouse_pos.y; + sys_ev.wheel.delta = GET_WHEEL_DELTA_WPARAM( win_ev->wparam ); break; + case WM_TOUCH: { + UINT i, n = LOWORD( win_ev->wparam ); + PTOUCHINPUT inputs = NEW( TOUCHINPUT, n ); + HTOUCHINPUT handle = (HTOUCHINPUT)win_ev->lparam; + if( inputs == NULL ) { + break; + } + sys_ev.type = LCUI_TOUCH; + sys_ev.touch.n_points = n; + sys_ev.touch.points = NEW( LCUI_TouchPointRec, n ); + if( sys_ev.touch.points == NULL ) { + free( inputs ); + break; + } + if( !GetTouchInputInfo( handle, n, inputs, + sizeof( TOUCHINPUT ) ) ) { + break; + } + for( i = 0; i < n; ++i ) { + POINT pos; + pos.x = inputs[i].x / 100; + pos.y = inputs[i].y / 100; + ScreenToClient( win_ev->hwnd, &pos ); + sys_ev.touch.points[i].x = pos.x; + sys_ev.touch.points[i].y = pos.y; + sys_ev.touch.points[i].id = inputs[i].dwID; + if( inputs[i].dwFlags & TOUCHEVENTF_PRIMARY ) { + sys_ev.touch.points[i].is_primary = TRUE; + } else { + sys_ev.touch.points[i].is_primary = FALSE; + } + if( inputs[i].dwFlags & TOUCHEVENTF_DOWN ) { + sys_ev.touch.points[i].state = LCUI_TOUCHDOWN; + } else if( inputs[i].dwFlags & TOUCHEVENTF_UP ) { + sys_ev.touch.points[i].state = LCUI_TOUCHUP; + } else if( inputs[i].dwFlags & TOUCHEVENTF_MOVE ) { + sys_ev.touch.points[i].state = LCUI_TOUCHMOVE; + } + } + free( inputs ); + if( !CloseTouchInputHandle( handle ) ) { + break; + } + break; + } default: break; } if( sys_ev.type != LCUI_NONE ) { LCUI_TriggerEvent( &sys_ev, NULL ); + LCUI_DestroyEvent( &sys_ev ); } } @@ -59,6 +117,7 @@ void LCUI_InitWinMouse( void ) LCUI_BindSysEvent( WM_RBUTTONDOWN, OnMouseMessage, NULL, NULL ); LCUI_BindSysEvent( WM_RBUTTONUP, OnMouseMessage, NULL, NULL ); LCUI_BindSysEvent( WM_MOUSEWHEEL, OnMouseMessage, NULL, NULL ); + LCUI_BindSysEvent( WM_TOUCH, OnMouseMessage, NULL, NULL ); } void LCUI_ExitWinMouse( void ) @@ -69,5 +128,6 @@ void LCUI_ExitWinMouse( void ) LCUI_UnbindSysEvent( WM_RBUTTONDOWN, OnMouseMessage ); LCUI_UnbindSysEvent( WM_RBUTTONUP, OnMouseMessage ); LCUI_UnbindSysEvent( WM_MOUSEWHEEL, OnMouseMessage ); + LCUI_UnbindSysEvent( WM_TOUCH, OnMouseMessage ); } #endif From 310a22aae29c2a4d07d518adb37a2c68ad189d1e Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Mon, 30 May 2016 23:02:02 +0800 Subject: [PATCH 012/124] =?UTF-8?q?=E4=B8=BA=E6=BB=9A=E5=8A=A8=E5=B1=82?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=A7=A6=E5=B1=8F=E6=8B=96=E5=8A=A8=E6=94=AF?= =?UTF-8?q?=E6=8C=81=EF=BC=88=E5=BE=85=E5=AE=8C=E5=96=84=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gui/widget/scrollbar.c | 61 +++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 7 deletions(-) diff --git a/src/gui/widget/scrollbar.c b/src/gui/widget/scrollbar.c index 15ace638..4dbe31fa 100644 --- a/src/gui/widget/scrollbar.c +++ b/src/gui/widget/scrollbar.c @@ -37,6 +37,7 @@ * 没有,请查看:. * ****************************************************************************/ +#include #include #include #include @@ -54,9 +55,12 @@ typedef struct LCUI_ScrollBarRec_ { int slider_x, slider_y; /**< 拖拽开始时的滑块位置 */ int mouse_x, mouse_y; /**< 拖拽开始时的鼠标坐标 */ int direction; /**< 滚动条的方向(垂直或水平) */ - int eids[2]; /**< 鼠标事件的绑定ID */ + int eid_mousemove; + int eid_mouseup; + int eid_touch; int scroll_step; /**< 每次滚动的距离,主要针对使用鼠标滚轮触发的滚动 */ int pos; /**< 当前的位置 */ + int old_pos; /**< 拖拽开始时的位置 */ } LCUI_ScrollBarRec, *LCUI_ScrollBar; static int scroll_event_id = -1; @@ -102,10 +106,18 @@ static void OnMouseUp( LCUI_SysEvent e, void *arg ) { LCUI_Widget w = e->data; LCUI_ScrollBar scrollbar = w->private_data; - LCUI_UnbindEvent( scrollbar->eids[0] ); - LCUI_UnbindEvent( scrollbar->eids[1] ); - scrollbar->eids[0] = -1; - scrollbar->eids[1] = -1; + if( scrollbar->eid_mousemove > 0 ) { + LCUI_UnbindEvent( scrollbar->eid_mousemove ); + } + if( scrollbar->eid_mouseup > 0 ) { + LCUI_UnbindEvent( scrollbar->eid_mouseup ); + } + if( scrollbar->eid_touch > 0 ) { + LCUI_UnbindEvent( scrollbar->eid_touch ); + } + scrollbar->eid_mousemove = -1; + scrollbar->eid_mouseup = -1; + scrollbar->eid_touch = -1; scrollbar->is_dragging = FALSE; } @@ -184,6 +196,22 @@ static void OnMouseMove( LCUI_SysEvent e, void *arg ) Widget_Move( scrollbar->slider, x, y ); } +static void OnTouch( LCUI_SysEvent e, void *arg ) +{ + int pos; + LCUI_TouchPoint point; + LCUI_Widget w = e->data; + LCUI_ScrollBar scrollbar = w->private_data; + if( e->touch.n_points < 1 ) { + return; + } + point = &e->touch.points[0]; + if( point->state == LCUI_TOUCHMOVE ) { + pos = scrollbar->old_pos - (point->y - scrollbar->mouse_y); + ScrollBar_SetPosition( w, pos ); + } +} + static void OnMouseDown( LCUI_Widget slider, LCUI_WidgetEvent e, void *arg ) { LCUI_Widget w = slider->parent; @@ -196,8 +224,10 @@ static void OnMouseDown( LCUI_Widget slider, LCUI_WidgetEvent e, void *arg ) scrollbar->mouse_x = e->screen_x; scrollbar->mouse_y = e->screen_y; scrollbar->is_dragging = TRUE; - scrollbar->eids[0] = LCUI_BindEvent( LCUI_MOUSEMOVE, OnMouseMove, w, NULL ); - scrollbar->eids[1] = LCUI_BindEvent( LCUI_MOUSEUP, OnMouseUp, w, NULL ); + scrollbar->eid_mousemove = LCUI_BindEvent( LCUI_MOUSEMOVE, + OnMouseMove, w, NULL ); + scrollbar->eid_mouseup = LCUI_BindEvent( LCUI_MOUSEUP, + OnMouseUp, w, NULL ); } static void ScrollBar_OnInit( LCUI_Widget w ) @@ -212,9 +242,13 @@ static void ScrollBar_OnInit( LCUI_Widget w ) self->direction = SBD_VERTICAL; self->is_dragging = FALSE; self->scroll_step = 40; + self->eid_mousemove = -1; + self->eid_mouseup = -1; + self->eid_touch = -1; self->slider = slider; self->layer = NULL; self->box = NULL; + self->old_pos = 0; self->pos = 0; } @@ -269,6 +303,18 @@ static void ScrollLayer_OnWheel( LCUI_Widget layer, LCUI_WidgetEvent e, void *ar ScrollBar_SetPosition( w, pos ); } +static void ScrollLayer_OnMouseDown( LCUI_Widget layer, LCUI_WidgetEvent e, void *arg ) +{ + LCUI_Widget w = e->data; + LCUI_ScrollBar scrollbar = w->private_data; + scrollbar->eid_touch = LCUI_BindEvent( LCUI_TOUCH, OnTouch, w, NULL ); + scrollbar->eid_mouseup = LCUI_BindEvent( LCUI_MOUSEUP, OnMouseUp, w, NULL ); + scrollbar->mouse_x = e->screen_x; + scrollbar->mouse_y = e->screen_y; + scrollbar->old_pos = scrollbar->pos; + scrollbar->is_dragging = TRUE; +} + static void ScrollBar_OnUpdateSize( LCUI_Widget box, LCUI_WidgetEvent e, void *arg ) { ScrollBar_UpdateSize( e->data ); @@ -296,6 +342,7 @@ void ScrollBar_BindLayer( LCUI_Widget w, LCUI_Widget layer ) scrollbar->layer = layer; Widget_BindEvent( layer, "resize", ScrollBar_OnUpdateSize, w, NULL ); Widget_BindEvent( layer, "mousewheel", ScrollLayer_OnWheel, w, NULL ); + Widget_BindEvent( layer, "mousedown", ScrollLayer_OnMouseDown, w, NULL ); ScrollBar_UpdateSize( w ); } From 72d2636fc54105348ae6287fb24eb6f462c7373d Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Mon, 30 May 2016 23:35:47 +0800 Subject: [PATCH 013/124] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AE=8F=E5=91=BD?= =?UTF-8?q?=E5=90=8D=E6=A0=BC=E5=BC=8F=20#31?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/LCUI.h | 6 +- include/LCUI/cursor.h | 4 +- include/LCUI/display.h | 4 +- include/LCUI/draw.h | 4 +- include/LCUI/draw/background.h | 4 +- include/LCUI/draw/border.h | 4 +- include/LCUI/draw/boxshadow.h | 4 +- include/LCUI/draw/line.h | 4 +- include/LCUI/font.h | 4 +- include/LCUI/font/charset.h | 4 +- include/LCUI/font/fontlibrary.h | 4 +- include/LCUI/font/textlayer.h | 4 +- include/LCUI/font/textstyle.h | 4 +- include/LCUI/graph.h | 6 +- include/LCUI/gui/builder.h | 4 +- include/LCUI/gui/css_parser.h | 4 +- include/LCUI/gui/messagebox.h | 120 -- include/LCUI/gui/widget.h | 4 +- include/LCUI/gui/widget/button.h | 4 +- include/LCUI/gui/widget/scrollbar.h | 4 +- include/LCUI/gui/widget/sidebar.h | 4 +- include/LCUI/gui/widget/textview.h | 4 +- include/LCUI/gui/widget_base.h | 12 +- include/LCUI/gui/widget_event.h | 4 +- include/LCUI/gui/widget_library.h | 4 +- include/LCUI/gui/widget_paint.h | 4 +- include/LCUI/gui/widget_style.h | 4 +- include/LCUI/gui/widget_task.h | 4 +- include/LCUI/ime.h | 4 +- include/LCUI/input.h | 6 +- include/LCUI/main.h | 4 +- include/LCUI/platform.h | 4 +- .../LCUI/platform/windows/windows_display.h | 4 +- .../LCUI/platform/windows/windows_events.h | 4 +- .../LCUI/platform/windows/windows_keyboard.h | 4 +- include/LCUI/platform/windows/windows_mouse.h | 4 +- include/LCUI/surface.h | 6 +- include/LCUI/thread.h | 4 +- include/LCUI/timer.h | 4 +- include/LCUI/util/delay.h | 4 +- include/LCUI/util/dict.h | 6 +- include/LCUI/util/dirent.h | 4 +- include/LCUI/util/event.h | 4 +- include/LCUI/util/framectrl.h | 6 +- include/LCUI/util/linkedlist.h | 4 +- include/LCUI/util/parse.h | 4 +- include/LCUI/util/rbtree.h | 4 +- include/LCUI/util/rect.h | 4 +- include/LCUI/util/string.h | 4 +- include/LCUI/util/time.h | 4 +- include/LCUI_Build.h | 4 +- src/gui/messagebox.c | 1775 ----------------- src/gui/widget/scrollbar.c | 3 + src/gui/widget_task.c | 1 - src/main.c | 2 - src/platform/windows/windows_display.c | 2 +- src/platform/windows/windows_mouse.c | 1 + src/util/framectrl.c | 2 +- 58 files changed, 113 insertions(+), 2013 deletions(-) delete mode 100755 include/LCUI/gui/messagebox.h delete mode 100755 src/gui/messagebox.c diff --git a/include/LCUI/LCUI.h b/include/LCUI/LCUI.h index 1096e956..47f31dc9 100755 --- a/include/LCUI/LCUI.h +++ b/include/LCUI/LCUI.h @@ -39,8 +39,8 @@ * ****************************************************************************/ /* 为了解决结构体被重复定义,用宏进行头文件保护(其它地方出现类似的内容,将不再注释) */ -#ifndef __LCUI_H__ /* 如果没有定义 __LCUI_H__ 宏 */ -#define __LCUI_H__ /* 定义 __LCUI_H__ 宏 */ +#ifndef LCUI_H /* 如果没有定义 LCUI_H 宏 */ +#define LCUI_H /* 定义 LCUI_H 宏 */ #define LCUI_VERSION "1.0.0" @@ -312,4 +312,4 @@ LCUI_END_HEADER #include #include -#endif /* __LCUI_H__ */ +#endif /* LCUI_H */ diff --git a/include/LCUI/cursor.h b/include/LCUI/cursor.h index 739b985f..cf31d65b 100644 --- a/include/LCUI/cursor.h +++ b/include/LCUI/cursor.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_CURSOR_H__ -#define __LCUI_CURSOR_H__ +#ifndef LCUI_CURSOR_H +#define LCUI_CURSOR_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/display.h b/include/LCUI/display.h index 69b72e4b..f87f9df2 100644 --- a/include/LCUI/display.h +++ b/include/LCUI/display.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_DISPLAY_H__ -#define __LCUI_DISPLAY_H__ +#ifndef LCUI_DISPLAY_CONTROL_H +#define LCUI_DISPLAY_CONTROL_H #include #include diff --git a/include/LCUI/draw.h b/include/LCUI/draw.h index addaa9d9..dcbf91ba 100644 --- a/include/LCUI/draw.h +++ b/include/LCUI/draw.h @@ -39,8 +39,8 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_DRAW_H__ -#define __LCUI_DRAW_H__ +#ifndef LCUI_DRAW_H +#define LCUI_DRAW_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/draw/background.h b/include/LCUI/draw/background.h index eeb22350..7a62b289 100644 --- a/include/LCUI/draw/background.h +++ b/include/LCUI/draw/background.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ***************************************************************************/ -#ifndef __LCUI_DRAW_BACKGROUND_H__ -#define __LCUI_DRAW_BACKGROUND_H__ +#ifndef LCUI_DRAW_BACKGROUND_H +#define LCUI_DRAW_BACKGROUND_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/draw/border.h b/include/LCUI/draw/border.h index b81e887e..ce27e717 100755 --- a/include/LCUI/draw/border.h +++ b/include/LCUI/draw/border.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ***************************************************************************/ -#ifndef __LCUI_DRAW_BORDER_H__ -#define __LCUI_DRAW_BORDER_H__ +#ifndef LCUI_DRAW_BORDER_H +#define LCUI_DRAW_BORDER_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/draw/boxshadow.h b/include/LCUI/draw/boxshadow.h index 593c8ba3..3de55c32 100644 --- a/include/LCUI/draw/boxshadow.h +++ b/include/LCUI/draw/boxshadow.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ***************************************************************************/ -#ifndef __LCUI_DRAW_BOXSHADOW_H__ -#define __LCUI_DRAW_BOXSHADOW_H__ +#ifndef LCUI_DRAW_BOXSHADOW_H +#define LCUI_DRAW_BOXSHADOW_H LCUI_API LCUI_BoxShadow BoxShadow( int x, int y, int blur, LCUI_Color color ); diff --git a/include/LCUI/draw/line.h b/include/LCUI/draw/line.h index dccded48..183d4cae 100644 --- a/include/LCUI/draw/line.h +++ b/include/LCUI/draw/line.h @@ -1,6 +1,6 @@  -#ifndef __LCUI_DRAW_LINE_H__ -#define __LCUI_DRAW_LINE_H__ +#ifndef LCUI_DRAW_LINE_H +#define LCUI_DRAW_LINE_H /* 绘制水平线 */ LCUI_API void Graph_DrawHorizLine( LCUI_Graph *graph, LCUI_Color color, int size, LCUI_Pos start, int end_x ); diff --git a/include/LCUI/font.h b/include/LCUI/font.h index 43293e06..a2254fda 100644 --- a/include/LCUI/font.h +++ b/include/LCUI/font.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ***************************************************************************/ -#ifndef __LCUI_FONT_H__ -#define __LCUI_FONT_H__ +#ifndef LCUI_FONT_H +#define LCUI_FONT_H #include #include diff --git a/include/LCUI/font/charset.h b/include/LCUI/font/charset.h index 312e391e..d3ef1844 100755 --- a/include/LCUI/font/charset.h +++ b/include/LCUI/font/charset.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_CHARSET_H__ -#define __LCUI_CHARSET_H__ +#ifndef LCUI_CHARSET_H +#define LCUI_CHARSET_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/font/fontlibrary.h b/include/LCUI/font/fontlibrary.h index 0d18d69c..007862b7 100755 --- a/include/LCUI/font/fontlibrary.h +++ b/include/LCUI/font/fontlibrary.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_FONT_LIBRARY_H__ -#define __LCUI_FONT_LIBRARY_H__ +#ifndef LCUI_FONT_LIBRARY_H +#define LCUI_FONT_LIBRARY_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/font/textlayer.h b/include/LCUI/font/textlayer.h index f88e76b2..204d30a5 100755 --- a/include/LCUI/font/textlayer.h +++ b/include/LCUI/font/textlayer.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_TEXTLAYER_H__ -#define __LCUI_TEXTLAYER_H__ +#ifndef LCUI_TEXTLAYER_H +#define LCUI_TEXTLAYER_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/font/textstyle.h b/include/LCUI/font/textstyle.h index c1f2eea3..e7cbc666 100755 --- a/include/LCUI/font/textstyle.h +++ b/include/LCUI/font/textstyle.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_TEXTSTYLE_H__ -#define __LCUI_TEXTSTYLE_H__ +#ifndef LCUI_TEXTSTYLE_H +#define LCUI_TEXTSTYLE_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/graph.h b/include/LCUI/graph.h index c398aa00..6b63ff39 100644 --- a/include/LCUI/graph.h +++ b/include/LCUI/graph.h @@ -36,8 +36,8 @@ * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果s * 没有,请查看:. * ***************************************************************************/ -#ifndef __LCUI_GRAPH_H__ -#define __LCUI_GRAPH_H__ +#ifndef LCUI_GRAPH_H +#define LCUI_GRAPH_H LCUI_BEGIN_HEADER @@ -223,4 +223,4 @@ LCUI_END_HEADER #include -#endif /* __LCUI_GRAPH_H__ */ +#endif /* LCUI_GRAPH_H */ diff --git a/include/LCUI/gui/builder.h b/include/LCUI/gui/builder.h index e0baf668..ca51a331 100644 --- a/include/LCUI/gui/builder.h +++ b/include/LCUI/gui/builder.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_BUILDER_H__ -#define __LCUI_BUILDER_H__ +#ifndef LCUI_BUILDER_H +#define LCUI_BUILDER_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/gui/css_parser.h b/include/LCUI/gui/css_parser.h index 4f63d2d8..6c27f77f 100644 --- a/include/LCUI/gui/css_parser.h +++ b/include/LCUI/gui/css_parser.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_CSS_PARSER_H__ -#define __LCUI_CSS_PARSER_H__ +#ifndef LCUI_CSS_PARSER_H +#define LCUI_CSS_PARSER_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/gui/messagebox.h b/include/LCUI/gui/messagebox.h deleted file mode 100755 index 047dfe80..00000000 --- a/include/LCUI/gui/messagebox.h +++ /dev/null @@ -1,120 +0,0 @@ -/* *************************************************************************** - * messagebox.h -- MessageBox for LCUI - * - * Copyright (C) 2012-2013 by - * Liu Chao - * - * 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 . - * ****************************************************************************/ - -/* **************************************************************************** - * messagebox.h -- LCUI 的消息框 - * - * 版权所有 (C) 2012-2013 归属于 - * 刘超 - * - * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 - * - * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) - * - * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 - * - * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 - * 定用途的隐含担保,详情请参照GPLv2许可协议。 - * - * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 - * 没有,请查看:. - * ****************************************************************************/ -#ifndef __LCUI_GUI_MESSAGEBOX_H__ -#define __LCUI_GUI_MESSAGEBOX_H__ - -LCUI_BEGIN_HEADER - -typedef enum { - MB_ICON_NONE, - MB_ICON_ERROR, - MB_ICON_HELP, - MB_ICON_INFO, - MB_ICON_WARNING -} MB_ICON_TYPE; - -typedef enum { - MB_BTN_OK, - MB_BTN_OKCANCEL, - MB_BTN_ABORTRETRYIGNORE, - MB_BTN_RETRYCANCEL, - MB_BTN_YESNO, - MB_BTN_YESNOCANCEL -} MB_BTN_TYPE; - -typedef enum { - MB_BTN_IS_OK, - MB_BTN_IS_CANCEL, - MB_BTN_IS_ABORT, - MB_BTN_IS_RETRY, - MB_BTN_IS_IGNORE, - MB_BTN_IS_YES, - MB_BTN_IS_NO, - MB_BTN_IS_QUIT -} MB_BTN; - -/* LCUI的消息框 - * 参数: - * icon_type : 指定消息框中显示的图标,可取以下值: - * MB_ICON_NONE 无图标 - * MB_ICON_ERROR “错误”图标 - * MB_ICON_HELP ”帮助“图标 - * MB_ICON_INFO “信息”图标 - * MB_ICON_WARNING “警告”图标 - * text : 消息框内显示的消息内容 - * title : 消息框的标题文本 - * button : 指定消息框内显示的按钮,可取以下值: - * MB_BTN_OK : 一个“确定”按钮 - * MB_BTN_OKCANCEL : “确定”和“取消”按钮 - * MB_BTN_ABORTRETRYIGNORE : “终止”、"重试"和“忽略”按钮 - * MB_BTN_RETRYCANCEL : "重试"和“取消”按钮 - * MB_BTN_YESNO : "是"和“否”按钮 - * MB_BTN_YESNOCANCEL : “是”、"否"和“取消”按钮 - * 返回值: - * -1 : button参数的值异常 - * -2 : 无法获取消息框关闭时所点击的按钮ID - * 正常则会返回按钮的ID,有以下值: - * MB_BTN_IS_OK : "确定"按钮 - * MB_BTN_IS_CANCEL: "取消"按钮 - * MB_BTN_IS_ABORT : "终止"按钮 - * MB_BTN_IS_RETRY : "重试"按钮 - * MB_BTN_IS_IGNORE: "忽略"按钮 - * MB_BTN_IS_YES : "是"按钮 - * MB_BTN_IS_NO : "否"按钮 - * MB_BTN_IS_QUIT : 窗口右上角的关闭按钮 - * */ -LCUI_API int -LCUI_MessageBoxW( MB_ICON_TYPE icon_type, const wchar_t *text, - const wchar_t *title, MB_BTN_TYPE button ); - -/* UTF-8版的LCUI_MessageBox */ -LCUI_API int -LCUI_MessageBox( MB_ICON_TYPE icon_type, const char *text, - const char *title, MB_BTN_TYPE button ); - -/* ASCII版的LCUI_MessageBox */ -LCUI_API int -LCUI_MessageBoxA( MB_ICON_TYPE icon_type, const char *text, - const char *title, MB_BTN_TYPE button ); - -LCUI_END_HEADER - -#endif diff --git a/include/LCUI/gui/widget.h b/include/LCUI/gui/widget.h index 7a22e70e..924aeb1a 100644 --- a/include/LCUI/gui/widget.h +++ b/include/LCUI/gui/widget.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_WIDGET_BUILD_H__ -#define __LCUI_WIDGET_BUILD_H__ +#ifndef LCUI_WIDGET_BUILD_H +#define LCUI_WIDGET_BUILD_H #include #include diff --git a/include/LCUI/gui/widget/button.h b/include/LCUI/gui/widget/button.h index 32a6c85d..7ff7b06a 100644 --- a/include/LCUI/gui/widget/button.h +++ b/include/LCUI/gui/widget/button.h @@ -36,8 +36,8 @@ * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_BUTTON_H__ -#define __LCUI_BUTTON_H__ +#ifndef LCUI_BUTTON_H +#define LCUI_BUTTON_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/gui/widget/scrollbar.h b/include/LCUI/gui/widget/scrollbar.h index 7d1ffc39..8ed0f7ba 100644 --- a/include/LCUI/gui/widget/scrollbar.h +++ b/include/LCUI/gui/widget/scrollbar.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_SCROLLBAR_H__ -#define __LCUI_SCROLLBAR_H__ +#ifndef LCUI_SCROLLBAR_H +#define LCUI_SCROLLBAR_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/gui/widget/sidebar.h b/include/LCUI/gui/widget/sidebar.h index ba461e8c..cc584bae 100644 --- a/include/LCUI/gui/widget/sidebar.h +++ b/include/LCUI/gui/widget/sidebar.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_SIDEBAR_WIDGET_H__ -#define __LCUI_SIDEBAR_WIDGET_H__ +#ifndef LCUI_SIDEBAR_WIDGET_H +#define LCUI_SIDEBAR_WIDGET_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/gui/widget/textview.h b/include/LCUI/gui/widget/textview.h index 6bbbb094..bb5facad 100644 --- a/include/LCUI/gui/widget/textview.h +++ b/include/LCUI/gui/widget/textview.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_TEXTVIEW_H__ -#define __LCUI_TEXTVIEW_H__ +#ifndef LCUI_TEXTVIEW_H +#define LCUI_TEXTVIEW_H #include diff --git a/include/LCUI/gui/widget_base.h b/include/LCUI/gui/widget_base.h index f43b4551..e8556942 100755 --- a/include/LCUI/gui/widget_base.h +++ b/include/LCUI/gui/widget_base.h @@ -37,13 +37,13 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_WIDGET_BASE_H__ -#define __LCUI_WIDGET_BASE_H__ +#ifndef LCUI_WIDGET_BASE_H +#define LCUI_WIDGET_BASE_H LCUI_BEGIN_HEADER /** 如果没有包含 widget_build.h 头文件 */ -#ifndef __LCUI_WIDGET_BUILD_H__ +#ifndef LCUI_WIDGET_BUILD_H typedef struct LCUI_WidgetBase* LCUI_Widget; #endif @@ -193,12 +193,6 @@ enum WidgetTaskType { WTT_TOTAL_NUM }; -#ifndef __IN_WIDGET_TASK_SOURCE_FILE__ -typedef void* LCUI_WidgetTaskBox; -#else -typedef struct LCUI_WidgetTaskBoxRec_* LCUI_WidgetTaskBox; -#endif - typedef struct LCUI_WidgetBoxRect { LCUI_Rect content; /**< 内容框的区域 */ LCUI_Rect padding; /**< 内边距框的区域 */ diff --git a/include/LCUI/gui/widget_event.h b/include/LCUI/gui/widget_event.h index c570d471..c531810b 100644 --- a/include/LCUI/gui/widget_event.h +++ b/include/LCUI/gui/widget_event.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ***************************************************************************/ -#ifndef __LCUI_WIDGET_EVENT_H__ -#define __LCUI_WIDGET_EVENT_H__ +#ifndef LCUI_WIDGET_EVENT_H +#define LCUI_WIDGET_EVENT_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/gui/widget_library.h b/include/LCUI/gui/widget_library.h index 46143262..d8c48bc8 100644 --- a/include/LCUI/gui/widget_library.h +++ b/include/LCUI/gui/widget_library.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ***************************************************************************/ -#ifndef __LCUI_WIDGET_LIBRARY_H__ -#define __LCUI_WIDGET_LIBRARY_H__ +#ifndef LCUI_WIDGET_LIBRARY_H +#define LCUI_WIDGET_LIBRARY_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/gui/widget_paint.h b/include/LCUI/gui/widget_paint.h index a164a347..c4415f87 100644 --- a/include/LCUI/gui/widget_paint.h +++ b/include/LCUI/gui/widget_paint.h @@ -38,8 +38,8 @@ * 没有,请查看:. * ***************************************************************************/ -#ifndef __WIDGET_PAINT_H__ -#define __WIDGET_PAINT_H__ +#ifndef __WIDGET_PAINT_H +#define __WIDGET_PAINT_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/gui/widget_style.h b/include/LCUI/gui/widget_style.h index b12d6940..0cd6d1bb 100644 --- a/include/LCUI/gui/widget_style.h +++ b/include/LCUI/gui/widget_style.h @@ -38,8 +38,8 @@ * ****************************************************************************/ -#ifndef __LCUI_WIDGET_STYLE_LIBRARY_H__ -#define __LCUI_WIDGET_STYLE_LIBRARY_H__ +#ifndef LCUI_WIDGET_STYLE_LIBRARY_H +#define LCUI_WIDGET_STYLE_LIBRARY_H /** 初始化 */ void LCUIWidget_InitStyle( void ); diff --git a/include/LCUI/gui/widget_task.h b/include/LCUI/gui/widget_task.h index c2f2304d..7d9fbe0e 100644 --- a/include/LCUI/gui/widget_task.h +++ b/include/LCUI/gui/widget_task.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ***************************************************************************/ -#ifndef __LCUI_WIDGET_TASK_H__ -#define __LCUI_WIDGET_TASK_H__ +#ifndef LCUI_WIDGET_TASK_H +#define LCUI_WIDGET_TASK_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/ime.h b/include/LCUI/ime.h index f992652d..d943e749 100644 --- a/include/LCUI/ime.h +++ b/include/LCUI/ime.h @@ -1,5 +1,5 @@ -#ifndef __LCUI_IME_H__ -#define __LCUI_IME_H__ +#ifndef LCUI_IME_H +#define LCUI_IME_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/input.h b/include/LCUI/input.h index 475a2541..3e733a6f 100644 --- a/include/LCUI/input.h +++ b/include/LCUI/input.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ***************************************************************************/ -#ifndef __LCUI_INPUT_H__ -#define __LCUI_INPUT_H__ +#ifndef LCUI_INPUT_H +#define LCUI_INPUT_H #define LCUIKEY_SPACE ' ' #define LCUIKEY_0 '0' @@ -170,4 +170,4 @@ LCUI_API int LCUI_ExitKeyboard( void ); LCUI_END_HEADER -#endif /* __LCUI_INPUT_H__ */ +#endif /* LCUI_INPUT_H */ diff --git a/include/LCUI/main.h b/include/LCUI/main.h index d39c7feb..59ab9041 100644 --- a/include/LCUI/main.h +++ b/include/LCUI/main.h @@ -36,8 +36,8 @@ * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 * 没有,请查看:. * ***************************************************************************/ -#ifndef __LCUI_LIB_MAIN_H__ -#define __LCUI_LIB_MAIN_H__ +#ifndef LCUI_LIB_MAIN_H +#define LCUI_LIB_MAIN_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/platform.h b/include/LCUI/platform.h index 02064936..443ab294 100644 --- a/include/LCUI/platform.h +++ b/include/LCUI/platform.h @@ -1,5 +1,5 @@ -#ifndef __LCUI_PLATFORM_H__ -#define __LCUI_PLATFORM_H__ +#ifndef LCUI_PLATFORM_H +#define LCUI_PLATFORM_H #ifdef LCUI_BUILD_IN_WIN32 #define LCUI_InitApp LCUI_InitWinApp diff --git a/include/LCUI/platform/windows/windows_display.h b/include/LCUI/platform/windows/windows_display.h index 2f3dc2ae..edba8f33 100644 --- a/include/LCUI/platform/windows/windows_display.h +++ b/include/LCUI/platform/windows/windows_display.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_WINDOWS_DISPLAY_H__ -#define __LCUI_WINDOWS_DISPLAY_H__ +#ifndef LCUI_WINDOWS_DISPLAY_H +#define LCUI_WINDOWS_DISPLAY_H int LCUI_InitWinDisplay( LCUI_DisplayDriver driver ); diff --git a/include/LCUI/platform/windows/windows_events.h b/include/LCUI/platform/windows/windows_events.h index 0db46767..dfa3aa08 100644 --- a/include/LCUI/platform/windows/windows_events.h +++ b/include/LCUI/platform/windows/windows_events.h @@ -1,5 +1,5 @@ -#ifndef __WINDOWS_EVENTS_H__ -#define __WINDOWS_EVENTS_H__ +#ifndef __WINDOWS_EVENTS_H +#define __WINDOWS_EVENTS_H typedef struct WIN_SysEvent_ { HWND hwnd; diff --git a/include/LCUI/platform/windows/windows_keyboard.h b/include/LCUI/platform/windows/windows_keyboard.h index 6ce540b2..cf4f5c1d 100644 --- a/include/LCUI/platform/windows/windows_keyboard.h +++ b/include/LCUI/platform/windows/windows_keyboard.h @@ -1,5 +1,5 @@ -#ifndef __LCUI_WINDOWS_KEYBOARD__ -#define __LCUI_WINDOWS_KEYBOARD__ +#ifndef LCUI_WINDOWS_KEYBOARD__ +#define LCUI_WINDOWS_KEYBOARD__ void LCUI_InitWinKeyboard( void ); diff --git a/include/LCUI/platform/windows/windows_mouse.h b/include/LCUI/platform/windows/windows_mouse.h index b6342c4d..8c488556 100644 --- a/include/LCUI/platform/windows/windows_mouse.h +++ b/include/LCUI/platform/windows/windows_mouse.h @@ -1,5 +1,5 @@ -#ifndef __LCUI_WINDOWS_MOUSE_H__ -#define __LCUI_WINDOWS_MOUSE_H__ +#ifndef LCUI_WINDOWS_MOUSE_H +#define LCUI_WINDOWS_MOUSE_H void LCUI_InitWinMouse( void ); diff --git a/include/LCUI/surface.h b/include/LCUI/surface.h index 5805325b..18dc9645 100644 --- a/include/LCUI/surface.h +++ b/include/LCUI/surface.h @@ -37,13 +37,13 @@ * 没有,请查看:. * ***************************************************************************/ -#ifndef __LCUI_SURFACE_H__ -#define __LCUI_SURFACE_H__ +#ifndef LCUI_SURFACE_H +#define LCUI_SURFACE_H #define RENDER_MODE_BIT_BLT 0 #define RENDER_MODE_STRETCH_BLT 1 -#ifdef __IN_SURFACE_SOURCE_FILE__ +#ifdef LCUI_SURFACE_C typedef struct LCUI_SurfaceRec_ * LCUI_Surface; #else typedef void* LCUI_Surface; diff --git a/include/LCUI/thread.h b/include/LCUI/thread.h index 9a7687ca..242c8b0b 100644 --- a/include/LCUI/thread.h +++ b/include/LCUI/thread.h @@ -39,8 +39,8 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_THREAD_H__ -#define __LCUI_THREAD_H__ +#ifndef LCUI_THREAD_H +#define LCUI_THREAD_H #ifdef LCUI_THREAD_PTHREAD #include diff --git a/include/LCUI/timer.h b/include/LCUI/timer.h index 86d9d2fd..c4266626 100644 --- a/include/LCUI/timer.h +++ b/include/LCUI/timer.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ***************************************************************************/ -#ifndef __LCUI_TIMER_H__ -#define __LCUI_TIMER_H__ +#ifndef LCUI_TIMER_H +#define LCUI_TIMER_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/util/delay.h b/include/LCUI/util/delay.h index 1d31b662..2fe3cc33 100644 --- a/include/LCUI/util/delay.h +++ b/include/LCUI/util/delay.h @@ -36,8 +36,8 @@ * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_UTIL_DELAY_H__ -#define __LCUI_UTIL_DELAY_H__ +#ifndef LCUI_UTIL_DELAY_H +#define LCUI_UTIL_DELAY_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/util/dict.h b/include/LCUI/util/dict.h index 379f02f4..9f89da13 100644 --- a/include/LCUI/util/dict.h +++ b/include/LCUI/util/dict.h @@ -34,8 +34,8 @@ #include -#ifndef __DICT_H__ -#define __DICT_H__ +#ifndef __DICT_H +#define __DICT_H /** 哈希表节点结构 */ typedef struct DictEntry { @@ -231,4 +231,4 @@ extern DictType dictTypeHeapStringCopyKey; extern DictType dictTypeHeapStrings; extern DictType dictTypeHeapStringCopyKeyValue; -#endif /* __DICT_H__ */ +#endif /* __DICT_H */ diff --git a/include/LCUI/util/dirent.h b/include/LCUI/util/dirent.h index e4072180..12403074 100644 --- a/include/LCUI/util/dirent.h +++ b/include/LCUI/util/dirent.h @@ -1,6 +1,6 @@ // dirent.h -- Directory Entry pperation set. -#ifndef __LCUI_DIRECTORY_ENTRY_H__ -#define __LCUI_DIRECTORY_ENTRY_H__ +#ifndef LCUI_DIRECTORY_ENTRY_H +#define LCUI_DIRECTORY_ENTRY_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/util/event.h b/include/LCUI/util/event.h index 8fdd1643..d8c5d797 100644 --- a/include/LCUI/util/event.h +++ b/include/LCUI/util/event.h @@ -36,8 +36,8 @@ * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_LIB_EVENT_H__ -#define __LCUI_LIB_EVENT_H__ +#ifndef LCUI_LIB_EVENT_H +#define LCUI_LIB_EVENT_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/util/framectrl.h b/include/LCUI/util/framectrl.h index 7f576457..1372dd3e 100644 --- a/include/LCUI/util/framectrl.h +++ b/include/LCUI/util/framectrl.h @@ -38,12 +38,12 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LC_FRAME_CONTROL_H__ -#define __LC_FRAME_CONTROL_H__ +#ifndef __LC_FRAME_CONTROL_H +#define __LC_FRAME_CONTROL_H LCUI_BEGIN_HEADER -#ifdef __IN_FRAME_CONTROL_SOURCE_FILE__ +#ifdef LCUI_FRAME_CONTROL_C typedef struct FrameControlContext* FrameCtrlCtx; #else typedef void* FrameCtrlCtx; diff --git a/include/LCUI/util/linkedlist.h b/include/LCUI/util/linkedlist.h index b7975b36..725c0dc2 100644 --- a/include/LCUI/util/linkedlist.h +++ b/include/LCUI/util/linkedlist.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_UTIL_LINKEDLIST_H__ -#define __LCUI_UTIL_LINKEDLIST_H__ +#ifndef LCUI_UTIL_LINKEDLIST_H +#define LCUI_UTIL_LINKEDLIST_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/util/parse.h b/include/LCUI/util/parse.h index 5cab33ce..02372bbe 100644 --- a/include/LCUI/util/parse.h +++ b/include/LCUI/util/parse.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ***************************************************************************/ -#ifndef __LCUI_UTIL_PARSE_H__ -#define __LCUI_UTIL_PARSE_H__ +#ifndef LCUI_UTIL_PARSE_H +#define LCUI_UTIL_PARSE_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/util/rbtree.h b/include/LCUI/util/rbtree.h index 75f4174e..7ca41ac6 100644 --- a/include/LCUI/util/rbtree.h +++ b/include/LCUI/util/rbtree.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ***************************************************************************/ -#ifndef __LCUI_UTIL_RBTREE_H__ -#define __LCUI_UTIL_RBTREE_H__ +#ifndef LCUI_UTIL_RBTREE_H +#define LCUI_UTIL_RBTREE_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/util/rect.h b/include/LCUI/util/rect.h index ba321bad..383c7058 100644 --- a/include/LCUI/util/rect.h +++ b/include/LCUI/util/rect.h @@ -38,8 +38,8 @@ * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_MISC_RECT_H__ -#define __LCUI_MISC_RECT_H__ +#ifndef LCUI_MISC_RECT_H +#define LCUI_MISC_RECT_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/util/string.h b/include/LCUI/util/string.h index 25962af0..ef10ee5f 100644 --- a/include/LCUI/util/string.h +++ b/include/LCUI/util/string.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_MISC_STRING_H__ -#define __LCUI_MISC_STRING_H__ +#ifndef LCUI_MISC_STRING_H +#define LCUI_MISC_STRING_H #ifdef LCUI_BUILD_IN_WIN32 #include diff --git a/include/LCUI/util/time.h b/include/LCUI/util/time.h index 1dcc3980..f0ba24f4 100644 --- a/include/LCUI/util/time.h +++ b/include/LCUI/util/time.h @@ -1,6 +1,6 @@  -#ifndef __LCUI_LIB_TIME_H__ -#define __LCUI_LIB_TIME_H__ +#ifndef LCUI_LIB_TIME_H +#define LCUI_LIB_TIME_H LCUI_BEGIN_HEADER diff --git a/include/LCUI_Build.h b/include/LCUI_Build.h index 5da32a83..4493e731 100755 --- a/include/LCUI_Build.h +++ b/include/LCUI_Build.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_BUILD_H__ -#define __LCUI_BUILD_H__ +#ifndef LCUI_BUILD_H +#define LCUI_BUILD_H #if defined(__GNUC__) # define LCUI_API diff --git a/src/gui/messagebox.c b/src/gui/messagebox.c deleted file mode 100755 index 15d00e77..00000000 --- a/src/gui/messagebox.c +++ /dev/null @@ -1,1775 +0,0 @@ -/* *************************************************************************** - * messagebox.c -- MessageBox for LCUI - * - * Copyright (C) 2012-2013 by - * Liu Chao - * - * 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 . - * ****************************************************************************/ - -/* **************************************************************************** - * messagebox.c -- LCUI 的消息框 - * - * 版权所有 (C) 2012-2013 归属于 - * 刘超 - * - * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 - * - * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) - * - * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 - * - * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 - * 定用途的隐含担保,详情请参照GPLv2许可协议。 - * - * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 - * 没有,请查看:. - * ****************************************************************************/ -#ifdef ENABLE_THIS_MODULE -#include -#include -#include -#include -#include -#include -#include LC_LABEL_H -#include LC_BUTTON_H -#include LC_PICBOX_H -#include LC_WINDOW_H - -#define TEXT_MB_BTN_OK L"确定" -#define TEXT_MB_BTN_CANCEL L"取消" -#define TEXT_MB_BTN_ABORT L"终止" -#define TEXT_MB_BTN_IGNORE L"忽略" -#define TEXT_MB_BTN_RETRY L"重试" -#define TEXT_MB_BTN_YES L"是" -#define TEXT_MB_BTN_NO L"否" - -#define WIDGET_ID_MB_MSG_AREA 30 - -#define MB_BTN_SIZE Size(65, 28) -#define MB_BTN_AREA_BGCOLOR RGB(215,235,240) -#define MB_BTN_AREA_LINECOLOR RGB(180,200,240) -#define MB_ICONBOX_SIZE Size(48,48) -#define WIDGET_ID_MESSAGEBOX 1<<5 -#define MSGBOX_NONE_ICON 1<<6 -#define MB_BTN_AREA_HEIGHT 40 -#define MB_MSG_AREA_HEIGHT 55 -#define MB_BTN_AREA_HEIGHT_TEXT "40px" -#define MB_MSG_AREA_HEIGHT_TEXT "55px" - -enum IMG_ID { - IMG_ID_ERROR, - IMG_ID_HELP, - IMG_ID_INFO, - IMG_ID_WARNING, - IMG_TOTAL_NUM -}; - -typedef struct { - LCUI_MainLoop *mainloop; - LCUI_Widget msgbox; - MB_BTN clicked_button; -} MB_data; - -static unsigned char msgbox_icon[IMG_TOTAL_NUM][4][48*48] = { -{ - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,116,116,120,147, - 182,213,235,249,254,254,254,249,235,213,182,147,120,116,116,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,116,116,119,144,203,250,253,247,238,227,214,204,196,200,210,222,235,246,253,249,202,144,119, - 116,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,119,145,222,255,248,232,209, - 209,212,216,216,215,212,209,204,199,194,190,192,222,245,254,222,145,119,116,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,116,124,204,255,248,224,211,220,227,223,218,214,212,211,209,207,206,204,201,198,194,188,181,205,243, - 255,203,124,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,143,235,253,232,211,224,229,221,217, - 217,219,219,220,220,219,217,215,212,210,205,201,197,191,182,174,214,250,234,143,116,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,116,159,250,247,218,219,232,223,218,219,223,224,225,223,223,221,220,218,218,215,212,210,208,204,200,196,187, - 175,188,240,250,159,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,160,254,244,212,225,226,218,221,224,225,225, - 223,224,222,221,220,219,215,214,213,211,211,208,205,203,199,196,192,176,179,234,254,158,116,0,0,0,0,0,0,0,0,0, - 0,0,0,116,143,250,244,209,226,222,216,222,225,227,224,223,222,221,219,219,217,215,213,211,209,209,207,205,203,202,199,197, - 193,190,175,179,232,249,138,116,0,0,0,0,0,0,0,0,0,0,116,124,234,245,211,225,220,217,223,224,221,217,220,221, - 220,219,217,215,213,211,209,209,206,203,204,201,197,193,196,195,193,189,187,176,180,238,232,122,116,0,0,0,0,0,0,0, - 0,116,119,203,251,216,222,220,215,221,224,219,233,247,230,212,217,215,213,211,211,210,205,205,203,202,198,197,219,220,191,189, - 191,188,185,183,171,189,247,193,118,116,0,0,0,0,0,0,0,116,145,255,230,215,222,213,219,223,215,231,255,255,255,224, - 204,211,210,209,206,204,201,201,200,195,193,221,222,230,228,184,183,185,183,179,177,165,212,253,135,115,0,0,0,0,0,0, - 116,119,220,247,205,225,213,216,221,217,231,255,255,255,255,255,221,201,207,203,203,201,199,199,195,191,219,221,212,208,223,224, - 179,179,180,177,174,171,153,236,206,117,108,0,0,0,0,0,116,144,255,220,215,215,213,219,216,225,255,255,255,255,255,255, - 255,218,196,202,201,199,197,193,192,221,219,212,208,206,199,218,213,173,175,173,172,170,163,207,249,131,110,0,0,0,0,0, - 116,203,247,202,218,209,214,218,211,232,255,255,255,255,255,255,255,255,216,190,197,194,191,190,219,218,211,209,204,201,194,233, - 214,164,170,169,168,167,165,182,232,172,111,0,0,0,0,116,120,250,227,208,211,210,214,213,212,207,242,255,255,255,255,254, - 248,249,250,213,184,189,189,218,218,211,208,204,201,194,232,217,124,143,167,165,163,163,161,163,219,223,116,89,0,0,0,116, - 147,253,198,212,205,209,211,212,210,208,197,235,255,255,253,248,244,238,238,243,207,181,217,218,212,205,201,198,193,231,216,121, - 134,145,160,159,158,159,157,150,195,243,129,102,0,0,0,116,179,246,195,208,203,209,210,208,206,204,202,193,233,255,250,243, - 239,236,229,232,237,220,214,206,202,196,193,187,230,213,119,133,146,160,159,159,158,158,157,154,174,237,154,106,0,0,0,116, - 210,235,196,201,203,206,206,204,202,200,201,198,187,226,246,239,235,229,226,218,216,212,201,198,194,190,187,228,213,119,134,146, - 163,160,160,160,159,158,159,157,159,230,180,107,0,0,0,116,234,218,197,198,201,203,204,202,200,198,197,195,193,185,221,237, - 230,222,216,211,205,201,199,194,192,187,228,214,122,134,146,164,163,163,161,160,160,160,160,160,154,227,207,109,0,0,0,116, - 249,201,197,197,200,201,200,200,197,195,193,192,192,189,177,212,223,213,211,205,202,199,194,190,187,228,214,122,133,146,164,164, - 164,164,163,163,161,161,161,162,147,224,221,112,0,0,0,116,254,185,196,194,199,200,197,195,194,192,191,191,185,179,173,166, - 200,213,206,201,198,194,190,187,228,215,121,134,148,164,164,164,164,164,164,164,164,164,164,164,151,218,230,118,0,0,0,116, - 254,175,194,193,197,196,194,192,191,190,189,181,175,172,169,169,201,207,200,197,194,190,188,184,193,214,154,143,166,167,167,167, - 167,167,167,168,168,167,167,167,154,218,232,115,0,0,0,116,254,181,189,189,192,192,191,190,189,186,177,173,172,169,169,207, - 208,199,197,193,190,187,184,181,178,193,218,184,161,168,169,169,169,171,171,171,171,171,172,170,154,222,231,115,0,0,0,116, - 247,194,183,188,190,190,189,188,183,176,172,172,169,168,206,207,198,196,193,190,185,182,181,180,180,175,192,218,184,166,171,172, - 172,172,173,173,175,175,175,173,153,229,227,114,0,0,0,116,230,211,177,185,188,189,188,182,173,171,171,167,168,203,208,198, - 196,192,189,186,224,187,179,180,178,180,180,196,219,184,169,175,175,176,177,177,178,178,178,177,157,235,213,126,0,0,0,116, - 207,228,169,183,184,184,182,172,171,169,166,166,202,206,198,195,192,189,184,224,213,173,181,178,182,183,187,188,208,225,186,172, - 178,180,180,181,183,183,183,180,172,237,182,113,0,0,0,116,179,242,162,180,181,180,172,169,168,166,164,199,206,197,195,190, - 188,184,225,213,121,133,178,182,183,187,192,198,202,221,231,187,178,184,184,185,186,187,187,176,191,242,153,85,0,0,0,116, - 148,251,166,173,177,171,169,168,166,164,198,205,198,195,192,188,182,225,213,121,134,148,164,178,187,193,199,205,213,221,236,236, - 191,187,190,190,190,191,189,173,215,235,119,61,0,0,0,116,120,247,209,154,166,166,166,164,159,180,208,198,194,190,188,183, - 225,213,120,133,148,166,168,167,183,199,208,213,222,231,236,254,228,183,194,195,196,196,191,182,232,204,108,23,0,0,0,0, - 116,196,239,136,160,162,164,163,159,164,201,195,189,189,183,225,212,117,133,146,166,167,169,172,171,187,213,225,231,237,250,248, - 195,185,199,200,200,200,185,204,242,149,86,0,0,0,0,0,116,140,253,176,147,160,162,160,159,154,164,195,188,183,225,212, - 117,129,145,163,166,169,172,173,177,175,195,227,241,251,251,196,150,177,203,205,205,201,165,233,244,117,57,0,0,0,0,0, - 116,118,216,236,135,154,158,158,158,155,150,158,188,206,209,115,127,142,161,164,167,169,172,176,178,183,178,200,241,248,197,152, - 179,207,208,209,210,190,179,244,178,98,13,0,0,0,0,0,0,116,139,254,189,139,156,155,153,153,152,146,154,174,114,127, - 142,160,161,164,167,169,173,177,180,184,188,186,201,188,156,182,209,209,213,213,209,165,228,246,117,55,0,0,0,0,0,0, - 0,116,118,198,245,158,142,153,152,151,149,149,149,144,133,138,158,159,163,164,169,172,176,178,183,187,190,195,191,191,182,210, - 214,215,216,217,175,207,248,165,91,7,0,0,0,0,0,0,0,0,116,121,230,230,139,143,150,150,147,149,149,152,153,154, - 158,159,163,166,169,172,177,180,185,188,192,197,201,206,209,214,216,218,218,186,186,244,219,111,38,0,0,0,0,0,0,0, - 0,0,0,115,136,249,220,132,141,147,147,147,149,149,153,154,158,160,163,168,171,173,178,183,186,191,195,200,205,209,214,217, - 220,221,191,175,241,248,120,58,0,0,0,0,0,0,0,0,0,0,0,0,113,148,254,221,137,137,147,147,147,150,152,154, - 158,160,164,168,172,176,180,185,188,194,198,203,207,214,215,219,220,184,177,241,254,133,69,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,111,146,248,230,156,132,144,148,151,152,154,158,160,164,168,172,177,181,186,190,195,201,206,210,214,218,210, - 170,195,244,248,137,69,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,133,227,240,188,128,138,150,154,156, - 157,161,165,169,172,177,183,187,192,199,204,206,211,209,181,159,222,248,228,127,69,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,104,119,187,252,236,201,155,137,153,158,162,166,170,174,179,184,188,194,198,201,199,171,155,201,241, - 253,187,115,61,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,95,112,133,214,249,237,219,186, - 143,136,146,160,171,179,180,175,164,154,146,183,225,244,249,210,137,98,44,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,52,97,113,130,181,246,243,242,229,213,199,189,188,193,200,213,228,243,246,242,188,138,107, - 66,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56,91,104,115,132, - 179,212,230,245,254,254,254,247,231,213,190,150,120,96,66,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,65,85,94,102,117,117,116,116,116,117,118,99,86,70,41,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,115,115,119,146, - 181,213,235,249,254,254,254,249,235,213,181,146,119,115,115,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,115,115,118,144,203,250,250,229,199,160,122,87,69,84,117,155,194,227,249,249,202,144,118, - 115,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,118,145,222,253,231,174,96, - 100,113,121,121,117,109,102,91,81,72,66,77,163,228,253,222,145,118,115,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,115,123,203,254,229,149,103,130,149,129,108,92,81,76,72,72,71,71,71,69,68,65,58,129,224, - 254,202,123,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,142,235,245,176,103,141,150,114,89, - 78,77,76,76,77,76,74,73,71,69,69,65,64,62,58,53,157,243,234,142,115,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,115,158,250,231,128,129,161,115,84,79,78,78,76,77,77,76,76,75,73,73,72,70,67,66,63,61,57, - 53,99,222,250,159,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,159,254,218,107,145,135,91,78,78,78,78, - 77,76,75,75,73,73,72,73,71,69,69,68,66,65,61,59,58,50,81,210,254,157,115,0,0,0,0,0,0,0,0,0, - 0,0,0,115,142,250,218,99,150,117,79,77,78,77,77,76,75,75,73,72,72,70,70,69,67,67,67,65,66,64,62,60, - 58,56,49,89,209,249,138,115,0,0,0,0,0,0,0,0,0,0,115,123,234,222,104,149,109,77,77,79,68,58,68,76, - 73,70,71,70,70,67,67,67,65,64,66,61,47,48,59,60,57,56,52,48,98,223,232,121,115,0,0,0,0,0,0,0, - 0,115,118,202,242,126,140,115,76,77,77,62,98,165,101,58,72,70,68,68,67,65,64,63,63,63,57,54,127,127,50,51, - 56,54,51,49,47,125,242,193,117,115,0,0,0,0,0,0,0,115,145,254,173,123,127,76,74,76,56,100,230,255,231,96, - 50,68,66,65,65,62,61,62,62,53,48,147,229,236,157,42,47,51,51,49,46,46,173,253,134,114,0,0,0,0,0,0, - 115,118,220,228,96,148,87,74,76,60,100,233,255,255,255,234,97,47,66,64,63,61,61,59,53,46,149,227,217,213,230,154, - 40,47,48,46,43,42,45,224,206,116,107,0,0,0,0,0,115,144,253,148,126,104,73,73,65,88,231,255,255,255,255,255, - 234,95,46,60,61,59,58,51,47,154,227,215,206,204,204,223,140,37,43,42,42,41,43,169,249,130,109,0,0,0,0,0, - 115,203,230,91,127,76,72,71,54,113,255,255,255,255,255,255,255,238,99,37,58,57,49,45,153,228,215,207,204,201,194,241, - 184,35,40,42,40,38,39,103,226,171,110,0,0,0,0,115,119,250,170,110,97,69,68,67,65,56,157,255,255,255,255,254, - 248,255,238,98,37,48,43,157,228,215,206,204,201,194,237,203,44,27,37,34,34,31,29,58,194,223,115,88,0,0,0,115, - 146,249,88,118,76,67,65,65,66,59,44,156,255,255,252,248,244,238,247,233,92,33,154,228,214,205,201,198,192,236,201,33, - 11,10,11,11,11,11,12,15,129,242,128,101,0,0,0,115,179,228,83,101,65,65,65,62,63,62,56,45,157,255,254,243, - 239,236,229,239,215,164,215,210,201,196,193,187,233,199,33,11,9,11,11,11,11,11,12,13,79,233,153,105,0,0,0,115, - 210,197,90,85,64,62,62,60,60,58,60,52,38,154,253,241,235,229,226,217,221,222,203,198,194,190,186,233,200,30,11,9, - 11,11,11,11,11,11,11,13,49,210,179,106,0,0,0,115,233,156,91,73,62,60,60,59,58,56,57,56,49,40,158,247, - 236,222,216,211,205,201,199,194,192,187,232,202,35,11,9,10,11,11,11,11,11,11,11,13,32,197,205,108,0,0,0,115, - 249,114,90,66,60,58,58,58,57,53,54,52,57,48,23,131,229,218,211,205,202,199,194,190,186,231,201,36,11,9,10,10, - 10,10,11,11,11,11,11,12,17,184,219,111,0,0,0,115,254,78,85,61,58,58,57,55,53,52,53,56,40,17,9,10, - 108,218,207,201,198,194,190,187,231,199,30,11,9,10,10,10,10,10,10,10,10,10,11,12,15,171,229,118,0,0,0,115, - 254,59,80,59,56,55,53,53,52,53,51,27,9,9,10,10,114,212,202,197,194,190,188,184,198,195,43,10,10,10,10,10, - 10,10,10,10,10,10,10,12,14,169,231,114,0,0,0,115,254,79,75,56,54,53,52,51,53,46,14,9,9,10,10,125, - 216,203,196,193,190,187,184,181,178,200,200,53,11,10,10,10,10,10,10,10,10,10,10,12,15,173,230,114,0,0,0,115, - 247,113,69,56,53,52,51,54,37,9,9,9,10,10,127,218,204,194,193,190,186,185,181,180,180,175,202,201,48,10,10,9, - 9,9,9,9,9,9,10,12,17,189,227,113,0,0,0,115,230,152,64,54,52,51,54,35,9,10,10,10,10,124,218,202, - 194,192,189,185,227,195,183,179,178,180,179,207,202,50,10,9,9,9,9,9,9,9,10,12,26,201,212,125,0,0,0,115, - 207,191,57,53,50,52,37,9,10,10,10,10,119,219,203,195,192,189,184,229,192,111,182,183,180,183,187,188,219,207,49,9, - 9,9,8,8,8,8,9,12,54,213,180,112,0,0,0,115,178,223,52,53,48,39,9,10,10,10,10,113,217,202,194,190, - 188,184,228,200,34,11,89,191,186,187,192,198,202,234,213,40,9,8,8,8,8,8,10,13,87,232,152,84,0,0,0,115, - 147,249,68,48,38,9,10,10,10,10,108,213,201,194,192,188,185,228,201,35,11,9,10,94,196,198,198,205,213,219,244,214, - 42,8,7,7,7,8,10,28,133,230,118,60,0,0,0,115,119,247,160,32,18,9,10,10,11,56,213,206,193,190,188,183, - 229,200,36,11,9,10,10,10,94,210,213,213,222,230,236,255,173,8,7,7,7,11,12,63,188,196,107,23,0,0,0,0, - 115,196,224,10,9,9,10,11,11,26,165,207,190,188,183,229,196,31,11,9,10,10,10,9,10,96,219,229,230,237,254,255, - 101,8,8,9,10,13,16,108,223,143,86,0,0,0,0,0,115,140,253,100,8,10,10,11,11,11,30,168,200,186,228,197, - 31,11,10,11,10,10,9,9,9,9,102,236,247,255,255,118,9,7,12,10,12,15,22,173,240,116,57,0,0,0,0,0, - 115,117,215,222,8,10,10,11,11,11,12,32,160,219,193,29,12,10,11,10,10,10,9,9,9,8,9,102,251,255,116,9, - 5,13,11,12,15,18,44,217,165,97,13,0,0,0,0,0,0,115,138,254,128,9,10,11,12,12,12,12,26,105,25,12, - 10,11,11,10,10,10,9,9,8,8,8,8,81,76,8,5,12,12,14,15,17,25,149,242,116,55,0,0,0,0,0,0, - 0,115,117,198,240,60,10,11,12,12,12,12,12,13,11,10,11,11,11,10,10,9,9,9,8,8,7,7,7,7,9,13, - 12,13,15,16,21,83,232,151,90,7,0,0,0,0,0,0,0,0,115,120,230,215,24,11,11,12,12,12,12,12,12,11, - 11,11,11,10,10,9,9,8,8,8,7,8,11,11,12,13,14,15,16,21,45,205,206,110,38,0,0,0,0,0,0,0, - 0,0,0,114,136,249,195,12,11,12,12,12,12,12,12,11,11,11,11,10,10,9,9,8,8,7,8,11,11,11,13,14, - 15,17,21,33,185,244,117,58,0,0,0,0,0,0,0,0,0,0,0,0,112,147,254,192,24,12,13,13,12,12,12,11, - 11,11,10,10,9,9,8,8,8,7,10,12,13,13,14,15,18,23,41,182,253,125,68,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,110,146,248,207,59,14,13,12,12,12,12,11,11,10,10,9,9,8,8,7,8,11,14,13,15,16,19, - 25,69,197,243,124,69,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,107,132,227,229,120,14,14,13,13,13, - 12,12,11,11,10,10,9,9,8,12,12,15,16,18,23,27,122,221,213,118,69,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,103,118,187,251,218,147,65,17,15,13,13,12,12,11,11,11,11,11,15,15,19,22,24,92,189, - 248,166,112,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,94,111,132,213,245,221,181,122, - 41,15,15,16,15,15,15,16,17,19,21,85,160,210,239,191,120,96,43,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,52,96,112,130,179,243,231,225,201,168,144,127,124,131,143,160,187,211,224,237,164,120,105, - 65,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56,90,103,114,130, - 173,211,230,245,254,254,254,247,230,212,188,127,111,94,65,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,84,93,101,116,116,115,115,115,116,117,98,86,69,41,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,115,115,119,146, - 181,213,235,249,254,254,254,249,235,213,181,146,119,115,115,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,115,115,118,144,203,250,250,229,199,160,122,87,69,84,117,155,194,227,249,249,202,144,118, - 115,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,118,145,222,253,231,174,96, - 100,113,121,121,117,109,102,91,81,72,66,77,163,228,253,222,145,118,115,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,115,123,203,254,229,149,103,130,149,129,107,92,82,76,72,71,71,71,71,69,68,65,58,129,224, - 254,202,123,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,142,235,245,176,103,141,150,114,89, - 78,77,76,76,77,76,75,73,71,69,67,65,64,62,58,53,157,243,234,142,115,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,115,158,250,231,128,129,161,114,84,79,78,78,78,76,77,77,74,75,73,73,72,70,69,66,63,61,57, - 53,98,222,250,159,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,159,254,218,107,145,135,91,78,78,77,76, - 77,76,75,75,73,72,71,73,71,69,69,68,66,64,61,59,58,50,81,210,254,157,115,0,0,0,0,0,0,0,0,0, - 0,0,0,115,142,250,218,99,150,117,79,77,78,79,78,76,75,75,73,72,72,70,70,69,67,67,67,65,66,64,62,60, - 58,55,48,89,209,249,138,115,0,0,0,0,0,0,0,0,0,0,115,123,234,222,104,149,109,77,77,79,69,58,68,76, - 73,72,72,70,70,67,67,67,64,64,66,61,49,48,59,60,56,56,53,47,97,223,232,121,115,0,0,0,0,0,0,0, - 0,115,118,202,242,126,140,115,76,77,77,62,98,167,101,58,71,70,68,68,66,65,64,65,63,63,57,54,127,127,50,50, - 56,54,51,49,47,124,242,193,117,115,0,0,0,0,0,0,0,115,145,254,173,123,127,76,76,74,56,100,230,255,231,96, - 50,68,66,67,64,62,61,62,62,55,48,147,229,236,158,42,47,51,51,49,45,45,172,253,134,114,0,0,0,0,0,0, - 115,118,220,228,96,148,87,74,76,60,100,233,255,255,255,234,99,47,66,62,63,61,60,59,53,48,149,227,217,213,230,154, - 40,47,48,46,43,43,45,224,206,116,107,0,0,0,0,0,115,144,253,148,125,105,74,73,65,88,229,255,255,255,255,255, - 234,95,46,60,61,59,58,51,47,154,227,215,206,204,204,223,140,37,43,42,42,41,44,169,250,130,109,0,0,0,0,0, - 115,203,230,91,127,76,72,71,56,113,255,255,255,255,255,255,255,238,101,37,58,57,49,45,153,228,215,207,204,201,194,241, - 184,35,40,43,41,38,39,104,225,171,110,0,0,0,0,115,119,250,170,110,97,69,66,67,65,56,157,255,255,255,255,254, - 248,255,238,100,37,48,43,157,228,215,206,204,201,194,236,204,44,27,38,34,35,31,30,58,195,224,115,88,0,0,0,115, - 146,249,88,118,76,67,65,65,66,59,44,156,255,255,252,248,244,238,247,234,92,33,154,228,214,205,201,198,192,236,201,33, - 11,10,11,11,11,11,12,15,130,242,128,101,0,0,0,115,179,228,83,101,66,65,65,62,63,62,56,45,157,255,254,243, - 239,236,229,239,215,164,215,210,201,196,193,187,233,199,33,11,9,11,11,11,11,11,11,13,81,232,153,105,0,0,0,115, - 210,197,90,85,65,63,61,61,60,58,60,53,38,154,253,241,235,229,226,217,221,222,203,198,194,190,186,233,200,30,11,9, - 11,11,11,11,11,11,11,12,50,209,178,106,0,0,0,115,233,156,91,73,62,61,60,58,58,56,57,56,49,40,159,247, - 236,222,216,211,205,201,199,194,192,187,232,202,35,11,9,10,11,11,11,11,11,11,11,12,33,198,205,108,0,0,0,115, - 249,114,90,66,59,58,58,56,57,53,54,52,57,48,24,131,229,218,211,205,202,199,194,190,186,231,201,36,11,9,10,10, - 10,10,11,11,11,11,11,13,19,185,222,111,0,0,0,115,254,78,85,61,58,58,55,53,53,52,53,56,40,17,9,10, - 109,218,207,201,198,194,190,187,231,199,30,11,9,10,10,10,10,10,10,10,10,10,11,13,16,171,230,118,0,0,0,115, - 254,59,80,59,56,55,53,53,50,53,51,27,9,9,10,10,114,212,202,197,194,190,188,184,198,195,43,10,10,10,10,10, - 10,10,10,10,10,10,10,12,14,169,230,114,0,0,0,115,254,79,75,56,54,53,52,52,53,46,14,9,9,10,10,125, - 216,203,196,193,190,187,184,181,178,200,200,53,11,10,10,10,10,10,10,10,10,10,10,12,15,175,230,114,0,0,0,115, - 247,113,68,56,53,52,51,54,37,9,9,9,10,10,127,218,204,194,193,190,186,185,181,180,180,175,202,201,48,10,10,9, - 9,9,9,9,9,9,10,12,17,188,228,113,0,0,0,115,230,152,63,54,52,51,54,36,9,10,10,10,10,124,218,202, - 194,192,189,185,227,195,183,179,178,180,179,207,202,50,10,9,9,9,9,9,9,9,10,12,26,199,212,125,0,0,0,115, - 207,191,57,53,50,52,36,9,10,10,10,10,119,219,203,195,192,189,184,229,192,111,182,183,180,183,187,188,219,207,49,9, - 9,9,8,8,8,8,9,12,53,212,180,112,0,0,0,115,178,223,52,53,48,39,9,10,10,10,10,113,217,202,194,190, - 188,184,228,200,34,11,89,191,186,187,192,198,202,234,211,40,9,8,8,8,8,9,10,13,86,232,152,84,0,0,0,115, - 147,249,68,48,37,9,10,10,10,10,108,213,201,194,192,188,185,228,201,35,11,9,10,95,196,198,198,205,213,219,244,214, - 42,8,7,7,7,8,10,28,133,230,118,60,0,0,0,115,119,247,160,32,17,9,10,10,11,56,213,206,193,190,188,183, - 229,200,36,11,9,10,10,10,94,211,213,213,222,230,236,255,175,8,7,7,7,10,12,61,188,194,107,23,0,0,0,0, - 115,196,224,9,9,9,10,11,11,26,165,207,190,188,183,229,196,31,11,9,10,10,10,9,10,96,219,229,230,237,254,255, - 101,8,6,8,10,13,16,109,223,143,86,0,0,0,0,0,115,140,253,99,9,10,10,11,11,11,30,166,200,186,228,197, - 31,11,10,11,10,10,9,9,9,9,102,236,247,255,255,118,9,7,10,11,12,15,22,173,240,116,57,0,0,0,0,0, - 115,117,215,222,8,10,10,11,11,11,12,32,160,219,193,30,12,10,11,10,10,10,9,9,9,8,9,102,251,255,116,9, - 5,13,11,13,14,18,44,217,165,97,13,0,0,0,0,0,0,115,138,254,128,9,10,11,12,12,12,12,26,105,25,12, - 10,11,11,10,10,10,9,9,8,8,8,8,81,76,8,5,12,12,14,15,17,25,149,242,116,55,0,0,0,0,0,0, - 0,115,117,198,240,60,10,11,12,12,12,12,12,13,11,10,11,11,11,10,10,9,9,9,8,8,7,7,7,7,9,13, - 13,13,15,16,21,83,232,151,90,7,0,0,0,0,0,0,0,0,115,120,230,215,23,10,11,12,12,12,12,12,12,11, - 11,11,11,10,10,9,9,8,8,8,7,8,11,11,12,13,14,16,16,21,44,205,206,110,38,0,0,0,0,0,0,0, - 0,0,0,114,136,249,195,12,11,12,12,12,12,12,12,11,11,11,11,10,10,9,9,8,8,7,8,11,10,11,13,15, - 15,17,21,33,185,244,117,58,0,0,0,0,0,0,0,0,0,0,0,0,112,147,254,192,24,12,13,13,12,12,12,11, - 11,11,10,10,9,9,8,8,8,7,10,12,13,13,14,15,18,23,41,182,253,125,68,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,110,146,248,207,59,14,13,12,12,12,12,11,11,10,10,9,9,8,8,7,10,12,12,13,15,16,19, - 25,69,197,243,124,69,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,107,132,227,229,120,13,14,13,13,13, - 12,12,11,11,10,10,9,9,8,12,12,15,16,18,23,27,122,221,213,118,69,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,103,118,187,251,218,147,65,18,15,13,13,12,12,11,11,11,11,11,15,15,19,22,24,91,189, - 248,166,112,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,94,111,132,213,246,221,182,121, - 41,15,15,16,15,15,15,16,18,19,21,86,160,210,239,191,120,96,43,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,52,96,112,130,179,243,231,225,201,167,144,128,124,130,142,161,188,211,224,237,164,119,105, - 65,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56,90,103,114,130, - 173,211,230,245,254,254,254,247,231,212,188,127,111,94,65,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,84,93,101,116,116,115,115,115,116,117,98,86,69,41,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,42,93,139,181,216,242,254,254,254,242,216,181,139,93,42,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,21,90,169,220,209, - 218,235,248,253,255,255,255,253,248,235,218,209,220,169,90,21,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,12,93,203,207,225,252,255,255,255,255,255,255,255,255,255,255,255,255,255,252,225,207,203, - 93,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,55,176,206,234,253,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,252,233,206,176,55,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,91,212,222,253,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 253,221,212,92,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,114,204,242,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,241,203,115,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,115,204,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,252,204,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,204,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,204,114,0,0,0,0,0,0,0,0,0, - 0,0,0,92,203,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,252,207,83,0,0,0,0,0,0,0,0,0,0,56,211,241,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,242,216,49,0,0,0,0,0,0,0, - 0,12,176,221,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,221,166,8,0,0,0,0,0,0,0,93,206,253,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,212,77,0,0,0,0,0,0, - 20,200,234,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,232,189,14,0,0,0,0,0,91,206,252,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,253,217,73,0,0,0,0,0, - 170,224,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,254,225,141,2,0,0,0,42,220,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,247,222,26,0,0,0,93, - 209,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,254,223,73,1,0,0,136,218,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,225,124,4,0,0,178, - 233,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,254,236,165,8,0,0,215,247,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,250,191,13,1,0,242, - 253,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,252,212,19,3,0,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,229,24,6,0,254, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,227,28,8,0,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,228,32,9,0,238, - 253,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,224,33,10,0,210,246,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,221,34,10,0,175, - 233,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,246,190,33,10,0,135,218,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,241,145,32,9,0,94, - 209,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,253,234,103,28,7,0,38,223,251,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,249,222,65,23,5,0,0, - 162,224,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,236,164,46,18,3,0,0,84,209,253,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,233,111,36,12,1,0,0, - 17,197,233,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,243,195,64,27,7,0,0,0,0,81,210,253,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,234,119,46,18,4,0,0,0, - 0,9,173,223,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,239,184,67,32,10,1,0,0,0,0,0,47,218,242,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,249,232,103,48,20,5,0,0,0,0, - 0,0,0,83,208,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,254,232,135,61,31,10,1,0,0,0,0,0,0,0,0,105,209,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,232,155,72,41,17,4,0,0,0,0,0, - 0,0,0,0,1,107,211,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,254,234,158,79,49,24,8,1,0,0,0,0,0,0,0,0,0,0,2,108,213,244,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,252,234,158,81,54,28,10,2,0,0,0,0,0,0, - 0,0,0,0,0,0,3,88,220,228,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,244,235,145,80,54,30,12,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,60,180,217,248,253,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,249,237,205,122,74,51,29,12,3,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,3,20,103,209,220,235,254,255,255,255,255,255,255,255,255,255,255,255,255,255,253,246,238,223, - 150,90,65,44,25,11,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,8,35,107,183,231,225, - 247,255,255,255,255,255,255,255,255,255,255,244,241,203,149,96,70,52,34,19,8,2,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,1,5,13,24,70,124,166,200,233,247,255,255,255,249,237,208,181,151,113,78,66,52, - 37,24,12,5,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,7,13,22, - 32,43,52,60,67,72,76,77,76,72,67,60,52,43,32,22,13,7,2,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,5,10,16,22,27,31,34,37,38,37,35,31,27,22,16,10,5, - 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 1,2,4,7,9,10,12,12,12,10,9,7,4,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} -},{ - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,116,116,120,147, - 182,213,235,249,254,254,254,249,235,213,182,147,120,116,116,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,116,116,119,144,203,250,251,237,213,185,155,135,126,131,151,182,211,236,251,249,202,144,119, - 116,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,119,145,222,254,238,199,161, - 135,112,94,86,82,80,80,80,80,85,100,134,191,236,253,222,145,119,116,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,116,124,204,254,238,186,153,142,116,84,72,71,71,69,68,69,69,67,68,69,67,77,90,161,233, - 254,203,124,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,143,235,249,203,161,149,113,85,69, - 68,70,70,69,68,67,66,65,63,62,64,65,65,68,67,92,183,246,234,143,116,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,116,159,250,239,176,157,122,84,67,68,70,70,69,68,67,66,66,63,62,61,61,60,60,59,61,62,63, - 67,128,231,250,159,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,160,254,232,170,147,109,64,68,70,70,69, - 68,67,65,62,60,59,59,59,59,60,59,58,57,56,55,57,62,60,89,216,254,158,116,0,0,0,0,0,0,0,0,0, - 0,0,0,116,143,250,231,155,148,92,66,70,70,69,68,66,57,57,62,66,75,76,72,61,57,48,50,56,56,53,52,53, - 54,58,60,75,216,249,138,116,0,0,0,0,0,0,0,0,0,0,116,124,234,233,165,147,84,66,70,70,69,68,63,63, - 123,183,216,231,244,245,240,223,206,173,92,47,50,52,52,52,50,51,56,58,89,229,232,122,116,0,0,0,0,0,0,0, - 0,116,119,203,246,167,144,85,67,70,69,69,68,60,99,223,255,255,255,255,255,255,255,255,255,255,246,180,56,46,51,49, - 47,47,48,54,54,111,244,193,118,116,0,0,0,0,0,0,0,116,145,254,198,149,109,63,70,69,68,67,67,51,139,255, - 255,255,255,255,255,255,255,254,252,247,246,255,167,46,47,47,46,45,44,46,53,58,167,253,135,115,0,0,0,0,0,0, - 116,119,220,237,148,122,63,69,68,68,67,65,65,50,136,255,255,255,255,255,255,255,255,254,253,251,249,243,255,142,35,46, - 45,45,43,44,47,56,65,228,206,117,108,0,0,0,0,0,116,144,254,178,142,85,66,68,67,67,65,63,63,49,133,255, - 254,255,255,251,249,252,255,255,252,251,250,246,252,206,41,45,46,43,43,43,44,50,56,143,251,131,110,0,0,0,0,0, - 116,203,237,123,115,61,66,66,65,63,62,62,61,47,131,255,251,179,107,86,76,80,140,253,253,250,250,249,249,238,59,40, - 45,45,43,43,43,46,55,72,228,172,111,0,0,0,0,116,120,250,192,140,91,61,63,63,62,61,61,61,59,49,112,204, - 109,35,38,46,48,45,35,145,252,247,249,247,249,250,82,36,47,47,46,45,43,45,50,53,180,226,116,89,0,0,0,116, - 147,251,140,123,62,63,62,61,61,61,60,59,58,58,55,47,43,52,52,51,51,51,43,56,226,246,245,246,247,251,81,32, - 41,40,39,39,40,41,45,52,105,244,129,102,0,0,0,116,179,236,114,83,61,61,61,61,60,60,59,57,57,56,55,52, - 53,52,51,51,51,49,42,60,218,230,231,234,241,230,40,21,27,27,27,27,27,28,31,41,63,226,154,106,0,0,0,116, - 210,210,90,68,61,61,60,60,59,57,57,56,55,55,52,52,52,51,51,49,41,33,18,110,206,208,218,225,242,196,21,26, - 28,28,28,29,29,29,31,38,50,193,179,107,0,0,0,116,233,174,81,65,61,60,59,58,57,56,56,55,53,52,51,51, - 50,46,38,29,24,12,55,182,193,200,211,221,253,136,16,28,29,29,30,30,30,31,32,38,48,194,206,109,0,0,0,116, - 249,139,83,60,59,58,57,57,56,55,53,52,52,51,51,47,35,25,21,22,14,40,164,184,183,193,204,230,191,22,27,30, - 30,30,30,31,31,32,33,39,48,174,221,112,0,0,0,116,254,113,80,57,57,56,55,53,52,52,52,51,52,48,35,26, - 21,21,22,14,65,159,183,175,180,188,206,225,62,19,32,32,33,33,33,33,33,33,34,40,49,138,231,118,0,0,0,116, - 254,101,76,56,55,55,53,52,52,51,51,50,40,28,22,22,21,21,17,45,165,185,174,175,178,196,219,101,18,37,37,37, - 37,37,38,38,38,37,37,41,49,131,231,115,0,0,0,116,254,113,72,54,53,52,51,51,51,50,46,31,24,22,22,21, - 21,19,35,164,188,179,178,178,195,189,79,24,40,41,41,42,43,43,43,43,43,42,42,46,53,148,231,115,0,0,0,116, - 247,138,71,54,52,50,50,49,50,43,26,21,22,21,20,20,21,10,86,201,188,185,184,195,178,50,27,43,45,46,47,47, - 48,48,48,48,48,47,48,51,57,178,228,114,0,0,0,116,230,172,70,54,51,49,49,49,39,25,21,21,21,20,19,20, - 20,15,139,209,196,195,200,193,56,31,47,47,49,50,51,51,52,52,52,52,52,51,50,55,62,190,214,126,0,0,0,116, - 207,206,71,55,48,47,47,40,24,21,22,20,19,19,20,20,18,28,178,210,202,203,213,110,29,49,49,51,53,55,55,56, - 56,57,56,56,56,55,55,60,70,203,181,113,0,0,0,116,179,232,84,55,47,46,38,22,21,20,20,19,18,18,20,19, - 19,38,193,208,204,209,203,51,45,52,53,56,58,58,59,59,60,60,59,59,59,58,60,64,88,239,153,85,0,0,0,116, - 148,250,107,53,47,39,22,20,20,19,19,17,17,19,19,20,22,37,174,198,195,203,190,49,50,56,57,59,60,61,61,62, - 62,62,62,61,61,60,63,66,126,238,119,61,0,0,0,116,120,247,179,56,45,27,19,20,19,18,17,16,17,18,19,24, - 28,31,52,62,65,69,67,50,57,59,60,61,61,63,63,63,63,63,62,62,61,62,66,70,187,207,108,23,0,0,0,0, - 116,196,231,57,42,22,19,18,17,17,16,16,17,18,21,26,31,36,33,31,35,38,43,57,60,61,61,62,63,63,63,63, - 63,63,62,62,62,65,69,91,229,150,86,0,0,0,0,0,116,140,253,132,36,23,20,17,17,16,15,16,17,19,25,29, - 35,35,60,104,123,126,103,57,59,63,63,63,63,63,63,63,63,62,62,62,63,68,72,162,242,117,57,0,0,0,0,0, - 116,118,215,229,53,28,20,17,16,15,15,16,17,20,27,31,32,58,170,190,189,190,206,162,60,62,63,63,63,63,62,62, - 62,61,61,62,66,71,89,227,174,98,13,0,0,0,0,0,0,116,139,254,153,34,26,19,16,14,15,16,18,22,28,33, - 31,122,193,181,181,182,188,215,107,55,63,63,62,61,61,61,60,59,60,64,70,76,177,244,117,55,0,0,0,0,0,0, - 0,116,118,198,242,93,30,23,15,13,15,16,19,25,30,36,37,157,195,185,184,185,191,208,121,49,62,62,60,59,59,58, - 58,58,61,68,72,128,240,162,91,7,0,0,0,0,0,0,0,0,116,121,230,222,64,30,20,15,15,16,21,27,33,39, - 37,143,208,194,193,194,199,221,110,50,61,60,58,57,56,55,54,59,65,71,98,222,215,111,38,0,0,0,0,0,0,0, - 0,0,0,115,136,249,207,49,30,22,18,18,22,29,36,41,40,87,212,218,209,212,225,204,63,59,59,57,56,55,53,53, - 57,64,69,84,211,247,120,58,0,0,0,0,0,0,0,0,0,0,0,0,113,148,254,205,64,33,27,25,27,32,37,43, - 48,50,94,160,195,191,138,66,55,60,57,55,52,52,53,57,64,69,91,208,253,132,69,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,111,146,248,217,93,39,35,34,36,41,46,50,55,51,49,61,57,45,57,61,58,55,54,53,54,59,65, - 70,117,218,246,136,69,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,133,227,234,145,48,43,45,47,51, - 53,57,60,61,60,61,63,62,60,58,56,57,59,64,67,72,162,234,223,126,69,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,104,119,187,251,222,124,56,53,57,59,61,63,64,65,64,65,65,63,64,65,67,66,71,132,212, - 251,183,115,61,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,95,112,133,214,248,211,147,72, - 62,64,66,70,73,74,73,71,68,68,69,84,155,213,248,205,136,98,44,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,52,97,113,130,181,245,237,231,229,191,161,137,129,138,159,186,216,224,237,245,184,136,107, - 66,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56,91,104,115,132, - 178,211,230,245,254,254,254,247,230,212,190,147,120,96,66,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,65,85,94,102,117,117,116,116,116,117,118,99,86,70,41,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,115,115,119,146, - 181,213,235,249,254,254,254,249,235,213,181,146,119,115,115,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,115,115,118,144,203,250,251,237,214,188,163,144,136,140,159,186,211,236,251,249,202,144,118, - 115,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,118,145,222,254,238,200,167, - 152,140,128,123,119,117,117,115,114,114,122,143,193,236,253,222,145,118,115,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,115,123,203,254,238,188,167,166,149,124,113,111,110,109,110,109,108,108,105,105,101,106,110,165,233, - 254,202,123,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,142,235,249,203,172,172,146,125,111, - 110,111,110,110,110,109,107,106,103,103,103,103,102,101,96,110,184,246,234,142,115,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,115,158,250,239,181,178,153,123,109,110,111,110,110,110,109,108,107,106,103,102,101,101,99,99,99,98,95, - 93,136,231,250,159,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,159,254,232,177,172,144,109,111,112,111,110, - 110,109,107,104,101,101,101,100,99,99,99,98,97,96,94,95,95,89,104,217,254,157,115,0,0,0,0,0,0,0,0,0, - 0,0,0,115,142,250,231,170,174,130,108,112,112,110,110,108,100,99,104,107,113,113,111,101,98,90,91,94,96,93,92,91, - 90,91,89,93,216,249,138,115,0,0,0,0,0,0,0,0,0,0,115,123,234,233,174,173,124,108,112,111,110,110,106,104, - 153,201,225,238,247,249,243,230,216,190,124,87,90,92,90,89,88,88,90,87,101,230,232,121,115,0,0,0,0,0,0,0, - 0,115,118,202,246,174,169,125,108,111,111,110,109,102,133,231,255,255,255,255,255,255,255,255,255,255,247,194,93,86,89,87, - 86,84,84,85,82,120,244,193,117,115,0,0,0,0,0,0,0,115,145,254,199,171,142,106,111,110,109,108,108,96,165,255, - 255,255,255,255,255,255,255,254,252,247,245,255,182,83,84,84,84,83,81,83,85,82,169,253,134,114,0,0,0,0,0,0, - 115,118,220,237,162,152,105,110,110,109,108,107,106,92,161,255,255,255,255,255,255,255,255,254,253,251,249,243,255,162,75,83, - 83,82,80,80,81,84,84,228,206,116,107,0,0,0,0,0,115,144,254,180,166,122,108,110,108,108,107,104,104,91,158,255, - 253,255,255,251,249,251,255,255,252,251,250,247,251,212,78,82,82,81,80,80,80,83,82,146,251,130,109,0,0,0,0,0, - 115,203,237,145,146,103,108,107,106,104,103,103,102,89,157,255,250,185,127,112,106,109,158,252,252,250,250,249,247,238,88,79, - 81,81,80,79,79,81,83,88,229,171,110,0,0,0,0,115,119,250,194,164,125,103,106,104,102,102,102,101,100,91,140,209, - 128,69,78,88,88,84,75,163,251,247,249,247,247,250,107,75,82,82,81,81,81,80,81,76,182,226,115,88,0,0,0,115, - 146,251,148,152,103,104,103,102,102,101,100,99,98,97,94,82,82,93,93,91,90,89,83,91,229,245,245,246,246,249,104,70, - 78,77,76,76,76,76,77,77,113,244,128,101,0,0,0,115,179,236,133,120,101,103,102,101,101,100,98,98,97,94,93,92, - 92,92,90,89,88,87,80,94,220,230,231,234,240,231,69,61,65,65,63,65,65,65,66,70,79,226,153,105,0,0,0,115, - 210,211,120,107,102,101,101,99,99,98,97,94,93,92,92,91,91,90,89,86,79,73,60,130,205,208,216,225,241,202,56,65, - 65,66,66,66,66,66,66,69,71,194,179,106,0,0,0,115,233,178,115,105,101,100,99,98,96,96,94,93,92,91,91,90, - 89,84,78,69,65,57,88,183,192,200,211,220,251,150,52,66,67,67,67,67,67,67,67,70,70,197,206,108,0,0,0,115, - 249,147,117,100,98,98,96,96,94,93,92,91,90,90,89,86,75,66,63,63,56,78,169,182,183,192,203,228,196,53,65,67, - 67,67,67,67,67,67,68,70,71,179,221,111,0,0,0,115,254,122,115,97,96,94,94,93,93,92,91,90,89,86,75,68, - 63,63,63,57,94,164,181,175,180,188,205,224,86,57,69,69,69,68,69,68,68,68,69,71,73,145,231,118,0,0,0,115, - 254,111,112,94,96,94,93,92,91,90,90,88,80,70,63,63,63,63,58,80,169,182,174,175,178,195,219,119,55,72,71,72, - 72,72,72,72,72,72,71,72,74,139,231,114,0,0,0,115,254,121,107,93,93,92,91,90,89,89,84,72,65,63,63,62, - 62,59,72,169,185,179,178,178,193,191,99,58,76,76,76,77,77,77,77,77,77,76,76,77,75,154,231,114,0,0,0,115, - 247,144,104,92,90,89,88,87,88,82,67,63,63,63,61,61,61,52,110,199,188,185,184,194,180,73,62,78,78,79,80,80, - 81,81,81,81,80,80,79,81,79,183,228,113,0,0,0,115,230,175,99,91,89,88,87,88,79,67,63,63,62,61,60,60, - 60,56,152,206,196,195,200,194,80,66,80,80,81,82,83,83,83,83,83,83,83,82,82,83,81,193,214,125,0,0,0,115, - 207,207,95,91,88,86,86,79,66,62,62,61,60,60,60,60,58,65,183,209,202,203,212,122,62,82,82,83,84,86,87,87, - 87,87,87,87,87,86,85,85,85,204,181,112,0,0,0,115,178,232,99,89,84,84,78,63,62,62,61,59,59,59,59,59, - 58,73,194,206,204,209,203,76,78,84,86,87,88,89,89,90,90,90,90,89,89,88,89,88,100,239,152,84,0,0,0,115, - 147,250,113,86,82,78,63,61,61,60,59,58,58,58,58,59,61,71,179,196,195,202,191,73,83,87,88,89,90,91,90,91, - 91,91,91,91,90,89,90,86,133,238,118,60,0,0,0,115,119,247,181,82,80,66,61,61,59,58,58,57,57,57,59,61, - 65,68,82,88,89,92,91,80,88,89,90,91,91,92,92,92,92,91,91,91,90,91,91,87,189,205,107,23,0,0,0,0, - 115,196,231,72,74,62,60,59,58,57,56,57,56,57,60,65,68,70,70,68,71,73,78,88,90,91,91,92,92,92,92,92, - 92,91,91,91,90,92,90,101,229,146,86,0,0,0,0,0,115,140,253,134,63,61,60,57,57,56,55,56,56,57,62,67, - 70,70,90,124,139,142,126,88,89,91,92,92,92,92,91,91,91,91,90,90,91,92,88,165,242,116,57,0,0,0,0,0, - 115,117,215,229,67,60,59,56,55,55,55,55,56,59,63,68,68,88,174,188,188,189,204,173,89,92,92,91,91,91,90,90, - 90,90,89,90,92,90,100,228,168,97,13,0,0,0,0,0,0,115,138,254,155,58,60,57,53,53,53,53,56,60,65,69, - 68,138,192,181,181,182,187,213,127,84,91,91,90,90,89,88,88,87,88,89,92,90,180,244,116,55,0,0,0,0,0,0, - 0,115,117,198,242,100,57,57,53,52,53,53,57,61,66,70,72,165,194,185,185,185,191,205,137,79,91,89,89,87,87,86, - 86,84,86,90,87,133,240,154,90,7,0,0,0,0,0,0,0,0,115,120,230,222,73,57,55,53,52,55,59,62,68,73, - 71,157,205,194,193,194,199,220,126,79,89,88,87,84,83,83,83,84,87,87,104,223,209,110,38,0,0,0,0,0,0,0, - 0,0,0,114,136,249,207,62,57,55,54,56,59,65,71,76,73,111,211,215,209,211,224,206,87,88,87,86,83,81,81,81, - 82,86,86,93,211,245,117,58,0,0,0,0,0,0,0,0,0,0,0,0,112,147,254,205,73,58,58,59,62,67,72,77, - 81,82,116,167,196,193,147,87,82,88,84,83,80,80,80,81,85,85,97,209,253,126,68,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,110,146,248,217,99,60,63,65,69,74,78,82,86,82,78,86,80,72,87,89,86,83,80,80,79,82,83, - 83,122,218,244,125,69,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,107,132,227,234,148,63,66,72,77,80, - 83,87,90,91,90,91,91,89,87,85,84,82,83,83,82,82,164,234,217,119,69,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,103,118,187,251,222,128,69,73,81,85,89,91,92,92,92,91,90,88,87,87,87,81,82,136,213, - 250,170,112,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,94,111,132,214,248,211,149,81, - 75,81,85,90,93,94,93,90,86,82,81,90,157,213,246,196,121,96,43,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,52,96,112,130,179,244,237,231,231,194,167,144,136,144,163,188,217,225,237,243,172,122,105, - 65,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56,90,103,114,130, - 174,211,230,245,254,254,254,247,230,212,188,129,111,94,65,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,84,93,101,116,116,115,115,115,116,117,98,86,69,41,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,115,115,119,146, - 181,213,235,249,254,254,254,249,235,213,181,146,119,115,115,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,115,115,118,144,203,250,251,237,216,197,184,171,166,167,179,195,215,236,251,249,202,144,118, - 115,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,118,145,222,254,238,204,185, - 198,215,221,221,219,217,212,207,197,188,177,167,197,236,253,222,145,118,115,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,115,123,203,254,238,192,207,233,235,229,224,221,219,218,216,216,212,208,204,199,189,180,166,178,233, - 254,202,123,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,142,235,249,206,204,235,236,228,223, - 223,222,220,219,218,215,214,212,209,207,203,200,194,186,172,155,189,246,234,142,115,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,115,158,250,239,194,231,238,229,223,224,222,220,219,218,216,214,212,210,209,206,205,203,201,197,194,187,176, - 160,159,231,250,159,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,159,254,232,202,236,233,223,224,223,221,219, - 219,216,215,212,209,208,206,204,203,202,201,198,195,193,190,186,177,161,143,217,254,157,115,0,0,0,0,0,0,0,0,0, - 0,0,0,115,142,250,231,209,240,229,223,224,222,220,219,216,213,211,212,211,211,211,209,204,201,195,194,195,193,191,190,187, - 181,174,160,136,216,249,138,115,0,0,0,0,0,0,0,0,0,0,115,123,234,233,200,239,227,222,222,221,219,219,215,214, - 229,245,251,255,255,255,254,249,243,233,205,190,190,189,187,185,182,177,170,155,134,230,232,121,115,0,0,0,0,0,0,0, - 0,115,118,202,246,196,235,226,221,221,219,218,216,213,222,253,255,255,255,255,255,255,255,255,254,254,250,231,187,184,183,181, - 179,176,172,165,149,142,244,193,117,115,0,0,0,0,0,0,0,115,145,254,202,229,231,219,220,218,216,215,214,208,231,255, - 255,255,255,255,255,255,255,255,254,251,246,252,221,177,180,178,175,174,171,168,159,140,177,253,134,114,0,0,0,0,0,0, - 115,118,220,237,199,235,218,219,218,216,214,213,211,205,228,255,255,255,255,255,255,255,255,255,255,253,251,245,255,209,172,175, - 174,172,171,169,162,151,127,229,206,116,107,0,0,0,0,0,115,144,254,189,231,222,218,218,215,213,212,210,209,203,224,255, - 254,255,255,251,250,252,255,255,254,253,252,251,250,230,167,173,172,171,169,167,162,157,141,158,251,130,109,0,0,0,0,0, - 115,203,237,201,229,213,215,214,212,210,208,206,205,200,220,254,247,205,178,180,179,181,202,252,253,252,252,252,250,242,160,170, - 170,168,165,164,162,158,148,127,229,171,110,0,0,0,0,115,119,250,199,225,220,213,212,211,209,206,205,203,201,198,211,220, - 175,155,179,188,187,184,174,209,251,250,251,251,251,250,163,164,169,167,164,164,163,160,151,129,185,226,115,88,0,0,0,115, - 146,251,169,227,212,211,210,206,205,204,202,201,199,196,193,174,182,192,189,185,184,183,179,181,238,247,247,249,250,251,158,160, - 164,163,161,160,159,158,152,136,132,244,128,101,0,0,0,115,179,236,184,216,209,208,206,204,203,202,200,196,195,194,193,192, - 190,187,184,183,181,180,175,181,228,233,235,239,243,236,138,155,157,154,154,153,152,152,148,137,116,227,153,105,0,0,0,115, - 210,214,196,208,205,205,203,202,200,198,195,193,192,190,189,187,184,184,182,180,174,170,164,184,206,212,222,231,242,218,138,155, - 154,153,153,153,152,151,149,140,119,197,179,106,0,0,0,115,233,188,201,204,204,203,201,198,196,194,193,191,190,187,185,184, - 182,179,174,169,164,161,169,190,196,205,216,225,251,184,143,155,153,153,153,152,152,151,150,144,124,204,206,108,0,0,0,115, - 249,166,201,201,201,199,198,195,193,192,190,189,185,184,183,180,173,168,164,163,161,167,184,185,190,199,210,230,210,126,154,154, - 152,153,153,152,152,152,151,147,129,191,221,111,0,0,0,115,254,147,203,199,198,195,193,192,191,189,187,185,183,180,173,169, - 165,164,162,159,170,183,183,182,187,194,210,228,142,145,155,154,154,153,153,153,152,153,153,149,132,160,231,118,0,0,0,115, - 254,137,200,194,195,193,191,190,188,185,184,182,178,171,167,164,163,161,160,164,183,183,181,181,184,200,220,159,140,160,155,155, - 155,155,155,155,155,157,155,153,135,157,231,114,0,0,0,115,254,142,194,190,190,190,189,187,184,183,179,172,168,164,164,161, - 160,158,162,188,188,185,184,184,198,200,147,141,161,159,159,159,159,159,159,160,160,160,160,155,137,170,231,114,0,0,0,115, - 247,157,184,188,188,187,184,183,181,177,169,165,164,162,161,159,158,154,172,198,194,192,191,199,191,130,149,162,161,161,161,161, - 162,162,163,163,163,163,162,156,135,195,228,113,0,0,0,115,230,181,171,184,186,183,182,180,174,168,164,163,161,159,158,158, - 155,153,190,208,203,201,204,201,136,149,163,162,162,163,164,165,167,167,167,168,168,168,165,158,134,200,214,125,0,0,0,115, - 207,208,155,179,182,181,179,173,167,164,162,160,158,157,155,155,153,155,202,212,209,209,214,155,143,165,163,164,165,168,169,170, - 171,171,171,171,171,171,169,158,132,207,181,112,0,0,0,115,178,232,136,173,178,178,172,164,162,161,159,158,155,154,153,152, - 152,158,205,210,209,212,209,134,161,167,167,169,170,172,173,174,174,175,175,175,175,174,171,154,136,240,152,84,0,0,0,115, - 147,250,128,166,173,172,163,161,160,159,157,154,153,151,151,151,151,157,195,199,199,205,199,138,167,169,171,173,174,175,178,179, - 179,180,180,180,180,178,171,147,153,238,118,60,0,0,0,115,119,247,184,143,164,161,159,159,157,155,153,151,150,150,149,151, - 152,154,154,149,150,153,153,158,171,172,174,177,179,180,181,182,182,183,183,183,183,179,167,141,195,205,107,23,0,0,0,0, - 115,196,231,108,152,155,157,155,153,152,150,150,149,148,149,151,152,153,155,158,161,163,167,172,173,175,179,181,182,183,184,185, - 185,187,187,187,186,178,158,137,229,146,86,0,0,0,0,0,115,140,253,140,128,147,152,153,151,150,149,148,148,147,149,151, - 153,154,163,175,180,184,187,173,177,180,182,184,187,188,189,190,190,191,191,190,186,175,147,177,242,116,57,0,0,0,0,0, - 115,117,215,229,99,137,146,149,149,147,145,145,144,147,149,151,152,161,189,189,189,189,205,209,179,183,187,188,190,191,192,193, - 193,193,193,190,184,161,138,228,168,97,13,0,0,0,0,0,0,115,138,254,158,115,138,144,146,145,144,143,144,147,149,151, - 152,179,192,188,187,189,192,213,191,184,189,191,192,194,195,195,198,196,194,188,173,143,187,244,116,55,0,0,0,0,0,0, - 0,115,117,198,242,117,121,136,140,142,143,142,144,145,149,152,155,190,196,191,191,192,196,208,187,182,192,193,195,198,198,198, - 199,198,193,182,152,154,240,154,90,7,0,0,0,0,0,0,0,0,115,120,230,222,97,121,133,138,140,141,143,147,150,154, - 155,191,206,200,199,200,204,220,181,185,195,196,199,200,201,201,200,196,185,159,134,224,209,110,38,0,0,0,0,0,0,0, - 0,0,0,114,136,249,207,92,120,132,137,140,144,148,152,157,159,173,214,215,213,215,224,215,170,195,196,199,201,202,202,201, - 196,186,161,132,213,245,117,58,0,0,0,0,0,0,0,0,0,0,0,0,112,147,254,206,96,115,128,137,143,148,153,158, - 162,164,175,191,205,204,179,162,187,198,199,201,203,203,201,195,183,158,134,211,253,126,68,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,110,146,248,218,113,108,126,137,146,152,159,163,168,170,162,159,157,165,191,196,198,199,201,201,198,190,176, - 148,145,219,244,125,69,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,107,132,227,234,153,98,119,135,146,154, - 161,167,172,178,182,188,192,192,194,197,197,196,190,180,160,134,173,234,217,119,69,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,103,118,187,251,223,138,100,123,140,151,159,166,172,178,183,185,186,188,186,182,174,157,132,153,215, - 250,170,112,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,94,111,132,214,248,212,154,99, - 109,127,141,153,161,168,167,163,157,146,131,120,164,215,246,196,121,96,43,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,52,96,112,130,179,244,237,232,235,203,181,164,161,167,181,199,223,226,237,243,172,122,105, - 65,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56,90,103,114,130, - 174,211,230,245,254,254,254,247,230,212,188,129,111,94,65,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,84,93,101,116,116,115,115,115,116,117,98,86,69,41,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,42,93,139,181,216,242,254,254,254,242,216,181,139,93,42,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,21,90,169,220,209, - 218,235,248,253,255,255,255,253,248,235,218,209,220,169,90,21,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,12,93,203,207,225,252,255,255,255,255,255,255,255,255,255,255,255,255,255,252,225,207,203, - 93,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,55,176,206,234,253,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,252,233,206,176,55,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,91,212,222,253,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 253,221,212,92,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,114,204,242,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,241,203,115,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,115,204,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,252,204,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,204,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,204,114,0,0,0,0,0,0,0,0,0, - 0,0,0,92,203,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,252,207,83,0,0,0,0,0,0,0,0,0,0,56,211,241,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,242,216,49,0,0,0,0,0,0,0, - 0,12,176,221,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,221,166,8,0,0,0,0,0,0,0,93,206,253,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,212,77,0,0,0,0,0,0, - 20,200,234,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,232,189,14,0,0,0,0,0,91,206,252,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,217,73,0,0,0,0,0, - 170,224,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,225,141,2,0,0,0,42,220,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,248,222,26,0,0,0,93, - 209,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,223,73,1,0,0,136,218,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,225,124,4,0,0,178, - 233,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,236,165,8,0,0,215,247,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,251,191,13,1,0,242, - 253,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,254,212,19,3,0,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,229,24,6,0,254, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,227,28,8,0,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,228,32,9,0,238, - 253,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,224,33,10,0,210,246,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,221,34,10,0,175, - 233,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,246,190,33,10,0,135,218,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,241,145,32,9,0,94, - 209,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,234,103,28,7,0,38,223,251,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,250,222,65,23,5,0,0, - 162,224,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,237,164,46,18,3,0,0,84,209,253,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,233,111,36,12,1,0,0, - 17,197,233,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,243,195,64,27,7,0,0,0,0,81,210,253,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,234,119,46,18,4,0,0,0, - 0,9,173,223,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,239,184,67,32,10,1,0,0,0,0,0,47,218,242,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,249,232,103,48,20,5,0,0,0,0, - 0,0,0,83,208,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,254,232,135,61,31,10,1,0,0,0,0,0,0,0,0,105,209,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,232,155,72,41,17,4,0,0,0,0,0, - 0,0,0,0,1,107,211,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,254,234,158,79,49,24,8,1,0,0,0,0,0,0,0,0,0,0,2,108,213,244,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,252,234,158,81,54,28,10,2,0,0,0,0,0,0, - 0,0,0,0,0,0,3,88,220,228,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,244,235,145,80,54,30,12,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,60,180,217,248,254,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,249,237,205,122,74,51,29,12,3,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,3,20,103,209,220,235,254,255,255,255,255,255,255,255,255,255,255,255,255,255,254,246,238,223, - 150,90,65,44,25,11,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,8,35,107,183,231,225, - 247,255,255,255,255,255,255,255,255,255,255,244,241,203,149,96,70,52,34,19,8,2,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,1,5,13,24,70,124,166,200,233,247,255,255,255,249,237,208,181,151,113,78,66,52, - 37,24,12,5,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,7,13,22, - 32,43,52,60,67,72,76,77,76,72,67,60,52,43,32,22,13,7,2,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,5,10,16,22,27,31,34,37,38,37,35,31,27,22,16,10,5, - 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 1,2,4,7,9,10,12,12,12,10,9,7,4,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} -},{ - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,116,116,120,147, - 182,213,235,249,254,254,254,249,235,213,182,147,120,116,116,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,116,116,119,144,203,250,251,238,218,192,166,142,129,139,160,187,213,236,251,249,202,144,119, - 116,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,119,145,222,254,239,202,151, - 149,151,145,139,133,128,125,122,119,117,121,132,191,236,253,222,145,119,116,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,116,124,204,254,238,185,157,163,148,132,119,111,106,103,100,99,98,99,100,101,103,107,111,165,233, - 254,203,124,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,143,235,249,203,156,164,146,118,108, - 104,100,99,96,95,92,91,90,88,88,87,88,91,96,100,106,184,246,234,143,116,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,116,159,250,239,172,163,149,117,105,101,98,97,95,94,93,88,81,80,83,85,82,81,80,81,82,85,92, - 97,138,231,250,159,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,160,254,231,158,163,123,105,101,97,95,94, - 93,93,93,83,104,137,132,94,78,81,79,78,76,75,76,78,86,91,107,216,254,158,116,0,0,0,0,0,0,0,0,0, - 0,0,0,116,143,250,231,153,151,115,100,97,94,93,93,91,91,91,83,110,242,255,255,242,103,73,78,76,74,72,71,71, - 73,81,88,95,216,249,138,116,0,0,0,0,0,0,0,0,0,0,116,124,234,233,156,153,111,98,92,90,90,90,90,89, - 89,86,96,236,255,255,255,255,202,71,73,73,72,70,69,66,66,69,77,86,100,230,232,122,116,0,0,0,0,0,0,0, - 0,116,119,203,246,170,150,110,94,90,88,87,87,87,87,87,86,78,121,255,255,255,255,255,255,93,68,71,69,68,65,64, - 62,62,65,74,86,125,244,193,118,116,0,0,0,0,0,0,0,116,145,254,201,155,114,93,88,86,85,86,85,85,85,83, - 83,77,112,255,255,255,255,255,244,81,68,70,68,66,65,63,61,60,59,64,75,86,173,253,135,115,0,0,0,0,0,0, - 116,119,220,237,148,135,93,85,82,83,83,83,82,82,82,82,81,79,77,206,255,255,255,255,163,54,70,68,66,65,63,61, - 60,59,56,57,64,77,87,229,206,117,108,0,0,0,0,0,116,144,254,183,140,99,85,81,80,80,80,80,80,80,80,79, - 79,78,73,81,168,236,229,153,72,65,68,66,64,62,61,60,57,55,55,54,56,66,79,150,251,131,110,0,0,0,0,0, - 116,203,238,140,116,85,79,77,78,78,78,78,78,77,77,76,76,74,76,70,64,74,70,55,63,68,64,63,62,61,60,57, - 56,54,53,51,51,56,71,87,228,172,111,0,0,0,0,116,120,250,197,137,93,77,74,76,76,76,76,76,74,74,73,73, - 73,73,71,64,64,61,61,63,61,67,65,63,61,59,55,54,53,51,51,49,48,50,58,67,180,226,116,89,0,0,0,116, - 147,251,141,117,81,73,72,73,73,73,73,73,73,72,72,72,72,69,68,91,123,123,123,123,93,51,47,40,36,32,30,30, - 30,30,31,32,35,40,48,59,111,244,129,102,0,0,0,116,179,237,131,97,75,71,71,71,71,71,71,70,70,70,70,70, - 69,67,71,198,255,249,240,235,192,40,23,26,27,27,27,28,28,28,27,27,27,28,34,49,75,227,154,106,0,0,0,116, - 210,216,124,86,70,68,68,68,68,68,68,68,68,68,66,66,66,63,76,240,214,201,196,191,225,40,30,28,27,28,27,28, - 28,28,27,27,28,28,32,44,60,195,179,107,0,0,0,116,233,186,113,79,68,65,65,65,65,65,65,66,65,64,64,64, - 56,34,47,230,201,196,191,187,224,40,30,27,27,28,27,28,27,27,27,27,28,27,31,41,56,199,206,109,0,0,0,116, - 249,156,106,74,65,63,63,63,63,63,64,64,63,64,60,42,29,20,46,229,196,190,187,181,223,41,29,27,27,27,27,27, - 27,27,27,27,27,27,29,38,52,182,221,112,0,0,0,116,254,129,101,71,62,61,61,61,61,62,61,62,62,47,34,28, - 29,22,46,224,190,183,181,175,221,41,30,27,27,27,27,27,27,27,27,27,27,27,28,36,50,146,231,118,0,0,0,116, - 254,115,97,68,60,59,59,59,60,59,60,56,42,29,29,29,29,22,46,222,184,179,176,172,219,41,29,27,27,27,27,27, - 27,27,27,27,27,27,28,36,49,139,231,115,0,0,0,116,254,128,95,67,58,56,56,57,56,57,52,35,29,30,30,29, - 29,22,45,218,179,175,173,171,219,41,29,28,28,27,27,27,27,27,27,27,27,27,28,36,50,155,231,115,0,0,0,116, - 247,151,94,67,56,55,55,54,56,49,32,30,30,30,30,29,29,22,43,214,176,172,172,171,219,41,30,28,28,27,28,28, - 28,28,27,27,27,27,29,38,51,184,228,114,0,0,0,116,230,180,94,68,55,53,53,53,47,32,30,31,30,30,29,29, - 29,23,43,212,173,172,173,174,222,42,30,28,28,28,28,28,28,28,28,28,28,27,30,41,55,191,214,126,0,0,0,116, - 207,209,97,69,56,51,52,48,32,30,31,30,30,30,29,29,29,23,42,212,173,174,176,179,223,42,30,28,29,29,28,28, - 28,28,28,28,28,28,32,44,62,203,181,113,0,0,0,116,179,232,99,71,54,50,47,35,31,31,31,30,30,30,29,29, - 29,23,43,212,178,179,182,185,224,41,31,30,29,30,30,30,29,29,29,28,28,30,34,47,81,239,153,85,0,0,0,116, - 148,250,114,73,54,49,37,31,32,31,31,30,30,30,29,29,29,23,43,214,182,184,189,193,228,41,32,30,30,30,30,30, - 30,30,30,29,29,31,38,50,122,238,119,61,0,0,0,116,120,247,183,70,56,45,32,32,31,31,31,30,30,30,29,29, - 29,22,43,218,188,191,196,201,229,41,32,30,30,30,30,30,31,30,30,30,30,33,45,60,184,207,108,23,0,0,0,0, - 116,196,231,66,58,43,32,32,31,31,30,30,30,30,29,29,29,22,45,220,193,198,204,213,234,41,33,31,32,32,32,32, - 31,31,31,30,32,39,51,82,227,150,86,0,0,0,0,0,116,140,253,136,58,45,36,33,31,31,30,30,30,30,29,30, - 30,23,46,224,202,209,218,230,239,40,34,32,32,32,32,32,32,32,32,33,36,47,58,161,242,117,57,0,0,0,0,0, - 116,118,215,229,66,51,41,34,32,31,30,30,30,30,30,30,30,23,46,229,215,224,233,243,243,40,34,34,34,32,34,34, - 34,32,32,35,43,54,82,227,174,98,13,0,0,0,0,0,0,116,139,254,157,60,49,38,33,31,31,30,30,30,30,30, - 30,23,46,235,230,236,244,253,244,40,34,34,34,34,34,34,34,35,36,42,54,65,177,244,117,55,0,0,0,0,0,0, - 0,116,118,198,242,107,53,46,37,32,31,30,30,30,30,30,31,23,48,243,242,247,251,255,244,41,35,35,35,35,35,35, - 36,37,41,53,61,124,240,162,91,7,0,0,0,0,0,0,0,0,116,121,230,222,78,53,45,37,32,31,30,30,31,31, - 31,23,49,247,252,252,252,255,245,41,35,35,35,35,35,36,37,42,54,62,93,223,215,111,38,0,0,0,0,0,0,0, - 0,0,0,115,136,249,207,66,53,46,38,33,31,31,31,31,31,25,49,190,255,255,255,255,184,40,35,35,36,36,37,38, - 44,55,63,82,210,247,120,58,0,0,0,0,0,0,0,0,0,0,0,0,113,148,254,206,76,55,48,40,35,32,31,31, - 32,30,40,83,121,119,119,122,68,33,39,36,37,38,41,48,59,66,90,208,253,132,69,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,111,146,248,218,104,58,50,45,39,35,34,33,34,33,25,22,23,23,22,30,41,37,38,40,45,54,63, - 66,117,218,246,136,69,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,133,227,234,153,64,54,50,46,41, - 38,38,37,36,40,41,41,42,42,40,42,47,53,62,65,75,166,234,223,126,69,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,104,119,187,251,224,134,62,55,54,52,50,47,46,44,44,46,47,50,54,60,65,64,73,137,214, - 251,183,115,61,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,95,112,133,214,248,212,152,77, - 60,57,56,58,61,63,64,62,61,63,67,86,158,214,248,205,136,98,44,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,52,97,113,130,181,245,237,233,235,200,173,148,140,148,168,192,220,226,237,245,184,136,107, - 66,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56,91,104,115,132, - 178,211,230,245,254,254,254,247,230,212,190,147,120,96,66,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,65,85,94,102,117,117,116,116,116,117,118,99,86,70,41,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,115,115,119,146, - 181,213,235,249,254,254,254,249,235,213,181,146,119,115,115,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,115,115,118,144,203,250,251,238,218,192,167,144,132,141,162,187,213,236,251,249,202,144,118, - 115,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,118,145,222,254,239,202,153, - 154,161,161,157,154,150,146,141,135,130,127,135,191,236,253,222,145,118,115,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,115,123,203,254,238,185,161,175,170,158,148,143,139,137,134,133,131,129,129,126,125,122,119,165,233, - 254,202,123,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,142,235,249,204,159,177,169,148,142, - 141,140,138,136,134,132,131,129,128,125,124,122,120,118,116,113,184,246,234,142,115,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,115,158,250,239,173,172,172,147,140,140,138,138,136,134,133,129,123,122,124,125,123,122,120,117,115,115,113, - 110,140,231,250,159,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,159,254,231,160,177,153,140,138,137,136,134, - 134,133,132,127,141,166,163,133,119,122,120,119,116,114,113,112,111,107,113,217,254,157,115,0,0,0,0,0,0,0,0,0, - 0,0,0,115,142,250,231,156,170,145,136,136,134,134,133,132,132,131,125,146,248,255,255,248,139,115,117,116,115,113,111,108, - 108,108,105,102,216,249,138,115,0,0,0,0,0,0,0,0,0,0,115,123,234,233,158,170,142,134,133,132,131,131,131,130, - 130,127,134,243,255,255,255,255,215,112,115,114,113,111,110,107,105,104,105,103,106,230,232,121,115,0,0,0,0,0,0,0, - 0,115,118,202,246,171,167,140,131,130,129,129,129,128,128,127,127,121,154,255,255,255,255,255,255,125,110,112,110,108,106,105, - 103,102,101,102,102,128,244,193,117,115,0,0,0,0,0,0,0,115,145,254,201,165,143,129,127,127,125,127,125,125,124,125, - 124,120,146,255,255,255,255,255,244,112,108,110,107,106,105,104,100,99,98,99,100,99,174,253,134,114,0,0,0,0,0,0, - 115,118,220,237,151,158,127,124,124,123,124,124,123,123,123,123,122,120,117,218,255,255,255,255,176,90,110,107,106,104,103,102, - 99,97,96,96,96,98,96,229,206,116,107,0,0,0,0,0,115,144,254,183,156,131,123,121,121,121,121,121,121,121,120,120, - 120,119,114,119,183,239,231,166,104,105,107,105,104,102,100,99,97,96,95,93,92,94,96,152,251,130,109,0,0,0,0,0, - 115,203,238,145,142,122,119,119,117,119,117,117,117,117,117,116,116,115,114,111,104,108,104,93,104,106,104,103,100,99,98,97, - 95,94,93,90,90,90,94,97,228,171,110,0,0,0,0,115,119,250,197,150,125,116,115,116,116,116,116,115,115,115,114,114, - 113,113,111,105,105,104,104,104,102,107,103,102,98,97,94,93,90,89,89,88,87,86,87,84,181,226,115,88,0,0,0,115, - 146,251,143,140,116,113,114,114,114,114,114,113,113,113,112,112,111,108,106,126,152,152,152,152,127,90,85,79,73,72,70,69, - 69,69,70,71,72,76,81,80,117,244,128,101,0,0,0,115,179,237,136,125,113,112,112,111,111,111,111,111,111,110,110,108, - 108,107,109,210,255,247,239,232,202,70,63,64,65,65,65,66,66,65,65,65,65,65,69,74,86,227,153,105,0,0,0,115, - 210,216,134,117,109,108,108,110,108,108,107,107,107,106,106,106,106,102,112,240,213,201,196,190,226,68,64,66,65,64,64,65, - 65,65,65,65,66,65,67,72,76,196,179,106,0,0,0,115,233,187,129,112,107,106,106,106,106,106,105,105,104,104,105,104, - 95,73,82,230,201,196,191,185,224,68,63,65,65,64,65,64,64,65,64,64,65,65,65,70,75,201,206,108,0,0,0,115, - 249,156,125,108,105,104,104,104,104,103,103,103,103,104,99,80,68,60,82,229,196,189,185,180,224,68,63,65,65,65,65,64, - 64,65,64,64,64,64,65,69,72,185,221,111,0,0,0,115,254,130,123,106,102,103,102,100,102,102,100,100,102,86,72,66, - 68,62,81,224,189,183,180,175,222,68,63,64,64,64,64,64,64,63,63,63,63,64,66,68,71,151,231,118,0,0,0,115, - 254,116,119,102,99,99,99,99,99,99,99,96,80,68,66,68,68,62,81,222,183,179,176,172,221,68,62,64,64,64,64,64, - 64,63,63,63,63,64,63,68,71,144,231,114,0,0,0,115,254,129,116,101,98,97,96,97,96,97,93,74,66,69,68,68, - 68,61,79,218,179,175,173,170,221,68,62,64,63,63,63,63,63,63,63,63,63,63,64,68,71,160,231,114,0,0,0,115, - 247,152,112,100,96,95,94,94,96,89,71,68,69,68,68,68,66,61,77,213,174,172,172,170,221,68,61,63,63,63,63,63, - 63,63,63,63,63,63,64,68,72,188,228,113,0,0,0,115,230,180,108,99,94,93,93,93,87,72,69,69,68,68,68,66, - 66,61,77,212,173,172,173,174,222,68,62,63,63,63,63,63,63,63,63,63,63,63,64,70,74,194,214,125,0,0,0,115, - 207,209,107,98,92,90,90,88,72,69,69,69,68,68,66,66,66,61,77,212,173,174,176,179,224,68,61,64,64,63,63,63, - 63,63,63,63,63,63,65,71,78,204,181,112,0,0,0,115,178,232,104,97,90,88,86,73,70,70,69,68,68,68,66,66, - 66,61,77,213,178,179,182,185,226,66,62,64,64,64,64,63,63,63,63,63,63,64,66,71,94,239,152,84,0,0,0,115, - 147,250,116,94,87,87,77,70,70,70,69,68,68,66,66,66,65,61,77,215,181,184,189,192,229,66,62,64,64,64,64,64, - 64,64,63,63,63,64,68,71,130,238,118,60,0,0,0,115,119,247,183,84,84,80,71,70,70,69,69,68,68,66,66,65, - 65,60,77,218,188,191,196,201,231,65,62,64,64,64,64,64,64,64,64,64,64,66,71,77,187,205,107,23,0,0,0,0, - 115,196,231,71,80,77,71,71,70,69,69,68,66,66,66,65,65,60,79,220,193,198,204,213,235,65,63,65,64,64,64,64, - 64,64,64,64,65,69,74,94,228,146,86,0,0,0,0,0,115,140,253,137,73,74,72,71,70,69,69,66,66,66,66,65, - 65,60,79,224,202,209,218,230,240,65,63,65,65,65,65,65,65,65,64,65,67,73,75,165,242,116,57,0,0,0,0,0, - 115,117,215,229,71,72,73,71,69,69,69,66,66,66,65,65,65,60,79,229,214,224,233,243,243,64,63,65,65,65,65,65, - 65,65,65,67,71,75,93,227,168,97,13,0,0,0,0,0,0,115,138,254,158,70,74,72,70,69,68,66,66,66,65,65, - 65,60,80,236,230,236,244,252,245,64,63,65,65,65,65,65,65,65,66,70,77,80,179,244,116,55,0,0,0,0,0,0, - 0,115,117,198,242,108,69,73,70,69,68,66,66,66,66,65,65,59,81,243,241,247,251,255,245,65,64,66,66,66,66,66, - 65,66,70,77,77,130,240,154,90,7,0,0,0,0,0,0,0,0,115,120,230,222,81,69,72,71,68,66,66,66,65,65, - 65,59,82,248,252,252,251,255,246,65,64,66,66,66,66,66,67,71,77,78,102,223,209,110,38,0,0,0,0,0,0,0, - 0,0,0,114,136,249,207,71,70,73,70,67,66,66,65,66,65,59,82,202,255,255,255,255,196,63,64,66,66,66,67,68, - 71,78,80,91,211,245,117,58,0,0,0,0,0,0,0,0,0,0,0,0,112,147,254,206,80,69,73,71,68,67,66,66, - 66,64,73,108,134,133,133,136,92,59,66,66,66,67,69,73,80,81,97,209,253,126,68,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,110,146,248,218,105,69,71,71,69,68,67,66,66,65,55,51,51,51,50,57,68,68,69,70,73,78,81, - 80,122,219,244,125,69,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,107,132,227,234,153,70,69,72,72,70, - 68,68,67,67,68,68,68,69,69,70,72,74,78,82,81,84,167,234,217,119,69,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,103,118,187,251,224,134,69,69,73,75,73,72,71,71,71,71,74,76,78,81,84,79,81,139,214, - 250,170,112,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,94,111,132,214,248,212,153,80, - 68,69,71,75,79,82,82,78,76,75,76,91,159,214,246,196,121,96,43,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,52,96,112,130,179,244,237,233,236,201,174,151,143,151,171,194,221,226,237,243,172,122,105, - 65,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56,90,103,114,130, - 174,211,230,245,254,254,254,247,230,212,188,129,111,94,65,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,84,93,101,116,116,115,115,115,116,117,98,86,69,41,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,115,115,119,146, - 181,213,235,249,254,254,254,249,235,213,181,146,119,115,115,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,115,115,118,144,203,250,251,238,218,193,170,149,138,146,166,189,214,236,251,249,202,144,118, - 115,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,118,145,222,254,239,203,156, - 166,186,200,204,207,205,198,188,176,161,145,141,192,236,253,222,145,118,115,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,115,123,203,254,238,186,168,201,224,225,222,221,222,223,220,217,212,206,199,189,176,159,137,169,233, - 254,202,123,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,142,235,249,204,166,208,229,226,228, - 233,234,234,233,232,231,230,227,223,218,213,204,193,175,155,130,185,246,234,142,115,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,115,158,250,239,175,194,230,225,229,235,237,236,235,233,233,232,229,226,226,225,223,221,216,211,200,187,166, - 142,148,231,250,159,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,159,254,231,164,210,224,227,233,236,237,235, - 234,233,233,230,233,240,238,229,222,222,219,217,214,212,205,192,173,146,127,217,254,157,115,0,0,0,0,0,0,0,0,0, - 0,0,0,115,142,250,231,162,217,221,227,234,235,235,234,233,232,232,229,234,255,255,255,255,226,217,217,215,214,212,209,204, - 193,174,147,119,216,249,138,115,0,0,0,0,0,0,0,0,0,0,115,123,234,233,163,214,217,225,232,232,232,232,231,230, - 230,229,230,255,255,255,255,255,246,212,216,214,212,209,208,206,202,191,173,146,120,230,232,121,115,0,0,0,0,0,0,0, - 0,115,118,202,246,173,207,215,222,229,230,229,229,229,227,226,226,224,233,255,255,255,255,255,255,204,214,212,210,208,206,206, - 202,198,188,169,141,137,244,193,117,115,0,0,0,0,0,0,0,115,145,254,201,187,215,219,226,227,226,226,226,225,225,224, - 223,222,230,255,255,255,255,255,250,190,213,209,208,207,206,204,201,199,194,184,162,132,177,253,134,114,0,0,0,0,0,0, - 115,118,220,237,160,218,214,223,225,225,224,224,224,224,223,223,222,221,218,246,255,255,255,255,208,184,212,208,207,205,204,202, - 199,199,196,192,178,151,119,229,206,116,107,0,0,0,0,0,115,144,254,184,196,210,217,221,222,222,222,221,222,222,221,219, - 219,218,217,214,223,243,240,201,184,207,209,207,205,202,201,200,199,197,196,192,185,168,138,157,251,130,109,0,0,0,0,0, - 115,203,238,156,208,209,216,218,219,218,218,218,218,218,217,217,217,216,216,214,206,197,190,193,207,209,206,205,204,202,200,199, - 197,196,195,192,189,178,152,124,229,171,110,0,0,0,0,115,119,250,198,184,203,212,216,216,216,217,216,216,215,215,215,215, - 215,214,213,211,211,211,211,211,209,209,207,205,202,200,198,196,193,192,192,190,190,182,162,127,186,226,115,88,0,0,0,115, - 146,251,148,197,203,212,214,214,214,215,214,214,214,213,214,213,213,212,207,216,226,226,226,226,214,197,190,182,178,175,173,172, - 172,173,173,175,176,177,167,135,134,244,128,101,0,0,0,115,179,237,150,196,205,211,210,212,212,212,212,212,212,212,212,210, - 210,210,209,239,253,244,235,227,228,149,168,168,170,170,170,170,171,170,170,170,170,169,162,141,118,228,153,105,0,0,0,115, - 210,216,160,192,203,207,209,209,209,209,209,209,209,209,208,208,209,209,207,241,214,201,196,190,229,144,160,171,171,171,171,171, - 171,171,171,171,170,171,166,148,118,198,179,106,0,0,0,115,233,187,167,193,203,206,206,207,207,207,207,207,207,207,208,207, - 199,182,180,232,200,197,192,184,229,146,161,172,171,171,172,172,171,171,171,171,171,171,168,154,124,206,206,108,0,0,0,115, - 249,157,171,192,202,205,205,205,205,206,205,205,206,206,204,184,172,170,180,229,195,190,185,179,227,146,161,172,172,172,172,172, - 172,172,172,172,171,171,169,158,128,195,221,111,0,0,0,115,254,132,174,190,200,202,202,202,204,202,202,204,205,190,176,172, - 173,171,180,226,188,184,181,174,224,147,161,173,173,173,172,172,173,173,172,172,172,172,171,161,132,163,231,118,0,0,0,115, - 254,118,172,189,199,201,200,201,200,201,202,200,184,173,173,173,173,171,179,222,182,179,176,170,224,148,161,173,173,173,174,173, - 173,173,172,172,172,173,171,162,134,160,231,114,0,0,0,115,254,131,168,187,197,198,198,199,199,200,196,179,172,174,174,174, - 174,173,178,218,178,174,173,168,224,148,161,174,175,175,174,174,174,174,174,173,173,173,172,163,134,173,231,114,0,0,0,115, - 247,153,157,183,195,197,197,197,199,192,176,173,174,174,174,174,174,174,176,215,173,172,172,168,224,149,164,176,176,176,176,176, - 176,176,175,175,175,174,171,161,132,199,228,113,0,0,0,115,230,181,145,178,191,194,196,196,191,176,175,175,174,175,175,175, - 175,174,176,213,172,172,173,173,225,149,166,179,178,179,178,178,178,178,176,176,176,175,171,159,130,200,214,125,0,0,0,115, - 207,209,133,171,187,191,195,192,176,174,175,175,175,175,175,175,175,174,176,213,172,174,176,178,227,152,167,180,181,181,181,181, - 181,180,180,179,178,178,174,156,128,208,181,112,0,0,0,115,178,232,118,164,182,189,190,179,175,175,175,175,175,175,175,175, - 175,175,176,213,176,179,182,184,229,153,169,183,182,183,183,183,183,182,182,182,181,179,173,151,135,240,152,84,0,0,0,115, - 147,250,122,149,172,186,181,175,176,175,175,175,175,175,176,176,178,176,179,216,181,184,189,191,232,153,171,185,185,185,185,185, - 185,184,184,184,182,180,169,140,156,238,118,60,0,0,0,115,119,247,184,118,159,176,175,176,176,176,176,176,176,176,178,178, - 178,178,179,218,185,191,196,199,234,154,173,188,188,187,188,188,188,187,187,185,184,180,163,135,195,205,107,23,0,0,0,0, - 115,196,231,83,142,165,172,176,176,176,176,176,176,178,178,178,179,180,179,221,192,198,204,212,238,155,174,190,189,190,190,190, - 190,189,189,188,186,177,153,136,229,146,86,0,0,0,0,0,115,140,253,138,112,150,169,175,178,178,178,178,178,178,178,180, - 180,181,180,224,201,210,218,229,243,155,177,192,192,192,192,192,192,191,191,189,185,170,139,178,242,116,57,0,0,0,0,0, - 115,117,215,229,83,131,161,174,177,178,178,178,179,179,180,181,182,182,181,229,213,224,234,243,247,155,178,193,193,193,193,193, - 193,193,192,189,181,153,136,228,168,97,13,0,0,0,0,0,0,115,138,254,158,98,143,165,175,177,178,178,179,180,180,181, - 183,183,183,236,229,238,246,252,248,156,180,195,195,196,196,195,195,194,191,185,167,137,187,244,116,55,0,0,0,0,0,0, - 0,115,117,198,242,112,114,148,167,175,178,179,179,181,182,183,184,184,184,243,241,248,252,253,248,157,181,197,197,197,197,197, - 196,195,189,175,144,153,240,154,90,7,0,0,0,0,0,0,0,0,115,120,230,222,91,120,151,168,176,179,180,181,183,184, - 185,185,185,249,251,252,252,253,249,159,182,198,199,199,199,198,196,191,179,150,135,224,209,110,38,0,0,0,0,0,0,0, - 0,0,0,114,136,249,207,83,123,151,168,176,180,182,183,185,187,187,187,231,255,255,255,255,227,157,184,199,199,199,199,197, - 191,178,152,130,213,245,117,58,0,0,0,0,0,0,0,0,0,0,0,0,112,147,254,206,90,115,147,165,175,181,184,187, - 188,189,195,188,185,185,187,188,174,167,185,200,199,198,195,188,174,148,130,211,253,126,68,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,110,146,248,218,112,105,138,158,170,179,184,188,190,191,171,166,167,168,169,174,184,199,198,195,191,181,165, - 140,142,220,244,125,69,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,107,132,227,234,154,88,118,146,162,173, - 181,185,188,193,182,183,183,183,182,195,193,189,182,168,148,121,173,234,217,119,69,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,103,118,187,251,224,138,92,118,144,157,166,172,179,183,186,186,184,181,177,171,163,144,121,151,215, - 250,170,112,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,94,111,132,214,248,212,155,91, - 95,115,131,144,153,158,156,150,143,130,116,110,164,215,246,196,121,96,43,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,52,96,112,130,179,244,237,233,237,206,183,163,157,164,180,200,224,227,237,243,172,122,105, - 65,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56,90,103,114,130, - 174,211,230,245,254,254,254,247,230,212,188,129,111,94,65,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,84,93,101,116,116,115,115,115,116,117,98,86,69,41,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,42,93,139,181,216,242,254,254,254,242,216,181,139,93,42,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,21,90,169,220,209, - 218,235,248,253,255,255,255,253,248,235,218,209,220,169,90,21,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,12,93,203,207,225,252,255,255,255,255,255,255,255,255,255,255,255,255,255,252,225,207,203, - 93,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,55,176,206,234,253,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,252,233,206,176,55,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,91,212,222,253,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 253,221,212,92,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,114,204,242,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,241,203,115,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,115,204,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,252,204,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,204,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,204,114,0,0,0,0,0,0,0,0,0, - 0,0,0,92,203,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,252,207,83,0,0,0,0,0,0,0,0,0,0,56,211,241,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,242,216,49,0,0,0,0,0,0,0, - 0,12,176,221,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,221,166,8,0,0,0,0,0,0,0,93,206,253,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,212,77,0,0,0,0,0,0, - 20,200,234,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,232,189,14,0,0,0,0,0,91,206,252,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,217,73,0,0,0,0,0, - 170,224,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,225,141,2,0,0,0,42,220,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,248,222,26,0,0,0,93, - 209,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,223,73,1,0,0,136,218,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,225,124,4,0,0,178, - 233,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,236,165,8,0,0,215,247,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,251,191,13,1,0,242, - 253,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,254,212,19,3,0,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,229,24,6,0,254, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,227,28,8,0,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,228,32,9,0,238, - 253,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,224,33,10,0,210,246,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,221,34,10,0,175, - 233,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,246,190,33,10,0,135,218,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,241,145,32,9,0,94, - 209,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,234,103,28,7,0,38,223,251,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,250,222,65,23,5,0,0, - 162,224,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,237,164,46,18,3,0,0,84,209,253,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,233,111,36,12,1,0,0, - 17,197,233,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,243,195,64,27,7,0,0,0,0,81,210,253,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,234,119,46,18,4,0,0,0, - 0,9,173,223,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,239,184,67,32,10,1,0,0,0,0,0,47,218,242,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,249,232,103,48,20,5,0,0,0,0, - 0,0,0,83,208,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,254,232,135,61,31,10,1,0,0,0,0,0,0,0,0,105,209,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,232,155,72,41,17,4,0,0,0,0,0, - 0,0,0,0,1,107,211,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,254,234,158,79,49,24,8,1,0,0,0,0,0,0,0,0,0,0,2,108,213,244,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,252,234,158,81,54,28,10,2,0,0,0,0,0,0, - 0,0,0,0,0,0,3,88,220,228,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,244,235,145,80,54,30,12,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,60,180,217,248,254,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,249,237,205,122,74,51,29,12,3,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,3,20,103,209,220,235,254,255,255,255,255,255,255,255,255,255,255,255,255,255,254,246,238,223, - 150,90,65,44,25,11,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,8,35,107,183,231,225, - 247,255,255,255,255,255,255,255,255,255,255,244,241,203,149,96,70,52,34,19,8,2,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,1,5,13,24,70,124,166,200,233,247,255,255,255,249,237,208,181,151,113,78,66,52, - 37,24,12,5,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,7,13,22, - 32,43,52,60,67,72,76,77,76,72,67,60,52,43,32,22,13,7,2,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,5,10,16,22,27,31,34,37,38,37,35,31,27,22,16,10,5, - 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 1,2,4,7,9,10,12,12,12,10,9,7,4,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} -},{ - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,150,173,179,153,115,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,158,166,182,188,174,119,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,153,168,193,188,194,158,91,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,150,157,196,182,190,193,187,154,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,154,179,189,177,232,176,196,162,108,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,150,157,202,153,224,255,244,165,193,157,52,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,156,193,176,185,255,252,254,186,201,173,134,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 153,165,205,159,239,255,251,252,248,174,202,159,81,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,155,156,205,178,202,255,251,250,250,252,190,208,189,147,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,154, - 173,207,165,248,252,250,250,250,250,247,178,209,160,98,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,151,157,214,179,208,252,252,252,252,252,252,253,191,217,201,155,29,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,154,188, - 207,173,255,240,233,233,233,233,233,243,250,182,218,167,122,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,151,159,221,172,238,246,144,87,87,86,86,94,158,245,241,178,211,158,55, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,155,156,209,195, - 200,255,244,112,122,122,120,118,114,136,235,248,185,225,184,135,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,154,172,230,177,243,254,244,116,118,118,117,114,110,136,234,248,237,184,230,161, - 80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,147,156,231,204,210, - 254,251,245,119,114,114,112,109,101,139,237,245,243,188,236,205,149,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,154,187,237,184,247,250,251,245,122,108,109,104,101,88,140,241,244,243,234,188,243, - 166,106,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,149,157,243,204,215,252, - 248,249,246,123,99,101,97,92,77,139,243,241,240,239,183,241,228,157,28,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,156,206,219,202,250,248,247,249,246,127,91,92,88,83,67,137,244,240,238,239,231,183, - 248,180,123,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,152,164,249,190,240,249,247, - 247,248,244,128,83,82,77,75,65,140,241,238,237,237,238,195,222,240,159,61,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,155,155,225,213,208,250,247,246,246,247,245,130,73,71,71,72,66,147,240,238,237,237,237,233, - 179,246,196,140,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,154,178,243,182,243,248,246,245, - 245,245,245,130,60,62,65,71,70,154,241,238,236,236,235,235,220,186,245,162,80,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,150,156,236,202,212,250,245,245,244,243,244,241,130,53,60,66,72,75,158,241,237,235,235,234,234, - 231,176,239,209,150,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,154,192,230,185,247,245,244,244,243, - 241,241,243,126,20,30,40,51,59,154,234,233,231,231,231,231,233,224,178,239,167,109,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,150,159,236,181,235,247,243,243,239,237,235,235,233,124,0,0,17,37,55,154,231,229,229,229,229,229, - 229,229,188,215,219,157,38,0,0,0,0,0,0,0,0,0,0,0,0,0,0,155,155,203,200,194,243,238,236,234,231,231, - 231,231,233,134,0,8,30,51,76,163,231,230,229,229,229,229,229,229,221,174,229,179,122,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,152,166,226,174,231,236,234,233,233,231,231,231,230,234,146,0,14,38,60,89,168,231,229,229,229,229,229, - 227,227,228,186,204,219,159,60,0,0,0,0,0,0,0,0,0,0,0,0,147,155,212,187,196,238,234,233,231,231,230,230, - 230,230,234,159,0,13,39,62,101,168,231,229,229,229,228,228,227,226,227,224,169,221,186,141,0,0,0,0,0,0,0,0, - 0,0,0,0,154,178,214,167,231,235,233,231,230,230,230,230,230,230,232,186,13,30,54,77,93,175,231,229,229,228,227,227, - 227,226,226,226,214,171,218,160,92,0,0,0,0,0,0,0,0,0,0,149,156,214,177,201,236,231,230,230,230,230,230,230, - 230,230,231,226,215,215,215,215,215,225,228,228,228,227,226,226,226,225,224,224,224,167,213,195,151,8,0,0,0,0,0,0, - 0,0,0,155,192,185,183,235,231,230,230,230,230,230,230,230,230,230,229,233,231,208,179,210,234,231,228,228,227,226,226,226, - 225,225,224,224,225,218,165,211,166,108,0,0,0,0,0,0,0,0,153,160,208,161,223,234,230,230,230,230,230,230,229,229, - 229,229,229,235,148,45,46,78,165,230,228,227,226,226,226,225,224,224,224,224,224,225,181,192,197,157,38,0,0,0,0,0, - 0,155,155,198,175,182,236,231,230,230,230,230,230,230,229,229,229,229,230,185,16,12,43,64,89,194,227,226,226,226,225,224, - 224,224,224,224,224,226,220,164,204,172,129,0,0,0,0,0,0,153,167,197,157,230,234,233,231,231,230,231,231,230,230,231, - 231,231,231,138,0,27,55,80,93,167,229,228,227,226,226,226,226,226,226,226,226,226,227,185,184,198,158,62,0,0,0,0, - 150,155,198,165,193,238,234,234,234,233,234,233,233,231,233,233,234,234,233,179,17,33,68,93,109,176,234,229,228,228,228,227, - 227,227,227,228,228,228,228,229,164,196,177,140,0,0,0,0,154,177,188,161,239,237,237,236,236,236,236,236,236,236,237,237, - 236,236,238,237,121,50,75,107,139,210,236,233,233,231,231,231,231,231,231,231,233,233,233,236,194,180,195,159,91,0,0,150, - 157,197,158,204,245,240,240,240,240,241,241,241,241,241,241,243,241,241,241,244,239,184,150,173,215,238,238,237,237,237,236,236, - 237,237,237,237,238,238,239,239,241,166,189,183,154,16,0,157,186,183,183,243,238,238,238,238,237,238,237,238,238,238,238,238, - 238,238,237,236,238,240,235,234,236,235,234,234,234,233,233,233,233,234,234,235,236,236,237,237,239,231,176,190,163,110,0,160, - 196,187,194,170,167,169,169,170,172,175,176,177,178,181,183,184,186,187,188,190,190,191,193,192,191,191,190,189,187,186,185,183, - 179,178,177,176,175,172,171,170,169,167,193,189,185,114,0,117,186,189,189,190,192,192,193,195,198,203,207,211,216,220,225,229, - 234,238,241,245,248,250,252,252,251,249,246,241,239,234,230,226,220,217,211,207,203,200,196,193,192,192,192,192,169,87,0,28, - 107,108,108,108,108,108,108,109,109,110,110,111,112,113,113,114,114,115,116,116,117,117,117,117,116,115,114,113,112,112,111,110, - 110,109,108,107,106,106,105,105,104,104,105,105,89,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,156,174,179,153,115,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,157,167,182,188,174,119,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,153,168,193,188,194,158,91,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,150,157,196,182,190,193,187,154,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,154,179,190,176,228,175,196,162,108,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,150,157,202,153,220,255,238,165,193,157,52,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,156,193,177,183,250,248,248,182,203,174,134,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 153,165,205,159,235,250,246,246,240,172,203,159,81,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,155,156,205,178,199,252,246,245,243,244,183,209,189,147,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,154, - 173,208,164,241,246,244,243,241,241,235,176,210,160,98,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,151,157,214,179,204,246,245,245,245,245,245,243,180,217,201,155,29,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,154,188, - 207,171,247,233,226,226,226,226,226,235,234,177,219,167,122,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,151,159,221,171,230,239,142,87,87,86,86,94,153,228,225,177,212,158,55, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,155,156,209,196, - 195,247,236,112,122,122,120,118,115,132,218,227,175,227,184,135,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,154,172,230,176,234,243,235,115,118,118,117,114,110,131,215,228,215,178,231,161, - 80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,147,156,231,204,204, - 243,239,235,117,115,114,112,109,102,133,217,224,218,171,237,205,149,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,154,187,237,180,236,237,237,234,119,108,109,104,101,91,133,217,220,218,206,178,245, - 166,106,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,149,157,244,204,205,238, - 234,235,234,121,99,101,97,92,80,129,218,217,215,210,161,241,228,157,28,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,156,206,219,198,236,233,231,233,234,122,91,92,88,83,70,126,217,214,210,209,198,168, - 250,180,123,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,152,164,249,189,228,234,231, - 230,230,233,123,85,82,77,75,66,128,213,209,207,206,205,165,219,241,159,61,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,155,155,225,214,201,234,230,229,227,227,231,122,73,71,71,72,67,134,210,208,205,203,201,193, - 161,248,196,140,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,154,178,243,180,227,230,228,226, - 225,224,229,120,61,62,65,71,71,137,208,205,201,199,197,197,177,178,247,162,80,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,150,156,236,202,202,231,226,225,223,221,220,217,117,54,60,66,73,76,139,207,200,198,196,195,193, - 186,148,240,210,150,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,154,192,230,178,229,226,225,223,220, - 218,216,216,112,23,30,40,51,60,132,188,192,192,189,187,186,186,172,165,243,167,109,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,150,159,236,180,220,227,223,218,213,208,205,203,196,108,0,0,17,38,57,128,182,185,184,182,180,178, - 177,176,151,215,220,157,38,0,0,0,0,0,0,0,0,0,0,0,0,0,0,155,155,203,201,186,218,211,206,203,200,197, - 196,195,196,115,0,8,30,51,77,134,182,183,180,179,177,177,176,175,165,152,233,179,122,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,152,166,226,171,208,204,201,200,199,197,196,194,193,196,123,0,14,38,60,91,135,181,180,178,177,176,175, - 173,173,173,140,201,220,159,60,0,0,0,0,0,0,0,0,0,0,0,0,147,155,212,190,182,206,201,199,198,196,194,194, - 193,193,195,131,0,14,39,62,102,135,181,178,177,175,174,173,173,172,170,164,143,224,186,141,0,0,0,0,0,0,0,0, - 0,0,0,0,154,178,214,164,203,200,199,197,196,194,193,192,192,190,193,150,14,33,55,77,93,137,180,177,175,173,173,173, - 170,169,168,168,156,161,220,160,92,0,0,0,0,0,0,0,0,0,0,149,156,214,177,181,201,197,196,194,194,193,192,190, - 189,188,187,177,167,166,166,166,166,173,174,175,173,172,172,170,168,167,167,166,163,133,214,195,151,8,0,0,0,0,0,0, - 0,0,0,155,192,187,172,200,197,194,193,193,192,192,188,188,187,186,183,184,185,164,143,164,183,177,174,173,172,169,169,168, - 167,167,165,164,164,155,150,215,166,108,0,0,0,0,0,0,0,0,153,160,209,160,194,196,194,193,192,192,189,188,187,185, - 184,182,182,185,118,43,47,76,131,175,174,170,169,168,168,167,165,165,164,164,164,163,140,191,197,157,38,0,0,0,0,0, - 0,155,155,198,176,167,197,194,193,193,190,189,187,187,186,183,183,182,185,146,16,13,43,66,89,150,172,170,169,168,167,166, - 165,165,165,165,165,166,157,140,208,173,129,0,0,0,0,0,0,153,167,199,152,197,197,194,194,193,190,188,188,187,186,184, - 183,183,186,112,0,27,55,80,95,135,174,173,172,170,169,168,168,168,168,168,168,168,169,138,176,201,158,62,0,0,0,0, - 150,155,199,165,172,203,198,197,195,195,194,193,192,192,189,188,187,187,188,144,19,33,68,95,111,140,180,178,177,175,175,175, - 175,175,175,175,175,175,176,173,131,198,177,140,0,0,0,0,154,177,190,152,207,206,204,203,201,200,199,199,197,197,197,196, - 195,195,195,194,103,50,76,108,123,167,189,186,185,185,185,185,185,185,185,185,185,185,186,188,152,169,197,159,91,0,0,151, - 157,197,157,185,216,213,211,211,210,209,209,208,207,208,207,206,206,205,205,206,200,157,132,147,178,197,198,197,197,196,196,196, - 196,196,197,197,197,198,198,198,200,138,187,183,154,16,0,156,186,185,173,214,209,209,208,207,206,206,205,204,204,204,204,203, - 203,203,201,199,200,201,196,195,197,196,195,195,195,195,194,195,195,195,195,197,197,198,198,198,200,189,158,193,163,110,0,160, - 196,187,192,158,149,152,152,153,155,156,157,159,160,162,164,166,168,170,171,171,171,173,174,174,173,172,171,171,170,168,166,164, - 162,160,159,158,156,155,153,152,150,150,188,189,185,114,0,117,186,189,190,192,194,194,195,197,201,205,209,214,218,223,227,231, - 236,240,244,247,250,254,255,255,254,251,248,245,241,236,233,228,223,219,215,209,205,203,198,195,194,194,192,192,169,87,0,28, - 107,108,108,108,108,108,108,109,109,110,110,111,112,113,113,114,114,115,116,116,117,117,117,117,116,115,114,113,112,112,111,110, - 110,109,108,107,106,106,105,105,104,104,105,105,89,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,153,175,179,154,116,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,158,166,183,189,175,120,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,155,168,196,198,196,159,92,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,150,157,198,179,136,190,189,155,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,154,179,203,116,0,114,210,163,109,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,150,157,205,161,57,0,50,164,196,158,52,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,156,193,189,114,5,0,0,101,219,175,135,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 153,165,210,150,44,0,3,0,22,149,212,160,81,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,155,156,206,190,92,0,3,6,9,0,81,224,191,148,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,154, - 174,216,143,26,0,9,10,12,12,26,148,220,161,99,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,151,157,216,187,79,7,9,11,12,12,13,11,62,224,203,156,29,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,154,188, - 219,125,19,10,12,13,13,13,14,14,23,125,230,168,122,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,151,159,226,165,60,9,77,91,88,87,87,104,66,21,62,173,216,159,55, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,155,156,210,209, - 116,11,15,101,129,124,123,122,129,75,29,30,116,238,186,136,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,154,172,237,159,48,14,18,94,124,118,117,114,123,68,31,37,48,161,236,162, - 81,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,147,156,232,213,98, - 16,24,20,91,122,114,112,109,114,66,34,43,30,96,249,206,150,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,154,187,247,153,37,23,31,21,86,115,109,104,101,103,62,36,42,38,43,157,251, - 167,107,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,149,157,248,207,86,23, - 32,34,23,81,109,101,97,92,92,56,36,42,40,26,68,248,231,158,28,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,156,207,230,146,34,31,36,38,24,73,101,92,88,85,83,52,36,40,36,35,24,130, - 255,181,124,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,152,164,254,179,68,29,38, - 40,42,24,69,93,82,77,75,77,48,33,36,34,31,21,43,217,245,160,62,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,155,155,226,224,119,31,38,41,42,42,24,63,85,71,71,72,77,48,31,32,30,26,24,10, - 107,255,197,141,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,154,178,250,163,58,35,42,42, - 43,43,24,56,73,62,65,71,78,45,26,27,25,23,21,13,17,165,253,163,80,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,150,156,238,208,98,35,41,42,43,43,43,35,48,66,60,66,73,83,42,23,24,21,19,15,13, - 0,71,248,211,151,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,154,193,239,136,46,38,43,45,44, - 42,41,33,35,35,30,40,53,66,31,6,12,10,9,9,7,5,0,131,251,168,109,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,150,159,241,178,83,36,42,38,31,25,21,17,11,22,0,0,17,39,62,22,1,2,1,1,1,1, - 1,0,49,222,222,158,38,0,0,0,0,0,0,0,0,0,0,0,0,0,0,155,156,204,211,127,26,21,16,12,10,10, - 11,10,9,21,0,8,30,53,80,20,1,1,1,1,0,1,0,0,0,111,241,180,123,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,152,166,231,160,44,2,9,10,12,12,12,11,10,9,19,1,14,38,62,92,17,1,0,0,0,0,0, - 1,2,0,22,198,224,160,60,0,0,0,0,0,0,0,0,0,0,0,0,147,155,213,200,91,3,11,12,12,12,12,11, - 10,9,8,15,2,16,40,66,104,11,1,0,0,0,0,1,1,3,3,0,91,234,187,142,0,0,0,0,0,0,0,0, - 0,0,0,0,154,178,221,138,27,6,12,12,12,12,11,10,9,7,8,7,22,35,59,83,89,2,1,0,0,0,1,2, - 3,3,5,2,12,150,225,161,92,0,0,0,0,0,0,0,0,0,0,149,156,218,180,63,5,12,12,12,11,10,9,9, - 6,6,4,1,1,1,1,2,1,0,2,0,0,1,2,3,3,5,6,7,0,59,219,198,152,8,0,0,0,0,0,0, - 0,0,0,155,193,196,111,10,10,12,12,11,10,9,9,6,5,3,3,2,4,4,11,1,1,0,0,0,0,2,3,4, - 4,6,7,7,6,0,119,224,167,108,0,0,0,0,0,0,0,0,153,160,214,153,40,5,12,11,11,10,9,7,6,5, - 4,3,1,0,10,34,52,66,20,0,0,0,2,3,4,5,6,7,7,7,9,0,48,196,200,157,38,0,0,0,0,0, - 0,155,155,199,185,92,7,12,12,12,11,11,10,7,6,5,4,3,4,4,16,20,44,72,88,13,2,4,5,7,9,9, - 10,11,11,11,11,10,0,97,218,174,130,0,0,0,0,0,0,153,167,207,128,34,15,20,19,19,17,16,15,14,13,12, - 11,10,5,20,10,27,55,81,101,38,4,13,14,15,16,17,17,17,17,17,17,17,11,27,167,206,159,63,0,0,0,0, - 150,155,201,166,65,26,33,33,33,32,31,31,30,29,27,27,25,25,10,25,21,36,68,97,112,36,26,30,31,32,33,33, - 33,33,33,32,32,32,31,17,67,205,178,141,0,0,0,0,154,177,199,110,47,53,54,54,54,53,52,52,51,50,50,48, - 48,48,47,47,43,53,80,109,72,41,52,53,54,54,54,54,54,54,54,54,53,53,53,51,42,152,203,160,92,0,0,150, - 157,201,153,81,74,78,78,77,77,77,77,77,76,76,76,75,75,75,75,75,73,67,67,65,65,76,78,78,78,80,80,80, - 80,80,78,78,78,77,77,77,72,73,189,185,155,16,0,157,187,193,129,83,87,88,87,88,88,87,87,87,87,87,86,86, - 85,85,85,85,86,85,82,83,86,87,87,88,88,88,88,88,89,89,88,88,89,88,88,88,88,77,130,198,164,111,0,161, - 197,189,184,135,125,128,128,129,131,131,133,135,136,139,141,142,143,144,147,148,149,149,150,150,149,149,148,147,145,143,142,141, - 139,137,136,134,132,131,129,128,127,126,183,192,186,115,0,117,187,190,193,197,199,199,200,203,206,210,214,218,223,228,231,237, - 240,245,249,251,255,255,255,255,255,255,252,249,246,241,237,233,227,224,219,215,210,207,204,200,199,199,194,192,170,88,0,28, - 108,109,109,109,109,109,109,109,110,110,111,112,113,114,114,115,115,116,116,117,117,117,118,118,117,116,115,114,113,113,112,111, - 110,109,109,108,107,107,106,105,105,105,106,106,90,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, - {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,31,159,208,154,52,7,1,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,6,137,255,255,254,146,29,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,101,250,255,255,255,249,117,20,2,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,28,249,255,255,255,255,255,246,61,13,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,182,253,255,255,255,255,255,248,165,34,4,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,54,248,255,255,255,255,255,255,255,250,83,17,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,219,255,255,255,255,255,255,255,255,252,212,42,8,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 111,249,255,255,255,255,255,255,255,255,255,251,121,24,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,242,255,255,255,255,255,255,255,255,255,255,254,234,51,11,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,154, - 248,255,255,255,255,255,255,255,255,255,255,255,249,151,30,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,37,249,255,255,255,255,255,255,255,255,255,255,255,255,255,246,67,15, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,198,253, - 255,255,255,255,255,255,255,255,255,255,255,255,255,249,185,37,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,83,247,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,250,88, - 19,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,229,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,252,213,43,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,125,249,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,252, - 122,25,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,19,245,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,236,54,11,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,169,247,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 249,162,31,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,50,250,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,247,70,16,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,216,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,251,192,38,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,97,248,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,251,94,20,1,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,12,240,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,252,222,45,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,152,249,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,251,124,26,2,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,28,245,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,254,236,54,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,184,249,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,250,165,32,4,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,62,245,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,249,76,16,1,0,0,0,0,0,0,0,0,0,0,0,0,3,224,253,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,251,194,39,6,0,0,0,0,0,0,0, - 0,0,0,0,0,113,247,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,252,97,21,1,0,0,0,0,0,0,0,0,0,0,19,244,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,253,223,46,9,0,0,0,0,0,0, - 0,0,0,0,165,248,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,251,136,27,3,0,0,0,0,0,0,0,0,50,248,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,241,57,13,0,0,0,0,0, - 0,0,0,211,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,252,167,33,4,0,0,0,0,0,0,76,242,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,249,76,17,1,0,0,0, - 0,6,234,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,252,203,40,7,0,0,0,0,129,245,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,251,101,22,1,0,0, - 28,246,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,253,224,47,9,0,0,178,248,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,251,138,27,3,33, - 247,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,244,61,13,184,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,251,175,34,179, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,198,58,169,228,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,245,187,70,44, - 188,228,234,235,235,235,235,235,235,234,234,234,234,234,234,234,234,234,234,234,234,234,234,234,234,234,233,233,233,233,233,232, - 232,232,232,232,232,232,231,231,231,231,231,231,209,135,60,7,31,63,81,85,86,86,86,86,86,86,86,86,86,86,86,86, - 86,86,86,86,86,86,86,86,86,85,85,85,85,85,85,85,85,85,85,84,84,84,84,84,84,84,84,84,81,65,34,1, - 7,18,25,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27, - 26,26,26,26,26,26,26,26,26,26,26,26,25,19,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} -} -}; - -static LCUI_BOOL msgbox_list_init = FALSE; -static LCUI_Queue msgbox_list; - -static int LoadMsgIcon( LCUI_Graph *buff, int img_res_id ) -{ - if( img_res_id >= IMG_TOTAL_NUM ) { - return -1; - } - if( Graph_IsValid( buff ) ) { - Graph_Free( buff ); - } - Graph_Init( buff ); - buff->color_type = COLOR_TYPE_ARGB;; - buff->alpha = 255; - if( Graph_Create( buff, 48, 48 ) != 0 ) { - return -2; - } - Graph_SetRedBits( buff, msgbox_icon[img_res_id][0], 48*48 ); - Graph_SetGreenBits( buff, msgbox_icon[img_res_id][1], 48*48 ); - Graph_SetBlueBits( buff, msgbox_icon[img_res_id][2], 48*48 ); - Graph_SetAlphaBits( buff, msgbox_icon[img_res_id][3], 48*48 ); - return 0; -} - -static LCUI_MainLoop* -msgbox_mainloop_new( LCUI_Widget msgbox ) -{ - MB_data *data; - if( !msgbox_list_init ) { - Queue_Init( &msgbox_list, sizeof(MB_data), NULL ); - msgbox_list_init = TRUE; - } - - data = (MB_data*)malloc( sizeof(MB_data) ); - if( data == NULL ) { - return NULL; - } - - data->msgbox = msgbox; - data->mainloop = LCUI_MainLoop_New(); - Queue_InsertPointer( &msgbox_list, 0, data ); - return data->mainloop; -} - -static MB_data * -msgbox_data_find( LCUI_Widget msgbox ) -{ - int i, n; - MB_data *data; - n = Queue_GetTotal( &msgbox_list ); - for(i=0; imsgbox == msgbox ) { - return data; - } - } - return NULL; -} - -static int -msgbox_data_delete( LCUI_Widget msgbox ) -{ - int i, n; - MB_data *data; - n = Queue_GetTotal( &msgbox_list ); - for(i=0; imsgbox == msgbox ) { - Queue_Delete( &msgbox_list, i ); - return 0; - } - } - return -1; -} - -static void -msgbox_mainloop_quit( LCUI_Widget btn, LCUI_WidgetEvent *unused ) -{ - LCUI_Widget msgbox; - MB_data *data; - - msgbox = Widget_GetParent( btn, "window" ); - data = msgbox_data_find( msgbox ); - if( !data ) { - return; - } - data->clicked_button = btn->self_id; - LCUI_MainLoop_Quit( data->mainloop ); -} - -/* 响应用于显示文本的label部件的尺寸变动,并自动调整消息框的尺寸 */ -static void -auto_resize_msgbox(LCUI_Widget textlabel, LCUI_WidgetEvent *event ) -{ - int area_height; - LCUI_Widget msgbox, *msg_area; - LCUI_Size msgbox_size; - - msgbox = Widget_GetParent( textlabel, "window" ); - if( !msgbox ) { - return; - } - if( (msgbox->self_id & WIDGET_ID_MESSAGEBOX) != WIDGET_ID_MESSAGEBOX ) { - return; - } - /* 以下只是估算消息框的尺寸,不要纠结 为何要+=14、为何要+=30 等之类的问题 */ - if( (msgbox->self_id & MSGBOX_NONE_ICON) == MSGBOX_NONE_ICON ) { - msgbox_size.h = area_height = MB_MSG_AREA_HEIGHT; - msgbox_size.w = 0; - } else { - msgbox_size = MB_ICONBOX_SIZE; - } - msgbox_size.w += 14; - msgbox_size.w += event->resize.new_size.w; - area_height = msgbox_size.h; - if( area_height < event->resize.new_size.h ) { - area_height = event->resize.new_size.h; - } - if( area_height < MB_MSG_AREA_HEIGHT ) { - area_height = MB_MSG_AREA_HEIGHT; - } - - DEBUG_MSG("area_height: %d\n", area_height); - /* 加上按钮区域的固定高度 */ - msgbox_size.h = area_height + MB_BTN_AREA_HEIGHT; - /* 加上窗口边框尺寸 */ - msgbox_size.w += 14; - msgbox_size.h += 30; - - DEBUG_MSG("widget: %p, old size: (%d,%d), new size: (%d,%d)\n", - textlabel, - event->resize.old_size.w, event->resize.old_size.h, - event->resize.new_size.w, event->resize.new_size.h); - DEBUG_MSG("msgbox size: (%d,%d)\n", msgbox_size.w, msgbox_size.h); - - /* 获取消息框内的消息区域的指针 */ - msg_area = Widget_GetChildByID( Window_GetClientArea(msgbox), - WIDGET_ID_MB_MSG_AREA ); - if( !msg_area ) { - return; - } - Widget_SetHeight( msg_area, area_height ); - Widget_Resize( msgbox, msgbox_size ); -} - -static void -msgbox_add_BTN_OK( LCUI_Widget btn_area ) -{ - LCUI_Widget btn; - btn = Widget_New("button"); - btn->self_id = MB_BTN_IS_OK; - Widget_Resize( btn, MB_BTN_SIZE ); - Widget_SetAutoSize( btn, FALSE, 0 ); - Button_TextW( btn, TEXT_MB_BTN_OK ); - Widget_Container_Add( btn_area, btn ); - Widget_SetAlign( btn, ALIGN_MIDDLE_CENTER, Pos(0,0) ); - Widget_ConnectEvent( btn, EVENT_CLICKED, msgbox_mainloop_quit ); - Widget_Show( btn ); -} - -static void -msgbox_add_BTN_OKCANCEL( LCUI_Widget btn_area ) -{ - LCUI_Size btn_size; - LCUI_Widget btn[2]; - btn[0] = Widget_New("button"); - btn[1] = Widget_New("button"); - btn[0]->self_id = MB_BTN_IS_OK; - btn[1]->self_id = MB_BTN_IS_CANCEL; - Widget_Resize( btn[0], MB_BTN_SIZE ); - Widget_Resize( btn[1], MB_BTN_SIZE ); - Widget_SetAutoSize( btn[0], FALSE, 0 ); - Widget_SetAutoSize( btn[1], FALSE, 0 ); - Button_TextW( btn[0], TEXT_MB_BTN_OK ); - Button_TextW( btn[1], TEXT_MB_BTN_CANCEL ); - Widget_Container_Add( btn_area, btn[0] ); - Widget_Container_Add( btn_area, btn[1] ); - btn_size = MB_BTN_SIZE; - Widget_SetAlign( btn[0], ALIGN_MIDDLE_CENTER, Pos(0-(btn_size.w/2.0+3),0) ); - Widget_SetAlign( btn[1], ALIGN_MIDDLE_CENTER, Pos((btn_size.w/2.0+3),0) ); - Widget_ConnectEvent( btn[0], EVENT_CLICKED, msgbox_mainloop_quit ); - Widget_ConnectEvent( btn[1], EVENT_CLICKED, msgbox_mainloop_quit ); - Widget_Show( btn[0] ); - Widget_Show( btn[1] ); -} - -static void -msgbox_add_BTN_ABORTRETRYIGNORE( LCUI_Widget btn_area ) -{ - LCUI_Size btn_size; - LCUI_Widget btn[3]; - btn[0] = Widget_New("button"); - btn[1] = Widget_New("button"); - btn[2] = Widget_New("button"); - btn[0]->self_id = MB_BTN_IS_ABORT; - btn[1]->self_id = MB_BTN_IS_RETRY; - btn[2]->self_id = MB_BTN_IS_IGNORE; - Widget_Resize( btn[0], MB_BTN_SIZE ); - Widget_Resize( btn[1], MB_BTN_SIZE ); - Widget_Resize( btn[2], MB_BTN_SIZE ); - Widget_SetAutoSize( btn[0], FALSE, 0 ); - Widget_SetAutoSize( btn[1], FALSE, 0 ); - Widget_SetAutoSize( btn[2], FALSE, 0 ); - Button_TextW( btn[0], TEXT_MB_BTN_ABORT ); - Button_TextW( btn[1], TEXT_MB_BTN_RETRY ); - Button_TextW( btn[2], TEXT_MB_BTN_IGNORE ); - Widget_Container_Add( btn_area, btn[0] ); - Widget_Container_Add( btn_area, btn[1] ); - Widget_Container_Add( btn_area, btn[2] ); - btn_size = MB_BTN_SIZE; - Widget_SetAlign( btn[0], ALIGN_MIDDLE_CENTER, Pos(0-(btn_size.w+3),0) ); - Widget_SetAlign( btn[1], ALIGN_MIDDLE_CENTER, Pos(0,0) ); - Widget_SetAlign( btn[2], ALIGN_MIDDLE_CENTER, Pos((btn_size.w+3),0) ); - Widget_ConnectEvent( btn[0], EVENT_CLICKED, msgbox_mainloop_quit ); - Widget_ConnectEvent( btn[1], EVENT_CLICKED, msgbox_mainloop_quit ); - Widget_ConnectEvent( btn[2], EVENT_CLICKED, msgbox_mainloop_quit ); - Widget_Show( btn[0] ); - Widget_Show( btn[1] ); - Widget_Show( btn[2] ); -} - -static void -msgbox_add_BTN_RETRYCANCEL( LCUI_Widget btn_area ) -{ - LCUI_Size btn_size; - LCUI_Widget btn[3]; - btn[0] = Widget_New("button"); - btn[1] = Widget_New("button"); - btn[0]->self_id = MB_BTN_IS_RETRY; - btn[1]->self_id = MB_BTN_IS_CANCEL; - Widget_Resize( btn[0], MB_BTN_SIZE ); - Widget_Resize( btn[1], MB_BTN_SIZE ); - Widget_SetAutoSize( btn[0], FALSE, 0 ); - Widget_SetAutoSize( btn[1], FALSE, 0 ); - Button_TextW( btn[0], TEXT_MB_BTN_RETRY ); - Button_TextW( btn[1], TEXT_MB_BTN_CANCEL ); - Widget_Container_Add( btn_area, btn[0] ); - Widget_Container_Add( btn_area, btn[1] ); - btn_size = MB_BTN_SIZE; - Widget_SetAlign( btn[0], ALIGN_MIDDLE_CENTER, Pos(0-(btn_size.w/2.0+3),0) ); - Widget_SetAlign( btn[1], ALIGN_MIDDLE_CENTER, Pos((btn_size.w/2.0+3),0) ); - Widget_ConnectEvent( btn[0], EVENT_CLICKED, msgbox_mainloop_quit ); - Widget_ConnectEvent( btn[1], EVENT_CLICKED, msgbox_mainloop_quit ); - Widget_Show( btn[0] ); - Widget_Show( btn[1] ); -} - -static void -msgbox_add_BTN_YESNO( LCUI_Widget btn_area ) -{ - LCUI_Size btn_size; - LCUI_Widget btn[2]; - btn[0] = Widget_New("button"); - btn[1] = Widget_New("button"); - btn[0]->self_id = MB_BTN_IS_YES; - btn[1]->self_id = MB_BTN_IS_NO; - Widget_Resize( btn[0], MB_BTN_SIZE ); - Widget_Resize( btn[1], MB_BTN_SIZE ); - Widget_SetAutoSize( btn[0], FALSE, 0 ); - Widget_SetAutoSize( btn[1], FALSE, 0 ); - Button_TextW( btn[0], TEXT_MB_BTN_YES ); - Button_TextW( btn[1], TEXT_MB_BTN_NO ); - Widget_Container_Add( btn_area, btn[0] ); - Widget_Container_Add( btn_area, btn[1] ); - btn_size = MB_BTN_SIZE; - Widget_SetAlign( btn[0], ALIGN_MIDDLE_CENTER, Pos(0-(btn_size.w/2.0+3),0) ); - Widget_SetAlign( btn[1], ALIGN_MIDDLE_CENTER, Pos((btn_size.w/2.0+3),0) ); - Widget_ConnectEvent( btn[0], EVENT_CLICKED, msgbox_mainloop_quit ); - Widget_ConnectEvent( btn[1], EVENT_CLICKED, msgbox_mainloop_quit ); - Widget_Show( btn[0] ); - Widget_Show( btn[1] ); -} - -static void -msgbox_add_BTN_YESNOCANCEL( LCUI_Widget btn_area ) -{ - LCUI_Size btn_size; - LCUI_Widget btn[3]; - btn[0] = Widget_New("button"); - btn[1] = Widget_New("button"); - btn[2] = Widget_New("button"); - btn[0]->self_id = MB_BTN_IS_YES; - btn[1]->self_id = MB_BTN_IS_NO; - btn[2]->self_id = MB_BTN_IS_CANCEL; - Widget_Resize( btn[0], MB_BTN_SIZE ); - Widget_Resize( btn[1], MB_BTN_SIZE ); - Widget_Resize( btn[2], MB_BTN_SIZE ); - Widget_SetAutoSize( btn[0], FALSE, 0 ); - Widget_SetAutoSize( btn[1], FALSE, 0 ); - Widget_SetAutoSize( btn[2], FALSE, 0 ); - Button_TextW( btn[0], TEXT_MB_BTN_YES ); - Button_TextW( btn[1], TEXT_MB_BTN_NO ); - Button_TextW( btn[2], TEXT_MB_BTN_CANCEL ); - Widget_Container_Add( btn_area, btn[0] ); - Widget_Container_Add( btn_area, btn[1] ); - Widget_Container_Add( btn_area, btn[2] ); - btn_size = MB_BTN_SIZE; - Widget_SetAlign( btn[0], ALIGN_MIDDLE_CENTER, Pos(0-(btn_size.w+3),0) ); - Widget_SetAlign( btn[1], ALIGN_MIDDLE_CENTER, Pos(0,0) ); - Widget_SetAlign( btn[2], ALIGN_MIDDLE_CENTER, Pos((btn_size.w+3),0) ); - Widget_ConnectEvent( btn[0], EVENT_CLICKED, msgbox_mainloop_quit ); - Widget_ConnectEvent( btn[1], EVENT_CLICKED, msgbox_mainloop_quit ); - Widget_ConnectEvent( btn[2], EVENT_CLICKED, msgbox_mainloop_quit ); - Widget_Show( btn[0] ); - Widget_Show( btn[1] ); - Widget_Show( btn[2] ); -} - - -/* LCUI的消息框 - * 参数: - * icon_type : 指定消息框中显示的图标,可取以下值: - * MB_ICON_NONE 无图标 - * MB_ICON_ERROR “错误”图标 - * MB_ICON_HELP ”帮助“图标 - * MB_ICON_INFO “信息”图标 - * MB_ICON_WARNING “警告”图标 - * text : 消息框内显示的消息内容 - * title : 消息框的标题文本 - * button : 指定消息框内显示的按钮,可取以下值: - * MB_BTN_OK : 一个“确定”按钮 - * MB_BTN_OKCANCEL : “确定”和“取消”按钮 - * MB_BTN_ABORTRETRYIGNORE : “终止”、"重试"和“忽略”按钮 - * MB_BTN_RETRYCANCEL : "重试"和“取消”按钮 - * MB_BTN_YESNO : "是"和“否”按钮 - * MB_BTN_YESNOCANCEL : “是”、"否"和“取消”按钮 - * 返回值: - * -1 : button参数的值异常 - * -2 : 无法获取消息框关闭时所点击的按钮ID - * 正常则会返回按钮的ID,有以下值: - * MB_BTN_IS_OK : "确定"按钮 - * MB_BTN_IS_CANCEL: "取消"按钮 - * MB_BTN_IS_ABORT : "终止"按钮 - * MB_BTN_IS_RETRY : "重试"按钮 - * MB_BTN_IS_IGNORE: "忽略"按钮 - * MB_BTN_IS_YES : "是"按钮 - * MB_BTN_IS_NO : "否"按钮 - * MB_BTN_IS_QUIT : 窗口右上角的关闭按钮 - * */ -LCUI_API int -LCUI_MessageBoxW( MB_ICON_TYPE icon_type, const wchar_t *text, - const wchar_t *title, MB_BTN_TYPE button ) -{ - int ret, icon_flag; - LCUI_Graph icon; - LCUI_MainLoop *loop; - MB_data *msgbox_data; - LCUI_Border btn_area_border; - LCUI_Widget iconbox, *textbox, *msgbox; - LCUI_Widget btn_close; - LCUI_Widget msg_area, *btn_area; - LCUI_Size min_size, max_size; - - iconbox = Widget_New("picture_box"); - textbox = Label_New(); - msg_area = Widget_New(NULL); - btn_area = Widget_New(NULL); - msg_area->self_id = WIDGET_ID_MB_MSG_AREA; - - Graph_Init( &icon ); - /* 根据参数的值,载入相应的图标 */ - switch(icon_type) { - case MB_ICON_ERROR: - LoadMsgIcon( &icon, IMG_ID_ERROR ); - break; - case MB_ICON_HELP: - LoadMsgIcon( &icon, IMG_ID_HELP ); - break; - case MB_ICON_INFO: - LoadMsgIcon( &icon, IMG_ID_INFO ); - break; - case MB_ICON_WARNING: - LoadMsgIcon( &icon, IMG_ID_WARNING ); - break; - case MB_ICON_NONE: - default:break; - } - /* 添加图标后文本进消息区域 */ - Widget_Container_Add( msg_area, iconbox ); - Widget_Container_Add( msg_area, textbox ); - /* 设定图标框的默认尺寸 */ - Widget_Resize( iconbox, MB_ICONBOX_SIZE ); - /* 为图标框设置需显示的图标 */ - PictureBox_SetImage( iconbox, &icon ); - PictureBox_SetSizeMode( iconbox, SIZE_MODE_CENTER ); - /* 判断是否有图标,并调整文本位置 */ - if( icon_type == MB_ICON_NONE ) { - icon_flag = MSGBOX_NONE_ICON; - Widget_SetAlign( textbox, ALIGN_MIDDLE_CENTER, Pos(0,0) ); - } else { - icon_flag = 0; - Widget_SetAlign( iconbox, ALIGN_MIDDLE_LEFT, Pos(5,0) ); - Widget_SetAlign( textbox, ALIGN_MIDDLE_LEFT, - Pos(icon.w + 10,0) ); - } - /* 根据按钮数量,得出相应的最小尺寸 */ - switch( button ) { - case MB_BTN_OK: - msgbox_add_BTN_OK( btn_area ); - min_size = Size(150,125); - break; - case MB_BTN_OKCANCEL: - msgbox_add_BTN_OKCANCEL( btn_area ); - min_size = Size(180,125); - break; - case MB_BTN_ABORTRETRYIGNORE: - msgbox_add_BTN_ABORTRETRYIGNORE( btn_area ); - min_size = Size(215,125); - break; - case MB_BTN_RETRYCANCEL: - msgbox_add_BTN_RETRYCANCEL( btn_area ); - min_size = Size(180,125); - break; - case MB_BTN_YESNO: - msgbox_add_BTN_YESNO( btn_area ); - min_size = Size(180,125); - break; - case MB_BTN_YESNOCANCEL: - msgbox_add_BTN_YESNOCANCEL( btn_area ); - min_size = Size(215,125); - break; - default: return -1; - } - /* 创建消息框,并设置ID */ - msgbox = Window_New(); - Window_SetTextW( msgbox, title ); - Widget_Resize( msgbox, min_size ); - - msgbox->self_id = WIDGET_ID_MESSAGEBOX | button | icon_flag; - /* 获取窗口右上角的按钮指针,并设定按钮的ID */ - btn_close = Window_GetCloseButton( msgbox ); - btn_close->self_id = MB_BTN_IS_QUIT; - /* 限制消息框的尺寸 */ - LCUIScreen_GetSize( &max_size ); - Widget_LimitSize( msgbox, min_size, max_size ); - /* 设置为模态部件 */ - Widget_SetModal( msgbox, TRUE ); - /* 添加这两个区域至消息框内 */ - Window_ClientArea_Add( msgbox, msg_area ); - Window_ClientArea_Add( msgbox, btn_area ); - /* 设置区域的停靠方式及初始尺寸 */ - Widget_SetDock( msg_area, DOCK_TOP ); - Widget_SetDock( btn_area, DOCK_BOTTOM ); - Widget_SetSize( msg_area, NULL, MB_MSG_AREA_HEIGHT_TEXT ); - Widget_SetSize( btn_area, NULL, MB_BTN_AREA_HEIGHT_TEXT ); - - /* 设定按钮区域的样式 */ - Widget_SetBackgroundTransparent( btn_area, FALSE ); - Widget_SetBackgroundColor( btn_area, MB_BTN_AREA_BGCOLOR ); - Border_Init( &btn_area_border ); - btn_area_border.top_width = 1; - btn_area_border.top_style = BORDER_SOLID; - btn_area_border.top_color = MB_BTN_AREA_LINECOLOR; - Widget_SetBorder( btn_area, btn_area_border ); - - Label_SetTextW( textbox, text ); - Widget_Show( textbox ); - if( icon_type != MB_ICON_NONE ) { - Widget_Show( iconbox ); - } - Widget_Show( btn_area ); - Widget_Show( msg_area ); - Widget_Show( msgbox ); - - loop = msgbox_mainloop_new( msgbox ); - /* 关联消息框右上角关闭按钮的CLICKED事件 */ - Widget_ConnectEvent( btn_close, EVENT_CLICKED, msgbox_mainloop_quit ); - /* 关联用于显示文本的label部件的RESIZE事件 */ - Widget_ConnectEvent( textbox, EVENT_RESIZE, auto_resize_msgbox ); - /* 进入主循环 */ - LCUI_MainLoop_Run( loop ); - msgbox_data = msgbox_data_find( msgbox ); - if( msgbox_data ) { - Widget_Destroy( msgbox ); - ret = msgbox_data->clicked_button; - msgbox_data_delete( msgbox ); - return ret; - } - return -2; -} - -/* UTF-8版的LCUI_MessageBox */ -LCUI_API int -LCUI_MessageBox( MB_ICON_TYPE icon_type, const char *text, - const char *title, MB_BTN_TYPE button ) -{ - int ret; - wchar_t *unicode_text, *unicode_title; - - LCUICharset_UTF8ToUnicode( text, &unicode_text ); - LCUICharset_UTF8ToUnicode( title, &unicode_title ); - ret = LCUI_MessageBoxW( icon_type, unicode_text, unicode_title, button ); - if( unicode_text != NULL ) { - free( unicode_text ); - } - if( unicode_title != NULL ) { - free( unicode_title ); - } - return ret; -} - -/* ANSI版的LCUI_MessageBox */ -LCUI_API int -LCUI_MessageBoxA( MB_ICON_TYPE icon_type, const char *text, - const char *title, MB_BTN_TYPE button ) -{ - int ret; - wchar_t *unicode_text, *unicode_title; - - LCUICharset_GB2312ToUnicode( text, &unicode_text ); - LCUICharset_GB2312ToUnicode( title, &unicode_title ); - ret = LCUI_MessageBoxW( icon_type, unicode_text, unicode_title, button ); - if( unicode_text != NULL ) { - free( unicode_text ); - } - if( unicode_title != NULL ) { - free( unicode_title ); - } - return ret; -} - -#endif diff --git a/src/gui/widget/scrollbar.c b/src/gui/widget/scrollbar.c index 4dbe31fa..12158d6e 100644 --- a/src/gui/widget/scrollbar.c +++ b/src/gui/widget/scrollbar.c @@ -307,6 +307,9 @@ static void ScrollLayer_OnMouseDown( LCUI_Widget layer, LCUI_WidgetEvent e, void { LCUI_Widget w = e->data; LCUI_ScrollBar scrollbar = w->private_data; + if( scrollbar->is_dragging ) { + return; + } scrollbar->eid_touch = LCUI_BindEvent( LCUI_TOUCH, OnTouch, w, NULL ); scrollbar->eid_mouseup = LCUI_BindEvent( LCUI_MOUSEUP, OnMouseUp, w, NULL ); scrollbar->mouse_x = e->screen_x; diff --git a/src/gui/widget_task.c b/src/gui/widget_task.c index dbcfbcb9..eddf1699 100644 --- a/src/gui/widget_task.c +++ b/src/gui/widget_task.c @@ -38,7 +38,6 @@ * ***************************************************************************/ //#define DEBUG -#define __IN_WIDGET_TASK_SOURCE_FILE__ #include #include #include diff --git a/src/main.c b/src/main.c index ecf780b2..d693e02a 100644 --- a/src/main.c +++ b/src/main.c @@ -37,8 +37,6 @@ * 没有,请查看:. * ***************************************************************************/ //#define DEBUG -#define __IN_MAIN_SOURCE_FILE__ - #include #include #include diff --git a/src/platform/windows/windows_display.c b/src/platform/windows/windows_display.c index 55831d7a..47e44f98 100644 --- a/src/platform/windows/windows_display.c +++ b/src/platform/windows/windows_display.c @@ -40,7 +40,7 @@ //#define DEBUG #include #include -#define __IN_SURFACE_SOURCE_FILE__ +#define LCUI_SURFACE_C #ifdef LCUI_BUILD_IN_WIN32 #include #include diff --git a/src/platform/windows/windows_mouse.c b/src/platform/windows/windows_mouse.c index 056866cc..7bca4abc 100644 --- a/src/platform/windows/windows_mouse.c +++ b/src/platform/windows/windows_mouse.c @@ -72,6 +72,7 @@ static void OnMouseMessage( LCUI_Event ev, void *arg ) } if( !GetTouchInputInfo( handle, n, inputs, sizeof( TOUCHINPUT ) ) ) { + free( inputs ); break; } for( i = 0; i < n; ++i ) { diff --git a/src/util/framectrl.c b/src/util/framectrl.c index 0fbd408a..a4477686 100644 --- a/src/util/framectrl.c +++ b/src/util/framectrl.c @@ -38,7 +38,7 @@ * 没有,请查看:. * ****************************************************************************/ -#define __IN_FRAME_CONTROL_SOURCE_FILE__ +#define LCUI_FRAME_CONTROL_C #include #include From 79dc921faa8672fbb4a6c732e77e511fa1b566c6 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Mon, 30 May 2016 23:36:43 +0800 Subject: [PATCH 014/124] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/VS2012/LCUI/LCUI.vcxproj | 3 +-- build/VS2012/LCUI/LCUI.vcxproj.filters | 9 +++------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/build/VS2012/LCUI/LCUI.vcxproj b/build/VS2012/LCUI/LCUI.vcxproj index 76199db3..0a63f91d 100644 --- a/build/VS2012/LCUI/LCUI.vcxproj +++ b/build/VS2012/LCUI/LCUI.vcxproj @@ -113,7 +113,7 @@ Windows - false + true true true libxml2.lib;libpng16.lib;libjpeg.lib;freetype253.lib;zlib.lib;kernel32.lib;user32.lib;gdi32.lib; @@ -249,7 +249,6 @@ - diff --git a/build/VS2012/LCUI/LCUI.vcxproj.filters b/build/VS2012/LCUI/LCUI.vcxproj.filters index 529db24b..b69f6042 100644 --- a/build/VS2012/LCUI/LCUI.vcxproj.filters +++ b/build/VS2012/LCUI/LCUI.vcxproj.filters @@ -272,9 +272,6 @@ 源文件\bmp - - 源文件\bmp - 源文件\bmp @@ -386,9 +383,6 @@ 源文件\util - - 源文件\util - 源文件\util @@ -404,6 +398,9 @@ 源文件\util + + 源文件\bmp + From 72d3db0d627f858e0b35be5d3f19e5753c826ef9 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Mon, 30 May 2016 23:41:46 +0800 Subject: [PATCH 015/124] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=AE=8F=E5=91=BD?= =?UTF-8?q?=E5=90=8D=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/main.h | 4 ++-- include/LCUI/util/event.h | 4 ++-- include/LCUI/util/rect.h | 4 ++-- include/LCUI/util/string.h | 4 ++-- include/LCUI/util/time.h | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/LCUI/main.h b/include/LCUI/main.h index 59ab9041..fa3877e1 100644 --- a/include/LCUI/main.h +++ b/include/LCUI/main.h @@ -36,8 +36,8 @@ * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 * 没有,请查看:. * ***************************************************************************/ -#ifndef LCUI_LIB_MAIN_H -#define LCUI_LIB_MAIN_H +#ifndef LCUI_MAIN_H +#define LCUI_MAIN_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/util/event.h b/include/LCUI/util/event.h index d8c5d797..8b683643 100644 --- a/include/LCUI/util/event.h +++ b/include/LCUI/util/event.h @@ -36,8 +36,8 @@ * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 * 没有,请查看:. * ****************************************************************************/ -#ifndef LCUI_LIB_EVENT_H -#define LCUI_LIB_EVENT_H +#ifndef LCUI_UTIL_EVENT_H +#define LCUI_UTIL_EVENT_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/util/rect.h b/include/LCUI/util/rect.h index 383c7058..6bba6591 100644 --- a/include/LCUI/util/rect.h +++ b/include/LCUI/util/rect.h @@ -38,8 +38,8 @@ * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 * 没有,请查看:. * ****************************************************************************/ -#ifndef LCUI_MISC_RECT_H -#define LCUI_MISC_RECT_H +#ifndef LCUI_UTIL_RECT_H +#define LCUI_UTIL_RECT_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/util/string.h b/include/LCUI/util/string.h index ef10ee5f..d408392b 100644 --- a/include/LCUI/util/string.h +++ b/include/LCUI/util/string.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef LCUI_MISC_STRING_H -#define LCUI_MISC_STRING_H +#ifndef LCUI_UTIL_STRING_H +#define LCUI_UTIL_STRING_H #ifdef LCUI_BUILD_IN_WIN32 #include diff --git a/include/LCUI/util/time.h b/include/LCUI/util/time.h index f0ba24f4..2209bbde 100644 --- a/include/LCUI/util/time.h +++ b/include/LCUI/util/time.h @@ -1,6 +1,6 @@  -#ifndef LCUI_LIB_TIME_H -#define LCUI_LIB_TIME_H +#ifndef LCUI_UTIL_TIME_H +#define LCUI_UTIL_TIME_H LCUI_BEGIN_HEADER From cbe99071cd21d06b3a85e309cf3ee8e98c358a0d Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Mon, 30 May 2016 23:42:06 +0800 Subject: [PATCH 016/124] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/VS2012/LCUI/LCUI.vcxproj | 2 -- build/VS2012/LCUI/LCUI.vcxproj.filters | 6 ------ 2 files changed, 8 deletions(-) diff --git a/build/VS2012/LCUI/LCUI.vcxproj b/build/VS2012/LCUI/LCUI.vcxproj index 0a63f91d..9f85941d 100644 --- a/build/VS2012/LCUI/LCUI.vcxproj +++ b/build/VS2012/LCUI/LCUI.vcxproj @@ -149,7 +149,6 @@ - @@ -170,7 +169,6 @@ - diff --git a/build/VS2012/LCUI/LCUI.vcxproj.filters b/build/VS2012/LCUI/LCUI.vcxproj.filters index b69f6042..02f30379 100644 --- a/build/VS2012/LCUI/LCUI.vcxproj.filters +++ b/build/VS2012/LCUI/LCUI.vcxproj.filters @@ -96,9 +96,6 @@ 头文件\LCUI\draw - - 头文件\LCUI\gui - 头文件\LCUI\draw @@ -195,9 +192,6 @@ 头文件\LCUI\platform\windows - - 头文件\LCUI - 头文件\LCUI From fdd323f26ba873ea199002850ccac436036bc016 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Tue, 31 May 2016 11:29:39 +0800 Subject: [PATCH 017/124] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E9=BC=A0=E6=A0=87?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在鼠标按钮按住后,将调用 SetCapture() 函数来捕获接下来产生的鼠标消息,包括窗口外产生的鼠标消息,直到鼠标按钮释放为止。 --- src/platform/windows/windows_mouse.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/platform/windows/windows_mouse.c b/src/platform/windows/windows_mouse.c index 7bca4abc..697a49ad 100644 --- a/src/platform/windows/windows_mouse.c +++ b/src/platform/windows/windows_mouse.c @@ -31,24 +31,28 @@ static void OnMouseMessage( LCUI_Event ev, void *arg ) sys_ev.button.button = 1; sys_ev.button.x = mouse_pos.x; sys_ev.button.y = mouse_pos.y; + SetCapture( win_ev->hwnd ); break; case WM_LBUTTONUP: sys_ev.type = LCUI_MOUSEUP; sys_ev.button.button = 1; sys_ev.button.x = mouse_pos.x; sys_ev.button.y = mouse_pos.y; + ReleaseCapture(); break; case WM_RBUTTONDOWN: sys_ev.type = LCUI_MOUSEDOWN; sys_ev.button.button = 2; sys_ev.button.x = mouse_pos.x; sys_ev.button.y = mouse_pos.y; + SetCapture( win_ev->hwnd ); break; case WM_RBUTTONUP: sys_ev.type = LCUI_MOUSEUP; sys_ev.button.button = 2; sys_ev.button.x = mouse_pos.x; sys_ev.button.y = mouse_pos.y; + ReleaseCapture( win_ev->hwnd ); break; case WM_MOUSEWHEEL: sys_ev.type = LCUI_MOUSEWHEEL; From de711ef7ec8237c4cdbedbd07625365863ca6499 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Tue, 31 May 2016 11:39:46 +0800 Subject: [PATCH 018/124] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AE=8F=E5=91=BD?= =?UTF-8?q?=E5=90=8D=E6=A0=BC=E5=BC=8F=20#31?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/platform/linux/linux_display.h | 4 ++-- include/LCUI/platform/linux/linux_events.h | 4 ++-- include/LCUI/platform/linux/linux_keyboard.h | 4 ++-- include/LCUI/platform/linux/linux_mouse.h | 4 ++-- include/LCUI/platform/windows/windows_events.h | 4 ++-- include/LCUI/platform/windows/windows_keyboard.h | 4 ++-- include/LCUI/util/dict.h | 4 ++-- include/LCUI/util/dirent.h | 4 ++-- include/LCUI/util/framectrl.h | 4 ++-- include/LCUI/util/rect.h | 7 +++---- include/LCUI/util/string.h | 12 ++++++------ 11 files changed, 27 insertions(+), 28 deletions(-) diff --git a/include/LCUI/platform/linux/linux_display.h b/include/LCUI/platform/linux/linux_display.h index 23194955..d28407fc 100644 --- a/include/LCUI/platform/linux/linux_display.h +++ b/include/LCUI/platform/linux/linux_display.h @@ -1,5 +1,5 @@ -#ifndef __LCUI_LINUX_DISPLAY_H__ -#define __LCUI_LINUX_DISPLAY_H__ +#ifndef LCUI_LINUX_DISPLAY_H +#define LCUI_LINUX_DISPLAY_H int LCUI_InitLinuxDisplay( LCUI_DisplayDriver driver ); diff --git a/include/LCUI/platform/linux/linux_events.h b/include/LCUI/platform/linux/linux_events.h index f8c1949c..374e4926 100644 --- a/include/LCUI/platform/linux/linux_events.h +++ b/include/LCUI/platform/linux/linux_events.h @@ -1,5 +1,5 @@ -#ifndef __LCUI_LINUX_EVENTS_H__ -#define __LCUI_LINUX_EVENTS_H__ +#ifndef LCUI_LINUX_EVENTS_H +#define LCUI_LINUX_EVENTS_H int LCUI_InitLinuxApp( LCUI_AppDriver app ); diff --git a/include/LCUI/platform/linux/linux_keyboard.h b/include/LCUI/platform/linux/linux_keyboard.h index a2107494..9eece3c1 100644 --- a/include/LCUI/platform/linux/linux_keyboard.h +++ b/include/LCUI/platform/linux/linux_keyboard.h @@ -1,5 +1,5 @@ -#ifndef __LCUI_LINUX_KEYBOARD_H__ -#define __LCUI_LINUX_KEYBOARD_H__ +#ifndef LCUI_LINUX_KEYBOARD_H +#define LCUI_LINUX_KEYBOARD_H void LCUI_InitLinuxKeyboard( void ); diff --git a/include/LCUI/platform/linux/linux_mouse.h b/include/LCUI/platform/linux/linux_mouse.h index db72fdc8..ac3134b6 100644 --- a/include/LCUI/platform/linux/linux_mouse.h +++ b/include/LCUI/platform/linux/linux_mouse.h @@ -1,5 +1,5 @@ -#ifndef __LCUI_LINUX_MOUSE_H__ -#define __LCUI_LINUX_MOUSE_H__ +#ifndef LCUI_LINUX_MOUSE_H +#define LCUI_LINUX_MOUSE_H void LCUI_InitLinuxMouse( void ); diff --git a/include/LCUI/platform/windows/windows_events.h b/include/LCUI/platform/windows/windows_events.h index dfa3aa08..6182dcd8 100644 --- a/include/LCUI/platform/windows/windows_events.h +++ b/include/LCUI/platform/windows/windows_events.h @@ -1,5 +1,5 @@ -#ifndef __WINDOWS_EVENTS_H -#define __WINDOWS_EVENTS_H +#ifndef LCUI_WINDOWS_EVENTS_H +#define LCUI_WINDOWS_EVENTS_H typedef struct WIN_SysEvent_ { HWND hwnd; diff --git a/include/LCUI/platform/windows/windows_keyboard.h b/include/LCUI/platform/windows/windows_keyboard.h index cf4f5c1d..066ca047 100644 --- a/include/LCUI/platform/windows/windows_keyboard.h +++ b/include/LCUI/platform/windows/windows_keyboard.h @@ -1,5 +1,5 @@ -#ifndef LCUI_WINDOWS_KEYBOARD__ -#define LCUI_WINDOWS_KEYBOARD__ +#ifndef LCUI_WINDOWS_KEYBOARD_H +#define LCUI_WINDOWS_KEYBOARD_H void LCUI_InitWinKeyboard( void ); diff --git a/include/LCUI/util/dict.h b/include/LCUI/util/dict.h index 9f89da13..bea3397a 100644 --- a/include/LCUI/util/dict.h +++ b/include/LCUI/util/dict.h @@ -34,8 +34,8 @@ #include -#ifndef __DICT_H -#define __DICT_H +#ifndef LCUI_UTIL_DICT_H +#define LCUI_UTIL_DICT_H /** 哈希表节点结构 */ typedef struct DictEntry { diff --git a/include/LCUI/util/dirent.h b/include/LCUI/util/dirent.h index 12403074..f6975b55 100644 --- a/include/LCUI/util/dirent.h +++ b/include/LCUI/util/dirent.h @@ -1,6 +1,6 @@ // dirent.h -- Directory Entry pperation set. -#ifndef LCUI_DIRECTORY_ENTRY_H -#define LCUI_DIRECTORY_ENTRY_H +#ifndef LCUI_UTIL_DIRENT_H +#define LCUI_UTIL_DIRENT_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/util/framectrl.h b/include/LCUI/util/framectrl.h index 1372dd3e..b69c3262 100644 --- a/include/LCUI/util/framectrl.h +++ b/include/LCUI/util/framectrl.h @@ -38,8 +38,8 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LC_FRAME_CONTROL_H -#define __LC_FRAME_CONTROL_H +#ifndef LCUI_UTIL_FRAMECTRL_H +#define LCUI_UTIL_FRAMECTRL_H LCUI_BEGIN_HEADER diff --git a/include/LCUI/util/rect.h b/include/LCUI/util/rect.h index 6bba6591..347ac046 100644 --- a/include/LCUI/util/rect.h +++ b/include/LCUI/util/rect.h @@ -1,8 +1,7 @@ /* *************************************************************************** * rect.h -- Rectangle area handling * - * Copyright (C) 2012-2015 by - * Liu Chao + * Copyright (C) 2012-2016 by Liu Chao * * This file is part of the LCUI project, and may only be used, modified, and * distributed under the terms of the GPLv2. @@ -23,8 +22,7 @@ /* **************************************************************************** * rect.h -- 矩形区域处理 * - * 版权所有 (C) 2012-2015 归属于 - * 刘超 + * 版权所有 (C) 2012-2016 归属于 刘超 * * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 * @@ -38,6 +36,7 @@ * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 * 没有,请查看:. * ****************************************************************************/ + #ifndef LCUI_UTIL_RECT_H #define LCUI_UTIL_RECT_H diff --git a/include/LCUI/util/string.h b/include/LCUI/util/string.h index d408392b..1948c62c 100644 --- a/include/LCUI/util/string.h +++ b/include/LCUI/util/string.h @@ -63,12 +63,12 @@ typedef char TCHAR; LCUI_BEGIN_HEADER /** -* 清除字符串首尾的字符 -* @param[out] outstr 处理后的字符串 -* @param[in] instr 需要处理的字符串 -* @param[in] charlist 需要清除的字符列表,当为NULL时,默认清除空白符 -* @return 处理后的字符串的长度 -*/ + * 清除字符串首尾的字符 + * @param[out] outstr 处理后的字符串 + * @param[in] instr 需要处理的字符串 + * @param[in] charlist 需要清除的字符列表,当为NULL时,默认清除空白符 + * @return 处理后的字符串的长度 + */ LCUI_API int strtrim( char *outstr, const char *instr, const char *charlist ); LCUI_END_HEADER From 9b8bc24e24f5bb2c062cc878ad08bc874a09a5aa Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Tue, 31 May 2016 15:33:59 +0800 Subject: [PATCH 019/124] =?UTF-8?q?=E6=94=B9=E8=BF=9B=20LCUICond=5FWait()?= =?UTF-8?q?=20=E7=9A=84=E5=AE=9E=E7=8E=B0=E5=92=8C=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E7=9A=84=E8=B0=83=E7=94=A8=E4=BB=A3=E7=A0=81=20#34?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/util/framectrl.h | 2 +- src/thread/win32/cond.c | 35 +++++++++++++++++++++-------- src/util/framectrl.c | 42 ++++++++++++++++++++++------------- 3 files changed, 54 insertions(+), 25 deletions(-) diff --git a/include/LCUI/util/framectrl.h b/include/LCUI/util/framectrl.h index b69c3262..d8f72216 100644 --- a/include/LCUI/util/framectrl.h +++ b/include/LCUI/util/framectrl.h @@ -43,7 +43,7 @@ LCUI_BEGIN_HEADER -#ifdef LCUI_FRAME_CONTROL_C +#ifdef LCUI_UTIL_FRAMECTRL_C typedef struct FrameControlContext* FrameCtrlCtx; #else typedef void* FrameCtrlCtx; diff --git a/src/thread/win32/cond.c b/src/thread/win32/cond.c index 83ab7a22..ef1ae35d 100644 --- a/src/thread/win32/cond.c +++ b/src/thread/win32/cond.c @@ -37,6 +37,7 @@ * 没有,请查看:. * ***************************************************************************/ +#include #include #include #include @@ -73,25 +74,41 @@ int LCUICond_Wait( LCUI_Cond *cond, LCUI_Mutex *mutex ) LCUIMutex_Unlock( mutex ); ret = WaitForSingleObject( *cond, INFINITE ); switch( ret ) { - case WAIT_TIMEOUT: break; - case WAIT_OBJECT_0: LCUIMutex_Lock( mutex ); return 0; + case WAIT_TIMEOUT: + ret = ETIMEDOUT; + break; + case WAIT_OBJECT_0: + ret = 0; + break; case WAIT_FAILED: - default: return -1; + default: + ret = GetLastError(); + break; } - return 1; + LCUIMutex_Lock( mutex ); + return ret; } /** 计时阻塞当前线程,等待条件成立 */ int LCUICond_TimedWait( LCUI_Cond *cond, LCUI_Mutex *mutex, unsigned int ms ) { + int ret; LCUIMutex_Unlock( mutex ); - switch( WaitForSingleObject( *cond, ms ) ) { - case WAIT_TIMEOUT: break; - case WAIT_OBJECT_0: LCUIMutex_Lock( mutex ); return 0; + ret = WaitForSingleObject( *cond, ms ); + switch( ret ) { + case WAIT_TIMEOUT: + ret = ETIMEDOUT; + break; + case WAIT_OBJECT_0: + ret = 0; + break; case WAIT_FAILED: - default: return -1; + default: + ret = GetLastError(); + break; } - return 1; + LCUIMutex_Lock( mutex ); + return ret; } /** 唤醒一个阻塞等待条件成立的线程 */ diff --git a/src/util/framectrl.c b/src/util/framectrl.c index a4477686..0b7094da 100644 --- a/src/util/framectrl.c +++ b/src/util/framectrl.c @@ -38,16 +38,17 @@ * 没有,请查看:. * ****************************************************************************/ -#define LCUI_FRAME_CONTROL_C +#define LCUI_UTIL_FRAMECTRL_C +#include #include #include #include #include -#define FRAME_CTRL_STATE_RUN 0 -#define FRAME_CTRL_STATE_PAUSE 1 -#define FRAME_CTRL_STATE_QUIT 2 +#define STATE_RUN 0 +#define STATE_PAUSE 1 +#define STATE_QUIT 2 struct FrameControlContext { int state; @@ -76,7 +77,6 @@ FrameCtrlCtx FrameControl_Create( void ) LCUICond_Init( &ctx->wait_continue ); LCUICond_Init( &ctx->wait_pause ); LCUIMutex_Init( &ctx->mutex ); - LCUIMutex_Lock( &ctx->mutex ); return ctx; } @@ -105,13 +105,16 @@ int FrameControl_GetFPS( FrameCtrlCtx ctx ) /** 让当前帧停留一定时间 */ void FrameControl_Remain( FrameCtrlCtx ctx ) { - unsigned int n_ms, lost_ms; + int ret; int64_t current_time; + unsigned int n_ms, lost_ms; - if( ctx->state == FRAME_CTRL_STATE_QUIT ) { + if( ctx->state == STATE_QUIT ) { return; } + lost_ms = 0; current_time = LCUI_GetTickCount(); + LCUIMutex_Lock( &ctx->mutex ); n_ms = (int)(current_time - ctx->prev_frame_start_time); if( n_ms > ctx->one_frame_remain_time ) { goto normal_exit; @@ -120,18 +123,26 @@ void FrameControl_Remain( FrameCtrlCtx ctx ) if( n_ms < 1 ) { goto normal_exit; } - /* 进行睡眠,直到需要暂停为止 */ - LCUICond_TimedWait( &ctx->wait_pause, &ctx->mutex, n_ms ); + while( lost_ms < n_ms ) { + /* 进行睡眠,直到需要暂停为止 */ + ret = LCUICond_TimedWait( &ctx->wait_pause, &ctx->mutex, + n_ms - lost_ms ); + if( ret == ETIMEDOUT || ret == 0 ) { + break; + } + lost_ms = (unsigned int)LCUI_GetTicks( current_time ); + } /* 睡眠结束后,如果当前状态不为PAUSE,则说明睡眠不是因为要暂停而终止的 */ - if( ctx->state != FRAME_CTRL_STATE_PAUSE ) { + if( ctx->state != STATE_PAUSE ) { goto normal_exit; } current_time = LCUI_GetTickCount(); /* 需要暂停,进行睡眠,直到需要继续为止 */ - LCUICond_Wait( &ctx->wait_continue, &ctx->mutex ); + while( LCUICond_Wait( &ctx->wait_continue, &ctx->mutex ) != 0 ); lost_ms = (unsigned int)LCUI_GetTicks( current_time ); ctx->pause_time = lost_ms; ctx->prev_frame_start_time += lost_ms; + LCUIMutex_Unlock( &ctx->mutex ); return; normal_exit:; @@ -143,20 +154,21 @@ normal_exit:; } ctx->prev_frame_start_time = current_time; ++ctx->temp_fps; + LCUIMutex_Unlock( &ctx->mutex ); } /** 暂停数据帧的更新 */ void FrameControl_Pause( FrameCtrlCtx ctx, LCUI_BOOL need_pause ) { - if( ctx->state == FRAME_CTRL_STATE_RUN && need_pause ) { + if( ctx->state == STATE_RUN && need_pause ) { LCUIMutex_Lock( &ctx->mutex ); - ctx->state = FRAME_CTRL_STATE_PAUSE; + ctx->state = STATE_PAUSE; LCUICond_Signal( &ctx->wait_pause ); LCUIMutex_Unlock( &ctx->mutex ); } - else if( ctx->state == FRAME_CTRL_STATE_PAUSE && !need_pause ){ + else if( ctx->state == STATE_PAUSE && !need_pause ){ LCUIMutex_Lock( &ctx->mutex ); - ctx->state = FRAME_CTRL_STATE_RUN; + ctx->state = STATE_RUN; LCUICond_Signal( &ctx->wait_continue ); LCUIMutex_Unlock( &ctx->mutex ); } From 002b07bfb8069e4255d3d67e7baeca5359dd3d10 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Wed, 1 Jun 2016 21:03:12 +0800 Subject: [PATCH 020/124] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20Widget=5FBlockEven?= =?UTF-8?q?t()=20=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/gui/widget_base.h | 1 + include/LCUI/gui/widget_event.h | 3 +++ src/gui/widget_event.c | 31 ++++++++++++++++++------------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/include/LCUI/gui/widget_base.h b/include/LCUI/gui/widget_base.h index e8556942..ed1e09d2 100755 --- a/include/LCUI/gui/widget_base.h +++ b/include/LCUI/gui/widget_base.h @@ -253,6 +253,7 @@ typedef struct LCUI_WidgetRec_ { LinkedList dirty_rects; /**< 记录无效区域(脏矩形) */ LCUI_BOOL has_dirty_child; /**< 子级部件是否有无效区域 */ LCUI_BOOL layout_locked; /**< 子级部件布局是否已锁定 */ + LCUI_BOOL event_blocked; /**< 是否阻止自己和子级部件的事件处理 */ } LCUI_WidgetRec; #define Widget_GetNode(w) (LinkedListNode*)(((char*)w) + sizeof(LCUI_WidgetRec)) diff --git a/include/LCUI/gui/widget_event.h b/include/LCUI/gui/widget_event.h index c531810b..cd32655b 100644 --- a/include/LCUI/gui/widget_event.h +++ b/include/LCUI/gui/widget_event.h @@ -87,6 +87,9 @@ typedef struct LCUI_WidgetEventRec_ { typedef void(*LCUI_WidgetEventFunc)(LCUI_Widget, LCUI_WidgetEvent, void*); +/** 设置阻止部件及其子级部件的事件 */ +#define Widget_BlockEvent(WIDGET, FLAG) (WIDGET)->event_blocked = FLAG + /** 触发事件,让事件处理器在主循环中调用 */ LCUI_API int Widget_PostEvent( LCUI_Widget widget, LCUI_WidgetEvent e, void *data, void( *destroy_data )(void*) ); diff --git a/src/gui/widget_event.c b/src/gui/widget_event.c index eb113493..5e8e0c21 100644 --- a/src/gui/widget_event.c +++ b/src/gui/widget_event.c @@ -371,16 +371,6 @@ int Widget_TriggerEvent( LCUI_Widget widget, LCUI_WidgetEvent e, void *data ) return Widget_TriggerEventEx( widget, e, data, NULL, TRUE ); } -void LCUIWidget_ClearEventTarget( LCUI_Widget widget ) -{ - int i; - for( i = 0; i < WST_TOTAL; ++i ) { - if( self.targets[i] == widget ) { - self.targets[i] = NULL; - } - } -} - int Widget_StopEventPropagation(LCUI_Widget widget ) { LCUI_WidgetEvent e; @@ -448,19 +438,34 @@ static void Widget_UpdateStatus( LCUI_Widget widget, int type ) } } +void LCUIWidget_ClearEventTarget( LCUI_Widget widget ) +{ + int i; + for( i = 0; i < WST_TOTAL; ++i ) { + if( !widget || self.targets[i] == widget ) { + Widget_UpdateStatus( NULL, i ); + } + } +} + /** 响应系统的鼠标移动事件,向目标部件投递相关鼠标事件 */ static void OnMouseEvent( LCUI_SysEvent e, void *arg ) { LCUI_Pos pos; LCUI_WidgetEventRec ebuff; - LCUI_Widget target, root; - root = LCUIWidget_GetRoot(); + LCUI_Widget target, w; + w = LCUIWidget_GetRoot(); LCUICursor_GetPos( &pos ); - target = Widget_At( root, pos.x, pos.y ); + target = Widget_At( w, pos.x, pos.y ); if( !target ) { Widget_UpdateStatus( NULL, WST_HOVER ); return; } + for( w = target; w; w = w->parent ) { + if( w->event_blocked ) { + return; + } + } Widget_GetAbsXY( target, NULL, &ebuff.x, &ebuff.y ); ebuff.cancel_bubble = FALSE; ebuff.x = pos.x - ebuff.x; From 9a54619e57ea50b9f01542fd9730ae454cc2c345 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Wed, 1 Jun 2016 21:06:41 +0800 Subject: [PATCH 021/124] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=83=AF=E6=80=A7?= =?UTF-8?q?=E6=BB=9A=E5=8A=A8=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gui/widget/scrollbar.c | 178 ++++++++++++++++++++++++++++++------- 1 file changed, 148 insertions(+), 30 deletions(-) diff --git a/src/gui/widget/scrollbar.c b/src/gui/widget/scrollbar.c index 12158d6e..4890255d 100644 --- a/src/gui/widget/scrollbar.c +++ b/src/gui/widget/scrollbar.c @@ -44,23 +44,41 @@ #include #include #include +#include #include #include +#define EFFECT_FRAMES 50 + +/** 惯性滚动效果的相关数据 */ +typedef struct InertialScrollingRec_ { + int start_pos; /**< 起始位置 */ + int end_pos; /**< 结束位置 */ + int timer; /**< 定时器 */ + int interval; /**< 定时器的间隔时间 */ + int speed; /**< 滚动速度 */ + int speed_delta; /**< 速度差(加速度) */ + int64_t timestamp; /**< 开始时间 */ + LCUI_BOOL is_running; /**< 当前效果是否正在运行 */ +} InertialScrollingRec, *InertialScrolling; + +/** 滚动条的相关数据 */ typedef struct LCUI_ScrollBarRec_ { - LCUI_Widget box; /**< 容器 */ - LCUI_Widget layer; /**< 滚动层 */ - LCUI_Widget slider; /**< 滑块 */ - LCUI_BOOL is_dragging; /**< 是否处于拖拽状态 */ - int slider_x, slider_y; /**< 拖拽开始时的滑块位置 */ - int mouse_x, mouse_y; /**< 拖拽开始时的鼠标坐标 */ - int direction; /**< 滚动条的方向(垂直或水平) */ - int eid_mousemove; - int eid_mouseup; - int eid_touch; - int scroll_step; /**< 每次滚动的距离,主要针对使用鼠标滚轮触发的滚动 */ - int pos; /**< 当前的位置 */ - int old_pos; /**< 拖拽开始时的位置 */ + LCUI_Widget box; /**< 容器 */ + LCUI_Widget layer; /**< 滚动层 */ + LCUI_Widget slider; /**< 滑块 */ + LCUI_BOOL is_dragging; /**< 是否处于拖拽状态 */ + int slider_x, slider_y; /**< 拖拽开始时的滑块位置 */ + int mouse_x, mouse_y; /**< 拖拽开始时的鼠标坐标 */ + int direction; /**< 滚动条的方向(垂直或水平) */ + int scroll_step; /**< 每次滚动的距离,主要针对使用鼠标滚轮触发的滚动 */ + int pos; /**< 当前的位置 */ + int old_pos; /**< 拖拽开始时的位置 */ + int distance; /**< 滚动距离 */ + InertialScrollingRec effect; /**< 用于实现惯性滚动效果的相关数据 */ + int eid_mousemove; /**< MOUSEMOVE 事件的绑定ID */ + int eid_mouseup; /**< MOUSEUP 事件的绑定ID */ + int eid_touch; /**< TOUCH 事件的绑定ID */ } LCUI_ScrollBarRec, *LCUI_ScrollBar; static int scroll_event_id = -1; @@ -102,6 +120,70 @@ top: auto; ); +static void OnInertialScrolling( void *arg ) +{ + int pos; + LCUI_Widget w = arg; + LCUI_ScrollBar scrollbar; + InertialScrolling effect; + scrollbar = w->private_data; + effect = &scrollbar->effect; + pos = scrollbar->pos + effect->speed; + effect->speed += effect->speed_delta; + ScrollBar_SetPosition( w, pos ); + if( effect->speed == 0 || !effect->is_running || + (effect->speed_delta > 0) == (effect->speed > 0) ) { + effect->speed = 0; + effect->timer = -1; + effect->is_running = FALSE; + return; + } + effect->timer = LCUITimer_Set( effect->interval, + OnInertialScrolling, w, FALSE ); +} + +static void ScrollBar_UpdateInertialScrolling( LCUI_Widget w ) +{ + LCUI_ScrollBar scrollbar; + scrollbar = w->private_data; + scrollbar->effect.speed = 0; + scrollbar->effect.is_running = FALSE; + scrollbar->effect.start_pos = scrollbar->pos; + scrollbar->effect.timestamp = LCUI_GetTickCount(); +} + +static void ScrollBar_StartInertialScrolling( LCUI_Widget w ) +{ + int distance; + int64_t time_delta; + LCUI_ScrollBar scrollbar; + InertialScrolling effect; + scrollbar = w->private_data; + effect = &scrollbar->effect; + effect->end_pos = scrollbar->pos; + distance = effect->end_pos - effect->start_pos; + time_delta = LCUI_GetTicks( effect->timestamp ); + /* 计算每一帧的滚动距离(速度) */ + if( time_delta > 0 ) { + effect->speed = distance * effect->interval / (int)time_delta; + } else { + effect->speed = 0; + } + /* 计算加速度,该值的正负符号始终与速度值的相反 */ + if( (effect->speed > 0) == (effect->speed_delta > 0) ) { + effect->speed_delta = -effect->speed_delta; + } + effect->timestamp = LCUI_GetTickCount(); + if( effect->is_running ) { + return; + } + effect->is_running = TRUE; + effect->timer = LCUITimer_Set( effect->interval, + OnInertialScrolling, w, FALSE ); + DEBUG_MSG("effect->speed: %d, distance: %d, time: %d\n", + effect->speed, distance, (int)time_delta); +} + static void OnMouseUp( LCUI_SysEvent e, void *arg ) { LCUI_Widget w = e->data; @@ -114,14 +196,20 @@ static void OnMouseUp( LCUI_SysEvent e, void *arg ) } if( scrollbar->eid_touch > 0 ) { LCUI_UnbindEvent( scrollbar->eid_touch ); + if( scrollbar->is_dragging ) { + ScrollBar_StartInertialScrolling( w ); + } } + scrollbar->is_dragging = FALSE; scrollbar->eid_mousemove = -1; scrollbar->eid_mouseup = -1; scrollbar->eid_touch = -1; - scrollbar->is_dragging = FALSE; + if( scrollbar->layer ) { + scrollbar->layer->event_blocked = FALSE; + } } -static void OnMouseMove( LCUI_SysEvent e, void *arg ) +static void Slider_OnMouseMove( LCUI_SysEvent e, void *arg ) { float n; LCUI_Pos pos; @@ -196,23 +284,39 @@ static void OnMouseMove( LCUI_SysEvent e, void *arg ) Widget_Move( scrollbar->slider, x, y ); } -static void OnTouch( LCUI_SysEvent e, void *arg ) +/** 滚动层的触屏事件响应 */ +static void ScrollLayer_OnTouch( LCUI_SysEvent e, void *arg ) { - int pos; + int pos, distance; LCUI_TouchPoint point; LCUI_Widget w = e->data; - LCUI_ScrollBar scrollbar = w->private_data; + LCUI_ScrollBar scrollbar; if( e->touch.n_points < 1 ) { return; } point = &e->touch.points[0]; - if( point->state == LCUI_TOUCHMOVE ) { - pos = scrollbar->old_pos - (point->y - scrollbar->mouse_y); - ScrollBar_SetPosition( w, pos ); + if( point->state != LCUI_TOUCHMOVE ) { + return; } + scrollbar = w->private_data; + pos = scrollbar->old_pos - (point->y - scrollbar->mouse_y); + if( pos != scrollbar->pos ) { + if( !scrollbar->is_dragging ) { + scrollbar->is_dragging = TRUE; + LCUIWidget_ClearEventTarget( NULL ); + Widget_BlockEvent( scrollbar->layer, TRUE ); + } + distance = pos - scrollbar->pos; + if( (scrollbar->distance > 0) != (distance > 0) ) { + ScrollBar_UpdateInertialScrolling( w ); + } + scrollbar->distance = distance; + } + ScrollBar_SetPosition( w, pos ); } -static void OnMouseDown( LCUI_Widget slider, LCUI_WidgetEvent e, void *arg ) +static void Slider_OnMouseDown( LCUI_Widget slider, LCUI_WidgetEvent e, + void *arg ) { LCUI_Widget w = slider->parent; LCUI_ScrollBar scrollbar = w->private_data; @@ -225,7 +329,8 @@ static void OnMouseDown( LCUI_Widget slider, LCUI_WidgetEvent e, void *arg ) scrollbar->mouse_y = e->screen_y; scrollbar->is_dragging = TRUE; scrollbar->eid_mousemove = LCUI_BindEvent( LCUI_MOUSEMOVE, - OnMouseMove, w, NULL ); + Slider_OnMouseMove, + w, NULL ); scrollbar->eid_mouseup = LCUI_BindEvent( LCUI_MOUSEUP, OnMouseUp, w, NULL ); } @@ -236,9 +341,6 @@ static void ScrollBar_OnInit( LCUI_Widget w ) LCUI_ScrollBar self; slider = LCUIWidget_New( NULL ); self = Widget_NewPrivateData( w, LCUI_ScrollBarRec ); - Widget_BindEvent( slider, "mousedown", OnMouseDown, NULL, NULL ); - Widget_AddClass( slider, "slider" ); - Widget_Append( w, slider ); self->direction = SBD_VERTICAL; self->is_dragging = FALSE; self->scroll_step = 40; @@ -250,6 +352,18 @@ static void ScrollBar_OnInit( LCUI_Widget w ) self->box = NULL; self->old_pos = 0; self->pos = 0; + self->effect.timer = -1; + self->effect.end_pos = 0; + self->effect.start_pos = 0; + self->effect.timestamp = 0; + self->effect.speed = 0; + self->effect.speed_delta = 1; + self->effect.is_running = FALSE; + self->effect.interval = 1000 / EFFECT_FRAMES; + Widget_BindEvent( slider, "mousedown", + Slider_OnMouseDown, NULL, NULL ); + Widget_AddClass( slider, "slider" ); + Widget_Append( w, slider ); } static void ScrollBar_UpdateSize( LCUI_Widget w ) @@ -306,16 +420,20 @@ static void ScrollLayer_OnWheel( LCUI_Widget layer, LCUI_WidgetEvent e, void *ar static void ScrollLayer_OnMouseDown( LCUI_Widget layer, LCUI_WidgetEvent e, void *arg ) { LCUI_Widget w = e->data; - LCUI_ScrollBar scrollbar = w->private_data; + LCUI_ScrollBar scrollbar; + scrollbar = w->private_data; + scrollbar->distance = 0; + scrollbar->effect.speed = 0; + scrollbar->effect.is_running = FALSE; + scrollbar->old_pos = scrollbar->pos; if( scrollbar->is_dragging ) { return; } - scrollbar->eid_touch = LCUI_BindEvent( LCUI_TOUCH, OnTouch, w, NULL ); + scrollbar->eid_touch = LCUI_BindEvent( LCUI_TOUCH, + ScrollLayer_OnTouch, w, NULL ); scrollbar->eid_mouseup = LCUI_BindEvent( LCUI_MOUSEUP, OnMouseUp, w, NULL ); scrollbar->mouse_x = e->screen_x; scrollbar->mouse_y = e->screen_y; - scrollbar->old_pos = scrollbar->pos; - scrollbar->is_dragging = TRUE; } static void ScrollBar_OnUpdateSize( LCUI_Widget box, LCUI_WidgetEvent e, void *arg ) From 7a6e9da21e5e8c805f617133652e0a6bff180dfb Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Wed, 1 Jun 2016 22:27:20 +0800 Subject: [PATCH 022/124] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=83=AF=E6=80=A7?= =?UTF-8?q?=E6=BB=9A=E5=8A=A8=E6=95=88=E6=9E=9C=E3=80=81=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E5=85=B6=E4=BB=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gui/widget/scrollbar.c | 6 ++++-- src/platform/windows/windows_mouse.c | 2 +- src/util/framectrl.c | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/gui/widget/scrollbar.c b/src/gui/widget/scrollbar.c index 4890255d..11207b45 100644 --- a/src/gui/widget/scrollbar.c +++ b/src/gui/widget/scrollbar.c @@ -180,6 +180,7 @@ static void ScrollBar_StartInertialScrolling( LCUI_Widget w ) effect->is_running = TRUE; effect->timer = LCUITimer_Set( effect->interval, OnInertialScrolling, w, FALSE ); + DEBUG_MSG("start_pos: %d, end_pos: %d\n", effect->start_pos, effect->end_pos); DEBUG_MSG("effect->speed: %d, distance: %d, time: %d\n", effect->speed, distance, (int)time_delta); } @@ -205,7 +206,7 @@ static void OnMouseUp( LCUI_SysEvent e, void *arg ) scrollbar->eid_mouseup = -1; scrollbar->eid_touch = -1; if( scrollbar->layer ) { - scrollbar->layer->event_blocked = FALSE; + Widget_BlockEvent( scrollbar->layer, FALSE ); } } @@ -307,7 +308,8 @@ static void ScrollLayer_OnTouch( LCUI_SysEvent e, void *arg ) Widget_BlockEvent( scrollbar->layer, TRUE ); } distance = pos - scrollbar->pos; - if( (scrollbar->distance > 0) != (distance > 0) ) { + if( (scrollbar->distance > 0) != (distance > 0) || + scrollbar->distance == 0 ) { ScrollBar_UpdateInertialScrolling( w ); } scrollbar->distance = distance; diff --git a/src/platform/windows/windows_mouse.c b/src/platform/windows/windows_mouse.c index 697a49ad..e8f4386a 100644 --- a/src/platform/windows/windows_mouse.c +++ b/src/platform/windows/windows_mouse.c @@ -52,7 +52,7 @@ static void OnMouseMessage( LCUI_Event ev, void *arg ) sys_ev.button.button = 2; sys_ev.button.x = mouse_pos.x; sys_ev.button.y = mouse_pos.y; - ReleaseCapture( win_ev->hwnd ); + ReleaseCapture(); break; case WM_MOUSEWHEEL: sys_ev.type = LCUI_MOUSEWHEEL; diff --git a/src/util/framectrl.c b/src/util/framectrl.c index 0b7094da..5e8ffbd1 100644 --- a/src/util/framectrl.c +++ b/src/util/framectrl.c @@ -115,7 +115,7 @@ void FrameControl_Remain( FrameCtrlCtx ctx ) lost_ms = 0; current_time = LCUI_GetTickCount(); LCUIMutex_Lock( &ctx->mutex ); - n_ms = (int)(current_time - ctx->prev_frame_start_time); + n_ms = (unsigned int)(current_time - ctx->prev_frame_start_time); if( n_ms > ctx->one_frame_remain_time ) { goto normal_exit; } From 2ed3fefd469e4704ef7944af1532e0a1ab5e55cf Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Thu, 2 Jun 2016 13:46:47 +0800 Subject: [PATCH 023/124] update README.md --- README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index c1d4a677..7b0c18c2 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,11 @@ ## Description - The LCUI project is create by a China developer, and his English is - not very good, so, some files will appear chinese character, - please understand. thanks. + LCUI is a freely available software library to create GUI application. + + It is written in C, support the use XML and CSS describe the graphical + interface. author is from China, but his English is not very good, so, some + files will appear chinese character, please understand. thanks. Please read the file `docs/CHANGES.md`, it contains IMPORTANT INFORMATION. @@ -33,12 +35,9 @@ In the simplest case you would run: git clone https://github.com/lc-soft/LCUI.git cd LCUI - git submodule update --init + ./autogen.sh ./configure -Please note that if you downloaded the source code (rather than cloned -via git) you likely miss the submodules and the build will therefor fail. - ## Bugs Please report bugs by e-mail to `lc-soft@live.cn`. Don't forget to @@ -106,9 +105,9 @@ If a lot of changes has happened upstream you can replay your local changes This will fetch changes and re-apply your commits on top of these. -This is generally better than merge, as it will give a clear picture of - which commits are local to your branch. It will also “prune” any of your - local commits if the same changes have been applied upstream. +This is generally better than merge, as it will give a clear picture of which +commits are local to your branch. It will also “prune” any of your local commits +if the same changes have been applied upstream. You can use `-i` with `rebase` for an “interactive” rebase. This allows you to drop, re-arrange, merge, and reword commits, e.g.: @@ -123,7 +122,8 @@ The LCUI Project is released under the GNU General Public License as published option) any later version. ## Thanks to - Liu Chao + +Liu Chao Special thanks to Liu Chao for his great work on the LCUI's development. From 5697ab5cea12edcb0ec8885206ab5397a0dd4093 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Thu, 2 Jun 2016 13:48:23 +0800 Subject: [PATCH 024/124] update configure.ac #33 --- configure.ac | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/configure.ac b/configure.ac index d1d30d31..1a4702f4 100755 --- a/configure.ac +++ b/configure.ac @@ -62,13 +62,13 @@ want_thread=no thread_name=pthread AC_ARG_WITH(pthread, [ --with-pthread use pthread (default)]) if test "x$with_pthread" != "xno"; then - m4_include([m4/ax_pthread.m4]) AX_PTHREAD([ want_thread=yes + CC="$PTHREAD_CC" CFLAGS="$CFLAGS $PTHREAD_CFLAGS" LCUI_LIBS="$LCUI_LIBS $PTHREAD_LIBS" - AC_DEFINE_UNQUOTED(LCUI_THREAD_PTHREAD, 1, Define to 1 if you using pthread support) - ], want_thread=no) + AC_DEFINE_UNQUOTED(LCUI_THREAD_PTHREAD, 1, Define to 1 if you are using pthread support) + ], [AC_MSG_ERROR(The support could not be configured for the POSIX thread programming interface.)]) fi ##检测是否有libxml2库,必须有 libxml2 库才能启用 LCUIBuilder 功能模块 @@ -79,8 +79,8 @@ if test "$enable_builder" = "yes"; then AC_CHECK_HEADERS([libxml/parser.h],[ AC_CHECK_LIB([xml2], [xmlParseFile], [ enable_builder=yes - CFLAGS="$CFLAGS -I/usr/include/libxml2" LCUI_LIBS="$LCUI_LIBS -lxml2" + CFLAGS="$CFLAGS -I/usr/include/libxml2" AC_DEFINE_UNQUOTED(USE_LCUI_BUILDER, 1, Define to 1 if you enabled LCUIBuilder function module) ], enable_builder=no) ], enable_builder=no) @@ -95,9 +95,9 @@ if test "$want_font_engine" = yes; then AC_CHECK_HEADERS([ft2build.h], [ AC_CHECK_LIB([freetype], [FT_Init_FreeType], [ want_font_engine=yes - CFLAGS="$CFLAGS -I/usr/include/freetype2" - LCUI_LIBS="$LCUI_LIBS -lfreetype" font_engine_name=freetype2 + LCUI_LIBS="$LCUI_LIBS `pkg-config --libs freetype2`" + CFLAGS="$CFLAGS `pkg-config --cflags-only-I freetype2`" AC_DEFINE_UNQUOTED(LCUI_FONT_ENGINE_FREETYPE, 1, Define to 1 if you have the FreeType font engine) ], want_font_engine=no) ], [want_font_engine=no]) @@ -117,9 +117,9 @@ if test "$want_video_output" = yes; then ], [video_driver_name=none]) AC_CHECK_HEADERS([X11/Xlib.h],[ AC_CHECK_LIB([X11], [XOpenDisplay], [ - CFLAGS="$CFLAGS `pkg-config --cflags-only-I x11`" - LCUI_LIBS="$LCUI_LIBS `pkg-config --libs x11`" video_driver_name=x11 + LCUI_LIBS="$LCUI_LIBS `pkg-config --libs x11`" + CFLAGS="$CFLAGS `pkg-config --cflags-only-I x11`" AC_DEFINE_UNQUOTED(LCUI_VIDEO_DRIVER_X11, 1, Define to 1 if you select XWindow for video support) ], []) ], []) @@ -144,7 +144,8 @@ if test "x$with_png" != "xno"; then AC_CHECK_HEADERS([png.h],[ AC_CHECK_LIB([png], [png_sig_cmp],[ want_png=yes - LCUI_LIBS="$LCUI_LIBS -lpng" + LCUI_LIBS="$LCUI_LIBS `pkg-config --libs libpng`" + CFLAGS="$CFLAGS `pkg-config --cflags-only-I libpng`" AC_DEFINE_UNQUOTED(USE_LIBPNG, 1, Define to 1 if you have the libpng) ],want_png=no) ],want_png=no) From 756589145b8e787fafae6b65e04f96ccd67985ba Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Thu, 2 Jun 2016 17:02:26 +0800 Subject: [PATCH 025/124] Add donation description. --- README.md | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 7b0c18c2..3d21511b 100644 --- a/README.md +++ b/README.md @@ -7,29 +7,28 @@ ## Description - LCUI is a freely available software library to create GUI application. +LCUI is a freely available software library to create GUI application. - It is written in C, support the use XML and CSS describe the graphical - interface. author is from China, but his English is not very good, so, some - files will appear chinese character, please understand. thanks. +It is written in C, support the use XML and CSS describe the graphical +interface. author is from China, but his English is not very good, so, some +files will appear chinese character, please understand. thanks. - Please read the file `docs/CHANGES.md`, it contains IMPORTANT INFORMATION. +Please read the file `docs/CHANGES.md`, it contains IMPORTANT INFORMATION. - Read the file `INSTALL` for installation instructions. +Read the file `INSTALL` for installation instructions. - See the file `docs/LICENSE.TXT` for the available licenses. +See the file `docs/LICENSE.TXT` for the available licenses. ## Documentation - API reference documentation has not yet been prepared, development to - more mature in this project will consider writing it. - At this stage, you can refer to the header files, source code, and - sample programs . +API reference documentation has not yet been prepared, development to more +mature in this project will consider writing it. At this stage, you can refer +to the header files, source code, and sample programs. ## Building -To bootstrap the build you need to run `./configure` (in the root of the - source tree). +To bootstrap the build you need to run `./configure` (in the root of the +source tree). In the simplest case you would run: @@ -40,13 +39,15 @@ In the simplest case you would run: ## Bugs - Please report bugs by e-mail to `lc-soft@live.cn`. Don't forget to - send a detailed explanation of the problem -- there is nothing - worse than receiving a terse message that only says `it doesn't work`. +Please report bugs by e-mail to `lc-soft@live.cn`. Don't forget to send a +detailed explanation of the problem -- there is nothing worse than receiving +a terse message that only says `it doesn't work`. ## Contributing -You can send pull requests via GitHub. Patches should: +**You can send pull requests via GitHub.** + +Patches should: 1. Follow the style of the existing code. 2. One commit should do exactly one thing. @@ -68,6 +69,12 @@ You can send pull requests via GitHub. Patches should: make it easier for us (and avoid any legal issues) we prefer if patches are released as public domain. +**You can donate support the development of LCUI.** + +I'm currently an independent developer and your contributions are useful. +I have setup an [LCUI Patreon page](https://www.patreon.com/lcsoft) if you +want to donate and enable me to spend more time improving the library. +One-off donations are also greatly appreciated. Thanks! ### GitHub Workflow From 616cdbf9107a4d467d120c52746e9690ab16ad7c Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Thu, 2 Jun 2016 22:53:48 +0800 Subject: [PATCH 026/124] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=83=A8=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E8=A7=A6=E6=8E=A7=E4=BA=8B=E4=BB=B6=E6=94=AF=E6=8C=81?= =?UTF-8?q?=EF=BC=88=E5=BE=85=E5=AE=8C=E5=96=84=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/gui/widget_event.h | 26 +++ src/gui/widget_event.c | 279 +++++++++++++++++++++++++++++++- 2 files changed, 298 insertions(+), 7 deletions(-) diff --git a/include/LCUI/gui/widget_event.h b/include/LCUI/gui/widget_event.h index cd32655b..b9c1c99e 100644 --- a/include/LCUI/gui/widget_event.h +++ b/include/LCUI/gui/widget_event.h @@ -67,6 +67,10 @@ enum WidgetEventType { WET_MOUSEUP, WET_MOUSEWHEEL, WET_CLICK, + WET_TOUCH, + WET_TOUCHDOWN, + WET_TOUCHUP, + WET_TOUCHMOVE, WET_TITLE, WET_SURFACE, @@ -80,6 +84,8 @@ typedef struct LCUI_WidgetEventRec_ { int x, y; /**< 事件触发时鼠标的坐标(相对于当前部件的边框盒) */ int z_delta; /**< 鼠标滚轮滚动的距离差值 */ int screen_x, screen_y; /**< 事件触发时鼠标的屏幕坐标 */ + int n_points; /**< 触点数量 */ + LCUI_TouchPoint points; /**< 触点列表 */ void *data; /**< 附加数据 */ LCUI_Widget target; /**< 触发事件的部件 */ LCUI_BOOL cancel_bubble; /**< 是否取消事件冒泡 */ @@ -163,6 +169,26 @@ LCUI_API void LCUIWidget_ClearEventTarget( LCUI_Widget widget ); /** 停止部件的事件传播 */ LCUI_API int Widget_StopEventPropagation( LCUI_Widget widget ); +/** 为部件设置鼠标捕获,设置后将捕获全局范围内的鼠标事件 */ +LCUI_API void Widget_SetMouseCapture( LCUI_Widget w ); + +/** 为部件解除鼠标捕获 */ +LCUI_API void Widget_ReleaseMouseCapture( LCUI_Widget w ); + +/** + * 为部件设置触点捕获,设置后将捕获全局范围内的触点事件 + * @param[in] w 部件 + * @param[in] point_id 触点ID,当值为 -1 时则捕获全部触点 + */ +LCUI_API void Widget_SetTouchCapture( LCUI_Widget w, int point_id ); + +/** + * 为部件解除触点捕获 + * @param[in] w 部件 + * @param[in] point_id 触点ID,当值为 -1 时则解除全部触点的捕获 + */ +LCUI_API int Widget_ReleaseTouchCapture( LCUI_Widget w, int point_id ); + /** 初始化 LCUI 部件的事件系统 */ void LCUIWidget_InitEvent(void); diff --git a/src/gui/widget_event.c b/src/gui/widget_event.c index 5e8e0c21..90a72da3 100644 --- a/src/gui/widget_event.c +++ b/src/gui/widget_event.c @@ -45,6 +45,11 @@ #include #include +typedef struct TouchCapturerRec_ { + LinkedList points; + LCUI_Widget widget; +} TouchCapturerRec, *TouchCapturer; + typedef struct WidgetEventHandlerRec_ { LCUI_WidgetEventFunc func; void *data; @@ -73,6 +78,8 @@ typedef struct EventRecordNodeRec_ { /** 当前功能模块的相关数据 */ static struct LCUIWidgetEvnetModule { + LCUI_Widget mouse_capturer; + LinkedList touch_capturers; LCUI_Widget targets[WST_TOTAL]; /**< 相关的部件 */ LCUI_RBTree event_records; /**< 当前正执行的事件的记录 */ LCUI_RBTree event_names; /**< 事件标识号 -> 名称映射表 */ @@ -167,6 +174,38 @@ static void WidgetEventTranslator( LCUI_Event e, LCUI_WidgetEventPack pack ) EventTrigger_Trigger( w->trigger, e->type, pack ); } +/** 复制部件事件包 */ +static void CopyWidgetEventPack( LCUI_WidgetEventPack dst, + const LCUI_WidgetEventPack src ) +{ + *dst = *src; + if( src->event.type == WET_TOUCH ) { + if( src->event.n_points > 0 ) { + int n = src->event.n_points; + size_t size = sizeof( LCUI_TouchPointRec ) * n; + dst->event.points = malloc( size ); + if( !dst->event.points ) { + return; + } + memcpy( dst->event.points, src->event.points, size ); + } + } +} + +/** 销毁部件事件包 */ +static void DestroyWidgetEventPack( void *arg ) +{ + LCUI_WidgetEventPack pack = arg; + if( pack->event.type == WET_TOUCH ) { + if( pack->event.n_points > 0 ) { + free( pack->event.points ); + } + pack->event.points = NULL; + pack->event.n_points = 0; + } + free( pack ); +} + /** 响应原始事件 */ static void OnWidgetEvent( LCUI_Event e, void *arg ) { @@ -183,14 +222,93 @@ static void OnWidgetEvent( LCUI_Event e, void *arg ) task.arg[1] = malloc( sizeof( LCUI_WidgetEventPackRec ) ); /* 这两个参数都需要在任务执行完后释放 */ task.destroy_arg[0] = free; - task.destroy_arg[1] = free; + task.destroy_arg[1] = DestroyWidgetEventPack; /* 复制所需数据,因为在本函数退出后,这两个参数会被销毁 */ *((LCUI_Event)task.arg[0]) = *e; - *((LCUI_WidgetEventPack)task.arg[1]) = *pack; + CopyWidgetEventPack( task.arg[1], pack ); /* 把任务扔给当前跑主循环的线程 */ LCUI_PostTask( &task ); } +static void DestroyTouchCapturer( void *arg ) +{ + TouchCapturer tc = arg; + LinkedList_Clear( &tc->points, free ); + tc->widget = NULL; + free( tc ); +} + +#define TouchCapturers_Clear(LIST) \ +LinkedList_Clear( LIST, DestroyTouchCapturer ) + +static void TouchCapturers_Add( LinkedList *list, LCUI_Widget w, int point_id ) +{ + int *data; + TouchCapturer tc = NULL; + LinkedListNode *node, *ptnode; + if( point_id < 0 ) { + tc = NEW( TouchCapturerRec, 1 ); + tc->widget = w; + LinkedList_Init( &tc->points ); + TouchCapturers_Clear( list ); + LinkedList_Append( list, tc ); + return; + } + /* 获取该部件的触点捕捉记录 */ + LinkedList_ForEach( node, list ) { + tc = node->data; + if( tc->widget == w ) { + break; + } + } + /* 如果没有该部件的触点捕捉记录 */ + if( !tc || tc->widget != w ) { + /* 清除与该触点绑定的其它捕捉记录 */ + LinkedList_ForEach( ptnode, list ) { + if( point_id != *(int*)ptnode->data ) { + continue; + } + free( ptnode->data ); + LinkedList_DeleteNode( list, ptnode ); + break; + } + tc = NEW( TouchCapturerRec, 1 ); + tc->widget = w; + LinkedList_Init( &tc->points ); + LinkedList_Append( list, tc ); + } + /* 追加触点捕捉记录 */ + data = NEW( int, 1 ); + *data = point_id; + LinkedList_Append( &tc->points, data ); +} + +static int TouchCapturers_Delete( LinkedList *list, LCUI_Widget w, int point_id ) +{ + TouchCapturer tc = NULL; + LinkedListNode *node, *ptnode; + LinkedList_ForEach( node, list ) { + tc = node->data; + if( tc->widget == w ) { + break; + } + } + if( !tc || tc->widget != w ) { + return -1; + } + if( point_id < 0 ) { + LinkedList_Clear( &tc->points, free );; + } else { + LinkedList_ForEach( ptnode, &tc->points ) { + if( *(int*)ptnode->data == point_id ) { + free( node->data ); + LinkedList_DeleteNode( &tc->points, ptnode ); + } + } + } + return 0; +} + int LCUIWidget_SetEventName( int event_id, const char *event_name ) { char *name; @@ -452,14 +570,18 @@ void LCUIWidget_ClearEventTarget( LCUI_Widget widget ) static void OnMouseEvent( LCUI_SysEvent e, void *arg ) { LCUI_Pos pos; - LCUI_WidgetEventRec ebuff; LCUI_Widget target, w; + LCUI_WidgetEventRec ebuff; w = LCUIWidget_GetRoot(); LCUICursor_GetPos( &pos ); - target = Widget_At( w, pos.x, pos.y ); - if( !target ) { - Widget_UpdateStatus( NULL, WST_HOVER ); - return; + if( self.mouse_capturer ) { + target = self.mouse_capturer; + } else { + target = Widget_At( w, pos.x, pos.y ); + if( !target ) { + Widget_UpdateStatus( NULL, WST_HOVER ); + return; + } } for( w = target; w; w = w->parent ) { if( w->event_blocked ) { @@ -526,6 +648,142 @@ static void OnInput( LCUI_SysEvent e, void *arg ) } +static void ConvertTouchPoint( LCUI_TouchPoint point ) +{ + switch( point->state ) { + case LCUI_TOUCHUP: point->state = WET_TOUCHUP; break; + case LCUI_TOUCHDOWN: point->state = WET_TOUCHDOWN; break; + case LCUI_TOUCHMOVE: point->state = WET_TOUCHMOVE; break; + default:break; + } +} + +static void OnTouchWithCapturers( LCUI_SysEvent sys_ev, void *arg ) +{ + int i, n; + TouchCapturer tc; + LCUI_TouchPoint points; + LCUI_WidgetEventRec ev; + LinkedListNode *node, *ptnode; + + ev.type = WET_TOUCH; + ev.cancel_bubble = FALSE; + n = sys_ev->touch.n_points; + points = sys_ev->touch.points; + ev.points = NEW( LCUI_TouchPointRec, n ); + LinkedList_ForEach( node, &self.touch_capturers ) { + tc = node->data; + ev.n_points = 0; + LinkedList_ForEach( ptnode, &tc->points ) { + for( i = 0; i < n; ++i ) { + if( points[i].id != *(int*)ptnode->data ) { + continue; + } + ev.points[ev.n_points] = points[i]; + ConvertTouchPoint( &ev.points[ev.n_points] ); + ++ev.n_points; + } + } + Widget_PostEvent( tc->widget, &ev, NULL, NULL ); + } +} + +static void OnTouchWithoutCapturers( LCUI_SysEvent sys_ev, void *arg ) +{ + int i, n; + TouchCapturer tc; + LinkedList capturers; + LCUI_TouchPoint points; + LCUI_WidgetEventRec ev; + LCUI_Widget target, root, w; + LinkedListNode *node, *ptnode; + + ev.type = WET_TOUCH; + ev.cancel_bubble = FALSE; + n = sys_ev->touch.n_points; + root = LCUIWidget_GetRoot(); + points = sys_ev->touch.points; + ev.points = NEW( LCUI_TouchPointRec, n ); + LinkedList_Init( &capturers ); + /* 先将各个触点按命中的部件进行分组 */ + for( i = 0; i < n; ++i ) { + target = Widget_At( root, points[i].x, points[i].y ); + if( !target ) { + continue; + } + for( w = target; w; w = w->parent ) { + if( w->event_blocked ) { + break; + } + } + if( w->event_blocked ) { + continue; + } + TouchCapturers_Add( &capturers, target, points[i].id ); + } + /* 然后向命中的部件发送触控事件 */ + LinkedList_ForEach( node, &capturers ) { + tc = node->data; + ev.n_points = 0; + for( i = 0; i < n; ++i ) { + /* 如果没有触点记录,则说明是捕获全部触点 */ + if( tc->points.length == 0 ) { + ev.points[ev.n_points] = points[i]; + ConvertTouchPoint( &ev.points[ev.n_points] ); + ++ev.n_points; + continue; + } + LinkedList_ForEach( ptnode, &tc->points ) { + if( points[i].id != *(int*)ptnode->data ) { + continue; + } + ev.points[ev.n_points] = points[i]; + ConvertTouchPoint( &ev.points[ev.n_points] ); + ++ev.n_points; + } + } + Widget_PostEvent( tc->widget, &ev, NULL, NULL ); + } + TouchCapturers_Clear( &capturers ); +} + +static void OnTouch( LCUI_SysEvent sys_ev, void *arg ) +{ + LCUIMutex_Lock( &self.mutex ); + if( self.touch_capturers.length > 0 ) { + OnTouchWithCapturers( sys_ev, arg ); + } else { + OnTouchWithoutCapturers( sys_ev, arg ); + } + LCUIMutex_Unlock( &self.mutex ); +} + +void Widget_SetMouseCapture( LCUI_Widget w ) +{ + self.mouse_capturer = w; +} + +void Widget_ReleaseMouseCapture( LCUI_Widget w ) +{ + self.mouse_capturer = NULL; +} + +void Widget_SetTouchCapture( LCUI_Widget w, int point_id ) +{ + LCUIMutex_Lock( &self.mutex ); + TouchCapturers_Add( &self.touch_capturers, w, point_id ); + LCUIMutex_Unlock( &self.mutex ); +} + +int Widget_ReleaseTouchCapture( LCUI_Widget w, int point_id ) +{ + int ret; + LCUIMutex_Lock( &self.mutex ); + ret = TouchCapturers_Delete( &self.touch_capturers, w, point_id ); + LCUIMutex_Unlock( &self.mutex ); + return ret; +} + int Widget_PostSurfaceEvent( LCUI_Widget w, int event_type ) { LCUI_Widget root; @@ -623,6 +881,7 @@ void LCUIWidget_InitEvent(void) RBTree_Init( &self.event_records ); self.targets[WST_ACTIVE] = NULL; self.targets[WST_HOVER] = NULL; + self.mouse_capturer = NULL; self.base_event_id = WET_USER + 1000; self.event_ids = Dict_Create( &DictType_String, NULL ); n = sizeof( mappings ) / sizeof( mappings[0] ); @@ -635,14 +894,20 @@ void LCUIWidget_InitEvent(void) LCUI_BindEvent( LCUI_MOUSEUP, OnMouseEvent, NULL, NULL ); LCUI_BindEvent( LCUI_KEYPRESS, OnKeyPress, NULL, NULL ); LCUI_BindEvent( LCUI_KEYDOWN, OnKeyDown, NULL, NULL ); + LCUI_BindEvent( LCUI_TOUCH, OnTouch, NULL, NULL ); LCUI_BindEvent( LCUI_INPUT, OnInput, NULL, NULL ); LCUI_BindEvent( LCUI_KEYUP, OnKeyUp, NULL, NULL ); RBTree_OnJudge( &self.event_records, CompareEventRecord ); + LinkedList_Init( &self.touch_capturers ); } void LCUIWidget_ExitEvent(void) { + LCUIMutex_Lock( &self.mutex ); RBTree_Destroy( &self.event_names ); RBTree_Destroy( &self.event_records ); Dict_Release( self.event_ids ); + TouchCapturers_Clear( &self.touch_capturers ); + LCUIMutex_Unlock( &self.mutex ); + LCUIMutex_Destroy( &self.mutex ); } From fd44e82da7433e3b89529d6a7e851315cf7e9342 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Thu, 2 Jun 2016 22:54:48 +0800 Subject: [PATCH 027/124] =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=83=A8=E5=88=86?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=92=8C=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/gui/widget.h | 1 - src/gui/css_parser.c | 11 ++++++----- src/gui/widget_base.c | 7 ++++--- src/gui/widget_paint.c | 1 + 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/include/LCUI/gui/widget.h b/include/LCUI/gui/widget.h index 924aeb1a..d265e22b 100644 --- a/include/LCUI/gui/widget.h +++ b/include/LCUI/gui/widget.h @@ -40,7 +40,6 @@ #ifndef LCUI_WIDGET_BUILD_H #define LCUI_WIDGET_BUILD_H -#include #include #include #include diff --git a/src/gui/css_parser.c b/src/gui/css_parser.c index 371254b3..7ba18bda 100644 --- a/src/gui/css_parser.c +++ b/src/gui/css_parser.c @@ -42,6 +42,7 @@ #include #include #include +#include #include /** 解析器的环境参数(上下文数据) */ @@ -69,11 +70,11 @@ typedef struct KeyNameGroup { char *name; } KeyNameGroup; -static struct { - LCUI_RBTree parser_tree; - LCUI_RBTree option_tree; - LCUI_RBTree name_tree; - int count; +static struct CSSParserModule { + LCUI_RBTree parser_tree; /**< 解析器树,以名称进行索引 */ + LCUI_RBTree option_tree; /**< 样式属性值树,以属性值进行索引 */ + LCUI_RBTree name_tree; /**< 样式属性名称树,以属性名称进行索引 */ + int count; /**< 当前记录的属性数量 */ } self; #define SPLIT_NUMBER 1 diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index 2937a81c..835be57f 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -42,13 +42,14 @@ #include #include #include +#include #include #undef max #define max(a,b) (((a) > (b)) ? (a) : (b)) static struct LCUIWidgetModule { - LCUI_Widget root; /** 获取根级部件 */ + LCUI_Widget root; /** 根级部件 */ LCUI_RBTree ids; /** 各种部件的ID索引 */ } LCUIWidget; @@ -58,8 +59,8 @@ LCUI_Widget LCUIWidget_GetRoot(void) } /** 刷新在追加部件后的状态,例如 :first-child 和 :last-child */ -static void Widget_UpdateStatusAfterAppend( LCUI_Widget w, - LCUI_BOOL is_remove_mode ) +static void Widget_UpdateStatusAfterAppend( LCUI_Widget w, + LCUI_BOOL is_remove_mode ) { LinkedListNode *node = Widget_GetNode( w ); if( w->index == 0 ) { diff --git a/src/gui/widget_paint.c b/src/gui/widget_paint.c index 5f1af90d..44c5fa9c 100644 --- a/src/gui/widget_paint.c +++ b/src/gui/widget_paint.c @@ -42,6 +42,7 @@ #include #include #include +#include #include /** 判断部件是否有可绘制内容 */ From c67b16de0a0637e927c5f01b6f8900d988fc6812 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Fri, 3 Jun 2016 15:39:47 +0800 Subject: [PATCH 028/124] update configure.ac #33 --- configure.ac | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/configure.ac b/configure.ac index 1a4702f4..d9ef9a60 100755 --- a/configure.ac +++ b/configure.ac @@ -53,7 +53,7 @@ if test "x$with_iconv" != "xno"; then AC_CHECK_LIB([iconv], [iconv_open], [ want_iconv=yes LCUI_LIBADD="$LCUI_LIBADD -liconv" - AC_DEFINE_UNQUOTED(USE_LIBICONV, 1, Define to 1 if you have the libiconv) + AC_DEFINE_UNQUOTED([USE_LIBICONV], 1, [Define to 1 if you have the libiconv.]) ], want_iconv=no) fi @@ -67,30 +67,30 @@ if test "x$with_pthread" != "xno"; then CC="$PTHREAD_CC" CFLAGS="$CFLAGS $PTHREAD_CFLAGS" LCUI_LIBS="$LCUI_LIBS $PTHREAD_LIBS" - AC_DEFINE_UNQUOTED(LCUI_THREAD_PTHREAD, 1, Define to 1 if you are using pthread support) - ], [AC_MSG_ERROR(The support could not be configured for the POSIX thread programming interface.)]) + AC_DEFINE_UNQUOTED([LCUI_THREAD_PTHREAD], 1, [Define to 1 if you are using pthread support.]) + ], [AC_MSG_ERROR([The support could not be configured for the POSIX thread programming interface.])]) fi ##检测是否有libxml2库,必须有 libxml2 库才能启用 LCUIBuilder 功能模块 enable_builder=yes AC_ARG_ENABLE(lcui-builder, AC_HELP_STRING([--enable-lcui-builder], -[enable lcui-builder function module [[default=no]]]), enable_builder=$enableval) +[enable lcui-builder function module [[default=no]]]), [enable_builder=$enableval]) if test "$enable_builder" = "yes"; then AC_CHECK_HEADERS([libxml/parser.h],[ AC_CHECK_LIB([xml2], [xmlParseFile], [ enable_builder=yes LCUI_LIBS="$LCUI_LIBS -lxml2" CFLAGS="$CFLAGS -I/usr/include/libxml2" - AC_DEFINE_UNQUOTED(USE_LCUI_BUILDER, 1, Define to 1 if you enabled LCUIBuilder function module) - ], enable_builder=no) - ], enable_builder=no) + AC_DEFINE_UNQUOTED([USE_LCUI_BUILDER], 1, [Define to 1 if you enabled LCUIBuilder function module.]) + ], [enable_builder=no]) + ], [enable_builder=no]) fi ##检测是否有freetype库 want_font_engine=yes font_engine_name=none AC_ARG_ENABLE(font-engine, AC_HELP_STRING([--enable-font-engine], -[turn on font-engine [[default=yes]]]), want_font_engine=$enableval) +[turn on font-engine [[default=yes]]]), [want_font_engine=$enableval]) if test "$want_font_engine" = yes; then AC_CHECK_HEADERS([ft2build.h], [ AC_CHECK_LIB([freetype], [FT_Init_FreeType], [ @@ -98,8 +98,8 @@ if test "$want_font_engine" = yes; then font_engine_name=freetype2 LCUI_LIBS="$LCUI_LIBS `pkg-config --libs freetype2`" CFLAGS="$CFLAGS `pkg-config --cflags-only-I freetype2`" - AC_DEFINE_UNQUOTED(LCUI_FONT_ENGINE_FREETYPE, 1, Define to 1 if you have the FreeType font engine) - ], want_font_engine=no) + AC_DEFINE_UNQUOTED([LCUI_FONT_ENGINE_FREETYPE], 1, [Define to 1 if you have the FreeType font engine.]) + ], [want_font_engine=no]) ], [want_font_engine=no]) else want_font_engine=no @@ -109,18 +109,18 @@ fi want_video_output=yes video_driver_name=framebuffer AC_ARG_ENABLE(video-output, AC_HELP_STRING([--enable-video-output], -[turn on video-output [[default=yes]]]), want_video_output=$enableval) +[turn on video-output [[default=yes]]]), [want_video_output=$enableval]) if test "$want_video_output" = yes; then AC_CHECK_HEADERS([linux/fb.h],[ video_driver_name=framebuffer - AC_DEFINE_UNQUOTED(LCUI_VIDEO_DRIVER_FRAMEBUFFER, 1, Define to 1 if you select FrameBuffer for video support) + AC_DEFINE_UNQUOTED([LCUI_VIDEO_DRIVER_FRAMEBUFFER], 1, [Define to 1 if you select FrameBuffer for video support.]) ], [video_driver_name=none]) AC_CHECK_HEADERS([X11/Xlib.h],[ AC_CHECK_LIB([X11], [XOpenDisplay], [ video_driver_name=x11 LCUI_LIBS="$LCUI_LIBS `pkg-config --libs x11`" CFLAGS="$CFLAGS `pkg-config --cflags-only-I x11`" - AC_DEFINE_UNQUOTED(LCUI_VIDEO_DRIVER_X11, 1, Define to 1 if you select XWindow for video support) + AC_DEFINE_UNQUOTED([LCUI_VIDEO_DRIVER_X11], 1, [Define to 1 if you select XWindow for video support.]) ], []) ], []) else @@ -134,8 +134,8 @@ if test "x$with_ts" != "xno"; then AC_CHECK_LIB([ts], [ts_open], [ want_ts=yes LCUI_LIBS="$LCUI_LIBS -lts" - AC_DEFINE_UNQUOTED(USE_TSLIB, 1, Define to 1 if you have the tslib) - ], want_ts=no) + AC_DEFINE_UNQUOTED([USE_TSLIB], 1, [Define to 1 if you have the tslib]) + ], [want_ts=no]) fi want_png=no @@ -146,9 +146,9 @@ if test "x$with_png" != "xno"; then want_png=yes LCUI_LIBS="$LCUI_LIBS `pkg-config --libs libpng`" CFLAGS="$CFLAGS `pkg-config --cflags-only-I libpng`" - AC_DEFINE_UNQUOTED(USE_LIBPNG, 1, Define to 1 if you have the libpng) - ],want_png=no) - ],want_png=no) + AC_DEFINE_UNQUOTED([USE_LIBPNG], 1, [Define to 1 if you have the libpng.]) + ], [want_png=no]) + ], [want_png=no]) fi want_jpeg=no @@ -158,9 +158,9 @@ if test "x$with_jpeg" != "xno"; then AC_CHECK_LIB([jpeg], [jpeg_start_decompress],[ want_jpeg=yes LCUI_LIBS="$LCUI_LIBS -ljpeg" - AC_DEFINE_UNQUOTED(USE_LIBJPEG, 1, Define to 1 if you have the libjpeg) - ],want_jpeg=no) - ],want_jpeg=no) + AC_DEFINE_UNQUOTED([USE_LIBJPEG], 1, [Define to 1 if you have the libjpeg]) + ], [want_jpeg=no]) + ], [want_jpeg=no]) fi # DEBUG option From 2b7c31c372199b9f7cb244f9097a772989b9bcef Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Fri, 3 Jun 2016 23:08:53 +0800 Subject: [PATCH 029/124] update framectrl.c #34 --- include/LCUI/util/framectrl.h | 16 +++---- src/display.c | 2 +- src/util/framectrl.c | 86 +++++++++++++++-------------------- 3 files changed, 45 insertions(+), 59 deletions(-) diff --git a/include/LCUI/util/framectrl.h b/include/LCUI/util/framectrl.h index d8f72216..0a648622 100644 --- a/include/LCUI/util/framectrl.h +++ b/include/LCUI/util/framectrl.h @@ -44,29 +44,29 @@ LCUI_BEGIN_HEADER #ifdef LCUI_UTIL_FRAMECTRL_C -typedef struct FrameControlContext* FrameCtrlCtx; +typedef struct FrameControlRec_* FrameControl; #else -typedef void* FrameCtrlCtx; +typedef void* FrameControl; #endif /** 新建帧数控制实例 */ -LCUI_API FrameCtrlCtx FrameControl_Create( void ); +LCUI_API FrameControl FrameControl_Create( void ); /** 销毁帧数控制相关资源 */ -LCUI_API void FrameControl_Destroy( FrameCtrlCtx ctx ); +LCUI_API void FrameControl_Destroy( FrameControl ctx ); /** 设置最大FPS(帧数/秒) */ -LCUI_API void FrameControl_SetMaxFPS( FrameCtrlCtx ctx, unsigned int fps ); +LCUI_API void FrameControl_SetMaxFPS( FrameControl ctx, unsigned int fps ); /** 获取当前FPS */ -LCUI_API int FrameControl_GetFPS( FrameCtrlCtx ctx ); +LCUI_API int FrameControl_GetFPS( FrameControl ctx ); /** 让当前帧停留一定时间 */ -LCUI_API void FrameControl_Remain( FrameCtrlCtx ctx ); +LCUI_API void FrameControl_Remain( FrameControl ctx ); /** 暂停数据帧的更新 */ -LCUI_API void FrameControl_Pause( FrameCtrlCtx ctx, LCUI_BOOL need_pause ); +LCUI_API void FrameControl_Pause( FrameControl ctx, LCUI_BOOL need_pause ); LCUI_END_HEADER diff --git a/src/display.c b/src/display.c index 17ee3395..81f096dc 100644 --- a/src/display.c +++ b/src/display.c @@ -63,7 +63,7 @@ static struct DisplayContext { int mode; /**< 显示模式 */ LCUI_BOOL show_rect_border; /**< 是否为重绘的区域显示边框 */ LCUI_BOOL is_working; /**< 标志,指示当前模块是否处于工作状态 */ - FrameCtrlCtx fc_ctx; /**< 上下文句柄,用于画面更新时的帧数控制 */ + FrameControl fc_ctx; /**< 上下文句柄,用于画面更新时的帧数控制 */ LCUI_Thread thread; /**< 线程,负责画面更新工作 */ LinkedList surfaces; /**< surface 列表 */ LCUI_Mutex mutex; diff --git a/src/util/framectrl.c b/src/util/framectrl.c index 5e8ffbd1..da180df5 100644 --- a/src/util/framectrl.c +++ b/src/util/framectrl.c @@ -40,20 +40,20 @@ #define LCUI_UTIL_FRAMECTRL_C -#include #include #include #include #include -#define STATE_RUN 0 -#define STATE_PAUSE 1 -#define STATE_QUIT 2 +enum FrameControlState { + STATE_RUN, + STATE_PAUSE, + STATE_QUIT +}; -struct FrameControlContext { +typedef struct FrameControlRec_ { int state; - LCUI_Cond wait_continue; - LCUI_Cond wait_pause; + LCUI_Cond cond; LCUI_Mutex mutex; unsigned int temp_fps; unsigned int current_fps; @@ -61,51 +61,43 @@ struct FrameControlContext { unsigned int pause_time; int64_t prev_frame_start_time; int64_t prev_fps_update_time; -}; +} FrameControlRec; -/** 新建帧数控制实例 */ -FrameCtrlCtx FrameControl_Create( void ) +FrameControl FrameControl_Create( void ) { - FrameCtrlCtx ctx; - ctx = (FrameCtrlCtx)malloc(sizeof(struct FrameControlContext)); + FrameControl ctx; + ctx = NEW( FrameControlRec, 1 ); ctx->temp_fps = 0; ctx->current_fps = 0; ctx->pause_time = 0; ctx->one_frame_remain_time = 10; ctx->prev_frame_start_time = LCUI_GetTickCount(); ctx->prev_fps_update_time = LCUI_GetTickCount(); - LCUICond_Init( &ctx->wait_continue ); - LCUICond_Init( &ctx->wait_pause ); + LCUICond_Init( &ctx->cond ); LCUIMutex_Init( &ctx->mutex ); return ctx; } -/** 销毁帧数控制相关资源 */ -void FrameControl_Destroy( FrameCtrlCtx ctx ) +void FrameControl_Destroy( FrameControl ctx ) { LCUIMutex_Unlock( &ctx->mutex ); - LCUICond_Destroy( &ctx->wait_continue ); - LCUICond_Destroy( &ctx->wait_pause ); + LCUICond_Destroy( &ctx->cond ); LCUIMutex_Destroy( &ctx->mutex ); free( ctx ); } -/** 设置最大FPS(帧数/秒) */ -void FrameControl_SetMaxFPS( FrameCtrlCtx ctx, unsigned int fps ) +void FrameControl_SetMaxFPS( FrameControl ctx, unsigned int fps ) { ctx->one_frame_remain_time = (int)(1000.0/fps); } -/** 获取当前FPS */ -int FrameControl_GetFPS( FrameCtrlCtx ctx ) +int FrameControl_GetFPS( FrameControl ctx ) { return ctx->current_fps; } -/** 让当前帧停留一定时间 */ -void FrameControl_Remain( FrameCtrlCtx ctx ) +void FrameControl_Remain( FrameControl ctx ) { - int ret; int64_t current_time; unsigned int n_ms, lost_ms; @@ -123,27 +115,24 @@ void FrameControl_Remain( FrameCtrlCtx ctx ) if( n_ms < 1 ) { goto normal_exit; } - while( lost_ms < n_ms ) { - /* 进行睡眠,直到需要暂停为止 */ - ret = LCUICond_TimedWait( &ctx->wait_pause, &ctx->mutex, - n_ms - lost_ms ); - if( ret == ETIMEDOUT || ret == 0 ) { - break; - } + /* 睡眠一段时间 */ + while( lost_ms < n_ms && ctx->state == STATE_RUN ) { + LCUICond_TimedWait( &ctx->cond, &ctx->mutex, n_ms - lost_ms ); lost_ms = (unsigned int)LCUI_GetTicks( current_time ); } - /* 睡眠结束后,如果当前状态不为PAUSE,则说明睡眠不是因为要暂停而终止的 */ - if( ctx->state != STATE_PAUSE ) { - goto normal_exit; + /* 睡眠结束后,如果当前状态为 PAUSE,则说明睡眠是因为要暂停而终止的 */ + if( ctx->state == STATE_PAUSE ) { + current_time = LCUI_GetTickCount(); + /* 等待状态改为“继续” */ + while( ctx->state == STATE_PAUSE ) { + LCUICond_Wait( &ctx->cond, &ctx->mutex ); + } + lost_ms = (unsigned int)LCUI_GetTicks( current_time ); + ctx->pause_time = lost_ms; + ctx->prev_frame_start_time += lost_ms; + LCUIMutex_Unlock( &ctx->mutex ); + return; } - current_time = LCUI_GetTickCount(); - /* 需要暂停,进行睡眠,直到需要继续为止 */ - while( LCUICond_Wait( &ctx->wait_continue, &ctx->mutex ) != 0 ); - lost_ms = (unsigned int)LCUI_GetTicks( current_time ); - ctx->pause_time = lost_ms; - ctx->prev_frame_start_time += lost_ms; - LCUIMutex_Unlock( &ctx->mutex ); - return; normal_exit:; current_time = LCUI_GetTickCount(); @@ -157,20 +146,17 @@ normal_exit:; LCUIMutex_Unlock( &ctx->mutex ); } -/** 暂停数据帧的更新 */ -void FrameControl_Pause( FrameCtrlCtx ctx, LCUI_BOOL need_pause ) +void FrameControl_Pause( FrameControl ctx, LCUI_BOOL need_pause ) { if( ctx->state == STATE_RUN && need_pause ) { LCUIMutex_Lock( &ctx->mutex ); ctx->state = STATE_PAUSE; - LCUICond_Signal( &ctx->wait_pause ); + LCUICond_Signal( &ctx->cond ); LCUIMutex_Unlock( &ctx->mutex ); - } - else if( ctx->state == STATE_PAUSE && !need_pause ){ + } else if( ctx->state == STATE_PAUSE && !need_pause ) { LCUIMutex_Lock( &ctx->mutex ); ctx->state = STATE_RUN; - LCUICond_Signal( &ctx->wait_continue ); + LCUICond_Signal( &ctx->cond ); LCUIMutex_Unlock( &ctx->mutex ); } } - From b68b87094315054c9c61f7ec56690555ca64eaf8 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Fri, 3 Jun 2016 23:12:54 +0800 Subject: [PATCH 030/124] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=A7=A6=E6=8E=A7?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gui/widget_base.c | 2 ++ src/gui/widget_event.c | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index 835be57f..bb5d14ca 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -230,6 +230,8 @@ static void Widget_OnDestroy( void *arg ) void Widget_ExecDestroy( LCUI_Widget widget ) { + Widget_ReleaseMouseCapture( widget ); + Widget_ReleaseTouchCapture( widget, -1 ); Widget_StopEventPropagation( widget ); LCUIWidget_ClearEventTarget( widget ); /* 先释放显示列表,后销毁部件列表,因为部件在这两个链表中的节点是和它共用 diff --git a/src/gui/widget_event.c b/src/gui/widget_event.c index 90a72da3..cc4a619e 100644 --- a/src/gui/widget_event.c +++ b/src/gui/widget_event.c @@ -48,6 +48,7 @@ typedef struct TouchCapturerRec_ { LinkedList points; LCUI_Widget widget; + LinkedListNode node; } TouchCapturerRec, *TouchCapturer; typedef struct WidgetEventHandlerRec_ { @@ -274,8 +275,9 @@ static void TouchCapturers_Add( LinkedList *list, LCUI_Widget w, int point_id ) } tc = NEW( TouchCapturerRec, 1 ); tc->widget = w; + tc->node.data = tc; LinkedList_Init( &tc->points ); - LinkedList_Append( list, tc ); + LinkedList_AppendNode( list, &tc->node ); } /* 追加触点捕捉记录 */ data = NEW( int, 1 ); @@ -287,7 +289,8 @@ static int TouchCapturers_Delete( LinkedList *list, LCUI_Widget w, int point_id { TouchCapturer tc = NULL; LinkedListNode *node, *ptnode; - LinkedList_ForEach( node, list ) { + LinkedList_ForEach( node, list ) + { tc = node->data; if( tc->widget == w ) { break; @@ -297,15 +300,20 @@ static int TouchCapturers_Delete( LinkedList *list, LCUI_Widget w, int point_id return -1; } if( point_id < 0 ) { - LinkedList_Clear( &tc->points, free );; + LinkedList_Clear( &tc->points, free ); } else { - LinkedList_ForEach( ptnode, &tc->points ) { + LinkedList_ForEach( ptnode, &tc->points ) + { if( *(int*)ptnode->data == point_id ) { free( node->data ); LinkedList_DeleteNode( &tc->points, ptnode ); } } } + if( tc->points.length == 0 ) { + LinkedList_Unlink( &self.touch_capturers, &tc->node ); + free( tc ); + } return 0; } @@ -716,7 +724,7 @@ static void OnTouchWithoutCapturers( LCUI_SysEvent sys_ev, void *arg ) break; } } - if( w->event_blocked ) { + if( w && w->event_blocked ) { continue; } TouchCapturers_Add( &capturers, target, points[i].id ); @@ -867,6 +875,10 @@ void LCUIWidget_InitEvent(void) { WET_CLICK, "click" }, { WET_MOUSEOUT, "mouseout" }, { WET_MOUSEOVER, "mouseover" }, + { WET_TOUCH, "touch" }, + { WET_TOUCHDOWN, "touchdown" }, + { WET_TOUCHMOVE, "touchmove" }, + { WET_TOUCHUP, "touchup" }, { WET_RESIZE, "resize" }, { WET_AFTERLAYOUT, "afterlayout" }, { WET_FOCUS, "focus" }, From 887327a3d140f6239b3141acf13b3e94559dda23 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Fri, 3 Jun 2016 23:13:50 +0800 Subject: [PATCH 031/124] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=A7=A6=E6=8E=A7?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=B5=8B=E8=AF=95=E7=A8=8B=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/VS2012/LCUI-Demo.sln | 10 ++ build/VS2012/testtouch/testtouch.vcxproj | 107 ++++++++++++++++++ .../testtouch/testtouch.vcxproj.filters | 22 ++++ test/helloworld.c | 3 +- test/testtouch.c | 95 ++++++++++++++++ 5 files changed, 236 insertions(+), 1 deletion(-) create mode 100644 build/VS2012/testtouch/testtouch.vcxproj create mode 100644 build/VS2012/testtouch/testtouch.vcxproj.filters create mode 100644 test/testtouch.c diff --git a/build/VS2012/LCUI-Demo.sln b/build/VS2012/LCUI-Demo.sln index ab665613..a2a5306b 100644 --- a/build/VS2012/LCUI-Demo.sln +++ b/build/VS2012/LCUI-Demo.sln @@ -7,6 +7,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "helloworld", "helloworld\he EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LCUITest", "LCUITest\LCUITest.vcxproj", "{D639E1FA-B41B-40E5-8EC8-6FA3E5D946E7}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testtouch", "testtouch\testtouch.vcxproj", "{E5E79245-9412-49C8-8FE7-3AF7A7111E2F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|ARM = Debug|ARM @@ -33,6 +35,14 @@ Global {D639E1FA-B41B-40E5-8EC8-6FA3E5D946E7}.Release|Win32.ActiveCfg = Release|Win32 {D639E1FA-B41B-40E5-8EC8-6FA3E5D946E7}.Release|Win32.Build.0 = Release|Win32 {D639E1FA-B41B-40E5-8EC8-6FA3E5D946E7}.Release|x64.ActiveCfg = Release|Win32 + {E5E79245-9412-49C8-8FE7-3AF7A7111E2F}.Debug|ARM.ActiveCfg = Debug|Win32 + {E5E79245-9412-49C8-8FE7-3AF7A7111E2F}.Debug|Win32.ActiveCfg = Debug|Win32 + {E5E79245-9412-49C8-8FE7-3AF7A7111E2F}.Debug|Win32.Build.0 = Debug|Win32 + {E5E79245-9412-49C8-8FE7-3AF7A7111E2F}.Debug|x64.ActiveCfg = Debug|Win32 + {E5E79245-9412-49C8-8FE7-3AF7A7111E2F}.Release|ARM.ActiveCfg = Release|Win32 + {E5E79245-9412-49C8-8FE7-3AF7A7111E2F}.Release|Win32.ActiveCfg = Release|Win32 + {E5E79245-9412-49C8-8FE7-3AF7A7111E2F}.Release|Win32.Build.0 = Release|Win32 + {E5E79245-9412-49C8-8FE7-3AF7A7111E2F}.Release|x64.ActiveCfg = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/build/VS2012/testtouch/testtouch.vcxproj b/build/VS2012/testtouch/testtouch.vcxproj new file mode 100644 index 00000000..806fd875 --- /dev/null +++ b/build/VS2012/testtouch/testtouch.vcxproj @@ -0,0 +1,107 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {E5E79245-9412-49C8-8FE7-3AF7A7111E2F} + Win32Proj + testtouch + 8.1 + + + + Application + true + v110 + Unicode + + + Application + false + v140_xp + true + MultiByte + + + + + + + + + + + + + true + AllRules.ruleset + + + $(SolutionDir)..\..\bin\ + $(SolutionDir)..\..\bin\$(Configuration)\ + + + false + AllRules.ruleset + + + $(SolutionDir)..\..\bin\ + $(SolutionDir)..\..\bin\$(Configuration)\ + + + + + + Level3 + Disabled + WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + $(SolutionDir)\include;$(SolutionDir)\include\..\..\..\include;%(AdditionalIncludeDirectories) + CompileAsC + + + Windows + true + $(OutDir) + LCUI_D.lib;LCUIMain.lib; + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + $(SolutionDir)\include;$(SolutionDir)\include\..\..\..\include;%(AdditionalIncludeDirectories) + 4819 + true + + + Windows + true + true + true + $(OutDir) + LCUI.lib + + + true + + + + + + + + + \ No newline at end of file diff --git a/build/VS2012/testtouch/testtouch.vcxproj.filters b/build/VS2012/testtouch/testtouch.vcxproj.filters new file mode 100644 index 00000000..f7629373 --- /dev/null +++ b/build/VS2012/testtouch/testtouch.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 源文件 + + + \ No newline at end of file diff --git a/test/helloworld.c b/test/helloworld.c index bd60b78a..7c4b0ca4 100755 --- a/test/helloworld.c +++ b/test/helloworld.c @@ -1,4 +1,5 @@ -#include +#include +#include #include #include #include diff --git a/test/testtouch.c b/test/testtouch.c new file mode 100644 index 00000000..7c8b611f --- /dev/null +++ b/test/testtouch.c @@ -0,0 +1,95 @@ +/** testtouch.c -- test touch support */ + +#include +#include +#include +#include +#include +#include + +/** 触点绑定记录 */ +typedef struct TouchPointBindingRec_ { + int point_id; /**< 触点 ID */ + LCUI_Widget widget; /**< 部件 */ + LinkedListNode node; /**< 在链表中的结点 */ + LCUI_BOOL is_valid; /**< 是否有效 */ +} TouchPointBindingRec, *TouchPointBinding; + +/** 触点绑定记录列表 */ +static LinkedList touch_bindings; + +static void OnTouchWidget( LCUI_Widget w, LCUI_WidgetEvent e, void *arg ) +{ + LCUI_TouchPoint point; + TouchPointBinding binding; + if( e->n_points == 0 ) { + return; + } + binding = e->data; + point = & e->points[0]; + switch( point->state ) { + case WET_TOUCHMOVE: + Widget_Move( binding->widget, point->x - 32, point->y - 32 ); + break; + case WET_TOUCHUP: + if( !binding->is_valid ) { + break; + } + /* 当触点释放后销毁部件及绑定记录 */ + Widget_ReleaseTouchCapture( binding->widget, -1 ); + LinkedList_Unlink( &touch_bindings, &binding->node ); + binding->is_valid = FALSE; + Widget_Destroy( w ); + free( binding ); + break; + case WET_TOUCHDOWN: + default: break; + } +} + +static void OnTouch( LCUI_SysEvent e, void *arg ) +{ + int i; + LinkedListNode *node; + LCUI_StyleSheet sheet; + LCUI_TouchPoint point; + for( i = 0; i < e->touch.n_points; ++i ) { + TouchPointBinding binding; + LCUI_BOOL is_existed = FALSE; + point = &e->touch.points[i]; + /* 检查该触点是否已经被绑定 */ + LinkedList_ForEach( node, &touch_bindings ) { + binding = node->data; + if( binding->point_id == point->id ) { + is_existed = TRUE; + } + } + if( is_existed ) { + continue; + } + /* 新建绑定记录 */ + binding = NEW( TouchPointBindingRec, 1 ); + binding->widget = LCUIWidget_New( NULL ); + binding->point_id = point->id; + binding->is_valid = TRUE; + binding->node.data = binding; + Widget_Resize( binding->widget, 64, 64 ); + Widget_Move( binding->widget, point->x - 32, point->y - 32 ); + /* 设置让该部件捕获当前触点 */ + Widget_SetTouchCapture( binding->widget, binding->point_id ); + Widget_BindEvent( binding->widget, "touch", OnTouchWidget, binding, NULL ); + sheet = binding->widget->custom_style; + SetStyle( sheet, key_position, SV_ABSOLUTE, style ); + SetStyle( sheet, key_background_color, RGB( 255, 0, 0 ), color ); + LinkedList_AppendNode( &touch_bindings, &binding->node ); + Widget_Top( binding->widget ); + } +} + +int main( int argc, char **argv ) +{ + LCUI_Init(); + LinkedList_Init( &touch_bindings ); + LCUI_BindEvent( LCUI_TOUCH, OnTouch, NULL, NULL ); + return LCUI_Main(); +} From 33b2c1663204b399ab990b5e8195b25163b11e63 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Sat, 4 Jun 2016 22:26:29 +0800 Subject: [PATCH 032/124] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=BB=9A=E5=8A=A8?= =?UTF-8?q?=E6=9D=A1=E7=9A=84=E8=A7=A6=E6=8E=A7=E4=BA=8B=E4=BB=B6=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gui/widget/scrollbar.c | 161 ++++++++++++++++++------------------- src/gui/widget_event.c | 2 +- 2 files changed, 78 insertions(+), 85 deletions(-) diff --git a/src/gui/widget/scrollbar.c b/src/gui/widget/scrollbar.c index 11207b45..76ed036b 100644 --- a/src/gui/widget/scrollbar.c +++ b/src/gui/widget/scrollbar.c @@ -76,9 +76,6 @@ typedef struct LCUI_ScrollBarRec_ { int old_pos; /**< 拖拽开始时的位置 */ int distance; /**< 滚动距离 */ InertialScrollingRec effect; /**< 用于实现惯性滚动效果的相关数据 */ - int eid_mousemove; /**< MOUSEMOVE 事件的绑定ID */ - int eid_mouseup; /**< MOUSEUP 事件的绑定ID */ - int eid_touch; /**< TOUCH 事件的绑定ID */ } LCUI_ScrollBarRec, *LCUI_ScrollBar; static int scroll_event_id = -1; @@ -185,38 +182,13 @@ static void ScrollBar_StartInertialScrolling( LCUI_Widget w ) effect->speed, distance, (int)time_delta); } -static void OnMouseUp( LCUI_SysEvent e, void *arg ) -{ - LCUI_Widget w = e->data; - LCUI_ScrollBar scrollbar = w->private_data; - if( scrollbar->eid_mousemove > 0 ) { - LCUI_UnbindEvent( scrollbar->eid_mousemove ); - } - if( scrollbar->eid_mouseup > 0 ) { - LCUI_UnbindEvent( scrollbar->eid_mouseup ); - } - if( scrollbar->eid_touch > 0 ) { - LCUI_UnbindEvent( scrollbar->eid_touch ); - if( scrollbar->is_dragging ) { - ScrollBar_StartInertialScrolling( w ); - } - } - scrollbar->is_dragging = FALSE; - scrollbar->eid_mousemove = -1; - scrollbar->eid_mouseup = -1; - scrollbar->eid_touch = -1; - if( scrollbar->layer ) { - Widget_BlockEvent( scrollbar->layer, FALSE ); - } -} - -static void Slider_OnMouseMove( LCUI_SysEvent e, void *arg ) +static void Slider_OnMouseMove( LCUI_Widget slider, + LCUI_WidgetEvent e, void *arg ) { float n; LCUI_Pos pos; LCUI_Widget w = e->data; LCUI_ScrollBar scrollbar = w->private_data; - LCUI_Widget slider = scrollbar->slider; LCUI_Widget layer = scrollbar->layer; int x, y, box_size, size, layer_pos; @@ -282,45 +254,24 @@ static void Slider_OnMouseMove( LCUI_SysEvent e, void *arg ) } scrollbar->pos = layer_pos; Widget_UpdateStyle( layer, FALSE ); - Widget_Move( scrollbar->slider, x, y ); + Widget_Move( slider, x, y ); } -/** 滚动层的触屏事件响应 */ -static void ScrollLayer_OnTouch( LCUI_SysEvent e, void *arg ) +static void Slider_OnMouseUp( LCUI_Widget slider, + LCUI_WidgetEvent e, void *arg ) { - int pos, distance; - LCUI_TouchPoint point; LCUI_Widget w = e->data; - LCUI_ScrollBar scrollbar; - if( e->touch.n_points < 1 ) { - return; - } - point = &e->touch.points[0]; - if( point->state != LCUI_TOUCHMOVE ) { - return; - } - scrollbar = w->private_data; - pos = scrollbar->old_pos - (point->y - scrollbar->mouse_y); - if( pos != scrollbar->pos ) { - if( !scrollbar->is_dragging ) { - scrollbar->is_dragging = TRUE; - LCUIWidget_ClearEventTarget( NULL ); - Widget_BlockEvent( scrollbar->layer, TRUE ); - } - distance = pos - scrollbar->pos; - if( (scrollbar->distance > 0) != (distance > 0) || - scrollbar->distance == 0 ) { - ScrollBar_UpdateInertialScrolling( w ); - } - scrollbar->distance = distance; - } - ScrollBar_SetPosition( w, pos ); + LCUI_ScrollBar scrollbar = w->private_data; + Widget_UnbindEvent( slider, "mousemove", Slider_OnMouseMove ); + Widget_UnbindEvent( slider, "mouseup", Slider_OnMouseUp ); + Widget_ReleaseMouseCapture( slider ); + scrollbar->is_dragging = FALSE; } -static void Slider_OnMouseDown( LCUI_Widget slider, LCUI_WidgetEvent e, - void *arg ) +static void Slider_OnMouseDown( LCUI_Widget slider, + LCUI_WidgetEvent e, void *arg ) { - LCUI_Widget w = slider->parent; + LCUI_Widget w = e->data; LCUI_ScrollBar scrollbar = w->private_data; if( scrollbar->is_dragging ) { return; @@ -330,11 +281,9 @@ static void Slider_OnMouseDown( LCUI_Widget slider, LCUI_WidgetEvent e, scrollbar->mouse_x = e->screen_x; scrollbar->mouse_y = e->screen_y; scrollbar->is_dragging = TRUE; - scrollbar->eid_mousemove = LCUI_BindEvent( LCUI_MOUSEMOVE, - Slider_OnMouseMove, - w, NULL ); - scrollbar->eid_mouseup = LCUI_BindEvent( LCUI_MOUSEUP, - OnMouseUp, w, NULL ); + Widget_SetMouseCapture( slider ); + Widget_BindEvent( slider, "mousemove", Slider_OnMouseMove, w, NULL ); + Widget_BindEvent( slider, "mouseup", Slider_OnMouseUp, w, NULL ); } static void ScrollBar_OnInit( LCUI_Widget w ) @@ -346,9 +295,6 @@ static void ScrollBar_OnInit( LCUI_Widget w ) self->direction = SBD_VERTICAL; self->is_dragging = FALSE; self->scroll_step = 40; - self->eid_mousemove = -1; - self->eid_mouseup = -1; - self->eid_touch = -1; self->slider = slider; self->layer = NULL; self->box = NULL; @@ -363,7 +309,7 @@ static void ScrollBar_OnInit( LCUI_Widget w ) self->effect.is_running = FALSE; self->effect.interval = 1000 / EFFECT_FRAMES; Widget_BindEvent( slider, "mousedown", - Slider_OnMouseDown, NULL, NULL ); + Slider_OnMouseDown, w, NULL ); Widget_AddClass( slider, "slider" ); Widget_Append( w, slider ); } @@ -419,23 +365,70 @@ static void ScrollLayer_OnWheel( LCUI_Widget layer, LCUI_WidgetEvent e, void *ar ScrollBar_SetPosition( w, pos ); } -static void ScrollLayer_OnMouseDown( LCUI_Widget layer, LCUI_WidgetEvent e, void *arg ) +/** 滚动层的触屏事件响应 */ +static void ScrollLayer_OnTouch( LCUI_Widget layer, LCUI_WidgetEvent e, void *arg ) { + int i, pos, distance; + LCUI_TouchPoint point; LCUI_Widget w = e->data; LCUI_ScrollBar scrollbar; - scrollbar = w->private_data; - scrollbar->distance = 0; - scrollbar->effect.speed = 0; - scrollbar->effect.is_running = FALSE; - scrollbar->old_pos = scrollbar->pos; - if( scrollbar->is_dragging ) { + if( e->n_points < 1 ) { return; } - scrollbar->eid_touch = LCUI_BindEvent( LCUI_TOUCH, - ScrollLayer_OnTouch, w, NULL ); - scrollbar->eid_mouseup = LCUI_BindEvent( LCUI_MOUSEUP, OnMouseUp, w, NULL ); - scrollbar->mouse_x = e->screen_x; - scrollbar->mouse_y = e->screen_y; + scrollbar = w->private_data; + for( point = NULL, i = 0; i < e->n_points; ++i ) { + point = &e->points[i]; + if( point->is_primary ) { + break; + } + } + if( !point ) { + return; + } + switch( point->state ) { + case WET_TOUCHDOWN: + scrollbar->distance = 0; + scrollbar->effect.speed = 0; + scrollbar->effect.is_running = FALSE; + scrollbar->old_pos = scrollbar->pos; + if( scrollbar->is_dragging ) { + return; + } + Widget_SetTouchCapture( layer, point->id ); + scrollbar->mouse_x = point->x; + scrollbar->mouse_y = point->y; + break; + case WET_TOUCHUP: + Widget_ReleaseTouchCapture( layer, -1 ); + if( scrollbar->is_dragging ) { + ScrollBar_StartInertialScrolling( w ); + } + scrollbar->is_dragging = FALSE; + Widget_BlockEvent( layer, FALSE ); + break; + case WET_TOUCHMOVE: + pos = scrollbar->old_pos; + if( scrollbar->direction == SBD_HORIZONTAL ) { + pos -= point->x - scrollbar->mouse_x; + } else { + pos -= point->y - scrollbar->mouse_y; + } + if( pos != scrollbar->pos ) { + if( !scrollbar->is_dragging ) { + scrollbar->is_dragging = TRUE; + LCUIWidget_ClearEventTarget( NULL ); + Widget_BlockEvent( layer, TRUE ); + } + distance = pos - scrollbar->pos; + if( (scrollbar->distance > 0) != (distance > 0) || + scrollbar->distance == 0 ) { + ScrollBar_UpdateInertialScrolling( w ); + } + scrollbar->distance = distance; + } + ScrollBar_SetPosition( w, pos ); + default: break; + } } static void ScrollBar_OnUpdateSize( LCUI_Widget box, LCUI_WidgetEvent e, void *arg ) @@ -465,7 +458,7 @@ void ScrollBar_BindLayer( LCUI_Widget w, LCUI_Widget layer ) scrollbar->layer = layer; Widget_BindEvent( layer, "resize", ScrollBar_OnUpdateSize, w, NULL ); Widget_BindEvent( layer, "mousewheel", ScrollLayer_OnWheel, w, NULL ); - Widget_BindEvent( layer, "mousedown", ScrollLayer_OnMouseDown, w, NULL ); + Widget_BindEvent( layer, "touch", ScrollLayer_OnTouch, w, NULL ); ScrollBar_UpdateSize( w ); } diff --git a/src/gui/widget_event.c b/src/gui/widget_event.c index cc4a619e..9b5b9dc3 100644 --- a/src/gui/widget_event.c +++ b/src/gui/widget_event.c @@ -240,7 +240,7 @@ static void DestroyTouchCapturer( void *arg ) } #define TouchCapturers_Clear(LIST) \ -LinkedList_Clear( LIST, DestroyTouchCapturer ) +LinkedList_ClearData( LIST, DestroyTouchCapturer ) static void TouchCapturers_Add( LinkedList *list, LCUI_Widget w, int point_id ) { From c88cb5423bbefacf38756d511e1802fe12945020 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Sun, 5 Jun 2016 15:22:17 +0800 Subject: [PATCH 033/124] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fonts/README.zh-cn | 2 - fonts/glyphicons-halflings-regular.ttf | Bin 45404 -> 0 bytes src/output/Makefile.am | 4 - src/output/dummy.c | 101 ----- src/output/linuxfb_surface.c | 476 -------------------- src/output/win32.c | 403 ----------------- src/output/win32_surface.c | 581 ------------------------- 7 files changed, 1567 deletions(-) delete mode 100755 fonts/README.zh-cn delete mode 100644 fonts/glyphicons-halflings-regular.ttf delete mode 100755 src/output/Makefile.am delete mode 100755 src/output/dummy.c delete mode 100644 src/output/linuxfb_surface.c delete mode 100755 src/output/win32.c delete mode 100644 src/output/win32_surface.c diff --git a/fonts/README.zh-cn b/fonts/README.zh-cn deleted file mode 100755 index 35b86277..00000000 --- a/fonts/README.zh-cn +++ /dev/null @@ -1,2 +0,0 @@ -测试程序默认打开本文件目录中的msyh.ttf文件,也就是微软雅黑字体,你可以将其它字体放在本文件目录下,在程序调用LCUI_Init()函数前用Set_Default_Font()函数自定义字体文件所在位置,或者设置环境变量LCUI_FONTFILE,这样LCUI初始化后就会使用该字体文件。 - diff --git a/fonts/glyphicons-halflings-regular.ttf b/fonts/glyphicons-halflings-regular.ttf deleted file mode 100644 index 1413fc609ab6f21774de0cb7e01360095584f65b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 45404 zcmd?Sd0-pWwLh*qi$?oCk~i6sWlOeWJC3|4juU5JNSu9hSVACzERcmjLV&P^utNzg zIE4Kr1=5g!SxTX#Ern9_%4&01rlrW`Z!56xXTGQR4C z3vR~wXq>NDx$c~e?;ia3YjJ*$!C>69a?2$lLyhpI!CFfJsP=|`8@K0|bbMpWwVUEygg0=0x_)HeHpGSJagJNLA3c!$EuOV>j$wi! zbo{vZ(s8tl>@!?}dmNHXo)ABy7ohD7_1G-P@SdJWT8*oeyBVYVW9*vn}&VI4q++W;Z+uz=QTK}^C75!`aFYCX# zf7fC2;o`%!huaTNJAB&VWrx=szU=VLhwnbT`vc<#<`4WI6n_x@AofA~2d90o?1L3w z9!I|#P*NQ)$#9aASijuw>JRld^-t)Zhmy|i-`Iam|IWkguaMR%lhi4p~cX-9& zjfbx}yz}s`4-6>D^+6FzihR)Y!GsUy=_MWi_v7y#KmYi-{iZ+s@ekkq!@Wxz!~BQwiI&ti z>hC&iBe2m(dpNVvSbZe3DVgl(dxHt-k@{xv;&`^c8GJY%&^LpM;}7)B;5Qg5J^E${ z7z~k8eWOucjX6)7q1a%EVtmnND8cclz8R1=X4W@D8IDeUGXxEWe&p>Z*voO0u_2!! zj3dT(Ki+4E;uykKi*yr?w6!BW2FD55PD6SMj`OfBLwXL5EA-9KjpMo4*5Eqs^>4&> z8PezAcn!9jk-h-Oo!E9EjX8W6@EkTHeI<@AY{f|5fMW<-Ez-z)xCvW3()Z#x0oydB zzm4MzY^NdpIF9qMp-jU;99LjlgY@@s+=z`}_%V*xV7nRV*Kwrx-i`FzI0BZ#yOI8# z!SDeNA5b6u9!Imj89v0(g$;dT_y|Yz!3V`i{{_dez8U@##|X9A};s^7vEd!3AcdyVlhVk$v?$O442KIM1-wX^R{U7`JW&lPr3N(%kXfXT_`7w^? z=#ntx`tTF|N$UT?pELvw7T*2;=Q-x@KmDUIbLyXZ>f5=y7z1DT<7>Bp0k;eItHF?1 zErzhlD2B$Tm|^7DrxnTYm-tgg`Mt4Eivp5{r$o9e)8(fXBO4g|G^6Xy?y$SM*&V52 z6SR*%`%DZC^w(gOWQL?6DRoI*hBNT)xW9sxvmi@!vI^!mI$3kvAMmR_q#SGn3zRb_ zGe$=;Tv3dXN~9XuIHow*NEU4y&u}FcZEZoSlXb9IBOA}!@J3uovp}yerhPMaiI8|SDhvWVr z^BE&yx6e3&RYqIg;mYVZ*3#A-cDJ;#ms4txEmwm@g^s`BB}KmSr7K+ruIoKs=s|gOXP|2 zb1!)87h9?(+1^QRWb(Vo8+@G=o24gyuzF3ytfsKjTHZJ}o{YznGcTDm!s)DRnmOX} z3pPL4wExoN$kyc2>#J`k+<67sy-VsfbQ-1u+HkyFR?9G`9r6g4*8!(!c65Be-5hUg zZHY$M0k(Yd+DT1*8)G(q)1&tDl=g9H7!bZTOvEEFnBOk_K=DXF(d4JOaH zI}*A3jGmy{gR>s}EQzyJa_q_?TYPNXRU1O;fcV_&TQZhd{@*8Tgpraf~nT0BYktu*n{a~ub^UUqQPyr~yBY{k2O zgV)honv{B_CqY|*S~3up%Wn%7i*_>Lu|%5~j)}rQLT1ZN?5%QN`LTJ}vA!EE=1`So z!$$Mv?6T)xk)H8JTrZ~m)oNXxS}pwPd#);<*>zWsYoL6iK!gRSBB{JCgB28C#E{T? z5VOCMW^;h~eMke(w6vLlKvm!!TyIf;k*RtK)|Q>_@nY#J%=h%aVb)?Ni_By)XNxY)E3`|}_u}fn+Kp^3p4RbhFUBRtGsDyx9Eolg77iWN z2iH-}CiM!pfYDIn7;i#Ui1KG01{3D<{e}uWTdlX4Vr*nsb^>l0%{O?0L9tP|KGw8w z+T5F}md>3qDZQ_IVkQ|BzuN08uN?SsVt$~wcHO4pB9~ykFTJO3g<4X({-Tm1w{Ufo zI03<6KK`ZjqVyQ(>{_aMxu7Zm^ck&~)Q84MOsQ-XS~{6j>0lTl@lMtfWjj;PT{nlZ zIn0YL?kK7CYJa)(8?unZ)j8L(O}%$5S#lTcq{rr5_gqqtZ@*0Yw4}OdjL*kBv+>+@ z&*24U=y{Nl58qJyW1vTwqsvs=VRAzojm&V zEn6=WzdL1y+^}%Vg!ap>x%%nFi=V#wn# zUuheBR@*KS)5Mn0`f=3fMwR|#-rPMQJg(fW*5e`7xO&^UUH{L(U8D$JtI!ac!g(Ze89<`UiO@L+)^D zjPk2_Ie0p~4|LiI?-+pHXuRaZKG$%zVT0jn!yTvvM^jlcp`|VSHRt-G@_&~<4&qW@ z?b#zIN)G(}L|60jer*P7#KCu*Af;{mpWWvYK$@Squ|n-Vtfgr@ZOmR5Xpl;0q~VILmjk$$mgp+`<2jP z@+nW5Oap%fF4nFwnVwR7rpFaOdmnfB$-rkO6T3#w^|*rft~acgCP|ZkgA6PHD#Of| zY%E!3tXtsWS`udLsE7cSE8g@p$ceu*tI71V31uA7jwmXUCT7+Cu3uv|W>ZwD{&O4Nfjjvl43N#A$|FWxId! z%=X!HSiQ-#4nS&smww~iXRn<-`&zc)nR~js?|Ei-cei$^$KsqtxNDZvl1oavXK#Pz zT&%Wln^Y5M95w=vJxj0a-ko_iQt(LTX_5x#*QfQLtPil;kkR|kz}`*xHiLWr35ajx zHRL-QQv$|PK-$ges|NHw8k6v?&d;{A$*q15hz9{}-`e6ys1EQ1oNNKDFGQ0xA!x^( zkG*-ueZT(GukSnK&Bs=4+w|(kuWs5V_2#3`!;f}q?>xU5IgoMl^DNf+Xd<=sl2XvkqviJ>d?+G@Z5nxxd5Sqd$*ENUB_mb8Z+7CyyU zA6mDQ&e+S~w49csl*UePzY;^K)Fbs^%?7;+hFc(xz#mWoek4_&QvmT7Fe)*{h-9R4 zqyXuN5{)HdQ6yVi#tRUO#M%;pL>rQxN~6yoZ)*{{!?jU)RD*oOxDoTjVh6iNmhWNC zB5_{R=o{qvxEvi(khbRS`FOXmOO|&Dj$&~>*oo)bZz%lPhEA@ zQ;;w5eu5^%i;)w?T&*=UaK?*|U3~{0tC`rvfEsRPgR~16;~{_S2&=E{fE2=c>{+y} zx1*NTv-*zO^px5TA|B```#NetKg`19O!BK*-#~wDM@KEllk^nfQ2quy25G%)l72<> zzL$^{DDM#jKt?<>m;!?E2p0l12`j+QJjr{Lx*47Nq(v6i3M&*P{jkZB{xR?NOSPN% zU>I+~d_ny=pX??qjF*E78>}Mgts@_yn`)C`wN-He_!OyE+gRI?-a>Om>Vh~3OX5+& z6MX*d1`SkdXwvb7KH&=31RCC|&H!aA1g_=ZY0hP)-Wm6?A7SG0*|$mC7N^SSBh@MG z9?V0tv_sE>X==yV{)^LsygK2=$Mo_0N!JCOU?r}rmWdHD%$h~~G3;bt`lH& zAuOOZ=G1Mih**0>lB5x+r)X^8mz!0K{SScj4|a=s^VhUEp#2M=^#WRqe?T&H9GnWa zYOq{+gBn9Q0e0*Zu>C(BAX=I-Af9wIFhCW6_>TsIH$d>|{fIrs&BX?2G>GvFc=<8` zVJ`#^knMU~65dWGgXcht`Kb>{V2oo%<{NK|iH+R^|Gx%q+env#Js*(EBT3V0=w4F@W+oLFsA)l7Qy8mx_;6Vrk;F2RjKFvmeq} zro&>@b^(?f))OoQ#^#s)tRL>b0gzhRYRG}EU%wr9GjQ#~Rpo|RSkeik^p9x2+=rUr}vfnQoeFAlv=oX%YqbLpvyvcZ3l$B z5bo;hDd(fjT;9o7g9xUg3|#?wU2#BJ0G&W1#wn?mfNR{O7bq747tc~mM%m%t+7YN}^tMa24O4@w<|$lk@pGx!;%pKiq&mZB z?3h<&w>un8r?Xua6(@Txu~Za9tI@|C4#!dmHMzDF_-_~Jolztm=e)@vG11bZQAs!tFvd9{C;oxC7VfWq377Y(LR^X_TyX9bn$)I765l=rJ%9uXcjggX*r?u zk|0!db_*1$&i8>d&G3C}A`{Fun_1J;Vx0gk7P_}8KBZDowr*8$@X?W6v^LYmNWI)lN92yQ;tDpN zOUdS-W4JZUjwF-X#w0r;97;i(l}ZZT$DRd4u#?pf^e2yaFo zbm>I@5}#8FjsmigM8w_f#m4fEP~r~_?OWB%SGWcn$ThnJ@Y`ZI-O&Qs#Y14To( zWAl>9Gw7#}eT(!c%D0m>5D8**a@h;sLW=6_AsT5v1Sd_T-C4pgu_kvc?7+X&n_fct znkHy(_LExh=N%o3I-q#f$F4QJpy>jZBW zRF7?EhqTGk)w&Koi}QQY3sVh?@e-Z3C9)P!(hMhxmXLC zF_+ZSTQU`Gqx@o(~B$dbr zHlEUKoK&`2gl>zKXlEi8w6}`X3kh3as1~sX5@^`X_nYl}hlbpeeVlj#2sv)CIMe%b zBs7f|37f8qq}gA~Is9gj&=te^wN8ma?;vF)7gce;&sZ64!7LqpR!fy)?4cEZposQ8 zf;rZF7Q>YMF1~eQ|Z*!5j0DuA=`~VG$Gg6B?Om1 z6fM@`Ck-K*k(eJ)Kvysb8sccsFf@7~3vfnC=<$q+VNv)FyVh6ZsWw}*vs>%k3$)9| zR9ek-@pA23qswe1io)(Vz!vS1o*XEN*LhVYOq#T`;rDkgt86T@O`23xW~;W_#ZS|x zvwx-XMb7_!hIte-#JNpFxskMMpo2OYhHRr0Yn8d^(jh3-+!CNs0K2B!1dL$9UuAD= zQ%7Ae(Y@}%Cd~!`h|wAdm$2WoZ(iA1(a_-1?znZ%8h72o&Mm*4x8Ta<4++;Yr6|}u zW8$p&izhdqF=m8$)HyS2J6cKyo;Yvb>DTfx4`4R{ zPSODe9E|uflE<`xTO=r>u~u=NuyB&H!(2a8vwh!jP!yfE3N>IiO1jI>7e&3rR#RO3_}G23W?gwDHgSgekzQ^PU&G5z&}V5GO? zfg#*72*$DP1T8i`S7=P;bQ8lYF9_@8^C(|;9v8ZaK2GnWz4$Th2a0$)XTiaxNWfdq z;yNi9veH!j)ba$9pke8`y2^63BP zIyYKj^7;2don3se!P&%I2jzFf|LA&tQ=NDs{r9fIi-F{-yiG-}@2`VR^-LIFN8BC4 z&?*IvLiGHH5>NY(Z^CL_A;yISNdq58}=u~9!Ia7 zm7MkDiK~lsfLpvmPMo!0$keA$`%Tm`>Fx9JpG^EfEb(;}%5}B4Dw!O3BCkf$$W-dF z$BupUPgLpHvr<<+QcNX*w@+Rz&VQz)Uh!j4|DYeKm5IC05T$KqVV3Y|MSXom+Jn8c zgUEaFW1McGi^44xoG*b0JWE4T`vka7qTo#dcS4RauUpE{O!ZQ?r=-MlY#;VBzhHGU zS@kCaZ*H73XX6~HtHd*4qr2h}Pf0Re@!WOyvres_9l2!AhPiV$@O2sX>$21)-3i+_ z*sHO4Ika^!&2utZ@5%VbpH(m2wE3qOPn-I5Tbnt&yn9{k*eMr3^u6zG-~PSr(w$p> zw)x^a*8Ru$PE+{&)%VQUvAKKiWiwvc{`|GqK2K|ZMy^Tv3g|zENL86z7i<c zW`W>zV1u}X%P;Ajn+>A)2iXZbJ5YB_r>K-h5g^N=LkN^h0Y6dPFfSBh(L`G$D%7c` z&0RXDv$}c7#w*7!x^LUes_|V*=bd&aP+KFi((tG*gakSR+FA26%{QJdB5G1F=UuU&koU*^zQA=cEN9}Vd?OEh| zgzbFf1?@LlPkcXH$;YZe`WEJ3si6&R2MRb}LYK&zK9WRD=kY-JMPUurX-t4(Wy{%` zZ@0WM2+IqPa9D(^*+MXw2NWwSX-_WdF0nMWpEhAyotIgqu5Y$wA=zfuXJ0Y2lL3#ji26-P3Z?-&0^KBc*`T$+8+cqp`%g0WB zTH9L)FZ&t073H4?t=(U6{8B+uRW_J_n*vW|p`DugT^3xe8Tomh^d}0k^G7$3wLgP& zn)vTWiMA&=bR8lX9H=uh4G04R6>C&Zjnx_f@MMY!6HK5v$T%vaFm;E8q=`w2Y}ucJ zkz~dKGqv9$E80NTtnx|Rf_)|3wxpnY6nh3U9<)fv2-vhQ6v=WhKO@~@X57N-`7Ppc zF;I7)eL?RN23FmGh0s;Z#+p)}-TgTJE%&>{W+}C`^-sy{gTm<$>rR z-X7F%MB9Sf%6o7A%ZHReD4R;imU6<9h81{%avv}hqugeaf=~^3A=x(Om6Lku-Pn9i zC;LP%Q7Xw*0`Kg1)X~nAsUfdV%HWrpr8dZRpd-#%)c#Fu^mqo|^b{9Mam`^Zw_@j@ zR&ZdBr3?@<@%4Z-%LT&RLgDUFs4a(CTah_5x4X`xDRugi#vI-cw*^{ncwMtA4NKjByYBza)Y$hozZCpuxL{IP&=tw6ZO52WY3|iwGf&IJCn+u(>icK zZB1~bWXCmwAUz|^<&ysd#*!DSp8}DLNbl5lRFat4NkvItxy;9tpp9~|@ z;JctShv^Iq4(z+y7^j&I?GCdKMVg&jCwtCkc4*@O7HY*veGDBtAIn*JgD$QftP}8= zxFAdF=(S>Ra6(4slk#h%b?EOU-96TIX$Jbfl*_7IY-|R%H zF8u|~hYS-YwWt5+^!uGcnKL~jM;)ObZ#q68ZkA?}CzV-%6_vPIdzh_wHT_$mM%vws9lxUj;E@#1UX?WO2R^41(X!nk$+2oJGr!sgcbn1f^yl1 z#pbPB&Bf;1&2+?};Jg5qgD1{4_|%X#s48rOLE!vx3@ktstyBsDQWwDz4GYlcgu$UJ zp|z_32yN72T*oT$SF8<}>e;FN^X&vWNCz>b2W0rwK#<1#kbV)Cf`vN-F$&knLo5T& z8!sO-*^x4=kJ$L&*h%rQ@49l?7_9IG99~xJDDil00<${~D&;kiqRQqeW5*22A`8I2 z(^@`qZoF7_`CO_e;8#qF!&g>UY;wD5MxWU>azoo=E{kW(GU#pbOi%XAn%?W{b>-bTt&2?G=E&BnK9m0zs{qr$*&g8afR_x`B~o zd#dxPpaap;I=>1j8=9Oj)i}s@V}oXhP*{R|@DAQXzQJekJnmuQ;vL90_)H_nD1g6e zS1H#dzg)U&6$fz0g%|jxDdz|FQN{KJ&Yx0vfuzAFewJjv`pdMRpY-wU`-Y6WQnJ(@ zGVb!-8DRJZvHnRFiR3PG3Tu^nCn(CcZHh7hQvyd7i6Q3&ot86XI{jo%WZqCPcTR0< zMRg$ZE=PQx66ovJDvI_JChN~k@L^Pyxv#?X^<)-TS5gk`M~d<~j%!UOWG;ZMi1af< z+86U0=sm!qAVJAIqqU`Qs1uJhQJA&n@9F1PUrYuW!-~IT>l$I!#5dBaiAK}RUufjg{$#GdQBkxF1=KU2E@N=i^;xgG2Y4|{H>s` z$t`k8c-8`fS7Yfb1FM#)vPKVE4Uf(Pk&%HLe z%^4L>@Z^9Z{ZOX<^e)~adVRkKJDanJ6VBC_m@6qUq_WF@Epw>AYqf%r6qDzQ~AEJ!jtUvLp^CcqZ^G-;Kz3T;O4WG45Z zFhrluCxlY`M+OKr2SeI697btH7Kj`O>A!+2DTEQ=48cR>Gg2^5uqp(+y5Sl09MRl* zp|28!v*wvMd_~e2DdKDMMQ|({HMn3D%%ATEecGG8V9>`JeL)T0KG}=}6K8NiSN5W< z79-ZdYWRUb`T}(b{RjN8>?M~opnSRl$$^gT`B27kMym5LNHu-k;A;VF8R(HtDYJHS zU7;L{a@`>jd0svOYKbwzq+pWSC(C~SPgG~nWR3pBA8@OICK$Cy#U`kS$I;?|^-SBC zBFkoO8Z^%8Fc-@X!KebF2Ob3%`8zlVHj6H;^(m7J35(_bS;cZPd}TY~qixY{MhykQ zV&7u7s%E=?i`}Ax-7dB0ih47w*7!@GBt<*7ImM|_mYS|9_K7CH+i}?*#o~a&tF-?C zlynEu1DmiAbGurEX2Flfy$wEVk7AU;`k#=IQE*6DMWafTL|9-vT0qs{A3mmZGzOyN zcM9#Rgo7WgB_ujU+?Q@Ql?V-!E=jbypS+*chI&zA+C_3_@aJal}!Q54?qsL0In({Ly zjH;e+_SK8yi0NQB%TO+Dl77jp#2pMGtwsgaC>K!)NimXG3;m7y`W+&<(ZaV>N*K$j zLL~I+6ouPk6_(iO>61cIsinx`5}DcKSaHjYkkMuDoVl>mKO<4$F<>YJ5J9A2Vl}#BP7+u~L8C6~D zsk`pZ$9Bz3teQS1Wb|8&c2SZ;qo<#F&gS;j`!~!ADr(jJXMtcDJ9cVi>&p3~{bqaP zgo%s8i+8V{UrYTc9)HiUR_c?cfx{Yan2#%PqJ{%?Wux4J;T$#cumM0{Es3@$>}DJg zqe*c8##t;X(4$?A`ve)e@YU3d2Balcivot{1(ahlE5qg@S-h(mPNH&`pBX$_~HdG48~)$x5p z{>ghzqqn_t8~pY<5?-To>cy^6o~mifr;KWvx_oMtXOw$$d6jddXG)V@a#lL4o%N@A zNJlQAz6R8{7jax-kQsH6JU_u*En%k^NHlvBB!$JAK!cYmS)HkLAkm0*9G3!vwMIWv zo#)+EamIJHEUV|$d|<)2iJ`lqBQLx;HgD}c3mRu{iK23C>G{0Mp1K)bt6OU?xC4!_ zZLqpFzeu&+>O1F>%g-%U^~yRg(-wSp@vmD-PT#bCWy!%&H;qT7rfuRCEgw67V!Qob z&tvPU@*4*$YF#2_>M0(75QxqrJr3Tvh~iDeFhxl=MzV@(psx%G8|I{~9;tv#BBE`l z3)_98eZqFNwEF1h)uqhBmT~mSmT8k$7vSHdR97K~kM)P9PuZdS;|Op4A?O<*%!?h` zn`}r_j%xvffs46x2hCWuo0BfIQWCw9aKkH==#B(TJ%p}p-RuIVzsRlaPL_Co{&R0h zQrqn=g1PGjQg3&sc2IlKG0Io#v%@p>tFwF)RG0ahYs@Zng6}M*d}Xua)+h&?$`%rb z;>M=iMh5eIHuJ5c$aC`y@CYjbFsJnSPH&}LQz4}za9YjDuao>Z^EdL@%saRm&LGQWXs*;FzwN#pH&j~SLhDZ+QzhplV_ij(NyMl z;v|}amvxRddO81LJFa~2QFUs z+Lk zZck)}9uK^buJNMo4G(rSdX{57(7&n=Q6$QZ@lIO9#<3pA2ceDpO_340B*pHlh_y{>i&c1?vdpN1j>3UN-;;Yq?P+V5oY`4Z(|P8SwWq<)n`W@AwcQ?E9 zd5j8>FT^m=MHEWfN9jS}UHHsU`&SScib$qd0i=ky0>4dz5ADy70AeIuSzw#gHhQ_c zOp1!v6qU)@8MY+ zMNIID?(CysRc2uZQ$l*QZVY)$X?@4$VT^>djbugLQJdm^P>?51#lXBkdXglYm|4{L zL%Sr?2f`J+xrcN@=0tiJt(<-=+v>tHy{XaGj7^cA6felUn_KPa?V4ebfq7~4i~GKE zpm)e@1=E;PP%?`vK6KVPKXjUXyLS1^NbnQ&?z>epHCd+J$ktT1G&L~T)nQeExe;0Z zlei}<_ni ztFo}j7nBl$)s_3odmdafVieFxc)m!wM+U`2u%yhJ90giFcU1`dR6BBTKc2cQ*d zm-{?M&%(={xYHy?VCx!ogr|4g5;V{2q(L?QzJGsirn~kWHU`l`rHiIrc-Nan!hR7zaLsPr4uR zG{En&gaRK&B@lyWV@yfFpD_^&z>84~_0Rd!v(Nr%PJhFF_ci3D#ixf|(r@$igZiWw za*qbXIJ_Hm4)TaQ=zW^g)FC6uvyO~Hg-#Z5Vsrybz6uOTF>Rq1($JS`imyNB7myWWpxYL(t7`H8*voI3Qz6mvm z$JxtArLJ(1wlCO_te?L{>8YPzQ})xJlvc5wv8p7Z=HviPYB#^#_vGO#*`<0r%MR#u zN_mV4vaBb2RwtoOYCw)X^>r{2a0kK|WyEYoBjGxcObFl&P*??)WEWKU*V~zG5o=s@ z;rc~uuQQf9wf)MYWsWgPR!wKGt6q;^8!cD_vxrG8GMoFGOVV=(J3w6Xk;}i)9(7*U zwR4VkP_5Zx7wqn8%M8uDj4f1aP+vh1Wue&ry@h|wuN(D2W;v6b1^ z`)7XBZ385zg;}&Pt@?dunQ=RduGRJn^9HLU&HaeUE_cA1{+oSIjmj3z+1YiOGiu-H zf8u-oVnG%KfhB8H?cg%@#V5n+L$MO2F4>XoBjBeX>css^h}Omu#)ExTfUE^07KOQS znMfQY2wz?!7!{*C^)aZ^UhMZf=TJNDv8VrrW;JJ9`=|L0`w9DE8MS>+o{f#{7}B4P z{I34>342vLsP}o=ny1eZkEabr@niT5J2AhByUz&i3Ck0H*H`LRHz;>3C_ru!X+EhJ z6(+(lI#4c`2{`q0o9aZhI|jRjBZOV~IA_km7ItNtUa(Wsr*Hmb;b4=;R(gF@GmsRI`pF+0tmq0zy~wnoJD(LSEwHjTOt4xb0XB-+ z&4RO{Snw4G%gS9w#uSUK$Zbb#=jxEl;}6&!b-rSY$0M4pftat-$Q)*y!bpx)R%P>8 zrB&`YEX2%+s#lFCIV;cUFUTIR$Gn2%F(3yLeiG8eG8&)+cpBlzx4)sK?>uIlH+$?2 z9q9wk5zY-xr_fzFSGxYp^KSY0s%1BhsI>ai2VAc8&JiwQ>3RRk?ITx!t~r45qsMnj zkX4bl06ojFCMq<9l*4NHMAtIxDJOX)H=K*$NkkNG<^nl46 zHWH1GXb?Og1f0S+8-((5yaeegCT62&4N*pNQY;%asz9r9Lfr;@Bl${1@a4QAvMLbV6JDp>8SO^q1)#(o%k!QiRSd0eTmzC< zNIFWY5?)+JTl1Roi=nS4%@5iF+%XztpR^BSuM~DX9q`;Mv=+$M+GgE$_>o+~$#?*y zAcD4nd~L~EsAjXV-+li6Lua4;(EFdi|M2qV53`^4|7gR8AJI;0Xb6QGLaYl1zr&eu zH_vFUt+Ouf4SXA~ z&Hh8K@ms^`(hJfdicecj>J^Aqd00^ccqN!-f-!=N7C1?`4J+`_f^nV!B3Q^|fuU)7 z1NDNT04hd4QqE+qBP+>ZE7{v;n3OGN`->|lHjNL5w40pePJ?^Y6bFk@^k%^5CXZ<+4qbOplxpe)l7c6m%o-l1oWmCx%c6@rx85hi(F=v(2 zJ$jN>?yPgU#DnbDXPkHLeQwED5)W5sH#-eS z%#^4dxiVs{+q(Yd^ShMN3GH)!h!@W&N`$L!SbElXCuvnqh{U7lcCvHI#{ZjwnKvu~ zAeo7Pqot+Ohm{8|RJsTr3J4GjCy5UTo_u_~p)MS&Z5UrUc|+;Mc(YS+ju|m3Y_Dvt zonVtpBWlM718YwaN3a3wUNqX;7TqvAFnVUoD5v5WTh~}r)KoLUDw%8Rrqso~bJqd> z_T!&Rmr6ebpV^4|knJZ%qmzL;OvG3~A*loGY7?YS%hS{2R0%NQ@fRoEK52Aiu%gj( z_7~a}eQUh8PnyI^J!>pxB(x7FeINHHC4zLDT`&C*XUpp@s0_B^!k5Uu)^j_uuu^T> z8WW!QK0SgwFHTA%M!L`bl3hHjPp)|wL5Var_*A1-H8LV?uY5&ou{hRjj>#X@rxV>5%-9hbP+v?$4}3EfoRH;l_wSiz{&1<+`Y5%o%q~4rdpRF0jOsCoLnWY5x?V)0ga>CDo`NpqS) z@x`mh1QGkx;f)p-n^*g5M^zRTHz%b2IkLBY{F+HsjrFC9_H(=9Z5W&Eymh~A_FUJ} znhTc9KG((OnjFO=+q>JQZJbeOoUM77M{)$)qQMcxK9f;=L;IOv_J>*~w^YOW744QZ zoG;!b9VD3ww}OX<8sZ0F##8hvfDP{hpa3HjaLsKbLJ8 z0WpY2E!w?&cWi7&N%bOMZD~o7QT*$xCRJ@{t31~qx~+0yYrLXubXh2{_L699Nl_pn z6)9eu+uUTUdjHXYs#pX^L)AIb!FjjNsTp7C399w&B{Q4q%yKfmy}T2uQdU|1EpNcY zDk~(h#AdxybjfzB+mg6rdU9mDZ^V>|U13Dl$Gj+pAL}lR2a1u!SJXU_YqP9N{ose4 zk+$v}BIHX60WSGVWv;S%zvHOWdDP(-ceo(<8`y@Goy%4wDu>57QZNJc)f>Ls+}9h7 z^N=#3q3|l?aG8K#HwiW2^PJu{v|x5;awYfahC?>_af3$LmMc4%N~JwVlRZa4c+eW2 zE!zosAjOv&UeCeu;Bn5OQUC=jtZjF;NDk9$fGbxf3d29SUBekX1!a$Vmq_VK*MHQ4)eB!dQrHH)LVYNF%-t8!d`@!cb z2CsKs3|!}T^7fSZm?0dJ^JE`ZGxA&a!jC<>6_y67On0M)hd$m*RAzo_qM?aeqkm`* zXpDYcc_>TFZYaC3JV>{>mp(5H^efu!Waa7hGTAts29jjuVd1vI*fEeB?A&uG<8dLZ z(j6;-%vJ7R0U9}XkH)1g>&uptXPHBEA*7PSO2TZ+dbhVxspNW~ZQT3fApz}2 z_@0-lZODcd>dLrYp!mHn4k>>7kibI!Em+Vh*;z}l?0qro=aJt68joCr5Jo(Vk<@i) z5BCKb4p6Gdr9=JSf(2Mgr=_6}%4?SwhV+JZj3Ox^_^OrQk$B^v?eNz}d^xRaz&~ zKVnlLnK#8^y=If2f1zmb~^5lPLe?%l}>?~wN4IN((2~U{e9fKhLMtYFj)I$(y zgnKv?R+ZpxA$f)Q2l=aqE6EPTK=i0sY&MDFJp!vQayyvzh4wee<}kybNthRlX>SHh z7S}9he^EBOqzBCww^duHu!u+dnf9veG{HjW!}aT7aJqzze9K6-Z~8pZAgdm1n~aDs z8_s7?WXMPJ3EPJHi}NL&d;lZP8hDhAXf5Hd!x|^kEHu`6QukXrVdLnq5zbI~oPo?7 z2Cbu8U?$K!Z4_yNM1a(bL!GRe!@{Qom+DxjrJ!B99qu5b*Ma%^&-=6UEbC+S2zX&= zQ!%bgJTvmv^2}hhvNQg!l=kbapAgM^hruE3k@jTxsG(B6d=4thBC*4tzVpCYXFc$a zeqgVB^zua)y-YjpiibCCdU%txXYeNFnXcbNj*D?~)5AGjL+!!ij_4{5EWKGav0^={~M^q}baAFOPzxfUM>`KPf|G z&hsaR*7(M6KzTj8Z?;45zX@L#xU{4n$9Q_<-ac(y4g~S|Hyp^-<*d8+P4NHe?~vfm z@y309=`lGdvN8*jw-CL<;o#DKc-%lb0i9a3%{v&2X($|Qxv(_*()&=xD=5oBg=$B0 zU?41h9)JKvP0yR{KsHoC>&`(Uz>?_`tlLjw1&5tPH3FoB%}j;yffm$$s$C=RHi`I3*m@%CPqWnP@B~%DEe;7ZT{9!IMTo1hT3Q347HJ&!)BM2 z3~aClf>aFh0_9||4G}(Npu`9xYY1*SD|M~9!CCFn{-J$u2&Dg*=5$_nozpoD2nxqq zB!--eA8UWZlcEDp4r#vhZ6|vq^9sFvRnA9HpHch5Mq4*T)oGbruj!U8Lx_G%Lby}o zTQ-_4A7b)5A42vA0U}hUJq6&wQ0J%$`w#ph!EGmW96)@{AUx>q6E>-r^Emk!iCR+X zdIaNH`$}7%57D1FyTccs3}Aq0<0Ei{`=S7*>pyg=Kv3nrqblqZcpsCWSQl^uMSsdj zYzh73?6th$c~CI0>%5@!Ej`o)Xm38u0fp9=HE@Sa6l2oX9^^4|Aq%GA z3(AbFR9gA_2T2i%Ck5V2Q2WW-(a&(j#@l6wE4Z`xg#S za#-UWUpU2U!TmIo`CN0JwG^>{+V#9;zvx;ztc$}@NlcyJr?q(Y`UdW6qhq!aWyB5xV1#Jb{I-ghFNO0 zFU~+QgPs{FY1AbiU&S$QSix>*rqYVma<-~s%ALhFyVhAYepId1 zs!gOB&weC18yhE-v6ltKZMV|>JwTX+X)Y_EI(Ff^3$WTD|Ea-1HlP;6L~&40Q&5{0 z$e$2KhUgH8ucMJxJV#M%cs!d~#hR^nRwk|uuCSf6irJCkSyI<%CR==tftx6d%;?ef zYIcjZrP@APzbtOeUe>m-TW}c-ugh+U*RbL1eIY{?>@8aW9bb1NGRy@MTse@>= za%;5=U}X%K2tKTYe9gjMcBvX%qrC&uZ`d(t)g)X8snf?vBe3H%dG=bl^rv8Z@YN$gd9yveHY0@Wt0$s zh^7jCp(q+6XDoekb;=%y=Wr8%6;z0ANH5dDR_VudDG|&_lYykJaiR+(y{zpR=qL3|2e${8 z2V;?jgHj7}Kl(d8C9xWRjhpf_)KOXl+@c4wrHy zL3#9U(`=N59og2KqVh>nK~g9>fX*PI0`>i;;b6KF|8zg+k2hViCt}4dfMdvb1NJ-Rfa7vL2;lPK{Lq*u`JT>S zoM_bZ_?UY6oV6Ja14X^;LqJPl+w?vf*C!nGK;uU^0GRN|UeFF@;H(Hgp8x^|;ygh? zIZx3DuO(lD01ksanR@Mn#lti=p28RTNYY6yK={RMFiVd~k8!@a&^jicZ&rxD3CCI! zVb=fI?;c#f{K4Pp2lnb8iF2mig)|6JEmU86Y%l}m>(VnI*Bj`a6qk8QL&~PFDxI8b z2mcsQBe9$q`Q$LfG2wdvK`M1}7?SwLAV&)nO;kAk`SAz%x9CDVHVbUd$O(*aI@D|s zLxJW7W(QeGpQY<$dSD6U$ja(;Hb3{Zx@)*fIQaW{8<$KJ&fS0caI2Py^clOq9@Irt z7th7F?7W`j{&UmM==Lo~T&^R7A?G=K_e-zfTX|)i`pLitlNE(~tq*}sS1x2}Jlul6 z5+r#4SpQu8h{ntIv#qCVH`uG~+I8l+7ZG&d`Dm!+(rZQDV*1LS^WfH%-!5aTAxry~ z4xl&rot5ct{xQ$w$MtVTUi6tBFSJWq2Rj@?HAX1H$eL*fk{Hq;E`x|hghRkipYNyt zKCO=*KSziiVk|+)qQCGrTYH9X!Z0$k{Nde~0Wl`P{}ca%nv<6fnYw^~9dYxTnTZB&&962jX0DM&wy&8fdxX8xeHSe=UU&Mq zRTaUKnQO|A>E#|PUo+F=Q@dMdt`P*6e92za(TH{5C*2I2S~p?~O@hYiT>1(n^Lqqn zqewq3ctAA%0E)r53*P-a8Ak32mGtUG`L^WVcm`QovX`ecB4E9X60wrA(6NZ7z~*_DV_e z8$I*eZ8m=WtChE{#QzeyHpZ%7GwFHlwo2*tAuloI-j2exx3#x7EL^&D;Re|Kj-XT- zt908^soV2`7s+Hha!d^#J+B)0-`{qIF_x=B811SZlbUe%kvPce^xu7?LY|C z@f1gRPha1jq|=f}Se)}v-7MWH9)YAs*FJ&v3ZT9TSi?e#jarin0tjPNmxZNU_JFJG z+tZi!q)JP|4pQ)?l8$hRaPeoKf!3>MM-bp06RodLa*wD=g3)@pYJ^*YrwSIO!SaZo zDTb!G9d!hb%Y0QdYxqNSCT5o0I!GDD$Z@N!8J3eI@@0AiJmD7brkvF!pJGg_AiJ1I zO^^cKe`w$DsO|1#^_|`6XTfw6E3SJ(agG*G9qj?JiqFSL|6tSD6vUwK?Cwr~gg)Do zp@$D~7~66-=p4`!!UzJDKAymb!!R(}%O?Uel|rMH>OpRGINALtg%gpg`=}M^Q#V5( zMgJY&gF)+;`e38QHI*c%B}m94o&tOfae;og&!J2;6ENW}QeL73jatbI1*9X~y=$Dm%6FwDcnCyMRL}zo`0=y7=}*Uw zo3!qZncAL{HCgY!+}eKr{P8o27ye+;qJP;kOB%RpSesGoHLT6tcYp*6v~Z9NCyb6m zP#qds0jyqXX46qMNhXDn3pyIxw2f_z;L_X9EIB}AhyC`FYI}G3$WnW>#NMy{0aw}nB%1=Z4&*(FaCn5QG(zvdG^pQRU25;{wwG4h z@kuLO0F->{@g2!;NNd!PfqM-;@F0;&wK}0fT9UrH}(8A5I zt33(+&U;CLN|8+71@g z(s!f-kZZZILUG$QXm9iYiE*>2w;gpM>lgM{R9vT3q>qI{ELO2hJHVi`)*jzOk$r)9 zq}$VrE0$GUCm6A3H5J-=Z9i*biw8ng zi<1nM0lo^KqRY@Asucc#DMmWsnCS;5uPR)GL3pL=-IqSd>4&D&NKSGHH?pG;=Xo`w zw~VV9ddkwbp~m>9G0*b?j7-0fOwR?*U#BE#n7A=_fDS>`fwatxQ+`FzhBGQUAyIRZ??eJt46vHBlR>9m!vfb6I)8!v6TmtZ%G6&E|1e zOtx5xy%yOSu+<9Ul5w5N=&~4Oph?I=ZKLX5DXO(*&Po>5KjbY7s@tp$8(fO|`Xy}Y z;NmMypLoG7r#Xz4aHz7n)MYZ7Z1v;DFHLNV{)to;(;TJ=bbMgud96xRMME#0d$z-S z-r1ROBbW^&YdQWA>U|Y>{whex#~K!ZgEEk=LYG8Wqo28NFv)!t!~}quaAt}I^y-m| z8~E{9H2VnyVxb_wCZ7v%y(B@VrM6lzk~|ywCi3HeiSV`TF>j+Ijd|p*kyn;=mqtf8&DK^|*f+y$38+9!sis9N=S)nINm9=CJ<;Y z!t&C>MIeyou4XLM*ywT_JuOXR>VkpFwuT9j5>667A=CU*{TBrMTgb4HuW&!%Yt`;#md7-`R`ouOi$rEd!ErI zo#>qggAcx?C7`rQ2;)~PYCw%CkS(@EJHZ|!!lhi@Dp$*n^mgrrImsS~(ioGak>3)w zvop0lq@IISuA0Ou*#1JkG{U>xSQV1e}c)!d$L1plFX5XDXX5N7Ns{kT{y5|6MfhBD+esT)e7&CgSW8FxsXTAY=}?0A!j_V9 zJ;IJ~d%av<@=fNPJ9)T3qE78kaz64E>dJaYab5uaU`n~Zdp2h{8DV%SKE5G^$LfuOTRRjB;TnT(Jk$r{Pfe4CO!SM_7d)I zquW~FVCpSycJ~c*B*V8?Qqo=GwU8CkmmLFugfHQ7;A{yCy1OL-+X=twLYg9|H=~8H znnN@|tCs^ZLlCBl5wHvYF}2vo>a6%mUWpTds_mt*@wMN4-r`%NTA%+$(`m6{MNpi@ zMx)8f>U4hd!row@gM&PVo&Hx+lV@$j9yWTjTue zG9n0DP<*HUmJ7ZZWwI2x+{t3QEfr6?T}2iXl=6e0b~)J>X3`!fXd9+2wc1%cj&F@Z zgYR|r5Xd5jy9;YW&=4{-0rJ*L5CgDPj9^3%bp-`HkyBs`j1iTUGD4?WilZ6RO8mIE z+~Joc?GID6K96dyuv(dWREK9Os~%?$$FxswxQsoOi8M?RnL%B~Lyk&(-09D0M?^Jy zWjP)n(b)TF<-|CG%!Vz?8Fu&6iU<>oG#kGcrcrrBlfZMVl0wOJvsq%RL9To%iCW@)#& zZAJWhgzYAq)#NTNb~3GBcD%ZZOc43!YWSyA7TD6xkk)n^FaRAz73b}%9d&YisBic(?mv=Iq^r%Ug zzHq-rRrhfOOF+yR=AN!a9*Rd#sM9ONt5h~w)yMP7Dl9lfpi$H0%GPW^lS4~~?vI8Z z%^ToK#NOe0ExmUsb`lLO$W*}yXNOxPe@zD*90uTDULnH6C?InP3J=jYEO2d)&e|mP z1DSd0QOZeuLWo*NqZzopA+LXy9)fJC00NSX=_4Mi1Z)YyZVC>C!g}cY(Amaj%QN+bev|Xxd2OPD zk!dfkY6k!(sDBvsFC2r^?}hb81(WG5Lt9|riT`2?P;B%jaf5UX<~OJ;uAL$=Ien+V zC!V8u0v?CUa)4*Q+Q_u zkx{q;NjLcvyMuU*{+uDsCQ4U{JLowYby-tn@hatL zy}X>9y08#}oytdn^qfFesF)Tt(2!XGw#r%?7&zzFFh2U;#U9XBO8W--#gOpfbJ`Ey z|M8FCKlWQrOJwE;@Sm02l9OBr7N}go4V8ur)}M@m2uWjggb)DC4s`I4d7_8O&E(j; z?3$9~R$QDxNM^rNh9Y;6P7w+bo2q}NEd6f&_raor-v`UCaTM3TT8HK2-$|n{N@U>_ zL-`P7EXoEU5JRMa)?tNUEe8XFis+w8g9k(QQ)%?&Oac}S`2V$b?%`DwXBgja&&fR@ zH_XidF$p1wA)J|Wk1;?lCl?fgc)=TB3>Y8;BoMqHwJqhL)Tgydv9(?(TBX)fq%=~C zmLj!iX-kn7QA(9snzk0LRf<%SzO&~IhLor6A3f*U^UcoAygRe!H#@UCv$JUP&vPxs zeDj$1%#<2T1!e|!7xI+~_VXLl5|jHqvOhU7ZDUGee;HnkcPP=_k_FFxPjXg*9KyI+ zIh0@+s)1JDSuKMeaDZ3|<_*J8{TUFDLl|mXmY8B>Wj_?4mC#=XjsCKPEO=p0c&t&Z zd1%kHxR#o9S*C?du*}tEHfAC7WetnvS}`<%j=o7YVna)6pw(xzkUi7f#$|^y4WQ{7 zu@@lu=j6xr*11VEIY+`B{tgd(c3zO8%nGk0U^%ec6h)G_`ki|XQXr!?NsQkxzV6Bn1ea9L+@ z(Zr7CU_oXaW>VOdfzENm+FlFQ7Se0ROrNdw(QLvb6{f}HRQ{$Je>(c&rws#{dFI^r zZ4^(`J*G0~Pu_+p5AAh>RRpkcbaS2a?Fe&JqxDTp`dIW9;DL%0wxX5;`KxyA4F{(~_`93>NF@bj4LF!NC&D6Zm+Di$Q-tb2*Q z&csGmXyqA%Z9s(AxNO3@Ij=WGt=UG6J7F;r*uqdQa z?7j!nV{8eQE-cwY7L(3AEXF3&V*9{DpSYdyCjRhv#&2johwf{r+k`QB81%!aRVN<& z@b*N^xiw_lU>H~@4MWzgHxSOGVfnD|iC7=hf0%CPm_@@4^t-nj#GHMug&S|FJtr?i z^JVrobltd(-?Ll>)6>jwgX=dUy+^n_ifzM>3)an3iOzpG9Tu;+96TP<0Jm_PIqof3 zMn=~M!#Ky{CTN_2f7Y-i#|gW~32RCWKA4-J9sS&>kYpTOx#xVNLCo)A$LUme^fVNH z@^S7VU^UJ0YR8?Oy$^IYuG*bm|g;@aX~i60%`7XLy*AYpYvZ^F^U(!|RW z*C!rJ@+7TGdL=nNd1gv^%B+;Fcr$y)i0!GRsZXRHPs>QVGVR{9r_#&Qd(wL|5;H;> zD>HUw=4CF++&{7$<8G@j*nGjhEO%BQYfjeItp4mPvY*JYb1HKd!{HJ9*)(3%BR%{Pp?AM&*yHAJsW({ivOzj*qS!-7|XEn6@zo z3L*tBT%<4RxoAh>q{0n_JBmgW6&8hx?kL(_^k%VL>?xjAyrKBmSl`$=V|SK}ELl}@ zd|d0eo#RfG`bw9SK3%r4Y+rdvc}w}~ixV%tqawbdqvE-WcgE+BUpxMT%F@btm76MG zn=oQRWWuTm+a{dy)Oc2V4yX(@M{QAkx>(QB59*`dLT`Pz3Lsj9iB=HSHAiCq()ns|Cr)1*c605Cx}3V&x}Lg?b+6Q?)z7Kl zQh&1Hx`y6JY-Cwvd*ozeps}a1xAA0CR+Da;+O(i)P1C;SjOI}Dtmf6tPqo-Bl`U78 zv$kYgPntPp@G)n1an9tEoL*Vumu9`>_@I(;+5+fBa-*?fEx=mTEjZ7wq}#@Gd5_cW z!mP{N=yqEntDo)|>oy6{9cu+-3*GTnmb^`O0^FzRPO^&aG`f@F_R*aQ_e{F+_9%NW z4KG_B`@X3EVV9L>?_RNDMddA>w=e0KfAiw5?#i1NFT%Zz#nuv(&!yIU>lVxmzYKQ` zzJ*0w9<&L4aJ6A;0j|_~i>+y(q-=;2Xxhx2v%CYY^{} z^J@LO()eLo|7!{ghQ+(u$wxO*xY#)cL(|miH2_ck2yN{mu4O9=hBW*pM_()-_YdH#Ru{JtwJ^R2}3?!>>m1pohh zrn(!xCjE0Q&EH1QK?zA%sxVh&H99cObJUY$veZhQ)MLu-h%`!*G)s$2k;~+A z)Kk->Ri?`oGDEJEtI*wijm(s5f$W78FH{+qBxiU{~kq((J3uK{m z$|C8K#j-?hm8H@x%VfFqpnvu@xn1s%J7uNZC9C99a<_b1J|mx%)$%!6gPU|~<@2&m zz99GDp`|a%m*iggvfL;4%X;~WY>)@!tMWB@P`)k?$;0x9JSrRI8?s3rlgH(o@`OAo zn{f*gZ#t2u6K??hx|aElOM`Xd0t+SAIUEHvFw%?Wsm$s zUXq{6UU?a>Nc@@Xlb_2k9M1Ctr<#+O?yd}rv z_wu&=_t$!Yngd@N_AUj}T; z#*Ce|%XZr_sQcsWcsl{pCnnj+c8ZNIMmx<;w=-g$Q>BU;9k;w|zQ;4!W32Xg2Cd?{ zvmO3kuKQ^Hv;o>6ZHP8ZJ2`4~Bx?N;cf<0fi=!*G^^WzbTF3e$b&d^qqB{>nqLG81 zs94bBh%|Vj+hLu=!8(b9brJ>ZBns9^6s(gdSVyP9qnu2_I{Sg8j-rloG6{d`De5We zDe5WeY3ga}Y3ga}Y3ga}Y3ga}Y3ga}d8y~6o|k%F>UpW>rJk31Ug~+N=cS&HdOqs; zsOO`ek9t1p`Kafko{xGy>iMbXr=FjBxZMYc8a#gL`Kjlpo}YSt>iMY`pk9DF0qO*( z6QE9jIsxhgs1u-0kUBx8D@eT{^@7w3QZGooAoYUO3sNscy%6<6)C*BBM7L`dk$Xk%6}eZQXgo#!75P`>Uy*-B{uTLGUy*-B{uTLGUy*-B{uTLG. - * ****************************************************************************/ - -/* **************************************************************************** - * dummy.c -- 通常在找不到合适的图形输出支持的情况下,使用该源文件,用虚设函数凑数 - * - * 版权所有 (C) 2013 归属于 - * 刘超 - * - * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 - * - * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) - * - * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 - * - * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 - * 定用途的隐含担保,详情请参照GPLv2许可协议。 - * - * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 - * 没有,请查看:. - * ****************************************************************************/ - -#include -#include - -#ifdef LCUI_VIDEO_DRIVER_NONE - -LCUI_API void -LCUIScreen_FillPixel( LCUI_Pos pos, LCUI_RGB color ) -{ - return; -} - -LCUI_API int -LCUIScreen_GetGraph( LCUI_Graph *out ) -{ - return -1; -} - - -LCUI_API int -LCUIScreen_Init( int w, int h, int mode ) -{ - return -1; -} - - -/* 设置视频输出模式 */ -LCUI_API int -LCUIScreen_SetMode( int w, int h, int mode ) -{ - return -1; -} - - -LCUI_API int -LCUIScreen_Destroy( void ) -{ - return -1; -} - - -LCUI_API void -LCUIScreen_SyncFrameBuffer( void ) -{ - return; -} - - -LCUI_API int -LCUIScreen_PutGraph (LCUI_Graph *graph, LCUI_Pos des_pos ) -{ - return -1; -} - -LCUI_API void -LCUIScreen_CatchGraph( LCUI_Rect area, LCUI_Graph *out ) -{ - return; -} - -#endif diff --git a/src/output/linuxfb_surface.c b/src/output/linuxfb_surface.c deleted file mode 100644 index 1e89b6b2..00000000 --- a/src/output/linuxfb_surface.c +++ /dev/null @@ -1,476 +0,0 @@ -/* *************************************************************************** - * linuxfb_surface.c -- surface support for linux framebuffer. - * - * Copyright (C) 2015 by Liu Chao - * - * 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 . - * ***************************************************************************/ - -/* **************************************************************************** - * linuxfb_surface.c -- 基于linux平台帧缓冲(framebuffer)的 surface 功能支持。 - * - * 版权所有 (C) 2015 归属于 刘超 - * - * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 - * - * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) - * - * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 - * - * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 - * 定用途的隐含担保,详情请参照GPLv2许可协议。 - * - * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 - * 没有,请查看:. - * ***************************************************************************/ - -#include -#ifdef LCUI_VIDEO_DRIVER_FRAMEBUFFER -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#define FB_DEV "/dev/fb0" -#define FB_BACKUP_FILE "/tmp/framebuffer.bak" - -static struct LinuxFBContext { - int dev_fd; - uchar_t *mem; - int mem_len; - int bits_per_pixel; - int bytes_per_line; - int width, height; - LCUI_SurfaceMethods methods; -} linuxfb; - -/** 备份帧缓冲内容 */ -static int LinuxFB_Backup(void) -{ - char cmd[256], *fb_dev; - fb_dev = getenv("LCUI_FB_DEVICE"); - if(fb_dev == NULL) { - fb_dev = FB_DEV; - } - sprintf( cmd, "cat %s > %s", fb_dev, FB_BACKUP_FILE ); - return system( cmd ); -} - -/** 恢复帧缓冲内容 */ -static int LinuxFB_Restore(void) -{ - char cmd[256], *fb_dev; - fb_dev = getenv("LCUI_FB_DEVICE"); - if(fb_dev == NULL) { - fb_dev = FB_DEV; - } - sprintf( cmd, "cat %s > %s", FB_BACKUP_FILE, fb_dev ); - return system( cmd ); -} - -static int LinuxFB_GetWidth(void) -{ - return linuxfb.width; -} - -static int LinuxFB_GetHeight(void) -{ - return linuxfb.height; -} - -/** 打印屏幕相关的信息 */ -static void print_screeninfo( struct fb_var_screeninfo fb_vinfo, - struct fb_fix_screeninfo fb_fix ) -{ - char visual[256], type[256]; - - switch(fb_fix.type) { - case FB_TYPE_PACKED_PIXELS: - strcpy(type, "packed pixels");break; - case FB_TYPE_PLANES: - strcpy(type, "non interleaved planes");break; - case FB_TYPE_INTERLEAVED_PLANES: - strcpy(type, "interleaved planes");break; - case FB_TYPE_TEXT: - strcpy(type, "text/attributes");break; - case FB_TYPE_VGA_PLANES: - strcpy(type, "EGA/VGA planes");break; - default: - strcpy(type, "unkown");break; - } - - switch(fb_fix.visual) { - case FB_VISUAL_MONO01: - strcpy(visual, "Monochr. 1=Black 0=White");break; - case FB_VISUAL_MONO10: - strcpy(visual, "Monochr. 1=White 0=Black");break; - case FB_VISUAL_TRUECOLOR: - strcpy(visual, "true color");break; - case FB_VISUAL_PSEUDOCOLOR: - strcpy(visual, "pseudo color (like atari)");break; - case FB_VISUAL_DIRECTCOLOR: - strcpy(visual, "direct color");break; - case FB_VISUAL_STATIC_PSEUDOCOLOR: - strcpy(visual, "pseudo color readonly");break; - default: - strcpy(type, "unkown");break; - } - printf( - "============== screen info =============\n" - "FB mem start : 0x%08lX\n" - "FB mem length : %d\n" - "FB type : %s\n" - "FB visual : %s\n" - "accel : %d\n" - "geometry : %d %d %d %d %d\n" - "timings : %d %d %d %d %d %d\n" - "rgba : %d/%d, %d/%d, %d/%d, %d/%d\n" - "========================================\n", - fb_fix.smem_start, fb_fix.smem_len, - type, visual, - fb_fix.accel, - fb_vinfo.xres, fb_vinfo.yres, - fb_vinfo.xres_virtual, fb_vinfo.yres_virtual, - fb_vinfo.bits_per_pixel, - fb_vinfo.upper_margin, fb_vinfo.lower_margin, - fb_vinfo.left_margin, fb_vinfo.right_margin, - fb_vinfo.hsync_len, fb_vinfo.vsync_len, - fb_vinfo.red.length, fb_vinfo.red.offset, - fb_vinfo.green.length, fb_vinfo.green.offset, - fb_vinfo.blue.length, fb_vinfo.blue.offset, - fb_vinfo. transp.length, fb_vinfo. transp.offset - ); -} - -static LCUI_Surface LinuxFB_New(void) -{ - return (void*)&linuxfb.dev_fd; -} - -static void LinuxFB_Delete( LCUI_Surface surface ) -{ - -} - -static void LinuxFB_Resize( LCUI_Surface surface, int w, int h ) -{ - // ... -} - -static LCUI_BOOL LinuxFB_IsReady( LCUI_Surface surface ) -{ - return TRUE; -} - -static void LinuxFB_Update( LCUI_Surface surface ) -{ - -} - -static void LinuxFB_SetRenderMode( LCUI_Surface surface, int mode ) -{ - // ... -} - -LCUI_PaintContext LinuxFB_BeginPaint( LCUI_Surface surface, LCUI_Rect *rect ) -{ - LCUI_PaintContext paint; - paint = (LCUI_PaintContext)malloc(sizeof(LCUI_PaintContextRec)); - Graph_Init( &paint->canvas ); - Graph_Create( &paint->canvas, rect->w, rect->h ); - paint->rect = *rect; - _DEBUG_MSG("canvas: %p, rect: %d,%d,%d,%d\n", - &paint->canvas, rect->x, rect->y, rect->w, rect->h); - return paint; -} - -/** - * 将图形绘制到帧缓存中,适用于像素数据格式为BGRA的32位色模式 - * 一个像素点的数据共占32位,其中RGB各占8位,剩下的8位用于alpha,共4个字节 - * @warning 目前是默认将所有 Graph 都视为使用32位BGRA色彩模式,其它模式暂不做处理 - */ -static void LinuxFB_PutGraph32( LCUI_Rect rect, LCUI_Graph *canvas ) -{ - int y, des_row_bytes; - uchar_t *des_row, *src_row; - LCUI_Rect read_rect; - - des_row_bytes = linuxfb.width*4; - des_row = linuxfb.mem + rect.y*des_row_bytes + rect.x*4; - Graph_GetValidRect( canvas, &read_rect ); - if( read_rect.width <= 0 || read_rect.height <= 0 ) { - return; - } - canvas = Graph_GetQuote( canvas ); - src_row = canvas->bytes + read_rect.y*canvas->bytes_per_row; - src_row += read_rect.x * canvas->bytes_per_pixel; - for( y=0; yh; ++y ) { - /* 将当前行像素转换成ARGB格式,并直接覆盖至帧缓存中 */ - PixelsFormat( src_row, canvas->color_type, - des_row, COLOR_TYPE_ARGB, - canvas->w ); - des_row += des_row_bytes; - src_row += canvas->bytes_per_row; - } -} - -/** - * 将图形绘制到帧缓存中,适用于像素数据格式为BGR的24位色模式 - * 一个像素点的数据共占24位,RGB各占8位,共3个字节 - */ -static void LinuxFB_PutGraph24( LCUI_Rect rect, LCUI_Graph *canvas ) -{ - int x, y, dest_line_bytes; - uchar_t *dest_line, *dest, *src_pixel_line; - LCUI_Color *src_pixel; - - dest_line = linuxfb.mem + rect.y*linuxfb.width + rect.x; - dest_line_bytes = linuxfb.width*3; - src_pixel_line = canvas->bytes; - for( y=0; yh; ++y ) { - dest = dest_line; - src_pixel = (LCUI_Color*)src_pixel_line; - for( x=0; xw; ++x ) { - *dest++ = src_pixel->blue; - *dest++ = src_pixel->green; - *dest++ = src_pixel->red; - ++src_pixel; - } - dest_line += dest_line_bytes; - src_pixel_line += canvas->w; - } -} - -/** - * 将图形绘制到帧缓存中,适用于像素数据格式为RGB565的16位色模式 - * 一个像素点的数据共占16位,rgb分别占5位,6位,5位,共2个字节 - */ -static void LinuxFB_PutGraph16( LCUI_Rect rect, LCUI_Graph *canvas ) -{ - int x, y, dest_line_bytes; - uchar_t *dest_line, *dest, *src_pixel_line; - LCUI_Color *src_pixel; - - dest_line = linuxfb.mem + rect.y*linuxfb.width + rect.x; - dest_line_bytes = linuxfb.width*2; - src_pixel_line = canvas->bytes; - for( y=0; yh; ++y ) { - dest = dest_line; - src_pixel = (LCUI_Color*)src_pixel_line; - for( x=0; xw; ++x ) { - /* - * 低字节的前5位用来表示B(BLUE) - * 低字节的后三位+高字节的前三位用来表示G(Green) - * 高字节的后5位用来表示R(RED) - * */ - *dest = ((src_pixel->green & 0x1c)<<3); - *dest += ((src_pixel->blue & 0xf8)>>3); - ++dest; - *dest = ((src_pixel->red & 0xf8)); - *dest += ((src_pixel->green & 0xe0)>>5); - ++dest; - ++src_pixel; - } - dest_line += dest_line_bytes; - src_pixel_line += canvas->w; - } -} - -/** 将图形绘制到帧缓存中,适用于像素数据格式为8位色模式 */ -static void LinuxFB_PutGraph8( LCUI_Rect rect, LCUI_Graph *canvas ) -{ - int x, y, dest_line_bytes; - uchar_t *dest_line, *dest, *src_pixel_line; - struct fb_cmap kolor; - LCUI_Color *src_pixel; - unsigned int r, g, b, i; - - kolor.start = 0; - kolor.len = 255; - kolor.red = calloc(256, sizeof(__u16)); - kolor.green = calloc(256, sizeof(__u16)); - kolor.blue = calloc(256, sizeof(__u16)); - kolor.transp = 0; - dest_line = linuxfb.mem + rect.y*linuxfb.width + rect.x; - dest_line_bytes = linuxfb.width; - src_pixel_line = canvas->bytes; - - for( i=0; i<256; ++i ) { - kolor.red[i] = 0; - kolor.green[i] = 0; - kolor.blue[i] = 0; - } - for( y=0; yh; ++y ) { - src_pixel = (LCUI_Color*)src_pixel_line; - dest = dest_line; - for( x=0; xw; ++x ) { - r = src_pixel->red * 0.92; - g = src_pixel->green * 0.92; - b = src_pixel->blue * 0.92; - i = (r & 0xc0) + ((g & 0xf0)>>2) + ((b & 0xc0)>>6); - kolor.red[i] = r*256; - kolor.green[i] = g*256; - kolor.blue[i] = b*256; - *dest++ = i; - ++src_pixel; - } - dest_line += dest_line_bytes; - src_pixel_line += canvas->w; - } - - ioctl( linuxfb.dev_fd, FBIOPUTCMAP, &kolor ); - free( kolor.red ); - free( kolor.green ); - free( kolor.blue ); -} - -void LinuxFB_EndPaint( LCUI_Surface surface, LCUI_PaintContext paint_ctx ) -{ - LCUI_Rect cut_rect; - LCUI_Graph canvas; - - LCUIRect_GetCutArea( linuxfb.width, linuxfb.height, - paint_ctx->rect, &cut_rect ); - if( cut_rect.w <= 0 || cut_rect.h <= 0 ) { - free( paint_ctx ); - return; - } - Graph_Init( &canvas ); - /* 如果需要裁剪图形 */ - if( cut_rect.x != 0 || cut_rect.y != 0 - || cut_rect.w != paint_ctx->rect.w - || cut_rect.h != paint_ctx->rect.h ) { - paint_ctx->rect.x += cut_rect.x; - paint_ctx->rect.y += cut_rect.y; - paint_ctx->rect.w = cut_rect.w; - paint_ctx->rect.h = cut_rect.h; - Graph_Quote( &canvas, &paint_ctx->canvas, &cut_rect ); - } else { - Graph_Quote( &canvas, &paint_ctx->canvas, NULL ); - } - - _DEBUG_MSG("linuxfb.bits_per_pixel: %d\n", linuxfb.bits_per_pixel); - switch( linuxfb.bits_per_pixel ) { - case 32: - LinuxFB_PutGraph32( paint_ctx->rect, &canvas ); - break; - case 24: - LinuxFB_PutGraph24( paint_ctx->rect, &canvas ); - break; - case 16: - LinuxFB_PutGraph16( paint_ctx->rect, &canvas ); - break; - case 8: - LinuxFB_PutGraph8( paint_ctx->rect, &canvas ); - break; - default: break; - } - Graph_Free( &canvas ); - free( paint_ctx ); - _DEBUG_MSG("%d,%d,%d,%d\n", paint_ctx->rect.x, paint_ctx->rect.y, paint_ctx->rect.w, paint_ctx->rect.h); -} - -static void LinuxFB_Present( LCUI_Surface surface ) -{ - -} - -/** 初始化适用于 Linux 帧缓冲(FrameBuffer) 的 surface 支持 */ -LCUI_SurfaceMethods *LCUIDisplay_InitLinuxFB( LCUI_DisplayInfo *info ) -{ - char *fb_dev; - __u16 rr[256],gg[256],bb[256]; - struct fb_var_screeninfo fb_vinfo; - struct fb_fix_screeninfo fb_fix; - struct fb_cmap oldcmap = {0,256,rr,gg,bb}; - - /* 获取环境变量中指定的帧缓冲设备的位置 */ - fb_dev = getenv("LCUI_FB_DEVICE"); - if( fb_dev == NULL ) { - fb_dev = FB_DEV; - } - nobuff_printf("[linuxfb] open video output device..."); - linuxfb.dev_fd = open(fb_dev, O_RDWR); - if( linuxfb.dev_fd == -1 ) { - printf("failed\n[linuxfb] %s: %s\n", fb_dev, strerror(errno)); - return NULL; - } else { - printf("ok\n"); - } - /* 获取屏幕相关信息 */ - ioctl( linuxfb.dev_fd, FBIOGET_VSCREENINFO, &fb_vinfo ); - ioctl( linuxfb.dev_fd, FBIOGET_FSCREENINFO, &fb_fix ); - /* 打印屏幕信息 */ - print_screeninfo( fb_vinfo, fb_fix ); - if( fb_vinfo.bits_per_pixel == 8 ) { - ioctl( linuxfb.dev_fd, FBIOGETCMAP, &oldcmap ); - } - nobuff_printf("[linuxfb] mapping framebuffer..."); - linuxfb.bits_per_pixel = fb_vinfo.bits_per_pixel; - linuxfb.bytes_per_line = fb_fix.line_length; - linuxfb.mem_len = fb_fix.smem_len; - /* 映射帧缓存至内存空间 */ - linuxfb.mem = mmap( NULL, fb_fix.smem_len, - PROT_READ|PROT_WRITE, MAP_SHARED, - linuxfb.dev_fd, 0 ); - - if( (void *)-1 == linuxfb.mem ) { - printf("fail\n"); - perror(strerror(errno)); - return NULL; - } else { - printf("success\n"); - } - LinuxFB_Backup(); - linuxfb.width = fb_vinfo.xres; - linuxfb.height = fb_vinfo.yres; - strncpy( info->name, "linux framebuffer", 32 ); - info->getWidth = LinuxFB_GetWidth; - info->getHeight = LinuxFB_GetHeight; - linuxfb.methods.new = LinuxFB_New; - linuxfb.methods.delete = LinuxFB_Delete; - linuxfb.methods.isReady = LinuxFB_IsReady; - linuxfb.methods.show = NULL; - linuxfb.methods.hide = NULL; - linuxfb.methods.move = NULL; - linuxfb.methods.resize = LinuxFB_Resize; - linuxfb.methods.update = LinuxFB_Update; - linuxfb.methods.present = LinuxFB_Present; - linuxfb.methods.setCaptionW = NULL; - linuxfb.methods.setRenderMode = LinuxFB_SetRenderMode; - linuxfb.methods.setOpacity = NULL; - linuxfb.methods.beginPaint = LinuxFB_BeginPaint; - linuxfb.methods.endPaint = LinuxFB_EndPaint; - linuxfb.methods.onInvalidRect = NULL; - linuxfb.methods.onEvent = NULL; - return &linuxfb.methods; -} - -int LCUIDisplay_ExitLinuxFB(void) -{ - LinuxFB_Restore(); - return 0; -} - -#endif diff --git a/src/output/win32.c b/src/output/win32.c deleted file mode 100755 index 58f65a55..00000000 --- a/src/output/win32.c +++ /dev/null @@ -1,403 +0,0 @@ -/* *************************************************************************** - * win32.c -- win32 platform support for graphical output - * - * Copyright (C) 2012-2013 by - * Liu Chao - * - * 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 . - * ****************************************************************************/ - -/* **************************************************************************** - * win32.c -- win32平台上的图形输出支持 - * - * 版权所有 (C) 2013 归属于 - * 刘超 - * - * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 - * - * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) - * - * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 - * - * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 - * 定用途的隐含担保,详情请参照GPLv2许可协议。 - * - * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 - * 没有,请查看:. - * ****************************************************************************/ - -#include -#include - -#ifdef LCUI_VIDEO_DRIVER_WIN32 - -#include -#include -#include -#include -#include -#include "resource.h" - -#define WIN32_WINDOW_STYLE (WS_OVERLAPPEDWINDOW &~WS_THICKFRAME &~WS_MAXIMIZEBOX) - -static HWND current_hwnd = NULL; -static HINSTANCE win32_hInstance = NULL, dll_hInstance = NULL; -static LCUI_Mutex screen_mutex; -static LCUI_Thread th_win32; -static LCUI_Graph framebuffer; -static HDC hdc_framebuffer; -static HBITMAP client_bitmap; -static LCUI_Cond win32_init_cond; -static LCUI_BOOL win32_init_error = TRUE; -static LCUI_BOOL is_running = FALSE; - -void Win32_LCUI_Init__( HINSTANCE hInstance ) -{ - win32_hInstance = hInstance; -} - -HWND Win32_GetSelfHWND( void ) -{ - return current_hwnd; -} - -void Win32_SetSelfHWND( HWND hwnd ) -{ - current_hwnd = hwnd; -} - -/** win32的动态库的入口函数 */ -BOOL APIENTRY DllMain__( HMODULE hModule, DWORD ul_reason_for_call, - LPVOID lpReserved ) -{ - switch (ul_reason_for_call) - { - case DLL_PROCESS_ATTACH: - case DLL_THREAD_ATTACH: - case DLL_THREAD_DETACH: - case DLL_PROCESS_DETACH: - break; - } - dll_hInstance = hModule; - return TRUE; -} - -static LRESULT CALLBACK Win32_LCUI_WndProc( HWND hwnd, UINT message, - WPARAM wParam, LPARAM lParam ) -{ - PAINTSTRUCT ps; - LCUI_Rect area; - - switch (message) { - case WM_KEYDOWN: - LCUI_PostKeyDownEvent( wParam ); - return 0; - case WM_KEYUP: - LCUI_PostKeyUpEvent( wParam ); - return 0; - case WM_RBUTTONDOWN: - LCUI_PostMouseDownEvent( LCUIKEY_RIGHTBUTTON ); - return 0; - case WM_RBUTTONUP: - LCUI_PostMouseUpEvent( LCUIKEY_RIGHTBUTTON ); - return 0; - case WM_LBUTTONDOWN: - LCUI_PostMouseDownEvent( LCUIKEY_LEFTBUTTON ); - return 0; - case WM_LBUTTONUP: - LCUI_PostMouseUpEvent( LCUIKEY_LEFTBUTTON ); - return 0; - case WM_PAINT: - BeginPaint( hwnd, &ps ); - /* 获取区域坐标及尺寸 */ - area.x = ps.rcPaint.left; - area.y = ps.rcPaint.top; - area.width = ps.rcPaint.right - area.x; - area.height = ps.rcPaint.bottom - area.y; - /* 记录该无效区域 */ - LCUIScreen_InvalidateArea( &area ); - EndPaint( hwnd, &ps ); - return 0; - case WM_DESTROY: - PostQuitMessage(0); - LCUI_Quit(); - return 0; - default:break; - } - return DefWindowProc( hwnd, message, wParam, lParam ); -} - -static int Win32_ScreenInit(void) -{ - WNDCLASS wndclass; - TCHAR szAppName[] = TEXT ("LCUI OutPut"); - - wndclass.style = CS_HREDRAW | CS_VREDRAW; - wndclass.lpfnWndProc = Win32_LCUI_WndProc; - wndclass.cbClsExtra = 0; - wndclass.cbWndExtra = 0; - wndclass.hInstance = win32_hInstance; - /* 载入动态库里的图标 */ - wndclass.hIcon = LoadIcon( dll_hInstance, MAKEINTRESOURCE(IDI_MAIN_ICON) ); - wndclass.hCursor = LoadCursor( NULL, IDC_ARROW ); - wndclass.hbrBackground = (HBRUSH) GetStockObject( WHITE_BRUSH ); - wndclass.lpszMenuName = NULL; - wndclass.lpszClassName = szAppName; - - if( !RegisterClass(&wndclass) ) { - MessageBox( NULL, TEXT("This program requires Windows NT!" ), - szAppName, MB_ICONERROR ); - return -1; - } - /* 创建窗口 */ - current_hwnd = CreateWindow( - szAppName, TEXT ("LCUI Application"), - WIN32_WINDOW_STYLE, - CW_USEDEFAULT, CW_USEDEFAULT, - 0, 0, - NULL, NULL, win32_hInstance, NULL); - return 0; -} - -/** Win32的消息循环线程 */ -static void LCUI_Win32_Thread( void *arg ) -{ - MSG msg; - if( Win32_ScreenInit() == -1 ) { - /* 设置标志为TRUE,表示初始化失败 */ - win32_init_error = TRUE; - /* 打断处于睡眠状态的线程的睡眠 */ - LCUICond_Broadcast( &win32_init_cond ); - LCUIThread_Exit(NULL); - return; - } - /* 设置标志为FALSE,表示初始化成功 */ - win32_init_error = FALSE; - /* 隐藏windows的鼠标游标 */ - ShowCursor( FALSE ); - LCUICond_Broadcast( &win32_init_cond ); - while( is_running ) { - /* 获取消息 */ - if( GetMessage( &msg, Win32_GetSelfHWND(), 0, 0 ) ) { - TranslateMessage( &msg ); - DispatchMessage( &msg ); - } - } - LCUIThread_Exit(NULL); -} - -/** 初始化屏幕 */ -static int Win32Screen_Init( int w, int h, int mode ) -{ - HDC hdc_client; - LCUI_ScreenInfo screen_info; - - is_running = TRUE; - /* 初始化屏幕互斥锁 */ - LCUIMutex_Init( &screen_mutex ); - LCUICond_Init( &win32_init_cond ); - /* 创建线程 */ - LCUIThread_Create( &th_win32, LCUI_Win32_Thread, NULL ); - /* 进行睡眠,最长时间为5秒 */ - LCUICond_TimedWait( &win32_init_cond, 5000 ); - /* 若初始化出现错误 */ - if( win32_init_error ) { - return -1; - } - /* 准备屏幕相关信息 */ - screen_info.bits = 32; - screen_info.mode = mode; - strcpy( screen_info.dev_name, "win32 GDI" ); - /* 设置屏幕信息 */ - LCUIScreen_SetInfo( &screen_info ); - /* 设置图形输出模式 */ - LCUIScreen_SetMode( w, h, mode ); - /* 获取屏幕信息 */ - LCUIScreen_GetInfo( &screen_info ); - - framebuffer.color_type = COLOR_TYPE_ARGB; - if( Graph_Create(&framebuffer, w, h) != 0 ) { - return -2; - } - /* 获取客户区的DC */ - hdc_client = GetDC( current_hwnd ); - /* 为帧缓冲创建一个DC */ - hdc_framebuffer = CreateCompatibleDC( hdc_client ); - /* 为客户区创建一个Bitmap */ - client_bitmap = CreateCompatibleBitmap( hdc_client, w, h ); - /* 为帧缓冲的DC选择client_bitmap作为对象 */ - SelectObject( hdc_framebuffer, client_bitmap ); - - Widget_Resize( LCUIRootWidget, screen_info.size.w, screen_info.size.h ); - Widget_SetBackgroundColor( LCUIRootWidget, RGB(255,255,255) ); - Widget_Show( LCUIRootWidget ); - - UpdateWindow( current_hwnd ); - /* 显示窗口 */ - ShowWindow( current_hwnd, SW_SHOWNORMAL ); - /* 前置并激活窗口 */ - SetForegroundWindow( current_hwnd ); - return 0; -} - -/* 设置视频输出模式 */ -static int Win32Screen_SetMode( int w, int h, int mode ) -{ - LCUI_Pos pos; - LCUI_Size real_size; - LCUI_ScreenInfo screen_info; - - LCUIMutex_Lock( &screen_mutex ); - LCUIScreen_GetInfo( &screen_info ); - real_size.w = GetSystemMetrics(SM_CXSCREEN); - real_size.h = GetSystemMetrics(SM_CYSCREEN); - if( mode == LCUI_MODE_AUTO ) { - if( w == 0 && h == 0 ) { - mode = LCUI_MODE_FULLSCREEN; - } else { - mode = LCUI_MODE_WINDOWED; - } - } - if( mode == LCUI_MODE_FULLSCREEN ) { - if( w == 0 ) { - w = real_size.w; - } - if( h == 0 ) { - h = real_size.h; - } - SetWindowLong( current_hwnd, GWL_STYLE, WS_POPUP ); - SetWindowPos( current_hwnd, HWND_NOTOPMOST, 0, 0, - real_size.w, real_size.h, SWP_SHOWWINDOW ); - } else { - RECT rect; - int boader_w, boader_h; - /* 计算边框的尺寸 */ - boader_w = GetSystemMetrics(SM_CXFIXEDFRAME) * 2; - boader_h = GetSystemMetrics(SM_CYFIXEDFRAME) * 2; - boader_h += GetSystemMetrics(SM_CYCAPTION); - /* 计算窗口尺寸 */ - w = w + boader_w; - h = h + boader_h; - pos.x = (real_size.w - w)/2; - pos.y = (real_size.h - h)/2; - - SetWindowLong( current_hwnd, GWL_STYLE, WIN32_WINDOW_STYLE ); - /* 调整窗口尺寸 */ - SetWindowPos( current_hwnd, HWND_NOTOPMOST, - pos.x, pos.y, w, h, SWP_SHOWWINDOW ); - /* 获取客户区的尺寸 */ - GetClientRect( current_hwnd, &rect ); - w = rect.right; - h = rect.bottom; - } - screen_info.size.w = w; - screen_info.size.h = h; - screen_info.mode = mode; - /* 重新调整帧缓冲大小 */ - if( Graph_Create(&framebuffer, w, h) != 0 ) { - return -2; - } - LCUIScreen_SetInfo( &screen_info ); - Widget_Resize( LCUIRootWidget, w, h ); - - LCUIMutex_Unlock( &screen_mutex ); - return 0; -} - -static int Win32Screen_Destroy( void ) -{ - is_running = FALSE; - LCUIMutex_Destroy( &screen_mutex ); - return 0; -} - -static int Win32Screen_PutGraph( const LCUI_Graph *graph, LCUI_Pos pos ) -{ - Graph_Replace( &framebuffer, graph, pos ); - return 0; -} - -static int Win32Screen_MixGraph( const LCUI_Graph *graph, LCUI_Pos pos ) -{ - Graph_Mix( &framebuffer, graph, pos ); - return 0; -} - -static int Win32Screen_Sync( void ) -{ - HDC hdc_client; - RECT client_rect; - - hdc_client = GetDC( current_hwnd ); - LCUIMutex_Lock( &screen_mutex ); - SetBitmapBits( client_bitmap, framebuffer.mem_size, framebuffer.bytes ); - switch(LCUIScreen_GetMode()) { - case LCUI_MODE_FULLSCREEN: - /* 全屏模式下,则使用拉伸模式,将帧拉伸至全屏 */ - GetClientRect( current_hwnd, &client_rect ); - StretchBlt( hdc_client, 0, 0, - client_rect.right, client_rect.bottom, - hdc_framebuffer, 0, 0, - LCUIScreen_GetWidth(), LCUIScreen_GetHeight(), - SRCCOPY ); - break; - case LCUI_MODE_WINDOWED: - /* 将帧缓冲内的位图数据更新至客户区内指定区域(area) */ - BitBlt( hdc_client, 0, 0, - LCUIScreen_GetWidth(), LCUIScreen_GetHeight(), - hdc_framebuffer, 0, 0, - SRCCOPY ); - break; - } - ValidateRect( current_hwnd, NULL ); - LCUIMutex_Unlock( &screen_mutex ); - return 0; -} - -static int Win32Screen_CatchGraph( LCUI_Graph *out, LCUI_Rect area ) -{ - return -1; -#ifdef test - LCUI_Rect cut_rect; - if( !LCUI_Active() ) { - return -1; - } - /* 如果需要裁剪图形 */ - LCUIRect_GetCutArea( Size(framebuffer.w, framebuffer.h), area, &cut_rect ); - if( cut_rect.w <= 0 || cut_rect.h <= 0 ) { - return -2; - } - area.x += cut_rect.x; - area.y += cut_rect.y; - area.width = cut_rect.width; - area.height = cut_rect.height; - Graph_Cut( &framebuffer, cut_rect, out ); - return 0; -#endif -} - -void LCUIScreen_UseWin32( LCUI_Screen *screen ) -{ - screen->Init = Win32Screen_Init; - screen->Sync = Win32Screen_Sync; - screen->Destroy = Win32Screen_Destroy; - screen->SetMode = Win32Screen_SetMode; - screen->PutGraph = Win32Screen_PutGraph; - screen->MixGraph = Win32Screen_MixGraph; - screen->CatchGraph = Win32Screen_CatchGraph; -} - -#endif diff --git a/src/output/win32_surface.c b/src/output/win32_surface.c deleted file mode 100644 index 78210e7e..00000000 --- a/src/output/win32_surface.c +++ /dev/null @@ -1,581 +0,0 @@ -/* *************************************************************************** - * win32_surface.c -- surface support for win32 platform. - * - * Copyright (C) 2014-2016 by Liu Chao - * - * 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 . - * ***************************************************************************/ - -/* **************************************************************************** - * win32_surface.c -- win32平台的 surface 功能支持。 - * - * 版权所有 (C) 2014-2016 归属于 刘超 - * - * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 - * - * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) - * - * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 - * - * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 - * 定用途的隐含担保,详情请参照GPLv2许可协议。 - * - * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 - * 没有,请查看:. - * ***************************************************************************/ -//#define DEBUG -#include -#define __IN_SURFACE_SOURCE_FILE__ -#ifdef LCUI_BUILD_IN_WIN32 -#include -#include -#include -#include -#include "resource.h" - -#define WIN32_WINDOW_STYLE (WS_OVERLAPPEDWINDOW &~WS_THICKFRAME &~WS_MAXIMIZEBOX) -#define MSG_SURFACE_CREATE WM_USER+100 - -enum SurfaceTaskType { - TASK_MOVE, - TASK_RESIZE, - TASK_SHOW, - TASK_SET_CAPTION, - TASK_TOTAL_NUM -}; - -typedef struct LCUI_SurfaceTask { - LCUI_BOOL is_valid; - union { - struct { - int x, y; - }; - struct { - int width, height; - }; - LCUI_BOOL show; - wchar_t *caption; - }; -} LCUI_SurfaceTask; - -struct LCUI_SurfaceRec_ { - HWND hwnd; - int mode; - int w, h; - HDC fb_hdc; - HBITMAP fb_bmp; - LCUI_BOOL is_ready; - LCUI_Graph fb; - LCUI_SurfaceTask task_buffer[TASK_TOTAL_NUM]; -}; - -static struct { - HINSTANCE main_instance; /**< 主程序的资源句柄 */ - HINSTANCE dll_instance; /**< 动态库中的资源句柄 */ - LCUI_Thread loop_thread; /**< 消息循环线程 */ - LCUI_Cond cond; /**< 条件,当消息循环已创建时成立 */ - LCUI_Mutex mutex; /**< 互斥锁 */ - LCUI_BOOL is_ready; /**< 消息循环线程是否已准备好 */ - LinkedList surfaces; /**< surface 记录 */ - LCUI_SurfaceMethods methods; /**< 方法集 */ -} win32; - -void LCUI_InitWin32Mode( HINSTANCE hInstance ) -{ - win32.main_instance = hInstance; -} - -/** win32的动态库的入口函数 */ -BOOL APIENTRY DllMain( HMODULE hModule, DWORD reason, LPVOID unused ) -{ - switch (reason) { - case DLL_PROCESS_ATTACH: - case DLL_THREAD_ATTACH: - case DLL_THREAD_DETACH: - case DLL_PROCESS_DETACH: - break; - } - win32.dll_instance = hModule; - return TRUE; -} - -/** 根据 hwnd 获取 Surface */ -static LCUI_Surface GetSurfaceByHWND( HWND hwnd ) -{ - LinkedListNode *node; - LinkedList_ForEach( node, &win32.surfaces ) { - if( ((LCUI_Surface)node->data)->hwnd == hwnd ) { - return node->data; - } - } - return NULL; -} - -static void Win32Surface_Destroy( LCUI_Surface surface ) -{ - surface->w = 0; - surface->h = 0; - if( surface->hwnd ) { - if( surface->fb_hdc ) { - ReleaseDC( surface->hwnd, surface->fb_hdc ); - } - } - if( surface->fb_bmp ) { - DeleteObject( surface->fb_bmp ); - } - surface->fb_hdc = NULL; - surface->fb_bmp = NULL; - surface->hwnd = NULL; - Graph_Free( &surface->fb ); -} - -static void Win32Surface_ExecDelete( LCUI_Surface surface ) -{ - LinkedListNode *node; - LinkedList_ForEach( node, &win32.surfaces ) { - if( node->data == surface ) { - Win32Surface_Destroy( node->data ); - LinkedList_DeleteNode( &win32.surfaces, node ); - break; - } - } -} - -/** 删除 Surface */ -static void Win32Surface_Delete( LCUI_Surface surface ) -{ - if( surface->hwnd ) { - PostMessage( surface->hwnd, WM_CLOSE, 0, 0 ); - } -} - -static LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, - WPARAM arg1, LPARAM arg2 ) -{ - LCUI_SysEventRec e = {0}; - LCUI_Surface surface = GetSurfaceByHWND(hwnd); - DEBUG_MSG( "surface: %p, msg: %d\n", surface, msg ); - if( !surface ) { - return DefWindowProc( hwnd, msg, arg1, arg2 ); - } - switch( msg ) { - case WM_KEYDOWN: - e.type = LCUI_KEYDOWN; - e.key_code = arg1; - break; - case WM_KEYUP: - e.type = LCUI_KEYUP; - e.key_code = arg1; - break; - case WM_MOUSEMOVE: { - POINT new_pos; - GetCursorPos( &new_pos ); - ScreenToClient( hwnd, &new_pos ); - e.rel_x = new_pos.x; - e.rel_y = new_pos.y; - e.type = LCUI_MOUSEMOVE; - break; - } - case WM_LBUTTONDOWN: - e.type = LCUI_MOUSEDOWN; - e.key_code = 1; - break; - case WM_LBUTTONUP: - e.type = LCUI_MOUSEUP; - e.key_code = 1; - break; - case WM_RBUTTONDOWN: - e.type = LCUI_MOUSEDOWN; - e.key_code = 2; - break; - case WM_RBUTTONUP: - e.type = LCUI_MOUSEUP; - e.key_code = 2; - break; - case WM_MOUSEWHEEL: - e.type = LCUI_MOUSEWHEEL; - e.z_delta = GET_WHEEL_DELTA_WPARAM(arg1); - break; - case WM_PAINT: { - PAINTSTRUCT ps; - LCUI_Rect area; - - BeginPaint( hwnd, &ps ); - /* 获取区域坐标及尺寸 */ - area.x = ps.rcPaint.left; - area.y = ps.rcPaint.top; - area.width = ps.rcPaint.right - area.x; - area.height = ps.rcPaint.bottom - area.y; - if( win32.methods.onInvalidRect ) { - win32.methods.onInvalidRect( surface, &area ); - } - EndPaint( hwnd, &ps ); - return 0; - } - case WM_CLOSE: - if( LCUIDisplay_GetMode() != LDM_SEAMLESS ) { - LCUI_Quit(); - } - break; - case WM_DESTROY: - Win32Surface_ExecDelete( surface ); - break; - case WM_SHOWWINDOW: - if( arg1 ) { - //Widget_Show( surface->target ); - } else { - //Widget_Hide( surface->target ); - } - break; - case WM_ACTIVATE: - break; - default:break; - } - if( e.type != LCUI_NONE && win32.methods.onEvent ) { - win32.methods.onEvent( surface, &e ); - } - return DefWindowProc( hwnd, msg, arg1, arg2 ); -} - -/** 新建一个 Surface */ -static LCUI_Surface Win32Surface_New(void) -{ - int i; - LCUI_Surface surface; - surface = NEW(struct LCUI_SurfaceRec_, 1); - surface->mode = RENDER_MODE_BIT_BLT; - surface->hwnd = NULL; - surface->fb_hdc = NULL; - surface->fb_bmp = NULL; - surface->is_ready = FALSE; - Graph_Init( &surface->fb ); - surface->fb.color_type = COLOR_TYPE_ARGB; - for( i=0; itask_buffer[i].is_valid = FALSE; - } - LinkedList_Append( &win32.surfaces, surface ); - if( !win32.is_ready ) { - LCUIMutex_Lock( &win32.mutex ); - /* 等待 Surface 线程创建完 windows 消息队列 */ - LCUICond_Wait( &win32.cond, &win32.mutex ); - LCUIMutex_Unlock( &win32.mutex ); - } - /* 让 Surface 线程去完成 windows 窗口的创建 */ - PostThreadMessage( win32.loop_thread, MSG_SURFACE_CREATE, 0, (LPARAM)surface ); - return surface; -} - -static LCUI_BOOL Win32Surface_IsReady( LCUI_Surface surface ) -{ - return surface->is_ready; -} - -static void Win32Surface_ExecMove( LCUI_Surface surface, int x, int y ) -{ - x += GetSystemMetrics( SM_CXFIXEDFRAME ); - y += GetSystemMetrics( SM_CYFIXEDFRAME ); - SetWindowPos( surface->hwnd, HWND_NOTOPMOST, - x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER ); - return; -} - -static void Win32Surface_Move( LCUI_Surface surface, int x, int y ) -{ - /* 缓存任务,等获得窗口句柄后处理 */ - surface->task_buffer[TASK_MOVE].x = x; - surface->task_buffer[TASK_MOVE].y = y; - surface->task_buffer[TASK_MOVE].is_valid = TRUE; -} - -static void Win32Surface_ExecResize( LCUI_Surface surface, int w, int h ) -{ - HDC hdc_client; - HBITMAP old_bmp; - RECT rect_client, rect_window; - surface->w = w; - surface->h = h; - _DEBUG_MSG("w = %d, h = %d\n", w, h); - Graph_Create( &surface->fb, w, h ); - hdc_client = GetDC( surface->hwnd ); - surface->fb_bmp = CreateCompatibleBitmap( hdc_client, w, h ); - old_bmp = (HBITMAP)SelectObject( surface->fb_hdc, surface->fb_bmp ); - if( old_bmp ) { - DeleteObject( old_bmp ); - } - GetClientRect( surface->hwnd, &rect_client ); - GetWindowRect( surface->hwnd, &rect_window ); - w += rect_window.right - rect_window.left; - w -= rect_client.right - rect_client.left; - h += rect_window.bottom - rect_window.top; - h -= rect_client.bottom - rect_client.top; - //SetWindowLong( surface->hwnd, GWL_STYLE, WIN32_WINDOW_STYLE ); - SetWindowPos( surface->hwnd, HWND_NOTOPMOST, - 0, 0, w, h, SWP_NOMOVE | SWP_NOZORDER ); -} - -static void Win32Surface_Resize( LCUI_Surface surface, int w, int h ) -{ - surface->task_buffer[TASK_RESIZE].width = w; - surface->task_buffer[TASK_RESIZE].height = h; - surface->task_buffer[TASK_RESIZE].is_valid = TRUE; -} - -static void Win32Surface_Show( LCUI_Surface surface ) -{ - DEBUG_MSG("surface: %p, buffer show.\n", surface); - surface->task_buffer[TASK_SHOW].show = TRUE; - surface->task_buffer[TASK_SHOW].is_valid = TRUE; -} - -static void Win32Surface_Hide( LCUI_Surface surface ) -{ - surface->task_buffer[TASK_SHOW].show = FALSE; - surface->task_buffer[TASK_SHOW].is_valid = TRUE; -} - -static void Win32Surface_SetCaptionW( LCUI_Surface surface, const wchar_t *str ) -{ - int len; - wchar_t *caption = NULL; - - if( str ) { - len = wcslen(str) + 1; - caption = (wchar_t*)malloc(sizeof(wchar_t)*len); - wcsncpy( caption, str, len ); - } - if( surface->task_buffer[TASK_SET_CAPTION].is_valid - && surface->task_buffer[TASK_SET_CAPTION].caption ) { - free( surface->task_buffer[TASK_SET_CAPTION].caption ); - } - surface->task_buffer[TASK_SET_CAPTION].caption = caption; - surface->task_buffer[TASK_SET_CAPTION].is_valid = TRUE; -} - -void Win32Surface_SetOpacity( LCUI_Surface surface, float opacity ) -{ - -} - -/** 设置 Surface 的渲染模式 */ -static void Win32Surface_SetRenderMode( LCUI_Surface surface, int mode ) -{ - surface->mode = mode; -} - -/** - * 准备绘制 Surface 中的内容 - * @param[in] surface 目标 surface - * @param[in] rect 需进行绘制的区域,若为NULL,则绘制整个 surface - * @return 返回绘制上下文句柄 - */ -static LCUI_PaintContext Win32Surface_BeginPaint( LCUI_Surface surface, LCUI_Rect *rect ) -{ - LCUI_PaintContext paint; - paint = malloc(sizeof(LCUI_PaintContextRec)); - paint->rect = *rect; - Graph_Init( &paint->canvas ); - LCUIRect_ValidateArea( &paint->rect, surface->w, surface->h ); - Graph_Quote( &paint->canvas, &surface->fb, &paint->rect ); - Graph_FillRect( &paint->canvas, RGB( 255, 255, 255 ), NULL, TRUE ); - return paint; -} - -/** - * 结束对 Surface 的绘制操作 - * @param[in] surface 目标 surface - * @param[in] paint_ctx 绘制上下文句柄 - */ -static void Win32Surface_EndPaint( LCUI_Surface surface, LCUI_PaintContext paint_ctx ) -{ - free( paint_ctx ); -} - -/** 将帧缓存中的数据呈现至Surface的窗口内 */ -static void Win32Surface_Present( LCUI_Surface surface ) -{ - HDC hdc_client; - RECT client_rect; - - DEBUG_MSG("surface: %p, hwnd: %p\n", surface, surface->hwnd); - hdc_client = GetDC( surface->hwnd ); - SetBitmapBits( surface->fb_bmp, surface->fb.mem_size, surface->fb.bytes ); - switch(surface->mode) { - case RENDER_MODE_STRETCH_BLT: - GetClientRect( surface->hwnd, &client_rect ); - StretchBlt( hdc_client, 0, 0, - client_rect.right, client_rect.bottom, - surface->fb_hdc, 0, 0, - surface->w, surface->h, SRCCOPY ); - break; - case RENDER_MODE_BIT_BLT: - default: - BitBlt( hdc_client, 0, 0, surface->w, surface->h, - surface->fb_hdc, 0, 0, SRCCOPY ); - break; - } - ValidateRect( surface->hwnd, NULL ); -} - -/** 更新 surface,应用缓存的变更 */ -static void Win32Surface_Update( LCUI_Surface surface ) -{ - LCUI_SurfaceTask *t; - if( !surface->hwnd ) { - return; - } - DEBUG_MSG("surface: %p\n", surface); - t = &surface->task_buffer[TASK_MOVE]; - if( t->is_valid ) { - Win32Surface_ExecMove( surface, t->x, t->y ); - t->is_valid = FALSE; - } - t = &surface->task_buffer[TASK_RESIZE]; - if( t->is_valid ) { - Win32Surface_ExecResize( surface, t->width, t->height ); - t->is_valid = FALSE; - } - t = &surface->task_buffer[TASK_SET_CAPTION]; - if( t->is_valid ) { - SetWindowText( surface->hwnd, t->caption ); - if( t->caption ) { - free( t->caption ); - t->caption = NULL; - } - } - t->is_valid = FALSE; - t = &surface->task_buffer[TASK_SHOW]; - DEBUG_MSG("surface: %p, hwnd: %p, is_valid: %d, show: %d\n", - surface, surface->hwnd, t->is_valid, t->show); - if( t->is_valid ) { - if( t->show ) { - ShowWindow( surface->hwnd, SW_SHOWNORMAL ); - } else { - ShowWindow( surface->hwnd, SW_HIDE ); - } - } - t->is_valid = FALSE; -} - -static void* Win32Surface_GetHandle( LCUI_Surface s ) -{ - return s->hwnd; -} - -static void LCUISurface_Loop( void *args ) -{ - MSG msg; - LCUI_Surface surface; - DEBUG_MSG("start\n"); - /* 创建消息队列 */ - PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE); - win32.is_ready = TRUE; - LCUIMutex_Lock( &win32.mutex ); - LCUICond_Broadcast( &win32.cond ); - LCUIMutex_Unlock( &win32.mutex ); - while( GetMessage( &msg, NULL, 0, 0 ) ) { - if( msg.message == MSG_SURFACE_CREATE ) { - HDC hdc_client; - surface = (LCUI_Surface)msg.lParam; - /* 为 Surface 创建窗口 */ - surface->hwnd = CreateWindow( - TEXT("LCUI"), TEXT("LCUI Surface"), - WIN32_WINDOW_STYLE, - CW_USEDEFAULT, CW_USEDEFAULT, - 0, 0, NULL, NULL, - win32.main_instance, NULL - ); - hdc_client = GetDC( surface->hwnd ); - surface->fb_hdc = CreateCompatibleDC( hdc_client ); - surface->is_ready = TRUE; - DEBUG_MSG("surface: %p, surface->hwnd: %p\n", surface, surface->hwnd); - continue; - } - TranslateMessage( &msg ); - DispatchMessage( &msg ); - } - DEBUG_MSG("quit\n"); - LCUIThread_Exit(NULL); -} - -static int Win32Display_GetWidth( void ) -{ - return GetSystemMetrics( SM_CXSCREEN ); -} - -static int Win32Display_GetHeight( void ) -{ - return GetSystemMetrics( SM_CYSCREEN ); -} - -/** 初始化适用于 Win32 平台的 surface 支持 */ -LCUI_SurfaceMethods *LCUIDisplay_InitWin32( LCUI_DisplayInfo *info ) -{ - WNDCLASS wndclass; - TCHAR szAppName[] = TEXT ("LCUI"); - - wndclass.style = CS_HREDRAW | CS_VREDRAW; - wndclass.lpfnWndProc = WndProc; - wndclass.cbClsExtra = 0; - wndclass.cbWndExtra = 0; - wndclass.hInstance = win32.main_instance; - /* 载入动态库里的图标 */ - wndclass.hIcon = LoadIcon( win32.dll_instance, MAKEINTRESOURCE(IDI_LCUI_ICON) ); - wndclass.hCursor = LoadCursor( NULL, IDC_ARROW ); - wndclass.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH ); - wndclass.lpszMenuName = NULL; - wndclass.lpszClassName = szAppName; - - if( !RegisterClass(&wndclass) ) { - wchar_t str[256]; - wsprintf(str, L"LCUISurface_Init(): error code: %d\n", GetLastError()); - MessageBox( NULL, str, szAppName, MB_ICONERROR ); - return NULL; - } - info->getWidth = Win32Display_GetWidth; - info->getHeight = Win32Display_GetHeight; - strncpy( info->name, "win32", 32 ); - win32.is_ready = FALSE; - win32.methods.new = Win32Surface_New; - win32.methods.delete = Win32Surface_Delete; - win32.methods.isReady = Win32Surface_IsReady; - win32.methods.show = Win32Surface_Show; - win32.methods.hide = Win32Surface_Hide; - win32.methods.move = Win32Surface_Move; - win32.methods.resize = Win32Surface_Resize; - win32.methods.update = Win32Surface_Update; - win32.methods.present = Win32Surface_Present; - win32.methods.setCaptionW = Win32Surface_SetCaptionW; - win32.methods.setRenderMode = Win32Surface_SetRenderMode; - win32.methods.setOpacity = Win32Surface_SetOpacity; - win32.methods.getHandle = Win32Surface_GetHandle; - win32.methods.beginPaint = Win32Surface_BeginPaint; - win32.methods.endPaint = Win32Surface_EndPaint; - win32.methods.onInvalidRect = NULL; - win32.methods.onEvent = NULL; - LCUICond_Init( &win32.cond ); - LCUIMutex_Init( &win32.mutex ); - LinkedList_Init( &win32.surfaces ); - LCUIThread_Create( &win32.loop_thread, LCUISurface_Loop, NULL ); - return &win32.methods; -} - -int LCUIDisplay_ExitWin32(void) -{ - // ... - return 0; -} - -#endif From b5cec0750150f0a71dde31b17a6f78d6a6fa2c40 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Sun, 5 Jun 2016 15:23:04 +0800 Subject: [PATCH 034/124] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/input/Makefile.am | 5 - src/input/keyboard.c | 312 ---------------------------------------- src/input/mouse.c | 217 ---------------------------- src/input/touchscreen.c | 171 ---------------------- 4 files changed, 705 deletions(-) delete mode 100755 src/input/Makefile.am delete mode 100755 src/input/keyboard.c delete mode 100644 src/input/mouse.c delete mode 100755 src/input/touchscreen.c diff --git a/src/input/Makefile.am b/src/input/Makefile.am deleted file mode 100755 index 231e788a..00000000 --- a/src/input/Makefile.am +++ /dev/null @@ -1,5 +0,0 @@ -AUTOMAKE_OPTIONS=foreign -AM_CFLAGS = -I$(abs_top_srcdir)/include -noinst_LTLIBRARIES = libinput.la -libinput_la_SOURCES = mouse.c keyboard.c touchscreen.c - diff --git a/src/input/keyboard.c b/src/input/keyboard.c deleted file mode 100755 index e1541937..00000000 --- a/src/input/keyboard.c +++ /dev/null @@ -1,312 +0,0 @@ - /* *************************************************************************** - * keyboard.c -- keyboard support - * - * Copyright (C) 2013-2016 by Liu Chao - * - * 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 . - * ***************************************************************************/ - -/* **************************************************************************** - * keyboard.c -- 键盘支持 - * - * 版权所有 (C) 2013-2016 归属于 刘超 - * - * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 - * - * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) - * - * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 - * - * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 - * 定用途的隐含担保,详情请参照GPLv2许可协议。 - * - * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 - * 没有,请查看:. - * ***************************************************************************/ - -#include -#include -#include -#include - -#include - -#include - -typedef struct KeyState { - int key_code; /**< 按键键值 */ - int state; /**< 当前状态 */ - clock_t hit_time; /**< 按下此键时的时间 */ - clock_t interval_time; /**< 近两次按下此键的时间间隔 */ -} KeyState; - -static LCUI_Mutex record_mutex; -static LinkedList key_state_record; - -#ifdef LCUI_KEYBOARD_DRIVER_LINUX - -//#define __NEED_CATCHSCREEN__ -#ifdef __NEED_CATCHSCREEN__ -#include -#include -#endif - -#include -#include -#include - -static struct termios tm;//, tm_old; -static int fd = STDIN_FILENO; -#endif - -/** 获取指定按键的状态数据 */ -static KeyState *GetKeySate( int key_code ) -{ - KeyState *ks; - LinkedListNode *node; - - LinkedList_ForEach( node, &key_state_record ) { - ks = (KeyState*)node->data; - if( ks && ks->key_code == key_code ) { - return ks; - } - } - return NULL; -} - -/** 检测指定键值的按键是否处于按下状态 */ -LCUI_BOOL LCUIKey_IsHit( int key_code ) -{ - KeyState *ks; - LCUIMutex_Lock( &record_mutex ); - ks = GetKeySate( key_code ); - LCUIMutex_Unlock( &record_mutex ); - if( ks && ks->state == LCUIKEYSTATE_PRESSED ) { - return TRUE; - } - return FALSE; -} - -/** -检测指定键值的按键是否按了两次 -@param key_code - 要检测的按键的键值 -@param interval_time - 该按键倒数第二次按下时的时间与当前时间的最大间隔 - */ -LCUI_BOOL LCUIKey_IsDoubleHit( int key_code, int interval_time ) -{ - clock_t ct; - KeyState* ks; - /* 计算当前时间(单位:毫秒) */ - ct = clock()*1000 / CLOCKS_PER_SEC; - LCUIMutex_Lock( &record_mutex ); - ks = GetKeySate( key_code ); - LCUIMutex_Unlock( &record_mutex ); - if( !ks ) { - return FALSE; - } - /* 间隔时间为-1,说明该键是新记录的 */ - if( ks->interval_time == -1 ) { - return FALSE; - } - ct -= (ks->hit_time - ks->interval_time); - /* 判断按键被按下两次时是否在距当前interval_time毫秒的时间内发生 */ - if( ct <= interval_time ) { - return TRUE; - } - return FALSE; -} - -/** 添加已被按下的按键 */ -void LCUIKeyBoard_HitKey( int key_code ) -{ - clock_t ct; - KeyState *ks; - - LCUIMutex_Lock( &record_mutex ); - ct = clock()*1000 / CLOCKS_PER_SEC; - ks = GetKeySate( key_code ); - if( !ks ) { - ks = NEW(KeyState, 1); - ks->key_code = key_code; - ks->interval_time = -1; - ks->hit_time = ct; - ks->state = LCUIKEYSTATE_PRESSED; - LinkedList_Append( &key_state_record, ks ); - LCUIMutex_Unlock( &record_mutex ); - return; - } - if( ks->state == LCUIKEYSTATE_RELEASE ) { - ks->state = LCUIKEYSTATE_PRESSED; - /* 记录与上次此键被按下时的时间间隔 */ - ks->interval_time = ct - ks->hit_time; - /* 记录本次此键被按下时的时间 */ - ks->hit_time = ct; - } - LCUIMutex_Unlock( &record_mutex ); -} - -/** 标记指定键值的按键已释放 */ -void LCUIKeyBoard_ReleaseKey( int key_code ) -{ - KeyState *ks; - LCUIMutex_Lock( &record_mutex ); - ks = GetKeySate( key_code ); - if( ks ) { - ks->state = LCUIKEYSTATE_RELEASE; - } - LCUIMutex_Unlock( &record_mutex ); -} - -/* 初始化键盘输入 */ -static LCUI_BOOL LCUIKeyboard_Init( void ) -{ -#ifdef LCUI_KEYBOARD_DRIVER_LINUX - if(tcgetattr(fd, &tm) < 0) { - return -1; - } - /* 设置终端为无回显无缓冲模式 */ - tm.c_lflag &= ~(ICANON|ECHO); - tm.c_cc[VMIN] = 1; - tm.c_cc[VTIME] = 0; - if(tcsetattr(fd, TCSANOW, &tm) < 0) { - return -1; - } - printf("\033[?25l");/* 隐藏光标 */ -#endif - return 0; -} - -/* 停用键盘输入 */ -static LCUI_BOOL LCUIKeyboard_Exit( void ) -{ -#ifdef LCUI_KEYBOARD_DRIVER_LINUX - tm.c_lflag |= ICANON; - tm.c_lflag |= ECHO; - tm.c_cc[VMIN] = 1; - tm.c_cc[VTIME] = 0; - if(tcsetattr(fd,TCSANOW,&tm)<0) { - return FALSE; - } - printf("\033[?25h"); /* 显示光标 */ -#endif - return TRUE; -} - -static void OnKeyboardEvent( LCUI_SysEvent e, void *arg ) -{ - if( e->type == LCUI_KEYDOWN ) { - LCUIKeyBoard_HitKey( e->key_code ); - } - else if( e->type == LCUI_KEYUP ) { - LCUIKeyBoard_ReleaseKey( e->key_code ); - } -} - -/** 检测键盘是否有按键按下(类似于kbhit函数) */ -LCUI_BOOL LCUIKeyboard_IsHit( void ) -{ -#ifdef LCUI_KEYBOARD_DRIVER_LINUX - struct termios oldt;//, newt; - int ch, oldf; - tcgetattr(STDIN_FILENO, &oldt); - //newt = oldt; - //newt.c_lflag &= ~(ICANON | ECHO); - //tcsetattr(STDIN_FILENO, TCSANOW, &newt); - oldf = fcntl(STDIN_FILENO, F_GETFL, 0); - fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK); - ch = getchar(); /* 获取一个字符 */ - tcsetattr(STDIN_FILENO, TCSANOW, &oldt); - fcntl(STDIN_FILENO, F_SETFL, oldf); - /* 如果字符有效,将字符放回输入缓冲区中 */ - if(ch != EOF) { - ungetc(ch, stdin); - return TRUE; - } - return FALSE; -#endif - return FALSE; -} - -/** 获取被按下的按键的键值(类似于getch函数) */ -int LCUIKeyboard_GetKey( void ) -{ -#ifdef LCUI_KEYBOARD_DRIVER_LINUX - int k,c; - static int input = 0, count = 0; - ++count; - /* 获取输入缓冲中的字符 */ - k = fgetc(stdin); - input += k; - /* 如果还有字符在缓冲中 */ - if(LCUIKeyboard_IsHit()) { - LCUIKeyboard_GetKey(); - } - c = input; - --count; - /* 递归结束后就置0 */ - if(count == 0) { - input = 0; - } - if(c == 3) { - exit(1); - } - return c; -#else - return -1; -#endif -} - -#ifdef LCUI_KEYBOARD_DRIVER_LINUX -static LCUI_BOOL LCUIKeyboard_Proc(void) -{ - LCUI_SysEventRec e; - /* 如果没有按键输入 */ - if ( !LCUIKeyboard_IsHit() ) { - return FALSE; - } - - e.type = LCUI_KEYDOWN; - e.key_code = LCUIKeyboard_GetKey(); - LCUI_TriggerEvent( &e, NULL ); - return TRUE; -} -#endif - -/** 初始化键盘输入模块 */ -int LCUI_InitKeyboard( void ) -{ - int ret; - LCUIMutex_Init( &record_mutex ); - LinkedList_Init( &key_state_record ); - nobuff_printf("[keyboard] set event ... "); - ret = LCUI_BindEvent( LCUI_KEYDOWN, OnKeyboardEvent, NULL, NULL ); - ret |= LCUI_BindEvent( LCUI_KEYUP, OnKeyboardEvent, NULL, NULL ); - nobuff_printf(ret < 0 ? "failed\n":"ok\n"); -#ifdef LCUI_KEYBOARD_DRIVER_LINUX - ret |= LCUIDevice_Add( LCUIKeyboard_Init, LCUIKeyboard_Proc, LCUIKeyboard_Exit ); -#endif - return ret; -} - -/** 停用键盘输入模块 */ -int LCUI_ExitKeyboard( void ) -{ - LinkedList_Clear( &key_state_record, free ); - LCUIMutex_Destroy( &record_mutex ); - return 0; -} diff --git a/src/input/mouse.c b/src/input/mouse.c deleted file mode 100644 index ef27ec76..00000000 --- a/src/input/mouse.c +++ /dev/null @@ -1,217 +0,0 @@ -/* *************************************************************************** - * mouse.c -- mouse input support. - * - * Copyright (C) 2012-2016 by Liu Chao - * - * 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 . - * ***************************************************************************/ - -/* **************************************************************************** - * mouse.c -- 鼠标输入支持。 - * - * 版权所有 (C) 2012-2016 归属于 刘超 - * - * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 - * - * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) - * - * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 - * - * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 - * 定用途的隐含担保,详情请参照GPLv2许可协议。 - * - * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 - * 没有,请查看:. - * ***************************************************************************/ - -#include -#include -#include -#include - -#ifdef LCUI_MOUSE_DRIVER_LINUX -#include -#include -#include - -#define MS_DEV "/dev/input/mice" /* 鼠标设备 */ -#endif - -enum LCUIMouseState { - STATE_REMOVE, - STATE_INSIDE -}; - -static struct LCUIMouseDeviceContext { -#ifdef LCUI_MOUSE_DRIVER_LINUX - int fd; /**< 鼠标设备标示符 */ - int state; /**< 鼠标设备的状态 */ -#elif defined(LCUI_BUILD_IN_WIN32) - int x, y; -#endif - int button_state[2]; /** 鼠标左右键的状态 */ -} mouse = { -#ifdef LCUI_MOUSE_DRIVER_LINUX - 0, 0, -#elif defined(LCUI_BUILD_IN_WIN32) - 0, 0, -#endif - {LCUIKEYSTATE_RELEASE, LCUIKEYSTATE_RELEASE} -}; - -static void OnMouseButtonEvent( LCUI_SysEvent e, void *arg ) -{ - if( e->key_code < 1 || e->key_code > 2 ) { - return; - } - DEBUG_MSG("key_code: %d\n", e->key_code); - switch( e->type ) { - case LCUI_MOUSEDOWN: - mouse.button_state[e->key_code] = LCUIKEYSTATE_PRESSED; - break; - case LCUI_MOUSEUP: - mouse.button_state[e->key_code] = LCUIKEYSTATE_RELEASE; - default:break; - } -} - -#ifdef LCUI_MOUSE_DRIVER_LINUX -static LCUI_BOOL MouseProc( void ) -{ - static int tmp; - static char buf[6]; - static fd_set readfds; - static struct timeval tv; - - if (mouse.state == STATE_REMOVE || mouse.fd < 0) { - return FALSE; - } - /* 设定select等待I/o的最长时间 */ - tv.tv_sec = 0; - tv.tv_usec = 0; - - FD_ZERO (&readfds); - FD_SET (mouse.fd, &readfds); - - tmp = select (mouse.fd+1, &readfds, NULL, NULL, &tv); - if (tmp == 0) { - //printf("Time out!\n"); - return FALSE; - } - if ( !FD_ISSET (mouse.fd, &readfds) ) { - return FALSE; - } - tmp = read (mouse.fd, buf, 6); - if (tmp <= 0){ - if (tmp < 0) { - mouse.state = STATE_REMOVE; - } - return FALSE; - } - - return TRUE; -} -#else - -static LCUI_BOOL MouseProc( void ) -{ - POINT new_pos; - LCUI_SysEventRec e; - static LCUI_Pos old_pos = {0, 0}; - - /* 如果是无缝模式则获取系统鼠标游标的坐标 */ - if( LCUIDisplay_GetMode() == LDM_SEAMLESS ) { - GetCursorPos( &new_pos ); - } else { - new_pos.x = mouse.x; - new_pos.y = mouse.y; - } - e.type = LCUI_MOUSEMOVE; - e.rel_x = new_pos.x - old_pos.x; - e.rel_y = new_pos.y - old_pos.y; - if( e.rel_x == 0 && e.rel_y == 0 ) { - return FALSE; - } - old_pos.x = new_pos.x; - old_pos.y = new_pos.y; - DEBUG_MSG("x: %d, y: %d, rel_x: %d, rel_y: %d\n", new_pos.x, new_pos.y, e.rel_x, e.rel_y); - LCUI_TriggerEvent( &e, NULL ); - return TRUE; -} - -void LCUIMouse_SetPos( int x, int y ) -{ - mouse.x = x; - mouse.y = y; -} -#endif - -/** 初始化鼠标输入处理 */ -static LCUI_BOOL MouseInit(void) -{ -#ifdef LCUI_MOUSE_DRIVER_LINUX - char *msdev, err_str[64]; - - if(mouse.state != STATE_REMOVE) { - return FALSE; - } - msdev = getenv("LCUI_MOUSE_DEVICE"); - if( msdev == NULL ) { - msdev = MS_DEV; - } - if ((mouse.fd = open (MS_DEV, O_RDONLY)) < 0) { - sprintf(err_str, "[mouse] failed to open %s", msdev); - perror(err_str); - mouse.state = STATE_REMOVE; - return FALSE; - } - mouse.state = STATE_INSIDE; - printf("[mouse] open %s successfuly.\n", msdev); -#else - /* 隐藏windows的鼠标游标 */ - ShowCursor( FALSE ); -#endif - return TRUE; -} - -/** 退出鼠标输入处理 */ -static LCUI_BOOL MouseExit(void) -{ -#ifdef LCUI_MOUSE_DRIVER_LINUX - if( mouse.state != STATE_INSIDE ) { - return FALSE; - } - close( mouse.fd ); - mouse.state = STATE_REMOVE; -#endif - return TRUE; -} - -/** 初始化鼠标输入模块 */ -int LCUI_InitMouse( void ) -{ - int ret; -#ifdef LCUI_MOUSE_DRIVER_LINUX - mouse.fd = -1; - mouse.state = STATE_REMOVE; /* 鼠标为移除状态 */ -#endif - nobuff_printf("[mouse] set event ... "); - ret = LCUI_BindEvent( LCUI_MOUSEDOWN, OnMouseButtonEvent, NULL, NULL ); - ret |= LCUI_BindEvent( LCUI_MOUSEUP, OnMouseButtonEvent, NULL, NULL ); - nobuff_printf(ret < 0 ? "failed\n":"ok\n"); - ret |= LCUIDevice_Add( MouseInit, MouseProc, MouseExit ); - return ret; -} diff --git a/src/input/touchscreen.c b/src/input/touchscreen.c deleted file mode 100755 index a4215de3..00000000 --- a/src/input/touchscreen.c +++ /dev/null @@ -1,171 +0,0 @@ -/* *************************************************************************** - * touchscreen.c -- touchscreen support - * - * Copyright (C) 2012-2013 by - * Liu Chao - * - * 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 . - * ****************************************************************************/ - -/* **************************************************************************** - * touchscreen.c -- 触屏支持 - * - * 版权所有 (C) 2013 归属于 - * 刘超 - * - * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 - * - * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) - * - * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 - * - * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 - * 定用途的隐含担保,详情请参照GPLv2许可协议。 - * - * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 - * 没有,请查看:. - * ****************************************************************************/ - -#include -#include -#include -#include -#include - -#define STATE_REMOVE 0 -#define STATE_INSIDE 1 - -#define TS_DEV "/dev/ts" - -#ifdef USE_TSLIB -#include -#endif - -typedef struct _LCUI_TS { - void *td; - int state; -} LCUI_TS; - -static LCUI_TS ts_data; - -static LCUI_BOOL proc_touchscreen(void) -{ -#ifdef USE_TSLIB - struct ts_sample samp; - int button, ret; - static LCUI_Pos pos; - - if (ts_data.state != STATE_INSIDE) { - return FALSE; - } - - /* 开始获取触屏点击处的坐标 */ - ret = ts_read (ts_data.td, &samp, 1); - if (ret < 0) { - perror ("ts_read"); - return FALSE; - } - - if (ret != 1) { - return FALSE; - } - pos.x = samp.x; - pos.y = samp.y; - - if (pos.x > LCUIScreen_GetWidth ()) { - pos.x = LCUIScreen_GetWidth (); - } - if (pos.y > LCUIScreen_GetHeight ()) { - pos.y = LCUIScreen_GetHeight (); - } - pos.x = pos.x<0 ? 0:pos.x; - pos.y = pos.y<0 ? 0:pos.y; - LCUICursor_SetPos( pos ); - LCUI_PushMouseMotionEvent( pos ); - if( samp.pressure > 0 ) { - LCUIMouse_ButtonDown( new_pos, LCUIKEY_LEFTBUTTON ); - LCUIMouse_ButtonUp( new_pos, LCUIKEY_RIGHTBUTTON ); - } - //printf("%ld.%06ld: %6d %6d %6d\n", samp.tv.tv_sec, samp.tv.tv_usec, samp.x, samp.y, samp.pressure); - return TRUE; -#else - return FALSE; -#endif -} - -/** 启用触屏输入处理 */ -LCUI_BOOL EnableTouchScreenInput(void) -{ -#ifdef USE_TSLIB - char *tsdevice; - char str[256]; - if (ts_data.state != STATE_INSIDE) { - tsdevice = getenv("TSLIB_TSDEVICE"); - if( tsdevice ) { - ts_data.td = ts_open(tsdevice, 0); - } else { - tsdevice = TS_DEV; - } - ts_data.td = ts_open (tsdevice, 0); - if (!ts_data.td) { - sprintf (str, "ts_open: %s", tsdevice); - perror (str); - ts_data.state = STATE_REMOVE; - return FALSE; - } - - if (ts_config (ts_data.td)) { - perror ("ts_config"); - ts_data.state = STATE_REMOVE; - return FALSE; - } - ts_data.state = STATE_INSIDE; - } - return TRUE; -#else - return FALSE; -#endif -} - -/** 禁用触屏输入处理 */ -LCUI_BOOL DisableTouchScreenInput(void) -{ -#ifdef USE_TSLIB - if(ts_data.state == STATE_INSIDE) { - ts_close(ts_data.td); - ts_data.state = STATE_REMOVE; - return TRUE; - } - return FALSE; -#else - return FALSE; -#endif -} - -/* 获取触屏的私有数据 */ -void* Get_TouchScreen(void) -{ - return ts_data.td; -} - -/* 初始化触屏输入模块 */ -void LCUI_InitTouchScreen( void ) -{ - ts_data.td = NULL; - ts_data.state = STATE_REMOVE; - LCUIDevice_Add( EnableTouchScreenInput, proc_touchscreen, - DisableTouchScreenInput ); -} From d8aff6f8af0481d0b7ae6b3d3c02fb75a06d7c10 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Sun, 5 Jun 2016 23:59:16 +0800 Subject: [PATCH 035/124] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=A7=A6=E6=8E=A7?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E7=9A=84=E5=88=86=E5=8F=91=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gui/widget_event.c | 132 +++++++++++++++++++---------------------- 1 file changed, 62 insertions(+), 70 deletions(-) diff --git a/src/gui/widget_event.c b/src/gui/widget_event.c index 9b5b9dc3..a035b8a4 100644 --- a/src/gui/widget_event.c +++ b/src/gui/widget_event.c @@ -258,21 +258,24 @@ static void TouchCapturers_Add( LinkedList *list, LCUI_Widget w, int point_id ) /* 获取该部件的触点捕捉记录 */ LinkedList_ForEach( node, list ) { tc = node->data; + /* 清除与该触点绑定的其它捕捉记录 */ + LinkedList_ForEach( ptnode, &tc->points ) { + if( point_id != *(int*)ptnode->data ) { + continue; + } + if( tc->widget == w ) { + return; + } + free( ptnode->data ); + LinkedList_DeleteNode( &tc->points, ptnode ); + break; + } if( tc->widget == w ) { break; } } /* 如果没有该部件的触点捕捉记录 */ if( !tc || tc->widget != w ) { - /* 清除与该触点绑定的其它捕捉记录 */ - LinkedList_ForEach( ptnode, list ) { - if( point_id != *(int*)ptnode->data ) { - continue; - } - free( ptnode->data ); - LinkedList_DeleteNode( list, ptnode ); - break; - } tc = NEW( TouchCapturerRec, 1 ); tc->widget = w; tc->node.data = tc; @@ -289,8 +292,7 @@ static int TouchCapturers_Delete( LinkedList *list, LCUI_Widget w, int point_id { TouchCapturer tc = NULL; LinkedListNode *node, *ptnode; - LinkedList_ForEach( node, list ) - { + LinkedList_ForEach( node, list ) { tc = node->data; if( tc->widget == w ) { break; @@ -302,8 +304,7 @@ static int TouchCapturers_Delete( LinkedList *list, LCUI_Widget w, int point_id if( point_id < 0 ) { LinkedList_Clear( &tc->points, free ); } else { - LinkedList_ForEach( ptnode, &tc->points ) - { + LinkedList_ForEach( ptnode, &tc->points ) { if( *(int*)ptnode->data == point_id ) { free( node->data ); LinkedList_DeleteNode( &tc->points, ptnode ); @@ -666,55 +667,21 @@ static void ConvertTouchPoint( LCUI_TouchPoint point ) } } -static void OnTouchWithCapturers( LCUI_SysEvent sys_ev, void *arg ) +/** 分发触控事件给对应的部件 */ +static int DispatchTouchEvent( LinkedList *capturers, LCUI_TouchPoint points, + int n_points ) { - int i, n; - TouchCapturer tc; - LCUI_TouchPoint points; - LCUI_WidgetEventRec ev; - LinkedListNode *node, *ptnode; - - ev.type = WET_TOUCH; - ev.cancel_bubble = FALSE; - n = sys_ev->touch.n_points; - points = sys_ev->touch.points; - ev.points = NEW( LCUI_TouchPointRec, n ); - LinkedList_ForEach( node, &self.touch_capturers ) { - tc = node->data; - ev.n_points = 0; - LinkedList_ForEach( ptnode, &tc->points ) { - for( i = 0; i < n; ++i ) { - if( points[i].id != *(int*)ptnode->data ) { - continue; - } - ev.points[ev.n_points] = points[i]; - ConvertTouchPoint( &ev.points[ev.n_points] ); - ++ev.n_points; - } - } - Widget_PostEvent( tc->widget, &ev, NULL, NULL ); - } -} - -static void OnTouchWithoutCapturers( LCUI_SysEvent sys_ev, void *arg ) -{ - int i, n; - TouchCapturer tc; - LinkedList capturers; - LCUI_TouchPoint points; + int i, count; LCUI_WidgetEventRec ev; LCUI_Widget target, root, w; LinkedListNode *node, *ptnode; ev.type = WET_TOUCH; ev.cancel_bubble = FALSE; - n = sys_ev->touch.n_points; root = LCUIWidget_GetRoot(); - points = sys_ev->touch.points; - ev.points = NEW( LCUI_TouchPointRec, n ); - LinkedList_Init( &capturers ); + ev.points = NEW( LCUI_TouchPointRec, n_points ); /* 先将各个触点按命中的部件进行分组 */ - for( i = 0; i < n; ++i ) { + for( i = 0; i < n_points; ++i ) { target = Widget_At( root, points[i].x, points[i].y ); if( !target ) { continue; @@ -727,20 +694,14 @@ static void OnTouchWithoutCapturers( LCUI_SysEvent sys_ev, void *arg ) if( w && w->event_blocked ) { continue; } - TouchCapturers_Add( &capturers, target, points[i].id ); + TouchCapturers_Add( capturers, target, points[i].id ); } + count = 0; + ev.n_points = 0; /* 然后向命中的部件发送触控事件 */ - LinkedList_ForEach( node, &capturers ) { - tc = node->data; - ev.n_points = 0; - for( i = 0; i < n; ++i ) { - /* 如果没有触点记录,则说明是捕获全部触点 */ - if( tc->points.length == 0 ) { - ev.points[ev.n_points] = points[i]; - ConvertTouchPoint( &ev.points[ev.n_points] ); - ++ev.n_points; - continue; - } + LinkedList_ForEach( node, capturers ) { + TouchCapturer tc = node->data; + for( i = 0; i < n_points; ++i ) { LinkedList_ForEach( ptnode, &tc->points ) { if( points[i].id != *(int*)ptnode->data ) { continue; @@ -750,19 +711,50 @@ static void OnTouchWithoutCapturers( LCUI_SysEvent sys_ev, void *arg ) ++ev.n_points; } } + if( ev.n_points == 0 ) { + continue; + } Widget_PostEvent( tc->widget, &ev, NULL, NULL ); + ev.n_points = 0; + ++count; } - TouchCapturers_Clear( &capturers ); + free( ev.points ); + return count; } +/** 响应系统触控事件 */ static void OnTouch( LCUI_SysEvent sys_ev, void *arg ) { + int i, n; + LinkedList capturers; + LCUI_TouchPoint points; + LinkedListNode *node, *ptnode; + + n = sys_ev->touch.n_points; + points = sys_ev->touch.points; + LinkedList_Init( &capturers ); LCUIMutex_Lock( &self.mutex ); - if( self.touch_capturers.length > 0 ) { - OnTouchWithCapturers( sys_ev, arg ); - } else { - OnTouchWithoutCapturers( sys_ev, arg ); + /* 合并现有的触点捕捉记录 */ + LinkedList_ForEach( node, &self.touch_capturers ) { + TouchCapturer tc = node->data; + for( i = 0; i < n; ++i ) { + /* 如果没有触点记录,则说明是捕获全部触点 */ + if( tc->points.length == 0 ) { + TouchCapturers_Add( &capturers, tc->widget, + points[i].id ); + continue; + } + LinkedList_ForEach( ptnode, &tc->points ) { + if( points[i].id != *(int*)ptnode->data ) { + continue; + } + TouchCapturers_Add( &capturers, tc->widget, + points[i].id ); + } + } } + DispatchTouchEvent( &capturers, points, n ); + TouchCapturers_Clear( &capturers ); LCUIMutex_Unlock( &self.mutex ); } From a366e608cee66b9826dcaa0cf4a997b591830cce Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Mon, 6 Jun 2016 23:36:58 +0800 Subject: [PATCH 036/124] =?UTF-8?q?=E5=8A=A0=E4=B8=8A=E6=9C=89=E6=95=88?= =?UTF-8?q?=E6=80=A7=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gui/widget/scrollbar.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/gui/widget/scrollbar.c b/src/gui/widget/scrollbar.c index 76ed036b..f4e64271 100644 --- a/src/gui/widget/scrollbar.c +++ b/src/gui/widget/scrollbar.c @@ -320,6 +320,9 @@ static void ScrollBar_UpdateSize( LCUI_Widget w ) int size, box_size; LCUI_ScrollBar scrollbar = w->private_data; LCUI_Widget slider = scrollbar->slider; + if( !scrollbar->box ) { + return; + } if( scrollbar->direction == SBD_HORIZONTAL ) { if( scrollbar->layer ) { size = scrollbar->layer->box.outer.width; From 10338a66beb8ef7dff1cc48ecc3ef26042137a59 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Tue, 7 Jun 2016 23:21:28 +0800 Subject: [PATCH 037/124] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20helloworld?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/helloworld.c | 61 +++++++++++++++++++++++---------------------- test/helloworld.css | 9 +++++++ test/helloworld.xml | 8 ++++++ 3 files changed, 48 insertions(+), 30 deletions(-) create mode 100644 test/helloworld.css create mode 100644 test/helloworld.xml diff --git a/test/helloworld.c b/test/helloworld.c index 7c4b0ca4..98da6846 100755 --- a/test/helloworld.c +++ b/test/helloworld.c @@ -1,43 +1,44 @@ -#include -#include +#include #include -#include #include #include -#ifdef LCUI_BUILD_IN_WIN32 -#include -#include - -/* 在运行程序时会打开控制台,以查看打印的调试信息 */ -static void InitConsoleWindow(void) +int main( int argc, char **argv ) { - int hCrt; - FILE *hf; - AllocConsole(); - hCrt=_open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE),_O_TEXT ); - hf=_fdopen( hCrt, "w" ); - *stdout=*hf; - setvbuf (stdout, NULL, _IONBF, 0); - // test code - printf ("InitConsoleWindow OK!\n"); + LCUI_Widget root, pack; + LCUI_Init(); + root = LCUIWidget_GetRoot(); + pack = LCUIBuilder_LoadFile( "helloworld.xml" ); + if( !pack ) { + return -1; + } + Widget_Append( root, pack ); + Widget_Unwrap( pack ); + return LCUI_Main(); } -#endif +/* version 2 +#include +#include +#include +#include int main( int argc, char **argv ) { - LCUI_Widget root, box; - -#ifdef LCUI_BUILD_IN_WIN32 - InitConsoleWindow(); -#endif + LCUI_Widget root, txt; + LCUI_Init(); - box = LCUIBuilder_LoadFile("hello.xml"); - if( box ) { - root = LCUIWidget_GetRoot(); - Widget_Append( root, box ); - Widget_Unwrap( box ); - } + root = LCUIWidget_GetRoot(); + txt = LCUIWidget_New( "textview" ); + TextView_SetTextAlign( txt, SV_CENTER ); + TextView_SetText( txt, "[size=18px]Hello, World![/size]" ); + SetStyle( txt->custom_style, key_margin_top, 25, px ); + SetStyle( txt->custom_style, key_margin_left, 25, px ); + SetStyle( txt->custom_style, key_padding_top, 25, px ); + SetStyle( txt->custom_style, key_border_width, 1, px ); + SetStyle( txt->custom_style, key_border_color, RGB(0,0,0), color ); + Widget_Resize( txt, 200, 100 ); + Widget_Append( root, txt ); return LCUI_Main(); } +*/ diff --git a/test/helloworld.css b/test/helloworld.css new file mode 100644 index 00000000..0aed259c --- /dev/null +++ b/test/helloworld.css @@ -0,0 +1,9 @@ +textview.text-hello { + color: #8cc63f; + font-size: 18px; + font-family: "Comic Sans MS"; + text-align: center; + padding: 25px; + margin: 25px 0 0 25px; + border: 1px solid #000; +} diff --git a/test/helloworld.xml b/test/helloworld.xml new file mode 100644 index 00000000..4fb04417 --- /dev/null +++ b/test/helloworld.xml @@ -0,0 +1,8 @@ + + + + + + Hello, World! + + From a8a14b9bb1d1c0fa10c054c235017837b828bf09 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Tue, 7 Jun 2016 23:23:46 +0800 Subject: [PATCH 038/124] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20textview=20?= =?UTF-8?q?=E9=83=A8=E4=BB=B6=EF=BC=8C=E8=A1=A5=E5=85=85=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E5=AF=B9=E9=BD=90=E8=AE=BE=E7=BD=AE=EF=BC=8C=E7=BA=A0=E6=AD=A3?= =?UTF-8?q?=E6=96=87=E6=9C=AC=E5=8C=BA=E5=9F=9F=E7=9A=84=E5=B0=BA=E5=AF=B8?= =?UTF-8?q?=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gui/widget/textview.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/gui/widget/textview.c b/src/gui/widget/textview.c index 41a21658..f02dcc20 100644 --- a/src/gui/widget/textview.c +++ b/src/gui/widget/textview.c @@ -287,11 +287,11 @@ static void TextView_OnResize( LCUI_Widget w, LCUI_WidgetEvent e, void *arg ) LinkedListNode *node; LCUI_Size new_size = {16, 16}; LCUI_TextView *txt = w->private_data; - if( w->width > new_size.w ) { - new_size.w = w->width; + if( w->box.content.width > new_size.w ) { + new_size.w = w->box.content.width; } - if( w->height > new_size.h ) { - new_size.h = w->height; + if( w->box.content.height > new_size.h ) { + new_size.h = w->box.content.height; } LinkedList_Init( &rects ); if( w->style->sheet[key_width].is_valid && @@ -365,6 +365,12 @@ static void TextView_OnTask( LCUI_Widget w ) TextLayer_SetAutoWrap( txt->layer, txt->tasks[i].autowrap ); txt->tasks[TASK_UPDATE].is_valid = TRUE; } + i = TASK_SET_TEXT_ALIGN; + if( txt->tasks[i].is_valid ) { + txt->tasks[i].is_valid = FALSE; + TextLayer_SetTextAlign( txt->layer, txt->tasks[i].align ); + txt->tasks[TASK_UPDATE].is_valid = TRUE; + } i = TASK_UPDATE; if( !txt->tasks[i].is_valid ) { return; From fb600ce4d2b3719d8955ab1f2f6d802b2640d8b5 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Tue, 7 Jun 2016 23:24:31 +0800 Subject: [PATCH 039/124] =?UTF-8?q?=E5=B0=8F=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/LCUI.h | 9 ++++++++- include/LCUI/gui/widget.h | 1 + src/cursor.c | 1 - src/display.c | 1 - src/gui/builder.c | 7 ++++--- src/gui/css_parser.c | 1 - src/gui/widget_background.c | 1 - src/gui/widget_base.c | 1 - src/gui/widget_paint.c | 1 - src/platform/windows/windows_display.c | 1 - test/.directory | 4 ---- 11 files changed, 13 insertions(+), 15 deletions(-) delete mode 100644 test/.directory diff --git a/include/LCUI/LCUI.h b/include/LCUI/LCUI.h index 47f31dc9..e46d71f0 100755 --- a/include/LCUI/LCUI.h +++ b/include/LCUI/LCUI.h @@ -101,7 +101,14 @@ typedef struct LCUI_Pos_ { } LCUI_Pos; typedef struct LCUI_Size_ { - int w, h; + union { + int w; + int width; + }; + union { + int h; + int height; + }; } LCUI_Size; typedef struct LCUI_String_ { diff --git a/include/LCUI/gui/widget.h b/include/LCUI/gui/widget.h index d265e22b..924aeb1a 100644 --- a/include/LCUI/gui/widget.h +++ b/include/LCUI/gui/widget.h @@ -40,6 +40,7 @@ #ifndef LCUI_WIDGET_BUILD_H #define LCUI_WIDGET_BUILD_H +#include #include #include #include diff --git a/src/cursor.c b/src/cursor.c index fbeef445..54e30d00 100644 --- a/src/cursor.c +++ b/src/cursor.c @@ -40,7 +40,6 @@ //#define DEBUG #include #include -#include #include #include diff --git a/src/display.c b/src/display.c index 81f096dc..49523aa8 100644 --- a/src/display.c +++ b/src/display.c @@ -43,7 +43,6 @@ #include #include #include -#include #include #include #include diff --git a/src/gui/builder.c b/src/gui/builder.c index f0cf1c0a..2852459c 100644 --- a/src/gui/builder.c +++ b/src/gui/builder.c @@ -108,20 +108,21 @@ static int ParseResource( XMLParserContext ctx, xmlNodePtr node ) } prop = prop->next; } - if( !type || !src ) { + if( !type && !src ) { return PB_WARNING; } if( strstr(type, "application/font-") ) { LCUIFont_LoadFile( src ); } else if( strstr(type, "text/css") ) { - LCUICSS_LoadFile( src ); + if( src ) { + LCUICSS_LoadFile( src ); + } for( node = node->children; node; node = node->next ) { if( node->type != XML_TEXT_NODE ) { continue; } LCUICSS_LoadString( (char*)node->content ); - node = node->next; } } return PB_NEXT; diff --git a/src/gui/css_parser.c b/src/gui/css_parser.c index 7ba18bda..5a315729 100644 --- a/src/gui/css_parser.c +++ b/src/gui/css_parser.c @@ -42,7 +42,6 @@ #include #include #include -#include #include /** 解析器的环境参数(上下文数据) */ diff --git a/src/gui/widget_background.c b/src/gui/widget_background.c index 62e1b22a..9e7dae27 100644 --- a/src/gui/widget_background.c +++ b/src/gui/widget_background.c @@ -42,7 +42,6 @@ #include #include #include -#include #include typedef struct ImageCacheRec_ { diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index bb5d14ca..cf9adbbc 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -42,7 +42,6 @@ #include #include #include -#include #include #undef max diff --git a/src/gui/widget_paint.c b/src/gui/widget_paint.c index 44c5fa9c..5f1af90d 100644 --- a/src/gui/widget_paint.c +++ b/src/gui/widget_paint.c @@ -42,7 +42,6 @@ #include #include #include -#include #include /** 判断部件是否有可绘制内容 */ diff --git a/src/platform/windows/windows_display.c b/src/platform/windows/windows_display.c index 47e44f98..0621407b 100644 --- a/src/platform/windows/windows_display.c +++ b/src/platform/windows/windows_display.c @@ -43,7 +43,6 @@ #define LCUI_SURFACE_C #ifdef LCUI_BUILD_IN_WIN32 #include -#include #include #include #include LCUI_DISPLAY_H diff --git a/test/.directory b/test/.directory deleted file mode 100644 index a7ebe757..00000000 --- a/test/.directory +++ /dev/null @@ -1,4 +0,0 @@ -[Dolphin] -Timestamp=2013,5,10,18,55,59 -Version=3 -ViewMode=1 From 180ea64161b72ee372ce787b091667dd8e02ff66 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Thu, 9 Jun 2016 00:04:04 +0800 Subject: [PATCH 040/124] add example screenshot. --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3d21511b..9cbf23bd 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,11 @@ LCUI is a freely available software library to create GUI application. It is written in C, support the use XML and CSS describe the graphical -interface. author is from China, but his English is not very good, so, some +interface, you can use it to make some simple effects, like in this example: + +![example screenshot](https://lcui.lc-soft.io/static/images/feature-screenshot-02.png) + +Author is from China, but his English is not very good, so, some files will appear chinese character, please understand. thanks. Please read the file `docs/CHANGES.md`, it contains IMPORTANT INFORMATION. From e4b39ae7f607e8ab5f4411432c4108225c64aef7 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Sat, 11 Jun 2016 17:11:16 +0800 Subject: [PATCH 041/124] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=BD=93=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E5=A4=9A=E8=A7=A6=E7=82=B9=E6=8B=96=E6=8B=BD=E6=BB=9A?= =?UTF-8?q?=E5=8A=A8=E5=B1=82=E5=90=8E=E6=97=A0=E6=B3=95=E5=86=8D=E6=AC=A1?= =?UTF-8?q?=E6=8B=96=E6=8B=BD=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gui/widget/scrollbar.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/gui/widget/scrollbar.c b/src/gui/widget/scrollbar.c index f4e64271..e9a98450 100644 --- a/src/gui/widget/scrollbar.c +++ b/src/gui/widget/scrollbar.c @@ -70,6 +70,7 @@ typedef struct LCUI_ScrollBarRec_ { LCUI_BOOL is_dragging; /**< 是否处于拖拽状态 */ int slider_x, slider_y; /**< 拖拽开始时的滑块位置 */ int mouse_x, mouse_y; /**< 拖拽开始时的鼠标坐标 */ + int touch_point_id; /**< 触点的ID */ int direction; /**< 滚动条的方向(垂直或水平) */ int scroll_step; /**< 每次滚动的距离,主要针对使用鼠标滚轮触发的滚动 */ int pos; /**< 当前的位置 */ @@ -300,6 +301,7 @@ static void ScrollBar_OnInit( LCUI_Widget w ) self->box = NULL; self->old_pos = 0; self->pos = 0; + self->touch_point_id = -1; self->effect.timer = -1; self->effect.end_pos = 0; self->effect.start_pos = 0; @@ -379,14 +381,24 @@ static void ScrollLayer_OnTouch( LCUI_Widget layer, LCUI_WidgetEvent e, void *ar return; } scrollbar = w->private_data; - for( point = NULL, i = 0; i < e->n_points; ++i ) { - point = &e->points[i]; - if( point->is_primary ) { - break; + if( scrollbar->touch_point_id == -1 ) { + point = &e->points[0]; + /* 如果这个触点的状态不是 TOUCHDOWN,则说明是上次触控拖拽操 + * 作时的多余触点,直接忽略这次触控事件 */ + if( point->state != WET_TOUCHDOWN ) { + return; + } + scrollbar->touch_point_id = point->id; + } else { + for( point = NULL, i = 0; i < e->n_points; ++i ) { + point = &e->points[i]; + if( point->id == scrollbar->touch_point_id ) { + break; + } + } + if( !point ) { + return; } - } - if( !point ) { - return; } switch( point->state ) { case WET_TOUCHDOWN: @@ -406,6 +418,7 @@ static void ScrollLayer_OnTouch( LCUI_Widget layer, LCUI_WidgetEvent e, void *ar if( scrollbar->is_dragging ) { ScrollBar_StartInertialScrolling( w ); } + scrollbar->touch_point_id = -1; scrollbar->is_dragging = FALSE; Widget_BlockEvent( layer, FALSE ); break; From c853f5b6e491636d3d0e0e41b0f929040a544da4 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Sun, 12 Jun 2016 23:07:15 +0800 Subject: [PATCH 042/124] =?UTF-8?q?=E4=B8=BA=E6=8C=89=E9=92=AE=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=20set=5Ftext=20=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gui/widget/button.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gui/widget/button.c b/src/gui/widget/button.c index e3425b74..552b416a 100755 --- a/src/gui/widget/button.c +++ b/src/gui/widget/button.c @@ -113,6 +113,7 @@ void LCUIWidget_AddButton( void ) LCUI_WidgetClass *wc = LCUIWidget_AddClass( "button" ); wc->methods.init = Button_OnInit; wc->methods.paint = Button_OnPaint; + wc->methods.set_text = Button_SetText; wc->methods.destroy = Button_OnDestroy; wc->task_handler = Button_OnTask; LCUICSS_LoadString( button_css ); From ab88251e7d4a4217aa8a4558e2349e8c8e55a7f4 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Sun, 12 Jun 2016 23:11:07 +0800 Subject: [PATCH 043/124] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AD=97=E4=BD=93?= =?UTF-8?q?=E7=9A=84=E8=8E=B7=E5=8F=96=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 之前在载入一个字符的字体字形时,即使字体文件中不存在该字符,FreeType_Render() 也会返回 0,导致无法切换至候选字体中载入字形,现已纠正。 --- src/font/fontlibrary.c | 28 +++++++++++++++------------- src/font/freetype.c | 16 ++++++++++------ src/font/textlayer.c | 14 ++++++-------- src/font/textstyle.c | 8 ++++---- src/gui/widget/textview.c | 1 - 5 files changed, 35 insertions(+), 32 deletions(-) diff --git a/src/font/fontlibrary.c b/src/font/fontlibrary.c index 3c267bbf..23d6f9f6 100644 --- a/src/font/fontlibrary.c +++ b/src/font/fontlibrary.c @@ -349,21 +349,21 @@ int LCUIFont_GetBitmap( wchar_t ch, int font_id, int size, LCUI_RBTree *ctx; LCUI_FontBitmap bmp_cache; + if( !fontlib.is_inited ) { + *bmp = NULL; + return -2; + } + if( font_id <= 0 ) { + if( !fontlib.default_font ) { + return -3; + } + font_id = fontlib.default_font->id; + } /* 这里的 while 只是为了减少缩进 */ while( TRUE ) { - if( !fontlib.is_inited ) { - *bmp = NULL; - return -2; - } if( !(ctx = SelectChar(ch)) ) { break; } - if( font_id <= 0 ) { - if( !fontlib.default_font ) { - return -3; - } - font_id = fontlib.default_font->id; - } ctx = SelectFont( ctx, font_id ); if( !ctx ) { break; @@ -376,9 +376,11 @@ int LCUIFont_GetBitmap( wchar_t ch, int font_id, int size, } FontBitmap_Init( &bmp_cache ); ret = FontBitmap_Load( &bmp_cache, ch, font_id, size ); - *bmp = LCUIFont_AddBitmap( ch, font_id, size, &bmp_cache ); - if( *bmp && ret == 0 ) { - return 0; + if( ret == 0 ) { + *bmp = LCUIFont_AddBitmap( ch, font_id, size, &bmp_cache ); + if( *bmp ) { + return 0; + } } return -1; } diff --git a/src/font/freetype.c b/src/font/freetype.c index 6548def2..3b25b0c7 100644 --- a/src/font/freetype.c +++ b/src/font/freetype.c @@ -165,11 +165,12 @@ static size_t Convert_FTGlyph( LCUI_FontBitmap *bmp, FT_GlyphSlot slot, int mode return size; } -static int FreeType_Render( LCUI_FontBitmap *bmp, wchar_t ch, +static int FreeType_Render( LCUI_FontBitmap *bmp, wchar_t ch, int pixel_size, LCUI_Font *font ) { - int error; + int ret = 0; size_t size; + FT_UInt index; LCUI_BOOL has_space = FALSE; FT_Face ft_face = (FT_Face)font->data; @@ -180,17 +181,20 @@ static int FreeType_Render( LCUI_FontBitmap *bmp, wchar_t ch, ch = 'a'; has_space = TRUE; } + index = FT_Get_Char_Index( ft_face, ch ); + if( index == 0 ) { + ret = -1; + } /* 载入该字的字形数据 */ - error = FT_Load_Char( ft_face, ch, LCUI_FONT_LOAD_FALGS ); - if(error) { - return error; + if( FT_Load_Glyph( ft_face, index, LCUI_FONT_LOAD_FALGS ) != 0 ) { + return -2; } size = Convert_FTGlyph( bmp, ft_face->glyph, LCUI_FONT_RENDER_MODE ); /* 如果是空格则将位图内容清空 */ if( has_space ) { memset( bmp->buffer, 0, size ); } - return 0; + return ret; } int LCUIFont_InitFreeType( LCUI_FontEngine *engine ) diff --git a/src/font/textlayer.c b/src/font/textlayer.c index 875628bb..d09189e3 100644 --- a/src/font/textlayer.c +++ b/src/font/textlayer.c @@ -272,17 +272,15 @@ static void TextChar_UpdateBitmap( TextChar ch, LCUI_TextStyle *style ) size = ch->style->pixel_size; } } - if( !font_ids ) { - LCUIFont_GetBitmap( ch->char_code, -1, size, &ch->bitmap ); - return; - } - while( font_ids[i] >= 0 ) { - if( 0 == LCUIFont_GetBitmap(ch->char_code, - style->font_ids[i], size, &ch->bitmap) ) { - break; + while( font_ids && font_ids[i] >= 0 ) { + int ret = LCUIFont_GetBitmap( ch->char_code, font_ids[i], + size, &ch->bitmap ); + if( ret == 0 ) { + return; } ++i; } + LCUIFont_GetBitmap( ch->char_code, -1, size, &ch->bitmap ); } /** 新建文本图层 */ diff --git a/src/font/textstyle.c b/src/font/textstyle.c index 08cd7ef2..f7b97c6d 100755 --- a/src/font/textstyle.c +++ b/src/font/textstyle.c @@ -91,8 +91,8 @@ void TextStyle_Destroy( LCUI_TextStyle *data ) int TextStyle_SetFont( LCUI_TextStyle *ts, const char *str ) { char name[256]; - const char *p, *style_name; int count, i, *ids; + const char *p, *style_name; if( ts->has_family && ts->font_ids ) { free( ts->font_ids ); @@ -110,7 +110,7 @@ int TextStyle_SetFont( LCUI_TextStyle *ts, const char *str ) if( p - str == 0 ) { return -1; } - ids = (int*)malloc(sizeof(int)*(count+1)); + ids = NEW( int, count + 1 ); if( !ids ) { return -2; } @@ -127,7 +127,7 @@ int TextStyle_SetFont( LCUI_TextStyle *ts, const char *str ) continue; } name[i] = 0; - strtrim( name, name, NULL ); + strtrim( name, name, "'\"\n\r\t " ); ids[count] = LCUIFont_GetId( name, style_name ); if( ids[count] > 0 ) { ++count; @@ -143,7 +143,7 @@ int TextStyle_SetFont( LCUI_TextStyle *ts, const char *str ) } else { ts->has_family = FALSE; ts->font_ids = NULL; - free(ids); + free( ids ); } return 0; } diff --git a/src/gui/widget/textview.c b/src/gui/widget/textview.c index f02dcc20..ad5787ce 100644 --- a/src/gui/widget/textview.c +++ b/src/gui/widget/textview.c @@ -176,7 +176,6 @@ static int OnParseFontFamily( LCUI_StyleSheet ss, int key, const char *str ) && ss->sheet[style_key_map[key]].string) { free( ss->sheet[style_key_map[key]].string ); } - strtrim( name, str, "'\"\n\r\t " ); SetStyle( ss, style_key_map[key], name, string ); return 0; } From ecb8faab7575550441f4b3b07dfc3724ca2bf3b4 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Sun, 12 Jun 2016 23:13:59 +0800 Subject: [PATCH 044/124] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20Widget=5FUnwrap()?= =?UTF-8?q?=20=E5=87=BD=E6=95=B0=E5=9C=A8=E5=B1=95=E5=BC=80=E9=83=A8?= =?UTF-8?q?=E4=BB=B6=E5=90=8E=EF=BC=8C=E5=AD=90=E9=83=A8=E4=BB=B6=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E9=A1=BA=E5=BA=8F=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改排版时的部件定位判定。 --- src/gui/widget_base.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index cf9adbbc..16534e1e 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -157,6 +157,7 @@ int Widget_Unwrap( LCUI_Widget widget ) Widget_UpdateZIndex( child ); Widget_AddTaskForChildren( child, WTT_REFRESH_STYLE ); Widget_UpdateTaskStatus( child ); + target = target->next; node = prev; } Widget_Destroy( widget ); @@ -1393,7 +1394,8 @@ void Widget_ExecUpdateLayout( LCUI_Widget w ) ctx.max_width = Widget_ComputeMaxWidth( w ); LinkedList_ForEach( node, &w->children ) { child = node->data; - if( child->computed_style.position != SV_STATIC ) { + if( child->computed_style.position != SV_STATIC && + child->computed_style.position != SV_RELATIVE ) { continue; } switch( child->computed_style.display ) { From d5e5339b79141c49167eb3236fc8b822a0e44b50 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Wed, 15 Jun 2016 23:07:55 +0800 Subject: [PATCH 045/124] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20ime.c=EF=BC=8C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20keyboard.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/ime.h | 90 ++++++---- include/LCUI/input.h | 34 ++-- src/ime.c | 380 +++++++++++++++++++++---------------------- src/keyboard.c | 161 ++++++++++++++++++ 4 files changed, 424 insertions(+), 241 deletions(-) create mode 100644 src/keyboard.c diff --git a/include/LCUI/ime.h b/include/LCUI/ime.h index d943e749..d9d232d6 100644 --- a/include/LCUI/ime.h +++ b/include/LCUI/ime.h @@ -1,51 +1,85 @@ -#ifndef LCUI_IME_H +/* *************************************************************************** + * ime.h -- Input Method Editor/Engine + * + * Copyright (C) 2016 by Liu Chao + * + * 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * ime.h -- 输入法管理器 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ + +#ifndef LCUI_IME_H #define LCUI_IME_H LCUI_BEGIN_HEADER -typedef struct LCUIIME_Func_ { +typedef struct LCUI_IMEHandlerRec_ { LCUI_BOOL (*prockey)(int,int); - void (*settarget)(LCUI_Widget*); + void (*settarget)(LCUI_Widget); + void (*cleartarget)(void); LCUI_Widget (*gettarget)(void); void (*totext)(char); LCUI_BOOL (*open)(void); LCUI_BOOL (*close)(void); -} LCUIIME_Func; +} LCUI_IMEHandlerRec, *LCUI_IMEHandler; -/* 注册一个输入法 */ -LCUI_API int -LCUIIME_Register( const char *ime_name, LCUIIME_Func *ime_func ); +/** 注册一个输入法 */ +LCUI_API int LCUIIME_Register( const char *ime_name, LCUI_IMEHandler handler ); -/* 选定输入法 */ -LCUI_API LCUI_BOOL -LCUIIME_Select( int ime_id ); +/** 选定输入法 */ +LCUI_API LCUI_BOOL LCUIIME_Select( int ime_id ); -LCUI_API LCUI_BOOL -LCUIIME_SelectByName( const char *name ); +LCUI_API LCUI_BOOL LCUIIME_SelectByName( const char *name ); -/* 切换至下一个输入法 */ -LCUI_API void -LCUIIME_Switch(void); +/** 切换至下一个输入法 */ +LCUI_API void LCUIIME_Switch( void ); -/* 检测输入法是否要处理按键事件 */ -LCUI_API LCUI_BOOL -LCUIIME_ProcessKey( const LCUI_KeyboardEvent *event ); +/** 检测输入法是否要处理按键事件 */ +LCUI_API LCUI_BOOL LCUIIME_ProcessKey( LCUI_SysEvent e ); -/* 提交输入法输入的内容至目标 */ -LCUI_API int -LCUIIME_Commit( const wchar_t *str ); +/** 提交输入法输入的内容至目标 */ +LCUI_API int LCUIIME_Commit( const wchar_t *str ); -/* 设置输入法的目标 */ -LCUI_API int -LCUIIME_SetTarget( LCUI_Widget widget ); +/** 设置输入法的目标 */ +LCUI_API int LCUIIME_SetTarget( LCUI_Widget widget ); + +/** 清除输入法的目标 */ +LCUI_API int LCUIIME_ClearTarget( void ); /* 初始化LCUI输入法模块 */ -LCUI_API void -LCUI_InitIME(void); +void LCUI_InitIME( void ); /* 停用LCUI输入法模块 */ -LCUI_API void -LCUIModule_IME_End(void); +void LCUI_ExitIME( void ); LCUI_END_HEADER diff --git a/include/LCUI/input.h b/include/LCUI/input.h index 3e733a6f..6b9728fb 100644 --- a/include/LCUI/input.h +++ b/include/LCUI/input.h @@ -136,37 +136,25 @@ LCUI_BEGIN_HEADER -/** 初始化鼠标输入模块 */ -LCUI_API int LCUI_InitMouse( void ); - -void LCUIMouse_SetPos( int x, int y ); +/** 检测指定键值的按键是否处于按下状态 */ +LCUI_API LCUI_BOOL LCUIKeyboard_IsHit( int key_code ); /** - * 检测指定键值的按键是否按了两次 - * @param key_code - * 要检测的按键的键值 - * @param interval_time - * 该按键倒数第二次按下时的时间与当前时间的最大间隔 - */ -LCUI_API LCUI_BOOL LCUIKey_IsDoubleHit( int key_code, int interval_time ); +* 检测指定键值的按键是否按了两次 +* @param key_code 要检测的按键的键值 +* @param interval_time 该按键倒数第二次按下时的时间与当前时间的最大间隔 +*/ +LCUI_API LCUI_BOOL LCUIKeyboard_IsDoubleHit( int key_code, int interval_time ); /** 添加已被按下的按键 */ -LCUI_API void LCUIKeyBoard_HitKey( int key_code ); +LCUI_API void LCUIKeyboard_HitKey( int key_code ); /** 标记指定键值的按键已释放 */ -LCUI_API void LCUIKeyBoard_ReleaseKey( int key_code ); +LCUI_API void LCUIKeyboard_ReleaseKey( int key_code ); -/** 检测键盘是否有按键按下(类似于kbhit函数) */ -LCUI_API LCUI_BOOL LCUIKeyboard_IsHit( void ); +void LCUI_InitKeyboard( void ); -/** 获取被按下的按键的键值(类似于getch函数) */ -LCUI_API int LCUIKeyboard_GetKey( void ); - -/** 初始化键盘输入模块 */ -LCUI_API int LCUI_InitKeyboard( void ); - -/** 停用键盘输入模块 */ -LCUI_API int LCUI_ExitKeyboard( void ); +void LCUI_ExitKeyboard( void ); LCUI_END_HEADER diff --git a/src/ime.c b/src/ime.c index 9a39e63a..b77c024f 100644 --- a/src/ime.c +++ b/src/ime.c @@ -1,174 +1,185 @@ -// IME: Input Method Editor/Engine -//#define NEED_IME -#ifdef NEED_IME +/* *************************************************************************** + * ime.c -- Input Method Editor/Engine + * + * Copyright (C) 2016 by Liu Chao + * + * 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * ime.c -- 输入法管理器 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ + +#include #include #include #include #include #include -typedef struct LCUIIME_Info_ { - int id; - LCUI_String name; - LCUIIME_Func func; -} LCUIIME_Info; +/** 输入法相关数据 */ +typedef struct LCUI_IMERec_ { + int id; /**< 输入法ID */ + char *name; /**< 名称 */ + LCUI_IMEHandlerRec handler; /**< 处理器 */ + LinkedListNode node; /**< 在链表中的结点 */ +} LCUI_IMERec, *LCUI_IME; -// 指示输入法列表是否初始化 -LCUI_BOOL imelist_init = FALSE; +/** 输入法管理模块的相关数据 */ +static struct LCUIIMEModule { + LCUI_BOOL is_inited; /**< 是否已经初始化 */ + LinkedList list; /**< 当前记录的输入法列表 */ + LCUI_IME ime; /**< 当前激活的输入法 */ + LCUI_BOOL enable_caps_lock; /**< 是否已经启用大写锁定 */ + int id_count; /**< ID 计数器,用于生成输入法的 ID */ +} self; -// 输入法列表 -LCUI_Queue imelist; - -// 当前选择的输入法 -static LCUIIME_Info* current_ime = NULL; - -// 指示是否开启了大写锁定 -static LCUI_BOOL enable_capitals_lock = FALSE; /* 通过ID查找输入法信息 */ -static LCUIIME_Info* LCUIIME_Find( int ime_id ) +static LCUI_IME LCUIIME_Find( int ime_id ) { - int n, i; - LCUIIME_Info *ptr; - - n = Queue_GetTotal( &imelist ); - for( i=0; iid != ime_id ) { - continue; + LinkedListNode *node; + LinkedList_ForEach( node, &self.list ) { + LCUI_IME ime = node->data; + if( ime->id == ime_id ) { + return ime; } - return ptr; } return NULL; } /* 通过名字查找输入法信息 */ -static LCUIIME_Info* LCUIIME_FindByName( const char *name ) +static LCUI_IME LCUIIME_FindByName( const char *name ) { - int n, i; - LCUIIME_Info *ptr; - - n = Queue_GetTotal( &imelist ); - for( i=0; iname, name ) == 0 ) { - return ptr; + LinkedListNode *node; + LinkedList_ForEach( node, &self.list ){ + LCUI_IME ime = node->data; + if( strcmp( ime->name, name ) == 0 ) { + return ime; } } return NULL; } /* 注册一个输入法 */ -LCUI_API int LCUIIME_Register( const char *ime_name, LCUIIME_Func *ime_func ) +int LCUIIME_Register( const char *name, LCUI_IMEHandler handler ) { - static int ime_id = 0; // 输入法的ID - LCUIIME_Info *ptr_data; - - if( !imelist_init ) { + size_t len; + LCUI_IME ime; + if( !self.is_inited ) { return -1; } - if( LCUIIME_FindByName( ime_name ) != NULL ) { + if( LCUIIME_FindByName( name ) ) { return -2; } - - ptr_data = (LCUIIME_Info*)malloc( sizeof(LCUIIME_Info) ); - if( !ptr_data ) { - return -3; + ime = NEW( LCUI_IMERec, 1 ); + if( !ime ) { + return -ENOMEM; } - 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; + len = strlen( name ) + 1; + ime->name = malloc( len * sizeof(char) ); + if( !ime->name ) { + return -ENOMEM; + } + self.id_count += 1; + ime->id = self.id_count; + ime->node.data = ime; + memcpy( &ime->handler, handler, sizeof(LCUI_IMEHandler) ); + LinkedList_AppendNode( &self.list, &ime->node ); + return ime->id; } /* 选定输入法 */ -LCUI_API LCUI_BOOL LCUIIME_Select( int ime_id ) +LCUI_BOOL LCUIIME_Select( int ime_id ) { - LCUIIME_Info *ptr_data; - ptr_data = LCUIIME_Find( ime_id ); - if( ptr_data == NULL ) { - return FALSE; + LCUI_IME ime = LCUIIME_Find( ime_id ); + if( ime ) { + self.ime = ime; + return TRUE; } - current_ime = ptr_data; - return TRUE; + return FALSE; } -LCUI_API LCUI_BOOL LCUIIME_SelectByName( const char *name ) +LCUI_BOOL LCUIIME_SelectByName( const char *name ) { - LCUIIME_Info *ptr_data; - ptr_data = LCUIIME_FindByName( name ); - if( ptr_data == NULL ) { - return FALSE; + LCUI_IME ime = LCUIIME_FindByName( name ); + if( ime ) { + self.ime = ime; + return TRUE; } - current_ime = ptr_data; - return TRUE; + return FALSE; } /* 打开输入法 */ -static LCUI_BOOL LCUIIME_Open( LCUIIME_Info *ime ) +static LCUI_BOOL LCUIIME_Open( LCUI_IME ime ) { - if( ime == NULL ) { - return FALSE; + if( ime && ime->handler.open ) { + return ime->handler.open(); } - if( ime->func.open == NULL ) { - return FALSE; - } - return ime->func.open(); + return FALSE; } /* 关闭输入法 */ -static LCUI_BOOL LCUIIME_Close( LCUIIME_Info *ime ) +static LCUI_BOOL LCUIIME_Close( LCUI_IME ime ) { - if( ime == NULL ) { - return FALSE; + if( ime && ime->handler.close ) { + return ime->handler.open(); } - if( ime->func.close == NULL ) { - return FALSE; - } - return ime->func.close(); + return FALSE; } /* 切换至下一个输入法 */ -LCUI_API void LCUIIME_Switch(void) +void LCUIIME_Switch( void ) { - int i=0, n; - LCUIIME_Info *ime_ptr; - - n = Queue_GetTotal( &imelist ); - if( i>=n ) { - i = 0; + LCUI_IME ime; + if( self.ime && self.ime->node.next ) { + ime = self.ime->node.next->data; + LCUIIME_Close( self.ime ); + self.ime = ime; + LCUIIME_Open( self.ime ); } - ime_ptr = Queue_Get( &imelist, i ); - if( ime_ptr == NULL ) { - return; - } - if(ime_ptr != current_ime) { - LCUIIME_Close( current_ime ); - current_ime = ime_ptr; - LCUIIME_Open( current_ime ); - } - ++i; } /* 销毁输入法信息 */ -static void LCUIIME_DestroyInfo( void *arg ) +static void LCUIIME_OnDestroy( void *arg ) { - LCUIIME_Info *p; - p = (LCUIIME_Info*)arg; - LCUIString_Free( &p->name ); + LCUI_IME ime = arg; + free( ime->name ); + ime->name = NULL; } -static void LCUIIME_ToText( const LCUI_KeyboardEvent *event ) +static void LCUIIME_ToText( LCUI_SysEvent e ) { char ch; - switch(event->key_code) { + switch(e->key.code) { #ifdef LCUI_BUILD_IN_WIN32 case 189: ch = '-'; break; case 187: ch = '='; break; @@ -181,19 +192,19 @@ static void LCUIIME_ToText( const LCUI_KeyboardEvent *event ) case 221: ch = ']'; break; case 219: ch = '['; break; #endif - default:ch = event->key_code;break; + default:ch = e->key.code;break; } DEBUG_MSG("key code: %d\n", event->key_code); /* 如果没开启大写锁定,则将字母转换成小写 */ - if( !enable_capitals_lock ) { + if( !self.enable_caps_lock ) { if( ch >= 'A' && ch <= 'Z' ) { - ch = event->key_code + 32; + ch = e->key.code + 32; } } /* 如果shift键处于按下状态 */ - if( LCUIKey_IsHit(LCUIKEY_SHIFT) ) { + if( LCUIKeyboard_IsHit(LCUIKEY_SHIFT) ) { if(ch >='a' && ch <= 'z') { ch = ch - 32; } else if(ch >='A' && ch <= 'Z') { @@ -225,103 +236,96 @@ static void LCUIIME_ToText( const LCUI_KeyboardEvent *event ) } } DEBUG_MSG("ch = %c\n", ch); - current_ime->func.totext( ch ); + self.ime->handler.totext( ch ); } -/* 检测输入法是否要处理按键事件 */ -LCUI_API LCUI_BOOL LCUIIME_ProcessKey( const LCUI_KeyboardEvent *event ) +LCUI_BOOL LCUIIME_ProcessKey( LCUI_SysEvent e ) { int key_state; /* 根据事件类型判定按键状态 */ - if( event->type == LCUI_KEYUP ) { + if( e->type == LCUI_KEYUP ) { key_state = LCUIKEYSTATE_RELEASE; + /* 如果是caps lock按键被释放 */ + if( e->key.code == LCUIKEY_CAPITAL ) { + self.enable_caps_lock = !self.enable_caps_lock; + return FALSE; + } } else { key_state = LCUIKEYSTATE_PRESSED; + /* 如果按下的是 shift 键,但没释放,则直接退出 */ + if( e->key.code == LCUIKEY_SHIFT ) { + return FALSE; + } } - /* 如果按下的是shift键,但没释放,则直接退出 */ - if( event->key_code == LCUIKEY_SHIFT - && event->type == LCUI_KEYDOWN ) { - return FALSE; - } - /* 如果是caps lock按键被释放 */ - if( event->key_code == LCUIKEY_CAPITAL - && event->type == LCUI_KEYUP ) { - enable_capitals_lock = !enable_capitals_lock; - return FALSE; - } - if( current_ime == NULL ) { - return FALSE; - } - if( current_ime->func.prockey == NULL ) { - return FALSE; - } - /* 如果输入法要处理该键,则调用LCUIIME_ToText函数 */ - if( current_ime->func.prockey( event->key_code, key_state ) ) { - LCUIIME_ToText( event ); - return TRUE; + if( self.ime && self.ime->handler.prockey ) { + /* 如果输入法要处理该键,则调用LCUIIME_ToText函数 */ + if( self.ime->handler.prockey( e->key.code, key_state ) ) { + LCUIIME_ToText( e ); + return TRUE; + } } return FALSE; } -/* 提交输入法输入的内容至目标 */ -LCUI_API int LCUIIME_Commit( const wchar_t *str ) +int LCUIIME_Commit( const wchar_t *str ) { LCUI_Widget widget; - LCUI_WidgetEvent event; - - if( current_ime == NULL ) { + LCUI_WidgetEventRec e; + if( !self.ime || !self.ime->handler.gettarget ) { return -1; } - if( current_ime->func.gettarget == NULL ) { + widget = self.ime->handler.gettarget(); + if( !widget ) { return -2; } - widget = current_ime->func.gettarget(); - if(! widget ) { - return -3; - } - /* 设置事件 */ - event.type = EVENT_INPUT; - wcscpy( event.input.text, str ); - /* 派发事件 */ - return Widget_DispatchEvent( widget, &event ); + e.type = LCUI_INPUT; + wcscpy( e.input.text, str ); + return Widget_PostEvent( widget, &e, NULL, NULL ); } -/* 设置输入法的目标 */ -LCUI_API int LCUIIME_SetTarget( LCUI_Widget widget ) +int LCUIIME_SetTarget( LCUI_Widget widget ) { - if( current_ime == NULL ) { - return -1; + if( self.ime && self.ime->handler.settarget ) { + self.ime->handler.settarget( widget ); + return 0; } - if( current_ime->func.settarget == NULL ) { - return -2; - } - current_ime->func.settarget( widget ); - return 0; + return -1; } -static int LCUI_DefaultIMERegister(void); +int LCUIIME_ClearTarget( void ) +{ + if( self.ime && self.ime->handler.cleartarget ) { + self.ime->handler.cleartarget(); + return 0; + } + return -1; +} + +int LCUI_RegisterDefaultIME( void ); /* 初始化LCUI输入法模块 */ -LCUI_API void LCUI_InitIME(void) +void LCUI_InitIME( void ) { int ime_id; - Queue_Init( &imelist, sizeof(LCUIIME_Info), LCUIIME_DestroyInfo ); - imelist_init = TRUE; - ime_id = LCUI_DefaultIMERegister(); + LinkedList_Init( &self.list ); + self.is_inited = TRUE; + ime_id = LCUI_RegisterDefaultIME(); LCUIIME_Select( ime_id ); } /* 停用LCUI输入法模块 */ -LCUI_API void LCUIModule_IME_End(void) +void LCUI_ExitIME( void ) { - imelist_init = FALSE; + self.is_inited = FALSE; } /*-------------------------- 默认的输入法 ------------------------------*/ -// 目标部件 -static LCUI_Widget target_widget = NULL; +static struct { + LCUI_Widget target; +} default_ime; + /** 判断按键是否需要处理,也可以用于设置当前的输入法,比如: @@ -403,12 +407,12 @@ static LCUI_BOOL IME_ProcessKey( int key, int key_state ) static void IME_SetTarget( LCUI_Widget widget ) { - target_widget = widget; + default_ime.target = widget; } -static LCUI_Widget* IME_GetTarget( void ) +static LCUI_Widget IME_GetTarget( void ) { - return target_widget; + return default_ime.target; } static void IME_ToText( char ch ) @@ -428,33 +432,29 @@ static void IME_ToText( char ch ) } /** - 输入法被打开时的处理 - 可以在输入法被打开时,初始化相关数据,链接至词库什么的 + * 输入法被打开时的处理 + * 可以在输入法被打开时,初始化相关数据,链接至词库什么的 **/ static LCUI_BOOL IME_Open(void) { return TRUE; } - -/* 输入法被关闭时的处理 */ +/** 输入法被关闭时的处理 */ static LCUI_BOOL IME_Close(void) { return TRUE; } -/* 注册LCUI默认的输入法 */ -static int LCUI_DefaultIMERegister(void) +/** 注册LCUI默认的输入法 */ +static int LCUI_RegisterDefaultIME( void ) { - LCUIIME_Func ime_func; - ime_func.gettarget = IME_GetTarget; - ime_func.settarget = IME_SetTarget; - ime_func.prockey = IME_ProcessKey; - ime_func.totext = IME_ToText; - ime_func.close = IME_Close; - ime_func.open = IME_Open; - return LCUIIME_Register( "LCUI Input Method", &ime_func ); + LCUI_IMEHandlerRec handler; + handler.gettarget = IME_GetTarget; + handler.settarget = IME_SetTarget; + handler.prockey = IME_ProcessKey; + handler.totext = IME_ToText; + handler.close = IME_Close; + handler.open = IME_Open; + return LCUIIME_Register( "LCUI Input Method", &handler ); } -/*------------------------------ END ----------------------------------*/ - -#endif diff --git a/src/keyboard.c b/src/keyboard.c new file mode 100644 index 00000000..c220bbec --- /dev/null +++ b/src/keyboard.c @@ -0,0 +1,161 @@ +/* *************************************************************************** + * keyboard.c -- keyboard input management + * + * Copyright (C) 2016 by Liu Chao + * + * 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * keyboard.c -- 键盘输入管理 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ + + +#include +#include +#include +#include +#include + +typedef struct KeyStateNodeRec_ { + int state; /**< 当前状态 */ + clock_t hit_time; /**< 按下此键时的时间 */ + clock_t interval_time; /**< 近两次按下此键的时间间隔 */ +} KeyStateNodeRec, *KeyStateNode; + +static struct LCUIKeyboardModule { + LCUI_Mutex mutex; + LCUI_RBTree state_tree; +} self; + +/** 检测指定键值的按键是否处于按下状态 */ +LCUI_BOOL LCUIKeyboard_IsHit( int key_code ) +{ + KeyStateNode node; + LCUIMutex_Lock( &self.mutex ); + node = RBTree_GetData( &self.state_tree, key_code ); + LCUIMutex_Unlock( &self.mutex ); + if( node && node->state == LCUIKEYSTATE_PRESSED ) { + return TRUE; + } + return FALSE; +} + +/** + * 检测指定键值的按键是否按了两次 + * @param key_code 要检测的按键的键值 + * @param interval_time 该按键倒数第二次按下时的时间与当前时间的最大间隔 +*/ +LCUI_BOOL LCUIKeyboard_IsDoubleHit( int key_code, int interval_time ) +{ + clock_t ct; + KeyStateNode node; + /* 计算当前时间(单位:毫秒) */ + ct = clock() * 1000 / CLOCKS_PER_SEC; + LCUIMutex_Lock( &self.mutex ); + node = RBTree_GetData( &self.state_tree, key_code ); + LCUIMutex_Unlock( &self.mutex ); + if( !node ) { + return FALSE; + } + /* 间隔时间为-1,说明该键是新记录的 */ + if( node->interval_time == -1 ) { + return FALSE; + } + ct -= node->hit_time - node->interval_time; + /* 判断按键被按下两次时是否在距当前 interval_time 毫秒的时间内发生 */ + if( ct <= interval_time ) { + return TRUE; + } + return FALSE; +} + +/** 添加已被按下的按键 */ +void LCUIKeyboard_HitKey( int key_code ) +{ + clock_t ct; + KeyStateNode node; + LCUIMutex_Lock( &self.mutex ); + ct = clock() * 1000 / CLOCKS_PER_SEC; + node = RBTree_GetData( &self.state_tree, key_code ); + if( !node ) { + node = NEW( KeyStateNodeRec, 1 ); + node->interval_time = -1; + node->hit_time = ct; + node->state = LCUIKEYSTATE_PRESSED; + RBTree_Insert( &self.state_tree, key_code, node ); + LCUIMutex_Unlock( &self.mutex ); + return; + } + if( node->state == LCUIKEYSTATE_RELEASE ) { + node->state = LCUIKEYSTATE_PRESSED; + /* 记录与上次此键被按下时的时间间隔 */ + node->interval_time = ct - node->hit_time; + /* 记录本次此键被按下时的时间 */ + node->hit_time = ct; + } + LCUIMutex_Unlock( &self.mutex ); +} + +/** 标记指定键值的按键已释放 */ +void LCUIKeyboard_ReleaseKey( int key_code ) +{ + KeyStateNode node; + LCUIMutex_Lock( &self.mutex ); + node = RBTree_GetData( &self.state_tree, key_code ); + if( node ) { + node->state = LCUIKEYSTATE_RELEASE; + } + LCUIMutex_Unlock( &self.mutex ); +} + +static void OnKeyboardEvent( LCUI_SysEvent e, void *arg ) +{ + if( e->type == LCUI_KEYDOWN ) { + LCUIKeyboard_HitKey( e->key.code ); + } else if( e->type == LCUI_KEYUP ) { + LCUIKeyboard_ReleaseKey( e->key.code ); + } +} + +void LCUI_InitKeyboard( void ) +{ + LCUIMutex_Init( &self.mutex ); + RBTree_Init( &self.state_tree ); + RBTree_SetDataNeedFree( &self.state_tree, TRUE ); + LCUI_BindEvent( LCUI_KEYDOWN, OnKeyboardEvent, NULL, NULL ); + LCUI_BindEvent( LCUI_KEYUP, OnKeyboardEvent, NULL, NULL ); +} + +void LCUI_ExitKeyboard( void ) +{ + RBTree_Destroy( &self.state_tree ); + LCUIMutex_Destroy( &self.mutex ); +} From ddfe1659f987add3c7baf8e26fafa66f9b447b0a Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Wed, 15 Jun 2016 23:18:31 +0800 Subject: [PATCH 046/124] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=83=A8=E4=BB=B6?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E6=95=B0=E6=8D=AE=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/gui/widget_event.h | 27 +++++++++---- src/gui/widget_event.c | 72 ++++++++++++++++++--------------- 2 files changed, 59 insertions(+), 40 deletions(-) diff --git a/include/LCUI/gui/widget_event.h b/include/LCUI/gui/widget_event.h index b9c1c99e..f5796c13 100644 --- a/include/LCUI/gui/widget_event.h +++ b/include/LCUI/gui/widget_event.h @@ -77,18 +77,31 @@ enum WidgetEventType { WET_USER }; +/* 部件的事件数据结构和系统事件一样 */ +typedef LCUI_MouseMotionEvent LCUI_WidgetMouseMotionEvent; +typedef LCUI_MouseButtonEvent LCUI_WidgetMouseButtonEvent; +typedef LCUI_MouseWheelEvent LCUI_WidgetMouseWheelEvent; +typedef LCUI_KeyboardEvent LCUI_WidgetKeyboardEvent; +typedef LCUI_TouchEvent LCUI_WidgetTouchEvent; + +typedef struct LCUI_WidgetInputEvent_ { + wchar_t text[128]; +} LCUI_WidgetInputEvent; + /** 面向部件级的事件内容结构 */ typedef struct LCUI_WidgetEventRec_ { - int type; /**< 事件类型标识号 */ - int which; /**< 指示按了哪个键或按钮 */ - int x, y; /**< 事件触发时鼠标的坐标(相对于当前部件的边框盒) */ - int z_delta; /**< 鼠标滚轮滚动的距离差值 */ - int screen_x, screen_y; /**< 事件触发时鼠标的屏幕坐标 */ - int n_points; /**< 触点数量 */ - LCUI_TouchPoint points; /**< 触点列表 */ + uint32_t type; /**< 事件类型标识号 */ void *data; /**< 附加数据 */ LCUI_Widget target; /**< 触发事件的部件 */ LCUI_BOOL cancel_bubble; /**< 是否取消事件冒泡 */ + union { + LCUI_WidgetMouseMotionEvent motion; + LCUI_WidgetMouseButtonEvent button; + LCUI_WidgetMouseWheelEvent wheel; + LCUI_WidgetKeyboardEvent key; + LCUI_WidgetTouchEvent touch; + LCUI_WidgetInputEvent input; + }; } LCUI_WidgetEventRec, *LCUI_WidgetEvent; typedef void(*LCUI_WidgetEventFunc)(LCUI_Widget, LCUI_WidgetEvent, void*); diff --git a/src/gui/widget_event.c b/src/gui/widget_event.c index a035b8a4..7d4b0d61 100644 --- a/src/gui/widget_event.c +++ b/src/gui/widget_event.c @@ -60,6 +60,7 @@ typedef struct WidgetEventHandlerRec_ { typedef struct LCUI_WidgetEventPackRec_ { void *data; /**< 额外数据 */ void (*destroy_data)(void*); /**< 数据的销毁函数 */ + int x, y; /**< 事件触发点的坐标,主要用于鼠标事件的传递 */ LCUI_Widget widget; /**< 当前处理该事件的部件 */ LCUI_WidgetEventRec event; /**< 事件数据 */ LCUI_BOOL is_direct_run; /**< 是否直接处理该事件 */ @@ -165,11 +166,11 @@ static void WidgetEventTranslator( LCUI_Event e, LCUI_WidgetEventPack pack ) } return; } - pack->event.x += w->box.border.x; - pack->event.y += w->box.border.y; + pack->x += w->box.border.x; + pack->y += w->box.border.y; w = w->parent; - pack->event.x += w->padding.left; - pack->event.y += w->padding.top; + pack->x += w->padding.left; + pack->y += w->padding.top; pack->widget = w; /** 向父级部件冒泡传递事件 */ EventTrigger_Trigger( w->trigger, e->type, pack ); @@ -181,14 +182,15 @@ static void CopyWidgetEventPack( LCUI_WidgetEventPack dst, { *dst = *src; if( src->event.type == WET_TOUCH ) { - if( src->event.n_points > 0 ) { - int n = src->event.n_points; + if( src->event.touch.n_points > 0 ) { + int n = src->event.touch.n_points; size_t size = sizeof( LCUI_TouchPointRec ) * n; - dst->event.points = malloc( size ); - if( !dst->event.points ) { + dst->event.touch.points = malloc( size ); + if( !dst->event.touch.points ) { return; } - memcpy( dst->event.points, src->event.points, size ); + memcpy( dst->event.touch.points, + src->event.touch.points, size ); } } } @@ -198,11 +200,11 @@ static void DestroyWidgetEventPack( void *arg ) { LCUI_WidgetEventPack pack = arg; if( pack->event.type == WET_TOUCH ) { - if( pack->event.n_points > 0 ) { - free( pack->event.points ); + if( pack->event.touch.n_points > 0 ) { + free( pack->event.touch.points ); } - pack->event.points = NULL; - pack->event.n_points = 0; + pack->event.touch.points = NULL; + pack->event.touch.n_points = 0; } free( pack ); } @@ -473,17 +475,17 @@ static int Widget_TriggerEventEx( LCUI_Widget widget, LCUI_WidgetEvent e, return -1; } /* 转换成相对于父级部件内容框的坐标 */ - pack.event.x += widget->box.border.x; - pack.event.y += widget->box.border.y; + pack.x += widget->box.border.x; + pack.y += widget->box.border.y; /* 从当前部件后面找到当前坐标点命中的兄弟部件 */ - w = Widget_GetNextAt( widget, pack.event.x, pack.event.y ); + w = Widget_GetNextAt( widget, pack.x, pack.y ); /* 找不到就向父级部件冒泡 */ if( !w ) { return Widget_PostEvent( widget->parent, e, data, destroy_data ); } - pack.event.x -= w->box.border.x; - pack.event.y -= w->box.border.y; + pack.x -= w->box.border.x; + pack.y -= w->box.border.y; return EventTrigger_Trigger( w->trigger, e->type, &pack ); } @@ -597,22 +599,22 @@ static void OnMouseEvent( LCUI_SysEvent e, void *arg ) return; } } - Widget_GetAbsXY( target, NULL, &ebuff.x, &ebuff.y ); ebuff.cancel_bubble = FALSE; - ebuff.x = pos.x - ebuff.x; - ebuff.y = pos.y - ebuff.y; - ebuff.screen_x = pos.x; - ebuff.screen_y = pos.y; ebuff.target = target; - ebuff.which = 0; switch( e->type ) { case LCUI_MOUSEDOWN: ebuff.type = WET_MOUSEDOWN; + ebuff.button.x = pos.x; + ebuff.button.y = pos.y; + ebuff.button.button = e->button.button; Widget_PostEvent( target, &ebuff, NULL, NULL ); Widget_UpdateStatus( target, WST_ACTIVE ); break; case LCUI_MOUSEUP: ebuff.type = WET_MOUSEUP; + ebuff.button.x = pos.x; + ebuff.button.y = pos.y; + ebuff.button.button = e->button.button; Widget_PostEvent( target, &ebuff, NULL, NULL ); if( self.targets[WST_ACTIVE] == target ) { ebuff.type = WET_CLICK; @@ -622,11 +624,13 @@ static void OnMouseEvent( LCUI_SysEvent e, void *arg ) break; case LCUI_MOUSEMOVE: ebuff.type = WET_MOUSEMOVE; + ebuff.motion.x = pos.x; + ebuff.motion.y = pos.y; Widget_PostEvent( target, &ebuff, NULL, NULL ); break; case LCUI_MOUSEWHEEL: ebuff.type = WET_MOUSEWHEEL; - ebuff.z_delta = e->wheel.delta; + ebuff.wheel.delta = e->wheel.delta; Widget_PostEvent( target, &ebuff, NULL, NULL ); default:return; } @@ -679,7 +683,7 @@ static int DispatchTouchEvent( LinkedList *capturers, LCUI_TouchPoint points, ev.type = WET_TOUCH; ev.cancel_bubble = FALSE; root = LCUIWidget_GetRoot(); - ev.points = NEW( LCUI_TouchPointRec, n_points ); + ev.touch.points = NEW( LCUI_TouchPointRec, n_points ); /* 先将各个触点按命中的部件进行分组 */ for( i = 0; i < n_points; ++i ) { target = Widget_At( root, points[i].x, points[i].y ); @@ -697,28 +701,30 @@ static int DispatchTouchEvent( LinkedList *capturers, LCUI_TouchPoint points, TouchCapturers_Add( capturers, target, points[i].id ); } count = 0; - ev.n_points = 0; + ev.touch.n_points = 0; /* 然后向命中的部件发送触控事件 */ LinkedList_ForEach( node, capturers ) { TouchCapturer tc = node->data; for( i = 0; i < n_points; ++i ) { LinkedList_ForEach( ptnode, &tc->points ) { + LCUI_TouchPoint point; if( points[i].id != *(int*)ptnode->data ) { continue; } - ev.points[ev.n_points] = points[i]; - ConvertTouchPoint( &ev.points[ev.n_points] ); - ++ev.n_points; + point = &ev.touch.points[ev.touch.n_points]; + *point = points[i]; + ConvertTouchPoint( point ); + ++ev.touch.n_points; } } - if( ev.n_points == 0 ) { + if( ev.touch.n_points == 0 ) { continue; } Widget_PostEvent( tc->widget, &ev, NULL, NULL ); - ev.n_points = 0; + ev.touch.n_points = 0; ++count; } - free( ev.points ); + free( ev.touch.points ); return count; } From 501d363f5062f32f806f2f8633d5855773013c1e Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Wed, 15 Jun 2016 23:20:17 +0800 Subject: [PATCH 047/124] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20textedit=20?= =?UTF-8?q?=E9=83=A8=E4=BB=B6=EF=BC=8C=E4=BF=AE=E6=94=B9=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 有待测试完善 --- build/VS2012/LCUI/LCUI.vcxproj | 3 + build/VS2012/LCUI/LCUI.vcxproj.filters | 9 + include/LCUI/font/textlayer.h | 2 +- include/LCUI/font/textstyle.h | 5 +- include/LCUI/gui/widget/textedit.h | 68 +++ src/font/textlayer.c | 8 +- src/font/textstyle.c | 2 +- src/gui/widget/textedit.c | 660 +++++++++++++++++++++++++ src/gui/widget/textview.c | 2 +- 9 files changed, 748 insertions(+), 11 deletions(-) create mode 100644 include/LCUI/gui/widget/textedit.h create mode 100644 src/gui/widget/textedit.c diff --git a/build/VS2012/LCUI/LCUI.vcxproj b/build/VS2012/LCUI/LCUI.vcxproj index 9f85941d..2f69b341 100644 --- a/build/VS2012/LCUI/LCUI.vcxproj +++ b/build/VS2012/LCUI/LCUI.vcxproj @@ -153,6 +153,7 @@ + @@ -216,6 +217,7 @@ + @@ -229,6 +231,7 @@ MaxSpeed + diff --git a/build/VS2012/LCUI/LCUI.vcxproj.filters b/build/VS2012/LCUI/LCUI.vcxproj.filters index 02f30379..8d11fe9f 100644 --- a/build/VS2012/LCUI/LCUI.vcxproj.filters +++ b/build/VS2012/LCUI/LCUI.vcxproj.filters @@ -231,6 +231,9 @@ 头文件\LCUI\util + + 头文件\LCUI\gui\widget + @@ -395,6 +398,12 @@ 源文件\bmp + + 源文件\gui\widget + + + 源文件 + diff --git a/include/LCUI/font/textlayer.h b/include/LCUI/font/textlayer.h index 204d30a5..1307b594 100755 --- a/include/LCUI/font/textlayer.h +++ b/include/LCUI/font/textlayer.h @@ -137,7 +137,7 @@ LCUI_API void TextLayer_SetOffset( LCUI_TextLayer layer, int offset_x, int offse LCUI_API LCUI_TextLayer TextLayer_New(void); /** 销毁TextLayer */ -LCUI_API void TextLayer_Destroy( LCUI_TextLayer *layer ); +LCUI_API void TextLayer_Destroy( LCUI_TextLayer layer ); /** 标记指定范围内容的文本行的矩形为无效 */ LCUI_API void TextLayer_InvalidateRowsRect( LCUI_TextLayer layer, diff --git a/include/LCUI/font/textstyle.h b/include/LCUI/font/textstyle.h index e7cbc666..b47ff837 100755 --- a/include/LCUI/font/textstyle.h +++ b/include/LCUI/font/textstyle.h @@ -97,11 +97,10 @@ LCUI_API int TextStyle_SetFont( LCUI_TextStyle *ts, const char *str ); /*-------------------------- StyleTag --------------------------------*/ -#define TagList_Init LinkedList_Init +#define StyleTags_Init LinkedList_Init -LCUI_API void TagList_Clear( LinkedList *tags ); +LCUI_API void StyleTags_Clear( LinkedList *tags ); -/** 获取当前的文本样式 */ LCUI_API LCUI_TextStyle* StyleTags_GetTextStyle( LinkedList *tags ); /** 在字符串中获取样式的结束标签,输出的是标签名 */ diff --git a/include/LCUI/gui/widget/textedit.h b/include/LCUI/gui/widget/textedit.h new file mode 100644 index 00000000..5c69c5b6 --- /dev/null +++ b/include/LCUI/gui/widget/textedit.h @@ -0,0 +1,68 @@ +/* *************************************************************************** + * textedit.c -- textedit widget, used to allow user edit text. + * + * Copyright (C) 2016 by Liu Chao + * + * 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * textedit.c -- Îı¾±༭²¿¼þ£¬ÓÃÓÚÈÃÓû§±༭Îı¾¡£ + * + * °æȨËùÓÐ (C) 2016 ¹éÊôÓÚ Áõ³¬ + * + * Õâ¸öÎļþÊÇLCUIÏîĿµÄһ²¿·֣¬²¢ÇÒֻ¿ÉÒԸù¾ÝGPLv2Ðí¿ÉЭÒéÀ´ʹÓᢸü¸ĺͷ¢²¼¡£ + * + * (GPLv2 ÊÇ GNUͨÓù«¹²Ðí¿É֤µڶþ°æ µÄӢÎÄËõд) + * + * ¼ÌÐøʹÓá¢Ð޸Ļ򷢲¼±¾Îļþ£¬±íÃ÷ÄúÒѾ­ÔĶÁ²¢ÍêȫÀí½âºͽÓÊÜÕâ¸öÐí¿ÉЭÒ顣 + * + * LCUI ÏîĿÊǻùÓÚʹÓÃĿµĶø¼ÓÒÔɢ²¼µģ¬µ«²»¸ºÈκε£±£ÔðÈΣ¬ÉõÖÁûÓÐÊÊÏúÐԻòÌØ + * ¶¨ÓÃ;µÄÒþº¬µ£±££¬ÏêÇéÇë²ÎÕÕGPLv2Ðí¿ÉЭÒ顣 + * + * ÄúӦÒÑÊյ½¸½ËæÓڱ¾ÎļþµÄGPLv2Ðí¿ÉЭÒéµĸ±±¾£¬Ëüͨ³£ÔÚLICENSE.TXTÎļþÖУ¬Èç¹û + * ûÓУ¬Çë²鿴£º. + * ****************************************************************************/ +#ifndef LCUI_TEXTBOX_H +#define LCUI_TEXTBOX_H + +LCUI_BEGIN_HEADER + +#define TextEdit_New() Widget_New("textedit") + +/** ָ¶¨Îı¾¿òÊǷñ´¦Àí¿ØÖƷû */ +LCUI_API void TextEdit_SetUsingStyleTags( LCUI_Widget widget, LCUI_BOOL is_true ); + +/** ָ¶¨Îı¾¿òÊǷñÆôÓöàÐÐÎı¾ÏÔʾ */ +LCUI_API void TextEdit_SetMultiline( LCUI_Widget widget, LCUI_BOOL is_true ); + +/** Çå¿ÕÎı¾ÄÚÈÝ */ +LCUI_API void TextEdit_ClearText( LCUI_Widget widget ); + +/** ΪÎı¾¿òÉèÖÃÎı¾£¨¿í×ַû°棩 */ +LCUI_API int TextEdit_SetTextW( LCUI_Widget widget, const wchar_t *wstr ); + +LCUI_API int TextEdit_SetText( LCUI_Widget widget, const char *utf8_str ); + +/** ΪÎı¾¿ò׷¼ÓÎı¾£¨¿í×ַû°棩 */ +LCUI_API int TextEdit_AppendTextW( LCUI_Widget widget, const wchar_t *wstr ); + +/** ΪÎı¾¿ò²åÈëÎı¾£¨¿í×ַû°棩 */ +LCUI_API int TextEdit_InsertTextW( LCUI_Widget widget, const wchar_t *wstr ); + +LCUI_END_HEADER + +#endif \ No newline at end of file diff --git a/src/font/textlayer.c b/src/font/textlayer.c index d09189e3..44e81855 100644 --- a/src/font/textlayer.c +++ b/src/font/textlayer.c @@ -333,14 +333,12 @@ static void TextRowList_Destroy( TextRowList list ) } /** 销毁TextLayer */ -void TextLayer_Destroy( LCUI_TextLayer *layer_ptr ) +void TextLayer_Destroy( LCUI_TextLayer layer ) { - LCUI_TextLayer layer = *layer_ptr; LinkedList_Clear( &layer->dirty_rect, free ); Graph_Free( &layer->graph ); TextRowList_Destroy( &layer->rowlist ); free( layer ); - *layer_ptr = NULL; } /** 获取指定文本行中的文本段的矩形区域 */ @@ -714,7 +712,7 @@ static int TextLayer_ProcessText( LCUI_TextLayer layer, /* 如果没有可用的标签栈,则使用临时的标签栈 */ if( !tags ) { is_tmp_tag_stack = TRUE; - TagList_Init( &tmp_tags ); + StyleTags_Init( &tmp_tags ); tags = &tmp_tags; } p_end = wstr + wcslen(wstr); @@ -788,7 +786,7 @@ static int TextLayer_ProcessText( LCUI_TextLayer layer, } /* 如果使用的是临时标签栈,则销毁它 */ if( is_tmp_tag_stack ) { - TagList_Clear( tags ); + StyleTags_Clear( tags ); } return 0; } diff --git a/src/font/textstyle.c b/src/font/textstyle.c index f7b97c6d..bf538656 100755 --- a/src/font/textstyle.c +++ b/src/font/textstyle.c @@ -157,7 +157,7 @@ static void DestroyTag( LCUI_StyleTag *tag ) // XXX } -void TagList_Clear( LinkedList *tags ) +void StyleTags_Clear( LinkedList *tags ) { LinkedList_Clear( tags, (FuncPtr)DestroyTag ); } diff --git a/src/gui/widget/textedit.c b/src/gui/widget/textedit.c new file mode 100644 index 00000000..fac67bee --- /dev/null +++ b/src/gui/widget/textedit.c @@ -0,0 +1,660 @@ +/* *************************************************************************** + * textedit.c -- textedit widget, used to allow user edit text. + * + * Copyright (C) 2016 by Liu Chao + * + * 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * textedit.c -- Îı¾±༭²¿¼þ£¬ÓÃÓÚÈÃÓû§±༭Îı¾¡£ + * + * °æȨËùÓÐ (C) 2016 ¹éÊôÓÚ Áõ³¬ + * + * Õâ¸öÎļþÊÇLCUIÏîĿµÄһ²¿·֣¬²¢ÇÒֻ¿ÉÒԸù¾ÝGPLv2Ðí¿ÉЭÒéÀ´ʹÓᢸü¸ĺͷ¢²¼¡£ + * + * (GPLv2 ÊÇ GNUͨÓù«¹²Ðí¿É֤µڶþ°æ µÄӢÎÄËõд) + * + * ¼ÌÐøʹÓá¢Ð޸Ļ򷢲¼±¾Îļþ£¬±íÃ÷ÄúÒѾ­ÔĶÁ²¢ÍêȫÀí½âºͽÓÊÜÕâ¸öÐí¿ÉЭÒ顣 + * + * LCUI ÏîĿÊǻùÓÚʹÓÃĿµĶø¼ÓÒÔɢ²¼µģ¬µ«²»¸ºÈκε£±£ÔðÈΣ¬ÉõÖÁûÓÐÊÊÏúÐԻòÌØ + * ¶¨ÓÃ;µÄÒþº¬µ£±££¬ÏêÇéÇë²ÎÕÕGPLv2Ðí¿ÉЭÒ顣 + * + * ÄúӦÒÑÊյ½¸½ËæÓڱ¾ÎļþµÄGPLv2Ðí¿ÉЭÒéµĸ±±¾£¬Ëüͨ³£ÔÚLICENSE.TXTÎļþÖУ¬Èç¹û + * ûÓУ¬Çë²鿴£º. + * ****************************************************************************/ + +//#define DEBUG +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define CARET_HIDE 0 +#define CARET_SHOW 1 +#define TEXT_BLOCK_SIZE 512 + +enum TaskType { + TASK_SET_TEXT, + TASK_TOTAL +}; + +/** Îı¾²åÈë·ûÏà¹ØÊý¾Ý */ +typedef struct LCUI_TextCaretRec_ { + int type; + int state; /**< µ±ǰ״̬ */ + int blink_time; /**< ÉÁ˸¼ä¸ô */ + int timer_id; /**< ¶¨ʱÆ÷ */ + LCUI_BOOL need_show; +} LCUI_TextCaretRec, *LCUI_TextCaret; + +typedef struct LCUI_TextEditRec_ { + LCUI_TextLayer text; /**< ʵ¼ÊÎı¾ */ + LCUI_TextLayer mask_text; /**< ÆÁ±κóµÄÎı¾ */ + LCUI_Widget scrollbar[2]; /**< Á½¸ö¹ö¶¯Ìõ */ + LCUI_Widget caret; /**< Îı¾²åÈë·û */ + LCUI_BOOL read_only; /**< ÊǷñֻ¶Á */ + int block_size; /**< ¿é´óС */ + LinkedList text_blocks; /**< Îı¾¿黺³åÇø */ + LinkedList text_tags; /**< µ±ǰ´¦ÀíµıêǩÁбí */ + LCUI_BOOL show_placeholder; /**< ±íʾռλ·ûÊǷñÒѾ­ÏÔʾ */ + wchar_t *placeholder; /**< Îı¾¿òµÄռλ·û */ + wchar_t *allow_input_char; /**< ÔÊÐíÊäÈëµÄ×ַû */ + wchar_t password_char; /**< ÆÁ±ηûµĸ±±¾ */ + LCUI_TextStyle placeholder_style; /**< ռλ·ûµÄÎı¾Ñùʽ */ + LCUI_TextStyle textstyle_bak; /**< Îı¾¿òÄÚÎı¾Ñùʽµĸ±±¾ */ + LCUI_BOOL tasks[TASK_TOTAL]; /**< ´ý´¦ÀíµÄÈÎÎñ */ + LCUI_Mutex mutex; /**< »¥³âËø */ +} LCUI_TextEditRec, *LCUI_TextEdit; + +enum TextBlockType_ { + TEXT_BLOCK_BEGIN, + TEXT_BLOCK_BODY, + TEXT_BLOCK_END +}; + +/** Îı¾¿éÊý¾ݽṹ */ +typedef struct LCUI_TextBlockRec_ { + int type; /**< Îı¾¿éÀàÐÍ */ + int add_type; /**< ָ¶¨¸ÃÎı¾¿éµÄÌí¼ӷ½ʽ */ + wchar_t *text; /**< Îı¾¿é(¶Î) */ +} LCUI_TextBlockRec, *LCUI_TextBlock; + +/*---------------------------------- Caret ----------------------------------*/ + +static const char *textcaret_css = ToString( +textcaret { + pointer-events: none; + width: 1px; + height:14px; + position: absolute; + background-color: #000; +} +); + +static const char *textedit_css = ToString( +textedit { +min-width: 124px; +min-height:14px; +background-color: #fff; +border: 1px solid #eee; +} +); + +static void TextCaret_BlinkShow( LCUI_Widget widget ) +{ + LCUI_TextCaret caret = widget->private_data; + if( !caret->need_show ) { + return; + } + caret->state = CARET_SHOW; + LCUITimer_Reset( caret->timer_id, caret->blink_time ); + Widget_Show( widget ); +} + +static void TextCaret_BlinkHide( LCUI_Widget widget ) +{ + LCUI_TextCaret caret = widget->private_data; + caret->state = CARET_HIDE; + LCUITimer_Reset( caret->timer_id, caret->blink_time ); + Widget_Hide( widget ); +} + +static void TextCaret_OnBlink( void *arg ) +{ + LCUI_Widget widget = arg; + LCUI_TextCaret caret = widget->private_data; + if( caret->need_show ) { + if( caret->state == CARET_HIDE ) { + caret->state = CARET_SHOW; + Widget_Show( widget ); + } else { + caret->state = CARET_HIDE; + Widget_Hide( widget ); + } + } +} + +static void TextCaret_SetVisible( LCUI_Widget widget, LCUI_BOOL visible ) +{ + LCUI_TextCaret caret = widget->private_data; + caret->need_show = visible; + if( caret->need_show ) { + TextCaret_BlinkShow( widget ); + } else { + TextCaret_BlinkHide( widget ); + } +} + +static void TextCaret_OnInit( LCUI_Widget widget ) +{ + LCUI_TextCaret caret; + caret = Widget_NewPrivateData( widget, LCUI_TextCaretRec ); + caret->type = 0; + caret->need_show = FALSE; + caret->state = CARET_HIDE; + caret->blink_time = 500; + caret->timer_id = LCUITimer_Set( caret->blink_time, + TextCaret_OnBlink, caret, TRUE ); + LCUICSS_LoadString( textcaret_css ); +} + +/** ÉèÖÃÉÁ˸µÄʱ¼ä¼ä¸ô */ +static void TextCaret_SetBlinkTime( LCUI_Widget widget, unsigned int n_ms ) +{ + LCUI_TextCaret caret = widget->private_data; + caret->blink_time = n_ms; + LCUITimer_Reset( caret->timer_id, caret->blink_time ); +} + +/** Ïú»ٲåÈë·û */ +static void TextCaret_OnDestroy( LCUI_Widget widget ) +{ + LCUI_TextCaret caret = widget->private_data; + LCUITimer_Free( caret->timer_id ); + caret->timer_id = -1; +} + +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 ); +} + +/*-------------------------------- End Caret --------------------------------*/ + +/** Òƶ¯Îı¾¿òÄڵÄÎı¾²åÈë·ûµÄÐÐÁÐ×ø±ê */ +static void TextEdit_MoveCaret( LCUI_Widget widget, int row, int col ) +{ + LCUI_Pos pos; + LCUI_TextEdit edit = widget->private_data; + TextLayer_SetCaretPos( edit->text, row, col ); + if( TextLayer_GetCaretPixelPos( edit->text, &pos ) == 0 ) { + int height = TextLayer_GetRowHeight( edit->text, row ); + LCUI_StyleSheet sheet = edit->caret->custom_style; + SetStyle( sheet, key_height, height, px ); + Widget_Move( edit->caret, pos.x, pos.y ); + } + TextCaret_BlinkShow( edit->caret ); +} + +/*------------------------------- TextBlock ---------------------------------*/ +static void TextBlock_OnDestroy( void *arg ) +{ + LCUI_TextBlock blk = arg; + free( blk->text ); + blk->text = NULL; +} + +static int TextEdit_AddTextToBuffer( LCUI_Widget widget, const wchar_t *wtext, + int add_type ) +{ + const wchar_t *p; + LCUI_TextEdit edit; + LCUI_TextBlock txtblk; + int i, j, len, tag_len, size; + + edit = widget->private_data; + len = wcslen( wtext ); + for( i = 0; i < len; ++i ) { + txtblk = NEW( LCUI_TextBlockRec, 1 ); + if( !txtblk ) { + return ENOMEM; + } + if( i == 0 ) { + txtblk->type = TEXT_BLOCK_BEGIN; + } else if( len - i > edit->block_size ) { + size = edit->block_size; + txtblk->type = TEXT_BLOCK_BODY; + } else { + size = len - i; + txtblk->type = TEXT_BLOCK_END; + } + size += 1; + txtblk->add_type = add_type; + txtblk->text = NEW( wchar_t, size ); + if( !txtblk->text ) { + return ENOMEM; + } + /* Èç¹ûδÆôÓÃÑùʽ±êǩ¹¦ÄÜ */ + if( !edit->text->is_using_style_tags ) { + for( j = 0; i < len && j < size - 1; ++j, ++i ) { + txtblk->text[j] = wtext[i]; + } + --i; + txtblk->text[j] = 0; + LinkedList_Append( &edit->text_blocks, txtblk ); + continue; + } + for( j = 0; i < len&&j < size - 1; ++j, ++i ) { + wchar_t *text; + txtblk->text[j] = wtext[i]; + /* ¼ì²âÊǷñÓÐÑùʽ±êǩ */ + p = scan_style_tag( wtext + i, NULL, 0, NULL ); + if( !p ) { + p = scan_style_ending_tag( wtext + i, NULL ); + if( !p ) { + continue; + } + } + /* ¼ÆËã±êǩµij¤¶È */ + tag_len = p - wtext - i; + /* Èôµ±ǰ¿é´óСÄܹ»ÈÝÄÉÕâ¸ö±êǩ */ + if( j + tag_len <= size - 1 ) { + continue; + } + /* ÖØÐ¼ÆËã¸ÃÎı¾¿éµĴóС£¬²¢ÖØÐ·ÖÅäÄڴæ¿ռä */ + size = j + tag_len + 1; + text = realloc( txtblk->text, sizeof(wchar_t) * size ); + if( !text ) { + return ENOMEM; + } + txtblk->text = text; + } + --i; + txtblk->text[j] = 0; + /* Ìí¼ÓÎı¾¿éÖÁ»º³åÇø */ + LinkedList_Append( &edit->text_blocks, txtblk ); + } + edit->tasks[TASK_SET_TEXT] = TRUE; + Widget_AddTask( widget, WTT_USER ); + return 0; +} + +/** ¸üÐÂÎı¾¿òÄڵÄ×ÖÌåλͼ */ +static void TextEdit_ProcTextBlock( LCUI_Widget widget, LCUI_TextBlock txtblk ) +{ + LCUI_TextEdit edit; + edit = widget->private_data; + if( edit->text_blocks.length <= 0 ) { + return; + } + switch( txtblk->add_type ) { + case TEXT_ADD_TYPE_APPEND: + /* ½«´ËÎı¾¿é׷¼ÓÖÁÎı¾ĩβ */ + TextLayer_AppendTextW( edit->text, txtblk->text, + &edit->text_tags ); + break; + case TEXT_ADD_TYPE_INSERT: + /* ½«´ËÎı¾¿é²åÈëÖÁÎı¾²åÈë·ûËùÔڴ¦ */ + TextLayer_InsertTextW( edit->text, txtblk->text, + &edit->text_tags ); + default: break; + } +} + + +/** ¸üÐÂÎı¾¿òµÄÎı¾ͼ²ã */ +static void TextEdit_UpdateTextLayer( LCUI_Widget widget ) +{ + LinkedList rects; + LCUI_TextEdit edit; + LCUI_TextLayer layer; + LinkedListNode *node; + + LinkedList_Init( &rects ); + edit = widget->private_data; + /* ¸ù¾ÝÊǷñÆôÓÃÆÁ±ηû£¬ÅжÏÐè¸üÐÂÄĸöÎı¾ͼ²ãµÄÊý¾Ý */ + if( edit->password_char ) { + layer = edit->mask_text; + } else { + layer = edit->text; + } + LinkedList_ForEach( node, &rects ) { + Widget_InvalidateArea( widget, node->data, SV_CONTENT_BOX ); + } + LinkedList_Clear( &rects, free ); + TextLayer_ClearInvalidRect( layer ); +} + +static void TextEdit_OnTask( LCUI_Widget widget ) +{ + LCUI_TextEdit edit = widget->private_data; + if( edit->tasks[TASK_SET_TEXT] ) { + LinkedList blocks; + LinkedListNode *node; + LCUIMutex_Lock( &edit->mutex ); + blocks = edit->text_blocks; + LinkedList_Init( &edit->text_blocks ); + LCUIMutex_Unlock( &edit->mutex ); + LinkedList_ForEach( node, &blocks ) { + TextEdit_ProcTextBlock( widget, node->data ); + } + LinkedList_Clear( &blocks, TextBlock_OnDestroy ); + } + TextEdit_UpdateTextLayer( widget ); +} + +/*----------------------------- End TextBlock ---------------------------------*/ + +/** ָ¶¨Îı¾¿òÊǷñ´¦Àí¿ØÖƷû */ +void TextEdit_SetUsingStyleTags( LCUI_Widget widget, LCUI_BOOL is_true ) +{ + LCUI_TextEdit edit = widget->private_data; + TextLayer_SetUsingStyleTags( edit->text, is_true ); +} + +/** ָ¶¨Îı¾¿òÊǷñÆôÓöàÐÐÎı¾ÏÔʾ */ +void TextEdit_SetMultiline( LCUI_Widget widget, LCUI_BOOL is_true ) +{ + LCUI_TextEdit edit = widget->private_data; + TextLayer_SetMultiline( edit->text, is_true ); +} + +/** Çå¿ÕÎı¾ÄÚÈÝ */ +void TextEdit_ClearText( LCUI_Widget widget ) +{ + LCUI_TextEdit edit; + Widget_Lock( widget ); + edit = widget->private_data; + LCUIMutex_Lock( &edit->mutex ); + TextLayer_ClearText( edit->text ); + StyleTags_Clear( &edit->text_tags ); + LCUIMutex_Unlock( &edit->mutex ); + Widget_InvalidateArea( widget, NULL, SV_PADDING_BOX ); + Widget_Unlock( widget ); +} + +/** ΪÎı¾¿òÉèÖÃÎı¾£¨¿í×ַû°棩 */ +int TextEdit_SetTextW( LCUI_Widget widget, const wchar_t *wstr ) +{ + TextEdit_ClearText( widget ); + return TextEdit_AddTextToBuffer( widget, wstr, TEXT_ADD_TYPE_APPEND ); +} + +int TextEdit_SetText( LCUI_Widget widget, const char *utf8_str ) +{ + int ret; + size_t len = strlen( utf8_str ) + 1; + wchar_t *wstr = malloc( len * sizeof( wchar_t ) ); + if( !wstr ) { + return ENOMEM; + } + LCUI_DecodeString( wstr, utf8_str, len, ENCODING_UTF8 ); + ret = TextEdit_SetTextW( widget, wstr ); + free( wstr ); + return ret; +} + +/** ΪÎı¾¿ò׷¼ÓÎı¾£¨¿í×ַû°棩 */ +int TextEdit_AppendTextW( LCUI_Widget widget, const wchar_t *wstr ) +{ + return TextEdit_AddTextToBuffer( widget, wstr, TEXT_ADD_TYPE_APPEND ); +} + +/** ΪÎı¾¿ò²åÈëÎı¾£¨¿í×ַû°棩 */ +int TextEdit_InsertTextW( LCUI_Widget widget, const wchar_t *wstr ) +{ + return TextEdit_AddTextToBuffer( widget, wstr, TEXT_ADD_TYPE_INSERT ); +} + +static void TextEdit_OnFocus( LCUI_Widget widget, LCUI_WidgetEvent e, void *arg ) +{ + LCUI_TextEdit edit; + edit = widget->private_data; + /* É趨ÊäÈ뷨µÄĿ±ê */ + LCUIIME_SetTarget( widget ); + TextCaret_SetVisible( edit->caret, TRUE ); + TextCaret_BlinkHide( edit->caret ); +} + +static void TextEdit_OnBlur( LCUI_Widget widget, LCUI_WidgetEvent e, void *arg ) +{ + LCUI_TextEdit edit; + edit = widget->private_data; + LCUIIME_ClearTarget(); + TextCaret_SetVisible( edit->caret, TRUE ); +} + +static void TextEdit_TextBackspace( LCUI_Widget widget, int n_ch ) +{ + LCUI_TextEdit edit; + Widget_Lock( widget ); + edit = widget->private_data; + LCUIMutex_Lock( &edit->mutex ); + TextLayer_Backspace( edit->text, n_ch ); + TextCaret_BlinkShow( edit->caret ); + LCUIMutex_Unlock( &edit->mutex ); + Widget_Unlock( widget ); +} + +static void TextEdit_TextDelete(LCUI_Widget widget, int n_ch ) +{ + LCUI_TextEdit edit; + Widget_Lock( widget ); + edit = widget->private_data; + LCUIMutex_Lock( &edit->mutex ); + TextLayer_Delete( edit->text, n_ch ); + TextCaret_BlinkShow( edit->caret ); + LCUIMutex_Unlock( &edit->mutex ); + Widget_Unlock( widget ); +} + +/** ´¦Àí°´¼üʼþ */ +static void TextEdit_OnKeyDown( LCUI_Widget widget, LCUI_WidgetEvent e, void *arg ) +{ + LCUI_TextEdit edit; + int cols, rows, cur_col, cur_row; + + edit = widget->private_data; + cur_row = edit->text->insert_y; + cur_col = edit->text->insert_x; + cols = TextLayer_GetRowTextLength( edit->text, cur_row ); + rows = TextLayer_GetRowTotal( edit->text ); + switch( e->key.code ) { + case LCUIKEY_HOMEPAGE: // home¼üÒƶ¯¹â±êÖÁÐÐÊ× + cur_col = 0; + break; + case LCUIKEY_END: // end¼üÒƶ¯¹â±êÖÁÐÐβ + cur_col = cols; + break; + case LCUIKEY_LEFT: + if( cur_col > 0 ) { + --cur_col; + } else if( cur_row > 0 ) { + --cur_row; + cur_col = TextLayer_GetRowTextLength( edit->text, + cur_row ); + } + break; + case LCUIKEY_RIGHT: + if( cur_col < cols ) { + ++cur_col; + } else if( cur_row < rows - 1 ) { + ++cur_row; + cur_col = 0; + } + break; + case LCUIKEY_UP: + if( cur_row > 0 ) { + --cur_row; + } + break; + case LCUIKEY_DOWN: + if( cur_row < rows - 1 ) { + ++cur_row; + } + break; + case LCUIKEY_BACKSPACE: // ɾ³ý¹â±ê×ó±ߵÄ×ַû + TextEdit_TextBackspace( widget, 1 ); + break; + case LCUIKEY_DELETE: // ɾ³ý¹â±êÓұߵÄ×ַû + TextEdit_TextDelete( widget, 1 ); + break; + default:break; + } + TextEdit_MoveCaret( widget, cur_row, cur_col ); +} + +/** ´¦ÀíÊäÈ뷨¶ÔÎı¾¿òÊäÈëµÄÄÚÈÝ */ +static void TextEdit_OnInput( LCUI_Widget widget, LCUI_WidgetEvent e, void *arg ) +{ + uint_t i; + LCUI_TextEdit edit; + wchar_t *ptr, *tmp_ptr, *ptr_last; + + ptr = e->input.text; + edit = widget->private_data; + ptr_last = ptr + sizeof( e->input.text ) / sizeof( wchar_t ); + /* Èç¹ûÎı¾¿òÊÇֻ¶ÁµÄ */ + if( edit->read_only ) { + return; + } + for( ; ptr < ptr_last && *ptr != '\0'; ++ptr ) { + if( edit->allow_input_char ) { + /* Åжϵ±ǰ×ַûÊǷñΪÏÞÖƷ¶ΧÄڵÄ×ַû */ + for( i = 0; i < edit->allow_input_char[i]; ++i ) { + if( edit->allow_input_char[i] == *ptr ) { + break; + } + } + /* Èç¹ûÒÑÌáǰ½áÊøѭ»·£¬Ôò±íÃ÷µ±ǰ×ַûÊÇÔÊÐíµÄ */ + if( edit->allow_input_char[i] ) { + continue; + } + } else { + continue; + } + /* ·ñÔò²»ÊÇÔÊÐíµÄ×ַû£¬ÐèÒƳý¸Ã×ַû */ + tmp_ptr = ptr; + while( tmp_ptr < ptr_last && *tmp_ptr != '\0' ) { + *tmp_ptr = *(tmp_ptr + 1); + ++tmp_ptr; + } + } + TextEdit_InsertTextW( widget, e->input.text ); +} + +static void TextEdit_OnInit( LCUI_Widget widget ) +{ + LCUI_TextEdit edit; + edit = Widget_NewPrivateData( widget, LCUI_TextEditRec ); + edit->read_only = FALSE; + edit->text = TextLayer_New(); + edit->allow_input_char = NULL; + edit->show_placeholder = FALSE; + edit->mask_text = TextLayer_New(); + edit->block_size = TEXT_BLOCK_SIZE; + edit->caret = LCUIWidget_New( "textcaret" ); + TextLayer_SetUsingStyleTags( edit->text, FALSE ); + TextEdit_SetMultiline( widget, FALSE ); + LinkedList_Init( &edit->text_blocks ); + Widget_Append( widget, edit->caret ); + TextLayer_SetAutoWrap( edit->text, TRUE ); + TextLayer_SetAutoWrap( edit->mask_text, TRUE ); + Widget_BindEvent( widget, "keydown", TextEdit_OnKeyDown, NULL, NULL ); + Widget_BindEvent( widget, "input", TextEdit_OnInput, NULL, NULL ); + Widget_BindEvent( widget, "focus", TextEdit_OnFocus, NULL, NULL ); + Widget_BindEvent( widget, "blur", TextEdit_OnBlur, NULL, NULL ); + LCUIMutex_Init( &edit->mutex ); +} + +static void TextEdit_OnDestroy( LCUI_Widget widget ) +{ + LCUI_TextEdit edit = widget->private_data; + TextLayer_Destroy( edit->text ); + TextLayer_Destroy( edit->mask_text ); + LinkedList_Clear( &edit->text_blocks, TextBlock_OnDestroy ); +} + +static void TextEdit_OnResize( LCUI_Widget w, LCUI_WidgetEvent e, void *arg ) +{ + LinkedList rects; + LinkedListNode *node; + LCUI_Size new_size = {16, 16}; + LCUI_TextEdit edit = w->private_data; + if( w->box.content.width > new_size.w ) { + new_size.w = w->box.content.width; + } + if( w->box.content.height > new_size.h ) { + new_size.h = w->box.content.height; + } + LinkedList_Init( &rects ); + TextLayer_SetMaxSize( edit->text, new_size ); + TextLayer_Update( edit->text, &rects ); + LinkedList_ForEach( node, &rects ) { + Widget_InvalidateArea( w, node->data, SV_CONTENT_BOX ); + } + LinkedList_Clear( &rects, free ); + TextLayer_ClearInvalidRect( edit->text ); +} + +static void TextEdit_OnPaint( LCUI_Widget w, LCUI_PaintContext paint ) +{ + LCUI_TextEdit edit; + LCUI_Pos layer_pos; + LCUI_TextLayer layer; + LCUI_Rect content_rect, rect; + + edit = w->private_data; + content_rect.width = w->box.content.width; + content_rect.height = w->box.content.height; + content_rect.y = w->box.content.top - w->box.graph.top; + content_rect.x = w->box.content.left - w->box.graph.left; + LCUIRect_GetOverlayRect( &content_rect, &paint->rect, &rect ); + layer_pos.x = content_rect.x - paint->rect.x; + layer_pos.y = content_rect.y - paint->rect.y; + rect.x -= content_rect.x; + rect.y -= content_rect.y; + if( edit->password_char ) { + layer = edit->mask_text; + } else { + layer = edit->text; + } + TextLayer_DrawToGraph( layer, rect, layer_pos, &paint->canvas ); +} + + +/** Ìí¼Ó TextEdit ²¿¼þÀàÐÍ */ +void LCUIWidget_AddTextEdit( void ) +{ + LCUI_WidgetClass *wc = LCUIWidget_AddClass( "textedit" ); + wc->methods.init = TextEdit_OnInit; + wc->methods.paint = TextEdit_OnPaint; + wc->methods.destroy = TextEdit_OnDestroy; + wc->methods.set_text = TextEdit_SetText; + wc->task_handler = TextEdit_OnTask; + LCUICSS_LoadString( textedit_css ); + LCUIWidget_AddTextCaret(); +} diff --git a/src/gui/widget/textview.c b/src/gui/widget/textview.c index ad5787ce..ba188d63 100644 --- a/src/gui/widget/textview.c +++ b/src/gui/widget/textview.c @@ -332,7 +332,7 @@ static void TextView_OnDestroy( LCUI_Widget w ) { LCUI_TextView *txt; txt = w->private_data; - TextLayer_Destroy( &txt->layer ); + TextLayer_Destroy( txt->layer ); } static void TextView_AutoSize( LCUI_Widget w, int *width, int *height ) From 28c02b59f4889667eb0ce2a07eb395f637de4d55 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Wed, 15 Jun 2016 23:21:26 +0800 Subject: [PATCH 048/124] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20LCUI=5FWidgetEvent?= =?UTF-8?q?=20=E7=9A=84=E7=94=A8=E6=B3=95=E3=80=81=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E9=83=A8=E4=BB=B6=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/util/linkedlist.h | 7 +++---- src/gui/widget/scrollbar.c | 14 +++++++------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/include/LCUI/util/linkedlist.h b/include/LCUI/util/linkedlist.h index 725c0dc2..587b7627 100644 --- a/include/LCUI/util/linkedlist.h +++ b/include/LCUI/util/linkedlist.h @@ -61,9 +61,6 @@ struct LinkedListRec_ { #define LinkedList_ForEachReverse(node, list) \ for( node = (list)->tail.prev; node && node != &(list)->head; node = node->prev ) -#define LinkedList_Clear(list, func) LinkedList_ClearEx( list, func, 1 ) -#define LinkedList_ClearData(list, func) LinkedList_ClearEx( list, func, 0 ) - LCUI_API LinkedListNode *LinkedList_Append( LinkedList *list, void *data ); LCUI_API LinkedListNode *LinkedList_Insert( LinkedList *list, int pos, void *data ); LCUI_API LinkedListNode *LinkedList_GetNode( LinkedList *list, int pos ); @@ -74,10 +71,12 @@ LCUI_API void LinkedList_Link( LinkedList *list, LinkedListNode *cur, LinkedList LCUI_API void LinkedList_Delete( LinkedList *list, int pos ); LCUI_API void LinkedList_DeleteNode( LinkedList *list, LinkedListNode *node ); LCUI_API void LinkedList_AppendNode( LinkedList *list, LinkedListNode *node ); -LCUI_API void LinkedList_Sort( LinkedList *list, void(*on_sort)(void*, void*) ); LCUI_API void LinkedList_ClearEx( LinkedList *list, void(*on_destroy)(void*), int free_node ); LCUI_API void LinkedList_Concat( LinkedList *list1, LinkedList *list2 ); +#define LinkedList_Clear(list, func) LinkedList_ClearEx( list, func, 1 ) +#define LinkedList_ClearData(list, func) LinkedList_ClearEx( list, func, 0 ) + LCUI_END_HEADER #endif diff --git a/src/gui/widget/scrollbar.c b/src/gui/widget/scrollbar.c index e9a98450..f2da4604 100644 --- a/src/gui/widget/scrollbar.c +++ b/src/gui/widget/scrollbar.c @@ -279,8 +279,8 @@ static void Slider_OnMouseDown( LCUI_Widget slider, } scrollbar->slider_x = slider->x; scrollbar->slider_y = slider->y; - scrollbar->mouse_x = e->screen_x; - scrollbar->mouse_y = e->screen_y; + scrollbar->mouse_x = e->motion.x; + scrollbar->mouse_y = e->motion.y; scrollbar->is_dragging = TRUE; Widget_SetMouseCapture( slider ); Widget_BindEvent( slider, "mousemove", Slider_OnMouseMove, w, NULL ); @@ -362,7 +362,7 @@ static void ScrollLayer_OnWheel( LCUI_Widget layer, LCUI_WidgetEvent e, void *ar LCUI_Widget w = e->data; LCUI_ScrollBar scrollbar = w->private_data; int pos = ScrollBar_GetPosition( w ); - if( e->z_delta > 0 ) { + if( e->wheel.delta > 0 ) { pos -= scrollbar->scroll_step; } else { pos += scrollbar->scroll_step; @@ -377,12 +377,12 @@ static void ScrollLayer_OnTouch( LCUI_Widget layer, LCUI_WidgetEvent e, void *ar LCUI_TouchPoint point; LCUI_Widget w = e->data; LCUI_ScrollBar scrollbar; - if( e->n_points < 1 ) { + if( e->touch.n_points < 1 ) { return; } scrollbar = w->private_data; if( scrollbar->touch_point_id == -1 ) { - point = &e->points[0]; + point = &e->touch.points[0]; /* 如果这个触点的状态不是 TOUCHDOWN,则说明是上次触控拖拽操 * 作时的多余触点,直接忽略这次触控事件 */ if( point->state != WET_TOUCHDOWN ) { @@ -390,8 +390,8 @@ static void ScrollLayer_OnTouch( LCUI_Widget layer, LCUI_WidgetEvent e, void *ar } scrollbar->touch_point_id = point->id; } else { - for( point = NULL, i = 0; i < e->n_points; ++i ) { - point = &e->points[i]; + for( point = NULL, i = 0; i < e->touch.n_points; ++i ) { + point = &e->touch.points[i]; if( point->id == scrollbar->touch_point_id ) { break; } From 8c0543e1d9a92dc59ca89f18751f20f50f5beafe Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Thu, 16 Jun 2016 23:47:59 +0800 Subject: [PATCH 049/124] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20Widget=5FUnwrap()?= =?UTF-8?q?=20=E5=87=BD=E6=95=B0=E3=80=81=E4=BF=AE=E5=A4=8D=20textedit=20?= =?UTF-8?q?=E9=83=A8=E4=BB=B6=E4=B8=AD=E5=AD=98=E5=9C=A8=E7=9A=84=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=20BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gui/widget/textedit.c | 166 +++++++++++++++++++------------------- src/gui/widget_base.c | 23 +++++- src/gui/widget_style.c | 2 +- 3 files changed, 103 insertions(+), 88 deletions(-) diff --git a/src/gui/widget/textedit.c b/src/gui/widget/textedit.c index fac67bee..d051907a 100644 --- a/src/gui/widget/textedit.c +++ b/src/gui/widget/textedit.c @@ -1,4 +1,4 @@ -/* *************************************************************************** +/* *************************************************************************** * textedit.c -- textedit widget, used to allow user edit text. * * Copyright (C) 2016 by Liu Chao @@ -20,21 +20,21 @@ * ****************************************************************************/ /* **************************************************************************** - * textedit.c -- Îı¾±༭²¿¼þ£¬ÓÃÓÚÈÃÓû§±༭Îı¾¡£ + * textedit.c -- 文本编辑部件,用于让用户编辑文本。 * - * °æȨËùÓÐ (C) 2016 ¹éÊôÓÚ Áõ³¬ + * 版权所有 (C) 2016 归属于 刘超 * - * Õâ¸öÎļþÊÇLCUIÏîĿµÄһ²¿·֣¬²¢ÇÒֻ¿ÉÒԸù¾ÝGPLv2Ðí¿ÉЭÒéÀ´ʹÓᢸü¸ĺͷ¢²¼¡£ + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 * - * (GPLv2 ÊÇ GNUͨÓù«¹²Ðí¿É֤µڶþ°æ µÄӢÎÄËõд) + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) * - * ¼ÌÐøʹÓá¢Ð޸Ļ򷢲¼±¾Îļþ£¬±íÃ÷ÄúÒѾ­ÔĶÁ²¢ÍêȫÀí½âºͽÓÊÜÕâ¸öÐí¿ÉЭÒ顣 + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 * - * LCUI ÏîĿÊǻùÓÚʹÓÃĿµĶø¼ÓÒÔɢ²¼µģ¬µ«²»¸ºÈκε£±£ÔðÈΣ¬ÉõÖÁûÓÐÊÊÏúÐԻòÌØ - * ¶¨ÓÃ;µÄÒþº¬µ£±££¬ÏêÇéÇë²ÎÕÕGPLv2Ðí¿ÉЭÒ顣 + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 * - * ÄúӦÒÑÊյ½¸½ËæÓڱ¾ÎļþµÄGPLv2Ðí¿ÉЭÒéµĸ±±¾£¬Ëüͨ³£ÔÚLICENSE.TXTÎļþÖУ¬Èç¹û - * ûÓУ¬Çë²鿴£º. + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. * ****************************************************************************/ //#define DEBUG @@ -58,32 +58,32 @@ enum TaskType { TASK_TOTAL }; -/** Îı¾²åÈë·ûÏà¹ØÊý¾Ý */ +/** 文本插入符相关数据 */ typedef struct LCUI_TextCaretRec_ { int type; - int state; /**< µ±ǰ״̬ */ - int blink_time; /**< ÉÁ˸¼ä¸ô */ - int timer_id; /**< ¶¨ʱÆ÷ */ + int state; /**< 当前状态 */ + int blink_time; /**< 闪烁间隔 */ + int timer_id; /**< 定时器 */ LCUI_BOOL need_show; } LCUI_TextCaretRec, *LCUI_TextCaret; typedef struct LCUI_TextEditRec_ { - LCUI_TextLayer text; /**< ʵ¼ÊÎı¾ */ - LCUI_TextLayer mask_text; /**< ÆÁ±κóµÄÎı¾ */ - LCUI_Widget scrollbar[2]; /**< Á½¸ö¹ö¶¯Ìõ */ - LCUI_Widget caret; /**< Îı¾²åÈë·û */ - LCUI_BOOL read_only; /**< ÊǷñֻ¶Á */ - int block_size; /**< ¿é´óС */ - LinkedList text_blocks; /**< Îı¾¿黺³åÇø */ - LinkedList text_tags; /**< µ±ǰ´¦ÀíµıêǩÁбí */ - LCUI_BOOL show_placeholder; /**< ±íʾռλ·ûÊǷñÒѾ­ÏÔʾ */ - wchar_t *placeholder; /**< Îı¾¿òµÄռλ·û */ - wchar_t *allow_input_char; /**< ÔÊÐíÊäÈëµÄ×ַû */ - wchar_t password_char; /**< ÆÁ±ηûµĸ±±¾ */ - LCUI_TextStyle placeholder_style; /**< ռλ·ûµÄÎı¾Ñùʽ */ - LCUI_TextStyle textstyle_bak; /**< Îı¾¿òÄÚÎı¾Ñùʽµĸ±±¾ */ - LCUI_BOOL tasks[TASK_TOTAL]; /**< ´ý´¦ÀíµÄÈÎÎñ */ - LCUI_Mutex mutex; /**< »¥³âËø */ + LCUI_TextLayer text; /**< 实际文本 */ + LCUI_TextLayer mask_text; /**< 屏蔽后的文本 */ + LCUI_Widget scrollbar[2]; /**< 两个滚动条 */ + LCUI_Widget caret; /**< 文本插入符 */ + LCUI_BOOL read_only; /**< 是否只读 */ + int block_size; /**< 块大小 */ + LinkedList text_blocks; /**< 文本块缓冲区 */ + LinkedList text_tags; /**< 当前处理的标签列表 */ + LCUI_BOOL show_placeholder; /**< 表示占位符是否已经显示 */ + wchar_t *placeholder; /**< 文本框的占位符 */ + wchar_t *allow_input_char; /**< 允许输入的字符 */ + wchar_t password_char; /**< 屏蔽符的副本 */ + LCUI_TextStyle placeholder_style; /**< 占位符的文本样式 */ + LCUI_TextStyle textstyle_bak; /**< 文本框内文本样式的副本 */ + LCUI_BOOL tasks[TASK_TOTAL]; /**< 待处理的任务 */ + LCUI_Mutex mutex; /**< 互斥锁 */ } LCUI_TextEditRec, *LCUI_TextEdit; enum TextBlockType_ { @@ -92,11 +92,11 @@ enum TextBlockType_ { TEXT_BLOCK_END }; -/** Îı¾¿éÊý¾ݽṹ */ +/** 文本块数据结构 */ typedef struct LCUI_TextBlockRec_ { - int type; /**< Îı¾¿éÀàÐÍ */ - int add_type; /**< ָ¶¨¸ÃÎı¾¿éµÄÌí¼ӷ½ʽ */ - wchar_t *text; /**< Îı¾¿é(¶Î) */ + int type; /**< 文本块类型 */ + int add_type; /**< 指定该文本块的添加方式 */ + wchar_t *text; /**< 文本块(段) */ } LCUI_TextBlockRec, *LCUI_TextBlock; /*---------------------------------- Caret ----------------------------------*/ @@ -117,6 +117,7 @@ min-width: 124px; min-height:14px; background-color: #fff; border: 1px solid #eee; +padding: 4px; } ); @@ -174,11 +175,11 @@ static void TextCaret_OnInit( LCUI_Widget widget ) caret->state = CARET_HIDE; caret->blink_time = 500; caret->timer_id = LCUITimer_Set( caret->blink_time, - TextCaret_OnBlink, caret, TRUE ); + TextCaret_OnBlink, widget, TRUE ); LCUICSS_LoadString( textcaret_css ); } -/** ÉèÖÃÉÁ˸µÄʱ¼ä¼ä¸ô */ +/** 设置闪烁的时间间隔 */ static void TextCaret_SetBlinkTime( LCUI_Widget widget, unsigned int n_ms ) { LCUI_TextCaret caret = widget->private_data; @@ -186,7 +187,7 @@ static void TextCaret_SetBlinkTime( LCUI_Widget widget, unsigned int n_ms ) LCUITimer_Reset( caret->timer_id, caret->blink_time ); } -/** Ïú»ٲåÈë·û */ +/** 销毁插入符 */ static void TextCaret_OnDestroy( LCUI_Widget widget ) { LCUI_TextCaret caret = widget->private_data; @@ -204,7 +205,7 @@ static void LCUIWidget_AddTextCaret( void ) /*-------------------------------- End Caret --------------------------------*/ -/** Òƶ¯Îı¾¿òÄڵÄÎı¾²åÈë·ûµÄÐÐÁÐ×ø±ê */ +/** 移动文本框内的文本插入符的行列坐标 */ static void TextEdit_MoveCaret( LCUI_Widget widget, int row, int col ) { LCUI_Pos pos; @@ -225,6 +226,7 @@ static void TextBlock_OnDestroy( void *arg ) LCUI_TextBlock blk = arg; free( blk->text ); blk->text = NULL; + free( blk ); } static int TextEdit_AddTextToBuffer( LCUI_Widget widget, const wchar_t *wtext, @@ -240,24 +242,23 @@ static int TextEdit_AddTextToBuffer( LCUI_Widget widget, const wchar_t *wtext, for( i = 0; i < len; ++i ) { txtblk = NEW( LCUI_TextBlockRec, 1 ); if( !txtblk ) { - return ENOMEM; + return -ENOMEM; } + size = edit->block_size; if( i == 0 ) { txtblk->type = TEXT_BLOCK_BEGIN; } else if( len - i > edit->block_size ) { - size = edit->block_size; txtblk->type = TEXT_BLOCK_BODY; } else { size = len - i; txtblk->type = TEXT_BLOCK_END; } - size += 1; txtblk->add_type = add_type; txtblk->text = NEW( wchar_t, size ); if( !txtblk->text ) { - return ENOMEM; + return -ENOMEM; } - /* Èç¹ûδÆôÓÃÑùʽ±êǩ¹¦ÄÜ */ + /* 如果未启用样式标签功能 */ if( !edit->text->is_using_style_tags ) { for( j = 0; i < len && j < size - 1; ++j, ++i ) { txtblk->text[j] = wtext[i]; @@ -267,10 +268,10 @@ static int TextEdit_AddTextToBuffer( LCUI_Widget widget, const wchar_t *wtext, LinkedList_Append( &edit->text_blocks, txtblk ); continue; } - for( j = 0; i < len&&j < size - 1; ++j, ++i ) { + for( j = 0; i < len && j < size - 1; ++j, ++i ) { wchar_t *text; txtblk->text[j] = wtext[i]; - /* ¼ì²âÊǷñÓÐÑùʽ±êǩ */ + /* 检测是否有样式标签 */ p = scan_style_tag( wtext + i, NULL, 0, NULL ); if( !p ) { p = scan_style_ending_tag( wtext + i, NULL ); @@ -278,23 +279,23 @@ static int TextEdit_AddTextToBuffer( LCUI_Widget widget, const wchar_t *wtext, continue; } } - /* ¼ÆËã±êǩµij¤¶È */ + /* 计算标签的长度 */ tag_len = p - wtext - i; - /* Èôµ±ǰ¿é´óСÄܹ»ÈÝÄÉÕâ¸ö±êǩ */ + /* 若当前块大小能够容纳这个标签 */ if( j + tag_len <= size - 1 ) { continue; } - /* ÖØÐ¼ÆËã¸ÃÎı¾¿éµĴóС£¬²¢ÖØÐ·ÖÅäÄڴæ¿ռä */ + /* 重新计算该文本块的大小,并重新分配内存空间 */ size = j + tag_len + 1; - text = realloc( txtblk->text, sizeof(wchar_t) * size ); + text = realloc( txtblk->text, sizeof( wchar_t ) * size ); if( !text ) { - return ENOMEM; + return -ENOMEM; } txtblk->text = text; } --i; txtblk->text[j] = 0; - /* Ìí¼ÓÎı¾¿éÖÁ»º³åÇø */ + /* 添加文本块至缓冲区 */ LinkedList_Append( &edit->text_blocks, txtblk ); } edit->tasks[TASK_SET_TEXT] = TRUE; @@ -302,22 +303,19 @@ static int TextEdit_AddTextToBuffer( LCUI_Widget widget, const wchar_t *wtext, return 0; } -/** ¸üÐÂÎı¾¿òÄڵÄ×ÖÌåλͼ */ +/** 更新文本框内的字体位图 */ static void TextEdit_ProcTextBlock( LCUI_Widget widget, LCUI_TextBlock txtblk ) { LCUI_TextEdit edit; edit = widget->private_data; - if( edit->text_blocks.length <= 0 ) { - return; - } switch( txtblk->add_type ) { case TEXT_ADD_TYPE_APPEND: - /* ½«´ËÎı¾¿é׷¼ÓÖÁÎı¾ĩβ */ + /* 将此文本块追加至文本末尾 */ TextLayer_AppendTextW( edit->text, txtblk->text, &edit->text_tags ); break; case TEXT_ADD_TYPE_INSERT: - /* ½«´ËÎı¾¿é²åÈëÖÁÎı¾²åÈë·ûËùÔڴ¦ */ + /* 将此文本块插入至文本插入符所在处 */ TextLayer_InsertTextW( edit->text, txtblk->text, &edit->text_tags ); default: break; @@ -325,7 +323,7 @@ static void TextEdit_ProcTextBlock( LCUI_Widget widget, LCUI_TextBlock txtblk ) } -/** ¸üÐÂÎı¾¿òµÄÎı¾ͼ²ã */ +/** 更新文本框的文本图层 */ static void TextEdit_UpdateTextLayer( LCUI_Widget widget ) { LinkedList rects; @@ -335,7 +333,7 @@ static void TextEdit_UpdateTextLayer( LCUI_Widget widget ) LinkedList_Init( &rects ); edit = widget->private_data; - /* ¸ù¾ÝÊǷñÆôÓÃÆÁ±ηû£¬ÅжÏÐè¸üÐÂÄĸöÎı¾ͼ²ãµÄÊý¾Ý */ + /* 根据是否启用屏蔽符,判断需更新哪个文本图层的数据 */ if( edit->password_char ) { layer = edit->mask_text; } else { @@ -354,9 +352,9 @@ static void TextEdit_OnTask( LCUI_Widget widget ) if( edit->tasks[TASK_SET_TEXT] ) { LinkedList blocks; LinkedListNode *node; + LinkedList_Init( &blocks ); LCUIMutex_Lock( &edit->mutex ); - blocks = edit->text_blocks; - LinkedList_Init( &edit->text_blocks ); + LinkedList_Concat( &blocks, &edit->text_blocks ); LCUIMutex_Unlock( &edit->mutex ); LinkedList_ForEach( node, &blocks ) { TextEdit_ProcTextBlock( widget, node->data ); @@ -368,21 +366,21 @@ static void TextEdit_OnTask( LCUI_Widget widget ) /*----------------------------- End TextBlock ---------------------------------*/ -/** ָ¶¨Îı¾¿òÊǷñ´¦Àí¿ØÖƷû */ +/** 指定文本框是否处理控制符 */ void TextEdit_SetUsingStyleTags( LCUI_Widget widget, LCUI_BOOL is_true ) { LCUI_TextEdit edit = widget->private_data; TextLayer_SetUsingStyleTags( edit->text, is_true ); } -/** ָ¶¨Îı¾¿òÊǷñÆôÓöàÐÐÎı¾ÏÔʾ */ +/** 指定文本框是否启用多行文本显示 */ void TextEdit_SetMultiline( LCUI_Widget widget, LCUI_BOOL is_true ) { LCUI_TextEdit edit = widget->private_data; TextLayer_SetMultiline( edit->text, is_true ); } -/** Çå¿ÕÎı¾ÄÚÈÝ */ +/** 清空文本内容 */ void TextEdit_ClearText( LCUI_Widget widget ) { LCUI_TextEdit edit; @@ -396,7 +394,7 @@ void TextEdit_ClearText( LCUI_Widget widget ) Widget_Unlock( widget ); } -/** ΪÎı¾¿òÉèÖÃÎı¾£¨¿í×ַû°棩 */ +/** 为文本框设置文本(宽字符版) */ int TextEdit_SetTextW( LCUI_Widget widget, const wchar_t *wstr ) { TextEdit_ClearText( widget ); @@ -409,7 +407,7 @@ int TextEdit_SetText( LCUI_Widget widget, const char *utf8_str ) size_t len = strlen( utf8_str ) + 1; wchar_t *wstr = malloc( len * sizeof( wchar_t ) ); if( !wstr ) { - return ENOMEM; + return -ENOMEM; } LCUI_DecodeString( wstr, utf8_str, len, ENCODING_UTF8 ); ret = TextEdit_SetTextW( widget, wstr ); @@ -417,13 +415,13 @@ int TextEdit_SetText( LCUI_Widget widget, const char *utf8_str ) return ret; } -/** ΪÎı¾¿ò׷¼ÓÎı¾£¨¿í×ַû°棩 */ +/** 为文本框追加文本(宽字符版) */ int TextEdit_AppendTextW( LCUI_Widget widget, const wchar_t *wstr ) { return TextEdit_AddTextToBuffer( widget, wstr, TEXT_ADD_TYPE_APPEND ); } -/** ΪÎı¾¿ò²åÈëÎı¾£¨¿í×ַû°棩 */ +/** 为文本框插入文本(宽字符版) */ int TextEdit_InsertTextW( LCUI_Widget widget, const wchar_t *wstr ) { return TextEdit_AddTextToBuffer( widget, wstr, TEXT_ADD_TYPE_INSERT ); @@ -433,7 +431,7 @@ static void TextEdit_OnFocus( LCUI_Widget widget, LCUI_WidgetEvent e, void *arg { LCUI_TextEdit edit; edit = widget->private_data; - /* É趨ÊäÈ뷨µÄĿ±ê */ + /* 设定输入法的目标 */ LCUIIME_SetTarget( widget ); TextCaret_SetVisible( edit->caret, TRUE ); TextCaret_BlinkHide( edit->caret ); @@ -471,7 +469,7 @@ static void TextEdit_TextDelete(LCUI_Widget widget, int n_ch ) Widget_Unlock( widget ); } -/** ´¦Àí°´¼üʼþ */ +/** 处理按键事件 */ static void TextEdit_OnKeyDown( LCUI_Widget widget, LCUI_WidgetEvent e, void *arg ) { LCUI_TextEdit edit; @@ -483,10 +481,10 @@ static void TextEdit_OnKeyDown( LCUI_Widget widget, LCUI_WidgetEvent e, void *ar cols = TextLayer_GetRowTextLength( edit->text, cur_row ); rows = TextLayer_GetRowTotal( edit->text ); switch( e->key.code ) { - case LCUIKEY_HOMEPAGE: // home¼üÒƶ¯¹â±êÖÁÐÐÊ× + case LCUIKEY_HOMEPAGE: // home键移动光标至行首 cur_col = 0; break; - case LCUIKEY_END: // end¼üÒƶ¯¹â±êÖÁÐÐβ + case LCUIKEY_END: // end键移动光标至行尾 cur_col = cols; break; case LCUIKEY_LEFT: @@ -516,10 +514,10 @@ static void TextEdit_OnKeyDown( LCUI_Widget widget, LCUI_WidgetEvent e, void *ar ++cur_row; } break; - case LCUIKEY_BACKSPACE: // ɾ³ý¹â±ê×ó±ߵÄ×ַû + case LCUIKEY_BACKSPACE: // 删除光标左边的字符 TextEdit_TextBackspace( widget, 1 ); break; - case LCUIKEY_DELETE: // ɾ³ý¹â±êÓұߵÄ×ַû + case LCUIKEY_DELETE: // 删除光标右边的字符 TextEdit_TextDelete( widget, 1 ); break; default:break; @@ -527,7 +525,7 @@ static void TextEdit_OnKeyDown( LCUI_Widget widget, LCUI_WidgetEvent e, void *ar TextEdit_MoveCaret( widget, cur_row, cur_col ); } -/** ´¦ÀíÊäÈ뷨¶ÔÎı¾¿òÊäÈëµÄÄÚÈÝ */ +/** 处理输入法对文本框输入的内容 */ static void TextEdit_OnInput( LCUI_Widget widget, LCUI_WidgetEvent e, void *arg ) { uint_t i; @@ -537,26 +535,26 @@ static void TextEdit_OnInput( LCUI_Widget widget, LCUI_WidgetEvent e, void *arg ptr = e->input.text; edit = widget->private_data; ptr_last = ptr + sizeof( e->input.text ) / sizeof( wchar_t ); - /* Èç¹ûÎı¾¿òÊÇֻ¶ÁµÄ */ + /* 如果文本框是只读的 */ if( edit->read_only ) { return; } for( ; ptr < ptr_last && *ptr != '\0'; ++ptr ) { if( edit->allow_input_char ) { - /* Åжϵ±ǰ×ַûÊǷñΪÏÞÖƷ¶ΧÄڵÄ×ַû */ + /* 判断当前字符是否为限制范围内的字符 */ for( i = 0; i < edit->allow_input_char[i]; ++i ) { if( edit->allow_input_char[i] == *ptr ) { break; } } - /* Èç¹ûÒÑÌáǰ½áÊøѭ»·£¬Ôò±íÃ÷µ±ǰ×ַûÊÇÔÊÐíµÄ */ + /* 如果已提前结束循环,则表明当前字符是允许的 */ if( edit->allow_input_char[i] ) { continue; } } else { continue; } - /* ·ñÔò²»ÊÇÔÊÐíµÄ×ַû£¬ÐèÒƳý¸Ã×ַû */ + /* 否则不是允许的字符,需移除该字符 */ tmp_ptr = ptr; while( tmp_ptr < ptr_last && *tmp_ptr != '\0' ) { *tmp_ptr = *(tmp_ptr + 1); @@ -577,16 +575,18 @@ static void TextEdit_OnInit( LCUI_Widget widget ) edit->mask_text = TextLayer_New(); edit->block_size = TEXT_BLOCK_SIZE; edit->caret = LCUIWidget_New( "textcaret" ); - TextLayer_SetUsingStyleTags( edit->text, FALSE ); - TextEdit_SetMultiline( widget, FALSE ); LinkedList_Init( &edit->text_blocks ); - Widget_Append( widget, edit->caret ); + StyleTags_Init( &edit->text_tags ); + TextEdit_SetMultiline( widget, FALSE ); TextLayer_SetAutoWrap( edit->text, TRUE ); TextLayer_SetAutoWrap( edit->mask_text, TRUE ); + TextLayer_SetUsingStyleTags( edit->text, FALSE ); Widget_BindEvent( widget, "keydown", TextEdit_OnKeyDown, NULL, NULL ); Widget_BindEvent( widget, "input", TextEdit_OnInput, NULL, NULL ); Widget_BindEvent( widget, "focus", TextEdit_OnFocus, NULL, NULL ); Widget_BindEvent( widget, "blur", TextEdit_OnBlur, NULL, NULL ); + Widget_Append( widget, edit->caret ); + Widget_Hide( edit->caret ); LCUIMutex_Init( &edit->mutex ); } @@ -646,7 +646,7 @@ static void TextEdit_OnPaint( LCUI_Widget w, LCUI_PaintContext paint ) } -/** Ìí¼Ó TextEdit ²¿¼þÀàÐÍ */ +/** 添加 TextEdit 部件类型 */ void LCUIWidget_AddTextEdit( void ) { LCUI_WidgetClass *wc = LCUIWidget_AddClass( "textedit" ); diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index 16534e1e..5fe95a8f 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -132,6 +132,7 @@ int Widget_Append( LCUI_Widget parent, LCUI_Widget widget ) int Widget_Unwrap( LCUI_Widget widget ) { + int i; LCUI_Widget child; LinkedList *list, *list_show; LinkedListNode *target, *node, *prev, *snode; @@ -141,25 +142,37 @@ int Widget_Unwrap( LCUI_Widget widget ) } list = &widget->parent->children; list_show = &widget->parent->children_show; + if( widget->children.length > 0 ) { + node = LinkedList_GetNode( &widget->children, 0 ); + Widget_RemoveStatus( node->data, "first-child" ); + node = LinkedList_GetNode( &widget->children, -1 ); + Widget_RemoveStatus( node->data, "last-child" ); + } node = Widget_GetNode( widget ); + i = widget->children.length; target = node->prev; - LinkedList_ForEach( node, &widget->children ) { + node = widget->children.tail.prev; + while( i-- > 0 ) { prev = node->prev; child = node->data; snode = Widget_GetShowNode( child ); - Widget_UpdateStatusAfterAppend( child, TRUE ); LinkedList_Unlink( &widget->children, node ); LinkedList_Unlink( &widget->children_show, snode ); child->parent = widget->parent; LinkedList_Link( list, target, node ); LinkedList_AppendNode( list_show, snode ); - Widget_UpdateStatusAfterAppend( child, FALSE ); Widget_UpdateZIndex( child ); Widget_AddTaskForChildren( child, WTT_REFRESH_STYLE ); Widget_UpdateTaskStatus( child ); - target = target->next; node = prev; } + if( widget->index == 0 ) { + Widget_AddStatus( target->next->data, "first-child" ); + } + if( widget->index == list->length - 1 ) { + node = LinkedList_GetNode( list, -1 ); + Widget_AddStatus( node->data, "last-child" ); + } Widget_Destroy( widget ); return 0; } @@ -1518,6 +1531,7 @@ extern void LCUIWidget_AddTextView( void ); extern void LCUIWidget_AddButton( void ); extern void LCUIWidget_AddSideBar( void ); extern void LCUIWidget_AddTScrollBar( void ); +extern void LCUIWidget_AddTextEdit( void ); void LCUI_InitWidget(void) { @@ -1529,6 +1543,7 @@ void LCUI_InitWidget(void) LCUIWidget_AddButton(); LCUIWidget_AddSideBar(); LCUIWidget_AddTScrollBar(); + LCUIWidget_AddTextEdit(); RBTree_Init( &LCUIWidget.ids ); RBTree_SetDataNeedFree( &LCUIWidget.ids, FALSE ); RBTree_OnJudge( &LCUIWidget.ids, CompareWidgetId ); diff --git a/src/gui/widget_style.c b/src/gui/widget_style.c index eb7d4c32..e9c32999 100644 --- a/src/gui/widget_style.c +++ b/src/gui/widget_style.c @@ -1082,7 +1082,7 @@ void Widget_ExecUpdateStyle( LCUI_Widget w, LCUI_BOOL is_update_all ) int i, key; LCUI_Style s; LCUI_WidgetClass *wc; - LCUI_BOOL need_update_expend_style; + LCUI_BOOL need_update_expend_style = FALSE; typedef struct { int start, end, task; LCUI_BOOL is_valid; From 13e675256293c626049ad9a35d124424047cf547 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Fri, 17 Jun 2016 22:58:41 +0800 Subject: [PATCH 050/124] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20focusable=20?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=EF=BC=8C=E6=B7=BB=E5=8A=A0=20focus=20?= =?UTF-8?q?=E5=92=8C=20blur=20=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/gui/widget_base.h | 2 + src/gui/css_parser.c | 24 +++++++++++ src/gui/widget_base.c | 8 ++++ src/gui/widget_event.c | 77 ++++++++++++++++++++++------------ src/gui/widget_style.c | 2 +- 5 files changed, 86 insertions(+), 27 deletions(-) diff --git a/include/LCUI/gui/widget_base.h b/include/LCUI/gui/widget_base.h index ed1e09d2..2fdc4efc 100755 --- a/include/LCUI/gui/widget_base.h +++ b/include/LCUI/gui/widget_base.h @@ -50,6 +50,7 @@ typedef struct LCUI_WidgetBase* LCUI_Widget; /** 部件样式 */ typedef struct LCUI_WidgetStyle { LCUI_BOOL visible; /**< 是否可见 */ + LCUI_BOOL focusable; /**< 是否能够得到焦点 */ int left, top; /**< 左边界、顶边界的偏移距离 */ int right, bottom; /**< 右边界、底边界的偏移距离 */ int z_index; /**< 堆叠顺序,该值越高,部件显示得越靠前 */ @@ -141,6 +142,7 @@ enum LCUI_StyleKeyName { key_box_shadow_color, key_box_shadow_end, key_pointer_events, + key_focusable, STYLE_KEY_TOTAL }; diff --git a/src/gui/css_parser.c b/src/gui/css_parser.c index 5a315729..cf425d86 100644 --- a/src/gui/css_parser.c +++ b/src/gui/css_parser.c @@ -191,6 +191,29 @@ static int OnParseNumber( LCUI_StyleSheet ss, int key, const char *str ) return -1; } +static int OnParseBoolean( LCUI_StyleSheet ss, int key, const char *str ) +{ + LCUI_Style s = &ss->sheet[key]; + if( strcasecmp(str, "true") == 0 ) { + s->is_valid = TRUE; + s->type = SVT_VALUE; + s->value = 1; + return 0; + } else if( strcasecmp(str, "false") == 0 ) { + s->is_valid = TRUE; + s->type = SVT_VALUE; + s->value = 0; + return 0; + } + if( strcmp("auto", str) == 0 ) { + s->is_valid = TRUE; + s->type = SVT_AUTO; + s->style = SV_AUTO; + return 0; + } + return -1; +} + static int OnParseColor( LCUI_StyleSheet ss, int key, const char *str ) { LCUI_Style s = &ss->sheet[key]; @@ -635,6 +658,7 @@ static LCUI_StyleParserRec style_parser_map[] = { { key_margin_right, NULL, OnParseNumber }, { key_margin_bottom, NULL, OnParseNumber }, { key_margin_left, NULL, OnParseNumber }, + { key_focusable, NULL, OnParseBoolean }, { key_pointer_events, NULL, OnParseStyleOption }, { key_box_sizing, NULL, OnParseStyleOption }, { -1, "border", OnParseBorder }, diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index 5fe95a8f..f58d8857 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -189,6 +189,7 @@ static void Widget_Init( LCUI_Widget widget ) widget->inherited_style = StyleSheet(); widget->computed_style.opacity = 1.0; widget->computed_style.visible = TRUE; + widget->computed_style.focusable = TRUE; widget->computed_style.display = SV_BLOCK; widget->computed_style.position = SV_STATIC; widget->computed_style.pointer_events = SV_AUTO; @@ -1094,8 +1095,15 @@ void Widget_UpdateSize( LCUI_Widget w ) void Widget_UpdateProps( LCUI_Widget w ) { + LCUI_Style s; int prop = ComputeStyleOption( w, key_pointer_events, SV_AUTO ); w->computed_style.pointer_events = prop; + s = &w->style->sheet[key_focusable]; + if( s->is_valid && s->type == SVT_VALUE && s->value == 0 ) { + w->computed_style.focusable = FALSE; + } else { + w->computed_style.focusable = TRUE; + } } /** 设置内边距 */ diff --git a/src/gui/widget_event.c b/src/gui/widget_event.c index 7d4b0d61..21cfe12c 100644 --- a/src/gui/widget_event.c +++ b/src/gui/widget_event.c @@ -69,6 +69,7 @@ typedef struct LCUI_WidgetEventPackRec_ { enum WidgetStatusType { WST_HOVER, WST_ACTIVE, + WST_FOCUS, WST_TOTAL }; @@ -578,11 +579,11 @@ void LCUIWidget_ClearEventTarget( LCUI_Widget widget ) } /** 响应系统的鼠标移动事件,向目标部件投递相关鼠标事件 */ -static void OnMouseEvent( LCUI_SysEvent e, void *arg ) +static void OnMouseEvent( LCUI_SysEvent sys_ev, void *arg ) { LCUI_Pos pos; LCUI_Widget target, w; - LCUI_WidgetEventRec ebuff; + LCUI_WidgetEventRec ev; w = LCUIWidget_GetRoot(); LCUICursor_GetPos( &pos ); if( self.mouse_capturer ) { @@ -599,39 +600,62 @@ static void OnMouseEvent( LCUI_SysEvent e, void *arg ) return; } } - ebuff.cancel_bubble = FALSE; - ebuff.target = target; - switch( e->type ) { + ev.cancel_bubble = FALSE; + ev.target = target; + switch( sys_ev->type ) { case LCUI_MOUSEDOWN: - ebuff.type = WET_MOUSEDOWN; - ebuff.button.x = pos.x; - ebuff.button.y = pos.y; - ebuff.button.button = e->button.button; - Widget_PostEvent( target, &ebuff, NULL, NULL ); + ev.type = WET_MOUSEDOWN; + ev.button.x = pos.x; + ev.button.y = pos.y; + ev.button.button = sys_ev->button.button; + Widget_PostEvent( target, &ev, NULL, NULL ); Widget_UpdateStatus( target, WST_ACTIVE ); + /* 开始处理焦点 */ + for( w = target; w; w = w->parent ) { + if( w->computed_style.focusable ) { + break; + } + } + if( self.targets[WST_FOCUS] == w ) { + break; + } + if( self.targets[WST_FOCUS] ) { + ev.type = WET_BLUR; + ev.target = self.targets[WST_FOCUS]; + Widget_RemoveStatus( ev.target, "focus" ); + Widget_PostEvent( ev.target, &ev, NULL, NULL ); + } + if( !w->computed_style.focusable ) { + break; + } + ev.target = w; + ev.type = WET_FOCUS; + self.targets[WST_FOCUS] = w; + Widget_AddStatus( ev.target, "focus" ); + Widget_PostEvent( ev.target, &ev, NULL, NULL ); break; case LCUI_MOUSEUP: - ebuff.type = WET_MOUSEUP; - ebuff.button.x = pos.x; - ebuff.button.y = pos.y; - ebuff.button.button = e->button.button; - Widget_PostEvent( target, &ebuff, NULL, NULL ); + ev.type = WET_MOUSEUP; + ev.button.x = pos.x; + ev.button.y = pos.y; + ev.button.button = sys_ev->button.button; + Widget_PostEvent( target, &ev, NULL, NULL ); if( self.targets[WST_ACTIVE] == target ) { - ebuff.type = WET_CLICK; - Widget_PostEvent( target, &ebuff, NULL, NULL ); + ev.type = WET_CLICK; + Widget_PostEvent( target, &ev, NULL, NULL ); } Widget_UpdateStatus( NULL, WST_ACTIVE ); break; case LCUI_MOUSEMOVE: - ebuff.type = WET_MOUSEMOVE; - ebuff.motion.x = pos.x; - ebuff.motion.y = pos.y; - Widget_PostEvent( target, &ebuff, NULL, NULL ); + ev.type = WET_MOUSEMOVE; + ev.motion.x = pos.x; + ev.motion.y = pos.y; + Widget_PostEvent( target, &ev, NULL, NULL ); break; case LCUI_MOUSEWHEEL: - ebuff.type = WET_MOUSEWHEEL; - ebuff.wheel.delta = e->wheel.delta; - Widget_PostEvent( target, &ebuff, NULL, NULL ); + ev.type = WET_MOUSEWHEEL; + ev.wheel.delta = sys_ev->wheel.delta; + Widget_PostEvent( target, &ev, NULL, NULL ); default:return; } Widget_UpdateStatus( target, WST_HOVER ); @@ -672,8 +696,8 @@ static void ConvertTouchPoint( LCUI_TouchPoint point ) } /** 分发触控事件给对应的部件 */ -static int DispatchTouchEvent( LinkedList *capturers, LCUI_TouchPoint points, - int n_points ) +static int DispatchTouchEvent( LinkedList *capturers, + LCUI_TouchPoint points, int n_points ) { int i, count; LCUI_WidgetEventRec ev; @@ -891,6 +915,7 @@ void LCUIWidget_InitEvent(void) RBTree_Init( &self.event_records ); self.targets[WST_ACTIVE] = NULL; self.targets[WST_HOVER] = NULL; + self.targets[WST_FOCUS] = NULL; self.mouse_capturer = NULL; self.base_event_id = WET_USER + 1000; self.event_ids = Dict_Create( &DictType_String, NULL ); diff --git a/src/gui/widget_style.c b/src/gui/widget_style.c index e9c32999..5c18f29b 100644 --- a/src/gui/widget_style.c +++ b/src/gui/widget_style.c @@ -1097,7 +1097,7 @@ void Widget_ExecUpdateStyle( LCUI_Widget w, LCUI_BOOL is_update_all ) { key_border_start, key_border_end, WTT_BORDER, TRUE }, { key_background_start, key_background_end, WTT_BACKGROUND, TRUE }, { key_box_shadow_start, key_box_shadow_end, WTT_SHADOW, TRUE }, - { key_pointer_events, key_pointer_events, WTT_PROPS, TRUE }, + { key_pointer_events, key_focusable, WTT_PROPS, TRUE }, { key_box_sizing, key_box_sizing, WTT_RESIZE, TRUE } }; if( is_update_all ) { From 13b4a4482273e4ce4d6ae7fdb45f77e5d52d600d Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Fri, 17 Jun 2016 23:00:28 +0800 Subject: [PATCH 051/124] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20textedit=20?= =?UTF-8?q?=E9=83=A8=E4=BB=B6=EF=BC=8C=E8=B0=83=E6=95=B4=E6=A0=B7=E5=BC=8F?= =?UTF-8?q?=E3=80=81=E5=B0=BA=E5=AF=B8=E8=AE=A1=E7=AE=97=E5=92=8C=E5=85=89?= =?UTF-8?q?=E6=A0=87=E4=BD=8D=E7=BD=AE=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/LCUI.h | 19 +----- src/font/textlayer.c | 10 ++-- src/gui/widget/textedit.c | 122 ++++++++++++++++++++++---------------- src/gui/widget/textview.c | 8 +-- 4 files changed, 80 insertions(+), 79 deletions(-) diff --git a/include/LCUI/LCUI.h b/include/LCUI/LCUI.h index e46d71f0..3cf87073 100755 --- a/include/LCUI/LCUI.h +++ b/include/LCUI/LCUI.h @@ -101,26 +101,9 @@ typedef struct LCUI_Pos_ { } LCUI_Pos; typedef struct LCUI_Size_ { - union { - int w; - int width; - }; - union { - int h; - int height; - }; + int width, height; } LCUI_Size; -typedef struct LCUI_String_ { - char *string; - uint_t length; -} LCUI_String; - -typedef struct LCUI_WString_ { - wchar_t *string; - uint_t length; -} LCUI_WString; - typedef struct LCUI_Rect_ { union { int x, left; }; union { int y, top; }; diff --git a/src/font/textlayer.c b/src/font/textlayer.c index 44e81855..8368d833 100644 --- a/src/font/textlayer.c +++ b/src/font/textlayer.c @@ -892,15 +892,15 @@ LCUI_Graph* TextLayer_GetGraphBuffer( LCUI_TextLayer layer ) } /** 设置最大尺寸 */ -int TextLayer_SetMaxSize( LCUI_TextLayer layer, LCUI_Size new_size ) +int TextLayer_SetMaxSize( LCUI_TextLayer layer, LCUI_Size size ) { - if( new_size.w <= 0 || new_size.h <= 0 ) { + if( size.width <= 0 || size.height <= 0 ) { return -1; } - layer->max_width = new_size.w; - layer->max_height = new_size.h; + layer->max_width = size.width; + layer->max_height = size.height; if( layer->is_using_buffer ) { - Graph_Create( &layer->graph, new_size.w, new_size.h ); + Graph_Create( &layer->graph, size.width, size.height ); } layer->task.redraw_all = TRUE; if( layer->is_autowrap_mode ) { diff --git a/src/gui/widget/textedit.c b/src/gui/widget/textedit.c index d051907a..d78b4932 100644 --- a/src/gui/widget/textedit.c +++ b/src/gui/widget/textedit.c @@ -68,11 +68,13 @@ typedef struct LCUI_TextCaretRec_ { } LCUI_TextCaretRec, *LCUI_TextCaret; typedef struct LCUI_TextEditRec_ { - LCUI_TextLayer text; /**< 实际文本 */ - LCUI_TextLayer mask_text; /**< 屏蔽后的文本 */ - LCUI_Widget scrollbar[2]; /**< 两个滚动条 */ + LCUI_TextLayer source_text; /**< 实际文本层 */ + LCUI_TextLayer mask_text; /**< 屏蔽后的文本层 */ + LCUI_TextLayer text; /**< 当前使用的文本层 */ + LCUI_Widget scrollbars[2]; /**< 两个滚动条 */ LCUI_Widget caret; /**< 文本插入符 */ - LCUI_BOOL read_only; /**< 是否只读 */ + LCUI_BOOL is_read_only; /**< 是否只读 */ + LCUI_BOOL is_multiline_mode; /**< 是否为多行模式 */ int block_size; /**< 块大小 */ LinkedList text_blocks; /**< 文本块缓冲区 */ LinkedList text_tags; /**< 当前处理的标签列表 */ @@ -112,13 +114,19 @@ textcaret { ); static const char *textedit_css = ToString( + textedit { min-width: 124px; min-height:14px; background-color: #fff; border: 1px solid #eee; -padding: 4px; +padding: 5px 10px; } +textedit:focus { +border: 1px solid #2196F3; +box-shadow: 0 0 6px rgba(33,150,243,0.4); +} + ); static void TextCaret_BlinkShow( LCUI_Widget widget ) @@ -205,21 +213,30 @@ static void LCUIWidget_AddTextCaret( void ) /*-------------------------------- End Caret --------------------------------*/ -/** 移动文本框内的文本插入符的行列坐标 */ -static void TextEdit_MoveCaret( LCUI_Widget widget, int row, int col ) +static void TextEdit_UpdateCaret( LCUI_Widget widget ) { LCUI_Pos pos; LCUI_TextEdit edit = widget->private_data; - TextLayer_SetCaretPos( edit->text, row, col ); if( TextLayer_GetCaretPixelPos( edit->text, &pos ) == 0 ) { + int row = edit->text->insert_y; int height = TextLayer_GetRowHeight( edit->text, row ); LCUI_StyleSheet sheet = edit->caret->custom_style; SetStyle( sheet, key_height, height, px ); + pos.x += widget->padding.left; + pos.y += widget->padding.top; Widget_Move( edit->caret, pos.x, pos.y ); } TextCaret_BlinkShow( edit->caret ); } +/** 移动文本框内的文本插入符的行列坐标 */ +static void TextEdit_MoveCaret( LCUI_Widget widget, int row, int col ) +{ + LCUI_TextEdit edit = widget->private_data; + TextLayer_SetCaretPos( edit->text, row, col ); + TextEdit_UpdateCaret( widget ); +} + /*------------------------------- TextBlock ---------------------------------*/ static void TextBlock_OnDestroy( void *arg ) { @@ -328,22 +345,14 @@ static void TextEdit_UpdateTextLayer( LCUI_Widget widget ) { LinkedList rects; LCUI_TextEdit edit; - LCUI_TextLayer layer; LinkedListNode *node; - LinkedList_Init( &rects ); edit = widget->private_data; - /* 根据是否启用屏蔽符,判断需更新哪个文本图层的数据 */ - if( edit->password_char ) { - layer = edit->mask_text; - } else { - layer = edit->text; - } LinkedList_ForEach( node, &rects ) { Widget_InvalidateArea( widget, node->data, SV_CONTENT_BOX ); } LinkedList_Clear( &rects, free ); - TextLayer_ClearInvalidRect( layer ); + TextLayer_ClearInvalidRect( edit->text ); } static void TextEdit_OnTask( LCUI_Widget widget ) @@ -364,6 +373,16 @@ static void TextEdit_OnTask( LCUI_Widget widget ) TextEdit_UpdateTextLayer( widget ); } +static void TextEdit_AutoSize( LCUI_Widget widget, int *width, int *height ) +{ + LCUI_TextEdit edit = widget->private_data; + if( edit->is_multiline_mode ) { + return; + } + *width = TextLayer_GetWidth( edit->text ); + *height = TextLayer_GetHeight( edit->text ); +} + /*----------------------------- End TextBlock ---------------------------------*/ /** 指定文本框是否处理控制符 */ @@ -378,6 +397,7 @@ void TextEdit_SetMultiline( LCUI_Widget widget, LCUI_BOOL is_true ) { LCUI_TextEdit edit = widget->private_data; TextLayer_SetMultiline( edit->text, is_true ); + edit->is_multiline_mode = is_true; } /** 清空文本内容 */ @@ -435,6 +455,7 @@ static void TextEdit_OnFocus( LCUI_Widget widget, LCUI_WidgetEvent e, void *arg LCUIIME_SetTarget( widget ); TextCaret_SetVisible( edit->caret, TRUE ); TextCaret_BlinkHide( edit->caret ); + TextEdit_UpdateCaret( widget ); } static void TextEdit_OnBlur( LCUI_Widget widget, LCUI_WidgetEvent e, void *arg ) @@ -442,7 +463,7 @@ static void TextEdit_OnBlur( LCUI_Widget widget, LCUI_WidgetEvent e, void *arg ) LCUI_TextEdit edit; edit = widget->private_data; LCUIIME_ClearTarget(); - TextCaret_SetVisible( edit->caret, TRUE ); + TextCaret_SetVisible( edit->caret, FALSE ); } static void TextEdit_TextBackspace( LCUI_Widget widget, int n_ch ) @@ -478,8 +499,8 @@ static void TextEdit_OnKeyDown( LCUI_Widget widget, LCUI_WidgetEvent e, void *ar edit = widget->private_data; cur_row = edit->text->insert_y; cur_col = edit->text->insert_x; - cols = TextLayer_GetRowTextLength( edit->text, cur_row ); rows = TextLayer_GetRowTotal( edit->text ); + cols = TextLayer_GetRowTextLength( edit->text, cur_row ); switch( e->key.code ) { case LCUIKEY_HOMEPAGE: // home键移动光标至行首 cur_col = 0; @@ -536,7 +557,7 @@ static void TextEdit_OnInput( LCUI_Widget widget, LCUI_WidgetEvent e, void *arg edit = widget->private_data; ptr_last = ptr + sizeof( e->input.text ) / sizeof( wchar_t ); /* 如果文本框是只读的 */ - if( edit->read_only ) { + if( edit->is_read_only ) { return; } for( ; ptr < ptr_last && *ptr != '\0'; ++ptr ) { @@ -564,15 +585,39 @@ static void TextEdit_OnInput( LCUI_Widget widget, LCUI_WidgetEvent e, void *arg TextEdit_InsertTextW( widget, e->input.text ); } +static void TextEdit_OnResize( LCUI_Widget w, LCUI_WidgetEvent e, void *arg ) +{ + LinkedList rects; + LinkedListNode *node; + LCUI_Size new_size = {16, 16}; + LCUI_TextEdit edit = w->private_data; + if( w->box.content.width > new_size.width ) { + new_size.width = w->box.content.width; + } + if( w->box.content.height > new_size.height ) { + new_size.height = w->box.content.height; + } + LinkedList_Init( &rects ); + TextLayer_SetMaxSize( edit->text, new_size ); + TextLayer_Update( edit->text, &rects ); + LinkedList_ForEach( node, &rects ) { + Widget_InvalidateArea( w, node->data, SV_CONTENT_BOX ); + } + LinkedList_Clear( &rects, free ); + TextLayer_ClearInvalidRect( edit->text ); +} + static void TextEdit_OnInit( LCUI_Widget widget ) { LCUI_TextEdit edit; edit = Widget_NewPrivateData( widget, LCUI_TextEditRec ); - edit->read_only = FALSE; - edit->text = TextLayer_New(); + edit->is_read_only = FALSE; + edit->password_char = 0; edit->allow_input_char = NULL; edit->show_placeholder = FALSE; edit->mask_text = TextLayer_New(); + edit->source_text = TextLayer_New(); + edit->text = edit->source_text; edit->block_size = TEXT_BLOCK_SIZE; edit->caret = LCUIWidget_New( "textcaret" ); LinkedList_Init( &edit->text_blocks ); @@ -582,6 +627,7 @@ static void TextEdit_OnInit( LCUI_Widget widget ) TextLayer_SetAutoWrap( edit->mask_text, TRUE ); TextLayer_SetUsingStyleTags( edit->text, FALSE ); Widget_BindEvent( widget, "keydown", TextEdit_OnKeyDown, NULL, NULL ); + Widget_BindEvent( widget, "resize", TextEdit_OnResize, NULL, NULL ); Widget_BindEvent( widget, "input", TextEdit_OnInput, NULL, NULL ); Widget_BindEvent( widget, "focus", TextEdit_OnFocus, NULL, NULL ); Widget_BindEvent( widget, "blur", TextEdit_OnBlur, NULL, NULL ); @@ -598,33 +644,10 @@ static void TextEdit_OnDestroy( LCUI_Widget widget ) LinkedList_Clear( &edit->text_blocks, TextBlock_OnDestroy ); } -static void TextEdit_OnResize( LCUI_Widget w, LCUI_WidgetEvent e, void *arg ) -{ - LinkedList rects; - LinkedListNode *node; - LCUI_Size new_size = {16, 16}; - LCUI_TextEdit edit = w->private_data; - if( w->box.content.width > new_size.w ) { - new_size.w = w->box.content.width; - } - if( w->box.content.height > new_size.h ) { - new_size.h = w->box.content.height; - } - LinkedList_Init( &rects ); - TextLayer_SetMaxSize( edit->text, new_size ); - TextLayer_Update( edit->text, &rects ); - LinkedList_ForEach( node, &rects ) { - Widget_InvalidateArea( w, node->data, SV_CONTENT_BOX ); - } - LinkedList_Clear( &rects, free ); - TextLayer_ClearInvalidRect( edit->text ); -} - static void TextEdit_OnPaint( LCUI_Widget w, LCUI_PaintContext paint ) { LCUI_TextEdit edit; LCUI_Pos layer_pos; - LCUI_TextLayer layer; LCUI_Rect content_rect, rect; edit = w->private_data; @@ -637,15 +660,9 @@ static void TextEdit_OnPaint( LCUI_Widget w, LCUI_PaintContext paint ) layer_pos.y = content_rect.y - paint->rect.y; rect.x -= content_rect.x; rect.y -= content_rect.y; - if( edit->password_char ) { - layer = edit->mask_text; - } else { - layer = edit->text; - } - TextLayer_DrawToGraph( layer, rect, layer_pos, &paint->canvas ); + TextLayer_DrawToGraph( edit->text, rect, layer_pos, &paint->canvas ); } - /** 添加 TextEdit 部件类型 */ void LCUIWidget_AddTextEdit( void ) { @@ -654,6 +671,7 @@ void LCUIWidget_AddTextEdit( void ) wc->methods.paint = TextEdit_OnPaint; wc->methods.destroy = TextEdit_OnDestroy; wc->methods.set_text = TextEdit_SetText; + wc->methods.autosize = TextEdit_AutoSize; wc->task_handler = TextEdit_OnTask; LCUICSS_LoadString( textedit_css ); LCUIWidget_AddTextCaret(); diff --git a/src/gui/widget/textview.c b/src/gui/widget/textview.c index ba188d63..dd2cc232 100644 --- a/src/gui/widget/textview.c +++ b/src/gui/widget/textview.c @@ -286,11 +286,11 @@ static void TextView_OnResize( LCUI_Widget w, LCUI_WidgetEvent e, void *arg ) LinkedListNode *node; LCUI_Size new_size = {16, 16}; LCUI_TextView *txt = w->private_data; - if( w->box.content.width > new_size.w ) { - new_size.w = w->box.content.width; + if( w->box.content.width > new_size.width ) { + new_size.width = w->box.content.width; } - if( w->box.content.height > new_size.h ) { - new_size.h = w->box.content.height; + if( w->box.content.height > new_size.height ) { + new_size.height = w->box.content.height; } LinkedList_Init( &rects ); if( w->style->sheet[key_width].is_valid && From 14cb525f5b430ae1022878679c6beab92b7a3fa6 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Fri, 17 Jun 2016 23:08:23 +0800 Subject: [PATCH 052/124] =?UTF-8?q?=E4=B8=BA=E7=9B=92=E5=BD=A2=E9=98=B4?= =?UTF-8?q?=E5=BD=B1=E7=9A=84=E5=8F=82=E6=95=B0=E8=AE=BE=E7=BD=AE=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=80=BC=EF=BC=8C=E9=81=BF=E5=85=8D=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E6=AE=8B=E7=95=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gui/widget_base.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index f58d8857..34f1d7c1 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -516,6 +516,7 @@ static void ComputeBoxShadowStyle( LCUI_StyleSheet ss, LCUI_BoxShadow *bsd ) { LCUI_Style style; int key = key_box_shadow_start + 1; + memset( bsd, 0, sizeof( *bsd ) ); for( ; key < key_box_shadow_end; ++key ) { style = &ss->sheet[key]; if( !style->is_valid ) { From 1ba4e310740892c1d353a94b9cb9c1fe5df231db Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Sat, 18 Jun 2016 17:14:10 +0800 Subject: [PATCH 053/124] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20CSS=20=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E5=8A=9F=E8=83=BD=E3=80=81=E8=A1=A5=E5=85=85=E9=83=A8?= =?UTF-8?q?=E4=BB=B6=E5=B1=9E=E6=80=A7=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 解决 pointer-events 和 focusable 属性未被部件应用的问题。 更新 LCUI_PrintStyleSheet() 函数。 --- include/LCUI/LCUI.h | 3 +++ include/LCUI/gui/css_parser.h | 4 +++- src/gui/css_parser.c | 42 ++++++++++++++++++++++++++--------- src/gui/widget/textview.c | 2 +- src/gui/widget_base.c | 4 ++-- src/gui/widget_style.c | 24 +++++++++++--------- src/gui/widget_task.c | 1 + 7 files changed, 55 insertions(+), 25 deletions(-) diff --git a/include/LCUI/LCUI.h b/include/LCUI/LCUI.h index 3cf87073..f1894874 100755 --- a/include/LCUI/LCUI.h +++ b/include/LCUI/LCUI.h @@ -130,6 +130,7 @@ typedef enum LCUI_StyleType { SVT_IMAGE, SVT_STYLE, SVT_VALUE, + SVT_BOOL, SVT_STRING, SVT_WSTRING } LCUI_StyleType; @@ -142,6 +143,7 @@ typedef enum LCUI_StyleType { #define SVT_scale SVT_SCALE #define SVT_style SVT_STYLE #define SVT_data SVT_DATA +#define SVT_bool SVT_BOOL #define SVT_image SVT_IMAGE #define SVT_string SVT_STRING #define SVT_wstring SVT_WSTRING @@ -252,6 +254,7 @@ typedef struct LCUI_StyleRec_ { LCUI_Color val_color; LCUI_Graph *image; LCUI_Graph *val_image; + LCUI_BOOL val_bool; }; } LCUI_StyleRec, *LCUI_Style; diff --git a/include/LCUI/gui/css_parser.h b/include/LCUI/gui/css_parser.h index 6c27f77f..b1f0f91a 100644 --- a/include/LCUI/gui/css_parser.h +++ b/include/LCUI/gui/css_parser.h @@ -49,7 +49,9 @@ typedef struct LCUI_StyleParserRec_ { int (*parse)(LCUI_StyleSheet, int, const char*); } LCUI_StyleParserRec, *LCUI_StyleParser; -LCUI_API int ParseStyleOption( const char *str ); +LCUI_API int GetStyleOption( const char *str ); + +LCUI_API const char *GetStyleOptionName( int val ); LCUI_API const char *GetStyleName( int key ); diff --git a/src/gui/css_parser.c b/src/gui/css_parser.c index cf425d86..853c3d1b 100644 --- a/src/gui/css_parser.c +++ b/src/gui/css_parser.c @@ -71,7 +71,8 @@ typedef struct KeyNameGroup { static struct CSSParserModule { LCUI_RBTree parser_tree; /**< 解析器树,以名称进行索引 */ - LCUI_RBTree option_tree; /**< 样式属性值树,以属性值进行索引 */ + LCUI_RBTree option_name_tree; /**< 样式属性值名称树,以值进行索引 */ + LCUI_RBTree option_tree; /**< 样式属性值树,以值的名称进行索引 */ LCUI_RBTree name_tree; /**< 样式属性名称树,以属性名称进行索引 */ int count; /**< 当前记录的属性数量 */ } self; @@ -80,7 +81,7 @@ static struct CSSParserModule { #define SPLIT_COLOR (1<<1) #define SPLIT_STYLE (1<<2) -int ParseStyleOption( const char *str ) +int GetStyleOption( const char *str ) { LCUI_RBTreeNode *node; node = RBTree_CustomSearch( &self.option_tree, str ); @@ -90,6 +91,16 @@ int ParseStyleOption( const char *str ) 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 ); @@ -143,7 +154,7 @@ static int SplitValues( const char *str, LCUI_Style slist, } } if( mode & SPLIT_STYLE ) { - val = ParseStyleOption( values[vj] ); + val = GetStyleOption( values[vj] ); if( val > 0 ) { slist[vj].style = val; slist[vj].type = SVT_style; @@ -196,13 +207,13 @@ static int OnParseBoolean( LCUI_StyleSheet ss, int key, const char *str ) LCUI_Style s = &ss->sheet[key]; if( strcasecmp(str, "true") == 0 ) { s->is_valid = TRUE; - s->type = SVT_VALUE; - s->value = 1; + s->type = SVT_BOOL; + s->value = TRUE; return 0; } else if( strcasecmp(str, "false") == 0 ) { s->is_valid = TRUE; - s->type = SVT_VALUE; - s->value = 0; + s->type = SVT_BOOL; + s->value = FALSE; return 0; } if( strcmp("auto", str) == 0 ) { @@ -262,12 +273,12 @@ 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 = ParseStyleOption( str ); + int v = GetStyleOption( str ); if( v < 0 ) { return -1; } - s->type = SVT_style; s->style = v; + s->type = SVT_STYLE; s->is_valid = TRUE; s->is_changed = TRUE; return 0; @@ -577,7 +588,13 @@ static KeyNameGroup style_name_map[] = { { 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" } }; @@ -935,12 +952,14 @@ void LCUICSS_Init(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.name_tree ); + RBTree_Init( &self.option_name_tree ); + RBTree_SetDataNeedFree( &self.name_tree, FALSE ); RBTree_SetDataNeedFree( &self.parser_tree, TRUE ); RBTree_SetDataNeedFree( &self.option_tree, FALSE ); - RBTree_SetDataNeedFree( &self.name_tree, FALSE ); + RBTree_SetDataNeedFree( &self.option_name_tree, FALSE ); RBTree_OnJudge( &self.parser_tree, CompareParserName ); RBTree_OnJudge( &self.option_tree, CompareName ); skn = style_name_map; @@ -970,6 +989,7 @@ void LCUICSS_Init(void) 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; } diff --git a/src/gui/widget/textview.c b/src/gui/widget/textview.c index dd2cc232..55b99e4e 100644 --- a/src/gui/widget/textview.c +++ b/src/gui/widget/textview.c @@ -196,7 +196,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 = ParseStyleOption( str ); + int val = GetStyleOption( str ); if( val < 0 ) { return -1; } diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index 34f1d7c1..a0438f1f 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -1100,7 +1100,7 @@ void Widget_UpdateProps( LCUI_Widget w ) int prop = ComputeStyleOption( w, key_pointer_events, SV_AUTO ); w->computed_style.pointer_events = prop; s = &w->style->sheet[key_focusable]; - if( s->is_valid && s->type == SVT_VALUE && s->value == 0 ) { + if( s->is_valid && s->type == SVT_BOOL && s->value == 0 ) { w->computed_style.focusable = FALSE; } else { w->computed_style.focusable = TRUE; @@ -1542,7 +1542,7 @@ extern void LCUIWidget_AddSideBar( void ); extern void LCUIWidget_AddTScrollBar( void ); extern void LCUIWidget_AddTextEdit( void ); -void LCUI_InitWidget(void) +void LCUI_InitWidget( void ) { LCUIWidget_InitTask(); LCUIWidget_InitEvent(); diff --git a/src/gui/widget_style.c b/src/gui/widget_style.c index 5c18f29b..2af7c09d 100644 --- a/src/gui/widget_style.c +++ b/src/gui/widget_style.c @@ -957,7 +957,8 @@ void LCUI_PrintStyleSheet( LCUI_StyleSheet ss ) int key; const char *name; for( key = 0; keylength; ++key ) { - if( !ss->sheet[key].is_valid ) { + LCUI_Style s = &ss->sheet[key]; + if( !s->is_valid ) { continue; } name = GetStyleName(key); @@ -967,17 +968,16 @@ void LCUI_PrintStyleSheet( LCUI_StyleSheet ss ) printf( "\t\t", key); } printf( "%s: ", key > STYLE_KEY_TOTAL ? " (+)" : "" ); - switch( ss->sheet[key].type ) { + switch( s->type ) { case SVT_AUTO: printf( "auto\n"); break; - case SVT_VALUE: { - LCUI_BOOL b = ss->sheet[key].value; - printf( "%s\n", b ? "true" : "false" ); + case SVT_BOOL: { + printf( "%s\n", s->val_bool ? "true" : "false" ); break; } case SVT_COLOR: { - LCUI_Color *clr = &ss->sheet[key].color; + LCUI_Color *clr = &s->val_color; if( clr->alpha < 255 ) { printf("rgba(%d,%d,%d,%0.2f)\n", clr->r, clr->g, clr->b, clr->a / 255.0); @@ -987,16 +987,20 @@ void LCUI_PrintStyleSheet( LCUI_StyleSheet ss ) break; } case SVT_PX: - printf("%dpx\n", ss->sheet[key].px); + printf("%dpx\n", s->val_px); break; case SVT_STRING: - printf("%s\n", ss->sheet[key].string); + printf("%s\n", s->val_string); break; case SVT_SCALE: - printf("%.2lf%%\n", ss->sheet[key].scale*100); + printf("%.2lf%%\n", s->val_scale*100); break; + case SVT_STYLE:{ + printf("%s\n", GetStyleOptionName( s->val_style )); + break; + } default: - printf("%d\n", ss->sheet[key].value); + printf("%d\n", s->value); break; } } diff --git a/src/gui/widget_task.c b/src/gui/widget_task.c index eddf1699..9d9e4597 100644 --- a/src/gui/widget_task.c +++ b/src/gui/widget_task.c @@ -146,6 +146,7 @@ static void MapTaskHandler(void) task_handlers[WTT_BACKGROUND] = Widget_UpdateBackground; task_handlers[WTT_LAYOUT] = Widget_ExecUpdateLayout; task_handlers[WTT_ZINDEX] = Widget_ExecUpdateZIndex; + task_handlers[WTT_PROPS] = Widget_UpdateProps; } /** 初始化 LCUI 部件任务处理功能 */ From b83389f5efb773f29632e15e756bd0477a766f45 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Sat, 18 Jun 2016 17:17:11 +0800 Subject: [PATCH 054/124] =?UTF-8?q?=E5=AE=8C=E5=96=84=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E6=B3=95=E6=94=AF=E6=8C=81=EF=BC=8C=E8=A1=A5=E5=85=85=20textin?= =?UTF-8?q?put=20=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/gui/widget_event.h | 9 +- include/LCUI/ime.h | 5 +- include/LCUI/main.h | 8 +- src/gui/widget_event.c | 176 ++++++++++++++++++++++---------- src/ime.c | 125 +++++++++++++++++------ src/main.c | 20 +++- 6 files changed, 241 insertions(+), 102 deletions(-) diff --git a/include/LCUI/gui/widget_event.h b/include/LCUI/gui/widget_event.h index f5796c13..a37e3be5 100644 --- a/include/LCUI/gui/widget_event.h +++ b/include/LCUI/gui/widget_event.h @@ -58,7 +58,7 @@ enum WidgetEventType { WET_KEYDOWN, WET_KEYUP, WET_KEYPRESS, - WET_INPUT, + WET_TEXTINPUT, WET_MOUSEOVER, WET_MOUSEMOVE, @@ -81,13 +81,10 @@ enum WidgetEventType { typedef LCUI_MouseMotionEvent LCUI_WidgetMouseMotionEvent; typedef LCUI_MouseButtonEvent LCUI_WidgetMouseButtonEvent; typedef LCUI_MouseWheelEvent LCUI_WidgetMouseWheelEvent; +typedef LCUI_TextInputEvent LCUI_WidgetTextInputEvent; typedef LCUI_KeyboardEvent LCUI_WidgetKeyboardEvent; typedef LCUI_TouchEvent LCUI_WidgetTouchEvent; -typedef struct LCUI_WidgetInputEvent_ { - wchar_t text[128]; -} LCUI_WidgetInputEvent; - /** 面向部件级的事件内容结构 */ typedef struct LCUI_WidgetEventRec_ { uint32_t type; /**< 事件类型标识号 */ @@ -100,7 +97,7 @@ typedef struct LCUI_WidgetEventRec_ { LCUI_WidgetMouseWheelEvent wheel; LCUI_WidgetKeyboardEvent key; LCUI_WidgetTouchEvent touch; - LCUI_WidgetInputEvent input; + LCUI_WidgetTextInputEvent text; }; } LCUI_WidgetEventRec, *LCUI_WidgetEvent; diff --git a/include/LCUI/ime.h b/include/LCUI/ime.h index d9d232d6..5373c6a8 100644 --- a/include/LCUI/ime.h +++ b/include/LCUI/ime.h @@ -67,11 +67,14 @@ LCUI_API void LCUIIME_Switch( void ); LCUI_API LCUI_BOOL LCUIIME_ProcessKey( LCUI_SysEvent e ); /** 提交输入法输入的内容至目标 */ -LCUI_API int LCUIIME_Commit( const wchar_t *str ); +LCUI_API int LCUIIME_Commit( const wchar_t *str, int length ); /** 设置输入法的目标 */ LCUI_API int LCUIIME_SetTarget( LCUI_Widget widget ); +/** 获取输入法的目标 */ +LCUI_API LCUI_Widget LCUIIME_GetTarget( void ); + /** 清除输入法的目标 */ LCUI_API int LCUIIME_ClearTarget( void ); diff --git a/include/LCUI/main.h b/include/LCUI/main.h index fa3877e1..b056eefa 100644 --- a/include/LCUI/main.h +++ b/include/LCUI/main.h @@ -59,7 +59,7 @@ enum LCUI_SysEventType { LCUI_MOUSEDOWN, /**< 鼠标触发的按钮按下事件 */ LCUI_MOUSEUP, /**< 鼠标触发的按钮释放事件 */ LCUI_MOUSEWHEEL, /**< 鼠标触发的滚轮滚动事件 */ - LCUI_INPUT, /**< 输入法触发的文本输入事件 */ + LCUI_TEXTINPUT, /**< 输入法触发的文本输入事件 */ LCUI_TOUCH, LCUI_TOUCHMOVE, LCUI_TOUCHDOWN, @@ -101,6 +101,11 @@ typedef struct LCUI_TouchEvent_ { LCUI_TouchPoint points; } LCUI_TouchEvent; +typedef struct LCUI_TextInputEvent_ { + wchar_t *text; + size_t length; +} LCUI_TextInputEvent; + typedef struct LCUI_SysEventRec_ { uint32_t type; void *data; @@ -108,6 +113,7 @@ typedef struct LCUI_SysEventRec_ { LCUI_MouseMotionEvent motion; LCUI_MouseButtonEvent button; LCUI_MouseWheelEvent wheel; + LCUI_TextInputEvent text; LCUI_KeyboardEvent key; LCUI_TouchEvent touch; }; diff --git a/src/gui/widget_event.c b/src/gui/widget_event.c index 21cfe12c..8f17ff53 100644 --- a/src/gui/widget_event.c +++ b/src/gui/widget_event.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -60,7 +61,6 @@ typedef struct WidgetEventHandlerRec_ { typedef struct LCUI_WidgetEventPackRec_ { void *data; /**< 额外数据 */ void (*destroy_data)(void*); /**< 数据的销毁函数 */ - int x, y; /**< 事件触发点的坐标,主要用于鼠标事件的传递 */ LCUI_Widget widget; /**< 当前处理该事件的部件 */ LCUI_WidgetEventRec event; /**< 事件数据 */ LCUI_BOOL is_direct_run; /**< 是否直接处理该事件 */ @@ -167,11 +167,7 @@ static void WidgetEventTranslator( LCUI_Event e, LCUI_WidgetEventPack pack ) } return; } - pack->x += w->box.border.x; - pack->y += w->box.border.y; w = w->parent; - pack->x += w->padding.left; - pack->y += w->padding.top; pack->widget = w; /** 向父级部件冒泡传递事件 */ EventTrigger_Trigger( w->trigger, e->type, pack ); @@ -181,18 +177,36 @@ static void WidgetEventTranslator( LCUI_Event e, LCUI_WidgetEventPack pack ) static void CopyWidgetEventPack( LCUI_WidgetEventPack dst, const LCUI_WidgetEventPack src ) { + int n; + size_t size; + LCUI_WidgetEvent e; + *dst = *src; - if( src->event.type == WET_TOUCH ) { - if( src->event.touch.n_points > 0 ) { - int n = src->event.touch.n_points; - size_t size = sizeof( LCUI_TouchPointRec ) * n; - dst->event.touch.points = malloc( size ); - if( !dst->event.touch.points ) { - return; - } - memcpy( dst->event.touch.points, - src->event.touch.points, size ); + e = &dst->event; + switch( src->event.type ) { + case WET_TOUCH: + if( e->touch.n_points <= 0 ) { + break; } + n = e->touch.n_points; + size = sizeof( LCUI_TouchPointRec ) * n; + e->touch.points = malloc( size ); + if( !e->touch.points ) { + return; + } + memcpy( e->touch.points, + src->event.touch.points, size ); + break; + case WET_TEXTINPUT: + if( !e->text.text ) { + return; + } + e->text.text = NEW( wchar_t, e->text.length + 1 ); + if( !e->text.text ) { + return; + } + wcsncpy( e->text.text, e->text.text, e->text.length + 1 ); + default:break; } } @@ -200,12 +214,22 @@ static void CopyWidgetEventPack( LCUI_WidgetEventPack dst, static void DestroyWidgetEventPack( void *arg ) { LCUI_WidgetEventPack pack = arg; - if( pack->event.type == WET_TOUCH ) { - if( pack->event.touch.n_points > 0 ) { - free( pack->event.touch.points ); + LCUI_WidgetEvent e = &pack->event; + switch( e->type ) { + case WET_TOUCH: + if( e->touch.points ) { + free( e->touch.points ); } - pack->event.touch.points = NULL; - pack->event.touch.n_points = 0; + e->touch.points = NULL; + e->touch.n_points = 0; + break; + case WET_TEXTINPUT: + if( e->text.text ) { + free( e->text.text ); + } + e->text.text = NULL; + e->text.length = 0; + break; } free( pack ); } @@ -443,9 +467,10 @@ static int Widget_TriggerEventEx( LCUI_Widget widget, LCUI_WidgetEvent e, void *data, void (*destroy_data)(void*), LCUI_BOOL direct_run ) { - int ret; LCUI_Widget w; + LCUI_BOOL is_pointer_event; LCUI_WidgetEventPackRec pack; + int ret, pointer_x, pointer_y; pack.event = *e; pack.data = data; pack.widget = widget; @@ -454,8 +479,8 @@ static int Widget_TriggerEventEx( LCUI_Widget widget, LCUI_WidgetEvent e, switch( e->type ) { case WET_CLICK: case WET_MOUSEDOWN: - case WET_MOUSEMOVE: case WET_MOUSEUP: + case WET_MOUSEMOVE: case WET_MOUSEOVER: case WET_MOUSEOUT: if( widget->computed_style.pointer_events == SV_NONE ) { @@ -475,19 +500,38 @@ static int Widget_TriggerEventEx( LCUI_Widget widget, LCUI_WidgetEvent e, if( !widget->parent || e->cancel_bubble ) { return -1; } - /* 转换成相对于父级部件内容框的坐标 */ - pack.x += widget->box.border.x; - pack.y += widget->box.border.y; - /* 从当前部件后面找到当前坐标点命中的兄弟部件 */ - w = Widget_GetNextAt( widget, pack.x, pack.y ); - /* 找不到就向父级部件冒泡 */ - if( !w ) { - return Widget_PostEvent( widget->parent, e, - data, destroy_data ); + is_pointer_event = TRUE; + switch( e->type ) { + case WET_CLICK: + case WET_MOUSEDOWN: + case WET_MOUSEUP: + pointer_x = e->button.x; + pointer_y = e->button.y; + break; + case WET_MOUSEMOVE: + case WET_MOUSEOVER: + case WET_MOUSEOUT: + pointer_x = e->motion.x; + pointer_y = e->motion.y; + break; + default: + is_pointer_event = FALSE; + break; } - pack.x -= w->box.border.x; - pack.y -= w->box.border.y; - return EventTrigger_Trigger( w->trigger, e->type, &pack ); + if( is_pointer_event ) { + int x, y; + Widget_GetAbsXY( widget->parent, NULL, &x, &y ); + /* 转换成相对于父级部件内容框的坐标 */ + x = pointer_x - x; + y = pointer_y - y; + /* 从当前部件后面找到当前坐标点命中的兄弟部件 */ + w = Widget_GetNextAt( widget, x, y ); + if( w ) { + return EventTrigger_Trigger( w->trigger, + e->type, &pack ); + } + } + return Widget_PostEvent( widget->parent, e, data, destroy_data ); } int Widget_PostEvent( LCUI_Widget widget, LCUI_WidgetEvent e, void *data, @@ -612,7 +656,8 @@ static void OnMouseEvent( LCUI_SysEvent sys_ev, void *arg ) Widget_UpdateStatus( target, WST_ACTIVE ); /* 开始处理焦点 */ for( w = target; w; w = w->parent ) { - if( w->computed_style.focusable ) { + if( w->computed_style.pointer_events != SV_NONE && + w->computed_style.focusable ) { break; } } @@ -661,28 +706,43 @@ static void OnMouseEvent( LCUI_SysEvent sys_ev, void *arg ) Widget_UpdateStatus( target, WST_HOVER ); } -/** 响应按键的按下 */ -static void OnKeyDown( LCUI_SysEvent e, void *arg ) +static void OnKeyboardEvent( LCUI_SysEvent e, void *arg ) { - -} - -/** 响应按键的释放 */ -static void OnKeyUp( LCUI_SysEvent e, void *arg ) -{ - -} - -/** 响应按键的输入 */ -static void OnKeyPress( LCUI_SysEvent e, void *arg ) -{ - + LCUI_WidgetEventRec ev; + if( !self.targets[WST_FOCUS] ) { + return; + } + switch( e->type ) { + case LCUI_KEYDOWN: ev.type = WET_KEYDOWN; break; + case LCUI_KEYUP: ev.type = WET_KEYUP; break; + case LCUI_KEYPRESS: ev.type = WET_KEYPRESS; break; + default: return; + } + ev.target = self.targets[WST_FOCUS]; + ev.key.code = e->key.code; + Widget_TriggerEvent( ev.target, &ev, NULL ); } /** 响应输入法的输入 */ -static void OnInput( LCUI_SysEvent e, void *arg ) +static void OnTextInput( LCUI_SysEvent e, void *arg ) { - + LCUI_WidgetEventRec ev; + LCUI_Widget target = LCUIIME_GetTarget(); + if( !target ) { + return; + } + ev.target = target; + ev.type = WET_TEXTINPUT; + ev.text.length = e->text.length; + ev.text.text = NEW( wchar_t, e->text.length + 1 ); + if( !ev.text.text ) { + return; + } + wcsncpy( ev.text.text, e->text.text, e->text.length + 1 ); + Widget_TriggerEvent( ev.target, &ev, NULL ); + free( ev.text.text ); + ev.text.text = NULL; + ev.text.length = 0; } static void ConvertTouchPoint( LCUI_TouchPoint point ) @@ -897,7 +957,11 @@ void LCUIWidget_InitEvent(void) { WET_CLICK, "click" }, { WET_MOUSEOUT, "mouseout" }, { WET_MOUSEOVER, "mouseover" }, + { WET_KEYDOWN, "keydown" }, + { WET_KEYUP, "keyup" }, + { WET_KEYPRESS, "keypress" }, { WET_TOUCH, "touch" }, + { WET_TEXTINPUT, "textinput" }, { WET_TOUCHDOWN, "touchdown" }, { WET_TOUCHMOVE, "touchmove" }, { WET_TOUCHUP, "touchup" }, @@ -927,11 +991,11 @@ void LCUIWidget_InitEvent(void) LCUI_BindEvent( LCUI_MOUSEDOWN, OnMouseEvent, NULL, NULL ); LCUI_BindEvent( LCUI_MOUSEMOVE, OnMouseEvent, NULL, NULL ); LCUI_BindEvent( LCUI_MOUSEUP, OnMouseEvent, NULL, NULL ); - LCUI_BindEvent( LCUI_KEYPRESS, OnKeyPress, NULL, NULL ); - LCUI_BindEvent( LCUI_KEYDOWN, OnKeyDown, NULL, NULL ); + LCUI_BindEvent( LCUI_KEYPRESS, OnKeyboardEvent, NULL, NULL ); + LCUI_BindEvent( LCUI_KEYDOWN, OnKeyboardEvent, NULL, NULL ); + LCUI_BindEvent( LCUI_KEYUP, OnKeyboardEvent, NULL, NULL ); LCUI_BindEvent( LCUI_TOUCH, OnTouch, NULL, NULL ); - LCUI_BindEvent( LCUI_INPUT, OnInput, NULL, NULL ); - LCUI_BindEvent( LCUI_KEYUP, OnKeyUp, NULL, NULL ); + LCUI_BindEvent( LCUI_TEXTINPUT, OnTextInput, NULL, NULL ); RBTree_OnJudge( &self.event_records, CompareEventRecord ); LinkedList_Init( &self.touch_capturers ); } diff --git a/src/ime.c b/src/ime.c index b77c024f..c8cf4486 100644 --- a/src/ime.c +++ b/src/ime.c @@ -111,32 +111,12 @@ int LCUIIME_Register( const char *name, LCUI_IMEHandler handler ) self.id_count += 1; ime->id = self.id_count; ime->node.data = ime; - memcpy( &ime->handler, handler, sizeof(LCUI_IMEHandler) ); + strncpy( ime->name, name, len ); + memcpy( &ime->handler, handler, sizeof(LCUI_IMEHandlerRec) ); LinkedList_AppendNode( &self.list, &ime->node ); return ime->id; } -/* 选定输入法 */ -LCUI_BOOL LCUIIME_Select( int ime_id ) -{ - LCUI_IME ime = LCUIIME_Find( ime_id ); - if( ime ) { - self.ime = ime; - return TRUE; - } - return FALSE; -} - -LCUI_BOOL LCUIIME_SelectByName( const char *name ) -{ - LCUI_IME ime = LCUIIME_FindByName( name ); - if( ime ) { - self.ime = ime; - return TRUE; - } - return FALSE; -} - /* 打开输入法 */ static LCUI_BOOL LCUIIME_Open( LCUI_IME ime ) { @@ -155,6 +135,31 @@ static LCUI_BOOL LCUIIME_Close( LCUI_IME ime ) return FALSE; } +/* 选定输入法 */ +LCUI_BOOL LCUIIME_Select( int ime_id ) +{ + LCUI_IME ime = LCUIIME_Find( ime_id ); + if( ime ) { + LCUIIME_Close( self.ime ); + self.ime = ime; + LCUIIME_Open( self.ime ); + return TRUE; + } + return FALSE; +} + +LCUI_BOOL LCUIIME_SelectByName( const char *name ) +{ + LCUI_IME ime = LCUIIME_FindByName( name ); + if( ime ) { + LCUIIME_Close( self.ime ); + self.ime = ime; + LCUIIME_Open( self.ime ); + return TRUE; + } + return FALSE; +} + /* 切换至下一个输入法 */ void LCUIIME_Switch( void ) { @@ -267,20 +272,24 @@ LCUI_BOOL LCUIIME_ProcessKey( LCUI_SysEvent e ) return FALSE; } -int LCUIIME_Commit( const wchar_t *str ) +int LCUIIME_Commit( const wchar_t *str, int length ) { - LCUI_Widget widget; - LCUI_WidgetEventRec e; - if( !self.ime || !self.ime->handler.gettarget ) { - return -1; + LCUI_SysEventRec sys_ev; + if( length < 0 ) { + length = wcslen( str ); } - widget = self.ime->handler.gettarget(); - if( !widget ) { - return -2; + sys_ev.type = LCUI_TEXTINPUT; + sys_ev.text.length = length; + sys_ev.text.text = NEW( wchar_t, length + 1 ); + if( !sys_ev.text.text ) { + return -ENOMEM; } - e.type = LCUI_INPUT; - wcscpy( e.input.text, str ); - return Widget_PostEvent( widget, &e, NULL, NULL ); + wcsncpy( sys_ev.text.text, str, length + 1 ); + LCUI_TriggerEvent( &sys_ev, NULL ); + free( sys_ev.text.text ); + sys_ev.text.text = NULL; + sys_ev.text.length = 0; + return 0; } int LCUIIME_SetTarget( LCUI_Widget widget ) @@ -292,6 +301,13 @@ int LCUIIME_SetTarget( LCUI_Widget widget ) return -1; } +LCUI_Widget LCUIIME_GetTarget( void ) +{ + if( self.ime && self.ime->handler.gettarget ) { + return self.ime->handler.gettarget(); + } + return NULL; +} int LCUIIME_ClearTarget( void ) { if( self.ime && self.ime->handler.cleartarget ) { @@ -322,6 +338,11 @@ void LCUI_ExitIME( void ) /*-------------------------- 默认的输入法 ------------------------------*/ +#ifdef LCUI_BUILD_IN_WIN32 +#include +#include LCUI_EVENTS_H +#endif + static struct { LCUI_Widget target; } default_ime; @@ -415,6 +436,11 @@ static LCUI_Widget IME_GetTarget( void ) return default_ime.target; } +static void IME_ClearTarget( void ) +{ + default_ime.target = NULL; +} + static void IME_ToText( char ch ) { wchar_t text[2]; @@ -428,21 +454,51 @@ static void IME_ToText( char ch ) text[0] = ch; text[1] = '\0'; DEBUG_MSG("%S, %d\n", text, ch); - LCUIIME_Commit( text ); // 直接提交该字符 + LCUIIME_Commit( text, 2 ); // 直接提交该字符 } + +#ifdef LCUI_BUILD_IN_WIN32 + +static void WinIME_OnEndComposition( LCUI_Event e, void *arg ) +{ + wchar_t *text; + size_t size, len; + WIN_SysEvent win_ev = arg; + HIMC imc = ImmGetContext( win_ev->hwnd ); + size = ImmGetCompositionString( imc, GCS_RESULTSTR, NULL, 0 ); + text = malloc( size + sizeof( wchar_t ) ); + if( !text ) { + return; + } + size = ImmGetCompositionString( imc, GCS_RESULTSTR, text, size ); + len = size / sizeof( wchar_t ); + text[len] = 0; + LCUIIME_Commit( text, len ); + wprintf(L"len: %d, text: %s\n", len, text); +} + +#endif + /** * 输入法被打开时的处理 * 可以在输入法被打开时,初始化相关数据,链接至词库什么的 **/ static LCUI_BOOL IME_Open(void) { +#ifdef LCUI_BUILD_IN_WIN32 + LCUI_BindSysEvent( WM_IME_ENDCOMPOSITION, + WinIME_OnEndComposition, NULL, NULL ); +#endif return TRUE; } /** 输入法被关闭时的处理 */ static LCUI_BOOL IME_Close(void) { +#ifdef LCUI_BUILD_IN_WIN32 + LCUI_UnbindSysEvent( WM_IME_ENDCOMPOSITION, WinIME_OnEndComposition ); +#endif return TRUE; } @@ -452,6 +508,7 @@ static int LCUI_RegisterDefaultIME( void ) LCUI_IMEHandlerRec handler; handler.gettarget = IME_GetTarget; handler.settarget = IME_SetTarget; + handler.cleartarget = IME_ClearTarget; handler.prockey = IME_ProcessKey; handler.totext = IME_ToText; handler.close = IME_Close; diff --git a/src/main.c b/src/main.c index d693e02a..052cf800 100644 --- a/src/main.c +++ b/src/main.c @@ -48,6 +48,7 @@ #include #include #include +#include #include #include LCUI_EVENTS_H #include LCUI_MOUSE_H @@ -177,12 +178,21 @@ int LCUI_TriggerEvent( LCUI_SysEvent e, void *arg ) void LCUI_DestroyEvent( LCUI_SysEvent e ) { - if( e->type == LCUI_TOUCH ) { - if( e->touch.n_points > 0 && e->touch.points ) { + switch( e->type ) { + case LCUI_TOUCH: + if( e->touch.points ) { free( e->touch.points ); - e->touch.points = NULL; - e->touch.n_points = 0; } + e->touch.points = NULL; + e->touch.n_points = 0; + break; + case LCUI_TEXTINPUT: + if( e->text.text ) { + free( e->text.text ); + } + e->text.text = NULL; + e->text.length = 0; + break; } e->type = LCUI_NONE; } @@ -431,6 +441,7 @@ int LCUI_Init(void) LCUI_InitTimer(); LCUI_InitMouseDriver(); LCUI_InitKeyboardDriver(); + LCUI_InitIME(); LCUI_InitWidget(); LCUI_InitDisplay(); LCUI_InitCursor(); @@ -444,6 +455,7 @@ static int LCUI_Destroy( void ) e.type = LCUI_QUIT; LCUI_TriggerEvent( &e, NULL ); System.state = STATE_KILLED; + LCUI_ExitIME(); LCUI_ExitEvent(); LCUI_ExitCursor(); LCUI_ExitWidget(); From 45ebf814e9e2e5431a84137097fc2a70f0a14a35 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Sun, 19 Jun 2016 17:35:49 +0800 Subject: [PATCH 055/124] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20LCUIFont=5FGetBitm?= =?UTF-8?q?ap()=20=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 设置 bmp 的默认值为 NULL,确保在出现错误时输出的 bmp 参数值为 NULL。 --- src/font/fontlibrary.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/font/fontlibrary.c b/src/font/fontlibrary.c index 23d6f9f6..42bd569d 100644 --- a/src/font/fontlibrary.c +++ b/src/font/fontlibrary.c @@ -349,8 +349,8 @@ int LCUIFont_GetBitmap( wchar_t ch, int font_id, int size, LCUI_RBTree *ctx; LCUI_FontBitmap bmp_cache; + *bmp = NULL; if( !fontlib.is_inited ) { - *bmp = NULL; return -2; } if( font_id <= 0 ) { From 97fbb82c3dae564ef0758accc02cdda18ea38b64 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Sun, 19 Jun 2016 17:36:42 +0800 Subject: [PATCH 056/124] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 删除 WM_IME_ENDCOMPOSITION 消息处理,改为处理 WM_CHAR 消息。 --- src/ime.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/src/ime.c b/src/ime.c index c8cf4486..25604ffc 100644 --- a/src/ime.c +++ b/src/ime.c @@ -460,22 +460,13 @@ static void IME_ToText( char ch ) #ifdef LCUI_BUILD_IN_WIN32 -static void WinIME_OnEndComposition( LCUI_Event e, void *arg ) +static void WinIME_OnChar( LCUI_Event e, void *arg ) { - wchar_t *text; - size_t size, len; + wchar_t text[2]; WIN_SysEvent win_ev = arg; - HIMC imc = ImmGetContext( win_ev->hwnd ); - size = ImmGetCompositionString( imc, GCS_RESULTSTR, NULL, 0 ); - text = malloc( size + sizeof( wchar_t ) ); - if( !text ) { - return; - } - size = ImmGetCompositionString( imc, GCS_RESULTSTR, text, size ); - len = size / sizeof( wchar_t ); - text[len] = 0; - LCUIIME_Commit( text, len ); - wprintf(L"len: %d, text: %s\n", len, text); + text[0] = win_ev->wparam; + text[1] = 0; + LCUIIME_Commit( text, 2 ); } #endif @@ -487,8 +478,7 @@ static void WinIME_OnEndComposition( LCUI_Event e, void *arg ) static LCUI_BOOL IME_Open(void) { #ifdef LCUI_BUILD_IN_WIN32 - LCUI_BindSysEvent( WM_IME_ENDCOMPOSITION, - WinIME_OnEndComposition, NULL, NULL ); + LCUI_BindSysEvent( WM_CHAR, WinIME_OnChar, NULL, NULL ); #endif return TRUE; } @@ -497,7 +487,7 @@ static LCUI_BOOL IME_Open(void) static LCUI_BOOL IME_Close(void) { #ifdef LCUI_BUILD_IN_WIN32 - LCUI_UnbindSysEvent( WM_IME_ENDCOMPOSITION, WinIME_OnEndComposition ); + LCUI_UnbindSysEvent( WM_CHAR, WinIME_OnChar ); #endif return TRUE; } From c1a70becc443d96f2e5c11b647ad22d84d6bbbcc Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Sun, 19 Jun 2016 17:37:13 +0800 Subject: [PATCH 057/124] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20textedit=20?= =?UTF-8?q?=E9=83=A8=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/gui/widget/textedit.h | 35 +++--- src/font/textlayer.c | 26 +++-- src/font/textstyle.c | 8 +- src/gui/widget/textedit.c | 170 +++++++++++++++++++++-------- 4 files changed, 161 insertions(+), 78 deletions(-) diff --git a/include/LCUI/gui/widget/textedit.h b/include/LCUI/gui/widget/textedit.h index 5c69c5b6..a31a1284 100644 --- a/include/LCUI/gui/widget/textedit.h +++ b/include/LCUI/gui/widget/textedit.h @@ -1,4 +1,4 @@ -/* *************************************************************************** +/* *************************************************************************** * textedit.c -- textedit widget, used to allow user edit text. * * Copyright (C) 2016 by Liu Chao @@ -20,21 +20,21 @@ * ****************************************************************************/ /* **************************************************************************** - * textedit.c -- Îı¾±༭²¿¼þ£¬ÓÃÓÚÈÃÓû§±༭Îı¾¡£ + * textedit.c -- 文本编辑部件,用于让用户编辑文本。 * - * °æȨËùÓÐ (C) 2016 ¹éÊôÓÚ Áõ³¬ + * 版权所有 (C) 2016 归属于 刘超 * - * Õâ¸öÎļþÊÇLCUIÏîĿµÄһ²¿·֣¬²¢ÇÒֻ¿ÉÒԸù¾ÝGPLv2Ðí¿ÉЭÒéÀ´ʹÓᢸü¸ĺͷ¢²¼¡£ + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 * - * (GPLv2 ÊÇ GNUͨÓù«¹²Ðí¿É֤µڶþ°æ µÄӢÎÄËõд) + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) * - * ¼ÌÐøʹÓá¢Ð޸Ļ򷢲¼±¾Îļþ£¬±íÃ÷ÄúÒѾ­ÔĶÁ²¢ÍêȫÀí½âºͽÓÊÜÕâ¸öÐí¿ÉЭÒ顣 + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 * - * LCUI ÏîĿÊǻùÓÚʹÓÃĿµĶø¼ÓÒÔɢ²¼µģ¬µ«²»¸ºÈκε£±£ÔðÈΣ¬ÉõÖÁûÓÐÊÊÏúÐԻòÌØ - * ¶¨ÓÃ;µÄÒþº¬µ£±££¬ÏêÇéÇë²ÎÕÕGPLv2Ðí¿ÉЭÒ顣 + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 * - * ÄúӦÒÑÊյ½¸½ËæÓڱ¾ÎļþµÄGPLv2Ðí¿ÉЭÒéµĸ±±¾£¬Ëüͨ³£ÔÚLICENSE.TXTÎļþÖУ¬Èç¹û - * ûÓУ¬Çë²鿴£º. + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. * ****************************************************************************/ #ifndef LCUI_TEXTBOX_H #define LCUI_TEXTBOX_H @@ -43,24 +43,27 @@ LCUI_BEGIN_HEADER #define TextEdit_New() Widget_New("textedit") -/** ָ¶¨Îı¾¿òÊǷñ´¦Àí¿ØÖƷû */ +/** 指定文本框是否处理控制符 */ LCUI_API void TextEdit_SetUsingStyleTags( LCUI_Widget widget, LCUI_BOOL is_true ); -/** ָ¶¨Îı¾¿òÊǷñÆôÓöàÐÐÎı¾ÏÔʾ */ +/** 指定文本框是否启用多行文本显示 */ LCUI_API void TextEdit_SetMultiline( LCUI_Widget widget, LCUI_BOOL is_true ); -/** Çå¿ÕÎı¾ÄÚÈÝ */ +/** 清空文本内容 */ LCUI_API void TextEdit_ClearText( LCUI_Widget widget ); -/** ΪÎı¾¿òÉèÖÃÎı¾£¨¿í×ַû°棩 */ +/** 获取文本内容 */ +LCUI_API int TextEdit_GetTextW( LCUI_Widget widget, int start, int max_len, wchar_t *buf ); + +/** 为文本框设置文本(宽字符版) */ LCUI_API int TextEdit_SetTextW( LCUI_Widget widget, const wchar_t *wstr ); LCUI_API int TextEdit_SetText( LCUI_Widget widget, const char *utf8_str ); -/** ΪÎı¾¿ò׷¼ÓÎı¾£¨¿í×ַû°棩 */ +/** 为文本框追加文本(宽字符版) */ LCUI_API int TextEdit_AppendTextW( LCUI_Widget widget, const wchar_t *wstr ); -/** ΪÎı¾¿ò²åÈëÎı¾£¨¿í×ַû°棩 */ +/** 为文本框插入文本(宽字符版) */ LCUI_API int TextEdit_InsertTextW( LCUI_Widget widget, const wchar_t *wstr ); LCUI_END_HEADER diff --git a/src/font/textlayer.c b/src/font/textlayer.c index 8368d833..2aaf07f9 100644 --- a/src/font/textlayer.c +++ b/src/font/textlayer.c @@ -666,10 +666,8 @@ static void TextLayer_TextTypeset( LCUI_TextLayer layer, int start_row ) } /** 对文本进行预处理 */ -static int TextLayer_ProcessText( LCUI_TextLayer layer, - const wchar_t *wstr, - int add_type, - LinkedList *tags ) +static int TextLayer_ProcessText( LCUI_TextLayer layer, const wchar_t *wstr, + int add_type, LinkedList *tags ) { EOLChar eol; TextRow txtrow; @@ -693,7 +691,7 @@ static int TextLayer_ProcessText( LCUI_TextLayer layer, } else { cur_row = 0; } - txtrow = TextLayer_GetRow( layer, cur_row ); + txtrow = TextLayer_GetRow( layer, cur_row ); if( !txtrow ) { txtrow = TextRowList_AddNewRow( &layer->rowlist ); } @@ -715,8 +713,8 @@ static int TextLayer_ProcessText( LCUI_TextLayer layer, StyleTags_Init( &tmp_tags ); tags = &tmp_tags; } - p_end = wstr + wcslen(wstr); - for( p=wstr; pis_using_style_tags ) { pp = StyleTags_ScanEndingTag( tags, p ); @@ -739,7 +737,7 @@ static int TextLayer_ProcessText( LCUI_TextLayer layer, if( *p == '\r' || *p == '\n' ) { /* 判断是哪一种换行模式 */ if( *p == '\r' ) { - if( p+1 < p_end && *(p+1) == '\n' ) { + if( p + 1 < p_end && *(p + 1) == '\n' ) { eol = EOL_CR_LF; } else { eol = EOL_CR; @@ -1056,7 +1054,7 @@ int TextLayer_Backspace( LCUI_TextLayer layer, int n_char ) char_x = layer->insert_x; char_y = layer->insert_y; /* 再计算删除 n_char 个字后的位置 */ - for( n_del=n_char; char_y>=0; --char_y ) { + for( n_del = n_char; char_y >= 0; --char_y ) { txtrow = layer->rowlist.rows[char_y]; /* 如果不是当前行,则重定位至行尾 */ if( char_y < layer->insert_y ) { @@ -1083,8 +1081,8 @@ int TextLayer_Backspace( LCUI_TextLayer layer, int n_char ) TextLayer_DeleteText( layer, char_y, char_x, n_char ); /* 若最后一行被完全移除,则移动输入点至上一行的行尾处 */ if( char_x == 0 && layer->rowlist.length > 0 - && char_y >= layer->rowlist.length ) { - char_y = layer->rowlist.length-1; + && char_y >= layer->rowlist.length ) { + char_y = layer->rowlist.length - 1; char_x = layer->rowlist.rows[char_y]->length; } /* 更新文本光标的位置 */ @@ -1325,3 +1323,9 @@ void TextLayer_SetLineHeight( LCUI_TextLayer layer, LCUI_Style val ) layer->task.update_typeset = TRUE; layer->task.typeset_start_row = 0; } + +void TextLayer_SetOffset( LCUI_TextLayer layer, int offset_x, int offset_y ) +{ + layer->new_offset_x = offset_x; + layer->new_offset_y = offset_y; +} diff --git a/src/font/textstyle.c b/src/font/textstyle.c index bf538656..6fdf96d0 100755 --- a/src/font/textstyle.c +++ b/src/font/textstyle.c @@ -151,15 +151,9 @@ int TextStyle_SetFont( LCUI_TextStyle *ts, const char *str ) /*-------------------------- StyleTag --------------------------------*/ #define MAX_TAG_NUM 2 -static void DestroyTag( LCUI_StyleTag *tag ) -{ - free( tag ); - // XXX -} - void StyleTags_Clear( LinkedList *tags ) { - LinkedList_Clear( tags, (FuncPtr)DestroyTag ); + LinkedList_Clear( tags, free ); } /** 获取当前的文本样式 */ diff --git a/src/gui/widget/textedit.c b/src/gui/widget/textedit.c index d78b4932..76488f50 100644 --- a/src/gui/widget/textedit.c +++ b/src/gui/widget/textedit.c @@ -55,6 +55,7 @@ enum TaskType { TASK_SET_TEXT, + TASK_UPDATE, TASK_TOTAL }; @@ -106,6 +107,7 @@ typedef struct LCUI_TextBlockRec_ { static const char *textcaret_css = ToString( textcaret { pointer-events: none; + focusable: false; width: 1px; height:14px; position: absolute; @@ -219,12 +221,26 @@ static void TextEdit_UpdateCaret( LCUI_Widget widget ) LCUI_TextEdit edit = widget->private_data; if( TextLayer_GetCaretPixelPos( edit->text, &pos ) == 0 ) { int row = edit->text->insert_y; + int offset_x = 0, offset_y = 0; int height = TextLayer_GetRowHeight( edit->text, row ); LCUI_StyleSheet sheet = edit->caret->custom_style; SetStyle( sheet, key_height, height, px ); pos.x += widget->padding.left; pos.y += widget->padding.top; + if( pos.x > widget->box.content.width ) { + offset_x = widget->box.content.width - pos.x; + offset_x -= edit->caret->width; + pos.x += offset_x; + } + if( pos.y > widget->box.content.height ) { + offset_y = widget->box.content.height - pos.y; + offset_y -= edit->caret->height; + pos.y += offset_y; + } + TextLayer_SetOffset( edit->text, offset_x, offset_y ); Widget_Move( edit->caret, pos.x, pos.y ); + edit->tasks[TASK_UPDATE] = TRUE; + Widget_AddTask( widget, WTT_USER ); } TextCaret_BlinkShow( edit->caret ); } @@ -348,6 +364,7 @@ static void TextEdit_UpdateTextLayer( LCUI_Widget widget ) LinkedListNode *node; LinkedList_Init( &rects ); edit = widget->private_data; + TextLayer_Update( edit->text, &rects ); LinkedList_ForEach( node, &rects ) { Widget_InvalidateArea( widget, node->data, SV_CONTENT_BOX ); } @@ -369,18 +386,30 @@ static void TextEdit_OnTask( LCUI_Widget widget ) TextEdit_ProcTextBlock( widget, node->data ); } LinkedList_Clear( &blocks, TextBlock_OnDestroy ); + edit->tasks[TASK_SET_TEXT] = FALSE; + edit->tasks[TASK_UPDATE] = TRUE; + TextEdit_UpdateCaret( widget ); } TextEdit_UpdateTextLayer( widget ); + edit->tasks[TASK_UPDATE] = FALSE; } static void TextEdit_AutoSize( LCUI_Widget widget, int *width, int *height ) { - LCUI_TextEdit edit = widget->private_data; + LCUI_TextEdit edit; + edit = widget->private_data; if( edit->is_multiline_mode ) { - return; + int i, n; + *height = 0; + n = TextLayer_GetRowTotal( edit->text ); + n = n > 3 ? 3 : n; + for( i = 0; i < n; ++i ) { + *height += TextLayer_GetRowHeight( edit->text, i ); + } + } else { + *height = TextLayer_GetHeight( edit->text ); } - *width = TextLayer_GetWidth( edit->text ); - *height = TextLayer_GetHeight( edit->text ); + *width = 176; } /*----------------------------- End TextBlock ---------------------------------*/ @@ -396,11 +425,11 @@ void TextEdit_SetUsingStyleTags( LCUI_Widget widget, LCUI_BOOL is_true ) void TextEdit_SetMultiline( LCUI_Widget widget, LCUI_BOOL is_true ) { LCUI_TextEdit edit = widget->private_data; - TextLayer_SetMultiline( edit->text, is_true ); + TextLayer_SetMultiline( edit->source_text, is_true ); + TextLayer_SetMultiline( edit->mask_text, is_true ); edit->is_multiline_mode = is_true; } -/** 清空文本内容 */ void TextEdit_ClearText( LCUI_Widget widget ) { LCUI_TextEdit edit; @@ -414,7 +443,12 @@ void TextEdit_ClearText( LCUI_Widget widget ) Widget_Unlock( widget ); } -/** 为文本框设置文本(宽字符版) */ +int TextEdit_GetTextW( LCUI_Widget widget, int start, int max_len, wchar_t *buf ) +{ + LCUI_TextEdit edit = widget->private_data; + return TextLayer_GetTextW( edit->source_text, start, max_len, buf ); +} + int TextEdit_SetTextW( LCUI_Widget widget, const wchar_t *wstr ) { TextEdit_ClearText( widget ); @@ -474,6 +508,8 @@ static void TextEdit_TextBackspace( LCUI_Widget widget, int n_ch ) LCUIMutex_Lock( &edit->mutex ); TextLayer_Backspace( edit->text, n_ch ); TextCaret_BlinkShow( edit->caret ); + edit->tasks[TASK_UPDATE] = TRUE; + Widget_AddTask( widget, WTT_USER ); LCUIMutex_Unlock( &edit->mutex ); Widget_Unlock( widget ); } @@ -486,6 +522,8 @@ static void TextEdit_TextDelete(LCUI_Widget widget, int n_ch ) LCUIMutex_Lock( &edit->mutex ); TextLayer_Delete( edit->text, n_ch ); TextCaret_BlinkShow( edit->caret ); + edit->tasks[TASK_UPDATE] = TRUE; + Widget_AddTask( widget, WTT_USER ); LCUIMutex_Unlock( &edit->mutex ); Widget_Unlock( widget ); } @@ -537,52 +575,64 @@ static void TextEdit_OnKeyDown( LCUI_Widget widget, LCUI_WidgetEvent e, void *ar break; case LCUIKEY_BACKSPACE: // 删除光标左边的字符 TextEdit_TextBackspace( widget, 1 ); - break; + return; case LCUIKEY_DELETE: // 删除光标右边的字符 TextEdit_TextDelete( widget, 1 ); - break; + return; default:break; } TextEdit_MoveCaret( widget, cur_row, cur_col ); } /** 处理输入法对文本框输入的内容 */ -static void TextEdit_OnInput( LCUI_Widget widget, LCUI_WidgetEvent e, void *arg ) +static void TextEdit_OnTextInput( LCUI_Widget widget, + LCUI_WidgetEvent e, void *arg ) { - uint_t i; - LCUI_TextEdit edit; - wchar_t *ptr, *tmp_ptr, *ptr_last; - - ptr = e->input.text; - edit = widget->private_data; - ptr_last = ptr + sizeof( e->input.text ) / sizeof( wchar_t ); + uint_t i, j, k; + wchar_t ch, *text, excludes[8] = L"\b\r\t"; + LCUI_TextEdit edit = widget->private_data; + /* 如果不是多行文本编辑模式则删除换行符 */ + if( !edit->is_multiline_mode ) { + wcscat( excludes, L"\n" ); + } /* 如果文本框是只读的 */ if( edit->is_read_only ) { return; } - for( ; ptr < ptr_last && *ptr != '\0'; ++ptr ) { - if( edit->allow_input_char ) { - /* 判断当前字符是否为限制范围内的字符 */ - for( i = 0; i < edit->allow_input_char[i]; ++i ) { - if( edit->allow_input_char[i] == *ptr ) { - break; - } + text = malloc( sizeof( wchar_t ) * (e->text.length + 1) ); + if( !text ) { + return; + } + for( i = 0, j = 0; i < e->text.length; ++i ) { + ch = e->text.text[i]; + for( k = 0; excludes[k]; ++k ) { + if( ch == excludes[k] ) { + break; } - /* 如果已提前结束循环,则表明当前字符是允许的 */ - if( edit->allow_input_char[i] ) { - continue; - } - } else { + } + if( excludes[k] ) { continue; } - /* 否则不是允许的字符,需移除该字符 */ - tmp_ptr = ptr; - while( tmp_ptr < ptr_last && *tmp_ptr != '\0' ) { - *tmp_ptr = *(tmp_ptr + 1); - ++tmp_ptr; + if( !edit->allow_input_char ) { + text[j++] = ch; + continue; } + /* 判断当前字符是否为限制范围内的字符 */ + for( j = 0; edit->allow_input_char[j]; ++j ) { + if( edit->allow_input_char[j] == ch ) { + break; + } + } + /* 如果已提前结束循环,则表明当前字符是允许的 */ + if( edit->allow_input_char[j] ) { + text[j++] = e->text.text[i]; + continue; + } + text[j] = 0; } - TextEdit_InsertTextW( widget, e->input.text ); + text[j] = 0; + TextEdit_InsertTextW( widget, text ); + free( text ); } static void TextEdit_OnResize( LCUI_Widget w, LCUI_WidgetEvent e, void *arg ) @@ -607,10 +657,40 @@ static void TextEdit_OnResize( LCUI_Widget w, LCUI_WidgetEvent e, void *arg ) TextLayer_ClearInvalidRect( edit->text ); } -static void TextEdit_OnInit( LCUI_Widget widget ) +static void TextEdit_OnMouseMove( LCUI_Widget w, LCUI_WidgetEvent e, void *arg ) +{ + int abs_x, abs_y, x, y; + LCUI_TextEdit edit = w->private_data; + Widget_GetAbsXY( w, NULL, &abs_x, &abs_y ); + x = e->motion.x - abs_x - w->padding.left; + y = e->motion.y - abs_y - w->padding.top; + TextLayer_SetCaretPosByPixelPos( edit->text, x, y ); + TextEdit_UpdateCaret( w ); +} + +static void TextEdit_OnMouseUp( LCUI_Widget w, LCUI_WidgetEvent e, void *arg ) +{ + Widget_ReleaseMouseCapture( w ); + Widget_UnbindEvent( w, "mousemove", TextEdit_OnMouseMove ); +} + +static void TextEdit_OnMouseDown( LCUI_Widget w, LCUI_WidgetEvent e, void *arg ) +{ + int abs_x, abs_y, x, y; + LCUI_TextEdit edit = w->private_data; + Widget_GetAbsXY( w, NULL, &abs_x, &abs_y ); + x = e->motion.x - abs_x - w->padding.left; + y = e->motion.y - abs_y - w->padding.top; + TextLayer_SetCaretPosByPixelPos( edit->text, x, y ); + TextEdit_UpdateCaret( w ); + Widget_SetMouseCapture( w ); + Widget_BindEvent( w, "mousemove", TextEdit_OnMouseMove, NULL, NULL ); +} + +static void TextEdit_OnInit( LCUI_Widget w ) { LCUI_TextEdit edit; - edit = Widget_NewPrivateData( widget, LCUI_TextEditRec ); + edit = Widget_NewPrivateData( w, LCUI_TextEditRec ); edit->is_read_only = FALSE; edit->password_char = 0; edit->allow_input_char = NULL; @@ -622,16 +702,18 @@ static void TextEdit_OnInit( LCUI_Widget widget ) edit->caret = LCUIWidget_New( "textcaret" ); LinkedList_Init( &edit->text_blocks ); StyleTags_Init( &edit->text_tags ); - TextEdit_SetMultiline( widget, FALSE ); + TextEdit_SetMultiline( w, FALSE ); TextLayer_SetAutoWrap( edit->text, TRUE ); TextLayer_SetAutoWrap( edit->mask_text, TRUE ); TextLayer_SetUsingStyleTags( edit->text, FALSE ); - Widget_BindEvent( widget, "keydown", TextEdit_OnKeyDown, NULL, NULL ); - Widget_BindEvent( widget, "resize", TextEdit_OnResize, NULL, NULL ); - Widget_BindEvent( widget, "input", TextEdit_OnInput, NULL, NULL ); - Widget_BindEvent( widget, "focus", TextEdit_OnFocus, NULL, NULL ); - Widget_BindEvent( widget, "blur", TextEdit_OnBlur, NULL, NULL ); - Widget_Append( widget, edit->caret ); + Widget_BindEvent( w, "textinput", TextEdit_OnTextInput, NULL, NULL ); + Widget_BindEvent( w, "mousedown", TextEdit_OnMouseDown, NULL, NULL ); + Widget_BindEvent( w, "mouseup", TextEdit_OnMouseUp, NULL, NULL ); + Widget_BindEvent( w, "keydown", TextEdit_OnKeyDown, NULL, NULL ); + Widget_BindEvent( w, "resize", TextEdit_OnResize, NULL, NULL ); + Widget_BindEvent( w, "focus", TextEdit_OnFocus, NULL, NULL ); + Widget_BindEvent( w, "blur", TextEdit_OnBlur, NULL, NULL ); + Widget_Append( w, edit->caret ); Widget_Hide( edit->caret ); LCUIMutex_Init( &edit->mutex ); } From 2566d60664691d308665813ccc80926044cf218c Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Wed, 22 Jun 2016 21:59:11 +0800 Subject: [PATCH 058/124] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20textedit=20?= =?UTF-8?q?=E7=9A=84=E5=B0=BA=E5=AF=B8=E8=AE=A1=E7=AE=97=E3=80=81=E4=B8=BA?= =?UTF-8?q?=20Widget=5FExecDestroy()=20=E5=87=BD=E6=95=B0=E8=A1=A5?= =?UTF-8?q?=E5=85=85=E6=9E=90=E6=9E=84=E5=87=BD=E6=95=B0=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gui/widget/textedit.c | 5 ++++- src/gui/widget_base.c | 5 +++++ src/ime.c | 3 ++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/gui/widget/textedit.c b/src/gui/widget/textedit.c index 76488f50..cd07891a 100644 --- a/src/gui/widget/textedit.c +++ b/src/gui/widget/textedit.c @@ -119,7 +119,7 @@ static const char *textedit_css = ToString( textedit { min-width: 124px; -min-height:14px; +min-height: 14px; background-color: #fff; border: 1px solid #eee; padding: 5px 10px; @@ -410,6 +410,9 @@ static void TextEdit_AutoSize( LCUI_Widget widget, int *width, int *height ) *height = TextLayer_GetHeight( edit->text ); } *width = 176; + if( widget->computed_style.box_sizing != SV_CONTENT_BOX ) { + *height += widget->padding.top + widget->padding.bottom; + } } /*----------------------------- End TextBlock ---------------------------------*/ diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index a0438f1f..fdbdb50d 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -244,10 +244,15 @@ static void Widget_OnDestroy( void *arg ) void Widget_ExecDestroy( LCUI_Widget widget ) { + LCUI_WidgetClass *wc; + wc = LCUIWidget_GetClass( widget->type ); Widget_ReleaseMouseCapture( widget ); Widget_ReleaseTouchCapture( widget, -1 ); Widget_StopEventPropagation( widget ); LCUIWidget_ClearEventTarget( widget ); + if( wc && wc->methods.destroy ) { + wc->methods.destroy( widget ); + } /* 先释放显示列表,后销毁部件列表,因为部件在这两个链表中的节点是和它共用 * 一块内存空间的,销毁部件列表会把部件释放掉,所以把这个操作放在后面 */ LinkedList_ClearData( &widget->children_show, NULL ); diff --git a/src/ime.c b/src/ime.c index 25604ffc..a7805e43 100644 --- a/src/ime.c +++ b/src/ime.c @@ -38,6 +38,7 @@ * ****************************************************************************/ #include +#include #include #include #include @@ -317,7 +318,7 @@ int LCUIIME_ClearTarget( void ) return -1; } -int LCUI_RegisterDefaultIME( void ); +static int LCUI_RegisterDefaultIME( void ); /* 初始化LCUI输入法模块 */ void LCUI_InitIME( void ) From dd091d9038f715bcaf45613e09985ddbc41c4069 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Thu, 23 Jun 2016 20:50:18 +0800 Subject: [PATCH 059/124] =?UTF-8?q?=E4=B8=BA=20textedit=20=E9=83=A8?= =?UTF-8?q?=E4=BB=B6=E6=B7=BB=E5=8A=A0=E5=8D=A0=E4=BD=8D=E7=AC=A6=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E3=80=81=E6=9B=B4=E6=96=B0=20textlayer.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/font/textlayer.h | 12 +- include/LCUI/font/textstyle.h | 2 + include/LCUI/gui/widget/textedit.h | 5 + src/font/textlayer.c | 40 +++- src/font/textstyle.c | 19 +- src/gui/widget/textedit.c | 311 +++++++++++++++++++---------- 6 files changed, 267 insertions(+), 122 deletions(-) diff --git a/include/LCUI/font/textlayer.h b/include/LCUI/font/textlayer.h index 1307b594..f6c9928c 100755 --- a/include/LCUI/font/textlayer.h +++ b/include/LCUI/font/textlayer.h @@ -42,12 +42,6 @@ LCUI_BEGIN_HEADER -/** 文本添加类型 */ -enum TextAddType { - TEXT_ADD_TYPE_INSERT, /**< 插入至插入点处 */ - TEXT_ADD_TYPE_APPEND /**< 追加至文本末尾 */ -}; - typedef struct TextCharRec_ { wchar_t char_code; /**< 字符码 */ LCUI_TextStyle *style; /**< 该字符使用的样式数据 */ @@ -87,12 +81,12 @@ typedef struct LCUI_TextLayerRec_ { int insert_y; /**< 光标所在行数 */ int max_width; /**< 最大文本宽度 */ int max_height; /**< 最大文本高度 */ + int length; /**< 文本长度 */ LCUI_BOOL is_mulitiline_mode; /**< 是否启用多行文本模式 */ LCUI_BOOL is_autowrap_mode; /**< 是否启用自动换行模式 */ LCUI_BOOL is_using_style_tags; /**< 是否使用文本样式标签 */ LCUI_BOOL is_using_buffer; /**< 是否使用缓存空间来存储文本位图 */ LinkedList dirty_rect; /**< 脏矩形记录 */ - int text_align; /**< 文本的对齐方式 */ TextRowListRec rowlist; /**< 文本行列表 */ LCUI_TextStyle text_style; /**< 文本全局样式 */ @@ -203,10 +197,10 @@ LCUI_API int TextLayer_SetMaxSize( LCUI_TextLayer layer, LCUI_Size new_size ); LCUI_API void TextLayer_SetMultiline( LCUI_TextLayer layer, int is_true ); /** 删除文本光标的当前坐标右边的文本 */ -LCUI_API int TextLayer_Delete( LCUI_TextLayer layer, int n_char ); +LCUI_API int TextLayer_TextDelete( LCUI_TextLayer layer, int n_char ); /** 退格删除文本,即删除文本光标的当前坐标左边的文本 */ -LCUI_API int TextLayer_Backspace( LCUI_TextLayer layer, int n_char ); +LCUI_API int TextLayer_TextBackspace( LCUI_TextLayer layer, int n_char ); /** 设置是否启用自动换行模式 */ LCUI_API void TextLayer_SetAutoWrap( LCUI_TextLayer layer, int is_true ); diff --git a/include/LCUI/font/textstyle.h b/include/LCUI/font/textstyle.h index b47ff837..a4ffbeaa 100755 --- a/include/LCUI/font/textstyle.h +++ b/include/LCUI/font/textstyle.h @@ -86,6 +86,8 @@ typedef struct LCUI_TextStyle { /** 初始化字体样式数据 */ LCUI_API void TextStyle_Init ( LCUI_TextStyle *data ); +LCUI_API int TextStyle_Copy( LCUI_TextStyle *dst, LCUI_TextStyle *src ); + LCUI_API void TextStyle_Destroy( LCUI_TextStyle *data ); /** diff --git a/include/LCUI/gui/widget/textedit.h b/include/LCUI/gui/widget/textedit.h index a31a1284..afb4b7e1 100644 --- a/include/LCUI/gui/widget/textedit.h +++ b/include/LCUI/gui/widget/textedit.h @@ -66,6 +66,11 @@ LCUI_API int TextEdit_AppendTextW( LCUI_Widget widget, const wchar_t *wstr ); /** 为文本框插入文本(宽字符版) */ LCUI_API int TextEdit_InsertTextW( LCUI_Widget widget, const wchar_t *wstr ); +/** 设置占位符,当文本编辑框内容为空时显示占位符 */ +LCUI_API int TextEdit_SetPlaceHolderW( LCUI_Widget w, const wchar_t *wstr ); + +LCUI_API int TextEdit_SetPlaceHolder( LCUI_Widget w, const char *str ); + LCUI_END_HEADER #endif \ No newline at end of file diff --git a/src/font/textlayer.c b/src/font/textlayer.c index 2aaf07f9..544a7bfc 100644 --- a/src/font/textlayer.c +++ b/src/font/textlayer.c @@ -43,6 +43,12 @@ #include #include + /** 文本添加类型 */ +enum TextAddType { + TAT_INSERT, /**< 插入至插入点处 */ + TAT_APPEND /**< 追加至文本末尾 */ +}; + #define TextRowList_AddNewRow(ROWLIST) TextRowList_InsertNewRow(ROWLIST, (ROWLIST)->length) #define TextLayer_GetRow(layer, n) (n >= layer->rowlist.length) ? NULL:layer->rowlist.rows[n] @@ -288,6 +294,7 @@ LCUI_TextLayer TextLayer_New(void) { LCUI_TextLayer layer; layer = malloc( sizeof( LCUI_TextLayerRec ) ); + layer->length = 0; layer->offset_x = 0; layer->offset_y = 0; layer->insert_x = 0; @@ -538,11 +545,13 @@ int TextLayer_GetCaretPixelPos( LCUI_TextLayer layer, LCUI_Pos *pixel_pos ) /** 清空文本 */ void TextLayer_ClearText( LCUI_TextLayer layer ) { + layer->length = 0; layer->insert_x = 0; layer->insert_y = 0; TextLayer_InvalidateRowsRect( layer, 0, -1 ); TextRowList_Destroy( &layer->rowlist ); LinkedList_Clear( &layer->style_cache, (FuncPtr)TextStyle_Destroy ); + TextRowList_InsertNewRow( &layer->rowlist, 0 ); layer->task.redraw_all = TRUE; } @@ -685,7 +694,7 @@ static int TextLayer_ProcessText( LCUI_TextLayer layer, const wchar_t *wstr, rect_has_added = FALSE; is_tmp_tag_stack = FALSE; /* 如果是将文本追加至文本末尾 */ - if( add_type == TEXT_ADD_TYPE_APPEND ) { + if( add_type == TAT_APPEND ) { if( layer->rowlist.length > 0 ) { cur_row = layer->rowlist.length - 1; } else { @@ -754,6 +763,7 @@ static int TextLayer_ProcessText( LCUI_TextLayer layer, const wchar_t *wstr, /* 将当前行中的插入点为截点,进行断行 */ TextLayer_BreakTextRow( layer, ins_y, ins_x, eol ); need_typeset = TRUE; + ++layer->length; ins_x = 0; ++ins_y; txtrow = TextLayer_GetRow( layer, ins_y ); @@ -763,11 +773,12 @@ static int TextLayer_ProcessText( LCUI_TextLayer layer, const wchar_t *wstr, txtchar.char_code = *p; TextChar_UpdateBitmap( &txtchar, &layer->text_style ); TextRow_InsertCopy( txtrow, ins_x, &txtchar ); + ++layer->length; ++ins_x; } /* 更新当前行的尺寸 */ TextLayer_UpdateRowSize( layer, txtrow ); - if( add_type == TEXT_ADD_TYPE_INSERT ) { + if( add_type == TAT_INSERT ) { layer->insert_x = ins_x; layer->insert_y = ins_y; } @@ -793,7 +804,7 @@ static int TextLayer_ProcessText( LCUI_TextLayer layer, const wchar_t *wstr, int TextLayer_InsertTextW( LCUI_TextLayer layer, const wchar_t *wstr, LinkedList *tag_stack ) { - return TextLayer_ProcessText( layer, wstr, TEXT_ADD_TYPE_INSERT, + return TextLayer_ProcessText( layer, wstr, TAT_INSERT, tag_stack ); } @@ -813,7 +824,7 @@ int TextLayer_InsertText( LCUI_TextLayer layer, const char *utf8_str ) int TextLayer_AppendTextW( LCUI_TextLayer layer, const wchar_t *wstr, LinkedList *tag_stack ) { - return TextLayer_ProcessText( layer, wstr, TEXT_ADD_TYPE_APPEND, + return TextLayer_ProcessText( layer, wstr, TAT_APPEND, tag_stack ); } @@ -919,8 +930,8 @@ void TextLayer_SetMultiline( LCUI_TextLayer layer, int is_true ) } /** 删除指定行列的文字及其右边的文本 */ -static int TextLayer_DeleteText( LCUI_TextLayer layer, int char_y, - int char_x, int n_char ) +static int TextLayer_TextDeleteEx( LCUI_TextLayer layer, int char_y, + int char_x, int n_char ) { int end_x, end_y, i, j, len; TextRow txtrow, end_txtrow, prev_txtrow; @@ -941,6 +952,7 @@ static int TextLayer_DeleteText( LCUI_TextLayer layer, int char_y, if( char_x > txtrow->length ) { char_x = txtrow->length; } + j = n_char; --n_char; end_x = char_x; end_y = char_y; @@ -963,6 +975,11 @@ static int TextLayer_DeleteText( LCUI_TextLayer layer, int char_y, n_char -= (txtrow->length - end_x); end_x = 0; } + if( n_char >= 0 ) { + layer->length -= j - n_char; + } else { + layer->length -= n_char; + } if( end_y >= layer->rowlist.length ) { end_y = layer->rowlist.length - 1; } @@ -1037,14 +1054,14 @@ static int TextLayer_DeleteText( LCUI_TextLayer layer, int char_y, } /** 删除文本光标的当前坐标右边的文本 */ -int TextLayer_Delete( LCUI_TextLayer layer, int n_char ) +int TextLayer_TextDelete( LCUI_TextLayer layer, int n_char ) { - return TextLayer_DeleteText( layer, layer->insert_y, + return TextLayer_TextDeleteEx( layer, layer->insert_y, layer->insert_x, n_char ); } /** 退格删除文本,即删除文本光标的当前坐标左边的文本 */ -int TextLayer_Backspace( LCUI_TextLayer layer, int n_char ) +int TextLayer_TextBackspace( LCUI_TextLayer layer, int n_char ) { int n_del; int char_x, char_y; @@ -1078,7 +1095,7 @@ int TextLayer_Backspace( LCUI_TextLayer layer, int n_char ) n_char -= n_del; } /* 开始删除文本 */ - TextLayer_DeleteText( layer, char_y, char_x, n_char ); + TextLayer_TextDeleteEx( layer, char_y, char_x, n_char ); /* 若最后一行被完全移除,则移动输入点至上一行的行尾处 */ if( char_x == 0 && layer->rowlist.length > 0 && char_y >= layer->rowlist.length ) { @@ -1304,7 +1321,8 @@ void TextLayer_ClearInvalidRect( LCUI_TextLayer layer ) /** 设置全局文本样式 */ void TextLayer_SetTextStyle( LCUI_TextLayer layer, LCUI_TextStyle *style ) { - layer->text_style = *style; + TextStyle_Destroy( &layer->text_style ); + TextStyle_Copy( &layer->text_style, style ); layer->task.update_bitmap = TRUE; } diff --git a/src/font/textstyle.c b/src/font/textstyle.c index 6fdf96d0..2c9d18fc 100755 --- a/src/font/textstyle.c +++ b/src/font/textstyle.c @@ -39,6 +39,7 @@ #include #include +#include #include #include #include @@ -57,7 +58,6 @@ typedef struct LCUI_StyleTag { LCUI_StyleRec style; } LCUI_StyleTag; -/** 初始化字体样式数据 */ void TextStyle_Init( LCUI_TextStyle *data ) { data->has_style = FALSE; @@ -75,6 +75,23 @@ void TextStyle_Init( LCUI_TextStyle *data ) data->pixel_size = 13; } +int TextStyle_Copy( LCUI_TextStyle *dst, LCUI_TextStyle *src ) +{ + int len; + *dst = *src; + if( !dst->has_family ) { + return 0; + } + for( len = 0; dst->font_ids[len] != -1; ++len ); + len += 1; + dst->font_ids = malloc( len * sizeof( int ) ); + if( !dst->font_ids ) { + return -ENOMEM; + } + memcpy( dst->font_ids, src->font_ids, len * sizeof( int ) ); + return 0; +} + void TextStyle_Destroy( LCUI_TextStyle *data ) { if( data->font_ids ) { diff --git a/src/gui/widget/textedit.c b/src/gui/widget/textedit.c index cd07891a..d25253d8 100644 --- a/src/gui/widget/textedit.c +++ b/src/gui/widget/textedit.c @@ -51,11 +51,12 @@ #define CARET_HIDE 0 #define CARET_SHOW 1 -#define TEXT_BLOCK_SIZE 512 +#define TBT_SIZE 512 enum TaskType { TASK_SET_TEXT, TASK_UPDATE, + TASK_UPDATE_CARET, TASK_TOTAL }; @@ -69,35 +70,45 @@ typedef struct LCUI_TextCaretRec_ { } LCUI_TextCaretRec, *LCUI_TextCaret; typedef struct LCUI_TextEditRec_ { - LCUI_TextLayer source_text; /**< 实际文本层 */ - LCUI_TextLayer mask_text; /**< 屏蔽后的文本层 */ - LCUI_TextLayer text; /**< 当前使用的文本层 */ + LCUI_TextLayer layer_source; /**< 实际文本层 */ + LCUI_TextLayer layer_mask; /**< 屏蔽后的文本层 */ + LCUI_TextLayer layer_placeholder; /**< 占位符的文本层 */ + LCUI_TextLayer layer; /**< 当前使用的文本层 */ LCUI_Widget scrollbars[2]; /**< 两个滚动条 */ LCUI_Widget caret; /**< 文本插入符 */ LCUI_BOOL is_read_only; /**< 是否只读 */ LCUI_BOOL is_multiline_mode; /**< 是否为多行模式 */ - int block_size; /**< 块大小 */ - LinkedList text_blocks; /**< 文本块缓冲区 */ - LinkedList text_tags; /**< 当前处理的标签列表 */ - LCUI_BOOL show_placeholder; /**< 表示占位符是否已经显示 */ - wchar_t *placeholder; /**< 文本框的占位符 */ + LCUI_BOOL is_placeholder_shown; /**< 是否已经显示占位符 */ + wchar_t *placeholder; /**< 占位符 */ wchar_t *allow_input_char; /**< 允许输入的字符 */ wchar_t password_char; /**< 屏蔽符的副本 */ - LCUI_TextStyle placeholder_style; /**< 占位符的文本样式 */ - LCUI_TextStyle textstyle_bak; /**< 文本框内文本样式的副本 */ + int text_block_size; /**< 块大小 */ + LinkedList text_blocks; /**< 文本块缓冲区 */ + LinkedList text_tags; /**< 当前处理的标签列表 */ LCUI_BOOL tasks[TASK_TOTAL]; /**< 待处理的任务 */ LCUI_Mutex mutex; /**< 互斥锁 */ } LCUI_TextEditRec, *LCUI_TextEdit; -enum TextBlockType_ { - TEXT_BLOCK_BEGIN, - TEXT_BLOCK_BODY, - TEXT_BLOCK_END +enum TextBlockType { + TBT_BEGIN, + TBT_BODY, + TBT_END +}; + +enum TextBlockAddType { + TBAT_INSERT, + TBAT_APPEND +}; + +enum TextBlockOwnerType { + TBOT_SOURCE, + TBOT_PLACEHOLDER }; /** 文本块数据结构 */ typedef struct LCUI_TextBlockRec_ { int type; /**< 文本块类型 */ + int owner; /**< 所属的文本层 */ int add_type; /**< 指定该文本块的添加方式 */ wchar_t *text; /**< 文本块(段) */ } LCUI_TextBlockRec, *LCUI_TextBlock; @@ -218,30 +229,37 @@ static void LCUIWidget_AddTextCaret( void ) static void TextEdit_UpdateCaret( LCUI_Widget widget ) { LCUI_Pos pos; + LCUI_StyleSheet sheet; LCUI_TextEdit edit = widget->private_data; - if( TextLayer_GetCaretPixelPos( edit->text, &pos ) == 0 ) { - int row = edit->text->insert_y; - int offset_x = 0, offset_y = 0; - int height = TextLayer_GetRowHeight( edit->text, row ); - LCUI_StyleSheet sheet = edit->caret->custom_style; - SetStyle( sheet, key_height, height, px ); - pos.x += widget->padding.left; - pos.y += widget->padding.top; - if( pos.x > widget->box.content.width ) { - offset_x = widget->box.content.width - pos.x; - offset_x -= edit->caret->width; - pos.x += offset_x; + int offset_x = 0, offset_y = 0, height, row; + + if( edit->is_placeholder_shown ) { + pos.x = pos.y = 0; + } else { + if( TextLayer_GetCaretPixelPos( edit->layer, &pos ) != 0 ) { + return; } - if( pos.y > widget->box.content.height ) { - offset_y = widget->box.content.height - pos.y; - offset_y -= edit->caret->height; - pos.y += offset_y; - } - TextLayer_SetOffset( edit->text, offset_x, offset_y ); - Widget_Move( edit->caret, pos.x, pos.y ); - edit->tasks[TASK_UPDATE] = TRUE; - Widget_AddTask( widget, WTT_USER ); } + row = edit->layer->insert_y; + sheet = edit->caret->custom_style; + height = TextLayer_GetRowHeight( edit->layer, row ); + SetStyle( sheet, key_height, height, px ); + pos.x += widget->padding.left; + pos.y += widget->padding.top; + if( pos.x > widget->box.content.width ) { + offset_x = widget->box.content.width - pos.x; + offset_x -= edit->caret->width; + pos.x += offset_x; + } + if( pos.y > widget->box.content.height ) { + offset_y = widget->box.content.height - pos.y; + offset_y -= edit->caret->height; + pos.y += offset_y; + } + TextLayer_SetOffset( edit->layer, offset_x, offset_y ); + Widget_Move( edit->caret, pos.x, pos.y ); + edit->tasks[TASK_UPDATE] = TRUE; + Widget_AddTask( widget, WTT_USER ); TextCaret_BlinkShow( edit->caret ); } @@ -249,7 +267,10 @@ static void TextEdit_UpdateCaret( LCUI_Widget widget ) static void TextEdit_MoveCaret( LCUI_Widget widget, int row, int col ) { LCUI_TextEdit edit = widget->private_data; - TextLayer_SetCaretPos( edit->text, row, col ); + if( edit->is_placeholder_shown ) { + row = col = 0; + } + TextLayer_SetCaretPos( edit->layer, row, col ); TextEdit_UpdateCaret( widget ); } @@ -263,13 +284,16 @@ static void TextBlock_OnDestroy( void *arg ) } static int TextEdit_AddTextToBuffer( LCUI_Widget widget, const wchar_t *wtext, - int add_type ) + int add_type, int owner ) { const wchar_t *p; LCUI_TextEdit edit; LCUI_TextBlock txtblk; int i, j, len, tag_len, size; + if( !wtext ) { + return -1; + } edit = widget->private_data; len = wcslen( wtext ); for( i = 0; i < len; ++i ) { @@ -277,22 +301,23 @@ static int TextEdit_AddTextToBuffer( LCUI_Widget widget, const wchar_t *wtext, if( !txtblk ) { return -ENOMEM; } - size = edit->block_size; + txtblk->owner = owner; + txtblk->add_type = add_type; + size = edit->text_block_size; if( i == 0 ) { - txtblk->type = TEXT_BLOCK_BEGIN; - } else if( len - i > edit->block_size ) { - txtblk->type = TEXT_BLOCK_BODY; + txtblk->type = TBT_BEGIN; + } else if( len - i > edit->text_block_size ) { + txtblk->type = TBT_BODY; } else { size = len - i; - txtblk->type = TEXT_BLOCK_END; + txtblk->type = TBT_END; } - txtblk->add_type = add_type; txtblk->text = NEW( wchar_t, size ); if( !txtblk->text ) { return -ENOMEM; } /* 如果未启用样式标签功能 */ - if( !edit->text->is_using_style_tags ) { + if( !edit->layer->is_using_style_tags ) { for( j = 0; i < len && j < size - 1; ++j, ++i ) { txtblk->text[j] = wtext[i]; } @@ -339,18 +364,29 @@ static int TextEdit_AddTextToBuffer( LCUI_Widget widget, const wchar_t *wtext, /** 更新文本框内的字体位图 */ static void TextEdit_ProcTextBlock( LCUI_Widget widget, LCUI_TextBlock txtblk ) { + LinkedList *tags; LCUI_TextEdit edit; + LCUI_TextLayer layer; edit = widget->private_data; - switch( txtblk->add_type ) { - case TEXT_ADD_TYPE_APPEND: - /* 将此文本块追加至文本末尾 */ - TextLayer_AppendTextW( edit->text, txtblk->text, - &edit->text_tags ); + switch( txtblk->owner ) { + case TBOT_SOURCE: + layer = edit->layer_source; + tags = &edit->text_tags; break; - case TEXT_ADD_TYPE_INSERT: + case TBOT_PLACEHOLDER: + layer = edit->layer_placeholder; + tags = NULL; + break; + default:return; + } + switch( txtblk->add_type ) { + case TBAT_APPEND: + /* 将此文本块追加至文本末尾 */ + TextLayer_AppendTextW( layer, txtblk->text, tags ); + break; + case TBAT_INSERT: /* 将此文本块插入至文本插入符所在处 */ - TextLayer_InsertTextW( edit->text, txtblk->text, - &edit->text_tags ); + TextLayer_InsertTextW( layer, txtblk->text, tags ); default: break; } } @@ -361,21 +397,28 @@ static void TextEdit_UpdateTextLayer( LCUI_Widget widget ) { LinkedList rects; LCUI_TextEdit edit; + LCUI_TextStyle style; LinkedListNode *node; LinkedList_Init( &rects ); edit = widget->private_data; - TextLayer_Update( edit->text, &rects ); + TextLayer_Update( edit->layer, &rects ); LinkedList_ForEach( node, &rects ) { Widget_InvalidateArea( widget, node->data, SV_CONTENT_BOX ); } LinkedList_Clear( &rects, free ); - TextLayer_ClearInvalidRect( edit->text ); + TextLayer_ClearInvalidRect( edit->layer ); + TextStyle_Copy( &style, &edit->layer_source->text_style ); + style.has_fore_color = TRUE; + style.fore_color.value = 0xC8C8C8; + TextLayer_SetTextStyle( edit->layer_placeholder, &style ); + TextStyle_Destroy( &style ); } static void TextEdit_OnTask( LCUI_Widget widget ) { LCUI_TextEdit edit = widget->private_data; if( edit->tasks[TASK_SET_TEXT] ) { + LCUI_BOOL is_shown; LinkedList blocks; LinkedListNode *node; LinkedList_Init( &blocks ); @@ -386,12 +429,28 @@ static void TextEdit_OnTask( LCUI_Widget widget ) TextEdit_ProcTextBlock( widget, node->data ); } LinkedList_Clear( &blocks, TextBlock_OnDestroy ); + is_shown = edit->layer_source->length == 0; + if( is_shown ) { + edit->layer = edit->layer_placeholder; + } else { + edit->layer = edit->layer_source; + } + if( edit->is_placeholder_shown != is_shown ) { + Widget_InvalidateArea( widget, NULL, SV_PADDING_BOX ); + } + edit->is_placeholder_shown = is_shown; + edit->tasks[TASK_UPDATE_CARET] = TRUE; edit->tasks[TASK_SET_TEXT] = FALSE; edit->tasks[TASK_UPDATE] = TRUE; - TextEdit_UpdateCaret( widget ); } - TextEdit_UpdateTextLayer( widget ); - edit->tasks[TASK_UPDATE] = FALSE; + if( edit->tasks[TASK_UPDATE] ) { + TextEdit_UpdateTextLayer( widget ); + edit->tasks[TASK_UPDATE] = FALSE; + } + if( edit->tasks[TASK_UPDATE_CARET] ) { + TextEdit_UpdateCaret( widget ); + edit->tasks[TASK_UPDATE_CARET] = FALSE; + } } static void TextEdit_AutoSize( LCUI_Widget widget, int *width, int *height ) @@ -401,13 +460,13 @@ static void TextEdit_AutoSize( LCUI_Widget widget, int *width, int *height ) if( edit->is_multiline_mode ) { int i, n; *height = 0; - n = TextLayer_GetRowTotal( edit->text ); + n = TextLayer_GetRowTotal( edit->layer ); n = n > 3 ? 3 : n; for( i = 0; i < n; ++i ) { - *height += TextLayer_GetRowHeight( edit->text, i ); + *height += TextLayer_GetRowHeight( edit->layer, i ); } } else { - *height = TextLayer_GetHeight( edit->text ); + *height = TextLayer_GetHeight( edit->layer ); } *width = 176; if( widget->computed_style.box_sizing != SV_CONTENT_BOX ) { @@ -421,15 +480,15 @@ static void TextEdit_AutoSize( LCUI_Widget widget, int *width, int *height ) void TextEdit_SetUsingStyleTags( LCUI_Widget widget, LCUI_BOOL is_true ) { LCUI_TextEdit edit = widget->private_data; - TextLayer_SetUsingStyleTags( edit->text, is_true ); + TextLayer_SetUsingStyleTags( edit->layer, is_true ); } /** 指定文本框是否启用多行文本显示 */ void TextEdit_SetMultiline( LCUI_Widget widget, LCUI_BOOL is_true ) { LCUI_TextEdit edit = widget->private_data; - TextLayer_SetMultiline( edit->source_text, is_true ); - TextLayer_SetMultiline( edit->mask_text, is_true ); + TextLayer_SetMultiline( edit->layer_source, is_true ); + TextLayer_SetMultiline( edit->layer_mask, is_true ); edit->is_multiline_mode = is_true; } @@ -439,23 +498,23 @@ void TextEdit_ClearText( LCUI_Widget widget ) Widget_Lock( widget ); edit = widget->private_data; LCUIMutex_Lock( &edit->mutex ); - TextLayer_ClearText( edit->text ); + TextLayer_ClearText( edit->layer ); StyleTags_Clear( &edit->text_tags ); LCUIMutex_Unlock( &edit->mutex ); Widget_InvalidateArea( widget, NULL, SV_PADDING_BOX ); Widget_Unlock( widget ); } -int TextEdit_GetTextW( LCUI_Widget widget, int start, int max_len, wchar_t *buf ) +int TextEdit_GetTextW( LCUI_Widget w, int start, int max_len, wchar_t *buf ) { - LCUI_TextEdit edit = widget->private_data; - return TextLayer_GetTextW( edit->source_text, start, max_len, buf ); + LCUI_TextEdit edit = w->private_data; + return TextLayer_GetTextW( edit->layer_source, start, max_len, buf ); } -int TextEdit_SetTextW( LCUI_Widget widget, const wchar_t *wstr ) +int TextEdit_SetTextW( LCUI_Widget w, const wchar_t *wstr ) { - TextEdit_ClearText( widget ); - return TextEdit_AddTextToBuffer( widget, wstr, TEXT_ADD_TYPE_APPEND ); + TextEdit_ClearText( w ); + return TextEdit_AddTextToBuffer( w, wstr, TBAT_APPEND, TBOT_SOURCE ); } int TextEdit_SetText( LCUI_Widget widget, const char *utf8_str ) @@ -473,15 +532,44 @@ int TextEdit_SetText( LCUI_Widget widget, const char *utf8_str ) } /** 为文本框追加文本(宽字符版) */ -int TextEdit_AppendTextW( LCUI_Widget widget, const wchar_t *wstr ) +int TextEdit_AppendTextW( LCUI_Widget w, const wchar_t *wstr ) { - return TextEdit_AddTextToBuffer( widget, wstr, TEXT_ADD_TYPE_APPEND ); + return TextEdit_AddTextToBuffer( w, wstr, TBAT_APPEND, TBOT_SOURCE ); } /** 为文本框插入文本(宽字符版) */ -int TextEdit_InsertTextW( LCUI_Widget widget, const wchar_t *wstr ) +int TextEdit_InsertTextW( LCUI_Widget w, const wchar_t *wstr ) { - return TextEdit_AddTextToBuffer( widget, wstr, TEXT_ADD_TYPE_INSERT ); + return TextEdit_AddTextToBuffer( w, wstr, TBAT_INSERT, TBOT_SOURCE ); +} + +int TextEdit_SetPlaceHolderW( LCUI_Widget w, const wchar_t *wstr ) +{ + LCUI_TextEdit edit = w->private_data; + Widget_Lock( w ); + LCUIMutex_Lock( &edit->mutex ); + TextLayer_ClearText( edit->layer_placeholder ); + LCUIMutex_Unlock( &edit->mutex ); + if( edit->is_placeholder_shown ) { + Widget_InvalidateArea( w, NULL, SV_PADDING_BOX ); + } + Widget_Unlock( w ); + return TextEdit_AddTextToBuffer( w, wstr, TBAT_INSERT, + TBOT_PLACEHOLDER ); +} + +int TextEdit_SetPlaceHolder( LCUI_Widget w, const char *str ) +{ + int ret; + size_t len = strlen( str ) + 1; + wchar_t *wstr = malloc( len * sizeof( wchar_t ) ); + if( !wstr ) { + return -ENOMEM; + } + LCUI_DecodeString( wstr, str, len, ENCODING_UTF8 ); + ret = TextEdit_SetPlaceHolderW( w, wstr ); + free( wstr ); + return ret; } static void TextEdit_OnFocus( LCUI_Widget widget, LCUI_WidgetEvent e, void *arg ) @@ -509,7 +597,10 @@ static void TextEdit_TextBackspace( LCUI_Widget widget, int n_ch ) Widget_Lock( widget ); edit = widget->private_data; LCUIMutex_Lock( &edit->mutex ); - TextLayer_Backspace( edit->text, n_ch ); + TextLayer_TextBackspace( edit->layer_source, n_ch ); + if( edit->password_char ) { + TextLayer_TextBackspace( edit->layer_mask, n_ch ); + } TextCaret_BlinkShow( edit->caret ); edit->tasks[TASK_UPDATE] = TRUE; Widget_AddTask( widget, WTT_USER ); @@ -523,7 +614,10 @@ static void TextEdit_TextDelete(LCUI_Widget widget, int n_ch ) Widget_Lock( widget ); edit = widget->private_data; LCUIMutex_Lock( &edit->mutex ); - TextLayer_Delete( edit->text, n_ch ); + TextLayer_TextDelete( edit->layer_source, n_ch ); + if( edit->password_char ) { + TextLayer_TextDelete( edit->layer_mask, n_ch ); + } TextCaret_BlinkShow( edit->caret ); edit->tasks[TASK_UPDATE] = TRUE; Widget_AddTask( widget, WTT_USER ); @@ -538,10 +632,10 @@ static void TextEdit_OnKeyDown( LCUI_Widget widget, LCUI_WidgetEvent e, void *ar int cols, rows, cur_col, cur_row; edit = widget->private_data; - cur_row = edit->text->insert_y; - cur_col = edit->text->insert_x; - rows = TextLayer_GetRowTotal( edit->text ); - cols = TextLayer_GetRowTextLength( edit->text, cur_row ); + cur_row = edit->layer->insert_y; + cur_col = edit->layer->insert_x; + rows = TextLayer_GetRowTotal( edit->layer ); + cols = TextLayer_GetRowTextLength( edit->layer, cur_row ); switch( e->key.code ) { case LCUIKEY_HOMEPAGE: // home键移动光标至行首 cur_col = 0; @@ -554,7 +648,7 @@ static void TextEdit_OnKeyDown( LCUI_Widget widget, LCUI_WidgetEvent e, void *ar --cur_col; } else if( cur_row > 0 ) { --cur_row; - cur_col = TextLayer_GetRowTextLength( edit->text, + cur_col = TextLayer_GetRowTextLength( edit->layer, cur_row ); } break; @@ -651,23 +745,27 @@ static void TextEdit_OnResize( LCUI_Widget w, LCUI_WidgetEvent e, void *arg ) new_size.height = w->box.content.height; } LinkedList_Init( &rects ); - TextLayer_SetMaxSize( edit->text, new_size ); - TextLayer_Update( edit->text, &rects ); + TextLayer_SetMaxSize( edit->layer_mask, new_size ); + TextLayer_SetMaxSize( edit->layer_source, new_size ); + TextLayer_SetMaxSize( edit->layer_placeholder, new_size ); + TextLayer_Update( edit->layer, &rects ); LinkedList_ForEach( node, &rects ) { Widget_InvalidateArea( w, node->data, SV_CONTENT_BOX ); } LinkedList_Clear( &rects, free ); - TextLayer_ClearInvalidRect( edit->text ); + TextLayer_ClearInvalidRect( edit->layer ); } static void TextEdit_OnMouseMove( LCUI_Widget w, LCUI_WidgetEvent e, void *arg ) { int abs_x, abs_y, x, y; LCUI_TextEdit edit = w->private_data; - Widget_GetAbsXY( w, NULL, &abs_x, &abs_y ); - x = e->motion.x - abs_x - w->padding.left; - y = e->motion.y - abs_y - w->padding.top; - TextLayer_SetCaretPosByPixelPos( edit->text, x, y ); + if( !edit->is_placeholder_shown ) { + Widget_GetAbsXY( w, NULL, &abs_x, &abs_y ); + x = e->motion.x - abs_x - w->padding.left; + y = e->motion.y - abs_y - w->padding.top; + TextLayer_SetCaretPosByPixelPos( edit->layer, x, y ); + } TextEdit_UpdateCaret( w ); } @@ -684,12 +782,20 @@ static void TextEdit_OnMouseDown( LCUI_Widget w, LCUI_WidgetEvent e, void *arg ) Widget_GetAbsXY( w, NULL, &abs_x, &abs_y ); x = e->motion.x - abs_x - w->padding.left; y = e->motion.y - abs_y - w->padding.top; - TextLayer_SetCaretPosByPixelPos( edit->text, x, y ); + TextLayer_SetCaretPosByPixelPos( edit->layer, x, y ); TextEdit_UpdateCaret( w ); Widget_SetMouseCapture( w ); Widget_BindEvent( w, "mousemove", TextEdit_OnMouseMove, NULL, NULL ); } +static void TextEdit_SetAttr( LCUI_Widget w, const char *name, + const char *val ) +{ + if( strcasecmp( name, "data-placeholder" ) == 0 ) { + TextEdit_SetPlaceHolder( w, val ); + } +} + static void TextEdit_OnInit( LCUI_Widget w ) { LCUI_TextEdit edit; @@ -697,18 +803,20 @@ static void TextEdit_OnInit( LCUI_Widget w ) edit->is_read_only = FALSE; edit->password_char = 0; edit->allow_input_char = NULL; - edit->show_placeholder = FALSE; - edit->mask_text = TextLayer_New(); - edit->source_text = TextLayer_New(); - edit->text = edit->source_text; - edit->block_size = TEXT_BLOCK_SIZE; + edit->is_placeholder_shown = FALSE; + edit->layer_mask = TextLayer_New(); + edit->layer_source = TextLayer_New(); + edit->layer_placeholder = TextLayer_New(); + edit->layer = edit->layer_source; + edit->text_block_size = TBT_SIZE; + memset( edit->tasks, 0, sizeof(edit->tasks) ); edit->caret = LCUIWidget_New( "textcaret" ); LinkedList_Init( &edit->text_blocks ); StyleTags_Init( &edit->text_tags ); TextEdit_SetMultiline( w, FALSE ); - TextLayer_SetAutoWrap( edit->text, TRUE ); - TextLayer_SetAutoWrap( edit->mask_text, TRUE ); - TextLayer_SetUsingStyleTags( edit->text, FALSE ); + TextLayer_SetAutoWrap( edit->layer, TRUE ); + TextLayer_SetAutoWrap( edit->layer_mask, TRUE ); + TextLayer_SetUsingStyleTags( edit->layer, FALSE ); Widget_BindEvent( w, "textinput", TextEdit_OnTextInput, NULL, NULL ); Widget_BindEvent( w, "mousedown", TextEdit_OnMouseDown, NULL, NULL ); Widget_BindEvent( w, "mouseup", TextEdit_OnMouseUp, NULL, NULL ); @@ -724,8 +832,8 @@ static void TextEdit_OnInit( LCUI_Widget w ) static void TextEdit_OnDestroy( LCUI_Widget widget ) { LCUI_TextEdit edit = widget->private_data; - TextLayer_Destroy( edit->text ); - TextLayer_Destroy( edit->mask_text ); + TextLayer_Destroy( edit->layer ); + TextLayer_Destroy( edit->layer_mask ); LinkedList_Clear( &edit->text_blocks, TextBlock_OnDestroy ); } @@ -745,7 +853,7 @@ static void TextEdit_OnPaint( LCUI_Widget w, LCUI_PaintContext paint ) layer_pos.y = content_rect.y - paint->rect.y; rect.x -= content_rect.x; rect.y -= content_rect.y; - TextLayer_DrawToGraph( edit->text, rect, layer_pos, &paint->canvas ); + TextLayer_DrawToGraph( edit->layer, rect, layer_pos, &paint->canvas ); } /** 添加 TextEdit 部件类型 */ @@ -756,6 +864,7 @@ void LCUIWidget_AddTextEdit( void ) wc->methods.paint = TextEdit_OnPaint; wc->methods.destroy = TextEdit_OnDestroy; wc->methods.set_text = TextEdit_SetText; + wc->methods.set_attr = TextEdit_SetAttr; wc->methods.autosize = TextEdit_AutoSize; wc->task_handler = TextEdit_OnTask; LCUICSS_LoadString( textedit_css ); From 5e79adea83eb96a9cd665776ad5741cd00a883ba Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Fri, 24 Jun 2016 21:40:32 +0800 Subject: [PATCH 060/124] =?UTF-8?q?=E4=B8=BA=20textedit=20=E9=83=A8?= =?UTF-8?q?=E4=BB=B6=E6=B7=BB=E5=8A=A0=20change=20=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=EF=BC=8C=E5=BD=93=E5=86=85=E5=AE=B9=E6=9C=89=E5=8F=98=E5=8C=96?= =?UTF-8?q?=E6=97=B6=E4=BC=9A=E8=A7=A6=E5=8F=91=E8=AF=A5=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/gui/widget/textedit.h | 3 +++ src/gui/widget/textedit.c | 21 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/include/LCUI/gui/widget/textedit.h b/include/LCUI/gui/widget/textedit.h index afb4b7e1..c748ba34 100644 --- a/include/LCUI/gui/widget/textedit.h +++ b/include/LCUI/gui/widget/textedit.h @@ -55,6 +55,9 @@ LCUI_API void TextEdit_ClearText( LCUI_Widget widget ); /** 获取文本内容 */ LCUI_API int TextEdit_GetTextW( LCUI_Widget widget, int start, int max_len, wchar_t *buf ); +/** 获取文本长度 */ +LCUI_API int TextEdit_GetTextLength( LCUI_Widget w ); + /** 为文本框设置文本(宽字符版) */ LCUI_API int TextEdit_SetTextW( LCUI_Widget widget, const wchar_t *wstr ); diff --git a/src/gui/widget/textedit.c b/src/gui/widget/textedit.c index d25253d8..f951adaf 100644 --- a/src/gui/widget/textedit.c +++ b/src/gui/widget/textedit.c @@ -79,7 +79,6 @@ typedef struct LCUI_TextEditRec_ { LCUI_BOOL is_read_only; /**< 是否只读 */ LCUI_BOOL is_multiline_mode; /**< 是否为多行模式 */ LCUI_BOOL is_placeholder_shown; /**< 是否已经显示占位符 */ - wchar_t *placeholder; /**< 占位符 */ wchar_t *allow_input_char; /**< 允许输入的字符 */ wchar_t password_char; /**< 屏蔽符的副本 */ int text_block_size; /**< 块大小 */ @@ -113,6 +112,8 @@ typedef struct LCUI_TextBlockRec_ { wchar_t *text; /**< 文本块(段) */ } LCUI_TextBlockRec, *LCUI_TextBlock; +static int textedit_event_id = -1; + /*---------------------------------- Caret ----------------------------------*/ static const char *textcaret_css = ToString( @@ -421,6 +422,7 @@ static void TextEdit_OnTask( LCUI_Widget widget ) LCUI_BOOL is_shown; LinkedList blocks; LinkedListNode *node; + LCUI_WidgetEventRec ev; LinkedList_Init( &blocks ); LCUIMutex_Lock( &edit->mutex ); LinkedList_Concat( &blocks, &edit->text_blocks ); @@ -438,6 +440,8 @@ static void TextEdit_OnTask( LCUI_Widget widget ) if( edit->is_placeholder_shown != is_shown ) { Widget_InvalidateArea( widget, NULL, SV_PADDING_BOX ); } + ev.type = textedit_event_id; + Widget_TriggerEvent( widget, &ev, NULL ); edit->is_placeholder_shown = is_shown; edit->tasks[TASK_UPDATE_CARET] = TRUE; edit->tasks[TASK_SET_TEXT] = FALSE; @@ -511,6 +515,12 @@ int TextEdit_GetTextW( LCUI_Widget w, int start, int max_len, wchar_t *buf ) return TextLayer_GetTextW( edit->layer_source, start, max_len, buf ); } +int TextEdit_GetTextLength( LCUI_Widget w ) +{ + LCUI_TextEdit edit = w->private_data; + return edit->layer_source->length; +} + int TextEdit_SetTextW( LCUI_Widget w, const wchar_t *wstr ) { TextEdit_ClearText( w ); @@ -594,6 +604,7 @@ static void TextEdit_OnBlur( LCUI_Widget widget, LCUI_WidgetEvent e, void *arg ) static void TextEdit_TextBackspace( LCUI_Widget widget, int n_ch ) { LCUI_TextEdit edit; + LCUI_WidgetEventRec ev; Widget_Lock( widget ); edit = widget->private_data; LCUIMutex_Lock( &edit->mutex ); @@ -606,11 +617,14 @@ static void TextEdit_TextBackspace( LCUI_Widget widget, int n_ch ) Widget_AddTask( widget, WTT_USER ); LCUIMutex_Unlock( &edit->mutex ); Widget_Unlock( widget ); + ev.type = textedit_event_id; + Widget_TriggerEvent( widget, &ev, NULL ); } static void TextEdit_TextDelete(LCUI_Widget widget, int n_ch ) { LCUI_TextEdit edit; + LCUI_WidgetEventRec ev; Widget_Lock( widget ); edit = widget->private_data; LCUIMutex_Lock( &edit->mutex ); @@ -623,6 +637,8 @@ static void TextEdit_TextDelete(LCUI_Widget widget, int n_ch ) Widget_AddTask( widget, WTT_USER ); LCUIMutex_Unlock( &edit->mutex ); Widget_Unlock( widget ); + ev.type = textedit_event_id; + Widget_TriggerEvent( widget, &ev, NULL ); } /** 处理按键事件 */ @@ -630,7 +646,6 @@ static void TextEdit_OnKeyDown( LCUI_Widget widget, LCUI_WidgetEvent e, void *ar { LCUI_TextEdit edit; int cols, rows, cur_col, cur_row; - edit = widget->private_data; cur_row = edit->layer->insert_y; cur_col = edit->layer->insert_x; @@ -869,4 +884,6 @@ void LCUIWidget_AddTextEdit( void ) wc->task_handler = TextEdit_OnTask; LCUICSS_LoadString( textedit_css ); LCUIWidget_AddTextCaret(); + textedit_event_id = LCUIWidget_AllocEventId(); + LCUIWidget_SetEventName( textedit_event_id, "change" ); } From 4e4920c35ce521e7a12a5ee959d559ad375875b7 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Fri, 24 Jun 2016 21:42:15 +0800 Subject: [PATCH 061/124] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20disabled=20?= =?UTF-8?q?=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/gui/widget_base.h | 4 ++++ src/gui/widget/button.c | 4 ++++ src/gui/widget_base.c | 10 ++++++++++ 3 files changed, 18 insertions(+) diff --git a/include/LCUI/gui/widget_base.h b/include/LCUI/gui/widget_base.h index 2fdc4efc..9c8945e7 100755 --- a/include/LCUI/gui/widget_base.h +++ b/include/LCUI/gui/widget_base.h @@ -256,6 +256,7 @@ typedef struct LCUI_WidgetRec_ { LCUI_BOOL has_dirty_child; /**< 子级部件是否有无效区域 */ LCUI_BOOL layout_locked; /**< 子级部件布局是否已锁定 */ LCUI_BOOL event_blocked; /**< 是否阻止自己和子级部件的事件处理 */ + LCUI_BOOL disabled; /**< 是否禁用 */ } LCUI_WidgetRec; #define Widget_GetNode(w) (LinkedListNode*)(((char*)w) + sizeof(LCUI_WidgetRec)) @@ -370,6 +371,9 @@ LCUI_API int Widget_AddStatus( LCUI_Widget w, const char *status_name ); /** 判断部件是否包含指定的状态 */ LCUI_API LCUI_BOOL Widget_HasStatus( LCUI_Widget w, const char *status_name ); +/** 设置部件是否禁用 */ +LCUI_API void Widget_SetDisabled( LCUI_Widget w, LCUI_BOOL disabled ); + /** 计算部件的最大宽度 */ LCUI_API int Widget_ComputeMaxWidth( LCUI_Widget w ); diff --git a/src/gui/widget/button.c b/src/gui/widget/button.c index 552b416a..b714f3c9 100755 --- a/src/gui/widget/button.c +++ b/src/gui/widget/button.c @@ -105,6 +105,10 @@ button:active { background-color:rgb(215,215,215); } +button:disabled textview { + color: #aaa; +} + ); /** 添加按钮部件类型 */ diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index fdbdb50d..64291e59 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -1163,6 +1163,16 @@ void Widget_SetBackgroundColor( LCUI_Widget w, LCUI_Color color ) w->computed_style.background.color = color; } +void Widget_SetDisabled( LCUI_Widget w, LCUI_BOOL disabled ) +{ + w->disabled = disabled; + if( w->disabled ) { + Widget_AddStatus( w, "disabled" ); + } else { + Widget_RemoveStatus( w, "disabled" ); + } +} + void Widget_Lock( LCUI_Widget w ) { LCUIMutex_Lock( &w->mutex ); From b43a8444df8ca4af8102ffbca14bef187d0b3156 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Thu, 30 Jun 2016 22:12:52 +0800 Subject: [PATCH 062/124] =?UTF-8?q?=E5=88=A0=E9=99=A4=20textview=20?= =?UTF-8?q?=E9=83=A8=E4=BB=B6=E7=9A=84=20pointer-events=20=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gui/widget/textview.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/gui/widget/textview.c b/src/gui/widget/textview.c index 55b99e4e..3fe8ded0 100644 --- a/src/gui/widget/textview.c +++ b/src/gui/widget/textview.c @@ -67,15 +67,6 @@ typedef struct LCUI_TextView_ { } tasks[TASK_TOTAL]; } LCUI_TextView; - -static const char *textview_css = ToString( - -textview { - pointer-events: none; -} - -); - /*---------------------------- Private -------------------------------*/ enum FontStyleKey { @@ -509,5 +500,4 @@ void LCUIWidget_AddTextView( void ) style_key_map[style_parsers[i].key] = LCUICSS_AddParser( &style_parsers[i] ); } - LCUICSS_LoadString( textview_css ); } From 4313d01a71a0af5ca4c83f0f7acaa7716465fefc Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Thu, 30 Jun 2016 22:13:11 +0800 Subject: [PATCH 063/124] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20Widget=5FEmpty()?= =?UTF-8?q?=20=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gui/widget_base.c | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index 64291e59..1b30e687 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -273,6 +273,10 @@ void Widget_Destroy( LCUI_Widget w ) root = root->parent; } w->state = WSTATE_DELETED; + if( root != LCUIWidget.root ) { + Widget_ExecDestroy( w ); + return; + } if( w->parent ) { LCUI_Widget child; LinkedListNode *node, *snode; @@ -294,20 +298,37 @@ void Widget_Destroy( LCUI_Widget w ) Widget_InvalidateArea( w->parent, &w->box.graph, SV_PADDING_BOX ); } - if( root != LCUIWidget.root ) { - Widget_ExecDestroy( w ); - return; - } } -void Widget_Empty( LCUI_Widget widget ) +void Widget_Empty( LCUI_Widget w ) { - LinkedListNode *node, *prev; - node = widget->children.head.next; - while( node ) { - prev = node->prev; - Widget_Destroy( node->data ); - node = prev->next; + LinkedListNode *node; + LCUI_Widget root = w, child; + while( root->parent ) { + root = root->parent; + } + LinkedList_ClearData( &w->children_show, NULL ); + if( root == LCUIWidget.root ) { + LinkedList_ForEach( node, &w->children ) { + child = node->data; + child->state = WSTATE_DELETED; + } + LinkedList_Concat( &w->children_trash, &w->children ); + Widget_InvalidateArea( w->parent, &w->box.graph, + SV_PADDING_BOX ); + Widget_AddTask( w, WTT_LAYOUT ); + return; + } else { + LinkedList list; + LinkedListNode *prev; + LinkedList_Init( &list ); + LinkedList_Concat( &list, &w->children ); + node = list.head.next; + while( node ) { + prev = node->prev; + Widget_ExecDestroy( node->data ); + node = prev->next; + } } } From 9f35a550437a7a3ec22da215d8106fbc6f770083 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Thu, 30 Jun 2016 22:17:00 +0800 Subject: [PATCH 064/124] =?UTF-8?q?=E8=A7=A3=E5=86=B3=20LinkedList=5FClear?= =?UTF-8?q?Ex()=20=E5=87=BD=E6=95=B0=E4=B8=AD=E5=AD=98=E5=9C=A8=E7=9A=84?= =?UTF-8?q?=E5=86=85=E5=AD=98=E8=AE=BF=E9=97=AE=E8=B6=8A=E7=95=8C=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 销毁部件列表时,由于链表结点与部件同属一块内存空间内,在释放结点数据域后,node->data = NULL; 操作会有内存访问越界的问题,因此,删除该行代码。 --- src/util/linkedlist.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/util/linkedlist.c b/src/util/linkedlist.c index e8d943d4..f834cb05 100644 --- a/src/util/linkedlist.c +++ b/src/util/linkedlist.c @@ -52,7 +52,10 @@ void LinkedList_Init( LinkedList *list ) void LinkedList_Unlink( LinkedList *list, LinkedListNode *node ) { - (list)->length -= 1; + list->length -= 1; + if( list->length < 0 ) { + abort(); + } if( node->next ) { node->next->prev = node->prev; } @@ -78,7 +81,6 @@ void LinkedList_ClearEx( LinkedList *list, void(*on_destroy)(void*), if( node->data && on_destroy ) { on_destroy( node->data ); } - node->data = NULL; if( free_node ) { free( node ); } From b4850c7b0e64acf9a4f4d01a2ce17dca81f12a32 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Sat, 2 Jul 2016 23:39:11 +0800 Subject: [PATCH 065/124] =?UTF-8?q?=E6=9B=B4=E6=96=B0=EF=BC=9A=E7=84=A6?= =?UTF-8?q?=E7=82=B9=E5=A4=84=E7=90=86=E3=80=81=E9=83=A8=E4=BB=B6=E5=8F=AF?= =?UTF-8?q?=E8=A7=81=E6=80=A7=E5=A4=84=E7=90=86=E3=80=81=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E6=A1=86=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 被禁用的部件无法获取焦点。 部件可见性发生变化后,如果不是绝对定位,则需更新部件布局。 --- include/LCUI/gui/widget_base.h | 1 - src/gui/widget/textedit.c | 4 ++++ src/gui/widget_base.c | 7 +++---- src/gui/widget_event.c | 4 ++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/LCUI/gui/widget_base.h b/include/LCUI/gui/widget_base.h index 9c8945e7..c69a77e7 100755 --- a/include/LCUI/gui/widget_base.h +++ b/include/LCUI/gui/widget_base.h @@ -56,7 +56,6 @@ typedef struct LCUI_WidgetStyle { int z_index; /**< 堆叠顺序,该值越高,部件显示得越靠前 */ float opacity; /**< 不透明度,有效范围从 0.0 (完全透明)到 1.0(完全不透明) */ LCUI_StyleValue position; /**< 定位方式 */ - LCUI_StyleValue float_mode; /**< 浮动模式 */ LCUI_StyleValue display; /**< 显示方式,决定以何种布局显示该部件 */ LCUI_StyleValue box_sizing; /**< 以何种方式计算宽度和高度 */ LCUI_StyleValue vertical_align; /**< 垂直对齐方式 */ diff --git a/src/gui/widget/textedit.c b/src/gui/widget/textedit.c index f951adaf..5407d6bf 100644 --- a/src/gui/widget/textedit.c +++ b/src/gui/widget/textedit.c @@ -141,6 +141,10 @@ border: 1px solid #2196F3; box-shadow: 0 0 6px rgba(33,150,243,0.4); } +textedit:disabled { +background-color: #eaeaea; +} + ); static void TextCaret_BlinkShow( LCUI_Widget widget ) diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index 1b30e687..f7add9e6 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -582,6 +582,7 @@ void Widget_UpdateBoxShadow( LCUI_Widget w ) void Widget_UpdateVisibility( LCUI_Widget w ) { + int display = w->computed_style.display; LCUI_Style s = &w->style->sheet[key_visible]; LCUI_BOOL visible = w->computed_style.visible; if( w->computed_style.display == SV_NONE ) { @@ -604,10 +605,8 @@ void Widget_UpdateVisibility( LCUI_Widget w ) if( w->parent ) { Widget_InvalidateArea( w->parent, &w->box.graph, SV_PADDING_BOX ); - if( (w->computed_style.display == SV_BLOCK || - w->computed_style.display == SV_INLINE_BLOCK) - && w->computed_style.position == SV_STATIC - && w->computed_style.float_mode == SV_NONE ) { + if( w->computed_style.display != display && + w->computed_style.position != SV_ABSOLUTE ) { Widget_UpdateLayout( w->parent ); } } diff --git a/src/gui/widget_event.c b/src/gui/widget_event.c index 8f17ff53..679ccf57 100644 --- a/src/gui/widget_event.c +++ b/src/gui/widget_event.c @@ -657,7 +657,7 @@ static void OnMouseEvent( LCUI_SysEvent sys_ev, void *arg ) /* 开始处理焦点 */ for( w = target; w; w = w->parent ) { if( w->computed_style.pointer_events != SV_NONE && - w->computed_style.focusable ) { + w->computed_style.focusable && !w->disabled ) { break; } } @@ -670,7 +670,7 @@ static void OnMouseEvent( LCUI_SysEvent sys_ev, void *arg ) Widget_RemoveStatus( ev.target, "focus" ); Widget_PostEvent( ev.target, &ev, NULL, NULL ); } - if( !w->computed_style.focusable ) { + if( !w->computed_style.focusable || w->disabled ) { break; } ev.target = w; From d5e89d5af0560f9a19d7491ed87e95d8d1b037ce Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Sun, 3 Jul 2016 00:46:51 +0800 Subject: [PATCH 066/124] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20LCUIWidget=5FSetFo?= =?UTF-8?q?cus()=20=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/gui/widget_event.h | 3 ++ src/gui/widget_event.c | 56 +++++++++++++++++++-------------- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/include/LCUI/gui/widget_event.h b/include/LCUI/gui/widget_event.h index a37e3be5..da0bec6e 100644 --- a/include/LCUI/gui/widget_event.h +++ b/include/LCUI/gui/widget_event.h @@ -176,6 +176,9 @@ LCUI_API int Widget_PostSurfaceEvent( LCUI_Widget w, int event_type ); /** 清除事件对象,通常在部件销毁时调用该函数,以避免部件销毁后还有事件发送给它 */ LCUI_API void LCUIWidget_ClearEventTarget( LCUI_Widget widget ); +/** 将一个部件设置为焦点 */ +LCUI_API int LCUIWidget_SetFocus( LCUI_Widget widget ); + /** 停止部件的事件传播 */ LCUI_API int Widget_StopEventPropagation( LCUI_Widget widget ); diff --git a/src/gui/widget_event.c b/src/gui/widget_event.c index 679ccf57..a652f7d1 100644 --- a/src/gui/widget_event.c +++ b/src/gui/widget_event.c @@ -622,6 +622,37 @@ void LCUIWidget_ClearEventTarget( LCUI_Widget widget ) } } +int LCUIWidget_SetFocus( LCUI_Widget widget ) +{ + LCUI_Widget w; + LCUI_WidgetEventRec ev; + /* 开始处理焦点 */ + for( w = widget; w; w = w->parent ) { + if( w->computed_style.pointer_events != SV_NONE && + w->computed_style.focusable && !w->disabled ) { + break; + } + } + if( self.targets[WST_FOCUS] == w ) { + return 0; + } + if( self.targets[WST_FOCUS] ) { + ev.type = WET_BLUR; + ev.target = self.targets[WST_FOCUS]; + Widget_RemoveStatus( ev.target, "focus" ); + Widget_PostEvent( ev.target, &ev, NULL, NULL ); + } + if( !w->computed_style.focusable || w->disabled ) { + return -1; + } + ev.target = w; + ev.type = WET_FOCUS; + self.targets[WST_FOCUS] = w; + Widget_AddStatus( ev.target, "focus" ); + Widget_PostEvent( ev.target, &ev, NULL, NULL ); + return 0; +} + /** 响应系统的鼠标移动事件,向目标部件投递相关鼠标事件 */ static void OnMouseEvent( LCUI_SysEvent sys_ev, void *arg ) { @@ -654,30 +685,7 @@ static void OnMouseEvent( LCUI_SysEvent sys_ev, void *arg ) ev.button.button = sys_ev->button.button; Widget_PostEvent( target, &ev, NULL, NULL ); Widget_UpdateStatus( target, WST_ACTIVE ); - /* 开始处理焦点 */ - for( w = target; w; w = w->parent ) { - if( w->computed_style.pointer_events != SV_NONE && - w->computed_style.focusable && !w->disabled ) { - break; - } - } - if( self.targets[WST_FOCUS] == w ) { - break; - } - if( self.targets[WST_FOCUS] ) { - ev.type = WET_BLUR; - ev.target = self.targets[WST_FOCUS]; - Widget_RemoveStatus( ev.target, "focus" ); - Widget_PostEvent( ev.target, &ev, NULL, NULL ); - } - if( !w->computed_style.focusable || w->disabled ) { - break; - } - ev.target = w; - ev.type = WET_FOCUS; - self.targets[WST_FOCUS] = w; - Widget_AddStatus( ev.target, "focus" ); - Widget_PostEvent( ev.target, &ev, NULL, NULL ); + LCUIWidget_SetFocus( target ); break; case LCUI_MOUSEUP: ev.type = WET_MOUSEUP; From f93abab93e45c63e2a210b3ee2311c92cdf7bc41 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Sun, 3 Jul 2016 11:53:08 +0800 Subject: [PATCH 067/124] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20textedit=20?= =?UTF-8?q?=E9=83=A8=E4=BB=B6=E7=9A=84=E6=96=87=E6=9C=AC=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/font/textlayer.c | 46 ++++++++++++++++++++------------------- src/gui/widget/textedit.c | 29 ++++++++++++++---------- 2 files changed, 42 insertions(+), 33 deletions(-) diff --git a/src/font/textlayer.c b/src/font/textlayer.c index 544a7bfc..d5e95c80 100644 --- a/src/font/textlayer.c +++ b/src/font/textlayer.c @@ -952,59 +952,61 @@ static int TextLayer_TextDeleteEx( LCUI_TextLayer layer, int char_y, if( char_x > txtrow->length ) { char_x = txtrow->length; } - j = n_char; - --n_char; + i = n_char; end_x = char_x; end_y = char_y; /* 计算结束点的位置 */ for( ; end_y < layer->rowlist.length && n_char > 0; ++end_y ) { txtrow = layer->rowlist.rows[end_y]; - if( txtrow->eol == EOL_NONE ) { - if( end_x + n_char < txtrow->length ) { - end_x += n_char; - n_char = 0; - break; - } - } else { - if( end_x + n_char <= txtrow->length ) { - end_x += n_char; - n_char = 0; - break; - } + if( end_x + n_char <= txtrow->length ) { + end_x += n_char; + n_char = 0; + break; } n_char -= (txtrow->length - end_x); - end_x = 0; + if( txtrow->eol == EOL_NONE ) { + end_x = 0; + } else { + n_char -= 1; + end_x = 0; + } } if( n_char >= 0 ) { - layer->length -= j - n_char; + layer->length -= i - n_char; } else { layer->length -= n_char; } if( end_y >= layer->rowlist.length ) { end_y = layer->rowlist.length - 1; + end_txtrow = layer->rowlist.rows[end_y]; + end_x = end_txtrow->length; + } else { + end_txtrow = layer->rowlist.rows[end_y]; } - end_txtrow = layer->rowlist.rows[end_y]; if( end_x > end_txtrow->length ) { end_x = end_txtrow->length; } + if( end_x == char_x && end_y == char_y ) { + return 0; + } /* 获取上一行文本 */ prev_txtrow = layer->rowlist.rows[char_y - 1]; // 计算起始行与结束行拼接后的长度 // 起始行:0 1 2 3 4 5,起点位置:2 // 结束行:0 1 2 3 4 5,终点位置:4 - // 拼接后的长度:2 + 6 - 4 - 1 = 3 - len = char_x + end_txtrow->length - end_x - 1; + // 拼接后的长度:2 + 6 - 4 = 4 + len = char_x + end_txtrow->length - end_x; if( len < 0 ) { return -3; } /* 如果是同一行 */ if( txtrow == end_txtrow ) { - if( end_x >= end_txtrow->length ) { + if( end_x > end_txtrow->length ) { return -4; } TextLayer_InvalidateRowRect( layer, char_y, char_x, -1 ); TextLayer_AddUpdateTypeset( layer, char_y ); - for( i = char_x, j = end_x + 1; j < txtrow->length; ++i, ++j ) { + for( i = char_x, j = end_x; j < txtrow->length; ++i, ++j ) { txtrow->string[i] = txtrow->string[j]; } /* 如果当前行为空,也不是第一行,并且上一行没有结束符 */ @@ -1087,7 +1089,7 @@ int TextLayer_TextBackspace( LCUI_TextLayer layer, int n_char ) } n_del = n_del - char_x - 1; } - if( char_y < 0 && n_del == n_char ) { + if( char_y < 0 || n_del == n_char ) { return -1; } /* 若能够被删除的字不够 n_char 个,则调整需删除的字数 */ diff --git a/src/gui/widget/textedit.c b/src/gui/widget/textedit.c index 5407d6bf..8608f7e6 100644 --- a/src/gui/widget/textedit.c +++ b/src/gui/widget/textedit.c @@ -423,7 +423,6 @@ static void TextEdit_OnTask( LCUI_Widget widget ) { LCUI_TextEdit edit = widget->private_data; if( edit->tasks[TASK_SET_TEXT] ) { - LCUI_BOOL is_shown; LinkedList blocks; LinkedListNode *node; LCUI_WidgetEventRec ev; @@ -435,6 +434,15 @@ static void TextEdit_OnTask( LCUI_Widget widget ) TextEdit_ProcTextBlock( widget, node->data ); } LinkedList_Clear( &blocks, TextBlock_OnDestroy ); + ev.type = textedit_event_id; + Widget_TriggerEvent( widget, &ev, NULL ); + edit->tasks[TASK_UPDATE_CARET] = TRUE; + edit->tasks[TASK_SET_TEXT] = FALSE; + edit->tasks[TASK_UPDATE] = TRUE; + } + if( edit->tasks[TASK_UPDATE] ) { + LCUI_BOOL is_shown; + TextEdit_UpdateTextLayer( widget ); is_shown = edit->layer_source->length == 0; if( is_shown ) { edit->layer = edit->layer_placeholder; @@ -444,15 +452,7 @@ static void TextEdit_OnTask( LCUI_Widget widget ) if( edit->is_placeholder_shown != is_shown ) { Widget_InvalidateArea( widget, NULL, SV_PADDING_BOX ); } - ev.type = textedit_event_id; - Widget_TriggerEvent( widget, &ev, NULL ); edit->is_placeholder_shown = is_shown; - edit->tasks[TASK_UPDATE_CARET] = TRUE; - edit->tasks[TASK_SET_TEXT] = FALSE; - edit->tasks[TASK_UPDATE] = TRUE; - } - if( edit->tasks[TASK_UPDATE] ) { - TextEdit_UpdateTextLayer( widget ); edit->tasks[TASK_UPDATE] = FALSE; } if( edit->tasks[TASK_UPDATE_CARET] ) { @@ -594,7 +594,8 @@ static void TextEdit_OnFocus( LCUI_Widget widget, LCUI_WidgetEvent e, void *arg LCUIIME_SetTarget( widget ); TextCaret_SetVisible( edit->caret, TRUE ); TextCaret_BlinkHide( edit->caret ); - TextEdit_UpdateCaret( widget ); + edit->tasks[TASK_UPDATE_CARET] = TRUE; + Widget_AddTask( widget, WTT_USER ); } static void TextEdit_OnBlur( LCUI_Widget widget, LCUI_WidgetEvent e, void *arg ) @@ -705,7 +706,7 @@ static void TextEdit_OnTextInput( LCUI_Widget widget, LCUI_WidgetEvent e, void *arg ) { uint_t i, j, k; - wchar_t ch, *text, excludes[8] = L"\b\r\t"; + wchar_t ch, *text, excludes[8] = L"\b\r\t\x1b"; LCUI_TextEdit edit = widget->private_data; /* 如果不是多行文本编辑模式则删除换行符 */ if( !edit->is_multiline_mode ) { @@ -807,6 +808,11 @@ static void TextEdit_OnMouseDown( LCUI_Widget w, LCUI_WidgetEvent e, void *arg ) Widget_BindEvent( w, "mousemove", TextEdit_OnMouseMove, NULL, NULL ); } +static void TextEdit_OnReady( LCUI_Widget w, LCUI_WidgetEvent e, void *arg ) +{ + TextEdit_UpdateCaret( w ); +} + static void TextEdit_SetAttr( LCUI_Widget w, const char *name, const char *val ) { @@ -843,6 +849,7 @@ static void TextEdit_OnInit( LCUI_Widget w ) Widget_BindEvent( w, "resize", TextEdit_OnResize, NULL, NULL ); Widget_BindEvent( w, "focus", TextEdit_OnFocus, NULL, NULL ); Widget_BindEvent( w, "blur", TextEdit_OnBlur, NULL, NULL ); + Widget_BindEvent( w, "ready", TextEdit_OnReady, NULL, NULL ); Widget_Append( w, edit->caret ); Widget_Hide( edit->caret ); LCUIMutex_Init( &edit->mutex ); From 137b1bf88bfa0bc44f69fee201a86155f4dd85f9 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Mon, 4 Jul 2016 10:31:45 +0800 Subject: [PATCH 068/124] =?UTF-8?q?=E4=B8=BA=20textlayer=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=20fixed=5Fwidth=20=E5=92=8C=20fiexed=5Fheight=20?= =?UTF-8?q?=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 现在,max_width 和 max_height 仅用于限制文本最大扩张尺寸,且仅在没有指定 fixed_width 和 fiexed_height 时起作用。 --- include/LCUI/LCUI.h | 3 +- include/LCUI/font/textlayer.h | 31 +++---- src/font/textlayer.c | 158 ++++++++++++++++++++-------------- src/gui/css_parser.c | 3 +- src/gui/widget_base.c | 7 +- 5 files changed, 116 insertions(+), 86 deletions(-) diff --git a/include/LCUI/LCUI.h b/include/LCUI/LCUI.h index f1894874..9567f2e2 100755 --- a/include/LCUI/LCUI.h +++ b/include/LCUI/LCUI.h @@ -226,7 +226,8 @@ typedef enum LCUI_StyleValue { SV_FLOAT_LEFT, SV_FLOAT_RIGHT, SV_BLOCK, - SV_INLINE_BLOCK + SV_INLINE_BLOCK, + SV_NOWRAP } LCUI_StyleValue; typedef struct LCUI_StyleRec_ { diff --git a/include/LCUI/font/textlayer.h b/include/LCUI/font/textlayer.h index f6c9928c..a29d0fb6 100755 --- a/include/LCUI/font/textlayer.h +++ b/include/LCUI/font/textlayer.h @@ -79,7 +79,10 @@ typedef struct LCUI_TextLayerRec_ { int new_offset_y; /**< 新的Y轴坐标偏移量 */ int insert_x; /**< 光标所在列数 */ int insert_y; /**< 光标所在行数 */ - int max_width; /**< 最大文本宽度 */ + int width; /**< 实际文本宽度 */ + int fixed_width; /**< 固定文本宽度 */ + int fixed_height; /**< 固定文本高度 */ + int max_width; /**< 最大文本宽度,当未设置固定宽度时,文字排版将按最大宽度进行 */ int max_height; /**< 最大文本高度 */ int length; /**< 文本长度 */ LCUI_BOOL is_mulitiline_mode; /**< 是否启用多行文本模式 */ @@ -113,15 +116,6 @@ LCUI_API int TextLayer_GetRowTextLength( LCUI_TextLayer layer, int row ); /** 添加 更新文本排版 的任务 */ LCUI_API void TextLayer_AddUpdateTypeset( LCUI_TextLayer layer, int start_row ); -/** 设置文本颜色 */ -LCUI_API void TextLayer_SetFontColor( LCUI_TextLayer layer, LCUI_Color color ); - -/** 设置文本所使用的字体字族 */ -LCUI_API void TextLayer_SetFontFamily( LCUI_TextLayer layer, const char *family_name ); - -/** 设置文本的字体像素大小 */ -LCUI_API void TextLayer_SetFontPixelSize( LCUI_TextLayer layer, int pixel_size ); - /** 设置文本对齐方式 */ LCUI_API void TextLayer_SetTextAlign( LCUI_TextLayer layer, int align ); @@ -190,8 +184,17 @@ LCUI_API int TextLayer_GetTextW( LCUI_TextLayer layer, int start_pos, /** 获取文本位图缓存 */ LCUI_API LCUI_Graph* TextLayer_GetGraphBuffer( LCUI_TextLayer layer ); +/** 计算并获取文本的宽度 */ +LCUI_API int TextLayer_GetWidth( LCUI_TextLayer layer ); + +/** 计算并获取文本的高度 */ +LCUI_API int TextLayer_GetHeight( LCUI_TextLayer layer ); + +/** 设置固定尺寸 */ +LCUI_API int TextLayer_SetFixedSize( LCUI_TextLayer layer, int width, int height ); + /** 设置最大尺寸 */ -LCUI_API int TextLayer_SetMaxSize( LCUI_TextLayer layer, LCUI_Size new_size ); +LCUI_API int TextLayer_SetMaxSize( LCUI_TextLayer layer, int width, int height ); /** 设置是否启用多行文本模式 */ LCUI_API void TextLayer_SetMultiline( LCUI_TextLayer layer, int is_true ); @@ -208,12 +211,6 @@ LCUI_API void TextLayer_SetAutoWrap( LCUI_TextLayer layer, int is_true ); /** 设置是否使用样式标签 */ LCUI_API void TextLayer_SetUsingStyleTags( LCUI_TextLayer layer, LCUI_BOOL is_true ); -/** 计算并获取文本的宽度 */ -LCUI_API int TextLayer_GetWidth( LCUI_TextLayer layer ); - -/** 计算并获取文本的高度 */ -LCUI_API int TextLayer_GetHeight( LCUI_TextLayer layer ); - /** 重新载入各个文字的字体位图 */ LCUI_API void TextLayer_ReloadCharBitmap( LCUI_TextLayer layer ); diff --git a/src/font/textlayer.c b/src/font/textlayer.c index d5e95c80..34270ada 100644 --- a/src/font/textlayer.c +++ b/src/font/textlayer.c @@ -55,9 +55,15 @@ enum TextAddType { /* 根据对齐方式,计算文本行的起始X轴位置 */ static int TextLayer_GetRowStartX( LCUI_TextLayer layer, TextRow txtrow ) { + int width; + if( layer->fixed_width > 0 ) { + width = layer->fixed_width; + } else { + width = layer->width; + } switch( layer->text_align ) { - case SV_CENTER: return (layer->max_width - txtrow->width)/2; - case SV_RIGHT: return layer->max_width - txtrow->width; + case SV_CENTER: return (width - txtrow->width) / 2; + case SV_RIGHT: return width - txtrow->width; case SV_LEFT: default: break; } @@ -294,6 +300,7 @@ LCUI_TextLayer TextLayer_New(void) { LCUI_TextLayer layer; layer = malloc( sizeof( LCUI_TextLayerRec ) ); + layer->width = 0; layer->length = 0; layer->offset_x = 0; layer->offset_y = 0; @@ -301,6 +308,8 @@ LCUI_TextLayer TextLayer_New(void) layer->insert_y = 0; layer->max_width = 0; layer->max_height = 0; + layer->fixed_width = 0; + layer->fixed_height = 0; layer->new_offset_x = 0; layer->new_offset_y = 0; layer->rowlist.length = 0; @@ -386,7 +395,6 @@ static int TextLayer_GetRowRect( LCUI_TextLayer layer, int i_row, rect->width += txtrow->string[i]->bitmap->advance.x; } } - LCUIRect_ValidateArea( rect, layer->max_width, layer->max_height ); if( rect->width <= 0 || rect->height <= 0 ) { return 1; } @@ -411,18 +419,18 @@ void TextLayer_InvalidateRowsRect( LCUI_TextLayer layer, LCUI_Rect rect; if( end_row < 0 || end_row >= layer->rowlist.length ) { - end_row = layer->rowlist.length-1; + end_row = layer->rowlist.length - 1; } y = layer->offset_y; - for( i=0; irowlist.length; ++i ) { + for( i = 0; i < layer->rowlist.length; ++i ) { y += layer->rowlist.rows[i]->height; if( i >= start_row && y >= 0 ) { y -= layer->rowlist.rows[i]->height; break; } } - for( ; i<=end_row; ++i ) { + for( ; i <= end_row; ++i ) { TextLayer_GetRowRect( layer, i, 0, -1, &rect ); RectList_Add( &layer->dirty_rect, &rect ); y += layer->rowlist.rows[i]->height; @@ -548,6 +556,7 @@ void TextLayer_ClearText( LCUI_TextLayer layer ) layer->length = 0; layer->insert_x = 0; layer->insert_y = 0; + layer->width = 0; TextLayer_InvalidateRowsRect( layer, 0, -1 ); TextRowList_Destroy( &layer->rowlist ); LinkedList_Clear( &layer->style_cache, (FuncPtr)TextStyle_Destroy ); @@ -582,7 +591,13 @@ static void TextLayer_TextRowTypeset( LCUI_TextLayer layer, int row ) TextChar txtchar; LCUI_BOOL not_autowrap; int col, row_width = 0; - if( layer->max_width <= 0 || !layer->is_autowrap_mode || + int max_width; + if( layer->fixed_width > 0 ) { + max_width = layer->fixed_width; + } else { + max_width = layer->max_width; + } + if( max_width <= 0 || !layer->is_autowrap_mode || (layer->is_autowrap_mode && !layer->is_mulitiline_mode) ) { not_autowrap = TRUE; } else { @@ -597,8 +612,7 @@ static void TextLayer_TextRowTypeset( LCUI_TextLayer layer, int row ) /* 累加行宽度 */ row_width += txtchar->bitmap->advance.x; /* 如果是当前行的第一个字符,或者行宽度没有超过宽度限制 */ - if( not_autowrap || col < 1 || - row_width <= layer->max_width ) { + if( not_autowrap || col < 1 || row_width <= max_width ) { continue; } TextLayer_BreakTextRow( layer, row, col, EOL_NONE ); @@ -627,7 +641,7 @@ static void TextLayer_TextRowTypeset( LCUI_TextLayer layer, int row ) } row_width += txtchar->bitmap->advance.x; /* 如果没有超过宽度限制 */ - if( not_autowrap || row_width <= layer->max_width ) { + if( not_autowrap || row_width <= max_width ) { TextRow_Insert( txtrow, -1, txtchar ); next_txtrow->string[col] = NULL; continue; @@ -667,7 +681,7 @@ static void TextLayer_TextTypeset( LCUI_TextLayer layer, int start_row ) int row; /* 记录排版前各个文本行的矩形区域 */ TextLayer_InvalidateRowsRect( layer, start_row, -1 ); - for( row=start_row; rowrowlist.length; ++row ) { + for( row = start_row; row < layer->rowlist.length; ++row ) { TextLayer_TextRowTypeset( layer, row ); } /* 记录排版后各个文本行的矩形区域 */ @@ -762,6 +776,7 @@ static int TextLayer_ProcessText( LCUI_TextLayer layer, const wchar_t *wstr, } /* 将当前行中的插入点为截点,进行断行 */ TextLayer_BreakTextRow( layer, ins_y, ins_x, eol ); + layer->width = max( layer->width, txtrow->width ); need_typeset = TRUE; ++layer->length; ins_x = 0; @@ -778,6 +793,7 @@ static int TextLayer_ProcessText( LCUI_TextLayer layer, const wchar_t *wstr, } /* 更新当前行的尺寸 */ TextLayer_UpdateRowSize( layer, txtrow ); + layer->width = max( layer->width, txtrow->width ); if( add_type == TAT_INSERT ) { layer->insert_x = ins_x; layer->insert_y = ins_y; @@ -891,7 +907,6 @@ int TextLayer_GetTextW( LCUI_TextLayer layer, int start_pos, return i; } -/** 获取文本位图缓存 */ LCUI_Graph* TextLayer_GetGraphBuffer( LCUI_TextLayer layer ) { if( layer->is_using_buffer ) { @@ -900,16 +915,57 @@ LCUI_Graph* TextLayer_GetGraphBuffer( LCUI_TextLayer layer ) return NULL; } -/** 设置最大尺寸 */ -int TextLayer_SetMaxSize( LCUI_TextLayer layer, LCUI_Size size ) +int TextLayer_GetWidth( LCUI_TextLayer layer ) { - if( size.width <= 0 || size.height <= 0 ) { - return -1; + int i, row, w, max_w; + TextRow txtrow; + + for( row = 0, max_w = 0; row < layer->rowlist.length; ++row ) { + txtrow = layer->rowlist.rows[row]; + for( i = 0, w = 0; i < txtrow->length; ++i ) { + if( !txtrow->string[i]->bitmap || + !txtrow->string[i]->bitmap->buffer ) { + continue; + } + w += txtrow->string[i]->bitmap->advance.x; + } + if( w > max_w ) { + max_w = w; + } } - layer->max_width = size.width; - layer->max_height = size.height; + return max_w; +} + +int TextLayer_GetHeight( LCUI_TextLayer layer ) +{ + int i, h; + for( i = 0, h = 0; i < layer->rowlist.length; ++i ) { + h += layer->rowlist.rows[i]->height; + } + return h; +} + +int TextLayer_SetFixedSize( LCUI_TextLayer layer, int width, int height ) +{ + layer->fixed_width = width; + layer->fixed_height = height; if( layer->is_using_buffer ) { - Graph_Create( &layer->graph, size.width, size.height ); + Graph_Create( &layer->graph, width, height ); + } + layer->task.redraw_all = TRUE; + if( layer->is_autowrap_mode ) { + layer->task.typeset_start_row = 0; + layer->task.update_typeset = TRUE; + } + return 0; +} + +int TextLayer_SetMaxSize( LCUI_TextLayer layer, int width, int height ) +{ + layer->max_width = width; + layer->max_height = height; + if( layer->is_using_buffer ) { + Graph_Create( &layer->graph, width, height ); } layer->task.redraw_all = TRUE; if( layer->is_autowrap_mode ) { @@ -1125,45 +1181,13 @@ void TextLayer_SetUsingStyleTags( LCUI_TextLayer layer, LCUI_BOOL is_true ) layer->is_using_style_tags = is_true; } -/** 计算并获取文本的宽度 */ -int TextLayer_GetWidth( LCUI_TextLayer layer ) -{ - int i, row, w, max_w; - TextRow txtrow; - - for( row=0,max_w=0; rowrowlist.length; ++row ) { - txtrow = layer->rowlist.rows[row]; - for( i=0, w=0; ilength; ++i ) { - if( !txtrow->string[i]->bitmap || - !txtrow->string[i]->bitmap->buffer ) { - continue; - } - w += txtrow->string[i]->bitmap->advance.x; - } - if( w > max_w ) { - max_w = w; - } - } - return max_w; -} - -/** 计算并获取文本的高度 */ -int TextLayer_GetHeight( LCUI_TextLayer layer ) -{ - int i, h; - for( i=0,h=0; irowlist.length; ++i ) { - h += layer->rowlist.rows[i]->height; - } - return h; -} - /** 重新载入各个文字的字体位图 */ void TextLayer_ReloadCharBitmap( LCUI_TextLayer layer ) { int row, col; - for( row=0; rowrowlist.length; ++row ) { + for( row = 0; row < layer->rowlist.length; ++row ) { TextRow txtrow = layer->rowlist.rows[row]; - for( col=0; collength; ++col ) { + for( col = 0; col < txtrow->length; ++col ) { TextChar txtchar = txtrow->string[col]; TextChar_UpdateBitmap( txtchar, &layer->text_style ); } @@ -1186,6 +1210,7 @@ void TextLayer_Update( LCUI_TextLayer layer, LinkedList *rect_list ) layer->task.update_typeset = FALSE; layer->task.typeset_start_row = 0; } + layer->width = TextLayer_GetWidth( layer ); /* 如果坐标偏移量有变化,记录各个文本行区域 */ if( layer->new_offset_x != layer->offset_x || layer->new_offset_y != layer->offset_y ) { @@ -1200,23 +1225,26 @@ void TextLayer_Update( LCUI_TextLayer layer, LinkedList *rect_list ) } } -/** - * 将文本图层中的指定区域的内容绘制至目标图像中 - * @param layer 要使用的文本图层 - * @param area 文本图层中需要绘制的区域 - * @param layer_pos 文本图层在目标图像中的位置 - * @param graph 目标图像 - */ int TextLayer_DrawToGraph( LCUI_TextLayer layer, LCUI_Rect area, LCUI_Pos layer_pos, LCUI_Graph *graph ) { TextRow txtrow; TextChar txtchar; LCUI_Pos char_pos; - int x, y, row, col; + int x, y, row, col, width, height; y = layer->offset_y; - LCUIRect_ValidateArea( &area, layer->max_width, layer->max_height ); - for( row=0; rowrowlist.length; ++row ) { + if( layer->fixed_width > 0 ) { + width = layer->fixed_width; + } else { + width = layer->width; + } + if( layer->fixed_width > 0 ) { + height = layer->fixed_width; + } else { + height = TextLayer_GetHeight( layer ); + } + LCUIRect_ValidateArea( &area, width, height ); + for( row = 0; row < layer->rowlist.length; ++row ) { txtrow = TextLayer_GetRow( layer, row ); y += txtrow->height; if( y > area.y ) { @@ -1233,7 +1261,7 @@ int TextLayer_DrawToGraph( LCUI_TextLayer layer, LCUI_Rect area, x = TextLayer_GetRowStartX( layer, txtrow ); x += layer->offset_x; /* 确定从哪个文字开始绘制 */ - for( col=0; collength; ++col ) { + for( col = 0; col < txtrow->length; ++col ) { txtchar = txtrow->string[col]; /* 忽略无字体位图的文字 */ if( !txtchar->bitmap ) { @@ -1251,7 +1279,7 @@ int TextLayer_DrawToGraph( LCUI_TextLayer layer, LCUI_Rect area, continue; } /* 遍历该行的文字 */ - for( ; collength; ++col ) { + for( ; col < txtrow->length; ++col ) { txtchar = txtrow->string[col]; if( !txtchar->bitmap ) { continue; diff --git a/src/gui/css_parser.c b/src/gui/css_parser.c index 853c3d1b..82e1f34a 100644 --- a/src/gui/css_parser.c +++ b/src/gui/css_parser.c @@ -631,7 +631,8 @@ static KeyNameGroup style_option_map[] = { { SV_RELATIVE, "relative" }, { SV_ABSOLUTE, "absolute" }, { SV_BLOCK, "block" }, - { SV_INLINE_BLOCK, "inline-block" } + { SV_INLINE_BLOCK, "inline-block" }, + { SV_NOWRAP, "nowrap" } }; /** 各个样式的解析器映射表 */ diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index f7add9e6..a24cb33f 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -1403,8 +1403,11 @@ int Widget_ComputeMaxWidth( LCUI_Widget w ) break; case SVT_SCALE: scale *= s->val_scale; - padding += child->parent->padding.left; - padding += child->parent->padding.right; + if( child == w ) { + break; + } + padding += child->padding.left; + padding += child->padding.right; case SVT_AUTO: default: continue; } From b8dd10356d4540ac349a609361c5f64d6ea69a8b Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Mon, 4 Jul 2016 10:34:43 +0800 Subject: [PATCH 069/124] =?UTF-8?q?=E4=B8=BA=20textview=20=E9=83=A8?= =?UTF-8?q?=E4=BB=B6=E6=B7=BB=E5=8A=A0=20white-space=20=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=E6=94=AF=E6=8C=81=EF=BC=8C=E6=9B=B4=E6=96=B0=20textview=20?= =?UTF-8?q?=E5=92=8C=20textedit=20=E9=83=A8=E4=BB=B6=E7=9A=84=20textlayer?= =?UTF-8?q?=20=E5=B0=BA=E5=AF=B8=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/gui/widget/textview.h | 2 + src/gui/widget/textedit.c | 33 ++++++++---- src/gui/widget/textview.c | 81 +++++++++++++++++++++++------- 3 files changed, 89 insertions(+), 27 deletions(-) diff --git a/include/LCUI/gui/widget/textview.h b/include/LCUI/gui/widget/textview.h index bb5facad..6cb27d3d 100644 --- a/include/LCUI/gui/widget/textview.h +++ b/include/LCUI/gui/widget/textview.h @@ -57,6 +57,8 @@ LCUI_API void TextView_GetTextStyle( LCUI_Widget w, LCUI_TextStyle *style ); LCUI_API void TextView_SetTextAlign( LCUI_Widget w, int align ); +LCUI_API void TextView_SetAutoWrap( LCUI_Widget w, LCUI_BOOL autowrap ); + LCUI_END_HEADER #endif diff --git a/src/gui/widget/textedit.c b/src/gui/widget/textedit.c index 8608f7e6..a2f9a844 100644 --- a/src/gui/widget/textedit.c +++ b/src/gui/widget/textedit.c @@ -508,6 +508,8 @@ void TextEdit_ClearText( LCUI_Widget widget ) LCUIMutex_Lock( &edit->mutex ); TextLayer_ClearText( edit->layer ); StyleTags_Clear( &edit->text_tags ); + edit->tasks[TASK_UPDATE] = TRUE; + Widget_AddTask( widget, WTT_USER ); LCUIMutex_Unlock( &edit->mutex ); Widget_InvalidateArea( widget, NULL, SV_PADDING_BOX ); Widget_Unlock( widget ); @@ -756,18 +758,31 @@ static void TextEdit_OnResize( LCUI_Widget w, LCUI_WidgetEvent e, void *arg ) { LinkedList rects; LinkedListNode *node; - LCUI_Size new_size = {16, 16}; - LCUI_TextEdit edit = w->private_data; - if( w->box.content.width > new_size.width ) { - new_size.width = w->box.content.width; + LCUI_TextEdit edit; + int width = 0, height = 0; + int max_width = 0, max_height = 0; + + edit = w->private_data; + if( !w->style->sheet[key_width].is_valid || + w->style->sheet[key_width].type == SVT_AUTO ) { + max_width = Widget_ComputeMaxWidth( w ); + max_width -= w->computed_style.border.left.width; + max_width -= w->computed_style.border.right.width; + max_width -= w->padding.left + w->padding.right; + } else { + max_width = width = w->box.content.width; } - if( w->box.content.height > new_size.height ) { - new_size.height = w->box.content.height; + if( w->style->sheet[key_height].is_valid && + !w->style->sheet[key_height].type == SVT_AUTO ) { + max_height = height = w->box.content.width; } LinkedList_Init( &rects ); - TextLayer_SetMaxSize( edit->layer_mask, new_size ); - TextLayer_SetMaxSize( edit->layer_source, new_size ); - TextLayer_SetMaxSize( edit->layer_placeholder, new_size ); + TextLayer_SetFixedSize( edit->layer_mask, width, height ); + TextLayer_SetFixedSize( edit->layer_source, width, height ); + TextLayer_SetFixedSize( edit->layer_placeholder, width, height ); + TextLayer_SetMaxSize( edit->layer_mask, max_width, max_height ); + TextLayer_SetMaxSize( edit->layer_source, max_width, max_height ); + TextLayer_SetMaxSize( edit->layer_placeholder, max_width, max_height ); TextLayer_Update( edit->layer, &rects ); LinkedList_ForEach( node, &rects ) { Widget_InvalidateArea( w, node->data, SV_CONTENT_BOX ); diff --git a/src/gui/widget/textview.c b/src/gui/widget/textview.c index 3fe8ded0..7651d4f1 100644 --- a/src/gui/widget/textview.c +++ b/src/gui/widget/textview.c @@ -67,6 +67,11 @@ typedef struct LCUI_TextView_ { } tasks[TASK_TOTAL]; } LCUI_TextView; +static const char *textview_css = ToString( +textview{ + white-space: normal; +} +); /*---------------------------- Private -------------------------------*/ enum FontStyleKey { @@ -78,6 +83,7 @@ enum FontStyleKey { key_line_height, key_text_align, key_content, + key_white_space, TOTAL_FONT_STYLE_KEY }; @@ -92,7 +98,7 @@ static int style_key_map[TOTAL_FONT_STYLE_KEY]; static int unescape( const wchar_t *instr, wchar_t *outstr ) { int i = -1; - char buff[6]; + wchar_t buff[6]; wchar_t *pout = outstr; const wchar_t *pin = instr; @@ -100,20 +106,20 @@ static int unescape( const wchar_t *instr, wchar_t *outstr ) if( i >= 0 ) { buff[i++] = *pin; if( i >= 4 ) { - sscanf( buff, "%x", pout ); + swscanf( buff, L"%x", pout ); ++pout; i = -1; } continue; } - if( *pin == '\\' ) { + if( *pin == L'\\' ) { i = 0; continue; } *pout++ = *pin; } if( i >= 4 ) { - sscanf( buff, "%x", pout ); + swscanf( buff, L"%x", pout ); ++pout; } *pout = 0; @@ -208,6 +214,20 @@ static int OnParseLineHeight( LCUI_StyleSheet ss, int key, const char *str ) return -1; } +static int OnParseStyleOption( LCUI_StyleSheet ss, int key, const char *str ) +{ + LCUI_Style s = &ss->sheet[style_key_map[key]]; + int v = GetStyleOption( str ); + if( v < 0 ) { + return -1; + } + s->style = v; + s->type = SVT_STYLE; + s->is_valid = TRUE; + s->is_changed = TRUE; + return 0; +} + static LCUI_StyleParserRec style_parsers[] = { { key_color, "color", OnParseColor }, { key_font_family, "font-family", OnParseFontFamily }, @@ -217,6 +237,7 @@ static LCUI_StyleParserRec style_parsers[] = { { key_text_align, "text-align", OnParseTextAlign }, { key_line_height, "line-height", OnParseLineHeight }, { key_content, "content", OnParseContent }, + { key_white_space, "white-space", OnParseStyleOption } }; static void TextView_UpdateStyle( LCUI_Widget w ) @@ -263,6 +284,16 @@ static void TextView_UpdateStyle( LCUI_Widget w ) break; case key_content: TextView_SetTextW( w, s->wstring ); + break; + case key_white_space: + if( s->type != SVT_STYLE ) { + break; + } + if( s->style == SV_NOWRAP ) { + TextLayer_SetAutoWrap( txt->layer, FALSE ); + } else { + TextLayer_SetAutoWrap( txt->layer, TRUE ); + } default:break; } } @@ -275,22 +306,27 @@ static void TextView_OnResize( LCUI_Widget w, LCUI_WidgetEvent e, void *arg ) { LinkedList rects; LinkedListNode *node; - LCUI_Size new_size = {16, 16}; - LCUI_TextView *txt = w->private_data; - if( w->box.content.width > new_size.width ) { - new_size.width = w->box.content.width; - } - if( w->box.content.height > new_size.height ) { - new_size.height = w->box.content.height; - } + LCUI_TextView *txt; + int width = 0, height = 0; + int max_width = 0, max_height = 0; + + txt = w->private_data; LinkedList_Init( &rects ); - if( w->style->sheet[key_width].is_valid && - w->style->sheet[key_width].type != SVT_AUTO ) { - TextLayer_SetAutoWrap( txt->layer, TRUE ); + if( !w->style->sheet[key_width].is_valid || + w->style->sheet[key_width].type == SVT_AUTO ) { + max_width = Widget_ComputeMaxWidth( w ); + max_width -= w->computed_style.border.left.width; + max_width -= w->computed_style.border.right.width; + max_width -= w->padding.left + w->padding.right; } else { - TextLayer_SetAutoWrap( txt->layer, FALSE ); + max_width = width = w->box.content.width; } - TextLayer_SetMaxSize( txt->layer, new_size ); + if( w->style->sheet[key_height].is_valid && + !w->style->sheet[key_height].type == SVT_AUTO ) { + max_height = height = w->box.content.width; + } + TextLayer_SetMaxSize( txt->layer, max_width, max_height ); + TextLayer_SetFixedSize( txt->layer, width, height ); TextLayer_Update( txt->layer, &rects ); LinkedList_ForEach( node, &rects ) { Widget_InvalidateArea( w, node->data, SV_CONTENT_BOX ); @@ -312,6 +348,7 @@ static void TextView_OnInit( LCUI_Widget w ) /* 初始化文本图层 */ txt->layer = TextLayer_New(); /* 启用多行文本显示 */ + TextLayer_SetAutoWrap( txt->layer, TRUE ); TextLayer_SetMultiline( txt->layer, TRUE ); /* 启用样式标签的支持 */ TextLayer_SetUsingStyleTags( txt->layer, TRUE ); @@ -331,7 +368,6 @@ static void TextView_AutoSize( LCUI_Widget w, int *width, int *height ) LCUI_TextView *txt = w->private_data; *width = TextLayer_GetWidth( txt->layer ); *height = TextLayer_GetHeight( txt->layer ); - DEBUG_MSG("width: %d, height: %d\n", *width, *height); } /** 私有的任务处理接口 */ @@ -482,6 +518,14 @@ void TextView_SetTextAlign( LCUI_Widget w, int align ) Widget_AddTask( w, WTT_USER ); } +void TextView_SetAutoWrap( LCUI_Widget w, LCUI_BOOL autowrap ) +{ + LCUI_TextView *txt = w->private_data; + txt->tasks[TASK_SET_AUTOWRAP].autowrap = autowrap; + txt->tasks[TASK_SET_AUTOWRAP].is_valid = TRUE; + Widget_AddTask( w, WTT_USER ); +} + /*-------------------------- End Public ------------------------------*/ /** 添加 TextView 部件类型 */ @@ -500,4 +544,5 @@ void LCUIWidget_AddTextView( void ) style_key_map[style_parsers[i].key] = LCUICSS_AddParser( &style_parsers[i] ); } + LCUICSS_LoadString( textview_css ); } From 615bc943031ce2e623b182dda91d9d98ac4a5b36 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Mon, 4 Jul 2016 10:34:56 +0800 Subject: [PATCH 070/124] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E8=87=B32016?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 052cf800..c533780a 100644 --- a/src/main.c +++ b/src/main.c @@ -394,7 +394,7 @@ static void LCUI_ShowCopyrightText(void) "\n" #endif "Build at "__DATE__" - "__TIME__"\n" - "Copyright (C) 2012-2015 Liu Chao .\n" + "Copyright (C) 2012-2016 Liu Chao .\n" "This is free software, licensed under GPLv2. \n" "See source distribution for detailed copyright notices.\n" "To learn more, visit http://www.lcui.org.\n\n" From 64bb5afbf82e0f7b2141e9ba50fc34f144006d3b Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Mon, 4 Jul 2016 11:09:30 +0800 Subject: [PATCH 071/124] =?UTF-8?q?=E8=A7=A3=E5=86=B3=20linux=20=E4=B8=AD?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E7=9A=84=E7=BC=96=E8=AF=91=E8=AD=A6=E5=91=8A?= =?UTF-8?q?=E5=92=8C=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/gui/widget/textedit.h | 5 ++++- src/Makefile.am | 2 +- src/bmp/png.c | 10 ++++++---- src/font/in-core/font_inconsolata.c | 4 ++-- src/gui/Makefile.am | 1 + src/gui/builder.c | 7 ++++--- src/gui/widget/textedit.c | 17 ++++++++++++++++- src/gui/widget_style.c | 4 +--- src/ime.c | 2 ++ src/keyboard.c | 2 +- 10 files changed, 38 insertions(+), 16 deletions(-) diff --git a/include/LCUI/gui/widget/textedit.h b/include/LCUI/gui/widget/textedit.h index c748ba34..7611e91b 100644 --- a/include/LCUI/gui/widget/textedit.h +++ b/include/LCUI/gui/widget/textedit.h @@ -58,6 +58,9 @@ LCUI_API int TextEdit_GetTextW( LCUI_Widget widget, int start, int max_len, wcha /** 获取文本长度 */ LCUI_API int TextEdit_GetTextLength( LCUI_Widget w ); +/** 设置文本编辑框内的光标,指定是否闪烁、闪烁时间间隔 */ +LCUI_API void TextEdit_SetCaretBlink( LCUI_Widget w, LCUI_BOOL enabled, int time ); + /** 为文本框设置文本(宽字符版) */ LCUI_API int TextEdit_SetTextW( LCUI_Widget widget, const wchar_t *wstr ); @@ -76,4 +79,4 @@ LCUI_API int TextEdit_SetPlaceHolder( LCUI_Widget w, const char *str ); LCUI_END_HEADER -#endif \ No newline at end of file +#endif diff --git a/src/Makefile.am b/src/Makefile.am index d586ecc6..7502f699 100755 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,7 +3,7 @@ AUTOMAKE_OPTIONS=foreign AM_CFLAGS = -I$(abs_top_srcdir)/include ##以下是给Libtool的参数 LCUI_LDFLAGS = -version-info 3:0:0 -LCUI_SOURCES = graph.c ime.c cursor.c main.c timer.c display.c +LCUI_SOURCES = graph.c ime.c cursor.c main.c timer.c display.c keyboard.c LCUI_LIBADD = thread/libthread.la util/libutil.la platform/libplatform.la \ bmp/libbmp.la draw/libdraw.la gui/libgui.la font/libfont.la \ font/in-core/libfont_incore.la $(LCUI_LIBS) diff --git a/src/bmp/png.c b/src/bmp/png.c index 8a5a8532..727034aa 100644 --- a/src/bmp/png.c +++ b/src/bmp/png.c @@ -105,7 +105,7 @@ int Graph_LoadPNG( const char *filepath, LCUI_Graph *graph ) graph->color_type = COLOR_TYPE_ARGB; temp = Graph_Create( graph, w, h ); if( temp != 0 ) { - ret = ENOMEM; + ret = -ENOMEM; break; } pixel_ptr = graph->bytes; @@ -127,7 +127,7 @@ int Graph_LoadPNG( const char *filepath, LCUI_Graph *graph ) graph->color_type = COLOR_TYPE_RGB; temp = Graph_Create( graph, w, h ); if( temp != 0 ) { - ret = ENOMEM; + ret = -ENOMEM; break; } pixel_ptr = graph->bytes; @@ -144,10 +144,11 @@ int Graph_LoadPNG( const char *filepath, LCUI_Graph *graph ) } fclose( fp ); png_destroy_read_struct( &png_ptr, &info_ptr, 0 ); + return ret; #else _DEBUG_MSG( "warning: not PNG support!" ); + return -1; #endif - return ret; } int Graph_GetPNGSize( const char *filepath, int *width, int *height ) @@ -183,10 +184,11 @@ int Graph_GetPNGSize( const char *filepath, int *width, int *height ) *height = png_get_image_height( png_ptr, info_ptr ); fclose( fp ); png_destroy_read_struct( &png_ptr, &info_ptr, 0 ); + return 0; #else _DEBUG_MSG( "warning: not PNG support!" ); + return -1; #endif - return ret; } int Graph_WritePNG( const char *file_name, const LCUI_Graph *graph ) diff --git a/src/font/in-core/font_inconsolata.c b/src/font/in-core/font_inconsolata.c index 3d5e0104..30677e6d 100644 --- a/src/font/in-core/font_inconsolata.c +++ b/src/font/in-core/font_inconsolata.c @@ -7615,7 +7615,7 @@ static const unsigned char *font_bitmap[SIZE_TOTAL] = { int FontInconsolata_GetBitmap( LCUI_FontBitmap *bmp, wchar_t ch, int size ) { - int i, j; + int i, j, *ptr; const uchar_t *byte_ptr; if( size < 12 || size > 18 ) { @@ -7664,7 +7664,7 @@ int FontInconsolata_GetBitmap( LCUI_FontBitmap *bmp, wchar_t ch, int size ) i = size - 12; j = ch - ' '; *bmp = font_info_index[i][j]; - j = *((int*)&bmp->buffer); + j = *(ptr = (int*)&bmp->buffer); byte_ptr = &font_bitmap[i][j]; size = sizeof(unsigned char)*bmp->width*bmp->rows; bmp->buffer = (uchar_t*)malloc(size); diff --git a/src/gui/Makefile.am b/src/gui/Makefile.am index 38102dec..ccda2759 100755 --- a/src/gui/Makefile.am +++ b/src/gui/Makefile.am @@ -12,6 +12,7 @@ widget_background.c \ css_parser.c \ builder.c \ widget/textview.c \ +widget/textedit.c \ widget/sidebar.c \ widget/scrollbar.c \ widget/button.c diff --git a/src/gui/builder.c b/src/gui/builder.c index 2852459c..fdf3eb34 100644 --- a/src/gui/builder.c +++ b/src/gui/builder.c @@ -37,6 +37,7 @@ * 没有,请查看:. * ****************************************************************************/ +#include #include #include #include @@ -44,7 +45,7 @@ #include #include -#define WARNING_TEXT "[builder] warning: this module is not enabled before build." +#define WARN_TXT "[builder] warning: this module is not enabled before build.\n" #ifdef USE_LCUI_BUILDER #include @@ -268,7 +269,7 @@ static void ParseNode( XMLParserContext ctx, xmlNodePtr node ) LCUI_Widget LCUIBuilder_LoadString( const char *str, int size ) { #ifndef USE_LCUI_BUILDER - printf(WARNING_TEXT); + printf(WARN_TXT); #else xmlDocPtr doc; xmlNodePtr cur; @@ -302,7 +303,7 @@ FAILED: LCUI_Widget LCUIBuilder_LoadFile( const char *filepath ) { #ifndef USE_LCUI_BUILDER - printf(WARNING_TEXT); + printf(WARN_TXT); #else xmlDocPtr doc; xmlNodePtr cur; diff --git a/src/gui/widget/textedit.c b/src/gui/widget/textedit.c index 8608f7e6..4051bc4d 100644 --- a/src/gui/widget/textedit.c +++ b/src/gui/widget/textedit.c @@ -39,6 +39,8 @@ //#define DEBUG #include +#include +#include #include #include #include @@ -586,6 +588,19 @@ int TextEdit_SetPlaceHolder( LCUI_Widget w, const char *str ) return ret; } +void TextEdit_SetCaretBlink( LCUI_Widget w, LCUI_BOOL enabled, int time ) +{ + LCUI_TextEdit edit; + edit = w->private_data; + TextCaret_SetVisible( edit->caret, enabled ); + TextCaret_SetBlinkTime( edit->caret, time ); +} + +static void TextEdit_OnParseText( LCUI_Widget w, const char *text ) +{ + TextEdit_SetText( w, text ); +} + static void TextEdit_OnFocus( LCUI_Widget widget, LCUI_WidgetEvent e, void *arg ) { LCUI_TextEdit edit; @@ -889,7 +904,7 @@ void LCUIWidget_AddTextEdit( void ) wc->methods.init = TextEdit_OnInit; wc->methods.paint = TextEdit_OnPaint; wc->methods.destroy = TextEdit_OnDestroy; - wc->methods.set_text = TextEdit_SetText; + wc->methods.set_text = TextEdit_OnParseText; wc->methods.set_attr = TextEdit_SetAttr; wc->methods.autosize = TextEdit_AutoSize; wc->task_handler = TextEdit_OnTask; diff --git a/src/gui/widget_style.c b/src/gui/widget_style.c index 2af7c09d..eb9badfc 100644 --- a/src/gui/widget_style.c +++ b/src/gui/widget_style.c @@ -794,7 +794,7 @@ static void StyleSheetFinder_Destroy( StyleSheetFinder sfinder ) int StyleSheetFinder_Find( StyleSheetFinder sfinder, LinkedList *list ) { LinkedListNode *node; - int i, name_len, len, old_len, old_level, count = 0; + int i, len, old_len, old_level, count = 0; char *fullname = sfinder->name + sfinder->name_i; old_len = len = strlen( fullname ); old_level = sfinder->level; @@ -856,7 +856,6 @@ int StyleSheetFinder_Find( StyleSheetFinder sfinder, LinkedList *list ) i += 1; continue; } - name_len = strlen( node->data ); strcpy( fullname + len, node->data ); count += FindStyleNodeByName( fullname, sfinder->widget, list ); @@ -914,7 +913,6 @@ int StyleSheetFinder_Find( StyleSheetFinder sfinder, LinkedList *list ) continue; } fullname[len] = ':'; - name_len = strlen( node->data ); strcpy( fullname + len + 1, node->data ); count += FindStyleNodeByName( fullname, sfinder->widget, list ); diff --git a/src/ime.c b/src/ime.c index a7805e43..e14bb80f 100644 --- a/src/ime.c +++ b/src/ime.c @@ -39,6 +39,7 @@ #include #include +#include #include #include #include @@ -334,6 +335,7 @@ void LCUI_InitIME( void ) void LCUI_ExitIME( void ) { self.is_inited = FALSE; + LinkedList_ClearData( &self.list, LCUIIME_OnDestroy ); } diff --git a/src/keyboard.c b/src/keyboard.c index c220bbec..73fdd92c 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ - #include +#include #include #include #include From e46615573f4d30a5ae618af04318d3e9588ae58f Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Tue, 5 Jul 2016 20:47:50 +0800 Subject: [PATCH 072/124] Update badge --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9cbf23bd..f37ee474 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,11 @@ # The LCUI Project +![LCUI Logo](http://lcui.org/static/images/lcui-project-logo.png) + [![Join the chat at https://gitter.im/lc-soft/LCUI](https://badges.gitter.im/lc-soft/LCUI.svg)](https://gitter.im/lc-soft/LCUI?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Build Status](https://travis-ci.org/lc-soft/LCUI.png?branch=master)](https://travis-ci.org/lc-soft/LCUI) - -![LCUI Logo](http://lcui.org/static/images/lcui-project-logo.png) +[![Downloads](https://img.shields.io/sourceforge/dt/lc-ui.svg)](https://sourceforge.net/projects/lc-ui) +[![License](https://img.shields.io/badge/license-GPLv2-blue.svg)](http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) ## Description From 521d88f925b1fab74e74d0a550bc14da2ee9a93e Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Sat, 9 Jul 2016 18:12:50 +0800 Subject: [PATCH 073/124] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20linux=20=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E4=B8=8B=E7=9A=84=E5=AD=97=E7=AC=A6=E4=B8=B2=E7=BC=96?= =?UTF-8?q?=E7=A0=81=E8=BD=AC=E6=8D=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/font/charset.c | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/src/font/charset.c b/src/font/charset.c index 4ca34d8c..3f51d3f5 100755 --- a/src/font/charset.c +++ b/src/font/charset.c @@ -1,7 +1,7 @@ /* *************************************************************************** * charset.c -- The charset opreation set. * -* Copyright (C) 2012-2016 by Liu Chao +* Copyright (C) 2015-2016 by Liu Chao * * 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 @@ /* **************************************************************************** * charset.c -- 字符集的相关操作函数 * -* 版权所有 (C) 2013-2016 归属于 刘超 +* 版权所有 (C) 2015-2016 归属于 刘超 * * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 * @@ -39,7 +39,7 @@ #include #include -#include +#include #include #include @@ -48,6 +48,25 @@ #define MAX_SAVE_NUM 20 +#ifdef LCUI_BUILD_IN_LINUX +static int SetLocaleByEncoding( int encoding ) +{ + const char *locale; + switch( encoding ) { + case ENCODING_ANSI: + locale = NULL; + break; + case ENCODING_UTF8: + locale = "zh_CN.UTF-8"; + break; + default: return -1; + } + if( !setlocale( LC_CTYPE, locale ) ) { + return -1; + } + return 0; +} +#else /** 将UTF-8字符串解码成 Unicode 字符串 */ static int DecodeFromUTF8( wchar_t *wstr, int max_len, const char *str ) { @@ -107,9 +126,12 @@ static int DecodeFromUTF8( wchar_t *wstr, int max_len, const char *str ) return len; } +#endif + int LCUI_DecodeString( wchar_t *wstr, const char *str, int max_len, int encoding ) { +#ifdef LCUI_BUILD_IN_WIN32 // 暂时不处理其它编码方式 switch( encoding ) { case ENCODING_ANSI: @@ -117,6 +139,12 @@ int LCUI_DecodeString( wchar_t *wstr, const char *str, default: break; } return DecodeFromUTF8( wstr, max_len, str ); +#else + if( SetLocaleByEncoding( encoding ) != 0 ) { + return -1; + } + return mbstowcs( wstr, str, max_len ); +#endif } #ifdef LCUI_BUILD_IN_WIN32 @@ -137,6 +165,9 @@ int LCUI_EncodeString( char *str, const wchar_t *wstr, } return encode( cp, wstr, str, max_len ); #else - return -1; + if( SetLocaleByEncoding( encoding ) != 0 ) { + return -1; + } + return wcstombs( str, wstr, max_len ); #endif } From 077ceec716d7f63687f7604a9eafcd3be4d26c41 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Sat, 9 Jul 2016 18:14:09 +0800 Subject: [PATCH 074/124] =?UTF-8?q?=E8=A1=A5=E5=85=85=20linux=20=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E4=B8=8B=E7=9A=84=E4=BA=8B=E4=BB=B6=E5=A4=84=E7=90=86?= =?UTF-8?q?=E5=92=8C=E5=9B=BE=E5=BD=A2=E8=BE=93=E5=87=BA=E7=9A=84=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 图形输出支持代码有待继续补充。 --- include/LCUI/platform/linux/linux_display.h | 3 + include/LCUI/platform/linux/linux_events.h | 1 + .../LCUI/platform/linux/linux_x11display.h | 8 + include/LCUI/platform/linux/linux_x11events.h | 24 ++ src/display.c | 6 +- src/gui/widget_event.c | 3 +- src/platform/linux/linux_display.c | 6 + src/platform/linux/linux_events.c | 4 + src/platform/linux/linux_x11display.c | 385 ++++++++++++++++++ src/platform/linux/linux_x11events.c | 126 +++++- 10 files changed, 548 insertions(+), 18 deletions(-) diff --git a/include/LCUI/platform/linux/linux_display.h b/include/LCUI/platform/linux/linux_display.h index d28407fc..83c2f19e 100644 --- a/include/LCUI/platform/linux/linux_display.h +++ b/include/LCUI/platform/linux/linux_display.h @@ -1,6 +1,9 @@ #ifndef LCUI_LINUX_DISPLAY_H #define LCUI_LINUX_DISPLAY_H +#include +#include + int LCUI_InitLinuxDisplay( LCUI_DisplayDriver driver ); int LCUI_ExitLinuxDisplay( void ); diff --git a/include/LCUI/platform/linux/linux_events.h b/include/LCUI/platform/linux/linux_events.h index 374e4926..8a29efce 100644 --- a/include/LCUI/platform/linux/linux_events.h +++ b/include/LCUI/platform/linux/linux_events.h @@ -1,6 +1,7 @@ #ifndef LCUI_LINUX_EVENTS_H #define LCUI_LINUX_EVENTS_H +#include int LCUI_InitLinuxApp( LCUI_AppDriver app ); diff --git a/include/LCUI/platform/linux/linux_x11display.h b/include/LCUI/platform/linux/linux_x11display.h index 8b137891..d0d32d07 100644 --- a/include/LCUI/platform/linux/linux_x11display.h +++ b/include/LCUI/platform/linux/linux_x11display.h @@ -1 +1,9 @@ +#ifndef LCUI_LINUX_X11_DISPLAY_H +#define LCUI_LINUX_X11_DISPLAY_H + +int LCUI_InitLinuxX11Display( LCUI_DisplayDriver driver ); + +int LCUI_ExitLinuxX11Display( void ); + +#endif \ No newline at end of file diff --git a/include/LCUI/platform/linux/linux_x11events.h b/include/LCUI/platform/linux/linux_x11events.h index 8b137891..6aad4ab3 100644 --- a/include/LCUI/platform/linux/linux_x11events.h +++ b/include/LCUI/platform/linux/linux_x11events.h @@ -1 +1,25 @@ +#ifndef LCUI_LINUX_X11_EVENTS_H +#define LCUI_LINUX_X11_EVENTS_H +#include +#include +#include +#include + +typedef struct LCUI_X11AppDriverRec_ { + int screen; + Display *display; + Window win_root; + Window win_main; + Colormap cmap; + Atom wm_lcui; + LCUI_EventTrigger trigger; +} LCUI_X11AppDriverRec, *LCUI_X11AppDriver; + +void LCUI_SetLinuxX11MainWindow( Window win ); + +void LCUI_PreInitLinuxX11App( void *data ); + +int LCUI_InitLinuxX11App( LCUI_AppDriver app ); + +#endif diff --git a/src/display.c b/src/display.c index 49523aa8..6f16a38f 100644 --- a/src/display.c +++ b/src/display.c @@ -113,6 +113,9 @@ static void LCUIDisplay_Update(void) /* 在 surface 上逐个重绘无效区域 */ LinkedList_ForEach( rn, &rlist ) { paint = Surface_BeginPaint( p_sr->surface, rn->data ); + if( !paint ) { + continue; + } DEBUG_MSG( "[%s]: render rect: (%d,%d,%d,%d)\n", p_sr->widget->type, paint->rect.left, paint->rect.top, paint->rect.w, paint->rect.h ); @@ -504,7 +507,6 @@ static void OnSurfaceEvent( LCUI_Widget w, LCUI_WidgetEvent e, void *arg ) e_type = *((int*)&arg); root = LCUIWidget_GetRoot(); surface = LCUIDisplay_GetBindSurface( e->target ); - DEBUG_MSG("tip, widget: %s, e_type = %d\n", w->type, e_type); if( display.mode == LCDM_SEAMLESS ) { if( !surface && e_type != WET_ADD ) { return; @@ -605,7 +607,7 @@ int LCUI_InitDisplay( void ) FrameControl_SetMaxFPS( display.fc_ctx, MAX_FRAMES_PER_SEC ); Widget_BindEvent( root, "surface", OnSurfaceEvent, NULL, NULL ); LCUIDisplay_SetMode( LCDM_DEFAULT ); - printf("[display] init ok.\n"); + printf("[display] init ok, driver name: %s\n", display.driver.name); return LCUIThread_Create( &display.thread, LCUIDisplay_Thread, NULL ); } diff --git a/src/gui/widget_event.c b/src/gui/widget_event.c index a652f7d1..d75a55e4 100644 --- a/src/gui/widget_event.c +++ b/src/gui/widget_event.c @@ -37,6 +37,7 @@ * 没有,请查看:. * ***************************************************************************/ //#define DEBUG +#include #include #include #include @@ -496,6 +497,7 @@ static int Widget_TriggerEventEx( LCUI_Widget widget, LCUI_WidgetEvent e, return Widget_PostEvent( widget->parent, e, data, destroy_data ); } + return 0; } if( !widget->parent || e->cancel_bubble ) { return -1; @@ -893,7 +895,6 @@ int Widget_PostSurfaceEvent( LCUI_Widget w, int event_type ) } e.target = w; e.type = WET_SURFACE; - DEBUG_MSG("widget: %s, post event: %d\n", w->type, event_type ); return Widget_PostEvent( root, &e, *((int**)n), NULL ); } diff --git a/src/platform/linux/linux_display.c b/src/platform/linux/linux_display.c index 7b2b7998..5d97fc5f 100644 --- a/src/platform/linux/linux_display.c +++ b/src/platform/linux/linux_display.c @@ -4,9 +4,15 @@ #include #include #include +#include LCUI_EVENTS_H +#include LCUI_DISPLAY_H int LCUI_InitLinuxDisplay( LCUI_DisplayDriver driver ) { + LCUI_BOOL is_x11_mode = TRUE; + if( is_x11_mode ) { + return LCUI_InitLinuxX11Display( driver ); + } return -1; } diff --git a/src/platform/linux/linux_events.c b/src/platform/linux/linux_events.c index 8c90705a..6092f322 100644 --- a/src/platform/linux/linux_events.c +++ b/src/platform/linux/linux_events.c @@ -13,6 +13,10 @@ void LCUI_PreInitLinuxApp( void *data ) int LCUI_InitLinuxApp( LCUI_AppDriver app ) { + LCUI_BOOL is_x11_mode = TRUE; + if( is_x11_mode ) { + return LCUI_InitLinuxX11App( app ); + } return -1; } #endif diff --git a/src/platform/linux/linux_x11display.c b/src/platform/linux/linux_x11display.c index 8b137891..f7ffbcd7 100644 --- a/src/platform/linux/linux_x11display.c +++ b/src/platform/linux/linux_x11display.c @@ -1 +1,386 @@ +/* *************************************************************************** + * linux_x11display.c -- surface support for linux xwindow. + * + * Copyright (C) 2016 by Liu Chao + * + * 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 . + * ****************************************************************************/ +/* **************************************************************************** + * linux_x11display.c -- linux 平台的图形显示功能支持,基于 xwindow。 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ + +//#define DEBUG +#include +#include +#include +#define LCUI_SURFACE_C +#ifdef LCUI_BUILD_IN_LINUX +#include +#include +#include +#include +#include LCUI_DISPLAY_H +#include LCUI_EVENTS_H + +#define MIN_WIDTH 50 +#define MIN_HEIGHT 50 + +enum SurfaceTaskType { + TASK_CREATE, + TASK_MOVE, + TASK_RESIZE, + TASK_SHOW, + TASK_SET_CAPTION, + TASK_DELETE, + TASK_TOTAL_NUM +}; + +typedef struct LCUI_SurfaceTaskRec_ { + int type; + union { + struct { + int x, y; + }; + struct { + int width, height; + }; + LCUI_BOOL show; + struct { + char *caption; + size_t caption_len; + }; + }; +} LCUI_SurfaceTaskRec, *LCUI_SurfaceTask; + +typedef struct LCUI_SurfaceRec_ { + int mode; + int w, h; + GC gc; + Window window; + XImage ximage; + LCUI_BOOL is_ready; + LCUI_Graph fb; + LinkedListNode node; +} LCUI_SurfaceRec; + +static struct X11_Display { + XVisualInfo vinfo; + LCUI_BOOL is_inited; + LinkedList surfaces; + LCUI_X11AppDriver app; + LCUI_EventTrigger trigger; +} x11; + +LCUI_Surface main_surface; + +static void ReleaseSurfaceTask( void *arg ) +{ + LCUI_SurfaceTask task = arg; + if( task->type == TASK_SET_CAPTION ) { + free( task->caption ); + task->caption = NULL; + } +} + +static void X11Surface_OnCreate( LCUI_Surface s ) +{ + XGCValues gcv; + gcv.graphics_exposures = False; + unsigned long bdcolor = BlackPixel(x11.app->display, x11.app->screen); + unsigned long bgcolor = WhitePixel(x11.app->display, x11.app->screen); + s->window = XCreateSimpleWindow( x11.app->display, x11.app->win_root, + 0, 100, MIN_WIDTH, MIN_HEIGHT, 1, + bdcolor, bgcolor ); + s->gc = XCreateGC( x11.app->display, s->window, + GCGraphicsExposures, &gcv ); + if( !s->gc ) { + printf("[x11display] create graphics context faild.\n"); + return; + } + s->is_ready = TRUE; + main_surface = s; + LCUI_SetLinuxX11MainWindow( s->window ); +} + +static void X11Surface_OnTask( LCUI_Surface surface, LCUI_SurfaceTask task ) +{ + Window win = surface->window; + Display *dpy = x11.app->display; + + switch( task->type ) { + case TASK_CREATE: + X11Surface_OnCreate( surface ); + break; + case TASK_RESIZE: { + int w = task->width , h = task->height; + w = MIN_WIDTH > w ? MIN_WIDTH: w; + h = MIN_HEIGHT > h ? MIN_HEIGHT: h; + XResizeWindow( dpy, win, w, h ); + break; + } + case TASK_MOVE: + XMoveWindow( dpy, win, task->x, task->y ); + break; + case TASK_SHOW: + if( task->show ) { + XMapWindow( dpy, win ); + } else { + XUnmapWindow( dpy, win ); + } + break; + case TASK_SET_CAPTION: { + XTextProperty name; + name.value = (unsigned char*)task->caption; + name.encoding = XA_STRING; + name.format = 8 * sizeof(char); + name.nitems = task->caption_len; + XSetWMName( dpy, win, &name ); + break; + } + case TASK_DELETE: + default: break; + } +} + +static void X11Surface_SendTask( LCUI_Surface surface, LCUI_SurfaceTask task ) +{ + LCUI_AppTaskRec apptask; + LCUI_SurfaceTask newtask; + newtask = NEW( LCUI_SurfaceTaskRec, 1 ); + *newtask = *task; + apptask.arg[0] = surface; + apptask.arg[1] = newtask; + apptask.destroy_arg[0] = NULL; + apptask.destroy_arg[1] = ReleaseSurfaceTask; + apptask.func = (LCUI_AppTaskFunc)X11Surface_OnTask; + LCUI_PostTask( &apptask ); +} + +static void X11Surface_Delete( LCUI_Surface surface ) +{ + LCUI_SurfaceTaskRec task; + task.type = TASK_DELETE; + LinkedList_Unlink( &x11.surfaces, &surface->node ); + X11Surface_SendTask( surface, &task ); +} + +static LCUI_Surface X11Surface_New( void ) +{ + LCUI_Surface surface; + LCUI_SurfaceTaskRec task; + task.type = TASK_CREATE; + surface = NEW( LCUI_SurfaceRec, 1 ); + surface->is_ready = FALSE; + surface->node.data = surface; + Graph_Init( &surface->fb ); + surface->fb.color_type = COLOR_TYPE_ARGB; + LinkedList_AppendNode( &x11.surfaces, &surface->node ); + X11Surface_SendTask( surface, &task ); + _DEBUG_MSG("create surface: %p\n", surface); + return surface; +} + +static LCUI_BOOL X11Surface_IsReady( LCUI_Surface surface ) +{ + return surface->is_ready; +} + +static void X11Surface_Move( LCUI_Surface surface, int x, int y ) +{ + LCUI_SurfaceTaskRec task; + task.type = TASK_MOVE; + task.x = x; + task.y = y; + X11Surface_SendTask( surface, &task ); +} + +static void X11Surface_Resize( LCUI_Surface surface, int width, int height ) +{ + LCUI_SurfaceTaskRec task; + task.type = TASK_RESIZE; + task.width = width; + task.height = height; + X11Surface_SendTask( surface, &task ); + _DEBUG_MSG("resize: %d, %d\n", width, height); +} + +static void X11Surface_Show( LCUI_Surface surface ) +{ + LCUI_SurfaceTaskRec task; + task.type = TASK_SHOW; + task.show = TRUE; + X11Surface_SendTask( surface, &task ); +} + +static void X11Surface_Hide( LCUI_Surface surface ) +{ + LCUI_SurfaceTaskRec task; + task.type = TASK_SHOW; + task.show = FALSE; + X11Surface_SendTask( surface, &task ); +} + +static void X11Surface_SetCaptionW( LCUI_Surface surface, const wchar_t *wstr ) +{ + int len; + LCUI_SurfaceTaskRec task; + + if( wstr ) { + char *caption; + len = LCUI_EncodeString( NULL, wstr, 0, ENCODING_UTF8 ) + 1; + caption = malloc( sizeof(char) * len ); + if( !caption ) { + return; + } + LCUI_EncodeString( caption, wstr, len, ENCODING_UTF8 ); + task.caption = caption; + task.caption_len = len - 1; + } else { + task.caption = NULL; + task.caption_len = 0; + } + task.type = TASK_SET_CAPTION; + X11Surface_SendTask( surface, &task ); +} + +void X11Surface_SetOpacity( LCUI_Surface surface, float opacity ) +{ + +} + +/** 设置 Surface 的渲染模式 */ +static void X11Surface_SetRenderMode( LCUI_Surface surface, int mode ) +{ + surface->mode = mode; +} + +/** +* 准备绘制 Surface 中的内容 +* @param[in] surface 目标 surface +* @param[in] rect 需进行绘制的区域,若为NULL,则绘制整个 surface +* @return 返回绘制上下文句柄 +*/ +static LCUI_PaintContext X11Surface_BeginPaint( LCUI_Surface surface, LCUI_Rect *rect ) +{ + return NULL; + /*** + LCUI_PaintContext paint; + paint = malloc(sizeof(LCUI_PaintContextRec)); + paint->rect = *rect; + paint->with_alpha = FALSE; + Graph_Init( &paint->canvas ); + LCUIRect_ValidateArea( &paint->rect, surface->w, surface->h ); + Graph_Quote( &paint->canvas, &surface->fb, &paint->rect ); + Graph_FillRect( &paint->canvas, RGB( 255, 255, 255 ), NULL, TRUE ); + return paint;***/ +} + +/** +* 结束对 Surface 的绘制操作 +* @param[in] surface 目标 surface +* @param[in] paint_ctx 绘制上下文句柄 +*/ +static void X11Surface_EndPaint( LCUI_Surface surface, LCUI_PaintContext paint_ctx ) +{ + free( paint_ctx ); +} + +/** 将帧缓存中的数据呈现至Surface的窗口内 */ +static void X11Surface_Present( LCUI_Surface surface ) +{ + +} + +/** 更新 surface,应用缓存的变更 */ +static void X11Surface_Update( LCUI_Surface surface ) +{ + return; +} + +static int WinDisplay_BindEvent( int event_id, LCUI_EventFunc func, + void *data, void (*destroy_data)(void*) ) +{ + return EventTrigger_Bind( x11.trigger, event_id, func, + data, destroy_data ); +} + +static void* X11Surface_GetHandle( LCUI_Surface s ) +{ + return NULL; +} + +static int X11Display_GetWidth( void ) +{ + Screen *s = DefaultScreenOfDisplay( x11.app->display ); + return XWidthOfScreen( s ); +} + +static int X11Display_GetHeight( void ) +{ + Screen *s = DefaultScreenOfDisplay( x11.app->display ); + return XHeightOfScreen( s ); +} + +int LCUI_InitLinuxX11Display( LCUI_DisplayDriver driver ) +{ + strcpy( driver->name, "x11" ); + x11.app = LCUI_GetAppData(); + driver->getWidth = X11Display_GetWidth; + driver->getHeight = X11Display_GetHeight; + driver->new = X11Surface_New; + driver->delete = X11Surface_Delete; + driver->isReady = X11Surface_IsReady; + driver->show = X11Surface_Show; + driver->hide = X11Surface_Hide; + driver->move = X11Surface_Move; + driver->resize = X11Surface_Resize; + driver->update = X11Surface_Update; + driver->present = X11Surface_Present; + driver->setCaptionW = X11Surface_SetCaptionW; + driver->setRenderMode = X11Surface_SetRenderMode; + driver->setOpacity = X11Surface_SetOpacity; + driver->getHandle = X11Surface_GetHandle; + driver->beginPaint = X11Surface_BeginPaint; + driver->endPaint = X11Surface_EndPaint; + driver->bindEvent = WinDisplay_BindEvent; + LinkedList_Init( &x11.surfaces ); + x11.trigger = EventTrigger(); + x11.is_inited = TRUE; + return 0; +} + +int LCUI_ExitLinuxX11Display( void ) +{ + // ... + return 0; +} + +#endif diff --git a/src/platform/linux/linux_x11events.c b/src/platform/linux/linux_x11events.c index 59542060..41b6e425 100644 --- a/src/platform/linux/linux_x11events.c +++ b/src/platform/linux/linux_x11events.c @@ -1,24 +1,59 @@ + +#include +#include #include -#if defined(LCUI_BUILD_IN_LINUX) -#include -#include -#include +#ifdef LCUI_BUILD_IN_LINUX #include #include #include #include LCUI_EVENTS_H -static struct X11Driver { - int screen; - Display *display; - Window rootwin; - Colormap cmap; - LCUI_EventTrigger trigger; -} x11; +static LCUI_X11AppDriverRec x11; + +enum AppTaskAgentState { + STATE_NONE, + STATE_RUNNING, + STATE_PAUSE +}; + +static struct AppTaskAgent { + int state; + LinkedList tasks; + LCUI_Mutex mutex; + LCUI_Cond cond; +} agent; + +void LCUI_SetLinuxX11MainWindow( Window win ) +{ + _DEBUG_MSG("set start.\n"); + LCUIMutex_Lock( &agent.mutex ); + agent.state = STATE_PAUSE; + x11.win_main = win; + LCUICond_Signal( &agent.cond ); + LCUIMutex_Unlock( &agent.mutex ); + XSelectInput(x11.display, win, ExposureMask | KeyPressMask); + _DEBUG_MSG("set done.\n"); +} static LCUI_BOOL X11_PostTask( LCUI_AppTask task ) { - return FALSE; + LCUIMutex_Lock( &agent.mutex ); + LinkedList_Append( &agent.tasks, task ); + LCUICond_Signal( &agent.cond ); + LCUIMutex_Unlock( &agent.mutex ); + if( agent.state == STATE_PAUSE && x11.win_main != 0 ) { + int ret; + XEvent ev; + memset( &ev, 0, sizeof (ev) ); + ev.xclient.type = ClientMessage; + ev.xclient.window = x11.win_main; + ev.xclient.format = 32; + ev.xclient.message_type = x11.wm_lcui; + ret = XSendEvent(x11.display, x11.win_main, FALSE, NoEventMask, &ev); + return TRUE; + } + _DEBUG_MSG("agent mode\n"); + return TRUE; } static LCUI_BOOL X11_WaitEvent( void ) @@ -26,6 +61,22 @@ static LCUI_BOOL X11_WaitEvent( void ) int fd; fd_set fdset; struct timeval zero_time; + if( agent.tasks.length > 0 ) { + return TRUE; + } + if( agent.state == STATE_RUNNING ) { + _DEBUG_MSG("agent mode\n"); + LCUIMutex_Lock( &agent.mutex ); + while( agent.state == STATE_RUNNING ) { + if( agent.tasks.length > 0 ) { + LCUIMutex_Unlock( &agent.mutex ); + return TRUE; + } + LCUICond_Wait( &agent.cond, &agent.mutex ); + } + LCUIMutex_Unlock( &agent.mutex ); + return FALSE; + } XFlush( x11.display ); fd = ConnectionNumber( x11.display ); if( XEventsQueued(x11.display, QueuedAlready) ) { @@ -39,9 +90,47 @@ static LCUI_BOOL X11_WaitEvent( void ) return FALSE; } +static void X11_DispatchEvent( void ) +{ + XEvent xevent; + LCUI_AppTask task; + LinkedListNode *node; + DEBUG_MSG("proc lcui task, length: %d\n", agent.tasks.length); + LCUIMutex_Lock( &agent.mutex ); + node = LinkedList_GetNode( &agent.tasks, 0 ); + if( node ) { + task = node->data; + LinkedList_Unlink( &agent.tasks, node ); + LCUIMutex_Unlock( &agent.mutex ); + LCUI_RunTask( task ); + LCUI_DeleteTask( task ); + free( task ); + free( node ); + return; + } else { + LCUIMutex_Unlock( &agent.mutex ); + } + if( agent.state == STATE_RUNNING ) { + return; + } + DEBUG_MSG("waiting xevent\n"); + XNextEvent( x11.display, &xevent ); + DEBUG_MSG("waitting is done\n"); + DEBUG_MSG("%d\n", xevent.type); + switch( xevent.type ) { + case ClientMessage: + DEBUG_MSG("message_type: %ld, wm_lcui: %ld\n", xevent.xclient.message_type, x11.wm_lcui); + default: break; + } + DEBUG_MSG("done\n"); +} + static void X11_PumpEvents( void ) { - + while( X11_WaitEvent() ) { + DEBUG_MSG("get event\n"); + X11_DispatchEvent(); + } } static int X11_BindSysEvent( int event_id, LCUI_EventFunc func, @@ -62,7 +151,7 @@ static int X11_UnbindSysEvent2( int handler_id ) static void *X11_GetData( void ) { - return NULL; + return &x11; } void LCUI_PreInitLinuxX11App( void *data ) @@ -77,8 +166,10 @@ int LCUI_InitLinuxX11App( LCUI_AppDriver app ) return -1; } x11.screen = DefaultScreen( x11.display ); - x11.rootwin = RootWindow( x11.display, x11.screen ); + x11.win_root = RootWindow( x11.display, x11.screen ); x11.cmap = DefaultColormap( x11.display, x11.screen ); + x11.wm_lcui = XInternAtom(x11.display, "WM_DELETE_WINDOW", FALSE); + XSetWMProtocols(x11.display, x11.win_root, &x11.wm_lcui, 1); app->WaitEvent = X11_WaitEvent; app->PumbEvents = X11_PumpEvents; app->PostTask = X11_PostTask; @@ -86,7 +177,12 @@ int LCUI_InitLinuxX11App( LCUI_AppDriver app ) app->UnbindSysEvent = X11_UnbindSysEvent; app->UnbindSysEvent2 = X11_UnbindSysEvent2; app->GetData = X11_GetData; + agent.state = STATE_RUNNING; + LinkedList_Init( &agent.tasks ); + LCUIMutex_Init( &agent.mutex ); + LCUICond_Init( &agent.cond ); x11.trigger = EventTrigger(); return 0; } + #endif From 7a8bd776c0e3f7c6d11db579721b824120e81449 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Sun, 10 Jul 2016 23:43:13 +0800 Subject: [PATCH 075/124] =?UTF-8?q?=E5=AE=8C=E5=96=84=20x11=20=E5=9B=BE?= =?UTF-8?q?=E5=BD=A2=E8=BE=93=E5=87=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Liu Chao --- src/display.c | 8 +- src/platform/linux/linux_x11display.c | 141 ++++++++++++++++++++------ src/platform/linux/linux_x11events.c | 18 +--- 3 files changed, 120 insertions(+), 47 deletions(-) diff --git a/src/display.c b/src/display.c index 6f16a38f..c2000ef9 100644 --- a/src/display.c +++ b/src/display.c @@ -51,6 +51,9 @@ #include #include LCUI_DISPLAY_H +#define DEFAULT_WIDTH 800 +#define DEFAULT_HEIGHT 600 + /** surface 记录 */ typedef struct SurfaceRecord { LCUI_Surface surface; /**< surface */ @@ -233,9 +236,10 @@ static int LCUIDisplay_Windowed( void ) { LCUI_Widget root = LCUIWidget_GetRoot(); switch( display.mode ) { - case LCDM_FULLSCREEN: case LCDM_WINDOWED: return 0; + case LCDM_FULLSCREEN: + break; case LCDM_SEAMLESS: default: LCUIDisplay_CleanSurfaces(); @@ -243,7 +247,7 @@ static int LCUIDisplay_Windowed( void ) break; } Widget_Show( root ); - Widget_Resize( root, LCUIDisplay_GetWidth(), LCUIDisplay_GetHeight() ); + Widget_Resize( root, DEFAULT_WIDTH, DEFAULT_HEIGHT ); display.mode = LCDM_WINDOWED; return 0; } diff --git a/src/platform/linux/linux_x11display.c b/src/platform/linux/linux_x11display.c index f7ffbcd7..1ab5e396 100644 --- a/src/platform/linux/linux_x11display.c +++ b/src/platform/linux/linux_x11display.c @@ -59,6 +59,7 @@ enum SurfaceTaskType { TASK_RESIZE, TASK_SHOW, TASK_SET_CAPTION, + TASK_PRESENT, TASK_DELETE, TASK_TOTAL_NUM }; @@ -82,12 +83,14 @@ typedef struct LCUI_SurfaceTaskRec_ { typedef struct LCUI_SurfaceRec_ { int mode; - int w, h; + int width; + int height; GC gc; Window window; - XImage ximage; + XImage *ximage; LCUI_BOOL is_ready; LCUI_Graph fb; + LinkedList rects; LinkedListNode node; } LCUI_SurfaceRec; @@ -99,8 +102,6 @@ static struct X11_Display { LCUI_EventTrigger trigger; } x11; -LCUI_Surface main_surface; - static void ReleaseSurfaceTask( void *arg ) { LCUI_SurfaceTask task = arg; @@ -110,23 +111,72 @@ static void ReleaseSurfaceTask( void *arg ) } } -static void X11Surface_OnCreate( LCUI_Surface s ) +static LCUI_Surface GetSurfaceByWindow( Window win ) { + LinkedListNode *node; + LinkedList_ForEach( node, &x11.surfaces ) { + if( ((LCUI_Surface)node->data)->window == win ) { + return node->data; + } + } + return NULL; +} + +static void X11Surface_OnResize( LCUI_Surface s, int width, int height ) +{ + int depth; XGCValues gcv; + Visual *visual; + if( s->ximage ) { + XDestroyImage( s->ximage ); + s->ximage = NULL; + } + if( s->gc ) { + XFreeGC( x11.app->display, s->gc ); + s->gc = NULL; + } + Graph_Init( &s->fb ); + s->width = width; + s->height = height; + depth = DefaultDepth( x11.app->display, x11.app->screen ); + switch( depth ) { + case 32: + case 24: + s->fb.color_type = COLOR_TYPE_ARGB; + break; + default: + printf("[x11display] unsupport depth: %d.\n", depth); + break; + } + Graph_Create( &s->fb, width, height ); + visual = DefaultVisual( x11.app->display, x11.app->screen ); + s->ximage = XCreateImage( x11.app->display, visual, depth, ZPixmap, + 0, (char *)(s->fb.bytes), + width, height, 32, 0 ); + if( !s->ximage ) { + Graph_Free( &s->fb ); + printf("[x11display] create XImage faild.\n"); + return; + } gcv.graphics_exposures = False; - unsigned long bdcolor = BlackPixel(x11.app->display, x11.app->screen); - unsigned long bgcolor = WhitePixel(x11.app->display, x11.app->screen); - s->window = XCreateSimpleWindow( x11.app->display, x11.app->win_root, - 0, 100, MIN_WIDTH, MIN_HEIGHT, 1, - bdcolor, bgcolor ); s->gc = XCreateGC( x11.app->display, s->window, GCGraphicsExposures, &gcv ); if( !s->gc ) { printf("[x11display] create graphics context faild.\n"); return; } +} + +static void X11Surface_OnCreate( LCUI_Surface s ) +{ + unsigned long bdcolor = BlackPixel(x11.app->display, x11.app->screen); + unsigned long bgcolor = WhitePixel(x11.app->display, x11.app->screen); + s->window = XCreateSimpleWindow( x11.app->display, x11.app->win_root, + 0, 100, MIN_WIDTH, MIN_HEIGHT, 1, + bdcolor, bgcolor ); + LinkedList_Init( &s->rects ); + X11Surface_OnResize( s, MIN_WIDTH, MIN_HEIGHT ); s->is_ready = TRUE; - main_surface = s; LCUI_SetLinuxX11MainWindow( s->window ); } @@ -143,6 +193,7 @@ static void X11Surface_OnTask( LCUI_Surface surface, LCUI_SurfaceTask task ) int w = task->width , h = task->height; w = MIN_WIDTH > w ? MIN_WIDTH: w; h = MIN_HEIGHT > h ? MIN_HEIGHT: h; + X11Surface_OnResize( surface, w, h ); XResizeWindow( dpy, win, w, h ); break; } @@ -165,6 +216,17 @@ static void X11Surface_OnTask( LCUI_Surface surface, LCUI_SurfaceTask task ) XSetWMName( dpy, win, &name ); break; } + case TASK_PRESENT: { + LinkedListNode *node; + LinkedList_ForEach( node, &surface->rects ) { + LCUI_Rect *rect = node->data; + XPutImage( x11.app->display, surface->window, surface->gc, + surface->ximage, 0, 0, rect->x, rect->y, + rect->width, rect->height); + } + LinkedList_Clear( &surface->rects, free ); + break; + } case TASK_DELETE: default: break; } @@ -200,11 +262,12 @@ static LCUI_Surface X11Surface_New( void ) surface = NEW( LCUI_SurfaceRec, 1 ); surface->is_ready = FALSE; surface->node.data = surface; + surface->gc = NULL; + surface->ximage = NULL; Graph_Init( &surface->fb ); surface->fb.color_type = COLOR_TYPE_ARGB; LinkedList_AppendNode( &x11.surfaces, &surface->node ); X11Surface_SendTask( surface, &task ); - _DEBUG_MSG("create surface: %p\n", surface); return surface; } @@ -229,7 +292,6 @@ static void X11Surface_Resize( LCUI_Surface surface, int width, int height ) task.width = width; task.height = height; X11Surface_SendTask( surface, &task ); - _DEBUG_MSG("resize: %d, %d\n", width, height); } static void X11Surface_Show( LCUI_Surface surface ) @@ -282,41 +344,37 @@ static void X11Surface_SetRenderMode( LCUI_Surface surface, int mode ) surface->mode = mode; } -/** -* 准备绘制 Surface 中的内容 -* @param[in] surface 目标 surface -* @param[in] rect 需进行绘制的区域,若为NULL,则绘制整个 surface -* @return 返回绘制上下文句柄 -*/ -static LCUI_PaintContext X11Surface_BeginPaint( LCUI_Surface surface, LCUI_Rect *rect ) +static LCUI_PaintContext X11Surface_BeginPaint( LCUI_Surface surface, + LCUI_Rect *rect ) { - return NULL; - /*** LCUI_PaintContext paint; paint = malloc(sizeof(LCUI_PaintContextRec)); paint->rect = *rect; paint->with_alpha = FALSE; Graph_Init( &paint->canvas ); - LCUIRect_ValidateArea( &paint->rect, surface->w, surface->h ); + LCUIRect_ValidateArea( &paint->rect, surface->width, surface->height ); Graph_Quote( &paint->canvas, &surface->fb, &paint->rect ); Graph_FillRect( &paint->canvas, RGB( 255, 255, 255 ), NULL, TRUE ); - return paint;***/ + return paint; } -/** -* 结束对 Surface 的绘制操作 -* @param[in] surface 目标 surface -* @param[in] paint_ctx 绘制上下文句柄 -*/ -static void X11Surface_EndPaint( LCUI_Surface surface, LCUI_PaintContext paint_ctx ) +static void X11Surface_EndPaint( LCUI_Surface surface, + LCUI_PaintContext paint ) { - free( paint_ctx ); + LCUI_Rect *r; + r = NEW( LCUI_Rect, 1 ); + *r = paint->rect; + LinkedList_Append( &surface->rects, r ); + free( paint ); } /** 将帧缓存中的数据呈现至Surface的窗口内 */ static void X11Surface_Present( LCUI_Surface surface ) { + LCUI_SurfaceTaskRec task; + task.type = TASK_PRESENT; + X11Surface_SendTask( surface, &task ); } /** 更新 surface,应用缓存的变更 */ @@ -349,6 +407,26 @@ static int X11Display_GetHeight( void ) return XHeightOfScreen( s ); } +static void OnExpose( LCUI_Event e, void *arg ) +{ + LCUI_Rect rect; + XEvent *ev = arg; + LCUI_Surface surface; + LCUI_DisplayEventRec dpy_ev; + rect.x = ev->xexpose.x; + rect.y = ev->xexpose.y; + rect.width = ev->xexpose.width; + rect.height = ev->xexpose.height; + surface = GetSurfaceByWindow( ev->xexpose.window ); + if( !surface ) { + return; + } + dpy_ev.type = DET_PAINT; + dpy_ev.surface = surface; + dpy_ev.paint.rect = rect; + EventTrigger_Trigger( x11.trigger, DET_PAINT, &dpy_ev ); +} + int LCUI_InitLinuxX11Display( LCUI_DisplayDriver driver ) { strcpy( driver->name, "x11" ); @@ -372,6 +450,7 @@ int LCUI_InitLinuxX11Display( LCUI_DisplayDriver driver ) driver->endPaint = X11Surface_EndPaint; driver->bindEvent = WinDisplay_BindEvent; LinkedList_Init( &x11.surfaces ); + LCUI_BindSysEvent( Expose, OnExpose, NULL, NULL ); x11.trigger = EventTrigger(); x11.is_inited = TRUE; return 0; diff --git a/src/platform/linux/linux_x11events.c b/src/platform/linux/linux_x11events.c index 41b6e425..92b46d9f 100644 --- a/src/platform/linux/linux_x11events.c +++ b/src/platform/linux/linux_x11events.c @@ -25,14 +25,12 @@ static struct AppTaskAgent { void LCUI_SetLinuxX11MainWindow( Window win ) { - _DEBUG_MSG("set start.\n"); LCUIMutex_Lock( &agent.mutex ); agent.state = STATE_PAUSE; x11.win_main = win; LCUICond_Signal( &agent.cond ); LCUIMutex_Unlock( &agent.mutex ); XSelectInput(x11.display, win, ExposureMask | KeyPressMask); - _DEBUG_MSG("set done.\n"); } static LCUI_BOOL X11_PostTask( LCUI_AppTask task ) @@ -42,17 +40,15 @@ static LCUI_BOOL X11_PostTask( LCUI_AppTask task ) LCUICond_Signal( &agent.cond ); LCUIMutex_Unlock( &agent.mutex ); if( agent.state == STATE_PAUSE && x11.win_main != 0 ) { - int ret; XEvent ev; memset( &ev, 0, sizeof (ev) ); ev.xclient.type = ClientMessage; ev.xclient.window = x11.win_main; ev.xclient.format = 32; ev.xclient.message_type = x11.wm_lcui; - ret = XSendEvent(x11.display, x11.win_main, FALSE, NoEventMask, &ev); + XSendEvent(x11.display, x11.win_main, FALSE, NoEventMask, &ev); return TRUE; } - _DEBUG_MSG("agent mode\n"); return TRUE; } @@ -65,7 +61,6 @@ static LCUI_BOOL X11_WaitEvent( void ) return TRUE; } if( agent.state == STATE_RUNNING ) { - _DEBUG_MSG("agent mode\n"); LCUIMutex_Lock( &agent.mutex ); while( agent.state == STATE_RUNNING ) { if( agent.tasks.length > 0 ) { @@ -95,7 +90,6 @@ static void X11_DispatchEvent( void ) XEvent xevent; LCUI_AppTask task; LinkedListNode *node; - DEBUG_MSG("proc lcui task, length: %d\n", agent.tasks.length); LCUIMutex_Lock( &agent.mutex ); node = LinkedList_GetNode( &agent.tasks, 0 ); if( node ) { @@ -113,22 +107,18 @@ static void X11_DispatchEvent( void ) if( agent.state == STATE_RUNNING ) { return; } - DEBUG_MSG("waiting xevent\n"); XNextEvent( x11.display, &xevent ); - DEBUG_MSG("waitting is done\n"); DEBUG_MSG("%d\n", xevent.type); switch( xevent.type ) { case ClientMessage: - DEBUG_MSG("message_type: %ld, wm_lcui: %ld\n", xevent.xclient.message_type, x11.wm_lcui); default: break; } - DEBUG_MSG("done\n"); + EventTrigger_Trigger( x11.trigger, xevent.type, &xevent ); } static void X11_PumpEvents( void ) { while( X11_WaitEvent() ) { - DEBUG_MSG("get event\n"); X11_DispatchEvent(); } } @@ -168,8 +158,8 @@ int LCUI_InitLinuxX11App( LCUI_AppDriver app ) x11.screen = DefaultScreen( x11.display ); x11.win_root = RootWindow( x11.display, x11.screen ); x11.cmap = DefaultColormap( x11.display, x11.screen ); - x11.wm_lcui = XInternAtom(x11.display, "WM_DELETE_WINDOW", FALSE); - XSetWMProtocols(x11.display, x11.win_root, &x11.wm_lcui, 1); + x11.wm_lcui = XInternAtom( x11.display, "WM_LCUI", FALSE ); + XSetWMProtocols( x11.display, x11.win_root, &x11.wm_lcui, 1 ); app->WaitEvent = X11_WaitEvent; app->PumbEvents = X11_PumpEvents; app->PostTask = X11_PostTask; From 745d8d10cab1094d0ce4e9940f67ed566ac3f96d Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Mon, 11 Jul 2016 00:19:22 +0800 Subject: [PATCH 076/124] =?UTF-8?q?=E5=B0=86=20linux=5Fx11events.c=20?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E4=BB=BB=E5=8A=A1=E4=BB=A3=E7=90=86=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E7=A7=BB=E5=85=A5=20main.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/main.h | 4 +- src/main.c | 108 ++++++++++++++++++++------- src/platform/linux/linux_x11events.c | 88 +++------------------- 3 files changed, 96 insertions(+), 104 deletions(-) diff --git a/include/LCUI/main.h b/include/LCUI/main.h index b056eefa..e77a2e48 100644 --- a/include/LCUI/main.h +++ b/include/LCUI/main.h @@ -123,7 +123,7 @@ typedef void(*LCUI_SysEventFunc)(LCUI_SysEvent, void*); /** LCUI 应用程序驱动接口,封装了各个平台下的应用程序相关功能支持接口 */ typedef struct LCUI_AppDriverRec_ { - void( *PumbEvents )(void); + void( *DispatchEvent )(void); LCUI_BOOL( *WaitEvent )(void); LCUI_BOOL( *PostTask )(LCUI_AppTask); int( *BindSysEvent )(int, LCUI_EventFunc, void*, void( *)(void*)); @@ -158,6 +158,8 @@ LCUI_API void LCUI_PumbEvents( void ); LCUI_API void *LCUI_GetAppData( void ); +LCUI_API void LCUI_SetTaskAgent( LCUI_BOOL enabled ); + /** 添加任务 */ LCUI_API LCUI_BOOL LCUI_PostTask( LCUI_AppTask task ); diff --git a/src/main.c b/src/main.c index 052cf800..e9f742a8 100644 --- a/src/main.c +++ b/src/main.c @@ -81,27 +81,26 @@ static struct LCUI_System { int state; /**< 状态 */ int mode; /**< LCUI的运行模式 */ LCUI_BOOL is_inited; /**< 标志,指示LCUI是否初始化过 */ - unsigned long int main_tid; /**< 主线程ID */ - struct { LCUI_EventTrigger trigger; /**< 系统事件容器 */ LCUI_Mutex mutex; /**< 互斥锁 */ } event; - - int exit_code; /**< 退出码 */ - void (*func_atexit)(void); /**< 在LCUI退出时调用的函数 */ } System; /** LCUI 应用程序数据 */ static struct LCUI_App { - LinkedList tasks; /**< 程序的任务队列 */ - LCUI_Mutex tasks_mutex; /**< 任务记录互斥锁 */ LCUI_Mutex loop_mutex; /**< 互斥锁,确保一次只允许一个线程跑主循环 */ LCUI_Cond loop_changed; /**< 条件变量,用于指示当前运行的主循环是否改变 */ LCUI_MainLoop loop; /**< 当前运行的主循环 */ LinkedList loops; /**< 主循环列表 */ LCUI_AppDriverRec driver; /**< 程序事件驱动支持 */ + struct LCUI_AppTaskAgent { + int state; /**< 状态 */ + LinkedList tasks; /**< 任务队列 */ + LCUI_Mutex mutex; /**< 互斥锁 */ + LCUI_Cond cond; /**< 条件变量 */ + } agent; } MainApp; /*-------------------------- system event ---------------------------*/ @@ -201,10 +200,14 @@ void LCUI_DestroyEvent( LCUI_SysEvent e ) LCUI_BOOL LCUI_PostTask( LCUI_AppTask task ) { - LCUI_AppTask buff; - buff = NEW( LCUI_AppTaskRec, 1 ); - *buff = *task; - return MainApp.driver.PostTask( buff ); + LCUI_AppTask newtask; + newtask = NEW( LCUI_AppTaskRec, 1 ); + *newtask = *task; + LCUIMutex_Lock( &MainApp.agent.mutex ); + LinkedList_Append( &MainApp.agent.tasks, newtask ); + LCUICond_Signal( &MainApp.agent.cond ); + LCUIMutex_Unlock( &MainApp.agent.mutex ); + return MainApp.driver.PostTask( newtask ); } void LCUI_DeleteTask( LCUI_AppTask task ) @@ -294,14 +297,31 @@ static void LCUIApp_Init(void) LCUICond_Init( &MainApp.loop_changed ); LCUIMutex_Init( &MainApp.loop_mutex ); LinkedList_Init( &MainApp.loops ); - LCUIMutex_Init( &MainApp.tasks_mutex ); - LinkedList_Init( &MainApp.tasks ); + LCUIMutex_Init( &MainApp.agent.mutex ); + LCUICond_Init( &MainApp.agent.cond ); + LinkedList_Init( &MainApp.agent.tasks ); LCUI_InitApp( &MainApp.driver ); + MainApp.agent.state = STATE_RUNNING; } LCUI_BOOL LCUI_WaitEvent( void ) { - return MainApp.driver.WaitEvent(); + if( MainApp.agent.tasks.length > 0 ) { + return TRUE; + } + if( MainApp.agent.state != STATE_RUNNING ) { + return MainApp.driver.WaitEvent(); + } + LCUIMutex_Lock( &MainApp.agent.mutex ); + while( MainApp.agent.state == STATE_RUNNING ) { + if( MainApp.agent.tasks.length > 0 ) { + LCUIMutex_Unlock( &MainApp.agent.mutex ); + return TRUE; + } + LCUICond_Wait( &MainApp.agent.cond, &MainApp.agent.mutex ); + } + LCUIMutex_Unlock( &MainApp.agent.mutex ); + return FALSE; } int LCUI_BindSysEvent( int event_id, LCUI_EventFunc func, @@ -315,9 +335,35 @@ int LCUI_UnbindSysEvent( int event_id, LCUI_EventFunc func ) return MainApp.driver.UnbindSysEvent( event_id, func ); } +static void LCUI_DispatchEvent( void ) +{ + LCUI_AppTask task; + LinkedListNode *node; + LCUIMutex_Lock( &MainApp.agent.mutex ); + node = LinkedList_GetNode( &MainApp.agent.tasks, 0 ); + if( node ) { + task = node->data; + LinkedList_Unlink( &MainApp.agent.tasks, node ); + LCUIMutex_Unlock( &MainApp.agent.mutex ); + LCUI_RunTask( task ); + LCUI_DeleteTask( task ); + free( task ); + free( node ); + return; + } else { + LCUIMutex_Unlock( &MainApp.agent.mutex ); + } + if( MainApp.agent.state == STATE_RUNNING ) { + return; + } + MainApp.driver.DispatchEvent(); +} + void LCUI_PumbEvents( void ) { - MainApp.driver.PumbEvents(); + while( LCUI_WaitEvent() ) { + LCUI_DispatchEvent(); + } } void *LCUI_GetAppData( void ) @@ -325,6 +371,18 @@ void *LCUI_GetAppData( void ) return MainApp.driver.GetData(); } +void LCUI_SetTaskAgent( LCUI_BOOL enabled ) +{ + LCUIMutex_Lock( &MainApp.agent.mutex ); + if( enabled ) { + MainApp.agent.state = STATE_RUNNING; + } else { + MainApp.agent.state = STATE_PAUSED; + } + LCUICond_Signal( &MainApp.agent.cond ); + LCUIMutex_Unlock( &MainApp.agent.mutex ); +} + /** 退出所有主循环 */ static void LCUIApp_QuitAllMainLoop(void) { @@ -338,6 +396,12 @@ static void LCUIApp_QuitAllMainLoop(void) } } +static void OnDeleteTask( void *arg ) +{ + LCUI_DeleteTask( arg ); + free( arg ); +} + /* 销毁程序占用的资源 */ static void LCUIApp_Destroy(void) { @@ -351,8 +415,10 @@ static void LCUIApp_Destroy(void) /* 开始清理 */ LCUIMutex_Destroy( &MainApp.loop_mutex ); LCUICond_Destroy( &MainApp.loop_changed ); - LCUIMutex_Destroy( &MainApp.tasks_mutex ); + LCUIMutex_Destroy( &MainApp.agent.mutex ); + LCUICond_Destroy( &MainApp.agent.cond ); LinkedList_Clear( &MainApp.loops, free ); + LinkedList_Clear( &MainApp.agent.tasks, OnDeleteTask ); } /** 打印LCUI的信息 */ @@ -429,8 +495,6 @@ int LCUI_Init(void) return -1; } System.is_inited = TRUE; - System.func_atexit = NULL; - System.exit_code = 0; System.state = STATE_ACTIVE; System.main_tid = LCUIThread_SelfID(); LCUI_ShowCopyrightText(); @@ -463,7 +527,7 @@ static int LCUI_Destroy( void ) LCUI_ExitTimer(); LCUI_ExitDisplay(); LCUIApp_Destroy(); - return System.exit_code; + return 0; } void LCUI_Quit(void) @@ -472,12 +536,6 @@ void LCUI_Quit(void) LCUIApp_QuitAllMainLoop(); } -void LCUI_Exit( int exit_code ) -{ - System.exit_code = exit_code; - LCUI_Quit(); -} - /* * 功能:LCUI程序的主循环 * 说明:每个LCUI程序都需要调用它,此函数会让程序执行LCUI分配的任务 diff --git a/src/platform/linux/linux_x11events.c b/src/platform/linux/linux_x11events.c index 92b46d9f..0822715a 100644 --- a/src/platform/linux/linux_x11events.c +++ b/src/platform/linux/linux_x11events.c @@ -10,45 +10,22 @@ static LCUI_X11AppDriverRec x11; -enum AppTaskAgentState { - STATE_NONE, - STATE_RUNNING, - STATE_PAUSE -}; - -static struct AppTaskAgent { - int state; - LinkedList tasks; - LCUI_Mutex mutex; - LCUI_Cond cond; -} agent; - void LCUI_SetLinuxX11MainWindow( Window win ) { - LCUIMutex_Lock( &agent.mutex ); - agent.state = STATE_PAUSE; x11.win_main = win; - LCUICond_Signal( &agent.cond ); - LCUIMutex_Unlock( &agent.mutex ); - XSelectInput(x11.display, win, ExposureMask | KeyPressMask); + XSelectInput( x11.display, win, ExposureMask | KeyPressMask ); + LCUI_SetTaskAgent( FALSE ); } static LCUI_BOOL X11_PostTask( LCUI_AppTask task ) { - LCUIMutex_Lock( &agent.mutex ); - LinkedList_Append( &agent.tasks, task ); - LCUICond_Signal( &agent.cond ); - LCUIMutex_Unlock( &agent.mutex ); - if( agent.state == STATE_PAUSE && x11.win_main != 0 ) { - XEvent ev; - memset( &ev, 0, sizeof (ev) ); - ev.xclient.type = ClientMessage; - ev.xclient.window = x11.win_main; - ev.xclient.format = 32; - ev.xclient.message_type = x11.wm_lcui; - XSendEvent(x11.display, x11.win_main, FALSE, NoEventMask, &ev); - return TRUE; - } + XEvent ev; + memset( &ev, 0, sizeof (ev) ); + ev.xclient.type = ClientMessage; + ev.xclient.window = x11.win_main; + ev.xclient.format = 32; + ev.xclient.message_type = x11.wm_lcui; + XSendEvent(x11.display, x11.win_main, FALSE, NoEventMask, &ev); return TRUE; } @@ -57,21 +34,6 @@ static LCUI_BOOL X11_WaitEvent( void ) int fd; fd_set fdset; struct timeval zero_time; - if( agent.tasks.length > 0 ) { - return TRUE; - } - if( agent.state == STATE_RUNNING ) { - LCUIMutex_Lock( &agent.mutex ); - while( agent.state == STATE_RUNNING ) { - if( agent.tasks.length > 0 ) { - LCUIMutex_Unlock( &agent.mutex ); - return TRUE; - } - LCUICond_Wait( &agent.cond, &agent.mutex ); - } - LCUIMutex_Unlock( &agent.mutex ); - return FALSE; - } XFlush( x11.display ); fd = ConnectionNumber( x11.display ); if( XEventsQueued(x11.display, QueuedAlready) ) { @@ -88,25 +50,6 @@ static LCUI_BOOL X11_WaitEvent( void ) static void X11_DispatchEvent( void ) { XEvent xevent; - LCUI_AppTask task; - LinkedListNode *node; - LCUIMutex_Lock( &agent.mutex ); - node = LinkedList_GetNode( &agent.tasks, 0 ); - if( node ) { - task = node->data; - LinkedList_Unlink( &agent.tasks, node ); - LCUIMutex_Unlock( &agent.mutex ); - LCUI_RunTask( task ); - LCUI_DeleteTask( task ); - free( task ); - free( node ); - return; - } else { - LCUIMutex_Unlock( &agent.mutex ); - } - if( agent.state == STATE_RUNNING ) { - return; - } XNextEvent( x11.display, &xevent ); DEBUG_MSG("%d\n", xevent.type); switch( xevent.type ) { @@ -116,13 +59,6 @@ static void X11_DispatchEvent( void ) EventTrigger_Trigger( x11.trigger, xevent.type, &xevent ); } -static void X11_PumpEvents( void ) -{ - while( X11_WaitEvent() ) { - X11_DispatchEvent(); - } -} - static int X11_BindSysEvent( int event_id, LCUI_EventFunc func, void *data, void(*destroy_data)(void*) ) { @@ -161,16 +97,12 @@ int LCUI_InitLinuxX11App( LCUI_AppDriver app ) x11.wm_lcui = XInternAtom( x11.display, "WM_LCUI", FALSE ); XSetWMProtocols( x11.display, x11.win_root, &x11.wm_lcui, 1 ); app->WaitEvent = X11_WaitEvent; - app->PumbEvents = X11_PumpEvents; + app->DispatchEvent = X11_DispatchEvent; app->PostTask = X11_PostTask; app->BindSysEvent = X11_BindSysEvent; app->UnbindSysEvent = X11_UnbindSysEvent; app->UnbindSysEvent2 = X11_UnbindSysEvent2; app->GetData = X11_GetData; - agent.state = STATE_RUNNING; - LinkedList_Init( &agent.tasks ); - LCUIMutex_Init( &agent.mutex ); - LCUICond_Init( &agent.cond ); x11.trigger = EventTrigger(); return 0; } From 87c7cd943c4ce623c1f05d132f35cfc568a85a4e Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Mon, 11 Jul 2016 00:44:45 +0800 Subject: [PATCH 077/124] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20windows=20?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E4=B8=8B=E7=9A=84=E4=BA=8B=E4=BB=B6=E5=A4=84?= =?UTF-8?q?=E7=90=86=E5=92=8C=E5=9B=BE=E5=BD=A2=E8=BE=93=E5=87=BA=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E7=A7=BB=E9=99=A4=E9=9A=90=E8=97=8F=E7=AA=97?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/main.h | 2 - .../LCUI/platform/windows/windows_events.h | 10 +--- src/ime.c | 4 +- src/main.c | 57 ++++++++----------- src/platform/windows/windows_display.c | 22 +++---- src/platform/windows/windows_events.c | 39 +++++-------- src/platform/windows/windows_keyboard.c | 8 +-- src/platform/windows/windows_mouse.c | 18 +++--- 8 files changed, 68 insertions(+), 92 deletions(-) diff --git a/include/LCUI/main.h b/include/LCUI/main.h index e77a2e48..419360c6 100644 --- a/include/LCUI/main.h +++ b/include/LCUI/main.h @@ -154,8 +154,6 @@ LCUI_API int LCUI_BindSysEvent( int event_id, LCUI_EventFunc func, LCUI_API int LCUI_UnbindSysEvent( int event_id, LCUI_EventFunc func ); -LCUI_API void LCUI_PumbEvents( void ); - LCUI_API void *LCUI_GetAppData( void ); LCUI_API void LCUI_SetTaskAgent( LCUI_BOOL enabled ); diff --git a/include/LCUI/platform/windows/windows_events.h b/include/LCUI/platform/windows/windows_events.h index 6182dcd8..7983281c 100644 --- a/include/LCUI/platform/windows/windows_events.h +++ b/include/LCUI/platform/windows/windows_events.h @@ -1,16 +1,10 @@ #ifndef LCUI_WINDOWS_EVENTS_H #define LCUI_WINDOWS_EVENTS_H -typedef struct WIN_SysEvent_ { - HWND hwnd; - WPARAM wparam; - LPARAM lparam; - UINT msg; - void *data; -} WIN_SysEventRec, *WIN_SysEvent; - LCUI_API void LCUI_PreInitWinApp( void *data ); +void LCUI_SetMainWindow( HWND hwnd ); + int LCUI_InitWinApp( LCUI_AppDriver app ); #endif diff --git a/src/ime.c b/src/ime.c index e14bb80f..d5699623 100644 --- a/src/ime.c +++ b/src/ime.c @@ -465,9 +465,9 @@ static void IME_ToText( char ch ) static void WinIME_OnChar( LCUI_Event e, void *arg ) { + MSG *msg = arg; wchar_t text[2]; - WIN_SysEvent win_ev = arg; - text[0] = win_ev->wparam; + text[0] = msg->wParam; text[1] = 0; LCUIIME_Commit( text, 2 ); } diff --git a/src/main.c b/src/main.c index 26974970..280dccbf 100644 --- a/src/main.c +++ b/src/main.c @@ -198,6 +198,30 @@ void LCUI_DestroyEvent( LCUI_SysEvent e ) /*--------------------------- system event ----------------------------*/ +static void LCUI_DispatchEvent( void ) +{ + LCUI_AppTask task; + LinkedListNode *node; + LCUIMutex_Lock( &MainApp.agent.mutex ); + node = LinkedList_GetNode( &MainApp.agent.tasks, 0 ); + if( node ) { + task = node->data; + LinkedList_Unlink( &MainApp.agent.tasks, node ); + LCUIMutex_Unlock( &MainApp.agent.mutex ); + LCUI_RunTask( task ); + LCUI_DeleteTask( task ); + free( task ); + free( node ); + return; + } else { + LCUIMutex_Unlock( &MainApp.agent.mutex ); + } + if( MainApp.agent.state == STATE_RUNNING ) { + return; + } + MainApp.driver.DispatchEvent(); +} + LCUI_BOOL LCUI_PostTask( LCUI_AppTask task ) { LCUI_AppTask newtask; @@ -264,7 +288,7 @@ int LCUI_MainLoop_Run( LCUI_MainLoop loop ) MainApp.loop = loop; while( loop->state != STATE_EXITED ) { LCUI_WaitEvent(); - LCUI_PumbEvents(); + LCUI_DispatchEvent(); /* 如果当前运行的主循环不是自己 */ while( MainApp.loop != loop ) { loop->state = STATE_PAUSED; @@ -335,37 +359,6 @@ int LCUI_UnbindSysEvent( int event_id, LCUI_EventFunc func ) return MainApp.driver.UnbindSysEvent( event_id, func ); } -static void LCUI_DispatchEvent( void ) -{ - LCUI_AppTask task; - LinkedListNode *node; - LCUIMutex_Lock( &MainApp.agent.mutex ); - node = LinkedList_GetNode( &MainApp.agent.tasks, 0 ); - if( node ) { - task = node->data; - LinkedList_Unlink( &MainApp.agent.tasks, node ); - LCUIMutex_Unlock( &MainApp.agent.mutex ); - LCUI_RunTask( task ); - LCUI_DeleteTask( task ); - free( task ); - free( node ); - return; - } else { - LCUIMutex_Unlock( &MainApp.agent.mutex ); - } - if( MainApp.agent.state == STATE_RUNNING ) { - return; - } - MainApp.driver.DispatchEvent(); -} - -void LCUI_PumbEvents( void ) -{ - while( LCUI_WaitEvent() ) { - LCUI_DispatchEvent(); - } -} - void *LCUI_GetAppData( void ) { return MainApp.driver.GetData(); diff --git a/src/platform/windows/windows_display.c b/src/platform/windows/windows_display.c index 0621407b..33e590e7 100644 --- a/src/platform/windows/windows_display.c +++ b/src/platform/windows/windows_display.c @@ -161,6 +161,8 @@ static void OnCreateSurface( void *arg1, void *arg2 ) surface->fb_hdc = CreateCompatibleDC( hdc_client ); surface->is_ready = TRUE; DEBUG_MSG("surface: %p, surface->hwnd: %p\n", surface, surface->hwnd); + LCUI_SetMainWindow( surface->hwnd ); + LCUI_SetTaskAgent( FALSE ); } /** 新建一个 Surface */ @@ -384,19 +386,19 @@ static void WinSurface_Update( LCUI_Surface surface ) static void OnWMPaint( LCUI_Event e, void *arg ) { + MSG *msg = arg; PAINTSTRUCT ps; LCUI_Rect area; LCUI_Surface surface; LCUI_DisplayEventRec dpy_ev; - WIN_SysEvent sys_event = arg; - BeginPaint( sys_event->hwnd, &ps ); + BeginPaint( msg->hwnd, &ps ); /* 获取区域坐标及尺寸 */ area.x = ps.rcPaint.left; area.y = ps.rcPaint.top; area.width = ps.rcPaint.right - area.x; area.height = ps.rcPaint.bottom - area.y; - EndPaint( sys_event->hwnd, &ps ); - surface = GetSurfaceByHWND( sys_event->hwnd ); + EndPaint( msg->hwnd, &ps ); + surface = GetSurfaceByHWND( msg->hwnd ); if( !surface ) { return; } @@ -408,26 +410,26 @@ static void OnWMPaint( LCUI_Event e, void *arg ) static void OnWMGetMinMaxInfo( LCUI_Event e, void *arg ) { + MSG *msg = arg; MINMAXINFO *mminfo; - WIN_SysEvent sys_event = arg; - mminfo = (PMINMAXINFO)sys_event->lparam; + mminfo = (PMINMAXINFO)msg->lParam; mminfo->ptMinTrackSize.x = MIN_WIDTH; mminfo->ptMinTrackSize.y = MIN_HEIGHT; } static void OnWMSize( LCUI_Event e, void *arg ) { + MSG *msg = arg; LCUI_Surface surface; LCUI_DisplayEventRec dpy_ev; - WIN_SysEvent sys_event = arg; - surface = GetSurfaceByHWND( sys_event->hwnd ); + surface = GetSurfaceByHWND( msg->hwnd ); if( !surface ) { return; } dpy_ev.surface = surface; dpy_ev.type = DET_RESIZE; - dpy_ev.resize.width = LOWORD( sys_event->lparam ); - dpy_ev.resize.height = HIWORD( sys_event->lparam ); + dpy_ev.resize.width = LOWORD( msg->lParam ); + dpy_ev.resize.height = HIWORD( msg->lParam ); EventTrigger_Trigger( win.trigger, DET_RESIZE, &dpy_ev ); } diff --git a/src/platform/windows/windows_events.c b/src/platform/windows/windows_events.c index db31f634..d11a167a 100644 --- a/src/platform/windows/windows_events.c +++ b/src/platform/windows/windows_events.c @@ -20,24 +20,19 @@ static struct WindowsDriver { static LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM arg1, LPARAM arg2 ) { - LCUI_AppTask task; - WIN_SysEventRec win_event; + MSG win_ev; switch( msg ) { case WM_LCUI_EVENT: - task = (LCUI_AppTask)arg2; - LCUI_RunTask( task ); - LCUI_DeleteTask( task ); return 0; case WM_CLOSE: LCUI_Quit(); default:break; } - win_event.msg = msg; - win_event.data = NULL; - win_event.hwnd = hwnd; - win_event.wparam = arg1; - win_event.lparam = arg2; - if( EventTrigger_Trigger( win.trigger, msg, &win_event ) == 0 ) { + win_ev.hwnd = hwnd; + win_ev.wParam = arg1; + win_ev.lParam = arg2; + win_ev.message = msg; + if( EventTrigger_Trigger( win.trigger, msg, &win_ev ) == 0 ) { return DefWindowProc( hwnd, msg, arg1, arg2 ); } return 0; @@ -57,10 +52,10 @@ static LCUI_BOOL WIN_WaitEvent( void ) return WaitMessage(); } -static void WIN_PumpEvents( void ) +static void WIN_DispatchEvent( void ) { MSG msg; - while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) { + if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } @@ -87,6 +82,11 @@ static void *WIN_GetData( void ) return win.main_instance; } +void LCUI_SetMainWindow( HWND hwnd ) +{ + win.main_hwnd = hwnd; +} + /** win32的动态库的入口函数 */ BOOL APIENTRY DllMain( HMODULE hModule, DWORD reason, LPVOID unused ) { @@ -131,22 +131,11 @@ int LCUI_InitWinApp( LCUI_AppDriver app ) app->GetData = WIN_GetData; app->PostTask = WIN_PostTask; app->WaitEvent = WIN_WaitEvent; - app->PumbEvents = WIN_PumpEvents; + app->DispatchEvent = WIN_DispatchEvent; app->BindSysEvent = WIN_BindSysEvent; app->UnbindSysEvent = WIN_UnbindSysEvent; app->UnbindSysEvent2 = WIN_UnbindSysEvent2; win.trigger = EventTrigger(); - /** - * 创建一个隐藏的主窗体,用于接收 LCUI 的任务 - * 之前用 PostThreadMessage() 无法发送自定义消息到主线程的消息循环,因此 - * 改成创建隐藏窗体并用 PostMessage() 发送任务。 - */ - win.main_hwnd = CreateWindow( - TEXT("LCUI"), TEXT("LCUI Task Receiver"), 0, - CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL, - win.main_instance, NULL - ); - RegisterTouchWindow( win.main_hwnd, 0 ); return 0; } diff --git a/src/platform/windows/windows_keyboard.c b/src/platform/windows/windows_keyboard.c index 2783425c..0771c133 100644 --- a/src/platform/windows/windows_keyboard.c +++ b/src/platform/windows/windows_keyboard.c @@ -8,17 +8,17 @@ static void OnKeyboardMessage( LCUI_Event ev, void *arg ) { + MSG* msg = arg; static POINT mouse_pos; LCUI_SysEventRec sys_ev; - WIN_SysEvent win_ev = arg; - switch( win_ev->msg ) { + switch( msg->message ) { case WM_KEYDOWN: sys_ev.type = LCUI_KEYDOWN; - sys_ev.key.code = win_ev->wparam; + sys_ev.key.code = msg->wParam; break; case WM_KEYUP: sys_ev.type = LCUI_KEYUP; - sys_ev.key.code = win_ev->wparam; + sys_ev.key.code = msg->wParam; break; default: return; } diff --git a/src/platform/windows/windows_mouse.c b/src/platform/windows/windows_mouse.c index e8f4386a..75e5b4cf 100644 --- a/src/platform/windows/windows_mouse.c +++ b/src/platform/windows/windows_mouse.c @@ -8,15 +8,15 @@ static void OnMouseMessage( LCUI_Event ev, void *arg ) { + MSG *msg = arg; LCUI_SysEventRec sys_ev; - WIN_SysEvent win_ev = arg; static POINT mouse_pos = {0, 0}; sys_ev.type = LCUI_NONE; - switch( win_ev->msg ) { + switch( msg->message ) { case WM_MOUSEMOVE: { POINT new_pos; GetCursorPos( &new_pos ); - ScreenToClient( win_ev->hwnd, &new_pos ); + ScreenToClient( msg->hwnd, &new_pos ); sys_ev.motion.x = new_pos.x; sys_ev.motion.y = new_pos.y; sys_ev.motion.xrel = new_pos.x - mouse_pos.x; @@ -31,7 +31,7 @@ static void OnMouseMessage( LCUI_Event ev, void *arg ) sys_ev.button.button = 1; sys_ev.button.x = mouse_pos.x; sys_ev.button.y = mouse_pos.y; - SetCapture( win_ev->hwnd ); + SetCapture( msg->hwnd ); break; case WM_LBUTTONUP: sys_ev.type = LCUI_MOUSEUP; @@ -45,7 +45,7 @@ static void OnMouseMessage( LCUI_Event ev, void *arg ) sys_ev.button.button = 2; sys_ev.button.x = mouse_pos.x; sys_ev.button.y = mouse_pos.y; - SetCapture( win_ev->hwnd ); + SetCapture( msg->hwnd ); break; case WM_RBUTTONUP: sys_ev.type = LCUI_MOUSEUP; @@ -58,12 +58,12 @@ static void OnMouseMessage( LCUI_Event ev, void *arg ) sys_ev.type = LCUI_MOUSEWHEEL; sys_ev.wheel.x = mouse_pos.x; sys_ev.wheel.y = mouse_pos.y; - sys_ev.wheel.delta = GET_WHEEL_DELTA_WPARAM( win_ev->wparam ); + sys_ev.wheel.delta = GET_WHEEL_DELTA_WPARAM( msg->wParam ); break; case WM_TOUCH: { - UINT i, n = LOWORD( win_ev->wparam ); + UINT i, n = LOWORD( msg->wParam ); PTOUCHINPUT inputs = NEW( TOUCHINPUT, n ); - HTOUCHINPUT handle = (HTOUCHINPUT)win_ev->lparam; + HTOUCHINPUT handle = (HTOUCHINPUT)msg->lParam; if( inputs == NULL ) { break; } @@ -83,7 +83,7 @@ static void OnMouseMessage( LCUI_Event ev, void *arg ) POINT pos; pos.x = inputs[i].x / 100; pos.y = inputs[i].y / 100; - ScreenToClient( win_ev->hwnd, &pos ); + ScreenToClient( msg->hwnd, &pos ); sys_ev.touch.points[i].x = pos.x; sys_ev.touch.points[i].y = pos.y; sys_ev.touch.points[i].id = inputs[i].dwID; From 420739a20df30ef0f89aea08f591985f2e7654b6 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Mon, 11 Jul 2016 18:36:04 +0800 Subject: [PATCH 078/124] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20x11=20=E9=BC=A0?= =?UTF-8?q?=E6=A0=87=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/Makefile.am | 5 +- include/LCUI/platform/linux/linux_mouse.h | 41 ++++++++ include/LCUI/platform/linux/linux_x11mouse.h | 47 +++++++++ src/platform/Makefile.am | 7 +- src/platform/linux/linux_mouse.c | 46 ++++++++- src/platform/linux/linux_x11events.c | 6 +- src/platform/linux/linux_x11mouse.c | 101 +++++++++++++++++++ 7 files changed, 246 insertions(+), 7 deletions(-) create mode 100644 include/LCUI/platform/linux/linux_x11mouse.h create mode 100644 src/platform/linux/linux_x11mouse.c diff --git a/include/LCUI/Makefile.am b/include/LCUI/Makefile.am index 76da7dfd..163fa0bc 100755 --- a/include/LCUI/Makefile.am +++ b/include/LCUI/Makefile.am @@ -8,8 +8,9 @@ EXTRA_DIST=platform.h platform/linux/linux_display.h \ platform/linux/linux_events.h platform/linux/linux_mouse.h \ platform/linux/linux_keyboard.h platform/linux/linux_fbdisplay.h \ platform/linux/linux_x11display.h platform/linux/linux_x11events.h \ -platform/windows/windows_display.h platform/windows/windows_events.h \ -platform/windows/windows_mouse.h platform/windows/windows_keyboard.h +platform/linux/linux_x11mouse.h platform/windows/windows_display.h \ +platform/windows/windows_events.h platform/windows/windows_mouse.h \ +platform/windows/windows_keyboard.h # Headers to install pkginclude_HEADERS = $(INSTINCLUDES) diff --git a/include/LCUI/platform/linux/linux_mouse.h b/include/LCUI/platform/linux/linux_mouse.h index ac3134b6..b72b8d8f 100644 --- a/include/LCUI/platform/linux/linux_mouse.h +++ b/include/LCUI/platform/linux/linux_mouse.h @@ -1,6 +1,47 @@ +/* *************************************************************************** + * linux_x11mouse.h -- mouse support for linux. + * + * Copyright (C) 2016 by Liu Chao + * + * 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * linux_x11mouse.h -- linux 平台的鼠标支持 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ + #ifndef LCUI_LINUX_MOUSE_H #define LCUI_LINUX_MOUSE_H +#include + void LCUI_InitLinuxMouse( void ); void LCUI_ExitLinuxMouse( void ); diff --git a/include/LCUI/platform/linux/linux_x11mouse.h b/include/LCUI/platform/linux/linux_x11mouse.h new file mode 100644 index 00000000..aabd4ae3 --- /dev/null +++ b/include/LCUI/platform/linux/linux_x11mouse.h @@ -0,0 +1,47 @@ +/* *************************************************************************** + * linux_x11mouse.h -- mouse support for linux xwindow. + * + * Copyright (C) 2016 by Liu Chao + * + * 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * linux_x11mouse.h -- linux 平台的鼠标支持,基于 xwindow。 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ + +#ifndef LCUI_LINUX_X11_MOUSE_H +#define LCUI_LINUX_X11_MOUSE_H + +void LCUI_InitLinuxX11Mouse( void ); + +void LCUI_ExitLinuxX11Mouse( void ); + +#endif diff --git a/src/platform/Makefile.am b/src/platform/Makefile.am index f5f05bff..8e53117e 100755 --- a/src/platform/Makefile.am +++ b/src/platform/Makefile.am @@ -2,7 +2,8 @@ AUTOMAKE_OPTIONS=foreign subdir-objects AM_CFLAGS = -I$(abs_top_srcdir)/include noinst_LTLIBRARIES = libplatform.la libplatform_la_SOURCES = linux/linux_keyboard.c linux/linux_display.c \ -linux/linux_x11events.c linux/linux_events.c linux/linux_mouse.c \ -linux/linux_fbdisplay.c linux/linux_x11display.c windows/windows_events.c \ -windows/windows_keyboard.c windows/windows_display.c windows/windows_mouse.c +linux/linux_events.c linux/linux_mouse.c linux/linux_x11events.c \ +linux/linux_x11mouse.c linux/linux_x11display.c linux/linux_fbdisplay.c \ +windows/windows_events.c linux/linux_fbdisplay.c windows/windows_keyboard.c \ +windows/windows_display.c windows/windows_mouse.c diff --git a/src/platform/linux/linux_mouse.c b/src/platform/linux/linux_mouse.c index 2f800bf5..b923f8ed 100644 --- a/src/platform/linux/linux_mouse.c +++ b/src/platform/linux/linux_mouse.c @@ -1,10 +1,54 @@ +/* *************************************************************************** + * linux_x11mouse.c -- mouse support for linux. + * + * Copyright (C) 2016 by Liu Chao + * + * 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * linux_x11mouse.c -- linux 平台的鼠标支持 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ #include #ifdef LCUI_BUILD_IN_LINUX +#include +#include +#include LCUI_EVENTS_H void LCUI_InitLinuxMouse( void ) { - + LCUI_BOOL is_x11_mode = TRUE; + if( is_x11_mode ) { + LCUI_InitLinuxX11Mouse(); + } } void LCUI_ExitLinuxMouse( void ) diff --git a/src/platform/linux/linux_x11events.c b/src/platform/linux/linux_x11events.c index 0822715a..d5d0fd75 100644 --- a/src/platform/linux/linux_x11events.c +++ b/src/platform/linux/linux_x11events.c @@ -13,7 +13,11 @@ static LCUI_X11AppDriverRec x11; void LCUI_SetLinuxX11MainWindow( Window win ) { x11.win_main = win; - XSelectInput( x11.display, win, ExposureMask | KeyPressMask ); + XSelectInput( x11.display, win, ExposureMask | KeyPressMask | + ButtonPress | StructureNotifyMask | ButtonReleaseMask | + KeyReleaseMask | EnterWindowMask | LeaveWindowMask | + PointerMotionMask | Button1MotionMask | + VisibilityChangeMask ); LCUI_SetTaskAgent( FALSE ); } diff --git a/src/platform/linux/linux_x11mouse.c b/src/platform/linux/linux_x11mouse.c new file mode 100644 index 00000000..a1516aa5 --- /dev/null +++ b/src/platform/linux/linux_x11mouse.c @@ -0,0 +1,101 @@ +/* *************************************************************************** + * linux_x11mouse.c -- mouse support for linux xwindow. + * + * Copyright (C) 2016 by Liu Chao + * + * 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * linux_x11mouse.c -- linux 平台的鼠标支持,基于 xwindow。 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ + +#include +#include +#include +#ifdef LCUI_BUILD_IN_LINUX +#include +#include +#include LCUI_EVENTS_H + #include LCUI_MOUSE_H + +static void OnMotionNotify( LCUI_Event e, void *arg ) +{ + XEvent *ev = arg; + LCUI_SysEventRec sys_ev; + static LCUI_Pos mouse_pos = {0, 0}; + sys_ev.type = LCUI_MOUSEMOVE; + sys_ev.motion.x = ev->xmotion.x; + sys_ev.motion.y = ev->xmotion.y; + sys_ev.motion.xrel = ev->xmotion.x - mouse_pos.x; + sys_ev.motion.yrel = ev->xmotion.y - mouse_pos.y; + mouse_pos.x = ev->xmotion.x; + mouse_pos.y = ev->xmotion.y; + LCUI_TriggerEvent( &sys_ev, NULL ); + LCUI_DestroyEvent( &sys_ev ); +} + +static void OnButtonPress( LCUI_Event e, void *arg ) +{ + XEvent *ev = arg; + LCUI_SysEventRec sys_ev; + sys_ev.type = LCUI_MOUSEDOWN; + sys_ev.button.x = ev->xbutton.x; + sys_ev.button.y = ev->xbutton.y; + sys_ev.button.button = ev->xbutton.button; + LCUI_TriggerEvent( &sys_ev, NULL ); + LCUI_DestroyEvent( &sys_ev ); +} + +static void OnButtonRelease( LCUI_Event e, void *arg ) +{ + XEvent *ev = arg; + LCUI_SysEventRec sys_ev; + sys_ev.type = LCUI_MOUSEUP; + sys_ev.button.x = ev->xbutton.x; + sys_ev.button.y = ev->xbutton.y; + sys_ev.button.button = ev->xbutton.button; + LCUI_TriggerEvent( &sys_ev, NULL ); + LCUI_DestroyEvent( &sys_ev ); +} + +void LCUI_InitLinuxX11Mouse( void ) +{ + LCUI_BindSysEvent( MotionNotify, OnMotionNotify, NULL, NULL ); + LCUI_BindSysEvent( ButtonPress, OnButtonPress, NULL, NULL ); + LCUI_BindSysEvent( ButtonRelease, OnButtonRelease, NULL, NULL ); +} + +void LCUI_ExitLinuxX11Mouse( void ) +{ + LCUI_UnbindSysEvent( MotionNotify, OnMotionNotify ); +} + +#endif From 086bd8ec0ebf807d41769c9b70fb2bcfd0a11bd2 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Mon, 11 Jul 2016 18:36:46 +0800 Subject: [PATCH 079/124] =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=AD=97=E4=BD=93=E7=9A=84=E9=80=89=E6=8B=A9=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/font/fontlibrary.c | 16 ++++++++++------ src/font/textlayer.c | 2 ++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/font/fontlibrary.c b/src/font/fontlibrary.c index 42bd569d..05d48c40 100644 --- a/src/font/fontlibrary.c +++ b/src/font/fontlibrary.c @@ -75,8 +75,8 @@ static struct LCUI_FontLibraryContext { LCUI_RBTree family_tree; /**< 字族信息树,按字族名称记录着各个字体的信息 */ LCUI_RBTree bitmap_cache; /**< 字体位图缓存区 */ LCUI_Font ***font_cache; /**< 字体信息缓存区 */ - LCUI_Font *default_font; /**< 指针,引用的是默认字体信息 */ - LCUI_Font *incore_font; /**< 指针,引用的是内置字体的信息 */ + LCUI_Font *default_font; /**< 默认字体的信息 */ + LCUI_Font *incore_font; /**< 内置字体的信息 */ LCUI_FontEngine engines[2]; /**< 当前可用字体引擎列表 */ LCUI_FontEngine *engine; /**< 当前选择的字体引擎 */ } fontlib = {0, FALSE}; @@ -354,10 +354,11 @@ int LCUIFont_GetBitmap( wchar_t ch, int font_id, int size, return -2; } if( font_id <= 0 ) { - if( !fontlib.default_font ) { - return -3; + if( fontlib.default_font ) { + font_id = fontlib.default_font->id; + } else { + font_id = fontlib.incore_font->id; } - font_id = fontlib.default_font->id; } /* 这里的 while 只是为了减少缩进 */ while( TRUE ) { @@ -402,6 +403,7 @@ int LCUIFont_LoadFile( const char *filepath ) } ret = fontlib.engine->open( filepath, &font ); if( ret != 0 ) { + printf( "[font] failed to load file: %s\n", filepath ); return -2; } font->engine = fontlib.engine; @@ -596,6 +598,7 @@ int FontBitmap_Load( LCUI_FontBitmap *buff, wchar_t ch, } else { info = fontlib.incore_font; } + break; } if( !info ) { return -1; @@ -621,7 +624,7 @@ void LCUI_InitFont( void ) "C:/Windows/Fonts/simsun.ttc", "C:/Windows/Fonts/consola.ttf" #else - "../fonts/msyh.ttf" + "/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-R.ttf" #endif }; @@ -643,6 +646,7 @@ void LCUI_InitFont( void ) LCUIFont_InitInCoreFont( &fontlib.engines[0] ); font_id = LCUIFont_GetId( "inconsolata", NULL ); fontlib.incore_font = LCUIFont_GetById( font_id ); + fontlib.default_font = fontlib.incore_font; fontlib.engine = &fontlib.engines[0]; /* 然后看情况启用其它字体引擎 */ #ifdef LCUI_FONT_ENGINE_FREETYPE diff --git a/src/font/textlayer.c b/src/font/textlayer.c index 34270ada..1249e0d3 100644 --- a/src/font/textlayer.c +++ b/src/font/textlayer.c @@ -49,6 +49,8 @@ enum TextAddType { TAT_APPEND /**< 追加至文本末尾 */ }; + +#define max(a, b) ((a) > (b) ? (a):(b)) #define TextRowList_AddNewRow(ROWLIST) TextRowList_InsertNewRow(ROWLIST, (ROWLIST)->length) #define TextLayer_GetRow(layer, n) (n >= layer->rowlist.length) ? NULL:layer->rowlist.rows[n] From 50c4f80dad40251b62ae5d7e9ae52e61944f8be0 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Mon, 11 Jul 2016 18:37:02 +0800 Subject: [PATCH 080/124] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20helloworld=20?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/helloworld.c | 56 ++++++++++++++++++--------------------------- test/helloworld.css | 4 ++++ test/helloworld.xml | 6 +++-- 3 files changed, 30 insertions(+), 36 deletions(-) diff --git a/test/helloworld.c b/test/helloworld.c index 98da6846..0a669be0 100755 --- a/test/helloworld.c +++ b/test/helloworld.c @@ -2,43 +2,31 @@ #include #include #include - -int main( int argc, char **argv ) -{ - LCUI_Widget root, pack; - LCUI_Init(); - root = LCUIWidget_GetRoot(); - pack = LCUIBuilder_LoadFile( "helloworld.xml" ); - if( !pack ) { - return -1; - } - Widget_Append( root, pack ); - Widget_Unwrap( pack ); - return LCUI_Main(); -} - -/* version 2 -#include -#include -#include #include +#include + +static void OnBtnClick( LCUI_Widget self, LCUI_WidgetEvent e, void *arg ) +{ + wchar_t str[256]; + LCUI_Widget edit = LCUIWidget_GetById( "edit" ); + LCUI_Widget txt = LCUIWidget_GetById( "text-hello" ); + TextEdit_GetTextW( edit, 0, 255, str ); + TextView_SetTextW( txt, str ); +} int main( int argc, char **argv ) { - LCUI_Widget root, txt; + LCUI_Widget root, pack, btn; - LCUI_Init(); - root = LCUIWidget_GetRoot(); - txt = LCUIWidget_New( "textview" ); - TextView_SetTextAlign( txt, SV_CENTER ); - TextView_SetText( txt, "[size=18px]Hello, World![/size]" ); - SetStyle( txt->custom_style, key_margin_top, 25, px ); - SetStyle( txt->custom_style, key_margin_left, 25, px ); - SetStyle( txt->custom_style, key_padding_top, 25, px ); - SetStyle( txt->custom_style, key_border_width, 1, px ); - SetStyle( txt->custom_style, key_border_color, RGB(0,0,0), color ); - Widget_Resize( txt, 200, 100 ); - Widget_Append( root, txt ); - return LCUI_Main(); + LCUI_Init(); + root = LCUIWidget_GetRoot(); + pack = LCUIBuilder_LoadFile( "helloworld.xml" ); + if( !pack ) { + return -1; + } + Widget_Append( root, pack ); + Widget_Unwrap( pack ); + btn = LCUIWidget_GetById( "btn-ok" ); + Widget_BindEvent( btn, "click", OnBtnClick, NULL, NULL ); + return LCUI_Main(); } -*/ diff --git a/test/helloworld.css b/test/helloworld.css index 0aed259c..cb279fef 100644 --- a/test/helloworld.css +++ b/test/helloworld.css @@ -6,4 +6,8 @@ textview.text-hello { padding: 25px; margin: 25px 0 0 25px; border: 1px solid #000; + background-color: #fafafa; } +#btn-ok, #edit { + margin: 25px 0 0 25px; +} \ No newline at end of file diff --git a/test/helloworld.xml b/test/helloworld.xml index 4fb04417..6e096bc0 100644 --- a/test/helloworld.xml +++ b/test/helloworld.xml @@ -3,6 +3,8 @@ - Hello, World! + Hello, World! + Hello, World! + 确定 - + \ No newline at end of file From 93ef29b83a764055e616a363746755eb63b5d201 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Mon, 11 Jul 2016 19:00:48 +0800 Subject: [PATCH 081/124] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E9=A9=B1=E5=8A=A8=E6=94=AF=E6=8C=81=E6=9C=89=E6=95=88=E6=80=A7?= =?UTF-8?q?=E5=88=A4=E6=96=AD=EF=BC=8C=E9=81=BF=E5=85=8D=E8=AE=BF=E9=97=AE?= =?UTF-8?q?=E6=97=A0=E6=95=88=E7=9A=84=E4=BA=8B=E4=BB=B6=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.c | 31 +++++++++++++++++++++------ src/platform/linux/linux_mouse.c | 1 + src/platform/linux/linux_x11display.c | 3 +++ src/platform/linux/linux_x11events.c | 2 +- src/platform/linux/linux_x11mouse.c | 2 +- 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/main.c b/src/main.c index 280dccbf..1282f950 100644 --- a/src/main.c +++ b/src/main.c @@ -95,6 +95,7 @@ static struct LCUI_App { LCUI_MainLoop loop; /**< 当前运行的主循环 */ LinkedList loops; /**< 主循环列表 */ LCUI_AppDriverRec driver; /**< 程序事件驱动支持 */ + LCUI_BOOL driver_ready; /**< 事件驱动支持是否已经准备就绪 */ struct LCUI_AppTaskAgent { int state; /**< 状态 */ LinkedList tasks; /**< 任务队列 */ @@ -219,7 +220,9 @@ static void LCUI_DispatchEvent( void ) if( MainApp.agent.state == STATE_RUNNING ) { return; } - MainApp.driver.DispatchEvent(); + if( MainApp.driver_ready ) { + MainApp.driver.DispatchEvent(); + } } LCUI_BOOL LCUI_PostTask( LCUI_AppTask task ) @@ -231,7 +234,10 @@ LCUI_BOOL LCUI_PostTask( LCUI_AppTask task ) LinkedList_Append( &MainApp.agent.tasks, newtask ); LCUICond_Signal( &MainApp.agent.cond ); LCUIMutex_Unlock( &MainApp.agent.mutex ); - return MainApp.driver.PostTask( newtask ); + if( MainApp.driver_ready ) { + return MainApp.driver.PostTask( newtask ); + } + return TRUE; } void LCUI_DeleteTask( LCUI_AppTask task ) @@ -318,13 +324,16 @@ void LCUI_MainLoop_Quit( LCUI_MainLoop loop ) /** 初始化程序数据结构体 */ static void LCUIApp_Init(void) { + MainApp.driver_ready = FALSE; LCUICond_Init( &MainApp.loop_changed ); LCUIMutex_Init( &MainApp.loop_mutex ); LinkedList_Init( &MainApp.loops ); LCUIMutex_Init( &MainApp.agent.mutex ); LCUICond_Init( &MainApp.agent.cond ); LinkedList_Init( &MainApp.agent.tasks ); - LCUI_InitApp( &MainApp.driver ); + if( LCUI_InitApp( &MainApp.driver ) == 0 ) { + MainApp.driver_ready = TRUE; + } MainApp.agent.state = STATE_RUNNING; } @@ -351,17 +360,27 @@ LCUI_BOOL LCUI_WaitEvent( void ) int LCUI_BindSysEvent( int event_id, LCUI_EventFunc func, void *data, void( *destroy_data )(void*) ) { - return MainApp.driver.BindSysEvent( event_id, func, data, destroy_data ); + if( MainApp.driver_ready ) { + return MainApp.driver.BindSysEvent( event_id, func, + data, destroy_data ); + } + return -1; } int LCUI_UnbindSysEvent( int event_id, LCUI_EventFunc func ) { - return MainApp.driver.UnbindSysEvent( event_id, func ); + if( MainApp.driver_ready ) { + return MainApp.driver.UnbindSysEvent( event_id, func ); + } + return -1; } void *LCUI_GetAppData( void ) { - return MainApp.driver.GetData(); + if( MainApp.driver_ready ) { + return MainApp.driver.GetData(); + } + return NULL; } void LCUI_SetTaskAgent( LCUI_BOOL enabled ) diff --git a/src/platform/linux/linux_mouse.c b/src/platform/linux/linux_mouse.c index b923f8ed..1ab8a80b 100644 --- a/src/platform/linux/linux_mouse.c +++ b/src/platform/linux/linux_mouse.c @@ -42,6 +42,7 @@ #include #include #include LCUI_EVENTS_H +#include LCUI_MOUSE_H void LCUI_InitLinuxMouse( void ) { diff --git a/src/platform/linux/linux_x11display.c b/src/platform/linux/linux_x11display.c index 1ab5e396..cfb8c2ce 100644 --- a/src/platform/linux/linux_x11display.c +++ b/src/platform/linux/linux_x11display.c @@ -431,6 +431,9 @@ int LCUI_InitLinuxX11Display( LCUI_DisplayDriver driver ) { strcpy( driver->name, "x11" ); x11.app = LCUI_GetAppData(); + if( !x11.app ) { + return -1; + } driver->getWidth = X11Display_GetWidth; driver->getHeight = X11Display_GetHeight; driver->new = X11Surface_New; diff --git a/src/platform/linux/linux_x11events.c b/src/platform/linux/linux_x11events.c index d5d0fd75..961a084f 100644 --- a/src/platform/linux/linux_x11events.c +++ b/src/platform/linux/linux_x11events.c @@ -91,7 +91,7 @@ void LCUI_PreInitLinuxX11App( void *data ) int LCUI_InitLinuxX11App( LCUI_AppDriver app ) { - x11.display = XOpenDisplay(NULL); + x11.display = XOpenDisplay( NULL ); if( !x11.display ) { return -1; } diff --git a/src/platform/linux/linux_x11mouse.c b/src/platform/linux/linux_x11mouse.c index a1516aa5..839661d4 100644 --- a/src/platform/linux/linux_x11mouse.c +++ b/src/platform/linux/linux_x11mouse.c @@ -44,7 +44,7 @@ #include #include #include LCUI_EVENTS_H - #include LCUI_MOUSE_H +#include LCUI_MOUSE_H static void OnMotionNotify( LCUI_Event e, void *arg ) { From db001b6aaea3d40b3eeea6a6fed1dc4f669ba90e Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Thu, 14 Jul 2016 21:47:24 +0800 Subject: [PATCH 082/124] =?UTF-8?q?=E7=BA=A0=E6=AD=A3=E5=AD=97=E4=BD=93?= =?UTF-8?q?=E4=BD=8D=E5=9B=BE=E8=8E=B7=E5=8F=96=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当字体位图获取失败时,应该使用 FontBitmap_Load() 返回的字体位图(通常是方框)。 --- src/font/fontlibrary.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/font/fontlibrary.c b/src/font/fontlibrary.c index 05d48c40..bb721d9e 100644 --- a/src/font/fontlibrary.c +++ b/src/font/fontlibrary.c @@ -377,13 +377,8 @@ int LCUIFont_GetBitmap( wchar_t ch, int font_id, int size, } FontBitmap_Init( &bmp_cache ); ret = FontBitmap_Load( &bmp_cache, ch, font_id, size ); - if( ret == 0 ) { - *bmp = LCUIFont_AddBitmap( ch, font_id, size, &bmp_cache ); - if( *bmp ) { - return 0; - } - } - return -1; + *bmp = LCUIFont_AddBitmap( ch, font_id, size, &bmp_cache ); + return ret; } /** 载入字体值数据库中 */ From 9bb3e04373d4729c6343678cef0ff39470828d70 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Thu, 14 Jul 2016 21:50:29 +0800 Subject: [PATCH 083/124] =?UTF-8?q?=E7=BA=A0=E6=AD=A3=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E7=BB=99=20XPutImage()=20=E5=87=BD=E6=95=B0=E7=9A=84=E5=9D=90?= =?UTF-8?q?=E6=A0=87=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/platform/linux/linux_x11display.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/platform/linux/linux_x11display.c b/src/platform/linux/linux_x11display.c index cfb8c2ce..bc8bc126 100644 --- a/src/platform/linux/linux_x11display.c +++ b/src/platform/linux/linux_x11display.c @@ -220,9 +220,10 @@ static void X11Surface_OnTask( LCUI_Surface surface, LCUI_SurfaceTask task ) LinkedListNode *node; LinkedList_ForEach( node, &surface->rects ) { LCUI_Rect *rect = node->data; - XPutImage( x11.app->display, surface->window, surface->gc, - surface->ximage, 0, 0, rect->x, rect->y, - rect->width, rect->height); + XPutImage( x11.app->display, surface->window, + surface->gc, surface->ximage, + rect->x, rect->y, rect->x, rect->y, + rect->width, rect->height ); } LinkedList_Clear( &surface->rects, free ); break; From 46d281381bd77658511a99990c182c012c220373 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Thu, 14 Jul 2016 21:53:08 +0800 Subject: [PATCH 084/124] =?UTF-8?q?is=5Frunning=20=E6=A0=87=E8=AE=B0?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E5=9C=A8=E5=88=9B=E5=BB=BA=E5=AE=8C=E5=AE=9A?= =?UTF-8?q?=E6=97=B6=E5=99=A8=E7=BA=BF=E7=A8=8B=E5=90=8E=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E4=B8=BA=20TRUE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/timer.c b/src/timer.c index d1b15441..5cbc1fe1 100644 --- a/src/timer.c +++ b/src/timer.c @@ -122,7 +122,6 @@ static void TimerThread( void *arg ) int64_t lost_ms; LinkedListNode *node; LCUI_AppTaskRec task = {0}; - self.is_running = TRUE; LCUIMutex_Lock( &self.mutex ); while( self.is_running ) { Timer timer = NULL; @@ -291,6 +290,7 @@ void LCUI_InitTimer( void ) LCUICond_Init( &self.sleep_cond ); LinkedList_Init( &self.timer_list ); LCUIThread_Create( &self.tid, TimerThread, NULL ); + self.is_running = TRUE; } void LCUI_ExitTimer( void ) From 569d938024e866d7f17aed7e71124751b9339d5f Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Thu, 14 Jul 2016 21:56:06 +0800 Subject: [PATCH 085/124] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20linux=20=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E5=A4=84=E7=90=86=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit x11 貌似无法接收其它线程中发过来的事件,现在暂时将 X11_WaitEvent() 改为最长阻塞等待 10 毫秒,避免耽误 LCUI 任务处理。 Signed-off-by: Liu Chao --- include/LCUI/platform/linux/linux_events.h | 39 ++++++++++++++ include/LCUI/platform/linux/linux_fbdisplay.h | 38 ++++++++++++++ include/LCUI/platform/linux/linux_mouse.h | 4 +- .../LCUI/platform/linux/linux_x11display.h | 38 ++++++++++++++ include/LCUI/platform/linux/linux_x11events.h | 39 ++++++++++++++ src/platform/linux/linux_x11events.c | 52 +++++++++++++++++-- 6 files changed, 203 insertions(+), 7 deletions(-) diff --git a/include/LCUI/platform/linux/linux_events.h b/include/LCUI/platform/linux/linux_events.h index 8a29efce..585a917e 100644 --- a/include/LCUI/platform/linux/linux_events.h +++ b/include/LCUI/platform/linux/linux_events.h @@ -1,3 +1,42 @@ +/* *************************************************************************** + * linux_events.c -- event loop support for linux. + * + * Copyright (C) 2016 by Liu Chao + * + * 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * linux_events.c -- linux 平台的事件驱动支持。 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ + #ifndef LCUI_LINUX_EVENTS_H #define LCUI_LINUX_EVENTS_H diff --git a/include/LCUI/platform/linux/linux_fbdisplay.h b/include/LCUI/platform/linux/linux_fbdisplay.h index 8b137891..5323d41e 100644 --- a/include/LCUI/platform/linux/linux_fbdisplay.h +++ b/include/LCUI/platform/linux/linux_fbdisplay.h @@ -1 +1,39 @@ +/* *************************************************************************** + * linux_fbdisplay.h -- surface support for linux framebuffer. + * + * Copyright (C) 2016 by Liu Chao + * + * 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * linux_fbdisplay.h -- linux 平台的图形显示功能支持,基于帧缓存(FrameBuffer)。 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ diff --git a/include/LCUI/platform/linux/linux_mouse.h b/include/LCUI/platform/linux/linux_mouse.h index b72b8d8f..31ae4901 100644 --- a/include/LCUI/platform/linux/linux_mouse.h +++ b/include/LCUI/platform/linux/linux_mouse.h @@ -1,5 +1,5 @@ /* *************************************************************************** - * linux_x11mouse.h -- mouse support for linux. + * linux_mouse.h -- mouse support for linux. * * Copyright (C) 2016 by Liu Chao * @@ -20,7 +20,7 @@ * ****************************************************************************/ /* **************************************************************************** - * linux_x11mouse.h -- linux 平台的鼠标支持 + * linux_mouse.h -- linux 平台的鼠标支持 * * 版权所有 (C) 2016 归属于 刘超 * diff --git a/include/LCUI/platform/linux/linux_x11display.h b/include/LCUI/platform/linux/linux_x11display.h index d0d32d07..646e6198 100644 --- a/include/LCUI/platform/linux/linux_x11display.h +++ b/include/LCUI/platform/linux/linux_x11display.h @@ -1,3 +1,41 @@ +/* *************************************************************************** + * linux_x11display.h -- surface support for linux xwindow. + * + * Copyright (C) 2016 by Liu Chao + * + * 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * linux_x11display.h -- linux 平台的图形显示功能支持,基于 xwindow。 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ #ifndef LCUI_LINUX_X11_DISPLAY_H #define LCUI_LINUX_X11_DISPLAY_H diff --git a/include/LCUI/platform/linux/linux_x11events.h b/include/LCUI/platform/linux/linux_x11events.h index 6aad4ab3..0d5637c4 100644 --- a/include/LCUI/platform/linux/linux_x11events.h +++ b/include/LCUI/platform/linux/linux_x11events.h @@ -1,3 +1,42 @@ +/* *************************************************************************** + * linux_x11events.c -- event loop support for linux xwindow. + * + * Copyright (C) 2016 by Liu Chao + * + * 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * linux_x11events.c -- linux 平台的事件驱动支持,基于 xwindow。 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ + #ifndef LCUI_LINUX_X11_EVENTS_H #define LCUI_LINUX_X11_EVENTS_H diff --git a/src/platform/linux/linux_x11events.c b/src/platform/linux/linux_x11events.c index 961a084f..076b0a62 100644 --- a/src/platform/linux/linux_x11events.c +++ b/src/platform/linux/linux_x11events.c @@ -1,3 +1,41 @@ +/* *************************************************************************** + * linux_x11events.c -- event loop support for linux xwindow. + * + * Copyright (C) 2016 by Liu Chao + * + * 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * linux_x11events.c -- linux 平台的事件驱动支持,基于 xwindow。 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ #include #include @@ -29,7 +67,7 @@ static LCUI_BOOL X11_PostTask( LCUI_AppTask task ) ev.xclient.window = x11.win_main; ev.xclient.format = 32; ev.xclient.message_type = x11.wm_lcui; - XSendEvent(x11.display, x11.win_main, FALSE, NoEventMask, &ev); + XSendEvent( x11.display, x11.win_main, FALSE, NoEventMask, &ev ); return TRUE; } @@ -37,7 +75,7 @@ static LCUI_BOOL X11_WaitEvent( void ) { int fd; fd_set fdset; - struct timeval zero_time; + struct timeval tv; XFlush( x11.display ); fd = ConnectionNumber( x11.display ); if( XEventsQueued(x11.display, QueuedAlready) ) { @@ -45,7 +83,9 @@ static LCUI_BOOL X11_WaitEvent( void ) } FD_ZERO( &fdset ); FD_SET( fd, &fdset ); - if( select(fd + 1, &fdset, NULL, NULL, &zero_time) == 1 ) { + tv.tv_sec = 0; + tv.tv_usec = 10000; + if( select(fd + 1, &fdset, NULL, NULL, &tv) == 1 ) { return XPending( x11.display ); } return FALSE; @@ -54,10 +94,12 @@ static LCUI_BOOL X11_WaitEvent( void ) static void X11_DispatchEvent( void ) { XEvent xevent; + if( !XEventsQueued(x11.display, QueuedAlready) ) { + return; + } XNextEvent( x11.display, &xevent ); - DEBUG_MSG("%d\n", xevent.type); switch( xevent.type ) { - case ClientMessage: + case ClientMessage: default: break; } EventTrigger_Trigger( x11.trigger, xevent.type, &xevent ); From 4a68d3a8434a09c2f6a23fcb9a4d6da180d0dd5a Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Sat, 16 Jul 2016 23:28:07 +0800 Subject: [PATCH 086/124] =?UTF-8?q?=E4=B8=BA=E9=93=BE=E8=A1=A8=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=BF=AB=E9=80=9F=E6=8E=92=E5=BA=8F=E5=92=8C=E5=86=92?= =?UTF-8?q?=E6=B3=A1=E6=8E=92=E5=BA=8F=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/util/linkedlist.h | 4 + src/util/linkedlist.c | 147 +++++++++++++++++++++++++++++++++ 2 files changed, 151 insertions(+) diff --git a/include/LCUI/util/linkedlist.h b/include/LCUI/util/linkedlist.h index 587b7627..a890713c 100644 --- a/include/LCUI/util/linkedlist.h +++ b/include/LCUI/util/linkedlist.h @@ -77,6 +77,10 @@ LCUI_API void LinkedList_Concat( LinkedList *list1, LinkedList *list2 ); #define LinkedList_Clear(list, func) LinkedList_ClearEx( list, func, 1 ) #define LinkedList_ClearData(list, func) LinkedList_ClearEx( list, func, 0 ) +LCUI_API void LinkedList_SwapNode( LinkedList *list, LinkedListNode *a, LinkedListNode *b ); +LCUI_API void LinkedList_QuickSort( LinkedList *list, int( *cmp )(void*, void*) ); +LCUI_API void LinkedList_BubbleSort( LinkedList *list, int( *cmp )(void*, void*) ); + LCUI_END_HEADER #endif diff --git a/src/util/linkedlist.c b/src/util/linkedlist.c index f834cb05..72016009 100644 --- a/src/util/linkedlist.c +++ b/src/util/linkedlist.c @@ -95,6 +95,9 @@ LinkedListNode *LinkedList_GetNode( LinkedList *list, int pos ) if( pos < 0 ) { pos += list->length; } + if( pos >= list->length ) { + return NULL; + } if( pos > list->length / 2 ) { pos = list->length - pos - 1; node = list->tail.prev; @@ -198,3 +201,147 @@ void LinkedList_Concat( LinkedList *list1, LinkedList *list2 ) list1->length += list2->length; list2->length = 0; } + + +typedef struct SortRange_ { + int start, end; + LinkedListNode *snode, *enode; +} SortRange; + +static SortRange NewSortRange( int s, LinkedListNode *snode, + int e, LinkedListNode *enode ) +{ + SortRange r; + r.end = e; + r.start = s; + r.enode = enode; + r.snode = snode; + return r; +} + +void LinkedList_SwapNode( LinkedList *list, LinkedListNode *a, LinkedListNode *b ) +{ + LinkedListNode *node;/* + void *data; + data = a->data; + a->data = b->data; + b->data = data; + return;*/ + if( list->tail.prev == a ) { + list->tail.prev = b; + } else if( list->tail.prev == b ) { + list->tail.prev = a; + } + if( a->prev == b ) { + a->prev = b->prev; + a->prev->next = a; + b->prev = a; + b->next = a->next; + if( b->next ) { + b->next->prev = b; + } + a->next = b; + } else if( b->prev == a ) { + b->prev = a->prev; + b->prev->next = b; + a->prev = b; + a->next = b->next; + if( a->next ) { + a->next->prev = a; + } + b->next = a; + } else { + node = a->prev; + a->prev = b->prev; + a->prev->next = a; + b->prev = node; + b->prev->next = b; + node = a->next; + a->next = b->next; + if( a->next ) { + a->next->prev = a; + } + b->next = node; + if( b->next ) { + b->next->prev = b; + } + } +} + +void LinkedList_QuickSort( LinkedList *list, int (*cmp)(void*, void*) ) +{ + int p = 0; + SortRange *r; + if( list->length <= 0 ) { + return; + } + r = malloc( list->length * sizeof(SortRange) ); + r[p++] = NewSortRange( 0, list->head.next, + list->length - 1, list->tail.prev ); + while( p ) { + int left, right; + SortRange range = r[--p]; + LinkedListNode *mnode, *lnode, *rnode, *node; + if( range.start >= range.end ) { + continue; + } + mnode = range.enode; + left = range.start, right = range.end - 1; + lnode = range.snode, rnode = range.enode->prev; + while( left < right ) { + while( left < right && + cmp( lnode->data, mnode->data ) < 0 ) { + left++, lnode = lnode->next; + } + while( left < right && + cmp( rnode->data, mnode->data ) >= 0 ) { + right--, rnode = rnode->prev; + } + LinkedList_SwapNode( list, lnode, rnode ); + if( lnode == range.snode ) { + range.snode = rnode; + } + node = lnode; + lnode = rnode; + rnode = node; + } + if( cmp( lnode->data, range.enode->data) >= 0 ) { + LinkedList_SwapNode( list, lnode, range.enode ); + node = lnode; + lnode = range.enode; + range.enode = node; + mnode = node; + } else { + left++, lnode = lnode->next; + } + r[p++] = NewSortRange( range.start, range.snode, + left - 1, lnode->prev ); + r[p++] = NewSortRange( left + 1, lnode->next, + range.end, range.enode ); + } + free( r ); +} + +void LinkedList_BubbleSort( LinkedList *list, int( *cmp )(void*, void*) ) +{ + int i, j; + LinkedListNode *node, *cur, *next; + for( i = 0; i < list->length - 1; ++i ) { + LCUI_BOOL no_swap = TRUE; + cur = list->head.next; + for( j = 0; j < list->length - 1 - i; ++j ) { + next = cur->next; + if( cmp( cur->data, next->data ) >= 0 ) { + LinkedList_SwapNode( list, cur, next ); + node = cur; + cur = next; + next = node; + no_swap = FALSE; + } + cur = cur->next; + } + if( no_swap ) { + break; + } + } +} From 016213bc616bea5e7720eef6db8f2dd0e452bb17 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Tue, 19 Jul 2016 22:45:34 +0800 Subject: [PATCH 087/124] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20DictType=5FStringC?= =?UTF-8?q?opyKey=EF=BC=8C=E6=96=B9=E4=BE=BF=E5=88=9B=E5=BB=BA=E4=BB=A5?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E7=B4=A2=E5=BC=95=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=9A=84=E5=AD=97=E5=85=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/util/dict.h | 6 ++---- src/util/dict.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/include/LCUI/util/dict.h b/include/LCUI/util/dict.h index bea3397a..2eb50ad1 100644 --- a/include/LCUI/util/dict.h +++ b/include/LCUI/util/dict.h @@ -227,8 +227,6 @@ LCUI_API void Dict_SetHashFunctionSeed( unsigned int initval ); LCUI_API unsigned int Dict_GetHashFunctionSeed( void ); /* Hash table types */ -extern DictType dictTypeHeapStringCopyKey; -extern DictType dictTypeHeapStrings; -extern DictType dictTypeHeapStringCopyKeyValue; +extern DictType DictType_StringCopyKey; -#endif /* __DICT_H */ +#endif /* LCUI_UTIL_DICT_H */ diff --git a/src/util/dict.c b/src/util/dict.c index 7b3b0d0f..f9dbe809 100644 --- a/src/util/dict.c +++ b/src/util/dict.c @@ -658,3 +658,43 @@ void Dict_DisableResize( void ) { dict_can_resize = 0; } + +static unsigned int StringCopyKeyDict_KeyHash( const void *key ) +{ + const char *buf = key; + unsigned int hash = 5381; + while( *buf ) { + hash = ((hash << 5) + hash) + (*buf++); + } + return hash; +} + +static int StringCopyKeyDict_KeyCompare( void *privdata, const void *key1, + const void *key2 ) +{ + if( strcmp( key1, key2 ) == 0 ) { + return 1; + } + return 0; +} + +static void *StringCopyKeyDict_KeyDup( void *privdata, const void *key ) +{ + char *newkey = malloc( (strlen( key ) + 1)*sizeof( char ) ); + strcpy( newkey, key ); + return newkey; +} + +static void StringCopyKeyDict_KeyDestructor( void *privdata, void *key ) +{ + free( key ); +} + +DictType DictType_StringCopyKey = { + StringCopyKeyDict_KeyHash, + StringCopyKeyDict_KeyDup, + NULL, + StringCopyKeyDict_KeyCompare, + StringCopyKeyDict_KeyDestructor, + NULL +}; From 5cb480a0808962d3450491c4ef3e78d04070df82 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Tue, 19 Jul 2016 23:07:53 +0800 Subject: [PATCH 088/124] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=83=A8=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E6=8E=92=E5=BA=8F=E5=88=A4=E5=AE=9A=E5=92=8C=E6=97=A0?= =?UTF-8?q?=E6=95=88=E5=8C=BA=E5=9F=9F=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 解决非 static 和 relative 定位类型的部件有时无法改变成 WSTATE_NORMAL 状态的问题。 在排序部件前添加相关判断,避免多余的排序操作,毕竟一旦部件数量达到上万级别时为所有部件排序是非常耗时的。 在移动、改变尺寸、显示/隐藏部件时产生的无效区域,改为直接推送至根级部件,在逐级推送过程中,判断当前无效区域是否在部件的可见区域内,一旦判断为不在可见区域内则取消推送该无效区域。这样做可以减少多余的无效区域的遍历和合并操作,对于拥有上万子部件的部件,实际可见区域最多也就是整个屏幕,如果为处于可见区域外的几万子部件处理无效区域合并操作的话,性能开销是非常大的。 --- include/LCUI/gui/widget_base.h | 3 --- include/LCUI/gui/widget_paint.h | 9 +++++++ src/gui/widget_base.c | 44 +++++++++++++++++++++------------ src/gui/widget_paint.c | 28 ++++++++++++++++++++- 4 files changed, 64 insertions(+), 20 deletions(-) diff --git a/include/LCUI/gui/widget_base.h b/include/LCUI/gui/widget_base.h index c69a77e7..6628bcf1 100755 --- a/include/LCUI/gui/widget_base.h +++ b/include/LCUI/gui/widget_base.h @@ -326,9 +326,6 @@ LCUI_API void Widget_UpdateOpacity( LCUI_Widget w ); /** 处理部件中当前积累的任务 */ LCUI_API int Widget_Update( LCUI_Widget w ); -/** 计算部件通过继承得到的样式表 */ -LCUI_API int Widget_ComputeInheritStyle( LCUI_Widget w, LCUI_StyleSheet out_ss ); - /** 设置部件标题 */ LCUI_API void Widget_SetTitleW( LCUI_Widget w, const wchar_t *title ); diff --git a/include/LCUI/gui/widget_paint.h b/include/LCUI/gui/widget_paint.h index c4415f87..e8712216 100644 --- a/include/LCUI/gui/widget_paint.h +++ b/include/LCUI/gui/widget_paint.h @@ -51,6 +51,15 @@ LCUI_BEGIN_HEADER */ LCUI_API void Widget_InvalidateArea( LCUI_Widget w, LCUI_Rect *r, int box_type ); +/** + * 将部件一个无效区域推送到根级部件中 + * @param[in] w 目标部件 + * @param[in] r 矩形区域 + * @param[in] box_type 区域相对于何种框进行定位 + * @returns 推送成功返回 TRUE,如果在推送过程中区域处于部件不可见区域内,则推送失败,返回FALSE + */ +LCUI_API LCUI_BOOL Widget_PushInvalidArea( LCUI_Widget widget, + LCUI_Rect *r, int box_type ); /** * 获取部件中的无效区域 * @param[in] widget 目标部件 diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index a24cb33f..c9c8f0d5 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -94,7 +94,6 @@ int Widget_Append( LCUI_Widget parent, LCUI_Widget widget ) { LCUI_Widget child; LinkedListNode *node, *snode; - DEBUG_MSG("parent: %p, widget: %p\n", parent, widget); if( !parent || !widget || parent == widget->parent ) { return -1; } @@ -118,10 +117,10 @@ int Widget_Append( LCUI_Widget parent, LCUI_Widget widget ) Widget_PostSurfaceEvent( widget, WET_REMOVE ); } widget->parent = parent; + widget->state = WSTATE_CREATED; widget->index = parent->children.length; LinkedList_AppendNode( &parent->children, node ); LinkedList_AppendNode( &parent->children_show, snode ); - Widget_UpdateZIndex( widget ); Widget_PostSurfaceEvent( widget, WET_ADD ); Widget_AddTaskForChildren( widget, WTT_REFRESH_STYLE ); Widget_UpdateTaskStatus( widget ); @@ -161,7 +160,6 @@ int Widget_Unwrap( LCUI_Widget widget ) child->parent = widget->parent; LinkedList_Link( list, target, node ); LinkedList_AppendNode( list_show, snode ); - Widget_UpdateZIndex( child ); Widget_AddTaskForChildren( child, WTT_REFRESH_STYLE ); Widget_UpdateTaskStatus( child ); node = prev; @@ -295,8 +293,7 @@ void Widget_Destroy( LCUI_Widget w ) if( w->computed_style.position != SV_ABSOLUTE ) { Widget_UpdateLayout( w->parent ); } - Widget_InvalidateArea( w->parent, &w->box.graph, - SV_PADDING_BOX ); + Widget_PushInvalidArea( w, NULL, SV_GRAPH_BOX ); } } @@ -314,8 +311,7 @@ void Widget_Empty( LCUI_Widget w ) child->state = WSTATE_DELETED; } LinkedList_Concat( &w->children_trash, &w->children ); - Widget_InvalidateArea( w->parent, &w->box.graph, - SV_PADDING_BOX ); + Widget_PushInvalidArea( w, NULL, SV_GRAPH_BOX ); Widget_AddTask( w, WTT_LAYOUT ); return; } else { @@ -603,8 +599,7 @@ void Widget_UpdateVisibility( LCUI_Widget w ) } visible = w->computed_style.visible; if( w->parent ) { - Widget_InvalidateArea( w->parent, &w->box.graph, - SV_PADDING_BOX ); + Widget_PushInvalidArea( w, NULL, SV_GRAPH_BOX ); if( w->computed_style.display != display && w->computed_style.position != SV_ABSOLUTE ) { Widget_UpdateLayout( w->parent ); @@ -642,17 +637,24 @@ void Widget_UpdateZIndex( LCUI_Widget w ) void Widget_ExecUpdateZIndex( LCUI_Widget w ) { + int z_index; LinkedList *list; LinkedListNode *cnode, *csnode, *snode; LCUI_Style s = &w->style->sheet[key_z_index]; if( s->is_valid && s->type == SVT_VALUE ) { - w->computed_style.z_index = s->value; + z_index = s->value; } else { - w->computed_style.z_index = 0; + z_index = 0; } if( !w->parent ) { return; } + if( w->state == WSTATE_NORMAL ) { + if( w->computed_style.z_index == z_index ) { + return; + } + } + w->computed_style.z_index = z_index; snode = Widget_GetShowNode( w ); list = &w->parent->children_show; LinkedList_Unlink( list, snode ); @@ -741,7 +743,7 @@ void Widget_UpdatePosition( LCUI_Widget w ) Widget_UpdateLayout( w->parent ); } w->computed_style.position = position; - Widget_AddTask( w, WTT_ZINDEX ); + Widget_UpdateZIndex( w ); w->x = w->origin_x; w->y = w->origin_y; switch( position ) { @@ -822,8 +824,8 @@ void Widget_UpdatePosition( LCUI_Widget w ) DEBUG_MSG("new-rect: %d,%d,%d,%d\n", w->box.graph.x, w->box.graph.y, w->box.graph.w, w->box.graph.h); DEBUG_MSG("old-rect: %d,%d,%d,%d\n", rect.x, rect.y, rect.w, rect.h); /* 标记移动前后的区域 */ - Widget_InvalidateArea( w->parent, &w->box.graph, SV_PADDING_BOX ); - Widget_InvalidateArea( w->parent, &rect, SV_PADDING_BOX ); + Widget_PushInvalidArea( w, NULL, SV_GRAPH_BOX ); + Widget_PushInvalidArea( w->parent, &rect, SV_PADDING_BOX ); } /* 检测是否为顶级部件并做相应处理 */ Widget_PostSurfaceEvent( w, WET_MOVE ); @@ -1456,6 +1458,18 @@ void Widget_ExecUpdateLayout( LCUI_Widget w ) child = node->data; if( child->computed_style.position != SV_STATIC && child->computed_style.position != SV_RELATIVE ) { + /* 如果部件还处于未准备完毕的状态 */ + if( child->state < WSTATE_READY ) { + child->state |= WSTATE_LAYOUTED; + /* 如果部件已经准备完毕则触发 ready 事件 */ + if( child->state == WSTATE_READY ) { + LCUI_WidgetEventRec e; + e.type = WET_READY; + e.cancel_bubble = TRUE; + Widget_TriggerEvent( child, &e, NULL ); + child->state = WSTATE_NORMAL; + } + } continue; } switch( child->computed_style.display ) { @@ -1490,10 +1504,8 @@ void Widget_ExecUpdateLayout( LCUI_Widget w ) default: continue; } Widget_UpdatePosition( child ); - /* 如果部件还处于未准备完毕的状态 */ if( child->state < WSTATE_READY ) { child->state |= WSTATE_LAYOUTED; - /* 如果部件已经准备完毕则触发 ready 事件 */ if( child->state == WSTATE_READY ) { LCUI_WidgetEventRec e; e.type = WET_READY; diff --git a/src/gui/widget_paint.c b/src/gui/widget_paint.c index 5f1af90d..ace732e3 100644 --- a/src/gui/widget_paint.c +++ b/src/gui/widget_paint.c @@ -107,6 +107,32 @@ void Widget_InvalidateArea( LCUI_Widget w, LCUI_Rect *r, int box_type ) } } +LCUI_BOOL Widget_PushInvalidArea( LCUI_Widget widget, + LCUI_Rect *r, int box_type ) +{ + LCUI_Rect rect; + LCUI_Widget w = widget; + LCUI_Widget root = LCUIWidget_GetRoot(); + + if( !w ) { + w = root; + } + Widget_AdjustArea( w, r, &rect, box_type ); + while( w && w->parent ) { + int width = w->parent->box.padding.width; + int height = w->parent->box.padding.height; + rect.x += w->box.graph.x; + rect.y += w->box.graph.y; + LCUIRect_ValidateArea( &rect, width, height ); + if( rect.width < 0 || rect.height < 0 ) { + return FALSE; + } + w = w->parent; + } + Widget_InvalidateArea( root, &rect, SV_PADDING_BOX ); + return TRUE; +} + int Widget_GetInvalidArea( LCUI_Widget widget, LCUI_Rect *area ) { LCUI_Rect *rect; @@ -370,7 +396,7 @@ void Widget_Render( LCUI_Widget w, LCUI_PaintContext paint ) /* 按照显示顺序,从底到顶,递归遍历子级部件 */ LinkedList_ForEachReverse( node, &w->children_show ) { LCUI_Rect child_rect; - LCUI_Widget child = node->data; + LCUI_Widget child = node->data; if( !child->computed_style.visible || child->state != WSTATE_NORMAL ) { continue; From 9df94d8387b9b104ba7ceebad85170623e848fb8 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Sun, 31 Jul 2016 23:48:03 +0800 Subject: [PATCH 089/124] =?UTF-8?q?=E6=9B=B4=E6=94=B9=20CSS=20=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=9A=84=E5=AD=98=E5=82=A8=E7=BB=93=E6=9E=84=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=83=A8=E5=88=86=E6=93=8D=E4=BD=9C=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/gui/css_parser.h | 2 +- include/LCUI/gui/widget_base.h | 16 +- include/LCUI/gui/widget_style.h | 17 +- src/gui/builder.c | 5 +- src/gui/css_parser.c | 28 +- src/gui/widget/button.c | 2 +- src/gui/widget/scrollbar.c | 2 +- src/gui/widget/sidebar.c | 2 +- src/gui/widget/textedit.c | 5 +- src/gui/widget/textview.c | 2 +- src/gui/widget_base.c | 4 +- src/gui/widget_style.c | 1393 ++++++++++++++++++------------- 12 files changed, 851 insertions(+), 627 deletions(-) diff --git a/include/LCUI/gui/css_parser.h b/include/LCUI/gui/css_parser.h index b1f0f91a..c4064bd1 100644 --- a/include/LCUI/gui/css_parser.h +++ b/include/LCUI/gui/css_parser.h @@ -62,7 +62,7 @@ void LCUICSS_Init(void); LCUI_API int LCUICSS_LoadFile( const char *filepath ); /** 从字符串中载入CSS样式数据,并导入至样式库中 */ -LCUI_API int LCUICSS_LoadString( const char *str ); +LCUI_API int LCUICSS_LoadString( const char *str, const char *space ); void LCUICSS_Destroy(void); diff --git a/include/LCUI/gui/widget_base.h b/include/LCUI/gui/widget_base.h index 6628bcf1..061adcb8 100755 --- a/include/LCUI/gui/widget_base.h +++ b/include/LCUI/gui/widget_base.h @@ -150,18 +150,22 @@ typedef struct LCUI_StyleSheetRec_ { int length; } LCUI_StyleSheetRec, *LCUI_StyleSheet; +/** 选择器结点结构 */ typedef struct LCUI_SelectorNodeRec_ { - char *id; - char *type; - char *class_name; - char *pseudo_class_name; + 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_ { - LCUI_SelectorNode *list; /**< 选择器结点列表 */ - int length; /**< 选择器结点长度 */ int rank; /**< 权值,决定优先级 */ int batch_num; /**< 批次号 */ + int length; /**< 选择器结点长度 */ + LCUI_SelectorNode *nodes; /**< 选择器结点列表 */ } LCUI_SelectorRec, *LCUI_Selector; #define SetStyle(S, NAME, VAL, TYPE) S->sheet[NAME].is_valid = TRUE, \ diff --git a/include/LCUI/gui/widget_style.h b/include/LCUI/gui/widget_style.h index 0cd6d1bb..c72ad505 100644 --- a/include/LCUI/gui/widget_style.h +++ b/include/LCUI/gui/widget_style.h @@ -1,7 +1,7 @@ /* *************************************************************************** * widget_style.h -- widget style library module for LCUI. * - * Copyright (C) 2015 by Liu Chao + * Copyright (C) 2015-2016 by Liu Chao * * 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 @@ /* **************************************************************************** * widget_style.h -- LCUI 的部件样式库模块。 * - * 版权所有 (C) 2015 归属于 刘超 + * 版权所有 (C) 2015-2016 归属于 刘超 * * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 * @@ -60,13 +60,13 @@ LCUI_API int StyleSheet_Merge( LCUI_StyleSheet dest, LCUI_StyleSheet src ); LCUI_API int StyleSheet_Replace( LCUI_StyleSheet dest, LCUI_StyleSheet src ); /** 删除样式表 */ -LCUI_API void StyleSheet_Delete( LCUI_StyleSheet *ss ); +LCUI_API void StyleSheet_Delete( LCUI_StyleSheet ss ); /** 根据字符串内容生成相应的选择器 */ LCUI_API LCUI_Selector Selector( const char *selector ); /** 删除选择器 */ -LCUI_API void Selector_Delete( LCUI_Selector *selector ); +LCUI_API void Selector_Delete( LCUI_Selector s ); /** 判断两个选择器是否相等 */ LCUI_API LCUI_BOOL Selector_Compare( LCUI_Selector s1, LCUI_Selector s2 ); @@ -75,7 +75,8 @@ 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_StyleSheet in_ss ); +LCUI_API int LCUI_PutStyle( LCUI_Selector selector, + LCUI_StyleSheet in_ss, const char *space ); /** 打印样式表的内容 */ LCUI_API void LCUI_PrintStyleSheet( LCUI_StyleSheet ss ); @@ -95,6 +96,12 @@ LCUI_API void Widget_UpdateStyle( LCUI_Widget w, LCUI_BOOL is_update_all ); /** 直接更新当前部件的样式 */ LCUI_API void Widget_ExecUpdateStyle( LCUI_Widget w, LCUI_BOOL is_update_all ); +/** 查找作用于当前部件的样式表 */ +LCUI_API int Widget_FindStyles( LCUI_Widget w, LinkedList *list ); + +/** 获取选择器 */ +LCUI_API LCUI_Selector Widget_GetSelector( LCUI_Widget w ); + #include #endif diff --git a/src/gui/builder.c b/src/gui/builder.c index fdf3eb34..8a52f733 100644 --- a/src/gui/builder.c +++ b/src/gui/builder.c @@ -82,6 +82,7 @@ struct XMLParserContextRec_ { LCUI_Widget widget; LCUI_Widget root; ParserPtr parent; + const char *space; }; static struct ModuleContext { @@ -123,7 +124,7 @@ static int ParseResource( XMLParserContext ctx, xmlNodePtr node ) if( node->type != XML_TEXT_NODE ) { continue; } - LCUICSS_LoadString( (char*)node->content ); + LCUICSS_LoadString( (char*)node->content, ctx->space ); } } return PB_NEXT; @@ -287,6 +288,7 @@ LCUI_Widget LCUIBuilder_LoadString( const char *str, int size ) ctx.root = NULL; ctx.widget = NULL; ctx.parent = NULL; + ctx.space = NULL; if( !self.is_inited ) { LCUIBuilder_Init(); } @@ -321,6 +323,7 @@ LCUI_Widget LCUIBuilder_LoadFile( const char *filepath ) ctx.root = NULL; ctx.widget = NULL; ctx.parent = NULL; + ctx.space = filepath; if( !self.is_inited ) { LCUIBuilder_Init(); } diff --git a/src/gui/css_parser.c b/src/gui/css_parser.c index 82e1f34a..b31d89c7 100644 --- a/src/gui/css_parser.c +++ b/src/gui/css_parser.c @@ -61,6 +61,7 @@ typedef struct CSSParserContextRec_ { LinkedList selectors; /**< 当前匹配到的选择器列表 */ LCUI_StyleSheet css; /**< 当前缓存的样式表 */ LCUI_StyleParser parser; /**< 当前找到的解析器 */ + char *space; /**< 样式记录所属的空间 */ } CSSParserContextRec, *CSSParserContext; /** 样式字符串值与标识码 */ @@ -703,7 +704,8 @@ static int CompareName( void *data, const void *keydata ) return strcmp(((KeyNameGroup*)data)->name, (const char*)keydata); } -static CSSParserContext NewCSSParserContext( size_t buffer_size ) +static CSSParserContext NewCSSParserContext( size_t buffer_size, + const char *space ) { CSSParserContext ctx = NEW(CSSParserContextRec, 1); LinkedList_Init( &ctx->selectors ); @@ -711,6 +713,7 @@ static CSSParserContext NewCSSParserContext( size_t buffer_size ) ctx->buffer_size = buffer_size; ctx->target_bak = TARGET_NONE; ctx->target = TARGET_NONE; + ctx->space = space ? strdup( space ): NULL; return ctx; } @@ -723,12 +726,6 @@ static void DeleteCSSParserContext( CSSParserContext *ctx_ptr ) *ctx_ptr = NULL; } -static void OnDeleteSelector( void *data ) -{ - LCUI_Selector s = data; - Selector_Delete( &s ); -} - /** 载入CSS代码块,用于实现CSS代码的分块载入 */ static int LCUICSS_LoadBlock( CSSParserContext ctx, const char *str ) { @@ -749,7 +746,7 @@ static int LCUICSS_LoadBlock( CSSParserContext ctx, const char *str ) ctx->buffer[ctx->pos] = 0; ctx->pos = 0; DEBUG_MSG("selector: %s\n", ctx->buffer); - s = Selector(ctx->buffer); + s = Selector( ctx->buffer ); if( !s ) { // 解析出错 ... break; @@ -847,10 +844,10 @@ put_css: DEBUG_MSG("put css\n"); /* 将记录的样式表添加至匹配到的选择器中 */ LinkedList_ForEach( node, &ctx->selectors ) { - LCUI_PutStyle( node->data, ctx->css ); + LCUI_PutStyle( node->data, ctx->css, ctx->space ); } - LinkedList_Clear( &ctx->selectors, OnDeleteSelector ); - StyleSheet_Delete( &ctx->css ); + LinkedList_Clear( &ctx->selectors, (FuncPtr)Selector_Delete ); + StyleSheet_Delete( ctx->css ); continue; select_parser: ctx->target = TARGET_VALUE; @@ -892,7 +889,7 @@ int LCUICSS_LoadFile( const char *filepath ) if( !fp ) { return -1; } - ctx = NewCSSParserContext( 512 ); + ctx = NewCSSParserContext( 512, filepath ); n = fread( buff, 1, 511, fp ); while( n > 0 ) { buff[n] = 0; @@ -904,14 +901,13 @@ int LCUICSS_LoadFile( const char *filepath ) return 0; } -/** 从字符串中解析出样式,并导入至样式库中 */ -int LCUICSS_LoadString( const char *str ) +int LCUICSS_LoadString( const char *str, const char *space ) { int len = 1; const char *cur; CSSParserContext ctx; DEBUG_MSG("parse begin\n"); - ctx = NewCSSParserContext( 512 ); + ctx = NewCSSParserContext( 512, space ); for( cur = str; len > 0; cur += len ) { len = LCUICSS_LoadBlock( ctx, cur ); } @@ -920,13 +916,11 @@ int LCUICSS_LoadString( const char *str ) return 0; } -/** 获取当前记录的样式属性的总数 */ int LCUICSS_GetStyleTotal(void) { return self.count; } -/** 注册新的属性和对应的属性值解析器 */ int LCUICSS_AddParser( LCUI_StyleParser sp ) { int key; diff --git a/src/gui/widget/button.c b/src/gui/widget/button.c index b714f3c9..ae051555 100755 --- a/src/gui/widget/button.c +++ b/src/gui/widget/button.c @@ -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 ); + LCUICSS_LoadString( button_css, NULL ); } diff --git a/src/gui/widget/scrollbar.c b/src/gui/widget/scrollbar.c index f2da4604..a6b67443 100644 --- a/src/gui/widget/scrollbar.c +++ b/src/gui/widget/scrollbar.c @@ -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 ); + LCUICSS_LoadString( scrollbar_css, NULL ); } diff --git a/src/gui/widget/sidebar.c b/src/gui/widget/sidebar.c index 6c463774..21064cf1 100644 --- a/src/gui/widget/sidebar.c +++ b/src/gui/widget/sidebar.c @@ -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 ); + LCUICSS_LoadString( sidebar_css, NULL ); } diff --git a/src/gui/widget/textedit.c b/src/gui/widget/textedit.c index e206110e..e157f519 100644 --- a/src/gui/widget/textedit.c +++ b/src/gui/widget/textedit.c @@ -204,7 +204,6 @@ static void TextCaret_OnInit( LCUI_Widget widget ) caret->blink_time = 500; caret->timer_id = LCUITimer_Set( caret->blink_time, TextCaret_OnBlink, widget, TRUE ); - LCUICSS_LoadString( textcaret_css ); } /** 设置闪烁的时间间隔 */ @@ -228,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 ); + LCUICSS_LoadString( textcaret_css, NULL ); } /*-------------------------------- End Caret --------------------------------*/ @@ -923,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 ); + LCUICSS_LoadString( textedit_css, NULL ); LCUIWidget_AddTextCaret(); textedit_event_id = LCUIWidget_AllocEventId(); LCUIWidget_SetEventName( textedit_event_id, "change" ); diff --git a/src/gui/widget/textview.c b/src/gui/widget/textview.c index 7651d4f1..89140425 100644 --- a/src/gui/widget/textview.c +++ b/src/gui/widget/textview.c @@ -544,5 +544,5 @@ void LCUIWidget_AddTextView( void ) style_key_map[style_parsers[i].key] = LCUICSS_AddParser( &style_parsers[i] ); } - LCUICSS_LoadString( textview_css ); + LCUICSS_LoadString( textview_css, NULL ); } diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index c9c8f0d5..4f956f82 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -1369,7 +1369,7 @@ int Widget_AddStatus( LCUI_Widget w, const char *status_name ) return 0; } Widget_UpdateStyle( w, TRUE ); - Widget_AddTaskForChildren( w, WTT_REFRESH_STYLE ); + Widget_AddTaskForChildren( w, WTT_REFRESH_STYLE ); return 1; } @@ -1386,7 +1386,7 @@ int Widget_RemoveStatus( LCUI_Widget w, const char *status_name ) return 0; } Widget_UpdateStyle( w, TRUE ); - Widget_AddTaskForChildren( w, WTT_REFRESH_STYLE ); + Widget_AddTaskForChildren( w, WTT_REFRESH_STYLE ); return 1; } diff --git a/src/gui/widget_style.c b/src/gui/widget_style.c index eb9badfc..4058dff9 100644 --- a/src/gui/widget_style.c +++ b/src/gui/widget_style.c @@ -1,7 +1,7 @@ /* *************************************************************************** * widget_style.c -- widget style library module for LCUI. * - * Copyright (C) 2015 by Liu Chao + * Copyright (C) 2015-2016 by Liu Chao * * 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 @@ /* **************************************************************************** * widget_style.c -- LCUI 的部件样式库模块。 * - * 版权所有 (C) 2015 归属于 刘超 + * 版权所有 (C) 2015-2016 归属于 刘超 * * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 * @@ -37,6 +37,7 @@ * 没有,请查看:. * ****************************************************************************/ +#include #include #include #include @@ -45,9 +46,12 @@ #include #define MAX_NAME_LEN 256 +#define MAX_SELECTOR_LEN 1024 #define MAX_NODE_DEPTH 32 #define MAX_SELECTOR_DEPTH 32 +#define FindStyleSheet(S, L) FindStyleSheetFromGroup(0, S, L) + enum SelectorRank { GENERAL_RANK = 0, TYPE_RANK = 1, @@ -67,38 +71,48 @@ enum SelectorFinderLevel { LEVEL_TOTAL_NUM }; -typedef struct StyleListNodeRec_ { - LCUI_StyleSheet style; /**< 样式表 */ - LCUI_Selector selector; /**< 作用范围 */ -} StyleListNodeRec, *StyleListNode; - -typedef struct StyleTreeNodeRec_ { - char name[MAX_NAME_LEN]; /**< 作用对象的名称 */ - LinkedList styles; /**< 其它样式表 */ -} StyleTreeNodeRec, *StyleTreeNode; - /* 样式表查找器的上下文数据结构 */ -typedef struct StyleSheetFinderRec_ { +typedef struct NamesFinderRec_ { int level; /**< 当前选择器层级 */ int class_i; /**< 当前处理到第几个类名 */ int status_i; /**< 当前处理到第几个状态名(伪类名) */ int name_i; /**< 选择器名称从第几个字符开始 */ char name[MAX_NAME_LEN]; /**< 选择器名称缓存 */ - LinkedList classes; /**< 已排序的类名列表 */ - LinkedList status; /**< 已排序的状态列表 */ - LCUI_Widget widget; /**< 针对的部件 */ -} StyleSheetFinderRec, *StyleSheetFinder; + LCUI_SelectorNode node; /**< 针对的选择器结点 */ +} NamesFinderRec, *NamesFinder; + +/** 样式链接记录组 */ +typedef struct StyleLinkGroupRec_ { + Dict *links; /**< 样式链接表 */ + char *name; /**< 选择器名称 */ + LCUI_SelectorNodeRec snode; /**< 选择器结点 */ +} StyleLinkGroupRec, *StyleLinkGroup; + +/** 样式结点记录 */ +typedef struct StyleNodeRec_ { + int rank; /**< 权值,决定优先级 */ + int batch_num; /**< 批次号 */ + char *space; /**< 所属的空间 */ + LCUI_StyleSheet sheet; /**< 样式表 */ +} StyleNodeRec, *StyleNode; + +/** 样式链接记录 */ +typedef struct StyleLinkRec_ { + StyleLinkGroup group; /**< 所属组 */ + LinkedList styles; /**< 作用于当前选择器的样式 */ + Dict *parents; /**< 父级节点 */ +} StyleLinkRec, *StyleLink; static struct { LCUI_BOOL is_inited; - LCUI_RBTree tree; /**< 样式树 */ + LinkedList groups; /**< 样式组列表 */ } style_library; const char *global_css = ToString( * { width: auto; - height: auto; + height: auto; background-color: transparent; display: block; position: static; @@ -108,92 +122,175 @@ const char *global_css = ToString( ); -/** 获取指针数组的长度 */ -static size_t ptrslen( char *const *list ) +static int SortedStrList_Add( char ***strlist, const char *str ) { - char *const *p = list; - if( list == NULL ) { - return 0; + int i, n, len, pos; + char **newlist, *newstr; + + if( *strlist ) { + for( i = 0; (*strlist)[i]; ++i ); + len = i + 2; + } else { + len = 2; } - while( *p ) { - p++; + newlist = realloc( *strlist, sizeof( char* ) * len ); + if( !newlist ) { + return -ENOMEM; } - return p - list; + 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; } -static int CompareName( void *data, const void *keydata ) +static void SortedStrList_Destroy( char **strlist ) { - return strcmp( ((StyleTreeNode)data)->name, (const char*)keydata ); + int i; + for( i = 0; strlist[i]; ++i ) { + free( strlist[i] ); + strlist[i] = NULL; + } + free( strlist ); } -static void SelectorNode_Delete( LCUI_SelectorNode *node_ptr ) +/** + * 匹配选择器节点 + * 左边的选择器必须包含右边的选择器的所有属性。 + */ +static LCUI_BOOL SelectorNode_Match( LCUI_SelectorNode sn1, + LCUI_SelectorNode sn2 ) +{ + int i, j; + if( sn2->id ) { + if( !sn1->id || strcmp( sn1->id, sn2->id ) != 0 ) { + return FALSE; + } + } + if( sn2->type ) { + if( !sn1->type || strcmp( sn1->type, sn2->type ) != 0 ) { + return FALSE; + } + } + if( sn2->classes ) { + if( !sn1->classes ) { + return FALSE; + } + for( i = 0; sn2->classes[i]; ++i ) { + for( j = 0; sn1->classes[j]; ++j ) { + if( strcmp( sn2->classes[i], + sn1->classes[i] ) == 0 ) { + j = -1; + break; + } + } + if( j != -1 ) { + return FALSE; + } + } + } + if( sn2->status ) { + if( !sn1->status ) { + return FALSE; + } + for( i = 0; sn2->status[i]; ++i ) { + for( j = 0; sn1->status[j]; ++j ) { + if( strcmp( sn2->status[i], + sn1->status[i] ) == 0 ) { + j = -1; + break; + } + } + if( j != -1 ) { + return FALSE; + } + } + } + return TRUE; +} + +static void SelectorNode_Copy( LCUI_SelectorNode dst, LCUI_SelectorNode src ) +{ + int i; + dst->id = src->id ? strdup( src->id ) : NULL; + dst->type = src->type ? strdup( src->type ) : NULL; + dst->fullname = src->fullname ? strdup( src->fullname ) : NULL; + if( src->classes ) { + for( i = 0; src->classes[i]; ++i ) { + SortedStrList_Add( &dst->classes, src->classes[i] ); + } + } + if( src->status ) { + for( i = 0; src->status[i]; ++i ) { + SortedStrList_Add( &dst->status, src->status[i] ); + } + } +} + +static void SelectorNode_Delete( LCUI_SelectorNode node ) { - LCUI_SelectorNode node = *node_ptr; if( node->type ) { free( node->type ); node->type = NULL; } - if( node->class_name ) { - free( node->class_name ); - node->class_name = NULL; - } if( node->id ) { free( node->id ); node->id = NULL; } - if( node->pseudo_class_name ) { - free( node->pseudo_class_name ); - node->pseudo_class_name = NULL; + if( node->classes ) { + SortedStrList_Destroy( node->classes ); + node->classes = NULL; + } + if( node->status ) { + SortedStrList_Destroy( node->status ); + node->status = NULL; + } + if( node->fullname ) { + free( node->fullname ); + node->fullname = NULL; } free( node ); - *node_ptr = NULL; } -void Selector_Delete( LCUI_Selector *s_ptr ) +void Selector_Delete( LCUI_Selector s ) { int i; - LCUI_Selector s = *s_ptr; - for( i = 0; ilist[i] ) { + for( i = 0; i < MAX_SELECTOR_DEPTH; ++i ) { + if( !s->nodes[i] ) { break; } - SelectorNode_Delete( &s->list[i] ); + SelectorNode_Delete( s->nodes[i] ); + s->nodes[i] = NULL; } s->rank = 0; s->length = 0; s->batch_num = 0; - free( s->list ); + free( s->nodes ); free( s ); - *s_ptr = NULL; -} - -static void DestroyStyleListNode( StyleListNode node ) -{ - StyleSheet_Delete( &node->style ); - Selector_Delete( &node->selector ); -} - -static void DestroyStyleTreeNode( void *data ) -{ - StyleTreeNode node = data; - LinkedList_Clear( &node->styles, (FuncPtr)DestroyStyleListNode ); -} - -void LCUIWidget_InitStyle( void ) -{ - RBTree_Init( &style_library.tree ); - RBTree_OnJudge( &style_library.tree, CompareName ); - RBTree_OnDestroy( &style_library.tree, DestroyStyleTreeNode ); - style_library.is_inited = TRUE; - LCUICSS_Init(); - LCUICSS_LoadString( global_css ); -} - -void LCUIWidget_ExitStyle( void ) -{ - RBTree_Destroy( &style_library.tree ); - style_library.is_inited = FALSE; - LCUICSS_Destroy(); } LCUI_StyleSheet StyleSheet( void ) @@ -228,12 +325,11 @@ void StyleSheet_Clear( LCUI_StyleSheet ss ) } } -void StyleSheet_Delete( LCUI_StyleSheet *ss ) +void StyleSheet_Delete( LCUI_StyleSheet ss ) { - StyleSheet_Clear( *ss ); - free( (*ss)->sheet ); - free( *ss ); - *ss = NULL; + StyleSheet_Clear( ss ); + free( ss->sheet ); + free( ss ); } int StyleSheet_Merge( LCUI_StyleSheet dest, LCUI_StyleSheet src ) @@ -326,6 +422,177 @@ int StyleSheet_Replace( LCUI_StyleSheet dest, LCUI_StyleSheet src ) return count; } +/** 初始化样式表查找器 */ +static void NamesFinder_Init( NamesFinder sfinder, LCUI_SelectorNode snode ) +{ + sfinder->level = 0; + sfinder->class_i = 0; + sfinder->name_i = 0; + sfinder->status_i = 0; + sfinder->name[0] = 0; + sfinder->node = snode; +} + +/** 销毁样式表查找器 */ +static void NamesFinder_Destroy( NamesFinder sfinder ) +{ + sfinder->name_i = 0; + sfinder->name[0] = 0; + sfinder->class_i = 0; + sfinder->status_i = 0; + sfinder->node = NULL; + sfinder->level = LEVEL_NONE; +} + +/* 查找匹配的样式表 */ +static int NamesFinder_Find( NamesFinder sfinder, LinkedList *list ) +{ + int i, len, old_len, old_level, count = 0; + char *fullname = sfinder->name + sfinder->name_i; + old_len = len = strlen( fullname ); + old_level = sfinder->level; + switch( sfinder->level ) { + case LEVEL_TYPE: + /* 按类型选择器搜索样式表 */ + if( !sfinder->node->type ) { + return 0; + } + strcpy( fullname, sfinder->node->type ); + LinkedList_Append( list, strdup( fullname ) ); + break; + case LEVEL_ID: + /* 按ID选择器搜索样式表 */ + if( !sfinder->node->id ) { + return 0; + } + fullname[len++] = '#'; + strcpy( fullname + len, sfinder->node->id ); + LinkedList_Append( list, strdup( fullname ) ); + fullname[old_len] = 0; + break; + case LEVEL_CLASS: + if( !sfinder->node->classes ) { + return 0; + } + /* 按类选择器搜索样式表 + * 假设当前选择器全名为:textview#main-btn-text,且有 .a .b .c + * 这三个类,那么下面的处理将会拆分成以下三个选择器来匹配样式表: + * textview#test-text.a + * textview#test-text.b + * textview#test-text.a + */ + fullname[len++] = '.'; + for( i = 0; sfinder->node->classes[i]; ++i ) { + sfinder->level += 1; + strcpy( fullname + len, sfinder->node->classes[i] ); + LinkedList_Append( list, strdup( fullname ) ); + /* 将当前选择器名与其它层级的选择器名组合 */ + while( sfinder->level < LEVEL_TOTAL_NUM ) { + count += NamesFinder_Find( sfinder, list ); + sfinder->level += 1; + } + sfinder->level = LEVEL_CLASS; + sfinder->class_i += 1; + } + sfinder->level = LEVEL_CLASS; + fullname[old_len] = 0; + sfinder->class_i = 0; + return count; + case LEVEL_CLASS_2: + if( !sfinder->node->classes ) { + return 0; + } + /* 按类选择器搜索交集样式表,结果类似于这样: + * textview#test-text.a.b + * textview#test-text.a.c + * textview#test-text.b.c + * textview#test-text.a.b.c + */ + fullname[len++] = '.'; + for( i = 0; sfinder->node->classes[i]; ++i ) { + if( i <= sfinder->class_i ) { + continue; + } + strcpy( fullname + len, sfinder->node->classes[i] ); + LinkedList_Append( list, strdup( fullname ) ); + sfinder->class_i += 1; + count += NamesFinder_Find( sfinder, list ); + sfinder->class_i -= 1; + sfinder->level = LEVEL_STATUS; + /** + * 递归拼接伪类名,例如: + * textview#main-btn-text:active + */ + count += NamesFinder_Find( sfinder, list ); + sfinder->level = LEVEL_CLASS_2; + } + fullname[old_len] = 0; + sfinder->level = LEVEL_CLASS_2; + return count; + case LEVEL_STATUS: + if( !sfinder->node->status ) { + return 0; + } + fullname[len++] = ':'; + sfinder->level = LEVEL_STATUS_2; + /** + * 按伪类选择器搜索样式表 + * 假设当前选择器全名为:textview#main-btn-text:hover:focus:active + * 那么下面的循环会将它拆分为以下几个选择器来匹配样式: + * textview#main-btn-text:active + * textview#main-btn-text:active:focus + * textview#main-btn-text:active:focus:hover + * textview#main-btn-text:active:hover + * textview#main-btn-text:focus + * textview#main-btn-text:focus:hover + * textview#main-btn-text:hover + */ + for( i = 0; sfinder->node->status[i]; ++i ) { + strcpy( fullname + len, sfinder->node->status[i] ); + LinkedList_Append( list, strdup( fullname ) ); + /** + * 递归调用,以一层层拼接出像下面这样的选择器: + * textview#main-btn-text:active:focus:hover + */ + count += NamesFinder_Find( sfinder, list ); + sfinder->status_i += 1; + } + sfinder->level = LEVEL_STATUS; + fullname[old_len] = 0; + sfinder->status_i = 0; + return count; + case LEVEL_STATUS_2: + if( !sfinder->node->status ) { + return 0; + } + /** 按伪类选择器搜索交集样式表 */ + for( i = 0; sfinder->node->status[i]; ++i ) { + if( i <= sfinder->status_i ) { + continue; + } + fullname[len] = ':'; + strcpy( fullname + len + 1, sfinder->node->status[i] ); + LinkedList_Append( list, strdup( fullname ) ); + sfinder->status_i += 1; + count += NamesFinder_Find( sfinder, list ); + sfinder->status_i -= 1; + } + fullname[old_len] = 0; + return count; + default:break; + } + for( i = sfinder->level + 1; i < LEVEL_TOTAL_NUM; ++i ) { + if( i == LEVEL_STATUS_2 || i == LEVEL_CLASS_2 ) { + continue; + } + sfinder->level = i; + count += NamesFinder_Find( sfinder, list ); + } + fullname[old_len] = 0; + sfinder->level = old_level; + return count; +} + static int SelectorNode_Save( LCUI_SelectorNode node, const char *name, int len, char type ) { @@ -333,39 +600,115 @@ static int SelectorNode_Save( LCUI_SelectorNode node, if( len < 1 ) { return 0; } - str = malloc( (len + 1)*sizeof( char ) ); - strcpy( str, name ); switch( type ) { case 0: if( node->type ) { break; } + len += 1; + str = malloc( sizeof( char ) * len ); + strncpy( str, name, len ); node->type = str; return TYPE_RANK; case ':': - if( node->pseudo_class_name ) { - break; + if( SortedStrList_Add( &node->status, name ) == 0 ) { + return PCLASS_RANK; } - node->pseudo_class_name = str; - return PCLASS_RANK; + break; case '.': - if( node->class_name ) { - break; + if( SortedStrList_Add( &node->classes, name ) == 0 ) { + return CLASS_RANK; } - node->class_name = str; - return CLASS_RANK; + break; case '#': if( node->id ) { break; } + len += 1; + str = malloc( sizeof( char ) * len ); + strncpy( str, name, len ); node->id = str; return ID_RANK; default: break; } - free( str ); return 0; } +static int SelectorNode_GetNames( LCUI_SelectorNode sn, LinkedList *names ) +{ + int count; + NamesFinderRec sfinder; + NamesFinder_Init( &sfinder, sn ); + count = NamesFinder_Find( &sfinder, names ); + NamesFinder_Destroy( &sfinder ); + return count; +} + +static int SelectorNode_Update( LCUI_SelectorNode node ) +{ + int i, len = 0; + char *fullname; + + node->rank = 0; + if( node->id ) { + len += strlen( node->id ) + 2; + node->rank += ID_RANK; + } + if( node->type ) { + len += strlen( node->type ) + 2; + node->rank += TYPE_RANK; + } + if( node->classes ) { + for( i = 0; node->classes[i]; ++i ) { + len += strlen( node->classes[i] ) + 1; + node->rank += CLASS_RANK; + } + len += 1; + } + if( node->status ) { + for( i = 0; node->status[i]; ++i ) { + len += strlen( node->status[i] ) + 1; + node->rank += PCLASS_RANK; + } + len += 1; + } + if( len > 0 ) { + fullname = malloc( sizeof( char ) * len ); + if( !fullname ) { + return -ENOMEM; + } + fullname[0] = 0; + if( node->type ) { + strcat( fullname, node->type ); + } + if( node->id ) { + strcat( fullname, "#" ); + strcat( fullname, node->id ); + } + if( node->classes ) { + for( i = 0; node->classes[i]; ++i ) { + strcat( fullname, "." ); + strcat( fullname, node->classes[i] ); + } + len += 1; + } + if( node->status ) { + for( i = 0; node->status[i]; ++i ) { + strcat( fullname, ":" ); + strcat( fullname, node->status[i] ); + } + len += 1; + } + } else { + fullname = NULL; + } + if( node->fullname ) { + free( node->fullname ); + } + node->fullname = fullname; + return len; +} + LCUI_Selector Selector( const char *selector ) { const char *p; @@ -377,7 +720,12 @@ LCUI_Selector Selector( const char *selector ) LCUI_Selector s = NEW( LCUI_SelectorRec, 1 ); s->batch_num = ++batch_num; - s->list = NEW( LCUI_SelectorNode, MAX_SELECTOR_DEPTH ); + s->nodes = NEW( LCUI_SelectorNode, MAX_SELECTOR_DEPTH ); + if( !selector ) { + s->length = 0; + s->nodes[0] = NULL; + return s; + } for( ni = 0, si = 0, p = selector; *p; ++p ) { if( !node && is_saving ) { node = NEW( LCUI_SelectorNodeRec, 1 ); @@ -386,7 +734,7 @@ LCUI_Selector Selector( const char *selector ) selector ); return NULL; } - s->list[si] = node; + s->nodes[si] = node; } switch( *p ) { case ':': @@ -404,7 +752,8 @@ LCUI_Selector Selector( const char *selector ) } else { _DEBUG_MSG( "%s: invalid selector node at %ld.\n", selector, p - selector - ni ); - SelectorNode_Delete( &node ); + SelectorNode_Delete( node ); + node = NULL; } ni = 0; is_saving = TRUE; @@ -422,15 +771,17 @@ LCUI_Selector Selector( const char *selector ) is_saving = FALSE; rank = SelectorNode_Save( node, name, ni, type ); if( rank > 0 ) { - si++; - ni = 0; - node = NULL; + SelectorNode_Update( node ); s->rank += rank; + node = NULL; + ni = 0; + si++; continue; } _DEBUG_MSG( "%s: invalid selector node at %ld.\n", selector, p - selector - ni ); - SelectorNode_Delete( &node ); + SelectorNode_Delete( node ); + node = NULL; ni = 0; continue; default: break; @@ -451,502 +802,279 @@ LCUI_Selector Selector( const char *selector ) return NULL; } if( is_saving ) { - rank = SelectorNode_Save( s->list[si], name, ni, type ); + rank = SelectorNode_Save( s->nodes[si], name, ni, type ); if( rank > 0 ) { + SelectorNode_Update( s->nodes[si] ); s->rank += rank; si++; } else { - SelectorNode_Delete( &s->list[si] ); + SelectorNode_Delete( s->nodes[si] ); } } - s->list[si] = NULL; - s->length += si; + s->nodes[si] = NULL; + s->length = si; return s; } -LCUI_Selector Selector_Dup( const LCUI_Selector src ) +static void DeleteStyleNode( StyleNode node ) { - int i; - LCUI_SelectorNode new_sn, *sn_ptr, sn; - LCUI_Selector dst = NEW( LCUI_SelectorRec, 1 ); - dst->list = NEW( LCUI_SelectorNode, src->length + 1 ); - for( sn_ptr = src->list, i = 0; *sn_ptr; ++sn_ptr, ++i ) { - sn = *sn_ptr; - new_sn = NEW( LCUI_SelectorNodeRec, 1 ); - if( sn->type ) { - new_sn->type = strdup( sn->type ); - } - if( sn->id ) { - new_sn->id = strdup( sn->id ); - } - if( sn->class_name ) { - new_sn->class_name = strdup( sn->class_name ); - } - if( sn->pseudo_class_name ) { - new_sn->pseudo_class_name = strdup( sn->pseudo_class_name ); - } - dst->list[i] = new_sn; + if( node->space ) { + free( node->space ); + node->space = NULL; } - dst->list[i] = NULL; - dst->length = i; - dst->rank = src->rank; - dst->batch_num = src->batch_num; - return dst; + StyleSheet_Delete( node->sheet ); + node->sheet = NULL; } -static int mystrcmp( const char *str1, const char *str2 ) +static StyleLink CreateStyleLink( void ) { - if( str1 == str2 ) { - return 0; - } - if( str1 == NULL || str2 == NULL ) { - return -1; - } - return strcasecmp( str1, str2 ); + StyleLink link = NEW( StyleLinkRec, 1 ); + link->group = NULL; + LinkedList_Init( &link->styles ); + link->parents = Dict_Create( &DictType_StringCopyKey, NULL ); + return link; } -LCUI_BOOL Selector_Compare( LCUI_Selector s1, LCUI_Selector s2 ) +static void DeleteStyleLink( StyleLink link ) { - LCUI_SelectorNode *sn1_ptr = s1->list, *sn2_ptr = s2->list; - for( ; *sn1_ptr && *sn2_ptr; ++sn1_ptr,++sn2_ptr ) { - if( mystrcmp((*sn1_ptr)->type, (*sn2_ptr)->type) ) { - return FALSE; - } - if( mystrcmp((*sn1_ptr)->class_name, - (*sn2_ptr)->class_name) ) { - return FALSE; - } - if( mystrcmp((*sn1_ptr)->pseudo_class_name, - (*sn2_ptr)->pseudo_class_name) ) { - return FALSE; - } - if( mystrcmp((*sn1_ptr)->id, (*sn2_ptr)->id) ) { - return FALSE; - } - } - if( sn1_ptr == sn2_ptr ) { - return TRUE; - } - return FALSE; + link->group = NULL; + Dict_Release( link->parents ); + link->parents = NULL; + LinkedList_Clear( &link->styles, (FuncPtr)DeleteStyleNode ); } -static LCUI_StyleSheet SelectStyleSheetByName( LCUI_Selector selector, - const char *name ) +static void OnDeleteStyleLink( void *privdata, void *data ) { - StyleTreeNode stn; - StyleListNode sln; - LCUI_RBTreeNode *tn; + DeleteStyleLink( data ); +} + +static StyleLinkGroup CreateStyleLinkGroup( LCUI_SelectorNode snode ) +{ + DictType *dtype = NEW( DictType, 1 ); + StyleLinkGroup group = NEW( StyleLinkGroupRec, 1 ); + SelectorNode_Copy( &group->snode, snode ); + group->name = group->snode.fullname; + *dtype = DictType_StringCopyKey; + dtype->valDestructor = OnDeleteStyleLink; + group->links = Dict_Create( dtype, dtype ); + return group; +} + +static void DeleteStyleLinkGroup( StyleLinkGroup group ) +{ + free( group->name ); + Dict_Release( group->links ); + free( group->links->privdata ); + group->name = NULL; + group->links = NULL; +} + +static void OnDeleteStyleLinkGroup( void *privdata, void *data ) +{ + DeleteStyleLinkGroup( data ); +} + +static Dict *CreateStyleGroup( void ) +{ + Dict *dict; + DictType *dtype = NEW( DictType, 1 ); + *dtype = DictType_StringCopyKey; + dtype->valDestructor = OnDeleteStyleLinkGroup; + dict = Dict_Create( dtype, dtype ); + return dict; +} + +static void DeleteStyleGroup( Dict *dict ) +{ + Dict_Release( dict ); + free( dict->privdata ); + dict->privdata = NULL; +} + +/** 根据选择器,选中匹配的样式表 */ +static LCUI_StyleSheet SelectStyleSheet( LCUI_Selector selector, + const char *space ) +{ + int i, right; + StyleLink link; + StyleNode snode; + StyleLinkGroup slg; LinkedListNode *node; - int i = 0, pos = -1; - tn = RBTree_CustomSearch( &style_library.tree, (const void*)name ); - if( !tn ) { - stn = NEW( StyleTreeNodeRec, 1 ); - strncpy( stn->name, name, MAX_NAME_LEN ); - LinkedList_Init( &stn->styles ); - tn = RBTree_CustomInsert( &style_library.tree, - (const void*)name, stn ); - } - stn = tn->data; - LinkedList_ForEach( node, &stn->styles ) { - sln = node->data; - if( Selector_Compare(sln->selector, selector) ) { - return sln->style; + LCUI_SelectorNode sn; + Dict *group, *parents; + + parents = NULL; + link = NULL; + for( i = 0, right = selector->length - 1; right >= 0; --right, ++i ) { + char fullname[MAX_SELECTOR_LEN], buf[MAX_SELECTOR_LEN]; + group = LinkedList_Get( &style_library.groups, i ); + if( !group ) { + group = CreateStyleGroup(); + LinkedList_Append( &style_library.groups, group ); } - if( pos != -1 ) { - i += 1; - continue; + sn = selector->nodes[right]; + slg = Dict_FetchValue( group, sn->fullname ); + if( !slg ) { + slg = CreateStyleLinkGroup( sn ); + Dict_Add( group, sn->fullname, slg ); } - if( selector->rank > sln->selector->rank ) { - pos = i; - } else if( selector->rank == sln->selector->rank ) { - if( selector->batch_num > sln->selector->batch_num ) { - pos = i; - break; + if( i == 0 ) { + strcpy( fullname, "*" ); + } else { + if( i == 1 ) { + strcpy( fullname, sn->fullname ); + } else { + strcpy( buf, fullname ); + sprintf( fullname, "%s %s", sn->fullname, buf ); } } - i += 1; + link = Dict_FetchValue( slg->links, fullname ); + if( !link ) { + link = CreateStyleLink(); + link->group = slg; + Dict_Add( slg->links, fullname, link ); + } + /* 如果有上一级的父链接记录,则将当前链接添加进去 */ + if( parents ) { + if( !Dict_FetchValue( parents, sn->fullname ) ) { + Dict_Add( parents, sn->fullname, link ); + } + } + parents = link->parents; } - sln = NEW( StyleListNodeRec, 1 ); - sln->style = StyleSheet(); - sln->selector = Selector_Dup( selector ); - if( pos >= 0 ) { - LinkedList_Insert( &stn->styles, pos, sln ); - } else { - LinkedList_Append( &stn->styles, sln ); - } - return sln->style; -} - -static LCUI_StyleSheet SelectStyleSheet( LCUI_Selector selector ) -{ - char fullname[MAX_NAME_LEN] = ""; - LCUI_SelectorNode sn = selector->list[selector->length-1]; - if( sn->type ) { - strcat( fullname, sn->type ); - } - if( sn->id ) { - strcat( fullname, "#" ); - strcat( fullname, sn->id ); - } - if( sn->class_name ) { - strcat( fullname, "." ); - strcat( fullname, sn->class_name ); - } - if( sn->pseudo_class_name ) { - strcat( fullname, ":" ); - strcat( fullname, sn->pseudo_class_name ); - } - if( fullname[0] == 0 ) { + if( !link ) { return NULL; } - return SelectStyleSheetByName( selector, fullname ); + LinkedList_ForEach( node, &link->styles ) { + snode = node->data; + if( !space ) { + if( !snode->space ) { + return snode->sheet; + } + } else if( strcmp(snode->space, space) == 0 ) { + return snode->sheet; + } + } + snode = NEW( StyleNodeRec, 1 ); + if( space ) { + snode->space = NEW( char, strlen(space) + 1 ); + strcpy( snode->space, space ); + } else { + snode->space = NULL; + } + snode->sheet = StyleSheet(); + snode->rank = selector->rank; + snode->batch_num = selector->batch_num; + LinkedList_Append( &link->styles, snode ); + return snode->sheet; } -int LCUI_PutStyle( LCUI_Selector selector, LCUI_StyleSheet in_ss ) +int LCUI_PutStyle( LCUI_Selector selector, + LCUI_StyleSheet in_ss, const char *space ) { LCUI_StyleSheet ss; - ss = SelectStyleSheet( selector ); + ss = SelectStyleSheet( selector, space ); if( ss ) { StyleSheet_Replace( ss, in_ss ); } return 0; } -LCUI_BOOL Selector_MatchPath( LCUI_Selector selector, LCUI_Widget *wlist ) +static int StyleLink_GetStyleSheets( StyleLink link, LinkedList *outlist ) { - int i, n; - LCUI_Widget *obj_ptr = wlist, w; - LCUI_SelectorNode sn, *sn_ptr = selector->list; - /* 定位到最后一个元素 */ - sn_ptr += selector->length-1; - for( ;*obj_ptr; ++obj_ptr ); - --obj_ptr; - /* 从右到左遍历,进行匹配 */ - for( ; obj_ptr >= wlist && sn_ptr >= selector->list; --obj_ptr ) { - w = *obj_ptr; - sn = *sn_ptr; - if( sn->id ) { - if( !w->id || strcmp( w->id, sn->id ) ) { - continue; - } - } - if( sn->type && strcmp("*", sn->type) ) { - if( !w->type || strcmp( w->type, sn->type ) ) { - continue; - } - } - if( sn->class_name ) { - n = ptrslen( w->classes ); - for( i = 0; i < n; ++i ) { - if( strcmp( w->classes[i], - sn->class_name ) == 0 ) { - break; - } - } - if( i >= n ) { - continue; - } - } - if( sn->pseudo_class_name ) { - n = ptrslen( w->status ); - for( i = 0; i < n; ++i ) { - if( strcmp( w->status[i], - sn->pseudo_class_name ) == 0 ) { - break; - } - } - if( i >= n ) { - continue; - } - } - --sn_ptr; - } - /* 匹配成功的标志是遍历完选择器列表 */ - if( sn_ptr < selector->list ) { - return TRUE; - } - return FALSE; -} + StyleNode snode, out_snode; + LinkedListNode *node, *out_node; -static int InsertStyleSheet( LinkedList *list, LCUI_Selector s, - LCUI_StyleSheet ss ) -{ - int pos = -1, i = 0; - StyleListNode pack; - LinkedListNode *node; - LinkedList_ForEach( node, list ) { - pack = node->data; - if( s->rank > pack->selector->rank ) { - pos = i; - break; - } else if( s->rank == pack->selector->rank ) { - if( s->batch_num > pack->selector->batch_num ) { + if( !outlist ) { + return link->styles.length; + } + LinkedList_ForEach( node, &link->styles ) { + int pos = -1, i = 0; + snode = node->data; + LinkedList_ForEach( out_node, outlist ) { + out_snode = out_node->data; + if( snode->rank > out_snode->rank ) { pos = i; break; } + if( snode->rank != out_snode->rank ) { + i += 1; + continue; + } + if( snode->batch_num > out_snode->batch_num ) { + pos = i; + break; + } + i += 1; + } + if( pos >= 0 ) { + LinkedList_Insert( outlist, pos, snode ); + } else { + LinkedList_Append( outlist, snode ); } - i += 1; } - pack = NEW( StyleListNodeRec, 1 ); - pack->selector = s; - pack->style = ss; - if( pos >= 0 ) { - LinkedList_Insert( list, pos, pack ); - } else { - LinkedList_Append( list, pack ); - } - return pos; + return link->styles.length; } -static int FindStyleNodeByName( const char *name, LCUI_Widget widget, - LinkedList *list ) +static int FindStyleSheetFromLink( StyleLink link, LCUI_Selector s, + int i, LinkedList *list ) { - int n, count = 0; - StyleListNode sln; - LinkedList *styles; - LCUI_RBTreeNode *tn; + int count = 0; + StyleLink parent; + LinkedList names; LinkedListNode *node; - LCUI_Widget w, wlist[MAX_SELECTOR_DEPTH]; - tn = RBTree_CustomSearch( &style_library.tree, (const void*)name ); - if( !tn ) { + LCUI_SelectorNode sn; + + LinkedList_Init( &names ); + count += StyleLink_GetStyleSheets( link, list ); + while( --i >= 0 ) { + sn = s->nodes[i]; + SelectorNode_GetNames( sn, &names ); + LinkedList_ForEach( node, &names ) { + parent = Dict_FetchValue( link->parents, node->data ); + if( !parent ) { + continue; + } + count += FindStyleSheetFromLink( parent, s, i, list ); + } + LinkedList_Clear( &names, free ); + } + return count; +} + +static int FindStyleSheetFromGroup( int group, LCUI_Selector s, + LinkedList *list ) +{ + int i, count; + Dict *groups; + StyleLinkGroup slg; + LinkedListNode *node; + LinkedList names; + + groups = LinkedList_Get( &style_library.groups, group ); + if( !groups ) { return 0; } - for( n = 0, w = widget; w; ++n, w = w->parent ); - if( n >= MAX_SELECTOR_DEPTH ) { - return -1; - } - if( n == 0 ) { - wlist[0] = NULL; - } else { - w = widget; - wlist[n] = NULL; - while( --n >= 0 ) { - wlist[n] = w; - w = w->parent; - } - } - styles = &((StyleTreeNode)tn->data)->styles; - LinkedList_ForEach( node, styles ) { - sln = node->data; - /* 如果当前元素在该样式结点的作用范围内 */ - if( !Selector_MatchPath( sln->selector, wlist ) ) { + count = 0; + i = s->length - 1; + LinkedList_Init( &names ); + SelectorNode_GetNames( s->nodes[i], &names ); + LinkedList_Append( &names, strdup( "*" ) ); + LinkedList_ForEach( node, &names ) { + DictEntry *entry; + DictIterator *iter; + char *name = node->data; + slg = Dict_FetchValue( groups, name ); + if( !slg ) { continue; } - InsertStyleSheet( list, sln->selector, sln->style ); - ++count; - } - return count; -} - -/** 从小到大,排序名称列表 */ -static void SortNames( char **names, LinkedList *outnames ) -{ - char *name; - int i, len; - LinkedListNode *node; - len = ptrslen( names ); - while( --len >= 0 ) { - i = 0; - name = names[len]; - LinkedList_ForEach( node, outnames ) { - if( strcmp(name, node->data) > 0 ) { - ++i; - continue; - } - LinkedList_Insert( outnames, i, name ); - break; - } - if( i >= outnames->length ) { - LinkedList_Append( outnames, name ); + iter = Dict_GetIterator( slg->links ); + while( entry = Dict_Next( iter ) ) { + StyleLink link = DictEntry_GetVal( entry ); + count += FindStyleSheetFromLink( link, s, i, list ); } } -} - -/** 初始化样式表查找器 */ -static void StyleSheetFinder_Init( StyleSheetFinder sfinder, LCUI_Widget w ) -{ - sfinder->level = 0; - sfinder->class_i = 0; - sfinder->name_i = 0; - sfinder->status_i = 0; - sfinder->name[0] = 0; - sfinder->widget = w; - LinkedList_Init( &sfinder->classes ); - LinkedList_Init( &sfinder->status ); - SortNames( w->classes, &sfinder->classes ); - SortNames( w->status, &sfinder->status ); -} - -/** 销毁样式表查找器 */ -static void StyleSheetFinder_Destroy( StyleSheetFinder sfinder ) -{ - sfinder->name_i = 0; - sfinder->name[0] = 0; - sfinder->class_i = 0; - sfinder->status_i = 0; - sfinder->widget = NULL; - sfinder->level = LEVEL_NONE; - LinkedList_Clear( &sfinder->classes, NULL ); - LinkedList_Clear( &sfinder->status, NULL ); -} - -/* 查找匹配的样式表 */ -int StyleSheetFinder_Find( StyleSheetFinder sfinder, LinkedList *list ) -{ - LinkedListNode *node; - int i, len, old_len, old_level, count = 0; - char *fullname = sfinder->name + sfinder->name_i; - old_len = len = strlen( fullname ); - old_level = sfinder->level; - switch( sfinder->level ) { - case LEVEL_TYPE: - /* 按类型选择器搜索样式表 */ - if( !sfinder->widget->type ) { - return 0; - } - strcpy( fullname, sfinder->widget->type ); - count = FindStyleNodeByName( fullname, sfinder->widget, list ); - break; - case LEVEL_ID: - /* 按ID选择器搜索样式表 */ - if( !sfinder->widget->id ) { - return 0; - } - fullname[len++] = '#'; - strcpy( fullname + len, sfinder->widget->id ); - count = FindStyleNodeByName( fullname, sfinder->widget, list ); - fullname[old_len] = 0; - break; - case LEVEL_CLASS: - /* 按类选择器搜索样式表 - * 假设当前选择器全名为:textview#main-btn-text,且有 .a .b .c - * 这三个类,那么下面的处理将会拆分成以下三个选择器来匹配样式表: - * textview#test-text.a - * textview#test-text.b - * textview#test-text.a - */ - fullname[len++] = '.'; - LinkedList_ForEach( node, &sfinder->classes ) { - strcpy( fullname + len, node->data ); - count += FindStyleNodeByName( fullname, - sfinder->widget, list ); - /* 将当前选择器名与其它层级的选择器名组合 */ - for( i = sfinder->level + 1; i < LEVEL_TOTAL_NUM; ++i ) { - sfinder->level = i; - count += StyleSheetFinder_Find( sfinder, list ); - } - sfinder->level = LEVEL_CLASS; - sfinder->class_i += 1; - } - sfinder->level = LEVEL_CLASS; - fullname[old_len] = 0; - sfinder->class_i = 0; - return count; - case LEVEL_CLASS_2: - /* 按类选择器搜索交集样式表,结果类似于这样: - * textview#test-text.a.b - * textview#test-text.a.c - * textview#test-text.b.c - * textview#test-text.a.b.c - */ - i = 0; - fullname[len++] = '.'; - LinkedList_ForEach( node, &sfinder->classes ) { - if( i <= sfinder->class_i ) { - i += 1; - continue; - } - strcpy( fullname + len, node->data ); - count += FindStyleNodeByName( fullname, - sfinder->widget, list ); - sfinder->class_i += 1; - count += StyleSheetFinder_Find( sfinder, list ); - sfinder->class_i -= 1; - sfinder->level = LEVEL_STATUS; - /** - * 递归拼接伪类名,例如: - * textview#main-btn-text:active - */ - count += StyleSheetFinder_Find( sfinder, list ); - sfinder->level = LEVEL_CLASS_2; - i += 1; - } - fullname[old_len] = 0; - sfinder->level = LEVEL_CLASS_2; - return count; - case LEVEL_STATUS: - fullname[len++] = ':'; - sfinder->level = LEVEL_STATUS_2; - /** - * 按伪类选择器搜索样式表 - * 假设当前选择器全名为:textview#main-btn-text:hover:focus:active - * 那么下面的循环会将它拆分为以下几个选择器来匹配样式: - * textview#main-btn-text:active - * textview#main-btn-text:active:focus - * textview#main-btn-text:active:focus:hover - * textview#main-btn-text:active:hover - * textview#main-btn-text:focus - * textview#main-btn-text:focus:hover - * textview#main-btn-text:hover - */ - LinkedList_ForEach( node, &sfinder->status ) { - strcpy( fullname + len, node->data ); - count += FindStyleNodeByName( fullname, - sfinder->widget, list ); - /** - * 递归调用,以一层层拼接出像下面这样的选择器: - * textview#main-btn-text:active:focus:hover - */ - count += StyleSheetFinder_Find( sfinder, list ); - sfinder->status_i += 1; - } - sfinder->level = LEVEL_STATUS; - fullname[old_len] = 0; - sfinder->status_i = 0; - return count; - case LEVEL_STATUS_2: - /** 按伪类选择器搜索交集样式表 */ - i = 0; - LinkedList_ForEach( node, &sfinder->status ) { - if( i <= sfinder->status_i ) { - i += 1; - continue; - } - fullname[len] = ':'; - strcpy( fullname + len + 1, node->data ); - count += FindStyleNodeByName( fullname, - sfinder->widget, list ); - sfinder->status_i += 1; - count += StyleSheetFinder_Find( sfinder, list ); - sfinder->status_i -= 1; - i += 1; - } - fullname[old_len] = 0; - return count; - default:break; - } - for( i = sfinder->level + 1; i < LEVEL_TOTAL_NUM; ++i ) { - if( i == LEVEL_STATUS_2 || i == LEVEL_CLASS_2 ) { - continue; - } - sfinder->level = i; - count += StyleSheetFinder_Find( sfinder, list ); - } - fullname[old_len] = 0; - sfinder->level = old_level; - return count; -} - -/** 查找样式数据节点 */ -static int FindStyleNode( LCUI_Widget w, LinkedList *list ) -{ - int count; - StyleSheetFinderRec sfinder; - StyleSheetFinder_Init( &sfinder, w ); - count = StyleSheetFinder_Find( &sfinder, list ); - StyleSheetFinder_Destroy( &sfinder ); - /* 记录作用于全局元素的样式表 */ - count += FindStyleNodeByName( "*", w, list ); + LinkedList_Clear( &names, free ); return count; } @@ -961,46 +1089,47 @@ void LCUI_PrintStyleSheet( LCUI_StyleSheet ss ) } name = GetStyleName(key); if( name ) { - printf( "\t\t%s", name ); + printf( "\t%s", name ); } else { - printf( "\t\t", key); + printf( "\t", key); } printf( "%s: ", key > STYLE_KEY_TOTAL ? " (+)" : "" ); switch( s->type ) { case SVT_AUTO: - printf( "auto\n"); + printf( "auto"); break; case SVT_BOOL: { - printf( "%s\n", s->val_bool ? "true" : "false" ); + printf( "%s", s->val_bool ? "true" : "false" ); break; } case SVT_COLOR: { LCUI_Color *clr = &s->val_color; if( clr->alpha < 255 ) { - printf("rgba(%d,%d,%d,%0.2f)\n", clr->r, + printf("rgba(%d,%d,%d,%0.2f)", clr->r, clr->g, clr->b, clr->a / 255.0); } else { - printf("#%02x%02x%02x\n", clr->r, clr->g, clr->b); + printf("#%02x%02x%02x", clr->r, clr->g, clr->b); } break; } case SVT_PX: - printf("%dpx\n", s->val_px); + printf("%dpx", s->val_px); break; case SVT_STRING: - printf("%s\n", s->val_string); + printf("%s", s->val_string); break; case SVT_SCALE: - printf("%.2lf%%\n", s->val_scale*100); + printf("%.2lf%%", s->val_scale*100); break; case SVT_STYLE:{ - printf("%s\n", GetStyleOptionName( s->val_style )); + printf("%s", GetStyleOptionName( s->val_style )); break; } default: - printf("%d\n", s->value); + printf("%d", s->value); break; } + printf( ";\n"); } } @@ -1010,63 +1139,135 @@ void LCUI_PrintSelector( LCUI_Selector selector ) LCUI_SelectorNode *sn; path[0] = 0; - for( sn = selector->list; *sn; ++sn ) { - if( (*sn)->id ) { - strcat( path, "#" ); - strcat( path, (*sn)->id ); - } - if( (*sn)->type ) { - strcat( path, (*sn)->type ); - } - if( (*sn)->class_name ) { - strcat( path, "." ); - strcat( path, (*sn)->class_name ); - } - if( (*sn)->pseudo_class_name ) { - strcat( path, ":" ); - strcat( path, (*sn)->pseudo_class_name ); - } + for( sn = selector->nodes; *sn; ++sn ) { + strcat( path, (*sn)->fullname ); strcat( path, " " ); } printf("\tpath: %s (rank = %d, batch_num = %d)\n", path, selector->rank, selector->batch_num); } -void LCUI_PrintStyleLibrary(void) +static void LCUI_PrintStyleLink( StyleLink link, const char *selector ) { - LCUI_RBTreeNode *tn; + DictEntry *entry; + DictIterator *iter; LinkedListNode *node; - StyleTreeNode stn; - StyleListNode sln; - - printf("style library begin\n"); - tn = RBTree_First( &style_library.tree ); - while( tn ) { - stn = tn->data; - printf("target: %s\n", stn->name); - LinkedList_ForEach( node, &stn->styles ) { - sln = node->data; - LCUI_PrintSelector( sln->selector ); - LCUI_PrintStyleSheet( sln->style ); - } - tn = RBTree_Next( tn ); + char fullname[MAX_SELECTOR_LEN]; + if( selector ) { + sprintf( fullname, "%s %s", link->group->name, selector ); + } else { + strcpy( fullname, link->group->name ); } - printf("style library end\n"); + LinkedList_ForEach( node, &link->styles ) { + StyleNode snode = node->data; + printf("\n[%s]\n", snode->space ? snode->space:""); + printf("%s {\n", fullname); + LCUI_PrintStyleSheet( snode->sheet ); + printf("}\n"); + } + iter = Dict_GetIterator( link->parents ); + while( entry = Dict_Next( iter ) ) { + StyleLink parent = DictEntry_GetVal( entry ); + LCUI_PrintStyleLink( parent, fullname ); + } + Dict_ReleaseIterator( iter ); +} + +void LCUI_PrintStyleLibrary( void ) +{ + Dict *group; + StyleLink link; + StyleLinkGroup slg; + DictIterator *iter; + DictEntry *entry; + + link = NULL; + printf( "style library begin\n" ); + group = LinkedList_Get( &style_library.groups, 0 ); + iter = Dict_GetIterator( group ); + while( entry = Dict_Next(iter) ) { + DictEntry *entry_slg; + DictIterator *iter_slg; + slg = DictEntry_GetVal( entry ); + iter_slg = Dict_GetIterator( slg->links ); + while( entry_slg = Dict_Next(iter_slg) ) { + link = DictEntry_GetVal( entry_slg ); + LCUI_PrintStyleLink( link, NULL ); + } + Dict_ReleaseIterator( iter_slg ); + } + Dict_ReleaseIterator( iter ); + printf( "style library end\n" ); +} + +LCUI_Selector Widget_GetSelector( LCUI_Widget w ) +{ + int ni = 0; + LinkedList list; + LCUI_Selector s; + LCUI_Widget parent; + LinkedListNode *node; + s = Selector( NULL ); + LinkedList_Init( &list ); + for( parent = w; parent; parent = parent->parent ) { + if( parent->id || parent->type || + parent->classes || parent->status ) { + LinkedList_Append( &list, parent ); + } + } + if( list.length >= MAX_SELECTOR_DEPTH ) { + LinkedList_Clear( &list, NULL ); + Selector_Delete( s ); + return NULL; + } + LinkedList_ForEachReverse( node, &list ) { + int i; + LCUI_SelectorNode sn; + parent = node->data; + sn = NEW( LCUI_SelectorNodeRec, 1 ); + if( parent->id ) { + sn->id = strdup( parent->id ); + } + if( parent->type ) { + sn->type = strdup( parent->type ); + } + if( parent->classes ) { + for( i = 0; parent->classes[i]; ++i ) { + SortedStrList_Add( &sn->classes, + parent->classes[i] ); + } + } + if( parent->status ) { + for( i = 0; parent->status[i]; ++i ) { + SortedStrList_Add( &sn->status, + parent->status[i] ); + } + } + SelectorNode_Update( sn ); + s->nodes[ni] = sn; + s->rank += sn->rank; + ni += 1; + } + LinkedList_Clear( &list, NULL ); + s->nodes[ni] = NULL; + s->length = ni; + return s; } int Widget_ComputeInheritStyle( LCUI_Widget w, LCUI_StyleSheet out_ss ) { + LCUI_Selector s; LinkedList list; - StyleListNode sln; LinkedListNode *node; LinkedList_Init( &list ); - FindStyleNode( w, &list ); StyleSheet_Clear( out_ss ); + s = Widget_GetSelector( w ); + FindStyleSheet( s, &list ); LinkedList_ForEach( node, &list ) { - sln = node->data; - StyleSheet_Merge( out_ss, sln->style ); + StyleNode sn = node->data; + StyleSheet_Merge( out_ss, sn->sheet ); } - LinkedList_Clear( &list, free ); + LinkedList_Clear( &list, NULL ); return 0; } @@ -1092,6 +1293,7 @@ void Widget_ExecUpdateStyle( LCUI_Widget w, LCUI_BOOL is_update_all ) TaskMap task_map[] = { { key_display_start, key_display_end, WTT_VISIBLE, TRUE }, { key_opacity, key_opacity, WTT_OPACITY, TRUE }, + { key_z_index, key_z_index, WTT_ZINDEX, TRUE }, { key_width, key_height, WTT_RESIZE, TRUE }, { key_padding_top, key_padding_left, WTT_RESIZE, TRUE }, { key_position_start, key_position_end, WTT_POSITION, TRUE }, @@ -1135,3 +1337,18 @@ void Widget_ExecUpdateStyle( LCUI_Widget w, LCUI_BOOL is_update_all ) wc && wc->methods.update ? wc->methods.update( w ) : 0; } } + +void LCUIWidget_ExitStyle( void ) +{ + LinkedList_Clear( &style_library.groups, (FuncPtr)DeleteStyleGroup ); + style_library.is_inited = FALSE; + LCUICSS_Destroy(); +} + +void LCUIWidget_InitStyle( void ) +{ + LinkedList_Init( &style_library.groups ); + LCUICSS_Init(); + LCUICSS_LoadString( global_css, NULL ); + style_library.is_inited = TRUE; +} From 10c2a61457d0220697507bbc13084e41f6b4fb41 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Mon, 1 Aug 2016 23:49:35 +0800 Subject: [PATCH 090/124] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=B2=E5=88=86=E5=89=B2=E5=87=BD=E6=95=B0=20strsplit()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/util/string.h | 11 +++++++++ src/util/string.c | 48 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/include/LCUI/util/string.h b/include/LCUI/util/string.h index 1948c62c..01cbd6c5 100644 --- a/include/LCUI/util/string.h +++ b/include/LCUI/util/string.h @@ -71,6 +71,17 @@ LCUI_BEGIN_HEADER */ LCUI_API int strtrim( char *outstr, const char *instr, const char *charlist ); +/** + * 分割字符串 + * @param[in] instr 需分割的字符串 + * @param[in] sep 分割标记字符串 + * @param[out] outstrs 分割后的字符串列表 + */ +LCUI_API int strsplit( const char *instr, const char *sep, char ***outstrs ); + +/** 释放字符串组 */ +void freestrs( char **strs ); + LCUI_END_HEADER #endif diff --git a/src/util/string.c b/src/util/string.c index 6926c7c8..9c54c1a5 100644 --- a/src/util/string.c +++ b/src/util/string.c @@ -79,3 +79,51 @@ int strtrim( char *outstr, const char *instr, const char *charlist ) *op = 0; return op - outstr; } + +void freestrs( char **strs ) +{ + int i = 0; + while( strs[i] ) { + free( strs[i] ); + ++i; + } + free( strs ); +} + +int strsplit( const char *instr, const char *sep, char ***outstrs ) +{ + int len, i = 0; + const char *prev = instr; + int sep_len = strlen( sep ); + char *next = strstr( prev, sep ); + char **newstrs = NULL; + + while( 1 ) { + char **tmp, *str; + if( next ) { + len = next - prev + 1; + } else { + len = strlen( prev ) + 1; + } + str = malloc( sizeof( char ) * len ); + tmp = realloc( newstrs, sizeof( char* ) * (i + 2) ); + if( !tmp ) { + freestrs( newstrs ); + return 0; + } + newstrs = tmp; + strncpy( str, prev, len - 1 ); + str[len - 1] = 0; + newstrs[i] = str; + newstrs[i + 1] = NULL; + if( next ) { + prev = next + sep_len; + } else { + break; + } + next = strstr( prev, sep ); + i += 1; + } + *outstrs = newstrs; + return i + 1; +} From a7aa013189b59d02c3727636a764caf72a6d80e2 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Mon, 1 Aug 2016 23:51:21 +0800 Subject: [PATCH 091/124] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20Widget=5FHandleChi?= =?UTF-8?q?ldrenStyleChange()=20=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/gui/widget_style.h | 3 ++ src/gui/widget_base.c | 17 +++---- src/gui/widget_style.c | 89 +++++++++++++++++++++++++++++---- 3 files changed, 90 insertions(+), 19 deletions(-) diff --git a/include/LCUI/gui/widget_style.h b/include/LCUI/gui/widget_style.h index c72ad505..92554129 100644 --- a/include/LCUI/gui/widget_style.h +++ b/include/LCUI/gui/widget_style.h @@ -102,6 +102,9 @@ LCUI_API int Widget_FindStyles( LCUI_Widget w, LinkedList *list ); /** 获取选择器 */ LCUI_API LCUI_Selector Widget_GetSelector( LCUI_Widget w ); +/** 处理子级部件样式变化 */ +LCUI_API int Widget_HandleChildrenStyleChange( LCUI_Widget w, int type, char *name ); + #include #endif diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index 4f956f82..89a178d1 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -1336,8 +1336,7 @@ int Widget_AddClass( LCUI_Widget w, const char *class_name ) if( StrList_Add(&w->classes, class_name) <= 0 ) { return 0; } - /* 标记需要更新该部件及子级部件的样式表 */ - Widget_AddTaskForChildren( w, WTT_REFRESH_STYLE ); + Widget_HandleChildrenStyleChange( w, 0, class_name ); Widget_UpdateStyle( w, TRUE ); return 1; } @@ -1351,10 +1350,10 @@ LCUI_BOOL Widget_HasClass( LCUI_Widget w, const char *class_name ) /** 从部件中移除一个类 */ int Widget_RemoveClass( LCUI_Widget w, const char *class_name ) { - if( StrList_Remove( &w->classes, class_name ) <= 0 ) { - return 0; + if( StrList_Has( w->classes, class_name ) ) { + Widget_HandleChildrenStyleChange( w, 0, class_name ); } - Widget_AddTaskForChildren( w, WTT_REFRESH_STYLE ); + StrList_Remove( &w->classes, class_name ); Widget_UpdateStyle( w, TRUE ); return 1; } @@ -1369,7 +1368,7 @@ int Widget_AddStatus( LCUI_Widget w, const char *status_name ) return 0; } Widget_UpdateStyle( w, TRUE ); - Widget_AddTaskForChildren( w, WTT_REFRESH_STYLE ); + Widget_HandleChildrenStyleChange( w, 1, status_name ); return 1; } @@ -1382,11 +1381,11 @@ LCUI_BOOL Widget_HasStatus( LCUI_Widget w, const char *status_name ) /** 从部件中移除一个状态 */ int Widget_RemoveStatus( LCUI_Widget w, const char *status_name ) { - if( StrList_Remove( &w->status, status_name ) != 1 ) { - return 0; + if( StrList_Has( w->status, status_name ) ) { + Widget_HandleChildrenStyleChange( w, 1, status_name ); } + StrList_Remove( &w->status, status_name ); Widget_UpdateStyle( w, TRUE ); - Widget_AddTaskForChildren( w, WTT_REFRESH_STYLE ); return 1; } diff --git a/src/gui/widget_style.c b/src/gui/widget_style.c index 4058dff9..35d27881 100644 --- a/src/gui/widget_style.c +++ b/src/gui/widget_style.c @@ -50,7 +50,7 @@ #define MAX_NODE_DEPTH 32 #define MAX_SELECTOR_DEPTH 32 -#define FindStyleSheet(S, L) FindStyleSheetFromGroup(0, S, L) +#define FindStyleSheet(S, L) FindStyleSheetFromGroup(0, NULL, S, L) enum SelectorRank { GENERAL_RANK = 0, @@ -466,9 +466,9 @@ static int NamesFinder_Find( NamesFinder sfinder, LinkedList *list ) return 0; } fullname[len++] = '#'; + fullname[len] = 0; strcpy( fullname + len, sfinder->node->id ); LinkedList_Append( list, strdup( fullname ) ); - fullname[old_len] = 0; break; case LEVEL_CLASS: if( !sfinder->node->classes ) { @@ -947,12 +947,14 @@ static LCUI_StyleSheet SelectStyleSheet( LCUI_Selector selector, } LinkedList_ForEach( node, &link->styles ) { snode = node->data; - if( !space ) { - if( !snode->space ) { + if( snode->space && space ) { + if( strcmp( snode->space, space ) == 0 ) { + return snode->sheet; + } + } else { + if( snode->space == space ) { return snode->sheet; } - } else if( strcmp(snode->space, space) == 0 ) { - return snode->sheet; } } snode = NEW( StyleNodeRec, 1 ); @@ -1042,8 +1044,15 @@ static int FindStyleSheetFromLink( StyleLink link, LCUI_Selector s, return count; } -static int FindStyleSheetFromGroup( int group, LCUI_Selector s, - LinkedList *list ) +/** + * 从指定组中查找样式表 + * @param[in] group 组号 + * @param[in] name 选择器结点名称,若为 NULL,则根据选择器结点生成名称 + * @param[in] s 选择器 + * @param[out] list 找到的样式表列表 + */ +static int FindStyleSheetFromGroup( int group, const char *name, + LCUI_Selector s, LinkedList *list ) { int i, count; Dict *groups; @@ -1058,8 +1067,12 @@ static int FindStyleSheetFromGroup( int group, LCUI_Selector s, count = 0; i = s->length - 1; LinkedList_Init( &names ); - SelectorNode_GetNames( s->nodes[i], &names ); - LinkedList_Append( &names, strdup( "*" ) ); + if( name ) { + LinkedList_Append( &names, strdup( name ) ); + } else { + SelectorNode_GetNames( s->nodes[i], &names ); + LinkedList_Append( &names, strdup( "*" ) ); + } LinkedList_ForEach( node, &names ) { DictEntry *entry; DictIterator *iter; @@ -1254,6 +1267,62 @@ LCUI_Selector Widget_GetSelector( LCUI_Widget w ) return s; } +int Widget_HandleChildrenStyleChange( LCUI_Widget w, int type, char *name ) +{ + LCUI_Selector s; + LinkedList snames; + LinkedListNode *node; + int i, n, count = 0; + char ch, **names = NULL; + + /* 选择相应的前缀 */ + switch( type ) { + case 0: ch = '.'; + case 1: ch = ':'; break; + default: return 0; + } + LinkedList_Init( &snames ); + s = Widget_GetSelector( w ); + n = strsplit( name, " ", &names ); + /* 为分割出来的字符串加上前缀 */ + for( i = 0; i < n; ++i ) { + int len = strlen( names[i] ) + 2; + char *str = malloc( len * sizeof( char ) ); + strncpy( str + 1, names[i], len - 1 ); + str[0] = ch; + free( names[i] ); + names[i] = str; + } + SelectorNode_GetNames( s->nodes[s->length - 1], &snames ); + LinkedList_ForEach( node, &snames ) { + char *sname = node->data; + /* 过滤掉不包含 name 中存在的名称 */ + for( i = 0; i < n; ++i ) { + char *p = strstr( sname, names[i] ); + if( p ) { + p += strlen( names[i] ); + switch( *p ) { + case 0: + case ':': + case '.': break; + default: continue; + } + break; + } + } + if( i < n ) { + count += FindStyleSheetFromGroup( 1, sname, s, NULL ); + } + } + Selector_Delete( s ); + /* 若子部件的样式受到了影响,则标记子部件需要刷新 */ + if( count > 0 ) { + Widget_AddTaskForChildren( w, WTT_REFRESH_STYLE ); + } + freestrs( names ); + return count; +} + int Widget_ComputeInheritStyle( LCUI_Widget w, LCUI_StyleSheet out_ss ) { LCUI_Selector s; From 55c5b450491600cadbc867ea39ad89b6d9bb2a43 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Wed, 10 Aug 2016 00:27:36 +0800 Subject: [PATCH 092/124] =?UTF-8?q?=E7=BA=A0=E6=AD=A3=20CSS=20=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=AE=B0=E5=BD=95=E6=93=8D=E4=BD=9C=EF=BC=8C=E8=A7=A3?= =?UTF-8?q?=E5=86=B3=E6=97=A0=E6=B3=95=E6=AD=A3=E5=B8=B8=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E5=88=B0=E6=A0=B7=E5=BC=8F=E8=A1=A8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/gui/widget_style.h | 2 +- src/gui/widget_style.c | 34 +++++++++++++++++++++------------ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/include/LCUI/gui/widget_style.h b/include/LCUI/gui/widget_style.h index 92554129..bed209b7 100644 --- a/include/LCUI/gui/widget_style.h +++ b/include/LCUI/gui/widget_style.h @@ -103,7 +103,7 @@ LCUI_API int Widget_FindStyles( LCUI_Widget w, LinkedList *list ); LCUI_API LCUI_Selector Widget_GetSelector( LCUI_Widget w ); /** 处理子级部件样式变化 */ -LCUI_API int Widget_HandleChildrenStyleChange( LCUI_Widget w, int type, char *name ); +LCUI_API int Widget_HandleChildrenStyleChange( LCUI_Widget w, int type, const char *name ); #include diff --git a/src/gui/widget_style.c b/src/gui/widget_style.c index 35d27881..afdc5d9e 100644 --- a/src/gui/widget_style.c +++ b/src/gui/widget_style.c @@ -93,11 +93,13 @@ typedef struct StyleNodeRec_ { int rank; /**< 权值,决定优先级 */ int batch_num; /**< 批次号 */ char *space; /**< 所属的空间 */ + char *selector; /**< 选择器 */ LCUI_StyleSheet sheet; /**< 样式表 */ } StyleNodeRec, *StyleNode; /** 样式链接记录 */ typedef struct StyleLinkRec_ { + char *selector; /**< 选择器 */ StyleLinkGroup group; /**< 所属组 */ LinkedList styles; /**< 作用于当前选择器的样式 */ Dict *parents; /**< 父级节点 */ @@ -822,6 +824,10 @@ static void DeleteStyleNode( StyleNode node ) free( node->space ); node->space = NULL; } + if( node->selector ) { + free( node->selector ); + node->selector = NULL; + } StyleSheet_Delete( node->sheet ); node->sheet = NULL; } @@ -902,11 +908,12 @@ static LCUI_StyleSheet SelectStyleSheet( LCUI_Selector selector, LinkedListNode *node; LCUI_SelectorNode sn; Dict *group, *parents; + char buf[MAX_SELECTOR_LEN]; + char fullname[MAX_SELECTOR_LEN]; - parents = NULL; link = NULL; + parents = NULL; for( i = 0, right = selector->length - 1; right >= 0; --right, ++i ) { - char fullname[MAX_SELECTOR_LEN], buf[MAX_SELECTOR_LEN]; group = LinkedList_Get( &style_library.groups, i ); if( !group ) { group = CreateStyleGroup(); @@ -921,19 +928,21 @@ static LCUI_StyleSheet SelectStyleSheet( LCUI_Selector selector, if( i == 0 ) { strcpy( fullname, "*" ); } else { - if( i == 1 ) { - strcpy( fullname, sn->fullname ); - } else { - strcpy( buf, fullname ); - sprintf( fullname, "%s %s", sn->fullname, buf ); - } + strcpy( fullname, buf ); } link = Dict_FetchValue( slg->links, fullname ); if( !link ) { link = CreateStyleLink(); link->group = slg; + link->selector = strdup( fullname ); Dict_Add( slg->links, fullname, link ); } + if( i == 0 ) { + strcpy( buf, sn->fullname ); + } else { + strcpy( fullname, buf ); + sprintf( buf, "%s %s", sn->fullname, fullname ); + } /* 如果有上一级的父链接记录,则将当前链接添加进去 */ if( parents ) { if( !Dict_FetchValue( parents, sn->fullname ) ) { @@ -966,6 +975,7 @@ static LCUI_StyleSheet SelectStyleSheet( LCUI_Selector selector, } snode->sheet = StyleSheet(); snode->rank = selector->rank; + snode->selector = strdup( fullname ); snode->batch_num = selector->batch_num; LinkedList_Append( &link->styles, snode ); return snode->sheet; @@ -1148,7 +1158,7 @@ void LCUI_PrintStyleSheet( LCUI_StyleSheet ss ) void LCUI_PrintSelector( LCUI_Selector selector ) { - char path[256]; + char path[MAX_SELECTOR_LEN]; LCUI_SelectorNode *sn; path[0] = 0; @@ -1156,7 +1166,7 @@ void LCUI_PrintSelector( LCUI_Selector selector ) strcat( path, (*sn)->fullname ); strcat( path, " " ); } - printf("\tpath: %s (rank = %d, batch_num = %d)\n", path, + printf("path: %s (rank = %d, batch_num = %d)\n", path, selector->rank, selector->batch_num); } @@ -1267,7 +1277,7 @@ LCUI_Selector Widget_GetSelector( LCUI_Widget w ) return s; } -int Widget_HandleChildrenStyleChange( LCUI_Widget w, int type, char *name ) +int Widget_HandleChildrenStyleChange( LCUI_Widget w, int type, const char *name ) { LCUI_Selector s; LinkedList snames; @@ -1277,7 +1287,7 @@ int Widget_HandleChildrenStyleChange( LCUI_Widget w, int type, char *name ) /* 选择相应的前缀 */ switch( type ) { - case 0: ch = '.'; + case 0: ch = '.'; break; case 1: ch = ':'; break; default: return 0; } From f579d0f8704579055147c6cded35679f1474730e Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Wed, 10 Aug 2016 00:30:09 +0800 Subject: [PATCH 093/124] =?UTF-8?q?click=20=E4=BA=8B=E4=BB=B6=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E4=BB=85=E5=9C=A8=E5=B7=A6=E9=94=AE=E6=8C=89=E4=B8=8B?= =?UTF-8?q?=E5=90=8E=E8=A7=A6=E5=8F=91=E3=80=81=E8=B0=83=E6=95=B4=E9=83=A8?= =?UTF-8?q?=E5=88=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/font/textlayer.c | 2 +- src/gui/widget_base.c | 14 ++++++++------ src/gui/widget_event.c | 6 ++++-- src/gui/widget_task.c | 3 ++- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/font/textlayer.c b/src/font/textlayer.c index 1249e0d3..522efc70 100644 --- a/src/font/textlayer.c +++ b/src/font/textlayer.c @@ -49,7 +49,7 @@ enum TextAddType { TAT_APPEND /**< 追加至文本末尾 */ }; - +#undef max #define max(a, b) ((a) > (b) ? (a):(b)) #define TextRowList_AddNewRow(ROWLIST) TextRowList_InsertNewRow(ROWLIST, (ROWLIST)->length) #define TextLayer_GetRow(layer, n) (n >= layer->rowlist.length) ? NULL:layer->rowlist.rows[n] diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index 89a178d1..b82e6611 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -1352,10 +1352,11 @@ int Widget_RemoveClass( LCUI_Widget w, const char *class_name ) { if( StrList_Has( w->classes, class_name ) ) { Widget_HandleChildrenStyleChange( w, 0, class_name ); + StrList_Remove( &w->classes, class_name ); + Widget_UpdateStyle( w, TRUE ); + return 1; } - StrList_Remove( &w->classes, class_name ); - Widget_UpdateStyle( w, TRUE ); - return 1; + return 0; } /** 为部件添加一个状态 */ @@ -1383,10 +1384,11 @@ int Widget_RemoveStatus( LCUI_Widget w, const char *status_name ) { if( StrList_Has( w->status, status_name ) ) { Widget_HandleChildrenStyleChange( w, 1, status_name ); + StrList_Remove( &w->status, status_name ); + Widget_UpdateStyle( w, TRUE ); + return 1; } - StrList_Remove( &w->status, status_name ); - Widget_UpdateStyle( w, TRUE ); - return 1; + return 0; } int Widget_ComputeMaxWidth( LCUI_Widget w ) diff --git a/src/gui/widget_event.c b/src/gui/widget_event.c index d75a55e4..2b98497d 100644 --- a/src/gui/widget_event.c +++ b/src/gui/widget_event.c @@ -696,8 +696,10 @@ static void OnMouseEvent( LCUI_SysEvent sys_ev, void *arg ) ev.button.button = sys_ev->button.button; Widget_PostEvent( target, &ev, NULL, NULL ); if( self.targets[WST_ACTIVE] == target ) { - ev.type = WET_CLICK; - Widget_PostEvent( target, &ev, NULL, NULL ); + if( ev.button.button == 1 ) { + ev.type = WET_CLICK; + Widget_PostEvent( target, &ev, NULL, NULL ); + } } Widget_UpdateStatus( NULL, WST_ACTIVE ); break; diff --git a/src/gui/widget_task.c b/src/gui/widget_task.c index 9d9e4597..7e15c1c8 100644 --- a/src/gui/widget_task.c +++ b/src/gui/widget_task.c @@ -85,7 +85,7 @@ static void HandleRefresh( LCUI_Widget w ) void Widget_UpdateTaskStatus( LCUI_Widget widget ) { int i; - for( i=0; itask.buffer[i] ) { widget->task.for_self = TRUE; } @@ -168,6 +168,7 @@ int Widget_Update( LCUI_Widget w ) LCUI_BOOL *buffer; LCUI_Widget child; LinkedListNode *node, *next; + /* 如果该部件有任务需要处理 */ if( w->task.for_self ) { ret = LCUIMutex_TryLock( &w->mutex ); From bd49e1df5fbe34ace5e69939dce7c16d6b41d2a1 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Sat, 13 Aug 2016 16:58:57 +0800 Subject: [PATCH 094/124] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20rbtree=20=E5=92=8C?= =?UTF-8?q?=20linkedlist=20=E7=9A=84=E6=93=8D=E4=BD=9C=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/util/linkedlist.h | 11 ++- include/LCUI/util/rbtree.h | 5 - src/font/fontlibrary.c | 11 +-- src/gui/builder.c | 1 - src/gui/css_parser.c | 28 +++--- src/gui/widget_base.c | 1 - src/gui/widget_library.c | 1 - src/keyboard.c | 2 +- src/util/linkedlist.c | 5 +- src/util/rbtree.c | 165 ++++++++++++++++----------------- 10 files changed, 113 insertions(+), 117 deletions(-) diff --git a/include/LCUI/util/linkedlist.h b/include/LCUI/util/linkedlist.h index a890713c..fb9d9c7e 100644 --- a/include/LCUI/util/linkedlist.h +++ b/include/LCUI/util/linkedlist.h @@ -55,11 +55,14 @@ struct LinkedListRec_ { LinkedListNode head, tail; }; -#define LinkedList_ForEach(node, list) \ - for( node = (list)->head.next; node; node = node->next ) +#define LinkedList_Each(node, list) \ + node = (list)->head.next; node; node = node->next -#define LinkedList_ForEachReverse(node, list) \ - for( node = (list)->tail.prev; node && node != &(list)->head; node = node->prev ) +#define LinkedList_EachReverse(node, list) \ + node = (list)->tail.prev; node && node != &(list)->head; node = node->prev + +#define LinkedList_ForEach(node, list) for( LinkedList_Each(node, list) ) +#define LinkedList_ForEachReverse(node, list) for( LinkedList_EachReverse(node, list) ) LCUI_API LinkedListNode *LinkedList_Append( LinkedList *list, void *data ); LCUI_API LinkedListNode *LinkedList_Insert( LinkedList *list, int pos, void *data ); diff --git a/include/LCUI/util/rbtree.h b/include/LCUI/util/rbtree.h index 7ca41ac6..2f19be2f 100644 --- a/include/LCUI/util/rbtree.h +++ b/include/LCUI/util/rbtree.h @@ -56,20 +56,15 @@ struct LCUI_RBTreeNodeRec_ { typedef struct LCUI_RBTreeRec_ { int total_node; - int need_free_data; int (*judge)(void*, const void*); void (*destroy)(void*); LCUI_RBTreeNode *root; } LCUI_RBTree; #define RBTree_GetTotal(rbt) (rbt)->total_node; - #define RBTree_OnJudge(rbt, func) (rbt)->judge = func - #define RBTree_OnDestroy(rbt, func) (rbt)->destroy = func -#define RBTree_SetDataNeedFree(rbt, flag) (rbt)->need_free_data = flag - /** 初始化红黑树 */ LCUI_API void RBTree_Init( LCUI_RBTree *rbt ); diff --git a/src/font/fontlibrary.c b/src/font/fontlibrary.c index bb721d9e..a4148569 100644 --- a/src/font/fontlibrary.c +++ b/src/font/fontlibrary.c @@ -113,7 +113,7 @@ static void DestroyFontPathNode( void *arg ) static void DestroyFontFamilyNode( void *arg ) { - LCUI_FontFamilyNode *node = (LCUI_FontFamilyNode*)arg; + LCUI_FontFamilyNode *node = arg; if( node->family_name ) { free( node->family_name ); } @@ -123,12 +123,14 @@ static void DestroyFontFamilyNode( void *arg ) static void DestroyFontBitmap( void *arg ) { - FontBitmap_Free( (LCUI_FontBitmap*)arg ); + FontBitmap_Free( arg ); + free( arg ); } static void DestroyTreeNode( void *arg ) { - RBTree_Destroy( (LCUI_RBTree*)arg ); + RBTree_Destroy( arg ); + free( arg ); } /** @@ -299,7 +301,6 @@ LCUI_FontBitmap* LCUIFont_AddBitmap( wchar_t ch, int font_id, return NULL; } RBTree_Init( tree_font ); - RBTree_SetDataNeedFree( tree_font, TRUE ); RBTree_OnDestroy( tree_font, DestroyTreeNode ); RBTree_Insert( &fontlib.bitmap_cache, ch, tree_font ); } @@ -316,7 +317,6 @@ LCUI_FontBitmap* LCUIFont_AddBitmap( wchar_t ch, int font_id, } RBTree_Init( tree_bmp ); RBTree_OnDestroy( tree_bmp, DestroyFontBitmap ); - RBTree_SetDataNeedFree( tree_bmp, TRUE ); RBTree_Insert( tree_font, font_id, tree_bmp ); } /* 在字体位图库中获取指定像素大小的字体位图 */ @@ -634,7 +634,6 @@ void LCUI_InitFont( void ) RBTree_OnDestroy( &fontlib.path_map, DestroyFontPathNode ); RBTree_OnDestroy( &fontlib.family_tree, DestroyFontFamilyNode ); RBTree_OnDestroy( &fontlib.bitmap_cache, DestroyTreeNode ); - RBTree_SetDataNeedFree( &fontlib.bitmap_cache, TRUE ); fontlib.is_inited = TRUE; /* 先初始化内置的字体引擎 */ diff --git a/src/gui/builder.c b/src/gui/builder.c index 8a52f733..5738e473 100644 --- a/src/gui/builder.c +++ b/src/gui/builder.c @@ -220,7 +220,6 @@ static void LCUIBuilder_Init( void ) RBTree_Init( &self.parsers ); RBTree_OnJudge( &self.parsers, CompareName ); - RBTree_SetDataNeedFree( &self.parsers, FALSE ); len = sizeof(parser_list) / sizeof(parser_list[0]); for( i = 0; i < len; ++i ) { p = &parser_list[i]; diff --git a/src/gui/css_parser.c b/src/gui/css_parser.c index b31d89c7..cfa7599f 100644 --- a/src/gui/css_parser.c +++ b/src/gui/css_parser.c @@ -941,8 +941,15 @@ int LCUICSS_AddParser( LCUI_StyleParser sp ) return key; } +static void OnDestroyStyleParser( void *arg ) +{ + LCUI_StyleParser sp = arg; + free( sp->name ); + free( sp ); +} + /** 初始化 LCUI 的 CSS 代码解析功能 */ -void LCUICSS_Init(void) +void LCUICSS_Init( void ) { KeyNameGroup *skn, *skn_end; LCUI_StyleParser new_sp, sp, sp_end; @@ -951,25 +958,22 @@ void LCUICSS_Init(void) RBTree_Init( &self.parser_tree ); RBTree_Init( &self.option_tree ); RBTree_Init( &self.option_name_tree ); - RBTree_SetDataNeedFree( &self.name_tree, FALSE ); - RBTree_SetDataNeedFree( &self.parser_tree, TRUE ); - RBTree_SetDataNeedFree( &self.option_tree, FALSE ); - RBTree_SetDataNeedFree( &self.option_name_tree, FALSE ); + RBTree_OnDestroy( &self.parser_tree, OnDestroyStyleParser ); RBTree_OnJudge( &self.parser_tree, CompareParserName ); RBTree_OnJudge( &self.option_tree, CompareName ); skn = style_name_map; - skn_end = skn + sizeof(style_name_map)/sizeof(KeyNameGroup); + skn_end = skn + sizeof( style_name_map ) / sizeof( KeyNameGroup ); for( ; skn < skn_end; ++skn ) { RBTree_Insert( &self.name_tree, skn->key, skn->name ); } - sp = style_parser_map; - sp_end = sp + sizeof(style_parser_map)/sizeof(LCUI_StyleParserRec); + sp_end = sp = style_parser_map; + sp_end += sizeof( style_parser_map ) / sizeof( LCUI_StyleParserRec ); for( ; sp < sp_end; ++sp ) { - new_sp = malloc(sizeof(LCUI_StyleParserRec)); + 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 = GetStyleName( sp->key ); if( !name ) { free( new_sp ); continue; @@ -981,7 +985,7 @@ void LCUICSS_Init(void) RBTree_CustomInsert( &self.parser_tree, new_sp->name, new_sp ); } skn = style_option_map; - skn_end = skn + sizeof(style_option_map)/sizeof(KeyNameGroup); + 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 ); @@ -989,7 +993,7 @@ void LCUICSS_Init(void) self.count = STYLE_KEY_TOTAL; } -void LCUICSS_Destroy(void) +void LCUICSS_Destroy( void ) { } diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index b82e6611..ab9be483 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -1605,7 +1605,6 @@ void LCUI_InitWidget( void ) LCUIWidget_AddTScrollBar(); LCUIWidget_AddTextEdit(); RBTree_Init( &LCUIWidget.ids ); - RBTree_SetDataNeedFree( &LCUIWidget.ids, FALSE ); RBTree_OnJudge( &LCUIWidget.ids, CompareWidgetId ); LCUIWidget.root = LCUIWidget_New("root"); Widget_SetTitleW( LCUIWidget.root, L"LCUI Display" ); diff --git a/src/gui/widget_library.c b/src/gui/widget_library.c index abcfed9c..543aaedb 100644 --- a/src/gui/widget_library.c +++ b/src/gui/widget_library.c @@ -61,7 +61,6 @@ void LCUIWidget_InitLibrary(void) { RBTree_Init( &widget_class_library ); RBTree_OnJudge( &widget_class_library, CompareName ); - RBTree_SetDataNeedFree( &widget_class_library, FALSE ); RBTree_OnDestroy( &widget_class_library, OnDestroyWidgetClass ); } diff --git a/src/keyboard.c b/src/keyboard.c index 73fdd92c..c30d6e6f 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -149,7 +149,7 @@ void LCUI_InitKeyboard( void ) { LCUIMutex_Init( &self.mutex ); RBTree_Init( &self.state_tree ); - RBTree_SetDataNeedFree( &self.state_tree, TRUE ); + RBTree_OnDestroy( &self.state_tree, free ); LCUI_BindEvent( LCUI_KEYDOWN, OnKeyboardEvent, NULL, NULL ); LCUI_BindEvent( LCUI_KEYUP, OnKeyboardEvent, NULL, NULL ); } diff --git a/src/util/linkedlist.c b/src/util/linkedlist.c index 72016009..e67ca6bd 100644 --- a/src/util/linkedlist.c +++ b/src/util/linkedlist.c @@ -38,6 +38,7 @@ * ****************************************************************************/ //#define DEBUG +#include #include #include #include @@ -307,10 +308,12 @@ void LinkedList_QuickSort( LinkedList *list, int (*cmp)(void*, void*) ) } if( cmp( lnode->data, range.enode->data) >= 0 ) { LinkedList_SwapNode( list, lnode, range.enode ); + if( mnode == range.enode ) { + mnode = lnode; + } node = lnode; lnode = range.enode; range.enode = node; - mnode = node; } else { left++, lnode = lnode->next; } diff --git a/src/util/rbtree.c b/src/util/rbtree.c index 561b30bb..b111a67c 100644 --- a/src/util/rbtree.c +++ b/src/util/rbtree.c @@ -58,7 +58,6 @@ void RBTree_Init( LCUI_RBTree *rbt ) rbt->judge = NULL; rbt->destroy = NULL; rbt->total_node = 0; - rbt->need_free_data = 0; } static void DestroyRBTreeNode( LCUI_RBTree *rbt, LCUI_RBTreeNode *node ) @@ -75,13 +74,11 @@ static void DestroyRBTreeNode( LCUI_RBTree *rbt, LCUI_RBTreeNode *node ) node->parent->right = NULL; } } - if( rbt->destroy ) { + if( rbt->destroy && node->data ) { rbt->destroy( node->data ); } - if( rbt->need_free_data ) { - free( node->data ); - } node->data = NULL; + free( node ); } /** 销毁红黑树 */ @@ -89,6 +86,7 @@ void RBTree_Destroy( LCUI_RBTree *rbt ) { rbt->total_node = 0; DestroyRBTreeNode( rbt, rbt->root ); + rbt->root = NULL; } /** 获取第一个结点 */ @@ -446,98 +444,95 @@ rb_erase_rebalance( LCUI_RBTreeNode *node, LCUI_RBTreeNode *parent, /** 删除红黑树中的结点 */ static int rb_erase( LCUI_RBTree *rbt, int key, const void *keydata ) { - unsigned char color; - LCUI_RBTreeNode *root, *child = NULL, *parent, *old, *left, *node; + unsigned char color; + LCUI_RBTreeNode *root, *child = NULL, *parent, *old, *left, *node; - root = rbt->root; - /* 查找要删除的结点 */ + root = rbt->root; + /* 查找要删除的结点 */ node = rb_search_auxiliary( root, key, keydata, rbt->judge, NULL ); - if( !node ) { - return -1; - } - old = node; - if (node->left && node->right) { - node = node->right; - while ((left = node->left) != NULL) { - node = left; - } - child = node->right; - parent = node->parent; - color = node->color; + if( !node ) { + return -1; + } + old = node; + if( node->left && node->right ) { + node = node->right; + while( (left = node->left) != NULL ) { + node = left; + } + child = node->right; + parent = node->parent; + color = node->color; - if (child) { - child->parent = parent; - } - if (parent) { - if (parent->left == node) { - parent->left = child; - } else { - parent->right = child; - } - } else { - root = child; - } + if( child ) { + child->parent = parent; + } + if( parent ) { + if( parent->left == node ) { + parent->left = child; + } else { + parent->right = child; + } + } else { + root = child; + } - if (node->parent == old) { - parent = node; - } + if( node->parent == old ) { + parent = node; + } - node->parent = old->parent; - node->color = old->color; - node->right = old->right; - node->left = old->left; + node->parent = old->parent; + node->color = old->color; + node->right = old->right; + node->left = old->left; - if (old->parent) { - if (old->parent->left == old) { - old->parent->left = node; - } else { - old->parent->right = node; - } - } else { - root = node; - } + if( old->parent ) { + if( old->parent->left == old ) { + old->parent->left = node; + } else { + old->parent->right = node; + } + } else { + root = node; + } - old->left->parent = node; - if (old->right) { - old->right->parent = node; - } - } else { - if (!node->left) { - child = node->right; - } else if (!node->right) { - child = node->left; - } - parent = node->parent; - color = node->color; + old->left->parent = node; + if( old->right ) { + old->right->parent = node; + } + } else { + if( !node->left ) { + child = node->right; + } else if( !node->right ) { + child = node->left; + } + parent = node->parent; + color = node->color; - if (child) { - child->parent = parent; - } - if (parent) { - if (parent->left == node) { - parent->left = child; - } else { - parent->right = child; - } - } else { - root = child; - } - } + if( child ) { + child->parent = parent; + } + if( parent ) { + if( parent->left == node ) { + parent->left = child; + } else { + parent->right = child; + } + } else { + root = child; + } + } - if( rbt->destroy ) { + if( rbt->destroy && old->data ) { rbt->destroy( old->data ); } - if( rbt->need_free_data ) { - free( old->data ); + free( old ); + if( color == BLACK ) { + /* 恢复红黑树性质 */ + root = rb_erase_rebalance( child, parent, root ); } - free( old ); - if (color == BLACK) { - /* 恢复红黑树性质 */ - root = rb_erase_rebalance( child, parent, root ); - } - rbt->root = root; - rbt->total_node -= 1; - return 0; + rbt->root = root; + rbt->total_node -= 1; + return 0; } int RBTree_Erase( LCUI_RBTree *rbt, int key ) From 486e0fd472caa40ac849b9e1cb26c0cb9e0a30e2 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Sat, 13 Aug 2016 17:09:16 +0800 Subject: [PATCH 095/124] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=A0=B7=E5=BC=8F?= =?UTF-8?q?=E8=A1=A8=E7=BC=93=E5=AD=98=EF=BC=8C=E5=87=8F=E5=B0=91=E5=A4=9A?= =?UTF-8?q?=E4=BD=99=E7=9A=84=E6=A0=B7=E5=BC=8F=E8=A1=A8=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为选择器添加 hash 属性,凭该属性可以在样式表缓存中索引样式表。 在为部件匹配继承过来的样式表时,会先凭部件的选择器的 hash 值从缓存中取样式表,如果没有则z哎样式库中匹配样式表,再存入样式表缓存中。有了缓存后,在有大量样式相同的子部件的情况下,就不用为每个部件重新匹配样式表了。 --- include/LCUI/gui/widget_base.h | 1 + include/LCUI/gui/widget_style.h | 5 ++- src/gui/widget_style.c | 67 +++++++++++++++++++++++++-------- 3 files changed, 56 insertions(+), 17 deletions(-) diff --git a/include/LCUI/gui/widget_base.h b/include/LCUI/gui/widget_base.h index 061adcb8..544f4167 100755 --- a/include/LCUI/gui/widget_base.h +++ b/include/LCUI/gui/widget_base.h @@ -165,6 +165,7 @@ typedef struct LCUI_SelectorRec_ { int rank; /**< 权值,决定优先级 */ int batch_num; /**< 批次号 */ int length; /**< 选择器结点长度 */ + unsigned int hash; /**< 哈希值 */ LCUI_SelectorNode *nodes; /**< 选择器结点列表 */ } LCUI_SelectorRec, *LCUI_Selector; diff --git a/include/LCUI/gui/widget_style.h b/include/LCUI/gui/widget_style.h index bed209b7..101a73b0 100644 --- a/include/LCUI/gui/widget_style.h +++ b/include/LCUI/gui/widget_style.h @@ -65,6 +65,9 @@ LCUI_API void StyleSheet_Delete( LCUI_StyleSheet ss ); /** 根据字符串内容生成相应的选择器 */ LCUI_API LCUI_Selector Selector( const char *selector ); +/** 更新选择器内的数据 */ +LCUI_API void Selector_Update( LCUI_Selector s ); + /** 删除选择器 */ LCUI_API void Selector_Delete( LCUI_Selector s ); @@ -88,7 +91,7 @@ LCUI_API void LCUI_PrintSelector( LCUI_Selector selector ); LCUI_API void LCUI_PrintStyleLibrary(void); /** 计算部件继承得到的样式表 */ -LCUI_API int Widget_ComputeInheritStyle( LCUI_Widget w, LCUI_StyleSheet out_ss ); +LCUI_API void Widget_GetInheritStyle( LCUI_Widget w, LCUI_StyleSheet out_ss ); /** 更新当前部件的样式 */ LCUI_API void Widget_UpdateStyle( LCUI_Widget w, LCUI_BOOL is_update_all ); diff --git a/src/gui/widget_style.c b/src/gui/widget_style.c index afdc5d9e..bbe264c8 100644 --- a/src/gui/widget_style.c +++ b/src/gui/widget_style.c @@ -107,7 +107,9 @@ typedef struct StyleLinkRec_ { static struct { LCUI_BOOL is_inited; + LCUI_Mutex mutex; /**< 互斥锁 */ LinkedList groups; /**< 样式组列表 */ + LCUI_RBTree cache; /**< 样式表缓存,以选择器的 hash 值索引 */ } style_library; const char *global_css = ToString( @@ -193,7 +195,7 @@ static LCUI_BOOL SelectorNode_Match( LCUI_SelectorNode sn1, return FALSE; } } - if( sn2->type ) { + if( sn2->type && strcmp(sn2->type, "*") != 0 ) { if( !sn1->type || strcmp( sn1->type, sn2->type ) != 0 ) { return FALSE; } @@ -711,6 +713,20 @@ static int SelectorNode_Update( LCUI_SelectorNode node ) return len; } +void Selector_Update( LCUI_Selector s ) +{ + int i; + const unsigned char *p; + unsigned int hash = 5381; + for( i = 0; i < s->length; ++i ) { + p = (unsigned char*)s->nodes[i]->fullname; + while( *p ) { + hash = ((hash << 5) + hash) + (*p++); + } + } + s->hash = hash; +} + LCUI_Selector Selector( const char *selector ) { const char *p; @@ -815,6 +831,7 @@ LCUI_Selector Selector( const char *selector ) } s->nodes[si] = NULL; s->length = si; + Selector_Update( s ); return s; } @@ -954,7 +971,7 @@ static LCUI_StyleSheet SelectStyleSheet( LCUI_Selector selector, if( !link ) { return NULL; } - LinkedList_ForEach( node, &link->styles ) { + for( LinkedList_Each( node, &link->styles ) ) { snode = node->data; if( snode->space && space ) { if( strcmp( snode->space, space ) == 0 ) { @@ -985,10 +1002,13 @@ int LCUI_PutStyle( LCUI_Selector selector, LCUI_StyleSheet in_ss, const char *space ) { LCUI_StyleSheet ss; + LCUIMutex_Lock( &style_library.mutex ); + RBTree_Destroy( &style_library.cache ); ss = SelectStyleSheet( selector, space ); if( ss ) { StyleSheet_Replace( ss, in_ss ); } + LCUIMutex_Unlock( &style_library.mutex ); return 0; } @@ -1000,10 +1020,10 @@ static int StyleLink_GetStyleSheets( StyleLink link, LinkedList *outlist ) if( !outlist ) { return link->styles.length; } - LinkedList_ForEach( node, &link->styles ) { + for( LinkedList_Each( node, &link->styles ) ) { int pos = -1, i = 0; snode = node->data; - LinkedList_ForEach( out_node, outlist ) { + for( LinkedList_Each( out_node, outlist ) ) { out_snode = out_node->data; if( snode->rank > out_snode->rank ) { pos = i; @@ -1042,7 +1062,7 @@ static int FindStyleSheetFromLink( StyleLink link, LCUI_Selector s, while( --i >= 0 ) { sn = s->nodes[i]; SelectorNode_GetNames( sn, &names ); - LinkedList_ForEach( node, &names ) { + for( LinkedList_Each( node, &names ) ) { parent = Dict_FetchValue( link->parents, node->data ); if( !parent ) { continue; @@ -1083,7 +1103,7 @@ static int FindStyleSheetFromGroup( int group, const char *name, SelectorNode_GetNames( s->nodes[i], &names ); LinkedList_Append( &names, strdup( "*" ) ); } - LinkedList_ForEach( node, &names ) { + for( LinkedList_Each( node, &names ) ) { DictEntry *entry; DictIterator *iter; char *name = node->data; @@ -1181,7 +1201,7 @@ static void LCUI_PrintStyleLink( StyleLink link, const char *selector ) } else { strcpy( fullname, link->group->name ); } - LinkedList_ForEach( node, &link->styles ) { + for( LinkedList_Each( node, &link->styles ) ) { StyleNode snode = node->data; printf("\n[%s]\n", snode->space ? snode->space:""); printf("%s {\n", fullname); @@ -1243,7 +1263,7 @@ LCUI_Selector Widget_GetSelector( LCUI_Widget w ) Selector_Delete( s ); return NULL; } - LinkedList_ForEachReverse( node, &list ) { + for( LinkedList_EachReverse( node, &list ) ) { int i; LCUI_SelectorNode sn; parent = node->data; @@ -1256,13 +1276,13 @@ LCUI_Selector Widget_GetSelector( LCUI_Widget w ) } if( parent->classes ) { for( i = 0; parent->classes[i]; ++i ) { - SortedStrList_Add( &sn->classes, + SortedStrList_Add( &sn->classes, parent->classes[i] ); } } if( parent->status ) { for( i = 0; parent->status[i]; ++i ) { - SortedStrList_Add( &sn->status, + SortedStrList_Add( &sn->status, parent->status[i] ); } } @@ -1274,6 +1294,7 @@ LCUI_Selector Widget_GetSelector( LCUI_Widget w ) LinkedList_Clear( &list, NULL ); s->nodes[ni] = NULL; s->length = ni; + Selector_Update( s ); return s; } @@ -1304,7 +1325,7 @@ int Widget_HandleChildrenStyleChange( LCUI_Widget w, int type, const char *name names[i] = str; } SelectorNode_GetNames( s->nodes[s->length - 1], &snames ); - LinkedList_ForEach( node, &snames ) { + for( LinkedList_Each( node, &snames ) ) { char *sname = node->data; /* 过滤掉不包含 name 中存在的名称 */ for( i = 0; i < n; ++i ) { @@ -1333,21 +1354,32 @@ int Widget_HandleChildrenStyleChange( LCUI_Widget w, int type, const char *name return count; } -int Widget_ComputeInheritStyle( LCUI_Widget w, LCUI_StyleSheet out_ss ) +void Widget_GetInheritStyle( LCUI_Widget w, LCUI_StyleSheet out_ss ) { LCUI_Selector s; + LCUI_StyleSheet ss; LinkedList list; LinkedListNode *node; LinkedList_Init( &list ); StyleSheet_Clear( out_ss ); s = Widget_GetSelector( w ); + LCUIMutex_Lock( &style_library.mutex ); + ss = RBTree_GetData( &style_library.cache, (int)s->hash ); + if( ss ) { + StyleSheet_Replace( out_ss, ss ); + LCUIMutex_Unlock( &style_library.mutex ); + return; + } + ss = StyleSheet(); FindStyleSheet( s, &list ); - LinkedList_ForEach( node, &list ) { + for( LinkedList_Each( node, &list ) ) { StyleNode sn = node->data; - StyleSheet_Merge( out_ss, sn->sheet ); + StyleSheet_Merge( ss, sn->sheet ); } LinkedList_Clear( &list, NULL ); - return 0; + RBTree_Insert( &style_library.cache, (int)s->hash, ss ); + StyleSheet_Replace( out_ss, ss ); + LCUIMutex_Unlock( &style_library.mutex ); } void Widget_UpdateStyle( LCUI_Widget w, LCUI_BOOL is_update_all ) @@ -1384,7 +1416,7 @@ void Widget_ExecUpdateStyle( LCUI_Widget w, LCUI_BOOL is_update_all ) { key_box_sizing, key_box_sizing, WTT_RESIZE, TRUE } }; if( is_update_all ) { - Widget_ComputeInheritStyle( w, w->inherited_style ); + Widget_GetInheritStyle( w, w->inherited_style ); } StyleSheet_Clear( w->style ); StyleSheet_Merge( w->style, w->custom_style ); @@ -1426,7 +1458,10 @@ void LCUIWidget_ExitStyle( void ) void LCUIWidget_InitStyle( void ) { + RBTree_Init( &style_library.cache ); + RBTree_OnDestroy( &style_library.cache, (FuncPtr)StyleSheet_Delete ); LinkedList_Init( &style_library.groups ); + LCUIMutex_Init( &style_library.mutex ); LCUICSS_Init(); LCUICSS_LoadString( global_css, NULL ); style_library.is_inited = TRUE; From 63d7508dc980c18d6ea65d09d8d2a0bb7e86e0a9 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Sat, 13 Aug 2016 19:12:01 +0800 Subject: [PATCH 096/124] Update README.md --- README.md | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f37ee474..3f0f0fb7 100644 --- a/README.md +++ b/README.md @@ -27,12 +27,14 @@ See the file `docs/LICENSE.TXT` for the available licenses. ## Documentation -API reference documentation has not yet been prepared, development to more -mature in this project will consider writing it. At this stage, you can refer -to the header files, source code, and sample programs. +Tutorial: https://lcui.lc-soft.io/guide/ + +API reference documentation has not yet been prepared, you can refer to the header files, source code, and sample programs. ## Building +### Bootstrap + To bootstrap the build you need to run `./configure` (in the root of the source tree). @@ -43,6 +45,19 @@ In the simplest case you would run: ./autogen.sh ./configure +### Prerequisites + +If you want to build full-featured LCUI, we suggest you install the following dependent libraries: + + * [libpng](http://www.libpng.org/pub/png/libpng.html) — PNG image compression library + * [libjpeg](http://www.ijg.org/) — JPEG image compression library + * [libxml2](http://xmlsoft.org/) — The XML C parser and toolkit + * [freetype](https://www.freetype.org/) — Font engine + +If you system is Ubuntu, you can run following command to install dependencies: + + apt-get install libpng-dev libjpeg-dev libxml2-dev libfreetype6-dev + ## Bugs Please report bugs by e-mail to `lc-soft@live.cn`. Don't forget to send a From efe44ad789b2b89d1f2e1f7fdbbefed07f334369 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Sat, 13 Aug 2016 23:30:00 +0800 Subject: [PATCH 097/124] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E9=93=BE=E8=A1=A8?= =?UTF-8?q?=E9=81=8D=E5=8E=86=E6=96=B9=E5=BC=8F=20#38=EF=BC=9ALinkedList?= =?UTF-8?q?=5FForEach(=20..=20)=20->=20for(=20LinkedList=5FEach(=20...=20)?= =?UTF-8?q?=20)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/font/fontlibrary.c | 4 ++-- src/font/textlayer.c | 2 +- src/font/textstyle.c | 2 +- src/gui/css_parser.c | 2 +- src/gui/widget/textedit.c | 6 +++--- src/gui/widget/textview.c | 4 ++-- src/gui/widget_base.c | 14 +++++++------- src/gui/widget_event.c | 20 ++++++++++---------- src/gui/widget_paint.c | 4 ++-- src/gui/widget_task.c | 2 +- src/ime.c | 4 ++-- src/main.c | 4 ++-- src/platform/windows/windows_display.c | 4 ++-- src/thread/win32/thread.c | 4 ++-- src/timer.c | 8 ++++---- src/util/event.c | 4 ++-- src/util/rect.c | 4 ++-- 17 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/font/fontlibrary.c b/src/font/fontlibrary.c index a4148569..66c85ecc 100644 --- a/src/font/fontlibrary.c +++ b/src/font/fontlibrary.c @@ -170,7 +170,7 @@ int LCUIFont_Add( LCUI_Font *font, const char *filepath ) RBTree_CustomInsert( &fontlib.family_tree, font->family_name, fn ); } - LinkedList_ForEach( node, &fn->styles ) { + for( LinkedList_Each( node, &fn->styles ) ) { f = (LCUI_Font*)node->data; if( strcmp( f->style_name, font->style_name ) == 0 ) { return -3; @@ -236,7 +236,7 @@ int LCUIFont_GetId( const char *family_name, const char *style_name ) if( !fnode ) { return -2; } - LinkedList_ForEach( node, &fnode->styles ) { + for( LinkedList_Each( node, &fnode->styles ) ) { font = (LCUI_Font*)node->data; if( style_name ) { if( strcasecmp( font->style_name, style_name ) ) { diff --git a/src/font/textlayer.c b/src/font/textlayer.c index 522efc70..eaa60580 100644 --- a/src/font/textlayer.c +++ b/src/font/textlayer.c @@ -1343,7 +1343,7 @@ void TextLayer_ClearInvalidRect( LCUI_TextLayer layer ) LinkedList_Clear( &layer->dirty_rect, free ); return; } - LinkedList_ForEach( node, &layer->dirty_rect ) { + for( LinkedList_Each( node, &layer->dirty_rect ) ) { Graph_Quote( &invalid_graph, &layer->graph, node->data ); Graph_FillAlpha( &invalid_graph, 0 ); } diff --git a/src/font/textstyle.c b/src/font/textstyle.c index 2c9d18fc..3cb73964 100755 --- a/src/font/textstyle.c +++ b/src/font/textstyle.c @@ -232,7 +232,7 @@ static void StyleTags_Delete( LinkedList *tags, int id ) if( tags->length <= 0 ) { return; } - LinkedList_ForEach( node, tags ) { + for( LinkedList_Each( node, tags ) ) { p = (LCUI_StyleTag*)node->data; if( p->id == id ) { LinkedList_DeleteNode( tags, node ); diff --git a/src/gui/css_parser.c b/src/gui/css_parser.c index cfa7599f..5fc0cd23 100644 --- a/src/gui/css_parser.c +++ b/src/gui/css_parser.c @@ -843,7 +843,7 @@ proc_comment: put_css: DEBUG_MSG("put css\n"); /* 将记录的样式表添加至匹配到的选择器中 */ - LinkedList_ForEach( node, &ctx->selectors ) { + for( LinkedList_Each( node, &ctx->selectors ) ) { LCUI_PutStyle( node->data, ctx->css, ctx->space ); } LinkedList_Clear( &ctx->selectors, (FuncPtr)Selector_Delete ); diff --git a/src/gui/widget/textedit.c b/src/gui/widget/textedit.c index e157f519..f9f27b3e 100644 --- a/src/gui/widget/textedit.c +++ b/src/gui/widget/textedit.c @@ -408,7 +408,7 @@ static void TextEdit_UpdateTextLayer( LCUI_Widget widget ) LinkedList_Init( &rects ); edit = widget->private_data; TextLayer_Update( edit->layer, &rects ); - LinkedList_ForEach( node, &rects ) { + for( LinkedList_Each( node, &rects ) ) { Widget_InvalidateArea( widget, node->data, SV_CONTENT_BOX ); } LinkedList_Clear( &rects, free ); @@ -431,7 +431,7 @@ static void TextEdit_OnTask( LCUI_Widget widget ) LCUIMutex_Lock( &edit->mutex ); LinkedList_Concat( &blocks, &edit->text_blocks ); LCUIMutex_Unlock( &edit->mutex ); - LinkedList_ForEach( node, &blocks ) { + for( LinkedList_Each( node, &blocks ) ) { TextEdit_ProcTextBlock( widget, node->data ); } LinkedList_Clear( &blocks, TextBlock_OnDestroy ); @@ -798,7 +798,7 @@ static void TextEdit_OnResize( LCUI_Widget w, LCUI_WidgetEvent e, void *arg ) TextLayer_SetMaxSize( edit->layer_source, max_width, max_height ); TextLayer_SetMaxSize( edit->layer_placeholder, max_width, max_height ); TextLayer_Update( edit->layer, &rects ); - LinkedList_ForEach( node, &rects ) { + for( LinkedList_Each( node, &rects ) ) { Widget_InvalidateArea( w, node->data, SV_CONTENT_BOX ); } LinkedList_Clear( &rects, free ); diff --git a/src/gui/widget/textview.c b/src/gui/widget/textview.c index 89140425..ef96c147 100644 --- a/src/gui/widget/textview.c +++ b/src/gui/widget/textview.c @@ -328,7 +328,7 @@ static void TextView_OnResize( LCUI_Widget w, LCUI_WidgetEvent e, void *arg ) TextLayer_SetMaxSize( txt->layer, max_width, max_height ); TextLayer_SetFixedSize( txt->layer, width, height ); TextLayer_Update( txt->layer, &rects ); - LinkedList_ForEach( node, &rects ) { + for( LinkedList_Each( node, &rects ) ) { Widget_InvalidateArea( w, node->data, SV_CONTENT_BOX ); } LinkedList_Clear( &rects, free ); @@ -405,7 +405,7 @@ static void TextView_OnTask( LCUI_Widget w ) txt = w->private_data; LinkedList_Init( &rects ); TextLayer_Update( txt->layer, &rects ); - LinkedList_ForEach( node, &rects ) { + for( LinkedList_Each( node, &rects ) ) { Widget_InvalidateArea( w, node->data, SV_CONTENT_BOX ); } LinkedList_Clear( &rects, free ); diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index ab9be483..6afb31c8 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -306,7 +306,7 @@ void Widget_Empty( LCUI_Widget w ) } LinkedList_ClearData( &w->children_show, NULL ); if( root == LCUIWidget.root ) { - LinkedList_ForEach( node, &w->children ) { + for( LinkedList_Each( node, &w->children ) ) { child = node->data; child->state = WSTATE_DELETED; } @@ -338,7 +338,7 @@ LCUI_Widget Widget_At( LCUI_Widget widget, int x, int y ) } do { is_hit = FALSE; - LinkedList_ForEach( node, &target->children_show ) { + for( LinkedList_Each( node, &target->children_show ) ) { c = node->data; if( !c->computed_style.visible ) { continue; @@ -658,7 +658,7 @@ void Widget_ExecUpdateZIndex( LCUI_Widget w ) snode = Widget_GetShowNode( w ); list = &w->parent->children_show; LinkedList_Unlink( list, snode ); - LinkedList_ForEach( cnode, list ) { + for( LinkedList_Each( cnode, list ) ) { LCUI_Widget child = cnode->data; LCUI_WidgetStyle *ccs = &child->computed_style; csnode = Widget_GetShowNode( child ); @@ -868,7 +868,7 @@ static void Widget_ComputeContentSize( LCUI_Widget w, int *width, int *height ) LinkedListNode *node; *width = *height = 0; - LinkedList_ForEach( node, &w->children_show ) { + for( LinkedList_Each( node, &w->children_show ) ) { child = node->data; /* 忽略不可见、绝对定位的部件 */ if( !child->computed_style.visible || @@ -1030,7 +1030,7 @@ static void Widget_SendResizeEvent( LCUI_Widget w ) Widget_TriggerEvent( w, &e, NULL ); Widget_AddTask( w, WTT_REFRESH ); Widget_PostSurfaceEvent( w, WET_RESIZE ); - LinkedList_ForEach( node, &w->children ) { + for( LinkedList_Each( node, &w->children ) ) { child = node->data; if( child->style->sheet[key_width].type == SVT_SCALE || child->style->sheet[key_height].type == SVT_SCALE ) { @@ -1455,7 +1455,7 @@ void Widget_ExecUpdateLayout( LCUI_Widget w ) LinkedListNode *node; ctx.max_width = Widget_ComputeMaxWidth( w ); - LinkedList_ForEach( node, &w->children ) { + for( LinkedList_Each( node, &w->children ) ) { child = node->data; if( child->computed_style.position != SV_STATIC && child->computed_style.position != SV_RELATIVE ) { @@ -1536,7 +1536,7 @@ static void _LCUIWidget_PrintTree( LCUI_Widget w, int depth, const char *prefix len = strlen(prefix); strcpy( child_prefix, prefix ); - LinkedList_ForEach( node, &w->children ) { + for( LinkedList_Each( node, &w->children ) ) { if( node == w->children.tail.prev ) { strcpy( str, "└" ); strcpy( &child_prefix[len], " " ); diff --git a/src/gui/widget_event.c b/src/gui/widget_event.c index 2b98497d..70f26382 100644 --- a/src/gui/widget_event.c +++ b/src/gui/widget_event.c @@ -141,7 +141,7 @@ static int Widget_DeleteEventRecord( LCUI_Widget widget, LCUI_WidgetEvent e ) LCUIMutex_Unlock( &self.mutex ); return -1; } - LinkedList_ForEach( node, &enode->records ) { + for( LinkedList_Each( node, &enode->records ) ) { prev = node->prev; if( node->data == e ) { LinkedList_DeleteNode( &enode->records, node ); @@ -284,10 +284,10 @@ static void TouchCapturers_Add( LinkedList *list, LCUI_Widget w, int point_id ) return; } /* 获取该部件的触点捕捉记录 */ - LinkedList_ForEach( node, list ) { + for( LinkedList_Each( node, list ) ) { tc = node->data; /* 清除与该触点绑定的其它捕捉记录 */ - LinkedList_ForEach( ptnode, &tc->points ) { + for( LinkedList_Each( ptnode, &tc->points ) ) { if( point_id != *(int*)ptnode->data ) { continue; } @@ -320,7 +320,7 @@ static int TouchCapturers_Delete( LinkedList *list, LCUI_Widget w, int point_id { TouchCapturer tc = NULL; LinkedListNode *node, *ptnode; - LinkedList_ForEach( node, list ) { + for( LinkedList_Each( node, list ) ) { tc = node->data; if( tc->widget == w ) { break; @@ -332,7 +332,7 @@ static int TouchCapturers_Delete( LinkedList *list, LCUI_Widget w, int point_id if( point_id < 0 ) { LinkedList_Clear( &tc->points, free ); } else { - LinkedList_ForEach( ptnode, &tc->points ) { + for( LinkedList_Each( ptnode, &tc->points ) ) { if( *(int*)ptnode->data == point_id ) { free( node->data ); LinkedList_DeleteNode( &tc->points, ptnode ); @@ -558,7 +558,7 @@ int Widget_StopEventPropagation(LCUI_Widget widget ) LCUIMutex_Unlock( &self.mutex ); return -1; } - LinkedList_ForEach( node, &enode->records ) { + for( LinkedList_Each( node, &enode->records ) ) { e = node->data; e->cancel_bubble = TRUE; } @@ -799,10 +799,10 @@ static int DispatchTouchEvent( LinkedList *capturers, count = 0; ev.touch.n_points = 0; /* 然后向命中的部件发送触控事件 */ - LinkedList_ForEach( node, capturers ) { + for( LinkedList_Each( node, capturers ) ) { TouchCapturer tc = node->data; for( i = 0; i < n_points; ++i ) { - LinkedList_ForEach( ptnode, &tc->points ) { + for( LinkedList_Each( ptnode, &tc->points ) ) { LCUI_TouchPoint point; if( points[i].id != *(int*)ptnode->data ) { continue; @@ -837,7 +837,7 @@ static void OnTouch( LCUI_SysEvent sys_ev, void *arg ) LinkedList_Init( &capturers ); LCUIMutex_Lock( &self.mutex ); /* 合并现有的触点捕捉记录 */ - LinkedList_ForEach( node, &self.touch_capturers ) { + for( LinkedList_Each( node, &self.touch_capturers ) ) { TouchCapturer tc = node->data; for( i = 0; i < n; ++i ) { /* 如果没有触点记录,则说明是捕获全部触点 */ @@ -846,7 +846,7 @@ static void OnTouch( LCUI_SysEvent sys_ev, void *arg ) points[i].id ); continue; } - LinkedList_ForEach( ptnode, &tc->points ) { + for( LinkedList_Each( ptnode, &tc->points ) ) { if( points[i].id != *(int*)ptnode->data ) { continue; } diff --git a/src/gui/widget_paint.c b/src/gui/widget_paint.c index ace732e3..82437aeb 100644 --- a/src/gui/widget_paint.c +++ b/src/gui/widget_paint.c @@ -203,7 +203,7 @@ static int _Widget_ProcInvalidArea( LCUI_Widget w, int x, int y, LCUI_Rect rect, child_box, *r; count = w->dirty_rects.length; /* 取出当前记录的无效区域 */ - LinkedList_ForEach( node, &w->dirty_rects ) { + for( LinkedList_Each( node, &w->dirty_rects ) ) { r = node->data; /* 若有独立位图缓存,则重绘脏矩形区域 */ if( w->enable_graph && Graph_IsValid( &w->graph ) ) { @@ -229,7 +229,7 @@ static int _Widget_ProcInvalidArea( LCUI_Widget w, int x, int y, x += w->box.padding.x - w->box.graph.x; y += w->box.padding.y - w->box.graph.y; /* 向子级部件递归 */ - LinkedList_ForEach( node, &w->children ) { + for( LinkedList_Each( node, &w->children ) ) { int child_x, child_y; child = node->data; if( !child->computed_style.visible || diff --git a/src/gui/widget_task.c b/src/gui/widget_task.c index 7e15c1c8..e63f5ca6 100644 --- a/src/gui/widget_task.c +++ b/src/gui/widget_task.c @@ -102,7 +102,7 @@ void Widget_AddTaskForChildren( LCUI_Widget widget, int task ) LCUI_Widget child; LinkedListNode *node; widget->task.for_children = TRUE; - LinkedList_ForEach( node, &widget->children ) { + for( LinkedList_Each( node, &widget->children ) ) { child = node->data; Widget_AddTask( child, task ); Widget_AddTaskForChildren( child, task ); diff --git a/src/ime.c b/src/ime.c index d5699623..b3b28609 100644 --- a/src/ime.c +++ b/src/ime.c @@ -68,7 +68,7 @@ static struct LCUIIMEModule { static LCUI_IME LCUIIME_Find( int ime_id ) { LinkedListNode *node; - LinkedList_ForEach( node, &self.list ) { + for( LinkedList_Each( node, &self.list ) ) { LCUI_IME ime = node->data; if( ime->id == ime_id ) { return ime; @@ -81,7 +81,7 @@ static LCUI_IME LCUIIME_Find( int ime_id ) static LCUI_IME LCUIIME_FindByName( const char *name ) { LinkedListNode *node; - LinkedList_ForEach( node, &self.list ){ + for( LinkedList_Each( node, &self.list ) ) { LCUI_IME ime = node->data; if( strcmp( ime->name, name ) == 0 ) { return ime; diff --git a/src/main.c b/src/main.c index 1282f950..58b9dc80 100644 --- a/src/main.c +++ b/src/main.c @@ -400,7 +400,7 @@ static void LCUIApp_QuitAllMainLoop(void) { LCUI_MainLoop loop; LinkedListNode *node; - LinkedList_ForEach( node, &MainApp.loops ) { + for( LinkedList_Each( node, &MainApp.loops ) ) { loop = node->data; if( loop ) { loop->state = STATE_EXITED; @@ -419,7 +419,7 @@ static void LCUIApp_Destroy(void) { LCUI_MainLoop loop; LinkedListNode *node; - LinkedList_ForEach( node, &MainApp.loops ) { + for( LinkedList_Each( node, &MainApp.loops ) ) { loop = node->data; LCUI_MainLoop_Quit( loop ); LCUIThread_Join( loop->tid, NULL ); diff --git a/src/platform/windows/windows_display.c b/src/platform/windows/windows_display.c index 33e590e7..15f21f63 100644 --- a/src/platform/windows/windows_display.c +++ b/src/platform/windows/windows_display.c @@ -97,7 +97,7 @@ static struct WIN_Display { static LCUI_Surface GetSurfaceByHWND( HWND hwnd ) { LinkedListNode *node; - LinkedList_ForEach( node, &win.surfaces ) { + for( LinkedList_Each( node, &win.surfaces ) ) { if( ((LCUI_Surface)node->data)->hwnd == hwnd ) { return node->data; } @@ -126,7 +126,7 @@ static void WinSurface_Destroy( LCUI_Surface surface ) static void WinSurface_ExecDelete( LCUI_Surface surface ) { LinkedListNode *node; - LinkedList_ForEach( node, &win.surfaces ) { + for( LinkedList_Each( node, &win.surfaces ) ) { if( node->data == surface ) { WinSurface_Destroy( node->data ); LinkedList_DeleteNode( &win.surfaces, node ); diff --git a/src/thread/win32/thread.c b/src/thread/win32/thread.c index 4d669699..ba67c202 100644 --- a/src/thread/win32/thread.c +++ b/src/thread/win32/thread.c @@ -92,7 +92,7 @@ static LCUI_ThreadData *LCUIThread_Find( LCUI_Thread tid ) { LinkedListNode *node; LCUI_ThreadData *thread_data; - LinkedList_ForEach( node, &thread_database ) { + for( LinkedList_Each( node, &thread_database ) ) { thread_data = (LCUI_ThreadData*)node->data; if( thread_data && thread_data->tid == tid ) { return thread_data; @@ -108,7 +108,7 @@ static int LCUIThread_Destroy( LCUI_Thread thread ) if(!thread){ return -1; } - LinkedList_ForEach( node, &thread_database ) { + for( LinkedList_Each( node, &thread_database ) ) { thread_data = (LCUI_ThreadData*)node->data; if( thread_data && thread_data->tid == thread ) { LinkedList_DeleteNode( &thread_database, node ); diff --git a/src/timer.c b/src/timer.c index 5cbc1fe1..5cbd6443 100644 --- a/src/timer.c +++ b/src/timer.c @@ -84,7 +84,7 @@ static void TimerList_AddNode( LinkedListNode *node ) timer = node->data; t = LCUI_GetTicks( timer->start_time ); t = timer->total_ms - t + timer->pause_ms; - LinkedList_ForEach( cur, &self.timer_list ) { + for( LinkedList_Each( cur, &self.timer_list ) ) { timer = cur->data; tt = LCUI_GetTicks( timer->start_time ); tt = timer->total_ms - tt + timer->pause_ms; @@ -105,7 +105,7 @@ static void TimerList_Print( void ) Timer timer; LinkedListNode *node; _DEBUG_MSG("timer list(%d) start:\n", self.timer_list.length); - LinkedList_ForEach( node, &self.timer_list ) { + for( LinkedList_Each( node, &self.timer_list ) { timer = node->data; _DEBUG_MSG("[%02d] %ld, func: %p, cur_ms: %ldms, total_ms: %ldms\n", i++, timer->id, timer->func, timer->total_ms - (long int)LCUI_GetTicks(timer->start_time), timer->total_ms ); @@ -125,7 +125,7 @@ static void TimerThread( void *arg ) LCUIMutex_Lock( &self.mutex ); while( self.is_running ) { Timer timer = NULL; - LinkedList_ForEach( node, &self.timer_list ) { + for( LinkedList_Each( node, &self.timer_list ) ) { timer = node->data; if( timer && timer->state == STATE_RUN ) { break; @@ -171,7 +171,7 @@ static Timer TimerList_Find( int timer_id ) { Timer timer; LinkedListNode *node; - LinkedList_ForEach( node, &self.timer_list ) { + for( LinkedList_Each( node, &self.timer_list ) ) { timer = node->data; if( timer && timer->id == timer_id ) { return timer; diff --git a/src/util/event.c b/src/util/event.c index ff4538ad..f32c31ac 100644 --- a/src/util/event.c +++ b/src/util/event.c @@ -108,7 +108,7 @@ int EventTrigger_Unbind( LCUI_EventTrigger trigger, int event_id, return -1; } handlers = event_node->data; - LinkedList_ForEach( handler_node, handlers ) { + for( LinkedList_Each( handler_node, handlers ) ) { handler = handler_node->data; if( handler->func != func ) { continue; @@ -154,7 +154,7 @@ int EventTrigger_Unbind3( LCUI_EventTrigger trigger, int event_id, return -1; } handlers = event_node->data; - LinkedList_ForEach( handler_node, handlers ) { + for( LinkedList_Each( handler_node, handlers ) ) { handler = handler_node->data; if( !compare_func(key, handler->data) ) { continue; diff --git a/src/util/rect.c b/src/util/rect.c index 7ee5870c..c4d9582b 100644 --- a/src/util/rect.c +++ b/src/util/rect.c @@ -241,7 +241,7 @@ int RectList_Add( LinkedList *list, LCUI_Rect *rect ) if( rect->w <= 0 || rect->h <= 0 ) { return -1; } - LinkedList_ForEach( node, list ) { + for( LinkedList_Each( node, list ) ) { added_rect = node->data; /* 如果被现有的矩形包含 */ if( LCUIRect_IsIncludeRect( added_rect, rect ) ) { @@ -282,7 +282,7 @@ int RectList_Delete( LinkedList *list, LCUI_Rect *rect ) } DEBUG_MSG("list: %p, total: %d, rect(%d,%d,%d,%d)\n", list, list->length, rect->x, rect->y, rect->w, rect->h); - LinkedList_ForEach( node, list ) { + for( LinkedList_Each( node, list ) ) { p_rect = (LCUI_Rect*)node->data; DEBUG_MSG("p_rect(%d,%d,%d,%d)\n", p_rect->x, p_rect->y, p_rect->w, p_rect->h); From 7dc368383a73d27997c1b5b1d69eec4210118aad Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Sun, 14 Aug 2016 23:50:50 +0800 Subject: [PATCH 098/124] =?UTF-8?q?=E4=B8=BA=E9=83=A8=E4=BB=B6=E7=9A=84?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E8=AF=BB=E5=86=99=E6=93=8D=E4=BD=9C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E4=BA=92=E6=96=A5=E9=94=81=E3=80=81=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E9=83=A8=E4=BB=B6=E6=9E=90=E6=9E=84=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在频繁添加子部件时,如果父部件的class或status发生变化,会使正在计算样式的子部件出现内存访问越界的问题,因为计算样式需要访问父级部件的id、class、status等属性。现在先暂时用互斥锁,以后再考虑改用读写锁。 为部件析构函数添加几个销毁项。 --- src/gui/widget_base.c | 292 ++++++++++++++++++++++++----------------- src/gui/widget_style.c | 4 + 2 files changed, 172 insertions(+), 124 deletions(-) diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index 6afb31c8..5e076f22 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -52,6 +52,130 @@ static struct LCUIWidgetModule { LCUI_RBTree ids; /** 各种部件的ID索引 */ } LCUIWidget; +#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; @@ -247,6 +371,10 @@ void Widget_ExecDestroy( LCUI_Widget widget ) Widget_ReleaseMouseCapture( widget ); Widget_ReleaseTouchCapture( widget, -1 ); Widget_StopEventPropagation( widget ); + StyleSheet_Delete( widget->style ); + StyleSheet_Delete( widget->cached_style ); + StyleSheet_Delete( widget->custom_style ); + StyleSheet_Delete( widget->inherited_style ); LCUIWidget_ClearEventTarget( widget ); if( wc && wc->methods.destroy ) { wc->methods.destroy( widget ); @@ -254,11 +382,23 @@ void Widget_ExecDestroy( LCUI_Widget widget ) /* 先释放显示列表,后销毁部件列表,因为部件在这两个链表中的节点是和它共用 * 一块内存空间的,销毁部件列表会把部件释放掉,所以把这个操作放在后面 */ LinkedList_ClearData( &widget->children_show, NULL ); + LinkedList_ClearData( &widget->children_trash, NULL ); LinkedList_ClearData( &widget->children, Widget_OnDestroy ); LinkedList_Clear( &widget->dirty_rects, free ); Widget_PostSurfaceEvent( widget, WET_REMOVE ); Widget_UpdateLayout( widget->parent ); Widget_SetId( widget, NULL ); + if( widget->type ) { + free( widget->type ); + widget->type = NULL; + } + if( widget->title ) { + free( widget->title ); + widget->title = NULL; + } + widget->classes ? StrList_Destroy( widget->classes ):0; + widget->status ? StrList_Destroy( widget->status ):0; + LCUIMutex_Destroy( &widget->mutex ); EventTrigger_Destroy( widget->trigger ); widget->trigger = NULL; free( widget ); @@ -1205,189 +1345,93 @@ void Widget_Unlock( LCUI_Widget w ) LCUIMutex_Unlock( &w->mutex ); } -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; -} - -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; -} - -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; -} - /** 为部件添加一个类 */ int Widget_AddClass( LCUI_Widget w, const char *class_name ) { + Widget_Lock( w ); if( StrList_Has( w->classes, class_name ) ) { + Widget_Unlock( w ); return 1; } if( StrList_Add(&w->classes, class_name) <= 0 ) { + Widget_Unlock( w ); return 0; } Widget_HandleChildrenStyleChange( w, 0, class_name ); Widget_UpdateStyle( w, TRUE ); + Widget_Unlock( w ); return 1; } /** 判断部件是否包含指定的类 */ LCUI_BOOL Widget_HasClass( LCUI_Widget w, const char *class_name ) { - return StrList_Has( w->classes, class_name ); + Widget_Lock( w ); + if( StrList_Has( w->classes, class_name ) ) { + Widget_Unlock( w ); + return TRUE; + } + Widget_Unlock( w ); + return FALSE; } /** 从部件中移除一个类 */ int Widget_RemoveClass( LCUI_Widget w, const char *class_name ) { + Widget_Lock( w ); if( StrList_Has( w->classes, class_name ) ) { Widget_HandleChildrenStyleChange( w, 0, class_name ); StrList_Remove( &w->classes, class_name ); Widget_UpdateStyle( w, TRUE ); + Widget_Unlock( w ); return 1; } + Widget_Unlock( w ); return 0; } /** 为部件添加一个状态 */ int Widget_AddStatus( LCUI_Widget w, const char *status_name ) { + Widget_Lock( w ); if( StrList_Has( w->status, status_name ) ) { + Widget_Unlock( w ); return 0; } if( StrList_Add( &w->status, status_name ) <= 0 ) { + Widget_Unlock( w ); return 0; } Widget_UpdateStyle( w, TRUE ); Widget_HandleChildrenStyleChange( w, 1, status_name ); + Widget_Unlock( w ); return 1; } /** 判断部件是否包含指定的状态 */ LCUI_BOOL Widget_HasStatus( LCUI_Widget w, const char *status_name ) { - return StrList_Has( w->status, status_name ); + Widget_Lock( w ); + if( StrList_Has( w->status, status_name ) ) { + Widget_Unlock( w ); + return TRUE; + } + Widget_Unlock( w ); + return FALSE; } /** 从部件中移除一个状态 */ int Widget_RemoveStatus( LCUI_Widget w, const char *status_name ) { + Widget_Lock( w ); if( StrList_Has( w->status, status_name ) ) { Widget_HandleChildrenStyleChange( w, 1, status_name ); StrList_Remove( &w->status, status_name ); Widget_UpdateStyle( w, TRUE ); + Widget_Unlock( w ); return 1; } + Widget_Unlock( w ); return 0; } diff --git a/src/gui/widget_style.c b/src/gui/widget_style.c index bbe264c8..905a70ce 100644 --- a/src/gui/widget_style.c +++ b/src/gui/widget_style.c @@ -1268,6 +1268,7 @@ LCUI_Selector Widget_GetSelector( LCUI_Widget w ) LCUI_SelectorNode sn; parent = node->data; sn = NEW( LCUI_SelectorNodeRec, 1 ); + Widget_Lock( parent ); if( parent->id ) { sn->id = strdup( parent->id ); } @@ -1286,6 +1287,7 @@ LCUI_Selector Widget_GetSelector( LCUI_Widget w ) parent->status[i] ); } } + Widget_Unlock( parent ); SelectorNode_Update( sn ); s->nodes[ni] = sn; s->rank += sn->rank; @@ -1368,6 +1370,7 @@ void Widget_GetInheritStyle( LCUI_Widget w, LCUI_StyleSheet out_ss ) if( ss ) { StyleSheet_Replace( out_ss, ss ); LCUIMutex_Unlock( &style_library.mutex ); + Selector_Delete( s ); return; } ss = StyleSheet(); @@ -1380,6 +1383,7 @@ void Widget_GetInheritStyle( LCUI_Widget w, LCUI_StyleSheet out_ss ) RBTree_Insert( &style_library.cache, (int)s->hash, ss ); StyleSheet_Replace( out_ss, ss ); LCUIMutex_Unlock( &style_library.mutex ); + Selector_Delete( s ); } void Widget_UpdateStyle( LCUI_Widget w, LCUI_BOOL is_update_all ) From 6e3c550032021cf5a9872f0eab2a7c0c2a9b3a4b Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Tue, 16 Aug 2016 22:19:26 +0800 Subject: [PATCH 099/124] =?UTF-8?q?=E6=92=A4=E9=94=80=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E4=BA=92=E6=96=A5=E9=94=81=E3=80=81=E4=BF=AE=E6=94=B9=E9=83=A8?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E9=94=80=E6=AF=81=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 用互斥锁会出现死锁,因此撤销使用互斥锁。 修改部件的销毁函数,部件的数据销毁需要在调用完该类部件的 destroy() 函数后进行。 --- include/LCUI/util/string.h | 2 +- src/gui/widget_base.c | 36 ++++++------------------------------ src/gui/widget_style.c | 2 -- 3 files changed, 7 insertions(+), 33 deletions(-) diff --git a/include/LCUI/util/string.h b/include/LCUI/util/string.h index 01cbd6c5..2bcfe153 100644 --- a/include/LCUI/util/string.h +++ b/include/LCUI/util/string.h @@ -80,7 +80,7 @@ LCUI_API int strtrim( char *outstr, const char *instr, const char *charlist ); LCUI_API int strsplit( const char *instr, const char *sep, char ***outstrs ); /** 释放字符串组 */ -void freestrs( char **strs ); +LCUI_API void freestrs( char **strs ); LCUI_END_HEADER diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index 5e076f22..7debd461 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -371,10 +371,6 @@ void Widget_ExecDestroy( LCUI_Widget widget ) Widget_ReleaseMouseCapture( widget ); Widget_ReleaseTouchCapture( widget, -1 ); Widget_StopEventPropagation( widget ); - StyleSheet_Delete( widget->style ); - StyleSheet_Delete( widget->cached_style ); - StyleSheet_Delete( widget->custom_style ); - StyleSheet_Delete( widget->inherited_style ); LCUIWidget_ClearEventTarget( widget ); if( wc && wc->methods.destroy ) { wc->methods.destroy( widget ); @@ -385,6 +381,10 @@ void Widget_ExecDestroy( LCUI_Widget widget ) LinkedList_ClearData( &widget->children_trash, NULL ); LinkedList_ClearData( &widget->children, Widget_OnDestroy ); LinkedList_Clear( &widget->dirty_rects, free ); + StyleSheet_Delete( widget->inherited_style ); + StyleSheet_Delete( widget->cached_style ); + StyleSheet_Delete( widget->custom_style ); + StyleSheet_Delete( widget->style ); Widget_PostSurfaceEvent( widget, WET_REMOVE ); Widget_UpdateLayout( widget->parent ); Widget_SetId( widget, NULL ); @@ -1348,52 +1348,38 @@ 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 ) ) { - Widget_Unlock( w ); return 1; } if( StrList_Add(&w->classes, class_name) <= 0 ) { - Widget_Unlock( w ); return 0; } Widget_HandleChildrenStyleChange( w, 0, class_name ); Widget_UpdateStyle( w, TRUE ); - Widget_Unlock( w ); return 1; } /** 判断部件是否包含指定的类 */ LCUI_BOOL Widget_HasClass( LCUI_Widget w, const char *class_name ) { - Widget_Lock( w ); - if( StrList_Has( w->classes, class_name ) ) { - Widget_Unlock( w ); - return TRUE; - } - Widget_Unlock( w ); - return FALSE; + return StrList_Has( w->classes, class_name ); } /** 从部件中移除一个类 */ int Widget_RemoveClass( LCUI_Widget w, const char *class_name ) { - Widget_Lock( w ); if( StrList_Has( w->classes, class_name ) ) { Widget_HandleChildrenStyleChange( w, 0, class_name ); StrList_Remove( &w->classes, class_name ); Widget_UpdateStyle( w, TRUE ); - Widget_Unlock( w ); return 1; } - Widget_Unlock( w ); return 0; } /** 为部件添加一个状态 */ int Widget_AddStatus( LCUI_Widget w, const char *status_name ) { - Widget_Lock( w ); if( StrList_Has( w->status, status_name ) ) { Widget_Unlock( w ); return 0; @@ -1404,34 +1390,24 @@ int Widget_AddStatus( LCUI_Widget w, const char *status_name ) } Widget_UpdateStyle( w, TRUE ); Widget_HandleChildrenStyleChange( w, 1, status_name ); - Widget_Unlock( w ); return 1; } /** 判断部件是否包含指定的状态 */ LCUI_BOOL Widget_HasStatus( LCUI_Widget w, const char *status_name ) { - Widget_Lock( w ); - if( StrList_Has( w->status, status_name ) ) { - Widget_Unlock( w ); - return TRUE; - } - Widget_Unlock( w ); - return FALSE; + return StrList_Has( w->status, status_name ); } /** 从部件中移除一个状态 */ int Widget_RemoveStatus( LCUI_Widget w, const char *status_name ) { - Widget_Lock( w ); if( StrList_Has( w->status, status_name ) ) { Widget_HandleChildrenStyleChange( w, 1, status_name ); StrList_Remove( &w->status, status_name ); Widget_UpdateStyle( w, TRUE ); - Widget_Unlock( w ); return 1; } - Widget_Unlock( w ); return 0; } diff --git a/src/gui/widget_style.c b/src/gui/widget_style.c index 905a70ce..b9a2a1d4 100644 --- a/src/gui/widget_style.c +++ b/src/gui/widget_style.c @@ -1268,7 +1268,6 @@ LCUI_Selector Widget_GetSelector( LCUI_Widget w ) LCUI_SelectorNode sn; parent = node->data; sn = NEW( LCUI_SelectorNodeRec, 1 ); - Widget_Lock( parent ); if( parent->id ) { sn->id = strdup( parent->id ); } @@ -1287,7 +1286,6 @@ LCUI_Selector Widget_GetSelector( LCUI_Widget w ) parent->status[i] ); } } - Widget_Unlock( parent ); SelectorNode_Update( sn ); s->nodes[ni] = sn; s->rank += sn->rank; From 25214960cff3ab7f01a05fd96ac51ff239f16b82 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Wed, 17 Aug 2016 23:25:01 +0800 Subject: [PATCH 100/124] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=92=E6=96=A5?= =?UTF-8?q?=E9=94=81=E5=88=9D=E5=A7=8B=E5=8C=96=E6=97=B6=E7=9A=84=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=EF=BC=8C=E4=BB=A5=E6=94=AF=E6=8C=81=E5=9C=A8=E5=90=8C?= =?UTF-8?q?=E4=B8=80=E7=BA=BF=E7=A8=8B=E4=B8=8A=E5=A4=9A=E6=AC=A1=E4=B8=8A?= =?UTF-8?q?=E9=94=81/=E8=A7=A3=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 以默认的设置初始化的互斥锁,如果互斥锁在同一线程上被锁上第二次,会出现死锁,为避免这一问题,将互斥锁类型设置为 PTHREAD_MUTEX_RECURSIVE。 --- src/thread/pthread/mutex.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/thread/pthread/mutex.c b/src/thread/pthread/mutex.c index e4fcb77e..000b5499 100755 --- a/src/thread/pthread/mutex.c +++ b/src/thread/pthread/mutex.c @@ -45,7 +45,10 @@ /* init the mutex */ int LCUIMutex_Init( LCUI_Mutex *mutex ) { - return pthread_mutex_init( mutex, NULL ); + pthread_mutexattr_t attr; + pthread_mutexattr_init( &attr ); + pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_RECURSIVE ); + return pthread_mutex_init( mutex, &attr ); } /* Free the mutex */ From d09bb285471ec7bb6a6594047edd7e6b5dcac186 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Wed, 17 Aug 2016 23:37:44 +0800 Subject: [PATCH 101/124] =?UTF-8?q?=E4=B8=BA=E9=83=A8=E4=BB=B6=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=93=8D=E4=BD=9C=E5=8A=A0=E4=B8=8A=E4=BA=92=E6=96=A5?= =?UTF-8?q?=E9=94=81=E3=80=81=E5=8E=BB=E9=99=A4=E7=BC=96=E8=AF=91=E8=AD=A6?= =?UTF-8?q?=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gui/widget_base.c | 27 +++++++++++++++++++++++++-- src/gui/widget_style.c | 14 ++++++++------ src/util/string.c | 1 + 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index 7debd461..db614683 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -1348,38 +1348,52 @@ 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 ) ) { + Widget_Unlock( w ); return 1; } if( StrList_Add(&w->classes, class_name) <= 0 ) { + Widget_Unlock( w ); return 0; } Widget_HandleChildrenStyleChange( w, 0, class_name ); Widget_UpdateStyle( w, TRUE ); + Widget_Unlock( w ); return 1; } /** 判断部件是否包含指定的类 */ LCUI_BOOL Widget_HasClass( LCUI_Widget w, const char *class_name ) { - return StrList_Has( w->classes, class_name ); + Widget_Lock( w ); + if( StrList_Has( w->classes, class_name ) ) { + Widget_Unlock( w ); + return TRUE; + } + Widget_Unlock( w ); + return FALSE; } /** 从部件中移除一个类 */ int Widget_RemoveClass( LCUI_Widget w, const char *class_name ) { + Widget_Lock( w ); if( StrList_Has( w->classes, class_name ) ) { Widget_HandleChildrenStyleChange( w, 0, class_name ); StrList_Remove( &w->classes, class_name ); Widget_UpdateStyle( w, TRUE ); + Widget_Unlock( w ); return 1; } + Widget_Unlock( w ); return 0; } /** 为部件添加一个状态 */ int Widget_AddStatus( LCUI_Widget w, const char *status_name ) { + Widget_Lock( w ); if( StrList_Has( w->status, status_name ) ) { Widget_Unlock( w ); return 0; @@ -1390,24 +1404,33 @@ int Widget_AddStatus( LCUI_Widget w, const char *status_name ) } Widget_UpdateStyle( w, TRUE ); Widget_HandleChildrenStyleChange( w, 1, status_name ); + Widget_Unlock( w ); return 1; } /** 判断部件是否包含指定的状态 */ LCUI_BOOL Widget_HasStatus( LCUI_Widget w, const char *status_name ) { - return StrList_Has( w->status, status_name ); + Widget_Lock( w ); + if( StrList_Has( w->status, status_name ) ) { + return TRUE; + } + Widget_Unlock( w ); + return FALSE; } /** 从部件中移除一个状态 */ int Widget_RemoveStatus( LCUI_Widget w, const char *status_name ) { + Widget_Lock( w ); if( StrList_Has( w->status, status_name ) ) { Widget_HandleChildrenStyleChange( w, 1, status_name ); StrList_Remove( &w->status, status_name ); Widget_UpdateStyle( w, TRUE ); + Widget_Unlock( w ); return 1; } + Widget_Unlock( w ); return 0; } diff --git a/src/gui/widget_style.c b/src/gui/widget_style.c index b9a2a1d4..136bdfbc 100644 --- a/src/gui/widget_style.c +++ b/src/gui/widget_style.c @@ -186,8 +186,8 @@ static void SortedStrList_Destroy( char **strlist ) * 匹配选择器节点 * 左边的选择器必须包含右边的选择器的所有属性。 */ -static LCUI_BOOL SelectorNode_Match( LCUI_SelectorNode sn1, - LCUI_SelectorNode sn2 ) +LCUI_BOOL SelectorNode_Match( LCUI_SelectorNode sn1, + LCUI_SelectorNode sn2 ) { int i, j; if( sn2->id ) { @@ -1112,7 +1112,7 @@ static int FindStyleSheetFromGroup( int group, const char *name, continue; } iter = Dict_GetIterator( slg->links ); - while( entry = Dict_Next( iter ) ) { + while( (entry = Dict_Next( iter )) ) { StyleLink link = DictEntry_GetVal( entry ); count += FindStyleSheetFromLink( link, s, i, list ); } @@ -1209,7 +1209,7 @@ static void LCUI_PrintStyleLink( StyleLink link, const char *selector ) printf("}\n"); } iter = Dict_GetIterator( link->parents ); - while( entry = Dict_Next( iter ) ) { + while( (entry = Dict_Next( iter )) ) { StyleLink parent = DictEntry_GetVal( entry ); LCUI_PrintStyleLink( parent, fullname ); } @@ -1228,12 +1228,12 @@ void LCUI_PrintStyleLibrary( void ) printf( "style library begin\n" ); group = LinkedList_Get( &style_library.groups, 0 ); iter = Dict_GetIterator( group ); - while( entry = Dict_Next(iter) ) { + while( (entry = Dict_Next(iter)) ) { DictEntry *entry_slg; DictIterator *iter_slg; slg = DictEntry_GetVal( entry ); iter_slg = Dict_GetIterator( slg->links ); - while( entry_slg = Dict_Next(iter_slg) ) { + while( (entry_slg = Dict_Next(iter_slg)) ) { link = DictEntry_GetVal( entry_slg ); LCUI_PrintStyleLink( link, NULL ); } @@ -1268,6 +1268,7 @@ LCUI_Selector Widget_GetSelector( LCUI_Widget w ) LCUI_SelectorNode sn; parent = node->data; sn = NEW( LCUI_SelectorNodeRec, 1 ); + Widget_Lock( parent ); if( parent->id ) { sn->id = strdup( parent->id ); } @@ -1286,6 +1287,7 @@ LCUI_Selector Widget_GetSelector( LCUI_Widget w ) parent->status[i] ); } } + Widget_Unlock( parent ); SelectorNode_Update( sn ); s->nodes[ni] = sn; s->rank += sn->rank; diff --git a/src/util/string.c b/src/util/string.c index 9c54c1a5..10125462 100644 --- a/src/util/string.c +++ b/src/util/string.c @@ -37,6 +37,7 @@ * 没有,请查看:. * ****************************************************************************/ +#include #include #include From 4bddec1bae42e7e8913afc4547e19c7adb65b1b3 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Thu, 18 Aug 2016 23:10:05 +0800 Subject: [PATCH 102/124] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E6=88=B3=E8=8E=B7=E5=8F=96=E5=87=BD=E6=95=B0=E7=9A=84=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=EF=BC=8C=E5=90=88=E5=B9=B6=20time.c=20=E5=92=8C=20del?= =?UTF-8?q?ay.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/util.h | 5 +-- include/LCUI/util/delay.h | 53 ------------------------ include/LCUI/util/time.h | 51 +++++++++++++++++++++-- src/gui/widget/scrollbar.c | 6 +-- src/timer.c | 20 ++++----- src/util/delay.c | 69 ------------------------------- src/util/dict.c | 2 +- src/util/framectrl.c | 14 +++---- src/util/time.c | 84 +++++++++++++++++++++++++++++++------- 9 files changed, 140 insertions(+), 164 deletions(-) delete mode 100644 include/LCUI/util/delay.h delete mode 100644 src/util/delay.c diff --git a/include/LCUI/util.h b/include/LCUI/util.h index 3aa48a71..6df2a98e 100644 --- a/include/LCUI/util.h +++ b/include/LCUI/util.h @@ -37,10 +37,9 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_MISC_H__ -#define __LCUI_MISC_H__ +#ifndef __LCUI_UTIL_H__ +#define __LCUI_UTIL_H__ #include -#include #include #include #include diff --git a/include/LCUI/util/delay.h b/include/LCUI/util/delay.h deleted file mode 100644 index 2fe3cc33..00000000 --- a/include/LCUI/util/delay.h +++ /dev/null @@ -1,53 +0,0 @@ -/* *************************************************************************** - * delay.h -- time delay function. - * - * Copyright (C) 2013-2016 by Liu Chao - * - * 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 . - * ****************************************************************************/ - -/* **************************************************************************** - * delay.h -- 一些提供延时功能的函数 - * - * 版权所有 (C) 2013-2016 归属于 刘超 - * - * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 - * - * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) - * - * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 - * - * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 - * 定用途的隐含担保,详情请参照GPLv2许可协议。 - * - * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 - * 没有,请查看:. - * ****************************************************************************/ -#ifndef LCUI_UTIL_DELAY_H -#define LCUI_UTIL_DELAY_H - -LCUI_BEGIN_HEADER - -/* 秒级延时 */ -LCUI_API void LCUI_Sleep( unsigned int s ); - -/* 毫秒级延时 */ -LCUI_API void LCUI_MSleep( unsigned int ms ); - -LCUI_END_HEADER - -#endif - diff --git a/include/LCUI/util/time.h b/include/LCUI/util/time.h index 2209bbde..e04cbcfa 100644 --- a/include/LCUI/util/time.h +++ b/include/LCUI/util/time.h @@ -1,14 +1,57 @@ - +/* *************************************************************************** +* time.c -- The time operation set. +* +* Copyright (C) 2015-2016 by Liu Chao +* +* 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 . +* ****************************************************************************/ + +/* **************************************************************************** +* time.c -- 时间相关函数集 +* +* 版权所有 (C) 2015-2016 归属于 刘超 +* +* 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 +* +* (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) +* +* 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 +* +* LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 +* 定用途的隐含担保,详情请参照GPLv2许可协议。 +* +* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 +* 没有,请查看:. +* ****************************************************************************/ + #ifndef LCUI_UTIL_TIME_H #define LCUI_UTIL_TIME_H LCUI_BEGIN_HEADER -LCUI_API void LCUI_StartTicks( void ); +LCUI_API void LCUITime_Init( void ); -LCUI_API int64_t LCUI_GetTickCount( void ); +LCUI_API int64_t LCUI_GetTime( void ); + +LCUI_API int64_t LCUI_GetTimeDelta( int64_t start ); + +LCUI_API void LCUI_Sleep( unsigned int s ); + +LCUI_API void LCUI_MSleep( unsigned int ms ); -LCUI_API int64_t LCUI_GetTicks( int64_t start_ticks ); LCUI_END_HEADER diff --git a/src/gui/widget/scrollbar.c b/src/gui/widget/scrollbar.c index a6b67443..3a03e4be 100644 --- a/src/gui/widget/scrollbar.c +++ b/src/gui/widget/scrollbar.c @@ -147,7 +147,7 @@ static void ScrollBar_UpdateInertialScrolling( LCUI_Widget w ) scrollbar->effect.speed = 0; scrollbar->effect.is_running = FALSE; scrollbar->effect.start_pos = scrollbar->pos; - scrollbar->effect.timestamp = LCUI_GetTickCount(); + scrollbar->effect.timestamp = LCUI_GetTime(); } static void ScrollBar_StartInertialScrolling( LCUI_Widget w ) @@ -160,7 +160,7 @@ static void ScrollBar_StartInertialScrolling( LCUI_Widget w ) effect = &scrollbar->effect; effect->end_pos = scrollbar->pos; distance = effect->end_pos - effect->start_pos; - time_delta = LCUI_GetTicks( effect->timestamp ); + time_delta = LCUI_GetTimeDelta( effect->timestamp ); /* 计算每一帧的滚动距离(速度) */ if( time_delta > 0 ) { effect->speed = distance * effect->interval / (int)time_delta; @@ -171,7 +171,7 @@ static void ScrollBar_StartInertialScrolling( LCUI_Widget w ) if( (effect->speed > 0) == (effect->speed_delta > 0) ) { effect->speed_delta = -effect->speed_delta; } - effect->timestamp = LCUI_GetTickCount(); + effect->timestamp = LCUI_GetTime(); if( effect->is_running ) { return; } diff --git a/src/timer.c b/src/timer.c index 5cbd6443..ac16c26c 100644 --- a/src/timer.c +++ b/src/timer.c @@ -82,11 +82,11 @@ static void TimerList_AddNode( LinkedListNode *node ) LinkedListNode *cur; /* 计算该定时器的剩余定时时长 */ timer = node->data; - t = LCUI_GetTicks( timer->start_time ); + t = LCUI_GetTimeDelta( timer->start_time ); t = timer->total_ms - t + timer->pause_ms; for( LinkedList_Each( cur, &self.timer_list ) ) { timer = cur->data; - tt = LCUI_GetTicks( timer->start_time ); + tt = LCUI_GetTimeDelta( timer->start_time ); tt = timer->total_ms - tt + timer->pause_ms; if( t <= tt ) { LinkedList_Link( &self.timer_list, cur->prev, node ); @@ -108,7 +108,7 @@ static void TimerList_Print( void ) for( LinkedList_Each( node, &self.timer_list ) { timer = node->data; _DEBUG_MSG("[%02d] %ld, func: %p, cur_ms: %ldms, total_ms: %ldms\n", - i++, timer->id, timer->func, timer->total_ms - (long int)LCUI_GetTicks(timer->start_time), timer->total_ms ); + i++, timer->id, timer->func, timer->total_ms - (long int)LCUI_GetTimeDelta(timer->start_time), timer->total_ms ); } _DEBUG_MSG("timer list end\n\n"); } @@ -138,7 +138,7 @@ static void TimerThread( void *arg ) LCUIMutex_Lock( &self.mutex ); continue; } - lost_ms = LCUI_GetTicks( timer->start_time ); + lost_ms = LCUI_GetTimeDelta( timer->start_time ); /* 减去处于暂停状态的时长 */ lost_ms -= timer->pause_ms; /* 若流失的时间未达到总定时时长,则睡眠一段时间 */ @@ -155,7 +155,7 @@ static void TimerThread( void *arg ) LinkedList_Unlink( &self.timer_list, node ); if( timer->reuse ) { timer->pause_ms = 0; - timer->start_time = LCUI_GetTickCount(); + timer->start_time = LCUI_GetTime(); TimerList_AddNode( node ); } else { free( timer ); @@ -199,7 +199,7 @@ int LCUITimer_Set( long int n_ms, void (*func)(void*), timer->total_ms = n_ms; timer->state = STATE_RUN; timer->id = ++self.id_count; - timer->start_time = LCUI_GetTickCount(); + timer->start_time = LCUI_GetTime(); timer->node.next = NULL; timer->node.prev = NULL; timer->node.data = timer; @@ -239,7 +239,7 @@ int LCUITimer_Pause( int timer_id ) timer = TimerList_Find( timer_id ); if( timer ) { /* 记录暂停时的时间 */ - timer->pause_time = LCUI_GetTickCount(); + timer->pause_time = LCUI_GetTime(); timer->state = STATE_PAUSE; } LCUICond_Signal( &self.sleep_cond ); @@ -257,7 +257,7 @@ int LCUITimer_Continue( int timer_id ) timer = TimerList_Find( timer_id ); if( timer ) { /* 计算处于暂停状态的时长 */ - timer->pause_ms += (long int)LCUI_GetTicks( timer->pause_time ); + timer->pause_ms += (long int)LCUI_GetTimeDelta( timer->pause_time ); timer->state = STATE_RUN; } LCUICond_Signal( &self.sleep_cond ); @@ -276,7 +276,7 @@ int LCUITimer_Reset( int timer_id, long int n_ms ) if( timer ) { timer->pause_ms = 0; timer->total_ms = n_ms; - timer->start_time = LCUI_GetTickCount(); + timer->start_time = LCUI_GetTime(); } LCUICond_Signal( &self.sleep_cond ); LCUIMutex_Unlock( &self.mutex ); @@ -285,7 +285,7 @@ int LCUITimer_Reset( int timer_id, long int n_ms ) void LCUI_InitTimer( void ) { - LCUI_StartTicks(); + LCUITime_Init(); LCUIMutex_Init( &self.mutex ); LCUICond_Init( &self.sleep_cond ); LinkedList_Init( &self.timer_list ); diff --git a/src/util/delay.c b/src/util/delay.c deleted file mode 100644 index 94de0240..00000000 --- a/src/util/delay.c +++ /dev/null @@ -1,69 +0,0 @@ -/* *************************************************************************** - * delay.c -- time delay function. - * - * Copyright (C) 2012-2013 by - * Liu Chao - * - * 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 . - * ****************************************************************************/ - -/* **************************************************************************** - * delay.c -- 一些提供延时功能的函数 - * - * 版权所有 (C) 2013 归属于 - * 刘超 - * - * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 - * - * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) - * - * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 - * - * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 - * 定用途的隐含担保,详情请参照GPLv2许可协议。 - * - * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 - * 没有,请查看:. - * ****************************************************************************/ -#include -#include - -#ifdef LCUI_BUILD_IN_WIN32 -#include -#else -#include -#endif -/* 秒级延时 */ -LCUI_API void -LCUI_Sleep( unsigned int s ) -{ -#ifdef LCUI_BUILD_IN_WIN32 - Sleep(s*1000); -#else - sleep(s); -#endif -} - -/* 毫秒级延时 */ -LCUI_API void -LCUI_MSleep( unsigned int ms ) -{ -#ifdef LCUI_BUILD_IN_WIN32 - Sleep(ms); -#else - usleep(ms*1000); -#endif -} diff --git a/src/util/dict.c b/src/util/dict.c index f9dbe809..025760ce 100644 --- a/src/util/dict.c +++ b/src/util/dict.c @@ -222,7 +222,7 @@ int Dict_Rehash( Dict *d, int n ) return 1; } -#define timeInMilliseconds LCUI_GetTickCount +#define timeInMilliseconds LCUI_GetTime int Dict_RehashMilliseconds( Dict *d, int ms ) { diff --git a/src/util/framectrl.c b/src/util/framectrl.c index da180df5..bf7b4b55 100644 --- a/src/util/framectrl.c +++ b/src/util/framectrl.c @@ -71,8 +71,8 @@ FrameControl FrameControl_Create( void ) ctx->current_fps = 0; ctx->pause_time = 0; ctx->one_frame_remain_time = 10; - ctx->prev_frame_start_time = LCUI_GetTickCount(); - ctx->prev_fps_update_time = LCUI_GetTickCount(); + ctx->prev_frame_start_time = LCUI_GetTime(); + ctx->prev_fps_update_time = LCUI_GetTime(); LCUICond_Init( &ctx->cond ); LCUIMutex_Init( &ctx->mutex ); return ctx; @@ -105,7 +105,7 @@ void FrameControl_Remain( FrameControl ctx ) return; } lost_ms = 0; - current_time = LCUI_GetTickCount(); + current_time = LCUI_GetTime(); LCUIMutex_Lock( &ctx->mutex ); n_ms = (unsigned int)(current_time - ctx->prev_frame_start_time); if( n_ms > ctx->one_frame_remain_time ) { @@ -118,16 +118,16 @@ void FrameControl_Remain( FrameControl ctx ) /* 睡眠一段时间 */ while( lost_ms < n_ms && ctx->state == STATE_RUN ) { LCUICond_TimedWait( &ctx->cond, &ctx->mutex, n_ms - lost_ms ); - lost_ms = (unsigned int)LCUI_GetTicks( current_time ); + lost_ms = (unsigned int)LCUI_GetTimeDelta( current_time ); } /* 睡眠结束后,如果当前状态为 PAUSE,则说明睡眠是因为要暂停而终止的 */ if( ctx->state == STATE_PAUSE ) { - current_time = LCUI_GetTickCount(); + current_time = LCUI_GetTime(); /* 等待状态改为“继续” */ while( ctx->state == STATE_PAUSE ) { LCUICond_Wait( &ctx->cond, &ctx->mutex ); } - lost_ms = (unsigned int)LCUI_GetTicks( current_time ); + lost_ms = (unsigned int)LCUI_GetTimeDelta( current_time ); ctx->pause_time = lost_ms; ctx->prev_frame_start_time += lost_ms; LCUIMutex_Unlock( &ctx->mutex ); @@ -135,7 +135,7 @@ void FrameControl_Remain( FrameControl ctx ) } normal_exit:; - current_time = LCUI_GetTickCount(); + current_time = LCUI_GetTime(); if( current_time - ctx->prev_fps_update_time >= 1000 ) { ctx->current_fps = ctx->temp_fps; ctx->prev_fps_update_time = current_time; diff --git a/src/util/time.c b/src/util/time.c index 6999c5a9..2cdc70ee 100644 --- a/src/util/time.c +++ b/src/util/time.c @@ -1,4 +1,42 @@ - +/* *************************************************************************** +* time.c -- The time operation set. +* +* Copyright (C) 2015-2016 by Liu Chao +* +* 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 . +* ****************************************************************************/ + +/* **************************************************************************** +* time.c -- 时间相关函数集 +* +* 版权所有 (C) 2015-2016 归属于 刘超 +* +* 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 +* +* (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) +* +* 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 +* +* LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 +* 定用途的隐含担保,详情请参照GPLv2许可协议。 +* +* 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 +* 没有,请查看:. +* ****************************************************************************/ + #include #include #include @@ -14,7 +52,7 @@ static int hires_timer_available; /**< 标志,指示高精度计数器是否可用 */ static double hires_ticks_per_second; /**< 高精度计数器每秒的滴答数 */ -void LCUI_StartTicks( void ) +void LCUITime_Init( void ) { LARGE_INTEGER hires; if( QueryPerformanceFrequency(&hires) ) { @@ -26,11 +64,11 @@ void LCUI_StartTicks( void ) } } -int64_t LCUI_GetTickCount( void ) +int64_t LCUI_GetTime( void ) { LARGE_INTEGER hires_now; - if (hires_timer_available) { - QueryPerformanceCounter(&hires_now); + if( hires_timer_available ) { + QueryPerformanceCounter( &hires_now ); hires_now.QuadPart *= 1000; hires_now.QuadPart /= hires_ticks_per_second; return (int64_t)hires_now.QuadPart; @@ -39,14 +77,16 @@ int64_t LCUI_GetTickCount( void ) } #elif defined LCUI_BUILD_IN_LINUX +#include #include -void LCUI_StartTicks( void ) + +void LCUITime_Init( void ) { return; } -int64_t LCUI_GetTickCount( void ) +int64_t LCUI_GetTime( void ) { int64_t t; struct timeval tv; @@ -58,13 +98,29 @@ int64_t LCUI_GetTickCount( void ) #endif -int64_t LCUI_GetTicks( int64_t start_ticks ) +int64_t LCUI_GetTimeDelta( int64_t start ) { - int64_t now_ticks; - - now_ticks = LCUI_GetTickCount(); - if ( now_ticks < start_ticks ) { - return (TIME_WRAP_VALUE-start_ticks) + now_ticks; + int64_t now = LCUI_GetTime(); + if( now < start ) { + return (TIME_WRAP_VALUE - start) + now; } - return now_ticks - start_ticks; + return now - start; +} + +void LCUI_Sleep( unsigned int s ) +{ +#ifdef LCUI_BUILD_IN_WIN32 + Sleep( s * 1000 ); +#else + sleep( s ); +#endif +} + +void LCUI_MSleep( unsigned int ms ) +{ +#ifdef LCUI_BUILD_IN_WIN32 + Sleep( ms ); +#else + usleep( ms * 1000 ); +#endif } From 4488b87de736529ab48e784e230da7131382902e Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Thu, 18 Aug 2016 23:11:52 +0800 Subject: [PATCH 103/124] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=BA=A2=E9=BB=91?= =?UTF-8?q?=E6=A0=91=E7=9A=84=E6=93=8D=E4=BD=9C=E5=87=BD=E6=95=B0=E3=80=81?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=85=B6=E5=AE=83=E5=9C=B0=E6=96=B9=E7=9A=84?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/util/rbtree.h | 14 +++------- src/display.c | 18 ++++++------- src/font/fontlibrary.c | 4 +-- src/gui/builder.c | 2 +- src/gui/css_parser.c | 4 +-- src/gui/widget_background.c | 4 +-- src/gui/widget_event.c | 2 +- src/gui/widget_library.c | 2 +- src/util/rbtree.c | 53 ++++++++++++++++++++++++------------- src/util/string.c | 5 ++-- 10 files changed, 58 insertions(+), 50 deletions(-) diff --git a/include/LCUI/util/rbtree.h b/include/LCUI/util/rbtree.h index 2f19be2f..440e2b4c 100644 --- a/include/LCUI/util/rbtree.h +++ b/include/LCUI/util/rbtree.h @@ -56,32 +56,24 @@ struct LCUI_RBTreeNodeRec_ { typedef struct LCUI_RBTreeRec_ { int total_node; - int (*judge)(void*, const void*); + int (*compare)(void*, const void*); void (*destroy)(void*); LCUI_RBTreeNode *root; } LCUI_RBTree; #define RBTree_GetTotal(rbt) (rbt)->total_node; -#define RBTree_OnJudge(rbt, func) (rbt)->judge = func +#define RBTree_OnCompare(rbt, func) (rbt)->compare = func #define RBTree_OnDestroy(rbt, func) (rbt)->destroy = func -/** 初始化红黑树 */ LCUI_API void RBTree_Init( LCUI_RBTree *rbt ); - -/** 销毁红黑树 */ LCUI_API void RBTree_Destroy( LCUI_RBTree *rbt ); - -/** 获取第一个结点 */ LCUI_API LCUI_RBTreeNode *RBTree_First( const LCUI_RBTree *rbt ); - -/** 获取下一个结点 */ LCUI_API LCUI_RBTreeNode *RBTree_Next( const LCUI_RBTreeNode *node ); - LCUI_API LCUI_RBTreeNode* RBTree_Search( LCUI_RBTree* rbt, int key ); LCUI_API void* RBTree_GetData( LCUI_RBTree* rbt, int key ); LCUI_API LCUI_RBTreeNode* RBTree_Insert( LCUI_RBTree *rbt, int key, void *data ); LCUI_API int RBTree_Erase( LCUI_RBTree *rbt, int key ); - +LCUI_API void RBTree_EraseNode( LCUI_RBTree *rbt, LCUI_RBTreeNode *node ); LCUI_API int RBTree_CustomErase( LCUI_RBTree *rbt, const void *keydata ); LCUI_API LCUI_RBTreeNode* RBTree_CustomSearch( LCUI_RBTree* rbt, const void *keydata ); LCUI_API void* RBTree_CustomGetData( LCUI_RBTree* rbt, const void *keydata ); diff --git a/src/display.c b/src/display.c index c2000ef9..6377b7e9 100644 --- a/src/display.c +++ b/src/display.c @@ -104,7 +104,7 @@ static void LCUIDisplay_Update(void) LCUI_PaintContext paint; LinkedList_Init( &rlist ); /* 遍历当前的 surface 记录列表 */ - LinkedList_ForEach( sn, &display.surfaces ) { + for( LinkedList_Each( sn, &display.surfaces ) ) { p_sr = sn->data; if( !p_sr->widget || !p_sr->surface || !Surface_IsReady(p_sr->surface) ) { @@ -114,7 +114,7 @@ static void LCUIDisplay_Update(void) /* 收集无效区域记录 */ Widget_ProcInvalidArea( p_sr->widget, &rlist ); /* 在 surface 上逐个重绘无效区域 */ - LinkedList_ForEach( rn, &rlist ) { + for( LinkedList_Each( rn, &rlist ) ) { paint = Surface_BeginPaint( p_sr->surface, rn->data ); if( !paint ) { continue; @@ -136,7 +136,7 @@ static void LCUIDisplay_Update(void) LinkedList_Clear( &rlist, free ); } -void LCUIDisplay_InvalidateArea(LCUI_Rect *rect ) +void LCUIDisplay_InvalidateArea( LCUI_Rect *rect ) { } @@ -145,7 +145,7 @@ static LCUI_Widget LCUIDisplay_GetBindWidget( LCUI_Surface surface ) { SurfaceRecord *sr; LinkedListNode *node; - LinkedList_ForEach( node, &display.surfaces ) { + for( LinkedList_Each( node, &display.surfaces ) ) { sr = node->data; if( sr && sr->surface == surface ) { return sr->widget; @@ -158,7 +158,7 @@ static LCUI_Surface LCUIDisplay_GetBindSurface( LCUI_Widget widget ) { SurfaceRecord *sr; LinkedListNode *node; - LinkedList_ForEach( node, &display.surfaces ) { + for( LinkedList_Each( node, &display.surfaces ) ) { sr = node->data; if( sr && sr->widget == widget ) { return sr->surface; @@ -211,7 +211,7 @@ static void LCUIDisplay_UnbindSurface( LCUI_Widget widget ) { SurfaceRecord *sr; LinkedListNode *node; - LinkedList_ForEach( node, &display.surfaces ) { + for( LinkedList_Each( node, &display.surfaces ) ) { sr = node->data; if( sr && sr->widget == widget ) { Surface_Delete( sr->surface ); @@ -225,7 +225,7 @@ static void LCUIDisplay_CleanSurfaces( void ) { SurfaceRecord *sr; LinkedListNode *node; - LinkedList_ForEach( node, &display.surfaces ) { + for( LinkedList_Each( node, &display.surfaces ) ) { sr = node->data; Surface_Delete( sr->surface ); LinkedList_DeleteNode( &display.surfaces, node ); @@ -283,7 +283,7 @@ static int LCUIDisplay_Seamless( void ) LCUIDisplay_CleanSurfaces(); break; } - LinkedList_ForEach( node, &root->children ) { + for( LinkedList_Each( node, &root->children ) ) { LCUIDisplay_BindSurface( node->data ); } display.mode = LCDM_SEAMLESS; @@ -567,7 +567,7 @@ static void OnPaint( LCUI_Event e, void *arg ) SurfaceRecord *sr; LinkedListNode *node; LCUI_DisplayEvent dpy_ev = arg; - LinkedList_ForEach( node, &display.surfaces ) { + for( LinkedList_Each( node, &display.surfaces ) ) { sr = node->data; if( sr && sr->surface != dpy_ev->surface ) { continue; diff --git a/src/font/fontlibrary.c b/src/font/fontlibrary.c index 66c85ecc..c197eddb 100644 --- a/src/font/fontlibrary.c +++ b/src/font/fontlibrary.c @@ -629,8 +629,8 @@ void LCUI_InitFont( void ) RBTree_Init( &fontlib.bitmap_cache ); RBTree_Init( &fontlib.path_map ); RBTree_Init( &fontlib.family_tree ); - RBTree_OnJudge( &fontlib.path_map, OnComparePath ); - RBTree_OnJudge( &fontlib.family_tree, OnCompareFamily ); + RBTree_OnCompare( &fontlib.path_map, OnComparePath ); + RBTree_OnCompare( &fontlib.family_tree, OnCompareFamily ); RBTree_OnDestroy( &fontlib.path_map, DestroyFontPathNode ); RBTree_OnDestroy( &fontlib.family_tree, DestroyFontFamilyNode ); RBTree_OnDestroy( &fontlib.bitmap_cache, DestroyTreeNode ); diff --git a/src/gui/builder.c b/src/gui/builder.c index 5738e473..630943e0 100644 --- a/src/gui/builder.c +++ b/src/gui/builder.c @@ -219,7 +219,7 @@ static void LCUIBuilder_Init( void ) Parser *p; RBTree_Init( &self.parsers ); - RBTree_OnJudge( &self.parsers, CompareName ); + RBTree_OnCompare( &self.parsers, CompareName ); len = sizeof(parser_list) / sizeof(parser_list[0]); for( i = 0; i < len; ++i ) { p = &parser_list[i]; diff --git a/src/gui/css_parser.c b/src/gui/css_parser.c index 5fc0cd23..8127c19f 100644 --- a/src/gui/css_parser.c +++ b/src/gui/css_parser.c @@ -959,8 +959,8 @@ void LCUICSS_Init( void ) RBTree_Init( &self.option_tree ); RBTree_Init( &self.option_name_tree ); RBTree_OnDestroy( &self.parser_tree, OnDestroyStyleParser ); - RBTree_OnJudge( &self.parser_tree, CompareParserName ); - RBTree_OnJudge( &self.option_tree, CompareName ); + 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 ) { diff --git a/src/gui/widget_background.c b/src/gui/widget_background.c index 9e7dae27..7b761a04 100644 --- a/src/gui/widget_background.c +++ b/src/gui/widget_background.c @@ -129,8 +129,8 @@ static void AsyncLoadImage( LCUI_Widget widget, const char *path ) if( !is_inited ) { RBTree_Init( &images ); RBTree_Init( &refs ); - RBTree_OnJudge( &refs, OnCompareWidget ); - RBTree_OnJudge( &images, OnComparePath ); + RBTree_OnCompare( &refs, OnCompareWidget ); + RBTree_OnCompare( &images, OnComparePath ); RBTree_OnDestroy( &refs, free ); RBTree_OnDestroy( &images, OnDestroyCache ); is_inited = TRUE; diff --git a/src/gui/widget_event.c b/src/gui/widget_event.c index 70f26382..e9abd29a 100644 --- a/src/gui/widget_event.c +++ b/src/gui/widget_event.c @@ -1007,7 +1007,7 @@ void LCUIWidget_InitEvent(void) LCUI_BindEvent( LCUI_KEYUP, OnKeyboardEvent, NULL, NULL ); LCUI_BindEvent( LCUI_TOUCH, OnTouch, NULL, NULL ); LCUI_BindEvent( LCUI_TEXTINPUT, OnTextInput, NULL, NULL ); - RBTree_OnJudge( &self.event_records, CompareEventRecord ); + RBTree_OnCompare( &self.event_records, CompareEventRecord ); LinkedList_Init( &self.touch_capturers ); } diff --git a/src/gui/widget_library.c b/src/gui/widget_library.c index 543aaedb..ce3a6a3c 100644 --- a/src/gui/widget_library.c +++ b/src/gui/widget_library.c @@ -60,7 +60,7 @@ static void OnDestroyWidgetClass( void *arg ) void LCUIWidget_InitLibrary(void) { RBTree_Init( &widget_class_library ); - RBTree_OnJudge( &widget_class_library, CompareName ); + RBTree_OnCompare( &widget_class_library, CompareName ); RBTree_OnDestroy( &widget_class_library, OnDestroyWidgetClass ); } diff --git a/src/util/rbtree.c b/src/util/rbtree.c index b111a67c..6b477ac4 100644 --- a/src/util/rbtree.c +++ b/src/util/rbtree.c @@ -55,7 +55,7 @@ void RBTree_Init( LCUI_RBTree *rbt ) { rbt->root = NULL; - rbt->judge = NULL; + rbt->compare = NULL; rbt->destroy = NULL; rbt->total_node = 0; } @@ -280,18 +280,18 @@ rb_search_auxiliary( LCUI_RBTreeNode *root, int key, const void *keydata, LCUI_RBTreeNode* RBTree_CustomSearch( LCUI_RBTree* rbt, const void *keydata ) { - return rb_search_auxiliary( rbt->root, 0, keydata, rbt->judge, NULL ); + return rb_search_auxiliary( rbt->root, 0, keydata, rbt->compare, NULL ); } LCUI_RBTreeNode* RBTree_Search( LCUI_RBTree* rbt, int key ) { - return rb_search_auxiliary( rbt->root, key, NULL, rbt->judge, NULL ); + return rb_search_auxiliary( rbt->root, key, NULL, rbt->compare, NULL ); } void* RBTree_CustomGetData( LCUI_RBTree* rbt, const void *keydata ) { LCUI_RBTreeNode *node; - node = rb_search_auxiliary( rbt->root, 0, keydata, rbt->judge, NULL ); + node = rb_search_auxiliary( rbt->root, 0, keydata, rbt->compare, NULL ); if( node ) { return node->data; } @@ -301,7 +301,7 @@ void* RBTree_CustomGetData( LCUI_RBTree* rbt, const void *keydata ) void* RBTree_GetData( LCUI_RBTree* rbt, int key ) { LCUI_RBTreeNode *node; - node = rb_search_auxiliary( rbt->root, key, NULL, rbt->judge, NULL ); + node = rb_search_auxiliary( rbt->root, key, NULL, rbt->compare, NULL ); if( node ) { return node->data; } @@ -315,7 +315,7 @@ rb_insert( LCUI_RBTree *rbt, int key, const void *keydata, void *data ) parent_node = NULL; root = rbt->root; - node = rb_search_auxiliary( root, key, keydata, rbt->judge, &parent_node ); + node = rb_search_auxiliary( root, key, keydata, rbt->compare, &parent_node ); if( node ) { return NULL; } @@ -329,8 +329,8 @@ rb_insert( LCUI_RBTree *rbt, int key, const void *keydata, void *data ) node->color = RED; if( parent_node ) { - if( rbt->judge && keydata ) { - if( rbt->judge( parent_node->data, keydata ) > 0 ) { + if( rbt->compare && keydata ) { + if( rbt->compare( parent_node->data, keydata ) > 0 ) { parent_node->left = node; } else { parent_node->right = node; @@ -441,20 +441,15 @@ rb_erase_rebalance( LCUI_RBTreeNode *node, LCUI_RBTreeNode *parent, return root; } -/** 删除红黑树中的结点 */ -static int rb_erase( LCUI_RBTree *rbt, int key, const void *keydata ) +static void rb_erase_by_node( LCUI_RBTree *rbt, LCUI_RBTreeNode *node ) { unsigned char color; - LCUI_RBTreeNode *root, *child = NULL, *parent, *old, *left, *node; - - root = rbt->root; - /* 查找要删除的结点 */ - node = rb_search_auxiliary( root, key, keydata, rbt->judge, NULL ); - if( !node ) { - return -1; - } - old = node; + LCUI_RBTreeNode *parent; + LCUI_RBTreeNode *old = node; + LCUI_RBTreeNode *child = NULL; + LCUI_RBTreeNode *root = rbt->root; if( node->left && node->right ) { + LCUI_RBTreeNode *left; node = node->right; while( (left = node->left) != NULL ) { node = left; @@ -532,6 +527,21 @@ static int rb_erase( LCUI_RBTree *rbt, int key, const void *keydata ) } rbt->root = root; rbt->total_node -= 1; +} + +/** 删除红黑树中的结点 */ +static int rb_erase( LCUI_RBTree *rbt, int key, const void *keydata ) +{ + unsigned char color; + LCUI_RBTreeNode *root, *child = NULL, *parent, *old, *left, *node; + + root = rbt->root; + /* 查找要删除的结点 */ + node = rb_search_auxiliary( root, key, keydata, rbt->compare, NULL ); + if( !node ) { + return -1; + } + rb_erase_by_node( rbt, node ); return 0; } @@ -540,6 +550,11 @@ int RBTree_Erase( LCUI_RBTree *rbt, int key ) return rb_erase( rbt, key, NULL ); } +void RBTree_EraseNode( LCUI_RBTree *rbt, LCUI_RBTreeNode *node ) +{ + rb_erase_by_node( rbt, node ); +} + int RBTree_CustomErase( LCUI_RBTree *rbt, const void *keydata ) { return rb_erase( rbt, 0, keydata ); diff --git a/src/util/string.c b/src/util/string.c index 10125462..00e653d9 100644 --- a/src/util/string.c +++ b/src/util/string.c @@ -1,7 +1,7 @@ /* *************************************************************************** * string.c -- The string operation set. * - * Copyright (C) 2015 by Liu Chao + * Copyright (C) 2015-2016 by Liu Chao * * 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.c -- 字符串相关操作函数。 * - * 版权所有 (C) 2015 归属于 刘超 + * 版权所有 (C) 2015-2016 归属于 刘超 * * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 * @@ -38,6 +38,7 @@ * ****************************************************************************/ #include +#include #include #include From ab27556500fd298027324d77209a491fee20ace4 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Thu, 18 Aug 2016 23:57:45 +0800 Subject: [PATCH 104/124] =?UTF-8?q?=E9=98=9F=E5=88=97=E5=8C=96=E9=83=A8?= =?UTF-8?q?=E4=BB=B6=E4=BB=BB=E5=8A=A1=E7=9A=84=E5=A4=84=E7=90=86=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E5=8A=A0=E5=85=A5=E8=B6=85=E6=97=B6=E4=B8=AD=E6=96=AD?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/gui/widget_base.h | 1 - include/LCUI/gui/widget_task.h | 12 +- src/gui/widget_base.c | 11 +- src/gui/widget_task.c | 211 ++++++++++++++++++++------------- 4 files changed, 144 insertions(+), 91 deletions(-) diff --git a/include/LCUI/gui/widget_base.h b/include/LCUI/gui/widget_base.h index 544f4167..4ccb1a08 100755 --- a/include/LCUI/gui/widget_base.h +++ b/include/LCUI/gui/widget_base.h @@ -209,7 +209,6 @@ typedef struct LCUI_WidgetBoxRect { typedef struct LCUI_WidgetTaskBoxRec_ { LCUI_BOOL for_self; /**< 标志,指示当前部件是否有待处理的任务 */ - LCUI_BOOL for_children; /**< 标志,指示是否有待处理的子级部件 */ LCUI_BOOL buffer[WTT_TOTAL_NUM]; /**< 记录缓存 */ } LCUI_WidgetTaskBoxRec; diff --git a/include/LCUI/gui/widget_task.h b/include/LCUI/gui/widget_task.h index 7d9fbe0e..d5da2dea 100644 --- a/include/LCUI/gui/widget_task.h +++ b/include/LCUI/gui/widget_task.h @@ -48,17 +48,23 @@ LCUI_API void Widget_UpdateTaskStatus( LCUI_Widget widget ); /** 添加任务 */ LCUI_API void Widget_AddTask( LCUI_Widget widget, int task_type ); +/** 将部件标记为垃圾,等待销毁 */ +LCUI_API void Widget_AddToTrash( LCUI_Widget w ); + /** 为子级部件添加任务 */ LCUI_API void Widget_AddTaskForChildren( LCUI_Widget widget, int task ); +/** 移除指定部件的任务记录 */ +LCUI_API void LCUIWidget_ClearTaskTarget( LCUI_Widget w ); + /** 初始化 LCUI 部件任务处理功能 */ -void LCUIWidget_InitTask(void); +void LCUIWidget_InitTask( void ); /** 销毁(释放) LCUI 部件任务处理功能的相关资源 */ -void LCUIWidget_ExitTask(void); +void LCUIWidget_ExitTask( void ); /** 处理一次当前积累的部件任务 */ -void LCUIWidget_StepTask(void); +void LCUIWidget_StepTask( void ); LCUI_END_HEADER diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index db614683..6c637c7d 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -372,6 +372,7 @@ void Widget_ExecDestroy( LCUI_Widget widget ) Widget_ReleaseTouchCapture( widget, -1 ); Widget_StopEventPropagation( widget ); LCUIWidget_ClearEventTarget( widget ); + LCUIWidget_ClearTaskTarget( widget ); if( wc && wc->methods.destroy ) { wc->methods.destroy( widget ); } @@ -417,7 +418,7 @@ void Widget_Destroy( LCUI_Widget w ) } if( w->parent ) { LCUI_Widget child; - LinkedListNode *node, *snode; + LinkedListNode *node; node = Widget_GetNode( w ); node = node->next; while( node ) { @@ -425,15 +426,11 @@ void Widget_Destroy( LCUI_Widget w ) child->index -= 1; node = node->next; } - node = Widget_GetNode( w ); - snode = Widget_GetShowNode( w ); - LinkedList_Unlink( &w->parent->children, node ); - LinkedList_Unlink( &w->parent->children_show, snode ); - LinkedList_AppendNode( &w->parent->children_trash, node ); if( w->computed_style.position != SV_ABSOLUTE ) { Widget_UpdateLayout( w->parent ); } Widget_PushInvalidArea( w, NULL, SV_GRAPH_BOX ); + Widget_AddToTrash( w ); } } @@ -1648,7 +1645,7 @@ void LCUI_InitWidget( void ) LCUIWidget_AddTScrollBar(); LCUIWidget_AddTextEdit(); RBTree_Init( &LCUIWidget.ids ); - RBTree_OnJudge( &LCUIWidget.ids, CompareWidgetId ); + RBTree_OnCompare( &LCUIWidget.ids, CompareWidgetId ); LCUIWidget.root = LCUIWidget_New("root"); Widget_SetTitleW( LCUIWidget.root, L"LCUI Display" ); } diff --git a/src/gui/widget_task.c b/src/gui/widget_task.c index e63f5ca6..3ee104f7 100644 --- a/src/gui/widget_task.c +++ b/src/gui/widget_task.c @@ -38,12 +38,28 @@ * ***************************************************************************/ //#define DEBUG +#include #include #include #include #include #include +typedef void (*callback)(LCUI_Widget); + +typedef struct WidgetTaskIndexRec_ { + LCUI_Widget widget; + LinkedListNode node; +} WidgetTaskIndexRec, *WidgetTaskIndex; + +static struct LCUIWidgetTaskModule { + LinkedList tasks; + LCUI_RBTree indexes; + LCUI_Mutex mutex; + LinkedList trash; + callback handlers[WTT_TOTAL_NUM]; +} self; + static void HandleRefreshStyle( LCUI_Widget w ) { Widget_ExecUpdateStyle( w, TRUE ); @@ -88,20 +104,15 @@ void Widget_UpdateTaskStatus( LCUI_Widget widget ) for( i = 0; i < WTT_TOTAL_NUM; ++i ) { if( widget->task.buffer[i] ) { widget->task.for_self = TRUE; + Widget_AddTask( widget, widget->task.buffer[i] ); } } - widget = widget->parent; - while( widget ) { - widget->task.for_children = TRUE; - widget = widget->parent; - } } void Widget_AddTaskForChildren( LCUI_Widget widget, int task ) { LCUI_Widget child; LinkedListNode *node; - widget->task.for_children = TRUE; for( LinkedList_Each( node, &widget->children ) ) { child = node->data; Widget_AddTask( child, task ); @@ -109,6 +120,19 @@ void Widget_AddTaskForChildren( LCUI_Widget widget, int task ) } } +void LCUIWidget_ClearTaskTarget( LCUI_Widget w ) +{ + WidgetTaskIndex idx; + LCUIMutex_Lock( &self.mutex ); + idx = RBTree_CustomGetData( &self.indexes, w ); + if( idx ) { + LinkedList_Unlink( &self.tasks, &idx->node ); + RBTree_CustomErase( &self.indexes, w ); + free( idx ); + } + LCUIMutex_Unlock( &self.mutex ); +} + void Widget_AddTask( LCUI_Widget widget, int task ) { if( widget->state == WSTATE_DELETED ) { @@ -116,65 +140,84 @@ void Widget_AddTask( LCUI_Widget widget, int task ) } widget->task.for_self = TRUE; widget->task.buffer[task] = TRUE; - widget = widget->parent; - /* 向没有标记的父级部件添加标记 */ - while( widget && !widget->task.for_children ) { - widget->task.for_children = TRUE; - widget = widget->parent; + LCUIMutex_Lock( &self.mutex ); + if( !RBTree_CustomGetData( &self.indexes, widget ) ) { + WidgetTaskIndex idx = NEW( WidgetTaskIndexRec, 1 ); + idx->widget = widget; + idx->node.data = widget; + RBTree_CustomInsert( &self.indexes, widget, idx ); + LinkedList_AppendNode( &self.tasks, &idx->node ); } + LCUIMutex_Unlock( &self.mutex ); } -typedef void (*callback)(LCUI_Widget); - -static callback task_handlers[WTT_TOTAL_NUM]; - /** 映射任务处理器 */ static void MapTaskHandler(void) { - task_handlers[WTT_VISIBLE] = Widget_UpdateVisibility; - task_handlers[WTT_POSITION] = Widget_UpdatePosition; - task_handlers[WTT_RESIZE] = Widget_UpdateSize; - task_handlers[WTT_SHADOW] = Widget_UpdateBoxShadow; - task_handlers[WTT_BORDER] = Widget_UpdateBorder; - task_handlers[WTT_OPACITY] = Widget_UpdateOpacity; - task_handlers[WTT_BODY] = HandleBody; - task_handlers[WTT_TITLE] = HandleSetTitle; - task_handlers[WTT_REFRESH] = HandleRefresh; - task_handlers[WTT_UPDATE_STYLE] = HandleUpdateStyle; - task_handlers[WTT_REFRESH_STYLE] = HandleRefreshStyle; - task_handlers[WTT_CACHE_STYLE] = HandleCacheStyle; - task_handlers[WTT_BACKGROUND] = Widget_UpdateBackground; - task_handlers[WTT_LAYOUT] = Widget_ExecUpdateLayout; - task_handlers[WTT_ZINDEX] = Widget_ExecUpdateZIndex; - task_handlers[WTT_PROPS] = Widget_UpdateProps; + self.handlers[WTT_VISIBLE] = Widget_UpdateVisibility; + self.handlers[WTT_POSITION] = Widget_UpdatePosition; + self.handlers[WTT_RESIZE] = Widget_UpdateSize; + self.handlers[WTT_SHADOW] = Widget_UpdateBoxShadow; + self.handlers[WTT_BORDER] = Widget_UpdateBorder; + self.handlers[WTT_OPACITY] = Widget_UpdateOpacity; + self.handlers[WTT_BODY] = HandleBody; + self.handlers[WTT_TITLE] = HandleSetTitle; + self.handlers[WTT_REFRESH] = HandleRefresh; + self.handlers[WTT_UPDATE_STYLE] = HandleUpdateStyle; + self.handlers[WTT_REFRESH_STYLE] = HandleRefreshStyle; + self.handlers[WTT_CACHE_STYLE] = HandleCacheStyle; + self.handlers[WTT_BACKGROUND] = Widget_UpdateBackground; + self.handlers[WTT_LAYOUT] = Widget_ExecUpdateLayout; + self.handlers[WTT_ZINDEX] = Widget_ExecUpdateZIndex; + self.handlers[WTT_PROPS] = Widget_UpdateProps; } -/** 初始化 LCUI 部件任务处理功能 */ -void LCUIWidget_InitTask(void) +static int OnCompareIndex( void *data, const void *keydata ) +{ + return ((WidgetTaskIndex)data)->widget - (LCUI_Widget)keydata; +} + +void LCUIWidget_InitTask( void ) { MapTaskHandler(); + LCUIMutex_Init( &self.mutex ); + LinkedList_Init( &self.tasks ); + LinkedList_Init( &self.trash ); + RBTree_Init( &self.indexes ); + RBTree_OnCompare( &self.indexes, OnCompareIndex ); } -/** 销毁(释放) LCUI 部件任务处理功能的相关资源 */ -void LCUIWidget_ExitTask(void) +void LCUIWidget_ExitTask( void ) { + LCUIMutex_Lock( &self.mutex ); + LinkedList_Clear( &self.tasks, NULL ); + RBTree_Destroy( &self.indexes ); + LCUIMutex_Unlock( &self.mutex ); + LCUIMutex_Destroy( &self.mutex ); +} +void Widget_AddToTrash( LCUI_Widget w ) +{ + LinkedListNode *snode, *node; + + if( !w->parent ) { + return; + } + node = Widget_GetNode( w ); + snode = Widget_GetShowNode( w ); + LinkedList_Unlink( &w->parent->children, node ); + LinkedList_Unlink( &w->parent->children_show, snode ); + LinkedList_AppendNode( &self.trash, node ); } -/** 处理部件中当前积累的任务 */ int Widget_Update( LCUI_Widget w ) { - int ret = 1, i; + int i; LCUI_BOOL *buffer; - LCUI_Widget child; - LinkedListNode *node, *next; - /* 如果该部件有任务需要处理 */ if( w->task.for_self ) { - ret = LCUIMutex_TryLock( &w->mutex ); - if( ret != 0 ) { - ret = 1; - goto skip_proc_self_task; + if( LCUIMutex_TryLock( &w->mutex ) != 0 ) { + return 1; } w->task.for_self = FALSE; buffer = w->task.buffer; @@ -187,8 +230,8 @@ int Widget_Update( LCUI_Widget w ) for( i = 0; i < WTT_USER; ++i ) { if( buffer[i] ) { buffer[i] = FALSE; - if( task_handlers[i] ) { - task_handlers[i]( w ); + if( self.handlers[i] ) { + self.handlers[i]( w ); } } else { buffer[i] = FALSE; @@ -208,41 +251,49 @@ int Widget_Update( LCUI_Widget w ) } } } - /* 删除无用部件 */ - node = w->children_trash.head.next; - while( node ) { - next = node->next; - LinkedList_Unlink( &w->children_trash, node ); - Widget_ExecDestroy( node->data ); - node = next; - } - -skip_proc_self_task:; - - /* 如果子级部件中有待处理的部件,则递归进去 */ - if( w->task.for_children ) { - w->task.for_children = FALSE; - node = w->children.head.next; - while( node ) { - child = node->data; - /* 如果当前部件有销毁任务,结点空间会连同部件一起被 - * 释放,为避免因访问非法空间而出现异常,预先保存下 - * 个结点。 - */ - next = node->next; - ret = Widget_Update( child ); - /* 如果该级部件的任务需要留到下次再处理 */ - if( ret == 1 ) { - w->task.for_children = TRUE; - } - node = next; - } - } - return (w->task.for_self || w->task.for_children) ? 1 : 0; + return w->task.for_self; } -/** 处理一次当前积累的部件任务 */ -void LCUIWidget_StepTask(void) +void LCUIWidget_StepTask( void ) { - Widget_Update( LCUIWidget_GetRoot() ); + int i; + WidgetTaskIndex idx; + LinkedListNode *prev, *node; + int64_t current_time = LCUI_GetTime(); + int64_t end_time = current_time + 30; + size_t offset = offsetof( WidgetTaskIndexRec, node ); + + while( current_time < end_time ) { + i = 0, node = NULL; + LCUIMutex_Lock( &self.mutex ); + for( LinkedList_Each( node, &self.tasks ) ) { + if( i >= 50 ) { + break; + } + prev = node->prev; + if( Widget_Update( node->data ) ) { + i += 1; + continue; + } + idx = (WidgetTaskIndex)((char*)node - offset); + RBTree_CustomErase( &self.indexes, node->data ); + LinkedList_Unlink( &self.tasks, node ); + free( idx ); + node = prev; + i += 1; + } + /* 删除无用部件 */ + node = self.trash.head.next; + while( node && node != &self.trash.head ) { + prev = node->prev; + LinkedList_Unlink( &self.trash, node ); + Widget_ExecDestroy( node->data ); + node = prev; + } + LCUIMutex_Unlock( &self.mutex ); + if( !node ) { + break; + } + current_time = LCUI_GetTime(); + } } From ccae916e8ff93ebf63a81df9dcdd8ddb984844b5 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Fri, 19 Aug 2016 00:02:27 +0800 Subject: [PATCH 105/124] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E9=83=A8=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=20children=5Ftrash=20=E5=B1=9E=E6=80=A7=EF=BC=8C?= =?UTF-8?q?=E8=A1=A5=E5=85=85=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/gui/widget_base.h | 1 - src/gui/widget_task.c | 19 ++++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/LCUI/gui/widget_base.h b/include/LCUI/gui/widget_base.h index 4ccb1a08..91febce0 100755 --- a/include/LCUI/gui/widget_base.h +++ b/include/LCUI/gui/widget_base.h @@ -247,7 +247,6 @@ typedef struct LCUI_WidgetRec_ { LCUI_Widget parent; /**< 父部件 */ LinkedList children; /**< 子部件 */ LinkedList children_show; /**< 子部件的堆叠顺序记录,由顶到底 */ - LinkedList children_trash; /**< 需被删除的子部件 */ void *private_data; /**< 私有数据 */ void *extend_data; /**< 扩展数据 */ LCUI_BOOL enable_graph; /**< 是否启用位图缓存 */ diff --git a/src/gui/widget_task.c b/src/gui/widget_task.c index 3ee104f7..e61684b2 100644 --- a/src/gui/widget_task.c +++ b/src/gui/widget_task.c @@ -37,7 +37,6 @@ * 没有,请查看:. * ***************************************************************************/ -//#define DEBUG #include #include #include @@ -47,17 +46,19 @@ typedef void (*callback)(LCUI_Widget); +/** 部件任务索引记录 */ typedef struct WidgetTaskIndexRec_ { - LCUI_Widget widget; - LinkedListNode node; + LCUI_Widget widget; /**< 部件 */ + LinkedListNode node; /**< 任务数据结点 */ } WidgetTaskIndexRec, *WidgetTaskIndex; -static struct LCUIWidgetTaskModule { - LinkedList tasks; - LCUI_RBTree indexes; - LCUI_Mutex mutex; - LinkedList trash; - callback handlers[WTT_TOTAL_NUM]; +/** 部件任务模块数据 */ +static struct WidgetTaskModule { + LinkedList tasks; /**< 任务队列 */ + LCUI_RBTree indexes; /**< 索引记录 */ + LCUI_Mutex mutex; /**< 互斥锁 */ + LinkedList trash; /**< 待删除的部件列表 */ + callback handlers[WTT_TOTAL_NUM]; /**< 任务处理器 */ } self; static void HandleRefreshStyle( LCUI_Widget w ) From 900aeb27c176845cf5a2b779690b83d580a51580 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Fri, 19 Aug 2016 00:13:41 +0800 Subject: [PATCH 106/124] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=83=A8=E4=BB=B6?= =?UTF-8?q?=E6=B8=85=E7=A9=BA=E5=92=8C=E9=94=80=E6=AF=81=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gui/widget_base.c | 33 ++++++++++++--------------------- src/gui/widget_task.c | 1 + 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index 6c637c7d..e3607401 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -329,7 +329,6 @@ static void Widget_Init( LCUI_Widget widget ) Border_Init( &widget->computed_style.border ); LinkedList_Init( &widget->children ); LinkedList_Init( &widget->children_show ); - LinkedList_Init( &widget->children_trash ); LinkedList_Init( &widget->dirty_rects ); LCUIMutex_Init( &widget->mutex ); Graph_Init( &widget->graph ); @@ -379,7 +378,6 @@ void Widget_ExecDestroy( LCUI_Widget widget ) /* 先释放显示列表,后销毁部件列表,因为部件在这两个链表中的节点是和它共用 * 一块内存空间的,销毁部件列表会把部件释放掉,所以把这个操作放在后面 */ LinkedList_ClearData( &widget->children_show, NULL ); - LinkedList_ClearData( &widget->children_trash, NULL ); LinkedList_ClearData( &widget->children, Widget_OnDestroy ); LinkedList_Clear( &widget->dirty_rects, free ); StyleSheet_Delete( widget->inherited_style ); @@ -411,7 +409,6 @@ void Widget_Destroy( LCUI_Widget w ) while( root->parent ) { root = root->parent; } - w->state = WSTATE_DELETED; if( root != LCUIWidget.root ) { Widget_ExecDestroy( w ); return; @@ -436,32 +433,26 @@ void Widget_Destroy( LCUI_Widget w ) void Widget_Empty( LCUI_Widget w ) { - LinkedListNode *node; + LinkedListNode *prev, *node; LCUI_Widget root = w, child; + while( root->parent ) { root = root->parent; } - LinkedList_ClearData( &w->children_show, NULL ); if( root == LCUIWidget.root ) { - for( LinkedList_Each( node, &w->children ) ) { - child = node->data; - child->state = WSTATE_DELETED; - } - LinkedList_Concat( &w->children_trash, &w->children ); - Widget_PushInvalidArea( w, NULL, SV_GRAPH_BOX ); - Widget_AddTask( w, WTT_LAYOUT ); - return; - } else { - LinkedList list; - LinkedListNode *prev; - LinkedList_Init( &list ); - LinkedList_Concat( &list, &w->children ); - node = list.head.next; + node = w->children.tail.prev; while( node ) { prev = node->prev; - Widget_ExecDestroy( node->data ); - node = prev->next; + child = node->data; + child->state = WSTATE_DELETED; + Widget_AddToTrash( node->data ); + node = prev; } + Widget_PushInvalidArea( w, NULL, SV_GRAPH_BOX ); + Widget_AddTask( w, WTT_LAYOUT ); + } else { + LinkedList_ClearData( &w->children_show, NULL ); + LinkedList_ClearData( &w->children, Widget_OnDestroy ); } } diff --git a/src/gui/widget_task.c b/src/gui/widget_task.c index e61684b2..4f1490c1 100644 --- a/src/gui/widget_task.c +++ b/src/gui/widget_task.c @@ -201,6 +201,7 @@ void Widget_AddToTrash( LCUI_Widget w ) { LinkedListNode *snode, *node; + w->state = WSTATE_DELETED; if( !w->parent ) { return; } From a1ef6d19ff089792d15fb09f40f34edbf4bec04d Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Fri, 19 Aug 2016 01:17:48 +0800 Subject: [PATCH 107/124] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=BD=9C=E5=9C=A8?= =?UTF-8?q?=E7=9A=84=E6=AD=BB=E9=94=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gui/widget_base.c | 28 +++++++++++++++++++--------- src/gui/widget_style.c | 2 +- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index e3607401..d2a00d71 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -1345,9 +1345,14 @@ int Widget_AddClass( LCUI_Widget w, const char *class_name ) Widget_Unlock( w ); return 0; } + Widget_Unlock( w ); + /** + * 先解除部件互斥锁,因为下面的函数所添加的部件任务可能会锁上全局任务锁和 + * 部件互斥锁,如果在处理任务时部件互斥锁没有解锁,那么整个部件任务功能都 + * 会进入死锁状态 + */ Widget_HandleChildrenStyleChange( w, 0, class_name ); Widget_UpdateStyle( w, TRUE ); - Widget_Unlock( w ); return 1; } @@ -1368,10 +1373,12 @@ int Widget_RemoveClass( LCUI_Widget w, const char *class_name ) { Widget_Lock( w ); if( StrList_Has( w->classes, class_name ) ) { - Widget_HandleChildrenStyleChange( w, 0, class_name ); - StrList_Remove( &w->classes, class_name ); - Widget_UpdateStyle( w, TRUE ); Widget_Unlock( w ); + Widget_HandleChildrenStyleChange( w, 0, class_name ); + Widget_Lock( w ); + StrList_Remove( &w->classes, class_name ); + Widget_Unlock( w ); + Widget_UpdateStyle( w, TRUE ); return 1; } Widget_Unlock( w ); @@ -1390,9 +1397,9 @@ int Widget_AddStatus( LCUI_Widget w, const char *status_name ) Widget_Unlock( w ); return 0; } - Widget_UpdateStyle( w, TRUE ); - Widget_HandleChildrenStyleChange( w, 1, status_name ); Widget_Unlock( w ); + Widget_HandleChildrenStyleChange( w, 1, status_name ); + Widget_UpdateStyle( w, TRUE ); return 1; } @@ -1401,6 +1408,7 @@ LCUI_BOOL Widget_HasStatus( LCUI_Widget w, const char *status_name ) { Widget_Lock( w ); if( StrList_Has( w->status, status_name ) ) { + Widget_Unlock( w ); return TRUE; } Widget_Unlock( w ); @@ -1412,10 +1420,12 @@ int Widget_RemoveStatus( LCUI_Widget w, const char *status_name ) { Widget_Lock( w ); if( StrList_Has( w->status, status_name ) ) { - Widget_HandleChildrenStyleChange( w, 1, status_name ); - StrList_Remove( &w->status, status_name ); - Widget_UpdateStyle( w, TRUE ); Widget_Unlock( w ); + Widget_HandleChildrenStyleChange( w, 1, status_name ); + Widget_Lock( w ); + StrList_Remove( &w->status, status_name ); + Widget_Unlock( w ); + Widget_UpdateStyle( w, TRUE ); return 1; } Widget_Unlock( w ); diff --git a/src/gui/widget_style.c b/src/gui/widget_style.c index 136bdfbc..56024ac2 100644 --- a/src/gui/widget_style.c +++ b/src/gui/widget_style.c @@ -1091,7 +1091,7 @@ static int FindStyleSheetFromGroup( int group, const char *name, LinkedList names; groups = LinkedList_Get( &style_library.groups, group ); - if( !groups ) { + if( !groups || s->length < 1 ) { return 0; } count = 0; From 5a0ab668790393725d05e2cceee2346d33bf8081 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Sun, 21 Aug 2016 15:34:27 +0800 Subject: [PATCH 108/124] =?UTF-8?q?=E6=92=A4=E9=94=80=E9=83=A8=E4=BB=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=9A=84=E9=98=9F=E5=88=97=E5=8C=96=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 忘了为啥要队列化部件任务,这种做法的内存开销和效率感觉比之前的要高,互斥锁操作频繁。经测试发现还有一些奇怪的问题,由于懒得花时间解决,现已改回之前的处理方式。 --- include/LCUI/gui/widget_base.h | 4 +- include/LCUI/gui/widget_task.h | 8 +- src/gui/widget_base.c | 26 ++---- src/gui/widget_task.c | 148 ++++++++++++++------------------- src/util/linkedlist.c | 5 +- src/util/rbtree.c | 8 +- 6 files changed, 79 insertions(+), 120 deletions(-) diff --git a/include/LCUI/gui/widget_base.h b/include/LCUI/gui/widget_base.h index 91febce0..ea255c8b 100755 --- a/include/LCUI/gui/widget_base.h +++ b/include/LCUI/gui/widget_base.h @@ -209,6 +209,7 @@ typedef struct LCUI_WidgetBoxRect { typedef struct LCUI_WidgetTaskBoxRec_ { LCUI_BOOL for_self; /**< 标志,指示当前部件是否有待处理的任务 */ + LCUI_BOOL for_children; /**< 标志,指示是否有待处理的子级部件 */ LCUI_BOOL buffer[WTT_TOTAL_NUM]; /**< 记录缓存 */ } LCUI_WidgetTaskBoxRec; @@ -326,9 +327,6 @@ LCUI_API void Widget_UpdateProps( LCUI_Widget w ); /** 更新透明度 */ LCUI_API void Widget_UpdateOpacity( LCUI_Widget w ); -/** 处理部件中当前积累的任务 */ -LCUI_API int Widget_Update( LCUI_Widget w ); - /** 设置部件标题 */ LCUI_API void Widget_SetTitleW( LCUI_Widget w, const wchar_t *title ); diff --git a/include/LCUI/gui/widget_task.h b/include/LCUI/gui/widget_task.h index d5da2dea..2619d46a 100644 --- a/include/LCUI/gui/widget_task.h +++ b/include/LCUI/gui/widget_task.h @@ -40,6 +40,8 @@ #ifndef LCUI_WIDGET_TASK_H #define LCUI_WIDGET_TASK_H +#define Widget_Update(W) Widget_UpdateEx(W, FALSE) + LCUI_BEGIN_HEADER /** 更新当前任务状态,确保部件的任务能够被处理到 */ @@ -48,15 +50,15 @@ LCUI_API void Widget_UpdateTaskStatus( LCUI_Widget widget ); /** 添加任务 */ LCUI_API void Widget_AddTask( LCUI_Widget widget, int task_type ); +/** 处理部件中当前积累的任务 */ +LCUI_API int Widget_UpdateEx( LCUI_Widget w, LCUI_BOOL has_timeout ); + /** 将部件标记为垃圾,等待销毁 */ LCUI_API void Widget_AddToTrash( LCUI_Widget w ); /** 为子级部件添加任务 */ LCUI_API void Widget_AddTaskForChildren( LCUI_Widget widget, int task ); -/** 移除指定部件的任务记录 */ -LCUI_API void LCUIWidget_ClearTaskTarget( LCUI_Widget w ); - /** 初始化 LCUI 部件任务处理功能 */ void LCUIWidget_InitTask( void ); diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index d2a00d71..9b051971 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -371,7 +371,6 @@ void Widget_ExecDestroy( LCUI_Widget widget ) Widget_ReleaseTouchCapture( widget, -1 ); Widget_StopEventPropagation( widget ); LCUIWidget_ClearEventTarget( widget ); - LCUIWidget_ClearTaskTarget( widget ); if( wc && wc->methods.destroy ) { wc->methods.destroy( widget ); } @@ -433,20 +432,18 @@ void Widget_Destroy( LCUI_Widget w ) void Widget_Empty( LCUI_Widget w ) { - LinkedListNode *prev, *node; - LCUI_Widget root = w, child; + LCUI_Widget root = w; while( root->parent ) { root = root->parent; } if( root == LCUIWidget.root ) { - node = w->children.tail.prev; + LinkedListNode *next, *node; + node = w->children.head.next; while( node ) { - prev = node->prev; - child = node->data; - child->state = WSTATE_DELETED; + next = node->next; Widget_AddToTrash( node->data ); - node = prev; + node = next; } Widget_PushInvalidArea( w, NULL, SV_GRAPH_BOX ); Widget_AddTask( w, WTT_LAYOUT ); @@ -1346,11 +1343,6 @@ int Widget_AddClass( LCUI_Widget w, const char *class_name ) return 0; } Widget_Unlock( w ); - /** - * 先解除部件互斥锁,因为下面的函数所添加的部件任务可能会锁上全局任务锁和 - * 部件互斥锁,如果在处理任务时部件互斥锁没有解锁,那么整个部件任务功能都 - * 会进入死锁状态 - */ Widget_HandleChildrenStyleChange( w, 0, class_name ); Widget_UpdateStyle( w, TRUE ); return 1; @@ -1373,12 +1365,10 @@ int Widget_RemoveClass( LCUI_Widget w, const char *class_name ) { Widget_Lock( w ); if( StrList_Has( w->classes, class_name ) ) { - Widget_Unlock( w ); Widget_HandleChildrenStyleChange( w, 0, class_name ); - Widget_Lock( w ); StrList_Remove( &w->classes, class_name ); - Widget_Unlock( w ); Widget_UpdateStyle( w, TRUE ); + Widget_Unlock( w ); return 1; } Widget_Unlock( w ); @@ -1420,12 +1410,10 @@ int Widget_RemoveStatus( LCUI_Widget w, const char *status_name ) { Widget_Lock( w ); if( StrList_Has( w->status, status_name ) ) { - Widget_Unlock( w ); Widget_HandleChildrenStyleChange( w, 1, status_name ); - Widget_Lock( w ); StrList_Remove( &w->status, status_name ); - Widget_Unlock( w ); Widget_UpdateStyle( w, TRUE ); + Widget_Unlock( w ); return 1; } Widget_Unlock( w ); diff --git a/src/gui/widget_task.c b/src/gui/widget_task.c index 4f1490c1..e9874515 100644 --- a/src/gui/widget_task.c +++ b/src/gui/widget_task.c @@ -37,7 +37,6 @@ * 没有,请查看:. * ***************************************************************************/ -#include #include #include #include @@ -46,17 +45,11 @@ typedef void (*callback)(LCUI_Widget); -/** 部件任务索引记录 */ -typedef struct WidgetTaskIndexRec_ { - LCUI_Widget widget; /**< 部件 */ - LinkedListNode node; /**< 任务数据结点 */ -} WidgetTaskIndexRec, *WidgetTaskIndex; - /** 部件任务模块数据 */ static struct WidgetTaskModule { - LinkedList tasks; /**< 任务队列 */ - LCUI_RBTree indexes; /**< 索引记录 */ - LCUI_Mutex mutex; /**< 互斥锁 */ + size_t count; + int64_t timeout; + LCUI_BOOL is_timeout; LinkedList trash; /**< 待删除的部件列表 */ callback handlers[WTT_TOTAL_NUM]; /**< 任务处理器 */ } self; @@ -114,6 +107,7 @@ void Widget_AddTaskForChildren( LCUI_Widget widget, int task ) { LCUI_Widget child; LinkedListNode *node; + widget->task.for_children = TRUE; for( LinkedList_Each( node, &widget->children ) ) { child = node->data; Widget_AddTask( child, task ); @@ -121,19 +115,6 @@ void Widget_AddTaskForChildren( LCUI_Widget widget, int task ) } } -void LCUIWidget_ClearTaskTarget( LCUI_Widget w ) -{ - WidgetTaskIndex idx; - LCUIMutex_Lock( &self.mutex ); - idx = RBTree_CustomGetData( &self.indexes, w ); - if( idx ) { - LinkedList_Unlink( &self.tasks, &idx->node ); - RBTree_CustomErase( &self.indexes, w ); - free( idx ); - } - LCUIMutex_Unlock( &self.mutex ); -} - void Widget_AddTask( LCUI_Widget widget, int task ) { if( widget->state == WSTATE_DELETED ) { @@ -141,15 +122,12 @@ void Widget_AddTask( LCUI_Widget widget, int task ) } widget->task.for_self = TRUE; widget->task.buffer[task] = TRUE; - LCUIMutex_Lock( &self.mutex ); - if( !RBTree_CustomGetData( &self.indexes, widget ) ) { - WidgetTaskIndex idx = NEW( WidgetTaskIndexRec, 1 ); - idx->widget = widget; - idx->node.data = widget; - RBTree_CustomInsert( &self.indexes, widget, idx ); - LinkedList_AppendNode( &self.tasks, &idx->node ); + widget = widget->parent; + /* 向没有标记的父级部件添加标记 */ + while( widget && !widget->task.for_children ) { + widget->task.for_children = TRUE; + widget = widget->parent; } - LCUIMutex_Unlock( &self.mutex ); } /** 映射任务处理器 */ @@ -173,28 +151,16 @@ static void MapTaskHandler(void) self.handlers[WTT_PROPS] = Widget_UpdateProps; } -static int OnCompareIndex( void *data, const void *keydata ) -{ - return ((WidgetTaskIndex)data)->widget - (LCUI_Widget)keydata; -} - void LCUIWidget_InitTask( void ) { MapTaskHandler(); - LCUIMutex_Init( &self.mutex ); - LinkedList_Init( &self.tasks ); + self.timeout = 0; LinkedList_Init( &self.trash ); - RBTree_Init( &self.indexes ); - RBTree_OnCompare( &self.indexes, OnCompareIndex ); } void LCUIWidget_ExitTask( void ) { - LCUIMutex_Lock( &self.mutex ); - LinkedList_Clear( &self.tasks, NULL ); - RBTree_Destroy( &self.indexes ); - LCUIMutex_Unlock( &self.mutex ); - LCUIMutex_Destroy( &self.mutex ); + LinkedList_Clear( &self.trash, NULL ); } void Widget_AddToTrash( LCUI_Widget w ) @@ -212,14 +178,17 @@ void Widget_AddToTrash( LCUI_Widget w ) LinkedList_AppendNode( &self.trash, node ); } -int Widget_Update( LCUI_Widget w ) +int Widget_UpdateEx( LCUI_Widget w, LCUI_BOOL has_timeout ) { int i; LCUI_BOOL *buffer; + LCUI_Widget child; + LinkedListNode *node, *next; + /* 如果该部件有任务需要处理 */ if( w->task.for_self ) { if( LCUIMutex_TryLock( &w->mutex ) != 0 ) { - return 1; + goto skip_proc_self_task; } w->task.for_self = FALSE; buffer = w->task.buffer; @@ -252,50 +221,55 @@ int Widget_Update( LCUI_Widget w ) w->state = WSTATE_NORMAL; } } + self.count += 1; } - return w->task.for_self; + +skip_proc_self_task:; + + /* 如果子级部件中有待处理的部件,则递归进去 */ + if( w->task.for_children ) { + w->task.for_children = FALSE; + node = w->children.head.next; + while( node ) { + child = node->data; + /* 如果当前部件有销毁任务,结点空间会连同部件一起被 + * 释放,为避免因访问非法空间而出现异常,预先保存下 + * 个结点。 + */ + next = node->next; + /* 如果该级部件的任务需要留到下次再处理 */ + if( Widget_UpdateEx( child, has_timeout ) ) { + w->task.for_children = TRUE; + } + if( has_timeout ) { + if( !self.is_timeout && self.count >= 50 ) { + self.count = 0; + if( LCUI_GetTime() >= self.timeout ) { + self.is_timeout = TRUE; + } + } + if( self.is_timeout ) { + break; + } + } + node = next; + } + } + return w->task.for_self || w->task.for_children; } void LCUIWidget_StepTask( void ) { - int i; - WidgetTaskIndex idx; - LinkedListNode *prev, *node; - int64_t current_time = LCUI_GetTime(); - int64_t end_time = current_time + 30; - size_t offset = offsetof( WidgetTaskIndexRec, node ); - - while( current_time < end_time ) { - i = 0, node = NULL; - LCUIMutex_Lock( &self.mutex ); - for( LinkedList_Each( node, &self.tasks ) ) { - if( i >= 50 ) { - break; - } - prev = node->prev; - if( Widget_Update( node->data ) ) { - i += 1; - continue; - } - idx = (WidgetTaskIndex)((char*)node - offset); - RBTree_CustomErase( &self.indexes, node->data ); - LinkedList_Unlink( &self.tasks, node ); - free( idx ); - node = prev; - i += 1; - } - /* 删除无用部件 */ - node = self.trash.head.next; - while( node && node != &self.trash.head ) { - prev = node->prev; - LinkedList_Unlink( &self.trash, node ); - Widget_ExecDestroy( node->data ); - node = prev; - } - LCUIMutex_Unlock( &self.mutex ); - if( !node ) { - break; - } - current_time = LCUI_GetTime(); + LinkedListNode *node; + self.is_timeout = FALSE; + self.timeout = LCUI_GetTime() + 20; + Widget_UpdateEx( LCUIWidget_GetRoot(), TRUE ); + /* 删除无用部件 */ + node = self.trash.head.next; + while( node ) { + LinkedListNode *next = node->next; + LinkedList_Unlink( &self.trash, node ); + Widget_ExecDestroy( node->data ); + node = next; } } diff --git a/src/util/linkedlist.c b/src/util/linkedlist.c index e67ca6bd..ff34be0f 100644 --- a/src/util/linkedlist.c +++ b/src/util/linkedlist.c @@ -53,9 +53,8 @@ void LinkedList_Init( LinkedList *list ) void LinkedList_Unlink( LinkedList *list, LinkedListNode *node ) { - list->length -= 1; - if( list->length < 0 ) { - abort(); + if( list->length > 0 ) { + list->length -= 1; } if( node->next ) { node->next->prev = node->prev; diff --git a/src/util/rbtree.c b/src/util/rbtree.c index 6b477ac4..a0e78fe5 100644 --- a/src/util/rbtree.c +++ b/src/util/rbtree.c @@ -532,12 +532,10 @@ static void rb_erase_by_node( LCUI_RBTree *rbt, LCUI_RBTreeNode *node ) /** 删除红黑树中的结点 */ static int rb_erase( LCUI_RBTree *rbt, int key, const void *keydata ) { - unsigned char color; - LCUI_RBTreeNode *root, *child = NULL, *parent, *old, *left, *node; - - root = rbt->root; + LCUI_RBTreeNode *node; /* 查找要删除的结点 */ - node = rb_search_auxiliary( root, key, keydata, rbt->compare, NULL ); + node = rb_search_auxiliary( rbt->root, key, keydata, + rbt->compare, NULL ); if( !node ) { return -1; } From fe7ab391cc070971a86ecd05635d97dd425e54d1 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Mon, 22 Aug 2016 21:00:42 +0800 Subject: [PATCH 109/124] Update README.md --- README.md | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 3f0f0fb7..a2729501 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,8 @@ See the file `docs/LICENSE.TXT` for the available licenses. Tutorial: https://lcui.lc-soft.io/guide/ -API reference documentation has not yet been prepared, you can refer to the header files, source code, and sample programs. +API reference documentation has not yet been prepared, you can refer to the +header files, source code, and sample programs. ## Building @@ -47,16 +48,23 @@ In the simplest case you would run: ### Prerequisites -If you want to build full-featured LCUI, we suggest you install the following dependent libraries: +If you want to build full-featured LCUI, we suggest you install the following + dependent libraries: * [libpng](http://www.libpng.org/pub/png/libpng.html) — PNG image compression library * [libjpeg](http://www.ijg.org/) — JPEG image compression library * [libxml2](http://xmlsoft.org/) — The XML C parser and toolkit + * [libx11-dev](https://www.x.org/) — X11 client-side library * [freetype](https://www.freetype.org/) — Font engine If you system is Ubuntu, you can run following command to install dependencies: - apt-get install libpng-dev libjpeg-dev libxml2-dev libfreetype6-dev + apt-get install libpng-dev libjpeg-dev libxml2-dev libfreetype6-dev libx11-dev + +### Building On Windows + +LCUI is mainly develop in the Windows environment, you can use VisualStudio +to open file `build/VS2012/LCUI.sln` and compile LCUI. ## Bugs @@ -134,8 +142,8 @@ If a lot of changes has happened upstream you can replay your local changes This will fetch changes and re-apply your commits on top of these. This is generally better than merge, as it will give a clear picture of which -commits are local to your branch. It will also “prune” any of your local commits -if the same changes have been applied upstream. +commits are local to your branch. It will also “prune” any of your local +commits if the same changes have been applied upstream. You can use `-i` with `rebase` for an “interactive” rebase. This allows you to drop, re-arrange, merge, and reword commits, e.g.: From f2517ddfe9cca39cdea2d215ab453427b7daa07c Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Mon, 22 Aug 2016 21:41:14 +0800 Subject: [PATCH 110/124] Update README.zh-cn.md --- README.zh-cn.md | 126 +++++++++++++++++++++++------------------------- 1 file changed, 59 insertions(+), 67 deletions(-) diff --git a/README.zh-cn.md b/README.zh-cn.md index f7efe018..8d2eaf2f 100644 --- a/README.zh-cn.md +++ b/README.zh-cn.md @@ -1,17 +1,24 @@ # The LCUI Project -[![Gitter](https://badges.gitter.im/lc-soft/LCUI.svg)](https://gitter.im/lc-soft/LCUI?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) -[![Build Status](https://travis-ci.org/lc-soft/LCUI.png?branch=master)](https://travis-ci.org/lc-soft/LCUI) - ![LCUI Logo](http://lcui.org/static/images/lcui-project-logo.png) +[![Join the chat at https://gitter.im/lc-soft/LCUI](https://badges.gitter.im/lc-soft/LCUI.svg)](https://gitter.im/lc-soft/LCUI?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +[![Build Status](https://travis-ci.org/lc-soft/LCUI.png?branch=master)](https://travis-ci.org/lc-soft/LCUI) +[![Downloads](https://img.shields.io/sourceforge/dt/lc-ui.svg)](https://sourceforge.net/projects/lc-ui) +[![License](https://img.shields.io/badge/license-GPLv2-blue.svg)](http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) + ## 说明 -LCUI 是一个简单的跨平台图形界面库,适用于开发一些简单的小程序,其诞生目的主要是方便作者开发图形界面程序。 +LCUI 是一个简单的跨平台图形界面库,其诞生目的主要是方便作者开发图形界面程序, +源代码主要由 C 语言编写,支持使用 XML 和 CSS 代码来描述图像界面,适用于开发一 +些简单的小程序,可以实现一些简单的效果,类似于这样: -LCUI 是一个自由软件项目,基于 GNU通用公共许可协议 发布,该许可协议要求 LCUI 及 LCUI 衍生软件无论以何种形式发布,都必须确保收受者能收到或得到源码。 +![example screenshot](https://lcui.lc-soft.io/static/images/feature-screenshot-02.png) -此项目主要由作者利用闲余时间进行开发和维护,项目的活跃度通常会受到各种因素的影响,大多数时间内都处于低活跃度状态。 +LCUI 是一个自由软件项目,基于 [GNU通用公共许可协议](http://www.gnu.org/licenses/gpl-2.0.html) +发布,该许可协议要求 LCUI 及 LCUI 衍生软件无论以何种形式发布,都必须确保收受者 +能收到或得到该版本的源代码。此项目主要由作者利用闲余时间进行开发和维护,项目的 +活跃度通常会受到各种因素的影响,大多数时间内都处于低活跃度状态。 请阅读 `docs/CHANGES.zh-cn.md` 文件了解新版本的更新内容。 @@ -19,51 +26,23 @@ LCUI 是一个自由软件项目,基于 GNU通用公共许可协议 发布, 阅读 `docs/LICENSE.TXT` 文件了解 GPLv2 许可协议的具体内容。 -项目主页:http://www.lcui.org +项目主页:http://lcui.lc-soft.io 联系邮箱:lc-soft@live.cn -项目托管:https://github.com/lc-soft/LCUI - -LCUI 的相关信息与资料可以在项目主页中找到,如果遇到问题、发现BUG或者有好的建议和 -想法,可以在项目主页上留言或发送邮件告诉我们。 - -我们已经使用 GitHub 托管 LCUI 项目,网址在上面,欢迎您参与 LCUI 项目的优化和改进。 - -## 文件目录结构 - -以下是各个目录内容的相关说明: -``` - -/ 项目文件目录 -/bin/ 在编译生成后库文件的存放目录 -/build/ 参与项目编译、构建和生成的相关文件 -/build/VS2012/ VisualStudio 2012 工程文件 -/docs/ 相关文档 -/include/ 头文件 -/src/ 源文件 -/src/gui/ 图形界面 -/src/gui/widget/ 预置的图形界面组件 -/src/font/ 文字和字体 -/src/draw/ 图形绘制 -/src/bmp/ 位图文件读写 -/src/thread/ 各平台下的线程操作接口的封装 -/src/util/ 一些常用工具集 -/src/platform/ 平台相关支持 -/src/platform/windows windows 平台支持 -/src/platform/linux linux 平台支持 -/test/ 测试(示例)程序 - -``` +Github:https://github.com/lc-soft/LCUI ## 文档 -你可以访问LCUI的项目主页浏览开发文档,开发文档也托管在GitHub上,地址:https://github.com/lc-soft/LCUI-Documentation +教程:https://lcui.lc-soft.io/guide/ -如果你通过LCUI的源代码和示例程序领悟到了一些些有趣的东西,可以帮助我们完善开发文档,与其他人分享你的成果。 +目前还没有 API 参考文档,你可以参考头文件、源代码、示例程序以及作者开发过的相 +关程序来了解基本用法。 ## 构建 +### 引导 + 你需要运行 `./configure` (在源码根目录中) 以引导项目的构建。 在最简单的情况下,你可以运行: @@ -74,41 +53,50 @@ LCUI 的相关信息与资料可以在项目主页中找到,如果遇到问题 如果未找到 ./configure,请运行 ./autogen.sh 脚本生成它。 -在 LCUI 的项目主页上发布的源码包,一般是比较稳定的版本,你只需要这样做: +在 `./configure` 执行完后,运行以下命令编译源代码并安装 LCUI 的函数库和头文件: -1. 解压LCUI的源码包。 -2. 进入解压后得到的新文件夹。 -3. 运行源码根目录中的configure脚本,以对系统环境进行检测。 -4. 使用make命令编译 LCUI 的源代码。 -5. 等待编译成功完成,如果在编译过程中遇到错误,请检查您的系统中是否有完整的编译环境。 -6. 使用make install命令安装 LCUI 的函数库和头文件。 + make + make install -windows系统上构建本项目方法,有两种: +如果需要运行示例程序,可运行命令来编译生成示例程序: -1. 使用 Visual Studio 2012 或更高版本,你只需要使用它打开 `build/VS2012/` 目录下的 - `LCUI.sln` 文件,然后生成解决方案即可,生成成功后,在 `bin/` 目录下可找到库文件。 -2. 使用 Cygwin 或 MSYS,可按照上述1至6的步骤进行构建,在完成步骤3后,请修改 - `include/LCUI/config.h` 文件,定义 `LCUI_BUILD_IN_WIN32` 宏,若有 - `LCUI_BUILD_IN_LINUX` 宏,请删除它。该方法并未实际测试,如有其它方法请告知。 + cd test + make -### 系统需求 +### 依赖项 -* 字体处理:freetype2 -* XML 解析:libxml2 -* 线程支持:pthread -* 图片处理:libpng 和 libjpeg +如果你想构建全特性的 LCUI,建议安装以下依赖库: -为了你能正常使用 LCUI 全部功能,请先确保您的计算机已经安装了上述的函数库,并保持较新的版本。 -理论上,LCUI 能在 GNU/Linux 系统环境中正常工作,LCUI 的图形输出,需要内核支持 FrameBuffer。 + * [libpng](http://www.libpng.org/pub/png/libpng.html) — PNG 图像压缩库 + * [libjpeg](http://www.ijg.org/) — JPEG 图像压缩库 + * [libxml2](http://xmlsoft.org/) — XML 解析器及相关工具集 + * [libx11-dev](https://www.x.org/) — X11 客户端库 + * [freetype](https://www.freetype.org/) — 字体渲染引擎 + +如果你的系统是 Ubuntu,可运行以下命令来安装依赖: + + apt-get install libpng-dev libjpeg-dev libxml2-dev libfreetype6-dev libx11-dev + + +### 在 Windows 中构建 + +LCUI 主要是在 Windows 系统环境下开发的,你可以使用 VisualStudio 打开 +`/build/VS2012/LCUI.sln` 文件,然后编译生成 LCUI。如果你用的是其它 IDE,请尝 +试按该 IDE 的方式创建项目并将源文件添加至项目内,然后编译。 + +上述的依赖库除 libx11 外,都可以在 Windows 下编译生成,如果觉得手动编译它们很 +麻烦,想要现成可用的依赖库和头文件,可以联系作者。 ## 贡献 -你可以通过GitHub向本项目提交合并请求,补丁应符合以下要求: +**你可以通过 GitHub 向本项目提交合并请求** + +补丁应符合以下要求: 1. 遵循现有代码风格,请参考 `docs/CodingStyle.zh-cn.md` 文件。 2. 一次提交应该做完整的一件事。 3. 提交信息的第一行为摘要行,长度应低于80个字符,如果需要描述修改原因,请在摘要行后留空行,然后再补充。 -4. 修复之前的提交(已经合并)中存在的bug,提交信息的摘要行应该以 `修复` 或含义类似的词语开头,表示修复 +4. 修复之前的提交(已经合并)中存在的 bug,提交信息的摘要行应该以 `修复` 或含义类似的词语开头,表示修复 了它。如果你修复的是 issues 列表中未解决的问题,需在摘要行中加上 issues 列表中对应问题的编号。 5. 衍合你的分支至源项目的 master 分支。我们不希望落拉取到冗余的合并请求。 6. **要清楚什么许可证适用于你的补丁:** 该代码库中的文件基于GPLv2(或更高版本),但(原 @@ -116,17 +104,21 @@ windows系统上构建本项目方法,有两种: 以后不会进入任何非自由的衍生工具,因此,如果补丁发布于公共领域,会为我们带来方便(以及 避免任何法律问题)。 +**你可以通过捐赠来支持 LCUI 的开发** -### GitHub流程 +作者目前是一名独立开发者,你的贡献是非常有帮助的,如果你想通过捐赠来让作者能够花更多的时间来改进该项目, +可以访问作者在 [Patreon](https://www.patreon.com/lcsoft) 上设立的页面。 + +### GitHub 流程 开发补丁应遵循以下流程: #### 初始设置 -1. 在GitHub上进行Fork (点击 Fork 按钮) -2. Clone到计算机: `git clone git@github.com:你的用户名/LCUI.git` +1. 在 GitHub 上进行Fork (点击 Fork 按钮) +2. Clone 到计算机: `git clone git@github.com:你的用户名/LCUI.git` 3. cd 到代码库中: `cd LCUI` -4. 设置远程仓库记录,假设该记录名为upstream,那么命令为: `git remote add -f upstream git://github.com/lc-soft/LCUI.git` +4. 设置远程仓库记录,假设该记录名为 upstream,那么命令为: `git remote add -f upstream git://github.com/lc-soft/LCUI.git` #### 添加Feature From 04ad567c2c54ee59b92090e14daeb04fc86ff3a6 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Mon, 22 Aug 2016 21:43:21 +0800 Subject: [PATCH 111/124] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index a2729501..0e8ac36d 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ ## Description +[中文版说明文档](README.zh-cn.md) + LCUI is a freely available software library to create GUI application. It is written in C, support the use XML and CSS describe the graphical From 727fefd4b0e470a1b9f7a61126e49cc463dc38da Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Mon, 22 Aug 2016 23:10:37 +0800 Subject: [PATCH 112/124] update Makefile.am --- include/LCUI/util/Makefile.am | 2 +- src/util/Makefile.am | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/LCUI/util/Makefile.am b/include/LCUI/util/Makefile.am index af4e1773..f6754e4d 100644 --- a/include/LCUI/util/Makefile.am +++ b/include/LCUI/util/Makefile.am @@ -1,5 +1,5 @@ AUTOMAKE_OPTIONS=foreign # Headers to install -pkginclude_HEADERS = dict.h rbtree.h linkedlist.h framectrl.h parse.h string.h rect.h delay.h dirent.h +pkginclude_HEADERS = dict.h rbtree.h linkedlist.h framectrl.h parse.h string.h rect.h dirent.h pkgincludedir=$(prefix)/include/LCUI/util diff --git a/src/util/Makefile.am b/src/util/Makefile.am index 7a6c292e..7c789bfa 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -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 \ -delay.c dirent.c parse.c framectrl.c +dirent.c parse.c framectrl.c From 17b02750b6c79967d68198bbd8fa066df4f0878e Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Thu, 25 Aug 2016 22:58:10 +0800 Subject: [PATCH 113/124] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20memdebug.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/util.h | 5 +- include/LCUI/util/memdebug.h | 74 ++++++++++++++ src/util/memdebug.c | 185 +++++++++++++++++++++++++++++++++++ 3 files changed, 262 insertions(+), 2 deletions(-) create mode 100644 include/LCUI/util/memdebug.h create mode 100644 src/util/memdebug.c diff --git a/include/LCUI/util.h b/include/LCUI/util.h index 6df2a98e..538050ac 100644 --- a/include/LCUI/util.h +++ b/include/LCUI/util.h @@ -37,8 +37,8 @@ * 没有,请查看:. * ****************************************************************************/ -#ifndef __LCUI_UTIL_H__ -#define __LCUI_UTIL_H__ +#ifndef LCUI_UTIL_H +#define LCUI_UTIL_H #include #include #include @@ -49,4 +49,5 @@ #include #include #include +#include #endif diff --git a/include/LCUI/util/memdebug.h b/include/LCUI/util/memdebug.h new file mode 100644 index 00000000..2835b7d4 --- /dev/null +++ b/include/LCUI/util/memdebug.h @@ -0,0 +1,74 @@ +/* *************************************************************************** + * memdebug.h -- memory debug module, used for memory usage statistics. + * + * Copyright (C) 2016 by Liu Chao + * + * 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * memdebug.h -- Äڴæµ÷ÊÔģ¿飬ÓÃÓÚͳ¼Ƹ÷¸öÄڴæ¿éµÄʹÓÃÇé¿ö£¬·½±ãµ÷Êԡ£ + * + * °æȨËùÓÐ (C) 2016 ¹éÊôÓÚ Áõ³¬ + * + * Õâ¸öÎļþÊÇLCUIÏîĿµÄһ²¿·֣¬²¢ÇÒֻ¿ÉÒԸù¾ÝGPLv2Ðí¿ÉЭÒéÀ´ʹÓᢸü¸ĺͷ¢²¼¡£ + * + * (GPLv2 ÊÇ GNUͨÓù«¹²Ðí¿É֤µڶþ°æ µÄӢÎÄËõд) + * + * ¼ÌÐøʹÓá¢Ð޸Ļ򷢲¼±¾Îļþ£¬±íÃ÷ÄúÒѾ­ÔĶÁ²¢ÍêȫÀí½âºͽÓÊÜÕâ¸öÐí¿ÉЭÒ顣 + * + * LCUI ÏîĿÊǻùÓÚʹÓÃĿµĶø¼ÓÒÔɢ²¼µģ¬µ«²»¸ºÈκε£±£ÔðÈΣ¬ÉõÖÁûÓÐÊÊÏúÐԻòÌØ + * ¶¨ÓÃ;µÄÒþº¬µ£±££¬ÏêÇéÇë²ÎÕÕGPLv2Ðí¿ÉЭÒ顣 + * + * ÄúӦÒÑÊյ½¸½ËæÓڱ¾ÎļþµÄGPLv2Ðí¿ÉЭÒéµĸ±±¾£¬Ëüͨ³£ÔÚLICENSE.TXTÎļþÖУ¬Èç¹û + * ûÓУ¬Çë²鿴£º. + * ****************************************************************************/ + +#ifndef LCUI_UTIL_MEMDEBUG_H +#define LCUI_UTIL_MEMDEBUG_H + +LCUI_API void LCUI_InitMemDebug( void ); + +LCUI_API void LCUI_ExitMemDebug( void ); + +LCUI_API void LCUI_PrintMemStats( void ); + +#ifdef ENABLE_MEMDEBUG + +LCUI_API void *LCUI_Malloc( size_t size, const char *name ); + +LCUI_API void *LCUI_Calloc( size_t count, size_t size, const char *name ); + +LCUI_API void *LCUI_Realloc( void *ptr, size_t size ); + +LCUI_API void LCUI_Free( void *ptr ); + +LCUI_API void LCUI_SetMemBlockName( void *ptr, const char *name ); + +#undef NEW +#define NEW(TYPE, COUNT) (TYPE*)LCUI_Calloc(COUNT, sizeof(TYPE), __FUNCTION__) + +#else + +#define LCUI_Malloc(SIZE, NAME) malloc(SIZE) +#define LCUI_Calloc(COUNT, SIZE, NAME) calloc(COUNT, SIZE) +#define LCUI_Realloc(PTR, SIZE) realloc(PTR, SIZE) +#define LCUI_Free free +#define LCUI_SetMemBlockName(PTR, NAME) + +#endif + +#endif diff --git a/src/util/memdebug.c b/src/util/memdebug.c new file mode 100644 index 00000000..8b929bdd --- /dev/null +++ b/src/util/memdebug.c @@ -0,0 +1,185 @@ +/* *************************************************************************** + * memdebug.c -- memory debug module, used for memory usage statistics. + * + * Copyright (C) 2016 by Liu Chao + * + * 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * memdebug.c -- 内存调试模块,用于统计各个内存块的使用情况,方便调试。 + * + * 版权所有 (C) 2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ + +#define ENABLE_MEMDEBUG +#include +#include +#include +#include +#include +#include + +#define HEAD_SIGN 123456 +#define TAIL_SIGN 654321 + +/** 内存块组 */ +typedef struct MemBlockGroupRec_ { + int id; /**< 组的标识号 */ + char *name; /**< 组的名称 */ + size_t size; /**< 当前组内内存块的总占用大小 */ + size_t count; /**< 内存块总数 */ +} MemBlockGroupRec, *MemBlockGroup; + +/** 内存块 */ +typedef struct MemBlockRec_ { + int head_sign; /**< 头部标识 */ + size_t size; /**< 内存块大小 */ + MemBlockGroup group; /**< 内存块所属组 */ + int tail_sign; /**< 尾部标识 */ +} MemBlockRec, *MemBlock; + +static struct { + int id_count; + Dict *groups; + LCUI_Mutex mutex; + DictType dtype; +} self; + +void LCUI_InitMemDebug( void ) +{ + self.dtype = DictType_StringCopyKey; + self.dtype.keyDup = NULL; + self.dtype.keyDestructor = NULL; + self.id_count = 1; + self.groups = Dict_Create( &self.dtype, NULL ); + LCUIMutex_Init( &self.mutex ); +} + +void LCUI_ExitMemDebug( void ) +{ + +} + +void LCUI_PrintMemStats( void ) +{ + DictEntry *entry; + DictIterator *iter; + printf("mem stats list start\n"); + LCUIMutex_Lock( &self.mutex ); + iter = Dict_GetIterator( self.groups ); + while( (entry = Dict_Next(iter)) ) { + MemBlockGroup group = DictEntry_GetVal( entry ); + printf( "[%40s] size: %.02f KB, count: %d\n", group->name, + 1.0 * group->size / 1024., group->count ); + } + LCUIMutex_Unlock( &self.mutex ); + printf("mem stats list end\n"); +} + +static void SetMemBlock( MemBlock blk, size_t size, const char *name ) +{ + MemBlockGroup group; + LCUIMutex_Lock( &self.mutex ); + group = Dict_FetchValue( self.groups, name ); + if( !group ) { + group = malloc( sizeof(MemBlockGroupRec) ); + group->id = self.id_count++; + group->name = strdup( name ); + group->size = 0; + group->count = 0; + Dict_Add( self.groups, group->name, group ); + } + group->count += 1; + group->size += size; + LCUIMutex_Unlock( &self.mutex ); + blk->head_sign = HEAD_SIGN; + blk->tail_sign = TAIL_SIGN; + blk->size = size; + blk->group = group; +} + +void LCUI_SetMemBlockName( void *ptr, const char *name ) +{ + MemBlock blk = (MemBlock)((char*)ptr - sizeof( MemBlockRec )); + if( blk->head_sign != HEAD_SIGN || blk->tail_sign != TAIL_SIGN ) { + abort(); + } + LCUIMutex_Lock( &self.mutex ); + blk->group->size -= blk->size; + blk->group->count -= 1; + LCUIMutex_Unlock( &self.mutex ); + SetMemBlock( blk, blk->size, name ); +} + +void *LCUI_Calloc( size_t count, size_t size, const char *name ) +{ + MemBlock blk; + size_t totalsize = size * count + sizeof( MemBlockRec ); + blk = calloc( count, (size_t)(1.0 * totalsize / count + 0.5) ); + SetMemBlock( blk, size * count, name ); + return ((char*)blk) + sizeof( MemBlockRec ); +} + +void *LCUI_Malloc( size_t size, const char *name ) +{ + MemBlock blk = malloc( size + sizeof( MemBlockRec ) ); + SetMemBlock( blk, size, name ); + return ((char*)blk) + sizeof( MemBlockRec ); +} + +void *LCUI_Realloc( void *ptr, size_t size ) +{ + MemBlock newblk; + MemBlock blk = (MemBlock)((char*)ptr - sizeof( MemBlockRec )); + if( blk->head_sign != HEAD_SIGN || blk->tail_sign != TAIL_SIGN ) { + abort(); + } + newblk = realloc( blk, size + sizeof( MemBlockRec ) ); + if( newblk ) { + LCUIMutex_Lock( &self.mutex ); + newblk->group->size += size - newblk->size; + newblk->size = size; + LCUIMutex_Unlock( &self.mutex ); + return ((char*)blk) + sizeof( MemBlockRec ); + } + return NULL; +} + +void LCUI_Free( void *ptr ) +{ + MemBlock blk = (MemBlock)((char*)ptr - sizeof( MemBlockRec )); + if( blk->head_sign != HEAD_SIGN || blk->tail_sign != TAIL_SIGN ) { + abort(); + } + LCUIMutex_Lock( &self.mutex ); + blk->group->size -= blk->size; + blk->group->count -= 1; + LCUIMutex_Unlock( &self.mutex ); + free( blk ); +} From da18105cc36bef78de1992e76d2ea212b90804c3 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Fri, 26 Aug 2016 23:36:06 +0800 Subject: [PATCH 114/124] =?UTF-8?q?=E5=88=A0=E9=99=A4=20cached=5Fstyle=20?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E8=A1=A8=EF=BC=8C=E7=BC=A9=E5=87=8F=20LCUI?= =?UTF-8?q?=5FStyleRec=20=E7=9A=84=E5=86=85=E5=AD=98=E5=8D=A0=E7=94=A8?= =?UTF-8?q?=E3=80=82#40?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/LCUI.h | 6 +- include/LCUI/gui/widget_base.h | 4 +- src/gui/widget_background.c | 2 +- src/gui/widget_base.c | 20 +++-- src/gui/widget_style.c | 12 ++- src/gui/widget_task.c | 141 +++++++++++++++------------------ 6 files changed, 87 insertions(+), 98 deletions(-) diff --git a/include/LCUI/LCUI.h b/include/LCUI/LCUI.h index 9567f2e2..e9975e7f 100755 --- a/include/LCUI/LCUI.h +++ b/include/LCUI/LCUI.h @@ -231,9 +231,9 @@ typedef enum LCUI_StyleValue { } LCUI_StyleValue; typedef struct LCUI_StyleRec_ { - LCUI_BOOL is_valid:1; - LCUI_BOOL is_changed:1; - LCUI_StyleType type:30; + LCUI_BOOL is_valid:2; + LCUI_BOOL is_changed:2; + unsigned short int type; union { int value; int val_int; diff --git a/include/LCUI/gui/widget_base.h b/include/LCUI/gui/widget_base.h index ea255c8b..a927bcf5 100755 --- a/include/LCUI/gui/widget_base.h +++ b/include/LCUI/gui/widget_base.h @@ -194,7 +194,6 @@ enum WidgetTaskType { WTT_OPACITY, WTT_BODY, WTT_REFRESH, - WTT_CACHE_STYLE, /**< 缓存当前样式 */ WTT_USER, WTT_TOTAL_NUM }; @@ -241,9 +240,8 @@ typedef struct LCUI_WidgetRec_ { LCUI_Rect2 margin; /**< 外边距框 */ LCUI_WidgetBoxRect box; /**< 部件的各个区域信息 */ LCUI_StyleSheet style; /**< 当前完整样式表 */ - LCUI_StyleSheet cached_style; /**< 已缓存的完整样式表 */ - LCUI_StyleSheet inherited_style; /**< 通过继承得到的样式表 */ LCUI_StyleSheet custom_style; /**< 自定义样式表 */ + LCUI_StyleSheet inherited_style; /**< 通过继承得到的样式表 */ LCUI_WidgetStyle computed_style; /**< 已经计算的样式数据 */ LCUI_Widget parent; /**< 父部件 */ LinkedList children; /**< 子部件 */ diff --git a/src/gui/widget_background.c b/src/gui/widget_background.c index 7b761a04..e50c893d 100644 --- a/src/gui/widget_background.c +++ b/src/gui/widget_background.c @@ -124,7 +124,7 @@ static void AsyncLoadImage( LCUI_Widget widget, const char *path ) { ImageCache cache; LCUI_AppTaskRec task = {0}; - LCUI_Style s = &widget->cached_style->sheet[key_background_image]; + LCUI_Style s = &widget->style->sheet[key_background_image]; if( !is_inited ) { RBTree_Init( &images ); diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index 9b051971..bcfeb30d 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -307,7 +307,6 @@ static void Widget_Init( LCUI_Widget widget ) widget->trigger = EventTrigger(); widget->style = StyleSheet(); widget->custom_style = StyleSheet(); - widget->cached_style = StyleSheet(); widget->inherited_style = StyleSheet(); widget->computed_style.opacity = 1.0; widget->computed_style.visible = TRUE; @@ -380,7 +379,6 @@ void Widget_ExecDestroy( LCUI_Widget widget ) LinkedList_ClearData( &widget->children, Widget_OnDestroy ); LinkedList_Clear( &widget->dirty_rects, free ); StyleSheet_Delete( widget->inherited_style ); - StyleSheet_Delete( widget->cached_style ); StyleSheet_Delete( widget->custom_style ); StyleSheet_Delete( widget->style ); Widget_PostSurfaceEvent( widget, WET_REMOVE ); @@ -1145,6 +1143,7 @@ static void Widget_ComputeSize( LCUI_Widget w ) static void Widget_SendResizeEvent( LCUI_Widget w ) { + LCUI_Style s; LCUI_Widget child; LCUI_WidgetEventRec e; LinkedListNode *node; @@ -1157,14 +1156,19 @@ static void Widget_SendResizeEvent( LCUI_Widget w ) Widget_PostSurfaceEvent( w, WET_RESIZE ); for( LinkedList_Each( node, &w->children ) ) { child = node->data; - if( child->style->sheet[key_width].type == SVT_SCALE || - child->style->sheet[key_height].type == SVT_SCALE ) { + s = child->style->sheet; + if( s[key_width].type == SVT_SCALE || + s[key_height].type == SVT_SCALE ) { Widget_AddTask( child, WTT_RESIZE ); } - if( child->computed_style.position == SV_ABSOLUTE && - (child->style->sheet[key_right].is_valid || - child->style->sheet[key_bottom].is_valid) ) { - Widget_AddTask( child, WTT_POSITION ); + if( child->computed_style.position == SV_ABSOLUTE ) { + if( s[key_right].is_valid || s[key_bottom].is_valid ) { + Widget_AddTask( child, WTT_POSITION ); + } + else if( s[key_margin_left].is_valid && + s[key_margin_left].value == SV_AUTO ) { + Widget_AddTask( child, WTT_POSITION ); + } } if( child->computed_style.vertical_align != SV_TOP ) { Widget_AddTask( child, WTT_POSITION ); diff --git a/src/gui/widget_style.c b/src/gui/widget_style.c index 56024ac2..6f582b52 100644 --- a/src/gui/widget_style.c +++ b/src/gui/widget_style.c @@ -300,12 +300,12 @@ void Selector_Delete( LCUI_Selector s ) LCUI_StyleSheet StyleSheet( void ) { LCUI_StyleSheet ss; - ss = malloc( sizeof( LCUI_StyleSheetRec ) ); + ss = NEW( LCUI_StyleSheetRec, 1 ); if( !ss ) { return ss; } ss->length = LCUICSS_GetStyleTotal(); - ss->sheet = NEW(LCUI_StyleRec, ss->length + 1); + ss->sheet = NEW( LCUI_StyleRec, ss->length + 1 ); return ss; } @@ -655,11 +655,11 @@ static int SelectorNode_Update( LCUI_SelectorNode node ) node->rank = 0; if( node->id ) { - len += strlen( node->id ) + 2; + len += strlen( node->id ) + 1; node->rank += ID_RANK; } if( node->type ) { - len += strlen( node->type ) + 2; + len += strlen( node->type ) + 1; node->rank += TYPE_RANK; } if( node->classes ) { @@ -667,17 +667,15 @@ static int SelectorNode_Update( LCUI_SelectorNode node ) len += strlen( node->classes[i] ) + 1; node->rank += CLASS_RANK; } - len += 1; } if( node->status ) { for( i = 0; node->status[i]; ++i ) { len += strlen( node->status[i] ) + 1; node->rank += PCLASS_RANK; } - len += 1; } if( len > 0 ) { - fullname = malloc( sizeof( char ) * len ); + fullname = malloc( sizeof( char ) * (len + 1) ); if( !fullname ) { return -ENOMEM; } diff --git a/src/gui/widget_task.c b/src/gui/widget_task.c index e9874515..8420234a 100644 --- a/src/gui/widget_task.c +++ b/src/gui/widget_task.c @@ -58,19 +58,11 @@ static void HandleRefreshStyle( LCUI_Widget w ) { Widget_ExecUpdateStyle( w, TRUE ); w->task.buffer[WTT_UPDATE_STYLE] = FALSE; - w->task.buffer[WTT_CACHE_STYLE] = TRUE; } static void HandleUpdateStyle( LCUI_Widget w ) { Widget_ExecUpdateStyle( w, FALSE ); - w->task.buffer[WTT_CACHE_STYLE] = TRUE; -} - -static void HandleCacheStyle( LCUI_Widget w ) -{ - StyleSheet_Clear( w->cached_style ); - StyleSheet_Replace( w->cached_style, w->style ); } static void HandleSetTitle( LCUI_Widget w ) @@ -144,7 +136,6 @@ static void MapTaskHandler(void) self.handlers[WTT_REFRESH] = HandleRefresh; self.handlers[WTT_UPDATE_STYLE] = HandleUpdateStyle; self.handlers[WTT_REFRESH_STYLE] = HandleRefreshStyle; - self.handlers[WTT_CACHE_STYLE] = HandleCacheStyle; self.handlers[WTT_BACKGROUND] = Widget_UpdateBackground; self.handlers[WTT_LAYOUT] = Widget_ExecUpdateLayout; self.handlers[WTT_ZINDEX] = Widget_ExecUpdateZIndex; @@ -182,79 +173,77 @@ int Widget_UpdateEx( LCUI_Widget w, LCUI_BOOL has_timeout ) { int i; LCUI_BOOL *buffer; - LCUI_Widget child; LinkedListNode *node, *next; - /* 如果该部件有任务需要处理 */ - if( w->task.for_self ) { - if( LCUIMutex_TryLock( &w->mutex ) != 0 ) { - goto skip_proc_self_task; - } - w->task.for_self = FALSE; - buffer = w->task.buffer; - /* 如果有用户自定义任务 */ - if( buffer[WTT_USER] ) { - LCUI_WidgetClass *wc; - wc = LCUIWidget_GetClass( w->type ); - wc ? wc->task_handler( w ) : FALSE; - } - for( i = 0; i < WTT_USER; ++i ) { - if( buffer[i] ) { - buffer[i] = FALSE; - if( self.handlers[i] ) { - self.handlers[i]( w ); - } - } else { - buffer[i] = FALSE; - } - } - LCUIMutex_Unlock( &w->mutex ); - /* 如果部件还处于未准备完毕的状态 */ - if( w->state < WSTATE_READY ) { - w->state |= WSTATE_UPDATED; - /* 如果部件已经准备完毕则触发 ready 事件 */ - if( w->state == WSTATE_READY ) { - LCUI_WidgetEventRec e; - e.type = WET_READY; - e.cancel_bubble = TRUE; - Widget_TriggerEvent( w, &e, NULL ); - w->state = WSTATE_NORMAL; - } - } - self.count += 1; + /* 如果该部件没有任务需要处理、或者被其它线程占用 */ + if( !w->task.for_self || LCUIMutex_TryLock( &w->mutex ) != 0 ) { + goto proc_children_task; } - -skip_proc_self_task:; - - /* 如果子级部件中有待处理的部件,则递归进去 */ - if( w->task.for_children ) { - w->task.for_children = FALSE; - node = w->children.head.next; - while( node ) { - child = node->data; - /* 如果当前部件有销毁任务,结点空间会连同部件一起被 - * 释放,为避免因访问非法空间而出现异常,预先保存下 - * 个结点。 - */ - next = node->next; - /* 如果该级部件的任务需要留到下次再处理 */ - if( Widget_UpdateEx( child, has_timeout ) ) { - w->task.for_children = TRUE; + w->task.for_self = FALSE; + buffer = w->task.buffer; + /* 如果有用户自定义任务 */ + if( buffer[WTT_USER] ) { + LCUI_WidgetClass *wc; + wc = LCUIWidget_GetClass( w->type ); + wc ? wc->task_handler( w ) : FALSE; + } + for( i = 0; i < WTT_USER; ++i ) { + if( buffer[i] ) { + buffer[i] = FALSE; + if( self.handlers[i] ) { + self.handlers[i]( w ); } - if( has_timeout ) { - if( !self.is_timeout && self.count >= 50 ) { - self.count = 0; - if( LCUI_GetTime() >= self.timeout ) { - self.is_timeout = TRUE; - } - } - if( self.is_timeout ) { - break; - } - } - node = next; + } else { + buffer[i] = FALSE; } } + LCUIMutex_Unlock( &w->mutex ); + /* 如果部件还处于未准备完毕的状态 */ + if( w->state < WSTATE_READY ) { + w->state |= WSTATE_UPDATED; + /* 如果部件已经准备完毕则触发 ready 事件 */ + if( w->state == WSTATE_READY ) { + LCUI_WidgetEventRec e; + e.type = WET_READY; + e.cancel_bubble = TRUE; + Widget_TriggerEvent( w, &e, NULL ); + w->state = WSTATE_NORMAL; + } + } + self.count += 1; + +proc_children_task: + + if( !w->task.for_children ) { + return w->task.for_self; + } + /* 如果子级部件中有待处理的部件,则递归进去 */ + w->task.for_children = FALSE; + node = w->children.head.next; + while( node ) { + LCUI_Widget child = node->data; + /* 如果当前部件有销毁任务,结点空间会连同部件一起被 + * 释放,为避免因访问非法空间而出现异常,预先保存下 + * 个结点。 + */ + next = node->next; + /* 如果该级部件的任务需要留到下次再处理 */ + if( Widget_UpdateEx( child, has_timeout ) ) { + w->task.for_children = TRUE; + } + if( has_timeout ) { + if( !self.is_timeout && self.count >= 50 ) { + self.count = 0; + if( LCUI_GetTime() >= self.timeout ) { + self.is_timeout = TRUE; + } + } + if( self.is_timeout ) { + break; + } + } + node = next; + } return w->task.for_self || w->task.for_children; } From 1423eec519d6e7d11c2381dca9f0bae74aa072a2 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Sun, 28 Aug 2016 22:08:02 +0800 Subject: [PATCH 115/124] =?UTF-8?q?=E7=BA=A0=E6=AD=A3=E9=83=A8=E4=BB=B6?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E8=A1=A8=E7=9A=84=E5=AF=B9=E6=AF=94=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E3=80=81=E6=9B=B4=E6=96=B0=20textview=20=E9=83=A8?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E7=BC=BA=E7=9C=81=E6=A0=B7=E5=BC=8F=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gui/widget/textview.c | 72 ++++++++++++++++++++++++++------------- src/gui/widget_style.c | 10 ++++-- 2 files changed, 56 insertions(+), 26 deletions(-) diff --git a/src/gui/widget/textview.c b/src/gui/widget/textview.c index ef96c147..1ca55e44 100644 --- a/src/gui/widget/textview.c +++ b/src/gui/widget/textview.c @@ -56,7 +56,8 @@ enum TaskType { typedef struct LCUI_TextView_ { LCUI_TextStyle style; - LCUI_TextLayer layer; /**< 文本图层 */ + LCUI_BOOL has_content; /**< 是否有设置 content 属性 */ + LCUI_TextLayer layer; /**< 文本图层 */ struct { LCUI_BOOL is_valid; union { @@ -67,11 +68,6 @@ typedef struct LCUI_TextView_ { } tasks[TASK_TOTAL]; } LCUI_TextView; -static const char *textview_css = ToString( -textview{ - white-space: normal; -} -); /*---------------------------- Private -------------------------------*/ enum FontStyleKey { @@ -251,42 +247,72 @@ static void TextView_UpdateStyle( LCUI_Widget w ) continue; } s = &w->style->sheet[style_key_map[i]]; - if( !s->is_valid ) { - continue; - } switch( i ) { case key_color: - txt->style.fore_color = s->color; - txt->style.has_fore_color = TRUE; + if( s->is_valid ) { + txt->style.fore_color = s->color; + txt->style.has_fore_color = TRUE; + } else { + txt->style.has_fore_color = FALSE; + } break; case key_font_family: - TextStyle_SetFont( &txt->style, s->string ); + if( s->is_valid ) { + TextStyle_SetFont( &txt->style, s->string ); + } else { + TextStyle_SetFont( &txt->style, NULL ); + } break; case key_font_size: - if( s->type == SVT_PX ) { - txt->style.pixel_size = s->px; - } else if( s->type == SVT_PT ) { - // ... + txt->style.pixel_size = 14; + if( s->is_valid ) { + if( s->type == SVT_PX ) { + txt->style.pixel_size = s->px; + } } txt->style.has_pixel_size = TRUE; break; case key_font_style: - txt->style.style = s->value; - txt->style.has_style = TRUE; + txt->style.has_style = FALSE; + if( s->is_valid ) { + txt->style.style = s->value; + txt->style.has_style = TRUE; + } break; case key_font_weight: break; case key_text_align: - TextLayer_SetTextAlign( txt->layer, s->style ); + if( s->is_valid ) { + TextLayer_SetTextAlign( txt->layer, s->style ); + } else { + TextLayer_SetTextAlign( txt->layer, SV_LEFT ); + } break; case key_line_height: - TextLayer_SetLineHeight( txt->layer, s ); + if( s->is_valid ) { + TextLayer_SetLineHeight( txt->layer, s ); + } else { + LCUI_StyleRec style; + style.val_scale = 1.5; + style.type = SVT_SCALE; + style.is_valid = TRUE; + TextLayer_SetLineHeight( txt->layer, &style ); + } break; case key_content: - TextView_SetTextW( w, s->wstring ); + if( s->is_valid ) { + txt->has_content = TRUE; + TextView_SetTextW( w, s->wstring ); + } else { + if( txt->has_content ) { + txt->has_content = FALSE; + TextView_SetTextW( w, NULL ); + } + } break; case key_white_space: - if( s->type != SVT_STYLE ) { + if( !s->is_valid || s->type != SVT_STYLE ) { + TextLayer_SetAutoWrap( txt->layer, FALSE ); break; } if( s->style == SV_NOWRAP ) { @@ -345,6 +371,7 @@ static void TextView_OnInit( LCUI_Widget w ) for( i = 0; i < TASK_TOTAL; ++i ) { txt->tasks[i].is_valid = FALSE; } + txt->has_content = FALSE; /* 初始化文本图层 */ txt->layer = TextLayer_New(); /* 启用多行文本显示 */ @@ -544,5 +571,4 @@ void LCUIWidget_AddTextView( void ) style_key_map[style_parsers[i].key] = LCUICSS_AddParser( &style_parsers[i] ); } - LCUICSS_LoadString( textview_css, NULL ); } diff --git a/src/gui/widget_style.c b/src/gui/widget_style.c index 6f582b52..64cb0cac 100644 --- a/src/gui/widget_style.c +++ b/src/gui/widget_style.c @@ -1397,6 +1397,7 @@ void Widget_ExecUpdateStyle( LCUI_Widget w, LCUI_BOOL is_update_all ) { int i, key; LCUI_Style s; + LCUI_StyleSheet ss; LCUI_WidgetClass *wc; LCUI_BOOL need_update_expend_style = FALSE; typedef struct { @@ -1420,16 +1421,18 @@ void Widget_ExecUpdateStyle( LCUI_Widget w, LCUI_BOOL is_update_all ) if( is_update_all ) { Widget_GetInheritStyle( w, w->inherited_style ); } - StyleSheet_Clear( w->style ); + ss = w->style; + w->style = StyleSheet(); StyleSheet_Merge( w->style, w->custom_style ); StyleSheet_Merge( w->style, w->inherited_style ); /* 对比两张样式表,确定哪些需要更新 */ for( key = 0; key < w->style->length; ++key ) { s = &w->style->sheet[key]; - if( !s->is_changed ) { + if( ss->sheet[key].is_valid == s->is_valid && + ss->sheet[key].type == s->type && + ss->sheet[key].value == s->value ) { continue; } - s->is_changed = FALSE; if( key >= STYLE_KEY_TOTAL ) { need_update_expend_style = TRUE; break; @@ -1449,6 +1452,7 @@ void Widget_ExecUpdateStyle( LCUI_Widget w, LCUI_BOOL is_update_all ) wc = LCUIWidget_GetClass( w->type ); wc && wc->methods.update ? wc->methods.update( w ) : 0; } + StyleSheet_Delete( ss ); } void LCUIWidget_ExitStyle( void ) From 9fbc433c97d203d970b9779b5b8a7eaa9b80b59d Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Tue, 30 Aug 2016 23:38:53 +0800 Subject: [PATCH 116/124] =?UTF-8?q?=E5=B0=86=20CSS=20=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E4=BB=A3=E7=A0=81=E6=8A=BD=E7=A6=BB=E8=87=B3?= =?UTF-8?q?=20css=5Flibrary.c=EF=BC=8C=E8=B0=83=E6=95=B4=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/gui/Makefile.am | 2 +- include/LCUI/gui/css_library.h | 236 ++++++ include/LCUI/gui/css_parser.h | 19 +- include/LCUI/gui/widget_base.h | 113 +-- include/LCUI/gui/widget_style.h | 6 +- include/LCUI/util/dict.h | 5 +- include/LCUI/util/string.h | 35 +- src/gui/Makefile.am | 1 + src/gui/builder.c | 4 +- src/gui/css_library.c | 1401 +++++++++++++++++++++++++++++++ src/gui/css_parser.c | 238 +----- src/gui/widget/button.c | 2 +- src/gui/widget/scrollbar.c | 2 +- src/gui/widget/sidebar.c | 2 +- src/gui/widget/textedit.c | 4 +- src/gui/widget/textview.c | 6 +- src/gui/widget_base.c | 142 +--- src/gui/widget_style.c | 1242 +-------------------------- src/main.c | 2 + src/util/Makefile.am | 2 +- src/util/dict.c | 30 + src/util/mem_debug.c | 45 - src/util/string.c | 169 ++++ 23 files changed, 1973 insertions(+), 1735 deletions(-) create mode 100644 include/LCUI/gui/css_library.h create mode 100644 src/gui/css_library.c delete mode 100644 src/util/mem_debug.c diff --git a/include/LCUI/gui/Makefile.am b/include/LCUI/gui/Makefile.am index 704128ee..6389a95b 100755 --- a/include/LCUI/gui/Makefile.am +++ b/include/LCUI/gui/Makefile.am @@ -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 diff --git a/include/LCUI/gui/css_library.h b/include/LCUI/gui/css_library.h new file mode 100644 index 00000000..afdd0d7f --- /dev/null +++ b/include/LCUI/gui/css_library.h @@ -0,0 +1,236 @@ +/* *************************************************************************** + * css_library.h -- css library operation module. + * + * Copyright (C) 2015-2016 by Liu Chao + * + * 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * css_library.h -- CSS 样式库操作模块 + * + * 版权所有 (C) 2015-2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ + +#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 \ No newline at end of file diff --git a/include/LCUI/gui/css_parser.h b/include/LCUI/gui/css_parser.h index c4064bd1..bb81d22f 100644 --- a/include/LCUI/gui/css_parser.h +++ b/include/LCUI/gui/css_parser.h @@ -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 diff --git a/include/LCUI/gui/widget_base.h b/include/LCUI/gui/widget_base.h index a927bcf5..26e758a3 100755 --- a/include/LCUI/gui/widget_base.h +++ b/include/LCUI/gui/widget_base.h @@ -42,10 +42,8 @@ LCUI_BEGIN_HEADER -/** 如果没有包含 widget_build.h 头文件 */ -#ifndef LCUI_WIDGET_BUILD_H -typedef struct LCUI_WidgetBase* LCUI_Widget; -#endif +#include +#include /** 部件样式 */ 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, /**< 刷新部件全部样式 */ diff --git a/include/LCUI/gui/widget_style.h b/include/LCUI/gui/widget_style.h index 101a73b0..e026fb4d 100644 --- a/include/LCUI/gui/widget_style.h +++ b/include/LCUI/gui/widget_style.h @@ -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 - #endif diff --git a/include/LCUI/util/dict.h b/include/LCUI/util/dict.h index 2eb50ad1..b3432018 100644 --- a/include/LCUI/util/dict.h +++ b/include/LCUI/util/dict.h @@ -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 */ diff --git a/include/LCUI/util/string.h b/include/LCUI/util/string.h index 2bcfe153..e7ccb35e 100644 --- a/include/LCUI/util/string.h +++ b/include/LCUI/util/string.h @@ -1,7 +1,7 @@ /* *************************************************************************** * string.h -- The string operation set. * - * Copyright (C) 2015 by Liu Chao + * Copyright (C) 2015-2016 by Liu Chao * * 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 归属于 刘超 + * 版权所有 (C) 2015-2016 归属于 刘超 * * 这个文件是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 ); diff --git a/src/gui/Makefile.am b/src/gui/Makefile.am index ccda2759..d3c8679c 100755 --- a/src/gui/Makefile.am +++ b/src/gui/Makefile.am @@ -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 \ diff --git a/src/gui/builder.c b/src/gui/builder.c index 630943e0..7b4eaeb2 100644 --- a/src/gui/builder.c +++ b/src/gui/builder.c @@ -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; diff --git a/src/gui/css_library.c b/src/gui/css_library.c new file mode 100644 index 00000000..ff316b2e --- /dev/null +++ b/src/gui/css_library.c @@ -0,0 +1,1401 @@ +/* *************************************************************************** + * css_library.c -- css library operation module. + * + * Copyright (C) 2015-2016 by Liu Chao + * + * 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 . + * ****************************************************************************/ + +/* **************************************************************************** + * css_library.c -- CSS 样式库操作模块 + * + * 版权所有 (C) 2015-2016 归属于 刘超 + * + * 这个文件是LCUI项目的一部分,并且只可以根据GPLv2许可协议来使用、更改和发布。 + * + * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写) + * + * 继续使用、修改或发布本文件,表明您已经阅读并完全理解和接受这个许可协议。 + * + * LCUI 项目是基于使用目的而加以散布的,但不负任何担保责任,甚至没有适销性或特 + * 定用途的隐含担保,详情请参照GPLv2许可协议。 + * + * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 + * 没有,请查看:. + * ****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX_NAME_LEN 256 +#define LEN(A) sizeof( A ) / sizeof( *A ) + +enum SelectorRank { + GENERAL_RANK = 0, + TYPE_RANK = 1, + CLASS_RANK = 10, + PCLASS_RANK = 10, + ID_RANK = 100 +}; + +enum SelectorFinderLevel { + LEVEL_NONE, + LEVEL_TYPE, + LEVEL_ID, + LEVEL_CLASS, + LEVEL_CLASS_2, + LEVEL_STATUS, + LEVEL_STATUS_2, + LEVEL_TOTAL_NUM +}; + +/* 样式表查找器的上下文数据结构 */ +typedef struct NamesFinderRec_ { + int level; /**< 当前选择器层级 */ + int class_i; /**< 当前处理到第几个类名 */ + int status_i; /**< 当前处理到第几个状态名(伪类名) */ + int name_i; /**< 选择器名称从第几个字符开始 */ + char name[MAX_NAME_LEN]; /**< 选择器名称缓存 */ + LCUI_SelectorNode node; /**< 针对的选择器结点 */ +} NamesFinderRec, *NamesFinder; + +/** 样式链接记录组 */ +typedef struct StyleLinkGroupRec_ { + Dict *links; /**< 样式链接表 */ + char *name; /**< 选择器名称 */ + LCUI_SelectorNodeRec snode; /**< 选择器结点 */ +} StyleLinkGroupRec, *StyleLinkGroup; + +/** 样式结点记录 */ +typedef struct StyleNodeRec_ { + int rank; /**< 权值,决定优先级 */ + int batch_num; /**< 批次号 */ + char *space; /**< 所属的空间 */ + char *selector; /**< 选择器 */ + LCUI_StyleSheet sheet; /**< 样式表 */ +} StyleNodeRec, *StyleNode; + +/** 样式链接记录 */ +typedef struct StyleLinkRec_ { + char *selector; /**< 选择器 */ + StyleLinkGroup group; /**< 所属组 */ + LinkedList styles; /**< 作用于当前选择器的样式 */ + Dict *parents; /**< 父级节点 */ +} StyleLinkRec, *StyleLink; + +static struct { + LCUI_BOOL is_inited; + LCUI_Mutex mutex; /**< 互斥锁 */ + LinkedList groups; /**< 样式组列表 */ + DictType cachedict; /**< 样式表缓存字典的类型数据 */ + Dict *cache; /**< 样式表缓存,以选择器的 hash 值索引 */ + Dict *names; /**< 样式属性名称表,以值的名称索引 */ + Dict *value_keys; /**< 样式属性值表,以值的名称索引 */ + Dict *value_names; /**< 样式属性值名称表,以值索引 */ + size_t count; /**< 当前记录的属性数量 */ +} library; + +/** 样式字符串值与标识码 */ +typedef struct KeyNameGroupRec_ { + int key; + char *name; +} KeyNameGroupRec, *KeyNameGroup; + +static KeyNameGroupRec 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 KeyNameGroupRec style_value_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 int LCUI_DirectAddStyleName( int key, const char *name ) +{ + char *newname = strdup( name ); + if( !newname ) { + return -ENOMEM; + } + if( Dict_Add( library.names, (void*)key, newname ) == 0 ) { + return 0; + } + free( newname ); + return -1; +} + +int LCUI_AddStyleName( int key, const char *name ) +{ + int ret; + LCUIMutex_Lock( &library.mutex ); + key = library.count++; + ret = LCUI_DirectAddStyleName( key, name ); + if( ret != 0 ) { + --library.count; + } + LCUIMutex_Unlock( &library.mutex ); + return ret; +} + +int LCUI_AddStyleValue( int key, const char *name ) +{ + int *val; + char *newname; + newname = strdup( name ); + if( !newname ) { + return -ENOMEM; + } + val = malloc( sizeof( int ) ); + if( !val ) { + free( newname ); + return -ENOMEM; + } + *val = key; + if( Dict_Add( library.value_keys, newname, val ) ) { + free( newname ); + free( val ); + return -1; + } + return Dict_Add( library.value_names, val, newname ); +} + +int LCUI_GetStyleValue( const char *str ) +{ + int *val = Dict_FetchValue( library.value_keys, str ); + if( val ) { + return *val; + } + return -1; +} + +const char *LCUI_GetStyleValueName( int val ) +{ + return Dict_FetchValue( library.value_names, (void*)val ); +} + +const char *LCUI_GetStyleName( int key ) +{ + return Dict_FetchValue( library.names, (void*)key ); +} + +int LCUI_GetStyleTotal( void ) +{ + return library.count; +} + +LCUI_BOOL SelectorNode_Match( LCUI_SelectorNode sn1, + LCUI_SelectorNode sn2 ) +{ + int i, j; + if( sn2->id ) { + if( !sn1->id || strcmp( sn1->id, sn2->id ) != 0 ) { + return FALSE; + } + } + if( sn2->type && strcmp(sn2->type, "*") != 0 ) { + if( !sn1->type || strcmp( sn1->type, sn2->type ) != 0 ) { + return FALSE; + } + } + if( sn2->classes ) { + if( !sn1->classes ) { + return FALSE; + } + for( i = 0; sn2->classes[i]; ++i ) { + for( j = 0; sn1->classes[j]; ++j ) { + if( strcmp( sn2->classes[i], + sn1->classes[i] ) == 0 ) { + j = -1; + break; + } + } + if( j != -1 ) { + return FALSE; + } + } + } + if( sn2->status ) { + if( !sn1->status ) { + return FALSE; + } + for( i = 0; sn2->status[i]; ++i ) { + for( j = 0; sn1->status[j]; ++j ) { + if( strcmp( sn2->status[i], + sn1->status[i] ) == 0 ) { + j = -1; + break; + } + } + if( j != -1 ) { + return FALSE; + } + } + } + return TRUE; +} + +static void SelectorNode_Copy( LCUI_SelectorNode dst, LCUI_SelectorNode src ) +{ + int i; + dst->id = src->id ? strdup( src->id ) : NULL; + dst->type = src->type ? strdup( src->type ) : NULL; + dst->fullname = src->fullname ? strdup( src->fullname ) : NULL; + if( src->classes ) { + for( i = 0; src->classes[i]; ++i ) { + sortedstrsadd( &dst->classes, src->classes[i] ); + } + } + if( src->status ) { + for( i = 0; src->status[i]; ++i ) { + sortedstrsadd( &dst->status, src->status[i] ); + } + } +} + +static void SelectorNode_Delete( LCUI_SelectorNode node ) +{ + if( node->type ) { + free( node->type ); + node->type = NULL; + } + if( node->id ) { + free( node->id ); + node->id = NULL; + } + if( node->classes ) { + freestrs( node->classes ); + node->classes = NULL; + } + if( node->status ) { + freestrs( node->status ); + node->status = NULL; + } + if( node->fullname ) { + free( node->fullname ); + node->fullname = NULL; + } + free( node ); +} + +void Selector_Delete( LCUI_Selector s ) +{ + int i; + for( i = 0; i < MAX_SELECTOR_DEPTH; ++i ) { + if( !s->nodes[i] ) { + break; + } + SelectorNode_Delete( s->nodes[i] ); + s->nodes[i] = NULL; + } + s->rank = 0; + s->length = 0; + s->batch_num = 0; + free( s->nodes ); + free( s ); +} + +LCUI_StyleSheet StyleSheet( void ) +{ + LCUI_StyleSheet ss; + ss = NEW( LCUI_StyleSheetRec, 1 ); + if( !ss ) { + return ss; + } + ss->length = LCUI_GetStyleTotal(); + ss->sheet = NEW( LCUI_StyleRec, ss->length + 1 ); + return ss; +} + +void StyleSheet_Clear( LCUI_StyleSheet ss ) +{ + int i; + LCUI_Style s; + for( i = 0; i < ss->length; ++i ) { + s = &ss->sheet[i]; + switch( s->type ) { + case SVT_STRING: + case SVT_WSTRING: + if( s->is_valid && s->string ) { + free( s->string ); + } + s->string = NULL; + default: break; + } + s->is_valid = FALSE; + s->is_changed = TRUE; + } +} + +void StyleSheet_Delete( LCUI_StyleSheet ss ) +{ + StyleSheet_Clear( ss ); + free( ss->sheet ); + free( ss ); +} + +int StyleSheet_Merge( LCUI_StyleSheet dest, LCUI_StyleSheet src ) +{ + LCUI_Style s; + int i, name_count, size; + if( src->length > dest->length ) { + size = sizeof( LCUI_StyleRec )*src->length; + s = realloc( dest->sheet, size ); + if( !s ) { + return -1; + } + for( i = dest->length; i < src->length; ++i ) { + s[i].is_valid = FALSE; + } + dest->sheet = s; + dest->length = src->length; + } + for( name_count = 0, i = 0; i < src->length; ++i ) { + s = &dest->sheet[i]; + if( !src->sheet[i].is_valid || s->is_valid ) { + continue; + } + ++name_count; + switch( src->sheet[i].type ) { + case SVT_STRING: + s->string = strdup( src->sheet[i].string ); + break; + case SVT_WSTRING: + size = wcslen( src->sheet[i].wstring ) + 1; + s->wstring = malloc( size * sizeof( wchar_t ) ); + wcscpy( s->wstring, src->sheet[i].wstring ); + break; + default: + *s = src->sheet[i]; + break; + } + s->is_valid = TRUE; + s->is_changed = TRUE; + s->type = src->sheet[i].type; + } + return 0; +} + +int StyleSheet_Replace( LCUI_StyleSheet dest, LCUI_StyleSheet src ) +{ + LCUI_Style s; + int i, name_count, size; + if( src->length > dest->length ) { + size = sizeof(LCUI_StyleRec)*src->length; + s = realloc( dest->sheet, size ); + if( !s ) { + return -1; + } + for( i=dest->length; ilength; ++i ) { + s[i].is_valid = FALSE; + } + dest->sheet = s; + dest->length = src->length; + } + for( name_count=0,i=0; ilength; ++i ) { + if( !src->sheet[i].is_valid ) { + continue; + } + s = &dest->sheet[i]; + switch( src->sheet[i].type ) { + case SVT_STRING: + if( s->is_valid && s->string ) { + free( s->string ); + } + s->string = strdup( src->sheet[i].string ); + break; + case SVT_WSTRING: + if( s->is_valid && s->string ) { + free( s->wstring ); + } + size = wcslen( src->sheet[i].wstring ) + 1; + s->wstring = malloc( size * sizeof(wchar_t) ); + wcscpy( s->wstring, src->sheet[i].wstring ); + break; + default: + *s = src->sheet[i]; + break; + } + s->is_valid = TRUE; + s->is_changed = TRUE; + s->type = src->sheet[i].type; + ++name_count; + } + return name_count; +} + +/** 初始化样式表查找器 */ +static void NamesFinder_Init( NamesFinder sfinder, LCUI_SelectorNode snode ) +{ + sfinder->level = 0; + sfinder->class_i = 0; + sfinder->name_i = 0; + sfinder->status_i = 0; + sfinder->name[0] = 0; + sfinder->node = snode; +} + +/** 销毁样式表查找器 */ +static void NamesFinder_Destroy( NamesFinder sfinder ) +{ + sfinder->name_i = 0; + sfinder->name[0] = 0; + sfinder->class_i = 0; + sfinder->status_i = 0; + sfinder->node = NULL; + sfinder->level = LEVEL_NONE; +} + +/* 生成选择器全名列表 */ +static int NamesFinder_Find( NamesFinder sfinder, LinkedList *list ) +{ + int i, len, old_len, old_level, name_count = 0; + char *fullname = sfinder->name + sfinder->name_i; + old_len = len = strlen( fullname ); + old_level = sfinder->level; + switch( sfinder->level ) { + case LEVEL_TYPE: + /* 按类型选择器生成选择器全名 */ + if( !sfinder->node->type ) { + return 0; + } + strcpy( fullname, sfinder->node->type ); + LinkedList_Append( list, strdup( fullname ) ); + break; + case LEVEL_ID: + /* 按ID选择器生成选择器全名 */ + if( !sfinder->node->id ) { + return 0; + } + fullname[len++] = '#'; + fullname[len] = 0; + strcpy( fullname + len, sfinder->node->id ); + LinkedList_Append( list, strdup( fullname ) ); + break; + case LEVEL_CLASS: + if( !sfinder->node->classes ) { + return 0; + } + /* 按类选择器生成选择器全名 + * 假设当前选择器全名为:textview#main-btn-text,且有 .a .b .c + * 这三个类,那么下面的处理将会拆分成以下三个选择器: + * textview#test-text.a + * textview#test-text.b + * textview#test-text.a + */ + fullname[len++] = '.'; + for( i = 0; sfinder->node->classes[i]; ++i ) { + sfinder->level += 1; + strcpy( fullname + len, sfinder->node->classes[i] ); + LinkedList_Append( list, strdup( fullname ) ); + /* 将当前选择器名与其它层级的选择器名组合 */ + while( sfinder->level < LEVEL_TOTAL_NUM ) { + name_count += NamesFinder_Find( sfinder, list ); + sfinder->level += 1; + } + sfinder->level = LEVEL_CLASS; + sfinder->class_i += 1; + } + sfinder->level = LEVEL_CLASS; + fullname[old_len] = 0; + sfinder->class_i = 0; + return name_count; + case LEVEL_CLASS_2: + if( !sfinder->node->classes ) { + return 0; + } + /* 按类选择器生成选择器全名,结果类似于这样: + * textview#test-text.a.b + * textview#test-text.a.c + * textview#test-text.b.c + * textview#test-text.a.b.c + */ + fullname[len++] = '.'; + for( i = 0; sfinder->node->classes[i]; ++i ) { + if( i <= sfinder->class_i ) { + continue; + } + strcpy( fullname + len, sfinder->node->classes[i] ); + LinkedList_Append( list, strdup( fullname ) ); + sfinder->class_i += 1; + name_count += NamesFinder_Find( sfinder, list ); + sfinder->class_i -= 1; + sfinder->level = LEVEL_STATUS; + /** + * 递归拼接伪类名,例如: + * textview#main-btn-text:active + */ + name_count += NamesFinder_Find( sfinder, list ); + sfinder->level = LEVEL_CLASS_2; + } + fullname[old_len] = 0; + sfinder->level = LEVEL_CLASS_2; + return name_count; + case LEVEL_STATUS: + if( !sfinder->node->status ) { + return 0; + } + fullname[len++] = ':'; + sfinder->level = LEVEL_STATUS_2; + /** + * 按伪类选择器生成选择器全名 + * 假设当前选择器全名为:textview#main-btn-text:hover:focus:active + * 那么下面的循环会将它拆分为以下几个选择器: + * textview#main-btn-text:active + * textview#main-btn-text:active:focus + * textview#main-btn-text:active:focus:hover + * textview#main-btn-text:active:hover + * textview#main-btn-text:focus + * textview#main-btn-text:focus:hover + * textview#main-btn-text:hover + */ + for( i = 0; sfinder->node->status[i]; ++i ) { + strcpy( fullname + len, sfinder->node->status[i] ); + LinkedList_Append( list, strdup( fullname ) ); + /** + * 递归调用,以一层层拼接出像下面这样的选择器: + * textview#main-btn-text:active:focus:hover + */ + name_count += NamesFinder_Find( sfinder, list ); + sfinder->status_i += 1; + } + sfinder->level = LEVEL_STATUS; + fullname[old_len] = 0; + sfinder->status_i = 0; + return name_count; + case LEVEL_STATUS_2: + if( !sfinder->node->status ) { + return 0; + } + /** 按伪类选择器生成选择器全名 */ + for( i = 0; sfinder->node->status[i]; ++i ) { + if( i <= sfinder->status_i ) { + continue; + } + fullname[len] = ':'; + strcpy( fullname + len + 1, sfinder->node->status[i] ); + LinkedList_Append( list, strdup( fullname ) ); + sfinder->status_i += 1; + name_count += NamesFinder_Find( sfinder, list ); + sfinder->status_i -= 1; + } + fullname[old_len] = 0; + return name_count; + default:break; + } + for( i = sfinder->level + 1; i < LEVEL_TOTAL_NUM; ++i ) { + if( i == LEVEL_STATUS_2 || i == LEVEL_CLASS_2 ) { + continue; + } + sfinder->level = i; + name_count += NamesFinder_Find( sfinder, list ); + } + fullname[old_len] = 0; + sfinder->level = old_level; + return name_count; +} + +static int SelectorNode_Save( LCUI_SelectorNode node, + const char *name, int len, char type ) +{ + char *str; + if( len < 1 ) { + return 0; + } + switch( type ) { + case 0: + if( node->type ) { + break; + } + len += 1; + str = malloc( sizeof( char ) * len ); + strncpy( str, name, len ); + node->type = str; + return TYPE_RANK; + case ':': + if( sortedstrsadd( &node->status, name ) == 0 ) { + return PCLASS_RANK; + } + break; + case '.': + if( sortedstrsadd( &node->classes, name ) == 0 ) { + return CLASS_RANK; + } + break; + case '#': + if( node->id ) { + break; + } + len += 1; + str = malloc( sizeof( char ) * len ); + strncpy( str, name, len ); + node->id = str; + return ID_RANK; + default: break; + } + return 0; +} + +int SelectorNode_GetNames( LCUI_SelectorNode sn, LinkedList *names ) +{ + int name_count; + NamesFinderRec sfinder; + NamesFinder_Init( &sfinder, sn ); + name_count = NamesFinder_Find( &sfinder, names ); + NamesFinder_Destroy( &sfinder ); + return name_count; +} + +int SelectorNode_Update( LCUI_SelectorNode node ) +{ + int i, len = 0; + char *fullname; + + node->rank = 0; + if( node->id ) { + len += strlen( node->id ) + 1; + node->rank += ID_RANK; + } + if( node->type ) { + len += strlen( node->type ) + 1; + node->rank += TYPE_RANK; + } + if( node->classes ) { + for( i = 0; node->classes[i]; ++i ) { + len += strlen( node->classes[i] ) + 1; + node->rank += CLASS_RANK; + } + } + if( node->status ) { + for( i = 0; node->status[i]; ++i ) { + len += strlen( node->status[i] ) + 1; + node->rank += PCLASS_RANK; + } + } + if( len > 0 ) { + fullname = malloc( sizeof( char ) * (len + 1) ); + if( !fullname ) { + return -ENOMEM; + } + fullname[0] = 0; + if( node->type ) { + strcat( fullname, node->type ); + } + if( node->id ) { + strcat( fullname, "#" ); + strcat( fullname, node->id ); + } + if( node->classes ) { + for( i = 0; node->classes[i]; ++i ) { + strcat( fullname, "." ); + strcat( fullname, node->classes[i] ); + } + len += 1; + } + if( node->status ) { + for( i = 0; node->status[i]; ++i ) { + strcat( fullname, ":" ); + strcat( fullname, node->status[i] ); + } + len += 1; + } + } else { + fullname = NULL; + } + if( node->fullname ) { + free( node->fullname ); + } + node->fullname = fullname; + return len; +} + +void Selector_Update( LCUI_Selector s ) +{ + int i; + const unsigned char *p; + unsigned int hash = 5381; + for( i = 0; i < s->length; ++i ) { + p = (unsigned char*)s->nodes[i]->fullname; + while( *p ) { + hash = ((hash << 5) + hash) + (*p++); + } + } + s->hash = hash; +} + +LCUI_Selector Selector( const char *selector ) +{ + const char *p; + int ni, si, rank; + static int batch_num = 0; + char type = 0, name[MAX_NAME_LEN]; + LCUI_BOOL is_saving = FALSE; + LCUI_SelectorNode node = NULL; + LCUI_Selector s = NEW( LCUI_SelectorRec, 1 ); + + s->batch_num = ++batch_num; + s->nodes = NEW( LCUI_SelectorNode, MAX_SELECTOR_DEPTH ); + if( !selector ) { + s->length = 0; + s->nodes[0] = NULL; + return s; + } + for( ni = 0, si = 0, p = selector; *p; ++p ) { + if( !node && is_saving ) { + node = NEW( LCUI_SelectorNodeRec, 1 ); + if( si >= MAX_SELECTOR_DEPTH ) { + _DEBUG_MSG( "%s: selector node list is too long.\n", + selector ); + return NULL; + } + s->nodes[si] = node; + } + switch( *p ) { + case ':': + case '.': + case '#': + if( !is_saving ) { + is_saving = TRUE; + type = *p; + continue; + } + /* 保存上个结点 */ + rank = SelectorNode_Save( node, name, ni, type ); + if( rank > 0 ) { + s->rank += rank; + } else { + _DEBUG_MSG( "%s: invalid selector node at %ld.\n", + selector, p - selector - ni ); + SelectorNode_Delete( node ); + node = NULL; + } + ni = 0; + is_saving = TRUE; + type = *p; + continue; + case ' ': + case '\r': + case '\n': + case '\t': + if( !is_saving ) { + ni = 0; + node = NULL; + continue; + } + is_saving = FALSE; + rank = SelectorNode_Save( node, name, ni, type ); + if( rank > 0 ) { + SelectorNode_Update( node ); + s->rank += rank; + node = NULL; + ni = 0; + si++; + continue; + } + _DEBUG_MSG( "%s: invalid selector node at %ld.\n", + selector, p - selector - ni ); + SelectorNode_Delete( node ); + node = NULL; + ni = 0; + continue; + default: break; + } + if( *p == '-' || *p == '_' || *p == '*' + || (*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') + || (*p >= '0' && *p <= '9') ) { + if( !is_saving ) { + type = 0; + is_saving = TRUE; + } + name[ni++] = *p; + name[ni] = 0; + continue; + } + _DEBUG_MSG( "%s: unknown char 0x%02x at %ld.\n", + selector, *p, p - selector ); + return NULL; + } + if( is_saving ) { + rank = SelectorNode_Save( s->nodes[si], name, ni, type ); + if( rank > 0 ) { + SelectorNode_Update( s->nodes[si] ); + s->rank += rank; + si++; + } else { + SelectorNode_Delete( s->nodes[si] ); + } + } + s->nodes[si] = NULL; + s->length = si; + Selector_Update( s ); + return s; +} + +static void DeleteStyleNode( StyleNode node ) +{ + if( node->space ) { + free( node->space ); + node->space = NULL; + } + if( node->selector ) { + free( node->selector ); + node->selector = NULL; + } + StyleSheet_Delete( node->sheet ); + node->sheet = NULL; +} + +static StyleLink CreateStyleLink( void ) +{ + StyleLink link = NEW( StyleLinkRec, 1 ); + link->group = NULL; + LinkedList_Init( &link->styles ); + link->parents = Dict_Create( &DictType_StringCopyKey, NULL ); + return link; +} + +static void DeleteStyleLink( StyleLink link ) +{ + link->group = NULL; + Dict_Release( link->parents ); + link->parents = NULL; + LinkedList_Clear( &link->styles, (FuncPtr)DeleteStyleNode ); +} + +static void OnDeleteStyleLink( void *privdata, void *data ) +{ + DeleteStyleLink( data ); +} + +static StyleLinkGroup CreateStyleLinkGroup( LCUI_SelectorNode snode ) +{ + DictType *dtype = NEW( DictType, 1 ); + StyleLinkGroup group = NEW( StyleLinkGroupRec, 1 ); + SelectorNode_Copy( &group->snode, snode ); + group->name = group->snode.fullname; + *dtype = DictType_StringCopyKey; + dtype->valDestructor = OnDeleteStyleLink; + group->links = Dict_Create( dtype, dtype ); + return group; +} + +static void DeleteStyleLinkGroup( StyleLinkGroup group ) +{ + free( group->name ); + Dict_Release( group->links ); + free( group->links->privdata ); + group->name = NULL; + group->links = NULL; +} + +static void OnDeleteStyleLinkGroup( void *privdata, void *data ) +{ + DeleteStyleLinkGroup( data ); +} + +static Dict *CreateStyleGroup( void ) +{ + Dict *dict; + DictType *dtype = NEW( DictType, 1 ); + *dtype = DictType_StringCopyKey; + dtype->valDestructor = OnDeleteStyleLinkGroup; + dict = Dict_Create( dtype, dtype ); + return dict; +} + +static void DeleteStyleGroup( Dict *dict ) +{ + Dict_Release( dict ); + free( dict->privdata ); + dict->privdata = NULL; +} + +/** 根据选择器,选中匹配的样式表 */ +static LCUI_StyleSheet LCUI_SelectStyleSheet( LCUI_Selector selector, + const char *space ) +{ + int i, right; + StyleLink link; + StyleNode snode; + StyleLinkGroup slg; + LinkedListNode *node; + LCUI_SelectorNode sn; + Dict *group, *parents; + char buf[MAX_SELECTOR_LEN]; + char fullname[MAX_SELECTOR_LEN]; + + link = NULL; + parents = NULL; + for( i = 0, right = selector->length - 1; right >= 0; --right, ++i ) { + group = LinkedList_Get( &library.groups, i ); + if( !group ) { + group = CreateStyleGroup(); + LinkedList_Append( &library.groups, group ); + } + sn = selector->nodes[right]; + slg = Dict_FetchValue( group, sn->fullname ); + if( !slg ) { + slg = CreateStyleLinkGroup( sn ); + Dict_Add( group, sn->fullname, slg ); + } + if( i == 0 ) { + strcpy( fullname, "*" ); + } else { + strcpy( fullname, buf ); + } + link = Dict_FetchValue( slg->links, fullname ); + if( !link ) { + link = CreateStyleLink(); + link->group = slg; + link->selector = strdup( fullname ); + Dict_Add( slg->links, fullname, link ); + } + if( i == 0 ) { + strcpy( buf, sn->fullname ); + } else { + strcpy( fullname, buf ); + sprintf( buf, "%s %s", sn->fullname, fullname ); + } + /* 如果有上一级的父链接记录,则将当前链接添加进去 */ + if( parents ) { + if( !Dict_FetchValue( parents, sn->fullname ) ) { + Dict_Add( parents, sn->fullname, link ); + } + } + parents = link->parents; + } + if( !link ) { + return NULL; + } + for( LinkedList_Each( node, &link->styles ) ) { + snode = node->data; + if( snode->space && space ) { + if( strcmp( snode->space, space ) == 0 ) { + return snode->sheet; + } + } else { + if( snode->space == space ) { + return snode->sheet; + } + } + } + snode = NEW( StyleNodeRec, 1 ); + if( space ) { + snode->space = NEW( char, strlen(space) + 1 ); + strcpy( snode->space, space ); + } else { + snode->space = NULL; + } + snode->sheet = StyleSheet(); + snode->rank = selector->rank; + snode->selector = strdup( fullname ); + snode->batch_num = selector->batch_num; + LinkedList_Append( &link->styles, snode ); + return snode->sheet; +} + +int LCUI_PutStyleSheet( LCUI_Selector selector, + LCUI_StyleSheet in_ss, const char *space ) +{ + LCUI_StyleSheet ss; + LCUIMutex_Lock( &library.mutex ); + Dict_Empty( library.cache ); + ss = LCUI_SelectStyleSheet( selector, space ); + if( ss ) { + StyleSheet_Replace( ss, in_ss ); + } + LCUIMutex_Unlock( &library.mutex ); + return 0; +} + +static int StyleLink_GetStyleSheets( StyleLink link, LinkedList *outlist ) +{ + StyleNode snode, out_snode; + LinkedListNode *node, *out_node; + + if( !outlist ) { + return link->styles.length; + } + for( LinkedList_Each( node, &link->styles ) ) { + int pos = -1, i = 0; + snode = node->data; + for( LinkedList_Each( out_node, outlist ) ) { + out_snode = out_node->data; + if( snode->rank > out_snode->rank ) { + pos = i; + break; + } + if( snode->rank != out_snode->rank ) { + i += 1; + continue; + } + if( snode->batch_num > out_snode->batch_num ) { + pos = i; + break; + } + i += 1; + } + if( pos >= 0 ) { + LinkedList_Insert( outlist, pos, snode ); + } else { + LinkedList_Append( outlist, snode ); + } + } + return link->styles.length; +} + +static int LCUI_FindStyleSheetFromLink( StyleLink link, LCUI_Selector s, + int i, LinkedList *list ) +{ + int name_count = 0; + StyleLink parent; + LinkedList names; + LinkedListNode *node; + LCUI_SelectorNode sn; + + LinkedList_Init( &names ); + name_count += StyleLink_GetStyleSheets( link, list ); + while( --i >= 0 ) { + sn = s->nodes[i]; + SelectorNode_GetNames( sn, &names ); + for( LinkedList_Each( node, &names ) ) { + parent = Dict_FetchValue( link->parents, node->data ); + if( !parent ) { + continue; + } + name_count += LCUI_FindStyleSheetFromLink( parent, s, + i, list ); + } + LinkedList_Clear( &names, free ); + } + return name_count; +} + +int LCUI_FindStyleSheetFromGroup( int group, const char *name, + LCUI_Selector s, LinkedList *list ) +{ + int i, name_count; + Dict *groups; + StyleLinkGroup slg; + LinkedListNode *node; + LinkedList names; + + groups = LinkedList_Get( &library.groups, group ); + if( !groups || s->length < 1 ) { + return 0; + } + name_count = 0; + i = s->length - 1; + LinkedList_Init( &names ); + if( name ) { + LinkedList_Append( &names, strdup( name ) ); + } else { + SelectorNode_GetNames( s->nodes[i], &names ); + LinkedList_Append( &names, strdup( "*" ) ); + } + for( LinkedList_Each( node, &names ) ) { + DictEntry *entry; + DictIterator *iter; + char *name = node->data; + slg = Dict_FetchValue( groups, name ); + if( !slg ) { + continue; + } + iter = Dict_GetIterator( slg->links ); + while( (entry = Dict_Next( iter )) ) { + StyleLink link = DictEntry_GetVal( entry ); + name_count += LCUI_FindStyleSheetFromLink( link, s, + i, list ); + } + } + LinkedList_Clear( &names, free ); + return name_count; +} + +void LCUI_PrintStyleSheet( LCUI_StyleSheet ss ) +{ + int key; + const char *name; + for( key = 0; key < ss->length; ++key ) { + LCUI_Style s = &ss->sheet[key]; + if( !s->is_valid ) { + continue; + } + name = LCUI_GetStyleName( key ); + if( name ) { + printf( "\t%s", name ); + } else { + printf( "\t", key ); + } + printf( "%s: ", key > STYLE_KEY_TOTAL ? " (+)" : "" ); + switch( s->type ) { + case SVT_AUTO: + printf( "auto" ); + break; + case SVT_BOOL: + printf( "%s", s->val_bool ? "true" : "false" ); + break; + case SVT_COLOR: { + LCUI_Color *clr = &s->val_color; + if( clr->alpha < 255 ) { + printf( "rgba(%d,%d,%d,%0.2f)", clr->r, + clr->g, clr->b, clr->a / 255.0 ); + } else { + printf( "#%02x%02x%02x", clr->r, clr->g, clr->b ); + } + break; + } + case SVT_PX: + printf( "%dpx", s->val_px ); + break; + case SVT_STRING: + printf( "%s", s->val_string ); + break; + case SVT_SCALE: + printf( "%.2lf%%", s->val_scale * 100 ); + break; + case SVT_STYLE: + printf( "%s", LCUI_GetStyleValueName( s->val_style ) ); + break; + default: + printf( "%d", s->value ); + break; + } + printf( ";\n" ); + } +} + +void LCUI_PrintSelector( LCUI_Selector selector ) +{ + char path[MAX_SELECTOR_LEN]; + LCUI_SelectorNode *sn; + + path[0] = 0; + for( sn = selector->nodes; *sn; ++sn ) { + strcat( path, (*sn)->fullname ); + strcat( path, " " ); + } + printf("path: %s (rank = %d, batch_num = %d)\n", path, + selector->rank, selector->batch_num); +} + +static void LCUI_PrintStyleLink( StyleLink link, const char *selector ) +{ + DictEntry *entry; + DictIterator *iter; + LinkedListNode *node; + char fullname[MAX_SELECTOR_LEN]; + if( selector ) { + sprintf( fullname, "%s %s", link->group->name, selector ); + } else { + strcpy( fullname, link->group->name ); + } + for( LinkedList_Each( node, &link->styles ) ) { + StyleNode snode = node->data; + printf("\n[%s]\n", snode->space ? snode->space:""); + printf("%s {\n", fullname); + LCUI_PrintStyleSheet( snode->sheet ); + printf("}\n"); + } + iter = Dict_GetIterator( link->parents ); + while( (entry = Dict_Next( iter )) ) { + StyleLink parent = DictEntry_GetVal( entry ); + LCUI_PrintStyleLink( parent, fullname ); + } + Dict_ReleaseIterator( iter ); +} + +void LCUI_PrintCSSLibrary( void ) +{ + Dict *group; + StyleLink link; + StyleLinkGroup slg; + DictIterator *iter; + DictEntry *entry; + + link = NULL; + printf( "style library begin\n" ); + group = LinkedList_Get( &library.groups, 0 ); + iter = Dict_GetIterator( group ); + while( (entry = Dict_Next(iter)) ) { + DictEntry *entry_slg; + DictIterator *iter_slg; + slg = DictEntry_GetVal( entry ); + iter_slg = Dict_GetIterator( slg->links ); + while( (entry_slg = Dict_Next(iter_slg)) ) { + link = DictEntry_GetVal( entry_slg ); + LCUI_PrintStyleLink( link, NULL ); + } + Dict_ReleaseIterator( iter_slg ); + } + Dict_ReleaseIterator( iter ); + printf( "style library end\n" ); +} + +void LCUI_GetStyleSheet( LCUI_Selector s, LCUI_StyleSheet out_ss ) +{ + LinkedList list; + LinkedListNode *node; + LCUI_StyleSheet ss; + LinkedList_Init( &list ); + StyleSheet_Clear( out_ss ); + LCUIMutex_Lock( &library.mutex ); + ss = Dict_FetchValue( library.cache, (void*)s->hash ); + if( ss ) { + StyleSheet_Replace( out_ss, ss ); + LCUIMutex_Unlock( &library.mutex ); + return; + } + ss = StyleSheet(); + LCUI_FindStyleSheet( s, &list ); + for( LinkedList_Each( node, &list ) ) { + StyleNode sn = node->data; + StyleSheet_Merge( ss, sn->sheet ); + } + LinkedList_Clear( &list, NULL ); + Dict_Add( library.cache, (void*)s->hash, ss ); + StyleSheet_Replace( out_ss, ss ); + LCUIMutex_Unlock( &library.mutex ); +} + +static void DestroyStyleSheetCache( void *privdata, void *val ) +{ + StyleSheet_Delete( val ); +} + +void LCUI_InitCSSLibrary( void ) +{ + KeyNameGroup skn, skn_end; + library.cachedict = DictType_IdentityKey; + library.cachedict.valDestructor = DestroyStyleSheetCache; + library.cache = Dict_Create( &library.cachedict, NULL ); + library.names = Dict_Create( &DictType_IdentityKey, NULL ); + library.value_keys = Dict_Create( &DictType_StringKey, NULL ); + library.value_names = Dict_Create( &DictType_IdentityKey, NULL ); + LinkedList_Init( &library.groups ); + LCUIMutex_Init( &library.mutex ); + skn_end = style_name_map + LEN( style_name_map ); + for( skn = style_name_map; skn < skn_end; ++skn ) { + LCUI_DirectAddStyleName( skn->key, skn->name ); + } + skn_end = style_value_map + LEN( style_value_map ); + for( skn = style_value_map; skn < skn_end; ++skn ) { + LCUI_AddStyleValue( skn->key, skn->name ); + } + library.count = STYLE_KEY_TOTAL; + library.is_inited = TRUE; +} + +void LCUI_ExitCSSLibrary( void ) +{ + library.is_inited = FALSE; + Dict_Release( library.names ); + Dict_Release( library.cache ); + Dict_Release( library.value_keys ); + Dict_Release( library.value_names ); + LCUIMutex_Destroy( &library.mutex ); + LinkedList_Clear( &library.groups, (FuncPtr)DeleteStyleGroup ); +} diff --git a/src/gui/css_parser.c b/src/gui/css_parser.c index 8127c19f..5f0ec6ac 100644 --- a/src/gui/css_parser.c +++ b/src/gui/css_parser.c @@ -36,13 +36,21 @@ * 您应已收到附随于本文件的GPLv2许可协议的副本,它通常在LICENSE.TXT文件中,如果 * 没有,请查看:. * ****************************************************************************/ -//#define DEBUG + #include #include #include #include #include -#include +#include +#include +#include + +#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 ); } diff --git a/src/gui/widget/button.c b/src/gui/widget/button.c index ae051555..e86d83d9 100755 --- a/src/gui/widget/button.c +++ b/src/gui/widget/button.c @@ -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 ); } diff --git a/src/gui/widget/scrollbar.c b/src/gui/widget/scrollbar.c index 3a03e4be..f08a12ca 100644 --- a/src/gui/widget/scrollbar.c +++ b/src/gui/widget/scrollbar.c @@ -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 ); } diff --git a/src/gui/widget/sidebar.c b/src/gui/widget/sidebar.c index 21064cf1..159fcc46 100644 --- a/src/gui/widget/sidebar.c +++ b/src/gui/widget/sidebar.c @@ -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 ); } diff --git a/src/gui/widget/textedit.c b/src/gui/widget/textedit.c index f9f27b3e..f0a305e6 100644 --- a/src/gui/widget/textedit.c +++ b/src/gui/widget/textedit.c @@ -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" ); diff --git a/src/gui/widget/textview.c b/src/gui/widget/textview.c index 1ca55e44..26415dec 100644 --- a/src/gui/widget/textview.c +++ b/src/gui/widget/textview.c @@ -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] ); } } diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index bcfeb30d..8f9a563b 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -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; diff --git a/src/gui/widget_style.c b/src/gui/widget_style.c index 64cb0cac..49f37687 100644 --- a/src/gui/widget_style.c +++ b/src/gui/widget_style.c @@ -44,73 +44,7 @@ #include #include #include - -#define MAX_NAME_LEN 256 -#define MAX_SELECTOR_LEN 1024 -#define MAX_NODE_DEPTH 32 -#define MAX_SELECTOR_DEPTH 32 - -#define FindStyleSheet(S, L) FindStyleSheetFromGroup(0, NULL, S, L) - -enum SelectorRank { - GENERAL_RANK = 0, - TYPE_RANK = 1, - CLASS_RANK = 10, - PCLASS_RANK = 10, - ID_RANK = 100 -}; - -enum SelectorFinderLevel { - LEVEL_NONE, - LEVEL_TYPE, - LEVEL_ID, - LEVEL_CLASS, - LEVEL_CLASS_2, - LEVEL_STATUS, - LEVEL_STATUS_2, - LEVEL_TOTAL_NUM -}; - -/* 样式表查找器的上下文数据结构 */ -typedef struct NamesFinderRec_ { - int level; /**< 当前选择器层级 */ - int class_i; /**< 当前处理到第几个类名 */ - int status_i; /**< 当前处理到第几个状态名(伪类名) */ - int name_i; /**< 选择器名称从第几个字符开始 */ - char name[MAX_NAME_LEN]; /**< 选择器名称缓存 */ - LCUI_SelectorNode node; /**< 针对的选择器结点 */ -} NamesFinderRec, *NamesFinder; - -/** 样式链接记录组 */ -typedef struct StyleLinkGroupRec_ { - Dict *links; /**< 样式链接表 */ - char *name; /**< 选择器名称 */ - LCUI_SelectorNodeRec snode; /**< 选择器结点 */ -} StyleLinkGroupRec, *StyleLinkGroup; - -/** 样式结点记录 */ -typedef struct StyleNodeRec_ { - int rank; /**< 权值,决定优先级 */ - int batch_num; /**< 批次号 */ - char *space; /**< 所属的空间 */ - char *selector; /**< 选择器 */ - LCUI_StyleSheet sheet; /**< 样式表 */ -} StyleNodeRec, *StyleNode; - -/** 样式链接记录 */ -typedef struct StyleLinkRec_ { - char *selector; /**< 选择器 */ - StyleLinkGroup group; /**< 所属组 */ - LinkedList styles; /**< 作用于当前选择器的样式 */ - Dict *parents; /**< 父级节点 */ -} StyleLinkRec, *StyleLink; - -static struct { - LCUI_BOOL is_inited; - LCUI_Mutex mutex; /**< 互斥锁 */ - LinkedList groups; /**< 样式组列表 */ - LCUI_RBTree cache; /**< 样式表缓存,以选择器的 hash 值索引 */ -} style_library; +#include const char *global_css = ToString( @@ -126,1121 +60,6 @@ const char *global_css = ToString( ); -static int SortedStrList_Add( 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; -} - -static void SortedStrList_Destroy( char **strlist ) -{ - int i; - for( i = 0; strlist[i]; ++i ) { - free( strlist[i] ); - strlist[i] = NULL; - } - free( strlist ); -} - -/** - * 匹配选择器节点 - * 左边的选择器必须包含右边的选择器的所有属性。 - */ -LCUI_BOOL SelectorNode_Match( LCUI_SelectorNode sn1, - LCUI_SelectorNode sn2 ) -{ - int i, j; - if( sn2->id ) { - if( !sn1->id || strcmp( sn1->id, sn2->id ) != 0 ) { - return FALSE; - } - } - if( sn2->type && strcmp(sn2->type, "*") != 0 ) { - if( !sn1->type || strcmp( sn1->type, sn2->type ) != 0 ) { - return FALSE; - } - } - if( sn2->classes ) { - if( !sn1->classes ) { - return FALSE; - } - for( i = 0; sn2->classes[i]; ++i ) { - for( j = 0; sn1->classes[j]; ++j ) { - if( strcmp( sn2->classes[i], - sn1->classes[i] ) == 0 ) { - j = -1; - break; - } - } - if( j != -1 ) { - return FALSE; - } - } - } - if( sn2->status ) { - if( !sn1->status ) { - return FALSE; - } - for( i = 0; sn2->status[i]; ++i ) { - for( j = 0; sn1->status[j]; ++j ) { - if( strcmp( sn2->status[i], - sn1->status[i] ) == 0 ) { - j = -1; - break; - } - } - if( j != -1 ) { - return FALSE; - } - } - } - return TRUE; -} - -static void SelectorNode_Copy( LCUI_SelectorNode dst, LCUI_SelectorNode src ) -{ - int i; - dst->id = src->id ? strdup( src->id ) : NULL; - dst->type = src->type ? strdup( src->type ) : NULL; - dst->fullname = src->fullname ? strdup( src->fullname ) : NULL; - if( src->classes ) { - for( i = 0; src->classes[i]; ++i ) { - SortedStrList_Add( &dst->classes, src->classes[i] ); - } - } - if( src->status ) { - for( i = 0; src->status[i]; ++i ) { - SortedStrList_Add( &dst->status, src->status[i] ); - } - } -} - -static void SelectorNode_Delete( LCUI_SelectorNode node ) -{ - if( node->type ) { - free( node->type ); - node->type = NULL; - } - if( node->id ) { - free( node->id ); - node->id = NULL; - } - if( node->classes ) { - SortedStrList_Destroy( node->classes ); - node->classes = NULL; - } - if( node->status ) { - SortedStrList_Destroy( node->status ); - node->status = NULL; - } - if( node->fullname ) { - free( node->fullname ); - node->fullname = NULL; - } - free( node ); -} - -void Selector_Delete( LCUI_Selector s ) -{ - int i; - for( i = 0; i < MAX_SELECTOR_DEPTH; ++i ) { - if( !s->nodes[i] ) { - break; - } - SelectorNode_Delete( s->nodes[i] ); - s->nodes[i] = NULL; - } - s->rank = 0; - s->length = 0; - s->batch_num = 0; - free( s->nodes ); - free( s ); -} - -LCUI_StyleSheet StyleSheet( void ) -{ - LCUI_StyleSheet ss; - ss = NEW( LCUI_StyleSheetRec, 1 ); - if( !ss ) { - return ss; - } - ss->length = LCUICSS_GetStyleTotal(); - ss->sheet = NEW( LCUI_StyleRec, ss->length + 1 ); - return ss; -} - -void StyleSheet_Clear( LCUI_StyleSheet ss ) -{ - int i; - LCUI_Style s; - for( i=0; ilength; ++i ) { - s = &ss->sheet[i]; - switch( s->type ) { - case SVT_STRING: - case SVT_WSTRING: - if( s->is_valid && s->string ) { - free( s->string ); - } - s->string = NULL; - default: break; - } - s->is_valid = FALSE; - s->is_changed = TRUE; - } -} - -void StyleSheet_Delete( LCUI_StyleSheet ss ) -{ - StyleSheet_Clear( ss ); - free( ss->sheet ); - free( ss ); -} - -int StyleSheet_Merge( LCUI_StyleSheet dest, LCUI_StyleSheet src ) -{ - LCUI_Style s; - int i, count, size; - if( src->length > dest->length ) { - size = sizeof(LCUI_StyleRec)*src->length; - s = realloc( dest->sheet, size ); - if( !s ) { - return -1; - } - for( i=dest->length; ilength; ++i ) { - s[i].is_valid = FALSE; - } - dest->sheet = s; - dest->length = src->length; - } - for( count=0,i=0; ilength; ++i ) { - s = &dest->sheet[i]; - if( !src->sheet[i].is_valid || s->is_valid ) { - continue; - } - ++count; - switch( src->sheet[i].type ) { - case SVT_STRING: - s->string = strdup( src->sheet[i].string ); - break; - case SVT_WSTRING: - size = wcslen( src->sheet[i].wstring ) + 1; - s->wstring = malloc( size * sizeof(wchar_t) ); - wcscpy( s->wstring, src->sheet[i].wstring ); - break; - default: - *s = src->sheet[i]; - break; - } - s->is_valid = TRUE; - s->is_changed = TRUE; - s->type = src->sheet[i].type; - } - return 0; -} - -int StyleSheet_Replace( LCUI_StyleSheet dest, LCUI_StyleSheet src ) -{ - LCUI_Style s; - int i, count, size; - if( src->length > dest->length ) { - size = sizeof(LCUI_StyleRec)*src->length; - s = realloc( dest->sheet, size ); - if( !s ) { - return -1; - } - for( i=dest->length; ilength; ++i ) { - s[i].is_valid = FALSE; - } - dest->sheet = s; - dest->length = src->length; - } - for( count=0,i=0; ilength; ++i ) { - if( !src->sheet[i].is_valid ) { - continue; - } - s = &dest->sheet[i]; - switch( src->sheet[i].type ) { - case SVT_STRING: - if( s->is_valid && s->string ) { - free( s->string ); - } - s->string = strdup( src->sheet[i].string ); - break; - case SVT_WSTRING: - if( s->is_valid && s->string ) { - free( s->wstring ); - } - size = wcslen( src->sheet[i].wstring ) + 1; - s->wstring = malloc( size * sizeof(wchar_t) ); - wcscpy( s->wstring, src->sheet[i].wstring ); - break; - default: - *s = src->sheet[i]; - break; - } - s->is_valid = TRUE; - s->is_changed = TRUE; - s->type = src->sheet[i].type; - ++count; - } - return count; -} - -/** 初始化样式表查找器 */ -static void NamesFinder_Init( NamesFinder sfinder, LCUI_SelectorNode snode ) -{ - sfinder->level = 0; - sfinder->class_i = 0; - sfinder->name_i = 0; - sfinder->status_i = 0; - sfinder->name[0] = 0; - sfinder->node = snode; -} - -/** 销毁样式表查找器 */ -static void NamesFinder_Destroy( NamesFinder sfinder ) -{ - sfinder->name_i = 0; - sfinder->name[0] = 0; - sfinder->class_i = 0; - sfinder->status_i = 0; - sfinder->node = NULL; - sfinder->level = LEVEL_NONE; -} - -/* 查找匹配的样式表 */ -static int NamesFinder_Find( NamesFinder sfinder, LinkedList *list ) -{ - int i, len, old_len, old_level, count = 0; - char *fullname = sfinder->name + sfinder->name_i; - old_len = len = strlen( fullname ); - old_level = sfinder->level; - switch( sfinder->level ) { - case LEVEL_TYPE: - /* 按类型选择器搜索样式表 */ - if( !sfinder->node->type ) { - return 0; - } - strcpy( fullname, sfinder->node->type ); - LinkedList_Append( list, strdup( fullname ) ); - break; - case LEVEL_ID: - /* 按ID选择器搜索样式表 */ - if( !sfinder->node->id ) { - return 0; - } - fullname[len++] = '#'; - fullname[len] = 0; - strcpy( fullname + len, sfinder->node->id ); - LinkedList_Append( list, strdup( fullname ) ); - break; - case LEVEL_CLASS: - if( !sfinder->node->classes ) { - return 0; - } - /* 按类选择器搜索样式表 - * 假设当前选择器全名为:textview#main-btn-text,且有 .a .b .c - * 这三个类,那么下面的处理将会拆分成以下三个选择器来匹配样式表: - * textview#test-text.a - * textview#test-text.b - * textview#test-text.a - */ - fullname[len++] = '.'; - for( i = 0; sfinder->node->classes[i]; ++i ) { - sfinder->level += 1; - strcpy( fullname + len, sfinder->node->classes[i] ); - LinkedList_Append( list, strdup( fullname ) ); - /* 将当前选择器名与其它层级的选择器名组合 */ - while( sfinder->level < LEVEL_TOTAL_NUM ) { - count += NamesFinder_Find( sfinder, list ); - sfinder->level += 1; - } - sfinder->level = LEVEL_CLASS; - sfinder->class_i += 1; - } - sfinder->level = LEVEL_CLASS; - fullname[old_len] = 0; - sfinder->class_i = 0; - return count; - case LEVEL_CLASS_2: - if( !sfinder->node->classes ) { - return 0; - } - /* 按类选择器搜索交集样式表,结果类似于这样: - * textview#test-text.a.b - * textview#test-text.a.c - * textview#test-text.b.c - * textview#test-text.a.b.c - */ - fullname[len++] = '.'; - for( i = 0; sfinder->node->classes[i]; ++i ) { - if( i <= sfinder->class_i ) { - continue; - } - strcpy( fullname + len, sfinder->node->classes[i] ); - LinkedList_Append( list, strdup( fullname ) ); - sfinder->class_i += 1; - count += NamesFinder_Find( sfinder, list ); - sfinder->class_i -= 1; - sfinder->level = LEVEL_STATUS; - /** - * 递归拼接伪类名,例如: - * textview#main-btn-text:active - */ - count += NamesFinder_Find( sfinder, list ); - sfinder->level = LEVEL_CLASS_2; - } - fullname[old_len] = 0; - sfinder->level = LEVEL_CLASS_2; - return count; - case LEVEL_STATUS: - if( !sfinder->node->status ) { - return 0; - } - fullname[len++] = ':'; - sfinder->level = LEVEL_STATUS_2; - /** - * 按伪类选择器搜索样式表 - * 假设当前选择器全名为:textview#main-btn-text:hover:focus:active - * 那么下面的循环会将它拆分为以下几个选择器来匹配样式: - * textview#main-btn-text:active - * textview#main-btn-text:active:focus - * textview#main-btn-text:active:focus:hover - * textview#main-btn-text:active:hover - * textview#main-btn-text:focus - * textview#main-btn-text:focus:hover - * textview#main-btn-text:hover - */ - for( i = 0; sfinder->node->status[i]; ++i ) { - strcpy( fullname + len, sfinder->node->status[i] ); - LinkedList_Append( list, strdup( fullname ) ); - /** - * 递归调用,以一层层拼接出像下面这样的选择器: - * textview#main-btn-text:active:focus:hover - */ - count += NamesFinder_Find( sfinder, list ); - sfinder->status_i += 1; - } - sfinder->level = LEVEL_STATUS; - fullname[old_len] = 0; - sfinder->status_i = 0; - return count; - case LEVEL_STATUS_2: - if( !sfinder->node->status ) { - return 0; - } - /** 按伪类选择器搜索交集样式表 */ - for( i = 0; sfinder->node->status[i]; ++i ) { - if( i <= sfinder->status_i ) { - continue; - } - fullname[len] = ':'; - strcpy( fullname + len + 1, sfinder->node->status[i] ); - LinkedList_Append( list, strdup( fullname ) ); - sfinder->status_i += 1; - count += NamesFinder_Find( sfinder, list ); - sfinder->status_i -= 1; - } - fullname[old_len] = 0; - return count; - default:break; - } - for( i = sfinder->level + 1; i < LEVEL_TOTAL_NUM; ++i ) { - if( i == LEVEL_STATUS_2 || i == LEVEL_CLASS_2 ) { - continue; - } - sfinder->level = i; - count += NamesFinder_Find( sfinder, list ); - } - fullname[old_len] = 0; - sfinder->level = old_level; - return count; -} - -static int SelectorNode_Save( LCUI_SelectorNode node, - const char *name, int len, char type ) -{ - char *str; - if( len < 1 ) { - return 0; - } - switch( type ) { - case 0: - if( node->type ) { - break; - } - len += 1; - str = malloc( sizeof( char ) * len ); - strncpy( str, name, len ); - node->type = str; - return TYPE_RANK; - case ':': - if( SortedStrList_Add( &node->status, name ) == 0 ) { - return PCLASS_RANK; - } - break; - case '.': - if( SortedStrList_Add( &node->classes, name ) == 0 ) { - return CLASS_RANK; - } - break; - case '#': - if( node->id ) { - break; - } - len += 1; - str = malloc( sizeof( char ) * len ); - strncpy( str, name, len ); - node->id = str; - return ID_RANK; - default: break; - } - return 0; -} - -static int SelectorNode_GetNames( LCUI_SelectorNode sn, LinkedList *names ) -{ - int count; - NamesFinderRec sfinder; - NamesFinder_Init( &sfinder, sn ); - count = NamesFinder_Find( &sfinder, names ); - NamesFinder_Destroy( &sfinder ); - return count; -} - -static int SelectorNode_Update( LCUI_SelectorNode node ) -{ - int i, len = 0; - char *fullname; - - node->rank = 0; - if( node->id ) { - len += strlen( node->id ) + 1; - node->rank += ID_RANK; - } - if( node->type ) { - len += strlen( node->type ) + 1; - node->rank += TYPE_RANK; - } - if( node->classes ) { - for( i = 0; node->classes[i]; ++i ) { - len += strlen( node->classes[i] ) + 1; - node->rank += CLASS_RANK; - } - } - if( node->status ) { - for( i = 0; node->status[i]; ++i ) { - len += strlen( node->status[i] ) + 1; - node->rank += PCLASS_RANK; - } - } - if( len > 0 ) { - fullname = malloc( sizeof( char ) * (len + 1) ); - if( !fullname ) { - return -ENOMEM; - } - fullname[0] = 0; - if( node->type ) { - strcat( fullname, node->type ); - } - if( node->id ) { - strcat( fullname, "#" ); - strcat( fullname, node->id ); - } - if( node->classes ) { - for( i = 0; node->classes[i]; ++i ) { - strcat( fullname, "." ); - strcat( fullname, node->classes[i] ); - } - len += 1; - } - if( node->status ) { - for( i = 0; node->status[i]; ++i ) { - strcat( fullname, ":" ); - strcat( fullname, node->status[i] ); - } - len += 1; - } - } else { - fullname = NULL; - } - if( node->fullname ) { - free( node->fullname ); - } - node->fullname = fullname; - return len; -} - -void Selector_Update( LCUI_Selector s ) -{ - int i; - const unsigned char *p; - unsigned int hash = 5381; - for( i = 0; i < s->length; ++i ) { - p = (unsigned char*)s->nodes[i]->fullname; - while( *p ) { - hash = ((hash << 5) + hash) + (*p++); - } - } - s->hash = hash; -} - -LCUI_Selector Selector( const char *selector ) -{ - const char *p; - int ni, si, rank; - static int batch_num = 0; - char type = 0, name[MAX_NAME_LEN]; - LCUI_BOOL is_saving = FALSE; - LCUI_SelectorNode node = NULL; - LCUI_Selector s = NEW( LCUI_SelectorRec, 1 ); - - s->batch_num = ++batch_num; - s->nodes = NEW( LCUI_SelectorNode, MAX_SELECTOR_DEPTH ); - if( !selector ) { - s->length = 0; - s->nodes[0] = NULL; - return s; - } - for( ni = 0, si = 0, p = selector; *p; ++p ) { - if( !node && is_saving ) { - node = NEW( LCUI_SelectorNodeRec, 1 ); - if( si >= MAX_SELECTOR_DEPTH ) { - _DEBUG_MSG( "%s: selector node list is too long.\n", - selector ); - return NULL; - } - s->nodes[si] = node; - } - switch( *p ) { - case ':': - case '.': - case '#': - if( !is_saving ) { - is_saving = TRUE; - type = *p; - continue; - } - /* 保存上个结点 */ - rank = SelectorNode_Save( node, name, ni, type ); - if( rank > 0 ) { - s->rank += rank; - } else { - _DEBUG_MSG( "%s: invalid selector node at %ld.\n", - selector, p - selector - ni ); - SelectorNode_Delete( node ); - node = NULL; - } - ni = 0; - is_saving = TRUE; - type = *p; - continue; - case ' ': - case '\r': - case '\n': - case '\t': - if( !is_saving ) { - ni = 0; - node = NULL; - continue; - } - is_saving = FALSE; - rank = SelectorNode_Save( node, name, ni, type ); - if( rank > 0 ) { - SelectorNode_Update( node ); - s->rank += rank; - node = NULL; - ni = 0; - si++; - continue; - } - _DEBUG_MSG( "%s: invalid selector node at %ld.\n", - selector, p - selector - ni ); - SelectorNode_Delete( node ); - node = NULL; - ni = 0; - continue; - default: break; - } - if( *p == '-' || *p == '_' || *p == '*' - || (*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') - || (*p >= '0' && *p <= '9') ) { - if( !is_saving ) { - type = 0; - is_saving = TRUE; - } - name[ni++] = *p; - name[ni] = 0; - continue; - } - _DEBUG_MSG( "%s: unknown char 0x%02x at %ld.\n", - selector, *p, p - selector ); - return NULL; - } - if( is_saving ) { - rank = SelectorNode_Save( s->nodes[si], name, ni, type ); - if( rank > 0 ) { - SelectorNode_Update( s->nodes[si] ); - s->rank += rank; - si++; - } else { - SelectorNode_Delete( s->nodes[si] ); - } - } - s->nodes[si] = NULL; - s->length = si; - Selector_Update( s ); - return s; -} - -static void DeleteStyleNode( StyleNode node ) -{ - if( node->space ) { - free( node->space ); - node->space = NULL; - } - if( node->selector ) { - free( node->selector ); - node->selector = NULL; - } - StyleSheet_Delete( node->sheet ); - node->sheet = NULL; -} - -static StyleLink CreateStyleLink( void ) -{ - StyleLink link = NEW( StyleLinkRec, 1 ); - link->group = NULL; - LinkedList_Init( &link->styles ); - link->parents = Dict_Create( &DictType_StringCopyKey, NULL ); - return link; -} - -static void DeleteStyleLink( StyleLink link ) -{ - link->group = NULL; - Dict_Release( link->parents ); - link->parents = NULL; - LinkedList_Clear( &link->styles, (FuncPtr)DeleteStyleNode ); -} - -static void OnDeleteStyleLink( void *privdata, void *data ) -{ - DeleteStyleLink( data ); -} - -static StyleLinkGroup CreateStyleLinkGroup( LCUI_SelectorNode snode ) -{ - DictType *dtype = NEW( DictType, 1 ); - StyleLinkGroup group = NEW( StyleLinkGroupRec, 1 ); - SelectorNode_Copy( &group->snode, snode ); - group->name = group->snode.fullname; - *dtype = DictType_StringCopyKey; - dtype->valDestructor = OnDeleteStyleLink; - group->links = Dict_Create( dtype, dtype ); - return group; -} - -static void DeleteStyleLinkGroup( StyleLinkGroup group ) -{ - free( group->name ); - Dict_Release( group->links ); - free( group->links->privdata ); - group->name = NULL; - group->links = NULL; -} - -static void OnDeleteStyleLinkGroup( void *privdata, void *data ) -{ - DeleteStyleLinkGroup( data ); -} - -static Dict *CreateStyleGroup( void ) -{ - Dict *dict; - DictType *dtype = NEW( DictType, 1 ); - *dtype = DictType_StringCopyKey; - dtype->valDestructor = OnDeleteStyleLinkGroup; - dict = Dict_Create( dtype, dtype ); - return dict; -} - -static void DeleteStyleGroup( Dict *dict ) -{ - Dict_Release( dict ); - free( dict->privdata ); - dict->privdata = NULL; -} - -/** 根据选择器,选中匹配的样式表 */ -static LCUI_StyleSheet SelectStyleSheet( LCUI_Selector selector, - const char *space ) -{ - int i, right; - StyleLink link; - StyleNode snode; - StyleLinkGroup slg; - LinkedListNode *node; - LCUI_SelectorNode sn; - Dict *group, *parents; - char buf[MAX_SELECTOR_LEN]; - char fullname[MAX_SELECTOR_LEN]; - - link = NULL; - parents = NULL; - for( i = 0, right = selector->length - 1; right >= 0; --right, ++i ) { - group = LinkedList_Get( &style_library.groups, i ); - if( !group ) { - group = CreateStyleGroup(); - LinkedList_Append( &style_library.groups, group ); - } - sn = selector->nodes[right]; - slg = Dict_FetchValue( group, sn->fullname ); - if( !slg ) { - slg = CreateStyleLinkGroup( sn ); - Dict_Add( group, sn->fullname, slg ); - } - if( i == 0 ) { - strcpy( fullname, "*" ); - } else { - strcpy( fullname, buf ); - } - link = Dict_FetchValue( slg->links, fullname ); - if( !link ) { - link = CreateStyleLink(); - link->group = slg; - link->selector = strdup( fullname ); - Dict_Add( slg->links, fullname, link ); - } - if( i == 0 ) { - strcpy( buf, sn->fullname ); - } else { - strcpy( fullname, buf ); - sprintf( buf, "%s %s", sn->fullname, fullname ); - } - /* 如果有上一级的父链接记录,则将当前链接添加进去 */ - if( parents ) { - if( !Dict_FetchValue( parents, sn->fullname ) ) { - Dict_Add( parents, sn->fullname, link ); - } - } - parents = link->parents; - } - if( !link ) { - return NULL; - } - for( LinkedList_Each( node, &link->styles ) ) { - snode = node->data; - if( snode->space && space ) { - if( strcmp( snode->space, space ) == 0 ) { - return snode->sheet; - } - } else { - if( snode->space == space ) { - return snode->sheet; - } - } - } - snode = NEW( StyleNodeRec, 1 ); - if( space ) { - snode->space = NEW( char, strlen(space) + 1 ); - strcpy( snode->space, space ); - } else { - snode->space = NULL; - } - snode->sheet = StyleSheet(); - snode->rank = selector->rank; - snode->selector = strdup( fullname ); - snode->batch_num = selector->batch_num; - LinkedList_Append( &link->styles, snode ); - return snode->sheet; -} - -int LCUI_PutStyle( LCUI_Selector selector, - LCUI_StyleSheet in_ss, const char *space ) -{ - LCUI_StyleSheet ss; - LCUIMutex_Lock( &style_library.mutex ); - RBTree_Destroy( &style_library.cache ); - ss = SelectStyleSheet( selector, space ); - if( ss ) { - StyleSheet_Replace( ss, in_ss ); - } - LCUIMutex_Unlock( &style_library.mutex ); - return 0; -} - -static int StyleLink_GetStyleSheets( StyleLink link, LinkedList *outlist ) -{ - StyleNode snode, out_snode; - LinkedListNode *node, *out_node; - - if( !outlist ) { - return link->styles.length; - } - for( LinkedList_Each( node, &link->styles ) ) { - int pos = -1, i = 0; - snode = node->data; - for( LinkedList_Each( out_node, outlist ) ) { - out_snode = out_node->data; - if( snode->rank > out_snode->rank ) { - pos = i; - break; - } - if( snode->rank != out_snode->rank ) { - i += 1; - continue; - } - if( snode->batch_num > out_snode->batch_num ) { - pos = i; - break; - } - i += 1; - } - if( pos >= 0 ) { - LinkedList_Insert( outlist, pos, snode ); - } else { - LinkedList_Append( outlist, snode ); - } - } - return link->styles.length; -} - -static int FindStyleSheetFromLink( StyleLink link, LCUI_Selector s, - int i, LinkedList *list ) -{ - int count = 0; - StyleLink parent; - LinkedList names; - LinkedListNode *node; - LCUI_SelectorNode sn; - - LinkedList_Init( &names ); - count += StyleLink_GetStyleSheets( link, list ); - while( --i >= 0 ) { - sn = s->nodes[i]; - SelectorNode_GetNames( sn, &names ); - for( LinkedList_Each( node, &names ) ) { - parent = Dict_FetchValue( link->parents, node->data ); - if( !parent ) { - continue; - } - count += FindStyleSheetFromLink( parent, s, i, list ); - } - LinkedList_Clear( &names, free ); - } - return count; -} - -/** - * 从指定组中查找样式表 - * @param[in] group 组号 - * @param[in] name 选择器结点名称,若为 NULL,则根据选择器结点生成名称 - * @param[in] s 选择器 - * @param[out] list 找到的样式表列表 - */ -static int FindStyleSheetFromGroup( int group, const char *name, - LCUI_Selector s, LinkedList *list ) -{ - int i, count; - Dict *groups; - StyleLinkGroup slg; - LinkedListNode *node; - LinkedList names; - - groups = LinkedList_Get( &style_library.groups, group ); - if( !groups || s->length < 1 ) { - return 0; - } - count = 0; - i = s->length - 1; - LinkedList_Init( &names ); - if( name ) { - LinkedList_Append( &names, strdup( name ) ); - } else { - SelectorNode_GetNames( s->nodes[i], &names ); - LinkedList_Append( &names, strdup( "*" ) ); - } - for( LinkedList_Each( node, &names ) ) { - DictEntry *entry; - DictIterator *iter; - char *name = node->data; - slg = Dict_FetchValue( groups, name ); - if( !slg ) { - continue; - } - iter = Dict_GetIterator( slg->links ); - while( (entry = Dict_Next( iter )) ) { - StyleLink link = DictEntry_GetVal( entry ); - count += FindStyleSheetFromLink( link, s, i, list ); - } - } - LinkedList_Clear( &names, free ); - return count; -} - -void LCUI_PrintStyleSheet( LCUI_StyleSheet ss ) -{ - int key; - const char *name; - for( key = 0; keylength; ++key ) { - LCUI_Style s = &ss->sheet[key]; - if( !s->is_valid ) { - continue; - } - name = GetStyleName(key); - if( name ) { - printf( "\t%s", name ); - } else { - printf( "\t", key); - } - printf( "%s: ", key > STYLE_KEY_TOTAL ? " (+)" : "" ); - switch( s->type ) { - case SVT_AUTO: - printf( "auto"); - break; - case SVT_BOOL: { - printf( "%s", s->val_bool ? "true" : "false" ); - break; - } - case SVT_COLOR: { - LCUI_Color *clr = &s->val_color; - if( clr->alpha < 255 ) { - printf("rgba(%d,%d,%d,%0.2f)", clr->r, - clr->g, clr->b, clr->a / 255.0); - } else { - printf("#%02x%02x%02x", clr->r, clr->g, clr->b); - } - break; - } - case SVT_PX: - printf("%dpx", s->val_px); - break; - case SVT_STRING: - printf("%s", s->val_string); - break; - case SVT_SCALE: - printf("%.2lf%%", s->val_scale*100); - break; - case SVT_STYLE:{ - printf("%s", GetStyleOptionName( s->val_style )); - break; - } - default: - printf("%d", s->value); - break; - } - printf( ";\n"); - } -} - -void LCUI_PrintSelector( LCUI_Selector selector ) -{ - char path[MAX_SELECTOR_LEN]; - LCUI_SelectorNode *sn; - - path[0] = 0; - for( sn = selector->nodes; *sn; ++sn ) { - strcat( path, (*sn)->fullname ); - strcat( path, " " ); - } - printf("path: %s (rank = %d, batch_num = %d)\n", path, - selector->rank, selector->batch_num); -} - -static void LCUI_PrintStyleLink( StyleLink link, const char *selector ) -{ - DictEntry *entry; - DictIterator *iter; - LinkedListNode *node; - char fullname[MAX_SELECTOR_LEN]; - if( selector ) { - sprintf( fullname, "%s %s", link->group->name, selector ); - } else { - strcpy( fullname, link->group->name ); - } - for( LinkedList_Each( node, &link->styles ) ) { - StyleNode snode = node->data; - printf("\n[%s]\n", snode->space ? snode->space:""); - printf("%s {\n", fullname); - LCUI_PrintStyleSheet( snode->sheet ); - printf("}\n"); - } - iter = Dict_GetIterator( link->parents ); - while( (entry = Dict_Next( iter )) ) { - StyleLink parent = DictEntry_GetVal( entry ); - LCUI_PrintStyleLink( parent, fullname ); - } - Dict_ReleaseIterator( iter ); -} - -void LCUI_PrintStyleLibrary( void ) -{ - Dict *group; - StyleLink link; - StyleLinkGroup slg; - DictIterator *iter; - DictEntry *entry; - - link = NULL; - printf( "style library begin\n" ); - group = LinkedList_Get( &style_library.groups, 0 ); - iter = Dict_GetIterator( group ); - while( (entry = Dict_Next(iter)) ) { - DictEntry *entry_slg; - DictIterator *iter_slg; - slg = DictEntry_GetVal( entry ); - iter_slg = Dict_GetIterator( slg->links ); - while( (entry_slg = Dict_Next(iter_slg)) ) { - link = DictEntry_GetVal( entry_slg ); - LCUI_PrintStyleLink( link, NULL ); - } - Dict_ReleaseIterator( iter_slg ); - } - Dict_ReleaseIterator( iter ); - printf( "style library end\n" ); -} - LCUI_Selector Widget_GetSelector( LCUI_Widget w ) { int ni = 0; @@ -1275,14 +94,14 @@ LCUI_Selector Widget_GetSelector( LCUI_Widget w ) } if( parent->classes ) { for( i = 0; parent->classes[i]; ++i ) { - SortedStrList_Add( &sn->classes, - parent->classes[i] ); + sortedstrsadd( &sn->classes, + parent->classes[i] ); } } if( parent->status ) { for( i = 0; parent->status[i]; ++i ) { - SortedStrList_Add( &sn->status, - parent->status[i] ); + sortedstrsadd( &sn->status, + parent->status[i] ); } } Widget_Unlock( parent ); @@ -1342,7 +161,8 @@ int Widget_HandleChildrenStyleChange( LCUI_Widget w, int type, const char *name } } if( i < n ) { - count += FindStyleSheetFromGroup( 1, sname, s, NULL ); + count += LCUI_FindStyleSheetFromGroup( 1, sname, + s, NULL ); } } Selector_Delete( s ); @@ -1357,30 +177,8 @@ int Widget_HandleChildrenStyleChange( LCUI_Widget w, int type, const char *name void Widget_GetInheritStyle( LCUI_Widget w, LCUI_StyleSheet out_ss ) { LCUI_Selector s; - LCUI_StyleSheet ss; - LinkedList list; - LinkedListNode *node; - LinkedList_Init( &list ); - StyleSheet_Clear( out_ss ); s = Widget_GetSelector( w ); - LCUIMutex_Lock( &style_library.mutex ); - ss = RBTree_GetData( &style_library.cache, (int)s->hash ); - if( ss ) { - StyleSheet_Replace( out_ss, ss ); - LCUIMutex_Unlock( &style_library.mutex ); - Selector_Delete( s ); - return; - } - ss = StyleSheet(); - FindStyleSheet( s, &list ); - for( LinkedList_Each( node, &list ) ) { - StyleNode sn = node->data; - StyleSheet_Merge( ss, sn->sheet ); - } - LinkedList_Clear( &list, NULL ); - RBTree_Insert( &style_library.cache, (int)s->hash, ss ); - StyleSheet_Replace( out_ss, ss ); - LCUIMutex_Unlock( &style_library.mutex ); + LCUI_GetStyleSheet( s, out_ss ); Selector_Delete( s ); } @@ -1455,20 +253,16 @@ void Widget_ExecUpdateStyle( LCUI_Widget w, LCUI_BOOL is_update_all ) StyleSheet_Delete( ss ); } -void LCUIWidget_ExitStyle( void ) -{ - LinkedList_Clear( &style_library.groups, (FuncPtr)DeleteStyleGroup ); - style_library.is_inited = FALSE; - LCUICSS_Destroy(); -} - void LCUIWidget_InitStyle( void ) { - RBTree_Init( &style_library.cache ); - RBTree_OnDestroy( &style_library.cache, (FuncPtr)StyleSheet_Delete ); - LinkedList_Init( &style_library.groups ); - LCUIMutex_Init( &style_library.mutex ); - LCUICSS_Init(); - LCUICSS_LoadString( global_css, NULL ); - style_library.is_inited = TRUE; + + LCUI_InitCSSLibrary(); + LCUI_InitCSSParser(); + LCUI_LoadCSSString( global_css, NULL ); +} + +void LCUIWidget_ExitStyle( void ) +{ + LCUI_ExitCSSLibrary(); + LCUI_ExitCSSParser(); } diff --git a/src/main.c b/src/main.c index 58b9dc80..49468c74 100644 --- a/src/main.c +++ b/src/main.c @@ -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; } diff --git a/src/util/Makefile.am b/src/util/Makefile.am index 7c789bfa..ebc9b1e3 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -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 diff --git a/src/util/dict.c b/src/util/dict.c index 025760ce..84904d67 100644 --- a/src/util/dict.c +++ b/src/util/dict.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 +}; \ No newline at end of file diff --git a/src/util/mem_debug.c b/src/util/mem_debug.c deleted file mode 100644 index f2eedff3..00000000 --- a/src/util/mem_debug.c +++ /dev/null @@ -1,45 +0,0 @@ -#include -#include -#include - -//#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 diff --git a/src/util/string.c b/src/util/string.c index 00e653d9..eb56186a 100644 --- a/src/util/string.c +++ b/src/util/string.c @@ -39,6 +39,7 @@ #include #include +#include #include #include @@ -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; +} From bbec5dfd18853c7a6f5e2b2310031aee05c72506 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Wed, 31 Aug 2016 21:26:53 +0800 Subject: [PATCH 117/124] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20css=5Flibrary.c=20?= =?UTF-8?q?=E4=B8=AD=E5=AD=98=E5=9C=A8=E7=9A=84=E4=B8=80=E4=BA=9BBUG?= =?UTF-8?q?=EF=BC=8C=E6=9B=B4=E6=96=B0=E9=83=A8=E4=BB=B6=E6=A0=B7=E5=BC=8F?= =?UTF-8?q?=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/gui/css_library.h | 4 +- include/LCUI/util/dict.h | 6 +- src/gui/css_library.c | 169 ++++++++++++++++++++++----------- src/gui/css_parser.c | 5 +- src/gui/widget/textview.c | 5 +- src/gui/widget_background.c | 4 +- src/gui/widget_base.c | 8 +- src/util/dict.c | 10 -- 8 files changed, 134 insertions(+), 77 deletions(-) diff --git a/include/LCUI/gui/css_library.h b/include/LCUI/gui/css_library.h index afdd0d7f..d7714f8a 100644 --- a/include/LCUI/gui/css_library.h +++ b/include/LCUI/gui/css_library.h @@ -211,7 +211,9 @@ LCUI_API int LCUI_FindStyleSheetFromGroup( int group, const char *name, 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_SetStyleName( int key, const char *name ); + +LCUI_API int LCUI_AddStyleName( const char *name ); LCUI_API int LCUI_AddStyleValue( int key, const char *name ); diff --git a/include/LCUI/util/dict.h b/include/LCUI/util/dict.h index b3432018..7762b0f3 100644 --- a/include/LCUI/util/dict.h +++ b/include/LCUI/util/dict.h @@ -203,6 +203,10 @@ LCUI_API void Dict_PrintStats( Dict *d ); LCUI_API unsigned int Dict_GenHashFunction( const unsigned char *buf, int len ); LCUI_API unsigned int Dict_GenCaseHashFunction( const unsigned char *buf, int len ); +LCUI_API unsigned int Dict_IntHashFunction( unsigned int key ); + +/* Identity hash function for integer keys */ +LCUI_API unsigned int Dict_IdentityHashFunction( unsigned int key ); /** 清空字典 */ LCUI_API void Dict_Empty( Dict *d ); @@ -229,7 +233,5 @@ LCUI_API unsigned int Dict_GetHashFunctionSeed( void ); /* Hash table types */ DictType DictType_StringKey; DictType DictType_StringCopyKey; -DictType DictType_IntKey; -DictType DictType_IdentityKey; #endif /* LCUI_UTIL_DICT_H */ diff --git a/src/gui/css_library.c b/src/gui/css_library.c index ff316b2e..1228b886 100644 --- a/src/gui/css_library.c +++ b/src/gui/css_library.c @@ -107,7 +107,6 @@ static struct { LCUI_BOOL is_inited; LCUI_Mutex mutex; /**< 互斥锁 */ LinkedList groups; /**< 样式组列表 */ - DictType cachedict; /**< 样式表缓存字典的类型数据 */ Dict *cache; /**< 样式表缓存,以选择器的 hash 值索引 */ Dict *names; /**< 样式属性名称表,以值的名称索引 */ Dict *value_keys; /**< 样式属性值表,以值的名称索引 */ @@ -217,39 +216,64 @@ static KeyNameGroupRec style_value_map[] = { static int LCUI_DirectAddStyleName( int key, const char *name ) { + unsigned int *newkey; char *newname = strdup( name ); if( !newname ) { return -ENOMEM; } - if( Dict_Add( library.names, (void*)key, newname ) == 0 ) { + newkey = malloc( sizeof(unsigned int) ); + if( !newkey ) { + free( newname ); + return -ENOMEM; + } + *newkey = key; + if( Dict_Add( library.names, newkey, newname ) == 0 ) { return 0; } free( newname ); return -1; } -int LCUI_AddStyleName( int key, const char *name ) +int LCUI_SetStyleName( int key, const char *name ) { - int ret; + char *newname; + DictEntry *entry; LCUIMutex_Lock( &library.mutex ); - key = library.count++; - ret = LCUI_DirectAddStyleName( key, name ); - if( ret != 0 ) { - --library.count; + entry = Dict_Find( library.names, &key ); + if( entry ) { + newname = strdup( name ); + free( DictEntry_GetVal( entry ) ); + Dict_SetVal( library.names, entry, newname ); + LCUIMutex_Unlock( &library.mutex ); + return 0; } LCUIMutex_Unlock( &library.mutex ); - return ret; + return -1; +} + +int LCUI_AddStyleName( const char *name ) +{ + int key; + LCUIMutex_Lock( &library.mutex ); + key = library.count++; + if( LCUI_DirectAddStyleName( key, name ) != 0 ) { + --library.count; + LCUIMutex_Unlock( &library.mutex ); + return -1; + } + LCUIMutex_Unlock( &library.mutex ); + return key; } int LCUI_AddStyleValue( int key, const char *name ) { - int *val; char *newname; + unsigned int *val; newname = strdup( name ); if( !newname ) { return -ENOMEM; } - val = malloc( sizeof( int ) ); + val = malloc( sizeof( unsigned int ) ); if( !val ) { free( newname ); return -ENOMEM; @@ -274,12 +298,12 @@ int LCUI_GetStyleValue( const char *str ) const char *LCUI_GetStyleValueName( int val ) { - return Dict_FetchValue( library.value_names, (void*)val ); + return Dict_FetchValue( library.value_names, &val ); } const char *LCUI_GetStyleName( int key ) { - return Dict_FetchValue( library.names, (void*)key ); + return Dict_FetchValue( library.names, &key ); } int LCUI_GetStyleTotal( void ) @@ -440,7 +464,7 @@ void StyleSheet_Delete( LCUI_StyleSheet ss ) int StyleSheet_Merge( LCUI_StyleSheet dest, LCUI_StyleSheet src ) { LCUI_Style s; - int i, name_count, size; + int i, count, size; if( src->length > dest->length ) { size = sizeof( LCUI_StyleRec )*src->length; s = realloc( dest->sheet, size ); @@ -453,12 +477,12 @@ int StyleSheet_Merge( LCUI_StyleSheet dest, LCUI_StyleSheet src ) dest->sheet = s; dest->length = src->length; } - for( name_count = 0, i = 0; i < src->length; ++i ) { + for( count = 0, i = 0; i < src->length; ++i ) { s = &dest->sheet[i]; if( !src->sheet[i].is_valid || s->is_valid ) { continue; } - ++name_count; + ++count; switch( src->sheet[i].type ) { case SVT_STRING: s->string = strdup( src->sheet[i].string ); @@ -482,20 +506,20 @@ int StyleSheet_Merge( LCUI_StyleSheet dest, LCUI_StyleSheet src ) int StyleSheet_Replace( LCUI_StyleSheet dest, LCUI_StyleSheet src ) { LCUI_Style s; - int i, name_count, size; + int i, count, size; if( src->length > dest->length ) { - size = sizeof(LCUI_StyleRec)*src->length; + size = sizeof( LCUI_StyleRec )*src->length; s = realloc( dest->sheet, size ); if( !s ) { return -1; } - for( i=dest->length; ilength; ++i ) { + for( i = dest->length; i < src->length; ++i ) { s[i].is_valid = FALSE; } dest->sheet = s; dest->length = src->length; } - for( name_count=0,i=0; ilength; ++i ) { + for( count = 0, i = 0; i < src->length; ++i ) { if( !src->sheet[i].is_valid ) { continue; } @@ -512,7 +536,7 @@ int StyleSheet_Replace( LCUI_StyleSheet dest, LCUI_StyleSheet src ) free( s->wstring ); } size = wcslen( src->sheet[i].wstring ) + 1; - s->wstring = malloc( size * sizeof(wchar_t) ); + s->wstring = malloc( size * sizeof( wchar_t ) ); wcscpy( s->wstring, src->sheet[i].wstring ); break; default: @@ -522,9 +546,9 @@ int StyleSheet_Replace( LCUI_StyleSheet dest, LCUI_StyleSheet src ) s->is_valid = TRUE; s->is_changed = TRUE; s->type = src->sheet[i].type; - ++name_count; + ++count; } - return name_count; + return count; } /** 初始化样式表查找器 */ @@ -552,7 +576,7 @@ static void NamesFinder_Destroy( NamesFinder sfinder ) /* 生成选择器全名列表 */ static int NamesFinder_Find( NamesFinder sfinder, LinkedList *list ) { - int i, len, old_len, old_level, name_count = 0; + int i, len, old_len, old_level, count = 0; char *fullname = sfinder->name + sfinder->name_i; old_len = len = strlen( fullname ); old_level = sfinder->level; @@ -593,7 +617,7 @@ static int NamesFinder_Find( NamesFinder sfinder, LinkedList *list ) LinkedList_Append( list, strdup( fullname ) ); /* 将当前选择器名与其它层级的选择器名组合 */ while( sfinder->level < LEVEL_TOTAL_NUM ) { - name_count += NamesFinder_Find( sfinder, list ); + count += NamesFinder_Find( sfinder, list ); sfinder->level += 1; } sfinder->level = LEVEL_CLASS; @@ -602,7 +626,7 @@ static int NamesFinder_Find( NamesFinder sfinder, LinkedList *list ) sfinder->level = LEVEL_CLASS; fullname[old_len] = 0; sfinder->class_i = 0; - return name_count; + return count; case LEVEL_CLASS_2: if( !sfinder->node->classes ) { return 0; @@ -621,19 +645,19 @@ static int NamesFinder_Find( NamesFinder sfinder, LinkedList *list ) strcpy( fullname + len, sfinder->node->classes[i] ); LinkedList_Append( list, strdup( fullname ) ); sfinder->class_i += 1; - name_count += NamesFinder_Find( sfinder, list ); + count += NamesFinder_Find( sfinder, list ); sfinder->class_i -= 1; sfinder->level = LEVEL_STATUS; /** * 递归拼接伪类名,例如: * textview#main-btn-text:active */ - name_count += NamesFinder_Find( sfinder, list ); + count += NamesFinder_Find( sfinder, list ); sfinder->level = LEVEL_CLASS_2; } fullname[old_len] = 0; sfinder->level = LEVEL_CLASS_2; - return name_count; + return count; case LEVEL_STATUS: if( !sfinder->node->status ) { return 0; @@ -659,13 +683,13 @@ static int NamesFinder_Find( NamesFinder sfinder, LinkedList *list ) * 递归调用,以一层层拼接出像下面这样的选择器: * textview#main-btn-text:active:focus:hover */ - name_count += NamesFinder_Find( sfinder, list ); + count += NamesFinder_Find( sfinder, list ); sfinder->status_i += 1; } sfinder->level = LEVEL_STATUS; fullname[old_len] = 0; sfinder->status_i = 0; - return name_count; + return count; case LEVEL_STATUS_2: if( !sfinder->node->status ) { return 0; @@ -679,11 +703,11 @@ static int NamesFinder_Find( NamesFinder sfinder, LinkedList *list ) strcpy( fullname + len + 1, sfinder->node->status[i] ); LinkedList_Append( list, strdup( fullname ) ); sfinder->status_i += 1; - name_count += NamesFinder_Find( sfinder, list ); + count += NamesFinder_Find( sfinder, list ); sfinder->status_i -= 1; } fullname[old_len] = 0; - return name_count; + return count; default:break; } for( i = sfinder->level + 1; i < LEVEL_TOTAL_NUM; ++i ) { @@ -691,11 +715,11 @@ static int NamesFinder_Find( NamesFinder sfinder, LinkedList *list ) continue; } sfinder->level = i; - name_count += NamesFinder_Find( sfinder, list ); + count += NamesFinder_Find( sfinder, list ); } fullname[old_len] = 0; sfinder->level = old_level; - return name_count; + return count; } static int SelectorNode_Save( LCUI_SelectorNode node, @@ -741,12 +765,12 @@ static int SelectorNode_Save( LCUI_SelectorNode node, int SelectorNode_GetNames( LCUI_SelectorNode sn, LinkedList *names ) { - int name_count; + int count; NamesFinderRec sfinder; NamesFinder_Init( &sfinder, sn ); - name_count = NamesFinder_Find( &sfinder, names ); + count = NamesFinder_Find( &sfinder, names ); NamesFinder_Destroy( &sfinder ); - return name_count; + return count; } int SelectorNode_Update( LCUI_SelectorNode node ) @@ -1055,6 +1079,7 @@ static LCUI_StyleSheet LCUI_SelectStyleSheet( LCUI_Selector selector, } if( i == 0 ) { strcpy( buf, sn->fullname ); + strcpy( fullname, buf ); } else { strcpy( fullname, buf ); sprintf( buf, "%s %s", sn->fullname, fullname ); @@ -1150,14 +1175,14 @@ static int StyleLink_GetStyleSheets( StyleLink link, LinkedList *outlist ) static int LCUI_FindStyleSheetFromLink( StyleLink link, LCUI_Selector s, int i, LinkedList *list ) { - int name_count = 0; + int count = 0; StyleLink parent; LinkedList names; LinkedListNode *node; LCUI_SelectorNode sn; LinkedList_Init( &names ); - name_count += StyleLink_GetStyleSheets( link, list ); + count += StyleLink_GetStyleSheets( link, list ); while( --i >= 0 ) { sn = s->nodes[i]; SelectorNode_GetNames( sn, &names ); @@ -1166,18 +1191,18 @@ static int LCUI_FindStyleSheetFromLink( StyleLink link, LCUI_Selector s, if( !parent ) { continue; } - name_count += LCUI_FindStyleSheetFromLink( parent, s, + count += LCUI_FindStyleSheetFromLink( parent, s, i, list ); } LinkedList_Clear( &names, free ); } - return name_count; + return count; } int LCUI_FindStyleSheetFromGroup( int group, const char *name, LCUI_Selector s, LinkedList *list ) { - int i, name_count; + int i, count; Dict *groups; StyleLinkGroup slg; LinkedListNode *node; @@ -1187,7 +1212,7 @@ int LCUI_FindStyleSheetFromGroup( int group, const char *name, if( !groups || s->length < 1 ) { return 0; } - name_count = 0; + count = 0; i = s->length - 1; LinkedList_Init( &names ); if( name ) { @@ -1207,12 +1232,12 @@ int LCUI_FindStyleSheetFromGroup( int group, const char *name, iter = Dict_GetIterator( slg->links ); while( (entry = Dict_Next( iter )) ) { StyleLink link = DictEntry_GetVal( entry ); - name_count += LCUI_FindStyleSheetFromLink( link, s, + count += LCUI_FindStyleSheetFromLink( link, s, i, list ); } } LinkedList_Clear( &names, free ); - return name_count; + return count; } void LCUI_PrintStyleSheet( LCUI_StyleSheet ss ) @@ -1343,7 +1368,7 @@ void LCUI_GetStyleSheet( LCUI_Selector s, LCUI_StyleSheet out_ss ) LinkedList_Init( &list ); StyleSheet_Clear( out_ss ); LCUIMutex_Lock( &library.mutex ); - ss = Dict_FetchValue( library.cache, (void*)s->hash ); + ss = Dict_FetchValue( library.cache, &s->hash ); if( ss ) { StyleSheet_Replace( out_ss, ss ); LCUIMutex_Unlock( &library.mutex ); @@ -1356,7 +1381,7 @@ void LCUI_GetStyleSheet( LCUI_Selector s, LCUI_StyleSheet out_ss ) StyleSheet_Merge( ss, sn->sheet ); } LinkedList_Clear( &list, NULL ); - Dict_Add( library.cache, (void*)s->hash, ss ); + Dict_Add( library.cache, &s->hash, ss ); StyleSheet_Replace( out_ss, ss ); LCUIMutex_Unlock( &library.mutex ); } @@ -1366,15 +1391,53 @@ static void DestroyStyleSheetCache( void *privdata, void *val ) StyleSheet_Delete( val ); } +static void DestroyStyleName( void *privdata, void *val ) +{ + free( val ); +} + +static unsigned int IntKeyDict_HashFunction( const void *key ) +{ + return Dict_IdentityHashFunction( *(unsigned int*)key ); +} + +static int IntKeyDict_KeyCompare( void *privdata, + const void *key1, const void *key2 ) +{ + return *(unsigned int*)key1 == *(unsigned int*)key2; +} + +static void IntKeyDict_KeyDestructor( void *privdata, void *key ) +{ + free( key ); +} + +static void *IntKeyDict_KeyDup( void *privdata, const void *key ) +{ + unsigned int *newkey = malloc( sizeof(unsigned int) ); + *newkey = *(unsigned int*)key; + return newkey; +} + void LCUI_InitCSSLibrary( void ) { KeyNameGroup skn, skn_end; - library.cachedict = DictType_IdentityKey; - library.cachedict.valDestructor = DestroyStyleSheetCache; - library.cache = Dict_Create( &library.cachedict, NULL ); - library.names = Dict_Create( &DictType_IdentityKey, NULL ); + static DictType cachedict, namedict; + cachedict.keyDup = IntKeyDict_KeyDup; + cachedict.keyCompare = IntKeyDict_KeyCompare; + cachedict.hashFunction = IntKeyDict_HashFunction; + cachedict.keyDestructor = IntKeyDict_KeyDestructor; + cachedict.valDestructor = DestroyStyleSheetCache; + cachedict.valDup = namedict.valDup = NULL; + namedict.keyDup = IntKeyDict_KeyDup; + namedict.keyCompare = IntKeyDict_KeyCompare; + namedict.hashFunction = IntKeyDict_HashFunction; + namedict.keyDestructor = IntKeyDict_KeyDestructor; + namedict.valDestructor = DestroyStyleName; + library.names = Dict_Create( &namedict, NULL ); + library.cache = Dict_Create( &cachedict, NULL ); + library.value_names = Dict_Create( &namedict, NULL ); library.value_keys = Dict_Create( &DictType_StringKey, NULL ); - library.value_names = Dict_Create( &DictType_IdentityKey, NULL ); LinkedList_Init( &library.groups ); LCUIMutex_Init( &library.mutex ); skn_end = style_name_map + LEN( style_name_map ); diff --git a/src/gui/css_parser.c b/src/gui/css_parser.c index 5f0ec6ac..04d5e927 100644 --- a/src/gui/css_parser.c +++ b/src/gui/css_parser.c @@ -793,7 +793,6 @@ int LCUI_LoadCSSString( const char *str, const char *space ) int LCUI_AddCSSParser( LCUI_StyleParser sp ) { - int key; LCUI_StyleParser new_sp; if( !sp->name || strlen( sp->name ) < 1 ) { return -1; @@ -801,13 +800,13 @@ int LCUI_AddCSSParser( LCUI_StyleParser sp ) if( Dict_FetchValue( self.parsers, sp->name ) ) { return -2; } - key = self.count++; + self.count += 1; new_sp = NEW( LCUI_StyleParserRec, 1 ); new_sp->key = sp->key; new_sp->parse = sp->parse; new_sp->name = strdup( sp->name ); Dict_Add( self.parsers, new_sp->name, new_sp ); - return key; + return 0; } static void DestroyStyleParser( void *privdata, void *val ) diff --git a/src/gui/widget/textview.c b/src/gui/widget/textview.c index 26415dec..7a49e1e5 100644 --- a/src/gui/widget/textview.c +++ b/src/gui/widget/textview.c @@ -568,7 +568,8 @@ void LCUIWidget_AddTextView( void ) wc->methods.set_text = TextView_OnParseText; wc->task_handler = TextView_OnTask; for( i = 0; i < TOTAL_FONT_STYLE_KEY; ++i ) { - style_key_map[style_parsers[i].key] = - LCUI_AddCSSParser( &style_parsers[i] ); + LCUI_StyleParser parser = &style_parsers[i]; + style_key_map[parser->key] = LCUI_AddStyleName( parser->name ); + LCUI_AddCSSParser( parser ); } } diff --git a/src/gui/widget_background.c b/src/gui/widget_background.c index e50c893d..fca12add 100644 --- a/src/gui/widget_background.c +++ b/src/gui/widget_background.c @@ -162,9 +162,9 @@ void Widget_UpdateBackground( LCUI_Widget widget ) LCUI_Style s; LCUI_StyleSheet ss = widget->style; LCUI_Background *bg = &widget->computed_style.background; - int key = key_background_start + 1; + int key = key_background_start; - for( ; key < key_background_end; ++key ) { + for( ; key <= key_background_end; ++key ) { s = &ss->sheet[key]; if( !s->is_valid ) { continue; diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index 8f9a563b..3f160d69 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -422,8 +422,8 @@ int Widget_SetId( LCUI_Widget w, const char *idstr ) static void ComputeBorderStyle( LCUI_StyleSheet ss, LCUI_Border *b ) { LCUI_Style style; - int key = key_border_start + 1; - for( ; key < key_border_end; ++key ) { + int key = key_border_start ; + for( ; key <= key_border_end; ++key ) { style = &ss->sheet[key]; if( !style->is_valid ) { continue; @@ -538,9 +538,9 @@ void Widget_UpdateBorder( LCUI_Widget w ) static void ComputeBoxShadowStyle( LCUI_StyleSheet ss, LCUI_BoxShadow *bsd ) { LCUI_Style style; - int key = key_box_shadow_start + 1; + int key = key_box_shadow_start; memset( bsd, 0, sizeof( *bsd ) ); - for( ; key < key_box_shadow_end; ++key ) { + for( ; key <= key_box_shadow_end; ++key ) { style = &ss->sheet[key]; if( !style->is_valid ) { continue; diff --git a/src/util/dict.c b/src/util/dict.c index 84904d67..07df84a6 100644 --- a/src/util/dict.c +++ b/src/util/dict.c @@ -718,13 +718,3 @@ 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 -}; \ No newline at end of file From 3ae2abb4fe68035bd3d0cde3e5424ef1b6519db8 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Wed, 31 Aug 2016 23:14:29 +0800 Subject: [PATCH 118/124] =?UTF-8?q?=E7=BA=A0=E6=AD=A3=E6=97=A0=E6=95=88?= =?UTF-8?q?=E5=8C=BA=E5=9F=9F=E7=9A=84=E5=9D=90=E6=A0=87=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E3=80=81=E4=BF=AE=E6=94=B9=E7=9B=92=E5=9E=8B=E9=98=B4=E5=BD=B1?= =?UTF-8?q?=E7=9A=84=E9=87=8D=E7=BB=98=E5=88=A4=E5=AE=9A=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gui/widget_base.c | 16 +++++++++------- src/gui/widget_paint.c | 7 ++++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index 3f160d69..d3e5caa1 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -561,16 +561,18 @@ void Widget_UpdateBoxShadow( LCUI_Widget w ) LCUI_BoxShadow bs = w->computed_style.shadow; ComputeBoxShadowStyle( w->style, &w->computed_style.shadow ); /* 如果阴影变化并未导致图层尺寸变化,则只重绘阴影 */ - if( bs.x == w->computed_style.shadow.x && - bs.y == w->computed_style.shadow.y && - bs.spread == w->computed_style.shadow.spread ) { + if( bs.x == w->computed_style.shadow.x && + bs.y == w->computed_style.shadow.y && + bs.blur == w->computed_style.shadow.blur ) { + int i; LCUI_Rect rects[4]; LCUIRect_CutFourRect( &w->box.border, &w->box.graph, rects ); - Widget_InvalidateArea( w, &rects[0], SV_GRAPH_BOX ); - Widget_InvalidateArea( w, &rects[1], SV_GRAPH_BOX ); - Widget_InvalidateArea( w, &rects[2], SV_GRAPH_BOX ); - Widget_InvalidateArea( w, &rects[3], SV_GRAPH_BOX ); + for( i = 0; i < 4; ++i ) { + rects[i].x -= w->box.graph.x; + rects[i].y -= w->box.graph.y; + Widget_InvalidateArea( w, &rects[i], SV_GRAPH_BOX ); + } return; } Widget_AddTask( w, WTT_RESIZE ); diff --git a/src/gui/widget_paint.c b/src/gui/widget_paint.c index 82437aeb..f34f0fbf 100644 --- a/src/gui/widget_paint.c +++ b/src/gui/widget_paint.c @@ -113,21 +113,22 @@ LCUI_BOOL Widget_PushInvalidArea( LCUI_Widget widget, LCUI_Rect rect; LCUI_Widget w = widget; LCUI_Widget root = LCUIWidget_GetRoot(); - if( !w ) { w = root; } Widget_AdjustArea( w, r, &rect, box_type ); + rect.x += w->box.graph.x; + rect.y += w->box.graph.y; while( w && w->parent ) { int width = w->parent->box.padding.width; int height = w->parent->box.padding.height; - rect.x += w->box.graph.x; - rect.y += w->box.graph.y; LCUIRect_ValidateArea( &rect, width, height ); if( rect.width < 0 || rect.height < 0 ) { return FALSE; } w = w->parent; + rect.x += w->box.padding.x; + rect.y += w->box.padding.y; } Widget_InvalidateArea( root, &rect, SV_PADDING_BOX ); return TRUE; From df956677cfe13a57a90748093c46c78451dc8d6a Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Thu, 1 Sep 2016 00:18:03 +0800 Subject: [PATCH 119/124] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=A4=96=E9=97=B4?= =?UTF-8?q?=E8=B7=9D=E5=92=8C=E5=86=85=E9=97=B4=E8=B7=9D=E7=9A=84=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 解决当左右外间距值为 auto 时部件位置不会水平居中的问题 解决在设置内间距后子部件位置未及时更新的问题 --- include/LCUI/gui/css_library.h | 11 +++ include/LCUI/gui/widget_base.h | 3 + src/gui/widget_base.c | 140 ++++++++++++++++++++++----------- src/gui/widget_style.c | 3 +- src/gui/widget_task.c | 1 + 5 files changed, 112 insertions(+), 46 deletions(-) diff --git a/include/LCUI/gui/css_library.h b/include/LCUI/gui/css_library.h index d7714f8a..be88ebc2 100644 --- a/include/LCUI/gui/css_library.h +++ b/include/LCUI/gui/css_library.h @@ -67,14 +67,21 @@ enum LCUI_StyleKeyName { key_height, key_min_height, key_max_height, + + // margin start key_margin_top, key_margin_right, key_margin_bottom, key_margin_left, + // margin end + + // padding start key_padding_top, key_padding_right, key_padding_bottom, key_padding_left, + // padding end + key_vertical_align, // border start @@ -131,6 +138,10 @@ enum LCUI_StyleKeyName { #define key_display_end key_display #define key_position_start key_left #define key_position_end key_position +#define key_margin_start key_margin_top +#define key_margin_end key_margin_left +#define key_padding_start key_padding_top +#define key_padding_end key_padding_left #define key_border_start key_border_color #define key_border_end key_border_bottom_right_radius #define key_background_start key_background_color diff --git a/include/LCUI/gui/widget_base.h b/include/LCUI/gui/widget_base.h index 26e758a3..05aa8152 100755 --- a/include/LCUI/gui/widget_base.h +++ b/include/LCUI/gui/widget_base.h @@ -207,6 +207,9 @@ LCUI_API void Widget_ExecUpdateZIndex( LCUI_Widget w ); /** 刷新位置 */ LCUI_API void Widget_UpdatePosition( LCUI_Widget w ); +/** 刷新外间距 */ +LCUI_API void Widget_UpdateMargin( LCUI_Widget w ); + /** 刷新尺寸 */ LCUI_API void Widget_UpdateSize( LCUI_Widget w ); diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index d3e5caa1..5f87d06c 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -983,6 +983,76 @@ static void Widget_ComputeSize( LCUI_Widget w ) } w->width = w->box.border.width; w->height = w->box.border.height; + w->box.outer.width = w->box.border.width; + w->box.outer.height = w->box.border.height; + w->box.outer.width += w->margin.left + w->margin.right; + w->box.outer.height += w->margin.top + w->margin.bottom; +} + +static void Widget_SendResizeEvent( LCUI_Widget w ) +{ + LCUI_Style s; + LCUI_Widget child; + LCUI_WidgetEventRec e; + LinkedListNode *node; + e.target = w; + e.data = NULL; + e.type = WET_RESIZE; + e.cancel_bubble = TRUE; + Widget_TriggerEvent( w, &e, NULL ); + Widget_AddTask( w, WTT_REFRESH ); + Widget_PostSurfaceEvent( w, WET_RESIZE ); + for( LinkedList_Each( node, &w->children ) ) { + child = node->data; + s = child->style->sheet; + if( s[key_width].type == SVT_SCALE || + s[key_height].type == SVT_SCALE ) { + Widget_AddTask( child, WTT_RESIZE ); + } + if( child->computed_style.position == SV_ABSOLUTE ) { + if( s[key_right].is_valid || s[key_bottom].is_valid ) { + Widget_AddTask( child, WTT_POSITION ); + } + } + if( s[key_margin_left].is_valid && + s[key_margin_left].value == SV_AUTO ) { + Widget_AddTask( child, WTT_MARGIN ); + } + else if( s[key_margin_right].is_valid && + s[key_margin_right].value == SV_AUTO ) { + Widget_AddTask( child, WTT_MARGIN ); + } + if( child->computed_style.vertical_align != SV_TOP ) { + Widget_AddTask( child, WTT_POSITION ); + } + } +} + +void Widget_UpdateMargin( LCUI_Widget w ) +{ + int i; + LCUI_BoundBox *mbox = &w->computed_style.margin; + struct { + LCUI_Style sval; + int *ival; + int key; + } pd_map[4] = { + { &mbox->top, &w->margin.top, key_margin_top }, + { &mbox->right, &w->margin.right, key_margin_right }, + { &mbox->bottom, &w->margin.bottom, key_margin_bottom }, + { &mbox->left, &w->margin.left, key_margin_left } + }; + for( i = 0; i < 4; ++i ) { + LCUI_Style s = &w->style->sheet[pd_map[i].key]; + if( !s->is_valid || s->type != SVT_PX ) { + pd_map[i].sval->type = SVT_PX; + pd_map[i].sval->px = 0; + *pd_map[i].ival = 0; + continue; + } + *pd_map[i].sval = *s; + *pd_map[i].ival = s->px; + } /* 如果有父级部件,则处理 margin-left 和 margin-right 的值 */ if( w->parent ) { int width = w->parent->box.content.width; @@ -1015,70 +1085,38 @@ static void Widget_ComputeSize( LCUI_Widget w ) } } } - w->box.outer.width = w->box.border.width; - w->box.outer.height = w->box.border.height; - w->box.outer.width += w->margin.left + w->margin.right; - w->box.outer.height += w->margin.top + w->margin.bottom; -} - -static void Widget_SendResizeEvent( LCUI_Widget w ) -{ - LCUI_Style s; - LCUI_Widget child; - LCUI_WidgetEventRec e; - LinkedListNode *node; - e.target = w; - e.data = NULL; - e.type = WET_RESIZE; - e.cancel_bubble = TRUE; - Widget_TriggerEvent( w, &e, NULL ); - Widget_AddTask( w, WTT_REFRESH ); - Widget_PostSurfaceEvent( w, WET_RESIZE ); - for( LinkedList_Each( node, &w->children ) ) { - child = node->data; - s = child->style->sheet; - if( s[key_width].type == SVT_SCALE || - s[key_height].type == SVT_SCALE ) { - Widget_AddTask( child, WTT_RESIZE ); + if( w->parent ) { + if( w->parent->style->sheet[key_width].type == SVT_AUTO + || w->parent->style->sheet[key_height].type == SVT_AUTO ) { + Widget_AddTask( w->parent, WTT_RESIZE ); } - if( child->computed_style.position == SV_ABSOLUTE ) { - if( s[key_right].is_valid || s[key_bottom].is_valid ) { - Widget_AddTask( child, WTT_POSITION ); - } - else if( s[key_margin_left].is_valid && - s[key_margin_left].value == SV_AUTO ) { - Widget_AddTask( child, WTT_POSITION ); - } - } - if( child->computed_style.vertical_align != SV_TOP ) { - Widget_AddTask( child, WTT_POSITION ); + if( w->computed_style.display != SV_NONE && + w->computed_style.position == SV_STATIC ) { + Widget_UpdateLayout( w->parent ); } } + Widget_AddTask( w, WTT_POSITION ); } void Widget_UpdateSize( LCUI_Widget w ) { LCUI_Rect rect; int i, box_sizing; - LCUI_BoundBox *mbox = &w->computed_style.margin; + LCUI_Rect2 padding = w->padding; LCUI_BoundBox *pbox = &w->computed_style.padding; struct { LCUI_Style sval; int *ival; int key; - } pd_map[8] = { + } pd_map[4] = { { &pbox->top, &w->padding.top, key_padding_top }, { &pbox->right, &w->padding.right, key_padding_right }, { &pbox->bottom, &w->padding.bottom, key_padding_bottom }, - { &pbox->left, &w->padding.left, key_padding_left }, - { &mbox->top, &w->margin.top, key_margin_top }, - { &mbox->right, &w->margin.right, key_margin_right }, - { &mbox->bottom, &w->margin.bottom, key_margin_bottom }, - { &mbox->left, &w->margin.left, key_margin_left } + { &pbox->left, &w->padding.left, key_padding_left } }; rect = w->box.graph; /* 内边距的单位暂时都用 px */ - for( i = 0; i < 8; ++i ) { + for( i = 0; i < 4; ++i ) { LCUI_Style s = &w->style->sheet[pd_map[i].key]; if( !s->is_valid || s->type != SVT_PX ) { pd_map[i].sval->type = SVT_PX; @@ -1093,9 +1131,21 @@ void Widget_UpdateSize( LCUI_Widget w ) w->computed_style.box_sizing = box_sizing; Widget_ComputeSize( w ); Widget_UpdateGraphBox( w ); + /* 如果左右外间距是 auto 类型的,则需要计算外间距 */ + if( w->style->sheet[key_margin_left].is_valid && + w->style->sheet[key_margin_left].type == SVT_AUTO ) { + Widget_UpdateMargin( w ); + } else if( w->style->sheet[key_margin_right].is_valid && + w->style->sheet[key_margin_right].type == SVT_AUTO ) { + Widget_UpdateMargin( w ); + } /* 若尺寸无变化则不继续处理 */ if( rect.width == w->box.graph.width && - rect.height == w->box.graph.height ) { + rect.height == w->box.graph.height && + padding.top == w->padding.top && + padding.right == w->padding.right && + padding.bottom == w->padding.bottom && + padding.left == w->padding.left) { return; } /* 若在变化前后的宽高中至少有一个为 0,则不继续处理 */ diff --git a/src/gui/widget_style.c b/src/gui/widget_style.c index 49f37687..07663266 100644 --- a/src/gui/widget_style.c +++ b/src/gui/widget_style.c @@ -207,7 +207,8 @@ void Widget_ExecUpdateStyle( LCUI_Widget w, LCUI_BOOL is_update_all ) { key_opacity, key_opacity, WTT_OPACITY, TRUE }, { key_z_index, key_z_index, WTT_ZINDEX, TRUE }, { key_width, key_height, WTT_RESIZE, TRUE }, - { key_padding_top, key_padding_left, WTT_RESIZE, TRUE }, + { key_padding_start, key_padding_end, WTT_RESIZE, TRUE }, + { key_margin_start, key_margin_end, WTT_MARGIN, TRUE }, { key_position_start, key_position_end, WTT_POSITION, TRUE }, { key_vertical_align, key_vertical_align, WTT_POSITION, TRUE }, { key_border_start, key_border_end, WTT_BORDER, TRUE }, diff --git a/src/gui/widget_task.c b/src/gui/widget_task.c index 8420234a..e722bb3b 100644 --- a/src/gui/widget_task.c +++ b/src/gui/widget_task.c @@ -131,6 +131,7 @@ static void MapTaskHandler(void) self.handlers[WTT_SHADOW] = Widget_UpdateBoxShadow; self.handlers[WTT_BORDER] = Widget_UpdateBorder; self.handlers[WTT_OPACITY] = Widget_UpdateOpacity; + self.handlers[WTT_MARGIN] = Widget_UpdateMargin; self.handlers[WTT_BODY] = HandleBody; self.handlers[WTT_TITLE] = HandleSetTitle; self.handlers[WTT_REFRESH] = HandleRefresh; From 813f87d2949d610f15df148b72422c83f7a571f0 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Thu, 1 Sep 2016 00:25:04 +0800 Subject: [PATCH 120/124] =?UTF-8?q?textview=20=E9=BB=98=E8=AE=A4=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=8D=A2=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gui/widget/textview.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/widget/textview.c b/src/gui/widget/textview.c index 7a49e1e5..933854f1 100644 --- a/src/gui/widget/textview.c +++ b/src/gui/widget/textview.c @@ -312,7 +312,7 @@ static void TextView_UpdateStyle( LCUI_Widget w ) break; case key_white_space: if( !s->is_valid || s->type != SVT_STYLE ) { - TextLayer_SetAutoWrap( txt->layer, FALSE ); + TextLayer_SetAutoWrap( txt->layer, TRUE ); break; } if( s->style == SV_NOWRAP ) { From 82904311a93fad7e8f69cc5e84b64222f3f01877 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Fri, 2 Sep 2016 00:16:34 +0800 Subject: [PATCH 121/124] =?UTF-8?q?=E7=BA=A0=E6=AD=A3=E6=97=A0=E6=95=88?= =?UTF-8?q?=E5=8C=BA=E5=9F=9F=E5=9D=90=E6=A0=87=E8=AE=A1=E7=AE=97=E3=80=81?= =?UTF-8?q?=E8=A1=A5=E5=85=85=E9=83=A8=E4=BB=B6=E7=BC=BA=E7=9C=81=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gui/widget_paint.c | 10 ++++++++-- src/gui/widget_style.c | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/gui/widget_paint.c b/src/gui/widget_paint.c index f34f0fbf..af1c3684 100644 --- a/src/gui/widget_paint.c +++ b/src/gui/widget_paint.c @@ -88,8 +88,8 @@ static void Widget_AdjustArea( LCUI_Widget w, LCUI_Rect *in_rect, out_rect->h = box->h; } else { *out_rect = *in_rect; + LCUIRect_ValidateArea( out_rect, box->w, box->h ); } - LCUIRect_ValidateArea( out_rect, box->w, box->h ); /* 将坐标转换成相对于图像呈现区的坐标 */ out_rect->x += (box->x - w->box.graph.x); out_rect->y += (box->y - w->box.graph.y); @@ -239,14 +239,20 @@ static int _Widget_ProcInvalidArea( LCUI_Widget w, int x, int y, } child_x = child->box.graph.x + x; child_y = child->box.graph.y + y; + child_box = child->box.graph; + /* 部件坐标是相对于内容框的,所以加上内容框XY坐标 */ + child_box.x += w->box.padding.x - w->box.graph.x; + child_box.y += w->box.padding.y - w->box.graph.y; /* 若有效框与子部件没有重叠区域,则不向子级部件递归 */ - if( !LCUIRect_GetOverlayRect( valid_box, &child->box.graph, + if( !LCUIRect_GetOverlayRect( valid_box, &child_box, &child_box ) ) { continue; } /* 转换为相对于子部件的坐标 */ child_box.x -= child->box.graph.x; child_box.y -= child->box.graph.y; + child_box.x -= w->box.padding.x - w->box.graph.x; + child_box.y -= w->box.padding.y - w->box.graph.y; count += _Widget_ProcInvalidArea( child, child_x, child_y, &child_box, rlist ); } diff --git a/src/gui/widget_style.c b/src/gui/widget_style.c index 07663266..c77b5a5d 100644 --- a/src/gui/widget_style.c +++ b/src/gui/widget_style.c @@ -46,12 +46,14 @@ #include #include +/** 部件的缺省样式 */ const char *global_css = ToString( * { width: auto; height: auto; background-color: transparent; + border: 0px solid #000; display: block; position: static; padding: 0; From b0619b4e96aa7a42ce878b33cf32da9a290d80b0 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Thu, 8 Sep 2016 23:07:14 +0800 Subject: [PATCH 122/124] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=9C=A8=E9=83=A8?= =?UTF-8?q?=E4=BB=B6=E6=98=BE=E7=A4=BA/=E9=9A=90=E8=97=8F=E5=90=8E?= =?UTF-8?q?=E7=9A=84=E5=B8=83=E5=B1=80=E6=9B=B4=E6=96=B0=E5=88=A4=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gui/widget_base.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index 5f87d06c..e2c80b54 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -248,13 +248,13 @@ void Widget_ExecDestroy( LCUI_Widget widget ) Widget_ReleaseTouchCapture( widget, -1 ); Widget_StopEventPropagation( widget ); LCUIWidget_ClearEventTarget( widget ); - if( wc && wc->methods.destroy ) { - wc->methods.destroy( widget ); - } /* 先释放显示列表,后销毁部件列表,因为部件在这两个链表中的节点是和它共用 * 一块内存空间的,销毁部件列表会把部件释放掉,所以把这个操作放在后面 */ LinkedList_ClearData( &widget->children_show, NULL ); LinkedList_ClearData( &widget->children, Widget_OnDestroy ); + if( wc && wc->methods.destroy ) { + wc->methods.destroy( widget ); + } LinkedList_Clear( &widget->dirty_rects, free ); StyleSheet_Delete( widget->inherited_style ); StyleSheet_Delete( widget->custom_style ); @@ -603,7 +603,7 @@ void Widget_UpdateVisibility( LCUI_Widget w ) visible = w->computed_style.visible; if( w->parent ) { Widget_PushInvalidArea( w, NULL, SV_GRAPH_BOX ); - if( w->computed_style.display != display && + if( w->computed_style.display != display || w->computed_style.position != SV_ABSOLUTE ) { Widget_UpdateLayout( w->parent ); } @@ -1481,8 +1481,8 @@ void Widget_ExecUpdateLayout( LCUI_Widget w ) ctx.prev = child; ctx.prev_display = child->computed_style.display; } - if( w->style->sheet[key_width].type == SVT_AUTO - || w->style->sheet[key_height].type == SVT_AUTO ) { + if( w->style->sheet[key_width].type == SVT_AUTO || + w->style->sheet[key_height].type == SVT_AUTO ) { Widget_AddTask( w, WTT_RESIZE ); } e.cancel_bubble = TRUE; From bab1131086c91d7a73c9b04565a1ddb60d7277a4 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Thu, 8 Sep 2016 23:10:27 +0800 Subject: [PATCH 123/124] =?UTF-8?q?=E8=A1=A5=E5=85=85=E9=92=88=E5=AF=B9?= =?UTF-8?q?=E5=BE=85=E5=88=A0=E9=99=A4=E7=9A=84=E9=83=A8=E4=BB=B6=E7=9A=84?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gui/widget_event.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/gui/widget_event.c b/src/gui/widget_event.c index e9abd29a..97fd445b 100644 --- a/src/gui/widget_event.c +++ b/src/gui/widget_event.c @@ -583,7 +583,12 @@ static void Widget_UpdateStatus( LCUI_Widget widget, int type ) for( w = new_w; w != root && w; w = w->parent ) { ++depth; } + i = depth; for( w = old_w; w != root && w; w = w->parent ) { + if( w->state == WSTATE_DELETED ) { + depth = i; + old_w = w; + } --depth; } i = depth > 0 ? depth : -depth; @@ -617,9 +622,17 @@ static void Widget_UpdateStatus( LCUI_Widget widget, int type ) void LCUIWidget_ClearEventTarget( LCUI_Widget widget ) { int i; + LCUI_Widget w; for( i = 0; i < WST_TOTAL; ++i ) { - if( !widget || self.targets[i] == widget ) { + if( !widget ) { Widget_UpdateStatus( NULL, i ); + continue; + } + for( w = self.targets[i]; w; w = w->parent ) { + if( w == widget ) { + Widget_UpdateStatus( NULL, i ); + break; + } } } } From ff5a7cb496a7cc583df8066ae6d59161159aed69 Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Thu, 8 Sep 2016 23:11:00 +0800 Subject: [PATCH 124/124] =?UTF-8?q?=E6=9B=B4=E6=96=B0VS=E5=B7=A5=E7=A8=8B?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/VS2012/LCUI/LCUI.vcxproj | 6 +++++- build/VS2012/LCUI/LCUI.vcxproj.filters | 18 +++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/build/VS2012/LCUI/LCUI.vcxproj b/build/VS2012/LCUI/LCUI.vcxproj index 2f69b341..5ffa731c 100644 --- a/build/VS2012/LCUI/LCUI.vcxproj +++ b/build/VS2012/LCUI/LCUI.vcxproj @@ -148,6 +148,7 @@ + @@ -179,12 +180,14 @@ + + @@ -213,6 +216,7 @@ + @@ -244,12 +248,12 @@ $(SolutionDir)include;$(SolutionDir)include\..\..\..\include;%(AdditionalIncludeDirectories) - + diff --git a/build/VS2012/LCUI/LCUI.vcxproj.filters b/build/VS2012/LCUI/LCUI.vcxproj.filters index 8d11fe9f..284f7823 100644 --- a/build/VS2012/LCUI/LCUI.vcxproj.filters +++ b/build/VS2012/LCUI/LCUI.vcxproj.filters @@ -234,6 +234,15 @@ 头文件\LCUI\gui\widget + + 头文件\LCUI\util + + + 头文件\LCUI + + + 头文件\LCUI\gui + @@ -362,9 +371,6 @@ 源文件 - - 源文件\util - 源文件\util @@ -404,6 +410,12 @@ 源文件 + + 源文件\util + + + 源文件\gui +