1.将A27新UI文件夹重命名为CANUI 2.A272O新版本发布

This commit is contained in:
2025-03-26 18:43:18 +08:00
parent 497f8eb1e1
commit 5bc7ee438c
13399 changed files with 58500 additions and 59183 deletions

View File

@ -0,0 +1,4 @@
# 特性类控件
特性类控件一般是给所在的容器控件加上指定的特性。比如可拖动、可点击、可选择、可调整大小和上下文帮助等。

View File

@ -0,0 +1,366 @@
/**
* File: draggable.c
* Author: AWTK Develop Team
* Brief: make parent widget or window draggable
*
* Copyright (c) 2019 - 2021 Guangzhou ZHIYUAN Electronics Co.,Ltd.
*
* 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
* License file for more details.
*
*/
/**
* History:
* ================================================================
* 2019-10-25 Li XianJing <xianjimli@hotmail.com> created
*
*/
#include "tkc/mem.h"
#include "tkc/utils.h"
#include "draggable.h"
ret_t draggable_set_top(widget_t* widget, int32_t top) {
draggable_t* draggable = DRAGGABLE(widget);
return_value_if_fail(draggable != NULL, RET_BAD_PARAMS);
draggable->top = top;
return RET_OK;
}
ret_t draggable_set_bottom(widget_t* widget, int32_t bottom) {
draggable_t* draggable = DRAGGABLE(widget);
return_value_if_fail(draggable != NULL, RET_BAD_PARAMS);
draggable->bottom = bottom;
return RET_OK;
}
ret_t draggable_set_left(widget_t* widget, int32_t left) {
draggable_t* draggable = DRAGGABLE(widget);
return_value_if_fail(draggable != NULL, RET_BAD_PARAMS);
draggable->left = left;
return RET_OK;
}
ret_t draggable_set_right(widget_t* widget, int32_t right) {
draggable_t* draggable = DRAGGABLE(widget);
return_value_if_fail(draggable != NULL, RET_BAD_PARAMS);
draggable->right = right;
return RET_OK;
}
ret_t draggable_set_vertical_only(widget_t* widget, bool_t vertical_only) {
draggable_t* draggable = DRAGGABLE(widget);
return_value_if_fail(draggable != NULL, RET_BAD_PARAMS);
draggable->vertical_only = vertical_only;
return RET_OK;
}
ret_t draggable_set_horizontal_only(widget_t* widget, bool_t horizontal_only) {
draggable_t* draggable = DRAGGABLE(widget);
return_value_if_fail(draggable != NULL, RET_BAD_PARAMS);
draggable->horizontal_only = horizontal_only;
return RET_OK;
}
ret_t draggable_set_drag_window(widget_t* widget, bool_t drag_window) {
draggable_t* draggable = DRAGGABLE(widget);
return_value_if_fail(draggable != NULL, RET_BAD_PARAMS);
draggable->drag_window = drag_window;
return RET_OK;
}
ret_t draggable_set_drag_parent(widget_t* widget, uint32_t drag_parent) {
draggable_t* draggable = DRAGGABLE(widget);
return_value_if_fail(draggable != NULL, RET_BAD_PARAMS);
draggable->drag_parent = drag_parent;
return RET_OK;
}
static ret_t draggable_get_prop(widget_t* widget, const char* name, value_t* v) {
draggable_t* draggable = DRAGGABLE(widget);
return_value_if_fail(draggable != NULL && name != NULL && v != NULL, RET_BAD_PARAMS);
if (tk_str_eq(DRAGGABLE_PROP_TOP, name)) {
value_set_int32(v, draggable->top);
return RET_OK;
} else if (tk_str_eq(DRAGGABLE_PROP_BOTTOM, name)) {
value_set_int32(v, draggable->bottom);
return RET_OK;
} else if (tk_str_eq(DRAGGABLE_PROP_LEFT, name)) {
value_set_int32(v, draggable->left);
return RET_OK;
} else if (tk_str_eq(DRAGGABLE_PROP_RIGHT, name)) {
value_set_int32(v, draggable->right);
return RET_OK;
} else if (tk_str_eq(DRAGGABLE_PROP_VERTICAL_ONLY, name)) {
value_set_bool(v, draggable->vertical_only);
return RET_OK;
} else if (tk_str_eq(DRAGGABLE_PROP_HORIZONTAL_ONLY, name)) {
value_set_bool(v, draggable->horizontal_only);
return RET_OK;
} else if (tk_str_eq(DRAGGABLE_PROP_DRAG_WINDOW, name)) {
value_set_bool(v, draggable->drag_window);
return RET_OK;
} else if (tk_str_eq(DRAGGABLE_PROP_DRAG_PARENT, name)) {
value_set_uint32(v, draggable->drag_parent);
return RET_OK;
}
return RET_NOT_FOUND;
}
static ret_t draggable_set_prop(widget_t* widget, const char* name, const value_t* v) {
return_value_if_fail(widget != NULL && name != NULL && v != NULL, RET_BAD_PARAMS);
if (tk_str_eq(DRAGGABLE_PROP_TOP, name)) {
draggable_set_top(widget, value_int32(v));
return RET_OK;
} else if (tk_str_eq(DRAGGABLE_PROP_BOTTOM, name)) {
draggable_set_bottom(widget, value_int32(v));
return RET_OK;
} else if (tk_str_eq(DRAGGABLE_PROP_LEFT, name)) {
draggable_set_left(widget, value_int32(v));
return RET_OK;
} else if (tk_str_eq(DRAGGABLE_PROP_RIGHT, name)) {
draggable_set_right(widget, value_int32(v));
return RET_OK;
} else if (tk_str_eq(DRAGGABLE_PROP_VERTICAL_ONLY, name)) {
draggable_set_vertical_only(widget, value_bool(v));
return RET_OK;
} else if (tk_str_eq(DRAGGABLE_PROP_HORIZONTAL_ONLY, name)) {
draggable_set_horizontal_only(widget, value_bool(v));
return RET_OK;
} else if (tk_str_eq(DRAGGABLE_PROP_DRAG_WINDOW, name)) {
draggable_set_drag_window(widget, value_bool(v));
return RET_OK;
} else if (tk_str_eq(DRAGGABLE_PROP_DRAG_PARENT, name)) {
draggable_set_drag_parent(widget, value_uint32(v));
return RET_OK;
}
return RET_NOT_FOUND;
}
static ret_t draggable_on_destroy(widget_t* widget) {
draggable_t* draggable = DRAGGABLE(widget);
return_value_if_fail(widget != NULL && draggable != NULL, RET_BAD_PARAMS);
(void)draggable;
return RET_OK;
}
static ret_t draggable_on_paint_self(widget_t* widget, canvas_t* c) {
return RET_OK;
}
static widget_t* draggable_get_target(widget_t* widget) {
widget_t* target = NULL;
draggable_t* draggable = DRAGGABLE(widget);
return_value_if_fail(draggable != NULL, NULL);
if (draggable->drag_window) {
target = widget_get_window(widget);
} else {
uint32_t i = draggable->drag_parent;
target = widget->parent;
while (i > 0 && target != NULL && target->parent != NULL) {
target = target->parent;
if (widget_is_window(target)) {
break;
}
i--;
}
}
return target;
}
static ret_t draggable_on_parent_pointer_down(void* ctx, event_t* e) {
widget_t* widget = WIDGET(ctx);
return_value_if_fail(widget != NULL, RET_BAD_PARAMS);
if (widget->enable) {
pointer_event_t* evt = (pointer_event_t*)e;
draggable_t* draggable = DRAGGABLE(widget);
return_value_if_fail(draggable != NULL, RET_BAD_PARAMS);
widget_t* target = draggable_get_target(widget);
draggable->pressed = TRUE;
draggable->down.x = evt->x;
draggable->down.y = evt->y;
draggable->saved_position.x = target->x;
draggable->saved_position.y = target->y;
widget_grab(widget->parent->parent, widget->parent);
}
return RET_OK;
}
static ret_t draggable_move_target(widget_t* widget, xy_t x, xy_t y) {
widget_t* target = NULL;
draggable_t* draggable = DRAGGABLE(widget);
return_value_if_fail(draggable != NULL, RET_BAD_PARAMS);
target = draggable_get_target(widget);
return_value_if_fail(target != NULL, RET_BAD_PARAMS);
xy_t min_x = draggable->left != DRAGGABLE_UNSPECIFIED_NUM ? draggable->left : 0;
xy_t min_y = draggable->top != DRAGGABLE_UNSPECIFIED_NUM ? draggable->top : 0;
xy_t max_x =
(draggable->right != DRAGGABLE_UNSPECIFIED_NUM ? draggable->right : target->parent->w) -
target->w;
xy_t max_y =
(draggable->bottom != DRAGGABLE_UNSPECIFIED_NUM ? draggable->bottom : target->parent->h) -
target->h;
x = tk_clampi(x, min_x, max_x);
y = tk_clampi(y, min_y, max_y);
widget_move(target, x, y);
return RET_OK;
}
static ret_t draggable_on_parent_pointer_move(void* ctx, event_t* e) {
widget_t* widget = WIDGET(ctx);
draggable_t* draggable = DRAGGABLE(widget);
return_value_if_fail(widget != NULL && draggable != NULL, RET_BAD_PARAMS);
if (widget->enable && draggable->pressed) {
xy_t x = 0;
xy_t y = 0;
pointer_event_t* evt = (pointer_event_t*)e;
xy_t dx = evt->x - draggable->down.x;
xy_t dy = evt->y - draggable->down.y;
x = draggable->saved_position.x + (draggable->vertical_only ? 0 : dx);
y = draggable->saved_position.y + (draggable->horizontal_only ? 0 : dy);
draggable_move_target(widget, x, y);
}
return RET_OK;
}
static ret_t draggable_on_parent_pointer_up(void* ctx, event_t* e) {
widget_t* widget = WIDGET(ctx);
return_value_if_fail(widget != NULL, RET_BAD_PARAMS);
if (widget->enable) {
int32_t dx, dy;
widget_t* target = NULL;
draggable_t* draggable = DRAGGABLE(widget);
return_value_if_fail(draggable != NULL, RET_BAD_PARAMS);
draggable->pressed = FALSE;
target = draggable_get_target(widget);
dx = target->x - draggable->saved_position.x;
dy = target->y - draggable->saved_position.y;
if (tk_abs(dx) > 5 || tk_abs(dy) > 5) {
pointer_event_t abort;
pointer_event_init(&abort, EVT_POINTER_DOWN_ABORT, NULL, 0, 0);
widget_dispatch(widget->parent, (event_t*)&abort);
}
widget_ungrab(widget->parent->parent, widget->parent);
}
return RET_OK;
}
static ret_t draggable_on_attach_parent(widget_t* widget, widget_t* parent) {
draggable_t* draggable = DRAGGABLE(widget);
widget_on(parent, EVT_POINTER_DOWN_BEFORE_CHILDREN, draggable_on_parent_pointer_down, draggable);
widget_on(parent, EVT_POINTER_MOVE_BEFORE_CHILDREN, draggable_on_parent_pointer_move, draggable);
widget_on(parent, EVT_POINTER_UP_BEFORE_CHILDREN, draggable_on_parent_pointer_up, draggable);
return RET_OK;
}
static ret_t draggable_on_detach_parent(widget_t* widget, widget_t* parent) {
widget_off_by_ctx(parent, widget);
return RET_OK;
}
static ret_t draggable_on_event(widget_t* widget, event_t* e) {
draggable_t* draggable = DRAGGABLE(widget);
return_value_if_fail(widget != NULL && draggable != NULL, RET_BAD_PARAMS);
(void)draggable;
return RET_OK;
}
const char* s_draggable_properties[] = {
DRAGGABLE_PROP_TOP, DRAGGABLE_PROP_BOTTOM,
DRAGGABLE_PROP_LEFT, DRAGGABLE_PROP_RIGHT,
DRAGGABLE_PROP_VERTICAL_ONLY, DRAGGABLE_PROP_HORIZONTAL_ONLY,
DRAGGABLE_PROP_DRAG_WINDOW, NULL};
TK_DECL_VTABLE(draggable) = {.size = sizeof(draggable_t),
.type = WIDGET_TYPE_DRAGGABLE,
.clone_properties = s_draggable_properties,
.persistent_properties = s_draggable_properties,
.parent = TK_PARENT_VTABLE(widget),
.create = draggable_create,
.on_paint_self = draggable_on_paint_self,
.set_prop = draggable_set_prop,
.get_prop = draggable_get_prop,
.on_event = draggable_on_event,
.on_attach_parent = draggable_on_attach_parent,
.on_detach_parent = draggable_on_detach_parent,
.on_destroy = draggable_on_destroy};
widget_t* draggable_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h) {
widget_t* widget = widget_create(parent, TK_REF_VTABLE(draggable), x, y, w, h);
draggable_t* draggable = DRAGGABLE(widget);
return_value_if_fail(draggable != NULL, NULL);
draggable->top = DRAGGABLE_UNSPECIFIED_NUM;
draggable->bottom = DRAGGABLE_UNSPECIFIED_NUM;
draggable->left = DRAGGABLE_UNSPECIFIED_NUM;
draggable->right = DRAGGABLE_UNSPECIFIED_NUM;
draggable->vertical_only = FALSE;
draggable->horizontal_only = FALSE;
draggable->drag_window = FALSE;
draggable->pressed = FALSE;
widget_set_sensitive(widget, FALSE);
return widget;
}
widget_t* draggable_cast(widget_t* widget) {
return_value_if_fail(WIDGET_IS_INSTANCE_OF(widget, draggable), NULL);
return widget;
}
#include "base/widget_factory.h"
ret_t draggable_register(void) {
return widget_factory_register(widget_factory(), WIDGET_TYPE_DRAGGABLE, draggable_create);
}

