latest CW additions
authorStefan Csomor <csomor@advancedconcepts.ch>
Mon, 1 Feb 1999 15:00:12 +0000 (15:00 +0000)
committerStefan Csomor <csomor@advancedconcepts.ch>
Mon, 1 Feb 1999 15:00:12 +0000 (15:00 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1556 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

17 files changed:
include/wx/mac/filedlg.h
include/wx/mac/setup.h
include/wx/msw/setup.h
src/common/file.cpp
src/common/fileconf.cpp
src/common/gdicmn.cpp
src/mac/app.cpp
src/mac/carbon/app.cpp
src/mac/carbon/data.cpp
src/mac/carbon/filedlg.cpp
src/mac/carbon/scrolbar.cpp
src/mac/carbon/thread.cpp
src/mac/data.cpp
src/mac/filedlg.cpp
src/mac/scrolbar.cpp
src/mac/thread.cpp
src/msw/app.cpp

index 0259f2d9435524d0d84917ff347e79aad4336f34..2e4c6476e69688ded310da18c7ef0d3a3c20e80b 100644 (file)
@@ -67,23 +67,26 @@ public:
 #define wxHIDE_READONLY     0x0008
 #define wxFILE_MUST_EXIST   0x0010
 
+/*
 // File selector - backward compatibility
-char* WXDLLEXPORT wxFileSelector(const char *message = wxFileSelectorPromptStr, const char *default_path = NULL,
+WXDLLEXPORT wxString wxFileSelector(const char *message = wxFileSelectorPromptStr, const char *default_path = NULL,
                      const char *default_filename = NULL, const char *default_extension = NULL,
                      const char *wildcard = wxFileSelectorDefaultWildcardStr, int flags = 0,
                      wxWindow *parent = NULL, int x = -1, int y = -1);
 
 // An extended version of wxFileSelector
-char* WXDLLEXPORT wxFileSelectorEx(const char *message = wxFileSelectorPromptStr, const char *default_path = NULL,
+WXDLLEXPORT wxString wxFileSelectorEx(const char *message = wxFileSelectorPromptStr, const char *default_path = NULL,
                      const char *default_filename = NULL, int *indexDefaultExtension = NULL,
                      const char *wildcard = wxFileSelectorDefaultWildcardStr, int flags = 0,
                      wxWindow *parent = NULL, int x = -1, int y = -1);
 
 // Generic file load dialog
-char* WXDLLEXPORT wxLoadFileSelector(const char *what, const char *extension, const char *default_name = NULL, wxWindow *parent = NULL);
+WXDLLEXPORT wxString wxLoadFileSelector(const char *what, const char *extension, const char *default_name = NULL, wxWindow *parent = NULL);
 
 // Generic file save dialog
-char* WXDLLEXPORT wxSaveFileSelector(const char *what, const char *extension, const char *default_name = NULL, wxWindow *parent = NULL);
+WXDLLEXPORT wxString wxSaveFileSelector(const char *what, const char *extension, const char *default_name = NULL, wxWindow *parent = NULL);
+
+*/
 
 #endif
     // _WX_FILEDLG_H_
index 74e055c016fb5c55db1919f53a155fd0ad578ef4..3eb97f3e835bb2692502cd5d3decb0d75d9bdc05 100644 (file)
                                 // Level 1: wxDC, OnSize (etc.) compatibility, but
                                 //          some new features such as event tables
 
+#define wxUSE_AUTOTRANS   0
+                                // Define wxTString
 #define wxUSE_POSTSCRIPT  1
                                // 0 for no PostScript device context
 #define wxUSE_AFM_FOR_POSTSCRIPT 0
                                 // 1 to use font metric files in GetTextExtent
 #define wxUSE_METAFILE    1
                                 // 0 for no Metafile and metafile device context
+#define wxUSE_FORM        0
+                                // 0 for no wxForm
 #define wxUSE_IPC         1
                                 // 0 for no interprocess comms
 #define wxUSE_HELP        1
index 0d40d36837401a32992f8d7a61d0f38126fe2f4a..bf4d3db7786e6e5f5289ac81fe0c023956a66053 100644 (file)
@@ -22,7 +22,7 @@
 #define _WX_GOODCOMPILER__
                                 // gcc can have problems, but Windows compilers
                                 // are generally OK.
-#define WXWIN_COMPATIBILITY  0
+#define WXWIN_COMPATIBILITY  1  
                                 // Compatibility with 1.68 API.
                                 // Level 0: no backward compatibility, all new features
                                 // Level 1: Some compatibility. In fact
index 8dacc139670ca0458440f7f2c4ff1953ecc692f4..604aaa207794cfe6ef14a4bbe59de4e4c10cf8cf 100644 (file)
 #define MAX_PATH 512
 #endif
 
+#ifdef __WXMAC__
+char gwxMacFileName[ MAX_PATH ] ;
+char gwxMacFileName2[ MAX_PATH ] ;
+char gwxMacFileName3[ MAX_PATH ] ;
+#endif
+
 // ============================================================================
 // implementation of wxFile
 // ============================================================================
index dd99938e9a3b8ae194b182be5bddf12766db8c5a..4750baf77602f7082fff4ff36cbfbe0b5282b13c 100644 (file)
@@ -95,6 +95,8 @@ wxString wxFileConfig::GetGlobalDir()
     strDir = "/etc/";
   #elif defined(__WXSTUBS__)
     wxASSERT_MSG( FALSE, "TODO" ) ;
+  #elif defined(__WXMAC__)
+    wxASSERT_MSG( FALSE, "TODO" ) ;
   #else // Windows
     char szWinDir[MAX_PATH];
     ::GetWindowsDirectory(szWinDir, MAX_PATH);
index 30f08f8560b547238f370c0dd638397940192f77..2661bd44cca97e1069d0c609bd0a37eb2a870985 100644 (file)
@@ -270,6 +270,9 @@ wxColour *wxColourDatabase::FindColour(const wxString& colour)
 
 // TODO for other implementations. This should really go into
 // platform-specific directories.
+#ifdef __WXMAC__
+  else return NULL;
+#endif
 #ifdef __WXSTUBS__
   else return NULL;
 #endif
index b04a01bbe254908e39fe0a9b0d67217474674ac7..c1ea01dc9f16af33234f5f075dbfa4e1a184addf 100644 (file)
@@ -47,10 +47,41 @@ BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
 END_EVENT_TABLE()
 #endif
 
+// platform layer
+
+typedef void * PLEventHandle ;
+
+int PLTestMinimalRequirements() ;
+void PLErrorMessage( int errorCode ) ;
+int PLStartupPhase1() ;
+int PLStartupPhase2() ;
+void PLCleanup() ;
+
+bool PLDoOneEvent() ;
+bool PLHandleOneEvent( PLEventHandle event ) ; // true if really event
+bool PLCallbackIdle() ;
+bool PLCallbackRepeat() ;
+
 long wxApp::sm_lastMessageTime = 0;
 
 bool wxApp::Initialize()
 {
+  int error = 0 ;
+       
+  error = PLStartupPhase1() ;
+  if ( !error )
+  {
+    error = PLTestMinimalRequirements() ;
+    if ( !error )
+      error = PLStartupPhase2() ;
+  }
+       
+  if ( error )
+  {
+    PLErrorMessage( error ) ;
+    return FALSE ;
+  }  
+  
 #ifdef __WXMSW__
   wxBuffer = new char[1500];
 #else
@@ -141,6 +172,8 @@ void wxApp::CleanUp()
   wxLog::DontCreateOnDemand();
   // do it as the very last thing because everything else can log messages
   delete wxLog::SetActiveTarget(NULL);
+
+       PLCleanup() ;
 }
 
 int wxEntry( int argc, char *argv[] )
@@ -218,25 +251,21 @@ wxApp::wxApp()
 
 bool wxApp::Initialized()
 {
-  if (GetTopWindow())
     return TRUE;
-  else
-    return FALSE;
+//  if (GetTopWindow())
+//    return TRUE;
+//  else
+//    return FALSE;
 }
 
 int wxApp::MainLoop()
 {
   m_keepGoing = TRUE;
 
-/* TODO: implement your main loop here, calling ProcessIdle in idle time.
   while (m_keepGoing)
   {
-    while (!::PeekMessage(&s_currentMsg, 0, 0, 0, PM_NOREMOVE) &&
-           ProcessIdle()) {}
-    if (!DoMessage())
-      m_keepGoing = FALSE;
+               PLDoOneEvent() ;
   }
-*/
 
   return 0;
 }
@@ -389,3 +418,1127 @@ bool wxYield()
   return TRUE;
 }
 
+// -------------------------------------------------------------------
+// Portability Layer PL
+// -------------------------------------------------------------------
+// this is the c-api part, the only part of this file that needs to be
+// adapted for supporting a new platform
+// there are two flavours of PL... functions, Callbacks and normal functions
+// Callbacks are called by other PLxxx functions and allow to trigger idle 
+// processing etc. the callbacks don't have to be adapted for every platform
+// but only in case of changes to the underlying wx framework
+
+// callbacks
+
+bool PLCallbackIdle() 
+{
+       return wxTheApp->ProcessIdle() ;
+}
+
+bool PLCallbackRepeat() 
+{
+       // wxMacProcessSocketEvents() ;  
+       return false ;
+}
+
+// platform specific static variables
+
+bool                                   gMacHasAppearance = false ;
+long                                   gMacAppearanceVersion = 0 ;
+RgnHandle                      gMacCursorRgn = NULL ;
+
+#define        kMinHeap                                 (29 * 1024)
+#define        kMinSpace                               (20 * 1024)
+#define        eWrongMachine                   1
+#define        eSmallSize                              2
+#define        eNoMemory                               3
+#define        eOldSystem                              4
+#define        eGenericAbout                   5
+
+// platform specific prototypes
+
+void DoMacNullEvent( EventRecord *ev ) ;
+void DoMacHighLevelEvent( EventRecord *ev ) ;
+void DoMacMouseDownEvent( EventRecord *ev ) ;
+void DoMacMouseUpEvent( EventRecord *ev ) ;
+void DoMacKeyDownEvent( EventRecord *ev ) ;
+void DoMacKeyUpEvent( EventRecord *ev ) ;
+void DoMacAutoKeyEvent( EventRecord *ev ) ;
+void DoMacActivateEvent( EventRecord *ev ) ;
+void DoMacUpdateEvent( EventRecord *ev ) ;
+void DoMacDiskEvent( EventRecord *ev ) ;
+void DoMacOSEvent( EventRecord *ev ) ;
+
+// platform specific functions
+
+// -------------------------------------------------------------------
+// PLStartupPhase1
+// -------------------------------------------------------------------
+// Initializes the system so that at least the requirements can be tested
+// and that error messages will shop up at all ;-)
+// 
+// parameters   : none
+// return value : non zero for a implementation specific error code
+
+int PLStartupPhase1()
+{
+       ::InitGraf(&qd.thePort);
+       ::InitFonts();
+       ::InitWindows();
+       ::InitMenus();
+       ::TEInit();
+       ::InitDialogs(0L);
+       ::InitCursor();
+       CursHandle aCursHandle = ::GetCursor(watchCursor);      // Watch should be in system
+       if (aCursHandle)
+               ::SetCursor(*aCursHandle);                                              // Change cursor to watch 
+       ::FlushEvents(everyEvent, 0);
+       
+       gMacCursorRgn = ::NewRgn() ;
+
+       return 0 ;
+}
+
+// -------------------------------------------------------------------
+// PLStartupPhase2
+// -------------------------------------------------------------------
+// booting the system further until all subsystems are running
+// 
+// parameters   : none
+// return value : non zero for a implementation specific error code
+
+int PLStartupPhase2()
+{
+       long total,contig;
+
+       ::MaxApplZone();
+       for (long i = 1; i <= 4; i++)
+               ::MoreMasters();
+       PurgeSpace(&total, &contig);
+       ::SetCursor( &qd.arrow ) ; 
+
+#if 0
+       InitAEHandlers();
+       InitializeAECore() ;
+       GUSISetup(GUSIwithInternetSockets);
+#endif
+
+       return 0 ;
+}
+
+// -------------------------------------------------------------------
+// PLErrorMessage
+// -------------------------------------------------------------------
+// notifies the user of a implementation specific error
+// is useful for messages before the wx System is up and running
+// 
+// parameters   : int error = error code (implementation specific)
+// return value : none
+
+void PLErrorMessage( int error )
+{
+       short itemHit;
+       Str255 message;
+
+       SetCursor(&qd.arrow);
+       GetIndString(message, 128, error);
+       ParamText(message, (ConstStr255Param)"\p", (ConstStr255Param)"\p", (ConstStr255Param)"\p");
+       itemHit = Alert(129, nil);
+}
+
+// -------------------------------------------------------------------
+// PLCleanup
+// -------------------------------------------------------------------
+// notifies the user of a implementation specific error
+// is useful for messages before the wx System is up and running
+// 
+// parameters   : int error = error code (implementation specific)
+// return value : none
+
+void PLCleanup()
+{
+       ::PrClose() ;
+       if (gMacCursorRgn)
+               ::DisposeRgn(gMacCursorRgn);
+#if 0
+       TerminateAE() ;
+#endif
+}
+
+// -------------------------------------------------------------------
+// PLTestMinimalRequirements
+// -------------------------------------------------------------------
+// test whether we are on the correct runnable system and read out any
+// useful informations from the system
+// 
+// parameters  : none
+// return value : non zero for a implementation specific error code
+
+int PLTestMinimalRequirements()
+{
+       long theSystem ;
+       long theMachine;
+       long theAppearance ;
+
+       if (Gestalt(gestaltMachineType, &theMachine) != noErr)
+       {
+               return(eWrongMachine);
+       }
+
+       if (theMachine < gestaltMacPlus)
+       {
+               return(eWrongMachine);
+       }
+
+       if (Gestalt(gestaltSystemVersion, &theSystem) != noErr )
+       {
+               return( eOldSystem ) ;
+       }
+               
+       if ( theSystem < 0x0700 )
+       {
+               return( eOldSystem ) ;
+       }
+
+       if ((long)GetApplLimit() - (long)ApplicationZone() < kMinHeap)
+       {
+               return(eSmallSize);
+       }
+
+       if ( Gestalt( gestaltAppearanceAttr, &theAppearance ) == noErr )
+       {
+               gMacHasAppearance = true ;
+               RegisterAppearanceClient();
+               if ( Gestalt( gestaltAppearanceVersion, &theAppearance ) == noErr )
+               {
+                       gMacAppearanceVersion = theAppearance ;
+               }
+               else
+               {
+                       gMacAppearanceVersion = 0x0100 ;
+               }
+       }
+
+       return 0 ;
+}
+
+// -------------------------------------------------------------------
+// PLDoOneEvent
+// -------------------------------------------------------------------
+// 
+// parameters  : none
+// return value : returns true if a real event occured (no null or timeout event)
+
+bool PLDoOneEvent() 
+{
+  EventRecord event ;
+
+       long sleepTime = 60;
+
+       bool gotEvent = false ;
+  
+
+       if (WaitNextEvent(everyEvent, &event,sleepTime, gMacCursorRgn))
+       {
+    gotEvent = PLHandleOneEvent( &event );
+       }
+       else
+       {
+    PLCallbackIdle();
+       }
+               
+       PLCallbackRepeat() ;
+  
+  return gotEvent ;
+}
+
+// -------------------------------------------------------------------
+// PLHandleOneEvent
+// -------------------------------------------------------------------
+// 
+// parameters  : event = event handle of the platform specific event to be handled
+// return value : returns true if a real event occured (no null or timeout event)
+
+bool PLHandleOneEvent( PLEventHandle event ) 
+{
+       bool realEvent = true ;
+
+       EventRecord* ev = (EventRecord*) event ;
+
+       switch (ev->what)
+       {
+               case nullEvent:
+                       DoMacNullEvent( ev ) ;
+                       realEvent = false ;
+                       break ;
+               case kHighLevelEvent:
+                       DoMacHighLevelEvent( ev ) ;
+                       break;
+               case mouseDown:
+                       DoMacMouseDownEvent( ev ) ;
+                       wxTheApp->ExitMainLoop() ;
+                       break;
+               case mouseUp:
+                       DoMacMouseUpEvent( ev ) ;
+                       break;
+               case keyDown:
+                       DoMacKeyDownEvent( ev ) ;
+                       break;
+               case autoKey:
+                       DoMacAutoKeyEvent( ev ) ;
+                       break;
+               case keyUp:
+                       DoMacKeyUpEvent( ev ) ;
+                       break;
+               case activateEvt:
+                       DoMacActivateEvent( ev ) ;
+                       break;
+               case updateEvt:
+                       DoMacUpdateEvent( ev ) ;
+                       break;
+               case diskEvt:
+                       DoMacDiskEvent( ev ) ;
+                       break;
+               case osEvt:
+                       DoMacOSEvent( ev ) ;
+                       break;
+               default:
+                       break;
+       }
+  return realEvent ;
+}
+
+// platform specific functions (non PLxxx functions)
+
+void DoMacNullEvent( EventRecord *ev ) 
+{
+}
+
+void DoMacHighLevelEvent( EventRecord *ev )
+{
+}
+
+void DoMacMouseDownEvent( EventRecord *ev )
+{
+}
+
+void DoMacMouseUpEvent( EventRecord *ev )
+{
+}
+
+void DoMacKeyDownEvent( EventRecord *ev )
+{
+}
+
+void DoMacKeyUpEvent( EventRecord *ev )
+{
+}
+
+void DoMacAutoKeyEvent( EventRecord *ev )
+{
+}
+
+void DoMacActivateEvent( EventRecord *ev )
+{
+}
+
+void DoMacUpdateEvent( EventRecord *ev )
+{
+}
+
+void DoMacDiskEvent( EventRecord *ev )
+{
+}
+
+void DoMacOSEvent( EventRecord *ev )
+{
+}
+
+
+
+/*
+
+void wxApp::doMacMouseDown(void)
+{
+       WindowPtr window;
+       short windowPart = ::FindWindow(m_event.where, &window);
+       if ( windowPart != inMenuBar )
+       {
+               WindowPtr frontWindow = FrontWindow();
+               if (WindowIsModal(frontWindow) && (window != frontWindow))
+                       SysBeep(1);
+               else
+               {       
+                       switch (windowPart)
+                       {
+                               case inMenuBar:
+                                       break;
+                               case inContent:
+                                       doMacInContent(window); break;
+                               case inDrag:
+                                       doMacInDrag(window); break;
+                               case inGrow:
+                                       doMacInGrow(window); break;
+                               case inGoAway:
+                                       doMacInGoAway(window); break;
+                               case inZoomIn:
+                               case inZoomOut:
+                                       doMacInZoom(window, windowPart); break;
+                               default:
+                                       break;
+                       }
+       
+               }
+       }
+       else
+       {
+               doMacInMenuBar(::MenuSelect(m_event.where));
+       }
+}
+
+void wxApp::doMacMouseUp(void)
+{
+       if (m_mouseWindow)
+       {
+#if 0
+               int hitX = m_event.where.h;                             // screen window c.s.
+               int hitY = m_event.where.v;                             // screen window c.s.
+               m_mouseWindow->ScreenToClient(&hitX, &hitY);            // mouseWindow client c.s.
+               m_mouseWindow->ClientToLogical(&hitX, &hitY);   // mouseWindow logical c.s.
+#endif
+               
+               wxMouseEvent event(wxEVT_LEFT_UP);
+               event.m_shiftDown = m_event.modifiers & shiftKey;
+               event.m_controlDown = m_event.modifiers & controlKey;
+               event.m_altDown = m_event.modifiers & optionKey;
+               event.m_metaDown = m_event.modifiers & cmdKey;
+               event.m_leftDown = FALSE;
+               event.m_middleDown = FALSE;
+               event.m_rightDown = FALSE;
+               event.m_x = m_event.where.h;
+               event.m_y = m_event.where.v;
+               event.m_timeStamp = m_event.when;
+               event.SetEventObject(m_mouseWindow);
+
+               m_mouseWindow->ProcessEvent(event);
+       }
+       else
+       {
+               //??? Can't we just throw away mouse up events without matching mouse down
+               wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
+               if (theMacWxFrame)
+               {
+#if 0
+                       int hitX = cCurrentEvent.where.h; // screen window c.s.
+                       int hitY = cCurrentEvent.where.v; // screen window c.s.
+                       theMacWxFrame->ScreenToWindow(&hitX, &hitY);
+#endif
+
+                       wxMouseEvent event(wxEVT_LEFT_UP);
+                       event.m_shiftDown = m_event.modifiers & shiftKey;
+                       event.m_controlDown = m_event.modifiers & controlKey;
+                       event.m_altDown = m_event.modifiers & optionKey;
+                       event.m_metaDown = m_event.modifiers & cmdKey;
+                       event.m_leftDown = FALSE;
+                       event.m_middleDown = FALSE;
+                       event.m_rightDown = FALSE;
+                       event.m_x = m_event.where.h;
+                       event.m_y = m_event.where.v;
+                       event.m_timeStamp = m_event.when;
+                       event.SetEventObject(m_mouseWindow);
+
+                       theMacWxFrame->ProcessEvent(event);
+               }
+       }
+}
+
+void wxApp::doMacMouseMotion(void)
+{
+       if (m_mouseWindow) {
+               wxMouseEvent event(wxEVT_MOTION);
+               event.m_shiftDown = m_event.modifiers & shiftKey;
+               event.m_controlDown = m_event.modifiers & controlKey;
+               event.m_altDown = m_event.modifiers & optionKey;
+               event.m_metaDown = m_event.modifiers & cmdKey;
+               event.m_leftDown = !(m_event.modifiers & btnState);
+               event.m_middleDown = FALSE;
+               event.m_rightDown = FALSE;
+               event.m_x = m_event.where.h;
+               event.m_y = m_event.where.v;
+               event.m_timeStamp = m_event.when;
+               event.SetEventObject(m_mouseWindow);
+
+               m_mouseWindow->ProcessEvent(event);
+       }
+       else
+       {
+               wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
+               if (theMacWxFrame)
+               {
+                       wxMouseEvent event(wxEVT_MOTION);
+                       event.m_shiftDown = m_event.modifiers & shiftKey;
+                       event.m_controlDown = m_event.modifiers & controlKey;
+                       event.m_altDown = m_event.modifiers & optionKey;
+                       event.m_metaDown = m_event.modifiers & cmdKey;
+                       event.m_leftDown = !(m_event.modifiers & btnState);
+                       event.m_middleDown = FALSE;
+                       event.m_rightDown = FALSE;
+                       event.m_x = m_event.where.h;
+                       event.m_y = m_event.where.v;
+                       event.m_timeStamp = m_event.when;
+                       event.SetEventObject(m_mouseWindow);
+
+                       m_mouseWindow->ProcessEvent(event);
+               }
+       }
+       
+       //??? Need to work with floating windows... isn't there a toolbox call to find the
+       // top window intersecting a point is screen coordinates??
+#if 0
+       else    // will only work for one floating window at the moment... ?
+       {       
+               WindowPtr frontDocPtr = findFrontNonFloatingWindow();
+               WindowPtr frontFloatingPtr = ::FrontWindow();
+               
+               int hitX = cCurrentEvent.where.h;
+               int hitY = cCurrentEvent.where.v;
+               
+               wxFrame* macWxFrame = findMacWxFrame(frontDocPtr);
+               
+               if ((frontFloatingPtr != frontDocPtr) & (frontFloatingPtr != NULL))
+               {
+                       RgnHandle frontFloatStrRgn = getStructureRegion(frontFloatingPtr);
+                       Rect      frontFloatRect = (**frontFloatStrRgn).rgnBBox;
+       
+                       if         ((hitX >= frontFloatRect.left) & 
+                                       (hitX <= frontFloatRect.right) & 
+                                       (hitY >= frontFloatRect.top) &
+                                       (hitY <= frontFloatRect.bottom))
+                       {
+                               macWxFrame = findMacWxFrame(frontFloatingPtr);
+                       }
+               }
+       }
+#endif
+}
+
+void wxApp::doMacKeyDown(void)
+{
+       long menuResult = 0 ;
+       short keycode ;
+       short keychar ;
+       keychar = short(m_event.message & charCodeMask);
+       keycode = short(m_event.message & keyCodeMask) >> 8 ;
+
+       // Handle menu accelerators
+       if ( gSFMacHasAppearance )
+       {
+               menuResult = MenuEvent( &m_event ) ;
+               if ( HiWord( menuResult ) )
+               {
+                       doMacInMenuBar( menuResult ) ;
+               }
+               else
+               {
+                       ControlHandle control ;
+                       
+                       GetKeyboardFocus( FrontNonFloatingWindow() , &control ) ;
+                       if ( control && keychar != 0x07 )
+                               HandleControlKey( control , keycode , keychar , m_event.modifiers ) ;
+                       else
+                       {
+                               wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
+                               if (theMacWxFrame)
+                               {
+                                       wxKeyEvent event(wxEVT_CHAR);
+                                       event.m_shiftDown = m_event.modifiers & shiftKey;
+                                       event.m_controlDown = m_event.modifiers & controlKey;
+                                       event.m_altDown = m_event.modifiers & optionKey;
+                                       event.m_metaDown = m_event.modifiers & cmdKey;
+                                       event.m_keyCode = macTranslateKey(keychar, m_event.modifiers & (shiftKey|optionKey));
+                                       event.m_x = m_event.where.h;
+                                       event.m_y = m_event.where.v;
+                                       event.m_timeStamp = m_event.when;
+                                       event.SetEventObject(theMacWxFrame);
+                       
+                                       theMacWxFrame->ProcessEvent(event);
+                               }
+                       }
+               }
+       }
+       else
+       {
+               if (GetMenuHandle( kwxMacAppleMenuId ) )
+               {
+//                     menuResult = MDEF_MenuKey(m_event.message, m_event.modifiers , GetMenuHandle( kwxMacAppleMenuId ) );
+               }
+               else
+               {
+                       if (m_event.modifiers & cmdKey)
+                       {
+                               menuResult = MenuKey( keychar ) ;
+                       }
+               }
+
+               if ( HiWord( menuResult ) )
+               {
+                       doMacInMenuBar( menuResult ) ;
+               }
+               else
+               {
+                       wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
+                       if (theMacWxFrame)
+                       {
+                               wxKeyEvent event(wxEVT_CHAR);
+                               event.m_shiftDown = m_event.modifiers & shiftKey;
+                               event.m_controlDown = m_event.modifiers & controlKey;
+                               event.m_altDown = m_event.modifiers & optionKey;
+                               event.m_metaDown = m_event.modifiers & cmdKey;
+                               event.m_keyCode = macTranslateKey(keychar, m_event.modifiers & (shiftKey|optionKey));
+                               event.m_x = m_event.where.h;
+                               event.m_y = m_event.where.v;
+                               event.m_timeStamp = m_event.when;
+                               event.SetEventObject(theMacWxFrame);
+               
+                               theMacWxFrame->ProcessEvent(event);
+                       }
+               }
+       }
+}
+
+void wxApp::doMacAutoKey(void)
+{
+       doMacKeyDown();
+}
+
+void wxApp::doMacKeyUp(void)
+{
+}
+
+void wxApp::doMacActivateEvt(void)
+{
+       HighlightAndActivateWindow( (WindowPtr) m_event.message , m_event.modifiers & activeFlag ) ;
+}
+
+void wxApp::doMacUpdateEvt(void)
+{
+       WindowPtr theMacWindow = (WindowPtr)(m_event.message);
+       ::BeginUpdate(theMacWindow);
+       
+       wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(theMacWindow);
+       if (theMacWxFrame)
+       {
+//             if (!::EmptyRgn(theMacWindow->visRgn))  // this doesn't work with windowshade
+//             {
+                       if ( theMacWxFrame->MacSetupPort() )
+                       {
+                               // Erase update region
+                               // we must do this, because controls add their former rect to the inval
+                               // rgn and the background might not have been correct at that moment
+                               ::EraseRect(&theMacWindow->portRect); 
+       
+                               // Can't use UpdateControls since each control has it's own coordinate system
+                               //              ::UpdateControls(theMacWindow, theMacWindow->visRgn);
+       
+                               ::UpdateControls( theMacWindow , theMacWindow->visRgn ) ;
+       #if 0
+                               // Draw the grow box
+                               if (cStyle & wxRESIZE_BORDER)
+                                       MacDrawGrowIcon();
+       #endif
+       
+                               wxPaintEvent event;
+                               event.m_timeStamp = m_event.when;
+                               event.SetEventObject(theMacWxFrame);
+       
+                               theMacWxFrame->ProcessEvent(event);
+       //                      ::SetThemeWindowBackground(  theMacWindow , kThemeActiveDialogBackgroundBrush ,  false ) ;
+                               ::ClipRect( &theMacWindow->portRect ) ;         
+                               ::SetOrigin(  0 , 0 );  
+                       }
+                       else
+                       {
+                               wxASSERT_MSG( false , "unabled to setup window mac port") ;
+                       }
+                       
+//             }
+       }
+
+       ::EndUpdate(theMacWindow);
+}
+
+void wxApp::doMacDiskEvt(void)
+{ // based on "Programming for System 7" by Gary Little and Tim Swihart
+       if ((m_event.message >> 16) != noErr)
+       {
+               const int kDILeft = 0x0050; // top coord for disk init dialog
+               const int kDITop = 0x0070; // left coord for disk init dialog
+               Point mountPoint;
+               mountPoint.h = kDILeft;
+               mountPoint.v = kDITop;
+               int myError = DIBadMount(mountPoint, m_event.message);
+       }
+}
+
+void wxApp::doMacOsEvt(void)
+{ // based on "Programming for System 7" by Gary Little and Tim Swihart
+       switch ((m_event.message >> 24) & 0x0ff)
+       {
+               case suspendResumeMessage:
+                       if (m_event.message & resumeFlag)
+                               doMacResumeEvent();
+                       else
+                               doMacSuspendEvent();
+                       break;
+               case mouseMovedMessage:
+                       doMacMouseMovedMessage();
+                       break;
+       }
+}
+
+void wxApp::doMacHighLevelEvent(void)
+{
+       ::AEProcessAppleEvent(&m_event); // System 7 or higher
+}
+
+void wxApp::doMacResumeEvent(void)
+{
+       wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
+       if (theMacWxFrame)
+       {
+               if (m_event.message & convertClipboardFlag)
+                       ::TEFromScrap();
+
+               wxActivateEvent event(wxEVT_ACTIVATE, TRUE);
+               event.m_timeStamp = m_event.when;
+               event.SetEventObject(theMacWxFrame);
+
+               theMacWxFrame->ProcessEvent(event);
+       }
+}
+
+void wxApp::doMacSuspendEvent(void)
+{
+       wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
+       if (theMacWxFrame)
+       {
+               ::ZeroScrap();
+               ::TEToScrap();
+
+               wxActivateEvent event(wxEVT_ACTIVATE, FALSE);
+               event.m_timeStamp = m_event.when;
+               event.SetEventObject(theMacWxFrame);
+
+               theMacWxFrame->ProcessEvent(event);
+       }
+}
+
+void wxApp::doMacMouseMovedMessage(void)
+{ // based on "Programming for System 7" by Gary Little and Tim Swihart
+       if (m_cursorRgn)
+               ::DisposeRgn(m_cursorRgn);
+       m_cursorRgn = ::NewRgn();
+       ::SetRectRgn(m_cursorRgn, -32768, -32768, 32766, 32766);
+}
+
+void wxApp::doMacInMenuBar(long menuResult)
+{
+       int macMenuId = HiWord(menuResult);
+       int macMenuItemNum = LoWord(menuResult); // counting from 1
+
+       if (macMenuId == 0)                                     // no menu item selected;
+                return;
+       if (macMenuId == 128) 
+       {
+               if (macMenuItemNum != 1) 
+               {                       // if not the "About" entry (or the separator)
+                       Str255          daName;
+                       ::GetMenuItemText(GetMenuHandle(128), macMenuItemNum, daName);
+                       (void)::OpenDeskAcc(daName);
+                       ::HiliteMenu(0);                                                                
+                       return;
+               }
+       }
+
+       wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
+       if (theMacWxFrame)
+       {
+               if ( theMacWxFrame->IsKindOf( CLASSINFO( wxDialog ) ) )
+                       (( wxDialog *) theMacWxFrame)->MacMenuSelect(m_event, macMenuId, macMenuItemNum);
+               else if ( theMacWxFrame->IsKindOf( CLASSINFO( wxFrame ) ) )
+                       (( wxFrame *) theMacWxFrame)->MacMenuSelect(m_event, macMenuId, macMenuItemNum);
+       }
+       ::HiliteMenu(0);                                                                
+}
+
+void wxApp::doMacInContent(WindowPtr window)
+{
+       WindowPtr frontWindow = FrontWindow();
+       if (window != frontWindow )
+       {
+//             SFSelectWindow( window ) ;
+       }
+       else
+       {
+               ControlHandle   control ;
+               Point           localwhere = m_event.where ;
+               GrafPtr         port ;
+               SInt16          controlpart ;
+               
+               ::GetPort( &port ) ;
+               ::SetPort( window ) ;
+               ::GlobalToLocal( &localwhere ) ;
+
+               ::SetPort( port ) ;
+               
+               if ( !gSFMacHasAppearance )
+               {
+                       controlpart = FindControl( localwhere , window , &control ) ;
+               }
+               else
+               {
+                       control = FindControlUnderMouse( localwhere , window , &controlpart ) ;
+               }
+               
+               if ( control && IsControlActive( control ) )
+               {
+                       wxControl* wxc = (wxControl*) GetControlReference( control ) ;
+                                       
+                       if ( wxWindow::FindFocus() != wxc &&  wxc->AcceptsFocus() )
+                       {
+                               wxc->SetFocus() ;       
+                               if ( wxWindow::FindFocus() != wxc )
+                                       control = NULL ; // we were not able to change focus
+                       }               
+                                                               
+                       if ( control )
+                       {
+                               if ( !gSFMacHasAppearance)
+                               {
+                                       controlpart = TrackControl( control , localwhere , NULL ) ;
+                               }
+                               else
+                               {
+                                       controlpart = HandleControlClick( control , localwhere , m_event.modifiers , (ControlActionUPP) -1 ) ;
+                               }
+                               
+                               if ( controlpart )
+                               {
+                                       wxControl*      wx = (wxControl*) GetControlReference( control ) ;
+                                       if ( wx )
+                                               wx->MacHandleControlClick( control , controlpart ) ;
+                               }
+                       }
+               }
+               else
+               {
+                       wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(window);
+                       if (theMacWxFrame)
+                       {
+                               doMacContentClick((wxFrame*)theMacWxFrame); // todo : this cast is wrong
+                       }
+               }
+       }
+       
+#if 0
+       wxFrame* theMacWxFrame = findMacWxFrame(window);
+       if (theMacWxFrame)
+       {
+               WindowPtr MacWindow = findFrontNonFloatingWindow();
+               if (window != MacWindow)
+               {               
+                       wxFrame* frontFrame = findMacWxFrame(MacWindow);
+                       if (!frontFrame) wxFatalError("No wxFrame for frontnonfloatingWindow.");
+                       if (!frontFrame->IsModal())
+                       {
+                               frontFrame->SetFocus();
+                               doMacContentClick(theMacWxFrame);       // jonto - to deal with doc windows behind floaters ?
+                               ::newSelectWindow(window);                      // WCH : should I be calling some wxMethod?
+                               if (!IsFloating(MacWindow))
+                               {
+                                       KeyMap keyMap;
+                                       GetKeys(keyMap);
+                                       if (!(keyMap[1] & 0x8000)) theMacWxFrame->ShowAsActive(true);   // temporary measure...
+                               }
+                       }                                                                               // jonto : not sure yet, but let's try this ...
+                       else ::SysBeep(3);
+               }
+               else
+               {
+                       doMacContentClick(theMacWxFrame);
+               }
+       }
+#endif
+}
+
+void wxApp::doMacContentClick(wxWindow* frame)
+{
+       m_mouseWindow = frame;
+
+       wxMouseEvent event(wxEVT_LEFT_DOWN);
+       event.m_shiftDown = m_event.modifiers & shiftKey;
+       event.m_controlDown = m_event.modifiers & controlKey;
+       event.m_altDown = m_event.modifiers & optionKey;
+       event.m_metaDown = m_event.modifiers & cmdKey;
+       event.m_leftDown = FALSE;
+       event.m_middleDown = FALSE;
+       event.m_rightDown = FALSE;
+       if ( m_event.modifiers & controlKey )
+       {
+               event.m_rightDown = TRUE;
+       }
+       else
+       {
+               event.m_leftDown = TRUE;
+       }
+#if 0
+  event.m_leftDown = !(m_event.modifiers & btnState);
+       event.m_middleDown = FALSE;
+       event.m_rightDown = FALSE;
+#endif
+       event.m_x = m_event.where.h;
+       event.m_y = m_event.where.v;
+       event.m_timeStamp = m_event.when;
+       event.SetEventObject(m_mouseWindow);
+
+//     m_mouseWindow->ProcessEvent(event);
+       m_mouseWindow->MacDispatchMouseEvent(event);
+       
+#if 0
+       // RightButton is cmdKey click  on the mac platform for one-button mouse
+       Bool rightButton = cCurrentEvent.modifiers & cmdKey;
+       // altKey is optionKey on the mac platform:
+       Bool isAltKey = cCurrentEvent.modifiers & optionKey;
+
+       WXTYPE mouseEventType = rightButton ? wxEVENT_TYPE_RIGHT_DOWN
+                                                                               : wxEVENT_TYPE_LEFT_DOWN;
+       wxMouseEvent theMouseEvent(mouseEventType);
+       theMouseEvent.leftDown = !rightButton;
+       theMouseEvent.middleDown = FALSE;
+       theMouseEvent.rightDown = rightButton;
+       theMouseEvent.shiftDown = cCurrentEvent.modifiers & shiftKey;
+       theMouseEvent.controlDown = cCurrentEvent.modifiers & controlKey;
+       theMouseEvent.altDown = isAltKey;
+       theMouseEvent.metaDown = FALSE;  // mflatt
+       theMouseEvent.timeStamp = cCurrentEvent.when; // mflatt
+
+       int hitX = cCurrentEvent.where.h; // screen window c.s.
+       int hitY = cCurrentEvent.where.v; // screen window c.s.
+
+       frame->ScreenToWindow(&hitX, &hitY);
+//     frameParentArea->ScreenToArea(&hitX, &hitY);                    // tx coords ?
+       theMouseEvent.x = hitX; // frame parent area c.s.
+       theMouseEvent.y = hitY; // frame parent area c.s.
+
+       frame->SeekMouseEventArea(theMouseEvent);
+#endif
+}
+
+void wxApp::doMacInDrag(WindowPtr window)
+{
+       wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(window);
+       if (theMacWxFrame)
+       {
+               // should be desktop, not screen
+               Rect dragBoundsRect = qd.screenBits.bounds;     // can't move to a different screen
+//xxx  ::InsetRect(&dragBoundsRect, 4, ::GetMBarHeight() + 4); // This is not really necessary
+               Rect oldPos = (**(((WindowPeek)window)->strucRgn)).rgnBBox;
+               ::DragReferencedWindow(window, m_event.where, &dragBoundsRect); // jonto
+               #if 0
+               theMacWxFrame->m_x += (**(((WindowPeek)window)->strucRgn)).rgnBBox.left - oldPos.left;
+               theMacWxFrame->m_y += (**(((WindowPeek)window)->strucRgn)).rgnBBox.top - oldPos.top;
+               #endif
+               Move( (**(((WindowPeek)window)->strucRgn)).rgnBBox.left , (**(((WindowPeek)window)->strucRgn)).rgnBBox.top ) ;
+#if 0
+               theMacWxFrame->wxMacRecalcNewSize(); // Actually, recalc new position only
+#endif
+       }
+       
+#if 0
+//     if (window != ::FrontWindow())
+       if (window != findFrontNonFloatingWindow())
+       {
+//             wxFrame* frontFrame = findMacWxFrame(::FrontWindow());
+               wxFrame* frontFrame = findMacWxFrame(findFrontNonFloatingWindow());
+               if (!frontFrame) wxFatalError("No wxFrame for frontWindow.");
+               if (frontFrame->IsModal())
+               {
+                       ::SysBeep(3);
+                       return;
+               }
+       }
+
+       wxFrame* theMacWxFrame = findMacWxFrame(window);
+       if (theMacWxFrame)
+       {
+               Rect dragBoundsRect = qd.screenBits.bounds;     // can't move to a different screen
+               ::InsetRect(&dragBoundsRect, 4, ::GetMBarHeight() + 4); // This is not really necessary
+               newDragWindow(window, cCurrentEvent.where, &dragBoundsRect);    // jonto
+               theMacWxFrame->wxMacRecalcNewSize(); // Actually, recalc new position only
+               if (!IsFloating(window))
+               {
+                       theMacWxFrame->ShowAsActive(true);      // temporary measure...
+               }
+       }
+#endif
+}
+
+void wxApp::doMacInGrow(WindowPtr window)
+{
+       wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(window);
+       if (theMacWxFrame)
+       {
+               Rect growSizeRect; // WCH: growSizeRect should be a member of wxFrame class
+               growSizeRect.top = 1; // minimum window height
+               growSizeRect.left = 1; // minimum window width
+               growSizeRect.bottom = qd.screenBits.bounds.bottom - qd.screenBits.bounds.top;
+               growSizeRect.right = qd.screenBits.bounds.right - qd.screenBits.bounds.left;
+               long windSize = ::GrowWindow(window, m_event.where, &growSizeRect);
+               if (windSize != 0)
+               {
+                       int nWidth = LoWord(windSize);
+                       int nHeight = HiWord(windSize);
+                       int oWidth, oHeight;
+                       theMacWxFrame->GetSize(&oWidth, &oHeight);
+                       if (nWidth == 0) nWidth = oWidth;
+                       if (nHeight == 0) nHeight = oHeight;
+                       theMacWxFrame->SetSize( -1, -1, nWidth, nHeight, wxSIZE_USE_EXISTING);
+               }
+       }
+}
+
+void wxApp::doMacInGoAway(WindowPtr window)
+{
+       wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(window);
+       if (theMacWxFrame)
+       {
+               if (TrackGoAway(window, m_event.where))
+               {
+                       if (theMacWxFrame->OnClose()) {
+#if WXGARBAGE_COLLECTION_ON
+                               theMacWxFrame->Show(FALSE);
+#else
+                               delete theMacWxFrame;
+#endif
+                       }
+               }
+       }
+}
+
+void wxApp::doMacInZoom(WindowPtr window, short windowPart)
+{
+       wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(window);
+       if (theMacWxFrame)
+       {
+               if (TrackBox(window, m_event.where, windowPart))
+               {
+#if 0
+                       theMacWxFrame->Maximize(windowPart == inZoomOut);
+#endif
+               }
+       }
+}
+
+long wxApp::macTranslateKey(char key, int mods)
+{
+    static Handle transH = NULL;
+    static unsigned long transState = 0;
+    static Handle ScriptH = NULL;
+    static short region_code = 1;
+
+       if (!ScriptH) { // tom: don't guess the regioncode!!!!
+      struct ItlbRecord * r;
+      ScriptH = GetResource('itlb',0);
+      if (ScriptH) {
+       HLock(ScriptH);
+       r = (ItlbRecord*)*ScriptH;
+       region_code = r->itlbKeys;      
+       HUnlock(ScriptH);
+      }        
+    }
+    switch (key) {
+    case 0x7e:
+    case 0x3e:
+      key = WXK_UP;
+      break;
+    case 0x7d:
+    case 0x3d:
+      key = WXK_DOWN;
+      break;
+    case 0x7b:
+    case 0x3b:
+      key = WXK_LEFT;
+      break;
+    case 0x7c:
+    case 0x3c:
+      key = WXK_RIGHT;
+      break;
+    case 0x24:
+    case 0x4c:
+      key = WXK_RETURN;
+      break;
+    case 0x30:
+      key = WXK_TAB;
+      break;
+    case 0x33:
+      key = WXK_BACK;
+      break;
+    case 0x75:
+      key = WXK_DELETE;
+      break;
+    case 0x73:
+         key = WXK_HOME;
+         break;
+       case 0x77:
+         key = WXK_END;
+         break;   
+       case 0x74:
+         key = WXK_PAGEUP;
+         break;     
+       case 0x79:
+         key = WXK_PAGEDOWN;
+         break;     
+    default:
+      if (!transH) {
+               transH = GetIndResource('KCHR', 1);
+               HNoPurge(transH);
+      }
+#if 0 //Tom replaces
+      if (transH) {
+               // Only let shift & option modify the key: 
+               HLock(transH);
+               key = KeyTranslate(*transH, (key & 0x7F) | mods, &transState) & charCodeMask;
+               HUnlock(transH);
+#else
+       if (0) { // tom fettig@dfki.uni-sb.de
+               // why if(0):
+               // code is not correct, see inside Macintosh: Text 1-87
+               // and 'itlk'-resource!!
+               // and it is not necessary, as the translated char is in
+               // cCurrrentEvent.message!!
+               // Only let shift & option modify the key: 
+               HLock(transH);
+               key = KeyTranslate(*transH, (key & 0x7F) | mods, &transState) & charCodeMask;
+               HUnlock(transH);
+#endif
+         }
+       } // end switch
+       
+       return key;
+}
+
+void
+wxApp::macAdjustCursor()
+{
+  if (m_event.what != kHighLevelEvent)
+  {
+       wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
+       if (theMacWxFrame)
+       {
+         if (!theMacWxFrame->MacAdjustCursor(m_event.where))
+               ::SetCursor(&(qd.arrow));
+       }
+  }
+}
+*/
\ No newline at end of file
index b04a01bbe254908e39fe0a9b0d67217474674ac7..c1ea01dc9f16af33234f5f075dbfa4e1a184addf 100644 (file)
@@ -47,10 +47,41 @@ BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
 END_EVENT_TABLE()
 #endif
 
+// platform layer
+
+typedef void * PLEventHandle ;
+
+int PLTestMinimalRequirements() ;
+void PLErrorMessage( int errorCode ) ;
+int PLStartupPhase1() ;
+int PLStartupPhase2() ;
+void PLCleanup() ;
+
+bool PLDoOneEvent() ;
+bool PLHandleOneEvent( PLEventHandle event ) ; // true if really event
+bool PLCallbackIdle() ;
+bool PLCallbackRepeat() ;
+
 long wxApp::sm_lastMessageTime = 0;
 
 bool wxApp::Initialize()
 {
+  int error = 0 ;
+       
+  error = PLStartupPhase1() ;
+  if ( !error )
+  {
+    error = PLTestMinimalRequirements() ;
+    if ( !error )
+      error = PLStartupPhase2() ;
+  }
+       
+  if ( error )
+  {
+    PLErrorMessage( error ) ;
+    return FALSE ;
+  }  
+  
 #ifdef __WXMSW__
   wxBuffer = new char[1500];
 #else
@@ -141,6 +172,8 @@ void wxApp::CleanUp()
   wxLog::DontCreateOnDemand();
   // do it as the very last thing because everything else can log messages
   delete wxLog::SetActiveTarget(NULL);
+
+       PLCleanup() ;
 }
 
 int wxEntry( int argc, char *argv[] )
