Skip to content

Commit

Permalink
Get working on julia-0.3
Browse files Browse the repository at this point in the history
Note we can't use the Compat package because this defines an
internal Compat module!
  • Loading branch information
timholy committed Sep 9, 2015
1 parent 61f90dd commit fb9afb7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
25 changes: 22 additions & 3 deletions src/events.jl
Expand Up @@ -117,6 +117,12 @@ end

const default_mouse_cb = (w, event)->nothing

if VERSION < v"0.4.0-dev"
typealias MHStack Vector{(Symbol,Function)}
else
typealias MHStack Vector{Tuple{Symbol,Function}}
end

type MouseHandler
button1press::Function
button1release::Function
Expand All @@ -127,7 +133,7 @@ type MouseHandler
motion::Function
button1motion::Function
scroll::Function
stack::Vector{Tuple{Symbol,Function}}
stack::MHStack
widget::GtkWidget

MouseHandler() = new(default_mouse_cb, default_mouse_cb, default_mouse_cb,
Expand All @@ -136,6 +142,19 @@ type MouseHandler
Array(Tuple{Symbol,Function}, 0))
end

if VERSION < v"0.4.0-dev"
typealias MHPair (MouseHandler,Symbol)
function findlast(testf::Function, A)
for i = length(A):-1:1
testf(A[i]) && return i
end
0
end

else
typealias MHPair Tuple{MouseHandler,Symbol}
end

function mousedown_cb(ptr::Ptr, eventp::Ptr, this::MouseHandler)
event = unsafe_load(eventp)
if event.button == 1
Expand Down Expand Up @@ -176,14 +195,14 @@ function mousescroll_cb(ptr::Ptr, eventp::Ptr, this::MouseHandler)
end


function push!(mh_evt::Tuple{MouseHandler,Symbol}, func::Function)
function push!(mh_evt::MHPair, func::Function)
mh, evt = mh_evt
push!(mh.stack, (evt, getfield(mh, evt)))
setfield!(mh, evt, func)
mh
end

function pop!(mh_evt::Tuple{MouseHandler,Symbol})
function pop!(mh_evt::MHPair)
mh, evt = mh_evt
idx = findlast(x->x[1]==evt, mh.stack)
if idx != 0
Expand Down
6 changes: 3 additions & 3 deletions test/gui.jl
Expand Up @@ -538,8 +538,8 @@ showall(w)
io = IOBuffer()
c.mouse.button1press = (widget,evt) -> println(io, "cb1_1")
c.mouse.button2press = (widget,evt) -> println(io, "cb2_1")
press1=Gtk.GdkEventButton(Gtk.GdkEventType.BUTTON_PRESS, Gtk.gdk_window(c), Int8(0), UInt32(0), 0.0, 0.0, convert(Ptr{Float64},C_NULL), UInt32(0), UInt32(1), C_NULL, 0.0, 0.0)
press2=Gtk.GdkEventButton(Gtk.GdkEventType.BUTTON_PRESS, Gtk.gdk_window(c), Int8(0), UInt32(0), 0.0, 0.0, convert(Ptr{Float64},C_NULL), UInt32(0), UInt32(2), C_NULL, 0.0, 0.0)
press1=Gtk.GdkEventButton(Gtk.GdkEventType.BUTTON_PRESS, Gtk.gdk_window(c), int8(0), uint32(0), 0.0, 0.0, convert(Ptr{Float64},C_NULL), uint32(0), uint32(1), C_NULL, 0.0, 0.0)
press2=Gtk.GdkEventButton(Gtk.GdkEventType.BUTTON_PRESS, Gtk.gdk_window(c), int8(0), uint32(0), 0.0, 0.0, convert(Ptr{Float64},C_NULL), uint32(0), uint32(2), C_NULL, 0.0, 0.0)
signal_emit(c, "button-press-event", Bool, press1)
signal_emit(c, "button-press-event", Bool, press2)
push!((c.mouse,:button1press), (widget,evt) -> println(io, "cb1_2"))
Expand All @@ -555,7 +555,7 @@ str = takebuf_string(io)
@assert str == "cb1_1\ncb2_1\ncb1_2\ncb2_1\ncb1_2\ncb2_2\ncb1_1\ncb2_2\n"

c.mouse.scroll = (widget,event) -> println(io, "scrolling")
scroll = Gtk.GdkEventScroll(Gtk.GdkEventType.SCROLL, Gtk.gdk_window(c), Int8(0), UInt32(0), 0.0, 0.0, UInt32(0), Gtk.GdkScrollDirection.UP, convert(Ptr{Float64},C_NULL), 0.0, 0.0, 0.0, 0.0)
scroll = Gtk.GdkEventScroll(Gtk.GdkEventType.SCROLL, Gtk.gdk_window(c), int8(0), uint32(0), 0.0, 0.0, uint32(0), Gtk.GdkScrollDirection.UP, convert(Ptr{Float64},C_NULL), 0.0, 0.0, 0.0, 0.0)
signal_emit(c, "scroll-event", Bool, scroll)
str = takebuf_string(io)
@assert str == "scrolling\n"
Expand Down

0 comments on commit fb9afb7

Please sign in to comment.