📄 textsw_once.c
字号:
if (textsw_head) { folio->key_maps = textsw_head->key_maps; } else (void) textsw_parse_rc(folio); /* * Initialize selection service data. * Note that actual hookup will only be attempted when necessary. */ folio->selection_client = TXTSW_NEED_SELN_CLIENT; timerclear(&folio->selection_died); folio->selection_func.function = SELN_FN_ERROR; folio->selection_holder = (Seln_holder *)0; *status = TEXTSW_STATUS_OKAY; folio->state |= TXTSW_INITIALIZED; /* * Link this folio in. */ if (textsw_head) folio->next = textsw_head; textsw_head = folio; folio->temp_filename = NULL; if (textsw_file_name(folio, &name)) { textsw_notify(view, TEXTSW_ACTION_USING_MEMORY, 0); } else textsw_notify(view, TEXTSW_ACTION_LOADED_FILE, name, 0); return(view);Error_Return: free((char *)folio); free((char *)view); if (pw) pw_close(pw); return(0);}pkg_private Textsw_viewtextsw_create_view(folio, rect, left_margin, right_margin) Textsw_folio folio; Rect rect; int left_margin, right_margin;{ struct toolsw *toolsw; Textsw_status status; Pixwin *pw; Textsw_view result = NEW(struct textsw_view_object); if (result) { toolsw = tool_createsubwindow((struct tool *)LINT_CAST(folio->tool) , "", rect.r_width, rect.r_height); if (toolsw == 0) goto Free_Result; toolsw->ts_data = (caddr_t)result; result->magic = TEXTSW_VIEW_MAGIC; result->window_fd = toolsw->ts_windowfd; result->folio = folio; win_setrect(result->window_fd, &rect); pw = textsw_init_view_internal(result); if (pw == 0) goto Free_Toolsw; rect.r_top = rect.r_left = 0; result->e_view = ev_create_view(folio->views, pw, &rect); if (result->e_view == EV_NULL) goto Free_Toolsw; (void) ev_set(result->e_view, EV_LEFT_MARGIN, left_margin, EV_RIGHT_MARGIN, right_margin, 0); (void) ev_set(result->e_view, EV_NO_REPAINT_TIL_EVENT, FALSE, 0); status = textsw_register_view(result); if (status != TEXTSW_STATUS_OKAY) goto Free_Toolsw; result->next = folio->first_view->next; folio->first_view->next = result; } goto Return;Free_Toolsw: if (pw) pw_close(pw); tool_destroysubwindow((struct tool *)LINT_CAST(folio->tool), toolsw);Free_Result: free((char *)result); result = (Textsw_view)0;Return: return(result);}static voidtextsw_set_our_scrollbar_attrs(view) Textsw_view view;{ scrollbar_set(SCROLLBAR_FOR_VIEW(view), SCROLL_NOTIFY_CLIENT, view, SCROLL_OBJECT, view, SCROLL_MARGIN, 0, SCROLL_NORMALIZE, 0, 0);}pkg_private voidtextsw_add_scrollbar_to_view(view, sb) Textsw_view view; Scrollbar sb;{ Scrollbar old_sb; Rect rect; Rect *sb_rect; VALIDATE_VIEW(view); rect = view->e_view->rect; /* Remove the old scrollbar if there is one */ if ((old_sb = SCROLLBAR_FOR_VIEW(view)) != (Scrollbar)0) { /* Update the entity view rect BEFORE destroying the scrollbar */ sb_rect = (Rect *) LINT_CAST(scrollbar_get(old_sb, SCROLL_RECT)); rect.r_width += sb_rect->r_width; if (sb_rect->r_left <= rect.r_left) { /* Scrollbar is West, reclaim space by moving view West */ rect.r_left -= sb_rect->r_width; } scrollbar_destroy(old_sb); } /* Create the new scrollbar */ if (sb == TEXTSW_DEFAULT_SCROLLBAR) { view->scrollbar = scrollbar_create( SCROLL_DIRECTION, SCROLL_VERTICAL, 0); } else { view->scrollbar = sb; if (sb == (Scrollbar)0) { /* Don't move view (and cause paint) iff dying */ if ((view->state & TXTSW_VIEW_DYING) == 0) (void) ev_set(view->e_view, EV_RECT, &rect, 0); return; } } textsw_set_our_scrollbar_attrs(view); sb_rect = (Rect *)LINT_CAST(scrollbar_get(view->scrollbar, SCROLL_RECT)); /* Move the entity view to accomodate the scrollbar */ if (sb_rect->r_left <= rect.r_left) { /* Scrollbar is West, move view East */ rect.r_left += sb_rect->r_width; } /* Always subtract out the width of the scrollbar */ rect.r_width -= sb_rect->r_width; (void) ev_set(view->e_view, EV_RECT, &rect, 0);}static voidtextsw_cleanup_folio(textsw, process_death) register Textsw_folio textsw; int process_death;{ if (!process_death) textsw_init_again(textsw, 0); /* Flush AGAIN info */ /* Clean up of AGAIN info requires valid esh in case of piece frees. * textsw_destroy_esh may try to give Shelf to Seln. Svc., so need * to keep textsw->selection_client around. */ textsw_destroy_esh(textsw, textsw->views->esh); if (process_death) return; /* exit() snaps TCP connection to Seln. Svc., so it will know we are * gone when the process finishes dying. */ if (textsw->selection_client && (textsw->selection_client != TXTSW_NEED_SELN_CLIENT) ) { seln_destroy(textsw->selection_client); textsw->selection_client = 0; } if (textsw->state & TXTSW_OPENED_FONT) { PIXFONT *font = (PIXFONT *) LINT_CAST(ei_get(textsw->views->eih, EI_FONT)); pf_close(font); } textsw->views->eih = ei_destroy(textsw->views->eih); (void) ev_destroy_chain_and_views(textsw->views); textsw->caret_state &= ~TXTSW_CARET_ON; textsw_remove_timer(textsw); /* * Unlink the textsw from the chain. */ if (textsw == textsw_head) { textsw_head = textsw->next; if (textsw->next == 0) { /* * Last textsw in process, so free key_maps. */ Key_map_handle this_key, next_key; for (this_key = textsw->key_maps; this_key; this_key = next_key) { next_key = this_key->next; free((char *)this_key); } } } else { Textsw_folio temp; for (temp = textsw_head; temp; temp = temp->next) { if (textsw == temp->next) { temp->next = textsw->next; break; } } }/* This has been added to compensate missing release of memory for the menu package, menu_table and undo struct. There are more memory leaks in textsw package, but I have no more time to spend on it. This will reduce memory leak from 8k per create/destroy cirle to less then 1k.*/ if(textsw->menu) menu_destroy(textsw->menu); if(textsw->menu_table) free(textsw->menu_table); if(textsw->undo) free(textsw->undo); free((char *)textsw);}static voidtextsw_destroy_view(view) register Textsw_view view;/* * Several pieces of the system and client code know about the * folio->first_view, and thus that actual node cannot be freed unless it is * the only node, in which case the folio must be freed as well. */{ int destroy_folio = FALSE; Textsw_folio folio = FOLIO_FOR_VIEW(view); Textsw_view temp_view; view->state |= TXTSW_VIEW_DYING; /* Warn client that view is dying BEFORE killing it. */ if (folio->notify_level & TEXTSW_NOTIFY_DESTROY_VIEW) textsw_notify(view, TEXTSW_ACTION_DESTROY_VIEW, 0); /* Unlink view from view chain */ if (view == folio->first_view) { folio->first_view = view->next; if (!folio->first_view) destroy_folio = TRUE; } else { FORALL_TEXT_VIEWS(folio, temp_view) { if (temp_view->next == view) { temp_view->next = view->next; break; } } } /* Destroy all of the view's auxillary objects and any back links */ textsw_add_scrollbar_to_view(view, (Scrollbar)0); ev_destroy(view->e_view); textsw_unregister_view(view); pw_close(PIXWIN_FOR_VIEW(view)); /* win_unregister needs valid pw */ free((char *)view); if (destroy_folio) textsw_cleanup_folio(folio, FALSE);}extern voidtextsw_destroy(abstract) Textsw abstract;{ Textsw_folio folio = FOLIO_FOR_VIEW(VIEW_ABS_TO_REP(abstract)); Textsw_view view; /* This loop cannot use FORALL_TEXT_VIEWS because it cannot handle * changes to the view linking during the iteration. */ FOREVER { view = folio->first_view; if (view->next) { textsw_destroy_view(view->next); } else { textsw_destroy_view(view); /* Invalidates *folio */ break; } }}extern Notify_valuetextsw_notify_destroy(abstract, status) Textsw abstract; register Destroy_status status;{ register Textsw_view view = VIEW_ABS_TO_REP(abstract); register Textsw_folio folio = FOLIO_FOR_VIEW(view); register int tool_fd; int destroy_next_view_too = FALSE; switch (status) { case DESTROY_CHECKING: if (textsw_has_been_modified(abstract) && (!folio->first_view->next || folio->state & TXTSW_DESTROY_ALL_VIEWS) && (folio->ignore_limit != TEXTSW_INFINITY)) { Event event; tool_fd = win_get_fd(folio->tool); if (tool_fd == -1) { (void) notify_veto_destroy((Notify_client)abstract); } else { extern void tool_veto_destroy(); int old_fcntl_flags = fcntl(tool_fd, F_GETFL, 0); (void) fcntl(tool_fd, F_SETFL, FNDELAY); (void) alert_prompt( (Frame)window_get( WINDOW_FROM_VIEW(view), WIN_OWNER), &event, ALERT_MESSAGE_STRINGS, "Unable to Quit. The text has been edited.", "Please Save Current File or Store as New File", "or Undo All Edits before quiting.", 0, ALERT_BUTTON_YES, "Continue", ALERT_TRIGGER, ACTION_STOP, 0); (void) fcntl(tool_fd, F_SETFL, old_fcntl_flags); tool_veto_destroy((struct tool *)LINT_CAST(folio->tool)); } } break; case DESTROY_PROCESS_DEATH: if (view == folio->first_view) textsw_cleanup_folio(folio, TRUE); break; case DESTROY_CLEANUP: default: /* Conservative in face of new cases. */ destroy_next_view_too = (folio->state & TXTSW_DESTROY_ALL_VIEWS) && folio->first_view->next; textsw_destroy_view(view); if (destroy_next_view_too) window_destroy((Window)LINT_CAST(folio->first_view)); break; } return(NOTIFY_DONE);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -