1 
2 #include "studiox_includes.h"
3 
4 #ifdef _DEBUG
5 #define new DEBUG_NEW
6 #endif
7 
drop_list_service_provider()8 drop_list_service_provider::drop_list_service_provider()
9 {
10 }
11 
GetVarDeclaration()12 CString drop_list_service_provider::GetVarDeclaration()
13 {
14     return CString("GX_DROP_LIST_MEMBERS_DECLARE");
15 }
16 
DeclarePropertiesStruct()17 CString drop_list_service_provider::DeclarePropertiesStruct()
18 {
19     CString out(""
20    "typedef struct\n"
21     "{\n"
22     "    GX_RESOURCE_ID pixelmap_id;\n"
23     "    GX_RESOURCE_ID wallpaper_id;\n"
24     "    VOID (*callback)(GX_VERTICAL_LIST *, GX_WIDGET *, INT);\n"
25     "    int total_rows;\n"
26     "    int open_height;\n"
27     "} GX_DROP_LIST_PROPERTIES;\n\n");
28     return out;
29 }
30 
WriteExtendedProperties(screen_generator * gen,CString & prefix,widget_info * info)31 CString drop_list_service_provider::WriteExtendedProperties(screen_generator *gen, CString &prefix, widget_info *info)
32 {
33     CString out;
34     CString propname = prefix + info->app_name;
35     CString callback;
36 
37     if (info->callback_func.IsEmpty())
38     {
39         callback = "GX_NULL";
40     }
41     else
42     {
43         callback = info->callback_func;
44     }
45 
46     out.Format(_T("GX_DROP_LIST_PROPERTIES %s_properties =\n")
47         _T("{\n")
48         _T("    %s, /* widget pixelmap id */\n")
49         _T("    %s, /* popup list wallpaper pixelmap id */\n")
50         _T("    %s, /* callback function */\n")
51         _T("    %d, /* total rows */\n")
52         _T("    %d  /* open height */\n};\n"),
53         propname,
54         gen->GetPixelmapIdName(info->pixelmap_id[DROP_LIST_PIXELMAP_INDEX]),
55         gen->GetPixelmapIdName(info->pixelmap_id[WALLPAPER_PIXELMAP_INDEX]),
56         callback,
57         info->ewi.drop_list.total_rows,
58         info->ewi.drop_list.open_height);
59     return out;
60 }
61 
62 
GetCreateFromDefFunctionName()63 CString drop_list_service_provider::GetCreateFromDefFunctionName()
64 {
65     return CString("gx_studio_drop_list_create");
66 }
67 
GetCreateFromDefFunction(int version)68 CString drop_list_service_provider::GetCreateFromDefFunction(int version)
69 {
70     CString out;
71     MakeCreatePreamble("drop_list", version, out);
72 
73     out += "{\n"
74         "    UINT status;\n"
75         "    GX_DROP_LIST *list = (GX_DROP_LIST *) control_block;\n"
76         "    GX_DROP_LIST_PROPERTIES *props = (GX_DROP_LIST_PROPERTIES *) info->properties;\n"
77         "    status = gx_drop_list_create(list, info->widget_name, parent,\n"
78         "                                 props->total_rows, props->open_height,\n"
79         "                                 props->callback, info->style, info->widget_id, &info->size);\n"
80         "    if (status == GX_SUCCESS)\n"
81         "    {\n"
82         "        if (props->pixelmap_id)\n"
83         "        {\n"
84         "            gx_drop_list_pixelmap_set(list, props->pixelmap_id);\n"
85         "        }\n"
86         "        if (props->wallpaper_id)\n"
87         "        {\n"
88         "            gx_window_wallpaper_set((GX_WINDOW *)&list->gx_drop_list_popup.gx_popup_list_list, props->wallpaper_id, info->style & GX_STYLE_TILE_WALLPAPER);\n"
89         "        }\n"
90         "    }\n"
91         "    return status;\n"
92         "}\n";
93     return out;
94 }
95 
96 
CreateNewInstance(GX_WIDGET * parent)97 widget_info *drop_list_service_provider::CreateNewInstance(GX_WIDGET *parent)
98 {
99     GX_RECTANGLE size;
100 
101     gx_utility_rectangle_define(&size, 0, 0, 100, 23);
102 
103     gx_utility_rectangle_center(&size, &parent->gx_widget_size);
104 
105     GX_DROP_LIST *list = new GX_DROP_LIST;
106     gx_drop_list_create(list, "drop_list", parent,
107         10, 100, NULL, GX_STYLE_ENABLED | GX_STYLE_BORDER_THIN, 0, &size);
108     widget_info *info = InitWidgetInfo((GX_WIDGET *) list);
109 
110     // keep the list box size in the info struture, along with open height
111     info->size = list -> gx_widget_size;
112     info->pixelmap_id[WALLPAPER_PIXELMAP_INDEX] = 0;
113     info->pixelmap_id[DROP_LIST_PIXELMAP_INDEX] = 0;
114     info->callback_func = CString("callback_name");
115     info->ewi.drop_list.total_rows  = 10;
116     info->ewi.drop_list.open_height = 100;
117     info->ewi.drop_list.seperation = 0;
118 
119     return info;
120 }
121 
GenerateFromInfo(GX_WIDGET * parent,widget_info * info)122 GX_WIDGET *drop_list_service_provider::GenerateFromInfo(GX_WIDGET *parent, widget_info *info)
123 {
124     GX_DROP_LIST *list = new GX_DROP_LIST;
125     gx_drop_list_create(list,
126         (CHAR *) info->app_name.GetString(),
127         parent,
128         info->ewi.drop_list.total_rows, info->ewi.drop_list.open_height, NULL,
129         info->style,
130         0,
131         &info->size);
132 
133     gx_widget_fill_color_set(list,
134         info->color_id[NORMAL_FILL_COLOR_INDEX],
135         info->color_id[SELECTED_FILL_COLOR_INDEX],
136         info->color_id[DISABLED_FILL_COLOR_INDEX]);
137 
138     if (info->pixelmap_id[DROP_LIST_PIXELMAP_INDEX] > 0)
139     {
140         gx_drop_list_pixelmap_set(list, info->pixelmap_id[DROP_LIST_PIXELMAP_INDEX]);
141     }
142 
143     if (info->pixelmap_id[WALLPAPER_PIXELMAP_INDEX] > 0)
144     {
145         BOOL tile = FALSE;
146 
147         if (info->style & GX_STYLE_TILE_WALLPAPER)
148         {
149             tile = TRUE;
150         }
151         gx_window_wallpaper_set((GX_WINDOW *)&list->gx_drop_list_popup.gx_popup_list_list, info->pixelmap_id[WALLPAPER_PIXELMAP_INDEX], tile);
152     }
153 
154     return ((GX_WIDGET *) list);
155 }
156 
SaveToProject(xml_writer & writer,studiox_project * project,int display,widget_info * info)157 void drop_list_service_provider::SaveToProject(xml_writer &writer, studiox_project *project, int display, widget_info *info)
158 {
159     window_service_provider::SaveToProject(writer, project, display, info);
160     writer.WriteInt("seperation", info->ewi.drop_list.seperation);
161     writer.WriteInt("total_rows", info->ewi.drop_list.total_rows);
162     writer.WriteInt("open_height", info->ewi.drop_list.open_height);
163     WritePixelmapId(writer, project, display, "pixelmap_id", info->pixelmap_id[DROP_LIST_PIXELMAP_INDEX]);
164     writer.WriteString("callback", info->callback_func);
165 }
166 
ReadFromProject(xml_reader & reader,studiox_project * project,int display,widget_info * info,ULONG valid_styles)167 void drop_list_service_provider::ReadFromProject(xml_reader &reader, studiox_project *project, int display, widget_info *info, ULONG valid_styles)
168 {
169     valid_styles |= GX_STYLE_TILE_BACKGROUND|GX_STYLE_CENTER_SELECTED|GX_STYLE_WRAP|GX_STYLE_FLICKABLE|GX_STYLE_REPEAT_SELECT;
170 
171     window_service_provider::ReadFromProject(reader, project, display, info, valid_styles);
172     info->pixelmap_id[DROP_LIST_PIXELMAP_INDEX] = ReadPixelmapId(reader, project, display, "pixelmap_id");
173     reader.ReadInt("seperation", info->ewi.drop_list.seperation, 0);
174     reader.ReadInt("total_rows", info->ewi.drop_list.total_rows, 10);
175     reader.ReadInt("open_height", info->ewi.drop_list.open_height, 100);
176     reader.ReadString("callback", info->callback_func);
177 }
178 
179 
AssignPixelmap(widget_info * info,int index,GX_RESOURCE_ID pixmap_id)180 void drop_list_service_provider::AssignPixelmap(widget_info *info,
181     int index, GX_RESOURCE_ID pixmap_id)
182 {
183     GX_DROP_LIST *list = (GX_DROP_LIST *) (info->widget);
184     BOOL tile = GX_FALSE;
185 
186     switch (index)
187     {
188     case DROP_LIST_PIXELMAP_INDEX:
189         info->pixelmap_id[DROP_LIST_PIXELMAP_INDEX] = pixmap_id;
190 
191         if (list)
192         {
193             if (info->style & GX_STYLE_TILE_BACKGROUND)
194             {
195                 gx_widget_style_add((GX_WIDGET *)list, GX_STYLE_TILE_BACKGROUND);
196             }
197             else
198             {
199                 gx_widget_style_remove((GX_WIDGET *)list, GX_STYLE_TILE_BACKGROUND);
200             }
201             gx_drop_list_pixelmap_set(list, info->pixelmap_id[DROP_LIST_PIXELMAP_INDEX]);
202         }
203         break;
204 
205     case WALLPAPER_PIXELMAP_INDEX:
206         info->pixelmap_id[WALLPAPER_PIXELMAP_INDEX] = pixmap_id;
207 
208         if (list)
209         {
210             if (info->style & GX_STYLE_TILE_WALLPAPER)
211             {
212                 tile = GX_TRUE;
213             }
214             gx_window_wallpaper_set((GX_WINDOW *)&list->gx_drop_list_popup.gx_popup_list_list, info->pixelmap_id[WALLPAPER_PIXELMAP_INDEX], tile);
215         }
216         break;
217 
218     default:
219         break;
220     }
221 }
222 
223 
224