Hi Matt,

Sorry for inconvenience!

I have fix this bug in darcs version with below code:

------------------------------> new version start 
<------------------------------
insertText :: EditableClass self => Signal self (String -> Int -> IO Int)
insertText = Signal (connect_STRINGPTR_INT__INTPTR "insert-text")

-- | Singal helper functions.
connect_STRINGPTR_INT__INTPTR ::
    EditableClass self => SignalName ->
    ConnectAfter -> self ->
    (String -> Int -> IO Int) ->
    IO (ConnectId self)
connect_STRINGPTR_INT__INTPTR signal after obj user =
    connectGeneric signal after obj
       (\strPtr strLen posPtr -> do
          str <- if strLen<0 then peekUTFString strPtr
                else peekUTFStringLen (strPtr, strLen)
          pos <- peek (posPtr :: Ptr {#type gint#})
          pos' <- user str (fromIntegral pos)
          poke (posPtr :: Ptr {#type gint#}) (fromIntegral pos'))
------------------------------> new version end   
<------------------------------

Thanks for your report!

  -- Andy

Matt Arsenault <arse...@rpi.edu> writes:

> Hi,
>
> I happened to come across a problem with the insertText signal for
> Editable in Gtk.
>
> I'm having problems getting the autotools to actually build, so I
> haven't exactly fixed it myself.
>
> In gtk/Graphics/UI/Gtk/Entry/Editable.chs.pp:
>
>>  insertText :: EditableClass self => Signal self (String -> Int -> Int
> -> IO ())
>>  insertText = Signal (connect_STRING_INT_INT__NONE "insert-text")
>
>
> However, this is wrong. This doesn't match what the
> onInsertText/afterInsertText do, and what the callback is supposed to
> be.
>
> The C callback is supposed to be
>  (GtkEditable *editable, 
>   gchar *new_text, 
>   gint new_text_length, 
>   gint *position, 
>   gpointer user_data)
>
> Where the position argument is an in and out argument which is kind of
> weird. onInsertText/afterInsertText handle this, but insertText does
> not. insertText will just treat a pointer as an int, and doesn't respect
> the out argument aspect at all. 
>
> onInsertText:
>
>> onInsertText, afterInsertText :: EditableClass self => self
>>  -> (String -> Int -> IO Int)
>> -> IO (ConnectId self)
>> onInsertText obj handler =
>>  connect_PTR_INT_PTR__NONE "insert_text" False obj
>>  (\strPtr strLen posPtr -> do
>>    str <- if strLen<0 then peekUTFString strPtr
>>         else peekUTFStringLen (strPtr, strLen)
>>    pos <- peek (posPtr :: Ptr {#type gint#})
>>    pos' <- handler str (fromIntegral pos)
>>    poke (posPtr :: Ptr {#type gint#}) (fromIntegral pos')
>>  )
>
>
> This should be something more like this, except I haven't actually
> tested it since I gave up on trying to get current darcs gtk2hs built
> and didn't have time to fight with it.
>
>>  insertText :: EditableClass self => Signal self (String -> Int -> IO
> Int)
>>  insertText = Signal $ 
>>  connect_PTR_INT_PTR__NONE "insert_text"
>>  (\strPtr strLen posPtr -> do
>>    str <- if strLen<0 then peekUTFString strPtr
>>         else peekUTFStringLen (strPtr, strLen)
>>    pos <- peek (posPtr :: Ptr {#type gint#})
>>    pos' <- handler str (fromIntegral pos)
>>    poke (posPtr :: Ptr {#type gint#}) (fromIntegral pos')
>>  )
>
>
> - Matt Arsenault
>
>
>
> ------------------------------------------------------------------------------
> Download Intel&#174; Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev


------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Gtk2hs-devel mailing list
Gtk2hs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gtk2hs-devel

Reply via email to