📄 panel_seln.c
字号:
} case SELN_REQ_YIELD: result = SELN_FAILED; switch (context->rank) { case SELN_SHELF: if (panel->shelf) { free(panel->shelf); panel->shelf = 0; (void) seln_done(panel->seln_client, SELN_SHELF); result = SELN_SUCCESS; } break; default: if (selection->ip) { panel_seln_cancel(panel, context->rank); result = SELN_SUCCESS; } break; } *context->response_pointer++ = (caddr_t) result; return result; case SELN_REQ_COMMIT_PENDING_DELETE: if (panel_is_pending_delete(context->rank)) { if (context->rank == SELN_SECONDARY) panel_seln_shelve(panel, selection, context->rank); if (selection->ip && !selection->is_null) panel_seln_delete(selection->ip, context->rank); } *context->response_pointer++ = (caddr_t) SELN_SUCCESS; return SELN_SUCCESS; default: return SELN_UNRECOGNIZED; }}/* Selection utilities */panel_seln_process_request(panel, buffer, holder) register panel_handle panel; register Seln_function_buffer *buffer; Seln_holder *holder;{ switch (buffer->function) { case SELN_FN_GET: /* PASTE */ (void)panel_seln_get(panel, holder, buffer->addressee_rank); break; case SELN_FN_PUT: /* COPY */ (void)panel_seln_put(panel, holder, buffer); break; }}/* * Get the selection from holder and put it in the text item that owns the * selection rank. */static voidpanel_seln_put(panel, holder, buffer) panel_handle panel; Seln_holder *holder; register Seln_function_buffer *buffer;{ Seln_request *reqbuf; register Attr_avlist avlist; register u_char *cp; Event event; int num_chars; int old_primary_caret_position; int new_primary_caret_position; int old_secondary_caret_position; int new_secondary_caret_position; int caret_was_on; panel_selection_handle selection = panel_seln(panel, buffer->addressee_rank); panel_item_handle ip = selection->ip; if (!panel->seln_client) return; /* * get the primary selection and save in a buffer */ /* if the request is too large, drop it on the floor. */ reqbuf = seln_ask(holder, SELN_REQ_BYTESIZE, 0, SELN_REQ_CONTENTS_ASCII, 0, 0); cp = NULL; if (reqbuf->status != SELN_FAILED) { avlist = (Attr_avlist) LINT_CAST(reqbuf->data); if ((Seln_attribute) * avlist++ == SELN_REQ_BYTESIZE) { num_chars = (int) *avlist++; if ((Seln_attribute) * avlist++ == SELN_REQ_CONTENTS_ASCII) cp = (u_char *) avlist; } } /* * make sure the string is null terminated in the last byte of the * selection. */ if (cp != NULL) { cp[num_chars] = '\0'; if ((cp = (u_char *)strdup(cp)) == NULL) { fprintf(stderr, "panel_seln: Out of memory!"); exit(1); } } /* * dehilite (and possibly shelf and delete) the secondary selection */ reqbuf = seln_ask(buffer->secondary, SELN_REQ_COMMIT_PENDING_DELETE, 0); /* now, clean up */ if (holder->rank == SELN_PRIMARY) { reqbuf = seln_ask(holder, SELN_REQ_COMMIT_PENDING_DELETE, 0); } else { reqbuf = seln_ask(holder, SELN_REQ_COMMIT_PENDING_DELETE, SELN_REQ_YIELD, 0, 0); } reqbuf = seln_ask(buffer->secondary, SELN_REQ_YIELD, 0, 0); if (reqbuf->status == SELN_FAILED) return; if (cp == (u_char *)0) return; if (buffer->addressee_rank == SELN_SECONDARY) { caret_was_on = 0; if (ip->panel->caret_on) { panel_caret_on(panel, FALSE); caret_was_on = 1; } /* * INSERT TEXT AT SECONDARY CARET OFFSET */ old_primary_caret_position = panel_get_caret_position(ip, SELN_PRIMARY); old_secondary_caret_position = panel_get_caret_position(ip, SELN_SECONDARY); panel_set_caret_position(ip, SELN_PRIMARY, old_secondary_caret_position); } /* * put the primary selection where secondary selection was */ /* initialize the event */ event_init(&event); event_set_down(&event); while (*cp) { event_id(&event) = (short) *cp++; if (event_id(&event) >= 0x80) event_id(&event) += ISO_FIRST; (void) panel_handle_event((Panel_item) ip, &event); } if (buffer->addressee_rank == SELN_SECONDARY) { /* yes, this is correct */ new_secondary_caret_position = panel_get_caret_position(ip, SELN_PRIMARY); if (old_secondary_caret_position <= old_primary_caret_position) { new_primary_caret_position = new_secondary_caret_position - old_secondary_caret_position + old_primary_caret_position; } else new_primary_caret_position = old_primary_caret_position; if (ip == ip->panel->caret) panel_set_caret_position(ip, SELN_PRIMARY, new_primary_caret_position); if (caret_was_on) panel_caret_on(panel, TRUE); }}/* * Get the selection from holder and put it in the text item that owns the * selection rank. */static voidpanel_seln_get(panel, holder, rank) panel_handle panel; Seln_holder *holder; Seln_rank rank;{ Seln_request *reqbuf; register Attr_avlist avlist; register u_char *cp; Event event; Seln_holder shelf_holder; int num_chars = 0; int had_shelf = 0; int had_primary_pending_delete = 0; char *selection_string = NULL; int selection_length = 0; panel_selection_handle selection = panel_seln(panel, rank); panel_item_handle ip = selection->ip; if (!panel->seln_client) return; if (panel->shelf) { (void) seln_done(panel->seln_client, SELN_SHELF); had_shelf = 1; } /* preserve primary selection in case overlapping secondary selection */ if (holder->rank == SELN_SECONDARY && ip == panel_seln(panel, SELN_PRIMARY)->ip && panel_is_pending_delete(SELN_PRIMARY)) { panel_get_text_selection(ip, &selection_string, &selection_length, SELN_PRIMARY); if ((selection_string = (char *)strdup(selection_string)) == NULL) { fprintf(stderr, "panel_seln: Out of memory!"); exit(1); } selection_string[selection_length] = '\0'; /* terminate string */ had_primary_pending_delete = 1; } /* * if the request is too large, drop it on the floor. */ if (holder->rank == SELN_SECONDARY) reqbuf = seln_ask(holder, SELN_REQ_BYTESIZE, 0, SELN_REQ_CONTENTS_ASCII, 0, SELN_REQ_COMMIT_PENDING_DELETE, SELN_REQ_YIELD, 0, 0); else reqbuf = seln_ask(holder, SELN_REQ_BYTESIZE, 0, SELN_REQ_CONTENTS_ASCII, 0, SELN_REQ_COMMIT_PENDING_DELETE, 0); if (reqbuf->status == SELN_FAILED) return; avlist = (Attr_avlist) LINT_CAST(reqbuf->data); if ((Seln_attribute) * avlist++ != SELN_REQ_BYTESIZE) return; num_chars = (int) *avlist++; if ((Seln_attribute) * avlist++ != SELN_REQ_CONTENTS_ASCII) return; cp = (u_char *) avlist; /* * make sure the string is null terminated in the last byte of the * selection. */ cp[num_chars] = '\0'; /* reclaim the shelf if no one else took it */ if (had_shelf) { shelf_holder = seln_inquire(SELN_SHELF); if (shelf_holder.state == SELN_NONE) panel_seln_acquire(panel, (panel_item_handle) 0, SELN_SHELF, TRUE); } /* initialize the event */ event_init(&event); event_set_down(&event); /* insert the text */ while (*cp) { event_id(&event) = (short) *cp++; if (event_id(&event) >= 0x80) event_id(&event) += ISO_FIRST; (void) panel_handle_event((Panel_item) ip, &event); } if (had_primary_pending_delete) { free(panel->shelf); panel->shelf = selection_string; }}/* * panel_seln_shelve -- put the panel selection of specified rank on the * shelf */panel_seln_shelve(panel, selection, rank) panel_handle panel; panel_selection_handle selection; Seln_rank rank;{ char *selection_string = (char *) 0; char save_char; u_long selection_length; if (rank != SELN_PRIMARY && rank != SELN_SECONDARY) return; if (panel->shelf) free(panel->shelf); /* * shelve the requested selection, not the caret selection */ if (selection->is_null || !selection->ip) { panel->shelf = panel_strsave(""); return; } panel_get_text_selection(selection->ip, &selection_string, &selection_length, rank); if (selection_string) { save_char = *(selection_string + selection_length); *(selection_string + selection_length) = 0; panel->shelf = panel_strsave(selection_string); *(selection_string + selection_length) = save_char; } else panel->shelf = panel_strsave(""); panel_seln_acquire(panel, (panel_item_handle) 0, SELN_SHELF, TRUE);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -