/* Callback when the user toggles the selection */ static void selection_toggled( GtkWidget *widget, gint *have_selection ) { if (GTK_TOGGLE_BUTTON (widget)->active) { *have_selection = gtk_selection_owner_set (selection_widget, GDK_SELECTION_PRIMARY, GDK_CURRENT_TIME); /* if claiming the selection failed, we return the button to the out state */ if (!*have_selection) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE); } else { if (*have_selection) { /* Before clearing the selection by setting the owner to NULL, we check if we are the actual owner */ if (gdk_selection_owner_get (GDK_SELECTION_PRIMARY) == widget->window) gtk_selection_owner_set (NULL, GDK_SELECTION_PRIMARY, GDK_CURRENT_TIME); *have_selection = FALSE; } } }
static gint toggle_button_toggled_cb(GtkToggleButton *button, gpointer data) { charpick_data *curr_data = data; gint button_index; gboolean toggled; button_index = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button), "index")); toggled = gtk_toggle_button_get_active (button); if (toggled) { gunichar unichar; if (curr_data->last_toggle_button && (button != curr_data->last_toggle_button)) gtk_toggle_button_set_active (curr_data->last_toggle_button, FALSE); curr_data->last_toggle_button = button; gtk_widget_grab_focus(curr_data->applet); unichar = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button), "unichar")); curr_data->selected_unichar = unichar; /* set this? widget as the selection owner */ gtk_selection_owner_set (curr_data->applet, GDK_SELECTION_PRIMARY, GDK_CURRENT_TIME); gtk_selection_owner_set (curr_data->applet, GDK_SELECTION_CLIPBOARD, GDK_CURRENT_TIME); curr_data->last_index = button_index; } return TRUE; }
/* 当用户触发选中区时的回调 */ void selection_toggled( GtkWidget *widget, gint *have_selection ) { if (GTK_TOGGLE_BUTTON (widget)->active) { *have_selection = gtk_selection_owner_set (selection_widget, GDK_SELECTION_PRIMARY, GDK_CURRENT_TIME); /* 如果声称选中区失败,则使按钮返回未选中状态 */ if (!*have_selection) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE); } else { if (*have_selection) { /* 在设置所有者为NULL来清空选中区前, * 先检测自己是不是真正的所有者 */ if (gdk_selection_owner_get (GDK_SELECTION_PRIMARY) == widget->window) gtk_selection_owner_set (NULL, GDK_SELECTION_PRIMARY, GDK_CURRENT_TIME); *have_selection = FALSE; } } }
void wxClipboard::Clear() { if (m_data) { #if wxUSE_THREADS /* disable GUI threads */ #endif /* As we have data we also own the clipboard. Once we no longer own it, clear_selection is called which will set m_data to zero */ #if 0 if (gdk_selection_owner_get( g_clipboardAtom ) == m_clipboardWidget->window) { m_waiting = true; gtk_selection_owner_set( NULL, g_clipboardAtom, (guint32) GDK_CURRENT_TIME ); while (m_waiting) gtk_main_iteration(); } if (gdk_selection_owner_get( GDK_SELECTION_PRIMARY ) == m_clipboardWidget->window) { m_waiting = true; gtk_selection_owner_set( NULL, GDK_SELECTION_PRIMARY, (guint32) GDK_CURRENT_TIME ); while (m_waiting) gtk_main_iteration(); } #endif if (m_data) { delete m_data; m_data = NULL; } #if wxUSE_THREADS /* re-enable GUI threads */ #endif } m_targetRequested = 0; m_formatSupported = false; }
void NavGtk::set_selection_owner( int set) { gboolean sts; if ( set) { sts = gtk_selection_owner_set( selection_widget, GDK_SELECTION_PRIMARY, gtk_get_current_event_time()); if ( !sts) { brow_SelectClear( brow_ctx); return; } selection_owner = 1; } else { sts = gtk_selection_owner_set( NULL, GDK_SELECTION_PRIMARY, gtk_get_current_event_time()); selection_owner = 0; } }
int appDocOwnSelection( EditDocument * ed, const char * selection, AppSelectionTargetType * targets, int targetCount ) { int i; AppSelectionType * ast; EditApplication * ea= ed->edApplication; ast= ea->eaDocSelectionTypes; for ( i= 0; i < ea->eaDocSelectionTypeCount; ast++, i++ ) { if ( ! strcmp( ast->astSelectionString, selection ) ) { break; } } if ( i >= ea->eaDocSelectionTypeCount ) { SDEB(selection); return -1; } if ( ast->astTargetTypeCount == 0 ) { SLDEB(selection,ast->astTargetTypeCount); return -1; } for ( i= 0; i < targetCount; i++ ) { if ( ! targets[i].asttTargetAtom ) { targets[i].asttTargetAtom= gdk_atom_intern( targets[i].asttTargetString, 0 ); if ( ! targets[i].asttTargetAtom ) { SDEB(targets[i].asttTargetString); XDEB(targets[i].asttTargetAtom); return -1; } } gtk_selection_add_target( ed->edDocumentWidget, ast->astSelectionAtom, targets[i].asttTargetAtom, 0 ); } ed->edTargetTypes= targets; ed->edTargetTypeCount= targetCount; if ( ! gtk_selection_owner_set( ed->edDocumentWidget, ast->astSelectionAtom, GDK_CURRENT_TIME ) ) { return -1; } return 0; }
/* * get clipboard content - partialy inspired by Downloader for X */ gboolean my_get_xselection(GtkWidget *window, GdkEvent *event) { GdkAtom atom; gint format; size_t length; gchar *content = NULL; /* previous clipboard content */ static size_t old_content_len = 0; static gchar *old_content = ""; begin_func("my_get_xselection"); gtk_clipboard_request_text(gtk_clipboard_get(clipboard), my_get_selection_text, NULL); return_val(TRUE); length = (size_t) gdk_selection_property_get(gtk_widget_get_window(window), (guchar **) &content, &atom, &format); if (length > 0) { if ((length != old_content_len || memcmp(content, old_content, length) != 0) && !gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_app_clip_ignore))) { /* new data in clipboard */ /* store new content for future comparation */ if (old_content_len > 0) g_free(old_content); old_content = content; old_content_len = length; /* process item */ /* process_item(content, length, 0, TRUE); */ } else { /* no new data */ g_free(content); } /* when clipboard is locked, set selection owener to myself */ if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_app_clip_ignore)) || gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_app_clip_lock))) { if (gtk_selection_owner_set(dock_app, clipboard, GDK_CURRENT_TIME) == 0) selected = NULL; } } return_val(TRUE); }
void selection_toggled (GtkWidget *widget) { if (GTK_TOGGLE_BUTTON(widget)->active) { have_selection = gtk_selection_owner_set (selection_widget, GDK_SELECTION_PRIMARY, GDK_CURRENT_TIME); if (!have_selection) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(widget), FALSE); } else { if (have_selection) { if (gdk_selection_owner_get (GDK_SELECTION_PRIMARY) == widget->window) gtk_selection_owner_set (NULL, GDK_SELECTION_PRIMARY, GDK_CURRENT_TIME); have_selection = FALSE; } } }
static gboolean drw_selection_claim (DrwSelection *drw_selection) { drw_selection->invisible = gtk_invisible_new (); g_signal_connect (drw_selection->invisible, "selection-clear-event", G_CALLBACK (drw_selection_clear), drw_selection); if (gtk_selection_owner_set (drw_selection->invisible, gdk_atom_intern (SELECTION_NAME, FALSE), GDK_CURRENT_TIME)) { return TRUE; } else { drw_selection_reset (drw_selection); return FALSE; } }
void my_get_selection_text(GtkClipboard *cb, const gchar *text, gpointer data) { /* previous clipboard content */ static gchar *old_content = ""; static gint has_old_content = 0; gchar *content; gchar *converted; begin_func("my_get_selection_text"); if (text == NULL) { return_void(); } if (g_utf8_collate(text, old_content) != 0 && !gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_app_clip_ignore))) { /* new data in clipboard */ /* store new content for future comparation */ content = g_strdup(text); converted = from_utf8(content); /* fprintf(stderr, ">>> %s\n", converted); */ g_free(converted); if (has_old_content > 0) g_free(old_content); old_content = content; has_old_content = 1; /* process item */ process_item(content, 0, TRUE); } /* when clipboard is locked, set selection owener to myself */ if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_app_clip_ignore)) || gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_app_clip_lock))) { if (gtk_selection_owner_set(dock_app, clipboard, GDK_CURRENT_TIME) == 0) selected = NULL; } return_void(); }
bool wxClipboard::SetSelectionOwner(bool set) { bool rc = gtk_selection_owner_set ( set ? m_clipboardWidget : NULL, GTKGetClipboardAtom(), (guint32)GDK_CURRENT_TIME ) != 0; if ( !rc ) { wxLogTrace(TRACE_CLIPBOARD, wxT("Failed to %sset selection owner"), set ? wxT("") : wxT("un")); } return rc; }
static VALUE gtkdrag_selection_owner_set(int argc, VALUE *argv, VALUE self) { gboolean ret; if (argc == 3){ VALUE widget, selection, time; rb_scan_args(argc, argv, "30", &widget, &selection, &time); ret = gtk_selection_owner_set(RVAL2WIDGET(widget), RVAL2ATOM(selection), NUM2INT(time)); } else { #if GTK_CHECK_VERSION(2,2,0) VALUE display, widget, selection, time; rb_scan_args(argc, argv, "40", &display, &widget, &selection, &time); ret = gtk_selection_owner_set_for_display(GDK_DISPLAY_OBJECT(RVAL2GOBJ(display)), RVAL2WIDGET(widget), RVAL2ATOM(selection), NUM2INT(time)); #else rb_raise(rb_eArgError, "Wrong number of arguments: %d", argc); #endif } return CBOOL2RVAL(ret); }
bool wxClipboard::AddData( wxDataObject *data ) { #if wxUSE_NANOX return false; #else wxCHECK_MSG( m_open, false, wxT("clipboard not open") ); wxCHECK_MSG( data, false, wxT("data is invalid") ); /* we can only store one wxDataObject */ Clear(); m_data = data; /* get formats from wxDataObjects */ wxDataFormat *array = new wxDataFormat[ m_data->GetFormatCount() ]; m_data->GetAllFormats( array ); #if 0 /* primary selection or clipboard */ Atom clipboard = m_usePrimary ? (Atom) 1 // 1 = primary selection : g_clipboardAtom; #endif // 0 for (size_t i = 0; i < m_data->GetFormatCount(); i++) { wxLogTrace( TRACE_CLIPBOARD, wxT("wxClipboard now supports atom %s"), array[i].GetId().c_str() ); #if 0 gtk_selection_add_target( GTK_WIDGET(m_clipboardWidget), clipboard, array[i], 0 ); /* what is info ? */ #endif } delete[] array; #if 0 gtk_signal_connect( GTK_OBJECT(m_clipboardWidget), "selection_get", GTK_SIGNAL_FUNC(selection_handler), (gpointer) NULL ); #endif #if wxUSE_THREADS /* disable GUI threads */ #endif bool res = false; #if 0 /* Tell the world we offer clipboard data */ res = (gtk_selection_owner_set( m_clipboardWidget, clipboard, (guint32) GDK_CURRENT_TIME )); #endif if (m_usePrimary) m_ownsPrimarySelection = res; else m_ownsClipboard = res; #if wxUSE_THREADS /* re-enable GUI threads */ #endif return res; #endif }
gboolean gimp_remote_drop_files (GdkDisplay *display, GdkWindow *window, GString *file_list) { GdkDragContext *context; GdkDragProtocol protocol; GtkWidget *source; GdkAtom sel_type; GdkAtom sel_id; GList *targetlist; guint timeout; gdk_drag_get_protocol_for_display (display, GDK_WINDOW_XID (window), &protocol); if (protocol != GDK_DRAG_PROTO_XDND) { g_printerr ("GIMP Window doesnt use Xdnd-Protocol - huh?\n"); return FALSE; } /* Problem: If the Toolbox is hidden via Tab (gtk_widget_hide) * it does not accept DnD-Operations and gtk_main() will not be * terminated. If the Toolbox is simply unmapped (by the WM) * DnD works. But in both cases gdk_window_is_visible() returns * FALSE. To work around this we add a timeout and abort after * 5 seconds. */ timeout = g_timeout_add (5000, toolbox_hidden, NULL); /* set up an DND-source */ source = gtk_window_new (GTK_WINDOW_TOPLEVEL); g_signal_connect (source, "selection-get", G_CALLBACK (source_selection_get), file_list->str); gtk_widget_realize (source); /* specify the id and the content-type of the selection used to * pass the URIs to GIMP. */ sel_id = gdk_atom_intern ("XdndSelection", FALSE); sel_type = gdk_atom_intern ("text/uri-list", FALSE); targetlist = g_list_prepend (NULL, GUINT_TO_POINTER (sel_type)); /* assign the selection to our DnD-source */ gtk_selection_owner_set (source, sel_id, GDK_CURRENT_TIME); gtk_selection_add_target (source, sel_id, sel_type, 0); /* drag_begin/motion/drop */ context = gdk_drag_begin (gtk_widget_get_window (source), targetlist); gdk_drag_motion (context, window, protocol, 0, 0, GDK_ACTION_COPY, GDK_ACTION_COPY, GDK_CURRENT_TIME); gdk_drag_drop (context, GDK_CURRENT_TIME); /* finally enter the mainloop to handle the events */ gtk_main (); g_source_remove (timeout); return TRUE; }
bool wxClipboard::AddData( wxDataObject *data ) { wxCHECK_MSG( m_open, false, wxT("clipboard not open") ); wxCHECK_MSG( data, false, wxT("data is invalid") ); // we can only store one wxDataObject Clear(); m_data = data; // get formats from wxDataObjects wxDataFormat *array = new wxDataFormat[ m_data->GetFormatCount() ]; m_data->GetAllFormats( array ); // primary selection or clipboard GdkAtom clipboard = m_usePrimary ? (GdkAtom)GDK_SELECTION_PRIMARY : g_clipboardAtom; // by default provide TIMESTAMP as a target gtk_selection_add_target( GTK_WIDGET(m_clipboardWidget), clipboard, g_timestampAtom, 0 ); for (size_t i = 0; i < m_data->GetFormatCount(); i++) { wxLogTrace( TRACE_CLIPBOARD, wxT("wxClipboard now supports atom %s"), array[i].GetId().c_str() ); // printf( "added %s\n", // gdk_atom_name( array[i].GetFormatId() ) ); gtk_selection_add_target( GTK_WIDGET(m_clipboardWidget), clipboard, array[i], 0 ); /* what is info ? */ } delete[] array; gtk_signal_connect( GTK_OBJECT(m_clipboardWidget), "selection_get", GTK_SIGNAL_FUNC(selection_handler), GUINT_TO_POINTER( gdk_event_get_time(gtk_get_current_event()) ) ); #if wxUSE_THREADS /* disable GUI threads */ #endif /* Tell the world we offer clipboard data */ bool res = (gtk_selection_owner_set( m_clipboardWidget, clipboard, (guint32) GDK_CURRENT_TIME )); if (m_usePrimary) m_ownsPrimarySelection = res; else m_ownsClipboard = res; #if wxUSE_THREADS /* re-enable GUI threads */ #endif return res; }
NS_IMETHODIMP nsClipboard::SetData(nsITransferable *aTransferable, nsIClipboardOwner *aOwner, PRInt32 aWhichClipboard) { // See if we can short cut if ((aWhichClipboard == kGlobalClipboard && aTransferable == mGlobalTransferable.get() && aOwner == mGlobalOwner.get()) || (aWhichClipboard == kSelectionClipboard && aTransferable == mSelectionTransferable.get() && aOwner == mSelectionOwner.get())) { return NS_OK; } // Clear out the clipboard in order to set the new data EmptyClipboard(aWhichClipboard); if (aWhichClipboard == kSelectionClipboard) { mSelectionOwner = aOwner; mSelectionTransferable = aTransferable; } else { mGlobalOwner = aOwner; mGlobalTransferable = aTransferable; } // Which selection are we about to claim, CLIPBOARD or PRIMARY? GdkAtom selectionAtom = GetSelectionAtom(aWhichClipboard); // Make ourselves the owner. If we fail to, return. if (!gtk_selection_owner_set(mWidget, selectionAtom, GDK_CURRENT_TIME)) return NS_ERROR_FAILURE; // Clear the old selection target list. gtk_selection_clear_targets(mWidget, selectionAtom); // Get the types of supported flavors nsresult rv; nsCOMPtr<nsISupportsArray> flavors; rv = aTransferable->FlavorsTransferableCanExport(getter_AddRefs(flavors)); if (!flavors || NS_FAILED(rv)) return NS_ERROR_FAILURE; // Add all the flavors to this widget's supported type. PRUint32 count; flavors->Count(&count); for (PRUint32 i=0; i < count; i++) { nsCOMPtr<nsISupports> tastesLike; flavors->GetElementAt(i, getter_AddRefs(tastesLike)); nsCOMPtr<nsISupportsCString> flavor = do_QueryInterface(tastesLike); if (flavor) { nsXPIDLCString flavorStr; flavor->ToString(getter_Copies(flavorStr)); // special case text/unicode since we can handle all of // the string types if (!strcmp(flavorStr, kUnicodeMime)) { AddTarget(gdk_atom_intern("UTF8_STRING", FALSE), selectionAtom); AddTarget(gdk_atom_intern("COMPOUND_TEXT", FALSE), selectionAtom); AddTarget(gdk_atom_intern("TEXT", FALSE), selectionAtom); AddTarget(GDK_SELECTION_TYPE_STRING, selectionAtom); // next loop iteration continue; } // Add this to our list of valid targets GdkAtom atom = gdk_atom_intern(flavorStr, FALSE); AddTarget(atom, selectionAtom); } } return NS_OK; }
gboolean gwy_remote_open_files(GwyRemote *remote, int argc, char **argv) { GdkNativeWindow xid; GdkDragContext *context; GdkDragProtocol protocol; GtkWidget *source; GdkAtom sel_type, sel_id; GString *file_list; GList *targetlist; gchar *cwd; gint i; if (!remote) return FALSE; xid = gdk_drag_get_protocol_for_display(remote->display, remote->winid, &protocol); /* FIXME: Here we may need some platform-dependent protocol check. * protocol should be GDK_DRAG_PROTO_XDND on X11, but on win32 * gdk_drag_get_protocol_for_display returns 0, which means there * is no DnD support for target window. */ if (!xid) { g_printerr("Gwyddion window doesn't support DnD.\n"); return FALSE; } /* Now we have the toolbox, it seems to support DnD and we have some files * to send to it. So build the list. */ cwd = g_get_current_dir(); file_list = g_string_sized_new(32*argc); for (i = 0; i < argc; i++) { gchar *s, *t; if (i) g_string_append_c(file_list, '\n'); if (g_path_is_absolute(argv[i])) s = g_filename_to_uri(argv[i], NULL, NULL); else { t = g_build_filename(cwd, argv[i], NULL); s = g_filename_to_uri(t, NULL, NULL); g_free(t); } g_string_append(file_list, s); g_free(s); } /* Don't hang when the toolbox is non-responsive. * This may not be necessary in Gwyddion, but it does not hurt either. */ g_timeout_add(2000, toolbox_timeout, NULL); /* Set up an DnD-source. */ source = gtk_window_new(GTK_WINDOW_TOPLEVEL); g_signal_connect(source, "selection-get", G_CALLBACK(source_selection_get), file_list->str); gtk_widget_realize(source); /* Specify the id and the content-type of the selection used to * pass the URIs to Gwyddion toolbox. */ sel_id = gdk_atom_intern("XdndSelection", FALSE); sel_type = gdk_atom_intern("text/plain", FALSE); targetlist = g_list_prepend(NULL, GUINT_TO_POINTER(sel_type)); /* Assign the selection to our DnD-source. */ gtk_selection_owner_set(source, sel_id, GDK_CURRENT_TIME); gtk_selection_add_target(source, sel_id, sel_type, 0); /* Drag_begin/motion/drop. */ context = gdk_drag_begin(source->window, targetlist); gdk_drag_motion(context, remote->toolbox, protocol, 0, 0, GDK_ACTION_COPY, GDK_ACTION_COPY, GDK_CURRENT_TIME); gdk_drag_drop(context, GDK_CURRENT_TIME); /* Finally enter the mainloop to handle the events. */ gtk_main(); gdk_notify_startup_complete(); return TRUE; }