View | Details | Raw Unified | Return to bug 178927 | Differences between
and this patch

Collapse All | Expand All

(-)library/carbon/eclipseCarbon.c (+145 lines)
Lines 73-89 Link Here
73
}
73
}
74
74
75
@end
75
@end
76
77
@interface AppleEventDelegate : NSObject
78
- (void)handleOpenDocuments:(NSAppleEventDescriptor *)event withReplyEvent: (NSAppleEventDescriptor *)replyEvent;
79
@end
80
@implementation AppleEventDelegate
81
	NSTimer *timer;
82
	NSMutableArray *files;
83
	
84
- (void)handleOpenDocuments:(NSAppleEventDescriptor *)event withReplyEvent: (NSAppleEventDescriptor *)replyEvent {
85
	NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
86
    int count = [event numberOfItems];
87
    int index = 1;
88
    
89
 	if (!files) {
90
		files = [NSMutableArray arrayWithCapacity:count];
91
		[files retain];
92
	}
93
		
94
	for (index = 1; index<=count; index++) {
95
		NSAppleEventDescriptor *desc = [event descriptorAtIndex:index];
96
		if (desc) {
97
			desc = [desc coerceToDescriptorType:typeFSRef];
98
			CFURLRef url = CFURLCreateFromFSRef(kCFAllocatorDefault, [[desc data] bytes]);
99
			if (url) {
100
				NSString *pathName = (NSString *)CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle);
101
				[files addObject:pathName];
102
				[pathName release];
103
				CFRelease(url);
104
			}
105
		}
106
	}
107
	
108
	if (!timer) {
109
		timer = [NSTimer scheduledTimerWithTimeInterval: 1.0
110
												 target: self
111
											   selector: @selector(handleTimer:)
112
											   userInfo: nil
113
												repeats: YES];
114
	}
115
	[pool release];
