1 
2 #include "studiox_includes.h"
3 
4 #ifdef _DEBUG
5 #define new DEBUG_NEW
6 #endif
7 
pixelmap_button_service_provider()8 pixelmap_button_service_provider::pixelmap_button_service_provider()
9 {
10 }
11 
GetVarDeclaration()12 CString pixelmap_button_service_provider::GetVarDeclaration()
13 {
14     return CString("GX_PIXELMAP_BUTTON_MEMBERS_DECLARE");
15 }
16 
DeclarePropertiesStruct()17 CString pixelmap_button_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_RESOURCE_ID disabled_pixelmap_id;\n"
25     "} GX_PIXELMAP_BUTTON_PROPERTIES;\n\n");
26 
27     return out;
28 }
29 
WriteExtendedProperties(screen_generator * gen,CString & prefix,widget_info * info)30 CString pixelmap_button_service_provider::WriteExtendedProperties(screen_generator *gen, CString &prefix, widget_info *info)
31 {
32     CString out;
33     CString propname = prefix + info->app_name;
34     out.Format(_T("GX_PIXELMAP_BUTTON_PROPERTIES %s_properties =\n")
35         _T("{\n")
36         _T("    %s, /* normal pixelmap id */\n")
37         _T("    %s, /* selected pixelmap id */\n")
38         _T("    %s  /* disabled pixelmap id */\n")
39         _T("};\n"),
40         propname,
41         gen->GetPixelmapIdName(info->pixelmap_id[NORMAL_PIXELMAP_INDEX]),
42         gen->GetPixelmapIdName(info->pixelmap_id[SELECTED_PIXELMAP_INDEX]),
43         gen->GetPixelmapIdName(info->pixelmap_id[DISABLED_PIXELMAP_INDEX]));
44     return out;
45 }
46 
GetCreateFromDefFunctionName()47 CString pixelmap_button_service_provider::GetCreateFromDefFunctionName()
48 {
49     return CString("gx_studio_pixelmap_button_create");
50 }
51 
GetCreateFromDefFunction(int version)52 CString pixelmap_button_service_provider::GetCreateFromDefFunction(int version)
53 {
54     CString out;
55     MakeCreatePreamble("pixelmap_button", version, out);
56 
57     out += "{\n"
58         "    UINT status;\n"
59         "    GX_PIXELMAP_BUTTON *button = (GX_PIXELMAP_BUTTON *) control_block;\n"
60         "    GX_PIXELMAP_BUTTON_PROPERTIES *props = (GX_PIXELMAP_BUTTON_PROPERTIES *) info->properties;\n"
61         "    status = gx_pixelmap_button_create(button, info->widget_name, parent,\n"
62         "               props->normal_pixelmap_id,\n"
63         "               props->selected_pixelmap_id,\n"
64         "               props->disabled_pixelmap_id,\n"
65         "               info->style, info->widget_id, &info->size);\n"
66         "    return status;\n"
67         "}\n";
68     return out;
69 }
70 
CreateNewInstance(GX_WIDGET * parent)71 widget_info *pixelmap_button_service_provider::CreateNewInstance(GX_WIDGET *parent)
72 {
73     GX_RECTANGLE size;
74     gx_utility_rectangle_define(&size, 0, 0, 79, 23);
75     gx_utility_rectangle_center(&size, &parent->gx_widget_size);
76 
77     GX_PIXELMAP_BUTTON *button = new GX_PIXELMAP_BUTTON;
78     gx_pixelmap_button_create(button, "pixelmap_button", parent,
79         0, 0, 0, GX_STYLE_ENABLED, 0, &size);
80     widget_info *info = InitWidgetInfo((GX_WIDGET *) button);
81     info->pixelmap_id[DISABLED_PIXELMAP_INDEX] = 0;
82     info->pixelmap_id[NORMAL_PIXELMAP_INDEX] = 0;
83     info->pixelmap_id[SELECTED_PIXELMAP_INDEX] = 0;
84     return info;
85 }
86 
GenerateFromInfo(GX_WIDGET * parent,widget_info * info)87 GX_WIDGET *pixelmap_button_service_provider::GenerateFromInfo(GX_WIDGET *parent, widget_info *info)
88 {
89     GX_PIXELMAP_BUTTON *button = new GX_PIXELMAP_BUTTON;
90 
91     gx_pixelmap_button_create(button,
92         (CHAR *) info->app_name.GetString(),
93         parent,
94         info->pixelmap_id[NORMAL_PIXELMAP_INDEX],
95         info->pixelmap_id[SELECTED_PIXELMAP_INDEX],
96         info->pixelmap_id[DISABLED_PIXELMAP_INDEX],
97         info->style, 0, &info->size);
98 
99     gx_widget_fill_color_set((GX_WIDGET *) button,
100         info->color_id[NORMAL_FILL_COLOR_INDEX], info->color_id[SELECTED_FILL_COLOR_INDEX], info->color_id[DISABLED_FILL_COLOR_INDEX]);
101     return ((GX_WIDGET *) button);
102 }
103 
SaveToProject(xml_writer & writer,studiox_project * project,int display,widget_info * info)104 void pixelmap_button_service_provider::SaveToProject(xml_writer &writer, studiox_project *project, int display, widget_info *info)
105 {
106     button_service_provider::SaveToProject(writer, project, display, info);
107     WritePixelmapId(writer, project, display, "normal_pixelmap", info->pixelmap_id[NORMAL_PIXELMAP_INDEX]);
108     WritePixelmapId(writer, project, display, "selected_pixelmap", info->pixelmap_id[SELECTED_PIXELMAP_INDEX]);
109     WritePixelmapId(writer, project, display, "disabled_pixelmap", info->pixelmap_id[DISABLED_PIXELMAP_INDEX]);
110 }
111 
ReadFromProject(xml_reader & reader,studiox_project * project,int display,widget_info * info,ULONG valid_styles)112 void pixelmap_button_service_provider::ReadFromProject(xml_reader &reader, studiox_project *project, int display, widget_info *info, ULONG valid_styles)
113 {
114     valid_styles |= GX_PIXELMAP_HALIGN_MASK|GX_PIXELMAP_VALIGN_MASK;
115     button_service_provider::ReadFromProject(reader, project, display, info, valid_styles);
116     info->pixelmap_id[NORMAL_PIXELMAP_INDEX] = ReadPixelmapId(reader, project, display, "normal_pixelmap");
117     info->pixelmap_id[SELECTED_PIXELMAP_INDEX] = ReadPixelmapId(reader, project, display, "selected_pixelmap");
118     info->pixelmap_id[DISABLED_PIXELMAP_INDEX] = ReadPixelmapId(reader, project, display, "disabled_pixelmap");
119 }
120 
121 
AssignPixelmap(widget_info * info,int index,GX_RESOURCE_ID pixmap_id)122 void pixelmap_button_service_provider::AssignPixelmap(widget_info *info, int index,
123     GX_RESOURCE_ID pixmap_id)
124 {
125     GX_PIXELMAP_BUTTON *pb = (GX_PIXELMAP_BUTTON *) (info->widget);
126 
127     switch(index)
128     {
129     case NORMAL_PIXELMAP_INDEX:
130         info->pixelmap_id[NORMAL_PIXELMAP_INDEX] = pixmap_id;
131 
132         if (pb)
133         {
134             gx_pixelmap_button_pixelmap_set(pb, pixmap_id,
135                 pb->gx_pixelmap_button_selected_id,
136                 pb->gx_pixelmap_button_disabled_id);
137         }
138         break;
139 
140     case SELECTED_PIXELMAP_INDEX:
141         info->pixelmap_id[SELECTED_PIXELMAP_INDEX] = pixmap_id;
142 
143         if (pb)
144         {
145             gx_pixelmap_button_pixelmap_set(pb,
146                 pb->gx_pixelmap_button_normal_id,
147                 pixmap_id,
148                 pb->gx_pixelmap_button_disabled_id);
149         }
150         break;
151 
152     case DISABLED_PIXELMAP_INDEX:
153         info->pixelmap_id[DISABLED_PIXELMAP_INDEX] = pixmap_id;
154 
155         if (pb)
156         {
157             gx_pixelmap_button_pixelmap_set(pb,
158                 pb->gx_pixelmap_button_normal_id,
159                 pb->gx_pixelmap_button_selected_id,
160                 pixmap_id);
161         }
162         break;
163     }
164 }
165 
Autosize(widget_info * info)166 void pixelmap_button_service_provider::Autosize(widget_info *info)
167 {
168     CheckResizeToPixelmap(info, RESIZE_MODE_ALL);
169 }
170