Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
widgeteventhandler.c
Go to the documentation of this file.
2 {
3  private ref static WidgetEventHandler s_instance;
4 
5  protected ref map<Widget, ref Param> m_OnMouseButtonDownRegister;
6  protected ref map<Widget, ref Param> m_OnMouseButtonUpRegister;
7  protected ref map<Widget, ref Param> m_OnMouseWheel;
8  protected ref map<Widget, ref Param> m_OnDropReceived;
9  protected ref map<Widget, ref Param> m_OnDrag;
10  protected ref map<Widget, ref Param> m_OnDrop;
11  protected ref map<Widget, ref Param> m_OnDraggingOver;
12  protected ref map<Widget, ref Param> m_OnMouseEnter;
13  protected ref map<Widget, ref Param> m_OnMouseButtonLeave;
14  protected ref map<Widget, ref Param> m_OnClick;
15  protected ref map<Widget, ref Param> m_OnDoubleClick;
16  protected ref map<Widget, ref Param> m_OnFocus;
17  protected ref map<Widget, ref Param> m_OnFocusLost;
18  protected ref map<Widget, ref Param> m_OnController;
19  protected ref map<Widget, ref Param> m_OnChildAdd;
20  protected ref map<Widget, ref Param> m_OnChildRemove;
21 
22  static WidgetEventHandler GetInstance()
23  {
24  return s_instance;
25  }
26 
27  void WidgetEventHandler()
28  {
29  s_instance = this;
30  m_OnMouseButtonDownRegister = new map<Widget, ref Param>;
31  m_OnMouseButtonUpRegister = new map<Widget, ref Param>;
32  m_OnMouseWheel = new map<Widget, ref Param>;
33  m_OnDropReceived = new map<Widget, ref Param>;
34  m_OnDrag = new map<Widget, ref Param>;
35  m_OnDrop = new map<Widget, ref Param>;
36  m_OnDraggingOver = new map<Widget, ref Param>;
37  m_OnMouseEnter = new map<Widget, ref Param>;
38  m_OnMouseButtonLeave = new map<Widget, ref Param>;
39  m_OnClick = new map<Widget, ref Param>;
40  m_OnDoubleClick = new map<Widget, ref Param>;
41  m_OnFocus = new map<Widget, ref Param>;
42  m_OnFocusLost = new map<Widget, ref Param>;
43  m_OnController = new map<Widget, ref Param>;
44  m_OnChildAdd = new map<Widget, ref Param>;
45  m_OnChildRemove = new map<Widget, ref Param>;
46  }
47 
48  void UnregisterWidget( Widget w )
49  {
50  m_OnMouseButtonDownRegister.Remove( w );
51  m_OnMouseButtonUpRegister.Remove( w );
52  m_OnMouseWheel.Remove( w );
53  m_OnDropReceived.Remove( w );
54  m_OnDrag.Remove( w );
55  m_OnDrop.Remove( w );
56  m_OnDraggingOver.Remove( w );
57  m_OnMouseEnter.Remove( w );
58  m_OnMouseButtonLeave.Remove( w );
59  m_OnClick.Remove( w );
60  m_OnDoubleClick.Remove( w );
61  m_OnDoubleClick.Remove( w );
62  m_OnFocus.Remove( w );
63  m_OnFocusLost.Remove( w );
64  m_OnController.Remove( w );
65  m_OnChildAdd.Remove( w );
66  m_OnChildRemove.Remove( w );
67  w.SetHandler( NULL );
68  }
69 
70  void RegisterOnMouseButtonDown( Widget w, Managed eventHandler, string functionName )
71  {
72  w.SetHandler( this );
73  Param param = new Param2<Managed, string>( eventHandler, functionName );
74  m_OnMouseButtonDownRegister.Insert( w, param );
75  }
76 
77  void RegisterOnMouseButtonUp( Widget w, Managed eventHandler, string functionName )
78  {
79  w.SetHandler( this );
80  Param param = new Param2<Managed, string>( eventHandler, functionName );
81  m_OnMouseButtonUpRegister.Insert( w, param );
82  }
83 
84  void RegisterOnMouseWheel( Widget w, Managed eventHandler, string functionName )
85  {
86  w.SetHandler( this );
87  Param param = new Param2<Managed, string>( eventHandler, functionName );
88  m_OnMouseWheel.Insert( w, param );
89  }
90 
91  void RegisterOnDropReceived( Widget w, Managed eventHandler, string functionName )
92  {
93  w.SetHandler( this );
94  Param param = new Param2<Managed, string>( eventHandler, functionName );
95  m_OnDropReceived.Insert( w, param );
96  }
97 
98  void RegisterOnDrag( Widget w, Managed eventHandler, string functionName )
99  {
100  w.SetHandler( this );
101  Param param = new Param2<Managed, string>( eventHandler, functionName );
102  m_OnDrag.Insert( w, param );
103  }
104 
105  void RegisterOnDrop( Widget w, Managed eventHandler, string functionName )
106  {
107  w.SetHandler( this );
108  Param param = new Param2<Managed, string>( eventHandler, functionName );
109  m_OnDrop.Insert( w, param );
110  }
111 
112  void RegisterOnDraggingOver( Widget w, Managed eventHandler, string functionName )
113  {
114  w.SetHandler( this );
115  Param param = new Param2<Managed, string>( eventHandler, functionName );
116  m_OnDraggingOver.Insert( w, param );
117  }
118 
119  void RegisterOnMouseEnter(Widget w, Managed eventHandler, string functionName )
120  {
121  w.SetHandler( this );
122  Param param = new Param2<Managed, string>( eventHandler, functionName );
123  m_OnMouseEnter.Insert( w, param );
124  }
125 
126  void RegisterOnMouseLeave(Widget w, Managed eventHandler, string functionName )
127  {
128  w.SetHandler( this );
129  Param param = new Param2<Managed, string>( eventHandler, functionName );
130  m_OnMouseButtonLeave.Insert( w, param );
131  }
132 
133  void RegisterOnClick(Widget w, Managed eventHandler, string functionName )
134  {
135  w.SetHandler( this );
136  Param param = new Param2<Managed, string>( eventHandler, functionName );
137  m_OnClick.Insert( w, param );
138  }
139 
140  void RegisterOnDoubleClick(Widget w, Managed eventHandler, string functionName )
141  {
142  w.SetHandler( this );
143  Param param = new Param2<Managed, string>( eventHandler, functionName );
144  m_OnDoubleClick.Insert( w, param );
145  }
146 
147  void RegisterOnFocus(Widget w, Managed eventHandler, string functionName )
148  {
149  w.SetHandler( this );
150  Param param = new Param2<Managed, string>( eventHandler, functionName );
151  m_OnFocus.Insert( w, param );
152  }
153  void RegisterOnFocusLost(Widget w, Managed eventHandler, string functionName )
154  {
155  w.SetHandler( this );
156  Param param = new Param2<Managed, string>( eventHandler, functionName );
157  m_OnFocusLost.Insert( w, param );
158  }
159 
160  void RegisterOnChildAdd(Widget w, Managed eventHandler, string functionName )
161  {
162  w.SetHandler( this );
163  Param param = new Param2<Managed, string>( eventHandler, functionName );
164  m_OnChildAdd.Insert( w, param );
165  }
166 
167  void RegisterOnChildRemove(Widget w, Managed eventHandler, string functionName )
168  {
169  w.SetHandler( this );
170  Param param = new Param2<Managed, string>( eventHandler, functionName );
171  m_OnChildRemove.Insert( w, param );
172  }
173 
174  override bool OnClick(Widget w, int x, int y, int button)
175  {
176  Param2<Managed, string> param = Param2<Managed, string>.Cast( m_OnClick.Get( w ) );
177  if( param == NULL )
178  {
179  return false;
180  }
181 
182  if( !param.param1 )
183  {
184  m_OnClick.Remove( w );
185  }
186 
187  Param param2 = new Param4<Widget, int, int, int>( w, x, y, button );
188  GetGame().GameScript.CallFunctionParams( param.param1, param.param2, NULL, param2 );
189 
190  return true;
191  }
192 
193  override bool OnDoubleClick(Widget w, int x, int y, int button)
194  {
195  Param2<Managed, string> param = Param2<Managed, string>.Cast( m_OnDoubleClick.Get( w ) );
196  if( param == NULL )
197  {
198  return false;
199  }
200 
201  if( !param.param1 )
202  {
203  m_OnDoubleClick.Remove( w );
204  }
205 
206  Param param2 = new Param4<Widget, int, int, int>( w, x, y, button );
207  GetGame().GameScript.CallFunctionParams( param.param1, param.param2, NULL, param2 );
208 
209  return true;
210  }
211 
212  override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
213  {
214  Param2<Managed, string> param = Param2<Managed, string>.Cast( m_OnMouseButtonLeave.Get( w ) );
215  if( param == NULL )
216  {
217  return false;
218  }
219 
220  if( !param.param1 )
221  {
222  m_OnMouseButtonLeave.Remove( w );
223  }
224 
225  Param param2 = new Param4<Widget, Widget, int, int>( w, enterW, x, y );
226  GetGame().GameScript.CallFunctionParams( param.param1, param.param2, NULL, param2 );
227 
228  return true;
229  }
230 
231  override bool OnMouseEnter( Widget w, int x, int y )
232  {
233  Param2<Managed, string> param = Param2<Managed, string>.Cast( m_OnMouseEnter.Get( w ) );
234  if( param == NULL )
235  {
236  return false;
237  }
238 
239  if( !param.param1 )
240  {
241  m_OnMouseEnter.Remove( w );
242  }
243 
244  Param param2 = new Param3<Widget, int, int>( w, x, y );
245  GetGame().GameScript.CallFunctionParams( param.param1, param.param2, NULL, param2 );
246 
247  return true;
248  }
249 
250  override bool OnMouseButtonDown( Widget w, int x, int y, int button )
251  {
252  Param2<Managed, string> param = Param2<Managed, string>.Cast( m_OnMouseButtonDownRegister.Get( w ) );
253  if( param == NULL )
254  {
255  return false;
256  }
257 
258  if( !param.param1 )
259  {
260  m_OnMouseButtonDownRegister.Remove( w );
261  }
262 
263  Param param2 = new Param4<Widget, int, int, int>( w, x, y, button );
264  GetGame().GameScript.CallFunctionParams( param.param1, param.param2, NULL, param2 );
265 
266  return true;
267  }
268 
269  override bool OnMouseButtonUp( Widget w, int x, int y, int button )
270  {
271  Param2<Managed, string> param = Param2<Managed, string>.Cast( m_OnMouseButtonUpRegister.Get( w ) );
272  if( param == NULL )
273  {
274  return false;
275  }
276 
277  if( !param.param1 )
278  {
279  m_OnMouseButtonUpRegister.Remove( w );
280  }
281 
282  Param param2 = new Param4<Widget, int, int, int>( w, x, y, button );
283  GetGame().GameScript.CallFunctionParams( param.param1, param.param2, NULL, param2 );
284 
285  return true;
286  }
287 
288  override bool OnDrag(Widget w, int x, int y)
289  {
290  Param2<Managed, string> param = Param2<Managed, string>.Cast( m_OnDrag.Get( w ) );
291  if( param == NULL )
292  {
293  return false;
294  }
295 
296  if( !param.param1 )
297  {
298  m_OnDrag.Remove( w );
299  }
300 
301  Param param2 = new Param3<Widget, int, int>( w, x, y );
302  GetGame().GameScript.CallFunctionParams( param.param1, param.param2, NULL, param2 );
303 
304  return true;
305  }
306 
307  override bool OnDrop(Widget w, int x, int y, Widget reciever)
308  {
309  Param2<Managed, string> param = Param2<Managed, string>.Cast( m_OnDrop.Get( w ) );
310  if( param == NULL )
311  {
312  return false;
313  }
314 
315  if( !param.param1 )
316  {
317  m_OnDrop.Remove( w );
318  }
319 
320  Param param2 = new Param3<Widget, int, int>( w, x, y );
321  GetGame().GameScript.CallFunctionParams( param.param1, param.param2, NULL, param2 );
322 
323  return true;
324  }
325 
326  override bool OnDraggingOver(Widget w, int x, int y, Widget reciever)
327  {
328  Param2<Managed, string> param = Param2<Managed, string>.Cast( m_OnDraggingOver.Get( reciever ) );
329  if( param == NULL )
330  {
331  return false;
332  }
333 
334  if( !param.param1 )
335  {
336  m_OnDraggingOver.Remove( w );
337  }
338 
339  Param param2 = new Param4<Widget, int, int, Widget>( w, x, y, reciever );
340  GetGame().GameScript.CallFunctionParams( param.param1, param.param2, NULL, param2 );
341 
342  return true;
343  }
344 
345  override bool OnDropReceived( Widget w, int x, int y, Widget reciever )
346  {
347  if( w.GetName() == "GridItem" )
348  {
349  return false;
350  }
351  Param p = m_OnDropReceived.Get( reciever );
353  if( param == NULL )
354  {
355  return false;
356  }
357 
358  if( !param.param1 )
359  {
360  m_OnDropReceived.Remove( w );
361  }
362 
363  Param param2 = new Param4<Widget, int, int, Widget>( w, x, y, reciever );
364  GetGame().GameScript.CallFunctionParams( param.param1, param.param2, NULL, param2 );
365 
366  return true;
367  }
368 
369  override bool OnFocus( Widget w, int x, int y )
370  {
371  Param2<Managed, string> param = Param2<Managed, string>.Cast( m_OnFocus.Get( w ) );
372  if( param == NULL )
373  {
374  return false;
375  }
376 
377  if( !param.param1 )
378  {
379  m_OnFocus.Remove( w );
380  }
381 
382  Param param2 = new Param3<Widget, int, int>( w, x, y );
383  GetGame().GameScript.CallFunctionParams( param.param1, param.param2, NULL, param2 );
384 
385  return true;
386  }
387 
388  override bool OnFocusLost( Widget w, int x, int y )
389  {
390  Param2<Managed, string> param = Param2<Managed, string>.Cast( m_OnFocusLost.Get( w ) );
391  if( param == NULL )
392  {
393  return false;
394  }
395 
396  if( !param.param1 )
397  {
398  m_OnFocusLost.Remove( w );
399  }
400 
401  Param param2 = new Param3<Widget, int, int>( w, x, y );
402  GetGame().GameScript.CallFunctionParams( param.param1, param.param2, NULL, param2 );
403 
404  return true;
405  }
406 
407  override bool OnMouseWheel(Widget w, int x, int y, int wheel)
408  {
409  Param2<Managed, string> param = Param2<Managed, string>.Cast( m_OnMouseWheel.Get( w ) );
410  if( param == NULL )
411  {
412  return false;
413  }
414 
415  if( !param.param1 )
416  {
417  m_OnMouseWheel.Remove( w );
418  }
419 
420  Param param2 = new Param4<Widget, int, int, int>( w, x, y, wheel );
421  GetGame().GameScript.CallFunctionParams( param.param1, param.param2, NULL, param2 );
422 
423  return true;
424  }
425 
426  override bool OnChildAdd( Widget w, Widget child )
427  {
428  Param2<Managed, string> param = Param2<Managed, string>.Cast( m_OnChildAdd.Get( w ) );
429  if( param == NULL )
430  {
431  return false;
432  }
433 
434  if( !param.param1 )
435  {
436  m_OnChildAdd.Remove( w );
437  }
438 
439  Param param2 = new Param2<Widget, Widget>( w, child );
440  GetGame().GameScript.CallFunctionParams( param.param1, param.param2, NULL, param2 );
441 
442  return true;
443  }
444 
445  override bool OnChildRemove( Widget w, Widget child )
446  {
447  Param2<Managed, string> param = Param2<Managed, string>.Cast( m_OnChildRemove.Get( w ) );
448  if( param == NULL )
449  {
450  return false;
451  }
452 
453  if( !param.param1 )
454  {
455  m_OnChildRemove.Remove( w );
456  }
457 
458  Param param2 = new Param2<Widget, Widget>( w, child );
459  GetGame().GameScript.CallFunctionParams( param.param1, param.param2, NULL, param2 );
460 
461  return true;
462  }
463 }
Param2
Definition: ppeconstants.c:66
GetGame
proto native CGame GetGame()
Param
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Definition: param.c:11
y
Icon y
Managed
TODO doc.
Definition: enscript.c:117
Param3
Definition: entityai.c:95
map
map
Definition: controlsxboxnew.c:3
x
Icon x
Widget
Definition: enwidgets.c:189
ScriptedWidgetEventHandler
map: item x vector(index, width, height)
Definition: enwidgets.c:650
WidgetEventHandler
Definition: widgeteventhandler.c:1