Example #1
0
/*
 * 	main entry point for cut and copy operations
 * 	cut : cut = TRUE;
 * 	copy: cut = FALSE;
 *
 * 	NOTE: every we cut or copy, we need to override
 * 	      previous data in clipboard.so we acquire
 * 	      clipboard every time we cut or copy.
 * 	      _clipboard_owner_change_cb is used to clear
 * 	      clipboard
 * 	      1. this is the only way we can set clipboard_info.
 * 	      2. this is the only way we can set clipboard_info_prev.
 *
 */
void
init_fileops_clipboard (GFile* file_list[], guint num, gboolean cut)
{
    g_debug ("init_fileops_clipboard:begin");

    //set prev clipboard_info
    __clear_clipboard_info (&clipboard_info_prev);
    __copy_clipboard_info (&clipboard_info, &clipboard_info_prev);

    int j=0;
    for (j = 0; j < clipboard_info_prev.num; j++)
    {
	g_debug ("init_fileops prev: file_list[%d] = %s", j, g_file_get_uri (clipboard_info_prev.file_list[j]));
    }
    //we're the clipboard owner, cleanup clipboard_info
    __clear_clipboard_info (&clipboard_info);

    clipboard_info.file_list = (GFile**)g_malloc (num * sizeof (GFile*));
    int i;
    for (i = 0; i < num; i++)
    {
	clipboard_info.file_list[i] = g_object_ref (file_list[i]);
	g_debug ("init_fileops %s: file_list[%d] = %s", cut? "cut": "paste", i, g_file_get_uri (file_list[i]));
    }
    clipboard_info.num = num;
    clipboard_info.cut = cut;

    GtkTargetList*  target_list;
    GtkTargetEntry* targets;
    gint	    n_targets;

    if (copied_files_atom == GDK_NONE)
	copied_files_atom = gdk_atom_intern ("x-special/gnome-copied-files", FALSE);

    //TODO: request clipboard data before take ownership
    //      so we can interoperate with nautilus.
    if (fileops_clipboard == NULL)
    {
	fileops_clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
	g_signal_connect (fileops_clipboard, "owner-change",
		          G_CALLBACK (_clipboard_owner_change_cb), NULL);
    }

    target_list = gtk_target_list_new (NULL, 0);
    gtk_target_list_add (target_list, copied_files_atom, 0, 0);
    gtk_target_list_add_uri_targets (target_list, 0);
    gtk_target_list_add_text_targets (target_list, 0);

    targets = gtk_target_table_new_from_list (target_list, &n_targets);

    gtk_clipboard_set_with_data (fileops_clipboard,
				 targets, n_targets,
				 _get_clipboard_callback, _clear_clipboard_callback,
				 NULL);

    gtk_target_list_unref (target_list);
    gtk_target_table_free (targets, n_targets);

    g_debug ("init_fileops_clipboard:end");
}
void EditorClient::respondToChangedSelection()
{
    WebKitWebViewPrivate* priv = m_webView->priv;
    Frame* targetFrame = core(m_webView)->focusController()->focusedOrMainFrame();

    if (!targetFrame)
        return;

    if (targetFrame->editor()->ignoreCompositionSelectionChange())
        return;

    GtkClipboard* clipboard = gtk_widget_get_clipboard(GTK_WIDGET(m_webView), GDK_SELECTION_PRIMARY);
    if (targetFrame->selection()->isRange()) {
        GtkTargetList* targetList = webkit_web_view_get_copy_target_list(m_webView);
        gint targetCount;
        GtkTargetEntry* targets = gtk_target_table_new_from_list(targetList, &targetCount);
        gtk_clipboard_set_with_owner(clipboard, targets, targetCount,
                                     clipboard_get_contents_cb, clipboard_clear_contents_cb, G_OBJECT(m_webView));
        gtk_target_table_free(targets, targetCount);
    } else if (gtk_clipboard_get_owner(clipboard) == G_OBJECT(m_webView))
        gtk_clipboard_clear(clipboard);

    if (!targetFrame->editor()->hasComposition())
        return;

    unsigned start;
    unsigned end;
    if (!targetFrame->editor()->getCompositionSelection(start, end)) {
        // gtk_im_context_reset() clears the composition for us.
        gtk_im_context_reset(priv->imContext);
        targetFrame->editor()->confirmCompositionWithoutDisturbingSelection();
    }
}
Example #3
0
void PasteboardHelper::writeClipboardContents(GtkClipboard* clipboard, SmartPasteInclusion includeSmartPaste, GClosure* callback)
{
    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
    GtkTargetList* list = targetListForDataObject(dataObject, includeSmartPaste);

    int numberOfTargets;
    GtkTargetEntry* table = gtk_target_table_new_from_list(list, &numberOfTargets);

    if (numberOfTargets > 0 && table) {
        settingClipboardDataObject = dataObject;

        if (gtk_clipboard_set_with_data(clipboard, table, numberOfTargets, getClipboardContentsCallback, clearClipboardContentsCallback, callback ? g_closure_ref(callback) : nullptr))
            gtk_clipboard_set_can_store(clipboard, nullptr, 0);
        else {
            // When gtk_clipboard_set_with_data fails the callbacks are ignored, so we need to release the reference we were passing to clearClipboardContentsCallback.
            if (callback)
                g_closure_unref(callback);
        }

        settingClipboardDataObject = nullptr;

    } else
        gtk_clipboard_clear(clipboard);

    if (table)
        gtk_target_table_free(table, numberOfTargets);
    gtk_target_list_unref(list);
}
Example #4
0
static int gtkSetDragSourceAttrib(Ihandle* ih, const char* value)
{
  if (iupStrBoolean(value))
  {
    GtkTargetList *targetlist = (GtkTargetList*)iupAttribGet(ih, "_IUPGTK_DRAG_TARGETLIST");
    GtkTargetEntry *drag_types_entry;
    int targetlist_count;

    if(!targetlist)
      return 0;

    drag_types_entry = gtk_target_table_new_from_list(targetlist, &targetlist_count);

    gtk_drag_source_set(ih->handle, GDK_BUTTON1_MASK, drag_types_entry, targetlist_count, 
                        iupAttribGetBoolean(ih, "DRAGSOURCEMOVE")? GDK_ACTION_MOVE|GDK_ACTION_COPY: GDK_ACTION_COPY);

    g_signal_connect(ih->handle, "drag_begin", G_CALLBACK(gtkDragBegin), ih);
    g_signal_connect(ih->handle, "drag_data_get", G_CALLBACK(gtkDragDataGet), ih);
    g_signal_connect(ih->handle, "drag_end", G_CALLBACK(gtkDragEnd), ih);

    gtk_target_table_free(drag_types_entry, targetlist_count);
  }
  else
    gtk_drag_source_unset(ih->handle);

  return 1;
}
Example #5
0
static void test_pasting_markup(CopyAndPasteFixture* fixture, gconstpointer data)
{
    fixture->info = (TestInfo*)data;
    currentFixture = fixture;

    GtkTargetList* targetList = gtk_target_list_new(0, 0);
    gtk_target_list_add(targetList, gdk_atom_intern("text/html", FALSE), 0, 0);

    int numberOfTargets = 1;
    GtkTargetEntry* targetTable = gtk_target_table_new_from_list(targetList, &numberOfTargets);
    gtk_clipboard_set_with_data(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
                                targetTable, numberOfTargets,
                                pasting_test_get_data_callback,
                                pasting_test_clear_data_callback,
                                g_strdup(fixture->info->expectedContent));
    gtk_target_list_unref(targetList);
    gtk_target_table_free(targetTable, numberOfTargets);

    g_signal_connect(fixture->window, "map-event",
                     G_CALLBACK(map_event_cb), fixture);
    g_signal_connect(fixture->webView, "window-object-cleared",
                     G_CALLBACK(window_object_cleared_callback), fixture);

    gtk_widget_show(fixture->window);
    gtk_widget_show(GTK_WIDGET(fixture->webView));
    gtk_window_present(GTK_WINDOW(fixture->window));

    g_main_loop_run(fixture->loop);
}
Example #6
0
static void
_g_paste_clipboard_select_uris (GPasteClipboard *self,
                                GPasteUrisItem  *item)
{
    g_return_if_fail (G_PASTE_IS_CLIPBOARD (self));
    g_return_if_fail (G_PASTE_IS_URIS_ITEM (item));

    GtkClipboard *real = self->priv->real;
    GtkTargetList *target_list = gtk_target_list_new (NULL, 0);

    _g_paste_clipboard_set_text (self, g_paste_item_get_value (G_PASTE_ITEM (item)));

    gtk_target_list_add_text_targets (target_list, 0);
    gtk_target_list_add_uri_targets (target_list, 0);
    gtk_target_list_add (target_list, g_paste_clipboard_copy_files_target, 0, 0);

    gint n_targets;
    GtkTargetEntry *targets = gtk_target_table_new_from_list (target_list, &n_targets);
    gtk_clipboard_set_with_owner (real,
                                  targets,
                                  n_targets,
                                  g_paste_clipboard_get_clipboard_data,
                                  g_paste_clipboard_clear_clipboard_data,
                                  g_object_ref (item));
    gtk_clipboard_store (real);

    gtk_target_table_free (targets, n_targets);
    gtk_target_list_unref (target_list);
}
Example #7
0
void
dnd_init (GtkWidget * w)
{
  GtkTargetList *tlist;
  GtkTargetEntry *tgts;
  gint ntgts;

  tlist = gtk_target_list_new (NULL, 0);
  gtk_target_list_add_uri_targets (tlist, 0);
  gtk_target_list_add_text_targets (tlist, 0);

  tgts = gtk_target_table_new_from_list (tlist, &ntgts);

  gtk_drag_dest_set (w, GTK_DEST_DEFAULT_ALL, tgts, ntgts, GDK_ACTION_COPY | GDK_ACTION_MOVE);
  g_signal_connect (G_OBJECT (w), "drag_data_received", G_CALLBACK (drop_data_cb), NULL);

  gtk_target_table_free (tgts, ntgts);
  gtk_target_list_unref (tlist);

  /* set tooltip */
  if (options.dnd_data.tooltip)
    {
      GtkWidget *box;

      box = gtk_dialog_get_content_area (GTK_DIALOG (w));
      if (!options.data.no_markup)
        gtk_widget_set_tooltip_markup (box, options.data.dialog_text);
      else
        gtk_widget_set_tooltip_text (box, options.data.dialog_text);
    }
}
Example #8
0
static int gtkSetDropTargetAttrib(Ihandle* ih, const char* value)
{
  if(iupStrBoolean(value))
  {
    GtkTargetList *targetlist = (GtkTargetList*)iupAttribGet(ih, "_IUPGTK_DROP_TARGETLIST");
    GtkTargetEntry *drop_types_entry;
    int targetlist_count;

    if(!targetlist)
      return 0;

    drop_types_entry = gtk_target_table_new_from_list(targetlist, &targetlist_count);

    gtk_drag_dest_set(ih->handle, GTK_DEST_DEFAULT_ALL, drop_types_entry, targetlist_count, GDK_ACTION_MOVE|GDK_ACTION_COPY);

    g_signal_connect(ih->handle, "drag_motion", G_CALLBACK(gtkDragMotion), ih);
    g_signal_connect(ih->handle, "drag_data_received", G_CALLBACK(gtkDragDataReceived), ih);

    gtk_target_table_free(drop_types_entry, targetlist_count);
  }
  else
    gtk_drag_dest_unset(ih->handle);

  return 1;
}
void PasteboardHelperGtk::writeClipboardContents(GtkClipboard* clipboard, gpointer data)
{
    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
    GtkTargetList* list = targetListForDataObject(dataObject);

    int numberOfTargets;
    GtkTargetEntry* table = gtk_target_table_new_from_list(list, &numberOfTargets);

    if (numberOfTargets > 0 && table) {
        settingClipboardDataObject = dataObject;
        settingClipboardData = data;

        // Protect the web view from being destroyed before one of the clipboard callbacks
        // is called. Balanced in both getClipboardContentsCallback and
        // clearClipboardContentsCallback.
        WebKitWebView* webView = static_cast<WebKitWebView*>(data);
        g_object_ref(webView);

        gboolean succeeded = gtk_clipboard_set_with_data(clipboard, table, numberOfTargets,
                                                         getClipboardContentsCallback,
                                                         clearClipboardContentsCallback, data);
        if (!succeeded)
            g_object_unref(webView);

        settingClipboardDataObject = 0;
        settingClipboardData = 0;
    } else
        gtk_clipboard_clear(clipboard);

    if (table)
        gtk_target_table_free(table, numberOfTargets);

    gtk_target_list_unref(list);
}
Example #10
0
void ToIndex(GtkTargetList *target_list, Index<String>& ndx)
{
	gint n;
	GtkTargetEntry *t = gtk_target_table_new_from_list(target_list, &n);
	for(int i = 0; i < n; i++)
		ndx.Add(t[i].target);
	gtk_target_table_free(t, n);
	gtk_target_list_unref(target_list);
}
Example #11
0
void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame)
{
    GtkClipboard* clipboard = m_helper->getClipboard(frame);
    gchar* text = g_strdup(frame->selectedText().utf8().data());
    gchar* markup = g_strdup(createMarkup(selectedRange, 0, AnnotateForInterchange).utf8().data());
    PasteboardSelectionData* data = new PasteboardSelectionData(text, markup);

    gint n_targets;
    GtkTargetEntry* targets = gtk_target_table_new_from_list(m_helper->getCopyTargetList(frame), &n_targets);
    gtk_clipboard_set_with_data(clipboard, targets, n_targets,
                                clipboard_get_contents_cb, clipboard_clear_contents_cb, data);
    gtk_target_table_free(targets, n_targets);
}
Example #12
0
void remmina_rdp_cliprdr_set_clipboard_data(RemminaProtocolWidget* gp, RemminaPluginRdpUiObject* ui)
{
	TRACE_CALL(__func__);
	GtkClipboard* gtkClipboard;
	GtkTargetEntry* targets;
	gint n_targets;
	rfContext* rfi = GET_PLUGIN_DATA(gp);

	targets = gtk_target_table_new_from_list(ui->clipboard.targetlist, &n_targets);
	gtkClipboard = gtk_widget_get_clipboard(rfi->drawing_area, GDK_SELECTION_CLIPBOARD);
	if (gtkClipboard && targets) {
		gtk_clipboard_set_with_owner(gtkClipboard, targets, n_targets,
			(GtkClipboardGetFunc)remmina_rdp_cliprdr_request_data,
			(GtkClipboardClearFunc)remmina_rdp_cliprdr_empty_clipboard, G_OBJECT(gp));
		gtk_target_table_free(targets, n_targets);
	}
}
/*
 * Class:     com_sun_glass_ui_gtk_GtkSystemClipboard
 * Method:    pushToSystem
 * Signature: (Ljava/util/HashMap;I)V
 */
JNIEXPORT void JNICALL Java_com_sun_glass_ui_gtk_GtkSystemClipboard_pushToSystem
  (JNIEnv * env, jobject obj, jobject data, jint supported)
{
    GtkTargetEntry* targets = NULL;
    gint ntargets;
    data = env->NewGlobalRef(data);
    init_atoms();
    data_to_targets(env, data, &targets, &ntargets);
    CHECK_JNI_EXCEPTION(env)
    if (targets) {
        gtk_clipboard_set_with_data(get_clipboard(), targets, ntargets, set_data_func, clear_data_func, data);
        gtk_target_table_free(targets, ntargets);
    } else { 
        // targets == NULL means that we want to clear clipboard.
        // Passing NULL as targets parameter to gtk_clipboard_set_with_data will produce Gtk-CRITICAL assertion
        // but passing 0 as n_targets parameter allows to set empty list of available mime types
        GtkTargetEntry dummy_targets = {(gchar*) "MIME_DUMMY_TARGET", 0, 0};
        gtk_clipboard_set_with_data(get_clipboard(), &dummy_targets, 0, set_data_func, clear_data_func, data);
    }

    is_clipboard_updated_by_glass = TRUE;
}
Example #14
0
static void
_gth_browser_clipboard_copy_or_cut (GthBrowser *browser,
				    GList      *file_list,
				    gboolean    cut)
{
	ClipboardData  *data;
	GtkTargetList  *target_list;
	GtkTargetEntry *targets;
	int             n_targets;
	GList          *scan;
	int             i;

	data = g_new0 (ClipboardData, 1);
	data->cut = cut;
	data->n_uris = g_list_length (file_list);
	data->uris = g_new (char *, data->n_uris + 1);
	for (scan = file_list, i = 0; scan; scan = scan->next, i++) {
		GthFileData *file_data = scan->data;
		data->uris[i] = g_file_get_uri (file_data->file);
	}
	data->uris[data->n_uris] = NULL;

	target_list = gtk_target_list_new (NULL, 0);
	gtk_target_list_add (target_list, GNOME_COPIED_FILES, 0, 0);
	gtk_target_list_add_uri_targets (target_list, 0);
	gtk_target_list_add_text_targets (target_list, 0);
	targets = gtk_target_table_new_from_list (target_list, &n_targets);
	gtk_clipboard_set_with_data (gtk_clipboard_get_for_display (gtk_widget_get_display (GTK_WIDGET (browser)), GDK_SELECTION_CLIPBOARD),
				     targets,
				     n_targets,
				     clipboard_get_cb,
				     clipboard_clear_cb,
				     data);

	gtk_target_list_unref (target_list);
	gtk_target_table_free (targets, n_targets);
}
Example #15
0
void PasteboardHelper::writeClipboardContents(GtkClipboard* clipboard, GClosure* callback)
{
    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
    GtkTargetList* list = targetListForDataObject(dataObject);

    int numberOfTargets;
    GtkTargetEntry* table = gtk_target_table_new_from_list(list, &numberOfTargets);

    if (numberOfTargets > 0 && table) {
        settingClipboardDataObject = dataObject;

        gtk_clipboard_set_with_data(clipboard, table, numberOfTargets,
            getClipboardContentsCallback, clearClipboardContentsCallback, callback);
        gtk_clipboard_set_can_store(clipboard, 0, 0);

        settingClipboardDataObject = 0;

    } else
        gtk_clipboard_clear(clipboard);

    if (table)
        gtk_target_table_free(table, numberOfTargets);
    gtk_target_list_unref(list);
}
    void SetupClipboardContentTypes()
    {
        GtkTargetList* list = gtk_target_list_new(NULL, 0);

        // TODO: Support for images
        if (!this->text && !this->uris)
            return;

        if (this->text)
            gtk_target_list_add_text_targets(list, ClipboardPrivate::TEXT_DATA);

        if (this->uris)
            gtk_target_list_add_uri_targets(list, ClipboardPrivate::URI_LIST_DATA);

        int size = 0;
        GtkTargetEntry* table = gtk_target_table_new_from_list(list, &size);
        if (table)
        {
            // gtk_clipboard_set_with_data may try to clear our clipboard when we
            // call it, so we turn on a flag here which prevents our clipboard data
            // from being freed during this call.
            this->preserve = true;
            GtkClipboard* clipboard = GetClipboard();
            if (gtk_clipboard_set_with_data(clipboard, table, size, GetClipboardData,
                ClearClipboardData, NULL))
            {
                this->ownClipboard = true;
                gtk_clipboard_set_can_store(clipboard, NULL, 0);
            }
            this->preserve = false;

            gtk_target_table_free(table, size);
        }

        gtk_target_list_unref(list);
    }
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;
    }

    nsresult rv;
    if (!mPrivacyHandler) {
        rv = NS_NewClipboardPrivacyHandler(getter_AddRefs(mPrivacyHandler));
        NS_ENSURE_SUCCESS(rv, rv);
    }
    rv = mPrivacyHandler->PrepareDataForClipboard(aTransferable);
    NS_ENSURE_SUCCESS(rv, rv);

    // Clear out the clipboard in order to set the new data
    EmptyClipboard(aWhichClipboard);

    // List of suported targets
    GtkTargetList *list = gtk_target_list_new(NULL, 0);

    // Get the types of supported flavors
    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.
    PRBool imagesAdded = PR_FALSE;
    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)) {
                gtk_target_list_add(list, gdk_atom_intern("UTF8_STRING", FALSE), 0, 0);
                gtk_target_list_add(list, gdk_atom_intern("COMPOUND_TEXT", FALSE), 0, 0);
                gtk_target_list_add(list, gdk_atom_intern("TEXT", FALSE), 0, 0);
                gtk_target_list_add(list, GDK_SELECTION_TYPE_STRING, 0, 0);
                continue;
            }

            if (flavorStr.EqualsLiteral(kNativeImageMime) ||
                flavorStr.EqualsLiteral(kPNGImageMime) ||
                flavorStr.EqualsLiteral(kJPEGImageMime) ||
                flavorStr.EqualsLiteral(kGIFImageMime)) {
                // don't bother adding image targets twice
                if (!imagesAdded) {
                    // accept any writable image type
                    gtk_target_list_add_image_targets(list, 0, TRUE);
                    imagesAdded = PR_TRUE;
                }
                continue;
            }

            // Add this to our list of valid targets
            GdkAtom atom = gdk_atom_intern(flavorStr, FALSE);
            gtk_target_list_add(list, atom, 0, 0);
        }
    }
    
    // Get GTK clipboard (CLIPBOARD or PRIMARY)
    GtkClipboard *gtkClipboard = gtk_clipboard_get(GetSelectionAtom(aWhichClipboard));
  
    gint numTargets;
    GtkTargetEntry *gtkTargets = gtk_target_table_new_from_list(list, &numTargets);
          
    // Set getcallback and request to store data after an application exit
    if (gtk_clipboard_set_with_data(gtkClipboard, gtkTargets, numTargets, 
                                    clipboard_get_cb, clipboard_clear_cb, this))
    {
        // We managed to set-up the clipboard so update internal state
        // We have to set it now because gtk_clipboard_set_with_data() calls clipboard_clear_cb()
        // which reset our internal state 
        if (aWhichClipboard == kSelectionClipboard) {
            mSelectionOwner = aOwner;
            mSelectionTransferable = aTransferable;
        }
        else {
            mGlobalOwner = aOwner;
            mGlobalTransferable = aTransferable;
            gtk_clipboard_set_can_store(gtkClipboard, gtkTargets, numTargets);
        }

        rv = NS_OK;
    }
    else {  
        rv = NS_ERROR_FAILURE;
    }

    gtk_target_table_free(gtkTargets, numTargets);
    gtk_target_list_unref(list);
  
    return rv;
}
Example #18
0
static void
task_shell_content_constructed (GObject *object)
{
	ETaskShellContent *task_shell_content;
	EShellView *shell_view;
	EShellContent *shell_content;
	EShellTaskbar *shell_taskbar;
	ECalModel *model;
	GalViewInstance *view_instance;
	GtkTargetList *target_list;
	GtkTargetEntry *targets;
	GtkWidget *container;
	GtkWidget *widget;
	gint n_targets;

	task_shell_content = E_TASK_SHELL_CONTENT (object);

	/* Chain up to parent's constructed() method. */
	G_OBJECT_CLASS (e_task_shell_content_parent_class)->constructed (object);

	model = e_cal_base_shell_content_get_model (E_CAL_BASE_SHELL_CONTENT (task_shell_content));

	shell_content = E_SHELL_CONTENT (object);
	shell_view = e_shell_content_get_shell_view (shell_content);
	shell_taskbar = e_shell_view_get_shell_taskbar (shell_view);

	/* Build content widgets. */

	container = GTK_WIDGET (object);

	widget = e_paned_new (GTK_ORIENTATION_VERTICAL);
	gtk_container_add (GTK_CONTAINER (container), widget);
	task_shell_content->priv->paned = g_object_ref (widget);
	gtk_widget_show (widget);

	e_binding_bind_property (
		object, "orientation",
		widget, "orientation",
		G_BINDING_SYNC_CREATE);

	container = task_shell_content->priv->paned;

	widget = gtk_scrolled_window_new (NULL, NULL);
	gtk_scrolled_window_set_policy (
		GTK_SCROLLED_WINDOW (widget),
		GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
	gtk_paned_pack1 (GTK_PANED (container), widget, TRUE, FALSE);
	gtk_widget_show (widget);

	container = widget;

	widget = e_task_table_new (shell_view, model);
	gtk_container_add (GTK_CONTAINER (container), widget);
	task_shell_content->priv->task_table = g_object_ref (widget);
	gtk_widget_show (widget);

	container = task_shell_content->priv->paned;

	widget = e_cal_component_preview_new ();
	gtk_widget_show (widget);

	g_signal_connect_swapped (
		widget, "status-message",
		G_CALLBACK (e_shell_taskbar_set_message),
		shell_taskbar);

	widget = e_preview_pane_new (E_WEB_VIEW (widget));
	gtk_paned_pack2 (GTK_PANED (container), widget, FALSE, FALSE);
	task_shell_content->priv->preview_pane = g_object_ref (widget);
	gtk_widget_show (widget);

	e_binding_bind_property (
		object, "preview-visible",
		widget, "visible",
		G_BINDING_SYNC_CREATE);

	target_list = gtk_target_list_new (NULL, 0);
	e_target_list_add_calendar_targets (target_list, 0);
	targets = gtk_target_table_new_from_list (target_list, &n_targets);

	e_table_drag_source_set (
		E_TABLE (task_shell_content->priv->task_table),
		GDK_BUTTON1_MASK, targets, n_targets,
		GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_ASK);

	gtk_target_table_free (targets, n_targets);
	gtk_target_list_unref (target_list);

	g_signal_connect_swapped (
		task_shell_content->priv->task_table, "table-drag-data-get",
		G_CALLBACK (task_shell_content_table_drag_data_get_cb),
		object);

	g_signal_connect_swapped (
		task_shell_content->priv->task_table, "table-drag-data-delete",
		G_CALLBACK (task_shell_content_table_drag_data_delete_cb),
		object);

	g_signal_connect_swapped (
		task_shell_content->priv->task_table, "cursor-change",
		G_CALLBACK (task_shell_content_cursor_change_cb),
		object);

	g_signal_connect_swapped (
		task_shell_content->priv->task_table, "selection-change",
		G_CALLBACK (task_shell_content_selection_change_cb),
		object);

	e_signal_connect_notify (
		task_shell_content->priv->task_table, "notify::is-editing",
		G_CALLBACK (task_shell_content_is_editing_changed_cb), shell_view);

	g_signal_connect_swapped (
		model, "model-row-changed",
		G_CALLBACK (task_shell_content_model_row_changed_cb), object);

	/* Prepare the view instance. */

	view_instance = e_shell_view_new_view_instance (shell_view, NULL);
	g_signal_connect_swapped (
		view_instance, "display-view",
		G_CALLBACK (task_shell_content_display_view_cb),
		object);
	e_shell_view_set_view_instance (shell_view, view_instance);
	g_object_unref (view_instance);
}
static void
memo_shell_content_constructed (GObject *object)
{
	EMemoShellContentPrivate *priv;
	EShell *shell;
	EShellView *shell_view;
	EShellContent *shell_content;
	EShellTaskbar *shell_taskbar;
	EShellWindow *shell_window;
	ESourceRegistry *registry;
	GalViewInstance *view_instance;
	GtkTargetList *target_list;
	GtkTargetEntry *targets;
	GtkWidget *container;
	GtkWidget *widget;
	gint n_targets;

	priv = E_MEMO_SHELL_CONTENT_GET_PRIVATE (object);

	/* Chain up to parent's constructed() method. */
	G_OBJECT_CLASS (e_memo_shell_content_parent_class)->constructed (object);

	shell_content = E_SHELL_CONTENT (object);
	shell_view = e_shell_content_get_shell_view (shell_content);
	shell_taskbar = e_shell_view_get_shell_taskbar (shell_view);
	shell_window = e_shell_view_get_shell_window (shell_view);
	shell = e_shell_window_get_shell (shell_window);

	registry = e_shell_get_registry (shell);
	priv->memo_model = e_cal_model_memos_new (registry);

	/* Build content widgets. */

	container = GTK_WIDGET (object);

	widget = e_paned_new (GTK_ORIENTATION_VERTICAL);
	gtk_container_add (GTK_CONTAINER (container), widget);
	priv->paned = g_object_ref (widget);
	gtk_widget_show (widget);

	g_object_bind_property (
		object, "orientation",
		widget, "orientation",
		G_BINDING_SYNC_CREATE);

	container = priv->paned;

	widget = gtk_scrolled_window_new (NULL, NULL);
	gtk_scrolled_window_set_policy (
		GTK_SCROLLED_WINDOW (widget),
		GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
	gtk_scrolled_window_set_shadow_type (
		GTK_SCROLLED_WINDOW (widget), GTK_SHADOW_IN);
	gtk_paned_pack1 (GTK_PANED (container), widget, TRUE, FALSE);
	gtk_widget_show (widget);

	container = widget;

	widget = e_memo_table_new (shell_view, priv->memo_model);
	gtk_container_add (GTK_CONTAINER (container), widget);
	priv->memo_table = g_object_ref (widget);
	gtk_widget_show (widget);

	container = priv->paned;

	widget = e_cal_component_preview_new ();
	gtk_widget_show (widget);

	g_signal_connect_swapped (
		widget, "status-message",
		G_CALLBACK (e_shell_taskbar_set_message),
		shell_taskbar);

	widget = e_preview_pane_new (E_WEB_VIEW (widget));
	gtk_paned_pack2 (GTK_PANED (container), widget, FALSE, FALSE);
	priv->preview_pane = g_object_ref (widget);
	gtk_widget_show (widget);

	g_object_bind_property (
		object, "preview-visible",
		widget, "visible",
		G_BINDING_SYNC_CREATE);

	target_list = gtk_target_list_new (NULL, 0);
	e_target_list_add_calendar_targets (target_list, 0);
	targets = gtk_target_table_new_from_list (target_list, &n_targets);

	e_table_drag_source_set (
		E_TABLE (priv->memo_table),
		GDK_BUTTON1_MASK, targets, n_targets,
		GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_ASK);

	gtk_target_table_free (targets, n_targets);
	gtk_target_list_unref (target_list);

	g_signal_connect_swapped (
		priv->memo_table, "table-drag-data-get",
		G_CALLBACK (memo_shell_content_table_drag_data_get_cb),
		object);

	g_signal_connect_swapped (
		priv->memo_table, "table-drag-data-delete",
		G_CALLBACK (memo_shell_content_table_drag_data_delete_cb),
		object);

	g_signal_connect_swapped (
		priv->memo_table, "cursor-change",
		G_CALLBACK (memo_shell_content_cursor_change_cb),
		object);

	g_signal_connect_swapped (
		priv->memo_table, "selection-change",
		G_CALLBACK (memo_shell_content_selection_change_cb),
		object);

	e_signal_connect_notify (
		priv->memo_table, "notify::is-editing",
		G_CALLBACK (memo_shell_content_is_editing_changed_cb), shell_view);

	g_signal_connect_swapped (
		priv->memo_model, "model-row-changed",
		G_CALLBACK (memo_shell_content_model_row_changed_cb),
		object);

	/* Load the view instance. */

	view_instance = e_shell_view_new_view_instance (shell_view, NULL);
	g_signal_connect_swapped (
		view_instance, "display-view",
		G_CALLBACK (memo_shell_content_display_view_cb),
		object);
	e_shell_view_set_view_instance (shell_view, view_instance);
	gal_view_instance_load (view_instance);
	g_object_unref (view_instance);

	/* Restore pane positions from the last session once
	 * the shell view is fully initialized and visible. */
	g_signal_connect (
		shell_window, "shell-view-created::memos",
		G_CALLBACK (memo_shell_content_restore_state_cb),
		shell_content);
}
Example #20
0
void selection_to_clip(void)
{
  struct XojSelectionData *sel;
  int bufsz, nitems, val;
  char *p;
  GList *list;
  struct Item *item;
  GtkTargetList *targetlist;
  GtkTargetEntry *targets;
  int n_targets;
  
  if (ui.selection == NULL) return;
  bufsz = 2*sizeof(int) // bufsz, nitems
        + sizeof(struct BBox); // bbox
  nitems = 0;
  for (list = ui.selection->items; list != NULL; list = list->next) {
    item = (struct Item *)list->data;
    nitems++;
    if (item->type == ITEM_STROKE) {
      bufsz+= sizeof(int) // type
            + sizeof(struct Brush) // brush
            + sizeof(int) // num_points
            + 2*item->path->num_points*sizeof(double); // the points
      if (item->brush.variable_width)
        bufsz += (item->path->num_points-1)*sizeof(double); // the widths
    }
    else if (item->type == ITEM_TEXT) {
      bufsz+= sizeof(int) // type
            + sizeof(struct Brush) // brush
            + 2*sizeof(double) // bbox upper-left
            + sizeof(int) // text len
            + strlen(item->text)+1 // text
            + sizeof(int) // font_name len
            + strlen(item->font_name)+1 // font_name
            + sizeof(double); // font_size
    }
    else if (item->type == ITEM_IMAGE) {
      if (item->image_png == NULL) {
        set_cursor_busy(TRUE);
        if (!gdk_pixbuf_save_to_buffer(item->image, &item->image_png, &item->image_png_len, "png", NULL, NULL))
          item->image_png_len = 0;       // failed for some reason, so forget it
        set_cursor_busy(FALSE);
      }
      bufsz+= sizeof(int) // type
        + sizeof(struct BBox)
        + sizeof(gsize) // png_buflen
        + item->image_png_len;
    }
    else bufsz+= sizeof(int); // type
  }

  // allocate selection data structure and buffer
  sel = g_malloc(sizeof(struct XojSelectionData));
  sel->xo_data_len = bufsz;
  sel->xo_data = g_malloc(bufsz);
  sel->image_data = NULL;
  sel->text_data = NULL;

  // fill in the data
  p = sel->xo_data;
  g_memmove(p, &bufsz, sizeof(int)); p+= sizeof(int);
  g_memmove(p, &nitems, sizeof(int)); p+= sizeof(int);
  g_memmove(p, &ui.selection->bbox, sizeof(struct BBox)); p+= sizeof(struct BBox);
  for (list = ui.selection->items; list != NULL; list = list->next) {
    item = (struct Item *)list->data;
    g_memmove(p, &item->type, sizeof(int)); p+= sizeof(int);
    if (item->type == ITEM_STROKE) {
      g_memmove(p, &item->brush, sizeof(struct Brush)); p+= sizeof(struct Brush);
      g_memmove(p, &item->path->num_points, sizeof(int)); p+= sizeof(int);
      g_memmove(p, item->path->coords, 2*item->path->num_points*sizeof(double));
      p+= 2*item->path->num_points*sizeof(double);
      if (item->brush.variable_width) {
        g_memmove(p, item->widths, (item->path->num_points-1)*sizeof(double));
        p+= (item->path->num_points-1)*sizeof(double);
      }
    }
    if (item->type == ITEM_TEXT) {
      g_memmove(p, &item->brush, sizeof(struct Brush)); p+= sizeof(struct Brush);
      g_memmove(p, &item->bbox.left, sizeof(double)); p+= sizeof(double);
      g_memmove(p, &item->bbox.top, sizeof(double)); p+= sizeof(double);
      val = strlen(item->text);
      g_memmove(p, &val, sizeof(int)); p+= sizeof(int);
      g_memmove(p, item->text, val+1); p+= val+1;
      val = strlen(item->font_name);
      g_memmove(p, &val, sizeof(int)); p+= sizeof(int);
      g_memmove(p, item->font_name, val+1); p+= val+1;
      g_memmove(p, &item->font_size, sizeof(double)); p+= sizeof(double);
      if (nitems==1) sel->text_data = g_strdup(item->text); // single text item
    }
    if (item->type == ITEM_IMAGE) {
      g_memmove(p, &item->bbox, sizeof(struct BBox)); p+= sizeof(struct BBox);
      g_memmove(p, &item->image_png_len, sizeof(gsize)); p+= sizeof(gsize);
      if (item->image_png_len > 0) {
        g_memmove(p, item->image_png, item->image_png_len); p+= item->image_png_len;
      }
      if (nitems==1) sel->image_data = gdk_pixbuf_copy(item->image); // single image
    }
  }
  
  /* build list of valid targets */
  targetlist = gtk_target_list_new(NULL, 0);
  gtk_target_list_add(targetlist, 
    gdk_atom_intern(XOURNAL_TARGET_ATOM, FALSE), 0, TARGET_XOURNAL);
  if (sel->image_data!=NULL)
    gtk_target_list_add_image_targets(targetlist, TARGET_PIXBUF, TRUE);
  if (sel->text_data!=NULL) 
    gtk_target_list_add_text_targets(targetlist, TARGET_TEXT);
  targets = gtk_target_table_new_from_list(targetlist, &n_targets);
  gtk_target_list_unref(targetlist);
  
  gtk_clipboard_set_with_data(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), 
       targets, n_targets,
       callback_clipboard_get, callback_clipboard_clear, sel);
  gtk_target_table_free(targets, n_targets);
}