From cf682b9dab36c4b96084c6f7b5e4ebc1f33ca28e Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Wed, 9 Oct 2019 13:36:56 +0200 Subject: GPU: show more descriptive labels on unsupported GPU dialog Thanks to Ray Molenkamp for the help with the Windows implementation. Fixes T70521 Differential Revision: https://developer.blender.org/D6023 --- intern/ghost/GHOST_C-api.h | 4 ++ intern/ghost/GHOST_ISystem.h | 4 ++ intern/ghost/intern/GHOST_C-api.cpp | 4 +- intern/ghost/intern/GHOST_System.h | 4 ++ intern/ghost/intern/GHOST_SystemWin32.cpp | 73 +++++++++++++++++++------------ intern/ghost/intern/GHOST_SystemWin32.h | 7 +-- intern/ghost/intern/GHOST_SystemX11.cpp | 20 ++++++--- intern/ghost/intern/GHOST_SystemX11.h | 4 ++ 8 files changed, 82 insertions(+), 38 deletions(-) (limited to 'intern') diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h index 5e0216c0339..720929ce945 100644 --- a/intern/ghost/GHOST_C-api.h +++ b/intern/ghost/GHOST_C-api.h @@ -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); diff --git a/intern/ghost/GHOST_ISystem.h b/intern/ghost/GHOST_ISystem.h index d89785ad9b2..fe2f42df8a6 100644 --- a/intern/ghost/GHOST_ISystem.h +++ b/intern/ghost/GHOST_ISystem.h @@ -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; diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp index 4d755de77ff..eeb23ea7471 100644 --- a/intern/ghost/intern/GHOST_C-api.cpp +++ b/intern/ghost/intern/GHOST_C-api.cpp @@ -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, diff --git a/intern/ghost/intern/GHOST_System.h b/intern/ghost/intern/GHOST_System.h index ea85611870a..893592e3cf5 100644 --- a/intern/ghost/intern/GHOST_System.h +++ b/intern/ghost/intern/GHOST_System.h @@ -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 { diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp index 1423e0df8ec..c86accf4ede 100644 --- a/intern/ghost/intern/GHOST_SystemWin32.cpp +++ b/intern/ghost/intern/GHOST_SystemWin32.cpp @@ -28,6 +28,13 @@ # 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 #include #include #include @@ -35,6 +42,7 @@ #include #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; } /* \} */ diff --git a/intern/ghost/intern/GHOST_SystemWin32.h b/intern/ghost/intern/GHOST_SystemWin32.h index 6e803b3d760..391f0866cd7 100644 --- a/intern/ghost/intern/GHOST_SystemWin32.h +++ b/intern/ghost/intern/GHOST_SystemWin32.h @@ -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 @@ -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; diff --git a/intern/ghost/intern/GHOST_SystemX11.cpp b/intern/ghost/intern/GHOST_SystemX11.cpp index a6c6aaffd6f..1ca412fbccc 100644 --- a/intern/ghost/intern/GHOST_SystemX11.cpp +++ b/intern/ghost/intern/GHOST_SystemX11.cpp @@ -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; } } } diff --git a/intern/ghost/intern/GHOST_SystemX11.h b/intern/ghost/intern/GHOST_SystemX11.h index ba7371c6ea0..67dd0789ac3 100644 --- a/intern/ghost/intern/GHOST_SystemX11.h +++ b/intern/ghost/intern/GHOST_SystemX11.h @@ -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 -- cgit v1.2.3