1
2 #include "studiox_includes.h"
3
4 #ifdef _DEBUG
5 #define new DEBUG_NEW
6 #endif
7
checkbox_service_provider()8 checkbox_service_provider::checkbox_service_provider()
9 {
10 }
11
GetVarDeclaration()12 CString checkbox_service_provider::GetVarDeclaration()
13 {
14 return CString("GX_CHECKBOX_MEMBERS_DECLARE");
15 }
16
DeclarePropertiesStruct()17 CString checkbox_service_provider::DeclarePropertiesStruct()
18 {
19 CString out;
20
21 out.Format(_T("typedef struct\n")
22 _T("{\n")
23 _T("%s\n")
24 _T(" GX_RESOURCE_ID unchecked_pixelmap_id;\n")
25 _T(" GX_RESOURCE_ID checked_pixelmap_id;\n")
26 _T(" GX_RESOURCE_ID unchecked_disabled_pixelmap_id;\n")
27 _T(" GX_RESOURCE_ID checked_disabled_pixelmap_id;\n")
28 _T("} GX_CHECKBOX_PROPERTIES;\n\n"),
29 text_button_service_provider::DeclaraPropertiesStructContent());
30
31 return out;
32 }
33
WriteExtendedProperties(screen_generator * gen,CString & prefix,widget_info * info)34 CString checkbox_service_provider::WriteExtendedProperties(screen_generator *gen, CString &prefix, widget_info *info)
35 {
36 CString out;
37 CString propname = prefix + info->app_name;
38
39 GX_RESOURCE_ID check_on_id;
40 GX_RESOURCE_ID check_off_id;
41
42 check_on_id = info->pixelmap_id[CHECKED_PIXELMAP_INDEX];
43 if (check_on_id == GX_PIXELMAP_CHECKBOX_ON_ID)
44 {
45 // if the id is the default, set it to 0 to avoid
46 // generating pixelmap set call
47 check_on_id = 0;
48 }
49
50 check_off_id = info->pixelmap_id[UNCHECKED_PIXELMAP_INDEX];
51 if (check_off_id == GX_PIXELMAP_CHECKBOX_OFF_ID)
52 {
53 // if the id is the default, set it to 0 to avoid
54 // generating pixelmap set call
55 check_off_id = 0;
56 }
57
58
59 out.Format(_T("GX_CHECKBOX_PROPERTIES %s_properties =\n")
60 _T("{\n")
61 _T("%s\n")
62 _T(" %s, /* unchecked pixelmap id */\n")
63 _T(" %s, /* checked pixelmap id */\n")
64 _T(" %s, /* unchecked disabled pixelmap id */\n")
65 _T(" %s /* checked disabled pixelmap id */\n};\n"),
66 propname,
67 text_button_service_provider::WriteExtendedPropertiesContent(gen, info, TRUE),
68 gen->GetPixelmapIdName(check_off_id),
69 gen->GetPixelmapIdName(check_on_id),
70 gen->GetPixelmapIdName(info->pixelmap_id[UNCHECKED_DISABLED_PIXELMAP_INDEX]),
71 gen->GetPixelmapIdName(info->pixelmap_id[CHECKED_DISABLED_PIXELMAP_INDEX])
72 );
73 return out;
74 }
75
GetCreateFromDefFunctionName()76 CString checkbox_service_provider::GetCreateFromDefFunctionName()
77 {
78 return CString("gx_studio_checkbox_create");
79 }
80
GetCreateFromDefFunction(int version)81 CString checkbox_service_provider::GetCreateFromDefFunction(int version)
82 {
83 CString out;
84 MakeCreatePreamble("checkbox", version, out);
85
86 out += "{\n"
87 " UINT status;\n"
88 " GX_CHECKBOX *button = (GX_CHECKBOX *) control_block;\n"
89 " GX_TEXT_BUTTON *text_button = (GX_TEXT_BUTTON *) button;\n"
90 " GX_CHECKBOX_PROPERTIES *props = (GX_CHECKBOX_PROPERTIES *) info->properties;\n"
91 " status = gx_checkbox_create(button, info->widget_name, parent, props->string_id, info->style, info->widget_id, &info->size);\n"
92 " if (status == GX_SUCCESS)\n"
93 " {\n"
94 " gx_text_button_font_set(text_button, props->font_id);\n";
95
96 if (version > 50401)
97 {
98 out += "#if defined(GUIX_5_4_0_COMPATIBILITY)\n"
99 " gx_text_button_text_color_set(text_button, props->normal_text_color_id, props->selected_text_color_id);\n "
100 "#else\n"
101 " gx_text_button_text_color_set(text_button, props->normal_text_color_id, props->selected_text_color_id, props->disabled_text_color_id);\n"
102 "#endif\n";
103 }
104 else
105 {
106 out += " gx_text_button_text_color_set(text_button, props->normal_text_color_id, props->selected_text_color_id);\n";
107 }
108
109 out += "\n"
110 " if (props->unchecked_pixelmap_id ||\n"
111 " props->checked_pixelmap_id ||\n"
112 " props->unchecked_disabled_pixelmap_id ||\n"
113 " props->checked_disabled_pixelmap_id)\n"
114 " {\n"
115 " gx_checkbox_pixelmap_set(button,\n"
116 " props->unchecked_pixelmap_id,\n"
117 " props->checked_pixelmap_id,\n"
118 " props->unchecked_disabled_pixelmap_id,\n"
119 " props->checked_disabled_pixelmap_id);\n"
120 " }\n"
121 " }\n"
122 " return status;\n"
123 "}\n";
124
125 return out;
126 }
127
CreateNewInstance(GX_WIDGET * parent)128 widget_info *checkbox_service_provider::CreateNewInstance(GX_WIDGET *parent)
129 {
130 GX_RECTANGLE size;
131 gx_utility_rectangle_define(&size, 0, 0, 79, 23);
132 gx_utility_rectangle_center(&size, &parent->gx_widget_size);
133
134 GX_CHECKBOX *button = new GX_CHECKBOX;
135 GX_RESOURCE_ID string_id = GetStringId("checkbox");
136 gx_checkbox_create(button, "checkbox", parent,
137 string_id, GX_STYLE_ENABLED|GX_STYLE_TRANSPARENT|GX_STYLE_TEXT_LEFT, 0, &size);
138
139 widget_info *info = InitWidgetInfo((GX_WIDGET *) button);
140
141 info->string_id[0] = string_id;
142
143 info->color_id[NORMAL_TEXT_COLOR_INDEX] = button->gx_text_button_normal_text_color;
144 info->color_id[SELECTED_TEXT_COLOR_INDEX] = button->gx_text_button_selected_text_color;
145 info->color_id[DISABLED_TEXT_COLOR_INDEX] = button->gx_text_button_disabled_text_color;
146 info->font_id[0] = button->gx_text_button_font_id;
147
148 info->pixelmap_id[UNCHECKED_PIXELMAP_INDEX] = GX_PIXELMAP_CHECKBOX_OFF_ID;
149 info->pixelmap_id[CHECKED_PIXELMAP_INDEX] = GX_PIXELMAP_CHECKBOX_ON_ID;
150
151 return info;
152 }
153
GenerateFromInfo(GX_WIDGET * parent,widget_info * info)154 GX_WIDGET *checkbox_service_provider::GenerateFromInfo(GX_WIDGET *parent, widget_info *info)
155 {
156 GX_CHECKBOX *button = new GX_CHECKBOX;
157 gx_checkbox_create(button,
158 (CHAR *) info->app_name.GetString(),
159 parent,
160 info->string_id[0],
161 info->style,
162 0,
163 &info->size);
164
165 if(info->pixelmap_id[UNCHECKED_PIXELMAP_INDEX] == 0)
166 {
167 info->pixelmap_id[UNCHECKED_PIXELMAP_INDEX] = GX_PIXELMAP_CHECKBOX_OFF_ID;
168 }
169 if (info->pixelmap_id[CHECKED_PIXELMAP_INDEX] == 0)
170 {
171 info->pixelmap_id[CHECKED_PIXELMAP_INDEX] = GX_PIXELMAP_CHECKBOX_ON_ID;
172 }
173
174
175 gx_checkbox_pixelmap_set(button,
176 info->pixelmap_id[UNCHECKED_PIXELMAP_INDEX],
177 info->pixelmap_id[CHECKED_PIXELMAP_INDEX],
178 info->pixelmap_id[UNCHECKED_DISABLED_PIXELMAP_INDEX],
179 info->pixelmap_id[CHECKED_DISABLED_PIXELMAP_INDEX]);
180
181 GX_TEXT_BUTTON *tb = (GX_TEXT_BUTTON *)button;
182
183 gx_widget_fill_color_set(tb,
184 info->color_id[NORMAL_FILL_COLOR_INDEX],
185 info->color_id[SELECTED_FILL_COLOR_INDEX],
186 info->color_id[DISABLED_FILL_COLOR_INDEX]);
187
188 gx_text_button_text_color_set(tb,
189 info->color_id[NORMAL_TEXT_COLOR_INDEX],
190 info->color_id[SELECTED_TEXT_COLOR_INDEX],
191 info->color_id[DISABLED_TEXT_COLOR_INDEX]);
192
193 gx_text_button_font_set(tb, info->font_id[0]);
194 return ((GX_WIDGET *) button);
195 }
196
SaveToProject(xml_writer & writer,studiox_project * project,int display,widget_info * info)197 void checkbox_service_provider::SaveToProject(xml_writer &writer, studiox_project *project, int display, widget_info *info)
198 {
199 text_button_service_provider::SaveToProject(writer, project, display, info);
200 WritePixelmapId(writer, project, display, "unchecked_pixelmap_id", info->pixelmap_id[UNCHECKED_PIXELMAP_INDEX]);
201 WritePixelmapId(writer, project, display, "checked_pixelmap_id", info->pixelmap_id[CHECKED_PIXELMAP_INDEX]);
202 WritePixelmapId(writer, project, display, "unchecked_disabled_pixelmap_id", info->pixelmap_id[UNCHECKED_DISABLED_PIXELMAP_INDEX]);
203 WritePixelmapId(writer, project, display, "checked_disabled_pixelmap_id", info->pixelmap_id[CHECKED_DISABLED_PIXELMAP_INDEX]);
204 }
205
ReadFromProject(xml_reader & reader,studiox_project * project,int display,widget_info * info,ULONG valid_styles)206 void checkbox_service_provider::ReadFromProject(xml_reader &reader, studiox_project *project, int display, widget_info *info, ULONG valid_styles)
207 {
208 text_button_service_provider::ReadFromProject(reader, project, display, info, valid_styles);
209 info->pixelmap_id[UNCHECKED_PIXELMAP_INDEX] = ReadPixelmapId(reader, project, display, "unchecked_pixelmap_id");
210 info->pixelmap_id[CHECKED_PIXELMAP_INDEX] = ReadPixelmapId(reader, project, display, "checked_pixelmap_id");
211 info->pixelmap_id[UNCHECKED_DISABLED_PIXELMAP_INDEX] = ReadPixelmapId(reader, project, display, "unchecked_disabled_pixelmap_id");
212 info->pixelmap_id[CHECKED_DISABLED_PIXELMAP_INDEX] = ReadPixelmapId(reader, project, display, "checked_disabled_pixelmap_id");
213 }
214
AssignText(widget_info * info,int index,GX_RESOURCE_ID string_id)215 void checkbox_service_provider::AssignText(widget_info *info, int index, GX_RESOURCE_ID string_id)
216 {
217 GX_WIDGET *widget = info->widget;
218
219 if (widget)
220 {
221 GX_TEXT_BUTTON *pb = (GX_TEXT_BUTTON *)widget;
222
223 gx_text_button_text_id_set(pb, string_id);
224 gx_system_dirty_mark(widget);
225 }
226
227 info->string_id[0] = string_id;
228 }
229
AssignFont(widget_info * info,int index,GX_RESOURCE_ID font_id)230 void checkbox_service_provider::AssignFont(widget_info *info, int index, GX_RESOURCE_ID font_id)
231 {
232 GX_WIDGET *widget = info->widget;
233
234 if (widget)
235 {
236 GX_TEXT_BUTTON *pb = (GX_TEXT_BUTTON *)widget;
237
238 gx_text_button_font_set(pb, font_id);
239 }
240
241 info->font_id[0] = font_id;
242 }
243
244
AssignPixelmap(widget_info * info,int index,GX_RESOURCE_ID pixmap_id)245 void checkbox_service_provider::AssignPixelmap(widget_info *info, int index, GX_RESOURCE_ID pixmap_id)
246 {
247 GX_WIDGET *widget = info->widget;
248
249 if (widget)
250 {
251 GX_CHECKBOX *box = (GX_CHECKBOX *)widget;
252 GX_RESOURCE_ID ucheck = box->gx_checkbox_unchecked_pixelmap_id;
253 GX_RESOURCE_ID check = box->gx_checkbox_checked_pixelmap_id;
254 GX_RESOURCE_ID ducheck = box->gx_checkbox_unchecked_disabled_pixelmap_id;
255 GX_RESOURCE_ID dcheck = box->gx_checkbox_checked_disabled_pixelmap_id;
256
257 switch (index)
258 {
259 case UNCHECKED_PIXELMAP_INDEX:
260 if (!pixmap_id)
261 {
262 ucheck = pixmap_id;
263 }
264 else
265 {
266 //set to default pixelmap
267 ucheck = GX_PIXELMAP_CHECKBOX_OFF_ID;
268 }
269 break;
270 case CHECKED_PIXELMAP_INDEX:
271 if (pixmap_id)
272 {
273 check = pixmap_id;
274 }
275 else
276 {
277 check = GX_PIXELMAP_CHECKBOX_ON_ID;
278 }
279 break;
280 case UNCHECKED_DISABLED_PIXELMAP_INDEX:
281 if (pixmap_id)
282 {
283 ducheck = pixmap_id;
284 }
285 else
286 {
287 ducheck = GX_PIXELMAP_CHECKBOX_OFF_ID;
288 }
289 break;
290 case CHECKED_DISABLED_PIXELMAP_INDEX:
291 if (pixmap_id)
292 {
293 dcheck = pixmap_id;
294 }
295 else
296 {
297 dcheck = GX_PIXELMAP_CHECKBOX_ON_ID;
298 }
299 break;
300 }
301
302 gx_checkbox_pixelmap_set(box, ucheck, check, ducheck, dcheck);
303 }
304
305 info->pixelmap_id[index] = pixmap_id;
306
307 }
308
Autosize(widget_info * info)309 void checkbox_service_provider::Autosize(widget_info *info)
310 {
311 CheckResizeToText(info);
312 CheckResizeToPixelmap(info, RESIZE_MODE_HEIGHT, TRUE);
313 }