Skip to content

Commit

Permalink
for #363 - good enough to start work on the native side
Browse files Browse the repository at this point in the history
* have a test script
* gdb verified that shoes_systray_new is called and the c strings
  are extracted
* the icon_path will be tricky - ignore for now.
  • Loading branch information
Cecil committed Aug 2, 2017
1 parent c1673dd commit 9e3ce50
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 10 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,4 @@ req/bloopsaphone
req/json
/qtifw
*.orig
shoes/types/types.h
cshoes
10 changes: 10 additions & 0 deletions Tests/systray/note.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Shoes.app do
stack do
para "Press button and look in your systems notication area"
ctr = 0;
button "Notify" do
ctr += 1
systray title: "Notify Test", message: "message ##{ctr}"
end
end
end
53 changes: 44 additions & 9 deletions shoes/types/systray.c
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
/* systray
*/

#include "shoes/types/native.h"
#include "shoes/types/systray.h"

// ruby
VALUE cSystray

VALUE cSystray;
FUNC_M("+systray", systray, -1);

// systray
shoes_systray_init() {
cSystray = rb_define_class_under(cTypes, "Systray", cNative);
rb_define_alloc_func(cSystray, shoes_systray_alloc);
//rb_define_method(cSystray, "width", CASTHOOK(shoes_svghandle_get_width), 0);
//rb_define_method(cSystray, "height", CASTHOOK(shoes_svghandle_get_height), 0);
RUBY_M("+systray", systray, -1);
}

// canvas
VALUE shoes_canvas_systray(int argc, VALUE *argv, VALUE self) {
VALUE han;
han = shoes_systray_new(argc, argv, self);
return han;
}

void shoes_systray_mark(shoes_systray *handle) {
// we don't have any Ruby objects to mark.
}

static void shoes_systray_free(shoes_systray *handle) {
if (handle->path) free(handle->icon_path);
if (handle->data) free(handle->title);
if (handle->subid) free(handle->message);
if (handle->icon_path) free(handle->icon_path);
if (handle->title) free(handle->title);
if (handle->message) free(handle->message);
RUBY_CRITICAL(SHOE_FREE(handle));
}

Expand All @@ -25,10 +39,31 @@ VALUE shoes_systray_alloc(VALUE klass) {
shoes_systray *handle = SHOE_ALLOC(shoes_systray);
SHOE_MEMZERO(handle, shoes_systray, 1);
obj = Data_Wrap_Struct(klass, NULL, shoes_systray_free, handle);
handle->handl = NULL;
handle->subid = NULL;
handle->icon_path = NULL;
handle->title = NULL;
handle->message = NULL;
return obj;
}

VALUE shoes_systray_new(int argc, VALUE *argv, VALUE parent) {
// Get Ruby args.
VALUE rbtitle, rbmessage, rbpath;
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"));
char *title = NULL, *message = NULL, *path = NULL;

// Alloc the object and init
VALUE obj = shoes_systray_alloc(cSystray);
shoes_systray *self_t;
Data_Get_Struct(obj, shoes_systray, self_t);
if ((!NIL_P(rbtitle)) && (RSTRING_LEN(rbtitle) > 0)) {
title = strdup(RSTRING_PTR(rbtitle));
}
if ((!NIL_P(rbmessage)) && (RSTRING_LEN(rbmessage) > 0)) {
message = strdup(RSTRING_PTR(rbmessage));
}
if ((!NIL_P(rbpath)) && (RSTRING_LEN(rbpath) > 0)) {
path = strdup(RSTRING_PTR(rbpath));
} // call the native widget
}
54 changes: 54 additions & 0 deletions shoes/types/types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include "shoes/types/button.h"
#include "shoes/types/check.h"
#include "shoes/types/color.h"
#include "shoes/types/download.h"
#include "shoes/types/edit_box.h"
#include "shoes/types/edit_line.h"
#include "shoes/types/effect.h"
#include "shoes/types/image.h"
#include "shoes/types/list_box.h"
#include "shoes/types/native.h"
#include "shoes/types/pattern.h"
#include "shoes/types/plot.h"
#include "shoes/types/progress.h"
#include "shoes/types/radio.h"
#include "shoes/types/shape.h"
#include "shoes/types/slider.h"
#include "shoes/types/spinner.h"
#include "shoes/types/svg.h"
#include "shoes/types/switch.h"
#include "shoes/types/systray.h"
#include "shoes/types/text.h"
#include "shoes/types/text_link.h"
#include "shoes/types/text_view.h"
#include "shoes/types/textblock.h"
#include "shoes/types/timerbase.h"
#include "shoes/types/video.h"

#define SHOES_TYPES_INIT \
shoes_0_native_type_init(); \
shoes_button_init(); \
shoes_check_init(); \
shoes_color_init(); \
shoes_download_init(); \
shoes_edit_box_init(); \
shoes_edit_line_init(); \
shoes_effect_init(); \
shoes_image_init(); \
shoes_list_box_init(); \
shoes_pattern_init(); \
shoes_plot_init(); \
shoes_progress_init(); \
shoes_radio_init(); \
shoes_shape_init(); \
shoes_slider_init(); \
shoes_spinner_init(); \
shoes_svg_init(); \
shoes_switch_init(); \
shoes_systray_init(); \
shoes_text_init(); \
shoes_text_link_init(); \
shoes_text_view_init(); \
shoes_textblock_init(); \
shoes_timerbase_init(); \
shoes_video_init();

0 comments on commit 9e3ce50

Please sign in to comment.