2 * Create dynamic new structures of various types
3 * and some utils in that trend.
5 * Copyright 1998 Bertho A. Stultiens
21 /* Generate new_* functions that have no parameters (NOTE: no ';') */
22 __NEW_STRUCT_FUNC(dialog
)
23 __NEW_STRUCT_FUNC(dialogex
)
24 __NEW_STRUCT_FUNC(name_id
)
25 __NEW_STRUCT_FUNC(menu
)
26 __NEW_STRUCT_FUNC(menuex
)
27 __NEW_STRUCT_FUNC(menu_item
)
28 __NEW_STRUCT_FUNC(menuex_item
)
29 __NEW_STRUCT_FUNC(control
)
30 __NEW_STRUCT_FUNC(icon
)
31 __NEW_STRUCT_FUNC(cursor
)
32 __NEW_STRUCT_FUNC(versioninfo
)
33 __NEW_STRUCT_FUNC(ver_value
)
34 __NEW_STRUCT_FUNC(ver_block
)
35 __NEW_STRUCT_FUNC(stt_entry
)
36 __NEW_STRUCT_FUNC(accelerator
)
37 __NEW_STRUCT_FUNC(event
)
38 __NEW_STRUCT_FUNC(raw_data
)
39 __NEW_STRUCT_FUNC(lvc
)
40 __NEW_STRUCT_FUNC(res_count
)
41 __NEW_STRUCT_FUNC(string
)
42 __NEW_STRUCT_FUNC(toolbar_item
)
44 /* New instances for all types of structures */
45 /* Very inefficient (in size), but very functional :-]
46 * Especially for type-checking.
48 resource_t
*new_resource(enum res_e t
, void *res
, int memopt
, language_t
*lan
)
50 resource_t
*r
= (resource_t
*)xmalloc(sizeof(resource_t
));
58 version_t
*new_version(DWORD v
)
60 version_t
*vp
= (version_t
*)xmalloc(sizeof(version_t
));
65 characts_t
*new_characts(DWORD c
)
67 characts_t
*cp
= (characts_t
*)xmalloc(sizeof(characts_t
));
72 language_t
*new_language(int id
, int sub
)
74 language_t
*lan
= (language_t
*)xmalloc(sizeof(language_t
));
80 language_t
*dup_language(language_t
*l
)
83 return new_language(l
->id
, l
->sub
);
86 version_t
*dup_version(version_t
*v
)
89 return new_version(*v
);
92 characts_t
*dup_characts(characts_t
*c
)
95 return new_characts(*c
);
98 rcdata_t
*new_rcdata(raw_data_t
*rd
, int *memopt
)
100 rcdata_t
*rc
= (rcdata_t
*)xmalloc(sizeof(rcdata_t
));
104 rc
->memopt
= *memopt
;
108 rc
->memopt
= WRC_MO_MOVEABLE
| WRC_MO_PURE
;
112 font_id_t
*new_font_id(int size
, string_t
*face
, int weight
, int italic
)
114 font_id_t
*fid
= (font_id_t
*)xmalloc(sizeof(font_id_t
));
117 fid
->weight
= weight
;
118 fid
->italic
= italic
;
122 user_t
*new_user(name_id_t
*type
, raw_data_t
*rd
, int *memopt
)
124 user_t
*usr
= (user_t
*)xmalloc(sizeof(user_t
));
128 usr
->memopt
= *memopt
;
132 usr
->memopt
= WRC_MO_MOVEABLE
| WRC_MO_PURE
;
137 font_t
*new_font(raw_data_t
*rd
, int *memopt
)
139 font_t
*fnt
= (font_t
*)xmalloc(sizeof(font_t
));
143 fnt
->memopt
= *memopt
;
147 fnt
->memopt
= WRC_MO_MOVEABLE
| WRC_MO_PURE
;
151 icon_group_t
*new_icon_group(raw_data_t
*rd
, int *memopt
)
153 icon_group_t
*icog
= (icon_group_t
*)xmalloc(sizeof(icon_group_t
));
156 icog
->memopt
= *memopt
;
160 icog
->memopt
= WRC_MO_MOVEABLE
| WRC_MO_PURE
| WRC_MO_DISCARDABLE
;
161 icog
->lvc
.language
= dup_language(currentlanguage
);
162 split_icons(rd
, icog
, &(icog
->nicon
));
168 cursor_group_t
*new_cursor_group(raw_data_t
*rd
, int *memopt
)
170 cursor_group_t
*curg
= (cursor_group_t
*)xmalloc(sizeof(cursor_group_t
));
173 curg
->memopt
= *memopt
;
177 curg
->memopt
= WRC_MO_MOVEABLE
| WRC_MO_PURE
| WRC_MO_DISCARDABLE
;
178 curg
->lvc
.language
= dup_language(currentlanguage
);
179 split_cursors(rd
, curg
, &(curg
->ncursor
));
185 bitmap_t
*new_bitmap(raw_data_t
*rd
, int *memopt
)
187 bitmap_t
*bmp
= (bitmap_t
*)xmalloc(sizeof(bitmap_t
));
191 bmp
->memopt
= *memopt
;
195 bmp
->memopt
= WRC_MO_MOVEABLE
| WRC_MO_PURE
;
199 ver_words_t
*new_ver_words(int i
)
201 ver_words_t
*w
= (ver_words_t
*)xmalloc(sizeof(ver_words_t
));
202 w
->words
= (WORD
*)xmalloc(sizeof(WORD
));
203 w
->words
[0] = (WORD
)i
;
208 ver_words_t
*add_ver_words(ver_words_t
*w
, int i
)
210 w
->words
= (WORD
*)xrealloc(w
->words
, (w
->nwords
+1) * sizeof(WORD
));
211 w
->words
[w
->nwords
] = (WORD
)i
;
216 messagetable_t
*new_messagetable(raw_data_t
*rd
)
218 messagetable_t
*msg
= (messagetable_t
*)xmalloc(sizeof(messagetable_t
));
223 void copy_raw_data(raw_data_t
*dst
, raw_data_t
*src
, int offs
, int len
)
225 assert(offs
<= src
->size
);
226 assert(offs
+ len
<= src
->size
);
229 dst
->data
= (char *)xmalloc(len
);
233 dst
->data
= (char *)xrealloc(dst
->data
, dst
->size
+ len
);
234 /* dst->size holds the offset to copy to */
235 memcpy(dst
->data
+ dst
->size
, src
->data
+ offs
, len
);
241 int *ip
= (int *)xmalloc(sizeof(int));
246 stringtable_t
*new_stringtable(lvc_t
*lvc
)
248 stringtable_t
*stt
= (stringtable_t
*)xmalloc(sizeof(stringtable_t
));
256 toolbar_t
*new_toolbar(int button_width
, int button_height
, toolbar_item_t
*items
, int nitems
)
258 toolbar_t
*tb
= (toolbar_t
*)xmalloc(sizeof(toolbar_t
));
259 tb
->button_width
= button_width
;
260 tb
->button_height
= button_height
;
266 dlginit_t
*new_dlginit(raw_data_t
*rd
, int *memopt
)
268 dlginit_t
*di
= (dlginit_t
*)xmalloc(sizeof(dlginit_t
));
272 di
->memopt
= *memopt
;
276 di
->memopt
= WRC_MO_MOVEABLE
| WRC_MO_PURE
| WRC_MO_DISCARDABLE
;
281 style_pair_t
*new_style_pair(style_t
*style
, style_t
*exstyle
)
283 style_pair_t
*sp
= (style_pair_t
*)xmalloc(sizeof(style_pair_t
));
285 sp
->exstyle
= exstyle
;
289 style_t
*new_style(DWORD or_mask
, DWORD and_mask
)
291 style_t
*st
= (style_t
*)xmalloc(sizeof(style_t
));
292 st
->or_mask
= or_mask
;
293 st
->and_mask
= and_mask
;