Home | History | Annotate | Download | only in ports
      1 #if defined(SK_BUILD_FOR_MAC) && !defined(SK_USE_WXWIDGETS)
      2 #include <Carbon/Carbon.h>
      3 #include <unistd.h>
      4 #include <cerrno>
      5 #include "SkApplication.h"
      6 #include "SkTypes.h"
      7 
      8 extern void get_preferred_size(int*, int*, int*, int* );
      9 
     10 int main(int argc, char* argv[])
     11 {
     12     
     13 #if 0
     14 {
     15 	FILE* f = ::fopen("/whereami.txt", "w");
     16 	for (int i = 0; i < argc; i++)
     17 		fprintf(f, "[%d] %s\n", i, argv[i]);
     18 	::fclose(f);
     19 }
     20 #else
     21 // argv[0] is set to the execution path of the application, e.g. 
     22 // /Users/caryclark/android/device/build/ide/xcode/animatorTest/build/Debug/animatorTest.app/Contents/MacOS/animatorTest
     23 // the desired directory path is :
     24 // /Users/caryclark/android/device/jsapps
     25 // the variable (client-specific) part is :
     26 // /Users/caryclark/android/
     27 // since different applications share this library, they only have in common:
     28 // {client}/device/build/ide/xcode/{application}
     29 {
     30 	const char* applicationPath = argv[0];
     31 	const char* common = strstr(applicationPath, "build/ide/xcode/");
     32 	const char systemParent[] = "apps/"; 
     33 	if (common != 0) {
     34 		size_t prefixLength = common - applicationPath;
     35 		char* workingDirectory = new char[prefixLength + sizeof(systemParent)];
     36 		strncpy(workingDirectory, applicationPath, prefixLength);
     37 		strcpy(&workingDirectory[prefixLength], systemParent);
     38 		int error = chdir(workingDirectory);
     39 		if (error != 0) {
     40 			error = errno;
     41 			SkASSERT(error != ENOENT);
     42 			SkASSERT(error != ENOTDIR);
     43 			SkASSERT(error != EACCES);
     44 			SkASSERT(error != EIO);
     45 			SkASSERT(0);
     46 		}
     47 		delete workingDirectory;
     48 	}
     49 }
     50 #endif
     51 	IBNibRef 		nibRef;
     52     WindowRef 		window;
     53     
     54     OSStatus		err;
     55 
     56     // Create a Nib reference passing the name of the nib file (without the .nib extension)
     57     // CreateNibReference only searches into the application bundle.
     58     err = CreateNibReference(CFSTR("main"), &nibRef);
     59     require_noerr( err, CantGetNibRef );
     60     
     61     // Once the nib reference is created, set the menu bar. "MainMenu" is the name of the menu bar
     62     // object. This name is set in InterfaceBuilder when the nib is created.
     63     err = SetMenuBarFromNib(nibRef, CFSTR("MenuBar"));
     64     require_noerr( err, CantSetMenuBar );
     65     
     66     // Then create a window. "MainWindow" is the name of the window object. This name is set in 
     67     // InterfaceBuilder when the nib is created.
     68     err = CreateWindowFromNib(nibRef, CFSTR("MainWindow"), &window);
     69     require_noerr( err, CantCreateWindow );
     70 
     71     // We don't need the nib reference anymore.
     72     DisposeNibReference(nibRef);
     73     {
     74 	// if we get here, we can start our normal Skia sequence
     75 	application_init();
     76 	(void)create_sk_window(window);
     77         int x =0, y =0, width =640, height=480;
     78         get_preferred_size(&x, &y, &width, &height);
     79         MoveWindow(window, x, y, false);
     80         SizeWindow(window, width, height, false);
     81     }
     82     // The window was created hidden so show it.
     83     ShowWindow( window );
     84 
     85     // Call the event loop
     86     RunApplicationEventLoop();
     87 	
     88 	application_term();
     89 
     90 CantCreateWindow:
     91 CantSetMenuBar:
     92 CantGetNibRef:
     93 	return err;
     94 }
     95 
     96 #endif