From: John L. <jr...@us...> - 2006-05-25 03:55:34
|
Update of /cvsroot/wxlua/wxLua/modules/wxbind/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv10746/wxLua/modules/wxbind/src Modified Files: event.cpp 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.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxbind/src/event.cpp,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** event.cpp 18 May 2006 05:47:39 -0000 1.19 --- event.cpp 25 May 2006 03:55:23 -0000 1.20 *************** *** 66,71 **** } ! // %override wxLua_wxEvtHandler_ConnectEvent ! // void ConnectEvent() #include "wxlua/include/wxlcallb.h" --- 66,71 ---- } ! // %override wxLua_wxEvtHandler_Connect ! // void Connect(int id, int lastId, wxEventType eventType, LuaFunction func) #include "wxlua/include/wxlcallb.h" *************** *** 79,83 **** // 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")); --- 79,83 ---- // 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")); *************** *** 85,90 **** wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); ! int id; ! double eventType = 0; wxLuaCallback *pCallback = NULL; --- 85,91 ---- wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); ! int winId = wxID_ANY; ! int lastId = wxID_ANY; ! int eventType = 0; wxLuaCallback *pCallback = NULL; *************** *** 93,111 **** 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; --- 94,112 ---- 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; *************** *** 113,161 **** 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; --- 114,249 ---- 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; ! } ! ! // %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; *************** *** 164,174 **** break; } ! default: { ! wxlState.terror("wxLua: ConnectEvent: Incorrect number of parameters."); break; } } ! return 0; } --- 252,282 ---- 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; } *************** *** 261,265 **** { LuaConstructor, "wxEvtHandler", wxLua_wxEvtHandler_constructor, 0, 0, { 0 } }, { LuaMethod, "AddPendingEvent", wxLua_wxEvtHandler_AddPendingEvent, 1, 1, { &s_wxluatag_wxEvent, 0 } }, ! { LuaMethod, "ConnectEvent", wxLua_wxEvtHandler_ConnectEvent, 0, 0, { 0 } }, { LuaMethod, "GetClientObject", wxLua_wxEvtHandler_GetClientObject, 0, 0, { 0 } }, { LuaMethod, "GetEvtHandlerEnabled", wxLua_wxEvtHandler_GetEvtHandlerEnabled, 0, 0, { 0 } }, --- 369,374 ---- { LuaConstructor, "wxEvtHandler", wxLua_wxEvtHandler_constructor, 0, 0, { 0 } }, { LuaMethod, "AddPendingEvent", wxLua_wxEvtHandler_AddPendingEvent, 1, 1, { &s_wxluatag_wxEvent, 0 } }, ! { LuaMethod, "Connect", wxLua_wxEvtHandler_Connect, 4, 4, { &s_wxluaarg_Number, &s_wxluaarg_Number, &s_wxluaarg_Number, &s_wxluaarg_LuaFunction, 0 } }, ! { LuaMethod, "Disconnect", wxLua_wxEvtHandler_Disconnect, 3, 3, { &s_wxluaarg_Number, &s_wxluaarg_Number, &s_wxluaarg_Number, 0 } }, { LuaMethod, "GetClientObject", wxLua_wxEvtHandler_GetClientObject, 0, 0, { 0 } }, { LuaMethod, "GetEvtHandlerEnabled", wxLua_wxEvtHandler_GetEvtHandlerEnabled, 0, 0, { 0 } }, |