GetIcon() returns wxIconLocation, not wxIcon, now
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21316 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
80185c6ceb
commit
da0766ab2a
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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; }
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user