static Ret ftk_key_board_on_mouse_event(FtkWidget* thiz, FtkEventType event, size_t x, size_t y) { DECL_PRIV0(thiz, priv); FtkKeyBoardCell* cell = NULL; FtkKeyBoardDesc* desc = priv->desc; FtkKeyBoardView* view = desc->views + desc->current_view; x -= ftk_widget_left_abs(thiz); y -= ftk_widget_top_abs(thiz); view->last_click_pos.x = x; view->last_click_pos.y = y; cell = ftk_key_board_find_cell(thiz, x, y); if(cell == NULL) { return RET_OK; } if(cell->action == ftk_key_board_candidate_text) { size_t i = 0; size_t x_c = cell->x; for(i = desc->candidate_start; i < desc->candidate_nr; i++) { FtkKeyBoardCandidate* candidate = desc->candidates+i; if(x >= x_c && x < (x_c + candidate->extent)) { desc->candidate_focus = i; ftk_logd("%s:%d on %s\n", __func__, __LINE__, candidate->text); break; } x_c += candidate->extent + desc->candidate_space; } ftk_widget_invalidate(thiz); } switch(event) { case FTK_EVT_MOUSE_DOWN: { view->focus = cell; ftk_window_grab(ftk_widget_toplevel(thiz), thiz); break; } case FTK_EVT_MOUSE_UP: { if(cell->action != NULL) { cell->action(thiz, cell); } view->focus = NULL; desc->candidate_focus = -1; ftk_window_ungrab(ftk_widget_toplevel(thiz), thiz); } default: { if(view->focus == cell) { return RET_OK; } if(view->focus != NULL) { view->focus = cell; } } } if(cell->action != NULL) { ftk_widget_invalidate(thiz); } return RET_OK; }
static Ret ftk_scroll_bar_on_paint(FtkWidget* thiz) { int i = 0; int dx = 0; int dy = 0; int fill_size = 0; int half_size = 0; int bitmap_width = 0; int bitmap_height = 0; DECL_PRIV0(thiz, priv); FTK_BEGIN_PAINT(x, y, width, height, canvas); return_val_if_fail(priv->bitmap != NULL, RET_FAIL); bitmap_width = ftk_bitmap_width(priv->bitmap); bitmap_height = ftk_bitmap_height(priv->bitmap); if(priv->vertical) { priv->tracker_size = height * priv->page_delta/priv->max_value; priv->tracker_size = priv->tracker_size < bitmap_height ? bitmap_height : priv->tracker_size; dy = height * priv->value / priv->max_value; dy = (dy + priv->tracker_size) < height ? dy : height - priv->tracker_size; priv->tracker_pos = dy + ftk_widget_top_abs(thiz); fill_size = priv->tracker_size - bitmap_height; dx += x; dy += y; half_size = bitmap_height/2; ftk_canvas_draw_bitmap_simple(canvas, priv->bitmap, 0, 0, bitmap_width, half_size, dx, dy); for(i = 0; i < fill_size; i++) { ftk_canvas_draw_bitmap_simple(canvas, priv->bitmap, 0, half_size, bitmap_width, 1, dx, dy + i + half_size); } ftk_canvas_draw_bitmap_simple(canvas, priv->bitmap, 0, half_size, bitmap_width, half_size, dx, dy + half_size + fill_size); } else { priv->tracker_size = width * priv->page_delta/priv->max_value; priv->tracker_size = priv->tracker_size < bitmap_width ? bitmap_width : priv->tracker_size; dx = width * priv->value / priv->max_value; dx = (dx + priv->tracker_size) < width ? dx : width - priv->tracker_size; priv->tracker_pos = dx + ftk_widget_left_abs(thiz); fill_size = priv->tracker_size - bitmap_width; dy += y; dx += x; half_size = bitmap_width/2; ftk_canvas_draw_bitmap_simple(canvas, priv->bitmap, 0, 0, half_size, bitmap_height, dx, dy); for(i = 0; i < fill_size; i++) { ftk_canvas_draw_bitmap_simple(canvas, priv->bitmap, half_size, 0, 1, bitmap_height, dx + i + half_size, dy); } ftk_canvas_draw_bitmap_simple(canvas, priv->bitmap, half_size, 0, half_size, bitmap_height, dx + fill_size + half_size, dy); } FTK_END_PAINT(); }
static Ret ftk_wnd_manager_default_relayout_one(FtkWndManager* thiz, FtkWidget* window) { int x = 0; int y = 0; int w = 0; int h = 0; int work_area_h = 0; FtkEvent event; return_val_if_fail(thiz != NULL && window != NULL, RET_FAIL); work_area_h = ftk_display_height(ftk_default_display()) - ftk_wnd_manager_get_status_bar_height(thiz); /*XXX: we assume panel is added as first window*/ switch(ftk_widget_type(window)) { case FTK_WINDOW: { w = ftk_display_width(ftk_default_display()); h = ftk_display_height(ftk_default_display()); if(!ftk_window_is_fullscreen(window)) { h -= ftk_wnd_manager_get_status_bar_height(thiz); y = ftk_wnd_manager_get_status_bar_height(thiz); } break; } case FTK_DIALOG: { if(ftk_widget_has_attr(window, FTK_ATTR_AUTO_LAYOUT)) { x = FTK_DIALOG_MARGIN; w = ftk_display_width(ftk_default_display()) - FTK_DIALOG_MARGIN * 2; h = work_area_h < ftk_widget_height(window) ? work_area_h : ftk_widget_height(window); y = (work_area_h - h) / 2; if(!ftk_wnd_manager_default_has_fullscreen_win(thiz)) { y += ftk_wnd_manager_get_status_bar_height(thiz); } } else { x = ftk_widget_left_abs(window); y = ftk_widget_top_abs(window); w = ftk_widget_width(window); h = ftk_widget_height(window); } break; } case FTK_STATUS_PANEL: { ftk_event_init(&event, FTK_EVT_MAP); event.widget = window; ftk_wnd_manager_dispatch_event(thiz, &event); w = ftk_display_width(ftk_default_display()); h = FTK_STATUS_PANEL_HEIGHT; break; } case FTK_MENU_PANEL: { ftk_event_init(&event, FTK_EVT_MAP); event.widget = window; ftk_wnd_manager_dispatch_event(thiz, &event); w = ftk_display_width(ftk_default_display()); h = ftk_widget_height(window); x = 0; y = ftk_display_height(ftk_default_display()) - h; break; } default: { x = ftk_widget_left_abs(window); y = ftk_widget_top_abs(window); w = ftk_widget_width(window); h = ftk_widget_height(window); break; } } ftk_widget_move_resize(window, x, y, w, h); ftk_logd("type=%d %d %d %d %d\n", ftk_widget_type(window), x, y, w, h); return RET_OK; }