From 13d536c13c48b17bd9e6b01a910cc4a75b3a3b57 Mon Sep 17 00:00:00 2001 From: scuri Date: Sun, 2 Dec 2012 02:28:07 +0000 Subject: [PATCH] *** empty log message *** --- iup/html/en/ctrl/iup_pplot.html | 448 ++++ iup/html/en/ctrl/iupmatrix_attrib.html | 451 ++++ iup/html/en/elem/iuptree_attrib.html | 346 +++ iup/html/en/elem/iuptree_cb.html | 243 ++ iup/mak.vc9/iupsample.vcproj | 1203 +++++++++ iup/srcpplot/iup_pplot.cpp | 3171 ++++++++++++++++++++++++ iup/test/matrix.c | 173 ++ iup/test/vbox.c | 132 + 8 files changed, 6167 insertions(+) create mode 100644 iup/html/en/ctrl/iup_pplot.html create mode 100644 iup/html/en/ctrl/iupmatrix_attrib.html create mode 100644 iup/html/en/elem/iuptree_attrib.html create mode 100644 iup/html/en/elem/iuptree_cb.html create mode 100644 iup/mak.vc9/iupsample.vcproj create mode 100644 iup/srcpplot/iup_pplot.cpp create mode 100644 iup/test/matrix.c create mode 100644 iup/test/vbox.c diff --git a/iup/html/en/ctrl/iup_pplot.html b/iup/html/en/ctrl/iup_pplot.html new file mode 100644 index 00000000..c7cea85e --- /dev/null +++ b/iup/html/en/ctrl/iup_pplot.html @@ -0,0 +1,448 @@ + + + + +IupPPlot + + + + + + + +

IupPPlot

+

Creates a PPlot plot. It inherits from +IupCanvas.

+

PPlot is a library for creating plots that is system independent. It is +maintained by Pier Philipsen (pierphil@xs4all.nl) and available at SourceForge +http://pplot.sourceforge.net/ with a +very flexible BSD License). IupPPlot library includes the PPlot source code so no external +references are needed. Also the standard PPlot distribution source code was +changed to improve features and visual appearance.

+

IupPPlot first implementation was written by Marian Trifon +(mtrif@katamail.com), then completed and documented by the IUP team.

+

Initialization and Usage

+

The IupPPlotOpen function must be called after a IupOpen, so that the control can be used. + The "iup_pplot.h" file must also be included in the source code. The program must be linked to the controls + library (iup_pplot), and with the CD library.

+

To make the control available in Lua use require"iuplua_pplot" or manually +call the initialization function in C, +iuppplotlua_open, after calling iuplua_open. +  When manually calling the function the iuplua_pplot.h file must also be included in the source code +and the program must be linked to the +Lua control + library (iuplua_pplot).

+

Guide

+

Each plot can contain 2 axis (X and Y), a title, a +legend box, a grid, a dataset area and as many +datasets you want.

+

Each data set is added using the IupPPlotAdd function. All other plot +parameters are configured by attributes.

+

If no attribute is set, the default values were selected to best display +the plot.

+

When setting attributes the plot is NOT redrawn until the REDRAW attribute is +set or a redraw event occurs.

+

The dataset area is delimited by a margin. Data is only plotted inside +the dataset area. Axis and main title are +positioned independent of this margin. It is very important to set the margins when +using axis automatic scaling or the axis maybe hidden.

+

The legend box is a list of the dataset names, each one drawn with the +same color of the correspondent dataset. The box is located in one of the four +corners of the dataset area.

+

The grid is automatically spaced accordingly the current axis +displayed values.

+

The title is always centered in the top of the plot.

+

The axis are always positioned at the origin, except when CrossOrigin +is disabled, then it is positioned at the left-bottom. If values are only positive then the +origin will be placed in left +bottom position. If values are negative and positive then origin will be placed +inside the plot. The ticks in the axis are also automatically distributed.

+

PPlot implementation demands that the MARGIN* attributes must be set so the +plot is not cropped.

+

Interaction

+

Zoom

+

Zoom in can be done selecting a region using the left mouse button. Zoom out +is done with a single click of the left mouse button. If the Ctrl+X key +combination is pressed the zoom selection is restricted to the X axis, the Y +axis will be left unchanged. If the Ctrl+Y key combination is pressed the +zoom selection is restricted to the Y axis, the X axis will be left unchanged. +If the Ctrl+R key combination is pressed the zoom selection is restored +to a free rectangle.

+

Each zoom in operation is stacked, so each zoom out operation goes back the +the previous zoom selection.

+

Zoom operates on AXS_XMAX, AXS_XMIN, AXS_YMAX, AXS_YMIN even if +AUTOMIN/MAX is enabled. The axis may be hidden depending on the selected +rectangle.

+

CrossHair Cursor

+

If you press the Ctrl+Shift key combination, while holding the left +mouse button down, a cross hair cursor will be displayed for each dataset in the +plot. The X coordinate will control the cursor, the Y coordinate will reflect +each dataset correspondent value.

+

Selection and Editing

+

Selection and editing of a dataset can be enabled using the DS_EDIT +attribute.

+

To select all the samples in the dataset press the Shift key while +clicking with the left mouse button near a sample in the dataset. To deselect +all samples press the Shift key while clicking with the left mouse button +in the background.

+

To select or deselect individual samples press the Ctrl key while +clicking with the left mouse button near the sample in the dataset.

+

After selecting samples use the Del key to remove the selected +samples. Also use the arrow keys to move the Y coordinate of the selected +samples. Press the Ctrl key to increase the step size when moving the Y +coordinate.

+

Creation

+
+
Ihandle* IupPPlot(void); [in C]
+iup.pplot{} -> (elem: ihandle) [in Lua]
+pplot() [in LED]
+
+

This function returns the identifier of the + created plot, or NULL if an error occurs.

+

Auxiliary Functions

+
void IupPPlotBegin(Ihandle* ih, int strXdata); [in C]
+iup.PPlotBegin(ih: ihandle, strXdata: number) [in Lua]
+

Prepares a dataset to receive samples. If strXdata is 1 then the X axis value +is a string.

+
+
void IupPPlotAdd(Ihandle* ih, float x, float y); [in C]
+iup.PPlotAdd(ih: ihandle, x, y: number) [in Lua]
+

Adds a sample to the dataset. Can only be called if IupPPlotBegin was +called with strXdata=0.

+
+
void IupPPlotAddStr(Ihandle* ih, const char* x, float y); [in C]
+iup.PPlotAddStr(ih: ihandle, x: string, y: number) [in Lua]
+

Same as IupPPlotAdd, but allows to use a string as the X +axis value. Can only be called if IupPPlotBegin was called with +strXdata=1.

+
+
int IupPPlotEnd(Ihandle* ih); [in C]
+iup.PPlotEnd(ih: ihandle) -> (index: number) [in Lua]
+

Adds a 2D dataset to the plot and returns the dataset index. +The data set can be empty. Redraw is NOT +done until the REDRAW attribute is set. Also it will change the current dataset +index to the return value. You can only set attributes of a dataset AFTER you +added the dataset.  Can only be called if IupPPlotBegin was called. +Whenever you create a dataset all its "DS_*" attributes will be set to the +default values. Notice that DS_MODE must be set before other "DS_*" attributes.

+
+
void IupPPlotInsert(Ihandle *ih, int index, int sample_index, float x, float y); [in C]
+void IupPPlotInsertStr(Ihandle *ih, int index, int sample_index, const char* x, float y);
+iup.IupPPlotInsert(ih: ihandle, index, sample_index, x, y: number) [in Lua]
+iup.IupPPlotInsertStr(ih: ihandle, index, sample_index, x, y: number)
+

Inserts a sample in a dataset at the given sample_index. Can +be used only after the dataset is added to the +plot.

+
+
void IupPPlotInsertPoints(Ihandle *ih, int index, int sample_index, float* x, float* y, int count); [in C]
+void IupPPlotInsertStrPoints(Ihandle *ih, int index, int sample_index, const char** x, float* y, int count);
+iup.IupPPlotInsertPoints(ih: ihandle, index, sample_index, x, y: table of number) [in Lua]
+iup.IupPPlotInsertStrPoints(ih: ihandle, index, sample_index, x, y: table of number)
+

Inserts an array of samples in a dataset at the given sample_index. +Can be used only after the dataset is added to the +plot. (Since 3.4)

+
+
void IupPPlotAddPoints(Ihandle *ih, int index, float* x, float* y, int count); [in C]
+void IupPPlotAddStrPoints(Ihandle *ih, int index, const char** x, float* y, int count);
+iup.IupPPlotAddPoints(ih: ihandle, index, x, y: table of number) [in Lua]
+iup.IupPPlotAddStrPoints(ih: ihandle, index, x, y: table of number)
+

Adds an array of samples in a dataset at the end. Can be used only after the dataset is added to the +plot. (Since 3.4)

+
+
void IupPPlotTransform(Ihandle* ih, float x, float y, int *ix, int *iy); [in C]
+iup.PPlotTransform(ih: ihandle, x, y: number) -> (ix, iy: number) [in Lua]
+

Converts coordinates in plot units to pixels. It should be used in PREDRAW_CB +and POSTDRAW_CB callbacks only. Output variables can be NULL if not used. It can +be used inside other callbacks, but make sure that the drawing after a resize is +done.

+
+
void IupPPlotPaintTo(Ihandle* ih, cdCanvas* cnv); [in C]
+iup.PPlotPaintTo(ih: ihandle, cnv: cdCanvas) [in Lua]
+

Plots to the given CD canvas instead of the display canvas.

+

Attributes

+ + +

REDRAW (write-only) (non inheritable): redraw the plot and update the display. Value is +ignored. All other attributes will NOT update the display, so you can set many +attributes without visual output.

+ +

USE_IMAGERGB (non inheritable): defines if the double buffer will use standard driver +image (NO - faster) or an RGB image (YES - slower). Default: NO. The IMAGERGB +driver has anti-aliasing which can improve the line drawing.

+

USE_CONTEXTPLUS (non inheritable): defines if the CD canvas will use +ContextPlus drivers +(YES) for drawing or standard drivers (NO). Default: NO. The + +ContextPlus +drivers has +anti-aliasing which can improve the line drawing. (renamed from USE_GDI+ in 3.8)

+
+

FONT: + the default font used in all text elements of the plot: title, legend and labels.

+

BGCOLOR: the background color. The default value is white "255 255 +255".

+

MARGINLEFT, MARGINRIGHT, MARGINTOP, MARGINBOTTOM (non inheritable): margin of the +dataset area. PPlot implementation demands that margins must be set so the plot +is not cropped. Default: "15", "15", "30", "15".

+

Title Configuration (non inheritable)

+

FGCOLOR: the title color. The default value is black "0 0 0".

+

TITLE (non inheritable): the title. Located always at the top center area.

+

TITLEFONTSIZE, TITLEFONTSTYLE (non inheritable): the title font size and style. The default +values depends on the FONT attribute and the returned value is NULL. Set to +NULL, to use the FONT attribute values. Style can be "PLAIN", "BOLD", "ITALIC" +or "BOLDITALIC".

+

Legend Configuration (non inheritable)

+

LEGENDSHOW: shows or hides the legend box. Can be YES or NO. Default: +NO.

+

LEGENDPOS: legend box position. Can be: "TOPLEFT", "TOPRIGHT", +"BOTTOMLEFT", or "BOTTOMRIGHT. Default: "TOPRIGHT".

+

LEGENDFONTSIZE, LEGENDFONTSTYLE: the legend box text font size and style.

+

Grid Configuration (non inheritable)

+

GRID: shows or hides the grid in both or a +specific axis. Can be: YES (both), HORIZONTAL, VERTICAL or NO. Default: NO.

+

GRIDLINESTYLE: line style of the grid. Can be: "CONTINUOUS", +"DASHED", "DOTTED", "DASH_DOT", "DASH_DOT_DOT". Default is "CONTINUOUS".

+

GRIDCOLOR: grid color. Default: "200 200 200".

+

Dataset List Management (non inheritable)

+

REMOVE (write-only): removes a dataset given its index.

+

CLEAR (write-only): removes all datasets. Value is ignored.

+

COUNT [read-only]: total number of datasets.

+

CURRENT: current dataset index. Default is +-1. When a dataset is added it becomes the current dataset. The index starts at +0. All "DS_*" attributes are dependent on this value.

+

Dataset Configuration (non inheritable)

+

DS_LEGEND: legend text of the current dataset. Default is dynamically +generated: "plot 0", "plot 1", "plot 2", ...

+

DS_COLOR: color of the current dataset and it legend text. Default  +is dynamically generated for the 6 first datasets, others are default to black +"0 0 0". The first 6 are: 0="255 0 0", 1="0 0 255", 2="0 255 0", 3="0 255 255", +4="255 0 255", 5="255 255 0".

+

DS_COUNT: returns the number of samples of the current +dataset. (since 3.6)

+

DS_MODE: drawing mode of the current dataset. Can be: "LINE", "BAR", +"MARK" or "MARKLINE". Default: "LINE". This must +be set before other "DS_*" attributes.

+

DS_LINESTYLE: line style of the current dataset. Can be: "CONTINUOUS", +"DASHED", "DOTTED", "DASH_DOT", "DASH_DOT_DOT". Default is "CONTINUOUS".

+

DS_LINEWIDTH: line width of the current dataset. Default: 1.

+

DS_MARKSTYLE: mark style of the current dataset. Can be: "PLUS", +"STAR", "CIRCLE", "X", "BOX", "DIAMOND", "HOLLOW_CIRCLE", "HOLLOW_BOX", +"HOLLOW_DIAMOND". Default is "X".

+

DS_MARKSIZE: mark size of the current dataset. Default: 7.

+

DS_SHOWVALUES: enable or disable the display of the values near each +sample. Can be YES or NO. Default: NO.

+

DS_REMOVE (write-only): removes a sample from the current dataset given its index.

+

DS_EDIT: enable or disable the current dataset interactive selection and editing. Can be +YES or NO. Default: NO.

+

Axis Configuration (non inheritable)

+

AXS_XCOLOR, AXS_YCOLOR: axis, ticks and label color. Default: "0 0 0".

+

AXS_XMAX, AXS_XMIN, AXS_YMAX, AXS_YMIN: minimum and maximum displayed +values of the respective axis. Automatically calculated values when AUTOMIN or +AUTOMAX are enabled.

+

AXS_XAUTOMIN, AXS_XAUTOMAX, AXS_YAUTOMIN, AXS_YAUTOMAX: configures the automatic scaling of the minimum and maximum display values. +Can be YES or NO. Default: YES.

+

AXS_XLABEL, AXS_YLABEL: text label of the  respective axis.

+

AXS_XLABELCENTERED, AXS_YLABELCENTERED: text label position at +center (YES) or at top/right (NO). Default: YES.

+

AXS_XREVERSE, AXS_YREVERSE: reverse the axis direction. Can be YES or +NO. Default: NO. Default is Y oriented bottom to top, and X oriented from left +to right.

+

AXS_XCROSSORIGIN, AXS_YCROSSORIGIN: allow the axis to cross the +origin and to be placed inside the dataset area. Can be YES or NO. Default: YES.

+

AXS_XSCALE, AXS_YSCALE: configures the scale of the respective axis. +Can be: LIN (liner), LOG10 (base 10), LOG2 (base 2) and LOGN (base e). Default: +LIN.

+

AXS_XFONTSIZE, AXS_YFONTSIZE, AXS_XFONTSTYLE, AXS_YFONTSTYLE: axis +label text font size and style. See TITLEFONTSIZE and TITLEFONTSTYLE.

+

Axis Ticks Configuration (non inheritable)

+

AXS_XTICK, AXS_YTICK: enable or disable the axis tick display. Can be +YES or NO. Default: YES.

+

AXS_XTICKFORMAT, AXS_YTICKFORMAT: axis tick number C format string. +Default: "%.0f".

+

AXS_XTICKFONTSIZE, AXS_YTICKFONTSIZE, AXS_XTICKFONTSTYLE, +AXS_YTICKFONTSTYLE: axis tick number font size and style.  See TITLEFONTSIZE +and TITLEFONTSTYLE.

+

AXS_XAUTOTICK, AXS_YAUTOTICK: configures the automatic tick +spacing. Can be YES or NO. Default: YES.

+

AXS_XTICKMAJORSPAN, AXS_YTICKMAJORSPAN: The spacing between +major ticks. Default is 1 when AUTOTICK is disabled.

+

AXS_XTICKDIVISION, AXS_YTICKDIVISION: number of minor ticks +intervals between +each major tick. Default is 5 when AUTOTICK is disabled.

+

AXS_XAUTOTICKSIZE, AXS_YAUTOTICKSIZE: configures the +automatic tick size. Can be YES or NO. Default: YES.

+

AXS_XTICKSIZE, AXS_YTICKSIZE: size of minor ticks in pixels. +Default is 5 when AUTOTICKSIZE is disabled.

+

AXS_XTICKMAJORSIZE, AXS_YTICKMAJORSIZE: size of major +ticks in pixels. Default is 8 when AUTOTICKSIZE is disabled.

+
+
+
+

+ACTIVE, +SCREENPOSITION, + +POSITION, +MINSIZE, +MAXSIZE, + WID, TIP, +SIZE, + RASTERSIZE, + ZORDER, VISIBLE: +also accepted. 

+

Callbacks

+ +

DELETE_CB: + Action generated when the Del key is pressed to removed a sample from a +dataset. + If multiple points are selected it is called once for each selected point.

+ +
int function(Ihandle *ih, int index, int sample_index, float x, float y); [in C]
+elem:delete_cb(index, sample_index, x, y: number) -> (ret: number) [in Lua]
+

index: index of the dataset
+ sample_index: index of the sample in the dataset
+ x
: X coordinate value of the sample
+ y: Y coordinate value of the sample

+

+ Returns: + If IUP_IGNORE then the sample is not deleted.

+ +

DELETEBEGIN_CB, DELETEEND_CB: Actions generated when a delete operation +will begin or end. But they are called only if DELETE_CB is also defined.

+ +
int function(Ihandle *ih); [in C]
+elem:deletebegin_cb() -> (ret: number) [in Lua]
+elem:deleteend_cb() -> (ret: number) [in Lua]
+

+ Returns: + If DELETEBEGIN_CB returns IUP_IGNORE the delete operation for + all the selected samples are aborted.

+ +

SELECT_CB: + Action generated when a sample is selected. + If multiple points are selected it is called once for each new selected point. +It is called only if the selection state of the sample is about to be changed.

+ +
int function(Ihandle *ih, int index, int sample_index, float x, float y, int select); [in C]
+elem:select_cb(index, sample_index, x, y, select: number) -> (ret: number) [in Lua]
+

index: index of the dataset
+ sample_index: index of the sample in the dataset
+ x
: X coordinate value of the sample
+ y: Y coordinate value of the sample
+ select: boolean value that a non zero value indicates if the point is + to be selected.

+

+ Returns: + If IUP_IGNORE then the sample is not selected.

+ +

SELECTBEGIN_CB, SELECTEND_CB: Actions generated when a selection +operation will begin or end. But they are called only if SELECT_CB is also +defined.

+ +
int function(Ihandle *ih); [in C]
+elem:selectbegin_cb() -> (ret: number) [in Lua]
+elem:selectend_cb() -> (ret: number) [in Lua]
+

+ Returns: + If SELECTBEGIN_CB returns IUP_IGNORE the selection operation is + aborted.

+ +

EDIT_CB: + Action generated when a sample is selected. + If multiple points are selected it is called once for each new selected point. +It is called only if the selection state of the sample is about to be changed.

+ +
int function(Ihandle *ih, int index, int sample_index, float x, float y, float *new_x, float *new_y); [in C]
+elem:edit_cb(index, sample_index, x, y, new_x, new_y: number) -> (new_x, new_y, ret: number) [in Lua]
+

index: index of the dataset
+ sample_index: index of the sample in the dataset
+ x
: X coordinate value of the sample
+ y: Y coordinate value of the sample
+ new_x: the new X coordinate value of the sample
+ new_y: the new Y coordinate value of the sample

+

+ Returns: + If IUP_IGNORE then the sample is not edited. The + application can changed the new value before it is edited.

+ +

EDITBEGIN_CB, EDITEND_CB: Actions generated when an editing +operation will begin or end. But they are called only if EDIT_CB is also +defined.

+ +
int function(Ihandle *ih); [in C]
+elem:editbegin_cb() -> (ret: number) [in Lua]
+elem:editend_cb() -> (ret: number) [in Lua]
+

+ Returns: + If EDITBEGIN_CB returns IUP_IGNORE the editing operation is + aborted.

+ +

PREDRAW_CB, POSTDRAW_CB: Actions generated before and after the redraw +operation. Predraw can be used to draw a different background and Postdraw can +be used to draw additional information in the plot. Predraw has no restrictions, +but Postdraw is clipped to the dataset area. To position elements in plot units, +use the IupPPlotTransform function.

+ +
int function(Ihandle *ih, cdCanvas* cnv); [in C]
+elem:predraw_cb(cnv: cdCanvas) -> (ret: number) [in Lua]
+elem:postdraw_cb(cnv: cdCanvas) -> (ret: number) [in Lua]
+

cnv: the CD canvas where the draw operation + occurs.

+
+
+
+ +

MAP_CB, +UNMAP_CB, +GETFOCUS_CB, + KILLFOCUS_CB, +ENTERWINDOW_CB, + LEAVEWINDOW_CB, +K_ANY, + HELP_CB: All common callbacks are +supported.

+ +

Examples

+

Browse for Example Files

+
+
+ + + + + + + + + + + + + +
+
+
+

See Also

+ +

IupCanvas, +IupMglPlot

+ + + + \ No newline at end of file diff --git a/iup/html/en/ctrl/iupmatrix_attrib.html b/iup/html/en/ctrl/iupmatrix_attrib.html new file mode 100644 index 00000000..ece7d2d1 --- /dev/null +++ b/iup/html/en/ctrl/iupmatrix_attrib.html @@ -0,0 +1,451 @@ + + + + +IupMatrix Attributes + + + + + +

IupMatrix Attributes (all non inheritable with +exceptions)

+

General Attributes

+

CURSOR: + Default cursor used by the matrix. The + default cursor is a symbol that looks like a cross. If you need to refer to this default cursor, use the name +"IupMatrixCrossCursor".

+

EDIT_MODE: + When set to YES, programmatically puts the + current cell in edition mode, allowing the user to modify its value. When consulted informs if the the current cell is + being edited. Possible values: "YES" or "NO".

+

EDITNEXT: controls how the next cell after editing is +chosen. Can be LIN, COL, LINCR, COLCR. Default: LIN. (since 3.4)

