wx haskell拖放示例

时间:2013-04-07 20:49:48

标签: haskell wxhaskell

我正在寻找一个wx haskell拖放示例。我还没找到。

有空吗?还是提示?

到目前为止:

  • 我可以看到on drag事件(但没有“放弃”)
  • 鼠标只是在目标上提供left up
  • 我看到一些注释,我应该将一个drop target附加到object上,但是我看不到它是如何被调用的:

    Graphics.UI.WXCore.DragAndDrop

    L 51

    - |创建'DropSource'。然后'dragAndDrop'用'DataObject'替换目标的'DataObject'。

    dropSource :: DataObject a - >窗口b - > 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

1 个答案:

答案 0 :(得分:2)

摘要:

  • 从Graphics.UI.WXCore.DragAndDrop
  • 创建一个dropTarget和一个dropSource:
  • 使用 source 小部件上的事件“on drag”,从中调用Graphics.UI.WXCore.Events
  • 中的dragAndDrop

我的错误和错误的假设:

  • 我正在寻找目标上的“堕落”事件。不存在,也不需要,因为:
  • 当“拖动”时,其他事件将被暂停。不再是mouse upmouse down。             如果未在(DnD)目标上释放,则拖动将中止并恢复正常事件。 [0]
  • 请注意,textEntry需要焦点才能获得“粘贴”,但仍会出现丢弃。在控制台上查看“on drag Activated”。
  • 交换的文本是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

相关问题