⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 panel_seln.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
#ifndef lint#ifdef sccsstatic char     sccsid[] = "@(#)panel_seln.c 1.1 92/07/30 Copyr 1984 Sun Micro";#endif#endif/***********************************************************************//* panel_seln.c                                                        *//* Copyright (c) 1984 by Sun Microsystems, Inc.                        *//***********************************************************************/#include <suntool/panel_impl.h>#include <sunwindow/sun.h>#include <suntool/selection_attributes.h>#define MIN_SELN_TIMEOUT        0#define DEFAULT_SELN_TIMEOUT    10	/* 10 seconds */#define MAX_SELN_TIMEOUT        300	/* 5 minutes */extern void     (*panel_seln_inform_proc) (),                (*panel_seln_destroy_proc) ();static void     panel_seln_destroy_info(),                panel_seln_function(),                panel_seln_get(),                panel_seln_put();static void     panel_seln_report_event(), check_cache();static Seln_result panel_seln_request();/* * panel_seln_init -- register with the selection service */voidpanel_seln_init(panel)    register panel_handle panel;{    /*     * static so we only try to contact the selection service once.     */    static          no_selection_service;	/* Defaults to FALSE */    int             selection_timeout;    register panel_selection_handle primary = panel_seln(panel, SELN_PRIMARY);    register panel_selection_handle secondary = panel_seln(panel, SELN_SECONDARY);    register panel_selection_handle caret = panel_seln(panel, SELN_CARET);    register panel_selection_handle shelf = panel_seln(panel, SELN_SHELF);    /*     * don't register with the selection service unless we are using the     * notifier (i.e. panel_begin() was used instead of panel_create().     */    if (!using_notifier(panel) || no_selection_service)	return;    selection_timeout = defaults_get_integer_check("/SunView/Selection_Timeout",	       DEFAULT_SELN_TIMEOUT, MIN_SELN_TIMEOUT, MAX_SELN_TIMEOUT, 0);    seln_use_timeout(selection_timeout);	/* set selection timeout */    panel->seln_client = seln_create(panel_seln_function, panel_seln_request,		                     (char *) (LINT_CAST(panel)));    if (!panel->seln_client) {	no_selection_service = TRUE;	return;    }    panel_seln_destroy_proc = panel_seln_destroy_info;    panel_seln_inform_proc = (void (*) ()) panel_seln_report_event;    primary->rank = SELN_PRIMARY;    primary->is_null = TRUE;    primary->ip = (panel_item_handle) 0;    secondary->rank = SELN_SECONDARY;    secondary->is_null = TRUE;    secondary->ip = (panel_item_handle) 0;    caret->rank = SELN_CARET;    caret->is_null = TRUE;    caret->ip = (panel_item_handle) 0;    shelf->rank = SELN_SHELF;    shelf->is_null = TRUE;    shelf->ip = (panel_item_handle) 0;}/* * panel_seln_inquire -- inquire about the holder of a selection */Seln_holderpanel_seln_inquire(panel, rank)    panel_handle    panel;    Seln_rank       rank;{    /*     * always ask the service, even if we have not setup contact before (i.e.     * no text items). This could happen if some other item has     * PANEL_ACCEPT_KEYSTROKE on. if (!panel->seln_client) holder.rank =     * SELN_UNKNOWN; else     */    return(seln_inquire(rank));}static voidpanel_seln_report_event(panel, event)    panel_handle    panel;    Event          *event;{    seln_report_event(panel->seln_client, event);    if (!panel->seln_client)	return;    check_cache(panel, SELN_PRIMARY);    check_cache(panel, SELN_SECONDARY);    check_cache(panel, SELN_CARET);}static voidcheck_cache(panel, rank)    register panel_handle panel;    register Seln_rank rank;{    Seln_holder     holder;    if (panel_seln(panel, rank)->ip) {	holder = seln_inquire(rank);	if (!seln_holder_same_client(&holder, (char *) (LINT_CAST(panel))))	    panel_seln_cancel(panel, rank);    }}/* * panel_seln_acquire -- acquire the selection and update the state */voidpanel_seln_acquire(panel, ip, rank, is_null)    register panel_handle panel;    Seln_rank       rank;    panel_item_handle ip;    int             is_null;{    register panel_selection_handle selection;    if (!panel->seln_client)	return;    switch (rank) {	case SELN_PRIMARY:	case SELN_SECONDARY:	case SELN_CARET:	    selection = panel_seln(panel, rank);	    /*	     * if we already own the selection, don't ask the service for it.	     */	    if (ip && selection->ip == ip)		break;	    /* otherwise fall through ... */	default:	    rank = seln_acquire(panel->seln_client, rank);	    switch (rank) {		case SELN_PRIMARY:		case SELN_SECONDARY:		case SELN_CARET:		case SELN_SHELF:		    selection = panel_seln(panel, rank);		    break;		default:		    return;	    }	    break;    }    /* if there was an old selection, de-hilite it */    if (selection->ip)	panel_seln_dehilite(selection->ip, rank);    /* record the selection & hilite it if it's not null */    selection->ip = ip;    selection->is_null = is_null;    if (!is_null)	panel_seln_hilite(selection);}/* * panel_seln_cancel -- cancel the current selection. */voidpanel_seln_cancel(panel, rank)    panel_handle    panel;    Seln_rank       rank;{    panel_selection_handle selection = panel_seln(panel, rank);    if (!panel->seln_client || !selection->ip)	return;    /* de-hilite the selection */    panel_seln_dehilite(selection->ip, rank);    panel_clear_pending_delete(rank);    selection->ip = (panel_item_handle) 0;    (void) seln_done(panel->seln_client, rank);}/* * panel_seln_destroy -- destroy myself as a selection client */static voidpanel_seln_destroy_info(panel)    register panel_handle panel;{    if (!panel->seln_client)	return;    /*     * cancel PRIMARY and SECONDARY to get rid of possible highlighting     */    panel_seln_cancel(panel, SELN_PRIMARY);    panel_seln_cancel(panel, SELN_SECONDARY);    if (panel->shelf) {	free(panel->shelf);	panel->shelf = (char *) 0;    }    seln_destroy(panel->seln_client);}/* Callback routines */static voidpanel_seln_function(panel, buffer)    register panel_handle panel;    register Seln_function_buffer *buffer;{    Seln_holder    *holder;    panel_selection_handle selection;    /* A function key has gone up -- handle it. */    if (!panel->caret)	return;    switch (seln_figure_response(buffer, &holder)) {    case SELN_IGNORE:	break;    case SELN_REQUEST:	panel_seln_process_request(panel, buffer, holder);	break;    case SELN_SHELVE:	selection = panel_seln(panel, buffer->addressee_rank);	panel_seln_shelve(panel, selection, buffer->addressee_rank);	break;    case SELN_FIND:	(void) seln_ask(holder,			SELN_REQ_COMMIT_PENDING_DELETE,			SELN_REQ_YIELD, 0,			0);	break;    case SELN_DELETE:	selection = panel_seln(panel, buffer->addressee_rank);	if (buffer->addressee_rank == SELN_PRIMARY ||	    buffer->addressee_rank == SELN_SECONDARY) {	    if (selection->ip && !selection->is_null) {	        panel_seln_shelve(panel, selection, buffer->addressee_rank);	        panel_seln_delete(selection->ip, buffer->addressee_rank);	        selection->ip = (panel_item_handle) 0;	        (void) seln_done(panel->seln_client, buffer->addressee_rank);	    }	}	break;    default:	/* ignore anything else */	break;    }}/* * Respond to a request about my selections. */static          Seln_resultpanel_seln_request(attr, context, max_length)    Seln_attribute  attr;    register Seln_replier_data *context;    int             max_length;{    register panel_handle panel = (panel_handle) LINT_CAST(context->client_data);    register panel_selection_handle selection;    char           *selection_string = (char *) 0;    char            save_char;    u_long          selection_length;    Seln_result     result;    selection = panel_seln(panel, context->rank);    switch (context->rank) {    case SELN_PRIMARY:    case SELN_SECONDARY:	if (selection->ip && !selection->is_null)	    panel_get_text_selection(selection->ip, &selection_string,				     &selection_length, context->rank);	break;    case SELN_SHELF:	selection_string = panel->shelf ? panel->shelf : "";	selection_length = strlen(selection_string);	break;    default:	break;    }    switch (attr) {    case SELN_REQ_BYTESIZE:	if (!selection_string)	    return SELN_DIDNT_HAVE;	*context->response_pointer++ = (caddr_t) selection_length;	return SELN_SUCCESS;    case SELN_REQ_CONTENTS_ASCII:	{	    char           *temp = (char *) context->response_pointer;	    int             count;	    if (!selection_string)		return SELN_DIDNT_HAVE;	    count = selection_length;	    if (count <= max_length) {		bcopy(selection_string, temp, count);		temp += count;		while ((unsigned) temp % sizeof(*context->response_pointer))		    *temp++ = '\0';		context->response_pointer = (char **) LINT_CAST(temp);		*context->response_pointer++ = 0;		return SELN_SUCCESS;	    }	    return SELN_FAILED;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -