mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-11-29 18:48:09 +08:00
draggable support drag native window
This commit is contained in:
parent
47b555896d
commit
fafdd3793e
@ -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 (感谢兆坤提供补丁)。
|
||||||
|
@ -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;
|
||||||
|
@ -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
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user