OpenIndiana and Solaris port
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / oliasdb / graphic_hd.C
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 librararies 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: graphic_hd.cc /main/4 1996/06/11 17:28:57 cde-hal $
25  * $XConsortium: graphic_hd.cc /main/4 1996/06/11 17:28:57 cde-hal $
26  *
27  * Copyright (c) 1992 HAL Computer Systems International, Ltd.
28  * All rights reserved.  Unpublished -- rights reserved under
29  * the Copyright Laws of the United States.  USE OF A COPYRIGHT
30  * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
31  * OR DISCLOSURE.
32  * 
33  * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
34  * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.  USE,
35  * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
36  * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
37  * INTERNATIONAL, LTD.
38  * 
39  *                         RESTRICTED RIGHTS LEGEND
40  * Use, duplication, or disclosure by the Government is subject
41  * to the restrictions as set forth in subparagraph (c)(l)(ii)
42  * of the Rights in Technical Data and Computer Software clause
43  * at DFARS 252.227-7013.
44  *
45  *          HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
46  *                  1315 Dell Avenue
47  *                  Campbell, CA  95008
48  * 
49  */
50
51
52 #include "oliasdb/graphic_hd.h"
53
54 #ifdef C_API
55 buffer* graphic_smart_ptr::local_graphic_buffer_ptr = 0;
56 #endif
57
58 MMDB_BODIES(graphic)
59
60 void
61 graphic_smart_ptr::init () {
62     f_type = 0;
63     f_width = 0;
64     f_height = 0;
65     f_coding = 0;
66     f_llx = 0;
67     f_lly = 0;
68     f_urx = 0;
69     f_ury = 0;
70 }
71
72 graphic_smart_ptr::
73 graphic_smart_ptr(info_lib* lib_ptr, const char* ibase_name, const char* locator) : 
74 smart_ptr(lib_ptr, ibase_name, GRAPHIC_SET_POS, 
75                  managers::query_mgr -> form_pstring_handler(locator),
76                  BASE_COMPONENT_INDEX, smart_ptr::SET
77                 ),
78   _converted(false)
79 {
80     init ();
81 }
82
83 graphic_smart_ptr::
84 graphic_smart_ptr(info_base* base_ptr, const char* locator)
85 : smart_ptr(base_ptr, GRAPHIC_SET_POS, 
86             managers::query_mgr -> form_pstring_handler(locator),
87             BASE_COMPONENT_INDEX, smart_ptr::SET
88             ),
89   _converted(false)
90 {
91    //debug(cerr, locator);
92     init ();
93 }
94
95 graphic_smart_ptr::
96 graphic_smart_ptr(info_base* base_ptr, const oid_t& id)
97 : smart_ptr(base_ptr -> get_set(GRAPHIC_SET_POS) -> its_store(), id),
98   _converted(false)
99 {
100     init ();
101 }
102
103 ///////////////////////////////
104 //
105 ///////////////////////////////
106
107 const char* graphic_smart_ptr::locator()
108 {
109   return get_string(BASE_COMPONENT_INDEX);
110 }
111
112 const char* graphic_smart_ptr::file_name()
113 {
114   return get_string(BASE_COMPONENT_INDEX+1);
115 }
116
117 const char* graphic_smart_ptr::version()
118 {
119   return get_string(BASE_COMPONENT_INDEX+2);
120 }
121
122 Boolean graphic_smart_ptr::_convert_to_ints()
123 {
124    pstring_handler* x = (pstring_handler*)get_handler(BASE_COMPONENT_INDEX+3, STRING_CODE);
125
126    char* y = (*x)->get();
127    int ct = (*x) -> size();
128
129    int dots = 0;
130    for ( int i=0; i<ct; i++ ) 
131       if ( y[i] == '.' )
132          dots++;
133
134    switch (dots) {
135      case 3:
136       sscanf(y, "%d.%hu.%hu.%hu", &f_type, &f_coding, &f_width, &f_height);
137       break;
138    
139      case 5:
140       sscanf(y, "%d.%hu.%u.%u.%u.%u",
141              &f_type, &f_coding, &f_llx, &f_lly, &f_urx, &f_ury);
142 //debug(cerr, f_llx);
143 //debug(cerr, f_lly);
144 //debug(cerr, f_urx);
145 //debug(cerr, f_ury);
146       break;
147
148     default:
149       throw(stringException("wrong number of dots"));
150   }
151
152    _converted = true;
153
154    delete x;
155    return true;
156 }
157
158 #ifdef C_API
159 #define local_graphic_buffer (*local_graphic_buffer_ptr)
160 #else
161 static buffer local_graphic_buffer(LBUFSIZ);
162 #endif
163
164
165 const char* graphic_smart_ptr::data()
166 {
167   return get_string(BASE_COMPONENT_INDEX+4, local_graphic_buffer);
168 }
169
170 int graphic_smart_ptr::data_size()
171 {
172   return get_string_size(BASE_COMPONENT_INDEX+4);
173 }
174
175 const char* graphic_smart_ptr::title()
176 {
177   mtry
178   {
179      return get_string(BASE_COMPONENT_INDEX+5);
180   }
181
182   mcatch (mmdbException&,e)
183   {
184      return 0;
185   } 
186   end_try;
187
188   return 0;
189 }
190
191 int graphic_smart_ptr::type() const
192 {
193    if ( _converted == false )
194      // cast away to achieve logical constness
195      ((graphic_smart_ptr*)this)->_convert_to_ints();
196
197    return f_type;
198 }
199
200 unsigned short graphic_smart_ptr::coding()
201 {
202    if ( _converted == false )
203      _convert_to_ints();
204
205    return f_coding;
206 }
207
208 unsigned short graphic_smart_ptr::width()
209 {
210    if ( _converted == false )
211      _convert_to_ints();
212
213    return f_width;
214 }
215
216 unsigned short graphic_smart_ptr::height()
217 {
218    if ( _converted == false )
219       _convert_to_ints();
220
221    return f_height;
222 }
223
224 /////////////////////////////////////////////
225 unsigned int graphic_smart_ptr::llx()
226 {
227    if ( _converted == false )
228       _convert_to_ints();
229
230    return f_llx;
231 }
232
233 unsigned int graphic_smart_ptr::lly()
234 {
235    if ( _converted == false )
236       _convert_to_ints();
237
238    return f_lly;
239 }
240
241 unsigned int graphic_smart_ptr::urx()
242 {
243    if ( _converted == false )
244       _convert_to_ints();
245
246    return f_urx;
247 }
248
249 unsigned int graphic_smart_ptr::ury()
250 {
251    if ( _converted == false )
252       _convert_to_ints();
253
254    return f_ury;
255 }
256