remove OSF1 support
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / wwl / include / WWL / WXmString.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /*
24  * $XConsortium: WXmString.h /main/4 1996/09/05 17:39:41 cde-hal $
25  *
26  * Copyright (c) 1991 HaL Computer Systems, Inc.  All rights reserved.
27  * UNPUBLISHED -- rights reserved under the Copyright Laws of the United
28  * States.  Use of a copyright notice is precautionary only and does not
29  * imply publication or disclosure.
30  * 
31  * This software contains confidential information and trade secrets of HaL
32  * Computer Systems, Inc.  Use, disclosure, or reproduction is prohibited
33  * without the prior express written permission of HaL Computer Systems, Inc.
34  * 
35  *                         RESTRICTED RIGHTS LEGEND
36  * Use, duplication, or disclosure by the Government is subject to
37  * restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
38  * Technical Data and Computer Software clause at DFARS 252.227-7013.
39  *                        HaL Computer Systems, Inc.
40  *                  1315 Dell Avenue, Campbell, CA  95008
41  * 
42  */
43
44 #ifndef WXmString_h
45 #define WXmString_h
46
47 extern Boolean XmStringUngenerate(XmString, XmStringCharSet, char**);
48
49 class WXmString {
50
51 protected:
52
53    XmString     string;
54
55 public:
56
57    enum { NO_COPY = False, COPY = True };
58
59 // Constructors
60
61    inline       WXmString ()            { string = 0; }
62    inline       WXmString (XmString s,
63                            Boolean copy = True)
64      { if (copy)
65          string = XmStringCopy(s);
66        else
67          string = s;
68      }
69    inline       WXmString (const WXmString& w)  { string = w.Copy(); }
70
71 #if XmVersion >= 1002
72    inline       WXmString (const char* t, char *tag=XmFONTLIST_DEFAULT_TAG)
73    {
74       if (tag == XmFONTLIST_DEFAULT_TAG)
75         string = XmStringCreateLocalized((char *) t);
76       else
77         string = XmStringCreate ((char *) t, tag);
78    }
79 #else
80    inline       WXmString (char* t,
81                            XmStringCharSet charset=XmSTRING_DEFAULT_CHARSET) {
82       string = XmStringCreateLtoR (t, charset);
83    }
84 #endif
85    inline       WXmString (XmStringDirection d) {
86       string = XmStringDirectionCreate (d);
87    }
88
89 // Destructor
90
91    inline       ~WXmString () {
92       if (string) XmStringFree (string);
93    }
94
95 // Operators
96
97    inline WXmString&    operator= (const WXmString& w) {
98       if (string) XmStringFree (string);
99       string = XmStringCopy(w.string);
100       return *this;
101    }
102    inline WXmString&    operator= (const XmString s) {
103       if (string) XmStringFree (string);
104       string = XmStringCopy(s);
105       return *this;
106    }
107    inline WXmString&    operator= (char *cs) {
108       if (string) XmStringFree (string);
109 #if XmVersion >= 1002
110       string = XmStringCreateLocalized (cs);
111 #else
112       string = XmStringCreateLtoR (cs, XmSTRING_DEFAULT_CHARSET);
113 #endif
114       return *this;
115    }
116
117    inline               operator XmString () const { return string; }
118    inline               operator XtArgVal () const { return (XtArgVal) string; }
119    inline               operator char* () const {
120       char* ret;
121 #if XmVersion >= 1002
122       XmStringUngenerate(string, XmFONTLIST_DEFAULT_TAG, &ret);
123 #else
124       XmStringGetLtoR (string, XmSTRING_DEFAULT_CHARSET, &ret);
125 #endif
126       return ret;
127    }
128    inline Boolean       operator== (XmString s) const {
129       return ByteCompare (s);
130    }
131    inline WXmString&    operator<< (const WXmString& s) {
132       XmString n = Concat(s.string);
133       XmStringFree(string);
134       string = n;
135       return *this;
136    }
137    // Beware that this operator modifies the first string!!
138    inline WXmString&    operator + (const WXmString& s) {
139       XmString n = Concat(s.string);
140       XmStringFree(string);
141       string = n;
142       return *this;
143    }
144
145 // Methods
146
147    inline void          Free () {
148       if (string) XmStringFree (string);
149       string = 0;
150    }
151    inline Dimension     Baseline (XmFontList fl) const {
152       return XmStringBaseline (fl, string);
153    }
154    inline Boolean       ByteCompare (XmString s) const {
155       return XmStringByteCompare (string, s);
156    }
157    inline Boolean       Compare (XmString s) const {
158       return XmStringCompare (string, s);
159    }
160    // Caller responsible for deleting return value!!
161    inline XmString      Concat (XmString s) const {
162       return XmStringConcat (string, s);
163    }
164    inline XmString      Copy () const { return XmStringCopy (string); }
165    inline Boolean       Empty () const { return XmStringEmpty (string); }
166    inline void          Extent (XmFontList fl, Dimension* w, Dimension* h)
167    const {
168       XmStringExtent (fl, string, w, h);
169    }
170 #if XmVersion >= 1002
171    inline Boolean       GetLtoR (char** text, char *tag=XmFONTLIST_DEFAULT_TAG)
172    const {
173       return XmStringUngenerate(string, tag, text);
174    }
175 #else
176    inline Boolean       GetLtoR (char** text,
177                                  XmStringCharSet cs=XmSTRING_DEFAULT_CHARSET)
178    const {
179       return XmStringGetLtoR (string, cs, text);
180    }
181 #endif
182    inline Dimension     Height (XmFontList fl) const {
183       return XmStringHeight (fl, string);
184    }
185    inline int           LineCount () const {
186       return XmStringLineCount (string);
187    }
188    inline void          NConcat (XmString s, int n) {
189       XmStringNConcat (string, s, n);
190    }
191    inline Dimension     Width (XmFontList fl) const {
192       return XmStringWidth (fl, string);
193    }
194    inline void          Zero () { string = 0; }
195    inline XmString disown() { XmString s = string; string = NULL; return s; }
196
197    WXmString  CopyUsingFont( char* newtag );
198
199 };
200
201 #endif