]> granicus.if.org Git - graphviz/commitdiff
basic viewer app for Mac OS X
authorglenlow <devnull@localhost>
Mon, 4 Feb 2008 13:30:08 +0000 (13:30 +0000)
committerglenlow <devnull@localhost>
Mon, 4 Feb 2008 13:30:08 +0000 (13:30 +0000)
macbuild
macosx/GVContext.h [new file with mode: 0644]
macosx/GVContext.m [new file with mode: 0644]

index 950511ee27e5ae92b510c18c69d0c330c93004d2..cd76e52d3d2ce423c7619e3006360aa9afcafa00 100755 (executable)
--- a/macbuild
+++ b/macbuild
@@ -1,6 +1,7 @@
 #!/bin/sh
 
 PACKAGEMAKER="/Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS/PackageMaker"
+XCODEBUILD="xcodebuild"
 
 # configure for Universal Binaries
 ./configure --disable-dependency-tracking --with-quartz CFLAGS="-arch i386 -arch ppc" LDFLAGS="-arch i386 -arch ppc"
@@ -10,5 +11,8 @@ make
 rm -rf macosx/build/usr/local/*
 make DESTDIR=$PWD/macosx/build install
 
+# build the GUI application
+$XCODEBUILD -project macosx/graphviz.xcodeproj -configuration Release
+
 # convert the build directory into a package
 $PACKAGEMAKER --doc macosx/graphviz.pmdoc --out $1
diff --git a/macosx/GVContext.h b/macosx/GVContext.h
new file mode 100644 (file)
index 0000000..58f54b4
--- /dev/null
@@ -0,0 +1,33 @@
+/* $Id$ $Revision$ */
+/* vim:set shiftwidth=4 ts=8: */
+
+/**********************************************************
+*      This software is part of the graphviz package      *
+*                http://www.graphviz.org/                 *
+*                                                         *
+*            Copyright (c) 1994-2008 AT&T Corp.           *
+*                and is licensed under the                *
+*            Common Public License, Version 1.0           *
+*                      by AT&T Corp.                      *
+*                                                         *
+*        Information and Software Systems Research        *
+*              AT&T Research, Florham Park NJ             *
+**********************************************************/
+
+#import <Foundation/Foundation.h>
+#include <graphviz/gvc.h>
+
+@interface GVContext : NSObject
+{
+       GVC_t *_context;
+}
+
++ (GVContext *)sharedContext;
+
+- (id)init;
+
+- (void)layoutGraph:(graph_t *)graph withEngine:(NSString*)engine;
+
+- (NSData*)renderGraph:(graph_t *)graph withFormat:(NSString*)format;
+- (void)renderGraph:(graph_t *)graph withFormat:(NSString*) format toURL:(NSURL*)URL;
+@end
diff --git a/macosx/GVContext.m b/macosx/GVContext.m
new file mode 100644 (file)
index 0000000..86145f7
--- /dev/null
@@ -0,0 +1,67 @@
+/* $Id$ $Revision$ */
+/* vim:set shiftwidth=4 ts=8: */
+
+/**********************************************************
+*      This software is part of the graphviz package      *
+*                http://www.graphviz.org/                 *
+*                                                         *
+*            Copyright (c) 1994-2008 AT&T Corp.           *
+*                and is licensed under the                *
+*            Common Public License, Version 1.0           *
+*                      by AT&T Corp.                      *
+*                                                         *
+*        Information and Software Systems Research        *
+*              AT&T Research, Florham Park NJ             *
+**********************************************************/
+
+#import "GVContext.h"
+
+@implementation GVContext
+
++ (GVContext *)sharedContext
+{
+       static GVContext *shared = nil;
+       if (!shared)
+               shared = [[GVContext alloc] init];
+       return shared;
+}
+
+- (id)init
+{
+       if (self = [super init])
+               _context = gvContext();
+       return self;
+}
+
+- (void)layoutGraph:(graph_t *)graph withEngine:(NSString*)engine
+{
+       if (gvLayout(_context, graph, (char*)[engine UTF8String]) != 0)
+               @throw [NSException exceptionWithName:@"GVException" reason:@"Bad layout" userInfo:nil];
+}
+
+- (NSData*)renderGraph:(graph_t *)graph withFormat:(NSString*)format
+{
+       char *renderedData = NULL;
+       unsigned int renderedLength = 0;
+       if (gvRenderData(_context, graph, (char*)[format UTF8String], &renderedData, &renderedLength) != 0)
+               @throw [NSException exceptionWithName:@"GVException" reason:@"Bad render" userInfo:nil];
+       return [NSData dataWithBytesNoCopy:renderedData length:renderedLength freeWhenDone:YES];
+}
+
+- (void)renderGraph:(graph_t *)graph withFormat:(NSString*)format toURL:(NSURL*)URL
+{
+       if ([URL isFileURL]) {
+               if (gvRenderFilename(_context, graph, (char*)[format UTF8String], (char*)[[URL path] UTF8String]) != 0)
+                       @throw [NSException exceptionWithName:@"GVException" reason:@"Bad render" userInfo:nil];
+       }
+       else
+               [[self renderGraph:graph withFormat:format] writeToURL:URL atomically:NO];
+}
+
+- (void)dealloc
+{
+       if(_context)
+               gvFreeContext(_context);
+       [super dealloc];
+}
+@end