]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkquartz.c
filechooserbutton: whitespace fixes
[~andy/gtk] / gtk / gtkquartz.c
index e15890e7ed5d4ca1fb84ef75b90b2ae4a187adfd..557fa8ac2c9b4d4153632603354ab0ec3bacaf80 100644 (file)
@@ -13,9 +13,7 @@
  * 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"
@@ -35,9 +33,11 @@ _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);
 
@@ -57,6 +57,13 @@ _gtk_quartz_create_image_from_pixbuf (GdkPixbuf *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];
@@ -94,6 +101,7 @@ _gtk_quartz_target_list_to_pasteboard_types (GtkTargetList *target_list)
     {
       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);
     }
@@ -311,70 +319,87 @@ _gtk_quartz_set_selection_data_for_pasteboard (NSPasteboard     *pasteboard,
                                             forType:type];
 }
 
-/*
- * Bundle-based functions for various directories. These almost work
+#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 gchar *
-get_bundle_path()
+static const gchar *
+get_bundle_path (void)
 {
-  gchar *base, *path;
-  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-  gchar *resource_path = g_strdup([[[NSBundle mainBundle] resourcePath] UTF8String]);
-  [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);
+  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)
 {
-  gchar *resource_dir = get_bundle_path();
-  gchar *retval = g_build_filename(resource_dir, "share", NULL);
-  g_free(resource_dir);
-  return retval;
+  static gchar *path = NULL;
+
+  if (path == NULL)
+    path = g_build_filename (get_bundle_path (), "share", NULL);
+
+  return path;
 }
 
 const gchar *
 _gtk_get_libdir (void)
 {
-  gchar *resource_dir = get_bundle_path();
-  gchar *retval = g_build_filename(resource_dir, "lib", NULL);
-  g_free(resource_dir);
-  return retval;
+  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;
 
-  gchar *resource_dir = get_bundle_path();
-  gchar *retval = g_build_filename(resource_dir, "share", "locale", NULL);
-  g_free(resource_dir);
-  return retval;
+  if (path == NULL)
+    path = g_build_filename (get_bundle_path (), "share", "locale", NULL);
+
+  return path;
 }
 
 const gchar *
 _gtk_get_sysconfdir (void)
 {
-  gchar *resource_dir = get_bundle_path();
-  gchar *retval = g_build_filename(resource_dir, "etc", NULL);
-  g_free(resource_dir);
-  return retval;
+  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();
+  return get_bundle_path ();
 }
 
+#endif /* QUARTZ_RELOCATION */