]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/glcanvas.cpp
default button on older systems was not shown with OK, but empty, resulting in wxID_C...
[wxWidgets.git] / src / mac / carbon / glcanvas.cpp
index 44215b6b75824b9678a9a68717f3131d14498dea..f5e7c59eb0cfef51ae5e015b444a85b098f19eaa 100644 (file)
@@ -1,36 +1,31 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        glcanvas.cpp
-// Purpose:     wxGLCanvas, for using OpenGL with wxWindows under Macintosh
+// Name:        src/mac/carbon/glcanvas.cpp
+// Purpose:     wxGLCanvas, for using OpenGL with wxWidgets under Macintosh
 // Author:      Stefan Csomor
 // Modified by:
 // Created:     1998-01-01
 // RCS-ID:      $Id$
 // Copyright:   (c) Stefan Csomor
-// Licence:       wxWindows licence
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
-#ifdef __GNUG__
-#pragma implementation "glcanvas.h"
-#endif
-
 #include "wx/wxprec.h"
 
 #if defined(__BORLANDC__)
-#pragma hdrstop
+    #pragma hdrstop
 #endif
 
-#include "wx/setup.h"
-
 #if wxUSE_GLCANVAS
 
+#include "wx/glcanvas.h"
+
 #ifndef WX_PRECOMP
-#include "wx/frame.h"
+    #include "wx/frame.h"
+    #include "wx/log.h"
 #endif
 
 #include "wx/settings.h"
-#include "wx/log.h"
 
-#include "wx/glcanvas.h"
 #include "wx/mac/uma.h"
 
 // DLL options compatibility check:
@@ -48,12 +43,12 @@ wxGLContext::wxGLContext(
                          )
 {
     m_window = win;
-    
-    m_drawable = (AGLDrawable) UMAGetWindowPort(MAC_WXHWND(win->MacGetRootWindow()));
-    
+
+    m_drawable = (AGLDrawable) UMAGetWindowPort(MAC_WXHWND(win->MacGetTopLevelWindowRef()));
+
     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") );
@@ -97,15 +92,12 @@ void wxGLContext::Update()
 
 void wxGLContext::SetColour(const wxChar *colour)
 {
-    float r = 0.0;
-    float g = 0.0;
-    float b = 0.0;
-    wxColour *col = wxTheColourDatabase->FindColour(colour);
-    if (col)
+    wxColour col = wxTheColourDatabase->Find(colour);
+    if (col.Ok())
     {
-        r = (float)(col->Red()/256.0);
-        g = (float)(col->Green()/256.0);
-        b = (float)(col->Blue()/256.0);
+        float r = (float)(col.Red()/256.0);
+        float g = (float)(col.Green()/256.0);
+        float b = (float)(col.Blue()/256.0);
         glColor3f( r, g, b);
     }
 }
@@ -154,14 +146,14 @@ wxGLCanvas::~wxGLCanvas()
 static AGLPixelFormat ChoosePixelFormat(const int *attribList)
 {
     GLint data[512];
-    GLint defaultAttribs[] = { AGL_RGBA, 
-        AGL_DOUBLEBUFFER, 
-        AGL_MINIMUM_POLICY, 
+    GLint defaultAttribs[] = { AGL_RGBA,
+        AGL_DOUBLEBUFFER,
+        AGL_MINIMUM_POLICY,
         AGL_DEPTH_SIZE, 1,  // use largest available depth buffer
-        AGL_RED_SIZE, 1, 
-        AGL_GREEN_SIZE, 1, 
-        AGL_BLUE_SIZE, 1, 
-        AGL_ALPHA_SIZE, 0, 
+        AGL_RED_SIZE, 1,
+        AGL_GREEN_SIZE, 1,
+        AGL_BLUE_SIZE, 1,
+        AGL_ALPHA_SIZE, 0,
         AGL_NONE };
     GLint *attribs;
     if (!attribList)
@@ -171,7 +163,7 @@ static AGLPixelFormat ChoosePixelFormat(const int *attribList)
     else
     {
         int arg=0, p=0;
-        
+
         data[p++] = AGL_MINIMUM_POLICY; // make _SIZE tags behave more like GLX
         while( (attribList[arg]!=0) && (p<512) )
         {
@@ -194,9 +186,9 @@ static AGLPixelFormat ChoosePixelFormat(const int *attribList)
                 data[p++]=AGL_BLUE_SIZE; data[p++]=attribList[arg++]; break;
             case WX_GL_MIN_ALPHA:
                 data[p++]=AGL_ALPHA_SIZE; data[p++]=attribList[arg++]; break;
-            case WX_GL_DEPTH_SIZE: 
+            case WX_GL_DEPTH_SIZE:
                 data[p++]=AGL_DEPTH_SIZE; data[p++]=attribList[arg++]; break;
-            case WX_GL_STENCIL_SIZE: 
+            case WX_GL_STENCIL_SIZE:
                 data[p++]=AGL_STENCIL_SIZE; data[p++]=attribList[arg++]; break;
             case WX_GL_MIN_ACCUM_RED:
                 data[p++]=AGL_ACCUM_RED_SIZE; data[p++]=attribList[arg++]; break;
@@ -209,12 +201,12 @@ static AGLPixelFormat ChoosePixelFormat(const int *attribList)
             default:
                 break;
             }
-        }       
-        data[p] = 0; 
-        
+        }
+        data[p] = 0;
+
         attribs = data;
     }
-    
+
     return aglChoosePixelFormat(NULL, 0, attribs);
 }
 
@@ -222,15 +214,17 @@ bool wxGLCanvas::Create(wxWindow *parent, const wxGLContext *shared, wxWindowID
                         const wxPoint& pos, const wxSize& size, long style, const wxString& name,
                         int *attribList, const wxPalette& palette)
 {
+    m_macCanvasIsShown = false ;
+    m_glContext = 0 ;
     wxWindow::Create( parent, id, pos, size, style, name );
-    
+
     AGLPixelFormat fmt = ChoosePixelFormat(attribList);
     wxCHECK_MSG( fmt, false, wxT("Couldn't create OpenGl pixel format") );
-    
+
     m_glContext = new wxGLContext(fmt, this, palette, shared);
     m_macCanvasIsShown = true ;
     aglDestroyPixelFormat(fmt);
-    
+
     return true;
 }
 
@@ -252,30 +246,30 @@ void wxGLCanvas::SetViewport()
     // adjust glViewport to just this window
     int x = 0 ;
     int y = 0 ;
-    
+
     wxWindow* iter = this ;
     while( iter->GetParent() )
     {
-       iter = iter->GetParent() ;
+        iter = iter->GetParent() ;
     }
-    
+
     if ( iter && iter->IsTopLevel() )
     {
-           MacClientToRootWindow( &x , &y ) ;
-           int width, height;
-           GetClientSize(& width, & height);
-           Rect bounds ;
-           GetWindowPortBounds( MAC_WXHWND(MacGetRootWindow()) , &bounds ) ;
-           GLint parms[4] ;
-           parms[0] = x ;
-           parms[1] = bounds.bottom - bounds.top - ( y + height ) ;
-           parms[2] = width ;
-           parms[3] = height ;
-           
-           if ( !m_macCanvasIsShown )
-               parms[0] += 20000 ;
-           aglSetInteger( m_glContext->m_glContext , AGL_BUFFER_RECT , parms ) ;
-       }
+        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 ;
+
+        if ( !m_macCanvasIsShown )
+            parms[0] += 20000 ;
+        aglSetInteger( m_glContext->m_glContext , AGL_BUFFER_RECT , parms ) ;
+   }
 }
 
 void wxGLCanvas::OnSize(wxSizeEvent& event)
@@ -319,11 +313,11 @@ void wxGLCanvas::SetColour(const wxChar *colour)
         m_glContext->SetColour(colour);
 }
 
-bool wxGLCanvas::Show(bool show) 
+bool wxGLCanvas::Show(bool show)
 {
     if ( !wxWindow::Show( show ) )
         return FALSE ;
-        
+/*
     if ( !show )
     {
         if ( m_macCanvasIsShown )
@@ -334,18 +328,19 @@ bool wxGLCanvas::Show(bool show)
     }
     else
     {
-        if ( MacIsReallyShown() && !m_macCanvasIsShown )
+        if ( m_peer->IsVisible()&& !m_macCanvasIsShown )
         {
             m_macCanvasIsShown = true ;
             SetViewport() ;
         }
     }
+*/
     return TRUE ;
 }
 
-void wxGLCanvas::MacSuperShown( bool show ) 
+void wxGLCanvas::MacVisibilityChanged()
 {
-    if ( !show )
+    if ( !MacIsReallyShown() )
     {
         if ( m_macCanvasIsShown )
         {
@@ -355,14 +350,13 @@ void wxGLCanvas::MacSuperShown( bool show )
     }
     else
     {
-        if ( MacIsReallyShown() && !m_macCanvasIsShown )
+        if ( !m_macCanvasIsShown )
         {
             m_macCanvasIsShown = true ;
             SetViewport() ;
         }
     }
-        
-    wxWindow::MacSuperShown( show ) ;
+    wxWindowMac::MacVisibilityChanged() ;
 }
 
 //---------------------------------------------------------------------------