1
2 #include "studiox_includes.h"
3
4 #ifdef _DEBUG
5 #define new DEBUG_NEW
6 #endif
7
text_button_service_provider()8 text_button_service_provider::text_button_service_provider()
9 {
10 }
11
GetVarDeclaration()12 CString text_button_service_provider::GetVarDeclaration()
13 {
14 return CString("GX_TEXT_BUTTON_MEMBERS_DECLARE");
15 }
16
DeclaraPropertiesStructContent()17 CString text_button_service_provider::DeclaraPropertiesStructContent()
18 {
19 CString out;
20
21 if (project_lib_version() > 50401)
22 {
23 out = (""
24 " GX_RESOURCE_ID string_id; \n"
25 " GX_RESOURCE_ID font_id;\n"
26 " GX_RESOURCE_ID normal_text_color_id;\n"
27 " GX_RESOURCE_ID selected_text_color_id;\n"
28 " GX_RESOURCE_ID disabled_text_color_id;");
29 }
30 else
31 {
32 out = (""
33 " GX_RESOURCE_ID string_id;\n"
34 " GX_RESOURCE_ID font_id;\n"
35 " GX_RESOURCE_ID normal_text_color_id;\n"
36 " GX_RESOURCE_ID selected_text_color_id;");
37 }
38
39 return out;
40 }
41
DeclarePropertiesStruct()42 CString text_button_service_provider::DeclarePropertiesStruct()
43 {
44 CString out;
45
46 out.Format(_T("typedef struct\n")
47 _T("{\n")
48 _T("%s\n")
49 _T("} GX_TEXT_BUTTON_PROPERTIES;\n\n"),
50 DeclaraPropertiesStructContent());
51 return out;
52 }
53
WriteExtendedPropertiesContent(screen_generator * gen,widget_info * info,BOOL add_last_comma)54 CString text_button_service_provider::WriteExtendedPropertiesContent(screen_generator *gen, widget_info *info, BOOL add_last_comma)
55 {
56 CString out;
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, /* selected text color */\n")
74 _T(" %s%s /* disabled text color */"),
75 gen->GetStringIdName(info->string_id[0]),
76 gen->GetFontIdName(info->font_id[0]),
77 gen->GetColorIdName(info->color_id[NORMAL_TEXT_COLOR_INDEX]),
78 gen->GetColorIdName(info->color_id[SELECTED_TEXT_COLOR_INDEX]),
79 gen->GetColorIdName(info->color_id[DISABLED_TEXT_COLOR_INDEX]), last_delimiter);
80 }
81 else
82 {
83 out.Format(_T(" %s, /* string id */\n")
84 _T(" %s, /* font id */\n")
85 _T(" %s, /* normal text color */\n")
86 _T(" %s%s /* selected text color */"),
87 gen->GetStringIdName(info->string_id[0]),
88 gen->GetFontIdName(info->font_id[0]),
89 gen->GetColorIdName(info->color_id[NORMAL_TEXT_COLOR_INDEX]),
90 gen->GetColorIdName(info->color_id[SELECTED_TEXT_COLOR_INDEX]), last_delimiter);
91 }
92
93 return out;
94 }
95
WriteExtendedProperties(screen_generator * gen,CString & prefix,widget_info * info)96 CString text_button_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_TEXT_BUTTON_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 text_button_service_provider::GetCreateFromDefFunctionName()
111 {
112 return CString("gx_studio_text_button_create");
113 }
114
GetCreateFromDefFunction(int version)115 CString text_button_service_provider::GetCreateFromDefFunction(int version)
116 {
117 CString out;
118 MakeCreatePreamble("text_button", version, out);
119
120 out += "{\n"
121 " UINT status;\n"
122 " GX_TEXT_BUTTON *button = (GX_TEXT_BUTTON *) control_block;\n"
123 " GX_TEXT_BUTTON_PROPERTIES *props = (GX_TEXT_BUTTON_PROPERTIES *) info->properties;\n"
124 " status = gx_text_button_create(button, 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_text_button_font_set(button, props->font_id);\n";
128 if (project_lib_version() > 50401)
129 {
130 out += "#if defined(GUIX_5_4_0_COMPATIBILITY)\n"
131 " gx_text_button_text_color_set(button, props->normal_text_color_id, props->selected_text_color_id);\n"
132 "#else\n"
133 " gx_text_button_text_color_set(button, props->normal_text_color_id, props->selected_text_color_id, props->disabled_text_color_id);\n"
134 "#endif\n";
135 }
136 else
137 {
138 out += " gx_text_button_text_color_set(button, props->normal_text_color_id, props->selected_text_color_id);\n";
139 }
140
141 out += " }\n"
142 " return status;\n"
143 "}\n";
144 return out;
145 }
146
CreateNewInstance(GX_WIDGET * parent)147 widget_info *text_button_service_provider::CreateNewInstance(GX_WIDGET *parent)
148 {
149 GX_RECTANGLE size;
150 gx_utility_rectangle_define(&size, 0, 0, 79, 23);
151 gx_utility_rectangle_center(&size, &parent->gx_widget_size);
152
153 GX_TEXT_BUTTON *button = new GX_TEXT_BUTTON;
154 GX_RESOURCE_ID string_id = GetStringId("button");
155
156 gx_text_button_create(button, "button", parent,
157 string_id, GX_STYLE_ENABLED|GX_STYLE_TEXT_CENTER|GX_STYLE_BORDER_RAISED, 0, &size);
158
159 widget_info *info = InitWidgetInfo((GX_WIDGET *) button);
160
161 info->string_id[0] = string_id;
162 info->color_id[NORMAL_TEXT_COLOR_INDEX] = button->gx_text_button_normal_text_color;
163 info->color_id[SELECTED_TEXT_COLOR_INDEX] = button->gx_text_button_selected_text_color;
164 info->color_id[DISABLED_TEXT_COLOR_INDEX] = button->gx_text_button_disabled_text_color;
165 info->font_id[0] = button->gx_text_button_font_id;
166
167 return info;
168 }
169
GenerateFromInfo(GX_WIDGET * parent,widget_info * info)170 GX_WIDGET *text_button_service_provider::GenerateFromInfo(GX_WIDGET *parent, widget_info *info)
171 {
172 GX_TEXT_BUTTON *button = new GX_TEXT_BUTTON;
173 gx_text_button_create(button,
174 (CHAR *) info->app_name.GetString(),
175 parent,
176 info->string_id[0],
177 info->style,
178 0,
179 &info->size);
180
181 gx_widget_fill_color_set(button,
182 info->color_id[NORMAL_FILL_COLOR_INDEX],
183 info->color_id[SELECTED_FILL_COLOR_INDEX],
184 info->color_id[DISABLED_FILL_COLOR_INDEX]);
185 gx_text_button_text_color_set(button,
186 info->color_id[NORMAL_TEXT_COLOR_INDEX],
187 info->color_id[SELECTED_TEXT_COLOR_INDEX],
188 info->color_id[DISABLED_TEXT_COLOR_INDEX]);
189 gx_text_button_font_set(button, info->font_id[0]);
190 return ((GX_WIDGET *) button);
191 }
192
SaveToProject(xml_writer & writer,studiox_project * project,int display,widget_info * info)193 void text_button_service_provider::SaveToProject(xml_writer &writer, studiox_project *project, int display, widget_info *info)
194 {
195 button_service_provider::SaveToProject(writer, project, display, info);
196 WriteStringId(writer, project,display, "text_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 text_button_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
207 button_service_provider::ReadFromProject(reader, project, display, info, valid_styles);
208 info->string_id[0] = ReadStringId(reader, project, display, "text_id");
209 info->font_id[0] = ReadFontId(reader, project, display, "font_id");
210 info->color_id[NORMAL_TEXT_COLOR_INDEX] = ReadColorId(reader, project, display, "normal_text_color");
211 info->color_id[SELECTED_TEXT_COLOR_INDEX] = ReadColorId(reader, project, display, "selected_text_color");
212
213 if (project->mHeader.project_version > 54)
214 {
215 info->color_id[DISABLED_TEXT_COLOR_INDEX] = ReadColorId(reader, project, display, "disabled_text_color");
216 }
217 else
218 {
219 info->color_id[DISABLED_TEXT_COLOR_INDEX] = info->color_id[NORMAL_TEXT_COLOR_INDEX];
220 }
221 }
222
AssignText(widget_info * info,int index,GX_RESOURCE_ID string_id)223 void text_button_service_provider::AssignText(widget_info *info, int index,
224 GX_RESOURCE_ID string_id)
225 {
226 GX_WIDGET *widget = info->widget;
227
228 if (widget)
229 {
230 GX_TEXT_BUTTON *pb = (GX_TEXT_BUTTON *)widget;
231
232 gx_text_button_text_id_set(pb, string_id);
233 }
234
235 info->string_id[0] = string_id;
236 }
237
AssignFont(widget_info * info,int index,GX_RESOURCE_ID font_id)238 void text_button_service_provider::AssignFont(widget_info *info, int index, GX_RESOURCE_ID font_id)
239 {
240 GX_WIDGET *widget = info->widget;
241
242 if (widget)
243 {
244 GX_TEXT_BUTTON *pb = (GX_TEXT_BUTTON *)widget;
245
246 gx_text_button_font_set(pb, font_id);
247 }
248
249 info->font_id[0] = font_id;
250 }
251
AssignColor(widget_info * info,int index,GX_RESOURCE_ID color_id)252 void text_button_service_provider::AssignColor(widget_info *info, int index, GX_RESOURCE_ID color_id)
253 {
254 GX_TEXT_BUTTON *pb = (GX_TEXT_BUTTON *) (info->widget);
255
256 switch(index)
257 {
258 case NORMAL_TEXT_COLOR_INDEX:
259 if (pb)
260 {
261 gx_text_button_text_color_set(pb, color_id, pb->gx_text_button_selected_text_color, pb->gx_text_button_disabled_text_color);
262 }
263
264 info->color_id[NORMAL_TEXT_COLOR_INDEX] = color_id;
265 break;
266
267 case SELECTED_TEXT_COLOR_INDEX:
268 if (pb)
269 {
270 gx_text_button_text_color_set(pb, pb->gx_text_button_normal_text_color, color_id, pb->gx_text_button_disabled_text_color);
271 }
272
273 info->color_id[SELECTED_TEXT_COLOR_INDEX] = color_id;
274 break;
275
276 case DISABLED_TEXT_COLOR_INDEX:
277 if (pb)
278 {
279 gx_text_button_text_color_set(pb, pb->gx_text_button_normal_text_color, pb->gx_text_button_selected_text_color, color_id);
280 }
281
282 info->color_id[DISABLED_TEXT_COLOR_INDEX] = color_id;
283 break;
284
285 default:
286 widget_service_provider::AssignColor(info, index, color_id);
287 }
288 }
289
Autosize(widget_info * info)290 void text_button_service_provider::Autosize(widget_info *info)
291 {
292 CheckResizeToText(info);
293 }