1 
2 #include "studiox_includes.h"
3 
4 #ifdef _DEBUG
5 #define new DEBUG_NEW
6 #endif
7 
8 ///////////////////////////////////////////////////////////////////////////////
window_service_provider()9 window_service_provider::window_service_provider()
10 {
11 }
12 
13 ///////////////////////////////////////////////////////////////////////////////
GetVarDeclaration()14 CString window_service_provider::GetVarDeclaration()
15 {
16     return CString("GX_WINDOW_MEMBERS_DECLARE");
17 }
18 
19 ///////////////////////////////////////////////////////////////////////////////
DeclarePropertiesStruct()20 CString window_service_provider::DeclarePropertiesStruct()
21 {
22     CString out(""
23     "typedef struct\n"
24     "{\n"
25     "    GX_RESOURCE_ID wallpaper_id;\n"
26     "} GX_WINDOW_PROPERTIES;\n\n");
27     return out;
28 }
29 
30 ///////////////////////////////////////////////////////////////////////////////
WriteExtendedProperties(screen_generator * gen,CString & prefix,widget_info * info)31 CString window_service_provider::WriteExtendedProperties(screen_generator *gen, CString &prefix, widget_info *info)
32 {
33     CString out;
34     CString propname = prefix + info->app_name;
35     out.Format(_T("GX_WINDOW_PROPERTIES %s_properties =\n")
36         _T("{\n")
37         _T("    %s  /* wallpaper pixelmap id */\n};\n"),
38         propname,
39         gen->GetPixelmapIdName(info->pixelmap_id[WALLPAPER_PIXELMAP_INDEX]));
40     return out;
41 }
42 
43 ///////////////////////////////////////////////////////////////////////////////
GetCreateFromDefFunctionName()44 CString window_service_provider::GetCreateFromDefFunctionName()
45 {
46     return CString("gx_studio_window_create");
47 }
48 
49 ///////////////////////////////////////////////////////////////////////////////
GetCreateFromDefFunction(int version)50 CString window_service_provider::GetCreateFromDefFunction(int version)
51 {
52     CString out;
53     MakeCreatePreamble("window", version, out);
54 
55     out +="{\n"
56         "    UINT status;\n"
57         "    GX_WINDOW *window = (GX_WINDOW *) control_block;\n"
58         "    GX_WINDOW_PROPERTIES *props = (GX_WINDOW_PROPERTIES *) info->properties;\n"
59         "    status = gx_window_create(window, info->widget_name, parent, info->style, info->widget_id, &info->size);\n"
60         "    if (status == GX_SUCCESS)\n"
61         "    {\n"
62         "        if (props->wallpaper_id)\n"
63         "        {\n"
64         "            gx_window_wallpaper_set(window, props->wallpaper_id, info->style & GX_STYLE_TILE_WALLPAPER);\n"
65         "        }\n"
66         "    }\n"
67         "    return status;\n"
68         "}\n";
69     return out;
70 }
71 
72 
73 ///////////////////////////////////////////////////////////////////////////////
CreateNewInstance(GX_WIDGET * parent)74 widget_info *window_service_provider::CreateNewInstance(GX_WIDGET *parent)
75 {
76     int parent_size;
77 
78     GX_RECTANGLE size = parent->gx_widget_size;
79 
80     if (parent->gx_widget_type != GX_TYPE_ROOT_WINDOW)
81     {
82         gx_utility_rectangle_define(&size, 0, 0, 79, 23);
83         parent_size = (parent->gx_widget_size.gx_rectangle_right -
84                        parent->gx_widget_size.gx_rectangle_left) / 2;
85         size.gx_rectangle_right = size.gx_rectangle_left + parent_size;
86 
87         parent_size = (parent->gx_widget_size.gx_rectangle_bottom -
88                        parent->gx_widget_size.gx_rectangle_top) / 2;
89         size.gx_rectangle_bottom = size.gx_rectangle_top + parent_size;
90 
91         gx_utility_rectangle_center(&size, &parent->gx_widget_size);
92     }
93 
94     GX_WINDOW *window = new GX_WINDOW;
95     gx_window_create(window, "window", parent,
96         GX_STYLE_ENABLED | GX_STYLE_BORDER_THIN, 0, &size);
97     gx_widget_style_remove(window, GX_STYLE_DRAW_SELECTED);
98     widget_info *info = InitWidgetInfo((GX_WIDGET *) window);
99     info->pixelmap_id[WALLPAPER_PIXELMAP_INDEX] = 0;
100 
101     return info;
102 }
103 
104 ///////////////////////////////////////////////////////////////////////////////
GenerateFromInfo(GX_WIDGET * parent,widget_info * info)105 GX_WIDGET *window_service_provider::GenerateFromInfo(GX_WIDGET *parent, widget_info *info)
106 {
107     GX_WINDOW *win = new GX_WINDOW;
108     gx_window_create(win,
109         (CHAR *) info->app_name.GetString(),
110         parent,
111         info->style,
112         0,
113         &info->size);
114 
115     gx_widget_fill_color_set(win,
116         info->color_id[NORMAL_FILL_COLOR_INDEX],
117         info->color_id[SELECTED_FILL_COLOR_INDEX],
118         info->color_id[DISABLED_FILL_COLOR_INDEX]);
119 
120     if (info->pixelmap_id[WALLPAPER_PIXELMAP_INDEX] > 0)
121     {
122         BOOL tile = FALSE;
123 
124         if (info->style & GX_STYLE_TILE_WALLPAPER)
125         {
126             tile = TRUE;
127         }
128         gx_window_wallpaper_set(win, info->pixelmap_id[WALLPAPER_PIXELMAP_INDEX], tile);
129     }
130     return ((GX_WIDGET *) win);
131 }
132 
133 ///////////////////////////////////////////////////////////////////////////////
SaveToProject(xml_writer & writer,studiox_project * project,int display,widget_info * info)134 void window_service_provider::SaveToProject(xml_writer &writer, studiox_project *project, int display, widget_info *info)
135 {
136     widget_service_provider::SaveToProject(writer, project, display, info);
137     WritePixelmapId(writer, project, display, "wallpaper", info->pixelmap_id[WALLPAPER_PIXELMAP_INDEX]);
138 }
139 
140 ///////////////////////////////////////////////////////////////////////////////
ReadFromProject(xml_reader & reader,studiox_project * project,int display,widget_info * info,ULONG valid_styles)141 void window_service_provider::ReadFromProject(xml_reader &reader, studiox_project *project, int display, widget_info *info, ULONG valid_styles)
142 {
143     valid_styles |= GX_STYLE_TILE_WALLPAPER;
144 
145     widget_service_provider::ReadFromProject(reader, project, display, info, valid_styles);
146     info->pixelmap_id[WALLPAPER_PIXELMAP_INDEX] = ReadPixelmapId(reader, project, display, "wallpaper");
147 
148     if (project->mHeader.project_version <= 54)
149     {
150         //selected fill color is enabled after version 5.4.0
151         info->color_id[SELECTED_FILL_COLOR_INDEX] = info->color_id[NORMAL_FILL_COLOR_INDEX];
152     }
153 }
154 
155 ///////////////////////////////////////////////////////////////////////////////
AssignPixelmap(widget_info * info,int index,GX_RESOURCE_ID pixmap_id)156 void window_service_provider::AssignPixelmap(widget_info *info, int index,
157     GX_RESOURCE_ID pixmap_id)
158 {
159     GX_WINDOW *window = (GX_WINDOW *) (info->widget);
160 
161     switch(index)
162     {
163     case WALLPAPER_PIXELMAP_INDEX:
164         info->pixelmap_id[WALLPAPER_PIXELMAP_INDEX] = pixmap_id;
165 
166         if (window)
167         {
168             gx_window_wallpaper_set(window, pixmap_id, info->style & GX_STYLE_TILE_WALLPAPER);
169         }
170         break;
171 
172     default:
173         break;
174     }
175 }
176 
177 ///////////////////////////////////////////////////////////////////////////////
Autosize(widget_info * info)178 void window_service_provider::Autosize(widget_info *info)
179 {
180     if (info->pixelmap_id[0] &&
181         !(info->style & GX_STYLE_TILE_WALLPAPER))
182     {
183         CheckResizeToPixelmap(info, RESIZE_MODE_ALL);
184     }
185 }