1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010-2018 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
6 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as
10 // published by the Free Software Foundation, either version 3 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "nel/gui/ctrl_base_button.h"
24 #include "nel/misc/xml_auto_ptr.h"
25 #include "nel/gui/interface_group.h"
26 #include "nel/gui/lua_ihm.h"
27 #include "nel/gui/widget_manager.h"
28 #include "nel/gui/db_manager.h"
32 using namespace NLMISC
;
40 const uint KEY_REPEAT_MIN
= 100;
41 const uint KEY_REPEAT_MAX
= 750;
47 sint64
CCtrlBaseButton::_LastLeftClickDate
= 0;
48 NLMISC::CRefPtr
<CCtrlBaseButton
> CCtrlBaseButton::_LastLeftClickButton
;
51 // ***************************************************************************
52 CCtrlBaseButton::CCtrlBaseButton(const TCtorParam
¶m
) : CCtrlBase(param
), _Type(ToggleButton
)
54 _Pushed
= _Over
= false;
56 _FrozenHalfTone
= true;
57 _OverWhenPushed
= true;
58 _ColorOver
= _ColorPushed
= _ColorNormal
= NLMISC::CRGBA(255,255,255,255);
59 _ModulateGlobalColorNormal
= _ModulateGlobalColorPushed
= _ModulateGlobalColorOver
= true;
60 _LeftLongClickHandled
= true;
61 _LeftDblClickHandled
= false;
62 _ClickWhenPushed
= false;
67 _AHOnLeftClick
= NULL
;
68 _AHOnRightClick
= NULL
;
69 _AHOnClockTick
= NULL
;
70 _AHOnLeftLongClick
= NULL
;
71 _AHOnLeftDblClick
= NULL
;
74 std::string
CCtrlBaseButton::getProperty( const std::string
&name
) const
76 if( name
== "button_type" )
78 return getTypeString();
81 if( name
== "pushed" )
83 return toString( _Pushed
);
86 if( name
== "over_when_pushed" )
88 return toString( _OverWhenPushed
);
91 if( name
== "clicked_when_pushed" )
93 return toString( _ClickWhenPushed
);
98 return getColorAsString();
101 if( name
== "col_pushed" )
103 return getColorPushedAsString();
106 if( name
== "col_over" )
108 return getColorOverAsString();
111 if( name
== "global_color_normal" )
113 return toString( _ModulateGlobalColorNormal
);
116 if( name
== "global_color_pushed" )
118 return toString( _ModulateGlobalColorPushed
);
121 if( name
== "global_color_over" )
123 return toString( _ModulateGlobalColorOver
);
126 if( name
== "onover" )
128 return getAHString( "onover" );
131 if( name
== "params_over" )
133 return _getParamsOnOver();
136 if( name
== "onclick_l" )
138 return getAHString( "onclick_l" );
141 if( name
== "params_l" )
143 return _getParamsOnLeftClick();
146 if( name
== "ondblclick_l" )
148 return getAHString( "ondblclick_l" );
151 if( name
== "params_dblclick_l" )
153 return _AHLeftDblClickParams
.toString();
156 if( name
== "onlongclick_l" )
158 return getAHString( "onlongclick_l" );
161 if( name
== "params_longclick_l" )
163 return _AHLeftLongClickParams
.toString();
166 if( name
== "onclick_r" )
168 return getAHString( "onclick_r" );
171 if( name
== "params_r" )
173 return _AHRightClickParams
.toString();
176 if( name
== "onclock_tick" )
178 return getAHString( "onclock_tick" );
181 if( name
== "params_clock_tick" )
183 return _AHClockTickParams
.toString();
186 if( name
== "menu_l" )
188 return _ListMenuLeft
.toString();
191 if( name
== "menu_r" )
193 return _ListMenuRight
.toString();
196 if( name
== "menu_b" )
198 if( _ListMenuLeft
.toString() == _ListMenuRight
.toString() )
199 return _ListMenuLeft
.toString();
204 if( name
== "frozen" )
206 return toString( _Frozen
);
209 if( name
== "frozen_half_tone" )
211 return toString( _FrozenHalfTone
);
214 return CCtrlBase::getProperty( name
);
217 void CCtrlBaseButton::setProperty( const std::string
&name
, const std::string
&value
)
219 if( name
== "button_type" )
221 setTypeFromString( value
);
225 if( name
== "pushed" )
228 if( fromString( value
, b
) )
233 if( name
== "over_when_pushed" )
236 if( fromString( value
, b
) )
241 if( name
== "clicked_when_pushed" )
244 if( fromString( value
, b
) )
245 _ClickWhenPushed
= b
;
249 if( name
== "color" )
251 setColorAsString( value
);
255 if( name
== "col_pushed" )
257 setColorPushedAsString( value
);
261 if( name
== "col_over" )
263 setColorOverAsString( value
);
267 if( name
== "global_color_normal" )
270 if( fromString( value
, b
) )
271 _ModulateGlobalColorNormal
= b
;
275 if( name
== "global_color_pushed" )
278 if( fromString( value
, b
) )
279 _ModulateGlobalColorPushed
= b
;
284 if( name
== "global_color_over" )
287 if( fromString( value
, b
) )
288 _ModulateGlobalColorOver
= b
;
292 if( name
== "onover" )
295 _AHOnOver
= CAHManager::getInstance()->getAH( value
, dummy
);
296 mapAHString( "onover", value
);
300 if( name
== "params_over" )
302 _AHOverParams
= value
;
306 if( name
== "onclick_l" )
309 _AHOnLeftClick
= CAHManager::getInstance()->getAH( value
, dummy
);
310 mapAHString( "onclick_l", value
);
314 if( name
== "params_l" )
316 _AHLeftClickParams
= value
;
320 if( name
== "ondblclick_l" )
323 _AHOnLeftDblClick
= CAHManager::getInstance()->getAH( value
, dummy
);
324 mapAHString( "ondblclick_l", value
);
328 if( name
== "params_dblclick_l" )
330 _AHLeftDblClickParams
= value
;
334 if( name
== "onlongclick_l" )
337 _AHOnLeftLongClick
= CAHManager::getInstance()->getAH( value
, dummy
);
338 mapAHString( "onlongclick_l", value
);
342 if( name
== "params_longclick_l" )
344 _AHLeftLongClickParams
= value
;
348 if( name
== "onclick_r" )
351 _AHOnRightClick
= CAHManager::getInstance()->getAH( value
, dummy
);
352 mapAHString( "onclick_r", value
);
356 if( name
== "params_r" )
358 _AHRightClickParams
= value
;
362 if( name
== "onclock_tick" )
365 _AHOnClockTick
= CAHManager::getInstance()->getAH( value
, dummy
);
366 mapAHString( "onclock_tick", value
);
370 if( name
== "params_clock_tick" )
372 _AHClockTickParams
= value
;
376 if( name
== "menu_l" )
378 _ListMenuLeft
= value
;
382 if( name
== "menu_r" )
384 _ListMenuRight
= value
;
388 if( name
== "menu_b" )
390 _ListMenuLeft
= _ListMenuRight
= value
;
394 if( name
== "frozen" )
397 if( fromString( value
, b
) )
402 if( name
== "frozen_half_tone" )
405 if( fromString( value
, b
) )
410 CCtrlBase::setProperty( name
, value
);
414 xmlNodePtr
CCtrlBaseButton::serialize( xmlNodePtr parentNode
, const char *type
) const
416 xmlNodePtr node
= CCtrlBase::serialize( parentNode
, type
);
420 xmlSetProp( node
, BAD_CAST
"type", BAD_CAST
"button" );
421 xmlNewProp( node
, BAD_CAST
"button_type", BAD_CAST
getTypeString().c_str() );
422 xmlNewProp( node
, BAD_CAST
"pushed", BAD_CAST
toString( _Pushed
).c_str() );
423 xmlNewProp( node
, BAD_CAST
"over_when_pushed", BAD_CAST
toString( _OverWhenPushed
).c_str() );
424 xmlNewProp( node
, BAD_CAST
"clicked_when_pushed", BAD_CAST
toString( _ClickWhenPushed
).c_str() );
425 xmlNewProp( node
, BAD_CAST
"color", BAD_CAST
getColorAsString().c_str() );
426 xmlNewProp( node
, BAD_CAST
"col_pushed", BAD_CAST
getColorPushedAsString().c_str() );
427 xmlNewProp( node
, BAD_CAST
"col_over", BAD_CAST
getColorOverAsString().c_str() );
428 xmlNewProp( node
, BAD_CAST
"global_color_normal", BAD_CAST
toString( _ModulateGlobalColorNormal
).c_str() );
429 xmlNewProp( node
, BAD_CAST
"global_color_pushed", BAD_CAST
toString( _ModulateGlobalColorPushed
).c_str() );
430 xmlNewProp( node
, BAD_CAST
"global_color_over", BAD_CAST
toString( _ModulateGlobalColorOver
).c_str() );
432 xmlNewProp( node
, BAD_CAST
"onover", BAD_CAST
getAHString( "onover" ).c_str() );
433 xmlNewProp( node
, BAD_CAST
"params_over", BAD_CAST
_getParamsOnOver().c_str() );
434 xmlNewProp( node
, BAD_CAST
"onclick_l", BAD_CAST
getAHString( "onclick_l" ).c_str() );
435 xmlNewProp( node
, BAD_CAST
"params_l", BAD_CAST
_getParamsOnLeftClick().c_str() );
436 xmlNewProp( node
, BAD_CAST
"ondblclick_l", BAD_CAST
getAHString( "ondblclick_l" ).c_str() );
437 xmlNewProp( node
, BAD_CAST
"params_dblclick_l", BAD_CAST _AHLeftDblClickParams
.toString().c_str() );
438 xmlNewProp( node
, BAD_CAST
"onlongclick_l", BAD_CAST
getAHString( "onlongclick_l" ).c_str() );
439 xmlNewProp( node
, BAD_CAST
"params_longclick_l", BAD_CAST _AHLeftLongClickParams
.toString().c_str() );
440 xmlNewProp( node
, BAD_CAST
"onclick_r", BAD_CAST
getAHString( "onclick_r" ).c_str() );
441 xmlNewProp( node
, BAD_CAST
"params_r", BAD_CAST _AHRightClickParams
.toString().c_str() );
442 xmlNewProp( node
, BAD_CAST
"onclock_tick", BAD_CAST
getAHString( "onclock_tick" ).c_str() );
443 xmlNewProp( node
, BAD_CAST
"params_clock_tick", BAD_CAST _AHClockTickParams
.toString().c_str() );
446 xmlNewProp( node
, BAD_CAST
"menu_l", BAD_CAST _ListMenuLeft
.toString().c_str() );
447 xmlNewProp( node
, BAD_CAST
"menu_r", BAD_CAST _ListMenuRight
.toString().c_str() );
449 if( _ListMenuLeft
.toString() == _ListMenuRight
.toString() )
450 xmlNewProp( node
, BAD_CAST
"menu_b", BAD_CAST _ListMenuLeft
.toString().c_str() );
452 xmlNewProp( node
, BAD_CAST
"menu_b", BAD_CAST
"" );
454 xmlNewProp( node
, BAD_CAST
"frozen", BAD_CAST
toString( _Frozen
).c_str() );
455 xmlNewProp( node
, BAD_CAST
"frozen_half_tone", BAD_CAST
toString( _FrozenHalfTone
).c_str() );
461 // ***************************************************************************
462 bool CCtrlBaseButton::parse (xmlNodePtr cur
,CInterfaceGroup
* parentGroup
)
466 //try to get props that can be inherited from groups
467 //if a property is not defined, try to find it in the parent group.
468 //if it is undefined, set it to zero
469 if (! CCtrlBase::parse(cur
,parentGroup
) )
474 // *** try to get the NEEDED specific props
475 prop
= xmlGetProp (cur
, (xmlChar
*)"button_type");
479 type
= (const char*) prop
;
482 if (type
.empty() || type
== "toggle_button")
484 _Type
= ToggleButton
;
486 else if (type
== "push_button")
490 else if (type
== "radio_button")
500 nlinfo(("cannot parse button type for button " + getId()).c_str());
503 prop
= (char*) xmlGetProp (cur
, (xmlChar
*)"pushed");
506 _Pushed
= convertBool(prop
);
508 prop
= (char*) xmlGetProp (cur
, (xmlChar
*)"over_when_pushed");
509 _OverWhenPushed
= true;
511 _OverWhenPushed
= convertBool(prop
);
513 prop
= (char*) xmlGetProp (cur
, (xmlChar
*)"click_when_pushed");
514 _ClickWhenPushed
= false;
516 _ClickWhenPushed
= convertBool(prop
);
520 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"color" );
521 _ColorNormal
= CRGBA(255,255,255,255);
523 _ColorNormal
= convertColor (prop
);
526 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"col_pushed" );
527 _ColorPushed
= CRGBA(255,255,255,255);
529 _ColorPushed
= convertColor(prop
);
532 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"col_over" );
533 _ColorOver
= CRGBA(255,255,255,255);
535 _ColorOver
= convertColor(prop
);
537 // Default: take "global_color" param interface_element option.
538 _ModulateGlobalColorNormal
= _ModulateGlobalColorPushed
= _ModulateGlobalColorOver
= getModulateGlobalColor();
540 // Read special global_color for each state
541 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"global_color_normal" );
542 if (prop
) _ModulateGlobalColorNormal
= convertBool(prop
);
543 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"global_color_pushed" );
544 if (prop
) _ModulateGlobalColorPushed
= convertBool(prop
);
545 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"global_color_over" );
546 if (prop
) _ModulateGlobalColorOver
= convertBool(prop
);
549 // *** Read Action handlers
550 CAHManager::getInstance()->parseAH(cur
, "onover", "params_over", _AHOnOver
, _AHOverParams
);
551 CAHManager::getInstance()->parseAH(cur
, "onclick_l", "params_l", _AHOnLeftClick
, _AHLeftClickParams
);
552 CAHManager::getInstance()->parseAH(cur
, "ondblclick_l", "params_dblclick_l", _AHOnLeftDblClick
, _AHLeftDblClickParams
);
553 CAHManager::getInstance()->parseAH(cur
, "onclick_r", "params_r", _AHOnRightClick
, _AHRightClickParams
);
554 CAHManager::getInstance()->parseAH(cur
, "onlongclick_l", "params_longclick_l", _AHOnLeftLongClick
, _AHLeftLongClickParams
);
555 CAHManager::getInstance()->parseAH(cur
, "onclock_tick", "params_clock_tick", _AHOnClockTick
, _AHClockTickParams
);
559 prop
= (char*) xmlGetProp( cur
, BAD_CAST
"onover" );
561 mapAHString( "onover", std::string( (const char*)prop
) );
563 prop
= (char*) xmlGetProp( cur
, BAD_CAST
"onclick_l" );
565 mapAHString( "onclick_l", std::string( (const char*)prop
) );
567 prop
= (char*) xmlGetProp( cur
, BAD_CAST
"ondblclick_l" );
569 mapAHString( "ondblclick_l", std::string( (const char*)prop
) );
571 prop
= (char*) xmlGetProp( cur
, BAD_CAST
"onclick_r" );
573 mapAHString( "onclick_r", std::string( (const char*)prop
) );
575 prop
= (char*) xmlGetProp( cur
, BAD_CAST
"onlongclick_l" );
577 mapAHString( "onlongclick_l", std::string( (const char*)prop
) );
579 prop
= (char*) xmlGetProp( cur
, BAD_CAST
"onclock_tick" );
581 mapAHString( "onclock_tick", std::string( (const char*)prop
) );
584 // Context menu association
585 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"menu_l" );
588 _ListMenuLeft
= NLMISC::toLowerAscii(std::string((const char *) prop
));
590 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"menu_r" );
593 _ListMenuRight
= NLMISC::toLowerAscii(std::string((const char *) prop
));
595 // list menu on both clicks
596 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"menu_b" );
599 setListMenuBoth(NLMISC::toLowerAscii(std::string((const char *) prop
)));
602 prop
= (char*) xmlGetProp (cur
, (xmlChar
*)"frozen");
605 _Frozen
= convertBool(prop
);
607 prop
= (char*) xmlGetProp (cur
, (xmlChar
*)"frozen_half_tone");
608 _FrozenHalfTone
= true;
610 _FrozenHalfTone
= convertBool(prop
);
616 // ***************************************************************************
617 void CCtrlBaseButton::setModulateGlobalColorAll(bool state
)
619 setModulateGlobalColor(state
);
620 setModulateGlobalColorNormal(state
);
621 setModulateGlobalColorPushed(state
);
622 setModulateGlobalColorOver(state
);
626 // ***************************************************************************
627 bool CCtrlBaseButton::handleEvent (const NLGUI::CEventDescriptor
& event
)
629 if (CCtrlBase::handleEvent(event
)) return true;
630 if (!_Active
|| _Frozen
)
633 sint64 T1
= NLMISC::CTime::getLocalTime();
635 if (event
.getType() == NLGUI::CEventDescriptor::mouse
)
637 const NLGUI::CEventDescriptorMouse
&eventDesc
= (const NLGUI::CEventDescriptorMouse
&)event
;
639 if (eventDesc
.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mouseleftup
)
641 if (CWidgetManager::getInstance()->getCapturePointerLeft() != this)
643 _LeftLongClickHandled
= true;
646 if (!((eventDesc
.getX() >= _XReal
) &&
647 (eventDesc
.getX() < (_XReal
+ _WReal
))&&
648 (eventDesc
.getY() > _YReal
) &&
649 (eventDesc
.getY() <= (_YReal
+ _HReal
))))
652 if (eventDesc
.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mouseleftdown
)
654 if (_AHOnLeftDblClick
)
656 if ((CCtrlBaseButton
*) _LastLeftClickButton
== this && (T1
- _LastLeftClickDate
) < CWidgetManager::getInstance()->getUserDblClickDelay())
658 CAHManager::getInstance()->runActionHandler (_AHOnLeftDblClick
, this, _AHLeftDblClickParams
);
659 _LeftDblClickHandled
= true;
660 _LastLeftClickButton
= NULL
;
665 if (_AHOnLeftLongClick
!= NULL
)
667 _LeftLongClickHandled
= false;
668 _LeftLongClickDate
= T1
;
670 _LeftDblClickHandled
= false;
671 _LastLeftClickButton
= NULL
;
675 if (eventDesc
.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mouseleftup
)
677 if (CWidgetManager::getInstance()->getCapturePointerLeft() != this)
680 if (_LeftDblClickHandled
) // no effect on mouse up after double click has been handled
682 _LeftDblClickHandled
= false;
686 // Do not launch 2 times action handler if we are already pushed ! except if we want.
687 if (!_ClickWhenPushed
)
689 if ((_Type
== RadioButton
) && _RBRef
&& (*_RBRef
== this))
693 if (_Type
== RadioButton
)
696 if(_RBRef
) *_RBRef
= this;
699 if (_Type
== ToggleButton
)
704 if(_AHOnLeftClick != NULL)
706 //nlinfo("clicked on %s", _Id.c_str());
707 pIM->submitEvent ("button_click:"+getId());//TEMP
708 CAHManager::getInstance()->runActionHandler (_AHOnLeftClick, this, _AHLeftClickParams);
709 //pIM->submitEvent ("button_click:"+getId());
713 // top-right corner is EventX=0, EventY=0
714 _EventX
= eventDesc
.getX() - _XReal
;
715 _EventY
= (_YReal
+ _HReal
) - eventDesc
.getY();
717 runLeftClickAction();
718 if (CWidgetManager::getInstance()->getCapturePointerLeft() == NULL
) return true; // event handler may release cpature from this object (if it is removed for example)
721 if (!_ListMenuLeft
.empty())
722 CWidgetManager::getInstance()->enableModalWindow (this, _ListMenuLeft
);
724 if (_AHOnLeftDblClick
!= NULL
)
726 _LastLeftClickDate
= T1
;
727 _LastLeftClickButton
= this;
730 // Always return true on LeftClick.
733 if (eventDesc
.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mouserightdown
)
735 _LastLeftClickButton
= NULL
;
738 if (eventDesc
.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mouserightup
)
740 _LastLeftClickButton
= NULL
;
742 if (CWidgetManager::getInstance()->getCapturePointerRight() != this)
746 if(_AHOnRightClick
!= NULL
)
749 CAHManager::getInstance()->runActionHandler (_AHOnRightClick
, this, _AHRightClickParams
);
751 if (CWidgetManager::getInstance()->getCapturePointerRight() == NULL
) return true; // if this become NULL, this ctrl has been deleted
753 if (!_ListMenuRight
.empty())
756 CWidgetManager::getInstance()->enableModalWindow (this, _ListMenuRight
);
758 // If not handled here, ret to parent
764 else if (event
.getType() == NLGUI::CEventDescriptor::system
)
766 const NLGUI::CEventDescriptorSystem
&systemEvent
= (const NLGUI::CEventDescriptorSystem
&) event
;
767 if (systemEvent
.getEventTypeExtended() == NLGUI::CEventDescriptorSystem::clocktick
)
769 if (_AHOnClockTick
!= NULL
)
771 CAHManager::getInstance()->runActionHandler(_AHOnClockTick
, this, _AHClockTickParams
);
774 if (CWidgetManager::getInstance()->getCapturePointerLeft() == this)
776 if (!_LeftLongClickHandled
)
779 CCDBNodeLeaf
*pNL
= NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:KEY_REPEAT_SPEED");
781 nVal
= pNL
->getValue32();
782 uint repeatDelay
= (uint
)(KEY_REPEAT_MIN
+ (KEY_REPEAT_MAX
-KEY_REPEAT_MIN
) * (float)nVal
/ 100.0f
);
783 if ((T1
- _LeftLongClickDate
) > repeatDelay
)
785 _LeftLongClickHandled
= true;
786 CAHManager::getInstance()->runActionHandler(_AHOnLeftLongClick
, this, _AHLeftLongClickParams
);
795 std::string
CCtrlBaseButton::getTypeString() const
800 return "push_button";
804 return "toggle_button";
808 return "radio_button";
818 void CCtrlBaseButton::setTypeFromString( const std::string
&type
)
820 if( type
.empty() || type
== "toggle_button" )
822 _Type
= ToggleButton
;
826 if( type
== "push_button" )
832 if( type
== "radio_button" )
844 _Type
= ToggleButton
;
845 nlinfo( ( "cannot parse button type for button " + getId() ).c_str() );
849 // ***************************************************************************
850 void CCtrlBaseButton::initRBRef()
852 if (_RBRef
!= NULL
) return;
854 const vector
<CCtrlBase
*> &vCB
= _Parent
->getControls();
856 for (i
= 0; i
< vCB
.size(); ++i
)
858 CCtrlBaseButton
*pBut
= dynamic_cast<CCtrlBaseButton
*>(vCB
[i
]);
859 if (pBut
&& pBut
->_Type
== RadioButton
)
861 _RBRef
= &pBut
->_RBRefBut
;
865 // If we are the first radio button of the group and not added
867 _RBRef
= &this->_RBRefBut
;
870 // ***************************************************************************
871 void CCtrlBaseButton::initRBRefFromRadioButton(CCtrlBaseButton
* pBut
)
873 if(pBut
&& pBut
->_Type
== RadioButton
)
875 _RBRef
= &(pBut
->_RBRefBut
);
881 // ***************************************************************************
882 void CCtrlBaseButton::setPushed (bool state
)
886 if (_Type
== RadioButton
&& _RBRef
)
894 if (*_RBRef
== this) // I have to be pushed to unpush me
895 *_RBRef
= NULL
; // After that : All radio buttons are NOT pushed
900 // ***************************************************************************
901 void CCtrlBaseButton::setFrozen (bool state
)
911 // ***************************************************************************
912 void CCtrlBaseButton::setFrozenHalfTone(bool enabled
)
914 _FrozenHalfTone
= enabled
;
917 // ***************************************************************************
918 void CCtrlBaseButton::unselect()
920 if (_Type
== RadioButton
)
922 if (_RBRef
) *_RBRef
= NULL
;
927 // ***************************************************************************
928 void CCtrlBaseButton::updateOver(bool &lastOver
)
930 if (!CWidgetManager::getInstance()->isMouseHandlingEnabled())
936 if (CWidgetManager::getInstance()->getCapturePointerLeft() != NULL
)
938 if (CWidgetManager::getInstance()->getCapturePointerLeft() != this)
945 const vector
<CCtrlBase
*> &rVB
= CWidgetManager::getInstance()->getCtrlsUnderPointer ();
951 // show over if it is the last control that has the same father
952 CCtrlBase
*candidate
= NULL
;
953 for (i
= 0; i
< rVB
.size(); ++i
)
955 if (rVB
[i
]->getParent() == this->getParent())
960 _Over
= (candidate
== this);
968 // ***************************************************************************
969 void CCtrlBaseButton::elementCaptured(CCtrlBase
*capturedElement
)
971 // if not me, then reset my '_Over'
972 if (capturedElement
!= this)
979 // ***************************************************************************
980 void CCtrlBaseButton::runLeftClickAction()
982 if(_AHOnLeftClick
!= NULL
)
985 //nlinfo("clicked on %s", _Id.c_str());
986 CAHManager::getInstance()->submitEvent( "button_click:" + getId() );
987 CAHManager::getInstance()->runActionHandler (_AHOnLeftClick
, this, _AHLeftClickParams
);
988 //pIM->submitEvent ("button_click:"+getId());
992 // ***************************************************************************
993 int CCtrlBaseButton::luaRunLeftClickAction(CLuaState
&ls
)
995 const char *funcName
= "onLeftClick";
996 CLuaIHM::checkArgCount(ls
, funcName
, 0);
998 runLeftClickAction();
1003 // ***************************************************************************
1004 void CCtrlBaseButton::runRightClickAction()
1006 if(_AHOnRightClick
!= NULL
)
1009 CAHManager::getInstance()->submitEvent( "button_click:" + getId() );
1010 CAHManager::getInstance()->runActionHandler (_AHOnRightClick
, this, _AHRightClickParams
);
1014 // ***************************************************************************
1015 int CCtrlBaseButton::luaRunRightClickAction(CLuaState
&ls
)
1017 const char *funcName
= "onRightClick";
1018 CLuaIHM::checkArgCount(ls
, funcName
, 0);
1020 runRightClickAction();