📄 toplevel.cpp
字号:
///////////////////////////////////////////////////////////////////////////////// Name: src/mac/classic/toplevel.cpp// Purpose: implements wxTopLevelWindow for Mac// Author: Stefan Csomor// Modified by:// Created: 24.09.01// RCS-ID: $Id: toplevel.cpp,v 1.11 2006/06/13 20:44:37 ABX Exp $// Copyright: (c) 2001-2004 Stefan Csomor// License: wxWindows licence///////////////////////////////////////////////////////////////////////////////// ============================================================================// declarations// ============================================================================// ----------------------------------------------------------------------------// headers// ----------------------------------------------------------------------------// For compilers that support precompilation, includes "wx.h".#include "wx/wxprec.h"#ifdef __BORLANDC__ #pragma hdrstop#endif#include "wx/toplevel.h"#ifndef WX_PRECOMP #include "wx/app.h" #include "wx/frame.h" #include "wx/string.h" #include "wx/log.h" #include "wx/intl.h"#endif //WX_PRECOMP#include "wx/mac/uma.h"#include "wx/mac/aga.h"#include "wx/tooltip.h"#include "wx/dnd.h"#if wxUSE_SYSTEM_OPTIONS #include "wx/sysopt.h"#endif#include <ToolUtils.h>#define wxMAC_DEBUG_REDRAW 0#ifndef wxMAC_DEBUG_REDRAW#define wxMAC_DEBUG_REDRAW 0#endif// ----------------------------------------------------------------------------// globals// ----------------------------------------------------------------------------// list of all frames and modeless dialogswxWindowList wxModelessWindows;// double click testingstatic Point gs_lastWhere;static long gs_lastWhen = 0;#if TARGET_CARBONstatic pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param);#endif// ============================================================================// wxTopLevelWindowMac implementation// ============================================================================// ---------------------------------------------------------------------------// Carbon Events// ---------------------------------------------------------------------------#if TARGET_CARBONextern long wxMacTranslateKey(unsigned char key, unsigned char code) ;static const EventTypeSpec eventList[] ={ { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } , { kEventClassKeyboard, kEventRawKeyDown } , { kEventClassKeyboard, kEventRawKeyRepeat } , { kEventClassKeyboard, kEventRawKeyUp } , { kEventClassKeyboard, kEventRawKeyModifiersChanged } , { kEventClassWindow , kEventWindowShown } , { kEventClassWindow , kEventWindowUpdate } , { kEventClassWindow , kEventWindowActivated } , { kEventClassWindow , kEventWindowDeactivated } , { kEventClassWindow , kEventWindowBoundsChanging } , { kEventClassWindow , kEventWindowBoundsChanged } , { kEventClassWindow , kEventWindowClose } , { kEventClassMouse , kEventMouseDown } , { kEventClassMouse , kEventMouseUp } , { kEventClassMouse , kEventMouseWheelMoved } , { kEventClassMouse , kEventMouseMoved } , { kEventClassMouse , kEventMouseDragged } ,} ;static pascal OSStatus TextInputEventHandler( EventHandlerCallRef handler , EventRef event , void *data ){ OSStatus result = eventNotHandledErr ; wxWindow* focus = wxWindow::FindFocus() ; char charCode ; UInt32 keyCode ; UInt32 modifiers ; Point point ; 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 ); switch ( GetEventKind( event ) ) { case kEventTextInputUnicodeForKeyEvent : // this is only called when no default handler has jumped in, eg a wxControl on a floater window does not // get its own kEventTextInputUnicodeForKeyEvent, so we route back the wxControl* control = wxDynamicCast( focus , wxControl ) ; if ( control ) { ControlHandle macControl = (ControlHandle) control->GetMacControl() ; if ( macControl ) { ::HandleControlKey( macControl , keyCode , charCode , modifiers ) ; result = noErr ; } } /* // this may lead to double events sent to a window in case all handlers have skipped the key down event UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ; UInt32 message = (keyCode << 8) + charCode; 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 : { WXEVENTREF formerEvent = wxTheApp->MacGetCurrentEvent() ; WXEVENTHANDLERCALLREF formerHandler = wxTheApp->MacGetCurrentEventHandlerCallRef() ; wxTheApp->MacSetCurrentEvent( event , handler ) ; if ( (focus != NULL) && wxTheApp->MacSendKeyDownEvent( focus , message , modifiers , when , point.h , point.v ) ) { result = noErr ; } wxTheApp->MacSetCurrentEvent( formerEvent , formerHandler ) ; } 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.SetTimestamp(when); wxWindow* focus = wxWindow::FindFocus() ; event.SetEventObject(focus); if ( focus && (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 ( focus && (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 ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & optionKey ) { event.m_keyCode = WXK_ALT ; event.SetEventType( ( modifiers & optionKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; focus->GetEventHandler()->ProcessEvent( event ) ; } if ( focus && (modifiers ^ wxTheApp->s_lastModifiers ) & cmdKey ) { event.m_keyCode = WXK_COMMAND ; event.SetEventType( ( modifiers & cmdKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; focus->GetEventHandler()->ProcessEvent( event ) ; } wxTheApp->s_lastModifiers = modifiers ; } break ; } return result ;}pascal OSStatus MouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data ){ OSStatus result = eventNotHandledErr ; wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ; Point point ; UInt32 modifiers = 0; EventMouseButton button = 0 ; UInt32 click = 0 ; GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL, sizeof( Point ), NULL, &point ); GetEventParameter( event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof( UInt32 ), NULL, &modifiers ); GetEventParameter( event, kEventParamMouseButton, typeMouseButton, NULL, sizeof( EventMouseButton ), NULL, &button ); GetEventParameter( event, kEventParamClickCount, typeUInt32, NULL, sizeof( UInt32 ), NULL, &click ); if ( button == 0 || GetEventKind( event ) == kEventMouseUp ) modifiers += btnState ; // temporary hack to support true two button mouse if ( button == kEventMouseButtonSecondary ) { modifiers |= controlKey ; } WindowRef window ; short windowPart = ::FindWindow(point, &window); // either we really are active or we are capturing mouse events if ( (IsWindowActive(window) && windowPart == inContent) || (wxTheApp->s_captureWindow && wxTheApp->s_captureWindow->MacGetTopLevelWindow() == toplevelWindow) ) { switch ( GetEventKind( event ) ) { case kEventMouseDown : toplevelWindow->MacFireMouseEvent( mouseDown , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; result = noErr ; break ; case kEventMouseUp : toplevelWindow->MacFireMouseEvent( mouseUp , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; result = noErr ; break ; case kEventMouseMoved : wxTheApp->MacHandleMouseMovedEvent( point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; result = noErr ; break ; case kEventMouseDragged : toplevelWindow->MacFireMouseEvent( nullEvent , point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; result = noErr ; break ; case kEventMouseWheelMoved : { //bClearTooltip = false; EventMouseWheelAxis axis = kEventMouseWheelAxisY; SInt32 delta = 0; Point mouseLoc = {0, 0}; if (::GetEventParameter(event, kEventParamMouseWheelAxis, typeMouseWheelAxis, NULL, sizeof(EventMouseWheelAxis), NULL, &axis) == noErr && ::GetEventParameter(event, kEventParamMouseWheelDelta, typeLongInteger, NULL, sizeof(SInt32), NULL, &delta) == noErr && ::GetEventParameter(event, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &mouseLoc) == noErr) { wxMouseEvent wheelEvent(wxEVT_MOUSEWHEEL); wheelEvent.m_x = mouseLoc.h; wheelEvent.m_y = mouseLoc.v; wheelEvent.m_wheelRotation = delta; wheelEvent.m_wheelDelta = 1; wheelEvent.m_linesPerAction = 1; wxWindow* currentMouseWindow = NULL; wxWindow::MacGetWindowFromPoint(wxPoint(mouseLoc.h, mouseLoc.v), ¤tMouseWindow); if (currentMouseWindow) { currentMouseWindow->GetEventHandler()->ProcessEvent(wheelEvent); result = noErr; } } } break ; default : break ; } } return result ;}static pascal OSStatus WindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data ){ OSStatus result = eventNotHandledErr ; OSStatus err = noErr ; UInt32 attributes; WindowRef windowRef ; wxTopLevelWindowMac* toplevelWindow = (wxTopLevelWindowMac*) data ; GetEventParameter( event, kEventParamDirectObject, typeWindowRef, NULL, sizeof( WindowRef ), NULL, &windowRef ); switch( GetEventKind( event ) ) { case kEventWindowUpdate : if ( !wxPendingDelete.Member(toplevelWindow) ) toplevelWindow->MacUpdate( EventTimeToTicks( GetEventTime( event ) ) ) ; result = noErr ; break ; case kEventWindowActivated : toplevelWindow->MacActivate( EventTimeToTicks( GetEventTime( event ) ) , true) ; result = noErr ; break ; case kEventWindowDeactivated : toplevelWindow->MacActivate( EventTimeToTicks( GetEventTime( event ) ) , false) ; result = noErr ; break ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -