1 
2 #include "studiox_includes.h"
3 
4 #ifdef _DEBUG
5 #define new DEBUG_NEW
6 #endif
7 
pixelmap_slider_service_provider()8 pixelmap_slider_service_provider::pixelmap_slider_service_provider()
9 {
10 }
11 
DeclarePropertiesStruct()12 CString pixelmap_slider_service_provider::DeclarePropertiesStruct()
13 {
14     CString out(""
15     "typedef struct\n"
16     "{\n"
17     "    int min_val;\n"
18     "    int max_val;\n"
19     "    int current_val;\n"
20     "    int increment;\n"
21     "    GX_VALUE min_travel;\n"
22     "    GX_VALUE max_travel;\n"
23     "    GX_VALUE needle_width;\n"
24     "    GX_VALUE needle_height;\n"
25     "    GX_VALUE needle_inset;\n"
26     "    GX_VALUE needle_hotspot;\n"
27     "    GX_RESOURCE_ID lower_pixelmap;\n"
28     "    GX_RESOURCE_ID upper_pixelmap;\n"
29     "    GX_RESOURCE_ID needle_pixelmap;\n"
30     "} GX_PIXELMAP_SLIDER_PROPERTIES;\n\n");
31     return out;
32 }
33 
WriteExtendedProperties(screen_generator * gen,CString & prefix,widget_info * info)34 CString pixelmap_slider_service_provider::WriteExtendedProperties(screen_generator *gen, CString &prefix, widget_info *info)
35 {
36     CString out;
37     CString propname = prefix + info->app_name;
38     out.Format(_T("GX_PIXELMAP_SLIDER_PROPERTIES %s_properties =\n")
39         _T("{\n")
40         _T("    %d, /* minimum value */\n")
41         _T("    %d, /* maximum value */\n")
42         _T("    %d, /* current value */\n")
43         _T("    %d, /* increment */\n")
44         _T("    %d, /* minimum travel */\n")
45         _T("    %d, /* maximum travel */\n")
46         _T("    %d, /* needle width */\n")
47         _T("    %d, /* needle height */\n")
48         _T("    %d, /* needle inset */\n")
49         _T("    %d, /* needle hotspot */\n")
50         _T("    %s, /* lower pixelmap id */\n")
51         _T("    %s, /* upper pixelmap id */\n")
52         _T("    %s  /* needle pixelmap id */\n};\n"),
53         propname,
54         info->ewi.slider.gx_slider_info_min_val,
55         info->ewi.slider.gx_slider_info_max_val,
56         info->ewi.slider.gx_slider_info_current_val,
57         info->ewi.slider.gx_slider_info_increment,
58         info->ewi.slider.gx_slider_info_min_travel,
59         info->ewi.slider.gx_slider_info_max_travel,
60         info->ewi.slider.gx_slider_info_needle_width,
61         info->ewi.slider.gx_slider_info_needle_height,
62         info->ewi.slider.gx_slider_info_needle_inset,
63         info->ewi.slider.gx_slider_info_needle_hotspot_offset,
64         gen->GetPixelmapIdName(info->pixelmap_id[LOWER_PIXELMAP_INDEX]),
65         gen->GetPixelmapIdName(info->pixelmap_id[UPPER_PIXELMAP_INDEX]),
66         gen->GetPixelmapIdName(info->pixelmap_id[NEEDLE_PIXELMAP_INDEX]));
67     return out;
68 }
69 
GetCreateFromDefFunctionName()70 CString pixelmap_slider_service_provider::GetCreateFromDefFunctionName()
71 {
72     return CString("gx_studio_pixelmap_slider_create");
73 }
74 
GetCreateFromDefFunction(int version)75 CString pixelmap_slider_service_provider::GetCreateFromDefFunction(int version)
76 {
77     CString out;
78     MakeCreatePreamble("pixelmap_slider", version, out);
79 
80     out += "{\n"
81         "    UINT status;\n"
82         "    GX_PIXELMAP_SLIDER *slider = (GX_PIXELMAP_SLIDER *) control_block;\n"
83         "    GX_PIXELMAP_SLIDER_PROPERTIES *props = (GX_PIXELMAP_SLIDER_PROPERTIES *) info->properties;\n"
84         "    GX_PIXELMAP_SLIDER_INFO pixelmap_info;\n"
85         "    GX_SLIDER_INFO slider_info;\n"
86         "    slider_info.gx_slider_info_min_val = props->min_val;\n"
87         "    slider_info.gx_slider_info_max_val = props->max_val;\n"
88         "    slider_info.gx_slider_info_current_val = props->current_val;\n"
89         "    slider_info.gx_slider_info_increment = props->increment;\n"
90         "    slider_info.gx_slider_info_min_travel = props->min_travel;\n"
91         "    slider_info.gx_slider_info_max_travel = props->max_travel;\n"
92         "    slider_info.gx_slider_info_needle_width = props->needle_width;\n"
93         "    slider_info.gx_slider_info_needle_height = props->needle_height;\n"
94         "    slider_info.gx_slider_info_needle_inset = props->needle_inset;\n"
95         "    slider_info.gx_slider_info_needle_hotspot_offset = props->needle_hotspot;\n"
96         "    pixelmap_info.gx_pixelmap_slider_info_lower_background_pixelmap = props->lower_pixelmap;\n"
97         "    pixelmap_info.gx_pixelmap_slider_info_upper_background_pixelmap = props->upper_pixelmap;\n"
98         "    pixelmap_info.gx_pixelmap_slider_info_needle_pixelmap = props->needle_pixelmap;\n"
99         "    status = gx_pixelmap_slider_create(slider,\n"
100         "                    info->widget_name,\n"
101         "                    parent,\n"
102         "                    &slider_info,\n"
103         "                    &pixelmap_info,\n"
104         "                    info->style,\n"
105         "                    info->widget_id,\n"
106         "                    &info->size);\n"
107         "    return status;\n"
108         "}\n";
109     return out;
110 }
111 
CreateNewInstance(GX_WIDGET * parent)112 widget_info *pixelmap_slider_service_provider::CreateNewInstance(GX_WIDGET *parent)
113 {
114     GX_RECTANGLE size;
115     gx_utility_rectangle_define(&size, 0, 0, 79, 23);
116     gx_utility_rectangle_center(&size, &parent->gx_widget_size);
117 
118     GX_PIXELMAP_SLIDER *slider = new GX_PIXELMAP_SLIDER;
119     GX_PIXELMAP_SLIDER_INFO pixelmap_info;
120     GX_SLIDER_INFO slider_info;
121 
122     slider_info.gx_slider_info_min_val = 0;
123     slider_info.gx_slider_info_max_val = 100;
124     slider_info.gx_slider_info_current_val = 50;
125     slider_info.gx_slider_info_increment = 10;
126     slider_info.gx_slider_info_min_travel = 0;
127     slider_info.gx_slider_info_max_travel = 0;
128     slider_info.gx_slider_info_needle_width = 5;
129     slider_info.gx_slider_info_needle_height = 10;
130     slider_info.gx_slider_info_needle_inset = 5;
131     slider_info.gx_slider_info_needle_hotspot_offset = 2;
132 
133     pixelmap_info.gx_pixelmap_slider_info_lower_background_pixelmap = 0;
134     pixelmap_info.gx_pixelmap_slider_info_upper_background_pixelmap = 0;
135     pixelmap_info.gx_pixelmap_slider_info_needle_pixelmap = 0;
136 
137     gx_pixelmap_slider_create(slider,
138                     "pixelmap_slider",
139                     parent,
140                     &slider_info,
141                     &pixelmap_info,
142                     GX_STYLE_BORDER_RAISED|GX_STYLE_ENABLED, 0,
143                     &size);
144 
145     widget_info *info = InitWidgetInfo((GX_WIDGET *) slider);
146 
147     info->ewi.slider = slider_info;
148     return info;
149 }
150 
GenerateFromInfo(GX_WIDGET * parent,widget_info * info)151 GX_WIDGET *pixelmap_slider_service_provider::GenerateFromInfo(GX_WIDGET *parent, widget_info *info)
152 {
153     GX_PIXELMAP_SLIDER *slider = new GX_PIXELMAP_SLIDER;
154     GX_PIXELMAP_SLIDER_INFO pixelmap_info;
155 
156     pixelmap_info.gx_pixelmap_slider_info_lower_background_pixelmap = info->pixelmap_id[LOWER_PIXELMAP_INDEX];
157     pixelmap_info.gx_pixelmap_slider_info_upper_background_pixelmap = info->pixelmap_id[UPPER_PIXELMAP_INDEX];
158     pixelmap_info.gx_pixelmap_slider_info_needle_pixelmap = info->pixelmap_id[NEEDLE_PIXELMAP_INDEX];
159 
160     gx_pixelmap_slider_create(slider,
161                     (CHAR *) info->app_name.GetString(),
162                     parent,
163                     &info->ewi.slider,
164                     &pixelmap_info,
165                     info->style, 0,
166                      &info->size);
167     gx_widget_fill_color_set((GX_WIDGET *) slider,
168         info->color_id[NORMAL_FILL_COLOR_INDEX], info->color_id[SELECTED_FILL_COLOR_INDEX], info->color_id[DISABLED_FILL_COLOR_INDEX]);
169 
170     return ((GX_WIDGET *) slider);
171 }
172 
SaveToProject(xml_writer & writer,studiox_project * project,int display,widget_info * info)173 void pixelmap_slider_service_provider::SaveToProject(xml_writer &writer, studiox_project *project, int display, widget_info *info)
174 {
175     slider_service_provider::SaveToProject(writer, project, display, info);
176     WritePixelmapId(writer, project, display, "lower_pixmap", info->pixelmap_id[LOWER_PIXELMAP_INDEX]);
177     WritePixelmapId(writer, project, display, "upper_pixmap", info->pixelmap_id[UPPER_PIXELMAP_INDEX]);
178     WritePixelmapId(writer, project, display, "needle_pixmap", info->pixelmap_id[NEEDLE_PIXELMAP_INDEX]);
179 }
180 
ReadFromProject(xml_reader & reader,studiox_project * project,int display,widget_info * info,ULONG valid_styles)181 void pixelmap_slider_service_provider::ReadFromProject(xml_reader &reader, studiox_project *project, int display, widget_info *info, ULONG valid_styles)
182 {
183     valid_styles |= GX_PIXELMAP_HALIGN_MASK|GX_PIXELMAP_VALIGN_MASK|GX_STYLE_TILE_BACKGROUND;
184     slider_service_provider::ReadFromProject(reader, project, display, info, valid_styles);
185     info->pixelmap_id[LOWER_PIXELMAP_INDEX] = ReadPixelmapId(reader, project, display, "lower_pixmap");
186     info->pixelmap_id[UPPER_PIXELMAP_INDEX] = ReadPixelmapId(reader, project, display, "upper_pixmap");
187     info->pixelmap_id[NEEDLE_PIXELMAP_INDEX] = ReadPixelmapId(reader, project, display, "needle_pixmap");
188 }
189 
AssignPixelmap(widget_info * info,int index,GX_RESOURCE_ID pixmap_id)190 void pixelmap_slider_service_provider::AssignPixelmap(widget_info *info,
191     int index, GX_RESOURCE_ID pixmap_id)
192 {
193     GX_PIXELMAP_SLIDER_INFO slider_info;
194     GX_PIXELMAP_SLIDER *slider = (GX_PIXELMAP_SLIDER *) (info->widget);
195 
196     switch(index)
197     {
198     case LOWER_PIXELMAP_INDEX:
199         info->pixelmap_id[LOWER_PIXELMAP_INDEX] = pixmap_id;
200 
201         if (slider)
202         {
203             slider_info.gx_pixelmap_slider_info_lower_background_pixelmap = pixmap_id;
204             slider_info.gx_pixelmap_slider_info_needle_pixelmap = info->pixelmap_id[NEEDLE_PIXELMAP_INDEX];
205             slider_info.gx_pixelmap_slider_info_upper_background_pixelmap = info->pixelmap_id[UPPER_PIXELMAP_INDEX];
206             gx_pixelmap_slider_pixelmap_set(slider, &slider_info);
207         }
208         break;
209 
210     case UPPER_PIXELMAP_INDEX:
211         info->pixelmap_id[UPPER_PIXELMAP_INDEX] = pixmap_id;
212 
213         if (slider)
214         {
215             slider_info.gx_pixelmap_slider_info_upper_background_pixelmap = pixmap_id;
216             slider_info.gx_pixelmap_slider_info_needle_pixelmap = info->pixelmap_id[NEEDLE_PIXELMAP_INDEX];
217             slider_info.gx_pixelmap_slider_info_lower_background_pixelmap = info->pixelmap_id[LOWER_PIXELMAP_INDEX];
218             gx_pixelmap_slider_pixelmap_set(slider, &slider_info);
219         }
220         break;
221 
222     case NEEDLE_PIXELMAP_INDEX:
223         info->pixelmap_id[NEEDLE_PIXELMAP_INDEX] = pixmap_id;
224 
225         if (slider)
226         {
227             slider_info.gx_pixelmap_slider_info_needle_pixelmap = pixmap_id;
228             slider_info.gx_pixelmap_slider_info_lower_background_pixelmap = info->pixelmap_id[LOWER_PIXELMAP_INDEX];
229             slider_info.gx_pixelmap_slider_info_upper_background_pixelmap = info->pixelmap_id[UPPER_PIXELMAP_INDEX];
230             gx_pixelmap_slider_pixelmap_set(slider, &slider_info);
231         }
232         break;
233     }
234 }
235 
Autosize(widget_info * info)236 void pixelmap_slider_service_provider::Autosize(widget_info *info)
237 {
238     if (info->style & GX_STYLE_SLIDER_VERTICAL)
239     {
240         CheckResizeToPixelmap(info, RESIZE_MODE_WIDTH);
241     }
242     else
243     {
244         CheckResizeToPixelmap(info, RESIZE_MODE_HEIGHT);
245     }
246 }
247