lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] Ctrl-C in message box in Wine


From: Greg Chicares
Subject: Re: [lmi] Ctrl-C in message box in Wine
Date: Thu, 2 May 2019 21:58:43 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1

On 2019-05-02 15:12, Vadim Zeitlin wrote:
> On Thu, 2 May 2019 01:20:24 +0000 Greg Chicares <address@hidden> wrote:
> 
> GC> BTW, in msw I could copy the contents of a messagebox with Ctrl-C
> GC> or something, but that doesn't work in wine, so I have to transcribe
> GC> diagnostics manually. Fixing wine sounds hard;
> 
>  It isn't really, I've had a look at dlls/user32/msgbox.c in Wine sources
> and adding a handler for WM_CHAR/WM_KEYDOWN there seems pretty
> straightforward. Of course, a patch doing this would take some time to be
> accepted into Wine (assuming it is accepted) and propagate into Debian from
> there, but maybe you could use your own build of Wine in the meanwhile?

If it's that easy, then would you send winehq a patch, please?

> GC> maybe the answer is to print a copy of any messagebox's contents on the
> GC> console.
> 
>  We could use a custom wxMessageOutput object in lmi: from what I remember
> you're somewhat allergic to wxLog, but wxMessageOutput is much more
> straightforward and is really just a direct replacement for modal
> wxMessageBox calls, so I hope this would be less controversial.

Please see the idea I've thrown together as an lmi patch below.

>  But I believe adding the missing feature to Wine would be a better choice.

Yes, that's the right thing to do, for the long term. For now,
what do you think of the following? End users run without a
console, so they'd never see console output. This new feature
might be turned on or off with a command-line switch. I haven't
really polished the idea, but I'm using it already to debug a
production problem.

diff --git a/alert.cpp b/alert.cpp
index 43b5483b..282513b1 100644
--- a/alert.cpp
+++ b/alert.cpp
@@ -23,12 +23,11 @@
 
 #include "alert.hpp"
 
-#if !defined LMI_MSW
-#   include <cstdio>
-#else  // defined LMI_MSW
+#if defined LMI_MSW
 #   include <windows.h>
 #endif // defined LMI_MSW
 
+#include <cstdio>
 #include <ios>
 #include <sstream>                      // stringbuf
 #include <stdexcept>
@@ -69,11 +68,8 @@ inline bool any_function_pointer_has_been_set()
 
 void report_catastrophe(char const* message)
 {
-#if !defined LMI_MSW
-    std::fputs(message, stderr);
-    std::fputc('\n'   , stderr);
-    std::fflush(stderr);
-#else  // defined LMI_MSW
+    safely_show_on_stdout(message);
+#if defined LMI_MSW
     ::MessageBoxA
         (0
         ,message
@@ -223,6 +219,19 @@ std::ostream& alarum()
     return alert_stream<alarum_buf>();
 }
 
+void LMI_SO safely_show_on_stdout(char const* message)
+{
+    std::fputs(message, stderr);
+    std::fputc('\n'   , stderr);
+    // Flush explicitly. C99 7.19.3/7 says only that stderr is
+    // "not fully buffered", not that it is 'unbuffered'. See:
+    //   http://article.gmane.org/gmane.comp.gnu.mingw.user/14358
+    //     [2004-12-20T09:07:24Z from Danny Smith]
+    //   http://article.gmane.org/gmane.comp.gnu.mingw.user/15063
+    //     [2005-02-10T17:23:09Z from Greg Chicares]
+    std::fflush(stderr);
+}
+
 void safely_show_message(char const* message)
 {
     if(nullptr == safe_message_alert_function)
diff --git a/alert.hpp b/alert.hpp
index 7b32ec99..81bdf931 100644
--- a/alert.hpp
+++ b/alert.hpp
@@ -163,6 +163,8 @@ std::ostream& LMI_SO warning();
 std::ostream& LMI_SO hobsons_choice();
 std::ostream& LMI_SO alarum();
 
+void LMI_SO safely_show_on_stdout(char const*);
+
 void LMI_SO safely_show_message(char const*);
 void LMI_SO safely_show_message(std::string const&);
 
diff --git a/alert_wx.cpp b/alert_wx.cpp
index 9f8144c7..dd613ebc 100644
--- a/alert_wx.cpp
+++ b/alert_wx.cpp
@@ -33,7 +33,8 @@
 #   include <wx/msw/wrapwin.h>          // HWND etc.
 #endif // defined LMI_MSW
 
-#include <cstdio>
+//#include <cstdio>
+#include <iostream>
 #include <stdexcept>
 
 LMI_FORCE_LINKING_IN_SITU(alert_wx)
@@ -72,6 +73,7 @@ void status_alert(std::string const& s)
 
 void warning_alert(std::string const& s)
 {
+    std::cerr << "Warning: " << s << std::endl;
     wxMessageBox(s, "Warning", wxOK, wxTheApp ? wxTheApp->GetTopWindow() : 
nullptr);
 }
 
@@ -85,6 +87,8 @@ void warning_alert(std::string const& s)
 
 void hobsons_choice_alert(std::string const& s)
 {
+    std::cerr << "Hobson's choice: " << s << std::endl;
+
     wxWindow* w = nullptr;
     if(wxTheApp)
         {
@@ -121,6 +125,7 @@ void hobsons_choice_alert(std::string const& s)
 
 void alarum_alert(std::string const& s)
 {
+    std::cerr << "Alarum: " << s << std::endl;
     throw std::runtime_error(s);
 }
 
@@ -148,17 +153,8 @@ void alarum_alert(std::string const& s)
 
 void safe_message_alert(char const* message)
 {
-#if !defined LMI_MSW
-    std::fputs(message, stderr);
-    std::fputc('\n'   , stderr);
-    // Flush explicitly. C99 7.19.3/7 says only that stderr is
-    // "not fully buffered", not that it is 'unbuffered'. See:
-    //   http://article.gmane.org/gmane.comp.gnu.mingw.user/14358
-    //     [2004-12-20T09:07:24Z from Danny Smith]
-    //   http://article.gmane.org/gmane.comp.gnu.mingw.user/15063
-    //     [2005-02-10T17:23:09Z from Greg Chicares]
-    std::fflush(stderr);
-#else  // defined LMI_MSW
+    safely_show_on_stdout(message);
+#if defined LMI_MSW
     HWND handle = 0;
     if(wxTheApp && wxTheApp->GetTopWindow())
         {



reply via email to

[Prev in Thread] Current Thread [Next in Thread]