1 
2 #include "studiox_includes.h"
3 
4 #ifdef _DEBUG
5 #define new DEBUG_NEW
6 #endif
7 
8 ///////////////////////////////////////////////////////////////////////////////
ReadOneWidget(xml_reader & reader,studiox_project * project,int display)9 widget_info *widget_reader::ReadOneWidget(xml_reader &reader, studiox_project *project, int display)
10 {
11     CString widget_type_name;
12     widget_info *info = NULL;
13 
14     reader.ReadString("type", widget_type_name);
15     int widget_type = widget_factory::WidgetStringToType(widget_type_name);
16 
17     widget_service_provider *provider = widget_factory::GetServiceProvider(widget_type);
18 
19     if (provider)
20     {
21         info = new widget_info(widget_type);
22         provider->ReadFromProject(reader, project, display, info, 0);
23 
24         if (!info->id_name.IsEmpty())
25         {
26             /* Add id name to id dictionary. */
27             project->AddToIdDictionary(display, ID_TYPE_WIDGET, info->id_name);
28         }
29     }
30     else
31     {
32         ErrorMsg("Unknown widget type in project");
33     }
34 
35     return info;
36 }
37 
38 ///////////////////////////////////////////////////////////////////////////////
ReadChildWidgets(xml_reader & reader,studiox_project * project,int display,widget_info * parent)39 void widget_reader::ReadChildWidgets(xml_reader &reader, studiox_project *project, int display, widget_info *parent)
40 {
41     widget_info *widget = NULL;
42     widget_info *previous = NULL;
43 
44     while (reader.EnterSection(CT2A(widget_factory::WidgetTypeToString(GX_TYPE_WIDGET))))
45     {
46         widget = ReadOneWidget(reader, project, display);
47 
48         if (widget)
49         {
50             if (previous)
51             {
52                 previous->SetNextWidgetInfo(widget);
53             }
54             else
55             {
56                 parent->SetChildWidgetInfo(widget);
57             }
58             ReadChildWidgets(reader, project, display, widget);
59             previous = widget;
60         }
61 
62         reader.CloseSection(TRUE, TRUE);
63     }
64 }
65 
66 ///////////////////////////////////////////////////////////////////////////////
ReadWidgets(xml_reader & reader,studiox_project * project,int display,folder_info * widgets_folder)67 void widget_reader::ReadWidgets(xml_reader &reader, studiox_project *project, int display, folder_info *widgets_folder)
68 {
69     CString widget_type_name;
70     widget_info *widget = NULL;
71     widget_info *previous = NULL;
72 
73     while (reader.EnterSection(CT2A(widget_factory::WidgetTypeToString(GX_TYPE_WIDGET))))
74     {
75         widget = ReadOneWidget(reader, project, display);
76 
77         if (widget)
78         {
79             if (previous)
80             {
81                 previous->SetNextWidgetInfo(widget);
82             }
83             else
84             {
85                 widgets_folder->SetFirstChildWidget(widget);
86             }
87             ReadChildWidgets(reader, project, display, widget);
88             previous = widget;
89 
90             /* This is a check to repair templates that were previously allowed to be marked as
91                dynamically allocated
92             */
93 
94             if (widget->is_template)
95             {
96                 if (widget->allocation != STATICALLY_ALLOCATED)
97                 {
98                     widget->allocation = STATICALLY_ALLOCATED;
99                     properties_win::SetChildAllocation(widget->GetChildWidgetInfo(), STATICALLY_ALLOCATED);
100                 }
101             }
102         }
103         reader.CloseSection(TRUE, TRUE);
104     }
105 }
106 
107 
108 
109 ///////////////////////////////////////////////////////////////////////////////
ReadWidgetFolders(xml_reader & reader,studiox_project * project,int display)110 void widget_reader::ReadWidgetFolders(xml_reader &reader, studiox_project *project, int display)
111 {
112     CString widget_type_name;
113     folder_info *folder = NULL;
114     folder_info *previous = NULL;
115     display_info *info = &project->mDisplays[display];
116 
117     while (reader.EnterSection("widget_folder"))
118     {
119         CString name;
120         reader.ReadString("folder_name", name);
121         folder = new folder_info(name);
122 
123         if (previous)
124         {
125             previous->SetNextFolder(folder);
126         }
127         else
128         {
129             info->SetFirstChildFolder(folder);
130         }
131         previous = folder;
132         reader.ReadString("specified_output_name", name);
133         folder->output_filename = name;
134         ReadWidgets(reader, project, display, folder);
135         reader.CloseSection(TRUE, TRUE);
136     }
137 }