gboolean iupgtkButtonEvent(GtkWidget *widget, GdkEventButton *evt, Ihandle *ih) { IFniiiis cb = (IFniiiis)IupGetCallback(ih,"BUTTON_CB"); if (cb) { int doubleclick = 0, ret, press = 1; int b = IUP_BUTTON1+(evt->button-1); char status[IUPKEY_STATUS_SIZE] = IUPKEY_STATUS_INIT; if (evt->type == GDK_BUTTON_RELEASE) press = 0; if (evt->type == GDK_2BUTTON_PRESS) doubleclick = 1; iupgtkButtonKeySetStatus(evt->state, evt->button, status, doubleclick); ret = cb(ih, b, press, (int)evt->x, (int)evt->y, status); if (ret==IUP_CLOSE) IupExitLoop(); else if (ret==IUP_IGNORE) return TRUE; } (void)widget; return FALSE; }
gboolean iupgtkMotionNotifyEvent(GtkWidget *widget, GdkEventMotion *evt, Ihandle *ih) { IFniis cb = (IFniis)IupGetCallback(ih,"MOTION_CB"); if (cb) { char status[IUPKEY_STATUS_SIZE] = IUPKEY_STATUS_INIT; iupgtkButtonKeySetStatus(evt->state, 0, status, 0); cb(ih, (int)evt->x, (int)evt->y, status); } (void)widget; return FALSE; }
static gboolean gtkCanvasScrollEvent(GtkWidget *widget, GdkEventScroll *evt, Ihandle *ih) { /* occours only for the mouse wheel. Not related to the scrollbars */ IFnfiis wcb = (IFnfiis)IupGetCallback(ih, "WHEEL_CB"); if (wcb) { int delta = evt->direction==GDK_SCROLL_UP||evt->direction==GDK_SCROLL_LEFT? 1: -1; char status[IUPKEY_STATUS_SIZE] = IUPKEY_STATUS_INIT; int button = evt->direction==GDK_SCROLL_UP||evt->direction==GDK_SCROLL_LEFT? 4: 5; iupgtkButtonKeySetStatus(evt->state, button, status, 0); wcb(ih, (float)delta, (int)evt->x, (int)evt->y, status); } else { IFniff scb = (IFniff)IupGetCallback(ih,"SCROLL_CB"); int delta = evt->direction==GDK_SCROLL_UP||evt->direction==GDK_SCROLL_LEFT? 1: -1; if (evt->direction==GDK_SCROLL_UP || evt->direction==GDK_SCROLL_DOWN) { float posy = ih->data->posy; posy -= delta*iupAttribGetFloat(ih, "DY")/10.0f; IupSetfAttribute(ih, "POSY", "%g", posy); } else { float posx = ih->data->posx; posx -= delta*iupAttribGetFloat(ih, "DX")/10.0f; IupSetfAttribute(ih, "POSX", "%g", posx); } if (scb) { int scroll_gtk2iup[4] = {IUP_SBUP, IUP_SBDN, IUP_SBLEFT, IUP_SBRIGHT}; int op = scroll_gtk2iup[evt->direction]; scb(ih,op,ih->data->posx,ih->data->posy); } } (void)widget; return TRUE; }
static gboolean gtkDragMotion(GtkWidget *widget, GdkDragContext *drag_context, gint x, gint y, guint time, Ihandle* ih) { GdkAtom targetAtom; /* The third argument must be NULL. Internally, GTK will use the list returned by the call gtk_drag_dest_get_target_list(widget), which is the list of targets that be destination widget can accept (defined in the gtkSetDropTargetAttrib IUP) */ targetAtom = gtk_drag_dest_find_target(widget, drag_context, NULL); if(targetAtom != GDK_NONE) { IFniis cbDropMotion = (IFniis)IupGetCallback(ih, "DROPMOTION_CB"); if(cbDropMotion) { char status[IUPKEY_STATUS_SIZE] = IUPKEY_STATUS_INIT; GdkModifierType mask; gdk_window_get_pointer(iupgtkGetWindow(widget), NULL, NULL, &mask); iupgtkButtonKeySetStatus(mask, 0, status, 0); cbDropMotion(ih, x, y, status); } #if GTK_CHECK_VERSION(2, 22, 0) gdk_drag_status(drag_context, gdk_drag_context_get_suggested_action(drag_context), time); #else gdk_drag_status(drag_context, drag_context->suggested_action, time); #endif return TRUE; } (void)ih; (void)x; (void)y; gdk_drag_status(drag_context, 0, time); return FALSE; }
static void iGdkEventFunc(GdkEvent *evt, gpointer data) { switch(evt->type) { case GDK_BUTTON_PRESS: case GDK_2BUTTON_PRESS: case GDK_3BUTTON_PRESS: case GDK_BUTTON_RELEASE: { IFiiiis cb = (IFiiiis)IupGetFunction("GLOBALBUTTON_CB"); if (cb) { GdkEventButton* evt_button = (GdkEventButton*)evt; gint win_x = 0, win_y = 0; int doubleclick = 0, press = 1; int b = IUP_BUTTON1+(evt_button->button-1); char status[IUPKEY_STATUS_SIZE] = IUPKEY_STATUS_INIT; int x = (int)evt_button->x; int y = (int)evt_button->y; if (evt_button->type == GDK_BUTTON_RELEASE) press = 0; if (evt_button->type == GDK_2BUTTON_PRESS) doubleclick = 1; iupgtkButtonKeySetStatus(evt_button->state, evt_button->button, status, doubleclick); gdk_window_get_origin(evt_button->window, &win_x, &win_y); /* GDK window relative to screen */ x += win_x; y += win_y; if (doubleclick) { /* Must compensate the fact that in GTK there is an extra button press event when occours a double click, we compensate that completing the event with a button release before the double click. */ status[5] = ' '; /* clear double click */ cb(b, 0, x, y, status); /* release */ status[5] = 'D'; /* restore double click */ } cb(b, press, x, y, status); } break; } case GDK_MOTION_NOTIFY: { IFiis cb = (IFiis)IupGetFunction("GLOBALMOTION_CB"); if (cb) { GdkEventMotion* evt_motion = (GdkEventMotion*)evt; gint win_x = 0, win_y = 0; int x = (int)evt_motion->x; int y = (int)evt_motion->y; char status[IUPKEY_STATUS_SIZE] = IUPKEY_STATUS_INIT; iupgtkButtonKeySetStatus(evt_motion->state, 0, status, 0); if (evt_motion->is_hint) iupgtkWindowGetPointer(evt_motion->window, &x, &y, NULL); gdk_window_get_origin(evt_motion->window, &win_x, &win_y); /* GDK window relative to screen */ x += win_x; y += win_y; cb(x, y, status); } break; } case GDK_KEY_PRESS: case GDK_KEY_RELEASE: { IFii cb = (IFii)IupGetFunction("GLOBALKEYPRESS_CB"); if (cb) { int pressed = (evt->type==GDK_KEY_PRESS)? 1: 0; int code = iupgtkKeyDecode((GdkEventKey*)evt); if (code != 0) cb(code, pressed); } break; } default: break; } (void)data; gtk_main_do_event(evt); }