new common code files

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55138 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2008-08-21 07:28:04 +00:00
parent 60a14f1bf2
commit 3ccc5735bf
3 changed files with 867 additions and 0 deletions

149
src/osx/dialog_osx.cpp Normal file
View File

@@ -0,0 +1,149 @@
/////////////////////////////////////////////////////////////////////////////
// Name: src/osx/dialog_osx.cpp
// Purpose: wxDialog class
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id: dialog.cpp 54820 2008-07-29 20:04:11Z SC $
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/wxprec.h"
#include "wx/dialog.h"
#ifndef WX_PRECOMP
#include "wx/app.h"
#include "wx/utils.h"
#include "wx/frame.h"
#include "wx/settings.h"
#endif // WX_PRECOMP
#include "wx/osx/private.h"
// Lists to keep track of windows, so we can disable/enable them
// for modal dialogs
wxList wxModalDialogs;
IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow)
void wxDialog::Init()
{
m_isModalStyle = false;
}
bool wxDialog::Create( wxWindow *parent,
wxWindowID id,
const wxString& title,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name )
{
SetExtraStyle( GetExtraStyle() | wxTOPLEVEL_EX_DIALOG );
// All dialogs should really have this style...
style |= wxTAB_TRAVERSAL;
// ...but not these styles
style &= ~(wxYES | wxOK | wxNO); // | wxCANCEL
if ( !wxTopLevelWindow::Create( parent, id, title, pos, size, style, name ) )
return false;
return true;
}
void wxDialog::SetModal( bool flag )
{
if ( flag )
{
m_isModalStyle = true;
}
else
{
m_isModalStyle = false;
}
}
wxDialog::~wxDialog()
{
m_isBeingDeleted = true;
// if the dialog is modal, this will end its event loop
Show(false);
}
// On mac command-stop does the same thing as Esc, let the base class know
// about it
bool wxDialog::IsEscapeKey(const wxKeyEvent& event)
{
if ( event.GetKeyCode() == '.' && event.GetModifiers() == wxMOD_CMD )
return true;
return wxDialogBase::IsEscapeKey(event);
}
bool wxDialog::IsModal() const
{
return wxModalDialogs.Find((wxDialog *)this) != NULL; // const_cast
// return m_isModalStyle;
}
bool wxDialog::Show(bool show)
{
if ( !wxDialogBase::Show(show) )
// nothing to do
return false;
if (show && CanDoLayoutAdaptation())
DoLayoutAdaptation();
if ( show )
// usually will result in TransferDataToWindow() being called
InitDialog();
if ( m_isModalStyle )
{
if ( show )
{
DoShowModal();
}
else // end of modal dialog
{
// this will cause IsModalShowing() return false and our local
// message loop will terminate
wxModalDialogs.DeleteObject(this);
}
}
return true;
}
// Replacement for Show(true) for modal dialogs - returns return code
int wxDialog::ShowModal()
{
if ( !m_isModalStyle )
SetModal(true);
if ( IsShown() )
DoShowModal();
else
Show(true);
return GetReturnCode();
}
// NB: this function (surprizingly) may be called for both modal and modeless
// dialogs and should work for both of them
void wxDialog::EndModal(int retCode)
{
SetReturnCode(retCode);
Show(false);
SetModal(false);
}

436
src/osx/nonownedwnd_osx.cpp Normal file
View File

