1 
2 #include "studiox_includes.h"
3 
4 #ifdef _DEBUG
5 #define new DEBUG_NEW
6 #endif
7 
icon_service_provider()8 icon_service_provider::icon_service_provider()
9 {
10 }
11 
GetVarDeclaration()12 CString icon_service_provider::GetVarDeclaration()
13 {
14     return CString("GX_ICON_MEMBERS_DECLARE");
15 }
16 
DeclarePropertiesStruct()17 CString icon_service_provider::DeclarePropertiesStruct()
18 {
19     CString out(""
20     "typedef struct\n"
21     "{\n"
22     "    GX_RESOURCE_ID normal_pixelmap_id;\n"
23     "    GX_RESOURCE_ID selected_pixelmap_id;\n"
24     "} GX_ICON_PROPERTIES;\n\n");
25     return out;
26 }
27 
WriteExtendedProperties(screen_generator * gen,CString & prefix,widget_info * info)28 CString icon_service_provider::WriteExtendedProperties(screen_generator *gen, CString &prefix, widget_info *info)
29 {
30     CString out;
31     CString propname = prefix + info->app_name;
32     out.Format(_T("GX_ICON_PROPERTIES %s_properties =\n")
33         _T("{\n")
34         _T("    %s, /* normal pixelmap id */\n")
35         _T("    %s  /* selected pixelmap id */\n")
36         _T("};\n"),
37         propname,
38         gen->GetPixelmapIdName(info->pixelmap_id[NORMAL_PIXELMAP_INDEX]),
39         gen->GetPixelmapIdName(info->pixelmap_id[SELECTED_PIXELMAP_INDEX]));
40     return out;
41 }
42 
GetCreateFromDefFunctionName()43 CString icon_service_provider::GetCreateFromDefFunctionName()
44 {
45     return CString("gx_studio_icon_create");
46 }
47 
GetCreateFromDefFunction(int version)48 CString icon_service_provider::GetCreateFromDefFunction(int version)
49 {
50     CString out;
51     MakeCreatePreamble("icon", version, out);
52 
53    out += "{\n"
54         "    UINT status;\n"
55         "    GX_ICON *icon = (GX_ICON *) control_block;\n"
56         "    GX_ICON_PROPERTIES *props = (GX_ICON_PROPERTIES *) info->properties;\n"
57         "    status = gx_icon_create(icon, info->widget_name, parent, props->normal_pixelmap_id, info->style, info->widget_id, info->size.gx_rectangle_left, info->size.gx_rectangle_top);\n"
58         "    if (props->selected_pixelmap_id)\n"
59         "    {\n"
60         "        gx_icon_pixelmap_set(icon, props->normal_pixelmap_id, props->selected_pixelmap_id);\n"
61         "    }\n"
62         "    else\n"
63         "    {\n"
64         "        gx_widget_resize((GX_WIDGET *)icon, (GX_RECTANGLE *)&info->size);\n"
65         "    }\n"
66         "    return status;\n"
67         "}\n";
68     return out;
69 }
70 
CreateNewInstance(GX_WIDGET * parent)71 widget_info *icon_service_provider::CreateNewInstance(GX_WIDGET *parent)
72 {
73     GX_RECTANGLE size;
74     gx_utility_rectangle_define(&size, 0, 0, 39, 39);
75     gx_utility_rectangle_center(&size, &parent->gx_widget_size);
76 
77     GX_ICON *icon = new GX_ICON;
78     gx_icon_create(icon, "icon", parent, 0,
79         GX_STYLE_ENABLED|GX_STYLE_HALIGN_LEFT|GX_STYLE_VALIGN_TOP,
80         0, size.gx_rectangle_left, size.gx_rectangle_top);
81 
82     // the icon will be 1x1 pixels since it has no pixelmap, so make it larger
83     // so that you can actually see it.
84     gx_widget_resize((GX_WIDGET *) icon, &size);
85 
86     widget_info *info = InitWidgetInfo((GX_WIDGET *) icon);
87     info->pixelmap_id[NORMAL_PIXELMAP_INDEX] = 0;
88     info->pixelmap_id[SELECTED_PIXELMAP_INDEX] = 0;
89     return info;
90 }
91 
GenerateFromInfo(GX_WIDGET * parent,widget_info * info)92 GX_WIDGET *icon_service_provider::GenerateFromInfo(GX_WIDGET *parent, widget_info *info)
93 {
94     GX_ICON *icon = new GX_ICON;
95     gx_icon_create(icon,
96         (CHAR *) info->app_name.GetString(),
97         parent, info->pixelmap_id[NORMAL_PIXELMAP_INDEX],
98         info->style, 0,
99         info->size.gx_rectangle_left, info->size.gx_rectangle_top);
100 
101     gx_widget_resize((GX_WIDGET *) icon, &info->size);
102     gx_widget_fill_color_set((GX_WIDGET *) icon,
103         info->color_id[NORMAL_FILL_COLOR_INDEX], info->color_id[SELECTED_FILL_COLOR_INDEX], info->color_id[DISABLED_FILL_COLOR_INDEX]);
104 
105     return ((GX_WIDGET *) icon);
106 }
107 
SaveToProject(xml_writer & writer,studiox_project * project,int display,widget_info * info)108 void icon_service_provider::SaveToProject(xml_writer &writer, studiox_project *project, int display, widget_info *info)
109 {
110     widget_service_provider::SaveToProject(writer, project, display, info);
111     WritePixelmapId(writer, project, display, "normal_map_id", info->pixelmap_id[NORMAL_PIXELMAP_INDEX]);
112     WritePixelmapId(writer, project, display, "selected_map_id", info->pixelmap_id[SELECTED_PIXELMAP_INDEX]);
113 }
114 
ReadFromProject(xml_reader & reader,studiox_project * project,int display,widget_info * info,ULONG valid_styles)115 void icon_service_provider::ReadFromProject(xml_reader &reader, studiox_project *project, int display,widget_info *info, ULONG valid_styles)
116 {
117     valid_styles |= GX_PIXELMAP_HALIGN_MASK|GX_PIXELMAP_VALIGN_MASK;
118     widget_service_provider::ReadFromProject(reader, project, display, info, valid_styles);
119     info->pixelmap_id[NORMAL_PIXELMAP_INDEX] = ReadPixelmapId(reader, project, display, "normal_map_id");
120     info->pixelmap_id[SELECTED_PIXELMAP_INDEX] = ReadPixelmapId(reader, project, display, "selected_map_id");
121 
122     // Validate HALIGN and VALIGN styles, as these were added later
123 
124     if ((info->style & GX_PIXELMAP_HALIGN_MASK) == 0)
125     {
126         info->style |= GX_STYLE_HALIGN_LEFT;
127     }
128 
129     if ((info->style & GX_PIXELMAP_VALIGN_MASK) == 0)
130     {
131         info->style |= GX_STYLE_VALIGN_TOP;
132     }
133 }
134 
135 
AssignPixelmap(widget_info * info,int index,GX_RESOURCE_ID pixmap_id)136 void icon_service_provider::AssignPixelmap(widget_info *info, int index,
137     GX_RESOURCE_ID pixmap_id)
138 {
139     GX_ICON *picon = (GX_ICON *) (info->widget);
140     GX_RECTANGLE newsize;
141 
142     switch (index)
143     {
144     case NORMAL_PIXELMAP_INDEX:
145         info->pixelmap_id[NORMAL_PIXELMAP_INDEX] = pixmap_id;
146 
147         if (picon)
148         {
149             gx_icon_pixelmap_set(picon, pixmap_id,
150                 picon->gx_icon_selected_pixelmap);
151 
152         }
153         break;
154 
155     case SELECTED_PIXELMAP_INDEX:
156         info->pixelmap_id[SELECTED_PIXELMAP_INDEX] = pixmap_id;
157 
158         if (picon)
159         {
160             gx_icon_pixelmap_set(picon,
161                 picon->gx_icon_normal_pixelmap,
162                 pixmap_id);
163 
164             GetPropsWin()->WidgetWasMoved();
165             GetTargetScreen()->WidgetWasMoved(info);
166         }
167         break;
168     }
169 
170     // check to see if the icon auto-sized to the pixelmap, if so
171     // notify the properties window
172     if (picon)
173     {
174         newsize = picon->gx_widget_size;
175 
176         if (!gx_utility_rectangle_compare(&newsize, &info->size))
177         {
178             info->size = newsize;
179             GetPropsWin()->WidgetWasMoved();
180             GetTargetScreen()->WidgetWasMoved(info);
181         }
182     }
183 }
184 
Autosize(widget_info * info)185 void icon_service_provider::Autosize(widget_info *info)
186 {
187     CheckResizeToPixelmap(info, RESIZE_MODE_ALL);
188 }
189