monodll_accel.o \
monodll_aga.o \
monodll_app.o \
+ monodll_artmac.o \
monodll_bitmap.o \
monodll_bmpbuttn.o \
monodll_brush.o \
monolib_accel.o \
monolib_aga.o \
monolib_app.o \
+ monolib_artmac.o \
monolib_bitmap.o \
monolib_bmpbuttn.o \
monolib_brush.o \
coredll_accel.o \
coredll_aga.o \
coredll_app.o \
+ coredll_artmac.o \
coredll_bitmap.o \
coredll_bmpbuttn.o \
coredll_brush.o \
corelib_accel.o \
corelib_aga.o \
corelib_app.o \
+ corelib_artmac.o \
corelib_bitmap.o \
corelib_bmpbuttn.o \
corelib_brush.o \
monodll_aga.o: $(srcdir)/src/mac/carbon/aga.cpp $(MONODLL_ODEP)
$(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/mac/carbon/aga.cpp
+monodll_artmac.o: $(srcdir)/src/mac/carbon/artmac.cpp $(MONODLL_ODEP)
+ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/mac/carbon/artmac.cpp
+
monodll_dccg.o: $(srcdir)/src/mac/carbon/dccg.cpp $(MONODLL_ODEP)
$(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/mac/carbon/dccg.cpp
monolib_aga.o: $(srcdir)/src/mac/carbon/aga.cpp $(MONOLIB_ODEP)
$(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/mac/carbon/aga.cpp
+monolib_artmac.o: $(srcdir)/src/mac/carbon/artmac.cpp $(MONOLIB_ODEP)
+ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/mac/carbon/artmac.cpp
+
monolib_dccg.o: $(srcdir)/src/mac/carbon/dccg.cpp $(MONOLIB_ODEP)
$(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/mac/carbon/dccg.cpp
coredll_aga.o: $(srcdir)/src/mac/carbon/aga.cpp $(COREDLL_ODEP)
$(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/mac/carbon/aga.cpp
+coredll_artmac.o: $(srcdir)/src/mac/carbon/artmac.cpp $(COREDLL_ODEP)
+ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/mac/carbon/artmac.cpp
+
coredll_dccg.o: $(srcdir)/src/mac/carbon/dccg.cpp $(COREDLL_ODEP)
$(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/mac/carbon/dccg.cpp
corelib_aga.o: $(srcdir)/src/mac/carbon/aga.cpp $(CORELIB_ODEP)
$(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/mac/carbon/aga.cpp
+corelib_artmac.o: $(srcdir)/src/mac/carbon/artmac.cpp $(CORELIB_ODEP)
+ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/mac/carbon/artmac.cpp
+
corelib_dccg.o: $(srcdir)/src/mac/carbon/dccg.cpp $(CORELIB_ODEP)
$(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/mac/carbon/dccg.cpp
src/mac/carbon/accel.cpp
src/mac/carbon/aga.cpp
src/mac/carbon/app.cpp
+ src/mac/carbon/artmac.cpp
src/mac/carbon/bitmap.cpp
src/mac/carbon/bmpbuttn.cpp
src/mac/carbon/brush.cpp
-if exist $(LIBDIRNAME)\wx$(PORTNAME)$(WXUNIVNAME)$(WX_RELEASE_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_gl.lib del $(LIBDIRNAME)\wx$(PORTNAME)$(WXUNIVNAME)$(WX_RELEASE_NODOT)$(WXUNICODEFLAG)$(WXDEBUGFLAG)$(WX_LIB_FLAVOUR)_gl.lib
cd ..\..\samples
$(MAKE) -f makefile.vc $(MAKEARGS) clean
- cd $(MAKEDIR)
+ cd "$(MAKEDIR)"
setup_h: $(SETUPHDIR)\wx ..\..\include\wx\$(__SETUP_H_SUBDIR_FILENAMES)\setup.h $(SETUPHDIR)\wx\setup.h $(SETUPHDIR)\wx\msw\rcdefs.h
sub_samples:
cd ..\..\samples
$(MAKE) -f makefile.vc $(MAKEARGS) all
- cd $(MAKEDIR)
+ cd "$(MAKEDIR)"
$(LIBDIRNAME):
if not exist $(LIBDIRNAME) mkdir $(LIBDIRNAME)
wxMac:
+- Better IconRef support (Alan Shouls)
- Fix duplicate (empty) help menu in non-English programs (Andreas Jacobs)
- Allow accelerators to be used with buttons too (Ryan Wilcox)
- Support resource forks in wxCopyFile() (Hank Schultz)
dialog), it does not use a hard-coded resource but asks wxArtProvider for it
instead. This way users can plug in their own wxArtProvider class and easily
replace standard art with their own version. All
-that is needed is to derive a class from wxArtProvider, override its
-\helpref{CreateBitmap}{wxartprovidercreatebitmap} method and register the
-provider with
+that is needed is to derive a class from wxArtProvider, override either its
+\helpref{CreateBitmap}{wxartprovidercreatebitmap} and/or its
+\helpref{CreateIconBundle}{wxartprovidercreateiconbundle} methods
+and register the provider with
\helpref{wxArtProvider::Push}{wxartproviderpush}:
\begin{verbatim}
wxBitmap CreateBitmap(const wxArtID& id,
const wxArtClient& client,
const wxSize size)
+
+ // optionally override this one as well
+ wxIconBundle CreateIconBundle(const wxArtID& id,
+ const wxArtClient& client)
{ ... }
};
...
wxArtProvider::Push(new MyProvider);
\end{verbatim}
+If you need bitmap images (of the same artwork) that should be displayed at different sizes
+you should probably consider overriding \helpref{CreateIconBundle()}{wxartprovidercreateiconbundle}
+and supplying icon bundles that contain different bitmap sizes.
+
There's another way of taking advantage of this class: you can use it in your code and use
platform native icons as provided by \helpref{wxArtProvider::GetBitmap}{wxartprovidergetbitmap} or
\helpref{wxArtProvider::GetIcon}{wxartprovidergeticon} (NB: this is not yet really
\membersection{Identifying art resources}\label{artprovideridentifying}
-Every bitmap is known to wxArtProvider under an unique ID that is used by when
+Every bitmap and icon bundle are known to wxArtProvider under an unique ID that is used when
requesting a resource from it. The ID is represented by wxArtID type and can
have one of these predefined values (you can see bitmaps represented by these
constants in the \helpref{artprov}{sampleartprovider} sample):
\func{wxBitmap}{CreateBitmap}{\param{const wxArtID\& }{id}, \param{const wxArtClient\& }{client}, \param{const wxSize\& }{size}}
-Derived art provider classes must override this method to create requested
-art resource. Note that returned bitmaps are cached by wxArtProvider and it is therefore
-not necessary to optimize CreateBitmap for speed (e.g. you may create wxBitmap objects
-from XPMs here).
+Derived art provider classes must override this method or the CreateIconBundle() method
+to create requested art resource. Note that returned bitmaps are cached by wxArtProvider
+and it is therefore not necessary to optimize CreateBitmap() for speed (e.g. you may create
+wxBitmap objects from XPMs here).
\wxheading{Parameters}
This is {\bf not} part of wxArtProvider's public API, use
\helpref{wxArtProvider::GetBitmap}{wxartprovidergetbitmap} or
+\helpref{wxArtProvider::GetIconBundle}{wxartprovidergeticonbundle} or
\helpref{wxArtProvider::GetIcon}{wxartprovidergeticon}
to query wxArtProvider for a resource.
+\func{wxIconBundle}{CreateIconBundle}{\param{const wxArtID\& }{id}, \param{const wxArtClient\& }{client}}
+
+Derived art provider classes must override this method or the CreateIconBundle method
+to create requested art resource. Note that returned icon bundles are cached by wxArtProvider
+and it is therefore not necessary to optimize CreateIconBundle for speed (e.g. you may create icon bundles
+from artwork resources here).
+
+\wxheading{Parameters}
+
+\docparam{id}{wxArtID unique identifier of the icon bundle.}
+
+\docparam{client}{wxArtClient identifier of the client (i.e. who is asking for the icon bundle).
+This only servers as a hint.}
+
+\wxheading{Note}
+
+This is {\bf not} part of wxArtProvider's public API, use
+\helpref{wxArtProvider::GetBitmap}{wxartprovidergetbitmap} or
+\helpref{wxArtProvider::GetIconBundle}{wxartprovidergeticonbundle} or
+\helpref{wxArtProvider::GetIcon}{wxartprovidergeticon}
+to query wxArtProvider for a resource.
+
\membersection{wxArtProvider::Delete}\label{wxartproviderdelete}
\func{static bool}{Delete}{\param{wxArtProvider* }{provider}}
The bitmap if one of registered providers recognizes the ID or wxNullBitmap otherwise.
+\membersection{wxArtProvider::GetIconBundle}\label{wxartprovidergeticonbundle}
+
+\func{static wxIconBundle}{GetIconBundle}{\param{const wxArtID\& }{id}, \param{const wxArtClient\& }{client = wxART\_OTHER}}
+
+Query registered providers for icon bundle with given ID.
+
+\wxheading{Parameters}
+
+\docparam{id}{wxArtID unique identifier of the icon bundle.}
+
+\docparam{client}{wxArtClient identifier of the client (i.e. who is asking for the icon bundle).}
+
+\wxheading{Return value}
+
+The icon bundle if one of registered providers recognizes the ID or wxNullIconBundle otherwise.
+
+
\membersection{wxArtProvider::GetIcon}\label{wxartprovidergeticon}
\func{static wxIcon}{GetIcon}{\param{const wxArtID\& }{id}, \param{const wxArtClient\& }{client = wxART\_OTHER}, \param{const wxSize\& }{size = wxDefaultSize}}
\wxheading{Derived from}
-No base class
+\helpref{wxGDIObject}{wxgdiobject}\\
+\helpref{wxObject}{wxobject}
+
+\wxheading{Predefined objects}
+
+{\bf wxNullIconBundle}
\latexignore{\rtfignore{\wxheading{Members}}}
\membersection{wxIconBundle::GetIcon}\label{wxiconbundlegeticon}
-\constfunc{const wxIcon\&}{GetIcon}{\param{const wxSize\& }{size}}
+\constfunc{wxIcon}{GetIcon}{\param{const wxSize\& }{size}}
Returns the icon with the given size; if no such icon exists,
returns the icon with size wxSYS\_ICON\_X/wxSYS\_ICON\_Y;
returns the first icon in the bundle. If size = wxSize( -1, -1 ),
returns the icon with size wxSYS\_ICON\_X/wxSYS\_ICON\_Y.
-\constfunc{const wxIcon\&}{GetIcon}{\param{wxCoord }{size = -1}}
+\constfunc{wxIcon}{GetIcon}{\param{wxCoord }{size = -1}}
Same as GetIcon( wxSize( size, size ) ).
-\membersection{wxIconBundle::operator=}\label{wxiconbundleoperatorassign}
+\membersection{wxIconBundle::operator $=$}\label{wxiconbundleoperatorassign}
+
+\func{wxIconBundle\&}{operator $=$}{\param{const wxIconBundle\& }{ic}}
+
+Assignment operator, using \helpref{reference counting}{trefcount}.
+
+\membersection{wxIconBundle::operator $==$}\label{wxiconbundleoperatorequals}
+
+\func{bool}{operator $==$}{\param{const wxIconBundle\& }{ic}}
+
+Equality operator. This returns \true if two icon bundles are equal.
-\func{const wxIconBundle\&}{operator=}{\param{const wxIconBundle\& }{ic}}
+\membersection{wxIconBundle::operator $!=$}\label{wxiconbundleoperatornotequals}
-Assignment operator.
+\func{bool}{operator $!=$}{\param{const wxIconBundle\& }{ic}}
+Inequality operator. This returns \true if two icon bundles are not equal.
#include "wx/string.h"
#include "wx/bitmap.h"
#include "wx/icon.h"
+#include "wx/iconbndl.h"
class WXDLLEXPORT wxArtProvidersList;
class WXDLLEXPORT wxArtProviderCache;
#define wxART_HELP_BROWSER wxART_MAKE_CLIENT_ID(wxART_HELP_BROWSER)
#define wxART_MESSAGE_BOX wxART_MAKE_CLIENT_ID(wxART_MESSAGE_BOX)
#define wxART_BUTTON wxART_MAKE_CLIENT_ID(wxART_BUTTON)
+#define wxART_LIST wxART_MAKE_CLIENT_ID(wxART_LIST)
#define wxART_OTHER wxART_MAKE_CLIENT_ID(wxART_OTHER)
const wxArtClient& client = wxART_OTHER,
const wxSize& size = wxDefaultSize);
+ // Query the providers for iconbundle with given ID and return it. Return
+ // wxNullIconBundle if no provider provides it.
+ static wxIconBundle GetIconBundle(const wxArtID& id,
+ const wxArtClient& client = wxART_OTHER);
+
// Get the size hint of an icon from a specific wxArtClient, queries
// the topmost provider if platform_dependent = false
static wxSize GetSizeHint(const wxArtClient& client, bool platform_dependent = false);
return GetSizeHint(client, true);
}
- // Derived classes must override this method to create requested
- // art resource. This method is called only once per instance's
- // lifetime for each requested wxArtID.
+ // Derived classes must override CreateBitmap or CreateIconBundle
+ // (or both) to create requested art resource. This method is called
+ // only once per instance's lifetime for each requested wxArtID.
virtual wxBitmap CreateBitmap(const wxArtID& WXUNUSED(id),
const wxArtClient& WXUNUSED(client),
- const wxSize& WXUNUSED(size)) = 0;
+ const wxSize& WXUNUSED(size)) { return wxNullBitmap; }
+
+ virtual wxIconBundle CreateIconBundle(const wxArtID& WXUNUSED(id),
+ const wxArtClient& WXUNUSED(client))
+ {
+ return wxNullIconBundle;
+ }
private:
static void CommonAddingProvider();
class WXDLLIMPEXP_CORE wxPen;
class WXDLLIMPEXP_CORE wxRegion;
class WXDLLIMPEXP_BASE wxString;
+class WXDLLIMPEXP_CORE wxIconBundle;
// ---------------------------------------------------------------------------
// constants
extern WXDLLEXPORT_DATA(wxCursor) wxNullCursor;
extern WXDLLEXPORT_DATA(wxPen) wxNullPen;
extern WXDLLEXPORT_DATA(wxBrush) wxNullBrush;
-extern WXDLLEXPORT_DATA(wxPalette) wxNullPalette;
+extern WXDLLEXPORT_DATA(wxPalette) wxNullPalette;
extern WXDLLEXPORT_DATA(wxFont) wxNullFont;
extern WXDLLEXPORT_DATA(wxColour) wxNullColour;
+extern WXDLLEXPORT_DATA(wxIconBundle) wxNullIconBundle;
extern WXDLLEXPORT_DATA(wxColourDatabase*) wxTheColourDatabase;
#define _WX_ICONBNDL_H_
#include "wx/dynarray.h"
+#include "wx/gdiobj.h"
// for wxSize
#include "wx/gdicmn.h"
+#include "wx/icon.h"
class WXDLLIMPEXP_CORE wxIcon;
class WXDLLIMPEXP_BASE wxString;
-WX_DECLARE_EXPORTED_OBJARRAY( wxIcon, wxIconArray );
+class WXDLLEXPORT wxIconBundle;
+
+WX_DECLARE_EXPORTED_OBJARRAY(wxIcon, wxIconArray);
// this class can't load bitmaps of type wxBITMAP_TYPE_ICO_RESOURCE,
// if you need them, you have to load them manually and call
// wxIconCollection::AddIcon
-class WXDLLEXPORT wxIconBundle
+class WXDLLEXPORT wxIconBundle : public wxGDIObject
{
public:
// default constructor
- wxIconBundle() : m_icons() {}
+ wxIconBundle();
+
// initializes the bundle with the icon(s) found in the file
- wxIconBundle( const wxString& file, long type ) : m_icons()
- { AddIcon( file, type ); }
+ wxIconBundle(const wxString& file, long type);
+
// initializes the bundle with a single icon
- wxIconBundle( const wxIcon& icon ) : m_icons()
- { AddIcon( icon ); }
+ wxIconBundle(const wxIcon& icon);
+
+ // initializes the bundle from another icon bundle
+ wxIconBundle(const wxIconBundle& icon);
- const wxIconBundle& operator =( const wxIconBundle& ic );
- wxIconBundle( const wxIconBundle& ic ) : m_icons()
- { *this = ic; }
+ wxIconBundle& operator=(const wxIconBundle& ic)
+ { if ( this != &ic) Ref(ic); return *this; }
+
+ virtual bool IsOk() const;
- ~wxIconBundle() { DeleteIcons(); }
// adds all the icons contained in the file to the collection,
// if the collection already contains icons with the same
// width and height, they are replaced
- void AddIcon( const wxString& file, long type );
+ void AddIcon(const wxString& file, long type);
+
// adds the icon to the collection, if the collection already
// contains an icon with the same width and height, it is
// replaced
- void AddIcon( const wxIcon& icon );
+ void AddIcon(const wxIcon& icon);
// returns the icon with the given size; if no such icon exists,
// returns the icon with size wxSYS_ICON_[XY]; if no such icon exists,
// returns the first icon in the bundle
- const wxIcon& GetIcon( const wxSize& size ) const;
+ wxIcon GetIcon(const wxSize& size) const;
+
// equivalent to GetIcon( wxSize( size, size ) )
- const wxIcon& GetIcon( wxCoord size = wxDefaultCoord ) const
+ wxIcon GetIcon(wxCoord size = wxDefaultCoord) const
{ return GetIcon( wxSize( size, size ) ); }
+
+
+ // enumerate all icons in the bundle: don't use these functions if ti can
+ // be avoided, using GetIcon() directly is better
+
+ // return the number of available icons
+ size_t GetIconCount() const;
+
+ // return the icon at index (must be < GetIconCount())
+ wxIcon GetIconByIndex(size_t n) const;
+
+protected:
+ virtual wxObjectRefData *CreateRefData() const;
+ virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
+
private:
// delete all icons
void DeleteIcons();
-public:
- wxIconArray m_icons;
+
+ DECLARE_DYNAMIC_CLASS(wxIconBundle)
};
-#endif
- // _WX_ICONBNDL_H_
+#endif // _WX_ICONBNDL_H_
{
LoadFile(loc.GetFileName(), wxBITMAP_TYPE_ICON);
}
+
+ wxIcon(WXHICON icon, const wxSize& size);
+
virtual ~wxIcon();
bool LoadFile(const wxString& name, wxBitmapType flags /* = wxBITMAP_TYPE_ICON_RESOURCE */ ,
virtual bool IsIconized() const = 0;
// get the frame icon
- const wxIcon& GetIcon() const { return m_icons.GetIcon( -1 ); }
+ wxIcon GetIcon() const { return m_icons.GetIcon( -1 ); }
// get the frame icons
const wxIconBundle& GetIcons() const { return m_icons; }
#include "wx/colordlg.h"
#include "wx/numdlg.h"
+#include "wx/artprov.h"
#include "wx/image.h"
#include "wx/imaglist.h"
#include "wx/treectrl.h"
MENU_LINK(DeleteAll)
MENU_LINK(Recreate)
MENU_LINK(ToggleImages)
+ MENU_LINK(ToggleAlternateImages)
MENU_LINK(ToggleButtons)
MENU_LINK(SetImageSize)
MENU_LINK(CollapseAndReset)
style_menu->AppendCheckItem(TreeTest_ToggleSel, wxT("Toggle &selection mode"));
#endif // NO_MULTIPLE_SELECTION
style_menu->AppendCheckItem(TreeTest_ToggleImages, wxT("Toggle show ima&ges"));
+ style_menu->AppendCheckItem(TreeTest_ToggleAlternateImages, wxT("Toggle alternate images"));
style_menu->Append(TreeTest_SetImageSize, wxT("Set image si&ze..."));
style_menu->AppendSeparator();
style_menu->Append(TreeTest_SetFgColour, wxT("Set &foreground colour..."));
CreateTreeWithDefStyle();
menu_bar->Check(TreeTest_ToggleImages, true);
+ menu_bar->Check(TreeTest_ToggleAlternateImages, false);
#if wxUSE_STATUSBAR
// create a status bar
}
}
+void MyFrame::OnToggleAlternateImages(wxCommandEvent& WXUNUSED(event))
+{
+ bool alternateImages = m_treeCtrl->AlternateImages();
+
+ m_treeCtrl->SetAlternateImages(!alternateImages);
+ m_treeCtrl->CreateImageList(0);
+}
+
void MyFrame::OnToggleButtons(wxCommandEvent& WXUNUSED(event))
{
#if USE_GENERIC_TREECTRL || !defined(__WXMSW__)
MyTreeCtrl::MyTreeCtrl(wxWindow *parent, const wxWindowID id,
const wxPoint& pos, const wxSize& size,
long style)
- : wxTreeCtrl(parent, id, pos, size, style)
+ : wxTreeCtrl(parent, id, pos, size, style),
+ m_alternateImages(false)
{
m_reverseSort = false;
// should correspond to TreeCtrlIcon_xxx enum
wxBusyCursor wait;
wxIcon icons[5];
- icons[0] = wxIcon(icon1_xpm);
- icons[1] = wxIcon(icon2_xpm);
- icons[2] = wxIcon(icon3_xpm);
- icons[3] = wxIcon(icon4_xpm);
- icons[4] = wxIcon(icon5_xpm);
- int sizeOrig = icons[0].GetWidth();
+ if (m_alternateImages)
+ {
+ icons[TreeCtrlIcon_File] = wxIcon(icon1_xpm);
+ icons[TreeCtrlIcon_FileSelected] = wxIcon(icon2_xpm);
+ icons[TreeCtrlIcon_Folder] = wxIcon(icon3_xpm);
+ icons[TreeCtrlIcon_FolderSelected] = wxIcon(icon4_xpm);
+ icons[TreeCtrlIcon_FolderOpened] = wxIcon(icon5_xpm);
+ }
+ else
+ {
+ wxSize iconSize(size, size);
+
+ icons[TreeCtrlIcon_File] =
+ icons[TreeCtrlIcon_FileSelected] = wxArtProvider::GetIcon(wxART_NORMAL_FILE, wxART_LIST, iconSize);
+ icons[TreeCtrlIcon_Folder] =
+ icons[TreeCtrlIcon_FolderSelected] =
+ icons[TreeCtrlIcon_FolderOpened] = wxArtProvider::GetIcon(wxART_FOLDER, wxART_LIST, iconSize);
+ }
+
for ( size_t i = 0; i < WXSIZEOF(icons); i++ )
{
+ int sizeOrig = icons[0].GetWidth();
if ( size == sizeOrig )
{
images->Add(icons[i]);
// should correspond to TreeCtrlIcon_xxx enum
wxBusyCursor wait;
wxIcon icons[4];
- icons[0] = wxIcon(icon3_xpm); // closed
- icons[1] = wxIcon(icon3_xpm); // closed, selected
- icons[2] = wxIcon(icon5_xpm); // open
- icons[3] = wxIcon(icon5_xpm); // open, selected
- for ( size_t i = 0; i < WXSIZEOF(icons); i++ )
+ if (m_alternateImages)
+ {
+ icons[0] = wxIcon(icon3_xpm); // closed
+ icons[1] = wxIcon(icon3_xpm); // closed, selected
+ icons[2] = wxIcon(icon5_xpm); // open
+ icons[3] = wxIcon(icon5_xpm); // open, selected
+ }
+ else
+ {
+ wxSize iconSize(size, size);
+
+ icons[0] = // closed
+ icons[1] = wxArtProvider::GetIcon(wxART_FOLDER, wxART_LIST, iconSize); // closed, selected
+ icons[2] = // open
+ icons[3] = wxArtProvider::GetIcon(wxART_FOLDER_OPEN, wxART_LIST, iconSize);// open, selected
+ }
+
+ for ( size_t i = 0; i < WXSIZEOF(icons); i++ )
{
int sizeOrig = icons[i].GetWidth();
if ( size == sizeOrig )
TreeCtrlIcon_FolderOpened
};
- MyTreeCtrl() { }
+ MyTreeCtrl() { m_alternateImages = false; }
MyTreeCtrl(wxWindow *parent, const wxWindowID id,
const wxPoint& pos, const wxSize& size,
long style);
void SetLastItem(wxTreeItemId id) { m_lastItem = id; }
+ void SetAlternateImages(bool show) { m_alternateImages = show; }
+ bool AlternateImages() const { return m_alternateImages; }
+
protected:
virtual int OnCompareItems(const wxTreeItemId& i1, const wxTreeItemId& i2);
bool m_reverseSort; // flag for OnCompareItems
wxTreeItemId m_lastItem, // for OnEnsureVisible()
m_draggedItem; // item being dragged right now
+ bool m_alternateImages;
// NB: due to an ugly wxMSW hack you _must_ use DECLARE_DYNAMIC_CLASS()
// if you want your overloaded OnCompareItems() to be called.
void OnRecreate(wxCommandEvent& event);
void OnToggleButtons(wxCommandEvent& event);
void OnToggleImages(wxCommandEvent& event);
+ void OnToggleAlternateImages(wxCommandEvent& event);
void OnSetImageSize(wxCommandEvent& event);
void OnCollapseAndReset(wxCommandEvent& event);
TreeTest_DeleteAll,
TreeTest_Recreate,
TreeTest_ToggleImages,
+ TreeTest_ToggleAlternateImages,
TreeTest_ToggleButtons,
TreeTest_SetImageSize,
TreeTest_ToggleSel,
// ----------------------------------------------------------------------------
WX_DECLARE_EXPORTED_STRING_HASH_MAP(wxBitmap, wxArtProviderBitmapsHash);
+WX_DECLARE_EXPORTED_STRING_HASH_MAP(wxIconBundle, wxArtProviderIconBundlesHash);
class WXDLLEXPORT wxArtProviderCache
{
void PutBitmap(const wxString& full_id, const wxBitmap& bmp)
{ m_bitmapsHash[full_id] = bmp; }
+ bool GetIconBundle(const wxString& full_id, wxIconBundle* bmp);
+ void PutIconBundle(const wxString& full_id, const wxIconBundle& iconbundle)
+ { m_iconBundlesHash[full_id] = iconbundle; }
+
void Clear();
static wxString ConstructHashID(const wxArtID& id,
const wxArtClient& client,
const wxSize& size);
+ static wxString ConstructHashID(const wxArtID& id,
+ const wxArtClient& client);
+
private:
- wxArtProviderBitmapsHash m_bitmapsHash;
+ wxArtProviderBitmapsHash m_bitmapsHash; // cache of wxBitmaps
+ wxArtProviderIconBundlesHash m_iconBundlesHash; // cache of wxIconBundles
};
bool wxArtProviderCache::GetBitmap(const wxString& full_id, wxBitmap* bmp)
}
}
+bool wxArtProviderCache::GetIconBundle(const wxString& full_id, wxIconBundle* bmp)
+{
+ wxArtProviderIconBundlesHash::iterator entry = m_iconBundlesHash.find(full_id);
+ if ( entry == m_iconBundlesHash.end() )
+ {
+ return false;
+ }
+ else
+ {
+ *bmp = entry->second;
+ return true;
+ }
+}
+
void wxArtProviderCache::Clear()
{
m_bitmapsHash.clear();
+ m_iconBundlesHash.clear();
}
-/*static*/ wxString wxArtProviderCache::ConstructHashID(
- const wxArtID& id, const wxArtClient& client,
- const wxSize& size)
+/* static */ wxString
+wxArtProviderCache::ConstructHashID(const wxArtID& id,
+ const wxArtClient& client)
{
- wxString str;
- str.Printf(wxT("%s-%s-%i-%i"), id.c_str(), client.c_str(), size.x, size.y);
- return str;
+ return id + _T('-') + client;
}
+/* static */ wxString
+wxArtProviderCache::ConstructHashID(const wxArtID& id,
+ const wxArtClient& client,
+ const wxSize& size)
+{
+ return ConstructHashID(id, client) + _T('-') +
+ wxString::Format(_T("%d-%d"), size.x, size.y);
+}
+
// ============================================================================
// wxArtProvider class
// ============================================================================
#endif
break;
}
+ // We could try the IconBundles here and convert what we find
+ // to a bitmap.
}
-
sm_cache->PutBitmap(hashId, bmp);
- }
+ }
return bmp;
}
+/*static*/ wxIconBundle wxArtProvider::GetIconBundle(const wxArtID& id, const wxArtClient& client)
+{
+ // safety-check against writing client,id,size instead of id,client,size:
+ wxASSERT_MSG( client.Last() == _T('C'), _T("invalid 'client' parameter") );
+
+ wxCHECK_MSG( sm_providers, wxNullIconBundle, _T("no wxArtProvider exists") );
+
+ wxString hashId = wxArtProviderCache::ConstructHashID(id, client);
+
+ wxIconBundle iconbundle;
+ if ( !sm_cache->GetIconBundle(hashId, &iconbundle) )
+ {
+ for (wxArtProvidersList::compatibility_iterator node = sm_providers->GetFirst();
+ node; node = node->GetNext())
+ {
+ iconbundle = node->GetData()->CreateIconBundle(id, client);
+ if ( iconbundle.IsOk() )
+ break;
+ }
+
+ sm_cache->PutIconBundle(hashId, iconbundle);
+ }
+
+ return iconbundle;
+}
+
/*static*/ wxIcon wxArtProvider::GetIcon(const wxArtID& id,
const wxArtClient& client,
const wxSize& size)
{
wxCHECK_MSG( sm_providers, wxNullIcon, _T("no wxArtProvider exists") );
+ // First look for an appropriate icon bundle - this will give us the best icon
+ wxIconBundle iconBundle = GetIconBundle(id, client);
+ if ( iconBundle.IsOk() )
+ return iconBundle.GetIcon(size);
+
+ // If there is no icon bundle then look for a bitmap
wxBitmap bmp = GetBitmap(id, client, size);
if ( !bmp.Ok() )
return wxNullIcon;
wxArtProvider::Push(new wxDefaultArtProvider);
}
-#if !defined(__WXGTK20__) || defined(__WXUNIVERSAL__)
+#if !(defined(__WXGTK20__) || defined(__WXMAC__)) || defined(__WXUNIVERSAL__)
/*static*/ void wxArtProvider::InitNativeProvider()
{
}
#include "wx/brush.h"
#include "wx/palette.h"
#include "wx/icon.h"
+ #include "wx/iconbndl.h"
#include "wx/cursor.h"
#include "wx/settings.h"
#include "wx/bitmap.h"
#if wxUSE_PALETTE
WXDLLIMPEXP_DATA_CORE(wxPalette) wxNullPalette;
#endif
+WXDLLIMPEXP_DATA_CORE(wxIconBundle) wxNullIconBundle;
const wxSize wxDefaultSize(wxDefaultCoord, wxDefaultCoord);
const wxPoint wxDefaultPosition(wxDefaultCoord, wxDefaultCoord);
/////////////////////////////////////////////////////////////////////////////
// Name: src/common/iconbndl.cpp
// Purpose: wxIconBundle
-// Author: Mattia Barbon
+// Author: Mattia Barbon, Vadim Zeitlin
// Created: 23.03.2002
// RCS-ID: $Id$
// Copyright: (c) Mattia barbon
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
+// ============================================================================
+// declarations
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
WX_DEFINE_OBJARRAY(wxIconArray)
-const wxIconBundle& wxIconBundle::operator =( const wxIconBundle& ic )
+IMPLEMENT_DYNAMIC_CLASS(wxIconBundle, wxGDIObject)
+
+#define M_ICONBUNDLEDATA ((wxIconBundleRefData *)m_refData)
+
+// ----------------------------------------------------------------------------
+// wxIconBundleRefData
+// ----------------------------------------------------------------------------
+
+class WXDLLEXPORT wxIconBundleRefData : public wxGDIRefData
+{
+public:
+ // default and copy ctors and assignment operators are ok
+
+protected:
+ wxIconArray m_icons;
+
+ friend class WXDLLEXPORT wxIconBundle;
+};
+
+// ============================================================================
+// wxIconBundle implementation
+// ============================================================================
+
+wxIconBundle::wxIconBundle()
+ : wxGDIObject()
+{
+ m_refData = new wxIconBundleRefData;
+}
+
+wxIconBundle::wxIconBundle(const wxString& file, long type)
+ : wxGDIObject()
{
- if( this == &ic ) return *this;
+ m_refData = new wxIconBundleRefData;
+ AddIcon(file, type);
+}
- size_t i, max = ic.m_icons.GetCount();
+wxIconBundle::wxIconBundle(const wxIconBundle& icon)
+ : wxGDIObject()
+{
+ Ref(icon);
+}
- DeleteIcons();
- for( i = 0; i < max; ++i )
- m_icons.Add( ic.m_icons[i] );
+wxIconBundle::wxIconBundle(const wxIcon& icon)
+ : wxGDIObject()
+{
+ m_refData = new wxIconBundleRefData;
+ AddIcon(icon);
+}
- return *this;
+wxObjectRefData *wxIconBundle::CreateRefData() const
+{
+ return new wxIconBundleRefData;
+}
+
+wxObjectRefData *wxIconBundle::CloneRefData(const wxObjectRefData *data) const
+{
+ return new wxIconBundleRefData(*wx_static_cast(const wxIconBundleRefData *, data));
}
void wxIconBundle::DeleteIcons()
{
- m_icons.Empty();
+ wxIconBundleRefData* ref = new wxIconBundleRefData();
+ UnRef();
+ m_refData = ref;
}
-#if wxUSE_IMAGE
-void wxIconBundle::AddIcon( const wxString& file, long type )
-#else
-void wxIconBundle::AddIcon( const wxString& WXUNUSED(file), long WXUNUSED(type) )
-#endif
+bool wxIconBundle::IsOk() const
+{
+ return M_ICONBUNDLEDATA && !M_ICONBUNDLEDATA->m_icons.IsEmpty();
+}
+
+void wxIconBundle::AddIcon(const wxString& file, long type)
{
+#ifdef __WXMAC__
+ // Deal with standard icons
+ if ( type == wxBITMAP_TYPE_ICON_RESOURCE )
+ {
+ wxIcon tmp(file, type);
+ if (tmp.Ok())
+ {
+ AddIcon(tmp);
+ return;
+ }
+ }
+#endif // __WXMAC__
+
#if wxUSE_IMAGE && (!defined(__WXMSW__) || wxUSE_WXDIB)
- size_t count = wxImage::GetImageCount( file, type );
- size_t i;
wxImage image;
- for( i = 0; i < count; ++i )
+ const size_t count = wxImage::GetImageCount( file, type );
+ for ( size_t i = 0; i < count; ++i )
{
- if( !image.LoadFile( file, type, i ) )
+ if ( !image.LoadFile( file, type, i ) )
{
wxLogError( _("Failed to load image %d from file '%s'."),
i, file.c_str() );
continue;
}
- wxIcon* tmp = new wxIcon();
- tmp->CopyFromBitmap( wxBitmap( image ) );
- AddIcon( *tmp );
- delete tmp;
+ wxIcon tmp;
+ tmp.CopyFromBitmap(wxBitmap(image));
+ AddIcon(tmp);
}
-#endif
+#else // !wxUSE_IMAGE
+ wxUnusedVar(file);
+ wxUnusedVar(type);
+#endif // wxUSE_IMAGE/!wxUSE_IMAGE
}
-const wxIcon& wxIconBundle::GetIcon( const wxSize& size ) const
+wxIcon wxIconBundle::GetIcon(const wxSize& size) const
{
- // temp. variable needed to fix Borland C++ 5.5.1 problem
- // with passing a return value through two functions
- wxIcon *tmp;
-
- size_t max = m_icons.GetCount();
-
- // if we have one or no icon, we can return now without doing more work:
- if ( max <= 1 )
- {
- if ( max == 1 ) // fix for broken BCC
- tmp = &m_icons[0];
- else // max == 0
- tmp = &wxNullIcon;
- return *tmp;
- }
+ wxCHECK_MSG( IsOk(), wxNullIcon, _T("invalid icon bundle") );
- // there are more icons, find the best match:
- wxCoord sysX = wxSystemSettings::GetMetric( wxSYS_ICON_X ),
- sysY = wxSystemSettings::GetMetric( wxSYS_ICON_Y );
+ const wxIconArray& iconArray = M_ICONBUNDLEDATA->m_icons;
- wxIcon *sysIcon = 0;
+ const size_t count = iconArray.size();
- for( size_t i = 0; i < max; i++ )
+ // optimize for the common case of icon bundles containing one icon only
+ wxIcon iconBest;
+ switch ( count )
{
- if( !m_icons[i].Ok() )
- continue;
- wxCoord sx = m_icons[i].GetWidth(), sy = m_icons[i].GetHeight();
- // requested size
- if( sx == size.x && sy == size.y )
- {
- tmp = &m_icons[i]; // fix for broken BCC
- return *tmp;
- }
- // keep track if there is a system-size icon
- if( sx == sysX && sy == sysY )
- sysIcon = &m_icons[i];
+ case 0:
+ // nothing to do, iconBest is already invalid
+ break;
+
+ case 1:
+ iconBest = iconArray[0];
+ break;
+
+ default:
+ // there is more than one icon, find the best match:
+ wxCoord sysX = wxSystemSettings::GetMetric( wxSYS_ICON_X ),
+ sysY = wxSystemSettings::GetMetric( wxSYS_ICON_Y );
+
+ for ( size_t i = 0; i < count; i++ )
+ {
+ const wxIcon& icon = iconArray[i];
+ wxCoord sx = icon.GetWidth(),
+ sy = icon.GetHeight();
+
+ // if we got an icon of exactly the requested size, we're done
+ if ( sx == size.x && sy == size.y )
+ {
+ iconBest = icon;
+ break;
+ }
+
+ // the best icon is by default (arbitrarily) the first one but
+ // if we find a system-sized icon, take it instead
+ if ( sx == sysX && sy == sysY || !iconBest.IsOk() )
+ iconBest = icon;
+ }
}
- // return the system-sized icon if we've got one
- if( sysIcon ) return *sysIcon;
- // we certainly have at least one icon thanks to the <=1 check above
- tmp = &m_icons[0];
- return *tmp;
+#ifdef __WXMAC__
+ return wxIcon(iconBest.GetHICON(), size);
+#else
+ return iconBest;
+#endif
}
-void wxIconBundle::AddIcon( const wxIcon& icon )
+void wxIconBundle::AddIcon(const wxIcon& icon)
{
- size_t i, max = m_icons.GetCount();
+ wxCHECK_RET( icon.IsOk(), _T("invalid icon") );
- for( i = 0; i < max; ++i )
+ AllocExclusive();
+
+ wxIconArray& iconArray = M_ICONBUNDLEDATA->m_icons;
+
+ // replace existing icon with the same size if we already have it
+ const size_t count = iconArray.size();
+ for ( size_t i = 0; i < count; ++i )
{
- wxIcon& tmp = m_icons[i];
- if( tmp.Ok() && tmp.GetWidth() == icon.GetWidth() &&
- tmp.GetHeight() == icon.GetHeight() )
+ wxIcon& tmp = iconArray[i];
+ if ( tmp.Ok() &&
+ tmp.GetWidth() == icon.GetWidth() &&
+ tmp.GetHeight() == icon.GetHeight() )
{
tmp = icon;
return;
}
}
- m_icons.Add( icon );
+ // if we don't, add an icon with new size
+ iconArray.Add(icon);
}
+
+size_t wxIconBundle::GetIconCount() const
+{
+ return M_ICONBUNDLEDATA->m_icons.size();
+}
+
+wxIcon wxIconBundle::GetIconByIndex(size_t n) const
+{
+ return M_ICONBUNDLEDATA->m_icons[n];
+}
+
void wxTopLevelWindowGTK::SetIcon( const wxIcon &icon )
{
- SetIcons( wxIconBundle( icon ) );
+ // passing wxNullIcon to SetIcon() is possible (it means that we shouldn't
+ // have any icon), but adding an invalid icon to wxIconBundle is not
+ wxIconBundle icons;
+ if ( icon.Ok() )
+ icons.AddIcon(icon);
+
+ SetIcons(icons);
}
void wxTopLevelWindowGTK::SetIcons( const wxIconBundle &icons )
wxTopLevelWindowBase::SetIcons( icons );
GList *list = NULL;
- size_t max = icons.m_icons.GetCount();
- for (size_t i = 0; i < max; i++)
+ const size_t numIcons = icons.GetIconCount();
+ for ( size_t i = 0; i < numIcons; i++ )
{
- if (icons.m_icons[i].Ok())
- {
- list = g_list_prepend(list, icons.m_icons[i].GetPixbuf());
- }
+ list = g_list_prepend(list, icons.GetIconByIndex(i).GetPixbuf());
}
+
gtk_window_set_icon_list(GTK_WINDOW(m_widget), list);
g_list_free(list);
}
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: src/mac/carbon/artmac.cpp
+// Purpose: wxArtProvider instance with native Mac stock icons
+// Author: Alan Shouls
+// Created: 2006-10-30
+// RCS-ID: $Id$
+// Copyright: (c) wxWindows team
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+// ---------------------------------------------------------------------------
+// headers
+// ---------------------------------------------------------------------------
+
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
+
+#if defined(__BORLANDC__)
+ #pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+ #include "wx/image.h"
+#endif
+
+#include "wx/artprov.h"
+#include "wx/image.h"
+
+// ----------------------------------------------------------------------------
+// wxMacArtProvider
+// ----------------------------------------------------------------------------
+
+class wxMacArtProvider : public wxArtProvider
+{
+protected:
+ virtual wxBitmap CreateBitmap(const wxArtID& id, const wxArtClient& client,
+ const wxSize& size);
+ virtual wxIconBundle CreateIconBundle(const wxArtID& id,
+ const wxArtClient& client);
+};
+
+/* static */ void wxArtProvider::InitNativeProvider()
+{
+ wxArtProvider::Push(new wxMacArtProvider);
+}
+
+// ----------------------------------------------------------------------------
+// helper macros
+// ----------------------------------------------------------------------------
+
+#define CREATE_STD_ICON(iconId, xpmRc) \
+ { \
+ wxIconBundle icon(_T(iconId), wxBITMAP_TYPE_ICON_RESOURCE); \
+ return icon; \
+ }
+
+// Macro used in CreateBitmap to get wxICON_FOO icons:
+#define ART_MSGBOX(artId, iconId, xpmRc) \
+ if ( id == artId ) \
+ { \
+ CREATE_STD_ICON(#iconId, xpmRc) \
+ }
+
+static wxIconBundle wxMacArtProvider_CreateIconBundle(const wxArtID& id)
+{
+ ART_MSGBOX(wxART_ERROR, wxICON_ERROR, error)
+ ART_MSGBOX(wxART_INFORMATION, wxICON_INFORMATION, info)
+ ART_MSGBOX(wxART_WARNING, wxICON_WARNING, warning)
+ ART_MSGBOX(wxART_QUESTION, wxICON_QUESTION, question)
+
+ ART_MSGBOX(wxART_FOLDER, wxICON_FOLDER, folder)
+ ART_MSGBOX(wxART_FOLDER_OPEN, wxICON_FOLDER_OPEN, folder_open)
+ ART_MSGBOX(wxART_NORMAL_FILE, wxICON_NORMAL_FILE, deffile)
+
+ return wxNullIconBundle;
+}
+
+// ----------------------------------------------------------------------------
+// CreateIconBundle
+// ----------------------------------------------------------------------------
+
+wxIconBundle wxMacArtProvider::CreateIconBundle(const wxArtID& id, const wxArtClient& client)
+{
+ // On the Mac folders in lists are always drawn closed, so if an open
+ // folder icon is asked for we will ask for a closed one in its place
+ if ( client == wxART_LIST && id == wxART_FOLDER_OPEN )
+ return wxMacArtProvider_CreateIconBundle(wxART_FOLDER);
+
+ return wxMacArtProvider_CreateIconBundle(id);
+}
+
+// ----------------------------------------------------------------------------
+// CreateBitmap
+// ----------------------------------------------------------------------------
+
+wxBitmap wxMacArtProvider::CreateBitmap(const wxArtID& id,
+ const wxArtClient& client,
+ const wxSize& reqSize)
+{
+ wxIconBundle ic(CreateIconBundle(id, client));
+ if (ic.IsOk())
+ {
+ wxIcon theIcon(ic.GetIcon(reqSize));
+ return wxBitmap(theIcon);
+ }
+
+ return wxNullBitmap;
+}
LoadFile( icon_file, (wxBitmapType) flags, desiredWidth, desiredHeight );
}
+wxIcon::wxIcon(WXHICON icon, const wxSize& size)
+ : wxGDIObject()
+{
+ // as the icon owns that ref, we have to acquire it as well
+ if (icon)
+ AcquireIconRef( (IconRef) icon ) ;
+
+ m_refData = new wxIconRefData( icon ) ;
+ M_ICONDATA->SetWidth( size.x ) ;
+ M_ICONDATA->SetHeight( size.y ) ;
+}
+
wxIcon::~wxIcon()
{
}
{
theId = kAlertStopIcon ;
}
+ else if ( filename == wxT("wxICON_FOLDER") )
+ {
+ theId = kGenericFolderIcon ;
+ }
+ else if ( filename == wxT("wxICON_FOLDER_OPEN") )
+ {
+ theId = kOpenFolderIcon ;
+ }
+ else if ( filename == wxT("wxICON_NORMAL_FILE") )
+ {
+ theId = kGenericDocumentIcon ;
+ }
else
{
#if 0
// Setting icons for window manager:
// ----------------------------------------------------------------------------
-void wxSetIconsX11( WXDisplay* display, WXWindow window,
- const wxIconBundle& ib )
+void
+wxSetIconsX11(WXDisplay* display, WXWindow window, const wxIconBundle& ib)
{
#if !wxUSE_NANOX
size_t size = 0;
- size_t i, max = ib.m_icons.GetCount();
- for( i = 0; i < max; ++i )
- if( ib.m_icons[i].Ok() )
- size += 2 + ib.m_icons[i].GetWidth() * ib.m_icons[i].GetHeight();
+ const size_t numIcons = ib.GetIconCount();
+ for ( size_t i = 0; i < numIcons; ++i )
+ {
+ const wxIcon icon = ib.GetIconByIndex(i);
+
+ size += 2 + icon.GetWidth() * icon.GetHeight();
+ }
wxMAKE_ATOM(_NET_WM_ICON, (Display*)display);
- if( size > 0 )
+ if ( size > 0 )
{
-// The code below is correct for 64-bit machines also.
-// wxUint32* data = new wxUint32[size];
-// wxUint32* ptr = data;
unsigned long* data = new unsigned long[size];
unsigned long* ptr = data;
- for( i = 0; i < max; ++i )
+ for ( size_t i = 0; i < numIcons; ++i )
{
- const wxImage image = ib.m_icons[i].ConvertToImage();
- int width = image.GetWidth(), height = image.GetHeight();
+ const wxImage image = ib.GetIconByIndex(i).ConvertToImage();
+ int width = image.GetWidth(),
+ height = image.GetHeight();
unsigned char* imageData = image.GetData();
unsigned char* imageDataEnd = imageData + ( width * height * 3 );
bool hasMask = image.HasMask();
*ptr++ = width;
*ptr++ = height;
- while( imageData < imageDataEnd ) {
+ while ( imageData < imageDataEnd )
+ {
r = imageData[0];
g = imageData[1];
b = imageData[2];