+ infoRec.processInfoLength = sizeof(ProcessInfoRec);
+ infoRec.processName = NULL;
+ infoRec.processAppSpec = NULL;
+
+ if ( pPSN == NULL )
+ {
+ localPSN.highLongOfPSN = 0;
+ localPSN.lowLongOfPSN = kCurrentProcess;
+ }
+ else
+ {
+ localPSN = *pPSN;
+ }
+
+ anErr = GetProcessInformation(&localPSN, &infoRec);
+ if (anErr == noErr)
+ {
+ *pProcessType = infoRec.processType;
+ *pCreator = infoRec.processSignature;
+ }
+
+ return anErr;
+}
+
+//
+//
+// TODO: clean this up, its messy
+//
+//
+//
+
+#include "wx/mac/corefoundation/cfstring.h"
+
+#define wxCF_RELEASE true
+#define wxCF_RETAIN false
+
+// ----------------------------------------------------------------------------
+// wxCFDictionary
+// ----------------------------------------------------------------------------
+
+class wxCFDictionary
+{
+public:
+ wxCFDictionary(CFTypeRef ref, bool bRetain = wxCF_RELEASE)
+ {
+ m_cfmdRef = (CFMutableDictionaryRef) ref;
+ if (bRetain == wxCF_RETAIN && ref)
+ CFRetain(ref);
+ }
+
+ wxCFDictionary(CFIndex cfiSize = 0)
+ {
+ CFDictionaryKeyCallBacks kcbs;
+ CFDictionaryValueCallBacks vcbs;
+ BuildKeyCallbacks(&kcbs);
+ BuildValueCallbacks(&vcbs);
+
+ m_cfmdRef = CFDictionaryCreateMutable(
+ kCFAllocatorDefault, cfiSize, &kcbs, &vcbs );
+ }
+
+ ~wxCFDictionary()
+ { Clear(); }
+
+ void Clear()
+ {
+ if (m_cfmdRef)
+ CFRelease(m_cfmdRef);
+ }
+
+ static const void* RetainProc(CFAllocatorRef, const void* v)
+ { return (const void*) CFRetain(v); }
+
+ static void ReleaseProc(CFAllocatorRef, const void* v)
+ { CFRelease(v); }
+
+ void MakeMutable(CFIndex cfiSize = 0)
+ {
+ CFDictionaryRef oldref = (CFDictionaryRef) m_cfmdRef;
+
+ m_cfmdRef = CFDictionaryCreateMutableCopy(
+ kCFAllocatorDefault, cfiSize, oldref );
+
+ CFRelease( oldref );
+ }
+
+ void BuildKeyCallbacks(CFDictionaryKeyCallBacks* pCbs)
+ {
+ pCbs->version = 0;
+ pCbs->retain = RetainProc;
+ pCbs->release = ReleaseProc;
+ pCbs->copyDescription = NULL;
+ pCbs->equal = NULL;
+ pCbs->hash = NULL;
+ }
+
+ void BuildValueCallbacks(CFDictionaryValueCallBacks* pCbs)
+ {
+ pCbs->version = 0;
+ pCbs->retain = RetainProc;
+ pCbs->release = ReleaseProc;
+ pCbs->copyDescription = NULL;
+ pCbs->equal = NULL;
+ }
+
+ operator CFTypeRef () const
+ { return (CFTypeRef)m_cfmdRef; }
+
+ CFDictionaryRef GetCFDictionary() const
+ { return (CFDictionaryRef)m_cfmdRef; }
+
+ CFMutableDictionaryRef GetCFMutableDictionary()
+ { return (CFMutableDictionaryRef) m_cfmdRef; }
+
+ CFTypeRef operator [] (CFTypeRef cftEntry) const
+ {
+ wxASSERT(IsValid());
+ return (CFTypeRef) CFDictionaryGetValue((CFDictionaryRef)m_cfmdRef, cftEntry);
+ }
+
+ CFIndex GetCount() const
+ {
+ wxASSERT(IsValid());
+ return CFDictionaryGetCount((CFDictionaryRef)m_cfmdRef);
+ }
+
+ void Add(CFTypeRef cftKey, CFTypeRef cftValue)
+ {
+ wxASSERT(IsValid());
+ wxASSERT(Exists(cftKey) == false);
+ CFDictionaryAddValue(m_cfmdRef, cftKey, cftValue);
+ }
+
+ void Remove(CFTypeRef cftKey)
+ {
+ wxASSERT(IsValid());
+ wxASSERT(Exists(cftKey));
+ CFDictionaryRemoveValue(m_cfmdRef, cftKey);
+ }
+
+ void Set(CFTypeRef cftKey, CFTypeRef cftValue)
+ {
+ wxASSERT(IsValid());
+ wxASSERT(Exists(cftKey));
+ CFDictionarySetValue(m_cfmdRef, cftKey, cftValue);
+ }
+
+ bool Exists(CFTypeRef cftKey) const
+ {
+ wxASSERT(IsValid());
+ return CFDictionaryContainsKey((CFDictionaryRef)m_cfmdRef, cftKey);
+ }
+
+ bool IsOk() const
+ { return m_cfmdRef != NULL; }
+
+ bool IsValid() const
+ { return IsOk() && CFGetTypeID((CFTypeRef)m_cfmdRef) == CFDictionaryGetTypeID(); }
+
+ void PrintOut(wxString& sMessage)
+ {
+ PrintOutDictionary(sMessage, m_cfmdRef);
+ }
+
+ static void PrintOutDictionary(wxString& sMessage, CFDictionaryRef cfdRef)
+ {
+ CFIndex cfiCount = CFDictionaryGetCount(cfdRef);
+ CFTypeRef* pKeys = new CFTypeRef[cfiCount];
+ CFTypeRef* pValues = new CFTypeRef[cfiCount];
+
+ CFDictionaryGetKeysAndValues(cfdRef, pKeys, pValues);
+
+ for (CFIndex i = 0; i < cfiCount; ++i)
+ {
+ wxString sKey = wxMacCFStringHolder(CFCopyTypeIDDescription(CFGetTypeID(pKeys[i]))).AsString();
+ wxString sValue = wxMacCFStringHolder(CFCopyTypeIDDescription(CFGetTypeID(pValues[i]))).AsString();
+
+ sMessage <<
+ wxString::Format(wxT("[{#%d} Key : %s]"), (int) i,
+ sKey.c_str());
+
+ PrintOutType(sMessage, sKey, pKeys[i]);
+
+ sMessage <<
+ wxString::Format(wxT("\n\t[Value : %s]"),
+ sValue.c_str());
+
+ PrintOutType(sMessage, sValue, pValues[i]);
+
+ sMessage << wxT("\n");
+ }
+
+ delete [] pKeys;
+ delete [] pValues;
+ }
+
+ static void PrintOutArray(wxString& sMessage, CFArrayRef cfaRef)
+ {
+ for (CFIndex i = 0; i < CFArrayGetCount(cfaRef); ++i)
+ {
+ wxString sValue = wxMacCFStringHolder(CFCopyTypeIDDescription(CFGetTypeID(
+ CFArrayGetValueAtIndex(cfaRef, i)
+ ))).AsString();
+
+ sMessage <<
+ wxString::Format(wxT("\t\t[{#%d} ArrayValue : %s]\n"), (int) i,
+ sValue.c_str());
+
+ PrintOutType(sMessage, sValue, CFArrayGetValueAtIndex(cfaRef, i));
+ }
+ }
+
+ static void PrintOutType(wxString& sMessage, const wxString& sValue, CFTypeRef cfRef)
+ {
+ sMessage << wxT(" {");
+
+ if (sValue == wxT("CFString"))
+ {
+ sMessage << wxMacCFStringHolder((CFStringRef)cfRef, false).AsString();
+ }
+ else if (sValue == wxT("CFNumber"))
+ {
+ int nOut;
+ CFNumberGetValue((CFNumberRef)cfRef, kCFNumberIntType, &nOut);
+ sMessage << nOut;
+ }
+ else if (sValue == wxT("CFDictionary"))
+ {
+ PrintOutDictionary(sMessage, (CFDictionaryRef)cfRef);
+ }
+ else if (sValue == wxT("CFArray"))
+ {
+ PrintOutArray(sMessage, (CFArrayRef)cfRef);
+ }
+ else if (sValue == wxT("CFBoolean"))
+ {
+ sMessage << (cfRef == kCFBooleanTrue ? wxT("true") : wxT("false"));
+ }
+ else if (sValue == wxT("CFURL"))
+ {
+ sMessage << wxMacCFStringHolder(CFURLCopyPath((CFURLRef) cfRef)).AsString();
+ }
+ else
+ {
+ sMessage << wxT("*****UNKNOWN TYPE******");
+ }
+
+ sMessage << wxT("} ");
+ }
+
+#if wxUSE_MIMETYPE
+ void MakeValidXML();
+#endif
+
+ CFTypeRef WriteAsXML()
+ {
+ return CFPropertyListCreateXMLData(kCFAllocatorDefault, m_cfmdRef);
+ }
+
+ bool ReadAsXML(CFTypeRef cfData, wxString* pErrorMsg = NULL)
+ {
+ Clear();
+ CFStringRef cfsError=NULL;
+ m_cfmdRef = (CFMutableDictionaryRef) CFPropertyListCreateFromXMLData(
+ kCFAllocatorDefault,
+ (CFDataRef)cfData,
+ kCFPropertyListMutableContainersAndLeaves,
+ &cfsError );
+ if (cfsError)
+ {
+ if (pErrorMsg)
+ *pErrorMsg = wxMacCFStringHolder(cfsError).AsString();
+ else
+ CFRelease(cfsError);
+ }
+
+ return m_cfmdRef != NULL;
+ }
+
+private:
+ CFMutableDictionaryRef m_cfmdRef;
+};
+
+// ----------------------------------------------------------------------------
+// wxCFArray
+// ----------------------------------------------------------------------------
+
+class wxCFArray