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