1 
2 #include "studiox_includes.h"
3 
4 #ifdef _DEBUG
5 #define new DEBUG_NEW
6 #endif
7 
radial_progress_bar_service_provider()8 radial_progress_bar_service_provider::radial_progress_bar_service_provider()
9 {
10 }
11 
GetVarDeclaration()12 CString radial_progress_bar_service_provider::GetVarDeclaration()
13 {
14     return CString("GX_RADIAL_PROGRESS_BAR_MEMBERS_DECLARE");
15 }
16 
DeclarePropertiesStruct()17 CString radial_progress_bar_service_provider::DeclarePropertiesStruct()
18 {
19     CString out("");
20     return out;
21 }
22 
WriteExtendedProperties(screen_generator * gen,CString & prefix,widget_info * info)23 CString radial_progress_bar_service_provider::WriteExtendedProperties(screen_generator *gen, CString &prefix, widget_info *info)
24 {
25     CString out;
26     CString propname = prefix + info->app_name;
27     if (project_lib_version() > 50401)
28     {
29         out.Format(_T("GX_RADIAL_PROGRESS_BAR_INFO %s_properties =\n")
30             _T("{\n")
31             _T("    %d, /* xcenter */\n")
32             _T("    %d, /* ycenter */\n")
33             _T("    %d, /* radius */\n")
34             _T("    %d, /* current val */\n")
35             _T("    %d, /* anchor val*/\n")
36             _T("    %s, /* font_id */\n")
37             _T("    %s, /* normal text color */\n")
38             _T("    %s, /* selected text color */\n")
39             _T("    %s, /* disabled text color*/\n")
40             _T("    %d, /* normal brush width */\n")
41             _T("    %d, /* selected brush width */\n")
42             _T("    %s, /* normal brush color */\n")
43             _T("    %s, /* selected brush color */\n")
44             _T("};\n"),
45             propname,
46             info->ewi.radial_progress.gx_radial_progress_bar_info_xcenter,
47             info->ewi.radial_progress.gx_radial_progress_bar_info_ycenter,
48             info->ewi.radial_progress.gx_radial_progress_bar_info_radius,
49             info->ewi.radial_progress.gx_radial_progress_bar_info_current_val,
50             info->ewi.radial_progress.gx_radial_progress_bar_info_anchor_val,
51             gen->GetFontIdName(info->font_id[0]),
52             gen->GetColorIdName(info->color_id[NORMAL_TEXT_COLOR_INDEX]),
53             gen->GetColorIdName(info->color_id[SELECTED_TEXT_COLOR_INDEX]),
54             gen->GetColorIdName(info->color_id[DISABLED_TEXT_COLOR_INDEX]),
55             info->ewi.radial_progress.gx_radial_progress_bar_info_normal_brush_width,
56             info->ewi.radial_progress.gx_radial_progress_bar_info_selected_brush_width,
57             gen->GetColorIdName(info->ewi.radial_progress.gx_radial_progress_bar_info_normal_brush_color),
58             gen->GetColorIdName(info->ewi.radial_progress.gx_radial_progress_bar_info_selected_brush_color));
59     }
60     else
61     {
62         out.Format(_T("GX_RADIAL_PROGRESS_BAR_INFO %s_properties =\n")
63             _T("{\n")
64             _T("    %d, /* xcenter */\n")
65             _T("    %d, /* ycenter */\n")
66             _T("    %d, /* radius */\n")
67             _T("    %d, /* current val */\n")
68             _T("    %d, /* anchor val*/\n")
69             _T("    %s, /* font_id */\n")
70             _T("    %s, /* normal text color */\n")
71             _T("    %s, /* selected text color */\n")
72             _T("    %d, /* normal brush width */\n")
73             _T("    %d, /* selected brush width */\n")
74             _T("    %s, /* normal brush color */\n")
75             _T("    %s, /* selected brush color */\n")
76             _T("};\n"),
77             propname,
78             info->ewi.radial_progress.gx_radial_progress_bar_info_xcenter,
79             info->ewi.radial_progress.gx_radial_progress_bar_info_ycenter,
80             info->ewi.radial_progress.gx_radial_progress_bar_info_radius,
81             info->ewi.radial_progress.gx_radial_progress_bar_info_current_val,
82             info->ewi.radial_progress.gx_radial_progress_bar_info_anchor_val,
83             gen->GetFontIdName(info->font_id[0]),
84             gen->GetColorIdName(info->color_id[NORMAL_TEXT_COLOR_INDEX]),
85             gen->GetColorIdName(info->color_id[SELECTED_TEXT_COLOR_INDEX]),
86             info->ewi.radial_progress.gx_radial_progress_bar_info_normal_brush_width,
87             info->ewi.radial_progress.gx_radial_progress_bar_info_selected_brush_width,
88             gen->GetColorIdName(info->ewi.radial_progress.gx_radial_progress_bar_info_normal_brush_color),
89             gen->GetColorIdName(info->ewi.radial_progress.gx_radial_progress_bar_info_selected_brush_color));
90     }
91 
92     return out;
93 }
94 
GetCreateFromDefFunctionName()95 CString radial_progress_bar_service_provider::GetCreateFromDefFunctionName()
96 {
97     return CString("gx_studio_radial_progress_bar_create");
98 }
99 
GetCreateFromDefFunction(int version)100 CString radial_progress_bar_service_provider::GetCreateFromDefFunction(int version)
101 {
102     CString out;
103     MakeCreatePreamble("radial_progress_bar", version, out);
104 
105     out += "{\n"
106         "    UINT status;\n"
107         "    GX_RADIAL_PROGRESS_BAR *bar = (GX_RADIAL_PROGRESS_BAR *) control_block;\n"
108         "    GX_RADIAL_PROGRESS_BAR_INFO *bar_info = (GX_RADIAL_PROGRESS_BAR_INFO *) info->properties;\n"
109         "    status = gx_radial_progress_bar_create(bar,\n"
110         "                    info->widget_name,\n"
111         "                    parent,\n"
112         "                    bar_info,\n"
113         "                    info->style,\n"
114         "                    info->widget_id);\n"
115         "    return status;\n"
116         "}\n";
117     return out;
118 
119 }
120 
CreateNewInstance(GX_WIDGET * parent)121 widget_info *radial_progress_bar_service_provider::CreateNewInstance(GX_WIDGET *parent)
122 {
123     GX_RADIAL_PROGRESS_BAR_INFO props;
124     int xcenter;
125     int ycenter;
126 
127     xcenter = (parent->gx_widget_size.gx_rectangle_left + parent->gx_widget_size.gx_rectangle_right) >> 1;
128     ycenter = (parent->gx_widget_size.gx_rectangle_top + parent->gx_widget_size.gx_rectangle_bottom) >> 1;
129 
130     GX_RADIAL_PROGRESS_BAR *bar = new GX_RADIAL_PROGRESS_BAR;
131     props.gx_radial_progress_bar_info_xcenter = xcenter;
132     props.gx_radial_progress_bar_info_ycenter = ycenter;
133     props.gx_radial_progress_bar_info_radius = 100;
134     props.gx_radial_progress_bar_info_anchor_val = 90;
135     props.gx_radial_progress_bar_info_current_val = -180;
136     props.gx_radial_progress_bar_info_font_id = GX_FONT_ID_DEFAULT;
137     props.gx_radial_progress_bar_info_normal_text_color = GX_COLOR_ID_TEXT;
138     props.gx_radial_progress_bar_info_selected_text_color = GX_COLOR_ID_SELECTED_TEXT;
139     props.gx_radial_progress_bar_info_disabled_text_color = GX_COLOR_ID_DISABLED_TEXT;
140     props.gx_radial_progress_bar_info_normal_brush_color = GX_COLOR_ID_SLIDER_NEEDLE_FILL;
141     props.gx_radial_progress_bar_info_selected_brush_color = GX_COLOR_ID_SELECTED_FILL;
142     props.gx_radial_progress_bar_info_normal_brush_width = 20;
143     props.gx_radial_progress_bar_info_selected_brush_width = 20;
144 
145     gx_radial_progress_bar_create(bar,
146                     "radial_progress_bar",
147                     parent, &props,
148                     GX_STYLE_ENABLED | GX_STYLE_BORDER_NONE | GX_STYLE_TRANSPARENT | GX_STYLE_PROGRESS_PERCENT |
149                     GX_STYLE_PROGRESS_TEXT_DRAW | GX_STYLE_RADIAL_PROGRESS_ALIAS | GX_STYLE_RADIAL_PROGRESS_ROUND, 0);
150 
151     widget_info *info = InitWidgetInfo((GX_WIDGET *) bar);
152 
153     info->ewi.radial_progress = props;
154     info->font_id[0] =  props.gx_radial_progress_bar_info_font_id;
155     info->color_id[NORMAL_TEXT_COLOR_INDEX] = props.gx_radial_progress_bar_info_normal_text_color;
156     info->color_id[SELECTED_TEXT_COLOR_INDEX] = props.gx_radial_progress_bar_info_selected_text_color;
157     info->color_id[DISABLED_TEXT_COLOR_INDEX] = props.gx_radial_progress_bar_info_disabled_text_color;
158 
159     return info;
160 }
161 
GenerateFromInfo(GX_WIDGET * parent,widget_info * info)162 GX_WIDGET *radial_progress_bar_service_provider::GenerateFromInfo(GX_WIDGET *parent, widget_info *info)
163 {
164     GX_RADIAL_PROGRESS_BAR *bar = new GX_RADIAL_PROGRESS_BAR;
165     GX_RADIAL_PROGRESS_BAR_INFO *props = &info->ewi.radial_progress;
166 
167     props->gx_radial_progress_bar_info_xcenter = info->ewi.radial_progress.gx_radial_progress_bar_info_xcenter;
168     props->gx_radial_progress_bar_info_ycenter = info->ewi.radial_progress.gx_radial_progress_bar_info_ycenter;
169     props->gx_radial_progress_bar_info_radius = info->ewi.radial_progress.gx_radial_progress_bar_info_radius;
170     props->gx_radial_progress_bar_info_anchor_val = info->ewi.radial_progress.gx_radial_progress_bar_info_anchor_val;
171     props->gx_radial_progress_bar_info_current_val = info->ewi.radial_progress.gx_radial_progress_bar_info_current_val;
172     props->gx_radial_progress_bar_info_normal_brush_width = info->ewi.radial_progress.gx_radial_progress_bar_info_normal_brush_width;
173     props->gx_radial_progress_bar_info_selected_brush_width = info->ewi.radial_progress.gx_radial_progress_bar_info_selected_brush_width;
174     props->gx_radial_progress_bar_info_normal_brush_color = info->ewi.radial_progress.gx_radial_progress_bar_info_normal_brush_color;
175     props->gx_radial_progress_bar_info_selected_brush_color = info->ewi.radial_progress.gx_radial_progress_bar_info_selected_brush_color;
176     props->gx_radial_progress_bar_info_font_id = info->font_id[0];
177     props->gx_radial_progress_bar_info_normal_text_color = info->color_id[NORMAL_TEXT_COLOR_INDEX];
178     props->gx_radial_progress_bar_info_selected_text_color = info->color_id[SELECTED_TEXT_COLOR_INDEX];
179     props->gx_radial_progress_bar_info_disabled_text_color = info->color_id[DISABLED_TEXT_COLOR_INDEX];
180 
181     gx_radial_progress_bar_create(bar,
182         (CHAR *) info->app_name.GetString(),
183         parent, props,
184         info->style,
185         0);
186 
187     gx_widget_fill_color_set((GX_WIDGET *) bar,
188                              info->color_id[NORMAL_FILL_COLOR_INDEX],
189                              info->color_id[SELECTED_FILL_COLOR_INDEX],
190                              info->color_id[DISABLED_FILL_COLOR_INDEX]);
191 
192     return ((GX_WIDGET *) bar);
193 }
194 
AssignFont(widget_info * info,int index,GX_RESOURCE_ID font_id)195 void radial_progress_bar_service_provider::AssignFont(widget_info *info, int index,
196     GX_RESOURCE_ID font_id)
197 {
198     GX_WIDGET *widget = info->widget;
199 
200     if (widget)
201     {
202         GX_RADIAL_PROGRESS_BAR *bar = (GX_RADIAL_PROGRESS_BAR *)widget;
203         gx_radial_progress_bar_font_set(bar, font_id);
204     }
205 
206     info->font_id[0] = font_id;
207     info->ewi.radial_progress.gx_radial_progress_bar_info_font_id = font_id;
208 }
209 
AssignColor(widget_info * info,int index,GX_RESOURCE_ID color_id)210 void radial_progress_bar_service_provider::AssignColor(widget_info *info, int index, GX_RESOURCE_ID color_id)
211 {
212     GX_RADIAL_PROGRESS_BAR *bar = (GX_RADIAL_PROGRESS_BAR *) (info->widget);
213     GX_RADIAL_PROGRESS_BAR_INFO *progress_info;
214 
215     if (bar)
216     {
217         progress_info = &bar->gx_radial_progress_bar_info;
218     }
219 
220     switch(index)
221     {
222     case NORMAL_TEXT_COLOR_INDEX:
223         if (bar)
224         {
225             gx_radial_progress_bar_text_color_set(bar, color_id, progress_info->gx_radial_progress_bar_info_selected_text_color,
226                 progress_info->gx_radial_progress_bar_info_disabled_text_color);
227         }
228 
229         info->ewi.radial_progress.gx_radial_progress_bar_info_normal_text_color = color_id;
230         info->color_id[NORMAL_TEXT_COLOR_INDEX] = color_id;
231         break;
232 
233     case SELECTED_TEXT_COLOR_INDEX:
234         if (bar)
235         {
236             gx_radial_progress_bar_text_color_set(bar, progress_info->gx_radial_progress_bar_info_normal_text_color, color_id,
237                 progress_info->gx_radial_progress_bar_info_disabled_text_color);
238         }
239 
240         info->ewi.radial_progress.gx_radial_progress_bar_info_selected_text_color = color_id;
241         info->color_id[SELECTED_TEXT_COLOR_INDEX] = color_id;
242         break;
243 
244     case DISABLED_TEXT_COLOR_INDEX:
245         if (bar)
246         {
247             gx_radial_progress_bar_text_color_set(bar, progress_info->gx_radial_progress_bar_info_normal_text_color,
248                 progress_info->gx_radial_progress_bar_info_selected_text_color, color_id);
249         }
250 
251         info->ewi.radial_progress.gx_radial_progress_bar_info_disabled_text_color = color_id;
252         info->color_id[DISABLED_TEXT_COLOR_INDEX] = color_id;
253         break;
254 
255     default:
256         widget_service_provider::AssignColor(info, index, color_id);
257     }
258 }
259 
260 
SaveToProject(xml_writer & writer,studiox_project * project,int display,widget_info * info)261 void radial_progress_bar_service_provider::SaveToProject(xml_writer &writer, studiox_project *project, int display, widget_info *info)
262 {
263     widget_service_provider::SaveToProject(writer, project, display, info);
264     writer.WriteInt("xcenter", info->ewi.radial_progress.gx_radial_progress_bar_info_xcenter);
265     writer.WriteInt("ycenter", info->ewi.radial_progress.gx_radial_progress_bar_info_ycenter);
266     writer.WriteInt("radius", info->ewi.radial_progress.gx_radial_progress_bar_info_radius);
267     writer.WriteInt("anchor_val", info->ewi.radial_progress.gx_radial_progress_bar_info_anchor_val);
268     writer.WriteInt("current_val", info->ewi.radial_progress.gx_radial_progress_bar_info_current_val);
269     writer.WriteInt("normal_brush_width", info->ewi.radial_progress.gx_radial_progress_bar_info_normal_brush_width);
270     writer.WriteInt("selected_brush_width", info->ewi.radial_progress.gx_radial_progress_bar_info_selected_brush_width);
271     WriteColorId(writer, project, display, "normal_brush_color", info->ewi.radial_progress.gx_radial_progress_bar_info_normal_brush_color);
272     WriteColorId(writer, project, display, "selected_brush_color", info->ewi.radial_progress.gx_radial_progress_bar_info_selected_brush_color);
273     WriteColorId(writer, project, display, "normal_text_color", info->color_id[NORMAL_TEXT_COLOR_INDEX]);
274     WriteColorId(writer, project, display, "selected_text_color", info->color_id[SELECTED_TEXT_COLOR_INDEX]);
275     WriteColorId(writer, project, display, "disabled_text_color", info->color_id[DISABLED_TEXT_COLOR_INDEX]);
276     WriteFontId(writer, project, display, "font_id", info->font_id[0]);
277 }
278 
ReadFromProject(xml_reader & reader,studiox_project * project,int display,widget_info * info,ULONG valid_styles)279 void radial_progress_bar_service_provider::ReadFromProject(xml_reader &reader, studiox_project *project, int display, widget_info *info, ULONG valid_styles)
280 {
281     valid_styles |= GX_STYLE_PROGRESS_PERCENT|GX_STYLE_PROGRESS_TEXT_DRAW|GX_STYLE_PROGRESS_VERTICAL;
282     valid_styles |= GX_STYLE_RADIAL_PROGRESS_ALIAS|GX_STYLE_RADIAL_PROGRESS_ROUND|GX_STYLE_RADIAL_PROGRESS_NO_BACKTRACK;
283 
284     widget_service_provider::ReadFromProject(reader, project, display, info, valid_styles);
285     reader.ReadValue("xcenter", info->ewi.radial_progress.gx_radial_progress_bar_info_xcenter);
286     reader.ReadValue("ycenter", info->ewi.radial_progress.gx_radial_progress_bar_info_ycenter);
287     reader.ReadValue("radius", info->ewi.radial_progress.gx_radial_progress_bar_info_radius);
288     reader.ReadValue("anchor_val", info->ewi.radial_progress.gx_radial_progress_bar_info_anchor_val);
289     reader.ReadValue("current_val", info->ewi.radial_progress.gx_radial_progress_bar_info_current_val);
290     reader.ReadValue("normal_brush_width", info->ewi.radial_progress.gx_radial_progress_bar_info_normal_brush_width);
291     reader.ReadValue("selected_brush_width", info->ewi.radial_progress.gx_radial_progress_bar_info_selected_brush_width);
292     info->ewi.radial_progress.gx_radial_progress_bar_info_normal_brush_color = ReadColorId(reader, project, display, "normal_brush_color");
293     info->ewi.radial_progress.gx_radial_progress_bar_info_selected_brush_color = ReadColorId(reader, project, display, "selected_brush_color");
294     info->color_id[NORMAL_TEXT_COLOR_INDEX] = ReadColorId(reader, project, display, "normal_text_color");
295     info->color_id[SELECTED_TEXT_COLOR_INDEX] = ReadColorId(reader, project, display, "selected_text_color");
296     if (project->mHeader.project_version > 54)
297     {
298         info->color_id[DISABLED_TEXT_COLOR_INDEX] = ReadColorId(reader, project, display, "disabled_text_color");
299     }
300     else
301     {
302         info->color_id[DISABLED_TEXT_COLOR_INDEX] = info->color_id[NORMAL_TEXT_COLOR_INDEX];
303     }
304     info->font_id[0] = ReadFontId(reader, project, display, "font_id");
305 }
306