View File

@ -0,0 +1,265 @@
/**
* File: draggable.h
* Author: AWTK Develop Team
* Brief: make parent widget or window draggable
*
* Copyright (c) 2019 - 2021 Guangzhou ZHIYUAN Electronics Co.,Ltd.
*
* 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
* License file for more details.
*
*/
/**
* History:
* ================================================================
* 2019-10-25 Li XianJing <xianjimli@hotmail.com> created
*
*/
#ifndef TK_DRAGGABLE_H
#define TK_DRAGGABLE_H
#include "base/widget.h"
BEGIN_C_DECLS
/**
* @class draggable_t
* @parent widget_t
* @annotation ["scriptable","design","widget"]
*
* 将draggable放入目标控件即可让目标控件或当前窗口可以被拖动。
*
* draggable\_t是[widget\_t](widget_t.md)的子类控件widget\_t的函数均适用于draggable\_t控件。
*
* 在xml中使用"draggable"标签创建draggable控件。如
*
* ```xml
* <button text="Drag Me" w="80" h="40" x="10" y="10">
* <draggable />
* </button>
* ```
*
* 拖动对话框标题时移动对话框:
*
* ```xml
* <dialog_title x="0" y="0" w="100%" h="30" text="Hello AWTK" >
* <draggable drag_window="true"/>
* </dialog_title>
* ```
*
* > 更多用法请参考:
* [draggable.xml](https://github.com/zlgopen/awtk/blob/master/design/default/ui/draggable.xml)
*
* 在c代码中使用函数draggable\_create创建按钮控件。如
*
* ```c
* widget_t* draggable = draggable_create(target, 0, 0, 0, 0);
* ```
*
* > draggable本身不可见故无需style。
*
*/
typedef struct _draggable_t {
widget_t widget;
/**
* @property {int32_t} top
* @annotation ["set_prop","get_prop","readable","persitent","design","scriptable"]
* 拖动范围的顶部限制。缺省为父控件的顶部。
*/
int32_t top;
/**
* @property {int32_t} bottom
* @annotation ["set_prop","get_prop","readable","persitent","design","scriptable"]
* 拖动范围的底部限制。缺省为父控件的底部。
*/
int32_t bottom;
/**
* @property {int32_t} left
* @annotation ["set_prop","get_prop","readable","persitent","design","scriptable"]
* 拖动范围的左边限制。缺省为父控件的左边。
*/
int32_t left;
/**
* @property {int32_t} right
* @annotation ["set_prop","get_prop","readable","persitent","design","scriptable"]
* 拖动范围的右边限制。缺省为父控件的右边边。
*/
int32_t right;
/**
* @property {bool_t} vertical_only
* @annotation ["set_prop","get_prop","readable","persitent","design","scriptable"]
* 只允许垂直拖动。
*/
bool_t vertical_only;
/**
* @property {bool_t} horizontal_only
* @annotation ["set_prop","get_prop","readable","persitent","design","scriptable"]
* 只允许水平拖动。
*/
bool_t horizontal_only;
/**
* @property {bool_t} drag_window
* @annotation ["set_prop","get_prop","readable","persitent","design","scriptable"]
* 拖动窗口而不是父控件。比如放在对话框的titlebar上拖动titlebar其实是希望拖动对话框。
*/
bool_t drag_window;
/**
* @property {uint32_t} drag_parent
* @annotation ["set_prop","get_prop","readable","persitent","design","scriptable"]
* 拖动父控件。0表示直系父控件1表示父控件的父控件依次类推。
*/
uint32_t drag_parent;
/*private*/
bool_t pressed;
point_t down;
point_t saved_position;
} draggable_t;
/**
* @method draggable_create
* @annotation ["constructor", "scriptable"]
* 创建draggable对象
* @param {widget_t*} parent 父控件
* @param {xy_t} x x坐标
* @param {xy_t} y y坐标
* @param {wh_t} w 宽度
* @param {wh_t} h 高度
*
* @return {widget_t*} 对象。
*/
widget_t* draggable_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h);
/**
* @method draggable_cast
* 转换为draggable对象(供脚本语言使用)。
* @annotation ["cast", "scriptable"]
* @param {widget_t*} widget draggable对象。
*
* @return {widget_t*} draggable对象。
*/
widget_t* draggable_cast(widget_t* widget);
/**
* @method draggable_set_top
* 设置top。
* @annotation ["scriptable"]
* @param {widget_t*} widget widget对象。
* @param {int32_t} top 拖动范围的顶部限制。缺省为父控件的顶部。
*
* @return {ret_t} 返回RET_OK表示成功否则表示失败。
*/
ret_t draggable_set_top(widget_t* widget, int32_t top);
/**
* @method draggable_set_bottom
* 设置bottom。
* @annotation ["scriptable"]
* @param {widget_t*} widget widget对象。
* @param {int32_t} bottom 拖动范围的底部限制。缺省为父控件的底部。
*
* @return {ret_t} 返回RET_OK表示成功否则表示失败。
*/
ret_t draggable_set_bottom(widget_t* widget, int32_t bottom);
/**
* @method draggable_set_left
* 设置left。
* @annotation ["scriptable"]
* @param {widget_t*} widget widget对象。
* @param {int32_t} left 拖动范围的左边限制。缺省为父控件的左边。
*
* @return {ret_t} 返回RET_OK表示成功否则表示失败。
*/
ret_t draggable_set_left(widget_t* widget, int32_t left);
/**
* @method draggable_set_right
* 设置right。
* @annotation ["scriptable"]
* @param {widget_t*} widget widget对象。
* @param {int32_t} right 拖动范围的右边限制。缺省为父控件的右边边。
*
* @return {ret_t} 返回RET_OK表示成功否则表示失败。
*/
ret_t draggable_set_right(widget_t* widget, int32_t right);
/**
* @method draggable_set_vertical_only
* 设置vertical_only。
* @annotation ["scriptable"]
* @param {widget_t*} widget widget对象。
* @param {bool_t} vertical_only 只允许垂直拖动。
*
* @return {ret_t} 返回RET_OK表示成功否则表示失败。
*/
ret_t draggable_set_vertical_only(widget_t* widget, bool_t vertical_only);
/**
* @method draggable_set_horizontal_only
* 设置horizontal_only。
* @annotation ["scriptable"]
* @param {widget_t*} widget widget对象。
* @param {bool_t} horizontal_only 只允许水平拖动。
*
* @return {ret_t} 返回RET_OK表示成功否则表示失败。
*/
ret_t draggable_set_horizontal_only(widget_t* widget, bool_t horizontal_only);
/**
* @method draggable_set_drag_window
* 设置drag_window。
* @annotation ["scriptable"]
* @param {widget_t*} widget widget对象。
* @param {bool_t} drag_window drag_window
* 拖动窗口而不是父控件。比如放在对话框的titlebar上拖动titlebar其实是希望拖动对话框。
*
* @return {ret_t} 返回RET_OK表示成功否则表示失败。
*/
ret_t draggable_set_drag_window(widget_t* widget, bool_t drag_window);
/**
* @method draggable_set_drag_parent
* 设置drag_parent。
* @annotation ["scriptable"]
* @param {widget_t*} widget widget对象。
* @param {uint32_t} drag_parent 0表示直系父控件1表示父控件的父控件依次类推。
* 拖动窗口而不是父控件。比如放在对话框的titlebar上拖动titlebar其实是希望拖动对话框。
*
* @return {ret_t} 返回RET_OK表示成功否则表示失败。
*/
ret_t draggable_set_drag_parent(widget_t* widget, uint32_t drag_parent);
#define DRAGGABLE_PROP_TOP "top"
#define DRAGGABLE_PROP_BOTTOM "bottom"
#define DRAGGABLE_PROP_LEFT "left"
#define DRAGGABLE_PROP_RIGHT "right"
#define DRAGGABLE_PROP_DRAG_WINDOW "drag_window"
#define DRAGGABLE_PROP_DRAG_PARENT "drag_parent"
#define DRAGGABLE_PROP_VERTICAL_ONLY "vertical_only"
#define DRAGGABLE_PROP_HORIZONTAL_ONLY "horizontal_only"
#define WIDGET_TYPE_DRAGGABLE "draggable"
#define DRAGGABLE_UNSPECIFIED_NUM 0x1fffffff
#define DRAGGABLE(widget) ((draggable_t*)(draggable_cast(WIDGET(widget))))
ret_t draggable_register(void);
/*public for subclass and runtime type check*/
TK_EXTERN_VTABLE(draggable);
END_C_DECLS
#endif /*TK_DRAGGABLE_H*/