From aaf7ab431b85d817af39d1a19b6d392ff5bd9379 Mon Sep 17 00:00:00 2001
From: Vadim Zeitlin <vadim@wxwidgets.org>
Date: Sat, 21 Jun 2003 13:39:40 +0000
Subject: [PATCH] added wxIconLocation; minor fixes to wxIcon on some platforms

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21279 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 docs/latex/wx/classes.tex |  1 +
 docs/latex/wx/icon.tex    |  7 ++++
 docs/latex/wx/iconloc.tex | 47 +++++++++++++++++++++++++
 include/wx/cocoa/icon.h   | 17 +++++----
 include/wx/gtk/icon.h     |  5 +++
 include/wx/gtk1/icon.h    |  5 +++
 include/wx/icon.h         |  6 +---
 include/wx/iconloc.h      | 74 +++++++++++++++++++++++++++++++++++++++
 include/wx/mac/icon.h     | 21 ++++++-----
 include/wx/mgl/icon.h     | 15 +++++---
 include/wx/motif/icon.h   | 30 ++++++++++------
 include/wx/msw/icon.h     |  4 +++
 include/wx/os2/icon.h     |  5 +++
 include/wx/x11/icon.h     | 11 ++++--
 src/motif/icon.cpp        |  7 ----
 src/msw/icon.cpp          | 13 +++++++
 16 files changed, 224 insertions(+), 44 deletions(-)
 create mode 100644 docs/latex/wx/iconloc.tex
 create mode 100644 include/wx/iconloc.h

diff --git a/docs/latex/wx/classes.tex b/docs/latex/wx/classes.tex
index d263aaa0a5..a8d555ce31 100644
--- a/docs/latex/wx/classes.tex
+++ b/docs/latex/wx/classes.tex
@@ -157,6 +157,7 @@
 \input http.tex
 \input icon.tex
 \input iconbndl.tex
+\input iconloc.tex
 \input iconevt.tex
 \input idleevt.tex
 \input image.tex
diff --git a/docs/latex/wx/icon.tex b/docs/latex/wx/icon.tex
index 7d2ca62537..4a7243fa00 100644
--- a/docs/latex/wx/icon.tex
+++ b/docs/latex/wx/icon.tex
@@ -85,6 +85,10 @@ Creates an icon from XPM data.
 
 Loads an icon from a file or resource.
 
+\func{}{wxIcon}{\param{const wxIconLocation\& }{loc}}
+
+Loads an icon from the specified \helpref{location}{wxiconlocation}.
+
 \wxheading{Parameters}
 
 \docparam{bits}{Specifies an array of pixel values.}
@@ -107,6 +111,9 @@ screen is used.}
 \docparam{name}{This can refer to a resource name under MS Windows, or a filename under MS Windows and X.
 Its meaning is determined by the {\it flags} parameter.}
 
+\docparam{loc}{The object describing the location of the native icon, see 
+\helpref{wxIconLocation}{wxiconlocation}.}
+
 \docparam{type}{May be one of the following:
 
 \twocolwidtha{5cm}
diff --git a/docs/latex/wx/iconloc.tex b/docs/latex/wx/iconloc.tex
new file mode 100644
index 0000000000..c379121dcb
--- /dev/null
+++ b/docs/latex/wx/iconloc.tex
@@ -0,0 +1,47 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% Name:        iconloc.tex
+%% Purpose:     wxIconLocation documentation
+%% Author:      Vadim Zeitlin
+%% Modified by:
+%% Created:     21.06.03
+%% RCS-ID:      $Id$
+%% Copyright:   (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
+%% License:     wxWindows license
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\section{\class{wxIconLocation}}\label{wxiconlocation}
+
+wxIconLocation is a tiny class describing the location of an (external, i.e.
+not embedded into the application resources) icon. For most platforms it simply
+contains the file name but under some others (notably Windows) the same file
+may contain multiple icons and so this class also stores the index of the icon
+inside the file.
+
+In any case, its details should be of no interest to the application code and
+most of them are not even documented here (on purpose) as it is only meant to
+be used as an opaque class: the application may get the object of this class
+from somewhere and the only reasonable thing to do with it later is to create
+a \helpref{wxIcon}{wxicon} from it.
+
+\wxheading{Derived from}
+
+None.
+
+\wxheading{Include files}
+
+<wx/iconloc.h>
+
+\wxheading{See also}
+
+\wxheading{wxIcon}{wxicon}, \helpref{wxFileType::GetIcon()}{wxfiletypegeticon}
+
+
+\latexignore{\rtfignore{\wxheading{Members}}}
+
+\membersection{wxIconLocation::IsOk}\label{wxiconlocationisok}
+
+\constfunc{bool}{IsOk}{\void}
+
+Returns {\tt true} if the object is valid, i.e. was properly initialized, and 
+{\tt false} otherwise.
+
diff --git a/include/wx/cocoa/icon.h b/include/wx/cocoa/icon.h
index b1f045c714..d1247f393d 100644
--- a/include/wx/cocoa/icon.h
+++ b/include/wx/cocoa/icon.h
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        icon.h
+// Name:        wx/cocoa/icon.h
 // Purpose:     wxIcon class
 // Author:      AUTHOR
 // Modified by:
@@ -36,17 +36,22 @@ public:
   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 ) ; } 
