CHANGED: #1471 CDBGroupComboBox is now part of the NELGUI library and is under the NLGUI namespace.
This commit is contained in:
parent
02ba7f66f9
commit
0c8698d7f0
21 changed files with 810 additions and 793 deletions
162
code/nel/include/nel/gui/dbgroup_combo_box.h
Normal file
162
code/nel/include/nel/gui/dbgroup_combo_box.h
Normal file
|
@ -0,0 +1,162 @@
|
|||
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
|
||||
// Copyright (C) 2010 Winch Gate Property Limited
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
|
||||
#ifndef NL_DBGROUP_COMBO_BOX_H
|
||||
#define NL_DBGROUP_COMBO_BOX_H
|
||||
|
||||
#include "nel/misc/types_nl.h"
|
||||
#include "nel/gui/interface_group.h"
|
||||
|
||||
namespace NLGUI
|
||||
{
|
||||
class CCtrlBaseButton;
|
||||
class CViewText;
|
||||
class CGroupMenu;
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
/**
|
||||
* Widget: ComboBox of text
|
||||
* \author Lionel Berenguier
|
||||
* \author Nevrax France
|
||||
* \date 2002
|
||||
*/
|
||||
class CDBGroupComboBox : public CInterfaceGroup
|
||||
{
|
||||
public:
|
||||
|
||||
/// Constructor
|
||||
CDBGroupComboBox(const TCtorParam ¶m);
|
||||
~CDBGroupComboBox();
|
||||
|
||||
/// CInterfaceGroup Interface
|
||||
virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup);
|
||||
virtual void updateCoords ();
|
||||
virtual void checkCoords ();
|
||||
|
||||
// Combo Texts
|
||||
void resetTexts();
|
||||
void addText(const ucstring &text);
|
||||
void setText(uint i, const ucstring &text);
|
||||
void insertText(uint i, const ucstring &text);
|
||||
const ucstring &getText(uint i) const;
|
||||
const ucstring &getTexture(uint i) const;
|
||||
void removeText(uint i);
|
||||
uint getNumTexts() const {return (uint)_Texts.size();}
|
||||
|
||||
// selection
|
||||
void setSelection(sint32 val);
|
||||
void setSelectionNoTrigger(sint32 val);
|
||||
sint32 getSelection() const;
|
||||
|
||||
// selection number
|
||||
void setSelectionNb(sint32 /* val */){}
|
||||
sint32 getSelectionNb() const {return (sint32)_Texts.size();}
|
||||
|
||||
// selection text
|
||||
void setSelectionText(const std::string & val);
|
||||
std::string getSelectionText() const;
|
||||
|
||||
// view text
|
||||
void setViewText(const ucstring & text);
|
||||
ucstring getViewText() const;
|
||||
|
||||
void setTexture(uint i, const ucstring &texture);
|
||||
|
||||
sint32 evalContentWidth() const;
|
||||
|
||||
|
||||
int luaAddText(CLuaState &ls);
|
||||
int luaRemoveSelection(CLuaState &ls);
|
||||
int luaRemoveText(CLuaState &ls);
|
||||
int luaRemoveTextByIndex(CLuaState &ls);
|
||||
int luaResetTexts(CLuaState &ls);
|
||||
int luaSetText(CLuaState &ls);
|
||||
int luaInsertText(CLuaState &ls);
|
||||
int luaGetText(CLuaState &ls);
|
||||
int luaGetNumTexts(CLuaState &ls);
|
||||
int luaSetTexture(CLuaState &ls);
|
||||
|
||||
|
||||
REFLECT_EXPORT_START(CDBGroupComboBox, CInterfaceGroup)
|
||||
REFLECT_SINT32("selection", getSelection, setSelection)
|
||||
REFLECT_LUA_METHOD("addText", luaAddText)
|
||||
REFLECT_LUA_METHOD("setText", luaSetText)
|
||||
REFLECT_LUA_METHOD("insertText", luaInsertText)
|
||||
REFLECT_LUA_METHOD("setTexture", luaSetTexture)
|
||||
REFLECT_LUA_METHOD("getText", luaGetText)
|
||||
REFLECT_LUA_METHOD("getNumTexts", luaGetNumTexts)
|
||||
REFLECT_LUA_METHOD("removeSelection", luaRemoveSelection)
|
||||
REFLECT_LUA_METHOD("removeText", luaRemoveText)
|
||||
REFLECT_LUA_METHOD("removeTextByIndex", luaRemoveTextByIndex)
|
||||
REFLECT_LUA_METHOD("resetTexts", luaResetTexts)
|
||||
REFLECT_SINT32 ("selectionNb", getSelectionNb, setSelectionNb)
|
||||
REFLECT_STRING ("selection_text", getSelectionText, setSelectionText)
|
||||
REFLECT_UCSTRING ("view_text", getViewText, setViewText)
|
||||
REFLECT_EXPORT_END
|
||||
|
||||
|
||||
protected:
|
||||
friend class CHandlerComboBoxSelectStart;
|
||||
|
||||
bool _LinkedToDB; // if not linked to db, then _NotLinkedToDBSelection is used instead
|
||||
bool _Setuped;
|
||||
bool _DirtySelection;
|
||||
sint32 _CacheSelection;
|
||||
|
||||
// sint32
|
||||
CInterfaceProperty _Selection;
|
||||
sint32 _NotLinkedToDBSelection;
|
||||
std::vector<ucstring> _Texts;
|
||||
std::vector<ucstring> _Textures;
|
||||
|
||||
// Action Handler called on combo click
|
||||
std::string _AHOnSelectStart;
|
||||
|
||||
// Action handler called when the content is changed
|
||||
std::string _AHOnChange;
|
||||
std::string _AHOnChangeParams;
|
||||
bool _CallingOnChangeActionHandler; // avoid infinite loop here
|
||||
|
||||
|
||||
// Children
|
||||
CViewText *_ViewText;
|
||||
CCtrlBaseButton *_SelectButton;
|
||||
|
||||
bool _IsExternViewText;
|
||||
ucstring _ExternViewText;
|
||||
|
||||
|
||||
private:
|
||||
void setup();
|
||||
void dirt();
|
||||
public:
|
||||
// private : fill a menu with current content
|
||||
void fillMenu(CGroupMenu *groupMenu) const;
|
||||
|
||||
|
||||
static std::string measureMenu;
|
||||
static std::string selectMenu;
|
||||
static std::string selectMenuOut;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // NL_DBGROUP_COMBO_BOX_H
|
||||
|
||||
/* End of dbgroup_combo_box.h */
|
|
@ -42,6 +42,8 @@ namespace NLGUI
|
|||
virtual bool parse (xmlNodePtr cur, CInterfaceGroup * parentGroup);
|
||||
virtual void draw ();
|
||||
|
||||
static void forceLink();
|
||||
|
||||
|
||||
protected:
|
||||
CInterfaceProperty _Number;
|
||||
|
|
622
code/nel/src/gui/dbgroup_combo_box.cpp
Normal file
622
code/nel/src/gui/dbgroup_combo_box.cpp
Normal file
|
@ -0,0 +1,622 @@
|
|||
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
|
||||
// Copyright (C) 2010 Winch Gate Property Limited
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#include "nel/gui/dbgroup_combo_box.h"
|
||||
#include "nel/gui/group_menu.h"
|
||||
#include "nel/misc/xml_auto_ptr.h"
|
||||
#include "nel/gui/ctrl_button.h"
|
||||
#include "nel/gui/action_handler.h"
|
||||
#include "nel/gui/lua_ihm.h"
|
||||
#include "nel/gui/widget_manager.h"
|
||||
#include "nel/misc/i18n.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace NLMISC;
|
||||
|
||||
NLMISC_REGISTER_OBJECT(CViewBase, CDBGroupComboBox, std::string, "combo_box");
|
||||
|
||||
namespace NLGUI
|
||||
{
|
||||
|
||||
std::string CDBGroupComboBox::measureMenu;
|
||||
std::string CDBGroupComboBox::selectMenu;
|
||||
std::string CDBGroupComboBox::selectMenuOut;
|
||||
|
||||
// ***************************************************************************
|
||||
CDBGroupComboBox::CDBGroupComboBox(const TCtorParam ¶m)
|
||||
: CInterfaceGroup(param)
|
||||
{
|
||||
_Setuped= false;
|
||||
_ViewText= NULL;
|
||||
_SelectButton= NULL;
|
||||
_LinkedToDB = true;
|
||||
_NotLinkedToDBSelection = 0;
|
||||
_CallingOnChangeActionHandler = false;
|
||||
_IsExternViewText = false;
|
||||
dirt();
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
CDBGroupComboBox::~CDBGroupComboBox()
|
||||
{
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
sint32 CDBGroupComboBox::evalContentWidth() const
|
||||
{
|
||||
// get the menu to open.
|
||||
CGroupMenu *groupMenu= dynamic_cast<CGroupMenu*>(CWidgetManager::getInstance()->getElementFromId( CDBGroupComboBox::measureMenu ));
|
||||
if( !groupMenu )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
fillMenu(groupMenu);
|
||||
groupMenu->setActive(true);
|
||||
groupMenu->updateCoords();
|
||||
sint32 width = groupMenu->getWReal();
|
||||
groupMenu->setActive(false);
|
||||
groupMenu->reset();
|
||||
// add width for the selection arrow
|
||||
return width;
|
||||
}
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
bool CDBGroupComboBox::parse (xmlNodePtr cur, CInterfaceGroup *parentGroup)
|
||||
{
|
||||
if( !CInterfaceGroup::parse(cur, parentGroup) )
|
||||
return false;
|
||||
|
||||
CXMLAutoPtr prop((const char*)xmlGetProp(cur, (xmlChar*)"linked_to_db"));
|
||||
if (prop)
|
||||
{
|
||||
_LinkedToDB = convertBool(prop);
|
||||
}
|
||||
|
||||
if (_LinkedToDB)
|
||||
{
|
||||
// read the selection value
|
||||
CXMLAutoPtr prop((const char*)xmlGetProp(cur, (xmlChar*)"value"));
|
||||
if(!prop)
|
||||
{
|
||||
nlwarning("'value' not found in %s", _Id.c_str());
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_Selection.link((const char*)prop);
|
||||
}
|
||||
}
|
||||
|
||||
// read the sons text
|
||||
xmlNodePtr child;
|
||||
child = cur->children;
|
||||
while (child)
|
||||
{
|
||||
if (stricmp((char*)child->name,"combo_text") == 0)
|
||||
{
|
||||
CXMLAutoPtr name((const char*) xmlGetProp (child, (xmlChar*)"name"));
|
||||
if (name)
|
||||
{
|
||||
const char *propPtr = name;
|
||||
ucstring Text = ucstring::makeFromUtf8(propPtr);
|
||||
if ((strlen(propPtr)>2) && (propPtr[0] == 'u') && (propPtr[1] == 'i'))
|
||||
Text = CI18N::get (propPtr);
|
||||
addText(Text);
|
||||
}
|
||||
}
|
||||
child = child->next;
|
||||
}
|
||||
|
||||
// optional ActionHandler on click
|
||||
prop= xmlGetProp(cur, (xmlChar*)"on_select_start");
|
||||
if(prop) _AHOnSelectStart= (const char*)prop;
|
||||
|
||||
// optional ActionHandler on change
|
||||
prop= xmlGetProp(cur, (xmlChar*)"on_change");
|
||||
if(prop) _AHOnChange= (const char*)prop;
|
||||
|
||||
prop= xmlGetProp(cur, (xmlChar*)"on_change_params");
|
||||
if(prop) _AHOnChangeParams= (const char*)prop;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CDBGroupComboBox::checkCoords ()
|
||||
{
|
||||
if(!_ViewText)
|
||||
return;
|
||||
bool mustUpdate = false;
|
||||
if (_LinkedToDB)
|
||||
{
|
||||
// if some change in texts/selection
|
||||
if(_DirtySelection || _CacheSelection!=_Selection.getSInt32())
|
||||
{
|
||||
_CacheSelection= _Selection.getSInt32();
|
||||
mustUpdate = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// if some change in texts/selection
|
||||
if(_DirtySelection || _CacheSelection != _NotLinkedToDBSelection)
|
||||
{
|
||||
_CacheSelection= _NotLinkedToDBSelection;
|
||||
mustUpdate = true;
|
||||
}
|
||||
}
|
||||
if (mustUpdate)
|
||||
{
|
||||
// change selected text
|
||||
if(_CacheSelection<0 || _CacheSelection>=(sint32)_Texts.size() )
|
||||
{
|
||||
_ViewText->setText(ucstring());
|
||||
}
|
||||
else if(_IsExternViewText)
|
||||
{
|
||||
_ViewText->setText(_ExternViewText);
|
||||
}
|
||||
else
|
||||
{
|
||||
_ViewText->setText(_Texts[_CacheSelection]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CDBGroupComboBox::updateCoords ()
|
||||
{
|
||||
if(!_Setuped)
|
||||
setup();
|
||||
CInterfaceGroup::updateCoords();
|
||||
}
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
void CDBGroupComboBox::dirt()
|
||||
{
|
||||
_DirtySelection= true;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CDBGroupComboBox::resetTexts()
|
||||
{
|
||||
dirt();
|
||||
_Texts.clear();
|
||||
_Textures.clear();
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CDBGroupComboBox::addText(const ucstring &text)
|
||||
{
|
||||
dirt();
|
||||
_Texts.push_back(text);
|
||||
_Textures.push_back(std::string());
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CDBGroupComboBox::setText(uint i, const ucstring &text)
|
||||
{
|
||||
dirt();
|
||||
if(i<_Texts.size())
|
||||
_Texts[i]= text;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CDBGroupComboBox::insertText(uint i, const ucstring &text)
|
||||
{
|
||||
dirt();
|
||||
if(i<_Texts.size())
|
||||
{
|
||||
addText(_Texts[_Texts.size()-1]);
|
||||
|
||||
for(uint t=i; t<_Texts.size()-1; t++)
|
||||
{
|
||||
_Texts[t+1] = _Texts[t];
|
||||
_Textures[t+1] = _Textures[t];
|
||||
}
|
||||
_Texts[i]= text;
|
||||
_Textures[i] = std::string();
|
||||
}
|
||||
else if(i==_Texts.size())
|
||||
addText(text);
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CDBGroupComboBox::setTexture(uint i, const ucstring &texture)
|
||||
{
|
||||
dirt();
|
||||
if(i<_Textures.size())
|
||||
_Textures[i]= texture;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CDBGroupComboBox::removeText(uint i)
|
||||
{
|
||||
dirt();
|
||||
if(i<_Texts.size())
|
||||
{
|
||||
_Texts.erase( _Texts.begin()+i );
|
||||
_Textures.erase( _Textures.begin()+i );
|
||||
}
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
const ucstring &CDBGroupComboBox::getText(uint i) const
|
||||
{
|
||||
static ucstring null;
|
||||
if(i<_Texts.size())
|
||||
return _Texts[i];
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
const ucstring &CDBGroupComboBox::getTexture(uint i) const
|
||||
{
|
||||
static ucstring null;
|
||||
if(i<_Textures.size())
|
||||
return _Textures[i];
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
void CDBGroupComboBox::setSelection(sint32 val)
|
||||
{
|
||||
_IsExternViewText = false;
|
||||
|
||||
if (_LinkedToDB)
|
||||
{
|
||||
_Selection.setSInt32(val);
|
||||
}
|
||||
else
|
||||
{
|
||||
_NotLinkedToDBSelection = val;
|
||||
}
|
||||
if (!_AHOnChange.empty())
|
||||
{
|
||||
if (!_CallingOnChangeActionHandler)
|
||||
{
|
||||
_CallingOnChangeActionHandler = true;
|
||||
CAHManager::getInstance()->runActionHandler (_AHOnChange, this, _AHOnChangeParams);
|
||||
_CallingOnChangeActionHandler = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CDBGroupComboBox::setSelectionNoTrigger(sint32 val)
|
||||
{
|
||||
if (_LinkedToDB)
|
||||
{
|
||||
_Selection.setSInt32(val);
|
||||
}
|
||||
else
|
||||
{
|
||||
_NotLinkedToDBSelection = val;
|
||||
}
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
sint32 CDBGroupComboBox::getSelection() const
|
||||
{
|
||||
if (_LinkedToDB)
|
||||
{
|
||||
return _Selection.getSInt32();
|
||||
}
|
||||
else
|
||||
{
|
||||
return _NotLinkedToDBSelection;
|
||||
}
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CDBGroupComboBox::setSelectionText(const std::string & val)
|
||||
{
|
||||
sint32 value;
|
||||
for(uint i=0; i<getNumTexts(); i++)
|
||||
{
|
||||
std::string sText;
|
||||
getText(i).toString(sText);
|
||||
if(sText == val)
|
||||
{
|
||||
value = i;
|
||||
setSelection(value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CDBGroupComboBox::setViewText(const ucstring & text)
|
||||
{
|
||||
_IsExternViewText = true;
|
||||
_ExternViewText = ucstring(text);
|
||||
_ViewText->setText(_ExternViewText);
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
ucstring CDBGroupComboBox::getViewText() const
|
||||
{
|
||||
return _ViewText->getText();
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
std::string CDBGroupComboBox::getSelectionText() const
|
||||
{
|
||||
ucstring text;
|
||||
if (_LinkedToDB)
|
||||
{
|
||||
text = getText(_Selection.getSInt32());
|
||||
}
|
||||
else
|
||||
{
|
||||
text = getText(_NotLinkedToDBSelection);
|
||||
}
|
||||
std::string texteS;
|
||||
text.toString(texteS);
|
||||
return texteS;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CDBGroupComboBox::setup()
|
||||
{
|
||||
_Setuped= true;
|
||||
|
||||
// get the viewText
|
||||
_ViewText= dynamic_cast<CViewText*>(CInterfaceGroup::getView("text"));
|
||||
// get the button
|
||||
_SelectButton= dynamic_cast<CCtrlBaseButton*>(CInterfaceGroup::getCtrl("select"));
|
||||
|
||||
// force the action handler
|
||||
if( _SelectButton )
|
||||
_SelectButton->setActionOnLeftClick("combo_box_select_start");
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
int CDBGroupComboBox::luaRemoveSelection(CLuaState &ls)
|
||||
{
|
||||
CLuaIHM::checkArgCount(ls, "removeSelection", 1);
|
||||
sint32 value;
|
||||
if(CLuaIHM::popSINT32(ls, value))
|
||||
{
|
||||
removeText(value);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CDBGroupComboBox::luaRemoveText(CLuaState &ls)
|
||||
{
|
||||
CLuaIHM::checkArgCount(ls, "removeText", 1);
|
||||
CLuaIHM::checkArgType(ls, "removeText", 1, LUA_TSTRING);
|
||||
std::string text = ls.toString(1);
|
||||
sint32 value;
|
||||
for(uint i=0; i<getNumTexts(); i++)
|
||||
{
|
||||
std::string sText;
|
||||
getText(i).toString(sText);
|
||||
if(sText == text)
|
||||
{
|
||||
value = i;
|
||||
removeText(value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CDBGroupComboBox::luaResetTexts(CLuaState &ls)
|
||||
{
|
||||
CLuaIHM::checkArgCount(ls, "resetTexts", 0);
|
||||
resetTexts();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CDBGroupComboBox::luaAddText(CLuaState &ls)
|
||||
{
|
||||
const char *funcName = "addText";
|
||||
CLuaIHM::checkArgCount(ls, funcName, 1);
|
||||
CLuaIHM::checkArgTypeUCString(ls, funcName, 1);
|
||||
ucstring text;
|
||||
nlverify(CLuaIHM::pop(ls, text));
|
||||
addText(text);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CDBGroupComboBox::luaSetText(CLuaState &ls)
|
||||
{
|
||||
const char *funcName = "setText";
|
||||
CLuaIHM::checkArgCount(ls, funcName, 2);
|
||||
CLuaIHM::checkArgType(ls, funcName, 1, LUA_TNUMBER);
|
||||
CLuaIHM::checkArgTypeUCString(ls, funcName, 2);
|
||||
ucstring text;
|
||||
nlverify(CLuaIHM::pop(ls, text));
|
||||
setText((uint) ls.toNumber(1), text);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CDBGroupComboBox::luaInsertText(CLuaState &ls)
|
||||
{
|
||||
const char *funcName = "insertText";
|
||||
CLuaIHM::checkArgCount(ls, funcName, 2);
|
||||
CLuaIHM::checkArgType(ls, funcName, 1, LUA_TNUMBER);
|
||||
CLuaIHM::checkArgTypeUCString(ls, funcName, 2);
|
||||
ucstring text;
|
||||
nlverify(CLuaIHM::pop(ls, text));
|
||||
insertText((uint) ls.toNumber(1), text);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CDBGroupComboBox::luaSetTexture(CLuaState &ls)
|
||||
{
|
||||
const char *funcName = "setTexture";
|
||||
CLuaIHM::checkArgCount(ls, funcName, 2);
|
||||
CLuaIHM::checkArgType(ls, funcName, 1, LUA_TNUMBER);
|
||||
CLuaIHM::checkArgTypeUCString(ls, funcName, 2);
|
||||
ucstring texture;
|
||||
nlverify(CLuaIHM::pop(ls, texture));
|
||||
setTexture((uint) ls.toNumber(1), texture);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CDBGroupComboBox::luaGetText(CLuaState &ls)
|
||||
{
|
||||
const char *funcName = "setText";
|
||||
CLuaIHM::checkArgCount(ls, funcName, 1);
|
||||
CLuaIHM::checkArgType(ls, funcName, 1, LUA_TNUMBER);
|
||||
CLuaIHM::push(ls, getText((uint) ls.toNumber(1)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CDBGroupComboBox::luaRemoveTextByIndex(CLuaState &ls)
|
||||
{
|
||||
const char *funcName = "removeText";
|
||||
CLuaIHM::checkArgCount(ls, funcName, 1);
|
||||
CLuaIHM::checkArgType(ls, funcName, 1, LUA_TNUMBER);
|
||||
removeText((uint) ls.toNumber(1));
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CDBGroupComboBox::luaGetNumTexts(CLuaState &ls)
|
||||
{
|
||||
const char *funcName = "getNumTexts";
|
||||
CLuaIHM::checkArgCount(ls, funcName, 0);
|
||||
ls.push((double) getNumTexts());
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CDBGroupComboBox::fillMenu(CGroupMenu *groupMenu) const
|
||||
{
|
||||
nlassert(groupMenu);
|
||||
|
||||
// Setup the menu with combo action.
|
||||
groupMenu->reset();
|
||||
for(uint i=0; i<getNumTexts(); i++)
|
||||
{
|
||||
// set the id as the parameter
|
||||
bool checkable = false;
|
||||
if(getTexture(i).toString() != std::string())
|
||||
{
|
||||
checkable = true;
|
||||
}
|
||||
groupMenu->addLine(getText(i), "combo_box_select_end", toString(i),
|
||||
"", std::string(), getTexture(i).toString(), checkable);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
class CHandlerComboBoxSelectStart : public IActionHandler
|
||||
{
|
||||
public:
|
||||
virtual void execute (CCtrlBase *pCaller, const std::string &/* Params */)
|
||||
{
|
||||
CDBGroupComboBox *pCB = dynamic_cast<CDBGroupComboBox*>(pCaller->getParent());
|
||||
if (pCB == NULL) return;
|
||||
// if no choice, return.
|
||||
if( pCB->getNumTexts()==0 )
|
||||
return;
|
||||
|
||||
// get the menu to open.
|
||||
CGroupMenu *groupMenu= dynamic_cast<CGroupMenu*>(CWidgetManager::getInstance()->getElementFromId( CDBGroupComboBox::selectMenu ));
|
||||
if( !groupMenu )
|
||||
{
|
||||
groupMenu= dynamic_cast<CGroupMenu*>(CWidgetManager::getInstance()->getElementFromId( CDBGroupComboBox::selectMenuOut ));
|
||||
}
|
||||
if( !groupMenu )
|
||||
return;
|
||||
|
||||
pCB->fillMenu(groupMenu);
|
||||
|
||||
groupMenu->setMaxVisibleLine(8);
|
||||
|
||||
// pos and size wisely the menu.
|
||||
groupMenu->setMinW(pCB->getWReal());
|
||||
groupMenu->setX(pCB->getXReal());
|
||||
groupMenu->setBaseX(pCB->getXReal());
|
||||
groupMenu->setY(pCB->getYReal());
|
||||
groupMenu->setBaseY(pCB->getYReal());
|
||||
|
||||
// Must ensure the combo menu has same windows priority than the combo box window
|
||||
CInterfaceGroup *rootWin= pCB->getRootWindow();
|
||||
if(rootWin)
|
||||
groupMenu->setPriority(rootWin->getPriority());
|
||||
|
||||
// After menu init, Call user activation method
|
||||
if( !pCB->_AHOnSelectStart.empty() )
|
||||
{
|
||||
CAHManager::getInstance()->runActionHandler(pCB->_AHOnSelectStart, pCB);
|
||||
}
|
||||
|
||||
// launch the menu
|
||||
// if the combo box is in a modal, must do a push, else just replace
|
||||
if(dynamic_cast<CGroupModal*>(pCB->getRootWindow()))
|
||||
{
|
||||
groupMenu->setCloseSubMenuUsingPopModal(true);
|
||||
CWidgetManager::getInstance()->pushModalWindow(pCB, groupMenu);
|
||||
}
|
||||
else
|
||||
{
|
||||
groupMenu->setCloseSubMenuUsingPopModal(false);
|
||||
CWidgetManager::getInstance()->enableModalWindow (pCB, groupMenu);
|
||||
}
|
||||
}
|
||||
};
|
||||
REGISTER_ACTION_HANDLER (CHandlerComboBoxSelectStart, "combo_box_select_start");
|
||||
|
||||
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
class CHandlerComboBoxSelectEnd : public IActionHandler
|
||||
{
|
||||
public:
|
||||
virtual void execute (CCtrlBase * /* pCaller */, const std::string &Params)
|
||||
{
|
||||
CDBGroupComboBox *pCB = dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getCtrlLaunchingModal());
|
||||
if (pCB == NULL) return;
|
||||
|
||||
// set the selection
|
||||
sint32 selection;
|
||||
fromString(Params, selection);
|
||||
pCB->setSelection(selection);
|
||||
}
|
||||
};
|
||||
REGISTER_ACTION_HANDLER (CHandlerComboBoxSelectEnd, "combo_box_select_end");
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -111,4 +111,8 @@ namespace NLGUI
|
|||
setText(toString((const char*)buf));
|
||||
}
|
||||
}
|
||||
|
||||
void CDBViewQuantity::forceLink()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "nel/gui/dbview_bar3.h"
|
||||
#include "nel/gui/dbview_number.h"
|
||||
#include "nel/gui/dbview_quantity.h"
|
||||
|
||||
namespace NLGUI
|
||||
{
|
||||
|
@ -8,5 +9,6 @@ namespace NLGUI
|
|||
{
|
||||
CDBViewBar3::forceLink();
|
||||
CDBViewNumber::forceLink();
|
||||
CDBViewQuantity::forceLink();
|
||||
}
|
||||
}
|
|
@ -71,7 +71,7 @@
|
|||
#include "init_main_loop.h"
|
||||
#include "continent_manager.h"
|
||||
#include "interface_v3/group_quick_help.h"
|
||||
#include "interface_v3/dbgroup_combo_box.h"
|
||||
#include "nel/gui/dbgroup_combo_box.h"
|
||||
|
||||
#include "r2/dmc/client_edition_module.h"
|
||||
#include "r2/editor.h"
|
||||
|
|
|
@ -82,7 +82,7 @@
|
|||
#include "game_share/scores.h"
|
||||
|
||||
// Game Config
|
||||
#include "dbgroup_combo_box.h"
|
||||
#include "nel/gui/dbgroup_combo_box.h"
|
||||
#include "nel/gui/ctrl_button.h"
|
||||
#include "../global.h"
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#include "nel/gui/view_text_id.h"
|
||||
#include "../user_entity.h"
|
||||
#include "../entities.h"
|
||||
#include "dbgroup_combo_box.h"
|
||||
#include "nel/gui/dbgroup_combo_box.h"
|
||||
#include "nel/gui/dbview_bar.h"
|
||||
#include "../debug_client.h"
|
||||
#include "interface_3d_scene.h"
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include "nel/gui/interface_group.h"
|
||||
#include "../string_manager_client.h"
|
||||
#include "nel/gui/action_handler.h"
|
||||
#include "dbgroup_combo_box.h"
|
||||
#include "nel/gui/dbgroup_combo_box.h"
|
||||
#include "bot_chat_page_all.h"
|
||||
#include "bot_chat_manager.h"
|
||||
#include "../client_cfg.h"
|
||||
|
|
|
@ -21,7 +21,10 @@
|
|||
|
||||
#include "bot_chat_page.h"
|
||||
|
||||
class CDBGroupComboBox;
|
||||
namespace NLGUI
|
||||
{
|
||||
class CDBGroupComboBox;
|
||||
}
|
||||
|
||||
// number of choices that the player must make to create a dynamic mission
|
||||
const uint DYNAMIC_MISSION_NUM_CHOICES = 3;
|
||||
|
@ -51,7 +54,7 @@ public:
|
|||
void regen();
|
||||
private:
|
||||
// The control for each choice list
|
||||
CDBGroupComboBox *_ChoiceCB[DYNAMIC_MISSION_NUM_CHOICES];
|
||||
NLGUI::CDBGroupComboBox *_ChoiceCB[DYNAMIC_MISSION_NUM_CHOICES];
|
||||
// current choice for each group (-1 means that choice has not been made)
|
||||
sint _Choice[DYNAMIC_MISSION_NUM_CHOICES];
|
||||
// For each text ID, true if the text has been received
|
||||
|
|
|
@ -1,616 +0,0 @@
|
|||
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
|
||||
// Copyright (C) 2010 Winch Gate Property Limited
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#include "dbgroup_combo_box.h"
|
||||
#include "nel/gui/group_menu.h"
|
||||
#include "nel/misc/xml_auto_ptr.h"
|
||||
#include "nel/gui/ctrl_button.h"
|
||||
#include "nel/gui/action_handler.h"
|
||||
#include "nel/gui/lua_ihm.h"
|
||||
#include "nel/gui/widget_manager.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace NLMISC;
|
||||
|
||||
NLMISC_REGISTER_OBJECT(CViewBase, CDBGroupComboBox, std::string, "combo_box");
|
||||
|
||||
std::string CDBGroupComboBox::measureMenu;
|
||||
std::string CDBGroupComboBox::selectMenu;
|
||||
std::string CDBGroupComboBox::selectMenuOut;
|
||||
|
||||
// ***************************************************************************
|
||||
CDBGroupComboBox::CDBGroupComboBox(const TCtorParam ¶m)
|
||||
: CInterfaceGroup(param)
|
||||
{
|
||||
_Setuped= false;
|
||||
_ViewText= NULL;
|
||||
_SelectButton= NULL;
|
||||
_LinkedToDB = true;
|
||||
_NotLinkedToDBSelection = 0;
|
||||
_CallingOnChangeActionHandler = false;
|
||||
_IsExternViewText = false;
|
||||
dirt();
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
CDBGroupComboBox::~CDBGroupComboBox()
|
||||
{
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
sint32 CDBGroupComboBox::evalContentWidth() const
|
||||
{
|
||||
// get the menu to open.
|
||||
CGroupMenu *groupMenu= dynamic_cast<CGroupMenu*>(CWidgetManager::getInstance()->getElementFromId( CDBGroupComboBox::measureMenu ));
|
||||
if( !groupMenu )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
fillMenu(groupMenu);
|
||||
groupMenu->setActive(true);
|
||||
groupMenu->updateCoords();
|
||||
sint32 width = groupMenu->getWReal();
|
||||
groupMenu->setActive(false);
|
||||
groupMenu->reset();
|
||||
// add width for the selection arrow
|
||||
return width;
|
||||
}
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
bool CDBGroupComboBox::parse (xmlNodePtr cur, CInterfaceGroup *parentGroup)
|
||||
{
|
||||
if( !CInterfaceGroup::parse(cur, parentGroup) )
|
||||
return false;
|
||||
|
||||
CXMLAutoPtr prop((const char*)xmlGetProp(cur, (xmlChar*)"linked_to_db"));
|
||||
if (prop)
|
||||
{
|
||||
_LinkedToDB = convertBool(prop);
|
||||
}
|
||||
|
||||
if (_LinkedToDB)
|
||||
{
|
||||
// read the selection value
|
||||
CXMLAutoPtr prop((const char*)xmlGetProp(cur, (xmlChar*)"value"));
|
||||
if(!prop)
|
||||
{
|
||||
nlwarning("'value' not found in %s", _Id.c_str());
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_Selection.link((const char*)prop);
|
||||
}
|
||||
}
|
||||
|
||||
// read the sons text
|
||||
xmlNodePtr child;
|
||||
child = cur->children;
|
||||
while (child)
|
||||
{
|
||||
if (stricmp((char*)child->name,"combo_text") == 0)
|
||||
{
|
||||
CXMLAutoPtr name((const char*) xmlGetProp (child, (xmlChar*)"name"));
|
||||
if (name)
|
||||
{
|
||||
const char *propPtr = name;
|
||||
ucstring Text = ucstring::makeFromUtf8(propPtr);
|
||||
if ((strlen(propPtr)>2) && (propPtr[0] == 'u') && (propPtr[1] == 'i'))
|
||||
Text = CI18N::get (propPtr);
|
||||
addText(Text);
|
||||
}
|
||||
}
|
||||
child = child->next;
|
||||
}
|
||||
|
||||
// optional ActionHandler on click
|
||||
prop= xmlGetProp(cur, (xmlChar*)"on_select_start");
|
||||
if(prop) _AHOnSelectStart= (const char*)prop;
|
||||
|
||||
// optional ActionHandler on change
|
||||
prop= xmlGetProp(cur, (xmlChar*)"on_change");
|
||||
if(prop) _AHOnChange= (const char*)prop;
|
||||
|
||||
prop= xmlGetProp(cur, (xmlChar*)"on_change_params");
|
||||
if(prop) _AHOnChangeParams= (const char*)prop;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CDBGroupComboBox::checkCoords ()
|
||||
{
|
||||
if(!_ViewText)
|
||||
return;
|
||||
bool mustUpdate = false;
|
||||
if (_LinkedToDB)
|
||||
{
|
||||
// if some change in texts/selection
|
||||
if(_DirtySelection || _CacheSelection!=_Selection.getSInt32())
|
||||
{
|
||||
_CacheSelection= _Selection.getSInt32();
|
||||
mustUpdate = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// if some change in texts/selection
|
||||
if(_DirtySelection || _CacheSelection != _NotLinkedToDBSelection)
|
||||
{
|
||||
_CacheSelection= _NotLinkedToDBSelection;
|
||||
mustUpdate = true;
|
||||
}
|
||||
}
|
||||
if (mustUpdate)
|
||||
{
|
||||
// change selected text
|
||||
if(_CacheSelection<0 || _CacheSelection>=(sint32)_Texts.size() )
|
||||
{
|
||||
_ViewText->setText(ucstring());
|
||||
}
|
||||
else if(_IsExternViewText)
|
||||
{
|
||||
_ViewText->setText(_ExternViewText);
|
||||
}
|
||||
else
|
||||
{
|
||||
_ViewText->setText(_Texts[_CacheSelection]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CDBGroupComboBox::updateCoords ()
|
||||
{
|
||||
if(!_Setuped)
|
||||
setup();
|
||||
CInterfaceGroup::updateCoords();
|
||||
}
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
void CDBGroupComboBox::dirt()
|
||||
{
|
||||
_DirtySelection= true;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CDBGroupComboBox::resetTexts()
|
||||
{
|
||||
dirt();
|
||||
_Texts.clear();
|
||||
_Textures.clear();
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CDBGroupComboBox::addText(const ucstring &text)
|
||||
{
|
||||
dirt();
|
||||
_Texts.push_back(text);
|
||||
_Textures.push_back(std::string());
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CDBGroupComboBox::setText(uint i, const ucstring &text)
|
||||
{
|
||||
dirt();
|
||||
if(i<_Texts.size())
|
||||
_Texts[i]= text;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CDBGroupComboBox::insertText(uint i, const ucstring &text)
|
||||
{
|
||||
dirt();
|
||||
if(i<_Texts.size())
|
||||
{
|
||||
addText(_Texts[_Texts.size()-1]);
|
||||
|
||||
for(uint t=i; t<_Texts.size()-1; t++)
|
||||
{
|
||||
_Texts[t+1] = _Texts[t];
|
||||
_Textures[t+1] = _Textures[t];
|
||||
}
|
||||
_Texts[i]= text;
|
||||
_Textures[i] = std::string();
|
||||
}
|
||||
else if(i==_Texts.size())
|
||||
addText(text);
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CDBGroupComboBox::setTexture(uint i, const ucstring &texture)
|
||||
{
|
||||
dirt();
|
||||
if(i<_Textures.size())
|
||||
_Textures[i]= texture;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CDBGroupComboBox::removeText(uint i)
|
||||
{
|
||||
dirt();
|
||||
if(i<_Texts.size())
|
||||
{
|
||||
_Texts.erase( _Texts.begin()+i );
|
||||
_Textures.erase( _Textures.begin()+i );
|
||||
}
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
const ucstring &CDBGroupComboBox::getText(uint i) const
|
||||
{
|
||||
static ucstring null;
|
||||
if(i<_Texts.size())
|
||||
return _Texts[i];
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
const ucstring &CDBGroupComboBox::getTexture(uint i) const
|
||||
{
|
||||
static ucstring null;
|
||||
if(i<_Textures.size())
|
||||
return _Textures[i];
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
void CDBGroupComboBox::setSelection(sint32 val)
|
||||
{
|
||||
_IsExternViewText = false;
|
||||
|
||||
if (_LinkedToDB)
|
||||
{
|
||||
_Selection.setSInt32(val);
|
||||
}
|
||||
else
|
||||
{
|
||||
_NotLinkedToDBSelection = val;
|
||||
}
|
||||
if (!_AHOnChange.empty())
|
||||
{
|
||||
if (!_CallingOnChangeActionHandler)
|
||||
{
|
||||
_CallingOnChangeActionHandler = true;
|
||||
CAHManager::getInstance()->runActionHandler (_AHOnChange, this, _AHOnChangeParams);
|
||||
_CallingOnChangeActionHandler = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CDBGroupComboBox::setSelectionNoTrigger(sint32 val)
|
||||
{
|
||||
if (_LinkedToDB)
|
||||
{
|
||||
_Selection.setSInt32(val);
|
||||
}
|
||||
else
|
||||
{
|
||||
_NotLinkedToDBSelection = val;
|
||||
}
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
sint32 CDBGroupComboBox::getSelection() const
|
||||
{
|
||||
if (_LinkedToDB)
|
||||
{
|
||||
return _Selection.getSInt32();
|
||||
}
|
||||
else
|
||||
{
|
||||
return _NotLinkedToDBSelection;
|
||||
}
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CDBGroupComboBox::setSelectionText(const std::string & val)
|
||||
{
|
||||
sint32 value;
|
||||
for(uint i=0; i<getNumTexts(); i++)
|
||||
{
|
||||
std::string sText;
|
||||
getText(i).toString(sText);
|
||||
if(sText == val)
|
||||
{
|
||||
value = i;
|
||||
setSelection(value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CDBGroupComboBox::setViewText(const ucstring & text)
|
||||
{
|
||||
_IsExternViewText = true;
|
||||
_ExternViewText = ucstring(text);
|
||||
_ViewText->setText(_ExternViewText);
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
ucstring CDBGroupComboBox::getViewText() const
|
||||
{
|
||||
return _ViewText->getText();
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
std::string CDBGroupComboBox::getSelectionText() const
|
||||
{
|
||||
ucstring text;
|
||||
if (_LinkedToDB)
|
||||
{
|
||||
text = getText(_Selection.getSInt32());
|
||||
}
|
||||
else
|
||||
{
|
||||
text = getText(_NotLinkedToDBSelection);
|
||||
}
|
||||
std::string texteS;
|
||||
text.toString(texteS);
|
||||
return texteS;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CDBGroupComboBox::setup()
|
||||
{
|
||||
_Setuped= true;
|
||||
|
||||
// get the viewText
|
||||
_ViewText= dynamic_cast<CViewText*>(CInterfaceGroup::getView("text"));
|
||||
// get the button
|
||||
_SelectButton= dynamic_cast<CCtrlBaseButton*>(CInterfaceGroup::getCtrl("select"));
|
||||
|
||||
// force the action handler
|
||||
if( _SelectButton )
|
||||
_SelectButton->setActionOnLeftClick("combo_box_select_start");
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
int CDBGroupComboBox::luaRemoveSelection(CLuaState &ls)
|
||||
{
|
||||
CLuaIHM::checkArgCount(ls, "removeSelection", 1);
|
||||
sint32 value;
|
||||
if(CLuaIHM::popSINT32(ls, value))
|
||||
{
|
||||
removeText(value);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CDBGroupComboBox::luaRemoveText(CLuaState &ls)
|
||||
{
|
||||
CLuaIHM::checkArgCount(ls, "removeText", 1);
|
||||
CLuaIHM::checkArgType(ls, "removeText", 1, LUA_TSTRING);
|
||||
std::string text = ls.toString(1);
|
||||
sint32 value;
|
||||
for(uint i=0; i<getNumTexts(); i++)
|
||||
{
|
||||
std::string sText;
|
||||
getText(i).toString(sText);
|
||||
if(sText == text)
|
||||
{
|
||||
value = i;
|
||||
removeText(value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CDBGroupComboBox::luaResetTexts(CLuaState &ls)
|
||||
{
|
||||
CLuaIHM::checkArgCount(ls, "resetTexts", 0);
|
||||
resetTexts();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CDBGroupComboBox::luaAddText(CLuaState &ls)
|
||||
{
|
||||
const char *funcName = "addText";
|
||||
CLuaIHM::checkArgCount(ls, funcName, 1);
|
||||
CLuaIHM::checkArgTypeUCString(ls, funcName, 1);
|
||||
ucstring text;
|
||||
nlverify(CLuaIHM::pop(ls, text));
|
||||
addText(text);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CDBGroupComboBox::luaSetText(CLuaState &ls)
|
||||
{
|
||||
const char *funcName = "setText";
|
||||
CLuaIHM::checkArgCount(ls, funcName, 2);
|
||||
CLuaIHM::checkArgType(ls, funcName, 1, LUA_TNUMBER);
|
||||
CLuaIHM::checkArgTypeUCString(ls, funcName, 2);
|
||||
ucstring text;
|
||||
nlverify(CLuaIHM::pop(ls, text));
|
||||
setText((uint) ls.toNumber(1), text);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CDBGroupComboBox::luaInsertText(CLuaState &ls)
|
||||
{
|
||||
const char *funcName = "insertText";
|
||||
CLuaIHM::checkArgCount(ls, funcName, 2);
|
||||
CLuaIHM::checkArgType(ls, funcName, 1, LUA_TNUMBER);
|
||||
CLuaIHM::checkArgTypeUCString(ls, funcName, 2);
|
||||
ucstring text;
|
||||
nlverify(CLuaIHM::pop(ls, text));
|
||||
insertText((uint) ls.toNumber(1), text);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CDBGroupComboBox::luaSetTexture(CLuaState &ls)
|
||||
{
|
||||
const char *funcName = "setTexture";
|
||||
CLuaIHM::checkArgCount(ls, funcName, 2);
|
||||
CLuaIHM::checkArgType(ls, funcName, 1, LUA_TNUMBER);
|
||||
CLuaIHM::checkArgTypeUCString(ls, funcName, 2);
|
||||
ucstring texture;
|
||||
nlverify(CLuaIHM::pop(ls, texture));
|
||||
setTexture((uint) ls.toNumber(1), texture);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CDBGroupComboBox::luaGetText(CLuaState &ls)
|
||||
{
|
||||
const char *funcName = "setText";
|
||||
CLuaIHM::checkArgCount(ls, funcName, 1);
|
||||
CLuaIHM::checkArgType(ls, funcName, 1, LUA_TNUMBER);
|
||||
CLuaIHM::push(ls, getText((uint) ls.toNumber(1)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CDBGroupComboBox::luaRemoveTextByIndex(CLuaState &ls)
|
||||
{
|
||||
const char *funcName = "removeText";
|
||||
CLuaIHM::checkArgCount(ls, funcName, 1);
|
||||
CLuaIHM::checkArgType(ls, funcName, 1, LUA_TNUMBER);
|
||||
removeText((uint) ls.toNumber(1));
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
int CDBGroupComboBox::luaGetNumTexts(CLuaState &ls)
|
||||
{
|
||||
const char *funcName = "getNumTexts";
|
||||
CLuaIHM::checkArgCount(ls, funcName, 0);
|
||||
ls.push((double) getNumTexts());
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CDBGroupComboBox::fillMenu(CGroupMenu *groupMenu) const
|
||||
{
|
||||
nlassert(groupMenu);
|
||||
|
||||
// Setup the menu with combo action.
|
||||
groupMenu->reset();
|
||||
for(uint i=0; i<getNumTexts(); i++)
|
||||
{
|
||||
// set the id as the parameter
|
||||
bool checkable = false;
|
||||
if(getTexture(i).toString() != std::string())
|
||||
{
|
||||
checkable = true;
|
||||
}
|
||||
groupMenu->addLine(getText(i), "combo_box_select_end", toString(i),
|
||||
"", std::string(), getTexture(i).toString(), checkable);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
class CHandlerComboBoxSelectStart : public IActionHandler
|
||||
{
|
||||
public:
|
||||
virtual void execute (CCtrlBase *pCaller, const std::string &/* Params */)
|
||||
{
|
||||
CDBGroupComboBox *pCB = dynamic_cast<CDBGroupComboBox*>(pCaller->getParent());
|
||||
if (pCB == NULL) return;
|
||||
// if no choice, return.
|
||||
if( pCB->getNumTexts()==0 )
|
||||
return;
|
||||
|
||||
// get the menu to open.
|
||||
CGroupMenu *groupMenu= dynamic_cast<CGroupMenu*>(CWidgetManager::getInstance()->getElementFromId( CDBGroupComboBox::selectMenu ));
|
||||
if( !groupMenu )
|
||||
{
|
||||
groupMenu= dynamic_cast<CGroupMenu*>(CWidgetManager::getInstance()->getElementFromId( CDBGroupComboBox::selectMenuOut ));
|
||||
}
|
||||
if( !groupMenu )
|
||||
return;
|
||||
|
||||
pCB->fillMenu(groupMenu);
|
||||
|
||||
groupMenu->setMaxVisibleLine(8);
|
||||
|
||||
// pos and size wisely the menu.
|
||||
groupMenu->setMinW(pCB->getWReal());
|
||||
groupMenu->setX(pCB->getXReal());
|
||||
groupMenu->setBaseX(pCB->getXReal());
|
||||
groupMenu->setY(pCB->getYReal());
|
||||
groupMenu->setBaseY(pCB->getYReal());
|
||||
|
||||
// Must ensure the combo menu has same windows priority than the combo box window
|
||||
CInterfaceGroup *rootWin= pCB->getRootWindow();
|
||||
if(rootWin)
|
||||
groupMenu->setPriority(rootWin->getPriority());
|
||||
|
||||
// After menu init, Call user activation method
|
||||
if( !pCB->_AHOnSelectStart.empty() )
|
||||
{
|
||||
CAHManager::getInstance()->runActionHandler(pCB->_AHOnSelectStart, pCB);
|
||||
}
|
||||
|
||||
// launch the menu
|
||||
// if the combo box is in a modal, must do a push, else just replace
|
||||
if(dynamic_cast<CGroupModal*>(pCB->getRootWindow()))
|
||||
{
|
||||
groupMenu->setCloseSubMenuUsingPopModal(true);
|
||||
CWidgetManager::getInstance()->pushModalWindow(pCB, groupMenu);
|
||||
}
|
||||
else
|
||||
{
|
||||
groupMenu->setCloseSubMenuUsingPopModal(false);
|
||||
CWidgetManager::getInstance()->enableModalWindow (pCB, groupMenu);
|
||||
}
|
||||
}
|
||||
};
|
||||
REGISTER_ACTION_HANDLER (CHandlerComboBoxSelectStart, "combo_box_select_start");
|
||||
|
||||
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
class CHandlerComboBoxSelectEnd : public IActionHandler
|
||||
{
|
||||
public:
|
||||
virtual void execute (CCtrlBase * /* pCaller */, const std::string &Params)
|
||||
{
|
||||
CDBGroupComboBox *pCB = dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getCtrlLaunchingModal());
|
||||
if (pCB == NULL) return;
|
||||
|
||||
// set the selection
|
||||
sint32 selection;
|
||||
fromString(Params, selection);
|
||||
pCB->setSelection(selection);
|
||||
}
|
||||
};
|
||||
REGISTER_ACTION_HANDLER (CHandlerComboBoxSelectEnd, "combo_box_select_end");
|
||||
|
||||
|
|
@ -1,162 +0,0 @@
|
|||
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
|
||||
// Copyright (C) 2010 Winch Gate Property Limited
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
|
||||
#ifndef NL_DBGROUP_COMBO_BOX_H
|
||||
#define NL_DBGROUP_COMBO_BOX_H
|
||||
|
||||
#include "nel/misc/types_nl.h"
|
||||
#include "nel/gui/interface_group.h"
|
||||
|
||||
namespace NLGUI
|
||||
{
|
||||
class CCtrlBaseButton;
|
||||
class CViewText;
|
||||
class CGroupMenu;
|
||||
}
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
/**
|
||||
* Widget: ComboBox of text
|
||||
* \author Lionel Berenguier
|
||||
* \author Nevrax France
|
||||
* \date 2002
|
||||
*/
|
||||
class CDBGroupComboBox : public CInterfaceGroup
|
||||
{
|
||||
public:
|
||||
|
||||
/// Constructor
|
||||
CDBGroupComboBox(const TCtorParam ¶m);
|
||||
~CDBGroupComboBox();
|
||||
|
||||
/// CInterfaceGroup Interface
|
||||
virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup);
|
||||
virtual void updateCoords ();
|
||||
virtual void checkCoords ();
|
||||
|
||||
// Combo Texts
|
||||
void resetTexts();
|
||||
void addText(const ucstring &text);
|
||||
void setText(uint i, const ucstring &text);
|
||||
void insertText(uint i, const ucstring &text);
|
||||
const ucstring &getText(uint i) const;
|
||||
const ucstring &getTexture(uint i) const;
|
||||
void removeText(uint i);
|
||||
uint getNumTexts() const {return (uint)_Texts.size();}
|
||||
|
||||
// selection
|
||||
void setSelection(sint32 val);
|
||||
void setSelectionNoTrigger(sint32 val);
|
||||
sint32 getSelection() const;
|
||||
|
||||
// selection number
|
||||
void setSelectionNb(sint32 /* val */){}
|
||||
sint32 getSelectionNb() const {return (sint32)_Texts.size();}
|
||||
|
||||
// selection text
|
||||
void setSelectionText(const std::string & val);
|
||||
std::string getSelectionText() const;
|
||||
|
||||
// view text
|
||||
void setViewText(const ucstring & text);
|
||||
ucstring getViewText() const;
|
||||
|
||||
void setTexture(uint i, const ucstring &texture);
|
||||
|
||||
sint32 evalContentWidth() const;
|
||||
|
||||
|
||||
int luaAddText(CLuaState &ls);
|
||||
int luaRemoveSelection(CLuaState &ls);
|
||||
int luaRemoveText(CLuaState &ls);
|
||||
int luaRemoveTextByIndex(CLuaState &ls);
|
||||
int luaResetTexts(CLuaState &ls);
|
||||
int luaSetText(CLuaState &ls);
|
||||
int luaInsertText(CLuaState &ls);
|
||||
int luaGetText(CLuaState &ls);
|
||||
int luaGetNumTexts(CLuaState &ls);
|
||||
int luaSetTexture(CLuaState &ls);
|
||||
|
||||
|
||||
REFLECT_EXPORT_START(CDBGroupComboBox, CInterfaceGroup)
|
||||
REFLECT_SINT32("selection", getSelection, setSelection)
|
||||
REFLECT_LUA_METHOD("addText", luaAddText)
|
||||
REFLECT_LUA_METHOD("setText", luaSetText)
|
||||
REFLECT_LUA_METHOD("insertText", luaInsertText)
|
||||
REFLECT_LUA_METHOD("setTexture", luaSetTexture)
|
||||
REFLECT_LUA_METHOD("getText", luaGetText)
|
||||
REFLECT_LUA_METHOD("getNumTexts", luaGetNumTexts)
|
||||
REFLECT_LUA_METHOD("removeSelection", luaRemoveSelection)
|
||||
REFLECT_LUA_METHOD("removeText", luaRemoveText)
|
||||
REFLECT_LUA_METHOD("removeTextByIndex", luaRemoveTextByIndex)
|
||||
REFLECT_LUA_METHOD("resetTexts", luaResetTexts)
|
||||
REFLECT_SINT32 ("selectionNb", getSelectionNb, setSelectionNb)
|
||||
REFLECT_STRING ("selection_text", getSelectionText, setSelectionText)
|
||||
REFLECT_UCSTRING ("view_text", getViewText, setViewText)
|
||||
REFLECT_EXPORT_END
|
||||
|
||||
|
||||
protected:
|
||||
friend class CHandlerComboBoxSelectStart;
|
||||
|
||||
bool _LinkedToDB; // if not linked to db, then _NotLinkedToDBSelection is used instead
|
||||
bool _Setuped;
|
||||
bool _DirtySelection;
|
||||
sint32 _CacheSelection;
|
||||
|
||||
// sint32
|
||||
CInterfaceProperty _Selection;
|
||||
sint32 _NotLinkedToDBSelection;
|
||||
std::vector<ucstring> _Texts;
|
||||
std::vector<ucstring> _Textures;
|
||||
|
||||
// Action Handler called on combo click
|
||||
std::string _AHOnSelectStart;
|
||||
|
||||
// Action handler called when the content is changed
|
||||
std::string _AHOnChange;
|
||||
std::string _AHOnChangeParams;
|
||||
bool _CallingOnChangeActionHandler; // avoid infinite loop here
|
||||
|
||||
|
||||
// Children
|
||||
CViewText *_ViewText;
|
||||
CCtrlBaseButton *_SelectButton;
|
||||
|
||||
bool _IsExternViewText;
|
||||
ucstring _ExternViewText;
|
||||
|
||||
|
||||
private:
|
||||
void setup();
|
||||
void dirt();
|
||||
public:
|
||||
// private : fill a menu with current content
|
||||
void fillMenu(CGroupMenu *groupMenu) const;
|
||||
|
||||
|
||||
static std::string measureMenu;
|
||||
static std::string selectMenu;
|
||||
static std::string selectMenuOut;
|
||||
};
|
||||
|
||||
|
||||
#endif // NL_DBGROUP_COMBO_BOX_H
|
||||
|
||||
/* End of dbgroup_combo_box.h */
|
|
@ -42,7 +42,7 @@ extern "C"
|
|||
#include "interface_manager.h"
|
||||
#include "nel/gui/view_bitmap.h"
|
||||
#include "../actions.h"
|
||||
#include "dbgroup_combo_box.h"
|
||||
#include "nel/gui/dbgroup_combo_box.h"
|
||||
#include "nel/gui/lua_ihm.h"
|
||||
|
||||
#include "../time_client.h"
|
||||
|
|
|
@ -42,9 +42,9 @@ namespace NLGUI
|
|||
class CCtrlButton;
|
||||
class CCtrlScroll;
|
||||
class CGroupList;
|
||||
class CDBGroupComboBox;
|
||||
}
|
||||
|
||||
class CDBGroupComboBox;
|
||||
class CGroupParagraph;
|
||||
|
||||
// HTML group
|
||||
|
|
|
@ -87,7 +87,7 @@
|
|||
// DBGroup
|
||||
#include "nel/gui/dbgroup_select_number.h"
|
||||
#include "dbgroup_list_sheet.h"
|
||||
#include "dbgroup_combo_box.h"
|
||||
#include "nel/gui/dbgroup_combo_box.h"
|
||||
#include "dbgroup_list_sheet_trade.h"
|
||||
#include "dbgroup_list_sheet_mission.h"
|
||||
#include "guild_manager.h" // for CDBGroupListAscensor
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include "nel/gui/ctrl_button.h"
|
||||
#include "nel/gui/group_editbox.h"
|
||||
#include "nel/gui/group_list.h"
|
||||
#include "dbgroup_combo_box.h"
|
||||
#include "nel/gui/dbgroup_combo_box.h"
|
||||
#include "nel/gui/group_container.h"
|
||||
#include "group_modal_get_key.h"
|
||||
#include "nel/gui/interface_expr.h"
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#include "nel/gui/ctrl_button.h"
|
||||
#include "nel/gui/group_editbox.h"
|
||||
#include "nel/gui/group_list.h"
|
||||
#include "dbgroup_combo_box.h"
|
||||
#include "nel/gui/dbgroup_combo_box.h"
|
||||
#include "nel/gui/group_container.h"
|
||||
#include "group_modal_get_key.h"
|
||||
#include "task_bar_manager.h"
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
#include "nel/gui/dbview_bar3.h"
|
||||
#include "nel/gui/ctrl_scroll_base.h"
|
||||
#include "nel/gui/ctrl_scroll.h"
|
||||
#include "dbgroup_combo_box.h"
|
||||
#include "nel/gui/dbgroup_combo_box.h"
|
||||
#include "nel/gui/group_tab.h"
|
||||
#include "group_html.h"
|
||||
#include "nel/gui/group_header.h"
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include "nel/misc/cdb_leaf.h"
|
||||
#include "nel/gui/action_handler.h"
|
||||
#include "sbrick_manager.h"
|
||||
#include "dbgroup_combo_box.h"
|
||||
#include "nel/gui/dbgroup_combo_box.h"
|
||||
#include "nel/gui/view_bitmap.h"
|
||||
#include "../net_manager.h"
|
||||
#include "sbrick_manager.h"
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
#include "nel/gui/view_text.h"
|
||||
#include "nel/gui/ctrl_button.h"
|
||||
#include "nel/gui/ctrl_text_button.h"
|
||||
#include "interface_v3/dbgroup_combo_box.h"
|
||||
#include "nel/gui/dbgroup_combo_box.h"
|
||||
#include "sound_manager.h"
|
||||
#include "far_tp.h"
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include "../interface_v3/interface_manager.h"
|
||||
#include "nel/gui/group_container.h"
|
||||
#include "displayer_visual_entity.h"
|
||||
#include "../interface_v3/dbgroup_combo_box.h"
|
||||
#include "nel/gui/dbgroup_combo_box.h"
|
||||
|
||||
#include "../sheet_manager.h"
|
||||
|
||||
|
|
Loading…
Reference in a new issue