]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/classic/toplevel.cpp
fixed wxOverlay to handle wxWindowDC/wxClientDC in the same way wxMac does
[wxWidgets.git] / src / mac / classic / toplevel.cpp
index efa241a3d14a51d132a8b732600ad2a3dc930dca..aa5bc6892dc62db276adbd12d5aa676d6b8fe144 100644 (file)
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////
-// Name:        mac/toplevel.cpp
+// Name:        src/mac/classic/toplevel.cpp
 // Purpose:     implements wxTopLevelWindow for Mac
 // Author:      Stefan Csomor
 // Modified by:
 // Purpose:     implements wxTopLevelWindow for Mac
 // Author:      Stefan Csomor
 // Modified by:
 // headers
 // ----------------------------------------------------------------------------
 
 // headers
 // ----------------------------------------------------------------------------
 
-#ifdef __GNUG__
-    #pragma implementation "toplevel.h"
-#endif
-
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
     #pragma hdrstop
 #endif
 
     #pragma hdrstop
 #endif
 
+#include "wx/toplevel.h"
+
 #ifndef WX_PRECOMP
     #include "wx/app.h"
 #ifndef WX_PRECOMP
     #include "wx/app.h"
-    #include "wx/toplevel.h"
     #include "wx/frame.h"
     #include "wx/string.h"
     #include "wx/log.h"
     #include "wx/frame.h"
     #include "wx/string.h"
     #include "wx/log.h"
@@ -39,7 +36,6 @@
 
 #include "wx/mac/uma.h"
 #include "wx/mac/aga.h"
 
 #include "wx/mac/uma.h"
 #include "wx/mac/aga.h"
-#include "wx/app.h"
 #include "wx/tooltip.h"
 #include "wx/dnd.h"
 #if wxUSE_SYSTEM_OPTIONS
 #include "wx/tooltip.h"
 #include "wx/dnd.h"
 #if wxUSE_SYSTEM_OPTIONS
@@ -211,7 +207,7 @@ static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , Event
 
                 event.m_x = point.h;
                 event.m_y = point.v;
 
                 event.m_x = point.h;
                 event.m_y = point.v;
-                event.m_timeStamp = when;
+                event.SetTimestamp(when);
                 wxWindow* focus = wxWindow::FindFocus() ;
                 event.SetEventObject(focus);
 
                 wxWindow* focus = wxWindow::FindFocus() ;
                 event.SetEventObject(focus);
 
@@ -269,17 +265,17 @@ pascal OSStatus MouseEventHandler( EventHandlerCallRef handler , EventRef event
     if ( button == 0 || GetEventKind( event ) == kEventMouseUp )
         modifiers += btnState ;
 
     if ( button == 0 || GetEventKind( event ) == kEventMouseUp )
         modifiers += btnState ;
 
-       // temporary hack to support true two button mouse
-       if ( button == kEventMouseButtonSecondary )
-       {
-               modifiers |= controlKey ;
-       }
+    // 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
 
     WindowRef window ;
     short windowPart = ::FindWindow(point, &window);
 
     // either we really are active or we are capturing mouse events
 
-    if ( (IsWindowActive(window) && windowPart == inContent) || 
+    if ( (IsWindowActive(window) && windowPart == inContent) ||
         (wxTheApp->s_captureWindow && wxTheApp->s_captureWindow->MacGetTopLevelWindow() == toplevelWindow) )
     {
         switch ( GetEventKind( event ) )
         (wxTheApp->s_captureWindow && wxTheApp->s_captureWindow->MacGetTopLevelWindow() == toplevelWindow) )
     {
         switch ( GetEventKind( event ) )
@@ -314,17 +310,17 @@ pascal OSStatus MouseEventHandler( EventHandlerCallRef handler , EventRef event
                                         NULL, sizeof(Point), NULL, &mouseLoc) == noErr)
                     {
                         wxMouseEvent wheelEvent(wxEVT_MOUSEWHEEL);
                                         NULL, sizeof(Point), NULL, &mouseLoc) == noErr)
                     {
                         wxMouseEvent wheelEvent(wxEVT_MOUSEWHEEL);
-                       
+
                         wheelEvent.m_x = mouseLoc.h;
                         wheelEvent.m_y = mouseLoc.v;
                         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), &currentMouseWindow);
                         wheelEvent.m_wheelRotation = delta;
                         wheelEvent.m_wheelDelta = 1;
                         wheelEvent.m_linesPerAction = 1;
 
                         wxWindow* currentMouseWindow = NULL;
                         wxWindow::MacGetWindowFromPoint(wxPoint(mouseLoc.h, mouseLoc.v), &currentMouseWindow);
