adding mimetype patch, closes #12072
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64671 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1,174 +1,119 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Name: wx/osx/core/mimetype.h
|
// Name: wx/osx/core/mimetype.h
|
||||||
// Purpose: classes and functions to manage MIME types
|
// Purpose: Mac implementation for wx mime-related classes
|
||||||
// Author: Vadim Zeitlin
|
// Author: Neil Perkins
|
||||||
// Modified by:
|
// Modified by:
|
||||||
// Created: 23.09.98
|
// Created: 2010-05-15
|
||||||
// RCS-ID: $Id: mimetype.h 54448 2008-07-01 09:28:08Z RR $
|
// RCS-ID: $Id: mimetype.h 54448 2008-07-01 09:28:08Z RR $
|
||||||
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
|
// Copyright: (C) 2010 Neil Perkins
|
||||||
// Licence: wxWindows licence (part of wxExtra library)
|
// Licence: wxWindows licence
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef _MIMETYPE_IMPL_H
|
#ifndef _MIMETYPE_IMPL_H
|
||||||
#define _MIMETYPE_IMPL_H
|
#define _MIMETYPE_IMPL_H
|
||||||
|
|
||||||
#include "wx/mimetype.h"
|
#include "wx/defs.h"
|
||||||
|
|
||||||
#if wxUSE_MIMETYPE
|
#if wxUSE_MIMETYPE
|
||||||
|
|
||||||
class wxMimeTypeCommands;
|
#include "wx/mimetype.h"
|
||||||
|
#include "wx/hashmap.h"
|
||||||
|
#include "wx/iconloc.h"
|
||||||
|
|
||||||
WX_DEFINE_ARRAY_PTR(wxMimeTypeCommands *, wxMimeCommandsArray);
|
|
||||||
|
|
||||||
// this is the real wxMimeTypesManager for Unix
|
// This class implements mime type functionality for Mac OS X using UTIs and Launch Services
|
||||||
|
// Currently only the GetFileTypeFromXXXX public functions have been implemented
|
||||||
class WXDLLIMPEXP_BASE wxMimeTypesManagerImpl
|
class WXDLLIMPEXP_BASE wxMimeTypesManagerImpl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// ctor and dtor
|
|
||||||
wxMimeTypesManagerImpl();
|
wxMimeTypesManagerImpl();
|
||||||
virtual ~wxMimeTypesManagerImpl();
|
virtual ~wxMimeTypesManagerImpl();
|
||||||
|
|
||||||
// load all data into memory - done when it is needed for the first time
|
// These functions are not needed on Mac OS X and have no-op implementations
|
||||||
void Initialize(int mailcapStyles = wxMAILCAP_ALL,
|
void Initialize(int mailcapStyles = wxMAILCAP_STANDARD, const wxString& extraDir = wxEmptyString);
|
||||||
const wxString& extraDir = wxEmptyString);
|
|
||||||
|
|
||||||
// and delete the data here
|
|
||||||
void ClearData();
|
void ClearData();
|
||||||
|
|
||||||
// implement containing class functions
|
// Functions to look up types by ext, mime or UTI
|
||||||
wxFileType *GetFileTypeFromExtension(const wxString& ext);
|
wxFileType *GetFileTypeFromExtension(const wxString& ext);
|
||||||
wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
|
wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
|
||||||
|
wxFileType *GetFileTypeFromUti(const wxString& uti);
|
||||||
|
|
||||||
|
// These functions are only stubs on Mac OS X
|
||||||
size_t EnumAllFileTypes(wxArrayString& mimetypes);
|
size_t EnumAllFileTypes(wxArrayString& mimetypes);
|
||||||
|
|
||||||
void AddFallback(const wxFileTypeInfo& filetype);
|
|
||||||
|
|
||||||
// add information about the given mimetype
|
|
||||||
void AddMimeTypeInfo(const wxString& mimetype,
|
|
||||||
const wxString& extensions,
|
|
||||||
const wxString& description);
|
|
||||||
void AddMailcapInfo(const wxString& strType,
|
|
||||||
const wxString& strOpenCmd,
|
|
||||||
const wxString& strPrintCmd,
|
|
||||||
const wxString& strTest,
|
|
||||||
const wxString& strDesc);
|
|
||||||
|
|
||||||
// add a new record to the user .mailcap/.mime.types files
|
|
||||||
wxFileType *Associate(const wxFileTypeInfo& ftInfo);
|
wxFileType *Associate(const wxFileTypeInfo& ftInfo);
|
||||||
// remove association
|
|
||||||
bool Unassociate(wxFileType *ft);
|
bool Unassociate(wxFileType *ft);
|
||||||
|
|
||||||
// accessors
|
private:
|
||||||
// get the string containing space separated extensions for the given
|
|
||||||
// file type
|
|
||||||
wxString GetExtension(size_t index) { return m_aExtensions[index]; }
|
|
||||||
|
|
||||||
protected:
|
// The work of querying the OS for type data is done in these two functions
|
||||||
void InitIfNeeded();
|
void LoadTypeDataForUti(const wxString& uti);
|
||||||
|
void LoadDisplayDataForUti(const wxString& uti);
|
||||||
|
|
||||||
wxArrayString m_aTypes, // MIME types
|
// These functions are pass-throughs from wxFileTypeImpl
|
||||||
m_aDescriptions, // descriptions (just some text)
|
bool GetExtensions(const wxString& uti, wxArrayString& extensions);
|
||||||
m_aExtensions, // space separated list of extensions
|
bool GetMimeType(const wxString& uti, wxString *mimeType);
|
||||||
m_aIcons; // Icon filenames
|
bool GetMimeTypes(const wxString& uti, wxArrayString& mimeTypes);
|
||||||
|
bool GetIcon(const wxString& uti, wxIconLocation *iconLoc);
|
||||||
|
bool GetDescription(const wxString& uti, wxString *desc);
|
||||||
|
|
||||||
// verb=command pairs for this file type
|
// Structure to represent file types
|
||||||
wxMimeCommandsArray m_aEntries;
|
typedef struct FileTypeData
|
||||||
|
{
|
||||||
|
wxArrayString extensions;
|
||||||
|
wxArrayString mimeTypes;
|
||||||
|
wxIconLocation iconLoc;
|
||||||
|
wxString description;
|
||||||
|
}
|
||||||
|
FileTypeInfo;
|
||||||
|
|
||||||
// are we initialized?
|
// Map types
|
||||||
bool m_initialized;
|
WX_DECLARE_STRING_HASH_MAP( wxString, TagMap );
|
||||||
|
WX_DECLARE_STRING_HASH_MAP( FileTypeData, UtiMap );
|
||||||
|
|
||||||
wxString GetCommand(const wxString &verb, size_t nIndex) const;
|
// Data store
|
||||||
|
TagMap m_extMap;
|
||||||
|
TagMap m_mimeMap;
|
||||||
|
UtiMap m_utiMap;
|
||||||
|
|
||||||
// Read XDG *.desktop file
|
friend class wxFileTypeImpl;
|
||||||
void LoadXDGApp(const wxString& filename);
|
|
||||||
// Scan XDG directory
|
|
||||||
void LoadXDGAppsFilesFromDir(const wxString& dirname);
|
|
||||||
|
|
||||||
// Load XDG globs files
|
|
||||||
void LoadXDGGlobs(const wxString& filename);
|
|
||||||
|
|
||||||
// functions used to do associations
|
|
||||||
virtual int AddToMimeData(const wxString& strType,
|
|
||||||
const wxString& strIcon,
|
|
||||||
wxMimeTypeCommands *entry,
|
|
||||||
const wxArrayString& strExtensions,
|
|
||||||
const wxString& strDesc,
|
|
||||||
bool replaceExisting = true);
|
|
||||||
virtual bool DoAssociation(const wxString& strType,
|
|
||||||
const wxString& strIcon,
|
|
||||||
wxMimeTypeCommands *entry,
|
|
||||||
const wxArrayString& strExtensions,
|
|
||||||
const wxString& strDesc);
|
|
||||||
|
|
||||||
// give it access to m_aXXX variables
|
|
||||||
friend class WXDLLIMPEXP_FWD_BASE wxFileTypeImpl;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// This class provides the interface between wxFileType and wxMimeTypesManagerImple for Mac OS X
|
||||||
|
// Currently only extension, mimetype, description and icon information is available
|
||||||
|
// All other methods have no-op implementation
|
||||||
class WXDLLIMPEXP_BASE wxFileTypeImpl
|
class WXDLLIMPEXP_BASE wxFileTypeImpl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// initialization functions
|
|
||||||
// this is used to construct a list of mimetypes which match;
|
|
||||||
// if built with GetFileTypeFromMimetype index 0 has the exact match and
|
|
||||||
// index 1 the type / * match
|
|
||||||
// if built with GetFileTypeFromExtension, index 0 has the mimetype for
|
|
||||||
// the first extension found, index 1 for the second and so on
|
|
||||||
|
|
||||||
void Init(wxMimeTypesManagerImpl *manager, size_t index)
|
wxFileTypeImpl();
|
||||||
{ m_manager = manager; m_index.Add(index); }
|
virtual ~wxFileTypeImpl();
|
||||||
|
|
||||||
// accessors
|
bool GetExtensions(wxArrayString& extensions) const ;
|
||||||
bool GetExtensions(wxArrayString& extensions);
|
bool GetMimeType(wxString *mimeType) const ;
|
||||||
bool GetMimeType(wxString *mimeType) const
|
bool GetMimeTypes(wxArrayString& mimeTypes) const ;
|
||||||
{ *mimeType = m_manager->m_aTypes[m_index[0]]; return true; }
|
bool GetIcon(wxIconLocation *iconLoc) const ;
|
||||||
bool GetMimeTypes(wxArrayString& mimeTypes) const;
|
bool GetDescription(wxString *desc) const ;
|
||||||
bool GetIcon(wxIconLocation *iconLoc) const;
|
|
||||||
|
|
||||||
bool GetDescription(wxString *desc) const
|
// These functions are only stubs on Mac OS X
|
||||||
{ *desc = m_manager->m_aDescriptions[m_index[0]]; return true; }
|
bool GetOpenCommand(wxString *openCmd, const wxFileType::MessageParameters& params) const;
|
||||||
|
bool GetPrintCommand(wxString *printCmd, const wxFileType::MessageParameters& params) const;
|
||||||
bool GetOpenCommand(wxString *openCmd,
|
size_t GetAllCommands(wxArrayString *verbs, wxArrayString *commands, const wxFileType::MessageParameters& params) const;
|
||||||
const wxFileType::MessageParameters& params) const
|
bool SetCommand(const wxString& cmd, const wxString& verb, bool overwriteprompt = TRUE);
|
||||||
{
|
|
||||||
*openCmd = GetExpandedCommand(wxT("open"), params);
|
|
||||||
return (! openCmd -> IsEmpty() );
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GetPrintCommand(wxString *printCmd,
|
|
||||||
const wxFileType::MessageParameters& params) const
|
|
||||||
{
|
|
||||||
*printCmd = GetExpandedCommand(wxT("print"), params);
|
|
||||||
return (! printCmd -> IsEmpty() );
|
|
||||||
}
|
|
||||||
|
|
||||||
// return the number of commands defined for this file type, 0 if none
|
|
||||||
size_t GetAllCommands(wxArrayString *verbs, wxArrayString *commands,
|
|
||||||
const wxFileType::MessageParameters& params) const;
|
|
||||||
|
|
||||||
|
|
||||||
// remove the record for this file type
|
|
||||||
// probably a mistake to come here, use wxMimeTypesManager.Unassociate (ft) instead
|
|
||||||
bool Unassociate(wxFileType *ft)
|
|
||||||
{
|
|
||||||
return m_manager->Unassociate(ft);
|
|
||||||
}
|
|
||||||
|
|
||||||
// set an arbitrary command, ask confirmation if it already exists and
|
|
||||||
// overwriteprompt is TRUE
|
|
||||||
bool SetCommand(const wxString& cmd, const wxString& verb, bool overwriteprompt = true);
|
|
||||||
bool SetDefaultIcon(const wxString& strIcon = wxEmptyString, int index = 0);
|
bool SetDefaultIcon(const wxString& strIcon = wxEmptyString, int index = 0);
|
||||||
|
bool Unassociate(wxFileType *ft);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxString
|
|
||||||
GetExpandedCommand(const wxString & verb,
|
|
||||||
const wxFileType::MessageParameters& params) const;
|
|
||||||
|
|
||||||
wxMimeTypesManagerImpl *m_manager;
|
// All that is needed to query type info - UTI and pointer to the manager
|
||||||
wxArrayInt m_index; // in the wxMimeTypesManagerImpl arrays
|
wxString m_uti;
|
||||||
|
wxMimeTypesManagerImpl* m_manager;
|
||||||
|
|
||||||
|
friend class wxMimeTypesManagerImpl;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // wxUSE_MIMETYPE
|
#endif // wxUSE_MIMETYPE
|
||||||
|
#endif //_MIMETYPE_IMPL_H
|
||||||
#endif // _MIMETYPE_IMPL_H
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -58,6 +58,11 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
DECLARE_DYNAMIC_CLASS(wxIcon)
|
DECLARE_DYNAMIC_CLASS(wxIcon)
|
||||||
|
|
||||||
|
bool LoadIconFromSystemResource(const wxString& resourceName, int desiredWidth, int desiredHeight);
|
||||||
|
bool LoadIconFromBundleResource(const wxString& resourceName, int desiredWidth, int desiredHeight);
|
||||||
|
bool LoadIconFromFile(const wxString& filename, int desiredWidth, int desiredHeight);
|
||||||
|
bool LoadIconAsBitmap(const wxString& filename, wxBitmapType flags = wxICON_DEFAULT_TYPE, int desiredWidth = -1, int desiredHeight = -1);
|
||||||
};
|
};
|
||||||
|
|
||||||
class WXDLLIMPEXP_CORE wxICONResourceHandler: public wxBitmapHandler
|
class WXDLLIMPEXP_CORE wxICONResourceHandler: public wxBitmapHandler
|
||||||
|
@@ -48,7 +48,7 @@
|
|||||||
// implementation classes:
|
// implementation classes:
|
||||||
#if defined(__WXMSW__)
|
#if defined(__WXMSW__)
|
||||||
#include "wx/msw/mimetype.h"
|
#include "wx/msw/mimetype.h"
|
||||||
#elif ( defined(__WXMAC__) && wxOSX_USE_CARBON )
|
#elif ( defined(__WXMAC__) )
|
||||||
#include "wx/osx/mimetype.h"
|
#include "wx/osx/mimetype.h"
|
||||||
#elif defined(__WXPM__) || defined (__EMX__)
|
#elif defined(__WXPM__) || defined (__EMX__)
|
||||||
#include "wx/os2/mimetype.h"
|
#include "wx/os2/mimetype.h"
|
||||||
|
@@ -167,178 +167,248 @@ void wxIcon::SetHeight( int WXUNUSED(height) )
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load an icon based on resource name or filel name
|
||||||
|
// Return true on success, false otherwise
|
||||||
bool wxIcon::LoadFile(
|
bool wxIcon::LoadFile(
|
||||||
const wxString& filename, wxBitmapType type,
|
const wxString& filename, wxBitmapType type,
|
||||||
int desiredWidth, int desiredHeight )
|
int desiredWidth, int desiredHeight )
|
||||||
{
|
{
|
||||||
UnRef();
|
if( type == wxBITMAP_TYPE_ICON_RESOURCE )
|
||||||
|
|
||||||
if ( type == wxBITMAP_TYPE_ICON_RESOURCE )
|
|
||||||
{
|
{
|
||||||
OSType theId = 0 ;
|
if( LoadIconFromSystemResource( filename, desiredWidth, desiredHeight ) )
|
||||||
|
return true;
|
||||||
if ( filename == wxT("wxICON_INFORMATION") )
|
|
||||||
{
|
|
||||||
theId = kAlertNoteIcon ;
|
|
||||||
}
|
|
||||||
else if ( filename == wxT("wxICON_QUESTION") )
|
|
||||||
{
|
|
||||||
theId = kAlertCautionIcon ;
|
|
||||||
}
|
|
||||||
else if ( filename == wxT("wxICON_WARNING") )
|
|
||||||
{
|
|
||||||
theId = kAlertCautionIcon ;
|
|
||||||
}
|
|
||||||
else if ( filename == wxT("wxICON_ERROR") )
|
|
||||||
{
|
|
||||||
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 ( filename == wxT("wxICON_EXECUTABLE_FILE") )
|
|
||||||
{
|
|
||||||
theId = kGenericApplicationIcon ;
|
|
||||||
}
|
|
||||||
else if ( filename == wxT("wxICON_CDROM") )
|
|
||||||
{
|
|
||||||
theId = kGenericCDROMIcon ;
|
|
||||||
}
|
|
||||||
else if ( filename == wxT("wxICON_FLOPPY") )
|
|
||||||
{
|
|
||||||
theId = kGenericFloppyIcon ;
|
|
||||||
}
|
|
||||||
else if ( filename == wxT("wxICON_HARDDISK") )
|
|
||||||
{
|
|
||||||
theId = kGenericHardDiskIcon ;
|
|
||||||
}
|
|
||||||
else if ( filename == wxT("wxICON_REMOVABLE") )
|
|
||||||
{
|
|
||||||
theId = kGenericRemovableMediaIcon ;
|
|
||||||
}
|
|
||||||
else if ( filename == wxT("wxICON_DELETE") )
|
|
||||||
{
|
|
||||||
theId = kToolbarDeleteIcon ;
|
|
||||||
}
|
|
||||||
else if ( filename == wxT("wxICON_GO_BACK") )
|
|
||||||
{
|
|
||||||
theId = kBackwardArrowIcon ;
|
|
||||||
}
|
|
||||||
else if ( filename == wxT("wxICON_GO_FORWARD") )
|
|
||||||
{
|
|
||||||
theId = kForwardArrowIcon ;
|
|
||||||
}
|
|
||||||
else if ( filename == wxT("wxICON_GO_HOME") )
|
|
||||||
{
|
|
||||||
theId = kToolbarHomeIcon ;
|
|
||||||
}
|
|
||||||
else if ( filename == wxT("wxICON_HELP_SETTINGS") )
|
|
||||||
{
|
|
||||||
theId = kGenericFontIcon ;
|
|
||||||
}
|
|
||||||
else if ( filename == wxT("wxICON_HELP_PAGE") )
|
|
||||||
{
|
|
||||||
theId = kGenericDocumentIcon ;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
return LoadIconFromBundleResource( filename, desiredWidth, desiredHeight );
|
||||||
IconRef iconRef = NULL ;
|
}
|
||||||
|
else if( type == wxBITMAP_TYPE_ICON )
|
||||||
// first look in the resource fork
|
{
|
||||||
if ( iconRef == NULL )
|
return LoadIconFromFile( filename, desiredWidth, desiredHeight );
|
||||||
{
|
|
||||||
Str255 theName ;
|
|
||||||
|
|
||||||
wxMacStringToPascal( filename , theName ) ;
|
|
||||||
Handle resHandle = GetNamedResource( 'icns' , theName ) ;
|
|
||||||
if ( resHandle != 0L )
|
|
||||||
{
|
|
||||||
IconFamilyHandle iconFamily = (IconFamilyHandle) resHandle ;
|
|
||||||
HLock((Handle) iconFamily);
|
|
||||||
OSStatus err = GetIconRefFromIconFamilyPtr( *iconFamily, GetHandleSize((Handle) iconFamily), &iconRef );
|
|
||||||
HUnlock((Handle) iconFamily);
|
|
||||||
if ( err != noErr )
|
|
||||||
{
|
|
||||||
wxFAIL_MSG("Error when constructing icon ref");
|
|
||||||
}
|
|
||||||
|
|
||||||
ReleaseResource( resHandle ) ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( iconRef == NULL )
|
|
||||||
{
|
|
||||||
// TODO add other attempts to load it from files etc here
|
|
||||||
}
|
|
||||||
if ( iconRef )
|
|
||||||
{
|
|
||||||
m_refData = new wxIconRefData( (WXHICON) iconRef, desiredWidth, desiredHeight ) ;
|
|
||||||
return true ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( theId != 0 )
|
|
||||||
{
|
|
||||||
IconRef iconRef = NULL ;
|
|
||||||
verify_noerr( GetIconRef( kOnSystemDisk, kSystemIconsCreator, theId, &iconRef ) ) ;
|
|
||||||
if ( iconRef )
|
|
||||||
{
|
|
||||||
m_refData = new wxIconRefData( (WXHICON) iconRef, desiredWidth, desiredHeight ) ;
|
|
||||||
|
|
||||||
return true ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false ;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wxBitmapHandler *handler = wxBitmap::FindHandler( type );
|
return LoadIconAsBitmap( filename, type, desiredWidth, desiredHeight );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( handler )
|
// Load a well known system icon by its wxWidgets identifier
|
||||||
|
// Returns true on success, false otherwise
|
||||||
|
bool wxIcon::LoadIconFromSystemResource(const wxString& resourceName, int desiredWidth, int desiredHeight)
|
||||||
|
{
|
||||||
|
UnRef();
|
||||||
|
|
||||||
|
OSType theId = 0 ;
|
||||||
|
|
||||||
|
if ( resourceName == wxT("wxICON_INFORMATION") )
|
||||||
|
{
|
||||||
|
theId = kAlertNoteIcon ;
|
||||||
|
}
|
||||||
|
else if ( resourceName == wxT("wxICON_QUESTION") )
|
||||||
|
{
|
||||||
|
theId = kAlertCautionIcon ;
|
||||||
|
}
|
||||||
|
else if ( resourceName == wxT("wxICON_WARNING") )
|
||||||
|
{
|
||||||
|
theId = kAlertCautionIcon ;
|
||||||
|
}
|
||||||
|
else if ( resourceName == wxT("wxICON_ERROR") )
|
||||||
|
{
|
||||||
|
theId = kAlertStopIcon ;
|
||||||
|
}
|
||||||
|
else if ( resourceName == wxT("wxICON_FOLDER") )
|
||||||
|
{
|
||||||
|
theId = kGenericFolderIcon ;
|
||||||
|
}
|
||||||
|
else if ( resourceName == wxT("wxICON_FOLDER_OPEN") )
|
||||||
|
{
|
||||||
|
theId = kOpenFolderIcon ;
|
||||||
|
}
|
||||||
|
else if ( resourceName == wxT("wxICON_NORMAL_FILE") )
|
||||||
|
{
|
||||||
|
theId = kGenericDocumentIcon ;
|
||||||
|
}
|
||||||
|
else if ( resourceName == wxT("wxICON_EXECUTABLE_FILE") )
|
||||||
|
{
|
||||||
|
theId = kGenericApplicationIcon ;
|
||||||
|
}
|
||||||
|
else if ( resourceName == wxT("wxICON_CDROM") )
|
||||||
|
{
|
||||||
|
theId = kGenericCDROMIcon ;
|
||||||
|
}
|
||||||
|
else if ( resourceName == wxT("wxICON_FLOPPY") )
|
||||||
|
{
|
||||||
|
theId = kGenericFloppyIcon ;
|
||||||
|
}
|
||||||
|
else if ( resourceName == wxT("wxICON_HARDDISK") )
|
||||||
|
{
|
||||||
|
theId = kGenericHardDiskIcon ;
|
||||||
|
}
|
||||||
|
else if ( resourceName == wxT("wxICON_REMOVABLE") )
|
||||||
|
{
|
||||||
|
theId = kGenericRemovableMediaIcon ;
|
||||||
|
}
|
||||||
|
else if ( resourceName == wxT("wxICON_DELETE") )
|
||||||
|
{
|
||||||
|
theId = kToolbarDeleteIcon ;
|
||||||
|
}
|
||||||
|
else if ( resourceName == wxT("wxICON_GO_BACK") )
|
||||||
|
{
|
||||||
|
theId = kBackwardArrowIcon ;
|
||||||
|
}
|
||||||
|
else if ( resourceName == wxT("wxICON_GO_FORWARD") )
|
||||||
|
{
|
||||||
|
theId = kForwardArrowIcon ;
|
||||||
|
}
|
||||||
|
else if ( resourceName == wxT("wxICON_GO_HOME") )
|
||||||
|
{
|
||||||
|
theId = kToolbarHomeIcon ;
|
||||||
|
}
|
||||||
|
else if ( resourceName == wxT("wxICON_HELP_SETTINGS") )
|
||||||
|
{
|
||||||
|
theId = kGenericFontIcon ;
|
||||||
|
}
|
||||||
|
else if ( resourceName == wxT("wxICON_HELP_PAGE") )
|
||||||
|
{
|
||||||
|
theId = kGenericDocumentIcon ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( theId != 0 )
|
||||||
|
{
|
||||||
|
IconRef iconRef = NULL ;
|
||||||
|
verify_noerr( GetIconRef( kOnSystemDisk, kSystemIconsCreator, theId, &iconRef ) ) ;
|
||||||
|
if ( iconRef )
|
||||||
{
|
{
|
||||||
wxBitmap bmp ;
|
m_refData = new wxIconRefData( (WXHICON) iconRef, desiredWidth, desiredHeight ) ;
|
||||||
if ( handler->LoadFile( &bmp , filename, type, desiredWidth, desiredHeight ))
|
return true ;
|
||||||
{
|
|
||||||
CopyFromBitmap( bmp ) ;
|
|
||||||
|
|
||||||
return true ;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false ;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
#if wxUSE_IMAGE
|
|
||||||
wxImage loadimage( filename, type );
|
|
||||||
if (loadimage.Ok())
|
|
||||||
{
|
|
||||||
if ( desiredWidth == -1 )
|
|
||||||
desiredWidth = loadimage.GetWidth() ;
|
|
||||||
if ( desiredHeight == -1 )
|
|
||||||
desiredHeight = loadimage.GetHeight() ;
|
|
||||||
if ( desiredWidth != loadimage.GetWidth() || desiredHeight != loadimage.GetHeight() )
|
|
||||||
loadimage.Rescale( desiredWidth , desiredHeight ) ;
|
|
||||||
|
|
||||||
wxBitmap bmp( loadimage );
|
|
||||||
CopyFromBitmap( bmp ) ;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load an icon of type 'icns' by resource by name
|
||||||
|
// The resource must exist in one of the currently accessible bundles
|
||||||
|
// (usually this means the application bundle for the current application)
|
||||||
|
// Return true on success, false otherwise
|
||||||
|
bool wxIcon::LoadIconFromBundleResource(const wxString& resourceName, int desiredWidth, int desiredHeight)
|
||||||
|
{
|
||||||
|
UnRef();
|
||||||
|
|
||||||
|
IconRef iconRef = NULL ;
|
||||||
|
|
||||||
|
// first look in the resource fork
|
||||||
|
if ( iconRef == NULL )
|
||||||
|
{
|
||||||
|
Str255 theName ;
|
||||||
|
|
||||||
|
wxMacStringToPascal( resourceName , theName ) ;
|
||||||
|
Handle resHandle = GetNamedResource( 'icns' , theName ) ;
|
||||||
|
if ( resHandle != 0L )
|
||||||
|
{
|
||||||
|
IconFamilyHandle iconFamily = (IconFamilyHandle) resHandle ;
|
||||||
|
OSStatus err = GetIconRefFromIconFamilyPtr( *iconFamily, GetHandleSize((Handle) iconFamily), &iconRef );
|
||||||
|
|
||||||
|
if ( err != noErr )
|
||||||
|
{
|
||||||
|
wxFAIL_MSG("Error when constructing icon ref");
|
||||||
|
}
|
||||||
|
|
||||||
|
ReleaseResource( resHandle ) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( iconRef )
|
||||||
|
{
|
||||||
|
m_refData = new wxIconRefData( (WXHICON) iconRef, desiredWidth, desiredHeight );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load an icon from an icon file using the underlying OS X API
|
||||||
|
// The icon file must be in a format understood by the OS
|
||||||
|
// Return true for success, false otherwise
|
||||||
|
bool wxIcon::LoadIconFromFile(const wxString& filename, int desiredWidth, int desiredHeight)
|
||||||
|
{
|
||||||
|
UnRef();
|
||||||
|
|
||||||
|
OSStatus err;
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
// Get a file system reference
|
||||||
|
FSRef fsRef;
|
||||||
|
err = FSPathMakeRef( (const wxUint8*)filename.utf8_str().data(), &fsRef, NULL );
|
||||||
|
|
||||||
|
if( err != noErr )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Get a handle on the icon family
|
||||||
|
IconFamilyHandle iconFamily;
|
||||||
|
err = ReadIconFromFSRef( &fsRef, &iconFamily );
|
||||||
|
|
||||||
|
if( err != noErr )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Get the icon reference itself
|
||||||
|
IconRef iconRef;
|
||||||
|
err = GetIconRefFromIconFamilyPtr( *iconFamily, GetHandleSize((Handle) iconFamily), &iconRef );
|
||||||
|
|
||||||
|
if( err == noErr )
|
||||||
|
{
|
||||||
|
// If everthing is OK, assign m_refData
|
||||||
|
m_refData = new wxIconRefData( (WXHICON) iconRef, desiredWidth, desiredHeight );
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Release the iconFamily before returning
|
||||||
|
ReleaseResource( (Handle) iconFamily );
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load an icon from a file using functionality from wxWidgets
|
||||||
|
// A suitable bitmap handler (or image handler) must be available
|
||||||
|
// Return true on success, false otherwise
|
||||||
|
bool wxIcon::LoadIconAsBitmap(const wxString& filename, wxBitmapType type, int desiredWidth, int desiredHeight)
|
||||||
|
{
|
||||||
|
UnRef();
|
||||||
|
|
||||||
|
wxBitmapHandler *handler = wxBitmap::FindHandler( type );
|
||||||
|
|
||||||
|
if ( handler )
|
||||||
|
{
|
||||||
|
wxBitmap bmp ;
|
||||||
|
if ( handler->LoadFile( &bmp , filename, type, desiredWidth, desiredHeight ))
|
||||||
|
{
|
||||||
|
CopyFromBitmap( bmp ) ;
|
||||||
|
return true ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if wxUSE_IMAGE
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxImage loadimage( filename, type );
|
||||||
|
if (loadimage.Ok())
|
||||||
|
{
|
||||||
|
if ( desiredWidth == -1 )
|
||||||
|
desiredWidth = loadimage.GetWidth() ;
|
||||||
|
if ( desiredHeight == -1 )
|
||||||
|
desiredHeight = loadimage.GetHeight() ;
|
||||||
|
if ( desiredWidth != loadimage.GetWidth() || desiredHeight != loadimage.GetHeight() )
|
||||||
|
loadimage.Rescale( desiredWidth , desiredHeight ) ;
|
||||||
|
|
||||||
|
wxBitmap bmp( loadimage );
|
||||||
|
CopyFromBitmap( bmp ) ;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void wxIcon::CopyFromBitmap( const wxBitmap& bmp )
|
void wxIcon::CopyFromBitmap( const wxBitmap& bmp )
|
||||||
{
|
{
|
||||||
UnRef() ;
|
UnRef() ;
|
||||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user