Added the Ecore::X::Cursor class.
authorTilman Sauerbeck <tilman@code-monkey.de>
Thu, 26 Aug 2004 13:12:55 +0000 (13:12 +0000)
committerTilman Sauerbeck <tilman@code-monkey.de>
Thu, 26 Aug 2004 13:12:55 +0000 (13:12 +0000)
src/ecore_x/Makefile.am
src/ecore_x/rb_cursor.c [new file with mode: 0644]
src/ecore_x/rb_cursor.h [new file with mode: 0644]
src/ecore_x/rb_ecore_x.c
src/ecore_x/rb_ecore_x.h
src/ecore_x/rb_window.c

index ae04a7a75ff52afd8a5d18cea4fad72f3f723eff..064506df2f17e0787ad09bf5b369c6edf365fb50 100644 (file)
@@ -1,4 +1,4 @@
-## $Id: Makefile.am 72 2004-08-16 18:10:27Z tilman $
+## $Id: Makefile.am 98 2004-08-26 13:12:55Z tilman $
 
 AM_CFLAGS = $(ECORE_CFLAGS)
 INCLUDES = -I$(RUBYDIR) -I$(RUBYSITEDIR)
@@ -7,7 +7,8 @@ ext_LTLIBRARIES = ecore_x.la
 extdir = $(RUBYSITEDIR)
 
 ecore_x_la_SOURCES = rb_ecore_x.c rb_ecore_x.h \
-                     rb_window.c rb_window.h
+                     rb_window.c rb_window.h \
+                     rb_cursor.c rb_cursor.h
 
 ecore_x_la_LIBADD = -L$(RUBYLIBDIR) -lruby $(ECORE_LIBS)
 ecore_x_la_LDFLAGS = -module -avoid-version
diff --git a/src/ecore_x/rb_cursor.c b/src/ecore_x/rb_cursor.c
new file mode 100644 (file)
index 0000000..9109151
--- /dev/null
@@ -0,0 +1,139 @@
+/*
+ * $Id: rb_cursor.c 98 2004-08-26 13:12:55Z tilman $
+ *
+ * Copyright (C) 2004 ruby-ecore team (see AUTHORS)
+ *
+ * This library 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 library 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.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <ruby.h>
+
+#include <Ecore_X.h>
+#include <Ecore_X_Cursor.h>
+
+#define __RB_CURSOR_C
+#include "rb_ecore_x.h"
+#include "rb_cursor.h"
+
+VALUE cCursor;
+
+static void c_free (RbCursor *c)
+{
+       if (c->real && c->need_free)
+               ecore_x_cursor_free (c->real);
+
+       free (c);
+}
+
+static VALUE c_new_from_shape (VALUE klass, VALUE shape)
+{
+       VALUE self;
+       RbCursor *cursor = NULL;
+
+       self = Data_Make_Struct (klass, RbCursor, NULL, c_free, cursor);
+
+       cursor->real = ecore_x_cursor_shape_get (FIX2INT (shape));
+       cursor->need_free = false;
+
+       rb_obj_call_init (self, 0, NULL);
+
+       return self;
+}
+
+void Init_Cursor (void)
+{
+       cCursor = rb_define_class_under (mX, "Cursor", rb_cObject);
+
+       rb_define_singleton_method (cCursor, "new_from_shape",
+                                   c_new_from_shape, 1);
+
+       /* shape constants */
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, X);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, ARROW);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, BASED_ARROW_DOWN);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, UP);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, BOAT);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, BOTTOM_LEFT_CORNER);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, BOTTOM_RIGHT_CORNER);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, BOTTOM_SIDE);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, BOTTOM_TEE);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, BOX_SPIRAL);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, CENTER_PTR);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, CIRCLE);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, CLOCK);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, COFFEE_MUG);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, CROSS);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, CROSS_REVERSE);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, CROSSHAIR);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, DIAMOND_CROSS);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, DOT);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, DOT_BOX_MASK);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, DOUBLE_ARROW);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, DRAFT_LARGE);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, DRAFT_SMALL);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, DRAPED_BOX);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, EXCHANGE);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, FLEUR);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, GOBBLER);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, GUMBY);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, HAND1);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, HAND2);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, HEART);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, ICON);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, IRON_CROSS);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, LEFT_PTR);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, LEFT_SIDE);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, LEFT_TEE);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, LEFTBUTTON);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, LL_ANGLE);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, LR_ANGLE);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, MAN);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, MIDDLEBUTTON);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, MOUSE);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, PENCIL);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, PIRATE);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, PLUS);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, QUESTION_ARROW);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, RIGHT_PTR);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, RIGHT_SIDE);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, RIGHT_TEE);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, RIGHTBUTTON);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, RTL_LOGO);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, SAILBOAT);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, SB_DOWN_ARROW);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, SB_H_DOUBLE_ARROW);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, SB_LEFT_ARROW);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, SB_RIGHT_ARROW);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, SB_UP_ARROW);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, SB_V_DOUBLE_ARROW);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, SHUTTLE);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, SIZING);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, SPIDER);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, SPRAYCAN);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, STAR);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, TARGET);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, TCROSS);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, TOP_LEFT_ARROW);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, TOP_LEFT_CORNER);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, TOP_RIGHT_CORNER);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, TOP_SIDE);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, TOP_TEE);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, TREK);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, UL_ANGLE);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, UMBRELLA);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, UR_ANGLE);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, WATCH);
+       DEF_CONST (cCursor, ECORE_X_CURSOR_, XTERM);
+}
diff --git a/src/ecore_x/rb_cursor.h b/src/ecore_x/rb_cursor.h
new file mode 100644 (file)
index 0000000..b54a18e
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * $Id: rb_cursor.h 98 2004-08-26 13:12:55Z tilman $
+ *
+ * Copyright (C) 2004 ruby-ecore team (see AUTHORS)
+ *
+ * This library 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 library 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.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef __RB_CURSOR_H
+#define __RB_CURSOR_H
+
+#include <stdbool.h>
+
+typedef struct {
+       Ecore_X_Cursor real;
+       bool need_free;
+} RbCursor;
+
+void Init_Cursor (void);
+
+#ifndef __RB_CURSOR_C
+extern VALUE cCursor;
+#endif
+
+#endif
index e6a89b4bf51cd42c1ac15e2eb210757c4b7d822c..83405b02bd30160e3fb726eb8b0dd363efe536e6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: rb_ecore_x.c 94 2004-08-23 10:53:25Z tilman $
+ * $Id: rb_ecore_x.c 98 2004-08-26 13:12:55Z tilman $
  *
  * Copyright (C) 2004 ruby-ecore team (see AUTHORS)
  *
 #include "../ecore/rb_event_handler.h"
 #include "rb_ecore_x.h"
 #include "rb_window.h"
