123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701 |
- class IUP_GET_PARAM
- -- Shows a modal dialog for capturing parameter values using several types of
- -- controls. After create the dialog with "get_param" you can add any
- -- amout of parameters with features "add_xxxx_parameter". The first
- -- argument in these features are the label of the parameter, you can
- -- add any number of characters %T at the label to indent the parameter entry.
- -- The argument "tip" is a string that is displayed as a tool-tip for the main
- -- control of the parameter. To add break lines in tool-tip string
- -- add the characters "%%r". You can pass an empty string if don't want a
- -- tool-tip. You can also add "separators" to organize the parameters.
- -- The dialog is resizable if it contains a string, a multiline string or a
- -- number with a valuator. All the multiline strings will increase size equally
- -- in both directions.
- --
- -- The dialog is resizable if it contains a string, a multiline string or a
- -- number with a valuator. All the multiline strings will increase size equally
- -- in both directions.
- --
- -- The dialog uses a global attribute called "PARENTDIALOG" as the parent
- -- dialog if it is defined. It also uses a global attribute called "ICON" as
- -- the dialog icon if it is defined.
- inherit
- IUP_WIDGET
- redefine
- execute_param
- end
- IUP_WIDGET_CUSTOM_ATTRIBUTES
- create {ANY}
- get_param
- feature {ANY}
-
- -- To store the default values at panel.
- pd: ARRAY[POINTER]
- get_param (title: STRING;
- act: FUNCTION[TUPLE[IUP_GET_PARAM, INTEGER, POINTER], INTEGER];
- user_data: POINTER)
- -- Create the dialog.
- --
- -- title: dialog title.
- -- act: user callback to be called whenever a parameter value was
- -- changed, and when the user pressed the OK button.
- -- user_data: user pointer passed to the user callback.
- --
- -- The callback receive three arguments:
- --
- -- dialog: the IUP_GET_PARAM object
- -- param_index: current parameter being changed. Can have negative values
- -- to indicate specific situations:
- -- -1 = if the user pressed the button 1.
- -- -2 = after the dialog is mapped and just before it is shown.
- -- -3 = if the user pressed the button 2.
- -- -4 = if the user pressed the button 3, if any.
- -- -5 = if the user clicked on the dialog close button.
- -- user_data: a user pointer that is passed in the function call.
- --
- -- Returns: You can reject the change or the button action by returning 0
- -- in the callback, otherwise you must return 1. By default button 1 and
- -- button 2 will close the dialog.
- --
- -- You should not programmatically change the current parameter value
- -- during the callback. On the other hand you can freely change the value
- -- of other parameters.
- do
- t := title
- cb_param := act
- ud := user_data
- pe := 0
- i := 1
- create f.make_empty
- create pd.make_empty
- end
- launch: INTEGER
- -- Show the dialog, return 1 if the button 1 was pressed, 0 if the button
- -- 2 was pressed or if an error occurred.
- local
- m: ARRAY[POINTER]
- x: INTEGER
- do
- iup_open.set_get_param (Current)
-
- x := 0
- create m.make_filled(default_pointer, 1, pd.count + 1)
- across
- pd as ic
- loop
- x := x + 1
- m.put(ic.item, x)
- end
- Result := int_get_param (get_pointer(t.to_c), ud,
- get_pointer(f.to_c), pd.count, pe,
- get_pointer(m.to_c))
- end
- -- Set parameters
- add_boolean_parameter (label, extra_data, tip: STRING; def: POINTER)
- -- Add an entry for a boolean parameter, it shows a True/False toggle.
- -- The "extra_data" parameter are optional strings, in the form
- -- "false_title,true_title" for boolean types to be displayed after the
- -- toggle. The strings can not have commas ',', nor brackets '[' or ']'.
- -- The "def" parameter should be a pointer to a integer with
- -- the initial value (0 for False and 1 to True).
- do
- f.append_string(label)
- f.append_string("%%b")
- if not extra_data.is_empty then
- f.append_string("[")
- f.append_string(extra_data)
- f.append_string("]")
- end
- if not tip.is_empty then
- f.append_string("{")
- f.append_string(tip)
- f.append_string("}")
- end
- f.append_string("%N")
- pd.force(def, i)
- i := i + 1
- end
- add_integer_parameter (label, extra_data, tip: STRING; def: POINTER)
- -- A field to a C integer value. The "extra_data" parameter is a
- -- string of the form "min,max,step". The "max" and "step" values can be
- -- omitted. When "min" and "max" are specified a valuator will also be
- -- added to change the value. To specify "step", "max" must be also
- -- specified. "step" is the size of the increment. The "def" parameter
- -- should be a pointer to a INTEGER with the initial value.
- -- A integer parameter always has a spin attached to the text to
- -- increment and decrement the value.
- do
- f.append_string(label)
- f.append_string("%%i")
- if not extra_data.is_empty then
- f.append_string("[")
- f.append_string(extra_data)
- f.append_string("]")
- end
- if not tip.is_empty then
- f.append_string("{")
- f.append_string(tip)
- f.append_string("}")
- end
- f.append_string("%N")
- pd.force(def, i)
- i := i + 1
- end
- add_real_parameter (label, extra_data, tip: STRING; def: POINTER)
- -- A field to a C real value. The "extra_data" parameter is a
- -- string of the form "min,max,step". The "max" and "step" values can be
- -- omitted. When "min" and "max" are specified a valuator will also be
- -- added to change the value. To specify "step", "max" must be also
- -- specified. "step" is the size of the increment. The "def" parameter
- -- should be a pointer to a REAL_32 with the initial value.
- -- A real parameter only has a spin in a full interval is defined (min
- -- and max), in this case the default step is (max-min)/20.
- do
- f.append_string(label)
- f.append_string("%%r")
- if not extra_data.is_empty then
- f.append_string("[")
- f.append_string(extra_data)
- f.append_string("]")
- end
- if not tip.is_empty then
- f.append_string("{")
- f.append_string(tip)
- f.append_string("}")
- end
- f.append_string("%N")
- pd.force(def, i)
- i := i + 1
- end
- add_double_parameter (label, extra_data, tip: STRING; def: POINTER)
- -- A field to a C double value. The "extra_data" parameter is a
- -- string of the form "min,max,step". The "max" and "step" values can be
- -- omitted. When "min" and "max" are specified a valuator will also be
- -- added to change the value. To specify "step", "max" must be also
- -- specified. "step" is the size of the increment. The "def" parameter
- -- should be a pointer to a REAL_64 with the initial value.
- -- A double parameter only has a spin in a full interval is defined (min
- -- and max), in this case the default step is (max-min)/20.
- do
- f.append_string(label)
- f.append_string("%%R")
- if not extra_data.is_empty then
- f.append_string("[")
- f.append_string(extra_data)
- f.append_string("]")
- end
- if not tip.is_empty then
- f.append_string("{")
- f.append_string(tip)
- f.append_string("}")
- end
- f.append_string("%N")
- pd.force(def, i)
- i := i + 1
- end
- add_angle_real_parameter (label, extra_data, tip: STRING; def: POINTER)
- -- A field to a C real value. The "extra_data" parameter is a
- -- string of the form "min,max,step". The "max" and "step" values can be
- -- omitted. When "min" and "max" are specified a dial will also be
- -- added to change the value (only if "load_iup_controls" is
- -- called on IUP). To specify "step", "max" must be also
- -- specified. "step" is the size of the increment. The "def" parameter
- -- should be a pointer to a REAL_32 with the initial value.
- do
- f.append_string(label)
- f.append_string("%%a")
- if not extra_data.is_empty then
- f.append_string("[")
- f.append_string(extra_data)
- f.append_string("]")
- end
- if not tip.is_empty then
- f.append_string("{")
- f.append_string(tip)
- f.append_string("}")
- end
- f.append_string("%N")
- pd.force(def, i)
- i := i + 1
- end
- add_angle_double_parameter (label, extra_data, tip: STRING; def: POINTER)
- -- A field to an C double value. The "extra_data" parameter is a
- -- string of the form "min,max,step". The "max" and "step" values can be
- -- omitted. When "min" and "max" are specified a dial will also be
- -- added to change the value (only if "load_iup_controls" is
- -- called on IUP). To specify "step", "max" must be also
- -- specified. "step" is the size of the increment. The "def" parameter
- -- should be a pointer to a REAL_64 with the initial value.
- do
- f.append_string(label)
- f.append_string("%%A")
- if not extra_data.is_empty then
- f.append_string("[")
- f.append_string(extra_data)
- f.append_string("]")
- end
- if not tip.is_empty then
- f.append_string("{")
- f.append_string(tip)
- f.append_string("}")
- end
- f.append_string("%N")
- pd.force(def, i)
- i := i + 1
- end
- add_string_parameter (label, extra_data, tip: STRING; def: POINTER)
- -- A field to a string value. The "extra_data" parameter is an optional
- -- mask for the string. The maks have the same format used in IUP_TEXT.
- -- For more information see:
- -- http://webserver2.tecgraf.puc-rio.br/iup/en/attrib/iup_mask.html
- -- Pass an empty string if don't want a mask.
- -- The "def" parameter should be a pointer to a STRING with the initial
- -- value (if any) and with enough space for the user entry.
- do
- f.append_string(label)
- f.append_string("%%s")
- if not extra_data.is_empty then
- f.append_string("[")
- f.append_string(extra_data)
- f.append_string("]")
- end
- if not tip.is_empty then
- f.append_string("{")
- f.append_string(tip)
- f.append_string("}")
- end
- f.append_string("%N")
- pd.force(def, i)
- i := i + 1
- end
- add_multiline_parameter (label, extra_data, tip: STRING; def: POINTER)
- -- A field to a multiline string value. The "extra_data" parameter is an
- -- optional mask for the string. The maks have the same format used in
- -- IUP_TEXT. For more information see:
- -- http://webserver2.tecgraf.puc-rio.br/iup/en/attrib/iup_mask.html
- -- Pass an empty string if don't want a mask.
- -- The "def" parameter should be a pointer to a STRING with the initial
- -- value (if any) and with enough space for the user entry.
- do
- f.append_string(label)
- f.append_string("%%m")
- if not extra_data.is_empty then
- f.append_string("[")
- f.append_string(extra_data)
- f.append_string("]")
- end
- if not tip.is_empty then
- f.append_string("{")
- f.append_string(tip)
- f.append_string("}")
- end
- f.append_string("%N")
- pd.force(def, i)
- i := i + 1
- end
- add_list_parameter (label, extra_data, tip: STRING; def: POINTER)
- -- A dropdown list box. The "extra_data" parameter is a string of the
- -- form "item0|item1|item2|...|itemN" with the titles of the items in the
- -- list. At least one item must exist. Items index are zero based start.
- -- The "def" parameter should be a pointer to an INTEGER with
- -- the initial value (the selected item).
- do
- f.append_string(label)
- f.append_string("%%l")
- if not extra_data.is_empty then
- f.append_string("|")
- f.append_string(extra_data)
- f.append_string("|")
- end
- if not tip.is_empty then
- f.append_string("{")
- f.append_string(tip)
- f.append_string("}")
- end
- f.append_string("%N")
- pd.force(def, i)
- i := i + 1
- end
- add_radio_parameter (label, extra_data, tip: STRING; def: POINTER)
- -- A list of toggles inside a radio. The "extra_data" parameter is a
- -- string of the form "item0|item1|item2|...|itemN" with
- -- the titles of the items in the list. At least one item must exist.
- -- Items index are zero based start. The "def" parameter should be a
- -- pointer to an INTEGER with the initial value (the selected item).
- do
- f.append_string(label)
- f.append_string("%%o")
- if not extra_data.is_empty then
- f.append_string("|")
- f.append_string(extra_data)
- f.append_string("|")
- end
- if not tip.is_empty then
- f.append_string("{")
- f.append_string(tip)
- f.append_string("}")
- end
- f.append_string("%N")
- pd.force(def, i)
- i := i + 1
- end
- add_separator (label: STRING)
- -- Separator. Shows a horizontal line separator label, in this case text
- -- can be an empty string.
- do
- f.append_string(label)
- f.append_string("%%t")
- f.append_string("%N")
- pe := pe + 1
- end
- add_date_parameter (label, extra_data, tip: STRING; def: POINTER)
- -- A string parameter, but the interface uses a IUP_DATE_PICK element to
- -- select a date. The "extra_data" parameter are simply IUP_DATE_PICK
- -- attributes in a single string. The "def" parameter should be a pointer
- -- to a string with the initial value and with enough space for the user
- -- entry.
- do
- f.append_string(label)
- f.append_string("%%d")
- if not extra_data.is_empty then
- f.append_string("|")
- f.append_string(extra_data)
- f.append_string("|")
- end
- if not tip.is_empty then
- f.append_string("{")
- f.append_string(tip)
- f.append_string("}")
- end
- f.append_string("%N")
- pd.force(def, i)
- i := i + 1
- end
- add_file_parameter (label, extra_data, tip: STRING; def: POINTER)
- -- A string parameter with a button to open a file selection dialog box.
- -- The "estra_data" is a string of the form
- -- "dialogtype|filter|directory|nochangedir|nooverwriteprompt"
- -- with the respective attribute values passed to the IUP_FILE_DIALOG
- -- control when activated. All '|' must exist, but you can let empty
- -- values to use the default values.
- -- The "def" parameter should be a pointer to a string with the
- -- initial value and with enough space for the user entry.
- do
- f.append_string(label)
- f.append_string("%%f")
- if not tip.is_empty then
- f.append_string("{")
- f.append_string(tip)
- f.append_string("}")
- end
- f.append_string("%N")
- pd.force(def, i)
- i := i + 1
- end
- add_color_parameter (label, tip: STRING; def: POINTER)
- -- A string parameter with a color button to open a color selection
- -- dialog box. The "def" parameter should be a pointer to a string
- -- with the initial value and with enough space for the user entry.
- do
- f.append_string(label)
- f.append_string("%%c")
- if not tip.is_empty then
- f.append_string("{")
- f.append_string(tip)
- f.append_string("}")
- end
- f.append_string("%N")
- pd.force(def, i)
- i := i + 1
- end
- add_font_parameter (label, tip: STRING; def: POINTER)
- -- A string parameter with a font button to open a font selection
- -- dialog box. The "def" parameter should be a pointer to a string
- -- with the initial value and with enough space for the user entry.
- do
- f.append_string(label)
- f.append_string("%%n")
- if not tip.is_empty then
- f.append_string("{")
- f.append_string(tip)
- f.append_string("}")
- end
- f.append_string("%N")
- pd.force(def, i)
- i := i + 1
- end
- add_widget_parameter (label: STRING; wgt: IUP_WIDGET)
- -- Add a widget that will be managed by the application, it will be
- -- placed after the parameters and before the buttons
- do
- f.append_string(label)
- f.append_string("%%h")
- f.append_string("%N")
- pd.force(wgt.widget, i)
- i := i + 1
- end
- add_buttons_parameter (titles: STRING)
- -- Buttons titles. Allow to redefine the default button titles (OK and
- -- Cancel), and to add a third button. Use "button1,button2,button3".
- -- Can omit one of them, it will use the default name.
- do
- f.append_string("Bt %%u")
- f.append_string("[")
- f.append_string(titles)
- f.append_string("]")
- f.append_string("%N")
- pe := pe + 1
- end
- -- Attributes
- set_precision (decimals: INTEGER)
- -- The default number of decimal places used in floating point output by
- -- some controls.
- --
- -- The default precision for real value display is given by the global
- -- attribute DEFAULTPRECISION. But inside the callback the application
- -- can use this feature to use another value. It will work only during
- -- interactive changes. The decimal symbol will used the
- -- DEFAULTDECIMALSYMBOL global attribute. Local attributes may overwrite
- -- the default. Default: 2.
- require
- decimals >= 0
- do
- iup_open.set_attribute (Current, "PRECISION", decimals.out)
- end
- get_button (number: INTEGER): IUP_BUTTON
- -- Returns the button 1, 2 or 3 (if any).
- require
- number >= 1
- number <= 3
- local
- p: POINTER
- b: IUP_BUTTON
- do
- if number.is_equal(1) then
- p := iup_open.get_attribute_ihandle(Current, "BUTTON1")
- elseif number.is_equal(2) then
- p := iup_open.get_attribute_ihandle(Current, "BUTTON2")
- elseif number.is_equal(3) then
- p := iup_open.get_attribute_ihandle(Current, "BUTTON3")
- end
- create b.button_widget(p)
- Result := b
- end
- --get_parameter_label_at (number: INTEGER): IUP_LABEL
- -- local
- -- str: STRING
- -- a_label: IUP_LABEL
- -- p1, p2: POINTER
- -- do
- -- str := "PARAM"
- -- str.append_string(number.out)
- -- p1 := iup_open.get_attribute_ihandle(Current, str)
- -- p2 := iup_open.get_attribute_ihandle_from_handle(p1, str)
- --
- -- create a_label.label_widget(p2)
- -- Result := a_label
- -- end
- get_parameter_value_at (index: INTEGER): STRING
- -- Get the value, as string, that the user writes in the parameter at
- -- provided index.
- local
- p: POINTER
- str: STRING
- do
- str := "PARAM"
- str.append_string(index.out)
- p := iup_open.get_attribute_ihandle(Current, str)
- if p /= default_pointer then
- Result := iup_open.get_attribute_from_handle(p, "VALUE")
- else
- Result := ""
- end
- end
- set_parameter_value_at (value: STRING; index: INTEGER)
- -- Set the value, passed as string, in the parameter at provided index.
- -- This set the value at the control and at the auxiliary
- -- control (if any).
- local
- str: STRING
- p1, p2: POINTER
- do
- str := "PARAM"
- str.append_string(index.out)
- p1 := iup_open.get_attribute_ihandle(Current, str)
- if p1 /= default_pointer then
- iup_open.set_attribute_in_handle(p1, "VALUE", value)
- end
- p2 := iup_open.get_attribute_ihandle_from_handle(p1, "AUXCONTROL")
- if p2 /= default_pointer then
- iup_open.set_attribute_in_handle(p2, "VALUE", value)
- end
- end
- set_parameter_visible_columns_at (value, index: INTEGER)
- -- Set the visible columns in string parameters (those
- -- added with "add_string_parameter").
- local
- str: STRING
- p: POINTER
- do
- str := "PARAM"
- str.append_string(index.out)
- p := iup_open.get_attribute_ihandle(Current, str)
- if p /= default_pointer then
- iup_open.set_attribute_in_handle(p, "VISIBLECOLUMNS",
- value.out)
- end
- end
- get_spinning: INTEGER
- -- A integer parameter always has a spin attached to the text to
- -- increment and decrement the value. A real parameter only has a spin in
- -- a full interval is defined (min and max), in this case the default
- -- step is (max-min)/20. When the callback is called because a spin was
- -- activated then this feature return a non zero value.
- local
- str: STRING
- do
- str := iup_open.get_attribute (Current, "SPINNING")
- if str /= Void then
- if str.is_integer then
- Result := str.to_integer
- end
- end
- end
- feature {IUP}
- execute_param (handle: POINTER; param_index: INTEGER; user_data: POINTER): INTEGER
- do
- if attached cb_param as int_cb then
- widget := handle
- Result := int_cb.item([Current, param_index, user_data])
- else
- Result := 0
- end
- end
- feature {NONE}
- cb_param: detachable FUNCTION[TUPLE[IUP_GET_PARAM, INTEGER, POINTER], INTEGER]
- t, f: STRING
- ud: POINTER
- pe: INTEGER
- i: INTEGER
- -- Internals
- int_get_param (title, user_data, format: POINTER; param_count, param_extra: INTEGER; param_data: POINTER): INTEGER
- external
- "C inline use %"eiffel-iup.h%""
- alias
- "return get_param_dialog ($title, $user_data, $format, $param_count, $param_extra, $param_data);"
- end
- end -- end class
- -- The MIT License (MIT)
- -- Copyright (c) 2016, 2017, 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.
|