reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

commit 042ab4701e47f998f9511430c4069a716df3ddec
parent 41bb668b607210149234828dd61a9d940bdff914
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Sun, 29 Oct 2017 11:17:35 -0400

about: always show the about tab (even if documentation is empty or invalid)

Diffstat:
Msrc/about.cpp | 8++++++--
Msrc/richedit-gtk.cpp | 5+++++
Msrc/richedit-win32.cpp | 12+++++++++---
Msrc/richedit.hpp | 1+
Msrc/richedit.mm | 34++++++++++++++++++++++++----------
5 files changed, 45 insertions(+), 15 deletions(-)

diff --git a/src/about.cpp b/src/about.cpp @@ -182,8 +182,12 @@ void About::setMetadata(const Metadata *metadata, const bool substitution) boost::replace_all(aboutText, "[[REAPACK_BUILDTIME]]", ReaPack::BUILDTIME); } - if(m_desc->setRichText(aboutText)) - m_tabs->addTab({"About", {m_desc->handle()}}); + if(aboutText.empty()) + m_desc->setPlainText("This package or repository does not provide any documentation."); + else if(!m_desc->setRichText(aboutText)) + m_desc->setPlainText("Could not load RTF document."); + + m_tabs->addTab({"About", {m_desc->handle()}}); const auto &getLinkControl = [](const Metadata::LinkType type) { switch(type) { diff --git a/src/richedit-gtk.cpp b/src/richedit-gtk.cpp @@ -41,6 +41,11 @@ void RichEdit::onNotify(LPNMHDR, LPARAM) { } +void RichEdit::setPlainText(const string &text) +{ + SetWindowText(handle(), text.c_str()); +} + bool RichEdit::setRichText(const string &) { return false; diff --git a/src/richedit-win32.cpp b/src/richedit-win32.cpp @@ -20,7 +20,9 @@ #ifdef _WIN32 // Starting here and onward is the Win32 implementation of RichEdit -// The OS X implementation can be found in richedit.mm +// The macOS implementation is in richedit.mm, Linux is in richedit-gtk.cpp + +#include "win32.hpp" #include <memory> #include <richedit.h> @@ -69,14 +71,18 @@ void RichEdit::onNotify(LPNMHDR info, LPARAM lParam) }; } +void RichEdit::setPlainText(const string &text) +{ + Win32::setWindowText(handle(), text.c_str()); +} + bool RichEdit::setRichText(const string &rtf) { stringstream stream(rtf); EDITSTREAM es{}; es.dwCookie = (DWORD_PTR)&stream; - es.pfnCallback = [](DWORD_PTR cookie, LPBYTE buf, LONG size, LONG *pcb) - { + es.pfnCallback = [](DWORD_PTR cookie, LPBYTE buf, LONG size, LONG *pcb) { stringstream *stream = reinterpret_cast<stringstream *>(cookie); *pcb = (LONG)stream->readsome((char *)buf, size); return (DWORD)0; diff --git a/src/richedit.hpp b/src/richedit.hpp @@ -29,6 +29,7 @@ public: RichEdit(HWND); ~RichEdit(); + void setPlainText(const std::string &); bool setRichText(const std::string &); protected: diff --git a/src/richedit.mm b/src/richedit.mm @@ -43,25 +43,39 @@ void RichEdit::onNotify(LPNMHDR, LPARAM) { } -bool RichEdit::setRichText(const string &rtf) +void RichEdit::setPlainText(const string &text) { NSString *str = [NSString - stringWithCString:rtf.c_str() - encoding:NSUTF8StringEncoding + stringWithCString: text.c_str() + encoding: NSUTF8StringEncoding ]; NSTextView *textView = (NSTextView *)handle(); - // Manually clear the view so that invalid content will always result - // in this function to return false. Without this, the old text would be - // retained, length would stay the same and we would return true. - [textView setString: @""]; + NSAttributedString *attrStr = [[NSAttributedString alloc] initWithString: str]; + [[textView textStorage] setAttributedString: attrStr]; + [attrStr release]; +} - [textView - replaceCharactersInRange: NSMakeRange(0, [[textView string] length]) - withRTF: [str dataUsingEncoding: NSUTF8StringEncoding] +bool RichEdit::setRichText(const string &rtf) +{ + NSString *str = [NSString + stringWithCString: rtf.c_str() + encoding: NSUTF8StringEncoding ]; + NSTextView *textView = (NSTextView *)handle(); + + NSAttributedString *attrStr = [[NSAttributedString alloc] + initWithRTF: [str dataUsingEncoding: NSUTF8StringEncoding] + documentAttributes: nullptr]; + + if(!attrStr) + return false; + + [[textView textStorage] setAttributedString: attrStr]; + [attrStr release]; + // auto-detect links, equivalent to Windows' EM_AUTOURLDETECT message const BOOL isEditable = textView.isEditable; [textView setEditable: YES];