2013-04-07 76 views
5

我正在尋找一個wx haskell拖放示例。我還沒有找到。wx haskell拖放示例

任何可用的?或提示?

到目前爲止:

  • 我可以看到一個on drag事件(但不可「水滴」)
  • 鼠標只是目標給予left up
  • 我看到一些評論,其中我應該到武官下降目標對象上,但我不知道它是如何調用:

    Graphics.UI.WXCore.DragAndDrop

    L 51

    - 創建'DropSource'。然後'dragAndDrop'用這個'DataObject'替換目標的'DataObject'。

    dropSource ::一個數據對象 - >窗口乙 - > IO(DropSource())

  • 我不能看到其中上述Graphics.UI.WXCore.DragAndDrop

  • 的WX層,這是(太)老我猜:[0]:http://bb10.com/haskell-wxhaskell-general/2007-08/msg00035.html

反正很模糊,現在...


編輯:此是我現在的立場: 在拖動沒有得到激活,所以沒有dragAndDrop (在鼠標在xinput只是在那裏看看發生了什麼) (dragger是我從[O]得到),但我做沒有得到這個事件)

--- test where DnD from yinput to xinput 
module Main where 

import CustoWidget 
import Graphics.UI.WX hiding (empty) 
import Data.Graph.Inductive 
import Data.Maybe 
import Control.Monad 
import Graphics.UI.WX.Events 
import Graphics.UI.WXCore.WxcClassesMZ 
import Graphics.UI.WXCore.WxcClassesAL 
import Graphics.UI.WXCore.DragAndDrop 
import Graphics.UI.WXCore.Events 
import Debug.Trace 
main 
    = start ballsFrame 
    -- @next : try andrun start within a state 

ballsFrame 
    = do 

     f  <- frame [text := "Layout test"] 
     p  <- panel f []      -- panel for color and tab management. 
     ok  <- button p [text := "Ok"] 
     can <- button p [text := "Cancel", on command := infoDialog f "Info" "Pressed 'Cancel'"] 
     xinput <- textEntry p [text := "100", alignment := AlignRight] 
     yinput <- textEntry p [text := "100", alignment := AlignRight] 

     set f [defaultButton := ok 
      ,layout := container p $ 
         margin 10 $ 
         column 5 [boxed "coordinates" (grid 5 5 [[label "x:", hfill $ widget xinput] 
                   ,[label "y:", hfill $ widget yinput]]) 
           ,floatBottomRight $ row 5 [widget ok,widget can]] 
           ] 
     set xinput [ on mouse := showMe] --, on keyboard := showMeK 
     set yinput [ ] --on mouse := showMe, on keyboard := showMeK ] 
--  fileDropTarget xinput (\pt file -> putStrLn $ show file) 


     -- prepare the drop source 

     textdata <- textDataObjectCreate "" 
     drop <- dropTarget xinput textdata 

     textdata' <- textDataObjectCreate "text" 
     src <- dropSource textdata' yinput 

     -- activate on drag the do drag drop 
     set yinput [ on drag := onDrag src] 
     set ok [ on command := onOk f textdata] 




     return() 



onDrag s p = trace ("on drag " ++ show s ++ " " ++ show p) 
    dragAndDrop s Default (\_ -> return()) 



onOk f textdata = do 

      txt <- textDataObjectGetText textdata 
      infoDialog f "resultText" txt 
      close f 

showMe = \x -> do putStrLn $ show x 

dragger win wout = do 
      textdata <- textDataObjectCreate "" 
      drop <- dropTarget wout textdata 
      textdata' <- textDataObjectCreate "text" 
      src <- dropSource textdata' win 
      dragAndDrop src Default (\_ -> return()) 
      txt <- textDataObjectGetText textdata 
      infoDialog wout "resultText" txt 

回答

2

摘要:

  • 創建的DropTarget和dropSource:從Graphics.UI.WXCore.DragAndDrop
  • 使用事件 「on drag」 關於部件,在那裏你會調用dragAndDrop從Graphics.UI.WXCore.Events

我的失誤和錯誤的假設:

  • 我一直在尋找一個「上滴」事件,對目標。不存在,也不需要,因爲:
  • 當「拖動」時,其他事件被暫停。沒有更多mouse upmouse down。 如果未在(DnD)目標上釋放,則拖動將中止並恢復正常事件。 [0]
  • 請注意,textEntry需要重點才能獲得「粘貼」,但仍會出現拖放。在控制檯上查看「關於拖動激活」。
  • 交換的文本是來自DataObjects(而不是來自源,如果這將是一個textEntry)。看到「文字丟失」。

下面的代碼轉儲在控制檯上的事件,進行試驗:

module Main where 


import Graphics.UI.WX hiding (empty) 

import Data.Maybe 
import Control.Monad 
import Graphics.UI.WX.Events 
import Graphics.UI.WXCore.WxcClassesMZ 
--import Graphics.UI.WXCore.WxcClassesAL 
import Graphics.UI.WXCore.DragAndDrop 
import Graphics.UI.WXCore.Events 

main 
    = start dndtest 


dndtest 
    = do 

     f  <- frame [text := "Drag And Drop test"] 
     p  <- panel f []      
     ok  <- button p [text := "Ok"] 
     xinput <- textEntry p [text := "here :"] 
     yinput <- staticText p [text := "drag me"] 

     set f [defaultButton := ok 
      ,layout := container p $ 
         margin 10 $ 
         column 5 [boxed "coordinates" (grid 5 5 [[label "source:", hfill $ widget yinput] 
                   ,[label "target(focus first):", hfill $ widget xinput] 
                   ]) 
           ,floatBottomRight $ row 5 [widget ok]] 
           ] 

     set xinput [ on enter := onEnter] 

     set yinput [ ] 
--------------------------------------------------------- 
--- meaningful stuff starts here 
--------------------------------------------------------- 

     -- prepare the drop source : create a DataObject and associate it with the source 
     textdata' <- textDataObjectCreate "text dropped" 
     src <- dropSource textdata' yinput 

     -- prepare the drop target: create a DataObject (placeholder here) and associate it with the target 
     textdata <- textDataObjectCreate ".." 
     drop <- dropTarget xinput textdata 


     -- activate on drag the do dragdrop. this will replace the target dataObject with the source one. 
     -- Try with and without giving focus to the textEntry field 
     -- Try and source from your favorite editor also (focus first!) 
     set yinput [ on drag := onDrag src ] 
--------------------------------------------------------- 
--- meaningful stuff stops here 
--------------------------------------------------------- 

     set ok [ on command := close f ] 
     return() 





--onDrag:: Graphics.UI.WXCore.WxcClassTypes.DropSource a -> Point -> IO() 
onDrag s p = do 
    dragAndDrop s Default (\_ -> return()) 
    putStrLn "on Drag activated:" 



showMeE :: EventMouse -> IO() 
showMeE (MouseMotion point mod) = putStr "" --- discard meaningless Motion event 
showMeE e = putStrLn $ show e 


onEnter p = putStrLn $ "on Enter:" ++ show p 

我看到其他東西我可以探索,如在拖動期間改變光標,或在降的不同變體的反應。

[0]:http://docs.wxwidgets.org/2.8/wx_wxdndoverview.html