summaryrefslogtreecommitdiff
path: root/src/bin/eolian_mono/eolian/mono/klass.hh
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2019-02-06 17:50:28 -0200
committerVitor Sousa <vitorsousa@expertisesolutions.com.br>2019-03-01 23:04:08 -0300
commitdd89eb2fd1755c2816d97f28822639e03ed38608 (patch)
tree9931650c7db8f267e88b87103fe1c9cc85e0d594 /src/bin/eolian_mono/eolian/mono/klass.hh
parent6d61ca915195a5ff4c5dc24c271d37fa22d64314 (diff)
efl-mono: Add support for Efl.Class
Efl.Class (in practice, the return from the *_class_get() functions) can be used as argument to functions, like in Efl.Object.provider_find and Efl.Ui.Widget_Factory.item_class(get/set). This commits adds support by representing Efl.Class instances as System.Type in the C# API, allowing someone to do things like: `factory.ItemClass == typeof(MyFramework.MyButton)` It also supports user-defined classes that inherit from efl classes.
Diffstat (limited to 'src/bin/eolian_mono/eolian/mono/klass.hh')
-rw-r--r--src/bin/eolian_mono/eolian/mono/klass.hh29
1 files changed, 14 insertions, 15 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/klass.hh b/src/bin/eolian_mono/eolian/mono/klass.hh
index 6c02de6..e70729b 100644
--- a/src/bin/eolian_mono/eolian/mono/klass.hh
+++ b/src/bin/eolian_mono/eolian/mono/klass.hh
@@ -347,6 +347,15 @@ struct klass
347 return false; 347 return false;
348 } 348 }
349 349
350 // Copied from nativeinherit class, used when setting up providers.
351 if(!as_generator(
352 scope_tab << "private static " << (root ? "" : "new ") << " IntPtr GetEflClassStatic()\n"
353 << scope_tab << "{\n"
354 << scope_tab << scope_tab << "return " << name_helpers::klass_get_full_name(cls) << "();\n"
355 << scope_tab << "}\n"
356 ).generate(sink, attributes::unused, inherit_cxt))
357 return false;
358
350 if(!as_generator("}\n").generate(sink, attributes::unused, inherit_cxt)) return false; 359 if(!as_generator("}\n").generate(sink, attributes::unused, inherit_cxt)) return false;
351 } 360 }
352 361
@@ -454,7 +463,7 @@ struct klass
454 << scope_tab << scope_tab << scope_tab << "if (((object)this).GetType() == typeof (" << inherit_name << "))\n" 463 << scope_tab << scope_tab << scope_tab << "if (((object)this).GetType() == typeof (" << inherit_name << "))\n"
455 << scope_tab << scope_tab << scope_tab << scope_tab << "return " << native_inherit_full_name << ".GetEflClassStatic();\n" 464 << scope_tab << scope_tab << scope_tab << scope_tab << "return " << native_inherit_full_name << ".GetEflClassStatic();\n"
456 << scope_tab << scope_tab << scope_tab << "else\n" 465 << scope_tab << scope_tab << scope_tab << "else\n"
457 << scope_tab << scope_tab << scope_tab << scope_tab << "return Efl.Eo.Globals.klasses[((object)this).GetType()];\n" 466 << scope_tab << scope_tab << scope_tab << scope_tab << "return Efl.Eo.ClassRegister.klassFromType[((object)this).GetType()];\n"
458 << scope_tab << scope_tab << "}\n" 467 << scope_tab << scope_tab << "}\n"
459 << scope_tab << "}\n" 468 << scope_tab << "}\n"
460 ).generate(sink, attributes::unused, context)) 469 ).generate(sink, attributes::unused, context))
@@ -512,7 +521,7 @@ struct klass
512 // For constructors with arguments, the parent is also required, as optional parameters can't come before non-optional paramenters. 521 // For constructors with arguments, the parent is also required, as optional parameters can't come before non-optional paramenters.
513 << scope_tab << "public " << inherit_name << "(Efl.Object parent" << ((constructors.size() > 0) ? "" : "= null") << "\n" 522 << scope_tab << "public " << inherit_name << "(Efl.Object parent" << ((constructors.size() > 0) ? "" : "= null") << "\n"
514 << scope_tab << scope_tab << scope_tab << *(", " << constructor_param ) << ") :\n" 523 << scope_tab << scope_tab << scope_tab << *(", " << constructor_param ) << ") :\n"
515 << scope_tab << scope_tab << (root ? "this" : "base") << "(\"" << inherit_name << "\", " << name_helpers::klass_get_name(cls) << "(), typeof(" << inherit_name << "), parent)\n" 524 << scope_tab << scope_tab << (root ? "this" : "base") << "(" << name_helpers::klass_get_name(cls) << "(), typeof(" << inherit_name << "), parent)\n"
516 << scope_tab << "{\n" 525 << scope_tab << "{\n"
517 << *(scope_tab << scope_tab << constructor_invocation << "\n" ) 526 << *(scope_tab << scope_tab << constructor_invocation << "\n" )
518 << scope_tab << scope_tab << "FinishInstantiation();\n" 527 << scope_tab << scope_tab << "FinishInstantiation();\n"
@@ -531,7 +540,7 @@ struct klass
531 { 540 {
532 return as_generator( 541 return as_generator(
533 scope_tab << "///<summary>Internal usage: Constructor to forward the wrapper initialization to the root class that interfaces with native code. Should not be used directly.</summary>\n" 542 scope_tab << "///<summary>Internal usage: Constructor to forward the wrapper initialization to the root class that interfaces with native code. Should not be used directly.</summary>\n"
534 << scope_tab << "protected " << inherit_name << "(String klass_name, IntPtr base_klass, System.Type managed_type, Efl.Object parent) : base(klass_name, base_klass, managed_type, parent) {}\n" 543 << scope_tab << "protected " << inherit_name << "(IntPtr base_klass, System.Type managed_type, Efl.Object parent) : base(base_klass, managed_type, parent) {}\n"
535 ).generate(sink, attributes::unused, context); 544 ).generate(sink, attributes::unused, context);
536 545
537 } 546 }
@@ -539,22 +548,12 @@ struct klass
539 // Detailed constructors go only in root classes. 548 // Detailed constructors go only in root classes.
540 return as_generator( 549 return as_generator(
541 /// Actual root costructor that creates class and instantiates 550 /// Actual root costructor that creates class and instantiates
542 scope_tab << "protected " << inherit_name << "(String klass_name, IntPtr base_klass, System.Type managed_type, Efl.Object parent)\n" 551 scope_tab << "protected " << inherit_name << "(IntPtr base_klass, System.Type managed_type, Efl.Object parent)\n"
543 << scope_tab << "{\n" 552 << scope_tab << "{\n"
544 << scope_tab << scope_tab << "inherited = ((object)this).GetType() != managed_type;\n" 553 << scope_tab << scope_tab << "inherited = ((object)this).GetType() != managed_type;\n"
545 << scope_tab << scope_tab << "IntPtr actual_klass = base_klass;\n" 554 << scope_tab << scope_tab << "IntPtr actual_klass = base_klass;\n"
546 << scope_tab << scope_tab << "if (inherited) {\n" 555 << scope_tab << scope_tab << "if (inherited) {\n"
547 << scope_tab << scope_tab << scope_tab << "if (!Efl.Eo.Globals.klasses.ContainsKey(((object)this).GetType())) {\n" 556 << scope_tab << scope_tab << scope_tab << "actual_klass = Efl.Eo.ClassRegister.GetInheritKlassOrRegister(base_klass, ((object)this).GetType());\n"
548 << scope_tab << scope_tab << scope_tab << scope_tab << "lock (klassAllocLock) {\n"
549 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "actual_klass = Efl.Eo.Globals.register_class(klass_name, base_klass, ((object)this).GetType());\n"
550 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "if (actual_klass == System.IntPtr.Zero) {\n"
551 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "throw new System.InvalidOperationException(\"Failed to initialize class '" << inherit_name << "'\");\n"
552 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "}\n"
553 << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << scope_tab << "Efl.Eo.Globals.klasses[((object)this).GetType()] = actual_klass;\n"
554 << scope_tab << scope_tab << scope_tab << scope_tab << "}\n"
555 << scope_tab << scope_tab << scope_tab << "}\n"
556 << scope_tab << scope_tab << scope_tab << "else\n"
557 << scope_tab << scope_tab << scope_tab << scope_tab << "actual_klass = Efl.Eo.Globals.klasses[((object)this).GetType()];\n"
558 << scope_tab << scope_tab << "}\n" 557 << scope_tab << scope_tab << "}\n"
559 << scope_tab << scope_tab << "handle = Efl.Eo.Globals.instantiate_start(actual_klass, parent);\n" 558 << scope_tab << scope_tab << "handle = Efl.Eo.Globals.instantiate_start(actual_klass, parent);\n"
560 << scope_tab << scope_tab << "register_event_proxies();\n" 559 << scope_tab << scope_tab << "register_event_proxies();\n"