+

LIN      - go to the next line, if at +last line then go to the next column at the same line;
+LINCR  - go to the next line, if at last line then go to the next column at +the first line;
+COL     - go to the next column, if at last column then go +to the next line at the same column;
+COLCR - go to the next column, if at last column then go to the next line at the +first column;
NONE   - stay in the same cell. (since 3.6)

+

FOCUS_CELL: + Defines the current cell. Two numbers in the "L:C" format, +  (L>0 and C>0, a title cell can NOT be the current cell). Default: "1:1".

+

HIDEFOCUS: do not show the focus mark when + drawing the matrix. Default is NO.

+

HIDDENTEXTMARKS: when text is greater than cell space, it is +normally cropped, but when set to YES a "..." mark will be added at the crop +point to indicate that there is more text not visible. Default: NO. (since 3.1)

+

LIMITEXPAND: limit expansion to the maximum size that shows +all cells. This will set the MAXSIZE attribute to match the natural size of the +matrix. (since 3.5)

+

ORIGIN: Scroll the visible area to the +given cell. Returns the cell at the upper left corner. To scroll to a line or a +column, use a value such as "L:*" or "*:C" (where +L>0 and C>0). L and C +can not be a non scrollable cell either.

+

ORIGINOFFSET: complements the +ORIGIN attribute by specifying the drag offset of the top left cell. Returns the +current value. Has the format "XxY" or "%dx%d" in C. Used only the ORIGIN is set. (since 3.5)

+

READONLY: disables the editing of all cells. EDITION_CB and +VALUE_EDIT_CB will not be called anymore. The L:C attribute will still be able +to change the cell value. (since 3.0)

+ +

RESIZEMATRIX: + Defines if the width of a column can be + interactively changed. When this is possible, the user can change the size of a column by dragging the column title + right border. Possible values: "YES" or "NO". Default: + "NO" (does not allow interactive width change).

+

USETITLESIZE: Use the title size +to define the cell size if necessary. See WIDTHn and HEIGHTn. Default: NO. +(since 3.0)

+ + + +
+
+
+

+ACTIVE, +EXPAND, +FONT, SCREENPOSITION, + +POSITION, +MINSIZE, +MAXSIZE, + WID, TIP, +SIZE, +RASTERSIZE, + ZORDER, VISIBLE: +also accepted. 

+ +

Cell Attributes (no redraw)

+

(These attributes are only updated in the display when you set the +REDRAW attribute.)

+

L:C: + Text of the cell located in line + L and column + C, where L and C are integer numbers.
+L:0: + Title of line + L.
+0:C: + Title of column + C.
+0:0: + Title of the area between the line and + column titles.

+

These are valid only in normal mode.

+

BGCOLOR: + Background color of the matrix. (inheritable)
+BGCOLOR*:C: + Background color of column + C.
+BGCOLORL:*: + Background color of line + L.
+BGCOLORL:C: + Background color of the cell in line + L and column + C.

+

When more than one attribute are defined, the background color will be + selected following this priority: BGCOLORL:C, BGCOLORL:*, BGCOLOR*:C, and + last BGCOLOR. + (L or C >= 0)
+ Default BGCOLOR is the global attribute TXTBGCOLOR for cells and the parent's BGCOLOR for titles.
+ Since the matrix control can be larger than the matrix itself, the empty area will always be filled with the + parent's BGCOLOR.

+

FGCOLOR: + Text color. (inheritable)
+FGCOLOR*:C: + Text color of column + C.
+FGCOLORL:*
: + Text color of line + L.
+FGCOLORL:C: + Text color of the cell in line + L and column + C.

When more than one attribute are define, the text color of a cell will be selected + following this priority: FGCOLORL:C, FGCOLORL:*, FGCOLOR*:C, and last + FGCOLOR. + (L or C >= 0)
+Default FGCOLOR is the global attribute TXTFGCOLOR for cells or the global +attribute DLGFGCOLOR for titles.

+

FONT: + Character font of the text. (inheritable)
+FONTL:*: + Text + font of the cells in line L.
+FONT*:C: + Text + font of the cells in column C.
+FONTL:C: + Text font of the cell in line L and column C.

+

This attribute must be set before the control is showed. It affects the calculation of the size of all the matrix + cells. The cell size is always calculated from the base FONT attribute.

+

FRAMECOLOR: + Sets the color to be used in the frame lines. (inheritable)
+FRAMEVERTCOLORL:C: Color of the vertical right frame +of the cell. When not defined the FRAMECOLOR is used. For a title cell defines +right and left frames. If value is "BGCOLOR" the frame line is not drawn.
+FRAMEVERTCOLOR*:C: same as FRAMEVERTCOLORL:C +but for all the cells of the column C. (since 3.5)
+FRAMEHORIZCOLORL:C: Color of the horizontal bottom frame of the +cell. When not defined the +FRAMECOLOR is used. For a title cell defines bottom and top frames. If value is +"BGCOLOR" the frame line is not drawn.
+FRAMEHORIZCOLORL:*:same as FRAMEHORIZCOLORL:C +but for all the cells of the line L. (since 3.5)

+

VALUE: + Allows setting or verifying the value of the + current cell. Is the same as obtaining the current cell from +FOCUS_CELL value and using it as the attribute name for "L:C". +But when updated or retrieved during cell editing, the edit control will be +updated or consulted instead of the matrix cell. When retrieved inside the +EDITION_CB callback when mode is 0, then the return value is the new value + that will be updated in the cell.

+
+

CELLBGCOLORL:C +(read-only): Returns the actual cell BGCOLOR. Returns NULL if the cell does not +exists, or it is not visible, or the element is not mapped. (since 3.6)

+

CELLFGCOLORL:C +(read-only): Returns the actual cell FGCOLOR. Returns NULL if the cell does not +exists, or it is not visible, or the element is not mapped. (since 3.6)

+

CELLOFFSETL:C (read-only): Returns the cell +computed offset in pixels from the top-left corner of the matrix, in the format +"XxY" or "%dx%d" in C. Returns NULL +if the cell does not exists, or it is not visible, or the element is not mapped. +It will only return a valid result if the cell has already been displayed. They +are similar to the parameters of the DRAW_CB callback but they do NOT include +the decorations. (since 3.5)

+

CELLSIZEL:C (read-only): Returns the cell +computed size in pixels, in the format "WxH" or "%dx%d" in C. Returns NULL if the cell does not exists, or the +element is not mapped. It will only return a valid result if the cell has +already been displayed. They are similar to the parameters of the DRAW_CB +callback but they do NOT include the decorations. (since 3.5)

+

Column Attributes (no redraw)

+

ALIGNMENTC : + Alignment of the cells in column + C (C >= 0). + Possible values: "ALEFT", "ACENTER" or "ARIGHT". Default: + "ALEFT" for n=0 and "ACENTER" for n>0. Not used for +the column title. The 0:0 corner is always ACENTER, and the other column titles +are also centered but if they do not fit in the cell then the alignment is +changed to ALEFT. Before checking the default value it will check the "ALIGNMENT" +attribute value.

+

SORTSIGNC : Shows a sort sign (up or + down arrow) in the + column + C (C >= 0) + title. Possible values: "UP", "DOWN" + and "NO". Default: NO.

+

Column Size Attributes

+

For all columns if WIDTHn is not defined, then RASTERWIDTHn is used. If also +not defined, then depending on the circumstances a logic is used to find the +column width.

+

If it is the title column (n=0), then if USETITLESIZE=YES or not in callback +mode, it will search for the maximum width among the titles of all lines. +Finally if the conditions are not true or the maximum width of the column is 0, +then the column of line titles is hidden.

+

If it is a regular column (n>0), then if USETITLESIZE=YES, then it will use +the width of the title of the column. Finally if the condition is not true or +the width of the title of the column is 0, then the default value WIDTHDEF is +used.

+

RASTERWIDTHn: Same as WIDTHn but in pixels. +Has lower priority than WIDTHn.

+

WIDTHn: Width of column n in SIZE +units, where n is the number of the column (n>=0). If the width value is 0, the +column will not be shown on the screen. It does not includes the decoration size +occupied by the frame lines.

+

WIDTHDEF: + Default column width in SIZE units. Not used for the title column. Default: +80 (width corresponding to 20 characters).

+

Line Size Attributes

+

For all lines if HEIGHTn is not defined, then RASTERHEIGHTn is used. If also +not defined, then depending on the circumstances a logic is used to find the +line height.

+

If it is the title line (n=0), then if USETITLESIZE=YES or not in callback +mode, it will search for the maximum height among the titles of all columns. +Finally if the conditions are not true or the maximum height of the line is 0, +then the line of column titles is hidden.

+

If it is a regular line (n>0), then if USETITLESIZE=YES, then it will use the +height of the title of the line. Finally if the condition is not true or the +height of the title of the line is 0, then the default value HEIGHTDEF is used.

+

HEIGHTn: Height of line n in SIZE +units, where n is the number of the line (n>=0). If the height value is 0, the +line will not be shown on the screen. It does not includes the decoration size +occupied by the frame lines.

+

HEIGHTDEF: + Default line height in SIZE units. Not used for the title line. Default: +8 (height corresponding to 1 line).

+

RASTERHEIGHTn: Same as HEIGHTn but in pixels. +Has lower priority than HEIGHTn.

+

Number of Cells Attributes

+

ADDCOL (write-only): + Adds a new column to the matrix after the + specified column. To insert a column at the top of the spreadsheet, value 0 +must be used. To add more than one column, use format "C-C", where the first number corresponds to the base column and the second number corresponds to + the number of columns to be added. It is valid only in normal operation mode. +Can NOT add a title column. Ignored if set before map.

+

ADDLIN (write-only): + Adds a new line to the matrix after the + specified line. To insert a line at the top of the spreadsheet, value 0 must be used. To add more than one line, use format "L-L", +where the first number corresponds to the base line and the second number +corresponds to the number of lines to be added. It is valid only in normal +operation mode. Can NOT add a title line. Ignored if set before map.

+

DELCOL (write-only): + Removes the given column from the matrix. To + remove more than one column, use format "C-C", where the +first number corresponds to the base column and the second number corresponds to +the number of columns to be removed. It is valid only in normal operation mode. +Can NOT remove a title column, C>0. Ignored if set +before map.

+

DELLIN (write-only): + Removes the given line from the matrix. To + remove more than one line, use format "L-L", where the first number corresponds to the base line and the second number corresponds to the + number of lines to be removed. It is valid only in normal operation mode. Can +NOT remove a title line, L>0. Ignored if set before +map.

+

NUMCOL: + Defines the number of columns in the matrix. Must be an integer number. Default: "0". +It does not include the title column. If changed after map will add empty cells +or discard cells at the end.

+

NUMCOL_VISIBLE: + When set defines the number of + visible columns to be counted when calculating the Natural +size, not counting the title column. Not used elsewhere. + The Natural size will always include the title column if any. +Can be greater than the actual number of columns, so room will be reserved for +adding new columns without the need to resize the matrix. Also it will always use the first columns of the matrix, except if +NUMCOL_VISIBLE_LAST=YES then it will use the last columns. The +remaining columns will be accessible only by using the scrollbar. IMPORTANT: +When retrieved returns the current number of visible columns, not including the +non scrollable columns. Default: "4".

+

NUMCOL_NOSCROLL: Number of +columns that are non scrollable, not counting the title column. Default: "0". It does not affect +the NUMCOL_VISIBLE attribute behavior nor Natural size computation. It will +always use the first columns of the matrix. The cells appearance will be the +same of ordinary cells, and they can also receive the focus and be edited. Must +be less than the total number of columns. (since 3.5)

+

NUMLIN: + Defines the number of lines in the matrix. Must be an integer number. Default: "0". +It does not include the title line. If changed after map will add empty cells +or discard cells at the end.

+

NUMLIN_VISIBLE: + When set defines the number of visible lines to be counted when calculating +the Natural size, not counting the title line. Not used elsewhere. +The Natural size will always include the title line if any. +Can be greater than the actual number of lines, so room will be reserved for +adding new lines without the need to resize the matrix. Also it will always use the +first lines of the matrix, except if NUMLIN_VISIBLE_LAST=YES +then it will use the last lines. The remaining lines will be accessible only by using +the scrollbar. IMPORTANT: When + retrieved returns the current number of visible lines, not including the non +scrollable lines. Default: "3".

+

NUMLIN_NOSCROLL: Number of +lines that are non scrollable, not counting the title line. Default: "0". It does not affect the +NUMLIN_VISIBLE attribute behavior nor Natural size computation. It will always +use the first lines of the matrix. The cells appearance will be the same of +ordinary cells, and they can also receive the focus and be edited.  Must be +less than the total number of lines. (since 3.5)

+

Mark Attributes

+

MARKAREA: + Defines if the area to be interactively + marked by the user must be continuous or not, valid only if MARKMULTIPLE=YES. Possible values: "CONTINUOUS" or "NOT_CONTINUOUS". Default: "CONTINUOUS".

+

MARKMODE: + Defines the entity that can be marked: none, + lines, columns, (lines or columns), and cells. Possible values: "NO", "LIN", "COL", + "LINCOL" or "CELL". Default: "NO" + (no mark).

+

MARKL:C: marks a cell, a line or +a column depending on +MARKMODE, and returns cell, line or column mark state also according to MARKMODE. Can be "1" or +"0". If MARKMODE=LIN,COL,LINCOL use 0 to mark only the other element +(ex: "0:3" set/get for column 3). Even when MARKMODE=LIN,COL,LINCOL you can +specify a single cell address. (since 3.0)

+

MARKED: + String of '0' or '1' characters, informing which cells are + marked (indicated by value '1'). Use NULL to clear all marks, returns +NULL if no marks. + The format of this character vector depends on the value of the MARKMODE attribute: if its value is CELL, the vector will have NUMLIN x NUMCOL positions, corresponding to all the cells in the matrix +starting with all the cells of the first line, then the second line and so on. If its value is LIN, the vector will begin with letter +'L' and will have further NUMLIN positions, each one corresponding to a line + in the matrix. If its value is COL, the vector will begin with letter 'C' and will have further +NUMCOL positions, each one corresponding to a + column in the matrix. If its value is LINCOL, the first letter, which can be either +'L' or 'C', will indicate which of the above formats is being used. If you +change the other mark attributes the marked cells are cleared. When setting the +attribute the LIN and COL notation can be used even if MARKMODE=CELL. +MULTIPLE and AREA are NOT considered when setting MARKED or MARKL:C.

+

MARKMULTIPLE: + Defines if more than one entity defined by + MARKMODE can be interactively + marked. Possible values: "YES" or "NO". Default: + "NO".

+

Action Attributes

+

+CLEARATTRIB (write-only): + Clear all cell attributes if ALL, and all attributes except titles if CONTENTS. +When ALL is specified, all lines and column attributes are also cleared. (since 3.6)
CLEARVALUEL:C (write-only): Clear all +cell attributes in an interval starting at the specified cell. Its value defines the end +cell in the "L:C" format, the default is the last cell. (since 3.6)
+CLEARATTRIBL:* (write-only): + the cell attributes in line L. Its value defines a column inclusive interval in the +"C1-C2" format. The default is 0 and the last column. When a full line +is specified, all line attributes are also cleared. (since 3.6)
+CLEARATTRIB*:C (write-only): + the cell attributes in column C. Its value defines a line inclusive interval in the +"L1-L2" format. The default is 0 and the last line. When a full column +is specified, all column attributes are also cleared, including ALIGNMENT and +SORTSIGN. (since 3.6)

+

In all cases, attributes are set to NULL. Only the attributes +FONT*, BGCOLOR*, FGCOLOR*, FRAMEHORIZCOLOR*, FRAMEHORIZCOLOR*,  ALIGNMENT* +and SORTSIGN* are affected. Action only works if the matrix is mapped and NOT in +callback mode.

+

+CLEARVALUE (write-only): + Clear all values if ALL, and all values except titles if CONTENTS. (since 3.6)
CLEARVALUEL:C (write-only): Clear all +values in an interval starting at the specified cell. Its value defines the end +cell in the "L:C" format, the default is the last cell. (since 3.6)
+CLEARVALUEL:* (write-only): + the values in line L. Its value defines a column inclusive interval in the +"C1-C2" format. The default is 0 and the last column. (since 3.6)
+CLEARVALUE*:C (write-only): + the values in column C. Its value defines a line inclusive interval in the +"L1-L2" format. The default is 0 and the last line. (since 3.6)

+

In all cases, values are set to NULL. Action only works if the +matrix is mapped and NOT in callback mode.

+

FITTOSIZE (write-only): Force lines +and/or columns sizes so the matrix visible size fit in its current size. +NUMCOL_VISIBLE and NUMLIN_VISIBLE are considered when fitting and they are not +changed, only the RASTERWIDTHn and RASTERHEIGHTn attributes are changed. But if +any of the RASTERWIDTHn and RASTERHEIGHTn attributes where already set, then +they will not be changed. If the matrix is +resized then it must be set again to obtain the same result, but before doing +that set to NULL all the RASTERWIDTHn and RASTERHEIGHTn attributes that you want +to be changed. Can be LINES, +COLUMNS or YES (meaning both). (since 3.3)

+

FITTOTEXT (write-only): Fit the RASTERWIDTHn or the RASTERHEIGHTn attribute for the given column or line, so +that it will fit the largest text in the column or the highest text in the line. +The number of the column or line must be preceded by a character identifying its +type, "C" for columns and "L" for lines. For example "C5"=column 5 or "L3"=line +3. If FITMAXWIDTHn or FITMAXHEIGHTn are set for the column or line they are used +as maximum limit for the size. (since 3.4)

+

SHOW (write-only): If necessary scroll the visible area to +make the +given cell visible. To scroll to a line or a +column, use a value such as "L:*" or "*:C" (where +L>0 and C>0). (since +3.0)

+

REDRAW (write-only): + The user can inform the matrix that the data + has changed, and it must be redrawn. Values:

+

"ALL": + Redraws the whole matrix.
+ "L%d": + Redraws the given line (e. g.: "L3" redraws line 3)
+ "L%d-%d": + Redraws the lines in the given region (e.g.: + "L2-4" redraws lines 2, 3 and 4)
+ "C%d": + Redraws the given column (e.g.: "C3" redraws column 3)
+ "C%d-%d": + Redraws the columns in the given region + (e.g: "C2-4" redraws columns 2, 3 and 4)

+

No redraw is done when the application sets the attributes: +L:C, +ALIGNMENTc, BGCOLOR*, FGCOLOR*, FONT*, VALUE, FRAME*COLOR. Global and size attributes always automatically redraw the + matrix.

+

Text Editing Attributes

+

CARET: + Allows specifying and verifying the caret + position of the text box in edition mode.

+

MASKL:C: Defines a mask that will filter text input. The +MASK auxiliary attributes are also available +by adding the line and column at the end of the attribute name.

+

MULTILINE: allows the edition of +multiple lines. Use Shift+Enter to add lines. Enter will end the editing.

+

SELECTION: + Allows specifying and verifying selection + interval + of the text box in edition mode.

+

Canvas Attributes (inheritable)

+

BORDER: Changed to NO.

+

SCROLLBAR: + Changed to YES.

+ + + + \ No newline at end of file diff --git a/iup/html/en/elem/iuptree_attrib.html b/iup/html/en/elem/iuptree_attrib.html new file mode 100644 index 00000000..eb4dd0de --- /dev/null +++ b/iup/html/en/elem/iuptree_attrib.html @@ -0,0 +1,346 @@ + + + + +IupTree Attributes + + + + + +

IupTree Attributes

+

General

+

ADDEXPANDED (non inheritable): + Defines if branches will be expanded when + created. The branch will be actually expanded when it receives the first +child. Possible values: "YES" = + The branches will be created expanded; "NO" = + The branches will be created collapsed. Default: + "YES".

+

ADDROOT (non inheritable): +automatically adds an empty branch as the first node when the tree is mapped. +Default: "YES". (Since 3.1)

+

AUTOREDRAW [Windows] (non inheritable): +automatically redraws the tree when something has change. Set to NO to add many +items to the tree without updating the display. Default: "YES". (since 3.3)

+ +

BGCOLOR: Background color of the +tree. Default: the global attribute TXTBGCOLOR.

+ + +

CANFOCUS (creation only) (non inheritable): enables the focus traversal of the control. In Windows the control will still get the focus when clicked. Default: YES. (since 3.0)

+ + +

COUNT (read only) (non inheritable): returns the total number of +nodes in the +tree. (since 3.0)

+ + +

DROPFILESTARGET [Windows and GTK Only] (non inheritable): Enable or disable the drop of +files. Default: NO, but if DROPFILES_CB is defined when the element is mapped +then it will be automatically enabled. This is NOT related to the drag&drop of +nodes inside the tree. (since 3.0)

+

DROPEQUALDRAG (non inheritable): if +enabled will allow a drop node to be equal to the drag node. Used only if SHOWDRAGDROP +=Yes. In the case the nodes are equal the callback return value is ignored and +nothing is done after. (since 3.3)

+ + +

EXPAND (non inheritable): +The default value is "YES".

+ +

FGCOLOR: default text foreground color. Once each node is +created it will not change its color when FGCOLOR is changed. Default: the global +attribute TXTFGCOLOR. (since 3.0)

+ + +

HIDEBUTTONS (creation only): hide the expand and collapse +buttons. In GTK, branches will be only expanded programmatically. In Motif it did +not work and crash the test. (since 3.0) (GTK 2.12)

+ + +

HIDELINES (creation only): hide the lines that connect the +nodes in the hierarchy. (since 3.0) (GTK 2.10)

+

INDENTATION: sets the indentation level in pixels. The visual +effect of changing the indentation is highly system dependent. In GTK it acts as +an additional indent value, and the lines do not follow the extra indent. In Windows +is limited to a minimum of 5 pixels. (since 3.0)  (GTK 2.12)

+ + +

+RASTERSIZE (non inheritable): +the initial size is "400x200". Set to NULL to allow the automatic +layout use smaller values.

+

SHOWDRAGDROP (creation only) (non inheritable): Enables the +internal drag and drop of +nodes, and enables the DRAGDROP_CB callback. Default: + "NO". Works only if MARKMODE=SINGLE.

+

SHOWTOGGLE (creation only) (non inheritable): enables the use of toggles for all nodes of the +tree. Can + be "YES", "3STATE" or NO". Default: "NO". In Motif Versions 2.1.x and 2.2.x, the images +are disabled (toggle and text only are drawn in nodes of the tree). (since 3.6)

+ +

