📄 window.cpp
字号:
void wxWindowMac::Init(){ m_peer = NULL ; m_frozenness = 0 ; m_macAlpha = 255 ;#if WXWIN_COMPATIBILITY_2_4 m_backgroundTransparent = false;#endif#if wxMAC_USE_CORE_GRAPHICS m_cgContextRef = NULL ;#endif // as all windows are created with WS_VISIBLE style... m_isShown = true; m_hScrollBar = NULL ; m_vScrollBar = NULL ; m_macBackgroundBrush = wxNullBrush ; m_macIsUserPane = true; m_clipChildren = false ; m_cachedClippedRectValid = false ; // we need a valid font for the encodings wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));}wxWindowMac::~wxWindowMac(){ SendDestroyEvent(); m_isBeingDeleted = true; MacInvalidateBorders() ;#ifndef __WXUNIVERSAL__ // VS: make sure there's no wxFrame with last focus set to us: for ( wxWindow *win = GetParent(); win; win = win->GetParent() ) { wxFrame *frame = wxDynamicCast(win, wxFrame); if ( frame ) { if ( frame->GetLastFocus() == this ) frame->SetLastFocus((wxWindow*)NULL); break; } }#endif // destroy children before destroying this window itself DestroyChildren(); // wxRemoveMacControlAssociation( this ) ; // If we delete an item, we should initialize the parent panel, // because it could now be invalid. wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow); if ( tlw ) { if ( tlw->GetDefaultItem() == (wxButton*) this) tlw->SetDefaultItem(NULL); } if ( m_peer && m_peer->Ok() ) { // in case the callback might be called during destruction wxRemoveMacControlAssociation( this) ; ::RemoveEventHandler( (EventHandlerRef ) m_macControlEventHandler ) ; // we currently are not using this hook // ::SetControlColorProc( *m_peer , NULL ) ; m_peer->Dispose() ; } if ( g_MacLastWindow == this ) g_MacLastWindow = NULL ; wxFrame* frame = wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame ) ; if ( frame ) { if ( frame->GetLastFocus() == this ) frame->SetLastFocus( NULL ) ; } // delete our drop target if we've got one#if wxUSE_DRAG_AND_DROP if ( m_dropTarget != NULL ) { delete m_dropTarget; m_dropTarget = NULL; }#endif delete m_peer ;}WXWidget wxWindowMac::GetHandle() const{ return (WXWidget) m_peer->GetControlRef() ;}void wxWindowMac::MacInstallEventHandler( WXWidget control ){ wxAssociateControlWithMacControl( (ControlRef) control , this ) ; InstallControlEventHandler( (ControlRef)control , GetwxMacWindowEventHandlerUPP(), GetEventTypeCount(eventList), eventList, this, (EventHandlerRef *)&m_macControlEventHandler);#if !TARGET_API_MAC_OSX if ( (ControlRef) control == m_peer->GetControlRef() ) { m_peer->SetData<ControlUserPaneDrawUPP>(kControlEntireControl, kControlUserPaneDrawProcTag, GetwxMacControlUserPaneDrawProc()) ; m_peer->SetData<ControlUserPaneHitTestUPP>(kControlEntireControl, kControlUserPaneHitTestProcTag, GetwxMacControlUserPaneHitTestProc()) ; m_peer->SetData<ControlUserPaneTrackingUPP>(kControlEntireControl, kControlUserPaneTrackingProcTag, GetwxMacControlUserPaneTrackingProc()) ; m_peer->SetData<ControlUserPaneIdleUPP>(kControlEntireControl, kControlUserPaneIdleProcTag, GetwxMacControlUserPaneIdleProc()) ; m_peer->SetData<ControlUserPaneKeyDownUPP>(kControlEntireControl, kControlUserPaneKeyDownProcTag, GetwxMacControlUserPaneKeyDownProc()) ; m_peer->SetData<ControlUserPaneActivateUPP>(kControlEntireControl, kControlUserPaneActivateProcTag, GetwxMacControlUserPaneActivateProc()) ; m_peer->SetData<ControlUserPaneFocusUPP>(kControlEntireControl, kControlUserPaneFocusProcTag, GetwxMacControlUserPaneFocusProc()) ; m_peer->SetData<ControlUserPaneBackgroundUPP>(kControlEntireControl, kControlUserPaneBackgroundProcTag, GetwxMacControlUserPaneBackgroundProc()) ; }#endif}// Constructorbool wxWindowMac::Create(wxWindowMac *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name){ wxCHECK_MSG( parent, false, wxT("can't create wxWindowMac without parent") ); if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) ) return false; m_windowVariant = parent->GetWindowVariant() ; if ( m_macIsUserPane ) { Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; UInt32 features = 0 | kControlSupportsEmbedding | kControlSupportsLiveFeedback | kControlGetsFocusOnClick// | kControlHasSpecialBackground// | kControlSupportsCalcBestRect | kControlHandlesTracking | kControlSupportsFocus | kControlWantsActivate | kControlWantsIdle ; m_peer = new wxMacControl(this) ; OSStatus err =::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds, features , m_peer->GetControlRefAddr() ); verify_noerr( err ); MacPostControlCreate(pos, size) ; }#ifndef __WXUNIVERSAL__ // Don't give scrollbars to wxControls unless they ask for them if ( (! IsKindOf(CLASSINFO(wxControl)) && ! IsKindOf(CLASSINFO(wxStatusBar))) || (IsKindOf(CLASSINFO(wxControl)) && ((style & wxHSCROLL) || (style & wxVSCROLL)))) { MacCreateScrollBars( style ) ; }#endif wxWindowCreateEvent event(this); GetEventHandler()->AddPendingEvent(event); return true;}void wxWindowMac::MacChildAdded(){ if ( m_vScrollBar ) m_vScrollBar->Raise() ; if ( m_hScrollBar ) m_hScrollBar->Raise() ;}void wxWindowMac::MacPostControlCreate(const wxPoint& pos, const wxSize& size){ wxASSERT_MSG( m_peer != NULL && m_peer->Ok() , wxT("No valid mac control") ) ; m_peer->SetReference( (URefCon) this ) ; GetParent()->AddChild( this ); MacInstallEventHandler( (WXWidget) m_peer->GetControlRef() ); ControlRef container = (ControlRef) GetParent()->GetHandle() ; wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ; ::EmbedControl( m_peer->GetControlRef() , container ) ; GetParent()->MacChildAdded() ; // adjust font, controlsize etc DoSetWindowVariant( m_windowVariant ) ; m_peer->SetLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics) ) ; if (!m_macIsUserPane) SetInitialSize(size); SetCursor( *wxSTANDARD_CURSOR ) ;}void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant ){ // Don't assert, in case we set the window variant before // the window is created // wxASSERT( m_peer->Ok() ) ; m_windowVariant = variant ; if (m_peer == NULL || !m_peer->Ok()) return; ControlSize size ; ThemeFontID themeFont = kThemeSystemFont ; // we will get that from the settings later // and make this NORMAL later, but first // we have a few calculations that we must fix switch ( variant ) { case wxWINDOW_VARIANT_NORMAL : size = kControlSizeNormal; themeFont = kThemeSystemFont ; break ; case wxWINDOW_VARIANT_SMALL : size = kControlSizeSmall; themeFont = kThemeSmallSystemFont ; break ; case wxWINDOW_VARIANT_MINI : if (UMAGetSystemVersion() >= 0x1030 ) { // not always defined in the headers size = 3 ; themeFont = 109 ; } else { size = kControlSizeSmall; themeFont = kThemeSmallSystemFont ; } break ; case wxWINDOW_VARIANT_LARGE : size = kControlSizeLarge; themeFont = kThemeSystemFont ; break ; default: wxFAIL_MSG(_T("unexpected window variant")); break ; } m_peer->SetData<ControlSize>(kControlEntireControl, kControlSizeTag, &size ) ; wxFont font ; font.MacCreateThemeFont( themeFont ) ; SetFont( font ) ;}void wxWindowMac::MacUpdateControlFont(){ m_peer->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ; Refresh() ;}bool wxWindowMac::SetFont(const wxFont& font){ bool retval = wxWindowBase::SetFont( font ); MacUpdateControlFont() ; return retval;}bool wxWindowMac::SetForegroundColour(const wxColour& col ){ bool retval = wxWindowBase::SetForegroundColour( col ); if (retval) MacUpdateControlFont(); return retval;}bool wxWindowMac::SetBackgroundColour(const wxColour& col ){ if ( !wxWindowBase::SetBackgroundColour(col) && m_hasBgCol ) return false ; wxBrush brush ; wxColour newCol(GetBackgroundColour()); if ( newCol == wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) ) brush.MacSetTheme( kThemeBrushDocumentWindowBackground ) ; else if ( newCol == wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE ) ) brush.MacSetTheme( kThemeBrushDialogBackgroundActive ) ; else brush.SetColour( newCol ) ; MacSetBackgroundBrush( brush ) ; MacUpdateControlFont() ; return true ;}void wxWindowMac::MacSetBackgroundBrush( const wxBrush &brush ){ m_macBackgroundBrush = brush ; m_peer->SetBackground( brush ) ;}bool wxWindowMac::MacCanFocus() const{ // TODO : evaluate performance hits by looking up this value, eventually cache the results for a 1 sec or so // CAUTION : the value returned currently is 0 or 2, I've also found values of 1 having the same meaning, // but the value range is nowhere documented Boolean keyExistsAndHasValidFormat ; CFIndex fullKeyboardAccess = CFPreferencesGetAppIntegerValue( CFSTR("AppleKeyboardUIMode" ) , kCFPreferencesCurrentApplication, &keyExistsAndHasValidFormat ); if ( keyExistsAndHasValidFormat && fullKeyboardAccess > 0 ) { return true ; } else { UInt32 features = 0 ; m_peer->GetFeatures( &features ) ; return features & ( kControlSupportsFocus | kControlGetsFocusOnClick ) ; }}void wxWindowMac::SetFocus(){ if ( !AcceptsFocus() ) return ; wxWindow* former = FindFocus() ; if ( former == this ) return ; // as we cannot rely on the control features to find out whether we are in full keyboard mode, // we can only leave in case of an error OSStatus err = m_peer->SetFocus( kControlFocusNextPart ) ; if ( err == errCouldntSetFocus ) return ; SetUserFocusWindow( (WindowRef)MacGetTopLevelWindowRef() );#if !TARGET_API_MAC_OSX // emulate carbon events when running under CarbonLib where they are not natively available if ( former ) { EventRef evRef = NULL ; err = MacCreateEvent( NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) , kEventAttributeUserEvent , &evRef ); verify_noerr( err ); wxMacCarbonEvent cEvent( evRef ) ; cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) former->GetHandle() ) ; cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNoPart ) ; wxMacWindowEventHandler( NULL , evRef , former ) ; ReleaseEvent( evRef ) ; } // send new focus event { EventRef evRef = NULL ; err = MacCreateEvent( NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) , kEventAttributeUserEvent , &evRef ); verify_noerr( err ); wxMacCarbonEvent cEvent( evRef ) ; cEvent.SetParameter<ControlRef>( kEventParamDirectObject , (ControlRef) GetHandle() ) ; cEvent.SetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode , kControlFocusNextPart ) ; wxMacWindowEventHandler( NULL , evRef , this ) ; ReleaseEvent( evRef ) ; }#endif}void wxWindowMac::DoCaptureMouse(){ wxApp::s_captureWindow = this ;}wxWindow * wxWindowBase::GetCapture(){ return wxApp::s_captureWindow ;}void wxWindowMac::DoReleaseMouse(){ wxApp::s_captureWindow = NULL ;}#if wxUSE_DRAG_AND_DROPvoid wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget){ if ( m_dropTarget != NULL ) delete m_dropTarget; m_dropTarget = pDropTarget; if ( m_dropTarget != NULL ) { // TODO: }}#endif// Old-style File Manager Drag & Dropvoid wxWindowMac::DragAcceptFiles(bool accept){ // TODO:}// Returns the size of the native control. In the case of the toplevel window// this is the content area root controlvoid wxWindowMac::MacGetPositionAndSizeFromControl(int& x, int& y, int& w, int& h) const{ wxFAIL_MSG( wxT("Not currently supported") ) ;}// From a wx position / size calculate the appropriate size of the native controlbool wxWindowMac::MacGetBoundsForControl(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -