2003/09/08 20:40:48
[org.ibex.core.git] / src / org / xwt / plat / Darwin.cc
index 914ba77..76c4fd6 100644 (file)
 #include <java/lang/Object.h>
 #include <java/lang/Error.h>
 
-#include <org/xwt/plat/Carbon.h>
-#include <org/xwt/plat/Carbon$CarbonSurface.h>
-#include <org/xwt/plat/Carbon$GLCarbonSurface.h>
-#include <org/xwt/plat/Carbon$GLCarbonDoubleBuffer.h>
-#include <org/xwt/plat/Carbon$CarbonMessage.h>
-#include <org/xwt/plat/Carbon$CarbonOpenGL.h>
-#include <org/xwt/plat/Carbon$FileDialogHelper.h>
+#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$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/util/Semaphore.h>
@@ -42,13 +42,13 @@ using java::lang::Object;
 
 namespace org { namespace xwt { namespace plat {
 
-namespace carbon { }
-using namespace carbon;
+namespace darwin { }
+using namespace darwin;
 
 #pragma mark ------ Carbon Namespace ------
-namespace carbon {
-    // We put everything that isn't in org.xwt.plat.Carbon in 
-    // org.xwt.plat.carbon to prevent namespace conflicts
+namespace darwin {
+    // We put everything that isn't in org.xwt.plat.Darwin in 
+    // org.xwt.plat.darwin to prevent namespace conflicts
     
     template <bool CHECK> static inline int CompileTimeCheck() { const int something_is_wrong=1; something_is_wrong++; return 0; }
     template <> static inline int CompileTimeCheck<true>() { return 0; }
@@ -125,19 +125,19 @@ namespace carbon {
     const static UInt32 kEventCarbonMessage = 'xwtb';
     const static UInt32 kEventParamCarbonMessage = 'xwtc';
     
-    pascal OSStatus carbon::carbonMessageEventHandler(EventHandlerCallRef handler, EventRef e, void *userData);
+    pascal OSStatus darwin::carbonMessageEventHandler(EventHandlerCallRef handler, EventRef e, void *userData);
     void fileDialogEventHandler(NavEventCallbackMessage callBackSelector, NavCBRecPtr callBackParms, void *userData);
 
 } // end namespace
 
-jboolean Carbon::isJaguar() {
+jboolean Darwin::isJaguar() {
     SInt32 version;
     OSStatus r = Gestalt(gestaltSystemVersion, &version);
     checkStatus(r,"Gestalt");
     return version >= 0x1020;
 }
 
-void Carbon$CarbonMessage::natInit() {
+void Darwin$CarbonMessage::natInit() {
     OSStatus r;
     
     EventHandlerUPP upp = NewEventHandlerUPP(carbonMessageEventHandler);
@@ -146,7 +146,7 @@ void Carbon$CarbonMessage::natInit() {
     checkStatus(r,"InstallEventHandler");
 }
 
-void Carbon$CarbonMessage::add(Carbon$CarbonMessage *msg) {
+void Darwin$CarbonMessage::add(Darwin$CarbonMessage *msg) {
     EventRef event;
     OSStatus r;
     
@@ -162,11 +162,11 @@ void Carbon$CarbonMessage::add(Carbon$CarbonMessage *msg) {
 }
 
 
-pascal OSStatus carbon::carbonMessageEventHandler(EventHandlerCallRef handler, EventRef e, void *userData) {
+pascal OSStatus darwin::carbonMessageEventHandler(EventHandlerCallRef handler, EventRef e, void *userData) {
     UInt32 eKind = GetEventKind(e);
     UInt32 eClass = GetEventClass(e);
     OSStatus r;
-    Carbon$CarbonMessage *msg;
+    Darwin$CarbonMessage *msg;
     if(eClass != kEventClassCarbonMessage || eKind != kEventCarbonMessage)
         return eventNotHandledErr;
     r = GetEventParameter(e,kEventParamCarbonMessage,typeVoidPtr,NULL,sizeof(msg),NULL,&msg);
@@ -179,7 +179,7 @@ pascal OSStatus carbon::carbonMessageEventHandler(EventHandlerCallRef handler, E
 
 #pragma mark ------ Utility Functions ------
 
-void carbon::funcFailed(char *func,int r){
+void darwin::funcFailed(char *func,int r){
     fprintf(stderr,"%s() failed (%d)\n",func,r);
     exit(EXIT_FAILURE);
 } 
@@ -189,7 +189,7 @@ void carbon::funcFailed(char *func,int r){
 #pragma mark ----- Carbon Surface Methods ----
 
 
-void Carbon$CarbonSurface::natSyncCursor(jint n) {
+void Darwin$CarbonSurface::natSyncCursor(jint n) {
     ThemeCursor c;
     // see Carbon.java for what these numbers mean
     switch(n) {
@@ -204,46 +204,46 @@ void Carbon$CarbonSurface::natSyncCursor(jint n) {
     SetThemeCursor(c);
 }
    
-void Carbon$CarbonSurface::natSetInvisible(jboolean b) {
+void Darwin$CarbonSurface::natSetInvisible(jboolean b) {
     WindowRef window = (WindowRef) rawWindowRef;
     fprintf(stderr,"Making window %s\n",b?"invisible":"visible");
     if(b) HideWindow(window);
     else ShowWindow(window);
 }
 
-void Carbon$CarbonSurface::nat_setMaximized(jboolean b) {
+void Darwin$CarbonSurface::nat_setMaximized(jboolean b) {
     WindowRef window = (WindowRef) rawWindowRef;
     Point ideal = { 10000, 10000 };
     OSStatus r = ZoomWindowIdeal(window,(b?inZoomOut:inZoomIn),&ideal);
     checkStatus(r,"ZoomWindowIdeal");
 }
 
-void Carbon$CarbonSurface::nat_setMinimized(jboolean b) {
+void Darwin$CarbonSurface::nat_setMinimized(jboolean b) {
     WindowRef window = (WindowRef) rawWindowRef;
     if((IsWindowCollapsed(window) ? 1 : 0) == (b ? 1 : 0)) return;
     OSStatus r = CollapseWindow(window,b);
     checkStatus(r,"CollapseWindow");
 }
 
-void Carbon$CarbonSurface::natSetTitleBarText(jstring js) {
+void Darwin$CarbonSurface::natSetTitleBarText(jstring js) {
     SmartCFString s = js;
     WindowRef window = (WindowRef) rawWindowRef;
     SetWindowTitleWithCFString(window,s);
 }
 
-void Carbon$CarbonSurface::natToBack() {
+void Darwin$CarbonSurface::natToBack() {
     WindowRef window = (WindowRef) rawWindowRef;
     SendBehind(window,NULL);
 }
 
-void Carbon$CarbonSurface::natToFront() {
+void Darwin$CarbonSurface::natToFront() {
     WindowRef window = (WindowRef) rawWindowRef;
     fprintf(stderr,"SelectWindow()\n");
     SelectWindow(window);
 }
 
 #pragma mark ---- Window Event Handler ----
-namespace carbon {
+namespace darwin {
 static const EventTypeSpec eventTypeSpecs[] = {
     // kEventClassCommand
     // { kEventClassCommand, ??? },
@@ -274,7 +274,7 @@ static const EventTypeSpec eventTypeSpecs[] = {
 };
     
 pascal OSStatus windowEventHandler(EventHandlerCallRef handler, EventRef e, void *userData) {
-    Carbon$CarbonSurface *surface = (Carbon$CarbonSurface*) userData;
+    Darwin$CarbonSurface *surface = (Darwin$CarbonSurface*) userData;
     UInt32 eKind = GetEventKind(e);
     UInt32 eClass = GetEventClass(e);
     OSStatus r;
@@ -453,11 +453,11 @@ pascal OSStatus windowEventHandler(EventHandlerCallRef handler, EventRef e, void
             r = GetEventParameter(e,kEventParamDirectObject,typeWindowRef,NULL,sizeof(window),NULL,&window);
             checkStatus(r,"kEventClassWindow/GetEventParameter");
             
-            if((RawData*)window != surface->rawWindowRef) Carbon::abort(JvNewStringLatin1("window != surface->window"));
+            if((RawData*)window != surface->rawWindowRef) Darwin::abort(JvNewStringLatin1("window != surface->window"));
             
             switch(eKind) {
                 case kEventWindowUpdate: {
-                    surface->Dirty(0,0,surface->width,surface->height);
+                    surface->Dirty(0,0,surface->root->width,surface->root->height);
                     return noErr;
                 }
                 case kEventWindowBoundsChanged: {
@@ -517,7 +517,7 @@ pascal OSStatus windowEventHandler(EventHandlerCallRef handler, EventRef e, void
 }
 } // end namespace
 
-void Carbon$CarbonSurface::natInit(jboolean framed) {
+void Darwin$CarbonSurface::natInit(jboolean framed) {
     WindowRef window;
     Rect rect;
     WindowClass wc = framed ? kDocumentWindowClass : kPlainWindowClass;
@@ -541,15 +541,15 @@ void Carbon$CarbonSurface::natInit(jboolean framed) {
     rawEventHandlerUPP = (RawData*) upp;  
 }
 
-void Carbon$CarbonSurface::natDispose() {
+void Darwin$CarbonSurface::natDispose() {
     WindowRef window = (WindowRef) rawWindowRef;
     DisposeWindow(window);
 }
 
-void Carbon$CarbonSurface::natSetIcon(org::xwt::Picture *_p) {
+void Darwin$CarbonSurface::natSetIcon(org::xwt::Picture *_p) {
 }
 
-void Carbon$CarbonSurface::natSetLocation(jint x, jint y) {
+void Darwin$CarbonSurface::natSetLocation(jint x, jint y) {
     WindowRef window = (WindowRef) rawWindowRef;
     Rect rect;
     OSStatus r = GetWindowBounds(window,kWindowStructureRgn,&rect);
@@ -564,7 +564,7 @@ void Carbon$CarbonSurface::natSetLocation(jint x, jint y) {
     checkStatus(r,"ConstrainWindowToScreen");
 }
 
-void Carbon$CarbonSurface::natSetSize(jint w, jint h) {
+void Darwin$CarbonSurface::natSetSize(jint w, jint h) {
     WindowRef window = (WindowRef) rawWindowRef;
     Rect rect;
     OSStatus r = GetWindowBounds(window,kWindowStructureRgn,&rect);
@@ -577,7 +577,7 @@ void Carbon$CarbonSurface::natSetSize(jint w, jint h) {
     checkStatus(r,"ConstrainWindowToScreen");
 }
 
-void Carbon$CarbonSurface::natSetLimits(jint minw, jint minh, jint maxw, jint maxh) {
+void Darwin$CarbonSurface::natSetLimits(jint minw, jint minh, jint maxw, jint maxh) {
     WindowRef window = (WindowRef) rawWindowRef;
     const int maxMax = 32767;
     const int minMinW = 80;
@@ -593,8 +593,8 @@ void Carbon$CarbonSurface::natSetLimits(jint minw, jint minh, jint maxw, jint ma
 
 
 #pragma mark ------ Carbon Methods ------
-void carbon::fileDialogEventHandler(NavEventCallbackMessage callBackSelector, NavCBRecPtr callBackParms, void *userData) {
-    Carbon$FileDialogHelper *helper = (Carbon$FileDialogHelper*) userData;
+void darwin::fileDialogEventHandler(NavEventCallbackMessage callBackSelector, NavCBRecPtr callBackParms, void *userData) {
+    Darwin$FileDialogHelper *helper = (Darwin$FileDialogHelper*) userData;
     NavDialogRef dialog = callBackParms->context;
     OSStatus r;
     switch(callBackSelector) {
@@ -629,7 +629,7 @@ void carbon::fileDialogEventHandler(NavEventCallbackMessage callBackSelector, Na
     }
 }
 
-void Carbon::natFileDialog(Carbon$FileDialogHelper *helper,jstring suggestion_, jboolean write) {
+void Darwin::natFileDialog(Darwin$FileDialogHelper *helper,jstring suggestion_, jboolean write) {
     NavDialogRef dlg;
     SmartCFString suggestion = suggestion_;
     CFStringRef message = CFSTR("By selecting a file in this dialog you are giving this XWT application permission to access that file.");
@@ -637,7 +637,7 @@ void Carbon::natFileDialog(Carbon$FileDialogHelper *helper,jstring suggestion_,
     WindowRef window = FrontWindow();
     NavDialogCreationOptions options;
         
-    NavEventUPP handler = NewNavEventUPP(carbon::fileDialogEventHandler);
+    NavEventUPP handler = NewNavEventUPP(darwin::fileDialogEventHandler);
     
     NavGetDefaultDialogCreationOptions(&options);
     options.optionFlags =
@@ -660,7 +660,7 @@ void Carbon::natFileDialog(Carbon$FileDialogHelper *helper,jstring suggestion_,
     NavDialogRun(dlg);
 }
 
-jstring Carbon::natGetClipBoard() {
+jstring Darwin::natGetClipBoard() {
     ScrapRef scrap;
     OSStatus r;
     Size size,size2;
@@ -685,7 +685,7 @@ jstring Carbon::natGetClipBoard() {
     return js;
 }
 
-void Carbon::natSetClipBoard(jstring js) {
+void Darwin::natSetClipBoard(jstring js) {
     unsigned int length = js->length();
     ScrapRef scrap;
     OSStatus r;
@@ -697,7 +697,7 @@ void Carbon::natSetClipBoard(jstring js) {
     checkStatus(r,"PutScrapFlavor");
 }
 
-Proxy *Carbon::natDetectProxy() {
+Proxy *Darwin::natDetectProxy() {
     using org::xwt::Proxy;
     Proxy *p=0;
     CFStringRef string;
@@ -806,15 +806,15 @@ doproto(SOCKS,socks)
 */
 }
 
-jint Carbon::cgScreenWidth() {
+jint Darwin::cgScreenWidth() {
     return CGDisplayPixelsWide(kCGDirectMainDisplay);
 }
 
-jint Carbon::cgScreenHeight() {
+jint Darwin::cgScreenHeight() {
     return CGDisplayPixelsHigh(kCGDirectMainDisplay);
 }
 
-void Carbon::_newBrowserWindow(jstring js) {
+void Darwin::_newBrowserWindow(jstring js) {
     SmartCFString cfs = js;
     CFURLRef url = CFURLCreateWithString(kCFAllocatorDefault,cfs,NULL);
     SmartCFString scheme = CFURLCopyScheme(url);
@@ -823,7 +823,7 @@ void Carbon::_newBrowserWindow(jstring js) {
     CFRelease(url);
 }
 
-void Carbon::_exit() {
+void Darwin::_exit() {
     QuitApplicationEventLoop();
 }
 
@@ -834,7 +834,7 @@ extern "C" {
     OSErr CPSSetFrontProcess(ProcessSerialNumber *psn);
 }
 #endif
-void Carbon::natInit() {     
+void Darwin::natInit() {     
     OSStatus r;
     #ifdef XWT_CARBON_NO_BUNDLE_HACK
     {        
@@ -862,19 +862,19 @@ void Carbon::natInit() {
     #endif
 }
 
-void Carbon::_running() {
+void Darwin::_running() {
     RunApplicationEventLoop();
     ExitToShell();
 }
 
 #pragma mark ------ OpenGL Functions -----
 
-void Carbon$CarbonOpenGL::activateSharedContext() {
+void Darwin$CarbonOpenGL::activateSharedContext() {
     AGLContext ctx = (AGLContext) rawSharedContext;
     aglSetCurrentContext(ctx);
 }
 
-jboolean Carbon$CarbonOpenGL::initPixelFormat() {
+jboolean Darwin$CarbonOpenGL::initPixelFormat() {
     GLint attr[] = {
         AGL_NO_RECOVERY,
         AGL_RGBA,
@@ -890,13 +890,13 @@ jboolean Carbon$CarbonOpenGL::initPixelFormat() {
     return rawPixelFormat != 0;
 }
 
-void Carbon$CarbonOpenGL::initSharedContext() {
+void Darwin$CarbonOpenGL::initSharedContext() {
     AGLPixelFormat fmt =  (AGLPixelFormat) rawPixelFormat;
     rawSharedContext = (RawData*) aglCreateContext(fmt,NULL);
     checkStatus(rawSharedContext,"aglCreateContext");
 }
 
-void Carbon$GLCarbonDoubleBuffer::natInit() {
+void Darwin$GLCarbonDoubleBuffer::natInit() {
     WindowClass wc = kPlainWindowClass;
     WindowAttributes attr = 0;
     WindowRef window;
@@ -945,19 +945,19 @@ void Carbon$GLCarbonDoubleBuffer::natInit() {
     rawCTX = (RawData*) ctx;
 }
 
-void Carbon$GLCarbonDoubleBuffer::activateContext() {
+void Darwin$GLCarbonDoubleBuffer::activateContext() {
     AGLContext ctx = (AGLContext) rawCTX;
     aglSetCurrentContext(ctx);
 }
 
-void Carbon$GLCarbonDoubleBuffer::natCleanup(RawData* rawWindowRef, RawData* rawCTX) {
+void Darwin$GLCarbonDoubleBuffer::natCleanup(RawData* rawWindowRef, RawData* rawCTX) {
     WindowRef window = (WindowRef) rawWindowRef;
     AGLContext ctx = (AGLContext) rawCTX;
     aglDestroyContext(ctx);
     DisposeWindow(window);
 }
 
-void Carbon$GLCarbonSurface::natBlit(Carbon$GLCarbonDoubleBuffer *db, jint sx1, jint sy1, jint dx1, jint dy1, jint dx2, jint dy2) {
+void Darwin$GLCarbonSurface::natBlit(Darwin$GLCarbonDoubleBuffer *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);
@@ -1011,7 +1011,7 @@ void Carbon$GLCarbonSurface::natBlit(Carbon$GLCarbonDoubleBuffer *db, jint sx1,
     glFlush();
 }
 
-void Carbon$GLCarbonSurface::natReshape(jint w, jint h) {
+void Darwin$GLCarbonSurface::natReshape(jint w, jint h) {
     AGLContext ctx = (AGLContext) rawCTX;
     
     aglSetCurrentContext (ctx);
@@ -1027,7 +1027,7 @@ void Carbon$GLCarbonSurface::natReshape(jint w, jint h) {
     checkGLError();
 }
 
-void Carbon$GLCarbonSurface::natInit() {
+void Darwin$GLCarbonSurface::natInit() {
     WindowRef window = (WindowRef) rawWindowRef;
     AGLContext ctx,shared;
     AGLPixelFormat fmt;
@@ -1052,10 +1052,10 @@ void Carbon$GLCarbonSurface::natInit() {
     glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
 }
 
-void Carbon$GLCarbonSurface::natDispose() {
+void Darwin$GLCarbonSurface::natDispose() {
     AGLContext ctx = (AGLContext) rawCTX;
     aglDestroyContext(ctx);
-    Carbon$CarbonSurface::natDispose();
+    Darwin$CarbonSurface::natDispose();
 }
 
 } } } // end namepsace org::xwt::plat