From b9ae4c57de95a7d73640cce5776540d8d841b0c2 Mon Sep 17 00:00:00 2001 From: Nobuhiro Iwamatsu Date: Fri, 6 May 2022 16:16:30 +0900 Subject: [PATCH] renderer: Convert Gtk2 to Gtk3 Description: renderer: Convert Gtk2 to Gtk3 Forwarded: Not need Last-Update: 2022-05-07 Signed-off-by: Nobuhiro Iwamatsu --- src/renderer/mozc_renderer_main.cc | 2 +- src/renderer/renderer.gyp | 7 +++---- src/renderer/unix/candidate_window.cc | 4 ++-- src/renderer/unix/gtk_wrapper.cc | 4 ++-- src/renderer/unix/infolist_window.cc | 4 ++-- src/renderer/unix/pango_wrapper.cc | 15 +++------------ src/renderer/unix/pango_wrapper.h | 3 +-- src/renderer/unix/text_renderer.cc | 5 ++--- src/renderer/unix/text_renderer.h | 3 +-- src/renderer/unix/text_renderer_interface.h | 2 +- 10 files changed, 18 insertions(+), 31 deletions(-) diff --git a/src/renderer/mozc_renderer_main.cc b/src/renderer/mozc_renderer_main.cc index 85a0ae10..3b596d67 100644 --- a/src/renderer/mozc_renderer_main.cc +++ b/src/renderer/mozc_renderer_main.cc @@ -80,7 +80,7 @@ int main(int argc, char *argv[]) { #ifdef OS_WIN mozc::ScopedCOMInitializer com_initializer; #elif defined(ENABLE_GTK_RENDERER) - gtk_set_locale(); + setlocale(LC_ALL, ""); #if !GLIB_CHECK_VERSION(2, 31, 0) // There are not g_thread_init function in glib>=2.31.0. // http://developer.gnome.org/glib/2.31/glib-Deprecated-Thread-APIs.html#g-thread-init diff --git a/src/renderer/renderer.gyp b/src/renderer/renderer.gyp index 78eb6a75..34141a4a 100644 --- a/src/renderer/renderer.gyp +++ b/src/renderer/renderer.gyp @@ -532,15 +532,14 @@ # Required 'cflags' and 'link_settings' will be automatically # injected into any target which directly or indirectly depends # on this target. - 'target_name': 'gtk2_build_environment', + 'target_name': 'gtk3_build_environment', 'type': 'none', 'variables': { 'target_pkgs' : [ 'glib-2.0', 'gobject-2.0', 'gthread-2.0', - 'gtk+-2.0', - 'gdk-2.0', + 'gtk+-3.0', ], }, 'all_dependent_settings': { @@ -583,7 +582,7 @@ '../ipc/ipc.gyp:ipc', '../protocol/protocol.gyp:genproto_config_proto#host', '../protocol/protocol.gyp:renderer_proto', - 'gtk2_build_environment', + 'gtk3_build_environment', 'renderer_server', 'renderer_style_handler', 'table_layout', diff --git a/src/renderer/unix/candidate_window.cc b/src/renderer/unix/candidate_window.cc index bb0a346b..287f6871 100644 --- a/src/renderer/unix/candidate_window.cc +++ b/src/renderer/unix/candidate_window.cc @@ -85,7 +85,7 @@ CandidateWindow::CandidateWindow(TableLayoutInterface *table_layout, bool CandidateWindow::OnPaint(GtkWidget *widget, GdkEventExpose *event) { draw_tool_->Reset( - cairo_factory_->CreateCairoInstance(GetCanvasWidget()->window)); + cairo_factory_->CreateCairoInstance(gtk_widget_get_window(GetCanvasWidget()))); DrawBackground(); DrawShortcutBackground(); @@ -263,7 +263,7 @@ void CandidateWindow::DrawFrame() { } void CandidateWindow::Initialize() { - text_renderer_->Initialize(GetCanvasWidget()->window); + text_renderer_->Initialize(GetCanvasWidget()); } void CandidateWindow::UpdateScrollBarSize() { diff --git a/src/renderer/unix/gtk_wrapper.cc b/src/renderer/unix/gtk_wrapper.cc index 83d206d7..92c5483f 100644 --- a/src/renderer/unix/gtk_wrapper.cc +++ b/src/renderer/unix/gtk_wrapper.cc @@ -49,7 +49,7 @@ void GtkWrapper::GSignalConnect(gpointer instance, const gchar *signal, } void GtkWrapper::GtkWidgetHideAll(GtkWidget *widget) { - gtk_widget_hide_all(widget); + gtk_widget_hide(widget); } void GtkWrapper::GtkWidgetShowAll(GtkWidget *widget) { @@ -135,7 +135,7 @@ void GtkWrapper::GtkWidgetRealize(GtkWidget *widget) { void GtkWrapper::GdkWindowSetTypeHint(GtkWidget *widget, GdkWindowTypeHint hint) { - gdk_window_set_type_hint(widget->window, hint); + gdk_window_set_type_hint(gtk_widget_get_window(widget), hint); } } // namespace gtk diff --git a/src/renderer/unix/infolist_window.cc b/src/renderer/unix/infolist_window.cc index 253f9659..f76f4c93 100644 --- a/src/renderer/unix/infolist_window.cc +++ b/src/renderer/unix/infolist_window.cc @@ -100,7 +100,7 @@ Rect InfolistWindow::GetCandidateColumnInClientCord() const { bool InfolistWindow::OnPaint(GtkWidget *widget, GdkEventExpose *event) { draw_tool_->Reset( - cairo_factory_->CreateCairoInstance(GetCanvasWidget()->window)); + cairo_factory_->CreateCairoInstance(gtk_widget_get_window(GetCanvasWidget()))); Draw(); return true; } @@ -237,7 +237,7 @@ int InfolistWindow::DrawRow(int row, int ypos) { } void InfolistWindow::Initialize() { - text_renderer_->Initialize(GetCanvasWidget()->window); + text_renderer_->Initialize(GetCanvasWidget()); } void InfolistWindow::ReloadFontConfig(const std::string &font_description) { diff --git a/src/renderer/unix/pango_wrapper.cc b/src/renderer/unix/pango_wrapper.cc index 8f87699a..545072a3 100644 --- a/src/renderer/unix/pango_wrapper.cc +++ b/src/renderer/unix/pango_wrapper.cc @@ -88,21 +88,12 @@ void PangoWrapper::AttributesUnref(PangoAttrList *attribute) { PangoContext *PangoWrapper::GetContext() { return context_; } -PangoWrapper::PangoWrapper(GdkDrawable *drawable) : gc_(gdk_gc_new(drawable)) { - GdkScreen *screen = gdk_drawable_get_screen(drawable); - renderer_ = gdk_pango_renderer_new(screen); - gdk_pango_renderer_set_drawable(GDK_PANGO_RENDERER(renderer_), drawable); - gdk_pango_renderer_set_gc(GDK_PANGO_RENDERER(renderer_), gc_); - context_ = gdk_pango_context_get(); +PangoWrapper::PangoWrapper(GtkWidget *window) { + context_ = gtk_widget_get_pango_context(window); } PangoWrapper::~PangoWrapper() { - gdk_pango_renderer_set_override_color(GDK_PANGO_RENDERER(renderer_), - PANGO_RENDER_PART_FOREGROUND, nullptr); - gdk_pango_renderer_set_drawable(GDK_PANGO_RENDERER(renderer_), nullptr); - gdk_pango_renderer_set_gc(GDK_PANGO_RENDERER(renderer_), nullptr); - g_object_unref(gc_); - g_object_unref(context_); + g_object_unref(G_OBJECT(context_)); } } // namespace gtk diff --git a/src/renderer/unix/pango_wrapper.h b/src/renderer/unix/pango_wrapper.h index 7c41cc54..c7c7fb04 100644 --- a/src/renderer/unix/pango_wrapper.h +++ b/src/renderer/unix/pango_wrapper.h @@ -57,7 +57,7 @@ class PangoLayoutWrapper : public PangoLayoutWrapperInterface { class PangoWrapper : public PangoWrapperInterface { public: - explicit PangoWrapper(GdkDrawable *drawable); + explicit PangoWrapper(GtkWidget *window); virtual ~PangoWrapper(); virtual void RendererDrawLayout(PangoLayoutWrapperInterface *layout, int x, int y); @@ -68,7 +68,6 @@ class PangoWrapper : public PangoWrapperInterface { private: PangoRenderer *renderer_; PangoContext *context_; - GdkGC *gc_; DISALLOW_COPY_AND_ASSIGN(PangoWrapper); }; } // namespace gtk diff --git a/src/renderer/unix/text_renderer.cc b/src/renderer/unix/text_renderer.cc index 164f01bc..4ba96ea2 100644 --- a/src/renderer/unix/text_renderer.cc +++ b/src/renderer/unix/text_renderer.cc @@ -39,9 +39,8 @@ namespace gtk { TextRenderer::TextRenderer(FontSpecInterface *font_spec) : font_spec_(font_spec), pango_(nullptr) {} - -void TextRenderer::Initialize(GdkDrawable *drawable) { - pango_.reset(new PangoWrapper(drawable)); +void TextRenderer::Initialize(GtkWidget *window) { + pango_.reset(new PangoWrapper(window)); } void TextRenderer::SetUpPangoLayout(const std::string &str, diff --git a/src/renderer/unix/text_renderer.h b/src/renderer/unix/text_renderer.h index c4cd2430..ba36b052 100644 --- a/src/renderer/unix/text_renderer.h +++ b/src/renderer/unix/text_renderer.h @@ -50,8 +50,7 @@ class TextRenderer : public TextRendererInterface { public: explicit TextRenderer(FontSpecInterface *font_spec); virtual ~TextRenderer() {} - - virtual void Initialize(GdkDrawable *drawable); + virtual void Initialize(GtkWidget *window); virtual Size GetPixelSize(FontSpecInterface::FONT_TYPE font_type, const std::string &str); virtual Size GetMultiLinePixelSize(FontSpecInterface::FONT_TYPE font_type, diff --git a/src/renderer/unix/text_renderer_interface.h b/src/renderer/unix/text_renderer_interface.h index db823217..9c569f6a 100644 --- a/src/renderer/unix/text_renderer_interface.h +++ b/src/renderer/unix/text_renderer_interface.h @@ -44,7 +44,7 @@ class TextRendererInterface { TextRendererInterface() {} virtual ~TextRendererInterface() {} - virtual void Initialize(GdkDrawable *drawable) = 0; + virtual void Initialize(GtkWidget *window) = 0; // Returns boundary rectangle size of actual rendered text. virtual Size GetPixelSize(FontSpecInterface::FONT_TYPE font_type, const std::string &str) = 0; -- 2.36.0