116
}
117
- (void) handleTimer: (NSTimer *) timer {
118
	NSObject *delegate = [[NSApplication sharedApplication] delegate];
119
	if (delegate != NULL && [delegate respondsToSelector: @selector(application:openFiles:)]) {
120
		[delegate performSelector:@selector(application:openFiles:)	withObject:[NSApplication sharedApplication] withObject:files];
121
		[files release];
122
		[timer invalidate];
123
	}
124
}
125
@end
76
#endif
126
#endif
77
127
78
static CFRunLoopRef loopRef = NULL;
128
static CFRunLoopRef loopRef = NULL;
79
static void * startThread(void * init); 
129
static void * startThread(void * init); 
80
static void runEventLoop(CFRunLoopRef ref);
130
static void runEventLoop(CFRunLoopRef ref);
81
static void dummyCallback(void * info) {}
131
static void dummyCallback(void * info) {}
132
#ifndef COCOA
133
static CFMutableArrayRef files;
134
static EventHandlerRef appHandler;
135
static int SWT_CLASS = 'SWT-';
136
static int SWT_OPEN_FILE_KIND = 1;
137
static int SWT_OPEN_FILE_PARAM = 'odoc';
138
#endif
82
139
83
int main() {
140
int main() {
84
	return -1;
141
	return -1;
85
}
142
}
86
143
144
void installAppleEventHandler();
145
146
int reuseWorkbench(_TCHAR* filePath) {
147
	installAppleEventHandler();
148
	return 0;
149
}
150
87
#ifdef COCOA
151
#ifdef COCOA
88
152
89
/* Show the Splash Window
153
/* Show the Splash Window
Lines 149-154 Link Here
149
static CGImageSourceCreateWithURL_FUNC createWithURL = NULL;
213
static CGImageSourceCreateWithURL_FUNC createWithURL = NULL;
150
static CGImageSourceCreateImageAtIndex_FUNC createAtIndex = NULL;
214
static CGImageSourceCreateImageAtIndex_FUNC createAtIndex = NULL;
151
215
216
static pascal OSErr openDocumentsProc(const AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefcon);
217
152
static OSStatus drawProc (EventHandlerCallRef eventHandlerCallRef, EventRef eventRef, void * data) {
218
static OSStatus drawProc (EventHandlerCallRef eventHandlerCallRef, EventRef eventRef, void * data) {
153
	int result = CallNextEventHandler(eventHandlerCallRef, eventRef);
219
	int result = CallNextEventHandler(eventHandlerCallRef, eventRef);
154
	if (image) {
220
	if (image) {
Lines 183-188 Link Here
183
	}
249
	}
184
}
250
}
185
251
252
static OSStatus appleEventProc(EventHandlerCallRef inCaller, EventRef theEvent, void* inRefcon) {
253
	EventRecord eventRecord;
254
	Boolean release = false;
255
	EventQueueRef queue;
256
	
257
	queue = GetCurrentEventQueue();
258
	if (IsEventInQueue (queue, theEvent)) {
259
		RetainEvent (theEvent);
260
		release = true;
261
		RemoveEventFromQueue (queue, theEvent);
262
	}
263
	ConvertEventRefToEventRecord (theEvent, &eventRecord);
264
	AEProcessAppleEvent (&eventRecord);
265
	if (release) ReleaseEvent (theEvent);
266
	return noErr;
267
}
268
269
static void timerProc(EventLoopTimerRef timer, void *userData) {
270
	EventTargetRef target = GetApplicationEventTarget();
271
	CFIndex count = CFArrayGetCount  (files);
272
	int i;
273
	for (i=0; i<count; i++) {
274
		CFStringRef file = (CFStringRef) CFArrayGetValueAtIndex(files, i);
275
		EventRef event = NULL;
276
		CreateEvent (NULL, SWT_CLASS, SWT_OPEN_FILE_KIND, 0, kEventAttributeNone, &event);
277
		SetEventParameter (event, SWT_OPEN_FILE_PARAM, typeCFStringRef, sizeof(file), &file);
278
		OSStatus status = SendEventToEventTarget(event, target);
279
		ReleaseEvent(event);
280
		if (status == eventNotHandledErr) return;
281
	}
282
	CFRelease(files);
283
	RemoveEventLoopTimer(timer);
284
	RemoveEventHandler(appHandler);
285
	AERemoveEventHandler(kCoreEventClass, kAEOpenDocuments, NewAEEventHandlerUPP(openDocumentsProc), false);
286
}
287
 
288
static pascal OSErr openDocumentsProc(const AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefcon) {
289
    AEDescList  docList;
290
    FSRef       theFSRef;
291
    long        index;
292
    long        count = 0;
293
    
294
    AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, &docList);
295
	AECountItems(&docList, &count);
296
	for(index = 1; index <= count; index++) {
297
        AEGetNthPtr(&docList, index, typeFSRef, NULL, NULL, &theFSRef, sizeof(FSRef), NULL);
298
		CFURLRef url = CFURLCreateFromFSRef(kCFAllocatorDefault, &theFSRef);
299
		CFStringRef pathName = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle);
300
		if (!files) {
301
			files = CFArrayCreateMutable(kCFAllocatorDefault, count, &kCFTypeArrayCallBacks);		
302
            InstallEventLoopTimer(GetMainEventLoop(), 1, 1, NewEventLoopTimerUPP(timerProc), NULL, NULL); 
303
		}
304
		CFArrayAppendValue(files, pathName);
305
		CFRelease(pathName);
306
		CFRelease(url);
307
    }
308
    AEDisposeDesc(&docList);
309
    return noErr;
310
}
311
186
/* Show the Splash Window
312
/* Show the Splash Window
187
 *
313
 *
188
 * Create the splash window, load the bitmap and display the splash window.
314
 * Create the splash window, load the bitmap and display the splash window.
Lines 279-284 Link Here
279
}
405
}
280
#endif	
406
#endif	
281
407
408
void installAppleEventHandler() {
409
#ifdef COCOA
410
	NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
411
	AppleEventDelegate *appleEventDelegate = [[AppleEventDelegate alloc] init];
412
	[NSApplication sharedApplication];
413
	NSAppleEventManager *manager = [NSAppleEventManager sharedAppleEventManager];
414
	[manager setEventHandler:appleEventDelegate 
415
				 andSelector:@selector(handleOpenDocuments:withReplyEvent:) 
416
			   forEventClass:kCoreEventClass 
417
				  andEventID:kAEOpenDocuments];
418
//	[appleEventDelegate release];
419
	[pool release];
420
#else	
421
	EventTypeSpec kEvents[] = { {kEventClassAppleEvent, kEventAppleEvent} };
422
	InstallApplicationEventHandler(NewEventHandlerUPP(appleEventProc), GetEventTypeCount(kEvents), kEvents, 0, &appHandler);
423
	AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, NewAEEventHandlerUPP(openDocumentsProc), 0, false);
424
#endif
425
}
426
282
jlong getSplashHandle() {
427
jlong getSplashHandle() {
283
	return (jlong)window;
428
	return (jlong)window;
284
}
429
}
(-)library/eclipse.c (+5 lines)
Lines 226-231 Link Here
226
#define CP			 _T_ECLIPSE("-cp")
226
#define CP			 _T_ECLIPSE("-cp")
227
#define CLASSPATH    _T_ECLIPSE("-classpath")
227
#define CLASSPATH    _T_ECLIPSE("-classpath")
228
#define JAR 		 _T_ECLIPSE("-jar")
228
#define JAR 		 _T_ECLIPSE("-jar")
229
#define FILEPATH	  _T_ECLIPSE("-file")
229
230
230
#define LIBRARY		  _T_ECLIPSE("--launcher.library")
231
#define LIBRARY		  _T_ECLIPSE("--launcher.library")
231
#define SUPRESSERRORS _T_ECLIPSE("--launcher.suppressErrors")
232
#define SUPRESSERRORS _T_ECLIPSE("--launcher.suppressErrors")
Lines 258-263 Link Here
258
static _TCHAR*  name          = NULL;			/* program name */	
259
static _TCHAR*  name          = NULL;			/* program name */	
259
static _TCHAR*  library       = NULL;			/* the shared library */
260
static _TCHAR*  library       = NULL;			/* the shared library */
260
static _TCHAR*  permGen  	  = NULL;			/* perm gen size for sun */
261
static _TCHAR*  permGen  	  = NULL;			/* perm gen size for sun */
262
static _TCHAR*  filePath	  = NULL;			/* file to open */
261
263
262
/* variables for ee options */
264
/* variables for ee options */
263
static _TCHAR* eeExecutable = NULL;
265
static _TCHAR* eeExecutable = NULL;
Lines 300-305 Link Here
300
    { VM,           &vmName,		0,			2 },
