From: Gilles Depeyrot Date: Sun, 1 Apr 2001 20:42:05 +0000 (+0000) Subject: corrections for final release of Mac OS X X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/5fde6fcc9b551340a194ae4c726db5ab64b5c594 corrections for final release of Mac OS X applied patches proposed by Mark Newsam git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9625 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/generic/spinctlg.h b/include/wx/generic/spinctlg.h index f9f01943ce..c7eb2758ef 100644 --- a/include/wx/generic/spinctlg.h +++ b/include/wx/generic/spinctlg.h @@ -77,6 +77,9 @@ protected: int m_min; int m_max; + +private: + DECLARE_DYNAMIC_CLASS(wxSpinCtrl) }; #endif // _WX_GENERIC_SPINCTRL_H_ diff --git a/include/wx/geometry.h b/include/wx/geometry.h index 151f87aad6..7bc7f527eb 100644 --- a/include/wx/geometry.h +++ b/include/wx/geometry.h @@ -32,7 +32,7 @@ #define wxMulDivInt32( a , b , c ) ::MulDiv( a , b , c ) #elif defined( __WXMAC__ ) #ifdef __WXMAC_X__ - #include + #include #else #include "Math64.h" #endif diff --git a/include/wx/html/forcelnk.h b/include/wx/html/forcelnk.h index 16485fdd57..2a9c70f5c6 100644 --- a/include/wx/html/forcelnk.h +++ b/include/wx/html/forcelnk.h @@ -44,6 +44,7 @@ See mod_*.cpp and htmlwin.cpp for example :-) // This must be part of the module you want to force: #define FORCE_LINK_ME(module_name) \ + int _link_dummy_func_##module_name (); \ int _link_dummy_func_##module_name () \ { \ return 1; \ diff --git a/include/wx/mac/bitmap.h b/include/wx/mac/bitmap.h index a696eb125a..85eaf59e81 100644 --- a/include/wx/mac/bitmap.h +++ b/include/wx/mac/bitmap.h @@ -61,6 +61,7 @@ public: bool Create(const wxBitmap& bitmap); // Implementation + bool PointMasked(int x, int y); inline WXHBITMAP GetMaskBitmap() const { return m_maskBitmap; } inline void SetMaskBitmap(WXHBITMAP bmp) { m_maskBitmap = bmp; } protected: @@ -153,28 +154,33 @@ public: wxBitmap(int width, int height, int depth = -1); ~wxBitmap(); + // get the given part of bitmap + wxBitmap GetSubBitmap( const wxRect& rect ) const; + virtual bool Create(int width, int height, int depth = -1); virtual bool Create(void *data, long type, int width, int height, int depth = 1); virtual bool LoadFile(const wxString& name, long type = wxBITMAP_TYPE_BMP_RESOURCE); virtual bool SaveFile(const wxString& name, int type, const wxPalette *cmap = NULL); - inline bool Ok() const { return (M_BITMAPDATA && M_BITMAPDATA->m_ok); } - inline int GetWidth() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_width : 0); } - inline int GetHeight() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_height : 0); } - inline int GetDepth() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_depth : 0); } - inline int GetQuality() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_quality : 0); } + bool Ok() const; + int GetWidth() const; + int GetHeight() const; + int GetDepth() const; + int GetQuality() const; void SetWidth(int w); void SetHeight(int h); void SetDepth(int d); void SetQuality(int q); void SetOk(bool isOk); - inline wxPalette* GetPalette() const { return (M_BITMAPDATA ? (& M_BITMAPDATA->m_bitmapPalette) : (wxPalette*) NULL); } + wxPalette* GetPalette() const; void SetPalette(const wxPalette& palette); - inline wxMask *GetMask() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_bitmapMask : (wxMask*) NULL); } + wxMask *GetMask() const; void SetMask(wxMask *mask) ; + int GetBitmapType() const; + inline wxBitmap& operator = (const wxBitmap& bitmap) { if (*this == bitmap) return (*this); Ref(bitmap); return *this; } inline bool operator == (const wxBitmap& bitmap) { return m_refData == bitmap.m_refData; } inline bool operator != (const wxBitmap& bitmap) { return m_refData != bitmap.m_refData; } @@ -196,8 +202,10 @@ protected: // TODO: Implementation public: void SetHBITMAP(WXHBITMAP bmp); - inline WXHBITMAP GetHBITMAP() const { return (M_BITMAPDATA ? M_BITMAPDATA->m_hBitmap : 0); } + WXHBITMAP GetHBITMAP() const; + PicHandle GetPict() const; + bool FreeResource(bool force = FALSE); }; #endif diff --git a/include/wx/mac/choice.h b/include/wx/mac/choice.h index fa92e234d1..335bebd869 100644 --- a/include/wx/mac/choice.h +++ b/include/wx/mac/choice.h @@ -31,7 +31,7 @@ class WXDLLEXPORT wxChoice: public wxChoiceBase public: wxChoice() {} - ~wxChoice() ; + virtual ~wxChoice() ; wxChoice(wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, @@ -52,12 +52,15 @@ class WXDLLEXPORT wxChoice: public wxChoiceBase const wxValidator& validator = wxDefaultValidator, const wxString& name = wxChoiceNameStr); - virtual int DoAppend(const wxString& item); + // implement base class pure virtuals + virtual int DoAppend(const wxString& item); virtual void Delete(int n); virtual void Clear(); + virtual int GetCount() const ; virtual int GetSelection() const ; virtual void SetSelection(int n); + virtual int FindString(const wxString& s) const; virtual wxString GetString(int n) const ; virtual void SetString( int , const wxString& s ) ; @@ -73,9 +76,9 @@ class WXDLLEXPORT wxChoice: public wxChoiceBase virtual wxString GetStringSelection() const ; virtual bool SetStringSelection(const wxString& sel); - virtual inline int Number() const { return m_strings.GetCount(); } - virtual inline int GetCount() const { return m_strings.GetCount(); } + // Mac specific virtual void Command(wxCommandEvent& event); + void MacHandleControlClick( ControlHandle control , SInt16 controlpart ) ; virtual inline int GetColumns() const { return 1 ; }; */ diff --git a/include/wx/mac/dnd.h b/include/wx/mac/dnd.h index 4a1295fd1e..2b0f35375d 100644 --- a/include/wx/mac/dnd.h +++ b/include/wx/mac/dnd.h @@ -156,7 +156,7 @@ class WXDLLEXPORT wxDropTarget: public wxObject virtual void OnEnter() { } virtual void OnLeave() { } - virtual bool OnDrop( long x, long y, const void *pData ) = 0; + virtual bool OnDrop( wxCoord x, wxCoord y, const void *pData ) = 0; // protected: @@ -178,8 +178,8 @@ class WXDLLEXPORT wxTextDropTarget: public wxDropTarget public: wxTextDropTarget() {}; - virtual bool OnDrop( long x, long y, const void *pData ); - virtual bool OnDropText( long x, long y, const char *psz ); + virtual bool OnDrop( wxCoord x, wxCoord y, const void *pData ); + virtual bool OnDropText( wxCoord x, wxCoord y, const char *psz ); protected: @@ -197,8 +197,8 @@ class WXDLLEXPORT wxFileDropTarget: public wxDropTarget wxFileDropTarget() {}; - virtual bool OnDrop(long x, long y, const void *pData); - virtual bool OnDropFiles( long x, long y, + virtual bool OnDrop(wxCoord x, wxCoord y, const void *pData); + virtual bool OnDropFiles( wxCoord x, wxCoord y, size_t nFiles, const char * const aszFiles[]); protected: diff --git a/include/wx/mac/metafile.h b/include/wx/mac/metafile.h index c65ec89071..366ee6ce3a 100644 --- a/include/wx/mac/metafile.h +++ b/include/wx/mac/metafile.h @@ -20,7 +20,7 @@ #include "wx/gdiobj.h" #if wxUSE_DRAG_AND_DROP -#include "wx/dataobj.h" wx/defs.h +#include "wx/dataobj.h" #endif /* diff --git a/include/wx/mac/statbmp.h b/include/wx/mac/statbmp.h index a17d51af4b..a457c967f9 100644 --- a/include/wx/mac/statbmp.h +++ b/include/wx/mac/statbmp.h @@ -63,7 +63,7 @@ class WXDLLEXPORT wxStaticBitmap: public wxControl // for compatibility with wxMSW void SetIcon(const wxIcon& icon) { - SetBitmap( icon ); + SetBitmap( (const wxBitmap&) icon ); } // overriden base class virtuals diff --git a/include/wx/mac/statusbr.h b/include/wx/mac/statusbr.h index 622cbab452..2803992734 100644 --- a/include/wx/mac/statusbr.h +++ b/include/wx/mac/statusbr.h @@ -17,8 +17,6 @@ #pragma interface "statbar.h" #endif -#include "wx/generic/statusbr.h" - class WXDLLEXPORT wxStatusBarMac : public wxStatusBarGeneric { DECLARE_DYNAMIC_CLASS(wxStatusBarMac); @@ -50,4 +48,4 @@ protected: }; #endif - // _WX_STATBAR_H_ \ No newline at end of file + // _WX_STATBAR_H_ diff --git a/include/wx/mac/window.h b/include/wx/mac/window.h index bef7586650..bd6c9cec42 100644 --- a/include/wx/mac/window.h +++ b/include/wx/mac/window.h @@ -270,7 +270,6 @@ public : virtual void MacGetPortClientParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindow** rootwin) ; virtual void MacDoGetPortClientParams(Point* localOrigin, Rect* clipRect, WindowRef *window , wxWindow** rootwin) ; MacWindowData* MacGetWindowData() { return m_macWindowData ; } - static WindowRef MacGetWindowInUpdate() { return s_macWindowInUpdate ; } bool MacIsWindowScrollbar( const wxScrollBar* sb ) { return (m_hScrollBar == sb || m_vScrollBar == sb) ; } static wxWindow* s_lastMouseWindow ; private: @@ -278,7 +277,6 @@ private: protected: MacWindowData* m_macWindowData ; - static WindowRef s_macWindowInUpdate ; RgnHandle m_macUpdateRgn ; int m_x ; diff --git a/include/wx/object.h b/include/wx/object.h index 458f5e78e6..4c5ce0c4b4 100644 --- a/include/wx/object.h +++ b/include/wx/object.h @@ -115,6 +115,7 @@ WXDLLEXPORT wxObject* wxCreateStoredObject( wxInputStream& stream ); // Single inheritance with one base class #define IMPLEMENT_DYNAMIC_CLASS(name, basename) \ +wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name(void); \ wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name(void) \ { return new name; }\ wxClassInfo name::sm_class##name((wxChar *) wxT(#name), (wxChar *) wxT(#basename), (wxChar *) NULL, (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name); diff --git a/include/wx/spinbutt.h b/include/wx/spinbutt.h index 7e1cddfe98..5f8026b488 100644 --- a/include/wx/spinbutt.h +++ b/include/wx/spinbutt.h @@ -13,9 +13,9 @@ #define _WX_SPINBUTT_H_BASE_ #ifdef __GNUG__ - #ifndef __WXMOTIF__ // because there is no matching .cpp for Motif + #if !defined(__WXMOTIF__) && !defined(__WXMAC__) // because there is no matching .cpp #pragma interface "spinbutbase.h" - #endif // Motif + #endif #endif // ---------------------------------------------------------------------------- diff --git a/include/wx/statusbr.h b/include/wx/statusbr.h index ac33321b0c..8bd7b8965e 100644 --- a/include/wx/statusbr.h +++ b/include/wx/statusbr.h @@ -54,7 +54,8 @@ protected: #include "wx/msw/statbr95.h" typedef wxStatusBar95 wxStatusBarReal; -#elif defined(__WXMAC__) && !defined(__UNIX__) +#elif defined(__WXMAC__) /* && !defined(__UNIX__) */ + #include "wx/generic/statusbr.h" #include "wx/mac/statusbr.h" typedef wxStatusBarMac wxStatusBarReal; diff --git a/include/wx/stubs/treectrl.h b/include/wx/stubs/treectrl.h index 000bc1824a..14fac525fc 100644 --- a/include/wx/stubs/treectrl.h +++ b/include/wx/stubs/treectrl.h @@ -256,6 +256,7 @@ protected: wxEVT_COMMAND_TREE_KEY_DOWN */ +#ifndef __WXMAC_X__ class WXDLLEXPORT wxTreeEvent: public wxCommandEvent { DECLARE_DYNAMIC_CLASS(wxTreeEvent) @@ -275,6 +276,7 @@ class WXDLLEXPORT wxTreeEvent: public wxCommandEvent }; typedef void (wxEvtHandler::*wxTreeEventFunction)(wxTreeEvent&); +#endif #endif // _WX_TREECTRL_H_ diff --git a/src/common/dynlib.cpp b/src/common/dynlib.cpp index 6830ec2265..5f3f4fab75 100644 --- a/src/common/dynlib.cpp +++ b/src/common/dynlib.cpp @@ -247,7 +247,7 @@ wxDllLoader::LoadLibrary(const wxString & libname, bool *success) char zError[256] = ""; wxDllOpen(zError, libname, handle); #else // !Mac - handle = wxDllOpen(libname); + handle = wxDllOpen((char *)libname); #endif // OS if ( !handle ) @@ -321,7 +321,7 @@ wxDllLoader::GetSymbol(wxDllType dllHandle, const wxString &name) wxDllGetSymbol(dllHandle, symbol); #else // mb_str() is necessary in Unicode build - symbol = wxDllGetSymbol(dllHandle, name.mb_str()); + symbol = wxDllGetSymbol(dllHandle, (char *)name.mb_str()); #endif if ( !symbol ) diff --git a/src/common/ffile.cpp b/src/common/ffile.cpp index 4bca0e0e2e..a3eaac2586 100644 --- a/src/common/ffile.cpp +++ b/src/common/ffile.cpp @@ -64,7 +64,7 @@ bool wxFFile::Open(const wxChar *filename, const char *mode) tmp_fname = new char[fname_len]; wxWX2MB(tmp_fname, filename, fname_len); -#ifdef __WXMAC__ +#if defined(__WXMAC__) && !defined(__UNIX__) m_fp = fopen(wxUnix2MacFilename( tmp_fname ), mode); #else m_fp = fopen(tmp_fname, mode); @@ -72,7 +72,7 @@ bool wxFFile::Open(const wxChar *filename, const char *mode) delete tmp_fname; #else -#ifdef __WXMAC__ +#if defined(__WXMAC__) && !defined(__UNIX__) m_fp = fopen(wxUnix2MacFilename( filename ), mode); #else m_fp = fopen(filename, mode); diff --git a/src/common/file.cpp b/src/common/file.cpp index 5fac43328c..243bdc0373 100644 --- a/src/common/file.cpp +++ b/src/common/file.cpp @@ -136,7 +136,7 @@ bool wxFile::Exists(const wxChar *name) #if wxUSE_UNICODE && wxMBFILES wxCharBuffer fname = wxConvFile.cWC2MB(name); -#ifdef __WXMAC__ +#if defined(__WXMAC__) && !defined(__UNIX__) return !access(wxUnix2MacFilename( name ) , 0) && !stat(wxUnix2MacFilename( name ), &st) && (st.st_mode & S_IFREG); #else return !wxAccess(fname, 0) && @@ -144,7 +144,7 @@ bool wxFile::Exists(const wxChar *name) (st.st_mode & S_IFREG); #endif #else -#ifdef __WXMAC__ +#if defined(__WXMAC__) && !defined(__UNIX__) return !access(wxUnix2MacFilename( name ) , 0) && !stat(wxUnix2MacFilename( name ), &st) && (st.st_mode & S_IFREG); #else return !wxAccess(name, 0) && @@ -192,7 +192,7 @@ bool wxFile::Create(const wxChar *szFileName, bool bOverwrite, int accessMode) { // if bOverwrite we create a new file or truncate the existing one, // otherwise we only create the new file and fail if it already exists -#ifdef __WXMAC__ +#if defined(__WXMAC__) && !defined(__UNIX__) // Dominic Mazzoni [dmazzoni+@cs.cmu.edu] reports that open is still broken on the mac, so we replace // int fd = open(wxUnix2MacFilename( szFileName ), O_CREAT | (bOverwrite ? O_TRUNC : O_EXCL), access); int fd = creat(wxUnix2MacFilename( szFileName ), accessMode); @@ -240,7 +240,7 @@ bool wxFile::Open(const wxChar *szFileName, OpenMode mode, int accessMode) break; } -#ifdef __WXMAC__ +#if defined(__WXMAC__) && !defined(__UNIX__) int fd = open(wxUnix2MacFilename( szFileName ), flags, access); #else int fd = wxOpen(wxFNCONV(szFileName), flags ACCESS(accessMode)); @@ -555,7 +555,7 @@ bool wxTempFile::Commit() { m_file.Close(); -#ifndef __WXMAC__ +#if !defined(__WXMAC__) || defined(__UNIX__) if ( wxFile::Exists(m_strName) && wxRemove(m_strName) != 0 ) { wxLogSysError(_("can't remove file '%s'"), m_strName.c_str()); return FALSE; @@ -583,7 +583,7 @@ bool wxTempFile::Commit() void wxTempFile::Discard() { m_file.Close(); -#ifndef __WXMAC__ +#if !defined(__WXMAC__) || defined(__UNIX__) if ( wxRemove(m_strTemp) != 0 ) wxLogSysError(_("can't remove temporary file '%s'"), m_strTemp.c_str()); #else diff --git a/src/common/fileconf.cpp b/src/common/fileconf.cpp index bf8103304c..b8fec80df7 100644 --- a/src/common/fileconf.cpp +++ b/src/common/fileconf.cpp @@ -797,7 +797,7 @@ bool wxFileConfig::Flush(bool /* bCurrentOnly */) bool ret = file.Commit(); -#ifdef __WXMAC__ +#if defined(__WXMAC__) && !defined(__UNIX__) if ( ret ) { FSSpec spec ; @@ -811,7 +811,7 @@ bool wxFileConfig::Flush(bool /* bCurrentOnly */) FSpSetFInfo( &spec , &finfo ) ; } } -#endif // __WXMAC__ +#endif // __WXMAC__ && !__UNIX__ #ifdef __UNIX__ // restore the old umask if we changed it diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index b8ceb922f1..d06257478f 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -1058,7 +1058,7 @@ wxCopyFile (const wxString& file1, const wxString& file2) return FALSE; } -#if !defined(__VISAGECPP__) && !defined(__WXMAC__) +#if !defined(__VISAGECPP__) && !defined(__WXMAC__) || defined(__UNIX__) // no chmod in VA. SHould be some permission API for HPFS386 partitions however if ( chmod(OS_FILENAME(file2), fbuf.st_mode) != 0 ) { @@ -1099,7 +1099,7 @@ bool wxRemoveFile(const wxString& file) bool wxMkdir(const wxString& dir, int perm) { -#if defined( __WXMAC__ ) +#if defined(__WXMAC__) && !defined(__UNIX__) return (mkdir(wxUnix2MacFilename( dir ) , 0 ) == 0); #else // !Mac const wxChar *dirname = dir.c_str(); @@ -1664,7 +1664,7 @@ wxChar *wxGetWorkingDirectory(wxChar *buf, int sz) char *cbuf = new char[sz+1]; #ifdef _MSC_VER if (_getcwd(cbuf, sz) == NULL) { -#elif defined( __WXMAC__) +#elif defined(__WXMAC__) && !defined(__UNIX__) enum { SFSaveDisk = 0x214, CurDirStore = 0x398 @@ -1682,7 +1682,7 @@ wxChar *wxGetWorkingDirectory(wxChar *buf, int sz) #else // wxUnicode #ifdef _MSC_VER if (_getcwd(buf, sz) == NULL) { -#elif defined( __WXMAC__) +#elif defined(__WXMAC__) && !defined(__UNIX__) FSSpec cwdSpec ; FCBPBRec pb; OSErr error; diff --git a/src/common/image.cpp b/src/common/image.cpp index 3e54488163..ffdf89c740 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -1402,17 +1402,11 @@ wxImage::wxImage( const wxBitmap &bitmap ) #ifdef __WXMAC__ #ifdef __UNIX__ - #include + #include #else #include #endif -extern CTabHandle wxMacCreateColorTable( int numColors ) ; -extern void wxMacDestroyColorTable( CTabHandle colors ) ; -extern void wxMacSetColorTableEntry( CTabHandle newColors , int index , int red , int green , int blue ) ; -extern GWorldPtr wxMacCreateGWorld( int width , int height , int depth ) ; -extern void wxMacDestroyGWorld( GWorldPtr gw ) ; - wxBitmap wxImage::ConvertToBitmap() const { // width and height of the device-dependent bitmap @@ -1421,35 +1415,27 @@ wxBitmap wxImage::ConvertToBitmap() const // Create picture - wxBitmap bitmap( width , height , wxDisplayDepth() ) ; - - // Create mask - - if (HasMask()) - { - /* - unsigned char *mask_data = (unsigned char*)malloc( ((width >> 3)+8) * height ); - - mask_image = gdk_image_new_bitmap( gdk_visual_get_system(), mask_data, width, height ); - - wxMask *mask = new wxMask(); - mask->m_bitmap = gdk_pixmap_new( (GdkWindow*)&gdk_root_parent, width, height, 1 ); - - bitmap.SetMask( mask ); - */ - } - - // Render - - int r_mask = GetMaskRed(); - int g_mask = GetMaskGreen(); - int b_mask = GetMaskBlue(); + wxBitmap bitmap; + wxCHECK_MSG( Ok(), bitmap, wxT("invalid image") ); + + bitmap.Create( width , height , wxDisplayDepth() ) ; + wxBitmap maskBitmap( width, height, 1); + CGrafPtr origPort ; GDHandle origDevice ; + LockPixels( GetGWorldPixMap(bitmap.GetHBITMAP()) ); + LockPixels( GetGWorldPixMap(maskBitmap.GetHBITMAP()) ); + GetGWorld( &origPort , &origDevice ) ; SetGWorld( bitmap.GetHBITMAP() , NULL ) ; + + // Render image + wxColour rgb, maskcolor(GetMaskRed(), GetMaskGreen(), GetMaskBlue()); + RGBColor color; + RGBColor white = { 0xffff, 0xffff, 0xffff }; + RGBColor black = { 0 , 0 , 0 }; register unsigned char* data = GetData(); @@ -1458,158 +1444,96 @@ wxBitmap wxImage::ConvertToBitmap() const { for (int x = 0; x < width; x++) { - unsigned char r = data[index++]; - unsigned char g = data[index++]; - unsigned char b = data[index++]; - RGBColor color ; - color.red = ( r << 8 ) + r ; - color.green = ( g << 8 ) + g ; - color.blue = ( b << 8 ) + b ; + rgb.Set(data[index++], data[index++], data[index++]); + color = rgb.GetPixel(); SetCPixel( x , y , &color ) ; + if (HasMask()) + { + SetGWorld(maskBitmap.GetHBITMAP(), NULL); + if (rgb == maskcolor) { + SetCPixel(x,y, &white); + } + else { + SetCPixel(x,y, &black); + } + SetGWorld(bitmap.GetHBITMAP(), NULL); + } } } // for height - SetGWorld( origPort , origDevice ) ; - - if ( HasMask() ) - { - wxColour colour( GetMaskRed(), GetMaskGreen(), GetMaskBlue()); - wxMask *mask = new wxMask( bitmap, colour ); - bitmap.SetMask( mask ); + // Create mask + if ( HasMask() ) { + wxMask *mask = new wxMask( maskBitmap ); } - return bitmap; + + UnlockPixels( GetGWorldPixMap(bitmap.GetHBITMAP()) ); + UnlockPixels( GetGWorldPixMap(maskBitmap.GetHBITMAP()) ); + SetGWorld( origPort, origDevice ); + return bitmap; } wxImage::wxImage( const wxBitmap &bitmap ) { // check the bitmap - if( !bitmap.Ok() ) - { - wxFAIL_MSG( "invalid bitmap" ); - return; - } + wxCHECK_RET( bitmap.Ok(), wxT("Invalid bitmap") ); // create an wxImage object int width = bitmap.GetWidth(); int height = bitmap.GetHeight(); Create( width, height ); - /* + unsigned char *data = GetData(); - if( !data ) - { - wxFAIL_MSG( "could not allocate data for image" ); - return; - } - // calc the number of bytes per scanline and padding in the DIB - int bytePerLine = width*3; - int sizeDWORD = sizeof( DWORD ); - div_t lineBoundary = div( bytePerLine, sizeDWORD ); - int padding = 0; - if( lineBoundary.rem > 0 ) - { - padding = sizeDWORD - lineBoundary.rem; - bytePerLine += padding; - } + wxCHECK_RET( data, wxT("Could not allocate data for image") ); - // create a DIB header - int headersize = sizeof(BITMAPINFOHEADER); - LPBITMAPINFO lpDIBh = (BITMAPINFO *) malloc( headersize ); - if( !lpDIBh ) - { - wxFAIL_MSG( "could not allocate data for DIB header" ); - free( data ); - return; - } - // Fill in the DIB header - lpDIBh->bmiHeader.biSize = headersize; - lpDIBh->bmiHeader.biWidth = width; - lpDIBh->bmiHeader.biHeight = -height; - lpDIBh->bmiHeader.biSizeImage = bytePerLine * height; - lpDIBh->bmiHeader.biPlanes = 1; - lpDIBh->bmiHeader.biBitCount = 24; - lpDIBh->bmiHeader.biCompression = BI_RGB; - lpDIBh->bmiHeader.biClrUsed = 0; - // These seem not really needed for our purpose here. - lpDIBh->bmiHeader.biClrImportant = 0; - lpDIBh->bmiHeader.biXPelsPerMeter = 0; - lpDIBh->bmiHeader.biYPelsPerMeter = 0; - // memory for DIB data - unsigned char *lpBits; - lpBits = (unsigned char *) malloc( lpDIBh->bmiHeader.biSizeImage ); - if( !lpBits ) - { - wxFAIL_MSG( "could not allocate data for DIB" ); - free( data ); - free( lpDIBh ); - return; - } + WXHBITMAP origPort; + GDHandle origDevice; + int index; + RGBColor color; + // background color set to RGB(16,16,16) in consistent with wxGTK + unsigned char mask_r=16, mask_g=16, mask_b=16; + SInt16 r,g,b; + wxMask *mask = bitmap.GetMask(); - // copy data from the device-dependent bitmap to the DIB - HDC hdc = ::GetDC(NULL); - HBITMAP hbitmap; - hbitmap = (HBITMAP) bitmap.GetHBITMAP(); - ::GetDIBits( hdc, hbitmap, 0, height, lpBits, lpDIBh, DIB_RGB_COLORS ); - - // copy DIB data into the wxImage object - int i, j; - unsigned char *ptdata = data; - unsigned char *ptbits = lpBits; - for( i=0; iGetMaskBitmap() ) + // Copy data into image + index = 0; + for (int yy = 0; yy < height; yy++) { - hbitmap = (HBITMAP) bitmap.GetMask()->GetMaskBitmap(); - // memory DC created, color set, data copied, and memory DC deleted - HDC memdc = ::CreateCompatibleDC( hdc ); - ::SetTextColor( memdc, RGB( 0, 0, 0 ) ); - ::SetBkColor( memdc, RGB( 255, 255, 255 ) ); - ::GetDIBits( memdc, hbitmap, 0, height, lpBits, lpDIBh, DIB_RGB_COLORS ); - ::DeleteDC( memdc ); - // background color set to RGB(16,16,16) in consistent with wxGTK - unsigned char r=16, g=16, b=16; - ptdata = data; - ptbits = lpBits; - for( i=0; i> 8); + g = ((color.green ) >> 8); + b = ((color.blue ) >> 8); + data[index ] = r; + data[index + 1] = g; + data[index + 2] = b; + if (mask) { - if( *ptbits != 0 ) - ptdata += 3; - else + if (mask->PointMasked(xx,yy)) { - *(ptdata++) = r; - *(ptdata++) = g; - *(ptdata++) = b; + data[index ] = mask_r; + data[index + 1] = mask_g; + data[index + 2] = mask_b; } - ptbits += 3; } - ptbits += padding; + index += 3; } - SetMaskColour( r, g, b ); - SetMask( TRUE ); } - else + if (mask) { - SetMask( FALSE ); + SetMaskColour( mask_r, mask_g, mask_b ); + SetMask( true ); } - // free allocated resources - ::ReleaseDC(NULL, hdc); - free(lpDIBh); - free(lpBits); - */ + + // Free resources + UnlockPixels(GetGWorldPixMap(bitmap.GetHBITMAP())); + SetGWorld(origPort, origDevice); } #endif diff --git a/src/common/mimecmn.cpp b/src/common/mimecmn.cpp index 80457d0b61..7ee3ef0dff 100644 --- a/src/common/mimecmn.cpp +++ b/src/common/mimecmn.cpp @@ -55,9 +55,9 @@ // implementation classes: #if defined(__WXMSW__) #include "wx/msw/mimetype.h" -#elif defined (__WXMAC__) +#elif defined(__WXMAC__) #include "wx/mac/mimetype.h" -#elif defined (__WXPM__) +#elif defined(__WXPM__) #include "wx/os2/mimetype.h" #else // Unix #include "wx/unix/mimetype.h" diff --git a/src/common/resource.cpp b/src/common/resource.cpp index d6c56f61d4..5a01013738 100644 --- a/src/common/resource.cpp +++ b/src/common/resource.cpp @@ -227,7 +227,7 @@ bool wxResourceTable::ParseResourceFile(const wxString& filename) { wxExprDatabase db; -#ifdef __WXMAC__ +#if defined(__WXMAC__) && !defined(__UNIX__) FILE *fd = fopen(wxUnix2MacFilename(filename.fn_str()), "r"); #else FILE *fd = wxFopen(filename, _T("r")); diff --git a/src/common/unzip.c b/src/common/unzip.c index be48958cfb..551b1c6b2d 100644 --- a/src/common/unzip.c +++ b/src/common/unzip.c @@ -358,7 +358,7 @@ local uLong unzlocal_SearchCentralDir(fin) return uPosFound; } -#ifdef __WXMAC__ +#if defined(__WXMAC__) && !defined(__UNIX__) void wxUnix2MacFilename (char *s) ; void wxUnix2MacFilename (char *s) @@ -430,10 +430,10 @@ extern unzFile ZEXPORT unzOpen (path) if (unz_copyright[0]!=' ') return NULL; -#ifdef __WXMAC__ +#if defined(__WXMAC__) && !defined(__UNIX__) strcpy( wxBuffer , path ) ; wxUnix2MacFilename( wxBuffer ) ; - fin=fopen(wxBuffer,"rb"); + fin=fopen(wxBuffer,"rb"); #else fin=fopen(path,"rb"); #endif diff --git a/src/common/zstream.cpp b/src/common/zstream.cpp index 29a7dfa23b..c83d44a4de 100644 --- a/src/common/zstream.cpp +++ b/src/common/zstream.cpp @@ -34,7 +34,7 @@ #if defined(__WXMSW__) && !defined(__WX_SETUP_H__) && !defined(wxUSE_ZLIB_H_IN_PATH) #include "../zlib/zlib.h" #elif defined(__WXMAC__) && defined(__UNIX__) - #include + #include #else #include #endif diff --git a/src/mac/aga.cpp b/src/mac/aga.cpp index 6c24f5ddf8..1f3310aca5 100644 --- a/src/mac/aga.cpp +++ b/src/mac/aga.cpp @@ -1,3 +1,4 @@ +#include "wx/dc.h" #include "wx/mac/uma.h" #include "wx/mac/aga.h" diff --git a/src/mac/app.cpp b/src/mac/app.cpp index 97c3590a5e..c7c54a882c 100644 --- a/src/mac/app.cpp +++ b/src/mac/app.cpp @@ -53,7 +53,7 @@ #if wxUSE_SOCKETS #ifdef __APPLE__ - #include + #include #else #include #include @@ -95,25 +95,25 @@ bool wxApp::s_macSupportPCMenuShortcuts = true ; long wxApp::s_macAboutMenuItemId = wxID_ABOUT ; wxString wxApp::s_macHelpMenuTitleName = "&Help" ; -pascal OSErr AEHandleODoc( const AppleEvent *event , AppleEvent *reply , unsigned long refcon ) +pascal OSErr AEHandleODoc( const AppleEvent *event , AppleEvent *reply , long refcon ) { wxApp* app = (wxApp*) refcon ; return wxTheApp->MacHandleAEODoc( (AppleEvent*) event , reply) ; } -pascal OSErr AEHandleOApp( const AppleEvent *event , AppleEvent *reply , unsigned long refcon ) +pascal OSErr AEHandleOApp( const AppleEvent *event , AppleEvent *reply , long refcon ) { wxApp* app = (wxApp*) refcon ; return wxTheApp->MacHandleAEOApp( (AppleEvent*) event , reply ) ; } -pascal OSErr AEHandlePDoc( const AppleEvent *event , AppleEvent *reply , unsigned long refcon ) +pascal OSErr AEHandlePDoc( const AppleEvent *event , AppleEvent *reply , long refcon ) { wxApp* app = (wxApp*) refcon ; return wxTheApp->MacHandleAEPDoc( (AppleEvent*) event , reply ) ; } -pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , unsigned long refcon ) +pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , long refcon ) { wxApp* app = (wxApp*) refcon ; return wxTheApp->MacHandleAEQuit( (AppleEvent*) event , reply) ; @@ -1469,7 +1469,11 @@ void wxApp::MacHandleOSEvent( EventRecord *ev ) case suspendResumeMessage : { bool isResuming = ev->message & resumeFlag ; +#if !TARGET_CARBON bool convertClipboard = ev->message & convertClipboardFlag ; +#else + bool convertClipboard = false; +#endif bool doesActivate = UMAGetProcessModeDoesActivateOnFGSwitch() ; if ( isResuming ) { diff --git a/src/mac/bitmap.cpp b/src/mac/bitmap.cpp index 5c1aec6c5f..5cc2a537fd 100644 --- a/src/mac/bitmap.cpp +++ b/src/mac/bitmap.cpp @@ -36,7 +36,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject) #endif #ifdef __UNIX__ - #include + #include #else #include #endif @@ -97,6 +97,97 @@ void wxMacDestroyGWorld( GWorldPtr gw ) DisposeGWorld( gw ) ; } +PicHandle wxMacCreatePict(GWorldPtr wp, GWorldPtr mask) +{ + CGrafPtr origPort ; + GDHandle origDev ; + + PicHandle pict; // this is the Picture we give back + + RGBColor gray = { 0xCCCC ,0xCCCC , 0xCCCC } ; + RGBColor white = { 0xffff ,0xffff , 0xffff } ; + RGBColor black = { 0x0000 ,0x0000 , 0x0000 } ; + + unsigned char *maskimage = NULL ; + Rect portRect ; + GetPortBounds( wp , &portRect ) ; + int width = portRect.right - portRect.left ; + int height = portRect.bottom - portRect.top ; + + LockPixels( GetGWorldPixMap( wp ) ) ; + GetGWorld( &origPort , &origDev ) ; + + if ( mask ) + { + maskimage = (unsigned char*) malloc( width * height ) ; + SetGWorld( mask , NULL ) ; + LockPixels( GetGWorldPixMap( mask ) ) ; + for ( int y = 0 ; y < height ; y++ ) + { + for( int x = 0 ; x < width ; x++ ) + { + RGBColor col ; + + GetCPixel( x + portRect.left , y + portRect.top , &col ) ; + maskimage[y*width + x] = ( col.red == 0 ) ; // for monochrome masks + } + } + UnlockPixels( GetGWorldPixMap( mask ) ) ; + } + + SetGWorld( wp , NULL ) ; + + pict = OpenPicture(&portRect); // open a picture, this disables drawing + if(!pict) + return NULL; + + if ( maskimage ) + { + RGBForeColor( &black ) ; + RGBBackColor( &white ) ; + PenMode(transparent); + + for ( int y = 0 ; y < height ; ++y ) + { + for( int x = 0 ; x < width ; ++x ) + { + if ( maskimage[y*width + x] ) + { + RGBColor col ; + + GetCPixel( x + portRect.left , y + portRect.top , &col ) ; + SetCPixel( x + portRect.left , y + portRect.top , &col ) ; + } + else { + // With transparency set this sets a blank pixel not a white one + SetCPixel( x + portRect.left , y + portRect.top , &white); + } + } + } + free( maskimage ) ; + maskimage = NULL ; + } + else + { + RGBBackColor( &gray ) ; + EraseRect(&portRect); + RGBForeColor( &black ) ; + RGBBackColor( &white ) ; + + CopyBits(GetPortBitMapForCopyBits(wp), /* src PixMap - we copy image over + * itself - */ + GetPortBitMapForCopyBits(wp), // dst PixMap - no drawing occurs + &portRect, // srcRect - it will be recorded and compressed - + &portRect, // dstRect - into the picture that is open - + srcCopy,NULL); // copyMode and no clip region + } + ClosePicture(); // We are done recording the picture + UnlockPixels( GetGWorldPixMap( wp ) ) ; + SetGWorld( origPort , origDev ) ; + + return pict; // return our groovy pict handle +} + wxBitmapRefData::wxBitmapRefData() { m_ok = FALSE; @@ -180,8 +271,18 @@ wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits GetGWorld( &origPort , &origDevice ) ; SetGWorld( M_BITMAPDATA->m_hBitmap , NULL ) ; - LockPixels( GetGWorldPixMap( (CGrafPtr) M_BITMAPDATA->m_hBitmap ) ) ; - + LockPixels( GetGWorldPixMap( M_BITMAPDATA->m_hBitmap ) ) ; + +#ifdef __UNIX__ + // bits is a word aligned array?? Don't think so + // bits is a char array on MAC OS X however using the benefit of the + // doubt I replaced references to 16 with sizeof(unsigned char)*8 + unsigned char* linestart = (unsigned char*) bits ; + int linesize = ( the_width / (sizeof(unsigned char) * 8)) ; + if ( the_width % (sizeof(unsigned char) * 8) ) { + linesize += sizeof(unsigned char); + } +#else // bits is a word aligned array unsigned char* linestart = (unsigned char*) bits ; @@ -190,6 +291,7 @@ wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits { linesize += 2 ; } +#endif RGBColor colors[2] = { { 0xFFFF , 0xFFFF , 0xFFFF } , @@ -214,7 +316,7 @@ wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits } } - UnlockPixels( GetGWorldPixMap( (CGrafPtr) M_BITMAPDATA->m_hBitmap ) ) ; + UnlockPixels( GetGWorldPixMap( M_BITMAPDATA->m_hBitmap ) ) ; SetGWorld( origPort , origDevice ) ; } @@ -261,6 +363,95 @@ wxBitmap::wxBitmap(char **data) (void) Create((void *)data, wxBITMAP_TYPE_XPM_DATA, 0, 0, 0); } +wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const +{ + wxCHECK_MSG( Ok() && + (rect.x >= 0) && (rect.y >= 0) && + (rect.x+rect.width <= GetWidth()) && + (rect.y+rect.height <= GetHeight()), + wxNullBitmap, wxT("invalid bitmap or bitmap region") ); + + + wxBitmap ret( rect.width, rect.height, GetDepth() ); + wxASSERT_MSG( ret.Ok(), wxT("GetSubBitmap error") ); + + WXHBITMAP origPort; + GDHandle origDevice; + + GetGWorld( &origPort, &origDevice ); + + // Update the subbitmaps reference data + wxBitmapRefData *ref = (wxBitmapRefData *)ret.GetRefData(); + + ref->m_numColors = M_BITMAPDATA->m_numColors; + ref->m_bitmapPalette = M_BITMAPDATA->m_bitmapPalette; + ref->m_bitmapType = M_BITMAPDATA->m_bitmapType; + + // Copy sub region of this bitmap + if(M_BITMAPDATA->m_bitmapType == kMacBitmapTypePict) + { + printf("GetSubBitmap: Copy a region of a Pict structure - TODO\n"); + } + else if(M_BITMAPDATA->m_bitmapType == kMacBitmapTypeGrafWorld) + { + // Copy mask + if(GetMask()) + { + WXHBITMAP submask, mask; + RGBColor color; + + mask = GetMask()->GetMaskBitmap(); + submask = wxMacCreateGWorld(rect.width, rect.height, 1); + LockPixels(GetGWorldPixMap(mask)); + LockPixels(GetGWorldPixMap(submask)); + + for(int yy = 0; yy < rect.height; yy++) + { + for(int xx = 0; xx < rect.width; xx++) + { + SetGWorld(mask, NULL); + GetCPixel(rect.x + xx, rect.y + yy, &color); + SetGWorld(submask, NULL); + SetCPixel(xx,yy, &color); + } + } + UnlockPixels(GetGWorldPixMap(mask)); + UnlockPixels(GetGWorldPixMap(submask)); + ref->m_bitmapMask = new wxMask; + ref->m_bitmapMask->SetMaskBitmap(submask); + } + + // Copy bitmap + if(GetHBITMAP()) + { + WXHBITMAP subbitmap, bitmap; + RGBColor color; + + bitmap = GetHBITMAP(); + subbitmap = wxMacCreateGWorld(rect.width, rect.height, GetDepth()); + LockPixels(GetGWorldPixMap(bitmap)); + LockPixels(GetGWorldPixMap(subbitmap)); + + for(int yy = 0; yy < rect.height; yy++) + { + for(int xx = 0; xx < rect.width; xx++) + { + SetGWorld(bitmap, NULL); + GetCPixel(rect.x + xx, rect.y + yy, &color); + SetGWorld(subbitmap, NULL); + SetCPixel(xx, yy, &color); + } + } + UnlockPixels(GetGWorldPixMap(bitmap)); + UnlockPixels(GetGWorldPixMap(subbitmap)); + ret.SetHBITMAP(subbitmap); + } + } + SetGWorld( origPort, origDevice ); + + return ret; +} + bool wxBitmap::Create(int w, int h, int d) { UnRef(); @@ -277,6 +468,13 @@ bool wxBitmap::Create(int w, int h, int d) return M_BITMAPDATA->m_ok; } +int wxBitmap::GetBitmapType() const +{ + wxCHECK_MSG( Ok(), kMacBitmapTypeUnknownType, wxT("invalid bitmap") ); + + return M_BITMAPDATA->m_bitmapType; +} + void wxBitmap::SetHBITMAP(WXHBITMAP bmp) { M_BITMAPDATA->m_bitmapType = kMacBitmapTypeGrafWorld ; @@ -331,6 +529,46 @@ bool wxBitmap::SaveFile(const wxString& filename, int type, const wxPalette *pal return handler->SaveFile(this, filename, type, palette); } +bool wxBitmap::Ok() const +{ + return (M_BITMAPDATA && M_BITMAPDATA->m_ok); +} + +int wxBitmap::GetHeight() const +{ + wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") ); + + return M_BITMAPDATA->m_height; +} + +int wxBitmap::GetWidth() const +{ + wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") ); + + return M_BITMAPDATA->m_width; +} + +int wxBitmap::GetDepth() const +{ + wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") ); + + return M_BITMAPDATA->m_depth; +} + +int wxBitmap::GetQuality() const +{ + wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") ); + + return M_BITMAPDATA->m_quality; +} + +wxMask *wxBitmap::GetMask() const +{ + wxCHECK_MSG( Ok(), (wxMask *) NULL, wxT("invalid bitmap") ); + + return M_BITMAPDATA->m_bitmapMask; +} + void wxBitmap::SetWidth(int w) { if (!M_BITMAPDATA) @@ -371,6 +609,13 @@ void wxBitmap::SetOk(bool isOk) M_BITMAPDATA->m_ok = isOk; } +wxPalette *wxBitmap::GetPalette() const +{ + wxCHECK_MSG( Ok(), NULL, wxT("Invalid bitmap GetPalette()") ); + + return &M_BITMAPDATA->m_bitmapPalette; +} + void wxBitmap::SetPalette(const wxPalette& palette) { if (!M_BITMAPDATA) @@ -387,6 +632,105 @@ void wxBitmap::SetMask(wxMask *mask) M_BITMAPDATA->m_bitmapMask = mask ; } +WXHBITMAP wxBitmap::GetHBITMAP() const +{ + wxCHECK_MSG( Ok(), NULL, wxT("invalid bitmap") ); + + return M_BITMAPDATA->m_hBitmap; +} + +PicHandle wxBitmap::GetPict() const +{ + wxCHECK_MSG( Ok(), NULL, wxT("invalid bitmap") ); + + PicHandle picture; // This is the returned picture + + // If bitmap already in Pict format return pointer + if(M_BITMAPDATA->m_bitmapType == kMacBitmapTypePict) { + return M_BITMAPDATA->m_hPict; + } + else if(M_BITMAPDATA->m_bitmapType != kMacBitmapTypeGrafWorld) { + // Invalid bitmap + return NULL; + } + + RGBColor gray = { 0xCCCC ,0xCCCC , 0xCCCC } ; + RGBColor white = { 0xffff ,0xffff , 0xffff } ; + RGBColor black = { 0x0000 ,0x0000 , 0x0000 } ; + CGrafPtr origPort; + GDHandle origDev ; + wxMask *mask; + Rect portRect ; + + GetPortBounds( GetHBITMAP() , &portRect ) ; + int width = portRect.right - portRect.left ; + int height = portRect.bottom - portRect.top ; + + LockPixels( GetGWorldPixMap( GetHBITMAP() ) ) ; + GetGWorld( &origPort , &origDev ) ; + + mask = GetMask(); + + SetGWorld( GetHBITMAP() , NULL ) ; + + picture = OpenPicture(&portRect); // open a picture, this disables drawing + if(!picture) { + return NULL; + } + + if( mask ) + { +#ifdef __UNIX__ + RGBColor trans = white; +#else + RGBBackColor( &gray ); + EraseRect( &portRect ); + RGBColor trans = gray; +#endif + RGBForeColor( &black ) ; + RGBBackColor( &white ) ; + PenMode(transparent); + + for ( int y = 0 ; y < height ; ++y ) + { + for( int x = 0 ; x < width ; ++x ) + { + if ( !mask->PointMasked(x,y) ) + { + RGBColor col ; + + GetCPixel( x + portRect.left , y + portRect.top , &col ) ; + SetCPixel( x + portRect.left , y + portRect.top , &col ) ; + } + else { + // With transparency this sets a blank pixel + SetCPixel( x + portRect.left , y + portRect.top , &trans); + } + } + } + } + else + { + RGBBackColor( &gray ) ; + EraseRect(&portRect); + RGBForeColor( &black ) ; + RGBBackColor( &white ) ; + + CopyBits(GetPortBitMapForCopyBits(GetHBITMAP()), + // src PixMap - we copy image over itself - + GetPortBitMapForCopyBits(GetHBITMAP()), + // dst PixMap - no drawing occurs + &portRect, // srcRect - it will be recorded and compressed - + &portRect, // dstRect - into the picture that is open - + srcCopy,NULL); // copyMode and no clip region + } + ClosePicture(); // We are done recording the picture + UnlockPixels( GetGWorldPixMap( GetHBITMAP() ) ) ; + SetGWorld( origPort , origDev ) ; + + return picture; // return our groovy pict handle +} + void wxBitmap::AddHandler(wxBitmapHandler *handler) { sm_handlers.Append(handler); @@ -493,8 +837,32 @@ wxMask::~wxMask() // Create a mask from a mono bitmap (copies the bitmap). bool wxMask::Create(const wxBitmap& bitmap) { -// TODO - return FALSE; + if ( m_maskBitmap ) + { + wxMacDestroyGWorld( m_maskBitmap ) ; + m_maskBitmap = NULL ; + } + wxCHECK_MSG( bitmap.GetBitmapType() == kMacBitmapTypeGrafWorld, false, + wxT("Cannot create mask from this bitmap type (TODO)")); + // other types would require a temporary bitmap. not yet implemented + + wxCHECK_MSG( bitmap.Ok(), false, wxT("Invalid bitmap")); + + wxCHECK_MSG(bitmap.GetDepth() == 1, false, + wxT("Cannot create mask from colour bitmap")); + + m_maskBitmap = wxMacCreateGWorld(bitmap.GetWidth(), bitmap.GetHeight(), 1); + Rect rect = { 0,0, bitmap.GetHeight(), bitmap.GetWidth() }; + + LockPixels( GetGWorldPixMap(m_maskBitmap) ); + LockPixels( GetGWorldPixMap(bitmap.GetHBITMAP()) ); + CopyBits(GetPortBitMapForCopyBits(bitmap.GetHBITMAP()), + GetPortBitMapForCopyBits(m_maskBitmap), + &rect, &rect, srcCopy, 0); + UnlockPixels( GetGWorldPixMap(m_maskBitmap) ); + UnlockPixels( GetGWorldPixMap(bitmap.GetHBITMAP()) ); + + return FALSE; } // Create a mask from a bitmap and a palette index indicating @@ -502,6 +870,7 @@ bool wxMask::Create(const wxBitmap& bitmap) bool wxMask::Create(const wxBitmap& bitmap, int paletteIndex) { // TODO + wxCHECK_MSG( 0, false, wxT("Not implemented")); return FALSE; } @@ -514,39 +883,35 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour) wxMacDestroyGWorld( m_maskBitmap ) ; m_maskBitmap = NULL ; } - wxASSERT( ((wxBitmapRefData*) bitmap.GetRefData())->m_bitmapType == kMacBitmapTypeGrafWorld ) ; + wxCHECK_MSG( bitmap.GetBitmapType() == kMacBitmapTypeGrafWorld, false, + wxT("Cannot create mask from this bitmap type (TODO)")); // other types would require a temporary bitmap. not yet implemented - if (!bitmap.Ok()) - { - return FALSE; - } + wxCHECK_MSG( bitmap.Ok(), false, wxT("Illigal bitmap")); - m_maskBitmap = wxMacCreateGWorld( bitmap.GetWidth() , bitmap.GetHeight() , 1 ) ; - LockPixels( GetGWorldPixMap( (CGrafPtr) m_maskBitmap ) ) ; - LockPixels( GetGWorldPixMap( (CGrafPtr) ((wxBitmapRefData*) bitmap.GetRefData())->m_hBitmap ) ) ; - RGBColor maskColor = colour.GetPixel() ; + m_maskBitmap = wxMacCreateGWorld( bitmap.GetWidth() , bitmap.GetHeight() , 1 ); + LockPixels( GetGWorldPixMap( m_maskBitmap ) ); + LockPixels( GetGWorldPixMap( bitmap.GetHBITMAP() ) ); + RGBColor maskColor = colour.GetPixel(); // this is not very efficient, but I can't think // of a better way of doing it CGrafPtr origPort ; GDHandle origDevice ; + RGBColor col; + RGBColor colors[2] = { + { 0xFFFF, 0xFFFF, 0xFFFF }, + { 0, 0, 0 }}; GetGWorld( &origPort , &origDevice ) ; for (int w = 0; w < bitmap.GetWidth(); w++) { for (int h = 0; h < bitmap.GetHeight(); h++) { - RGBColor colors[2] = { - { 0xFFFF , 0xFFFF , 0xFFFF } , - { 0, 0 , 0 } - } ; - - SetGWorld( ((wxBitmapRefData*) bitmap.GetRefData())->m_hBitmap , NULL ) ; - RGBColor col ; + SetGWorld( bitmap.GetHBITMAP(), NULL ) ; GetCPixel( w , h , &col ) ; SetGWorld( m_maskBitmap , NULL ) ; - if (col.red == maskColor.red && col.blue == maskColor.blue && col.green == maskColor.green) + if (col.red == maskColor.red && col.green == maskColor.green && col.blue == maskColor.blue) { SetCPixel( w , h , &colors[0] ) ; } @@ -557,12 +922,33 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour) } } UnlockPixels( GetGWorldPixMap( (CGrafPtr) m_maskBitmap ) ) ; - UnlockPixels( GetGWorldPixMap( ((wxBitmapRefData*) bitmap.GetRefData())->m_hBitmap ) ) ; + UnlockPixels( GetGWorldPixMap( bitmap.GetHBITMAP() ) ) ; SetGWorld( origPort , origDevice ) ; return TRUE; } +bool wxMask::PointMasked(int x, int y) +{ + WXHBITMAP origPort; + GDHandle origDevice; + RGBColor color; + bool masked = true; + + GetGWorld( &origPort, &origDevice); + + //Set port to mask and see if it masked (1) or not ( 0 ) + SetGWorld(m_maskBitmap, NULL); + LockPixels(GetGWorldPixMap(m_maskBitmap)); + GetCPixel(x,y, &color); + masked = !(color.red == 0 && color.green == 0 && color.blue == 0); + UnlockPixels(GetGWorldPixMap(m_maskBitmap)); + + SetGWorld( origPort, origDevice); + + return masked; +} + /* * wxBitmapHandler */ diff --git a/src/mac/carbon/aga.cpp b/src/mac/carbon/aga.cpp index 6c24f5ddf8..1f3310aca5 100644 --- a/src/mac/carbon/aga.cpp +++ b/src/mac/carbon/aga.cpp @@ -1,3 +1,4 @@ +#include "wx/dc.h" #include "wx/mac/uma.h" #include "wx/mac/aga.h" diff --git a/src/mac/carbon/app.cpp b/src/mac/carbon/app.cpp index 97c3590a5e..c7c54a882c 100644 --- a/src/mac/carbon/app.cpp +++ b/src/mac/carbon/app.cpp @@ -53,7 +53,7 @@ #if wxUSE_SOCKETS #ifdef __APPLE__ - #include + #include #else #include #include @@ -95,25 +95,25 @@ bool wxApp::s_macSupportPCMenuShortcuts = true ; long wxApp::s_macAboutMenuItemId = wxID_ABOUT ; wxString wxApp::s_macHelpMenuTitleName = "&Help" ; -pascal OSErr AEHandleODoc( const AppleEvent *event , AppleEvent *reply , unsigned long refcon ) +pascal OSErr AEHandleODoc( const AppleEvent *event , AppleEvent *reply , long refcon ) { wxApp* app = (wxApp*) refcon ; return wxTheApp->MacHandleAEODoc( (AppleEvent*) event , reply) ; } -pascal OSErr AEHandleOApp( const AppleEvent *event , AppleEvent *reply , unsigned long refcon ) +pascal OSErr AEHandleOApp( const AppleEvent *event , AppleEvent *reply , long refcon ) { wxApp* app = (wxApp*) refcon ; return wxTheApp->MacHandleAEOApp( (AppleEvent*) event , reply ) ; } -pascal OSErr AEHandlePDoc( const AppleEvent *event , AppleEvent *reply , unsigned long refcon ) +pascal OSErr AEHandlePDoc( const AppleEvent *event , AppleEvent *reply , long refcon ) { wxApp* app = (wxApp*) refcon ; return wxTheApp->MacHandleAEPDoc( (AppleEvent*) event , reply ) ; } -pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , unsigned long refcon ) +pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , long refcon ) { wxApp* app = (wxApp*) refcon ; return wxTheApp->MacHandleAEQuit( (AppleEvent*) event , reply) ; @@ -1469,7 +1469,11 @@ void wxApp::MacHandleOSEvent( EventRecord *ev ) case suspendResumeMessage : { bool isResuming = ev->message & resumeFlag ; +#if !TARGET_CARBON bool convertClipboard = ev->message & convertClipboardFlag ; +#else + bool convertClipboard = false; +#endif bool doesActivate = UMAGetProcessModeDoesActivateOnFGSwitch() ; if ( isResuming ) { diff --git a/src/mac/carbon/bitmap.cpp b/src/mac/carbon/bitmap.cpp index 5c1aec6c5f..5cc2a537fd 100644 --- a/src/mac/carbon/bitmap.cpp +++ b/src/mac/carbon/bitmap.cpp @@ -36,7 +36,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject) #endif #ifdef __UNIX__ - #include + #include #else #include #endif @@ -97,6 +97,97 @@ void wxMacDestroyGWorld( GWorldPtr gw ) DisposeGWorld( gw ) ; } +PicHandle wxMacCreatePict(GWorldPtr wp, GWorldPtr mask) +{ + CGrafPtr origPort ; + GDHandle origDev ; + + PicHandle pict; // this is the Picture we give back + + RGBColor gray = { 0xCCCC ,0xCCCC , 0xCCCC } ; + RGBColor white = { 0xffff ,0xffff , 0xffff } ; + RGBColor black = { 0x0000 ,0x0000 , 0x0000 } ; + + unsigned char *maskimage = NULL ; + Rect portRect ; + GetPortBounds( wp , &portRect ) ; + int width = portRect.right - portRect.left ; + int height = portRect.bottom - portRect.top ; + + LockPixels( GetGWorldPixMap( wp ) ) ; + GetGWorld( &origPort , &origDev ) ; + + if ( mask ) + { + maskimage = (unsigned char*) malloc( width * height ) ; + SetGWorld( mask , NULL ) ; + LockPixels( GetGWorldPixMap( mask ) ) ; + for ( int y = 0 ; y < height ; y++ ) + { + for( int x = 0 ; x < width ; x++ ) + { + RGBColor col ; + + GetCPixel( x + portRect.left , y + portRect.top , &col ) ; + maskimage[y*width + x] = ( col.red == 0 ) ; // for monochrome masks + } + } + UnlockPixels( GetGWorldPixMap( mask ) ) ; + } + + SetGWorld( wp , NULL ) ; + + pict = OpenPicture(&portRect); // open a picture, this disables drawing + if(!pict) + return NULL; + + if ( maskimage ) + { + RGBForeColor( &black ) ; + RGBBackColor( &white ) ; + PenMode(transparent); + + for ( int y = 0 ; y < height ; ++y ) + { + for( int x = 0 ; x < width ; ++x ) + { + if ( maskimage[y*width + x] ) + { + RGBColor col ; + + GetCPixel( x + portRect.left , y + portRect.top , &col ) ; + SetCPixel( x + portRect.left , y + portRect.top , &col ) ; + } + else { + // With transparency set this sets a blank pixel not a white one + SetCPixel( x + portRect.left , y + portRect.top , &white); + } + } + } + free( maskimage ) ; + maskimage = NULL ; + } + else + { + RGBBackColor( &gray ) ; + EraseRect(&portRect); + RGBForeColor( &black ) ; + RGBBackColor( &white ) ; + + CopyBits(GetPortBitMapForCopyBits(wp), /* src PixMap - we copy image over + * itself - */ + GetPortBitMapForCopyBits(wp), // dst PixMap - no drawing occurs + &portRect, // srcRect - it will be recorded and compressed - + &portRect, // dstRect - into the picture that is open - + srcCopy,NULL); // copyMode and no clip region + } + ClosePicture(); // We are done recording the picture + UnlockPixels( GetGWorldPixMap( wp ) ) ; + SetGWorld( origPort , origDev ) ; + + return pict; // return our groovy pict handle +} + wxBitmapRefData::wxBitmapRefData() { m_ok = FALSE; @@ -180,8 +271,18 @@ wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits GetGWorld( &origPort , &origDevice ) ; SetGWorld( M_BITMAPDATA->m_hBitmap , NULL ) ; - LockPixels( GetGWorldPixMap( (CGrafPtr) M_BITMAPDATA->m_hBitmap ) ) ; - + LockPixels( GetGWorldPixMap( M_BITMAPDATA->m_hBitmap ) ) ; + +#ifdef __UNIX__ + // bits is a word aligned array?? Don't think so + // bits is a char array on MAC OS X however using the benefit of the + // doubt I replaced references to 16 with sizeof(unsigned char)*8 + unsigned char* linestart = (unsigned char*) bits ; + int linesize = ( the_width / (sizeof(unsigned char) * 8)) ; + if ( the_width % (sizeof(unsigned char) * 8) ) { + linesize += sizeof(unsigned char); + } +#else // bits is a word aligned array unsigned char* linestart = (unsigned char*) bits ; @@ -190,6 +291,7 @@ wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits { linesize += 2 ; } +#endif RGBColor colors[2] = { { 0xFFFF , 0xFFFF , 0xFFFF } , @@ -214,7 +316,7 @@ wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits } } - UnlockPixels( GetGWorldPixMap( (CGrafPtr) M_BITMAPDATA->m_hBitmap ) ) ; + UnlockPixels( GetGWorldPixMap( M_BITMAPDATA->m_hBitmap ) ) ; SetGWorld( origPort , origDevice ) ; } @@ -261,6 +363,95 @@ wxBitmap::wxBitmap(char **data) (void) Create((void *)data, wxBITMAP_TYPE_XPM_DATA, 0, 0, 0); } +wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const +{ + wxCHECK_MSG( Ok() && + (rect.x >= 0) && (rect.y >= 0) && + (rect.x+rect.width <= GetWidth()) && + (rect.y+rect.height <= GetHeight()), + wxNullBitmap, wxT("invalid bitmap or bitmap region") ); + + + wxBitmap ret( rect.width, rect.height, GetDepth() ); + wxASSERT_MSG( ret.Ok(), wxT("GetSubBitmap error") ); + + WXHBITMAP origPort; + GDHandle origDevice; + + GetGWorld( &origPort, &origDevice ); + + // Update the subbitmaps reference data + wxBitmapRefData *ref = (wxBitmapRefData *)ret.GetRefData(); + + ref->m_numColors = M_BITMAPDATA->m_numColors; + ref->m_bitmapPalette = M_BITMAPDATA->m_bitmapPalette; + ref->m_bitmapType = M_BITMAPDATA->m_bitmapType; + + // Copy sub region of this bitmap + if(M_BITMAPDATA->m_bitmapType == kMacBitmapTypePict) + { + printf("GetSubBitmap: Copy a region of a Pict structure - TODO\n"); + } + else if(M_BITMAPDATA->m_bitmapType == kMacBitmapTypeGrafWorld) + { + // Copy mask + if(GetMask()) + { + WXHBITMAP submask, mask; + RGBColor color; + + mask = GetMask()->GetMaskBitmap(); + submask = wxMacCreateGWorld(rect.width, rect.height, 1); + LockPixels(GetGWorldPixMap(mask)); + LockPixels(GetGWorldPixMap(submask)); + + for(int yy = 0; yy < rect.height; yy++) + { + for(int xx = 0; xx < rect.width; xx++) + { + SetGWorld(mask, NULL); + GetCPixel(rect.x + xx, rect.y + yy, &color); + SetGWorld(submask, NULL); + SetCPixel(xx,yy, &color); + } + } + UnlockPixels(GetGWorldPixMap(mask)); + UnlockPixels(GetGWorldPixMap(submask)); + ref->m_bitmapMask = new wxMask; + ref->m_bitmapMask->SetMaskBitmap(submask); + } + + // Copy bitmap + if(GetHBITMAP()) + { + WXHBITMAP subbitmap, bitmap; + RGBColor color; + + bitmap = GetHBITMAP(); + subbitmap = wxMacCreateGWorld(rect.width, rect.height, GetDepth()); + LockPixels(GetGWorldPixMap(bitmap)); + LockPixels(GetGWorldPixMap(subbitmap)); + + for(int yy = 0; yy < rect.height; yy++) + { + for(int xx = 0; xx < rect.width; xx++) + { + SetGWorld(bitmap, NULL); + GetCPixel(rect.x + xx, rect.y + yy, &color); + SetGWorld(subbitmap, NULL); + SetCPixel(xx, yy, &color); + } + } + UnlockPixels(GetGWorldPixMap(bitmap)); + UnlockPixels(GetGWorldPixMap(subbitmap)); + ret.SetHBITMAP(subbitmap); + } + } + SetGWorld( origPort, origDevice ); + + return ret; +} + bool wxBitmap::Create(int w, int h, int d) { UnRef(); @@ -277,6 +468,13 @@ bool wxBitmap::Create(int w, int h, int d) return M_BITMAPDATA->m_ok; } +int wxBitmap::GetBitmapType() const +{ + wxCHECK_MSG( Ok(), kMacBitmapTypeUnknownType, wxT("invalid bitmap") ); + + return M_BITMAPDATA->m_bitmapType; +} + void wxBitmap::SetHBITMAP(WXHBITMAP bmp) { M_BITMAPDATA->m_bitmapType = kMacBitmapTypeGrafWorld ; @@ -331,6 +529,46 @@ bool wxBitmap::SaveFile(const wxString& filename, int type, const wxPalette *pal return handler->SaveFile(this, filename, type, palette); } +bool wxBitmap::Ok() const +{ + return (M_BITMAPDATA && M_BITMAPDATA->m_ok); +} + +int wxBitmap::GetHeight() const +{ + wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") ); + + return M_BITMAPDATA->m_height; +} + +int wxBitmap::GetWidth() const +{ + wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") ); + + return M_BITMAPDATA->m_width; +} + +int wxBitmap::GetDepth() const +{ + wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") ); + + return M_BITMAPDATA->m_depth; +} + +int wxBitmap::GetQuality() const +{ + wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") ); + + return M_BITMAPDATA->m_quality; +} + +wxMask *wxBitmap::GetMask() const +{ + wxCHECK_MSG( Ok(), (wxMask *) NULL, wxT("invalid bitmap") ); + + return M_BITMAPDATA->m_bitmapMask; +} + void wxBitmap::SetWidth(int w) { if (!M_BITMAPDATA) @@ -371,6 +609,13 @@ void wxBitmap::SetOk(bool isOk) M_BITMAPDATA->m_ok = isOk; } +wxPalette *wxBitmap::GetPalette() const +{ + wxCHECK_MSG( Ok(), NULL, wxT("Invalid bitmap GetPalette()") ); + + return &M_BITMAPDATA->m_bitmapPalette; +} + void wxBitmap::SetPalette(const wxPalette& palette) { if (!M_BITMAPDATA) @@ -387,6 +632,105 @@ void wxBitmap::SetMask(wxMask *mask) M_BITMAPDATA->m_bitmapMask = mask ; } +WXHBITMAP wxBitmap::GetHBITMAP() const +{ + wxCHECK_MSG( Ok(), NULL, wxT("invalid bitmap") ); + + return M_BITMAPDATA->m_hBitmap; +} + +PicHandle wxBitmap::GetPict() const +{ + wxCHECK_MSG( Ok(), NULL, wxT("invalid bitmap") ); + + PicHandle picture; // This is the returned picture + + // If bitmap already in Pict format return pointer + if(M_BITMAPDATA->m_bitmapType == kMacBitmapTypePict) { + return M_BITMAPDATA->m_hPict; + } + else if(M_BITMAPDATA->m_bitmapType != kMacBitmapTypeGrafWorld) { + // Invalid bitmap + return NULL; + } + + RGBColor gray = { 0xCCCC ,0xCCCC , 0xCCCC } ; + RGBColor white = { 0xffff ,0xffff , 0xffff } ; + RGBColor black = { 0x0000 ,0x0000 , 0x0000 } ; + CGrafPtr origPort; + GDHandle origDev ; + wxMask *mask; + Rect portRect ; + + GetPortBounds( GetHBITMAP() , &portRect ) ; + int width = portRect.right - portRect.left ; + int height = portRect.bottom - portRect.top ; + + LockPixels( GetGWorldPixMap( GetHBITMAP() ) ) ; + GetGWorld( &origPort , &origDev ) ; + + mask = GetMask(); + + SetGWorld( GetHBITMAP() , NULL ) ; + + picture = OpenPicture(&portRect); // open a picture, this disables drawing + if(!picture) { + return NULL; + } + + if( mask ) + { +#ifdef __UNIX__ + RGBColor trans = white; +#else + RGBBackColor( &gray ); + EraseRect( &portRect ); + RGBColor trans = gray; +#endif + RGBForeColor( &black ) ; + RGBBackColor( &white ) ; + PenMode(transparent); + + for ( int y = 0 ; y < height ; ++y ) + { + for( int x = 0 ; x < width ; ++x ) + { + if ( !mask->PointMasked(x,y) ) + { + RGBColor col ; + + GetCPixel( x + portRect.left , y + portRect.top , &col ) ; + SetCPixel( x + portRect.left , y + portRect.top , &col ) ; + } + else { + // With transparency this sets a blank pixel + SetCPixel( x + portRect.left , y + portRect.top , &trans); + } + } + } + } + else + { + RGBBackColor( &gray ) ; + EraseRect(&portRect); + RGBForeColor( &black ) ; + RGBBackColor( &white ) ; + + CopyBits(GetPortBitMapForCopyBits(GetHBITMAP()), + // src PixMap - we copy image over itself - + GetPortBitMapForCopyBits(GetHBITMAP()), + // dst PixMap - no drawing occurs + &portRect, // srcRect - it will be recorded and compressed - + &portRect, // dstRect - into the picture that is open - + srcCopy,NULL); // copyMode and no clip region + } + ClosePicture(); // We are done recording the picture + UnlockPixels( GetGWorldPixMap( GetHBITMAP() ) ) ; + SetGWorld( origPort , origDev ) ; + + return picture; // return our groovy pict handle +} + void wxBitmap::AddHandler(wxBitmapHandler *handler) { sm_handlers.Append(handler); @@ -493,8 +837,32 @@ wxMask::~wxMask() // Create a mask from a mono bitmap (copies the bitmap). bool wxMask::Create(const wxBitmap& bitmap) { -// TODO - return FALSE; + if ( m_maskBitmap ) + { + wxMacDestroyGWorld( m_maskBitmap ) ; + m_maskBitmap = NULL ; + } + wxCHECK_MSG( bitmap.GetBitmapType() == kMacBitmapTypeGrafWorld, false, + wxT("Cannot create mask from this bitmap type (TODO)")); + // other types would require a temporary bitmap. not yet implemented + + wxCHECK_MSG( bitmap.Ok(), false, wxT("Invalid bitmap")); + + wxCHECK_MSG(bitmap.GetDepth() == 1, false, + wxT("Cannot create mask from colour bitmap")); + + m_maskBitmap = wxMacCreateGWorld(bitmap.GetWidth(), bitmap.GetHeight(), 1); + Rect rect = { 0,0, bitmap.GetHeight(), bitmap.GetWidth() }; + + LockPixels( GetGWorldPixMap(m_maskBitmap) ); + LockPixels( GetGWorldPixMap(bitmap.GetHBITMAP()) ); + CopyBits(GetPortBitMapForCopyBits(bitmap.GetHBITMAP()), + GetPortBitMapForCopyBits(m_maskBitmap), + &rect, &rect, srcCopy, 0); + UnlockPixels( GetGWorldPixMap(m_maskBitmap) ); + UnlockPixels( GetGWorldPixMap(bitmap.GetHBITMAP()) ); + + return FALSE; } // Create a mask from a bitmap and a palette index indicating @@ -502,6 +870,7 @@ bool wxMask::Create(const wxBitmap& bitmap) bool wxMask::Create(const wxBitmap& bitmap, int paletteIndex) { // TODO + wxCHECK_MSG( 0, false, wxT("Not implemented")); return FALSE; } @@ -514,39 +883,35 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour) wxMacDestroyGWorld( m_maskBitmap ) ; m_maskBitmap = NULL ; } - wxASSERT( ((wxBitmapRefData*) bitmap.GetRefData())->m_bitmapType == kMacBitmapTypeGrafWorld ) ; + wxCHECK_MSG( bitmap.GetBitmapType() == kMacBitmapTypeGrafWorld, false, + wxT("Cannot create mask from this bitmap type (TODO)")); // other types would require a temporary bitmap. not yet implemented - if (!bitmap.Ok()) - { - return FALSE; - } + wxCHECK_MSG( bitmap.Ok(), false, wxT("Illigal bitmap")); - m_maskBitmap = wxMacCreateGWorld( bitmap.GetWidth() , bitmap.GetHeight() , 1 ) ; - LockPixels( GetGWorldPixMap( (CGrafPtr) m_maskBitmap ) ) ; - LockPixels( GetGWorldPixMap( (CGrafPtr) ((wxBitmapRefData*) bitmap.GetRefData())->m_hBitmap ) ) ; - RGBColor maskColor = colour.GetPixel() ; + m_maskBitmap = wxMacCreateGWorld( bitmap.GetWidth() , bitmap.GetHeight() , 1 ); + LockPixels( GetGWorldPixMap( m_maskBitmap ) ); + LockPixels( GetGWorldPixMap( bitmap.GetHBITMAP() ) ); + RGBColor maskColor = colour.GetPixel(); // this is not very efficient, but I can't think // of a better way of doing it CGrafPtr origPort ; GDHandle origDevice ; + RGBColor col; + RGBColor colors[2] = { + { 0xFFFF, 0xFFFF, 0xFFFF }, + { 0, 0, 0 }}; GetGWorld( &origPort , &origDevice ) ; for (int w = 0; w < bitmap.GetWidth(); w++) { for (int h = 0; h < bitmap.GetHeight(); h++) { - RGBColor colors[2] = { - { 0xFFFF , 0xFFFF , 0xFFFF } , - { 0, 0 , 0 } - } ; - - SetGWorld( ((wxBitmapRefData*) bitmap.GetRefData())->m_hBitmap , NULL ) ; - RGBColor col ; + SetGWorld( bitmap.GetHBITMAP(), NULL ) ; GetCPixel( w , h , &col ) ; SetGWorld( m_maskBitmap , NULL ) ; - if (col.red == maskColor.red && col.blue == maskColor.blue && col.green == maskColor.green) + if (col.red == maskColor.red && col.green == maskColor.green && col.blue == maskColor.blue) { SetCPixel( w , h , &colors[0] ) ; } @@ -557,12 +922,33 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour) } } UnlockPixels( GetGWorldPixMap( (CGrafPtr) m_maskBitmap ) ) ; - UnlockPixels( GetGWorldPixMap( ((wxBitmapRefData*) bitmap.GetRefData())->m_hBitmap ) ) ; + UnlockPixels( GetGWorldPixMap( bitmap.GetHBITMAP() ) ) ; SetGWorld( origPort , origDevice ) ; return TRUE; } +bool wxMask::PointMasked(int x, int y) +{ + WXHBITMAP origPort; + GDHandle origDevice; + RGBColor color; + bool masked = true; + + GetGWorld( &origPort, &origDevice); + + //Set port to mask and see if it masked (1) or not ( 0 ) + SetGWorld(m_maskBitmap, NULL); + LockPixels(GetGWorldPixMap(m_maskBitmap)); + GetCPixel(x,y, &color); + masked = !(color.red == 0 && color.green == 0 && color.blue == 0); + UnlockPixels(GetGWorldPixMap(m_maskBitmap)); + + SetGWorld( origPort, origDevice); + + return masked; +} + /* * wxBitmapHandler */ diff --git a/src/mac/carbon/clipbrd.cpp b/src/mac/carbon/clipbrd.cpp index ca5b793396..1e99ca3ce7 100644 --- a/src/mac/carbon/clipbrd.cpp +++ b/src/mac/carbon/clipbrd.cpp @@ -20,6 +20,7 @@ #include "wx/utils.h" #include "wx/metafile.h" #include "wx/clipbrd.h" +#include "wx/intl.h" #define wxUSE_DATAOBJ 1 diff --git a/src/mac/carbon/control.cpp b/src/mac/carbon/control.cpp index cbbd8e3429..63610676a0 100644 --- a/src/mac/carbon/control.cpp +++ b/src/mac/carbon/control.cpp @@ -16,6 +16,7 @@ #include "wx/control.h" #include "wx/panel.h" #include "wx/app.h" +#include "wx/dc.h" #include "wx/notebook.h" #include "wx/tabctrl.h" #include "wx/radiobox.h" diff --git a/src/mac/carbon/dir.cpp b/src/mac/carbon/dir.cpp deleted file mode 100644 index e37f079382..0000000000 --- a/src/mac/carbon/dir.cpp +++ /dev/null @@ -1,272 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: msw/dir.cpp -// Purpose: wxDir implementation for Mac -// Author: Stefan Csomor -// Modified by: -// Created: 08.12.99 -// RCS-ID: $Id$ -// Copyright: (c) 1999 Stefan Csomor -// Licence: wxWindows license -///////////////////////////////////////////////////////////////////////////// - -// ============================================================================ -// declarations -// ============================================================================ - -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - -#ifdef __GNUG__ - #pragma implementation "dir.h" -#endif - -// For compilers that support precompilation, includes "wx.h". -#include "wx/wxprec.h" - -#ifdef __BORLANDC__ - #pragma hdrstop -#endif - -#ifndef WX_PRECOMP - #include "wx/intl.h" - #include "wx/log.h" -#endif // PCH - -#include "wx/dir.h" -#include "wx/filefn.h" // for wxPathExists() - -#ifndef __WXMAC_X__ - #include -#endif - -#if defined(__WXMAC__) && !defined(__UNIX__) - #include "morefile.h" - #include "moreextr.h" - #include "fullpath.h" - #include "fspcompa.h" -#endif - -// ---------------------------------------------------------------------------- -// constants -// ---------------------------------------------------------------------------- - -#ifndef MAX_PATH - #define MAX_PATH 260 // from VC++ headers -#endif - -// ---------------------------------------------------------------------------- -// macros -// ---------------------------------------------------------------------------- - -#define M_DIR ((wxDirData *)m_data) - -// ---------------------------------------------------------------------------- -// private classes -// ---------------------------------------------------------------------------- - -// this class stores everything we need to enumerate the files -class wxDirData -{ -public: - wxDirData(const wxString& dirname); - ~wxDirData(); - - void SetFileSpec(const wxString& filespec) { m_filespec = filespec; } - void SetFlags(int flags) { m_flags = flags; } - - bool Read(wxString *filename); // reads the next - void Rewind() ; - -private: - CInfoPBRec m_CPB ; - wxInt16 m_index ; - long m_dirId ; - Str255 m_name ; - Boolean m_isDir ; - - wxString m_dirname; - wxString m_filespec; - - int m_flags; -}; - -// ============================================================================ -// implementation -// ============================================================================ - -// ---------------------------------------------------------------------------- -// wxDirData -// ---------------------------------------------------------------------------- - -wxDirData::wxDirData(const wxString& dirname) - : m_dirname(dirname) -{ - // throw away the trailing slashes - size_t n = m_dirname.length(); - wxCHECK_RET( n, _T("empty dir name in wxDir") ); - - while ( n > 0 && wxIsPathSeparator(m_dirname[--n]) ) - ; - - m_dirname.Truncate(n + 1); - - FSSpec fsspec ; - - wxUnixFilename2FSSpec( m_dirname , &fsspec ) ; - m_CPB.hFileInfo.ioVRefNum = fsspec.vRefNum ; - m_CPB.hFileInfo.ioNamePtr = m_name ; - m_index = 0 ; - -#ifdef __WXMAC_X__ - // TODO: what are we supposed to do for Mac OS X -#else - FSpGetDirectoryID( &fsspec , &m_dirId , &m_isDir ) ; -#endif -} - -wxDirData::~wxDirData() -{ -} - -void wxDirData::Rewind() -{ - m_index = 0 ; -} - -bool wxDirData::Read(wxString *filename) -{ - if ( !m_isDir ) - return FALSE ; - -#if TARGET_CARBON - char c_name[256] ; -#endif - wxString result; - - short err = noErr ; - - while ( err == noErr ) - { - m_index++ ; - m_CPB.dirInfo.ioFDirIndex = m_index; - m_CPB.dirInfo.ioDrDirID = m_dirId; /* we need to do this every time */ - err = PBGetCatInfoSync((CInfoPBPtr)&m_CPB); - if ( err != noErr ) - break ; - -#if TARGET_CARBON - p2cstrcpy( c_name, m_name ) ; - strcpy( (char *)m_name, c_name); -#else - p2cstr( m_name ) ; -#endif - if ( ( m_CPB.dirInfo.ioFlAttrib & ioDirMask) != 0 && (m_flags & wxDIR_DIRS) ) // we have a directory - break ; - - if ( ( m_CPB.dirInfo.ioFlAttrib & ioDirMask) == 0 && !(m_flags & wxDIR_FILES ) ) // its a file but we don't want it - continue ; - - if ( ( m_CPB.hFileInfo.ioFlFndrInfo.fdFlags & kIsInvisible ) && !(m_flags & wxDIR_HIDDEN) ) // its hidden but we don't want it - continue ; - - wxString file( m_name ) ; - if ( m_filespec.IsEmpty() || m_filespec == "*.*" ) - { - } - else if ( m_filespec.Length() > 1 && m_filespec.Left(1) =="*" ) - { - if ( file.Right( m_filespec.Length() - 1 ).Upper() != m_filespec.Mid(1).Upper() ) - { - continue ; - } - } - else if ( m_filespec.Length() > 1 && m_filespec.Right(1) == "*" ) - { - if ( file.Left( m_filespec.Length() - 1 ).Upper() != m_filespec.Left( m_filespec.Length() - 1 ).Upper() ) - { - continue ; - } - } - else if ( file.Upper() != m_filespec.Upper() ) - { - continue ; - } - - break ; - } - if ( err != noErr ) - { - return FALSE ; - } - - *filename = (char*) m_name ; - - return TRUE; -} - -// ---------------------------------------------------------------------------- -// wxDir helpers -// ---------------------------------------------------------------------------- - -/* static */ -bool wxDir::Exists(const wxString& dir) -{ - return wxPathExists(dir); -} - -// ---------------------------------------------------------------------------- -// wxDir construction/destruction -// ---------------------------------------------------------------------------- - -wxDir::wxDir(const wxString& dirname) -{ - m_data = NULL; - - (void)Open(dirname); -} - -bool wxDir::Open(const wxString& dirname) -{ - delete M_DIR; - m_data = new wxDirData(dirname); - - return TRUE; -} - -bool wxDir::IsOpened() const -{ - return m_data != NULL; -} - -wxDir::~wxDir() -{ - delete M_DIR; -} - -// ---------------------------------------------------------------------------- -// wxDir enumerating -// ---------------------------------------------------------------------------- - -bool wxDir::GetFirst(wxString *filename, - const wxString& filespec, - int flags) const -{ - wxCHECK_MSG( IsOpened(), FALSE, _T("must wxDir::Open() first") ); - - M_DIR->Rewind(); - - M_DIR->SetFileSpec(filespec); - M_DIR->SetFlags(flags); - - return GetNext(filename); -} - -bool wxDir::GetNext(wxString *filename) const -{ - wxCHECK_MSG( IsOpened(), FALSE, _T("must wxDir::Open() first") ); - - wxCHECK_MSG( filename, FALSE, _T("bad pointer in wxDir::GetNext()") ); - - return M_DIR->Read(filename); -} diff --git a/src/mac/carbon/dirdlg.cpp b/src/mac/carbon/dirdlg.cpp index e1255db7e1..89b3892451 100644 --- a/src/mac/carbon/dirdlg.cpp +++ b/src/mac/carbon/dirdlg.cpp @@ -21,7 +21,7 @@ #include "wx/cmndata.h" #if defined(__UNIX__) - #include + #include #else #include #endif @@ -182,7 +182,7 @@ static Boolean SameFSSpec(FSSpecPtr spec1, FSSpecPtr spec2) // flashing of the button when the key is hit static pascal Boolean SFGetFolderModalDialogFilter(DialogPtr theDlgPtr, EventRecord *eventRec, - short *item, Ptr dataPtr) + short *item, void *dataPtr) { #pragma unused (dataPtr) @@ -210,7 +210,7 @@ static pascal Boolean SFGetFolderModalDialogFilter(DialogPtr theDlgPtr, EventRec // MyDlgHook is a hook routine that maps the select button to Open // and sets the Select button name -static pascal short SFGetFolderDialogHook(short item, DialogPtr theDlgPtr, Ptr dataPtr) +static pascal short SFGetFolderDialogHook(short item, DialogPtr theDlgPtr, void *dataPtr) { UserDataRecPtr theUserDataRecPtr; long desktopDirID; @@ -422,7 +422,7 @@ void StandardGetFolder( ConstStr255Param message , ConstStr255Param path , FileF } } -static pascal Boolean OnlyVisibleFoldersCustomFileFilter(CInfoPBPtr myCInfoPBPtr, Ptr dataPtr) +static pascal Boolean OnlyVisibleFoldersCustomFileFilter(CInfoPBPtr myCInfoPBPtr, void *dataPtr) { #pragma unused (dataPtr) diff --git a/src/mac/carbon/dirmac.cpp b/src/mac/carbon/dirmac.cpp new file mode 100644 index 0000000000..e37f079382 --- /dev/null +++ b/src/mac/carbon/dirmac.cpp @@ -0,0 +1,272 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: msw/dir.cpp +// Purpose: wxDir implementation for Mac +// Author: Stefan Csomor +// Modified by: +// Created: 08.12.99 +// RCS-ID: $Id$ +// Copyright: (c) 1999 Stefan Csomor +// Licence: wxWindows license +///////////////////////////////////////////////////////////////////////////// + +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#ifdef __GNUG__ + #pragma implementation "dir.h" +#endif + +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#ifndef WX_PRECOMP + #include "wx/intl.h" + #include "wx/log.h" +#endif // PCH + +#include "wx/dir.h" +#include "wx/filefn.h" // for wxPathExists() + +#ifndef __WXMAC_X__ + #include +#endif + +#if defined(__WXMAC__) && !defined(__UNIX__) + #include "morefile.h" + #include "moreextr.h" + #include "fullpath.h" + #include "fspcompa.h" +#endif + +// ---------------------------------------------------------------------------- +// constants +// ---------------------------------------------------------------------------- + +#ifndef MAX_PATH + #define MAX_PATH 260 // from VC++ headers +#endif + +// ---------------------------------------------------------------------------- +// macros +// ---------------------------------------------------------------------------- + +#define M_DIR ((wxDirData *)m_data) + +// ---------------------------------------------------------------------------- +// private classes +// ---------------------------------------------------------------------------- + +// this class stores everything we need to enumerate the files +class wxDirData +{ +public: + wxDirData(const wxString& dirname); + ~wxDirData(); + + void SetFileSpec(const wxString& filespec) { m_filespec = filespec; } + void SetFlags(int flags) { m_flags = flags; } + + bool Read(wxString *filename); // reads the next + void Rewind() ; + +private: + CInfoPBRec m_CPB ; + wxInt16 m_index ; + long m_dirId ; + Str255 m_name ; + Boolean m_isDir ; + + wxString m_dirname; + wxString m_filespec; + + int m_flags; +}; + +// ============================================================================ +// implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// wxDirData +// ---------------------------------------------------------------------------- + +wxDirData::wxDirData(const wxString& dirname) + : m_dirname(dirname) +{ + // throw away the trailing slashes + size_t n = m_dirname.length(); + wxCHECK_RET( n, _T("empty dir name in wxDir") ); + + while ( n > 0 && wxIsPathSeparator(m_dirname[--n]) ) + ; + + m_dirname.Truncate(n + 1); + + FSSpec fsspec ; + + wxUnixFilename2FSSpec( m_dirname , &fsspec ) ; + m_CPB.hFileInfo.ioVRefNum = fsspec.vRefNum ; + m_CPB.hFileInfo.ioNamePtr = m_name ; + m_index = 0 ; + +#ifdef __WXMAC_X__ + // TODO: what are we supposed to do for Mac OS X +#else + FSpGetDirectoryID( &fsspec , &m_dirId , &m_isDir ) ; +#endif +} + +wxDirData::~wxDirData() +{ +} + +void wxDirData::Rewind() +{ + m_index = 0 ; +} + +bool wxDirData::Read(wxString *filename) +{ + if ( !m_isDir ) + return FALSE ; + +#if TARGET_CARBON + char c_name[256] ; +#endif + wxString result; + + short err = noErr ; + + while ( err == noErr ) + { + m_index++ ; + m_CPB.dirInfo.ioFDirIndex = m_index; + m_CPB.dirInfo.ioDrDirID = m_dirId; /* we need to do this every time */ + err = PBGetCatInfoSync((CInfoPBPtr)&m_CPB); + if ( err != noErr ) + break ; + +#if TARGET_CARBON + p2cstrcpy( c_name, m_name ) ; + strcpy( (char *)m_name, c_name); +#else + p2cstr( m_name ) ; +#endif + if ( ( m_CPB.dirInfo.ioFlAttrib & ioDirMask) != 0 && (m_flags & wxDIR_DIRS) ) // we have a directory + break ; + + if ( ( m_CPB.dirInfo.ioFlAttrib & ioDirMask) == 0 && !(m_flags & wxDIR_FILES ) ) // its a file but we don't want it + continue ; + + if ( ( m_CPB.hFileInfo.ioFlFndrInfo.fdFlags & kIsInvisible ) && !(m_flags & wxDIR_HIDDEN) ) // its hidden but we don't want it + continue ; + + wxString file( m_name ) ; + if ( m_filespec.IsEmpty() || m_filespec == "*.*" ) + { + } + else if ( m_filespec.Length() > 1 && m_filespec.Left(1) =="*" ) + { + if ( file.Right( m_filespec.Length() - 1 ).Upper() != m_filespec.Mid(1).Upper() ) + { + continue ; + } + } + else if ( m_filespec.Length() > 1 && m_filespec.Right(1) == "*" ) + { + if ( file.Left( m_filespec.Length() - 1 ).Upper() != m_filespec.Left( m_filespec.Length() - 1 ).Upper() ) + { + continue ; + } + } + else if ( file.Upper() != m_filespec.Upper() ) + { + continue ; + } + + break ; + } + if ( err != noErr ) + { + return FALSE ; + } + + *filename = (char*) m_name ; + + return TRUE; +} + +// ---------------------------------------------------------------------------- +// wxDir helpers +// ---------------------------------------------------------------------------- + +/* static */ +bool wxDir::Exists(const wxString& dir) +{ + return wxPathExists(dir); +} + +// ---------------------------------------------------------------------------- +// wxDir construction/destruction +// ---------------------------------------------------------------------------- + +wxDir::wxDir(const wxString& dirname) +{ + m_data = NULL; + + (void)Open(dirname); +} + +bool wxDir::Open(const wxString& dirname) +{ + delete M_DIR; + m_data = new wxDirData(dirname); + + return TRUE; +} + +bool wxDir::IsOpened() const +{ + return m_data != NULL; +} + +wxDir::~wxDir() +{ + delete M_DIR; +} + +// ---------------------------------------------------------------------------- +// wxDir enumerating +// ---------------------------------------------------------------------------- + +bool wxDir::GetFirst(wxString *filename, + const wxString& filespec, + int flags) const +{ + wxCHECK_MSG( IsOpened(), FALSE, _T("must wxDir::Open() first") ); + + M_DIR->Rewind(); + + M_DIR->SetFileSpec(filespec); + M_DIR->SetFlags(flags); + + return GetNext(filename); +} + +bool wxDir::GetNext(wxString *filename) const +{ + wxCHECK_MSG( IsOpened(), FALSE, _T("must wxDir::Open() first") ); + + wxCHECK_MSG( filename, FALSE, _T("bad pointer in wxDir::GetNext()") ); + + return M_DIR->Read(filename); +} diff --git a/src/mac/carbon/dnd.cpp b/src/mac/carbon/dnd.cpp index aa19db3d01..ece56ce7d3 100644 --- a/src/mac/carbon/dnd.cpp +++ b/src/mac/carbon/dnd.cpp @@ -39,20 +39,22 @@ wxDropTarget::~wxDropTarget() // ---------------------------------------------------------------------------- // wxTextDropTarget // ---------------------------------------------------------------------------- - -bool wxTextDropTarget::OnDrop( long x, long y, const void *pData ) +#ifndef __WXMAC_X__ +bool wxTextDropTarget::OnDrop( wxCoord x, wxCoord y, const void *pData ) { OnDropText( x, y, (const char*)pData ); return TRUE; }; +#endif -bool wxTextDropTarget::OnDropText( long x, long y, const char *psz ) +bool wxTextDropTarget::OnDropText( wxCoord x, wxCoord y, const wxString &psz ) { - printf( "Got dropped text: %s.\n", psz ); + printf( "Got dropped text: %s.\n", (char *)psz ); printf( "At x: %d, y: %d.\n", (int)x, (int)y ); return TRUE; }; +#ifndef __WXMAC_X__ size_t wxTextDropTarget::GetFormatCount() const { return 1; @@ -62,25 +64,27 @@ wxDataFormat wxTextDropTarget::GetFormat(size_t WXUNUSED(n)) const { return wxDF_TEXT; } +#endif // ---------------------------------------------------------------------------- // wxFileDropTarget // ---------------------------------------------------------------------------- -bool wxFileDropTarget::OnDropFiles( long x, long y, size_t nFiles, const char * const WXUNUSED(aszFiles)[] ) +#ifndef __WXMAC_X__ +bool wxFileDropTarget::OnDropFiles( wxCoord x, wxCoord y, size_t nFiles, const char * const WXUNUSED(aszFiles)[] ) { printf( "Got %d dropped files.\n", (int)nFiles ); printf( "At x: %d, y: %d.\n", (int)x, (int)y ); return TRUE; } +#endif -bool wxFileDropTarget::OnDrop(long x, long y, const void *WXUNUSED(pData) ) +bool wxFileDropTarget::OnDrop(wxCoord x, wxCoord y, const wxArrayString& filenames) { - char *str = "/this/is/a/path.txt"; - - return OnDropFiles(x, y, 1, &str ); + return OnDropFiles(x, y, 1, &filenames); } +#ifndef __WXMAC_X__ size_t wxFileDropTarget::GetFormatCount() const { return 1; @@ -90,6 +94,7 @@ wxDataFormat wxFileDropTarget::GetFormat(size_t WXUNUSED(n)) const { return wxDF_FILENAME; } +#endif //------------------------------------------------------------------------- // wxDropSource diff --git a/src/mac/carbon/filedlg.cpp b/src/mac/carbon/filedlg.cpp index 118ec1a6a8..406ce43b19 100644 --- a/src/mac/carbon/filedlg.cpp +++ b/src/mac/carbon/filedlg.cpp @@ -14,6 +14,7 @@ #endif #include "wx/defs.h" +#include "wx/app.h" #include "wx/utils.h" #include "wx/dialog.h" #include "wx/filedlg.h" @@ -30,7 +31,7 @@ IMPLEMENT_CLASS(wxFileDialog, wxDialog) // begin wxmac #if defined(__UNIX__) - #include + #include #else #include #endif @@ -73,6 +74,7 @@ NavEventProc( #endif */ + wxTheApp->MacHandleOneEvent(ioParams->eventData.eventDataParms.event); } } @@ -210,7 +212,7 @@ static Boolean SameFSSpec(FSSpecPtr spec1, FSSpecPtr spec2) // flashing of the button when the key is hit static pascal Boolean SFGetFolderModalDialogFilter(DialogPtr theDlgPtr, EventRecord *eventRec, - short *item, Ptr dataPtr) + short *item, void *dataPtr) { #pragma unused (dataPtr) @@ -371,7 +373,7 @@ void ExtendedOpenFile( ConstStr255Param message , ConstStr255Param path , const } } -static pascal Boolean CrossPlatformFileFilter(CInfoPBPtr myCInfoPBPtr, Ptr dataPtr) +static pascal Boolean CrossPlatformFileFilter(CInfoPBPtr myCInfoPBPtr, void *dataPtr) { Str255 filename ; OpenUserDataRecPtr data = (OpenUserDataRecPtr) dataPtr ; diff --git a/src/mac/carbon/gsocket.c b/src/mac/carbon/gsocket.c index 9a6a0596b1..ed895445f2 100644 --- a/src/mac/carbon/gsocket.c +++ b/src/mac/carbon/gsocket.c @@ -19,11 +19,8 @@ #if wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) -#define OTUNIXERRORS 1 #ifdef __UNIX__ - #include - #include - #include + #include #ifndef FALSE #define FALSE 0 @@ -32,6 +29,7 @@ #define TRUE 1 #endif #else + #define OTUNIXERRORS 1 #include #include #include @@ -123,7 +121,11 @@ OSStatus DoNegotiateIPReuseAddrOption(EndpointRef ep, Boolean enableReuseIPMode) ret.opt.maxlen = kOTFourByteOptionSize; opt->level = INET_IP; // dealing with an IP Level function +#ifdef __UNIX__ + opt->name = kIP_REUSEADDR; +#else opt->name = IP_REUSEADDR; +#endif opt->len = kOTFourByteOptionSize; opt->status = 0; *(UInt32*)opt->value = enableReuseIPMode; // set the desired option level, true or false @@ -1043,8 +1045,8 @@ int _GSocket_Recv_Stream(GSocket *socket, char *buffer, int size) { OTFlags flags ; OTResult res ; + OTByteCount sz = 0 ; - size_t sz = 0 ; OTCountDataBytes( socket->m_endpoint , &sz ) ; res = OTRcv( socket->m_endpoint , buffer , size , &flags ) ; if ( res < 0 ) @@ -1055,7 +1057,7 @@ int _GSocket_Recv_Stream(GSocket *socket, char *buffer, int size) // we simulate another read event if there are still bytes if ( socket->m_takesEvents ) { - size_t sz = 0 ; + OTByteCount sz = 0 ; OTCountDataBytes( socket->m_endpoint , &sz ) ; if ( sz > 0 ) { @@ -1365,7 +1367,7 @@ GSocketError GAddress_INET_GetHostName(GAddress *address, char *hostname, size_t assert(address != NULL); CHECK_ADDRESS(address, INET, GSOCK_INVADDR); - OTInetAddressToName( gInetSvcRef , address->m_host , &name ) ; + OTInetAddressToName( gInetSvcRef , address->m_host , name ) ; strncpy( hostname , name , sbuf ) ; return GSOCK_NOERROR; } @@ -1397,7 +1399,7 @@ void _GSocket_Enable_Events(GSocket *socket) state = OTGetEndpointState(socket->m_endpoint); { - size_t sz = 0 ; + OTByteCount sz = 0 ; OTCountDataBytes( socket->m_endpoint , &sz ) ; if ( state == T_INCON || sz > 0 ) { @@ -1437,7 +1439,7 @@ GSocketError _GSocket_Input_Timeout(GSocket *socket) while( (now.hi * 4294967296.0 + now.lo) - (start.hi * 4294967296.0 + start.lo) < socket->m_timeout * 1000.0 ) { OTResult state ; - size_t sz = 0 ; + OTByteCount sz = 0 ; state = OTGetEndpointState(socket->m_endpoint); OTCountDataBytes( socket->m_endpoint , &sz ) ; diff --git a/src/mac/carbon/mimetmac.cpp b/src/mac/carbon/mimetmac.cpp new file mode 100644 index 0000000000..77e60cbc20 --- /dev/null +++ b/src/mac/carbon/mimetmac.cpp @@ -0,0 +1,188 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: mac/mimetype.cpp +// Purpose: classes and functions to manage MIME types +// Author: Vadim Zeitlin +// Modified by: +// Created: 23.09.98 +// RCS-ID: $Id$ +// Copyright: (c) 1998 Vadim Zeitlin +// Licence: wxWindows license (part of wxExtra library) +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ +#pragma implementation "mimetype.h" +#endif + +// for compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#ifndef WX_PRECOMP + #include "wx/defs.h" +#endif + +#ifndef WX_PRECOMP + #include "wx/string.h" + #if wxUSE_GUI + #include "wx/icon.h" + #endif +#endif //WX_PRECOMP + + +#include "wx/log.h" +#include "wx/file.h" +#include "wx/intl.h" +#include "wx/dynarray.h" +#include "wx/confbase.h" + +#include "wx/mac/mimetype.h" + +// other standard headers +#include + +// in case we're compiling in non-GUI mode +class WXDLLEXPORT wxIcon; + + + + + + +bool wxFileTypeImpl::GetCommand(wxString *command, const char *verb) const +{ + return FALSE; +} + +// @@ this function is half implemented +bool wxFileTypeImpl::GetExtensions(wxArrayString& extensions) +{ + return FALSE; +} + +bool wxFileTypeImpl::GetMimeType(wxString *mimeType) const +{ + if ( m_strFileType.Length() > 0 ) + { + *mimeType = m_strFileType ; + return TRUE ; + } + else + return FALSE; +} + +bool wxFileTypeImpl::GetMimeTypes(wxArrayString& mimeTypes) const +{ + wxString s; + + if (GetMimeType(&s)) + { + mimeTypes.Clear(); + mimeTypes.Add(s); + return TRUE; + } + else + return FALSE; +} + +bool wxFileTypeImpl::GetIcon(wxIcon *icon) const +{ + // no such file type or no value or incorrect icon entry + return FALSE; +} + +bool wxFileTypeImpl::GetDescription(wxString *desc) const +{ + return FALSE; +} + +// extension -> file type +wxFileType * +wxMimeTypesManagerImpl::GetFileTypeFromExtension(const wxString& e) +{ + wxString ext = e ; + ext = ext.Lower() ; + if ( ext == "txt" ) + { + wxFileType *fileType = new wxFileType; + fileType->m_impl->SetFileType("text/text"); + fileType->m_impl->SetExt(ext); + return fileType; + } + else if ( ext == "htm" || ext == "html" ) + { + wxFileType *fileType = new wxFileType; + fileType->m_impl->SetFileType("text/html"); + fileType->m_impl->SetExt(ext); + return fileType; + } + else if ( ext == "gif" ) + { + wxFileType *fileType = new wxFileType; + fileType->m_impl->SetFileType("image/gif"); + fileType->m_impl->SetExt(ext); + return fileType; + } + else if ( ext == "png" ) + { + wxFileType *fileType = new wxFileType; + fileType->m_impl->SetFileType("image/png"); + fileType->m_impl->SetExt(ext); + return fileType; + } + else if ( ext == "jpg" || ext == "jpeg" ) + { + wxFileType *fileType = new wxFileType; + fileType->m_impl->SetFileType("image/jpeg"); + fileType->m_impl->SetExt(ext); + return fileType; + } + else if ( ext == "bmp" ) + { + wxFileType *fileType = new wxFileType; + fileType->m_impl->SetFileType("image/bmp"); + fileType->m_impl->SetExt(ext); + return fileType; + } + else if ( ext == "tif" || ext == "tiff" ) + { + wxFileType *fileType = new wxFileType; + fileType->m_impl->SetFileType("image/tiff"); + fileType->m_impl->SetExt(ext); + return fileType; + } + else if ( ext == "xpm" ) + { + wxFileType *fileType = new wxFileType; + fileType->m_impl->SetFileType("image/xpm"); + fileType->m_impl->SetExt(ext); + return fileType; + } + else if ( ext == "xbm" ) + { + wxFileType *fileType = new wxFileType; + fileType->m_impl->SetFileType("image/xbm"); + fileType->m_impl->SetExt(ext); + return fileType; + } + + // unknown extension + return NULL; +} + +// MIME type -> extension -> file type +wxFileType * +wxMimeTypesManagerImpl::GetFileTypeFromMimeType(const wxString& mimeType) +{ + return NULL; +} + +size_t wxMimeTypesManagerImpl::EnumAllFileTypes(wxArrayString& mimetypes) +{ + wxFAIL_MSG( _T("TODO") ); // VZ: don't know anything about this for Mac + + return 0; +} + diff --git a/src/mac/carbon/mimetype.cpp b/src/mac/carbon/mimetype.cpp deleted file mode 100644 index 77e60cbc20..0000000000 --- a/src/mac/carbon/mimetype.cpp +++ /dev/null @@ -1,188 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: mac/mimetype.cpp -// Purpose: classes and functions to manage MIME types -// Author: Vadim Zeitlin -// Modified by: -// Created: 23.09.98 -// RCS-ID: $Id$ -// Copyright: (c) 1998 Vadim Zeitlin -// Licence: wxWindows license (part of wxExtra library) -///////////////////////////////////////////////////////////////////////////// - -#ifdef __GNUG__ -#pragma implementation "mimetype.h" -#endif - -// for compilers that support precompilation, includes "wx.h". -#include "wx/wxprec.h" - -#ifdef __BORLANDC__ - #pragma hdrstop -#endif - -#ifndef WX_PRECOMP - #include "wx/defs.h" -#endif - -#ifndef WX_PRECOMP - #include "wx/string.h" - #if wxUSE_GUI - #include "wx/icon.h" - #endif -#endif //WX_PRECOMP - - -#include "wx/log.h" -#include "wx/file.h" -#include "wx/intl.h" -#include "wx/dynarray.h" -#include "wx/confbase.h" - -#include "wx/mac/mimetype.h" - -// other standard headers -#include - -// in case we're compiling in non-GUI mode -class WXDLLEXPORT wxIcon; - - - - - - -bool wxFileTypeImpl::GetCommand(wxString *command, const char *verb) const -{ - return FALSE; -} - -// @@ this function is half implemented -bool wxFileTypeImpl::GetExtensions(wxArrayString& extensions) -{ - return FALSE; -} - -bool wxFileTypeImpl::GetMimeType(wxString *mimeType) const -{ - if ( m_strFileType.Length() > 0 ) - { - *mimeType = m_strFileType ; - return TRUE ; - } - else - return FALSE; -} - -bool wxFileTypeImpl::GetMimeTypes(wxArrayString& mimeTypes) const -{ - wxString s; - - if (GetMimeType(&s)) - { - mimeTypes.Clear(); - mimeTypes.Add(s); - return TRUE; - } - else - return FALSE; -} - -bool wxFileTypeImpl::GetIcon(wxIcon *icon) const -{ - // no such file type or no value or incorrect icon entry - return FALSE; -} - -bool wxFileTypeImpl::GetDescription(wxString *desc) const -{ - return FALSE; -} - -// extension -> file type -wxFileType * -wxMimeTypesManagerImpl::GetFileTypeFromExtension(const wxString& e) -{ - wxString ext = e ; - ext = ext.Lower() ; - if ( ext == "txt" ) - { - wxFileType *fileType = new wxFileType; - fileType->m_impl->SetFileType("text/text"); - fileType->m_impl->SetExt(ext); - return fileType; - } - else if ( ext == "htm" || ext == "html" ) - { - wxFileType *fileType = new wxFileType; - fileType->m_impl->SetFileType("text/html"); - fileType->m_impl->SetExt(ext); - return fileType; - } - else if ( ext == "gif" ) - { - wxFileType *fileType = new wxFileType; - fileType->m_impl->SetFileType("image/gif"); - fileType->m_impl->SetExt(ext); - return fileType; - } - else if ( ext == "png" ) - { - wxFileType *fileType = new wxFileType; - fileType->m_impl->SetFileType("image/png"); - fileType->m_impl->SetExt(ext); - return fileType; - } - else if ( ext == "jpg" || ext == "jpeg" ) - { - wxFileType *fileType = new wxFileType; - fileType->m_impl->SetFileType("image/jpeg"); - fileType->m_impl->SetExt(ext); - return fileType; - } - else if ( ext == "bmp" ) - { - wxFileType *fileType = new wxFileType; - fileType->m_impl->SetFileType("image/bmp"); - fileType->m_impl->SetExt(ext); - return fileType; - } - else if ( ext == "tif" || ext == "tiff" ) - { - wxFileType *fileType = new wxFileType; - fileType->m_impl->SetFileType("image/tiff"); - fileType->m_impl->SetExt(ext); - return fileType; - } - else if ( ext == "xpm" ) - { - wxFileType *fileType = new wxFileType; - fileType->m_impl->SetFileType("image/xpm"); - fileType->m_impl->SetExt(ext); - return fileType; - } - else if ( ext == "xbm" ) - { - wxFileType *fileType = new wxFileType; - fileType->m_impl->SetFileType("image/xbm"); - fileType->m_impl->SetExt(ext); - return fileType; - } - - // unknown extension - return NULL; -} - -// MIME type -> extension -> file type -wxFileType * -wxMimeTypesManagerImpl::GetFileTypeFromMimeType(const wxString& mimeType) -{ - return NULL; -} - -size_t wxMimeTypesManagerImpl::EnumAllFileTypes(wxArrayString& mimetypes) -{ - wxFAIL_MSG( _T("TODO") ); // VZ: don't know anything about this for Mac - - return 0; -} - diff --git a/src/mac/carbon/pnghand.cpp b/src/mac/carbon/pnghand.cpp index 6134439271..af7b3a6f99 100644 --- a/src/mac/carbon/pnghand.cpp +++ b/src/mac/carbon/pnghand.cpp @@ -414,7 +414,11 @@ bool wxPNGReader::ReadFile(char * ImageFileName) wxPNGReaderIter iter(this); /* open the file */ +#ifndef __UNIX__ fp = fopen(wxUnix2MacFilename( ImageFileName ), "rb"); +#else + fp = fopen( ImageFileName , "rb" ); +#endif if (!fp) return FALSE; diff --git a/src/mac/carbon/statusbr.cpp b/src/mac/carbon/statusbr.cpp index 5b52c76ac0..4ff42994c0 100644 --- a/src/mac/carbon/statusbr.cpp +++ b/src/mac/carbon/statusbr.cpp @@ -17,12 +17,13 @@ // headers // ---------------------------------------------------------------------------- -#include "wx/mac/statusbr.h" +#include "wx/defs.h" +#include "wx/statusbr.h" -IMPLEMENT_DYNAMIC_CLASS(wxStatusBarXX, wxStatusBar); +IMPLEMENT_DYNAMIC_CLASS(wxStatusBarMac, wxStatusBar); -BEGIN_EVENT_TABLE(wxStatusBarXX, wxStatusBar) - EVT_SIZE(wxStatusBarXX::OnSize) +BEGIN_EVENT_TABLE(wxStatusBarMac, wxStatusBar) + EVT_SIZE(wxStatusBarMac::OnSize) END_EVENT_TABLE() @@ -31,20 +32,15 @@ END_EVENT_TABLE() // ============================================================================ // ---------------------------------------------------------------------------- -// wxStatusBarXX class +// wxStatusBarMac class // ---------------------------------------------------------------------------- -wxStatusBarXX::wxStatusBarXX() +wxStatusBarMac::wxStatusBarMac() { SetParent(NULL); } -wxStatusBarXX::wxStatusBarXX(wxWindow *parent, wxWindowID id, long style) -{ - Create(parent, id, style); -} - -bool wxStatusBarXX::Create(wxWindow *parent, wxWindowID id, long style) +bool wxStatusBarMac::Create(wxWindow *parent, wxWindowID id, long style, const wxString& name = wxPanelNameStr) { SetParent(parent); @@ -57,7 +53,7 @@ bool wxStatusBarXX::Create(wxWindow *parent, wxWindowID id, long style) return FALSE; } -void wxStatusBarXX::SetFieldsCount(int nFields, const int widths[]) +void wxStatusBarMac::SetFieldsCount(int nFields, const int widths[]) { wxASSERT( (nFields > 0) && (nFields < 255) ); @@ -67,7 +63,7 @@ void wxStatusBarXX::SetFieldsCount(int nFields, const int widths[]) SetFieldsWidth(); } -void wxStatusBarXX::SetStatusWidths(int n, const int widths[]) +void wxStatusBarMac::SetStatusWidths(int n, const int widths[]) { wxASSERT( n == m_nFields ); @@ -75,7 +71,7 @@ void wxStatusBarXX::SetStatusWidths(int n, const int widths[]) SetFieldsWidth(); } -void wxStatusBarXX::CopyFieldsWidth(const int widths[]) +void wxStatusBarMac::CopyFieldsWidth(const int widths[]) { if (widths && !m_statusWidths) m_statusWidths = new int[m_nFields]; @@ -90,7 +86,7 @@ void wxStatusBarXX::CopyFieldsWidth(const int widths[]) } } -void wxStatusBarXX::SetFieldsWidth() +void wxStatusBarMac::SetFieldsWidth() { int *pWidths = new int[m_nFields]; @@ -140,12 +136,12 @@ void wxStatusBarXX::SetFieldsWidth() delete [] pWidths; } -void wxStatusBarXX::SetStatusText(const wxString& strText, int nField) +void wxStatusBarMac::SetStatusText(const wxString& strText, int nField) { // TODO } -wxString wxStatusBarXX::GetStatusText(int nField) const +wxString wxStatusBarMac::GetStatusText(int nField) const { wxASSERT( (nField > -1) && (nField < m_nFields) ); @@ -153,7 +149,7 @@ wxString wxStatusBarXX::GetStatusText(int nField) const return wxString(""); } -void wxStatusBarXX::OnSize(wxSizeEvent& event) +void wxStatusBarMac::OnSize(wxSizeEvent& event) { // adjust fields widths to the new size SetFieldsWidth(); diff --git a/src/mac/carbon/textctrl.cpp b/src/mac/carbon/textctrl.cpp index 7e1450068d..0a51bb757e 100644 --- a/src/mac/carbon/textctrl.cpp +++ b/src/mac/carbon/textctrl.cpp @@ -22,6 +22,7 @@ #include #include "wx/app.h" +#include "wx/dc.h" #include "wx/button.h" #include "wx/panel.h" #include "wx/textctrl.h" diff --git a/src/mac/carbon/tooltip.cpp b/src/mac/carbon/tooltip.cpp index 5974c8808e..eb92ed996e 100644 --- a/src/mac/carbon/tooltip.cpp +++ b/src/mac/carbon/tooltip.cpp @@ -16,6 +16,7 @@ #if wxUSE_TOOLTIPS #include "wx/app.h" +#include "wx/dc.h" #include "wx/window.h" #include "wx/tooltip.h" #include "wx/timer.h" diff --git a/src/mac/carbon/uma.cpp b/src/mac/carbon/uma.cpp index f34db6bc39..13d4e27883 100644 --- a/src/mac/carbon/uma.cpp +++ b/src/mac/carbon/uma.cpp @@ -1,9 +1,10 @@ #include "wx/defs.h" +#include "wx/dc.h" #include "wx/mac/uma.h" #include "wx/mac/aga.h" #ifdef __UNIX__ - #include + #include #else #include #endif diff --git a/src/mac/carbon/utils.cpp b/src/mac/carbon/utils.cpp index 5d1e9faf41..6723ed2ad4 100644 --- a/src/mac/carbon/utils.cpp +++ b/src/mac/carbon/utils.cpp @@ -260,6 +260,7 @@ bool wxIsBusy() return (wxBusyCursorCount > 0); } +#ifndef __UNIX__ wxString wxMacFindFolder( short vol, OSType folderType, Boolean createFolder) @@ -278,6 +279,7 @@ wxString wxMacFindFolder( short vol, } return strDir ; } +#endif #ifndef __UNIX__ char *wxGetUserHome (const wxString& user) @@ -343,6 +345,11 @@ void wxDisplaySize(int *width, int *height) #endif } +void wxDisplaySizeMM(int *width, int *height) +{ + wxDisplaySize(width, height); +} + wxWindow* wxFindWindowAtPoint(const wxPoint& pt) { return wxGenericFindWindowAtPoint(pt); diff --git a/src/mac/carbon/utilsexc.cpp b/src/mac/carbon/utilsexc.cpp index b842d08e90..624a9c0524 100644 --- a/src/mac/carbon/utilsexc.cpp +++ b/src/mac/carbon/utilsexc.cpp @@ -14,11 +14,15 @@ #endif #include "wx/utils.h" +#ifdef __UNIX__ +#include "wx/unix/execute.h" +#endif #include #include #include +#ifndef __UNIX__ #define wxEXECUTE_WIN_MESSAGE 10000 long wxExecute(const wxString& command, bool sync, wxProcess *handler) @@ -26,3 +30,12 @@ long wxExecute(const wxString& command, bool sync, wxProcess *handler) // TODO return 0; } +#endif + +#ifdef __UNIX__ +int wxAddProcessCallback(wxEndProcessData *proc_data, int fd) +{ + wxFAIL_MSG(wxT("wxAddProcessCallback() function not ready")); + return 0; +} +#endif \ No newline at end of file diff --git a/src/mac/carbon/wave.cpp b/src/mac/carbon/wave.cpp index ac2dcac7e0..f0891a6546 100644 --- a/src/mac/carbon/wave.cpp +++ b/src/mac/carbon/wave.cpp @@ -126,14 +126,18 @@ bool wxWave::Play(bool async, bool looped) const if (m_isResource) { - strcpy(lpSnd, m_sndname); - c2pstr((char *) lpSnd); - SndListHandle hSnd; - - hSnd = (SndListHandle) GetNamedResource('snd ',(const unsigned char *) lpSnd); +#if TARGET_CARBON + c2pstrcpy((unsigned char *)lpSnd, m_sndname); +#else + strcpy(lpSnd, m_sndname); + c2pstr((char *) lpSnd); +#endif + SndListHandle hSnd; + + hSnd = (SndListHandle) GetNamedResource('snd ',(const unsigned char *) lpSnd); - if ((hSnd != NULL) && (SndPlay(m_sndChan, hSnd, async) == noErr)) - ret = true; + if ((hSnd != NULL) && (SndPlay(m_sndChan, hSnd, async) == noErr)) + ret = true; } return ret; diff --git a/src/mac/carbon/window.cpp b/src/mac/carbon/window.cpp index f3ba668abe..382b71024f 100644 --- a/src/mac/carbon/window.cpp +++ b/src/mac/carbon/window.cpp @@ -15,6 +15,7 @@ #include "wx/setup.h" #include "wx/menu.h" +#include "wx/window.h" #include "wx/dc.h" #include "wx/dcclient.h" #include "wx/utils.h" @@ -33,9 +34,6 @@ #include "wx/tabctrl.h" #include "wx/tooltip.h" #include "wx/statusbr.h" -// TODO remove the line below, just for lookup-up convenience CS -#include "wx/window.h" - #include "wx/menuitem.h" #include "wx/log.h" @@ -763,6 +761,11 @@ void wxWindow::MacSuperShown( bool show ) bool wxWindow::MacIsReallyShown() const { + if ( m_isShown && (m_parent != NULL) ) { + return m_parent->MacIsReallyShown(); + } + return m_isShown; +/* bool status = m_isShown ; wxWindow * win = this ; while ( status && win->m_parent != NULL ) @@ -771,6 +774,7 @@ bool wxWindow::MacIsReallyShown() const status = win->m_isShown ; } return status ; +*/ } int wxWindow::GetCharHeight() const @@ -794,7 +798,7 @@ void wxWindow::GetTextExtent(const wxString& string, int *x, int *y, wxClientDC dc( (wxWindow*) this ) ; long lx,ly,ld,le ; - dc.GetTextExtent( string , &lx , &ly , &ld, &le, fontToUse ) ; + dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ; if ( externalLeading ) *externalLeading = le ; if ( descent ) @@ -2306,7 +2310,37 @@ long wxWindow::MacRemoveBordersFromStyle( long style ) { return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ; } - +/* +wxMacFocusHelper::wxMacFocusHelper( wxWindow * theWindow ) +{ + m_ok = false ; + Point localOrigin ; + Rect clipRect ; + WindowRef window ; + wxWindow *rootwin ; + m_currentPort = NULL ; + GetPort( &m_formerPort ) ; + if ( theWindow ) + { + + theWindow->MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ; + m_currentPort = UMAGetWindowPort( window ) ; + theWindow->MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ; + m_ok = true ; + } +} + +wxMacFocusHelper::~wxMacFocusHelper() +{ + if ( m_ok ) + { + SetPort( m_currentPort ) ; + SetOrigin( 0 , 0 ) ; + } + if ( m_formerPort != m_currentPort ) + SetPort( m_formerPort ) ; +} +*/ wxMacDrawingHelper::wxMacDrawingHelper( wxWindow * theWindow ) { diff --git a/src/mac/cdef/extcdef.mcp b/src/mac/cdef/extcdef.mcp index 94663fa379..4981558381 100644 Binary files a/src/mac/cdef/extcdef.mcp and b/src/mac/cdef/extcdef.mcp differ diff --git a/src/mac/clipbrd.cpp b/src/mac/clipbrd.cpp index ca5b793396..1e99ca3ce7 100644 --- a/src/mac/clipbrd.cpp +++ b/src/mac/clipbrd.cpp @@ -20,6 +20,7 @@ #include "wx/utils.h" #include "wx/metafile.h" #include "wx/clipbrd.h" +#include "wx/intl.h" #define wxUSE_DATAOBJ 1 diff --git a/src/mac/control.cpp b/src/mac/control.cpp index cbbd8e3429..63610676a0 100644 --- a/src/mac/control.cpp +++ b/src/mac/control.cpp @@ -16,6 +16,7 @@ #include "wx/control.h" #include "wx/panel.h" #include "wx/app.h" +#include "wx/dc.h" #include "wx/notebook.h" #include "wx/tabctrl.h" #include "wx/radiobox.h" diff --git a/src/mac/dir.cpp b/src/mac/dir.cpp deleted file mode 100644 index e37f079382..0000000000 --- a/src/mac/dir.cpp +++ /dev/null @@ -1,272 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: msw/dir.cpp -// Purpose: wxDir implementation for Mac -// Author: Stefan Csomor -// Modified by: -// Created: 08.12.99 -// RCS-ID: $Id$ -// Copyright: (c) 1999 Stefan Csomor -// Licence: wxWindows license -///////////////////////////////////////////////////////////////////////////// - -// ============================================================================ -// declarations -// ============================================================================ - -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - -#ifdef __GNUG__ - #pragma implementation "dir.h" -#endif - -// For compilers that support precompilation, includes "wx.h". -#include "wx/wxprec.h" - -#ifdef __BORLANDC__ - #pragma hdrstop -#endif - -#ifndef WX_PRECOMP - #include "wx/intl.h" - #include "wx/log.h" -#endif // PCH - -#include "wx/dir.h" -#include "wx/filefn.h" // for wxPathExists() - -#ifndef __WXMAC_X__ - #include -#endif - -#if defined(__WXMAC__) && !defined(__UNIX__) - #include "morefile.h" - #include "moreextr.h" - #include "fullpath.h" - #include "fspcompa.h" -#endif - -// ---------------------------------------------------------------------------- -// constants -// ---------------------------------------------------------------------------- - -#ifndef MAX_PATH - #define MAX_PATH 260 // from VC++ headers -#endif - -// ---------------------------------------------------------------------------- -// macros -// ---------------------------------------------------------------------------- - -#define M_DIR ((wxDirData *)m_data) - -// ---------------------------------------------------------------------------- -// private classes -// ---------------------------------------------------------------------------- - -// this class stores everything we need to enumerate the files -class wxDirData -{ -public: - wxDirData(const wxString& dirname); - ~wxDirData(); - - void SetFileSpec(const wxString& filespec) { m_filespec = filespec; } - void SetFlags(int flags) { m_flags = flags; } - - bool Read(wxString *filename); // reads the next - void Rewind() ; - -private: - CInfoPBRec m_CPB ; - wxInt16 m_index ; - long m_dirId ; - Str255 m_name ; - Boolean m_isDir ; - - wxString m_dirname; - wxString m_filespec; - - int m_flags; -}; - -// ============================================================================ -// implementation -// ============================================================================ - -// ---------------------------------------------------------------------------- -// wxDirData -// ---------------------------------------------------------------------------- - -wxDirData::wxDirData(const wxString& dirname) - : m_dirname(dirname) -{ - // throw away the trailing slashes - size_t n = m_dirname.length(); - wxCHECK_RET( n, _T("empty dir name in wxDir") ); - - while ( n > 0 && wxIsPathSeparator(m_dirname[--n]) ) - ; - - m_dirname.Truncate(n + 1); - - FSSpec fsspec ; - - wxUnixFilename2FSSpec( m_dirname , &fsspec ) ; - m_CPB.hFileInfo.ioVRefNum = fsspec.vRefNum ; - m_CPB.hFileInfo.ioNamePtr = m_name ; - m_index = 0 ; - -#ifdef __WXMAC_X__ - // TODO: what are we supposed to do for Mac OS X -#else - FSpGetDirectoryID( &fsspec , &m_dirId , &m_isDir ) ; -#endif -} - -wxDirData::~wxDirData() -{ -} - -void wxDirData::Rewind() -{ - m_index = 0 ; -} - -bool wxDirData::Read(wxString *filename) -{ - if ( !m_isDir ) - return FALSE ; - -#if TARGET_CARBON - char c_name[256] ; -#endif - wxString result; - - short err = noErr ; - - while ( err == noErr ) - { - m_index++ ; - m_CPB.dirInfo.ioFDirIndex = m_index; - m_CPB.dirInfo.ioDrDirID = m_dirId; /* we need to do this every time */ - err = PBGetCatInfoSync((CInfoPBPtr)&m_CPB); - if ( err != noErr ) - break ; - -#if TARGET_CARBON - p2cstrcpy( c_name, m_name ) ; - strcpy( (char *)m_name, c_name); -#else - p2cstr( m_name ) ; -#endif - if ( ( m_CPB.dirInfo.ioFlAttrib & ioDirMask) != 0 && (m_flags & wxDIR_DIRS) ) // we have a directory - break ; - - if ( ( m_CPB.dirInfo.ioFlAttrib & ioDirMask) == 0 && !(m_flags & wxDIR_FILES ) ) // its a file but we don't want it - continue ; - - if ( ( m_CPB.hFileInfo.ioFlFndrInfo.fdFlags & kIsInvisible ) && !(m_flags & wxDIR_HIDDEN) ) // its hidden but we don't want it - continue ; - - wxString file( m_name ) ; - if ( m_filespec.IsEmpty() || m_filespec == "*.*" ) - { - } - else if ( m_filespec.Length() > 1 && m_filespec.Left(1) =="*" ) - { - if ( file.Right( m_filespec.Length() - 1 ).Upper() != m_filespec.Mid(1).Upper() ) - { - continue ; - } - } - else if ( m_filespec.Length() > 1 && m_filespec.Right(1) == "*" ) - { - if ( file.Left( m_filespec.Length() - 1 ).Upper() != m_filespec.Left( m_filespec.Length() - 1 ).Upper() ) - { - continue ; - } - } - else if ( file.Upper() != m_filespec.Upper() ) - { - continue ; - } - - break ; - } - if ( err != noErr ) - { - return FALSE ; - } - - *filename = (char*) m_name ; - - return TRUE; -} - -// ---------------------------------------------------------------------------- -// wxDir helpers -// ---------------------------------------------------------------------------- - -/* static */ -bool wxDir::Exists(const wxString& dir) -{ - return wxPathExists(dir); -} - -// ---------------------------------------------------------------------------- -// wxDir construction/destruction -// ---------------------------------------------------------------------------- - -wxDir::wxDir(const wxString& dirname) -{ - m_data = NULL; - - (void)Open(dirname); -} - -bool wxDir::Open(const wxString& dirname) -{ - delete M_DIR; - m_data = new wxDirData(dirname); - - return TRUE; -} - -bool wxDir::IsOpened() const -{ - return m_data != NULL; -} - -wxDir::~wxDir() -{ - delete M_DIR; -} - -// ---------------------------------------------------------------------------- -// wxDir enumerating -// ---------------------------------------------------------------------------- - -bool wxDir::GetFirst(wxString *filename, - const wxString& filespec, - int flags) const -{ - wxCHECK_MSG( IsOpened(), FALSE, _T("must wxDir::Open() first") ); - - M_DIR->Rewind(); - - M_DIR->SetFileSpec(filespec); - M_DIR->SetFlags(flags); - - return GetNext(filename); -} - -bool wxDir::GetNext(wxString *filename) const -{ - wxCHECK_MSG( IsOpened(), FALSE, _T("must wxDir::Open() first") ); - - wxCHECK_MSG( filename, FALSE, _T("bad pointer in wxDir::GetNext()") ); - - return M_DIR->Read(filename); -} diff --git a/src/mac/dirdlg.cpp b/src/mac/dirdlg.cpp index e1255db7e1..89b3892451 100644 --- a/src/mac/dirdlg.cpp +++ b/src/mac/dirdlg.cpp @@ -21,7 +21,7 @@ #include "wx/cmndata.h" #if defined(__UNIX__) - #include + #include #else #include #endif @@ -182,7 +182,7 @@ static Boolean SameFSSpec(FSSpecPtr spec1, FSSpecPtr spec2) // flashing of the button when the key is hit static pascal Boolean SFGetFolderModalDialogFilter(DialogPtr theDlgPtr, EventRecord *eventRec, - short *item, Ptr dataPtr) + short *item, void *dataPtr) { #pragma unused (dataPtr) @@ -210,7 +210,7 @@ static pascal Boolean SFGetFolderModalDialogFilter(DialogPtr theDlgPtr, EventRec // MyDlgHook is a hook routine that maps the select button to Open // and sets the Select button name -static pascal short SFGetFolderDialogHook(short item, DialogPtr theDlgPtr, Ptr dataPtr) +static pascal short SFGetFolderDialogHook(short item, DialogPtr theDlgPtr, void *dataPtr) { UserDataRecPtr theUserDataRecPtr; long desktopDirID; @@ -422,7 +422,7 @@ void StandardGetFolder( ConstStr255Param message , ConstStr255Param path , FileF } } -static pascal Boolean OnlyVisibleFoldersCustomFileFilter(CInfoPBPtr myCInfoPBPtr, Ptr dataPtr) +static pascal Boolean OnlyVisibleFoldersCustomFileFilter(CInfoPBPtr myCInfoPBPtr, void *dataPtr) { #pragma unused (dataPtr) diff --git a/src/mac/dirmac.cpp b/src/mac/dirmac.cpp new file mode 100644 index 0000000000..e37f079382 --- /dev/null +++ b/src/mac/dirmac.cpp @@ -0,0 +1,272 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: msw/dir.cpp +// Purpose: wxDir implementation for Mac +// Author: Stefan Csomor +// Modified by: +// Created: 08.12.99 +// RCS-ID: $Id$ +// Copyright: (c) 1999 Stefan Csomor +// Licence: wxWindows license +///////////////////////////////////////////////////////////////////////////// + +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#ifdef __GNUG__ + #pragma implementation "dir.h" +#endif + +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#ifndef WX_PRECOMP + #include "wx/intl.h" + #include "wx/log.h" +#endif // PCH + +#include "wx/dir.h" +#include "wx/filefn.h" // for wxPathExists() + +#ifndef __WXMAC_X__ + #include +#endif + +#if defined(__WXMAC__) && !defined(__UNIX__) + #include "morefile.h" + #include "moreextr.h" + #include "fullpath.h" + #include "fspcompa.h" +#endif + +// ---------------------------------------------------------------------------- +// constants +// ---------------------------------------------------------------------------- + +#ifndef MAX_PATH + #define MAX_PATH 260 // from VC++ headers +#endif + +// ---------------------------------------------------------------------------- +// macros +// ---------------------------------------------------------------------------- + +#define M_DIR ((wxDirData *)m_data) + +// ---------------------------------------------------------------------------- +// private classes +// ---------------------------------------------------------------------------- + +// this class stores everything we need to enumerate the files +class wxDirData +{ +public: + wxDirData(const wxString& dirname); + ~wxDirData(); + + void SetFileSpec(const wxString& filespec) { m_filespec = filespec; } + void SetFlags(int flags) { m_flags = flags; } + + bool Read(wxString *filename); // reads the next + void Rewind() ; + +private: + CInfoPBRec m_CPB ; + wxInt16 m_index ; + long m_dirId ; + Str255 m_name ; + Boolean m_isDir ; + + wxString m_dirname; + wxString m_filespec; + + int m_flags; +}; + +// ============================================================================ +// implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// wxDirData +// ---------------------------------------------------------------------------- + +wxDirData::wxDirData(const wxString& dirname) + : m_dirname(dirname) +{ + // throw away the trailing slashes + size_t n = m_dirname.length(); + wxCHECK_RET( n, _T("empty dir name in wxDir") ); + + while ( n > 0 && wxIsPathSeparator(m_dirname[--n]) ) + ; + + m_dirname.Truncate(n + 1); + + FSSpec fsspec ; + + wxUnixFilename2FSSpec( m_dirname , &fsspec ) ; + m_CPB.hFileInfo.ioVRefNum = fsspec.vRefNum ; + m_CPB.hFileInfo.ioNamePtr = m_name ; + m_index = 0 ; + +#ifdef __WXMAC_X__ + // TODO: what are we supposed to do for Mac OS X +#else + FSpGetDirectoryID( &fsspec , &m_dirId , &m_isDir ) ; +#endif +} + +wxDirData::~wxDirData() +{ +} + +void wxDirData::Rewind() +{ + m_index = 0 ; +} + +bool wxDirData::Read(wxString *filename) +{ + if ( !m_isDir ) + return FALSE ; + +#if TARGET_CARBON + char c_name[256] ; +#endif + wxString result; + + short err = noErr ; + + while ( err == noErr ) + { + m_index++ ; + m_CPB.dirInfo.ioFDirIndex = m_index; + m_CPB.dirInfo.ioDrDirID = m_dirId; /* we need to do this every time */ + err = PBGetCatInfoSync((CInfoPBPtr)&m_CPB); + if ( err != noErr ) + break ; + +#if TARGET_CARBON + p2cstrcpy( c_name, m_name ) ; + strcpy( (char *)m_name, c_name); +#else + p2cstr( m_name ) ; +#endif + if ( ( m_CPB.dirInfo.ioFlAttrib & ioDirMask) != 0 && (m_flags & wxDIR_DIRS) ) // we have a directory + break ; + + if ( ( m_CPB.dirInfo.ioFlAttrib & ioDirMask) == 0 && !(m_flags & wxDIR_FILES ) ) // its a file but we don't want it + continue ; + + if ( ( m_CPB.hFileInfo.ioFlFndrInfo.fdFlags & kIsInvisible ) && !(m_flags & wxDIR_HIDDEN) ) // its hidden but we don't want it + continue ; + + wxString file( m_name ) ; + if ( m_filespec.IsEmpty() || m_filespec == "*.*" ) + { + } + else if ( m_filespec.Length() > 1 && m_filespec.Left(1) =="*" ) + { + if ( file.Right( m_filespec.Length() - 1 ).Upper() != m_filespec.Mid(1).Upper() ) + { + continue ; + } + } + else if ( m_filespec.Length() > 1 && m_filespec.Right(1) == "*" ) + { + if ( file.Left( m_filespec.Length() - 1 ).Upper() != m_filespec.Left( m_filespec.Length() - 1 ).Upper() ) + { + continue ; + } + } + else if ( file.Upper() != m_filespec.Upper() ) + { + continue ; + } + + break ; + } + if ( err != noErr ) + { + return FALSE ; + } + + *filename = (char*) m_name ; + + return TRUE; +} + +// ---------------------------------------------------------------------------- +// wxDir helpers +// ---------------------------------------------------------------------------- + +/* static */ +bool wxDir::Exists(const wxString& dir) +{ + return wxPathExists(dir); +} + +// ---------------------------------------------------------------------------- +// wxDir construction/destruction +// ---------------------------------------------------------------------------- + +wxDir::wxDir(const wxString& dirname) +{ + m_data = NULL; + + (void)Open(dirname); +} + +bool wxDir::Open(const wxString& dirname) +{ + delete M_DIR; + m_data = new wxDirData(dirname); + + return TRUE; +} + +bool wxDir::IsOpened() const +{ + return m_data != NULL; +} + +wxDir::~wxDir() +{ + delete M_DIR; +} + +// ---------------------------------------------------------------------------- +// wxDir enumerating +// ---------------------------------------------------------------------------- + +bool wxDir::GetFirst(wxString *filename, + const wxString& filespec, + int flags) const +{ + wxCHECK_MSG( IsOpened(), FALSE, _T("must wxDir::Open() first") ); + + M_DIR->Rewind(); + + M_DIR->SetFileSpec(filespec); + M_DIR->SetFlags(flags); + + return GetNext(filename); +} + +bool wxDir::GetNext(wxString *filename) const +{ + wxCHECK_MSG( IsOpened(), FALSE, _T("must wxDir::Open() first") ); + + wxCHECK_MSG( filename, FALSE, _T("bad pointer in wxDir::GetNext()") ); + + return M_DIR->Read(filename); +} diff --git a/src/mac/dnd.cpp b/src/mac/dnd.cpp index aa19db3d01..ece56ce7d3 100644 --- a/src/mac/dnd.cpp +++ b/src/mac/dnd.cpp @@ -39,20 +39,22 @@ wxDropTarget::~wxDropTarget() // ---------------------------------------------------------------------------- // wxTextDropTarget // ---------------------------------------------------------------------------- - -bool wxTextDropTarget::OnDrop( long x, long y, const void *pData ) +#ifndef __WXMAC_X__ +bool wxTextDropTarget::OnDrop( wxCoord x, wxCoord y, const void *pData ) { OnDropText( x, y, (const char*)pData ); return TRUE; }; +#endif -bool wxTextDropTarget::OnDropText( long x, long y, const char *psz ) +bool wxTextDropTarget::OnDropText( wxCoord x, wxCoord y, const wxString &psz ) { - printf( "Got dropped text: %s.\n", psz ); + printf( "Got dropped text: %s.\n", (char *)psz ); printf( "At x: %d, y: %d.\n", (int)x, (int)y ); return TRUE; }; +#ifndef __WXMAC_X__ size_t wxTextDropTarget::GetFormatCount() const { return 1; @@ -62,25 +64,27 @@ wxDataFormat wxTextDropTarget::GetFormat(size_t WXUNUSED(n)) const { return wxDF_TEXT; } +#endif // ---------------------------------------------------------------------------- // wxFileDropTarget // ---------------------------------------------------------------------------- -bool wxFileDropTarget::OnDropFiles( long x, long y, size_t nFiles, const char * const WXUNUSED(aszFiles)[] ) +#ifndef __WXMAC_X__ +bool wxFileDropTarget::OnDropFiles( wxCoord x, wxCoord y, size_t nFiles, const char * const WXUNUSED(aszFiles)[] ) { printf( "Got %d dropped files.\n", (int)nFiles ); printf( "At x: %d, y: %d.\n", (int)x, (int)y ); return TRUE; } +#endif -bool wxFileDropTarget::OnDrop(long x, long y, const void *WXUNUSED(pData) ) +bool wxFileDropTarget::OnDrop(wxCoord x, wxCoord y, const wxArrayString& filenames) { - char *str = "/this/is/a/path.txt"; - - return OnDropFiles(x, y, 1, &str ); + return OnDropFiles(x, y, 1, &filenames); } +#ifndef __WXMAC_X__ size_t wxFileDropTarget::GetFormatCount() const { return 1; @@ -90,6 +94,7 @@ wxDataFormat wxFileDropTarget::GetFormat(size_t WXUNUSED(n)) const { return wxDF_FILENAME; } +#endif //------------------------------------------------------------------------- // wxDropSource diff --git a/src/mac/filedlg.cpp b/src/mac/filedlg.cpp index 118ec1a6a8..406ce43b19 100644 --- a/src/mac/filedlg.cpp +++ b/src/mac/filedlg.cpp @@ -14,6 +14,7 @@ #endif #include "wx/defs.h" +#include "wx/app.h" #include "wx/utils.h" #include "wx/dialog.h" #include "wx/filedlg.h" @@ -30,7 +31,7 @@ IMPLEMENT_CLASS(wxFileDialog, wxDialog) // begin wxmac #if defined(__UNIX__) - #include + #include #else #include #endif @@ -73,6 +74,7 @@ NavEventProc( #endif */ + wxTheApp->MacHandleOneEvent(ioParams->eventData.eventDataParms.event); } } @@ -210,7 +212,7 @@ static Boolean SameFSSpec(FSSpecPtr spec1, FSSpecPtr spec2) // flashing of the button when the key is hit static pascal Boolean SFGetFolderModalDialogFilter(DialogPtr theDlgPtr, EventRecord *eventRec, - short *item, Ptr dataPtr) + short *item, void *dataPtr) { #pragma unused (dataPtr) @@ -371,7 +373,7 @@ void ExtendedOpenFile( ConstStr255Param message , ConstStr255Param path , const } } -static pascal Boolean CrossPlatformFileFilter(CInfoPBPtr myCInfoPBPtr, Ptr dataPtr) +static pascal Boolean CrossPlatformFileFilter(CInfoPBPtr myCInfoPBPtr, void *dataPtr) { Str255 filename ; OpenUserDataRecPtr data = (OpenUserDataRecPtr) dataPtr ; diff --git a/src/mac/gsocket.c b/src/mac/gsocket.c index 9a6a0596b1..ed895445f2 100644 --- a/src/mac/gsocket.c +++ b/src/mac/gsocket.c @@ -19,11 +19,8 @@ #if wxUSE_SOCKETS || defined(__GSOCKET_STANDALONE__) -#define OTUNIXERRORS 1 #ifdef __UNIX__ - #include - #include - #include + #include #ifndef FALSE #define FALSE 0 @@ -32,6 +29,7 @@ #define TRUE 1 #endif #else + #define OTUNIXERRORS 1 #include #include #include @@ -123,7 +121,11 @@ OSStatus DoNegotiateIPReuseAddrOption(EndpointRef ep, Boolean enableReuseIPMode) ret.opt.maxlen = kOTFourByteOptionSize; opt->level = INET_IP; // dealing with an IP Level function +#ifdef __UNIX__ + opt->name = kIP_REUSEADDR; +#else opt->name = IP_REUSEADDR; +#endif opt->len = kOTFourByteOptionSize; opt->status = 0; *(UInt32*)opt->value = enableReuseIPMode; // set the desired option level, true or false @@ -1043,8 +1045,8 @@ int _GSocket_Recv_Stream(GSocket *socket, char *buffer, int size) { OTFlags flags ; OTResult res ; + OTByteCount sz = 0 ; - size_t sz = 0 ; OTCountDataBytes( socket->m_endpoint , &sz ) ; res = OTRcv( socket->m_endpoint , buffer , size , &flags ) ; if ( res < 0 ) @@ -1055,7 +1057,7 @@ int _GSocket_Recv_Stream(GSocket *socket, char *buffer, int size) // we simulate another read event if there are still bytes if ( socket->m_takesEvents ) { - size_t sz = 0 ; + OTByteCount sz = 0 ; OTCountDataBytes( socket->m_endpoint , &sz ) ; if ( sz > 0 ) { @@ -1365,7 +1367,7 @@ GSocketError GAddress_INET_GetHostName(GAddress *address, char *hostname, size_t assert(address != NULL); CHECK_ADDRESS(address, INET, GSOCK_INVADDR); - OTInetAddressToName( gInetSvcRef , address->m_host , &name ) ; + OTInetAddressToName( gInetSvcRef , address->m_host , name ) ; strncpy( hostname , name , sbuf ) ; return GSOCK_NOERROR; } @@ -1397,7 +1399,7 @@ void _GSocket_Enable_Events(GSocket *socket) state = OTGetEndpointState(socket->m_endpoint); { - size_t sz = 0 ; + OTByteCount sz = 0 ; OTCountDataBytes( socket->m_endpoint , &sz ) ; if ( state == T_INCON || sz > 0 ) { @@ -1437,7 +1439,7 @@ GSocketError _GSocket_Input_Timeout(GSocket *socket) while( (now.hi * 4294967296.0 + now.lo) - (start.hi * 4294967296.0 + start.lo) < socket->m_timeout * 1000.0 ) { OTResult state ; - size_t sz = 0 ; + OTByteCount sz = 0 ; state = OTGetEndpointState(socket->m_endpoint); OTCountDataBytes( socket->m_endpoint , &sz ) ; diff --git a/src/mac/ldef/extldef.h b/src/mac/ldef/extldef.h index a583d872c0..c678fafe58 100644 --- a/src/mac/ldef/extldef.h +++ b/src/mac/ldef/extldef.h @@ -1,7 +1,7 @@ #pragma once #if defined(__UNIX__) - #include + #include #else #include #endif diff --git a/src/mac/ldef/extldef.mcp b/src/mac/ldef/extldef.mcp index c3b002d3c2..458d375486 100644 Binary files a/src/mac/ldef/extldef.mcp and b/src/mac/ldef/extldef.mcp differ diff --git a/src/mac/mimetmac.cpp b/src/mac/mimetmac.cpp new file mode 100644 index 0000000000..77e60cbc20 --- /dev/null +++ b/src/mac/mimetmac.cpp @@ -0,0 +1,188 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: mac/mimetype.cpp +// Purpose: classes and functions to manage MIME types +// Author: Vadim Zeitlin +// Modified by: +// Created: 23.09.98 +// RCS-ID: $Id$ +// Copyright: (c) 1998 Vadim Zeitlin +// Licence: wxWindows license (part of wxExtra library) +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ +#pragma implementation "mimetype.h" +#endif + +// for compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#ifndef WX_PRECOMP + #include "wx/defs.h" +#endif + +#ifndef WX_PRECOMP + #include "wx/string.h" + #if wxUSE_GUI + #include "wx/icon.h" + #endif +#endif //WX_PRECOMP + + +#include "wx/log.h" +#include "wx/file.h" +#include "wx/intl.h" +#include "wx/dynarray.h" +#include "wx/confbase.h" + +#include "wx/mac/mimetype.h" + +// other standard headers +#include + +// in case we're compiling in non-GUI mode +class WXDLLEXPORT wxIcon; + + + + + + +bool wxFileTypeImpl::GetCommand(wxString *command, const char *verb) const +{ + return FALSE; +} + +// @@ this function is half implemented +bool wxFileTypeImpl::GetExtensions(wxArrayString& extensions) +{ + return FALSE; +} + +bool wxFileTypeImpl::GetMimeType(wxString *mimeType) const +{ + if ( m_strFileType.Length() > 0 ) + { + *mimeType = m_strFileType ; + return TRUE ; + } + else + return FALSE; +} + +bool wxFileTypeImpl::GetMimeTypes(wxArrayString& mimeTypes) const +{ + wxString s; + + if (GetMimeType(&s)) + { + mimeTypes.Clear(); + mimeTypes.Add(s); + return TRUE; + } + else + return FALSE; +} + +bool wxFileTypeImpl::GetIcon(wxIcon *icon) const +{ + // no such file type or no value or incorrect icon entry + return FALSE; +} + +bool wxFileTypeImpl::GetDescription(wxString *desc) const +{ + return FALSE; +} + +// extension -> file type +wxFileType * +wxMimeTypesManagerImpl::GetFileTypeFromExtension(const wxString& e) +{ + wxString ext = e ; + ext = ext.Lower() ; + if ( ext == "txt" ) + { + wxFileType *fileType = new wxFileType; + fileType->m_impl->SetFileType("text/text"); + fileType->m_impl->SetExt(ext); + return fileType; + } + else if ( ext == "htm" || ext == "html" ) + { + wxFileType *fileType = new wxFileType; + fileType->m_impl->SetFileType("text/html"); + fileType->m_impl->SetExt(ext); + return fileType; + } + else if ( ext == "gif" ) + { + wxFileType *fileType = new wxFileType; + fileType->m_impl->SetFileType("image/gif"); + fileType->m_impl->SetExt(ext); + return fileType; + } + else if ( ext == "png" ) + { + wxFileType *fileType = new wxFileType; + fileType->m_impl->SetFileType("image/png"); + fileType->m_impl->SetExt(ext); + return fileType; + } + else if ( ext == "jpg" || ext == "jpeg" ) + { + wxFileType *fileType = new wxFileType; + fileType->m_impl->SetFileType("image/jpeg"); + fileType->m_impl->SetExt(ext); + return fileType; + } + else if ( ext == "bmp" ) + { + wxFileType *fileType = new wxFileType; + fileType->m_impl->SetFileType("image/bmp"); + fileType->m_impl->SetExt(ext); + return fileType; + } + else if ( ext == "tif" || ext == "tiff" ) + { + wxFileType *fileType = new wxFileType; + fileType->m_impl->SetFileType("image/tiff"); + fileType->m_impl->SetExt(ext); + return fileType; + } + else if ( ext == "xpm" ) + { + wxFileType *fileType = new wxFileType; + fileType->m_impl->SetFileType("image/xpm"); + fileType->m_impl->SetExt(ext); + return fileType; + } + else if ( ext == "xbm" ) + { + wxFileType *fileType = new wxFileType; + fileType->m_impl->SetFileType("image/xbm"); + fileType->m_impl->SetExt(ext); + return fileType; + } + + // unknown extension + return NULL; +} + +// MIME type -> extension -> file type +wxFileType * +wxMimeTypesManagerImpl::GetFileTypeFromMimeType(const wxString& mimeType) +{ + return NULL; +} + +size_t wxMimeTypesManagerImpl::EnumAllFileTypes(wxArrayString& mimetypes) +{ + wxFAIL_MSG( _T("TODO") ); // VZ: don't know anything about this for Mac + + return 0; +} + diff --git a/src/mac/mimetype.cpp b/src/mac/mimetype.cpp deleted file mode 100644 index 77e60cbc20..0000000000 --- a/src/mac/mimetype.cpp +++ /dev/null @@ -1,188 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: mac/mimetype.cpp -// Purpose: classes and functions to manage MIME types -// Author: Vadim Zeitlin -// Modified by: -// Created: 23.09.98 -// RCS-ID: $Id$ -// Copyright: (c) 1998 Vadim Zeitlin -// Licence: wxWindows license (part of wxExtra library) -///////////////////////////////////////////////////////////////////////////// - -#ifdef __GNUG__ -#pragma implementation "mimetype.h" -#endif - -// for compilers that support precompilation, includes "wx.h". -#include "wx/wxprec.h" - -#ifdef __BORLANDC__ - #pragma hdrstop -#endif - -#ifndef WX_PRECOMP - #include "wx/defs.h" -#endif - -#ifndef WX_PRECOMP - #include "wx/string.h" - #if wxUSE_GUI - #include "wx/icon.h" - #endif -#endif //WX_PRECOMP - - -#include "wx/log.h" -#include "wx/file.h" -#include "wx/intl.h" -#include "wx/dynarray.h" -#include "wx/confbase.h" - -#include "wx/mac/mimetype.h" - -// other standard headers -#include - -// in case we're compiling in non-GUI mode -class WXDLLEXPORT wxIcon; - - - - - - -bool wxFileTypeImpl::GetCommand(wxString *command, const char *verb) const -{ - return FALSE; -} - -// @@ this function is half implemented -bool wxFileTypeImpl::GetExtensions(wxArrayString& extensions) -{ - return FALSE; -} - -bool wxFileTypeImpl::GetMimeType(wxString *mimeType) const -{ - if ( m_strFileType.Length() > 0 ) - { - *mimeType = m_strFileType ; - return TRUE ; - } - else - return FALSE; -} - -bool wxFileTypeImpl::GetMimeTypes(wxArrayString& mimeTypes) const -{ - wxString s; - - if (GetMimeType(&s)) - { - mimeTypes.Clear(); - mimeTypes.Add(s); - return TRUE; - } - else - return FALSE; -} - -bool wxFileTypeImpl::GetIcon(wxIcon *icon) const -{ - // no such file type or no value or incorrect icon entry - return FALSE; -} - -bool wxFileTypeImpl::GetDescription(wxString *desc) const -{ - return FALSE; -} - -// extension -> file type -wxFileType * -wxMimeTypesManagerImpl::GetFileTypeFromExtension(const wxString& e) -{ - wxString ext = e ; - ext = ext.Lower() ; - if ( ext == "txt" ) - { - wxFileType *fileType = new wxFileType; - fileType->m_impl->SetFileType("text/text"); - fileType->m_impl->SetExt(ext); - return fileType; - } - else if ( ext == "htm" || ext == "html" ) - { - wxFileType *fileType = new wxFileType; - fileType->m_impl->SetFileType("text/html"); - fileType->m_impl->SetExt(ext); - return fileType; - } - else if ( ext == "gif" ) - { - wxFileType *fileType = new wxFileType; - fileType->m_impl->SetFileType("image/gif"); - fileType->m_impl->SetExt(ext); - return fileType; - } - else if ( ext == "png" ) - { - wxFileType *fileType = new wxFileType; - fileType->m_impl->SetFileType("image/png"); - fileType->m_impl->SetExt(ext); - return fileType; - } - else if ( ext == "jpg" || ext == "jpeg" ) - { - wxFileType *fileType = new wxFileType; - fileType->m_impl->SetFileType("image/jpeg"); - fileType->m_impl->SetExt(ext); - return fileType; - } - else if ( ext == "bmp" ) - { - wxFileType *fileType = new wxFileType; - fileType->m_impl->SetFileType("image/bmp"); - fileType->m_impl->SetExt(ext); - return fileType; - } - else if ( ext == "tif" || ext == "tiff" ) - { - wxFileType *fileType = new wxFileType; - fileType->m_impl->SetFileType("image/tiff"); - fileType->m_impl->SetExt(ext); - return fileType; - } - else if ( ext == "xpm" ) - { - wxFileType *fileType = new wxFileType; - fileType->m_impl->SetFileType("image/xpm"); - fileType->m_impl->SetExt(ext); - return fileType; - } - else if ( ext == "xbm" ) - { - wxFileType *fileType = new wxFileType; - fileType->m_impl->SetFileType("image/xbm"); - fileType->m_impl->SetExt(ext); - return fileType; - } - - // unknown extension - return NULL; -} - -// MIME type -> extension -> file type -wxFileType * -wxMimeTypesManagerImpl::GetFileTypeFromMimeType(const wxString& mimeType) -{ - return NULL; -} - -size_t wxMimeTypesManagerImpl::EnumAllFileTypes(wxArrayString& mimetypes) -{ - wxFAIL_MSG( _T("TODO") ); // VZ: don't know anything about this for Mac - - return 0; -} - diff --git a/src/mac/pnghand.cpp b/src/mac/pnghand.cpp index 6134439271..af7b3a6f99 100644 --- a/src/mac/pnghand.cpp +++ b/src/mac/pnghand.cpp @@ -414,7 +414,11 @@ bool wxPNGReader::ReadFile(char * ImageFileName) wxPNGReaderIter iter(this); /* open the file */ +#ifndef __UNIX__ fp = fopen(wxUnix2MacFilename( ImageFileName ), "rb"); +#else + fp = fopen( ImageFileName , "rb" ); +#endif if (!fp) return FALSE; diff --git a/src/mac/statusbr.cpp b/src/mac/statusbr.cpp index 5b52c76ac0..4ff42994c0 100644 --- a/src/mac/statusbr.cpp +++ b/src/mac/statusbr.cpp @@ -17,12 +17,13 @@ // headers // ---------------------------------------------------------------------------- -#include "wx/mac/statusbr.h" +#include "wx/defs.h" +#include "wx/statusbr.h" -IMPLEMENT_DYNAMIC_CLASS(wxStatusBarXX, wxStatusBar); +IMPLEMENT_DYNAMIC_CLASS(wxStatusBarMac, wxStatusBar); -BEGIN_EVENT_TABLE(wxStatusBarXX, wxStatusBar) - EVT_SIZE(wxStatusBarXX::OnSize) +BEGIN_EVENT_TABLE(wxStatusBarMac, wxStatusBar) + EVT_SIZE(wxStatusBarMac::OnSize) END_EVENT_TABLE() @@ -31,20 +32,15 @@ END_EVENT_TABLE() // ============================================================================ // ---------------------------------------------------------------------------- -// wxStatusBarXX class +// wxStatusBarMac class // ---------------------------------------------------------------------------- -wxStatusBarXX::wxStatusBarXX() +wxStatusBarMac::wxStatusBarMac() { SetParent(NULL); } -wxStatusBarXX::wxStatusBarXX(wxWindow *parent, wxWindowID id, long style) -{ - Create(parent, id, style); -} - -bool wxStatusBarXX::Create(wxWindow *parent, wxWindowID id, long style) +bool wxStatusBarMac::Create(wxWindow *parent, wxWindowID id, long style, const wxString& name = wxPanelNameStr) { SetParent(parent); @@ -57,7 +53,7 @@ bool wxStatusBarXX::Create(wxWindow *parent, wxWindowID id, long style) return FALSE; } -void wxStatusBarXX::SetFieldsCount(int nFields, const int widths[]) +void wxStatusBarMac::SetFieldsCount(int nFields, const int widths[]) { wxASSERT( (nFields > 0) && (nFields < 255) ); @@ -67,7 +63,7 @@ void wxStatusBarXX::SetFieldsCount(int nFields, const int widths[]) SetFieldsWidth(); } -void wxStatusBarXX::SetStatusWidths(int n, const int widths[]) +void wxStatusBarMac::SetStatusWidths(int n, const int widths[]) { wxASSERT( n == m_nFields ); @@ -75,7 +71,7 @@ void wxStatusBarXX::SetStatusWidths(int n, const int widths[]) SetFieldsWidth(); } -void wxStatusBarXX::CopyFieldsWidth(const int widths[]) +void wxStatusBarMac::CopyFieldsWidth(const int widths[]) { if (widths && !m_statusWidths) m_statusWidths = new int[m_nFields]; @@ -90,7 +86,7 @@ void wxStatusBarXX::CopyFieldsWidth(const int widths[]) } } -void wxStatusBarXX::SetFieldsWidth() +void wxStatusBarMac::SetFieldsWidth() { int *pWidths = new int[m_nFields]; @@ -140,12 +136,12 @@ void wxStatusBarXX::SetFieldsWidth() delete [] pWidths; } -void wxStatusBarXX::SetStatusText(const wxString& strText, int nField) +void wxStatusBarMac::SetStatusText(const wxString& strText, int nField) { // TODO } -wxString wxStatusBarXX::GetStatusText(int nField) const +wxString wxStatusBarMac::GetStatusText(int nField) const { wxASSERT( (nField > -1) && (nField < m_nFields) ); @@ -153,7 +149,7 @@ wxString wxStatusBarXX::GetStatusText(int nField) const return wxString(""); } -void wxStatusBarXX::OnSize(wxSizeEvent& event) +void wxStatusBarMac::OnSize(wxSizeEvent& event) { // adjust fields widths to the new size SetFieldsWidth(); diff --git a/src/mac/textctrl.cpp b/src/mac/textctrl.cpp index 7e1450068d..0a51bb757e 100644 --- a/src/mac/textctrl.cpp +++ b/src/mac/textctrl.cpp @@ -22,6 +22,7 @@ #include #include "wx/app.h" +#include "wx/dc.h" #include "wx/button.h" #include "wx/panel.h" #include "wx/textctrl.h" diff --git a/src/mac/tooltip.cpp b/src/mac/tooltip.cpp index 5974c8808e..eb92ed996e 100644 --- a/src/mac/tooltip.cpp +++ b/src/mac/tooltip.cpp @@ -16,6 +16,7 @@ #if wxUSE_TOOLTIPS #include "wx/app.h" +#include "wx/dc.h" #include "wx/window.h" #include "wx/tooltip.h" #include "wx/timer.h" diff --git a/src/mac/uma.cpp b/src/mac/uma.cpp index f34db6bc39..13d4e27883 100644 --- a/src/mac/uma.cpp +++ b/src/mac/uma.cpp @@ -1,9 +1,10 @@ #include "wx/defs.h" +#include "wx/dc.h" #include "wx/mac/uma.h" #include "wx/mac/aga.h" #ifdef __UNIX__ - #include + #include #else #include #endif diff --git a/src/mac/utils.cpp b/src/mac/utils.cpp index 5d1e9faf41..6723ed2ad4 100644 --- a/src/mac/utils.cpp +++ b/src/mac/utils.cpp @@ -260,6 +260,7 @@ bool wxIsBusy() return (wxBusyCursorCount > 0); } +#ifndef __UNIX__ wxString wxMacFindFolder( short vol, OSType folderType, Boolean createFolder) @@ -278,6 +279,7 @@ wxString wxMacFindFolder( short vol, } return strDir ; } +#endif #ifndef __UNIX__ char *wxGetUserHome (const wxString& user) @@ -343,6 +345,11 @@ void wxDisplaySize(int *width, int *height) #endif } +void wxDisplaySizeMM(int *width, int *height) +{ + wxDisplaySize(width, height); +} + wxWindow* wxFindWindowAtPoint(const wxPoint& pt) { return wxGenericFindWindowAtPoint(pt); diff --git a/src/mac/utilsexc.cpp b/src/mac/utilsexc.cpp index b842d08e90..624a9c0524 100644 --- a/src/mac/utilsexc.cpp +++ b/src/mac/utilsexc.cpp @@ -14,11 +14,15 @@ #endif #include "wx/utils.h" +#ifdef __UNIX__ +#include "wx/unix/execute.h" +#endif #include #include #include +#ifndef __UNIX__ #define wxEXECUTE_WIN_MESSAGE 10000 long wxExecute(const wxString& command, bool sync, wxProcess *handler) @@ -26,3 +30,12 @@ long wxExecute(const wxString& command, bool sync, wxProcess *handler) // TODO return 0; } +#endif + +#ifdef __UNIX__ +int wxAddProcessCallback(wxEndProcessData *proc_data, int fd) +{ + wxFAIL_MSG(wxT("wxAddProcessCallback() function not ready")); + return 0; +} +#endif \ No newline at end of file diff --git a/src/mac/wave.cpp b/src/mac/wave.cpp index ac2dcac7e0..f0891a6546 100644 --- a/src/mac/wave.cpp +++ b/src/mac/wave.cpp @@ -126,14 +126,18 @@ bool wxWave::Play(bool async, bool looped) const if (m_isResource) { - strcpy(lpSnd, m_sndname); - c2pstr((char *) lpSnd); - SndListHandle hSnd; - - hSnd = (SndListHandle) GetNamedResource('snd ',(const unsigned char *) lpSnd); +#if TARGET_CARBON + c2pstrcpy((unsigned char *)lpSnd, m_sndname); +#else + strcpy(lpSnd, m_sndname); + c2pstr((char *) lpSnd); +#endif + SndListHandle hSnd; + + hSnd = (SndListHandle) GetNamedResource('snd ',(const unsigned char *) lpSnd); - if ((hSnd != NULL) && (SndPlay(m_sndChan, hSnd, async) == noErr)) - ret = true; + if ((hSnd != NULL) && (SndPlay(m_sndChan, hSnd, async) == noErr)) + ret = true; } return ret; diff --git a/src/mac/window.cpp b/src/mac/window.cpp index f3ba668abe..382b71024f 100644 --- a/src/mac/window.cpp +++ b/src/mac/window.cpp @@ -15,6 +15,7 @@ #include "wx/setup.h" #include "wx/menu.h" +#include "wx/window.h" #include "wx/dc.h" #include "wx/dcclient.h" #include "wx/utils.h" @@ -33,9 +34,6 @@ #include "wx/tabctrl.h" #include "wx/tooltip.h" #include "wx/statusbr.h" -// TODO remove the line below, just for lookup-up convenience CS -#include "wx/window.h" - #include "wx/menuitem.h" #include "wx/log.h" @@ -763,6 +761,11 @@ void wxWindow::MacSuperShown( bool show ) bool wxWindow::MacIsReallyShown() const { + if ( m_isShown && (m_parent != NULL) ) { + return m_parent->MacIsReallyShown(); + } + return m_isShown; +/* bool status = m_isShown ; wxWindow * win = this ; while ( status && win->m_parent != NULL ) @@ -771,6 +774,7 @@ bool wxWindow::MacIsReallyShown() const status = win->m_isShown ; } return status ; +*/ } int wxWindow::GetCharHeight() const @@ -794,7 +798,7 @@ void wxWindow::GetTextExtent(const wxString& string, int *x, int *y, wxClientDC dc( (wxWindow*) this ) ; long lx,ly,ld,le ; - dc.GetTextExtent( string , &lx , &ly , &ld, &le, fontToUse ) ; + dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ; if ( externalLeading ) *externalLeading = le ; if ( descent ) @@ -2306,7 +2310,37 @@ long wxWindow::MacRemoveBordersFromStyle( long style ) { return style & ~( wxDOUBLE_BORDER | wxSUNKEN_BORDER | wxRAISED_BORDER | wxBORDER | wxSTATIC_BORDER ) ; } - +/* +wxMacFocusHelper::wxMacFocusHelper( wxWindow * theWindow ) +{ + m_ok = false ; + Point localOrigin ; + Rect clipRect ; + WindowRef window ; + wxWindow *rootwin ; + m_currentPort = NULL ; + GetPort( &m_formerPort ) ; + if ( theWindow ) + { + + theWindow->MacGetPortParams( &localOrigin , &clipRect , &window , &rootwin) ; + m_currentPort = UMAGetWindowPort( window ) ; + theWindow->MacSetPortFocusParams( localOrigin, clipRect, window , rootwin ) ; + m_ok = true ; + } +} + +wxMacFocusHelper::~wxMacFocusHelper() +{ + if ( m_ok ) + { + SetPort( m_currentPort ) ; + SetOrigin( 0 , 0 ) ; + } + if ( m_formerPort != m_currentPort ) + SetPort( m_formerPort ) ; +} +*/ wxMacDrawingHelper::wxMacDrawingHelper( wxWindow * theWindow ) { diff --git a/src/mac/xpm/Image.c b/src/mac/xpm/Image.c deleted file mode 100644 index 0753622186..0000000000 --- a/src/mac/xpm/Image.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 1989-95 GROUPE BULL - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * GROUPE BULL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Except as contained in this notice, the name of GROUPE BULL shall not be - * used in advertising or otherwise to promote the sale, use or other dealings - * in this Software without prior written authorization from GROUPE BULL. - */ - -/*****************************************************************************\ -* Image.c: * -* * -* XPM library * -* Functions to init and free the XpmImage structure. * -* * -* Developed by Arnaud Le Hors * -\*****************************************************************************/ - -#include "XpmI.h" - -/* - * Init returned data to free safely later on - */ -void -xpmInitXpmImage(image) - XpmImage *image; -{ - image->ncolors = 0; - image->colorTable = NULL; - image->data = NULL; -} - -/* - * Free the XpmImage data which have been allocated - */ -void -XpmFreeXpmImage(image) - XpmImage *image; -{ - if (image->colorTable) - xpmFreeColorTable(image->colorTable, image->ncolors); - if (image->data) - XpmFree(image->data); - image->data = NULL; -} diff --git a/src/mac/xpm/RdFToBuf.c b/src/mac/xpm/RdFToBuf.c index abab09c787..ae939ae8ac 100644 --- a/src/mac/xpm/RdFToBuf.c +++ b/src/mac/xpm/RdFToBuf.c @@ -40,10 +40,6 @@ #include "wx/setup.h" #ifdef macintosh - #ifdef __std - #undef __std - #define __std() - #endif #include #include #include diff --git a/src/mac/xpm/RdFToI.c b/src/mac/xpm/RdFToI.c index 3339bbdde0..c022fdef55 100644 --- a/src/mac/xpm/RdFToI.c +++ b/src/mac/xpm/RdFToI.c @@ -35,10 +35,6 @@ #include "wx/setup.h" #ifdef macintosh - #ifdef __std - #undef __std - #define __std() - #endif #include #include #include diff --git a/src/mac/xpm/data.c b/src/mac/xpm/data.c deleted file mode 100644 index cba30633ab..0000000000 --- a/src/mac/xpm/data.c +++ /dev/null @@ -1,487 +0,0 @@ -/* - * Copyright (C) 1989-95 GROUPE BULL - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * GROUPE BULL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Except as contained in this notice, the name of GROUPE BULL shall not be - * used in advertising or otherwise to promote the sale, use or other dealings - * in this Software without prior written authorization from GROUPE BULL. - */ - -/*****************************************************************************\ -* data.c: * -* * -* XPM library * -* IO utilities * -* * -* Developed by Arnaud Le Hors * -\*****************************************************************************/ - -#ifndef CXPMPROG -/* Official version number */ -static char *RCS_Version = "$XpmVersion: 3.4k $"; - -/* Internal version number */ -static char *RCS_Id = "$Id$"; - -#include "XpmI.h" -#endif -#include - -#ifndef CXPMPROG -#define Getc(data, file) getc(file) -#define Ungetc(data, c, file) ungetc(c, file) -#endif - -static int -ParseComment(data) - xpmData *data; -{ - if (data->type == XPMBUFFER) { - register char c; - register unsigned int n = 0; - unsigned int notend; - char *s, *s2; - - s = data->Comment; - *s = data->Bcmt[0]; - - /* skip the string beginning comment */ - s2 = data->Bcmt; - do { - c = *data->cptr++; - *++s = c; - n++; - s2++; - } while (c == *s2 && *s2 != '\0' && c); - - if (*s2 != '\0') { - /* this wasn't the beginning of a comment */ - data->cptr -= n; - return 0; - } - /* store comment */ - data->Comment[0] = *s; - s = data->Comment; - notend = 1; - n = 0; - while (notend) { - s2 = data->Ecmt; - while (*s != *s2 && c) { - c = *data->cptr++; - if (n == XPMMAXCMTLEN - 1) { /* forget it */ - s = data->Comment; - n = 0; - } - *++s = c; - n++; - } - data->CommentLength = n; - do { - c = *data->cptr++; - if (n == XPMMAXCMTLEN - 1) { /* forget it */ - s = data->Comment; - n = 0; - } - *++s = c; - n++; - s2++; - } while (c == *s2 && *s2 != '\0' && c); - if (*s2 == '\0') { - /* this is the end of the comment */ - notend = 0; - data->cptr--; - } - } - return 0; - } else { - FILE *file = data->stream.file; - register int c; - register unsigned int n = 0, a; - unsigned int notend; - char *s, *s2; - - s = data->Comment; - *s = data->Bcmt[0]; - - /* skip the string beginning comment */ - s2 = data->Bcmt; - do { - c = Getc(data, file); - *++s = c; - n++; - s2++; - } while (c == *s2 && *s2 != '\0' && c != EOF); - - if (*s2 != '\0') { - /* this wasn't the beginning of a comment */ - /* put characters back in the order that we got them */ - for (a = n; a > 0; a--, s--) - Ungetc(data, *s, file); - return 0; - } - /* store comment */ - data->Comment[0] = *s; - s = data->Comment; - notend = 1; - n = 0; - while (notend) { - s2 = data->Ecmt; - while (*s != *s2 && c != EOF) { - c = Getc(data, file); - if (n == XPMMAXCMTLEN - 1) { /* forget it */ - s = data->Comment; - n = 0; - } - *++s = c; - n++; - } - data->CommentLength = n; - do { - c = Getc(data, file); - if (n == XPMMAXCMTLEN - 1) { /* forget it */ - s = data->Comment; - n = 0; - } - *++s = c; - n++; - s2++; - } while (c == *s2 && *s2 != '\0' && c != EOF); - if (*s2 == '\0') { - /* this is the end of the comment */ - notend = 0; - Ungetc(data, *s, file); - } - } - return 0; - } -} - -/* - * skip to the end of the current string and the beginning of the next one - */ -int -xpmNextString(data) - xpmData *data; -{ - if (!data->type) - data->cptr = (data->stream.data)[++data->line]; - else if (data->type == XPMBUFFER) { - register char c; - - /* get to the end of the current string */ - if (data->Eos) - while ((c = *data->cptr++)!=NULL && c != data->Eos) - {} - - /* - * then get to the beginning of the next string looking for possible - * comment - */ - if (data->Bos) { - while ((c = *data->cptr++)!=NULL && c != data->Bos) - if (data->Bcmt && c == data->Bcmt[0]) - ParseComment(data); - } else if (data->Bcmt) { /* XPM2 natural */ - while ((c = *data->cptr++) == data->Bcmt[0]) - ParseComment(data); - data->cptr--; - } - } else { - register int c; - FILE *file = data->stream.file; - - /* get to the end of the current string */ - if (data->Eos) - while ((c = Getc(data, file))!=NULL != data->Eos && c != EOF) - {} - - /* - * then get to the beginning of the next string looking for possible - * comment - */ - if (data->Bos) { - while ((c = Getc(data, file)) != data->Bos && c != EOF) - if (data->Bcmt && c == data->Bcmt[0]) - ParseComment(data); - - } else if (data->Bcmt) { /* XPM2 natural */ - while ((c = Getc(data, file)) == data->Bcmt[0]) - ParseComment(data); - Ungetc(data, c, file); - } - } - return 0; -} - - -/* - * skip whitespace and return the following word - */ -unsigned int -xpmNextWord(data, buf, buflen) - xpmData *data; - char *buf; - unsigned int buflen; -{ - register unsigned int n = 0; - int c; - - if (!data->type || data->type == XPMBUFFER) { - while (isspace(c = *data->cptr) && c != data->Eos) - data->cptr++; - do { - c = *data->cptr++; - *buf++ = c; - n++; - } while (!isspace(c) && c != data->Eos && n < buflen); - n--; - data->cptr--; - } else { - FILE *file = data->stream.file; - - while ((c = Getc(data, file)) != EOF && isspace(c) && c != data->Eos) - { - } - while (!isspace(c) && c != data->Eos && c != EOF && n < buflen) { - *buf++ = c; - n++; - c = Getc(data, file); - } - Ungetc(data, c, file); - } - return (n); -} - -/* - * skip whitespace and compute the following unsigned int, - * returns 1 if one is found and 0 if not - */ -int -xpmNextUI(data, ui_return) - xpmData *data; - unsigned int *ui_return; -{ - char buf[BUFSIZ]; - int l; - - l = xpmNextWord(data, buf, BUFSIZ); - return xpmatoui(buf, l, ui_return); -} - -/* - * return end of string - WARNING: malloc! - */ -int -xpmGetString(data, sptr, l) - xpmData *data; - char **sptr; - unsigned int *l; -{ - unsigned int i, n = 0; - int c; - char *p = NULL, *q, buf[BUFSIZ]; - - if (!data->type || data->type == XPMBUFFER) { - if (data->cptr) { - char *start = data->cptr; - while ((c = *data->cptr)!=NULL && c != data->Eos) - data->cptr++; - n = data->cptr - start + 1; - p = (char *) XpmMalloc(n); - if (!p) - return (XpmNoMemory); - strncpy(p, start, n); - if (data->type) /* XPMBUFFER */ - p[n - 1] = '\0'; - } - } else { - FILE *file = data->stream.file; - - if ((c = Getc(data, file)) == EOF) - return (XpmFileInvalid); - - i = 0; - q = buf; - p = (char *) XpmMalloc(1); - while (c != data->Eos && c != EOF) { - if (i == BUFSIZ) { - /* get to the end of the buffer */ - /* malloc needed memory */ - q = (char *) XpmRealloc(p, n + i); - if (!q) { - XpmFree(p); - return (XpmNoMemory); - } - p = q; - q += n; - /* and copy what we already have */ - strncpy(q, buf, i); - n += i; - i = 0; - q = buf; - } - *q++ = c; - i++; - c = Getc(data, file); - } - if (c == EOF) { - XpmFree(p); - return (XpmFileInvalid); - } - if (n + i != 0) { - /* malloc needed memory */ - q = (char *) XpmRealloc(p, n + i + 1); - if (!q) { - XpmFree(p); - return (XpmNoMemory); - } - p = q; - q += n; - /* and copy the buffer */ - strncpy(q, buf, i); - n += i; - p[n++] = '\0'; - } else { - *p = '\0'; - n = 1; - } - Ungetc(data, c, file); - } - *sptr = p; - *l = n; - return (XpmSuccess); -} - -/* - * get the current comment line - */ -int -xpmGetCmt(data, cmt) - xpmData *data; - char **cmt; -{ - if (!data->type) - *cmt = NULL; - else if (data->CommentLength) { - *cmt = (char *) XpmMalloc(data->CommentLength + 1); - strncpy(*cmt, data->Comment, data->CommentLength); - (*cmt)[data->CommentLength] = '\0'; - data->CommentLength = 0; - } else - *cmt = NULL; - return 0; -} - -xpmDataType xpmDataTypes[] = -{ - "", "!", "\n", '\0', '\n', "", "", "", "", /* Natural type */ - "C", "/*", "*/", '"', '"', ",\n", "static char *", "[] = {\n", "};\n", - "Lisp", ";", "\n", '"', '"', "\n", "(setq ", " '(\n", "))\n", -#ifdef VMS - NULL -#else - NULL, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL -#endif -}; - -/* - * parse xpm header - */ -int -xpmParseHeader(data) - xpmData *data; -{ - char buf[BUFSIZ]; - int l, n = 0; - - if (data->type) { - data->Bos = '\0'; - data->Eos = '\n'; - data->Bcmt = data->Ecmt = NULL; - l = xpmNextWord(data, buf, BUFSIZ); - if (l == 7 && !strncmp("#define", buf, 7)) { - /* this maybe an XPM 1 file */ - char *ptr; - - l = xpmNextWord(data, buf, BUFSIZ); - if (!l) - return (XpmFileInvalid); - buf[l] = '\0'; - #if defined(macintosh) || defined(__APPLE__) - ptr = strrchr(buf, '_'); - #else - ptr = rindex(buf, '_'); - #endif - if (!ptr || strncmp("_format", ptr, l - (ptr - buf))) - return XpmFileInvalid; - /* this is definitely an XPM 1 file */ - data->format = 1; - n = 1; /* handle XPM1 as mainly XPM2 C */ - } else { - - /* - * skip the first word, get the second one, and see if this is - * XPM 2 or 3 - */ - l = xpmNextWord(data, buf, BUFSIZ); - if ((l == 3 && !strncmp("XPM", buf, 3)) || - (l == 4 && !strncmp("XPM2", buf, 4))) { - if (l == 3) - n = 1; /* handle XPM as XPM2 C */ - else { - /* get the type key word */ - l = xpmNextWord(data, buf, BUFSIZ); - - /* - * get infos about this type - */ - while (xpmDataTypes[n].type - && strncmp(xpmDataTypes[n].type, buf, l)) - n++; - } - data->format = 0; - } else - /* nope this is not an XPM file */ - return XpmFileInvalid; - } - if (xpmDataTypes[n].type) { - if (n == 0) { /* natural type */ - data->Bcmt = xpmDataTypes[n].Bcmt; - data->Ecmt = xpmDataTypes[n].Ecmt; - xpmNextString(data); /* skip the end of the headerline */ - data->Bos = xpmDataTypes[n].Bos; - data->Eos = xpmDataTypes[n].Eos; - } else { - data->Bcmt = xpmDataTypes[n].Bcmt; - data->Ecmt = xpmDataTypes[n].Ecmt; - if (!data->format) { /* XPM 2 or 3 */ - data->Bos = xpmDataTypes[n].Bos; - data->Eos = '\0'; - /* get to the beginning of the first string */ - xpmNextString(data); - data->Eos = xpmDataTypes[n].Eos; - } else /* XPM 1 skip end of line */ - xpmNextString(data); - } - } else - /* we don't know about that type of XPM file... */ - return XpmFileInvalid; - } - return XpmSuccess; -} diff --git a/src/mac/xpm/imagexpm.c b/src/mac/xpm/imagexpm.c new file mode 100644 index 0000000000..0753622186 --- /dev/null +++ b/src/mac/xpm/imagexpm.c @@ -0,0 +1,61 @@ +/* + * Copyright (C) 1989-95 GROUPE BULL + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * GROUPE BULL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of GROUPE BULL shall not be + * used in advertising or otherwise to promote the sale, use or other dealings + * in this Software without prior written authorization from GROUPE BULL. + */ + +/*****************************************************************************\ +* Image.c: * +* * +* XPM library * +* Functions to init and free the XpmImage structure. * +* * +* Developed by Arnaud Le Hors * +\*****************************************************************************/ + +#include "XpmI.h" + +/* + * Init returned data to free safely later on + */ +void +xpmInitXpmImage(image) + XpmImage *image; +{ + image->ncolors = 0; + image->colorTable = NULL; + image->data = NULL; +} + +/* + * Free the XpmImage data which have been allocated + */ +void +XpmFreeXpmImage(image) + XpmImage *image; +{ + if (image->colorTable) + xpmFreeColorTable(image->colorTable, image->ncolors); + if (image->data) + XpmFree(image->data); + image->data = NULL; +} diff --git a/src/makemac.mcp b/src/makemac.mcp index 16c906da85..306c886a24 100644 Binary files a/src/makemac.mcp and b/src/makemac.mcp differ diff --git a/src/unix/dialup.cpp b/src/unix/dialup.cpp index 54797d807c..0b7c075c8c 100644 --- a/src/unix/dialup.cpp +++ b/src/unix/dialup.cpp @@ -680,7 +680,7 @@ wxDialUpManagerImpl::CheckIfconfig() cmd << " -a"; #elif defined(__LINUX__) || defined(__SGI__) // nothing to be added to ifconfig -#elif defined(__FREEBSD__) +#elif defined(__FREEBSD__) || defined(__WXMAC__) // add -l flag cmd << " -l"; #elif defined(__HPUX__) @@ -775,7 +775,7 @@ wxDialUpManagerImpl::NetConnection wxDialUpManagerImpl::CheckPing() cmd << m_PingPath << ' '; #if defined(__SOLARIS__) || defined (__SUNOS__) // nothing to add to ping command -#elif defined(__LINUX__) || defined ( __FREEBSD__) +#elif defined(__LINUX__) || defined ( __FREEBSD__) || defined(__WXMAC__) cmd << "-c 1 "; // only ping once #elif defined(__HPUX__) cmd << "64 1 "; // only ping once (need also specify the packet size)