/* AbiWord * Copyright (C) 1998 AbiSource, Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. */ #include #include "ut_types.h" #include "ut_assert.h" #include "ut_debugmsg.h" #include "xap_Frame.h" #include "xap_Frame.h" #include "gr_UnixGraphics.h" #include "ap_UnixClipartPane.h" #include "xap_UnixDialogHelper.h" ////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// #define _BYTE 8 AP_UnixClipartPane::AP_UnixClipartPane(XAP_Frame * pFrame) : AP_ClipartPane(pFrame) { m_wClipartPane = NULL; // m_pFrame = pFrame; } AP_UnixClipartPane::~AP_UnixClipartPane(void) { } // FIXME: we need more sanity checking here to make sure everything allocates correctly GtkWidget * AP_UnixClipartPane::createWidget(void) { UT_ASSERT(!m_wClipartPane); /* * This method creates a pane containing clipart that can be dragged into AbiWord * documents. It returns a set of nested widgets that look like this: * * GtkScrolledWindow (m_wClipartPane) * |_ GtkViewport * |_ GtkHBox (clipartHBox) * |_ GtkImage * |_ GtkImage * |_ ... */ m_wClipartPane = gtk_scrolled_window_new(NULL,NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(m_wClipartPane), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); GtkWidget* clipartHBox; clipartHBox = gtk_hbox_new(true, 10); // FIXME: this obviously should not be hardcoded. gchar * clipartPath = "/home/erik/Sugar/sugar-jhbuild/build/share/clipart"; GDir * clipartDir; GError * openError; clipartDir = g_dir_open (clipartPath, 0, &openError); UT_ASSERT(clipartDir); static GtkTargetEntry target_list[] = { { "STRING", 0, 0 }, }; static guint n_targets = G_N_ELEMENTS (target_list); while (TRUE) { const gchar *basename = g_dir_read_name (clipartDir); if (!basename) break; gchar * fullpath = g_strconcat(clipartPath, "/", basename, NULL); UT_DEBUGMSG(("image: %s\n", fullpath)); GtkWidget * image; image = gtk_image_new_from_file(fullpath); GtkWidget* button; button = gtk_button_new(); g_object_set(G_OBJECT(button), "user-data", fullpath, NULL); // FIXME: we need to free this eventually, but not now. When? // free(fullpath); gtk_button_set_image(GTK_BUTTON(button), image); gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE); gtk_drag_source_set(button, GDK_BUTTON1_MASK, target_list, n_targets, GDK_ACTION_COPY); g_signal_connect (G_OBJECT(button), "drag-data-get", G_CALLBACK (AP_UnixClipartPane::drag_data_get_callback), NULL); gtk_widget_show(button); gtk_container_add(GTK_CONTAINER(clipartHBox), button); } g_dir_close (clipartDir); gtk_widget_show(clipartHBox); gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(m_wClipartPane), clipartHBox); return m_wClipartPane; } /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// void AP_UnixClipartPane::show(void) { gtk_widget_show (m_wClipartPane); } void AP_UnixClipartPane::hide(void) { gtk_widget_hide (m_wClipartPane); m_pFrame->queue_resize(); } void AP_UnixClipartPane::drag_data_get_callback (GtkWidget *widget, GdkDragContext *context, GtkSelectionData *selection_data, guint target_type, guint time, gpointer user_data) { UT_DEBUGMSG(("drag data requested\n")); gchar *strval; g_object_get(G_OBJECT(widget), "user-data", &strval, NULL); UT_DEBUGMSG(("data: %s\n", strval)); gtk_selection_data_set ( selection_data, selection_data-> target, _BYTE, (guchar*) strval, strlen (strval) ); }