#! ruby

# cf:
# Delphi4 プログラミングバイブル p.215
# 5.1.5. コンポーネント間のドラッグ

require 'phi'
include Phi

form = Form.new
form.caption = $0

i = Edit.new form, :edit
i.align = Phi::AL_TOP
i.text = 'hello'

def i.on_mouse_down(btn, shift, x, y)
  begin_drag false, 10
end

i = ListBox.new form, :lbox
i.align = Phi::AL_CLIENT

def i.on_drag_over(accept, src, x, y, state)
  src != parent.edit || items.index_of(parent.edit.text) < 0
end

def i.on_drag_drop(src, x, y)
  case src
  when parent.edit
    items.add src.text
  end
end

form.show

Phi.mainloop
