void JXWidget::FitToEnclosure ( const JBoolean fitHoriz, const JBoolean fitVert ) { const JRect frame = GetFrame(); const JPoint oldPt = frame.topLeft(); const JRect enclBounds = (GetEnclosure())->GetBounds(); JCoordinate dx=0, dy=0, dw=0, dh=0; if (fitHoriz) { dx = enclBounds.left - oldPt.x; dw = enclBounds.width() - frame.width(); } if (fitVert) { dy = enclBounds.top - oldPt.y; dh = enclBounds.height() - frame.height(); } Move(dx,dy); AdjustSize(dw,dh); }
void JXWidget::CenterWithinEnclosure ( const JBoolean adjustHoriz, const JBoolean adjustVert ) { const JRect frame = GetFrame(); const JPoint oldPt = frame.topLeft(); const JRect enclBounds = (GetEnclosure())->GetBounds(); JCoordinate dx=0, dy=0; if (adjustHoriz) { dx = (enclBounds.xcenter() - frame.width()/2) - oldPt.x; } if (adjustVert) { dy = (enclBounds.ycenter() - frame.height()/2) - oldPt.y; } Move(dx,dy); }
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 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 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 GenerateCode ( istream& input, ostream& output, const JString& stringPath, const JString& formName, const JString& tagName, const JString& userTopEnclVarName, JPtrArray<JString>* objTypes, JPtrArray<JString>* objNames ) { JIndex i; // width input >> ws; JString line = JReadUntilws(input); assert( line == kFormWidthMarker ); JSize formWidth; input >> formWidth; // height input >> ws; line = JReadUntilws(input); assert( line == kFormHeightMarker ); JSize formHeight; input >> formHeight; // object count (marker contains whitespace) input >> ws; line = JReadUntil(input, ':') + ":"; assert( line == kFormObjCountMarker ); JSize itemCount; input >> itemCount; // create window const JString topEnclFrameName = tagName + "_Frame"; const JString topEnclApName = tagName + "_Aperture"; JString topEnclVarName; if (tagName == kDefaultDelimTag) { topEnclVarName = kDefTopEnclVarName; output << " JXWindow* window = new JXWindow(this, "; output << formWidth << ',' << formHeight; output << ", \"\");" << endl; output << " assert( window != NULL );" << endl; output << endl; } else { assert( !userTopEnclVarName.IsEmpty() ); topEnclVarName = userTopEnclVarName; output << " const JRect "; topEnclFrameName.Print(output); output << " = "; topEnclVarName.Print(output); output << "->GetFrame();" << endl; output << " const JRect "; topEnclApName.Print(output); output << " = "; topEnclVarName.Print(output); output << "->GetAperture();" << endl; output << " "; topEnclVarName.Print(output); output << "->AdjustSize(" << formWidth << " - "; topEnclApName.Print(output); output << ".width(), " << formHeight << " - "; topEnclApName.Print(output); output << ".height());" << endl; output << endl; } // We need to calculate the enclosure for each object. Since objects // are drawn in the order added, an object must come after its enclosure // in the list in order to be visible. JArray<JRect> rectList(10); JArray<JBoolean> isInstanceVar(10); // This array is used to send the options to ApplyOptions. // It does not own the pointers that it contains. JPtrArray<JString> optionValues(JPtrArrayT::kForgetAll, kOptionCount); for (i=1; i<=kOptionCount; i++) { optionValues.Append(NULL); } // generate code for each object JStringManager stringMgr; JIndex objCount = 1; for (i=1; i<=itemCount; i++) { // check for start-of-object input >> ws; line = JReadLine(input); assert( line == kBeginObjLine ); // object class JString flClass = JReadLine(input); RemoveIdentifier(kObjClassMarker, &flClass); // object type JString flType = JReadLine(input); RemoveIdentifier(kObjTypeMarker, &flType); // object frame input >> ws; line = JReadUntilws(input); assert( line == kObjRectMarker ); JCoordinate x,y,w,h; input >> x >> y >> w >> h >> ws; const JRect frame(y, x, y+h, x+w); rectList.AppendElement(frame); // box type JString boxType = JReadLine(input); RemoveIdentifier(kObjBoxTypeMarker, &boxType); // colors input >> ws; line = JReadUntilws(input); assert( line == kObjColorsMarker ); JString col1 = JReadUntilws(input); optionValues.SetElement(kCol1Index, &col1, JPtrArrayT::kForget); JString col2 = JReadUntilws(input); optionValues.SetElement(kCol2Index, &col2, JPtrArrayT::kForget); // label info JString lAlign = JReadLine(input); RemoveIdentifier(kObjLAlignMarker, &lAlign); JString lStyle = JReadLine(input); RemoveIdentifier(kObjLStyleMarker, &lStyle); JString lSize = JReadLine(input); RemoveIdentifier(kObjLSizeMarker, &lSize); JString lColor = JReadLine(input); RemoveIdentifier(kObjLColorMarker, &lColor); JString label = JReadLine(input); RemoveIdentifier(kObjLabelMarker, &label); // shortcuts JString shortcuts = JReadLine(input); RemoveIdentifier(kObjShortcutMarker, &shortcuts); optionValues.SetElement(kShortcutsIndex, &shortcuts, JPtrArrayT::kForget); // resizing (ignored) JIgnoreLine(input); // gravity input >> ws; line = JReadUntilws(input); assert( line == kObjGravityMarker ); const JString nwGravity = JReadUntilws(input); const JString seGravity = JReadUntilws(input); // variable name JBoolean isLocal = kJFalse; JString* varName = new JString(JReadLine(input)); assert( varName != NULL ); RemoveIdentifier(kObjNameMarker, varName); if (varName->IsEmpty()) { isInstanceVar.AppendElement(kJFalse); GetTempVarName(tagName, varName, *objNames); isLocal = kJTrue; } else if (varName->GetFirstCharacter() == '(' && varName->GetLastCharacter() == ')') { isInstanceVar.AppendElement(kJFalse); isLocal = kJTrue; *varName = varName->GetSubstring(2, varName->GetLength()-1); } else if (varName->GetFirstCharacter() == '<' && varName->GetLastCharacter() == '>') { isInstanceVar.AppendElement(kJFalse); *varName = varName->GetSubstring(2, varName->GetLength()-1); } else { isInstanceVar.AppendElement(kJTrue); } objNames->Append(varName); // callback (ignored) JIgnoreLine(input); // callback argument JString cbArg = JReadLine(input); RemoveIdentifier(kObjCBArgMarker, &cbArg); JString cbArgExtra; do { cbArgExtra = JReadLine(input); cbArgExtra.TrimWhitespace(); } while (!cbArgExtra.IsEmpty()); // don't bother to generate code for initial box // if it is FL_BOX, FLAT_BOX, FL_COL1 if (i==1 && flClass == "FL_BOX" && flType == "FLAT_BOX" && col1 == "FL_COL1") { rectList.RemoveElement(objCount); isInstanceVar.RemoveElement(objCount); objNames->DeleteElement(objCount); continue; } // check for errors -- safe since we have read in entire object JString hSizing, vSizing; if (!ParseGravity(nwGravity, &hSizing, &vSizing)) { cerr << "Illegal sizing specification "; cerr << nwGravity << ',' << seGravity; cerr << " for '" << *varName << '\'' << endl; rectList.RemoveElement(objCount); isInstanceVar.RemoveElement(objCount); objNames->DeleteElement(objCount); continue; } if (*varName == topEnclVarName) { cerr << "Cannot use reserved name '" << topEnclVarName << '\'' << endl; rectList.RemoveElement(objCount); isInstanceVar.RemoveElement(objCount); objNames->DeleteElement(objCount); continue; } // get the object's enclosure JIndex enclIndex; JString enclName; JRect localFrame = frame; if (GetEnclosure(rectList, objCount, &enclIndex)) { enclName = *(objNames->NthElement(enclIndex)); const JRect enclFrame = rectList.GetElement(enclIndex); localFrame.Shift(-enclFrame.topLeft()); } else { enclName = topEnclVarName; } // get the class name and additional arguments JString* className = new JString; assert( className != NULL ); objTypes->Append(className); JString argList; if (!GetConstructor(flClass, flType, &label, className, &argList)) { cerr << "Unsupported class: " << flClass << ", " << flType << endl; rectList.RemoveElement(objCount); isInstanceVar.RemoveElement(objCount); objNames->DeleteElement(objCount); objTypes->DeleteElement(objCount); continue; } // generate the actual code const JBoolean needCreate = NeedsCreateFunction(*className); output << " "; if (isLocal) { className->Print(output); output << "* "; } varName->Print(output); output << " =" << endl; output << " "; if (!needCreate) { output << "new "; } className->Print(output); if (needCreate) { output << "::Create"; } output << '('; if (!argList.IsEmpty()) { argList.Print(output); if (argList.GetLastCharacter() != ',') { output << ','; } output << ' '; } if (!cbArg.IsEmpty()) { cbArg.Print(output); if (cbArg.GetLastCharacter() != ',') { output << ','; } output << ' '; } if ((*className == "JXStaticText" && cbArg.IsEmpty()) || NeedsStringArg(*className)) { JString id = *varName; id += "::"; id += formName; id += "::"; id += tagName; // last since it is almost always the same output << "JGetString(\""; id.Print(output); output << "\"), "; stringMgr.SetElement(id, label, JPtrArrayT::kDelete); } enclName.Print(output); output << ',' << endl; output << " JXWidget::"; hSizing.Print(output); output << ", JXWidget::"; vSizing.Print(output); output << ", " << localFrame.left << ',' << localFrame.top << ", "; output << localFrame.width() << ',' << localFrame.height() << ");" << endl; output << " assert( "; varName->Print(output); output << " != NULL );" << endl; ApplyOptions(output, *className, formName, tagName, *varName, optionValues, lSize, lStyle, lColor, &stringMgr); if (*className == "JXStaticText" && cbArg.IsEmpty() && !lAlign.Contains("FL_ALIGN_TOP") && localFrame.height() <= 20) { output << " "; varName->Print(output); output << "->SetToLabel();" << endl; } output << endl; // now we know the object is valid objCount++; } // write string database JString dbFileName = stringPath + formName; if (tagName != kDefaultDelimTag) { dbFileName += kCustomTagMarker + tagName; } dbFileName += "_layout"; if (stringMgr.GetElementCount() > 0) { JEditVCS(dbFileName); ofstream dbOutput(dbFileName); stringMgr.WriteFile(dbOutput); } else { JRemoveVCS(dbFileName); JRemoveFile(dbFileName); } // reset enclosure size if (tagName != kDefaultDelimTag) { output << " "; topEnclVarName.Print(output); output << "->SetSize("; topEnclFrameName.Print(output); output << ".width(), "; topEnclFrameName.Print(output); output << ".height());" << endl; output << endl; } // throw away temporary variables objCount--; assert( objCount == isInstanceVar.GetElementCount() ); assert( objCount == objTypes->GetElementCount() ); assert( objCount == objNames->GetElementCount() ); for (i=objCount; i>=1; i--) { if (!isInstanceVar.GetElement(i)) { objTypes->DeleteElement(i); objNames->DeleteElement(i); } } }
void JXTreeListWidget::TableDrawCell ( JPainter& p, const JPoint& cell, const JRect& rect ) { if (JIndex(cell.x) == itsNodeColIndex && itsDrawSelectionFlag) { HilightIfSelected(p, cell, rect); } const JTreeNode* node = itsTreeList->GetNode(cell.y); if (JIndex(cell.x) == itsToggleOpenColIndex && node->IsOpenable()) { p.ShiftOrigin(rect.topLeft()); const JPolygon* triangle = (itsTreeList->IsOpen(cell.y) ? &kOpenTriangle : &kClosedTriangle); if (kOpenTriangle.IsEmpty()) { kOpenTriangle.AppendElement(JPoint(5, 6)); kOpenTriangle.AppendElement(JPoint(15, 6)); kOpenTriangle.AppendElement(JPoint(10, 11)); kClosedTriangle.AppendElement(JPoint(10, 3)); kClosedTriangle.AppendElement(JPoint(15, 8)); kClosedTriangle.AppendElement(JPoint(10, 13)); } const JColormap* colormap = p.GetColormap(); if ((itsToggleDragIndex == cell.y && itsMouseInToggleFlag) || itsDNDTargetIndex == JIndex(cell.y)) { p.SetFilling(kJTrue); p.SetPenColor(colormap->GetBlackColor()); p.Polygon(*triangle); } else { p.SetFilling(kJTrue); p.SetPenColor(colormap->GetGrayColor(90)); p.Polygon(*triangle); p.SetFilling(kJFalse); p.SetPenColor(colormap->GetBlackColor()); p.Polygon(*triangle); } p.ShiftOrigin(-(rect.topLeft())); } else if (JIndex(cell.x) == itsNodeColIndex) { JRect r = rect; r.left += GetNodeIndent(cell.y); p.SetClipRect(r); TLWDrawNode(p, cell, r); // Table controls clip rect, so we don't have to reset it. } }