#pragma implementation "app.h"
#endif
+#include "wx/defs.h"
+
#include "wx/window.h"
#include "wx/frame.h"
+#include "wx/button.h"
#include "wx/app.h"
#include "wx/utils.h"
#include "wx/gdicmn.h"
#include "wx/textctrl.h"
#include "wx/menu.h"
#if wxUSE_WX_RESOURCES
-#include "wx/resource.h"
+# include "wx/resource.h"
#endif
#include <string.h>
#include "wx/mac/uma.h"
#include "wx/mac/macnotfy.h"
-#if wxUSE_SOCKETS
- #ifdef __DARWIN__
- #include <CoreServices/CoreServices.h>
- #else
- #include <OpenTransport.h>
- #include <OpenTptInternet.h>
- #endif
+#ifdef __DARWIN__
+# include <CoreServices/CoreServices.h>
+#else
+# include <Sound.h>
+# include <Threads.h>
+# include <ToolUtils.h>
+# include <DiskInit.h>
+# include <Devices.h>
#endif
extern char *wxBuffer;
const short kwxMacMenuBarResource = 1 ;
const short kwxMacAppleMenuId = 1 ;
-RgnHandle wxApp::s_macCursorRgn = NULL;
+WXHRGN wxApp::s_macCursorRgn = NULL;
wxWindow* wxApp::s_captureWindow = NULL ;
int wxApp::s_lastMouseDown = 0 ;
long wxApp::sm_lastMessageTime = 0;
return wxTheApp->MacHandleAEQuit( (AppleEvent*) event , reply) ;
}
-OSErr wxApp::MacHandleAEODoc(const AppleEvent *event , AppleEvent *reply)
+short wxApp::MacHandleAEODoc(const WXEVENTREF event , WXEVENTREF reply)
{
SysBeep(40) ;
ProcessSerialNumber PSN ;
return noErr ;
}
-OSErr wxApp::MacHandleAEPDoc(const AppleEvent *event , AppleEvent *reply)
+short wxApp::MacHandleAEPDoc(const WXEVENTREF event , WXEVENTREF reply)
{
return noErr ;
}
-OSErr wxApp::MacHandleAEOApp(const AppleEvent *event , AppleEvent *reply)
+short wxApp::MacHandleAEOApp(const WXEVENTREF event , WXEVENTREF reply)
{
return noErr ;
}
-OSErr wxApp::MacHandleAEQuit(const AppleEvent *event , AppleEvent *reply)
+short wxApp::MacHandleAEQuit(const WXEVENTREF event , WXEVENTREF reply)
{
wxWindow* win = GetTopWindow() ;
if ( win )
return noErr ;
}
-char StringMac[] = "\x0d\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
+char StringMac[] = "\x0d\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
"\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
"\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xae\xaf"
"\xb1\xb4\xb5\xb6\xbb\xbc\xbe\xbf"
CopyCStringToPascal( from , to ) ;
}
}
+#ifdef WXMAKINGDLL
+#ifndef __DARWIN__
+// we know it's there ;-)
+WXIMPORT char std::__throws_bad_alloc ;
+#endif
+#endif
bool wxApp::Initialize()
{
if ( error )
{
+ wxStAppResource resload ;
short itemHit;
Str255 message;
#endif // wxUSE_LOG
#endif
+ wxWinMacWindowList = new wxList(wxKEY_INTEGER);
+ wxWinMacControlList = new wxList(wxKEY_INTEGER);
+
wxInitializeStockLists();
wxInitializeStockObjects();
return FALSE;
}
- wxWinMacWindowList = new wxList(wxKEY_INTEGER);
- wxWinMacControlList = new wxList(wxKEY_INTEGER);
-
wxMacCreateNotifierTable() ;
UMAShowArrowCursor() ;
void wxApp::CleanUp()
{
+ wxToolTip::RemoveToolTips() ;
#if wxUSE_LOG
// flush the logged messages if any and install a 'safer' log target: the
// default one (wxLogGui) can't be used after the resources are freed just
if (wxWinMacWindowList)
delete wxWinMacWindowList ;
+ if (wxWinMacControlList)
+ delete wxWinMacControlList ;
+
delete wxPendingEvents;
#if wxUSE_THREADS
delete wxPendingEventsLocker;
UMACleanupToolbox() ;
if (s_macCursorRgn)
- ::DisposeRgn(s_macCursorRgn);
+ ::DisposeRgn((RgnHandle)s_macCursorRgn);
#if 0
TerminateAE() ;
// wxEntry
//----------------------------------------------------------------------
-int wxEntryStart( int argc, char *argv[] )
+short gCurrentResource = -1 ;
+
+wxStAppResource::wxStAppResource()
+{
+ m_currentRefNum = CurResFile() ;
+ if ( gCurrentResource != -1 )
+ {
+ UseResFile( gCurrentResource ) ;
+ }
+}
+
+wxStAppResource::~wxStAppResource()
+{
+ if ( m_currentRefNum != -1 )
+ {
+ UseResFile( m_currentRefNum ) ;
+ }
+}
+
+#ifdef WXMAKINGDLL
+
+// for shared libraries we have to manually get the correct resource ref num upon
+// initializing and releasing when terminating, therefore the __wxinitialize and __wxterminate
+// must be used
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void __sinit(void); /* (generated by linker) */
+pascal OSErr __initialize(const CFragInitBlock *theInitBlock);
+pascal void __terminate(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+pascal OSErr __wxinitialize(const CFragInitBlock *theInitBlock)
+{
+ gCurrentResource = -1;
+
+ if (theInitBlock->fragLocator.where == kDataForkCFragLocator) {
+ gCurrentResource =
+ FSpOpenResFile(theInitBlock->fragLocator.u.onDisk.fileSpec,
+ fsRdPerm);
+ }
+ return __initialize( theInitBlock ) ;
+}
+
+pascal void __wxterminate(void)
+{
+ if (gCurrentResource != -1)
+ CloseResFile(gCurrentResource);
+ __terminate() ;
+}
+#endif
+
+int WXDLLEXPORT wxEntryStart( int argc, char *argv[] )
{
return wxApp::Initialize();
}
-int wxEntryInitGui()
+int WXDLLEXPORT wxEntryInitGui()
{
return wxTheApp->OnInitGui();
}
-void wxEntryCleanup()
+void WXDLLEXPORT wxEntryCleanup()
{
wxApp::CleanUp();
}
int wxEntry( int argc, char *argv[] , bool enterLoop )
{
+ gCurrentResource = CurResFile() ;
#ifdef __MWERKS__
#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
// This seems to be necessary since there are 'rogue'
wxCHECK_MSG( wxTheApp, 0, wxT("You have to define an instance of wxApp!") );
-#ifdef __WXMAC__
- argc = 0 ; // currently we don't support files as parameters
+#ifndef __DARWIN__
+ argc = 0 ; // currently we don't support files as parameters
#endif
+ // we could try to get the open apple events here to adjust argc and argv better
- wxTheApp->argc = argc;
- wxTheApp->argv = argv;
-
- // GUI-specific initialization, such as creating an app context.
- wxEntryInitGui();
+ wxTheApp->argc = argc;
+ wxTheApp->argv = argv;
- // we could try to get the open apple events here to adjust argc and argv better
+ // GUI-specific initialization, such as creating an app context.
+ wxEntryInitGui();
- // Here frames insert themselves automatically
- // into wxTopLevelWindows by getting created
- // in OnInit().
+ // Here frames insert themselves automatically
+ // into wxTopLevelWindows by getting created
+ // in OnInit().
- int retValue = 0;
+ int retValue = 0;
if ( wxTheApp->OnInit() )
{
m_topWindow = NULL;
wxTheApp = this;
- m_wantDebugOutput = TRUE ;
+#if WXWIN_COMPATIBILITY_2_2
+ m_wantDebugOutput = TRUE;
+#endif
argc = 0;
argv = NULL;
long sleepTime = 1 ; //::GetCaretTime();
- while ( !wxTheApp->IsExiting() && WaitNextEvent(everyEvent, &event,sleepTime, wxApp::s_macCursorRgn))
+ while ( !wxTheApp->IsExiting() && WaitNextEvent(everyEvent, &event,sleepTime, (RgnHandle) wxApp::s_macCursorRgn))
{
wxTheApp->MacHandleOneEvent( &event );
if ( event.what != kHighLevelEvent )
- SetRectRgn( wxApp::s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ;
+ SetRectRgn( (RgnHandle) wxApp::s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ;
}
wxMacProcessNotifierAndPendingEvents() ;
void wxApp::MacSuspend( bool convertClipboard )
{
- // we have to deactive the window manually
+ // we have to deactive the top level windows manually
- wxWindow* window = GetTopWindow() ;
- if ( window )
- window->MacActivate( MacGetCurrentEvent() , false ) ;
+ wxNode* node = wxTopLevelWindows.First();
+ while (node)
+ {
+ wxTopLevelWindow* win = (wxTopLevelWindow*) node->Data();
+ win->MacActivate( MacGetCurrentEvent() , false ) ;
- s_lastMouseDown = 0 ;
- if( convertClipboard )
- {
- MacConvertPrivateToPublicScrap() ;
- }
+ node = node->Next();
+ }
+
+ s_lastMouseDown = 0 ;
+ if( convertClipboard )
+ {
+ MacConvertPrivateToPublicScrap() ;
+ }
- ::HideFloatingWindows() ;
+ ::HideFloatingWindows() ;
}
void wxApp::MacResume( bool convertClipboard )
long sleepTime = 1; // GetCaretTime() / 4 ;
- if (WaitNextEvent(everyEvent, &event, sleepTime, s_macCursorRgn))
+ if (WaitNextEvent(everyEvent, &event, sleepTime, (RgnHandle) s_macCursorRgn))
{
MacHandleOneEvent( &event );
}
wxTheApp->ProcessIdle() ;
}
if ( event.what != kHighLevelEvent )
- SetRectRgn( s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ;
+ SetRectRgn( (RgnHandle) s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ;
// repeaters
wxMacProcessNotifierAndPendingEvents() ;
}
-void wxApp::MacHandleOneEvent( EventRecord *ev )
+void wxApp::MacHandleOneEvent( WXEVENTREF evr )
{
+ EventRecord* ev = (EventRecord*) evr ;
m_macCurrentEvent = ev ;
wxApp::sm_lastMessageTime = ev->when ;
wxMacProcessNotifierAndPendingEvents() ;
}
-void wxApp::MacHandleHighLevelEvent( EventRecord *ev )
+void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr )
{
+ EventRecord* ev = (EventRecord*) evr ;
::AEProcessAppleEvent( ev ) ;
}
bool s_macIsInModalLoop = false ;
-void wxApp::MacHandleMouseDownEvent( EventRecord *ev )
+void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr )
{
+ EventRecord* ev = (EventRecord*) evr ;
wxToolTip::RemoveToolTips() ;
WindowRef window;
::GetWindowAttributes( frontWindow , &frontWindowAttributes ) ;
short windowPart = ::FindWindow(ev->where, &window);
- wxWindow* win = wxFindWinFromMacWindow( window ) ;
+ wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ;
if ( wxPendingDelete.Member(win) )
return ;
GrafPtr port ;
GetPort( &port ) ;
Point pt = { 0, 0 } ;
- #if TARGET_CARBON
- SetPort( GetWindowPort(window) ) ;
- #else
- SetPort( (window) ) ;
- #endif
- SetOrigin( 0 , 0 ) ;
+ SetPortWindowPort(window) ;
LocalToGlobal( &pt ) ;
SetPort( port ) ;
win->SetSize( pt.h , pt.v , -1 ,
{
GrafPtr port ;
GetPort( &port ) ;
- #if TARGET_CARBON
- SetPort( GetWindowPort(window) ) ;
- #else
- SetPort( (window) ) ;
- #endif
- SetOrigin( 0 , 0 ) ;
+ SetPortWindowPort(window) ;
SetPort( port ) ;
}
if ( window != frontWindow && wxTheApp->s_captureWindow == NULL )
}
}
-void wxApp::MacHandleMouseUpEvent( EventRecord *ev )
+void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr )
{
+ EventRecord* ev = (EventRecord*) evr ;
WindowRef window;
- short windowPart = ::FindWindow(ev->where, &window);
+ short windowPart = inNoWindow ;
+ if ( wxTheApp->s_captureWindow )
+ {
+ window = (WindowRef) s_captureWindow->MacGetRootWindow() ;
+ windowPart = inContent ;
+ }
+ else
+ {
+ windowPart = ::FindWindow(ev->where, &window) ;
+ }
switch (windowPart)
{
break ;
default:
{
- wxWindow* win = wxFindWinFromMacWindow( window ) ;
+ wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ;
if ( win )
win->MacMouseUp( ev , windowPart ) ;
}
return retval;
}
-void wxApp::MacHandleKeyDownEvent( EventRecord *ev )
+void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr )
{
+ EventRecord* ev = (EventRecord*) evr ;
wxToolTip::RemoveToolTips() ;
UInt32 menuresult = UMAMenuEvent(ev) ;
short keychar ;
keychar = short(ev->message & charCodeMask);
keycode = short(ev->message & keyCodeMask) >> 8 ;
-
+ long keyval = wxMacTranslateKey(keychar, keycode) ;
+ bool handled = false ;
wxWindow* focus = wxWindow::FindFocus() ;
if ( focus )
{
- long keyval = wxMacTranslateKey(keychar, keycode) ;
wxKeyEvent event(wxEVT_KEY_DOWN);
event.m_shiftDown = ev->modifiers & shiftKey;
event.m_y = ev->where.v;
event.m_timeStamp = ev->when;
event.SetEventObject(focus);
- bool handled = focus->GetEventHandler()->ProcessEvent( event ) ;
+ handled = focus->GetEventHandler()->ProcessEvent( event ) ;
if ( !handled )
{
#if wxUSE_ACCEL
new_event.SetCurrentFocus( focus );
handled = focus->GetEventHandler()->ProcessEvent( new_event );
}
+ }
+ if ( !handled )
+ {
+ // if window is not having a focus still testing for default enter or cancel
+ // TODO add the UMA version for ActiveNonFloatingWindow
+ focus = wxFindWinFromMacWindow( FrontWindow() ) ;
+ if ( focus )
+ {
+ if ( keyval == WXK_RETURN )
+ {
+ wxButton *def = wxDynamicCast(focus->GetDefaultItem(),
+ wxButton);
+ if ( def && def->IsEnabled() )
+ {
+ wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
+ event.SetEventObject(def);
+ def->Command(event);
+ return ;
+ }
+ }
/* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
- if ( (!handled) &&
- (keyval == '.' && event.ControlDown() ) )
+ else if (keyval == WXK_ESCAPE || (keyval == '.' && ev->modifiers & cmdKey ) )
{
- wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);
- new_event.SetEventObject( focus );
- handled = focus->GetEventHandler()->ProcessEvent( new_event );
+ wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);
+ new_event.SetEventObject( focus );
+ handled = focus->GetEventHandler()->ProcessEvent( new_event );
}
+ }
}
}
}
-void wxApp::MacHandleKeyUpEvent( EventRecord *ev )
+void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr )
{
+ EventRecord* ev = (EventRecord*) evr ;
wxToolTip::RemoveToolTips() ;
UInt32 menuresult = UMAMenuEvent(ev) ;
}
}
-void wxApp::MacHandleActivateEvent( EventRecord *ev )
+void wxApp::MacHandleActivateEvent( WXEVENTREF evr )
{
+ EventRecord* ev = (EventRecord*) evr ;
WindowRef window = (WindowRef) ev->message ;
if ( window )
{
// if it is a floater we activate/deactivate the front non-floating window instead
window = ::FrontNonFloatingWindow() ;
}
- wxWindow* win = wxFindWinFromMacWindow( window ) ;
+ wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ;
if ( win )
win->MacActivate( ev , activate ) ;
}
}
-void wxApp::MacHandleUpdateEvent( EventRecord *ev )
+void wxApp::MacHandleUpdateEvent( WXEVENTREF evr )
{
+ EventRecord* ev = (EventRecord*) evr ;
WindowRef window = (WindowRef) ev->message ;
- wxWindow * win = wxFindWinFromMacWindow( window ) ;
+ wxTopLevelWindowMac * win = wxFindWinFromMacWindow( window ) ;
if ( win )
{
if ( !wxPendingDelete.Member(win) )
- win->MacUpdate( ev ) ;
+ win->MacUpdate( ev->when ) ;
}
else
{
}
}
-void wxApp::MacHandleDiskEvent( EventRecord *ev )
+void wxApp::MacHandleDiskEvent( WXEVENTREF evr )
{
+ EventRecord* ev = (EventRecord*) evr ;
if ( HiWord( ev->message ) != noErr )
{
#if !TARGET_CARBON
}
}
-void wxApp::MacHandleOSEvent( EventRecord *ev )
+void wxApp::MacHandleOSEvent( WXEVENTREF evr )
{
+ EventRecord* ev = (EventRecord*) evr ;
switch( ( ev->message & osEvtMessageMask ) >> 24 )
{
case suspendResumeMessage :
if ( oldFrontWindow )
{
- wxWindow* win = wxFindWinFromMacWindow( oldFrontWindow ) ;
+ wxTopLevelWindowMac* win = wxFindWinFromMacWindow( oldFrontWindow ) ;
if ( win )
win->MacActivate( ev , false ) ;
}
if ( newFrontWindow )
{
- wxWindow* win = wxFindWinFromMacWindow( newFrontWindow ) ;
+ wxTopLevelWindowMac* win = wxFindWinFromMacWindow( newFrontWindow ) ;
if ( win )
win->MacActivate( ev , true ) ;
}
wxWindow::MacGetWindowFromPoint( wxPoint( ev->where.h , ev->where.v ) ,
¤tMouseWindow ) ;
-
if ( currentMouseWindow != wxWindow::s_lastMouseWindow )
{
wxMouseEvent event ;
event.m_y = ev->where.v;
event.m_timeStamp = ev->when;
event.SetEventObject(this);
-
+
if ( wxWindow::s_lastMouseWindow )
{
- wxMouseEvent eventleave(event ) ;
- eventleave.SetEventType( wxEVT_LEAVE_WINDOW ) ;
+ wxMouseEvent eventleave(event);
+ eventleave.SetEventType( wxEVT_LEAVE_WINDOW );
+ wxWindow::s_lastMouseWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y );
+
wxWindow::s_lastMouseWindow->GetEventHandler()->ProcessEvent(eventleave);
}
if ( currentMouseWindow )
{
- wxMouseEvent evententer(event ) ;
- evententer.SetEventType( wxEVT_ENTER_WINDOW ) ;
+ wxMouseEvent evententer(event);
+ evententer.SetEventType( wxEVT_ENTER_WINDOW );
+ currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y );
+
currentMouseWindow->GetEventHandler()->ProcessEvent(evententer);
}
wxWindow::s_lastMouseWindow = currentMouseWindow ;
::GetNextEvent(0, &tmp);
ev->modifiers = tmp.modifiers;
- wxWindow* win = wxFindWinFromMacWindow( window ) ;
+ wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ;
if ( win )
win->MacMouseMoved( ev , windowPart ) ;
else