📄 app.cpp
字号:
node = node->GetNext();
}
::HideFloatingWindows() ;
#endif
s_lastMouseDown = 0 ;
if( convertClipboard )
{
MacConvertPrivateToPublicScrap() ;
}
}
extern wxList wxModalDialogs;
void wxApp::MacResume( bool convertClipboard )
{
s_lastMouseDown = 0 ;
if( convertClipboard )
{
MacConvertPublicToPrivateScrap() ;
}
#if !TARGET_CARBON
::ShowFloatingWindows() ;
// raise modal dialogs in case a non modal window was selected to activate the app
wxNode* node = wxModalDialogs.GetFirst();
while (node)
{
wxDialog* dialog = (wxDialog *) node->GetData();
dialog->Raise();
node = node->GetNext();
}
#endif
}
void wxApp::MacConvertPrivateToPublicScrap()
{
}
void wxApp::MacConvertPublicToPrivateScrap()
{
}
void wxApp::MacDoOneEvent()
{
#if TARGET_CARBON
EventRef theEvent;
s_inReceiveEvent = true ;
OSStatus status = ReceiveNextEvent(0, NULL,sleepTime,true,&theEvent) ;
s_inReceiveEvent = false ;
if ( status == eventLoopTimedOutErr )
{
if ( wxTheApp->ProcessIdle() )
sleepTime = kEventDurationNoWait ;
else
{
#if wxUSE_THREADS
if (g_numberOfThreads)
{
sleepTime = kEventDurationNoWait;
}
else
#endif // wxUSE_THREADS
{
sleepTime = kEventDurationSecond;
}
}
}
else if ( status == eventLoopQuitErr )
{
// according to QA1061 this may also occur when a WakeUp Process
// is executed
}
else
{
MacHandleOneEvent( theEvent ) ;
ReleaseEvent(theEvent);
sleepTime = kEventDurationNoWait ;
}
#else
EventRecord event ;
EventMask eventMask = everyEvent ;
if (WaitNextEvent(eventMask, &event, sleepTime, (RgnHandle) s_macCursorRgn))
{
MacHandleModifierEvents( &event ) ;
MacHandleOneEvent( &event );
}
else
{
MacHandleModifierEvents( &event ) ;
// idlers
WindowPtr window = ::FrontWindow() ;
if ( window )
::IdleControls( window ) ;
if ( wxTheApp->ProcessIdle() )
sleepTime = kEventDurationNoWait;
else
{
#if wxUSE_THREADS
if (g_numberOfThreads)
{
sleepTime = kEventDurationNoWait;
}
else
#endif // wxUSE_THREADS
{
sleepTime = kEventDurationSecond;
}
}
}
if ( event.what != kHighLevelEvent )
SetRectRgn( (RgnHandle) s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ;
#endif
// repeaters
DeletePendingObjects() ;
wxMacProcessNotifierAndPendingEvents() ;
}
/*virtual*/ void wxApp::MacHandleUnhandledEvent( WXEVENTREF evr )
{
// Override to process unhandled events as you please
}
void wxApp::MacHandleOneEvent( WXEVENTREF evr )
{
#if TARGET_CARBON
EventTargetRef theTarget;
theTarget = GetEventDispatcherTarget();
m_macCurrentEvent = evr ;
OSStatus status = SendEventToEventTarget ((EventRef) evr , theTarget);
if(status == eventNotHandledErr)
{
MacHandleUnhandledEvent(evr);
}
#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:
// In embedded mode we first let the UnhandledEvent function
// try to handle the update event. If we handle it ourselves
// first and then pass it on, the host's windows won't update.
MacHandleUnhandledEvent(ev);
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 )
{
EventRecord* ev = (EventRecord*) evr ;
if ( ev->modifiers != s_lastModifiers && wxWindow::FindFocus() != NULL )
{
wxKeyEvent event(wxEVT_KEY_DOWN);
event.m_shiftDown = ev->modifiers & shiftKey;
event.m_controlDown = ev->modifiers & controlKey;
event.m_altDown = ev->modifiers & optionKey;
event.m_metaDown = ev->modifiers & cmdKey;
event.m_x = ev->where.h;
event.m_y = ev->where.v;
event.SetTimestamp( ev->when );
wxWindow* focus = wxWindow::FindFocus() ;
event.SetEventObject(focus);
if ( (ev->modifiers ^ s_lastModifiers ) & controlKey )
{
event.m_keyCode = WXK_CONTROL ;
event.SetEventType( ( ev->modifiers & controlKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
focus->GetEventHandler()->ProcessEvent( event ) ;
}
if ( (ev->modifiers ^ s_lastModifiers ) & shiftKey )
{
event.m_keyCode = WXK_SHIFT ;
event.SetEventType( ( ev->modifiers & shiftKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
focus->GetEventHandler()->ProcessEvent( event ) ;
}
if ( (ev->modifiers ^ s_lastModifiers ) & optionKey )
{
event.m_keyCode = WXK_ALT ;
event.SetEventType( ( ev->modifiers & optionKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
focus->GetEventHandler()->ProcessEvent( event ) ;
}
if ( ( ev->modifiers ^ s_lastModifiers ) & cmdKey )
{
event.m_keyCode = WXK_COMMAND ;
event.SetEventType( ( ev->modifiers & cmdKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
focus->GetEventHandler()->ProcessEvent( event ) ;
}
s_lastModifiers = ev->modifiers ;
}
}
void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr )
{
// we must avoid reentrancy problems when processing high level events eg printing
bool former = s_inYield ;
s_inYield = true ;
EventRecord* ev = (EventRecord*) evr ;
::AEProcessAppleEvent( ev ) ;
s_inYield = former ;
}
void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr )
{
EventRecord* ev = (EventRecord*) evr ;
wxToolTip::RemoveToolTips() ;
WindowRef window;
WindowRef frontWindow = ::FrontNonFloatingWindow() ;
WindowAttributes frontWindowAttributes = NULL ;
if ( frontWindow )
::GetWindowAttributes( frontWindow , &frontWindowAttributes ) ;
short windowPart = ::FindWindow(ev->where, &window);
wxTopLevelWindowMac* win = wxFindWinFromMacWindow( (WXWindow) window ) ;
if ( wxPendingDelete.Member(win) )
return ;
BitMap screenBits;
GetQDGlobalsScreenBits( &screenBits );
switch (windowPart)
{
case inMenuBar :
if ( s_macIsInModalLoop )
{
SysBeep ( 30 ) ;
}
else
{
UInt32 menuresult = MenuSelect(ev->where) ;
MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) );
s_lastMouseDown = 0;
}
break ;
case inSysWindow :
SystemClick( ev , window ) ;
s_lastMouseDown = 0;
break ;
case inDrag :
if ( window != frontWindow && s_macIsInModalLoop && !(ev->modifiers & cmdKey ) )
{
SysBeep ( 30 ) ;
}
else
{
DragWindow(window, ev->where, &screenBits.bounds);
if (win)
{
GrafPtr port ;
GetPort( &port ) ;
Point pt = { 0, 0 } ;
SetPortWindowPort(window) ;
LocalToGlobal( &pt ) ;
SetPort( port ) ;
win->SetSize( pt.h , pt.v , -1 ,
-1 , wxSIZE_USE_EXISTING);
}
s_lastMouseDown = 0;
}
break ;
case inGoAway:
if (TrackGoAway(window, ev->where))
{
if ( win )
win->Close() ;
}
s_lastMouseDown = 0;
break;
case inGrow:
{
Rect newContentRect ;
Rect constraintRect ;
constraintRect.top = win->GetMinHeight() ;
if ( constraintRect.top == -1 )
constraintRect.top = 0 ;
constraintRect.left = win->GetMinWidth() ;
if ( constraintRect.left == -1 )
constraintRect.left = 0 ;
constraintRect.right = win->GetMaxWidth() ;
if ( constraintRect.right == -1 )
constraintRect.right = 32000 ;
constraintRect.bottom = win->GetMaxHeight() ;
if ( constraintRect.bottom == -1 )
constraintRect.bottom = 32000 ;
Boolean growResult = ResizeWindow( window , ev->where ,
&constraintRect , &newContentRect ) ;
if ( growResult )
{
win->SetSize( newContentRect.left , newContentRect.top ,
newContentRect.right - newContentRect.left ,
newContentRect.bottom - newContentRect.top, wxSIZE_USE_EXISTING);
}
s_lastMouseDown = 0;
}
break;
case inZoomIn:
case inZoomOut:
if (TrackBox(window, ev->where, windowPart))
{
// TODO setup size event
ZoomWindow( window , windowPart , false ) ;
if (win)
{
Rect tempRect ;
GrafPtr port ;
GetPort( &port ) ;
Point pt = { 0, 0 } ;
SetPortWindowPort(window) ;
LocalToGlobal( &pt ) ;
SetPort( port ) ;
GetWindowPortBounds(window, &tempRect ) ;
win->SetSize( pt.h , pt.v , tempRect.right-tempRect.left ,
tempRect.bottom-tempRect.top, wxSIZE_USE_EXISTING);
}
}
s_lastMouseDown = 0;
break;
case inCollapseBox :
// TODO setup size event
s_lastMouseDown = 0;
break ;
case inContent :
{
GrafPtr port ;
GetPort( &port ) ;
SetPortWindowPort(window) ;
SetPort( port ) ;
}
if ( window != frontWindow && wxTheApp->s_captureWindow == NULL )
{
if ( s_macIsInModalLoop )
{
SysBeep ( 30 ) ;
}
else if ( UMAIsWindowFloating( window ) )
{
if ( win )
win->MacMouseDown( ev , windowPart ) ;
}
else
{
// Activate window first
::SelectWindow( window ) ;
// Send event later
if ( win )
win->MacMouseDown( ev , windowPart ) ;
}
}
else
{
if ( win )
win->MacMouseDown( ev , windowPart ) ;
}
break ;
default:
break;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -