| 1 | import System.IO |
|---|
| 2 | import Graphics.UI.Gtk as Gtk |
|---|
| 3 | import Graphics.UI.Gtk.Gdk.EventM as GdkE |
|---|
| 4 | import Graphics.UI.Gtk.Glade as Glade |
|---|
| 5 | import Graphics.UI.Gtk.ModelView as MV |
|---|
| 6 | import Control.Monad.Trans ( liftIO ) |
|---|
| 7 | |
|---|
| 8 | _STRING_COLUMN :: MV.ColumnId String String |
|---|
| 9 | _STRING_COLUMN = MV.makeColumnIdString 1 |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | defaultDrag :: Gtk.SelectionTypeTag -- ^ Selection to set data with. |
|---|
| 13 | -> Maybe ( Gtk.DragSourceIface model row ) |
|---|
| 14 | defaultDrag tag = (Just Gtk.DragSourceIface |
|---|
| 15 | { |
|---|
| 16 | treeDragSourceRowDraggable = \_ _ -> return True, |
|---|
| 17 | treeDragSourceDragDataGet = \_ (i:_) -> do |
|---|
| 18 | Gtk.selectionDataSet tag [i] |
|---|
| 19 | return True, |
|---|
| 20 | treeDragSourceDragDataDelete = \_ _ -> return False |
|---|
| 21 | }) |
|---|
| 22 | |
|---|
| 23 | defaultDrop tag sourceStore = |
|---|
| 24 | (Just Gtk.DragDestIface |
|---|
| 25 | { |
|---|
| 26 | treeDragDestRowDropPossible = \_ _ -> do liftIO $ putStrLn "checking if ListStore drop is possible" |
|---|
| 27 | return True, |
|---|
| 28 | treeDragDestDragDataReceived = \destStore _ -> do |
|---|
| 29 | liftIO $ MV.listStorePrepend destStore "world" |
|---|
| 30 | liftIO $ putStrLn "prepending to ListStore" |
|---|
| 31 | return True |
|---|
| 32 | }) |
|---|
| 33 | |
|---|
| 34 | main = do |
|---|
| 35 | Gtk.initGUI |
|---|
| 36 | |
|---|
| 37 | win <- Gtk.windowNew |
|---|
| 38 | Gtk.onDestroy win Gtk.mainQuit |
|---|
| 39 | hbox <- Gtk.hBoxNew True 10 |
|---|
| 40 | |
|---|
| 41 | targetl <- Gtk.targetListNew |
|---|
| 42 | Gtk.targetListAdd targetl MV.targetTreeModelRow [TargetSameApp] 0 |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | ivSource <- Gtk.iconViewNew |
|---|
| 46 | storeSource <- MV.listStoreNewDND ["hello"] (defaultDrag Gtk.selectionTypeInteger) Nothing |
|---|
| 47 | MV.treeModelSetColumn storeSource _STRING_COLUMN id |
|---|
| 48 | MV.iconViewSetModel ivSource (Just storeSource) |
|---|
| 49 | MV.iconViewSetTextColumn ivSource _STRING_COLUMN |
|---|
| 50 | MV.iconViewEnableModelDragSource ivSource [GdkE.Button1] targetl [Gtk.ActionCopy] |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | ivDest <- Gtk.iconViewNew |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | storeDest <- MV.listStoreNewDND [] Nothing (defaultDrop Gtk.selectionTypeInteger storeSource) |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | MV.treeModelSetColumn storeDest _STRING_COLUMN id |
|---|
| 62 | MV.iconViewSetModel ivDest (Just storeDest) |
|---|
| 63 | MV.iconViewSetTextColumn ivDest _STRING_COLUMN |
|---|
| 64 | MV.iconViewEnableModelDragDest ivDest targetl [Gtk.ActionCopy] |
|---|
| 65 | |
|---|
| 66 | hbox `Gtk.containerAdd` ivSource |
|---|
| 67 | hbox `Gtk.containerAdd` ivDest |
|---|
| 68 | win `Gtk.containerAdd` hbox |
|---|
| 69 | Gtk.widgetShowAll win |
|---|
| 70 | Gtk.mainGUI |
|---|