Permalink
Browse files

Add PropertyGrid support to Events.hs

Ignore-this: 447bc057c961fe93de13c715f3fbfe4f

This incorporates changes from the following patches in Dave Tapley's
repo:

* Fix segfault with wxPGProperty caused returning local wxString
  The initial implementation of wxPGProperty was causing a segfault,
  after comparing my approach with that used by the existing methods
  I noticed that they all return wxString* (i.e. a pointer and not a
  copy) and use pattern [1], after modifying wxPGProperty to do the
  same the segfault went away.

  [1]
      wxString* result = new wxString();
      *result = self->FuncWhichReturnswxString()
      return result;
  (dukedave@gmail.com Fri Sep 23 2011)
* Added wxStringProperty and wxPropertyGrid_Append
  I've also updated the PropertyGrid.hs sample, to create a couple of
  wxStringProperty's and wxPropertyGrid_Append them; and updated the
  highlighted call back to print the label name when an item is hovered
  over, unfortunately this causes a segfault presently.
  (dukedave@gmail.com Wed Aug 31 2011)
* Added wxPropertyGridEvent_HasProperty, made PropertyGridHighlighted have
  a Maybe PGProperty
  (dukedave@gmail.com Fri Aug 26 2011)
* Wrapping wxPropertyGrid
  (dukedave@gmail.com Fri Aug 26 2011)

darcs-hash:20120319191305-75908-9cccfc338e4f15c7778af7a45a5a8fc226ac34b5.gz
  • Loading branch information...
1 parent 7e866b4 commit 584039a564cf8fa185bf104ba614d03e14dc97e3 @jodonoghue committed Mar 19, 2012
Showing with 51 additions and 0 deletions.
  1. +51 −0 wxcore/src/haskell/Graphics/UI/WXCore/Events.hs
@@ -33,6 +33,7 @@ module Graphics.UI.WXCore.Events
, listCtrlOnListEvent
, treeCtrlOnTreeEvent
, gridOnGridEvent
+ , propertyGridOnPropertyGridEvent
-- ** Windows
, windowOnMouse
@@ -89,6 +90,7 @@ module Graphics.UI.WXCore.Events
, listCtrlGetOnListEvent
, treeCtrlGetOnTreeEvent
, gridGetOnGridEvent
+ , propertyGridGetOnPropertyGridEvent
-- ** Windows
, windowGetOnMouse
@@ -190,6 +192,9 @@ module Graphics.UI.WXCore.Events
-- * TaskBar icon events
, EventTaskBarIcon(..)
+ -- ** PropertyGrid events
+ , EventPropertyGrid(..)
+
-- * Current event
, propagateEvent
@@ -2372,6 +2377,52 @@ evtHandlerGetOnTaskBarIconEvent window id evt
skipCurrentEvent
+{-----------------------------------------------------------------------------------------
+ PropertyGrid events
+-----------------------------------------------------------------------------------------}
+-- | PropertyGrid control events.
+data EventPropertyGrid
+ = PropertyGridHighlighted (Maybe (PGProperty ()))
+ | PropertyGridChanged (PGProperty ())
+ | PropertyGridUnknown
+
+fromPropertyGridEvent :: PropertyGridEvent a -> IO EventPropertyGrid
+fromPropertyGridEvent propertyGridEvent
+ = do tp <- eventGetEventType propertyGridEvent
+ case lookup tp propertyGridEvents of
+ Just f -> f propertyGridEvent
+ Nothing -> return PropertyGridUnknown
+
+propertyGridEvents :: [(Int, PropertyGridEvent a -> IO EventPropertyGrid)]
+propertyGridEvents
+ = [(wxEVT_PG_HIGHLIGHTED, withPGProperty PropertyGridHighlighted),
+ (wxEVT_PG_CHANGED, withPGProperty (PropertyGridChanged . fromJust))
+ ]
+ where
+ withPGProperty :: (Maybe((PGProperty ())) -> b) -> PropertyGridEvent a -> IO b
+ withPGProperty make propertyGridEvent = do
+ hasProp <- propertyGridEventHasProperty propertyGridEvent
+ if not hasProp then return (make Nothing) else do
+ prop <- propertyGridEventGetProperty propertyGridEvent
+ return (make (Just prop))
+
+-- | Set a PropertyGrid event handler.
+propertyGridOnPropertyGridEvent :: PropertyGrid a -> (EventPropertyGrid -> IO ()) -> IO ()
+propertyGridOnPropertyGridEvent propertyGrid eventHandler
+ = windowOnEvent propertyGrid (map fst propertyGridEvents) eventHandler listHandler
+ where
+ listHandler event
+ = do eventPropertyGrid <- fromPropertyGridEvent (objectCast event)
+ eventHandler eventPropertyGrid
+
+-- | Get the current PropertyGrid event handler of a window.
+propertyGridGetOnPropertyGridEvent :: PropertyGrid a -> IO (EventPropertyGrid -> IO ())
+propertyGridGetOnPropertyGridEvent propertyGrid
+ -- I'm not sure what expEVT_PG_HIGHLIGHTED needs to be here for, just followed pattern with `listCtrlGetOnListEvent'
+ = unsafeWindowGetHandlerState propertyGrid wxEVT_PG_HIGHLIGHTED (\event -> skipCurrentEvent)
+
+
+
------------------------------------------------------------------------------------------
-- TimerEx is handled specially.
------------------------------------------------------------------------------------------

0 comments on commit 584039a

Please sign in to comment.