📄 fieldviewc.c
字号:
Boolean inArea = False; Boolean exitArea = False; //..int extraHt = (hlThick + itemMarginHt)*2; int extraHt = (hlThick + itemMarginHt) * 2 + ySpacing; RectC drawBounds; for (int i=0; i<count; i++) { VItemC *item = visItems[i]; ItemDataC *data = (ItemDataC *)item->ViewData(); if ( !DataValid(data) ) continue;//// Only draw this item if it is at least partially visible// if ( !exitArea ) { drawBounds.Set(x, y, maxItemWd, data->itemHt + extraHt); if ( sarea.Overlaps(drawBounds) ) { inArea = True; DrawItem(*data, AS_IS, window); } else if ( inArea ) { exitArea = True; } }//// Move to next line// y += data->bounds.ht + ySpacing; } // End for each visible item XCopyArea(halApp->display, window, viewBox->ViewWin(), gc, 0, 0, viewBox->DAWidth(), viewBox->DAHeight(), 0, 0);//// Draw titles// DrawTitles();} // End Draw/*----------------------------------------------------------------------- * Draw the column headings */voidFieldViewC::DrawTitles(){ if ( !titleGC || maxTitleHt == 0 ) return;//// Set the drawing area size// XtVaSetValues(viewBox->ViewForm(), XmNresizePolicy, XmRESIZE_GROW, NULL); XtVaSetValues(titleSizeLabel, XmNheight, maxTitleHt, NULL); XtVaSetValues(viewBox->ViewForm(), XmNresizePolicy, XmRESIZE_ANY, NULL); Dimension wd; XtVaGetValues(titleDA, XmNwidth, &wd, NULL);//// Clear the title area// XSetForeground(halApp->display, titleGC, titleBgColor); XFillRectangle(halApp->display, titleWin, titleGC, 0, 0, wd, maxTitleHt); XSetForeground(halApp->display, titleGC, titleFgColor);//// Draw the titles// int x = itemMarginWd + hlThick - viewBox->HScrollValue(); if ( showPixmaps ) x += maxPmWd + itemMarginWd + sepThick + itemMarginWd; int y = itemMarginHt; unsigned tcount = columnList.size(); for (int i=0; i<tcount; i++) { int id = *columnDisplayOrder[i]; ColumnC *column = columnList[id]; if ( !column->visible ) continue;//// Draw string with font or fontList// FieldC& title = column->title; int colWd = column->Width(); int totalWd = itemMarginWd*2 + colWd; int xoff = (totalWd - title.width) / 2; if ( xoff < 0 ) xoff = 0; if ( !fontList ) { int yoff = (maxTitleHt - title.height) / 2 + font->ascent;//// See if we need clipping// if ( title.width > colWd ) { XRectangle rect; rect.x = x+xoff; rect.y = y; rect.width = colWd; rect.height = maxTitleHt; XSetClipRectangles(halApp->display, titleGC, 0, 0, &rect, 1, YXBanded); }//// Draw string// XDrawString(halApp->display, titleWin, titleGC, x+xoff, y+yoff, title.string, title.string.size());//// Restore clipping// if ( title.width > colWd ) XSetClipMask(halApp->display, titleGC, None); } // End if no font list specified else { WXmString tempStr((char*)title.string, column->title.tag); XRectangle rect; rect.x = x+xoff; rect.y = y; rect.width = colWd; rect.height = maxTitleHt; XmStringDraw(halApp->display, titleWin, fontList, (XmString)tempStr, titleGC, x, y, colWd, XmALIGNMENT_CENTER, XmSTRING_DIRECTION_L_TO_R, &rect); }//// Draw separator// if ( sepThick > 0 /*&& i < tcount-1*/ ) { xoff = colWd + itemMarginWd; if ( sepThick == 1 ) { XDrawLine(halApp->display, titleWin, titleGC, x+xoff, 0, x+xoff, maxTitleHt-1); } else { XFillRectangle(halApp->display, titleWin, titleGC, x+xoff, 0, sepThick, maxTitleHt); } }//// Move to next column// x += totalWd + sepThick; } // End for each column} // End DrawTitles/*----------------------------------------------------------------------- * Private method to redraw the specified item */voidFieldViewC::DrawItem(const ItemDataC& data, VItemDrawModeT mode, Drawable drawto){ if ( !viewBox->Realized() ) return; Boolean invert; if ( mode == AS_IS ) invert = viewBox->SelItems().includes(data.item); else invert = (mode == INVERT);#if 0 cout <<"Drawing item " <<data.item <<" for data " <<(int*)&data; if ( invert ) cout <<" inverted"; cout <<endl;#endif//// If drawto is NULL, draw to both the offscreen pixmap and the visible window// Drawable dst1 = drawto; Drawable dst2 = (Drawable)NULL; if ( !dst1 ) { dst1 = viewBox->ViewWin(); dst2 = viewBox->ViewPm(); } GC gc = viewBox->ViewGC();//// Draw background// XSetForeground(halApp->display, gc, invert ? invBgColor : regBgColor); int x = data.bounds.xmin + hlThick - viewBox->HScrollValue(); int y = data.bounds.ymin + hlThick - viewBox->VScrollValue(); int wd = data.bounds.wd - hlThick*2; int ht = data.bounds.ht - hlThick*2; XFillRectangle(halApp->display, dst1, gc, x, y, wd, ht); if ( dst2 ) XFillRectangle(halApp->display, dst2, gc, x, y, wd, ht); x += itemMarginWd; y += itemMarginHt;//// Draw pixmap// if ( showPixmaps && data.pixmap ) { PixmapC *pm = data.pixmap; Pixmap src = invert ? pm->inv : pm->reg; if ( src ) { int px = x + (maxPmWd - pm->wd) / 2; int py = data.bounds.ymin + ((data.bounds.ht - pm->ht) / 2) - viewBox->VScrollValue(); if ( pm->mask ) { XSetClipMask(halApp->display, gc, pm->mask); XSetClipOrigin(halApp->display, gc, px, py); } XCopyArea(halApp->display, src, dst1, gc, /*srcx*/0, /*srcy*/0, pm->wd, pm->ht, /*dstx*/px, /*dsty*/py); if ( dst2 ) XCopyArea(halApp->display, src, dst2, gc, /*srcx*/0, /*srcy*/0, pm->wd, pm->ht, /*dstx*/px, /*dsty*/py); if ( pm->mask ) { XSetClipMask(halApp->display, gc, None); XSetClipOrigin(halApp->display, gc, 0, 0); } } // End if source pixmap available } // End if pixmap data available and needed if ( showPixmaps ) x += maxPmWd + itemMarginWd + sepThick + itemMarginWd; XSetForeground(halApp->display, gc, invert ? invFgColor : regFgColor); if ( viewBox->GoodFont() ) XSetFont(halApp->display, gc, font->fid);//// Draw field strings// unsigned count = columnList.size(); for (int i=0; i<count; i++) { int id = *columnDisplayOrder[i]; ColumnC *column = columnList[id]; if ( !column->visible ) continue; int colWd = column->Width(); int totalWd = itemMarginWd*2 + colWd; if ( id >= 0 && id < data.fieldList.size() ) {//// Draw the string.// FieldC *field = data.fieldList[id]; if ( fontList ) { unsigned char alignment; WXmString tempStr((char*)field->string, field->tag); XRectangle rect; rect.x = x; rect.y = y; rect.width = colWd; rect.height = field->height; switch (column->justify) { case (JUSTIFY_LEFT): alignment = XmALIGNMENT_BEGINNING; break; case (JUSTIFY_RIGHT): alignment = XmALIGNMENT_END; break; case (JUSTIFY_CENTER): alignment = XmALIGNMENT_CENTER; break; } XmStringDraw(halApp->display, dst1, fontList, (XmString)tempStr, gc, x, y, colWd, alignment, XmSTRING_DIRECTION_L_TO_R, &rect); if (dst2) XmStringDraw(halApp->display, dst2, fontList, (XmString)tempStr, gc, x, y, colWd, alignment, XmSTRING_DIRECTION_L_TO_R, &rect); } // End if using font list else { // Draw string with font int xoff = 0; switch (column->justify) { case (JUSTIFY_LEFT): break; case (JUSTIFY_RIGHT): xoff = colWd - field->width; break; case (JUSTIFY_CENTER): xoff = (colWd - field->width) / 2; if ( xoff < 0 ) xoff = 0; break; } int yoff = (data.itemHt - field->height) / 2 + font->ascent;//// See if we need clipping// if ( field->width > colWd ) { XRectangle rect; rect.x = x+xoff; rect.y = y; rect.width = colWd; rect.height = field->height; XSetClipRectangles(halApp->display, gc, 0, 0, &rect, 1, YXBanded); }//// Draw the string// XDrawString(halApp->display, dst1, gc, x+xoff, y+yoff, field->string, field->string.size()); if ( dst2 ) XDrawString(halApp->display, dst2, gc, x+xoff, y+yoff, field->string, field->string.size());//// Restore clipping// if ( field->width > colWd ) XSetClipMask(halApp->display, gc, None); } }//// Move to next column// x += totalWd + sepThick; } // End for each column//// Draw separators// DrawItemSeparators(data, mode, drawto);//// Draw highlight if necessary// if ( focusHere && data.item == hlItem ) DrawHighlight(&data, hlColor, drawto);} // End DrawItem/*----------------------------------------------------------------------- * Draw a highlight border around an item using the given color */voidFieldViewC::DrawHighlight(const VItemC *item, Pixel color){ if ( !item ) return; ItemDataC *data = (ItemDataC *)item->ViewData(); if ( DataValid(data) ) DrawHighlight(data, color, (Drawable)NULL);}voidFieldViewC::DrawHighlight(const ItemDataC *data, Pixel color, Drawable drawto){ if ( !data ) return; XRectangle rects[4]; XRectangle *rect = rects; int xoff = viewBox->HScrollValue(); int yoff = viewBox->VScrollValue(); rect->x = data->bounds.xmin - xoff; rect->y = data->bounds.ymin - yoff; rect->width = data->bounds.wd; rect->height = hlThick; rect++; rect->x = data->bounds.xmin - xoff; rect->y = data->bounds.ymin + hlThick - yoff; rect->width = hlThick; rect->height = data->bounds.ht - hlThick*2; rect++; rect->x = data->bounds.xmax - hlThick + 1 - xoff; rect->y = data->bounds.ymin + hlThick - yoff; rect->width = hlThick; rect->height = data->bounds.ht - hlThick*2; rect++; rect->x = data->bounds.xmin - xoff; rect->y = data->bounds.ymax - hlThick + 1 - yoff; rect->width = data->bounds.wd; rect->height = hlThick; GC gc = viewBox->ViewGC(); XSetForeground(halApp->display, gc, color);//// If drawto is NULL, draw to both the offscreen pixmap and the visible window// Drawable dst1 = drawto; Drawable dst2 = (Drawable)NULL; if ( !dst1 ) { dst1 = viewBox->ViewWin(); dst2 = viewBox->ViewPm(); }#if 0 cout <<"Highlighting item " <<(int*)data->item <<" using color " <<(int*)color <<endl; cout <<" drawing to " <<(int*)dst1; if ( dst2 ) cout <<" and " <<(int*)dst2; cout <<endl;#endif XFillRectangles(halApp->display, dst1, gc, rects, 4); if ( dst2 ) XFillRectangles(halApp->display, dst2, gc, rects, 4);//// Redraw the separators if we erased the highlight// if ( color != hlColor ) DrawItemSeparators(*data, AS_IS, drawto);} // End DrawHighlight/*----------------------------------------------------------------------- * Method to draw the separators for the specified item */voidFieldViewC::DrawItemSeparators(const ItemDataC& data, VItemDrawModeT mode, Drawable drawto){ if ( sepThick <= 0 ) return; GC gc = viewBox->ViewGC();//// If drawto is NULL, draw to both the offscreen pixmap and the visible window// Drawable dst1 = drawto; Drawable dst2 = (Drawable)NULL; if ( !dst1 ) { dst1 = viewBox->ViewWin(); dst2 = viewBox->ViewPm(); } Boolean invert; if ( mode == AS_IS ) invert = viewBox->SelItems().includes(data.item); else invert = (mode == INVERT); int count = columnList.size(); int x = data.bounds.xmin + hlThick - viewBox->HScrollValue(); if ( showPixmaps ) x += itemMarginWd + maxPmWd + itemMarginWd + sepThick; for (int i=0; i<count-1; i++) { int id = *columnDisplayOrder[i]; ColumnC *column = columnList[id]; if ( !column->visible ) continue; x += itemMarginWd + column->Width() + itemMarginWd; int y = data.bounds.ymin - viewBox->VScrollValue();//// Add spacing to height if this is not the last item// int ht = data.bounds.ht; if ( viewBox->VisItems().indexOf(data.item) != viewBox->VisItems().size()-1 ) ht += ySpacing; if ( sepThick == 1 ) {//// Draw separator// XSetForeground(halApp->display, gc, regFgColor); XDrawLine(halApp->display, dst1, gc, x, y, x, y+ht); if ( dst2 ) XDrawLine(halApp->display, dst2, gc, x, y, x, y+ht);//// Invert part of separator if item is selected// if ( invert ) { XSetForeground(halApp->display, gc, invFgColor); XDrawLine(halApp->display, dst1, gc, x, y+hlThick, x, data.bounds.ymax - viewBox->VScrollValue() - hlThick); if ( dst2 ) XDrawLine(halApp->display, dst2, gc, x, y+hlThick, x, data.bounds.ymax - viewBox->VScrollValue() - hlThick); } } else {//// Draw separator// XSetForeground(halApp->display, gc, regFgColor); XFillRectangle(halApp->display, dst1, gc, x, y, sepThick+1, ht);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -