/** 设置窗口主题色 */ LCUI_API void Window_SetThemeColor( LCUI_Widget *window, LCUI_Color color ) { LCUI_Window *wnd; wnd = (LCUI_Window*)Widget_GetPrivateData( window ); wnd->theme_color = color; Widget_Update( window ); }
static void Window_OnUpdate( LCUI_Widget *window ) { LCUI_Window *wnd; LCUI_Border border; char h_str[20]; wnd = (LCUI_Window*)Widget_GetPrivateData( window ); border = Border( 1, BORDER_STYLE_SOLID, RGB(200,200,200) ); border.top_width = TOP_PANDDING; /* 若窗口已获得焦点 */ if( Widget_GetFocus( window ) ) { border.top_color = wnd->theme_color; border.bottom_color = wnd->theme_color; border.left_color = wnd->theme_color; border.right_color = wnd->theme_color; Widget_SetShadow( window, BoxShadow(0,0,8,wnd->theme_color) ); } else { Widget_SetShadow( window, BoxShadow(0,0,8,ARGB(120,200,200,200)) ); } Widget_SetBorder( window, border ); /* 更新窗口标题栏上的关闭按钮 */ Widget_Update( wnd->btn_close ); sprintf( h_str, "%dpx", Widget_GetContainerHeight(window)-35 ); Widget_SetSize( wnd->client_area, "100%", h_str ); }
/* 在窗口获得焦点时会调用此函数 */ static void Window_FocusIn( LCUI_Widget *window, LCUI_WidgetEvent *unused ) { //_DEBUG_MSG( "%p, Window_FocusIn!\n",window ); Widget_Front( window ); /* 前置窗口 */ Widget_Update( window ); /* 更新窗口 */ }
ScrollBar_SetCurrentSize( LCUI_Widget *widget, int current_size ) { LCUI_ScrollBar *scrollbar; scrollbar = Widget_GetPrivData( widget ); scrollbar->data.current_size = current_size; Widget_Update( widget ); }
ScrollBar_SetCurrentValue( LCUI_Widget *widget, int current_num ) { LCUI_ScrollBar *scrollbar; scrollbar = Widget_GetPrivData( widget ); scrollbar->data.current_num = current_num; Widget_Update( widget ); }
ScrollBar_SetMaxSize( LCUI_Widget *widget, int max_size ) { LCUI_ScrollBar *scrollbar; scrollbar = Widget_GetPrivData( widget ); scrollbar->data.max_size = max_size; Widget_Update( widget ); }
ScrollBar_SetMaxNum( LCUI_Widget *widget, int max_num ) { LCUI_ScrollBar *scrollbar; scrollbar = Widget_GetPrivData( widget ); scrollbar->data.max_num = max_num; Widget_Update( widget ); }
TextBox_Text_SetPasswordChar( LCUI_Widget *widget, wchar_t ch ) /* 为文本框设置屏蔽字符 */ { LCUI_TextLayer *layer; layer = TextBox_GetTextLayer( widget ); TextLayer_Text_SetPasswordChar( layer, ch ); TextLayer_Refresh( layer ); Widget_Update( widget ); }
TextBox_TextLayer_SetOffset( LCUI_Widget *widget, LCUI_Pos offset_pos ) /* 为文本框内的文本图层设置偏移 */ { LCUI_TextLayer *layer; layer = TextBox_GetTextLayer( widget ); if( TextLayer_SetOffset( layer, offset_pos ) == 0 ) { Widget_Update( widget ); } /* 需要更新光标的显示位置 */ TextBox_Cursor_Update( widget ); }
ScrollBar_SetDirection( LCUI_Widget *widget, int direction ) { LCUI_ScrollBar *scrollbar; scrollbar = Widget_GetPrivData( widget ); if(direction == 0) { /* 纵向 */ scrollbar->direction = 0; } else { /* 横向 */ scrollbar->direction = 1; } Widget_Update( widget ); }
TextBox_Text_Backspace(LCUI_Widget *widget, int n) /* 删除光标左边处n个字符 */ { LCUI_Pos cur_pos; LCUI_TextLayer *layer; layer = TextBox_GetTextLayer( widget ); TextLayer_Text_Backspace( layer, n ); cur_pos = TextLayer_Cursor_GetPos( layer ); TextBox_Cursor_Move( widget, cur_pos ); Widget_Update( widget ); return 0; }
int Widget_Update(LCUI_Widget w) { int i; LCUI_BOOL *buffer; LinkedListNode *node, *next; /* 如果该部件没有任务需要处理 */ if (!w->task.for_self) { goto proc_children_task; } w->task.for_self = FALSE; buffer = w->task.buffer; /* 如果有用户自定义任务 */ if (buffer[LCUI_WTASK_USER] && w->proto && w->proto->runtask) { w->proto->runtask(w); } for (i = 0; i < LCUI_WTASK_USER; ++i) { if (buffer[i]) { buffer[i] = FALSE; if (self.handlers[i]) { self.handlers[i](w); } } else { buffer[i] = FALSE; } } Widget_AddState(w, LCUI_WSTATE_UPDATED); 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_Update(child)) { w->task.for_children = TRUE; } node = next; } return w->task.for_self || w->task.for_children; }
void LCUIWidget_Update(void) { int count = 0; LCUI_Widget root; /* 前两次更新需要主动刷新所有部件的样式,主要是为了省去在应用程序里手动调用 * LCUIWidget_RefreshStyle() 的麻烦 */ if (self.update_count < 2) { LCUIWidget_RefreshStyle(); self.update_count += 1; } root = LCUIWidget_GetRoot(); while (Widget_Update(root) && count++ < 5); LCUIWidget_ClearTrash(); }
int TestCSSParser(void) { LCUI_Widget box, btn, text; box = LCUIBuilder_LoadFile( "test_css_parser.xml" ); if( !box ) { return -1; } text = LCUIWidget_GetById( "test-textview" ); Widget_UpdateStyle( text, TRUE ); Widget_Update( text ); assert( text->style->sheet[key_width].val_px == 100 ); assert( text->style->sheet[key_height].val_px == 60 ); assert( text->style->sheet[key_position].val_style == SV_ABSOLUTE ); assert( text->style->sheet[key_top].val_px == 12 ); assert( text->style->sheet[key_left].val_px == 20 ); btn = LCUIWidget_GetById( "test-btn" ); Widget_AddStatus( btn, "hover" ); Widget_UpdateStyle( btn, TRUE ); Widget_UpdateStyle( text, TRUE ); Widget_Update( text ); assert( text->style->sheet[key_background_color].val_color.value == 0xffff0000 ); assert( text->style->sheet[key_background_size].val_style == SV_CONTAIN ); return 0; }
TextBox_Text_AppendW( LCUI_Widget *widget, wchar_t *unicode_text ) { LCUI_TextBox *tb; LCUI_TextLayer *layer; tb = Widget_GetPrivData( widget ); TextBox_TextBuff_Add( widget, unicode_text, AT_TEXT_LAST ); if( tb->show_placeholder ) { layer = TextBox_GetTextLayer( widget ); TextLayer_Text_Clear( layer ); TextLayer_Text_SetPasswordChar( layer, tb->password_char_bak ); TextLayer_Text_SetDefaultStyle( layer, tb->textstyle_bak ); tb->show_placeholder = FALSE; } Widget_Update( widget ); }
TextBox_Text_AddW( LCUI_Widget *widget, wchar_t *unicode_text ) { LCUI_TextBox *tb; LCUI_TextLayer *layer; tb = Widget_GetPrivData( widget ); /* 把文本分割成若干块,加入至缓冲队列,让文本框分段处理显示 */ TextBox_TextBuff_Add( widget, unicode_text, AT_CURSOR_POS ); if( tb->show_placeholder ) { layer = TextBox_GetTextLayer( widget ); TextLayer_Text_Clear( layer ); TextLayer_Text_SetPasswordChar( layer, tb->password_char_bak ); TextLayer_Text_SetDefaultStyle( layer, tb->textstyle_bak ); tb->show_placeholder = FALSE; } Widget_Update( widget ); }
TextBox_TextW( LCUI_Widget *widget, wchar_t *unicode_text ) { LCUI_TextBox *tb; LCUI_TextLayer *layer; TextBox_Text_Clear( widget ); /* 清空显示的文本 */ tb = Widget_GetPrivData( widget ); /* 把文本分割成块,加入至缓冲队列,让文本框分段显示 */ TextBox_TextBuff_Add( widget, unicode_text, AT_TEXT_LAST ); if( tb->show_placeholder ) { layer = TextBox_GetTextLayer( widget ); tb->show_placeholder = FALSE; /* 恢复文本框的文本样式以及屏蔽符 */ TextLayer_Text_SetPasswordChar( layer, tb->password_char_bak ); TextLayer_Text_SetDefaultStyle( layer, tb->textstyle_bak ); } Widget_Update( widget ); }
static void Window_ExecUpdate( LCUI_Widget *win_p ) { LCUI_Size size; LCUI_Graph *graph; LCUI_Border border; LCUI_Widget *titlebar, *btn, *client_area; LCUI_RGB border_color, back_color; btn = Window_GetCloseButton(win_p); titlebar = Window_GetTitleBar(win_p); client_area = Window_GetClientArea(win_p); graph = Widget_GetSelfGraph( win_p ); /* 按不同的风格来处理 */ switch( win_p->style_id ) { case WINDOW_STYLE_NONE: /* 没有边框 */ /* 先计算坐标和尺寸 */ Widget_SetDock( client_area, DOCK_TYPE_FILL ); Widget_Hide( titlebar );/* 隐藏标题栏 */ Widget_Show( client_area );/* 客户区需要显示 */ break; case WINDOW_STYLE_LINE: /* 线条边框 */ Widget_SetBorder(win_p, Border(1, BORDER_STYLE_SOLID, RGB(50,50,50))); Widget_SetPadding( win_p, Padding(1,1,1,1) ); Widget_SetDock( client_area, DOCK_TYPE_FILL ); Widget_Hide( titlebar ); Widget_Show( client_area ); break; case WINDOW_STYLE_PURE_BLUE: back_color = RGB(30,160,225); border_color = RGB(0,130,195); goto union_draw_method; case WINDOW_STYLE_PURE_GREEN: back_color = RGB(140,190,40); border_color = RGB(110,160,10); goto union_draw_method; case WINDOW_STYLE_PURE_RED: back_color = RGB(230,20,0); border_color = RGB(200,0,0); goto union_draw_method; case WINDOW_STYLE_PURE_ORANGE: back_color = RGB(240,150,10); border_color = RGB(210,120,0); goto union_draw_method; case WINDOW_STYLE_PURE_PURPLE: back_color = RGB(110,20,95); border_color = RGB(80,0,65); union_draw_method:; /* 若窗口未获得焦点 */ if( !Widget_GetFocus( win_p ) ) { back_color = RGB(235,235,235); border_color = RGB(211,211,211); } /* 更新窗口标题栏上的关闭按钮 */ Widget_Update( btn ); border = Border(1, BORDER_STYLE_SOLID, border_color); Widget_SetBorder( client_area, border); Widget_SetBorder( win_p, border); Widget_SetBackgroundColor( win_p, back_color ); Graph_FillColor( graph, back_color ); Widget_SetBackgroundColor( client_area, RGB(255,255,255) ); Widget_SetBackgroundImage( titlebar, NULL ); Widget_SetBackgroundLayout( titlebar, 0 ); Widget_SetBackgroundTransparent( titlebar, TRUE ); Widget_SetBackgroundTransparent( client_area, FALSE ); Widget_SetPadding( win_p, Padding(1,4,4,4) ); Widget_SetPadding( client_area, Padding(1,1,1,1) ); size = Widget_GetContainerSize( win_p ); Widget_Resize( titlebar, Size(size.h, 25) ); Widget_Resize( client_area, Size(size.w, size.h - 25) ); Widget_SetDock( titlebar, DOCK_TYPE_TOP ); Widget_SetDock( client_area, DOCK_TYPE_BOTTOM ); Widget_Show( titlebar ); Widget_Show( client_area ); break; default: // break; } }
/** 在窗口获得焦点时会调用此函数 */ static void Window_OnFocusIn( LCUI_Widget window, LCUI_WidgetEvent *unused ) { //_DEBUG_MSG( "%p, Window_FocusIn!\n",window ); Widget_Front( window ); Widget_Update( window ); }
/** 在窗口失去焦点时会调用此函数 */ static void Window_OnFocusOut( LCUI_Widget *window, LCUI_WidgetEvent *unused ) { Widget_Update( window ); }
/* 在窗口失去焦点时会调用此函数 */ static void Window_FocusOut( LCUI_Widget *window, LCUI_WidgetEvent *unused ) { //_DEBUG_MSG( "%p, Window_FocusOut!\n", window ); Widget_Update( window ); }
static void Button_ProcFocusOut( LCUI_Widget *widget, LCUI_WidgetEvent *unused ) { Widget_Update( widget ); }