+  	{ 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); }
 
-  inline wxIcon& operator = (const wxIcon& icon) { if (*this == icon) return (*this); Ref(icon); return *this; }
-  inline bool operator == (const wxIcon& icon) { return m_refData == icon.m_refData; }
-  inline bool operator != (const wxIcon& icon) { return m_refData != icon.m_refData; }
-  
   // 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
diff --git a/include/wx/gtk/icon.h b/include/wx/gtk/icon.h
index be2f6be3d8..10bb5b12a2 100644
--- a/include/wx/gtk/icon.h
+++ b/include/wx/gtk/icon.h
@@ -45,6 +45,11 @@ public:
     }
     wxIcon( char **bits, int width=-1, int height=-1 );
 
+    wxIcon(const wxIconLocation& loc)
+        : wxBitmap(loc.GetFileName(), wxBITMAP_TYPE_XPM)
+    {
+    }
+
     wxIcon& operator=(const wxIcon& icon);
     bool operator==(const wxIcon& icon) const { return m_refData == icon.m_refData; }
     bool operator!=(const wxIcon& icon) const { return !(*this == icon); }
diff --git a/include/wx/gtk1/icon.h b/include/wx/gtk1/icon.h
index be2f6be3d8..10bb5b12a2 100644
--- a/include/wx/gtk1/icon.h
+++ b/include/wx/gtk1/icon.h
@@ -45,6 +45,11 @@ public:
     }
     wxIcon( char **bits, int width=-1, int height=-1 );
 
+    wxIcon(const wxIconLocation& loc)
+        : wxBitmap(loc.GetFileName(), wxBITMAP_TYPE_XPM)
+    {
+    }
+
     wxIcon& operator=(const wxIcon& icon);
     bool operator==(const wxIcon& icon) const { return m_refData == icon.m_refData; }
     bool operator!=(const wxIcon& icon) const { return !(*this == icon); }
diff --git a/include/wx/icon.h b/include/wx/icon.h
index 6d89222629..1f273ebb07 100644
--- a/include/wx/icon.h
+++ b/include/wx/icon.h
@@ -1,11 +1,7 @@
 #ifndef _WX_ICON_H_BASE_
 #define _WX_ICON_H_BASE_
 
-/* Commenting out since duplicated in gdicmn.h
-// this is for Unix (i.e. now for anything other than MSW)
-#undef  wxICON
-#define wxICON(icon_name)   wxIcon(icon_name##_xpm)
-*/
+#include "wx/iconloc.h"
 
 #if defined(__WXMSW__)
   #include "wx/msw/icon.h"
