From b5df4fc722412fe5f6764c490925b26293c5f662 Mon Sep 17 00:00:00 2001 From: David Elliott Date: Tue, 27 Jan 2004 06:01:34 +0000 Subject: [PATCH] wxCocoa: Better icon support git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25400 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- Makefile.in | 13 ++-- build/bakefiles/files.bkl | 2 +- include/wx/cocoa/bitmap.h | 3 + include/wx/cocoa/icon.h | 100 ++++++++++++------------ src/cocoa/icon.cpp | 65 ---------------- src/cocoa/icon.mm | 156 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 220 insertions(+), 119 deletions(-) delete mode 100644 src/cocoa/icon.cpp create mode 100644 src/cocoa/icon.mm diff --git a/Makefile.in b/Makefile.in index 25803077ac..44e0c7ce06 100644 --- a/Makefile.in +++ b/Makefile.in @@ -145,7 +145,7 @@ WXJPEG_OBJECTS = \ wxjpeg_jquant1.o \ wxjpeg_jquant2.o \ wxjpeg_jdmerge.o -WXTIFF_CFLAGS = $(CPPFLAGS) $(CFLAGS) +WXTIFF_CFLAGS = $(__INC_ZLIB_p) $(__INC_JPEG_p) $(CPPFLAGS) $(CFLAGS) WXTIFF_OBJECTS = \ $(__TIFF_PLATFORM_SRC_OBJECTS) \ wxtiff_tif_aux.o \ @@ -1149,6 +1149,7 @@ COND_TOOLKIT_X11_LOWLEVEL_HDR = \ wx/x11/window.h @COND_TOOLKIT_X11@LOWLEVEL_HDR = $(COND_TOOLKIT_X11_LOWLEVEL_HDR) COND_TOOLKIT_COCOA_GUI_HDR = \ + wx/cocoa/NSApplication.h \ wx/cocoa/NSBox.h \ wx/cocoa/NSButton.h \ wx/cocoa/NSControl.h \ @@ -1195,6 +1196,7 @@ COND_TOOLKIT_COCOA_GUI_HDR = \ wx/cocoa/radiobox.h \ wx/cocoa/radiobut.h \ wx/cocoa/region.h \ + wx/cocoa/slider.h \ wx/cocoa/spinbutt.h \ wx/cocoa/statbmp.h \ wx/cocoa/statbox.h \ @@ -1205,6 +1207,7 @@ COND_TOOLKIT_COCOA_GUI_HDR = \ wx/cocoa/toplevel.h \ wx/cocoa/window.h \ wx/generic/caret.h \ + wx/generic/dirdlgg.h \ wx/generic/fdrepdlg.h \ wx/generic/fontdlgg.h \ wx/generic/imaglist.h \ @@ -8163,7 +8166,7 @@ monodll_xtixml.o: $(srcdir)/src/common/xtixml.cpp $(MONODLL_ODEP) @COND_TOOLKIT_MAC_USE_GUI_1_WXUNIV_0@monodll_icon.o: $(srcdir)/src/mac/icon.cpp $(MONODLL_ODEP) @COND_TOOLKIT_MAC_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $< -@COND_TOOLKIT_COCOA_USE_GUI_1_WXUNIV_0@monodll_icon.o: $(srcdir)/src/cocoa/icon.cpp $(MONODLL_ODEP) +@COND_TOOLKIT_COCOA_USE_GUI_1_WXUNIV_0@monodll_icon.o: $(srcdir)/src/cocoa/icon.mm $(MONODLL_ODEP) @COND_TOOLKIT_COCOA_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $< @COND_TOOLKIT_PM_USE_GUI_1_WXUNIV_0@monodll_icon.o: $(srcdir)/src/os2/icon.cpp $(MONODLL_ODEP) @@ -10767,7 +10770,7 @@ monolib_xtixml.o: $(srcdir)/src/common/xtixml.cpp $(MONOLIB_ODEP) @COND_TOOLKIT_MAC_USE_GUI_1_WXUNIV_0@monolib_icon.o: $(srcdir)/src/mac/icon.cpp $(MONOLIB_ODEP) @COND_TOOLKIT_MAC_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $< -@COND_TOOLKIT_COCOA_USE_GUI_1_WXUNIV_0@monolib_icon.o: $(srcdir)/src/cocoa/icon.cpp $(MONOLIB_ODEP) +@COND_TOOLKIT_COCOA_USE_GUI_1_WXUNIV_0@monolib_icon.o: $(srcdir)/src/cocoa/icon.mm $(MONOLIB_ODEP) @COND_TOOLKIT_COCOA_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $< @COND_TOOLKIT_PM_USE_GUI_1_WXUNIV_0@monolib_icon.o: $(srcdir)/src/os2/icon.cpp $(MONOLIB_ODEP) @@ -13635,7 +13638,7 @@ coredll_win32.o: $(srcdir)/src/univ/themes/win32.cpp $(COREDLL_ODEP) @COND_TOOLKIT_MAC_USE_GUI_1_WXUNIV_0@coredll_icon.o: $(srcdir)/src/mac/icon.cpp $(COREDLL_ODEP) @COND_TOOLKIT_MAC_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $< -@COND_TOOLKIT_COCOA_USE_GUI_1_WXUNIV_0@coredll_icon.o: $(srcdir)/src/cocoa/icon.cpp $(COREDLL_ODEP) +@COND_TOOLKIT_COCOA_USE_GUI_1_WXUNIV_0@coredll_icon.o: $(srcdir)/src/cocoa/icon.mm $(COREDLL_ODEP) @COND_TOOLKIT_COCOA_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $< @COND_TOOLKIT_PM_USE_GUI_1_WXUNIV_0@coredll_icon.o: $(srcdir)/src/os2/icon.cpp $(COREDLL_ODEP) @@ -15744,7 +15747,7 @@ corelib_win32.o: $(srcdir)/src/univ/themes/win32.cpp $(CORELIB_ODEP) @COND_TOOLKIT_MAC_USE_GUI_1_WXUNIV_0@corelib_icon.o: $(srcdir)/src/mac/icon.cpp $(CORELIB_ODEP) @COND_TOOLKIT_MAC_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $< -@COND_TOOLKIT_COCOA_USE_GUI_1_WXUNIV_0@corelib_icon.o: $(srcdir)/src/cocoa/icon.cpp $(CORELIB_ODEP) +@COND_TOOLKIT_COCOA_USE_GUI_1_WXUNIV_0@corelib_icon.o: $(srcdir)/src/cocoa/icon.mm $(CORELIB_ODEP) @COND_TOOLKIT_COCOA_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $< @COND_TOOLKIT_PM_USE_GUI_1_WXUNIV_0@corelib_icon.o: $(srcdir)/src/os2/icon.cpp $(CORELIB_ODEP) diff --git a/build/bakefiles/files.bkl b/build/bakefiles/files.bkl index 27095d1788..3f9c161b49 100644 --- a/build/bakefiles/files.bkl +++ b/build/bakefiles/files.bkl @@ -1736,7 +1736,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file! src/cocoa/frame.mm src/cocoa/gauge.mm src/cocoa/gdiobj.cpp - src/cocoa/icon.cpp + src/cocoa/icon.mm src/cocoa/listbox.mm src/cocoa/main.cpp src/cocoa/mbarman.mm diff --git a/include/wx/cocoa/bitmap.h b/include/wx/cocoa/bitmap.h index 053e85f29c..47dc498d96 100644 --- a/include/wx/cocoa/bitmap.h +++ b/include/wx/cocoa/bitmap.h @@ -86,6 +86,9 @@ public: // Convert from wxImage: wxBitmap(const wxImage& image, int depth = -1) { CreateFromImage(image, depth); } + // Convert from wxIcon + wxBitmap(const wxIcon& icon) { CopyFromIcon(icon); } + // destructor ~wxBitmap(); diff --git a/include/wx/cocoa/icon.h b/include/wx/cocoa/icon.h index 90414c8441..79178d01aa 100644 --- a/include/wx/cocoa/icon.h +++ b/include/wx/cocoa/icon.h @@ -1,62 +1,66 @@ ///////////////////////////////////////////////////////////////////////////// // Name: wx/cocoa/icon.h // Purpose: wxIcon class -// Author: AUTHOR +// Author: David Elliott // Modified by: -// Created: ??/??/98 +// Created: 2003/08/11 // RCS-ID: $Id$ -// Copyright: (c) AUTHOR +// Copyright: (c) 2003 David Elliott // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifndef _WX_ICON_H_ -#define _WX_ICON_H_ +#ifndef _WX_COCOA_ICON_H__ +#define _WX_COCOA_ICON_H__ -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) -#pragma interface "icon.h" -#endif +#include "wx/gdicmn.h" +#include "wx/gdiobj.h" -#include "wx/bitmap.h" - -// Icon -class WXDLLEXPORT wxIcon: public wxBitmap +// ======================================================================== +// wxIcon +// ======================================================================== +class WXDLLEXPORT wxIcon: public wxGDIObject { - DECLARE_DYNAMIC_CLASS(wxIcon) - + DECLARE_DYNAMIC_CLASS(wxIcon) public: - wxIcon(); - - // Copy constructors - wxIcon(const wxIcon& icon) - : wxBitmap() - { Ref(icon); } - - wxIcon(const char **data); - wxIcon(char **data); - wxIcon(const char bits[], int width , int height ); - wxIcon(const wxString& name, int flags = wxBITMAP_TYPE_ICON_RESOURCE, - int desiredWidth = -1, int desiredHeight = -1); - wxIcon(const wxIconLocation& loc) - { - LoadFile(loc.GetFileName(), wxBITMAP_TYPE_ICON); - } - ~wxIcon(); - - bool LoadFile(const wxString& name, wxBitmapType flags /* = wxBITMAP_TYPE_ICON_RESOURCE */ , - int desiredWidth /* = -1 */ , int desiredHeight = -1); - bool LoadFile(const wxString& name ,wxBitmapType flags = wxBITMAP_TYPE_ICON_RESOURCE ) - { return LoadFile( name , flags , -1 , -1 ) ; } - - wxIcon& operator=(const wxIcon& icon) - { if (this != &icon) Ref(icon); return *this; } - bool operator==(const wxIcon& icon) const { return m_refData == icon.m_refData; } - bool operator!=(const wxIcon& icon) const { return !(*this == icon); } - - // create from bitmap (which should have a mask unless it's monochrome): - // there shouldn't be any implicit bitmap -> icon conversion (i.e. no - // ctors, assignment operators...), but it's ok to have such function - void CopyFromBitmap(const wxBitmap& bmp); + wxIcon(); + + // Copy constructors + wxIcon(const wxIcon& icon) + { Ref(icon); } + + wxIcon(const char **data) { CreateFromXpm(data); } + wxIcon(char **data) { CreateFromXpm((const char**)data); } + wxIcon(const char bits[], int width , int height ); + wxIcon(const wxString& name, int flags = wxBITMAP_TYPE_ICON_RESOURCE, + int desiredWidth = -1, int desiredHeight = -1); + wxIcon(const wxIconLocation& loc) + { + LoadFile(loc.GetFileName(), wxBITMAP_TYPE_ICON); + } + ~wxIcon(); + + bool LoadFile(const wxString& name, wxBitmapType flags /* = wxBITMAP_TYPE_ICON_RESOURCE */ , + int desiredWidth /* = -1 */ , int desiredHeight = -1); + bool LoadFile(const wxString& name, wxBitmapType flags = wxBITMAP_TYPE_ICON_RESOURCE ) + { return LoadFile( name , flags , -1 , -1 ) ; } + + wxIcon& operator=(const wxIcon& icon) + { if (this != &icon) Ref(icon); return *this; } + bool operator==(const wxIcon& icon) const + { return m_refData == icon.m_refData; } + bool operator!=(const wxIcon& icon) const { return !(*this == icon); } + + // create from bitmap (which should have a mask unless it's monochrome): + // there shouldn't be any implicit bitmap -> icon conversion (i.e. no + // ctors, assignment operators...), but it's ok to have such function + void CopyFromBitmap(const wxBitmap& bmp); + + bool Ok() const; + int GetWidth() const; + int GetHeight() const; + + WX_NSImage GetNSImage() const; + bool CreateFromXpm(const char **bits); }; -#endif - // _WX_ICON_H_ +#endif // _WX_COCOA_ICON_H__ diff --git a/src/cocoa/icon.cpp b/src/cocoa/icon.cpp deleted file mode 100644 index f473c7b275..0000000000 --- a/src/cocoa/icon.cpp +++ /dev/null @@ -1,65 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: icon.cpp -// Purpose: wxIcon class -// Author: AUTHOR -// Modified by: -// Created: ??/??/98 -// RCS-ID: $Id$ -// Copyright: (c) AUTHOR -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifdef __GNUG__ -#pragma implementation "icon.h" -#endif - -#include "wx/icon.h" - -#if !USE_SHARED_LIBRARIES -IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxBitmap) -#endif - -/* - * Icons - */ - - -wxIcon::wxIcon() -{ -} - -wxIcon::wxIcon(const char **xpm) -{ -} - -wxIcon::wxIcon(char **xpm) -{ -} - -wxIcon::wxIcon(const char WXUNUSED(bits)[], int WXUNUSED(width), int WXUNUSED(height)) -{ -} - -wxIcon::wxIcon(const wxString& icon_file, int flags, - int desiredWidth, int desiredHeight) - -{ - LoadFile(icon_file, (wxBitmapType)flags, desiredWidth, desiredHeight); -} - -wxIcon::~wxIcon() -{ -} - -bool wxIcon::LoadFile(const wxString& filename, wxBitmapType type, - int desiredWidth, int desiredHeight) -{ - UnRef(); - - return FALSE; -} - -void wxIcon::CopyFromBitmap(const wxBitmap& icno) -{ -} - diff --git a/src/cocoa/icon.mm b/src/cocoa/icon.mm new file mode 100644 index 0000000000..5299b5a645 --- /dev/null +++ b/src/cocoa/icon.mm @@ -0,0 +1,156 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: src/cocoa/icon.mm +// Purpose: wxIcon class +// Author: David Elliott +// Modified by: +// Created: 2003/08/11 +// RCS-ID: $Id$ +// Copyright: (c) 2003 David Elliott +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#include "wx/wxprec.h" +#ifndef WX_PRECOMP + #include "wx/icon.h" +#endif //WX_PRECOMP +#include "wx/bitmap.h" + +#import + +// ======================================================================== +// wxIconRefData +// ======================================================================== +class wxIconRefData: public wxGDIRefData +{ + friend class wxIcon; +public: + wxIconRefData(); + wxIconRefData( const wxIconRefData& data ); + virtual ~wxIconRefData(); + +protected: + int m_width; + int m_height; + int m_depth; + bool m_ok; + int m_numColors; + int m_quality; + WX_NSImage m_cocoaNSImage; +}; + +#define M_ICONDATA ((wxIconRefData *)m_refData) + +wxIconRefData::wxIconRefData() +{ + m_ok = FALSE; + m_width = 0; + m_height = 0; + m_depth = 0; + m_quality = 0; + m_numColors = 0; + m_cocoaNSImage = nil; +} + +wxIconRefData::wxIconRefData( const wxIconRefData& data) +{ + m_width = data.m_width; + m_height = data.m_height; + m_depth = data.m_depth; + m_ok = data.m_ok; + m_numColors = data.m_numColors; + m_quality = data.m_quality; + m_cocoaNSImage = [data.m_cocoaNSImage copyWithZone:nil]; +} + +wxIconRefData::~wxIconRefData() +{ + [m_cocoaNSImage release]; + m_cocoaNSImage = NULL; +} + + +// ======================================================================== +// wxIcon +// ======================================================================== +IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxGDIObject) + +wxIcon::wxIcon() +{ +} + +wxIcon::wxIcon(const char WXUNUSED(bits)[], int WXUNUSED(width), int WXUNUSED(height)) +{ +} + +wxIcon::wxIcon(const wxString& icon_file, int flags, + int desiredWidth, int desiredHeight) + +{ + LoadFile(icon_file, (wxBitmapType)flags, desiredWidth, desiredHeight); +} + +wxIcon::~wxIcon() +{ +} + +bool wxIcon::CreateFromXpm(const char **xpm) +{ + wxBitmap bitmap(xpm); + CopyFromBitmap(bitmap); + return Ok(); +} + +bool wxIcon::LoadFile(const wxString& filename, wxBitmapType type, + int desiredWidth, int desiredHeight) +{ + UnRef(); + + m_refData = new wxIconRefData; + M_ICONDATA->m_width = 5; + M_ICONDATA->m_height = 5; + M_ICONDATA->m_cocoaNSImage = [[NSImage alloc] initWithSize:NSMakeSize(5,5)]; + M_ICONDATA->m_ok = true; + M_ICONDATA->m_numColors = 0; + M_ICONDATA->m_quality = 0; + + return FALSE; +} + +void wxIcon::CopyFromBitmap(const wxBitmap& bitmap) +{ + UnRef(); + m_refData = new wxIconRefData; + M_ICONDATA->m_width = bitmap.GetWidth(); + M_ICONDATA->m_height = bitmap.GetHeight(); + M_ICONDATA->m_cocoaNSImage = bitmap.GetNSImage(true); + M_ICONDATA->m_ok = bitmap.Ok(); + M_ICONDATA->m_numColors = 0; + M_ICONDATA->m_quality = 0; +} + +bool wxIcon::Ok() const +{ + return m_refData && M_ICONDATA->m_ok; +} + +int wxIcon::GetWidth() const +{ + if(!m_refData) + return 0; + return M_ICONDATA->m_width; +} + +int wxIcon::GetHeight() const +{ + if(!m_refData) + return 0; + return M_ICONDATA->m_height; +} + +WX_NSImage wxIcon::GetNSImage() const +{ + if(!M_ICONDATA) + return nil; + return M_ICONDATA->m_cocoaNSImage; +} + -- 2.47.2