Mercurial > dwindows
comparison gtk4/dw.c @ 3005:522ef24b0aba default tip
GTK4: Fix even more deprecation warnings in GTK 4.10 and later.
Migrate to GtkAlertDialog for 4.10 from GtkMessageDialog.
Still need to center the dialog or something.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 20 Dec 2023 05:17:54 +0000 |
parents | 0ea8d055e7df |
children |
comparison
equal
deleted
inserted
replaced
3004:0ea8d055e7df | 3005:522ef24b0aba |
---|---|
1848 void API dw_vdebug(const char *format, va_list args) | 1848 void API dw_vdebug(const char *format, va_list args) |
1849 { | 1849 { |
1850 vfprintf(stderr, format, args); | 1850 vfprintf(stderr, format, args); |
1851 } | 1851 } |
1852 | 1852 |
1853 #if GTK_CHECK_VERSION(4,10,0) | |
1854 static void _dw_alert_dialog_choose_response(GObject *gobject, GAsyncResult *result, gpointer data) | |
1855 { | |
1856 DWDialog *tmp = data; | |
1857 GError *error = NULL; | |
1858 int retval = gtk_alert_dialog_choose_finish(GTK_ALERT_DIALOG(gobject), result, &error); | |
1859 | |
1860 if(error != NULL) | |
1861 { | |
1862 retval = -1; | |
1863 } | |
1864 dw_dialog_dismiss(tmp, DW_INT_TO_POINTER(retval)); | |
1865 } | |
1866 | |
1867 static char *_DW_BUTTON_OK = "Ok"; | |
1868 static char *_DW_BUTTON_YES = "Yes"; | |
1869 static char *_DW_BUTTON_NO = "No"; | |
1870 static char *_DW_BUTTON_CANCEL = "Cancel"; | |
1871 #endif | |
1872 | |
1853 /* Internal version that does not use variable arguments */ | 1873 /* Internal version that does not use variable arguments */ |
1854 DW_FUNCTION_DEFINITION(dw_messagebox_int, int, const char *title, int flags, char *outbuf) | 1874 DW_FUNCTION_DEFINITION(dw_messagebox_int, int, const char *title, int flags, char *outbuf) |
1855 DW_FUNCTION_ADD_PARAM3(title, flags, outbuf) | 1875 DW_FUNCTION_ADD_PARAM3(title, flags, outbuf) |
1856 DW_FUNCTION_RETURN(dw_messagebox_int, int) | 1876 DW_FUNCTION_RETURN(dw_messagebox_int, int) |
1857 DW_FUNCTION_RESTORE_PARAM3(title, const char *, flags, int, outbuf, char *) | 1877 DW_FUNCTION_RESTORE_PARAM3(title, const char *, flags, int, outbuf, char *) |
1858 { | 1878 { |
1879 int response, retval = DW_MB_RETURN_OK; | |
1880 DWDialog *tmp = dw_dialog_new(NULL); | |
1881 #if GTK_CHECK_VERSION(4,10,0) | |
1882 GtkAlertDialog *ad = gtk_alert_dialog_new("%s", title); | |
1883 char *buttons[4] = { 0 }; | |
1884 int button = 0; | |
1885 | |
1886 gtk_alert_dialog_set_message(ad, outbuf); | |
1887 gtk_alert_dialog_set_modal(ad, TRUE); | |
1888 | |
1889 if(flags & (DW_MB_OK | DW_MB_OKCANCEL)) | |
1890 buttons[button++] = _DW_BUTTON_OK; | |
1891 if(flags & (DW_MB_YESNO | DW_MB_YESNOCANCEL)) | |
1892 buttons[button++] = _DW_BUTTON_YES; | |
1893 if(flags & (DW_MB_YESNO | DW_MB_YESNOCANCEL)) | |
1894 buttons[button++] = _DW_BUTTON_NO; | |
1895 if(flags & (DW_MB_OKCANCEL | DW_MB_YESNOCANCEL)) | |
1896 buttons[button++] = _DW_BUTTON_CANCEL; | |
1897 gtk_alert_dialog_set_buttons(ad, (const char * const*)buttons); | |
1898 | |
1899 gtk_alert_dialog_choose(ad, NULL, NULL, (GAsyncReadyCallback)_dw_alert_dialog_choose_response, tmp); | |
1900 | |
1901 response = DW_POINTER_TO_INT(dw_dialog_wait(tmp)); | |
1902 | |
1903 if(response < 0 || response >= button || buttons[response] == _DW_BUTTON_OK) | |
1904 retval = DW_MB_RETURN_OK; | |
1905 else if(buttons[response] == _DW_BUTTON_CANCEL) | |
1906 retval = DW_MB_RETURN_CANCEL; | |
1907 else if(buttons[response] == _DW_BUTTON_YES) | |
1908 retval = DW_MB_RETURN_YES; | |
1909 else if(buttons[response] == _DW_BUTTON_NO) | |
1910 retval = DW_MB_RETURN_NO; | |
1911 #else | |
1859 GtkMessageType gtkicon = GTK_MESSAGE_OTHER; | 1912 GtkMessageType gtkicon = GTK_MESSAGE_OTHER; |
1860 GtkButtonsType gtkbuttons = GTK_BUTTONS_OK; | 1913 GtkButtonsType gtkbuttons = GTK_BUTTONS_OK; |
1861 GtkWidget *dialog; | 1914 GtkWidget *dialog; |
1862 int response, retval = DW_MB_RETURN_OK; | |
1863 DWDialog *tmp = dw_dialog_new(NULL); | |
1864 ULONG width, height; | 1915 ULONG width, height; |
1865 | 1916 |
1866 if(flags & DW_MB_ERROR) | 1917 if(flags & DW_MB_ERROR) |
1867 gtkicon = GTK_MESSAGE_ERROR; | 1918 gtkicon = GTK_MESSAGE_ERROR; |
1868 else if(flags & DW_MB_WARNING) | 1919 else if(flags & DW_MB_WARNING) |
1912 retval = DW_MB_RETURN_CANCEL; | 1963 retval = DW_MB_RETURN_CANCEL; |
1913 else if(flags & DW_MB_YESNO) | 1964 else if(flags & DW_MB_YESNO) |
1914 retval = DW_MB_RETURN_NO; | 1965 retval = DW_MB_RETURN_NO; |
1915 } | 1966 } |
1916 } | 1967 } |
1968 #endif | |
1917 DW_FUNCTION_RETURN_THIS(retval); | 1969 DW_FUNCTION_RETURN_THIS(retval); |
1918 } | 1970 } |
1919 | 1971 |
1920 /* | 1972 /* |
1921 * Displays a Message Box with given text and title.. | 1973 * Displays a Message Box with given text and title.. |