123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478 |
- class IUP_LABEL
- -- Creates a label interface element, which displays a separator, a text or an
- -- image. Labels with images, texts or line separator can not change its
- -- behavior after mapped. But after map the image can be changed for another
- -- image, and the text for another text.
- inherit
- IUP_WIDGET
- undefine
- execute_dragbegin,
- execute_dragdatasize,
- execute_dragdata,
- execute_dragend,
- execute_dropdata,
- execute_dropmotion
- redefine
- execute_map,
- execute_unmap,
- execute_destroy,
- execute_enterwindow,
- execute_leavewindow,
- execute_button,
- execute_motion,
- execute_dropfiles
- end
- IUP_WIDGET_ACTIVE
- IUP_WIDGET_BGCOLOR
- IUP_WIDGET_FGCOLOR
- IUP_WIDGET_TITLE
- IUP_WIDGET_FONT
- IUP_WIDGET_EXPAND
- IUP_WIDGET_SCREENPOSITION
- IUP_WIDGET_POSITION
- IUP_WIDGET_MAXMIN_SIZE
- IUP_WIDGET_TIP
- IUP_WIDGET_SIZE
- IUP_WIDGET_RASTERSIZE
- IUP_WIDGET_USERSIZE
- IUP_WIDGET_ZORDER
- IUP_WIDGET_VISIBLE
- IUP_WIDGET_CHILD
- IUP_WIDGET_NAME
- IUP_DRAG_AND_DROP
- IUP_WIDGET_CUSTOM_ATTRIBUTES
- IUP_WIDGET_PADDING
- create {ANY}
- label_empty,
- label
- feature {ANY}
- label_empty
- -- A new empty label.
- local
- a_label, p: POINTER
- do
- a_label := int_label (p)
- set_widget(a_label)
- end
-
- label (text: STRING)
- -- A new label with the provided text
- local
- a_label: POINTER
- do
- a_label := int_label (get_pointer(text.to_c))
- set_widget(a_label)
- end
- -- Attributes
- set_alignment (horizontal, vertical: STRING)
- -- (non inheritable): horizontal and vertical alignment. Possible values:
- -- "ALEFT", "ACENTER" and "ARIGHT", combined to "ATOP", "ACENTER" and
- -- "ABOTTOM". Default: "ALEFT:ACENTER". In Motif, vertical alignment is
- -- restricted to "ACENTER".
- require
- is_valid_alignment(horizontal, vertical)
- local
- str: STRING
- do
- create str.make_from_string(horizontal)
- str.append_string(":")
- str.append_string(vertical)
-
- iup_open.set_attribute(Current, "ALIGNMENT", str)
- end
- set_as_drop_files_target (state: BOOLEAN)
- -- [Windows and GTK Only] (non inheritable): Enable or disable the drop
- -- of files. Default: False, but if DROPFILES_CB is defined when the
- -- element is mapped then it will be automatically enabled.
- do
- iup_open.set_attribute(Current, "DROPFILESTARGET", boolean_to_yesno(state))
- end
- set_ellipsis (state: BOOLEAN)
- -- [Windows and GTK only]: add an ellipsis: "..." to the text if there
- -- is not enough space to render the entire string. Can be "YES" or "NO".
- -- Default: "False".
- do
- iup_open.set_attribute(Current, "ELLIPSIS", boolean_to_yesno(state))
- end
- set_image (name: STRING)
- -- (non inheritable): Image name. If set before map defines the behavior
- -- of the button to contain an image. The natural size will be size of
- -- the image in pixels. Use set_widget_name to associate an image to
- -- a name. See also IUP_IMAGE.
- do
- iup_open.set_attribute(Current, "IMAGE", name)
- end
- set_image_inactive (name: STRING)
- -- (non inheritable) [GTK and Motif only]: Image name of the element when
- -- inactive. If it is not defined then the IMAGE is used and the colors
- -- will be replaced by a modified version of the background color
- -- creating the disabled effect. GTK will also change the inactive image
- -- to look like other inactive objects.
- do
- iup_open.set_attribute(Current, "IMINACTIVE", name)
- end
- set_markup (state: BOOLEAN)
- -- [GTK only]: allows the title string to contains pango markup
- -- commands. Works only if a mnemonic is NOT defined in the title. Can
- -- be "True" or "False". Default: "False".
- do
- iup_open.set_attribute(Current, "MARKUP", boolean_to_yesno(state))
- end
- set_horizontal_separator
- -- (creation only) (non inheritable): Turns the label into a horizontal
- -- line separator. When changed before mapping the EXPAND attribute is
- -- set to "HORIZONTALFREE". (Since 3.11 changed to FREE based expand)
- do
- iup_open.set_attribute(Current, "SEPARATOR", "HORIZONTAL")
- end
- set_vertical_separator
- -- (creation only) (non inheritable): Turns the label into a vertical line
- -- separator. When changed before mapping the EXPAND attribute is set to
- -- "VERTICALFREE" accordingly. (Since 3.11 changed to FREE based expand)
- do
- iup_open.set_attribute(Current, "SEPARATOR", "VERTICAL")
- end
- set_word_wrap (state: BOOLEAN)
- -- [Windows and GTK only]: enables or disable the wrapping of lines that
- -- does not fits in the label. Can be "YES" or "NO". Default: "NO". Can
- -- only set WORDWRAP=YES if ALIGNMENT=ALEFT.
- do
- iup_open.set_attribute(Current, "WORDWRAP", boolean_to_yesno(state))
- end
- -- Validations
- is_valid_alignment (horizontal, vertical: STRING): BOOLEAN
- local
- h, v: BOOLEAN
- do
- if horizontal.is_equal("ALEFT") or
- horizontal.is_equal("ACENTER") or
- horizontal.is_equal("ARIGHT") then
- h := True
- else
- h := False
- end
- if vertical.is_equal("ATOP") or
- vertical.is_equal("ACENTER") or
- vertical.is_equal("ABOTTOM") then
- v := True
- else
- v := False
- end
- if h and v then
- Result := True
- else
- Result := False
- end
- end
- -- Callbacks
- -- Common
- set_cb_map (act: detachable FUNCTION[TUPLE[IUP_LABEL], STRING])
- -- Called right after an element is mapped and its attributes updated.
- local
- operation: INTEGER
- do
- cb_map := act
-
- if cb_map /= Void then
- operation := 1
- else
- operation := 0
- end
-
- iup_open.set_callback (Current, "MAP_CB", "NONEEDED", operation)
- end
- set_cb_unmap (act: detachable FUNCTION[TUPLE[IUP_LABEL], STRING])
- -- Called right before an element is unmapped.
- local
- operation: INTEGER
- do
- cb_unmap := act
- if cb_unmap /= Void then
- operation := 1
- else
- operation := 0
- end
-
- iup_open.set_callback (Current, "UNMAP_CB", "NONEEDED", operation)
- end
- set_cb_destroy (act: detachable FUNCTION[TUPLE[IUP_LABEL], STRING])
- -- Called right before an element is destroyed.
- local
- operation: INTEGER
- do
- cb_destroy := act
- if cb_destroy /= Void then
- operation := 1
- else
- operation := 0
- end
-
- iup_open.set_callback (Current, "DESTROY_CB", "NONEEDED", operation)
- end
- set_cb_enter_window (act: detachable FUNCTION[TUPLE[IUP_LABEL], STRING])
- -- Action generated when the mouse enters the native element.
- local
- operation: INTEGER
- do
- cb_enterwindow := act
- if cb_enterwindow /= Void then
- operation := 1
- else
- operation := 0
- end
-
- iup_open.set_callback (Current, "ENTERWINDOW_CB", "NONEEDED", operation)
- end
- set_cb_leave_window (act: detachable FUNCTION[TUPLE[IUP_LABEL], STRING])
- -- Action generated when the mouse leaves the native element.
- local
- operation: INTEGER
- do
- cb_leavewindow := act
- if cb_leavewindow /= Void then
- operation := 1
- else
- operation := 0
- end
-
- iup_open.set_callback (Current, "LEAVEWINDOW_CB", "NONEEDED", operation)
- end
- -- Extra
- set_cb_button (act: detachable FUNCTION[TUPLE[IUP_LABEL, INTEGER, INTEGER, INTEGER, INTEGER, STRING], STRING])
- -- Action generated when any mouse button is pressed and when it is
- -- released. Both calls occur before the ACTION callback when button 1 is
- -- being used.
- --
- -- IUP_BUTTON: identifies the element that activated the event.
- -- button: identifies the activated mouse button:
- --
- -- 1 - left mouse button (button 1);
- -- 2 - middle mouse button (button 2);
- -- 3 - right mouse button (button 3).
- --
- -- pressed: indicates the state of the button:
- --
- -- 0 - mouse button was released;
- -- 1 - mouse button was pressed.
- --
- -- x, y: position in the canvas where the event has occurred, in pixels.
- --
- -- status: status of the mouse buttons and some keyboard keys at the
- -- moment the event is generated. The following IUP features must be used
- -- for verification:
- --
- -- is_shift(status)
- -- is_control(status)
- -- is_button_1(status)
- -- is_button_2(status)
- -- is_button_3(status)
- -- is_button_4(status)
- -- is_button_5(status)
- -- is_double(status)
- -- is_alt(status)
- -- is_sys(status)
- --
- -- Returns: IUP_CLOSE will be processed. On some controls if IUP_IGNORE
- -- is returned the action is ignored (this is system dependent).
- local
- operation: INTEGER
- do
- cb_button := act
- if cb_button /= Void then
- operation := 1
- else
- operation := 0
- end
-
- iup_open.set_callback (Current, "BUTTON_CB", "NONEEDED", operation)
- end
- set_cb_motion (act: detachable FUNCTION[TUPLE[IUP_LABEL, INTEGER, INTEGER, STRING], STRING])
- -- Action generated when the mouse moves.
- -- ih: identifier of the element that activated the event.
- -- x, y: position in the canvas where the event has occurred, in pixels.
- -- status: status of mouse buttons and certain keyboard keys at the
- -- moment the event was generated. The same macros used for BUTTON_CB can
- -- be used for this status.
- local
- operation: INTEGER
- do
- cb_motion := act
- if cb_motion /= Void then
- operation := 1
- else
- operation := 0
- end
-
- iup_open.set_callback (Current, "MOTION_CB", "NONEEDED", operation)
- end
- set_cb_drop_files (act: detachable FUNCTION[TUPLE[IUP_LABEL, STRING, INTEGER, INTEGER, INTEGER], STRING])
- local
- operation: INTEGER
- do
- cb_dropfiles := act
- if cb_dropfiles /= Void then
- operation := 1
- else
- operation := 0
- end
-
- iup_open.set_callback (Current, "DROPFILES_CB", "NONEEDED", operation)
- end
- feature {IUP}
- execute_map: STRING
- do
- if attached cb_map as int_cb then
- Result := int_cb.item([Current])
- else
- Result := "IUP_DEFAULT"
- end
- end
- execute_unmap: STRING
- do
- if attached cb_unmap as int_cb then
- Result := int_cb.item([Current])
- else
- Result := "IUP_DEFAULT"
- end
- end
- execute_destroy: STRING
- do
- if attached cb_destroy as int_cb then
- Result := int_cb.item([Current])
- else
- Result := "IUP_DEFAULT"
- end
- end
- execute_enterwindow: STRING
- do
- if attached cb_enterwindow as int_cb then
- Result := int_cb.item([Current])
- else
- Result := "IUP_DEFAULT"
- end
- end
- execute_leavewindow: STRING
- do
- if attached cb_leavewindow as int_cb then
- Result := int_cb.item([Current])
- else
- Result := "IUP_DEFAULT"
- end
- end
- execute_button (btn, pressed, x, y: INTEGER; status: STRING): STRING
- do
- if attached cb_button as int_cb then
- Result := int_cb.item([Current, btn, pressed, x, y, status])
- else
- Result := "IUP_DEFAULT"
- end
- end
- execute_motion (x, y: INTEGER; status: STRING): STRING
- do
- if attached cb_motion as int_cb then
- Result := int_cb.item([Current, x, y, status])
- else
- Result := "IUP_DEFAULT"
- end
- end
- execute_dropfiles (filename: STRING; num: INTEGER; x: INTEGER; y: INTEGER): STRING
- do
- if attached cb_dropfiles as int_cb then
- Result := int_cb.item([Current, filename, num, x, y])
- else
- Result := "IUP_DEFAULT"
- end
- end
-
-
- feature {NONE}
- -- For callbacks
-
- cb_map: detachable FUNCTION[TUPLE[IUP_LABEL], STRING]
- cb_unmap: detachable FUNCTION[TUPLE[IUP_LABEL], STRING]
- cb_destroy: detachable FUNCTION[TUPLE[IUP_LABEL], STRING]
- cb_enterwindow: detachable FUNCTION[TUPLE[IUP_LABEL], STRING]
- cb_leavewindow: detachable FUNCTION[TUPLE[IUP_LABEL], STRING]
- cb_button: detachable FUNCTION[TUPLE[IUP_LABEL, INTEGER, INTEGER, INTEGER, INTEGER, STRING], STRING]
- cb_motion: detachable FUNCTION[TUPLE[IUP_LABEL, INTEGER, INTEGER, STRING], STRING]
- cb_dropfiles: detachable FUNCTION[TUPLE[IUP_LABEL, STRING, INTEGER, INTEGER, INTEGER], STRING]
- -- Internals
-
- int_label (text: POINTER): POINTER
- external
- "C inline use %"eiffel-iup.h%""
- alias
- "return IupLabel ($text);"
- end
-
- end -- class IUP_LABEL
- -- The MIT License (MIT)
- -- Copyright (c) 2016, 2017, 2018, 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.
|