1
2 #include "studiox_includes.h"
3
4 #ifdef _DEBUG
5 #define new DEBUG_NEW
6 #endif
7
text_input_service_provider()8 text_input_service_provider::text_input_service_provider()
9 {
10 }
11
GetVarDeclaration()12 CString text_input_service_provider::GetVarDeclaration()
13 {
14 return CString("GX_SINGLE_LINE_TEXT_INPUT_MEMBERS_DECLARE");
15 }
16
DeclarePropertiesStruct()17 CString text_input_service_provider::DeclarePropertiesStruct()
18 {
19 CString out;
20
21 if (project_lib_version() > 50401)
22 {
23 out = (""
24 "typedef struct\n"
25 "{\n"
26 " GX_RESOURCE_ID string_id;\n"
27 " GX_RESOURCE_ID font_id;\n"
28 " GX_RESOURCE_ID normal_text_color_id;\n"
29 " GX_RESOURCE_ID selected_text_color_id;\n"
30 " GX_RESOURCE_ID disabled_text_color_id;\n"
31 " GX_RESOURCE_ID readonly_fill_color_id;\n"
32 " GX_RESOURCE_ID readonly_text_color_id;\n"
33 " GX_CHAR *buffer;\n"
34 " UINT buffer_size;\n"
35 "} GX_SINGLE_LINE_TEXT_INPUT_PROPERTIES;\n\n");
36 }
37 else
38 {
39 out = (""
40 "typedef struct\n"
41 "{\n"
42 " GX_RESOURCE_ID string_id;\n"
43 " GX_RESOURCE_ID font_id;\n"
44 " GX_RESOURCE_ID normal_text_color_id;\n"
45 " GX_RESOURCE_ID selected_text_color_id;\n"
46 " GX_CHAR *buffer;\n"
47 " UINT buffer_size;\n"
48 "} GX_SINGLE_LINE_TEXT_INPUT_PROPERTIES;\n\n");
49 }
50 return out;
51 }
52
WriteExtendedProperties(screen_generator * gen,CString & prefix,widget_info * info)53 CString text_input_service_provider::WriteExtendedProperties(screen_generator *gen, CString &prefix, widget_info *info)
54 {
55 CString out;
56 CString props;
57 CString propname = prefix + info->app_name;
58 CString buffer;
59
60 if (!info->ewi.text_info.dynamic_buffer)
61 {
62 buffer.Format(_T("%s_buffer"), propname);
63 out.Format(_T("GX_CHAR %s_buffer[%d];\n"),
64 propname, info->ewi.text_info.buffer_size);
65 }
66 else
67 {
68 buffer = "GX_NULL";
69 out = "";
70 }
71
72 if (project_lib_version() > 50401)
73 {
74 props.Format(_T("GX_SINGLE_LINE_TEXT_INPUT_PROPERTIES %s_properties =\n")
75 _T("{\n")
76 _T(" %s, /* string id */\n")
77 _T(" %s, /* font id */\n")
78 _T(" %s, /* normal text color */\n")
79 _T(" %s, /* selected text color */\n")
80 _T(" %s, /* disabled text color */\n")
81 _T(" %s, /* readonly fill color */\n")
82 _T(" %s, /* readonly text color */\n")
83 _T(" %s, /* buffer */\n")
84 _T(" %d, /* buffer size */\n};\n"),
85 propname,
86 gen->GetStringIdName(info->string_id[0]),
87 gen->GetFontIdName(info->font_id[0]),
88 gen->GetColorIdName(info->color_id[NORMAL_TEXT_COLOR_INDEX]),
89 gen->GetColorIdName(info->color_id[SELECTED_TEXT_COLOR_INDEX]),
90 gen->GetColorIdName(info->color_id[DISABLED_TEXT_COLOR_INDEX]),
91 gen->GetColorIdName(info->color_id[READONLY_FILL_COLOR_INDEX]),
92 gen->GetColorIdName(info->color_id[READONLY_TEXT_COLOR_INDEX]),
93 buffer,
94 info->ewi.text_info.buffer_size);
95 }
96 else
97 {
98 props.Format(_T("GX_SINGLE_LINE_TEXT_INPUT_PROPERTIES %s_properties =\n")
99 _T("{\n")
100 _T(" %s, /* string id */\n")
101 _T(" %s, /* font id */\n")
102 _T(" %s, /* normal text color */\n")
103 _T(" %s, /* selected text color */\n")
104 _T(" %s, /* buffer */\n")
105 _T(" %d, /* buffer size */\n};\n"),
106 propname,
107 gen->GetStringIdName(info->string_id[0]),
108 gen->GetFontIdName(info->font_id[0]),
109 gen->GetColorIdName(info->color_id[NORMAL_TEXT_COLOR_INDEX]),
110 gen->GetColorIdName(info->color_id[SELECTED_TEXT_COLOR_INDEX]),
111 buffer,
112 info->ewi.text_info.buffer_size);
113 }
114 out += props;
115 return out;
116 }
117
GetCreateFromDefFunctionName()118 CString text_input_service_provider::GetCreateFromDefFunctionName()
119 {
120 return CString("gx_studio_text_input_create");
121 }
122
123 #if 0
124 UINT _gx_single_line_text_input_create(GX_SINGLE_LINE_TEXT_INPUT *text_input_ptr,
125 CHAR *name,
126 GX_WIDGET *parent,
127 CHAR *input_buffer,
128 UINT buffer_size,
129 UINT style,
130 USHORT text_input_id,
131 GX_RECTANGLE *size)
132 #endif
133
134
GetCreateFromDefFunction(int version)135 CString text_input_service_provider::GetCreateFromDefFunction(int version)
136 {
137 CString out;
138 MakeCreatePreamble("text_input", version, out);
139 studiox_project* project = GetOpenProject();
140
141 if (!project)
142 {
143 return out;
144 }
145
146 if (project_lib_version() >= GX_VERSION_STRING_LENGTH_FIX)
147 {
148 CString string;
149 string.Format(_T("{\n")
150 _T(" UINT status;\n")
151 _T(" GX_STRING text;\n")
152 _T(" GX_SINGLE_LINE_TEXT_INPUT *input = (GX_SINGLE_LINE_TEXT_INPUT *) control_block;\n")
153 _T(" GX_PROMPT *prompt = (GX_PROMPT *) input;\n")
154 _T(" GX_SINGLE_LINE_TEXT_INPUT_PROPERTIES *props = (GX_SINGLE_LINE_TEXT_INPUT_PROPERTIES *) info->properties;\n")
155 _T(" status = gx_single_line_text_input_create(input, info->widget_name, parent, props->buffer, props->buffer_size, info->style, info->widget_id, &info->size);\n")
156 _T(" if (status == GX_SUCCESS)\n")
157 _T(" {\n")
158 _T(" gx_prompt_font_set(prompt, props->font_id);\n")
159 _T(" gx_single_line_text_input_text_color_set(input, props->normal_text_color_id, props->selected_text_color_id,\n")
160 _T(" props->disabled_text_color_id, props->readonly_text_color_id);\n")
161 _T(" gx_single_line_text_input_fill_color_set(input, input->gx_widget_normal_fill_color, input->gx_widget_selected_fill_color,\n")
162 _T(" input->gx_widget_disabled_fill_color, props->readonly_fill_color_id);\n")
163 _T(" if (props->buffer && props->buffer_size > 0 && props->string_id)\n")
164 _T(" {\n")
165 _T(" gx_display_string_get_ext(%s_display_table[0].display, props->string_id, &text);\n")// FIXME: string set issue
166 _T("\n")
167 _T(" if (text.gx_string_ptr)\n")
168 _T(" {\n")
169 _T(" gx_single_line_text_input_text_set_ext(input, &text);\n")
170 _T(" }\n")
171 _T(" }\n")
172 _T(" }\n")
173 _T(" return status;\n")
174 _T("}\n"),
175 project->mHeader.project_name);
176
177 out += string;
178 }
179 else if (project_lib_version() > 50401)
180 {
181 out += "{\n"
182 " UINT status;\n"
183 " GX_CONST GX_CHAR *text;\n"
184 " GX_SINGLE_LINE_TEXT_INPUT *input = (GX_SINGLE_LINE_TEXT_INPUT *) control_block;\n"
185 " GX_PROMPT *prompt = (GX_PROMPT *) input;\n"
186 " GX_SINGLE_LINE_TEXT_INPUT_PROPERTIES *props = (GX_SINGLE_LINE_TEXT_INPUT_PROPERTIES *) info->properties;\n"
187 " status = gx_single_line_text_input_create(input, info->widget_name, parent, props->buffer, props->buffer_size, info->style, info->widget_id, &info->size);\n"
188 " if (status == GX_SUCCESS)\n"
189 " {\n"
190 " gx_prompt_font_set(prompt, props->font_id);\n"
191 " gx_single_line_text_input_text_color_set(input, props->normal_text_color_id, props->selected_text_color_id,\n"
192 " props->disabled_text_color_id, props->readonly_text_color_id);\n"
193 " gx_single_line_text_input_fill_color_set(input, input->gx_widget_normal_fill_color, input->gx_widget_selected_fill_color,\n"
194 " input->gx_widget_disabled_fill_color, props->readonly_fill_color_id);\n"
195 " if (props->buffer && props->buffer_size > 0 && props->string_id)\n"
196 " {\n"
197 " gx_system_string_get(props->string_id, &text);\n"
198 "\n"
199 " if (text)\n"
200 " {\n"
201 " gx_single_line_text_input_text_set(input, text);\n"
202 " }\n"
203 " }\n"
204 " }\n"
205 " return status;\n"
206 "}\n";
207 }
208 else
209 {
210 out += "{\n"
211 " UINT status;\n"
212 " GX_SINGLE_LINE_TEXT_INPUT *input = (GX_SINGLE_LINE_TEXT_INPUT *) control_block;\n"
213 " GX_PROMPT *prompt = (GX_PROMPT *) input;\n"
214 " GX_SINGLE_LINE_TEXT_INPUT_PROPERTIES *props = (GX_SINGLE_LINE_TEXT_INPUT_PROPERTIES *) info->properties;\n"
215 " status = gx_single_line_text_input_create(input, info->widget_name, parent, props->buffer, props->buffer_size, info->style, info->widget_id, &info->size);\n"
216 " if (status == GX_SUCCESS)\n"
217 " {\n"
218 " gx_prompt_font_set(prompt, props->font_id);\n"
219 " gx_prompt_text_color_set(prompt, props->normal_text_color_id, props->selected_text_color_id);\n"
220 " }\n"
221 " return status;\n"
222 "}\n";
223 }
224 return out;
225 }
226
CreateNewInstance(GX_WIDGET * parent)227 widget_info *text_input_service_provider::CreateNewInstance(GX_WIDGET *parent)
228 {
229 GX_RECTANGLE size;
230 gx_utility_rectangle_define(&size, 0, 0, 79, 23);
231 gx_utility_rectangle_center(&size, &parent->gx_widget_size);
232
233 GX_SINGLE_LINE_TEXT_INPUT *input = new GX_SINGLE_LINE_TEXT_INPUT;
234 GX_CHAR *buffer = new GX_CHAR[100];
235 memset(buffer, 0, 100);
236
237 gx_single_line_text_input_create(input, "text_input", parent, buffer, 100,
238 GX_STYLE_ENABLED|GX_STYLE_BORDER_THIN|GX_STYLE_TEXT_LEFT, 0, &size);
239 widget_info *info = InitWidgetInfo((GX_WIDGET *) input);
240
241 info->string_id[0] = 0;
242 info->font_id[0] = input->gx_prompt_font_id;
243 info->ewi.text_info.buffer_size = 100;
244 info->ewi.text_info.dynamic_buffer = false;
245 info->callback_func = GetMallocName();
246 info->color_id[NORMAL_TEXT_COLOR_INDEX] = input->gx_prompt_normal_text_color;
247 info->color_id[SELECTED_TEXT_COLOR_INDEX] = input->gx_prompt_selected_text_color;
248 info->color_id[DISABLED_TEXT_COLOR_INDEX] = input->gx_prompt_disabled_text_color;
249 info->color_id[READONLY_FILL_COLOR_INDEX] = input->gx_single_line_text_input_readonly_fill_color;
250 info->color_id[READONLY_TEXT_COLOR_INDEX] = input->gx_single_line_text_input_readonly_text_color;
251 return info;
252 }
253
GenerateFromInfo(GX_WIDGET * parent,widget_info * info)254 GX_WIDGET *text_input_service_provider::GenerateFromInfo(GX_WIDGET *parent, widget_info *info)
255 {
256 GX_SINGLE_LINE_TEXT_INPUT *input = new GX_SINGLE_LINE_TEXT_INPUT;
257
258 GX_CHAR *text = NULL;
259
260 if (info->ewi.text_info.buffer_size > 1)
261 {
262 text = new GX_CHAR[info->ewi.text_info.buffer_size + 1];
263 }
264
265 if (text && info->string_id[0])
266 {
267 GetStringText((char*)text, info->ewi.text_info.buffer_size, info);
268 }
269 else
270 {
271 text[0] = '\0';
272 }
273
274 gx_single_line_text_input_create(input,
275 (CHAR*)info->app_name.GetString(),
276 parent,
277 text, info->ewi.text_info.buffer_size,
278 info->style, 0,
279 &info->size);
280
281 gx_single_line_text_input_fill_color_set(input,
282 info->color_id[NORMAL_FILL_COLOR_INDEX], info->color_id[SELECTED_FILL_COLOR_INDEX],
283 info->color_id[DISABLED_FILL_COLOR_INDEX], info->color_id[READONLY_FILL_COLOR_INDEX]);
284 gx_single_line_text_input_text_color_set(input,
285 info->color_id[NORMAL_TEXT_COLOR_INDEX], info->color_id[SELECTED_TEXT_COLOR_INDEX],
286 info->color_id[DISABLED_TEXT_COLOR_INDEX], info->color_id[READONLY_TEXT_COLOR_INDEX]);
287 gx_prompt_font_set((GX_PROMPT *) input, info->font_id[0]);
288
289 return ((GX_WIDGET *) input);
290 }
291
SaveToProject(xml_writer & writer,studiox_project * project,int display,widget_info * info)292 void text_input_service_provider::SaveToProject(xml_writer &writer, studiox_project *project, int display, widget_info *info)
293 {
294 widget_service_provider::SaveToProject(writer, project, display, info);
295 WriteStringId(writer, project, display, "string_id", info->string_id[0]);
296 WriteFontId(writer, project, display, "font_id", info->font_id[0]);
297 WriteColorId(writer, project, display, "normal_text_color", info->color_id[NORMAL_TEXT_COLOR_INDEX]);
298 WriteColorId(writer, project, display, "selected_text_color", info->color_id[SELECTED_TEXT_COLOR_INDEX]);
299 WriteColorId(writer, project, display, "disabled_text_color", info->color_id[DISABLED_TEXT_COLOR_INDEX]);
300 WriteColorId(writer, project, display, "readonly_fill_color", info->color_id[READONLY_FILL_COLOR_INDEX]);
301 WriteColorId(writer, project, display, "readonly_text_color", info->color_id[READONLY_TEXT_COLOR_INDEX]);
302 writer.WriteString("buffer_allocator", info->callback_func);
303 writer.WriteInt("buffer_size", info->ewi.text_info.buffer_size);
304 writer.WriteBool("dynamic_buffer", info->ewi.text_info.dynamic_buffer);
305 }
306
ReadFromProject(xml_reader & reader,studiox_project * project,int display,widget_info * info,ULONG valid_styles)307 void text_input_service_provider::ReadFromProject(xml_reader &reader, studiox_project *project, int display, widget_info *info, ULONG valid_styles)
308 {
309 valid_styles |= GX_STYLE_TEXT_ALIGNMENT_MASK|GX_STYLE_CURSOR_BLINK|GX_STYLE_CURSOR_ALWAYS|GX_STYLE_TEXT_INPUT_NOTIFY_ALL|GX_STYLE_TEXT_INPUT_READONLY;
310 widget_service_provider::ReadFromProject(reader, project, display, info, valid_styles);
311 info->string_id[0] = ReadStringId(reader, project, display, "string_id");
312 if (info->string_id[0] < 0 || info->string_id[0] > 100000)
313 {
314 info->string_id[0] = 0;
315 }
316 info->font_id[0] = ReadFontId(reader, project, display, "font_id");
317 info->color_id[NORMAL_TEXT_COLOR_INDEX] = ReadColorId(reader, project, display, "normal_text_color");
318 info->color_id[SELECTED_TEXT_COLOR_INDEX] = ReadColorId(reader, project, display, "selected_text_color");
319
320 if (project->mHeader.project_version > 54)
321 {
322 info->color_id[DISABLED_TEXT_COLOR_INDEX] = ReadColorId(reader, project, display, "disabled_text_color");
323 info->color_id[READONLY_FILL_COLOR_INDEX] = ReadColorId(reader, project, display, "readonly_fill_color");
324 info->color_id[READONLY_TEXT_COLOR_INDEX] = ReadColorId(reader, project, display, "readonly_text_color");
325 }
326 else
327 {
328 info->color_id[DISABLED_TEXT_COLOR_INDEX] = info->color_id[NORMAL_TEXT_COLOR_INDEX];
329 info->color_id[READONLY_FILL_COLOR_INDEX] = GX_COLOR_ID_READONLY_FILL;
330 info->color_id[READONLY_TEXT_COLOR_INDEX] = GX_COLOR_ID_READONLY_TEXT;
331 }
332 reader.ReadString("buffer_allocator", info->callback_func);
333 reader.ReadInt("buffer_size", info->ewi.text_info.buffer_size, 100);
334 reader.ReadBool("dynamic_buffer", info->ewi.text_info.dynamic_buffer);
335 }
336
AssignText(widget_info * info,int index,GX_RESOURCE_ID string_id)337 void text_input_service_provider::AssignText(widget_info *info, int index,
338 GX_RESOURCE_ID string_id)
339 {
340 info->string_id[0] = string_id;
341 GX_WIDGET *widget = info->widget;
342
343 if (widget)
344 {
345 GX_SINGLE_LINE_TEXT_INPUT *input = (GX_SINGLE_LINE_TEXT_INPUT *)widget;
346
347 if (input->gx_single_line_text_input_buffer &&
348 info->ewi.text_info.buffer_size > 1)
349 {
350 CHAR *text = new CHAR[info->ewi.text_info.buffer_size];
351 GetStringText(text, info->ewi.text_info.buffer_size, info);
352 gx_single_line_text_input_buffer_clear(input);
353 gx_single_line_text_input_character_insert(input, (GX_UBYTE *)text, strlen(text));
354 delete text;
355 }
356 gx_system_dirty_mark(widget);
357 }
358 }
359
AssignColor(widget_info * info,int index,GX_RESOURCE_ID color_id)360 void text_input_service_provider::AssignColor(widget_info *info, int index, GX_RESOURCE_ID color_id)
361 {
362 GX_SINGLE_LINE_TEXT_INPUT *input = (GX_SINGLE_LINE_TEXT_INPUT *) (info->widget);
363
364 switch (index)
365 {
366 case READONLY_FILL_COLOR_INDEX:
367 if (input)
368 {
369 gx_single_line_text_input_fill_color_set(input, input->gx_widget_normal_fill_color, input->gx_widget_selected_fill_color,
370 input->gx_prompt_disabled_text_color, color_id);
371 }
372 info->color_id[READONLY_FILL_COLOR_INDEX] = color_id;
373 break;
374
375 case READONLY_TEXT_COLOR_INDEX:
376 if (input)
377 {
378 gx_single_line_text_input_text_color_set(input, input->gx_prompt_normal_text_color,
379 input->gx_prompt_selected_text_color, input->gx_prompt_disabled_text_color, color_id);
380 }
381 info->color_id[READONLY_TEXT_COLOR_INDEX] = color_id;
382 break;
383
384 default:
385 prompt_service_provider::AssignColor(info, index, color_id);
386 }
387 }
388
Autosize(widget_info * info)389 void text_input_service_provider::Autosize(widget_info *info)
390 {
391 CheckResizeToText(info, RESIZE_MODE_HEIGHT);
392 }
393