1
2 #include "studiox_includes.h"
3
4 #ifdef _DEBUG
5 #define new DEBUG_NEW
6 #endif
7
8 ///////////////////////////////////////////////////////////////////////////////
rich_text_view_service_provider()9 rich_text_view_service_provider::rich_text_view_service_provider()
10 {
11 }
12
13 ///////////////////////////////////////////////////////////////////////////////
GetVarDeclaration()14 CString rich_text_view_service_provider::GetVarDeclaration()
15 {
16 return CString("GX_RICH_TEXT_VIEW_MEMBERS_DECLARE");
17 }
18
19 ///////////////////////////////////////////////////////////////////////////////
DeclarePropertiesStruct()20 CString rich_text_view_service_provider::DeclarePropertiesStruct()
21 {
22 CString out;
23
24 out = (""
25 "typedef struct\n"
26 "{\n"
27 " GX_RESOURCE_ID string_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_UBYTE whitespace;\n"
32 " GX_BYTE line_space;\n"
33 " GX_RICH_TEXT_FONTS *fonts;\n"
34 "} GX_RICH_TEXT_VIEW_PROPERTIES;\n\n");
35
36 return out;
37 }
38
39 ///////////////////////////////////////////////////////////////////////////////
WriteExtendedProperties(screen_generator * gen,CString & prefix,widget_info * info)40 CString rich_text_view_service_provider::WriteExtendedProperties(screen_generator *gen, CString &prefix, widget_info *info)
41 {
42 CString out;
43 CString temp;
44 CString propname = prefix + info->app_name;
45
46 // generate rich text font
47 out.Format(_T("GX_RICH_TEXT_FONTS %s_fonts =\n")
48 _T("{\n")
49 _T(" %s, /* normal font. */\n")
50 _T(" %s, /* bold font. */\n")
51 _T(" %s, /* italic font. */\n")
52 _T(" %s /* bold italic font. */\n")
53 _T("};\n\n"),
54 propname,
55 gen->GetFontIdName(info->font_id[RICH_TEXT_FONT_NORMAL]),
56 gen->GetFontIdName(info->font_id[RICH_TEXT_FONT_BOLD]),
57 gen->GetFontIdName(info->font_id[RICH_TEXT_FONT_ITALIC]),
58 gen->GetFontIdName(info->font_id[RICH_TEXT_FONT_BOLD_ITALIC]));
59
60 temp.Format(_T("GX_RICH_TEXT_VIEW_PROPERTIES %s_properties =\n")
61 _T("{\n")
62 _T(" %s, /* string id */\n")
63 _T(" %s, /* normal text color */\n")
64 _T(" %s, /* selected text color */\n")
65 _T(" %s, /* disabled text color */\n")
66 _T(" %d, /* whitespace */\n")
67 _T(" %d, /* line_space */\n")
68 _T(" &%s_fonts, /* fonts */\n};\n"),
69 propname,
70 gen->GetStringIdName(info->string_id[0]),
71 gen->GetColorIdName(info->color_id[NORMAL_TEXT_COLOR_INDEX]),
72 gen->GetColorIdName(info->color_id[SELECTED_TEXT_COLOR_INDEX]),
73 gen->GetColorIdName(info->color_id[DISABLED_TEXT_COLOR_INDEX]),
74 info->ewi.text_info.whitespace,
75 info->ewi.text_info.line_space,
76 propname);
77
78 out += temp;
79
80 return out;
81 }
82
83 ///////////////////////////////////////////////////////////////////////////////
GetCreateFromDefFunctionName()84 CString rich_text_view_service_provider::GetCreateFromDefFunctionName()
85 {
86 return CString("gx_studio_rich_text_view_create");
87 }
88
89 ///////////////////////////////////////////////////////////////////////////////
GetCreateFromDefFunction(int version)90 CString rich_text_view_service_provider::GetCreateFromDefFunction(int version)
91 {
92 CString out;
93 MakeCreatePreamble("rich_text_view", version, out);
94
95 out += "{\n"
96 " UINT status;\n"
97 " GX_RICH_TEXT_VIEW *view = (GX_RICH_TEXT_VIEW *) control_block;\n"
98 " GX_RICH_TEXT_VIEW_PROPERTIES *props = (GX_RICH_TEXT_VIEW_PROPERTIES *) info->properties;\n"
99 " status = gx_rich_text_view_create(view, info->widget_name, parent, props->string_id, props->fonts, info->style, info->widget_id, &info->size);\n"
100 " if (status == GX_SUCCESS)\n"
101 " {\n"
102 " gx_multi_line_text_view_text_color_set((GX_MULTI_LINE_TEXT_VIEW *)view, props->normal_text_color_id, props->selected_text_color_id, props->disabled_text_color_id);\n"
103 " gx_multi_line_text_view_whitespace_set((GX_MULTI_LINE_TEXT_VIEW *)view, props->whitespace);\n"
104 " gx_multi_line_text_view_line_space_set((GX_MULTI_LINE_TEXT_VIEW *)view, props->line_space);\n"
105 " }\n"
106 " return status;\n"
107 "}\n";
108
109 return out;
110 }
111
112 ///////////////////////////////////////////////////////////////////////////////
CreateNewInstance(GX_WIDGET * parent)113 widget_info *rich_text_view_service_provider::CreateNewInstance(GX_WIDGET *parent)
114 {
115 int parent_size;
116
117 GX_RECTANGLE size = parent->gx_widget_size;
118 gx_utility_rectangle_define(&size, 0, 0, 79, 23);
119 parent_size = (parent->gx_widget_size.gx_rectangle_right -
120 parent->gx_widget_size.gx_rectangle_left) / 2;
121 size.gx_rectangle_right = size.gx_rectangle_left + parent_size;
122
123 parent_size = (parent->gx_widget_size.gx_rectangle_bottom -
124 parent->gx_widget_size.gx_rectangle_top) / 2;
125 size.gx_rectangle_bottom = size.gx_rectangle_top + parent_size;
126
127 gx_utility_rectangle_center(&size, &parent->gx_widget_size);
128
129 GX_RICH_TEXT_VIEW *view = new GX_RICH_TEXT_VIEW;
130 GX_RESOURCE_ID string_id = GetStringId("rich_text_view");
131 GX_RICH_TEXT_FONTS fonts;
132
133 fonts.gx_rich_text_fonts_normal_id = GX_FONT_ID_DEFAULT;
134 fonts.gx_rich_text_fonts_bold_id = GX_FONT_ID_DEFAULT;
135 fonts.gx_rich_text_fonts_italic_id = GX_FONT_ID_DEFAULT;
136 fonts.gx_rich_text_fonts_bold_italic_id = GX_FONT_ID_DEFAULT;
137
138 gx_rich_text_view_create(view, "rich_text_view", parent, string_id, &fonts,
139 GX_STYLE_ENABLED | GX_STYLE_BORDER_THIN | GX_STYLE_TEXT_CENTER, 0, &size);
140 gx_widget_style_remove(view, GX_STYLE_DRAW_SELECTED);
141 widget_info *info = InitWidgetInfo((GX_WIDGET *)view);
142
143 info->color_id[NORMAL_TEXT_COLOR_INDEX] = view->gx_multi_line_text_view_normal_text_color;
144 info->color_id[SELECTED_TEXT_COLOR_INDEX] = view->gx_multi_line_text_view_selected_text_color;
145 info->color_id[DISABLED_TEXT_COLOR_INDEX] = view->gx_multi_line_text_view_disabled_text_color;
146 info->string_id[0] = string_id;
147 info->font_id[RICH_TEXT_FONT_NORMAL] = fonts.gx_rich_text_fonts_normal_id;
148 info->font_id[RICH_TEXT_FONT_BOLD] = fonts.gx_rich_text_fonts_bold_id;
149 info->font_id[RICH_TEXT_FONT_ITALIC] = fonts.gx_rich_text_fonts_italic_id;
150 info->font_id[RICH_TEXT_FONT_BOLD_ITALIC] = fonts.gx_rich_text_fonts_bold_italic_id;
151 info->ewi.text_info.whitespace = 0;
152 info->ewi.text_info.line_space = 0;
153 return info;
154 }
155
156 ///////////////////////////////////////////////////////////////////////////////
GenerateFromInfo(GX_WIDGET * parent,widget_info * info)157 GX_WIDGET *rich_text_view_service_provider::GenerateFromInfo(GX_WIDGET *parent, widget_info *info)
158 {
159 GX_RICH_TEXT_VIEW *view = new GX_RICH_TEXT_VIEW;
160 GX_RICH_TEXT_FONTS fonts;
161
162 fonts.gx_rich_text_fonts_normal_id = info->font_id[RICH_TEXT_FONT_NORMAL];
163 fonts.gx_rich_text_fonts_bold_id = info->font_id[RICH_TEXT_FONT_BOLD];
164 fonts.gx_rich_text_fonts_italic_id = info->font_id[RICH_TEXT_FONT_ITALIC];
165 fonts.gx_rich_text_fonts_bold_italic_id = info->font_id[RICH_TEXT_FONT_BOLD_ITALIC];
166
167 gx_rich_text_view_create(view,
168 (CHAR *)info->app_name.GetString(),
169 parent,
170 info->string_id[0],
171 &fonts,
172 info->style, 0,
173 &info->size);
174
175 gx_widget_fill_color_set(view,
176 info->color_id[NORMAL_FILL_COLOR_INDEX],
177 info->color_id[SELECTED_FILL_COLOR_INDEX],
178 info->color_id[DISABLED_FILL_COLOR_INDEX]);
179
180 gx_multi_line_text_view_text_color_set((GX_MULTI_LINE_TEXT_VIEW *)view,
181 info->color_id[NORMAL_TEXT_COLOR_INDEX],
182 info->color_id[SELECTED_TEXT_COLOR_INDEX],
183 info->color_id[DISABLED_TEXT_COLOR_INDEX]);
184
185 gx_multi_line_text_view_whitespace_set((GX_MULTI_LINE_TEXT_VIEW *)view, info->ewi.text_info.whitespace);
186 gx_multi_line_text_view_line_space_set((GX_MULTI_LINE_TEXT_VIEW *)view, info->ewi.text_info.line_space);
187
188 return ((GX_WIDGET *)view);
189 }
190
191 ///////////////////////////////////////////////////////////////////////////////
SaveToProject(xml_writer & writer,studiox_project * project,int display,widget_info * info)192 void rich_text_view_service_provider::SaveToProject(xml_writer &writer, studiox_project *project, int display, widget_info *info)
193 {
194 widget_service_provider::SaveToProject(writer, project, display, info);
195 WriteStringId(writer, project, display, "string_id", info->string_id[0]);
196
197 WriteFontId(writer, project, display, "normal_font", info->font_id[RICH_TEXT_FONT_NORMAL]);
198 WriteFontId(writer, project, display, "bold_font", info->font_id[RICH_TEXT_FONT_BOLD]);
199 WriteFontId(writer, project, display, "italic_font", info->font_id[RICH_TEXT_FONT_ITALIC]);
200 WriteFontId(writer, project, display, "bold_italic_font", info->font_id[RICH_TEXT_FONT_BOLD_ITALIC]);
201
202 WriteColorId(writer, project, display, "normal_text_color", info->color_id[NORMAL_TEXT_COLOR_INDEX]);
203 WriteColorId(writer, project, display, "selected_text_color", info->color_id[SELECTED_TEXT_COLOR_INDEX]);
204 WriteColorId(writer, project, display, "disabled_fill_color", info->color_id[DISABLED_FILL_COLOR_INDEX]);
205 WriteColorId(writer, project, display, "disabled_text_color", info->color_id[DISABLED_TEXT_COLOR_INDEX]);
206 writer.WriteInt("whitespace", info->ewi.text_info.whitespace);
207 writer.WriteInt("line_space", info->ewi.text_info.line_space);
208 }
209
210 ///////////////////////////////////////////////////////////////////////////////
ReadFromProject(xml_reader & reader,studiox_project * project,int display,widget_info * info,ULONG valid_styles)211 void rich_text_view_service_provider::ReadFromProject(xml_reader &reader, studiox_project *project, int display, widget_info *info, ULONG valid_styles)
212 {
213 valid_styles |= GX_STYLE_TEXT_ALIGNMENT_MASK | GX_STYLE_TEXT_COPY;
214
215 widget_service_provider::ReadFromProject(reader, project, display, info, valid_styles);
216 info->string_id[0] = ReadStringId(reader, project, display, "string_id");
217 if (info->string_id[0] < 0 || info->string_id[0] > 100000)
218 {
219 info->string_id[0] = 0;
220 }
221
222 info->font_id[RICH_TEXT_FONT_NORMAL] = ReadFontId(reader, project, display, "normal_font");
223 info->font_id[RICH_TEXT_FONT_BOLD] = ReadFontId(reader, project, display, "bold_font");
224 info->font_id[RICH_TEXT_FONT_ITALIC ] = ReadFontId(reader, project, display, "italic_font");
225 info->font_id[RICH_TEXT_FONT_BOLD_ITALIC] = ReadFontId(reader, project, display, "bold_italic_font");
226
227 info->color_id[NORMAL_TEXT_COLOR_INDEX] = ReadColorId(reader, project, display, "normal_text_color");
228 info->color_id[SELECTED_TEXT_COLOR_INDEX] = ReadColorId(reader, project, display, "selected_text_color");
229 info->color_id[DISABLED_TEXT_COLOR_INDEX] = ReadColorId(reader, project, display, "disabled_text_color");
230 reader.ReadInt("whitespace", info->ewi.text_info.whitespace, 0);
231 reader.ReadInt("line_space", info->ewi.text_info.line_space, 0);
232 }
233
234
235 ///////////////////////////////////////////////////////////////////////////////
AssignFont(widget_info * info,int index,GX_RESOURCE_ID font_id)236 void rich_text_view_service_provider::AssignFont(widget_info *info, int index, GX_RESOURCE_ID font_id)
237 {
238 GX_WIDGET *widget = info->widget;
239
240 info->font_id[index] = font_id;
241
242 if (widget)
243 {
244 GX_RICH_TEXT_VIEW *view = (GX_RICH_TEXT_VIEW *)widget;
245
246 GX_RICH_TEXT_FONTS fonts = view->gx_rich_text_view_fonts;
247
248 switch (index)
249 {
250 case RICH_TEXT_FONT_NORMAL:
251 fonts.gx_rich_text_fonts_normal_id = font_id;
252 break;
253
254 case RICH_TEXT_FONT_BOLD:
255 fonts.gx_rich_text_fonts_bold_id = font_id;
256 break;
257
258 case RICH_TEXT_FONT_ITALIC:
259 fonts.gx_rich_text_fonts_italic_id = font_id;
260 break;
261
262 case RICH_TEXT_FONT_BOLD_ITALIC:
263 fonts.gx_rich_text_fonts_bold_italic_id = font_id;
264 break;
265 }
266 gx_rich_text_view_fonts_set((GX_RICH_TEXT_VIEW *)widget, &fonts);
267 }
268 }
269
270
271 ///////////////////////////////////////////////////////////////////////////////
AssignText(widget_info * info,int index,GX_RESOURCE_ID string_id)272 void rich_text_view_service_provider::AssignText(widget_info *info, int index,
273 GX_RESOURCE_ID string_id)
274 {
275 info->string_id[0] = string_id;
276 GX_WIDGET *widget = info->widget;
277
278 if (widget)
279 {
280 GX_MULTI_LINE_TEXT_VIEW *view = (GX_MULTI_LINE_TEXT_VIEW *)widget;
281 gx_multi_line_text_view_text_id_set(view, string_id);
282 }
283 }
284
285 ///////////////////////////////////////////////////////////////////////////////
AssignColor(widget_info * info,int index,GX_RESOURCE_ID color_id)286 void rich_text_view_service_provider::AssignColor(widget_info *info, int index, GX_RESOURCE_ID color_id)
287 {
288 GX_MULTI_LINE_TEXT_VIEW *view = (GX_MULTI_LINE_TEXT_VIEW *)(info->widget);
289
290 switch (index)
291 {
292 case NORMAL_TEXT_COLOR_INDEX:
293 if (view)
294 {
295 gx_multi_line_text_view_text_color_set(view, color_id, view->gx_multi_line_text_view_selected_text_color, view->gx_multi_line_text_view_disabled_text_color);
296 }
297
298 info->color_id[NORMAL_TEXT_COLOR_INDEX] = color_id;
299 break;
300
301 case SELECTED_TEXT_COLOR_INDEX:
302 if (view)
303 {
304 gx_multi_line_text_view_text_color_set(view, view->gx_multi_line_text_view_normal_text_color, color_id, view->gx_multi_line_text_view_disabled_text_color);
305 }
306
307 info->color_id[SELECTED_TEXT_COLOR_INDEX] = color_id;
308 break;
309
310 case DISABLED_TEXT_COLOR_INDEX:
311 if (view)
312 {
313 gx_multi_line_text_view_text_color_set(view, view->gx_multi_line_text_view_normal_text_color, view->gx_multi_line_text_view_selected_text_color, color_id);
314 }
315 info->color_id[DISABLED_TEXT_COLOR_INDEX] = color_id;
316 break;
317
318 default:
319 window_service_provider::AssignColor(info, index, color_id);
320 }
321 }