@@ -0,0 +1,436 @@
/////////////////////////////////////////////////////////////////////////////
// Name: src/osx/nonownedwnd_osx.cpp
// Purpose: implementation of wxNonOwnedWindow
// Author: Stefan Csomor
// Created: 2008-03-24
// RCS-ID: $Id: nonownedwnd.cpp 50329 2007-11-29 17:00:58Z VS $
// Copyright: (c) Stefan Csomor 2008
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifndef WX_PRECOMP
#include "wx/app.h"
#endif // WX_PRECOMP
#include "wx/hashmap.h"
#include "wx/evtloop.h"
#include "wx/tooltip.h"
#include "wx/nonownedwnd.h"
#include "wx/osx/private.h"
#include "wx/settings.h"
#include "wx/frame.h"
#if wxUSE_SYSTEM_OPTIONS
#include "wx/sysopt.h"
#endif
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
// trace mask for activation tracing messages
#define TRACE_ACTIVATE "activation"
wxWindow* g_MacLastWindow = NULL ;
// unified title and toolbar constant - not in Tiger headers, so we duplicate it here
#define kWindowUnifiedTitleAndToolbarAttribute (1 << 7)
// ---------------------------------------------------------------------------
// wxWindowMac utility functions
// ---------------------------------------------------------------------------
// Find an item given the Macintosh Window Reference
WX_DECLARE_HASH_MAP(WXWindow, wxNonOwnedWindow*, wxPointerHash, wxPointerEqual, MacWindowMap);
static MacWindowMap wxWinMacWindowList;
wxNonOwnedWindow *wxFindWindowFromWXWindow(WXWindow inWindowRef)
{
MacWindowMap::iterator node = wxWinMacWindowList.find(inWindowRef);
return (node == wxWinMacWindowList.end()) ? NULL : node->second;
}
void wxAssociateWindowWithWXWindow(WXWindow inWindowRef, wxNonOwnedWindow *win) ;
void wxAssociateWindowWithWXWindow(WXWindow inWindowRef, wxNonOwnedWindow *win)
{
// adding NULL WindowRef is (first) surely a result of an error and
// nothing else :-)
wxCHECK_RET( inWindowRef != (WXWindow) NULL, wxT("attempt to add a NULL WindowRef to window list") );
wxWinMacWindowList[inWindowRef] = win;
}
void wxRemoveWXWindowAssociation(wxNonOwnedWindow *win) ;
void wxRemoveWXWindowAssociation(wxNonOwnedWindow *win)
{
MacWindowMap::iterator it;
for ( it = wxWinMacWindowList.begin(); it != wxWinMacWindowList.end(); ++it )
{
if ( it->second == win )
{
wxWinMacWindowList.erase(it);
break;
}
}
}
wxNonOwnedWindow* wxNonOwnedWindow::GetFromWXWindow( WXWindow win )
{
return wxFindWindowFromWXWindow( win );
}
// ----------------------------------------------------------------------------
// wxNonOwnedWindow creation
// ----------------------------------------------------------------------------
IMPLEMENT_ABSTRACT_CLASS( wxNonOwnedWindowImpl , wxObject )
wxNonOwnedWindow *wxNonOwnedWindow::s_macDeactivateWindow = NULL;
void wxNonOwnedWindow::Init()
{
m_nowpeer = NULL;
}
bool wxNonOwnedWindow::Create(wxWindow *parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
{
// init our fields
Init();
m_windowStyle = style;
SetName( name );
m_windowId = id == -1 ? NewControlId() : id;
m_windowStyle = style;
m_isShown = false;
// create frame.
int x = (int)pos.x;
int y = (int)pos.y;
wxRect display = wxGetClientDisplayRect() ;
if ( x == wxDefaultPosition.x )
x = display.x ;
if ( y == wxDefaultPosition.y )
y = display.y ;
int w = WidthDefault(size.x);
int h = HeightDefault(size.y);
// temporary define, TODO
#if wxOSX_USE_CARBON
m_nowpeer = new wxNonOwnedWindowCarbonImpl( this );
#elif wxOSX_USE_COCOA
m_nowpeer = new wxNonOwnedWindowCocoaImpl( this );
#elif wxOSX_USE_IPHONE
m_nowpeer = new wxNonOwnedWindowIPhoneImpl( this );
#endif
m_nowpeer->Create( parent, wxPoint(x,y) , wxSize(w,h) , style , GetExtraStyle(), name ) ;
wxAssociateWindowWithWXWindow( m_nowpeer->GetWXWindow() , this ) ;
#if wxOSX_USE_CARBON
// temporary cast, TODO
m_peer = (wxMacControl*) wxWidgetImpl::CreateContentView(this);
#else
m_peer = wxWidgetImpl::CreateContentView(this);
#endif
DoSetWindowVariant( m_windowVariant ) ;
wxWindowCreateEvent event(this);
HandleWindowEvent(event);
SetBackgroundColour(wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE ));
if ( parent )
parent->AddChild(this);
return true;
}
wxNonOwnedWindow::~wxNonOwnedWindow()
{
wxRemoveWXWindowAssociation( this ) ;
if ( m_nowpeer )
m_nowpeer->Destroy();
// avoid dangling refs
if ( s_macDeactivateWindow == this )
s_macDeactivateWindow = NULL;
}
// ----------------------------------------------------------------------------
// wxNonOwnedWindow misc
// ----------------------------------------------------------------------------
bool wxNonOwnedWindow::ShowWithEffect(wxShowEffect effect,
unsigned timeout )
{
if ( !wxWindow::Show(true) )
return false;
// because apps expect a size event to occur at this moment
wxSizeEvent event(GetSize() , m_windowId);
event.SetEventObject(this);
HandleWindowEvent(event);
return m_nowpeer->ShowWithEffect(true, effect, timeout);
}
bool wxNonOwnedWindow::HideWithEffect(wxShowEffect effect,
unsigned timeout )
{
if ( !wxWindow::Show(false) )
return false;
return m_nowpeer->ShowWithEffect(false, effect, timeout);
}
wxPoint wxNonOwnedWindow::GetClientAreaOrigin() const
{
int left, top, width, height;
m_nowpeer->GetContentArea(left, top, width, height);
return wxPoint(left, top);
}
bool wxNonOwnedWindow::SetBackgroundColour(const wxColour& c )
{
if ( !wxWindow::SetBackgroundColour(c) && m_hasBgCol )
return false ;
if ( GetBackgroundStyle() != wxBG_STYLE_CUSTOM )
{
return m_nowpeer->SetBackgroundColour(c);
}
return true;
}
// Raise the window to the top of the Z order
void wxNonOwnedWindow::Raise()
{
m_nowpeer->Raise();
}
// Lower the window to the bottom of the Z order
void wxNonOwnedWindow::Lower()
{
m_nowpeer->Lower();
}
void wxNonOwnedWindow::HandleActivated( double timestampsec, bool didActivate )
{
MacActivate( (int) (timestampsec * 1000) , didActivate);
wxActivateEvent wxevent(wxEVT_ACTIVATE, didActivate , GetId());
wxevent.SetTimestamp( (int) (timestampsec * 1000) );
wxevent.SetEventObject(this);
HandleWindowEvent(wxevent);
}
void wxNonOwnedWindow::HandleResized( double timestampsec )
{
wxSizeEvent wxevent( GetSize() , GetId());
wxevent.SetTimestamp( (int) (timestampsec * 1000) );
wxevent.SetEventObject( this );
HandleWindowEvent(wxevent);
// we have to inform some controls that have to reset things
// relative to the toplevel window (e.g. OpenGL buffers)
wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
}
void wxNonOwnedWindow::HandleResizing( double timestampsec, wxRect* rect )
{
wxRect r = *rect ;
// this is a EVT_SIZING not a EVT_SIZE type !
wxSizeEvent wxevent( r , GetId() ) ;
wxevent.SetEventObject( this ) ;
if ( HandleWindowEvent(wxevent) )
r = wxevent.GetRect() ;
if ( GetMaxWidth() != -1 && r.GetWidth() > GetMaxWidth() )
r.SetWidth( GetMaxWidth() ) ;
if ( GetMaxHeight() != -1 && r.GetHeight() > GetMaxHeight() )
r.SetHeight( GetMaxHeight() ) ;
if ( GetMinWidth() != -1 && r.GetWidth() < GetMinWidth() )
r.SetWidth( GetMinWidth() ) ;
if ( GetMinHeight() != -1 && r.GetHeight() < GetMinHeight() )
r.SetHeight( GetMinHeight() ) ;
*rect = r;
// TODO actuall this is too early, in case the window extents are adjusted
wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
}
void wxNonOwnedWindow::HandleMoved( double timestampsec )
{
wxMoveEvent wxevent( GetPosition() , GetId());
wxevent.SetTimestamp( (int) (timestampsec * 1000) );
wxevent.SetEventObject( this );
HandleWindowEvent(wxevent);
}
void wxNonOwnedWindow::MacDelayedDeactivation(long timestamp)
{
if (s_macDeactivateWindow)
{
wxLogTrace(TRACE_ACTIVATE,
wxT("Doing delayed deactivation of %p"),
s_macDeactivateWindow);
s_macDeactivateWindow->MacActivate(timestamp, false);
}
}
void wxNonOwnedWindow::MacActivate( long timestamp , bool WXUNUSED(inIsActivating) )
{
wxLogTrace(TRACE_ACTIVATE, wxT("TopLevel=%p::MacActivate"), this);
if (s_macDeactivateWindow == this)
s_macDeactivateWindow = NULL;
MacDelayedDeactivation(timestamp);
}
bool wxNonOwnedWindow::Show(bool show)
{
if ( !wxWindow::Show(show) )
return false;
if ( m_nowpeer )
m_nowpeer->Show(show);
if ( show )
{
// because apps expect a size event to occur at this moment
wxSizeEvent event(GetSize() , m_windowId);
event.SetEventObject(this);
HandleWindowEvent(event);
}
return true ;
}
bool wxNonOwnedWindow::SetTransparent(wxByte alpha)
{
return m_nowpeer->SetTransparent(alpha);
}
bool wxNonOwnedWindow::CanSetTransparent()
{
return m_nowpeer->CanSetTransparent();
}
void wxNonOwnedWindow::SetExtraStyle(long exStyle)
{
if ( GetExtraStyle() == exStyle )
return ;
wxWindow::SetExtraStyle( exStyle ) ;
if ( m_nowpeer )
m_nowpeer->SetExtraStyle(exStyle);
}
bool wxNonOwnedWindow::SetBackgroundStyle(wxBackgroundStyle style)
{
if ( !wxWindow::SetBackgroundStyle(style) )
return false ;
return m_nowpeer->SetBackgroundStyle(style);
}
void wxNonOwnedWindow::DoMoveWindow(int x, int y, int width, int height)
{
m_cachedClippedRectValid = false ;
m_nowpeer->MoveWindow(x, y, width, height);
wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified
}
void wxNonOwnedWindow::DoGetPosition( int *x, int *y ) const
{
int x1,y1 ;
m_nowpeer->GetPosition(x1, y1);
if (x)
*x = x1 ;
if (y)
*y = y1 ;
}
void wxNonOwnedWindow::DoGetSize( int *width, int *height ) const
{
int w,h;
m_nowpeer->GetSize(w, h);
if (width)
*width = w ;
if (height)
*height = h ;
}
void wxNonOwnedWindow::DoGetClientSize( int *width, int *height ) const
{
int left, top, w, h;
m_nowpeer->GetContentArea(left, top, w, h);
if (width)
*width = w ;
if (height)
*height = h ;
}
void wxNonOwnedWindow::Update()
{
m_nowpeer->Update();
}
WXWindow wxNonOwnedWindow::GetWXWindow() const
{
return m_nowpeer ? m_nowpeer->GetWXWindow() : NULL;
}
// ---------------------------------------------------------------------------
// Shape implementation
// ---------------------------------------------------------------------------
bool wxNonOwnedWindow::SetShape(const wxRegion& region)
{
wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), false,
_T("Shaped windows must be created with the wxFRAME_SHAPED style."));
// The empty region signifies that the shape
// should be removed from the window.
if ( region.IsEmpty() )
{
wxSize sz = GetClientSize();
wxRegion rgn(0, 0, sz.x, sz.y);
if ( rgn.IsEmpty() )
return false ;
else
return SetShape(rgn);
}
return m_nowpeer->SetShape(region);
}

