diff --git a/docs/latex/wx/filetype.tex b/docs/latex/wx/filetype.tex index 30d87dd941..9cbeb4f35a 100644 --- a/docs/latex/wx/filetype.tex +++ b/docs/latex/wx/filetype.tex @@ -152,13 +152,16 @@ function in the first place. \membersection{wxFileType::GetIcon}\label{wxfiletypegeticon} -\func{bool}{GetIcon}{\param{wxIcon*}{ icon}, \param{wxString*}{ iconFile = NULL}, \param{int*}{ iconIndex = NULL}, \param{int}{ iconSize = wxICON\_LARGE}} +\func{bool}{GetIcon}{\param{wxIconLocation *}{ iconLoc}} -If the function returns {\tt TRUE}, the icon associated with this file type will be -created and assigned to the {\it icon} parameter. {\it iconFile} is assigned the file name -that contains the icon and {\it iconIndex} is assigned the index of the icon -(windows and unix only). A 32x32 icon is assigned if {\it iconSize} is wxICON\_LARGE -and a 16x16 icon is assigned if {\it iconSize} is wxICON\_SMALL (windows only). +If the function returns {\tt true}, the {\tt iconLoc} is filled with the +location of the icon for this MIME type. A \helpref{wxIcon}{wxicon} may be +created from {\it iconLoc} later. + +{\bf Windows:} The function returns the icon shown by Explorer for the files of +the specified type. + +{\bf Mac:} This function is not implemented and always returns {\tt false}. {\bf Unix:} MIME manager gathers information about icons from GNOME and KDE settings and thus GetIcon's success depends on availability diff --git a/include/wx/mac/mimetype.h b/include/wx/mac/mimetype.h index 35e1ba7b9b..4f71b9e045 100644 --- a/include/wx/mac/mimetype.h +++ b/include/wx/mac/mimetype.h @@ -83,7 +83,7 @@ public: bool GetExtensions(wxArrayString& extensions); bool GetMimeType(wxString *mimeType) const; bool GetMimeTypes(wxArrayString& mimeTypes) const; - bool GetIcon(wxIcon *icon, wxString *sCommand = NULL, int *iIndex = NULL) const; + bool GetIcon(wxIconLocation *iconLoc) const; bool GetDescription(wxString *desc) const; bool GetOpenCommand(wxString *openCmd, const wxFileType::MessageParameters&) const diff --git a/include/wx/mimetype.h b/include/wx/mimetype.h index ee204f6de5..9494e1ad16 100644 --- a/include/wx/mimetype.h +++ b/include/wx/mimetype.h @@ -30,7 +30,7 @@ #include "wx/dynarray.h" // fwd decls -class WXDLLEXPORT wxIcon; +class WXDLLEXPORT wxIconLocation; class WXDLLEXPORT wxFileTypeImpl; class WXDLLEXPORT wxMimeTypesManagerImpl; @@ -46,9 +46,6 @@ enum wxMailcapStyle wxMAILCAP_ALL = 15 }; -#define wxICON_LARGE 0 -#define wxICON_SMALL 1 - /* TODO: would it be more convenient to have this class? @@ -212,13 +209,8 @@ public: // fill passed in array with all extensions associated with this file // type bool GetExtensions(wxArrayString& extensions); - // get the icon corresponding to this file type, the name of the file - // where the icon resides is return in iconfile if !NULL and its index - // in this file (Win-only) is in iconIndex - bool GetIcon(wxIcon *icon, - wxString *iconFile = NULL, - int *iconIndex = NULL, - int iconSize = wxICON_LARGE) const; + // get the icon corresponding to this file type and of the given size + bool GetIcon(wxIconLocation *iconloc) const; // get a brief file type description ("*.txt" => "text document") bool GetDescription(wxString *desc) const; diff --git a/include/wx/msw/mimetype.h b/include/wx/msw/mimetype.h index 5170b63618..a9ba9b63be 100644 --- a/include/wx/msw/mimetype.h +++ b/include/wx/msw/mimetype.h @@ -44,8 +44,7 @@ public: bool GetExtensions(wxArrayString& extensions); bool GetMimeType(wxString *mimeType) const; bool GetMimeTypes(wxArrayString& mimeTypes) const; - bool GetIcon(wxIcon *icon, wxString *sCommand = NULL, int *iIndex = NULL, - int iconSize = wxICON_LARGE) const; + bool GetIcon(wxIconLocation *iconLoc) const; bool GetDescription(wxString *desc) const; bool GetOpenCommand(wxString *openCmd, const wxFileType::MessageParameters& params) const; diff --git a/include/wx/unix/mimetype.h b/include/wx/unix/mimetype.h index a15f76f881..3f03cf0483 100644 --- a/include/wx/unix/mimetype.h +++ b/include/wx/unix/mimetype.h @@ -177,8 +177,7 @@ public: bool GetMimeType(wxString *mimeType) const { *mimeType = m_manager->m_aTypes[m_index[0]]; return TRUE; } bool GetMimeTypes(wxArrayString& mimeTypes) const; - bool GetIcon(wxIcon *icon, wxString *iconFile = NULL, - int *iconIndex = NULL) const; + bool GetIcon(wxIconLocation *iconLoc) const; bool GetDescription(wxString *desc) const { *desc = m_manager->m_aDescriptions[m_index[0]]; return TRUE; } diff --git a/src/common/mimecmn.cpp b/src/common/mimecmn.cpp index 9b4f0ff3fa..ec98e8097c 100644 --- a/src/common/mimecmn.cpp +++ b/src/common/mimecmn.cpp @@ -39,13 +39,11 @@ #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/iconloc.h" #include "wx/intl.h" #include "wx/dynarray.h" #include "wx/confbase.h" @@ -269,36 +267,22 @@ bool wxFileType::GetMimeTypes(wxArrayString& mimeTypes) const return m_impl->GetMimeTypes(mimeTypes); } -bool wxFileType::GetIcon(wxIcon *icon, - wxString *iconFile, - int *iconIndex, - int iconSize) const +bool wxFileType::GetIcon(wxIconLocation *iconLoc) const { if ( m_info ) { - if ( iconFile ) - *iconFile = m_info->GetIconFile(); - if ( iconIndex ) - *iconIndex = m_info->GetIconIndex(); - -#if wxUSE_GUI - if ( icon && !m_info->GetIconFile().empty() ) + if ( iconLoc ) { - // FIXME: what about the index? - icon->LoadFile(m_info->GetIconFile()); + iconLoc->SetFileName(m_info->GetIconFile()); +#ifdef __WXMSW__ + iconLoc->SetIndex(m_info->GetIconIndex()); +#endif // __WXMSW__ } -#endif // wxUSE_GUI return TRUE; } -#if defined(__WXMSW__) - return m_impl->GetIcon(icon, iconFile, iconIndex, iconSize); -#elif defined(__UNIX__) - return m_impl->GetIcon(icon, iconFile, iconIndex); -#else - return m_impl->GetIcon(icon); -#endif + return m_impl->GetIcon(iconLoc); } bool wxFileType::GetDescription(wxString *desc) const diff --git a/src/mac/carbon/mimetmac.cpp b/src/mac/carbon/mimetmac.cpp index 296c7a81ba..1ea83612c2 100644 --- a/src/mac/carbon/mimetmac.cpp +++ b/src/mac/carbon/mimetmac.cpp @@ -92,7 +92,7 @@ bool wxFileTypeImpl::GetMimeTypes(wxArrayString& mimeTypes) const return FALSE; } -bool wxFileTypeImpl::GetIcon(wxIcon *icon, wxString *sCommand, int *iIndex) const +bool wxFileTypeImpl::GetIcon(wxIconLocation *WXUNUSED(icon)) const { // no such file type or no value or incorrect icon entry return FALSE; diff --git a/src/mac/mimetmac.cpp b/src/mac/mimetmac.cpp index 296c7a81ba..1ea83612c2 100644 --- a/src/mac/mimetmac.cpp +++ b/src/mac/mimetmac.cpp @@ -92,7 +92,7 @@ bool wxFileTypeImpl::GetMimeTypes(wxArrayString& mimeTypes) const return FALSE; } -bool wxFileTypeImpl::GetIcon(wxIcon *icon, wxString *sCommand, int *iIndex) const +bool wxFileTypeImpl::GetIcon(wxIconLocation *WXUNUSED(icon)) const { // no such file type or no value or incorrect icon entry return FALSE; diff --git a/src/msw/mimetype.cpp b/src/msw/mimetype.cpp index 6f488946c5..8e663b816b 100644 --- a/src/msw/mimetype.cpp +++ b/src/msw/mimetype.cpp @@ -35,6 +35,7 @@ #include "wx/log.h" #include "wx/file.h" +#include "wx/iconloc.h" #include "wx/intl.h" #include "wx/dynarray.h" #include "wx/confbase.h" @@ -334,12 +335,8 @@ bool wxFileTypeImpl::GetMimeTypes(wxArrayString& mimeTypes) const } -bool wxFileTypeImpl::GetIcon(wxIcon *icon, - wxString *iconFile, - int *iconIndex, - int iconSize) const +bool wxFileTypeImpl::GetIcon(wxIconLocation *iconLoc) const { -#if wxUSE_GUI wxString strIconKey; strIconKey << m_strFileType << wxT("\\DefaultIcon"); @@ -364,39 +361,18 @@ bool wxFileTypeImpl::GetIcon(wxIcon *icon, strIndex = wxT("0"); } - wxString strExpPath = wxExpandEnvVars(strFullPath); - // here we need C based counting! - int nIndex = wxAtoi(strIndex); + if ( iconLoc ) + { + iconLoc->SetFileName(wxExpandEnvVars(strFullPath)); - HICON hIcon, hIconLarge, hIconSmall; - ExtractIconEx(strExpPath, nIndex, &hIconLarge, &hIconSmall, 1); - - hIcon = (iconSize == wxICON_LARGE) ? hIconLarge : hIconSmall; - - - switch ( (int)hIcon ) { - case 0: // means no icons were found - case 1: // means no such file or it wasn't a DLL/EXE/OCX/ICO/... - wxLogDebug(wxT("incorrect registry entry '%s': no such icon."), - key.GetName().c_str()); - break; - - default: - icon->SetHICON((WXHICON)hIcon); - wxSize size = wxGetHiconSize(hIcon); - icon->SetSize(size); - if ( iconIndex ) - *iconIndex = nIndex; - if ( iconFile ) - *iconFile = strFullPath; - return TRUE; + iconLoc->SetIndex(wxAtoi(strIndex)); } + + return TRUE; } } // no such file type or no value or incorrect icon entry -#endif // wxUSE_GUI - return FALSE; } diff --git a/src/unix/mimetype.cpp b/src/unix/mimetype.cpp index 5f6157c61e..0d1b83011c 100644 --- a/src/unix/mimetype.cpp +++ b/src/unix/mimetype.cpp @@ -1172,12 +1172,9 @@ wxString wxFileTypeImpl::GetExpandedCommand(const wxString & verb, const wxFileT return wxFileType::ExpandCommand(sTmp, params); } -bool wxFileTypeImpl::GetIcon(wxIcon *icon, - wxString *iconFile /*= NULL */, - int *iconIndex /*= NULL*/) const +bool wxFileTypeImpl::GetIcon(wxIconLocation *iconLoc) const { -#if wxUSE_GUI wxString sTmp; size_t i = 0; while ( (i < m_index.GetCount() ) && sTmp.empty() ) @@ -1185,25 +1182,15 @@ bool wxFileTypeImpl::GetIcon(wxIcon *icon, sTmp = m_manager->m_aIcons[m_index[i]]; i ++; } - if ( sTmp.empty () ) return FALSE; + if ( sTmp.empty () ) + return FALSE; - wxIcon icn; - - if (sTmp.Right(4).MakeUpper() == _T(".XPM")) - icn = wxIcon(sTmp); - else - icn = wxIcon(sTmp, wxBITMAP_TYPE_ANY); - - if ( icn.Ok() ) + if ( iconLoc ) { - *icon = icn; - if (iconFile) *iconFile = sTmp; - if (iconIndex) *iconIndex = 0; - return TRUE; + iconLoc->SetIconFile(sTmp); } -#endif // wxUSE_GUI - return FALSE; + return TRUE; }