/gtk2/ext/gtk2/rbgdkwindowattr.c

https://github.com/masaakiaoyagi/ruby-gnome2 · C · 208 lines · 167 code · 19 blank · 22 comment · 3 complexity · 72d866401d418eb6d5b146a256cf3e94 MD5 · raw file

  1. /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
  2. /*
  3. * Copyright (C) 2011 Ruby-GNOME2 Project Team
  4. * Copyright (C) 2003 Masao Mutoh
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  19. * MA 02110-1301 USA
  20. */
  21. #include "global.h"
  22. /*****************************************/
  23. static GdkWindowAttr*
  24. attr_copy(const GdkWindowAttr* win)
  25. {
  26. GdkWindowAttr* new_win;
  27. g_return_val_if_fail (win != NULL, NULL);
  28. new_win = g_new(GdkWindowAttr, 1);
  29. *new_win = *win;
  30. return new_win;
  31. }
  32. GType
  33. gdk_windowattr_get_type(void)
  34. {
  35. static GType our_type = 0;
  36. if (our_type == 0)
  37. our_type = g_boxed_type_register_static ("GdkWindowAttr",
  38. (GBoxedCopyFunc)attr_copy,
  39. (GBoxedFreeFunc)g_free);
  40. return our_type;
  41. }
  42. /*****************************************/
  43. #define RG_TARGET_NAMESPACE cWindowAttr
  44. #define _SELF(w) ((GdkWindowAttr*)RVAL2BOXED(w, GDK_TYPE_WINDOW_ATTR))
  45. static VALUE
  46. rg_initialize(VALUE self, VALUE width, VALUE height, VALUE wclass,
  47. VALUE window_type)
  48. {
  49. GdkWindowAttr w;
  50. w.width = NUM2INT(width);
  51. w.height = NUM2INT(height);
  52. w.wclass = RVAL2GENUM(wclass, GDK_TYPE_WINDOW_CLASS);
  53. w.window_type = RVAL2GENUM(window_type, GDK_TYPE_WINDOW_TYPE);
  54. G_INITIALIZE(self, &w);
  55. return Qnil;
  56. }
  57. #define ATTR_STR(name)\
  58. static VALUE \
  59. attr_get_ ## name (VALUE self)\
  60. {\
  61. return CSTR2RVAL(_SELF(self)->name);\
  62. }\
  63. static VALUE \
  64. attr_set_ ## name (VALUE self, VALUE val)\
  65. {\
  66. _SELF(self)->name = (gchar *)RVAL2CSTR(val);\
  67. return self;\
  68. }
  69. #define ATTR_INT(name)\
  70. static VALUE \
  71. attr_get_ ## name (VALUE self)\
  72. {\
  73. return INT2NUM(_SELF(self)->name);\
  74. }\
  75. static VALUE \
  76. attr_set_ ## name (VALUE self, VALUE val)\
  77. {\
  78. _SELF(self)->name = NUM2INT(val);\
  79. return self;\
  80. }
  81. ATTR_STR(title);
  82. ATTR_INT(event_mask);
  83. ATTR_INT(x);
  84. ATTR_INT(y);
  85. ATTR_INT(width);
  86. ATTR_INT(height);
  87. static VALUE
  88. rg_wclass(VALUE self)
  89. {
  90. return GENUM2RVAL(_SELF(self)->wclass, GDK_TYPE_WINDOW_CLASS);
  91. }
  92. static VALUE
  93. rg_set_wclass(VALUE self, VALUE val)
  94. {
  95. _SELF(self)->wclass = RVAL2GENUM(val, GDK_TYPE_WINDOW_CLASS);
  96. return self;
  97. }
  98. static VALUE
  99. rg_visual(VALUE self)
  100. {
  101. return GOBJ2RVAL(_SELF(self)->visual);
  102. }
  103. static VALUE
  104. rg_set_visual(VALUE self, VALUE val)
  105. {
  106. _SELF(self)->visual = GDK_VISUAL(RVAL2GOBJ(val));
  107. return self;
  108. }
  109. static VALUE
  110. rg_colormap(VALUE self)
  111. {
  112. return GOBJ2RVAL(_SELF(self)->colormap);
  113. }
  114. static VALUE
  115. rg_set_colormap(VALUE self, VALUE val)
  116. {
  117. _SELF(self)->colormap = GDK_COLORMAP(RVAL2GOBJ(val));
  118. return self;
  119. }
  120. static VALUE
  121. rg_window_type(VALUE self)
  122. {
  123. return GENUM2RVAL(_SELF(self)->window_type, GDK_TYPE_WINDOW_TYPE);
  124. }
  125. static VALUE
  126. rg_set_window_type(VALUE self, VALUE val)
  127. {
  128. _SELF(self)->window_type = RVAL2GENUM(val, GDK_TYPE_WINDOW_TYPE);
  129. return self;
  130. }
  131. static VALUE
  132. rg_cursor(VALUE self)
  133. {
  134. return BOXED2RVAL(_SELF(self)->cursor, GDK_TYPE_CURSOR);
  135. }
  136. static VALUE
  137. rg_set_cursor(VALUE self, VALUE val)
  138. {
  139. _SELF(self)->cursor = (GdkCursor*)(RVAL2BOXED(val, GDK_TYPE_CURSOR));
  140. return self;
  141. }
  142. ATTR_STR(wmclass_name);
  143. ATTR_STR(wmclass_class);
  144. static VALUE
  145. rg_override_redirect(VALUE self)
  146. {
  147. return CBOOL2RVAL(_SELF(self)->override_redirect);
  148. }
  149. static VALUE
  150. rg_set_override_redirect(VALUE self, VALUE val)
  151. {
  152. _SELF(self)->override_redirect = RVAL2CBOOL(val);
  153. return self;
  154. }
  155. void
  156. Init_gtk_gdk_windowattr(VALUE mGdk)
  157. {
  158. VALUE RG_TARGET_NAMESPACE = G_DEF_CLASS(GDK_TYPE_WINDOW_ATTR, "WindowAttr", mGdk);
  159. RG_DEF_METHOD(initialize, 4);
  160. rb_define_method(RG_TARGET_NAMESPACE, "title", attr_get_title, 0);
  161. rb_define_method(RG_TARGET_NAMESPACE, "set_title", attr_set_title, 1);
  162. rb_define_method(RG_TARGET_NAMESPACE, "event_mask", attr_get_event_mask, 0);
  163. rb_define_method(RG_TARGET_NAMESPACE, "set_event_mask", attr_set_event_mask, 1);
  164. rb_define_method(RG_TARGET_NAMESPACE, "x", attr_get_x, 0);
  165. rb_define_method(RG_TARGET_NAMESPACE, "set_x", attr_set_x, 1);
  166. rb_define_method(RG_TARGET_NAMESPACE, "y", attr_get_y, 0);
  167. rb_define_method(RG_TARGET_NAMESPACE, "set_y", attr_set_y, 1);
  168. rb_define_method(RG_TARGET_NAMESPACE, "width", attr_get_width, 0);
  169. rb_define_method(RG_TARGET_NAMESPACE, "set_width", attr_set_width, 1);
  170. rb_define_method(RG_TARGET_NAMESPACE, "height", attr_get_height, 0);
  171. rb_define_method(RG_TARGET_NAMESPACE, "set_height", attr_set_height, 1);
  172. RG_DEF_METHOD(wclass, 0);
  173. RG_DEF_METHOD(set_wclass, 1);
  174. RG_DEF_METHOD(visual, 0);
  175. RG_DEF_METHOD(set_visual, 1);
  176. RG_DEF_METHOD(colormap, 0);
  177. RG_DEF_METHOD(set_colormap, 1);
  178. RG_DEF_METHOD(window_type, 0);
  179. RG_DEF_METHOD(set_window_type, 1);
  180. RG_DEF_METHOD(cursor, 0);
  181. RG_DEF_METHOD(set_cursor, 1);
  182. rb_define_method(RG_TARGET_NAMESPACE, "wmclass_name", attr_get_wmclass_name, 0);
  183. rb_define_method(RG_TARGET_NAMESPACE, "set_wmclass_name", attr_set_wmclass_name, 1);
  184. rb_define_method(RG_TARGET_NAMESPACE, "wmclass_class", attr_get_wmclass_class, 0);
  185. rb_define_method(RG_TARGET_NAMESPACE, "set_wmclass_class", attr_set_wmclass_class, 1);
  186. RG_DEF_METHOD(override_redirect, 0);
  187. RG_DEF_METHOD(set_override_redirect, 1);
  188. G_DEF_SETTERS(RG_TARGET_NAMESPACE);
  189. }