282
src/osx/utils_osx.cpp Normal file
View File

@@ -0,0 +1,282 @@
/////////////////////////////////////////////////////////////////////////////
// Name: src/osx/utils_osx.cpp
// Purpose: Various utilities
// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
// RCS-ID: $Id: utils.cpp 54886 2008-07-31 13:02:53Z SC $
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/wxprec.h"
#include "wx/utils.h"
#ifndef WX_PRECOMP
#include "wx/intl.h"
#include "wx/app.h"
#if wxUSE_GUI
#include "wx/toplevel.h"
#include "wx/font.h"
#endif
#endif
#include "wx/apptrait.h"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
// #include "MoreFilesX.h"
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
#include <AudioToolbox/AudioServices.h>
#endif
#include "wx/osx/private.h"
#ifdef wxOSX_USE_COCOA
// to get the themeing APIs
#include <Carbon/Carbon.h>
#endif
#if wxUSE_GUI
#include "wx/osx/private/timer.h"
#endif // wxUSE_GUI
#include "wx/evtloop.h"
#if defined(__MWERKS__) && wxUSE_UNICODE
#if __MWERKS__ < 0x4100
#include <wtime.h>
#endif
#endif
//
// TODO BEGIN move to utils_osx.cpp
//
#if wxUSE_BASE
extern bool WXDLLEXPORT wxIsDebuggerRunning()
{
// TODO : try to find out ...
return false;
}
#if wxOSX_USE_COCOA_OR_CARBON
// have a fast version for mac code that returns the version as a return value
long UMAGetSystemVersion()
{
static SInt32 sUMASystemVersion = 0 ;
if ( sUMASystemVersion == 0 )
{
verify_noerr(Gestalt(gestaltSystemVersion, &sUMASystemVersion));
}
return sUMASystemVersion ;
}
// our OS version is the same in non GUI and GUI cases
wxOperatingSystemId wxGetOsVersion(int *majorVsn, int *minorVsn)
{
SInt32 theSystem;
Gestalt(gestaltSystemVersion, &theSystem);
if ( majorVsn != NULL )
*majorVsn = (theSystem >> 8);
if ( minorVsn != NULL )
*minorVsn = (theSystem & 0xFF);
return wxOS_MAC_OSX_DARWIN;
}
#include <sys/utsname.h>
wxString wxGetOsDescription()
{
struct utsname name;
uname(&name);
return wxString::Format(_T("Mac OS X (%s %s %s)"),
wxString::FromAscii(name.sysname).c_str(),
wxString::FromAscii(name.release).c_str(),
wxString::FromAscii(name.machine).c_str());
}
#endif // wxOSX_USE_COCOA_OR_CARBON
//---------------------------------------------------------------------------
// wxMac Specific utility functions
//---------------------------------------------------------------------------
void wxMacStringToPascal( const wxString&from , StringPtr to )
{
wxCharBuffer buf = from.mb_str( wxConvLocal );
int len = strlen(buf);
if ( len > 255 )
len = 255;
to[0] = len;
memcpy( (char*) &to[1] , buf , len );
}
wxString wxMacMakeStringFromPascal( ConstStringPtr from )
{
return wxString( (char*) &from[1] , wxConvLocal , from[0] );
}
#endif // wxUSE_BASE
#if wxUSE_GUI
// Check whether this window wants to process messages, e.g. Stop button
// in long calculations.
bool wxCheckForInterrupt(wxWindow *WXUNUSED(wnd))
{
// TODO
return false;
}
// Return true if we have a colour display
bool wxColourDisplay()
{
return true;
}
#if wxOSX_USE_COCOA_OR_CARBON
// Returns depth of screen
int wxDisplayDepth()
{
int theDepth = (int) CGDisplayBitsPerPixel(CGMainDisplayID());
return theDepth;
}
// Get size of display
void wxDisplaySize(int *width, int *height)
{
// TODO adapt for multi-displays
CGRect bounds = CGDisplayBounds(CGMainDisplayID());
if ( width )
*width = (int)bounds.size.width ;
if ( height )
*height = (int)bounds.size.height;
}
#endif
void wxDisplaySizeMM(int *width, int *height)
{
wxDisplaySize(width, height);
// on mac 72 is fixed (at least now;-)
double cvPt2Mm = 25.4 / 72;
if (width != NULL)
*width = int( *width * cvPt2Mm );
if (height != NULL)
*height = int( *height * cvPt2Mm );
}
wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const
{
// We suppose that toolkit version is the same as OS version under Mac
wxGetOsVersion(verMaj, verMin);
return wxPORT_OSX;
}
wxEventLoopBase* wxGUIAppTraits::CreateEventLoop()
{
return new wxEventLoop;
}
wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
{
return wxGenericFindWindowAtPoint(pt);
}
/*
Return the generic RGB color space. This is a 'get' function and the caller should
not release the returned value unless the caller retains it first. Usually callers
of this routine will immediately use the returned colorspace with CoreGraphics
so they typically do not need to retain it themselves.
This function creates the generic RGB color space once and hangs onto it so it can
return it whenever this function is called.
*/
CGColorSpaceRef wxMacGetGenericRGBColorSpace()
{
static wxCFRef<CGColorSpaceRef> genericRGBColorSpace;
if (genericRGBColorSpace == NULL)
{
#if wxOSX_USE_IPHONE
genericRGBColorSpace.reset( CGColorSpaceCreateDeviceRGB() );
#else
genericRGBColorSpace.reset( CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB ) );
#endif
}
return genericRGBColorSpace;
}
#if wxOSX_USE_COCOA_OR_CARBON
CGColorRef wxMacCreateCGColorFromHITheme( ThemeBrush brush )
{
CGColorRef color ;
HIThemeBrushCreateCGColor( brush, &color );
return color;
}
#endif // wxOSX_USE_COCOA_OR_CARBON
IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl , wxObject )
wxWidgetImpl::wxWidgetImpl( wxWindowMac* peer , bool isRootControl )
{
Init();
m_isRootControl = isRootControl;
m_wxPeer = peer;
}
wxWidgetImpl::wxWidgetImpl()
{
Init();
}
wxWidgetImpl::~wxWidgetImpl()
{
}
void wxWidgetImpl::Init()
{
m_isRootControl = false;
m_wxPeer = NULL;
m_needsFocusRect = false;
}
void wxWidgetImpl::Destroy()
{
}
void wxWidgetImpl::SetNeedsFocusRect( bool needs )
{
m_needsFocusRect = needs;
}
bool wxWidgetImpl::NeedsFocusRect() const
{
return m_needsFocusRect;
}
#endif // wxUSE_GUI