From: John L. <jr...@us...> - 2006-05-25 03:55:34
|
Update of /cvsroot/wxlua/wxLua/bindings/wxwidgets In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv10746/wxLua/bindings/wxwidgets Modified Files: event.i override.hpp Log Message: changed wxEvtHandler::ConnectEvent to Connect update all samples to reflect this add win id ranges to connect add untested wxEvtHandler::Disconnect Index: event.i =================================================================== RCS file: /cvsroot/wxlua/wxLua/bindings/wxwidgets/event.i,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** event.i 18 May 2006 05:47:39 -0000 1.14 --- event.i 25 May 2006 03:55:22 -0000 1.15 *************** *** 18,27 **** void AddPendingEvent(wxEvent& event) ! // %override wxEvtHandler::ConnectEvent(int id, wxEventType eventType, lua function) ! // %override wxEvtHandler::ConnectEvent(wxEventType eventType, lua function) ! void ConnectEvent() ! //bool Disconnect(wxEventType eventType = wxEVT_NULL, wxObjectEventFunction function = NULL, wxObject* userData = NULL, wxEvtHandler* eventSink = NULL) ! //bool Disconnect(int id = wxID_ANY, wxEventType eventType = wxEVT_NULL, wxObjectEventFunction function = NULL, wxObject* userData = NULL, wxEvtHandler* eventSink = NULL) //void* GetClientData() --- 18,33 ---- void AddPendingEvent(wxEvent& event) ! // NOTE: Connect used to be called ConnectEvent which is not the name of any C++ function. ! // %override wxEvtHandler::Connect(int id, int lastId, wxEventType eventType, lua function) ! // %override wxEvtHandler::Connect(int id, wxEventType eventType, lua function) ! // %override wxEvtHandler::Connect(wxEventType eventType, lua function) ! // Note: wxLua uses the userdata and the event sink and so they're not available ! void Connect(int id, int lastId, wxEventType eventType, LuaFunction func) ! ! // %override bool Disconnect(int winid, int lastId, wxEventType eventType) ! // %override bool Disconnect(int winid, wxEventType eventType) ! // %override bool Disconnect(wxEventType eventType) ! bool Disconnect(int id, int lastId, wxEventType eventType) //void* GetClientData() Index: override.hpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/bindings/wxwidgets/override.hpp,v retrieving revision 1.44 retrieving revision 1.45 diff -C2 -d -r1.44 -r1.45 *** override.hpp 24 May 2006 16:56:45 -0000 1.44 --- override.hpp 25 May 2006 03:55:22 -0000 1.45 *************** *** 1646,1651 **** %end ! %override wxLua_wxEvtHandler_ConnectEvent ! // void ConnectEvent() #include "wxlua/include/wxlcallb.h" --- 1646,1651 ---- %end ! %override wxLua_wxEvtHandler_Connect ! // void Connect(int id, int lastId, wxEventType eventType, LuaFunction func) #include "wxlua/include/wxlcallb.h" *************** *** 1659,1663 **** // which is a reference to the event object // associated with the event. ! static int LUACALL wxLua_wxEvtHandler_ConnectEvent(lua_State *L) { wxCHECK_MSG(s_wxluatag_wxEvtHandler != -1, 0, wxT("wxEvtHandler is not wrapped by wxLua")); --- 1659,1663 ---- // which is a reference to the event object // associated with the event. ! static int LUACALL wxLua_wxEvtHandler_Connect(lua_State *L) { wxCHECK_MSG(s_wxluatag_wxEvtHandler != -1, 0, wxT("wxEvtHandler is not wrapped by wxLua")); *************** *** 1665,1670 **** wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); ! int id; ! double eventType = 0; wxLuaCallback *pCallback = NULL; --- 1665,1671 ---- wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); ! int winId = wxID_ANY; ! int lastId = wxID_ANY; ! int eventType = 0; wxLuaCallback *pCallback = NULL; *************** *** 1673,1691 **** wxEvtHandler *evtHandler = (wxEvtHandler *)wxlState.GetUserDataType(1, s_wxluatag_wxEvtHandler); switch (nParams) { ! case 4: { ! if (!lua_isfunction(L, 4)) ! { ! wxlState.terror("wxLua: ConnectEvent: Callback function is not a valid Lua function for parameter 3."); ! return 0; ! } if (wxlState.IsNumberType(3)) ! eventType = lua_tonumber(L, 3); else { ! wxlState.terror(wxString::Format(wxT("wxLua: ConnectEvent: Invalid event type, expected a number for parameter 2, got '%s'."), wxlState.lua_TypeNameIndex(3).c_str())); return 0; --- 1674,1692 ---- wxEvtHandler *evtHandler = (wxEvtHandler *)wxlState.GetUserDataType(1, s_wxluatag_wxEvtHandler); + int func_idx = 0; + int evttype_idx = 0; + switch (nParams) { ! case 5: { ! func_idx = 5; ! evttype_idx = 4; if (wxlState.IsNumberType(3)) ! lastId = (int)lua_tonumber(L, 3); else { ! wxlState.terror(wxString::Format(wxT("wxLua: Connect: Invalid lastId, expected a number for parameter 2, got '%s'."), wxlState.lua_TypeNameIndex(3).c_str())); return 0; *************** *** 1693,1741 **** if (wxlState.IsNumberType(2)) ! id = (int)lua_tonumber(L, 2); else { ! wxlState.terror(wxString::Format(wxT("wxLua: ConnectEvent: Invalid id, expected a number for parameter 1, got '%s'."), ! wxlState.lua_TypeNameIndex(3).c_str())); return 0; } - // Create and connect the callback - pCallback = new wxLuaCallback(wxlState, 4, id, (int) eventType, evtHandler); - break; } ! case 3: { ! if (!lua_isfunction(L, 3)) { ! wxlState.terror("wxLua: ConnectEvent: Callback function is not a valid Lua function for parameter 2."); return 0; } if (evtHandler->IsKindOf(CLASSINFO(wxWindow))) { // FIXME! bug in Mac this is the fix ! #if defined(__WXMAC__) && !wxCHECK_VERSION(2,6,0) ! id = -1; ! #else ! id = ((wxWindow *)evtHandler)->GetId(); #endif } else { ! wxlState.terror("wxLua: ConnectEvent: Unexpected event object type, expected a wxWindow."); return 0; } if (wxlState.IsNumberType(2)) { ! eventType = lua_tonumber(L, 2); ! // Create and connect the callback ! pCallback = new wxLuaCallback(wxlState, 3, id, (int) eventType, evtHandler); } else { ! wxlState.terror(wxString::Format(wxT("wxLua: ConnectEvent: Invalid event type, expected a number for parameter 1, got '%s'."), wxlState.lua_TypeNameIndex(2).c_str())); return 0; --- 1694,1830 ---- if (wxlState.IsNumberType(2)) ! winId = (int)lua_tonumber(L, 2); else { ! wxlState.terror(wxString::Format(wxT("wxLua: Connect: Invalid winId, expected a number for parameter 1, got '%s'."), ! wxlState.lua_TypeNameIndex(2).c_str())); return 0; } break; } ! case 4: { ! func_idx = 4; ! evttype_idx = 3; ! ! if (wxlState.IsNumberType(2)) ! winId = (int)lua_tonumber(L, 2); ! else { ! wxlState.terror(wxString::Format(wxT("wxLua: Connect: Invalid id, expected a number for parameter 1, got '%s'."), ! wxlState.lua_TypeNameIndex(2).c_str())); return 0; } + break; + } + case 3: + { + func_idx = 3; + evttype_idx = 2; + /* + // Is this right? wxWidgets just uses wxID_ANY for no winId overload if (evtHandler->IsKindOf(CLASSINFO(wxWindow))) { // FIXME! bug in Mac this is the fix ! #if !defined(__WXMAC__) || wxCHECK_VERSION(2,6,0) ! winId = ((wxWindow *)evtHandler)->GetId(); ! wxPrintf(wxT("winId %d\n"), winId); #endif } else { ! wxlState.terror("wxLua: Connect: Unexpected event object type, expected a wxWindow."); ! return 0; ! } ! */ ! break; ! } ! default: ! { ! wxlState.terror("wxLua: Connect: Incorrect number of parameters."); ! return 0; ! } ! } ! ! if (!lua_isfunction(L, func_idx)) ! { ! wxlState.terror(wxString::Format(wxT("wxLua: Connect: Callback function is not a valid Lua function for parameter %d."), ! func_idx-1)); // -1 for self ! return 0; ! } ! ! if (wxlState.IsNumberType(evttype_idx)) ! eventType = lua_tonumber(L, evttype_idx); ! else ! { ! wxlState.terror(wxString::Format(wxT("wxLua: Connect: Invalid event type, expected a number for parameter %d, got '%s'."), ! evttype_idx - 1, wxlState.lua_TypeNameIndex(evttype_idx).c_str())); ! return 0; ! } ! ! // Create and connect the callback ! pCallback = new wxLuaCallback(wxlState, nParams, winId, lastId, eventType, evtHandler); ! ! return 0; ! } ! %end ! ! %override wxLua_wxEvtHandler_Disconnect ! // void Disconnect(int id, int lastId, wxEventType eventType) ! ! #include "wxlua/include/wxlcallb.h" ! static int LUACALL wxLua_wxEvtHandler_Disconnect(lua_State *L) ! { ! wxCHECK_MSG(s_wxluatag_wxEvtHandler != -1, 0, wxT("wxEvtHandler is not wrapped by wxLua")); ! wxLuaState wxlState(L); ! wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); ! ! int winId = wxID_ANY; ! int lastId = wxID_ANY; ! int eventType = 0; ! ! int nParams = lua_gettop(L); ! ! wxEvtHandler *evtHandler = (wxEvtHandler *)wxlState.GetUserDataType(1, s_wxluatag_wxEvtHandler); ! ! int evttype_idx = 0; ! ! switch (nParams) ! { ! case 4: ! { ! evttype_idx = 4; ! ! if (wxlState.IsNumberType(3)) ! lastId = (int)lua_tonumber(L, 3); ! else ! { ! wxlState.terror(wxString::Format(wxT("wxLua: Disconnect: Invalid lastId, expected a number for parameter 2, got '%s'."), ! wxlState.lua_TypeNameIndex(3).c_str())); return 0; } if (wxlState.IsNumberType(2)) + winId = (int)lua_tonumber(L, 2); + else { ! wxlState.terror(wxString::Format(wxT("wxLua: Disconnect: Invalid winId, expected a number for parameter 1, got '%s'."), ! wxlState.lua_TypeNameIndex(2).c_str())); ! return 0; } + + break; + } + case 3: + { + evttype_idx = 3; + + if (wxlState.IsNumberType(2)) + winId = (int)lua_tonumber(L, 2); else { ! wxlState.terror(wxString::Format(wxT("wxLua: Disconnect: Invalid id, expected a number for parameter 1, got '%s'."), wxlState.lua_TypeNameIndex(2).c_str())); return 0; *************** *** 1744,1754 **** break; } ! default: { ! wxlState.terror("wxLua: ConnectEvent: Incorrect number of parameters."); break; } } ! return 0; } %end --- 1833,1863 ---- break; } ! case 2: { ! evttype_idx = 2; ! break; } + default: + { + wxlState.terror("wxLua: Disconnect: Incorrect number of parameters."); + return 0; + } } ! ! if (wxlState.IsNumberType(evttype_idx)) ! eventType = lua_tonumber(L, evttype_idx); ! else ! { ! wxlState.terror(wxString::Format(wxT("wxLua: ConnectEvent: Invalid event type, expected a number for parameter %d, got '%s'."), ! evttype_idx - 1, wxlState.lua_TypeNameIndex(evttype_idx).c_str())); ! return 0; ! } ! ! // Try to disconnect from the callback ! bool returns = evtHandler->Disconnect(winId, lastId, eventType, (wxObjectEventFunction)&wxLuaCallback::EventHandler); ! ! lua_pushboolean(L, returns); ! return 1; } %end |