Ejemplo n.º 1
0
	HTREEITEM Tree_AddExtraIconGroup(intlist &group, bool selected, HTREEITEM hAfter = TVI_LAST)
	{
		intlist *ids = new intlist();
		CMString desc;
		int img = 0;
		for (int i = 0; i < group.count; i++) {
			BaseExtraIcon *extra = registeredExtraIcons[group.data[i] - 1];
			ids->add(extra->getID());

			if (img == 0 && !IsEmpty(extra->getDescIcon()))
				img = extra->getID();

			if (i > 0)
				desc += _T(" / ");
			desc += extra->getDescription();
		}

		TVINSERTSTRUCT tvis = { 0 };
		tvis.hInsertAfter = hAfter;
		tvis.item.mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_STATE;
		tvis.item.stateMask = TVIS_STATEIMAGEMASK;
		tvis.item.iSelectedImage = tvis.item.iImage = img;
		tvis.item.lParam = (LPARAM)ids;
		tvis.item.pszText = (TCHAR*)desc.c_str();
		tvis.item.state = INDEXTOSTATEIMAGEMASK(selected ? 2 : 1);
		return m_tree.InsertItem(&tvis);
	}
Ejemplo n.º 2
0
BaseExtraIcon* GetExtraIconByName(const char *name)
{
	for (int i=0; i < registeredExtraIcons.getCount(); i++) {
		BaseExtraIcon *extra = registeredExtraIcons[i];
		if (mir_strcmp(name, extra->getName()) == 0)
			return extra;
	}
	return NULL;
}
Ejemplo n.º 3
0
BaseExtraIcon * GetExtraIconByName(const char *name)
{
	for (unsigned int i = 0; i < registeredExtraIcons.size(); ++i)
	{
		BaseExtraIcon *extra = registeredExtraIcons[i];
		if (strcmp(name, extra->getName()) == 0)
			return extra;
	}
	return NULL;
}
Ejemplo n.º 4
0
static void LoadGroups(vector<ExtraIconGroup *> &groups)
{
	unsigned int count = DBGetContactSettingWord(NULL, MODULE_NAME "Groups", "Count", 0);
	for (unsigned int i = 0; i < count; ++i)
	{
		char setting[512];
		mir_snprintf(setting, MAX_REGS(setting), "%d_count", i);
		unsigned int items = DBGetContactSettingWord(NULL, MODULE_NAME "Groups", setting, 0);
		if (items < 1)
			continue;

		mir_snprintf(setting, MAX_REGS(setting), "__group_%d", i);
		ExtraIconGroup *group = new ExtraIconGroup(setting);

		for (unsigned int j = 0; j < items; ++j)
		{
			mir_snprintf(setting, MAX_REGS(setting), "%d_%d", i, j);

			DBVARIANT dbv = { 0 };
			if (!DBGetContactSettingString(NULL, MODULE_NAME "Groups", setting, &dbv))
			{
				if (!IsEmpty(dbv.pszVal))
				{
					BaseExtraIcon *extra = GetExtraIconByName(dbv.pszVal);
					if (extra != NULL)
					{
						group->items.push_back(extra);

						if (extra->getSlot() >= 0)
							group->setSlot(extra->getSlot());
					}
				}
				DBFreeVariant(&dbv);
			}
		}

		if (group->items.size() < 2)
		{
			delete group;
			continue;
		}

		groups.push_back(group);
	}
}
Ejemplo n.º 5
0
static void LoadGroups(LIST<ExtraIconGroup> &groups)
{
	int count = db_get_w(NULL, MODULE_NAME "Groups", "Count", 0);
	for (int i=0; i < count; i++) {
		char setting[512];
		mir_snprintf(setting, "%d_count", i);
		unsigned int items = db_get_w(NULL, MODULE_NAME "Groups", setting, 0);
		if (items < 1)
			continue;

		mir_snprintf(setting, "__group_%d", i);
		ExtraIconGroup *group = new ExtraIconGroup(setting);

		for (unsigned int j = 0; j < items; j++) {
			mir_snprintf(setting, "%d_%d", i, j);
			ptrA szIconName(db_get_sa(NULL, MODULE_NAME "Groups", setting));
			if (IsEmpty(szIconName))
				continue;

			BaseExtraIcon *extra = GetExtraIconByName(szIconName);
			if (extra == NULL)
				continue;

			group->m_items.insert(extra);
			if (extra->getSlot() >= 0)
				group->setSlot(extra->getSlot());
		}

		if (group->m_items.getCount() < 2) {
			delete group;
			continue;
		}

		groups.insert(group);
	}
}
Ejemplo n.º 6
0
EXTERN_C MIR_APP_DLL(HANDLE) ExtraIcon_RegisterIcolib(const char *name, const char *description, const char *descIcon,
	MIRANDAHOOKPARAM OnClick, LPARAM onClickParam, int _hLang)
{
	if (IsEmpty(name) || IsEmpty(description))
		return 0;

	ptrT tszDesc(mir_a2t(description));
	TCHAR *desc = TranslateTH(_hLang, tszDesc);

	BaseExtraIcon *extra = GetExtraIconByName(name);
	if (extra != NULL) {
		if (extra->getType() != EXTRAICON_TYPE_ICOLIB)
			return 0;

		// Found one, now merge it
		if (mir_tstrcmpi(extra->getDescription(), desc)) {
			CMString newDesc = extra->getDescription();
			newDesc += _T(" / ");
			newDesc += desc;
			extra->setDescription(newDesc.c_str());
		}

		if (!IsEmpty(descIcon))
			extra->setDescIcon(descIcon);

		if (OnClick != NULL)
			extra->setOnClick(OnClick, onClickParam);

		if (extra->getSlot() > 0) {
			if (clistRebuildAlreadyCalled)
				extra->rebuildIcons();
			if (clistApplyAlreadyCalled)
				extraIconsByHandle[extra->getID() - 1]->applyIcons();
		}

		return (HANDLE)extra->getID();
	}

	int id = registeredExtraIcons.getCount() + 1;
	extra = new IcolibExtraIcon(id, name, desc, descIcon == NULL ? "" : descIcon, OnClick, onClickParam);
	EI_PostCreate(extra, name, _hLang);
	return (HANDLE)id;
}
Ejemplo n.º 7
0
INT_PTR ExtraIcon_Register(WPARAM wParam, LPARAM lParam)
{
	if (wParam == 0)
		return 0;

	EXTRAICON_INFO *ei = (EXTRAICON_INFO *) wParam;
	if (ei->cbSize < (int) sizeof(EXTRAICON_INFO))
		return 0;
	if (ei->type != EXTRAICON_TYPE_CALLBACK && ei->type != EXTRAICON_TYPE_ICOLIB)
		return 0;
	if (IsEmpty(ei->name) || IsEmpty(ei->description))
		return 0;
	if (ei->type == EXTRAICON_TYPE_CALLBACK && (ei->ApplyIcon == NULL || ei->RebuildIcons == NULL))
		return 0;

	const char *desc = Translate(ei->description);

	BaseExtraIcon *extra = GetExtraIconByName(ei->name);
	if (extra != NULL)
	{
		if (ei->type != extra->getType() || ei->type != EXTRAICON_TYPE_ICOLIB)
			return 0;

		// Found one, now merge it

		if (_stricmp(extra->getDescription(), desc))
		{
			string newDesc = extra->getDescription();
			newDesc += " / ";
			newDesc += desc;
			extra->setDescription(newDesc.c_str());
		}

		if (!IsEmpty(ei->descIcon))
			extra->setDescIcon(ei->descIcon);

		if (ei->OnClick != NULL)
			extra->setOnClick(ei->OnClick, ei->onClickParam);

		if (extra->getSlot() > 0)
		{
			if (clistRebuildAlreadyCalled)
				extra->rebuildIcons();
			if (clistApplyAlreadyCalled)
				extraIconsByHandle[extra->getID() - 1]->applyIcons();
		}

		return extra->getID();
	}

	size_t id = registeredExtraIcons.size() + 1;

	switch (ei->type)
	{
		case EXTRAICON_TYPE_CALLBACK:
			extra = new CallbackExtraIcon(id, ei->name, desc, ei->descIcon == NULL ? "" : ei->descIcon,
					ei->RebuildIcons, ei->ApplyIcon, ei->OnClick, ei->onClickParam);
			break;
		case EXTRAICON_TYPE_ICOLIB:
			extra = new IcolibExtraIcon(id, ei->name, desc, ei->descIcon == NULL ? "" : ei->descIcon, ei->OnClick,
					ei->onClickParam);
			break;
		default:
			return 0;
	}

	char setting[512];
	mir_snprintf(setting, MAX_REGS(setting), "Position_%s", ei->name);
	extra->setPosition(DBGetContactSettingWord(NULL, MODULE_NAME, setting, 1000));

	mir_snprintf(setting, MAX_REGS(setting), "Slot_%s", ei->name);
	int slot = DBGetContactSettingWord(NULL, MODULE_NAME, setting, 1);
	if (slot == (WORD) -1)
		slot = -1;
	extra->setSlot(slot);

	registeredExtraIcons.push_back(extra);
	extraIconsByHandle.push_back(extra);

	vector<ExtraIconGroup *> groups;
	LoadGroups(groups);

	ExtraIconGroup *group = IsInGroup(groups, extra);
	if (group != NULL)
	{
		RebuildListsBasedOnGroups(groups);
	}
	else
	{
		for (unsigned int i = 0; i < groups.size(); ++i)
			delete groups[i];

		extraIconsBySlot.push_back(extra);
		std::sort(extraIconsBySlot.begin(), extraIconsBySlot.end(), compareFunc());
	}

	if (slot >= 0 || group != NULL)
	{
		if (clistRebuildAlreadyCalled)
			extra->rebuildIcons();

		slot = 0;
		for (unsigned int i = 0; i < extraIconsBySlot.size(); ++i)
		{
			ExtraIcon *ex = extraIconsBySlot[i];
			if (ex->getSlot() < 0)
				continue;

			int oldSlot = ex->getSlot();
			ex->setSlot(slot++);

			if (clistApplyAlreadyCalled && (ex == group || ex == extra || oldSlot != slot))
				extra->applyIcons();
		}
	}

	return id;
}
Ejemplo n.º 8
0
INT_PTR ExtraIcon_Register(WPARAM wParam, LPARAM lParam)
{
	if (wParam == 0)
		return 0;

	EXTRAICON_INFO *ei = (EXTRAICON_INFO *)wParam;
	if (ei->cbSize < (int)sizeof(EXTRAICON_INFO))
		return 0;
	if (ei->type != EXTRAICON_TYPE_CALLBACK && ei->type != EXTRAICON_TYPE_ICOLIB)
		return 0;
	if (IsEmpty(ei->name) || IsEmpty(ei->description))
		return 0;
	if (ei->type == EXTRAICON_TYPE_CALLBACK && (ei->ApplyIcon == NULL || ei->RebuildIcons == NULL))
		return 0;

	ptrT tszDesc(mir_a2t(ei->description));
	TCHAR *desc = TranslateTH(lParam, tszDesc);

	BaseExtraIcon *extra = GetExtraIconByName(ei->name);
	if (extra != NULL) {
		if (ei->type != extra->getType() || ei->type != EXTRAICON_TYPE_ICOLIB)
			return 0;

		// Found one, now merge it
		if (_tcsicmp(extra->getDescription(), desc)) {
			CMString newDesc = extra->getDescription();
			newDesc += _T(" / ");
			newDesc += desc;
			extra->setDescription(newDesc.c_str());
		}

		if (!IsEmpty(ei->descIcon))
			extra->setDescIcon(ei->descIcon);

		if (ei->OnClick != NULL)
			extra->setOnClick(ei->OnClick, ei->onClickParam);

		if (extra->getSlot() > 0) {
			if (clistRebuildAlreadyCalled)
				extra->rebuildIcons();
			if (clistApplyAlreadyCalled)
				extraIconsByHandle[extra->getID() - 1]->applyIcons();
		}

		return extra->getID();
	}

	int id = registeredExtraIcons.getCount() + 1;

	switch (ei->type) {
	case EXTRAICON_TYPE_CALLBACK:
		extra = new CallbackExtraIcon(id, ei->name, desc, ei->descIcon == NULL ? "" : ei->descIcon,
			ei->RebuildIcons, ei->ApplyIcon, ei->OnClick, ei->onClickParam);
		break;
	case EXTRAICON_TYPE_ICOLIB:
		extra = new IcolibExtraIcon(id, ei->name, desc, ei->descIcon == NULL ? "" : ei->descIcon, ei->OnClick,
			ei->onClickParam);
		break;
	default:
		return 0;
	}

	char setting[512];
	mir_snprintf(setting, SIZEOF(setting), "Position_%s", ei->name);
	extra->setPosition(db_get_w(NULL, MODULE_NAME, setting, 1000));

	mir_snprintf(setting, SIZEOF(setting), "Slot_%s", ei->name);
	int slot = db_get_w(NULL, MODULE_NAME, setting, 1);
	if (slot == (WORD)-1)
		slot = -1;
	extra->setSlot(slot);

	extra->hLangpack = (int)lParam;

	registeredExtraIcons.insert(extra);
	extraIconsByHandle.insert(extra);

	LIST<ExtraIconGroup> groups(1);
	LoadGroups(groups);

	ExtraIconGroup *group = IsInGroup(groups, extra);
	if (group != NULL)
		RebuildListsBasedOnGroups(groups);
	else {
		for (int i = 0; i < groups.getCount(); i++)
			delete groups[i];

		extraIconsBySlot.insert(extra);
	}

	if (slot >= 0 || group != NULL) {
		if (clistRebuildAlreadyCalled)
			extra->rebuildIcons();

		slot = 0;
		for (int i = 0; i < extraIconsBySlot.getCount(); i++) {
			ExtraIcon *ex = extraIconsBySlot[i];
			if (ex->getSlot() < 0)
				continue;

			int oldSlot = ex->getSlot();
			ex->setSlot(slot++);

			if (clistApplyAlreadyCalled && (ex == group || ex == extra || oldSlot != slot))
				extra->applyIcons();
		}
	}

	return id;
}
Ejemplo n.º 9
0
	virtual void OnApply()
	{
		// Store old slots
		int *oldSlots = new int[registeredExtraIcons.getCount()];
		int lastUsedSlot = -1;
		for (int i = 0; i < registeredExtraIcons.getCount(); i++) {
			if (extraIconsByHandle[i] == registeredExtraIcons[i])
				oldSlots[i] = registeredExtraIcons[i]->getSlot();
			else
				// Remove old slot for groups to re-set images
				oldSlots[i] = -1;
			lastUsedSlot = MAX(lastUsedSlot, registeredExtraIcons[i]->getSlot());
		}
		lastUsedSlot = MIN(lastUsedSlot, GetNumberOfSlots());

		// Get user data and create new groups
		LIST<ExtraIconGroup> groups(1);

		BYTE pos = 0;
		int firstEmptySlot = 0;
		HTREEITEM ht = m_tree.GetRoot();
		TVITEMEX tvi;
		tvi.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_STATE;
		tvi.stateMask = TVIS_STATEIMAGEMASK;
		while (ht) {
			tvi.hItem = ht;
			m_tree.GetItem(&tvi);

			intlist*ids = (intlist*)tvi.lParam;
			if (ids == NULL || ids->count < 1)
				continue; // ???

			bool enabled = ((tvi.state & INDEXTOSTATEIMAGEMASK(3)) == INDEXTOSTATEIMAGEMASK(2));
			int slot = (enabled ? firstEmptySlot++ : -1);
			if (slot >= GetNumberOfSlots())
				slot = -1;

			if (ids->count == 1) {
				BaseExtraIcon *extra = registeredExtraIcons[ids->data[0] - 1];
				extra->setPosition(pos++);
				extra->setSlot(slot);
			}
			else {
				char name[128];
				mir_snprintf(name, "__group_%d", groups.getCount());

				ExtraIconGroup *group = new ExtraIconGroup(name);

				for (int i = 0; i < ids->count; i++) {
					BaseExtraIcon *extra = registeredExtraIcons[ids->data[i] - 1];
					extra->setPosition(pos++);

					group->addExtraIcon(extra);
				}

				group->setSlot(slot);
				groups.insert(group);
			}

			ht = m_tree.GetNextSibling(ht);
		}

		// Store data
		for (int i = 0; i < registeredExtraIcons.getCount(); i++) {
			BaseExtraIcon *extra = registeredExtraIcons[i];

			char setting[512];
			mir_snprintf(setting, "Position_%s", extra->getName());
			db_set_w(NULL, MODULE_NAME, setting, extra->getPosition());

			mir_snprintf(setting, "Slot_%s", extra->getName());
			db_set_w(NULL, MODULE_NAME, setting, extra->getSlot());
		}

		CallService(MS_DB_MODULE_DELETE, 0, (LPARAM)MODULE_NAME "Groups");
		db_set_w(NULL, MODULE_NAME "Groups", "Count", groups.getCount());
		for (int k = 0; k < groups.getCount(); k++) {
			ExtraIconGroup *group = groups[k];

			char setting[512];
			mir_snprintf(setting, "%d_count", k);
			db_set_w(NULL, MODULE_NAME "Groups", setting, (WORD)group->m_items.getCount());

			for (int j = 0; j < group->m_items.getCount(); j++) {
				BaseExtraIcon *extra = group->m_items[j];

				mir_snprintf(setting, "%d_%d", k, j);
				db_set_s(NULL, MODULE_NAME "Groups", setting, extra->getName());
			}
		}

		// Clean removed slots
		for (int j = firstEmptySlot; j <= lastUsedSlot; j++)
			RemoveExtraIcons(j);

		// Apply icons to new slots
		RebuildListsBasedOnGroups(groups);
		for (int n = 0; n < extraIconsBySlot.getCount(); n++) {
			ExtraIcon *extra = extraIconsBySlot[n];
			if (extra->getType() != EXTRAICON_TYPE_GROUP)
				if (oldSlots[((BaseExtraIcon *)extra)->getID() - 1] == extra->getSlot())
					continue;

			if (extra->isEnabled())
				extra->applyIcons();
		}

		delete[] oldSlots;
	}