* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <config.h>
+#include "config.h"
#include "gtkquartz.h"
-#include "gtkalias.h"
+#include "gtkselectionprivate.h"
+#include <gdk/quartz/gdkquartz.h>
NSImage *
_gtk_quartz_create_image_from_pixbuf (GdkPixbuf *pixbuf)
int rowstride, pixbuf_width, pixbuf_height;
gboolean has_alpha;
NSImage *nsimage;
+ NSSize nsimage_size;
pixbuf_width = gdk_pixbuf_get_width (pixbuf);
pixbuf_height = gdk_pixbuf_get_height (pixbuf);
+ g_return_val_if_fail (pixbuf_width != 0 && pixbuf_height != 0, NULL);
rowstride = gdk_pixbuf_get_rowstride (pixbuf);
has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
CGColorSpaceRelease (colorspace);
nsimage = [[NSImage alloc] initWithSize:NSMakeSize (pixbuf_width, pixbuf_height)];
+ nsimage_size = [nsimage size];
+ if (nsimage_size.width == 0.0 && nsimage_size.height == 0.0)
+ {
+ [nsimage release];
+ g_critical ("%s returned a zero-sized image", G_STRFUNC);
+ return NULL;
+ }
[nsimage lockFocus];
context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
return [NSString stringWithUTF8String:target];
}
-NSArray *
+NSSet *
_gtk_quartz_target_list_to_pasteboard_types (GtkTargetList *target_list)
{
NSMutableSet *set = [[NSMutableSet alloc] init];
{
GtkTargetPair *pair = list->data;
gchar *target = gdk_atom_name (pair->target);
+ g_return_val_if_fail (pair->flags < 16, NULL);
[set addObject:target_to_pasteboard_type (target)];
g_free (target);
}
- return [set allObjects];
+ return set;
}
-NSArray *
+NSSet *
_gtk_quartz_target_entries_to_pasteboard_types (const GtkTargetEntry *targets,
guint n_targets)
{
[set addObject:target_to_pasteboard_type (targets[i].target)];
}
- return [set allObjects];
+ return set;
}
GdkAtom
selection_data = g_slice_new0 (GtkSelectionData);
selection_data->selection = selection;
selection_data->target = target;
-
+ if (!selection_data->display)
+ selection_data->display = gdk_display_get_default ();
if (target == gdk_atom_intern_static_string ("UTF8_STRING"))
{
NSString *s = [pasteboard stringForType:NSStringPboardType];
{
const char *utf8_string = [s UTF8String];
- selection_data->type = target;
- selection_data->format = 8;
- selection_data->length = strlen (utf8_string);
- selection_data->data = (guchar*) g_strdup (utf8_string);
+ gtk_selection_data_set (selection_data,
+ target, 8,
+ (guchar *)utf8_string, strlen (utf8_string));
}
}
else if (target == gdk_atom_intern_static_string ("application/x-color"))
if (data)
{
- selection_data->type = target;
- selection_data->format = 8;
- selection_data->length = [data length];
- selection_data->data = g_malloc (selection_data->length + 1);
- selection_data->data[selection_data->length] = '\0';
- memcpy(selection_data->data, [data bytes], selection_data->length);
+ gtk_selection_data_set (selection_data,
+ target, 8,
+ [data bytes], [data length]);
}
}
}
void
-_gtk_quartz_set_selection_data_for_pasteboard (NSPasteboard *pasteboard,
+_gtk_quartz_set_selection_data_for_pasteboard (NSPasteboard *pasteboard,
GtkSelectionData *selection_data)
{
NSString *type;
- gchar *target = gdk_atom_name (selection_data->target);
+ gchar *target;
+ GdkDisplay *display;
+ gint format;
+ const guchar *data;
+ NSUInteger length;
+
+ target = gdk_atom_name (gtk_selection_data_get_target (selection_data));
+ display = gtk_selection_data_get_display (selection_data);
+ format = gtk_selection_data_get_format (selection_data);
+ data = gtk_selection_data_get_data (selection_data);
+ length = gtk_selection_data_get_length (selection_data);
type = target_to_pasteboard_type (target);
g_free (target);
if ([type isEqualTo:NSStringPboardType])
- [pasteboard setString:[NSString stringWithUTF8String:(const char *)selection_data->data]
+ [pasteboard setString:[NSString stringWithUTF8String:(const char *)data]
forType:type];
else if ([type isEqualTo:NSColorPboardType])
{
- guint16 *color = (guint16 *)selection_data->data;
+ guint16 *color = (guint16 *)data;
float red, green, blue, alpha;
NSColor *nscolor;
green = (float)color[1] / 0xffff;
blue = (float)color[2] / 0xffff;
alpha = (float)color[3] / 0xffff;
-
+
nscolor = [NSColor colorWithDeviceRed:red green:green blue:blue alpha:alpha];
[nscolor writeToPasteboard:pasteboard];
}
else if ([type isEqualTo:NSURLPboardType])
{
- gchar **list = NULL;
- int count;
-
- count = gdk_text_property_to_utf8_list_for_display (selection_data->display,
- gdk_atom_intern_static_string ("UTF8_STRING"),
- selection_data->format,
- selection_data->data,
- selection_data->length,
- &list);
+ gchar **uris;
- if (count > 0)
+ uris = gtk_selection_data_get_uris (selection_data);
+ if (uris != NULL)
{
- gchar **result;
NSURL *url;
- result = g_uri_list_extract_uris (list[0]);
-
- url = [NSURL URLWithString:[NSString stringWithUTF8String:result[0]]];
+ url = [NSURL URLWithString:[NSString stringWithUTF8String:uris[0]]];
[url writeToPasteboard:pasteboard];
-
- g_strfreev (result);
}
-
- g_strfreev (list);
+ g_strfreev (uris);
}
else
- [pasteboard setData:[NSData dataWithBytesNoCopy:selection_data->data
- length:selection_data->length
- freeWhenDone:NO]
- forType:type];
+ [pasteboard setData:[NSData dataWithBytesNoCopy:(void *)data
+ length:length
+ freeWhenDone:NO]
+ forType:type];
}
+
+#ifdef QUARTZ_RELOCATION
+
+/* Bundle-based functions for various directories. These almost work
+ * even when the application isn't in a bundle, becuase mainBundle
+ * paths point to the bin directory in that case. It's a simple matter
+ * to test for that and remove the last element.
+ */
+
+static const gchar *
+get_bundle_path (void)
+{
+ static gchar *path = NULL;
+
+ if (path == NULL)
+ {
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ gchar *resource_path = g_strdup ([[[NSBundle mainBundle] resourcePath] UTF8String]);
+ gchar *base;
+ [pool drain];
+
+ base = g_path_get_basename (resource_path);
+ if (strcmp (base, "bin") == 0)
+ path = g_path_get_dirname (resource_path);
+ else
+ path = strdup (resource_path);
+
+ g_free (resource_path);
+ g_free (base);
+ }
+
+ return path;
+}
+
+const gchar *
+_gtk_get_datadir (void)
+{
+ static gchar *path = NULL;
+
+ if (path == NULL)
+ path = g_build_filename (get_bundle_path (), "share", NULL);
+
+ return path;
+}
+
+const gchar *
+_gtk_get_libdir (void)
+{
+ static gchar *path = NULL;
+
+ if (path == NULL)
+ path = g_build_filename (get_bundle_path (), "lib", NULL);
+
+ return path;
+}
+
+const gchar *
+_gtk_get_localedir (void)
+{
+ static gchar *path = NULL;
+
+ if (path == NULL)
+ path = g_build_filename (get_bundle_path (), "share", "locale", NULL);
+
+ return path;
+}
+
+const gchar *
+_gtk_get_sysconfdir (void)
+{
+ static gchar *path = NULL;
+
+ if (path == NULL)
+ path = g_build_filename (get_bundle_path (), "etc", NULL);
+
+ return path;
+}
+
+const gchar *
+_gtk_get_data_prefix (void)
+{
+ return get_bundle_path ();
+}
+
+#endif /* QUARTZ_RELOCATION */