#define MAC_SCROLLBAR_SIZE 16
#include "wx/mac/uma.h"
+#ifndef __DARWIN__
+#include <Windows.h>
+#include <ToolUtils.h>
+#endif
#if wxUSE_DRAG_AND_DROP
#include "wx/dnd.h"
#if !USE_SHARED_LIBRARY
BEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase)
+ EVT_NC_PAINT(wxWindowMac::OnNcPaint)
EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground)
EVT_SYS_COLOUR_CHANGED(wxWindowMac::OnSysColourChanged)
EVT_INIT_DIALOG(wxWindowMac::OnInitDialog)
#endif
+#define wxMAC_DEBUG_REDRAW 0
+#ifndef wxMAC_DEBUG_REDRAW
+#define wxMAC_DEBUG_REDRAW 0
+#endif
+
+#define wxMAC_USE_THEME_BORDER 0
// ===========================================================================
// implementation
// ===========================================================================
-// ---------------------------------------------------------------------------
-// wxWindowMac utility functions
-// ---------------------------------------------------------------------------
-
-// Find an item given the Macintosh Window Reference
-
-wxList *wxWinMacWindowList = NULL;
-wxWindowMac *wxFindWinFromMacWindow(WindowRef inWindowRef)
-{
- wxNode *node = wxWinMacWindowList->Find((long)inWindowRef);
- if (!node)
- return NULL;
- return (wxWindowMac *)node->Data();
-}
-
-void wxAssociateWinWithMacWindow(WindowRef inWindowRef, wxWindowMac *win)
-{
- // adding NULL WindowRef is (first) surely a result of an error and
- // (secondly) breaks menu command processing
- wxCHECK_RET( inWindowRef != (WindowRef) NULL, "attempt to add a NULL WindowRef to window list" );
-
- if ( !wxWinMacWindowList->Find((long)inWindowRef) )
- wxWinMacWindowList->Append((long)inWindowRef, win);
-}
-
-void wxRemoveMacWindowAssociation(wxWindowMac *win)
-{
- wxWinMacWindowList->DeleteObject(win);
-}
// ----------------------------------------------------------------------------
// constructors and such
// ----------------------------------------------------------------------------
-WindowRef wxWindowMac::s_macWindowInUpdate = NULL;
-
void wxWindowMac::Init()
{
// generic
InitBase();
- m_macEraseOnRedraw = true ;
-
// MSW specific
m_doubleClickAllowed = 0;
m_winCaptured = FALSE;
// as all windows are created with WS_VISIBLE style...
m_isShown = TRUE;
- m_macWindowData = NULL ;
- m_macEraseOnRedraw = true ;
-
m_x = 0;
m_y = 0 ;
m_width = 0 ;
m_hScrollBar = NULL ;
m_vScrollBar = NULL ;
-
-#if wxUSE_DRAG_AND_DROP
- m_pDropTarget = NULL;
-#endif
}
// Destructor
if ( IsShown() ) {
wxWindowMac* iter = this ;
while( iter ) {
- if ( iter->m_macWindowData )
+ if ( iter->IsTopLevel() )
{
Refresh() ;
break ;
m_parent->RemoveChild(this);
DestroyChildren();
-
- if ( m_macWindowData )
- {
- wxToolTip::NotifyWindowDelete(m_macWindowData->m_macWindow) ;
- UMADisposeWindow( m_macWindowData->m_macWindow ) ;
- delete m_macWindowData ;
- wxRemoveMacWindowAssociation( this ) ;
- }
}
// Constructor
{
if ( gFocusWindow == this )
return ;
-
+
if ( AcceptsFocus() )
{
if (gFocusWindow )
wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ;
if ( control && control->GetMacControl() )
{
- UMASetKeyboardFocus( gFocusWindow->GetMacRootWindow() , control->GetMacControl() , kControlFocusNoPart ) ;
+ UMASetKeyboardFocus( (WindowRef) gFocusWindow->MacGetRootWindow() , (ControlHandle) control->GetMacControl() , kControlFocusNoPart ) ;
control->MacRedrawControl() ;
}
#endif
#endif // wxUSE_CARET
// panel wants to track the window which was the last to have focus in it
wxChildFocusEvent eventFocus(this);
- (void)GetEventHandler()->ProcessEvent(eventFocus);
+ GetEventHandler()->ProcessEvent(eventFocus);
#ifndef __WXUNIVERSAL__
wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ;
if ( control && control->GetMacControl() )
{
- UMASetKeyboardFocus( gFocusWindow->GetMacRootWindow() , control->GetMacControl() , kControlEditTextPart ) ;
+ UMASetKeyboardFocus( (WindowRef) gFocusWindow->MacGetRootWindow() , (ControlHandle) control->GetMacControl() , kControlEditTextPart ) ;
}
#endif
wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId);
if ( !wxWindowBase::Enable(enable) )
return FALSE;
- wxWindowList::Node *node = GetChildren().GetFirst();
- while ( node )
- {
- wxWindowMac *child = node->GetData();
- child->Enable(enable);
-
- node = node->GetNext();
- }
+ MacSuperEnabled( enable ) ;
return TRUE;
}
void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget)
{
- if ( m_pDropTarget != 0 ) {
- delete m_pDropTarget;
+ if ( m_dropTarget != 0 ) {
+ delete m_dropTarget;
}
- m_pDropTarget = pDropTarget;
- if ( m_pDropTarget != 0 )
+ m_dropTarget = pDropTarget;
+ if ( m_dropTarget != 0 )
{
// TODO
}
xx = m_x ;
yy = m_y ;
- if (GetParent())
+ if ( !IsTopLevel() && GetParent())
{
wxPoint pt(GetParent()->GetClientAreaOrigin());
xx -= pt.x;
menu->UpdateUI();
ClientToScreen( &x , &y ) ;
- ::InsertMenu( menu->GetHMenu() , -1 ) ;
- long menuResult = ::PopUpMenuSelect(menu->GetHMenu() ,y,x, 0) ;
+ ::InsertMenu( (MenuHandle) menu->GetHMenu() , -1 ) ;
+ long menuResult = ::PopUpMenuSelect((MenuHandle) menu->GetHMenu() ,y,x, 0) ;
menu->MacMenuSelect( this , TickCount() , HiWord(menuResult) , LoWord(menuResult) ) ;
::DeleteMenu( menu->MacGetMenuId() ) ;
menu->SetInvokingWindow(NULL);
void wxWindowMac::DoScreenToClient(int *x, int *y) const
{
- WindowRef window = GetMacRootWindow() ;
+ WindowRef window = (WindowRef) MacGetRootWindow() ;
Point localwhere = {0,0} ;
if(x) *x = localwhere.h ;
if(y) *y = localwhere.v ;
- MacRootWindowToClient( x , y ) ;
+ MacRootWindowToWindow( x , y ) ;
+ if ( x )
+ x -= MacGetLeftBorderSize() ;
+ if ( y )
+ y -= MacGetTopBorderSize() ;
}
void wxWindowMac::DoClientToScreen(int *x, int *y) const
{
- WindowRef window = GetMacRootWindow() ;
+ WindowRef window = (WindowRef) MacGetRootWindow() ;
- MacClientToRootWindow( x , y ) ;
+ if ( x )
+ x += MacGetLeftBorderSize() ;
+ if ( y )
+ y += MacGetTopBorderSize() ;
+
+ MacWindowToRootWindow( x , y ) ;
Point localwhere = { 0,0 };
if(x) localwhere.h = * x ;
GrafPtr port ;
::GetPort( &port ) ;
::SetPort( UMAGetWindowPort( window ) ) ;
- ::SetOrigin( 0 , 0 ) ;
+
::LocalToGlobal( &localwhere ) ;
::SetPort( port ) ;
if(x) *x = localwhere.h ;
void wxWindowMac::MacClientToRootWindow( int *x , int *y ) const
{
- if ( m_macWindowData == NULL)
+ wxPoint origin = GetClientAreaOrigin() ;
+ if(x) *x += origin.x ;
+ if(y) *y += origin.y ;
+
+ MacWindowToRootWindow( x , y ) ;
+}
+
+void wxWindowMac::MacRootWindowToClient( int *x , int *y ) const
+{
+ wxPoint origin = GetClientAreaOrigin() ;
+ MacRootWindowToWindow( x , y ) ;
+ if(x) *x -= origin.x ;
+ if(y) *y -= origin.y ;
+}
+
+void wxWindowMac::MacWindowToRootWindow( int *x , int *y ) const
+{
+ if ( !IsTopLevel() )
{
- if(x) *x += m_x + MacGetLeftBorderSize();
- if(y) *y += m_y + MacGetTopBorderSize();
- GetParent()->MacClientToRootWindow( x , y ) ;
+ if(x) *x += m_x ;
+ if(y) *y += m_y ;
+ GetParent()->MacWindowToRootWindow( x , y ) ;
}
}
-void wxWindowMac::MacRootWindowToClient( int *x , int *y ) const
+void wxWindowMac::MacRootWindowToWindow( int *x , int *y ) const
{
- if ( m_macWindowData == NULL)
+ if ( !IsTopLevel() )
{
- if(x) *x -= m_x + MacGetLeftBorderSize();
- if(y) *y -= m_y + MacGetTopBorderSize();
- GetParent()->MacRootWindowToClient( x , y ) ;
+ if(x) *x -= m_x ;
+ if(y) *y -= m_y ;
+ GetParent()->MacRootWindowToWindow( x , y ) ;
}
}
int totW = 10000 , totH = 10000;
while( iter )
{
- if ( iter->m_macWindowData )
+ if ( iter->IsTopLevel() )
{
totW = iter->m_width ;
totH = iter->m_height ;
if ( doMove || doResize )
{
- if ( m_macWindowData )
- {
- }
- else
- {
- // erase former position
- wxMacDrawingHelper focus( this ) ;
- if ( focus.Ok() )
- {
- Rect clientrect = { 0 , 0 , m_height , m_width } ;
- // ClipRect( &clientrect ) ;
- InvalWindowRect( GetMacRootWindow() , &clientrect ) ;
- }
- }
+ // erase former position
+
+ Refresh() ;
+
m_x = actualX ;
m_y = actualY ;
m_width = actualWidth ;
m_height = actualHeight ;
- if ( m_macWindowData )
- {
- if ( doMove )
- ::MoveWindow(m_macWindowData->m_macWindow, m_x, m_y , false); // don't make frontmost
-
- if ( doResize )
- ::SizeWindow(m_macWindowData->m_macWindow, m_width, m_height , true);
-
- // the OS takes care of invalidating and erasing the new area
- // we have erased the old one
-
- if ( IsKindOf( CLASSINFO( wxFrame ) ) )
- {
- wxFrame* frame = (wxFrame*) this ;
- frame->PositionStatusBar();
- frame->PositionToolBar();
- }
- if ( doMove )
- wxWindowMac::MacTopLevelWindowChangedPosition() ; // like this only children will be notified
- }
- else
- {
- // erase new position
-
- {
- wxMacDrawingHelper focus( this ) ;
- if ( focus.Ok() )
- {
- Rect clientrect = { 0 , 0 , m_height , m_width } ;
- // ClipRect( &clientrect ) ;
- InvalWindowRect( GetMacRootWindow() , &clientrect ) ;
- }
- }
-
- if ( doMove )
- wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
- }
+
+ // erase new position
+
+ Refresh() ;
+ if ( doMove )
+ wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
+
MacRepositionScrollBars() ;
if ( doMove )
{
// get the current size and position...
int currentX, currentY;
GetPosition(¤tX, ¤tY);
+
int currentW,currentH;
GetSize(¤tW, ¤tH);
return wxPoint(MacGetLeftBorderSize( ) , MacGetTopBorderSize( ) );
}
-// Makes an adjustment to the window position (for example, a frame that has
-// a toolbar that it manages itself).
-void wxWindowMac::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags)
-{
- if( !m_macWindowData )
- {
- if (((sizeFlags & wxSIZE_NO_ADJUSTMENTS) == 0) && GetParent())
- {
- wxPoint pt(GetParent()->GetClientAreaOrigin());
- x += pt.x; y += pt.y;
- }
- }
-}
-
-void wxWindowMac::SetTitle(const wxString& title)
+void wxWindow::SetTitle(const wxString& title)
{
m_label = title ;
-
- wxString label ;
-
- if( wxApp::s_macDefaultEncodingIsPC )
- label = wxMacMakeMacStringFromPC( title ) ;
- else
- label = title ;
-
- if ( m_macWindowData )
- UMASetWTitleC( m_macWindowData->m_macWindow , label ) ;
}
-wxString wxWindowMac::GetTitle() const
+wxString wxWindow::GetTitle() const
{
return m_label ;
}
if ( !wxWindowBase::Show(show) )
return FALSE;
- if ( m_macWindowData )
- {
- if (show)
- {
- ::ShowWindow( m_macWindowData->m_macWindow ) ;
- ::SelectWindow( m_macWindowData->m_macWindow ) ;
- // no need to generate events here, they will get them triggered by macos
- // actually they should be , but apparently they are not
- wxSize size(m_width, m_height);
- wxSizeEvent event(size, m_windowId);
- event.SetEventObject(this);
- GetEventHandler()->ProcessEvent(event);
- }
- else
- {
- ::HideWindow( m_macWindowData->m_macWindow ) ;
- }
- }
MacSuperShown( show ) ;
if ( !show )
{
- WindowRef window = GetMacRootWindow() ;
+ WindowRef window = (WindowRef) MacGetRootWindow() ;
wxWindowMac* win = wxFindWinFromMacWindow( window ) ;
if ( win && !win->m_isBeingDeleted )
Refresh() ;
}
}
+void wxWindowMac::MacSuperEnabled( bool enabled )
+{
+ if ( !IsTopLevel() )
+ {
+ // to be absolutely correct we'd have to invalidate (with eraseBkground
+ // because unter MacOSX the frames are drawn with an addXXX mode)
+ // the borders area
+ }
+ wxNode *node = GetChildren().First();
+ while ( node )
+ {
+ wxWindowMac *child = (wxWindowMac *)node->Data();
+ if ( child->m_isShown )
+ child->MacSuperEnabled( enabled ) ;
+ node = node->Next();
+ }
+}
+
bool wxWindowMac::MacIsReallyShown() const
{
if ( m_isShown && (m_parent != NULL) ) {
*y = ly ;
}
-void wxWindowMac::MacEraseBackground( Rect *rect )
-{
/*
- WindowRef window = GetMacRootWindow() ;
- if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) )
- {
- UMASetThemeWindowBackground( window , kThemeBrushDocumentWindowBackground , false ) ;
- }
- else if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
- {
- // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
- // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
- // either a non gray background color or a non control window
-
- wxWindowMac* parent = GetParent() ;
- while( parent )
- {
- if ( parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
- {
- // if we have any other colours in the hierarchy
- RGBBackColor( &parent->m_backgroundColour.GetPixel()) ;
- break ;
- }
- if( parent->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)parent)->GetMacControl() )
- {
- // if we have the normal colours in the hierarchy but another control etc. -> use it's background
- if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
- {
- UMAApplyThemeBackground(kThemeBackgroundTabPane, rect, kThemeStateActive,8,true);
- break ;
- }
- }
- else
- {
- // we have arrived at a non control item
- parent = NULL ;
- break ;
- }
- parent = parent->GetParent() ;
- }
- if ( !parent )
- {
- // if there is nothing special -> use default
- UMASetThemeWindowBackground( window , kThemeBrushDialogBackgroundActive , false ) ;
- }
- }
- else
- {
- RGBBackColor( &m_backgroundColour.GetPixel()) ;
- }
-
- EraseRect( rect ) ;
-
- for (wxNode *node = GetChildren().First(); node; node = node->Next())
- {
- wxWindowMac *child = (wxWindowMac*)node->Data();
-
- Rect clientrect = { child->m_x , child->m_y , child->m_x +child->m_width , child->m_y + child->m_height } ;
- SectRect( &clientrect , rect , &clientrect ) ;
-
- OffsetRect( &clientrect , -child->m_x , -child->m_y ) ;
- if ( child->GetMacRootWindow() == window && child->IsShown() )
- {
- wxMacDrawingClientHelper focus( this ) ;
- if ( focus.Ok() )
- {
- child->MacEraseBackground( &clientrect ) ;
- }
- }
- }
-*/
-}
-
+ * Rect is given in client coordinates, for further reading, read wxTopLevelWindowMac::InvalidateRect
+ * we always intersect with the entire window, not only with the client area
+ */
+
void wxWindowMac::Refresh(bool eraseBack, const wxRect *rect)
{
-// if ( !IsShown() )
-// return ;
-
- wxMacDrawingClientHelper focus( this ) ;
- if ( focus.Ok() )
+ if ( MacGetTopLevelWindow() == NULL )
+ return ;
+
+ wxPoint client ;
+ client = GetClientAreaOrigin( ) ;
+ Rect clientrect = { -client.y , -client.x , m_height - client.y , m_width - client.x} ;
+ if ( rect )
{
- wxPoint client ;
- client = GetClientAreaOrigin( ) ;
- Rect clientrect = { -client.y , -client.x , m_height - client.y , m_width - client.x} ;
- // ClipRect( &clientrect ) ;
-
- if ( rect )
- {
- Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
- SectRect( &clientrect , &r , &clientrect ) ;
- }
- InvalWindowRect( GetMacRootWindow() , &clientrect ) ;
+ Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
+ SectRect( &clientrect , &r , &clientrect ) ;
}
- if ( !eraseBack )
- m_macEraseOnRedraw = false ;
- else
- m_macEraseOnRedraw = true ;
-}
-
-// Responds to colour changes: passes event on to children.
-void wxWindowMac::OnSysColourChanged(wxSysColourChangedEvent& event)
-{
- wxNode *node = GetChildren().First();
- while ( node )
+ if ( !EmptyRect( &clientrect ) )
{
- // Only propagate to non-top-level windows
- wxWindowMac *win = (wxWindowMac *)node->Data();
- if ( win->GetParent() )
- {
- wxSysColourChangedEvent event2;
- event.m_eventObject = win;
- win->GetEventHandler()->ProcessEvent(event2);
- }
-
- node = node->Next();
+ int top = 0 , left = 0 ;
+
+ MacClientToRootWindow( &left , &top ) ;
+ OffsetRect( &clientrect , left , top ) ;
+
+ MacGetTopLevelWindow()->MacInvalidate( &clientrect , eraseBack ) ;
}
}
// We really dont move the mouse programmatically under mac
}
+const wxBrush& wxWindowMac::MacGetBackgroundBrush()
+{
+ if ( m_backgroundColour == wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE) )
+ {
+ m_macBackgroundBrush.SetMacTheme( kThemeBrushDocumentWindowBackground ) ;
+ }
+ else if ( m_backgroundColour == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) )
+ {
+ // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
+ // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
+ // either a non gray background color or a non control window
+
+ WindowRef window = (WindowRef) MacGetRootWindow() ;
+
+ wxWindowMac* parent = GetParent() ;
+ while( parent )
+ {
+ if ( parent->MacGetRootWindow() != window )
+ {
+ // we are in a different window on the mac system
+ parent = NULL ;
+ break ;
+ }
+
+ {
+ if ( parent->m_backgroundColour != wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE )
+ && parent->m_backgroundColour != wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE) )
+ {
+ // if we have any other colours in the hierarchy
+ m_macBackgroundBrush.SetColour( parent->m_backgroundColour ) ;
+ break ;
+ }
+ // if we have the normal colours in the hierarchy but another control etc. -> use it's background
+ if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
+ {
+ Rect extent = { 0 , 0 , 0 , 0 } ;
+ int x , y ;
+ x = y = 0 ;
+ wxSize size = GetSize() ;
+ parent->MacClientToRootWindow( &x , &y ) ;
+ extent.left = x ;
+ extent.top = y ;
+ extent.top-- ;
+ extent.right = x + size.x ;
+ extent.bottom = y + size.y ;
+ m_macBackgroundBrush.SetMacThemeBackground( kThemeBackgroundTabPane , (WXRECTPTR) &extent ) ; // todo eventually change for inactive
+ break ;
+ }
+ }
+ parent = parent->GetParent() ;
+ }
+ if ( !parent )
+ {
+ m_macBackgroundBrush.SetMacTheme( kThemeBrushDialogBackgroundActive ) ; // todo eventually change for inactive
+ }
+ }
+ else
+ {
+ m_macBackgroundBrush.SetColour( m_backgroundColour ) ;
+ }
+
+ return m_macBackgroundBrush ;
+
+}
+
void wxWindowMac::OnEraseBackground(wxEraseEvent& event)
{
- // TODO : probably we would adopt the EraseEvent structure
+ event.GetDC()->Clear() ;
+}
+
+void wxWindowMac::OnNcPaint( wxNcPaintEvent& event )
+{
+ wxWindowDC dc(this) ;
+ wxMacPortSetter helper(&dc) ;
+
+ MacPaintBorders( dc.m_macLocalOrigin.x , dc.m_macLocalOrigin.y) ;
}
int wxWindowMac::GetScrollPos(int orient) const
{
- if ( orient == wxHORIZONTAL )
- {
- if ( m_hScrollBar )
- return m_hScrollBar->GetThumbPosition() ;
- }
- else
- {
- if ( m_vScrollBar )
- return m_vScrollBar->GetThumbPosition() ;
- }
+ if ( orient == wxHORIZONTAL )
+ {
+ if ( m_hScrollBar )
+ return m_hScrollBar->GetThumbPosition() ;
+ }
+ else
+ {
+ if ( m_vScrollBar )
+ return m_vScrollBar->GetThumbPosition() ;
+ }
return 0;
}
// of positions that we can scroll.
int wxWindowMac::GetScrollRange(int orient) const
{
- if ( orient == wxHORIZONTAL )
- {
- if ( m_hScrollBar )
- return m_hScrollBar->GetRange() ;
- }
- else
- {
- if ( m_vScrollBar )
- return m_vScrollBar->GetRange() ;
- }
+ if ( orient == wxHORIZONTAL )
+ {
+ if ( m_hScrollBar )
+ return m_hScrollBar->GetRange() ;
+ }
+ else
+ {
+ if ( m_vScrollBar )
+ return m_vScrollBar->GetRange() ;
+ }
return 0;
}
int wxWindowMac::GetScrollThumb(int orient) const
{
- if ( orient == wxHORIZONTAL )
- {
- if ( m_hScrollBar )
- return m_hScrollBar->GetThumbSize() ;
- }
- else
- {
- if ( m_vScrollBar )
- return m_vScrollBar->GetThumbSize() ;
- }
+ if ( orient == wxHORIZONTAL )
+ {
+ if ( m_hScrollBar )
+ return m_hScrollBar->GetThumbSize() ;
+ }
+ else
+ {
+ if ( m_vScrollBar )
+ return m_vScrollBar->GetThumbSize() ;
+ }
return 0;
}
void wxWindowMac::SetScrollPos(int orient, int pos, bool refresh)
{
- if ( orient == wxHORIZONTAL )
- {
- if ( m_hScrollBar )
- m_hScrollBar->SetThumbPosition( pos ) ;
- }
- else
- {
- if ( m_vScrollBar )
- m_vScrollBar->SetThumbPosition( pos ) ;
- }
-}
-
-void wxWindowMac::MacCreateRealWindow( const wxString& title,
- const wxPoint& pos,
- const wxSize& size,
- long style,
- const wxString& name )
-{
- SetName(name);
- m_windowStyle = style;
- m_isShown = FALSE;
-
- // create frame.
-
- Rect theBoundsRect;
-
- m_x = (int)pos.x;
- m_y = (int)pos.y;
- if ( m_y < 50 )
- m_y = 50 ;
- if ( m_x < 20 )
- m_x = 20 ;
-
- m_width = size.x;
- if (m_width == -1)
- m_width = 20;
- m_height = size.y;
- if (m_height == -1)
- m_height = 20;
-
- m_macWindowData = new MacWindowData() ;
-
- ::SetRect(&theBoundsRect, m_x, m_y , m_x + m_width, m_y + m_height);
-
- // translate the window attributes in the appropriate window class and attributes
-
- WindowClass wclass = 0;
- WindowAttributes attr = kWindowNoAttributes ;
-
- if ( HasFlag(wxTINY_CAPTION_HORIZ) || HasFlag(wxTINY_CAPTION_VERT) )
+ if ( orient == wxHORIZONTAL )
{
- wclass = kFloatingWindowClass ;
- if ( HasFlag(wxTINY_CAPTION_VERT) )
- {
- attr |= kWindowSideTitlebarAttribute ;
- }
- }
- else if ( HasFlag( wxCAPTION ) )
- {
- if ( HasFlag( wxDIALOG_MODAL ) )
- {
- wclass = kMovableModalWindowClass ;
- }
- else
- {
- wclass = kDocumentWindowClass ;
- }
+ if ( m_hScrollBar )
+ m_hScrollBar->SetThumbPosition( pos ) ;
}
else
{
- wclass = kModalWindowClass ;
- }
-
- if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) )
- {
- attr |= kWindowFullZoomAttribute ;
- attr |= kWindowCollapseBoxAttribute ;
- }
- if ( HasFlag( wxRESIZE_BORDER ) )
- {
- attr |= kWindowResizableAttribute ;
+ if ( m_vScrollBar )
+ m_vScrollBar->SetThumbPosition( pos ) ;
}
- if ( HasFlag( wxSYSTEM_MENU ) )
- {
- attr |= kWindowCloseBoxAttribute ;
- }
-
- ::CreateNewWindow( wclass , attr , &theBoundsRect , &m_macWindowData->m_macWindow ) ;
- wxAssociateWinWithMacWindow( m_macWindowData->m_macWindow , this ) ;
- wxString label ;
- if( wxApp::s_macDefaultEncodingIsPC )
- label = wxMacMakeMacStringFromPC( title ) ;
- else
- label = title ;
- UMASetWTitleC( m_macWindowData->m_macWindow , label ) ;
- ::CreateRootControl( m_macWindowData->m_macWindow , &m_macWindowData->m_macRootControl ) ;
-
- m_macWindowData->m_macFocus = NULL ;
- m_macWindowData->m_macHasReceivedFirstActivate = true ;
-}
-
-void wxWindowMac::MacPaint( wxPaintEvent &event )
-{
}
-void wxWindowMac::MacPaintBorders( )
+void wxWindowMac::MacPaintBorders( int left , int top )
{
- if( m_macWindowData )
+ if( IsTopLevel() )
return ;
RGBColor white = { 0xFFFF, 0xFFFF , 0xFFFF } ;
if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) )
{
+#if wxMAC_USE_THEME_BORDER
+ Rect rect = { top , left , m_height + top , m_width + left } ;
+ SInt32 border = 0 ;
+ /*
+ GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
+ InsetRect( &rect , border , border );
+ DrawThemeListBoxFrame(&rect,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
+ */
+
+ DrawThemePrimaryGroup(&rect ,IsEnabled() ? kThemeStateActive : kThemeStateInactive) ;
+#else
bool sunken = HasFlag( wxSUNKEN_BORDER ) ;
RGBForeColor( &face );
- MoveTo( 0 , m_height - 2 );
- LineTo( 0 , 0 );
- LineTo( m_width - 2 , 0 );
+ MoveTo( left + 0 , top + m_height - 2 );
+ LineTo( left + 0 , top + 0 );
+ LineTo( left + m_width - 2 , top + 0 );
- MoveTo( 2 , m_height - 3 );
- LineTo( m_width - 3 , m_height - 3 );
- LineTo( m_width - 3 , 2 );
+ MoveTo( left + 2 , top + m_height - 3 );
+ LineTo( left + m_width - 3 , top + m_height - 3 );
+ LineTo( left + m_width - 3 , top + 2 );
RGBForeColor( sunken ? &face : &black );
- MoveTo( 0 , m_height - 1 );
- LineTo( m_width - 1 , m_height - 1 );
- LineTo( m_width - 1 , 0 );
+ MoveTo( left + 0 , top + m_height - 1 );
+ LineTo( left + m_width - 1 , top + m_height - 1 );
+ LineTo( left + m_width - 1 , top + 0 );
RGBForeColor( sunken ? &shadow : &white );
- MoveTo( 1 , m_height - 3 );
- LineTo( 1, 1 );
- LineTo( m_width - 3 , 1 );
+ MoveTo( left + 1 , top + m_height - 3 );
+ LineTo( left + 1, top + 1 );
+ LineTo( left + m_width - 3 , top + 1 );
RGBForeColor( sunken ? &white : &shadow );
- MoveTo( 1 , m_height - 2 );
- LineTo( m_width - 2 , m_height - 2 );
- LineTo( m_width - 2 , 1 );
+ MoveTo( left + 1 , top + m_height - 2 );
+ LineTo( left + m_width - 2 , top + m_height - 2 );
+ LineTo( left + m_width - 2 , top + 1 );
RGBForeColor( sunken ? &black : &face );
- MoveTo( 2 , m_height - 4 );
- LineTo( 2 , 2 );
- LineTo( m_width - 4 , 2 );
+ MoveTo( left + 2 , top + m_height - 4 );
+ LineTo( left + 2 , top + 2 );
+ LineTo( left + m_width - 4 , top + 2 );
+#endif
}
else if (HasFlag(wxSIMPLE_BORDER))
{
- Rect rect = { 0 , 0 , m_height , m_width } ;
+ Rect rect = { top , left , m_height + top , m_width + left } ;
RGBForeColor( &black ) ;
FrameRect( &rect ) ;
}
// Does a physical scroll
void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect)
{
- wxMacDrawingClientHelper focus( this ) ;
- if ( focus.Ok() )
+ wxClientDC dc(this) ;
+ wxMacPortSetter helper(&dc) ;
+
{
int width , height ;
GetClientSize( &width , &height ) ;
- Rect scrollrect = { 0 , 0 , height , width } ;
-
+ Rect scrollrect = { dc.YLOG2DEVMAC(0) , dc.XLOG2DEVMAC(0) , dc.YLOG2DEVMAC(height) , dc.XLOG2DEVMAC(width) } ;
RgnHandle updateRgn = NewRgn() ;
ClipRect( &scrollrect ) ;
if ( rect )
{
- Rect r = { rect->y , rect->x , rect->y + rect->height , rect->x + rect->width } ;
+ Rect r = { dc.YLOG2DEVMAC(rect->y) , dc.XLOG2DEVMAC(rect->x) , dc.YLOG2DEVMAC(rect->y + rect->height) ,
+ dc.XLOG2DEVMAC(rect->x + rect->width) } ;
SectRect( &scrollrect , &r , &scrollrect ) ;
}
ScrollRect( &scrollrect , dx , dy , updateRgn ) ;
- InvalWindowRgn( GetMacRootWindow() , updateRgn ) ;
+ InvalWindowRgn( (WindowRef) MacGetRootWindow() , updateRgn ) ;
DisposeRgn( updateRgn ) ;
}
}
}
-bool wxWindowMac::SetFont(const wxFont& font)
-{
- if ( !wxWindowBase::SetFont(font) )
- {
- // nothing to do
- return FALSE;
- }
-
- return TRUE;
-}
-
// Get the window with the focus
wxWindowMac *wxWindowBase::FindFocus()
{
void wxWindowMac::Clear()
{
- if ( m_macWindowData )
- {
- wxMacDrawingClientHelper helper ( this ) ;
- int w ,h ;
- wxPoint origin = GetClientAreaOrigin() ;
- GetClientSize( &w , &h ) ;
- ::SetThemeWindowBackground( m_macWindowData->m_macWindow , m_macWindowData->m_macWindowBackgroundTheme , false ) ;
- Rect r = { origin.y , origin.x, origin.y+h , origin.x+w } ;
- EraseRect( &r ) ;
- }
- else
- {
- wxClientDC dc(this);
- wxBrush brush(GetBackgroundColour(), wxSOLID);
- dc.SetBackground(brush);
- dc.Clear();
- }
+ wxClientDC dc(this);
+ wxBrush brush(GetBackgroundColour(), wxSOLID);
+ dc.SetBackground(brush);
+ dc.Clear();
}
// Setup background and foreground colours correctly
// Raise the window to the top of the Z order
void wxWindowMac::Raise()
{
- if ( m_macWindowData )
- {
- ::BringToFront( m_macWindowData->m_macWindow ) ;
- }
}
// Lower the window to the bottom of the Z order
void wxWindowMac::Lower()
{
- if ( m_macWindowData )
- {
- ::SendBehind( m_macWindowData->m_macWindow , NULL ) ;
- }
}
void wxWindowMac::DoSetClientSize(int width, int height)
bool wxWindowMac::MacGetWindowFromPointSub( const wxPoint &point , wxWindowMac** outWin )
{
- if ((point.x < m_x) || (point.y < m_y) ||
- (point.x > (m_x + m_width)) || (point.y > (m_y + m_height)))
- return FALSE;
+ if ( IsTopLevel() )
+ {
+ if ((point.x < 0) || (point.y < 0) ||
+ (point.x > (m_width)) || (point.y > (m_height)))
+ return FALSE;
+ }
+ else
+ {
+ if ((point.x < m_x) || (point.y < m_y) ||
+ (point.x > (m_x + m_width)) || (point.y > (m_y + m_height)))
+ return FALSE;
+ }
- WindowRef window = GetMacRootWindow() ;
+ WindowRef window = (WindowRef) MacGetRootWindow() ;
wxPoint newPoint( point ) ;
- newPoint.x -= m_x;
- newPoint.y -= m_y;
+ if ( !IsTopLevel() )
+ {
+ newPoint.x -= m_x;
+ newPoint.y -= m_y;
+ }
for (wxNode *node = GetChildren().First(); node; node = node->Next())
{
wxWindowMac *child = (wxWindowMac*)node->Data();
// added the m_isShown test --dmazzoni
- if ( child->GetMacRootWindow() == window && child->m_isShown )
+ if ( child->MacGetRootWindow() == window && child->m_isShown )
{
if (child->MacGetWindowFromPointSub(newPoint , outWin ))
return TRUE;
bool wxWindowMac::MacGetWindowFromPoint( const wxPoint &screenpoint , wxWindowMac** outWin )
{
WindowRef window ;
+
Point pt = { screenpoint.y , screenpoint.x } ;
if ( ::FindWindow( pt , &window ) == 3 )
{
- wxPoint point( screenpoint ) ;
- wxWindowMac* win = wxFindWinFromMacWindow( window ) ;
- if ( win )
- {
- win->ScreenToClient( point ) ;
+
+ wxWindowMac* win = wxFindWinFromMacWindow( window ) ;
+ if ( win )
+ {
+ // No, this yields the CLIENT are, we need the whole frame. RR.
+ // point = win->ScreenToClient( point ) ;
+
+ GrafPtr port;
+ ::GetPort( &port ) ;
+ ::SetPort( UMAGetWindowPort( window ) ) ;
+ ::GlobalToLocal( &pt ) ;
+ ::SetPort( port ) ;
+
+ wxPoint point( pt.h, pt.v ) ;
+
return win->MacGetWindowFromPointSub( point , outWin ) ;
- }
+ }
}
return FALSE ;
}
if ( IsKindOf( CLASSINFO ( wxStaticBox ) ) )
return FALSE ;
- WindowRef window = GetMacRootWindow() ;
+ WindowRef window = (WindowRef) MacGetRootWindow() ;
event.m_x -= m_x;
event.m_y -= m_y;
for (wxNode *node = GetChildren().First(); node; node = node->Next())
{
wxWindowMac *child = (wxWindowMac*)node->Data();
- if ( child->GetMacRootWindow() == window && child->IsShown() && child->IsEnabled() )
+ if ( child->MacGetRootWindow() == window && child->IsShown() && child->IsEnabled() )
{
if (child->MacDispatchMouseEvent(event))
return TRUE;
|| event.GetEventType() == wxEVT_LEAVE_WINDOW )
wxToolTip::RelayEvent( this , event);
#endif // wxUSE_TOOLTIPS
+
GetEventHandler()->ProcessEvent( event ) ;
+
return TRUE;
}
-Point lastWhere ;
-long lastWhen = 0 ;
-
wxString wxWindowMac::MacGetToolTipString( wxPoint &pt )
{
if ( m_tooltip )
}
return "" ;
}
-void wxWindowMac::MacFireMouseEvent( EventRecord *ev )
-{
- wxMouseEvent event(wxEVT_LEFT_DOWN);
- bool isDown = !(ev->modifiers & btnState) ; // 1 is for up
- bool controlDown = ev->modifiers & controlKey ; // for simulating right mouse
-
- event.m_leftDown = isDown && !controlDown;
-
- event.m_middleDown = FALSE;
- event.m_rightDown = isDown && controlDown;
- if ( ev->what == mouseDown )
- {
- if ( controlDown )
- event.SetEventType(wxEVT_RIGHT_DOWN ) ;
- else
- event.SetEventType(wxEVT_LEFT_DOWN ) ;
- }
- else if ( ev->what == mouseUp )
+void wxWindowMac::Update()
+{
+ wxTopLevelWindowMac* win = MacGetTopLevelWindow( ) ;
+ if ( win )
{
- if ( controlDown )
- event.SetEventType(wxEVT_RIGHT_UP ) ;
- else
- event.SetEventType(wxEVT_LEFT_UP ) ;
- }
- else
+ win->MacUpdate( 0 ) ;
+ if ( QDIsPortBuffered( GetWindowPort( (WindowRef) win->MacGetWindowRef() ) ) )
+ {
+ QDFlushPortBuffer( GetWindowPort( (WindowRef) win->MacGetWindowRef() ) , NULL ) ;
+ }
+ }
+}
+
+wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const
+{
+ wxTopLevelWindowMac* win = NULL ;
+ WindowRef window = (WindowRef) MacGetRootWindow() ;
+ if ( window )
{
- event.SetEventType(wxEVT_MOTION ) ;
- }
+ win = wxFindWinFromMacWindow( window ) ;
+ }
+ return win ;
+}
- event.m_shiftDown = ev->modifiers & shiftKey;
- event.m_controlDown = ev->modifiers & controlKey;
- event.m_altDown = ev->modifiers & optionKey;
- event.m_metaDown = ev->modifiers & cmdKey;
+const wxRegion& wxWindowMac::MacGetVisibleRegion()
+{
+ RgnHandle visRgn = NewRgn() ;
+ RgnHandle tempRgn = NewRgn() ;
+
+ SetRectRgn( visRgn , 0 , 0 , m_width , m_height ) ;
- Point localwhere = ev->where ;
-
- GrafPtr port ;
- ::GetPort( &port ) ;
- ::SetPort( UMAGetWindowPort( m_macWindowData->m_macWindow ) ) ;
- ::GlobalToLocal( &localwhere ) ;
- ::SetPort( port ) ;
+ //TODO : as soon as the new scheme has proven to work correctly, move this to wxStaticBox
+ if ( IsKindOf( CLASSINFO( wxStaticBox ) ) )
+ {
+ int borderTop = 14 ;
+ int borderOther = 4 ;
+
+ SetRectRgn( tempRgn , borderOther , borderTop , m_width - borderOther , m_height - borderOther ) ;
+ DiffRgn( visRgn , tempRgn , visRgn ) ;
+ }
- if ( ev->what == mouseDown )
+ if ( !IsTopLevel() )
+ {
+ wxWindow* parent = GetParent() ;
+ while( parent )
+ {
+ wxSize size = parent->GetSize() ;
+ int x , y ;
+ x = y = 0 ;
+ parent->MacWindowToRootWindow( &x, &y ) ;
+ MacRootWindowToWindow( &x , &y ) ;
+ SetRectRgn( tempRgn , x , y , x + size.x , y + size.y ) ;
+ SectRgn( visRgn , tempRgn , visRgn ) ;
+ if ( parent->IsTopLevel() )
+ break ;
+ parent = parent->GetParent() ;
+ }
+ }
+ if ( GetWindowStyle() & wxCLIP_CHILDREN )
+ {
+ for (wxNode *node = GetChildren().First(); node; node = node->Next())
{
- if ( ev->when - lastWhen <= GetDblTime() )
+ wxWindowMac *child = (wxWindowMac*)node->Data();
+
+ if ( !child->IsTopLevel() && child->IsShown() )
{
- if ( abs( localwhere.h - lastWhere.h ) < 3 || abs( localwhere.v - lastWhere.v ) < 3 )
- {
- if ( controlDown )
- event.SetEventType(wxEVT_RIGHT_DCLICK ) ;
- else
- event.SetEventType(wxEVT_LEFT_DCLICK ) ;
- }
- lastWhen = 0 ;
+ SetRectRgn( tempRgn , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ;
+ DiffRgn( visRgn , tempRgn , visRgn ) ;
}
- else
+ }
+ }
+
+ if ( (GetWindowStyle() & wxCLIP_SIBLINGS) && GetParent() )
+ {
+ bool thisWindowThrough = false ;
+ for (wxNode *node = GetParent()->GetChildren().First(); node; node = node->Next())
+ {
+ wxWindowMac *sibling = (wxWindowMac*)node->Data();
+ if ( sibling == this )
{
- lastWhen = ev->when ;
+ thisWindowThrough = true ;
+ continue ;
}
- lastWhere = localwhere ;
- }
-
- event.m_x = localwhere.h;
- event.m_y = localwhere.v;
- event.m_x += m_x;
- event.m_y += m_y;
-
-/*
- wxPoint origin = GetClientAreaOrigin() ;
-
- event.m_x += origin.x ;
- event.m_y += origin.y ;
-*/
-
- event.m_timeStamp = ev->when;
- 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 ;
- wxTheApp->s_captureWindow->GetEventHandler()->ProcessEvent( event ) ;
- if ( ev->what == mouseUp )
+ if( !thisWindowThrough )
{
- wxTheApp->s_captureWindow = NULL ;
- if ( wxBusyCursorCount == 0 )
- {
- m_cursor.MacInstall() ;
- }
+ continue ;
}
- }
- else
- {
- MacDispatchMouseEvent( event ) ;
- }
-}
-
-void wxWindowMac::MacMouseDown( EventRecord *ev , short part)
-{
- MacFireMouseEvent( ev ) ;
-}
-
-void wxWindowMac::MacMouseUp( EventRecord *ev , short part)
-{
- switch (part)
- {
- case inContent:
- {
- MacFireMouseEvent( ev ) ;
- }
- break ;
- }
-}
-void wxWindowMac::MacMouseMoved( EventRecord *ev , short part)
-{
- switch (part)
- {
- case inContent:
- {
- MacFireMouseEvent( ev ) ;
- }
- break ;
- }
-}
-void wxWindowMac::MacActivate( EventRecord *ev , bool inIsActivating )
-{
- if ( !m_macWindowData->m_macHasReceivedFirstActivate )
- m_macWindowData->m_macHasReceivedFirstActivate = true ;
-
- wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating , m_windowId);
- event.m_timeStamp = ev->when ;
- event.SetEventObject(this);
-
- GetEventHandler()->ProcessEvent(event);
-
- Refresh(false) ;
- UMAHighlightAndActivateWindow( m_macWindowData->m_macWindow , inIsActivating ) ;
-// MacUpdateImmediately() ;
+ if ( !sibling->IsTopLevel() && sibling->IsShown() )
+ {
+ SetRectRgn( tempRgn , sibling->m_x - m_x , sibling->m_y - m_y , sibling->m_x + sibling->m_width - m_x , sibling->m_y + sibling->m_height - m_y ) ;
+ DiffRgn( visRgn , tempRgn , visRgn ) ;
+ }
+ }
+ }
+ m_macVisibleRegion = visRgn ;
+ DisposeRgn( visRgn ) ;
+ DisposeRgn( tempRgn ) ;
+ return m_macVisibleRegion ;
}
-void wxWindowMac::MacRedraw( RgnHandle updatergn , long time)
+void wxWindowMac::MacRedraw( WXHRGN updatergnr , long time, bool erase)
{
+ RgnHandle updatergn = (RgnHandle) updatergnr ;
// updatergn is always already clipped to our boundaries
- WindowRef window = GetMacRootWindow() ;
- // ownUpdateRgn is the area that this window has to invalidate i.e. its own area without its children
- RgnHandle ownUpdateRgn = NewRgn() ;
- CopyRgn( updatergn , ownUpdateRgn ) ;
+ // it is in window coordinates, not in client coordinates
+
+ WindowRef window = (WindowRef) MacGetRootWindow() ;
{
- wxMacDrawingHelper focus( this ) ; // was client
- if ( focus.Ok() )
- {
- WindowRef window = GetMacRootWindow() ;
- bool eraseBackground = false ;
- if ( m_macWindowData )
- eraseBackground = true ;
- if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE) )
- {
- ::SetThemeWindowBackground( window , kThemeBrushDocumentWindowBackground , false ) ;
- }
- else if ( m_backgroundColour == wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
- {
- // on mac we have the difficult situation, that 3dface gray can be different colours, depending whether
- // it is on a notebook panel or not, in order to take care of that we walk up the hierarchy until we have
- // either a non gray background color or a non control window
+ // ownUpdateRgn is the area that this window has to repaint, it is in window coordinates
+ RgnHandle ownUpdateRgn = NewRgn() ;
+ CopyRgn( updatergn , ownUpdateRgn ) ;
+
+ SectRgn( ownUpdateRgn , (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , ownUpdateRgn ) ;
-
- wxWindowMac* parent = GetParent() ;
- while( parent )
- {
- if ( parent->GetMacRootWindow() != window )
- {
- // we are in a different window on the mac system
- parent = NULL ;
- break ;
- }
-
- if( parent->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)parent)->GetMacControl() )
- {
- if ( parent->m_backgroundColour != wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE ) )
- {
- // if we have any other colours in the hierarchy
- RGBBackColor( &parent->m_backgroundColour.GetPixel()) ;
- break ;
- }
- // if we have the normal colours in the hierarchy but another control etc. -> use it's background
- if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
- {
- Rect box ;
- GetRegionBounds( updatergn , &box) ;
- ::ApplyThemeBackground(kThemeBackgroundTabPane, &box , kThemeStateActive,8,true);
- break ;
- }
- }
- else
- {
- parent = NULL ;
- break ;
- }
- parent = parent->GetParent() ;
- }
- if ( !parent )
- {
- // if there is nothing special -> use default
- ::SetThemeWindowBackground( window , kThemeBrushDialogBackgroundActive , false ) ;
- }
- }
- else
- {
- RGBBackColor( &m_backgroundColour.GetPixel()) ;
- }
- // subtract all non transparent children from updatergn
-
- RgnHandle childarea = NewRgn() ;
- for (wxNode *node = GetChildren().First(); node; node = node->Next())
- {
- wxWindowMac *child = (wxWindowMac*)node->Data();
- // eventually test for transparent windows
- if ( child->GetMacRootWindow() == window && child->IsShown() )
- {
- if ( child->GetBackgroundColour() != m_backgroundColour && !child->IsKindOf( CLASSINFO( wxControl ) ) && ((wxControl*)child)->GetMacControl() )
- {
- SetRectRgn( childarea , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ;
- DiffRgn( ownUpdateRgn , childarea , ownUpdateRgn ) ;
- }
- }
- }
- DisposeRgn( childarea ) ;
-
- if ( GetParent() && m_backgroundColour != GetParent()->GetBackgroundColour() )
- eraseBackground = true ;
- SetClip( ownUpdateRgn ) ;
- if ( m_macEraseOnRedraw ) {
- if ( eraseBackground )
- {
- EraseRgn( ownUpdateRgn ) ;
- }
- }
- else {
- m_macEraseOnRedraw = true ;
- }
+ // newupdate is the update region in client coordinates
+ RgnHandle newupdate = NewRgn() ;
+ wxSize point = GetClientSize() ;
+ wxPoint origin = GetClientAreaOrigin() ;
+ SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ;
+ SectRgn( newupdate , ownUpdateRgn , newupdate ) ;
+ OffsetRgn( newupdate , -origin.x , -origin.y ) ;
+ m_updateRegion = newupdate ;
+ DisposeRgn( newupdate ) ; // it's been cloned to m_updateRegion
+
+ if ( erase && !EmptyRgn(ownUpdateRgn) )
+ {
+ wxWindowDC dc(this);
+ dc.SetClippingRegion(wxRegion(ownUpdateRgn));
+ wxEraseEvent eevent( GetId(), &dc );
+ eevent.SetEventObject( this );
+ GetEventHandler()->ProcessEvent( eevent );
+
+ wxNcPaintEvent eventNc( GetId() );
+ eventNc.SetEventObject( this );
+ GetEventHandler()->ProcessEvent( eventNc );
}
-
+ DisposeRgn( ownUpdateRgn ) ;
+ if ( !m_updateRegion.Empty() )
{
- RgnHandle newupdate = NewRgn() ;
- wxSize point = GetClientSize() ;
- wxPoint origin = GetClientAreaOrigin() ;
-
- SetRectRgn( newupdate , origin.x , origin.y , origin.x + point.x , origin.y+point.y ) ;
- SectRgn( newupdate , ownUpdateRgn , newupdate ) ;
- OffsetRgn( newupdate , -origin.x , -origin.y ) ;
- m_updateRegion = newupdate ;
- DisposeRgn( newupdate ) ;
- }
-
- MacPaintBorders() ;
- wxPaintEvent event;
- event.m_timeStamp = time ;
- event.SetEventObject(this);
- GetEventHandler()->ProcessEvent(event);
+ wxPaintEvent event;
+ event.m_timeStamp = time ;
+ event.SetEventObject(this);
+ GetEventHandler()->ProcessEvent(event);
+ }
}
+ // now intersect for each of the children their rect with the updateRgn and call MacRedraw recursively
- RgnHandle childupdate = NewRgn() ;
-
+ RgnHandle childupdate = NewRgn() ;
for (wxNode *node = GetChildren().First(); node; node = node->Next())
{
+ // calculate the update region for the child windows by intersecting the window rectangle with our own
+ // passed in update region and then offset it to be client-wise window coordinates again
wxWindowMac *child = (wxWindowMac*)node->Data();
SetRectRgn( childupdate , child->m_x , child->m_y , child->m_x + child->m_width , child->m_y + child->m_height ) ;
SectRgn( childupdate , updatergn , childupdate ) ;
OffsetRgn( childupdate , -child->m_x , -child->m_y ) ;
- if ( child->GetMacRootWindow() == window && child->IsShown() && !EmptyRgn( childupdate ) )
+ if ( child->MacGetRootWindow() == window && child->IsShown() && !EmptyRgn( childupdate ) )
{
// because dialogs may also be children
- child->MacRedraw( childupdate , time ) ;
+ child->MacRedraw( childupdate , time , erase ) ;
}
}
DisposeRgn( childupdate ) ;
// eventually a draw grow box here
+
}
-void wxWindowMac::MacUpdateImmediately()
-{
- WindowRef window = GetMacRootWindow() ;
- if ( window )
- {
- wxWindowMac* win = wxFindWinFromMacWindow( window ) ;
- #if TARGET_CARBON
- AGAPortHelper help( GetWindowPort(window) ) ;
- #else
- AGAPortHelper help( (window) ) ;
- #endif
- SetOrigin( 0 , 0 ) ;
- BeginUpdate( window ) ;
- if ( win )
- {
- RgnHandle region = NewRgn();
-
- if ( region )
- {
- GetPortVisibleRegion( GetWindowPort( window ), region );
-
- // if windowshade gives incompatibility , take the follwing out
- if ( !EmptyRgn( region ) && win->m_macWindowData->m_macHasReceivedFirstActivate )
- {
- win->MacRedraw( region , wxTheApp->sm_lastMessageTime ) ;
- }
- DisposeRgn( region );
- }
- }
- EndUpdate( window ) ;
- }
-}
-
-void wxWindowMac::MacUpdate( EventRecord *ev )
-{
- WindowRef window = (WindowRef) ev->message ;
- wxWindowMac * win = wxFindWinFromMacWindow( window ) ;
- #if TARGET_CARBON
- AGAPortHelper help( GetWindowPort(window) ) ;
- #else
- AGAPortHelper help( (window) ) ;
- #endif
- SetOrigin( 0 , 0 ) ;
- BeginUpdate( window ) ;
- if ( win )
- {
- RgnHandle region = NewRgn();
-
- if ( region )
- {
- GetPortVisibleRegion( GetWindowPort( window ), region );
-
- // if windowshade gives incompatibility , take the follwing out
- if ( !EmptyRgn( region ) && win->m_macWindowData->m_macHasReceivedFirstActivate )
- {
- MacRedraw( region , ev->when ) ;
- }
- DisposeRgn( region );
- }
- }
- EndUpdate( window ) ;
-}
-
-WindowRef wxWindowMac::GetMacRootWindow() const
+WXHWND wxWindowMac::MacGetRootWindow() const
{
wxWindowMac *iter = (wxWindowMac*)this ;
while( iter )
{
- if ( iter->m_macWindowData )
- return iter->m_macWindowData->m_macWindow ;
+ if ( iter->IsTopLevel() )
+ return ((wxTopLevelWindow*)iter)->MacGetWindowRef() ;
iter = iter->GetParent() ;
}
int totW = 10000 , totH = 10000;
while( iter )
{
- if ( iter->m_macWindowData )
+ if ( iter->IsTopLevel() )
{
totW = iter->m_width ;
totH = iter->m_height ;
}
}
-void wxWindowMac::MacKeyDown( EventRecord *ev )
-{
-
-}
-
-
bool wxWindowMac::AcceptsFocus() const
{
return MacCanFocus() && wxWindowBase::AcceptsFocus();
}
-ControlHandle wxWindowMac::MacGetContainerForEmbedding()
+WXWidget wxWindowMac::MacGetContainerForEmbedding()
{
- if ( m_macWindowData )
- return m_macWindowData->m_macRootControl ;
- else
- return GetParent()->MacGetContainerForEmbedding() ;
+ return GetParent()->MacGetContainerForEmbedding() ;
}
void wxWindowMac::MacSuperChangedPosition()
node = node->Next();
}
}
-
-bool wxWindowMac::MacSetPortFocusParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindowMac* win )
-{
- if ( window == NULL )
- return false ;
-
- GrafPtr currPort;
- GrafPtr port ;
-
- ::GetPort(&currPort);
- port = UMAGetWindowPort( window) ;
- if (currPort != port )
- ::SetPort(port);
-
-// wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
- ::SetOrigin(-localOrigin.h, -localOrigin.v);
- return true;
-}
-
-bool wxWindowMac::MacSetPortDrawingParams( const Point & localOrigin, const Rect & clipRect, WindowRef window , wxWindowMac* win )
-{
- if ( window == NULL )
- return false ;
-
- GrafPtr currPort;
- GrafPtr port ;
- ::GetPort(&currPort);
- port = UMAGetWindowPort( window) ;
- if (currPort != port )
- ::SetPort(port);
-// wxASSERT( port->portRect.left == 0 && port->portRect.top == 0 ) ;
- ::SetOrigin(-localOrigin.h, -localOrigin.v);
- ::ClipRect(&clipRect);
-
- ::PenNormal() ;
- ::RGBBackColor(& win->GetBackgroundColour().GetPixel() ) ;
- ::RGBForeColor(& win->GetForegroundColour().GetPixel() ) ;
- Pattern whiteColor ;
-
- ::BackPat( GetQDGlobalsWhite( &whiteColor) ) ;
- ::SetThemeWindowBackground( win->m_macWindowData->m_macWindow , win->m_macWindowData->m_macWindowBackgroundTheme , false ) ;
- return true;
-}
-
-void wxWindowMac::MacGetPortParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindowMac** rootwin)
-{
- if ( m_macWindowData )
- {
- localOrigin->h = 0;
- localOrigin->v = 0;
- clipRect->left = 0;
- clipRect->top = 0;
- clipRect->right = m_width;
- clipRect->bottom = m_height;
- *window = m_macWindowData->m_macWindow ;
- *rootwin = this ;
- }
- else
- {
- wxASSERT( GetParent() != NULL ) ;
- GetParent()->MacGetPortParams( localOrigin , clipRect , window, rootwin) ;
- localOrigin->h += m_x;
- localOrigin->v += m_y;
- OffsetRect(clipRect, -m_x, -m_y);
-
- Rect myClip;
- myClip.left = 0;
- myClip.top = 0;
- myClip.right = m_width;
- myClip.bottom = m_height;
- SectRect(clipRect, &myClip, clipRect);
- }
-}
-
-void wxWindowMac::MacDoGetPortClientParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindowMac** rootwin )
-{
-// int width , height ;
-// GetClientSize( &width , &height ) ;
-
- if ( m_macWindowData )
- {
- localOrigin->h = 0;
- localOrigin->v = 0;
- clipRect->left = 0;
- clipRect->top = 0;
- clipRect->right = m_width ;//width;
- clipRect->bottom = m_height ;// height;
- *window = m_macWindowData->m_macWindow ;
- *rootwin = this ;
- }
- else
- {
- wxASSERT( GetParent() != NULL ) ;
-
- GetParent()->MacDoGetPortClientParams( localOrigin , clipRect , window, rootwin) ;
-
- localOrigin->h += m_x;
- localOrigin->v += m_y;
- OffsetRect(clipRect, -m_x, -m_y);
-
- Rect myClip;
- myClip.left = 0;
- myClip.top = 0;
- myClip.right = m_width ;//width;
- myClip.bottom = m_height ;// height;
- SectRect(clipRect, &myClip, clipRect);
- }
-}
-
-void wxWindowMac::MacGetPortClientParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindowMac** rootwin )
-{
- MacDoGetPortClientParams( localOrigin , clipRect , window , rootwin ) ;
-
- int width , height ;
- GetClientSize( &width , &height ) ;
- wxPoint client ;
- client = GetClientAreaOrigin( ) ;
-
- localOrigin->h += client.x;
- localOrigin->v += client.y;
- OffsetRect(clipRect, -client.x, -client.y);
-
- Rect myClip;
- myClip.left = 0;
- myClip.top = 0;
- myClip.right = width;
- myClip.bottom = height;
- SectRect(clipRect, &myClip, clipRect);
-}
-
long wxWindowMac::MacGetLeftBorderSize( ) const
{
- if( m_macWindowData )
+ if( IsTopLevel() )
return 0 ;
if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
{
- return 3 ;
+ SInt32 border = 3 ;
+#if wxMAC_USE_THEME_BORDER
+#if TARGET_CARBON
+ GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
+#endif
+#endif
+ return border ;
}
else if ( m_windowStyle &wxDOUBLE_BORDER)
{
- return 3 ;
+ SInt32 border = 3 ;
+#if wxMAC_USE_THEME_BORDER
+#if TARGET_CARBON
+ GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ;
+#endif
+#endif
+ return border ;
}
else if (m_windowStyle &wxSIMPLE_BORDER)
{
long wxWindowMac::MacGetRightBorderSize( ) const
{
- if( m_macWindowData )
- return 0 ;
-
- if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
- {
- return 3 ;
- }
- else if ( m_windowStyle &wxDOUBLE_BORDER)
- {
- return 3 ;
- }
- else if (m_windowStyle &wxSIMPLE_BORDER)
- {
- return 1 ;
- }
- return 0 ;
+ // they are all symmetric in mac themes
+ return MacGetLeftBorderSize() ;
}
long wxWindowMac::MacGetTopBorderSize( ) const
{
- if( m_macWindowData )
- return 0 ;
-
- if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
- {
- return 3 ;
- }
- else if ( m_windowStyle &wxDOUBLE_BORDER)
- {
- return 3 ;
- }
- else if (m_windowStyle &wxSIMPLE_BORDER)
- {
- return 1 ;
- }
- return 0 ;
+ // they are all symmetric in mac themes
+ return MacGetLeftBorderSize() ;
}
long wxWindowMac::MacGetBottomBorderSize( ) const
{
- if( m_macWindowData )
- return 0 ;
-
- if (m_windowStyle & wxRAISED_BORDER || m_windowStyle & wxSUNKEN_BORDER )
- {
- return 3 ;
- }
- else if ( m_windowStyle &wxDOUBLE_BORDER)
- {
- return 3 ;
- }
- else if (m_windowStyle &wxSIMPLE_BORDER)
- {
- return 1 ;
- }
- return 0 ;
+ // they are all symmetric in mac themes
+ return MacGetLeftBorderSize() ;
}
long wxWindowMac::MacRemoveBordersFromStyle( long style )
return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ;
}
-
-wxMacDrawingHelper::wxMacDrawingHelper( wxWindowMac * theWindow )
-{
- m_ok = false ;
- Point localOrigin ;
- Rect clipRect ;
- WindowRef window ;
- wxWindowMac *rootwin ;
- m_currentPort = NULL ;
-
- GetPort( &m_formerPort ) ;
- if ( theWindow )
- {
- theWindow->MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ;
- m_currentPort = UMAGetWindowPort( window ) ;
- if ( m_formerPort != m_currentPort )
- SetPort( m_currentPort ) ;
- GetPenState( &m_savedPenState ) ;
- theWindow->MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ;
- m_ok = true ;
- }
-}
-
-wxMacDrawingHelper::~wxMacDrawingHelper()
-{
- if ( m_ok )
- {
- SetPort( m_currentPort ) ;
- SetPenState( &m_savedPenState ) ;
- SetOrigin( 0 , 0 ) ;
- Rect portRect ;
- GetPortBounds( m_currentPort , &portRect ) ;
- ClipRect( &portRect ) ;
- }
-
- if ( m_formerPort != m_currentPort )
- SetPort( m_formerPort ) ;
-}
-
-wxMacDrawingClientHelper::wxMacDrawingClientHelper( wxWindowMac * theWindow )
-{
- m_ok = false ;
- Point localOrigin ;
- Rect clipRect ;
- WindowRef window ;
- wxWindowMac *rootwin ;
- m_currentPort = NULL ;
-
- GetPort( &m_formerPort ) ;
-
- if ( theWindow )
- {
- theWindow->MacGetPortClientParams( &localOrigin , &clipRect , &window , &rootwin) ;
- m_currentPort = UMAGetWindowPort( window ) ;
- if ( m_formerPort != m_currentPort )
- SetPort( m_currentPort ) ;
- GetPenState( &m_savedPenState ) ;
- theWindow->MacSetPortDrawingParams( localOrigin, clipRect, window , rootwin ) ;
- m_ok = true ;
- }
-}
-
-wxMacDrawingClientHelper::~wxMacDrawingClientHelper()
-{
- if ( m_ok )
- {
- SetPort( m_currentPort ) ;
- SetPenState( &m_savedPenState ) ;
- SetOrigin( 0 , 0 ) ;
- Rect portRect ;
- GetPortBounds( m_currentPort , &portRect ) ;
- ClipRect( &portRect ) ;
- }
-
- if ( m_formerPort != m_currentPort )
- SetPort( m_formerPort ) ;
-}
-
// Find the wxWindowMac at the current mouse position, returning the mouse
// position.
wxWindowMac* wxFindWindowAtPointer(wxPoint& pt)