Hi Axel,

Axel Simon <axel.si...@in.tum.de> writes:

> Hi Andy,
>
> I think your peekGdkPoint function and the mkIconInfo functions are fine. 
> Could you search for
> array' in the docs and replace it with  'list'? Also all file paths should be 
> of type FilePath, not
> String.
I see, i have improve those in my new patch.

>
> On May 6, 2010, at 17:15, Andy Stewart wrote:
>
>> +iconInfoGetAttachPoints :: IconInfo -> IO (Maybe ([Point], Int))
>> +iconInfoGetAttachPoints self =
>> +  allocaArray 0 $ \pointPtr ->
>
> This is not right. You're passing an array of size 0. What you want to pass 
> in is a pointer into
> which the function can write a pointer to a  heap-allocated array. I.e.
>
>     alloca $ \arrPtrPtr -> do
>> +  alloca $ \nPointsPtr -> do
>> +  success <- liftM toBool $
>> +            {# call gtk_icon_info_get_attach_points #}
>> +              self
>                 arrPtrPtr
>> +              (castPtr pointPtr)
>> +              nPointsPtr
>> +  if success
>> +     then do
>           arrPtr <- peek arrPtrPtr
>           nPoints <- peek nPointsPtr
>         pointList <- peekArray nPoints arrPtr
>           return (Just pointList)
>
>> +       pointListPtrs <- peekArray 0 pointPtr
>> +       pointList <- mapM peekPoint pointListPtrs
>> +       {#call unsafe g_free#} (castPtr pointPtr)
>> +       nPoints <- peek nPointsPtr
>> +       return (Just (pointList, (fromIntegral nPoints)))
>> +     else return Nothing
>
> You would need to create an instance of Storable for Point for this code to 
> work.
Below code is okay?

------------------------------> new code start <------------------------------
instance Storable Point where           
  sizeOf _ = #{const sizeof(GdkPoint)}
  alignment _ = alignment (undefined:: #gtk2hs_type gint)
  peek ptr = do
    (x_      ::#gtk2hs_type gint)       <- #{peek GdkPoint, x} ptr
    (y_      ::#gtk2hs_type gint)       <- #{peek GdkPoint, y} ptr
    return $ (fromIntegral x_, fromIntegral y_) 
  poke ptr (x, y) = do
    #{poke GdkPoint, x} ptr ((fromIntegral x)::#gtk2hs_type gint)
    #{poke GdkPoint, y} ptr ((fromIntegral y)::#gtk2hs_type gint)

-- | Fetches the set of attach points for an icon. An attach point is a 
location in the icon that can be
-- used as anchor points for attaching emblems or overlays to the icon.
iconInfoGetAttachPoints :: IconInfo -> IO (Maybe [Point])
iconInfoGetAttachPoints self =
  alloca $ \arrPtrPtr -> 
  alloca $ \nPointsPtr -> do
  success <- liftM toBool $ 
            {# call gtk_icon_info_get_attach_points #}
              self
              (castPtr arrPtrPtr)
              nPointsPtr
  if success 
     then do
       arrPtr <- peek arrPtrPtr
       nPoints <- peek nPointsPtr
       pointList <- peekArray (fromIntegral nPoints) arrPtr
       {#call unsafe g_free#} (castPtr arrPtrPtr)
       return $ Just pointList
     else return Nothing
------------------------------> new code end   <------------------------------

As i have create Storable instance for Point, i remove `peekPoint` from
Structs.hsc, it's unnecessary.

Please point my error, i will improve it.

Thanks,

  -- Andy

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

_______________________________________________
Gtk2hs-devel mailing list
Gtk2hs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gtk2hs-devel

Reply via email to