FtkWidget* ftk_wait_box_create(FtkWidget* parent, int x, int y, int w, int h) { FtkWidget* thiz = (FtkWidget*)FTK_ZALLOC(sizeof(FtkWidget)); return_val_if_fail(thiz != NULL, NULL); thiz->priv_subclass[0] = (PrivInfo*)FTK_ZALLOC(sizeof(PrivInfo)); if(thiz->priv_subclass[0] != NULL) { int w = 0; DECL_PRIV0(thiz, priv); thiz->on_event = ftk_wait_box_on_event; thiz->on_paint = ftk_wait_box_on_paint; thiz->destroy = ftk_wait_box_destroy; priv->bitmap = ftk_theme_load_image(ftk_default_theme(), "wait_box"FTK_STOCK_IMG_SUFFIX); assert(priv->bitmap != NULL); w = ftk_bitmap_width(priv->bitmap); ftk_widget_init(thiz, FTK_WAIT_BOX, 0, x, y, w, w, FTK_ATTR_TRANSPARENT|FTK_ATTR_INSENSITIVE); ftk_widget_set_attr(thiz, FTK_ATTR_TRANSPARENT|FTK_ATTR_INSENSITIVE); priv->timer = ftk_source_timer_create(500, (FtkTimer)ftk_widget_invalidate, thiz); ftk_widget_append_child(parent, thiz); } else { FTK_FREE(thiz); } return thiz; }
int ftk_progress_bar_get_percent(FtkWidget* thiz) { DECL_PRIV0(thiz, priv); return_val_if_fail(thiz != NULL, 0); return priv->percent; }
static FtkKeyBoardCell* ftk_key_board_find_cell(FtkWidget* thiz, size_t x, size_t y) { size_t r = 0; size_t c = 0; DECL_PRIV0(thiz, priv); FtkKeyBoardRow* row = NULL; FtkKeyBoardCell* cell = NULL; FtkKeyBoardView* view = priv->desc->views + priv->desc->current_view; for(r = 0; r < view->row_nr; r++) { row = view->rows + r; if(y < row->y || y >= (row->y + row->height)) continue; for(c = 0; c < row->cell_nr; c++) { cell = row->cells + c; if(x >= cell->x && x < (cell->x + cell->width)) { return cell; } } } return NULL; }
Ret ftk_progress_bar_set_interactive(FtkWidget* thiz, int interactive) { DECL_PRIV0(thiz, priv); return_val_if_fail(thiz != NULL, RET_FAIL); priv->interactive = interactive; if(interactive) { if(priv->bg == NULL) { priv->bg = ftk_theme_load_image(ftk_default_theme(), "progressbar_i_bg"FTK_STOCK_IMG_SUFFIX); } if(priv->cursor == NULL) { priv->cursor = ftk_theme_load_image(ftk_default_theme(), "progressbar_i_cursor"FTK_STOCK_IMG_SUFFIX); } thiz->on_event = ftk_progress_bar_on_event_interactive; thiz->on_paint = ftk_progress_bar_on_paint_interactive; } else { thiz->on_event = ftk_progress_bar_on_event; thiz->on_paint = ftk_progress_bar_on_paint; } ftk_widget_set_insensitive(thiz, !interactive); return RET_OK; }
FtkWidget* ftk_scroll_bar_create(FtkWidget* parent, int x, int y, int width, int height) { FtkWidget* thiz = (FtkWidget*)FTK_ZALLOC(sizeof(FtkWidget)); return_val_if_fail(thiz != NULL, NULL); thiz->priv_subclass[0] = (PrivInfo*)FTK_ZALLOC(sizeof(PrivInfo)); if(thiz != NULL) { DECL_PRIV0(thiz, priv); thiz->on_event = ftk_scroll_bar_on_event; thiz->on_paint = ftk_scroll_bar_on_paint; thiz->destroy = ftk_scroll_bar_destroy; if(width < height) { /*vertical*/ priv->vertical = 1; priv->bitmap = ftk_theme_load_image(ftk_default_theme(), "scrollbar_handle_vertical"FTK_STOCK_IMG_SUFFIX); } else { priv->vertical = 0; priv->bitmap = ftk_theme_load_image(ftk_default_theme(), "scrollbar_handle_horizontal"FTK_STOCK_IMG_SUFFIX); } ftk_widget_init(thiz, width < height ? FTK_SCROLL_VBAR : FTK_SCROLL_HBAR, 0, x, y, width, height, FTK_ATTR_TRANSPARENT); ftk_widget_append_child(parent, thiz); } return thiz; }
static Ret ftk_key_board_on_event(FtkWidget* thiz, FtkEvent* event) { Ret ret = RET_OK; DECL_PRIV0(thiz, priv); switch(event->type) { case FTK_EVT_MOUSE_MOVE: case FTK_EVT_MOUSE_DOWN: case FTK_EVT_MOUSE_UP: { size_t x = event->u.mouse.x; size_t y = event->u.mouse.y; ret = ftk_key_board_on_mouse_event(thiz, event->type, x, y); break; } case FTK_EVT_RESIZE: case FTK_EVT_MOVE_RESIZE: { ftk_key_board_desc_layout(priv->desc, ftk_widget_width(thiz), ftk_widget_height(thiz)); break; } default:break; } return ret; }
int ftk_check_button_get_checked(FtkWidget* thiz) { DECL_PRIV0(thiz, priv); return_val_if_fail(thiz != NULL, 0); return priv->checked; }
FtkWidget* ftk_check_button_create_ex(FtkWidget* parent, int x, int y, int width, int height, int radio) { FtkWidget* thiz = (FtkWidget*)FTK_ZALLOC(sizeof(FtkWidget)); return_val_if_fail(thiz != NULL, NULL); thiz->priv_subclass[0] = (PrivInfo*)FTK_ZALLOC(sizeof(PrivInfo)); if(thiz->priv_subclass[0] != NULL) { DECL_PRIV0(thiz, priv); priv->is_radio = radio; thiz->on_event = ftk_check_button_on_event; thiz->on_paint = ftk_check_button_on_paint; thiz->destroy = ftk_check_button_destroy; ftk_widget_init(thiz, radio ? FTK_RADIO_BUTTON : FTK_CHECK_BUTTON, 0, x, y, width, height, FTK_ATTR_TRANSPARENT); ftk_widget_append_child(parent, thiz); } else { FTK_FREE(thiz); } return thiz; }
int ftk_scroll_bar_get_max_value(FtkWidget* thiz) { DECL_PRIV0(thiz, priv); return_val_if_fail(priv != NULL, 0); return priv->max_value; }
static Ret ftk_progress_bar_on_paint_interactive(FtkWidget* thiz) { int ox = 0; int oy = 0; DECL_PRIV0(thiz, priv); FTK_BEGIN_PAINT(x, y, width, height, canvas); return_val_if_fail(thiz != NULL, RET_FAIL); oy = y + FTK_HALF(height - ftk_bitmap_height(priv->bg)); ftk_canvas_draw_bg_image(canvas, priv->bg, FTK_BG_FOUR_CORNER, x, oy, width, ftk_bitmap_height(priv->bg)); ox = x + width * priv->percent / 100 - FTK_HALF(ftk_bitmap_width(priv->cursor)); oy = y + FTK_HALF(height) - FTK_HALF(ftk_bitmap_height(priv->cursor)); if(ox < x) { ox = x; } if(ox > (x + width - ftk_bitmap_width(priv->cursor))) { ox = x + width - ftk_bitmap_width(priv->cursor); } ftk_canvas_draw_bitmap_simple(canvas, priv->cursor, 0, 0, ftk_bitmap_width(priv->cursor), ftk_bitmap_height(priv->cursor), ox, oy); FTK_END_PAINT(); }
Ret ftk_scroll_bar_pagedown(FtkWidget* thiz) { int value = 0; DECL_PRIV0(thiz, priv); return_val_if_fail(priv != NULL, RET_FAIL); value = priv->value + priv->page_delta; return ftk_scroll_bar_set_value(thiz, value); }
static Ret clocks_rtc_get_time(Clocks *thiz, Datetime *date_time) { return_val_if_failed(thiz != NULL && date_time != NULL, RET_INVALID_PARAMETER); if(thiz->priv_subclass[0]) { DECL_PRIV0(thiz, priv0); RtcTimeConversionDateTime(priv0->rtc_time, date_time) }
Ret ftk_key_board_set_custom_action(FtkWidget* thiz, FtkKeyBoardCellAction action) { DECL_PRIV0(thiz, priv); return_val_if_fail(priv != NULL && priv->desc != NULL, RET_FAIL); priv->desc->custom_action = action; return RET_OK; }
Ret ftk_key_board_set_editor(FtkWidget* thiz, FtkWidget* editor) { DECL_PRIV0(thiz, priv); return_val_if_fail(priv != NULL && priv->desc != NULL, RET_FAIL); priv->editor = editor; return RET_OK; }
Ret ftk_key_board_reset_candidates(FtkWidget* thiz) { DECL_PRIV0(thiz, priv); return_val_if_fail(priv != NULL && priv->desc != NULL, RET_FAIL); priv->desc->candidate_nr = 0; priv->desc->candidate_focus = -1; return RET_OK; }
Ret ftk_key_board_select_view(FtkWidget* thiz, size_t index) { DECL_PRIV0(thiz, priv); return_val_if_fail(priv != NULL && priv->desc != NULL, RET_FAIL); return_val_if_fail(index < priv->desc->view_nr, RET_FAIL); priv->desc->current_view = index; return RET_OK; }
static void ftk_painter_destroy(FtkWidget* thiz) { if(thiz != NULL) { DECL_PRIV0(thiz, priv); FTK_ZFREE(priv, sizeof(PrivInfo)); } return; }
Ret ftk_scroll_bar_set_listener(FtkWidget* thiz, FtkListener listener, void* ctx) { DECL_PRIV0(thiz, priv); return_val_if_fail(priv != NULL, RET_FAIL); priv->listener = listener; priv->listener_ctx = ctx; return RET_OK; }
Ret ftk_wait_box_stop_waiting(FtkWidget* thiz) { DECL_PRIV0(thiz, priv); return_val_if_fail(priv != NULL, RET_FAIL); return_val_if_fail(priv->waiting, RET_FAIL); priv->waiting = 0; return ftk_main_loop_remove_source(ftk_default_main_loop(), priv->timer); }
static void ftk_menu_item_destroy(FtkWidget* thiz) { if(thiz != NULL) { DECL_PRIV0(thiz, priv); FTK_FREE(priv); } return; }
Ret ftk_menu_item_set_clicked_listener(FtkWidget* thiz, FtkListener listener, void* ctx) { DECL_PRIV0(thiz, priv); return_val_if_fail(thiz != NULL, RET_FAIL); priv->listener_ctx = ctx; priv->listener = listener; return RET_OK; }
static Ret ftk_painter_on_paint(FtkWidget* thiz) { DECL_PRIV0(thiz, priv); if(priv->listener != NULL) { priv->listener(priv->listener_ctx, thiz); } return RET_OK; }
Ret ftk_scroll_bar_set_bitmap(FtkWidget* thiz, FtkBitmap* bitmap) { DECL_PRIV0(thiz, priv); return_val_if_fail(priv != NULL, RET_FAIL); ftk_bitmap_unref(priv->bitmap); priv->bitmap = bitmap; ftk_bitmap_ref(priv->bitmap); return RET_OK; }
static void ftk_scroll_bar_destroy(FtkWidget* thiz) { if(thiz != NULL) { DECL_PRIV0(thiz, priv); ftk_bitmap_unref(priv->bitmap); FTK_ZFREE(priv, sizeof(PrivInfo)); } return; }
static void ftk_key_board_destroy(FtkWidget* thiz) { if(thiz != NULL) { DECL_PRIV0(thiz, priv); ftk_key_board_desc_destroy(priv->desc); FTK_ZFREE(priv, sizeof(PrivInfo)); } return; }
Ret ftk_wait_box_start_waiting(FtkWidget* thiz) { DECL_PRIV0(thiz, priv); return_val_if_fail(priv != NULL, RET_FAIL); return_val_if_fail(!priv->waiting, RET_FAIL); priv->offset = 0; priv->waiting = 1; ftk_source_ref(priv->timer); return ftk_main_loop_add_source(ftk_default_main_loop(), priv->timer); }
static void ftk_check_button_destroy(FtkWidget* thiz) { if(thiz != NULL) { DECL_PRIV0(thiz, priv); ftk_bitmap_unref(priv->onimg); ftk_bitmap_unref(priv->offimg); FTK_ZFREE(priv, sizeof(PrivInfo)); } return; }
static Ret ftk_check_button_on_paint(FtkWidget* thiz) { int dx = 0; int dy = 0; int icon_w = 0; int icon_h = 0; FtkBitmap* bitmap = NULL; DECL_PRIV0(thiz, priv); const char** bg_imgs = NULL; FTK_BEGIN_PAINT(x, y, width, height, canvas); if (priv->onimg && priv->offimg) { if (priv->checked) bitmap = priv->onimg; else bitmap = priv->offimg; } else { // orignal code if(priv->is_radio) { bg_imgs = priv->checked ? radio_bg_on_imgs : radio_bg_off_imgs; } else { bg_imgs = priv->checked ? check_bg_on_imgs : check_bg_off_imgs; } bitmap = ftk_theme_load_image(ftk_default_theme(), bg_imgs[ftk_widget_state(thiz)]); } return_val_if_fail(bitmap != NULL, RET_FAIL); icon_w = ftk_bitmap_width(bitmap); icon_h = ftk_bitmap_height(bitmap); assert((icon_w) <= width && icon_h <= height); dy = (height - icon_h) / 2; dx = priv->icon_at_right ? width - icon_w : 0; ftk_canvas_draw_bitmap_simple(canvas, bitmap, 0, 0, icon_w, icon_h, x + dx, y + dy); if (NULL == priv->onimg) ftk_bitmap_unref(bitmap); if(ftk_widget_get_text(thiz) != NULL) { dy = height/2; dx = priv->icon_at_right ? 2 : icon_w; ftk_canvas_set_gc(canvas, ftk_widget_get_gc(thiz)); ftk_canvas_draw_string(canvas, x + dx, y + dy, ftk_widget_get_text(thiz), -1, 1); } FTK_END_PAINT(); }
static Ret ftk_check_button_on_event(FtkWidget* thiz, FtkEvent* event) { Ret ret = RET_OK; DECL_PRIV0(thiz, priv); switch(event->type) { case FTK_EVT_MOUSE_DOWN: { ftk_widget_set_active(thiz, 1); ftk_window_grab(ftk_widget_toplevel(thiz), thiz); break; } case FTK_EVT_MOUSE_UP: { int x = event->u.mouse.x; int y = event->u.mouse.y; if(ftk_widget_is_active(thiz)) { ftk_widget_set_active(thiz, 0); ftk_window_ungrab(ftk_widget_toplevel(thiz), thiz); if(FTK_POINT_IN_WIDGET(x, y, thiz)) { ret = FTK_CALL_LISTENER(priv->listener, priv->listener_ctx, thiz); ftk_check_button_check(thiz); } } break; } case FTK_EVT_KEY_DOWN: { if(FTK_IS_ACTIVE_KEY(event->u.key.code)) { ftk_widget_set_active(thiz, 1); } break; } case FTK_EVT_KEY_UP: { if(FTK_IS_ACTIVE_KEY(event->u.key.code) && ftk_widget_is_active(thiz)) { ftk_widget_set_active(thiz, 0); ftk_check_button_check(thiz); ret = FTK_CALL_LISTENER(priv->listener, priv->listener_ctx, thiz); } break; } default:break; } return ret; }
Ret ftk_check_button_set_checked(FtkWidget* thiz, int checked) { DECL_PRIV0(thiz, priv); return_val_if_fail(thiz != NULL, RET_FAIL); if(priv->checked != checked) { priv->checked = checked; ftk_widget_invalidate(thiz); } return RET_OK; }