From: <wxh...@al...> - 2004-05-19 04:31:03
|
Hello again, Continuing with my last example, I have been trying to get drag and drop working for trees. Is this implemented yet? The following doesn't seem to work with or without the "veto" line commented out. Any guidance would be appreciated. If it hasn't been implemented yet, how much work would be required to do so? Thanks module Main where import Graphics.UI.WX import Graphics.UI.WXCore imageNone :: Int imageNone = (-1) appendChild tree parent child = treeCtrlAppendItem tree parent child imageNone imageNone objectNull appendList tree parent children = mapM_ (appendChild tree parent) children main :: IO() main = start test test :: IO() test = do f <- frame [text := "Hello!"] tree <- treeCtrl f [] root <- treeCtrlAddRoot tree "Root" imageNone imageNone objectNull child1 <- treeCtrlAppendItem tree root "Child1" imageNone imageNone objectNull child2 <- treeCtrlAppendItem tree root "Child2" imageNone imageNone objectNull appendList tree child1 ["A","B","C"] appendList tree child2 ["1","2","3"] set tree [on treeEvent := onTreeEvent tree] set f [layout := fill $ widget tree, clientSize := sz 500 300] onTreeEvent :: TreeCtrl a -> EventTree -> IO () onTreeEvent t event = case event of TreeBeginDrag item point veto -> do putStrLn "started dragging..." veto propagateEvent TreeEndDrag item point -> do putStrLn "stopped dragging..." propagateEvent other -> propagateEvent |
From: Daan L. <daa...@xs...> - 2004-05-19 08:59:31
|
Hi alias in space and time :-) On Tue, 18 May 2004 23:31:00 -0500, <wxh...@al...> wrote: > Continuing with my last example, I have been trying to get drag and drop > working for trees. Is this implemented yet? The following doesn't seem > to work with or without the "veto" line commented out. Any guidance > would be appreciated. If it hasn't been implemented yet, how much work > would be required to do so? Well, when I tried your example, it first crashed on me! As I am using a debug version, I quickly found out that the wxWidget code asserts that an image list is present when dragging -- even when just using text labels :-( I just wonder whether that might cause you trouble. When I added images (using the filebrowse example images) everything worked -- of course, drags were vetoed so, nothing would happen. I hope this helps, All the best, Daan. > > Thanks > > module Main where > > import Graphics.UI.WX > import Graphics.UI.WXCore > > imageNone :: Int > imageNone = (-1) > > appendChild tree parent child = treeCtrlAppendItem tree parent child > imageNone imageNone objectNull > > appendList tree parent children = mapM_ (appendChild tree parent) > children > > main :: IO() > main = start test > > test :: IO() > test = do f <- frame [text := "Hello!"] > tree <- treeCtrl f [] > root <- treeCtrlAddRoot tree "Root" imageNone imageNone > objectNull > child1 <- treeCtrlAppendItem tree root "Child1" imageNone > imageNone objectNull > child2 <- treeCtrlAppendItem tree root "Child2" imageNone > imageNone objectNull > appendList tree child1 ["A","B","C"] > appendList tree child2 ["1","2","3"] > set tree [on treeEvent := onTreeEvent tree] > set f [layout := fill $ widget tree, clientSize := sz 500 300] > > > onTreeEvent :: TreeCtrl a -> EventTree -> IO () > onTreeEvent t event > = case event of > TreeBeginDrag item point veto > -> do putStrLn "started dragging..." > veto > propagateEvent > TreeEndDrag item point > -> do putStrLn "stopped dragging..." > propagateEvent > other > -> propagateEvent > > > > ------------------------------------------------------- > This SF.Net email is sponsored by: SourceForge.net Broadband > Sign-up now for SourceForge Broadband and get the fastest > 6.0/768 connection for only $19.95/mo for the first 3 months! > http://ads.osdn.com/?ad_id=2562&alloc_id=6184&op=click > _______________________________________________ > wxhaskell-users mailing list > wxh...@li... > https://lists.sourceforge.net/lists/listinfo/wxhaskell-users > |
From: <wxh...@al...> - 2004-05-19 16:30:36
|
> Well, when I tried your example, it first crashed on me! As I am using > a debug version, I quickly found out that the wxWidget code asserts that > an image list is present when dragging -- even when just using text > labels :-( > I just wonder whether that might cause you trouble. When I added images > (using > the filebrowse example images) everything worked -- of course, drags were > vetoed > so, nothing would happen. Hmm, doesn't crash on me. But I went ahead and added the images, but nothing changed. Note that I said try with and without the "veto", because I'm not sure it should really even be "veto". In the C++ version, you have to explicitly allow the dragging, because the default is not to drag, as evidenced in the wxWidgets sample program: void MyTreeCtrl::OnBeginDrag(wxTreeEvent& event) { // need to explicitly allow drag if ( event.GetItem() != GetRootItem() ) { m_draggedItem = event.GetItem(); wxLogMessage(wxT("OnBeginDrag: started dragging %s"), GetItemText(m_draggedItem).c_str()); event.Allow(); } else { wxLogMessage(wxT("OnBeginDrag: this item can't be dragged.")); } } That's why I wasn't sure if the "veto" wasn't really this "event.Allow()" call. But it doesn't matter, because I try it both ways and neither way works. Any ideas? Thanks. |
From: Daan L. <daa...@xs...> - 2004-05-21 08:40:45
|
> Hmm, doesn't crash on me. But I went ahead and added the images, but > nothing changed. Note that I said try with and without the "veto", > because I'm not sure it should really even be "veto". In the C++ > version, you have to explicitly allow the dragging, because the default > is not to drag, as evidenced in the wxWidgets sample program: No, it should be "allow", as signified by the documentation of TreeCtrl events :-) I tried it and it works on my machine -- ie. I have: onTreeEvent t event = case event of TreeBeginDrag item point allow -> putStrLn "dragging..." other -> propagateEvent Note that I removed the propagateEvent in the first case, as I have handled it now. I have a windows-XP system with wxWidgets 2.4.2 and ghc 6.2.1. If you tell me your system, I can maybe test it better on Monday, perhaps there is an OS dependency somewhere. (I have a MacOSX panther and Fedora core1 machine available). I hope this helps, -- Daan. |
From: <wxh...@al...> - 2004-05-22 03:33:36
|
> Note that I removed the propagateEvent in the first case, as I > have handled it now. That is exactly what fixed it. I wonder why it "hurts" to propagate the event. I'm assuming any further propagation would/should be ignored? In any case, I have a working solution now. Thanks for your help Daan (and for wxHaskell to begin with!). |