📄 textsw_edit.c
字号:
#ifndef lint#ifdef sccsstatic char sccsid[] = "@(#)textsw_edit.c 1.1 92/07/30";#endif#endif/* * Copyright (c) 1986 by Sun Microsystems, Inc. *//* * Programming interface to editing facilities of text subwindows. */#include <suntool/primal.h>#include <suntool/textsw_impl.h>#include <suntool/alert.h>#include <suntool/frame.h>extern void ev_input_before();extern void textsw_notify_replaced();pkg_private Seln_rank textsw_acquire_seln();extern Textsw_index textsw_replace();static int update_scrollbar();pkg_private Es_handletextsw_esh_for_span(view, first, last_plus_one, to_recycle) Textsw_view view; Es_index first, last_plus_one; Es_handle to_recycle;{ Es_handle esh = FOLIO_FOR_VIEW(view)->views->esh; return((Es_handle)LINT_CAST( es_get5(esh, ES_HANDLE_FOR_SPAN, first, last_plus_one, to_recycle, 0, 0) ));}pkg_private inttextsw_adjust_delete_span(folio, first, last_plus_one) register Textsw_folio folio; register Es_index *first, *last_plus_one;/* Returns: * TXTSW_PE_EMPTY_INTERVAL iff *first < *last_plus_one, else * TEXTSW_PE_READ_ONLY iff NOTHING should be deleted, else * TXTSW_PE_ADJUSTED iff *first adjusted to reflect the constraint * imposed by folio->read_only_boundary, else * 0. */{ if (*first >= *last_plus_one) return(TXTSW_PE_EMPTY_INTERVAL); if TXTSW_IS_READ_ONLY(folio) return(TEXTSW_PE_READ_ONLY); if (!EV_MARK_IS_NULL(&folio->read_only_boundary)) { register Es_index mark_at; mark_at = textsw_find_mark_internal(folio, folio->read_only_boundary); if AN_ERROR(mark_at == ES_INFINITY) return(0); if (*last_plus_one <= mark_at) return(TEXTSW_PE_READ_ONLY); if (*first < mark_at) { *first = mark_at; return(TXTSW_PE_ADJUSTED); } } return(0);}pkg_private inttextsw_is_out_of_memory(folio, status) Textsw_folio folio; Es_status status;{ return ((status == ES_SHORT_WRITE) && (ES_TYPE_MEMORY == (Es_enum)LINT_CAST(es_get( (Es_handle)LINT_CAST(es_get(folio->views->esh, ES_PS_SCRATCH)), ES_TYPE))));} pkg_private inttextsw_esh_failed_msg(view, preamble) Textsw_view view; char *preamble;{ Textsw_folio folio = FOLIO_FOR_VIEW(view); Es_status status; status = (Es_status)LINT_CAST( es_get(folio->views->esh, ES_STATUS) ); switch (status) { case ES_SHORT_WRITE: if (textsw_is_out_of_memory(folio, status)) { Event alert_event; (void) alert_prompt( (Frame)window_get(WINDOW_FROM_VIEW(view), WIN_OWNER), &alert_event, ALERT_MESSAGE_STRINGS, (strlen(preamble)) ? preamble : "Action failed -", "The memory buffer is full.", "If this is an isolated case, you can circumvent", "this condition by undoing the operation you just", "performed, storing the contents of the subwindow", "to a file using the text menu, and then redoing", "the operation. Or, you can enlarge the size of", "this buffer by using defaultsedit to increase", "the value of /Text/Memory_Maximum, and then", "restarting your tool.", 0, ALERT_BUTTON_YES, "Continue", ALERT_TRIGGER, ACTION_STOP, 0); break; } /* else fall through */ case ES_CHECK_ERRNO: case ES_CHECK_FERROR: case ES_FLUSH_FAILED: case ES_FSYNC_FAILED: case ES_SEEK_FAILED: { Event alert_event; (void) alert_prompt( (Frame)window_get(WINDOW_FROM_VIEW(view), WIN_OWNER), &alert_event, ALERT_MESSAGE_STRINGS, (strlen(preamble)) ? preamble : "Action failed -", "A problem with the file system has been detected.", "File system is probably full.", 0, ALERT_BUTTON_YES, "Continue", ALERT_TRIGGER, ACTION_STOP, 0); } break; case ES_REPLACE_DIVERTED: break; default: break; }}pkg_private Es_indextextsw_delete_span(view, first, last_plus_one, flags) Textsw_view view; Es_index first, last_plus_one; register unsigned flags;/* Returns the change in indices resulting from the operation. Result is: * a) usually < 0, * b) 0 if span is empty or in a read_only area, * c) ES_CANNOT_SET if ev_delete_span fails */{ register Textsw_folio folio = FOLIO_FOR_VIEW(view); Es_index result; result = (flags & TXTSW_DS_ADJUST) ? textsw_adjust_delete_span(folio, &first, &last_plus_one) : (first >= last_plus_one) ? TXTSW_PE_EMPTY_INTERVAL : 0; switch (result) { case TEXTSW_PE_READ_ONLY: case TXTSW_PE_EMPTY_INTERVAL: result = 0; break; case TXTSW_PE_ADJUSTED: if (flags & TXTSW_DS_CLEAR_IF_ADJUST(0)) { textsw_set_selection(VIEW_REP_TO_ABS(view), ES_INFINITY, ES_INFINITY, EV_SEL_BASE_TYPE(flags)); } /* Fall through to do delete on remaining span. */ default: if (flags & TXTSW_DS_SHELVE) { folio->trash = textsw_esh_for_span(view, first, last_plus_one, folio->trash); textsw_acquire_seln(folio, SELN_SHELF); } switch (ev_delete_span(folio->views, first, last_plus_one, &result)) { case 0: if (flags & TXTSW_DS_RECORD) { textsw_record_delete(folio); } break; case 3: textsw_esh_failed_msg(view, "Deletion failed - "); /* Fall through */ default: result = ES_CANNOT_SET; break; } break; } return(result);}pkg_private Es_indextextsw_do_pending_delete(view, type, flags) Textsw_view view; unsigned type; int flags;{ register Textsw_folio folio = FOLIO_FOR_VIEW(view); int is_pending_delete; Es_index first, last_plus_one, delta, insert; is_pending_delete = (EV_SEL_PENDING_DELETE & ev_get_selection(folio->views, &first, &last_plus_one, type) ); if (first >= last_plus_one) return(0); textsw_take_down_caret(folio); insert = (flags & TFC_INSERT) ? ev_get_insert(folio->views) : first; if (is_pending_delete && (first <= insert) && (insert <= last_plus_one)) { delta = textsw_delete_span(view, first, last_plus_one, TXTSW_DS_ADJUST|TXTSW_DS_SHELVE| TXTSW_DS_CLEAR_IF_ADJUST(type)); } else { if (flags & TFC_SEL) { textsw_set_selection(VIEW_REP_TO_ABS(view), ES_INFINITY, ES_INFINITY, type); } delta = 0; } return(delta);}extern Textsw_indextextsw_delete(abstract, first, last_plus_one) Textsw abstract; Es_index first, last_plus_one;{ Textsw_view view = VIEW_ABS_TO_REP(abstract); Textsw_folio folio = FOLIO_FOR_VIEW(view); int result; textsw_take_down_caret(folio); result = textsw_delete_span(view, first, last_plus_one, TXTSW_DS_ADJUST|TXTSW_DS_SHELVE); if (result == ES_CANNOT_SET) { result = 0; } else { result = -result; } return(result);}extern Textsw_indextextsw_erase(abstract, first, last_plus_one) Textsw abstract; Es_index first, last_plus_one;/* This routine is identical to textsw_delete EXCEPT it does not affect the * contents of the shelf (useful for client implementing ^W/^U or mailtool). */{ Textsw_view view = VIEW_ABS_TO_REP(abstract); Textsw_folio folio = FOLIO_FOR_VIEW(view); int result; textsw_take_down_caret(folio); result = textsw_delete_span(view, first, last_plus_one, TXTSW_DS_ADJUST); if (result == ES_CANNOT_SET) { result = 0; } else { result = -result; } return(result);}pkg_private inttextsw_do_insert_makes_visible(view) register Textsw_view view;{ extern int ev_insert_visible_in_view(); register Textsw_folio folio = FOLIO_FOR_VIEW(view); int lower_context; if ((folio->insert_makes_visible == TEXTSW_ALWAYS) && (folio->state & TXTSW_DOING_EVENT) && (!ev_insert_visible_in_view(view->e_view)) ) { lower_context = (int)LINT_CAST( ev_get((Ev_handle)folio->views, EV_CHAIN_LOWER_CONTEXT)); textsw_normalize_internal(view, ev_get_insert(folio->views), ES_INFINITY, 0, lower_context, TXTSW_NI_AT_BOTTOM|TXTSW_NI_NOT_IF_IN_VIEW|TXTSW_NI_MARK); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -