Back to index

texmacs  1.0.7.15
mac_app.mm
Go to the documentation of this file.
00001 /******************************************************************************
00002  * MODULE     : mac_app.mm
00003  * DESCRIPTION: NSApplication related function for the X11 interface
00004  * COPYRIGHT  : (C) 2009  Massimiliano Gubinelli
00005  *******************************************************************************
00006  * This software falls under the GNU general public license version 3 or later.
00007  * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00008  * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00009  ******************************************************************************/
00010 
00011 #include "mac_app.h"
00012 #include "Cocoa/mac_cocoa.h"
00013 #include "mac_utilities.h"
00014 #include "url.hpp"
00015 #include "converter.hpp"
00016 #include "../Scheme/scheme.hpp"
00017 
00018 static string 
00019 from_nsstring (NSString *s) {
00020   const char *cstr = [s cStringUsingEncoding:NSUTF8StringEncoding];
00021   return utf8_to_cork(string((char*)cstr));
00022 }
00023 
00024 
00025 @interface TMAppDelegate : NSObject {
00026 }
00027 - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename ;
00028 @end
00029 
00030 @implementation TMAppDelegate
00031 - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename 
00032 {
00033   (void) theApplication;
00034   call ("texmacs-load-buffer", object(url_system (from_nsstring(filename))), object("generic"), object(1), object(false));
00035   return YES;
00036 }
00037 @end
00038 
00039 NSAutoreleasePool *pool = nil;
00040 TMAppDelegate *delegate = nil;
00041 
00042 void init_mac_application ()
00043 {
00044   [NSApplication sharedApplication];
00045   pool = [[NSAutoreleasePool alloc] init]; 
00046   delegate = [[TMAppDelegate alloc] init];
00047   [NSApp setDelegate: delegate];
00048   [NSApp finishLaunching];
00049   
00050   mac_begin_remote ();
00051 }
00052 
00053 void finalize_mac_application ()
00054 {  
00055   mac_end_remote ();
00056 
00057   [pool release];
00058   [NSApp setDelegate:nil];
00059   [delegate release];
00060 }
00061 
00062 void process_mac_events ()
00063 {
00064   do {
00065     [pool release];
00066     pool = [[NSAutoreleasePool alloc] init];
00067     
00068     NSEvent *event =
00069     //[NSDate distantFuture][NSApp
00070      nextEventMatchingMask:NSAnyEventMask
00071      untilDate:nil 
00072      inMode:NSDefaultRunLoopMode
00073      dequeue:YES];
00074     
00075     if (!event) break;
00076     [NSApp sendEvent:event];
00077     [NSApp updateWindows];
00078   } while (true);
00079   
00080 }