OpenIndiana and Solaris port
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / oliasdb / c_api_graphic.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 // $XConsortium: c_api_graphic.cc /main/3 1996/06/11 17:27:16 cde-hal $
24
25 #include "oliasdb/c_api_common.h"
26
27 static graphic_smart_ptr*
28 getGraphicUsingLocAndProid(DtMmdbInfoRequest* request, Boolean checkLocOnly = false)
29 {
30    mtry {
31       info_base* x = getBookCase(request -> bookcase_descriptor);
32       if ( x == 0 ) return 0;
33
34       const char* str = getLocator(request);
35
36       if ( str ) {
37          return new graphic_smart_ptr(x, str);
38       }
39
40       if ( checkLocOnly == true ) return 0;
41
42       oid_t * id = getPrimiaryOid(request);
43
44       if ( id == 0 ) return 0;
45
46       return new graphic_smart_ptr(x, *id);
47    }
48
49    mcatch (mmdbException &,e)
50    {
51      return 0;
52    } end_try;
53      return 0;
54 }
55
56 const char*
57 DtMmdbGraphicGetData(DtMmdbInfoRequest* request, unsigned int* data_length)
58 {
59    mtry {
60       graphic_smart_ptr* x = getGraphicUsingLocAndProid(request, true);
61
62       if ( x == 0 ) return 0;
63
64 #ifdef DEBUG
65       fprintf(stderr, " graphicInfo: mmdb_oid = %d.%d\n", (int)(*x).its_oid().ccode(), (int)(*x).its_oid().icode());
66 #endif
67
68       const char* y = x -> data();
69       if ( data_length ) *data_length = x -> data_size();
70
71       delete x;
72       return y;
73    }
74
75    mcatch (mmdbException &,e)
76    {
77      return 0;
78    } end_try;
79      return 0;
80 }
81
82 DtMmdbGraphicInfo*
83 DtMmdbGraphicGetInfo(DtMmdbInfoRequest* request)
84 {
85
86    mtry {
87       graphic_smart_ptr* x = getGraphicUsingLocAndProid(request, true);
88
89       if ( x == 0 ) return 0;
90
91
92
93       DtMmdbGraphicInfo* z = newDtMmdbGraphicInfo();
94
95       if ( z == 0 ) return 0;
96
97       z -> type =  x -> coding();
98       z -> width = x -> width();
99       z -> height = x -> height();
100       z -> llx =  x -> llx();
101       z -> lly =  x -> lly();
102       z -> urx =  x -> urx();
103       z -> ury =  x -> ury();
104
105       delete x;
106
107       return z;
108    }
109
110    mcatch (mmdbException &,e)
111    {
112      return 0;
113    } end_try;
114      return 0;
115 }
116
117 const char* DtMmdbGraphicGetLoc(DtMmdbInfoRequest* request)
118 {
119    mtry {
120       graphic_smart_ptr* x = getGraphicUsingLocAndProid(request, true);
121
122       if ( x == 0 ) return 0;
123
124       const char* y = x -> locator();
125
126       delete x;
127       return y;
128    }
129
130    mcatch (mmdbException &,e)
131    {
132      return 0;
133    } end_try;
134      return 0;
135 }
136
137 void DtMmdbFreeGraphicInfo(DtMmdbGraphicInfo* x)
138 {
139    free((void*)x);
140 }