📄 sortexpwinc.c
字号:
// if ( writeFunc ) (*writeFunc)(this); BusyCursor(False); return True;} // End Apply/*------------------------------------------------------------------------- * Callback to handle press of Clear button */voidSortExpWinC::DoClear(Widget, SortExpWinC *This, XtPointer){ This->Clear();}voidSortExpWinC::Clear(){ unsigned count = expList.size(); for (int i=0; i<count; i++) delete expList[i]; expList.removeAll(); insertPos = 0; DrawExp();}/*------------------------------------------------------------------------- * Callback to handle press of Cancel button */voidSortExpWinC::DoCancel(Widget, SortExpWinC *This, XtPointer){ This->Hide();}/*------------------------------------------------------------------------- * Method to handle insertion of a terminal expression */WidgetSortExpWinC::AddSortKey(SortKeyC *key, const char *cs){ WArgList args; WXmString str(cs); args.Reset(); args.UserData(this); args.LabelString((XmString)str); Widget w = XmCreateLabel(expDA, "keyLabel", ARGS); XtManageChild(w); XtOverrideTranslations(w, translations); SortElemC *elem = new SortElemC(key, w); expList.insert(elem, insertPos); insertPos++; DrawExp(); return w;}/*------------------------------------------------------------------------- * Method to handle removal of a terminal expression */voidSortExpWinC::RemoveSortKey(SortKeyC *key){//// Loop through expList looking for key// Boolean found = False; unsigned count = expList.size(); for (int i=0; !found && i<count; i++) { SortElemC *elem = expList[i];//// If key matches, remove it and redraw// if ( &elem->SortKey() == key ) { if ( insertPos > i ) insertPos--; delete elem; expList.remove(elem); DrawExp(); found = True; } } // End for each element} // End RemoveSortKey/*------------------------------------------------------------------------- * Method to calculate positions for all expression elements */voidSortExpWinC::DrawExp(){ resizeOk = False; // Don't respond to self-induced resizes//// Position elements// Position y = marHt; WArgList args; unsigned count = expList.size(); for (int i=0; i<count; i++) { Position x = marWd; SortElemC *elem = expList[i];//// Draw insertion cursor if necessary// if ( insertPos == i ) { args.X(x); args.Y(y + ((int)(elem->Height() - cursorHt)/(int)2)); // Center vertically XtSetValues(cursorLabel, ARGS); x += cursorWd; } // End if placing cursor here//// Set and update position// args.X(x); args.Y(y); XtSetValues(*elem, ARGS); y += elem->Height(); } // End for each expression if ( insertPos == count ) { args.X(marWd); args.Y(y); XtSetValues(cursorLabel, ARGS); } resizeOk = True;} // End DrawExp/*----------------------------------------------------------------------- * Event handler for scrolled window resize */voidSortExpWinC::HandleResize(Widget, SortExpWinC *This, XEvent*, Boolean*){ XtVaGetValues(This->clipWin, XmNwidth, &This->clipWd, XmNheight, &This->clipHt, 0); XtVaSetValues(This->cornerDA, XmNx, (Position)(This->clipWd - This->borWd*2 - 1), XmNy, (Position)(This->clipHt - This->borWd*2 - 1), NULL); if ( This->resizeOk ) This->DrawExp();}/*--------------------------------------------------------------- * Timer proc to blink insertion cursor */voidSortExpWinC::BlinkProc(SortExpWinC *This, XtIntervalId*){ if ( This->cursorOn ) { XtSetMappedWhenManaged(This->cursorLabel, False); This->cursorOn = False; } else { XtSetMappedWhenManaged(This->cursorLabel, True); This->cursorOn = True; } This->blinkTimer = XtAppAddTimeOut(halApp->context, This->blinkInterval, (XtTimerCallbackProc)BlinkProc, (XtPointer)This);} // End BlinkProc/*--------------------------------------------------------------- * Handle a keyboard focus change event in the area */voidSortExpWinC::HandleFocusChange(Widget, SortExpWinC *This, XEvent *ev, Boolean*){ if ( This->blinkTimer ) XtRemoveTimeOut(This->blinkTimer); switch (ev->type) { case (FocusIn): case (EnterNotify): if ( This->blinkInterval > 0 ) BlinkProc(This, NULL); break; case (FocusOut): case (LeaveNotify): This->cursorOn = True; XtSetMappedWhenManaged(This->cursorLabel, True); break; }} // End HandleFocusChangevoidSortExpWinC::HandleDeleteLeft(Widget w, XKeyEvent*, String*, Cardinal*){ SortExpWinC *This; XtVaGetValues(w, XmNuserData, &This, NULL); if ( This->insertPos > 0 ) { This->insertPos--; delete This->expList[This->insertPos]; This->expList.remove(This->insertPos); This->DrawExp(); }}voidSortExpWinC::HandleDeleteRight(Widget w, XKeyEvent*, String*, Cardinal*){ SortExpWinC *This; XtVaGetValues(w, XmNuserData, &This, NULL); if ( This->insertPos < This->expList.size() ) { delete This->expList[This->insertPos]; This->expList.remove(This->insertPos); This->DrawExp(); }}voidSortExpWinC::HandleMoveLeft(Widget w, XKeyEvent*, String*, Cardinal*){ SortExpWinC *This; XtVaGetValues(w, XmNuserData, &This, NULL); if ( This->insertPos > 0 ) { This->insertPos--; This->DrawExp(); }}voidSortExpWinC::HandleMoveRight(Widget w, XKeyEvent*, String*, Cardinal*){ SortExpWinC *This; XtVaGetValues(w, XmNuserData, &This, NULL); if ( This->insertPos < This->expList.size() ) { This->insertPos++; This->DrawExp(); }}voidSortExpWinC::HandleMovePointer(Widget w, XButtonEvent *ev, String*, Cardinal*){ SortExpWinC *This; XtVaGetValues(w, XmNuserData, &This, NULL); XmProcessTraversal(This->expDA, XmTRAVERSE_CURRENT);//// Translate event coordinates to expDA if this is a child// if ( XtParent(w) == This->expDA ) { Position x, y; XtVaGetValues(w, XmNx, &x, XmNy, &y, NULL); ev->x += x; ev->y += y; }//// Find element which corresponds to this y value// int y = This->marHt; unsigned count = This->expList.size(); int i; for (i=0; i<count && ev->y > y; i++) { SortElemC *elem = This->expList[i]; y += elem->Height(); } if ( i>0 && ev->y <= y ) This->insertPos = i-1; else This->insertPos = i; This->DrawExp();} // End HandleMovePointer/*--------------------------------------------------------------- * Method to query for type of apply */BooleanSortExpWinC::ApplyQuery(){ return True;#if 0 static int reason;//// Create the dialog if necessary// if ( !applyQueryWin ) { WArgList args; BusyCursor(True); args.Reset(); args.DialogStyle(XmDIALOG_FULL_APPLICATION_MODAL); Widget w = XmCreateQuestionDialog(*this, "applyQueryWin", ARGS); XtAddCallback(w, XmNokCallback, (XtCallbackProc)WaitForAnswer, (XtPointer)&reason); XtAddCallback(w, XmNcancelCallback, (XtCallbackProc)WaitForAnswer, (XtPointer)&reason); Widget applyFrame = XmCreateFrame(w, "applyFrame", 0,0); args.Reset(); args.Orientation(XmVERTICAL); args.Packing(XmPACK_COLUMN); Widget applyRadio = XmCreateRadioBox(applyFrame, "applyRadio", ARGS); Widget applyAllTB = XmCreateToggleButton(applyRadio, "applyAllTB", 0,0); Widget applyCurrentTB = XmCreateToggleButton(applyRadio, "applyCurrentTB", 0,0); XmToggleButtonSetState(applyAllTB, True, False); XtAddCallback(applyAllTB, XmNvalueChangedCallback, (XtCallbackProc)SetApplyAll, (XtPointer)this); XtAddCallback(applyCurrentTB, XmNvalueChangedCallback, (XtCallbackProc)SetApplyCurrent, (XtPointer)this); Widget list[3]; list[0] = applyAllTB; list[1] = applyCurrentTB; XtManageChildren(list, 2); XtManageChild(applyRadio); XtManageChild(applyFrame); applyQueryWin = w; BusyCursor(False); } // End if query dialog not created XtManageChild(applyQueryWin); XMapRaised(halApp->display, XtWindow(XtParent(applyQueryWin)));//// Simulate the main event loop and wait for the answer// reason = XmCR_NONE; while ( reason == XmCR_NONE ) { XtAppProcessEvent(halApp->context, XtIMXEvent); XSync(halApp->display, False); } XtUnmanageChild(applyQueryWin); XSync(halApp->display, False); XmUpdateDisplay(applyQueryWin); return (reason == XmCR_OK);#endif} // End ApplyQuery#if 0/*--------------------------------------------------------------- * Callback routine to handle press of a APPLY QUERY answer */voidSortExpWinC::WaitForAnswer(Widget, int *reason, XmAnyCallbackStruct *cbs){ *reason = cbs->reason;}#endif/*--------------------------------------------------------------- * Callbacks to handle setting of apply type */voidSortExpWinC::SetApplyCurrent(Widget, SortExpWinC *sw, XmToggleButtonCallbackStruct *tb){ if ( !tb->set ) return; sw->applyAll = False;}voidSortExpWinC::SetApplyAll(Widget, SortExpWinC *sw, XmToggleButtonCallbackStruct *tb){ if ( !tb->set ) return; sw->applyAll = True;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -