1 
2 #include "studiox_includes.h"
3 
4 #ifdef _DEBUG
5 #define new DEBUG_NEW
6 #endif
7 
8 ///////////////////////////////////////////////////////////////////////////////
string_scroll_wheel_service_provider()9 string_scroll_wheel_service_provider::string_scroll_wheel_service_provider()
10 {
11 }
12 
13 ///////////////////////////////////////////////////////////////////////////////
GetVarDeclaration()14 CString string_scroll_wheel_service_provider::GetVarDeclaration()
15 {
16     return CString("GX_STRING_SCROLL_WHEEL_MEMBERS_DECLARE");
17 }
18 
19 ///////////////////////////////////////////////////////////////////////////////
DeclarePropertiesStruct()20 CString string_scroll_wheel_service_provider::DeclarePropertiesStruct()
21 {
22     CString out("");
23 
24     if (project_lib_version() >= 50400)
25     {
26         CString callback;
27 
28         if (project_lib_version() >= GX_VERSION_STRING_LENGTH_FIX)
29         {
30             callback = "UINT (*callback)(struct GX_STRING_SCROLL_WHEEL_STRUCT *, INT, GX_STRING *)";
31         }
32         else
33         {
34             callback = "GX_CONST GX_CHAR * (*callback)(struct GX_STRING_SCROLL_WHEEL_STRUCT *, INT)";
35         }
36 
37         out.Format(
38                  _T("typedef struct\n")
39                  _T("{\n")
40                  _T("%s\n")
41                  _T("    GX_CONST GX_RESOURCE_ID  *string_id_list;\n")
42                  _T("    %s;\n")
43                  _T("} GX_STRING_SCROLL_WHEEL_PROPERTIES;\n\n"),
44                  text_scroll_wheel_service_provider::DeclarePropertiesStructContent(),
45                  callback);
46     }
47     else
48     {
49         out.Format(
50                 _T("typedef struct\n")
51                 _T("{\n")
52                 _T("%s\n")
53                 _T("    GX_CONST GX_CHAR  **string_list;\n")
54                 _T("    GX_CONST GX_CHAR *(*callback)(struct GX_STRING_SCROLL_WHEEL_STRUCT *, INT);\n")
55                 _T("} GX_STRING_SCROLL_WHEEL_PROPERTIES;\n\n"),
56                 text_scroll_wheel_service_provider::DeclarePropertiesStructContent());
57     }
58 
59     return out;
60 }
61 
62 ///////////////////////////////////////////////////////////////////////////////
WriteExtendedProperties(screen_generator * gen,CString & prefix,widget_info * info)63 CString string_scroll_wheel_service_provider::WriteExtendedProperties(screen_generator *gen, CString &prefix, widget_info *info)
64 {
65     CString out;
66     CString propname = prefix + info->app_name;
67     CString string_list;
68     CString temp;
69     CString callback;
70     studiox_project *project = GetOpenProject();
71 
72     if (info->callback_func.IsEmpty() && project)
73     {
74         callback = "GX_NULL";
75 
76         if (info->ewi.string_scroll_wheel.string_id_list)
77         {
78             CString id_name;
79 
80             if (project->mHeader.guix_version < 50400)
81             {
82                 //old version of cold generation
83                 CString string;
84                 string_list.Format(_T("%s_string_list"), propname);
85                 out.Format(_T("GX_CONST CHAR *%s[]={\n"), string_list);
86 
87                 for (int index = 0; index < info->ewi.string_scroll_wheel.base.total_rows; index++)
88                 {
89                     string = gen->GetString(info->ewi.string_scroll_wheel.string_id_list[index]);
90 
91                     if (index == info->ewi.string_scroll_wheel.base.total_rows - 1)
92                     {
93                         temp.Format(_T("    \"%s\"\n"), string);
94                     }
95                     else
96                     {
97                         temp.Format(_T("    \"%s\",\n"), string);
98                     }
99                     out.Append(temp);
100                 }
101                 out.Append(_T("};\n"));
102             }
103             else
104             {
105                 string_list.Format(_T("%s_string_id_list"), propname);
106                 out.Format(_T("GX_CONST GX_RESOURCE_ID %s[]={\n"), string_list);
107 
108                 for (int index = 0; index < info->ewi.string_scroll_wheel.base.total_rows; index++)
109                 {
110                     id_name = gen->GetStringIdName(info->ewi.string_scroll_wheel.string_id_list[index]);
111                     if (index == info->ewi.string_scroll_wheel.base.total_rows - 1)
112                     {
113                         temp.Format(_T("    %s\n"), id_name);
114                     }
115                     else
116                     {
117                         temp.Format(_T("    %s,\n"), id_name);
118                     }
119                     out.Append(temp);
120                 }
121                 out.Append(_T("};\n"));
122             }
123         }
124         else
125         {
126             string_list = "GX_NULL";
127         }
128     }
129     else
130     {
131         callback = info->callback_func;
132         string_list = "GX_NULL";
133     }
134 
135         temp.Format(_T("GX_STRING_SCROLL_WHEEL_PROPERTIES %s_properties =\n")
136             _T("{\n")
137             _T("%s\n")
138             _T("    %s, /* string list */\n")
139         _T("    %s  /* callback */\n")
140             _T("\n};\n"),
141             propname,
142             text_scroll_wheel_service_provider::WriteExtendedPropertiesContent(gen, info, TRUE),
143             string_list,
144             callback);
145 
146     out.Append(temp);
147     return out;
148 }
149 
150 ///////////////////////////////////////////////////////////////////////////////
GetCreateFromDefFunctionName()151 CString string_scroll_wheel_service_provider::GetCreateFromDefFunctionName()
152 {
153     return CString("gx_studio_string_scroll_wheel_create");
154 }
155 
156 ///////////////////////////////////////////////////////////////////////////////
GetCreateFromDefFunction(int version)157 CString string_scroll_wheel_service_provider::GetCreateFromDefFunction(int version)
158 {
159     CString out;
160     MakeCreatePreamble("string_scroll_wheel", version, out);
161 
162     studiox_project *project = GetOpenProject();
163 
164     if (!project)
165     {
166         return out;
167     }
168 
169     out +=     "{\n"
170                "    UINT status;\n"
171                "    GX_STRING_SCROLL_WHEEL *wheel = (GX_STRING_SCROLL_WHEEL *) control_block;\n"
172                "    GX_STRING_SCROLL_WHEEL_PROPERTIES *props = (GX_STRING_SCROLL_WHEEL_PROPERTIES *) info->properties;\n";
173 
174     if (project_lib_version() >= 50400)
175     {
176         if (project_lib_version() >= GX_VERSION_STRING_LENGTH_FIX)
177         {
178             out += "    status = gx_string_scroll_wheel_create_ext(wheel, info->widget_name, parent, props->total_rows, GX_NULL, \n"
179                    "                                               info->style, info->widget_id, &info->size);\n";
180         }
181         else
182         {
183             out += "    status = gx_string_scroll_wheel_create(wheel, info->widget_name, parent, props->total_rows, GX_NULL, \n"
184                    "                                    info->style, info->widget_id, &info->size);\n";
185         }
186         out += "    if (status == GX_SUCCESS)\n"
187                "    {\n"
188                "        if(props->string_id_list)\n"
189                "        {\n"
190                "            gx_string_scroll_wheel_string_id_list_set(wheel, props->string_id_list, props->total_rows);\n"
191                "        }\n";
192     }
193     else
194     {
195         out += "    status = gx_string_scroll_wheel_create(wheel, info->widget_name, parent, props->total_rows, props->string_list, \n"
196                "                                    info->style, info->widget_id, &info->size);\n"
197                "    if (status == GX_SUCCESS)\n"
198                "    {\n";
199     }
200 
201     out +=     "        if (props->wallpaper_id)\n"
202                "        {\n"
203                "            gx_window_wallpaper_set((GX_WINDOW *) wheel, props->wallpaper_id, info->style & GX_STYLE_TILE_WALLPAPER);\n"
204                "        }\n"
205                "        if(props->selected_background)\n"
206                "        {\n"
207                "            gx_scroll_wheel_selected_background_set((GX_SCROLL_WHEEL *)wheel, props->selected_background);\n"
208                "        }\n"
209                "        gx_scroll_wheel_selected_set((GX_SCROLL_WHEEL *)wheel, props->selected_row);\n"
210                "        gx_scroll_wheel_gradient_alpha_set((GX_SCROLL_WHEEL *)wheel, props->start_alpha, props->end_alpha);\n"
211                "        gx_scroll_wheel_row_height_set((GX_SCROLL_WHEEL *)wheel, props->row_height);\n"
212                "        gx_text_scroll_wheel_font_set((GX_TEXT_SCROLL_WHEEL *)wheel, props->normal_font, props->selected_font);\n";
213 
214     if (project_lib_version() > 50401)
215     {
216         out += "#if defined(GUIX_5_4_0_COMPATIBILITY)\n"
217                "        gx_text_scroll_wheel_text_color_set((GX_TEXT_SCROLL_WHEEL *)wheel, props->normal_text_color, props->selected_text_color);\n"
218                "#else\n"
219                "        gx_text_scroll_wheel_text_color_set((GX_TEXT_SCROLL_WHEEL *)wheel, props->normal_text_color, props->selected_text_color, props->disabled_text_color);\n"
220                "#endif\n";
221     }
222     else
223     {
224         out += "        gx_text_scroll_wheel_text_color_set((GX_TEXT_SCROLL_WHEEL *)wheel, props->normal_text_color, props->selected_text_color);\n";
225     }
226 
227     out +=     "        if(props->callback)\n"
228                "        {\n";
229     if (project_lib_version() >= GX_VERSION_STRING_LENGTH_FIX)
230     {
231         out += "            gx_text_scroll_wheel_callback_set_ext((GX_TEXT_SCROLL_WHEEL *)wheel, (UINT (*)(GX_TEXT_SCROLL_WHEEL*, INT, GX_STRING *))props->callback);\n";
232     }
233     else
234     {
235         out += "            gx_text_scroll_wheel_callback_set((GX_TEXT_SCROLL_WHEEL *)wheel, (GX_CONST GX_CHAR *(*)(GX_TEXT_SCROLL_WHEEL*, INT))props->callback);\n";
236     }
237 
238     out +=     "        }\n"
239                "    }\n"
240                "    return status;\n"
241                "}\n";
242 
243     return out;
244 }
245 
246 ///////////////////////////////////////////////////////////////////////////////
CreateNewInstance(GX_WIDGET * parent)247 widget_info *string_scroll_wheel_service_provider::CreateNewInstance(GX_WIDGET *parent)
248 {
249     int parent_size;
250 
251     GX_RECTANGLE size = parent->gx_widget_size;
252     gx_utility_rectangle_define(&size, 0, 0, 79, 23);
253     parent_size = (parent->gx_widget_size.gx_rectangle_right -
254         parent->gx_widget_size.gx_rectangle_left) / 4;
255     size.gx_rectangle_right = size.gx_rectangle_left + parent_size;
256 
257     parent_size = (parent->gx_widget_size.gx_rectangle_bottom -
258         parent->gx_widget_size.gx_rectangle_top) / 2;
259     size.gx_rectangle_bottom = size.gx_rectangle_top + parent_size;
260 
261     gx_utility_rectangle_center(&size, &parent->gx_widget_size);
262 
263     GX_STRING_SCROLL_WHEEL *wheel = new GX_STRING_SCROLL_WHEEL;
264     gx_string_scroll_wheel_create_ext(wheel, "string_scroll_wheel", parent, 0, GX_NULL,
265         GX_STYLE_ENABLED | GX_STYLE_BORDER_THIN | GX_STYLE_TEXT_CENTER, 0, &size);
266 
267     gx_widget_style_remove((GX_WIDGET *)wheel, GX_STYLE_DRAW_SELECTED);
268 
269     widget_info *info = InitWidgetInfo((GX_WIDGET *)wheel);
270     info->pixelmap_id[WALLPAPER_PIXELMAP_INDEX] = 0;
271     info->ewi.string_scroll_wheel.base.start_alpha = wheel->gx_scroll_wheel_gradient.gx_gradient_alpha_start;
272     info->ewi.string_scroll_wheel.base.end_alpha = wheel->gx_scroll_wheel_gradient.gx_gradient_alpha_end;
273     info->ewi.string_scroll_wheel.base.row_height = wheel->gx_scroll_wheel_row_height;
274     info->ewi.string_scroll_wheel.base.selected_row = wheel->gx_scroll_wheel_selected_row;
275     info->ewi.string_scroll_wheel.base.total_rows = 0;
276     info->ewi.string_scroll_wheel.string_id_list = GX_NULL;
277     info->color_id[NORMAL_TEXT_COLOR_INDEX] = wheel->gx_text_scroll_wheel_normal_text_color;
278     info->color_id[SELECTED_TEXT_COLOR_INDEX] = wheel->gx_text_scroll_wheel_selected_text_color;
279     info->color_id[DISABLED_TEXT_COLOR_INDEX] = wheel->gx_text_scroll_wheel_disabled_text_color;
280     info->font_id[NORMAL_FONT_INDEX] = wheel->gx_text_scroll_wheel_normal_font;
281     info->font_id[SELECTED_FONT_INDEX] = wheel->gx_text_scroll_wheel_selected_font;
282 
283     return info;
284 }
285 
286 ///////////////////////////////////////////////////////////////////////////////
GenerateFromInfo(GX_WIDGET * parent,widget_info * info)287 GX_WIDGET *string_scroll_wheel_service_provider::GenerateFromInfo(GX_WIDGET *parent, widget_info *info)
288 {
289     GX_STRING_SCROLL_WHEEL *wheel = new GX_STRING_SCROLL_WHEEL;
290 
291     // Create scroll wheel widget.
292     gx_string_scroll_wheel_create_ext(wheel,
293         (CHAR *)info->app_name.GetString(),
294         parent,
295         info->ewi.string_scroll_wheel.base.total_rows,
296         GX_NULL,
297         info->style,
298         0,
299         &info->size);
300 
301     wheel->gx_string_scroll_wheel_string_id_list = info->ewi.string_scroll_wheel.string_id_list;
302 
303     // Set fill color.
304     gx_widget_fill_color_set(wheel,
305         info->color_id[NORMAL_FILL_COLOR_INDEX],
306         info->color_id[SELECTED_FILL_COLOR_INDEX],
307         info->color_id[DISABLED_FILL_COLOR_INDEX]);
308 
309     // Set wallpaper.
310     if (info->pixelmap_id[WALLPAPER_PIXELMAP_INDEX] > 0)
311     {
312         BOOL tile = FALSE;
313 
314         if (info->style & GX_STYLE_TILE_WALLPAPER)
315         {
316             tile = TRUE;
317         }
318         gx_window_wallpaper_set((GX_WINDOW *)wheel, info->pixelmap_id[WALLPAPER_PIXELMAP_INDEX], tile);
319     }
320 
321     // Set selected row background.
322     if (info->pixelmap_id[SCROLL_WHEEL_PIXELMAP_INDEX] > 0)
323     {
324         gx_scroll_wheel_selected_background_set((GX_SCROLL_WHEEL *)wheel, info->pixelmap_id[SCROLL_WHEEL_PIXELMAP_INDEX]);
325     }
326 
327     // Set scroll wheel properties.
328     gx_text_scroll_wheel_font_set(wheel, info->font_id[0], info->font_id[1]);
329     gx_text_scroll_wheel_text_color_set(wheel, info->color_id[NORMAL_TEXT_COLOR_INDEX],
330         info->color_id[SELECTED_TEXT_COLOR_INDEX], info->color_id[DISABLED_TEXT_COLOR_INDEX]);
331     gx_scroll_wheel_gradient_alpha_set(wheel, info->ewi.string_scroll_wheel.base.start_alpha, info->ewi.string_scroll_wheel.base.end_alpha);
332     gx_scroll_wheel_row_height_set(wheel, info->ewi.string_scroll_wheel.base.row_height);
333     gx_scroll_wheel_selected_set(wheel, info->ewi.string_scroll_wheel.base.selected_row);
334 
335     return (GX_WIDGET *)wheel;
336 }
337 
338 ///////////////////////////////////////////////////////////////////////////////
SaveToProject(xml_writer & writer,studiox_project * project,int display,widget_info * info)339 void string_scroll_wheel_service_provider::SaveToProject(xml_writer &writer, studiox_project *project, int display, widget_info *info)
340 {
341     text_scroll_wheel_service_provider::SaveToProject(writer, project, display, info);
342 
343     if (info->ewi.string_scroll_wheel.string_id_list)
344     {
345         writer.OpenTag("string_list");
346         CString id_name;
347         string_table *table = project->mDisplays[display].stable;
348 
349         //generate string id list
350         for (int index = 0; index < info->ewi.string_scroll_wheel.base.total_rows; index++)
351         {
352             id_name = table->GetResourceIdName(info->ewi.string_scroll_wheel.string_id_list[index]);
353             writer.WriteString("string_id", id_name, TRUE);
354         }
355 
356         writer.CloseTag("string_list");
357     }
358 }
359 
360 ///////////////////////////////////////////////////////////////////////////////
ReadFromProject(xml_reader & reader,studiox_project * project,int display,widget_info * info,ULONG valid_styles)361 void string_scroll_wheel_service_provider::ReadFromProject(xml_reader &reader, studiox_project *project, int display, widget_info *info, ULONG valid_styles)
362 {
363     text_scroll_wheel_service_provider::ReadFromProject(reader, project, display, info, valid_styles);
364 
365     if (reader.EnterSection("string_list"))
366     {
367         CString text;
368         CArray<GX_RESOURCE_ID> string_list;
369         string_table *table = project->mDisplays[display].stable;
370         CString id_name;
371         int res_id;
372         int index;
373 
374         if (!table)
375         {
376             table = new string_table;
377             table->Initialize(1, 1);
378             project->mDisplays[display].stable = table;
379         }
380 
381         if (project->mHeader.project_version < 54)
382         {
383             //read plain string and add it to string table
384             for (index = 0; index < info->ewi.string_scroll_wheel.base.total_rows; index++)
385             {
386                 reader.ReadString("val", text);
387                 res_id = table->CheckAddString(text);
388                 id_name = table->GetStringId(res_id);
389                 res_id = table->GetResourceId(id_name);
390                 string_list.Add(res_id);
391             }
392 
393             table->Sort();
394         }
395         else
396         {
397             //read string id name
398             for (index = 0; index < info->ewi.string_scroll_wheel.base.total_rows; index++)
399             {
400                 reader.ReadString("string_id", id_name);
401                 res_id = table->GetResourceId(id_name);
402                 string_list.Add(res_id);
403             }
404         }
405 
406         if (info->ewi.string_scroll_wheel.base.total_rows)
407         {
408             CreateStringIdList(info, string_list);
409         }
410 
411         reader.CloseSection(TRUE, TRUE);
412     }
413 }
414 
415 ///////////////////////////////////////////////////////////////////////////////
StringEditEnableDisable(widget_info * info,BOOL enabled)416 void string_scroll_wheel_service_provider::StringEditEnableDisable(widget_info *info, BOOL enabled)
417 {
418     GX_STRING_SCROLL_WHEEL *wheel = (GX_STRING_SCROLL_WHEEL *) (info->widget);
419 
420     if ((!enabled) && info->ewi.string_scroll_wheel.string_id_list)
421     {
422         delete info->ewi.string_scroll_wheel.string_id_list;
423         info->ewi.string_scroll_wheel.string_id_list = NULL;
424 
425         if (wheel)
426         {
427             wheel->gx_string_scroll_wheel_string_list = GX_NULL;
428             gx_system_dirty_mark((GX_WIDGET *)wheel);
429         }
430     }
431 }
432 
433 ///////////////////////////////////////////////////////////////////////////////
AssignScrollWheelInfo(widget_info * info,scroll_wheel_info * wheel_info)434 void string_scroll_wheel_service_provider::AssignScrollWheelInfo(widget_info *info, scroll_wheel_info *wheel_info)
435 {
436     if ((info->ewi.string_scroll_wheel.base.total_rows != wheel_info->total_rows) &&
437         (info->callback_func.IsEmpty()))
438     {
439         CArray<GX_RESOURCE_ID> list_array;
440 
441         // init list array with old string list
442         InitStringIdListArray(info->ewi.string_scroll_wheel.string_id_list, info->ewi.string_scroll_wheel.base.total_rows, list_array);
443 
444         // delete old string list
445         delete info->ewi.string_scroll_wheel.string_id_list;
446         info->ewi.string_scroll_wheel.string_id_list = NULL;
447 
448         scroll_wheel_service_provider::AssignScrollWheelInfo(info, wheel_info);
449 
450         // create new string list
451         CreateStringIdList(info, list_array);
452     }
453     else
454     {
455         scroll_wheel_service_provider::AssignScrollWheelInfo(info, wheel_info);
456     }
457 }
458 
459 ///////////////////////////////////////////////////////////////////////////////
InitStringIdListArray(GX_RESOURCE_ID * string_list,int total_rows,CArray<GX_RESOURCE_ID> & list_array)460 void string_scroll_wheel_service_provider::InitStringIdListArray(GX_RESOURCE_ID *string_list, int total_rows, CArray<GX_RESOURCE_ID> &list_array)
461 {
462     int index;
463     CString string;
464 
465     for (index = 0; index < total_rows; index++)
466     {
467         if (string_list && string_list[index])
468         {
469             list_array.Add(string_list[index]);
470         }
471         else
472         {
473             list_array.Add(0);
474         }
475     }
476 }
477 
478 ///////////////////////////////////////////////////////////////////////////////
CreateStringIdList(widget_info * info,CArray<GX_RESOURCE_ID> & list_array)479 void string_scroll_wheel_service_provider::CreateStringIdList(widget_info *info, CArray<GX_RESOURCE_ID> &list_array)
480 {
481     int index;
482     int total_rows;
483     string_scroll_wheel_info *wheel_info = &info->ewi.string_scroll_wheel;
484 
485     if (wheel_info->string_id_list)
486     {
487         return;
488     }
489 
490     // create new value list
491     total_rows = wheel_info->base.total_rows;
492     if (total_rows)
493     {
494         wheel_info->string_id_list = new GX_RESOURCE_ID[total_rows];
495         memset(wheel_info->string_id_list, 0, sizeof(GX_RESOURCE_ID)*total_rows);
496 
497         if (total_rows > list_array.GetCount())
498         {
499             total_rows = list_array.GetCount();
500         }
501 
502         for (index = 0; index < total_rows; index++)
503         {
504             wheel_info->string_id_list[index] = list_array.GetAt(index);
505         }
506     }
507 
508     if (info->widget)
509     {
510         GX_STRING_SCROLL_WHEEL *wheel = (GX_STRING_SCROLL_WHEEL *)info->widget;
511         wheel->gx_string_scroll_wheel_string_id_list = (const GX_RESOURCE_ID *)wheel_info->string_id_list;
512         gx_system_dirty_mark(info->widget);
513 
514         if (wheel_info->base.selected_row > wheel_info->base.total_rows)
515         {
516             wheel_info->base.selected_row = wheel_info->base.total_rows;
517             GetPropsWin()->ResourcesChanged();
518         }
519     }
520 }
521 
522 ///////////////////////////////////////////////////////////////////////////////
AssignText(widget_info * info,int index,GX_RESOURCE_ID string_id)523 void string_scroll_wheel_service_provider::AssignText(widget_info *info, int index, GX_RESOURCE_ID string_id)
524 {
525     if (index < info->ewi.string_scroll_wheel.base.total_rows)
526     {
527         info->ewi.string_scroll_wheel.string_id_list[index] = string_id;
528     }
529 
530     if (info->widget)
531     {
532         gx_system_dirty_mark(info->widget);
533     }
534 }
535 
536 ///////////////////////////////////////////////////////////////////////////////
Autosize(widget_info * info)537 void string_scroll_wheel_service_provider::Autosize(widget_info *info)
538 {
539     CheckResizeToText(info, RESIZE_MODE_WIDTH);
540 
541     window_service_provider::Autosize(info);
542 }
543 
544