155 {
156 GlassScreenDidChangeScreenParameters(env);
157 }
158 }
159
160 - (void)applicationWillFinishLaunching:(NSNotification *)aNotification
161 {
162 LOG("GlassApplication:applicationWillFinishLaunching");
163
164 GET_MAIN_JENV;
165 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
166 {
167 if (self->jLaunchable != NULL)
168 {
169 jclass runnableClass = [GlassHelper ClassForName:"java.lang.Runnable" withEnv:jEnv];
170 if ((*env)->ExceptionCheck(env) == JNI_TRUE)
171 {
172 (*env)->ExceptionDescribe(env);
173 (*env)->ExceptionClear(env);
174 }
175
176 jmethodID runMethod = (*env)->GetMethodID(env, runnableClass, "run", "()V");
177 if ((*env)->ExceptionCheck(env) == JNI_TRUE)
178 {
179 (*env)->ExceptionDescribe(env);
180 (*env)->ExceptionClear(env);
181 }
182
183 if ((runnableClass != 0) && (runMethod != 0))
184 {
185 (*env)->CallVoidMethod(env, self->jLaunchable, runMethod);
186 if ((*env)->ExceptionCheck(env) == JNI_TRUE)
187 {
188 (*env)->ExceptionDescribe(env);
189 (*env)->ExceptionClear(env);
190 }
191 else
192 {
193 [[NSNotificationCenter defaultCenter] addObserver:self
194 selector:@selector(GlassApplicationDidChangeScreenParameters)
195 name:NSApplicationDidChangeScreenParametersNotification
196 object:nil];
197
198 // localMonitor = [NSEvent addLocalMonitorForEventsMatchingMask: NSRightMouseDownMask
199 // handler:^(NSEvent *incomingEvent) {
200 // NSEvent *result = incomingEvent;
201 // NSWindow *targetWindowForEvent = [incomingEvent window];
202 // LOG("NSRightMouseDownMask local");
203 // return result;
204 // }];
205 //
206 // globalMonitor = [NSEvent addGlobalMonitorForEventsMatchingMask: NSRightMouseDownMask
207 // handler:^(NSEvent *incomingEvent) {
208 // NSEvent *result = incomingEvent;
209 // NSWindow *targetWindowForEvent = [incomingEvent window];
210 // NSWindow *window = [[NSApplication sharedApplication]
211 // windowWithWindowNumber:[incomingEvent windowNumber]];
212 // NSWindow *appWindow = [[NSApplication sharedApplication] mainWindow];
213 // LOG("NSRightMouseDownMask global: %p num %d win %p appwin %p",
214 // targetWindowForEvent, [incomingEvent windowNumber], window,
215 // [[NSApplication sharedApplication] mainWindow]);
216 // }];
217 }
218 }
219 else if (runnableClass == 0)
220 {
221 NSLog(@"ERROR: Glass could not find Runnable class\n");
222 }
223 else //if (runMethod == 0)
224 {
225 NSLog(@"ERROR: Glass could not find run() method\n");
226 }
227 }
228
229 (*env)->CallVoidMethod(env, self->jApplication, [GlassHelper ApplicationNotifyWillFinishLaunchingMethod]);
230
231 self->started = YES;
232 }
233 [pool drain];
234 GLASS_CHECK_EXCEPTION(env);
235 }
236
237 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
238 {
239 LOG("GlassApplication:applicationDidFinishLaunching");
240
241 GET_MAIN_JENV;
242 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
243 {
244 (*env)->CallVoidMethod(env, self->jApplication, [GlassHelper ApplicationNotifyDidFinishLaunchingMethod]);
245 }
246 [pool drain];
342 {
343 LOG("GlassApplication:applicationDidUnhide");
344
345 GET_MAIN_JENV;
346 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
347 {
348 (*env)->CallVoidMethod(env, self->jApplication, [GlassHelper ApplicationNotifyDidUnhideMethod]);
349 }
350 [pool drain];
351 GLASS_CHECK_EXCEPTION(env);
352 }
353
354 - (void)application:(NSApplication *)theApplication openFiles:(NSArray *)filenames
355 {
356 LOG("GlassApplication:application:openFiles");
357
358 GET_MAIN_JENV;
359 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
360 {
361 NSUInteger count = [filenames count];
362 jobjectArray files = (*env)->NewObjectArray(env, (jsize)count, [GlassHelper ClassForName:"java.lang.String" withEnv:env], NULL);
363 GLASS_CHECK_EXCEPTION(env);
364 for (NSUInteger i=0; i<count; i++)
365 {
366 NSString *file = [filenames objectAtIndex:i];
367 if (file != nil)
368 {
369 (*env)->SetObjectArrayElement(env, files, (jsize)i, (*env)->NewStringUTF(env, [file UTF8String]));
370 GLASS_CHECK_EXCEPTION(env);
371 }
372 }
373 (*env)->CallVoidMethod(env, self->jApplication, [GlassHelper ApplicationNotifyOpenFilesMethod], files);
374 }
375 [pool drain];
376 GLASS_CHECK_EXCEPTION(env);
377
378 [theApplication replyToOpenOrPrint:NSApplicationDelegateReplySuccess];
379 }
380
381 - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
382 {
|
155 {
156 GlassScreenDidChangeScreenParameters(env);
157 }
158 }
159
160 - (void)applicationWillFinishLaunching:(NSNotification *)aNotification
161 {
162 LOG("GlassApplication:applicationWillFinishLaunching");
163
164 GET_MAIN_JENV;
165 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
166 {
167 if (self->jLaunchable != NULL)
168 {
169 jclass runnableClass = [GlassHelper ClassForName:"java.lang.Runnable" withEnv:jEnv];
170 if ((*env)->ExceptionCheck(env) == JNI_TRUE)
171 {
172 (*env)->ExceptionDescribe(env);
173 (*env)->ExceptionClear(env);
174 }
175 if (runnableClass) {
176 jmethodID runMethod = (*env)->GetMethodID(env, runnableClass, "run", "()V");
177 if ((*env)->ExceptionCheck(env) == JNI_TRUE)
178 {
179 (*env)->ExceptionDescribe(env);
180 (*env)->ExceptionClear(env);
181 }
182 if (runMethod) {
183 (*env)->CallVoidMethod(env, self->jLaunchable, runMethod);
184 if ((*env)->ExceptionCheck(env) == JNI_TRUE)
185 {
186 (*env)->ExceptionDescribe(env);
187 (*env)->ExceptionClear(env);
188 }
189 else
190 {
191 [[NSNotificationCenter defaultCenter] addObserver:self
192 selector:@selector(GlassApplicationDidChangeScreenParameters)
193 name:NSApplicationDidChangeScreenParametersNotification
194 object:nil];
195
196 // localMonitor = [NSEvent addLocalMonitorForEventsMatchingMask: NSRightMouseDownMask
197 // handler:^(NSEvent *incomingEvent) {
198 // NSEvent *result = incomingEvent;
199 // NSWindow *targetWindowForEvent = [incomingEvent window];
200 // LOG("NSRightMouseDownMask local");
201 // return result;
202 // }];
203 //
204 // globalMonitor = [NSEvent addGlobalMonitorForEventsMatchingMask: NSRightMouseDownMask
205 // handler:^(NSEvent *incomingEvent) {
206 // NSEvent *result = incomingEvent;
207 // NSWindow *targetWindowForEvent = [incomingEvent window];
208 // NSWindow *window = [[NSApplication sharedApplication]
209 // windowWithWindowNumber:[incomingEvent windowNumber]];
210 // NSWindow *appWindow = [[NSApplication sharedApplication] mainWindow];
211 // LOG("NSRightMouseDownMask global: %p num %d win %p appwin %p",
212 // targetWindowForEvent, [incomingEvent windowNumber], window,
213 // [[NSApplication sharedApplication] mainWindow]);
214 // }];
215 }
216 } else {
217 NSLog(@"ERROR: Glass could not find run() method\n");
218 }
219 } else {
220 NSLog(@"ERROR: Glass could not find Runnable class\n");
221 }
222 }
223
224 (*env)->CallVoidMethod(env, self->jApplication, [GlassHelper ApplicationNotifyWillFinishLaunchingMethod]);
225
226 self->started = YES;
227 }
228 [pool drain];
229 GLASS_CHECK_EXCEPTION(env);
230 }
231
232 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
233 {
234 LOG("GlassApplication:applicationDidFinishLaunching");
235
236 GET_MAIN_JENV;
237 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
238 {
239 (*env)->CallVoidMethod(env, self->jApplication, [GlassHelper ApplicationNotifyDidFinishLaunchingMethod]);
240 }
241 [pool drain];
337 {
338 LOG("GlassApplication:applicationDidUnhide");
339
340 GET_MAIN_JENV;
341 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
342 {
343 (*env)->CallVoidMethod(env, self->jApplication, [GlassHelper ApplicationNotifyDidUnhideMethod]);
344 }
345 [pool drain];
346 GLASS_CHECK_EXCEPTION(env);
347 }
348
349 - (void)application:(NSApplication *)theApplication openFiles:(NSArray *)filenames
350 {
351 LOG("GlassApplication:application:openFiles");
352
353 GET_MAIN_JENV;
354 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
355 {
356 NSUInteger count = [filenames count];
357 jclass stringClass = [GlassHelper ClassForName:"java.lang.String" withEnv:env];
358 if (!stringClass) {
359 return;
360 }
361 jobjectArray files = (*env)->NewObjectArray(env, (jsize)count, stringClass, NULL);
362 GLASS_CHECK_EXCEPTION(env);
363 for (NSUInteger i=0; i<count; i++)
364 {
365 NSString *file = [filenames objectAtIndex:i];
366 if (file != nil)
367 {
368 (*env)->SetObjectArrayElement(env, files, (jsize)i, (*env)->NewStringUTF(env, [file UTF8String]));
369 GLASS_CHECK_EXCEPTION(env);
370 }
371 }
372 (*env)->CallVoidMethod(env, self->jApplication, [GlassHelper ApplicationNotifyOpenFilesMethod], files);
373 }
374 [pool drain];
375 GLASS_CHECK_EXCEPTION(env);
376
377 [theApplication replyToOpenOrPrint:NSApplicationDelegateReplySuccess];
378 }
379
380 - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
381 {
|