1
2 #include "studiox_includes.h"
3
4 #ifdef _DEBUG
5 #define new DEBUG_NEW
6 #endif
7
8 ///////////////////////////////////////////////////////////////////////////////
tree_view_service_provider()9 tree_view_service_provider::tree_view_service_provider()
10 {
11 }
12
13 ///////////////////////////////////////////////////////////////////////////////
GetVarDeclaration()14 CString tree_view_service_provider::GetVarDeclaration()
15 {
16 return CString("GX_TREE_VIEW_MEMBERS_DECLARE");
17 }
18
19 ///////////////////////////////////////////////////////////////////////////////
DeclarePropertiesStruct()20 CString tree_view_service_provider::DeclarePropertiesStruct()
21 {
22 CString out(""
23 "typedef struct\n"
24 "{\n"
25 " GX_RESOURCE_ID expand_map_id;\n"
26 " GX_RESOURCE_ID collapse_map_id;\n"
27 " GX_RESOURCE_ID root_line_color_id;\n"
28 " GX_VALUE indentation;\n"
29 "} GX_TREE_VIEW_PROPERTIES;\n\n");
30 return out;
31 }
32
33 ///////////////////////////////////////////////////////////////////////////////
WriteExtendedProperties(screen_generator * gen,CString & prefix,widget_info * info)34 CString tree_view_service_provider::WriteExtendedProperties(screen_generator *gen, CString &prefix, widget_info *info)
35 {
36 CString out;
37 CString propname = prefix + info->app_name;
38
39 out.Format(_T("GX_TREE_VIEW_PROPERTIES %s_properties =\n")
40 _T("{\n")
41 _T(" %s, /* expand map id */\n")
42 _T(" %s, /* collapse map id */\n")
43 _T(" %s, /* root line color id */\n")
44 _T(" %d /* indentation */\n};\n"),
45 propname,
46 gen->GetPixelmapIdName(info->pixelmap_id[TREE_VIEW_EXPAND_PIXELMAP_INDEX]),
47 gen->GetPixelmapIdName(info->pixelmap_id[TREE_VIEW_COLLAPSE_PIXELMAP_INDEX]),
48 gen->GetColorIdName(info->color_id[TREE_VIEW_ROOT_LINE_COLOR_INDEX]),
49 info->ewi.tree_view_indentation);
50
51 return out;
52 }
53
54 ///////////////////////////////////////////////////////////////////////////////
GetCreateFromDefFunctionName()55 CString tree_view_service_provider::GetCreateFromDefFunctionName()
56 {
57 return CString("gx_studio_tree_view_create");
58 }
59
60 ///////////////////////////////////////////////////////////////////////////////
GetCreateFromDefFunction(int version)61 CString tree_view_service_provider::GetCreateFromDefFunction(int version)
62 {
63 CString out;
64 MakeCreatePreamble("tree_view", version, out);
65
66 out += "{\n"
67 " UINT status;\n"
68 " GX_TREE_VIEW *tree = (GX_TREE_VIEW *) control_block;\n"
69 " GX_TREE_VIEW_PROPERTIES *props = (GX_TREE_VIEW_PROPERTIES *) info->properties;\n"
70 " status = gx_tree_view_create(tree, info->widget_name, parent,\n"
71 " info->style, info->widget_id, &info->size);\n"
72 " if (status == GX_SUCCESS)\n"
73 " {\n"
74 " if (props->expand_map_id || props->collapse_map_id)\n"
75 " {\n"
76 " gx_tree_view_root_pixelmap_set(tree, props->expand_map_id, props->collapse_map_id);\n"
77 " }\n"
78 " gx_tree_view_indentation_set(tree, props->indentation);\n"
79 " gx_tree_view_root_line_color_set(tree, props->root_line_color_id);\n"
80 " }\n"
81 " return status;\n"
82 "}\n";
83 return out;
84 }
85
86 ///////////////////////////////////////////////////////////////////////////////
CreateNewInstance(GX_WIDGET * parent)87 widget_info *tree_view_service_provider::CreateNewInstance(GX_WIDGET *parent)
88 {
89 int parent_size;
90
91 GX_RECTANGLE size = parent->gx_widget_size;
92 gx_utility_rectangle_define(&size, 0, 0, 79, 23);
93 parent_size = (parent->gx_widget_size.gx_rectangle_right -
94 parent->gx_widget_size.gx_rectangle_left) / 2;
95 size.gx_rectangle_right = size.gx_rectangle_left + parent_size;
96
97 parent_size = (parent->gx_widget_size.gx_rectangle_bottom -
98 parent->gx_widget_size.gx_rectangle_top) / 2;
99 size.gx_rectangle_bottom = size.gx_rectangle_top + parent_size;
100
101 gx_utility_rectangle_center(&size, &parent->gx_widget_size);
102
103 GX_TREE_VIEW *tree = new GX_TREE_VIEW;
104 gx_tree_view_create(tree, "tree_view", parent,
105 GX_STYLE_BORDER_THIN | GX_STYLE_ENABLED | GX_STYLE_TREE_VIEW_SHOW_ROOT_LINES, 0, &size);
106 gx_widget_style_remove(tree, GX_STYLE_DRAW_SELECTED);
107 widget_info *info = InitWidgetInfo((GX_WIDGET *)tree);
108 info->pixelmap_id[TREE_VIEW_EXPAND_PIXELMAP_INDEX] = 0;
109 info->pixelmap_id[TREE_VIEW_COLLAPSE_PIXELMAP_INDEX] = 0;
110 info->color_id[TREE_VIEW_ROOT_LINE_COLOR_INDEX] = tree->gx_tree_view_root_line_color;
111 info->ewi.tree_view_indentation = tree->gx_tree_view_indentation;
112 return info;
113 }
114
115 ///////////////////////////////////////////////////////////////////////////////
GenerateFromInfo(GX_WIDGET * parent,widget_info * info)116 GX_WIDGET *tree_view_service_provider::GenerateFromInfo(GX_WIDGET *parent, widget_info *info)
117 {
118 GX_TREE_VIEW *tree = new GX_TREE_VIEW;
119
120 //create a tree view widget
121 gx_tree_view_create(tree,
122 (CHAR *)info->app_name.GetString(),
123 parent,
124 info->style,
125 0,
126 &info->size);
127
128 //set fill color
129 gx_widget_fill_color_set((GX_WIDGET *)tree,
130 info->color_id[NORMAL_FILL_COLOR_INDEX],
131 info->color_id[SELECTED_FILL_COLOR_INDEX],
132 info->color_id[DISABLED_FILL_COLOR_INDEX]);
133
134 if (info->pixelmap_id[TREE_VIEW_EXPAND_PIXELMAP_INDEX] ||
135 info->pixelmap_id[TREE_VIEW_COLLAPSE_PIXELMAP_INDEX])
136 {
137 //set tree view root pixelmap
138 gx_tree_view_root_pixelmap_set(tree, info->pixelmap_id[TREE_VIEW_EXPAND_PIXELMAP_INDEX],
139 info->pixelmap_id[TREE_VIEW_COLLAPSE_PIXELMAP_INDEX]);
140 }
141
142 //set tree view indentation
143 gx_tree_view_indentation_set(tree, info->ewi.tree_view_indentation);
144 gx_tree_view_root_line_color_set(tree, info->color_id[TREE_VIEW_ROOT_LINE_COLOR_INDEX]);
145
146 return (GX_WIDGET*)tree;
147 }
148
149 ///////////////////////////////////////////////////////////////////////////////
SaveToProject(xml_writer & writer,studiox_project * project,int display,widget_info * info)150 void tree_view_service_provider::SaveToProject(xml_writer &writer, studiox_project *project, int display, widget_info *info)
151 {
152 window_service_provider::SaveToProject(writer, project, display, info);
153 WritePixelmapId(writer, project, display, "expand_map_id", info->pixelmap_id[TREE_VIEW_EXPAND_PIXELMAP_INDEX]);
154 WritePixelmapId(writer, project, display, "collapse_map_id", info->pixelmap_id[TREE_VIEW_COLLAPSE_PIXELMAP_INDEX]);
155 WriteColorId(writer, project, display, "root_line_color_id", info->color_id[TREE_VIEW_ROOT_LINE_COLOR_INDEX]);
156 writer.WriteInt("indentation", info->ewi.tree_view_indentation);
157 }
158
159 ///////////////////////////////////////////////////////////////////////////////
ReadFromProject(xml_reader & reader,studiox_project * project,int display,widget_info * info,ULONG valid_styles)160 void tree_view_service_provider::ReadFromProject(xml_reader &reader, studiox_project *project, int display, widget_info *info, ULONG valid_styles)
161 {
162 valid_styles |= GX_STYLE_TREE_VIEW_SHOW_ROOT_LINES;
163 window_service_provider::ReadFromProject(reader, project, display, info, valid_styles);
164 info->pixelmap_id[TREE_VIEW_EXPAND_PIXELMAP_INDEX] = ReadPixelmapId(reader, project, display, "expand_map_id");
165 info->pixelmap_id[TREE_VIEW_COLLAPSE_PIXELMAP_INDEX] = ReadPixelmapId(reader, project, display, "collapse_map_id");
166 info->color_id[TREE_VIEW_ROOT_LINE_COLOR_INDEX] = ReadColorId(reader, project, display, "root_line_color_id");
167 reader.ReadInt("indentation", info->ewi.tree_view_indentation);
168 }
169
170 ///////////////////////////////////////////////////////////////////////////////
AssignPixelmap(widget_info * info,int index,GX_RESOURCE_ID pixmap_id)171 void tree_view_service_provider::AssignPixelmap(widget_info *info, int index, GX_RESOURCE_ID pixmap_id)
172 {
173 GX_TREE_VIEW *tree = (GX_TREE_VIEW *) (info->widget);
174
175 switch (index)
176 {
177 case TREE_VIEW_EXPAND_PIXELMAP_INDEX:
178 info->pixelmap_id[TREE_VIEW_EXPAND_PIXELMAP_INDEX] = pixmap_id;
179
180 if (tree)
181 {
182 gx_tree_view_root_pixelmap_set(tree, pixmap_id, tree->gx_tree_view_collapse_pixelmap_id);
183 }
184 break;
185
186 case TREE_VIEW_COLLAPSE_PIXELMAP_INDEX:
187 info->pixelmap_id[TREE_VIEW_COLLAPSE_PIXELMAP_INDEX] = pixmap_id;
188
189 if (tree)
190 {
191 gx_tree_view_root_pixelmap_set(tree, tree->gx_tree_view_expand_pixelmap_id, pixmap_id);
192 }
193 break;
194
195 default:
196 break;
197 }
198 }
199
200 ///////////////////////////////////////////////////////////////////////////////
AssignColor(widget_info * info,int index,GX_RESOURCE_ID color_id)201 void tree_view_service_provider::AssignColor(widget_info *info, int index, GX_RESOURCE_ID color_id)
202 {
203 GX_WIDGET *widget = info->widget;
204
205 switch (index)
206 {
207 case TREE_VIEW_ROOT_LINE_COLOR_INDEX:
208 if (widget)
209 {
210 gx_tree_view_root_line_color_set((GX_TREE_VIEW *)widget, color_id);
211 }
212
213 info->color_id[TREE_VIEW_ROOT_LINE_COLOR_INDEX] = color_id;
214 break;
215
216 default:
217 widget_service_provider::AssignColor(info, index, color_id);
218 }
219 }
220
221