0

我对 IUP 事件系统的理解有基本的困惑。现在我说的是矩阵。

这是它的创建方式:

Ihandle *create_mat(void)
{
mat = IupMatrix(NULL);

IupSetAttribute(mat, "READONLY", "YES");
IupSetCallback(mat, "CLICK_CB", (Icallback)click);
IupSetCallback(mat, "BUTTON_CB", (Icallback)button);
return mat;
}

以下是回调:

int click(Ihandle *mat, int lin, int col)
{
char* value = IupMatGetAttribute(mat, "", lin, col);
if (!value) value = "NULL";
printf("click_cb(%d, %d)\n", lin, col);
return IUP_DEFAULT;
}

int button(Ihandle *mat, int button, int pressed, int x, int y, char* status)
{
printf("button %d, %d, %d, %d %s\n", button, pressed, x, y, status);
return IUP_DEFAULT;
}

问题在于我需要激活两个回调,但在显示的情况下 CLICK 事件没有被触发。
如果我禁用 BUTTON_CB 则触发 CLICK 事件。但我需要两者,点击,左键双击,右键释放等......

这是 BUTTON_CB 排除 CLICK_CB 的正常行为还是我做错了什么?

实际上,如果提供 lin 和 col 的 CLICK_CB、ENTERITEM_CB 和 LEAVEITEM_CB 不可用(在所述情况下未触发),我将如何从矩阵的 BUTTON_CB 或 WHEEL_CB 处理程序中获取“lin”和“col”?

还有更多,我将如何从表单级别使用的事件处理程序中获得“活动控件”(名称、具有焦点的控件类型)?

4

2 回答 2

1

这是 BUTTON_CB 排除 CLICK_CB 的正常行为还是我做错了什么?

是的。因为 BUTTON_CB 是一个 IupCanvas 回调,而 CLICK_CB 是一个 IupMatrix 回调。请记住,IupMatrix 继承自 IupCanvas。所以在内部 IupMatrix 使用 BUTTON_CB 回调来实现几个功能。

所以在这种情况下,你需要做的是在分配一个新的回调之前保存之前的回调,然后从你自己的内部调用旧的回调。像这样的东西:

old_callback = IupGetCallback(mat, "BUTTON_CB");
IupSetCallback(mat, "BUTTON_CB", new_callback);

int new_callback(...)
{
  return old_callback(...)
}

实际上,如果提供 lin 和 col 的 CLICK_CB、ENTERITEM_CB 和 LEAVEITEM_CB 不可用(在所述情况下未触发),我将如何从矩阵的 BUTTON_CB 或 WHEEL_CB 处理程序中获取“lin”和“col”?

使用函数 pos = IupConvertXYToPos(mat, x, y) 其中 pos=lin*numcol + col。考虑到它们是整数值,计算 lin 和 col 非常简单。

还有更多,我将如何从表单级别使用的事件处理程序中获得“活动控件”(名称、具有焦点的控件类型)?

我没有完全理解你的问题。但我认为 IupGetFocus 和 IupGetClassName 可能是您想要的功能。

于 2013-04-19T12:51:16.857 回答
1

我将使用 Antonio 的建议来回答我自己的问题,以便其他对 IUP 感兴趣的人可以从这些帖子中受益。

如果我理解得很好,那不太可能,这就是我为我的矩阵制作 BUTTON_CB 处理程序的方法:

int button(Ihandle *mat, int button, int pressed, int x, int y, char* status)
{
//actually 'name' is Ihandle
//and class name is a 'type'
//in compare with other toolkits
char* name = IupGetClassName(mat);

//so since we have handle already
//we can't be here if we are not in concrete matrix
//and this comparision is not needed
if (strncmp(name, "matrix", sizeof(name)) == 0)
{
    //if left mouse button is down
    if (button == IUP_BUTTON1 && pressed == 1)
    {
        //my calculation is not 100% correct
        //but good enough for this sample
        int pos = IupConvertXYToPos(mat, x, y);
        _line = pos/numcol;
        _col = pos%numcol;

        //if is doubleclick
        if (status[5] == 'D')
        {
            //press ENTER key
            //and open another modal dialog
            //with argument 'sel'
            k_any(mat, K_CR);

            printf("Doubleclick\n");
            //say HANDLED for IUP
            //but not matter when READONLY is "YES"
            return IUP_IGNORE;
        }

        //calculate (public) sel
        //for select a clicked line
        sel = _line + from - 1;
        refreshl(from, sel);

        printf("Click\n");
        return IUP_IGNORE;
    }
}
return IUP_DEFAULT;
}

这项工作符合预期。
如果有问题,请进一步提出建议。

于 2013-04-19T22:14:18.703 回答