📄 iconviewc.c
字号:
//// Translate the position by the scroll factors// int x = be->x + viewBox->HScrollValue(); int y = be->y + viewBox->VScrollValue();//// See which icon is under pointer. If this is not the same item as the// press event, start over// VItemC *releaseItem = PickItem(x, y); if ( releaseItem != pressItem ) return;//// Highlight the item// HighlightItem(pressItem);//// Open the item// pressItem->CallOpenCallbacks(); } // End HandleDoubleClick/*----------------------------------------------------------------------- * Handle pointer motion with button 1 pressed */voidIconViewC::HandleButton1Motion(XMotionEvent *ev){//// Clear the current rectangle// XDrawRectangle(halApp->display, viewBox->ViewWin(), pickGC, pickRect.xmin - viewBox->HScrollValue(), pickRect.ymin - viewBox->VScrollValue(), pickRect.wd, pickRect.ht);//// If the pointer is outside the bounds, start a timer to auto-scroll// Boolean off_top = (ev->y <= 0); Boolean off_bot = (ev->y >= (int)viewBox->DAHeight()); if ( off_top || off_bot ) {//// Return if no scrolling is possible// if ( !viewBox->VScrollOn() || (off_top && viewBox->VScrollValue() == 0) || (off_bot && viewBox->VScrollValue() == viewBox->VScrollMaxValue()) ) return; scrollEvent = *ev;//// Start scrolling if we're not already// if ( !scrollTimer ) {// // Call the action proc to scroll// char *parms = "0"; scrollAction = (char *) (off_top ? "IncrementUpOrLeft" : "IncrementDownOrRight"); XtCallActionProc(viewBox->VScrollBar(), scrollAction, (XEvent*)&scrollEvent, &parms, 1);//// Start automatic scrolling// scrollTimer = XtAppAddTimeOut(halApp->context, 250, (XtTimerCallbackProc)HandleAutoScroll, (XtPointer)this); } // End if not already scrolling } // End if pointer hit top or bottom of window else {//// Stop any auto scrolling// if ( scrollTimer ) XtRemoveTimeOut(scrollTimer); scrollTimer = (XtIntervalId)NULL; }//// Translate the position by the scroll factors// int x = ev->x + viewBox->HScrollValue(); int y = ev->y + viewBox->VScrollValue(); UpdatePickRect(x, y);} // End HandleButton1Motion/*----------------------------------------------------------------------- * Handle automatic scrolling */voidIconViewC::HandleAutoScroll(IconViewC *This, XtIntervalId*){//// Clear the current rectangle// XDrawRectangle(halApp->display, This->viewBox->ViewWin(), This->pickGC, This->pickRect.xmin - This->viewBox->HScrollValue(), This->pickRect.ymin - This->viewBox->VScrollValue(), This->pickRect.wd, This->pickRect.ht);//// Call the action proc to scroll// char *parms = "0"; XtCallActionProc(This->viewBox->VScrollBar(), This->scrollAction, (XEvent*)&This->scrollEvent, &parms, 1);//// Redraw the items in the pick list since the scroll cleared them// RectC sarea = This->viewBox->VisRect(); sarea.xmin += This->viewBox->HScrollValue(); sarea.xmax += This->viewBox->HScrollValue(); sarea.ymin += This->viewBox->VScrollValue(); sarea.ymax += This->viewBox->VScrollValue(); RectC drawBounds; unsigned count = This->pickList.size(); for (int i=0; i<count; i++) { VItemC *item = This->pickList[i]; IconDataC *data = (IconDataC *)item->ViewData(); drawBounds = data->bounds; drawBounds.ht += This->ySpacing; drawBounds.ymax += This->ySpacing;//// Redraw if item not clipped out// if ( sarea.Overlaps(drawBounds) ) This->DrawItem(*item, *data, This->pickDrawMode); }//// Update the rectangle// int x = This->scrollEvent.x + This->viewBox->HScrollValue(); int y = This->scrollEvent.y + This->viewBox->VScrollValue(); This->UpdatePickRect(x, y);//// Repeat the cycle// This->scrollTimer = XtAppAddTimeOut(halApp->context, 250, (XtTimerCallbackProc)HandleAutoScroll, (XtPointer)This);} // End HandleAutoScroll/*----------------------------------------------------------------------- * Redraw the pick rectangle */voidIconViewC::UpdatePickRect(int x, int y){//// Update the pick rectangle// if ( pickX > x ) { pickRect.xmin = x; pickRect.xmax = pickX; } else { pickRect.xmin = pickX; pickRect.xmax = x; } if ( pickY > y ) { pickRect.ymin = y; pickRect.ymax = pickY; } else { pickRect.ymin = pickY; pickRect.ymax = y; } pickRect.wd = pickRect.xmax - pickRect.xmin + 1; pickRect.ht = pickRect.ymax - pickRect.ymin + 1;//// Get a new list of items in the pick rectangle// VItemListC list; PickItems(pickRect, list);//// Remove items in old list, but not in new list // unsigned count = pickList.size(); int i; for (i=count-1; i>=0; i--) { VItemC *item = pickList[i]; if ( !list.includes(item) ) { DrawItem(*item, AS_IS); pickList.remove(i); } }//// Add items in new list, but not in old list // count = list.size(); for (i=0; i<count; i++) { VItemC *item = list[i]; if ( !pickList.includes(item) ) { DrawItem(*item, pickDrawMode); pickList.add(item); } }//// Draw the new rectangle// XDrawRectangle(halApp->display, viewBox->ViewWin(), pickGC, pickRect.xmin - viewBox->HScrollValue(), pickRect.ymin - viewBox->VScrollValue(), pickRect.wd, pickRect.ht);} // End UpdatePickRect/*----------------------------------------------------------------------- * Highlight an item */voidIconViewC::HighlightItem(const VItemC *item){ if ( item == hlItem ) return;//// Remove current highlight// if ( hlItem ) { DrawHighlight(hlItem, regBgColor); } hlItem = (VItemC *)item; if ( !hlItem ) return;//// Make sure the new item is visible// ScrollToItem(*hlItem);//// Highlight the new item// DrawHighlight(hlItem, hlColor);} // End HighlightItem/*----------------------------------------------------------------------- * Handle a pointer motion event in the area */voidIconViewC::HandlePointerMotion(Widget, IconViewC *This, XMotionEvent*, Boolean*){ if ( !This->shown || !This->focusHere ) return;//// Get all pending motion events// XMotionEvent mev; while (XCheckMaskEvent(halApp->display, PointerMotionMask, (XEvent *)&mev)); Window root, child; int rx, ry; // Position in root window int vx, vy; // Position in view window unsigned mods; // Keyboard modifiers//// Get current pointer location// XQueryPointer(halApp->display, This->viewBox->ViewWin(), &root, &child, &rx, &ry, &vx, &vy, &mods);//// Find the item under the pointer// VItemC *item = This->PickItem(vx + This->viewBox->HScrollValue(), vy + This->viewBox->VScrollValue()); if ( item == This->hlItem ) return;//// Remove current highlight// if ( This->hlItem ) { This->DrawHighlight(This->hlItem, This->regBgColor); } This->hlItem = item;//// Highlight the new item// if ( This->hlItem ) { This->DrawHighlight(This->hlItem, This->hlColor); }} // End HandlePointerMotion/*----------------------------------------------------------------------- * Change the label for an item */voidIconViewC::ChangeItemLabel(const VItemC& item){//// Look up the icon data// IconDataC *data = (IconDataC *)item.ViewData(); if ( !DataValid(data) ) return;//// Save current sizes// int oldLabelWd = data->labelWd; int oldLabelHt = data->labelHt;//// Calculate new sizes// if ( fontList ) data->GetLabelSize(fontList, labelSpacing); else data->GetLabelSize(font, labelSpacing); if ( data->labelWd != oldLabelWd || data->labelHt != oldLabelHt ) { needPlaces = True; } viewBox->Changed(True);} // End ChangeItemLabel/*----------------------------------------------------------------------- * Change the pixmaps for an item */voidIconViewC::ChangeItemPixmaps(const VItemC& item){ //..if ( !viewBox->Realized() ) return;//// Look up the icon data// IconDataC *data = (IconDataC *)item.ViewData(); if ( !DataValid(data) ) return;//// Remember current size// int oldWd = 0; int oldHt = 0; if ( data->pixmap ) { oldWd = data->pixmap->wd; oldHt = data->pixmap->ht; }//// Load the pixmap// GetPixmap(*data); if ( data->pixmap ) { if ( data->pixmap->wd != oldWd || data->pixmap->ht != oldHt ) needPlaces = True; } else { if ( oldWd > 0 || oldHt > 0 ) needPlaces = True; } viewBox->Changed(True);} // End ChangeItemPixmaps/*----------------------------------------------------------------------- * Public method to remove an item from this view */voidIconViewC::RemoveItem(VItemC& item){//// Get icon data structure// IconDataC *data = (IconDataC *)item.ViewData(); if ( !DataValid(data) ) return; dataDict.remove(&item); item.SetViewData(NULL); //cout <<"Deleting data " <<hex <<(int)data <<" for item " // <<(int)&item SP (int)data->item <<dec NL; needPlaces = True;//// Delete icon data structure// delete data; if ( hlItem == &item ) hlItem = NULL; viewBox->Changed(True);} // End RemoveItem/*----------------------------------------------------------------------- * Remove items from this view */voidIconViewC::RemoveItems(const VItemListC& list){ //..Boolean sizeChange = False;//// Remove items// unsigned count = list.size(); for (int i=0; i<count; i++) {//// Get icon data structure// VItemC *item = list[i]; IconDataC *data = (IconDataC *)item->ViewData(); if ( !DataValid(data) ) continue; dataDict.remove(item); item->SetViewData(NULL); //cout <<"Deleting data " <<hex <<(int)data <<" for item " // <<(int)item SP (int)data->item <<dec NL; if ( viewBox->VisItems().includes(item) ) needPlaces = True;//// Delete icon data structure// delete data; if ( hlItem == item ) hlItem = NULL; } // End for each item to be deleted viewBox->Changed(True);} // End RemoveItems/*----------------------------------------------------------------------- * Handle drag over event */voidIconViewC::HandleDragOver(XmDragProcCallbackStruct *dp){ VItemC *dropSite = PickItem(dp->x + viewBox->HScrollValue(), dp->y + viewBox->VScrollValue()); Boolean validDrop = (dropSite && dropSite->ValidDropSite()); if ( dropSite != dropItem ) { if ( dropItem ) { if ( dropItem == hlItem ) DrawHighlight(dropItem, hlColor); else DrawHighlight(dropItem, regBgColor); } if ( validDrop ) { DrawHighlight(dropSite, dropColor); dropItem = dropSite; } else { dropItem = NULL; } } // End if this is a new drop site if ( validDrop ) dp->dropSiteStatus = XmVALID_DROP_SITE; else dp->dropSiteStatus = XmINVALID_DROP_SITE;} // End HandleDragOver/*----------------------------------------------------------------------- * Handle drop event */voidIconViewC::DropFinished(){//// Remove drop highlight// if ( dropItem == hlItem ) DrawHighlight(dropItem, hlColor); else DrawHighlight(dropItem, regBgColor); dropItem = NULL; if ( dragIcon ) { XtDestroyWidget(dragIcon); dragIcon = NULL; }} // End DropFinished/*----------------------------------------------------------------------- * Create an icon for the drag */WidgetIconViewC::CreateDragIcon(VItemListC &list){// FIXME: doesn't work correctly#if 0 IconDataC *data = (IconDataC *)list[0]->ViewData(); if ( !DataValid(data) ) return NULL;//// Create widget for drag icon// WArgList args; args.Reset(); if ( data->pixmap ) { args.Width(data->pixmap->wd); args.Height(data->pixmap->ht); args.MaxWidth(data->pixmap->wd); args.MaxHeight(data->pixmap->ht); args.Depth(data->pixmap->depth); args.pixmap(data->pixmap->reg); if (data->pixmap->mask != XmUNSPECIFIED_PIXMAP && data->pixmap->mask != None) { args.Mask(data->pixmap->mask); } } args.Foreground(regFgColor); args.Background(regBgColor); dragIcon = XmCreateDragIcon(viewBox->ViewDA(), "dragIcon", ARGS); return dragIcon;#else return NULL;#endif} // End CreateDragIcon/*----------------------------------------------------------------------- * Create an icon for the drag */VItemC*IconViewC::DropItem(){ return dropItem;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -