void mainWindow_press( GtkWidget* widget, GdkEventButton* event, gpointer callback_data ) { if ( event->button == 1 ) { gdk_window_raise(widget->window ); gdk_pointer_grab(widget->window, FALSE, (GdkEventMask) ( GDK_BUTTON_MOTION_MASK | GDK_BUTTON_RELEASE_MASK ), GDK_NONE, GDK_NONE, GDK_CURRENT_TIME); offset_x = (int)event->x; offset_y = (int)event->y; indrag=1; } else if ( event->button == 3 ) { int x,y; gdk_window_get_pointer( NULL, &x, &y, NULL ); gtk_item_factory_popup( GTK_ITEM_FACTORY( mainMenu ), x, y, 3, GDK_CURRENT_TIME ); } }
/****************************************************************************** * gtk_ItemFactoryDeleteEntry( itemFactory, entry ) --> NIL *****************************************************************************/ int clip_GTK_ITEMFACTORYDELETEENTRY(ClipMachine * cm) { C_object *citem = _fetch_co_arg(cm); ClipArrVar *cventry = (ClipArrVar *)_clip_vptr(_clip_par(cm, 2)); GtkItemFactoryEntry entry ; ClipVar *cfunc ; C_var *data ; CHECKARG(1, MAP_t); CHECKCOBJ(citem, GTK_IS_ITEM_FACTORY(citem->object)); CHECKARG(2, ARRAY_t); entry.path = (cventry->items[0].t.type==UNDEF_t)?NULL:cventry->items[0].s.str.buf; entry.accelerator = (cventry->items[1].t.type==UNDEF_t)?NULL:cventry->items[1].s.str.buf; cfunc = &cventry->items[2]; data = NEW(C_var); data->cm = cm; data->co = citem; _clip_mclone(cm, &data->cfunc, cfunc); entry.callback = (cfunc==NULL)?0:(GtkItemFactoryCallback1)_item_factory_callback1; entry.callback_action = (cventry->items[3].t.type==UNDEF_t)?0:(guint)cventry->items[3].n.d; entry.item_type = (cventry->items[4].t.type==UNDEF_t)?NULL:cventry->items[4].s.str.buf; gtk_item_factory_delete_entry(GTK_ITEM_FACTORY(citem->object), &entry); return 0; err: return 1; }
gint button_press_event(GtkWidget *widget, GdkEventButton *event) { GtkTextIter iter; guint offset; gint buffer_x, buffer_y; GdkRectangle location; gboolean too_far=FALSE; LOG(LOG_DEBUG, "IN : button_press_event()"); if((event->type == GDK_BUTTON_PRESS) && (event->button == 1)){ // If you don't convert position as buffer origin, // position will be invalid when scrolling gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(widget), GTK_TEXT_WINDOW_TEXT, (gint)(event->x), (gint)(event->y), &buffer_x, &buffer_y); gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(widget), &iter, buffer_x, buffer_y); offset = gtk_text_iter_get_offset(&iter); gtk_text_view_get_iter_location(GTK_TEXT_VIEW(widget), &iter, &location); if((buffer_x >= location.x + font_width) || (buffer_x <= location.x - font_width)) too_far = TRUE; else too_far = FALSE; if(scan_link(offset) && !too_far){ if(follow_link(offset) == TRUE) return(TRUE); } } else if((event->type == GDK_BUTTON_PRESS) && ((event->button == 2) || (event->button == 3))){ gtk_item_factory_popup(GTK_ITEM_FACTORY(text_item_factory), event->x_root, event->y_root, event->button, event->time); LOG(LOG_DEBUG, "OUT : button_press_event() = TRUE"); return(TRUE); } //gdk_window_get_pointer(widget->window, &x, &y, &mask); LOG(LOG_DEBUG, "OUT : button_press_event() = FALSE"); return(FALSE); }
/****************************************************************************** * gtk_ItemFactoryDeleteItem( itemFactory, spath ) --> NIL ******************************************************************************/ int clip_GTK_ITEMFACTORYDELETEITEM(ClipMachine * cm) { C_object *citem = _fetch_co_arg(cm); const gchar *path = _clip_parc(cm, 2); CHECKARG(1, MAP_t); CHECKCOBJ(citem, GTK_IS_ITEM_FACTORY(citem->object)); CHECKARG(2, CHARACTER_t); gtk_item_factory_delete_item(GTK_ITEM_FACTORY(citem->object), path ); return 0; err: return 1; }
/****************************************************************************** * gtk_ItemFactoryCreateItems( itemFactory, array_entry ) --> NIL ******************************************************************************/ int clip_GTK_ITEMFACTORYCREATEITEMS(ClipMachine * cm) { C_object *citem = _fetch_co_arg(cm); ClipArrVar *cventry = (ClipArrVar *)_clip_vptr(_clip_par(cm, 2)); gint i, n ; CHECKARG(1, MAP_t); CHECKCOBJ(citem, GTK_IS_ITEM_FACTORY(citem->object)); CHECKARG(2, ARRAY_t); n = cventry->count; for (i=0; i<n; i++) { ClipArrVar *it = (ClipArrVar *)_clip_vptr(cventry->items[i].a.items); ClipVar *cfunc ; C_var *c ; GtkItemFactoryEntry entry; entry.path = (it->items[0].t.type==UNDEF_t)?NULL:it->items[0].s.str.buf; entry.accelerator = (it->items[1].t.type==UNDEF_t)?NULL:it->items[1].s.str.buf; cfunc = (it->items[2].t.type==UNDEF_t)?NULL:&it->items[2]; c = NEW(C_var); c->cm = cm; c->co = citem; _clip_mclone(cm, &c->cfunc, cfunc); entry.callback = (cfunc==NULL)?0:(GtkItemFactoryCallback1)_item_factory_callback1; entry.callback_action = 1; entry.item_type = (it->items[4].t.type==UNDEF_t)?0:it->items[4].s.str.buf; //citem->destroy = __itemfactory_destroy_data; //citem->data = c; gtk_item_factory_create_item(GTK_ITEM_FACTORY(citem->object), &entry, c, 1); } return 0; err: return 1; }
/****************************************************************************** * gtk_ItemFactoryGetWidget( itemFactory, spath ) --> widget ******************************************************************************/ int clip_GTK_ITEMFACTORYGETWIDGET(ClipMachine * cm) { C_object *citem = _fetch_co_arg(cm); const gchar *path = _clip_parc(cm, 2); GtkWidget *wid ; C_widget *cwid ; CHECKARG(1, MAP_t); CHECKCOBJ(citem, GTK_IS_ITEM_FACTORY(citem->object)); CHECKARG(2, CHARACTER_t); wid = gtk_item_factory_get_widget(GTK_ITEM_FACTORY(citem->object), path); if (!wid) goto err; cwid = _register_widget(cm, wid, NULL); _clip_mclone(cm,RETPTR(cm),&cwid->obj); return 0; err: return 1; }
/****************************************************************************** * gtk_ItemFactoryConstruct( itemFactory, container_type, spath, accel_group ) --> NIL * container_type is one of :GTK_TYPE_MENU_BAR, GTK_TYPE_MENU or GTK_TYPE_OPTION_MENU ******************************************************************************/ int clip_GTK_ITEMFACTORYCONSTRUCT(ClipMachine * cm) { C_object *citem = _fetch_co_arg(cm); GtkType type = INT_OPTION(cm, 2, GTK_TYPE_MENU_BAR); const gchar *path = _clip_parc(cm, 3); C_object *caccel = _fetch_cobject(cm, _clip_spar(cm, 4)); CHECKARG(1, MAP_t); CHECKCOBJ(citem, GTK_IS_ITEM_FACTORY(citem->object)); CHECKARG(2, NUMERIC_t); CHECKARG(3, CHARACTER_t); CHECKOPT(4, MAP_t); CHECKCOBJOPT(caccel, GTK_IS_ACCEL_GROUP(caccel->object)); gtk_item_factory_construct(GTK_ITEM_FACTORY(citem->object), type, path, GTK_ACCEL_GROUP(caccel->object)); return 0; err: return 1; }
/****************************************************************************** * gtk_ItemFactoryGetItemByAction( itemFactory, naction ) --> widget ******************************************************************************/ int clip_GTK_ITEMFACTORYGETITEMBYACTION(ClipMachine * cm) { C_object *citem = _fetch_co_arg(cm); gint action = _clip_parni(cm, 2); GtkWidget *wid ; C_widget *cwid ; CHECKARG(1, MAP_t); CHECKCOBJ(citem, GTK_IS_ITEM_FACTORY(citem->object)); CHECKARG(2, NUMERIC_t); wid = gtk_item_factory_get_item_by_action( GTK_ITEM_FACTORY(citem->object), action); if (!wid) goto err; cwid = _register_widget(cm, wid, NULL); _clip_mclone(cm,RETPTR(cm),&cwid->obj); return 0; err: return 1; }
/****************************************************************************** * gtk_ItemFactoryPopup( itemFactory, nx, ny, nmouse_button, ntime ) --> NIL * itemFactory of type GLIP_GTK_TYPE_MENU ******************************************************************************/ int clip_GTK_ITEMFACTORYPOPUP(ClipMachine * cm) { C_object *citem = _fetch_co_arg(cm); gint x = _clip_parni(cm, 2); gint y = _clip_parni(cm, 3); gint mouse_button = _clip_parni(cm, 4); guint32 time = _clip_parni(cm, 5); CHECKARG(1, MAP_t); CHECKCOBJ(citem, GTK_IS_ITEM_FACTORY(citem->object)); CHECKARG(2, NUMERIC_t); CHECKARG(3, NUMERIC_t); CHECKARG(4, NUMERIC_t); CHECKARG(5, NUMERIC_t); gtk_item_factory_popup(GTK_ITEM_FACTORY(citem->object), x, y, mouse_button, time ); return 0; err: return 1; }
/** * gwy_graph_func_build_menu: * @item_factory: A #GtkItemFactory to add items to. * @prefix: Where to add the menu items to the factory. * @item_callback: A #GtkItemFactoryCallback1 called when an item from the * menu is selected. * * Creates #GtkItemFactory for a graph menu with all registered graph * functions. * * Returns: The menu item factory as a #GtkObject. **/ GtkObject* gwy_graph_func_build_menu(GtkObject *item_factory, const gchar *prefix, GCallback item_callback) { GtkItemFactoryEntry branch = { NULL, NULL, NULL, 0, "<Branch>", NULL }; GtkItemFactoryEntry tearoff = { NULL, NULL, NULL, 0, "<Tearoff>", NULL }; GtkItemFactoryEntry item = { NULL, NULL, item_callback, 0, "<Item>", NULL }; GtkItemFactory *factory; GString *current, *prev; const gchar *mpath; GSList *l, *entries = NULL; gint i, dp_len; g_return_val_if_fail(GTK_IS_ITEM_FACTORY(item_factory), NULL); factory = GTK_ITEM_FACTORY(item_factory); if (!graph_funcs) { g_warning("No graph function present to build menu of"); entries = NULL; } else g_hash_table_foreach(graph_funcs, gwy_hash_table_to_slist_cb, &entries); entries = g_slist_sort(entries, (GCompareFunc)graph_menu_entry_compare); dp_len = strlen(prefix); /* the root branch */ current = g_string_new(prefix); /* the root tearoff */ prev = g_string_new(prefix); g_string_append(prev, "/---"); tearoff.path = prev->str; gtk_item_factory_create_item(factory, &tearoff, NULL, 1); /* create missing branches * XXX: Gtk+ essentially can do this itself * but this way we can e. g. put a tearoff at the top of each branch... */ for (l = entries; l; l = g_slist_next(l)) { GraphFuncInfo *func_info = (GraphFuncInfo*)l->data; mpath = func_info->menu_path_translated; if (!mpath || !*mpath) continue; if (mpath[0] != '/') { g_warning("Menu path `%s' doesn't start with a slash", mpath); continue; } g_string_truncate(current, dp_len); g_string_append(current, mpath); /* find where the paths differ */ i = gwy_strdiffpos(current->str + dp_len, prev->str + dp_len); if (!current->str[i] && !prev->str[i]) g_warning("Duplicate menu entry `%s'", mpath); else { /* find where the next / is */ do { i++; } while (current->str[i] && current->str[i] != '/'); } while (current->str[i]) { /* create a branch with a tearoff */ current->str[i] = '\0'; branch.path = current->str; gtk_item_factory_create_item(factory, &branch, NULL, 1); g_string_assign(prev, current->str); g_string_append(prev, "/---"); tearoff.path = prev->str; gtk_item_factory_create_item(factory, &tearoff, NULL, 1); current->str[i] = '/'; /* find where the next / is */ do { i++; } while (current->str[i] && current->str[i] != '/'); } /* XXX: passing directly func_info->name may be a little dangerous, * OTOH who would eventually free a newly allocated string? */ item.path = current->str; gtk_item_factory_create_item(factory, &item, (gpointer)func_info->info.name, 1); GWY_SWAP(GString*, current, prev); } g_string_free(prev, TRUE); g_string_free(current, TRUE); g_slist_free(entries); return item_factory; }