diff --git a/include/wx/iconloc.h b/include/wx/iconloc.h
new file mode 100644
index 0000000000..2ace40208b
--- /dev/null
+++ b/include/wx/iconloc.h
@@ -0,0 +1,74 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        wx/iconloc.h
+// Purpose:     declaration of wxIconLocation class
+// Author:      Vadim Zeitlin
+// Modified by:
+// Created:     21.06.2003
+// RCS-ID:      $Id$
+// Copyright:   (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
+// Licence:     wxWindows licence
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef _WX_ICONLOC_H_
+#define _WX_ICONLOC_H_
+
+#include "wx/string.h"
+
+// ----------------------------------------------------------------------------
+// wxIconLocation: describes the location of an icon
+// ----------------------------------------------------------------------------
+
+class WXDLLEXPORT wxIconLocationBase
+{
+public:
+    // ctor takes the name of the file where the icon is
+    wxEXPLICIT wxIconLocationBase(const wxString& file) : m_filename(file) { }
+
+    // default copy ctor, assignment operator and dtor are ok
+
+
+    // returns true if this object is valid/initialized
+    bool IsOk() const { return !m_filename.empty(); }
+
+    // set/get the icon file name
+    void SetFileName(const wxString& file) { m_filename = file; }
+    const wxString& GetFileName() const { return m_filename; }
+
+private:
+    wxString m_filename;
+};
+
+// under MSW the same file may contain several icons so we also store the
+// index of the icon
+#if defined(__WXMSW__)
+
+class WXDLLEXPORT wxIconLocation : public wxIconLocationBase
+{
+public:
+    // ctor takes the name of the file where the icon is and the icons index in
+    // the file
+    wxEXPLICIT wxIconLocation(const wxString& file, int num = 0);
+
+    // set/get the icon index
+    void SetIndex(int num) { m_index = num; }
+    int GetIndex() const { return m_index; }
+
+private:
+    int m_index;
+};
+
+inline
+wxIconLocation::wxIconLocation(const wxString& file, int num)
+              : wxIconLocationBase(file)
+{
+    SetIndex(num);
+}
+
+#else // !MSW
+
+typedef wxIconLocationBase wxIconLocation;
+
+#endif // platform
+
+#endif // _WX_ICONLOC_H_
+
diff --git a/include/wx/mac/icon.h b/include/wx/mac/icon.h
index 0993fa4305..88b40740cc 100644
--- a/include/wx/mac/icon.h
+++ b/include/wx/mac/icon.h
@@ -21,8 +21,6 @@
 // Icon
 class WXDLLEXPORT wxIcon: public wxBitmap
 {
-  DECLARE_DYNAMIC_CLASS(wxIcon)
-
 public:
   wxIcon();
 
@@ -35,22 +33,29 @@ public:
   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);
+         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 ) ; } 
+      { 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); }
 
-  inline wxIcon& operator = (const wxIcon& icon) { if (*this == icon) return (*this); Ref(icon); return *this; }
-  inline bool operator == (const wxIcon& icon) { return m_refData == icon.m_refData; }
-  inline bool operator != (const wxIcon& icon) { return m_refData != icon.m_refData; }
-  
   // 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);
+
+  DECLARE_DYNAMIC_CLASS(wxIcon)
 };
 
 /*
diff --git a/include/wx/mgl/icon.h b/include/wx/mgl/icon.h
index ca3007a15b..a555b70552 100644
--- a/include/wx/mgl/icon.h
+++ b/include/wx/mgl/icon.h
@@ -42,16 +42,21 @@ public:
     wxIcon(const wxString& filename, int type = wxBITMAP_TYPE_ICO_RESOURCE,
            int WXUNUSED(desiredWidth)=-1, int WXUNUSED(desiredHeight)=-1 ) :
            wxBitmap(filename, (wxBitmapType)type) {}
-    
-    wxIcon& operator = (const wxIcon& icon);
-    inline bool operator == (const wxIcon& icon) { return m_refData == icon.m_refData; }
-    inline bool operator != (const wxIcon& icon) { return m_refData != icon.m_refData; }
+
+    wxIcon(const wxIconLocation& loc)
+        : wxBitmap(loc.GetFileName(), wxBITMAP_TYPE_ICO)
+    {
+    }
+
+    wxIcon& operator=(const wxIcon& icon);
+    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);
-  
+
 private:
     DECLARE_DYNAMIC_CLASS(wxIcon)
 };
diff --git a/include/wx/motif/icon.h b/include/wx/motif/icon.h
index ec4b1a4050..1f2fab60b9 100644
--- a/include/wx/motif/icon.h
+++ b/include/wx/motif/icon.h
@@ -19,10 +19,8 @@
 #include "wx/bitmap.h"
 
 // Icon
-class WXDLLEXPORT wxIcon: public wxBitmap
+class WXDLLEXPORT wxIcon : public wxBitmap
 {
-    DECLARE_DYNAMIC_CLASS(wxIcon);
-        
 public:
     wxIcon();
     
@@ -37,23 +35,35 @@ public:
     wxIcon(char **data);
     
     wxIcon(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_XPM,
-        int desiredWidth = -1, int desiredHeight = -1);
+           int desiredWidth = -1, int desiredHeight = -1)
+    {
+        LoadFile(name, type, desiredWidth, desiredHeight);
+    }
+
+    wxIcon(const wxIconLocation& loc)
+    {
+        LoadFile(loc.GetFileName());
+    }
+
     ~wxIcon();
     
     bool LoadFile(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_XPM,
-        int desiredWidth = -1, int desiredHeight = -1);
+                  int desiredWidth = -1, int desiredHeight = -1);
 
     // 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);
     
-    inline wxIcon& operator = (const wxIcon& icon)
-        { if (*this == icon) return (*this); Ref(icon); return *this; }
-    inline bool operator == (const wxIcon& icon) const
+    wxIcon& operator = (const wxIcon& icon)
+        { if (this != &icon) Ref(icon); return *this; }
+    bool operator == (const wxIcon& icon) const
         { return m_refData == icon.m_refData; }
-    inline bool operator != (const wxIcon& icon) const
-        { return m_refData != icon.m_refData; }
+    bool operator != (const wxIcon& icon) const
+        { return !(*this == icon); }
+
+
+    DECLARE_DYNAMIC_CLASS(wxIcon);
 };
 
 #endif // _WX_ICON_H_
diff --git a/include/wx/msw/icon.h b/include/wx/msw/icon.h
index a83ec7baa4..f9a08a3c91 100644
--- a/include/wx/msw/icon.h
+++ b/include/wx/msw/icon.h
@@ -53,15 +53,19 @@ public:
 
         // from raw data
     wxIcon(const char bits[], int width, int height);
+
         // from XPM data
     wxIcon(const char **data) { CreateIconFromXpm(data); }
 
     wxIcon(char **data) { CreateIconFromXpm((const char **)data); }
+
         // from resource/file
     wxIcon(const wxString& name,
            long type = wxBITMAP_TYPE_ICO_RESOURCE,
            int desiredWidth = -1, int desiredHeight = -1);
 
+    wxIcon(const wxIconLocation& loc);
+
     virtual ~wxIcon();
 
     virtual bool LoadFile(const wxString& name,
diff --git a/include/wx/os2/icon.h b/include/wx/os2/icon.h
index 035506f8c7..3f138fb02a 100644
--- a/include/wx/os2/icon.h
+++ b/include/wx/os2/icon.h
@@ -66,6 +66,11 @@ public:
            ,int             nDesiredWidth = -1
            ,int             nDesiredHeight = -1
           );
+    wxIcon(const wxIconLocation& loc)
+    {
+        LoadFile(loc.GetFileName(), wxBITMAP_TYPE_ICO);
+    }
+
     ~wxIcon();
 
     bool LoadFile( const wxString& rName
diff --git a/include/wx/x11/icon.h b/include/wx/x11/icon.h
index 1f3314b6bd..95ec79f429 100644
--- a/include/wx/x11/icon.h
+++ b/include/wx/x11/icon.h
@@ -38,9 +38,14 @@ public:
     }
     wxIcon( char **bits, int width=-1, int height=-1 );
 
-    wxIcon& operator = (const wxIcon& icon);
-    inline bool operator == (const wxIcon& icon) { return m_refData == icon.m_refData; }
-    inline bool operator != (const wxIcon& icon) { return m_refData != icon.m_refData; }
+    wxIcon(const wxIconLocation& loc)
+        : wxBitmap(loc.GetFileName(), wxBITMAP_TYPE_XPM)
+    {
+    }
+
+    wxIcon& operator=(const wxIcon& icon);
+    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
diff --git a/src/motif/icon.cpp b/src/motif/icon.cpp
index 54edd5f3cb..e8316d4b9d 100644
--- a/src/motif/icon.cpp
+++ b/src/motif/icon.cpp
@@ -42,13 +42,6 @@ wxIcon::wxIcon(const char **data)
     (void) Create((void*) data, wxBITMAP_TYPE_XPM_DATA, 0, 0, 0);
 }
 
-wxIcon::wxIcon(const wxString& icon_file, wxBitmapType type,
-               int desiredWidth, int desiredHeight)
-               
-{
-    LoadFile(icon_file, type, desiredWidth, desiredHeight);
-}
-
 void wxIcon::CopyFromBitmap(const wxBitmap& bmp)
 {
     wxIcon *icon = (wxIcon*)(&bmp);
diff --git a/src/msw/icon.cpp b/src/msw/icon.cpp
index c0070fc713..74460dff34 100644
--- a/src/msw/icon.cpp
+++ b/src/msw/icon.cpp
@@ -85,6 +85,19 @@ wxIcon::wxIcon(const wxString& iconfile,
     LoadFile(iconfile, flags, desiredWidth, desiredHeight);
 }
 
+wxIcon::wxIcon(const wxIconLocation& loc)
+{
+    // wxICOFileHandler accepts names in the format "filename;index"
+    wxString fullname = loc.GetFileName();
+    if ( loc.GetIndex() )
+    {
+        fullname << _T(';') << loc.GetIndex();
+    }
+    //else: 0 is default
+
+    LoadFile(fullname);
+}
+
 wxIcon::~wxIcon()
 {
 }
-- 
2.50.0

