123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565 |
- class IUP_CELLS
- -- Creates a grid widget (set of cells) that enables several
- -- application-specific drawing, such as: chess tables, tiles editors, degrade
- -- scales, drawable spreadsheets and so forth.
- --
- -- This element is mostly based on application callbacks functions that
- -- determine the number of cells (rows and columns), their appearance and
- -- interaction. This mechanism offers full flexibility to applications, but
- -- requires programmers attention to avoid infinite loops inside this
- -- functions. Using callbacks, cells can be also grouped to form major or
- -- hierarchical elements, such as headers, footers etc. This callback approach
- -- was intentionally chosen to allow all cells to be dynamically and directly
- -- changed based on application's data structures. Since the size of each cell
- -- is given by the application the size of the control also must be given using
- -- size or raster_size attributes.
- --
- -- It inherits from IUP_CANVAS.
- inherit
- IUP_CONTROLS
- rename
- canvas as cells
- redefine
- cells,
- get_cd_canvas,
- execute_draw,
- execute_height,
- execute_hspan,
- execute_mouseclick,
- execute_mousemotion,
- execute_ncols,
- execute_nlines,
- execute_scrolling,
- execute_vspan,
- execute_width
- end
- create {ANY}
- cells
- feature {ANY}
- cells
- local
- a_cells: POINTER
- do
- a_cells := int_cells
- set_widget(a_cells)
- end
- -- Attributes
- set_boxed (state: BOOLEAN)
- -- Determines if the bounding cells' regions should be drawn with black
- -- lines. Default: "True". If the "span" attributes are used, set this
- -- attribute to "False" to avoid grid drawing over spanned cells.
- do
- iup_open.set_attribute(Current, "BOXED", boolean_to_yesno(state))
- end
- set_bufferize (state: BOOLEAN)
- -- Disables the automatic redrawing of the control, so many attributes
- -- can be changed without many redraws. When set to "False" the control
- -- is redrawn. When REPAINT attribute is set, BUFFERIZE is automatically
- -- set to "False". Default: "False".
- do
- iup_open.set_attribute(Current, "BUFFERIZE", boolean_to_yesno(state))
- end
- get_cd_canvas: CD_IUP
- -- (non inheritable): Returns the internal IUP CD canvas. This
- -- attribute should be used only in specific cases and by experienced
- -- CD programmers.
- local
- p: POINTER
- do
- p := iup_open.get_attribute_ihandle(Current, "CANVAS")
-
- Result := internal_cd(p)
- end
- set_clipped (state: BOOLEAN)
- -- Determines if, before cells drawing, each bounding region should be
- -- clipped. This attribute should be changed in few specific cases.
- -- Default: "True".
- do
- iup_open.set_attribute(Current, "CLIPPED", boolean_to_yesno(state))
- end
- get_first_column: INTEGER
- -- Returns the number of the first visible column.
- local
- str: STRING
- do
- str := iup_open.get_attribute(Current, "FIRST_COL")
- if str.is_integer then
- Result := str.to_integer
- end
- end
- get_first_line: INTEGER
- -- Returns the number of the first visible line.
- local
- str: STRING
- do
- str := iup_open.get_attribute(Current, "FIRST_LINE")
- if str.is_integer then
- Result := str.to_integer
- end
- end
- set_full_visible (line, column: INTEGER)
- -- Tries to show completely a specific cell (considering any vertical or
- -- horizontal header or scrollbar position).
- local
- value: STRING
- do
- create value.make_from_string(line.out)
- value.append_string(":")
- value.append_string(column.out)
- iup_open.set_attribute(Current, "FULL_VISIBLE", value)
- end
- -- Skip image_canvas
- get_limits (line, column: INTEGER): TUPLE[INTEGER, INTEGER, INTEGER, INTEGER]
- -- Returns the limits of a given cell.
- local
- str: STRING
- do
- str := iup_open.get_attribute_id2 (Current, "LIMITS", line, column)
- Result := components_of_limits(str)
- end
- set_non_scrollable_lines (number: INTEGER)
- -- Determines the number of non-scrollable lines (vertical headers) that
- -- should always be visible despite the vertical scrollbar position. It
- -- can be any non-negative integer value. Default: "0".
- require
- number >= 0
- do
- iup_open.set_attribute(Current, "NON_SCROLLABLE_LINES",
- number.out)
- end
- set_non_scrollable_columns (number: INTEGER)
- -- Determines the number of non-scrollable columns (horizontal headers)
- -- that should always be visible despite the horizontal scrollbar
- -- position. It can be any non-negative integer value. Default: "0".
- require
- number >= 0
- do
- iup_open.set_attribute(Current, "NON_SCROLLABLE_COLS",
- number.out)
- end
- set_origin (line, column: INTEGER)
- -- Sets the first visible line and column positions.
- local
- value: STRING
- do
- create value.make_from_string(line.out)
- value.append_string(":")
- value.append_string(column.out)
- iup_open.set_attribute(Current, "ORIGIN", value)
- end
- set_scrollbar (state: BOOLEAN)
- -- Default: "True".
- do
- iup_open.set_attribute(Current, "SCROLLBAR", boolean_to_yesno(state))
- end
-
- -- Operations
- repaint
- -- Provokes the control to be redrawn.
- do
- iup_open.set_attribute(Current, "REPAINT", "Yes")
- end
- -- Callbacks
- set_cb_draw (act: detachable FUNCTION[TUPLE[IUP_CELLS, INTEGER, INTEGER, INTEGER, INTEGER, INTEGER, INTEGER, CD_IUP], STRING])
- -- Called when a specific cell needs to be redrawn.
- --
- -- ih: identifier of the element that activated the event.
- -- line, column: the grid position inside the control that is being
- -- redrawn, in grid coordinates.
- -- xmin, xmax, ymin, ymax: the raster bounding box of the redrawn cells,
- -- where the application can use CD functions to draw anything. If
- -- the attribute IUP_CLIPPED is set (the default), all CD graphical
- -- primitives is clipped to the bounding region.
- -- canvas: internal canvas CD used to draw the cells.
- --
- -- Returns: "IUP_DEFAULT", "IUP_CONTINUE" or "IUP_IGNORE"
- local
- operation: INTEGER
- do
- cb_draw := act
- if cb_draw /= Void then
- operation := 1
- else
- operation := 0
- end
-
- iup_open.set_callback (Current, "DRAW_CB", "NONEEDED", operation)
- end
- set_cb_height (act: detachable FUNCTION[TUPLE[IUP_CELLS, INTEGER], INTEGER])
- -- Called when the controls needs to know a (eventually new) line height.
- --
- -- ih: identifier of the element that activated the event.
- -- line: the line index
- --
- -- Returns: an integer that specifies the desired height (in pixels).
- -- Default is 30 pixels.
- local
- operation: INTEGER
- do
- cb_height := act
- if cb_height /= Void then
- operation := 1
- else
- operation := 0
- end
-
- iup_open.set_callback (Current, "HEIGHT_CB", "NONEEDED", operation)
- end
- set_cb_horizontal_span (act: detachable FUNCTION[TUPLE[IUP_CELLS, INTEGER, INTEGER], INTEGER])
- -- Called when the control needs to know if a cell should be horizontally
- -- spanned.
- --
- -- ih: identifier of the element that activated the event.
- -- line, column: the line and column indexes (in grid coordinates)
- --
- -- Returns: an integer that specifies the desired span.
- -- Default is 1 (no span).
- local
- operation: INTEGER
- do
- cb_hspan := act
- if cb_hspan /= Void then
- operation := 1
- else
- operation := 0
- end
-
- iup_open.set_callback (Current, "HSPAN_CB", "NONEEDED", operation)
- end
- set_cb_mouse_click (act: detachable FUNCTION[TUPLE[IUP_CELLS, INTEGER, INTEGER, INTEGER, INTEGER, INTEGER, INTEGER, STRING], STRING])
- -- Same as "set_cb_button" at IUP_CANVAS callback with two additional
- -- parameters (the third and fourth integers):
- --
- -- IUP_CELLS: identifies the element that activated the event.
- -- button: as in "set_cb_button"
- -- pressed: as in "set_cb_button"
- -- line, column: the grid position in the control where the event has
- -- occurred, in grid coordinates.
- -- x, y: as in "set_cb_button"
- -- status: as in "set_cb_button"
- local
- operation: INTEGER
- do
- cb_mouseclick := act
- if cb_mouseclick /= Void then
- operation := 1
- else
- operation := 0
- end
-
- iup_open.set_callback (Current, "MOUSECLICK_CB", "NONEEDED", operation)
- end
- set_cb_mouse_motion (act: detachable FUNCTION[TUPLE[IUP_CELLS, INTEGER, INTEGER, INTEGER, INTEGER, STRING], STRING])
- -- Called when the mouse moves over the control.
- --
- -- Same as the "set_cb_motion" IUP_CANVAS callback with two additional
- -- parameters:
- --
- -- line, column: the grid position in the control where the event has
- -- occurred, in grid coordinates.
- local
- operation: INTEGER
- do
- cb_mousemotion := act
- if cb_mousemotion /= Void then
- operation := 1
- else
- operation := 0
- end
-
- iup_open.set_callback (Current, "MOUSEMOTION_CB", "NONEEDED", operation)
- end
- set_cb_number_of_columns (act: detachable FUNCTION[TUPLE[IUP_CELLS], INTEGER])
- -- Called when then controls needs to know its number of columns.
- --
- -- ih: identifier of the element that activated the event.
- --
- -- Returns: an integer that specifies the number of columns.
- -- Default is 10 columns.
- local
- operation: INTEGER
- do
- cb_ncols := act
- if cb_ncols /= Void then
- operation := 1
- else
- operation := 0
- end
-
- iup_open.set_callback (Current, "NCOLS_CB", "NONEEDED", operation)
- end
- set_cb_number_of_lines (act: detachable FUNCTION[TUPLE[IUP_CELLS], INTEGER])
- -- Called when then controls needs to know its number of lines.
- --
- -- ih: identifier of the element that activated the event.
- --
- -- Returns: an integer that specifies the number of lines.
- -- Default is 10 lines.
- local
- operation: INTEGER
- do
- cb_nlines := act
- if cb_nlines /= Void then
- operation := 1
- else
- operation := 0
- end
-
- iup_open.set_callback (Current, "NLINES_CB", "NONEEDED", operation)
- end
- set_cb_scrolling (act: detachable FUNCTION[TUPLE[IUP_CELLS, INTEGER, INTEGER], STRING])
- -- Called when the scrollbars are activated.
- --
- -- ih: identifier of the element that activated the event.
- -- line, column: the first visible line and column indexes (in grid
- -- coordinates)
- --
- -- Returns: If "IUP_IGNORE" the cell is not redrawn. By default the cell
- -- is always redrawn.
- local
- operation: INTEGER
- do
- cb_scrolling := act
- if cb_scrolling /= Void then
- operation := 1
- else
- operation := 0
- end
-
- iup_open.set_callback (Current, "SCROLLING_CB", "NONEEDED", operation)
- end
- set_cb_vertical_span (act: detachable FUNCTION[TUPLE[IUP_CELLS, INTEGER, INTEGER], INTEGER])
- -- Called when the control needs to know if a cell should be vertically
- -- spanned.
- --
- -- ih: identifier of the element that activated the event.
- -- line, column: the line and column indexes (in grid coordinates)
- --
- -- Returns: an integer that specifies the desired span.
- -- Default is 1 (no span).
- local
- operation: INTEGER
- do
- cb_vspan := act
- if cb_vspan /= Void then
- operation := 1
- else
- operation := 0
- end
-
- iup_open.set_callback (Current, "VSPAN_CB", "NONEEDED", operation)
- end
- set_cb_width (act: detachable FUNCTION[TUPLE[IUP_CELLS, INTEGER], INTEGER])
- -- Called when the controls needs to know the column width.
- --
- -- ih: identifier of the element that activated the event.
- -- column: the column index
- --
- -- Returns: an integer that specifies the desired width (in pixels).
- -- Default is 60 pixels.
- local
- operation: INTEGER
- do
- cb_width := act
- if cb_width /= Void then
- operation := 1
- else
- operation := 0
- end
-
- iup_open.set_callback (Current, "WIDTH_CB", "NONEEDED", operation)
- end
- feature {IUP}
- execute_draw (line, column, xmin, xmax, ymin, ymax: INTEGER; canvas: POINTER): STRING
- do
- if attached cb_draw as int_cb then
- Result := int_cb.item([Current, line, column, xmin, xmax, ymin, ymax, internal_cd(canvas)])
- else
- Result := "IUP_DEFAULT"
- end
- end
- execute_height (line: INTEGER): INTEGER
- do
- if attached cb_height as int_cb then
- Result := int_cb.item([Current, line])
- else
- Result := 0
- end
- end
- execute_hspan (line, column: INTEGER): INTEGER
- do
- if attached cb_hspan as int_cb then
- Result := int_cb.item([Current, line, column])
- else
- Result := 0
- end
- end
- execute_mouseclick (btn, prd, l, c, x, y: INTEGER; s: STRING): STRING
- do
- if attached cb_mouseclick as int_cb then
- Result := int_cb.item([Current, btn, prd, l, c, x, y, s])
- else
- Result := "IUP_DEFAULT"
- end
- end
- execute_mousemotion (l, c, x, y: INTEGER; r: STRING): STRING
- do
- if attached cb_mousemotion as int_cb then
- Result := int_cb.item([Current, l, c, x, y, r])
- else
- Result := "IUP_DEFAULT"
- end
- end
- execute_ncols: INTEGER
- do
- if attached cb_ncols as int_cb then
- Result := int_cb.item([Current])
- else
- Result := 0
- end
- end
- execute_nlines: INTEGER
- do
- if attached cb_nlines as int_cb then
- Result := int_cb.item([Current])
- else
- Result := 0
- end
- end
- execute_scrolling (l, c: INTEGER): STRING
- do
- if attached cb_scrolling as int_cb then
- Result := int_cb.item([Current, l, c])
- else
- Result := "IUP_DEFAULT"
- end
- end
- execute_vspan (l, c: INTEGER): INTEGER
- do
- if attached cb_vspan as int_cb then
- Result := int_cb.item([Current, l, c])
- else
- Result := 0
- end
- end
- execute_width (c: INTEGER): INTEGER
- do
- if attached cb_width as int_cb then
- Result := int_cb.item([Current, c])
- else
- Result := 0
- end
- end
- feature {NONE}
- cb_draw: detachable FUNCTION[TUPLE[IUP_CELLS, INTEGER, INTEGER, INTEGER, INTEGER, INTEGER, INTEGER, CD_IUP], STRING]
- cb_height: detachable FUNCTION[TUPLE[IUP_CELLS, INTEGER], INTEGER]
- cb_hspan: detachable FUNCTION[TUPLE[IUP_CELLS, INTEGER, INTEGER], INTEGER]
- cb_mouseclick: detachable FUNCTION[TUPLE[IUP_CELLS, INTEGER, INTEGER, INTEGER, INTEGER, INTEGER, INTEGER, STRING], STRING]
- cb_mousemotion: detachable FUNCTION[TUPLE[IUP_CELLS, INTEGER, INTEGER, INTEGER, INTEGER, STRING], STRING]
- cb_ncols: detachable FUNCTION[TUPLE[IUP_CELLS], INTEGER]
- cb_nlines: detachable FUNCTION[TUPLE[IUP_CELLS], INTEGER]
- cb_scrolling: detachable FUNCTION[TUPLE[IUP_CELLS, INTEGER, INTEGER], STRING]
- cb_vspan: detachable FUNCTION[TUPLE[IUP_CELLS, INTEGER, INTEGER], INTEGER]
- cb_width: detachable FUNCTION[TUPLE[IUP_CELLS, INTEGER], INTEGER]
- -- Internals
- int_cells: POINTER
- external
- "C inline use %"eiffel-iup.h%""
- alias
- "return IupCells();"
- end
- end
- -- The MIT License (MIT)
- -- Copyright (c) 2016, 2019, 2020 by German A. Arias
- -- Permission is hereby granted, free of charge, to any person obtaining a copy
- -- of this software and associated documentation files (the "Software"), to deal
- -- in the Software without restriction, including without limitation the rights
- -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- -- copies of the Software, and to permit persons to whom the Software is
- -- furnished to do so, subject to the following conditions:
- --
- -- The above copyright notice and this permission notice shall be included in
- -- all copies or substantial portions of the Software.
- --
- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- -- SOFTWARE.
|