Search code examples
iup

IUP matrix refresh


I am trying to use IUP matrix from C like I uses DataGrid from VB.
Till now I come to this:

int refreshl(Ihandle *mat, int from)  
{  
struct lotstruct lot;   

FILE *fol;
fol = fopen("C:/myfolder/myfile", "rb+");

int b;
int temp = 1;
for (b=from; b<(from+31); b++)
{
    int rec = sizeof(lot) * (b - 1);
    fseek(fol, rec, SEEK_SET);

    int fr;
    fr = fread(&lot, sizeof(lot), 1, fol);
    //------------------------------------
    char k1[36] = {0};
    strncpy(k1, lot.str1, 35);
    char* tp = ibm852_to_cp1250(k1);

    char row[6] = {0};
    sprintf(row, "%d", temp);
    char* ro = ibm852_to_cp1250(row);

    char cel1[10] = {0};
    sprintf(cel1, "%d%s", temp, ":0");
    IupSetAttribute(mat, cel1, ro);

    char cel2[10] = {0};
    sprintf(cel2, "%d%s", temp, ":1");
    IupSetAttribute(mat, cel2, tp);
    temp += 1;
}
fclose(fol);
IupSetAttribute(mat, "REDRAW", "ALL");

return 0;
}

With this I read data from binary file and I can see data on console. But mytrix don't refreshes by changing data. Data is changet by k_any + case K_DOWN function by increasing "from" integer.
So I call "REDRAW" "ALL" but also without result, starting data stays in matrix.

Since I am total beginner please answer to few questions.

1) Is this good idea to use IUP matrix like common windows Grid?
2) How to invoke refresh matrix to change data in it without loosing speed?
3) Can IUP work with UTF-8 strings on windows like gtk can? (I try but without results).


Solution

  • 1) Is this good idea to use IUP matrix like common windows Grid?

    Yes. IupMatrix is exactly for that.

    2) How to invoke refresh matrix to change data in it without loosing speed?

    Your code is correct. Maybe you are updating the wrong cell in the IupMatrix. L=0 or C=0 are title cells, and exist if certain conditions are true. Maybe what you want is to set L=1 or C=1.

    A suggestion, instead of this:

    char row[6] = {0};
    sprintf(row, "%d", temp);
    char* ro = ibm852_to_cp1250(row);
    char cel1[10] = {0};
    sprintf(cel1, "%d%s", temp, ":0");
    IupSetAttribute(mat, cel1, ro);
    

    Try this:

    IupMatSetfAttribute(mat, "", temp, 0, "%d", temp);
    

    and IupMatStoreAttribute(mat, "", temp, 1, tp);

    You only need the string conversion for the second part.

    Also, have you checked the temp variable if it has a valid index?

    3) Can IUP work with UTF-8 strings on windows like gtk can? (I try but without results).

    Not yet. It will be in a (near) future version.