JBoolean JXWidget::ScrollToRectCentered ( const JRect& origRect, const JBoolean forceScroll ) { const JRect ap = GetAperture(); if (!forceScroll && ap.Contains(origRect)) { return kJFalse; } JRect r = origRect; const JCoordinate dw = ap.width() - r.width(); if (dw > 0) { r.Shrink(-dw/2, 0); } const JCoordinate dh = ap.height() - r.height(); if (dh > 0) { r.Shrink(0, -dh/2); } return ScrollToRect(r); }
void JXHorizPartition::HandleMouseDown ( const JPoint& pt, const JXMouseButton button, const JSize clickCount, const JXButtonStates& buttonStates, const JXKeyModifiers& modifiers ) { itsDragType = kInvalidDrag; if (button != kJXLeftButton) { return; } if (modifiers.meta()) { itsDragType = kDragAll; PrepareToDragAll(pt.x, &itsMinDragX, &itsMaxDragX); } else { itsDragType = kDragOne; PrepareToDrag(pt.x, &itsMinDragX, &itsMaxDragX); } JPainter* p = CreateDragInsidePainter(); const JRect ap = GetAperture(); p->Line(pt.x, ap.top, pt.x, ap.bottom); itsPrevPt = pt; }
void JXTreeListWidget::ScrollToShowChildren ( const JIndex index ) { const JTreeNode* node = itsTreeList->GetNode(index); if (!node->HasChildren()) { return; } // scroll minimum to show last child const JTreeNode* lastChild = node->GetChild(node->GetChildCount()); ScrollToNode(lastChild); // if original node not visible, force it to be const JCoordinate y = GetRowTop(index); if (y < (GetAperture()).top) { ScrollTo(0, y); } }
void JXTabGroup::PlaceCardFile() { const JSize h = kSelMargin + kBorderWidth + 2*kTextMargin + (GetFontManager())->GetLineHeight(itsFontName, itsFontSize, itsFontStyle); JRect r = GetAperture(); if (itsEdge == kTop) { r.top += h; } else if (itsEdge == kLeft) { r.left += h; } else if (itsEdge == kBottom) { r.bottom -= h; } else if (itsEdge == kRight) { r.right -= h; } else { assert( 0 ); } r.Shrink(kBorderWidth, kBorderWidth); itsCardFile->Place(r.left, r.top); itsCardFile->SetSize(r.width(), r.height()); }
void JXTabGroup::ScrollUpToTab ( const JIndex index ) { assert( itsTitles->IndexValid(index) ); assert( index > itsFirstDrawIndex ); const JFontManager* fontMgr = GetFontManager(); const JFontID fontID = fontMgr->GetFontID(itsFontName, itsFontSize, itsFontStyle); const JCoordinate scrollArrowWidth = 2*(kArrowWidth + kBorderWidth); const JRect ap = GetAperture(); const JCoordinate min = (itsEdge == kTop || itsEdge == kBottom ? ap.left : ap.top); const JCoordinate max = (itsEdge == kTop || itsEdge == kBottom ? ap.right : ap.bottom); JCoordinate left = min + kSelMargin; JCoordinate right = left; JArray<JCoordinate> widthList; const JSize count = itsTitles->GetElementCount(); JBoolean offScreen = kJFalse; for (JIndex i=itsFirstDrawIndex; i<=index; i++) { const TabInfo info = itsTabInfoList->GetElement(index); right += 2*kBorderWidth + info.preMargin + info.postMargin + fontMgr->GetStringWidth(fontID, itsFontSize, itsFontStyle, *(itsTitles->NthElement(i))); if (info.closable) { right += kCloseMarginWidth + itsCloseImage->GetWidth(); } widthList.AppendElement(right - left); if (!offScreen && right >= max - scrollArrowWidth && !(itsFirstDrawIndex == 1 && i == count && right <= max)) { offScreen = kJTrue; } left = right; } if (offScreen) { JIndex i = 1; while (right > max - scrollArrowWidth && itsFirstDrawIndex < index) { right -= widthList.GetElement(i); itsFirstDrawIndex++; i++; } } }
JBoolean JXWidget::ScrollTo ( const JCoordinate x, const JCoordinate y ) { const JRect ap = GetAperture(); return Scroll(ap.left - x, ap.top - y); }
void JXTextMenuTable::GetSubmenuPoints ( const JIndex itemIndex, JPoint* leftPt, JPoint* rightPt ) { const JRect cellRect = GetCellRect(JPoint(1,itemIndex)); const JRect ap = GetAperture(); *leftPt = JPoint(ap.left+1, cellRect.top); *rightPt = JPoint(ap.right-1, cellRect.top); }
void JXImageWidget::AdjustBounds() { if (itsAdjustBoundsTask != NULL) { return; } JRect newBounds = GetAperture(); if (itsImage != NULL) { newBounds = JCovering(newBounds, itsImage->GetBounds()); } SetBounds(newBounds.width(), newBounds.height()); }
void JXPathInput::BoundsMoved ( const JCoordinate dx, const JCoordinate dy ) { JXInputField::BoundsMoved(dx, dy); const JRect ap = GetAperture(); if (ap.left != 0) { SetHint(GetText()); } else { ClearHint(); } }
void JXHorizPartition::HandleMouseDrag ( const JPoint& origPt, const JXButtonStates& buttonStates, const JXKeyModifiers& modifiers ) { if (itsDragType != kInvalidDrag) { JPoint pt = origPt; // keep compartment width larger than minimum if (pt.x < itsMinDragX) { pt.x = itsMinDragX; } else if (pt.x > itsMaxDragX) { pt.x = itsMaxDragX; } // check if we have moved if (pt.x != itsPrevPt.x) { JPainter* p = NULL; const JBoolean ok = GetDragPainter(&p); assert( ok ); JRect ap = GetAperture(); p->Line(itsPrevPt.x, ap.top, itsPrevPt.x, ap.bottom); p->Line(pt.x, ap.top, pt.x, ap.bottom); itsPrevPt = pt; } } }
void JXVertPartition::HandleMouseDrag ( const JPoint& origPt, const JXButtonStates& buttonStates, const JXKeyModifiers& modifiers ) { if (itsDragType != kInvalidDrag) { JPoint pt = origPt; // keep compartment width larger than minimum if (pt.y < itsMinDragY) { pt.y = itsMinDragY; } else if (pt.y > itsMaxDragY) { pt.y = itsMaxDragY; } // check if we have moved if (pt.y != itsPrevPt.y) { JPainter* p = NULL; const JBoolean ok = GetDragPainter(&p); assert( ok ); JRect ap = GetAperture(); p->Line(ap.left, itsPrevPt.y, ap.right, itsPrevPt.y); p->Line(ap.left, pt.y, ap.right, pt.y); itsPrevPt = pt; } } }
void JXDocktab::Draw ( JXWindowPainter& p, const JRect& rect ) { const JColormap* cmap = p.GetColormap(); // drag region JXWindow* w = GetWindow(); JXWindow* focusWindow; JXDockWidget* dock; if (w->GetDockWidget(&dock) && (dock->GetDockDirector())->GetFocusWindow(&focusWindow) && focusWindow == w) { p.SetPenColor(itsFocusColor); p.SetFilling(kJTrue); p.JPainter::Rect(rect); p.SetPenColor((GetColormap())->GetBlackColor()); p.SetFilling(kJFalse); p.SetPenColor(cmap->GetWhiteColor()); } else { p.SetPenColor(cmap->GetGrayColor(60)); } const JRect ap = GetAperture(); const JCoordinate y1 = ap.top + 1; const JCoordinate y2 = ap.bottom - 2; p.Line(3, y1, 3, y2); p.Line(5, y1, 5, y2); }
void JXHorizPartition::Draw ( JXWindowPainter& p, const JRect& rect ) { p.SetPenColor((p.GetColormap())->GetGray60Color()); const JRect ap = GetAperture(); const JCoordinate y1 = ap.top+1; const JCoordinate y2 = ap.bottom-2; const JSize compartmentCount = GetCompartmentCount(); JCoordinate x = 0; for (JIndex i=1; i<compartmentCount; i++) { x += GetCompartmentSize(i); p.Line(x+1, y1, x+1, y2); p.Line(x+3, y1, x+3, y2); x += kDragRegionSize; } }
void JXVertPartition::Draw ( JXWindowPainter& p, const JRect& rect ) { p.SetPenColor((p.GetColormap())->GetGray60Color()); const JRect ap = GetAperture(); const JCoordinate x1 = ap.left+1; const JCoordinate x2 = ap.right-2; const JSize compartmentCount = GetCompartmentCount(); JCoordinate y = 0; for (JIndex i=1; i<compartmentCount; i++) { y += GetCompartmentSize(i); p.Line(x1, y+1, x2, y+1); p.Line(x1, y+3, x2, y+3); y += kDragRegionSize; } }
void JXHorizPartition::HandleMouseUp ( const JPoint& pt, const JXMouseButton button, const JXButtonStates& buttonStates, const JXKeyModifiers& modifiers ) { if (itsDragType != kInvalidDrag) { // erase the line JPainter* p = NULL; const JBoolean ok = GetDragPainter(&p); assert( ok ); JRect ap = GetAperture(); p->Line(itsPrevPt.x, ap.top, itsPrevPt.x, ap.bottom); DeleteDragPainter(); // set the compartment widths if (itsDragType == kDragAll) { AdjustCompartmentsAfterDragAll(itsPrevPt.x); } else { assert( itsDragType == kDragOne ); AdjustCompartmentsAfterDrag(itsPrevPt.x); } } itsDragType = kInvalidDrag; }
void JXTabGroup::DrawTabBorder ( JXWindowPainter& p, const JRect& rect, const JBoolean isSelected ) { JXDrawUpFrame(p, rect, kBorderWidth); const JColormap* cmap = p.GetColormap(); if (itsEdge == kTop) { p.SetPenColor(cmap->GetDefaultBackColor()); p.JPainter::Point(rect.topLeft()); p.JPainter::Point(rect.topRight() + JPoint(-1,0)); p.JPainter::Point(rect.topRight() + JPoint(-2,0)); p.JPainter::Point(rect.topRight() + JPoint(-1,1)); p.JPainter::Point(rect.topRight() + JPoint(-1,2)); p.SetPenColor(cmap->Get3DLightColor()); p.JPainter::Point(rect.topLeft() + JPoint(kBorderWidth, kBorderWidth)); p.SetPenColor(cmap->Get3DShadeColor()); p.JPainter::Point(rect.topRight() + JPoint(-kBorderWidth-1, kBorderWidth)); if (isSelected) { JRect r(rect.bottom - kBorderWidth, rect.left + kBorderWidth, rect.bottom, rect.right - kBorderWidth); p.SetPenColor(cmap->GetGrayColor(kSelGrayPercentage)); p.JPainter::Rect(r); p.JPainter::Point(rect.topLeft() + JPoint(-1,kSelMargin+kBorderWidth)); p.SetPenColor(cmap->Get3DLightColor()); p.JPainter::Point(rect.bottomLeft() + JPoint(1,-1)); p.JPainter::Point(rect.bottomRight() + JPoint(-2,-1)); p.JPainter::Point(rect.bottomRight() + JPoint(-1,-2)); p.JPainter::Point(rect.bottomRight() + JPoint(-1,-1)); } } else if (itsEdge == kLeft) { p.SetPenColor(cmap->GetDefaultBackColor()); p.JPainter::Point(rect.topLeft()); p.JPainter::Point(rect.bottomLeft() + JPoint(0,-1)); p.JPainter::Point(rect.bottomLeft() + JPoint(0,-2)); p.JPainter::Point(rect.bottomLeft() + JPoint(1,-1)); p.JPainter::Point(rect.bottomLeft() + JPoint(2,-1)); p.SetPenColor(cmap->Get3DLightColor()); p.JPainter::Point(rect.topLeft() + JPoint(kBorderWidth, kBorderWidth)); p.SetPenColor(cmap->Get3DShadeColor()); p.JPainter::Point(rect.bottomLeft() + JPoint(kBorderWidth, -kBorderWidth-1)); if (isSelected) { JRect r(rect.top + kBorderWidth, rect.right - kBorderWidth, rect.bottom - kBorderWidth, rect.right); p.SetPenColor(cmap->GetGrayColor(kSelGrayPercentage)); p.JPainter::Rect(r); p.JPainter::Point(rect.topLeft() + JPoint(kSelMargin+kBorderWidth,-1)); p.SetPenColor(cmap->Get3DLightColor()); p.JPainter::Point(rect.topRight() + JPoint(-1,1)); if (rect.bottom < (GetAperture()).bottom) { p.JPainter::Point(rect.bottomRight() + JPoint(-1,-1)); p.JPainter::Point(rect.bottomRight() + JPoint(-2,-1)); p.JPainter::Point(rect.bottomRight() + JPoint(-1,-2)); } } } else if (itsEdge == kBottom) { p.SetPenColor(cmap->GetDefaultBackColor()); p.JPainter::Point(rect.bottomLeft() + JPoint(0,-1)); p.JPainter::Point(rect.bottomLeft() + JPoint(0,-2)); p.JPainter::Point(rect.bottomLeft() + JPoint(1,-1)); p.JPainter::Point(rect.bottomLeft() + JPoint(2,-1)); p.JPainter::Point(rect.bottomRight() + JPoint(-1,-1)); p.SetPenColor(cmap->Get3DLightColor()); p.JPainter::Point(rect.bottomLeft() + JPoint(kBorderWidth, -kBorderWidth-1)); p.SetPenColor(cmap->Get3DShadeColor()); p.JPainter::Point(rect.bottomRight() + JPoint(-kBorderWidth-1, -kBorderWidth-1)); if (isSelected) { JRect r(rect.top, rect.left + kBorderWidth, rect.top + kBorderWidth, rect.right - kBorderWidth); p.SetPenColor(cmap->GetGrayColor(kSelGrayPercentage)); p.JPainter::Rect(r); p.SetPenColor(cmap->Get3DShadeColor()); if (rect.left > (GetAperture()).left) { p.JPainter::Point(rect.topLeft()); } p.JPainter::Point(rect.topRight() + JPoint(-1,0)); p.JPainter::Point(rect.topRight() + JPoint(-2,0)); p.JPainter::Point(rect.topRight() + JPoint(-2,1)); } } else if (itsEdge == kRight) { p.SetPenColor(cmap->GetDefaultBackColor()); p.JPainter::Point(rect.topRight() + JPoint(-1,0)); p.JPainter::Point(rect.topRight() + JPoint(-2,0)); p.JPainter::Point(rect.topRight() + JPoint(-1,1)); p.JPainter::Point(rect.topRight() + JPoint(-1,2)); p.JPainter::Point(rect.bottomRight() + JPoint(-1,-1)); p.SetPenColor(cmap->Get3DLightColor()); p.JPainter::Point(rect.topRight() + JPoint(-kBorderWidth-1, kBorderWidth)); p.SetPenColor(cmap->Get3DShadeColor()); p.JPainter::Point(rect.bottomRight() + JPoint(-kBorderWidth-1, -kBorderWidth-1)); if (isSelected) { JRect r(rect.top + kBorderWidth, rect.left, rect.bottom - kBorderWidth, rect.left + kBorderWidth); p.SetPenColor(cmap->GetGrayColor(kSelGrayPercentage)); p.JPainter::Rect(r); p.SetPenColor(cmap->Get3DShadeColor()); if (rect.top > (GetAperture()).top) { p.JPainter::Point(rect.topLeft()); } p.JPainter::Point(rect.bottomLeft() + JPoint(0,-1)); p.JPainter::Point(rect.bottomLeft() + JPoint(0,-2)); p.JPainter::Point(rect.bottomLeft() + JPoint(1,-2)); } } }
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); }
void TestWidget::DrawStuff ( JPainter& p ) { JIndex i; JXColormap* colormap = GetColormap(); p.SetPenColor(colormap->GetGreenColor()); JRect ellipseRect(100,50,150,300); p.Ellipse(ellipseRect); p.SetPenColor(colormap->GetBlackColor()); if (itsFillFlag) { p.SetFilling(kJTrue); } JRect ap = GetAperture(); p.Line(ap.topLeft(), ap.bottomRight()); p.Line(ap.topRight(), ap.bottomLeft()); p.SetLineWidth(2); p.SetFontName(JXGetTimesFontName()); p.SetFontSize(18); p.Image(*itsHomeImage, itsHomeImage->GetBounds(), itsHomeRect); its2Rect = JRect(150, 5, 200, 30); p.SetPenColor(colormap->GetRedColor()); p.Rect(its2Rect); p.SetFontStyle(colormap->GetRedColor()); p.String(its2Rect.topLeft(), "2", its2Rect.width(), JPainter::kHAlignCenter, its2Rect.height(), JPainter::kVAlignCenter); its3Rect = JRect(10, 150, 40, 200); p.SetPenColor(colormap->GetBlueColor()); p.Rect(its3Rect); p.SetFontStyle(colormap->GetBlueColor()); p.String(its3Rect.topLeft(), "3", its3Rect.width(), JPainter::kHAlignCenter, its3Rect.height(), JPainter::kVAlignCenter); p.SetLineWidth(1); p.SetFont(JGetDefaultFontName(), kJXDefaultFontSize, colormap->GetBlackColor()); p.ShiftOrigin(10,10); p.Point(0,0); for (i=1; i<=itsRandPointCount; i++) { p.Point(itsRNG.UniformLong(0,200), itsRNG.UniformLong(0,200)); } p.SetPenColor(colormap->GetRedColor()); p.Line(10,0, 0,10); p.SetPenColor(colormap->GetGreenColor()); p.LineTo(10,20); p.SetPenColor(colormap->GetBlueColor()); p.LineTo(0,30); p.ShiftOrigin(2,0); JPoint textPt(40,30); p.String( 0.0, textPt, "Hello"); p.String( 90.0, textPt, "Hello"); p.String(180.0, textPt, "Hello"); p.String(270.0, textPt, "Hello"); p.Rect(310, 70, 80, 80); p.String( 0.0, 310, 70, "Hello", 80, JPainter::kHAlignCenter, 80, JPainter::kVAlignCenter); p.String( 90.0, 310,150, "Hello", 80, JPainter::kHAlignCenter, 80, JPainter::kVAlignCenter); p.String(180.0, 390,150, "Hello", 80, JPainter::kHAlignCenter, 80, JPainter::kVAlignCenter); p.String(270.0, 390, 70, "Hello", 80, JPainter::kHAlignCenter, 80, JPainter::kVAlignCenter); p.Rect(200, 10, 100, 50); p.String(200, 10, "Hello", 100, JPainter::kHAlignLeft); p.String(200, 10+p.GetLineHeight(), "Hello", 100, JPainter::kHAlignCenter); p.String(200, 10+2*p.GetLineHeight(), "Hello", 100, JPainter::kHAlignRight); p.SetPenColor(colormap->GetYellowColor()); JRect r(0,11,80,91); p.Rect(r); r.Shrink(1,1); p.SetPenColor(colormap->GetBlueColor()); p.Ellipse(r); r.Shrink(1,1); p.SetPenColor(colormap->GetRedColor()); p.Arc(r, 270.0-45.0, -270.0); JPolygon poly; poly.AppendElement(JPoint(0,85)); poly.AppendElement(JPoint(10,85)); poly.AppendElement(JPoint(5,95)); p.Polygon(poly); p.Line(0,100, 2,98); p.LineTo(4,100); p.LineTo(2,102); p.LineTo(0,100); poly.SetElement(1, JPoint(0,5)); poly.SetElement(2, JPoint(2,0)); poly.SetElement(3, JPoint(4,5)); p.Polygon(2,105, poly); // test filling rule p.SetPenColor(colormap->GetRedColor()); p.SetFilling(kJTrue); JPolygon fillRulePoly; fillRulePoly.AppendElement(JPoint(175,45)); fillRulePoly.AppendElement(JPoint(165,65)); fillRulePoly.AppendElement(JPoint(190,50)); fillRulePoly.AppendElement(JPoint(160,50)); fillRulePoly.AppendElement(JPoint(185,65)); p.Polygon(fillRulePoly); p.SetFilling(kJFalse); // dashed lines p.DrawDashedLines(kJTrue); p.SetPenColor(colormap->GetBlackColor()); JArray<JSize> dashList; // pixel rulers dashList.AppendElement(1); dashList.AppendElement(1); p.SetDashList(dashList); p.Line(100,110, 200,110); p.Line(100,114, 200,114); p.Line(100,118, 200,118); dashList.SetElement(1, 2); // simple pattern dashList.SetElement(2, 3); p.SetDashList(dashList); p.Line(100,112, 200,112); p.SetFontStyle(JFontStyle(kJFalse, kJFalse, 1, kJFalse)); p.String(130,155, "underline without dashes"); p.SetDashList(dashList, 3); // test offset p.Line(100,116, 200,116); dashList.SetElement(1, 1); // example with odd # of values from X manuals dashList.SetElement(2, 2); dashList.AppendElement(3); p.SetDashList(dashList); p.Line(100,120, 200,120); dashList.SetElement(1, 5); // dash-dot pattern dashList.SetElement(2, 2); dashList.SetElement(3, 1); dashList.AppendElement(2); p.SetDashList(dashList); p.Line(100,122, 200,122); p.Ellipse(210,110, 20,20); p.DrawDashedLines(kJFalse); p.Ellipse(213,113, 14,14); p.Rect(207,107, 26,26); p.SetPenColor(colormap->GetYellowColor()); p.DrawDashedLines(kJTrue); p.Ellipse(213,113, 14,14); // animated colors p.SetFilling(kJTrue); JCoordinate x = 25; const JSize animColorCount = itsAnimColorList->GetElementCount(); for (i=1; i<=animColorCount; i++) { p.SetPenColor(itsAnimColorList->GetElement(i)); p.Rect(x, 150, 10, 10); x += 10; } // icons p.Image(*itsXPMImage, itsXPMImage->GetBounds(), 33,110); p.Image(*itsPartialXPMImage, itsXPMImage->GetBounds(), 50,121); // *NEVER* do this in your code! I do it here ONLY to test JXColormap. // (Besides, look at how messy it is!) unsigned long xPixel; if (colormap->CalcPreallocatedXPixel(62720, 56832, 45824, &xPixel)) { JXDisplay* display = GetDisplay(); Display* xdisplay = display->GetXDisplay(); GC gc = DefaultGC(xdisplay, display->GetScreen()); XSetForeground(xdisplay, gc, xPixel); XFillRectangle(xdisplay, (GetWindow())->GetXWindow(), gc, 110,40, 20,20); } }
void CBSymbolTable::RebuildTable() { (JXGetApplication())->DisplayBusyCursor(); const JPoint scrollPt = (GetAperture()).topLeft(); ClearSelection(); itsKeyBuffer.Clear(); itsMaxStringWidth = 0; if (itsVisibleListLockedFlag) { const JSize count = itsVisibleList->GetElementCount(); for (JIndex i=1; i<=count; i++) { const JIndex j = itsVisibleList->GetElement(i); const JString* signature; itsSymbolList->GetSignature(j, &signature); CBLanguage lang; CBSymbolList::Type type; CalcColWidths(itsSymbolList->GetSymbol(j, &lang, &type), signature); } } else if (itsNameFilter != NULL || itsNameLiteral != NULL) { itsVisibleList->RemoveAll(); const JSize symbolCount = itsSymbolList->GetElementCount(); for (JIndex i=1; i<=symbolCount; i++) { CBLanguage lang; CBSymbolList::Type type; const JString& symbolName = itsSymbolList->GetSymbol(i, &lang, &type); const JString* signature; itsSymbolList->GetSignature(i, &signature); if (/* (CBGetSymbolTypeList())->IsVisible(type) && */ ((itsNameFilter != NULL && itsNameFilter->Match(symbolName)) || (itsNameLiteral != NULL && symbolName.Contains(*itsNameLiteral))) ) { itsVisibleList->AppendElement(i); CalcColWidths(symbolName, signature); } } } else // optimize because scanning 1e5 symbols takes a while! { const JSize symbolCount = itsSymbolList->GetElementCount(); if (itsVisibleList->GetElementCount() > symbolCount) { itsVisibleList->RemoveNextElements( symbolCount+1, itsVisibleList->GetElementCount() - symbolCount); } while (itsVisibleList->GetElementCount() < symbolCount) { itsVisibleList->AppendElement(itsVisibleList->GetElementCount()+1); } } const JSize rowCount = itsVisibleList->GetElementCount(); if (GetRowCount() < rowCount) { AppendRows(rowCount - GetRowCount()); } else if (GetRowCount() > rowCount) { RemoveNextRows(rowCount+1, GetRowCount() - rowCount); } AdjustColWidths(); ScrollTo(scrollPt); Refresh(); }
void JXTabGroup::DrawScrollButtons ( JXWindowPainter& p, const JCoordinate lineHeight ) { itsScrollUpRect = itsScrollDownRect = JRect(0,0,0,0); if (!itsCanScrollUpFlag && !itsCanScrollDownFlag) { return; } const JCoordinate w = 2*(kArrowWidth + kBorderWidth); const JCoordinate h = kSelMargin + kBorderWidth + 2*kTextMargin + lineHeight; const JRect ap = GetAperture(); const JColormap* cmap = p.GetColormap(); if (itsEdge == kTop) { JRect r(ap.top, ap.right - w, ap.top + h, ap.right); p.SetPenColor(cmap->GetDefaultBackColor()); p.SetFilling(kJTrue); p.JPainter::Rect(r); p.SetFilling(kJFalse); r.Shrink(kBorderWidth, 0); r.top = r.bottom = r.ycenter(); r.top -= kArrowWidth/2; r.bottom += kArrowWidth/2 + kArrowWidth%2; r.right = r.left + kArrowWidth; if (itsCanScrollUpFlag && itsScrollUpPushedFlag) { JXDrawDownArrowLeft(p, r, kBorderWidth); } else if (itsCanScrollUpFlag) { JXDrawUpArrowLeft(p, r, kBorderWidth); } else { JXFillArrowLeft(p, r, cmap->GetInactiveLabelColor()); } itsScrollUpRect = r; r.left += kArrowWidth; r.right += kArrowWidth; if (itsCanScrollDownFlag && itsScrollDownPushedFlag) { JXDrawDownArrowRight(p, r, kBorderWidth); } else if (itsCanScrollDownFlag) { JXDrawUpArrowRight(p, r, kBorderWidth); } else { JXFillArrowRight(p, r, cmap->GetInactiveLabelColor()); } itsScrollDownRect = r; } else if (itsEdge == kLeft) { JRect r(ap.top, ap.left, ap.top + w, ap.left + h); p.SetPenColor(cmap->GetDefaultBackColor()); p.SetFilling(kJTrue); p.JPainter::Rect(r); p.SetFilling(kJFalse); r.Shrink(0, kBorderWidth); r.left = r.right = r.xcenter(); r.left -= kArrowWidth/2; r.right += kArrowWidth/2 + kArrowWidth%2; r.bottom = r.top + kArrowWidth; if (itsCanScrollDownFlag && itsScrollDownPushedFlag) { JXDrawDownArrowUp(p, r, kBorderWidth); } else if (itsCanScrollDownFlag) { JXDrawUpArrowUp(p, r, kBorderWidth); } else { JXFillArrowUp(p, r, cmap->GetInactiveLabelColor()); } itsScrollDownRect = r; r.top += kArrowWidth; r.bottom += kArrowWidth; if (itsCanScrollUpFlag && itsScrollUpPushedFlag) { JXDrawDownArrowDown(p, r, kBorderWidth); } else if (itsCanScrollUpFlag) { JXDrawUpArrowDown(p, r, kBorderWidth); } else { JXFillArrowDown(p, r, cmap->GetInactiveLabelColor()); } itsScrollUpRect = r; } else if (itsEdge == kBottom) { JRect r(ap.bottom - h, ap.right - w, ap.bottom, ap.right); p.SetPenColor(cmap->GetDefaultBackColor()); p.SetFilling(kJTrue); p.JPainter::Rect(r); p.SetFilling(kJFalse); r.Shrink(kBorderWidth, 0); r.top = r.bottom = r.ycenter(); r.top -= kArrowWidth/2; r.bottom += kArrowWidth/2 + kArrowWidth%2; r.right = r.left + kArrowWidth; if (itsCanScrollUpFlag && itsScrollUpPushedFlag) { JXDrawDownArrowLeft(p, r, kBorderWidth); } else if (itsCanScrollUpFlag) { JXDrawUpArrowLeft(p, r, kBorderWidth); } else { JXFillArrowLeft(p, r, cmap->GetInactiveLabelColor()); } itsScrollUpRect = r; r.left += kArrowWidth; r.right += kArrowWidth; if (itsCanScrollDownFlag && itsScrollDownPushedFlag) { JXDrawDownArrowRight(p, r, kBorderWidth); } else if (itsCanScrollDownFlag) { JXDrawUpArrowRight(p, r, kBorderWidth); } else { JXFillArrowRight(p, r, cmap->GetInactiveLabelColor()); } itsScrollDownRect = r; } else if (itsEdge == kRight) { JRect r(ap.bottom - w, ap.right - h, ap.bottom, ap.right); p.SetPenColor(cmap->GetDefaultBackColor()); p.SetFilling(kJTrue); p.JPainter::Rect(r); p.SetFilling(kJFalse); r.Shrink(0, kBorderWidth); r.left = r.right = r.xcenter(); r.left -= kArrowWidth/2; r.right += kArrowWidth/2 + kArrowWidth%2; r.bottom = r.top + kArrowWidth; if (itsCanScrollUpFlag && itsScrollUpPushedFlag) { JXDrawDownArrowUp(p, r, kBorderWidth); } else if (itsCanScrollUpFlag) { JXDrawUpArrowUp(p, r, kBorderWidth); } else { JXFillArrowUp(p, r, cmap->GetInactiveLabelColor()); } itsScrollUpRect = r; r.top += kArrowWidth; r.bottom += kArrowWidth; if (itsCanScrollDownFlag && itsScrollDownPushedFlag) { JXDrawDownArrowDown(p, r, kBorderWidth); } else if (itsCanScrollDownFlag) { JXDrawUpArrowDown(p, r, kBorderWidth); } else { JXFillArrowDown(p, r, cmap->GetInactiveLabelColor()); } itsScrollDownRect = r; } }
void TestWidget::DrawStuff ( JPainter& p ) { JIndex i; JXColormap* colormap = GetColormap(); p.SetPenColor(colormap->GetGreenColor()); JRect ellipseRect(100,50,150,300); p.Ellipse(ellipseRect); p.SetPenColor(colormap->GetBlackColor()); if (itsFillFlag) { p.SetFilling(kJTrue); } JRect ap = GetAperture(); p.Line(ap.topLeft(), ap.bottomRight()); p.Line(ap.topRight(), ap.bottomLeft()); p.SetLineWidth(2); p.SetFontName("Times"); p.SetFontSize(18); p.Image(*itsHomeImage, itsHomeImage->GetBounds(), itsHomeRect); its2Rect = JRect(150, 5, 200, 30); p.SetPenColor(colormap->GetRedColor()); p.Rect(its2Rect); p.SetFontStyle(colormap->GetRedColor()); p.String(its2Rect.topLeft(), "2", its2Rect.width(), JPainter::kHAlignCenter, its2Rect.height(), JPainter::kVAlignCenter); its3Rect = JRect(10, 150, 40, 200); p.SetPenColor(colormap->GetBlueColor()); p.Rect(its3Rect); p.SetFontStyle(colormap->GetBlueColor()); p.String(its3Rect.topLeft(), "3", its3Rect.width(), JPainter::kHAlignCenter, its3Rect.height(), JPainter::kVAlignCenter); p.SetLineWidth(1); p.SetFont(GetFontManager()->GetDefaultFont()); p.ShiftOrigin(10,10); p.Point(0,0); for (i=1; i<=itsRandPointCount; i++) { p.Point(itsRNG.UniformLong(0,200), itsRNG.UniformLong(0,200)); } p.SetPenColor(colormap->GetRedColor()); p.Line(10,0, 0,10); p.SetPenColor(colormap->GetGreenColor()); p.LineTo(10,20); p.SetPenColor(colormap->GetBlueColor()); p.LineTo(0,30); p.ShiftOrigin(2,0); JPoint textPt(40,30); p.String( 0.0, textPt, "Hello"); p.String( 90.0, textPt, "Hello"); p.String(180.0, textPt, "Hello"); p.String(270.0, textPt, "Hello"); p.ShiftOrigin(-2, 0); p.SetPenColor(colormap->GetBlueColor()); JRect r(70, 290, 150, 390); p.Rect(r); /* for (JCoordinate y=70; y<150; y++) { p.SetPenColor(colormap->GetGrayColor(y-50)); p.Line(290,y, 390,y); } for (JCoordinate x=290; x<390; x++) { p.SetPenColor(colormap->GetGrayColor(x-290)); p.Line(x,70, x,150); } p.SetLineWidth(2); for (JCoordinate y=70; y<150; y+=2) { p.SetPenColor(colormap->GetGrayColor(y%4 ? 40 : 60)); p.Line(290,y, 390,y); } p.SetLineWidth(1); p.SetLineWidth(2); for (JCoordinate x=290; x<390; x+=2) { p.SetPenColor(colormap->GetGrayColor(x%4 ? 40 : 60)); p.Line(x,70, x,150); } p.SetLineWidth(1); */ p.String( 0.0, r, "Hello", JPainter::kHAlignCenter, JPainter::kVAlignCenter); p.String( 90.0, r, "Hello", JPainter::kHAlignCenter, JPainter::kVAlignCenter); p.String(180.0, r, "Hello", JPainter::kHAlignCenter, JPainter::kVAlignCenter); p.String(270.0, r, "Hello", JPainter::kHAlignCenter, JPainter::kVAlignCenter); p.String( 0.0, r, "Hello", JPainter::kHAlignRight, JPainter::kVAlignBottom); p.String( 90.0, r, "Hello", JPainter::kHAlignRight, JPainter::kVAlignBottom); p.String(180.0, r, "Hello", JPainter::kHAlignRight, JPainter::kVAlignBottom); p.String(270.0, r, "Hello", JPainter::kHAlignRight, JPainter::kVAlignBottom); p.SetPenColor(colormap->GetBlueColor()); p.Rect(200, 10, 100, 50); p.String(200, 10, "Hello", 100, JPainter::kHAlignLeft); p.String(200, 10+p.GetLineHeight(), "Hello", 100, JPainter::kHAlignCenter); p.String(200, 10+2*p.GetLineHeight(), "Hello", 100, JPainter::kHAlignRight); p.SetPenColor(colormap->GetDarkGreenColor()); p.SetFilling(kJTrue); p.Rect(290, 160, 100, 80); p.SetFilling(kJFalse); /* for (JCoordinate y=160; y<240; y++) { p.SetPenColor(colormap->GetGrayColor(y-140)); p.Line(290,y, 390,y); } for (JCoordinate x=290; x<390; x++) { p.SetPenColor(colormap->GetGrayColor(x-290)); p.Line(x,160, x,240); } p.SetLineWidth(2); for (JCoordinate y=160; y<240; y+=2) { p.SetPenColor(colormap->GetGrayColor(y%4 ? 40 : 60)); p.Line(290,y, 390,y); } p.SetLineWidth(1); p.SetLineWidth(2); for (JCoordinate x=290; x<390; x+=2) { p.SetPenColor(colormap->GetGrayColor(x%4 ? 40 : 60)); p.Line(x,160, x,240); } p.SetLineWidth(1); */ textPt.Set(340, 200); p.SetFontName("Times"); p.SetFontStyle(colormap->GetBlueColor()); p.String( 0.0, textPt, "Hello"); p.String( 90.0, textPt, "Hello"); p.SetFontStyle(colormap->GetYellowColor()); p.String(180.0, textPt, "Hello"); p.String(270.0, textPt, "Hello"); p.SetPenColor(colormap->GetYellowColor()); r.Set(0,11,80,91); p.Rect(r); r.Shrink(1,1); p.SetPenColor(colormap->GetBlueColor()); p.Ellipse(r); r.Shrink(1,1); p.SetPenColor(colormap->GetRedColor()); p.Arc(r, 270.0-45.0, -270.0); JPolygon poly; poly.AppendElement(JPoint(0,85)); poly.AppendElement(JPoint(10,85)); poly.AppendElement(JPoint(5,95)); p.Polygon(poly); p.Line(0,100, 2,98); p.LineTo(4,100); p.LineTo(2,102); p.LineTo(0,100); poly.SetElement(1, JPoint(0,5)); poly.SetElement(2, JPoint(2,0)); poly.SetElement(3, JPoint(4,5)); p.Polygon(2,105, poly); // test filling rule p.SetPenColor(colormap->GetRedColor()); p.SetFilling(kJTrue); JPolygon fillRulePoly; fillRulePoly.AppendElement(JPoint(175,45)); fillRulePoly.AppendElement(JPoint(165,65)); fillRulePoly.AppendElement(JPoint(190,50)); fillRulePoly.AppendElement(JPoint(160,50)); fillRulePoly.AppendElement(JPoint(185,65)); p.Polygon(fillRulePoly); p.SetFilling(kJFalse); // dashed lines p.DrawDashedLines(kJTrue); p.SetPenColor(colormap->GetBlackColor()); JArray<JSize> dashList; // pixel rulers dashList.AppendElement(1); dashList.AppendElement(1); p.SetDashList(dashList); p.Line(100,110, 200,110); p.Line(100,114, 200,114); p.Line(100,118, 200,118); dashList.SetElement(1, 2); // simple pattern dashList.SetElement(2, 3); p.SetDashList(dashList); p.Line(100,112, 200,112); p.SetFontStyle(JFontStyle(kJFalse, kJFalse, 1, kJFalse)); p.String(130,155, "underline without dashes"); p.SetDashList(dashList, 3); // test offset p.Line(100,116, 200,116); dashList.SetElement(1, 1); // example with odd # of values from X manuals dashList.SetElement(2, 2); dashList.AppendElement(3); p.SetDashList(dashList); p.Line(100,120, 200,120); dashList.SetElement(1, 5); // dash-dot pattern dashList.SetElement(2, 2); dashList.SetElement(3, 1); dashList.AppendElement(2); p.SetDashList(dashList); p.Line(100,122, 200,122); p.Ellipse(210,110, 20,20); p.DrawDashedLines(kJFalse); p.Ellipse(213,113, 14,14); p.Rect(207,107, 26,26); p.SetPenColor(colormap->GetYellowColor()); p.DrawDashedLines(kJTrue); p.Ellipse(213,113, 14,14); // icons p.Image(*itsXPMImage, itsXPMImage->GetBounds(), 33,110); p.Image(*itsPartialXPMImage, itsXPMImage->GetBounds(), 50,121); }
void JXMenuBar::WidthChanged() { if (itsMenus->IsEmpty() || itsIgnoreWidthChangedCount > 0) { return; } itsIgnoreWidthChangedCount++; // put all menus back in menubar ClearOverflowMenu(); // check if menus fit on menubar const JRect ap = GetAperture(); JXMenu* m = itsMenus->LastElement(); JRect frame = m->GetFrame(); if (frame.xcenter() < ap.right) { assert( itsIgnoreWidthChangedCount > 0 ); itsIgnoreWidthChangedCount--; return; } // create menu to hold overflow JXImage* image = new JXImage(GetDisplay(), jx_down_chevron); assert( image != NULL ); JXTextMenu* overflowMenu = new JXTextMenu(image, kJTrue, this, kFixedLeft, kFixedTop, 0,0, 10,10); assert( overflowMenu != NULL ); overflowMenu->SetUpdateAction(JXMenu::kDisableNone); overflowMenu->SetMenuBar(this); // don't show down arrow at right of title const JCoordinate extraWidth = overflowMenu->GetFrameWidth(); overflowMenu->SetMenuBar(NULL); // move menus to overflow menu while (frame.right > ap.right - extraWidth) { const JString& title = m->GetTitleText(); if (title.IsEmpty()) { break; } overflowMenu->PrependItem(title); overflowMenu->AttachSubmenu(1, m); if (itsMenus->IsEmpty()) { break; } m = itsMenus->LastElement(); frame = m->GetFrame(); } if (overflowMenu->IsEmpty()) { delete overflowMenu; overflowMenu = NULL; } else { AppendMenu(overflowMenu); itsOverflowMenu = overflowMenu; } assert( itsIgnoreWidthChangedCount > 0 ); itsIgnoreWidthChangedCount--; }