@@ -218,25 +251,21 @@ wxApp::wxApp()
 
 bool wxApp::Initialized()
 {
-  if (GetTopWindow())
     return TRUE;
-  else
-    return FALSE;
+//  if (GetTopWindow())
+//    return TRUE;
+//  else
+//    return FALSE;
 }
 
 int wxApp::MainLoop()
 {
   m_keepGoing = TRUE;
 
-/* TODO: implement your main loop here, calling ProcessIdle in idle time.
   while (m_keepGoing)
   {
-    while (!::PeekMessage(&s_currentMsg, 0, 0, 0, PM_NOREMOVE) &&
-           ProcessIdle()) {}
-    if (!DoMessage())
-      m_keepGoing = FALSE;
+               PLDoOneEvent() ;
   }
-*/
 
   return 0;
 }
@@ -389,3 +418,1127 @@ bool wxYield()
   return TRUE;
 }
 
+// -------------------------------------------------------------------
+// Portability Layer PL
+// -------------------------------------------------------------------
+// this is the c-api part, the only part of this file that needs to be
+// adapted for supporting a new platform
+// there are two flavours of PL... functions, Callbacks and normal functions
+// Callbacks are called by other PLxxx functions and allow to trigger idle 
+// processing etc. the callbacks don't have to be adapted for every platform
+// but only in case of changes to the underlying wx framework
+
+// callbacks
+
+bool PLCallbackIdle() 
+{
+       return wxTheApp->ProcessIdle() ;
+}
+
+bool PLCallbackRepeat() 
+{
+       // wxMacProcessSocketEvents() ;  
+       return false ;
+}
+
+// platform specific static variables
+
+bool                                   gMacHasAppearance = false ;
+long                                   gMacAppearanceVersion = 0 ;
+RgnHandle                      gMacCursorRgn = NULL ;
+
+#define        kMinHeap                                 (29 * 1024)
+#define        kMinSpace                               (20 * 1024)
+#define        eWrongMachine                   1
+#define        eSmallSize                              2
+#define        eNoMemory                               3
+#define        eOldSystem                              4
+#define        eGenericAbout                   5
+
+// platform specific prototypes
+
+void DoMacNullEvent( EventRecord *ev ) ;
+void DoMacHighLevelEvent( EventRecord *ev ) ;
+void DoMacMouseDownEvent( EventRecord *ev ) ;
+void DoMacMouseUpEvent( EventRecord *ev ) ;
+void DoMacKeyDownEvent( EventRecord *ev ) ;
+void DoMacKeyUpEvent( EventRecord *ev ) ;
+void DoMacAutoKeyEvent( EventRecord *ev ) ;
+void DoMacActivateEvent( EventRecord *ev ) ;
+void DoMacUpdateEvent( EventRecord *ev ) ;
+void DoMacDiskEvent( EventRecord *ev ) ;
+void DoMacOSEvent( EventRecord *ev ) ;
+
+// platform specific functions
+
+// -------------------------------------------------------------------
+// PLStartupPhase1
+// -------------------------------------------------------------------
+// Initializes the system so that at least the requirements can be tested
+// and that error messages will shop up at all ;-)
+// 
+// parameters   : none
+// return value : non zero for a implementation specific error code
+
+int PLStartupPhase1()
+{
+       ::InitGraf(&qd.thePort);
+       ::InitFonts();
+       ::InitWindows();
+       ::InitMenus();
+       ::TEInit();
+       ::InitDialogs(0L);
+       ::InitCursor();
+       CursHandle aCursHandle = ::GetCursor(watchCursor);      // Watch should be in system
+       if (aCursHandle)
+               ::SetCursor(*aCursHandle);                                              // Change cursor to watch 
+       ::FlushEvents(everyEvent, 0);
+       
+       gMacCursorRgn = ::NewRgn() ;
+
+       return 0 ;
+}
+
+// -------------------------------------------------------------------
+// PLStartupPhase2
+// -------------------------------------------------------------------
+// booting the system further until all subsystems are running
+// 
+// parameters   : none
+// return value : non zero for a implementation specific error code
+
+int PLStartupPhase2()
+{
+       long total,contig;
+
+       ::MaxApplZone();
+       for (long i = 1; i <= 4; i++)
+               ::MoreMasters();
+       PurgeSpace(&total, &contig);
+       ::SetCursor( &qd.arrow ) ; 
+
+#if 0
+       InitAEHandlers();
+       InitializeAECore() ;
+       GUSISetup(GUSIwithInternetSockets);
+#endif
+
+       return 0 ;
+}
+
+// -------------------------------------------------------------------
+// PLErrorMessage
+// -------------------------------------------------------------------
+// notifies the user of a implementation specific error
+// is useful for messages before the wx System is up and running
+// 
+// parameters   : int error = error code (implementation specific)
+// return value : none
+
+void PLErrorMessage( int error )
+{
+       short itemHit;
+       Str255 message;
+
+       SetCursor(&qd.arrow);
+       GetIndString(message, 128, error);
+       ParamText(message, (ConstStr255Param)"\p", (ConstStr255Param)"\p", (ConstStr255Param)"\p");
+       itemHit = Alert(129, nil);
+}
+
+// -------------------------------------------------------------------
+// PLCleanup
+// -------------------------------------------------------------------
+// notifies the user of a implementation specific error
+// is useful for messages before the wx System is up and running
+// 
+// parameters   : int error = error code (implementation specific)
+// return value : none
+
+void PLCleanup()
+{
+       ::PrClose() ;
+       if (gMacCursorRgn)
+               ::DisposeRgn(gMacCursorRgn);
+#if 0
+       TerminateAE() ;
+#endif
+}
+
+// -------------------------------------------------------------------
+// PLTestMinimalRequirements
+// -------------------------------------------------------------------
+// test whether we are on the correct runnable system and read out any
+// useful informations from the system
+// 
+// parameters  : none
+// return value : non zero for a implementation specific error code
+
+int PLTestMinimalRequirements()
+{
+       long theSystem ;
+       long theMachine;
+       long theAppearance ;
+
+       if (Gestalt(gestaltMachineType, &theMachine) != noErr)
+       {
+               return(eWrongMachine);
+       }
+
+       if (theMachine < gestaltMacPlus)
+       {
+               return(eWrongMachine);
+       }
+
+       if (Gestalt(gestaltSystemVersion, &theSystem) != noErr )
+       {
+               return( eOldSystem ) ;
+       }
+               
+       if ( theSystem < 0x0700 )
+       {
+               return( eOldSystem ) ;
+       }
+
+       if ((long)GetApplLimit() - (long)ApplicationZone() < kMinHeap)
+       {
+               return(eSmallSize);
+       }
+
+       if ( Gestalt( gestaltAppearanceAttr, &theAppearance ) == noErr )
+       {
+               gMacHasAppearance = true ;
+               RegisterAppearanceClient();
+               if ( Gestalt( gestaltAppearanceVersion, &theAppearance ) == noErr )
+               {
+                       gMacAppearanceVersion = theAppearance ;
+               }
+               else
+               {
+                       gMacAppearanceVersion = 0x0100 ;
+               }
+       }
+
+       return 0 ;
+}
+
+// -------------------------------------------------------------------
+// PLDoOneEvent
+// -------------------------------------------------------------------
+// 
+// parameters  : none
+// return value : returns true if a real event occured (no null or timeout event)
+
+bool PLDoOneEvent() 
+{
+  EventRecord event ;
+
+       long sleepTime = 60;
+
+       bool gotEvent = false ;
+  
+
+       if (WaitNextEvent(everyEvent, &event,sleepTime, gMacCursorRgn))
+       {
+    gotEvent = PLHandleOneEvent( &event );
+       }
+       else
+       {
+    PLCallbackIdle();
+       }
+               
+       PLCallbackRepeat() ;
+  
+  return gotEvent ;
+}
+
+// -------------------------------------------------------------------
+// PLHandleOneEvent
+// -------------------------------------------------------------------
+// 
+// parameters  : event = event handle of the platform specific event to be handled
+// return value : returns true if a real event occured (no null or timeout event)
+
+bool PLHandleOneEvent( PLEventHandle event ) 
+{
+       bool realEvent = true ;
+
+       EventRecord* ev = (EventRecord*) event ;
+
+       switch (ev->what)
+       {
+               case nullEvent:
+                       DoMacNullEvent( ev ) ;
+                       realEvent = false ;
+                       break ;
+               case kHighLevelEvent:
+                       DoMacHighLevelEvent( ev ) ;
+                       break;
+               case mouseDown:
+                       DoMacMouseDownEvent( ev ) ;
+                       wxTheApp->ExitMainLoop() ;
+                       break;
+               case mouseUp:
+                       DoMacMouseUpEvent( ev ) ;
+                       break;
+               case keyDown:
+                       DoMacKeyDownEvent( ev ) ;
+                       break;
+               case autoKey:
+                       DoMacAutoKeyEvent( ev ) ;
+                       break;
+               case keyUp:
+                       DoMacKeyUpEvent( ev ) ;
+                       break;
+               case activateEvt:
+                       DoMacActivateEvent( ev ) ;
+                       break;
+               case updateEvt:
+                       DoMacUpdateEvent( ev ) ;
+                       break;
+               case diskEvt:
+                       DoMacDiskEvent( ev ) ;
+                       break;
+               case osEvt:
+                       DoMacOSEvent( ev ) ;
+                       break;
+               default:
+                       break;
+       }
+  return realEvent ;
+}
+
+// platform specific functions (non PLxxx functions)
+
+void DoMacNullEvent( EventRecord *ev ) 
+{
+}
+
+void DoMacHighLevelEvent( EventRecord *ev )
+{
+}
+
+void DoMacMouseDownEvent( EventRecord *ev )
+{
+}
+
+void DoMacMouseUpEvent( EventRecord *ev )
+{
+}
+
+void DoMacKeyDownEvent( EventRecord *ev )
+{
+}
+
+void DoMacKeyUpEvent( EventRecord *ev )
+{
+}
+
+void DoMacAutoKeyEvent( EventRecord *ev )
+{
+}
+
+void DoMacActivateEvent( EventRecord *ev )
+{
+}
+
+void DoMacUpdateEvent( EventRecord *ev )
+{
+}
+
+void DoMacDiskEvent( EventRecord *ev )
+{
+}
+
+void DoMacOSEvent( EventRecord *ev )
+{
+}
+
+
+
+/*
+
+void wxApp::doMacMouseDown(void)
+{
+       WindowPtr window;
+       short windowPart = ::FindWindow(m_event.where, &window);
+       if ( windowPart != inMenuBar )
+       {
+               WindowPtr frontWindow = FrontWindow();
+               if (WindowIsModal(frontWindow) && (window != frontWindow))
+                       SysBeep(1);
+               else
+               {       
+                       switch (windowPart)
+                       {
+                               case inMenuBar:
+                                       break;
+                               case inContent:
+                                       doMacInContent(window); break;
+                               case inDrag:
+                                       doMacInDrag(window); break;
+                               case inGrow:
+                                       doMacInGrow(window); break;
+                               case inGoAway:
+                                       doMacInGoAway(window); break;
+                               case inZoomIn:
+                               case inZoomOut:
+                                       doMacInZoom(window, windowPart); break;
+                               default:
+                                       break;
+                       }
+       
+               }
+       }
+       else
+       {
+               doMacInMenuBar(::MenuSelect(m_event.where));
+       }
+}
+
+void wxApp::doMacMouseUp(void)
+{
+       if (m_mouseWindow)
+       {
+#if 0
+               int hitX = m_event.where.h;                             // screen window c.s.
+               int hitY = m_event.where.v;                             // screen window c.s.
+               m_mouseWindow->ScreenToClient(&hitX, &hitY);            // mouseWindow client c.s.
+               m_mouseWindow->ClientToLogical(&hitX, &hitY);   // mouseWindow logical c.s.
+#endif
+               
+               wxMouseEvent event(wxEVT_LEFT_UP);
+               event.m_shiftDown = m_event.modifiers & shiftKey;
+               event.m_controlDown = m_event.modifiers & controlKey;
+               event.m_altDown = m_event.modifiers & optionKey;
+               event.m_metaDown = m_event.modifiers & cmdKey;
+               event.m_leftDown = FALSE;
+               event.m_middleDown = FALSE;
+               event.m_rightDown = FALSE;
+               event.m_x = m_event.where.h;
+               event.m_y = m_event.where.v;
+               event.m_timeStamp = m_event.when;
+               event.SetEventObject(m_mouseWindow);
+
+               m_mouseWindow->ProcessEvent(event);
+       }
+       else
+       {
+               //??? Can't we just throw away mouse up events without matching mouse down
+               wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
+               if (theMacWxFrame)
+               {
+#if 0
+                       int hitX = cCurrentEvent.where.h; // screen window c.s.
+                       int hitY = cCurrentEvent.where.v; // screen window c.s.
+                       theMacWxFrame->ScreenToWindow(&hitX, &hitY);
+#endif
+
+                       wxMouseEvent event(wxEVT_LEFT_UP);
+                       event.m_shiftDown = m_event.modifiers & shiftKey;
+                       event.m_controlDown = m_event.modifiers & controlKey;
+                       event.m_altDown = m_event.modifiers & optionKey;
+                       event.m_metaDown = m_event.modifiers & cmdKey;
+                       event.m_leftDown = FALSE;
+                       event.m_middleDown = FALSE;
+                       event.m_rightDown = FALSE;
+                       event.m_x = m_event.where.h;
+                       event.m_y = m_event.where.v;
+                       event.m_timeStamp = m_event.when;
+                       event.SetEventObject(m_mouseWindow);
+
+                       theMacWxFrame->ProcessEvent(event);
+               }
+       }
+}
+
+void wxApp::doMacMouseMotion(void)
+{
+       if (m_mouseWindow) {
+               wxMouseEvent event(wxEVT_MOTION);
+               event.m_shiftDown = m_event.modifiers & shiftKey;
+               event.m_controlDown = m_event.modifiers & controlKey;
+               event.m_altDown = m_event.modifiers & optionKey;
+               event.m_metaDown = m_event.modifiers & cmdKey;
+               event.m_leftDown = !(m_event.modifiers & btnState);
+               event.m_middleDown = FALSE;
+               event.m_rightDown = FALSE;
+               event.m_x = m_event.where.h;
+               event.m_y = m_event.where.v;
+               event.m_timeStamp = m_event.when;
+               event.SetEventObject(m_mouseWindow);
+
+               m_mouseWindow->ProcessEvent(event);
+       }
+       else
+       {
+               wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
+               if (theMacWxFrame)
+               {
+                       wxMouseEvent event(wxEVT_MOTION);
+                       event.m_shiftDown = m_event.modifiers & shiftKey;
+                       event.m_controlDown = m_event.modifiers & controlKey;
+                       event.m_altDown = m_event.modifiers & optionKey;
+                       event.m_metaDown = m_event.modifiers & cmdKey;
+                       event.m_leftDown = !(m_event.modifiers & btnState);
+                       event.m_middleDown = FALSE;
+                       event.m_rightDown = FALSE;
+                       event.m_x = m_event.where.h;
+                       event.m_y = m_event.where.v;
+                       event.m_timeStamp = m_event.when;
+                       event.SetEventObject(m_mouseWindow);
+
+                       m_mouseWindow->ProcessEvent(event);
+               }
+       }
+       
+       //??? Need to work with floating windows... isn't there a toolbox call to find the
+       // top window intersecting a point is screen coordinates??
+#if 0
+       else    // will only work for one floating window at the moment... ?
+       {       
+               WindowPtr frontDocPtr = findFrontNonFloatingWindow();
+               WindowPtr frontFloatingPtr = ::FrontWindow();
+               
+               int hitX = cCurrentEvent.where.h;
+               int hitY = cCurrentEvent.where.v;
+               
+               wxFrame* macWxFrame = findMacWxFrame(frontDocPtr);
+               
+               if ((frontFloatingPtr != frontDocPtr) & (frontFloatingPtr != NULL))
+               {
+                       RgnHandle frontFloatStrRgn = getStructureRegion(frontFloatingPtr);
+                       Rect      frontFloatRect = (**frontFloatStrRgn).rgnBBox;
+       
+                       if         ((hitX >= frontFloatRect.left) & 
+                                       (hitX <= frontFloatRect.right) & 
+                                       (hitY >= frontFloatRect.top) &
+                                       (hitY <= frontFloatRect.bottom))
+                       {
+                               macWxFrame = findMacWxFrame(frontFloatingPtr);
+                       }
+               }
+       }
+#endif
+}
+
+void wxApp::doMacKeyDown(void)
+{
+       long menuResult = 0 ;
+       short keycode ;
+       short keychar ;
+       keychar = short(m_event.message & charCodeMask);
+       keycode = short(m_event.message & keyCodeMask) >> 8 ;
+
+       // Handle menu accelerators
+       if ( gSFMacHasAppearance )
+       {
+               menuResult = MenuEvent( &m_event ) ;
+               if ( HiWord( menuResult ) )
+               {
+                       doMacInMenuBar( menuResult ) ;
+               }
+               else
+               {
+                       ControlHandle control ;
+                       
+                       GetKeyboardFocus( FrontNonFloatingWindow() , &control ) ;
+                       if ( control && keychar != 0x07 )
+                               HandleControlKey( control , keycode , keychar , m_event.modifiers ) ;
+                       else
+                       {
+                               wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
+                               if (theMacWxFrame)
+                               {
+                                       wxKeyEvent event(wxEVT_CHAR);
+                                       event.m_shiftDown = m_event.modifiers & shiftKey;
+                                       event.m_controlDown = m_event.modifiers & controlKey;
+                                       event.m_altDown = m_event.modifiers & optionKey;
+                                       event.m_metaDown = m_event.modifiers & cmdKey;
+                                       event.m_keyCode = macTranslateKey(keychar, m_event.modifiers & (shiftKey|optionKey));
+                                       event.m_x = m_event.where.h;
+                                       event.m_y = m_event.where.v;
+                                       event.m_timeStamp = m_event.when;
+                                       event.SetEventObject(theMacWxFrame);
+                       
+                                       theMacWxFrame->ProcessEvent(event);
+                               }
+                       }
+               }
+       }
+       else
+       {
+               if (GetMenuHandle( kwxMacAppleMenuId ) )
+               {
+//                     menuResult = MDEF_MenuKey(m_event.message, m_event.modifiers , GetMenuHandle( kwxMacAppleMenuId ) );
+               }
+               else
+               {
+                       if (m_event.modifiers & cmdKey)
+                       {
+                               menuResult = MenuKey( keychar ) ;
+                       }
+               }
+
+               if ( HiWord( menuResult ) )
+               {
+                       doMacInMenuBar( menuResult ) ;
+               }
+               else
+               {
+                       wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
+                       if (theMacWxFrame)
+                       {
+                               wxKeyEvent event(wxEVT_CHAR);
+                               event.m_shiftDown = m_event.modifiers & shiftKey;
+                               event.m_controlDown = m_event.modifiers & controlKey;
+                               event.m_altDown = m_event.modifiers & optionKey;
+                               event.m_metaDown = m_event.modifiers & cmdKey;
+                               event.m_keyCode = macTranslateKey(keychar, m_event.modifiers & (shiftKey|optionKey));
+                               event.m_x = m_event.where.h;
+                               event.m_y = m_event.where.v;
+                               event.m_timeStamp = m_event.when;
+                               event.SetEventObject(theMacWxFrame);
+               
+                               theMacWxFrame->ProcessEvent(event);
+                       }
+               }
+       }
+}
+
+void wxApp::doMacAutoKey(void)
+{
+       doMacKeyDown();
+}
+
+void wxApp::doMacKeyUp(void)
+{
+}
+
+void wxApp::doMacActivateEvt(void)
+{
+       HighlightAndActivateWindow( (WindowPtr) m_event.message , m_event.modifiers & activeFlag ) ;
+}
+
+void wxApp::doMacUpdateEvt(void)
+{
+       WindowPtr theMacWindow = (WindowPtr)(m_event.message);
+       ::BeginUpdate(theMacWindow);
+       
+       wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(theMacWindow);
+       if (theMacWxFrame)
+       {
+//             if (!::EmptyRgn(theMacWindow->visRgn))  // this doesn't work with windowshade
+//             {
+                       if ( theMacWxFrame->MacSetupPort() )
+                       {
+                               // Erase update region
+                               // we must do this, because controls add their former rect to the inval
+                               // rgn and the background might not have been correct at that moment
+                               ::EraseRect(&theMacWindow->portRect); 
+       
+                               // Can't use UpdateControls since each control has it's own coordinate system
+                               //              ::UpdateControls(theMacWindow, theMacWindow->visRgn);
+       
+                               ::UpdateControls( theMacWindow , theMacWindow->visRgn ) ;
+       #if 0
+                               // Draw the grow box
+                               if (cStyle & wxRESIZE_BORDER)
+                                       MacDrawGrowIcon();
+       #endif
+       
+                               wxPaintEvent event;
+                               event.m_timeStamp = m_event.when;
+                               event.SetEventObject(theMacWxFrame);
+       
+                               theMacWxFrame->ProcessEvent(event);
+       //                      ::SetThemeWindowBackground(  theMacWindow , kThemeActiveDialogBackgroundBrush ,  false ) ;
+                               ::ClipRect( &theMacWindow->portRect ) ;         
+                               ::SetOrigin(  0 , 0 );  
+                       }
+                       else
+                       {
+                               wxASSERT_MSG( false , "unabled to setup window mac port") ;
+                       }
+                       
+//             }
+       }
+
+       ::EndUpdate(theMacWindow);
+}
+
+void wxApp::doMacDiskEvt(void)
+{ // based on "Programming for System 7" by Gary Little and Tim Swihart
+       if ((m_event.message >> 16) != noErr)
+       {
+               const int kDILeft = 0x0050; // top coord for disk init dialog
+               const int kDITop = 0x0070; // left coord for disk init dialog
+               Point mountPoint;
+               mountPoint.h = kDILeft;
+               mountPoint.v = kDITop;
+               int myError = DIBadMount(mountPoint, m_event.message);
+       }
+}
+
+void wxApp::doMacOsEvt(void)
+{ // based on "Programming for System 7" by Gary Little and Tim Swihart
+       switch ((m_event.message >> 24) & 0x0ff)
+       {
+               case suspendResumeMessage:
+                       if (m_event.message & resumeFlag)
+                               doMacResumeEvent();
+                       else
+                               doMacSuspendEvent();
+                       break;
+               case mouseMovedMessage:
+                       doMacMouseMovedMessage();
+                       break;
+       }
+}
+
+void wxApp::doMacHighLevelEvent(void)
+{
+       ::AEProcessAppleEvent(&m_event); // System 7 or higher
+}
+
+void wxApp::doMacResumeEvent(void)
+{
+       wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
+       if (theMacWxFrame)
+       {
+               if (m_event.message & convertClipboardFlag)
+                       ::TEFromScrap();
+
+               wxActivateEvent event(wxEVT_ACTIVATE, TRUE);
+               event.m_timeStamp = m_event.when;
+               event.SetEventObject(theMacWxFrame);
+
+               theMacWxFrame->ProcessEvent(event);
+       }
+}
+
+void wxApp::doMacSuspendEvent(void)
+{
+       wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
+       if (theMacWxFrame)
+       {
+               ::ZeroScrap();
+               ::TEToScrap();
+
+               wxActivateEvent event(wxEVT_ACTIVATE, FALSE);
+               event.m_timeStamp = m_event.when;
+               event.SetEventObject(theMacWxFrame);
+
+               theMacWxFrame->ProcessEvent(event);
+       }
+}
+
+void wxApp::doMacMouseMovedMessage(void)
+{ // based on "Programming for System 7" by Gary Little and Tim Swihart
+       if (m_cursorRgn)
+               ::DisposeRgn(m_cursorRgn);
+       m_cursorRgn = ::NewRgn();
+       ::SetRectRgn(m_cursorRgn, -32768, -32768, 32766, 32766);
+}
+
+void wxApp::doMacInMenuBar(long menuResult)
+{
+       int macMenuId = HiWord(menuResult);
+       int macMenuItemNum = LoWord(menuResult); // counting from 1
+
+       if (macMenuId == 0)                                     // no menu item selected;
+                return;
+       if (macMenuId == 128) 
+       {
+               if (macMenuItemNum != 1) 
+               {                       // if not the "About" entry (or the separator)
+                       Str255          daName;
+                       ::GetMenuItemText(GetMenuHandle(128), macMenuItemNum, daName);
+                       (void)::OpenDeskAcc(daName);
+                       ::HiliteMenu(0);                                                                
+                       return;
+               }
+       }
+
+       wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
+       if (theMacWxFrame)
+       {
+               if ( theMacWxFrame->IsKindOf( CLASSINFO( wxDialog ) ) )
+                       (( wxDialog *) theMacWxFrame)->MacMenuSelect(m_event, macMenuId, macMenuItemNum);
+               else if ( theMacWxFrame->IsKindOf( CLASSINFO( wxFrame ) ) )
+                       (( wxFrame *) theMacWxFrame)->MacMenuSelect(m_event, macMenuId, macMenuItemNum);
+       }
+       ::HiliteMenu(0);                                                                
+}
+
+void wxApp::doMacInContent(WindowPtr window)
+{
+       WindowPtr frontWindow = FrontWindow();
+       if (window != frontWindow )
+       {
+//             SFSelectWindow( window ) ;
+       }
+       else
+       {
+               ControlHandle   control ;
+               Point           localwhere = m_event.where ;
+               GrafPtr         port ;
+               SInt16          controlpart ;
+               
+               ::GetPort( &port ) ;
+               ::SetPort( window ) ;
+               ::GlobalToLocal( &localwhere ) ;
+
+               ::SetPort( port ) ;
+               
+               if ( !gSFMacHasAppearance )
+               {
+                       controlpart = FindControl( localwhere , window , &control ) ;
+               }
+               else
+               {
+                       control = FindControlUnderMouse( localwhere , window , &controlpart ) ;
+               }
+               
+               if ( control && IsControlActive( control ) )
+               {
+                       wxControl* wxc = (wxControl*) GetControlReference( control ) ;
+                                       
+                       if ( wxWindow::FindFocus() != wxc &&  wxc->AcceptsFocus() )
+                       {
+                               wxc->SetFocus() ;       
+                               if ( wxWindow::FindFocus() != wxc )
+                                       control = NULL ; // we were not able to change focus
+                       }               
+                                                               
+                       if ( control )
+                       {
+                               if ( !gSFMacHasAppearance)
+                               {
+                                       controlpart = TrackControl( control , localwhere , NULL ) ;
+                               }
+                               else
+                               {
+                                       controlpart = HandleControlClick( control , localwhere , m_event.modifiers , (ControlActionUPP) -1 ) ;
+                               }
+                               
+                               if ( controlpart )
+                               {
+                                       wxControl*      wx = (wxControl*) GetControlReference( control ) ;
+                                       if ( wx )
+                                               wx->MacHandleControlClick( control , controlpart ) ;
+                               }
+                       }
+               }
+               else
+               {
+                       wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(window);
+                       if (theMacWxFrame)
+                       {
+                               doMacContentClick((wxFrame*)theMacWxFrame); // todo : this cast is wrong
+                       }
+               }
+       }
+       
+#if 0
+       wxFrame* theMacWxFrame = findMacWxFrame(window);
+       if (theMacWxFrame)
+       {
+               WindowPtr MacWindow = findFrontNonFloatingWindow();
+               if (window != MacWindow)
+               {               
+                       wxFrame* frontFrame = findMacWxFrame(MacWindow);
+                       if (!frontFrame) wxFatalError("No wxFrame for frontnonfloatingWindow.");
+                       if (!frontFrame->IsModal())
+                       {
+                               frontFrame->SetFocus();
+                               doMacContentClick(theMacWxFrame);       // jonto - to deal with doc windows behind floaters ?
+                               ::newSelectWindow(window);                      // WCH : should I be calling some wxMethod?
+                               if (!IsFloating(MacWindow))
+                               {
+                                       KeyMap keyMap;
+                                       GetKeys(keyMap);
+                                       if (!(keyMap[1] & 0x8000)) theMacWxFrame->ShowAsActive(true);   // temporary measure...
+                               }
+                       }                                                                               // jonto : not sure yet, but let's try this ...
+                       else ::SysBeep(3);
+               }
+               else
+               {
+                       doMacContentClick(theMacWxFrame);
+               }
+       }
+#endif
+}
+
+void wxApp::doMacContentClick(wxWindow* frame)
+{
+       m_mouseWindow = frame;
+
+       wxMouseEvent event(wxEVT_LEFT_DOWN);
+       event.m_shiftDown = m_event.modifiers & shiftKey;
+       event.m_controlDown = m_event.modifiers & controlKey;
+       event.m_altDown = m_event.modifiers & optionKey;
+       event.m_metaDown = m_event.modifiers & cmdKey;
+       event.m_leftDown = FALSE;
+       event.m_middleDown = FALSE;
+       event.m_rightDown = FALSE;
+       if ( m_event.modifiers & controlKey )
+       {
+               event.m_rightDown = TRUE;
+       }
+       else
+       {
+               event.m_leftDown = TRUE;
+       }
+#if 0
+  event.m_leftDown = !(m_event.modifiers & btnState);
+       event.m_middleDown = FALSE;
+       event.m_rightDown = FALSE;
+#endif
+       event.m_x = m_event.where.h;
+       event.m_y = m_event.where.v;
+       event.m_timeStamp = m_event.when;
+       event.SetEventObject(m_mouseWindow);
+
+//     m_mouseWindow->ProcessEvent(event);
+       m_mouseWindow->MacDispatchMouseEvent(event);
+       
+#if 0
+       // RightButton is cmdKey click  on the mac platform for one-button mouse
+       Bool rightButton = cCurrentEvent.modifiers & cmdKey;
+       // altKey is optionKey on the mac platform:
+       Bool isAltKey = cCurrentEvent.modifiers & optionKey;
+
+       WXTYPE mouseEventType = rightButton ? wxEVENT_TYPE_RIGHT_DOWN
+                                                                               : wxEVENT_TYPE_LEFT_DOWN;
+       wxMouseEvent theMouseEvent(mouseEventType);
+       theMouseEvent.leftDown = !rightButton;
+       theMouseEvent.middleDown = FALSE;
+       theMouseEvent.rightDown = rightButton;
+       theMouseEvent.shiftDown = cCurrentEvent.modifiers & shiftKey;
+       theMouseEvent.controlDown = cCurrentEvent.modifiers & controlKey;
+       theMouseEvent.altDown = isAltKey;
+       theMouseEvent.metaDown = FALSE;  // mflatt
+       theMouseEvent.timeStamp = cCurrentEvent.when; // mflatt
+
+       int hitX = cCurrentEvent.where.h; // screen window c.s.
+       int hitY = cCurrentEvent.where.v; // screen window c.s.
+
+       frame->ScreenToWindow(&hitX, &hitY);
+//     frameParentArea->ScreenToArea(&hitX, &hitY);                    // tx coords ?
+       theMouseEvent.x = hitX; // frame parent area c.s.
+       theMouseEvent.y = hitY; // frame parent area c.s.
+
+       frame->SeekMouseEventArea(theMouseEvent);
+#endif
+}
+
+void wxApp::doMacInDrag(WindowPtr window)
+{
+       wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(window);
+       if (theMacWxFrame)
+       {
+               // should be desktop, not screen
+               Rect dragBoundsRect = qd.screenBits.bounds;     // can't move to a different screen
+//xxx  ::InsetRect(&dragBoundsRect, 4, ::GetMBarHeight() + 4); // This is not really necessary
+               Rect oldPos = (**(((WindowPeek)window)->strucRgn)).rgnBBox;
+               ::DragReferencedWindow(window, m_event.where, &dragBoundsRect); // jonto
+               #if 0
+               theMacWxFrame->m_x += (**(((WindowPeek)window)->strucRgn)).rgnBBox.left - oldPos.left;
+               theMacWxFrame->m_y += (**(((WindowPeek)window)->strucRgn)).rgnBBox.top - oldPos.top;
+               #endif
+               Move( (**(((WindowPeek)window)->strucRgn)).rgnBBox.left , (**(((WindowPeek)window)->strucRgn)).rgnBBox.top ) ;
+#if 0
+               theMacWxFrame->wxMacRecalcNewSize(); // Actually, recalc new position only
+#endif
+       }
+       
+#if 0
+//     if (window != ::FrontWindow())
+       if (window != findFrontNonFloatingWindow())
+       {
+//             wxFrame* frontFrame = findMacWxFrame(::FrontWindow());
+               wxFrame* frontFrame = findMacWxFrame(findFrontNonFloatingWindow());
+               if (!frontFrame) wxFatalError("No wxFrame for frontWindow.");
+               if (frontFrame->IsModal())
+               {
+                       ::SysBeep(3);
+                       return;
+               }
+       }
+
+       wxFrame* theMacWxFrame = findMacWxFrame(window);
+       if (theMacWxFrame)
+       {
+               Rect dragBoundsRect = qd.screenBits.bounds;     // can't move to a different screen
+               ::InsetRect(&dragBoundsRect, 4, ::GetMBarHeight() + 4); // This is not really necessary
+               newDragWindow(window, cCurrentEvent.where, &dragBoundsRect);    // jonto
+               theMacWxFrame->wxMacRecalcNewSize(); // Actually, recalc new position only
+               if (!IsFloating(window))
+               {
+                       theMacWxFrame->ShowAsActive(true);      // temporary measure...
+               }
+       }
+#endif
+}
+
+void wxApp::doMacInGrow(WindowPtr window)
+{
+       wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(window);
+       if (theMacWxFrame)
+       {
+               Rect growSizeRect; // WCH: growSizeRect should be a member of wxFrame class
+               growSizeRect.top = 1; // minimum window height
+               growSizeRect.left = 1; // minimum window width
+               growSizeRect.bottom = qd.screenBits.bounds.bottom - qd.screenBits.bounds.top;
+               growSizeRect.right = qd.screenBits.bounds.right - qd.screenBits.bounds.left;
+               long windSize = ::GrowWindow(window, m_event.where, &growSizeRect);
+               if (windSize != 0)
+               {
+                       int nWidth = LoWord(windSize);
+                       int nHeight = HiWord(windSize);
+                       int oWidth, oHeight;
+                       theMacWxFrame->GetSize(&oWidth, &oHeight);
+                       if (nWidth == 0) nWidth = oWidth;
+                       if (nHeight == 0) nHeight = oHeight;
+                       theMacWxFrame->SetSize( -1, -1, nWidth, nHeight, wxSIZE_USE_EXISTING);
+               }
+       }
+}
+
+void wxApp::doMacInGoAway(WindowPtr window)
+{
+       wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(window);
+       if (theMacWxFrame)
+       {
+               if (TrackGoAway(window, m_event.where))
+               {
+                       if (theMacWxFrame->OnClose()) {
+#if WXGARBAGE_COLLECTION_ON
+                               theMacWxFrame->Show(FALSE);
+#else
+                               delete theMacWxFrame;
+#endif
+                       }
+               }
+       }
+}
+
+void wxApp::doMacInZoom(WindowPtr window, short windowPart)
+{
+       wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(window);
+       if (theMacWxFrame)
+       {
+               if (TrackBox(window, m_event.where, windowPart))
+               {
+#if 0
+                       theMacWxFrame->Maximize(windowPart == inZoomOut);
+#endif
+               }
+       }
+}
+
+long wxApp::macTranslateKey(char key, int mods)
+{
+    static Handle transH = NULL;
+    static unsigned long transState = 0;
+    static Handle ScriptH = NULL;
+    static short region_code = 1;
+
+       if (!ScriptH) { // tom: don't guess the regioncode!!!!
+      struct ItlbRecord * r;
+      ScriptH = GetResource('itlb',0);
+      if (ScriptH) {
+       HLock(ScriptH);
+       r = (ItlbRecord*)*ScriptH;
+       region_code = r->itlbKeys;      
+       HUnlock(ScriptH);
+      }        
+    }
+    switch (key) {
+    case 0x7e:
+    case 0x3e:
+      key = WXK_UP;
+      break;
+    case 0x7d:
+    case 0x3d:
+      key = WXK_DOWN;
+      break;
+    case 0x7b:
+    case 0x3b:
+      key = WXK_LEFT;
+      break;
+    case 0x7c:
+    case 0x3c:
+      key = WXK_RIGHT;
+      break;
+    case 0x24:
+    case 0x4c:
+      key = WXK_RETURN;
+      break;
+    case 0x30:
+      key = WXK_TAB;
+      break;
+    case 0x33:
+      key = WXK_BACK;
+      break;
+    case 0x75:
+      key = WXK_DELETE;
+      break;
+    case 0x73:
+         key = WXK_HOME;
+         break;
+       case 0x77:
+         key = WXK_END;
+         break;   
+       case 0x74:
+         key = WXK_PAGEUP;
+         break;     
+       case 0x79:
+         key = WXK_PAGEDOWN;
+         break;     
+    default:
+      if (!transH) {
+               transH = GetIndResource('KCHR', 1);
+               HNoPurge(transH);
+      }
+#if 0 //Tom replaces
+      if (transH) {
+               // Only let shift & option modify the key: 
+               HLock(transH);
+               key = KeyTranslate(*transH, (key & 0x7F) | mods, &transState) & charCodeMask;
+               HUnlock(transH);
+#else
+       if (0) { // tom fettig@dfki.uni-sb.de
+               // why if(0):
+               // code is not correct, see inside Macintosh: Text 1-87
+               // and 'itlk'-resource!!
+               // and it is not necessary, as the translated char is in
+               // cCurrrentEvent.message!!
+               // Only let shift & option modify the key: 
+               HLock(transH);
+               key = KeyTranslate(*transH, (key & 0x7F) | mods, &transState) & charCodeMask;
+               HUnlock(transH);
+#endif
+         }
+       } // end switch
+       
+       return key;
+}
+
+void
+wxApp::macAdjustCursor()
+{
+  if (m_event.what != kHighLevelEvent)
+  {
+       wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
+       if (theMacWxFrame)
+       {
+         if (!theMacWxFrame->MacAdjustCursor(m_event.where))
+               ::SetCursor(&(qd.arrow));
+       }
+  }
+}
+*/
\ No newline at end of file
index 5e6c4185198e735e0e404e30df4754f7f8aba214..7143aa5e953c240192638fd391ae7a4486628b38 100644 (file)
@@ -16,7 +16,7 @@
 #include "wx/wx.h"
 
 #if wxUSE_POSTSCRIPT
