📄 fieldviewc.c
字号:
*/voidFieldViewC::_AddItem(VItemC& item){//// Create a new icon data structure and add it to the dictionary// ItemDataC *data = new ItemDataC(item, this); //cout <<"Created data " <<hex <<(int)data <<" for item " // <<(int)&item SP (int)data->item <<dec NL; dataDict.add(&item, data); item.SetViewData(data);//// Create the pixmap if necessary// if ( showPixmaps /*..&& viewBox->Realized()..*/ ) { GetPixmap(*data); //..if ( data->pixmap->wd > maxPmWd ) maxPmWd = data->pixmap->wd; } needPlaces = True;} // End _AddItem/*----------------------------------------------------------------------- * Handle a title exposure event */voidFieldViewC::TitleExpose(Widget, FieldViewC *This, XmDrawingAreaCallbackStruct *da){ XExposeEvent *ev = (XExposeEvent*)da->event;//// Initialize if necessary// if ( !This->titleWin ) This->InitializeTitle();//// Draw if this is the last expose event// if ( ev->count == 0 ) This->DrawTitles();} // End TitleExpose/*----------------------------------------------------------------------- * Create graphics context */voidFieldViewC::InitializeTitle(){ titleWin = XtWindow(titleDA);//// Create graphics contexts for drawing// XtGCMask fixMask = GCClipMask | GCFillStyle | GCFunction | GCGraphicsExposures | GCLineStyle | GCLineWidth | GCPlaneMask; XtGCMask modMask = GCForeground; XtGCMask naMask = GCArcMode | GCBackground | GCCapStyle | GCClipXOrigin | GCClipYOrigin | GCDashList | GCDashOffset | GCFillRule | GCJoinStyle | GCStipple | GCSubwindowMode | GCTile | GCTileStipXOrigin | GCTileStipYOrigin; XGCValues fixVals; fixVals.clip_mask = None; fixVals.fill_style = FillSolid; fixVals.function = GXcopy; fixVals.graphics_exposures = TRUE; fixVals.line_style = LineSolid; fixVals.line_width = 0; fixVals.plane_mask = AllPlanes; fixVals.foreground = regFgColor; if ( viewBox->GoodFont() ) { fixMask |= GCFont; fixVals.font = font->fid; } titleGC = XtAllocateGC(titleDA, 0, fixMask, &fixVals, modMask, naMask);} // End InitializeTitle/*----------------------------------------------------------------------- * Handle button and keyboard events in title bar */voidFieldViewC::TitleInput(Widget, FieldViewC *This, XmDrawingAreaCallbackStruct *da){ int type = da->event->type; if ( type != ButtonPress && type != ButtonRelease ) return; XButtonEvent *be = (XButtonEvent *)da->event; if ( be->button != Button1 ) return; if ( type == ButtonPress ) This->TitleButton1Press(be); else if ( type == ButtonRelease ) This->TitleButton1Release(be);} // End TitleInput/*----------------------------------------------------------------------- * Handle press of mouse button 1 in title bar */voidFieldViewC::TitleButton1Press(XButtonEvent *be){//// Translate the position by the scroll factors// titlePickX = titlePickOrigX = be->x + viewBox->HScrollValue(); pickSortDistance = 0;//// Find the closest thing, a column separator or a title..// int x = itemMarginWd + hlThick; if ( showPixmaps ) x += maxPmWd + itemMarginWd + sepThick + itemMarginWd; int minDist = MAXINT; titlePickCol = NULL; int finalX = x; unsigned count = columnList.size(); for (int i=0; i<count; i++) { int id = *columnDisplayOrder[i]; ColumnC *column = columnList[id]; if ( !column->visible ) continue; int dist; if ( dragTitlesEnabled ) {//// See if the pick position is closer to the title string or// to the separator. First Find the start and end positions// of the title string.// FieldC& title = column->title; int colWd = column->Width(); int totalWd = itemMarginWd*2 + colWd; int xoff = (totalWd - title.width) / 2; if ( xoff < 0 ) xoff = 0; int sx = x+xoff; int ex = sx+title.width; if ( title.width+xoff > colWd ) // Consider clipping... ex = x+colWd; dist = (sx - titlePickX); if ( dist < 0 ) dist = -dist; if ( dist < minDist ) { minDist = dist; titlePickCol = column; finalX = x; moveIndex = id; moveField = &title; } dist = (ex - titlePickX); if ( dist < 0 ) dist = -dist; if ( dist < minDist ) { minDist = dist; titlePickCol = column; finalX = x; moveIndex = id; moveField = &title; } }//// Find position of separator// x += column->Width() + itemMarginWd; dist = (x - titlePickX); if ( dist < 0 ) dist = -dist; if ( dist < minDist ) { minDist = dist; titlePickCol = column; finalX = x; moveField = NULL; }//// Move to next column// x += sepThick + itemMarginWd; } // End for each column if ( !titlePickCol ) return;//// Create a GC for the rubberband line if necessary// Widget gcw = viewBox->ViewForm(); if ( !titlePickGC ) { Pixel fg, bg; XtVaGetValues( viewBox->ViewDA(), XmNforeground, &fg, XmNbackground, &bg, NULL); XGCValues pickVals; pickVals.foreground = fg ^ bg; pickVals.function = GXxor; pickVals.subwindow_mode = IncludeInferiors; titlePickGC = XtGetGC(gcw, GCSubwindowMode|GCForeground|GCFunction, &pickVals); titlePickWin = XtWindow(gcw); } Window child; XTranslateCoordinates(XtDisplay(gcw), be->window, XtWindow(gcw), 0, 0, &titlePickXoffset, &titlePickYoffset, &child); if ( moveField ) {//// Disable the cursor and start moving the title.// // XUndefineCursor(halApp->display, XtWindow(viewBox->ViewForm())); titlePickX = be->x; titlePickY = be->y; XDrawString(halApp->display, titlePickWin, titlePickGC, titlePickX+titlePickXoffset, titlePickY+titlePickYoffset, moveField->string, moveField->string.size()); } else {//// Move the cursor to that position and change its image// if ( !resizeCursor ) resizeCursor = XCreateFontCursor(halApp->display, XC_sb_h_double_arrow); XDefineCursor(halApp->display, XtWindow(viewBox->ViewForm()), resizeCursor); XWarpPointer(halApp->display, None, titleWin, 0, 0, 0, 0, finalX - viewBox->HScrollValue(), maxTitleHt/(int)2);//// Find the range of motion// Dimension ht; XtVaGetValues(titleDA, XmNheight, &ht, NULL); titlePickXmin = titlePickX - titlePickCol->Width(); titlePickYmin = 0; titlePickYmax = maxTitleHt + daHt + (int)ht;//// Initialize the rubberband line// titleX = titleY = 0; XDrawLine(halApp->display, titlePickWin, titlePickGC, titleX+titlePickX-viewBox->HScrollValue()+titlePickXoffset, titleY+titlePickYmin+titlePickYoffset, titleX+titlePickX-viewBox->HScrollValue()+titlePickXoffset, titleY+titlePickYmax+titlePickYoffset); }//// Look for movement// XtAddEventHandler(titleDA, Button1MotionMask, False, (XtEventHandler)TitleButton1Motion, (XtPointer)this);} // End TitleButton1Press/*----------------------------------------------------------------------- * Handle motion of cursor with mouse button 1 pressed in title bar */voidFieldViewC::TitleButton1Motion(Widget, FieldViewC *This, XMotionEvent *ev, Boolean*){ //cout <<"TitleButton1Motion to " <<ev->x <<endl; if ( This->moveField ) {//// Clear the current string.// XDrawString(halApp->display, This->titlePickWin, This->titlePickGC, This->titlePickX+This->titlePickXoffset, This->titlePickY+This->titlePickYoffset, This->moveField->string, This->moveField->string.size()); This->titlePickX = ev->x; This->titlePickY = ev->y;//// Keep track of the max distance we've moved// int dx = (ev->x + This->viewBox->HScrollValue())-This->titlePickOrigX; if ( dx < 0 ) dx = -dx; if ( dx > This->pickSortDistance ) This->pickSortDistance = dx;//// Draw the string in the new position.// XDrawString(halApp->display, This->titlePickWin, This->titlePickGC, This->titlePickX+This->titlePickXoffset, This->titlePickY+This->titlePickYoffset, This->moveField->string, This->moveField->string.size()); } else { int ex = ev->x + This->viewBox->HScrollValue();//// Don't allow movement past the limits// if ( ex < This->titlePickXmin ) ex = This->titlePickXmin;//// Clear the current line// XDrawLine(halApp->display, This->titlePickWin, This->titlePickGC , This->titleX+This->titlePickX-This->viewBox->HScrollValue()+This->titlePickXoffset, This->titleY+This->titlePickYmin+This->titlePickYoffset, This->titleX+This->titlePickX-This->viewBox->HScrollValue()+This->titlePickXoffset, This->titleY+This->titlePickYmax+This->titlePickYoffset);//// Redraw the line// This->titlePickX = ex; XDrawLine(halApp->display, This->titlePickWin, This->titlePickGC, This->titleX+This->titlePickX-This->viewBox->HScrollValue()+This->titlePickXoffset, This->titleY+This->titlePickYmin+This->titlePickYoffset, This->titleX+This->titlePickX-This->viewBox->HScrollValue()+This->titlePickXoffset, This->titleY+This->titlePickYmax+This->titlePickYoffset); }} // End TitleButton1Motion/*----------------------------------------------------------------------- * Handle release of mouse button 1 in title bar */#define NULL_INDEX -1voidFieldViewC::TitleButton1Release(XButtonEvent* ev){ // if ( scrollTimer ) XtRemoveTimeOut(scrollTimer);//// Stop looking for movement// XtRemoveEventHandler(titleDA, Button1MotionMask, False, (XtEventHandler)TitleButton1Motion, (XtPointer)this); if ( moveField ) {//// Clear the string.// XDrawString(halApp->display, titlePickWin, titlePickGC, titlePickX+titlePickXoffset, titlePickY+titlePickYoffset, moveField->string, moveField->string.size());//// Find the column (if any) that the current event position is in// and move the moveField column to that column if its different.// int drop_x = ev->x + viewBox->HScrollValue(); int sx; int ex = 0; int mwd = itemMarginWd*2; unsigned count = columnList.size(); for (int i=0; i<count; i++) { int id = *columnDisplayOrder[i]; ColumnC *column = columnList[id]; if ( !column->visible ) continue; sx = ex; ex += column->Width() + mwd; if ( drop_x >= sx && drop_x <= ex ) { if ( pickSortDistance < pickSortThreshold ) {// the sort indexes or 1 based, if the index is negative// that means to sort in reverse order. int fnd_id = id+1; int pos_id = columnSortOrder.indexOf(fnd_id); int neg_id = columnSortOrder.indexOf(-fnd_id); if ( ev->state & (ShiftMask|ControlMask) ) { if ( pos_id != NULL_INDEX ) { // change to descending int *nums = columnSortOrder.start(); nums[pos_id] = -fnd_id; } else if ( neg_id != NULL_INDEX ) // no sorting columnSortOrder.remove(-fnd_id); else columnSortOrder.append(fnd_id); // add ascending } else { columnSortOrder.removeAll(); // no sorting if ( pos_id != NULL_INDEX ) // single descending columnSortOrder.append(-fnd_id); else if ( neg_id == NULL_INDEX ) columnSortOrder.append(fnd_id); // single ascending } viewBox->Sort(); } else SetColumnDisplayIndex(moveIndex, i); break; } } moveField = NULL; } else {//// Clear the current rubberband line// XDrawLine(halApp->display, titlePickWin, titlePickGC, titleX+titlePickX-viewBox->HScrollValue()+titlePickXoffset, titleY+titlePickYmin+titlePickYoffset, titleX+titlePickX-viewBox->HScrollValue()+titlePickXoffset, titleY+titlePickYmax+titlePickYoffset);//// Reset the cursor// XUndefineCursor(halApp->display, XtWindow(viewBox->ViewForm()));//// Set the new column size// int delta = titlePickX - titlePickOrigX; int wd = titlePickCol->Width() + delta; if ( wd < 1 ) wd = 1; int index = columnList.indexOf(titlePickCol); if ( delta < 0 ) { // Moved left if ( titlePickCol->minWd > 0 && wd < titlePickCol->minWd ) SetColumnMinPixels(index, wd); SetColumnMaxPixels(index, wd); } else if ( delta > 0 ) { // Moved right if ( titlePickCol->maxWd > 0 && wd > titlePickCol->maxWd ) SetColumnMaxPixels(index, wd); SetColumnMinPixels(index, wd); } } Redraw();} // End TitleButton1Release/*----------------------------------------------------------------------- * Redraw the items in this view */voidFieldViewC::Redraw(){ Draw(viewBox->VisRect());}/*----------------------------------------------------------------------- * Redraw the items in this view */voidFieldViewC::Draw(RectC& area){ if ( !viewBox->Realized() ) return; if ( needPlaces ) { PlaceItems(); viewBox->UpdateScrollBars(); }//// See how many items are visible// VItemListC& visItems = viewBox->VisItems(); unsigned count = visItems.size(); if ( needSetVisItemCount ) SetVisibleItemCount(visItemCount);//// Highlight the first one if there is none highlighted// if ( !hlItem || !visItems.includes(hlItem) ) hlItem = count ? visItems[0] : (VItemC*)NULL;//// Scroll the area// RectC sarea = area; sarea.xmin += viewBox->HScrollValue(); sarea.xmax += viewBox->HScrollValue(); sarea.ymin += viewBox->VScrollValue(); sarea.ymax += viewBox->VScrollValue(); GC gc = viewBox->ViewGC(); Window window = viewBox->ViewPm();//// Clear the drawing area// XSetForeground(halApp->display, gc, regBgColor); XFillRectangle(halApp->display, window, gc, area.xmin, area.ymin, area.wd, area.ht);//// Position of first object// int x = 0; int y = 0; int maxItemWd = daWd;//// Loop through item list//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -