Debian Codegraph @

clients/mwm/WmWsmLib/util.c

raw
1 /* $XConsortium: util.c /main/5 1995/07/15 20:38:54 drk $ */
2 /*
3 * Motif
4 *
5 * Copyright (c) 1987-2012, The Open Group. All rights reserved.
6 *
7 * These libraries and programs are free software; you can
8 * redistribute them and/or modify them under the terms of the GNU
9 * Lesser General Public License as published by the Free Software
10 * Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * These libraries and programs are distributed in the hope that
14 * they will be useful, but WITHOUT ANY WARRANTY; without even the
15 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU Lesser General Public License for more
17 * details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with these librararies and programs; if not, write
21 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
22 * Floor, Boston, MA 02110-1301 USA
23 *
24 */
25 /*
26 * HISTORY
27 */
28
29 #include "wsm_proto.h"
30
31 /************************************************************
32 *
33 * Routines for converting from targets to names to atoms.
34 *
35 ************************************************************/
36
37 /* Function Name: _WSMReqTypeToName
38 * Description: Given a request type, return its name, used mostly
39 * for error messages.
40 * Arguments: req_type - The request type to check.
41 * Returns: a string that is the name of the request.
42 */
43
44 String
45 _WSMReqTypeToName(WSMRequestType req_type)
46 {
47 switch (req_type) {
48 case WSM_CONNECT:
49 return("Connect");
50 case WSM_EXTENSIONS:
51 return("Extensions");
52 case WSM_CONFIG_FMT:
53 return("Config Format");
54 case WSM_GET_STATE:
55 return("Get State");
56 case WSM_SET_STATE:
57 return("Set State");
58 case WSM_REG_WINDOW:
59 return("Register Window");
60 default:
61 return("unknown");
62 }
63 }
64
65 /* Function Name: _WSMTargetToReqType
66 * Description: Given a target (Atom) and a display, returns the
67 * request type associated with this atom.
68 * Arguments: dpy - The display.
69 * target - The atom that needs to be mapped to a request.
70 * Returns: The request type.
71 */
72
73 WSMRequestType
74 _WSMTargetToReqType(Display *dpy, Atom target)
75 {
76 WSMDispInfo *disp_atoms = _WSMGetDispInfo(dpy);
77
78 if (target == disp_atoms->connect)
79 return(WSM_CONNECT);
80 if (target == disp_atoms->extensions)
81 return(WSM_EXTENSIONS);
82 if (target == disp_atoms->config_fmt)
83 return(WSM_CONFIG_FMT);
84 if (target == disp_atoms->get_state)
85 return(WSM_GET_STATE);
86 if (target == disp_atoms->set_state)
87 return(WSM_SET_STATE);
88 if (target == disp_atoms->reg_window)
89 return(WSM_REG_WINDOW);
90
91 /*
92 * Atom doesn't match any request, generate error message.
93 */
94
95 return(WSM_UNKNOWN);
96 }
97
98 /* Function Name: _WSMReqTypeToTarget
99 * Description: Given a request type and a display, return the target
100 * (Atom) that maps to it.
101 * Arguments: dpy - The display.
102 * req_type - The request type id.
103 * Returns: The atom that maps to this request type on this display.
104 */
105
106 Atom
107 _WSMReqTypeToTarget(Display *dpy, WSMRequestType req_type)
108 {
109 WSMDispInfo *disp_atoms = _WSMGetDispInfo(dpy);
110
111 switch (req_type) {
112 case WSM_CONNECT:
113 return(disp_atoms->connect);
114 case WSM_EXTENSIONS:
115 return(disp_atoms->extensions);
116 case WSM_CONFIG_FMT:
117 return(disp_atoms->config_fmt);
118 case WSM_GET_STATE:
119 return(disp_atoms->get_state);
120 case WSM_SET_STATE:
121 return(disp_atoms->set_state);
122 case WSM_REG_WINDOW:
123 return(disp_atoms->reg_window);
124 default:
125 break;
126 }
127
128 return(None); /* Universal null atom. */
129 }
130
131 /* Function Name: _WSMRequiresConfigFormat
132 * Description: Returns True if this request requires a valid config
133 * formats.
134 * Arguments: request_type - the request type to check.
135 * Returns: True if config format required for this request.
136 */
137
138 Boolean
139 _WSMRequiresConfigFormat(WSMRequestType request_type)
140 {
141 switch (request_type) {
142 case WSM_GET_STATE:
143 case WSM_SET_STATE:
144 case WSM_REG_WINDOW:
145 return(True);
146 default:
147 break;
148 }
149
150 return(False);
151 }
152
153 /* Function Name: _WSMGetConfigFormatType
154 * Description: Gets the config format type for this window.
155 * Arguments: win - The window to check.
156 * Returns: The config format type that matches the window passed.
157 */
158
159 WSMConfigFormatType
160 _WSMGetConfigFormatType(Window win)
161 {
162 if (win == None)
163 return(WSM_GLOBAL_FMT);
164
165 if (win & ~WIN_MASK)
166 return(WSM_ICON_FMT);
167
168 return(WSM_WINDOW_FMT);
169 }
170
171 /* Function Name: _WSMGetMatchingAttr
172 * Description: Gets the attribute from the format data passed
173 * that matches the the name passed.
174 * Arguments: nameq - The name to match stored as a quark.
175 * fmt_data - the config format data to check against.
176 * Returns: The attribute information that matches the name passed or NULL
177 */
178
179 WSMAttribute *
180 _WSMGetMatchingAttr(XrmQuark nameq, WSMConfigFormatData *fmt_data)
181 {
182 register int i;
183 WSMAttribute * attr = fmt_data->attr_list;
184
185 for (i = 0; i < fmt_data->num_attrs; i++, attr++) {
186 if (nameq == attr->nameq)
187 return(attr);
188 }
189
190 return(NULL);
191 }
192
193 /* Function Name: _WSMGetMatchingWinData
194 * Description: Gets the window data in the list passed whose name
195 * matches quark passed.
196 * Arguments: win_data_top - The top of the window data list.
197 * num - The number of items in the window data list.
198 * nameq - The name to match.
199 * Returns: The matching window data or NULL.
200 */
201
202 WSMWinData *
203 _WSMGetMatchingWinData(WSMWinData *win_data_top, int num, XrmQuark nameq)
204 {
205 register int i;
206 WSMWinData *local = win_data_top;
207
208 for (i = 0; i < num; i++, local++) {
209 if (local->nameq == nameq)
210 return(local);
211 }
212
213 return(NULL);
214 }
215