draggable support drag native window

This commit is contained in:
lixianjing 2022-03-01 15:54:29 +08:00
parent 47b555896d
commit fafdd3793e
4 changed files with 58 additions and 4 deletions

View File

@ -1,5 +1,8 @@
# 最新动态 # 最新动态
2022/02/26
* draggable 支持拖动原生窗口。
2022/02/25 2022/02/25
* 增加函数combo\_box\_has\_option\_text * 增加函数combo\_box\_has\_option\_text
* 完善themegen (感谢兆坤提供补丁)。 * 完善themegen (感谢兆坤提供补丁)。

View File

@ -86,6 +86,15 @@ ret_t draggable_set_drag_window(widget_t* widget, bool_t drag_window) {
return RET_OK; return RET_OK;
} }
ret_t draggable_set_drag_native_window(widget_t* widget, bool_t drag_native_window) {
draggable_t* draggable = DRAGGABLE(widget);
return_value_if_fail(draggable != NULL, RET_BAD_PARAMS);
draggable->drag_native_window = drag_native_window;
return RET_OK;
}
ret_t draggable_set_drag_parent(widget_t* widget, uint32_t drag_parent) { ret_t draggable_set_drag_parent(widget_t* widget, uint32_t drag_parent) {
draggable_t* draggable = DRAGGABLE(widget); draggable_t* draggable = DRAGGABLE(widget);
return_value_if_fail(draggable != NULL, RET_BAD_PARAMS); return_value_if_fail(draggable != NULL, RET_BAD_PARAMS);
@ -120,6 +129,9 @@ static ret_t draggable_get_prop(widget_t* widget, const char* name, value_t* v)
} else if (tk_str_eq(DRAGGABLE_PROP_DRAG_WINDOW, name)) { } else if (tk_str_eq(DRAGGABLE_PROP_DRAG_WINDOW, name)) {
value_set_bool(v, draggable->drag_window); value_set_bool(v, draggable->drag_window);
return RET_OK; return RET_OK;
} else if (tk_str_eq(DRAGGABLE_PROP_DRAG_NATIVE_WINDOW, name)) {
value_set_bool(v, draggable->drag_native_window);
return RET_OK;
} else if (tk_str_eq(DRAGGABLE_PROP_DRAG_PARENT, name)) { } else if (tk_str_eq(DRAGGABLE_PROP_DRAG_PARENT, name)) {
value_set_uint32(v, draggable->drag_parent); value_set_uint32(v, draggable->drag_parent);
return RET_OK; return RET_OK;
@ -152,6 +164,9 @@ static ret_t draggable_set_prop(widget_t* widget, const char* name, const value_
} else if (tk_str_eq(DRAGGABLE_PROP_DRAG_WINDOW, name)) { } else if (tk_str_eq(DRAGGABLE_PROP_DRAG_WINDOW, name)) {
draggable_set_drag_window(widget, value_bool(v)); draggable_set_drag_window(widget, value_bool(v));
return RET_OK; return RET_OK;
} else if (tk_str_eq(DRAGGABLE_PROP_DRAG_NATIVE_WINDOW, name)) {
draggable_set_drag_native_window(widget, value_bool(v));
return RET_OK;
} else if (tk_str_eq(DRAGGABLE_PROP_DRAG_PARENT, name)) { } else if (tk_str_eq(DRAGGABLE_PROP_DRAG_PARENT, name)) {
draggable_set_drag_parent(widget, value_uint32(v)); draggable_set_drag_parent(widget, value_uint32(v));
return RET_OK; return RET_OK;
@ -208,8 +223,17 @@ static ret_t draggable_on_parent_pointer_down(void* ctx, event_t* e) {
draggable->pressed = TRUE; draggable->pressed = TRUE;
draggable->down.x = evt->x; draggable->down.x = evt->x;
draggable->down.y = evt->y; draggable->down.y = evt->y;
draggable->saved_position.x = target->x;
draggable->saved_position.y = target->y; if (draggable->drag_native_window) {
native_window_info_t info;
native_window_t* nw = widget_get_native_window(widget);
native_window_get_info(nw, &info);
draggable->saved_position.x = info.x;
draggable->saved_position.y = info.y;
} else {
draggable->saved_position.x = target->x;
draggable->saved_position.y = target->y;
}
widget_grab(widget->parent->parent, widget->parent); widget_grab(widget->parent->parent, widget->parent);
} }
@ -257,7 +281,12 @@ static ret_t draggable_on_parent_pointer_move(void* ctx, event_t* e) {
x = draggable->saved_position.x + (draggable->vertical_only ? 0 : dx); x = draggable->saved_position.x + (draggable->vertical_only ? 0 : dx);
y = draggable->saved_position.y + (draggable->horizontal_only ? 0 : dy); y = draggable->saved_position.y + (draggable->horizontal_only ? 0 : dy);
draggable_move_target(widget, x, y); if (draggable->drag_native_window) {
native_window_t* nw = widget_get_native_window(widget);
native_window_move(nw, x, y, TRUE);
} else {
draggable_move_target(widget, x, y);
}
} }
return RET_OK; return RET_OK;

View File

@ -114,6 +114,13 @@ typedef struct _draggable_t {
*/ */
bool_t drag_window; bool_t drag_window;
/**
* @property {bool_t} drag_native_window
* @annotation ["set_prop","get_prop","readable","persitent","design","scriptable"]
*
*/
bool_t drag_native_window;
/** /**
* @property {uint32_t} drag_parent * @property {uint32_t} drag_parent
* @annotation ["set_prop","get_prop","readable","persitent","design","scriptable"] * @annotation ["set_prop","get_prop","readable","persitent","design","scriptable"]
@ -222,13 +229,24 @@ ret_t draggable_set_horizontal_only(widget_t* widget, bool_t horizontal_only);
* drag_window * drag_window
* @annotation ["scriptable"] * @annotation ["scriptable"]
* @param {widget_t*} widget widget对象 * @param {widget_t*} widget widget对象
* @param {bool_t} drag_window drag_window * @param {bool_t} drag_window
* titlebar上titlebar其实是希望拖动对话框 * titlebar上titlebar其实是希望拖动对话框
* *
* @return {ret_t} RET_OK表示成功 * @return {ret_t} RET_OK表示成功
*/ */
ret_t draggable_set_drag_window(widget_t* widget, bool_t drag_window); ret_t draggable_set_drag_window(widget_t* widget, bool_t drag_window);
/**
* @method draggable_set_drag_native_window
* drag_native_window
* @annotation ["scriptable"]
* @param {widget_t*} widget widget对象
* @param {bool_t} drag_native_window
*
* @return {ret_t} RET_OK表示成功
*/
ret_t draggable_set_drag_native_window(widget_t* widget, bool_t drag_native_window);
/** /**
* @method draggable_set_drag_parent * @method draggable_set_drag_parent
* drag_parent * drag_parent
@ -249,6 +267,7 @@ ret_t draggable_set_drag_parent(widget_t* widget, uint32_t drag_parent);
#define DRAGGABLE_PROP_DRAG_PARENT "drag_parent" #define DRAGGABLE_PROP_DRAG_PARENT "drag_parent"
#define DRAGGABLE_PROP_VERTICAL_ONLY "vertical_only" #define DRAGGABLE_PROP_VERTICAL_ONLY "vertical_only"
#define DRAGGABLE_PROP_HORIZONTAL_ONLY "horizontal_only" #define DRAGGABLE_PROP_HORIZONTAL_ONLY "horizontal_only"
#define DRAGGABLE_PROP_DRAG_NATIVE_WINDOW "drag_native_window"
#define WIDGET_TYPE_DRAGGABLE "draggable" #define WIDGET_TYPE_DRAGGABLE "draggable"
#define DRAGGABLE_UNSPECIFIED_NUM 0x1fffffff #define DRAGGABLE_UNSPECIFIED_NUM 0x1fffffff

View File

@ -46,5 +46,8 @@ TEST(Draggable, basic) {
ASSERT_EQ(widget_set_prop_int(d, DRAGGABLE_PROP_DRAG_WINDOW, 1), RET_OK); ASSERT_EQ(widget_set_prop_int(d, DRAGGABLE_PROP_DRAG_WINDOW, 1), RET_OK);
ASSERT_EQ(widget_get_prop_int(d, DRAGGABLE_PROP_DRAG_WINDOW, 0), 1); ASSERT_EQ(widget_get_prop_int(d, DRAGGABLE_PROP_DRAG_WINDOW, 0), 1);
ASSERT_EQ(widget_set_prop_int(d, DRAGGABLE_PROP_DRAG_NATIVE_WINDOW, 1), RET_OK);
ASSERT_EQ(widget_get_prop_int(d, DRAGGABLE_PROP_DRAG_NATIVE_WINDOW, 0), 1);
widget_destroy(w); widget_destroy(w);
} }