### ----------------------------------------------------
### -- Gnome::Gtk3
### -- Licenses: Artistic-2.0
### -- Authors: Marcel Timmerman
### -- File: t/Fixed.rakutest
### ----------------------------------------------------
use v6;
use NativeCall;
use Test;

use Gnome::Gtk3::Fixed:api<1>;
use Gnome::Gtk3::Button:api<1>;

use Gnome::GObject::Type:api<1>;

#use Gnome::N::GlibToRakuTypes:api<1>;
#use Gnome::N::N-GObject:api<1>;
#use Gnome::N::X:api<1>;
#Gnome::N::debug(:on);

#-------------------------------------------------------------------------------
my Gnome::Gtk3::Fixed $f;
my Gnome::Gtk3::Button $b;

#-------------------------------------------------------------------------------
subtest 'ISA test', {
  $f .= new;
  isa-ok $f, Gnome::Gtk3::Fixed, '.new()';
}

#-------------------------------------------------------------------------------
# set environment variable 'raku-test-all' if rest must be tested too.
unless %*ENV<raku_test_all>:exists {
  done-testing;
  exit;
}

#-------------------------------------------------------------------------------
subtest 'Manipulations', {
  $b .= new(:label<Start>);
  lives-ok {$f.put( $b, 10, 10);}, '.put()';
  lives-ok {$f.move( $b, 20, 20);}, '.move()';
}

#-------------------------------------------------------------------------------
subtest 'Inherit Gnome::Gtk3::Fixed', {
  class MyClass is Gnome::Gtk3::Fixed {
    method new ( |c ) {
      self.bless( :GtkFixed, |c);
    }

    submethod BUILD ( *%options ) {

    }
  }

  my MyClass $mgc .= new;
  isa-ok $mgc, Gnome::Gtk3::Fixed, '$mgc.new()';
}

#-------------------------------------------------------------------------------
subtest 'Child properties …', {
#  my Gnome::Gtk3::Fixed $f .= new;
#  my @r = $f.get-properties( 'x', gint, 'y', gint);
#  is-deeply @r, [ 20, 20], 'properties: ' ~ (<x y>).join(', ');

  is $f.child-get-property( $b, 'x', G_TYPE_INT), 20,
     'child property x';
  is $f.child-get-property( $b, 'y', G_TYPE_INT), 20,
     'child property y';
}

#-------------------------------------------------------------------------------
done-testing;

=finish


#-------------------------------------------------------------------------------
subtest 'Themes ...', {
}

#-------------------------------------------------------------------------------
subtest 'Signals ...', {
  use Gnome::Gtk3::Main:api<1>;
  use Gnome::N::GlibToRakuTypes:api<1>;

  my Gnome::Gtk3::Main $main .= new;

  class SignalHandlers {
    has Bool $!signal-processed = False;

    method ... (
      'any-args',
      Gnome::Gtk3::Fixed() :_native-object($_widget), gulong :$_handler-id
      # --> ...
    ) {

      isa-ok $_widget, Gnome::Gtk3::Fixed;
      $!signal-processed = True;
    }

    method signal-emitter ( Gnome::Gtk3::Fixed :$widget --> Str ) {

      while $main.gtk-events-pending() { $main.iteration-do(False); }

      $widget.emit-by-name(
        'signal',
      #  'any-args',
      #  :return-type(int32),
      #  :parameters([int32,])
      );
      is $!signal-processed, True, '\'...\' signal processed';

      while $main.gtk-events-pending() { $main.iteration-do(False); }

      #$!signal-processed = False;
      #$widget.emit-by-name(
      #  'signal',
      #  'any-args',
      #  :return-type(int32),
      #  :parameters([int32,])
      #);
      #is $!signal-processed, True, '\'...\' signal processed';

      while $main.gtk-events-pending() { $main.iteration-do(False); }
      sleep(0.4);
      $main.gtk-main-quit;

      'done'
    }
  }

  my Gnome::Gtk3::Fixed $f .= new;

  #my Gnome::Gtk3::Window $w .= new;
  #$w.add($m);

  my SignalHandlers $sh .= new;
  $f.register-signal( $sh, 'method', 'signal');

  my Promise $p = $f.start-thread(
    $sh, 'signal-emitter',
    # G_PRIORITY_DEFAULT,       # enable 'use Gnome::Glib::Main'
    # :!new-context,
    # :start-time(now + 1)
  );

  is $main.gtk-main-level, 0, "loop level 0";
  $main.gtk-main;
  #is $main.gtk-main-level, 0, "loop level is 0 again";

  is $p.result, 'done', 'emitter finished';
}


