Mercurial > repos > rhope
view syl_generic.cpp @ 121:1af91ceaaf49
Fixed memory leak when an output is only attached to a single null input
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 28 Oct 2010 21:04:12 -0400 |
parents | 76568becd6d6 |
children |
line wrap: on
line source
#include "syl_generic.h" #include "interp.h" #include "debugmacros.h" #include <gui/window.h> #include "syl_window.h" datum * get_callback(datum * handler_dict, char * name, worker_instance * instance) { queue_entry entry; datum * params[2]; params[0] = add_ref( handler_dict ); params[1] = make_string(name, -1, instance->def->prog); entry.instance = instance; vis_dict_index(params, &entry); if(params[1]) release_ref(params[1]); return params[0]; } void GenericView::SetCallbacks() { this->paint_worker = get_callback(this->handler_dict, "draw", instance); this->mousemove_worker = get_callback(this->handler_dict, "mousemove", instance); this->mousedown_worker = get_callback(this->handler_dict, "mousedown", instance); this->mouseup_worker = get_callback(this->handler_dict, "mouseup", instance); } void GenericView::ResetCallbacks() { release_ref(this->paint_worker); release_ref(this->mousemove_worker); release_ref(this->mousedown_worker); release_ref(this->mouseup_worker); SetCallbacks(); } GenericView::GenericView(const os::Rect& cFrame, const os::String& cTitle, datum * widget_datum, worker_instance * instance) : os::View(cFrame, cTitle/*, os::CF_FOLLOW_LEFT | os::CF_FOLLOW_TOP, os::WID_WILL_DRAW | os::WID_CLEAR_BACKGROUND | os::WID_TRANSPARENT*/) { datum * handler_dict; this->widget_datum = widget_datum; this->instance = instance; this->handler_dict = ((vis_widget *)(widget_datum->c.generic.data))->handler_dict; SetCallbacks(); } void GenericView::DoCallback(datum * worker, const os::Rect& rect, datum ** extra_params, int num_extra) { queue_entry entry; generic_view_datum * view; entry.instance = this->instance; datum * params[32]; datum * list; DEBUGPRINTF("program: %X\n", this->instance->def->prog); params[0] = create_list(this->instance->def->prog); params[1] = new_datum(BUILTIN_TYPE_SCREEN_CUSTOM, 1, sizeof(generic_view_datum), this->instance->def->prog); DEBUGPUTS("Datum created\n"); DEBUGPRINTF("screen custom widget company name: %s\n", params[1]->company->name); view = (generic_view_datum *)(params[1]->c.generic.data); view->view = this; view->update_rect = rect; vis_list_append(params, &entry); for(int i = 0; i < num_extra; ++i) { params[1] = extra_params[i]; vis_list_append(params, &entry); } list = params[0]; worker_populate_inputs(worker, list, params); release_ref(list); DEBUGPUTS("Calling execute_def_wait\n"); execute_def_wait(((worker_datum *)(worker->c.generic.data))->def, params); } void GenericView::Paint(const os::Rect& cUpdateRect) { //DEBUGPUTS("GenericView::Paint\n"); //queue_entry entry; //generic_view_datum * view; if(this->paint_worker) { DoCallback(this->paint_worker, cUpdateRect, NULL, 0); /*entry.instance = this->instance; datum * params[32]; datum * list; DEBUGPRINTF("program: %X\n", this->instance->def->prog); params[0] = create_list(this->instance->def->prog); params[1] = new_datum(BUILTIN_TYPE_SCREEN_CUSTOM, 1, sizeof(generic_view_datum), this->instance->def->prog); DEBUGPUTS("Datum created\n"); DEBUGPRINTF("screen custom widget company name: %s\n", params[1]->company->name); view = (generic_view_datum *)(params[1]->c.generic.data); view->view = this; view->update_rect = cUpdateRect; vis_list_append(params, &entry); list = params[0]; worker_populate_inputs(this->paint_worker, list, params); release_ref(list); DEBUGPUTS("Calling execute_def_wait\n"); execute_def_wait(((worker_datum *)(this->paint_worker->c.generic.data))->def, params); //params[0] = add_ref(this->paint_worker); //if(vis_worker_do(params, &entry) == 0) // release_ref(params[0]);*/ } else os::View::Paint(cUpdateRect); } void GenericView::DefaultPaint(const os::Rect& cUpdateRect) { os::View::Paint(cUpdateRect); } void GenericView::MouseMove( const os::Point& newPos, int code, uint32 buttons, os::Message* msg) { datum * params[2]; if(this->mousemove_worker) { params[0] = new_datum(BUILTIN_TYPE_REAL, 3, 0, this->instance->def->prog); params[0]->c.real = newPos.x; params[1] = new_datum(BUILTIN_TYPE_REAL, 3, 0, this->instance->def->prog); params[1]->c.real = newPos.y; DoCallback(this->mousemove_worker, os::Rect(0,0,0,0), params, 2); } } void GenericView::MouseDown( const os::Point& pos, uint32 buttons) { datum * params[3]; if(this->mousedown_worker) { DEBUGPRINTF("Mouse down worker: %X\n", this->mousedown_worker); params[0] = new_datum(BUILTIN_TYPE_REAL, 3, 0, this->instance->def->prog); params[0]->c.real = pos.x; params[1] = new_datum(BUILTIN_TYPE_REAL, 3, 0, this->instance->def->prog); params[1]->c.real = pos.y; params[2] = new_datum(BUILTIN_TYPE_WHOLE, 2, 0, this->instance->def->prog); params[2]->c.integers.num_a = buttons; DoCallback(this->mousedown_worker, os::Rect(0,0,0,0), params, 3); } } void GenericView::MouseUp( const os::Point& pos, uint32 buttons, os::Message* msg) { datum * params[3]; if(this->mouseup_worker) { params[0] = new_datum(BUILTIN_TYPE_REAL, 3, 0, this->instance->def->prog); params[0]->c.real = pos.x; params[1] = new_datum(BUILTIN_TYPE_REAL, 3, 0, this->instance->def->prog); params[1]->c.real = pos.y; params[2] = new_datum(BUILTIN_TYPE_WHOLE, 2, 0, this->instance->def->prog); params[2]->c.integers.num_a = buttons; DoCallback(this->mouseup_worker, os::Rect(0,0,0,0), params, 3); } } /* void GenericView::MakeFocus(bool give_focus) { os_window * parent_wind = (os_window *)GetWindow(); if(parent_wind) if(give_focus) parent_wind->SetFocusNoHandler(this) else if(parent_wind->GetFocusChild() == this) parent_wind->SetFocusNoHandler(NULL); } */ extern "C" { int vis_screen_custom_defaultpaint(datum ** params, queue_entry * entry) { generic_view_datum * view = (generic_view_datum *)(params[0]->c.generic.data); DEBUGPUTS("Calling Genericview::DefaultPaint\n"); view->view->DefaultPaint(view->update_rect); DEBUGPUTS("Genericview::DefaultPaint returned\n"); return 0; } int vis_screen_custom_drawline(datum ** params, queue_entry * entry) { DEBUGPRINTF("Draw line from %f,%f to %f,%f\n", params[1]->c.real,params[2]->c.real, params[3]->c.real,params[4]->c.real); generic_view_datum * view = (generic_view_datum *)(params[0]->c.generic.data); view->view->DrawLine(os::Point(params[1]->c.real,params[2]->c.real), os::Point(params[3]->c.real,params[4]->c.real)); DEBUGPUTS("finished calling DrawLine()\n"); release_ref(params[1]); release_ref(params[2]); release_ref(params[3]); release_ref(params[4]); return 0; } int vis_screen_custom_drawstring(datum ** params, queue_entry * entry) { generic_view_datum * view = (generic_view_datum *)(params[0]->c.generic.data); view->view->DrawString(os::Point(params[2]->c.real, params[3]->c.real), ((char *)(params[1]->c.generic.data))); release_ref(params[1]); release_ref(params[2]); release_ref(params[3]); return 0; } int vis_screen_custom_setdrawcolor(datum ** params, queue_entry * entry) { generic_view_datum * view = (generic_view_datum *)(params[0]->c.generic.data); view->view->SetFgColor(params[1]->c.integers.num_a, params[2]->c.integers.num_a, params[3]->c.integers.num_a, params[4]->c.integers.num_a); release_ref(params[1]); release_ref(params[2]); release_ref(params[3]); release_ref(params[4]); return 0; } int vis_screen_custom_moveby(datum ** params, queue_entry * entry) { generic_view_datum * view = (generic_view_datum *)(params[0]->c.generic.data); view->view->MoveBy(os::Point(params[1]->c.real, params[2]->c.real)); view->view->Flush(); release_ref(params[1]); release_ref(params[2]); return 0; } int vis_screen_custom_sethandler(datum ** params, queue_entry * entry) { datum * screen_datum; generic_view_datum * view = (generic_view_datum *)(params[0]->c.generic.data); screen_datum = params[0]; params[0] = view->view->handler_dict; vis_dict_set(params, entry); view->view->handler_dict = params[0]; params[0] = screen_datum; view->view->ResetCallbacks(); return 0; } int vis_screen_custom_removehandler(datum ** params, queue_entry * entry) { datum * screen_datum; generic_view_datum * view = (generic_view_datum *)(params[0]->c.generic.data); screen_datum = params[0]; params[0] = view->view->handler_dict; vis_dict_remove(params, entry); view->view->handler_dict = params[0]; params[0] = screen_datum; view->view->ResetCallbacks(); return 0; } int vis_screen_custom_givefocus(datum ** params, queue_entry * entry) { os::Window * wind; generic_view_datum * view = (generic_view_datum *)(params[0]->c.generic.data); wind = view->view->GetWindow(); if(wind) wind->Unlock(); view->view->MakeFocus(params[1]->c.integers.num_a); if(wind) wind->Lock(); release_ref(params[1]); return 0; } int vis_screen_custom_addwidget(datum ** params, queue_entry * entry) { generic_view_datum * view = (generic_view_datum *)(params[0]->c.generic.data); os_window * wind = (os_window *)(view->view->GetWindow()); //printf("Locking window: %X\n", wind); wind->Unlock(); puts("Adding widget"); add_widget_shared((vis_window_shown *)(wind->vis_wind->c.generic.data), params[2], (char *)(params[1]->c.generic.data), params[3]->c.real, params[4]->c.real, entry, view->view); puts("Unlocking window"); wind->Lock(); puts("Releasing refs"); release_ref(params[1]); release_ref(params[2]); release_ref(params[3]); release_ref(params[4]); return 0; } int vis_screen_custom_getwindow(datum ** params, queue_entry * entry) { generic_view_datum * view = (generic_view_datum *)(params[0]->c.generic.data); os_window * wind = (os_window *)(view->view->GetWindow()); release_ref(params[0]); params[0] = add_ref(wind->vis_wind); return 0; } }