void text_line_subscribe_scrollbar(struct widget* subscriber, struct widget* pulisher, si_t event) { struct text_line* t = TEXT_LINE_POINTER(subscriber); struct scroll_bar* s = SCROLL_BAR_POINTER(pulisher); si_t lineno_cur = text_line_get_line_cur(t); si_t lines_per_page = text_line_get_max_line_shown(t); switch(event) { /** * press up arrow **/ case SCROLL_BAR_EVENT_LINE_UP: text_line_update_ruler_line(t, lineno_cur - 1); break; /** * press down arow **/ case SCROLL_BAR_EVENT_LINE_DOWN: text_line_update_ruler_line(t, lineno_cur + 1); break; /** * press spaces above elevator **/ case SCROLL_BAR_EVENT_PAGE_UP: text_line_update_ruler_line(t, lineno_cur - lines_per_page); break; /** * press spaces below elevator **/ case SCROLL_BAR_EVENT_PAGE_DOWN: text_line_update_ruler_line(t, lineno_cur + lines_per_page); break; /** * move elevator **/ case SCROLL_BAR_EVENT_CHANGE: text_line_update_ruler_line(t, s->cur_offset / s->line_height); break; default: return; break; } text_line_repaint(t); text_line_show(t); }
struct text_line* text_line_init(si_t bufsize, si_t cur_line) { struct text_line* addr; /* 分配存储空间 */ if((addr = (struct text_line*)malloc(sizeof(struct text_line))) == NULL) { EGUI_PRINT_SYS_ERROR("fail to malloc"); return NULL; } /* 申请图形设备 */ addr->gd = graphics_device_init(0, 0, 0, 0, 0, 0 ,0 ,0 ,0); /* 申请失败 */ if(addr->gd == 0) { /* 释放存储空间 */ free(addr); return NULL; } /* struct text_line 的成员 */ addr->parent = NULL; addr->lchild = NULL; addr->rchild = NULL; addr->name = "struct text_line"; addr->id = 0; /* 默认是否能处理键盘输入消息 */ addr->input_enable = 1; /* 默认是否可以刷新 */ addr->update_enable = 1; /* 默认是否可见 */ addr->visible = 1; /* 默认是否拥有键盘焦点*/ addr->keybd_focus = 0; /* 默认是否是窗口 */ addr->is_window = 0; /* 用全局样式对象初始化text_line样式 */ text_line_init_with_default_style(addr); /* 默认的回调函数 */ addr->callback = text_line_default_callback; /** * for text_line **/ /** * default set buf to null **/ addr->buf = NULL; addr->buf_size = 0; /** * default keyboad type **/ addr->keybd_type = TEXT_LINE_KEYBOARD_TYPE_NUMBER | TEXT_LINE_KEYBOARD_TYPE_LETTER; /** * default pointer to NULL **/ addr->ruler_cur = NULL; addr->ruler_line_start = NULL; addr->show_start = NULL; /** * default single line **/ addr->is_linewrap = 0; addr->is_enter_enable = 0; addr->placeholder = NULL; /** * default handler **/ list_init(&addr->subscribe_info_list); text_line_set_bufsize(addr, bufsize); text_line_update_ruler_line(addr, cur_line); return addr; }