source: trunk/design/ui/source/wui-widgets-combo_boxes.adb

Last change on this file was 5761, checked in by vadim.godunko, 3 years ago

Add getter/setter for Current_Index.

  • Property svn:keywords set to Author Date Revision
File size: 7.1 KB
Line 
1------------------------------------------------------------------------------
2-- --
3-- Matreshka Project --
4-- --
5-- Web Framework --
6-- --
7-- Runtime Library Component --
8-- --
9------------------------------------------------------------------------------
10-- --
11-- Copyright © 2017, Vadim Godunko <vgodunko@gmail.com> --
12-- All rights reserved. --
13-- --
14-- Redistribution and use in source and binary forms, with or without --
15-- modification, are permitted provided that the following conditions --
16-- are met: --
17-- --
18-- * Redistributions of source code must retain the above copyright --
19-- notice, this list of conditions and the following disclaimer. --
20-- --
21-- * Redistributions in binary form must reproduce the above copyright --
22-- notice, this list of conditions and the following disclaimer in the --
23-- documentation and/or other materials provided with the distribution. --
24-- --
25-- * Neither the name of the Vadim Godunko, IE nor the names of its --
26-- contributors may be used to endorse or promote products derived from --
27-- this software without specific prior written permission. --
28-- --
29-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
30-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
31-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
32-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
33-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
34-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
35-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
36-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
37-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
38-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
39-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
40-- --
41------------------------------------------------------------------------------
42-- $Revision: 5761 $ $Date: 2017-05-20 08:06:31 +0000 (Sat, 20 May 2017) $
43------------------------------------------------------------------------------
44with WebAPI.HTML.Globals;
45
46package body WUI.Widgets.Combo_Boxes is
47
48 ------------------
49 -- Constructors --
50 ------------------
51
52 package body Constructors is
53
54 type Combo_Box_Internal_Access is access all Combo_Box'Class;
55
56 ------------
57 -- Create --
58 ------------
59
60 function Create
61 (Element :
62 not null WebAPI.HTML.Select_Elements.HTML_Select_Element_Access)
63 return not null Combo_Box_Access
64 is
65 Result : constant not null Combo_Box_Internal_Access
66 := new Combo_Box;
67
68 begin
69 Initialize (Result.all, Element);
70
71 return Combo_Box_Access (Result);
72 end Create;
73
74 ------------
75 -- Create --
76 ------------
77
78 function Create
79 (Id : League.Strings.Universal_String)
80 return not null Combo_Box_Access is
81 begin
82 return
83 Create
84 (WebAPI.HTML.Select_Elements.HTML_Select_Element_Access
85 (WebAPI.HTML.Globals.Window.Get_Document.Get_Element_By_Id
86 (Id)));
87 end Create;
88
89 ----------------
90 -- Initialize --
91 ----------------
92
93 procedure Initialize
94 (Self : in out Combo_Box'Class;
95 Element :
96 not null WebAPI.HTML.Select_Elements.HTML_Select_Element_Access) is
97 begin
98 WUI.Widgets.Constructors.Initialize
99 (Self,
100 WebAPI.HTML.Elements.HTML_Element_Access (Element));
101 end Initialize;
102
103 end Constructors;
104
105 -------------------
106 -- Current_Index --
107 -------------------
108
109 function Current_Index
110 (Self : in out Combo_Box'Class)
111 return League.Strings.Universal_String
112 is
113 Input : constant WebAPI.HTML.Select_Elements.HTML_Select_Element_Access
114 := WebAPI.HTML.Select_Elements.HTML_Select_Element_Access
115 (Self.Element);
116
117 begin
118 return Input.Get_Value;
119 end Current_Index;
120
121 ----------------------------------
122 -- Current_Index_Changed_Signal --
123 ----------------------------------
124
125 not overriding function Current_Index_Changed_Signal
126 (Self : in out Combo_Box)
127 return not null access WUI.String_Slots.Signal'Class is
128 begin
129 return Self.Current_Index_Changed'Unchecked_Access;
130 end Current_Index_Changed_Signal;
131
132 -----------------
133 -- Input_Event --
134 -----------------
135
136 overriding procedure Input_Event (Self : in out Combo_Box) is
137 Input : constant WebAPI.HTML.Select_Elements.HTML_Select_Element_Access
138 := WebAPI.HTML.Select_Elements.HTML_Select_Element_Access
139 (Self.Element);
140
141 begin
142 Self.Current_Index_Changed.Emit (Input.Get_Value);
143 end Input_Event;
144
145 -----------------------
146 -- Set_Current_Index --
147 -----------------------
148
149 not overriding procedure Set_Current_Index
150 (Self : in out Combo_Box;
151 To : League.Strings.Universal_String)
152 is
153 use type League.Strings.Universal_String;
154
155 Input : constant WebAPI.HTML.Select_Elements.HTML_Select_Element_Access
156 := WebAPI.HTML.Select_Elements.HTML_Select_Element_Access
157 (Self.Element);
158
159 begin
160 if Input.Get_Value /= To then
161 Input.Set_Value (To);
162 Self.Current_Index_Changed.Emit (Input.Get_Value);
163 -- 'input' event is not send when value is updated programmatically.
164 end if;
165 end Set_Current_Index;
166
167 ------------------
168 -- Set_Disabled --
169 ------------------
170
171 not overriding procedure Set_Disabled
172 (Self : in out Combo_Box;
173 Disabled : Boolean) is
174 begin
175 WebAPI.HTML.Select_Elements.HTML_Select_Element_Access
176 (Self.Element).Set_Disabled (Disabled);
177 end Set_Disabled;
178
179 -----------------
180 -- Set_Enabled --
181 -----------------
182
183 not overriding procedure Set_Enabled
184 (Self : in out Combo_Box;
185 Enabled : Boolean) is
186 begin
187 Self.Set_Disabled (not Enabled);
188 end Set_Enabled;
189
190end WUI.Widgets.Combo_Boxes;
Note: See TracBrowser for help on using the repository browser.