Update gtk.js

This commit is contained in:
Namhyeon Go 2020-10-27 10:45:04 +09:00
parent 4c804833cb
commit 4f2d5d9466

View File

@ -9,7 +9,13 @@ var binPath = "bin\\gtk-server.exe";
// start GTKServer
var GTKServer = SHELL.createExecObject([binPath, "-stdin"]);
// Common (Elements)
// Common (Event)
var GTKEvent = function(eventName) {
this.eventName = eventName;
this.target = null;
};
// Common (Widgets)
var GTKWidgets = {};
// Common (Element)
@ -17,41 +23,32 @@ var GTKWidget = function() {
this.widgetType = "GTKWidget";
this.widgetID = GTKCreateWidget(this);
this.eventListener = GTKEventListener(this);
this.addEventListener = function(ev, fn) {
this.dispatchEvent = function(event) {
event.target = this;
if(event.eventName in this) {
this['on' + event.eventName](event);
}
};
this.addEventListener = function(eventName, fn) {
if (typeof(fn) == "function") {
this['on' + ev] = fn;
this['on' + eventName] = fn;
} else {
throw new TypeError("EventListener must be a function");
}
};
GTKWidgets[this.widgetID] = this;
GTKEventListener(this);
};
// definedEvents
var definedEvents = {
"Window" [
"onload"
],
"Table": [
"onload"
],
"Button": [
"onload",
"onclick"
],
"Entry": [
"onload",
"onkeyup"
]
"RadioBox": [
"onload",
"onclick"
],
"TextBox" [
"onload"
]
"Window" ["load"],
"Table": ["load"],
"Button": ["load", "click"],
"Entry": ["load", "keyup"]
"RadioBox": ["load", "click"],
"TextBox" ["load"]
};
// GTKEventListener
@ -60,9 +57,8 @@ var GTKEventListener = function(widget) {
var widgetEvents = definedEvents[widget.widgetType];
for (var i = 0; i < widgetEvents.length; i++) {
var eventName = widgetEvents[i];
if (eventName in widget && typeof(widget[eventName]) == "function") {
widget[eventName]();
}
var event = new GTKEvent(eventName);
widget.dispatchEvent(event);
}
}
};