SPACING: vertical internal padding for each node. Notice that the distance between each +node will be actually 2x the spacing. (since 3.0)

+ + +

TOPITEM (write-only): position the given node identifier at the top of +the tree or near to make it visible. If any parent node is collapsed then they +are automatically expanded. (since 3.0)

+ + + +
+
+
+

+ACTIVE, +EXPAND, +FONT, SCREENPOSITION, + +POSITION, +MINSIZE, +MAXSIZE, + WID, TIP, +SIZE, +RASTERSIZE, + ZORDER, VISIBLE: +also accepted. 

+

+The NAME common attribute is still not supported because of a backward +compatibility code. Old applications must change the use of the old NAME +attribute to TITLE, so the new NAME common attribute can be enabled in future +versions.

+

+Drag & Drop attributes are +supported, but +SHOWDRAGDROP must be set no No. 

+

Nodes  (non inheritable)

+

For these attributes "id" is the specified node identifier. If + "id" is + empty or invalid, then the focus node is used as the specified node.

+

CHILDCOUNTid (read only): returns the immediate children + count of the specified branch. It + does not count children of child that are branches. (since 3.0)

+

COLORid: text foreground color of the specified node. The value should be a string in the format "R G B" where R, G, B are numbers + from 0 to 255.

+

DEPTHid (read only): returns the depth of the specified +node. The first node has depth=0, its +immediate children has depth=1, their children has depth=2 and so on.

+

KINDid (read only): + returns the kind of the specified node. Possible values: +

+
+ +
+

PARENTid (read only): returns the identifier of the +specified node.

+

STATEid: the state of the specified branch. Returns NULL for +a LEAF. In Windows, it +will be effective only if the branch has children. In GTK, it will be effective +only if the parent is expanded. Possible values:

+
+ +
+

TITLEid: the text label of the specified node.

+

TITLEFONTid: the text font of the specified node. The format +is the same as the FONT attribute. (since +3.0)

+

TOTALCHILDCOUNTid (read only): returns the total children + count of the specified branch. It + counts all grandchildren. (since 3.0)

+

USERDATAid: the user data associated with the specified node. (since 3.0)

+

Images (non inheritable)

+

IMAGEid (write only): + image name to be used in the specified node, where id is the specified node +identifier. Use IupSetHandle or + IupSetAttributeHandle to + associate an image to a name. See also IupImage. +In Windows and Motif set the BGCOLOR attribute before setting the image. If node +is a branch it is used when collapsed.

+

IMAGEEXPANDEDid (write only): + same as the IMAGE attribute but used for expanded branches.

+

IMAGELEAF: + the image name that will be shown for all + leaves. Default: "IMGLEAF". Internal values "IMGBLANK" and "IMGPAPER" are + also available. If BGCOLOR is set the image is automatically updated.

+

IMAGEBRANCHCOLLAPSED: + the image name that will be shown for all collapsed branches. + Default: + "IMGCOLLAPSED". If BGCOLOR is set the image is automatically +updated.

+

IMAGEBRANCHEXPANDED: + the image name that will be shown for all expanded branches. + Default: + "IMGEXPANDED". If BGCOLOR is set the image is automatically +updated.

+

Focus Node

+

VALUE (non inheritable): + The focus node identifier. When retrieved but there isn't a node with focus it +returns 0 if there are any nodes, and returns -1 if there are no nodes. When +changed and MARKMODE=SINGLE the node is also selected. The tree is +always scrolled so +the node becomes visible. In Motif the tree will also receive the focus.Additionally accepts the values:

+
+

"ROOT" or "FIRST": + the first node
+"LAST": + the last visible node
+"NEXT": + the next visible node, one node after the focus node. If at the last does nothing
+"PREVIOUS": the previous visible node, one node before the focus node. If at the +first does nothing
+"PGDN": the next visible node, ten nodes node after the focus node. If +at the last does nothing
+"PGUP": the previous visible node, ten nodes before the focus node. If +at the first does nothing

+
+

Marks

+

MARK (write only) (non inheritable): Selects a range +of nodes in the format "start-end" (%d-%d). Allowed only when +MARKMODE=MULTIPLE. Also accepts the values:

+
+

"INVERTid": + Inverts the specified node mark state, where id is the specified node +identifier. If id is empty or invalid, then the focus node is used as reference node. +
+"BLOCK": Marks all nodes between the focus node and the initial block-marking +node defined by MARKSTART
+"CLEARALL": + Unmark all nodes
+"MARKALL": + Marks all nodes
+"INVERTALL": + Inverts the marking of all nodes

+
+

MARKEDid (non inheritable): The selection state of the +specified node, where id is the specified node identifier. If id is empty or +invalid, then +the focus node is used as reference node. Can be: YES or NO. Default: NO

+

