Skip to content
This repository
tree: df9713514c
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 111 lines (91 sloc) 3.985 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
! Copyright (C) 2011
! Free Software Foundation, Inc.

! This file is part of the gtk-fortran GTK+ Fortran Interface library.

! This is free software; you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation; either version 3, or (at your option)
! any later version.

! This software is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.

! Under Section 7 of GPL version 3, you are granted additional
! permissions described in the GCC Runtime Library Exception, version
! 3.1, as published by the Free Software Foundation.

! You should have received a copy of the GNU General Public License along with
! this program; see the files COPYING3 and COPYING.RUNTIME respectively.
! If not, see <http://www.gnu.org/licenses/>.
!
! Contributed by Vincent Magnin, Jerry DeLisle, "jtappin" and Tobias Burnus, 01-23-2011
! Last modification: 03-15-2011

module gtk
  !use iso_c_binding, only: c_null_char, c_null_ptr, c_null_funptr, c_ptr, c_funptr, c_char, c_int, c_long
  use iso_c_binding
implicit none
include "gtkenums-auto.f90"

  interface
    !**************************************************************************
    ! You can add your own additional interfaces here:
    !**************************************************************************
    subroutine gtk_init_real(argc,argv) bind(c,name='gtk_init')
      use iso_c_binding, only: c_int, c_ptr
integer(c_int) :: argc
      type(c_ptr) :: argv
    end subroutine
  
    !**************************************************************************
    ! The interfaces automatically generated by cfwrapper.py are included here.
    ! Do not modify.
    include "gtk-auto.f90"
    !**************************************************************************
  end interface

  ! Some useful parameters to ease coding:
! character(kind=c_char), parameter :: CNULL = c_null_char
! type(c_ptr), parameter :: NULL = c_null_ptr
! type(c_funptr), parameter :: FNULL = c_null_funptr
  ! In GTK+ gboolean is int:
  integer(c_int), parameter :: FALSE = 0
  integer(c_int), parameter :: TRUE = 1

contains
subroutine g_signal_connect (instance, detailed_signal, c_handler, data0)
    use iso_c_binding, only: c_ptr, c_char, c_funptr
use g, only: g_signal_connect_data
    character(kind=c_char):: detailed_signal(*)
    type(c_ptr) :: instance
    type(c_funptr) :: c_handler
    type(c_ptr), optional :: data0
    integer(c_long) :: handler_id
    
    if (present(data0)) then
handler_id = g_signal_connect_data (instance, detailed_signal, c_handler, &
            & data0, c_null_funptr, 0)
    else
handler_id = g_signal_connect_data (instance, detailed_signal, c_handler, &
            & c_null_ptr, c_null_funptr, 0)
    end if
end subroutine


subroutine gtk_init()
    use iso_c_binding, only: c_ptr, c_char, c_int, c_null_char, c_loc
character(len=256,kind=c_char) :: arg
    character(len=1,kind=c_char), dimension(:),pointer :: carg
    type(c_ptr), allocatable, target :: argv(:)
    integer(c_int) :: argc, strlen, i, j

    argc = command_argument_count()
    allocate(argv(0:argc))

    do i = 0, argc
      call get_command_argument (i,arg,strlen)
      allocate(carg(0:strlen))
      do j = 0, strlen-1
        carg(j) = arg(j+1:j+1)
      end do
carg(strlen) = c_null_char
argv(i) = c_loc (carg(0))
    end do

argc = argc + 1

    ! This is a workaround to prevent locales with decimal comma
    ! from behaving wrongly reading reals after gtk_init is called
    ! when the code is compiled using gfortran.
    call gtk_disable_setlocale()

    call gtk_init_real (argc, c_loc(argv))
    !deallocate(argv)
    !deallocate(carg)
  end subroutine gtk_init
  
end module gtk
Something went wrong with that request. Please try again.