Re: (no subject)



jalkadir gosonic ca writes:

> I have been racking my brains trying to find informatio about writing a
> callback function that receives two parameters one that indicates the type
> of icon I want displayed and the other a character string variable that
> holds the different messages this callback function will pass to a a
> dialogbox.
>
> This is what the callback function looks like, or I think it would look like:
> typedef struct{
>       gchar* str; // Message
>       GtkWidget* obj; // Icon
>    }DATA;
> void GeneralMsg(DATA&);
> void GeneralMsg(DATA& d){
>        // Create and display a message box with the information in the
> DATA variable
>        .....
> }
>
> Is this possible?

Well, yes, I guess.  Personally, I'd go for a simpler and cleaner
approach:

typedef enum
{
  MY_MESSAGE_FOO,
  MY_MESSAGE_BAR
} MyMessage

And for the callback:

void
my_message_callback (MyMessage message_type,
                     GtkWidget *widget)
{
 ...
}

However, if by callback you mean a signal handler, I would create a
signal and class vfunc to do that, and also create a custom marshaller
using glib-genmarshal (VOID:ENUM,OBJECT =>
my_cclosure_marshal_VOID__ENUM_OBJECT)

Read the excellent GObject tutorial (in the Glib 2.8 API reference)
for more detail on how to create and emit signals.

Something like

typedef void (*MyMessageFunc)(MyMessage message_type, GtkWidget
*widget);

struct _MyClass
{
  MyMessageFunc *message;
}

And in your class_init:

my_signals[SIGNAL_MESSAGE] =
    g_signal_new ("message",
                  G_OBJECT_CLASS_TYPE(klass),
                  G_SIGNAL_RUN_LAST,
                  G_STRUCT_OFFSET (MyClass, message),
                  NULL, NULL,
                  my_cclosure_marshal_VOID__ENUM_OBJECT,
                  G_TYPE_VOID, 2, G_TYPE_ENUM, G_TYPE_OBJECT);


Regards,
Roger

-- 
Roger Leigh
                Printing on GNU/Linux?  http://gimp-print.sourceforge.net/
                Debian GNU/Linux        http://www.debian.org/
                GPG Public Key: 0x25BFB848.  Please sign and encrypt your mail.



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