MARKEDNODES (non inheritable): The selection state of all +nodes when MARKMODE=MULTIPLE. It is/accepts a sequence of '+' and '-' symbols +indicating the state of each item ('+'=selected, '-'=unselected. When setting +this value, if the number of specified symbols is smaller than the total count +then the remaining nodes will not be changed. (since 3.1)

+

MARKMODE: defines how the nodes can be +selected. Can be: +SINGLE or MULTIPLE. Default: SINGLE.

+

MARKSTART (non inheritable): + Defines the initial node for the block + marking, used when MARK=BLOCK. The value must be the node identifier. + Default: + 0 (first node).

+

TOGGLEVALUEid (non inheritable): +defines the toggle's state. Values can be "ON" or "OFF". If +SHOW3STATE=YES then can +also be "NOTDEF". Default: "OFF". (Since 3.6)

+

Hierarchy  (non inheritable)

+

For these attributes "id" is the specified node identifier. If + "id" is + empty or invalid, then the focus node is used as the specified node.

+

ADDLEAFid (write only): + Adds a new leaf +after the reference node, where id is the reference node identifier. Use id=-1 to add +before the first +node. The value is used as the +text label of the new node. The id of the new node will be the id of the +reference node + 1. + The attribute LASTADDNODE is set to the new id. The reference node is marked and all others unmarked. The reference node +position remains the same. If the reference node does not exist, nothing +happens. If the reference node is a branch then the depth of the new node is one +depth increment from the depth of the reference node, if the reference node is a +leaf then the new node has the same depth. If you need to +add a node after a specified node but at a different depth use +INSERTLEAF. Ignored if set before map.

+

ADDBRANCHid (write only): + Same as ADDLEAF for branches. Branches can be created +expanded or collapsed depending on ADDEXPANDED. Ignored if set +before map.

+ +

COPYNODEid (write only): Copies a node and its children, +where id is the specified node identifier. The value is the destination node identifier. If +the destination node is a branch and it is expanded, then the specified node is +inserted as the first child of the destination node. If the branch is not +expanded or the destination node is a leaf, then it is inserted as the next +brother of the leaf. The specified node is not changed. All node attributes are +copied, except user data. Ignored if set before map. (since 3.0)

+ +

DELNODEid (write only): + Removes a node and/or its children, where id is the specified node identifier. +Ignored if set before map. Possible values:

+
+ +
+

EXPANDALL (write only): expand or contracts all nodes. Can +be YES (expand all), or NO (contract all). (since 3.0)

+ +

INSERTLEAFid, INSERTBRANCHid +(write only): Same as ADDLEAF and ADDBRANCH but +the depth of the new node is always the same of the reference node. If the +reference node is a leaf, then the id of the new node will be the id of the +reference node + 1. If the reference node is a branch the id of the new node +will be the id of the reference node + 1 + the total number of child nodes of +the reference node. (since 3.0)

+ +

MOVENODEid (write only): Moves a node and its children, +where id is the specified node identifier. The value is the destination node identifier. If +the destination node is a branch and it is expanded, then the specified node is +inserted as the first child of the destination node. If the branch is not +expanded or the destination node is a leaf, then it is inserted as the next +brother of the leaf. The specified node is removed. User data and all node +attributes are preserved. Ignored if set before map. (since 3.0)

+

Editing

+

RENAME (write only): Forces a rename action to take place. Valid only +when SHOWRENAME=YES.

+ +

RENAMECARET (write only): + the caret’s + position of the text box when in-place renaming. Same as the CARET attribute +for IupText, but here is used only once +after SHOWRENAME_CB is called and before the text box is shown.

+

RENAMESELECTION (write only): + the selection + interval + of the text box when in-place renaming. Same as the SELECTION attribute for +IupText, but here is used only once after SHOWRENAME_CB +is called and before the text box is shown.

+

SHOWRENAME (creation in Windows) (non inheritable): Allows the in place rename of a +node. Default: + "NO". Since IUP 3.0, F2 and clicking twice only starts to rename a +node if SHOWRENAME=Yes. In Windows must be set to YES before map, but can be +changed later (since 3.3).

+ + + + \ No newline at end of file diff --git a/iup/html/en/elem/iuptree_cb.html b/iup/html/en/elem/iuptree_cb.html new file mode 100644 index 00000000..918adf04 --- /dev/null +++ b/iup/html/en/elem/iuptree_cb.html @@ -0,0 +1,243 @@ + + + + +IupTree Callbacks + + + + + + +

IupTree Callbacks

+

SELECTION_CB: Action generated when a node is selected + or deselected. This action occurs when the user clicks with the mouse or uses the keyboard with the appropriate + combination of keys. It may be called more than once for the same node with +the same status.

+
int function(Ihandle *ih, int id, int status) [in C]
+elem:selection_cb(id, status: number) -> (ret: number) [in Lua]
+

ih: identifier of the element that activated +the event.
+id: + Node identifier.
+ status: 1=node selected, 0=node unselected.

+

MULTISELECTION_CB: + Action generated + after a continuous range of nodes is selected in one single operation. If +not defined the SELECTION_CB with status=1 will be called for all nodes in the +range. The range is always completely included, independent if some nodes were already +marked. That single operation also guaranties that all other nodes outside the +range are already not selected. Called only if MARKMODE=MULTIPLE.

+
int function(Ihandle *ih, int* ids, int n) [in C]
+elem:multiselection_cb(ids: table, n: number) -> (ret: number) [in Lua]
+

ih: identifier of the element that activated +the event.
+ids: + Array of node identifiers. This array is kept for backward compatibility, +the range is simply defined by ids[0] to ids[n-1], where ids[i+1]=ids[i]+1.
+n: Number of nodes in the array.

+

MULTIUNSELECTION_CB: + Action generated + before multiple nodes are unselected in one single operation. If +not defined the SELECTION_CB with status=0 will be called for all nodes in the +range. The range is not necessarily continuous. Called only if MARKMODE=MULTIPLE. +(Since 3.1)

+
int function(Ihandle *ih, int* ids, int n) [in C]
+elem:multiunselection_cb(ids: table, n: number) -> (ret: number) [in Lua]
+

ih: identifier of the element that activated +the event.
+ids: + Array of node identifiers.
+n: Number of nodes in the array.

+
+

BRANCHOPEN_CB: + Action generated when a branch is expanded. + This action occurs when the user clicks the "+" sign on the left of the branch, or when double clicks the branch, or hits Enter on a collapsed branch.

+
int function(Ihandle *ih, int id) [in C] 
+elem:branchopen_cb(id: number) -> (ret: number) [in Lua]
+

ih: identifier of the element that activated +the event.
+id: + node identifier.

+

Returns: IUP_IGNORE for the branch not to be opened, or IUP_DEFAULT for the branch to be opened.

+

BRANCHCLOSE_CB: + Action generated when a branch is collapsed. + This action occurs when the user clicks the "-" + sign on the left of the branch, or when double + clicks + the branch, or hits Enter on an expanded branch. +

+
int function(Ihandle *ih, int id); [in C]
+elem:branchclose_cb(id: number) -> (ret: number) [in Lua]
+

ih: identifier of the element that activated +the event.
+id: + node identifier.

+

Returns: IUP_IGNORE for the branch not to be closed, or IUP_DEFAULT for the branch to be closed.

+

EXECUTELEAF_CB: + Action generated when a leaf is to be + executed. This action occurs when the user double clicks a + leaf, or hits Enter on a leaf. +

+
int function(Ihandle *ih, int id); [in C] 
+elem:executeleaf_cb(id: number) -> (ret: number) [in Lua]
+

ih: identifier of the element that activated +the event.
+id: + node identifier.  +
+

+
+

SHOWRENAME_CB: + Action generated when a node is about to be renamed. + It occurs when the user clicks twice the node or press +F2. Called only if SHOWRENAME=YES.

+
int function(Ihandle *ih, int id); [in C]
+elem:showrename_cb(id: number: string) -> (ret: number) [in Lua]
+

ih: identifier of the element that activated +the event.
+id: + node identifier.  +

+

Returns: if IUP_IGNORE is returned, +the rename is canceled (in GTK the rename continuous but the edit box is +read-only).
+

+

RENAME_CB: + Action generated after a node was renamed in + place. It occurs when the user press Enter after editing the name, or when the text box looses it focus. +Called only if SHOWRENAME=YES.

+
int function(Ihandle *ih, int id, char *title); [in C]
+elem:rename_cb(id: number, title: string) -> (ret: number) [in Lua]
+

ih: identifier of the element that activated +the event.
+id: + node identifier.
+title: new node title.

+

Returns: The new title is accepted only if the callback returns IUP_DEFAULT. If the callback does not exists the new +title + is always accepted. If the user pressed Enter and the callback returns IUP_IGNORE the editing continues. If + the text box looses its focus the editing stops always.
+

+
+

DRAGDROP_CB: + Action generated when + an internal drag & drop is executed. Only active if SHOWDRAGDROP=YES.

+
int function(Ihandle *ih, int drag_id, int drop_id, int isshift, int iscontrol); [in C] 
+elem:dragdrop_cb(drag_id, drop_id, isshift, iscontrol: number) -> (ret: number) [in Lua]
+

ih: identifier of the element that activated +the event.
+drag_id: + Identifier of the clicked node where the + drag start.
+drop_id: + Identifier of the clicked node where the + drop were executed. -1 indicates a drop in a blank area.
+isshift: Boolean flag indicating the shift key state.
+iscontrol: Boolean flag indicating the control key state.

+

Returns: if returns IUP_CONTINUE, or +if the callback is not defined and SHOWDRAGDROP=YES, then the node +is moved to the new position. If Ctrl is pressed then the node is copied instead +of moved. If the drop node is a branch and it is expanded, +then the drag node is inserted as the first child of the node. If the branch is +not expanded or the node is a leaf, then the drag node is inserted as the next brother +of the drop node.
+

+

NODEREMOVED_CB: + Action generated when a node is going to be removed. It is only a +notification, the action can not be aborted. No node dependent attribute can be +consulted during the callback. Not called when the tree is unmapped. It is +useful to remove memory allocated for the +userdata. (since 3.0)

+
int function(Ihandle *ih, void* userdata); [in C] 
+elem:noderemoved_cb(userid: userdata/table) -> (ret: number) [in Lua]
+

ih: identifier of the element that activated +the event.
+userdata/userid: USERDATA attribute in C, or userid object in +Lua.

+ + + +

RIGHTCLICK_CB: Action generated when the right mouse button +is pressed over a node.

+
int function(Ihandle *ih, int id); [in C] 
+elem:rightclick_cb(id: number) -> (ret: number) [in Lua]
+

ih: identifier of the element that activated +the event.
+id: + node identifier.

+ + + +
+ + + +

TOGGLEVALUE_CB: Action generated when the toggle's state was +changed. The callback also receives the new toggle's state. (since 3.6)

+
int function(Ihandle *ih, int id, int state); [in C]
+elem:togglevalue_cb(id, state: number: string) -> (ret: number) [in Lua]
+

ih: + identifier of the element that activated the + event.
+id: + node identifier.
+ + state: + 1 if the toggle's state was shifted to ON; 0 if it was shifted to OFF. If +SHOW3STATE=YES, −1 if it was shifted to NOTDEF.

+
+ + + +

BUTTON_CB: + Action generated when any mouse button is + pressed or released inside the element. Use +IupConvertXYToPos to convert + (x,y) coordinates in the node identifier. (since 3.0)

+ + + + +

MOTION_CB: + Action generated when the mouse is moved over the element. Use +IupConvertXYToPos + to convert (x,y) coordinates in item the node identifier. (since 3.0)

+ + + +

DROPFILES_CB [Windows and GTK Only]: Action generated when one or + more files are dropped in the element. (since 3.0)

+ + + + +
+ + +

MAP_CB, +UNMAP_CB, +GETFOCUS_CB, + KILLFOCUS_CB, +ENTERWINDOW_CB, + LEAVEWINDOW_CB, +K_ANY, + HELP_CB: All common callbacks are +supported.

+ +

In Motif the tree always resets the focus to the first node when receive the +focus. The KILLFOCUS_CB callback is called only when the focus is at the first +node. Also in Motif some LEAVEWINDOW_CB events are delayed to when the user +enter again, firing a leave and enter events at enter time.

+

+Drag & Drop callbacks are +supported, but +SHOWDRAGDROP must be set to NO. 

+ + + + diff --git a/iup/mak.vc9/iupsample.vcproj b/iup/mak.vc9/iupsample.vcproj new file mode 100644 index 00000000..6bbba128 --- /dev/null +++ b/iup/mak.vc9/iupsample.vcproj @@ -0,0 +1,1203 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/iup/srcpplot/iup_pplot.cpp b/iup/srcpplot/iup_pplot.cpp new file mode 100644 index 00000000..24774d57 --- /dev/null +++ b/iup/srcpplot/iup_pplot.cpp @@ -0,0 +1,3171 @@ +/* + * IupPPlot component + * + * Description : A component, derived from PPlot and IUP canvas + * Remark : Depend on libs IUP, CD, IUPCD + */ + + +#ifdef _MSC_VER +#pragma warning(disable: 4100) +#pragma warning(disable: 4512) +#endif + +//#define USE_OPENGL 1 +// Not fully working, needs improvements in CD_GL + +#ifdef USE_OPENGL +#ifdef WIN32 +#include +#endif +#ifdef __APPLE__ +#include +#include +#else +#include +#include +#endif +#endif + +#include +#include +#include +#include + +#include "iup.h" +#include "iupcbs.h" +#include "iup_pplot.h" +#include "iupkey.h" +#ifdef USE_OPENGL +#include "iupgl.h" +#endif + +#include +#ifdef USE_OPENGL +#include +#else +#include +#include +#include +#endif + +#include "iup_class.h" +#include "iup_register.h" +#include "iup_object.h" +#include "iup_attrib.h" +#include "iup_str.h" +#include "iup_drv.h" +#include "iup_stdcontrols.h" +#include "iup_assert.h" + +#include "iupPPlot.h" +#include "iupPPlotInteraction.h" +#include "iuppplot.hpp" + + +#ifndef M_E +#define M_E 2.71828182846 +#endif + +struct _IcontrolData +{ + iupCanvas canvas; /* from IupCanvas (must reserve it) */ + PPainterIup* plt; +}; + + +static int iPPlotGetCDFontStyle(const char* value); + + +/* PPlot function pointer typedefs. */ +typedef int (*IFnC)(Ihandle*, cdCanvas*); /* postdraw_cb, predraw_cb */ +typedef int (*IFniiff)(Ihandle*, int, int, float, float); /* delete_cb */ +typedef int (*IFniiffi)(Ihandle*, int, int, float, float, int); /* select_cb */ +typedef int (*IFniiffff)(Ihandle*, int, int, float, float, float*, float*); /* edit_cb */ + + +/* callback: forward redraw request to PPlot object */ +static int iPPlotRedraw_CB(Ihandle* ih) +{ + ih->data->plt->Draw(0, 1); /* full redraw only if nothing changed */ + return IUP_DEFAULT; +} + +/* callback: forward resize request to PPlot object */ +static int iPPlotResize_CB(Ihandle* ih, int w, int h) +{ + ih->data->plt->Resize(w, h); + return IUP_DEFAULT; +} + +/* callback: forward mouse button events to PPlot object */ +static int iPPlotMouseButton_CB(Ihandle* ih, int btn, int stat, int x, int y, char* r) +{ + ih->data->plt->MouseButton(btn, stat, x, y, r); + return IUP_DEFAULT; +} + +/* callback: forward mouse button events to PPlot object */ +static int iPPlotMouseMove_CB(Ihandle* ih, int x, int y) +{ + ih->data->plt->MouseMove(x, y); + return IUP_DEFAULT; +} + +/* callback: forward keyboard events to PPlot object */ +static int iPPlotKeyPress_CB(Ihandle* ih, int c, int press) +{ + ih->data->plt->KeyPress(c, press); + return IUP_DEFAULT; +} + +/* user level call: add dataset to plot */ +void IupPPlotBegin(Ihandle* ih, int strXdata) +{ + iupASSERT(iupObjectCheck(ih)); + if (!iupObjectCheck(ih)) + return; + + if (ih->iclass->nativetype != IUP_TYPECANVAS || + !IupClassMatch(ih, "pplot")) + return; + + PlotDataBase* inXData = (PlotDataBase*)iupAttribGet(ih, "_IUP_PPLOT_XDATA"); + PlotDataBase* inYData = (PlotDataBase*)iupAttribGet(ih, "_IUP_PPLOT_YDATA"); + + if (inXData) delete inXData; + if (inYData) delete inYData; + + if (strXdata) + inXData = (PlotDataBase*)(new StringPlotData()); + else + inXData = (PlotDataBase*)(new PlotData()); + + inYData = (PlotDataBase*)new PlotData(); + + iupAttribSetStr(ih, "_IUP_PPLOT_XDATA", (char*)inXData); + iupAttribSetStr(ih, "_IUP_PPLOT_YDATA", (char*)inYData); +} + +void IupPPlotAdd(Ihandle* ih, float x, float y) +{ + iupASSERT(iupObjectCheck(ih)); + if (!iupObjectCheck(ih)) + return; + + if (ih->iclass->nativetype != IUP_TYPECANVAS || + !IupClassMatch(ih, "pplot")) + return; + + PlotData* inXData = (PlotData*)iupAttribGet(ih, "_IUP_PPLOT_XDATA"); + PlotData* inYData = (PlotData*)iupAttribGet(ih, "_IUP_PPLOT_YDATA"); + + if (!inYData || !inXData || inXData->IsString()) + return; + + inXData->push_back(x); + inYData->push_back(y); +} + +void IupPPlotAddStr(Ihandle* ih, const char* x, float y) +{ + iupASSERT(iupObjectCheck(ih)); + if (!iupObjectCheck(ih)) + return; + + if (ih->iclass->nativetype != IUP_TYPECANVAS || + !IupClassMatch(ih, "pplot")) + return; + + StringPlotData *inXData = (StringPlotData*)iupAttribGet(ih, "_IUP_PPLOT_XDATA"); + PlotData *inYData = (PlotData*)iupAttribGet(ih, "_IUP_PPLOT_YDATA"); + + if (!inYData || !inXData || !inXData->IsString()) + return; + + inXData->AddItem(x); + inYData->push_back(y); +} + +void IupPPlotInsertStr(Ihandle* ih, int inIndex, int inSampleIndex, const char* inX, float inY) +{ + iupASSERT(iupObjectCheck(ih)); + if (!iupObjectCheck(ih)) + return; + + if (ih->iclass->nativetype != IUP_TYPECANVAS || + !IupClassMatch(ih, "pplot")) + return; + + PlotDataBase* theXDataBase = ih->data->plt->_plot.mPlotDataContainer.GetXData(inIndex); + PlotDataBase* theYDataBase = ih->data->plt->_plot.mPlotDataContainer.GetYData(inIndex); + StringPlotData *theXData = (StringPlotData*)theXDataBase; + PlotData *theYData = (PlotData*)theYDataBase; + + if (!theYData || !theXData || !theXData->IsString()) + return; + + theXData->InsertItem(inSampleIndex, inX); + theYData->insert(theYData->begin()+inSampleIndex, inY); +} + +void IupPPlotInsert(Ihandle* ih, int inIndex, int inSampleIndex, float inX, float inY) +{ + iupASSERT(iupObjectCheck(ih)); + if (!iupObjectCheck(ih)) + return; + + if (ih->iclass->nativetype != IUP_TYPECANVAS || + !IupClassMatch(ih, "pplot")) + return; + + PlotDataBase* theXDataBase = ih->data->plt->_plot.mPlotDataContainer.GetXData(inIndex); + PlotDataBase* theYDataBase = ih->data->plt->_plot.mPlotDataContainer.GetYData(inIndex); + PlotData* theXData = (PlotData*)theXDataBase; + PlotData* theYData = (PlotData*)theYDataBase; + + if (!theYData || !theXData || theXData->IsString()) + return; + + theXData->insert(theXData->begin()+inSampleIndex, inX); + theYData->insert(theYData->begin()+inSampleIndex, inY); +} + +void IupPPlotAddPoints(Ihandle* ih, int inIndex, float *x, float *y, int count) +{ + iupASSERT(iupObjectCheck(ih)); + if (!iupObjectCheck(ih)) + return; + + if (ih->iclass->nativetype != IUP_TYPECANVAS || + !IupClassMatch(ih, "pplot")) + return; + + PlotDataBase* theXDataBase = ih->data->plt->_plot.mPlotDataContainer.GetXData(inIndex); + PlotDataBase* theYDataBase = ih->data->plt->_plot.mPlotDataContainer.GetYData(inIndex); + PlotData* inXData = (PlotData*)theXDataBase; + PlotData* inYData = (PlotData*)theYDataBase; + + if (!inYData || !inXData || inXData->IsString()) + return; + + for (int i=0; ipush_back(x[i]); + inYData->push_back(y[i]); + } +} + +void IupPPlotAddStrPoints(Ihandle* ih, int inIndex, const char** x, float* y, int count) +{ + iupASSERT(iupObjectCheck(ih)); + if (!iupObjectCheck(ih)) + return; + + if (ih->iclass->nativetype != IUP_TYPECANVAS || + !IupClassMatch(ih, "pplot")) + return; + + PlotDataBase* theXDataBase = ih->data->plt->_plot.mPlotDataContainer.GetXData(inIndex); + PlotDataBase* theYDataBase = ih->data->plt->_plot.mPlotDataContainer.GetYData(inIndex); + StringPlotData *inXData = (StringPlotData*)theXDataBase; + PlotData *inYData = (PlotData*)theYDataBase; + + if (!inYData || !inXData || !inXData->IsString()) + return; + + for (int i=0; iAddItem(x[i]); + inYData->push_back(y[i]); + } +} + +void IupPPlotInsertStrPoints(Ihandle* ih, int inIndex, int inSampleIndex, const char** inX, float* inY, int count) +{ + iupASSERT(iupObjectCheck(ih)); + if (!iupObjectCheck(ih)) + return; + + if (ih->iclass->nativetype != IUP_TYPECANVAS || + !IupClassMatch(ih, "pplot")) + return; + + PlotDataBase* theXDataBase = ih->data->plt->_plot.mPlotDataContainer.GetXData(inIndex); + PlotDataBase* theYDataBase = ih->data->plt->_plot.mPlotDataContainer.GetYData(inIndex); + StringPlotData *theXData = (StringPlotData*)theXDataBase; + PlotData *theYData = (PlotData*)theYDataBase; + + if (!theYData || !theXData || !theXData->IsString()) + return; + + for (int i=0; iInsertItem(inSampleIndex+i, inX[i]); + theYData->insert(theYData->begin()+(inSampleIndex+i), inY[i]); + } +} + +void IupPPlotInsertPoints(Ihandle* ih, int inIndex, int inSampleIndex, float *inX, float *inY, int count) +{ + iupASSERT(iupObjectCheck(ih)); + if (!iupObjectCheck(ih)) + return; + + if (ih->iclass->nativetype != IUP_TYPECANVAS || + !IupClassMatch(ih, "pplot")) + return; + + PlotDataBase* theXDataBase = ih->data->plt->_plot.mPlotDataContainer.GetXData(inIndex); + PlotDataBase* theYDataBase = ih->data->plt->_plot.mPlotDataContainer.GetYData(inIndex); + PlotData* theXData = (PlotData*)theXDataBase; + PlotData* theYData = (PlotData*)theYDataBase; + + if (!theYData || !theXData || theXData->IsString()) + return; + + for (int i=0; iinsert(theXData->begin()+(inSampleIndex+i), inX[i]); + theYData->insert(theYData->begin()+(inSampleIndex+i), inY[i]); + } +} + +int IupPPlotEnd(Ihandle* ih) +{ + iupASSERT(iupObjectCheck(ih)); + if (!iupObjectCheck(ih)) + return -1; + + if (ih->iclass->nativetype != IUP_TYPECANVAS || + !IupClassMatch(ih, "pplot")) + return -1; + + PlotDataBase* inXData = (PlotDataBase*)iupAttribGet(ih, "_IUP_PPLOT_XDATA"); + PlotDataBase* inYData = (PlotDataBase*)iupAttribGet(ih, "_IUP_PPLOT_YDATA"); + if (!inYData || !inXData) + return -1; + + /* add to plot */ + ih->data->plt->_currentDataSetIndex = ih->data->plt->_plot.mPlotDataContainer.AddXYPlot(inXData, inYData); + + LegendData* legend = ih->data->plt->_plot.mPlotDataContainer.GetLegendData(ih->data->plt->_currentDataSetIndex); + legend->mStyle.mFontStyle = iPPlotGetCDFontStyle(IupGetAttribute(ih, "LEGENDFONTSTYLE")); + legend->mStyle.mFontSize = IupGetInt(ih, "LEGENDFONTSIZE"); + + iupAttribSetStr(ih, "_IUP_PPLOT_XDATA", NULL); + iupAttribSetStr(ih, "_IUP_PPLOT_YDATA", NULL); + + ih->data->plt->_redraw = 1; + return ih->data->plt->_currentDataSetIndex; +} + +void IupPPlotTransform(Ihandle* ih, float x, float y, int *ix, int *iy) +{ + iupASSERT(iupObjectCheck(ih)); + if (!iupObjectCheck(ih)) + return; + + if (ih->iclass->nativetype != IUP_TYPECANVAS || + !IupClassMatch(ih, "pplot")) + return; + + if (ix) *ix = ih->data->plt->_plot.Round(ih->data->plt->_plot.mXTrafo->Transform(x)); + if (iy) *iy = ih->data->plt->_plot.Round(ih->data->plt->_plot.mYTrafo->Transform(y)); +} + +/* user level call: plot on the given device */ +void IupPPlotPaintTo(Ihandle* ih, void* _cnv) +{ + iupASSERT(iupObjectCheck(ih)); + if (!iupObjectCheck(ih)) + return; + + if (ih->iclass->nativetype != IUP_TYPECANVAS || + !IupClassMatch(ih, "pplot")) + return; + + ih->data->plt->DrawTo((cdCanvas *)_cnv); +} + +/* -------------------------------------------------------------------- + class implementation + -------------------------------------------------------------------- */ + +PostPainterCallbackIup::PostPainterCallbackIup (PPlot &inPPlot, Ihandle* inHandle): + _ih(inHandle) +{ + inPPlot.mPostDrawerList.push_back (this); +} + +bool PostPainterCallbackIup::Draw(Painter &inPainter) +{ + IFnC cb = (IFnC)IupGetCallback(_ih, "POSTDRAW_CB"); + + if (cb) + { + PPainterIup* iupPainter = (PPainterIup*)(&inPainter); + cb(_ih, iupPainter->_cddbuffer); + } + + return true; +} + +PrePainterCallbackIup::PrePainterCallbackIup (PPlot &inPPlot, Ihandle* inHandle): + _ih(inHandle) +{ + inPPlot.mPreDrawerList.push_back (this); +} + +bool PrePainterCallbackIup::Draw(Painter &inPainter) +{ + IFnC cb = (IFnC)IupGetCallback(_ih, "PREDRAW_CB"); + if (cb) + { + PPainterIup* iupPainter = (PPainterIup*)(&inPainter); + cb(_ih, iupPainter->_cddbuffer); + } + + return true; +} + +bool PDeleteInteractionIup::DeleteNotify(int inIndex, int inSampleIndex, PlotDataBase* inXData, PlotDataBase* inYData) +{ + IFniiff cb = (IFniiff)IupGetCallback(_ih, "DELETE_CB"); + if (cb) + { + if (inIndex == -1) + { + Icallback cbb = IupGetCallback(_ih, "DELETEBEGIN_CB"); + if (cbb && cbb(_ih) == IUP_IGNORE) + return false; + } + else if (inIndex == -2) + { + Icallback cbb = IupGetCallback(_ih, "DELETEEND_CB"); + if (cbb) + cbb(_ih); + } + else + { + float theX = inXData->GetValue(inSampleIndex); + float theY = inYData->GetValue(inSampleIndex); + int ret = cb(_ih, inIndex, inSampleIndex, theX, theY); + if (ret == IUP_IGNORE) + return false; + } + } + + return true; +} + +bool PSelectionInteractionIup::SelectNotify(int inIndex, int inSampleIndex, PlotDataBase* inXData, PlotDataBase* inYData, bool inSelect) +{ + IFniiffi cb = (IFniiffi)IupGetCallback(_ih, "SELECT_CB"); + if (cb) + { + if (inIndex == -1) + { + Icallback cbb = IupGetCallback(_ih, "SELECTBEGIN_CB"); + if (cbb && cbb(_ih) == IUP_IGNORE) + return false; + } + else if (inIndex == -2) + { + Icallback cbb = IupGetCallback(_ih, "SELECTEND_CB"); + if (cbb) + cbb(_ih); + } + else + { + float theX = inXData->GetValue(inSampleIndex); + float theY = inYData->GetValue(inSampleIndex); + int ret = cb(_ih, inIndex, inSampleIndex, theX, theY, (int)inSelect); + if (ret == IUP_IGNORE) + return false; + } + } + + return true; +} + +bool PEditInteractionIup::Impl_HandleKeyEvent (const PKeyEvent &inEvent) +{ + if (inEvent.IsArrowDown () || inEvent.IsArrowUp () || + inEvent.IsArrowLeft () || inEvent.IsArrowRight ()) + return true; + + return false; +}; + +bool PEditInteractionIup::Impl_Calculate (Painter &inPainter, PPlot& inPPlot) +{ + PlotDataContainer &theContainer = inPPlot.mPlotDataContainer; + long thePlotCount = theContainer.GetPlotCount(); + + if (!EditNotify(-1, 0, 0, 0, NULL, NULL)) + return false; + + for (long theI=0;theIGetSize ();theI++) + { + if (inPlotDataSelection->IsSelected (theI)) + { + float theX = inXData->GetValue(theI); + float newX = theX; + + if (theXDelta) + { + float theXPixels = mPPlot.mXTrafo->Transform(theX); + theXPixels += theXDelta; + newX = mPPlot.mXTrafo->TransformBack(theXPixels); + } + + float theY = inYData->GetValue(theI); + float newY = theY; + if (theYDelta) + { + float theYPixels = mPPlot.mYTrafo->Transform(theY); + theYPixels -= theYDelta; /* in pixels Y is descending */ + newY = mPPlot.mYTrafo->TransformBack(theYPixels); + } + + if (!EditNotify(inIndex, theI, theX, theY, &newX, &newY)) + return; + + if (inXData->IsString()) + { + StringPlotData *theXData = (StringPlotData*)(inXData); + PlotData* theYData = (PlotData*)(inYData); + theXData->mRealPlotData[theI] = newX; + (*theYData)[theI] = newY; + } + else + { + PlotData* theXData = (PlotData*)(inXData); + PlotData* theYData = (PlotData*)(inYData); + (*theXData)[theI] = newX; + (*theYData)[theI] = newY; + } + } + } +} + +bool PEditInteractionIup::EditNotify(int inIndex, int inSampleIndex, float inX, float inY, float *inNewX, float *inNewY) +{ + IFniiffff cb = (IFniiffff)IupGetCallback(_ih, "EDIT_CB"); + if (cb) + { + if (inIndex == -1) + { + Icallback cbb = IupGetCallback(_ih, "EDITBEGIN_CB"); + if (cbb && cbb(_ih) == IUP_IGNORE) + return false; + } + else if (inIndex == -2) + { + Icallback cbb = IupGetCallback(_ih, "EDITEND_CB"); + if (cbb) + cbb(_ih); + } + else + { + int ret = cb(_ih, inIndex, inSampleIndex, inX, inY, inNewX, inNewY); + if (ret == IUP_IGNORE) + return false; + } + } + + return true; +} + +InteractionContainerIup::InteractionContainerIup(PPlot &inPPlot, Ihandle* inHandle): + mZoomInteraction (inPPlot), + mSelectionInteraction (inPPlot, inHandle), + mEditInteraction (inPPlot, inHandle), + mDeleteInteraction (inPPlot, inHandle), + mCrosshairInteraction (inPPlot), + mPostPainterCallback(inPPlot, inHandle), + mPrePainterCallback(inPPlot, inHandle) +{ + AddInteraction (mZoomInteraction); + AddInteraction (mSelectionInteraction); + AddInteraction (mEditInteraction); + AddInteraction (mDeleteInteraction); + AddInteraction (mCrosshairInteraction); +} + +PPainterIup::PPainterIup(Ihandle *ih) : + Painter(), + _ih(ih), +#ifndef USE_OPENGL + _cdcanvas(NULL), +#endif + _cddbuffer(NULL), + _mouseDown(0), + _currentDataSetIndex(-1), + _redraw(1) +{ + _plot.mShowLegend = false; /* change default to hidden */ + _plot.mPlotBackground.mTransparent = false; /* always draw the background */ + _plot.mMargins.mLeft = 15; + _plot.mMargins.mBottom = 15; + _plot.mMargins.mTop = 30; + _plot.mMargins.mRight = 15; + _plot.mXAxisSetup.mTickInfo.mTickDivision = 5; + _plot.mYAxisSetup.mTickInfo.mTickDivision = 5; + _plot.mXAxisSetup.mTickInfo.mMinorTickScreenSize = 5; + _plot.mYAxisSetup.mTickInfo.mMinorTickScreenSize = 5; + _plot.mXAxisSetup.mTickInfo.mMajorTickScreenSize = 8; + _plot.mYAxisSetup.mTickInfo.mMajorTickScreenSize = 8; + + _InteractionContainer = new InteractionContainerIup(_plot, _ih); + +} /* c-tor */ + + +PPainterIup::~PPainterIup() +{ + delete _InteractionContainer; +} /* d-tor */ + +class MarkDataDrawer: public LineDataDrawer +{ + public: + MarkDataDrawer (bool inDrawLine) + { + mDrawLine = inDrawLine; + mDrawPoint = true; + mMode = inDrawLine ? "MARKLINE" : "MARK"; + }; + virtual bool DrawPoint (int inScreenX, int inScreenY, const PRect &inRect, Painter &inPainter) const; +}; + +bool MarkDataDrawer::DrawPoint (int inScreenX, int inScreenY, const PRect &inRect, Painter &inPainter) const +{ + PPainterIup* painter = (PPainterIup*)&inPainter; + cdCanvasMark(painter->_cddbuffer, inScreenX, cdCanvasInvertYAxis(painter->_cddbuffer, inScreenY)); + + return true; +} + +static void RemoveSample(PPlot& inPPlot, int inIndex, int inSampleIndex) +{ + PlotDataBase* theXDataBase = inPPlot.mPlotDataContainer.GetXData(inIndex); + PlotDataBase* theYDataBase = inPPlot.mPlotDataContainer.GetYData(inIndex); + + if (theXDataBase->IsString()) + { + StringPlotData *theXData = (StringPlotData *)theXDataBase; + PlotData* theYData = (PlotData*)theYDataBase; + theXData->mRealPlotData.erase(theXData->mRealPlotData.begin()+inSampleIndex); + theXData->mStringPlotData.erase(theXData->mStringPlotData.begin()+inSampleIndex); + theYData->erase(theYData->begin()+inSampleIndex); + } + else + { + PlotData* theXData = (PlotData*)theXDataBase; + PlotData* theYData = (PlotData*)theYDataBase; + theXData->erase(theXData->begin()+inSampleIndex); + theYData->erase(theYData->begin()+inSampleIndex); + } +} + +/* -------------------------------------------------------------------- + CD Gets - size and style + -------------------------------------------------------------------- */ + +static int iPPlotGetCDFontStyle(const char* value) +{ + if (!value) + return -1; + if (iupStrEqualNoCase(value, "PLAIN")) + return CD_PLAIN; + if (iupStrEqualNoCase(value, "BOLD")) + return CD_BOLD; + if (iupStrEqualNoCase(value, "ITALIC")) + return CD_ITALIC; + if (iupStrEqualNoCase(value, "BOLDITALIC")) + return CD_BOLD_ITALIC; + return -1; +} + +static char* iPPlotGetPlotFontSize(int size) +{ + if (size) + { + char* buffer = iupStrGetMemory(50); + sprintf(buffer, "%d", size); + return buffer; + } + else + return NULL; +} + +static char* iPPlotGetPlotFontStyle(int style) +{ + if (style >= CD_PLAIN && style <= CD_BOLD_ITALIC) + { + char* style_str[4] = {"PLAIN", "BOLD", "ITALIC", "BOLDITALIC"}; + return style_str[style]; + } + else + return NULL; +} + +static char* iPPlotGetPlotPenStyle(int style) +{ + if (style >= CD_CONTINUOUS && style <= CD_DASH_DOT_DOT) + { + char* style_str[5] = {"CONTINUOUS", "DASHED", "DOTTED", "DASH_DOT", "DASH_DOT_DOT"}; + return style_str[style]; + } + else + return NULL; +} + +static int iPPlotGetCDPenStyle(const char* value) +{ + if (!value || iupStrEqualNoCase(value, "CONTINUOUS")) + return CD_CONTINUOUS; + else if (iupStrEqualNoCase(value, "DASHED")) + return CD_DASHED; + else if (iupStrEqualNoCase(value, "DOTTED")) + return CD_DOTTED; + else if (iupStrEqualNoCase(value, "DASH_DOT")) + return CD_DASH_DOT; + else if (iupStrEqualNoCase(value, "DASH_DOT_DOT")) + return CD_DASH_DOT_DOT; + else + return CD_CONTINUOUS; +} + +static char* iPPlotGetPlotMarkStyle(int style) +{ + if (style >= CD_PLUS && style <= CD_HOLLOW_DIAMOND) + { + char* style_str[9] = {"PLUS", "STAR", "CIRCLE", "X", "BOX", "DIAMOND", "HOLLOW_CIRCLE", "HOLLOW_BOX", "HOLLOW_DIAMOND"}; + return style_str[style]; + } + else + return NULL; +} + +static int iPPlotGetCDMarkStyle(const char* value) +{ + if (!value || iupStrEqualNoCase(value, "PLUS")) + return CD_PLUS; + else if (iupStrEqualNoCase(value, "STAR")) + return CD_STAR; + else if (iupStrEqualNoCase(value, "CIRCLE")) + return CD_CIRCLE; + else if (iupStrEqualNoCase(value, "X")) + return CD_X; + else if (iupStrEqualNoCase(value, "BOX")) + return CD_BOX; + else if (iupStrEqualNoCase(value, "DIAMOND")) + return CD_DIAMOND; + else if (iupStrEqualNoCase(value, "HOLLOW_CIRCLE")) + return CD_HOLLOW_CIRCLE; + else if (iupStrEqualNoCase(value, "HOLLOW_BOX")) + return CD_HOLLOW_BOX; + else if (iupStrEqualNoCase(value, "HOLLOW_DIAMOND")) + return CD_HOLLOW_DIAMOND; + else + return CD_PLUS; +} + +/*****************************************************************************/ +/***** SET AND GET ATTRIBUTES ************************************************/ +/*****************************************************************************/ + +/* refresh plot window (write only) */ +static int iPPlotSetRedrawAttrib(Ihandle* ih, const char* value) +{ + (void)value; /* not used */ + ih->data->plt->Draw(1, 1); /* force a full redraw here */ + return 0; +} + +/* total number of datasets (read only) */ +static char* iPPlotGetCountAttrib(Ihandle* ih) +{ + char* buffer = iupStrGetMemory(30); + sprintf(buffer, "%d", ih->data->plt->_plot.mPlotDataContainer.GetPlotCount()); + return buffer; +} + +/* legend box visibility */ +static int iPPlotSetLegendShowAttrib(Ihandle* ih, const char* value) +{ + if (iupStrBoolean(value)) + ih->data->plt->_plot.mShowLegend = true; + else + ih->data->plt->_plot.mShowLegend = false; + + ih->data->plt->_redraw = 1; + return 0; +} + +static char* iPPlotGetLegendShowAttrib(Ihandle* ih) +{ + if (ih->data->plt->_plot.mShowLegend) + return "YES"; + else + return "NO"; +} + +/* legend box visibility */ +static int iPPlotSetLegendPosAttrib(Ihandle* ih, const char* value) +{ + if (iupStrEqualNoCase(value, "TOPLEFT")) + ih->data->plt->_plot.mLegendPos = PPLOT_TOPLEFT; + else if (iupStrEqualNoCase(value, "BOTTOMLEFT")) + ih->data->plt->_plot.mLegendPos = PPLOT_BOTTOMLEFT; + else if (iupStrEqualNoCase(value, "BOTTOMRIGHT")) + ih->data->plt->_plot.mLegendPos = PPLOT_BOTTOMRIGHT; + else + ih->data->plt->_plot.mLegendPos = PPLOT_TOPRIGHT; + + ih->data->plt->_redraw = 1; + return 0; +} + +static char* iPPlotGetLegendPosAttrib(Ihandle* ih) +{ + char* legendpos_str[4] = {"TOPLEFT", "TOPRIGHT", "BOTTOMLEFT", "BOTTOMRIGHT"}; + + return legendpos_str[ih->data->plt->_plot.mLegendPos]; +} + +/* background color */ +static int iPPlotSetBGColorAttrib(Ihandle* ih, const char* value) +{ + unsigned char rr, gg, bb; + if (iupStrToRGB(value, &rr, &gg, &bb)) + { + ih->data->plt->_plot.mPlotBackground.mPlotRegionBackColor = PColor(rr, gg, bb); + ih->data->plt->_redraw = 1; + } + return 0; +} + +static char* iPPlotGetBGColorAttrib(Ihandle* ih) +{ + char* buffer = iupStrGetMemory(30); + sprintf(buffer, "%d %d %d", + ih->data->plt->_plot.mPlotBackground.mPlotRegionBackColor.mR, + ih->data->plt->_plot.mPlotBackground.mPlotRegionBackColor.mG, + ih->data->plt->_plot.mPlotBackground.mPlotRegionBackColor.mB); + return buffer; +} + + +/* title color */ +static int iPPlotSetFGColorAttrib(Ihandle* ih, const char* value) +{ + unsigned char rr, gg, bb; + if (iupStrToRGB(value, &rr, &gg, &bb)) + { + ih->data->plt->_plot.mPlotBackground.mTitleColor = PColor(rr, gg, bb); + ih->data->plt->_redraw = 1; + } + return 0; +} + +static char* iPPlotGetFGColorAttrib(Ihandle* ih) +{ + char* buffer = iupStrGetMemory(30); + sprintf(buffer, "%d %d %d", + ih->data->plt->_plot.mPlotBackground.mTitleColor.mR, + ih->data->plt->_plot.mPlotBackground.mTitleColor.mG, + ih->data->plt->_plot.mPlotBackground.mTitleColor.mB); + return buffer; +} + + +/* plot title */ +static int iPPlotSetTitleAttrib(Ihandle* ih, const char* value) +{ + if (value && value[0] != 0) + ih->data->plt->_plot.mPlotBackground.mTitle = value; + else + ih->data->plt->_plot.mPlotBackground.mTitle.resize(0); + + ih->data->plt->_redraw = 1; + return 0; +} + +static char* iPPlotGetTitleAttrib(Ihandle* ih) +{ + char* buffer = iupStrGetMemory(256); + strncpy(buffer, ih->data->plt->_plot.mPlotBackground.mTitle.c_str(), 256); + buffer[255]='\0'; + return buffer; +} + + +/* plot title font size */ +static int iPPlotSetTitleFontSizeAttrib(Ihandle* ih, const char* value) +{ + int ii; + if (iupStrToInt(value, &ii)) + { + ih->data->plt->_plot.mPlotBackground.mStyle.mFontSize = ii; + ih->data->plt->_redraw = 1; + } + return 0; +} + +static char* iPPlotGetTitleFontSizeAttrib(Ihandle* ih) +{ + return iPPlotGetPlotFontSize(ih->data->plt->_plot.mPlotBackground.mStyle.mFontSize); +} + + +/* plot title font style */ +static int iPPlotSetTitleFontStyleAttrib(Ihandle* ih, const char* value) +{ + int style = iPPlotGetCDFontStyle(value); + if (style != -1) + { + ih->data->plt->_plot.mPlotBackground.mStyle.mFontStyle = style; + ih->data->plt->_redraw = 1; + } + return 0; +} + +/* legend font size */ +static int iPPlotSetLegendFontSizeAttrib(Ihandle* ih, const char* value) +{ + int ii, xx; + if (!iupStrToInt(value, &xx)) + return 0; + + for (ii = 0; ii < ih->data->plt->_plot.mPlotDataContainer.GetPlotCount(); ii++) + { + LegendData* legend = ih->data->plt->_plot.mPlotDataContainer.GetLegendData(ii); + legend->mStyle.mFontSize = xx; + } + + ih->data->plt->_redraw = 1; + return 1; +} + +/* legend font style */ +static int iPPlotSetLegendFontStyleAttrib(Ihandle* ih, const char* value) +{ + int ii; + int style = iPPlotGetCDFontStyle(value); + if (style == -1) + return 0; + + for (ii = 0; ii < ih->data->plt->_plot.mPlotDataContainer.GetPlotCount(); ii++) + { + LegendData* legend = ih->data->plt->_plot.mPlotDataContainer.GetLegendData(ii); + legend->mStyle.mFontStyle = style; + } + + ih->data->plt->_redraw = 1; + return 1; +} + +/* plot margins */ +static int iPPlotSetMarginLeftAttrib(Ihandle* ih, const char* value) +{ + int ii; + if (iupStrToInt(value, &ii)) + { + ih->data->plt->_plot.mMargins.mLeft = ii; + ih->data->plt->_redraw = 1; + } + return 0; +} + +static int iPPlotSetMarginRightAttrib(Ihandle* ih, const char* value) +{ + int ii; + if (iupStrToInt(value, &ii)) + { + ih->data->plt->_plot.mMargins.mRight = ii; + ih->data->plt->_redraw = 1; + } + return 0; +} + +static int iPPlotSetMarginTopAttrib(Ihandle* ih, const char* value) +{ + int ii; + if (iupStrToInt(value, &ii)) + { + ih->data->plt->_plot.mMargins.mTop = ii; + ih->data->plt->_redraw = 1; + } + return 0; +} + +static int iPPlotSetMarginBottomAttrib(Ihandle* ih, const char* value) +{ + int ii; + if (iupStrToInt(value, &ii)) + { + ih->data->plt->_plot.mMargins.mBottom = ii; + ih->data->plt->_redraw = 1; + } + return 0; +} + +static char* iPPlotGetMarginLeftAttrib(Ihandle* ih) +{ + char* buffer = iupStrGetMemory(30); + sprintf(buffer, "%d", ih->data->plt->_plot.mMargins.mLeft); + return buffer; +} + +static char* iPPlotGetMarginRightAttrib(Ihandle* ih) +{ + char* buffer = iupStrGetMemory(30); + sprintf(buffer, "%d", ih->data->plt->_plot.mMargins.mRight); + return buffer; +} + +static char* iPPlotGetMarginTopAttrib(Ihandle* ih) +{ + char* buffer = iupStrGetMemory(30); + sprintf(buffer, "%d", ih->data->plt->_plot.mMargins.mTop); + return buffer; +} + +static char* iPPlotGetMarginBottomAttrib(Ihandle* ih) +{ + char* buffer = iupStrGetMemory(30); + sprintf(buffer, "%d", ih->data->plt->_plot.mMargins.mBottom); + return buffer; +} + +/* plot grid color */ +static int iPPlotSetGridColorAttrib(Ihandle* ih, const char* value) +{ + unsigned char rr, gg, bb; + if (iupStrToRGB(value, &rr, &gg, &bb)) + { + ih->data->plt->_plot.mGridInfo.mGridColor = PColor(rr, gg, bb); + ih->data->plt->_redraw = 1; + } + return 0; +} + +static char* iPPlotGetGridColorAttrib(Ihandle* ih) +{ + char* buffer = iupStrGetMemory(30); + sprintf(buffer, "%d %d %d", + ih->data->plt->_plot.mGridInfo.mGridColor.mR, + ih->data->plt->_plot.mGridInfo.mGridColor.mG, + ih->data->plt->_plot.mGridInfo.mGridColor.mB); + return buffer; +} + +/* plot grid line style */ +static int iPPlotSetGridLineStyleAttrib(Ihandle* ih, const char* value) +{ + ih->data->plt->_plot.mGridInfo.mStyle.mPenStyle = iPPlotGetCDPenStyle(value); + ih->data->plt->_redraw = 1; + return 0; +} + +static char* iPPlotGetGridLineStyleAttrib(Ihandle* ih) +{ + return iPPlotGetPlotPenStyle(ih->data->plt->_plot.mGridInfo.mStyle.mPenStyle); +} + +/* grid */ +static int iPPlotSetGridAttrib(Ihandle* ih, const char* value) +{ + if (iupStrEqualNoCase(value, "VERTICAL")) /* vertical grid - X axis */ + { + ih->data->plt->_plot.mGridInfo.mXGridOn = true; + ih->data->plt->_plot.mGridInfo.mYGridOn = false; + } + else if (iupStrEqualNoCase(value, "HORIZONTAL")) /* horizontal grid - Y axis */ + { + ih->data->plt->_plot.mGridInfo.mYGridOn = true; + ih->data->plt->_plot.mGridInfo.mXGridOn = false; + } + else if (iupStrEqualNoCase(value, "YES")) + { + ih->data->plt->_plot.mGridInfo.mXGridOn = true; + ih->data->plt->_plot.mGridInfo.mYGridOn = true; + } + else + { + ih->data->plt->_plot.mGridInfo.mYGridOn = false; + ih->data->plt->_plot.mGridInfo.mXGridOn = false; + } + + ih->data->plt->_redraw = 1; + return 0; +} + +static char* iPPlotGetGridAttrib(Ihandle* ih) +{ + if (ih->data->plt->_plot.mGridInfo.mXGridOn && ih->data->plt->_plot.mGridInfo.mYGridOn) + return "YES"; + else if (ih->data->plt->_plot.mGridInfo.mYGridOn) + return "HORIZONTAL"; + else if (ih->data->plt->_plot.mGridInfo.mXGridOn) + return "VERTICAL"; + else + return "NO"; +} + +/* current dataset index */ +static int iPPlotSetCurrentAttrib(Ihandle* ih, const char* value) +{ + int ii; + if (iupStrToInt(value, &ii)) + { + int imax = ih->data->plt->_plot.mPlotDataContainer.GetPlotCount(); + ih->data->plt->_currentDataSetIndex = ( (ii>=0) && (iidata->plt->_redraw = 1; + } + return 0; +} + +static char* iPPlotGetCurrentAttrib(Ihandle* ih) +{ + char* buffer = iupStrGetMemory(30); + sprintf(buffer, "%d", ih->data->plt->_currentDataSetIndex); + return buffer; +} + +/* remove a dataset */ +static int iPPlotSetRemoveAttrib(Ihandle* ih, const char* value) +{ + int ii; + if (iupStrToInt(value, &ii)) + { + ih->data->plt->_plot.mPlotDataContainer.RemoveElement(ii); + ih->data->plt->_redraw = 1; + } + return 0; +} + +/* clear all datasets */ +static int iPPlotSetClearAttrib(Ihandle* ih, const char* value) +{ + ih->data->plt->_plot.mPlotDataContainer.ClearData(); + ih->data->plt->_redraw = 1; + return 0; +} + +/* =============================== */ +/* current plot dataset attributes */ +/* =============================== */ + +/* current plot line style */ +static int iPPlotSetDSLineStyleAttrib(Ihandle* ih, const char* value) +{ + if (ih->data->plt->_currentDataSetIndex < 0 || + ih->data->plt->_currentDataSetIndex >= ih->data->plt->_plot.mPlotDataContainer.GetPlotCount()) + return 0; + + DataDrawerBase* drawer = ih->data->plt->_plot.mPlotDataContainer.GetDataDrawer(ih->data->plt->_currentDataSetIndex); + drawer->mStyle.mPenStyle = iPPlotGetCDPenStyle(value); + + ih->data->plt->_redraw = 1; + return 0; +} + +static char* iPPlotGetDSLineStyleAttrib(Ihandle* ih) +{ + if (ih->data->plt->_currentDataSetIndex < 0 || + ih->data->plt->_currentDataSetIndex >= ih->data->plt->_plot.mPlotDataContainer.GetPlotCount()) + return NULL; + + DataDrawerBase* drawer = ih->data->plt->_plot.mPlotDataContainer.GetDataDrawer(ih->data->plt->_currentDataSetIndex); + + return iPPlotGetPlotPenStyle(drawer->mStyle.mPenStyle); +} + +/* current plot line width */ +static int iPPlotSetDSLineWidthAttrib(Ihandle* ih, const char* value) +{ + int ii; + + if (ih->data->plt->_currentDataSetIndex < 0 || + ih->data->plt->_currentDataSetIndex >= ih->data->plt->_plot.mPlotDataContainer.GetPlotCount()) + return 0; + + if (iupStrToInt(value, &ii)) + { + DataDrawerBase* drawer = ih->data->plt->_plot.mPlotDataContainer.GetDataDrawer(ih->data->plt->_currentDataSetIndex); + drawer->mStyle.mPenWidth = ii; + ih->data->plt->_redraw = 1; + } + return 0; +} + +static char* iPPlotGetDSLineWidthAttrib(Ihandle* ih) +{ + if (ih->data->plt->_currentDataSetIndex < 0 || + ih->data->plt->_currentDataSetIndex >= ih->data->plt->_plot.mPlotDataContainer.GetPlotCount()) + return NULL; + + DataDrawerBase* drawer = ih->data->plt->_plot.mPlotDataContainer.GetDataDrawer(ih->data->plt->_currentDataSetIndex); + char* buffer = iupStrGetMemory(30); + sprintf(buffer, "%d", drawer->mStyle.mPenWidth); + return buffer; +} + +/* current plot mark style */ +static int iPPlotSetDSMarkStyleAttrib(Ihandle* ih, const char* value) +{ + if (ih->data->plt->_currentDataSetIndex < 0 || + ih->data->plt->_currentDataSetIndex >= ih->data->plt->_plot.mPlotDataContainer.GetPlotCount()) + return 0; + + DataDrawerBase* drawer = ih->data->plt->_plot.mPlotDataContainer.GetDataDrawer(ih->data->plt->_currentDataSetIndex); + drawer->mStyle.mMarkStyle = iPPlotGetCDMarkStyle(value); + ih->data->plt->_redraw = 1; + return 0; +} + +static char* iPPlotGetDSMarkStyleAttrib(Ihandle* ih) +{ + if (ih->data->plt->_currentDataSetIndex < 0 || + ih->data->plt->_currentDataSetIndex >= ih->data->plt->_plot.mPlotDataContainer.GetPlotCount()) + return NULL; + + DataDrawerBase* drawer = ih->data->plt->_plot.mPlotDataContainer.GetDataDrawer(ih->data->plt->_currentDataSetIndex); + + return iPPlotGetPlotMarkStyle(drawer->mStyle.mMarkStyle); +} + +/* current plot mark size */ +static int iPPlotSetDSMarkSizeAttrib(Ihandle* ih, const char* value) +{ + int ii; + + if (ih->data->plt->_currentDataSetIndex < 0 || + ih->data->plt->_currentDataSetIndex >= ih->data->plt->_plot.mPlotDataContainer.GetPlotCount()) + return 0; + + if (iupStrToInt(value, &ii)) + { + DataDrawerBase* drawer = ih->data->plt->_plot.mPlotDataContainer.GetDataDrawer(ih->data->plt->_currentDataSetIndex); + drawer->mStyle.mMarkSize = ii; + ih->data->plt->_redraw = 1; + } + return 0; +} + +static char* iPPlotGetDSMarkSizeAttrib(Ihandle* ih) +{ + if (ih->data->plt->_currentDataSetIndex < 0 || + ih->data->plt->_currentDataSetIndex >= ih->data->plt->_plot.mPlotDataContainer.GetPlotCount()) + return NULL; + + DataDrawerBase* drawer = ih->data->plt->_plot.mPlotDataContainer.GetDataDrawer(ih->data->plt->_currentDataSetIndex); + char* buffer = iupStrGetMemory(30); + sprintf(buffer, "%d", drawer->mStyle.mMarkSize); + return buffer; +} + +/* current dataset legend */ +static int iPPlotSetDSLegendAttrib(Ihandle* ih, const char* value) +{ + if (ih->data->plt->_currentDataSetIndex < 0 || + ih->data->plt->_currentDataSetIndex >= ih->data->plt->_plot.mPlotDataContainer.GetPlotCount()) + return 0; + + LegendData* legend = ih->data->plt->_plot.mPlotDataContainer.GetLegendData(ih->data->plt->_currentDataSetIndex); + + if (value) + legend->mName = value; + else + legend->mName.resize(0); + + ih->data->plt->_redraw = 1; + return 0; +} + +static char* iPPlotGetDSLegendAttrib(Ihandle* ih) +{ + if (ih->data->plt->_currentDataSetIndex < 0 || + ih->data->plt->_currentDataSetIndex >= ih->data->plt->_plot.mPlotDataContainer.GetPlotCount()) + return NULL; + + LegendData* legend = ih->data->plt->_plot.mPlotDataContainer.GetLegendData(ih->data->plt->_currentDataSetIndex); + char* buffer = iupStrGetMemory(256); + strncpy(buffer, legend->mName.c_str(), 255); + buffer[255]='\0'; + return buffer; +} + +/* current dataset line and legend color */ +static int iPPlotSetDSColorAttrib(Ihandle* ih, const char* value) +{ + unsigned char rr, gg, bb; + + if (ih->data->plt->_currentDataSetIndex < 0 || + ih->data->plt->_currentDataSetIndex >= ih->data->plt->_plot.mPlotDataContainer.GetPlotCount()) + return 0; + + if (iupStrToRGB(value, &rr, &gg, &bb)) + { + LegendData* legend = ih->data->plt->_plot.mPlotDataContainer.GetLegendData(ih->data->plt->_currentDataSetIndex); + legend->mColor = PColor(rr, gg, bb); + ih->data->plt->_redraw = 1; + } + return 0; +} + +static char* iPPlotGetDSColorAttrib(Ihandle* ih) +{ + if (ih->data->plt->_currentDataSetIndex < 0 || + ih->data->plt->_currentDataSetIndex >= ih->data->plt->_plot.mPlotDataContainer.GetPlotCount()) + return NULL; + + LegendData* legend = ih->data->plt->_plot.mPlotDataContainer.GetLegendData(ih->data->plt->_currentDataSetIndex); + char* buffer = iupStrGetMemory(30); + sprintf(buffer, "%d %d %d", legend->mColor.mR, legend->mColor.mG, legend->mColor.mB); + return buffer; +} + +/* show values */ +static int iPPlotSetDSShowValuesAttrib(Ihandle* ih, const char* value) +{ + if (ih->data->plt->_currentDataSetIndex < 0 || + ih->data->plt->_currentDataSetIndex >= ih->data->plt->_plot.mPlotDataContainer.GetPlotCount()) + return 0; + + DataDrawerBase* drawer = ih->data->plt->_plot.mPlotDataContainer.GetDataDrawer(ih->data->plt->_currentDataSetIndex); + + if (iupStrBoolean(value)) + drawer->mShowValues = true; + else + drawer->mShowValues = false; + + ih->data->plt->_redraw = 1; + return 0; +} + +static char* iPPlotGetDSShowValuesAttrib(Ihandle* ih) +{ + if (ih->data->plt->_currentDataSetIndex < 0 || + ih->data->plt->_currentDataSetIndex >= ih->data->plt->_plot.mPlotDataContainer.GetPlotCount()) + return NULL; + + DataDrawerBase* drawer = ih->data->plt->_plot.mPlotDataContainer.GetDataDrawer(ih->data->plt->_currentDataSetIndex); + if (drawer->mShowValues) + return "YES"; + else + return "NO"; +} + +/* current dataset drawing mode */ +static int iPPlotSetDSModeAttrib(Ihandle* ih, const char* value) +{ + if (ih->data->plt->_currentDataSetIndex < 0 || + ih->data->plt->_currentDataSetIndex >= ih->data->plt->_plot.mPlotDataContainer.GetPlotCount()) + return 0; + + DataDrawerBase *theDataDrawer = NULL; + ih->data->plt->_plot.mXAxisSetup.mDiscrete = false; + + if(iupStrEqualNoCase(value, "BAR")) + { + theDataDrawer = new BarDataDrawer(); + ih->data->plt->_plot.mXAxisSetup.mDiscrete = true; + } + else if(iupStrEqualNoCase(value, "MARK")) + theDataDrawer = new MarkDataDrawer(0); + else if(iupStrEqualNoCase(value, "MARKLINE")) + theDataDrawer = new MarkDataDrawer(1); + else /* LINE */ + theDataDrawer = new LineDataDrawer(); + + ih->data->plt->_plot.mPlotDataContainer.SetDataDrawer(ih->data->plt->_currentDataSetIndex, theDataDrawer); + + ih->data->plt->_redraw = 1; + return 0; +} + +static char* iPPlotGetDSModeAttrib(Ihandle* ih) +{ + if (ih->data->plt->_currentDataSetIndex < 0 || + ih->data->plt->_currentDataSetIndex >= ih->data->plt->_plot.mPlotDataContainer.GetPlotCount()) + return NULL; + + DataDrawerBase* drawer = ih->data->plt->_plot.mPlotDataContainer.GetDataDrawer(ih->data->plt->_currentDataSetIndex); + + return (char*)drawer->mMode; +} + +/* allows selection and editing */ +static int iPPlotSetDSEditAttrib(Ihandle* ih, const char* value) +{ + if (ih->data->plt->_currentDataSetIndex < 0 || + ih->data->plt->_currentDataSetIndex >= ih->data->plt->_plot.mPlotDataContainer.GetPlotCount()) + return 0; + + PlotDataSelection* dataselect = ih->data->plt->_plot.mPlotDataContainer.GetPlotDataSelection(ih->data->plt->_currentDataSetIndex); + + if (iupStrBoolean(value)) + dataselect->resize(ih->data->plt->_plot.mPlotDataContainer.GetConstYData(ih->data->plt->_currentDataSetIndex)->GetSize()); + else + dataselect->clear(); + + ih->data->plt->_redraw = 1; + return 0; +} + +static char* iPPlotGetDSEditAttrib(Ihandle* ih) +{ + if (ih->data->plt->_currentDataSetIndex < 0 || + ih->data->plt->_currentDataSetIndex >= ih->data->plt->_plot.mPlotDataContainer.GetPlotCount()) + return NULL; + + PlotDataSelection* dataselect = ih->data->plt->_plot.mPlotDataContainer.GetPlotDataSelection(ih->data->plt->_currentDataSetIndex); + if (dataselect->empty()) + return "NO"; + else + return "YES"; +} + +/* remove a sample */ +static int iPPlotSetDSRemoveAttrib(Ihandle* ih, const char* value) +{ + int ii; + + if (ih->data->plt->_currentDataSetIndex < 0 || + ih->data->plt->_currentDataSetIndex >= ih->data->plt->_plot.mPlotDataContainer.GetPlotCount()) + return 0; + + if (iupStrToInt(value, &ii)) + { + RemoveSample(ih->data->plt->_plot, ih->data->plt->_currentDataSetIndex, ii); + ih->data->plt->_redraw = 1; + } + return 0; +} + +static char* iPPlotGetDSCountAttrib(Ihandle* ih) +{ + if (ih->data->plt->_currentDataSetIndex < 0 || + ih->data->plt->_currentDataSetIndex >= ih->data->plt->_plot.mPlotDataContainer.GetPlotCount()) + return NULL; + + { + char* buffer = iupStrGetMemory(30); + int count = ih->data->plt->_plot.mPlotDataContainer.GetCount(ih->data->plt->_currentDataSetIndex); + sprintf(buffer, "%d", count); + return buffer; + } +} + +/* ========== */ +/* axis props */ +/* ========== */ + +/* ========== */ +/* axis props */ +/* ========== */ + +/* axis title */ +static int iPPlotSetAxisXLabelAttrib(Ihandle* ih, const char* value) +{ + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + + if (value) + axis->mLabel = value; + else + axis->mLabel = ""; + + ih->data->plt->_redraw = 1; + return 0; +} + +static int iPPlotSetAxisYLabelAttrib(Ihandle* ih, const char* value) +{ + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + + if (value) + axis->mLabel = value; + else + axis->mLabel = ""; + + ih->data->plt->_redraw = 1; + return 0; +} + +static char* iPPlotGetAxisXLabelAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + char* buffer = iupStrGetMemory(256); + strncpy(buffer, axis->mLabel.c_str(), 255); + buffer[255]='\0'; + return buffer; +} + +static char* iPPlotGetAxisYLabelAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + char* buffer = iupStrGetMemory(256); + strncpy(buffer, axis->mLabel.c_str(), 255); + buffer[255]='\0'; + return buffer; +} + +/* axis title position */ +static int iPPlotSetAxisXLabelCenteredAttrib(Ihandle* ih, const char* value) +{ + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + + if (iupStrBoolean(value)) + axis->mLabelCentered = true; + else + axis->mLabelCentered = false; + + ih->data->plt->_redraw = 1; + return 0; +} + +static int iPPlotSetAxisYLabelCenteredAttrib(Ihandle* ih, const char* value) +{ + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + + if (iupStrBoolean(value)) + axis->mLabelCentered = true; + else + axis->mLabelCentered = false; + + ih->data->plt->_redraw = 1; + return 0; +} + +static char* iPPlotGetAxisXLabelCenteredAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + + if (axis->mLabelCentered) + return "YES"; + else + return "NO"; +} + +static char* iPPlotGetAxisYLabelCenteredAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + + if (axis->mLabelCentered) + return "YES"; + else + return "NO"; +} + +/* axis, ticks and label color */ +static int iPPlotSetAxisXColorAttrib(Ihandle* ih, const char* value) +{ + unsigned char rr, gg, bb; + if (iupStrToRGB(value, &rr, &gg, &bb)) + { + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + axis->mColor = PColor(rr, gg, bb); + ih->data->plt->_redraw = 1; + } + return 0; +} + +static int iPPlotSetAxisYColorAttrib(Ihandle* ih, const char* value) +{ + unsigned char rr, gg, bb; + if (iupStrToRGB(value, &rr, &gg, &bb)) + { + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + axis->mColor = PColor(rr, gg, bb); + ih->data->plt->_redraw = 1; + } + return 0; +} + +static char* iPPlotGetAxisXColorAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + char* buffer = iupStrGetMemory(30); + sprintf(buffer, "%d %d %d", + axis->mColor.mR, + axis->mColor.mG, + axis->mColor.mB); + return buffer; +} + +static char* iPPlotGetAxisYColorAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + char* buffer = iupStrGetMemory(30); + sprintf(buffer, "%d %d %d", + axis->mColor.mR, + axis->mColor.mG, + axis->mColor.mB); + return buffer; +} + +/* autoscaling */ +static int iPPlotSetAxisXAutoMinAttrib(Ihandle* ih, const char* value) +{ + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + + if (iupStrBoolean(value)) + axis->mAutoScaleMin = true; + else + axis->mAutoScaleMin = false; + + ih->data->plt->_redraw = 1; + return 0; +} + +static int iPPlotSetAxisYAutoMinAttrib(Ihandle* ih, const char* value) +{ + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + + if (iupStrBoolean(value)) + axis->mAutoScaleMin = true; + else + axis->mAutoScaleMin = false; + + ih->data->plt->_redraw = 1; + return 0; +} + +static char* iPPlotGetAxisXAutoMinAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + + if (axis->mAutoScaleMin) + return "YES"; + else + return "NO"; +} + +static char* iPPlotGetAxisYAutoMinAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + + if (axis->mAutoScaleMin) + return "YES"; + else + return "NO"; +} + +/* autoscaling */ +static int iPPlotSetAxisXAutoMaxAttrib(Ihandle* ih, const char* value) +{ + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + + if (iupStrBoolean(value)) + axis->mAutoScaleMax = true; + else + axis->mAutoScaleMax = false; + + ih->data->plt->_redraw = 1; + return 0; +} + +static int iPPlotSetAxisYAutoMaxAttrib(Ihandle* ih, const char* value) +{ + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + + if (iupStrBoolean(value)) + axis->mAutoScaleMax = true; + else + axis->mAutoScaleMax = false; + + ih->data->plt->_redraw = 1; + return 0; +} + +static char* iPPlotGetAxisXAutoMaxAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + + if (axis->mAutoScaleMax) + return "YES"; + else + return "NO"; +} + +static char* iPPlotGetAxisYAutoMaxAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + + if (axis->mAutoScaleMax) + return "YES"; + else + return "NO"; +} + +/* min visible val */ +static int iPPlotSetAxisXMinAttrib(Ihandle* ih, const char* value) +{ + float xx; + if (iupStrToFloat(value, &xx)) + { + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + axis->mMin = xx; + ih->data->plt->_redraw = 1; + } + return 0; +} + +static int iPPlotSetAxisYMinAttrib(Ihandle* ih, const char* value) +{ + float xx; + if (iupStrToFloat(value, &xx)) + { + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + axis->mMin = xx; + ih->data->plt->_redraw = 1; + } + return 0; +} + +static char* iPPlotGetAxisXMinAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + char* buffer = iupStrGetMemory(30); + sprintf(buffer, "%g", axis->mMin); + return buffer; +} + +static char* iPPlotGetAxisYMinAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + char* buffer = iupStrGetMemory(30); + sprintf(buffer, "%g", axis->mMin); + return buffer; +} + +/* max visible val */ +static int iPPlotSetAxisXMaxAttrib(Ihandle* ih, const char* value) +{ + float xx; + if (iupStrToFloat(value, &xx)) + { + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + axis->mMax = xx; + ih->data->plt->_redraw = 1; + } + return 0; +} + +static int iPPlotSetAxisYMaxAttrib(Ihandle* ih, const char* value) +{ + float xx; + if (iupStrToFloat(value, &xx)) + { + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + axis->mMax = xx; + ih->data->plt->_redraw = 1; + } + return 0; +} + +static char* iPPlotGetAxisXMaxAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + char* buffer = iupStrGetMemory(30); + sprintf(buffer, "%g", axis->mMax); + return buffer; +} + +static char* iPPlotGetAxisYMaxAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + char* buffer = iupStrGetMemory(30); + sprintf(buffer, "%g", axis->mMax); + return buffer; +} + +/* values from left/top to right/bottom */ +static int iPPlotSetAxisXReverseAttrib(Ihandle* ih, const char* value) +{ + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + + if (iupStrBoolean(value)) + axis->mAscending = false; /* inverted for X */ + else + axis->mAscending = true; + + ih->data->plt->_redraw = 1; + return 0; +} + +static int iPPlotSetAxisYReverseAttrib(Ihandle* ih, const char* value) +{ + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + + if (iupStrBoolean(value)) + axis->mAscending = true; /* NOT inverted for Y */ + else + axis->mAscending = false; + + ih->data->plt->_redraw = 1; + return 0; +} + +static char* iPPlotGetAxisXReverseAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + + if (axis->mAscending) + return "NO"; /* inverted for X */ + else + return "YES"; +} + +static char* iPPlotGetAxisYReverseAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + + if (axis->mAscending) + return "YES"; /* NOT inverted for Y */ + else + return "NO"; +} + +/* axis mode */ +static int iPPlotSetAxisXCrossOriginAttrib(Ihandle* ih, const char* value) +{ + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + + if (iupStrBoolean(value)) + axis->mCrossOrigin = true; + else + axis->mCrossOrigin = false; + + ih->data->plt->_redraw = 1; + return 0; +} + +static int iPPlotSetAxisYCrossOriginAttrib(Ihandle* ih, const char* value) +{ + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + + if (iupStrBoolean(value)) + axis->mCrossOrigin = true; + else + axis->mCrossOrigin = false; + + ih->data->plt->_redraw = 1; + return 0; +} + +static char* iPPlotGetAxisXCrossOriginAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + + if (axis->mCrossOrigin) + return "YES"; + else + return "NO"; +} + +static char* iPPlotGetAxisYCrossOriginAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + + if (axis->mCrossOrigin) + return "YES"; + else + return "NO"; +} + +/* log/lin scale */ +static int iPPlotSetAxisXScaleAttrib(Ihandle* ih, const char* value) +{ + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + + if(iupStrEqualNoCase(value, "LIN")) + { + axis->mLogScale = false; + } + else if(iupStrEqualNoCase(value, "LOG10")) + { + axis->mLogScale = true; + axis->mLogBase = 10.0; + } + else if(iupStrEqualNoCase(value, "LOG2")) + { + axis->mLogScale = true; + axis->mLogBase = 2.0; + } + else + { + axis->mLogScale = true; + axis->mLogBase = (float)M_E; + } + + ih->data->plt->_redraw = 1; + return 0; +} + +static int iPPlotSetAxisYScaleAttrib(Ihandle* ih, const char* value) +{ + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + + if(iupStrEqualNoCase(value, "LIN")) + { + axis->mLogScale = false; + } + else if(iupStrEqualNoCase(value, "LOG10")) + { + axis->mLogScale = true; + axis->mLogBase = 10.0; + } + else if(iupStrEqualNoCase(value, "LOG2")) + { + axis->mLogScale = true; + axis->mLogBase = 2.0; + } + else + { + axis->mLogScale = true; + axis->mLogBase = (float)M_E; + } + + ih->data->plt->_redraw = 1; + return 0; +} + +static char* iPPlotGetAxisXScaleAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + char* buffer = iupStrGetMemory(30); + + if (axis->mLogScale) + { + if (axis->mLogBase == 10.0) + strcpy(buffer, "LOG10"); + else if (axis->mLogBase == 2.0) + strcpy(buffer, "LOG2"); + else + strcpy(buffer, "LOGN"); + } + else + strcpy(buffer, "LIN"); + + return buffer; +} + +static char* iPPlotGetAxisYScaleAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + char* buffer = iupStrGetMemory(30); + + if (axis->mLogScale) + { + if (axis->mLogBase == 10.0) + strcpy(buffer, "LOG10"); + else if (axis->mLogBase == 2.0) + strcpy(buffer, "LOG2"); + else + strcpy(buffer, "LOGN"); + } + else + strcpy(buffer, "LIN"); + + return buffer; +} + +/* axis label font size */ +static int iPPlotSetAxisXFontSizeAttrib(Ihandle* ih, const char* value) +{ + int ii; + if (iupStrToInt(value, &ii)) + { + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + axis->mStyle.mFontSize = ii; + ih->data->plt->_redraw = 1; + } + return 0; +} + +static int iPPlotSetAxisYFontSizeAttrib(Ihandle* ih, const char* value) +{ + int ii; + if (iupStrToInt(value, &ii)) + { + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + axis->mStyle.mFontSize = ii; + ih->data->plt->_redraw = 1; + } + return 0; +} + +static char* iPPlotGetAxisXFontSizeAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + return iPPlotGetPlotFontSize(axis->mStyle.mFontSize); +} + +static char* iPPlotGetAxisYFontSizeAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + return iPPlotGetPlotFontSize(axis->mStyle.mFontSize); +} + +/* axis label font style */ +static int iPPlotSetAxisXFontStyleAttrib(Ihandle* ih, const char* value) +{ + int style = iPPlotGetCDFontStyle(value); + if (style != -1) + { + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + axis->mStyle.mFontStyle = style; + ih->data->plt->_redraw = 1; + } + return 0; +} + +static int iPPlotSetAxisYFontStyleAttrib(Ihandle* ih, const char* value) +{ + int style = iPPlotGetCDFontStyle(value); + if (style != -1) + { + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + axis->mStyle.mFontStyle = style; + ih->data->plt->_redraw = 1; + } + return 0; +} + +static char* iPPlotGetAxisXFontStyleAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + return iPPlotGetPlotFontStyle(axis->mStyle.mFontStyle); +} + +static char* iPPlotGetAxisYFontStyleAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + return iPPlotGetPlotFontStyle(axis->mStyle.mFontStyle); +} + +/* automatic tick size */ +static int iPPlotSetAxisXAutoTickSizeAttrib(Ihandle* ih, const char* value) +{ + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + + if (iupStrBoolean(value)) + axis->mTickInfo.mAutoTickSize = true; + else + axis->mTickInfo.mAutoTickSize = false; + + ih->data->plt->_redraw = 1; + return 0; +} + +static int iPPlotSetAxisYAutoTickSizeAttrib(Ihandle* ih, const char* value) +{ + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + + if (iupStrBoolean(value)) + axis->mTickInfo.mAutoTickSize = true; + else + axis->mTickInfo.mAutoTickSize = false; + + ih->data->plt->_redraw = 1; + return 0; +} + +static char* iPPlotGetAxisXAutoTickSizeAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + + if (axis->mTickInfo.mAutoTickSize) + return "YES"; + else + return "NO"; +} + +static char* iPPlotGetAxisYAutoTickSizeAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + + if (axis->mTickInfo.mAutoTickSize) + return "YES"; + else + return "NO"; +} + +/* size of ticks (in pixels) */ +static int iPPlotSetAxisXTickSizeAttrib(Ihandle* ih, const char* value) +{ + int ii; + if (iupStrToInt(value, &ii)) + { + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + axis->mTickInfo.mMinorTickScreenSize = ii; + ih->data->plt->_redraw = 1; + } + return 0; +} + +static int iPPlotSetAxisYTickSizeAttrib(Ihandle* ih, const char* value) +{ + int ii; + if (iupStrToInt(value, &ii)) + { + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + axis->mTickInfo.mMinorTickScreenSize = ii; + ih->data->plt->_redraw = 1; + } + return 0; +} + +static char* iPPlotGetAxisXTickSizeAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + char* buffer = iupStrGetMemory(30); + sprintf(buffer, "%d", axis->mTickInfo.mMinorTickScreenSize); + return buffer; +} + +static char* iPPlotGetAxisYTickSizeAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + char* buffer = iupStrGetMemory(30); + sprintf(buffer, "%d", axis->mTickInfo.mMinorTickScreenSize); + return buffer; +} + +/* size of major ticks (in pixels) */ +static int iPPlotSetAxisXTickMajorSizeAttrib(Ihandle* ih, const char* value) +{ + int ii; + if (iupStrToInt(value, &ii)) + { + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + axis->mTickInfo.mMajorTickScreenSize = ii; + ih->data->plt->_redraw = 1; + } + return 0; +} + +static int iPPlotSetAxisYTickMajorSizeAttrib(Ihandle* ih, const char* value) +{ + int ii; + if (iupStrToInt(value, &ii)) + { + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + axis->mTickInfo.mMajorTickScreenSize = ii; + ih->data->plt->_redraw = 1; + } + return 0; +} + +static char* iPPlotGetAxisXTickMajorSizeAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + char* buffer = iupStrGetMemory(30); + sprintf(buffer, "%d", axis->mTickInfo.mMajorTickScreenSize); + return buffer; +} + +static char* iPPlotGetAxisYTickMajorSizeAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + char* buffer = iupStrGetMemory(30); + sprintf(buffer, "%d", axis->mTickInfo.mMajorTickScreenSize); + return buffer; +} + +/* axis ticks font size */ +static int iPPlotSetAxisXTickFontSizeAttrib(Ihandle* ih, const char* value) +{ + int ii; + if (iupStrToInt(value, &ii)) + { + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + axis->mTickInfo.mStyle.mFontSize = ii; + ih->data->plt->_redraw = 1; + } + return 0; +} + +static int iPPlotSetAxisYTickFontSizeAttrib(Ihandle* ih, const char* value) +{ + int ii; + if (iupStrToInt(value, &ii)) + { + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + axis->mTickInfo.mStyle.mFontSize = ii; + ih->data->plt->_redraw = 1; + } + return 0; +} + +static char* iPPlotGetAxisXTickFontSizeAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + + return iPPlotGetPlotFontSize(axis->mTickInfo.mStyle.mFontSize); +} + +static char* iPPlotGetAxisYTickFontSizeAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + + return iPPlotGetPlotFontSize(axis->mTickInfo.mStyle.mFontSize); +} + +/* axis ticks number font style */ +static int iPPlotSetAxisXTickFontStyleAttrib(Ihandle* ih, const char* value) +{ + int style = iPPlotGetCDFontStyle(value); + if (style != -1) + { + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + axis->mTickInfo.mStyle.mFontStyle = style; + ih->data->plt->_redraw = 1; + } + return 0; +} + +static int iPPlotSetAxisYTickFontStyleAttrib(Ihandle* ih, const char* value) +{ + int style = iPPlotGetCDFontStyle(value); + if (style != -1) + { + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + axis->mTickInfo.mStyle.mFontStyle = style; + ih->data->plt->_redraw = 1; + } + return 0; +} + +static char* iPPlotGetAxisXTickFontStyleAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + + return iPPlotGetPlotFontSize(axis->mTickInfo.mStyle.mFontStyle); +} + +static char* iPPlotGetAxisYTickFontStyleAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + + return iPPlotGetPlotFontSize(axis->mTickInfo.mStyle.mFontStyle); +} + +/* axis ticks number format */ +static int iPPlotSetAxisXTickFormatAttrib(Ihandle* ih, const char* value) +{ + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + + if (value && value[0]!=0) + axis->mTickInfo.mFormatString = value; + else + axis->mTickInfo.mFormatString = "%.0f"; + + ih->data->plt->_redraw = 1; + return 0; +} + +static int iPPlotSetAxisYTickFormatAttrib(Ihandle* ih, const char* value) +{ + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + + if (value && value[0]!=0) + axis->mTickInfo.mFormatString = value; + else + axis->mTickInfo.mFormatString = "%.0f"; + + ih->data->plt->_redraw = 1; + return 0; +} + +static char* iPPlotGetAxisXTickFormatAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + char* buffer = iupStrGetMemory(256); + strncpy(buffer, axis->mTickInfo.mFormatString.c_str(), 255); + buffer[255]='\0'; + return buffer; +} + +static char* iPPlotGetAxisYTickFormatAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + char* buffer = iupStrGetMemory(256); + strncpy(buffer, axis->mTickInfo.mFormatString.c_str(), 255); + buffer[255]='\0'; + return buffer; +} + +/* axis ticks */ +static int iPPlotSetAxisXTickAttrib(Ihandle* ih, const char* value) +{ + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + + if (iupStrBoolean(value)) + axis->mTickInfo.mTicksOn = true; + else + axis->mTickInfo.mTicksOn = false; + + ih->data->plt->_redraw = 1; + return 0; +} + +static int iPPlotSetAxisYTickAttrib(Ihandle* ih, const char* value) +{ + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + + if (iupStrBoolean(value)) + axis->mTickInfo.mTicksOn = true; + else + axis->mTickInfo.mTicksOn = false; + + ih->data->plt->_redraw = 1; + return 0; +} + +static char* iPPlotGetAxisXTickAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + + if (axis->mTickInfo.mTicksOn) + return "YES"; + else + return "NO"; +} + +static char* iPPlotGetAxisYTickAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + + if (axis->mTickInfo.mTicksOn) + return "YES"; + else + return "NO"; +} + +/* major tick spacing */ +static int iPPlotSetAxisXTickMajorSpanAttrib(Ihandle* ih, const char* value) +{ + float xx; + if (iupStrToFloat(value, &xx)) + { + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + axis->mTickInfo.mMajorTickSpan = xx; + ih->data->plt->_redraw = 1; + } + return 0; +} + +static int iPPlotSetAxisYTickMajorSpanAttrib(Ihandle* ih, const char* value) +{ + float xx; + if (iupStrToFloat(value, &xx)) + { + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + axis->mTickInfo.mMajorTickSpan = xx; + ih->data->plt->_redraw = 1; + } + return 0; +} + +static char* iPPlotGetAxisXTickMajorSpanAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + char* buffer = iupStrGetMemory(30); + sprintf(buffer, "%g", axis->mTickInfo.mMajorTickSpan); + return buffer; +} + +static char* iPPlotGetAxisYTickMajorSpanAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + char* buffer = iupStrGetMemory(30); + sprintf(buffer, "%g", axis->mTickInfo.mMajorTickSpan); + return buffer; +} + +/* number of ticks between major ticks */ +static int iPPlotSetAxisXTickDivisionAttrib(Ihandle* ih, const char* value) +{ + int ii; + if (iupStrToInt(value, &ii)) + { + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + axis->mTickInfo.mTickDivision = ii; + ih->data->plt->_redraw = 1; + } + return 0; +} + +static int iPPlotSetAxisYTickDivisionAttrib(Ihandle* ih, const char* value) +{ + int ii; + if (iupStrToInt(value, &ii)) + { + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + axis->mTickInfo.mTickDivision = ii; + ih->data->plt->_redraw = 1; + } + return 0; +} + +static char* iPPlotGetAxisXTickDivisionAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + char* buffer = iupStrGetMemory(30); + sprintf(buffer, "%d", axis->mTickInfo.mTickDivision); + return buffer; +} + +static char* iPPlotGetAxisYTickDivisionAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + char* buffer = iupStrGetMemory(30); + sprintf(buffer, "%d", axis->mTickInfo.mTickDivision); + return buffer; +} + +/* auto tick spacing */ +static int iPPlotSetAxisXAutoTickAttrib(Ihandle* ih, const char* value) +{ + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + + if (iupStrBoolean(value)) + axis->mTickInfo.mAutoTick = true; + else + axis->mTickInfo.mAutoTick = false; + + ih->data->plt->_redraw = 1; + return 0; +} + +static int iPPlotSetAxisYAutoTickAttrib(Ihandle* ih, const char* value) +{ + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + + if (iupStrBoolean(value)) + axis->mTickInfo.mAutoTick = true; + else + axis->mTickInfo.mAutoTick = false; + + ih->data->plt->_redraw = 1; + return 0; +} + +static char* iPPlotGetAxisXAutoTickAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mXAxisSetup; + + if (axis->mTickInfo.mAutoTick) + return "YES"; + else + return "NO"; +} + +static char* iPPlotGetAxisYAutoTickAttrib(Ihandle* ih) +{ + AxisSetup* axis = &ih->data->plt->_plot.mYAxisSetup; + + if (axis->mTickInfo.mAutoTick) + return "YES"; + else + return "NO"; +} + +/* MouseButton */ +void PPainterIup::MouseButton(int btn, int stat, int x, int y, char *r) +{ + PMouseEvent theEvent; + int theModifierKeys = 0; + + theEvent.mX = x; + theEvent.mY = y; + + if(btn == IUP_BUTTON1) + { + theEvent.mType = ( stat!=0 ? (PMouseEvent::kDown) : (PMouseEvent::kUp) ); + _mouseDown = ( stat!=0 ? 1 : 0 ); + } + else return; + + _mouse_ALT = 0; + _mouse_SHIFT = 0; + _mouse_CTRL = 0; + + if (iup_isalt(r)) /* signal Alt */ + { + theModifierKeys = (theModifierKeys | PMouseEvent::kAlt); + _mouse_ALT = 1; + } + if (iup_iscontrol(r)) /* signal Ctrl */ + { + theModifierKeys = (theModifierKeys | PMouseEvent::kControl); + _mouse_SHIFT = 1; + } + if (iup_isshift(r)) /* signal Shift */ + { + theModifierKeys = (theModifierKeys | PMouseEvent::kShift); + _mouse_CTRL = 1; + } + theEvent.SetModifierKeys (theModifierKeys); + + if( _InteractionContainer->HandleMouseEvent(theEvent)) + { + this->Draw(1, 1); + } + else + { + /* ignore the event */ + } +} + +/* MouseMove */ +void PPainterIup::MouseMove(int x, int y) +{ + PMouseEvent theEvent; + int theModifierKeys = 0; + + if(!_mouseDown ) return; + + theEvent.mX = x; + theEvent.mY = y; + + theEvent.mType = PMouseEvent::kMove; + if(_mouse_ALT) /* signal Alt */ + { + theModifierKeys = (theModifierKeys | PMouseEvent::kAlt); + } + if(_mouse_SHIFT) /* signal Shift */ + { + theModifierKeys = (theModifierKeys | PMouseEvent::kControl); + } + if(_mouse_CTRL) /* signal Ctrl */ + { + theModifierKeys = (theModifierKeys | PMouseEvent::kShift); + } + theEvent.SetModifierKeys (theModifierKeys); + + if(_InteractionContainer->HandleMouseEvent(theEvent)) + { + this->Draw(1, 1); + } + else + { + /* ignore the event */ + } +} + +/* KeyPress */ +void PPainterIup::KeyPress(int c, int press) +{ + int theModifierKeys = 0; + int theRepeatCount = 0; + PKeyEvent::EKey theKeyCode = PKeyEvent::kNone; + char theChar = 0; + + if(!press) return; + + switch(c) + { + case K_cX: /* CTRL + X */ + theModifierKeys = PMouseEvent::kControl; + theKeyCode = PKeyEvent::kChar; + theChar = 'x'; + break; + case K_cY: /* CTRL + Y */ + theModifierKeys = PMouseEvent::kControl; + theKeyCode = PKeyEvent::kChar; + theChar = 'y'; + break; + case K_cR: /* CTRL + R */ + theModifierKeys = PMouseEvent::kControl; + theKeyCode = PKeyEvent::kChar; + theChar = 'r'; + break; + case K_cUP: /* CTRL + Arrow */ + theModifierKeys = PMouseEvent::kControl; + case K_UP: /* Arrow */ + theKeyCode = PKeyEvent::kArrowUp; + break; + case K_cDOWN: /* CTRL + Arrow */ + theModifierKeys = PMouseEvent::kControl; + case K_DOWN: /* Arrow */ + theKeyCode = PKeyEvent::kArrowDown; + break; + case K_cLEFT: /* CTRL + Arrow */ + theModifierKeys = PMouseEvent::kControl; + case K_LEFT: /* Arrow */ + theKeyCode = PKeyEvent::kArrowLeft; + break; + case K_cRIGHT: /* CTRL + Arrow */ + theModifierKeys = PMouseEvent::kControl; + case K_RIGHT: /* Arrow */ + theKeyCode = PKeyEvent::kArrowRight; + break; + case K_cDEL: /* CTRL + Arrow */ + theModifierKeys = PMouseEvent::kControl; + case K_DEL: /* Arrow */ + theKeyCode = PKeyEvent::kDelete; + break; + } + + PKeyEvent theEvent (theKeyCode, theRepeatCount, theModifierKeys, theChar); + + if(_InteractionContainer->HandleKeyEvent(theEvent)) + { + this->Draw(1, 1); + } + else + { + /* ignore the event */ + } +} + +/* Draw */ +void PPainterIup::Draw(int force, int flush) +{ + if (!_cddbuffer) + return; + +#ifdef USE_OPENGL + if (!IupGLIsCurrent(_ih)) + force = 1; + IupGLMakeCurrent(_ih); +#endif + cdCanvasActivate(_cddbuffer); + + if (force || _redraw) + { + cdCanvasClear(_cddbuffer); + _plot.Draw(*this); + _redraw = 0; + } + + if (flush) + { + cdCanvasFlush(_cddbuffer); + +#ifdef USE_OPENGL + IupGLSwapBuffers(_ih); +#endif + } +} + +/* Resize */ +void PPainterIup::Resize(int w, int h) +{ +#ifndef USE_OPENGL + if (!_cddbuffer) + { + /* update canvas size */ + cdCanvasActivate(_cdcanvas); + + /* this can fail if canvas size is zero */ + if (IupGetInt(_ih, "USE_IMAGERGB")) + _cddbuffer = cdCreateCanvas(CD_DBUFFERRGB, _cdcanvas); + else + _cddbuffer = cdCreateCanvas(CD_DBUFFER, _cdcanvas); + } +#endif + + if (!_cddbuffer) + return; + +#ifdef USE_OPENGL + IupGLMakeCurrent(_ih); + glViewport(0, 0, w, h); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluOrtho2D(0, w, 0, h); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + char StrData[100]; + sprintf(StrData, "%dx%d", w, h); + cdCanvasSetAttribute(_cddbuffer, "SIZE", StrData); +#endif + + /* update canvas size */ + cdCanvasActivate(_cddbuffer); + + _redraw = 1; + + return; +} + +/* send plot to some other device */ +void PPainterIup::DrawTo(cdCanvas *usrCnv) +{ + cdCanvas *old_cddbuffer = _cddbuffer; + _cddbuffer = usrCnv; + +#ifndef USE_OPENGL + cdCanvas *old_cdcanvas = _cdcanvas; + _cdcanvas = usrCnv; +#endif + + if (_cddbuffer) + Draw(1, 0); /* no flush here */ + + _cddbuffer = old_cddbuffer; +#ifndef USE_OPENGL + _cdcanvas = old_cdcanvas; +#endif +} + +void PPainterIup::FillArrow(int inX1, int inY1, int inX2, int inY2, int inX3, int inY3) +{ + if (!_cddbuffer) + return; + + cdCanvasBegin(_cddbuffer, CD_FILL); + cdCanvasVertex(_cddbuffer, inX1, cdCanvasInvertYAxis(_cddbuffer, inY1)); + cdCanvasVertex(_cddbuffer, inX2, cdCanvasInvertYAxis(_cddbuffer, inY2)); + cdCanvasVertex(_cddbuffer, inX3, cdCanvasInvertYAxis(_cddbuffer, inY3)); + cdCanvasEnd(_cddbuffer); +} + +/* DrawLine */ +void PPainterIup::DrawLine(float inX1, float inY1, float inX2, float inY2) +{ + if (!_cddbuffer) + return; + + cdfCanvasLine(_cddbuffer, inX1, cdfCanvasInvertYAxis(_cddbuffer, inY1), + inX2, cdfCanvasInvertYAxis(_cddbuffer, inY2)); +} + +/* FillRect */ +void PPainterIup::FillRect(int inX, int inY, int inW, int inH) +{ + if (!_cddbuffer) + return; + + cdCanvasBox(_cddbuffer, inX, inX+inW, + cdCanvasInvertYAxis(_cddbuffer, inY), + cdCanvasInvertYAxis(_cddbuffer, inY + inH - 1)); +} + +/* InvertRect */ +void PPainterIup::InvertRect(int inX, int inY, int inW, int inH) +{ + long cprev; + + if (!_cddbuffer) + return; + + cdCanvasWriteMode(_cddbuffer, CD_XOR); + cprev = cdCanvasForeground(_cddbuffer, CD_WHITE); + cdCanvasRect(_cddbuffer, inX, inX + inW - 1, + cdCanvasInvertYAxis(_cddbuffer, inY), + cdCanvasInvertYAxis(_cddbuffer, inY + inH - 1)); + cdCanvasWriteMode(_cddbuffer, CD_REPLACE); + cdCanvasForeground(_cddbuffer, cprev); +} + +/* SetClipRect */ +void PPainterIup::SetClipRect(int inX, int inY, int inW, int inH) +{ + if (!_cddbuffer) + return; + + cdCanvasClipArea(_cddbuffer, inX, inX + inW - 1, + cdCanvasInvertYAxis(_cddbuffer, inY), + cdCanvasInvertYAxis(_cddbuffer, inY + inH - 1)); + cdCanvasClip(_cddbuffer, CD_CLIPAREA); +} + +/* GetWidth */ +long PPainterIup::GetWidth() const +{ + int iret; + + if (!_cddbuffer) + return IUP_DEFAULT; + + cdCanvasGetSize(_cddbuffer, &iret, NULL, NULL, NULL); + + return (long)iret; +} + +/* GetHeight */ +long PPainterIup::GetHeight() const +{ + int iret; + + if (!_cddbuffer) + return IUP_NOERROR; + + cdCanvasGetSize(_cddbuffer, NULL, &iret, NULL, NULL); + + return (long)iret; +} + +/* SetLineColor */ +void PPainterIup::SetLineColor(int inR, int inG, int inB) +{ + if (!_cddbuffer) + return; + + cdCanvasForeground(_cddbuffer, cdEncodeColor((unsigned char)inR, + (unsigned char)inG, + (unsigned char)inB)); +} + +/* SetFillColor */ +void PPainterIup::SetFillColor(int inR, int inG, int inB) +{ + if (!_cddbuffer) + return; + + cdCanvasForeground(_cddbuffer, cdEncodeColor((unsigned char)inR, + (unsigned char)inG, + (unsigned char)inB)); +} + +/* CalculateTextDrawSize */ +long PPainterIup::CalculateTextDrawSize(const char *inString) +{ + int iw; + + if (!_cddbuffer) + return IUP_NOERROR; + + cdCanvasGetTextSize(_cddbuffer, const_cast(inString), &iw, NULL); + + return iw; +} + +/* GetFontHeight */ +long PPainterIup::GetFontHeight() const +{ + int ih; + + if (!_cddbuffer) + return IUP_NOERROR; + + cdCanvasGetFontDim(_cddbuffer, NULL, &ih, NULL, NULL); + + return ih; +} + +/* DrawText */ +/* this call leave all the hard job of alignment on painter side */ +void PPainterIup::DrawText(int inX, int inY, short align, const char *inString) +{ + if (!_cddbuffer) + return; + + cdCanvasTextAlignment(_cddbuffer, align); + cdCanvasText(_cddbuffer, inX, cdCanvasInvertYAxis(_cddbuffer, inY), const_cast(inString)); +} + +/* DrawRotatedText */ +void PPainterIup::DrawRotatedText(int inX, int inY, float inDegrees, short align, const char *inString) +{ + double aprev; + + if (!_cddbuffer) + return; + + cdCanvasTextAlignment(_cddbuffer, align); + aprev = cdCanvasTextOrientation(_cddbuffer, -inDegrees); + cdCanvasText(_cddbuffer, inX, cdCanvasInvertYAxis(_cddbuffer, inY), const_cast(inString)); + cdCanvasTextOrientation(_cddbuffer, aprev); +} + +void PPainterIup::SetStyle(const PStyle &inStyle) +{ + if (!_cddbuffer) + return; + + cdCanvasLineWidth(_cddbuffer, inStyle.mPenWidth); + cdCanvasLineStyle(_cddbuffer, inStyle.mPenStyle); + + cdCanvasNativeFont(_cddbuffer, IupGetAttribute(_ih, "FONT")); + + if (inStyle.mFontStyle != -1 || inStyle.mFontSize != 0) + cdCanvasFont(_cddbuffer, NULL, inStyle.mFontStyle, inStyle.mFontSize); + + cdCanvasMarkType(_cddbuffer, inStyle.mMarkStyle); + cdCanvasMarkSize(_cddbuffer, inStyle.mMarkSize); +} + +static int iPPlotMapMethod(Ihandle* ih) +{ +#ifdef USE_OPENGL + char StrData[100]; + int w, h; + IupGetIntInt(ih, "DRAWSIZE", &w, &h); + sprintf(StrData, "%dx%d", w, h); + + ih->data->plt->_cddbuffer = cdCreateCanvas(CD_GL, StrData); + if (!ih->data->plt->_cddbuffer) + return IUP_ERROR; +#else + int old_gdi = 0; + + if (IupGetInt(ih, "USE_GDI+") || IupGetInt(ih, "USE_CONTEXTPLUS")) + old_gdi = cdUseContextPlus(1); + + ih->data->plt->_cdcanvas = cdCreateCanvas(CD_IUP, ih); + if (ih->data->plt->_cdcanvas) + { + /* this can fail if canvas size is zero */ + if (IupGetInt(ih, "USE_IMAGERGB")) + ih->data->plt->_cddbuffer = cdCreateCanvas(CD_DBUFFERRGB, ih->data->plt->_cdcanvas); + else + ih->data->plt->_cddbuffer = cdCreateCanvas(CD_DBUFFER, ih->data->plt->_cdcanvas); + + if (IupGetInt(ih, "USE_GDI+") || IupGetInt(ih, "USE_CONTEXTPLUS")) + cdUseContextPlus(old_gdi); + } + + if (!ih->data->plt->_cdcanvas) + return IUP_ERROR; +#endif + + ih->data->plt->_redraw = 1; + + return IUP_NOERROR; +} + +static void iPPlotUnMapMethod(Ihandle* ih) +{ + if (ih->data->plt->_cddbuffer != NULL) + { + cdKillCanvas(ih->data->plt->_cddbuffer); + ih->data->plt->_cddbuffer = NULL; + } + +#ifndef USE_OPENGL + if (ih->data->plt->_cdcanvas != NULL) + { + cdKillCanvas(ih->data->plt->_cdcanvas); + ih->data->plt->_cdcanvas = NULL; + } +#endif +} + +static void iPPlotDestroyMethod(Ihandle* ih) +{ + delete ih->data->plt; +} + +static int iPPlotCreateMethod(Ihandle* ih, void **params) +{ + (void)params; + + /* free the data alocated by IupCanvas */ + free(ih->data); + ih->data = iupALLOCCTRLDATA(); + + /* Initializing object with no cd canvases */ + ih->data->plt = new PPainterIup(ih); + + /* IupCanvas callbacks */ + IupSetCallback(ih, "ACTION", (Icallback)iPPlotRedraw_CB); + IupSetCallback(ih, "RESIZE_CB", (Icallback)iPPlotResize_CB); + IupSetCallback(ih, "BUTTON_CB", (Icallback)iPPlotMouseButton_CB); + IupSetCallback(ih, "MOTION_CB", (Icallback)iPPlotMouseMove_CB); + IupSetCallback(ih, "KEYPRESS_CB", (Icallback)iPPlotKeyPress_CB); + +#ifdef USE_OPENGL + IupSetAttribute(ih, "BUFFER", "DOUBLE"); +#endif + + return IUP_NOERROR; +} + +static Iclass* iPPlotNewClass(void) +{ +#ifdef USE_OPENGL + Iclass* ic = iupClassNew(iupRegisterFindClass("glcanvas")); +#else + Iclass* ic = iupClassNew(iupRegisterFindClass("canvas")); +#endif + + ic->name = "pplot"; + ic->format = NULL; /* none */ + ic->nativetype = IUP_TYPECANVAS; + ic->childtype = IUP_CHILDNONE; + ic->is_interactive = 1; + + /* Class functions */ + ic->New = iPPlotNewClass; + ic->Create = iPPlotCreateMethod; + ic->Destroy = iPPlotDestroyMethod; + ic->Map = iPPlotMapMethod; + ic->UnMap = iPPlotUnMapMethod; + + /* IupPPlot Callbacks */ + iupClassRegisterCallback(ic, "POSTDRAW_CB", "v"); + iupClassRegisterCallback(ic, "PREDRAW_CB", "v"); + iupClassRegisterCallback(ic, "DELETE_CB", "iiff"); + iupClassRegisterCallback(ic, "DELETEBEGIN_CB", ""); + iupClassRegisterCallback(ic, "DELETEEND_CB", ""); + iupClassRegisterCallback(ic, "SELECT_CB", "iiffi"); + iupClassRegisterCallback(ic, "SELECTBEGIN_CB", ""); + iupClassRegisterCallback(ic, "SELECTEND_CB", ""); + iupClassRegisterCallback(ic, "EDIT_CB", "iiffvv"); + iupClassRegisterCallback(ic, "EDITBEGIN_CB", ""); + iupClassRegisterCallback(ic, "EDITEND_CB", ""); + + /* Visual */ + iupClassRegisterAttribute(ic, "BGCOLOR", iPPlotGetBGColorAttrib, iPPlotSetBGColorAttrib, IUPAF_SAMEASSYSTEM, "255 255 255", IUPAF_NOT_MAPPED); /* overwrite canvas implementation, set a system default to force a new default */ + iupClassRegisterAttribute(ic, "FGCOLOR", iPPlotGetFGColorAttrib, iPPlotSetFGColorAttrib, IUPAF_SAMEASSYSTEM, "0 0 0", IUPAF_NOT_MAPPED); + + /* IupPPlot only */ + + iupClassRegisterAttribute(ic, "REDRAW", NULL, iPPlotSetRedrawAttrib, NULL, NULL, IUPAF_WRITEONLY|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "TITLE", iPPlotGetTitleAttrib, iPPlotSetTitleAttrib, NULL, NULL, IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "TITLEFONTSIZE", iPPlotGetTitleFontSizeAttrib, iPPlotSetTitleFontSizeAttrib, NULL, NULL, IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "TITLEFONTSTYLE", NULL, iPPlotSetTitleFontStyleAttrib, NULL, NULL, IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "LEGENDSHOW", iPPlotGetLegendShowAttrib, iPPlotSetLegendShowAttrib, NULL, NULL, IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "LEGENDPOS", iPPlotGetLegendPosAttrib, iPPlotSetLegendPosAttrib, IUPAF_SAMEASSYSTEM, "TOPRIGHT", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "LEGENDFONTSIZE", NULL, iPPlotSetLegendFontSizeAttrib, NULL, NULL, IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "LEGENDFONTSTYLE", NULL, iPPlotSetLegendFontStyleAttrib, NULL, NULL, IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "MARGINLEFT", iPPlotGetMarginLeftAttrib, iPPlotSetMarginLeftAttrib, NULL, NULL, IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "MARGINRIGHT", iPPlotGetMarginRightAttrib, iPPlotSetMarginRightAttrib, NULL, NULL, IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "MARGINTOP", iPPlotGetMarginTopAttrib, iPPlotSetMarginTopAttrib, NULL, NULL, IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "MARGINBOTTOM", iPPlotGetMarginBottomAttrib, iPPlotSetMarginBottomAttrib, NULL, NULL, IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "GRIDLINESTYLE", iPPlotGetGridLineStyleAttrib, iPPlotSetGridLineStyleAttrib, IUPAF_SAMEASSYSTEM, "CONTINUOUS", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "GRIDCOLOR", iPPlotGetGridColorAttrib, iPPlotSetGridColorAttrib, IUPAF_SAMEASSYSTEM, "200 200 200", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "GRID", iPPlotGetGridAttrib, iPPlotSetGridAttrib, NULL, NULL, IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + + iupClassRegisterAttribute(ic, "DS_LINESTYLE", iPPlotGetDSLineStyleAttrib, iPPlotSetDSLineStyleAttrib, IUPAF_SAMEASSYSTEM, "CONTINUOUS", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "DS_LINEWIDTH", iPPlotGetDSLineWidthAttrib, iPPlotSetDSLineWidthAttrib, IUPAF_SAMEASSYSTEM, "1", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "DS_MARKSTYLE", iPPlotGetDSMarkStyleAttrib, iPPlotSetDSMarkStyleAttrib, IUPAF_SAMEASSYSTEM, "X", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "DS_MARKSIZE", iPPlotGetDSMarkSizeAttrib, iPPlotSetDSMarkSizeAttrib, IUPAF_SAMEASSYSTEM, "7", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "DS_LEGEND", iPPlotGetDSLegendAttrib, iPPlotSetDSLegendAttrib, NULL, NULL, IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "DS_COLOR", iPPlotGetDSColorAttrib, iPPlotSetDSColorAttrib, NULL, NULL, IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "DS_SHOWVALUES", iPPlotGetDSShowValuesAttrib, iPPlotSetDSShowValuesAttrib, NULL, NULL, IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "DS_MODE", iPPlotGetDSModeAttrib, iPPlotSetDSModeAttrib, IUPAF_SAMEASSYSTEM, "LINE", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "DS_EDIT", iPPlotGetDSEditAttrib, iPPlotSetDSEditAttrib, NULL, NULL, IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "DS_REMOVE", NULL, iPPlotSetDSRemoveAttrib, NULL, NULL, IUPAF_WRITEONLY|IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "DS_COUNT", iPPlotGetDSCountAttrib, NULL, NULL, NULL, IUPAF_READONLY|IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + + iupClassRegisterAttribute(ic, "AXS_XLABEL", iPPlotGetAxisXLabelAttrib, iPPlotSetAxisXLabelAttrib, NULL, NULL, IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_YLABEL", iPPlotGetAxisYLabelAttrib, iPPlotSetAxisYLabelAttrib, NULL, NULL, IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_XLABELCENTERED", iPPlotGetAxisXLabelCenteredAttrib, iPPlotSetAxisXLabelCenteredAttrib, IUPAF_SAMEASSYSTEM, "YES", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_YLABELCENTERED", iPPlotGetAxisYLabelCenteredAttrib, iPPlotSetAxisYLabelCenteredAttrib, IUPAF_SAMEASSYSTEM, "YES", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_XCOLOR", iPPlotGetAxisXColorAttrib, iPPlotSetAxisXColorAttrib, IUPAF_SAMEASSYSTEM, "0 0 0", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_YCOLOR", iPPlotGetAxisYColorAttrib, iPPlotSetAxisYColorAttrib, IUPAF_SAMEASSYSTEM, "0 0 0", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_XAUTOMIN", iPPlotGetAxisXAutoMinAttrib, iPPlotSetAxisXAutoMinAttrib, IUPAF_SAMEASSYSTEM, "YES", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_YAUTOMIN", iPPlotGetAxisYAutoMinAttrib, iPPlotSetAxisYAutoMinAttrib, IUPAF_SAMEASSYSTEM, "YES", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_XAUTOMAX", iPPlotGetAxisXAutoMaxAttrib, iPPlotSetAxisXAutoMaxAttrib, IUPAF_SAMEASSYSTEM, "YES", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_YAUTOMAX", iPPlotGetAxisYAutoMaxAttrib, iPPlotSetAxisYAutoMaxAttrib, IUPAF_SAMEASSYSTEM, "YES", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_XMIN", iPPlotGetAxisXMinAttrib, iPPlotSetAxisXMinAttrib, NULL, NULL, IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_YMIN", iPPlotGetAxisYMinAttrib, iPPlotSetAxisYMinAttrib, NULL, NULL, IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_XMAX", iPPlotGetAxisXMaxAttrib, iPPlotSetAxisXMaxAttrib, NULL, NULL, IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_YMAX", iPPlotGetAxisYMaxAttrib, iPPlotSetAxisYMaxAttrib, NULL, NULL, IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_XREVERSE", iPPlotGetAxisXReverseAttrib, iPPlotSetAxisXReverseAttrib, NULL, NULL, IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_YREVERSE", iPPlotGetAxisYReverseAttrib, iPPlotSetAxisYReverseAttrib, NULL, NULL, IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_XCROSSORIGIN", iPPlotGetAxisXCrossOriginAttrib, iPPlotSetAxisXCrossOriginAttrib, IUPAF_SAMEASSYSTEM, "YES", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_YCROSSORIGIN", iPPlotGetAxisYCrossOriginAttrib, iPPlotSetAxisYCrossOriginAttrib, IUPAF_SAMEASSYSTEM, "YES", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_XSCALE", iPPlotGetAxisXScaleAttrib, iPPlotSetAxisXScaleAttrib, IUPAF_SAMEASSYSTEM, "LIN", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_YSCALE", iPPlotGetAxisYScaleAttrib, iPPlotSetAxisYScaleAttrib, IUPAF_SAMEASSYSTEM, "LIN", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_XFONTSIZE", iPPlotGetAxisXFontSizeAttrib, iPPlotSetAxisXFontSizeAttrib, NULL, NULL, IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_YFONTSIZE", iPPlotGetAxisYFontSizeAttrib, iPPlotSetAxisYFontSizeAttrib, NULL, NULL, IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_XFONTSTYLE", iPPlotGetAxisXFontStyleAttrib, iPPlotSetAxisXFontStyleAttrib, NULL, NULL, IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_YFONTSTYLE", iPPlotGetAxisYFontStyleAttrib, iPPlotSetAxisYFontStyleAttrib, NULL, NULL, IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_XTICK", iPPlotGetAxisXTickAttrib, iPPlotSetAxisXTickAttrib, IUPAF_SAMEASSYSTEM, "YES", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_YTICK", iPPlotGetAxisYTickAttrib, iPPlotSetAxisYTickAttrib, IUPAF_SAMEASSYSTEM, "YES", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_XTICKSIZE", iPPlotGetAxisXTickSizeAttrib, iPPlotSetAxisXTickSizeAttrib, IUPAF_SAMEASSYSTEM, "5", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_YTICKSIZE", iPPlotGetAxisYTickSizeAttrib, iPPlotSetAxisYTickSizeAttrib, IUPAF_SAMEASSYSTEM, "5", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_XTICKFORMAT", iPPlotGetAxisXTickFormatAttrib, iPPlotSetAxisXTickFormatAttrib, IUPAF_SAMEASSYSTEM, "%.0f", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_YTICKFORMAT", iPPlotGetAxisYTickFormatAttrib, iPPlotSetAxisYTickFormatAttrib, IUPAF_SAMEASSYSTEM, "%.0f", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_XTICKFONTSIZE", iPPlotGetAxisXTickFontSizeAttrib, iPPlotSetAxisXTickFontSizeAttrib, NULL, NULL, IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_YTICKFONTSIZE", iPPlotGetAxisYTickFontSizeAttrib, iPPlotSetAxisYTickFontSizeAttrib, NULL, NULL, IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_XTICKFONTSTYLE", iPPlotGetAxisXTickFontStyleAttrib, iPPlotSetAxisXTickFontStyleAttrib, NULL, NULL, IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_YTICKFONTSTYLE", iPPlotGetAxisYTickFontStyleAttrib, iPPlotSetAxisYTickFontStyleAttrib, NULL, NULL, IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_XAUTOTICK", iPPlotGetAxisXAutoTickAttrib, iPPlotSetAxisXAutoTickAttrib, IUPAF_SAMEASSYSTEM, "YES", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_YAUTOTICK", iPPlotGetAxisYAutoTickAttrib, iPPlotSetAxisYAutoTickAttrib, IUPAF_SAMEASSYSTEM, "YES", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_XAUTOTICKSIZE", iPPlotGetAxisXAutoTickSizeAttrib, iPPlotSetAxisXAutoTickSizeAttrib, IUPAF_SAMEASSYSTEM, "5", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_YAUTOTICKSIZE", iPPlotGetAxisYAutoTickSizeAttrib, iPPlotSetAxisYAutoTickSizeAttrib, IUPAF_SAMEASSYSTEM, "5", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_XTICKMAJORSPAN", iPPlotGetAxisXTickMajorSpanAttrib, iPPlotSetAxisXTickMajorSpanAttrib, IUPAF_SAMEASSYSTEM, "1", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_YTICKMAJORSPAN", iPPlotGetAxisYTickMajorSpanAttrib, iPPlotSetAxisYTickMajorSpanAttrib, IUPAF_SAMEASSYSTEM, "1", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_XTICKDIVISION", iPPlotGetAxisXTickDivisionAttrib, iPPlotSetAxisXTickDivisionAttrib, IUPAF_SAMEASSYSTEM, "5", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_YTICKDIVISION", iPPlotGetAxisYTickDivisionAttrib, iPPlotSetAxisYTickDivisionAttrib, IUPAF_SAMEASSYSTEM, "5", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_XAUTOTICKSIZE", iPPlotGetAxisXAutoTickSizeAttrib, iPPlotSetAxisXAutoTickSizeAttrib, IUPAF_SAMEASSYSTEM, "YES", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_YAUTOTICKSIZE", iPPlotGetAxisYAutoTickSizeAttrib, iPPlotSetAxisYAutoTickSizeAttrib, IUPAF_SAMEASSYSTEM, "YES", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_XTICKMAJORSIZE", iPPlotGetAxisXTickMajorSizeAttrib, iPPlotSetAxisXTickMajorSizeAttrib, IUPAF_SAMEASSYSTEM, "8", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "AXS_YTICKMAJORSIZE", iPPlotGetAxisYTickMajorSizeAttrib, iPPlotSetAxisYTickMajorSizeAttrib, IUPAF_SAMEASSYSTEM, "8", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + + iupClassRegisterAttribute(ic, "REMOVE", NULL, iPPlotSetRemoveAttrib, NULL, NULL, IUPAF_WRITEONLY|IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "CLEAR", NULL, iPPlotSetClearAttrib, NULL, NULL, IUPAF_WRITEONLY|IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "COUNT", iPPlotGetCountAttrib, NULL, NULL, NULL, IUPAF_READONLY|IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + iupClassRegisterAttribute(ic, "CURRENT", iPPlotGetCurrentAttrib, iPPlotSetCurrentAttrib, IUPAF_SAMEASSYSTEM, "-1", IUPAF_NOT_MAPPED|IUPAF_NO_INHERIT); + + return ic; +} + +/* user level call: create control */ +Ihandle* IupPPlot(void) +{ + return IupCreate("pplot"); +} + +void IupPPlotOpen(void) +{ +#ifdef USE_OPENGL + IupGLCanvasOpen(); +#endif + + if (!IupGetGlobal("_IUP_PPLOT_OPEN")) + { + iupRegisterClass(iPPlotNewClass()); + IupSetGlobal("_IUP_PPLOT_OPEN", "1"); + } +} diff --git a/iup/test/matrix.c b/iup/test/matrix.c new file mode 100644 index 00000000..260ead9d --- /dev/null +++ b/iup/test/matrix.c @@ -0,0 +1,173 @@ +#include +#include +#include +#include + +#undef __IUPDEF_H +#include "iup.h" +#include "iupcontrols.h" +#include "iupcbs.h" + +static int mousemove_cb(Ihandle *ih, int lin, int col) +{ + printf("mousemove_cb(%d, %d)\n", lin, col); + return IUP_DEFAULT; +} + +static int drop(Ihandle *self, Ihandle *drop, int lin, int col) +{ + printf("drop_cb(%d, %d)\n", lin, col); + if(lin == 3 && col == 1) + { + IupSetAttribute(drop, "1", "A - Test of Very Big String for Dropdown!"); + IupSetAttribute(drop, "2", "B"); + IupSetAttribute(drop, "3", "C"); + IupSetAttribute(drop, "4", "XXX"); + IupSetAttribute(drop, "5", "5"); + IupSetAttribute(drop, "6", "6"); + IupSetAttribute(drop, "7", "7"); + IupSetAttribute(drop, "8", NULL); + IupSetAttribute(drop, "VALUE", "4"); + return IUP_DEFAULT; + } + return IUP_IGNORE; +} + +static int dropcheck_cb(Ihandle *self, int lin, int col) +{ + if (lin == 3 && col == 1) + return IUP_DEFAULT; + return IUP_IGNORE; +} + +static Ihandle* create_matrix(void) +{ + Ihandle* mat = IupMatrix(NULL); + + IupSetAttribute(mat, "NUMLIN", "20"); + IupSetAttribute(mat, "NUMCOL", "8"); +// IupSetAttribute(mat, "NUMCOL", "15"); +// IupSetAttribute(mat, "NUMLIN", "3"); +// IupSetAttribute(mat, "NUMCOL", "2"); +// IupSetAttribute(mat, "NUMLIN", "8"); +// IupSetAttribute(mat, "NUMCOL", "5"); + + IupSetAttribute(mat, "0:0", "Inflation"); + IupSetAttribute(mat, "1:0", "Medicine\nPharma"); + IupSetAttribute(mat, "2:0", "Food"); + IupSetAttribute(mat, "3:0", "Energy"); + IupSetAttribute(mat, "0:1", "January 2000"); + IupSetAttribute(mat, "0:2", "February 2000"); + IupSetAttribute(mat, "1:1", "5.6\n3.33"); + IupSetAttribute(mat, "2:1", "2.2"); + IupSetAttribute(mat, "3:2", "Very Very Very Very Very Large Text"); + IupSetAttribute(mat, "1:2", "4.5"); + IupSetAttribute(mat, "2:2", "8.1"); + IupSetAttribute(mat, "3:1", "3.4"); + IupSetAttribute(mat, "3:3", "Font Test"); +// IupSetAttribute(mat, "HEIGHT2", "30"); +// IupSetAttribute(mat, "WIDTH2", "190"); +// IupSetAttributeId(mat, "WIDTH", 2, "190"); + IupSetAttribute(mat,"SORTSIGN2","DOWN"); +// IupSetAttribute(mat, "WIDTHDEF", "34"); +// IupSetAttribute(mat,"MULTILINE", "YES"); +// IupSetAttribute(mat,"RESIZEMATRIX", "YES"); +// IupSetAttribute(mat,"HIDDENTEXTMARKS", "YES"); +// IupSetAttribute(mat,"USETITLESIZE", "YES"); + //IupSetAttribute(mat,"SCROLLBAR", "NO"); + //IupSetAttribute(mat, "BGCOLOR1:2", "255 92 255"); + //IupSetAttribute(mat, "BGCOLOR2:*", "92 92 255"); + //IupSetAttribute(mat, "BGCOLOR*:3", "255 92 92"); + //IupSetAttribute(mat, "FGCOLOR1:2", "255 0 0"); + //IupSetAttribute(mat, "FGCOLOR2:*", "0 128 0"); + //IupSetAttribute(mat, "FGCOLOR*:3", "0 0 255"); + IupSetAttribute(mat, "FONT3:3", "Helvetica, 24"); + //IupSetAttribute(mat, "FONT2:*", "Courier, 14"); + //IupSetAttribute(mat, "FONT*:3", "Times, Bold 14"); + //IupSetAttribute(mat, "ALIGNMENT2", "ARIGHT"); +// IupSetAttribute(mat, "ACTIVE", "NO"); +// IupSetAttribute(mat, "EXPAND", "NO"); +// IupSetAttribute(mat, "ALIGNMENT", "ALEFT"); + + IupSetAttribute(mat,"MARKMODE","CELL"); +// IupSetAttribute(mat,"MARKMODE","LIN"); +// IupSetAttribute(mat,"MARKMULTIPLE","NO"); + IupSetAttribute(mat,"MARKMULTIPLE","YES"); +// IupSetAttribute(mat,"MARKAREA","NOT_CONTINUOUS"); + IupSetAttribute(mat,"MARK2:2","YES"); + IupSetAttribute(mat,"MARK2:3","YES"); + IupSetAttribute(mat,"MARK3:3","YES"); + + IupSetAttribute(mat,"FRAMEVERTCOLOR1:2","BGCOLOR"); + IupSetAttribute(mat,"FRAMEHORIZCOLOR1:2","0 0 255"); + IupSetAttribute(mat,"FRAMEHORIZCOLOR1:3","0 255 0"); + IupSetAttribute(mat,"FRAMEVERTCOLOR2:2","255 255 0"); + IupSetAttribute(mat,"FRAMEVERTCOLOR*:4","0 255 0"); + +// IupSetAttribute(mat,"MARKMODE","LINCOL"); + + //IupSetAttribute(mat, "NUMCOL_VISIBLE_LAST", "YES"); + //IupSetAttribute(mat, "NUMLIN_VISIBLE_LAST", "YES"); +// IupSetAttribute(mat, "WIDTHDEF", "15"); + IupSetAttribute(mat, "20:8", "The End"); + IupSetAttribute(mat, "10:0", "Middle Line"); + IupSetAttribute(mat, "15:0", "Middle Line"); + IupSetAttribute(mat, "0:4", "Middle Column"); + IupSetAttribute(mat, "20:0", "Line Title Test"); + IupSetAttribute(mat, "0:8", "Column Title Test"); + IupSetAttribute(mat, "NUMCOL_VISIBLE", "3"); + IupSetAttribute(mat, "NUMLIN_VISIBLE", "5"); +// IupSetAttribute(mat,"EDITNEXT","COLCR"); + IupSetAttribute(mat, "NUMCOL_NOSCROLL", "1"); + +// IupSetAttribute(mat, "LIMITEXPAND", "Yes"); +// IupSetAttribute(mat, "XAUTOHIDE", "NO"); +// IupSetAttribute(mat, "YAUTOHIDE", "NO"); + +// IupSetAttribute(mat,"RASTERSIZE","x300"); +// IupSetAttribute(mat,"FITTOSIZE","LINES"); + + /* test for custom matrix attributes */ + //{ + // char* v; + // IupSetAttribute(mat, "MTX_LINE_ACTIVE_FLAG3:4", "Test1"); + // IupMatSetAttribute(mat, "MTX_LINE_ACTIVE_FLAG", 5, 7, "Test2"); + // printf("Test1=%s\n", IupGetAttribute(mat, "MTX_LINE_ACTIVE_FLAG3:4")); + // printf("Test2=%s\n", IupMatGetAttribute(mat, "MTX_LINE_ACTIVE_FLAG", 5, 7)); + //} + + IupSetCallback(mat, "DROPCHECK_CB", (Icallback)dropcheck_cb); +// IupSetCallback(mat,"DROP_CB",(Icallback)drop); + IupSetCallback(mat,"MENUDROP_CB",(Icallback)drop); +// IupSetCallback(mat, "MOUSEMOVE_CB", (Icallback)mousemove_cb); + + return mat; +} + +void MatrixTest(void) +{ + Ihandle* dlg, *box; + + box = IupVbox(create_matrix(), NULL); + IupSetAttribute(box, "MARGIN", "10x10"); + + dlg = IupDialog(box); + IupSetAttribute(dlg, "TITLE", "IupMatrix Simple Test"); + IupShowXY(dlg, IUP_CENTER, IUP_CENTER); +} + +#ifndef BIG_TEST +int main(int argc, char* argv[]) +{ + IupOpen(&argc, &argv); + IupControlsOpen(); + + MatrixTest(); + + IupMainLoop(); + + IupClose(); + + return EXIT_SUCCESS; +} +#endif diff --git a/iup/test/vbox.c b/iup/test/vbox.c new file mode 100644 index 00000000..f4275141 --- /dev/null +++ b/iup/test/vbox.c @@ -0,0 +1,132 @@ +#include +#include +#include + +void VboxTest(void) +{ + /* IUP identifiers */ + Ihandle *dlg; + Ihandle *fr1, *fr2, *fr3; + Ihandle *btn_11, *btn_12, *btn_13; + Ihandle *btn_21, *btn_22, *btn_23; + Ihandle *btn_31, *btn_32, *btn_33; + Ihandle *vbox_1, *vbox_2, *vbox_3; + + /* Creates frame 1 */ + fr1 = IupFrame + ( + vbox_1 = IupVbox + ( + IupFill(), + btn_11=IupButton("1", NULL), + btn_12=IupButton("2", NULL), + btn_13=IupButton("3", NULL), + IupFill(), + NULL + ) + ); + + IupSetAttribute(fr1, "TITLE", "ALIGNMENT=ALEFT"); + IupSetAttribute(btn_11, "SIZE", "20x30"); + IupSetAttribute(btn_12, "SIZE", "30x20"); +// IupSetAttribute(btn_12, "SIZE", "30x"); +// IupSetAttribute(btn_12, "EXPAND", "VERTICAL"); +// IupSetAttribute(btn_12, "EXPANDWEIGHT", "1.3"); + IupSetAttribute(btn_13, "SIZE", "40x30"); +// IupSetAttribute(btn_13, "EXPAND", "VERTICAL"); +// IupSetAttribute(btn_13, "SIZE", "40x"); +// IupSetAttribute(btn_13, "EXPANDWEIGHT", "0.7"); + IupSetAttribute(vbox_1, "ALIGNMENT", "ALEFT"); +// IupSetAttribute(vbox_1, "MARGIN", "20x20"); +// IupSetAttribute(vbox_1, "GAP", "10"); +// IupSetAttribute(vbox_1, "HOMOGENEOUS", "YES"); +// IupSetAttribute(vbox_1, "EXPANDCHILDREN", "YES"); +// IupSetAttribute(btn_12, "VISIBLE", "NO"); +// IupSetAttribute(btn_12, "FLOATING", "YES"); +// IupSetAttribute(vbox_1, "NORMALIZESIZE", "BOTH"); + + + /* Creates frame 2 */ + fr2 = IupFrame + ( + vbox_2 = IupVbox + ( + IupFill(), + btn_21 = IupButton ("1", NULL), + btn_22 = IupButton ("2", NULL), + btn_23 = IupButton ("3", NULL), + IupFill(), + NULL + ) + ); + + IupSetAttribute(fr2, "TITLE", "ALIGNMENT=ACENTER"); + IupSetAttribute(btn_21, "SIZE", "20x30"); + IupSetAttribute(btn_22, "SIZE", "30x30"); + IupSetAttribute(btn_22, "EXPAND", "VERTICAL"); + IupSetAttribute(btn_23, "SIZE", "40x30"); + IupSetAttribute(btn_23, "EXPAND", "VERTICAL"); +// IupSetAttribute(vbox_2, "ALIGNMENT", "ACENTER"); + + /* Creates frame 3 */ + fr3 = IupFrame + ( + vbox_3 = IupVbox + ( + IupFill (), + btn_31=IupButton ("1", NULL), + btn_32=IupButton ("2", NULL), + btn_33=IupButton ("3", NULL), + IupFill (), + NULL + ) + ); + + IupSetAttribute(fr3, "TITLE", "ALIGNMENT=ARIGHT"); + IupSetAttribute(btn_31, "SIZE", "20x30"); + IupSetAttribute(btn_32, "SIZE", "30x30"); + IupSetAttribute(btn_33, "SIZE", "40x30"); + IupSetAttribute(vbox_3, "ALIGNMENT", "ARIGHT"); + + dlg = IupDialog + ( + IupHbox + ( + fr1, + IupFill (), + fr2, + IupFill (), + fr3, + IupFill (), + NULL + ) + ); + + IupSetAttribute(dlg, "TITLE", "IupVbox Test"); /* Sets dlg's title */ + IupSetAttribute(dlg, "MARGIN", "10x10"); + IupSetAttribute(dlg, "GAP", "10"); + IupSetAttribute(fr1, "MARGIN", "0x0"); /* avoid attribute propagation */ + IupSetAttribute(fr2, "MARGIN", "0x0"); + IupSetAttribute(fr3, "MARGIN", "0x0"); + IupSetAttribute(fr1, "GAP", "0"); + IupSetAttribute(fr2, "GAP", "0"); + IupSetAttribute(fr3, "GAP", "0"); + + /* Shows dlg in the center of the screen */ + IupShowXY(dlg, IUP_CENTER, IUP_CENTER); +} + +#ifndef BIG_TEST +int main(int argc, char* argv[]) +{ + IupOpen(&argc, &argv); + + VboxTest(); + + IupMainLoop(); + + IupClose(); + + return EXIT_SUCCESS; +} +#endif