Search code examples
iup

IUP matrix "Full row select"


By trying to use IUP matrix I find it's usage very intuitive and it work surprisingly fast even on weak computer. So I see that I can get from that control most of I need. But, since IUP has very original way of setting properties I can't get that matrix behaves like common multicolumn list or MS listview.

This is how I format it:

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

IupSetAttribute(mat, "READONLY", "YES");
IupSetAttribute(mat, "HIDEFOCUS", "YES");
IupSetAttribute(mat, "FRAMECOLOR", "220 220 220");
IupSetAttribute(mat, "NUMCOL", "5");
IupSetAttribute(mat, "NUMCOL_VISIBLE", "5");
IupSetAttribute(mat, "NUMLIN", "30");
IupSetAttribute(mat, "NUMLIN_VISIBLE", "30");
IupSetAttribute(mat, "RESIZEMATRIX", "YES");
IupSetAttribute(mat, "MARKMODE", "LIN");
IupSetAttribute(mat, "MARKAREA", "CONTINUOUS");
IupSetAttribute(mat, "MULTIPLE", "NO");
IupSetAttribute(mat, "BORDER", "NO");
IupSetAttribute(mat, "CURSOR", "ARROW");
IupSetAttribute(mat, "ALIGNMENT", "ARIGHT");
IupSetAttribute(mat, "ALIGNMENT1", "ALEFT");
IupSetAttribute(mat, "ALIGNMENT5", "ACENTER");
//
IupSetAttribute(mat, "WIDTH0", "30");
IupSetAttribute(mat, "WIDTH1", "150");
IupSetAttribute(mat, "WIDTH2", "50");
IupSetAttribute(mat, "WIDTH3", "50");
IupSetAttribute(mat, "WIDTH4", "50");
//
IupSetAttribute(mat, "0:0", "Row H");
IupSetAttribute(mat, "0:1", "Col1");
IupSetAttribute(mat, "0:2", "Col2");
IupSetAttribute(mat, "0:3", "Col3");
IupSetAttribute(mat, "0:4", "Col4");
IupSetAttribute(mat, "0:5", "Col5");
//
IupSetCallback(mat, "CLICK_CB", (Icallback)click);
IupSetCallback(mat, "LEAVEITEM_CB", (Icallback)leave);
IupSetCallback(mat, "ENTERITEM_CB", (Icallback)enter);
IupSetCallback(mat, "WHEEL_CB", (Icallback)wheel);

return mat;
}

All properties and events with callbacks work as expected. Since I have a bit specific way of using/managing data it is needed that when click to any cell full row becames selected or when I change position by keyboard also.

I would also like to be able to select full row with code like it selects by clicking to row header.
Besides a click (which I catch as expected), how to check doubleclick on matrix?

And finally, not most important but it will be good to know if here exists a way to get selected line in system color (mostly blue) instead of gray?

How to easiest achieve that functionality?
(Windows7/64)


Solution

  • The simplest form to select the row the way you want is to use the ENTERITEM_CB callback:

    static int enteritem_cb(Ihandle *ih, int lin, int col)
    {
      IupSetAttribute(ih,"MARKED", NULL);  /* clear all marks */
      IupMatSetAttribute(ih,"MARK", lin, 0, "Yes");
      IupSetfAttribute(ih,"REDRAW", "L%d", lin);
      return IUP_DEFAULT;
    }
    

    There is currently no way to change the selected line color. Actually because it is not a specific color. The marked cells are drawn with an attenuation at the foreground and background colors.