void JXImage::JXImageFromDrawable ( JXDisplay* display, Drawable source, const JRect& origRect ) { JXImageX(display); JRect rect = origRect; { Window rootWindow; int x,y; unsigned int w,h, bw, depth; XGetGeometry(*itsDisplay, source, &rootWindow, &x, &y, &w, &h, &bw, &depth); itsDepth = depth; if (rect.IsEmpty()) { SetDimensions(w,h); rect = GetBounds(); } } itsPixmap = XCreatePixmap(*itsDisplay, itsDisplay->GetRootWindow(), GetWidth(), GetHeight(), itsDepth); assert( itsPixmap != None ); if (itsDepth != itsDisplay->GetDepth()) { itsGC = new JXGC(itsDisplay, itsPixmap); assert( itsGC != NULL ); } (GetGC())->CopyPixels(source, rect.left, rect.top, rect.width(), rect.height(), itsPixmap, 0,0); }
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 JXImage::JXImageFromDrawable ( JXDisplay* display, JXColormap* colormap, Drawable source, const JRect& origRect ) { JXImageX(display, colormap); JRect rect = origRect; { Window rootWindow; int x,y; unsigned int w,h, bw, depth; XGetGeometry(*itsDisplay, source, &rootWindow, &x, &y, &w, &h, &bw, &depth); itsDepth = depth; if (rect.IsEmpty()) { SetDimensions(w,h); rect = GetBounds(); } } itsPixmap = XCreatePixmap(*itsDisplay, itsDisplay->GetRootWindow(), GetWidth(), GetHeight(), itsDepth); assert( itsPixmap != None ); if (itsDepth != itsDisplay->GetDepth()) { itsGC = new JXGC(itsDisplay, itsColormap, itsPixmap); assert( itsGC != NULL ); } (GetGC())->CopyPixels(source, rect.left, rect.top, rect.width(), rect.height(), itsPixmap, 0,0); // register the colors that are used in the drawable const JBoolean needRegister = JConvertToBoolean( itsDepth > 1 && !itsColormap->AllColorsPreallocated() ); if (needRegister && itsColormap->GetVisualClass() == DirectColor) { // With DirectColor, there could be just as many colors as pixels, // so we actually waste time (and memory!) by building a list of // X pixel values before converting them to JColorIndices. ConvertToImage(); const JCoordinate w = GetWidth(); const JCoordinate h = GetHeight(); for (JCoordinate y=0; y<=h; y++) { for (JCoordinate x=0; x<=w; x++) { JColorIndex color; const unsigned long xPixel = XGetPixel(itsImage, x,y); itsColormap->AllocateStaticColor(xPixel, &color); RegisterColor(color, kJFalse); } } } else if (needRegister) // using PseudoColor => small # of X pixels { // By building a list of unique X pixel values and then converting // each once, we reduce O(W H (alloc)) to O(W H) + O(P (alloc)), // where W=width, H=height, P=# of distinct pixels in Drawable. // Typically, W*H is much larger than P. Alloc usually requires // a server call. JIndex i; // build boolean array telling which X pixel values are used ConvertToImage(); const JSize maxColorCount = itsColormap->GetMaxColorCount(); char* pixelUsed = new char [ maxColorCount ]; assert( pixelUsed != NULL ); for (i=0; i<maxColorCount; i++) { pixelUsed[i] = 0; } const JCoordinate w = GetWidth(); const JCoordinate h = GetHeight(); for (JCoordinate y=0; y<=h; y++) { for (JCoordinate x=0; x<=w; x++) { const unsigned long xPixel = XGetPixel(itsImage, x,y); assert( xPixel < maxColorCount ); pixelUsed [ xPixel ] = 1; } } // register each X pixel value that is used JColorIndex color; for (i=0; i<maxColorCount; i++) { if (pixelUsed[i]) { itsColormap->AllocateStaticColor(i, &color); RegisterColor(color, kJFalse); } } delete [] pixelUsed; } }