📄 vboxc.c
字号:
int roff, boff; Dimension sbwd, sbht; XtVaGetValues(This->vScrollBar, XmNrightOffset, &roff, XmNwidth, &sbwd, 0); XtVaGetValues(This->hScrollBar, XmNbottomOffset, &boff, XmNheight, &sbht, 0);//// Get offsets to use if scrollbars are displayed// This->scrollRoff = This->noScrollRoff + sbwd + roff; This->scrollBoff = This->noScrollBoff + sbht + boff;//// Set scrollbar values// args.Reset(); args.Minimum(0); args.Maximum(This->DAWidth()); args.SliderSize(This->DAWidth()); args.Increment(1); args.PageIncrement(This->DAWidth()); args.Value(0); XtSetValues(This->hScrollBar, ARGS); args.Increment(1); args.Maximum(This->DAHeight()); args.SliderSize(This->DAHeight()); args.PageIncrement(This->DAHeight()); XtSetValues(This->vScrollBar, ARGS);//// Create a pixmap for off-screen drawing// unsigned depth = DefaultDepth(halApp->display, DefaultScreen(halApp->display)); This->viewPmWd = dawd; This->viewPmHt = daht; This->viewPm = XCreatePixmap(halApp->display, This->viewWin, This->viewPmWd, This->viewPmHt, depth);//// Fix the values of the joy stick.// XtVaSetValues(This->joyStickFrame, XmNwidth, sbwd, XmNheight, sbht, NULL); Pixel clr; XtVaGetValues(This->vScrollBar, XmNtroughColor, &clr, NULL); XtVaSetValues(*This->joyStick, XmNbackground, clr, NULL);//// Add callbacks// XtAddCallback(This->viewDA, XmNresizeCallback, (XtCallbackProc)HandleResize, (XtPointer)This); XtAddCallback(This->viewDA, XmNexposeCallback, (XtCallbackProc)HandleExpose, (XtPointer)This); XtAddEventHandler(This->viewDA, Button1MotionMask, False, (XtEventHandler)HandleButton1Motion, (XtPointer)This); XtAddEventHandler(This->viewDA, ButtonPressMask|ButtonReleaseMask, False, (XtEventHandler)HandleInput, (XtPointer)This); This->realized = True; if ( This->view ) This->view->Show();} // End HandleMapChange/*----------------------------------------------------------------------- * Callback for expose */voidVBoxC::HandleExpose(Widget, VBoxC *This, XmDrawingAreaCallbackStruct *da){ if ( !This->view ) return;//// Draw the exposed area// XExposeEvent *ev = (XExposeEvent*)da->event; RectC area(ev->x, ev->y, ev->width, ev->height); This->view->Draw(area);} // End HandleExpose/*----------------------------------------------------------------------- * Callback for resize */voidVBoxC::HandleResize(Widget, VBoxC *This, XtPointer){ Dimension wd, ht; XtVaGetValues(This->viewDA, XmNwidth, &wd, XmNheight, &ht, NULL); This->visRect.Set(0, 0, wd, ht);//// Set scrollbar values// int max; WArgList args; XtVaGetValues(This->hScrollBar, XmNmaximum, &max, NULL); args.Reset(); args.SliderSize(wd); args.PageIncrement(wd); if ( (int)wd > max ) { args.Maximum(wd); max = wd; } This->hScrollMaxValue = max - wd; if ( This->hScrollValue > This->hScrollMaxValue ) { This->hScrollValue = This->hScrollMaxValue; args.Value(This->hScrollValue); } XtSetValues(This->hScrollBar, ARGS); XtVaGetValues(This->vScrollBar, XmNmaximum, &max, NULL); args.Reset(); args.SliderSize(ht); args.PageIncrement(ht); if ( (int)ht > max ) { args.Maximum(ht); max = ht; } This->vScrollMaxValue = max - ht; if ( This->vScrollValue > This->vScrollMaxValue ) { This->vScrollValue = This->vScrollMaxValue; args.Value(This->vScrollValue); } XtSetValues(This->vScrollBar, ARGS);//// Re-create pixmap if size has increased// if ( wd > This->viewPmWd || ht > This->viewPmHt ) { if (This->viewPm) XFreePixmap(halApp->display, This->viewPm); unsigned depth = DefaultDepth(halApp->display, DefaultScreen(halApp->display)); This->viewPmWd = MAX(wd, This->viewPmWd); This->viewPmHt = MAX(ht, This->viewPmHt); This->viewPm = XCreatePixmap(halApp->display, This->viewWin, This->viewPmWd, This->viewPmHt, depth); }//// Resize current view// if ( This->view ) { This->view->PlaceItems(); This->UpdateScrollBars(); This->view->Redraw(); }} // End HandleResize/*----------------------------------------------------------------------- * Handle button and keyboard events */voidVBoxC::HandleInput(Widget, VBoxC *This, XEvent *ev, Boolean*){ if ( !This->view ) return; switch ( ev->type ) { case (ButtonPress): { XButtonEvent *be = (XButtonEvent *)ev; switch ( be->button ) { case (Button1): This->view->HandleButton1Press(be); break; case (Button2): This->HandleButton2Press(be); break; case (Button3): This->HandleButton3Press(be); break; } } break; case (ButtonRelease): { XButtonEvent *be = (XButtonEvent *)ev; if ( be->button == Button1 ) This->view->HandleButton1Release(be); } break; case (KeyPress): { XKeyEvent *ke = (XKeyEvent *)ev; This->view->HandleKeyPress(ke); } } // End switch event type} // End HandleInput/*----------------------------------------------------------------------- * Handle press of mouse button 2 */voidVBoxC::HandleButton2Press(XButtonEvent *be){ if ( !dragEnabled ) return;//// Translate the position by the scroll factors// be->x += hScrollValue; be->y += vScrollValue;//// See which icon is under pointer// VItemC *dragItem = view->PickItem(be->x, be->y); if ( !dragItem ) return; //cout <<"Starting drag for item " << dragItem NL; ViewDragDataT *dragData = new ViewDragDataT; dragData->widget = viewDA; dragData->viewBox = this; dragData->event = (XEvent *)be;//// If this icon is selected, drag the entire selection. If not, select and// drag only this icon.// if ( selItems.includes(dragItem) ) dragData->itemList = selItems; else { SelectItemOnly(*dragItem); dragData->itemList.add(dragItem); }//// Create widget for drag icon// dragData->icon = view->CreateDragIcon(dragData->itemList);//// Call drag callbacks// CallDragCallbacks(dragData); //cout <<"Done with drag callbacks" NL;} // End HandleButton2Press/*----------------------------------------------------------------------- * Display popup menu */voidVBoxC::HandleButton3Press(XButtonEvent *be){//// Translate the position by the scroll factors// be->x += hScrollValue; be->y += vScrollValue;//// See if there is a view item under the cursor// VItemC *item = view->PickItem(be->x, be->y); if ( item && item->HasMenu() ) { item->PostMenu(be); }//// Display the view box menu if no item menu was found// else if ( popupEnabled ) { XmMenuPosition(viewPopup, be); XtManageChild(viewPopup); } else { XtUngrabPointer(viewDA, CurrentTime); }} // End HandleButton3Press/*----------------------------------------------------------------------- * Callback to handle cursor movement while mouse button 1 is pressed */voidVBoxC::HandleButton1Motion(Widget, VBoxC *This, XMotionEvent *ev, Boolean*){ if ( This->view ) This->view->HandleButton1Motion(ev);}/*----------------------------------------------------------------------- * Callback to handle press of "select all" */voidVBoxC::DoSelectAll(Widget, VBoxC *This, XtPointer){ This->SelectAllItems();}/*----------------------------------------------------------------------- * Callback to handle press of "deselect all" */voidVBoxC::DoDeselectAll(Widget, VBoxC *This, XtPointer){ This->DeselectAllItems();}/*----------------------------------------------------------------------- * Store a number in the given label */#define VAL_LENGTH 4voidVBoxC::SetLabel(Widget label, unsigned count){ StringC val; val += (int)count; // Store count in a string// Pad string with spaces in front while ( val.length() < VAL_LENGTH ) val = " " + val; WXmString wval((char *)val); XtVaSetValues(label, XmNlabelString, (XmString)wval, NULL);}/*----------------------------------------------------------------------- * Register a new view type */VTypeTVBoxC::AddView(ViewC& _view){//// Look for an unused type// VTypeT type = 0; unsigned count = views.size(); while ( type<count && views[type] ) type++;//// Add a new entry to view dictionary// views.insert(&_view, type);//// If this is the first view entry, create the separator.// if ( popupEnabled ) { static Widget sep2 = NULL; static Widget first_viewTB = NULL; if ( views.size() == 1 ) sep2 = XmCreateSeparator(viewPopup, "sep2", 0,0);//// Add an entry to the popup menu for this type// WArgList args; args.UserData((void *)&_view); Widget viewTB = XmCreateToggleButton(viewPopup, _view.ButtonName(), ARGS); void *tmp = viewTB; viewTBList.insert(tmp, type);//// Set this button if it is the first// if ( views.size() == 1 ) { XmToggleButtonSetState(viewTB, True, False); first_viewTB = viewTB; } else { XtManageChild(sep2); XtManageChild(first_viewTB); XtManageChild(viewTB); }//// Add callback for selection// XtAddCallback(viewTB, XmNvalueChangedCallback, (XtCallbackProc)ChangeView, (XtPointer)this); } // End if we have a popup menu//// Set this is the first view// if ( views.size() == 1 ) { view = &_view; viewType = type; if ( realized ) view->Show(); } return type;} // End AddView/*----------------------------------------------------------------------- * Register a new view type */voidVBoxC::ViewType(VTypeT type){//// Return if already this type or type out of range// if ( type == viewType || type < 0 || type >= views.size() ) return;//// Force change using button in popup menu// if ( viewPopup ) XmToggleButtonSetState((Widget)*viewTBList[type], True, realized); else if ( realized ) {//// Hide current view// if ( view ) view->Hide();//// Reset scrollbar values// WArgList args; args.Minimum(0); args.Maximum(DAWidth()); args.SliderSize(DAWidth()); args.Increment(1); args.PageIncrement(DAWidth()); args.Value(0); XtSetValues(hScrollBar, ARGS); args.Maximum(DAHeight()); args.SliderSize(DAHeight()); args.Increment(1); args.PageIncrement(DAHeight()); XtSetValues(vScrollBar, ARGS); hScrollValue = vScrollValue = 0;//// Get new View// viewType = type; view = views[viewType]; view->Show(); } // End if realized} // End ViewType/*----------------------------------------------------------------------- * Display a different view */voidVBoxC::ChangeView(Widget w, VBoxC *This, XmToggleButtonCallbackStruct *tb){ if ( tb->set ) {//// Hide current view// if ( This->view ) This->view->Hide();//// Reset scrollbar values// WArgList args; args.Minimum(0); args.Maximum(This->DAWidth()); args.SliderSize(This->DAWidth()); args.Increment(1); args.PageIncrement(This->DAWidth()); args.Value(0); XtSetValues(This->hScrollBar, ARGS); args.Maximum(This->DAHeight()); args.SliderSize(This->DAHeight()); args.Increment(1); args.PageIncrement(This->DAHeight()); XtSetValues(This->vScrollBar, ARGS); This->hScrollValue = This->vScrollValue = 0;//// Get new View from user data and display it// XtVaGetValues(w, XmNuserData, &This->view, NULL); This->view->Show();//// Save the new view type// This->viewType = This->views.indexOf(This->view); } // End if button is set} // End ChangeView/*----------------------------------------------------------------------- * Public method to add a new item to this view box */voidVBoxC::AddItem(VItemC& item){ if ( items.includes(&item) ) return;//// Add it to the lists// _AddItem(item);//// Add item to current view// if ( realized && view ) view->AddItem(item); if ( selItems.includes(&item) ) { item.CallSelectCallbacks(); FinishSelect(); } changed = True;} // End AddItem/*----------------------------------------------------------------------- * Private method to add a new item to this view box */voidVBoxC::_AddItem(VItemC& item){//// Set compare function// item.SetCompareFunction(compFunc);//// Add callbacks// item.AddFieldChangeCallback ((CallbackFn *)ItemFieldChanged, this);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -