void
JXImageMenuData::ConfigureTable
	(
	JXImageMenuTable*	table,
	JBoolean*			hasCheckboxes,
	JBoolean*			hasSubmenus
	)
{
	*hasCheckboxes = HasCheckboxes();
	*hasSubmenus   = HasSubmenus();

	if (itsNeedGeomRecalcFlag)
		{
		itsNeedGeomRecalcFlag = kJFalse;
		itsRowHeight          = kMinCellSize;
		itsColWidth           = kMinCellSize;

		const JCoordinate bw = 2*(JXImageMenuTable::kHilightBorderWidth + 1);

		const JSize itemCount = itsIconData->GetElementCount();
		for (JIndex i=1; i<=itemCount; i++)
			{
			const IconData itemData = itsIconData->GetElement(i);
			itsRowHeight = JMax(itsRowHeight, (itemData.image)->GetHeight() + bw);
			itsColWidth  = JMax(itsColWidth, (itemData.image)->GetWidth() + bw);
			}

		if (*hasCheckboxes)
			{
			itsColWidth += JXMenuTable::kCheckboxColWidth;
			}
		if (*hasSubmenus)
			{
			itsColWidth += JXMenuTable::kSubmenuColWidth;
			}
		}

	table->SetAllRowHeights(itsRowHeight);
	table->SetAllColWidths(itsColWidth);
	table->SetDefaultRowHeight(itsRowHeight);
}
Пример #2
0
void
JXTextMenuData::ConfigureTable
	(
	JXTextMenuTable* table
	)
{
	const JBoolean hasCheckboxes = HasCheckboxes();
	const JBoolean hasSubmenus   = HasSubmenus();

	if (itsNeedGeomRecalcFlag)
		{
		itsNeedGeomRecalcFlag = kJFalse;
		itsMaxImageWidth      = 1;
		itsMaxTextWidth       = 1;
		itsMaxShortcutWidth   = JXMenuTable::kSubmenuColWidth;
		itsHasNMShortcutsFlag = kJFalse;
		itsItemHeights->RemoveAll();

		const JSize itemCount = itsTextItemData->GetElementCount();
		for (JIndex i=1; i<=itemCount; i++)
			{
			const TextItemData itemData = itsTextItemData->GetElement(i);
			JCoordinate h =
				(itsCompressHeightFlag && !hasCheckboxes && !hasSubmenus) ?
				0 : JXMenuTable::kMinRowHeight;

			if (itemData.text != NULL)
				{
				const JCoordinate th =
					itsFontMgr->GetLineHeight(itemData.fontID, itemData.fontSize,
											  itemData.fontStyle);
				h = JMax(h, th);
				const JCoordinate tw = 2*JXTextMenuTable::kHMarginWidth +
					itsFontMgr->GetStringWidth(itemData.fontID, itemData.fontSize,
											   itemData.fontStyle, *(itemData.text));
				itsMaxTextWidth = JMax(itsMaxTextWidth, tw);
				}

			if (itemData.image != NULL)
				{
				h = JMax(h, (itemData.image)->GetHeight());
				itsMaxImageWidth = JMax(itsMaxImageWidth, (itemData.image)->GetWidth());
				}

			if (itemData.nmShortcut != NULL)
				{
				JFontStyle style;
				itsHasNMShortcutsFlag = kJTrue;
				const JCoordinate th =
					itsFontMgr->GetLineHeight(itemData.fontID, itemData.fontSize, style);
				h = JMax(h, th);
				const JCoordinate tw = JXTextMenuTable::kHNMSMarginWidth +
					JXTextMenuTable::kHMarginWidth +
					itsFontMgr->GetStringWidth(itemData.fontID, itemData.fontSize,
											   style, *(itemData.nmShortcut));
				itsMaxShortcutWidth = JMax(itsMaxShortcutWidth, tw);
				}

			h += 2*(JXTextMenuTable::kHilightBorderWidth + 1);
			if (i < itemCount && itemData.separator)
				{
				h += JXTextMenuTable::kSeparatorHeight;
				}

			table->SetRowHeight(i,h);
			itsItemHeights->AppendElement(h);
			}
		}
	else
		{
		JRunArrayIterator<JCoordinate> iter(itsItemHeights);
		JCoordinate h;
		JIndex i=0;
		while(iter.Next(&h))
			{
			i++;
			table->SetRowHeight(i,h);
			}
		}

	// set the column widths

	if (hasCheckboxes)
		{
		table->SetColWidth(1, JXMenuTable::kCheckboxColWidth +
							  JXTextMenuTable::kHilightBorderWidth);
		}
	else
		{
		table->SetColWidth(1, JXTextMenuTable::kHilightBorderWidth);
		}

	table->SetColWidth(2, itsMaxImageWidth);
	table->SetColWidth(3, itsMaxTextWidth);

	if (itsHasNMShortcutsFlag || hasSubmenus)
		{
		table->SetColWidth(4, itsMaxShortcutWidth +
							  JXTextMenuTable::kHilightBorderWidth);
		}
	else
		{
		table->SetColWidth(4, JXTextMenuTable::kHilightBorderWidth);
		}

	// set a sensible scroll step

	const JCoordinate scrollStep =
		(itsFontMgr->GetLineHeight(itsDefFontID, itsDefFontSize, itsDefFontStyle)
		+ 2*(JXTextMenuTable::kHilightBorderWidth + 1));
	table->SetDefaultRowHeight(scrollStep);
}