1 
2 #include "studiox_includes.h"
3 
4 #ifdef _DEBUG
5 #define new DEBUG_NEW
6 #endif
7 
generic_scroll_wheel_service_provider()8 generic_scroll_wheel_service_provider::generic_scroll_wheel_service_provider()
9 {
10 }
11 
GetVarDeclaration()12 CString generic_scroll_wheel_service_provider::GetVarDeclaration()
13 {
14     return CString("GX_GENERIC_SCROLL_WHEEL_MEMBERS_DECLARE");
15 }
16 
DeclarePropertiesStructContent()17 CString generic_scroll_wheel_service_provider::DeclarePropertiesStructContent()
18 {
19     CString out;
20 
21     out =
22         "    int             total_rows;\n"
23         "    int             selected_row;\n"
24         "    GX_VALUE        row_height;\n"
25         "    GX_UBYTE        start_alpha;\n"
26         "    GX_UBYTE        end_alpha;\n"
27         "    GX_RESOURCE_ID  wallpaper_id;\n"
28         "    GX_RESOURCE_ID  selected_background;\n"
29         "    VOID          (*callback)(GX_GENERIC_SCROLL_WHEEL *, GX_WIDGET *, INT);\n";
30 
31     return out;
32 }
33 
DeclarePropertiesStruct()34 CString generic_scroll_wheel_service_provider::DeclarePropertiesStruct()
35 {
36     CString out;
37     out.Format(_T("typedef struct\n")
38         _T("{\n")
39         _T("%s\n")
40         _T("} GX_GENERIC_SCROLL_WHEEL_PROPERTIES;\n\n"),
41         DeclarePropertiesStructContent());
42     return out;
43 }
44 
WriteExtendedPropertiesContent(screen_generator * gen,widget_info * info,BOOL add_last_comma)45 CString generic_scroll_wheel_service_provider::WriteExtendedPropertiesContent(screen_generator *gen, widget_info *info, BOOL add_last_comma)
46 {
47     CString out;
48     CString last_delimiter;
49     CString callback;
50 
51     if (info->callback_func.IsEmpty())
52     {
53         callback = "GX_NULL";
54     }
55     else
56     {
57         callback = info->callback_func;
58     }
59 
60     if (add_last_comma)
61     {
62         last_delimiter = ",";
63     }
64     else
65     {
66         last_delimiter = " ";
67     }
68 
69     out.Format(
70         _T("    %d, /* total rows */\n")
71         _T("    %d, /* selected row */\n")
72         _T("    %d, /* row height */\n")
73         _T("    %d, /* start alpha */\n")
74         _T("    %d, /* end alpha */\n")
75         _T("    %s, /* wallpaper id */\n")
76         _T("    %s, /* selected background */\n")
77         _T("    %s%s /* callback function */"),
78         info->ewi.scroll_wheel.total_rows,
79         info->ewi.scroll_wheel.selected_row,
80         info->ewi.scroll_wheel.row_height,
81         info->ewi.scroll_wheel.start_alpha,
82         info->ewi.scroll_wheel.end_alpha,
83         gen->GetPixelmapIdName(info->pixelmap_id[WALLPAPER_PIXELMAP_INDEX]),
84         gen->GetPixelmapIdName(info->pixelmap_id[SCROLL_WHEEL_PIXELMAP_INDEX]),
85         callback, last_delimiter);
86 
87     return out;
88 }
89 
WriteExtendedProperties(screen_generator * gen,CString & prefix,widget_info * info)90 CString generic_scroll_wheel_service_provider::WriteExtendedProperties(screen_generator *gen, CString &prefix, widget_info *info)
91 {
92     CString out;
93     CString propname = prefix + info->app_name;
94 
95     out.Format(_T("GX_GENERIC_SCROLL_WHEEL_PROPERTIES %s_properties =\n")
96         _T("{\n")
97         _T("%s\n")
98         _T("};\n"),
99         propname,
100         WriteExtendedPropertiesContent(gen, info, TRUE));
101 
102     return out;
103 }
104 
105 
GetCreateFromDefFunctionName()106 CString generic_scroll_wheel_service_provider::GetCreateFromDefFunctionName()
107 {
108     return CString("gx_studio_generic_scroll_wheel_create");
109 }
110 
GetCreateFromDefFunction(int version)111 CString generic_scroll_wheel_service_provider::GetCreateFromDefFunction(int version)
112 {
113     CString out;
114     MakeCreatePreamble("generic_scroll_wheel", version, out);
115 
116     out += "{\n"
117         "    UINT status;\n"
118         "    GX_GENERIC_SCROLL_WHEEL *wheel = (GX_GENERIC_SCROLL_WHEEL *) control_block;\n"
119         "    GX_GENERIC_SCROLL_WHEEL_PROPERTIES *props = (GX_GENERIC_SCROLL_WHEEL_PROPERTIES *) info->properties;\n"
120         "    status = gx_generic_scroll_wheel_create(wheel, info->widget_name, parent, props->total_rows, props->callback, \n"
121         "                                           info->style, info->widget_id, &info->size);\n"
122         "    if (status == GX_SUCCESS)\n"
123         "    {\n"
124         "        if (props->wallpaper_id)\n"
125         "        {\n"
126         "            gx_window_wallpaper_set((GX_WINDOW *) wheel, props->wallpaper_id, info->style & GX_STYLE_TILE_WALLPAPER);\n"
127         "        }\n"
128         "        if(props->selected_background)\n"
129         "        {\n"
130         "            gx_scroll_wheel_selected_background_set((GX_SCROLL_WHEEL *)wheel, props->selected_background);\n"
131         "        }\n"
132         "        gx_scroll_wheel_selected_set((GX_SCROLL_WHEEL *)wheel, props->selected_row);\n"
133         "        gx_scroll_wheel_gradient_alpha_set((GX_SCROLL_WHEEL *)wheel, props->start_alpha, props->end_alpha);\n"
134         "        gx_generic_scroll_wheel_row_height_set(wheel, props->row_height);\n";
135 
136     out += "    }\n"
137         "    return status;\n"
138         "}\n";
139     return out;
140 }
141 
142 
CreateNewInstance(GX_WIDGET * parent)143 widget_info* generic_scroll_wheel_service_provider::CreateNewInstance(GX_WIDGET *parent)
144 {
145     int parent_size;
146 
147     GX_RECTANGLE size = parent->gx_widget_size;
148     gx_utility_rectangle_define(&size, 0, 0, 79, 23);
149     parent_size = (parent->gx_widget_size.gx_rectangle_right -
150         parent->gx_widget_size.gx_rectangle_left) / 2;
151     size.gx_rectangle_right = size.gx_rectangle_left + parent_size;
152 
153     parent_size = (parent->gx_widget_size.gx_rectangle_bottom -
154         parent->gx_widget_size.gx_rectangle_top) / 2;
155     size.gx_rectangle_bottom = size.gx_rectangle_top + parent_size;
156 
157     gx_utility_rectangle_center(&size, &parent->gx_widget_size);
158 
159     GX_GENERIC_SCROLL_WHEEL* wheel = new GX_GENERIC_SCROLL_WHEEL;
160     gx_generic_scroll_wheel_create(wheel, "generic_scroll_wheel", parent, 0, GX_NULL,
161         GX_STYLE_ENABLED | GX_STYLE_BORDER_THIN , 0, &size);
162 
163     widget_info* info = InitWidgetInfo((GX_WIDGET*)wheel);
164     info->pixelmap_id[WALLPAPER_PIXELMAP_INDEX] = 0;
165     info->ewi.scroll_wheel.start_alpha = wheel->gx_scroll_wheel_gradient.gx_gradient_alpha_start;
166     info->ewi.scroll_wheel.end_alpha = wheel->gx_scroll_wheel_gradient.gx_gradient_alpha_end;
167     info->ewi.scroll_wheel.row_height = wheel->gx_scroll_wheel_row_height;
168     info->ewi.scroll_wheel.selected_row = wheel->gx_scroll_wheel_selected_row;
169     info->ewi.scroll_wheel.total_rows = 0;
170 
171     return info;
172 }
173 
GenerateFromInfo(GX_WIDGET * parent,widget_info * info)174 GX_WIDGET* generic_scroll_wheel_service_provider::GenerateFromInfo(GX_WIDGET *parent, widget_info *info)
175 {
176     GX_GENERIC_SCROLL_WHEEL* wheel = new GX_GENERIC_SCROLL_WHEEL;
177 
178     // Create scroll wheel widget.
179     gx_generic_scroll_wheel_create(wheel,
180         (CHAR*)info->app_name.GetString(),
181         parent,
182         info->ewi.scroll_wheel.total_rows,
183         GX_NULL,
184         info->style,
185         0,
186         &info->size);
187 
188     // Set fill color.
189     gx_widget_fill_color_set(wheel,
190         info->color_id[NORMAL_FILL_COLOR_INDEX],
191         info->color_id[SELECTED_FILL_COLOR_INDEX],
192         info->color_id[DISABLED_FILL_COLOR_INDEX]);
193 
194     // Set wallpaper.
195     if (info->pixelmap_id[WALLPAPER_PIXELMAP_INDEX] > 0)
196     {
197         BOOL tile = FALSE;
198 
199         if (info->style & GX_STYLE_TILE_WALLPAPER)
200         {
201             tile = TRUE;
202         }
203         gx_window_wallpaper_set((GX_WINDOW*)wheel, info->pixelmap_id[WALLPAPER_PIXELMAP_INDEX], tile);
204     }
205 
206     // Set selected row background.
207     if (info->pixelmap_id[SCROLL_WHEEL_PIXELMAP_INDEX] > 0)
208     {
209         gx_scroll_wheel_selected_background_set((GX_SCROLL_WHEEL*)wheel, info->pixelmap_id[SCROLL_WHEEL_PIXELMAP_INDEX]);
210     }
211 
212     // Set scroll wheel properties.
213     gx_scroll_wheel_gradient_alpha_set(wheel, info->ewi.scroll_wheel.start_alpha, info->ewi.scroll_wheel.end_alpha);
214     gx_scroll_wheel_row_height_set(wheel, info->ewi.scroll_wheel.row_height);
215     gx_scroll_wheel_selected_set(wheel, info->ewi.scroll_wheel.selected_row);
216 
217     return (GX_WIDGET*)wheel;
218 }
219 
SaveToProject(xml_writer & writer,studiox_project * project,int display,widget_info * info)220 void generic_scroll_wheel_service_provider::SaveToProject(xml_writer &writer, studiox_project *project, int display, widget_info *info)
221 {
222     scroll_wheel_service_provider::SaveToProject(writer, project, display, info);
223 
224     writer.WriteString("callback", info->callback_func);
225 }
226 
ReadFromProject(xml_reader & reader,studiox_project * project,int display,widget_info * info,ULONG valid_styles)227 void generic_scroll_wheel_service_provider::ReadFromProject(xml_reader &reader, studiox_project *project, int display, widget_info *info, ULONG valid_styles)
228 {
229     scroll_wheel_service_provider::ReadFromProject(reader, project, display, info, valid_styles);
230 
231     reader.ReadString("callback", info->callback_func);
232 }
233 
AssignScrollWheelInfo(widget_info * info,scroll_wheel_info * wheel_info)234 void generic_scroll_wheel_service_provider::AssignScrollWheelInfo(widget_info *info, scroll_wheel_info *wheel_info)
235 {
236     GX_GENERIC_SCROLL_WHEEL* wheel = (GX_GENERIC_SCROLL_WHEEL*)(info->widget);
237 
238     info->ewi.scroll_wheel = *wheel_info;
239 
240     if (wheel)
241     {
242         gx_scroll_wheel_gradient_alpha_set(wheel, wheel_info->start_alpha, wheel_info->end_alpha);
243         gx_generic_scroll_wheel_row_height_set(wheel, wheel_info->row_height);
244 
245         gx_scroll_wheel_selected_set(wheel, wheel_info->selected_row);
246 
247         if (wheel_info->total_rows > 0)
248         {
249             gx_generic_scroll_wheel_total_rows_set(wheel, wheel_info->total_rows);
250         }
251     }
252 }