###################################
#
# vrclipboard.rb
# Programmed by  nyasu <nyasu@osk.3web.ne.jp>
# Copyright 2000-2001 Nishikawa,Yasuhiro
#
# More information at http://www.threeweb.ad.jp/~nyasu/software/vrproject.html
# (in Japanese)
#
#
#
###################################

vr_DIR="vr/" unless vr_DIR
require vr_DIR+'vruby'

module VRClipboardObserver
  SetClipboardViewer = Win32API.new('user32','SetClipboardViewer','L','L')
  ChangeClipboardChain = Win32API.new('user32','ChangeClipboardChain','LL','I')
  WM_CHANGECBCHAIN = 781
  WM_DRAWCLIPBOARD = 776

  def clipboardobserverinit
    @cbchainnext = SetClipboardViewer.call(self.hWnd)
    addHandler WM_DRAWCLIPBOARD,"drawclipboard",MSGTYPE::ARGNONE,nil
    addHandler WM_CHANGECBCHAIN,"vrchangecbchain",MSGTYPE::ARGINTINT,nil
    addHandler WMsg::WM_DESTROY,"vrcbdestroy",MSGTYPE::ARGNONE,nil
    acceptEvents [WM_DRAWCLIPBOARD,WM_CHANGECBCHAIN,WMsg::WM_DESTROY]
  end

  def vrinit
    super
    clipboardobserverinit
  end

  def self_vrchangecbchain(hwndremove,hwndnext)
    @cbchainnext=hwndnext if hwndremove == @cbchainnext
  end

  def self_vrcbdestroy
    ChangeClipboardChain.call self.hWnd,@cbchainnext
  end
end

