优化菜单按钮响应代码,由网友提供:https://aarbbs.com/198.html#comment-104

This commit is contained in:
一二三 2024-09-17 22:47:28 +08:00
parent efc8e21f46
commit 5c49d2ecc8

View File

@ -264,86 +264,53 @@ class TeMenu{
};
this.init();
};
setCommandFunc = function(side, idx, func){
select(side) {
case 0 {
if (idx > 0 and idx <= #this.toolbars_left) {
var ctrl = winform['plus_left'+idx];
winform['plus_left'+idx].oncommand = func(ctrl);
}
else {
return false;
}
}
case 1 {
if (idx > 0 and idx <= #this.toolbars_right) {
var ctrl = winform['plus_right'+idx];
winform['plus_right'+idx].oncommand = func(ctrl);
}
else {
return false;
}
}
else {
return false;
}
}
};
setRightClickFunc = function(side, idx, func){
select(side) {
case 0 {
if (idx > 0 and idx <= #this.toolbars_left) {
var ctrl = winform['plus_left'+idx];
winform['plus_left'+idx].wndproc = function(hwnd,message,wParam,lParam){
if (message == 0x205/*_WM_RBUTTONUP*/) {
func(ctrl);
}
}
}
else {
return false;
}
}
case 1 {
if (idx > 0 and idx <= #this.toolbars_right) {
var ctrl = winform['plus_right'+idx];
winform['plus_right'+idx].wndproc = function(hwnd,message,wParam,lParam){
if (message == 0x205/*_WM_RBUTTONUP*/) {
func(ctrl);
}
}
}
else {
return false;
}
}
else {
return false;
}
}
}
disabled = function(side, idx, status){
select(side) {
case 0 {
if (idx > 0 and idx <= #this.toolbars_left) {
winform['plus_left'+idx].disabled = status;
}
else {
return false;
}
}
case 1 {
if (idx > 0 and idx <= #this.toolbars_right) {
winform['plus_right'+idx].disabled = status;
}
else {
return false;
}
}
else {
return false;
}
}
};
getSid = function(side, idx) {
var std = {};
if (side == 0) {
std.sd = "plus_left";
std.n = #this.toolbars_left;
} else {
std.sd = "plus_right";
std.n = #this.toolbars_right;
}
if (idx > 0 && idx <= std.n) {
std.ctrl = winform[std.sd ++ idx];
return std;
}
return;
}
setCommandFunc = function(side, idx, func) {
var std = this.getSid(side, idx);
if (std) {
std.ctrl.oncommand = func(std.ctrl);
} else {
return;
}
}
setRightClickFunc = function(side, idx, func) {
var std = this.getSid(side, idx);
if (std) {
std.ctrl.wndproc = function(hwnd, message, wParam, lParam) {
if (message == 0x205 /*_WM_RBUTTONUP*/) {
func(std.ctrl);
}
}
} else {
return;
}
}
disabled = function(side, idx, status) {
var std = this.getSid(side, idx);
if (std) {
std.ctrl.disabled = status;
} else {
return;
}
}
}