Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit a39e5a7

Browse files
[[ Mac64 ]] Use the Cocoa dialogues instead of Carbon in revbrowser
1 parent 625110a commit a39e5a7

File tree

1 file changed

+44
-125
lines changed

1 file changed

+44
-125
lines changed

revbrowser/src/osxbrowser.mm

Lines changed: 44 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#include "osxbrowser.h"
1818

19+
#import <AppKit/AppKit.h>
20+
1921
////////////////////////////////////////////////////////////////////////////////
2022

2123
enum
@@ -74,11 +76,6 @@ - (void)printingFinished: (NSPrintOperation *)printOperation
7476
////////////////////////////////////////////////////////////////////////////////
7577

7678

77-
void
78-
OpenDialogEventProc( const NavEventCallbackMessage callbackSelector,
79-
NavCBRecPtr callbackParms,
80-
NavCallBackUserData callbackUD );
81-
8279
@interface WebBrowserAdapter : NSObject
8380
{
8481
TAltBrowser *m_browser;
@@ -278,135 +275,59 @@ @implementation NSObject (WebUIDelegate)
278275

279276
- (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message
280277
{
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];
300284
}
301285

302286
- (BOOL)webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message
303287
{
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, &param, &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);
325297
}
326298

327299
- (void)webView:(WebView *)sender runOpenPanelForFileButtonWithResultListener:(id<WebOpenPanelResultListener>)resultListener
328300
{
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];
350327
}
351328

352329
@end
353330

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-
}
410331

411332
////////////////////////////////////////////////////////////////////////////////
412333

@@ -487,10 +408,8 @@ - (void)com_runrev_livecode_setNativeViewId:(int)new_id
487408

488409
@end
489410

490-
void TAltBrowser::init(unsigned int p_window)
411+
void TAltBrowser::init(uintptr_t p_window)
491412
{
492-
WebInitForCarbon();
493-
494413
m_parent = p_window;
495414

496415
NSWindow *t_window;

0 commit comments

Comments
 (0)