carbon event support completed

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@19016 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2003-01-29 15:23:01 +00:00
parent ac9b5f9889
commit c5c9378c98
8 changed files with 798 additions and 808 deletions

View File

@@ -70,12 +70,21 @@
# include <Devices.h> # include <Devices.h>
#endif #endif
extern char *wxBuffer;
extern wxList wxPendingDelete; extern wxList wxPendingDelete;
extern wxList *wxWinMacWindowList; extern wxList *wxWinMacWindowList;
extern wxList *wxWinMacControlList; extern wxList *wxWinMacControlList;
// statics for implementation
static bool s_inYield = FALSE; static bool s_inYield = FALSE;
static bool s_inOnIdle = FALSE;
#if TARGET_CARBON
static bool s_inReceiveEvent = FALSE ;
static EventTime sleepTime = kEventDurationNoWait ;
#else
static long sleepTime = 0 ;
#endif
wxApp *wxTheApp = NULL; wxApp *wxTheApp = NULL;
@@ -218,12 +227,13 @@ short wxApp::MacHandleAEOApp(const WXEVENTREF WXUNUSED(event) , WXEVENTREF WXUNU
short wxApp::MacHandleAEQuit(const WXEVENTREF WXUNUSED(event) , WXEVENTREF WXUNUSED(reply)) short wxApp::MacHandleAEQuit(const WXEVENTREF WXUNUSED(event) , WXEVENTREF WXUNUSED(reply))
{ {
wxWindow* win = GetTopWindow() ; /* wxWindow* win = GetTopWindow() ;
if ( win ) if ( win )
{ {
win->Close(TRUE ) ; win->Close(TRUE ) ;
} }
else else
*/
{ {
ExitMainLoop() ; ExitMainLoop() ;
} }
@@ -273,218 +283,6 @@ void wxApp::MacNewFile()
{ {
} }
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"
"\xc0\xc1\xc2\xc4\xc7\xc8\xc9\xcb\xcc\xcd\xce\xcf"
"\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xca\xdb" ;
char StringANSI[] = "\x0a\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8"
"\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC"
"\x86\xBA\xA2\xA3\xA7\x95\xB6\xDF\xAE\xA9\x99\xB4\xA8\xC6\xD8"
"\xB1\xA5\xB5\xF0\xAA\xBA\xE6\xF8"
"\xBF\xA1\xAC\x83\xAB\xBB\x85\xC0\xC3\xD5\x8C\x9C"
"\x96\x97\x93\x94\x91\x92\xF7\xFF\xA0\x80" ;
void wxMacConvertFromPC( const char *from , char *to , int len )
{
char *c ;
if ( from == to )
{
for( int i = 0 ; i < len ; ++ i )
{
c = strchr( StringANSI , *from ) ;
if ( c != NULL )
{
*to = StringMac[ c - StringANSI] ;
}
++to ;
++from ;
}
}
else
{
for( int i = 0 ; i < len ; ++ i )
{
c = strchr( StringANSI , *from ) ;
if ( c != NULL )
{
*to = StringMac[ c - StringANSI] ;
}
else
{
*to = *from ;
}
++to ;
++from ;
}
}
}
void wxMacConvertToPC( const char *from , char *to , int len )
{
char *c ;
if ( from == to )
{
for( int i = 0 ; i < len ; ++ i )
{
c = strchr( StringMac , *from ) ;
if ( c != NULL )
{
*to = StringANSI[ c - StringMac] ;
}
++to ;
++from ;
}
}
else
{
for( int i = 0 ; i < len ; ++ i )
{
c = strchr( StringMac , *from ) ;
if ( c != NULL )
{
*to = StringANSI[ c - StringMac] ;
}
else
{
*to = *from ;
}
++to ;
++from ;
}
}
}
void wxMacConvertFromPC( char * p )
{
char *ptr = p ;
int len = strlen ( p ) ;
wxMacConvertFromPC( ptr , ptr , len ) ;
}
void wxMacConvertFromPCForControls( char * p )
{
char *ptr = p ;
int len = strlen ( p ) ;
wxMacConvertFromPC( ptr , ptr , len ) ;
for ( unsigned int i = 0 ; i < strlen ( ptr ) ; i++ )
{
if ( ptr[i] == '&' && ptr[i]+1 != ' ' )
{
memmove( &ptr[i] , &ptr[i+1] , strlen( &ptr[i+1] ) + 1) ;
}
}
}
void wxMacConvertFromPC( unsigned char *p )
{
char *ptr = (char*) p + 1 ;
int len = p[0] ;
wxMacConvertFromPC( ptr , ptr , len ) ;
}
extern char *wxBuffer ;
wxString wxMacMakeMacStringFromPC( const char * p )
{
const char *ptr = p ;
int len = strlen ( p ) ;
char *buf = wxBuffer ;
if ( len >= BUFSIZ + 512 )
{
buf = new char [len+1] ;
}
wxMacConvertFromPC( ptr , buf , len ) ;
buf[len] = 0 ;
wxString result( buf ) ;
if ( buf != wxBuffer )
delete buf ;
return result ;
}
void wxMacConvertToPC( char * p )
{
char *ptr = p ;
int len = strlen ( p ) ;
wxMacConvertToPC( ptr , ptr , len ) ;
}
void wxMacConvertToPC( unsigned char *p )
{
char *ptr = (char*) p + 1 ;
int len = p[0] ;
wxMacConvertToPC( ptr , ptr , len ) ;
}
wxString wxMacMakePCStringFromMac( const char * p )
{
const char *ptr = p ;
int len = strlen ( p ) ;
char *buf = wxBuffer ;
if ( len >= BUFSIZ + 512 )
{
buf = new char [len+1] ;
}
wxMacConvertToPC( ptr , buf , len ) ;
buf[len] = 0 ;
wxString result( buf ) ;
if ( buf != wxBuffer )
delete buf ;
return result ;
}
wxString wxMacMakeStringFromMacString( const char* from , bool mac2pcEncoding )
{
if (mac2pcEncoding)
{
return wxMacMakePCStringFromMac( from ) ;
}
else
{
return wxString( from ) ;
}
}
wxString wxMacMakeStringFromPascal( StringPtr from , bool mac2pcEncoding )
{
// this is safe since a pascal string can never be larger than 256 bytes
char s[256] ;
CopyPascalStringToC( from , s ) ;
if (mac2pcEncoding)
{
return wxMacMakePCStringFromMac( s ) ;
}
else
{
return wxString( s ) ;
}
}
void wxMacStringToPascal( const char * from , StringPtr to , bool pc2macEncoding )
{
if (pc2macEncoding)
{
CopyCStringToPascal( wxMacMakeMacStringFromPC( from ) , to ) ;
}
else
{
CopyCStringToPascal( from , to ) ;
}
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// Carbon Event Handler // Carbon Event Handler
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@@ -495,10 +293,54 @@ void wxMacStringToPascal( const char * from , StringPtr to , bool pc2macEncoding
{ {
{ kEventClassCommand, kEventProcessCommand } , { kEventClassCommand, kEventProcessCommand } ,
{ kEventClassCommand, kEventCommandUpdateStatus } , { kEventClassCommand, kEventCommandUpdateStatus } ,
{ kEventClassApplication , kEventAppActivated } , { kEventClassApplication , kEventAppActivated } ,
{ kEventClassApplication , kEventAppDeactivated } , { kEventClassApplication , kEventAppDeactivated } ,
// handling the quit event is not recommended by apple
// rather using the quit apple event - which we do
{ kEventClassMouse , kEventMouseDown } ,
} ; } ;
static pascal OSStatus MenuEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
{
OSStatus result = eventNotHandledErr ;
UInt32 kind = GetEventKind( event ) ;
return result ;
}
// due to the rather low-level event API of wxWindows, we cannot use RunApplicationEventLoop
// but have to use ReceiveNextEvent dealing with events manually, therefore we also have
// deal with clicks in the menu bar explicitely
static pascal OSStatus MouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
{
OSStatus result = eventNotHandledErr ;
switch( GetEventKind(event) )
{
case kEventMouseDown :
{
Point point ;
WindowRef window ;
GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL,
sizeof( Point ), NULL, &point );
short windowPart = ::FindWindow(point, &window);
if ( windowPart == inMenuBar )
{
MenuSelect( point ) ;
result = noErr ;
}
}
break ;
}
return result ;
}
static pascal OSStatus CommandEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) static pascal OSStatus CommandEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
{ {
OSStatus result = eventNotHandledErr ; OSStatus result = eventNotHandledErr ;
@@ -580,7 +422,12 @@ pascal OSStatus wxAppEventHandler( EventHandlerCallRef handler , EventRef event
case kEventClassApplication : case kEventClassApplication :
result = ApplicationEventHandler( handler , event , data ) ; result = ApplicationEventHandler( handler , event , data ) ;
break ; break ;
case kEventClassMenu :
result = MenuEventHandler( handler , event , data ) ;
break ;
case kEventClassMouse :
result = MouseEventHandler( handler , event , data ) ;
break ;
default : default :
break ; break ;
} }
@@ -684,8 +531,6 @@ bool wxApp::Initialize()
s_macCursorRgn = ::NewRgn() ; s_macCursorRgn = ::NewRgn() ;
wxBuffer = new char[BUFSIZ + 512];
wxClassInfo::InitializeClasses(); wxClassInfo::InitializeClasses();
#if wxUSE_RESOURCES #if wxUSE_RESOURCES
@@ -742,6 +587,8 @@ bool wxApp::OnInitGui()
return false ; return false ;
#if TARGET_CARBON #if TARGET_CARBON
InstallStandardEventHandler( GetApplicationEventTarget() ) ;
InstallApplicationEventHandler( InstallApplicationEventHandler(
GetwxAppEventHandlerUPP(), GetwxAppEventHandlerUPP(),
GetEventTypeCount(eventList), eventList, wxTheApp, &((EventHandlerRef)wxTheApp->m_macEventHandler)); GetEventTypeCount(eventList), eventList, wxTheApp, &((EventHandlerRef)wxTheApp->m_macEventHandler));
@@ -811,9 +658,6 @@ void wxApp::CleanUp()
wxBitmap::CleanUpHandlers(); wxBitmap::CleanUpHandlers();
delete[] wxBuffer;
wxBuffer = NULL;
wxMacDestroyNotifierTable() ; wxMacDestroyNotifierTable() ;
if (wxWinMacWindowList) { if (wxWinMacWindowList) {
delete wxWinMacWindowList ; delete wxWinMacWindowList ;
@@ -1317,15 +1161,26 @@ bool wxApp::ProcessIdle()
void wxApp::ExitMainLoop() void wxApp::ExitMainLoop()
{ {
m_keepGoing = FALSE; #if TARGET_CARBON
if (s_inReceiveEvent)
QuitApplicationEventLoop() ;
else
m_keepGoing = FALSE;
#else
m_keepGoing = FALSE;
#endif
} }
// Is a message/event pending? // Is a message/event pending?
bool wxApp::Pending() bool wxApp::Pending()
{ {
#if TARGET_CARBON
return GetNumEventsInQueue( GetMainEventQueue() ) > 0 ;
#else
EventRecord event ; EventRecord event ;
return EventAvail( everyEvent , &event ) ; return EventAvail( everyEvent , &event ) ;
#endif
} }
// Dispatch a message. // Dispatch a message.
@@ -1336,8 +1191,6 @@ void wxApp::Dispatch()
void wxApp::OnIdle(wxIdleEvent& event) void wxApp::OnIdle(wxIdleEvent& event)
{ {
static bool s_inOnIdle = FALSE;
// Avoid recursion (via ProcessEvent default case) // Avoid recursion (via ProcessEvent default case)
if ( s_inOnIdle ) if ( s_inOnIdle )
return; return;
@@ -1480,21 +1333,51 @@ bool wxApp::Yield(bool onlyIfNeeded)
#if wxUSE_THREADS #if wxUSE_THREADS
YieldToAnyThread() ; YieldToAnyThread() ;
#endif #endif
// by definition yield should handle all non-processed events
#if TARGET_CARBON
EventRef theEvent;
OSStatus status = noErr ;
do
{
s_inReceiveEvent = true ;
status = ReceiveNextEvent(0, NULL,kEventDurationNoWait,true,&theEvent) ;
s_inReceiveEvent = false ;
if ( status == eventLoopTimedOutErr )
{
// make sure next time the event loop will trigger idle events
sleepTime = kEventDurationNoWait ;
}
else if ( status == eventLoopQuitErr )
{
m_keepGoing = false ;
}
else
{
MacHandleOneEvent( theEvent ) ;
ReleaseEvent(theEvent);
}
} while( status == noErr ) ;
#else
EventRecord event ; EventRecord event ;
long sleepTime = 1 ; //::GetCaretTime(); // having a larger value here leads to large performance slowdowns
// so we cannot give background apps more processor time here
// we do so however having a large sleep value in the main event loop
long sleepTime = 0 ;
while ( !wxTheApp->IsExiting() && WaitNextEvent(everyEvent, &event,sleepTime, (RgnHandle) wxApp::s_macCursorRgn)) while ( !IsExiting() && WaitNextEvent(everyEvent, &event,sleepTime, (RgnHandle) wxApp::s_macCursorRgn))
{ {
wxTheApp->MacHandleModifierEvents( &event ) ; MacHandleModifierEvents( &event ) ;
wxTheApp->MacHandleOneEvent( &event ); MacHandleOneEvent( &event );
if ( event.what != kHighLevelEvent ) if ( event.what != kHighLevelEvent )
SetRectRgn( (RgnHandle) 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 ) ;
} }
wxTheApp->MacHandleModifierEvents( &event ) ; MacHandleModifierEvents( &event ) ;
#endif
wxMacProcessNotifierAndPendingEvents() ; wxMacProcessNotifierAndPendingEvents() ;
s_inYield = FALSE; s_inYield = FALSE;
return TRUE; return TRUE;
@@ -1561,11 +1444,34 @@ void wxApp::MacConvertPublicToPrivateScrap()
void wxApp::MacDoOneEvent() void wxApp::MacDoOneEvent()
{ {
EventRecord event ; #if TARGET_CARBON
EventRef theEvent;
long sleepTime = 1; // GetCaretTime() / 4 ; s_inReceiveEvent = true ;
OSStatus status = ReceiveNextEvent(0, NULL,sleepTime,true,&theEvent) ;
s_inReceiveEvent = false ;
if ( status == eventLoopTimedOutErr )
{
if ( wxTheApp->ProcessIdle() )
sleepTime = kEventDurationNoWait ;
else
sleepTime = kEventDurationForever ;
}
else if ( status == eventLoopQuitErr )
{
m_keepGoing = false ;
}
else
{
MacHandleOneEvent( theEvent ) ;
ReleaseEvent(theEvent);
}
#else
EventRecord event ;
if (WaitNextEvent(everyEvent, &event, sleepTime, (RgnHandle) s_macCursorRgn)) EventMask eventMask = everyEvent ;
if (WaitNextEvent(eventMask, &event, sleepTime, (RgnHandle) s_macCursorRgn))
{ {
MacHandleModifierEvents( &event ) ; MacHandleModifierEvents( &event ) ;
MacHandleOneEvent( &event ); MacHandleOneEvent( &event );
@@ -1578,37 +1484,89 @@ void wxApp::MacDoOneEvent()
if ( window ) if ( window )
::IdleControls( window ) ; ::IdleControls( window ) ;
wxTheApp->ProcessIdle() ; if ( wxTheApp->ProcessIdle() )
sleepTime = 0 ;
else
sleepTime = GetCaretTime() / 2 ;
} }
if ( event.what != kHighLevelEvent ) if ( event.what != kHighLevelEvent )
SetRectRgn( (RgnHandle) 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 ) ;
#endif
// repeaters // repeaters
DeletePendingObjects() ; DeletePendingObjects() ;
wxMacProcessNotifierAndPendingEvents() ; wxMacProcessNotifierAndPendingEvents() ;
} }
void wxApp::MacHandleOneEvent( WXEVENTREF evr )
{
#if TARGET_CARBON
EventTargetRef theTarget;
theTarget = GetEventDispatcherTarget();
m_macCurrentEvent = evr ;
SendEventToEventTarget ((EventRef) evr , theTarget);
#else
EventRecord* ev = (EventRecord*) evr ;
m_macCurrentEvent = ev ;
wxApp::sm_lastMessageTime = ev->when ;
switch (ev->what)
{
case mouseDown:
MacHandleMouseDownEvent( ev ) ;
if ( ev->modifiers & controlKey )
s_lastMouseDown = 2;
else
s_lastMouseDown = 1;
break;
case mouseUp:
if ( s_lastMouseDown == 2 )
{
ev->modifiers |= controlKey ;
}
else
{
ev->modifiers &= ~controlKey ;
}
MacHandleMouseUpEvent( ev ) ;
s_lastMouseDown = 0;
break;
case activateEvt:
MacHandleActivateEvent( ev ) ;
break;
case updateEvt:
MacHandleUpdateEvent( ev ) ;
break;
case keyDown:
case autoKey:
MacHandleKeyDownEvent( ev ) ;
break;
case keyUp:
MacHandleKeyUpEvent( ev ) ;
break;
case diskEvt:
MacHandleDiskEvent( ev ) ;
break;
case osEvt:
MacHandleOSEvent( ev ) ;
break;
case kHighLevelEvent:
MacHandleHighLevelEvent( ev ) ;
break;
default:
break;
}
#endif
wxMacProcessNotifierAndPendingEvents() ;
}
#if !TARGET_CARBON
bool s_macIsInModalLoop = false ;
void wxApp::MacHandleModifierEvents( WXEVENTREF evr ) void wxApp::MacHandleModifierEvents( WXEVENTREF evr )
{ {
EventRecord* ev = (EventRecord*) evr ; EventRecord* ev = (EventRecord*) evr ;
#if TARGET_CARBON
if ( ev->what == mouseDown || ev->what == mouseUp || ev->what == activateEvt ||
ev->what == keyDown || ev->what == autoKey || ev->what == keyUp || ev->what == kHighLevelEvent ||
ev->what == nullEvent
)
{
// in these cases the modifiers are already correctly setup by carbon
}
else
{
EventRecord nev ;
WaitNextEvent( 0 , &nev , 0 , NULL ) ;
ev->modifiers = nev.modifiers ;
// KeyModifiers unfortunately don't include btnState...
// ev->modifiers = GetCurrentKeyModifiers() ;
}
#endif
if ( ev->modifiers != s_lastModifiers && wxWindow::FindFocus() != NULL ) if ( ev->modifiers != s_lastModifiers && wxWindow::FindFocus() != NULL )
{ {
wxKeyEvent event(wxEVT_KEY_DOWN); wxKeyEvent event(wxEVT_KEY_DOWN);
@@ -1646,66 +1604,6 @@ void wxApp::MacHandleModifierEvents( WXEVENTREF evr )
} }
} }
void wxApp::MacHandleOneEvent( WXEVENTREF evr )
{
EventRecord* ev = (EventRecord*) evr ;
m_macCurrentEvent = ev ;
wxApp::sm_lastMessageTime = ev->when ;
switch (ev->what)
{
case mouseDown:
MacHandleMouseDownEvent( ev ) ;
if ( ev->modifiers & controlKey )
s_lastMouseDown = 2;
else
s_lastMouseDown = 1;
break;
#if !TARGET_CARBON
case mouseUp:
if ( s_lastMouseDown == 2 )
{
ev->modifiers |= controlKey ;
}
else
{
ev->modifiers &= ~controlKey ;
}
MacHandleMouseUpEvent( ev ) ;
s_lastMouseDown = 0;
break;
case activateEvt:
MacHandleActivateEvent( ev ) ;
break;
case updateEvt:
MacHandleUpdateEvent( ev ) ;
break;
#endif
case keyDown:
case autoKey:
MacHandleKeyDownEvent( ev ) ;
break;
case keyUp:
MacHandleKeyUpEvent( ev ) ;
break;
#if !TARGET_CARBON
case diskEvt:
MacHandleDiskEvent( ev ) ;
break;
case osEvt:
MacHandleOSEvent( ev ) ;
break;
#endif
case kHighLevelEvent:
MacHandleHighLevelEvent( ev ) ;
break;
default:
break;
}
wxMacProcessNotifierAndPendingEvents() ;
}
void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr ) void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr )
{ {
// we must avoid reentrancy problems when processing high level events eg printing // we must avoid reentrancy problems when processing high level events eg printing
@@ -1716,8 +1614,6 @@ void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr )
s_inYield = former ; s_inYield = former ;
} }
bool s_macIsInModalLoop = false ;
void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr ) void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr )
{ {
EventRecord* ev = (EventRecord*) evr ; EventRecord* ev = (EventRecord*) evr ;
@@ -1747,13 +1643,10 @@ void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr )
else else
{ {
UInt32 menuresult = MenuSelect(ev->where) ; UInt32 menuresult = MenuSelect(ev->where) ;
#if !TARGET_CARBON
MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) ); MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) );
#endif
s_lastMouseDown = 0; s_lastMouseDown = 0;
} }
break ; break ;
#if !TARGET_CARBON
case inSysWindow : case inSysWindow :
SystemClick( ev , window ) ; SystemClick( ev , window ) ;
s_lastMouseDown = 0; s_lastMouseDown = 0;
@@ -1875,14 +1768,11 @@ void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr )
win->MacMouseDown( ev , windowPart ) ; win->MacMouseDown( ev , windowPart ) ;
} }
break ; break ;
#endif
default: default:
break; break;
} }
} }
#if !TARGET_CARBON
void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr ) void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr )
{ {
EventRecord* ev = (EventRecord*) evr ; EventRecord* ev = (EventRecord*) evr ;
@@ -2026,12 +1916,12 @@ long wxMacTranslateKey(unsigned char key, unsigned char code)
return retval; return retval;
} }
#if !TARGET_CARBON
void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr ) void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr )
{ {
EventRecord* ev = (EventRecord*) evr ; EventRecord* ev = (EventRecord*) evr ;
wxToolTip::RemoveToolTips() ; wxToolTip::RemoveToolTips() ;
#if !TARGET_CARBON
UInt32 menuresult = UMAMenuEvent(ev) ; UInt32 menuresult = UMAMenuEvent(ev) ;
if ( HiWord( menuresult ) ) if ( HiWord( menuresult ) )
{ {
@@ -2039,7 +1929,6 @@ void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr )
MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) ) ; MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) ) ;
} }
else else
#endif
{ {
wxWindow* focus = wxWindow::FindFocus() ; wxWindow* focus = wxWindow::FindFocus() ;
@@ -2059,6 +1948,23 @@ void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr )
} }
} }
void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr )
{
EventRecord* ev = (EventRecord*) evr ;
wxToolTip::RemoveToolTips() ;
UInt32 menuresult = UMAMenuEvent(ev) ;
if ( HiWord( menuresult ) )
{
}
else
{
MacSendKeyUpEvent( wxWindow::FindFocus() , ev->message , ev->modifiers , ev->when , ev->where.h , ev->where.v ) ;
}
}
#endif
bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey ) bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey )
{ {
if ( !focus ) if ( !focus )
@@ -2189,22 +2095,6 @@ bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifi
return handled ; return handled ;
} }
void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr )
{
EventRecord* ev = (EventRecord*) evr ;
wxToolTip::RemoveToolTips() ;
UInt32 menuresult = UMAMenuEvent(ev) ;
if ( HiWord( menuresult ) )
{
}
else
{
MacSendKeyUpEvent( wxWindow::FindFocus() , ev->message , ev->modifiers , ev->when , ev->where.h , ev->where.v ) ;
}
}
bool wxApp::MacSendKeyUpEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey ) bool wxApp::MacSendKeyUpEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey )
{ {
if ( !focus ) if ( !focus )
@@ -2246,6 +2136,7 @@ bool wxApp::MacSendKeyUpEvent( wxWindow* focus , long keymessage , long modifier
return handled ; return handled ;
} }
#if !TARGET_CARBON #if !TARGET_CARBON
void wxApp::MacHandleActivateEvent( WXEVENTREF evr ) void wxApp::MacHandleActivateEvent( WXEVENTREF evr )
{ {

View File

@@ -70,12 +70,21 @@
# include <Devices.h> # include <Devices.h>
#endif #endif
extern char *wxBuffer;
extern wxList wxPendingDelete; extern wxList wxPendingDelete;
extern wxList *wxWinMacWindowList; extern wxList *wxWinMacWindowList;
extern wxList *wxWinMacControlList; extern wxList *wxWinMacControlList;
// statics for implementation
static bool s_inYield = FALSE; static bool s_inYield = FALSE;
static bool s_inOnIdle = FALSE;
#if TARGET_CARBON
static bool s_inReceiveEvent = FALSE ;
static EventTime sleepTime = kEventDurationNoWait ;
#else
static long sleepTime = 0 ;
#endif
wxApp *wxTheApp = NULL; wxApp *wxTheApp = NULL;
@@ -218,12 +227,13 @@ short wxApp::MacHandleAEOApp(const WXEVENTREF WXUNUSED(event) , WXEVENTREF WXUNU
short wxApp::MacHandleAEQuit(const WXEVENTREF WXUNUSED(event) , WXEVENTREF WXUNUSED(reply)) short wxApp::MacHandleAEQuit(const WXEVENTREF WXUNUSED(event) , WXEVENTREF WXUNUSED(reply))
{ {
wxWindow* win = GetTopWindow() ; /* wxWindow* win = GetTopWindow() ;
if ( win ) if ( win )
{ {
win->Close(TRUE ) ; win->Close(TRUE ) ;
} }
else else
*/
{ {
ExitMainLoop() ; ExitMainLoop() ;
} }
@@ -273,218 +283,6 @@ void wxApp::MacNewFile()
{ {
} }
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"
"\xc0\xc1\xc2\xc4\xc7\xc8\xc9\xcb\xcc\xcd\xce\xcf"
"\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xca\xdb" ;
char StringANSI[] = "\x0a\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8"
"\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC"
"\x86\xBA\xA2\xA3\xA7\x95\xB6\xDF\xAE\xA9\x99\xB4\xA8\xC6\xD8"
"\xB1\xA5\xB5\xF0\xAA\xBA\xE6\xF8"
"\xBF\xA1\xAC\x83\xAB\xBB\x85\xC0\xC3\xD5\x8C\x9C"
"\x96\x97\x93\x94\x91\x92\xF7\xFF\xA0\x80" ;
void wxMacConvertFromPC( const char *from , char *to , int len )
{
char *c ;
if ( from == to )
{
for( int i = 0 ; i < len ; ++ i )
{
c = strchr( StringANSI , *from ) ;
if ( c != NULL )
{
*to = StringMac[ c - StringANSI] ;
}
++to ;
++from ;
}
}
else
{
for( int i = 0 ; i < len ; ++ i )
{
c = strchr( StringANSI , *from ) ;
if ( c != NULL )
{
*to = StringMac[ c - StringANSI] ;
}
else
{
*to = *from ;
}
++to ;
++from ;
}
}
}
void wxMacConvertToPC( const char *from , char *to , int len )
{
char *c ;
if ( from == to )
{
for( int i = 0 ; i < len ; ++ i )
{
c = strchr( StringMac , *from ) ;
if ( c != NULL )
{
*to = StringANSI[ c - StringMac] ;
}
++to ;
++from ;
}
}
else
{
for( int i = 0 ; i < len ; ++ i )
{
c = strchr( StringMac , *from ) ;
if ( c != NULL )
{
*to = StringANSI[ c - StringMac] ;
}
else
{
*to = *from ;
}
++to ;
++from ;
}
}
}
void wxMacConvertFromPC( char * p )
{
char *ptr = p ;
int len = strlen ( p ) ;
wxMacConvertFromPC( ptr , ptr , len ) ;
}
void wxMacConvertFromPCForControls( char * p )
{
char *ptr = p ;
int len = strlen ( p ) ;
wxMacConvertFromPC( ptr , ptr , len ) ;
for ( unsigned int i = 0 ; i < strlen ( ptr ) ; i++ )
{
if ( ptr[i] == '&' && ptr[i]+1 != ' ' )
{
memmove( &ptr[i] , &ptr[i+1] , strlen( &ptr[i+1] ) + 1) ;
}
}
}
void wxMacConvertFromPC( unsigned char *p )
{
char *ptr = (char*) p + 1 ;
int len = p[0] ;
wxMacConvertFromPC( ptr , ptr , len ) ;
}
extern char *wxBuffer ;
wxString wxMacMakeMacStringFromPC( const char * p )
{
const char *ptr = p ;
int len = strlen ( p ) ;
char *buf = wxBuffer ;
if ( len >= BUFSIZ + 512 )
{
buf = new char [len+1] ;
}
wxMacConvertFromPC( ptr , buf , len ) ;
buf[len] = 0 ;
wxString result( buf ) ;
if ( buf != wxBuffer )
delete buf ;
return result ;
}
void wxMacConvertToPC( char * p )
{
char *ptr = p ;
int len = strlen ( p ) ;
wxMacConvertToPC( ptr , ptr , len ) ;
}
void wxMacConvertToPC( unsigned char *p )
{
char *ptr = (char*) p + 1 ;
int len = p[0] ;
wxMacConvertToPC( ptr , ptr , len ) ;
}
wxString wxMacMakePCStringFromMac( const char * p )
{
const char *ptr = p ;
int len = strlen ( p ) ;
char *buf = wxBuffer ;
if ( len >= BUFSIZ + 512 )
{
buf = new char [len+1] ;
}
wxMacConvertToPC( ptr , buf , len ) ;
buf[len] = 0 ;
wxString result( buf ) ;
if ( buf != wxBuffer )
delete buf ;
return result ;
}
wxString wxMacMakeStringFromMacString( const char* from , bool mac2pcEncoding )
{
if (mac2pcEncoding)
{
return wxMacMakePCStringFromMac( from ) ;
}
else
{
return wxString( from ) ;
}
}
wxString wxMacMakeStringFromPascal( StringPtr from , bool mac2pcEncoding )
{
// this is safe since a pascal string can never be larger than 256 bytes
char s[256] ;
CopyPascalStringToC( from , s ) ;
if (mac2pcEncoding)
{
return wxMacMakePCStringFromMac( s ) ;
}
else
{
return wxString( s ) ;
}
}
void wxMacStringToPascal( const char * from , StringPtr to , bool pc2macEncoding )
{
if (pc2macEncoding)
{
CopyCStringToPascal( wxMacMakeMacStringFromPC( from ) , to ) ;
}
else
{
CopyCStringToPascal( from , to ) ;
}
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// Carbon Event Handler // Carbon Event Handler
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@@ -495,10 +293,54 @@ void wxMacStringToPascal( const char * from , StringPtr to , bool pc2macEncoding
{ {
{ kEventClassCommand, kEventProcessCommand } , { kEventClassCommand, kEventProcessCommand } ,
{ kEventClassCommand, kEventCommandUpdateStatus } , { kEventClassCommand, kEventCommandUpdateStatus } ,
{ kEventClassApplication , kEventAppActivated } , { kEventClassApplication , kEventAppActivated } ,
{ kEventClassApplication , kEventAppDeactivated } , { kEventClassApplication , kEventAppDeactivated } ,
// handling the quit event is not recommended by apple
// rather using the quit apple event - which we do
{ kEventClassMouse , kEventMouseDown } ,
} ; } ;
static pascal OSStatus MenuEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
{
OSStatus result = eventNotHandledErr ;
UInt32 kind = GetEventKind( event ) ;
return result ;
}
// due to the rather low-level event API of wxWindows, we cannot use RunApplicationEventLoop
// but have to use ReceiveNextEvent dealing with events manually, therefore we also have
// deal with clicks in the menu bar explicitely
static pascal OSStatus MouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
{
OSStatus result = eventNotHandledErr ;
switch( GetEventKind(event) )
{
case kEventMouseDown :
{
Point point ;
WindowRef window ;
GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL,
sizeof( Point ), NULL, &point );
short windowPart = ::FindWindow(point, &window);
if ( windowPart == inMenuBar )
{
MenuSelect( point ) ;
result = noErr ;
}
}
break ;
}
return result ;
}
static pascal OSStatus CommandEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) static pascal OSStatus CommandEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
{ {
OSStatus result = eventNotHandledErr ; OSStatus result = eventNotHandledErr ;
@@ -580,7 +422,12 @@ pascal OSStatus wxAppEventHandler( EventHandlerCallRef handler , EventRef event
case kEventClassApplication : case kEventClassApplication :
result = ApplicationEventHandler( handler , event , data ) ; result = ApplicationEventHandler( handler , event , data ) ;
break ; break ;
case kEventClassMenu :
result = MenuEventHandler( handler , event , data ) ;
break ;
case kEventClassMouse :
result = MouseEventHandler( handler , event , data ) ;
break ;
default : default :
break ; break ;
} }
@@ -684,8 +531,6 @@ bool wxApp::Initialize()
s_macCursorRgn = ::NewRgn() ; s_macCursorRgn = ::NewRgn() ;
wxBuffer = new char[BUFSIZ + 512];
wxClassInfo::InitializeClasses(); wxClassInfo::InitializeClasses();
#if wxUSE_RESOURCES #if wxUSE_RESOURCES
@@ -742,6 +587,8 @@ bool wxApp::OnInitGui()
return false ; return false ;
#if TARGET_CARBON #if TARGET_CARBON
InstallStandardEventHandler( GetApplicationEventTarget() ) ;
InstallApplicationEventHandler( InstallApplicationEventHandler(
GetwxAppEventHandlerUPP(), GetwxAppEventHandlerUPP(),
GetEventTypeCount(eventList), eventList, wxTheApp, &((EventHandlerRef)wxTheApp->m_macEventHandler)); GetEventTypeCount(eventList), eventList, wxTheApp, &((EventHandlerRef)wxTheApp->m_macEventHandler));
@@ -811,9 +658,6 @@ void wxApp::CleanUp()
wxBitmap::CleanUpHandlers(); wxBitmap::CleanUpHandlers();
delete[] wxBuffer;
wxBuffer = NULL;
wxMacDestroyNotifierTable() ; wxMacDestroyNotifierTable() ;
if (wxWinMacWindowList) { if (wxWinMacWindowList) {
delete wxWinMacWindowList ; delete wxWinMacWindowList ;
@@ -1317,15 +1161,26 @@ bool wxApp::ProcessIdle()
void wxApp::ExitMainLoop() void wxApp::ExitMainLoop()
{ {
m_keepGoing = FALSE; #if TARGET_CARBON
if (s_inReceiveEvent)
QuitApplicationEventLoop() ;
else
m_keepGoing = FALSE;
#else
m_keepGoing = FALSE;
#endif
} }
// Is a message/event pending? // Is a message/event pending?
bool wxApp::Pending() bool wxApp::Pending()
{ {
#if TARGET_CARBON
return GetNumEventsInQueue( GetMainEventQueue() ) > 0 ;
#else
EventRecord event ; EventRecord event ;
return EventAvail( everyEvent , &event ) ; return EventAvail( everyEvent , &event ) ;
#endif
} }
// Dispatch a message. // Dispatch a message.
@@ -1336,8 +1191,6 @@ void wxApp::Dispatch()
void wxApp::OnIdle(wxIdleEvent& event) void wxApp::OnIdle(wxIdleEvent& event)
{ {
static bool s_inOnIdle = FALSE;
// Avoid recursion (via ProcessEvent default case) // Avoid recursion (via ProcessEvent default case)
if ( s_inOnIdle ) if ( s_inOnIdle )
return; return;
@@ -1480,21 +1333,51 @@ bool wxApp::Yield(bool onlyIfNeeded)
#if wxUSE_THREADS #if wxUSE_THREADS
YieldToAnyThread() ; YieldToAnyThread() ;
#endif #endif
// by definition yield should handle all non-processed events
#if TARGET_CARBON
EventRef theEvent;
OSStatus status = noErr ;
do
{
s_inReceiveEvent = true ;
status = ReceiveNextEvent(0, NULL,kEventDurationNoWait,true,&theEvent) ;
s_inReceiveEvent = false ;
if ( status == eventLoopTimedOutErr )
{
// make sure next time the event loop will trigger idle events
sleepTime = kEventDurationNoWait ;
}
else if ( status == eventLoopQuitErr )
{
m_keepGoing = false ;
}
else
{
MacHandleOneEvent( theEvent ) ;
ReleaseEvent(theEvent);
}
} while( status == noErr ) ;
#else
EventRecord event ; EventRecord event ;
long sleepTime = 1 ; //::GetCaretTime(); // having a larger value here leads to large performance slowdowns
// so we cannot give background apps more processor time here
// we do so however having a large sleep value in the main event loop
long sleepTime = 0 ;
while ( !wxTheApp->IsExiting() && WaitNextEvent(everyEvent, &event,sleepTime, (RgnHandle) wxApp::s_macCursorRgn)) while ( !IsExiting() && WaitNextEvent(everyEvent, &event,sleepTime, (RgnHandle) wxApp::s_macCursorRgn))
{ {
wxTheApp->MacHandleModifierEvents( &event ) ; MacHandleModifierEvents( &event ) ;
wxTheApp->MacHandleOneEvent( &event ); MacHandleOneEvent( &event );
if ( event.what != kHighLevelEvent ) if ( event.what != kHighLevelEvent )
SetRectRgn( (RgnHandle) 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 ) ;
} }
wxTheApp->MacHandleModifierEvents( &event ) ; MacHandleModifierEvents( &event ) ;
#endif
wxMacProcessNotifierAndPendingEvents() ; wxMacProcessNotifierAndPendingEvents() ;
s_inYield = FALSE; s_inYield = FALSE;
return TRUE; return TRUE;
@@ -1561,11 +1444,34 @@ void wxApp::MacConvertPublicToPrivateScrap()
void wxApp::MacDoOneEvent() void wxApp::MacDoOneEvent()
{ {
EventRecord event ; #if TARGET_CARBON
EventRef theEvent;
long sleepTime = 1; // GetCaretTime() / 4 ; s_inReceiveEvent = true ;
OSStatus status = ReceiveNextEvent(0, NULL,sleepTime,true,&theEvent) ;
s_inReceiveEvent = false ;
if ( status == eventLoopTimedOutErr )
{
if ( wxTheApp->ProcessIdle() )
sleepTime = kEventDurationNoWait ;
else
sleepTime = kEventDurationForever ;
}
else if ( status == eventLoopQuitErr )
{
m_keepGoing = false ;
}
else
{
MacHandleOneEvent( theEvent ) ;
ReleaseEvent(theEvent);
}
#else
EventRecord event ;
if (WaitNextEvent(everyEvent, &event, sleepTime, (RgnHandle) s_macCursorRgn)) EventMask eventMask = everyEvent ;
if (WaitNextEvent(eventMask, &event, sleepTime, (RgnHandle) s_macCursorRgn))
{ {
MacHandleModifierEvents( &event ) ; MacHandleModifierEvents( &event ) ;
MacHandleOneEvent( &event ); MacHandleOneEvent( &event );
@@ -1578,37 +1484,89 @@ void wxApp::MacDoOneEvent()
if ( window ) if ( window )
::IdleControls( window ) ; ::IdleControls( window ) ;
wxTheApp->ProcessIdle() ; if ( wxTheApp->ProcessIdle() )
sleepTime = 0 ;
else
sleepTime = GetCaretTime() / 2 ;
} }
if ( event.what != kHighLevelEvent ) if ( event.what != kHighLevelEvent )
SetRectRgn( (RgnHandle) 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 ) ;
#endif
// repeaters // repeaters
DeletePendingObjects() ; DeletePendingObjects() ;
wxMacProcessNotifierAndPendingEvents() ; wxMacProcessNotifierAndPendingEvents() ;
} }
void wxApp::MacHandleOneEvent( WXEVENTREF evr )
{
#if TARGET_CARBON
EventTargetRef theTarget;
theTarget = GetEventDispatcherTarget();
m_macCurrentEvent = evr ;
SendEventToEventTarget ((EventRef) evr , theTarget);
#else
EventRecord* ev = (EventRecord*) evr ;
m_macCurrentEvent = ev ;
wxApp::sm_lastMessageTime = ev->when ;
switch (ev->what)
{
case mouseDown:
MacHandleMouseDownEvent( ev ) ;
if ( ev->modifiers & controlKey )
s_lastMouseDown = 2;
else
s_lastMouseDown = 1;
break;
case mouseUp:
if ( s_lastMouseDown == 2 )
{
ev->modifiers |= controlKey ;
}
else
{
ev->modifiers &= ~controlKey ;
}
MacHandleMouseUpEvent( ev ) ;
s_lastMouseDown = 0;
break;
case activateEvt:
MacHandleActivateEvent( ev ) ;
break;
case updateEvt:
MacHandleUpdateEvent( ev ) ;
break;
case keyDown:
case autoKey:
MacHandleKeyDownEvent( ev ) ;
break;
case keyUp:
MacHandleKeyUpEvent( ev ) ;
break;
case diskEvt:
MacHandleDiskEvent( ev ) ;
break;
case osEvt:
MacHandleOSEvent( ev ) ;
break;
case kHighLevelEvent:
MacHandleHighLevelEvent( ev ) ;
break;
default:
break;
}
#endif
wxMacProcessNotifierAndPendingEvents() ;
}
#if !TARGET_CARBON
bool s_macIsInModalLoop = false ;
void wxApp::MacHandleModifierEvents( WXEVENTREF evr ) void wxApp::MacHandleModifierEvents( WXEVENTREF evr )
{ {
EventRecord* ev = (EventRecord*) evr ; EventRecord* ev = (EventRecord*) evr ;
#if TARGET_CARBON
if ( ev->what == mouseDown || ev->what == mouseUp || ev->what == activateEvt ||
ev->what == keyDown || ev->what == autoKey || ev->what == keyUp || ev->what == kHighLevelEvent ||
ev->what == nullEvent
)
{
// in these cases the modifiers are already correctly setup by carbon
}
else
{
EventRecord nev ;
WaitNextEvent( 0 , &nev , 0 , NULL ) ;
ev->modifiers = nev.modifiers ;
// KeyModifiers unfortunately don't include btnState...
// ev->modifiers = GetCurrentKeyModifiers() ;
}
#endif
if ( ev->modifiers != s_lastModifiers && wxWindow::FindFocus() != NULL ) if ( ev->modifiers != s_lastModifiers && wxWindow::FindFocus() != NULL )
{ {
wxKeyEvent event(wxEVT_KEY_DOWN); wxKeyEvent event(wxEVT_KEY_DOWN);
@@ -1646,66 +1604,6 @@ void wxApp::MacHandleModifierEvents( WXEVENTREF evr )
} }
} }
void wxApp::MacHandleOneEvent( WXEVENTREF evr )
{
EventRecord* ev = (EventRecord*) evr ;
m_macCurrentEvent = ev ;
wxApp::sm_lastMessageTime = ev->when ;
switch (ev->what)
{
case mouseDown:
MacHandleMouseDownEvent( ev ) ;
if ( ev->modifiers & controlKey )
s_lastMouseDown = 2;
else
s_lastMouseDown = 1;
break;
#if !TARGET_CARBON
case mouseUp:
if ( s_lastMouseDown == 2 )
{
ev->modifiers |= controlKey ;
}
else
{
ev->modifiers &= ~controlKey ;
}
MacHandleMouseUpEvent( ev ) ;
s_lastMouseDown = 0;
break;
case activateEvt:
MacHandleActivateEvent( ev ) ;
break;
case updateEvt:
MacHandleUpdateEvent( ev ) ;
break;
#endif
case keyDown:
case autoKey:
MacHandleKeyDownEvent( ev ) ;
break;
case keyUp:
MacHandleKeyUpEvent( ev ) ;
break;
#if !TARGET_CARBON
case diskEvt:
MacHandleDiskEvent( ev ) ;
break;
case osEvt:
MacHandleOSEvent( ev ) ;
break;
#endif
case kHighLevelEvent:
MacHandleHighLevelEvent( ev ) ;
break;
default:
break;
}
wxMacProcessNotifierAndPendingEvents() ;
}
void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr ) void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr )
{ {
// we must avoid reentrancy problems when processing high level events eg printing // we must avoid reentrancy problems when processing high level events eg printing
@@ -1716,8 +1614,6 @@ void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr )
s_inYield = former ; s_inYield = former ;
} }
bool s_macIsInModalLoop = false ;
void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr ) void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr )
{ {
EventRecord* ev = (EventRecord*) evr ; EventRecord* ev = (EventRecord*) evr ;
@@ -1747,13 +1643,10 @@ void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr )
else else
{ {
UInt32 menuresult = MenuSelect(ev->where) ; UInt32 menuresult = MenuSelect(ev->where) ;
#if !TARGET_CARBON
MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) ); MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) );
#endif
s_lastMouseDown = 0; s_lastMouseDown = 0;
} }
break ; break ;
#if !TARGET_CARBON
case inSysWindow : case inSysWindow :
SystemClick( ev , window ) ; SystemClick( ev , window ) ;
s_lastMouseDown = 0; s_lastMouseDown = 0;
@@ -1875,14 +1768,11 @@ void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr )
win->MacMouseDown( ev , windowPart ) ; win->MacMouseDown( ev , windowPart ) ;
} }
break ; break ;
#endif
default: default:
break; break;
} }
} }
#if !TARGET_CARBON
void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr ) void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr )
{ {
EventRecord* ev = (EventRecord*) evr ; EventRecord* ev = (EventRecord*) evr ;
@@ -2026,12 +1916,12 @@ long wxMacTranslateKey(unsigned char key, unsigned char code)
return retval; return retval;
} }
#if !TARGET_CARBON
void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr ) void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr )
{ {
EventRecord* ev = (EventRecord*) evr ; EventRecord* ev = (EventRecord*) evr ;
wxToolTip::RemoveToolTips() ; wxToolTip::RemoveToolTips() ;
#if !TARGET_CARBON
UInt32 menuresult = UMAMenuEvent(ev) ; UInt32 menuresult = UMAMenuEvent(ev) ;
if ( HiWord( menuresult ) ) if ( HiWord( menuresult ) )
{ {
@@ -2039,7 +1929,6 @@ void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr )
MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) ) ; MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) ) ;
} }
else else
#endif
{ {
wxWindow* focus = wxWindow::FindFocus() ; wxWindow* focus = wxWindow::FindFocus() ;
@@ -2059,6 +1948,23 @@ void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr )
} }
} }
void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr )
{
EventRecord* ev = (EventRecord*) evr ;
wxToolTip::RemoveToolTips() ;
UInt32 menuresult = UMAMenuEvent(ev) ;
if ( HiWord( menuresult ) )
{
}
else
{
MacSendKeyUpEvent( wxWindow::FindFocus() , ev->message , ev->modifiers , ev->when , ev->where.h , ev->where.v ) ;
}
}
#endif
bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey ) bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey )
{ {
if ( !focus ) if ( !focus )
@@ -2189,22 +2095,6 @@ bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifi
return handled ; return handled ;
} }
void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr )
{
EventRecord* ev = (EventRecord*) evr ;
wxToolTip::RemoveToolTips() ;
UInt32 menuresult = UMAMenuEvent(ev) ;
if ( HiWord( menuresult ) )
{
}
else
{
MacSendKeyUpEvent( wxWindow::FindFocus() , ev->message , ev->modifiers , ev->when , ev->where.h , ev->where.v ) ;
}
}
bool wxApp::MacSendKeyUpEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey ) bool wxApp::MacSendKeyUpEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey )
{ {
if ( !focus ) if ( !focus )
@@ -2246,6 +2136,7 @@ bool wxApp::MacSendKeyUpEvent( wxWindow* focus , long keymessage , long modifier
return handled ; return handled ;
} }
#if !TARGET_CARBON #if !TARGET_CARBON
void wxApp::MacHandleActivateEvent( WXEVENTREF evr ) void wxApp::MacHandleActivateEvent( WXEVENTREF evr )
{ {

View File

@@ -36,7 +36,6 @@ IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
BEGIN_EVENT_TABLE(wxControl, wxWindow) BEGIN_EVENT_TABLE(wxControl, wxWindow)
EVT_MOUSE_EVENTS( wxControl::OnMouseEvent ) EVT_MOUSE_EVENTS( wxControl::OnMouseEvent )
// EVT_CHAR( wxControl::OnKeyDown )
EVT_PAINT( wxControl::OnPaint ) EVT_PAINT( wxControl::OnPaint )
END_EVENT_TABLE() END_EVENT_TABLE()
#endif #endif
@@ -357,19 +356,7 @@ void wxControl::MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString l
((Rect*)outBounds)->bottom = 0; ((Rect*)outBounds)->bottom = 0;
((Rect*)outBounds)->right = 0; ((Rect*)outBounds)->right = 0;
char c_text[255]; wxMacStringToPascal( wxStripMenuCodes(label) , maclabel ) ;
strcpy( c_text , label ) ;
if( wxApp::s_macDefaultEncodingIsPC )
{
wxMacConvertFromPCForControls( c_text ) ;
}
#if TARGET_CARBON
c2pstrcpy( (StringPtr) maclabel , c_text ) ;
#else
strcpy( (char *) maclabel , c_text ) ;
c2pstr( (char *) maclabel ) ;
#endif
} }
void wxControl::MacPostControlCreate() void wxControl::MacPostControlCreate()
@@ -820,12 +807,24 @@ void wxControl::OnEraseBackground(wxEraseEvent& event)
wxWindow::OnEraseBackground( event ) ; wxWindow::OnEraseBackground( event ) ;
} }
void wxControl::OnKeyDown( wxKeyEvent &event ) void wxControl::OnKeyDown( wxKeyEvent &event )
{ {
if ( (ControlHandle) m_macControl == NULL ) if ( (ControlHandle) m_macControl == NULL )
return ; return ;
#if TARGET_CARBON
char charCode ;
UInt32 keyCode ;
UInt32 modifiers ;
GetEventParameter( (EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode );
GetEventParameter( (EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode );
GetEventParameter((EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers);
::HandleControlKey( (ControlHandle) m_macControl , keyCode , charCode , modifiers ) ;
#else
EventRecord *ev = (EventRecord*) wxTheApp->MacGetCurrentEvent() ; EventRecord *ev = (EventRecord*) wxTheApp->MacGetCurrentEvent() ;
short keycode ; short keycode ;
short keychar ; short keychar ;
@@ -833,6 +832,7 @@ void wxControl::OnKeyDown( wxKeyEvent &event )
keycode = short(ev->message & keyCodeMask) >> 8 ; keycode = short(ev->message & keyCodeMask) >> 8 ;
::HandleControlKey( (ControlHandle) m_macControl , keycode , keychar , ev->modifiers ) ; ::HandleControlKey( (ControlHandle) m_macControl , keycode , keychar , ev->modifiers ) ;
#endif
} }
void wxControl::OnMouseEvent( wxMouseEvent &event ) void wxControl::OnMouseEvent( wxMouseEvent &event )

View File

@@ -296,7 +296,13 @@ static pascal ControlPartCode TPPaneTrackingProc(ControlHandle theControl, Point
case kmUPTextPart: case kmUPTextPart:
{ SetPort((**tpvars).fDrawingEnvironment); { SetPort((**tpvars).fDrawingEnvironment);
wxMacWindowClipper clipper( wxFindControlFromMacControl(theControl ) ) ; wxMacWindowClipper clipper( wxFindControlFromMacControl(theControl ) ) ;
#if !TARGET_CARBON
TXNClick( varsp->fTXNRec, (const EventRecord*) wxTheApp->MacGetCurrentEvent()); TXNClick( varsp->fTXNRec, (const EventRecord*) wxTheApp->MacGetCurrentEvent());
#else
EventRecord rec ;
ConvertEventRefToEventRecord( (EventRef) wxTheApp->MacGetCurrentEvent() , &rec ) ;
TXNClick( varsp->fTXNRec, &rec );
#endif
} }
break; break;
@@ -729,12 +735,6 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
m_macControl = NewControl(MAC_WXHWND(parent->MacGetRootWindow()), &bounds, "\p", true, featurSet, 0, featurSet, kControlUserPaneProc, 0); m_macControl = NewControl(MAC_WXHWND(parent->MacGetRootWindow()), &bounds, "\p", true, featurSet, 0, featurSet, kControlUserPaneProc, 0);
/* set up the mUP specific features and data */ /* set up the mUP specific features and data */
mUPOpenControl((ControlHandle) m_macControl, m_windowStyle ); mUPOpenControl((ControlHandle) m_macControl, m_windowStyle );
/*
if ( parent )
{
parent->MacGetTopLevelWindow()->MacInstallEventHandler() ;
}
*/
} }
MacPostControlCreate() ; MacPostControlCreate() ;
@@ -769,46 +769,53 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
wxString wxTextCtrl::GetValue() const wxString wxTextCtrl::GetValue() const
{ {
Size actualsize; Size actualSize = 0;
wxString result ;
OSStatus err ;
if ( !m_macUsesTXN ) if ( !m_macUsesTXN )
{ {
::GetControlData( (ControlHandle) m_macControl, 0, err = ::GetControlDataSize((ControlHandle) m_macControl, 0,
( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag, &actualSize ) ;
32767 , wxBuffer , &actualsize ) ;
if ( err )
return wxEmptyString ;
if ( actualSize > 0 )
{
wxChar *ptr = result.GetWriteBuf(actualSize) ;
::GetControlData( (ControlHandle) m_macControl, 0,
( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag,
actualSize , ptr , &actualSize ) ;
ptr[actualSize] = 0 ;
result.UngetWriteBuf(actualSize) ;
}
} }
else else
{ {
Handle theText ; Handle theText ;
OSStatus err = TXNGetDataEncoded( ((TXNObject) m_macTXN), kTXNStartOffset, kTXNEndOffset, &theText , kTXNTextData ); err = TXNGetDataEncoded( ((TXNObject) m_macTXN), kTXNStartOffset, kTXNEndOffset, &theText , kTXNTextData );
// all done // all done
if ( err ) if ( err )
{ {
actualsize = 0 ; actualSize = 0 ;
} }
else else
{ {
actualsize = GetHandleSize( theText ) ; actualSize = GetHandleSize( theText ) ;
if (actualsize != 0) if ( actualSize > 0 )
strncpy( wxBuffer , *theText , actualsize ) ; {
DisposeHandle( theText ) ; wxChar *ptr = result.GetWriteBuf(actualSize) ;
strncpy( ptr , *theText , actualSize ) ;
ptr[actualSize] = 0 ;
result.UngetWriteBuf( actualSize ) ;
}
DisposeHandle( theText ) ;
} }
} }
wxBuffer[actualsize] = 0 ; return wxMacMakeStringFromMacString( result ) ;
wxString value;
if( wxApp::s_macDefaultEncodingIsPC )
{
value = wxMacMakePCStringFromMac( wxBuffer ) ;
value.Replace( "\r", "\n" );
}
else
value = wxBuffer;
return value;
} }
void wxTextCtrl::GetSelection(long* from, long* to) const void wxTextCtrl::GetSelection(long* from, long* to) const
@@ -831,7 +838,7 @@ void wxTextCtrl::SetValue(const wxString& st)
if( wxApp::s_macDefaultEncodingIsPC ) if( wxApp::s_macDefaultEncodingIsPC )
{ {
value = wxMacMakeMacStringFromPC( st ) ; value = wxMacMakeMacStringFromPC( st ) ;
value.Replace( "\n", "\r" ); // value.Replace( "\n", "\r" ); TODO this should be handled by the conversion
} }
else else
value = st; value = st;
@@ -1207,7 +1214,7 @@ void wxTextCtrl::WriteText(const wxString& text)
if( wxApp::s_macDefaultEncodingIsPC ) if( wxApp::s_macDefaultEncodingIsPC )
{ {
value = wxMacMakeMacStringFromPC( text ) ; value = wxMacMakeMacStringFromPC( text ) ;
value.Replace( "\n", "\r" ); // value.Replace( "\n", "\r" ); // TODO this should be handled by the conversion
} }
else else
value = text ; value = text ;

View File

@@ -74,12 +74,12 @@ extern long wxMacTranslateKey(unsigned char key, unsigned char code) ;
static const EventTypeSpec eventList[] = static const EventTypeSpec eventList[] =
{ {
{ kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } , { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } ,
/*
{ kEventClassKeyboard, kEventRawKeyDown } , { kEventClassKeyboard, kEventRawKeyDown } ,
{ kEventClassKeyboard, kEventRawKeyRepeat } , { kEventClassKeyboard, kEventRawKeyRepeat } ,
{ kEventClassKeyboard, kEventRawKeyUp } , { kEventClassKeyboard, kEventRawKeyUp } ,
{ kEventClassKeyboard, kEventRawKeyModifiersChanged } , { kEventClassKeyboard, kEventRawKeyModifiersChanged } ,
*/
{ kEventClassWindow , kEventWindowUpdate } , { kEventClassWindow , kEventWindowUpdate } ,
{ kEventClassWindow , kEventWindowActivated } , { kEventClassWindow , kEventWindowActivated } ,
{ kEventClassWindow , kEventWindowDeactivated } , { kEventClassWindow , kEventWindowDeactivated } ,
@@ -97,18 +97,112 @@ static const EventTypeSpec eventList[] =
static pascal OSStatus TextInputEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) static pascal OSStatus TextInputEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
{ {
OSStatus result = eventNotHandledErr ; OSStatus result = eventNotHandledErr ;
EventRecord rec ;
if ( wxMacConvertEventToRecord( event , &rec ) ) wxWindow* focus = wxWindow::FindFocus() ;
{ char charCode ;
wxTheApp->m_macCurrentEvent = &rec ; UInt32 keyCode ;
wxWindow* focus = wxWindow::FindFocus() ; UInt32 modifiers ;
if ( (focus != NULL) && !UMAMenuEvent(&rec) && wxTheApp->MacSendKeyDownEvent( focus , rec.message , rec.modifiers , rec.when , rec.where.h , rec.where.v ) ) Point point ;
{ UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ;
// was handled internally
result = noErr ; EventRef rawEvent ;
}
} GetEventParameter( event , kEventParamTextInputSendKeyboardEvent ,typeEventRef,NULL,sizeof(rawEvent),NULL,&rawEvent ) ;
GetEventParameter( rawEvent, kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode );
GetEventParameter( rawEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode );
GetEventParameter( rawEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers);
GetEventParameter( rawEvent, kEventParamMouseLocation, typeQDPoint, NULL,
sizeof( Point ), NULL, &point );
UInt32 message = (keyCode << 8) + charCode;
switch ( GetEventKind( event ) )
{
case kEventTextInputUnicodeForKeyEvent :
if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent(
focus , message , modifiers , when , point.h , point.v ) )
{
result = noErr ;
}
break ;
}
return result ;
}
static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
{
OSStatus result = eventNotHandledErr ;
wxWindow* focus = wxWindow::FindFocus() ;
char charCode ;
UInt32 keyCode ;
UInt32 modifiers ;
Point point ;
UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ;
GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode );
GetEventParameter( event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode );
GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers);
GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL,
sizeof( Point ), NULL, &point );
UInt32 message = (keyCode << 8) + charCode;
switch( GetEventKind( event ) )
{
case kEventRawKeyRepeat :
case kEventRawKeyDown :
if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent(
focus , message , modifiers , when , point.h , point.v ) )
{
result = noErr ;
}
break ;
case kEventRawKeyUp :
if ( (focus != NULL) && wxTheApp->MacSendKeyUpEvent(
focus , message , modifiers , when , point.h , point.v ) )
{
result = noErr ;
}
break ;
case kEventRawKeyModifiersChanged :
{
wxKeyEvent event(wxEVT_KEY_DOWN);
event.m_shiftDown = modifiers & shiftKey;
event.m_controlDown = modifiers & controlKey;
event.m_altDown = modifiers & optionKey;
event.m_metaDown = modifiers & cmdKey;
event.m_x = point.h;
event.m_y = point.v;
event.m_timeStamp = when;
wxWindow* focus = wxWindow::FindFocus() ;
event.SetEventObject(focus);
if ( (modifiers ^ wxTheApp->s_lastModifiers ) & controlKey )
{
event.m_keyCode = WXK_CONTROL ;
event.SetEventType( ( modifiers & controlKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
focus->GetEventHandler()->ProcessEvent( event ) ;
}
if ( (modifiers ^ wxTheApp->s_lastModifiers ) & shiftKey )
{
event.m_keyCode = WXK_SHIFT ;
event.SetEventType( ( modifiers & shiftKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
focus->GetEventHandler()->ProcessEvent( event ) ;
}
if ( (modifiers ^ wxTheApp->s_lastModifiers ) & optionKey )
{
event.m_keyCode = WXK_ALT ;
event.SetEventType( ( modifiers & optionKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
focus->GetEventHandler()->ProcessEvent( event ) ;
}
wxTheApp->s_lastModifiers = modifiers ;
}
break ;
}
return result ; return result ;
} }
@@ -138,7 +232,7 @@ static pascal OSStatus MouseEventHandler( EventHandlerCallRef handler , EventRef
WindowRef window ; WindowRef window ;
short windowPart = ::FindWindow(point, &window); short windowPart = ::FindWindow(point, &window);
if ( IsWindowActive(window) && windowPart == inContent ) if ( IsWindowActive(window) && windowPart == inContent )
{ {
switch ( GetEventKind( event ) ) switch ( GetEventKind( event ) )
{ {
@@ -227,6 +321,9 @@ pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef
switch ( GetEventClass( event ) ) switch ( GetEventClass( event ) )
{ {
case kEventClassKeyboard :
result = KeyboardEventHandler( handler, event , data ) ;
break ;
case kEventClassTextInput : case kEventClassTextInput :
result = TextInputEventHandler( handler, event , data ) ; result = TextInputEventHandler( handler, event , data ) ;
break ; break ;

View File

@@ -36,7 +36,6 @@ IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
BEGIN_EVENT_TABLE(wxControl, wxWindow) BEGIN_EVENT_TABLE(wxControl, wxWindow)
EVT_MOUSE_EVENTS( wxControl::OnMouseEvent ) EVT_MOUSE_EVENTS( wxControl::OnMouseEvent )
// EVT_CHAR( wxControl::OnKeyDown )
EVT_PAINT( wxControl::OnPaint ) EVT_PAINT( wxControl::OnPaint )
END_EVENT_TABLE() END_EVENT_TABLE()
#endif #endif
@@ -357,19 +356,7 @@ void wxControl::MacPreControlCreate( wxWindow *parent, wxWindowID id, wxString l
((Rect*)outBounds)->bottom = 0; ((Rect*)outBounds)->bottom = 0;
((Rect*)outBounds)->right = 0; ((Rect*)outBounds)->right = 0;
char c_text[255]; wxMacStringToPascal( wxStripMenuCodes(label) , maclabel ) ;
strcpy( c_text , label ) ;
if( wxApp::s_macDefaultEncodingIsPC )
{
wxMacConvertFromPCForControls( c_text ) ;
}
#if TARGET_CARBON
c2pstrcpy( (StringPtr) maclabel , c_text ) ;
#else
strcpy( (char *) maclabel , c_text ) ;
c2pstr( (char *) maclabel ) ;
#endif
} }
void wxControl::MacPostControlCreate() void wxControl::MacPostControlCreate()
@@ -820,12 +807,24 @@ void wxControl::OnEraseBackground(wxEraseEvent& event)
wxWindow::OnEraseBackground( event ) ; wxWindow::OnEraseBackground( event ) ;
} }
void wxControl::OnKeyDown( wxKeyEvent &event ) void wxControl::OnKeyDown( wxKeyEvent &event )
{ {
if ( (ControlHandle) m_macControl == NULL ) if ( (ControlHandle) m_macControl == NULL )
return ; return ;
#if TARGET_CARBON
char charCode ;
UInt32 keyCode ;
UInt32 modifiers ;
GetEventParameter( (EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode );
GetEventParameter( (EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode );
GetEventParameter((EventRef) wxTheApp->MacGetCurrentEvent(), kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers);
::HandleControlKey( (ControlHandle) m_macControl , keyCode , charCode , modifiers ) ;
#else
EventRecord *ev = (EventRecord*) wxTheApp->MacGetCurrentEvent() ; EventRecord *ev = (EventRecord*) wxTheApp->MacGetCurrentEvent() ;
short keycode ; short keycode ;
short keychar ; short keychar ;
@@ -833,6 +832,7 @@ void wxControl::OnKeyDown( wxKeyEvent &event )
keycode = short(ev->message & keyCodeMask) >> 8 ; keycode = short(ev->message & keyCodeMask) >> 8 ;
::HandleControlKey( (ControlHandle) m_macControl , keycode , keychar , ev->modifiers ) ; ::HandleControlKey( (ControlHandle) m_macControl , keycode , keychar , ev->modifiers ) ;
#endif
} }
void wxControl::OnMouseEvent( wxMouseEvent &event ) void wxControl::OnMouseEvent( wxMouseEvent &event )

View File

@@ -296,7 +296,13 @@ static pascal ControlPartCode TPPaneTrackingProc(ControlHandle theControl, Point
case kmUPTextPart: case kmUPTextPart:
{ SetPort((**tpvars).fDrawingEnvironment); { SetPort((**tpvars).fDrawingEnvironment);
wxMacWindowClipper clipper( wxFindControlFromMacControl(theControl ) ) ; wxMacWindowClipper clipper( wxFindControlFromMacControl(theControl ) ) ;
#if !TARGET_CARBON
TXNClick( varsp->fTXNRec, (const EventRecord*) wxTheApp->MacGetCurrentEvent()); TXNClick( varsp->fTXNRec, (const EventRecord*) wxTheApp->MacGetCurrentEvent());
#else
EventRecord rec ;
ConvertEventRefToEventRecord( (EventRef) wxTheApp->MacGetCurrentEvent() , &rec ) ;
TXNClick( varsp->fTXNRec, &rec );
#endif
} }
break; break;
@@ -729,12 +735,6 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
m_macControl = NewControl(MAC_WXHWND(parent->MacGetRootWindow()), &bounds, "\p", true, featurSet, 0, featurSet, kControlUserPaneProc, 0); m_macControl = NewControl(MAC_WXHWND(parent->MacGetRootWindow()), &bounds, "\p", true, featurSet, 0, featurSet, kControlUserPaneProc, 0);
/* set up the mUP specific features and data */ /* set up the mUP specific features and data */
mUPOpenControl((ControlHandle) m_macControl, m_windowStyle ); mUPOpenControl((ControlHandle) m_macControl, m_windowStyle );
/*
if ( parent )
{
parent->MacGetTopLevelWindow()->MacInstallEventHandler() ;
}
*/
} }
MacPostControlCreate() ; MacPostControlCreate() ;
@@ -769,46 +769,53 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
wxString wxTextCtrl::GetValue() const wxString wxTextCtrl::GetValue() const
{ {
Size actualsize; Size actualSize = 0;
wxString result ;
OSStatus err ;
if ( !m_macUsesTXN ) if ( !m_macUsesTXN )
{ {
::GetControlData( (ControlHandle) m_macControl, 0, err = ::GetControlDataSize((ControlHandle) m_macControl, 0,
( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag, &actualSize ) ;
32767 , wxBuffer , &actualsize ) ;
if ( err )
return wxEmptyString ;
if ( actualSize > 0 )
{
wxChar *ptr = result.GetWriteBuf(actualSize) ;
::GetControlData( (ControlHandle) m_macControl, 0,
( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag,
actualSize , ptr , &actualSize ) ;
ptr[actualSize] = 0 ;
result.UngetWriteBuf(actualSize) ;
}
} }
else else
{ {
Handle theText ; Handle theText ;
OSStatus err = TXNGetDataEncoded( ((TXNObject) m_macTXN), kTXNStartOffset, kTXNEndOffset, &theText , kTXNTextData ); err = TXNGetDataEncoded( ((TXNObject) m_macTXN), kTXNStartOffset, kTXNEndOffset, &theText , kTXNTextData );
// all done // all done
if ( err ) if ( err )
{ {
actualsize = 0 ; actualSize = 0 ;
} }
else else
{ {
actualsize = GetHandleSize( theText ) ; actualSize = GetHandleSize( theText ) ;
if (actualsize != 0) if ( actualSize > 0 )
strncpy( wxBuffer , *theText , actualsize ) ; {
DisposeHandle( theText ) ; wxChar *ptr = result.GetWriteBuf(actualSize) ;
strncpy( ptr , *theText , actualSize ) ;
ptr[actualSize] = 0 ;
result.UngetWriteBuf( actualSize ) ;
}
DisposeHandle( theText ) ;
} }
} }
wxBuffer[actualsize] = 0 ; return wxMacMakeStringFromMacString( result ) ;
wxString value;
if( wxApp::s_macDefaultEncodingIsPC )
{
value = wxMacMakePCStringFromMac( wxBuffer ) ;
value.Replace( "\r", "\n" );
}
else
value = wxBuffer;
return value;
} }
void wxTextCtrl::GetSelection(long* from, long* to) const void wxTextCtrl::GetSelection(long* from, long* to) const
@@ -831,7 +838,7 @@ void wxTextCtrl::SetValue(const wxString& st)
if( wxApp::s_macDefaultEncodingIsPC ) if( wxApp::s_macDefaultEncodingIsPC )
{ {
value = wxMacMakeMacStringFromPC( st ) ; value = wxMacMakeMacStringFromPC( st ) ;
value.Replace( "\n", "\r" ); // value.Replace( "\n", "\r" ); TODO this should be handled by the conversion
} }
else else
value = st; value = st;
@@ -1207,7 +1214,7 @@ void wxTextCtrl::WriteText(const wxString& text)
if( wxApp::s_macDefaultEncodingIsPC ) if( wxApp::s_macDefaultEncodingIsPC )
{ {
value = wxMacMakeMacStringFromPC( text ) ; value = wxMacMakeMacStringFromPC( text ) ;
value.Replace( "\n", "\r" ); // value.Replace( "\n", "\r" ); // TODO this should be handled by the conversion
} }
else else
value = text ; value = text ;

View File

@@ -74,12 +74,12 @@ extern long wxMacTranslateKey(unsigned char key, unsigned char code) ;
static const EventTypeSpec eventList[] = static const EventTypeSpec eventList[] =
{ {
{ kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } , { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } ,
/*
{ kEventClassKeyboard, kEventRawKeyDown } , { kEventClassKeyboard, kEventRawKeyDown } ,
{ kEventClassKeyboard, kEventRawKeyRepeat } , { kEventClassKeyboard, kEventRawKeyRepeat } ,
{ kEventClassKeyboard, kEventRawKeyUp } , { kEventClassKeyboard, kEventRawKeyUp } ,
{ kEventClassKeyboard, kEventRawKeyModifiersChanged } , { kEventClassKeyboard, kEventRawKeyModifiersChanged } ,
*/
{ kEventClassWindow , kEventWindowUpdate } , { kEventClassWindow , kEventWindowUpdate } ,
{ kEventClassWindow , kEventWindowActivated } , { kEventClassWindow , kEventWindowActivated } ,
{ kEventClassWindow , kEventWindowDeactivated } , { kEventClassWindow , kEventWindowDeactivated } ,
@@ -97,18 +97,112 @@ static const EventTypeSpec eventList[] =
static pascal OSStatus TextInputEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) static pascal OSStatus TextInputEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
{ {
OSStatus result = eventNotHandledErr ; OSStatus result = eventNotHandledErr ;
EventRecord rec ;
if ( wxMacConvertEventToRecord( event , &rec ) ) wxWindow* focus = wxWindow::FindFocus() ;
{ char charCode ;
wxTheApp->m_macCurrentEvent = &rec ; UInt32 keyCode ;
wxWindow* focus = wxWindow::FindFocus() ; UInt32 modifiers ;
if ( (focus != NULL) && !UMAMenuEvent(&rec) && wxTheApp->MacSendKeyDownEvent( focus , rec.message , rec.modifiers , rec.when , rec.where.h , rec.where.v ) ) Point point ;
{ UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ;
// was handled internally
result = noErr ; EventRef rawEvent ;
}
} GetEventParameter( event , kEventParamTextInputSendKeyboardEvent ,typeEventRef,NULL,sizeof(rawEvent),NULL,&rawEvent ) ;
GetEventParameter( rawEvent, kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode );
GetEventParameter( rawEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode );
GetEventParameter( rawEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers);
GetEventParameter( rawEvent, kEventParamMouseLocation, typeQDPoint, NULL,
sizeof( Point ), NULL, &point );
UInt32 message = (keyCode << 8) + charCode;
switch ( GetEventKind( event ) )
{
case kEventTextInputUnicodeForKeyEvent :
if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent(
focus , message , modifiers , when , point.h , point.v ) )
{
result = noErr ;
}
break ;
}
return result ;
}
static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
{
OSStatus result = eventNotHandledErr ;
wxWindow* focus = wxWindow::FindFocus() ;
char charCode ;
UInt32 keyCode ;
UInt32 modifiers ;
Point point ;
UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ;
GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, NULL,sizeof(char), NULL,&charCode );
GetEventParameter( event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode );
GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers);
GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL,
sizeof( Point ), NULL, &point );
UInt32 message = (keyCode << 8) + charCode;
switch( GetEventKind( event ) )
{
case kEventRawKeyRepeat :
case kEventRawKeyDown :
if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent(
focus , message , modifiers , when , point.h , point.v ) )
{
result = noErr ;
}
break ;
case kEventRawKeyUp :
if ( (focus != NULL) && wxTheApp->MacSendKeyUpEvent(
focus , message , modifiers , when , point.h , point.v ) )
{
result = noErr ;
}
break ;
case kEventRawKeyModifiersChanged :
{
wxKeyEvent event(wxEVT_KEY_DOWN);
event.m_shiftDown = modifiers & shiftKey;
event.m_controlDown = modifiers & controlKey;
event.m_altDown = modifiers & optionKey;
event.m_metaDown = modifiers & cmdKey;
event.m_x = point.h;
event.m_y = point.v;
event.m_timeStamp = when;
wxWindow* focus = wxWindow::FindFocus() ;
event.SetEventObject(focus);
if ( (modifiers ^ wxTheApp->s_lastModifiers ) & controlKey )
{
event.m_keyCode = WXK_CONTROL ;
event.SetEventType( ( modifiers & controlKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
focus->GetEventHandler()->ProcessEvent( event ) ;
}
if ( (modifiers ^ wxTheApp->s_lastModifiers ) & shiftKey )
{
event.m_keyCode = WXK_SHIFT ;
event.SetEventType( ( modifiers & shiftKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
focus->GetEventHandler()->ProcessEvent( event ) ;
}
if ( (modifiers ^ wxTheApp->s_lastModifiers ) & optionKey )
{
event.m_keyCode = WXK_ALT ;
event.SetEventType( ( modifiers & optionKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
focus->GetEventHandler()->ProcessEvent( event ) ;
}
wxTheApp->s_lastModifiers = modifiers ;
}
break ;
}
return result ; return result ;
} }
@@ -138,7 +232,7 @@ static pascal OSStatus MouseEventHandler( EventHandlerCallRef handler , EventRef
WindowRef window ; WindowRef window ;
short windowPart = ::FindWindow(point, &window); short windowPart = ::FindWindow(point, &window);
if ( IsWindowActive(window) && windowPart == inContent ) if ( IsWindowActive(window) && windowPart == inContent )
{ {
switch ( GetEventKind( event ) ) switch ( GetEventKind( event ) )
{ {
@@ -227,6 +321,9 @@ pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef
switch ( GetEventClass( event ) ) switch ( GetEventClass( event ) )
{ {
case kEventClassKeyboard :
result = KeyboardEventHandler( handler, event , data ) ;
break ;
case kEventClassTextInput : case kEventClassTextInput :
result = TextInputEventHandler( handler, event , data ) ; result = TextInputEventHandler( handler, event , data ) ;
break ; break ;