Hi,

Using GTK, the following works

<code>

-- | create a new 'Figure' plot
--     click on the window to save
plotNew :: FigureHandle -> IO DrawingArea
plotNew f = do
   canvas <- drawingAreaNew

   set canvas [maybeFigure := (Just f)]

   return canvas

-----------------------------------------------------------------------------

-- | the figure attribute
figure :: Attr DrawingArea FigureState
figure = newAttr getFigure setFigure
   where getFigure o = do
                       Just f <- get o maybeFigure
                       readMVar f
         setFigure o f = set o [maybeFigure :~> (\(Just h) -> do
                                                              modifyMVar_ h
(\_ -> return f)
                                                              return $ Just
h)]

-----------------------------------------------------------------------------

maybeFigure :: Attr DrawingArea (Maybe FigureHandle)
maybeFigure = unsafePerformIO $ objectCreateAttribute
{-# NOINLINE maybeFigure #-}

-----------------------------------------------------------------------------

</code>

I am attempting to port this code to WxHaskell but can not see how to
create a new attribute for the `FigureHandle`.

This is the code I have so far

type FigureHandle = MVar FigureState

-----------------------------------------------------------------------------
-- | create a new 'Figure' plot
--     click on the window to save
plot ::  Frame () -> FigureHandle -> IO (Panel ())
plot fr f = do
  p <- panel fr [figure := f]
  set p [on paint := paintFigure p]
  return p

paintFigure :: Panel () -> DC a -> Rect -> IO ()

-- | the figure attribute
figure :: Attr (Panel a) FigureHandle
figure = newAttr "figure" getFigure setFigure
   where getFigure o = do
           readMVar figureHandle
         setFigure o f = do
           modifyMVar_ figureHandle (\_ -> return f)

-----------------------------------------------------------------------------

I looked in the CustomControl.hs example, which uses a pre-existing
attribute and does not create a new one in the way that the call to
`objectCreateAttribute` does with GTK.

Thanks,

Vivian


DISCLAIMER

This transmission contains information that may be confidential. It is
intended for the named addressee only. Unless you are the named addressee
you may not copy or use it or disclose it to anyone else.
------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
wxhaskell-users mailing list
wxhaskell-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wxhaskell-users

Reply via email to