Skip to content

Commit

Permalink
Drop win32_message_dialog()s
Browse files Browse the repository at this point in the history
There doesn't seem to be much need for these and they look a little
different from the rest of Geany (or a lot different when Windows
uses the dark theme and Geany the light one). Before removing the native
win32 file open dialogs, win32_message_dialog() was called from the native
file dialog implementations so its presence was necessary but I think
normal GTK dialogs will serve their purpose well.
  • Loading branch information
techee committed Jun 12, 2024
1 parent 0528657 commit 8f00b04
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 97 deletions.
35 changes: 1 addition & 34 deletions src/dialogs.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include "support.h"
#include "utils.h"
#include "ui_utils.h"
#include "win32.h"

#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
Expand Down Expand Up @@ -712,7 +711,6 @@ gboolean dialogs_show_save_as(void)
}


#ifndef G_OS_WIN32
static void show_msgbox_dialog(GtkWidget *dialog, GtkMessageType type, GtkWindow *parent)
{
const gchar *title;
Expand All @@ -738,13 +736,10 @@ static void show_msgbox_dialog(GtkWidget *dialog, GtkMessageType type, GtkWindow
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
}
#endif


/**
* Shows a message box of the type @a type with @a text.
* On Unix-like systems a GTK message dialog box is shown, on Win32 systems a native Windows
* message dialog box is shown.
*
* @param type A @c GtkMessageType, e.g. @c GTK_MESSAGE_INFO, @c GTK_MESSAGE_WARNING,
* @c GTK_MESSAGE_QUESTION, @c GTK_MESSAGE_ERROR.
Expand All @@ -754,9 +749,7 @@ static void show_msgbox_dialog(GtkWidget *dialog, GtkMessageType type, GtkWindow
GEANY_API_SYMBOL
void dialogs_show_msgbox(GtkMessageType type, const gchar *text, ...)
{
#ifndef G_OS_WIN32
GtkWidget *dialog;
#endif
gchar *string;
va_list args;
GtkWindow *parent = (main_status.main_window_realized) ? GTK_WINDOW(main_widgets.window) : NULL;
Expand All @@ -765,32 +758,22 @@ void dialogs_show_msgbox(GtkMessageType type, const gchar *text, ...)
string = g_strdup_vprintf(text, args);
va_end(args);

#ifdef G_OS_WIN32
win32_message_dialog(GTK_WIDGET(parent), type, string);
#else
dialog = gtk_message_dialog_new(parent, GTK_DIALOG_DESTROY_WITH_PARENT,
type, GTK_BUTTONS_OK, "%s", string);
show_msgbox_dialog(dialog, type, parent);
#endif
g_free(string);
}


void dialogs_show_msgbox_with_secondary(GtkMessageType type, const gchar *text, const gchar *secondary)
{
GtkWindow *parent = (main_status.main_window_realized) ? GTK_WINDOW(main_widgets.window) : NULL;
#ifdef G_OS_WIN32
/* put the two strings together because Windows message boxes don't support secondary texts */
gchar *string = g_strconcat(text, "\n", secondary, NULL);
win32_message_dialog(GTK_WIDGET(parent), type, string);
g_free(string);
#else
GtkWidget *dialog;

dialog = gtk_message_dialog_new(parent, GTK_DIALOG_DESTROY_WITH_PARENT,
type, GTK_BUTTONS_OK, "%s", text);
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), "%s", secondary);
show_msgbox_dialog(dialog, type, parent);
#endif
}


Expand Down Expand Up @@ -1317,20 +1300,6 @@ static gint show_prompt(GtkWidget *parent,
response_3 = GTK_RESPONSE_YES;
}

#ifdef G_OS_WIN32
/* our native dialog code doesn't support custom buttons */
if (utils_str_equal(btn_3, GTK_STOCK_YES) &&
utils_str_equal(btn_2, GTK_STOCK_NO) && btn_1 == NULL)
{
gchar *string = (extra_text == NULL) ? g_strdup(question_text) :
g_strconcat(question_text, "\n\n", extra_text, NULL);

ret = win32_message_dialog(parent, GTK_MESSAGE_QUESTION, string);
ret = ret ? response_3 : response_2;
g_free(string);
return ret;
}
#endif
if (parent == NULL && main_status.main_window_realized)
parent = main_widgets.window;

Expand Down Expand Up @@ -1363,8 +1332,6 @@ static gint show_prompt(GtkWidget *parent,

/**
* Shows a question message box with @a text and Yes/No buttons.
* On Unix-like systems a GTK message dialog box is shown, on Win32 systems a native Windows
* message dialog box is shown.
*
* @param text Printf()-style format string.
* @param ... Arguments for the @a text format string.
Expand Down
61 changes: 0 additions & 61 deletions src/win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,67 +60,6 @@
#include <gdk/gdkwin32.h>


/* Creates a native Windows message box of the given type and returns always TRUE
* or FALSE representing th pressed Yes or No button.
* If type is not GTK_MESSAGE_QUESTION, it returns always TRUE. */
gboolean win32_message_dialog(GtkWidget *parent, GtkMessageType type, const gchar *msg)
{
gboolean ret = TRUE;
gint rc;
guint t;
const gchar *title;
HWND parent_hwnd = NULL;
static wchar_t w_msg[512];
static wchar_t w_title[512];

switch (type)
{
case GTK_MESSAGE_ERROR:
{
t = MB_OK | MB_ICONERROR;
title = _("Error");
break;
}
case GTK_MESSAGE_QUESTION:
{
t = MB_YESNO | MB_ICONQUESTION;
title = _("Question");
break;
}
case GTK_MESSAGE_WARNING:
{
t = MB_OK | MB_ICONWARNING;
title = _("Warning");
break;
}
default:
{
t = MB_OK | MB_ICONINFORMATION;
title = _("Information");
break;
}
}

/* convert the Unicode chars to wide chars */
/** TODO test if LANG == C then possibly skip conversion => g_win32_getlocale() */
MultiByteToWideChar(CP_UTF8, 0, msg, -1, w_msg, G_N_ELEMENTS(w_msg));
MultiByteToWideChar(CP_UTF8, 0, title, -1, w_title, G_N_ELEMENTS(w_title));

if (parent != NULL)
parent_hwnd = GDK_WINDOW_HWND(gtk_widget_get_window(parent));
else if (main_widgets.window != NULL)
parent_hwnd = GDK_WINDOW_HWND(gtk_widget_get_window(main_widgets.window));

/* display the message box */
rc = MessageBoxW(parent_hwnd, w_msg, w_title, t);

if (type == GTK_MESSAGE_QUESTION && rc != IDYES)
ret = FALSE;

return ret;
}


/* Little wrapper for _waccess(), returns errno or 0 if there was no error */
gint win32_check_write_permission(const gchar *dir)
{
Expand Down
2 changes: 0 additions & 2 deletions src/win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@

G_BEGIN_DECLS

gboolean win32_message_dialog(GtkWidget *parent, GtkMessageType type, const gchar *msg);

void win32_open_browser(const gchar *uri);


Expand Down

0 comments on commit 8f00b04

Please sign in to comment.