1 
2 #include "studiox_includes.h"
3 
4 #ifdef _DEBUG
5 #define new DEBUG_NEW
6 #endif
7 
slider_service_provider()8 slider_service_provider::slider_service_provider()
9 {
10 }
11 
GetVarDeclaration()12 CString slider_service_provider::GetVarDeclaration()
13 {
14     return CString("GX_SLIDER_MEMBERS_DECLARE");
15 }
16 
DeclarePropertiesStruct()17 CString slider_service_provider::DeclarePropertiesStruct()
18 {
19     CString out(""
20     "typedef struct\n"
21     "{\n"
22     "    int tickmark_count;\n"
23     "    int minval;\n"
24     "    int maxval;\n"
25     "    int current_val;\n"
26     "    int increment;\n"
27     "    GX_VALUE min_travel;\n"
28     "    GX_VALUE max_travel;\n"
29     "    GX_VALUE needle_width;\n"
30     "    GX_VALUE needle_height;\n"
31     "    GX_VALUE needle_inset;\n"
32     "    GX_VALUE needle_hotspot;\n"
33     "} GX_SLIDER_PROPERTIES;\n\n");
34     return out;
35 }
36 
WriteExtendedProperties(screen_generator * gen,CString & prefix,widget_info * info)37 CString slider_service_provider::WriteExtendedProperties(screen_generator *gen, CString &prefix, widget_info *info)
38 {
39     CString out;
40     CString propname = prefix + info->app_name;
41     out.Format(_T("GX_SLIDER_PROPERTIES %s_properties =\n")
42         _T("{\n")
43         _T("    %d, /* tickmark count */\n")
44         _T("    %d, /* mimimun value */\n")
45         _T("    %d, /* maximum value */\n")
46         _T("    %d, /* current value */\n")
47         _T("    %d, /* increment */\n")
48         _T("    %d, /* minimum travel */\n")
49         _T("    %d, /* maximum travel */\n")
50         _T("    %d, /* needle width */\n")
51         _T("    %d, /* needle height */\n")
52         _T("    %d, /* needle inset */\n")
53         _T("    %d  /* needle hotspot */\n};\n"),
54         propname,
55         info ->misc_value,
56         info->ewi.slider.gx_slider_info_min_val,
57         info->ewi.slider.gx_slider_info_max_val,
58         info->ewi.slider.gx_slider_info_current_val,
59         info->ewi.slider.gx_slider_info_increment,
60         info->ewi.slider.gx_slider_info_min_travel,
61         info->ewi.slider.gx_slider_info_max_travel,
62         info->ewi.slider.gx_slider_info_needle_width,
63         info->ewi.slider.gx_slider_info_needle_height,
64         info->ewi.slider.gx_slider_info_needle_inset,
65         info->ewi.slider.gx_slider_info_needle_hotspot_offset);
66     return out;
67 }
68 
GetCreateFromDefFunctionName()69 CString slider_service_provider::GetCreateFromDefFunctionName()
70 {
71     return CString("gx_studio_slider_create");
72 }
73 
GetCreateFromDefFunction(int version)74 CString slider_service_provider::GetCreateFromDefFunction(int version)
75 {
76     CString out;
77     MakeCreatePreamble("slider", version, out);
78 
79     out += "{\n"
80         "    UINT status;\n"
81         "    GX_SLIDER *slider = (GX_SLIDER *) control_block;\n"
82         "    GX_SLIDER_PROPERTIES *props = (GX_SLIDER_PROPERTIES *) info->properties;\n"
83         "    GX_SLIDER_INFO slider_info;\n"
84         "    slider_info.gx_slider_info_min_val = props->minval;\n"
85         "    slider_info.gx_slider_info_max_val = props->maxval;\n"
86         "    slider_info.gx_slider_info_current_val = props->current_val;\n"
87         "    slider_info.gx_slider_info_increment = props->increment;\n"
88         "    slider_info.gx_slider_info_min_travel = props->min_travel;\n"
89         "    slider_info.gx_slider_info_max_travel = props->max_travel;\n"
90         "    slider_info.gx_slider_info_needle_width = props->needle_width;\n"
91         "    slider_info.gx_slider_info_needle_height = props->needle_height;\n"
92         "    slider_info.gx_slider_info_needle_inset = props->needle_inset;\n"
93         "    slider_info.gx_slider_info_needle_hotspot_offset = props->needle_hotspot;\n"
94         "    status = gx_slider_create(slider,\n"
95         "                    info->widget_name,\n"
96         "                    parent,\n"
97         "                    props->tickmark_count,\n"
98         "                    &slider_info,\n"
99         "                    info->style,\n"
100         "                    info->widget_id,\n"
101         "                    &info->size);\n"
102         "    return status;\n"
103         "}\n";
104     return out;
105 
106 }
107 
CreateNewInstance(GX_WIDGET * parent)108 widget_info *slider_service_provider::CreateNewInstance(GX_WIDGET *parent)
109 {
110     GX_RECTANGLE size;
111     gx_utility_rectangle_define(&size, 0, 0, 79, 23);
112     gx_utility_rectangle_center(&size, &parent->gx_widget_size);
113 
114     GX_SLIDER *slider = new GX_SLIDER;
115     GX_SLIDER_INFO slider_info;
116 
117     slider_info.gx_slider_info_min_val = 0;
118     slider_info.gx_slider_info_max_val = 100;
119     slider_info.gx_slider_info_current_val = 50;
120     slider_info.gx_slider_info_increment = 10;
121     slider_info.gx_slider_info_min_travel = 0;
122     slider_info.gx_slider_info_max_travel = 0;
123     slider_info.gx_slider_info_needle_width = 5;
124     slider_info.gx_slider_info_needle_height = 10;
125     slider_info.gx_slider_info_needle_inset = 5;
126     slider_info.gx_slider_info_needle_hotspot_offset = 2;
127 
128     gx_slider_create(slider,
129                     "slider",
130                     parent, 10, &slider_info,
131                     GX_STYLE_SHOW_NEEDLE|GX_STYLE_ENABLED, 0,
132                     &size);
133 
134     widget_info *info = InitWidgetInfo((GX_WIDGET *) slider);
135     info -> misc_value = 10;
136     info -> ewi.slider = slider_info;
137     return info;
138 }
139 
GenerateFromInfo(GX_WIDGET * parent,widget_info * info)140 GX_WIDGET *slider_service_provider::GenerateFromInfo(GX_WIDGET *parent, widget_info *info)
141 {
142     GX_SLIDER *slider = new GX_SLIDER;
143 
144     int tick_count = info ->misc_value;
145     if (tick_count == 0)
146     {
147         info ->misc_value = 10;
148         tick_count = 10;
149     }
150 
151     gx_slider_create(slider,
152         (CHAR *) info->app_name.GetString(),
153         parent, tick_count, &info->ewi.slider,
154         info->style,
155         0,
156         &info->size);
157 
158     gx_widget_fill_color_set((GX_WIDGET *) slider,
159         info->color_id[NORMAL_FILL_COLOR_INDEX], info->color_id[SELECTED_FILL_COLOR_INDEX], info->color_id[DISABLED_FILL_COLOR_INDEX]);
160     return ((GX_WIDGET *) slider);
161 }
162 
SaveToProject(xml_writer & writer,studiox_project * project,int display,widget_info * info)163 void slider_service_provider::SaveToProject(xml_writer &writer, studiox_project *project, int display, widget_info *info)
164 {
165     widget_service_provider::SaveToProject(writer, project, display, info);
166     writer.WriteInt("tick_count", info->misc_value);
167     writer.WriteInt("minval", info->ewi.slider.gx_slider_info_min_val);
168     writer.WriteInt("maxval", info->ewi.slider.gx_slider_info_max_val);
169     writer.WriteInt("current_val", info->ewi.slider.gx_slider_info_current_val);
170     writer.WriteInt("increment", info->ewi.slider.gx_slider_info_increment);
171     writer.WriteInt("min_travel", info->ewi.slider.gx_slider_info_min_travel);
172     writer.WriteInt("max_travel", info->ewi.slider.gx_slider_info_max_travel);
173     writer.WriteInt("needle_width", info->ewi.slider.gx_slider_info_needle_width);
174     writer.WriteInt("needle_height", info->ewi.slider.gx_slider_info_needle_height);
175     writer.WriteInt("needle_inset", info->ewi.slider.gx_slider_info_needle_inset);
176     writer.WriteInt("needle_hotspot", info->ewi.slider.gx_slider_info_needle_hotspot_offset);
177 }
178 
ReadFromProject(xml_reader & reader,studiox_project * project,int display,widget_info * info,ULONG valid_styles)179 void slider_service_provider::ReadFromProject(xml_reader &reader, studiox_project *project, int display, widget_info *info, ULONG valid_styles)
180 {
181     valid_styles |= GX_STYLE_SHOW_NEEDLE|GX_STYLE_SHOW_TICKMARKS|GX_STYLE_SLIDER_VERTICAL;
182 
183     widget_service_provider::ReadFromProject(reader, project, display, info, valid_styles);
184     if (project->mHeader.project_version <= 54)
185     {
186         //selected fill color of slider is start been used after project version 5.4.0
187         //set selected fill color to normal fill color incase broken old projects
188         info->color_id[SELECTED_FILL_COLOR_INDEX] = info->color_id[NORMAL_FILL_COLOR_INDEX];
189     }
190     reader.ReadInt("tick_count", info->misc_value, 10);
191     reader.ReadInt("minval", info->ewi.slider.gx_slider_info_min_val);
192     reader.ReadInt("maxval", info->ewi.slider.gx_slider_info_max_val);
193     reader.ReadInt("current_val", info->ewi.slider.gx_slider_info_current_val);
194     reader.ReadInt("increment", info->ewi.slider.gx_slider_info_increment);
195     reader.ReadValue("min_travel", info->ewi.slider.gx_slider_info_min_travel);
196     reader.ReadValue("max_travel", info->ewi.slider.gx_slider_info_max_travel);
197 
198     reader.ReadValue("needle_width", info->ewi.slider.gx_slider_info_needle_width);
199     reader.ReadValue("needle_height", info->ewi.slider.gx_slider_info_needle_height);
200 
201     reader.ReadValue("needle_inset", info->ewi.slider.gx_slider_info_needle_inset);
202     reader.ReadValue("needle_hotspot", info->ewi.slider.gx_slider_info_needle_hotspot_offset);
203 }
204