// Calc and store row height for all items in the list
void RowHeights_CalcRowHeights(ClcData *dat, HWND hwnd)
{
	if (MirandaExiting()) return;

	// Draw lines
	ClcGroup *group = &dat->list;
	group->scanIndex = 0;
	int indent = 0;
	int subindex = -1;
	int line_num = -1;

	RowHeights_Clear(dat);

	while (true) {
		int subident;
		ClcContact *Drawing;
		if (subindex == -1) {
			if (group->scanIndex == group->cl.getCount()) {
				if ((group = group->parent) == nullptr)
					break;
				group->scanIndex++;
				indent--;
				continue;
			}

			// Get item to draw
			Drawing = group->cl[group->scanIndex];
			subident = 0;
		}
		else {
			// Get item to draw
			Drawing = &group->cl[group->scanIndex]->subcontacts[subindex];
			subident = dat->subIndent;
		}

		line_num++;

		// Calc row height
		if (!gl_RowRoot)
			RowHeights_GetRowHeight(dat, hwnd, Drawing, line_num);
		else
			RowHeight_CalcRowHeight(dat, Drawing, line_num);

		// increment by subcontacts
		if (group->cl[group->scanIndex]->subcontacts != nullptr && group->cl[group->scanIndex]->type != CLCIT_GROUP) {
			if (group->cl[group->scanIndex]->bSubExpanded && dat->bMetaExpanding) {
				if (subindex < group->cl[group->scanIndex]->iSubAllocated - 1)
					subindex++;
				else
					subindex = -1;
			}
		}

		if (subindex == -1) {
			if (group->cl[group->scanIndex]->type == CLCIT_GROUP && group->cl[group->scanIndex]->group->expanded) {
				group = group->cl[group->scanIndex]->group;
				indent++;
				group->scanIndex = 0;
				subindex = -1;
				continue;
			}
			group->scanIndex++;
		}
	}
}
// Calc and store row height for all itens in the list
void RowHeights_CalcRowHeights(struct ClcData *dat, HWND hwnd)
{
	int indent, subident, subindex, line_num;
	struct ClcContact *Drawing;
	struct ClcGroup *group;

	// Draw lines
	group=&dat->list;
	group->scanIndex=0;
	indent=0;
	subindex=-1;
	line_num = -1;

	RowHeights_Clear(dat);
	
	while(TRUE)
	{
		if (subindex==-1)
		{
			if (group->scanIndex==group->contactCount) 
			{
				group=group->parent;
				indent--;
				if(group==NULL) break;	// Finished list
				group->scanIndex++;
				continue;
			}

			// Get item to draw
			Drawing = &(group->contact[group->scanIndex]);
			subident = 0;
		}
		else
		{
			// Get item to draw
			Drawing = &(group->contact[group->scanIndex].subcontacts[subindex]);
			subident = dat->subIndent;
		}

		line_num++;

		// Calc row height
		RowHeights_GetRowHeight(dat, hwnd, Drawing, line_num);

		//increment by subcontacts
		if (group->contact[group->scanIndex].subcontacts!=NULL && group->contact[group->scanIndex].type!=CLCIT_GROUP)
		{
			if (group->contact[group->scanIndex].SubExpanded && dat->expandMeta)
			{
				if (subindex<group->contact[group->scanIndex].SubAllocated-1)
				{
					subindex++;
				}
				else
				{
					subindex=-1;
				}
			}
		}

		if(subindex==-1)
		{
			if(group->contact[group->scanIndex].type==CLCIT_GROUP && group->contact[group->scanIndex].group->expanded) 
			{
				group=group->contact[group->scanIndex].group;
				indent++;
				group->scanIndex=0;
				subindex=-1;
				continue;
			}
			group->scanIndex++;
		}
	}
}