IupMatrixEx
An extension library for IupMatrix. This library adds new features to the IupMatrix in order to extend the current features. Adds support for Import/Export, Clipboard, Undo/Redo, Find, Sort, Column Visibility, Numeric Columns, Numeric Units, Context Menu and others.
It can be used in callback mode or in standard more.
Based on the DMatrix library created by Bruno Kassar and Luiz Cristóvão Gomez Coelho.
Initialization and Usage
The IupControlsOpen function must be called after
IupOpen. The "iupcontrols.h" file must also be included
in the source code. The program must be linked to the controls library
(iupctrl). In Go it needs the ctrl build tag.
Creation
Ihandle* IupMatrixEx(void);
This function returns the identifier of the created editing component, or NULL if an error occurs.
Attributes
The IupMatrixEx element handles all attributes defined for a IupMatrix control.
BUSY: returns YES if the library is changing the matrix contents internally as a result of an operation such as paste or duplicate. Can be canceled setting to NO. See the BUSY_CB callback for more information.
BUSYPROGRESS: flag to display a progress dialog while data is being changed. Can be YES or NO. Default: NO.
LASTERROR (read-only): set when an error occurred during an operation. It is reset to NULL at the start of every operation that sets its value.
Import/Export and Clipboard
COPY (write-only): copies (export) the selected cells to the clipboard in TEXT format. If value is ALL then all cells are copied regardless if there is a selection. If value is MARKED then the MARKED attribute is used to define the selection. Value can also be a range of cells in the format "L1:C1-L2:C2". Title cells are not copied, even when a line or column is fully selected. If the column or line is invisible (its size=0) it is not copied. The TEXTSEPARATOR attribute can be used to define a column separator (default is tab '\t') and line separator will be line feeds ('\n').
When MARKMODE=CELLS and sparse cells are selected, there are two
options for copy according to the COPYKEEPSTRUCT
attribute, if "YES" the copied data will fit a rectangular region that
contains all the selected cells and the non selected cells inside the
region will be copied as empty spaces (' '), if "NO" only the selected
cells will be copied but they must contain a matrix consistent
structure, in other words the selected column pattern must be consistent
along lines.
LASTERROR can be set to "NOMARKED" (no selected cells) or
"MARKEDCONSISTENCY" (when COPYKEEPSTRUCT=NO and inconsistent
selection).
Copied lines will follow the sort order.
COPYDATA: Use the same parameters of the COPY attributes but will copy (export) to an internal buffer. To retrieve the buffer get the attribute value after setting it. To clear the internal buffer set it to NULL.
COPYFILE (write-only): copies (export) all visible cells to a given file. Value is the file name to be saved. LASTERROR can also be set to "INVALIDFILENAME" (failed to open). Data will be in plain text format, but the file format will be defined by the FILEFORMAT attribute, can be "TXT" (default), "HTML" or "LaTeX". The COPYCAPTION attribute can be used to define a caption that will be added to the file before the data, depending on the file format.
When using TXT format, the TEXTSEPARATOR attribute
can be used to define a column separator (default is tab '\t') and line
separator will be line feeds ('\n').
When using LaTeX format, the LATEXLABEL attribute can
be used to define a label for the table.
When using HTML format, the attributes "HTML
| ", "HTML | ", "HTML For all formats use: SKIPLINES: number of lines to skip at start when exporting the matrix to a file, not counting the title line if any. SKIPCOLUMNS: number of columns to skip at start when exporting the matrix to a file, not counting the title columns if any. Copied lines will follow the sort order. PASTE (write-only): paste (import) data from the clipboard. Data is obtained from the clipboard in TEXT format. Value is the insert position, it can be "FOCUS" to use the FOCUS_CELL attribute, can be "MARKED" to use the start of the selected groups of cells (top-left selected cell), or can be a cell address "L:C". Data must be in plain text format. Lines can be separated in DOS,
UNIX or MAC format. Columns can be separated with a tab ('\t'), or with
a semicolon (';'), or with a space (' ') or with a custom value defined
by the TEXTSEPARATOR attribute. Data must contain an
exact matrix organization. Use the attribute
TEXTSKIPLINES to skip a number of lines at the
beginning of the data. If data at the insert position have more lines or
columns than the current matrix, then the PASTESIZE_CB callback is
called if the callback does not exist, the matrix size is not changed,
and the exceeding data will be discarded. If defined, the EDITION_CB callback will be called before
the cell value is set. LASTERROR can be set to "NOTEXT"
(data is empty or NULL), "INVALIDMATRIX" (not matrix data).
BUSY will be set to YES during the operation. Only
visible cells will receive data. PASTEDATA (write-only): paste (import) data from a memory buffer. Value is the data. Insert position is obtained from the FOCUS_CELL attribute. See PASTE for more details. PASTEFILE (write-only): paste (import) data from a file. Value is the file name to be loaded. Insert position is always "0:0". See PASTE for more details. LASTERROR can also be set to "INVALIDFILENAME" (failed to open). The PASTEFILEAT attribute controls the insert position, can be "FOCUS" or a cell address "L:C". FindFIND: searches for the given text in the matrix cells. The search will start at the FOCUS_CELL cell, if found the FOCUS_CELL will be changed to the cell where the text was found and the cell will also be marked. If not visible the cell will the scrolled to the visible area. Returns the last text searched. FINDCOL: restricts the search for a given column number. FINDDIRECTION: direction of the find. Default RIGHTBOTTOM. if RIGHTBOTTOM will search from left to right, then
top to bottom; (search for columns then change
line) FINDMATCHCASE: defines if the text comparison is case-sensitive when using FIND. Can be YES or NO. Default: YES. FINDMATCHWHOLECELL: defines if the whole cell is used for comparison, or it will search for the first occurrence of the text inside the cell. Can be YES or NO. Default: YES. Undo/RedoUNDOREDO: Enable or disable the Undo/Redo support. Can be YES or NO. Default: NO. Undo/Redo support is available only for cell values, interactively or programmatically changed. Attributes are not saved/restored. UNDOCOUNT (read-only): Returns the total number of stored undo levels. UNDONAMEid (read-only): Returns a name for the given undo level. It represents the operation that was performed. Uses descriptive strings based on the names "PASTECLIP", "PASTEDATA", "PASTEFILE", "COPYCOLTO:ALL", "COPYCOLTO:TOP", "COPYCOLTO:BOTTOM", "COPYCOLTO:MARKED", "COPYCOLTO:INTERVAL", "CLEARVALUE", "SETCELL" and "EDITCELL", that are language dependent. UNDO: Sets the number of undo levels to be performed. If value is NULL will undo 1 level. When retrieved returns YES or NO indicating if it has Undo to be performed. BUSY will be set to YES during the operation. REDO: Sets the number of redo levels to be performed. If value is NULL will redo 1 level. When retrieved returns YES or NO indicating if it has Redo to be performed. BUSY will be set to YES during the operation. UNDOCLEAR (write-only): clears all Undo/Redo information. SortSORTCOLUMNid (write-only): sort the specified lines of the matrix based on the values of the given column (id). Can be ALL (1-NUMLIN), an interval in the format "L1-L2", INVERT (invert the order in the current interval of the current column, id is ignored) or RESET (remove any ordering). The SORTSIGNid attribute will be updated to reflect the ordering. When the SORTCOLUMNCOMPARE_CB callback is NOT defined, and the column
is NOT numeric, then the text is lexicographically
sorted. This means that numbers and text in the same value are sorted
separately (for ex: A1 A2 A11 A30 B1). Also, natural alphabetic order is
used: 123...aAáÁ...bBcC... The internal comparison will work only for
Latin-1 characters, even if UTF8MODE is YES. Uses the IupStringCompare
function. SORTCOLUMNORDER: defines if the number or text comparison is in ASCENDING or DESCENDING order. Default: ASCENDING. Used during SORTCOLUMNid and when the SORTCOLUMNCOMPARE_CB callback is NOT defined. Used to update the SORTSIGNid attribute when the SORTCOLUMNCOMPARE_CB callback is defined. SORTCOLUMNCASESENSITIVE: defines if the text comparison is case-sensitive. Can be YES or NO. Default: YES. Used only during SORTCOLUMNid and when the SORTCOLUMNCOMPARE_CB callback is not defined. SORTCOLUMNINTERVAL (read-only): Returns the last sorted interval, in the format "L1,L2". SORTLINEINDEXid (read-only): Returns the sorted line index given a line in regular order. To be used inside other callbacks. LASTSORTCOLUMN (read-only): Returns the last sorted column. Line and Column VisibilityFREEZE: freezes the scroll of columns and lines up to the given cell. Can be: "YES" - uses the value of the FOCUS_CELL attribute, "L:C" where L and C are the line and column, or "NO" clear the freeze state. Internally will set the NUMLIN_NOSCROLL and NUMCOL_NOSCROLL, and change the FRAMEHORIZCOLOR of the line and the FRAMEVERTCOLOR of the column to the color defined by FREEZECOLOR. FREEZECOLOR: color used for the freeze lines. Default: "0 0 255". Used only by the FREEZE attribute. VISIBLECOLid: returns if the column is visible ("YES" or "NO"). Actually checks for WIDTHid and RASTERWIDTHid if they are defined and non-zero, but more complex logic when id=0. When changed will simply set those attributes to zero or NULL (when setting to NULL and col=0 not necessarily the column will become visible because of the internal matrix logic for titles). VISIBLELINid: returns if the line is visible ("YES" or "NO"). Actually checks for HEIGHTid and RASTERHEIGHTid if they are defined and non-zero, but more complex logic when id=0. When changed will simply set those attributes to zero or NULL (when setting to NULL and lin=0 not necessarily the line will become visible because of the internal matrix logic for titles). Context MenuMENUCONTEXT: enable the context menu. Can be YES or NO. Default: YES. SHOWMENUCONTEXTL:C (write-only): shows the context menu for the L:C cell at the screen position given by the value, in the format "x,y". SHOWDIALOG (write-only): show the dialog used in the context menus. Can be: SETTINGS, EXPORT_TXT, EXPORT_LATEX, EXPORT_HTML, IMPORT_TXT, UNDOLIST, FIND, GOTO, SORT and COPYCOLTO_INTERVAL. Some dialogs are not show if the matrix is read-only. Copy CellsCOPYCOLTOL:C (write-only): copies (duplicates) the value of the given cell to a specified range of cells in the same column. Value can be "ALL" (for all lines), TOP (for all lines before the given line), BOTTOM (for all lines after the given line), MARKED (for all lines where the cell is marked), or a series of intervals in the format "L1-L2,L3-L4,L5,L6-L7,...". BUSY will be set to YES during the operation. Only visible cells will receive data. Numeric ColumnsNumeric columns are enabled when the NUMERICQUANTITYid attribute is set. To define a numeric column without using units, simply set NUMERICQUANTITYid to "None". NUMERICDECIMALSYMBOL: symbol used for decimal separator in numeric values. Can be "." or "," only. If not defined will try the DEFAULTDECIMALSYMBOL global attribute. NUMERICFORMATid: format to convert the numeric data into strings at the given column (id). If not defined the NUMERICFORMATDEF attribute will be used. Uses the same format specification of the sprintf function in C, but only one value will be processed, cannot contain other strings. (no redraw) NUMERICFORMATPRECISIONid: will set the
sprintf "precision" field in the
NUMERICFORMATid attribute string if the format
"%. NUMERICFORMATDEF: default value used when NUMERICFORMATid is not specified. If not defined it will use the DEFAULTPRECISION global attribute to build one (for instance, "%.2f" if the DEFAULTPRECISION is 2). NUMERICFORMATTITLEid: format of the title at the given column (id). Uses the same format specification of the sprintf function in C. It can contain other strings, and will receive two parameters the current column title string ("0:C") and the current column unit shown. If the current title is NULL, then only the unit parameter is passed. If not specified then only the title string ("0:C") is used. (no redraw) Numeric UnitsNUMERICQUANTITYid: Quantity used to define units for the numeric data at the given column (id). Must set this attribute for the other NUMERIC* attributes to work. For the available option see the Available Quantity and Units table below. To improve the precision, consider using the NUMERICGETVALUE_CB and NUMERICSETVALUE_CB callbacks. The returned value is always the name of the quantity in the table, regardless the value that was set. To use the numeric attributes and callbacks without using units, simply set quantity to "None". To disable all numeric support set quantity to NULL. (no redraw) NUMERICUNITCOUNTid (read-only): Returns the number of units for the current quantity at the given column (id). NUMERICUNITid: Unit of the numbers set into the matrix at the given column (id) using the unit name as value. Must be in the same category of the NUMERICQUANTITYid attribute. For the available options see the Available Quantity and Units table below. The application must process numbers for the column only in this unit, when getting or setting attributes. But the values passed to the DROP_CB and MENUDROP_CB callbacks will not be processed because they can contain strings. The returned value is always the name of the unit in the table, regardless the value that was set. Default value is the first unit on the table below. (no redraw) NUMERICUNITSHOWNid: Unit to be displayed at the given column (id). Must be in the same category of the NUMERICFORMAT attribute. The library will automatically convert the numeric data to and from the shown and data units when the data is displayed or modified. The returned value is always the name of the unit in the table, regardless the value that was set. Default value is the first unit on the table. (no redraw) NUMERICUNITSYMBOLid and NUMERICUNITSYMBOLSHOWNid: same as NUMERICUNIT* but using the unit symbol as value. (no redraw) NUMERICUNITSEARCH (write-only): Searches for a unit name. Set the result in the NUMERICFOUNDQUANTITY, NUMERICFOUNDUNIT and NUMERICFOUNDUNITSYMBOL attributes. For the available options see the Available Quantity and Units table below. NUMERICUNITSYMBOLSEARCH (write-only): same as NUMERICUNITSEARCH**,** but searches for a unit symbol. NUMERICFOUNDQUANTITY (read-only): Returns the quantity found after a NUMERICUNITSEARCH* set. Returns NULL if not found. NUMERICFOUNDUNIT (read-only): Returns the unit name found after a NUMERICUNITSEARCH* set. Returns NULL if not found. NUMERICFOUNDUNITSYMBOL (read-only): Returns the unit symbol found after a NUMERICUNITSEARCH* set. Returns NULL if not found. Numeric Units DatabaseThe following attributes will affect all IupMatrixEx controls. So the application can register new quantities and all IupMatrixEx elements will benefit. All strings must be constant strings. All attributes are Write-Only and non-inheritable. They all can be set without the element being mapped to the native system. NUMERICUNITSPELL: spelling used for Unit names. The default "INTERNATIONAL" uses the International Bureau of Weights and Measures standards: metre and litre. Set to "AMERICAN" To use the American spelling: "meter" and "liter". NUMERICADDQUANTITY: adds a new quantity given its name. Can have up to 25 new names. If the name exists, simply prepare to add new units to that quantity. NUMERICADDUNIT: adds a new unit given its name for the last quantity added. Can have up to 25 total names. The first unit added will be the reference unit, and its factor will be automatically set to 1. NUMERICADDUNITSYMBOL: sets the symbol name of the last unit added. NUMERICADDUNITFACTOR: sets the factor number in double precision of the last unit added. Use "%.18g" in IupSetStrf or sprintf for maximum double precision. The factor is the reference multiplier to obtain the unit, or how much you multiply a value in the reference unit to obtain a new value in this unit. For example, 1 km = 1000 m, then for the "km" unit factor=1000 considering that the reference unit is "m". CallbacksThe IupMatrixEx element understands all callbacks defined for a IupMatrix control. BUSY_CB: Action generated when the library is changing the matrix contents as a result of an operation such as paste or copy.
ih: identifier of the element that activated the
event. Returns: When status=2 and IUP_IGNORE is returned, the processing is aborted. When a process is aborted the callback will be called once more with status=0. NUMERICGETVALUE_CB: Action generated when a cell value is being retrieved from a numeric column. It is only called if the cell value is NULL in normal mode, or the VALUE_CB returned value is NULL in callback mode, and the column has NUMERICQUANTITYid defined. Not called for lin=0.
ih: identifier of the element that activated the
event. Returns: the number to be drawn. NUMERICSETVALUE_CB: Action generated when a cell value is being modified at a numeric column. It is only called if the column has NUMERICQUANTITYid defined. Not called for lin=0. If defined the value will not be updated as string in normal mode and VALUE_EDIT_CB will not be called in callback mode.
ih: identifier of the element that activated the
event. MENUCONTEXT_CB: Action generated after the context menu is created but before it is displayed, so the application can add or removed items from the menu. Only shown if MENUCONTEXT=YES.
ih: identifier of the element that activated the
event. Returns: if returns IUP_IGNORE the action will be aborted, and the context menu will not be shown. MENUCONTEXTCLOSE_CB: Same as MENUCONTEXT_CB, but called after the context menu is closed. Only shown if MENUCONTEXT=YES. PASTESIZE_CB: Action generated when pasting and importing data at the insert position will have more lines or columns than the current matrix. The application can change the NUMLIN and NUMCOL attributes to receive the new data.
ih: identifier of the element that activated the
event. Returns: if returns IUP_IGNORE the process will be aborted. if returns IUP_CONTINUE, the NUMLIN and NUMCOL attributes will be automatically changed to the given values. Otherwise and if the callback does not exist, the matrix size is not changed, and the exceeding data will be discarded. SORTCOLUMNCOMPARE_CB: Action generated when sorting data in a column to compare two cell values.
ih: identifier of the element that activated the
event. Returns: must return 0 if "col:lin1==col:lin2", -1 if "col:lin1<col:lin2", and 1 if "col:lin1>col:lin2". NotesContext MenuThe library adds a context menu where the user can execute the new features. If the matrix is read-only some of the features are not shown. The FILEDIRECTORY attribute can be used to control the initial directory in Export and Import file dialogs, just sets the DIRECTORY attribute of IupFileDlg. The LASTFILENAME attribute can be consulted after the file dialogs were successfully closed. If LASTFILENAME is set before the dialog is shown, then used to obtain the initial directory, just sets the FILE attribute of IupFileDlg. LASTFILENAME is set to NULL if the dialog is canceled. The CELLBYTITLE attribute controls how the "Go To..." dialog and the "Copy To - Interval" dialog interpret line and column values. If set to YES, then the title lines/columns are used as indices to locate the cell.
Dialogs
Shortcut KeysThe library adds some shortcut keys to the already implemented in IupMatrix:
Available Quantity and UnitsUnit names, symbols, and conversion factors were almost all based on: http://en.wikipedia.org/wiki/Conversion_of_units By definition, unit names and symbols follow the case displayed in the table. When setting the NUMERICQUANTITY and NUMERICUNIT attributes use English names, the case is insensitive and spaces are ignored. Some Quantities have alternative names, once used the returned values in the attribute will be the same alternative name. For example, you can use "Specific Weight" or "SPECIFICWEIGHT", and you can use "Speed" or "Velocity". All numeric attributes can be set without the element being mapped to the native system, so the IupMatrixEx element can also be used as a Quantity Units database. The unit used as a reference for conversion is always the first unit listed, and it is the unit defined by the International System of Units (SI). The American spell can be used setting NUMERICUNITSPELL=AMERICAN. NOTICE: These are only a small set of commonly used units. If you need other units, please let us know so we can include them. Obs: "g" in Comments is the standard gravity. All Quantity and Unit names are described in English. The symbols that have extended characters will work in ISO8859-1 and in UTF-8, according to the UTF8MODE global attribute. The cell background colors are just for clarity and do not imply in any standard classification.
ExamplesSee Also |
|---|
