1
2 #include "studiox_includes.h"
3
4 #ifdef _DEBUG
5 #define new DEBUG_NEW
6 #endif
7
numeric_prompt_service_provider()8 numeric_prompt_service_provider::numeric_prompt_service_provider()
9 {
10 }
11
GetVarDeclaration()12 CString numeric_prompt_service_provider::GetVarDeclaration()
13 {
14 return CString("GX_NUMERIC_PROMPT_MEMBERS_DECLARE");
15 }
16
DeclarePropertiesStruct()17 CString numeric_prompt_service_provider::DeclarePropertiesStruct()
18 {
19 CString out;
20
21 out.Format(_T("")
22 _T("typedef struct\n")
23 _T("{\n")
24 _T("%s\n")
25 _T(" VOID (*format_func)(GX_NUMERIC_PROMPT *, INT);\n")
26 _T(" INT numeric_prompt_value;\n")
27 _T("} GX_NUMERIC_PROMPT_PROPERTIES;\n\n"),
28 prompt_service_provider::DeclarePropertiesStructContent());
29 return out;
30 }
31
WriteExtendedProperties(screen_generator * gen,CString & prefix,widget_info * info)32 CString numeric_prompt_service_provider::WriteExtendedProperties(screen_generator *gen, CString &prefix, widget_info *info)
33 {
34 CString out;
35 CString propname = prefix + info->app_name;
36
37 CString format_func;
38
39 if (info->format_func.IsEmpty())
40 {
41 format_func = "GX_NULL";
42 }
43 else
44 {
45 format_func = info->format_func;
46 }
47
48
49 out.Format(_T("GX_NUMERIC_PROMPT_PROPERTIES %s_properties =\n")
50 _T("{\n")
51 _T("%s\n")
52 _T(" %s, /* format function */\n")
53 _T(" %d /* numeric prompt value */\n};\n"),
54 propname,
55 prompt_service_provider::WriteExtendedPropertiesContent(gen, info, TRUE),
56 format_func,
57 info->ewi.numeric_prompt_value);
58
59 return out;
60 }
61
GetCreateFromDefFunctionName()62 CString numeric_prompt_service_provider::GetCreateFromDefFunctionName()
63 {
64 return CString("gx_studio_numeric_prompt_create");
65 }
66
GetCreateFromDefFunction(int version)67 CString numeric_prompt_service_provider::GetCreateFromDefFunction(int version)
68 {
69 CString out;
70 MakeCreatePreamble("numeric_prompt", version, out);
71
72 out += "{\n"
73 " UINT status;\n"
74 " GX_NUMERIC_PROMPT *prompt = (GX_NUMERIC_PROMPT *) control_block;\n"
75 " GX_NUMERIC_PROMPT_PROPERTIES *props = (GX_NUMERIC_PROMPT_PROPERTIES *) info->properties;\n"
76 " status = gx_numeric_prompt_create(prompt, info->widget_name, parent, props->string_id, info->style, info->widget_id, &info->size);\n"
77 " if (status == GX_SUCCESS)\n"
78 " {\n"
79 " gx_prompt_font_set((GX_PROMPT *)prompt, props->font_id);\n";
80 if (version > 50401)
81 {
82 out += "#if defined(GUIX_5_4_0_COMPATIBILITY)\n"
83 " gx_prompt_text_color_set((GX_PROMPT *)prompt, props->normal_text_color_id, props->selected_text_color_id);\n"
84 "#else\n"
85 " gx_prompt_text_color_set((GX_PROMPT *)prompt, props->normal_text_color_id, props->selected_text_color_id, props->disabled_text_color_id);\n"
86 "#endif\n";
87 }
88 else
89 {
90 out += " gx_prompt_text_color_set((GX_PROMPT *)prompt, props->normal_text_color_id, props->selected_text_color_id);\n";
91 }
92 out += " if(!props->string_id)\n"
93 " {\n"
94 " gx_numeric_prompt_value_set(prompt, props->numeric_prompt_value);\n"
95 " }\n"
96 " if(props->format_func)\n"
97 " {\n"
98 " gx_numeric_prompt_format_function_set(prompt, props->format_func);\n"
99 " }\n"
100 " }\n"
101 " return status;\n"
102 "}\n";
103 return out;
104 }
105
CreateNewInstance(GX_WIDGET * parent)106 widget_info *numeric_prompt_service_provider::CreateNewInstance(GX_WIDGET *parent)
107 {
108 GX_RECTANGLE size;
109 gx_utility_rectangle_define(&size, 0, 0, 79, 23);
110 gx_utility_rectangle_center(&size, &parent->gx_widget_size);
111
112 GX_NUMERIC_PROMPT *prompt = new GX_NUMERIC_PROMPT;
113
114 gx_numeric_prompt_create(prompt, "prompt", parent, 0,
115 GX_STYLE_ENABLED | GX_STYLE_BORDER_THIN | GX_STYLE_TEXT_CENTER, 0, &size);
116
117 widget_info *info = InitWidgetInfo((GX_WIDGET *)prompt);
118
119 info->font_id[0] = prompt->gx_prompt_font_id;
120 info->color_id[NORMAL_TEXT_COLOR_INDEX] = prompt->gx_prompt_normal_text_color;
121 info->color_id[SELECTED_TEXT_COLOR_INDEX] = prompt->gx_prompt_selected_text_color;
122 info->color_id[DISABLED_TEXT_COLOR_INDEX] = prompt->gx_prompt_disabled_text_color;
123 info->string_id[0] = 0;
124 info->format_func = "";
125 info->ewi.numeric_prompt_value = 0;
126
127 /* Set prompt value to 0. */
128 gx_numeric_prompt_value_set(prompt, info->ewi.numeric_prompt_value);
129
130 return info;
131 }
132
GenerateFromInfo(GX_WIDGET * parent,widget_info * info)133 GX_WIDGET *numeric_prompt_service_provider::GenerateFromInfo(GX_WIDGET *parent, widget_info *info)
134 {
135 GX_NUMERIC_PROMPT *prompt = new GX_NUMERIC_PROMPT;
136
137 if (info->style & GX_STYLE_TEXT_COPY)
138 {
139 ErrorMsg("Numeric prompt has invalid style settings. Resetting to default.");
140 info->style &= ~GX_STYLE_TEXT_COPY;
141 }
142
143 gx_numeric_prompt_create(prompt,
144 (CHAR *)info->app_name.GetString(),
145 parent,
146 info->string_id[0], // this should be text id
147 info->style, 0,
148 &info->size);
149
150 if (!info->string_id[0])
151 {
152 gx_numeric_prompt_value_set(prompt, info->ewi.numeric_prompt_value);
153 }
154
155 gx_widget_fill_color_set((GX_PROMPT *)prompt,
156 info->color_id[NORMAL_FILL_COLOR_INDEX],
157 info->color_id[SELECTED_FILL_COLOR_INDEX],
158 info->color_id[DISABLED_FILL_COLOR_INDEX]);
159 gx_prompt_text_color_set((GX_PROMPT *)prompt,
160 info->color_id[NORMAL_TEXT_COLOR_INDEX],
161 info->color_id[SELECTED_TEXT_COLOR_INDEX],
162 info->color_id[DISABLED_TEXT_COLOR_INDEX]);
163 gx_prompt_font_set((GX_PROMPT *)prompt, info->font_id[0]);
164
165 return (GX_WIDGET*)prompt;
166 }
167
SaveToProject(xml_writer & writer,studiox_project * project,int display,widget_info * info)168 void numeric_prompt_service_provider::SaveToProject(xml_writer &writer, studiox_project *project, int display, widget_info *info)
169 {
170 prompt_service_provider::SaveToProject(writer, project, display, info);
171
172 writer.WriteString("format_func", info->format_func);
173
174 /* Write numeric prompt value. */
175 writer.WriteInt("numeric_prompt_value", info->ewi.numeric_prompt_value);
176 }
177
ReadFromProject(xml_reader & reader,studiox_project * project,int display,widget_info * info,ULONG valid_styles)178 void numeric_prompt_service_provider::ReadFromProject(xml_reader &reader, studiox_project *project, int display, widget_info *info, ULONG valid_styles)
179 {
180 prompt_service_provider::ReadFromProject(reader, project, display, info, valid_styles);
181
182 reader.ReadString("format_func", info->format_func);
183
184 /* Read prompt value. */
185 reader.ReadInt("numeric_prompt_value", info->ewi.numeric_prompt_value, 0);
186 }
187
AssignNumericValue(widget_info * info,INT value)188 void numeric_prompt_service_provider::AssignNumericValue(widget_info *info, INT value)
189 {
190 info->ewi.numeric_prompt_value = value;
191 info->string_id[0] = 0;
192
193 /* Set new numeric value. */
194 gx_numeric_prompt_value_set((GX_NUMERIC_PROMPT *)info->widget, value);
195 }