예제 #1
0
// virtual
void Properties::PropertyListener::handleEvent(System::Event* evt)
{
#if WIN32
	if (evt->get_eventPhase() != System::CAPTURING_PHASE)
	{
		if (*evt->get_type() == L"contextmenu")
		{
			evt->stopPropagation();
			UI::MouseEvent* mouseEvt = static_cast<UI::MouseEvent*>(evt);

			UI::CLXUIMenuElement* menu = new UI::CLXUIMenuElement();
		//	menu->SetRParent(m_ctledit);
			menu->SetOwnerWindow(mouseEvt->GetOwnerWindow());

			menu->addEventListener(WSTR("command"), this, false);

			if (false)
			{
				menu->AddItem(new UI::TextString(WSTR("Display As Table")), 100);
			}
			else
			{
				Type* pType = m_pProperty->get_method->m_decl->m_pType->GetFunction()->m_pReturnType;

				if (pType->get_Kind() == type_pointer && pType->GetPointerTo()->get_Kind() == type_class)
				{
					vector<ClassType*> list;
					GetDerived(pType->GetPointerTo()->GetClass(), list);

					for (int i = 0; i < list.GetSize(); i++)
					{
						ClassType* pDerived = list[i];
						if (pDerived->m_derived.GetSize() == 0)
						{
							menu->AddItem(new UI::TextString(pDerived->get_Name()->ToStringW()), (long)pDerived);
						}
					}
				}
			}

			menu->GetMenuPopup()->Popup(menu, LDraw::PointI(mouseEvt->get_ScreenX(), mouseEvt->get_ScreenY()));
		}
		else if (*evt->get_type() == L"command")
		{
			if (false)
			{
				m_bDisplayAsTable = !m_bDisplayAsTable;
			}
			else
			{
				evt->stopPropagation();
				UI::CommandInvokeEvent* cmdEvt = dynamic_cast<UI::CommandInvokeEvent*>(evt);

				long param = cmdEvt->get_Command();
				ClassType* pDerivedType = (ClassType*)param;

				void* p = newobj(pDerivedType);
				if (p)
				{
					Type* pType = m_pProperty->set_method->m_decl->m_pType->GetFunction()->m_parameters.m_parameters[0].m_pType;
					pType = pType->GetStripped();
					void* value = DynamicCast(p, pDerivedType, pType->GetPointerTo()->GetClass());

					ASSERT(0);
					void *_this = NULL;//__RTDynamicCast(m_itemVisual, 0, (void*)&typeid(m_itemVisual), (void*)m_pProperty->set_method->GetTypeInfo(), 0);

				//	StringA str_type = pType->ToString();

					ULONG_PTR func;
					if (m_pProperty->set_method->m_decl->m_offset != -1)
					{
						void* vtable = *(void**)_this;
						func = *(ULONG_PTR*)((uint8*)vtable + m_pProperty->set_method->m_decl->m_offset);
					}
					else
					{
						func = m_pProperty->set_method->m_func;
					}

					__asm
					{
						push ecx
						mov ecx,_this
						push value
						call func
						pop ecx
					}
				}
			}
		}

#if 0
		void *_this = __RTDynamicCast(m_itemVisual, 0, (void*)&typeid(m_itemVisual), (void*)put_type_info(), 0);

		cpp::Type* pType = put_decl->m_pType->m_pFunction->m_parameters[0]->m_pType;
		StringA str_type = pType->toString();
		pType = pType->GetType();

		DWORD func;
		if (put_decl->m_offset != -1)
		{
			void* vtable = *(void**)_this;
			func = *(DWORD*)((uint8*)vtable + put_decl->m_offset);
		}
		else
		{
			func = put_func;
		}

		if (*evt->get_type() == L"contextmenu")
		{
			evt->stopPropagation();
			UI::MouseEvent* mouseEvt = dynamic_cast<MouseEvent*>(evt);

			if (pType->m_type == cpp::type_pointer && pType->m_pPointerTo->m_type == cpp::type_class)
			{
				CLXUIMenuElement* menu = new CLXUIMenuElement();
				menu->SetRParent(m_ctledit);
				menu->SetOwnerWindow(m_ctledit->get_OwnerWindow());
				
				std::map<StringA, cpp::Type*>::iterator it = pD->m_namedTypes.begin();
				while (it != pD->m_namedTypes.end())
				{
					cpp::Type* pType2 = (*it).second;
					ASSERT(pType2);
					it++;

					if (pType2->m_type == cpp::type_class)
					{
						if (pType2->m_pClass->IsOfType(pType->m_pPointerTo->m_pClass))
						{
						//	pType2->m_pClass->IsOfType(pType->m_pPointerTo->m_pClass);
							menu->AddItem(new TextString(ConvertA2S(pType2->m_pClass->m_name)), (long)pType2);
						}
					}
				}

				menu->GetMenuPopup()->Popup(menu, LDraw::PointI(mouseEvt->get_ScreenX(), mouseEvt->get_ScreenY()));
			}
		}
		else if (*evt->get_type() == L"command")
		{
			evt->stopPropagation();
			CommandInvokeEvent* cmdEvt = dynamic_cast<CommandInvokeEvent*>(evt);

			long param = cmdEvt->get_Command();

			if (pType->m_type == cpp::type_enum)
			{
				__asm
				{
					push ecx
					mov ecx,_this
					push param
					call func
					pop ecx
				}
			}
			else
			{
				cpp::Type* pType2 = (cpp::Type*)param;

				void* object = newobj(pType2->m_pClass);
				Type_Info* src = (Type_Info*)pD->LookupSymbol(DecorateName(pType2->m_pClass->m_name));
				Type_Info* dst = (Type_Info*)pD->LookupSymbol(DecorateName(pType->m_pPointerTo->m_pClass->m_name));

				void* param = __RTDynamicCast(object, 0, src, dst, 0);

				__asm
				{
					push ecx
					mov ecx,_this
					push param
					call func
					pop ecx
				}
			}
		}
		else if (*evt->get_type() == L"ValueChange")