Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / wwl / include / WWL / wwl.h
1 /*
2  * $TOG: wwl.h /main/4 1998/04/17 11:46:09 mgreess $
3  *
4  * Copyright (c) 1991 HaL Computer Systems, Inc.  All rights reserved.
5  * UNPUBLISHED -- rights reserved under the Copyright Laws of the United
6  * States.  Use of a copyright notice is precautionary only and does not
7  * imply publication or disclosure.
8  * 
9  * This software contains confidential information and trade secrets of HaL
10  * Computer Systems, Inc.  Use, disclosure, or reproduction is prohibited
11  * without the prior express written permission of HaL Computer Systems, Inc.
12  * 
13  *                         RESTRICTED RIGHTS LEGEND
14  * Use, duplication, or disclosure by the Government is subject to
15  * restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
16  * Technical Data and Computer Software clause at DFARS 252.227-7013.
17  *                        HaL Computer Systems, Inc.
18  *                  1315 Dell Avenue, Campbell, CA  95008
19  * 
20  */
21
22 #ifndef wwl_h
23 #define wwl_h
24
25 // Widget Wrapper Library by:
26 //
27 //    ___    0  Jean-Daniel Fekete            uucp  : jdf@lri.lri.fr
28 //   /   \  /   LRI - Bat 490                 bitnet: jdf@FRLRI61.bitnet
29 //  /   _/ /    Universite de Paris-Sud       voice : +33 (1) 69 41 65 91
30 // /__   \/     F-91405 ORSAY Cedex                   +33 (1) 69 41 66 29
31
32 #include <X11/Intrinsic.h>
33 #include <generic.h>
34
35 #include <Xm/Xm.h>
36 #include "WXmString.h"
37
38 #include "WCallback.h"
39 #include "WTimeOut.h"
40 #include "WArgList.h"
41
42 #ifdef __STDC__
43 # define _stringify(x)  #x
44 #else
45 # define _stringify(x)  "x"
46 #endif
47
48 class WComposite;
49
50 #ifndef _XtintrinsicP_h
51  typedef void   (* XtProc)();
52 #endif
53
54 #define DEFINE_GETTER(rsc,typ,rnam) \
55 inline typ rsc() const \
56 { Arg a; typ __value; \
57   a.name = rnam; a.value = (XtArgVal)&__value; \
58   _Get(a); return __value; }
59
60 #define DEFINE_SETTER(rsc,typ,rnam) \
61 inline void rsc(typ val) const \
62 { Arg a; a.name = rnam; a.value = (XtArgVal)val; _Set(a); }
63
64 #if defined(linux)
65 #define CASTRNAM (char*)
66 #define CASTVAL  (void*)
67 #else
68 #define CASTRNAM
69 #define CASTVAL
70 #endif
71
72 #define DEFINE_ARG(rsc,typ,rnam) \
73 inline WArgList& rsc(typ val, WArgList& _w) const \
74 { return _w.Add (CASTRNAM rnam, CASTVAL val); }
75
76 #define DEFINE_GETTER_SETTER(rsc,typ,rnam) \
77         DEFINE_GETTER(rsc,typ,rnam) \
78         DEFINE_SETTER(rsc,typ,rnam) \
79         DEFINE_ARG(rsc, typ,rnam)
80
81
82 /*----------------------------------------------------------------------
83  * This special macro is used to prevent the dangerous action of setting
84  * an arg using a WXmString.  Since the member XmString of the WXmString
85  * gets deleted when the WXmString gets deleted, an implicit cast to a
86  * WXmString can cause a temporary to be created whose scope is undefined.
87  * By using this macro, we require an XmString to be explicitly created
88  * which can be freed when the arg list is no longer needed
89  */
90
91 #define DEFINE_STRING_GETSET(resource,rname)    \
92         DEFINE_GETTER(resource,WXmString,rname) \
93         DEFINE_SETTER(resource,WXmString,rname) \
94         DEFINE_ARG(resource,XmString,rname)
95
96 #define DEFINE_INIT(class_name, base_name, class) \
97  \
98 inline  class_name() {} \
99 /* Constructor with widget */ \
100 inline  class_name (Widget w) : base_name (w) {} \
101  \
102 /* Unmanaged Widget Constructors */     \
103 inline  class_name (const WComposite&   father,                 \
104                     WidgetClass         c       = class,        \
105                     const char          *name   = _stringify(class_name), \
106                     ArgList             args    = NULL,         \
107                     Cardinal            card    = 0)            \
108         : base_name (father, c, name, args, card) {}            \
109  \
110 inline  class_name (const WComposite&   father,                 \
111                     const char          *name,                  \
112                     ArgList             args = NULL,            \
113                     Cardinal            card = 0)               \
114         : base_name (father, class, name, args, card) {}        \
115  \
116 inline  class_name (const WComposite&   father,                 \
117                     const char          *name,                  \
118                     WArgList            args)                   \
119         : base_name (father, class, name, args.Args(), args.NumArgs()) {} \
120  \
121 /* Managed Widget Constructors */ \
122 inline  class_name (const WComposite&   father,                 \
123                     int                 automanage,             \
124                     WidgetClass         c       = class,        \
125                     const char          *name   = _stringify(class_name), \
126                     ArgList             args    = NULL,         \
127                     Cardinal            card    = 0)            \
128         : base_name (father, automanage, c, name, args, card) {} \
129  \
130 inline  class_name (const WComposite&   father,                 \
131                     const char          *name,                  \
132                     int                 automanage,             \
133                     ArgList             args = NULL,            \
134                     Cardinal            card = 0)               \
135         : base_name (father, automanage, class, name, args, card) {} \
136  \
137 inline  class_name (const WComposite&   father,                 \
138                     const char          *name,                  \
139                     int                 automanage,             \
140                     WArgList            args)                   \
141         : base_name (father, automanage, class, name, args.Args(), \
142                      args.NumArgs()) {} \
143  \
144 inline  class_name& operator=(const class_name& w) { \
145                        widget = w.widget; \
146                        return *this; \
147                     } \
148
149
150 #define DEFINE_POPUP_INIT(class_name, base_name, class)                   \
151 inline  class_name (const WComposite& father,                     \
152                     Boolean popup,                                \
153                     WidgetClass c = (WidgetClass)class,           \
154                     const char *name = _stringify(class_name),    \
155                     ArgList args = NULL, Cardinal card = 0)       \
156                 : base_name (father, popup, c, name, args, card) {}       \
157 inline  class_name (const WComposite& father,                     \
158                     Boolean popup,                                \
159                     const char *name,                             \
160                     ArgList args = NULL, Cardinal card = 0)       \
161                 : base_name (father, popup, (WidgetClass)class, name, args, card) {} \
162 inline  class_name (const WComposite& father,                     \
163                     Boolean popup,                                \
164                     const char *name,                             \
165                     WArgList args)                                \
166                 : base_name (father, popup, (WidgetClass)class, name, args.Args(), args.NumArgs()) {} \
167 inline  void Popup (XtGrabKind grab = XtGrabNone)                 \
168                 { XtPopup(widget,grab); }                         \
169 inline  void Popdown () { XtPopdown(widget); }
170
171 #define DEFINE_CINIT(class_name, base_name, class)                \
172 inline  class_name (Widget w) : base_name (w) {}                  \
173 inline  class_name (WObject& o) : base_name (o) {}
174
175
176 #define DEFINE_CALLBACK(cb_name, cb_res)                              \
177 inline  void    name2(Add,cb_name) (XtCallbackProc proc, caddr_t closure = 0) const \
178                 { XtAddCallback(widget, cb_res, proc, closure); }     \
179 inline  void    name2(Remove,cb_name) (XtCallbackProc proc, caddr_t closure = 0) const \
180                 { XtRemoveCallback(widget, cb_res, proc, closure); }     \
181 inline  void    name2(Call,cb_name) (caddr_t call_data) const \
182                 { XtCallCallbacks(widget, cb_res, call_data); }     \
183 inline  void    name2(RemoveAll,cb_name) () const \
184                 { XtRemoveAllCallbacks(widget, cb_res); } \
185         DEFINE_GETTER_SETTER (cb_name, XtCallbackList, cb_res) \
186 inline  WCallback*      name2(Set,cb_name) (WWL* obj, WWL_FUN fun, void* client=0) { return SetCallback (cb_res, obj, fun, client); }
187
188 #define NULLWidget      ((Widget)0)
189
190 #endif