b311480e |
1 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
2 | // |
3 | // The content of this file is subject to the Open CASCADE Technology Public |
4 | // License Version 6.5 (the "License"). You may not use the content of this file |
5 | // except in compliance with the License. Please obtain a copy of the License |
6 | // at http://www.opencascade.org and read it completely before using this file. |
7 | // |
8 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
9 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
10 | // |
11 | // The Original Code and all software distributed under the License is |
12 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
13 | // Initial Developer hereby disclaims all such warranties, including without |
14 | // limitation, any warranties of merchantability, fitness for a particular |
15 | // purpose or non-infringement. Please see the License for the specific terms |
16 | // and conditions governing the rights and limitations under the License. |
17 | |
7fd59977 |
18 | |
19 | #include <Xw_Extension.h> |
20 | |
b311480e |
21 | /* ifdef then trace on */ |
7fd59977 |
22 | #ifdef TRACE |
23 | #define TRACE_DEF_TILEMAP |
24 | #endif |
25 | |
26 | /* |
27 | XW_EXT_TILEMAP* Xw_def_tilemap(adisplay,ntile): |
28 | XW_EXT_DISPLAY *adisplay Extended Display structure |
29 | |
30 | int ntile Number of tile cells to be allocated |
31 | |
32 | Create a tilemap extension |
33 | allocate the tile cells in the tilemap as if possible |
34 | depending of the MAXTILE define . |
35 | |
36 | Returns Tilemap extension address if successuful |
37 | or NULL if ERROR |
38 | |
39 | */ |
40 | |
41 | #ifdef XW_PROTOTYPE |
42 | void* Xw_def_tilemap (void* adisplay,int ntile) |
43 | #else |
44 | void* Xw_def_tilemap (adisplay,ntile) |
45 | void *adisplay ; |
46 | int ntile ; |
47 | #endif /*XW_PROTOTYPE*/ |
48 | { |
49 | XW_EXT_DISPLAY *pdisplay = (XW_EXT_DISPLAY*)adisplay ; |
50 | XW_EXT_TILEMAP *ptilemap = NULL ; |
51 | //int i,tile ; |
52 | int i ; |
53 | |
54 | if( !Xw_isdefine_display(pdisplay) ) { |
55 | /*ERROR*Bad EXT_DISPLAY Address*/ |
56 | Xw_set_error(96,"Xw_def_tilemap",pdisplay) ; |
57 | return (NULL) ; |
58 | } |
59 | |
60 | if( !(ptilemap = Xw_add_tilemap_structure(sizeof(XW_EXT_TILEMAP))) ) |
61 | return (NULL) ; |
62 | |
63 | if( ntile <= 0 ) ntile = MAXTILE ; |
64 | |
65 | ptilemap->connexion = pdisplay ; |
66 | ptilemap->maxtile = min(ntile,MAXTILE) ; |
67 | |
68 | for( i=0 ; i<ptilemap->maxtile ; i++ ) { |
69 | ptilemap->tiles[i] = 0 ; |
70 | } |
71 | |
72 | #ifdef TRACE_DEF_TILEMAP |
73 | if( Xw_get_trace() ) { |
74 | printf(" %lx = Xw_def_tilemap(%lx,%d)\n", (long ) ptilemap,(long ) adisplay,ntile) ; |
75 | } |
76 | #endif |
77 | |
78 | return (ptilemap); |
79 | } |
80 | |
81 | static XW_EXT_TILEMAP *PtilemapList =NULL ; |
82 | |
83 | #ifdef XW_PROTOTYPE |
84 | XW_EXT_TILEMAP* Xw_add_tilemap_structure(int size) |
85 | #else |
86 | XW_EXT_TILEMAP* Xw_add_tilemap_structure(size) |
87 | int size ; |
88 | #endif /*XW_PROTOTYPE*/ |
89 | /* |
90 | Create and Insert one Extended tilemap structure in the |
91 | EXtended tilemap List |
92 | |
93 | returns Extended tilemap address if successful |
94 | or NULL if Bad Allocation |
95 | */ |
96 | { |
97 | XW_EXT_TILEMAP *ptilemap = (XW_EXT_TILEMAP*) Xw_malloc(size) ; |
98 | int i ; |
99 | |
100 | if( ptilemap ) { |
101 | ptilemap->type = TILEMAP_TYPE ; |
102 | ptilemap->link = PtilemapList ; |
103 | PtilemapList = ptilemap ; |
104 | ptilemap->connexion = NULL ; |
105 | ptilemap->maxtile = 0 ; |
106 | ptilemap->maxwindow = 0 ; |
107 | for( i=0 ; i<MAXTILE ; i++ ) { |
108 | ptilemap->tiles[i] = 0 ; |
109 | } |
110 | } else { |
111 | /*EXT_TILEMAP allocation failed*/ |
112 | Xw_set_error(17,"Xw_add_tilemap_structure",0) ; |
113 | } |
114 | |
115 | return (ptilemap) ; |
116 | } |
117 | |
118 | #ifdef XW_PROTOTYPE |
119 | XW_STATUS Xw_close_tilemap(void* atilemap) |
120 | #else |
121 | XW_STATUS Xw_close_tilemap(atilemap) |
122 | void* atilemap ; |
123 | #endif /*XW_PROTOTYPE*/ |
124 | { |
125 | XW_EXT_TILEMAP *ptilemap = (XW_EXT_TILEMAP*)atilemap ; |
126 | XW_STATUS status ; |
127 | |
128 | if( !Xw_isdefine_tilemap(ptilemap) ) { |
129 | /*Bad EXT_TILEMAP Address*/ |
130 | Xw_set_error(49,"Xw_close_tilemap",ptilemap) ; |
131 | return (XW_ERROR) ; |
132 | } |
133 | |
134 | status = Xw_del_tilemap_structure(ptilemap) ; |
135 | |
136 | #ifdef TRACE_DEF_TILEMAP |
137 | if( Xw_get_trace() ) { |
138 | printf(" %d = Xw_close_tilemap(%lx)\n",status,(long ) ptilemap) ; |
139 | } |
140 | #endif |
141 | |
142 | return (status) ; |
143 | } |
144 | |
145 | #ifdef XW_PROTOTYPE |
146 | XW_STATUS Xw_del_tilemap_structure(XW_EXT_TILEMAP* atilemap) |
147 | #else |
148 | XW_STATUS Xw_del_tilemap_structure(atilemap) |
149 | XW_EXT_TILEMAP *atilemap; |
150 | #endif /*XW_PROTOTYPE*/ |
151 | /* |
152 | Remove the Extended tilemap address from the Extended List |
153 | |
154 | returns ERROR if the tilemap address is not Found in the list |
155 | returns SUCCESS if successful |
156 | */ |
157 | { |
158 | XW_EXT_TILEMAP *ptilemap = PtilemapList ; |
159 | int i ; |
160 | |
161 | if( !atilemap ) return (XW_ERROR) ; |
162 | |
163 | if( atilemap->maxwindow ) --atilemap->maxwindow ; |
164 | |
165 | if( atilemap->maxwindow ) { |
166 | return (XW_ERROR) ; |
167 | } else { |
168 | for( i=0 ; i<MAXTILE ; i++) { |
169 | if( atilemap->tiles[i] ) XFreePixmap(_PDISPLAY,atilemap->tiles[i]) ; |
170 | } |
171 | |
172 | if( atilemap == ptilemap ) { |
173 | PtilemapList = (XW_EXT_TILEMAP*) atilemap->link ; |
174 | } else { |
175 | for( ; ptilemap ; ptilemap = (XW_EXT_TILEMAP*) ptilemap->link ) { |
176 | if( ptilemap->link == atilemap ) { |
177 | ptilemap->link = atilemap->link ; |
178 | break ; |
179 | } |
180 | } |
181 | } |
182 | Xw_free(atilemap) ; |
183 | } |
184 | return (XW_SUCCESS) ; |
185 | } |