/gtk3/ext/gtk3/rbgtkstyleproperties.c

https://github.com/masaakiaoyagi/ruby-gnome2 · C · 119 lines · 80 code · 20 blank · 19 comment · 2 complexity · ba32375766755807428af2493b1e4f6c MD5 · raw file

  1. /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
  2. /*
  3. * Copyright (C) 2011 Ruby-GNOME2 Project Team
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  18. * MA 02110-1301 USA
  19. */
  20. #include "rbgtk3private.h"
  21. #define RG_TARGET_NAMESPACE cStyleProperties
  22. #define _SELF(self) (RVAL2GTKSTYLEPROPERTIES(self))
  23. static VALUE
  24. rg_initialize(VALUE self)
  25. {
  26. G_INITIALIZE(self, gtk_style_properties_new());
  27. return Qnil;
  28. }
  29. static VALUE
  30. rg_clear(VALUE self)
  31. {
  32. gtk_style_properties_clear(_SELF(self));
  33. return self;
  34. }
  35. static VALUE
  36. rg_get_property(VALUE self, VALUE property, VALUE state)
  37. {
  38. GValue value = G_VALUE_INIT;
  39. gboolean result;
  40. VALUE ret = Qnil;
  41. result = gtk_style_properties_get_property(_SELF(self),
  42. RVAL2CSTR(property),
  43. RVAL2GTKSTATEFLAGS(state),
  44. &value);
  45. if (G_VALUE_TYPE(&value) != G_TYPE_INVALID){
  46. ret = GVAL2RVAL(&value);
  47. g_value_unset(&value);
  48. }
  49. return ret;
  50. }
  51. static VALUE
  52. rg_lookup_color(VALUE self, VALUE name)
  53. {
  54. return GOBJ2RVAL(gtk_style_properties_lookup_color(_SELF(self), RVAL2CSTR(name)));
  55. }
  56. static VALUE
  57. rg_map_color(VALUE self, VALUE name, VALUE color)
  58. {
  59. gtk_style_properties_map_color(_SELF(self),
  60. RVAL2CSTR(name),
  61. RVAL2GTKSYMBOLICCOLOR(color));
  62. return self;
  63. }
  64. static VALUE
  65. rg_merge(VALUE self, VALUE other, VALUE replace)
  66. {
  67. gtk_style_properties_merge(_SELF(self), _SELF(other), RVAL2CBOOL(replace));
  68. return self;
  69. }
  70. static VALUE
  71. rg_set_property(VALUE self, VALUE property, VALUE state, VALUE value)
  72. {
  73. gtk_style_properties_set_property(_SELF(self),
  74. RVAL2CSTR(property),
  75. RVAL2GTKSTATEFLAGS(state),
  76. RVAL2GVALUE(value));
  77. return self;
  78. }
  79. static VALUE
  80. rg_unset_property(VALUE self, VALUE property, VALUE state)
  81. {
  82. gtk_style_properties_unset_property(_SELF(self),
  83. RVAL2CSTR(property),
  84. RVAL2GTKSTATEFLAGS(state));
  85. return self;
  86. }
  87. void
  88. Init_gtk_styleproperties(VALUE mGtk)
  89. {
  90. VALUE RG_TARGET_NAMESPACE = G_DEF_CLASS(GTK_TYPE_STYLE_PROPERTIES, "StyleProperties", mGtk);
  91. RG_DEF_METHOD(initialize, 0);
  92. RG_DEF_METHOD(clear, 0);
  93. RG_DEF_METHOD(get_property, 2);
  94. RG_DEF_METHOD(lookup_color, 1);
  95. RG_DEF_METHOD(map_color, 2);
  96. RG_DEF_METHOD(merge, 2);
  97. RG_DEF_METHOD(set_property, 3);
  98. RG_DEF_METHOD(unset_property, 2);
  99. }