1 
2 #include "studiox_includes.h"
3 
4 #ifdef _DEBUG
5 #define new DEBUG_NEW
6 #endif
7 
radio_button_service_provider()8 radio_button_service_provider::radio_button_service_provider()
9 {
10 }
11 
GetVarDeclaration()12 CString radio_button_service_provider::GetVarDeclaration()
13 {
14     return CString("GX_RADIO_BUTTON_MEMBERS_DECLARE");
15 }
16 
DeclarePropertiesStruct()17 CString radio_button_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 off_pixelmap_id;\n")
25         _T("    GX_RESOURCE_ID on_pixelmap_id;\n")
26         _T("    GX_RESOURCE_ID off_disabled_pixelmap_id;\n")
27         _T("    GX_RESOURCE_ID on_disabled_pixelmap_id;\n")
28         _T("} GX_RADIO_BUTTON_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 radio_button_service_provider::WriteExtendedProperties(screen_generator *gen, CString &prefix, widget_info *info)
35 {
36     GX_RESOURCE_ID radio_on_id;
37     GX_RESOURCE_ID radio_off_id;
38 
39     radio_on_id = info->pixelmap_id[RADIO_ON_PIXELMAP_INDEX];
40     if (radio_on_id == GX_PIXELMAP_RADIO_ON_ID)
41     {
42         // if the id is the default, set it to 0 to avoid
43         // generating pixelmap set call
44         radio_on_id = 0;
45     }
46 
47     radio_off_id = info->pixelmap_id[RADIO_OFF_PIXELMAP_INDEX];
48     if (radio_off_id == GX_PIXELMAP_RADIO_OFF_ID)
49     {
50         // if the id is the default, set it to 0 to avoid
51         // generating pixelmap set call
52         radio_off_id = 0;
53     }
54 
55     CString out;
56     CString propname = prefix + info->app_name;
57     out.Format(_T("GX_RADIO_BUTTON_PROPERTIES %s_properties =\n")
58         _T("{\n")
59         _T("%s\n")
60         _T("    %s, /* off pixelmap id */\n")
61         _T("    %s, /* on pixelmap id */\n")
62         _T("    %s, /* off disabled pixelmap id */\n")
63         _T("    %s  /* on disabled pixelmap id */\n};\n"),
64         propname,
65         text_button_service_provider::WriteExtendedPropertiesContent(gen, info, TRUE),
66         gen->GetPixelmapIdName(radio_off_id),
67         gen->GetPixelmapIdName(radio_on_id),
68         gen->GetPixelmapIdName(info->pixelmap_id[RADIO_OFF_DISABLED_PIXELMAP_INDEX]),
69         gen->GetPixelmapIdName(info->pixelmap_id[RADIO_ON_DISABLED_PIXELMAP_INDEX])
70         );
71     return out;
72 }
73 
GetCreateFromDefFunctionName()74 CString radio_button_service_provider::GetCreateFromDefFunctionName()
75 {
76     return CString("gx_studio_radio_button_create");
77 }
78 
GetCreateFromDefFunction(int version)79 CString radio_button_service_provider::GetCreateFromDefFunction(int version)
80 {
81     CString out;
82     MakeCreatePreamble("radio_button", version, out);
83 
84     out += "{\n"
85         "    UINT status;\n"
86         "    GX_RADIO_BUTTON *button = (GX_RADIO_BUTTON *) control_block;\n"
87         "    GX_TEXT_BUTTON *text_button = (GX_TEXT_BUTTON *) button;\n"
88         "    GX_RADIO_BUTTON_PROPERTIES *props = (GX_RADIO_BUTTON_PROPERTIES *) info->properties;\n"
89         "    status = gx_radio_button_create(button, info->widget_name, parent, props->string_id, info->style, info->widget_id, &info->size);\n"
90         "    if (status == GX_SUCCESS)\n"
91         "    {\n"
92         "        gx_text_button_font_set(text_button, props->font_id);\n";
93 
94         if (version > 50401)
95         {
96             out += "#if defined(GUIX_5_4_0_COMPATIBILITY)\n"
97                 "        gx_text_button_text_color_set(text_button, props->normal_text_color_id, props->selected_text_color_id);\n"
98                 "#else\n"
99                 "        gx_text_button_text_color_set(text_button, props->normal_text_color_id, props->selected_text_color_id, props->disabled_text_color_id);\n"
100                 "#endif\n";
101         }
102         else
103         {
104             out += "        gx_text_button_text_color_set(text_button, props->normal_text_color_id, props->selected_text_color_id);\n";
105         }
106 
107         out += "\n"
108         "        if (props->off_pixelmap_id ||\n"
109         "            props->on_pixelmap_id ||\n"
110         "            props->off_disabled_pixelmap_id ||\n"
111         "            props->on_disabled_pixelmap_id)\n"
112         "        {\n"
113         "            gx_radio_button_pixelmap_set(button,\n"
114         "                                     props->off_pixelmap_id,\n"
115         "                                     props->on_pixelmap_id,\n"
116         "                                     props->off_disabled_pixelmap_id,\n"
117         "                                     props->on_disabled_pixelmap_id);\n"
118         "        }\n"
119         "    }\n"
120         "    return status;\n"
121         "}\n";
122 
123     return out;
124 }
125 
CreateNewInstance(GX_WIDGET * parent)126 widget_info *radio_button_service_provider::CreateNewInstance(GX_WIDGET *parent)
127 {
128     GX_RECTANGLE size;
129     gx_utility_rectangle_define(&size, 0, 0, 79, 23);
130     gx_utility_rectangle_center(&size, &parent->gx_widget_size);
131 
132     GX_RADIO_BUTTON *button = new GX_RADIO_BUTTON;
133     GX_RESOURCE_ID string_id = GetStringId("radio");
134     gx_radio_button_create(button, "radio_button", parent,
135         string_id, GX_STYLE_ENABLED|GX_STYLE_TRANSPARENT|GX_STYLE_TEXT_LEFT|GX_STYLE_BUTTON_RADIO, 0, &size);
136 
137     widget_info *info = InitWidgetInfo((GX_WIDGET *) button);
138 
139     info->string_id[0]  = string_id;
140 
141     info->color_id[NORMAL_TEXT_COLOR_INDEX] = button->gx_text_button_normal_text_color;
142     info->color_id[SELECTED_TEXT_COLOR_INDEX] = button->gx_text_button_selected_text_color;
143     info->color_id[DISABLED_TEXT_COLOR_INDEX] = button->gx_text_button_disabled_text_color;
144     info->font_id[0] = button->gx_text_button_font_id;
145 
146     info->pixelmap_id[RADIO_ON_PIXELMAP_INDEX] = GX_PIXELMAP_RADIO_ON_ID;
147     info->pixelmap_id[RADIO_OFF_PIXELMAP_INDEX] = GX_PIXELMAP_RADIO_OFF_ID;
148 
149     return info;
150 }
151 
GenerateFromInfo(GX_WIDGET * parent,widget_info * info)152 GX_WIDGET *radio_button_service_provider::GenerateFromInfo(GX_WIDGET *parent, widget_info *info)
153 {
154     GX_RADIO_BUTTON *button = new GX_RADIO_BUTTON;
155     gx_radio_button_create(button,
156         (CHAR *) info->app_name.GetString(),
157         parent,
158         info->string_id[0],
159         info->style,
160         0,
161         &info->size);
162 
163     if(info->pixelmap_id[RADIO_OFF_PIXELMAP_INDEX] == 0)
164     {
165         info->pixelmap_id[RADIO_OFF_PIXELMAP_INDEX] = GX_PIXELMAP_RADIO_OFF_ID;
166     }
167     if (info->pixelmap_id[RADIO_ON_PIXELMAP_INDEX] == 0)
168     {
169         info->pixelmap_id[RADIO_ON_PIXELMAP_INDEX] = GX_PIXELMAP_RADIO_ON_ID;
170     }
171 
172     gx_radio_button_pixelmap_set(button,
173         info->pixelmap_id[RADIO_OFF_PIXELMAP_INDEX],
174         info->pixelmap_id[RADIO_ON_PIXELMAP_INDEX],
175         info->pixelmap_id[RADIO_OFF_DISABLED_PIXELMAP_INDEX],
176         info->pixelmap_id[RADIO_ON_DISABLED_PIXELMAP_INDEX]);
177 
178     GX_TEXT_BUTTON *tb = (GX_TEXT_BUTTON *) button;
179 
180     gx_widget_fill_color_set(tb,
181         info->color_id[NORMAL_FILL_COLOR_INDEX],
182         info->color_id[SELECTED_FILL_COLOR_INDEX],
183         info->color_id[DISABLED_FILL_COLOR_INDEX]);
184 
185     gx_text_button_text_color_set(tb,
186         info->color_id[NORMAL_TEXT_COLOR_INDEX],
187         info->color_id[SELECTED_TEXT_COLOR_INDEX],
188         info->color_id[DISABLED_TEXT_COLOR_INDEX]);
189 
190     gx_text_button_font_set(tb, info->font_id[0]);
191     return ((GX_WIDGET *) button);
192 }
193 
SaveToProject(xml_writer & writer,studiox_project * project,int display,widget_info * info)194 void radio_button_service_provider::SaveToProject(xml_writer &writer, studiox_project *project, int display, widget_info *info)
195 {
196     text_button_service_provider::SaveToProject(writer, project, display, info);
197     WritePixelmapId(writer, project, display, "off_pixelmap_id", info->pixelmap_id[UNCHECKED_PIXELMAP_INDEX]);
198     WritePixelmapId(writer, project, display, "on_pixelmap_id", info->pixelmap_id[CHECKED_PIXELMAP_INDEX]);
199     WritePixelmapId(writer, project, display, "off_disabled_pixelmap_id", info->pixelmap_id[UNCHECKED_DISABLED_PIXELMAP_INDEX]);
200     WritePixelmapId(writer, project, display, "on_disabled_pixelmap_id", info->pixelmap_id[CHECKED_DISABLED_PIXELMAP_INDEX]);
201 }
202 
ReadFromProject(xml_reader & reader,studiox_project * project,int display,widget_info * info,ULONG valid_styles)203 void radio_button_service_provider::ReadFromProject(xml_reader &reader, studiox_project *project, int display, widget_info *info, ULONG valid_styles)
204 {
205     text_button_service_provider::ReadFromProject(reader, project, display, info, valid_styles);
206     info->pixelmap_id[UNCHECKED_PIXELMAP_INDEX] = ReadPixelmapId(reader, project, display, "off_pixelmap_id");
207     info->pixelmap_id[CHECKED_PIXELMAP_INDEX] = ReadPixelmapId(reader, project, display, "on_pixelmap_id");
208     info->pixelmap_id[UNCHECKED_DISABLED_PIXELMAP_INDEX] = ReadPixelmapId(reader, project, display, "off_disabled_pixelmap_id");
209     info->pixelmap_id[CHECKED_DISABLED_PIXELMAP_INDEX] = ReadPixelmapId(reader, project, display, "on_disabled_pixelmap_id");
210 }
211 
AssignPixelmap(widget_info * info,int index,GX_RESOURCE_ID pixmap_id)212 void radio_button_service_provider::AssignPixelmap(widget_info *info, int index,
213     GX_RESOURCE_ID pixmap_id)
214 {
215     info->pixelmap_id[index] = pixmap_id;
216     GX_WIDGET *widget = info->widget;
217 
218     if (widget)
219     {
220         GX_RADIO_BUTTON *button = (GX_RADIO_BUTTON *)widget;
221         GX_RESOURCE_ID off = button->gx_radio_button_off_pixelmap_id;
222         GX_RESOURCE_ID on = button->gx_radio_button_on_pixelmap_id;
223         GX_RESOURCE_ID dis_off = button->gx_radio_button_off_disabled_pixelmap_id;
224         GX_RESOURCE_ID dis_on = button->gx_radio_button_on_disabled_pixelmap_id;
225 
226         switch (index)
227         {
228         case RADIO_OFF_PIXELMAP_INDEX:
229             if (pixmap_id)
230             {
231                 off = pixmap_id;
232             }
233             else
234             {
235                 off = GX_PIXELMAP_RADIO_OFF_ID;
236             }
237             break;
238         case RADIO_ON_PIXELMAP_INDEX:
239             if (pixmap_id)
240             {
241                 on = pixmap_id;
242             }
243             else
244             {
245                 on = GX_PIXELMAP_RADIO_ON_ID;
246             }
247             break;
248         case RADIO_OFF_DISABLED_PIXELMAP_INDEX:
249             if (pixmap_id)
250             {
251                 dis_off = pixmap_id;
252             }
253             else
254             {
255                 dis_off = GX_PIXELMAP_RADIO_OFF_ID;
256             }
257             break;
258         case RADIO_ON_DISABLED_PIXELMAP_INDEX:
259             if (pixmap_id)
260             {
261                 dis_on = pixmap_id;
262             }
263             else
264             {
265                 dis_on = GX_PIXELMAP_RADIO_ON_ID;
266             }
267             break;
268         }
269 
270         gx_radio_button_pixelmap_set(button, off, on, dis_off, dis_on);
271     }
272 }
273 
Autosize(widget_info * info)274 void radio_button_service_provider::Autosize(widget_info *info)
275 {
276     CheckResizeToText(info);
277     CheckResizeToPixelmap(info, RESIZE_MODE_HEIGHT, TRUE);
278 }
279