1
2 #include "studiox_includes.h"
3
4 #ifdef _DEBUG
5 #define new DEBUG_NEW
6 #endif
7
progress_bar_service_provider()8 progress_bar_service_provider::progress_bar_service_provider()
9 {
10 }
11
GetVarDeclaration()12 CString progress_bar_service_provider::GetVarDeclaration()
13 {
14 return CString("GX_PROGRESS_BAR_MEMBERS_DECLARE");
15 }
16
DeclarePropertiesStruct()17 CString 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 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_PROGRESS_BAR_INFO %s_properties =\n")
30 _T("{\n")
31 _T(" %d, /* mimimun value */\n")
32 _T(" %d, /* maximum value */\n")
33 _T(" %d, /* current value */\n")
34 _T(" %s, /* font_id */\n")
35 _T(" %s, /* normal text color */\n")
36 _T(" %s, /* selected text color */\n")
37 _T(" %s, /* disabled text color*/\n")
38 _T(" %s /* fill pixelmap */\n};\n"),
39 propname,
40 info->ewi.progress.min_val,
41 info->ewi.progress.max_val,
42 info->ewi.progress.current_val,
43 gen->GetFontIdName(info->font_id[0]),
44 gen->GetColorIdName(info->color_id[NORMAL_TEXT_COLOR_INDEX]),
45 gen->GetColorIdName(info->color_id[SELECTED_TEXT_COLOR_INDEX]),
46 gen->GetColorIdName(info->color_id[DISABLED_TEXT_COLOR_INDEX]),
47 gen->GetPixelmapIdName(info->pixelmap_id[NORMAL_PIXELMAP_INDEX]));
48 }
49 else
50 {
51 out.Format(_T("GX_PROGRESS_BAR_INFO %s_properties =\n")
52 _T("{\n")
53 _T(" %d, /* mimimun value */\n")
54 _T(" %d, /* maximum value */\n")
55 _T(" %d, /* current value */\n")
56 _T(" %s, /* font_id */\n")
57 _T(" %s, /* normal text color */\n")
58 _T(" %s, /* selected text color */\n")
59 _T(" %s /* fill pixelmap */\n};\n"),
60 propname,
61 info->ewi.progress.min_val,
62 info->ewi.progress.max_val,
63 info->ewi.progress.current_val,
64 gen->GetFontIdName(info->font_id[0]),
65 gen->GetColorIdName(info->color_id[NORMAL_TEXT_COLOR_INDEX]),
66 gen->GetColorIdName(info->color_id[SELECTED_TEXT_COLOR_INDEX]),
67 gen->GetPixelmapIdName(info->pixelmap_id[NORMAL_PIXELMAP_INDEX]));
68 }
69 return out;
70 }
71
GetCreateFromDefFunctionName()72 CString progress_bar_service_provider::GetCreateFromDefFunctionName()
73 {
74 return CString("gx_studio_progress_bar_create");
75 }
76
GetCreateFromDefFunction(int version)77 CString progress_bar_service_provider::GetCreateFromDefFunction(int version)
78 {
79 CString out;
80 MakeCreatePreamble("progress_bar", version, out);
81
82 out += "{\n"
83 " UINT status;\n"
84 " GX_PROGRESS_BAR *bar = (GX_PROGRESS_BAR *) control_block;\n"
85 " GX_PROGRESS_BAR_INFO *bar_info = (GX_PROGRESS_BAR_INFO *) info->properties;\n"
86 " status = gx_progress_bar_create(bar,\n"
87 " info->widget_name,\n"
88 " parent,\n"
89 " bar_info,\n"
90 " info->style,\n"
91 " info->widget_id,\n"
92 " &info->size);\n"
93 " return status;\n"
94 "}\n";
95 return out;
96
97 }
98
CreateNewInstance(GX_WIDGET * parent)99 widget_info *progress_bar_service_provider::CreateNewInstance(GX_WIDGET *parent)
100 {
101 GX_RECTANGLE size;
102 GX_PROGRESS_BAR_INFO props;
103
104 gx_utility_rectangle_define(&size, 0, 0, 79, 23);
105 gx_utility_rectangle_center(&size, &parent->gx_widget_size);
106
107 GX_PROGRESS_BAR *bar = new GX_PROGRESS_BAR;
108 props.gx_progress_bar_info_current_val = 50;
109 props.gx_progress_bar_info_min_val = 0;
110 props.gx_progress_bar_info_max_val = 100;
111 props.gx_progress_bar_font_id = GX_FONT_ID_DEFAULT;
112 props.gx_progress_bar_normal_text_color = GX_COLOR_ID_TEXT;
113 props.gx_progress_bar_selected_text_color = GX_COLOR_ID_SELECTED_TEXT;
114 props.gx_progress_bar_disabled_text_color = GX_COLOR_ID_DISABLED_TEXT;
115 props.gx_progress_bar_fill_pixelmap = GX_PIXELMAP_NULL;
116
117 gx_progress_bar_create(bar,
118 "progress_bar",
119 parent, &props,
120 GX_STYLE_ENABLED | GX_STYLE_BORDER_RAISED | GX_STYLE_PROGRESS_PERCENT | GX_STYLE_PROGRESS_TEXT_DRAW,
121 0, &size);
122
123 widget_info *info = InitWidgetInfo((GX_WIDGET *) bar);
124
125 info->ewi.progress.current_val = props.gx_progress_bar_info_current_val;
126 info->ewi.progress.min_val = props.gx_progress_bar_info_min_val;
127 info->ewi.progress.max_val = props.gx_progress_bar_info_max_val;
128 info->font_id[0] = props.gx_progress_bar_font_id;
129 info->color_id[NORMAL_TEXT_COLOR_INDEX] = props.gx_progress_bar_normal_text_color;
130 info->color_id[SELECTED_TEXT_COLOR_INDEX] = props.gx_progress_bar_selected_text_color;
131 info->color_id[DISABLED_TEXT_COLOR_INDEX] = props.gx_progress_bar_disabled_text_color;
132 info->pixelmap_id[NORMAL_PIXELMAP_INDEX] = props.gx_progress_bar_fill_pixelmap;
133 return info;
134 }
135
GenerateFromInfo(GX_WIDGET * parent,widget_info * info)136 GX_WIDGET *progress_bar_service_provider::GenerateFromInfo(GX_WIDGET *parent, widget_info *info)
137 {
138 GX_PROGRESS_BAR *bar = new GX_PROGRESS_BAR;
139 GX_PROGRESS_BAR_INFO props;
140
141 props.gx_progress_bar_info_current_val = info->ewi.progress.current_val;
142 props.gx_progress_bar_info_min_val = info->ewi.progress.min_val;
143 props.gx_progress_bar_info_max_val = info->ewi.progress.max_val;
144 props.gx_progress_bar_font_id = info->font_id[0];
145 props.gx_progress_bar_normal_text_color = info->color_id[NORMAL_TEXT_COLOR_INDEX];
146 props.gx_progress_bar_selected_text_color = info->color_id[SELECTED_TEXT_COLOR_INDEX];
147 props.gx_progress_bar_disabled_text_color = info->color_id[DISABLED_TEXT_COLOR_INDEX];
148 props.gx_progress_bar_fill_pixelmap = info->pixelmap_id[NORMAL_PIXELMAP_INDEX];
149
150 gx_progress_bar_create(bar,
151 (CHAR *) info->app_name.GetString(),
152 parent, &props,
153 info->style,
154 0,
155 &info->size);
156
157 gx_widget_fill_color_set((GX_WIDGET *) bar,
158 info->color_id[NORMAL_FILL_COLOR_INDEX], info->color_id[SELECTED_FILL_COLOR_INDEX], info->color_id[DISABLED_FILL_COLOR_INDEX]);
159 return ((GX_WIDGET *) bar);
160 }
161
AssignFont(widget_info * info,int index,GX_RESOURCE_ID font_id)162 void progress_bar_service_provider::AssignFont(widget_info *info, int index,
163 GX_RESOURCE_ID font_id)
164 {
165 GX_WIDGET *widget = info->widget;
166
167 if (widget)
168 {
169 GX_PROGRESS_BAR *bar = (GX_PROGRESS_BAR *)widget;
170 gx_progress_bar_font_set(bar, font_id);
171 }
172
173 info->font_id[0] = font_id;
174 }
175
AssignColor(widget_info * info,int index,GX_RESOURCE_ID color_id)176 void progress_bar_service_provider::AssignColor(widget_info *info, int index, GX_RESOURCE_ID color_id)
177 {
178 GX_PROGRESS_BAR *bar = (GX_PROGRESS_BAR *) (info->widget);
179 GX_PROGRESS_BAR_INFO *bar_info;
180
181 if (bar)
182 {
183 bar_info = &bar->gx_progress_bar_info;
184 }
185
186 switch(index)
187 {
188 case NORMAL_TEXT_COLOR_INDEX:
189 if (bar)
190 {
191 gx_progress_bar_text_color_set(bar, color_id, bar_info->gx_progress_bar_selected_text_color,
192 bar_info->gx_progress_bar_disabled_text_color);
193 }
194
195 info->color_id[NORMAL_TEXT_COLOR_INDEX] = color_id;
196 break;
197
198 case SELECTED_TEXT_COLOR_INDEX:
199 if (bar)
200 {
201 gx_progress_bar_text_color_set(bar, bar_info->gx_progress_bar_normal_text_color, color_id,
202 bar_info->gx_progress_bar_disabled_text_color);
203 }
204
205 info->color_id[SELECTED_TEXT_COLOR_INDEX] = color_id;
206 break;
207
208 case DISABLED_TEXT_COLOR_INDEX:
209 if (bar)
210 {
211 gx_progress_bar_text_color_set(bar, bar_info->gx_progress_bar_normal_text_color,
212 bar_info->gx_progress_bar_selected_text_color, color_id);
213 }
214
215 info->color_id[DISABLED_TEXT_COLOR_INDEX] = color_id;
216 break;
217
218 default:
219 widget_service_provider::AssignColor(info, index, color_id);
220 }
221 }
222
AssignPixelmap(widget_info * info,int index,GX_RESOURCE_ID pixmap_id)223 void progress_bar_service_provider::AssignPixelmap(widget_info *info, int index, GX_RESOURCE_ID pixmap_id)
224 {
225 GX_WIDGET *widget = info->widget;
226
227 if (index == NORMAL_PIXELMAP_INDEX)
228 {
229 info->pixelmap_id[NORMAL_PIXELMAP_INDEX] = pixmap_id;
230
231 if (widget)
232 {
233 GX_PROGRESS_BAR *pb = (GX_PROGRESS_BAR *)widget;
234 gx_progress_bar_pixelmap_set(pb, pixmap_id);
235 }
236 }
237 }
238
239
Autosize(widget_info * info)240 void progress_bar_service_provider::Autosize(widget_info *info)
241 {
242 GX_PROGRESS_BAR *bar = (GX_PROGRESS_BAR *) info->widget;
243
244 if (bar)
245 {
246 if (info->pixelmap_id[0])
247 {
248 if (bar->gx_widget_style & GX_STYLE_PROGRESS_VERTICAL)
249 {
250 CheckResizeToPixelmap(info, RESIZE_MODE_WIDTH);
251 }
252 else
253 {
254 CheckResizeToPixelmap(info, RESIZE_MODE_HEIGHT);
255 }
256 }
257 }
258 }
259
SaveToProject(xml_writer & writer,studiox_project * project,int display,widget_info * info)260 void progress_bar_service_provider::SaveToProject(xml_writer &writer, studiox_project *project, int display, widget_info *info)
261 {
262 widget_service_provider::SaveToProject(writer, project, display, info);
263 writer.WriteInt("minval", info->ewi.progress.min_val);
264 writer.WriteInt("maxval", info->ewi.progress.max_val);
265 writer.WriteInt("current_val", info->ewi.progress.current_val);
266 WriteFontId(writer, project, display, "font_id", info->font_id[0]);
267 WriteColorId(writer, project, display, "normal_text_color", info->color_id[NORMAL_TEXT_COLOR_INDEX]);
268 WriteColorId(writer, project, display, "selected_text_color", info->color_id[SELECTED_TEXT_COLOR_INDEX]);
269 WriteColorId(writer, project, display, "disabled_text_color", info->color_id[DISABLED_TEXT_COLOR_INDEX]);
270 WritePixelmapId(writer, project, display, "fill_pixelmap", info->pixelmap_id[NORMAL_PIXELMAP_INDEX]);
271 }
272
ReadFromProject(xml_reader & reader,studiox_project * project,int display,widget_info * info,ULONG valid_styles)273 void progress_bar_service_provider::ReadFromProject(xml_reader &reader, studiox_project *project, int display, widget_info *info, ULONG valid_styles)
274 {
275 valid_styles |= GX_STYLE_PROGRESS_PERCENT|GX_STYLE_PROGRESS_TEXT_DRAW|GX_STYLE_PROGRESS_VERTICAL|GX_STYLE_PROGRESS_SEGMENTED_FILL;
276 widget_service_provider::ReadFromProject(reader, project, display, info, valid_styles);
277 reader.ReadInt("minval", info->ewi.progress.min_val);
278 reader.ReadInt("maxval", info->ewi.progress.max_val);
279 reader.ReadInt("current_val", info->ewi.progress.current_val);
280 info->font_id[0] = ReadFontId(reader, project, display, "font_id");
281 info->color_id[NORMAL_TEXT_COLOR_INDEX] = ReadColorId(reader, project, display, "normal_text_color");
282 info->color_id[SELECTED_TEXT_COLOR_INDEX] = ReadColorId(reader, project, display, "selected_text_color");
283
284 if (project->mHeader.project_version > 54)
285 {
286 info->color_id[DISABLED_TEXT_COLOR_INDEX] = ReadColorId(reader, project, display, "disabled_text_color");
287 }
288 else
289 {
290 //selected text color is start been used after guix version 5.4.0
291 //set selected text color to normal text color incase broken old projects
292 info->color_id[SELECTED_TEXT_COLOR_INDEX] = info->color_id[NORMAL_TEXT_COLOR_INDEX];
293 info->color_id[DISABLED_TEXT_COLOR_INDEX] = info->color_id[NORMAL_TEXT_COLOR_INDEX];
294 }
295 info->pixelmap_id[NORMAL_PIXELMAP_INDEX] = ReadPixelmapId(reader, project, display, "fill_pixelmap");
296 }
297