Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 6679b47e940ccf106519292ef4a52871d8c1ee3a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
 * Copyright (c) 2000, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at 
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *    IBM Corporation - initial API and implementation
 * 	  Andre Weinand (OTI Labs)
 */
 
/* MacOS X Carbon specific logic for displaying the splash screen. */

#include "eclipseOS.h"
#include "eclipseCommon.h"

#include <unistd.h>
#include <CoreServices/CoreServices.h>
#include <Carbon/Carbon.h>
#include <mach-o/dyld.h>

#define startupJarName "startup.jar"
#define LAUNCHER "-launcher"
#define SPLASH_LAUNCHER "/Resources/Splash.app/Contents/"

#define DEBUG 0

char *findCommand(char *command);

/* Global Variables */
char*  defaultVM     = "java";
char*  shippedVMDir  = "jre/bin/";

/* Define the window system arguments for the various Java VMs. */
static char*  argVM_JAVA[] = { "-XstartOnFirstThread", NULL };

static WindowRef window;
static ControlRef pane = NULL;
static CGImageRef image = NULL;
static long splashHandle = 0;

int main() {
	return -1;
}

static OSStatus drawProc (EventHandlerCallRef eventHandlerCallRef, EventRef eventRef, HIViewRef viewRef) {
	ControlRef control;
	CGContextRef context;
	
	GetEventParameter(eventRef, kEventParamDirectObject, typeControlRef, NULL, 4, NULL, &control);
	GetEventParameter(eventRef, kEventParamCGContextRef, typeCGContextRef, NULL, 4, NULL, &context);
	
	HIRect rect;
	HIViewGetBounds(viewRef, &rect);
	HIViewDrawCGImage(context, &rect, image);
	return eventNotHandledErr;
}

/* Show the Splash Window
 *
 * Create the splash window, load the bitmap and display the splash window.
 */
int showSplash( const _TCHAR* featureImage )
{
	Rect wRect;
	int w, h, deviceWidth, deviceHeight;
	int attributes;
	EventTypeSpec draw = {kEventClassControl, kEventControlDraw};
	ControlRef root;
	
	/*debug("featureImage: %s\n", featureImage);*/

	/*init();*/

	CFStringRef imageString = CFStringCreateWithCString(kCFAllocatorDefault, featureImage, kCFStringEncodingASCII);
	if(imageString != NULL) {
		CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, imageString, kCFURLPOSIXPathStyle, false);
		if(url != NULL) {
			CGImageSourceRef imageSource = CGImageSourceCreateWithURL(url, NULL);
			if(imageSource != NULL) {
				image = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL);
			}
			CFRelease(url);
		}
	}
	CFRelease(imageString);
	/* If the splash image data could not be loaded, return an error. */
	if (image == NULL)
		return ENOENT;
		
	w = CGImageGetWidth(image);
	h = CGImageGetHeight(image);

	GetAvailableWindowPositioningBounds(GetMainDevice(), &wRect);

	deviceWidth= wRect.right - wRect.left;
	deviceHeight= wRect.bottom - wRect.top;

	wRect.left+= (deviceWidth-w)/2;
	wRect.top+= (deviceHeight-h)/3;
	wRect.right= wRect.left + w;
	wRect.bottom= wRect.top + h;
	
	attributes = kWindowStandardHandlerAttribute | kWindowCompositingAttribute;
	attributes &= GetAvailableWindowAttributes(kSheetWindowClass);
	CreateNewWindow(kSheetWindowClass, attributes, &wRect, &window);
	if (window != NULL) {
		GetRootControl(window, &root);
		wRect.left = wRect.top = 0;	
		wRect.right = w;
		wRect.bottom = h;
		CreateUserPaneControl(window, &wRect, kControlSupportsEmbedding | kControlSupportsFocus | kControlGetsFocusOnClick, &pane);
		HIViewAddSubview(root, pane);	

		InstallEventHandler(GetControlEventTarget(pane), (EventHandlerUPP)drawProc, 1, &draw, pane, NULL);
		ShowWindow(window);
		splashHandle = (long)window;
		dispatchMessages();
	}

	return 0;
}

long getSplashHandle() {
	return splashHandle;
}

void takeDownSplash() {
	if( splashHandle != 0) {
		HideWindow(window);
		DisposeWindow(window);
		dispatchMessages();
		splashHandle = 0;
	}
}	
void dispatchMessages() {
	EventRef event;
	EventTargetRef target;
	
	target = GetEventDispatcherTarget();
	while( ReceiveNextEvent(0, NULL, kEventDurationNoWait, true, &event) == noErr ) {
		SendEventToEventTarget(event, target);
		ReleaseEvent(event);
	}
}	

/* Get the window system specific VM arguments */
char** getArgVM( char* vm ) 
{
	char** result;

	/* Use the default arguments for a standard Java VM */
	result = argVM_JAVA;

	return result;
}

char * findVMLibrary( char* command ) {
	char *start, *end;
	char *version;
	int length;
	
	/*check first to see if command already points to the library */
	start = strrchr( command, dirSeparator ) + 1;
	if (strcmp(start, "JavaVM") == 0) {
		return command;
	}
		
	/* select a version to use based on the command */	
	start = strstr(command, "/Versions/");
	if (start != NULL){
		start += 10;
		end = strchr( start, dirSeparator);
		if (end != NULL) {
			length = end - start;
			version = malloc(length);
			strncpy(version, start, length);
			version[length] = 0;
			
			setenv("JAVA_JVM_VERSION", version, 1);
		} 
	}
	return "/System/Library/Frameworks/JavaVM.framework/Versions/Current/JavaVM";
}


void restartLauncher( char* program, char* args[] ) 
{
	pid_t pid= fork();
	if (pid == 0) {
		/* Child process ... start the JVM */
		execv(program, args);

		/* The JVM would not start ... return error code to parent process. */
		_exit(errno);
	}
}

Back to the top