⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 boolexpwinc.c

📁 linux下的E_MAIL客户端源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * $Id: BoolExpWinC.C,v 1.5 2000/08/13 13:25:32 evgeny Exp $ * * Copyright (c) 1992 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 "BoolExpWinC.h"#include "WArgList.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 <X11/keysym.h>XtTranslations	BoolExpWinC::translations;XtActionsRec	BoolExpWinC::actions[10] = {   { "BoolExpWinC-insert-lparen",	(XtActionProc)HandleInsertLParen },   { "BoolExpWinC-insert-rparen",	(XtActionProc)HandleInsertRParen },   { "BoolExpWinC-insert-and",		(XtActionProc)HandleInsertAnd },   { "BoolExpWinC-insert-or",		(XtActionProc)HandleInsertOr },   { "BoolExpWinC-insert-not",		(XtActionProc)HandleInsertNot },   { "BoolExpWinC-delete-left",		(XtActionProc)HandleDeleteLeft },   { "BoolExpWinC-delete-right",	(XtActionProc)HandleDeleteRight },   { "BoolExpWinC-move-left",		(XtActionProc)HandleMoveLeft },   { "BoolExpWinC-move-right",		(XtActionProc)HandleMoveRight },   { "BoolExpWinC-move-pointer",	(XtActionProc)HandleMovePointer },};/*------------------------------------------------------------------------- * BoolExpWinC constructor */BoolExpWinC::BoolExpWinC(Widget parent): HalDialogC("boolExpWin", parent){   insertPos  = 0;   resizeOk   = True;   exp        = NULL;   blinkTimer = (XtIntervalId)NULL;   cursorOn   = False;   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:		BoolExpWinC-move-left()	\n\	  <Key>osfRight:	BoolExpWinC-move-right()");   } // End if actions not added//// Get keyboard focus policy//   unsigned char	focusPolicy;   XtVaGetValues(*this, XmNkeyboardFocusPolicy, &focusPolicy, NULL);   WArgList	args;//// appForm//    RowColumn		opRC//    Form		termForm//    ScrolledWindow	expWin//   args.Reset();   args.Orientation(XmHORIZONTAL);   args.Packing(XmPACK_COLUMN);   args.EntryAlignment(XmALIGNMENT_CENTER);   opRC = XmCreateRowColumn(appForm, "opRC", ARGS);   args.Reset();   args.TopAttachment(XmATTACH_WIDGET, opRC);   args.LeftAttachment(XmATTACH_FORM);   args.RightAttachment(XmATTACH_FORM);   termForm = XmCreateForm(appForm, "termForm", ARGS);   args.Reset();   args.TopAttachment(XmATTACH_WIDGET, termForm);   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);   XtVaSetValues(clipWin, XmNnavigationType, XmTAB_GROUP, XmNtraversalOn, True,		 NULL);   XtAddEventHandler(clipWin, StructureNotifyMask, False,		     (XtEventHandler)HandleResize, (XtPointer)this);//// buttonRC//    PushButton	okPB//    PushButton	applyPB//    PushButton	cancelPB//    PushButton	helpPB//   AddButtonBox();   okPB	    = XmCreatePushButton(buttonRC, "okPB",     0,0);   applyPB  = XmCreatePushButton(buttonRC, "applyPB",  0,0);   clearPB  = XmCreatePushButton(buttonRC, "clearPB",  0,0);   cancelPB = XmCreatePushButton(buttonRC, "cancelPB", 0,0);   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)DoHide, 		 (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);//// opRC//    PushButton	lparPB//    PushButton	rparPB//    PushButton	andPB//    PushButton	orPB//    PushButton	notPB//   lparPB = XmCreatePushButton(opRC, "lparPB", 0,0);   rparPB = XmCreatePushButton(opRC, "rparPB", 0,0);   andPB  = XmCreatePushButton(opRC, "andPB",  0,0);   orPB   = XmCreatePushButton(opRC, "orPB",   0,0);   notPB  = XmCreatePushButton(opRC, "notPB",  0,0);   XtAddCallback(lparPB, XmNactivateCallback, (XtCallbackProc)DoLParen,          	 (XtPointer)this);   XtAddCallback(rparPB, XmNactivateCallback, (XtCallbackProc)DoRParen,          	 (XtPointer)this);   XtAddCallback(andPB, XmNactivateCallback, (XtCallbackProc)DoAnd, 		 (XtPointer)this);   XtAddCallback(orPB, XmNactivateCallback, (XtCallbackProc)DoOr, 		 (XtPointer)this);   XtAddCallback(notPB, XmNactivateCallback, (XtCallbackProc)DoNot, 		 (XtPointer)this);//// Manage widgets//   Widget	list[5];   list[0] = lparPB;   list[1] = rparPB;   list[2] = andPB;   list[3] = orPB;   list[4] = notPB;   XtManageChildren(list, 5);	// opRC children   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] = opRC;   list[1] = termForm;   list[2] = expWin;   XtManageChildren(list, 3);	// appForm children   HandleHelp();//// Read window specific resources//   float	rate = get_float("BoolExpWinC", *this, "cursorBlinkRate", 4.0);   blinkInterval = (rate > 0.0) ? (int)((float)1000/rate) : 0;   XtAddCallback(*this, XmNpopupCallback, (XtCallbackProc)DoPopup,		 (XtPointer)this);} // End BoolExpWinC constructor/*------------------------------------------------------------------------- * Destructor */BoolExpWinC::~BoolExpWinC(){   if ( blinkTimer && halApp->xRunning ) XtRemoveTimeOut(blinkTimer);}/*------------------------------------------------------------------------- * Callback to handle initial display of window */voidBoolExpWinC::DoPopup(Widget, BoolExpWinC *be, XtPointer){   XtRemoveCallback(*be, XmNpopupCallback, (XtCallbackProc)DoPopup,		    (XtPointer)be);} // End BoolExpWinC DoPopup/*------------------------------------------------------------------------- * Callback to handle press of Ok button */voidBoolExpWinC::DoOk(Widget, BoolExpWinC *be, XtPointer){   if ( be->Apply() ) DoHide(NULL, be, NULL);}/*------------------------------------------------------------------------- * Callback to handle press of Apply button */voidBoolExpWinC::DoApply(Widget, BoolExpWinC *be, XtPointer){   be->Apply();}BooleanBoolExpWinC::Apply(){//// Make sure the parens balance//   unsigned	count = expList.size();   int		pcount = 0;   int	i;   for (i=0; i<count; i++) {      ExpElemC	*elem = expList[i];      if      ( elem->Type() == ExpElemC::LPAR ) pcount++;      else if ( elem->Type() == ExpElemC::RPAR ) pcount--;      if ( pcount < 0 ) { // Error	 XtVaSetValues(*elem, XmNborderWidth, 1, NULL);	 StringC msg("Right parenthesis is missing a corresponding left.");	 PopupMessage(msg);	 return False;      }   } // End for each element   if ( pcount > 0 ) { // Error      StringC msg("Not enough right parentheses in expression.");      PopupMessage(msg);      return False;   }   delete exp;   if ( expList.size() > 0 ) {      exp = ParseExpList(0, expList.size()-1);      if ( !exp ) return False;   } else {	// Blank expression always returns True      exp = new BoolExpC(&trueExp);   }//// Let user apply filter//   CallApplyCallbacks();   return True;} // End BoolExpWinC Apply/*------------------------------------------------------------------------- * Callback to handle press of Clear button */voidBoolExpWinC::DoClear(Widget, BoolExpWinC *be, XtPointer){   unsigned	count = be->expList.size();   int	i;   for (i=0; i<count; i++) delete be->expList[i];   be->expList.removeAll();   be->insertPos = 0;   be->DrawExp();}/*------------------------------------------------------------------------- * Callback to handle press of left parenthesis button */voidBoolExpWinC::DoLParen(Widget, BoolExpWinC *be, XtPointer){   WArgList	args;   args.Reset();   args.UserData(be);   Widget	w = XmCreateLabel(be->expDA, "lparLabel", ARGS);   XtManageChild(w);   XtOverrideTranslations(w, be->translations);   ExpElemC	*elem = new ExpElemC(ExpElemC::LPAR, w);   be->expList.insert(elem, be->insertPos);   be->insertPos++;   be->DrawExp();}/*------------------------------------------------------------------------- * Callback to handle press of right parenthesis button */voidBoolExpWinC::DoRParen(Widget, BoolExpWinC *be, XtPointer){   WArgList	args;   args.Reset();   args.UserData(be);   Widget	w = XmCreateLabel(be->expDA, "rparLabel", ARGS);   XtManageChild(w);   XtOverrideTranslations(w, be->translations);   ExpElemC	*elem = new ExpElemC(ExpElemC::RPAR, w);   be->expList.insert(elem, be->insertPos);   be->insertPos++;   be->DrawExp();}/*------------------------------------------------------------------------- * Callback to handle press of And button */voidBoolExpWinC::DoAnd(Widget, BoolExpWinC *be, XtPointer){   WArgList	args;   args.Reset();   args.UserData(be);   Widget	w = XmCreateLabel(be->expDA, "andLabel", ARGS);   XtManageChild(w);   XtOverrideTranslations(w, be->translations);   ExpElemC	*elem = new ExpElemC(ExpElemC::AND, w);   be->expList.insert(elem, be->insertPos);   be->insertPos++;   be->DrawExp();}/*------------------------------------------------------------------------- * Callback to handle press of Or button */voidBoolExpWinC::DoOr(Widget, BoolExpWinC *be, XtPointer){   WArgList	args;   args.Reset();   args.UserData(be);   Widget	w = XmCreateLabel(be->expDA, "orLabel", ARGS);   XtManageChild(w);   XtOverrideTranslations(w, be->translations);   ExpElemC	*elem = new ExpElemC(ExpElemC::OR, w);   be->expList.insert(elem, be->insertPos);   be->insertPos++;   be->DrawExp();}/*------------------------------------------------------------------------- * Callback to handle press of Not button */voidBoolExpWinC::DoNot(Widget, BoolExpWinC *be, XtPointer){   WArgList	args;   args.Reset();   args.UserData(be);   Widget	w = XmCreateLabel(be->expDA, "notLabel", ARGS);   XtManageChild(w);   XtOverrideTranslations(w, be->translations);   ExpElemC	*elem = new ExpElemC(ExpElemC::NOT, w);   be->expList.insert(elem, be->insertPos);   be->insertPos++;   be->DrawExp();}/*------------------------------------------------------------------------- * Method to handle insertion of a terminal expression */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -