|
16 | 16 |
|
17 | 17 | #include "osxbrowser.h" |
18 | 18 |
|
| 19 | +#import <AppKit/AppKit.h> |
| 20 | + |
19 | 21 | //////////////////////////////////////////////////////////////////////////////// |
20 | 22 |
|
21 | 23 | enum |
@@ -74,11 +76,6 @@ - (void)printingFinished: (NSPrintOperation *)printOperation |
74 | 76 | //////////////////////////////////////////////////////////////////////////////// |
75 | 77 |
|
76 | 78 |
|
77 | | -void |
78 | | -OpenDialogEventProc( const NavEventCallbackMessage callbackSelector, |
79 | | - NavCBRecPtr callbackParms, |
80 | | - NavCallBackUserData callbackUD ); |
81 | | - |
82 | 79 | @interface WebBrowserAdapter : NSObject |
83 | 80 | { |
84 | 81 | TAltBrowser *m_browser; |
@@ -278,135 +275,59 @@ @implementation NSObject (WebUIDelegate) |
278 | 275 |
|
279 | 276 | - (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message |
280 | 277 | { |
281 | | - AlertStdCFStringAlertParamRec param; |
282 | | - DialogRef alert; |
283 | | - DialogItemIndex itemHit; |
284 | | - |
285 | | - param.version = kStdCFStringAlertVersionOne; |
286 | | - param.movable = true; |
287 | | - param.helpButton = false; |
288 | | - param.defaultText = (CFStringRef)kAlertDefaultOKText; |
289 | | - param.cancelText = NULL; |
290 | | - param.otherText = NULL; |
291 | | - param.defaultButton = kAlertStdAlertOKButton; |
292 | | - param.cancelButton = 0; |
293 | | - param.position = kWindowDefaultPosition; |
294 | | - param.flags = 0; |
295 | | - |
296 | | - CreateStandardAlert( 0, (CFStringRef)message, NULL, NULL, &alert ); |
297 | | - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
298 | | - RunStandardAlert( alert, NULL, &itemHit ); |
299 | | - [pool release]; |
| 278 | + // Create and display an alert panel |
| 279 | + NSAutoreleasePool* t_pool = [[NSAutoreleasePool alloc] init]; |
| 280 | + NSAlert* t_alert = [[[NSAlert alloc] init] autorelease]; |
| 281 | + [t_alert setMessageText:message]; |
| 282 | + [t_alert runModal]; |
| 283 | + [t_pool release]; |
300 | 284 | } |
301 | 285 |
|
302 | 286 | - (BOOL)webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message |
303 | 287 | { |
304 | | - AlertStdCFStringAlertParamRec param; |
305 | | - DialogRef alert; |
306 | | - DialogItemIndex itemHit; |
307 | | - |
308 | | - param.version = kStdCFStringAlertVersionOne; |
309 | | - param.movable = true; |
310 | | - param.helpButton = false; |
311 | | - param.defaultText = (CFStringRef)kAlertDefaultOKText; |
312 | | - param.cancelText = (CFStringRef)kAlertDefaultCancelText; |
313 | | - param.otherText = NULL; |
314 | | - param.defaultButton = kAlertStdAlertOKButton; |
315 | | - param.cancelButton = kAlertStdAlertCancelButton; |
316 | | - param.position = kWindowDefaultPosition; |
317 | | - param.flags = 0; |
318 | | - |
319 | | - CreateStandardAlert( 0, (CFStringRef)message, NULL, ¶m, &alert ); |
320 | | - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
321 | | - RunStandardAlert( alert, NULL, &itemHit ); |
322 | | - [pool release]; |
323 | | - |
324 | | - return (itemHit == kAlertStdAlertOKButton ); |
| 288 | + // Create and display an alert panel with OK/Cancel buttons |
| 289 | + NSAutoreleasePool* t_pool = [[NSAutoreleasePool alloc] init]; |
| 290 | + NSAlert* t_alert = [[[NSAlert alloc] init] autorelease]; |
| 291 | + NSInteger t_response; |
| 292 | + [t_alert setMessageText:message]; |
| 293 | + [t_alert addButtonWithTitle:@"Cancel"]; |
| 294 | + t_response = [t_alert runModal]; |
| 295 | + [t_pool release]; |
| 296 | + return (t_response == NSAlertFirstButtonReturn); |
325 | 297 | } |
326 | 298 |
|
327 | 299 | - (void)webView:(WebView *)sender runOpenPanelForFileButtonWithResultListener:(id<WebOpenPanelResultListener>)resultListener |
328 | 300 | { |
329 | | - NavDialogCreationOptions dialogOptions; |
330 | | - NavDialogRef dialog; |
331 | | - OSStatus theErr = noErr; |
332 | | - |
333 | | - NavGetDefaultDialogCreationOptions( &dialogOptions ); |
334 | | - |
335 | | - dialogOptions.modality = kWindowModalityAppModal; |
336 | | - dialogOptions.clientName = CFStringCreateWithPascalString( NULL, LMGetCurApName(), GetApplicationTextEncoding()); |
337 | | - dialogOptions.optionFlags &= ~kNavAllowMultipleFiles; |
338 | | - |
339 | | - theErr = NavCreateChooseFileDialog( &dialogOptions, NULL, OpenDialogEventProc, NULL, NULL, resultListener, &dialog ); |
340 | | - if ( theErr == noErr ) |
341 | | - { |
342 | | - theErr = NavDialogRun( dialog ); |
343 | | - } |
344 | | - |
345 | | - if ( theErr != noErr ) |
346 | | - { |
347 | | - NavDialogDispose( dialog ); |
348 | | - [resultListener cancel]; |
349 | | - } |
| 301 | + // Create an open-file panel that allows a single file to be chosen |
| 302 | + NSOpenPanel* t_dialog = [NSOpenPanel openPanel]; |
| 303 | + [t_dialog setCanChooseDirectories:NO]; |
| 304 | + [t_dialog setCanChooseFiles:YES]; |
| 305 | + [t_dialog setAllowsMultipleSelection:NO]; |
| 306 | + |
| 307 | + // Run the dialogue |
| 308 | + NSInteger t_result = [t_dialog runModal]; |
| 309 | + |
| 310 | + // If the user didn't cancel it, get the selection |
| 311 | + if (t_result == NSFileHandlingPanelOKButton) |
| 312 | + { |
| 313 | + // Get the URL that was selected and convert to a file path |
| 314 | + NSURL* t_url = [[t_dialog URL] filePathURL]; |
| 315 | + NSString* t_path = [t_url path]; |
| 316 | + |
| 317 | + // Send it to the listener |
| 318 | + [resultListener chooseFilename:t_path]; |
| 319 | + } |
| 320 | + else |
| 321 | + { |
| 322 | + // The dialogue was cancelled and no selection was made |
| 323 | + [resultListener cancel]; |
| 324 | + } |
| 325 | + |
| 326 | + [t_dialog release]; |
350 | 327 | } |
351 | 328 |
|
352 | 329 | @end |
353 | 330 |
|
354 | | -void |
355 | | -OpenDialogEventProc( const NavEventCallbackMessage callbackSelector, |
356 | | - NavCBRecPtr callbackParms, |
357 | | - NavCallBackUserData callbackUD ) |
358 | | -{ |
359 | | - id<WebOpenPanelResultListener> resultListener = (id<WebOpenPanelResultListener>)callbackUD; |
360 | | - |
361 | | - switch ( callbackSelector ) |
362 | | - { |
363 | | - case kNavCBUserAction: |
364 | | - if ( callbackParms->userAction == kNavUserActionChoose ) |
365 | | - { |
366 | | - NavReplyRecord reply; |
367 | | - OSStatus status; |
368 | | - |
369 | | - status = NavDialogGetReply( callbackParms->context, &reply ); |
370 | | - if ( status == noErr ) |
371 | | - { |
372 | | - OSStatus anErr; |
373 | | - AEKeyword keywd; |
374 | | - DescType returnedType; |
375 | | - Size actualSize; |
376 | | - FSRef fileRef; |
377 | | - FSCatalogInfo theCatInfo; |
378 | | - UInt8 path[1024]; |
379 | | - CFStringRef filename; |
380 | | - |
381 | | - anErr = AEGetNthPtr( &reply.selection, 1, typeFSRef, &keywd, &returnedType, |
382 | | - (Ptr)(&fileRef), sizeof( fileRef ), &actualSize ); |
383 | | - require_noerr(anErr, AEGetNthPtr); |
384 | | - |
385 | | - anErr = FSGetCatalogInfo( &fileRef, kFSCatInfoFinderInfo, &theCatInfo, NULL, NULL, NULL ); |
386 | | - require_noerr(anErr, FSGetCatalogInfo); |
387 | | - |
388 | | - FSRefMakePath( &fileRef, path, sizeof( path ) ); |
389 | | - filename = CFStringCreateWithCString( NULL, (char *)path, kCFStringEncodingUTF8 ); |
390 | | - [resultListener chooseFilename:(NSString*)filename]; |
391 | | - CFRelease( filename ); |
392 | | - |
393 | | - AEGetNthPtr: |
394 | | - FSGetCatalogInfo: |
395 | | - |
396 | | - NavDisposeReply( &reply ); |
397 | | - } |
398 | | - } |
399 | | - else if ( callbackParms->userAction == kNavUserActionCancel ) |
400 | | - { |
401 | | - [resultListener cancel]; |
402 | | - } |
403 | | - break; |
404 | | - |
405 | | - case kNavCBTerminate: |
406 | | - NavDialogDispose( callbackParms->context ); |
407 | | - break; |
408 | | - } |
409 | | -} |
410 | 331 |
|
411 | 332 | //////////////////////////////////////////////////////////////////////////////// |
412 | 333 |
|
@@ -487,10 +408,8 @@ - (void)com_runrev_livecode_setNativeViewId:(int)new_id |
487 | 408 |
|
488 | 409 | @end |
489 | 410 |
|
490 | | -void TAltBrowser::init(unsigned int p_window) |
| 411 | +void TAltBrowser::init(uintptr_t p_window) |
491 | 412 | { |
492 | | - WebInitForCarbon(); |
493 | | - |
494 | 413 | m_parent = p_window; |
495 | 414 |
|
496 | 415 | NSWindow *t_window; |
|
0 commit comments