diff options
Diffstat (limited to 'mate-dictionary/src')
22 files changed, 772 insertions, 476 deletions
diff --git a/mate-dictionary/src/Makefile.am b/mate-dictionary/src/Makefile.am index af5e4edc..8616b3ef 100644 --- a/mate-dictionary/src/Makefile.am +++ b/mate-dictionary/src/Makefile.am @@ -1,3 +1,18 @@ +# This file is part of MATE Utils. +# +# MATE Utils is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# MATE Utils is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with MATE Utils. If not, see <https://www.gnu.org/licenses/>. + NULL = AM_CPPFLAGS = \ @@ -12,8 +27,12 @@ AM_CPPFLAGS = \ bin_PROGRAMS = mate-dictionary if BUILD_GDICT_APPLET +if ENABLE_IN_PROCESS +pkglib_LTLIBRARIES = libmate-dictionary-applet.la +else libexec_PROGRAMS = mate-dictionary-applet endif +endif mate_dictionary_SOURCES = \ gdict-about.c \ @@ -41,6 +60,7 @@ mate_dictionary_CFLAGS = \ $(GLIB_CFLAGS) \ $(GIO_CFLAGS) \ $(GTK_CFLAGS) \ + $(MATE_DESKTOP_CFLAGS) \ $(WARN_CFLAGS) \ $(NULL) @@ -50,10 +70,60 @@ mate_dictionary_LDADD = \ $(GLIB_LIBS) \ $(GIO_LIBS) \ $(GTK_LIBS) \ + $(MATE_DESKTOP_LIBS) \ $(NULL) if BUILD_GDICT_APPLET +if ENABLE_IN_PROCESS +libmate_dictionary_applet_la_SOURCES = \ + gdict-about.c \ + gdict-about.h \ + gdict-aligned-window.c \ + gdict-aligned-window.h \ + gdict-applet.c \ + gdict-applet.h \ + gdict-common.c \ + gdict-common.h \ + gdict-pref-dialog.c \ + gdict-pref-dialog.h \ + gdict-print.c \ + gdict-print.h \ + gdict-sidebar.c \ + gdict-sidebar.h \ + gdict-source-dialog.c \ + gdict-source-dialog.h \ + $(NULL) + +libmate_dictionary_applet_la_CFLAGS = \ + -I$(top_builddir)/mate-dictionary \ + -I$(top_srcdir)/mate-dictionary \ + $(APPLET_CFLAGS) \ + $(GLIB_CFLAGS) \ + $(GIO_CFLAGS) \ + $(GTK_CFLAGS) \ + $(MATE_DESKTOP_CFLAGS) \ + $(WARN_CFLAGS) \ + $(NULL) + +libmate_dictionary_applet_la_LIBADD = \ + -lm \ + $(top_builddir)/mate-dictionary/libgdict/libmatedict.la \ + $(APPLET_LIBS) \ + $(GLIB_LIBS) \ + $(GIO_LIBS) \ + $(GTK_LIBS) \ + $(MATE_DESKTOP_LIBS) \ + $(NULL) + +if ENABLE_WAYLAND +libmate_dictionary_applet_la_LIBADD += \ + $(WAYLAND_LIBS) +libmate_dictionary_applet_la_CFLAGS += \ + $(WAYLAND_CFLAGS) +endif + +else mate_dictionary_applet_SOURCES = \ gdict-about.c \ gdict-about.h \ @@ -80,6 +150,7 @@ mate_dictionary_applet_CFLAGS = \ $(GLIB_CFLAGS) \ $(GIO_CFLAGS) \ $(GTK_CFLAGS) \ + $(MATE_DESKTOP_CFLAGS) \ $(WARN_CFLAGS) \ $(NULL) @@ -90,8 +161,9 @@ mate_dictionary_applet_LDADD = \ $(GLIB_LIBS) \ $(GIO_LIBS) \ $(GTK_LIBS) \ + $(MATE_DESKTOP_LIBS) \ $(NULL) - +endif # ENABLE_IN_PROCESS endif # BUILD_GDICT_APPLET -include $(top_srcdir)/git.mk diff --git a/mate-dictionary/src/gdict-about.c b/mate-dictionary/src/gdict-about.c index 7a4979b4..914324ea 100644 --- a/mate-dictionary/src/gdict-about.c +++ b/mate-dictionary/src/gdict-about.c @@ -1,27 +1,24 @@ -/* gdict-about.c - GtkAboutDialog wrapper +/* Copyright (C) 2005 Emmanuele Bassi + * Copyright (C) 2012-2021 MATE Developers * - * This file is part of MATE Dictionary + * This file is part of MATE Utils. * - * Copyright (C) 2005 Emmanuele Bassi + * MATE Utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, + * MATE Utils is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301, USA. + * along with MATE Utils. If not, see <https://www.gnu.org/licenses/>. */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include <config.h> #endif #include <stdio.h> @@ -68,9 +65,7 @@ gdict_show_about_dialog (GtkWidget *parent) "General Public License for more details."), N_("You should have received a copy of the GNU General Public License " - "along with this program; if not, write to the Free Software " - "Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA " - "02110-1301, USA.") + "along with this program. If not, see <https://www.gnu.org/licenses/>.") }; g_return_if_fail (GTK_IS_WIDGET (parent)); @@ -88,7 +83,7 @@ gdict_show_about_dialog (GtkWidget *parent) "version", VERSION, "title", _("About Dictionary"), "copyright", _("Copyright \xc2\xa9 2005-2006 Emmanuele Bassi\n" - "Copyright \xc2\xa9 2011-2020 MATE developers"), + "Copyright \xc2\xa9 2011-2021 MATE developers"), "comments", comments, "authors", authors, "documenters", documenters, diff --git a/mate-dictionary/src/gdict-about.h b/mate-dictionary/src/gdict-about.h index 0e2e5a74..1393a9b6 100644 --- a/mate-dictionary/src/gdict-about.h +++ b/mate-dictionary/src/gdict-about.h @@ -1,23 +1,20 @@ -/* gdict-about.h - GtkAboutDialog wrapper +/* Copyright (C) 2005 Emmanuele Bassi + * Copyright (C) 2012-2021 MATE Developers * - * This file is part of MATE Dictionary + * This file is part of MATE Utils. * - * Copyright (C) 2005 Emmanuele Bassi + * MATE Utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, + * MATE Utils is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301, USA. + * along with MATE Utils. If not, see <https://www.gnu.org/licenses/>. */ #ifndef __GDICT_ABOUT_H__ diff --git a/mate-dictionary/src/gdict-aligned-window.c b/mate-dictionary/src/gdict-aligned-window.c index 3384840a..c4a7bca1 100644 --- a/mate-dictionary/src/gdict-aligned-window.c +++ b/mate-dictionary/src/gdict-aligned-window.c @@ -1,27 +1,27 @@ -/* gdict-aligned-window.c - Popup window aligned to a widget +/* Copyright (C) 2005-2006 Emmanuele Bassi <[email protected]> + * Copyright (C) 2012-2021 MATE Developers * - * Copyright (c) 2005-2006 Emmanuele Bassi <[email protected]> + * Ported from Seth Nickell's Python class. + * Copyright (C) 2003 Seth Nickell * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. + * This file is part of MATE Utils. * - * This program is distributed in the hope that it will be useful, + * MATE Utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * MATE Utils is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Ported from Seth Nickell's Python class: - * Copyright (c) 2003 Seth Nickell + * You should have received a copy of the GNU General Public License + * along with MATE Utils. If not, see <https://www.gnu.org/licenses/>. */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include <config.h> #endif #include <stdio.h> @@ -33,6 +33,11 @@ #include "gdict-aligned-window.h" +#if defined (ENABLE_WAYLAND) && defined (GDK_WINDOWING_WAYLAND) +#include <gdk/gdkwayland.h> +#include <gtk-layer-shell/gtk-layer-shell.h> +#endif + struct _GdictAlignedWindowPrivate { GtkWidget *align_widget; @@ -64,11 +69,8 @@ static gboolean gdict_aligned_window_motion_notify_cb (GtkWidget *widget, GdkEventMotion *event, GdictAlignedWindow *aligned_window); - G_DEFINE_TYPE_WITH_PRIVATE (GdictAlignedWindow, gdict_aligned_window, GTK_TYPE_WINDOW); - - static void gdict_aligned_window_class_init (GdictAlignedWindowClass *klass) { @@ -157,8 +159,10 @@ gdict_aligned_window_position (GdictAlignedWindow *window) gint entry_x, entry_y, entry_width, entry_height; gint x, y; GdkGravity gravity = GDK_GRAVITY_NORTH_WEST; - GdkWindow *gdk_window; + GdkWindow *gdk_window; GdkDisplay *display; + GdkMonitor *monitor; + GdkRectangle geometry = {0}; g_assert (GDICT_IS_ALIGNED_WINDOW (window)); priv = window->priv; @@ -188,7 +192,12 @@ gdict_aligned_window_position (GdictAlignedWindow *window) &entry_y); gdk_window_get_geometry (gdk_window, NULL, NULL, &entry_width, &entry_height); - if (entry_x + our_width < WidthOfScreen (gdk_x11_screen_get_xscreen (gdk_screen_get_default ()))) + /*Get the monitor dimensions*/ + display= gdk_screen_get_display (gdk_screen_get_default ()); + monitor = gdk_display_get_monitor (display, 0); + gdk_monitor_get_geometry (monitor, &geometry); + + if (entry_x + our_width < geometry.width) x = entry_x + 1; else { @@ -197,7 +206,7 @@ gdict_aligned_window_position (GdictAlignedWindow *window) gravity = GDK_GRAVITY_NORTH_EAST; } - if (entry_y + entry_height + our_height < HeightOfScreen (gdk_x11_screen_get_xscreen (gdk_screen_get_default ()))) + if (entry_y + entry_height + our_height < geometry.height) y = entry_y + entry_height - 1; else { @@ -211,6 +220,100 @@ gdict_aligned_window_position (GdictAlignedWindow *window) gtk_window_set_gravity (GTK_WINDOW (window), gravity); gtk_window_move (GTK_WINDOW (window), x, y); + +#if defined (ENABLE_WAYLAND) && defined (GDK_WINDOWING_WAYLAND) + if (GDK_IS_WAYLAND_DISPLAY (display)) + { + gboolean top, bottom, left, right; + GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET(priv->align_widget)); + + top = gtk_layer_get_anchor (GTK_WINDOW (toplevel), GTK_LAYER_SHELL_EDGE_TOP); + bottom = gtk_layer_get_anchor (GTK_WINDOW (toplevel), GTK_LAYER_SHELL_EDGE_BOTTOM); + left = gtk_layer_get_anchor (GTK_WINDOW (toplevel), GTK_LAYER_SHELL_EDGE_LEFT); + right = gtk_layer_get_anchor (GTK_WINDOW (toplevel), GTK_LAYER_SHELL_EDGE_RIGHT); + + /*Set anchors to the edges (will hold to panel edge) and position along the panel + *Confine the dialog to the screen dimensions if the applet is near right or bottom + *Unset margins and anchors from any other position so as to avoid rendering issues + *when orientation changes as when the panel is moved + */ + if (top && left && right) + { + gtk_layer_set_anchor (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_TOP, TRUE); + gtk_layer_set_anchor (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_BOTTOM, FALSE); + if (entry_x + our_width >= geometry.width) + { + gtk_layer_set_anchor (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_LEFT, FALSE); + gtk_layer_set_anchor (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_RIGHT,TRUE); + gtk_layer_set_margin (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_LEFT, 0); + } + else + { + gtk_layer_set_anchor (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_LEFT, TRUE); + gtk_layer_set_anchor (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_RIGHT, FALSE); + gtk_layer_set_margin (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_LEFT, entry_x); + } + gtk_layer_set_margin (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_TOP, 0); + } + + if (bottom && left && right) + { + gtk_layer_set_anchor (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_BOTTOM, TRUE); + gtk_layer_set_anchor (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_TOP, FALSE); + if (entry_x + our_width >= geometry.width) + { + gtk_layer_set_anchor (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_LEFT, FALSE); + gtk_layer_set_anchor (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_RIGHT,TRUE); + gtk_layer_set_margin (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_LEFT, 0); + } + else + { + gtk_layer_set_anchor (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_LEFT, TRUE); + gtk_layer_set_anchor (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_RIGHT, FALSE); + gtk_layer_set_margin (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_LEFT, entry_x); + } + + gtk_layer_set_margin (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_TOP, 0); + } + if (left && bottom && top && !right) + { + gtk_layer_set_anchor (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_LEFT, TRUE); + gtk_layer_set_anchor (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_RIGHT, FALSE); + if (entry_y + our_height >= geometry.height) + { + gtk_layer_set_anchor (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_TOP, FALSE); + gtk_layer_set_anchor (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_BOTTOM, TRUE); + gtk_layer_set_margin (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_TOP, 0); + } + else + { + gtk_layer_set_anchor (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_TOP, TRUE); + gtk_layer_set_anchor (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_BOTTOM, FALSE); + gtk_layer_set_margin (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_TOP, entry_y); + } + gtk_layer_set_margin (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_LEFT, 0); + } + if (right && bottom && top && !left) + { + gtk_layer_set_anchor (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_RIGHT, TRUE); + gtk_layer_set_anchor (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_LEFT, FALSE); + if (entry_y + our_height >= geometry.height) + { + gtk_layer_set_anchor (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_TOP, FALSE); + gtk_layer_set_anchor (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_BOTTOM, TRUE); + gtk_layer_set_margin (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_TOP, 0); + } + else + { + gtk_layer_set_anchor (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_TOP, TRUE); + gtk_layer_set_anchor (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_BOTTOM, FALSE); + gtk_layer_set_margin (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_TOP, entry_y); + } + gtk_layer_set_margin (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_TOP, entry_y); + gtk_layer_set_margin (GTK_WINDOW (window), GTK_LAYER_SHELL_EDGE_LEFT, 0); + } + } +#endif } static void @@ -257,7 +360,6 @@ gdict_aligned_window_motion_notify_cb (GtkWidget *widget, return FALSE; } - /** * gdict_aligned_window_new: * @align_widget: a #GtkWidget to which the window should align diff --git a/mate-dictionary/src/gdict-aligned-window.h b/mate-dictionary/src/gdict-aligned-window.h index d1f4f67e..b6c887d9 100644 --- a/mate-dictionary/src/gdict-aligned-window.h +++ b/mate-dictionary/src/gdict-aligned-window.h @@ -1,23 +1,23 @@ -/* gdict-aligned-widget.h - Popup window aligned to a widget +/* Copyright (c) 2005 Emmanuele Bassi <[email protected]> + * Copyright (C) 2012-2021 MATE Developers * - * Copyright (c) 2005 Emmanuele Bassi <[email protected]> + * Ported from Seth Nickell's Python class. + * Copyright (c) 2003 Seth Nickell * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. + * This file is part of MATE Utils. * - * This program is distributed in the hope that it will be useful, + * MATE Utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * MATE Utils is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU Library General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Ported from Seth Nickell's Python class: - * Copyright (c) 2003 Seth Nickell + * You should have received a copy of the GNU General Public License + * along with MATE Utils. If not, see <https://www.gnu.org/licenses/>. */ #ifndef __GDICT_ALIGNED_WINDOW_H__ diff --git a/mate-dictionary/src/gdict-app.c b/mate-dictionary/src/gdict-app.c index fe5e5b32..6c5f228f 100644 --- a/mate-dictionary/src/gdict-app.c +++ b/mate-dictionary/src/gdict-app.c @@ -1,27 +1,24 @@ -/* gdict-app.c - main application class +/* Copyright (C) 2005 Emmanuele Bassi + * Copyright (C) 2012-2021 MATE Developers * - * This file is part of MATE Dictionary + * This file is part of MATE Utils. * - * Copyright (C) 2005 Emmanuele Bassi + * MATE Utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, + * MATE Utils is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301, USA. + * along with MATE Utils. If not, see <https://www.gnu.org/licenses/>. */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include <config.h> #endif #include <stdio.h> @@ -40,17 +37,13 @@ static GdictApp *singleton = NULL; - struct _GdictAppClass { GObjectClass parent_class; }; - - G_DEFINE_TYPE (GdictApp, gdict_app, G_TYPE_OBJECT); - static void gdict_app_finalize (GObject *object) { @@ -334,7 +327,7 @@ gdict_init (int *argc, char ***argv) N_("Database to use"), N_("db") }, { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &lookup_words, N_("Words to look up"), N_("word") }, - { NULL }, + { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }, }; g_assert (singleton == NULL); @@ -345,7 +338,9 @@ gdict_init (int *argc, char ***argv) /* create the new option context */ context = g_option_context_new (_(" - Look up words in dictionaries")); +#ifdef ENABLE_NLS g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); +#endif /* ENABLE_NLS */ g_option_context_add_main_entries (context, gdict_app_goptions, GETTEXT_PACKAGE); g_option_context_add_group (context, gdict_get_option_group ()); g_option_context_add_group (context, gtk_get_option_group (TRUE)); @@ -360,6 +355,7 @@ gdict_init (int *argc, char ***argv) exit (1); } + g_option_context_free (context); g_set_application_name (_("Dictionary")); gtk_window_set_default_icon_name ("accessories-dictionary"); diff --git a/mate-dictionary/src/gdict-app.h b/mate-dictionary/src/gdict-app.h index b0a6ae2d..0602a0c3 100644 --- a/mate-dictionary/src/gdict-app.h +++ b/mate-dictionary/src/gdict-app.h @@ -1,23 +1,20 @@ -/* gdict-app.h - main application class +/* Copyright (C) 2005 Emmanuele Bassi + * Copyright (C) 2012-2021 MATE Developers * - * This file is part of MATE Dictionary + * This file is part of MATE Utils. * - * Copyright (C) 2005 Emmanuele Bassi + * MATE Utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, + * MATE Utils is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301, USA. + * along with MATE Utils. If not, see <https://www.gnu.org/licenses/>. */ #ifndef __GDICT_APP_H__ diff --git a/mate-dictionary/src/gdict-applet.c b/mate-dictionary/src/gdict-applet.c index 47da6d31..b635456a 100644 --- a/mate-dictionary/src/gdict-applet.c +++ b/mate-dictionary/src/gdict-applet.c @@ -1,24 +1,24 @@ -/* gdict-applet.c - MATE Dictionary Applet +/* Copyright (C) 2005 Emmanuele Bassi <[email protected]> + * Copyright (C) 2012-2021 MATE Developers * - * Copyright (c) 2005 Emmanuele Bassi <[email protected]> + * This file is part of MATE Utils. * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. + * MATE Utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, + * MATE Utils is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * along with MATE Utils. If not, see <https://www.gnu.org/licenses/>. */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include <config.h> #endif #include <stdio.h> @@ -38,6 +38,11 @@ #include "gdict-common.h" #include "gdict-aligned-window.h" +#if defined (ENABLE_WAYLAND) && defined (GDK_WINDOWING_WAYLAND) +#include <gdk/gdkwayland.h> +#include <gtk-layer-shell/gtk-layer-shell.h> +#endif + #define GDICT_APPLET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDICT_TYPE_APPLET, GdictAppletClass)) #define GDICT_APPLET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDICT_TYPE_APPLET, GdictAppletClass)) @@ -95,7 +100,6 @@ struct _GdictAppletPrivate G_DEFINE_TYPE_WITH_PRIVATE (GdictApplet, gdict_applet, PANEL_TYPE_APPLET); - static void set_atk_name_description (GtkWidget *widget, const char *name, @@ -133,7 +137,17 @@ set_window_default_size (GdictApplet *applet) font_size = pango_font_description_get_size (gtk_widget_get_style (defbox)->font_desc); font_size = PANGO_PIXELS (font_size); - width = font_size * WINDOW_NUM_COLUMNS; +#if defined (ENABLE_WAYLAND) && defined (GDK_WINDOWING_WAYLAND) + display = gtk_widget_get_display (widget); + if (GDK_IS_WAYLAND_DISPLAY (display)) + width = font_size * WINDOW_NUM_COLUMNS - 100; + + else +#endif + { + width = font_size * WINDOW_NUM_COLUMNS; + } + height = font_size * WINDOW_NUM_ROWS; /* Use at least the requisition size of the window... */ @@ -142,7 +156,6 @@ set_window_default_size (GdictApplet *applet) height = MAX (height, req.height); /* ... but make it no larger than half the monitor size */ - display = gtk_widget_get_display (widget); monitor_num = gdk_display_get_monitor_at_window (display, gtk_widget_get_window (widget)); gdk_monitor_get_geometry (monitor_num, &monitor); @@ -315,6 +328,15 @@ gdict_applet_build_window (GdictApplet *applet) G_CALLBACK (window_show_cb), applet); +#if defined (ENABLE_WAYLAND) && defined (GDK_WINDOWING_WAYLAND) + GdkDisplay *display = gdk_screen_get_display (gdk_screen_get_default()); + if ((GDK_IS_WAYLAND_DISPLAY (display)) && (!gtk_layer_is_layer_window (GTK_WINDOW (window)))) + { + gtk_layer_init_for_window (GTK_WINDOW (window)); + gtk_layer_set_layer (GTK_WINDOW (window), GTK_LAYER_SHELL_LAYER_TOP); + gtk_layer_set_keyboard_mode (GTK_WINDOW (window), GTK_LAYER_SHELL_KEYBOARD_MODE_ON_DEMAND); + } +#endif frame = gtk_frame_new (NULL); gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN); gtk_container_add (GTK_CONTAINER (window), frame); @@ -338,6 +360,14 @@ gdict_applet_build_window (GdictApplet *applet) bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL); gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END); gtk_box_set_spacing (GTK_BOX (bbox), 6); + +#if defined (ENABLE_WAYLAND) && defined (GDK_WINDOWING_WAYLAND) + if (GDK_IS_WAYLAND_DISPLAY (display)) + { + gtk_box_pack_start (GTK_BOX (bbox), priv->entry, TRUE, TRUE, 0); + gtk_button_box_set_child_non_homogeneous(GTK_BUTTON_BOX (bbox), priv->entry, TRUE); + } +#endif gtk_box_pack_end (GTK_BOX (vbox), bbox, FALSE, FALSE, 0); gtk_widget_show (bbox); @@ -386,6 +416,11 @@ gdict_applet_build_window (GdictApplet *applet) gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0); gtk_widget_show (button); +#if defined (ENABLE_WAYLAND) && defined (GDK_WINDOWING_WAYLAND) + if (GDK_IS_WAYLAND_DISPLAY (display)) + gtk_widget_show (priv->entry); +#endif + gtk_window_set_default (GTK_WINDOW (window), priv->defbox); priv->window = window; @@ -483,6 +518,11 @@ gdict_applet_icon_button_press_event_cb (GtkWidget *widget, if (event->button != 1) g_signal_stop_emission_by_name (priv->toggle, "button-press-event"); +#if defined (ENABLE_WAYLAND) && defined (GDK_WINDOWING_WAYLAND) + GdkDisplay *display = gdk_screen_get_display (gdk_screen_get_default()); + if ((GDK_IS_WAYLAND_DISPLAY (display)) && (GTK_IS_WIDGET (priv->window)) && (event->button == 1)) + gtk_widget_show_all (GTK_WIDGET (priv->window)); +#endif return FALSE; } @@ -571,13 +611,23 @@ gdict_applet_draw (GdictApplet *applet) /* entry */ priv->entry = gtk_entry_new (); +#if defined (ENABLE_WAYLAND) && defined (GDK_WINDOWING_WAYLAND) + GdkDisplay *display = gdk_screen_get_display (gdk_screen_get_default()); + if (GDK_IS_WAYLAND_DISPLAY (display)) + { + gtk_entry_set_icon_from_icon_name (GTK_ENTRY(priv->entry), GTK_ENTRY_ICON_PRIMARY, "gtk-edit"); + gtk_entry_set_icon_activatable (GTK_ENTRY(priv->entry), GTK_ENTRY_ICON_PRIMARY, FALSE); + /*Fill the available space since we must move the entry to the popup window for wayland*/ + } +#endif + gtk_entry_set_width_chars (GTK_ENTRY (priv->entry), 12); + gtk_widget_set_tooltip_text (priv->entry, _("Type the word you want to look up")); set_atk_name_description (priv->entry, _("Dictionary entry"), _("Look up words in dictionaries")); gtk_editable_set_editable (GTK_EDITABLE (priv->entry), TRUE); - gtk_entry_set_width_chars (GTK_ENTRY (priv->entry), 12); g_signal_connect (priv->entry, "activate", G_CALLBACK (gdict_applet_entry_activate_cb), applet); @@ -587,8 +637,19 @@ gdict_applet_draw (GdictApplet *applet) g_signal_connect (priv->entry, "key-press-event", G_CALLBACK (gdict_applet_entry_key_press_cb), applet); + +#if defined (ENABLE_WAYLAND) && defined (GDK_WINDOWING_WAYLAND) + if (GDK_IS_WAYLAND_DISPLAY (display)) + { + GtkStyleContext *context = gtk_widget_get_style_context (priv->entry); + gtk_style_context_add_class (context, "view"); + } + else +#endif + { gtk_box_pack_end (GTK_BOX (box), priv->entry, FALSE, FALSE, 0); gtk_widget_show (priv->entry); + } if (text) { @@ -1184,7 +1245,6 @@ gdict_applet_factory (MatePanelApplet *applet, gpointer data) { gboolean retval = FALSE; - gchar *ui_path; GdictApplet *dictionary_applet = GDICT_APPLET (applet); GdictAppletPrivate *priv = dictionary_applet->priv; @@ -1192,16 +1252,17 @@ gdict_applet_factory (MatePanelApplet *applet, { /* Set up the menu */ priv->context_menu_action_group = gtk_action_group_new ("Dictionary Applet Actions"); +#ifdef ENABLE_NLS gtk_action_group_set_translation_domain(priv->context_menu_action_group, GETTEXT_PACKAGE); +#endif /* ENABLE_NLS */ gtk_action_group_add_actions(priv->context_menu_action_group, gdict_applet_menu_actions, G_N_ELEMENTS (gdict_applet_menu_actions), applet); - ui_path = g_build_filename(PKGDATADIR, "dictionary-applet-menu.xml", NULL); - mate_panel_applet_setup_menu_from_file (applet, ui_path, + mate_panel_applet_setup_menu_from_file (applet, + PKGDATADIR "/dictionary-applet-menu.xml", priv->context_menu_action_group); - g_free (ui_path); gtk_widget_show (GTK_WIDGET (applet)); @@ -1215,9 +1276,9 @@ gdict_applet_factory (MatePanelApplet *applet, } /* this defines the main () for the applet */ -MATE_PANEL_APPLET_OUT_PROCESS_FACTORY ("DictionaryAppletFactory", - GDICT_TYPE_APPLET, - "mate-dictionary-applet", - gdict_applet_factory, - NULL); +PANEL_APPLET_FACTORY ("DictionaryAppletFactory", + GDICT_TYPE_APPLET, + "mate-dictionary-applet", + gdict_applet_factory, + NULL); diff --git a/mate-dictionary/src/gdict-applet.h b/mate-dictionary/src/gdict-applet.h index cf9396ed..e478d71c 100644 --- a/mate-dictionary/src/gdict-applet.h +++ b/mate-dictionary/src/gdict-applet.h @@ -1,20 +1,20 @@ -/* gdict-applet.h - MATE Dictionary Applet +/* Copyright (c) 2005 Emmanuele Bassi <[email protected]> + * Copyright (C) 2012-2021 MATE Developers * - * Copyright (c) 2005 Emmanuele Bassi <[email protected]> + * This file is part of MATE Utils. * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. + * MATE Utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, + * MATE Utils is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * along with MATE Utils. If not, see <https://www.gnu.org/licenses/>. */ #ifndef __GDICT_APPLET_H__ diff --git a/mate-dictionary/src/gdict-common.c b/mate-dictionary/src/gdict-common.c index 7c0b3063..5a78d95d 100644 --- a/mate-dictionary/src/gdict-common.c +++ b/mate-dictionary/src/gdict-common.c @@ -1,27 +1,24 @@ -/* gdict-common.h - shared code between application and applet +/* Copyright (C) 2005 Emmanuele Bassi + * Copyright (C) 2012-2021 MATE Developers * - * This file is part of MATE Dictionary + * This file is part of MATE Utils. * - * Copyright (C) 2005 Emmanuele Bassi + * MATE Utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, + * MATE Utils is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301, USA. + * along with MATE Utils. If not, see <https://www.gnu.org/licenses/>. */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include <config.h> #endif #include <stdio.h> diff --git a/mate-dictionary/src/gdict-common.h b/mate-dictionary/src/gdict-common.h index 800fc9d6..f42f5351 100644 --- a/mate-dictionary/src/gdict-common.h +++ b/mate-dictionary/src/gdict-common.h @@ -1,23 +1,20 @@ -/* gdict-common.h - shared code between application and applet +/* Copyright (C) 2005 Emmanuele Bassi + * Copyright (C) 2012-2021 MATE Developers * - * This file is part of MATE Dictionary + * This file is part of MATE Utils. * - * Copyright (C) 2005 Emmanuele Bassi + * MATE Utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, + * MATE Utils is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301, USA. + * along with MATE Utils. If not, see <https://www.gnu.org/licenses/>. */ #ifndef __GDICT_COMMON_H__ diff --git a/mate-dictionary/src/gdict-pref-dialog.c b/mate-dictionary/src/gdict-pref-dialog.c index 3afa876b..5552ebec 100644 --- a/mate-dictionary/src/gdict-pref-dialog.c +++ b/mate-dictionary/src/gdict-pref-dialog.c @@ -1,27 +1,24 @@ -/* gdict-pref-dialog.c - preferences dialog +/* Copyright (C) 2005 Emmanuele Bassi + * Copyright (C) 2012-2021 MATE Developers * - * This file is part of MATE Dictionary + * This file is part of MATE Utils. * - * Copyright (C) 2005 Emmanuele Bassi + * MATE Utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, + * MATE Utils is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301, USA. + * along with MATE Utils. If not, see <https://www.gnu.org/licenses/>. */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include <config.h> #endif #include <stdio.h> @@ -100,10 +97,8 @@ enum PROP_SOURCE_LOADER }; - G_DEFINE_TYPE (GdictPrefDialog, gdict_pref_dialog, GTK_TYPE_DIALOG); - static gboolean select_active_source_name (GtkTreeModel *model, GtkTreePath *path, diff --git a/mate-dictionary/src/gdict-pref-dialog.h b/mate-dictionary/src/gdict-pref-dialog.h index 1b25884d..8b6ca97d 100644 --- a/mate-dictionary/src/gdict-pref-dialog.h +++ b/mate-dictionary/src/gdict-pref-dialog.h @@ -1,23 +1,20 @@ -/* gdict-pref-dialog.h - preferences dialog +/* Copyright (C) 2005 Emmanuele Bassi + * Copyright (C) 2012-2021 MATE Developers * - * This file is part of MATE Dictionary + * This file is part of MATE Utils. * - * Copyright (C) 2005 Emmanuele Bassi + * MATE Utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, + * MATE Utils is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301, USA. + * along with MATE Utils. If not, see <https://www.gnu.org/licenses/>. */ #ifndef __GDICT_PREF_DIALOG_H__ diff --git a/mate-dictionary/src/gdict-print.c b/mate-dictionary/src/gdict-print.c index 559f98b7..58772968 100644 --- a/mate-dictionary/src/gdict-print.c +++ b/mate-dictionary/src/gdict-print.c @@ -1,27 +1,24 @@ -/* gdict-print.c - print-related helper functions +/* Copyright (C) 2005 Emmanuele Bassi + * Copyright (C) 2012-2021 MATE Developers * - * This file is part of MATE Dictionary + * This file is part of MATE Utils. * - * Copyright (C) 2005 Emmanuele Bassi + * MATE Utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, + * MATE Utils is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301, USA. + * along with MATE Utils. If not, see <https://www.gnu.org/licenses/>. */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include <config.h> #endif #include <stdio.h> diff --git a/mate-dictionary/src/gdict-print.h b/mate-dictionary/src/gdict-print.h index 1db61ded..d6a4c2f1 100644 --- a/mate-dictionary/src/gdict-print.h +++ b/mate-dictionary/src/gdict-print.h @@ -1,23 +1,20 @@ -/* gdict-print.h - print-related helper functions +/* Copyright (C) 2005 Emmanuele Bassi + * Copyright (C) 2012-2021 MATE Developers * - * This file is part of MATE Dictionary + * This file is part of MATE Utils. * - * Copyright (C) 2005 Emmanuele Bassi + * MATE Utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, + * MATE Utils is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301, USA. + * along with MATE Utils. If not, see <https://www.gnu.org/licenses/>. */ #ifndef __GDICT_PRINT_H__ diff --git a/mate-dictionary/src/gdict-sidebar.c b/mate-dictionary/src/gdict-sidebar.c index 1eacb15b..317f4cbf 100644 --- a/mate-dictionary/src/gdict-sidebar.c +++ b/mate-dictionary/src/gdict-sidebar.c @@ -1,28 +1,27 @@ -/* gdict-sidebar.c - sidebar widget +/* Copyright (C) 2006 Emmanuele Bassi <[email protected]> + * Copyright (C) 2012-2021 MATE Developers * - * Copyright (C) 2006 Emmanuele Bassi <[email protected]> + * Based on the equivalent widget from Evince by Jonathan Blandford. + * Copyright (C) 2004 Red Hat, Inc. * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. + * This file is part of MATE Utils. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * MATE Utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * MATE Utils is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * Based on the equivalent widget from Evince - * by Jonathan Blandford, - * Copyright (C) 2004 Red Hat, Inc. + * You should have received a copy of the GNU General Public License + * along with MATE Utils. If not, see <https://www.gnu.org/licenses/>. */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include <config.h> #endif #include <stdio.h> @@ -34,6 +33,8 @@ #include <gdk/gdkkeysyms.h> #include <glib/gi18n.h> +#include <libmate-desktop/mate-image-menu-item.h> + #include "gdict-sidebar.h" typedef struct @@ -73,7 +74,7 @@ static GQuark sidebar_page_id_quark = 0; G_DEFINE_TYPE_WITH_PRIVATE (GdictSidebar, gdict_sidebar, GTK_TYPE_BOX); -SidebarPage * +static SidebarPage * sidebar_page_new (const gchar *id, const gchar *name, GtkWidget *widget) @@ -91,7 +92,7 @@ sidebar_page_new (const gchar *id, return page; } -void +static void sidebar_page_free (SidebarPage *page) { if (G_LIKELY (page)) @@ -410,7 +411,7 @@ gdict_sidebar_add_page (GdictSidebar *sidebar, NULL); /* add the menu item for the page */ - menu_item = gtk_image_menu_item_new_with_label (page_name); + menu_item = mate_image_menu_item_new_with_label (page_name); g_object_set_qdata_full (G_OBJECT (menu_item), sidebar_page_id_quark, g_strdup (page_id), diff --git a/mate-dictionary/src/gdict-sidebar.h b/mate-dictionary/src/gdict-sidebar.h index 4d9b0512..66b733c6 100644 --- a/mate-dictionary/src/gdict-sidebar.h +++ b/mate-dictionary/src/gdict-sidebar.h @@ -1,24 +1,23 @@ -/* gdict-sidebar.h - sidebar widget +/* Copyright (C) 2006 Emmanuele Bassi <[email protected]> + * Copyright (C) 2012-2021 MATE Developers * - * Copyright (C) 2006 Emmanuele Bassi <[email protected]> + * Based on the equivalent widget from Evince by Jonathan Blandford. + * Copyright (C) 2004 Red Hat, Inc. * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. + * This file is part of MATE Utils. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * MATE Utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * MATE Utils is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * Based on the equivalent widget from Evince - * by Jonathan Blandford, - * Copyright (C) 2004 Red Hat, Inc. + * You should have received a copy of the GNU General Public License + * along with MATE Utils. If not, see <https://www.gnu.org/licenses/>. */ #ifndef __GDICT_SIDEBAR_H__ diff --git a/mate-dictionary/src/gdict-source-dialog.c b/mate-dictionary/src/gdict-source-dialog.c index 9807afba..d8fefb64 100644 --- a/mate-dictionary/src/gdict-source-dialog.c +++ b/mate-dictionary/src/gdict-source-dialog.c @@ -1,27 +1,24 @@ -/* gdict-source-dialog.c - source dialog +/* Copyright (C) 2005 Emmanuele Bassi + * Copyright (C) 2012-2021 MATE Developers * - * This file is part of MATE Dictionary + * This file is part of MATE Utils. * - * Copyright (C) 2005 Emmanuele Bassi + * MATE Utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, + * MATE Utils is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301, USA. + * along with MATE Utils. If not, see <https://www.gnu.org/licenses/>. */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include <config.h> #endif #include <stdio.h> @@ -404,7 +401,6 @@ save_source (GdictSourceDialog *dialog) gdict_source_set_strategy (source, text); g_free (text); - /* get the selected transport id */ transport = dialog->transport; switch (transport) diff --git a/mate-dictionary/src/gdict-source-dialog.h b/mate-dictionary/src/gdict-source-dialog.h index 31ec8efb..70a0d023 100644 --- a/mate-dictionary/src/gdict-source-dialog.h +++ b/mate-dictionary/src/gdict-source-dialog.h @@ -1,23 +1,20 @@ -/* gdict-source-dialog.h - source dialog +/* Copyright (C) 2005 Emmanuele Bassi + * Copyright (C) 2012-2021 MATE Developers * - * This file is part of MATE Dictionary + * This file is part of MATE Utils. * - * Copyright (C) 2005 Emmanuele Bassi + * MATE Utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, + * MATE Utils is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301, USA. + * along with MATE Utils. If not, see <https://www.gnu.org/licenses/>. */ #ifndef __GDICT_SOURCE_DIALOG_H__ diff --git a/mate-dictionary/src/gdict-window.c b/mate-dictionary/src/gdict-window.c index 5eb92c20..7d6a6bb2 100644 --- a/mate-dictionary/src/gdict-window.c +++ b/mate-dictionary/src/gdict-window.c @@ -1,27 +1,24 @@ -/* gdict-window.c - main application window +/* Copyright (C) 2005 Emmanuele Bassi + * Copyright (C) 2012-2021 MATE Developers * - * This file is part of MATE Dictionary + * This file is part of MATE Utils. * - * Copyright (C) 2005 Emmanuele Bassi + * MATE Utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, + * MATE Utils is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301, USA. + * along with MATE Utils. If not, see <https://www.gnu.org/licenses/>. */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include <config.h> #endif #include <stdio.h> @@ -99,11 +96,8 @@ static const GtkTargetEntry drop_types[] = }; static const guint n_drop_types = G_N_ELEMENTS (drop_types); - - G_DEFINE_TYPE (GdictWindow, gdict_window, GTK_TYPE_WINDOW); - static void gdict_window_finalize (GObject *gobject) { @@ -133,7 +127,6 @@ gdict_window_dispose (GObject *gobject) if (window->settings != NULL) { g_object_unref (window->settings); - window->settings = NULL; } @@ -192,14 +185,16 @@ gdict_window_dispose (GObject *gobject) window->busy_cursor = NULL; } + g_clear_pointer (&window->sidebar_page, g_free); + G_OBJECT_CLASS (gdict_window_parent_class)->dispose (gobject); } static const gchar *toggle_state[] = { - "/MainMenu/FileMenu/SaveAsMenu", - "/MainMenu/FileMenu/FilePreviewMenu", - "/MainMenu/FileMenu/FilePrintMenu", - "/MainMenu/GoMenu", + "save_as_item", + "preview_item", + "print_item", + "go_menu", }; static gint n_toggle_state = G_N_ELEMENTS (toggle_state); @@ -220,7 +215,7 @@ gdict_window_ensure_menu_state (GdictWindow *window) { GtkWidget *item; - item = gtk_ui_manager_get_widget (window->ui_manager, toggle_state[i]); + item = (GtkWidget *)gtk_builder_get_object (window->ui_manager, toggle_state[i]); if (!item) continue; @@ -238,17 +233,17 @@ gdict_window_set_sidebar_visible (GdictWindow *window, if (is_visible != window->sidebar_visible) { - GtkAction *action; + GAction *action; - window->sidebar_visible = is_visible; + window->sidebar_visible = (is_visible != FALSE); if (window->sidebar_visible) gtk_widget_show (window->sidebar_frame); else gtk_widget_hide (window->sidebar_frame); - action = gtk_action_group_get_action (window->action_group, "ViewSidebar"); - gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), window->sidebar_visible); + action = g_action_map_lookup_action (G_ACTION_MAP (window->action_group), "ViewSidebar"); + g_simple_action_set_state (G_SIMPLE_ACTION (action), g_variant_new_boolean (window->sidebar_visible)); } } @@ -861,21 +856,21 @@ gdict_window_load_state (GdictWindow *window) window->default_height = -1; } - window->is_maximized = g_key_file_get_boolean (state_key, "WindowState", "IsMaximized", &error); + window->is_maximized = (g_key_file_get_boolean (state_key, "WindowState", "IsMaximized", &error) != FALSE); if (error != NULL) { g_clear_error (&error); window->is_maximized = FALSE; } - window->sidebar_visible = g_key_file_get_boolean (state_key, "WindowState", "SidebarVisible", &error); + window->sidebar_visible = (g_key_file_get_boolean (state_key, "WindowState", "SidebarVisible", &error) != FALSE); if (error != NULL) { g_clear_error (&error); window->sidebar_visible = FALSE; } - window->statusbar_visible = g_key_file_get_boolean (state_key, "WindowState", "StatusbarVisible", &error); + window->statusbar_visible = (g_key_file_get_boolean (state_key, "WindowState", "StatusbarVisible", &error) != FALSE); if (error != NULL) { g_clear_error (&error); @@ -901,9 +896,11 @@ gdict_window_load_state (GdictWindow *window) } static void -gdict_window_cmd_file_new (GtkAction *action, - GdictWindow *window) +gdict_window_cmd_file_new (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { + GdictWindow *window = user_data; GtkWidget *new_window; gchar *word = NULL; @@ -928,9 +925,11 @@ gdict_window_cmd_file_new (GtkAction *action, } static void -gdict_window_cmd_save_as (GtkAction *action, - GdictWindow *window) +gdict_window_cmd_save_as (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { + GdictWindow *window = user_data; GtkWidget *dialog; g_assert (GDICT_IS_WINDOW (window)); @@ -983,9 +982,11 @@ gdict_window_cmd_save_as (GtkAction *action, } static void -gdict_window_cmd_file_preview (GtkAction *action, - GdictWindow *window) +gdict_window_cmd_file_preview (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { + GdictWindow *window = user_data; g_assert (GDICT_IS_WINDOW (window)); gdict_show_print_preview (GTK_WINDOW (window), @@ -993,9 +994,11 @@ gdict_window_cmd_file_preview (GtkAction *action, } static void -gdict_window_cmd_file_print (GtkAction *action, - GdictWindow *window) +gdict_window_cmd_file_print (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { + GdictWindow *window = user_data; g_assert (GDICT_IS_WINDOW (window)); gdict_show_print_dialog (GTK_WINDOW (window), @@ -1003,9 +1006,11 @@ gdict_window_cmd_file_print (GtkAction *action, } static void -gdict_window_cmd_file_close_window (GtkAction *action, - GdictWindow *window) +gdict_window_cmd_file_close_window (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { + GdictWindow *window = user_data; g_assert (GDICT_IS_WINDOW (window)); gdict_window_store_state (window); @@ -1019,9 +1024,11 @@ gdict_window_cmd_file_close_window (GtkAction *action, } static void -gdict_window_cmd_edit_copy (GtkAction *action, - GdictWindow *window) +gdict_window_cmd_edit_copy (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { + GdictWindow *window = user_data; g_assert (GDICT_IS_WINDOW (window)); if (gtk_widget_has_focus (window->entry)) @@ -1032,9 +1039,11 @@ gdict_window_cmd_edit_copy (GtkAction *action, } static void -gdict_window_cmd_edit_select_all (GtkAction *action, - GdictWindow *window) +gdict_window_cmd_edit_select_all (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { + GdictWindow *window = user_data; g_assert (GDICT_IS_WINDOW (window)); if (gtk_widget_has_focus (window->entry)) @@ -1044,36 +1053,43 @@ gdict_window_cmd_edit_select_all (GtkAction *action, } static void -gdict_window_cmd_edit_find (GtkAction *action, - GdictWindow *window) +gdict_window_cmd_edit_find (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { + GdictWindow *window = user_data; g_assert (GDICT_IS_WINDOW (window)); - gdict_defbox_set_show_find (GDICT_DEFBOX (window->defbox), TRUE); } static void -gdict_window_cmd_edit_find_next (GtkAction *action, - GdictWindow *window) +gdict_window_cmd_edit_find_next (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { + GdictWindow *window = user_data; g_assert (GDICT_IS_WINDOW (window)); gdict_defbox_find_next (GDICT_DEFBOX (window->defbox)); } static void -gdict_window_cmd_edit_find_previous (GtkAction *action, - GdictWindow *window) +gdict_window_cmd_edit_find_previous (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { + GdictWindow *window = user_data; g_assert (GDICT_IS_WINDOW (window)); gdict_defbox_find_previous (GDICT_DEFBOX (window->defbox)); } static void -gdict_window_cmd_edit_preferences (GtkAction *action, - GdictWindow *window) +gdict_window_cmd_edit_preferences (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { + GdictWindow *window = user_data; g_assert (GDICT_IS_WINDOW (window)); gdict_show_pref_dialog (GTK_WIDGET (window), @@ -1082,12 +1098,40 @@ gdict_window_cmd_edit_preferences (GtkAction *action, } static void -gdict_window_cmd_view_sidebar (GtkToggleAction *action, - GdictWindow *window) +sidebar_activate_toggle (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { + GVariant *state; + + state = g_action_get_state (G_ACTION (action)); + g_action_change_state (G_ACTION (action), g_variant_new_boolean (!g_variant_get_boolean (state))); + g_variant_unref (state); +} + +static void +statusbar_activate_toggle (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + GVariant *state; + + state = g_action_get_state (G_ACTION (action)); + g_action_change_state (G_ACTION (action), g_variant_new_boolean (!g_variant_get_boolean (state))); + g_variant_unref (state); +} + +static void +gdict_window_cmd_view_sidebar (GSimpleAction *action, + GVariant *state, + gpointer user_data) +{ + GdictWindow *window = user_data; g_assert (GDICT_IS_WINDOW (window)); - window->sidebar_visible = gtk_toggle_action_get_active (action); + g_variant_get_boolean (state); + window->sidebar_visible = (g_variant_get_boolean (state) != FALSE); + g_simple_action_set_state (action, state); if (window->sidebar_visible) gtk_widget_show (window->sidebar_frame); @@ -1096,12 +1140,15 @@ gdict_window_cmd_view_sidebar (GtkToggleAction *action, } static void -gdict_window_cmd_view_statusbar (GtkToggleAction *action, - GdictWindow *window) +gdict_window_cmd_view_statusbar (GSimpleAction *action, + GVariant *state, + gpointer user_data) { + GdictWindow *window = user_data; g_assert (GDICT_IS_WINDOW (window)); - window->statusbar_visible = gtk_toggle_action_get_active (action); + window->statusbar_visible = (g_variant_get_boolean (state) != FALSE); + g_simple_action_set_state (action, state); if (window->statusbar_visible) gtk_widget_show (window->status); @@ -1111,9 +1158,12 @@ gdict_window_cmd_view_statusbar (GtkToggleAction *action, } static void -gdict_window_cmd_view_speller (GtkAction *action, - GdictWindow *window) +gdict_window_cmd_view_speller (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) + { + GdictWindow *window = user_data; g_assert (GDICT_IS_WINDOW (window)); gdict_sidebar_view_page (GDICT_SIDEBAR (window->sidebar), @@ -1122,9 +1172,12 @@ gdict_window_cmd_view_speller (GtkAction *action, } static void -gdict_window_cmd_view_databases (GtkAction *action, - GdictWindow *window) +gdict_window_cmd_view_databases (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) + { + GdictWindow *window = user_data; g_assert (GDICT_IS_WINDOW (window)); gdict_sidebar_view_page (GDICT_SIDEBAR (window->sidebar), @@ -1133,9 +1186,12 @@ gdict_window_cmd_view_databases (GtkAction *action, } static void -gdict_window_cmd_view_strategies (GtkAction *action, - GdictWindow *window) +gdict_window_cmd_view_strategies (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) + { + GdictWindow *window = user_data; g_assert (GDICT_IS_WINDOW (window)); gdict_sidebar_view_page (GDICT_SIDEBAR (window->sidebar), @@ -1144,9 +1200,12 @@ gdict_window_cmd_view_strategies (GtkAction *action, } static void -gdict_window_cmd_view_sources (GtkAction *action, - GdictWindow *window) +gdict_window_cmd_view_sources (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) + { + GdictWindow *window = user_data; g_assert (GDICT_IS_WINDOW (window)); gdict_sidebar_view_page (GDICT_SIDEBAR (window->sidebar), @@ -1155,9 +1214,11 @@ gdict_window_cmd_view_sources (GtkAction *action, } static void -gdict_window_cmd_go_first_def (GtkAction *action, - GdictWindow *window) +gdict_window_cmd_go_first_def (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { + GdictWindow *window = user_data; g_assert (GDICT_IS_WINDOW (window)); window->last_definition = 0; @@ -1166,9 +1227,11 @@ gdict_window_cmd_go_first_def (GtkAction *action, } static void -gdict_window_cmd_go_previous_def (GtkAction *action, - GdictWindow *window) +gdict_window_cmd_go_previous_def (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { + GdictWindow *window = user_data; g_assert (GDICT_IS_WINDOW (window)); if (window->last_definition == 0) @@ -1180,9 +1243,11 @@ gdict_window_cmd_go_previous_def (GtkAction *action, } static void -gdict_window_cmd_go_next_def (GtkAction *action, - GdictWindow *window) +gdict_window_cmd_go_next_def (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { + GdictWindow *window = user_data; g_assert (GDICT_IS_WINDOW (window)); if (window->max_definition == -1) @@ -1197,9 +1262,11 @@ gdict_window_cmd_go_next_def (GtkAction *action, } static void -gdict_window_cmd_go_last_def (GtkAction *action, - GdictWindow *window) +gdict_window_cmd_go_last_def (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) { + GdictWindow *window = user_data; g_assert (GDICT_IS_WINDOW (window)); if (window->max_definition == -1) @@ -1211,9 +1278,12 @@ gdict_window_cmd_go_last_def (GtkAction *action, } static void -gdict_window_cmd_help_contents (GtkAction *action, - GdictWindow *window) +gdict_window_cmd_help_contents (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) + { + GdictWindow *window = user_data; GError *err = NULL; g_return_if_fail (GDICT_IS_WINDOW (window)); @@ -1230,105 +1300,106 @@ gdict_window_cmd_help_contents (GtkAction *action, } static void -gdict_window_cmd_help_about (GtkAction *action, - GdictWindow *window) +gdict_window_cmd_help_about (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) + { + GdictWindow *window = user_data; g_assert (GDICT_IS_WINDOW (window)); gdict_show_about_dialog (GTK_WIDGET (window)); } static void -gdict_window_cmd_lookup (GtkAction *action, - GdictWindow *window) +gdict_window_cmd_lookup (gpointer user_data) + { + GdictWindow *window = user_data; g_assert (GDICT_IS_WINDOW (window)); gtk_widget_grab_focus (window->entry); } static void -gdict_window_cmd_escape (GtkAction *action, - GdictWindow *window) +gdict_window_cmd_escape (gpointer user_data) + { + GdictWindow *window = user_data; g_assert (GDICT_IS_WINDOW (window)); gdict_defbox_set_show_find (GDICT_DEFBOX (window->defbox), FALSE); } -static const GtkActionEntry entries[] = +static void +gdict_window_cmd_slash (gpointer user_data) { - { "File", NULL, N_("_File"), NULL, NULL, NULL }, - { "Edit", NULL, N_("_Edit"), NULL, NULL, NULL }, - { "View", NULL, N_("_View"), NULL, NULL, NULL }, - { "Go", NULL, N_("_Go"), NULL, NULL, NULL }, - { "Help", NULL, N_("_Help"), NULL, NULL, NULL }, + GdictWindow *window = user_data; + g_assert (GDICT_IS_WINDOW (window)); + + gdict_defbox_set_show_find (GDICT_DEFBOX (window->defbox), TRUE); +} +static const GActionEntry entries[] = +{ /* File menu */ - { "FileNew", "document-new", N_("_New"), "<control>N", - N_("New look up"), G_CALLBACK (gdict_window_cmd_file_new) }, - { "FileSaveAs", "document-save-as", N_("_Save a Copy..."), NULL, NULL, - G_CALLBACK (gdict_window_cmd_save_as) }, - { "FilePreview", NULL, N_("P_review..."), "<control><shift>P", - N_("Preview this document"), G_CALLBACK (gdict_window_cmd_file_preview) }, - { "FilePrint", "document-print", N_("_Print..."), "<control>P", - N_("Print this document"), G_CALLBACK (gdict_window_cmd_file_print) }, - { "FileCloseWindow", "window-close", N_("_Close"), "<control>W", NULL, - G_CALLBACK (gdict_window_cmd_file_close_window) }, + { "FileNew", gdict_window_cmd_file_new, NULL, NULL, NULL }, + { "FileSaveAs", gdict_window_cmd_save_as, NULL, NULL, NULL }, + { "FilePreview", gdict_window_cmd_file_preview, NULL, NULL, NULL }, + { "FilePrint", gdict_window_cmd_file_print, NULL, NULL, NULL }, + { "FileCloseWindow", gdict_window_cmd_file_close_window, NULL, NULL, NULL }, /* Edit menu */ - { "EditCopy", "edit-copy", N_("_Copy"), "<control>C", NULL, - G_CALLBACK (gdict_window_cmd_edit_copy) }, - { "EditSelectAll", NULL, N_("Select _All"), "<control>A", NULL, - G_CALLBACK (gdict_window_cmd_edit_select_all) }, - { "EditFind", "edit-find", N_("_Find"), "<control>F", - N_("Find a word or phrase in the document"), - G_CALLBACK (gdict_window_cmd_edit_find) }, - { "EditFindNext", NULL, N_("Find Ne_xt"), "<control>G", NULL, - G_CALLBACK (gdict_window_cmd_edit_find_next) }, - { "EditFindPrevious", NULL, N_("Find Pre_vious"), "<control><shift>G", NULL, - G_CALLBACK (gdict_window_cmd_edit_find_previous) }, - { "EditPreferences", "preferences-desktop", N_("_Preferences"), NULL, NULL, - G_CALLBACK (gdict_window_cmd_edit_preferences) }, + { "EditCopy", gdict_window_cmd_edit_copy, NULL, NULL, NULL }, + { "EditSelectAll", gdict_window_cmd_edit_select_all, NULL, NULL, NULL }, + { "EditFind", gdict_window_cmd_edit_find, NULL, NULL, NULL }, + { "EditFindNext", gdict_window_cmd_edit_find_next, NULL, NULL, NULL }, + { "EditFindPrevious", gdict_window_cmd_edit_find_previous, NULL, NULL, NULL }, + { "EditPreferences", gdict_window_cmd_edit_preferences, NULL, NULL, NULL }, /* Go menu */ - { "GoPreviousDef", "go-previous", N_("_Previous Definition"), "<control>Page_Up", - N_("Go to the previous definition"), G_CALLBACK (gdict_window_cmd_go_previous_def) }, - { "GoNextDef", "go-next", N_("_Next Definition"), "<control>Page_Down", - N_("Go to the next definition"), G_CALLBACK (gdict_window_cmd_go_next_def) }, - { "GoFirstDef", "go-first", N_("_First Definition"), "<control>Home", - N_("Go to the first definition"), G_CALLBACK (gdict_window_cmd_go_first_def) }, - { "GoLastDef", "go-last", N_("_Last Definition"), "<control>End", - N_("Go to the last definition"), G_CALLBACK (gdict_window_cmd_go_last_def) }, + { "GoPreviousDef", gdict_window_cmd_go_previous_def, NULL, NULL, NULL }, + { "GoNextDef", gdict_window_cmd_go_next_def, NULL, NULL, NULL }, + { "GoFirstDef", gdict_window_cmd_go_first_def, NULL, NULL, NULL }, + { "GoLastDef", gdict_window_cmd_go_last_def, NULL, NULL, NULL }, /* View menu */ - { "ViewSpeller", NULL, N_("Similar _Words"), "<control>T", NULL, - G_CALLBACK (gdict_window_cmd_view_speller), }, - { "ViewSource", NULL, N_("Dictionary Sources"), "<control>D", NULL, - G_CALLBACK (gdict_window_cmd_view_sources), }, - { "ViewDB", NULL, N_("Available _Databases"), "<control>B", NULL, - G_CALLBACK (gdict_window_cmd_view_databases), }, - { "ViewStrat", NULL, N_("Available St_rategies"), "<control>R", NULL, - G_CALLBACK (gdict_window_cmd_view_strategies), }, + { "ViewSidebar", sidebar_activate_toggle, NULL, "false", gdict_window_cmd_view_sidebar }, + { "ViewStatusbar", statusbar_activate_toggle, NULL, "false", gdict_window_cmd_view_statusbar }, + { "ViewSpeller", gdict_window_cmd_view_speller, NULL, NULL, NULL }, + { "ViewSource", gdict_window_cmd_view_sources, NULL, NULL, NULL }, + { "ViewDB", gdict_window_cmd_view_databases, NULL, NULL, NULL }, + { "ViewStrat", gdict_window_cmd_view_strategies, NULL, NULL, NULL }, /* Help menu */ - { "HelpContents", "help-browser", N_("_Contents"), "F1", NULL, - G_CALLBACK (gdict_window_cmd_help_contents) }, - { "HelpAbout", "help-about", N_("_About"), NULL, NULL, - G_CALLBACK (gdict_window_cmd_help_about) }, - - /* Accelerators */ - { "Lookup", NULL, "", "<control>L", NULL, G_CALLBACK (gdict_window_cmd_lookup) }, - { "Escape", NULL, "", "Escape", "", G_CALLBACK (gdict_window_cmd_escape) }, - { "Slash", "edit-find", NULL, "slash", NULL, G_CALLBACK (gdict_window_cmd_edit_find) }, + { "HelpContents", gdict_window_cmd_help_contents, NULL, NULL, NULL }, + { "HelpAbout", gdict_window_cmd_help_about, NULL, NULL, NULL }, }; -static const GtkToggleActionEntry toggle_entries[] = { - /* View menu */ - { "ViewSidebar", NULL, N_("_Sidebar"), "F9", NULL, - G_CALLBACK (gdict_window_cmd_view_sidebar), FALSE }, - { "ViewStatusbar", NULL, N_("S_tatusbar"), NULL, NULL, - G_CALLBACK (gdict_window_cmd_view_statusbar), FALSE }, +static const struct { + guint keyval; + GdkModifierType modifier; + const gchar *widget_id; +} menu_keybindings [] = { + { GDK_KEY_N, GDK_CONTROL_MASK, "new_item" }, + { GDK_KEY_S, GDK_SHIFT_MASK | GDK_CONTROL_MASK, "preview_item" }, + { GDK_KEY_P, GDK_CONTROL_MASK, "print_item" }, + { GDK_KEY_W, GDK_CONTROL_MASK, "close_item" }, + { GDK_KEY_C, GDK_CONTROL_MASK, "copy_item" }, + { GDK_KEY_A, GDK_CONTROL_MASK, "select_item" }, + { GDK_KEY_F, GDK_CONTROL_MASK, "find_item" }, + { GDK_KEY_G, GDK_CONTROL_MASK, "find_next_item" }, + { GDK_KEY_G, GDK_SHIFT_MASK | GDK_CONTROL_MASK, "find_previous_item" }, + { GDK_KEY_Page_Up, GDK_CONTROL_MASK, "go_up_item" }, + { GDK_KEY_Page_Down, GDK_CONTROL_MASK, "go_down_item" }, + { GDK_KEY_Home, GDK_CONTROL_MASK, "go_home_item" }, + { GDK_KEY_End, GDK_CONTROL_MASK, "go_end_item" }, + { GDK_KEY_F9, 0, "side_item" }, + { GDK_KEY_T, GDK_CONTROL_MASK, "speller_item" }, + { GDK_KEY_D, GDK_CONTROL_MASK, "sources_item" }, + { GDK_KEY_B, GDK_CONTROL_MASK, "db_item" }, + { GDK_KEY_R, GDK_CONTROL_MASK, "strategies_item" }, + { GDK_KEY_F1, 0, "help_item" } }; static gboolean @@ -1336,7 +1407,7 @@ gdict_window_delete_event_cb (GtkWidget *widget, GdkEvent *event, gpointer user_data) { - gdict_window_cmd_file_close_window (NULL, GDICT_WINDOW (widget)); + gdict_window_cmd_file_close_window (NULL, NULL, GDICT_WINDOW (widget)); return FALSE; } @@ -1607,12 +1678,15 @@ gdict_window_constructor (GType type, GtkWidget *frame1, *frame2; GtkWidget *vbox; GtkWidget *button; - GtkActionGroup *action_group; + GtkWidget *item; + GActionGroup *action_group; GtkAccelGroup *accel_group; PangoFontDescription *font_desc; gchar *font_name; GError *error; GtkAllocation allocation; + GClosure *lookup, *escape, *slash; + int i; object = G_OBJECT_CLASS (gdict_window_parent_class)->constructor (type, n_construct_properties, construct_params); window = GDICT_WINDOW (object); @@ -1627,24 +1701,20 @@ gdict_window_constructor (GType type, gtk_widget_show (window->main_box); /* build menus */ - action_group = gtk_action_group_new ("MenuActions"); + action_group = (GActionGroup*)g_simple_action_group_new (); window->action_group = action_group; - gtk_action_group_set_translation_domain (action_group, NULL); - gtk_action_group_add_actions (action_group, entries, - G_N_ELEMENTS (entries), - window); - gtk_action_group_add_toggle_actions (action_group, toggle_entries, - G_N_ELEMENTS (toggle_entries), - window); - - window->ui_manager = gtk_ui_manager_new (); - gtk_ui_manager_insert_action_group (window->ui_manager, action_group, 0); - - accel_group = gtk_ui_manager_get_accel_group (window->ui_manager); + g_action_map_add_action_entries (G_ACTION_MAP (action_group), + entries, G_N_ELEMENTS (entries), + window); + + window->ui_manager = gtk_builder_new (); + gtk_widget_insert_action_group (GTK_WIDGET (window), "win", action_group); + + accel_group = gtk_accel_group_new (); gtk_window_add_accel_group (GTK_WINDOW (window), accel_group); error = NULL; - if (!gtk_ui_manager_add_ui_from_file (window->ui_manager, + if (!gtk_builder_add_from_file (window->ui_manager, PKGDATADIR "/mate-dictionary-ui.xml", &error)) { @@ -1653,7 +1723,7 @@ gdict_window_constructor (GType type, } else { - window->menubar = gtk_ui_manager_get_widget (window->ui_manager, "/MainMenu"); + window->menubar = (GtkWidget *)gtk_builder_get_object (window->ui_manager, "dictionarymenubar"); gtk_box_pack_start (GTK_BOX (window->main_box), window->menubar, FALSE, FALSE, 0); gtk_widget_show (window->menubar); @@ -1661,6 +1731,23 @@ gdict_window_constructor (GType type, gdict_window_ensure_menu_state (window); } + for (i = 0; i < G_N_ELEMENTS (menu_keybindings); i++) + { + item = (GtkWidget*)gtk_builder_get_object (window->ui_manager, menu_keybindings[i].widget_id); + gtk_widget_add_accelerator (item, "activate", accel_group, + menu_keybindings[i].keyval, + menu_keybindings[i].modifier, + GTK_ACCEL_VISIBLE); + } + lookup = g_cclosure_new_swap (G_CALLBACK (gdict_window_cmd_lookup), window, NULL); + gtk_accel_group_connect (accel_group, GDK_KEY_L, GDK_CONTROL_MASK, 0, lookup); + + escape = g_cclosure_new_swap (G_CALLBACK (gdict_window_cmd_escape), window, NULL); + gtk_accel_group_connect (accel_group, GDK_KEY_Escape, 0, 0, escape); + + slash = g_cclosure_new_swap (G_CALLBACK (gdict_window_cmd_slash), window, NULL); + gtk_accel_group_connect (accel_group, GDK_KEY_slash, 0, 0, slash); + vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); gtk_container_set_border_width (GTK_CONTAINER (vbox), 6); gtk_container_add (GTK_CONTAINER (window->main_box), vbox); @@ -1813,10 +1900,10 @@ gdict_window_constructor (GType type, if (window->sidebar_visible) { - GtkAction *action; + GAction *action; - action = gtk_action_group_get_action (window->action_group, "ViewSidebar"); - gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE); + action = g_action_map_lookup_action (G_ACTION_MAP (window->action_group), "ViewSidebar"); + g_simple_action_set_state (G_SIMPLE_ACTION (action), g_variant_new_boolean (TRUE)); gtk_widget_show (window->sidebar_frame); } @@ -1824,10 +1911,10 @@ gdict_window_constructor (GType type, gtk_box_pack_end (GTK_BOX (window->main_box), window->status, FALSE, FALSE, 0); if (window->statusbar_visible) { - GtkAction *action; + GAction *action; - action = gtk_action_group_get_action (window->action_group, "ViewStatusbar"); - gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE); + action = g_action_map_lookup_action (G_ACTION_MAP (window->action_group), "ViewStatusbar"); + g_simple_action_set_state (G_SIMPLE_ACTION (action), g_variant_new_boolean (TRUE)); gtk_widget_show (window->status); } @@ -2040,10 +2127,10 @@ gdict_window_new (GdictWindowAction action, g_return_val_if_fail (GDICT_IS_SOURCE_LOADER (loader), NULL); retval = g_object_new (GDICT_TYPE_WINDOW, - "action", action, + "action", action, "source-loader", loader, - "source-name", source_name, - NULL); + "source-name", source_name, + NULL); window = GDICT_WINDOW (retval); diff --git a/mate-dictionary/src/gdict-window.h b/mate-dictionary/src/gdict-window.h index 02a2ee7a..0fd8e3fc 100644 --- a/mate-dictionary/src/gdict-window.h +++ b/mate-dictionary/src/gdict-window.h @@ -1,23 +1,20 @@ -/* gdict-window.h - main application window +/* Copyright (C) 2005 Emmanuele Bassi + * Copyright (C) 2012-2021 MATE Developers * - * This file is part of MATE Dictionary + * This file is part of MATE Utils. * - * Copyright (C) 2005 Emmanuele Bassi + * MATE Utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, + * MATE Utils is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301, USA. + * along with MATE Utils. If not, see <https://www.gnu.org/licenses/>. */ #ifndef __GDICT_WINDOW_H__ @@ -69,8 +66,8 @@ struct _GdictWindow GtkWidget *status; GtkWidget *progress; - GtkUIManager *ui_manager; - GtkActionGroup *action_group; + GtkBuilder *ui_manager; + GActionGroup *action_group; GtkEntryCompletion *completion; GtkListStore *completion_model; diff --git a/mate-dictionary/src/main.c b/mate-dictionary/src/main.c index a89a5754..d0ab7c65 100644 --- a/mate-dictionary/src/main.c +++ b/mate-dictionary/src/main.c @@ -1,5 +1,22 @@ +/* This file is part of MATE Utils. + * Copyright (C) 2012-2021 MATE Developers + * + * MATE Utils is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * MATE Utils is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with MATE Utils. If not, see <https://www.gnu.org/licenses/>. + */ + #ifdef HAVE_CONFIG_H -#include "config.h" +#include <config.h> #endif #include <stdio.h> @@ -10,9 +27,11 @@ int main (int argc, char *argv[]) { +#ifdef ENABLE_NLS bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); +#endif /* ENABLE_NLS */ gdict_init (&argc, &argv); |