📄 test1.c
字号:
printf("enter win %d sub %d\n", event.xcrossing.window, event.xcrossing.subwindow); cur_window = event.xcrossing.window ; /* just enter a new top_level, check its dnd data */ DndReadReceiverProperty(event.xcrossing.display, event.xcrossing.window, &receiv_protocol_style); printf("receiv_protocol_style %d\n",receiv_protocol_style); if (receiv_protocol_style == DND_DRAG_NONE) { ChangeCursorInvalid(event.xcrossing.display, event.xcrossing.time) ; do_messaging = False ; do_drop = False ; } else if (receiv_protocol_style == DND_DRAG_DROP_ONLY) { ChangeCursorValid(event.xcrossing.display, event.xcrossing.time) ; do_messaging = False ; do_drop = True ; } else if (receiv_protocol_style == DND_DRAG_DYNAMIC) { /* we'll get valid visual on drop_site_entered */ ChangeCursorInvalid(event.xcrossing.display, event.xcrossing.time) ; dnd_data.reason = DND_TOP_LEVEL_ENTER ; dnd_data.time = event.xcrossing.time ; dnd_data.src_window = XtWindow(top_level); dnd_data.property = Dnd_selection ; DndFillClientMessage (event.xcrossing.display, cur_window, &cm, &dnd_data, 0); XSendEvent(event.xcrossing.display, cur_window, False, 0, (XEvent *)&cm) ; printf("XSendEvent DND_TOP_LEVEL_ENTER %d\n", cur_window); do_messaging = True ; do_drop = False ; } break ; case LeaveNotify: if (!in_drag || !do_messaging) break ; printf("leave win %d sub %d\n", event.xcrossing.window, event.xcrossing.subwindow); ChangeCursorInvalid(event.xcrossing.display, event.xcrossing.time) ; dnd_data.reason = DND_TOP_LEVEL_LEAVE ; dnd_data.time = event.xcrossing.time ; dnd_data.src_window = XtWindow(top_level); DndFillClientMessage (event.xcrossing.display, cur_window, &cm, &dnd_data, 0); XSendEvent(event.xcrossing.display, cur_window, False, 0, (XEvent *)&cm) ; printf("XSendEvent DND_TOP_LEVEL_LEAVE %d\n", cur_window); do_messaging = False ; cur_window = 0 ; break ; case MotionNotify: if (!in_drag || !do_messaging) break ; printf("motion win %d sub %d\n", event.xmotion.window, event.xmotion.subwindow); dnd_data.reason = DND_DRAG_MOTION ; dnd_data.time = event.xmotion.time ; dnd_data.operation = DND_MOVE|DND_COPY; dnd_data.operations = DND_MOVE|DND_COPY; dnd_data.x = event.xmotion.x_root ; dnd_data.y = event.xmotion.y_root ; DndFillClientMessage (event.xmotion.display, cur_window, &cm, &dnd_data, 0); XSendEvent(event.xmotion.display, cur_window, False, 0, (XEvent *)&cm) ; printf("XSendEvent DND_DRAG_MOTION %d\n", cur_window); break ; case ButtonRelease: if (!in_drag) break ; printf("release in %d\n",cur_window); XUngrabPointer(XtDisplay(top_level), event.xbutton.time); in_drag = False ; if (do_drop) { dnd_data.reason = DND_DROP_START ; dnd_data.time = event.xbutton.time ; dnd_data.operation = DND_MOVE|DND_COPY; dnd_data.operations = DND_MOVE|DND_COPY; dnd_data.src_window = XtWindow(top_level); dnd_data.property = Dnd_selection ; DndFillClientMessage (event.xbutton.display, cur_window, &cm, &dnd_data, 0); XSendEvent(event.xbutton.display, cur_window, False, 0, (XEvent *)&cm) ; printf("XSendEvent DND_DROP_START %d\n", cur_window); do_messaging = False ; do_drop = False ; } break ; case ClientMessage: if (!(DndParseClientMessage ((XClientMessageEvent*)&event, &dnd_data, &receiver))) { printf("not a valid Dnd client message\n"); break ; } if (dnd_data.reason == DND_DRAG_MOTION) { if (receiver) { printf("receiver echoing drag motion\n"); /* don't need to do anything, really, since we're not supporting better_x,y position */ } else { printf("source sending a drag motion\n"); /* check if in drop site, and depending on the state, send a drop site enter or drop site leave or echo */ printf("x %d y %d\n",dnd_data.x, dnd_data.y); if (dnd_data.x > dropx && dnd_data.y > dropy && dnd_data.x < dropx + (Position)dropw && dnd_data.y < dropy + (Position)droph) { if (!in_drop_site) { in_drop_site = True ; dnd_data.reason = DND_DROP_SITE_ENTER ; dnd_data.time = CurrentTime ; dnd_data.operation = DND_MOVE|DND_COPY; dnd_data.operations = DND_MOVE|DND_COPY; DndFillClientMessage (event.xclient.display, cur_window, &cm, &dnd_data, 0); XSendEvent(event.xbutton.display, cur_window, False, 0, (XEvent *)&cm) ; printf("XSendEvent DND_DROP_SITE_ENTER %d\n", cur_window); } else { dnd_data.reason = DND_DRAG_MOTION ; dnd_data.time = CurrentTime ; dnd_data.operation = DND_MOVE|DND_COPY; dnd_data.operations = DND_MOVE|DND_COPY; DndFillClientMessage (event.xclient.display, cur_window, &cm, &dnd_data, 0); XSendEvent(event.xbutton.display, cur_window, False, 0, (XEvent *)&cm) ; printf("XSendEvent DND_DRAG_MOTION %d\n", cur_window); } } else { if (in_drop_site) { in_drop_site = False ; dnd_data.reason = DND_DROP_SITE_LEAVE ; dnd_data.time = CurrentTime ; DndFillClientMessage (event.xclient.display, cur_window, &cm, &dnd_data, 0); XSendEvent(event.xbutton.display, cur_window, False, 0, (XEvent *)&cm) ; printf("XSendEvent DND_DROP_SITE_LEAVE %d\n", cur_window); } } } } else if (dnd_data.reason == DND_TOP_LEVEL_ENTER) { /* get the size of our drop site for later use */ XtVaGetValues(drop_label, XtNwidth, &dropw, XtNheight, &droph, NULL); XtTranslateCoords(drop_label, 0, 0, &dropx, &dropy); printf("x %d y %d w %d h %d\n", dropx, dropy, dropw, droph); printf("source sending a top level enter %d\n", dnd_data.src_window); cur_window = dnd_data.src_window ; /* no answer needed, just read source property */ DndReadSourceProperty (event.xclient.display, cur_window, dnd_data.property, &src_targets, &num_src_targets); printf("src_targets %d num_src_targets %d\n", src_targets[0], num_src_targets); /* we only support string for now */ if (num_src_targets && src_targets[0] == XA_STRING) printf("src target ok\n"); } else if (dnd_data.reason == DND_TOP_LEVEL_LEAVE) { printf("source sending a top level leave\n"); cur_window = 0 ; /* no need to do anything */ } else if (dnd_data.reason == DND_DROP_SITE_ENTER) { printf("receiver sending drop site enter\n"); ChangeCursorValid(event.xclient.display, CurrentTime); do_drop = True ; } else if (dnd_data.reason == DND_DROP_SITE_LEAVE) { printf("receiver sending drop site leave\n"); ChangeCursorInvalid(event.xclient.display, CurrentTime); do_drop = False ; } else if (dnd_data.reason == DND_OPERATION_CHANGED) { if (receiver) { printf("receiver echoing operation changed\n"); } else { printf("source sending an operation changed\n"); /* need to echo */ } } else if (dnd_data.reason == DND_DROP_START) { if (receiver) { printf("receiver echoing drop start\n"); } else { printf("source sending a drop start\n"); if (!in_drop_site) break ; /* need to echo and then request a convert */ dnd_data.reason = DND_DROP_START ; dnd_data.time = CurrentTime ; DndFillClientMessage (event.xclient.display, cur_window, &cm, &dnd_data, 0); XSendEvent(event.xbutton.display, cur_window, False, 0, (XEvent *)&cm) ; printf("XSendEvent DND_DROP_START %d\n", cur_window); /* ask for a convertion - the selection name is the same as the property on which the source stored its target, weird, but that's the way it was done in Motif... */ cv_targets[0] = XA_STRING ; cv_targets[1] = XInternAtom(XtDisplay(top_level), "TEXT", False); cv_targets[2] = XInternAtom(XtDisplay(top_level), "COMPOUND_TEXT", False); XtGetSelectionValues(top_level, dnd_data.property, cv_targets, XtNumber(cv_targets), ReceiverConvert, closures, CurrentTime); } printf("drop action %d\n", dnd_data.completion); } break ; default: break ; } XtDispatchEvent(&event); } exit(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -