/////////////////////
// Set column widths
void BaseGrid::SetColumnWidths() {
	// Width/height
	int w = 0;
	int h = 0;
	GetClientSize(&w,&h);

	// DC for text extents test
	wxClientDC dc(this);
	dc.SetFont(font);
	int fw,fh;
	//dc.GetTextExtent(_T("#TWFfgGhH"), &fw, &fh, NULL, NULL, &font);

	// O(1) widths
	dc.GetTextExtent(_T("0000"), &fw, &fh, NULL, NULL, &font);
	int marginLen = fw + 10;
	dc.GetTextExtent(wxString::Format(_T("%i"),GetRows()), &fw, &fh, NULL, NULL, &font);
	int labelLen = fw + 10;
	int startLen = 0;
	int endLen = 0;
	if (!byFrame) {
		AssTime time;
		dc.GetTextExtent(time.GetASSFormated(), &fw, &fh, NULL, NULL, &font);
		startLen = fw + 10;
		endLen = fw + 10;
	}

	// O(n) widths
	int actorLen = 0;
	int effectLen = 0;
	int maxLayer = 0;
	int maxStart = 0;
	int maxEnd = 0;
	AssDialogue *curDiag;
	for (int i=0;i<GetRows();i++) {
		curDiag = GetDialogue(i);
		if (curDiag) {
			// Layer
			if (curDiag->Layer > maxLayer) maxLayer = curDiag->Layer;

			// Actor
			if (!curDiag->Actor.IsEmpty()) {
				dc.GetTextExtent(curDiag->Actor, &fw, &fh, NULL, NULL, &font);
				if (fw > actorLen) actorLen = fw;
			}

			// Effect
			if (!curDiag->Effect.IsEmpty()) {
				dc.GetTextExtent(curDiag->Effect, &fw, &fh, NULL, NULL, &font);
				if (fw > effectLen) effectLen = fw;
			}

			// Times
			if (byFrame) {
				int tmp = VFR_Output.GetFrameAtTime(curDiag->Start.GetMS(),true);
				if (tmp > maxStart) maxStart = tmp;
				tmp = VFR_Output.GetFrameAtTime(curDiag->End.GetMS(),true);
				if (tmp > maxEnd) maxEnd = tmp;
			}
		}
	}

	// Finish layer
	dc.GetTextExtent(wxString::Format(_T("%i"),maxLayer), &fw, &fh, NULL, NULL, &font);
	int layerLen = fw + 10;

	// Finish times
	if (byFrame) {
		dc.GetTextExtent(wxString::Format(_T("%i"),maxStart), &fw, &fh, NULL, NULL, &font);
		startLen = fw + 10;
		dc.GetTextExtent(wxString::Format(_T("%i"),maxEnd), &fw, &fh, NULL, NULL, &font);
		endLen = fw + 10;
	}

	// Finish actor/effect
	if (actorLen) actorLen += 10;
	if (effectLen) effectLen += 10;

	// Style length
	int styleLen = 0;
	AssStyle *curStyle;
	if (AssFile::top) {
		for (entryIter curIter=AssFile::top->Line.begin();curIter!=AssFile::top->Line.end();curIter++) {
			curStyle = AssEntry::GetAsStyle(*curIter);
			if (curStyle) {
				dc.GetTextExtent(curStyle->name, &fw, &fh, NULL, NULL, &font);
				if (fw > styleLen) styleLen = fw;
			}
		}
	}
	styleLen += 10;

	// Set column widths
	colWidth[0] = labelLen;
	colWidth[1] = layerLen;
	colWidth[2] = startLen;
	colWidth[3] = endLen;
	colWidth[4] = styleLen;
	colWidth[5] = actorLen;
	colWidth[6] = effectLen;
	colWidth[7] = marginLen;
	colWidth[8] = marginLen;
	colWidth[9] = marginLen;

	// Set size of last
	int total = 0;
	for (int i=0;i<10;i++) total+= colWidth[i];
	colWidth[10] = w-total;
}