GPU: show more descriptive labels on unsupported GPU dialog
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Wed, 9 Oct 2019 11:36:56 +0000 (13:36 +0200)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Wed, 9 Oct 2019 11:41:26 +0000 (13:41 +0200)
Thanks to Ray Molenkamp for the help with the Windows implementation.

Fixes T70521

Differential Revision: https://developer.blender.org/D6023

12 files changed:
build_files/cmake/platform/platform_win32.cmake
intern/ghost/GHOST_C-api.h
intern/ghost/GHOST_ISystem.h
intern/ghost/intern/GHOST_C-api.cpp
intern/ghost/intern/GHOST_System.h
intern/ghost/intern/GHOST_SystemWin32.cpp
intern/ghost/intern/GHOST_SystemWin32.h
intern/ghost/intern/GHOST_SystemX11.cpp
intern/ghost/intern/GHOST_SystemX11.h
source/blender/windowmanager/intern/wm_platform_support.c
source/blender/windowmanager/intern/wm_window.c
source/blender/windowmanager/intern/wm_window_private.h

index 7e0fff00a37ffc3f11339c51e91f9465d5a1b2f9..7956a2993201f7acb75802ef06b365409acc8457 100644 (file)
@@ -112,7 +112,7 @@ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO")
 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /SAFESEH:NO")
 
 list(APPEND PLATFORM_LINKLIBS
-  ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32
+  ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 Comctl32
   advapi32 shfolder shell32 ole32 oleaut32 uuid psapi Dbghelp
 )
 
index 5e0216c03391103a2f548905dfc721d307be973a..720929ce9459a30c0c38c9ce8e944a0d7bd1c26a 100644 (file)
@@ -70,6 +70,8 @@ extern GHOST_TSuccess GHOST_DisposeSystem(GHOST_SystemHandle systemhandle);
  * \param systemhandle    The handle to the system
  * \param title           Title of the message box
  * \param message         Message of the message box
+ * \param help_label      Text to show on the help button that opens a link
+ * \param continue_label  Text to show on the ok button that continues
  * \param link            Optional (hyper)link to a webpage to show when pressing help
  * \param dialog_options  Options to configure the message box.
  * \return void.
@@ -77,6 +79,8 @@ extern GHOST_TSuccess GHOST_DisposeSystem(GHOST_SystemHandle systemhandle);
 extern void GHOST_ShowMessageBox(GHOST_SystemHandle systemhandle,
                                  const char *title,
                                  const char *message,
+                                 const char *help_label,
+                                 const char *continue_label,
                                  const char *link,
                                  GHOST_DialogOptions dialog_options);
 
