Getting parent object information in the GUI
Posted: Sun Nov 23, 2025 2:40 am
The lack of parent object information for gadgets is really frustrating. For instance, having functions like:
GetGadgetParent(#Gadget)
GetGadgetParentType(#Gadget)
This additional data would greatly help in developing extra features. Right now, I have to hook into some functions to track and log parent information.
I'm forced to do it this way:
GetGadgetParent(#Gadget)
GetGadgetParentType(#Gadget)
This additional data would greatly help in developing extra features. Right now, I have to hook into some functions to track and log parent information.
I'm forced to do it this way:
Code: Select all
// Description : Parent Tracking Helper Library
// Author .....: Webarion
// Version ....: 1.0
// parentStack - stack to track container nesting
// {id:-1,type:-1} - parent desktop
// {id:id,type:0} - parent window
// {id:id,type:1} - parent gadget
spider.webarion = {
parentStack: [{id: -1, type: -1}],
};
// === INTERCEPTION OPENWINDOW ===
var orig_OpenWindow = spider_OpenWindow;
spider_OpenWindow = function(id, x, y, width, height, title, flags, parent) {
// immediately call the original function and get its result
var result = orig_OpenWindow.call(this, id, x, y, width, height, title, flags, parent);
// Set this window as the current parent
if (result && typeof result === 'object') {
spider.webarion.parentStack = [{id: result.id, type: 0}];
} else {
spider.webarion.parentStack = [{id: result, type: 0}];
}
return result;
};
// === INTERCEPTION OF REGISTER (CREATION OF GADGETS) ===
var orig_Register = spider.gadget.register;
spider.gadget.register = function(g, t, d, dj) {
// call the original
var result = orig_Register.call(this, g, t, d, dj);
// Registering the parent for the gadget
g.parentInfo = spider.webarion.parentStack.at(-1);
// If this is a container gadget, make it the current container
if (t == 11 || t == 16 || t == 28 || t == 33) {
spider.webarion.parentStack.push({id: g.id, type: 1});
}
return result;
};
// === INTERCEPTION OPENGADGETLIST ===
var orig_OpenGadgetList = spider_OpenGadgetList;
spider_OpenGadgetList = function(gadgetId, flags) {
// call the original
orig_OpenGadgetList.call(this, gadgetId, flags);
// Save the current container to the stack and install a new one
spider.webarion.parentStack.push({id: gadgetId, type: 1});
};
// === INTERCEPTION CLOSEGADGETLIST ===
var orig_CloseGadgetList = spider_CloseGadgetList;
spider_CloseGadgetList = function() {
orig_CloseGadgetList.call(this);
// Remove the current parent from the stack
spider.webarion.parentStack.pop();
};
// === INTERCEPTION USEGADGETLIST ===
var orig_UseGadgetList = spider_UseGadgetList;
spider_UseGadgetList = function(window) {
spider.webarion.parentStack = [{id: window.id, type: 0}];
return orig_UseGadgetList.call(this, window);
};
// Intercepting FreeGadget is not implemented.
// --------------------------------------------------------------
function spider_GetGadgetParent(gadget) {
return spider.gadget.objects.Get(gadget).parentInfo.id;
}
function spider_GetGadgetParentType(gadget) {
return spider.gadget.objects.Get(gadget).parentInfo.type;
}