-
-#define DEF_CONST(mod, prefix, name) \
-       rb_define_const ((mod), #name, \
-                        INT2FIX (prefix##name));
+#include "rb_cursor.h"
 
 static VALUE default_root;
 
@@ -322,11 +319,11 @@ void Init_ecore_x (void)
                                   m_default_root_window_get, 0);
 
        Init_Window ();
+       Init_Cursor ();
 
        /* now create the default root window object */
        w = DefaultRootWindow (ecore_x_display_get ());
        default_root = TO_ECORE_X_WINDOW (Qnil, w);
-       OBJ_FREEZE (default_root);
        rb_global_variable (&default_root);
 
        /* event mask values */
index 4179c02621b03026821d990c500fec2186273483..a18a12d8128b442b947a7ea2a7a7731573aa1ed0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: rb_ecore_x.h 77 2004-08-19 17:39:29Z tilman $
+ * $Id: rb_ecore_x.h 98 2004-08-26 13:12:55Z tilman $
  *
  * Copyright (C) 2004 ruby-ecore team (see AUTHORS)
  *
 #ifndef __RB_ECORE_X_H
 #define __RB_ECORE_X_H
 
+#define DEF_CONST(mod, prefix, name) \
+       rb_define_const ((mod), #name, \
+                        INT2FIX (prefix##name));
+
 VALUE mX;
 
 #endif
index f5af7c78d9a168fc17db7e565b846624866db2ba..0463e2142e23dbab01c1234a0e0a1c85baae0ed6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: rb_window.c 97 2004-08-23 18:30:28Z tilman $
+ * $Id: rb_window.c 98 2004-08-26 13:12:55Z tilman $
  *
  * Copyright (C) 2004 ruby-ecore team (see AUTHORS)
  *
@@ -27,6 +27,7 @@
 #include "../ecore/rb_ecore.h"
 #include "rb_ecore_x.h"
 #include "rb_window.h"
+#include "rb_cursor.h"
 
 VALUE cWindow;
 
@@ -92,6 +93,13 @@ static VALUE c_new (int argc, VALUE *argv, VALUE klass)
        return self;
 }
 
+static VALUE c_init (int argc, VALUE *argv, VALUE self)
+{
+       rb_iv_set (self, "@cursor", Qnil);
+
+       return self;
+}
+
 static VALUE c_inspect (VALUE self)
 {
        char buf[128];
@@ -361,6 +369,19 @@ static VALUE c_sticky_set (VALUE self, VALUE val)
        return Qnil;
 }
 
+static VALUE c_cursor_set (VALUE self, VALUE val)
+{
+       GET_OBJ (self, RbWindow, win);
+
+       CHECK_CLASS (val, cCursor);
+       GET_OBJ (val, RbCursor, c);
+
+       ecore_x_window_cursor_set (win->real, c->real);
+       rb_iv_set (self, "@cursor", val);
+
+       return Qnil;
+}
+
 static VALUE c_manage (VALUE self)
 {
        GET_OBJ (self, RbWindow, win);
@@ -411,6 +432,7 @@ void Init_Window (void)
        cWindow = rb_define_class_under (mX, "Window", rb_cObject);
 
        rb_define_singleton_method (cWindow, "new", c_new, -1);
+       rb_define_method (cWindow, "initialize", c_init, -1);
        rb_define_method (cWindow, "inspect", c_inspect, 0);
        rb_define_method (cWindow, "==", c_equal_value, 1);
        rb_define_method (cWindow, "show", c_show, 0);
@@ -439,9 +461,12 @@ void Init_Window (void)
        rb_define_method (cWindow, "get_protocol", c_get_protocol, 1);
        rb_define_method (cWindow, "sticky?", c_sticky_get, 0);
        rb_define_method (cWindow, "sticky=", c_sticky_set, 1);
+       rb_define_method (cWindow, "cursor=", c_cursor_set, 1);
        rb_define_method (cWindow, "manage", c_manage, 0);
        rb_define_method (cWindow, "manage_container", c_manage_container, 0);
        rb_define_method (cWindow, "manage_client", c_manage_client, 0);
        rb_define_method (cWindow, "sniff", c_sniff, 0);
        rb_define_method (cWindow, "sniff_client", c_sniff_client, 0);
+
+       rb_define_attr (cWindow, "cursor", 1, 0);
 }