16c321187Smrg/*
26c321187Smrg
36c321187SmrgCopyright 1989, 1998  The Open Group
46c321187Smrg
56c321187SmrgPermission to use, copy, modify, distribute, and sell this software and its
66c321187Smrgdocumentation for any purpose is hereby granted without fee, provided that
76c321187Smrgthe above copyright notice appear in all copies and that both that
86c321187Smrgcopyright notice and this permission notice appear in supporting
96c321187Smrgdocumentation.
106c321187Smrg
116c321187SmrgThe above copyright notice and this permission notice shall be included in
126c321187Smrgall copies or substantial portions of the Software.
136c321187Smrg
146c321187SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
156c321187SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
166c321187SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
176c321187SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
186c321187SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
196c321187SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
206c321187Smrg
216c321187SmrgExcept as contained in this notice, the name of The Open Group shall not be
226c321187Smrgused in advertising or otherwise to promote the sale, use or other dealings
236c321187Smrgin this Software without prior written authorization from The Open Group.
246c321187Smrg
256c321187Smrg*/
266c321187Smrg
276c321187Smrg/*
286c321187Smrg * Author:  Chris D. Peterson, MIT X Consortium
296c321187Smrg */
306c321187Smrg
316c321187Smrg/************************************************************
326c321187Smrg
336c321187Smrg		The Editres Protocol
346c321187Smrg
356c321187Smrg
366c321187Smrg  The Client message sent to the application is:
376c321187Smrg
386c321187Smrg  ATOM = "ResEditor" 		--- RES_EDITOR_NAME
396c321187Smrg
406c321187Smrg  FORMAT = 32                   --- RES_EDIT_SEND_EVENT_FORMAT
416c321187Smrg
426c321187Smrg  l[0] = timestamp
436c321187Smrg  l[1] = command atom name
446c321187Smrg  l[2] = ident of command
456c321187Smrg  l[3] = protocol version number to use
466c321187Smrg
476c321187Smrg
486c321187Smrg
496c321187Smrg  The binary protocol has the following format:
506c321187Smrg
519dedec0cSmrg	Card8:		8-bit unsigned integer
529dedec0cSmrg	Card16:		16-bit unsigned integer
539dedec0cSmrg	Card32:		32-bit unsigned integer
546c321187Smrg	Int16:		16-bit signed integer
556c321187Smrg	Window:		32-bit value
566c321187Smrg	Widget:		32-bit value
576c321187Smrg	String8:        ListOfCard8
580cc2eac3Smrg
596c321187Smrg	[a][b][c] represent an exclusive list of choices.
606c321187Smrg
610cc2eac3Smrg	All widgets are passed as a list of widgets, containing the
629dedec0cSmrg	full instance heirarchy of this widget.  The hierarchy is ordered
636c321187Smrg	from parent to child.  Thus the first element of each list is
646c321187Smrg	the root of the widget tree (this makes verifying that the widget
656c321187Smrg	still exists, MUCH faster).
666c321187Smrg
676c321187Smrg	ListOfFoo comprises a list of things in the following format:
680cc2eac3Smrg
696c321187Smrg	number:			Card16
706c321187Smrg	<number> things:	????
710cc2eac3Smrg
726c321187Smrg  This is a synchronous protocol, every request MUST be followed by a
730cc2eac3Smrg  reply.
746c321187Smrg
756c321187Smrg  Request:
766c321187Smrg
776c321187Smrg	Serial Number:	Card8
786c321187Smrg	Op Code:	Card8 -	{ SendWidgetTree = 0,
796c321187Smrg				  SetValues = 1,
806c321187Smrg				  GetResources = 2,
816c321187Smrg				  GetGeometry = 3,
826c321187Smrg				  FindChild = 4,
836c321187Smrg				  GetValues = 5 }
846c321187Smrg	Length:		Card32
850cc2eac3Smrg	Data:
866c321187Smrg
876c321187Smrg   Reply:
886c321187Smrg
896c321187Smrg	Serial Number:	Card8
906c321187Smrg	Type:		Card8 - { Formatted = 0,
916c321187Smrg	                          Unformatted = 1,
926c321187Smrg				  ProtocolMismatch = 2
936c321187Smrg				}
946c321187Smrg	Length:		Card32
956c321187Smrg
966c321187Smrg
976c321187Smrg   Byte Order:
986c321187Smrg
996c321187Smrg	All Fields are MSB -> LSB
1006c321187Smrg
1016c321187Smrg    Data:
1026c321187Smrg
1036c321187Smrg    	Formatted:
1046c321187Smrg
1056c321187Smrg        	The data contains the reply information for the request as
1066c321187Smrg		specified below if the reply type is "Formatted".  The return
1076c321187Smrg		values for the other reply types are shown below.
1086c321187Smrg
1096c321187Smrg        Unformatted:
1106c321187Smrg
1116c321187Smrg		Message:	String8
1126c321187Smrg
1136c321187Smrg	ProtocolMismatch:
1146c321187Smrg
1156c321187Smrg		RequestedVersion:   	Card8
1166c321187Smrg
1176c321187Smrg------------------------------------------------------------
1186c321187Smrg
1196c321187Smrg   SendWidgetTree:
1206c321187Smrg
1216c321187Smrg	--->
1226c321187Smrg
1236c321187Smrg	Number of Entries:	Card16
1246c321187Smrg	Entry:
1256c321187Smrg		widget:		ListOfWidgets
1266c321187Smrg		name:		String8
1276c321187Smrg		class:		String8
1286c321187Smrg		window:		Card32
1296c321187Smrg         	toolkit:        String8
1306c321187Smrg
1319dedec0cSmrg        SendWidgetTree returns the toolkit type, and a fully specified list
1326c321187Smrg        of widgets for each widget in the tree.  This is enough information
1339dedec0cSmrg        to completely reconstruct the entire widget hierarchy.
1346c321187Smrg
1350cc2eac3Smrg	The window return value contains the Xid of the window currently
1366c321187Smrg	used by this widget.  If the widget is unrealized then 0 is returned,
1376c321187Smrg	and if widget is a non-windowed object a value of 2 is returned.
1386c321187Smrg
1396c321187Smrg   SetValues:
1406c321187Smrg
1416c321187Smrg	name:	String8
1426c321187Smrg	type:	String8
1436c321187Smrg	value:  String8
1446c321187Smrg	Number of Entries:	Card16
1456c321187Smrg	Entry:
1466c321187Smrg		widget:		ListOfWidgets
1476c321187Smrg
1486c321187Smrg	--->
1496c321187Smrg
1506c321187Smrg	Number of Entries:	Card16
1516c321187Smrg	Entry:
1526c321187Smrg		widget:		ListOfWidgets
1536c321187Smrg		message:	String8
1546c321187Smrg
1550cc2eac3Smrg	SetValues will allow the same resource to be set on a number of
1566c321187Smrg	widgets.  This function will return an error message if the SetValues
1576c321187Smrg	request caused an Xt error.
1580cc2eac3Smrg
1596c321187Smrg  GetValues:
1606c321187Smrg
1610cc2eac3Smrg        names:                ListOfString8
1626c321187Smrg        widget:               Widget
1636c321187Smrg
1646c321187Smrg        --->
1656c321187Smrg	novalues:             ListOfCard16
1666c321187Smrg	values:               ListOfString8
1670cc2eac3Smrg
1680cc2eac3Smrg        GetValues will allow a number of resource values to be read
1696c321187Smrg        on a particular widget.  The request specifies the names of
1706c321187Smrg	the resources wanted and the widget id these resources are
1716c321187Smrg	from.  The reply returns a list of indices from the requests
1726c321187Smrg	name list of resources for which a value can not be returned.
1736c321187Smrg	It also returns a list of returned values, in the order of the
1746c321187Smrg        requests names list, skipping those indices present in novalues.
1756c321187Smrg
1766c321187Smrg   GetResources:
1776c321187Smrg
1786c321187Smrg	Number of Entries:	Card16
1796c321187Smrg	Entry
1806c321187Smrg		widget:		ListOfWidgets:
1816c321187Smrg
1826c321187Smrg	---->
1836c321187Smrg
1846c321187Smrg	Number of Entries:	Card16
1856c321187Smrg	Entry
1866c321187Smrg		Widget:			ListOfWidgets:
1876c321187Smrg		Error:			Bool
1886c321187Smrg
1896c321187Smrg		[ Message:		String 8 ]
1906c321187Smrg		[ Number of Resources:	Card16
1916c321187Smrg		Resource:
1926c321187Smrg			Kind:	{normal, constraint}
1936c321187Smrg			Name:	String8
1940cc2eac3Smrg			Class:	String8
1956c321187Smrg			Type:	String8 ]
1966c321187Smrg
1979dedec0cSmrg	GetResources retrieves the kind, name, class, and type for every
1989dedec0cSmrg	widget passed to it.  If an error occurred with the resource fetch
1996c321187Smrg	Error will be set to True for the given widget and a message
2006c321187Smrg	is returned rather than the resource info.
2016c321187Smrg
2026c321187Smrg  GetGeometry:
2036c321187Smrg
2046c321187Smrg	Number of Entries:	Card16
2056c321187Smrg	Entry
2066c321187Smrg		Widget:		ListOfWidgets:
2076c321187Smrg
2086c321187Smrg	---->
2096c321187Smrg
2106c321187Smrg	Number of Entries:	Card16
2116c321187Smrg	Entry
2126c321187Smrg		Widget:			ListOfWidgets:
2136c321187Smrg		Error:			Bool
2146c321187Smrg
2156c321187Smrg		[ message:		String 8 ]
2166c321187Smrg		[ mapped:       Boolean
2176c321187Smrg		  X: 		Int16
2186c321187Smrg		  Y:  		Int16
2196c321187Smrg		  Width: 	Card16
2206c321187Smrg	      	  Height:	Card16
2216c321187Smrg		  BorderWidth:	Card16 ]
2226c321187Smrg
2239dedec0cSmrg	GetGeometry retrieves the mapping state, x, y, width, height
2249dedec0cSmrg	and border width for each widget specified.  If an error occurred
2250cc2eac3Smrg	with the geometry fetch "Error" will be set to True for the given
2260cc2eac3Smrg	widget and a message is returned rather than the geometry info.
2279dedec0cSmrg	X an Y correspond to the root coordinates of the upper left corner
2286c321187Smrg	of the widget (outside the window border).
2290cc2eac3Smrg
2306c321187Smrg  FindChild:
2316c321187Smrg
2326c321187Smrg	Widget:		ListOfWidgets
2336c321187Smrg	X:		Int16
2346c321187Smrg	Y:		Int16
2350cc2eac3Smrg
2366c321187Smrg	--->
2376c321187Smrg
2386c321187Smrg	Widget:		ListOfWidgets
2396c321187Smrg
2409dedec0cSmrg	FindChild returns a descendent of the widget specified that
2416c321187Smrg	is at the root coordinates specified.
2426c321187Smrg
2436c321187Smrg	NOTE:
2446c321187Smrg
2456c321187Smrg	The returned widget is undefined if the point is contained in
2466c321187Smrg	two or more mapped widgets, or in two overlapping Rect objs.
2476c321187Smrg
2486c321187Smrg  GetValues:
2496c321187Smrg
2500cc2eac3Smrg        names:                ListOfString8
2516c321187Smrg        widget:               Widget
2526c321187Smrg
2536c321187Smrg        --->
2540cc2eac3Smrg
2556c321187Smrg	values:               ListOfString8
2566c321187Smrg
2570cc2eac3Smrg        GetValues will allow a number of resource values to be read
2580cc2eac3Smrg        on a particular widget.  Currently only InterViews 3.0.1 Styles
2596c321187Smrg	and their attributes are supported.  In addition, the current
2606c321187Smrg	user interface  only supports the return of 1 resource.  The ability
2616c321187Smrg	to specify and return multiple resources is defined for future editres
2626c321187Smrg	interfaces where some or all of a widgets resource values are returned
2630cc2eac3Smrg	and displayed at once.
2646c321187Smrg
2656c321187Smrg
2666c321187Smrg************************************************************/
2676c321187Smrg
2686c321187Smrg#include <X11/Intrinsic.h>
2696c321187Smrg#include <X11/Xfuncproto.h>
2706c321187Smrg
2716c321187Smrg#define XER_NBBY 8		/* number of bits in a byte */
2726c321187Smrg#define BYTE_MASK 255
2736c321187Smrg
2746c321187Smrg#define HEADER_SIZE 6
2756c321187Smrg
2766c321187Smrg#define EDITRES_IS_OBJECT 2
2776c321187Smrg#define EDITRES_IS_UNREALIZED 0
2786c321187Smrg
2796c321187Smrg/*
2806c321187Smrg * Format for atoms
2816c321187Smrg */
2826c321187Smrg#define EDITRES_FORMAT             8
2836c321187Smrg#define EDITRES_SEND_EVENT_FORMAT 32
2846c321187Smrg
2856c321187Smrg/*
2866c321187Smrg * Atoms
2876c321187Smrg */
2886c321187Smrg#define EDITRES_NAME         "Editres"
2896c321187Smrg#define EDITRES_COMMAND_ATOM "EditresCommand"
2906c321187Smrg#define EDITRES_COMM_ATOM    "EditresComm"
2916c321187Smrg#define EDITRES_CLIENT_VALUE "EditresClientVal"
2926c321187Smrg#define EDITRES_PROTOCOL_ATOM "EditresProtocol"
2936c321187Smrg
2946c321187Smrgtypedef enum {
2956c321187Smrg  SendWidgetTree = 0,
2966c321187Smrg	       SetValues      = 1,
2976c321187Smrg	       GetResources   = 2,
2980cc2eac3Smrg	       GetGeometry    = 3,
2996c321187Smrg	       FindChild      = 4,
3006c321187Smrg	       GetValues      = 5
3016c321187Smrg} EditresCommand;
3026c321187Smrg
3036c321187Smrgtypedef enum {
3046c321187Smrg  NormalResource     = 0,
3056c321187Smrg  ConstraintResource = 1
3066c321187Smrg} ResourceType;
3076c321187Smrg
3086c321187Smrg/*
3096c321187Smrg * The type of a resource identifier
3106c321187Smrg */
3116c321187Smrgtypedef unsigned char ResIdent;
3126c321187Smrg
3136c321187Smrgtypedef enum {
3146c321187Smrg  PartialSuccess   = 0,
3156c321187Smrg  Failure	   = 1,
3166c321187Smrg  ProtocolMismatch = 2
3176c321187Smrg} EditResError;
3186c321187Smrg
3196c321187Smrgtypedef struct _WidgetInfo {
3206c321187Smrg    unsigned short num_widgets;
3216c321187Smrg  unsigned long *ids;
3226c321187Smrg    Widget real_widget;
3236c321187Smrg} WidgetInfo;
3246c321187Smrg
3256c321187Smrgtypedef struct _ProtocolStream {
3266c321187Smrg    unsigned long size, alloc;
3276c321187Smrg    unsigned char *real_top, *top, *current;
3286c321187Smrg} ProtocolStream;
3296c321187Smrg
3306c321187Smrg/************************************************************
3316c321187Smrg * Function definitions for reading and writing protocol requests
3326c321187Smrg ************************************************************/
3336c321187Smrg_XFUNCPROTOBEGIN
3346c321187Smrg
3356c321187Smrgvoid _XEditResPutString8
3366c321187Smrg(
3376c321187Smrg ProtocolStream		*stream,
3380cc2eac3Smrg _Xconst char		*str
3396c321187Smrg );
3406c321187Smrg
3416c321187Smrgvoid _XEditResPut8
3426c321187Smrg(
3436c321187Smrg ProtocolStream		*stream,
3446c321187Smrg unsigned int		value
3456c321187Smrg );
3466c321187Smrg
3476c321187Smrgvoid _XEditResPut16
3486c321187Smrg(
3496c321187Smrg ProtocolStream		*stream,
3506c321187Smrg unsigned int		value
3516c321187Smrg );
3526c321187Smrg
3536c321187Smrgvoid _XEditResPut32
3546c321187Smrg(
3556c321187Smrg ProtocolStream		*stream,
3566c321187Smrg unsigned long		value
3576c321187Smrg );
3586c321187Smrg
3596c321187Smrgvoid _XEditResPutWidgetInfo
3606c321187Smrg(
3616c321187Smrg ProtocolStream		*stream,
3626c321187Smrg WidgetInfo		*info
3636c321187Smrg );
3646c321187Smrg
3656c321187Smrgvoid _XEditResResetStream
3666c321187Smrg(
3676c321187Smrg ProtocolStream		*stream
3686c321187Smrg );
3696c321187Smrg
3706c321187SmrgBool _XEditResGet8
3716c321187Smrg(
3726c321187Smrg ProtocolStream		*stream,
3736c321187Smrg unsigned char		*value
3746c321187Smrg );
3756c321187Smrg
3766c321187SmrgBool _XEditResGet16
3776c321187Smrg(
3786c321187Smrg ProtocolStream		*stream,
3796c321187Smrg unsigned short		*value
3806c321187Smrg );
3816c321187Smrg
3826c321187SmrgBool _XEditResGetSigned16
3836c321187Smrg(
3846c321187Smrg ProtocolStream		*stream,
3856c321187Smrg short			*value
3866c321187Smrg );
3876c321187Smrg
3886c321187SmrgBool _XEditResGet32
3896c321187Smrg(
3906c321187Smrg ProtocolStream		*stream,
3916c321187Smrg unsigned long		*value
3926c321187Smrg );
3936c321187Smrg
3946c321187SmrgBool _XEditResGetString8
3956c321187Smrg(
3966c321187Smrg ProtocolStream		*stream,
3976c321187Smrg char			**str
3986c321187Smrg );
3996c321187Smrg
4006c321187SmrgBool _XEditResGetWidgetInfo
4016c321187Smrg(
4026c321187Smrg ProtocolStream		*stream,
4036c321187Smrg WidgetInfo		*info
4046c321187Smrg );
4056c321187Smrg
4066c321187Smrg_XFUNCPROTOEND
407