2003/09/20 05:03:47
[org.ibex.core.git] / src / org / xwt / plat / Darwin.cc
index cb08664..068b766 100644 (file)
@@ -7,6 +7,9 @@
 #define APPLE_GCC
 #endif
 
+#define __private_extern__
+#include <mach-o/dyld.h>
+
 #include "POSIX.cc"
 #include "OpenGL.cc"
 
 #include <org/xwt/plat/Darwin.h>
 #include <org/xwt/plat/Darwin$CarbonSurface.h>
 #include <org/xwt/plat/Darwin$GLCarbonSurface.h>
-#include <org/xwt/plat/Darwin$GLCarbonDoubleBuffer.h>
+#include <org/xwt/plat/Darwin$GLCarbonPixelBuffer.h>
 #include <org/xwt/plat/Darwin$CarbonMessage.h>
 #include <org/xwt/plat/Darwin$CarbonOpenGL.h>
 #include <org/xwt/plat/Darwin$FileDialogHelper.h>
 #include <org/xwt/plat/GCJ$Retainer.h>
-#include <org/xwt/Proxy.h>
+#include <org/xwt/HTTP$Proxy.h>
 #include <org/xwt/util/Semaphore.h>
 
-#include <Carbon/Carbon.h>
-#include <CoreFoundation/CoreFoundation.h>
-// For proxy stuff
-#include <SystemConfiguration/SystemConfiguration.h>
-// For LSOpenURLRef
-#include <ApplicationServices/ApplicationServices.h>
+#include <stdlib.h>
+#include <objc/objc.h>
 
-#include <AGL/agl.h>
+#include "DarwinCarbonHeaders.h"
 
-#include <stdlib.h>
+#define XWT_CARBON_NO_BUNDLE_HACK
+#ifdef XWT_CARBON_NO_BUNDLE_HACK
+extern "C" {
+    OSErr CPSEnableForegroundOperation(ProcessSerialNumber *psn);
+    OSErr CPSSetFrontProcess(ProcessSerialNumber *psn);
+}
+#endif
+
+#include "DarwinWeakSymbols.h"
 
 using namespace org::xwt::plat;
 using gnu::gcj::RawData;
