int shoes_px2(VALUE attr, ID k1, ID k2, int dv, int dr, int pv) { int px; VALUE obj = shoes_hash_get(attr, k2); if (!NIL_P(obj)) { px = shoes_px(obj, 0, pv, 0); px = (pv - dr) - px; } else { px = shoes_px(shoes_hash_get(attr, k1), dv, pv, 0); } return px; }
SHOES_CONTROL_REF shoes_native_slider(VALUE self, shoes_canvas *canvas, shoes_place *place, VALUE attr, char *msg) { SHOES_CONTROL_REF ref = gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL, 0., 1., 0.01); if (!NIL_P(shoes_hash_get(attr, rb_intern("tooltip")))) { gtk_widget_set_tooltip_text(GTK_WIDGET(ref), RSTRING_PTR(shoes_hash_get(attr, rb_intern("tooltip")))); } gtk_scale_set_draw_value(GTK_SCALE(ref), FALSE); g_signal_connect(G_OBJECT(ref), "value-changed", G_CALLBACK(shoes_widget_changed), (gpointer)self); return ref; }
VALUE shoes_systray_new(int argc, VALUE *argv, VALUE parent) { // Get Ruby args. VALUE rbtitle, rbmessage, rbpath; if (argc == 1) { rbtitle = shoes_hash_get(argv[0], rb_intern("title")); rbmessage = shoes_hash_get(argv[0], rb_intern("message")); rbpath = shoes_hash_get(argv[0], rb_intern("icon")); } else if (argc == 3) { rbtitle = argv[0]; rbmessage = argv[1]; rbpath = argv[2]; } else { rb_raise(rb_eArgError, "Missing an argument to systray"); } char *title = NULL, *message = NULL, *path = NULL; /* Alloc the object and init. We do keep a copy of the strings * which will be garbage collected at some point by Ruby * Assumes the strings and pixbufs in the native are copied * out of our process memory into the Desktop's space. */ VALUE obj = shoes_systray_alloc(cSystray); shoes_systray *self_t; Data_Get_Struct(obj, shoes_systray, self_t); Check_Type(rbtitle, T_STRING); if ((!NIL_P(rbtitle)) && (RSTRING_LEN(rbtitle) > 0)) { title = self_t->title = strdup(RSTRING_PTR(rbtitle)); } Check_Type(rbmessage, T_STRING); if ((!NIL_P(rbmessage)) && (RSTRING_LEN(rbmessage) > 0)) { message = self_t->message = strdup(RSTRING_PTR(rbmessage)); } Check_Type(rbpath, T_STRING); if ((!NIL_P(rbpath)) && (RSTRING_LEN(rbpath) > 0)) { path = self_t->icon_path =strdup(RSTRING_PTR(rbpath)); } if (path == NULL || message == NULL || title == NULL) { rb_raise(rb_eArgError, "Bad arguments to systray"); } // call the native widget shoes_native_systray(title, message, path); return Qnil; }
SHOES_CONTROL_REF shoes_native_check(VALUE self, shoes_canvas *canvas, shoes_place *place, VALUE attr, char *msg) { SHOES_CONTROL_REF ref = gtk_check_button_new(); // set visual state before connecting signal if (RTEST(ATTR(attr, checked))) { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ref), TRUE); } if (!NIL_P(shoes_hash_get(attr, rb_intern("checked")))) { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ref), shoes_hash_get(attr, rb_intern("checked")) == Qtrue); } if (!NIL_P(shoes_hash_get(attr, rb_intern("tooltip")))) { gtk_widget_set_tooltip_text(GTK_WIDGET(ref), RSTRING_PTR(shoes_hash_get(attr, rb_intern("tooltip")))); } g_signal_connect(G_OBJECT(ref), "clicked", G_CALLBACK(shoes_button_gtk_clicked), (gpointer)self); return ref; }
VALUE shoes_canvas_shoesevent(int argc, VALUE *argv, VALUE self) { VALUE ev = Qnil; SETUP_CANVAS(); // Parse the hash args VALUE hsh = argv[0]; VALUE typeq = shoes_hash_get(hsh, rb_intern("type")); ID type; if (TYPE(typeq) == T_SYMBOL) { type = SYM2ID(typeq); } else { type = rb_intern(RSTRING_PTR(typeq)); } //if (type == s_click) // fprintf(stderr, "made a s_click\n"); VALUE obj = Qnil; int x = NUM2INT(shoes_hash_get(hsh, rb_intern("x"))); int y = NUM2INT(shoes_hash_get(hsh, rb_intern("y"))); int btn = NUM2INT(shoes_hash_get(hsh, rb_intern("button"))); ev = shoes_event_new(cShoesEvent,type,obj,x,y,btn,Qnil,Qnil); return ev; }
SHOES_CONTROL_REF shoes_native_edit_box(VALUE self, shoes_canvas *canvas, shoes_place *place, VALUE attr, char *msg) { GtkTextBuffer *buffer; GtkWidget* textview = gtk_text_view_new(); SHOES_CONTROL_REF ref = gtk_scrolled_window_alt_new(NULL, NULL, place->w, place->h); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(textview), GTK_WRAP_WORD); buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)); gtk_text_buffer_set_text(buffer, _(msg), -1); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(ref), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(ref), GTK_SHADOW_IN); gtk_container_add(GTK_CONTAINER(ref), textview); // change font and color/stroke shoes_css_apply((GtkWidget*)textview, attr, css_template); if (!NIL_P(shoes_hash_get(attr, rb_intern("tooltip")))) { gtk_widget_set_tooltip_text(GTK_WIDGET(ref), RSTRING_PTR(shoes_hash_get(attr, rb_intern("tooltip")))); } g_signal_connect(G_OBJECT(buffer), "changed", G_CALLBACK(shoes_widget_changed), (gpointer)self); return ref; }
// initialize the default colors. Yes it could be a chart option. TODO ? void shoes_plot_util_default_colors(shoes_plot *plot) { rb_ary_store(plot->default_colors, 0, shoes_hash_get(cColors, rb_intern("blue"))); rb_ary_store(plot->default_colors, 1, shoes_hash_get(cColors, rb_intern("red"))); rb_ary_store(plot->default_colors, 2, shoes_hash_get(cColors, rb_intern("green"))); rb_ary_store(plot->default_colors, 3, shoes_hash_get(cColors, rb_intern("coral"))); rb_ary_store(plot->default_colors, 4, shoes_hash_get(cColors, rb_intern("purple"))); rb_ary_store(plot->default_colors, 5, shoes_hash_get(cColors, rb_intern("orange"))); rb_ary_store(plot->default_colors, 6, shoes_hash_get(cColors, rb_intern("aqua"))); rb_ary_store(plot->default_colors, 7, shoes_hash_get(cColors, rb_intern("brown"))); rb_ary_store(plot->default_colors, 8, shoes_hash_get(cColors, rb_intern("darkolive"))); rb_ary_store(plot->default_colors, 9, shoes_hash_get(cColors, rb_intern("hotpink"))); rb_ary_store(plot->default_colors, 10, shoes_hash_get(cColors, rb_intern("lightsky"))); rb_ary_store(plot->default_colors, 11, shoes_hash_get(cColors, rb_intern("greenyellow"))); rb_ary_store(plot->default_colors, 12, shoes_hash_get(cColors, rb_intern("gray"))); rb_ary_store(plot->default_colors, 13, shoes_hash_get(cColors, rb_intern("black"))); }
char * shoes_hash_cstr(VALUE hsh, ID key, char *dn) { VALUE v = shoes_hash_get(hsh, key); if (!NIL_P(v)) return RSTRING_PTR(v); return dn; }
double shoes_hash_dbl(VALUE hsh, ID key, double dn) { VALUE v = shoes_hash_get(hsh, key); if (!NIL_P(v)) return NUM2DBL(v); return dn; }
int shoes_hash_int(VALUE hsh, ID key, int dn) { VALUE v = shoes_hash_get(hsh, key); if (!NIL_P(v)) return NUM2INT(v); return dn; }