Blame clients/mwm/WmWsmLib/util.c

Packit b099d7
/* $XConsortium: util.c /main/5 1995/07/15 20:38:54 drk $ */
Packit b099d7
/*
Packit b099d7
 * Motif
Packit b099d7
 *
Packit b099d7
 * Copyright (c) 1987-2012, The Open Group. All rights reserved.
Packit b099d7
 *
Packit b099d7
 * These libraries and programs are free software; you can
Packit b099d7
 * redistribute them and/or modify them under the terms of the GNU
Packit b099d7
 * Lesser General Public License as published by the Free Software
Packit b099d7
 * Foundation; either version 2 of the License, or (at your option)
Packit b099d7
 * any later version.
Packit b099d7
 *
Packit b099d7
 * These libraries and programs are distributed in the hope that
Packit b099d7
 * they will be useful, but WITHOUT ANY WARRANTY; without even the
Packit b099d7
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
Packit b099d7
 * PURPOSE. See the GNU Lesser General Public License for more
Packit b099d7
 * details.
Packit b099d7
 *
Packit b099d7
 * You should have received a copy of the GNU Lesser General Public
Packit b099d7
 * License along with these librararies and programs; if not, write
Packit b099d7
 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
Packit b099d7
 * Floor, Boston, MA 02110-1301 USA
Packit b099d7
 * 
Packit b099d7
 */
Packit b099d7
/*
Packit b099d7
 * HISTORY
Packit b099d7
 */
Packit b099d7
Packit b099d7
#include "wsm_proto.h"
Packit b099d7
Packit b099d7
/************************************************************
Packit b099d7
 *
Packit b099d7
 *  Routines for converting from targets to names to atoms.
Packit b099d7
 *
Packit b099d7
 ************************************************************/
Packit b099d7
Packit b099d7
/*	Function Name: _WSMReqTypeToName
Packit b099d7
 *	Description: Given a request type, return its name, used mostly
Packit b099d7
 *                   for error messages.
Packit b099d7
 *	Arguments: req_type - The request type to check.
Packit b099d7
 *	Returns: a string that is the name of the request.
Packit b099d7
 */
Packit b099d7
Packit b099d7
String
Packit b099d7
_WSMReqTypeToName(WSMRequestType req_type)
Packit b099d7
{
Packit b099d7
    switch (req_type) {
Packit b099d7
    case WSM_CONNECT:
Packit b099d7
	return("Connect");
Packit b099d7
    case WSM_EXTENSIONS:
Packit b099d7
	return("Extensions");
Packit b099d7
    case WSM_CONFIG_FMT:
Packit b099d7
	return("Config Format");
Packit b099d7
    case WSM_GET_STATE:
Packit b099d7
	return("Get State");
Packit b099d7
    case WSM_SET_STATE:
Packit b099d7
	return("Set State");
Packit b099d7
    case WSM_REG_WINDOW:
Packit b099d7
	return("Register Window");
Packit b099d7
    default:
Packit b099d7
	return("unknown");
Packit b099d7
    }
Packit b099d7
}
Packit b099d7
Packit b099d7
/*	Function Name: _WSMTargetToReqType
Packit b099d7
 *	Description: Given a target (Atom) and a display, returns the
Packit b099d7
 *                   request type associated with this atom.
Packit b099d7
 *	Arguments: dpy - The display.
Packit b099d7
 *                 target - The atom that needs to be mapped to a request.
Packit b099d7
 *	Returns: The request type.
Packit b099d7
 */
Packit b099d7
Packit b099d7
WSMRequestType
Packit b099d7
_WSMTargetToReqType(Display *dpy, Atom target)
Packit b099d7
{
Packit b099d7
    WSMDispInfo *disp_atoms = _WSMGetDispInfo(dpy);
Packit b099d7
Packit b099d7
    if (target == disp_atoms->connect) 
Packit b099d7
	return(WSM_CONNECT);
Packit b099d7
    if (target == disp_atoms->extensions) 
Packit b099d7
	return(WSM_EXTENSIONS);
Packit b099d7
    if (target == disp_atoms->config_fmt) 
Packit b099d7
	return(WSM_CONFIG_FMT);
Packit b099d7
    if (target == disp_atoms->get_state) 
Packit b099d7
	return(WSM_GET_STATE);
Packit b099d7
    if (target == disp_atoms->set_state) 
Packit b099d7
	return(WSM_SET_STATE);
Packit b099d7
    if (target == disp_atoms->reg_window) 
Packit b099d7
	return(WSM_REG_WINDOW); 
Packit b099d7
Packit b099d7
    /*
Packit b099d7
     * Atom doesn't match any request, generate error message.
Packit b099d7
     */
Packit b099d7
    
Packit b099d7
    return(WSM_UNKNOWN);
Packit b099d7
}
Packit b099d7
Packit b099d7
/*	Function Name: _WSMReqTypeToTarget
Packit b099d7
 *	Description: Given a request type and a display, return the target
Packit b099d7
 *                   (Atom) that maps to it.
Packit b099d7
 *	Arguments: dpy - The display.
Packit b099d7
 *                 req_type - The request type id.
Packit b099d7
 *	Returns: The atom that maps to this request type on this display.
Packit b099d7
 */