-#include "wx/postscrp.h"
+#include "wx/generic/dcpsg.h"
 #endif
 
 #define _MAXPATHLEN 500
index 2aeffdf926776a60104fba72807157738c254091..ba8ad73df7644789ed70f41ffdd20a4604b89933 100644 (file)
@@ -23,7 +23,7 @@
 IMPLEMENT_CLASS(wxFileDialog, wxDialog)
 #endif
 
-char *wxFileSelector(const char *title,
+WXDLLEXPORT wxString wxFileSelector(const char *title,
                      const char *defaultDir, const char *defaultFileName,
                      const char *defaultExtension, const char *filter, int flags,
                      wxWindow *parent, int x, int y)
@@ -60,7 +60,7 @@ char *wxFileSelector(const char *title,
         return NULL;
 }
 
-char *wxFileSelectorEx(const char *title,
+WXDLLEXPORT wxString wxFileSelectorEx(const char *title,
                        const char *defaultDir,
                        const char *defaultFileName,
                        int* defaultFilterIndex,
@@ -105,7 +105,7 @@ int wxFileDialog::ShowModal()
 }
 
 // Generic file load/save dialog
-static char *
+static wxString
 wxDefaultFileSelector(bool load, const char *what, const char *extension, const char *default_name, wxWindow *parent)
 {
   char *ext = (char *)extension;
@@ -126,7 +126,7 @@ wxDefaultFileSelector(bool load, const char *what, const char *extension, const
 }
 
 // Generic file load dialog
-char *
+wxString
 wxLoadFileSelector(const char *what, const char *extension, const char *default_name, wxWindow *parent)
 {
   return wxDefaultFileSelector(TRUE, what, extension, default_name, parent);
@@ -134,7 +134,7 @@ wxLoadFileSelector(const char *what, const char *extension, const char *default_
 
 
 // Generic file save dialog
-char *
+wxString
 wxSaveFileSelector(const char *what, const char *extension, const char *default_name, wxWindow *parent)
 {
   return wxDefaultFileSelector(FALSE, what, extension, default_name, parent);
index 54df1811666b81aea8a5c83c27507e8fd2250ee8..a92154acfb116da48cde9e08a556a83c2ecff8ee 100644 (file)
@@ -18,6 +18,9 @@
 #if !USE_SHARED_LIBRARY
 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
 
+BEGIN_EVENT_TABLE(wxScrollBar, wxControl)
+END_EVENT_TABLE()
+
 #endif
 
 // Scrollbar
index 82fff92ba38b9fca81d02e7d8461e031c73aa6b8..8dd23bdce95c2f275b47019824aa22b5615de173 100644 (file)
@@ -24,6 +24,8 @@ enum thread_state {
   STATE_EXITED
 };
 
+#if wxUSE_THREADS
+
 /////////////////////////////////////////////////////////////////////////////
 // Static variables
 /////////////////////////////////////////////////////////////////////////////
@@ -259,3 +261,4 @@ public:
 
 IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)
 
+#endif
index 5e6c4185198e735e0e404e30df4754f7f8aba214..7143aa5e953c240192638fd391ae7a4486628b38 100644 (file)
@@ -16,7 +16,7 @@
 #include "wx/wx.h"
 
 #if wxUSE_POSTSCRIPT
-#include "wx/postscrp.h"
+#include "wx/generic/dcpsg.h"
 #endif
 
 #define _MAXPATHLEN 500
index 2aeffdf926776a60104fba72807157738c254091..ba8ad73df7644789ed70f41ffdd20a4604b89933 100644 (file)
@@ -23,7 +23,7 @@
 IMPLEMENT_CLASS(wxFileDialog, wxDialog)
 #endif
 
-char *wxFileSelector(const char *title,
+WXDLLEXPORT wxString wxFileSelector(const char *title,
                      const char *defaultDir, const char *defaultFileName,
                      const char *defaultExtension, const char *filter, int flags,
                      wxWindow *parent, int x, int y)
@@ -60,7 +60,7 @@ char *wxFileSelector(const char *title,
         return NULL;
 }
 
-char *wxFileSelectorEx(const char *title,
+WXDLLEXPORT wxString wxFileSelectorEx(const char *title,
                        const char *defaultDir,
                        const char *defaultFileName,
                        int* defaultFilterIndex,
@@ -105,7 +105,7 @@ int wxFileDialog::ShowModal()
 }
 
 // Generic file load/save dialog
-static char *
+static wxString
 wxDefaultFileSelector(bool load, const char *what, const char *extension, const char *default_name, wxWindow *parent)
 {
   char *ext = (char *)extension;
@@ -126,7 +126,7 @@ wxDefaultFileSelector(bool load, const char *what, const char *extension, const
 }
 
 // Generic file load dialog
-char *
+wxString
 wxLoadFileSelector(const char *what, const char *extension, const char *default_name, wxWindow *parent)
 {
   return wxDefaultFileSelector(TRUE, what, extension, default_name, parent);
@@ -134,7 +134,7 @@ wxLoadFileSelector(const char *what, const char *extension, const char *default_
 
 
 // Generic file save dialog
-char *
+wxString
 wxSaveFileSelector(const char *what, const char *extension, const char *default_name, wxWindow *parent)
 {
   return wxDefaultFileSelector(FALSE, what, extension, default_name, parent);
index 54df1811666b81aea8a5c83c27507e8fd2250ee8..a92154acfb116da48cde9e08a556a83c2ecff8ee 100644 (file)
@@ -18,6 +18,9 @@
 #if !USE_SHARED_LIBRARY
 IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
 
+BEGIN_EVENT_TABLE(wxScrollBar, wxControl)
+END_EVENT_TABLE()
+
 #endif
 
 // Scrollbar
index 82fff92ba38b9fca81d02e7d8461e031c73aa6b8..8dd23bdce95c2f275b47019824aa22b5615de173 100644 (file)
@@ -24,6 +24,8 @@ enum thread_state {
   STATE_EXITED
 };
 
+#if wxUSE_THREADS
+
 /////////////////////////////////////////////////////////////////////////////
 // Static variables
 /////////////////////////////////////////////////////////////////////////////
@@ -259,3 +261,4 @@ public:
 
 IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule)
 
+#endif
index 4366ad4350db59f116ad3dc3470a480d7a3f3348..418073ea9fbb71c56216da403457662e27ef53eb 100644 (file)
@@ -565,7 +565,7 @@ int wxEntry(WXHINSTANCE hInstance,
   // FIXME other compilers must support Win32 SEH (structured exception
   //       handling) too, just find the appropriate keyword in their docs!
   //       Please note that it's _not_ the same as C++ exceptions!
-#if !defined(__WXDEBUG__) && defined(_MSC_VER)
+#if !defined(__WXDEBUG__) && defined(_MSC_VER) && !defined(__MWERKS__)
     #define CATCH_PROGRAM_EXCEPTIONS
 
   __try {