forked from 0ad/0ad
Remove focus from chat box after sending message
This was SVN commit r7931.
This commit is contained in:
parent
6c7b82130c
commit
2deac598eb
@ -68,6 +68,9 @@ function submitChatInput()
|
||||
addChatMessage({ "type": "message", "username": g_Players[1].name, "text": text });
|
||||
|
||||
input.caption = "";
|
||||
|
||||
// Remove focus
|
||||
input.blur();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,29 +149,17 @@ InReaction CGUI::HandleEvent(const SDL_Event_* ev)
|
||||
switch (ev->ev.button.button)
|
||||
{
|
||||
case SDL_BUTTON_LEFT:
|
||||
// Focus the clicked object (or focus none if nothing clicked on)
|
||||
SetFocusedObject(pNearest);
|
||||
|
||||
if (pNearest)
|
||||
{
|
||||
if (pNearest != m_FocusedObject)
|
||||
{
|
||||
// Update focused object
|
||||
if (m_FocusedObject)
|
||||
m_FocusedObject->HandleMessage(SGUIMessage(GUIM_LOST_FOCUS));
|
||||
m_FocusedObject = pNearest;
|
||||
m_FocusedObject->HandleMessage(SGUIMessage(GUIM_GOT_FOCUS));
|
||||
}
|
||||
|
||||
pNearest->HandleMessage(SGUIMessage(GUIM_MOUSE_PRESS_LEFT));
|
||||
pNearest->ScriptEvent("mouseleftpress");
|
||||
|
||||
// Block event, so things on the map (behind the GUI) won't be pressed
|
||||
ret = IN_HANDLED;
|
||||
}
|
||||
else if (m_FocusedObject)
|
||||
{
|
||||
m_FocusedObject->HandleMessage(SGUIMessage(GUIM_LOST_FOCUS));
|
||||
//if (m_FocusedObject-> TODO SelfishFocus?
|
||||
m_FocusedObject = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_BUTTON_WHEELDOWN: // wheel down
|
||||
@ -535,6 +523,19 @@ IGUIObject* CGUI::FindObjectByName(const CStr& Name) const
|
||||
return it->second;
|
||||
}
|
||||
|
||||
void CGUI::SetFocusedObject(IGUIObject* pObject)
|
||||
{
|
||||
if (pObject == m_FocusedObject)
|
||||
return;
|
||||
|
||||
if (m_FocusedObject)
|
||||
m_FocusedObject->HandleMessage(SGUIMessage(GUIM_LOST_FOCUS));
|
||||
|
||||
m_FocusedObject = pObject;
|
||||
|
||||
if (m_FocusedObject)
|
||||
m_FocusedObject->HandleMessage(SGUIMessage(GUIM_GOT_FOCUS));
|
||||
}
|
||||
|
||||
// private struct used only in GenerateText(...)
|
||||
struct SGenerateTextImage
|
||||
|
@ -311,6 +311,15 @@ private:
|
||||
*/
|
||||
IGUIObject *GetFocusedObject() { return m_FocusedObject; }
|
||||
|
||||
public:
|
||||
/**
|
||||
* Change focus to new object.
|
||||
* Will send LOST_FOCUS/GOT_FOCUS messages as appropriate.
|
||||
* pObject can be NULL to remove all focus.
|
||||
*/
|
||||
void SetFocusedObject(IGUIObject* pObject);
|
||||
|
||||
private:
|
||||
//--------------------------------------------------------
|
||||
/** @name XML Reading Xeromyces specific subroutines
|
||||
*
|
||||
|
@ -375,9 +375,6 @@ protected:
|
||||
*/
|
||||
virtual float GetBufferedZ() const;
|
||||
|
||||
// This is done internally
|
||||
CGUI *GetGUI() { return m_pGUI; }
|
||||
const CGUI *GetGUI() const { return m_pGUI; }
|
||||
void SetGUI(CGUI * const &pGUI) { m_pGUI = pGUI; }
|
||||
|
||||
// Set parent
|
||||
@ -389,6 +386,9 @@ protected:
|
||||
}
|
||||
|
||||
public:
|
||||
CGUI *GetGUI() { return m_pGUI; }
|
||||
const CGUI *GetGUI() const { return m_pGUI; }
|
||||
|
||||
/**
|
||||
* Take focus!
|
||||
*/
|
||||
|
@ -48,6 +48,7 @@ JSFunctionSpec JSI_IGUIObject::JSI_methods[] =
|
||||
{
|
||||
{ "toString", JSI_IGUIObject::toString, 0, 0, 0 },
|
||||
{ "focus", JSI_IGUIObject::focus, 0, 0, 0 },
|
||||
{ "blur", JSI_IGUIObject::blur, 0, 0, 0 },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
@ -63,7 +64,8 @@ JSBool JSI_IGUIObject::getProperty(JSContext* cx, JSObject* obj, jsval id, jsval
|
||||
if (propName == "constructor" ||
|
||||
propName == "prototype" ||
|
||||
propName == "toString" ||
|
||||
propName == "focus"
|
||||
propName == "focus" ||
|
||||
propName == "blur"
|
||||
)
|
||||
return JS_TRUE;
|
||||
|
||||
@ -580,11 +582,18 @@ JSBool JSI_IGUIObject::toString(JSContext* cx, JSObject* obj, uintN UNUSED(argc)
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JSBool JSI_IGUIObject::focus(JSContext* cx, JSObject* obj, uintN UNUSED(argc), jsval* UNUSED(argv), jsval* rval)
|
||||
JSBool JSI_IGUIObject::focus(JSContext* cx, JSObject* obj, uintN UNUSED(argc), jsval* UNUSED(argv), jsval* UNUSED(rval))
|
||||
{
|
||||
IGUIObject* e = (IGUIObject*)JS_GetPrivate( cx, obj );
|
||||
|
||||
e->SetFocus();
|
||||
e->HandleMessage(SGUIMessage(GUIM_GOT_FOCUS));
|
||||
e->GetGUI()->SetFocusedObject(e);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JSBool JSI_IGUIObject::blur(JSContext* cx, JSObject* obj, uintN UNUSED(argc), jsval* UNUSED(argv), jsval* UNUSED(rval))
|
||||
{
|
||||
IGUIObject* e = (IGUIObject*)JS_GetPrivate( cx, obj );
|
||||
|
||||
e->GetGUI()->SetFocusedObject(NULL);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ namespace JSI_IGUIObject
|
||||
JSBool construct(JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval);
|
||||
JSBool toString(JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval);
|
||||
JSBool focus(JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval);
|
||||
JSBool blur(JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval);
|
||||
void init();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user