GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: a tiny graphical app kit for ruby
Homepage: http://code.whytheluckystiff.net/shoes
Clone URL: git://github.com/why/shoes.git
 * shoes/ruby.c: beginning work on `state=` and `state` for setting 
 controls in disabled and read-only modes.
why (author)
Sat Oct 11 08:04:24 -0700 2008
commit  3f646dcff75586e5221bcb3277c12a21e95defa2
tree    1b8f45306668dfdcfaf469a9853f407f477c7196
parent  9191255455f39aa49b44f1c8e6dab95d33e01f07
...
302
303
304
305
306
307
308
...
302
303
304
 
305
306
307
0
@@ -302,7 +302,6 @@ shoes_app_exception(VALUE rb_exec, VALUE e)
0
 shoes_code
0
 shoes_app_visit(shoes_app *app, char *path)
0
 {
0
- long i;
0
   shoes_exec exec;
0
   shoes_canvas *canvas;
0
   VALUE meth;
...
240
241
242
 
 
 
 
243
244
245
...
487
488
489
 
 
490
491
492
...
240
241
242
243
244
245
246
247
248
249
...
491
492
493
494
495
496
497
498
0
@@ -240,6 +240,10 @@ typedef struct {
0
 //
0
 // native controls struct
0
 //
0
+#define CONTROL_NORMAL 0
0
+#define CONTROL_READONLY 1
0
+#define CONTROL_DISABLED 2
0
+
0
 typedef struct {
0
   VALUE parent;
0
   VALUE attr;
0
@@ -487,6 +491,8 @@ VALUE shoes_control_remove(VALUE);
0
 VALUE shoes_control_show(VALUE);
0
 VALUE shoes_control_hide(VALUE);
0
 VALUE shoes_control_focus(VALUE);
0
+VALUE shoes_control_get_state(VALUE);
0
+VALUE shoes_control_set_state(VALUE, VALUE);
0
 
0
 VALUE shoes_button_draw(VALUE, VALUE, VALUE);
0
 void shoes_button_send_click(VALUE);
...
72
73
74
 
75
76
77
...
129
130
131
 
132
133
134
...
193
194
195
 
196
197
198
...
72
73
74
75
76
77
78
...
130
131
132
133
134
135
136
...
195
196
197
198
199
200
201
0
@@ -72,6 +72,7 @@ typedef struct {
0
 
0
 #define SHOES_CONTROL_REF GtkWidget *
0
 #define SHOES_SURFACE_REF GtkWidget *
0
+#define SHOES_BOOL gboolean
0
 #define SHOES_TIMER_REF guint
0
 #define DC(slot) slot->canvas
0
 #define HAS_DRAWABLE(slot) slot->canvas->window != 0
0
@@ -129,6 +130,7 @@ typedef struct {
0
 
0
 #define SHOES_CONTROL_REF NSControl *
0
 #define SHOES_SURFACE_REF CGrafPtr
0
+#define SHOES_BOOL BOOL
0
 #define SHOES_TIMER_REF ShoesTimer *
0
 #define DC(slot) slot->view
0
 #define HAS_DRAWABLE(slot) slot->context != NULL
0
@@ -193,6 +195,7 @@ typedef struct {
0
 
0
 #define SHOES_CONTROL_REF HWND
0
 #define SHOES_SURFACE_REF HWND
0
+#define SHOES_BOOL BOOL
0
 #define SHOES_TIMER_REF long
0
 #define DC(slot) slot->window
0
 #define HAS_DRAWABLE(slot) slot->window != NULL
...
53
54
55
 
56
57
58
...
53
54
55
56
57
58
59
0
@@ -53,6 +53,7 @@ void shoes_native_control_position(SHOES_CONTROL_REF, shoes_place *,
0
 void shoes_native_control_repaint(SHOES_CONTROL_REF, shoes_place *,
0
   shoes_canvas *, shoes_place *);
0
 void shoes_native_control_focus(SHOES_CONTROL_REF);
0
+void shoes_native_control_state(SHOES_CONTROL_REF, SHOES_BOOL, SHOES_BOOL);
0
 void shoes_native_control_remove(SHOES_CONTROL_REF, shoes_canvas *);
0
 void shoes_native_control_free(SHOES_CONTROL_REF);
0
 SHOES_SURFACE_REF shoes_native_surface_new(shoes_canvas *, VALUE, shoes_place *);
...
888
889
890
 
 
 
 
 
 
 
 
 
 
891
892
893
...
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
0
@@ -888,6 +888,16 @@ shoes_native_control_repaint(SHOES_CONTROL_REF ref, shoes_place *p1,
0
 }
0
 
0
 void
0
+shoes_native_control_state(SHOES_CONTROL_REF ref, BOOL sensitive, BOOL setting)
0
+{
0
+ COCOA_DO({
0
+ [ref setEnabled: sensitive];
0
+ if ([ref respondsToSelector: @selector(setEditable:)])
0
+ [ref setEditable: setting];
0
+ });
0
+}
0
+
0
+void
0
 shoes_native_control_focus(SHOES_CONTROL_REF ref)
0
 {
0
   COCOA_DO([[ref window] makeFirstResponder: ref]);
...
730
731
732
 
 
 
 
 
 
 
 
 
 
 
 
 
 
733
734
735
...
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
0
@@ -730,6 +730,20 @@ shoes_native_control_focus(SHOES_CONTROL_REF ref)
0
 }
0
 
0
 void
0
+shoes_native_control_state(SHOES_CONTROL_REF ref, gboolean sensitive, gboolean setting)
0
+{
0
+ gtk_widget_set_sensitive(ref, sensitive);
0
+ if (GTK_IS_EDITABLE(ref))
0
+ gtk_editable_set_editable(GTK_EDITABLE(ref), setting);
0
+ else if (GTK_IS_SCROLLED_WINDOW(ref))
0
+ {
0
+ GtkWidget *textview;
0
+ GTK_CHILD(textview, ref);
0
+ gtk_text_view_set_editable(GTK_TEXT_VIEW(textview), setting);
0
+ }
0
+}
0
+
0
+void
0
 shoes_native_control_remove(SHOES_CONTROL_REF ref, shoes_canvas *canvas)
0
 {
0
   gtk_container_remove(GTK_CONTAINER(canvas->slot->canvas), ref);
...
1078
1079
1080
 
 
 
 
 
 
 
1081
1082
1083
...
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
0
@@ -1078,6 +1078,13 @@ shoes_native_control_repaint(SHOES_CONTROL_REF ref, shoes_place *p1,
0
 }
0
 
0
 void
0
+shoes_native_control_state(SHOES_CONTROL_REF ref, BOOL sensitive, BOOL setting)
0
+{
0
+ EnableWindow(ref, sensitive);
0
+ SendMessage(ref, EM_SETREADONLY, setting, 0);
0
+}
0
+
0
+void
0
 shoes_native_control_focus(SHOES_CONTROL_REF ref)
0
 {
0
   SetFocus(ref);
...
17
18
19
20
 
21
22
23
...
2867
2868
2869
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2870
2871
2872
...
4134
4135
4136
 
4137
4138
4139
...
4473
4474
4475
 
 
4476
4477
4478
...
17
18
19
 
20
21
22
23
...
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
...
4175
4176
4177
4178
4179
4180
4181
...
4515
4516
4517
4518
4519
4520
4521
4522
0
@@ -17,7 +17,7 @@ VALUE cShoes, cApp, cDialog, cShoesWindow, cMouse, cCanvas, cFlow, cStack, cMask
0
 VALUE eVlcError, eImageError, eInvMode, eNotImpl;
0
 VALUE reHEX_SOURCE, reHEX3_SOURCE, reRGB_SOURCE, reRGBA_SOURCE, reGRAY_SOURCE, reGRAYA_SOURCE, reLF;
0
 VALUE symAltQuest, symAltSlash, symAltDot;
0
-ID s_aref, s_mult, s_perc, s_bind, s_gsub, s_keys, s_update, s_merge, s_new, s_run, s_to_pattern, s_to_i, s_to_s, s_URI, s_angle, s_angle1, s_angle2, s_arrow, s_autoplay, s_begin, s_body, s_call, s_center, s_change, s_checked, s_checked_q, s_choose, s_click, s_corner, s_curve, s_distance, s_displace_left, s_displace_top, s_downcase, s_draw, s_end, s_fill, s_finish, s_font, s_group, s_hand, s_headers, s_hidden, s_host, s_hover, s_href, s_inner, s_insert, s_items, s_keypress, s_link, s_method, s_motion, s_path, s_port, s_progress, s_redirect, s_release, s_request_uri, s_save, s_wheel, s_stroke, s_scroll, s_start, s_attach, s_leading, s_leave, s_outer, s_points, s_match, s_text, s_title, s_top, s_right, s_bottom, s_left, s_up, s_down, s_height, s_resizable, s_remove, s_cap, s_strokewidth, s_width, s_margin, s_margin_left, s_margin_right, s_margin_top, s_margin_bottom, s_radius, s_secret, s_now, s_debug, s_error, s_warn, s_info, s_blur, s_glow, s_shadow, s_arc, s_rect, s_oval, s_line, s_shape, s_star, s_project, s_round, s_square;
0
+ID s_aref, s_mult, s_perc, s_bind, s_gsub, s_keys, s_update, s_merge, s_new, s_run, s_to_pattern, s_to_i, s_to_s, s_URI, s_angle, s_angle1, s_angle2, s_arrow, s_autoplay, s_begin, s_body, s_call, s_center, s_change, s_checked, s_checked_q, s_choose, s_click, s_corner, s_curve, s_distance, s_displace_left, s_displace_top, s_downcase, s_draw, s_end, s_fill, s_finish, s_font, s_group, s_hand, s_headers, s_hidden, s_host, s_hover, s_href, s_inner, s_insert, s_items, s_keypress, s_link, s_method, s_motion, s_path, s_port, s_progress, s_redirect, s_release, s_request_uri, s_save, s_state, s_wheel, s_stroke, s_scroll, s_start, s_attach, s_leading, s_leave, s_outer, s_points, s_match, s_text, s_title, s_top, s_right, s_bottom, s_left, s_up, s_down, s_height, s_resizable, s_remove, s_cap, s_strokewidth, s_width, s_margin, s_margin_left, s_margin_right, s_margin_top, s_margin_bottom, s_radius, s_secret, s_now, s_debug, s_error, s_warn, s_info, s_blur, s_glow, s_shadow, s_arc, s_rect, s_oval, s_line, s_shape, s_star, s_project, s_round, s_square;
0
 
0
 //
0
 // Mauricio's instance_eval hack (he bested my cloaker back in 06 Jun 2006)
0
@@ -2867,6 +2867,47 @@ shoes_control_focus(VALUE self)
0
 }
0
 
0
 VALUE
0
+shoes_control_get_state(VALUE self)
0
+{
0
+ GET_STRUCT(control, self_t);
0
+ return ATTR(self_t->attr, state);
0
+}
0
+
0
+VALUE
0
+shoes_control_set_state(VALUE self, VALUE state)
0
+{
0
+ unsigned char cstate;
0
+ GET_STRUCT(control, self_t);
0
+ if (NIL_P(state))
0
+ cstate = CONTROL_NORMAL;
0
+ else if (TYPE(state) == T_STRING)
0
+ {
0
+ if (strncmp(RSTRING_PTR(state), "disabled", 8) == 0)
0
+ cstate = CONTROL_DISABLED;
0
+ else if (strncmp(RSTRING_PTR(state), "readonly", 8) == 0)
0
+ cstate = CONTROL_READONLY;
0
+ else
0
+ {
0
+ shoes_error("control can't have :state of %s\n", RSTRING_PTR(state));
0
+ return self;
0
+ }
0
+ }
0
+ else return self;
0
+
0
+ ATTRSET(self_t->attr, state, state);
0
+ if (self_t->ref != NULL)
0
+ {
0
+ if (cstate == CONTROL_NORMAL)
0
+ shoes_native_control_state(self_t->ref, TRUE, TRUE);
0
+ else if (cstate == CONTROL_DISABLED)
0
+ shoes_native_control_state(self_t->ref, FALSE, TRUE);
0
+ else if (cstate == CONTROL_READONLY)
0
+ shoes_native_control_state(self_t->ref, TRUE, FALSE);
0
+ }
0
+ return self;
0
+}
0
+
0
+VALUE
0
 shoes_control_hide(VALUE self)
0
 {
0
   GET_STRUCT(control, self_t);
0
@@ -4134,6 +4175,7 @@ shoes_ruby_init()
0
   s_release = rb_intern("release");
0
   s_request_uri = rb_intern("request_uri");
0
   s_save = rb_intern("save");
0
+ s_state = rb_intern("state");
0
   s_wheel = rb_intern("wheel");
0
   s_scroll = rb_intern("scroll");
0
   s_stroke = rb_intern("stroke");
0
@@ -4473,6 +4515,8 @@ shoes_ruby_init()
0
   rb_define_method(cNative, "focus", CASTHOOK(shoes_control_focus), 0);
0
   rb_define_method(cNative, "hide", CASTHOOK(shoes_control_hide), 0);
0
   rb_define_method(cNative, "show", CASTHOOK(shoes_control_show), 0);
0
+ rb_define_method(cNative, "state=", CASTHOOK(shoes_control_set_state), 1);
0
+ rb_define_method(cNative, "state", CASTHOOK(shoes_control_get_state), 0);
0
   rb_define_method(cNative, "move", CASTHOOK(shoes_control_move), 2);
0
   rb_define_method(cNative, "top", CASTHOOK(shoes_control_get_top), 0);
0
   rb_define_method(cNative, "left", CASTHOOK(shoes_control_get_left), 0);

Comments

    No one has commented yet.