@@ -45,8 +52,8 @@ namespace org { namespace xwt { namespace plat {
 namespace darwin { }
 using namespace darwin;
 
-#pragma mark ------ Carbon Namespace ------
-namespace darwin {
+#pragma mark ------ Darwin Namespace ------
+
     // We put everything that isn't in org.xwt.plat.Darwin in 
     // org.xwt.plat.darwin to prevent namespace conflicts
     
@@ -125,10 +132,10 @@ namespace darwin {
     const static UInt32 kEventCarbonMessage = 'xwtb';
     const static UInt32 kEventParamCarbonMessage = 'xwtc';
     
-    pascal OSStatus darwin::carbonMessageEventHandler(EventHandlerCallRef handler, EventRef e, void *userData);
+    OSStatus our_carbonMessageEventHandler(EventHandlerCallRef handler, EventRef e, void *userData);
     void fileDialogEventHandler(NavEventCallbackMessage callBackSelector, NavCBRecPtr callBackParms, void *userData);
 
-} // end namespace
+
 
 jboolean Darwin::isJaguar() {
     SInt32 version;
@@ -137,10 +144,14 @@ jboolean Darwin::isJaguar() {
     return version >= 0x1020;
 }
 
+void Darwin::linkMe() {
+    load_weak_symbols();
+}
+
 void Darwin$CarbonMessage::natInit() {
     OSStatus r;
     
-    EventHandlerUPP upp = NewEventHandlerUPP(carbonMessageEventHandler);
+    EventHandlerUPP upp = NewEventHandlerUPP(our_carbonMessageEventHandler);
     EventTypeSpec eventTypes = { kEventClassCarbonMessage, kEventCarbonMessage };
     r = InstallEventHandler(GetApplicationEventTarget(),upp,1,&eventTypes,NULL,NULL);
     checkStatus(r,"InstallEventHandler");
@@ -162,7 +173,7 @@ void Darwin$CarbonMessage::add(Darwin$CarbonMessage *msg) {
 }
 
 
-pascal OSStatus darwin::carbonMessageEventHandler(EventHandlerCallRef handler, EventRef e, void *userData) {
+OSStatus our_carbonMessageEventHandler(EventHandlerCallRef handler, EventRef e, void *userData) {
     UInt32 eKind = GetEventKind(e);
     UInt32 eClass = GetEventClass(e);
     OSStatus r;
@@ -179,7 +190,7 @@ pascal OSStatus darwin::carbonMessageEventHandler(EventHandlerCallRef handler, E
 
 #pragma mark ------ Utility Functions ------
 
-void darwin::funcFailed(char *func,int r){
+void funcFailed(char *func,int r){
     fprintf(stderr,"%s() failed (%d)\n",func,r);
     exit(EXIT_FAILURE);
 } 
@@ -273,7 +284,7 @@ static const EventTypeSpec eventTypeSpecs[] = {
     { kEventClassMouse, kEventMouseWheelMoved },
 };
     
-pascal OSStatus windowEventHandler(EventHandlerCallRef handler, EventRef e, void *userData) {
+OSStatus our_windowEventHandler(EventHandlerCallRef handler, EventRef e, void *userData) {
     Darwin$CarbonSurface *surface = (Darwin$CarbonSurface*) userData;
     UInt32 eKind = GetEventKind(e);
     UInt32 eClass = GetEventClass(e);
@@ -530,9 +541,18 @@ void Darwin$CarbonSurface::natInit(jboolean framed) {
     rect.top = 0; rect.left = 0; rect.bottom = 10; rect.right=10;
     r = CreateNewWindow(wc,attr,&rect,&window);
     checkStatus(r,"CreateNewWindow");
+
+    id NSWindowClass = objc_getClass("NSWindow");
+    printf("nswindowclass is %x\n", NSWindowClass);
+    SEL selector = sel_registerName("initWithWindowRef");
+    printf("selector is %s\n", selector);
+    objc_method method = class_getClassMethod(NSWindowClass, selector);
+    printf("method is %x\n", method);
+    id windowInstance = objc_msgSend(NSWindowClass, selector, window);
+    printf("instance is %x\n", windowInstance);
     
     GCJ$Retainer::retain(this); // Need to account for the EventHandlers pointer to us
-    EventHandlerUPP upp = NewEventHandlerUPP(windowEventHandler);
+    EventHandlerUPP upp = NewEventHandlerUPP(our_windowEventHandler);
     
     r = InstallWindowEventHandler(window,upp,sizeof(eventTypeSpecs)/sizeof(EventTypeSpec),eventTypeSpecs,this,NULL);
     checkStatus(r,"InstallWindowEventHandler");
@@ -593,7 +613,7 @@ void Darwin$CarbonSurface::natSetLimits(jint minw, jint minh, jint maxw, jint ma
 
 
 #pragma mark ------ Carbon Methods ------
-void darwin::fileDialogEventHandler(NavEventCallbackMessage callBackSelector, NavCBRecPtr callBackParms, void *userData) {
+void fileDialogEventHandler(NavEventCallbackMessage callBackSelector, NavCBRecPtr callBackParms, void *userData) {
     Darwin$FileDialogHelper *helper = (Darwin$FileDialogHelper*) userData;
     NavDialogRef dialog = callBackParms->context;
     OSStatus r;
@@ -637,7 +657,7 @@ void Darwin::natFileDialog(Darwin$FileDialogHelper *helper,jstring suggestion_,
     WindowRef window = FrontWindow();
     NavDialogCreationOptions options;
         
-    NavEventUPP handler = NewNavEventUPP(darwin::fileDialogEventHandler);
+    NavEventUPP handler = NewNavEventUPP(fileDialogEventHandler);
     
     NavGetDefaultDialogCreationOptions(&options);
     options.optionFlags =
@@ -697,9 +717,9 @@ void Darwin::natSetClipBoard(jstring js) {
     checkStatus(r,"PutScrapFlavor");
 }
 
-Proxy *Darwin::natDetectProxy() {
-    using org::xwt::Proxy;
-    Proxy *p=0;
+HTTP$Proxy *Darwin::natDetectProxy() {
+    using org::xwt::HTTP$Proxy;
+    HTTP$Proxy *p=0;
     CFStringRef string;
     CFNumberRef number;
     SmartCFString smartString;
@@ -718,7 +738,7 @@ Proxy *Darwin::natDetectProxy() {
         number = (CFNumberRef) CFDictionaryGetValue(proxyInfo, kSCPropNetProxies ## proto ## Port); \
         if(number != NULL && CFGetTypeID(number) != CFNumberGetTypeID()) number = NULL;    \
         if(string && number && CFNumberGetValue(number,kCFNumberIntType,&i) && i) {        \
-            if(!p) p = new Proxy();                                                        \
+            if(!p) p = new HTTP$Proxy();                                                        \
             p->var ## ProxyHost = cfStringToJString(string);                           \
             p->var ## ProxyPort = i;                                                   \
         }                                                                                  \
@@ -807,11 +827,11 @@ doproto(SOCKS,socks)
 }
 
 jint Darwin::cgScreenWidth() {
-    return CGDisplayPixelsWide(kCGDirectMainDisplay);
+    return CGDisplayPixelsWide(((CGDirectDisplayID)0));
 }
 
 jint Darwin::cgScreenHeight() {
-    return CGDisplayPixelsHigh(kCGDirectMainDisplay);
+    return CGDisplayPixelsHigh(((CGDirectDisplayID)0));
 }
 
 void Darwin::_newBrowserWindow(jstring js) {
@@ -827,13 +847,6 @@ void Darwin::_exit() {
     QuitApplicationEventLoop();
 }
 
-#define XWT_CARBON_NO_BUNDLE_HACK
-#ifdef XWT_CARBON_NO_BUNDLE_HACK
-extern "C" {
-    OSErr CPSEnableForegroundOperation(ProcessSerialNumber *psn);
-    OSErr CPSSetFrontProcess(ProcessSerialNumber *psn);
-}
-#endif
 void Darwin::natInit() {     
     OSStatus r;
     #ifdef XWT_CARBON_NO_BUNDLE_HACK
@@ -896,7 +909,7 @@ void Darwin$CarbonOpenGL::initSharedContext() {
     checkStatus(rawSharedContext,"aglCreateContext");
 }
 
-void Darwin$GLCarbonDoubleBuffer::natInit() {
+void Darwin$GLCarbonPixelBuffer::natInit() {
     WindowClass wc = kPlainWindowClass;
     WindowAttributes attr = 0;
     WindowRef window;
@@ -945,19 +958,19 @@ void Darwin$GLCarbonDoubleBuffer::natInit() {
     rawCTX = (RawData*) ctx;
 }
 
-void Darwin$GLCarbonDoubleBuffer::activateContext() {
+void Darwin$GLCarbonPixelBuffer::activateContext() {
     AGLContext ctx = (AGLContext) rawCTX;
     aglSetCurrentContext(ctx);
 }
 
-void Darwin$GLCarbonDoubleBuffer::natCleanup(RawData* rawWindowRef, RawData* rawCTX) {
+void Darwin$GLCarbonPixelBuffer::natCleanup(RawData* rawWindowRef, RawData* rawCTX) {
     WindowRef window = (WindowRef) rawWindowRef;
     AGLContext ctx = (AGLContext) rawCTX;
     aglDestroyContext(ctx);
     DisposeWindow(window);
 }
 
-void Darwin$GLCarbonSurface::natBlit(Darwin$GLCarbonDoubleBuffer *db, jint sx1, jint sy1, jint dx1, jint dy1, jint dx2, jint dy2) {
+void Darwin$GLCarbonSurface::natBlit(Darwin$GLCarbonPixelBuffer *db, jint sx1, jint sy1, jint dx1, jint dy1, jint dx2, jint dy2) {
     AGLContext ctx = (AGLContext) rawCTX;
     int sx2 = sx1 + (dx2-dx1);
     int sy2 = sy1 + (dy2-dy1);