+
+ module->m_state = State_Initializing;
+
+ // translate named dependencies to the normal ones first
+ if ( !module->ResolveNamedDependencies() )
+ return false;
+
+ const wxArrayClassInfo& dependencies = module->m_dependencies;
+
+ // satisfy module dependencies by loading them before the current module
+ for ( unsigned int i = 0; i < dependencies.size(); ++i )
+ {
+ wxClassInfo * cinfo = dependencies[i];
+
+ // Check if the module is already initialized
+ wxModuleList::compatibility_iterator node;
+ for ( node = initializedModules.GetFirst(); node; node = node->GetNext() )
+ {
+ if ( node->GetData()->GetClassInfo() == cinfo )
+ break;
+ }
+
+ if ( node )
+ {
+ // this dependency is already initialized, nothing to do
+ continue;
+ }
+
+ // find the module in the registered modules list
+ for ( node = m_modules.GetFirst(); node; node = node->GetNext() )
+ {
+ wxModule *moduleDep = node->GetData();
+ if ( moduleDep->GetClassInfo() == cinfo )
+ {
+ if ( !DoInitializeModule(moduleDep, initializedModules ) )
+ {
+ // failed to initialize a dependency, so fail this one too
+ return false;
+ }
+
+ break;
+ }
+ }
+
+ if ( !node )
+ {
+ wxLogError(_("Dependency \"%s\" of module \"%s\" doesn't exist."),
+ cinfo->GetClassName(),
+ module->GetClassInfo()->GetClassName());
+ return false;
+ }
+ }
+
+ if ( !module->Init() )
+ {
+ wxLogError(_("Module \"%s\" initialization failed"),
+ module->GetClassInfo()->GetClassName());
+ return false;
+ }
+
+ wxLogTrace(TRACE_MODULE, wxT("Module \"%s\" initialized"),
+ module->GetClassInfo()->GetClassName());
+
+ module->m_state = State_Initialized;
+ initializedModules.Append(module);
+
+ return true;
+}
+
+// Initialize user-defined modules
+bool wxModule::InitializeModules()
+{
+ wxModuleList initializedModules;
+
+ for ( wxModuleList::compatibility_iterator node = m_modules.GetFirst();
+ node;
+ node = node->GetNext() )
+ {
+ wxModule *module = node->GetData();
+
+ // the module could have been already initialized as dependency of
+ // another one
+ if ( module->m_state == State_Registered )
+ {
+ if ( !DoInitializeModule( module, initializedModules ) )
+ {
+ // failed to initialize all modules, so clean up the already
+ // initialized ones
+ DoCleanUpModules(initializedModules);
+
+ return false;
+ }
+ }
+ }
+
+ // remember the real initialisation order
+ m_modules = initializedModules;
+
+ return true;