Re: Fw: GtkTextBuffer, insert_text - Solved



Really thanks Rich Gautier  for giving me the idea
just wanted to share this,
i had to cast it to a G_OBJECT not GTK_OBJECT and it worked!

insert = g_signal_connect (G_OBJECT (buffer), "insert_text",
simultaneously i've changed the callback prototype to

                                     GTK_SIGNAL_FUNC (text_insert_cb), NULL);
    void text_insert_cb(GtkTextBuffer *buffer,
                            GtkTextIter *pos,
                            const gchar *text,
                            gint length,
                            gpointer user_data)
                 {
                 fprintf(stderr,"%s", text);
                 }
don't know which of the two or if they both have solved it but it did
work now


On Fri, 2002-07-19 at 16:41, Mohammed Sameer wrote:
    i don't care about the property or modifying it
    the inserted text should be passed to the signal handler
    
        void text_insert_cb(GtkTextBuffer *buffer,
                            GtkTextIter pos,
                            const gchar *text,
                            gint length,
                            gpointer user_data)
                 {
                 fprintf(stderr,"%s", text);
                 }
    text should be the inserted text
    i tried 
    insert = g_signal_connect (GTK_TEXT_BUFFER (buffer), "insert_text",
                                         GTK_SIGNAL_FUNC (text_insert_cb), NULL);
    i don't get the worning but still printing garbage ?
    
    i don't know if i understand you or not ??
    
    On Fri, 2002-07-19 at 06:32, Rich Gautier wrote:
         Well, once you have it in your function, you need to recast it to get the
         property out of the widget.
        
         You're only passing in a memory address, after all, and by casting it into
        a
         basic widget/object, you're not going to have the extended properties
         available....  I don't know what the property of buffer is for it to get at
        the
         actual text?  perhaps buffer->text?
        
         The cast you want is something like G_TEXT_BUFFER(buffer), perhaps?  You'll
        have to consult someone who is more  familiar with GTK on that,  all I can
        offer is my suggestion - question is -  did you still get the runtime
        invalid cast error?
        
        > ----- Original Message -----
        > From: "Mohammed Sameer" <uniball gmx net>
        > To: <gtk-app-devel-list gnome org>
        > Sent: Thursday, July 18, 2002 10:54 PM
        > Subject: Re: GtkTextBuffer, insert_text
        >
        >
        > Thanks for the reply
        > still didn't work?
        > i wonder what's the problem!!!!
        >
        > On Fri, 2002-07-19 at 04:21, Rich Gautier wrote:
        >     ï
        >     I think your callback function needs to have GtkWidget *widget as
        >     the first passed parameter.
        >
        >     such as:
        >
        >     void text_insert_cb(GtkWidget *buffer, ..., gpointer user_data)
        >
        >     because the callback function is going to cast it as a basic widget
        >     when it makes the call.  You may be able to recast it once it's in
        >     your callback function, but it's not passed as GtkTextBuffer type..
        >
        >     Rich G
        >         ----- Original Message -----
        >         From: Mohammed Sameer
        >         To: gtk-app-devel-list gnome org
        >         Sent: Thursday, July 18, 2002 7:28 PM
        >         Subject: GtkTextBuffer, insert_text
        >
        >         Hi all
        >         i have a small problem
        >
        >         i have a textbuffer
        >
        >           contents = gtk_text_view_new ();
        >           buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (contents));
        >                 /* Implementing undo/redo... */
        >         insert = g_signal_connect (GTK_OBJECT (buffer), "insert_text",
        >                                 GTK_SIGNAL_FUNC (text_insert_cb), NULL);
        >
        >         and the callback
        >         void text_insert_cb(GtkTextBuffer *buffer,
        >                                                     GtkTextIter pos,
        >                                                     const gchar *text,
        >                                                     gint length,
        >                                                     gpointer user_data)
        >         {
        >         fprintf(stderr,"%s", text);
        >         }
        >
        >         but it prints some garbage
        >         and when i run the program i get:
        >         GLib-GObject-WARNING **: invalid cast from `GtkTextBuffer' to
        >         `GtkObject'
        >
        >         what's the problem here ?
        >         can anyone point me ??
        >
        >         Thanks a million
        >
        >         --
        >         ----------------
        >         -- Uniball @ DALnet
        >         Linux registered user # 224950
        >         ICQ # 58475622
        >         With Great Power, Comes Great Responsibilities.
        > --
        > ----------------
        > -- Uniball @ DALnet
        > Linux registered user # 224950
        > ICQ # 58475622
        > With Great Power, Comes Great Responsibilities.
        >
        > _______________________________________________
        > gtk-app-devel-list mailing list
        > gtk-app-devel-list gnome org
        > http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
        >
        
        _______________________________________________
        gtk-app-devel-list mailing list
        gtk-app-devel-list gnome org
        http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
        
    -- 
    ----------------
    -- Uniball @ DALnet
    Linux registered user # 224950
    ICQ # 58475622
    With Great Power, Comes Great Responsibilities.
    
    _______________________________________________
    gtk-app-devel-list mailing list
    gtk-app-devel-list gnome org
    http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
    
-- 
----------------
-- Uniball @ DALnet
Linux registered user # 224950
ICQ # 58475622
With Great Power, Comes Great Responsibilities.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]