SDL: Use SDL_MessageBoxFlags and SDL_MessageBoxButtonFlags appropriately

From 991d28ae37a77b5338222134d40b18d094ccd0cf Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 7 May 2024 13:23:55 -0700
Subject: [PATCH] Use SDL_MessageBoxFlags and SDL_MessageBoxButtonFlags
 appropriately

---
 src/video/SDL_video.c                     |  2 +-
 src/video/haiku/SDL_bmessagebox.cc        | 25 +++++++----------------
 src/video/riscos/SDL_riscosmessagebox.c   |  4 ++--
 src/video/wayland/SDL_waylandmessagebox.c |  2 +-
 src/video/windows/SDL_windowsmessagebox.c |  4 ++--
 5 files changed, 13 insertions(+), 24 deletions(-)

diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 403f488f60d21..39093c2fc3996 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -5098,7 +5098,7 @@ int SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID)
     return retval;
 }
 
-int SDL_ShowSimpleMessageBox(Uint32 flags, const char *title, const char *message, SDL_Window *window)
+int SDL_ShowSimpleMessageBox(SDL_MessageBoxFlags flags, const char *title, const char *message, SDL_Window *window)
 {
 #ifdef SDL_PLATFORM_EMSCRIPTEN
     /* !!! FIXME: propose a browser API for this, get this #ifdef out of here? */
diff --git a/src/video/haiku/SDL_bmessagebox.cc b/src/video/haiku/SDL_bmessagebox.cc
index 7308d582dd233..8b929dc42193d 100644
--- a/src/video/haiku/SDL_bmessagebox.cc
+++ b/src/video/haiku/SDL_bmessagebox.cc
@@ -154,7 +154,7 @@ class HAIKU_SDL_MessageBox : public BAlert
 		(aMessageBoxData->message[0]) ?
 			SetMessageText(aMessageBoxData->message) : SetMessageText(HAIKU_SDL_DefMessage);
 
-		SetType(ConvertMessageBoxType(static_cast<SDL_MessageBoxFlags>(aMessageBoxData->flags)));
+		SetType(ConvertMessageBoxType(aMessageBoxData->flags));
 	}
 
 	void
@@ -264,23 +264,12 @@ class HAIKU_SDL_MessageBox : public BAlert
 
 		size_t countButtons = fButtons.size();
 		for (size_t i = 0; i < countButtons; ++i) {
-			switch (fButtons[i]->flags)
-			{
-				case SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT:
-				{
-					fCloseButton = static_cast<int>(i);
-					break;
-				}
-				case SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT:
-				{
-					fDefaultButton = static_cast<int>(i);
-					break;
-				}
-				default:
-				{
-					break;
-				}
-			}
+			if (fButtons[i]->flags & SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) {
+                fCloseButton = static_cast<int>(i);
+            }
+			if (fButtons[i]->flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) {
+                fDefaultButton = static_cast<int>(i);
+            }
 			AddButton(fButtons[i]->text);
 		}
 
diff --git a/src/video/riscos/SDL_riscosmessagebox.c b/src/video/riscos/SDL_riscosmessagebox.c
index 4ab79405af3fb..5ca0712141897 100644
--- a/src/video/riscos/SDL_riscosmessagebox.c
+++ b/src/video/riscos/SDL_riscosmessagebox.c
@@ -39,9 +39,9 @@ int RISCOS_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonI
     regs.r[0] = (unsigned int)&error;
 
     regs.r[1] = (1 << 8) | (1 << 4);
-    if (messageboxdata->flags == SDL_MESSAGEBOX_INFORMATION) {
+    if (messageboxdata->flags & SDL_MESSAGEBOX_INFORMATION) {
         regs.r[1] |= (1 << 9);
-    } else if (messageboxdata->flags == SDL_MESSAGEBOX_WARNING) {
+    } else if (messageboxdata->flags & SDL_MESSAGEBOX_WARNING) {
         regs.r[1] |= (2 << 9);
     }
 
diff --git a/src/video/wayland/SDL_waylandmessagebox.c b/src/video/wayland/SDL_waylandmessagebox.c
index 2a8540d0695a0..2167e2ab0d948 100644
--- a/src/video/wayland/SDL_waylandmessagebox.c
+++ b/src/video/wayland/SDL_waylandmessagebox.c
@@ -166,7 +166,7 @@ int Wayland_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *button
      * We need to handle it gracefully, otherwise no message box will be shown.
      */
     argv[argc++] = zenity_major > 3 || (zenity_major == 3 && zenity_minor >= 90) ? "--icon" : "--icon-name";
-    switch (messageboxdata->flags) {
+    switch (messageboxdata->flags & (SDL_MESSAGEBOX_ERROR | SDL_MESSAGEBOX_WARNING | SDL_MESSAGEBOX_INFORMATION)) {
     case SDL_MESSAGEBOX_ERROR:
         argv[argc++] = "dialog-error";
         break;
diff --git a/src/video/windows/SDL_windowsmessagebox.c b/src/video/windows/SDL_windowsmessagebox.c
index 9c0a2dc2562c4..0b8837ed9a838 100644
--- a/src/video/windows/SDL_windowsmessagebox.c
+++ b/src/video/windows/SDL_windowsmessagebox.c
@@ -238,7 +238,7 @@ typedef struct
     WORD numbuttons;
 } WIN_DialogData;
 
-static SDL_bool GetButtonIndex(const SDL_MessageBoxData *messageboxdata, Uint32 flags, size_t *i)
+static SDL_bool GetButtonIndex(const SDL_MessageBoxData *messageboxdata, SDL_MessageBoxButtonFlags flags, size_t *i)
 {
     for (*i = 0; *i < (size_t)messageboxdata->numbuttons; ++*i) {
         if (messageboxdata->buttons[*i].flags & flags) {
@@ -701,7 +701,7 @@ static int WIN_ShowOldMessageBox(const SDL_MessageBoxData *messageboxdata, int *
         return SDL_SetError("Number of buttons exceeds limit of %d", MAX_BUTTONS);
     }
 
-    switch (messageboxdata->flags) {
+    switch (messageboxdata->flags & (SDL_MESSAGEBOX_ERROR | SDL_MESSAGEBOX_WARNING | SDL_MESSAGEBOX_INFORMATION)) {
     case SDL_MESSAGEBOX_ERROR:
         icon = (Uint16)(size_t)IDI_ERROR;
         break;