wxClientDC::wxClientDC(wxWindow *window) { m_window = window ; wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ; if (!rootwindow) return; WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ; wxPoint origin = window->GetClientAreaOrigin() ; wxSize size = window->GetClientSize() ; int x , y ; x = origin.x ; y = origin.y ; window->MacWindowToRootWindow( &x , &y ) ; m_macLocalOrigin.x = x ; m_macLocalOrigin.y = y ; SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ; SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ; OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ; CopyRgn( (RgnHandle) m_macBoundaryClipRgn ,(RgnHandle) m_macCurrentClipRgn ) ; m_macPort = UMAGetWindowPort( windowref ) ; m_ok = TRUE ; SetBackground(window->MacGetBackgroundBrush()); SetFont( window->GetFont() ) ; }
wxGLContext::wxGLContext( AGLPixelFormat fmt, wxGLCanvas *win, const wxPalette& palette, const wxGLContext *other /* for sharing display lists */ ) { m_window = win; #ifndef __LP64__ m_drawable = (AGLDrawable) UMAGetWindowPort(MAC_WXHWND(win->MacGetTopLevelWindowRef())); #endif m_glContext = aglCreateContext(fmt, other ? other->m_glContext : NULL); wxCHECK_RET( m_glContext, wxT("Couldn't create OpenGl context") ); GLboolean b; #ifndef __LP64__ b = aglSetDrawable(m_glContext, m_drawable); aglEnable(m_glContext , AGL_BUFFER_RECT ) ; #else b = aglSetHIViewRef(m_glContext, (HIViewRef) win->GetHandle()); #endif wxCHECK_RET( b, wxT("Couldn't bind OpenGl context") ); b = aglSetCurrentContext(m_glContext); wxCHECK_RET( b, wxT("Couldn't activate OpenGl context") ); }
wxSize wxListBox::DoGetBestSize() const { int lbWidth = 100; // some defaults int lbHeight = 110; int wLine; { wxMacPortStateHelper st( UMAGetWindowPort( (WindowRef) MacGetTopLevelWindowRef() ) ) ; if ( m_font.Ok() ) { ::TextFont( m_font.MacGetFontNum() ) ; ::TextSize( m_font.MacGetFontSize() ) ; ::TextFace( m_font.MacGetFontStyle() ) ; } else { ::TextFont( kFontIDMonaco ) ; ::TextSize( 9 ); ::TextFace( 0 ) ; } // Find the widest line for(int i = 0; i < GetCount(); i++) { wxString str(GetString(i)); #if wxUSE_UNICODE Point bounds={0,0} ; SInt16 baseline ; ::GetThemeTextDimensions( wxMacCFStringHolder( str , m_font.GetEncoding() ) , kThemeCurrentPortFont, kThemeStateActive, false, &bounds, &baseline ); wLine = bounds.h ; #else wLine = ::TextWidth( str.c_str() , 0 , str.Length() ) ; #endif lbWidth = wxMax(lbWidth, wLine); } // Add room for the scrollbar lbWidth += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); // And just a bit more int cy = 12 ; int cx = ::TextWidth( "X" , 0 , 1 ) ; lbWidth += cx ; // don't make the listbox too tall (limit height to around 10 items) but don't // make it too small neither lbHeight = (cy+4) * wxMin(wxMax(GetCount(), 3), 10); } return wxSize(lbWidth, lbHeight); }
wxSize wxChoice::DoGetBestSize() const { int lbWidth = GetCount() > 0 ? 20 : 100; // some defaults int lbHeight = 20; int wLine; #if TARGET_CARBON long metric ; GetThemeMetric(kThemeMetricPopupButtonHeight , &metric ); lbHeight = metric ; #endif { wxMacPortStateHelper st( UMAGetWindowPort( (WindowRef) MacGetTopLevelWindowRef() ) ) ; if ( m_font.Ok() ) { ::TextFont( m_font.MacGetFontNum() ) ; ::TextSize( m_font.MacGetFontSize() ) ; ::TextFace( m_font.MacGetFontStyle() ) ; } else { ::TextFont( kFontIDMonaco ) ; ::TextSize( 9 ); ::TextFace( 0 ) ; } // Find the widest line for(int i = 0; i < GetCount(); i++) { wxString str(GetString(i)); #if wxUSE_UNICODE Point bounds={0,0} ; SInt16 baseline ; ::GetThemeTextDimensions( wxMacCFStringHolder( str , m_font.GetEncoding() ) , kThemeCurrentPortFont, kThemeStateActive, false, &bounds, &baseline ); wLine = bounds.h ; #else wLine = ::TextWidth( str.c_str() , 0 , str.Length() ) ; #endif lbWidth = wxMax(lbWidth, wLine); } // Add room for the popup arrow lbWidth += 2 * lbHeight ; // And just a bit more int cx = ::TextWidth( "X" , 0 , 1 ) ; lbWidth += cx ; } return wxSize(lbWidth, lbHeight); }
wxWindowDC::wxWindowDC(wxWindow *window) { m_window = window ; wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ; WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ; int x , y ; x = y = 0 ; window->MacWindowToRootWindow( &x , &y ) ; m_macLocalOrigin.x = x ; m_macLocalOrigin.y = y ; CopyRgn( (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ; CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ; m_macPort = UMAGetWindowPort( windowref ) ; m_ok = TRUE ; SetBackground(window->MacGetBackgroundBrush()); }
wxGLContext::wxGLContext( AGLPixelFormat fmt, wxGLCanvas *win, const wxPalette& palette, const wxGLContext *other /* for sharing display lists */ ) { m_window = win; m_drawable = (AGLDrawable) UMAGetWindowPort(MAC_WXHWND(win->MacGetRootWindow())); m_glContext = aglCreateContext(fmt, other ? other->m_glContext : NULL); wxCHECK_RET( m_glContext, wxT("Couldn't create OpenGl context") ); GLboolean b; b = aglSetDrawable(m_glContext, m_drawable); wxCHECK_RET( b, wxT("Couldn't bind OpenGl context") ); aglEnable(m_glContext , AGL_BUFFER_RECT ) ; b = aglSetCurrentContext(m_glContext); wxCHECK_RET( b, wxT("Couldn't activate OpenGl context") ); }
void wxTopLevelWindowMac::MacFireMouseEvent( wxUint16 kind , wxInt32 x , wxInt32 y ,wxUint32 modifiers , long timestamp ) { wxMouseEvent event(wxEVT_LEFT_DOWN); bool isDown = !(modifiers & btnState) ; // 1 is for up bool controlDown = modifiers & controlKey ; // for simulating right mouse event.m_leftDown = isDown && !controlDown; event.m_middleDown = FALSE; event.m_rightDown = isDown && controlDown; if ( kind == mouseDown ) { if ( controlDown ) event.SetEventType(wxEVT_RIGHT_DOWN ) ; else event.SetEventType(wxEVT_LEFT_DOWN ) ; } else if ( kind == mouseUp ) { if ( controlDown ) event.SetEventType(wxEVT_RIGHT_UP ) ; else event.SetEventType(wxEVT_LEFT_UP ) ; } else { event.SetEventType(wxEVT_MOTION ) ; } event.m_shiftDown = modifiers & shiftKey; event.m_controlDown = modifiers & controlKey; event.m_altDown = modifiers & optionKey; event.m_metaDown = modifiers & cmdKey; Point localwhere ; localwhere.h = x ; localwhere.v = y ; GrafPtr port ; ::GetPort( &port ) ; ::SetPort( UMAGetWindowPort( (WindowRef)m_macWindow ) ) ; ::GlobalToLocal( &localwhere ) ; ::SetPort( port ) ; if ( kind == mouseDown ) { if ( timestamp - gs_lastWhen <= (long) GetDblTime() ) { if ( abs( localwhere.h - gs_lastWhere.h ) < 3 && abs( localwhere.v - gs_lastWhere.v ) < 3 ) { // This is not right if the second mouse down // event occurred in a different window. We // correct this in MacDispatchMouseEvent. if ( controlDown ) event.SetEventType(wxEVT_RIGHT_DCLICK ) ; else event.SetEventType(wxEVT_LEFT_DCLICK ) ; } gs_lastWhen = 0 ; } else { gs_lastWhen = timestamp ; } gs_lastWhere = localwhere ; } event.m_x = localwhere.h; event.m_y = localwhere.v; event.m_x += m_x; event.m_y += m_y; event.SetTimestamp(timestamp); event.SetEventObject(this); if ( wxTheApp->s_captureWindow ) { int x = event.m_x ; int y = event.m_y ; wxTheApp->s_captureWindow->ScreenToClient( &x , &y ) ; event.m_x = x ; event.m_y = y ; event.SetEventObject( wxTheApp->s_captureWindow ) ; wxTheApp->s_captureWindow->GetEventHandler()->ProcessEvent( event ) ; if ( kind == mouseUp ) { wxTheApp->s_captureWindow = NULL ; if ( !wxIsBusy() ) { m_cursor.MacInstall() ; } } } else { MacDispatchMouseEvent( event ) ; } }