gtk_compat.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef UI_GTK_GTK_COMPAT_H_
  5. #define UI_GTK_GTK_COMPAT_H_
  6. #include <gdk-pixbuf/gdk-pixbuf.h>
  7. #include <gdk/gdk.h>
  8. #include <gio/gio.h>
  9. #include <gtk/gtk.h>
  10. #include <gtk/gtkunixprint.h>
  11. #include "base/files/file_path.h"
  12. #include "base/version.h"
  13. #include "third_party/abseil-cpp/absl/types/optional.h"
  14. #include "ui/base/glib/scoped_gobject.h"
  15. #include "ui/gfx/geometry/insets.h"
  16. #include "ui/gtk/gtk_types.h"
  17. extern "C" {
  18. #include "ui/gtk/gdk.sigs"
  19. #include "ui/gtk/gdk_pixbuf.sigs"
  20. #include "ui/gtk/gio.sigs"
  21. #include "ui/gtk/gsk.sigs"
  22. #include "ui/gtk/gtk.sigs"
  23. }
  24. #define GDK_KEY_PRESS Do_not_use_GDK_KEY_PRESS_because_it_is_not_ABI_compatible
  25. #define GDK_KEY_RELEASE \
  26. Do_not_use_GDK_KEY_RELEASE_because_it_is_not_ABI_compatible
  27. using SkColor = uint32_t;
  28. namespace gtk {
  29. // Loads libgtk and related libraries and returns true on success.
  30. bool LoadGtk();
  31. const base::Version& GtkVersion();
  32. // Returns true iff the runtime version of Gtk used meets
  33. // |major|.|minor|.|micro|. LoadGtk() must have been called
  34. // prior to calling this function.
  35. bool GtkCheckVersion(uint32_t major, uint32_t minor = 0, uint32_t micro = 0);
  36. // The below functions replace GTK functions whose interface has
  37. // changed across versions, but whose (symbol) names have not.
  38. [[nodiscard]] bool GtkInitCheck(int* argc, char** argv);
  39. gfx::Insets GtkStyleContextGetPadding(GtkStyleContext* context);
  40. gfx::Insets GtkStyleContextGetBorder(GtkStyleContext* context);
  41. gfx::Insets GtkStyleContextGetMargin(GtkStyleContext* context);
  42. SkColor GtkStyleContextGetColor(GtkStyleContext* context);
  43. // Only available in Gtk3.
  44. SkColor GtkStyleContextGetBackgroundColor(GtkStyleContext* context);
  45. // Only available in Gtk3.
  46. absl::optional<SkColor> GtkStyleContextLookupColor(GtkStyleContext* context,
  47. const gchar* color_name);
  48. bool GtkImContextFilterKeypress(GtkIMContext* context, GdkEventKey* event);
  49. bool GtkFileChooserSetCurrentFolder(GtkFileChooser* dialog,
  50. const base::FilePath& path);
  51. void GtkRenderIcon(GtkStyleContext* context,
  52. cairo_t* cr,
  53. GdkPixbuf* pixbuf,
  54. GdkTexture* texture,
  55. double x,
  56. double y);
  57. GtkWidget* GtkToplevelWindowNew();
  58. void GtkCssProviderLoadFromData(GtkCssProvider* css_provider,
  59. const char* data,
  60. gssize length);
  61. ScopedGObject<GListModel> Gtk4FileChooserGetFiles(GtkFileChooser* dialog);
  62. ScopedGObject<GtkIconInfo> Gtk3IconThemeLookupByGiconForScale(
  63. GtkIconTheme* theme,
  64. GIcon* icon,
  65. int size,
  66. int scale,
  67. GtkIconLookupFlags flags);
  68. ScopedGObject<GtkIconPaintable> Gtk4IconThemeLookupByGicon(
  69. GtkIconTheme* theme,
  70. GIcon* icon,
  71. int size,
  72. int scale,
  73. GtkTextDirection direction,
  74. GtkIconLookupFlags flags);
  75. ScopedGObject<GtkIconPaintable> Gtk4IconThemeLookupIcon(
  76. GtkIconTheme* theme,
  77. const char* icon_name,
  78. const char* fallbacks[],
  79. int size,
  80. int scale,
  81. GtkTextDirection direction,
  82. GtkIconLookupFlags flags);
  83. // generate_stubs cannot forward to C-style variadic functions, so the
  84. // functions below wrap the corresponding GTK va_list functions.
  85. void GtkStyleContextGet(GtkStyleContext* context, ...);
  86. void GtkStyleContextGetStyle(GtkStyleContext* context, ...);
  87. // These variadic functions do not have corresponding va_list equivalents,
  88. // so instances with only a fixed set of arguments are provided.
  89. GtkWidget* GtkFileChooserDialogNew(const gchar* title,
  90. GtkWindow* parent,
  91. GtkFileChooserAction action,
  92. const gchar* first_button_text,
  93. GtkResponseType first_response,
  94. const gchar* second_button_text,
  95. GtkResponseType second_response);
  96. GtkTreeStore* GtkTreeStoreNew(GType type);
  97. // These functions have dropped "const" in their signatures, so cannot be
  98. // declared in *.sigs.
  99. GdkEventType GdkEventGetEventType(GdkEvent* event);
  100. guint32 GdkEventGetTime(GdkEvent* event);
  101. // Some enum values have changed between versions.
  102. GdkEventType GdkKeyPress();
  103. GdkEventType GdkKeyRelease();
  104. } // namespace gtk
  105. #endif // UI_GTK_GTK_COMPAT_H_