-                       
+
                         if (currentMouseWindow)
                         {
                             currentMouseWindow->GetEventHandler()->ProcessEvent(wheelEvent);
                         if (currentMouseWindow)
                         {
                             currentMouseWindow->GetEventHandler()->ProcessEvent(wheelEvent);
@@ -369,10 +365,10 @@ static pascal OSStatus WindowEventHandler( EventHandlerCallRef handler , EventRe
                 toplevelWindow->MacActivate( EventTimeToTicks( GetEventTime( event ) ) , false) ;
             result = noErr ;
             break ;
                 toplevelWindow->MacActivate( EventTimeToTicks( GetEventTime( event ) ) , false) ;
             result = noErr ;
             break ;
-       case kEventWindowShown :
-               toplevelWindow->Refresh() ;
-               result = noErr ;
-               break ;
+        case kEventWindowShown :
+            toplevelWindow->Refresh() ;
+            result = noErr ;
+            break ;
         case kEventWindowClose :
                 toplevelWindow->Close() ;
             result = noErr ;
         case kEventWindowClose :
                 toplevelWindow->Close() ;
             result = noErr ;
@@ -406,12 +402,12 @@ static pascal OSStatus WindowEventHandler( EventHandlerCallRef handler , EventRe
 
                 wxSize formerSize = toplevelWindow->GetSize() ;
 
 
                 wxSize formerSize = toplevelWindow->GetSize() ;
 
-                if ( (attributes & kWindowBoundsChangeSizeChanged ) || 
+                if ( (attributes & kWindowBoundsChangeSizeChanged ) ||
                     ( attributes & kWindowBoundsChangeOriginChanged ) )
                     toplevelWindow->SetSize( newContentRect.left , newContentRect.top ,
                         newContentRect.right - newContentRect.left ,
                         newContentRect.bottom - newContentRect.top, wxSIZE_USE_EXISTING);
                     ( attributes & kWindowBoundsChangeOriginChanged ) )
                     toplevelWindow->SetSize( newContentRect.left , newContentRect.top ,
                         newContentRect.right - newContentRect.left ,
                         newContentRect.bottom - newContentRect.top, wxSIZE_USE_EXISTING);
-    
+
                 int x , y , w , h ;
                 toplevelWindow->GetPosition( &x , &y ) ;
                 toplevelWindow->GetSize( &w , &h ) ;
                 int x , y , w , h ;
                 toplevelWindow->GetPosition( &x , &y ) ;
                 toplevelWindow->GetSize( &w , &h ) ;
@@ -421,10 +417,10 @@ static pascal OSStatus WindowEventHandler( EventHandlerCallRef handler , EventRe
                 {
                     SetEventParameter( event , kEventParamCurrentBounds , typeQDRectangle, sizeof( adjustedRect ) , &adjustedRect ) ;
                 }
                 {
                     SetEventParameter( event , kEventParamCurrentBounds , typeQDRectangle, sizeof( adjustedRect ) , &adjustedRect ) ;
                 }
-                
+
                 if ( toplevelWindow->GetSize() != formerSize )
                     toplevelWindow->Update() ;
                 if ( toplevelWindow->GetSize() != formerSize )
                     toplevelWindow->Update() ;
-        
+
                 result = noErr ;
             }
             break ;
                 result = noErr ;
             }
             break ;
@@ -502,19 +498,19 @@ void wxRemoveMacWindowAssociation(wxTopLevelWindowMac *win)
 
 WXWindow wxTopLevelWindowMac::s_macWindowInUpdate = NULL;
 wxTopLevelWindowMac *wxTopLevelWindowMac::s_macDeactivateWindow = NULL;
 
 WXWindow wxTopLevelWindowMac::s_macWindowInUpdate = NULL;
 wxTopLevelWindowMac *wxTopLevelWindowMac::s_macDeactivateWindow = NULL;
-bool wxTopLevelWindowMac::s_macWindowCompositing = FALSE;
+bool wxTopLevelWindowMac::s_macWindowCompositing = false;
 
 void wxTopLevelWindowMac::Init()
 {
     m_iconized =
 
 void wxTopLevelWindowMac::Init()
 {
     m_iconized =
-    m_maximizeOnShow = FALSE;
+    m_maximizeOnShow = false;
     m_macNoEraseUpdateRgn = NewRgn() ;
     m_macNeedsErasing = false ;
     m_macWindow = NULL ;
     m_macNoEraseUpdateRgn = NewRgn() ;
     m_macNeedsErasing = false ;
     m_macWindow = NULL ;
-    m_macUsesCompositing = FALSE ;
+    m_macUsesCompositing = false ;
 #if TARGET_CARBON
     m_macEventHandler = NULL ;
 #if TARGET_CARBON
     m_macEventHandler = NULL ;
- #endif
+#endif
 }
 
 class wxMacDeferredWindowDeleter : public wxObject
 }
 
 class wxMacDeferredWindowDeleter : public wxObject
@@ -554,7 +550,7 @@ bool wxTopLevelWindowMac::Create(wxWindow *parent,
     if ( parent )
         parent->AddChild(this);
 
     if ( parent )
         parent->AddChild(this);
 
-    return TRUE;
+    return true;
 }
 
 wxTopLevelWindowMac::~wxTopLevelWindowMac()
 }
 
 wxTopLevelWindowMac::~wxTopLevelWindowMac()
@@ -645,7 +641,7 @@ void  wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title,
     OSStatus err = noErr ;
     SetName(name);
     m_windowStyle = style;
     OSStatus err = noErr ;
     SetName(name);
     m_windowStyle = style;
-    m_isShown = FALSE;
+    m_isShown = false;
 
     // create frame.
 
 
     // create frame.
 
@@ -742,21 +738,21 @@ void  wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title,
 #endif
 #endif
 
 #endif
 #endif
 
-    //this setup lets us have compositing and non-compositing 
-    //windows in the same application. 
-  
-#if UNIVERSAL_INTERFACES_VERSION >= 0x0400  
+    //this setup lets us have compositing and non-compositing
+    //windows in the same application.
+
+#if UNIVERSAL_INTERFACES_VERSION >= 0x0400
     if ( wxTopLevelWindowMac::s_macWindowCompositing )
     {
         attr |= kWindowCompositingAttribute;
     if ( wxTopLevelWindowMac::s_macWindowCompositing )
     {
         attr |= kWindowCompositingAttribute;
-        m_macUsesCompositing = TRUE;
+        m_macUsesCompositing = true;
     }
     else
 #endif
     {
     }
     else
 #endif
     {
-        m_macUsesCompositing = FALSE;
+        m_macUsesCompositing = false;
     }
     }
-    
+
 #if TARGET_CARBON
     if ( HasFlag(wxFRAME_SHAPED) )
     {
 #if TARGET_CARBON
     if ( HasFlag(wxFRAME_SHAPED) )
     {
@@ -809,8 +805,8 @@ void  wxTopLevelWindowMac::MacCreateRealWindow( const wxString& title,
 bool wxTopLevelWindowMac::MacEnableCompositing( bool useCompositing )
 {
     bool oldval = s_macWindowCompositing;
 bool wxTopLevelWindowMac::MacEnableCompositing( bool useCompositing )
 {
     bool oldval = s_macWindowCompositing;
-    s_macWindowCompositing = useCompositing; 
-    return oldval; 
+    s_macWindowCompositing = useCompositing;
+    return oldval;
 }
 
 void wxTopLevelWindowMac::MacGetPortParams(WXPOINTPTR localOrigin, WXRECTPTR clipRect, WXWindow *window  , wxWindowMac** rootwin)
 }
 
 void wxTopLevelWindowMac::MacGetPortParams(WXPOINTPTR localOrigin, WXRECTPTR clipRect, WXWindow *window  , wxWindowMac** rootwin)
@@ -906,7 +902,7 @@ void wxTopLevelWindowMac::MacFireMouseEvent(
 
     event.m_leftDown = isDown && !controlDown;
 
 
     event.m_leftDown = isDown && !controlDown;
 
-    event.m_middleDown = FALSE;
+    event.m_middleDown = false;
     event.m_rightDown = isDown && controlDown;
 
     if ( kind == mouseDown )
     event.m_rightDown = isDown && controlDown;
 
     if ( kind == mouseDown )
@@ -950,7 +946,7 @@ void wxTopLevelWindowMac::MacFireMouseEvent(
             if ( abs( localwhere.h - gs_lastWhere.h ) < 3 && abs( localwhere.v - gs_lastWhere.v ) < 3 )
             {
                 // This is not right if the second mouse down
             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 occured in a differen window. We
+                // event occurred in a different window. We
                 // correct this in MacDispatchMouseEvent.
                 if ( controlDown )
                     event.SetEventType(wxEVT_RIGHT_DCLICK ) ;
                 // correct this in MacDispatchMouseEvent.
                 if ( controlDown )
                     event.SetEventType(wxEVT_RIGHT_DCLICK ) ;
@@ -971,7 +967,7 @@ void wxTopLevelWindowMac::MacFireMouseEvent(
     event.m_x += m_x;
     event.m_y += m_y;
 
     event.m_x += m_x;
     event.m_y += m_y;
 
-    event.m_timeStamp = timestamp;
+    event.SetTimestamp(timestamp);
     event.SetEventObject(this);
     if ( wxTheApp->s_captureWindow )
     {
     event.SetEventObject(this);
     if ( wxTheApp->s_captureWindow )
     {
@@ -1051,7 +1047,7 @@ void wxTopLevelWindowMac::MacActivate( long timestamp , bool inIsActivating )
         s_macDeactivateWindow=NULL;
     MacDelayedDeactivation(timestamp);
     wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating , m_windowId);
         s_macDeactivateWindow=NULL;
     MacDelayedDeactivation(timestamp);
     wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating , m_windowId);
-    event.m_timeStamp = timestamp ;
+    event.SetTimestamp(timestamp);
     event.SetEventObject(this);
 
     GetEventHandler()->ProcessEvent(event);
     event.SetEventObject(this);
 
     GetEventHandler()->ProcessEvent(event);
@@ -1063,13 +1059,13 @@ void wxTopLevelWindowMac::MacActivate( long timestamp , bool inIsActivating )
     long osVersion = UMAGetSystemVersion();
     if (osVersion >= 0x1000 && osVersion < 0x1020 )
     {
     long osVersion = UMAGetSystemVersion();
     if (osVersion >= 0x1000 && osVersion < 0x1020 )
     {
-        Refresh(TRUE);
+        Refresh(true);
     }
     else
     {
         // for the moment we have to resolve some redrawing issues like this
         // the OS is stealing some redrawing areas as soon as it draws a control
     }
     else
     {
         // for the moment we have to resolve some redrawing issues like this
         // the OS is stealing some redrawing areas as soon as it draws a control
-        Refresh(TRUE);
+        Refresh(true);
     }
 }
 
     }
 }
 
@@ -1083,18 +1079,23 @@ void wxTopLevelWindowMac::MacKeyDown( WXEVENTREF ev )
 
 void wxTopLevelWindowMac::SetTitle(const wxString& title)
 {
 
 void wxTopLevelWindowMac::SetTitle(const wxString& title)
 {
-    wxWindow::SetTitle( title ) ;
+    wxWindow::SetLabel( title ) ;
     UMASetWTitle( (WindowRef)m_macWindow , title , m_font.GetEncoding() ) ;
 }
 
     UMASetWTitle( (WindowRef)m_macWindow , title , m_font.GetEncoding() ) ;
 }
 
+wxString wxTopLevelWindowMac::GetTitle() const
+{
+    return wxWindow::GetLabel();
+}
+
 bool wxTopLevelWindowMac::Show(bool show)
 {
     if ( !wxWindow::Show(show) )
 bool wxTopLevelWindowMac::Show(bool show)
 {
     if ( !wxWindow::Show(show) )
-        return FALSE;
+        return false;
 
     if (show)
     {
 
     if (show)
     {
-        #if wxUSE_SYSTEM_OPTIONS       //code contributed by Ryan Wilcox December 18, 2003
+        #if wxUSE_SYSTEM_OPTIONS    //code contributed by Ryan Wilcox December 18, 2003
         if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1) )
         {
            ::ShowWindow( (WindowRef)m_macWindow );
         if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1) )
         {
            ::ShowWindow( (WindowRef)m_macWindow );
@@ -1134,7 +1135,7 @@ bool wxTopLevelWindowMac::Show(bool show)
         Refresh() ;
     }
 
         Refresh() ;
     }
 
-    return TRUE;
+    return true;
 }
 
 void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height)
 }
 
 void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height)
@@ -1199,10 +1200,10 @@ void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height)
             wxFrame* frame = (wxFrame*) this ;
 #if wxUSE_STATUSBAR
             frame->PositionStatusBar();
             wxFrame* frame = (wxFrame*) this ;
 #if wxUSE_STATUSBAR
             frame->PositionStatusBar();
-#endif            
+#endif
 #if wxUSE_TOOLBAR
             frame->PositionToolBar();
 #if wxUSE_TOOLBAR
             frame->PositionToolBar();
-#endif            
+#endif
         }
         if ( doMove )
             wxWindowMac::MacTopLevelWindowChangedPosition() ; // like this only children will be notified
         }
         if ( doMove )
             wxWindowMac::MacTopLevelWindowChangedPosition() ; // like this only children will be notified