302
    { VM,           &vmName,		0,			2 },
301
    { NAME,         &name,			0,			2 },
303
    { NAME,         &name,			0,			2 },
302
    { PERM_GEN,		&permGen,		0,			2 },
304
    { PERM_GEN,		&permGen,		0,			2 },
305
    { FILEPATH,		&filePath,		0,			2 },
303
    { WS,			&wsArg,			0,			2 } };
306
    { WS,			&wsArg,			0,			2 } };
304
static int optionsSize = (sizeof(options) / sizeof(options[0]));
307
static int optionsSize = (sizeof(options) / sizeof(options[0]));
305
308
Lines 370-375 Link Here
370
	/* Initialize official program name */
373
	/* Initialize official program name */
371
   	officialName = name != NULL ? _tcsdup( name ) : getDefaultOfficialName();
374
   	officialName = name != NULL ? _tcsdup( name ) : getDefaultOfficialName();
372
    
375
    
376
	if (reuseWorkbench(filePath)) return 0;
377
373
#ifdef MACOSX
378
#ifdef MACOSX
374
   	/* Most platforms, we will initialize the window system later before trying to do any
379
   	/* Most platforms, we will initialize the window system later before trying to do any
375
   	 * graphics.  On Mac, we need it initialized to get the dock icon properly, so always do 
380
   	 * graphics.  On Mac, we need it initialized to get the dock icon properly, so always do 
(-)library/eclipseOS.h (+2 lines)
Lines 115-119 Link Here
115
/* an array of paths that will need to be on the search path to load the vm shared library */
115
/* an array of paths that will need to be on the search path to load the vm shared library */
116
extern _TCHAR ** getVMLibrarySearchPath(_TCHAR * vmLibrary);
116
extern _TCHAR ** getVMLibrarySearchPath(_TCHAR * vmLibrary);
117
117
118
extern int reuseWorkbench(_TCHAR* filePath);
119
118
#endif /* ECLIPSE_OS_H */
120
#endif /* ECLIPSE_OS_H */
119
121
(-)library/gtk/eclipseGtk.c (+169 lines)
Lines 32-37 Link Here
32
#include <stdlib.h>
32
#include <stdlib.h>
33
#include <string.h>
33
#include <string.h>
34
#include <locale.h>
34
#include <locale.h>
35
#include <semaphore.h>
36
#include <fcntl.h>
35
37
36
/* Global Variables */
38
/* Global Variables */
37
char*  defaultVM     = "java";
39
char*  defaultVM     = "java";
Lines 47-56 Link Here
47
static GdkPixbuf*	pixbuf = 0;
49
static GdkPixbuf*	pixbuf = 0;
48
static GtkWidget*   image = 0;
50
static GtkWidget*   image = 0;
49
51
52
static sem_t* 		mutex;
53
static Atom 		appAtom, launcherAtom;
54
static char*		file = NULL;
55
static int 			timerAttempts;
56
57
static struct sigaction	quitAction;
58
static struct sigaction	intAction;
59
50
/* Local functions */
60
/* Local functions */
61
static void catch_signal(int sig) {
62
	//catch signals, free the lock, reinstall the original
63
	//signal handlers and reraise the signal.
64
	sem_post(mutex);
65
	sem_close(mutex);
66
	sigaction(SIGINT, &intAction, NULL);
67
	sigaction(SIGQUIT, &intAction, NULL);
68
	raise(sig);
69
}
70
71
typedef  int (*LockFunc) ();
72
int executeWithLock (char *name, LockFunc func) {
73
	int 	result;
74
	struct 	sigaction	action;
75
76
	mutex = sem_open(name, O_CREAT|O_EXCL, S_IRWXU | S_IRWXG | S_IRWXO, 1);
77
	if (mutex == SEM_FAILED) {
78
		//create failed. Probably lock is already created so try opening the
79
		//existing lock.
80
		mutex = sem_open(name, 0);
81
	}
82
	if (mutex == SEM_FAILED) return -1; //this is an error.
83
84
	//install signal handler to free the lock if something bad
85
	//happens. sem_t is not freed automatically when a process ends.
86
	action.sa_handler = catch_signal;
87
	sigaction(SIGINT, &action, &intAction);
88
	sigaction(SIGQUIT, &action, &quitAction);
89
	//sem_t has no timeouts on wait. :-(
90
	sem_wait(mutex);
91
92
	result = func();
93
94
	sem_post(mutex);
95
	sem_close(mutex);
96
	//reinstall the original signal handlers
97
	sigaction(SIGINT, &intAction, NULL);
98
	sigaction(SIGQUIT, &quitAction, NULL);
99
	return result;
100
}
101
51
static void log_handler(const gchar* domain, GLogLevelFlags flags, const gchar* msg, gpointer data) {
102
static void log_handler(const gchar* domain, GLogLevelFlags flags, const gchar* msg, gpointer data) {
52
	/* nothing */
103
	/* nothing */
53
}
104
}
105
106
static int setAppWindowProperty() {
107
	Window appWindow;
108
	GdkWindow *propWindow;
109
	GdkAtom propAtom;
110
	char *propVal;
111
112
	//Look for the SWT window. If it's there, set a property on it.
113
	appWindow = XGetSelectionOwner(GDK_DISPLAY(), appAtom);
114
	if (appWindow) {
115
		propWindow = gdk_window_foreign_new (appWindow);
116
		propAtom = gdk_atom_intern("org.eclipse.swt.filePath.message", FALSE);
117
		//append a colon delimiter in case more than one file gets
118
		//appended to the app windows property.
119
		if (file != NULL) {
120
			propVal = malloc((_tcslen(file) + 2) * sizeof(char));
121
			_stprintf(propVal, _T_ECLIPSE("%s%s"), file, ":");
122
		} else {
123
			propVal = malloc(2);
124
			_stprintf(propVal, _T_ECLIPSE("%s"), ":");
125
		}
126
		gdk_property_change(propWindow, propAtom, propAtom, 8, GDK_PROP_MODE_APPEND, (guchar *)propVal, _tcslen(propVal));
127
		free(propVal);
128
		return 1;
129
	}
130
	return 0;
131
}
132
133
int setWindowProperty() {
134
	char	*mutexPrefix = "SWT_Window_";
135
	char 	*appName;
136
	int 	result;
137
138
	appName = malloc((_tcslen(mutexPrefix) + _tcslen(getOfficialName()) + 1) * sizeof(char));
139
	_stprintf(appName, _T_ECLIPSE("%s%s"), mutexPrefix, getOfficialName());
140
	result = executeWithLock(appName, setAppWindowProperty);
141
	XSync (GDK_DISPLAY (), False);
142
	free(appName);
143
	return result;
144
}
145
146
static gboolean timerProc (gpointer data) {
147
	//try to se the app window property. If unsuccessfull return
148
	//true to reschedule the timer. Try 60 times (1 minute) max.
149
	timerAttempts ++;
150
	return !setWindowProperty() && timerAttempts < 60;
151
}
152
153
void findWindow() {
154
	//try setWindowProperty every second until it succeeds
155
	//or a minute has passed.
156
	int count = 0;
157
	while (count < 60 && !setWindowProperty()) {
158
		count++;
159
		sleep(1);
160
	}
161
}
162
163
int createLauncherWindow() {
164
	Window 		window, launcherWindow;
165
	//check if a launcher window exists. If none exists, we know we are the
166
	//first and we should be launching the app.
167
	window = XGetSelectionOwner(GDK_DISPLAY(), launcherAtom);
168
	if (window == 0) {
169
		//create a launcher window that other processes can find.
170
		launcherWindow = XCreateWindow(GDK_DISPLAY(), RootWindow(GDK_DISPLAY(), DefaultScreen(GDK_DISPLAY())), -10, -10, 1, 1, 0, 0,
171
				InputOnly, CopyFromParent, (unsigned long) 0, (XSetWindowAttributes *)NULL);
172
		//for some reason Set and Get are both necessary. Set alone does nothing.
173
		XSetSelectionOwner(GDK_DISPLAY(), launcherAtom, launcherWindow, CurrentTime);
174
		XGetSelectionOwner(GDK_DISPLAY(), launcherAtom);
175
		//add a timeout to set the property on the apps window once the app is launched.
176
		if (file != NULL) {
177
			timerAttempts = 0;
178
			g_timeout_add(1000, timerProc, 0);
179
		}
180
		return 0;
181
	}
182
	return 1;
183
}
184
185
int reuseWorkbench(char* filePath) {
186
	char	*mutexPrefix = "SWT_Window_";
187
	char	*mutexSuffix = "_Launcher";
188
	char	*appName, *launcherName;
189
	int 	result = 0;
190
191
	if(initWindowSystem(&initialArgc, initialArgv, 1) != 0)
192
		return -1;
193
194
	file = filePath;
195
196
	//App name is defined in SWT as well. Values must be consistent.
197
	appName = malloc((_tcslen(mutexPrefix) + _tcslen(getOfficialName()) + 1) * sizeof(char));
198
	_stprintf(appName, _T_ECLIPSE("%s%s"), mutexPrefix, getOfficialName());
199
	appAtom = XInternAtom(GDK_DISPLAY(), appName, FALSE);
200
	free(appName);
201
	launcherName = malloc((_tcslen(mutexPrefix) + _tcslen(getOfficialName()) + _tcslen(mutexSuffix) + 1) * sizeof(char));
202
	_stprintf(launcherName, _T_ECLIPSE("%s%s%s"), mutexPrefix, getOfficialName(), mutexSuffix);
203
	launcherAtom = XInternAtom(GDK_DISPLAY(), launcherName, FALSE);
204
205
	//check if app is already running. Just set property if it is.
206
	if (setWindowProperty()) return 1;
207
208
	result = executeWithLock(launcherName, createLauncherWindow);
209
210
	free(launcherName);
211
212
	if (result == 1) {
213
		//The app is already being launched in another process.
214
		//Wait for it to complete, set the property on its window,
215
		//and exit this process.
216
		if (file != NULL) findWindow();
217
		result = 1;
218
	}
219
220
	return result;
221
}
222
54
/* Create and Display the Splash Window */
223
/* Create and Display the Splash Window */
55
int showSplash( const char* featureImage )
224
int showSplash( const char* featureImage )
56
{
225
{
(-)library/gtk/eclipseGtk.h (+1 lines)
Lines 13-18 Link Here
13
13
14
#include <gtk/gtk.h>
14
#include <gtk/gtk.h>
15
#include <gdk-pixbuf/gdk-pixbuf.h>
15
#include <gdk-pixbuf/gdk-pixbuf.h>
16
#include <gdk/gdkx.h>
16
17
17
struct GTK_PTRS { 
18
struct GTK_PTRS { 
18
	short not_initialized;
19
	short not_initialized;
(-)library/win32/eclipseWin.c (+86 lines)
Lines 14-19 Link Here
14
#include "eclipseUtil.h"
14
#include "eclipseUtil.h"
15
#include "eclipseCommon.h"
15
#include "eclipseCommon.h"
16
#include "eclipseJNI.h"
16
#include "eclipseJNI.h"
17
#include "eclipseShm.h"
17
18
18
#include <windows.h>
19
#include <windows.h>
19
#include <commctrl.h>
20
#include <commctrl.h>
Lines 35-40 Link Here
35
_TCHAR*  vmLibrary 	   = _T("jvm.dll");
36
_TCHAR*  vmLibrary 	   = _T("jvm.dll");
36
_TCHAR*  shippedVMDir  = _T("jre\\bin\\");
37
_TCHAR*  shippedVMDir  = _T("jre\\bin\\");
37
38
39
/* Define local variables for communicating with running eclipse instance. */
40
static HANDLE	mutex;
41
static UINT		findWindowTimeout = 1000;
42
static UINT_PTR findWindowTimerId = 97;
43
static UINT		timerCount = 0;
44
static _TCHAR*	openFilePath;
45
38
/* Define the window system arguments for the Java VM. */
46
/* Define the window system arguments for the Java VM. */
39
static _TCHAR*  argVM[] = { NULL };
47
static _TCHAR*  argVM[] = { NULL };
40
48
Lines 44-49 Link Here
44
static UINT    jvmExitTimeout = 100;
52
static UINT    jvmExitTimeout = 100;
45
static UINT_PTR jvmExitTimerId = 99;
53
static UINT_PTR jvmExitTimerId = 99;
46
54
55
static void CALLBACK findWindowProc(HWND hwnd, UINT message, UINT idTimer, DWORD dwTime);
47
static void CALLBACK  detectJvmExit( HWND hwnd, UINT uMsg, UINT id, DWORD dwTime );
56
static void CALLBACK  detectJvmExit( HWND hwnd, UINT uMsg, UINT id, DWORD dwTime );
48
static _TCHAR* checkVMRegistryKey(HKEY jrekey, _TCHAR* subKeyName);
57
static _TCHAR* checkVMRegistryKey(HKEY jrekey, _TCHAR* subKeyName);
49
static void adjustSearchPath( _TCHAR * vmLibrary );
58
static void adjustSearchPath( _TCHAR * vmLibrary );
Lines 69-74 Link Here
69
#define COMPANY_NAME_KEY _T_ECLIPSE("\\StringFileInfo\\%04x%04x\\CompanyName")
78
#define COMPANY_NAME_KEY _T_ECLIPSE("\\StringFileInfo\\%04x%04x\\CompanyName")
70
#define SUN_MICROSYSTEMS _T_ECLIPSE("Sun Microsystems")
79
#define SUN_MICROSYSTEMS _T_ECLIPSE("Sun Microsystems")
71
80
81
static void sendOpenFileMessage(HWND window) {
82
	_TCHAR* id;
83
	UINT msg;
84
	int size = (_tcslen(openFilePath) + 1) * sizeof(_TCHAR);
85
	DWORD wParam;
86
#ifdef WIN64
87
	DWORDLONG lParam;
88
#else
89
	DWORD lParam;
90
#endif
91
	createSharedData(&id, size);
92
	setSharedData(id, openFilePath);
93
	msg = RegisterWindowMessage(_T("SWT_FILEOPEN"));
94
	_stscanf(id, _T_ECLIPSE("%lx_%lx"), &wParam, &lParam);
95
	SendMessage(window, msg, wParam, lParam);
96
	destroySharedData(id);
97
}
98
99
static int findSWTMessageWindow(int startTimer) {
100
	HWND window;
101
	_TCHAR *windowTitle, *windowPrefix, *name;
102
	int result = 0;
103
104
	windowPrefix = _T("SWT_Window_");
105
	name = getOfficialName();
106
	windowTitle = malloc((_tcslen(windowPrefix) + _tcslen(name) + 1) * sizeof(_TCHAR));
107
	_stprintf(windowTitle, _T_ECLIPSE("%s%s"), windowPrefix, name);
108
	window = FindWindow(NULL, windowTitle);
109
	free(windowTitle);
110
	if (window != NULL) {
111
		sendOpenFileMessage(window);
112
		ReleaseMutex(mutex);
113
		CloseHandle(mutex);
114
		result = 1;
115
	} else {
116
		if (startTimer) {
117
			initWindowSystem(0, NULL, 0);
118
			SetTimer( topWindow, findWindowTimerId, findWindowTimeout, findWindowProc );
119
		}
120
	}
121
	return result;
122
}
123
124
static void CALLBACK findWindowProc(HWND hwnd, UINT message, UINT idTimer, DWORD dwTime) {
125
	if (findSWTMessageWindow(0)) {
126
		KillTimer(hwnd, findWindowTimerId);
127
		return;
128
	}
129
	if (timerCount++ >= 60) {
130
		KillTimer(hwnd, findWindowTimerId);
131
		ReleaseMutex(mutex);
132
		CloseHandle(mutex);
133
	}
134
}
135
136
int reuseWorkbench(_TCHAR* filePath) {
137
	_TCHAR*   mutexPrefix = _T("SWT_Mutex_");
138
	_TCHAR*   mutexName, *name;
139
	DWORD 		result=0, lock;
140
141
	openFilePath = filePath;
142
	name = getOfficialName();
143
	mutexName = malloc((_tcslen(mutexPrefix) + _tcslen(name)  + 1) * sizeof(_TCHAR));
144
	_stprintf(mutexName, _T_ECLIPSE("%s%s"), mutexPrefix, name);
145
	mutex = CreateMutex(NULL, FALSE, mutexName);
146
	free(mutexName);
147
	if (mutex == NULL) return -1;
148
	//wait for up to 1 minute
149
	lock = WaitForSingleObject(mutex, 60*1000);
150
	if (lock == WAIT_OBJECT_0) {
151
		result = findSWTMessageWindow(1);
152
	} else {
153
		CloseHandle(mutex);
154
	}
155
	return result;
156
}
157
72
/* Show the Splash Window
158
/* Show the Splash Window
73
 *
159
 *
74
 * Open the bitmap, insert into the splash window and display it.
160
 * Open the bitmap, insert into the splash window and display it.

Return to bug 178927