1 
2 #include "studiox_includes.h"
3 
4 #ifdef _DEBUG
5 #define new DEBUG_NEW
6 #endif
7 
prompt_service_provider()8 prompt_service_provider::prompt_service_provider()
9 {
10 }
11 
GetVarDeclaration()12 CString prompt_service_provider::GetVarDeclaration()
13 {
14     return CString("GX_PROMPT_MEMBERS_DECLARE");
15 }
16 
DeclarePropertiesStructContent()17 CString prompt_service_provider::DeclarePropertiesStructContent()
18 {
19     CString out;
20 
21     if (project_lib_version() > 50401)
22     {
23         out = ("    GX_RESOURCE_ID string_id;\n"
24             "    GX_RESOURCE_ID font_id;\n"
25             "    GX_RESOURCE_ID normal_text_color_id;\n"
26             "    GX_RESOURCE_ID selected_text_color_id;\n"
27             "    GX_RESOURCE_ID disabled_text_color_id;");
28     }
29     else
30     {
31         out = ("    GX_RESOURCE_ID string_id;\n"
32             "    GX_RESOURCE_ID font_id;\n"
33             "    GX_RESOURCE_ID normal_text_color_id;\n"
34             "    GX_RESOURCE_ID selected_text_color_id;");
35     }
36 
37     return out;
38 }
39 
DeclarePropertiesStruct()40 CString prompt_service_provider::DeclarePropertiesStruct()
41 {
42     CString out;
43 
44     out.Format(_T("typedef struct\n")
45         _T("{\n")
46         _T("%s\n")
47         _T("} GX_PROMPT_PROPERTIES;\n\n"),
48         DeclarePropertiesStructContent());
49 
50     return out;
51 }
52 
WriteExtendedPropertiesContent(screen_generator * gen,widget_info * info,GX_BOOL add_last_comma)53 CString prompt_service_provider::WriteExtendedPropertiesContent(screen_generator *gen, widget_info *info, GX_BOOL add_last_comma)
54 {
55     CString out;
56 
57     CString last_delimiter;
58 
59     if (add_last_comma)
60     {
61         last_delimiter = ",";
62     }
63     else
64     {
65         last_delimiter = " ";
66     }
67 
68     if (project_lib_version() <= 50401)
69     {
70         out.Format(_T("    %s, /* string id */\n")
71             _T("    %s, /* font id */\n")
72             _T("    %s, /* normal text color */\n")
73             _T("    %s%s /* selected text color */"),
74             gen->GetStringIdName(info->string_id[0]),
75             gen->GetFontIdName(info->font_id[0]),
76             gen->GetColorIdName(info->color_id[NORMAL_TEXT_COLOR_INDEX]),
77             gen->GetColorIdName(info->color_id[SELECTED_TEXT_COLOR_INDEX]), last_delimiter);
78     }
79     else
80     {
81         out.Format(_T("    %s, /* string id */\n")
82             _T("    %s, /* font id */\n")
83             _T("    %s, /* normal text color */\n")
84             _T("    %s,  /* selected text color */\n")
85             _T("    %s%s /* disabled text color */"),
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]), last_delimiter);
91     }
92 
93     return out;
94 }
95 
WriteExtendedProperties(screen_generator * gen,CString & prefix,widget_info * info)96 CString prompt_service_provider::WriteExtendedProperties(screen_generator *gen, CString &prefix, widget_info *info)
97 {
98     CString out;
99     CString propname = prefix + info->app_name;
100 
101     out.Format(_T("GX_PROMPT_PROPERTIES %s_properties =\n")
102         _T("{\n")
103         _T("%s\n")
104         _T("};\n"),
105         propname,
106         WriteExtendedPropertiesContent(gen, info));
107     return out;
108 }
109 
GetCreateFromDefFunctionName()110 CString prompt_service_provider::GetCreateFromDefFunctionName()
111 {
112     return CString("gx_studio_prompt_create");
113 }
114 
GetCreateFromDefFunction(int version)115 CString prompt_service_provider::GetCreateFromDefFunction(int version)
116 {
117     CString out;
118     MakeCreatePreamble("prompt", version, out);
119 
120     out += "{\n"
121         "    UINT status;\n"
122         "    GX_PROMPT *prompt = (GX_PROMPT *) control_block;\n"
123         "    GX_PROMPT_PROPERTIES *props = (GX_PROMPT_PROPERTIES *) info->properties;\n"
124         "    status = gx_prompt_create(prompt, info->widget_name, parent, props->string_id, info->style, info->widget_id, &info->size);\n"
125         "    if (status == GX_SUCCESS)\n"
126         "    {\n"
127         "        gx_prompt_font_set(prompt, props->font_id);\n";
128 
129         if (project_lib_version() > 50401)
130         {
131             out += "#if defined(GUIX_5_4_0_COMPATIBILITY)\n"
132             "        gx_prompt_text_color_set(prompt, props->normal_text_color_id, props->selected_text_color_id);\n"
133             "#else\n"
134             "        gx_prompt_text_color_set(prompt, props->normal_text_color_id, props->selected_text_color_id, props->disabled_text_color_id);\n"
135             "#endif\n";
136         }
137         else
138         {
139             out += "        gx_prompt_text_color_set(prompt, props->normal_text_color_id, props->selected_text_color_id);\n";
140         }
141 
142     out += "    }\n"
143         "    return status;\n"
144         "}\n";
145 
146     return out;
147 }
148 
CreateNewInstance(GX_WIDGET * parent)149 widget_info *prompt_service_provider::CreateNewInstance(GX_WIDGET *parent)
150 {
151     GX_RECTANGLE size;
152     gx_utility_rectangle_define(&size, 0, 0, 79, 23);
153     gx_utility_rectangle_center(&size, &parent->gx_widget_size);
154 
155     GX_PROMPT *prompt = new GX_PROMPT;
156     GX_RESOURCE_ID string_id = GetStringId("prompt");
157 
158     gx_prompt_create(prompt, "prompt", parent, string_id,
159         GX_STYLE_ENABLED|GX_STYLE_BORDER_THIN|GX_STYLE_TEXT_CENTER, 0, &size);
160     widget_info *info = InitWidgetInfo((GX_WIDGET *) prompt);
161 
162     info->font_id[0] = prompt->gx_prompt_font_id;
163     info->color_id[NORMAL_TEXT_COLOR_INDEX] = prompt->gx_prompt_normal_text_color;
164     info->color_id[SELECTED_TEXT_COLOR_INDEX] = prompt->gx_prompt_selected_text_color;
165     info->color_id[DISABLED_TEXT_COLOR_INDEX] = prompt->gx_prompt_disabled_text_color;
166     info->string_id[0] = string_id;
167     return info;
168 }
169 
GenerateFromInfo(GX_WIDGET * parent,widget_info * info)170 GX_WIDGET *prompt_service_provider::GenerateFromInfo(GX_WIDGET *parent, widget_info *info)
171 {
172     GX_PROMPT *prompt = new GX_PROMPT;
173     gx_prompt_create(prompt,
174         (CHAR *) info->app_name.GetString(),
175         parent,
176         info->string_id[0],      // this should be text id
177         info->style, 0,
178         &info->size);
179 
180     gx_widget_fill_color_set(prompt,
181         info->color_id[NORMAL_FILL_COLOR_INDEX],
182         info->color_id[SELECTED_FILL_COLOR_INDEX],
183         info->color_id[DISABLED_FILL_COLOR_INDEX]);
184     gx_prompt_text_color_set(prompt,
185         info->color_id[NORMAL_TEXT_COLOR_INDEX],
186         info->color_id[SELECTED_TEXT_COLOR_INDEX],
187         info->color_id[DISABLED_TEXT_COLOR_INDEX]);
188     gx_prompt_font_set(prompt, info->font_id[0]);
189 
190     return ((GX_WIDGET *) prompt);
191 }
192 
SaveToProject(xml_writer & writer,studiox_project * project,int display,widget_info * info)193 void prompt_service_provider::SaveToProject(xml_writer &writer, studiox_project *project, int display, widget_info *info)
194 {
195     widget_service_provider::SaveToProject(writer, project, display, info);
196     WriteStringId(writer, project, display, "string_id", info->string_id[0]);
197     WriteFontId(writer, project, display, "font_id", info->font_id[0]);
198     WriteColorId(writer, project, display, "normal_text_color", info->color_id[NORMAL_TEXT_COLOR_INDEX]);
199     WriteColorId(writer, project, display, "selected_text_color", info->color_id[SELECTED_TEXT_COLOR_INDEX]);
200     WriteColorId(writer, project, display, "disabled_text_color", info->color_id[DISABLED_TEXT_COLOR_INDEX]);
201 }
202 
ReadFromProject(xml_reader & reader,studiox_project * project,int display,widget_info * info,ULONG valid_styles)203 void prompt_service_provider::ReadFromProject(xml_reader &reader, studiox_project *project, int display, widget_info *info, ULONG valid_styles)
204 {
205     valid_styles |= GX_STYLE_TEXT_ALIGNMENT_MASK|GX_STYLE_TEXT_COPY;
206     widget_service_provider::ReadFromProject(reader, project, display, info, valid_styles);
207     info->string_id[0] = ReadStringId(reader, project, display, "string_id");
208     if (info->string_id[0] < 0 || info->string_id[0] > 100000)
209     {
210         info->string_id[0] = 0;
211     }
212     info->font_id[0] = ReadFontId(reader, project, display, "font_id");
213     info->color_id[NORMAL_TEXT_COLOR_INDEX] = ReadColorId(reader, project, display, "normal_text_color");
214     info->color_id[SELECTED_TEXT_COLOR_INDEX] = ReadColorId(reader, project, display, "selected_text_color");
215 
216     if (project->mHeader.project_version > 54)
217     {
218         info->color_id[DISABLED_TEXT_COLOR_INDEX] = ReadColorId(reader, project, display, "disabled_text_color");
219     }
220     else
221     {
222         info->color_id[DISABLED_TEXT_COLOR_INDEX] = info->color_id[NORMAL_TEXT_COLOR_INDEX];
223     }
224 }
225 
AssignText(widget_info * info,int index,GX_RESOURCE_ID string_id)226 void prompt_service_provider::AssignText(widget_info *info, int index,
227     GX_RESOURCE_ID string_id)
228 {
229     GX_WIDGET *widget = info->widget;
230 
231     if (widget)
232     {
233         GX_PROMPT *prompt = (GX_PROMPT *)widget;
234         gx_prompt_text_id_set(prompt, string_id);
235     }
236 
237     info->string_id[0] = string_id;
238 }
239 
AssignFont(widget_info * info,int index,GX_RESOURCE_ID font_id)240 void prompt_service_provider::AssignFont(widget_info *info, int index,
241     GX_RESOURCE_ID font_id)
242 {
243     GX_WIDGET *widget = info->widget;
244 
245     if (widget)
246     {
247         GX_PROMPT *prompt = (GX_PROMPT *)widget;
248         gx_prompt_font_set(prompt, font_id);
249     }
250 
251     info->font_id[0] = font_id;
252 }
253 
AssignColor(widget_info * info,int index,GX_RESOURCE_ID color_id)254 void prompt_service_provider::AssignColor(widget_info *info, int index, GX_RESOURCE_ID color_id)
255 {
256     GX_PROMPT *prompt = (GX_PROMPT *) (info->widget);
257 
258     switch(index)
259     {
260     case NORMAL_TEXT_COLOR_INDEX:
261         if (prompt)
262         {
263             gx_prompt_text_color_set(prompt,
264                 color_id,
265                 prompt->gx_prompt_selected_text_color,
266                 prompt->gx_prompt_disabled_text_color);
267         }
268 
269         info->color_id[NORMAL_TEXT_COLOR_INDEX] = color_id;
270         break;
271 
272     case SELECTED_TEXT_COLOR_INDEX:
273         if (prompt)
274         {
275             gx_prompt_text_color_set(prompt,
276                 prompt->gx_prompt_normal_text_color,
277                 color_id,
278                 prompt->gx_prompt_disabled_text_color);
279         }
280 
281         info->color_id[SELECTED_TEXT_COLOR_INDEX] = color_id;
282         break;
283 
284     case DISABLED_TEXT_COLOR_INDEX:
285         if (prompt)
286         {
287             gx_prompt_text_color_set(prompt,
288                 prompt->gx_prompt_normal_text_color,
289                 prompt->gx_prompt_selected_text_color,
290                 color_id);
291         }
292 
293         info->color_id[DISABLED_TEXT_COLOR_INDEX] = color_id;
294         break;
295 
296     default:
297         widget_service_provider::AssignColor(info, index, color_id);
298     }
299 }
300 
Autosize(widget_info * info)301 void prompt_service_provider::Autosize(widget_info *info)
302 {
303     CheckResizeToText(info);
304 }
305