index d89785ad9b2b81191582e0d8040ef77b90b21535..fe2f42df8a63dff2d4d1c08dc0e1d5b6a852bb1a 100644 (file)
@@ -446,11 +446,15 @@ class GHOST_ISystem {
    *
    * \param title                   The title of the message box
    * \param message                 The message to display
+   * \param help_label              Help button label
+   * \param continue_label          Continue button label
    * \param link                    An optional hyperlink
    * \param dialog_options Options  how to display the message
    */
   virtual GHOST_TSuccess showMessageBox(const char * /*title*/,
                                         const char * /*message*/,
+                                        const char * /*help_label*/,
+                                        const char * /*continue_label*/,
                                         const char * /*link*/,
                                         GHOST_DialogOptions /*dialog_options*/) const = 0;
 
index 4d755de77ff77a415c0ee612efe0e813c4d530da..eeb23ea7471e5545e5bc7f21020e83725164a1cf 100644 (file)
@@ -50,11 +50,13 @@ GHOST_TSuccess GHOST_DisposeSystem(GHOST_SystemHandle systemhandle)
 void GHOST_ShowMessageBox(GHOST_SystemHandle systemhandle,
                           const char *title,
                           const char *message,
+                          const char *help_label,
+                          const char *continue_label,
                           const char *link,
                           GHOST_DialogOptions dialog_options)
 {
   GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
-  system->showMessageBox(title, message, link, dialog_options);
+  system->showMessageBox(title, message, help_label, continue_label, link, dialog_options);
 }
 
 GHOST_EventConsumerHandle GHOST_CreateEventConsumer(GHOST_EventCallbackProcPtr eventCallback,
index ea85611870ad7e4fa307293ff6418fe70fcad540..893592e3cf5db5c931dfbc9b2666ee4f47783b35 100644 (file)
@@ -313,11 +313,15 @@ class GHOST_System : public GHOST_ISystem {
    * Show a system message box
    * \param title                   The title of the message box
    * \param message                 The message to display
+   * \param help_label              Help button label
+   * \param continue_label          Continue button label
    * \param link                    An optional hyperlink
    * \param dialog_options Options  how to display the message
    */
   virtual GHOST_TSuccess showMessageBox(const char * /*title*/,
                                         const char * /*message*/,
+                                        const char * /*help_label */,
+                                        const char * /*continue_label */,
                                         const char * /*link*/,
                                         GHOST_DialogOptions /*dialog_options*/) const
   {
index 1423e0df8ec46c175992b3d643f95a885adf1ec9..c86accf4eded1e24df7b547d906cc866dff4bf21 100644 (file)
 #  define _WIN32_IE 0x0501 /* shipped before XP, so doesn't impose additional requirements */
 #endif
 
+/* clang-format off */
+#pragma comment(linker,"\"/manifestdependency:type='win32' \
+name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
+processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
+/* clang-format on */
+
+#include <commctrl.h>
 #include <shlobj.h>
 #include <tlhelp32.h>
 #include <psapi.h>
@@ -35,6 +42,7 @@
 #include <windowsx.h>
 
 #include "utfconv.h"
+#include "utf_winfunc.h"
 
 #include "GHOST_DisplayManagerWin32.h"
 #include "GHOST_EventButton.h"
@@ -511,6 +519,7 @@ GHOST_TSuccess GHOST_SystemWin32::getButtons(GHOST_Buttons &buttons) const
 GHOST_TSuccess GHOST_SystemWin32::init()
 {
   GHOST_TSuccess success = GHOST_System::init();
+  InitCommonControls();
 
   /* Disable scaling on high DPI displays on Vista */
   HMODULE
@@ -1773,41 +1782,51 @@ void GHOST_SystemWin32::putClipboard(GHOST_TInt8 *buffer, bool selection) const
 
 /** \name Message Box
  * \{ */
-static const char *MESSAGE_BOX_HELP_LINK_PTR = NULL;
-VOID CALLBACK showMessageBoxCallBack(LPHELPINFO lpHelpInfo)
-{
-  if (MESSAGE_BOX_HELP_LINK_PTR) {
-    ShellExecute(NULL, "open", MESSAGE_BOX_HELP_LINK_PTR, NULL, NULL, SW_SHOWNORMAL);
-  }
-}
-
 GHOST_TSuccess GHOST_SystemWin32::showMessageBox(const char *title,
                                                  const char *message,
+                                                 const char *help_label,
+                                                 const char *continue_label,
                                                  const char *link,
                                                  GHOST_DialogOptions dialog_options) const
 {
-  uint style = MB_OK |
-               (dialog_options & GHOST_DialogError ?
-                    MB_ICONERROR :
-                    dialog_options & GHOST_DialogWarning ? MB_ICONWARNING : MB_ICONINFORMATION);
-  bool show_help = link && strlen(link);
-  if (show_help) {
-    GHOST_ASSERT(MESSAGE_BOX_HELP_LINK_PTR == NULL,
-                 "showMessageBox: MESSAGE_BOX_HELP_LINK_PTR is in use");
-    style |= MB_HELP;
-    MESSAGE_BOX_HELP_LINK_PTR = link;
+  const wchar_t *title_16 = alloc_utf16_from_8(title, 0);
+  const wchar_t *message_16 = alloc_utf16_from_8(message, 0);
+  const wchar_t *help_label_16 = alloc_utf16_from_8(help_label, 0);
+  const wchar_t *continue_label_16 = alloc_utf16_from_8(continue_label, 0);
+
+  int nButtonPressed = 0;
+  TASKDIALOGCONFIG config = {0};
+  const TASKDIALOG_BUTTON buttons[] = {{IDOK, help_label_16}, {IDCONTINUE, continue_label_16}};
+
+  config.cbSize = sizeof(config);
+  config.hInstance = 0;
+  config.dwCommonButtons = 0;
+  config.pszMainIcon = (dialog_options & GHOST_DialogError ?
+                            TD_ERROR_ICON :
+                            dialog_options & GHOST_DialogWarning ? TD_WARNING_ICON :
+                                                                   TD_INFORMATION_ICON);
+  config.pszWindowTitle = L"Blender";
+  config.pszMainInstruction = title_16;
+  config.pszContent = message_16;
+  config.pButtons = (link) ? buttons : buttons + 1;
+  config.cButtons = (link) ? 2 : 1;
+
+  TaskDialogIndirect(&config, &nButtonPressed, NULL, NULL);
+  switch (nButtonPressed) {
+    case IDOK:
+      ShellExecute(NULL, "open", link, NULL, NULL, SW_SHOWNORMAL);
+      break;
+    case IDCONTINUE:
+      break;
+    default:
+      break;  // should never happen
   }
 
-  MSGBOXPARAMSA message_box_params = {0};
-  message_box_params.cbSize = sizeof(MSGBOXCALLBACK);
-  message_box_params.lpszText = message;
-  message_box_params.lpszCaption = title;
-  message_box_params.dwStyle = style;
-  message_box_params.lpszText = message;
-  message_box_params.lpfnMsgBoxCallback = showMessageBoxCallBack;
+  free((void *)title_16);
+  free((void *)message_16);
+  free((void *)help_label_16);
+  free((void *)continue_label_16);
 
-  MessageBoxIndirectA(&message_box_params);
-  MESSAGE_BOX_HELP_LINK_PTR = NULL;
   return GHOST_kSuccess;
 }
 /* \} */
index 6e803b3d760bc16adf42bf16ffebea3b8d585a3c..391f0866cd7244e00bc08592b1dc4c31faa9e3d7 100644 (file)
@@ -29,9 +29,6 @@
 #  error WIN32 only!
 #endif  // WIN32
 
-/* require Windows XP or newer */
-#undef _WIN32_WINNT
-#define _WIN32_WINNT 0x501
 
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
@@ -208,11 +205,15 @@ class GHOST_SystemWin32 : public GHOST_System {
    * Show a system message box
    * \param title                   The title of the message box
    * \param message                 The message to display
+   * \param help_label              Help button label
+   * \param continue_label          Continue button label
    * \param link                    An optional hyperlink
    * \param dialog_options Options  how to display the message
    */
   GHOST_TSuccess showMessageBox(const char *title,
                                 const char *message,
+                                const char *help_label,
+                                const char *continue_label,
                                 const char *link,
                                 GHOST_DialogOptions dialog_options) const;
 
index a6c6aaffd6f399c5b278ddfae06cabbb6f2b66ac..1ca412fbccca64d06f48486c9fc286b261227a4d 100644 (file)
@@ -2176,7 +2176,7 @@ class DialogData {
         height(175),
         padding_x(10),
         padding_y(5),
-        button_width(50),
+        button_width(130),
         button_height(24),
         button_inset_x(10),
         button_border_size(1),
@@ -2247,6 +2247,8 @@ static void split(const char *text, const char *seps, char ***str, int *count)
 
 GHOST_TSuccess GHOST_SystemX11::showMessageBox(const char *title,
                                                const char *message,
+                                               const char *help_label,
+                                               const char *continue_label,
                                                const char *link,
                                                GHOST_DialogOptions) const
 {
@@ -2325,20 +2327,24 @@ GHOST_TSuccess GHOST_SystemX11::showMessageBox(const char *title,
                     text_splitted[i],
                     (int)strlen(text_splitted[i]));
       }
-      dialog_data.drawButton(m_display, window, buttonBorderGC, buttonGC, 1, "Ok");
+      dialog_data.drawButton(m_display, window, buttonBorderGC, buttonGC, 1, continue_label);
       if (strlen(link)) {
-        dialog_data.drawButton(m_display, window, buttonBorderGC, buttonGC, 2, "Help");
+        dialog_data.drawButton(m_display, window, buttonBorderGC, buttonGC, 2, help_label);
       }
     }
     else if (e.type == ButtonRelease) {
       if (dialog_data.isInsideButton(e, 1)) {
         break;
       }
-      else if (strlen(link) && dialog_data.isInsideButton(e, 2)) {
-        string cmd = "xdg-open \"" + string(link) + "\"";
-        if (system(cmd.c_str()) != 0) {
-          GHOST_PRINTF("GHOST_SystemX11::showMessageBox: Unable to run system command [%s]", cmd);
+      else if (dialog_data.isInsideButton(e, 2)) {
+        if (strlen(link)) {
+          string cmd = "xdg-open \"" + string(link) + "\"";
+          if (system(cmd.c_str()) != 0) {
+            GHOST_PRINTF("GHOST_SystemX11::showMessageBox: Unable to run system command [%s]",
+                         cmd);
+          }
         }
+        break;
       }
     }
   }
index ba7371c6ea0c5e29d9788f6914306e8f28bf3e33..67dd0789ac3e791277488ff309e2d17ee8e42525 100644 (file)
@@ -237,11 +237,15 @@ class GHOST_SystemX11 : public GHOST_System {
    * Show a system message box
    * \param title                   The title of the message box
    * \param message                 The message to display
+   * \param help_label              Help button label
+   * \param continue_label          Continue button label
    * \param link                    An optional hyperlink
    * \param dialog_options Options  how to display the message
    */
   GHOST_TSuccess showMessageBox(const char *title,
                                 const char *message,
+                                const char *help_label,
+                                const char *continue_label,
                                 const char *link,
                                 GHOST_DialogOptions dialog_options) const;
 #ifdef WITH_XDND
index 9ed6f9f4299a00041a83e18d3c00e8926123fc13..5153fc33d49cb3fe1f23a80b0fbf8cd71afc8d39 100644 (file)
@@ -152,10 +152,11 @@ bool WM_platform_support_perform_checks()
       /* TODO: Extra space is needed for the split function in GHOST_SystemX11. We should change
        * the behavior in GHOST_SystemX11. */
       STR_CONCAT(message, slen, "\n \n");
-      STR_CONCAT(message,
-                 slen,
-                 CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER,
-                            "Press help to see if the support can be improved."));
+      STR_CONCAT(
+          message,
+          slen,
+          CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER,
+                     "Newer graphics drivers may be available to improve Blender support."));
       STR_CONCAT(message, slen, "\n \n");
       STR_CONCAT(message, slen, CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER, "Graphics card:\n"));
       STR_CONCAT(message, slen, GPU_platform_gpu_name());
@@ -176,10 +177,11 @@ bool WM_platform_support_perform_checks()
                             "Your graphics card or driver is not supported."));
 
       STR_CONCAT(message, slen, "\n \n");
-      STR_CONCAT(message,
-                 slen,
-                 CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER,
-                            "Press help to see if the support can be improved."));
+      STR_CONCAT(
+          message,
+          slen,
+          CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER,
+                     "Newer graphics drivers may be available to improve Blender support."));
 
       STR_CONCAT(message, slen, "\n \n");
       STR_CONCAT(message, slen, CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER, "Graphics card:\n"));
@@ -209,8 +211,9 @@ bool WM_platform_support_perform_checks()
     result = true;
   }
   else if (show_message) {
-    WM_ghost_show_message_box(title, message, link, dialog_options);
+    WM_ghost_show_message_box(
+        title, message, "Find Latest Drivers", "Continue Anyway", link, dialog_options);
   }
 
   return result;
-}
\ No newline at end of file
+}
index ac10f9489a225b72173562a7eec8889b01df42bc..fa2320585d78770e240b9d03d986f00b8b086633 100644 (file)
@@ -2435,10 +2435,12 @@ void WM_opengl_context_release(void *context)
 
 void WM_ghost_show_message_box(const char *title,
                                const char *message,
+                               const char *help_label,
+                               const char *continue_label,
                                const char *link,
                                GHOST_DialogOptions dialog_options)
 {
   BLI_assert(g_system);
-  GHOST_ShowMessageBox(g_system, title, message, link, dialog_options);
+  GHOST_ShowMessageBox(g_system, title, message, help_label, continue_label, link, dialog_options);
 }
 /** \} */
index 189b77721cf3c098014e006d136fc3fe53020aa6..115539861d74e096667692846d0e60d1505b0645 100644 (file)
@@ -34,6 +34,8 @@
  * In all other cases this message box should not be used. */
 void WM_ghost_show_message_box(const char *title,
                                const char *message,
+                               const char *help_label,
+                               const char *continue_label,
                                const char *link,
                                GHOST_DialogOptions dialog_options);