Re: Phix+EuGTK

new topic     » goto parent     » topic index » view thread      » older message » newer message

This works to open multiple instances of a class (handles returned by GTK are unique)

constant LIB = open_dll("libgtk-3.so.0") 
constant  
 P = C_PTR, 
 I = C_INT 
 
integer init_rid = define_c_func(LIB,"gtk_init_check",{P,P},P)  
if init_rid < 1 or c_func(init_rid,{0,0})=0 then  
  crash("Failed to initialize GTK library!")  
end if  
 
class Widget 
  public atom handle 
  public integer sigid  
 
  procedure show() 
    c_proc(define_c_proc(LIB,"gtk_widget_show",{P}),{this.handle}) 
  end procedure   
 
  procedure connect(object sig, object fn, object data=0, object closure=0, integer flags=0) 
    integer rid 
    sig = allocate_string(sig) 
    if string(fn) then 
      rid = routine_id(fn)  
      if rid > 0 then 
        fn = call_back(rid) 
        if fn < 1 then  
          crash("Invalid callback for -> %s",{fn}) 
        end if 
      else 
        crash("Can't locate function -> %s",{fn}) 
      end if 
    end if 
    if string(data) then data = allocate_string(data) end if 
    sigid = c_func(define_c_func(LIB,"g_signal_connect_data",{P,P,P,P,P,I},I), 
            {this.handle,sig,fn,data,closure,flags}) 
  end procedure 
 
end class 
 
class Window extends Widget 
  function Window() 
    this.handle = c_func(define_c_func(LIB,"gtk_window_new",{I},P),{0}) 
    return this 
  end function 
 
  procedure title(sequence t) 
    c_proc(define_c_proc(LIB,"gtk_window_set_title",{P,P}),{handle,t}) 
  end procedure 
 
  procedure size(integer w, integer h) 
    c_proc(define_c_proc(LIB,"gtk_window_set_default_size",{P,I,I}),{handle,w,h}) 
  end procedure 
   
end class 
 
function Quit() 
  c_proc(define_c_proc(LIB,"gtk_main_quit",{})) 
return 0 
end function 
 
procedure main()  
c_proc(define_c_proc(LIB,"gtk_main",{}))  
end procedure  
 
-------------------------------------------------------------------- 
 
Window w1 = new()  ? w1.handle 
Window w2 = new()  ? w2.handle 
w1.title("I'm Number One!") 
w2.title("but I'm on top") 
w1.size(500,300) 
w1.connect("destroy","Quit") 
w1.show() w2.show() 
main() 

Window handles:

10781296 
10781968 

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu