bool wxGLCanvas::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name, const int *attribList, const wxPalette& WXUNUSED(palette)) { m_needsUpdate = false; m_macCanvasIsShown = false; m_glFormat = WXGLChoosePixelFormat(attribList); if ( !m_glFormat ) return false; if ( !wxWindow::Create(parent, id, pos, size, style, name) ) return false; m_dummyContext = WXGLCreateContext(m_glFormat, NULL); static GLint gCurrentBufferName = 1; m_bufferName = gCurrentBufferName++; aglSetInteger (m_dummyContext, AGL_BUFFER_NAME, &m_bufferName); AGLDrawable drawable = (AGLDrawable)GetWindowPort(MAC_WXHWND(MacGetTopLevelWindowRef())); aglSetDrawable(m_dummyContext, drawable); m_macCanvasIsShown = true; return true; }
void wxGLCanvas::SetViewport() { #ifndef __LP64__ // viewport is initially set to entire port // adjust glViewport to just this window int x = 0 ; int y = 0 ; wxWindow* iter = this ; while( iter->GetParent() ) { iter = iter->GetParent() ; } if ( iter && iter->IsTopLevel() ) { MacClientToRootWindow( &x , &y ) ; int width, height; GetClientSize(& width, & height); Rect bounds ; #if 0 // TODO in case we adopt point vs pixel coordinates, this will make the conversion GetWindowPortBounds( MAC_WXHWND(MacGetTopLevelWindowRef()) , &bounds ) ; HIRect hiRect = CGRectMake( x, y, width, height ) ; HIRectConvert( &hiRect, kHICoordSpace72DPIGlobal, NULL, kHICoordSpaceScreenPixel, NULL) ; HIRect hiBounds = CGRectMake( 0, 0, bounds.right - bounds.left , bounds.bottom - bounds.top ) ; HIRectConvert( &hiBounds, kHICoordSpace72DPIGlobal, NULL, kHICoordSpaceScreenPixel, NULL) ; GLint parms[4] ; parms[0] = hiRect.origin.x ; parms[1] = hiBounds.size.height - (hiRect.origin.y + hiRect.size.height) ; parms[2] = hiRect.size.width ; parms[3] = hiRect.size.height ; #else GetWindowPortBounds( MAC_WXHWND(MacGetTopLevelWindowRef()) , &bounds ) ; GLint parms[4] ; parms[0] = x ; parms[1] = bounds.bottom - bounds.top - ( y + height ) ; parms[2] = width ; parms[3] = height ; #endif if ( !m_macCanvasIsShown ) parms[0] += 20000 ; aglSetInteger( m_glContext->m_glContext , AGL_BUFFER_RECT , parms ) ; aglUpdateContext(m_glContext->m_glContext); } #endif }
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); }
// Added by Mark Newsam // When a page is added or deleted to the notebook this function updates // information held in the control so that it matches the order // the user would expect. // void wxNotebook::MacSetupTabs() { m_peer->SetMaximum( GetPageCount() ) ; wxNotebookPage *page; ControlTabInfoRecV1 info; const size_t countPages = GetPageCount(); for (size_t ii = 0; ii < countPages; ii++) { page = m_pages[ii]; info.version = kControlTabInfoVersionOne; info.iconSuiteID = 0; wxMacCFStringHolder cflabel( page->GetLabel(), m_font.GetEncoding() ) ; info.name = cflabel ; m_peer->SetData<ControlTabInfoRecV1>( ii + 1, kControlTabInfoTag, &info ) ; if ( GetImageList() && GetPageImage(ii) >= 0 && UMAGetSystemVersion() >= 0x1020 ) { const wxBitmap bmap = GetImageList()->GetBitmap( GetPageImage( ii ) ) ; if ( bmap.Ok() ) { ControlButtonContentInfo info ; wxMacCreateBitmapButton( &info, bmap ) ; OSStatus err = m_peer->SetData<ControlButtonContentInfo>( ii + 1, kControlTabImageContentTag, &info ); wxASSERT_MSG( err == noErr , wxT("Error when setting icon on tab") ) ; wxMacReleaseBitmapButton( &info ) ; } } m_peer->SetTabEnabled( ii + 1, true ) ; } #if wxMAC_USE_CORE_GRAPHICS Refresh(); #else Rect bounds; m_peer->GetRectInWindowCoords( &bounds ) ; InvalWindowRect( (WindowRef)MacGetTopLevelWindowRef(), &bounds ); #endif }
void wxGLCanvas::SetViewport() { if ( !m_needsUpdate ) return; m_needsUpdate = false; // AGLContext context = aglGetCurrentContext(); // if ( !context ) // return; // viewport is initially set to entire port, adjust it to just this window int x = 0, y = 0; MacClientToRootWindow(&x , &y); int width, height; GetClientSize(&width, &height); Rect bounds; GetWindowPortBounds(MAC_WXHWND(MacGetTopLevelWindowRef()) , &bounds); GLint parms[4]; parms[0] = x; parms[1] = bounds.bottom - bounds.top - ( y + height ); parms[2] = width; parms[3] = height; // move the buffer rect out of sight if we're hidden if ( !m_macCanvasIsShown ) parms[0] += 20000; if ( !aglSetInteger(m_dummyContext, AGL_BUFFER_RECT, parms) ) wxLogAGLError("aglSetInteger(AGL_BUFFER_RECT)"); if ( !aglEnable(m_dummyContext, AGL_BUFFER_RECT) ) wxLogAGLError("aglEnable(AGL_BUFFER_RECT)"); if ( !aglUpdateContext(m_dummyContext) ) wxLogAGLError("aglUpdateContext"); }
void VSTEffectDialog::BuildFancy() { struct { short top, left, bottom, right; } *rect; // Some effects like to have us get their rect before opening them. mEffect->callDispatcher(effEditGetRect, 0, 0, &rect, 0.0); #if defined(__WXMAC__) HIViewRef view; WindowRef win = (WindowRef) MacGetTopLevelWindowRef(); HIViewFindByID(HIViewGetRoot(win), kHIViewWindowContentID, &view); mEffect->callDispatcher(effEditOpen, 0, 0, win, 0.0); HIViewRef subview = HIViewGetFirstSubview(view); if (subview == NULL) { mEffect->callDispatcher(effEditClose, 0, 0, win, 0.0); mGui = false; BuildPlain(); return; } #elif defined(__WXMSW__) wxWindow *w = new wxPanel(this, wxID_ANY); mEffect->callDispatcher(effEditOpen, 0, 0, w->GetHWND(), 0.0); #else #endif mEffect->callDispatcher(effEditGetRect, 0, 0, &rect, 0.0); wxBoxSizer *vs = new wxBoxSizer(wxVERTICAL); wxBoxSizer *hs = new wxBoxSizer(wxHORIZONTAL); wxSizerItem *si; vs->Add(BuildProgramBar(), 0, wxCENTER); si = hs->Add(rect->right - rect->left, rect->bottom - rect->top); vs->Add(hs, 0, wxCENTER); vs->Add(CreateStdButtonSizer(this, ePreviewButton|eCancelButton|eOkButton), 0, wxEXPAND); SetSizerAndFit(vs); wxPoint pos = si->GetPosition(); #if defined(__WXMAC__) HIViewPlaceInSuperviewAt(subview, pos.x, pos.y); // Some VST effects do not work unless the default handler is removed since // it captures many of the events that the plugins need. But, it must be // done last since proper window sizing will not occur otherwise. ::RemoveEventHandler((EventHandlerRef)MacGetEventHandler()); // Install a bare minimum handler so we can capture the window close event. If // it's not captured, we will crash at Audacity termination since the window // is still on the wxWidgets toplevel window lists, but it's already gone. mHandlerUPP = NewEventHandlerUPP(EventHandler); InstallWindowEventHandler(win, mHandlerUPP, GetEventTypeCount(eventList), eventList, this, &mHandlerRef); #elif defined(__WXMSW__) w->SetPosition(pos); w->SetSize(si->GetSize()); #else #endif }
void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle) { wxToolBarTool *tool = (wxToolBarTool *)t; if ( tool->IsButton() ) { tool->UpdateToggleImage( toggle ) ; } } bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) { wxToolBarTool* tool = wx_static_cast( wxToolBarTool* , toolBase ) ; WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ; wxSize toolSize = GetToolSize() ; Rect toolrect = { 0, 0 , toolSize.y , toolSize.x } ; ControlRef controlHandle = NULL ; switch( tool->GetStyle() ) { case wxTOOL_STYLE_SEPARATOR : { wxASSERT( tool->GetControlHandle() == NULL ) ; toolSize.x /= 4 ; toolSize.y /= 4 ; if ( GetWindowStyleFlag() & wxTB_VERTICAL ) { toolrect.bottom = toolSize.y ; }