void
JXExprEditor::EIPBoundsChanged()
{
	const JRect newBounds = (GetRectList())->GetBoundsRect();
	const JRect apG       = GetApertureGlobal();
	const JCoordinate w   = JMax(newBounds.width(),  apG.width());
	const JCoordinate h   = JMax(newBounds.height(), apG.height());
	SetBounds(w,h);
}
JBoolean
PadColormap
	(
	gdImagePtr image
	)
{
	JSize colorCount = gdImageColorsTotal(image);
	if (colorCount >= kMinColorCount)
		{
		return kJFalse;
		}

	const JSize extraColorCount = kMinColorCount - colorCount;

	int x = gdImageSX(image) - extraColorCount;
	if (x < 0)
		{
		cerr << "image is too small to fit extra colors on single raster line" << endl;
		exit(1);
		}

	int y = gdImageSY(image) - 1;

	int c = gdImageGetPixel(image, x,y);
	int r = gdImageRed  (image, c);
	int g = gdImageGreen(image, c);
	int b = gdImageBlue (image, c);

	int delta = -1;
	if (r < 127 || g < 127 || b < 127)
		{
		delta = +1;
		}

	for (JIndex i=1; i<=extraColorCount; i++)
		{
		assert( x < gdImageSX(image) );

		while ((c = gdImageColorExact(image, r,g,b)) != -1)
			{
			r = JMax(0, JMin(r + delta, 255));
			g = JMax(0, JMin(g + delta, 255));
			b = JMax(0, JMin(b + delta, 255));
			}

		c = gdImageColorAllocate(image, r,g,b);
		assert( c != -1 );
		gdImageSetPixel(image, x,y, c);

		x++;
		}

	return kJTrue;
}
Esempio n. 3
0
JRect::JRect
(
    const JPoint& p1,
    const JPoint& p2
)
    :
    top    ( JMin(p1.y, p2.y)   ),
    left   ( JMin(p1.x, p2.x)   ),
    bottom ( JMax(p1.y, p2.y)+1 ),
    right  ( JMax(p1.x, p2.x)+1 )
{
}
Esempio n. 4
0
JRect
JCovering
(
    const JRect& r1,
    const JRect& r2
)
{
    JRect result;
    result.top    = JMin(r1.top,    r2.top);
    result.left   = JMin(r1.left,   r2.left);
    result.bottom = JMax(r1.bottom, r2.bottom);
    result.right  = JMax(r1.right,  r2.right);
    return result;
}
void
JXTreeListWidget::AdjustColWidths()
{
	if (itsAdjustToTreeTask != NULL)
		{
		return;
		}

	const JSize colCount = GetColCount();
	if (itsMinColWidths->GetElementCount() != colCount)
		{
		NeedsAdjustToTree();
		return;
		}

	for (JIndex i=1; i<=colCount; i++)
		{
		SetColWidth(i, itsMinColWidths->GetElement(i));
		}

	if (ColIndexValid(itsElasticColIndex))
		{
		const JCoordinate minReqWidth = itsMinColWidths->GetElement(itsElasticColIndex);
		if (minReqWidth > 0)
			{
			const JCoordinate availWidth =
				GetApertureWidth() - (GetBoundsWidth() - GetColWidth(itsElasticColIndex));
			SetColWidth(itsElasticColIndex, JMax(minReqWidth, availWidth));
			}
		}
}
JIndexRange
JCovering
	(
	const JIndexRange& r1,
	const JIndexRange& r2
	)
{
	const JBoolean n1 = r1.IsNothing();
	const JBoolean n2 = r2.IsNothing();
	if (n1 && n2)
		{
		return JIndexRange();
		}
	else if (n1)
		{
		return r2;
		}
	else if (n2)
		{
		return r1;
		}
	else
		{
		return JIndexRange( JMin(r1.first, r2.first),
							JMax((r1.IsEmpty() ? r1.first-1 : r1.last),
								 (r2.IsEmpty() ? r2.first-1 : r2.last)) );
		}
}
void
JDiagBandMatrix::AddRowToRow
	(
	const JIndex	sourceIndex,
	const JFloat	scaleFactor,
	const JIndex	destIndex
	)
{
	JIndex minSrcCol = 1;
	if (sourceIndex > itsLowerBandCount)
		{
		minSrcCol = sourceIndex - itsLowerBandCount;
		}

	const JIndex maxSrcCol = JMin(sourceIndex + itsUpperBandCount, itsSize);

	JIndex minDestCol = 1;
	if (destIndex > itsLowerBandCount)
		{
		minDestCol = destIndex - itsLowerBandCount;
		}

	const JIndex maxDestCol = JMin(destIndex + itsUpperBandCount, itsSize);

	const JIndex minCol = JMax(minSrcCol, minDestCol);
	const JIndex maxCol = JMin(maxSrcCol, maxDestCol);

	for (JIndex i=minCol; i<=maxCol; i++)
		{
		SetElement(destIndex,i, GetElement(destIndex,i) +
				   scaleFactor * GetElement(sourceIndex,i));
		}
}
Esempio n. 8
0
JPoint
JPinInRect
	(
	const JPoint&	pt,
	const JRect&	r
	)
{
	JPoint newPt = pt;

	newPt.x = JMax(newPt.x, r.left);
	newPt.x = JMin(newPt.x, (JCoordinate) (r.right-1));

	newPt.y = JMax(newPt.y, r.top);
	newPt.y = JMin(newPt.y, (JCoordinate) (r.bottom-1));

	return newPt;
}
Esempio n. 9
0
void
JXWidget::ShouldAllowUnboundedScrolling
	(
	const JBoolean allow
	)
{
	itsAllowUnboundedScrollingFlag = allow;
	if (!allow)
		{
		const JRect apG = GetApertureGlobal();
		const JRect bG  = GetBoundsGlobal();
		if (apG.top < bG.top || apG.left < bG.left)
			{
			ScrollTo(JMax(0L, apG.left - bG.left),
					 JMax(0L, apG.top - bG.top));
			}
		}
}
void
JTableSelectionIterator::MoveTo
	(
	const JIteratorPosition	newPosition,
	const JPoint&			cell
	)
{
	if (itsTableSelection == NULL)
		{
		return;
		}

	const JSize rowCount = itsTableSelection->GetRowCount();
	const JSize colCount = itsTableSelection->GetColCount();

	itsAtEndFlag = kJFalse;

	if (newPosition == kJIteratorStartAtBeginning)
		{
		itsCursor.x = 1;
		itsCursor.y = 1;
		}

	else if (newPosition == kJIteratorStartAtEnd)
		{
		itsCursor.x  = JMax((JSize) 1, colCount);
		itsCursor.y  = JMax((JSize) 1, rowCount);
		itsAtEndFlag = kJTrue;
		}

	else if (newPosition == kJIteratorStartBefore)
		{
		assert( itsTableSelection->CellValid(cell) );
		itsCursor = cell;
		}

	else
		{
		assert( newPosition == kJIteratorStartAfter );
		assert( itsTableSelection->CellValid(cell) );
		itsCursor = cell;
		NextCell();
		}
}
JIntRange
JCovering
	(
	const JIntRange& r1,
	const JIntRange& r2
	)
{
	return JIntRange( JMin(r1.first, r2.first),
					  JMax((r1.IsEmpty() ? r1.first-1 : r1.last),
						   (r2.IsEmpty() ? r2.first-1 : r2.last)) );
}
JBoolean
JIntersection
	(
	const JIntRange&	r1,
	const JIntRange&	r2,
	JIntRange*			result
	)
{
	result->Set(JMax(r1.first, r2.first), JMin(r1.last,  r2.last));
	return !result->IsEmpty();
}
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);
}
Esempio n. 14
0
JBoolean
JIntersection
(
    const JRect&	r1,
    const JRect&	r2,
    JRect*			result
)
{
    result->top    = JMax(r1.top,    r2.top);
    result->left   = JMax(r1.left,   r2.left);
    result->bottom = JMin(r1.bottom, r2.bottom);
    result->right  = JMin(r1.right,  r2.right);

    if (result->top < result->bottom && result->left < result->right)
    {
        return kJTrue;
    }
    else
    {
        *result = JRect(0,0,0,0);
        return kJFalse;
    }
}
void
JXFSBindingTable::UpdateColWidths()
{
	JCoordinate borderWidth;
	JColorIndex color;
	GetColBorderInfo(&borderWidth, &color);

	JCoordinate w = GetApertureWidth();
	for (JIndex i=1; i<=kColCount; i++)
		{
		if (i != kCommandColumn)
			{
			w -= GetColWidth(i) + borderWidth;
			}
		}

	w = JMax(w, kInitColWidth[ kCommandColumn-1 ]);
	SetColWidth(kCommandColumn, w);
}
JPlotFunctionBase::JPlotFunctionBase
(
    const Type		type,
    J2DPlotWidget*	plot,
    const JFloat	xMin,
    const JFloat	xMax
)
    :
    JPlotDataBase(type)
{
    itsPlot = plot;
    itsXMin = JMin(xMin, xMax);
    itsXMax = JMax(xMin, xMax);

    itsValues = new JArray<Point>(kDefSampleCount);
    assert( itsValues != NULL );

    ListenTo(itsPlot);
}
JBoolean
JIntersection
	(
	const JIndexRange&	r1,
	const JIndexRange&	r2,
	JIndexRange*		result
	)
{
	const JIndex min = JMax(r1.first, r2.first);
	const JIndex max = JMin(r1.last,  r2.last);
	if (max >= min)
		{
		result->Set(min, max);
		return kJTrue;
		}
	else
		{
		result->SetToNothing();
		return kJFalse;
		}
}
void
JXTabGroup::Draw
	(
	JXWindowPainter&	p,
	const JRect&		rect
	)
{
	const JRect ap = GetAperture();

	p.SetFont(itsFontName, itsFontSize, itsFontStyle);
	const JSize lineHeight = p.GetLineHeight();
	const JSize tabHeight  = 2*(kBorderWidth + kTextMargin) + lineHeight;

	JIndex selIndex;
	JRect selRect;
	const JBoolean hasSelection = itsCardFile->GetCurrentCardIndex(&selIndex);

	itsTabRects->RemoveAll();
	itsCanScrollUpFlag   = JI2B(itsFirstDrawIndex > 1);
	itsCanScrollDownFlag = kJFalse;

	const JCoordinate scrollArrowWidth = 2*(kArrowWidth + kBorderWidth);

	const JSize count = itsTitles->GetElementCount();
	itsLastDrawIndex  = JMax(count, itsFirstDrawIndex);

	const JColormap* cmap = p.GetColormap();
	if (itsEdge == kTop)
		{
		JRect r(ap.top + kSelMargin,             ap.left + kSelMargin,
				ap.top + kSelMargin + tabHeight, ap.left + kSelMargin);

		for (JIndex i=itsFirstDrawIndex; i<=count; i++)
			{
			const JString* title = itsTitles->NthElement(i);
			const JBoolean isSel = JI2B(hasSelection && i == selIndex);
			const TabInfo info   = itsTabInfoList->GetElement(i);

			r.right += 2*kBorderWidth + info.preMargin +info.postMargin + p.GetStringWidth(*title);
			if (info.closable)
				{
				r.right += kCloseMarginWidth + itsCloseImage->GetWidth();
				}
			JPoint titlePt(r.left + kBorderWidth + info.preMargin,
						   r.top  + kBorderWidth + kTextMargin);
			if (isSel)
				{
//				titlePt.y -= kSelMargin;
				r.top     -= kSelMargin;
				r.Expand(kSelMargin, 0);

				selRect = r;
				}

			if (isSel)
				{
				p.SetPenColor(cmap->GetGrayColor(kSelGrayPercentage));
				p.SetFilling(kJTrue);
				p.JPainter::Rect(r);
				p.SetFilling(kJFalse);
				}
			else
				{
				DrawTabBorder(p, r, kJFalse);
				}
			p.JPainter::String(titlePt, *title);

			itsTabRects->AppendElement(r);
			if (isSel)
				{
				r.top += kSelMargin;
				r.Shrink(kSelMargin, 0);
				}

			r.Shrink(kBorderWidth, kBorderWidth);
			DrawTab(i, p, r, itsEdge);
			DrawCloseButton(i, p, r);
			r.Expand(kBorderWidth, kBorderWidth);

			if (r.right >= ap.right - scrollArrowWidth)
				{
				if (itsFirstDrawIndex == 1 && i == count && r.right <= ap.right)
					{
					break;
					}
				itsCanScrollDownFlag = JI2B( itsFirstDrawIndex < count );
				itsLastDrawIndex     = i;
				if (r.right > ap.right - scrollArrowWidth && i > itsFirstDrawIndex)
					{
					itsLastDrawIndex--;
					}
				break;
				}

			r.left = r.right;
			}
		}

	else if (itsEdge == kLeft)
		{
		JRect r(ap.bottom - kSelMargin, ap.left + kSelMargin,
				ap.bottom - kSelMargin, ap.left + kSelMargin + tabHeight);

		for (JIndex i=itsFirstDrawIndex; i<=count; i++)
			{
			const JString* title = itsTitles->NthElement(i);
			const JBoolean isSel = JI2B(hasSelection && i == selIndex);
			const TabInfo info   = itsTabInfoList->GetElement(i);

			r.top -= 2*kBorderWidth + info.preMargin + info.postMargin + p.GetStringWidth(*title);
			if (info.closable)
				{
				r.top -= kCloseMarginWidth + itsCloseImage->GetWidth();
				}
			JPoint titlePt(r.left   + kBorderWidth + kTextMargin,
						   r.bottom - kBorderWidth - info.preMargin);
			if (isSel)
				{
//				titlePt.x -= kSelMargin;
				r.left    -= kSelMargin;
				r.Expand(0, kSelMargin);

				selRect = r;
				}

			if (isSel)
				{
				p.SetPenColor(cmap->GetGrayColor(kSelGrayPercentage));
				p.SetFilling(kJTrue);
				p.JPainter::Rect(r);
				p.SetFilling(kJFalse);
				}
			else
				{
				DrawTabBorder(p, r, kJFalse);
				}
			p.JPainter::String(90, titlePt, *title);

			itsTabRects->AppendElement(r);
			if (isSel)
				{
				r.left += kSelMargin;
				r.Shrink(0, kSelMargin);
				}

			r.Shrink(kBorderWidth, kBorderWidth);
			DrawTab(i, p, r, itsEdge);
			DrawCloseButton(i, p, r);
			r.Expand(kBorderWidth, kBorderWidth);

			if (r.top <= ap.top + scrollArrowWidth)
				{
				if (itsFirstDrawIndex == 1 && i == count && r.top >= ap.top)
					{
					break;
					}
				itsCanScrollDownFlag = JI2B( itsFirstDrawIndex < count );
				itsLastDrawIndex     = i;
				if (r.top < ap.top + scrollArrowWidth && i > itsFirstDrawIndex)
					{
					itsLastDrawIndex--;
					}
				break;
				}

			r.bottom = r.top;
			}
		}

	else if (itsEdge == kBottom)
		{
		JRect r(ap.bottom - kSelMargin - tabHeight, ap.left + kSelMargin,
				ap.bottom - kSelMargin,             ap.left + kSelMargin);

		for (JIndex i=itsFirstDrawIndex; i<=count; i++)
			{
			const JString* title = itsTitles->NthElement(i);
			const JBoolean isSel = JI2B(hasSelection && i == selIndex);
			const TabInfo info   = itsTabInfoList->GetElement(i);

			r.right += 2*kBorderWidth + info.preMargin + info.postMargin + p.GetStringWidth(*title);
			if (info.closable)
				{
				r.right += kCloseMarginWidth + itsCloseImage->GetWidth();
				}
			JPoint titlePt(r.left + kBorderWidth + info.preMargin,
						   r.top  + kBorderWidth + kTextMargin);
			if (isSel)
				{
//				titlePt.y += kSelMargin;
				r.bottom  += kSelMargin;
				r.Expand(kSelMargin, 0);

				selRect = r;
				}

			if (isSel)
				{
				p.SetPenColor(cmap->GetGrayColor(kSelGrayPercentage));
				p.SetFilling(kJTrue);
				p.JPainter::Rect(r);
				p.SetFilling(kJFalse);
				}
			else
				{
				DrawTabBorder(p, r, kJFalse);
				}
			p.JPainter::String(titlePt, *title);

			itsTabRects->AppendElement(r);
			if (isSel)
				{
				r.bottom -= kSelMargin;
				r.Shrink(kSelMargin, 0);
				}

			r.Shrink(kBorderWidth, kBorderWidth);
			DrawTab(i, p, r, itsEdge);
			DrawCloseButton(i, p, r);
			r.Expand(kBorderWidth, kBorderWidth);

			if (r.right >= ap.right - scrollArrowWidth)
				{
				if (itsFirstDrawIndex == 1 && i == count && r.right <= ap.right)
					{
					break;
					}
				itsCanScrollDownFlag = JI2B( itsFirstDrawIndex < count );
				itsLastDrawIndex     = i;
				if (r.right > ap.right - scrollArrowWidth && i > itsFirstDrawIndex)
					{
					itsLastDrawIndex--;
					}
				break;
				}

			r.left = r.right;
			}
		}

	else if (itsEdge == kRight)
		{
		JRect r(ap.top + kSelMargin, ap.right - kSelMargin - tabHeight,
				ap.top + kSelMargin, ap.right - kSelMargin);

		for (JIndex i=itsFirstDrawIndex; i<=count; i++)
			{
			const JString* title = itsTitles->NthElement(i);
			const JBoolean isSel = JI2B(hasSelection && i == selIndex);
			const TabInfo info   = itsTabInfoList->GetElement(i);

			r.bottom += 2*kBorderWidth + info.preMargin + info.postMargin + p.GetStringWidth(*title);
			if (info.closable)
				{
				r.bottom += kCloseMarginWidth + itsCloseImage->GetWidth();
				}
			JPoint titlePt(r.right - kBorderWidth - kTextMargin,
						   r.top   + kBorderWidth + info.preMargin);
			if (isSel)
				{
//				titlePt.x += kSelMargin;
				r.right   += kSelMargin;
				r.Expand(0, kSelMargin);

				selRect = r;
				}

			if (isSel)
				{
				p.SetPenColor(cmap->GetGrayColor(kSelGrayPercentage));
				p.SetFilling(kJTrue);
				p.JPainter::Rect(r);
				p.SetFilling(kJFalse);
				}
			else
				{
				DrawTabBorder(p, r, kJFalse);
				}
			p.JPainter::String(-90, titlePt, *title);

			itsTabRects->AppendElement(r);
			if (isSel)
				{
				r.right -= kSelMargin;
				r.Shrink(0, kSelMargin);
				}

			r.Shrink(kBorderWidth, kBorderWidth);
			DrawTab(i, p, r, itsEdge);
			DrawCloseButton(i, p, r);
			r.Expand(kBorderWidth, kBorderWidth);

			if (r.bottom >= ap.bottom - scrollArrowWidth)
				{
				if (itsFirstDrawIndex == 1 && i == count && r.bottom <= ap.bottom)
					{
					break;
					}
				itsCanScrollDownFlag = JI2B( itsFirstDrawIndex < count );
				itsLastDrawIndex     = i;
				if (r.bottom > ap.bottom - scrollArrowWidth && i > itsFirstDrawIndex)
					{
					itsLastDrawIndex--;
					}
				break;
				}

			r.top = r.bottom;
			}
		}

	JRect r = itsCardFile->GetFrame();
	r.Expand(kBorderWidth, kBorderWidth);
	JXDrawUpFrame(p, r, kBorderWidth);

	if (!selRect.IsEmpty())
		{
		DrawTabBorder(p, selRect, kJTrue);
		}

	DrawScrollButtons(p, lineHeight);
}
JFAID_t
CBFileListTable::GetUniqueID()
	const
{
	if (itsFileInfo->IsEmpty())
		{
		return JFAID::kMinID;
		}

	const JFAID_t prevUniqueID = JMax(itsLastUniqueID, (JFAID_t) itsFileInfo->GetElementCount());

	// this is relevant to the outmost do-while loop

	enum Range
	{
		kAboveLastUniqueID,
		kBelowLastUniqueID,
		kEmpty
	};
	Range idRange = kAboveLastUniqueID;

	do
		{
		// try the larger Id's first

		JFAID_t firstId, lastId;

		if (idRange == kAboveLastUniqueID && prevUniqueID < JFAID::kMaxID)
			{
			firstId = prevUniqueID + 1;
			lastId  = JFAID::kMaxID;
			}
		else if (idRange == kAboveLastUniqueID)
			{
			idRange = kBelowLastUniqueID;
			firstId = JFAID::kMinID;
			lastId  = JFAID::kMaxID;
			}
		else
			{
			assert( idRange == kBelowLastUniqueID );
			firstId = JFAID::kMinID;
			lastId  = prevUniqueID;
			}

		// try all possible id's in the given range

		for (JFAID_t id=firstId; id<=lastId; id++)
			{
			JIndex index;
			if (!IDToIndex(id, &index))
				{
				itsLastUniqueID = id;
				return id;
				}
			}

		if (idRange == kAboveLastUniqueID)
			{
			idRange = kBelowLastUniqueID;
			}
		else if (idRange == kBelowLastUniqueID)
			{
			idRange = kEmpty;
			}
		}
		while (idRange != kEmpty);

	// We've tried everything.  It's time to give up.

	return JFAID::kInvalidID;
}
CBCommandTable::CBCommandTable
	(
	const CBCommandManager::CmdList& cmdList,

	JXTextButton*		addCmdButton,
	JXTextButton*		removeCmdButton,
	JXTextButton*		duplicateCmdButton,
	JXScrollbarSet*		scrollbarSet,
	JXContainer*		enclosure,
	const HSizingOption	hSizing,
	const VSizingOption	vSizing,
	const JCoordinate	x,
	const JCoordinate	y,
	const JCoordinate	w,
	const JCoordinate	h
	)
	:
	JXEditTable(1,1, scrollbarSet, enclosure, hSizing,vSizing, x,y, w,h)
{
	itsTextInput   = NULL;
	itsDNDRowIndex = 0;

	itsCommandXAtom =
		(GetDisplay())->RegisterXAtom(CBCommandSelection::GetCommandXAtomName());

	// font

	(CBGetPrefsManager())->GetDefaultFont(&itsFontName, &itsFontSize);

	const JSize rowHeight = 2*kVMarginWidth + JMax(
		(GetFontManager())->GetLineHeight(JGetDefaultFontName(), kJDefaultFontSize, JFontStyle()),
		(GetFontManager())->GetLineHeight(itsFontName, itsFontSize, JFontStyle()));
	SetDefaultRowHeight(rowHeight);

	// buttons

	itsAddCmdButton       = addCmdButton;
	itsRemoveCmdButton    = removeCmdButton;
	itsDuplicateCmdButton = duplicateCmdButton;

	ListenTo(itsAddCmdButton);
	ListenTo(itsRemoveCmdButton);
	ListenTo(itsDuplicateCmdButton);

	// type menu

	itsOptionsMenu = new JXTextMenu("", this, kFixedLeft, kFixedTop, 0,0, 10,10);
	assert( itsOptionsMenu != NULL );
	itsOptionsMenu->SetToHiddenPopupMenu();
	itsOptionsMenu->SetMenuItems(kOptionsMenuStr);
	itsOptionsMenu->SetUpdateAction(JXMenu::kDisableNone);
	ListenTo(itsOptionsMenu);

	// base path

	CBProjectDocument* doc = NULL;
	if ((CBGetDocumentManager())->GetActiveProjectDocument(&doc))
		{
		itsBasePath = doc->GetFilePath();
		}

	// data

	itsCmdList = new CBCommandManager::CmdList(cmdList);
	assert( itsCmdList != NULL );
	FinishCmdListCopy(itsCmdList);

	for (JIndex i=1; i<=kColCount; i++)
		{
		AppendCols(1, kInitColWidth[i-1]);
		}

	AppendRows(itsCmdList->GetElementCount());

	UpdateButtons();
	ListenTo(&(GetTableSelection()));
}
void
CBCommandTable::HandleDNDDrop
	(
	const JPoint&		pt,
	const JArray<Atom>&	typeList,
	const Atom			action,
	const Time			time,
	const JXWidget*		source
	)
{
	JXSelectionManager* selMgr = GetSelectionManager();
	JXDNDManager* dndMgr       = GetDNDManager();
	const Atom selName         = dndMgr->GetDNDSelectionName();

	if (source == this && action == dndMgr->GetDNDActionMoveXAtom())
		{
		JPoint cell;
		if ((GetTableSelection()).GetSingleSelectedCell(&cell) &&
			itsDNDRowIndex != JIndex(cell.y) && itsDNDRowIndex != JIndex(cell.y)+1)
			{
			JIndex newIndex = itsDNDRowIndex;
			if (newIndex > JIndex(cell.y))
				{
				newIndex--;
				}
			newIndex = JMin(newIndex, GetRowCount());

			itsCmdList->MoveElementToIndex(cell.y, newIndex);
			MoveRow(cell.y, newIndex);
			SelectSingleCell(JPoint(1, newIndex));
			}
		}
	else if (source == this)
		{
		JPoint cell;
		if ((GetTableSelection()).GetSingleSelectedCell(&cell))
			{
			itsCmdList->InsertElementAtIndex(
				itsDNDRowIndex, (itsCmdList->GetElement(cell.y)).Copy());
			InsertRows(itsDNDRowIndex, 1);
			SelectSingleCell(JPoint(1, itsDNDRowIndex));
			}
		}
	else
		{
		Atom returnType;
		unsigned char* data;
		JSize dataLength;
		JXSelectionManager::DeleteMethod delMethod;
		if (selMgr->GetData(selName, time, itsCommandXAtom,
							&returnType, &data, &dataLength, &delMethod))
			{
			if (returnType == itsCommandXAtom)
				{
				const std::string s((char*) data, dataLength);
				std::istringstream input(s);

				CBCommandManager::CmdInfo cmdInfo =
					CBCommandManager::ReadCmdInfo(input, CBCommandManager::GetCurrentCmdInfoFileVersion());
				if (!input.fail())
					{
					const JIndex newIndex = JMax(JIndex(1), itsDNDRowIndex);
					itsCmdList->InsertElementAtIndex(newIndex, cmdInfo);
					InsertRows(newIndex, 1);
					SelectSingleCell(JPoint(1, newIndex));

					if (action == dndMgr->GetDNDActionMoveXAtom())
						{
						selMgr->SendDeleteRequest(selName, time);
						}
					}
				}

			selMgr->DeleteData(&data, delMethod);
			}
		}

	HandleDNDLeave();
}
void
JX2DCurveNameList::AdjustColWidth()
{
	SetColWidth(1, JMax(itsMinColWidth, GetApertureWidth()));
}
void
JXRadioGroupDialog::BuildWindow
	(
	const JCharacter*			windowTitle,
	const JCharacter*			prompt,
	const JPtrArray<JString>&	choiceList,
	const JPtrArray<JString>*	shortcutList
	)
{
JIndex i;

	const JSize actionCount = choiceList.GetElementCount();

	JXWindow* window = new JXWindow(this, 10,10, windowTitle);
	assert( window != NULL );

	JCoordinate y = kFirstItemTop;

	// instructions

	JXStaticText* instrText =
		new JXStaticText(prompt, window,
						 JXWidget::kFixedLeft, JXWidget::kFixedTop,
						 kHMarginWidth,y, 0,0);
	assert( instrText != NULL );

	y += instrText->GetFrameHeight() + kItemVDelta;

	// radio group

	const JCoordinate kInitRGWidth = 10;	// arbitrary, >0

	itsRG =
		new JXRadioGroup(window, JXWidget::kFixedLeft, JXWidget::kFixedTop,
						 kHMarginWidth,y,
						 kInitRGWidth, kItemVDelta + actionCount * kItemVSeparation);
	assert( itsRG != NULL );

	// choices

	JCoordinate wmin = 0;
	JPtrArray<JXRadioButton> buttonList(JPtrArrayT::kForgetAll, actionCount);
	for (i=1; i<=actionCount; i++)
		{
		JXTextRadioButton* button =
			new JXTextRadioButton(i, *(choiceList.NthElement(i)), itsRG,
								  JXWidget::kFixedLeft, JXWidget::kFixedTop,
								  kRGHLMarginWidth, kItemVDelta + (i-1) * kItemVSeparation,
								  10,kTextHeight);
		assert( button != NULL );

		if (shortcutList != NULL)
			{
			button->SetShortcuts(*(shortcutList->NthElement(i)));
			}

		buttonList.Append(button);
		wmin = JMax(button->GetPreferredWidth(), wmin);
		}

	// all choices should be the same width

	for (i=1; i<=actionCount; i++)
		{
		(buttonList.NthElement(i))->SetSize(wmin, kTextHeight);
		}

	wmin += kRGHLMarginWidth + kRGHRMarginWidth;
	itsRG->AdjustSize(wmin - kInitRGWidth, 0);

	const JCoordinate wminInstr = instrText->GetFrameWidth();
	if (wmin < wminInstr)
		{
		const JCoordinate delta = (wminInstr - wmin)/2;
		itsRG->Move(delta, 0);
		wmin = wminInstr;
		}

	y = (itsRG->GetFrame()).bottom + kRGButtonVDelta;

	// OK and Cancel buttons

	wmin += 2*kHMarginWidth;
	const JCoordinate wminButton = 3*kMinButtonHMargin + 2*kButtonWidth;
	if (wmin < wminButton)
		{
		const JCoordinate delta = (wminButton - wmin)/2;
		instrText->Move(delta, 0);
		itsRG->Move(delta, 0);
		wmin = wminButton;
		}

	const JCoordinate buttonX = (wmin - 2*kButtonWidth)/3;

	JXTextButton* cancelButton =
		new JXTextButton("Cancel", window,
						 JXWidget::kFixedLeft, JXWidget::kFixedTop,
						 buttonX,y, kButtonWidth,kTextHeight);
	assert( cancelButton != NULL );

	JXTextButton* okButton =
		new JXTextButton("OK", window,
						 JXWidget::kFixedLeft, JXWidget::kFixedTop,
						 wmin - buttonX - (kButtonWidth+2), y-1,
						 kButtonWidth+2, kTextHeight+2);
	assert( okButton != NULL );
	okButton->SetShortcuts("^M");

	SetButtons(okButton, cancelButton);

	// window size

	window->SetSize(wmin, y + kItemVSeparation);
}
void
GLFitDescriptionList::AdjustColWidth()
{
	SetColWidth(1, JMax(itsMinColWidth, GetApertureWidth()));
}
void
CBSymbolTable::AdjustColWidths()
{
	const JCoordinate minWidth = kIconWidth + itsMaxStringWidth + kTextPadding;
	SetColWidth(1, JMax(minWidth, GetApertureWidth()));
}
Esempio n. 26
0
void
LLDBGetAssembly::HandleSuccess
	(
	const JString& cmdData
	)
{
	LLDBLink* link = dynamic_cast<LLDBLink*>(CMGetLink());
	if (link == NULL)
		{
		return;
		}

	lldb::SBCommandInterpreter interp = link->GetDebugger()->GetCommandInterpreter();
	if (!interp.IsValid())
		{
		return;
		}

	const CMLocation& loc = (GetDirector())->GetDisassemblyLocation();

	const JString cmd = "disassemble -n " + JPrepArgForExec(loc.GetFunctionName());
	lldb::SBCommandReturnObject result;
	interp.HandleCommand(cmd, result);

	JPtrArray<JString> addrList(JPtrArrayT::kDeleteAll);
	JString instText;

	if (result.IsValid() && result.Succeeded() && result.HasResult())
		{
		std::istringstream input(result.GetOutput());
		JString line, s;
		JSize maxOffsetLength = 0;
		while (!input.eof() && !input.fail())
			{
			line = JReadLine(input);

			JIndex i;
			if (line.LocateSubstring(":", &i) && i < line.GetLength())
				{
				s = line.GetSubstring(1, i-1);
				if (s.BeginsWith("->") && s.GetLength() > 2)
					{
					s = s.GetSubstring(3, s.GetLength());
					}
				s.TrimWhitespace();
				addrList.Append(s);

				JIndexRange r;
				if (offsetPattern.Match(s, &r))
					{
					maxOffsetLength = JMax(maxOffsetLength, r.GetLength());
					}

				if (!instText.IsEmpty())
					{
					instText.AppendCharacter('\n');
					}
				s = line.GetSubstring(i+1, line.GetLength());
				s.TrimWhitespace();
				instText.Append(s);
				}
			}

		const JSize count = addrList.GetElementCount();
		for (JIndex i=1; i<count; i++)
			{
			JString* s = addrList.NthElement(i);
			JIndexRange r;
			if (offsetPattern.Match(*s, &r))
				{
				const JSize pad = maxOffsetLength - r.GetLength();
				for (JIndex j=0; j<pad; j++)
					{
					s->InsertCharacter('0', r.first+2);
					}
				}
			}
		}

	(GetDirector())->DisplayDisassembly(&addrList, instText);
}
JXFSBindingTable::JXFSBindingTable
	(
	JFSBindingList*		list,
	JXTextButton*		addButton,
	JXTextButton*		removeButton,
	JXTextButton*		duplicateButton,
	JXScrollbarSet*		scrollbarSet,
	JXContainer*		enclosure,
	const HSizingOption hSizing,
	const VSizingOption vSizing,
	const JCoordinate	x,
	const JCoordinate	y,
	const JCoordinate	w,
	const JCoordinate	h
	)
	:
	JXEditTable(1,1, scrollbarSet, enclosure, hSizing, vSizing, x, y, w, h),
	itsBindingList(list),
	itsAddButton(addButton),
	itsRemoveButton(removeButton),
	itsDuplicateButton(duplicateButton),
	itsTextInput(NULL)
{
	// row height

	const JSize rowHeight = 2*kVMarginWidth + JMax(
		(GetFontManager())->GetLineHeight(JGetDefaultFontName(), kJDefaultFontSize, JFontStyle()),
		(GetFontManager())->GetLineHeight(JGetMonospaceFontName(), kJDefaultMonoFontSize, JFontStyle()));
	SetDefaultRowHeight(rowHeight);

	// buttons

	ListenTo(itsAddButton);
	ListenTo(itsRemoveButton);
	ListenTo(itsDuplicateButton);

	// type menu

	itsTypeMenu = new JXTextMenu("", this, kFixedLeft, kFixedTop, 0,0, 10,10);
	assert( itsTypeMenu != NULL );
	itsTypeMenu->Hide();
	itsTypeMenu->SetToHiddenPopupMenu(kJTrue);
	itsTypeMenu->SetMenuItems(kTypeMenuStr);
	itsTypeMenu->SetUpdateAction(JXMenu::kDisableNone);
	ListenTo(itsTypeMenu);

	// regex for testing

	itsTestRegex = new JRegex;
	assert( itsTestRegex != NULL );

	// data

	for (JIndex i=1; i<=kColCount; i++)
		{
		AppendCols(1, kInitColWidth[i-1]);
		}
	UpdateColWidths();

	const JSize rowCount = itsBindingList->GetElementCount();
	AppendRows(rowCount);

	UpdateButtons();
	ListenTo(&(GetTableSelection()));
}
Esempio n. 28
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);
}