reapack

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

commit 5def8798a8e18d7422526382c9e905e8a5595f10
parent 6520c5739a4927719885167797c3063929df4ebd
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Mon,  1 Feb 2016 20:56:34 -0500

fix a crash on OS X occuring since 722d619dfbcb3329d3aaf7d784d07099b0f27038

1) Open a remote's about dialog
2) Hover some text and links in the description tabs
3) Close the dialog
4) Press the right mouse button in the bottom of the remote list,
   and drag to to the bottom of the window until the mouse leaves it
   then release.
5) Crash in -[SWELL_APP_PREFIX_hwnd mouseDragged:] because SWELL tries
to send an event to the captured control (RichEdit *m_about) wich is
deleted.

Diffstat:
Msrc/richedit.cpp | 55++++++++++++++++++++++++++-----------------------------
Msrc/richedit.hpp | 6+-----
Msrc/richedit.mm | 26++++++++++++++++++++++----
3 files changed, 49 insertions(+), 38 deletions(-)

diff --git a/src/richedit.cpp b/src/richedit.cpp @@ -17,63 +17,60 @@ #include "richedit.hpp" -#include <memory> +#ifdef _WIN32 -#include "encoding.hpp" +// Starting here and onward is the Win32 implementation of RichEdit +// The OS X implementation can be found in richedit.mm -#ifdef _WIN32 -#include <sstream> +#include <memory> #include <richedit.h> -#endif +#include <sstream> + +#include "encoding.hpp" using namespace std; +static void HandleLink(ENLINK *info, HWND handle) +{ + const CHARRANGE &range = info->chrg; + + auto_char *url = new auto_char[(range.cpMax - range.cpMin) + 1](); + unique_ptr<auto_char[]> ptr(url); + + TEXTRANGE tr{range, url}; + SendMessage(handle, EM_GETTEXTRANGE, 0, (LPARAM)&tr); + + if(info->msg == WM_LBUTTONUP) + ShellExecute(nullptr, AUTO_STR("open"), url, nullptr, nullptr, SW_SHOW); +} + void RichEdit::Init() { -#ifdef _WIN32 LoadLibrary(AUTO_STR("Msftedit.dll")); -#endif } RichEdit::RichEdit(HWND handle) : Control(handle) { -#ifdef _WIN32 SendMessage(handle, EM_AUTOURLDETECT, true, 0); SendMessage(handle, EM_SETEVENTMASK, 0, ENM_LINK); SendMessage(handle, EM_SETEDITSTYLE, SES_HYPERLINKTOOLTIPS, SES_HYPERLINKTOOLTIPS); -#endif +} + +RichEdit::~RichEdit() +{ } void RichEdit::onNotify(LPNMHDR info, LPARAM lParam) { -#ifdef _WIN32 switch(info->code) { case EN_LINK: - handleLink(lParam); + HandleLink((ENLINK *)lParam, handle()); break; }; -#endif -} - -#ifdef _WIN32 -void RichEdit::handleLink(LPARAM lParam) -{ - ENLINK *info = (ENLINK *)lParam; - const CHARRANGE &range = info->chrg; - - auto_char *url = new auto_char[(range.cpMax - range.cpMin) + 1](); - unique_ptr<auto_char[]> ptr(url); - - TEXTRANGE tr{range, url}; - SendMessage(handle(), EM_GETTEXTRANGE, 0, (LPARAM)&tr); - - if(info->msg == WM_LBUTTONUP) - ShellExecute(nullptr, AUTO_STR("open"), url, nullptr, nullptr, SW_SHOW); } -// OS X implementation of setRichText in richedit.mm bool RichEdit::setRichText(const string &rtf) { stringstream stream(rtf); diff --git a/src/richedit.hpp b/src/richedit.hpp @@ -27,16 +27,12 @@ public: static void Init(); RichEdit(HWND); + ~RichEdit(); bool setRichText(const std::string &); protected: void onNotify(LPNMHDR, LPARAM) override; - -private: -#ifdef _WIN32 - void handleLink(LPARAM); -#endif }; #endif diff --git a/src/richedit.mm b/src/richedit.mm @@ -21,6 +21,28 @@ using namespace std; +void RichEdit::Init() +{ +} + +RichEdit::RichEdit(HWND handle) + : Control(handle) +{ + // hack: restore NSTextView's default mouse cursors (eg. hover links) + // this is an incomplete fix for the hyperlink's shy tooltips + SetCapture(handle); +} + +RichEdit::~RichEdit() +{ + if(GetCapture() == handle()) + ReleaseCapture(); +} + +void RichEdit::onNotify(LPNMHDR, LPARAM) +{ +} + bool RichEdit::setRichText(const string &rtf) { NSString *str = [NSString @@ -43,9 +65,5 @@ bool RichEdit::setRichText(const string &rtf) [textView checkTextInDocument:nil]; [textView setEditable:isEditable]; - // hack: restore NSTextView's default mouse cursors (eg. hover links) - // this doesn't fix the shy link tooltips - SetCapture(handle()); - return [[textView string] length]; }