Packit b099d7
Packit b099d7
Atom
Packit b099d7
_WSMReqTypeToTarget(Display *dpy, WSMRequestType req_type)
Packit b099d7
{
Packit b099d7
    WSMDispInfo *disp_atoms = _WSMGetDispInfo(dpy);
Packit b099d7
Packit b099d7
    switch (req_type) {
Packit b099d7
    case WSM_CONNECT:
Packit b099d7
	return(disp_atoms->connect);
Packit b099d7
    case WSM_EXTENSIONS:
Packit b099d7
	return(disp_atoms->extensions);
Packit b099d7
    case WSM_CONFIG_FMT:
Packit b099d7
	return(disp_atoms->config_fmt);
Packit b099d7
    case WSM_GET_STATE:
Packit b099d7
	return(disp_atoms->get_state);
Packit b099d7
    case WSM_SET_STATE:
Packit b099d7
	return(disp_atoms->set_state);
Packit b099d7
    case WSM_REG_WINDOW:
Packit b099d7
	return(disp_atoms->reg_window);
Packit b099d7
    default:
Packit b099d7
	break;
Packit b099d7
    }
Packit b099d7
Packit b099d7
    return(None);		/* Universal null atom. */
Packit b099d7
}
Packit b099d7
Packit b099d7
/*	Function Name: _WSMRequiresConfigFormat
Packit b099d7
 *	Description: Returns True if this request requires a valid config
Packit b099d7
 *                   formats.
Packit b099d7
 *	Arguments: request_type - the request type to check.
Packit b099d7
 *	Returns: True if config format required for this request.
Packit b099d7
 */
Packit b099d7
Packit b099d7
Boolean
Packit b099d7
_WSMRequiresConfigFormat(WSMRequestType request_type)
Packit b099d7
{
Packit b099d7
    switch (request_type) {
Packit b099d7
    case WSM_GET_STATE:
Packit b099d7
    case WSM_SET_STATE:
Packit b099d7
    case WSM_REG_WINDOW:
Packit b099d7
	return(True);
Packit b099d7
    default:
Packit b099d7
	break;
Packit b099d7
    }
Packit b099d7
Packit b099d7
    return(False);
Packit b099d7
}
Packit b099d7
Packit b099d7
/*	Function Name: _WSMGetConfigFormatType
Packit b099d7
 *	Description: Gets the config format type for this window.
Packit b099d7
 *	Arguments: win - The window to check.
Packit b099d7
 *	Returns: The config format type that matches the window passed.
Packit b099d7
 */
Packit b099d7
Packit b099d7
WSMConfigFormatType
Packit b099d7
_WSMGetConfigFormatType(Window win)
Packit b099d7
{
Packit b099d7
    if (win == None)
Packit b099d7
	return(WSM_GLOBAL_FMT);
Packit b099d7
Packit b099d7
    if (win & ~WIN_MASK)
Packit b099d7
	return(WSM_ICON_FMT);
Packit b099d7
Packit b099d7
    return(WSM_WINDOW_FMT);
Packit b099d7
}
Packit b099d7
Packit b099d7
/*	Function Name: _WSMGetMatchingAttr
Packit b099d7
 *	Description: Gets the attribute from the format data passed
Packit b099d7
 *                   that matches the the name passed.
Packit b099d7
 *	Arguments: nameq - The name to match stored as a quark.
Packit b099d7
 *                 fmt_data - the config format data to check against.
Packit b099d7
 *	Returns: The attribute information that matches the name passed or NULL
Packit b099d7
 */
Packit b099d7
Packit b099d7
WSMAttribute *
Packit b099d7
_WSMGetMatchingAttr(XrmQuark nameq, WSMConfigFormatData *fmt_data)
Packit b099d7
{
Packit b099d7
    register int i;
Packit b099d7
    WSMAttribute * attr = fmt_data->attr_list;
Packit b099d7
Packit b099d7
    for (i = 0; i < fmt_data->num_attrs; i++, attr++) {
Packit b099d7
	if (nameq == attr->nameq)
Packit b099d7
	    return(attr);
Packit b099d7
    }
Packit b099d7
Packit b099d7
    return(NULL);
Packit b099d7
}
Packit b099d7
Packit b099d7
/*	Function Name: _WSMGetMatchingWinData
Packit b099d7
 *	Description: Gets the window data in the list passed whose name
Packit b099d7
 *                   matches quark passed.
Packit b099d7
 *	Arguments: win_data_top - The top of the window data list.
Packit b099d7
 *                 num - The number of items in the window data list.
Packit b099d7
 *                 nameq - The name to match.
Packit b099d7
 *	Returns: The matching window data or NULL.
Packit b099d7
 */
Packit b099d7
Packit b099d7
WSMWinData *
Packit b099d7
_WSMGetMatchingWinData(WSMWinData *win_data_top, int num, XrmQuark nameq)
Packit b099d7
{
Packit b099d7
    register int i; 
Packit b099d7
    WSMWinData *local = win_data_top;
Packit b099d7
Packit b099d7
    for (i = 0; i < num; i++, local++) {
Packit b099d7
	if (local->nameq == nameq)
Packit b099d7
	    return(local);
Packit b099d7
    }
Packit b099d7
Packit b099d7
    return(NULL);
Packit b099d7
}
Packit b099d7