void ZClipboard::Clear() { #if ZCONFIG(OS, MacOS7) if (!fTuple.Empty()) { fTuple = ZTuple(); ::ZeroScrap(); fLastKnownScrapCount = ::InfoScrap()->scrapCount; } #elif ZCONFIG(OS, Carbon) || ZCONFIG(OS, MacOSX) if (!fTuple.Empty()) { fTuple = ZTuple(); ::ClearScrap(&fLastKnownScrapRef); } #elif ZCONFIG(OS, Win32) sWin32_Set(ZTuple()); #else ZDebugLogf(0, ("ZClipboard::Empty(), Unsupported platform")); #endif }
void ZMessageLooperImpStd::DispatchMessageImp(const ZMessage& inMessage) { ZDebugLogf(0, ("ZMessageLooperImpStd::DispatchMessageImp called")); }
ZTuple ZClipboard::Get() { #if ZCONFIG(OS, MacOS7) SInt16 currentScrapCount = ::InfoScrap()->scrapCount; if (fLastKnownScrapCount != currentScrapCount) { fLastKnownScrapCount = currentScrapCount; fTuple = ZTuple(); // Walk through all the registered types and suck any data that might be on the clipboard into our tuple size_t theCount = ZDragClipManager::sGet()->Count(); for (size_t x = 0; x < theCount; ++x) { string currentMIME = ZDragClipManager::sGet()->At(x); bool isString; ScrapFlavorType theScrapFlavorType; if (ZDragClipManager::sGet()->LookupMIME(currentMIME, theScrapFlavorType, isString)) { SInt32 theOffset = 0; SInt32 theLength = ::GetScrap(nil, theScrapFlavorType, &theOffset); if (theLength >= 0) { // Creates a zero-length handle, rather than a NULL handle ZHandle theHandle(0); theLength = ::GetScrap(theHandle.GetMacHandle(), theScrapFlavorType, &theOffset); // AG 99-01-07. For the moment we're ignoring the value of theOffset, which indicates the order in which // different data items were written to the desk scrap, and hence their preference level. if (theHandle.GetSize() == theLength) { ZHandle::Ref theRef(theHandle); if (isString) fTuple.SetString(currentMIME, string(reinterpret_cast<char*>(theRef.GetData()), theRef.GetSize())); else fTuple.SetRaw(currentMIME, theRef.GetData(), theRef.GetSize()); } } } } } return fTuple; #elif ZCONFIG(OS, Carbon) || ZCONFIG(OS, MacOSX) ScrapRef currentScrapRef; ::GetCurrentScrap(¤tScrapRef); if (fLastKnownScrapRef != currentScrapRef) { fLastKnownScrapRef = currentScrapRef; fTuple = ZTuple(); // Walk through all the registered types and suck any data that might be on the clipboard into our tuple size_t theCount = ZDragClipManager::sGet()->Count(); for (size_t x = 0; x < theCount; ++x) { string currentMIME = ZDragClipManager::sGet()->At(x); bool isString; ScrapFlavorType flavorType; if (ZDragClipManager::sGet()->LookupMIME(currentMIME, flavorType, isString)) { ScrapFlavorFlags flavorFlags; if (noErr == ::GetScrapFlavorFlags(currentScrapRef, flavorType, &flavorFlags)) { Size availByteCount = 0; OSStatus status = ::GetScrapFlavorSize(currentScrapRef, flavorType, &availByteCount); if ((status == noErr) && (availByteCount >= 0)) { vector<uint8> buffer(availByteCount); Size actualByteCount = availByteCount; status = ::GetScrapFlavorData(currentScrapRef, flavorType, &actualByteCount, &buffer[0]); if (actualByteCount == availByteCount) { if (isString) fTuple.SetString(currentMIME, string(reinterpret_cast<char*>(&buffer[0]), availByteCount)); else fTuple.SetRaw(currentMIME, &buffer[0], availByteCount); } } } } } } return fTuple; #elif ZCONFIG(OS, Win32) return sWin32_Get(); #else ZDebugLogf(0, ("ZClipboard::Get(), Unsupported platform")); return ZTuple(); #endif }
void ZClipboard::Set(const ZTuple& iTuple) { #if ZCONFIG(OS, MacOS7) fTuple = iTuple; ::ZeroScrap(); // Push registered types out to the desk scrap for (ZTuple::const_iterator i = fTuple.begin(); i != fTuple.end(); ++i) { string propertyName = fTuple.NameOf(i); ScrapFlavorType theScrapFlavorType; bool isString; if (ZDragClipManager::sGet()->LookupMIME(propertyName, theScrapFlavorType, isString)) { ZType propertyType = fTuple.TypeOf(i); if (isString && propertyType == eZType_String) { string theString = fTuple.GetString(propertyName); if (theString.size()) ::PutScrap(theString.size(), theScrapFlavorType, theString.data()); else ::PutScrap(0, theScrapFlavorType, nil); } else if (!isString && propertyType == eZType_Raw) { size_t rawSize; const void* rawAddress; bool okay = fTuple.GetRawAttributes(propertyName, &rawAddress, &rawSize); ZAssertStop(1, okay); ::PutScrap(rawSize, theScrapFlavorType, rawAddress); } } } fLastKnownScrapCount = ::InfoScrap()->scrapCount; #elif ZCONFIG(OS, Carbon) || ZCONFIG(OS, MacOSX) fTuple = iTuple; ::ClearCurrentScrap(); ScrapRef currentScrapRef; ::GetCurrentScrap(¤tScrapRef); // Push registered types out to the desk scrap for (ZTuple::const_iterator i = fTuple.begin(); i != fTuple.end(); ++i) { string propertyName = fTuple.NameOf(i); ScrapFlavorType flavorType; bool isString; if (ZDragClipManager::sGet()->LookupMIME(propertyName, flavorType, isString)) { ZType propertyType = fTuple.TypeOf(i); if (isString && propertyType == eZType_String) { string theString = fTuple.GetString(propertyName); if (theString.size()) ::PutScrapFlavor(currentScrapRef, flavorType, kScrapFlavorMaskNone, theString.size(), theString.data()); else ::PutScrapFlavor(currentScrapRef, flavorType, kScrapFlavorMaskNone, 0, nil); } else if (!isString && propertyType == eZType_Raw) { size_t rawSize; const void* rawAddress; bool okay = fTuple.GetRawAttributes(propertyName, &rawAddress, &rawSize); ZAssertStop(1, okay); ::PutScrapFlavor(currentScrapRef, flavorType, kScrapFlavorMaskNone, rawSize, rawAddress); } } } ::GetCurrentScrap(&fLastKnownScrapRef); #elif ZCONFIG(OS, Win32) sWin32_Set(iTuple); #else ZDebugLogf(0, ("ZClipboard::Put(), Unsupported platform")); #endif }