| | 523 | char[][] bd; /* Return variable. */ |
|---|
| | 524 | char[] gtkCall; |
|---|
| | 525 | |
|---|
| | 526 | /* 1st: construct the actual GTK+ call. */ |
|---|
| | 527 | gtkCall ~= name ~ "("; //gtk_function( |
|---|
| | 528 | |
|---|
| | 529 | for(int i = 0; (i < parmsType.length) && (i < parms.length); ++i) |
|---|
| | 530 | { |
|---|
| | 531 | debug(parm) writefln("\t(%s -> %s) %s",parmsType[i], parmsWrap[i], parms[i]); |
|---|
| | 532 | |
|---|
| | 533 | if ( i == 0 ) |
|---|
| | 534 | { |
|---|
| | 535 | if ( parmsType[0] == strctPointer ) |
|---|
| | 536 | { |
|---|
| | 537 | if ( convParms.templ.length == 0 ) |
|---|
| | 538 | { |
|---|
| | 539 | gtkCall ~= GtkDClass.toVar(convParms.strct.dup); |
|---|
| | 540 | } |
|---|
| | 541 | else |
|---|
| | 542 | { |
|---|
| | 543 | gtkCall ~= "get"~convParms.clss~"Struct()"; |
|---|
| | 544 | } |
|---|
| | 545 | } |
|---|
| | 546 | else if ( parms[0].length > 0 ) |
|---|
| | 547 | { |
|---|
| | 548 | gtkCall ~= parameterToGtk(0, convParms, aliases); |
|---|
| | 549 | } |
|---|
| | 550 | } |
|---|
| | 551 | else |
|---|
| | 552 | { |
|---|
| | 553 | if ( parms[i].length > 0 ) |
|---|
| | 554 | { |
|---|
| | 555 | gtkCall ~= ", "; |
|---|
| | 556 | gtkCall ~= parameterToGtk(i, convParms, aliases); |
|---|
| | 557 | } |
|---|
| | 558 | } |
|---|
| | 559 | } |
|---|
| | 560 | |
|---|
| | 561 | gtkCall ~= ")"; //gtk_function(arg1...argN) |
|---|
| | 562 | |
|---|
| | 563 | /* 2nd: construct the rest of the body according to the type |
|---|
| | 564 | * of the function. */ |
|---|
| | 565 | if (type == "void") |
|---|
| | 566 | { |
|---|
| | 567 | /* If it's a void, we just need to make the call and be done |
|---|
| | 568 | * with it. */ |
|---|
| | 569 | gtkCall ~= ";"; |
|---|
| | 570 | bd ~= gtkCall; |
|---|
| | 571 | return bd; |
|---|
| | 572 | } |
|---|
| | 573 | else |
|---|
| | 574 | { |
|---|
| | 575 | /* If the call constructs an object, call the GTK+ constructor |
|---|
| | 576 | * and pass the object to the wrapper's constructor. */ |
|---|
| | 577 | if(ctor) |
|---|
| | 578 | { |
|---|
| | 579 | /*char[] prepend = "this(cast("; |
|---|
| | 580 | if(convParms.realStrct.length > 0) |
|---|
| | 581 | prepend ~= convParms.realStrct ~ "*)"; |
|---|
| | 582 | else |
|---|
| | 583 | prepend ~= convParms.strct ~ "*)"; |
|---|
| | 584 | gtkCall = prepend ~ gtkCall*/ |
|---|
| | 585 | char[] strct = (convParms.realStrct.length > 0) ? convParms.realStrct : convParms.strct; |
|---|
| | 586 | /* Do we need a cast? */ |
|---|
| | 587 | bd ~= "auto p = " ~ gtkCall ~ ";"; //GtkStruct* p = gtk_function(arg1...argN); |
|---|
| | 588 | |
|---|
| | 589 | char[][] check = [ "if(p is null)", |
|---|
| | 590 | "{", |
|---|
| | 591 | " this = null;", |
|---|
| | 592 | " version(Exceptions) throw new Exception(\"Construction failure.\");", |
|---|
| | 593 | " else return;", |
|---|
| | 594 | "}" ]; |
|---|
| | 595 | bd ~= check; |
|---|
| | 596 | /* What's with all the casting? */ |
|---|
| | 597 | /* A; Casting is needed because some GTK+ |
|---|
| | 598 | * functions can return void pointers. */ |
|---|
| | 599 | bd ~= "this(cast(" ~ strct ~ "*) p);"; |
|---|
| | 600 | //bd ~= "this(p);"; |
|---|
| | 601 | |
|---|
| | 602 | /* The body is constructed, return. */ |
|---|
| | 603 | return bd; |
|---|
| | 604 | } |
|---|
| | 605 | else |
|---|
| | 606 | { |
|---|
| | 607 | /* Non-void call. */ |
|---|
| | 608 | if(type == typeWrap) |
|---|
| | 609 | { |
|---|
| | 610 | /* We return an object of the same type as the GTK+ function. */ |
|---|
| | 611 | //return gtk_function(arg1...argN); |
|---|
| | 612 | bd ~= "return " ~ gtkCall ~ ";"; |
|---|
| | 613 | |
|---|
| | 614 | return bd; |
|---|
| | 615 | } |
|---|
| | 616 | else |
|---|
| | 617 | { |
|---|
| | 618 | /* We return an object of a different type, we need to wrap it |
|---|
| | 619 | * accordingly. */ |
|---|
| | 620 | if(typeWrap == "char[]") |
|---|
| | 621 | { |
|---|
| | 622 | /* Returned strings get special care. */ |
|---|
| | 623 | //return Str.toString(gtk_function(arg1...argN)).dup; |
|---|
| | 624 | bd ~= "return Str.toString(" ~ gtkCall ~ ").dup;"; |
|---|
| | 625 | |
|---|
| | 626 | return bd; |
|---|
| | 627 | } |
|---|
| | 628 | else |
|---|
| | 629 | { |
|---|
| | 630 | /* All other objects are wrapped in their container. */ |
|---|
| | 631 | /* Why do we need a cast? */ |
|---|
| | 632 | //GtkType p = gtk_function(arg1...argN); |
|---|
| | 633 | bd ~= "auto p = " ~ gtkCall ~ ";"; |
|---|
| | 634 | |
|---|
| | 635 | char[][] check = [ "if(p is null)", |
|---|
| | 636 | "{", |
|---|
| | 637 | " version(Exceptions) throw new Exception(\"Null GObject from GTK+.\");", |
|---|
| | 638 | " else return null;", |
|---|
| | 639 | "}" ]; |
|---|
| | 640 | bd ~= check; |
|---|
| | 641 | /* What's with all the casting? */ |
|---|
| | 642 | /* A; Casting is needed because some GTK+ |
|---|
| | 643 | * functions can return void pointers. */ |
|---|
| | 644 | bd ~= "return new " ~ typeWrap ~ "(cast(" ~ type ~ ") p);"; |
|---|
| | 645 | |
|---|
| | 646 | return bd; |
|---|
| | 647 | } |
|---|
| | 648 | } |
|---|
| | 649 | } |
|---|
| | 650 | } |
|---|
| | 651 | |
|---|
| | 652 | /* We should never reach here. */ |
|---|
| | 653 | assert(0, "A strange function body was requested."); |
|---|
| | 654 | } |
|---|
| | 655 | |
|---|
| | 656 | /* Deprecated */ |
|---|
| | 657 | /* Remove me for 1.0 */ |
|---|
| | 658 | char[][] bod_old(ConvParms* convParms, char[][char[]] aliases) |
|---|
| | 659 | { |
|---|