From 2cae7a76f525853f602af95db2413a5b5e679a41 Mon Sep 17 00:00:00 2001 From: Julian Storer Date: Thu, 8 Sep 2011 15:14:41 +0100 Subject: [PATCH] Linux http fix. Plugin header fix. win32 IME fix. --- .../codecs/juce_AiffAudioFormat.cpp | 6 ++-- .../codecs/juce_WavAudioFormat.cpp | 14 ++++---- .../utility/juce_IncludeSystemHeaders.h | 5 ++- .../juce_core/native/juce_linux_Network.cpp | 36 +++++++++---------- .../streams/juce_MemoryOutputStream.cpp | 16 +++++---- .../streams/juce_MemoryOutputStream.h | 3 ++ .../native/juce_win32_Windowing.cpp | 20 ++++++----- 7 files changed, 52 insertions(+), 48 deletions(-) diff --git a/modules/juce_audio_formats/codecs/juce_AiffAudioFormat.cpp b/modules/juce_audio_formats/codecs/juce_AiffAudioFormat.cpp index d73d031e44..d6c690d8d2 100644 --- a/modules/juce_audio_formats/codecs/juce_AiffAudioFormat.cpp +++ b/modules/juce_audio_formats/codecs/juce_AiffAudioFormat.cpp @@ -629,21 +629,21 @@ private: { output->writeInt (chunkName ("MARK")); output->writeIntBigEndian ((int) markChunk.getSize()); - output->write (markChunk.getData(), (int) markChunk.getSize()); + *output << markChunk; } if (comtChunk.getSize() > 0) { output->writeInt (chunkName ("COMT")); output->writeIntBigEndian ((int) comtChunk.getSize()); - output->write (comtChunk.getData(), (int) comtChunk.getSize()); + *output << comtChunk; } if (instChunk.getSize() > 0) { output->writeInt (chunkName ("INST")); output->writeIntBigEndian ((int) instChunk.getSize()); - output->write (instChunk.getData(), (int) instChunk.getSize()); + *output << instChunk; } output->writeInt (chunkName ("SSND")); diff --git a/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp b/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp index fe8de1441f..48d2c89e69 100644 --- a/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp +++ b/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp @@ -936,28 +936,28 @@ private: { output->writeInt (chunkName ("bext")); output->writeInt ((int) bwavChunk.getSize()); - output->write (bwavChunk.getData(), (int) bwavChunk.getSize()); + *output << bwavChunk; } if (smplChunk.getSize() > 0) { output->writeInt (chunkName ("smpl")); output->writeInt ((int) smplChunk.getSize()); - output->write (smplChunk.getData(), (int) smplChunk.getSize()); + *output << smplChunk; } if (instChunk.getSize() > 0) { output->writeInt (chunkName ("inst")); output->writeInt (7); - output->write (instChunk.getData(), (int) instChunk.getSize()); + *output << instChunk; } if (cueChunk.getSize() > 0) { output->writeInt (chunkName ("cue ")); output->writeInt ((int) cueChunk.getSize()); - output->write (cueChunk.getData(), (int) cueChunk.getSize()); + *output << cueChunk; } if (listChunk.getSize() > 0) @@ -965,7 +965,7 @@ private: output->writeInt (chunkName ("LIST")); output->writeInt ((int) listChunk.getSize() + 4); output->writeInt (chunkName ("adtl")); - output->write (listChunk.getData(), (int) listChunk.getSize()); + *output << listChunk; } output->writeInt (chunkName ("data")); @@ -1069,7 +1069,7 @@ bool WavAudioFormat::replaceMetadataInFile (const File& wavFile, const StringPai if (reader != nullptr) { - const int64 bwavPos = reader->bwavChunkStart; + const int64 bwavPos = reader->bwavChunkStart; const int64 bwavSize = reader->bwavSize; reader = nullptr; @@ -1085,7 +1085,7 @@ bool WavAudioFormat::replaceMetadataInFile (const File& wavFile, const StringPai { ScopedPointer out (wavFile.createOutputStream()); out->setPosition (bwavPos); - out->write (chunk.getData(), (int) chunk.getSize()); + *out << chunk; out->setPosition (oldSize); } diff --git a/modules/juce_audio_plugin_client/utility/juce_IncludeSystemHeaders.h b/modules/juce_audio_plugin_client/utility/juce_IncludeSystemHeaders.h index 6be765cf1e..5b98e65165 100644 --- a/modules/juce_audio_plugin_client/utility/juce_IncludeSystemHeaders.h +++ b/modules/juce_audio_plugin_client/utility/juce_IncludeSystemHeaders.h @@ -23,8 +23,6 @@ ============================================================================== */ -#include - #if JUCE_WINDOWS #undef _WIN32_WINNT #define _WIN32_WINNT 0x500 @@ -49,11 +47,12 @@ #undef Time #else + #include + #ifndef JUCE_SUPPORT_CARBON #define JUCE_SUPPORT_CARBON 1 #endif - #include #if JUCE_SUPPORT_CARBON #define Point CarbonDummyPointName #define Component CarbonDummyCompName diff --git a/modules/juce_core/native/juce_linux_Network.cpp b/modules/juce_core/native/juce_linux_Network.cpp index 2098247732..1e94ac43e5 100644 --- a/modules/juce_core/native/juce_linux_Network.cpp +++ b/modules/juce_core/native/juce_linux_Network.cpp @@ -67,7 +67,6 @@ bool Process::openEmailWithAttachments (const String& targetEmailAddress, class WebInputStream : public InputStream { public: - //============================================================================== WebInputStream (const String& address_, bool isPost_, const MemoryBlock& postData_, URL::OpenStreamProgressCallback* progressCallback, void* progressCallbackContext, const String& headers_, int timeOutMs_, StringPairArray* responseHeaders) @@ -333,35 +332,34 @@ private: return String::empty; } + static void writeValueIfNotPresent (MemoryOutputStream& dest, const String& headers, const String& key, const String& value) + { + if (! headers.containsIgnoreCase (key)) + dest << "\r\n" << key << ' ' << value; + } + static MemoryBlock createRequestHeader (const String& hostName, const int hostPort, const String& proxyName, const int proxyPort, const String& hostPath, const String& originalURL, const String& headers, const MemoryBlock& postData, const bool isPost) { - String header (isPost ? "POST " : "GET "); + MemoryOutputStream header; + + header << (isPost ? "POST " : "GET "); if (proxyName.isEmpty()) - { - header << hostPath << " HTTP/1.0\r\nHost: " - << hostName << ':' << hostPort; - } + header << hostPath << " HTTP/1.0\r\nHost: " << hostName << ':' << hostPort; else - { - header << originalURL << " HTTP/1.0\r\nHost: " - << proxyName << ':' << proxyPort; - } - - header << "\r\nUser-Agent: JUCE/" << JUCE_MAJOR_VERSION << '.' << JUCE_MINOR_VERSION - << "\r\nConnection: Close\r\nContent-Length: " - << (int) postData.getSize() << "\r\n" - << headers << "\r\n"; + header << originalURL << " HTTP/1.0\r\nHost: " << proxyName << ':' << proxyPort; - MemoryBlock mb; - mb.append (header.toUTF8(), (int) strlen (header.toUTF8())); - mb.append (postData.getData(), postData.getSize()); + writeValueIfNotPresent (header, headers, "User-Agent:", "JUCE/" + String (JUCE_MAJOR_VERSION) + "." + String (JUCE_MINOR_VERSION)); + writeValueIfNotPresent (header, headers, "Connection:", "Close"); + writeValueIfNotPresent (header, headers, "Content-Length:", String ((int) postData.getSize())); + header << "\r\n" << headers + << "\r\n" << postData; - return mb; + return header.getMemoryBlock(); } static bool sendHeader (int socketHandle, const MemoryBlock& requestHeader, const uint32 timeOutTime, diff --git a/modules/juce_core/streams/juce_MemoryOutputStream.cpp b/modules/juce_core/streams/juce_MemoryOutputStream.cpp index e250a08a8a..078407f824 100644 --- a/modules/juce_core/streams/juce_MemoryOutputStream.cpp +++ b/modules/juce_core/streams/juce_MemoryOutputStream.cpp @@ -103,14 +103,17 @@ void MemoryOutputStream::writeRepeatedByte (uint8 byte, int howMany) } } -const void* MemoryOutputStream::getData() const noexcept +const MemoryBlock& MemoryOutputStream::getMemoryBlock() const noexcept { - void* const d = data.getData(); - if (data.getSize() > size) - static_cast (d) [size] = 0; + static_cast (data.getData()) [size] = 0; + + return data; +} - return d; +const void* MemoryOutputStream::getData() const noexcept +{ + return getMemoryBlock().getData(); } bool MemoryOutputStream::setPosition (int64 newPosition) @@ -157,8 +160,7 @@ String MemoryOutputStream::toString() const OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const MemoryOutputStream& streamToRead) { - stream.write (streamToRead.getData(), (int) streamToRead.getDataSize()); - return stream; + return stream << streamToRead.getMemoryBlock(); } END_JUCE_NAMESPACE diff --git a/modules/juce_core/streams/juce_MemoryOutputStream.h b/modules/juce_core/streams/juce_MemoryOutputStream.h index 758fc6c922..baf1ce7121 100644 --- a/modules/juce_core/streams/juce_MemoryOutputStream.h +++ b/modules/juce_core/streams/juce_MemoryOutputStream.h @@ -97,6 +97,9 @@ public: */ String toString() const; + /** Returns the memory block that is being used internally to hold the data. */ + const MemoryBlock& getMemoryBlock() const noexcept; + //============================================================================== /** If the stream is writing to a user-supplied MemoryBlock, this will trim any excess capacity off the block, so that its length matches the amount of actual data that diff --git a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp index 94902390c8..b69f8d66b7 100644 --- a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp @@ -2325,18 +2325,15 @@ private: if ((lParam & GCS_RESULTSTR) != 0) // (composition has finished) { replaceCurrentSelection (target, getCompositionString (hImc, GCS_RESULTSTR), - Range::emptyRange (compositionRange.getEnd())); + Range::emptyRange (-1)); + reset(); target->setTemporaryUnderlining (Array >()); - - compositionInProgress = false; } else if ((lParam & GCS_COMPSTR) != 0) // (composition is still in-progress) { - const String newContent (getCompositionString (hImc, GCS_COMPSTR)); - const Range selection (getCompositionSelection (hImc, lParam)); - - replaceCurrentSelection (target, newContent, selection); + replaceCurrentSelection (target, getCompositionString (hImc, GCS_COMPSTR), + getCompositionSelection (hImc, lParam)); target->setTemporaryUnderlining (getCompositionUnderlines (hImc, lParam)); compositionInProgress = true; @@ -2425,12 +2422,17 @@ private: return Range (selectionStart, selectionEnd) + compositionRange.getStart(); } - void replaceCurrentSelection (TextInputTarget* const target, const String& newContent, const Range& newSelection) + void replaceCurrentSelection (TextInputTarget* const target, const String& newContent, Range newSelection) { - target->setHighlightedRegion (compositionRange); + if (compositionInProgress) + target->setHighlightedRegion (compositionRange); + target->insertTextAtCaret (newContent); compositionRange.setLength (newContent.length()); + if (newSelection.getStart() < 0) + newSelection = Range::emptyRange (compositionRange.getEnd()); + target->setHighlightedRegion (newSelection); }