📄 sortexpwinc.c
字号:
/* * $Id: SortExpWinC.C,v 1.3 2000/05/07 12:26:11 fnevgeny Exp $ * * Copyright (c) 1993 HAL Computer Systems International, Ltd. * * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. * 1315 Dell Avenue * Campbell, CA 95008 * * Author: Greg Hilton * Contributors: Tom Lang, Frank Bieser, and others * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * http://www.gnu.org/copyleft/gpl.html * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */#include <config.h>#include "HalAppC.h"#include "SortExpWinC.h"#include "WArgList.h"#include "WXmString.h"#include "StringC.h"#include "rsrc.h"#include <Xm/RowColumn.h>#include <Xm/Form.h>#include <Xm/Frame.h>#include <Xm/PushB.h>#include <Xm/DrawingA.h>#include <Xm/Label.h>#include <Xm/ScrolledW.h>#include <Xm/MessageB.h>#include <Xm/ToggleB.h>#include <X11/keysym.h>/*------------------------------------------------------------------------- * SortElemC constructors */SortElemC::SortElemC(SortKeyC *k, Widget w){ widget = w; key = k; ht = 0; XtVaGetValues(w, XmNheight, &ht, NULL);}/*------------------------------------------------------------------------- * SortElemC destructor */SortElemC::~SortElemC(){ if ( halApp->xRunning ) { XtUnmanageChild(widget); XtDestroyWidget(widget); }}/*------------------------------------------------------------------------- * SortElemC assignment */SortElemC&SortElemC::operator=(const SortElemC& e){ widget = e.widget; key = e.key; return *this;}/*------------------------------------------------------------------------- * SortElemC equivalence */intSortElemC::operator==(const SortElemC& e) const{ return ( widget == e.widget && key == e.key );}XtTranslations SortExpWinC::translations;XtActionsRec SortExpWinC::actions[5] = { "SortExpWinC-delete-left", (XtActionProc)HandleDeleteLeft, "SortExpWinC-delete-right", (XtActionProc)HandleDeleteRight, "SortExpWinC-move-left", (XtActionProc)HandleMoveLeft, "SortExpWinC-move-right", (XtActionProc)HandleMoveRight, "SortExpWinC-move-pointer", (XtActionProc)HandleMovePointer,};/*------------------------------------------------------------------------- * SortExpWinC constructor */SortExpWinC::SortExpWinC(Widget parent, const char *name): HalDialogC(name, parent){ insertPos = 0; resizeOk = True; blinkTimer = (XtIntervalId)NULL; cursorOn = False; applyAll = True; writeFunc = NULL; applyQueryWin = NULL; applyCalls.AllowDuplicates(TRUE);//// Add actions and translations if necessary// static Boolean actionsAdded = False; if ( !actionsAdded ) { XtAppAddActions(halApp->context, actions, XtNumber(actions)); actionsAdded = True;//// These translations cannot be specified in a resource file due to the fact// that Motif overrides them after the resource file is processed.// translations = XtParseTranslationTable( "<Key>osfLeft: SortExpWinC-move-left() \n\ <Key>osfRight: SortExpWinC-move-right()"); } // End if actions not added//// Get keyboard focus policy// unsigned char focusPolicy; XtVaGetValues(*this, XmNkeyboardFocusPolicy, &focusPolicy, NULL); WArgList args;//// appForm// Frame expFrame// Label keyOrderLabel// ScrolledWindow expWin// args.Reset(); args.TopAttachment(XmATTACH_FORM); args.LeftAttachment(XmATTACH_FORM); args.RightAttachment(XmATTACH_FORM); Widget expFrame = XmCreateFrame(appForm, "expFrame", ARGS); args.Reset(); args.TopAttachment(XmATTACH_WIDGET, expFrame); args.LeftAttachment(XmATTACH_FORM); args.Alignment(XmALIGNMENT_BEGINNING); Widget keyOrderLabel = XmCreateLabel(appForm, "keyOrderLabel", ARGS); args.Reset(); args.TopAttachment(XmATTACH_WIDGET, keyOrderLabel); args.LeftAttachment(XmATTACH_FORM); args.RightAttachment(XmATTACH_FORM); args.BottomAttachment(XmATTACH_FORM); args.ScrollingPolicy(XmAUTOMATIC); args.ScrollBarDisplayPolicy(XmSTATIC); expWin = XmCreateScrolledWindow(appForm, "expWin", ARGS); XtVaGetValues(expWin, XmNclipWindow, &clipWin, NULL); XtVaGetValues(clipWin, XmNwidth, &clipWd, XmNheight, &clipHt, NULL); XtAddEventHandler(clipWin, StructureNotifyMask, False, (XtEventHandler)HandleResize, (XtPointer)this);//// expFrame// Label availKeyLabel// Form expForm// args.Reset(); args.ChildType(XmFRAME_TITLE_CHILD); Widget availKeyLabel = XmCreateLabel(expFrame, "availKeyLabel", ARGS); expForm = XmCreateForm(expFrame, "expForm", 0,0);//// buttonRC// PushButton okPB// PushButton applyPB// PushButton clearPB// PushButton cancelPB// PushButton helpPB// AddButtonBox(); Widget okPB = XmCreatePushButton(buttonRC, "okPB", 0,0); Widget applyPB = XmCreatePushButton(buttonRC, "applyPB", 0,0); Widget clearPB = XmCreatePushButton(buttonRC, "clearPB", 0,0); Widget cancelPB = XmCreatePushButton(buttonRC, "cancelPB", 0,0); Widget helpPB = XmCreatePushButton(buttonRC, "helpPB", 0,0); XtAddCallback(okPB, XmNactivateCallback, (XtCallbackProc)DoOk, (XtPointer)this); XtAddCallback(applyPB, XmNactivateCallback, (XtCallbackProc)DoApply, (XtPointer)this); XtAddCallback(clearPB, XmNactivateCallback, (XtCallbackProc)DoClear, (XtPointer)this); XtAddCallback(cancelPB, XmNactivateCallback, (XtCallbackProc)DoCancel, (XtPointer)this); XtAddCallback(helpPB, XmNactivateCallback, (XtCallbackProc)HalAppC::DoHelp, (char *) "helpcard"); XtVaSetValues(appForm, XmNdefaultButton, okPB, NULL);//// expWin// DrawingArea expDA// args.Reset(); args.UserData(this); expDA = XmCreateDrawingArea(expWin, "expDA", ARGS); XtVaSetValues(expWin, XmNworkWindow, expDA, NULL); XtOverrideTranslations(expDA, translations);//// Add event handler for focus change// if ( focusPolicy == XmPOINTER ) { XtAddEventHandler(clipWin, EnterWindowMask|LeaveWindowMask, False, (XtEventHandler)HandleFocusChange, (XtPointer)this); } else { XtAddEventHandler(expDA, FocusChangeMask, False, (XtEventHandler)HandleFocusChange, (XtPointer)this); } Pixel expFG; XtVaGetValues(expDA, XmNmarginWidth, &marWd, XmNmarginHeight, &marHt, XmNborderWidth, &borWd, XmNforeground, &expFG, NULL); marWd += borWd; marHt += borWd;//// expDA// Label cursorLabel// DrawingArea cornerDA// args.Reset(); args.UserData(this); cursorLabel = XmCreateLabel(expDA, "cursor", ARGS); XtVaGetValues(cursorLabel, XmNwidth, &cursorWd, XmNheight, &cursorHt, NULL);//// Create a small child in the lower right corner to make sure the DA is always// the right size// args.Reset(); args.Width(1); args.Height(1); args.X((Position)clipWd); args.Y((Position)clipHt); args.NavigationType(XmNONE); args.TraversalOn(False); args.UserData(this); cornerDA = XmCreateDrawingArea(expDA, "cornerDA", ARGS);//// Create a frame between the button box and the button separator to show// the current/future choices//// topForm// Separator buttonSep (already created)// Frame centerFrame// Frame applyFrame// RadioBox applyRadio// ToggleButton applyAllTB// ToggleButton applyCurrentTB// Frame buttonFrame (already created)// args.Reset(); args.ShadowThickness(0); args.MarginWidth(0); args.MarginHeight(0); args.TopAttachment(XmATTACH_NONE); args.LeftAttachment(XmATTACH_FORM); args.RightAttachment(XmATTACH_FORM); args.BottomAttachment(XmATTACH_WIDGET, buttonRC); Widget centerFrame = XmCreateFrame(topForm, "centerFrame", ARGS); args.Reset(); args.ChildType(XmFRAME_TITLE_CHILD); args.ChildHorizontalAlignment(XmALIGNMENT_CENTER); args.ChildHorizontalSpacing(0); args.ChildVerticalAlignment(XmALIGNMENT_WIDGET_TOP); Widget applyFrame = XmCreateFrame(centerFrame, "applyFrame", ARGS); args.Reset(); args.Orientation(XmHORIZONTAL); args.Packing(XmPACK_TIGHT); 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); XtManageChild(applyAllTB); XtManageChild(applyCurrentTB); XtManageChild(applyRadio); XtManageChild(applyFrame); XtManageChild(centerFrame); args.Reset(); args.BottomAttachment(XmATTACH_WIDGET, centerFrame); XtSetValues(buttonSep, ARGS);//// Manage widgets// Widget list[5]; list[0] = cursorLabel; list[1] = cornerDA; XtManageChildren(list, 2); // expDA children XtManageChild(expDA); // expWin children list[0] = okPB; list[1] = applyPB; list[2] = clearPB; list[3] = cancelPB; list[4] = helpPB; XtManageChildren(list, 5); // buttonRC children list[0] = availKeyLabel; list[1] = expForm; XtManageChildren(list, 2); // expFrame children list[0] = expFrame; list[1] = keyOrderLabel; list[2] = expWin; XtManageChildren(list, 3); // appForm children HandleHelp();//// Read window specific resources// float rate = get_float("SortExpWinC", *this, "cursorBlinkRate", 4.0); blinkInterval = (rate > 0.0) ? (int)((float)1000/rate) : 0;} // End constructor/*------------------------------------------------------------------------- * Destructor */SortExpWinC::~SortExpWinC(){ if ( blinkTimer && halApp->xRunning ) XtRemoveTimeOut(blinkTimer); unsigned count = expList.size(); for (int i=0; i<count; i++) delete expList[i]; DeleteCallbacks(applyCalls);}/*------------------------------------------------------------------------- * Callback to handle press of Ok button */voidSortExpWinC::DoOk(Widget, SortExpWinC *This, XtPointer){ if ( This->Apply() ) DoCancel(NULL, This, NULL);}/*------------------------------------------------------------------------- * Callback to handle press of Apply button */voidSortExpWinC::DoApply(Widget, SortExpWinC *This, XtPointer){ This->Apply();}BooleanSortExpWinC::Apply(){ if ( writeFunc && !ApplyQuery() ) return False; BusyCursor(True);//// Build fresh list of sort keys// keyList.removeAll(); unsigned count = expList.size(); for (int i=0; i<count; i++) keyList.append((SortKeyC *)*expList[i]);//// Let user apply sort// CallApplyCallbacks();//// Write spec if necessary
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -