#ifndef _WX_MIMETYPE_H_
#define _WX_MIMETYPE_H_
-#if defined(__GNUG__) && !defined(__APPLE__)
- #pragma interface "mimetypebase.h"
-#endif // __GNUG__
-
// ----------------------------------------------------------------------------
// headers and such
// ----------------------------------------------------------------------------
// the things we really need
#include "wx/string.h"
#include "wx/dynarray.h"
+#include "wx/arrstr.h"
+
+#include <stdarg.h>
// fwd decls
-class WXDLLEXPORT wxIcon;
-class WXDLLEXPORT wxFileTypeImpl;
-class WXDLLEXPORT wxMimeTypesManagerImpl;
+class WXDLLIMPEXP_FWD_BASE wxIconLocation;
+class WXDLLIMPEXP_FWD_BASE wxFileTypeImpl;
+class WXDLLIMPEXP_FWD_BASE wxMimeTypesManagerImpl;
// these constants define the MIME informations source under UNIX and are used
// by wxMimeTypesManager::Initialize()
wxMAILCAP_ALL = 15
};
-#define wxICON_LARGE 0
-#define wxICON_SMALL 1
-
/*
TODO: would it be more convenient to have this class?
-class WXDLLEXPORT wxMimeType : public wxString
+class WXDLLIMPEXP_BASE wxMimeType : public wxString
{
public:
// all string ctors here
- wxString GetType() const { return BeforeFirst(_T('/')); }
- wxString GetSubType() const { return AfterFirst(_T('/')); }
+ wxString GetType() const { return BeforeFirst(wxT('/')); }
+ wxString GetSubType() const { return AfterFirst(wxT('/')); }
void SetSubType(const wxString& subtype)
{
- *this = GetType() + _T('/') + subtype;
+ *this = GetType() + wxT('/') + subtype;
}
bool Matches(const wxMimeType& wildcard)
*/
+// wxMimeTypeCommands stores the verbs defined for the given MIME type with
+// their values
+class WXDLLIMPEXP_BASE wxMimeTypeCommands
+{
+public:
+ wxMimeTypeCommands() {}
+
+ wxMimeTypeCommands(const wxArrayString& verbs,
+ const wxArrayString& commands)
+ : m_verbs(verbs),
+ m_commands(commands)
+ {
+ }
+
+ // add a new verb with the command or replace the old value
+ void AddOrReplaceVerb(const wxString& verb, const wxString& cmd);
+ void Add(const wxString& s)
+ {
+ m_verbs.Add(s.BeforeFirst(wxT('=')));
+ m_commands.Add(s.AfterFirst(wxT('=')));
+ }
+
+ // access the commands
+ size_t GetCount() const { return m_verbs.GetCount(); }
+ const wxString& GetVerb(size_t n) const { return m_verbs[n]; }
+ const wxString& GetCmd(size_t n) const { return m_commands[n]; }
+
+ bool HasVerb(const wxString& verb) const
+ { return m_verbs.Index(verb) != wxNOT_FOUND; }
+
+ // returns empty string and wxNOT_FOUND in idx if no such verb
+ wxString GetCommandForVerb(const wxString& verb, size_t *idx = NULL) const;
+
+ // get a "verb=command" string
+ wxString GetVerbCmd(size_t n) const;
+
+private:
+ wxArrayString m_verbs;
+ wxArrayString m_commands;
+};
+
// ----------------------------------------------------------------------------
// wxFileTypeInfo: static container of information accessed via wxFileType.
//
// This class is used with wxMimeTypesManager::AddFallbacks() and Associate()
// ----------------------------------------------------------------------------
-class WXDLLEXPORT wxFileTypeInfo
+class WXDLLIMPEXP_BASE wxFileTypeInfo
{
+private:
+ void DoVarArgInit(const wxString& mimeType,
+ const wxString& openCmd,
+ const wxString& printCmd,
+ const wxString& desc,
+ va_list argptr);
+
+ void VarArgInit(const wxString *mimeType,
+ const wxString *openCmd,
+ const wxString *printCmd,
+ const wxString *desc,
+ // the other parameters form a NULL terminated list of
+ // extensions
+ ...);
+
public:
+ // NB: This is a helper to get implicit conversion of variadic ctor's
+ // fixed arguments into something that can be passed to VarArgInit().
+ // Do not use, it's used by the ctor only.
+ struct CtorString
+ {
+ CtorString(const char *str) : m_str(str) {}
+ CtorString(const wchar_t *str) : m_str(str) {}
+ CtorString(const wxString& str) : m_str(str) {}
+ CtorString(const wxCStrData& str) : m_str(str) {}
+ CtorString(const wxScopedCharBuffer& str) : m_str(str) {}
+ CtorString(const wxScopedWCharBuffer& str) : m_str(str) {}
+
+ operator const wxString*() const { return &m_str; }
+
+ wxString m_str;
+ };
+
// ctors
- // a normal item
- wxFileTypeInfo(const wxChar *mimeType,
- const wxChar *openCmd,
- const wxChar *printCmd,
- const wxChar *desc,
- // the other parameters form a NULL terminated list of
- // extensions
- ...);
+
+ // Ctor specifying just the MIME type (which is mandatory), the other
+ // fields can be set later if needed.
+ wxFileTypeInfo(const wxString& mimeType)
+ : m_mimeType(mimeType)
+ {
+ }
+
+ // Ctor allowing to specify the values of all fields at once:
+ //
+ // wxFileTypeInfo(const wxString& mimeType,
+ // const wxString& openCmd,
+ // const wxString& printCmd,
+ // const wxString& desc,
+ // // the other parameters form a list of extensions for this
+ // // file type and should be terminated with wxNullPtr (not
+ // // just NULL!)
+ // ...);
+ WX_DEFINE_VARARG_FUNC_CTOR(wxFileTypeInfo,
+ 4, (const CtorString&,
+ const CtorString&,
+ const CtorString&,
+ const CtorString&),
+ VarArgInit, VarArgInit)
+#ifdef __WATCOMC__
+ // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
+ WX_VARARG_WATCOM_WORKAROUND_CTOR(
+ wxFileTypeInfo,
+ 4, (const wxString&,
+ const wxString&,
+ const wxString&,
+ const wxString&),
+ (CtorString(f1),
+ CtorString(f2),
+ CtorString(f3),
+ CtorString(f4)));
+ WX_VARARG_WATCOM_WORKAROUND_CTOR(
+ wxFileTypeInfo,
+ 4, (const wxCStrData&,
+ const wxCStrData&,
+ const wxCStrData&,
+ const wxCStrData&),
+ (CtorString(f1),
+ CtorString(f2),
+ CtorString(f3),
+ CtorString(f4)));
+ WX_VARARG_WATCOM_WORKAROUND_CTOR(
+ wxFileTypeInfo,
+ 4, (const char*,
+ const char*,
+ const char*,
+ const char*),
+ (CtorString(f1),
+ CtorString(f2),
+ CtorString(f3),
+ CtorString(f4)));
+ WX_VARARG_WATCOM_WORKAROUND_CTOR(
+ wxFileTypeInfo,
+ 4, (const wchar_t*,
+ const wchar_t*,
+ const wchar_t*,
+ const wchar_t*),
+ (CtorString(f1),
+ CtorString(f2),
+ CtorString(f3),
+ CtorString(f4)));
+#endif
// the array elements correspond to the parameters of the ctor above in
// the same order
wxFileTypeInfo() { }
// test if this object can be used
- bool IsValid() const { return !m_mimeType.IsEmpty(); }
+ bool IsValid() const { return !m_mimeType.empty(); }
// setters
+ // set the open/print commands
+ void SetOpenCommand(const wxString& command) { m_openCmd = command; }
+ void SetPrintCommand(const wxString& command) { m_printCmd = command; }
+
+ // set the description
+ void SetDescription(const wxString& desc) { m_desc = desc; }
+
+ // add another extension corresponding to this file type
+ void AddExtension(const wxString& ext) { m_exts.push_back(ext); }
+
// set the icon info
void SetIcon(const wxString& iconFile, int iconIndex = 0)
{
const wxString& GetDescription() const { return m_desc; }
// get the array of all extensions
const wxArrayString& GetExtensions() const { return m_exts; }
- int GetExtensionsCount() const {return m_exts.GetCount(); }
+ size_t GetExtensionsCount() const {return m_exts.GetCount(); }
// get the icon info
const wxString& GetIconFile() const { return m_iconFile; }
int GetIconIndex() const { return m_iconIndex; }
#endif // 0
};
-WX_DECLARE_EXPORTED_OBJARRAY(wxFileTypeInfo, wxArrayFileTypeInfo);
+WX_DECLARE_USER_EXPORTED_OBJARRAY(wxFileTypeInfo, wxArrayFileTypeInfo,
+ WXDLLIMPEXP_BASE);
// ----------------------------------------------------------------------------
// wxFileType: gives access to all information about the files of given type.
// the accessors *must* be checked!
// ----------------------------------------------------------------------------
-class WXDLLEXPORT wxFileType
+class WXDLLIMPEXP_BASE wxFileType
{
-friend class WXDLLEXPORT wxMimeTypesManagerImpl; // it has access to m_impl
+friend class WXDLLIMPEXP_FWD_BASE wxMimeTypesManagerImpl; // it has access to m_impl
public:
// An object of this class must be passed to Get{Open|Print}Command. The
// ctors
MessageParameters() { }
MessageParameters(const wxString& filename,
- const wxString& mimetype = _T(""))
+ const wxString& mimetype = wxEmptyString)
: m_filename(filename), m_mimetype(mimetype) { }
// accessors (called by GetOpenCommand)
// 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;
+ bool GetIcon(wxIconLocation *iconloc,
+ const MessageParameters& params) const;
// get a brief file type description ("*.txt" => "text document")
bool GetDescription(wxString *desc) const;
const wxFileType::MessageParameters& params) const;
// set an arbitrary command, ask confirmation if it already exists and
- // overwriteprompt is TRUE
+ // overwriteprompt is true
bool SetCommand(const wxString& cmd, const wxString& verb,
- bool overwriteprompt = TRUE);
+ bool overwriteprompt = true);
bool SetDefaultIcon(const wxString& cmd = wxEmptyString, int index = 0);
// operations
// expand a string in the format of GetOpenCommand (which may contain
- // '%s' and '%t' format specificators for the file name and mime type
+ // '%s' and '%t' format specifiers for the file name and mime type
// and %{param} constructions).
static wxString ExpandCommand(const wxString& command,
const MessageParameters& params);
wxFileTypeImpl *m_impl;
};
+//----------------------------------------------------------------------------
+// wxMimeTypesManagerFactory
+//----------------------------------------------------------------------------
+
+class WXDLLIMPEXP_BASE wxMimeTypesManagerFactory
+{
+public:
+ wxMimeTypesManagerFactory() {}
+ virtual ~wxMimeTypesManagerFactory() {}
+
+ virtual wxMimeTypesManagerImpl *CreateMimeTypesManagerImpl();
+
+ static void Set( wxMimeTypesManagerFactory *factory );
+ static wxMimeTypesManagerFactory *Get();
+
+private:
+ static wxMimeTypesManagerFactory *m_factory;
+};
+
// ----------------------------------------------------------------------------
// wxMimeTypesManager: interface to system MIME database.
//
// given type) about them.
// ----------------------------------------------------------------------------
-class WXDLLEXPORT wxMimeTypesManager
+class WXDLLIMPEXP_BASE wxMimeTypesManager
{
public:
// static helper functions
// check if the given MIME type is the same as the other one: the
// second argument may contain wildcards ('*'), but not the first. If
// the types are equal or if the mimeType matches wildcard the function
- // returns TRUE, otherwise it returns FALSE
+ // returns true, otherwise it returns false
static bool IsOfType(const wxString& mimeType, const wxString& wildcard);
// ctor
// get file type from MIME type (in format <category>/<format>)
wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
- // other operations: return TRUE if there were no errors or FALSE if there
- // were some unreckognized entries (the good entries are always read anyhow)
- //
- // FIXME: These ought to be private ??
-
- // read in additional file (the standard ones are read automatically)
- // in mailcap format (see mimetype.cpp for description)
- //
- // 'fallback' parameter may be set to TRUE to avoid overriding the
- // settings from other, previously parsed, files by this one: normally,
- // the files read most recently would override the older files, but with
- // fallback == TRUE this won't happen
-
- bool ReadMailcap(const wxString& filename, bool fallback = FALSE);
- // read in additional file in mime.types format
- bool ReadMimeTypes(const wxString& filename);
-
// enumerate all known MIME types
//
// returns the number of retrieved file types
size_t EnumAllFileTypes(wxArrayString& mimetypes);
// these functions can be used to provide default values for some of the
- // MIME types inside the program itself (you may also use
- // ReadMailcap(filenameWithDefaultTypes, TRUE /* use as fallback */) to
- // achieve the same goal, but this requires having this info in a file).
+ // MIME types inside the program itself
//
// The filetypes array should be terminated by either NULL entry or an
// invalid wxFileTypeInfo (i.e. the one created with default ctor)
// global variables
// ----------------------------------------------------------------------------
-// the default mime manager for wxWindows programs
-WXDLLEXPORT_DATA(extern wxMimeTypesManager *) wxTheMimeTypesManager;
+// the default mime manager for wxWidgets programs
+extern WXDLLIMPEXP_DATA_BASE(wxMimeTypesManager *) wxTheMimeTypesManager;
#endif // wxUSE_MIMETYPE