Re: Making Signal For A Widget.



Tristan Van Berkom wrote:

B. Souliotis wrote:

Gustavo J. A. M. Carneiro wrote:

A Ter, 2003-06-03 às 15:05, B. Souliotis escreveu:
Gustavo J. A. M. Carneiro wrote:

A Ter, 2003-06-03 às 13:03, B. Souliotis escreveu:


I would like to make a signal for a particular widget that will be emmited when you press the
first mouse button.
I don't want to use the
g_signal_connect(G_OBJECT(widget),"button_press_event",G_CALLBACK(callback),NULL); for the widget Because i want the callback to called only when i press the First mouse button.

So I would like to make something like "clicked" signal for the gtk_button.
IN gtkbutton.c is called
g_signal_new("clicked",....);
but i don't undarstand how this signal is emmited only when the button pressed. So can anyone tell me how you pass the events to g_signal_new that will emmit the new signal.


    What you want to do is:
1. register a new signal with signal_id = g_signal_new(...), but only
once per app!
    2. for each instance of the widget,
g_signal_connect(widget,"button_press_event", callback, NULL)
    3. In the 'callback' function, check if the first button has been
pressed..
    4. ..if so, g_signal_emit(signal_id, ...)

Actually doing what I say becomes more complicated if you are not used
to such things.  Also, this is usually done by creating a new widget
class deriving from the first widget, but this is also a lot of work...
    Good luck.



As far as i know if you make a new widget class i can put in the structure of new widget
something like
widget->button1_pressed = callback_1_pressed



    Right.

after make the signal

signal_id = g_signal_connect(widget,"button1_pressed",callback, NULL);



No. You register a signal with g_signal_new(). g_signal_connect does
not "make" a signal, it connects a signal to a callback.  Let me
summarize the differences between the main signal functions:

o g_signal_new: registers a new signal type; should be done once per
class, usually in the class_init function; returns a signal_id;

    o g_signal_emit: fires a signal once on an instance; receives the
signal_id (registered with g_signal_new), an instance and the signal
parameters, if any; is called multiple times, once for each time the
signal should be fired

    o g_signal_connect: connects a specific handler function to a
instance-signal pair; should be called once per instance for each
signal.

See:

http://developer.gnome.org/doc/API/2.0/gobject/gobject-Signals.html

and in  callback_1_pressed(GtkWidgetNewClass *)
i'll emit the signal with
g_signal_emit(signal_id,......);

The same thing exactly is doing the GtkButtonClass
with the clicked signal.
But I could not Understand how the signal is emitted only for the first button.



So the question is how the signal_id is connected with a specific event like Button1_pressed without using other signals like g_signal_connect(widget,"button_press_event", callback, NULL)
and after emiting the specific signal that you want.



You *have* to do this. There is no other way. With a handler +/- like
this:

static gboolean button_press_event(GtkWidget *widget, GdkEventButton *event)
{
 if (event->button == 1) {
   g_signal_emit (signals[BUTTON_1_PRESSED], widget, 0);
   return TRUE;
 }
 return FALSE;
}

    I think there is not other way to do this.  Or maybe I'm not
understanding you correctly...

Sorry i mispelled the previous mail
I wanted to say

signal_id = g_signal_new("button1_pressed",.......);

than

signal_id = g_signal_connect(widget,"button1_pressed",callback, NULL);

I thing that you are right because also and in GtkButton code
the clicked signal is emmited inside
gtk_button_release_event signal
that looks which button is  pressed.





You might do well to note also that gtkwidget.c is like a HUB for all theese events. As input, you get your GdkEvents and as output, you have a bunch of basic signals that are "emmited" at the GtkWidget level and handlers are "implemented" by various
subclasses.

you should probably read this:
http://developer.gnome.org/doc/API/2.0/gdk/gdk-Event-Structures.html#GdkEventButton

when a "clicked" signal is emitted (by the GtkButtonClass); the mouse button has already been "released". now wether you mean the "Left button", the "button down" or
"button press" by "First" is an entirely different question.

Hope this helps,
                                      -Tristan

I mean which button is pressed not how many times.
I've realized that the clicked signal is emmited (by the GtkButtonClass); with gtk_button_release_event

Thanks
In advance
Bill Souliotis



Why dont you just hook on to the GdkEventButton and check
for the left mouse button instead of writing a signal ?

Tristan.


I want to add such signals to drawing area widget.
So Iwant to add for button left down with Ctrl Modifier a specific signal
also for button left down with Shift Modifier
also for button middle down
also for button middle down with Shift Modifier
and many many more
But i want explicity to load more than one function to a specified signal and after to block or
remove this signal.
So One way to do this is what are you saying and holding to a stack all the functions that was loaded. The other way and more practical i think is to make a new GtkDrawingAreaClass with all signals that i want about mouse buttons and emiting them in button_press_event signal or button_motion_event
signal by checking GdkEventButton that comes in them.

Thanks
In advance
Bill Souliotis






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