@@ -1294,7 +1295,7 @@ void wxTopLevelWindowMac::MacInvalidate( const WXRECTPTR rect, bool eraseBackgro
 
 bool wxTopLevelWindowMac::SetShape(const wxRegion& region)
 {
 
 bool wxTopLevelWindowMac::SetShape(const wxRegion& region)
 {
-    wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), FALSE,
+    wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), false,
                  _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
 
 #if TARGET_CARBON
                  _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
 
 #if TARGET_CARBON
@@ -1321,9 +1322,9 @@ bool wxTopLevelWindowMac::SetShape(const wxRegion& region)
 
     // Tell the window manager that the window has changed shape
     ReshapeCustomWindow((WindowRef)MacGetWindowRef());
 
     // Tell the window manager that the window has changed shape
     ReshapeCustomWindow((WindowRef)MacGetWindowRef());
-    return TRUE;
+    return true;
 #else
 #else
-    return FALSE;
+    return false;
 #endif
 }
 
 #endif
 }
 
@@ -1390,10 +1391,10 @@ static void wxShapedMacWindowStructureRegion(WindowRef window, RgnHandle rgn)
     if (cachedRegion)
     {
         Rect windowRect;
     if (cachedRegion)
     {
         Rect windowRect;
-        wxShapedMacWindowGetPos(window, &windowRect);  //how big is the window
-        CopyRgn(cachedRegion, rgn);            //make a copy of our cached region
+        wxShapedMacWindowGetPos(window, &windowRect);    //how big is the window
+        CopyRgn(cachedRegion, rgn);        //make a copy of our cached region
         OffsetRgn(rgn, windowRect.left, windowRect.top); // position it over window
         OffsetRgn(rgn, windowRect.left, windowRect.top); // position it over window
-        //MapRgn(rgn, &mMaskSize, &windowRect);        //scale it to our actual window size
+        //MapRgn(rgn, &mMaskSize, &windowRect);    //scale it to our actual window size
     }
 }
 
     }
 }
 
@@ -1428,7 +1429,7 @@ static SInt32 wxShapedMacWindowHitTest(WindowRef window,SInt32 param)
     static RgnHandle tempRgn=nil;
 
     if(!tempRgn)
     static RgnHandle tempRgn=nil;
 
     if(!tempRgn)
-       tempRgn=NewRgn();
+        tempRgn=NewRgn();
 
     SetPt(&hitPoint,LoWord(param),HiWord(param));//get the point clicked
 
 
     SetPt(&hitPoint,LoWord(param),HiWord(param));//get the point clicked
 
@@ -1461,4 +1462,3 @@ static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16
 
 #endif
 // ---------------------------------------------------------------------------
 
 #endif
 // ---------------------------------------------------------------------------
-