static int iMatrixExUndoDataSwap(ImatExData* matex_data, IundoData* undo_data) { char* id = iupTableFirst(undo_data->data_table); while (id) { char *value, *old_value; int lin=1, col=1; iupStrToIntInt(id, &lin, &col, ':'); value = (char*)iupTableGetCurr(undo_data->data_table); old_value = iupStrDup(iupMatrixExGetCellValue(matex_data->ih, lin, col, 0)); /* get internal value */ iupMatrixExSetCellValue(matex_data->ih, lin, col, value); if (!old_value) iupTableSetCurr(undo_data->data_table, (void*)"", IUPTABLE_POINTER); else { iupTableSetCurr(undo_data->data_table, (void*)old_value, IUPTABLE_STRING); free(old_value); } if (!iupMatrixExBusyInc(matex_data)) return 0; id = iupTableNext(undo_data->data_table); } return 1; }
static void iMatrixExArrayAddCell(ImatExData* matex_data, Iarray* data, int lin, int col) { char* value = iupMatrixExGetCellValue(matex_data->ih, lin, col, 1); /* get displayed value */ if (value) iMatrixExArrayAddStr(data, value); else iMatrixExArrayAddEmpty(data); }
static void iMatrixExCopyTXT(Ihandle *ih, FILE* file, int num_lin, int num_col, int skip_lin, int skip_col) { ImatExData* matex_data = (ImatExData*)iupAttribGet(ih, "_IUP_MATEX_DATA"); int lin, col; int add_sep; char* str, sep; sep = *(iupAttribGetStr(ih, "TEXTSEPARATOR")); str = iupAttribGetStr(ih, "COPYCAPTION"); if (str) fprintf(file,"%s\n",str); /* Here includes the title cells */ for (lin = 0; lin <= num_lin; ++lin) { add_sep = 0; if (iupMatrixExIsLineVisible(ih, lin)) { for (col = 0; col <= num_col; ++col) { if (iupMatrixExIsColumnVisible(ih, col)) { if (add_sep) fprintf(file, "%c", sep); str = iupMatrixExGetCellValue(matex_data->ih, lin, col, 1); /* get displayed value */ if (str) { if (strchr(str, sep)) fprintf(file, "\"%s\"", str); else fprintf(file, "%s", str); } else fprintf(file, "%s", " "); add_sep = 1; } if (col == 0) col += skip_col; } fprintf(file, "%s", "\n"); } if (lin == 0) lin += skip_lin; } }
static void iMatrixExCopyLaTeX(Ihandle *ih, FILE* file, int num_lin, int num_col, char* buffer, int skip_lin, int skip_col) { ImatExData* matex_data = (ImatExData*)iupAttribGet(ih, "_IUP_MATEX_DATA"); int lin, col; int add_sep; char* str; fprintf(file,"%% File automatically generated by IUP\n"); fprintf(file,"\\begin{table}\n"); fprintf(file,"\\begin{center}\n"); fprintf(file,"\\begin{tabular}{"); for (col = 0; col <= num_col; ++col) { if (iupMatrixExIsColumnVisible(ih, col)) fprintf(file,"|r"); if (col == 0) col += skip_col; } fprintf(file,"|} \\hline\n"); /* Here includes the title cells */ for (lin = 0; lin <= num_lin; ++lin) { add_sep = 0; if (iupMatrixExIsLineVisible(ih, lin)) { int is_bold = iMatrixExIsBoldLine(ih, lin); for (col = 0; col <= num_col; ++col) { if (iupMatrixExIsColumnVisible(ih, col)) { if (add_sep) fprintf(file,"& "); if (is_bold) fprintf(file,"\\bf{"); str = iupMatrixExGetCellValue(matex_data->ih, lin, col, 1); /* get displayed value */ if (str) { iMatrixExStrCopyNoSepLaTeX(buffer, str); fprintf(file, "%s", buffer); } else fprintf(file, "%s", " "); if (is_bold) fprintf(file,"}"); add_sep = 1; } if (col == 0) col += skip_col; } fprintf(file,"\\\\ \\hline\n"); } if (lin == 0) lin += skip_lin; } fprintf(file,"\\end{tabular}\n"); str = iupAttribGetStr(ih, "COPYCAPTION"); if (str) fprintf(file,"\\caption{%s.}\n", str); str = iupAttribGetStr(ih, "LATEXLABEL"); if (str) fprintf(file,"\\label{tab:%s}\n", str); fprintf(file,"\\end{center}\n"); fprintf(file,"\\end{table}\n"); }
static void iMatrixExCopyHTML(Ihandle *ih, FILE* file, int num_lin, int num_col, char* buffer, int skip_lin, int skip_col) { ImatExData* matex_data = (ImatExData*)iupAttribGet(ih, "_IUP_MATEX_DATA"); int lin, col; char* str, *caption, f[512]; int add_format = iupAttribGetInt(ih, "HTMLADDFORMAT"); char* table = iupAttribGetStr(ih, "HTML<TABLE>"); char* tr = iupAttribGetStr(ih, "HTML<TR>"); char* th = iupAttribGetStr(ih, "HTML<TH>"); char* td = iupAttribGetStr(ih, "HTML<TD>"); caption = iupAttribGetStr(ih, "HTML<CAPTION>"); if (!table) table = ""; if (!tr) tr = ""; if (!th) th = ""; if (!td) td = ""; if (!caption) caption = ""; fprintf(file,"<!-- File automatically generated by IUP -->\n"); fprintf(file,"<TABLE%s>\n", table); str = iupAttribGetStr(ih, "COPYCAPTION"); if (str) fprintf(file,"<CAPTION%s>%s</CAPTION>\n", caption, str); /* Here includes the title cells */ for (lin = 0; lin <= num_lin; ++lin) { if (iupMatrixExIsLineVisible(ih, lin)) { fprintf(file,"<TR%s> ", tr); for (col = 0; col <= num_col; ++col) { if (iupMatrixExIsColumnVisible(ih, col)) { if (lin==0||col==0) fprintf(file,"<TH%s%s>", th, add_format? iMatrixExGetCellFormat(ih, lin, col, f): ""); else fprintf(file,"<TD%s%s>", td, add_format? iMatrixExGetCellFormat(ih, lin, col, f): ""); str = iupMatrixExGetCellValue(matex_data->ih, lin, col, 1); /* get displayed value */ if (str) { iMatrixExStrCopyNoSepHTML(buffer, str); fprintf(file, "%s", buffer); } else fprintf(file, "%s", " "); if (lin==0||col==0) fprintf(file,"</TH> "); else fprintf(file,"</TD> "); } if (col == 0) col += skip_col; } fprintf(file,"</TR>\n"); } if (lin == 0) lin += skip_lin; } fprintf(file,"</TABLE>\n"); }